30
30
#include <linux/of_address.h>
31
31
#include <linux/of_irq.h>
32
32
#include <linux/of_platform.h>
33
- #include <linux/gpio.h>
34
- #include <linux/of_gpio.h>
33
+ #include <linux/gpio/consumer.h>
35
34
#include <linux/clk.h>
36
35
37
36
#include <asm/io.h>
@@ -88,11 +87,11 @@ static void cpm_uart_set_mctrl(struct uart_port *port, unsigned int mctrl)
88
87
struct uart_cpm_port * pinfo =
89
88
container_of (port , struct uart_cpm_port , port );
90
89
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 ));
93
92
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 ));
96
95
}
97
96
98
97
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)
101
100
container_of (port , struct uart_cpm_port , port );
102
101
unsigned int mctrl = TIOCM_CTS | TIOCM_DSR | TIOCM_CAR ;
103
102
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 ]))
106
105
mctrl &= ~TIOCM_CTS ;
107
106
}
108
107
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 ]))
111
110
mctrl &= ~TIOCM_DSR ;
112
111
}
113
112
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 ]))
116
115
mctrl &= ~TIOCM_CAR ;
117
116
}
118
117
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 ]))
121
120
mctrl |= TIOCM_RNG ;
122
121
}
123
122
@@ -1139,6 +1138,7 @@ static int cpm_uart_init_port(struct device_node *np,
1139
1138
{
1140
1139
const u32 * data ;
1141
1140
void __iomem * mem , * pram ;
1141
+ struct device * dev = pinfo -> port .dev ;
1142
1142
int len ;
1143
1143
int ret ;
1144
1144
int i ;
@@ -1211,29 +1211,23 @@ static int cpm_uart_init_port(struct device_node *np,
1211
1211
}
1212
1212
1213
1213
for (i = 0 ; i < NUM_GPIOS ; i ++ ) {
1214
- int gpio ;
1214
+ struct gpio_desc * gpiod ;
1215
1215
1216
- pinfo -> gpios [i ] = -1 ;
1216
+ pinfo -> gpios [i ] = NULL ;
1217
1217
1218
- gpio = of_get_gpio ( np , i );
1218
+ gpiod = devm_gpiod_get_index ( dev , NULL , i , GPIOD_ASIS );
1219
1219
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 ) {
1226
1221
if (i == GPIO_RTS || i == GPIO_DTR )
1227
- ret = gpio_direction_output ( gpio , 0 );
1222
+ ret = gpiod_direction_output ( gpiod , 0 );
1228
1223
else
1229
- ret = gpio_direction_input ( gpio );
1224
+ ret = gpiod_direction_input ( gpiod );
1230
1225
if (ret ) {
1231
1226
pr_err ("can't set direction for gpio #%d: %d\n" ,
1232
1227
i , ret );
1233
- gpio_free (gpio );
1234
1228
continue ;
1235
1229
}
1236
- pinfo -> gpios [i ] = gpio ;
1230
+ pinfo -> gpios [i ] = gpiod ;
1237
1231
}
1238
1232
}
1239
1233
0 commit comments