.. | .. |
---|
1170 | 1170 | state |= BIT(offset); |
---|
1171 | 1171 | else |
---|
1172 | 1172 | state &= ~BIT(offset); |
---|
1173 | | - sc16is7xx_port_write(port, SC16IS7XX_IOSTATE_REG, state); |
---|
| 1173 | + |
---|
| 1174 | + /* |
---|
| 1175 | + * If we write IOSTATE first, and then IODIR, the output value is not |
---|
| 1176 | + * transferred to the corresponding I/O pin. |
---|
| 1177 | + * The datasheet states that each register bit will be transferred to |
---|
| 1178 | + * the corresponding I/O pin programmed as output when writing to |
---|
| 1179 | + * IOSTATE. Therefore, configure direction first with IODIR, and then |
---|
| 1180 | + * set value after with IOSTATE. |
---|
| 1181 | + */ |
---|
1174 | 1182 | sc16is7xx_port_update(port, SC16IS7XX_IODIR_REG, BIT(offset), |
---|
1175 | 1183 | BIT(offset)); |
---|
| 1184 | + sc16is7xx_port_write(port, SC16IS7XX_IOSTATE_REG, state); |
---|
1176 | 1185 | |
---|
1177 | 1186 | return 0; |
---|
1178 | 1187 | } |
---|
.. | .. |
---|
1243 | 1252 | } |
---|
1244 | 1253 | sched_set_fifo(s->kworker_task); |
---|
1245 | 1254 | |
---|
1246 | | -#ifdef CONFIG_GPIOLIB |
---|
1247 | | - if (devtype->nr_gpio) { |
---|
1248 | | - /* Setup GPIO cotroller */ |
---|
1249 | | - s->gpio.owner = THIS_MODULE; |
---|
1250 | | - s->gpio.parent = dev; |
---|
1251 | | - s->gpio.label = dev_name(dev); |
---|
1252 | | - s->gpio.direction_input = sc16is7xx_gpio_direction_input; |
---|
1253 | | - s->gpio.get = sc16is7xx_gpio_get; |
---|
1254 | | - s->gpio.direction_output = sc16is7xx_gpio_direction_output; |
---|
1255 | | - s->gpio.set = sc16is7xx_gpio_set; |
---|
1256 | | - s->gpio.base = -1; |
---|
1257 | | - s->gpio.ngpio = devtype->nr_gpio; |
---|
1258 | | - s->gpio.can_sleep = 1; |
---|
1259 | | - ret = gpiochip_add_data(&s->gpio, s); |
---|
1260 | | - if (ret) |
---|
1261 | | - goto out_thread; |
---|
1262 | | - } |
---|
1263 | | -#endif |
---|
1264 | | - |
---|
1265 | 1255 | /* reset device, purging any pending irq / data */ |
---|
1266 | 1256 | regmap_write(s->regmap, SC16IS7XX_IOCONTROL_REG << SC16IS7XX_REG_SHIFT, |
---|
1267 | 1257 | SC16IS7XX_IOCONTROL_SRESET_BIT); |
---|
.. | .. |
---|
1275 | 1265 | s->p[i].port.fifosize = SC16IS7XX_FIFO_SIZE; |
---|
1276 | 1266 | s->p[i].port.flags = UPF_FIXED_TYPE | UPF_LOW_LATENCY; |
---|
1277 | 1267 | s->p[i].port.iobase = i; |
---|
| 1268 | + /* |
---|
| 1269 | + * Use all ones as membase to make sure uart_configure_port() in |
---|
| 1270 | + * serial_core.c does not abort for SPI/I2C devices where the |
---|
| 1271 | + * membase address is not applicable. |
---|
| 1272 | + */ |
---|
| 1273 | + s->p[i].port.membase = (void __iomem *)~0; |
---|
1278 | 1274 | s->p[i].port.iotype = UPIO_PORT; |
---|
1279 | 1275 | s->p[i].port.uartclk = freq; |
---|
1280 | 1276 | s->p[i].port.rs485_config = sc16is7xx_config_rs485; |
---|
.. | .. |
---|
1327 | 1323 | s->p[u].irda_mode = true; |
---|
1328 | 1324 | } |
---|
1329 | 1325 | |
---|
| 1326 | +#ifdef CONFIG_GPIOLIB |
---|
| 1327 | + if (devtype->nr_gpio) { |
---|
| 1328 | + /* Setup GPIO cotroller */ |
---|
| 1329 | + s->gpio.owner = THIS_MODULE; |
---|
| 1330 | + s->gpio.parent = dev; |
---|
| 1331 | + s->gpio.label = dev_name(dev); |
---|
| 1332 | + s->gpio.direction_input = sc16is7xx_gpio_direction_input; |
---|
| 1333 | + s->gpio.get = sc16is7xx_gpio_get; |
---|
| 1334 | + s->gpio.direction_output = sc16is7xx_gpio_direction_output; |
---|
| 1335 | + s->gpio.set = sc16is7xx_gpio_set; |
---|
| 1336 | + s->gpio.base = -1; |
---|
| 1337 | + s->gpio.ngpio = devtype->nr_gpio; |
---|
| 1338 | + s->gpio.can_sleep = 1; |
---|
| 1339 | + ret = gpiochip_add_data(&s->gpio, s); |
---|
| 1340 | + if (ret) |
---|
| 1341 | + goto out_thread; |
---|
| 1342 | + } |
---|
| 1343 | +#endif |
---|
| 1344 | + |
---|
1330 | 1345 | /* |
---|
1331 | 1346 | * Setup interrupt. We first try to acquire the IRQ line as level IRQ. |
---|
1332 | 1347 | * If that succeeds, we can allow sharing the interrupt as well. |
---|
.. | .. |
---|
1346 | 1361 | if (!ret) |
---|
1347 | 1362 | return 0; |
---|
1348 | 1363 | |
---|
1349 | | -out_ports: |
---|
1350 | | - for (i--; i >= 0; i--) { |
---|
1351 | | - uart_remove_one_port(&sc16is7xx_uart, &s->p[i].port); |
---|
1352 | | - clear_bit(s->p[i].port.line, &sc16is7xx_lines); |
---|
1353 | | - } |
---|
1354 | | - |
---|
1355 | 1364 | #ifdef CONFIG_GPIOLIB |
---|
1356 | 1365 | if (devtype->nr_gpio) |
---|
1357 | 1366 | gpiochip_remove(&s->gpio); |
---|
1358 | 1367 | |
---|
1359 | 1368 | out_thread: |
---|
1360 | 1369 | #endif |
---|
| 1370 | + |
---|
| 1371 | +out_ports: |
---|
| 1372 | + for (i--; i >= 0; i--) { |
---|
| 1373 | + uart_remove_one_port(&sc16is7xx_uart, &s->p[i].port); |
---|
| 1374 | + clear_bit(s->p[i].port.line, &sc16is7xx_lines); |
---|
| 1375 | + } |
---|
| 1376 | + |
---|
1361 | 1377 | kthread_stop(s->kworker_task); |
---|
1362 | 1378 | |
---|
1363 | 1379 | out_clk: |
---|