serial: sc16is7xx: split into core and I2C/SPI parts (sc16is7xx_regcfg)
authorHugo Villeneuve <hvilleneuve@dimonoff.com>
Tue, 9 Apr 2024 15:42:53 +0000 (11:42 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 11 Apr 2024 12:08:08 +0000 (14:08 +0200)
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>
drivers/tty/serial/sc16is7xx.c
drivers/tty/serial/sc16is7xx.h
drivers/tty/serial/sc16is7xx_i2c.c
drivers/tty/serial/sc16is7xx_spi.c

index 9c9673243c4cb81c1e055645ebefedf358a0e36d..03cf30e20b75dfe2d518539944a8817b47ac295c 100644 (file)
@@ -1695,7 +1695,7 @@ const struct of_device_id __maybe_unused sc16is7xx_dt_ids[] = {
 EXPORT_SYMBOL_GPL(sc16is7xx_dt_ids);
 MODULE_DEVICE_TABLE(of, sc16is7xx_dt_ids);
 
-struct regmap_config sc16is7xx_regcfg = {
+const struct regmap_config sc16is7xx_regcfg = {
        .reg_bits = 5,
        .pad_bits = 3,
        .val_bits = 8,
index 2ee3ce83d95a4a503f9b86ddb35327f51c8918e6..afb784eaee45bcabeb85c4a9cc17073ffc03ba06 100644 (file)
@@ -19,7 +19,7 @@ struct sc16is7xx_devtype {
        int     nr_uart;
 };
 
-extern struct regmap_config sc16is7xx_regcfg;
+extern const struct regmap_config sc16is7xx_regcfg;
 
 extern const struct of_device_id sc16is7xx_dt_ids[];
 
index de51d1675abfd9e51522fd4ed94de3a177ec6087..3ed47c306d855711ddf1bcede4786b23bd45501a 100644 (file)
@@ -14,17 +14,20 @@ static int sc16is7xx_i2c_probe(struct i2c_client *i2c)
 {
        const struct sc16is7xx_devtype *devtype;
        struct regmap *regmaps[SC16IS7XX_MAX_PORTS];
+       struct regmap_config regcfg;
        unsigned int i;
 
        devtype = i2c_get_match_data(i2c);
        if (!devtype)
                return dev_err_probe(&i2c->dev, -ENODEV, "Failed to match device\n");
 
+       memcpy(&regcfg, &sc16is7xx_regcfg, sizeof(struct regmap_config));
+
        for (i = 0; i < devtype->nr_uart; i++) {
-               sc16is7xx_regcfg.name = sc16is7xx_regmap_name(i);
-               sc16is7xx_regcfg.read_flag_mask = sc16is7xx_regmap_port_mask(i);
-               sc16is7xx_regcfg.write_flag_mask = sc16is7xx_regmap_port_mask(i);
-               regmaps[i] = devm_regmap_init_i2c(i2c, &sc16is7xx_regcfg);
+               regcfg.name = sc16is7xx_regmap_name(i);
+               regcfg.read_flag_mask = sc16is7xx_regmap_port_mask(i);
+               regcfg.write_flag_mask = sc16is7xx_regmap_port_mask(i);
+               regmaps[i] = devm_regmap_init_i2c(i2c, &regcfg);
        }
 
        return sc16is7xx_probe(&i2c->dev, devtype, regmaps, i2c->irq);
index f110c4e6dce6329667a77ec0e8f1d46610a49b01..73df36f8a7fd8604d12704fd60827288b0e0b356 100644 (file)
@@ -18,6 +18,7 @@ static int sc16is7xx_spi_probe(struct spi_device *spi)
 {
        const struct sc16is7xx_devtype *devtype;
        struct regmap *regmaps[SC16IS7XX_MAX_PORTS];
+       struct regmap_config regcfg;
        unsigned int i;
        int ret;
 
@@ -37,17 +38,19 @@ static int sc16is7xx_spi_probe(struct spi_device *spi)
        if (!devtype)
                return dev_err_probe(&spi->dev, -ENODEV, "Failed to match device\n");
 
+       memcpy(&regcfg, &sc16is7xx_regcfg, sizeof(struct regmap_config));
+
        for (i = 0; i < devtype->nr_uart; i++) {
-               sc16is7xx_regcfg.name = sc16is7xx_regmap_name(i);
+               regcfg.name = sc16is7xx_regmap_name(i);
                /*
                 * If read_flag_mask is 0, the regmap code sets it to a default
                 * of 0x80. Since we specify our own mask, we must add the READ
                 * bit ourselves:
                 */
-               sc16is7xx_regcfg.read_flag_mask = sc16is7xx_regmap_port_mask(i) |
+               regcfg.read_flag_mask = sc16is7xx_regmap_port_mask(i) |
                        SC16IS7XX_SPI_READ_BIT;
-               sc16is7xx_regcfg.write_flag_mask = sc16is7xx_regmap_port_mask(i);
-               regmaps[i] = devm_regmap_init_spi(spi, &sc16is7xx_regcfg);
+               regcfg.write_flag_mask = sc16is7xx_regmap_port_mask(i);
+               regmaps[i] = devm_regmap_init_spi(spi, &regcfg);
        }
 
        return sc16is7xx_probe(&spi->dev, devtype, regmaps, spi->irq);