From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Linus Walleij <linus.walleij@linaro.org>, linux-gpio@vger.kernel.org
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Subject: [PATCH v1 5/9] pinctrl: mcp23s08: Refactor mcp23s08_spi_regmap_init()
Date: Tue, 7 Apr 2020 20:38:45 +0300 [thread overview]
Message-ID: <20200407173849.43628-5-andriy.shevchenko@linux.intel.com> (raw)
In-Reply-To: <20200407173849.43628-1-andriy.shevchenko@linux.intel.com>
There is a lot of duplication for one small helper function.
Refactor mcp23s08_spi_regmap_init() to prepare everything first
and then register regmap at the end.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/pinctrl/pinctrl-mcp23s08.c | 61 ++++++++++++++----------------
1 file changed, 28 insertions(+), 33 deletions(-)
diff --git a/drivers/pinctrl/pinctrl-mcp23s08.c b/drivers/pinctrl/pinctrl-mcp23s08.c
index 513864c74860..07b69242a5b3 100644
--- a/drivers/pinctrl/pinctrl-mcp23s08.c
+++ b/drivers/pinctrl/pinctrl-mcp23s08.c
@@ -888,50 +888,38 @@ struct mcp23s08_driver_data {
static int mcp23s08_spi_regmap_init(struct mcp23s08 *mcp, struct device *dev,
unsigned int addr, unsigned int type)
{
- struct regmap_config *one_regmap_config = NULL;
+ const struct regmap_config *config;
+ struct regmap_config *copy;
+ const char *name;
switch (type) {
case MCP_TYPE_S08:
+ mcp->reg_shift = 0;
+ mcp->chip.ngpio = 8;
+ mcp->chip.label = devm_kasprintf(dev, GFP_KERNEL, "mcp23s08.%d",
+ addr);
+
+ config = &mcp23x08_regmap;
+ name = devm_kasprintf(dev, GFP_KERNEL, "%d", addr);
+ break;
+
case MCP_TYPE_S17:
- switch (type) {
- case MCP_TYPE_S08:
- one_regmap_config =
- devm_kmemdup(dev, &mcp23x08_regmap,
- sizeof(struct regmap_config), GFP_KERNEL);
- mcp->reg_shift = 0;
- mcp->chip.ngpio = 8;
- mcp->chip.label = devm_kasprintf(dev, GFP_KERNEL,
- "mcp23s08.%d", addr);
- break;
- case MCP_TYPE_S17:
- one_regmap_config =
- devm_kmemdup(dev, &mcp23x17_regmap,
- sizeof(struct regmap_config), GFP_KERNEL);
- mcp->reg_shift = 1;
- mcp->chip.ngpio = 16;
- mcp->chip.label = devm_kasprintf(dev, GFP_KERNEL,
- "mcp23s17.%d", addr);
- break;
- }
- if (!one_regmap_config)
- return -ENOMEM;
+ mcp->reg_shift = 1;
+ mcp->chip.ngpio = 16;
+ mcp->chip.label = devm_kasprintf(dev, GFP_KERNEL, "mcp23s17.%d",
+ addr);
- one_regmap_config->name = devm_kasprintf(dev, GFP_KERNEL, "%d", addr);
- mcp->regmap = devm_regmap_init(dev, &mcp23sxx_spi_regmap, mcp,
- one_regmap_config);
+ config = &mcp23x17_regmap;
+ name = devm_kasprintf(dev, GFP_KERNEL, "%d", addr);
break;
case MCP_TYPE_S18:
- one_regmap_config =
- devm_kmemdup(dev, &mcp23x17_regmap,
- sizeof(struct regmap_config), GFP_KERNEL);
- if (!one_regmap_config)
- return -ENOMEM;
- mcp->regmap = devm_regmap_init(dev, &mcp23sxx_spi_regmap, mcp,
- one_regmap_config);
mcp->reg_shift = 1;
mcp->chip.ngpio = 16;
mcp->chip.label = "mcp23s18";
+
+ config = &mcp23x17_regmap;
+ name = config->name;
break;
default:
@@ -939,6 +927,13 @@ static int mcp23s08_spi_regmap_init(struct mcp23s08 *mcp, struct device *dev,
return -EINVAL;
}
+ copy = devm_kmemdup(dev, &config, sizeof(config), GFP_KERNEL);
+ if (!copy)
+ return -ENOMEM;
+
+ copy->name = name;
+
+ mcp->regmap = devm_regmap_init(dev, &mcp23sxx_spi_regmap, mcp, copy);
if (IS_ERR(mcp->regmap))
return PTR_ERR(mcp->regmap);
--
2.25.1
next prev parent reply other threads:[~2020-04-07 17:38 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-07 17:38 [PATCH v1 1/9] pinctrl: mcp23s08: Get rid of legacy platform data Andy Shevchenko
2020-04-07 17:38 ` [PATCH v1 2/9] pinctrl: mcp23s08: Deduplicate IRQ chip filling Andy Shevchenko
2020-04-07 17:38 ` [PATCH v1 3/9] pinctrl: mcp23s08: Consolidate SPI and I²C code Andy Shevchenko
2020-04-07 17:38 ` [PATCH v1 4/9] pinctrl: mcp23s08: Drop unused parameter in mcp23s08_probe_one() Andy Shevchenko
2020-04-07 17:38 ` Andy Shevchenko [this message]
2020-04-07 17:38 ` [PATCH v1 6/9] pinctrl: mcp23s08: Propagate error code from device_property_read_u32() Andy Shevchenko
2020-04-07 17:38 ` [PATCH v1 7/9] pinctrl: mcp23s08: Make use of device properties Andy Shevchenko
2020-04-07 17:38 ` [PATCH v1 8/9] pinctrl: mcp23s08: Use for_each_set_bit() and hweight_long() Andy Shevchenko
2020-04-07 17:38 ` [PATCH v1 9/9] pinctrl: mcp23s08: Split to three parts: core, I²C, SPI Andy Shevchenko
2020-04-16 10:35 ` [PATCH v1 1/9] pinctrl: mcp23s08: Get rid of legacy platform data Linus Walleij
2020-10-09 9:15 ` Martin Hundebøll
2020-10-09 14:02 ` Andy Shevchenko
2020-10-09 16:02 ` Andy Shevchenko
2021-09-16 12:51 ` Florian Eckert
2021-09-22 6:36 ` Andy Shevchenko
2021-09-22 7:53 ` Andy Shevchenko
2021-09-23 14:17 ` Add a SSDT ACPI description to recognize my I2C device connected via SMBus Florian Eckert
2021-09-23 16:24 ` Mika Westerberg
2021-09-23 20:26 ` Andy Shevchenko
2021-09-23 20:29 ` Andy Shevchenko
2021-09-29 22:40 ` Florian Eckert
2021-09-30 6:15 ` Andy Shevchenko
2021-09-30 6:19 ` Andy Shevchenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200407173849.43628-5-andriy.shevchenko@linux.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).