Commit 4ad8e34d authored by Andy Shevchenko's avatar Andy Shevchenko Committed by Greg Kroah-Hartman

serial: mctrl_gpio: Use gpiod flags directly

Description of the modem line control GPIOs contain a boolean type to set
direction of the line. Since GPIO library provides an enumerator type of flags,
we may utilize it and allow a bit more flexibility on the choice of the type of
the line parameters. It also removes an additional layer of value conversion.
Signed-off-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: default avatarStefan Roese <sr@denx.de>
Reviewed-by: default avatarGeert Uytterhoeven <geert+renesas@glider.be>
Link: https://lore.kernel.org/r/20190814140759.17486-1-andriy.shevchenko@linux.intel.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent c140e97f
...@@ -27,16 +27,21 @@ struct mctrl_gpios { ...@@ -27,16 +27,21 @@ struct mctrl_gpios {
static const struct { static const struct {
const char *name; const char *name;
unsigned int mctrl; unsigned int mctrl;
bool dir_out; enum gpiod_flags flags;
} mctrl_gpios_desc[UART_GPIO_MAX] = { } mctrl_gpios_desc[UART_GPIO_MAX] = {
{ "cts", TIOCM_CTS, false, }, { "cts", TIOCM_CTS, GPIOD_IN, },
{ "dsr", TIOCM_DSR, false, }, { "dsr", TIOCM_DSR, GPIOD_IN, },
{ "dcd", TIOCM_CD, false, }, { "dcd", TIOCM_CD, GPIOD_IN, },
{ "rng", TIOCM_RNG, false, }, { "rng", TIOCM_RNG, GPIOD_IN, },
{ "rts", TIOCM_RTS, true, }, { "rts", TIOCM_RTS, GPIOD_OUT_LOW, },
{ "dtr", TIOCM_DTR, true, }, { "dtr", TIOCM_DTR, GPIOD_OUT_LOW, },
}; };
static bool mctrl_gpio_flags_is_dir_out(unsigned int idx)
{
return mctrl_gpios_desc[idx].flags & GPIOD_FLAGS_BIT_DIR_OUT;
}
void mctrl_gpio_set(struct mctrl_gpios *gpios, unsigned int mctrl) void mctrl_gpio_set(struct mctrl_gpios *gpios, unsigned int mctrl)
{ {
enum mctrl_gpio_idx i; enum mctrl_gpio_idx i;
...@@ -48,7 +53,7 @@ void mctrl_gpio_set(struct mctrl_gpios *gpios, unsigned int mctrl) ...@@ -48,7 +53,7 @@ void mctrl_gpio_set(struct mctrl_gpios *gpios, unsigned int mctrl)
return; return;
for (i = 0; i < UART_GPIO_MAX; i++) for (i = 0; i < UART_GPIO_MAX; i++)
if (gpios->gpio[i] && mctrl_gpios_desc[i].dir_out) { if (gpios->gpio[i] && mctrl_gpio_flags_is_dir_out(i)) {
desc_array[count] = gpios->gpio[i]; desc_array[count] = gpios->gpio[i];
__assign_bit(count, values, __assign_bit(count, values,
mctrl & mctrl_gpios_desc[i].mctrl); mctrl & mctrl_gpios_desc[i].mctrl);
...@@ -73,7 +78,7 @@ unsigned int mctrl_gpio_get(struct mctrl_gpios *gpios, unsigned int *mctrl) ...@@ -73,7 +78,7 @@ unsigned int mctrl_gpio_get(struct mctrl_gpios *gpios, unsigned int *mctrl)
return *mctrl; return *mctrl;
for (i = 0; i < UART_GPIO_MAX; i++) { for (i = 0; i < UART_GPIO_MAX; i++) {
if (gpios->gpio[i] && !mctrl_gpios_desc[i].dir_out) { if (gpios->gpio[i] && !mctrl_gpio_flags_is_dir_out(i)) {
if (gpiod_get_value(gpios->gpio[i])) if (gpiod_get_value(gpios->gpio[i]))
*mctrl |= mctrl_gpios_desc[i].mctrl; *mctrl |= mctrl_gpios_desc[i].mctrl;
else else
...@@ -94,7 +99,7 @@ mctrl_gpio_get_outputs(struct mctrl_gpios *gpios, unsigned int *mctrl) ...@@ -94,7 +99,7 @@ mctrl_gpio_get_outputs(struct mctrl_gpios *gpios, unsigned int *mctrl)
return *mctrl; return *mctrl;
for (i = 0; i < UART_GPIO_MAX; i++) { for (i = 0; i < UART_GPIO_MAX; i++) {
if (gpios->gpio[i] && mctrl_gpios_desc[i].dir_out) { if (gpios->gpio[i] && mctrl_gpio_flags_is_dir_out(i)) {
if (gpiod_get_value(gpios->gpio[i])) if (gpiod_get_value(gpios->gpio[i]))
*mctrl |= mctrl_gpios_desc[i].mctrl; *mctrl |= mctrl_gpios_desc[i].mctrl;
else else
...@@ -116,7 +121,6 @@ struct mctrl_gpios *mctrl_gpio_init_noauto(struct device *dev, unsigned int idx) ...@@ -116,7 +121,6 @@ struct mctrl_gpios *mctrl_gpio_init_noauto(struct device *dev, unsigned int idx)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
for (i = 0; i < UART_GPIO_MAX; i++) { for (i = 0; i < UART_GPIO_MAX; i++) {
enum gpiod_flags flags;
char *gpio_str; char *gpio_str;
bool present; bool present;
...@@ -131,15 +135,11 @@ struct mctrl_gpios *mctrl_gpio_init_noauto(struct device *dev, unsigned int idx) ...@@ -131,15 +135,11 @@ struct mctrl_gpios *mctrl_gpio_init_noauto(struct device *dev, unsigned int idx)
if (!present) if (!present)
continue; continue;
if (mctrl_gpios_desc[i].dir_out)
flags = GPIOD_OUT_LOW;
else
flags = GPIOD_IN;
gpios->gpio[i] = gpios->gpio[i] =
devm_gpiod_get_index_optional(dev, devm_gpiod_get_index_optional(dev,
mctrl_gpios_desc[i].name, mctrl_gpios_desc[i].name,
idx, flags); idx,
mctrl_gpios_desc[i].flags);
if (IS_ERR(gpios->gpio[i])) if (IS_ERR(gpios->gpio[i]))
return ERR_CAST(gpios->gpio[i]); return ERR_CAST(gpios->gpio[i]);
...@@ -200,7 +200,7 @@ struct mctrl_gpios *mctrl_gpio_init(struct uart_port *port, unsigned int idx) ...@@ -200,7 +200,7 @@ struct mctrl_gpios *mctrl_gpio_init(struct uart_port *port, unsigned int idx)
for (i = 0; i < UART_GPIO_MAX; ++i) { for (i = 0; i < UART_GPIO_MAX; ++i) {
int ret; int ret;
if (!gpios->gpio[i] || mctrl_gpios_desc[i].dir_out) if (!gpios->gpio[i] || mctrl_gpio_flags_is_dir_out(i))
continue; continue;
ret = gpiod_to_irq(gpios->gpio[i]); ret = gpiod_to_irq(gpios->gpio[i]);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment