Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

serial: sc16is7xx: move port/channel init to separate function

The sc16is7xx_probe() function is very long. To improve readability, move
port/channel initialization to a separate function.

No functional change intended.

Signed-off-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
Link: https://patch.msgid.link/20251027142957.1032073-9-hugo@hugovil.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Hugo Villeneuve and committed by
Greg Kroah-Hartman
a5bb1465 983f91e5

+70 -57
+70 -57
drivers/tty/serial/sc16is7xx.c
··· 1499 1499 return 0; 1500 1500 } 1501 1501 1502 + static int sc16is7xx_setup_channel(struct sc16is7xx_one *one, int i, 1503 + bool *port_registered) 1504 + { 1505 + struct uart_port *port = &one->port; 1506 + int ret; 1507 + 1508 + ret = ida_alloc_max(&sc16is7xx_lines, SC16IS7XX_MAX_DEVS - 1, GFP_KERNEL); 1509 + if (ret < 0) 1510 + return ret; 1511 + 1512 + port->line = ret; 1513 + 1514 + /* Initialize port data */ 1515 + port->type = PORT_SC16IS7XX; 1516 + port->fifosize = SC16IS7XX_FIFO_SIZE; 1517 + port->flags = UPF_FIXED_TYPE | UPF_LOW_LATENCY; 1518 + port->iobase = i; 1519 + /* 1520 + * Use all ones as membase to make sure uart_configure_port() in 1521 + * serial_core.c does not abort for SPI/I2C devices where the 1522 + * membase address is not applicable. 1523 + */ 1524 + port->membase = (void __iomem *)~0; 1525 + port->iotype = UPIO_PORT; 1526 + port->rs485_config = sc16is7xx_config_rs485; 1527 + port->rs485_supported = sc16is7xx_rs485_supported; 1528 + port->ops = &sc16is7xx_ops; 1529 + one->old_mctrl = 0; 1530 + 1531 + mutex_init(&one->lock); 1532 + 1533 + ret = uart_get_rs485_mode(port); 1534 + if (ret) 1535 + return ret; 1536 + 1537 + /* Enable access to general register set */ 1538 + sc16is7xx_port_write(port, SC16IS7XX_LCR_REG, 0x00); 1539 + 1540 + /* Disable all interrupts */ 1541 + sc16is7xx_port_write(port, SC16IS7XX_IER_REG, 0); 1542 + /* Disable TX/RX */ 1543 + sc16is7xx_port_write(port, SC16IS7XX_EFCR_REG, 1544 + SC16IS7XX_EFCR_RXDISABLE_BIT | 1545 + SC16IS7XX_EFCR_TXDISABLE_BIT); 1546 + 1547 + /* Initialize kthread work structs */ 1548 + kthread_init_work(&one->tx_work, sc16is7xx_tx_proc); 1549 + kthread_init_work(&one->reg_work, sc16is7xx_reg_proc); 1550 + kthread_init_delayed_work(&one->ms_work, sc16is7xx_ms_proc); 1551 + 1552 + /* Register port */ 1553 + ret = uart_add_one_port(&sc16is7xx_uart, port); 1554 + if (ret) 1555 + return ret; 1556 + 1557 + *port_registered = true; 1558 + 1559 + sc16is7xx_regs_lock(port, SC16IS7XX_LCR_REG_SET_ENHANCED); 1560 + /* Enable write access to enhanced features */ 1561 + sc16is7xx_port_write(port, SC16IS7XX_EFR_REG, 1562 + SC16IS7XX_EFR_ENABLE_BIT); 1563 + sc16is7xx_regs_unlock(port); 1564 + 1565 + /* Go to suspend mode */ 1566 + sc16is7xx_power(port, 0); 1567 + 1568 + return 0; 1569 + } 1570 + 1502 1571 int sc16is7xx_probe(struct device *dev, const struct sc16is7xx_devtype *devtype, 1503 1572 struct regmap *regmaps[], int irq) 1504 1573 { ··· 1651 1582 } 1652 1583 1653 1584 for (i = 0; i < devtype->nr_uart; ++i) { 1654 - ret = ida_alloc_max(&sc16is7xx_lines, 1655 - SC16IS7XX_MAX_DEVS - 1, GFP_KERNEL); 1656 - if (ret < 0) 1657 - goto out_ports; 1658 - 1659 - s->p[i].port.line = ret; 1660 - 1661 - /* Initialize port data */ 1662 1585 s->p[i].port.dev = dev; 1663 1586 s->p[i].port.irq = irq; 1664 - s->p[i].port.type = PORT_SC16IS7XX; 1665 - s->p[i].port.fifosize = SC16IS7XX_FIFO_SIZE; 1666 - s->p[i].port.flags = UPF_FIXED_TYPE | UPF_LOW_LATENCY; 1667 - s->p[i].port.iobase = i; 1668 - /* 1669 - * Use all ones as membase to make sure uart_configure_port() in 1670 - * serial_core.c does not abort for SPI/I2C devices where the 1671 - * membase address is not applicable. 1672 - */ 1673 - s->p[i].port.membase = (void __iomem *)~0; 1674 - s->p[i].port.iotype = UPIO_PORT; 1675 1587 s->p[i].port.uartclk = freq; 1676 - s->p[i].port.rs485_config = sc16is7xx_config_rs485; 1677 - s->p[i].port.rs485_supported = sc16is7xx_rs485_supported; 1678 - s->p[i].port.ops = &sc16is7xx_ops; 1679 - s->p[i].old_mctrl = 0; 1680 1588 s->p[i].regmap = regmaps[i]; 1681 1589 1682 - mutex_init(&s->p[i].lock); 1683 - 1684 - ret = uart_get_rs485_mode(&s->p[i].port); 1590 + ret = sc16is7xx_setup_channel(&s->p[i], i, &port_registered[i]); 1685 1591 if (ret) 1686 1592 goto out_ports; 1687 - 1688 - /* Enable access to general register set */ 1689 - sc16is7xx_port_write(&s->p[i].port, SC16IS7XX_LCR_REG, 0x00); 1690 - 1691 - /* Disable all interrupts */ 1692 - sc16is7xx_port_write(&s->p[i].port, SC16IS7XX_IER_REG, 0); 1693 - /* Disable TX/RX */ 1694 - sc16is7xx_port_write(&s->p[i].port, SC16IS7XX_EFCR_REG, 1695 - SC16IS7XX_EFCR_RXDISABLE_BIT | 1696 - SC16IS7XX_EFCR_TXDISABLE_BIT); 1697 - 1698 - /* Initialize kthread work structs */ 1699 - kthread_init_work(&s->p[i].tx_work, sc16is7xx_tx_proc); 1700 - kthread_init_work(&s->p[i].reg_work, sc16is7xx_reg_proc); 1701 - kthread_init_delayed_work(&s->p[i].ms_work, sc16is7xx_ms_proc); 1702 - 1703 - /* Register port */ 1704 - ret = uart_add_one_port(&sc16is7xx_uart, &s->p[i].port); 1705 - if (ret) 1706 - goto out_ports; 1707 - 1708 - port_registered[i] = true; 1709 - 1710 - sc16is7xx_regs_lock(&s->p[i].port, SC16IS7XX_LCR_REG_SET_ENHANCED); 1711 - /* Enable write access to enhanced features */ 1712 - sc16is7xx_port_write(&s->p[i].port, SC16IS7XX_EFR_REG, 1713 - SC16IS7XX_EFR_ENABLE_BIT); 1714 - sc16is7xx_regs_unlock(&s->p[i].port); 1715 - 1716 - /* Go to suspend mode */ 1717 - sc16is7xx_power(&s->p[i].port, 0); 1718 1593 } 1719 1594 1720 1595 sc16is7xx_setup_irda_ports(s);