Commit 48d4a801 authored by Hugo Villeneuve's avatar Hugo Villeneuve Committed by Greg Kroah-Hartman

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: default avatarHugo Villeneuve <hvilleneuve@dimonoff.com>
Reviewed-by: default avatarAndy Shevchenko <andy@kernel.org>
Link: https://lore.kernel.org/r/20240409154253.3043822-6-hugo@hugovil.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent cf9c3753
...@@ -1695,7 +1695,7 @@ const struct of_device_id __maybe_unused sc16is7xx_dt_ids[] = { ...@@ -1695,7 +1695,7 @@ const struct of_device_id __maybe_unused sc16is7xx_dt_ids[] = {
EXPORT_SYMBOL_GPL(sc16is7xx_dt_ids); EXPORT_SYMBOL_GPL(sc16is7xx_dt_ids);
MODULE_DEVICE_TABLE(of, sc16is7xx_dt_ids); MODULE_DEVICE_TABLE(of, sc16is7xx_dt_ids);
struct regmap_config sc16is7xx_regcfg = { const struct regmap_config sc16is7xx_regcfg = {
.reg_bits = 5, .reg_bits = 5,
.pad_bits = 3, .pad_bits = 3,
.val_bits = 8, .val_bits = 8,
......
...@@ -19,7 +19,7 @@ struct sc16is7xx_devtype { ...@@ -19,7 +19,7 @@ struct sc16is7xx_devtype {
int nr_uart; 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[]; extern const struct of_device_id sc16is7xx_dt_ids[];
......
...@@ -14,17 +14,20 @@ static int sc16is7xx_i2c_probe(struct i2c_client *i2c) ...@@ -14,17 +14,20 @@ static int sc16is7xx_i2c_probe(struct i2c_client *i2c)
{ {
const struct sc16is7xx_devtype *devtype; const struct sc16is7xx_devtype *devtype;
struct regmap *regmaps[SC16IS7XX_MAX_PORTS]; struct regmap *regmaps[SC16IS7XX_MAX_PORTS];
struct regmap_config regcfg;
unsigned int i; unsigned int i;
devtype = i2c_get_match_data(i2c); devtype = i2c_get_match_data(i2c);
if (!devtype) if (!devtype)
return dev_err_probe(&i2c->dev, -ENODEV, "Failed to match device\n"); 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++) { for (i = 0; i < devtype->nr_uart; i++) {
sc16is7xx_regcfg.name = sc16is7xx_regmap_name(i); regcfg.name = sc16is7xx_regmap_name(i);
sc16is7xx_regcfg.read_flag_mask = sc16is7xx_regmap_port_mask(i); regcfg.read_flag_mask = sc16is7xx_regmap_port_mask(i);
sc16is7xx_regcfg.write_flag_mask = sc16is7xx_regmap_port_mask(i); regcfg.write_flag_mask = sc16is7xx_regmap_port_mask(i);
regmaps[i] = devm_regmap_init_i2c(i2c, &sc16is7xx_regcfg); regmaps[i] = devm_regmap_init_i2c(i2c, &regcfg);
} }
return sc16is7xx_probe(&i2c->dev, devtype, regmaps, i2c->irq); return sc16is7xx_probe(&i2c->dev, devtype, regmaps, i2c->irq);
......
...@@ -18,6 +18,7 @@ static int sc16is7xx_spi_probe(struct spi_device *spi) ...@@ -18,6 +18,7 @@ static int sc16is7xx_spi_probe(struct spi_device *spi)
{ {
const struct sc16is7xx_devtype *devtype; const struct sc16is7xx_devtype *devtype;
struct regmap *regmaps[SC16IS7XX_MAX_PORTS]; struct regmap *regmaps[SC16IS7XX_MAX_PORTS];
struct regmap_config regcfg;
unsigned int i; unsigned int i;
int ret; int ret;
...@@ -37,17 +38,19 @@ static int sc16is7xx_spi_probe(struct spi_device *spi) ...@@ -37,17 +38,19 @@ static int sc16is7xx_spi_probe(struct spi_device *spi)
if (!devtype) if (!devtype)
return dev_err_probe(&spi->dev, -ENODEV, "Failed to match device\n"); 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++) { 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 * 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 * of 0x80. Since we specify our own mask, we must add the READ
* bit ourselves: * 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_SPI_READ_BIT;
sc16is7xx_regcfg.write_flag_mask = sc16is7xx_regmap_port_mask(i); regcfg.write_flag_mask = sc16is7xx_regmap_port_mask(i);
regmaps[i] = devm_regmap_init_spi(spi, &sc16is7xx_regcfg); regmaps[i] = devm_regmap_init_spi(spi, &regcfg);
} }
return sc16is7xx_probe(&spi->dev, devtype, regmaps, spi->irq); return sc16is7xx_probe(&spi->dev, devtype, regmaps, spi->irq);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment