summaryrefslogtreecommitdiff
path: root/drivers/pinctrl/pinctrl-mcp23s08_spi.c
diff options
context:
space:
mode:
authorBiju Das <biju.das.jz@bp.renesas.com>2023-10-01 16:01:13 +0100
committerLinus Walleij <linus.walleij@linaro.org>2023-10-10 13:39:38 +0200
commit2e44555b05c0c04cf199348fbec5640f69deef8c (patch)
tree0520b2c7332320b87efb5cb582a03cb89e593929 /drivers/pinctrl/pinctrl-mcp23s08_spi.c
parentb03f7aa802b6b89165b4ad340129ef2cbac231a4 (diff)
pinctrl: mcp23s08: Simplify probe()/mcp23s08_spi_regmap_init()
Add struct mcp23s08_info and simplify probe()/mcp23s08_spi_regmap_init() by replacing match data 'type' with 'struct mcp23s08_info'. While at it, replace 'dev_err()'->'dev_err_probe()' and drop printing 'type' in error path for i2c_get_match_data(). Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Link: https://lore.kernel.org/r/20231001150113.7752-4-biju.das.jz@bp.renesas.com Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'drivers/pinctrl/pinctrl-mcp23s08_spi.c')
-rw-r--r--drivers/pinctrl/pinctrl-mcp23s08_spi.c88
1 files changed, 44 insertions, 44 deletions
diff --git a/drivers/pinctrl/pinctrl-mcp23s08_spi.c b/drivers/pinctrl/pinctrl-mcp23s08_spi.c
index caf528284d07..4a872fff5fe8 100644
--- a/drivers/pinctrl/pinctrl-mcp23s08_spi.c
+++ b/drivers/pinctrl/pinctrl-mcp23s08_spi.c
@@ -80,21 +80,18 @@ static const struct regmap_bus mcp23sxx_spi_regmap = {
};
static int mcp23s08_spi_regmap_init(struct mcp23s08 *mcp, struct device *dev,
- unsigned int addr, unsigned int type)
+ unsigned int addr,
+ const struct mcp23s08_info *info)
{
- const struct regmap_config *config;
struct regmap_config *copy;
const char *name;
- switch (type) {
+ switch (info->type) {
case MCP_TYPE_S08:
- mcp->reg_shift = 0;
- mcp->chip.ngpio = 8;
mcp->chip.label = devm_kasprintf(dev, GFP_KERNEL, "mcp23s08.%d", addr);
if (!mcp->chip.label)
return -ENOMEM;
- config = &mcp23x08_regmap;
name = devm_kasprintf(dev, GFP_KERNEL, "%d", addr);
if (!name)
return -ENOMEM;
@@ -102,13 +99,10 @@ static int mcp23s08_spi_regmap_init(struct mcp23s08 *mcp, struct device *dev,
break;
case MCP_TYPE_S17:
- mcp->reg_shift = 1;
- mcp->chip.ngpio = 16;
mcp->chip.label = devm_kasprintf(dev, GFP_KERNEL, "mcp23s17.%d", addr);
if (!mcp->chip.label)
return -ENOMEM;
- config = &mcp23x17_regmap;
name = devm_kasprintf(dev, GFP_KERNEL, "%d", addr);
if (!name)
return -ENOMEM;
@@ -116,20 +110,18 @@ static int mcp23s08_spi_regmap_init(struct mcp23s08 *mcp, struct device *dev,
break;
case MCP_TYPE_S18:
- mcp->reg_shift = 1;
- mcp->chip.ngpio = 16;
- mcp->chip.label = "mcp23s18";
-
- config = &mcp23x17_regmap;
- name = config->name;
+ mcp->chip.label = info->label;
+ name = info->regmap->name;
break;
default:
- dev_err(dev, "invalid device type (%d)\n", type);
+ dev_err(dev, "invalid device type (%d)\n", info->type);
return -EINVAL;
}
- copy = devm_kmemdup(dev, config, sizeof(*config), GFP_KERNEL);
+ mcp->reg_shift = info->reg_shift;
+ mcp->chip.ngpio = info->ngpio;
+ copy = devm_kmemdup(dev, info->regmap, sizeof(*info->regmap), GFP_KERNEL);
if (!copy)
return -ENOMEM;
@@ -144,16 +136,16 @@ static int mcp23s08_spi_regmap_init(struct mcp23s08 *mcp, struct device *dev,
static int mcp23s08_probe(struct spi_device *spi)
{
struct mcp23s08_driver_data *data;
+ const struct mcp23s08_info *info;
struct device *dev = &spi->dev;
unsigned long spi_present_mask;
unsigned int ngpio = 0;
- unsigned int type;
unsigned int addr;
int chips;
int ret;
u32 v;
- type = (uintptr_t)spi_get_device_match_data(spi);
+ info = spi_get_device_match_data(spi);
ret = device_property_read_u32(dev, "microchip,spi-present-mask", &v);
if (ret) {
@@ -182,7 +174,7 @@ static int mcp23s08_probe(struct spi_device *spi)
data->mcp[addr] = &data->chip[--chips];
data->mcp[addr]->irq = spi->irq;
- ret = mcp23s08_spi_regmap_init(data->mcp[addr], dev, addr, type);
+ ret = mcp23s08_spi_regmap_init(data->mcp[addr], dev, addr, info);
if (ret)
return ret;
@@ -192,7 +184,8 @@ static int mcp23s08_probe(struct spi_device *spi)
if (!data->mcp[addr]->pinctrl_desc.name)
return -ENOMEM;
- ret = mcp23s08_probe_one(data->mcp[addr], dev, 0x40 | (addr << 1), type, -1);
+ ret = mcp23s08_probe_one(data->mcp[addr], dev, 0x40 | (addr << 1),
+ info->type, -1);
if (ret < 0)
return ret;
@@ -203,36 +196,43 @@ static int mcp23s08_probe(struct spi_device *spi)
return 0;
}
+static const struct mcp23s08_info mcp23s08_spi = {
+ .regmap = &mcp23x08_regmap,
+ .type = MCP_TYPE_S08,
+ .ngpio = 8,
+ .reg_shift = 0,
+};
+
+static const struct mcp23s08_info mcp23s17_spi = {
+ .regmap = &mcp23x17_regmap,
+ .type = MCP_TYPE_S17,
+ .ngpio = 16,
+ .reg_shift = 1,
+};
+
+static const struct mcp23s08_info mcp23s18_spi = {
+ .regmap = &mcp23x17_regmap,
+ .label = "mcp23s18",
+ .type = MCP_TYPE_S18,
+ .ngpio = 16,
+ .reg_shift = 1,
+};
+
static const struct spi_device_id mcp23s08_ids[] = {
- { "mcp23s08", MCP_TYPE_S08 },
- { "mcp23s17", MCP_TYPE_S17 },
- { "mcp23s18", MCP_TYPE_S18 },
+ { "mcp23s08", (kernel_ulong_t)&mcp23s08_spi },
+ { "mcp23s17", (kernel_ulong_t)&mcp23s17_spi },
+ { "mcp23s18", (kernel_ulong_t)&mcp23s18_spi },
{ }
};
MODULE_DEVICE_TABLE(spi, mcp23s08_ids);
static const struct of_device_id mcp23s08_spi_of_match[] = {
- {
- .compatible = "microchip,mcp23s08",
- .data = (void *) MCP_TYPE_S08,
- },
- {
- .compatible = "microchip,mcp23s17",
- .data = (void *) MCP_TYPE_S17,
- },
- {
- .compatible = "microchip,mcp23s18",
- .data = (void *) MCP_TYPE_S18,
- },
+ { .compatible = "microchip,mcp23s08", .data = &mcp23s08_spi },
+ { .compatible = "microchip,mcp23s17", .data = &mcp23s17_spi },
+ { .compatible = "microchip,mcp23s18", .data = &mcp23s18_spi },
/* NOTE: The use of the mcp prefix is deprecated and will be removed. */
- {
- .compatible = "mcp,mcp23s08",
- .data = (void *) MCP_TYPE_S08,
- },
- {
- .compatible = "mcp,mcp23s17",
- .data = (void *) MCP_TYPE_S17,
- },
+ { .compatible = "mcp,mcp23s08", .data = &mcp23s08_spi },
+ { .compatible = "mcp,mcp23s17", .data = &mcp23s17_spi },
{ }
};
MODULE_DEVICE_TABLE(of, mcp23s08_spi_of_match);