Skip to content

Commit 97cbaf2

Browse files
linuswgregkh
authored andcommitted
tty: serial: cpm_uart: Convert to use GPIO descriptors
The CPM UART (PowerPC) has an open coded GPIO modem control handling. Since I can't test this I can't just migrate it to the serial mctrl GPIO helper library though I wish I could. I do second best and convert it to GPIO descriptors at least. Cc: Rasmus Villemoes <[email protected]> Cc: Christophe Leroy <[email protected]> Signed-off-by: Linus Walleij <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 8145e85 commit 97cbaf2

File tree

2 files changed

+24
-28
lines changed

2 files changed

+24
-28
lines changed

drivers/tty/serial/cpm_uart/cpm_uart.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#include <linux/platform_device.h>
1414
#include <linux/fs_uart_pd.h>
1515

16+
struct gpio_desc;
17+
1618
#if defined(CONFIG_CPM2)
1719
#include "cpm_uart_cpm2.h"
1820
#elif defined(CONFIG_CPM1)
@@ -80,7 +82,7 @@ struct uart_cpm_port {
8082
int wait_closing;
8183
/* value to combine with opcode to form cpm command */
8284
u32 command;
83-
int gpios[NUM_GPIOS];
85+
struct gpio_desc *gpios[NUM_GPIOS];
8486
};
8587

8688
extern int cpm_uart_nr;

drivers/tty/serial/cpm_uart/cpm_uart_core.c

+21-27
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@
3030
#include <linux/of_address.h>
3131
#include <linux/of_irq.h>
3232
#include <linux/of_platform.h>
33-
#include <linux/gpio.h>
34-
#include <linux/of_gpio.h>
33+
#include <linux/gpio/consumer.h>
3534
#include <linux/clk.h>
3635

3736
#include <asm/io.h>
@@ -88,11 +87,11 @@ static void cpm_uart_set_mctrl(struct uart_port *port, unsigned int mctrl)
8887
struct uart_cpm_port *pinfo =
8988
container_of(port, struct uart_cpm_port, port);
9089

91-
if (pinfo->gpios[GPIO_RTS] >= 0)
92-
gpio_set_value(pinfo->gpios[GPIO_RTS], !(mctrl & TIOCM_RTS));
90+
if (pinfo->gpios[GPIO_RTS])
91+
gpiod_set_value(pinfo->gpios[GPIO_RTS], !(mctrl & TIOCM_RTS));
9392

94-
if (pinfo->gpios[GPIO_DTR] >= 0)
95-
gpio_set_value(pinfo->gpios[GPIO_DTR], !(mctrl & TIOCM_DTR));
93+
if (pinfo->gpios[GPIO_DTR])
94+
gpiod_set_value(pinfo->gpios[GPIO_DTR], !(mctrl & TIOCM_DTR));
9695
}
9796

9897
static unsigned int cpm_uart_get_mctrl(struct uart_port *port)
@@ -101,23 +100,23 @@ static unsigned int cpm_uart_get_mctrl(struct uart_port *port)
101100
container_of(port, struct uart_cpm_port, port);
102101
unsigned int mctrl = TIOCM_CTS | TIOCM_DSR | TIOCM_CAR;
103102

104-
if (pinfo->gpios[GPIO_CTS] >= 0) {
105-
if (gpio_get_value(pinfo->gpios[GPIO_CTS]))
103+
if (pinfo->gpios[GPIO_CTS]) {
104+
if (gpiod_get_value(pinfo->gpios[GPIO_CTS]))
106105
mctrl &= ~TIOCM_CTS;
107106
}
108107

109-
if (pinfo->gpios[GPIO_DSR] >= 0) {
110-
if (gpio_get_value(pinfo->gpios[GPIO_DSR]))
108+
if (pinfo->gpios[GPIO_DSR]) {
109+
if (gpiod_get_value(pinfo->gpios[GPIO_DSR]))
111110
mctrl &= ~TIOCM_DSR;
112111
}
113112

114-
if (pinfo->gpios[GPIO_DCD] >= 0) {
115-
if (gpio_get_value(pinfo->gpios[GPIO_DCD]))
113+
if (pinfo->gpios[GPIO_DCD]) {
114+
if (gpiod_get_value(pinfo->gpios[GPIO_DCD]))
116115
mctrl &= ~TIOCM_CAR;
117116
}
118117

119-
if (pinfo->gpios[GPIO_RI] >= 0) {
120-
if (!gpio_get_value(pinfo->gpios[GPIO_RI]))
118+
if (pinfo->gpios[GPIO_RI]) {
119+
if (!gpiod_get_value(pinfo->gpios[GPIO_RI]))
121120
mctrl |= TIOCM_RNG;
122121
}
123122

@@ -1139,6 +1138,7 @@ static int cpm_uart_init_port(struct device_node *np,
11391138
{
11401139
const u32 *data;
11411140
void __iomem *mem, *pram;
1141+
struct device *dev = pinfo->port.dev;
11421142
int len;
11431143
int ret;
11441144
int i;
@@ -1211,29 +1211,23 @@ static int cpm_uart_init_port(struct device_node *np,
12111211
}
12121212

12131213
for (i = 0; i < NUM_GPIOS; i++) {
1214-
int gpio;
1214+
struct gpio_desc *gpiod;
12151215

1216-
pinfo->gpios[i] = -1;
1216+
pinfo->gpios[i] = NULL;
12171217

1218-
gpio = of_get_gpio(np, i);
1218+
gpiod = devm_gpiod_get_index(dev, NULL, i, GPIOD_ASIS);
12191219

1220-
if (gpio_is_valid(gpio)) {
1221-
ret = gpio_request(gpio, "cpm_uart");
1222-
if (ret) {
1223-
pr_err("can't request gpio #%d: %d\n", i, ret);
1224-
continue;
1225-
}
1220+
if (gpiod) {
12261221
if (i == GPIO_RTS || i == GPIO_DTR)
1227-
ret = gpio_direction_output(gpio, 0);
1222+
ret = gpiod_direction_output(gpiod, 0);
12281223
else
1229-
ret = gpio_direction_input(gpio);
1224+
ret = gpiod_direction_input(gpiod);
12301225
if (ret) {
12311226
pr_err("can't set direction for gpio #%d: %d\n",
12321227
i, ret);
1233-
gpio_free(gpio);
12341228
continue;
12351229
}
1236-
pinfo->gpios[i] = gpio;
1230+
pinfo->gpios[i] = gpiod;
12371231
}
12381232
}
12391233

0 commit comments

Comments
 (0)