diff options
author | Alexander Shiyan <shc_work@mail.ru> | 2014-02-10 13:18:32 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2014-02-13 12:34:47 -0500 |
commit | dba29a2894771562d265232ae4b61f0310bab1f5 (patch) | |
tree | 005e94d3ce88997382ac8c771619ace115ba749a | |
parent | d3a8a252e177cfaa2fb04120dd944104e4417bf5 (diff) |
serial: max310x: Always use dynamic GPIO ID assignment
Always register GPIOs and use dynamic GPIO ID assignment.
This is no much worth if GPIOs is not used, but helps remove
private driver header and add DT support in the future.
Additionally, patch adds missing uart_unregister_driver()
call if probe() fails.
Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | drivers/tty/serial/max310x.c | 55 | ||||
-rw-r--r-- | include/linux/platform_data/max310x.h | 3 |
2 files changed, 28 insertions, 30 deletions
diff --git a/drivers/tty/serial/max310x.c b/drivers/tty/serial/max310x.c index 310ee555fade..2a12cbcbf388 100644 --- a/drivers/tty/serial/max310x.c +++ b/drivers/tty/serial/max310x.c | |||
@@ -294,7 +294,6 @@ struct max310x_port { | |||
294 | struct mutex mutex; | 294 | struct mutex mutex; |
295 | struct clk *clk; | 295 | struct clk *clk; |
296 | struct max310x_pdata *pdata; | 296 | struct max310x_pdata *pdata; |
297 | int gpio_used; | ||
298 | #ifdef CONFIG_GPIOLIB | 297 | #ifdef CONFIG_GPIOLIB |
299 | struct gpio_chip gpio; | 298 | struct gpio_chip gpio; |
300 | #endif | 299 | #endif |
@@ -1177,6 +1176,23 @@ static int max310x_probe(struct device *dev, struct max310x_devtype *devtype, | |||
1177 | goto out_clk; | 1176 | goto out_clk; |
1178 | } | 1177 | } |
1179 | 1178 | ||
1179 | #ifdef CONFIG_GPIOLIB | ||
1180 | /* Setup GPIO cotroller */ | ||
1181 | s->gpio.owner = THIS_MODULE; | ||
1182 | s->gpio.dev = dev; | ||
1183 | s->gpio.label = dev_name(dev); | ||
1184 | s->gpio.direction_input = max310x_gpio_direction_input; | ||
1185 | s->gpio.get = max310x_gpio_get; | ||
1186 | s->gpio.direction_output= max310x_gpio_direction_output; | ||
1187 | s->gpio.set = max310x_gpio_set; | ||
1188 | s->gpio.base = -1; | ||
1189 | s->gpio.ngpio = devtype->nr * 4; | ||
1190 | s->gpio.can_sleep = 1; | ||
1191 | ret = gpiochip_add(&s->gpio); | ||
1192 | if (ret) | ||
1193 | goto out_uart; | ||
1194 | #endif | ||
1195 | |||
1180 | for (i = 0; i < devtype->nr; i++) { | 1196 | for (i = 0; i < devtype->nr; i++) { |
1181 | /* Initialize port data */ | 1197 | /* Initialize port data */ |
1182 | s->p[i].port.line = i; | 1198 | s->p[i].port.line = i; |
@@ -1208,25 +1224,6 @@ static int max310x_probe(struct device *dev, struct max310x_devtype *devtype, | |||
1208 | devtype->power(&s->p[i].port, 0); | 1224 | devtype->power(&s->p[i].port, 0); |
1209 | } | 1225 | } |
1210 | 1226 | ||
1211 | #ifdef CONFIG_GPIOLIB | ||
1212 | /* Setup GPIO cotroller */ | ||
1213 | if (s->pdata->gpio_base) { | ||
1214 | s->gpio.owner = THIS_MODULE; | ||
1215 | s->gpio.dev = dev; | ||
1216 | s->gpio.label = dev_name(dev); | ||
1217 | s->gpio.direction_input = max310x_gpio_direction_input; | ||
1218 | s->gpio.get = max310x_gpio_get; | ||
1219 | s->gpio.direction_output= max310x_gpio_direction_output; | ||
1220 | s->gpio.set = max310x_gpio_set; | ||
1221 | s->gpio.base = s->pdata->gpio_base; | ||
1222 | s->gpio.ngpio = devtype->nr * 4; | ||
1223 | s->gpio.can_sleep = 1; | ||
1224 | if (!gpiochip_add(&s->gpio)) | ||
1225 | s->gpio_used = 1; | ||
1226 | } else | ||
1227 | dev_info(dev, "GPIO support not enabled\n"); | ||
1228 | #endif | ||
1229 | |||
1230 | /* Setup interrupt */ | 1227 | /* Setup interrupt */ |
1231 | ret = devm_request_threaded_irq(dev, irq, NULL, max310x_ist, | 1228 | ret = devm_request_threaded_irq(dev, irq, NULL, max310x_ist, |
1232 | IRQF_TRIGGER_FALLING | IRQF_ONESHOT, | 1229 | IRQF_TRIGGER_FALLING | IRQF_ONESHOT, |
@@ -1235,11 +1232,14 @@ static int max310x_probe(struct device *dev, struct max310x_devtype *devtype, | |||
1235 | return 0; | 1232 | return 0; |
1236 | 1233 | ||
1237 | dev_err(dev, "Unable to reguest IRQ %i\n", irq); | 1234 | dev_err(dev, "Unable to reguest IRQ %i\n", irq); |
1235 | |||
1238 | #ifdef CONFIG_GPIOLIB | 1236 | #ifdef CONFIG_GPIOLIB |
1239 | if (s->gpio_used) | 1237 | WARN_ON(gpiochip_remove(&s->gpio)); |
1240 | WARN_ON(gpiochip_remove(&s->gpio)); | ||
1241 | #endif | 1238 | #endif |
1242 | 1239 | ||
1240 | out_uart: | ||
1241 | uart_unregister_driver(&s->uart); | ||
1242 | |||
1243 | out_clk: | 1243 | out_clk: |
1244 | clk_disable_unprepare(s->clk); | 1244 | clk_disable_unprepare(s->clk); |
1245 | 1245 | ||
@@ -1251,6 +1251,12 @@ static int max310x_remove(struct device *dev) | |||
1251 | struct max310x_port *s = dev_get_drvdata(dev); | 1251 | struct max310x_port *s = dev_get_drvdata(dev); |
1252 | int i, ret = 0; | 1252 | int i, ret = 0; |
1253 | 1253 | ||
1254 | #ifdef CONFIG_GPIOLIB | ||
1255 | ret = gpiochip_remove(&s->gpio); | ||
1256 | if (ret) | ||
1257 | return ret; | ||
1258 | #endif | ||
1259 | |||
1254 | for (i = 0; i < s->uart.nr; i++) { | 1260 | for (i = 0; i < s->uart.nr; i++) { |
1255 | cancel_work_sync(&s->p[i].tx_work); | 1261 | cancel_work_sync(&s->p[i].tx_work); |
1256 | cancel_work_sync(&s->p[i].md_work); | 1262 | cancel_work_sync(&s->p[i].md_work); |
@@ -1261,11 +1267,6 @@ static int max310x_remove(struct device *dev) | |||
1261 | uart_unregister_driver(&s->uart); | 1267 | uart_unregister_driver(&s->uart); |
1262 | clk_disable_unprepare(s->clk); | 1268 | clk_disable_unprepare(s->clk); |
1263 | 1269 | ||
1264 | #ifdef CONFIG_GPIOLIB | ||
1265 | if (s->gpio_used) | ||
1266 | ret = gpiochip_remove(&s->gpio); | ||
1267 | #endif | ||
1268 | |||
1269 | return ret; | 1270 | return ret; |
1270 | } | 1271 | } |
1271 | 1272 | ||
diff --git a/include/linux/platform_data/max310x.h b/include/linux/platform_data/max310x.h index 57a0cd46b847..1140a57e735f 100644 --- a/include/linux/platform_data/max310x.h +++ b/include/linux/platform_data/max310x.h | |||
@@ -21,7 +21,6 @@ | |||
21 | * | 21 | * |
22 | * static struct max310x_pdata max3107_pdata = { | 22 | * static struct max310x_pdata max3107_pdata = { |
23 | * .uart_flags[0] = MAX310X_ECHO_SUPRESS | MAX310X_AUTO_DIR_CTRL, | 23 | * .uart_flags[0] = MAX310X_ECHO_SUPRESS | MAX310X_AUTO_DIR_CTRL, |
24 | * .gpio_base = -1, | ||
25 | * }; | 24 | * }; |
26 | * | 25 | * |
27 | * static struct spi_board_info spi_device_max3107[] = { | 26 | * static struct spi_board_info spi_device_max3107[] = { |
@@ -45,8 +44,6 @@ struct max310x_pdata { | |||
45 | #define MAX310X_AUTO_DIR_CTRL (0x00000004) /* Enable Auto direction | 44 | #define MAX310X_AUTO_DIR_CTRL (0x00000004) /* Enable Auto direction |
46 | * control (RS-485) | 45 | * control (RS-485) |
47 | */ | 46 | */ |
48 | /* GPIO base number (can be negative) */ | ||
49 | const int gpio_base; | ||
50 | }; | 47 | }; |
51 | 48 | ||
52 | #endif | 49 | #endif |