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
9897static 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