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

serial: sc16is7xx: split into core and I2C/SPI parts (sc16is7xx_regcfg)

Since each I2C/SPI probe function can modify sc16is7xx_regcfg at the same
time, change structure to be constant and do the required modifications on
a local copy.

Signed-off-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
Reviewed-by: Andy Shevchenko <andy@kernel.org>
Link: https://lore.kernel.org/r/20240409154253.3043822-6-hugo@hugovil.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Hugo Villeneuve and committed by
Greg Kroah-Hartman
48d4a801 cf9c3753

+16 -10
+1 -1
drivers/tty/serial/sc16is7xx.c
··· 1695 1695 EXPORT_SYMBOL_GPL(sc16is7xx_dt_ids); 1696 1696 MODULE_DEVICE_TABLE(of, sc16is7xx_dt_ids); 1697 1697 1698 - struct regmap_config sc16is7xx_regcfg = { 1698 + const struct regmap_config sc16is7xx_regcfg = { 1699 1699 .reg_bits = 5, 1700 1700 .pad_bits = 3, 1701 1701 .val_bits = 8,
+1 -1
drivers/tty/serial/sc16is7xx.h
··· 19 19 int nr_uart; 20 20 }; 21 21 22 - extern struct regmap_config sc16is7xx_regcfg; 22 + extern const struct regmap_config sc16is7xx_regcfg; 23 23 24 24 extern const struct of_device_id sc16is7xx_dt_ids[]; 25 25
+7 -4
drivers/tty/serial/sc16is7xx_i2c.c
··· 14 14 { 15 15 const struct sc16is7xx_devtype *devtype; 16 16 struct regmap *regmaps[SC16IS7XX_MAX_PORTS]; 17 + struct regmap_config regcfg; 17 18 unsigned int i; 18 19 19 20 devtype = i2c_get_match_data(i2c); 20 21 if (!devtype) 21 22 return dev_err_probe(&i2c->dev, -ENODEV, "Failed to match device\n"); 22 23 24 + memcpy(&regcfg, &sc16is7xx_regcfg, sizeof(struct regmap_config)); 25 + 23 26 for (i = 0; i < devtype->nr_uart; i++) { 24 - sc16is7xx_regcfg.name = sc16is7xx_regmap_name(i); 25 - sc16is7xx_regcfg.read_flag_mask = sc16is7xx_regmap_port_mask(i); 26 - sc16is7xx_regcfg.write_flag_mask = sc16is7xx_regmap_port_mask(i); 27 - regmaps[i] = devm_regmap_init_i2c(i2c, &sc16is7xx_regcfg); 27 + regcfg.name = sc16is7xx_regmap_name(i); 28 + regcfg.read_flag_mask = sc16is7xx_regmap_port_mask(i); 29 + regcfg.write_flag_mask = sc16is7xx_regmap_port_mask(i); 30 + regmaps[i] = devm_regmap_init_i2c(i2c, &regcfg); 28 31 } 29 32 30 33 return sc16is7xx_probe(&i2c->dev, devtype, regmaps, i2c->irq);
+7 -4
drivers/tty/serial/sc16is7xx_spi.c
··· 18 18 { 19 19 const struct sc16is7xx_devtype *devtype; 20 20 struct regmap *regmaps[SC16IS7XX_MAX_PORTS]; 21 + struct regmap_config regcfg; 21 22 unsigned int i; 22 23 int ret; 23 24 ··· 38 37 if (!devtype) 39 38 return dev_err_probe(&spi->dev, -ENODEV, "Failed to match device\n"); 40 39 40 + memcpy(&regcfg, &sc16is7xx_regcfg, sizeof(struct regmap_config)); 41 + 41 42 for (i = 0; i < devtype->nr_uart; i++) { 42 - sc16is7xx_regcfg.name = sc16is7xx_regmap_name(i); 43 + regcfg.name = sc16is7xx_regmap_name(i); 43 44 /* 44 45 * If read_flag_mask is 0, the regmap code sets it to a default 45 46 * of 0x80. Since we specify our own mask, we must add the READ 46 47 * bit ourselves: 47 48 */ 48 - sc16is7xx_regcfg.read_flag_mask = sc16is7xx_regmap_port_mask(i) | 49 + regcfg.read_flag_mask = sc16is7xx_regmap_port_mask(i) | 49 50 SC16IS7XX_SPI_READ_BIT; 50 - sc16is7xx_regcfg.write_flag_mask = sc16is7xx_regmap_port_mask(i); 51 - regmaps[i] = devm_regmap_init_spi(spi, &sc16is7xx_regcfg); 51 + regcfg.write_flag_mask = sc16is7xx_regmap_port_mask(i); 52 + regmaps[i] = devm_regmap_init_spi(spi, &regcfg); 52 53 } 53 54 54 55 return sc16is7xx_probe(&spi->dev, devtype, regmaps, spi->irq);