* [PATCH 0/2] Match data improvements for mcp23s08 driver
@ 2023-09-02 9:09 Biju Das
2023-09-02 9:09 ` [PATCH 1/2] pinctrl: mcp23s08: Extend match support for OF tables Biju Das
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Biju Das @ 2023-09-02 9:09 UTC (permalink / raw)
To: Linus Walleij
Cc: Biju Das, linux-gpio, linux-kernel, Biju Das, Andy Shevchenko
This patch series aims to add match data improvements for mcp23s08 driver.
This patch series is only compile tested.
Biju Das (2):
pinctrl: mcp23s08: Extend match support for OF tables
pinctrl: mcp23s08: Simplify probe()
drivers/pinctrl/pinctrl-mcp23s08_i2c.c | 102 ++++++++++++-------------
1 file changed, 50 insertions(+), 52 deletions(-)
--
2.25.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/2] pinctrl: mcp23s08: Extend match support for OF tables
2023-09-02 9:09 [PATCH 0/2] Match data improvements for mcp23s08 driver Biju Das
@ 2023-09-02 9:09 ` Biju Das
2023-09-04 9:09 ` Andy Shevchenko
2023-09-02 9:09 ` [PATCH 2/2] pinctrl: mcp23s08: Simplify probe() Biju Das
2023-09-04 9:14 ` [PATCH 0/2] Match data improvements for mcp23s08 driver Andy Shevchenko
2 siblings, 1 reply; 7+ messages in thread
From: Biju Das @ 2023-09-02 9:09 UTC (permalink / raw)
To: Linus Walleij
Cc: Biju Das, linux-gpio, linux-kernel, Biju Das, Andy Shevchenko
The driver has OF match table, still it uses ID lookup table for
retrieving match data. Currently the driver is working on the
assumption that a I2C device registered via OF will always match a
legacy I2C device ID. The correct approach is to have an OF device ID
table using of_device_match_data() if the devices are registered via OF.
Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
---
drivers/pinctrl/pinctrl-mcp23s08_i2c.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/pinctrl/pinctrl-mcp23s08_i2c.c b/drivers/pinctrl/pinctrl-mcp23s08_i2c.c
index 3dd1bd8e73eb..393d9b099cc5 100644
--- a/drivers/pinctrl/pinctrl-mcp23s08_i2c.c
+++ b/drivers/pinctrl/pinctrl-mcp23s08_i2c.c
@@ -10,9 +10,8 @@
static int mcp230xx_probe(struct i2c_client *client)
{
- const struct i2c_device_id *id = i2c_client_get_device_id(client);
struct device *dev = &client->dev;
- unsigned int type = id->driver_data;
+ unsigned int type;
struct mcp23s08 *mcp;
int ret;
@@ -20,6 +19,7 @@ static int mcp230xx_probe(struct i2c_client *client)
if (!mcp)
return -ENOMEM;
+ type = (uintptr_t)i2c_get_match_data(client);
switch (type) {
case MCP_TYPE_008:
mcp->regmap = devm_regmap_init_i2c(client, &mcp23x08_regmap);
--
2.25.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/2] pinctrl: mcp23s08: Simplify probe()
2023-09-02 9:09 [PATCH 0/2] Match data improvements for mcp23s08 driver Biju Das
2023-09-02 9:09 ` [PATCH 1/2] pinctrl: mcp23s08: Extend match support for OF tables Biju Das
@ 2023-09-02 9:09 ` Biju Das
2023-09-04 9:12 ` Andy Shevchenko
2023-09-05 11:31 ` Dan Carpenter
2023-09-04 9:14 ` [PATCH 0/2] Match data improvements for mcp23s08 driver Andy Shevchenko
2 siblings, 2 replies; 7+ messages in thread
From: Biju Das @ 2023-09-02 9:09 UTC (permalink / raw)
To: Linus Walleij
Cc: Biju Das, linux-gpio, linux-kernel, Biju Das, Andy Shevchenko
Add struct mcp23s08_i2c_info and simplify probe() by replacing
match data 'type' with 'struct mcp23s08_i2c_info'.
While at it, replace dev_err()->dev_err_probe().
Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
---
drivers/pinctrl/pinctrl-mcp23s08_i2c.c | 102 ++++++++++++-------------
1 file changed, 50 insertions(+), 52 deletions(-)
diff --git a/drivers/pinctrl/pinctrl-mcp23s08_i2c.c b/drivers/pinctrl/pinctrl-mcp23s08_i2c.c
index 393d9b099cc5..61e92f68ec95 100644
--- a/drivers/pinctrl/pinctrl-mcp23s08_i2c.c
+++ b/drivers/pinctrl/pinctrl-mcp23s08_i2c.c
@@ -8,10 +8,18 @@
#include "pinctrl-mcp23s08.h"
+struct mcp23s08_i2c_info {
+ const struct regmap_config *regmap;
+ const char *label;
+ unsigned int type;
+ u16 ngpio;
+ bool reg_shift;
+};
+
static int mcp230xx_probe(struct i2c_client *client)
{
+ const struct mcp23s08_i2c_info *info;
struct device *dev = &client->dev;
- unsigned int type;
struct mcp23s08 *mcp;
int ret;
@@ -19,41 +27,22 @@ static int mcp230xx_probe(struct i2c_client *client)
if (!mcp)
return -ENOMEM;
- type = (uintptr_t)i2c_get_match_data(client);
- switch (type) {
- case MCP_TYPE_008:
- mcp->regmap = devm_regmap_init_i2c(client, &mcp23x08_regmap);
- mcp->reg_shift = 0;
- mcp->chip.ngpio = 8;
- mcp->chip.label = "mcp23008";
- break;
-
- case MCP_TYPE_017:
- mcp->regmap = devm_regmap_init_i2c(client, &mcp23x17_regmap);
- mcp->reg_shift = 1;
- mcp->chip.ngpio = 16;
- mcp->chip.label = "mcp23017";
- break;
-
- case MCP_TYPE_018:
- mcp->regmap = devm_regmap_init_i2c(client, &mcp23x17_regmap);
- mcp->reg_shift = 1;
- mcp->chip.ngpio = 16;
- mcp->chip.label = "mcp23018";
- break;
-
- default:
- dev_err(dev, "invalid device type (%d)\n", type);
- return -EINVAL;
- }
+ info = i2c_get_match_data(client);
+ if (!info)
+ return dev_err_probe(dev, -EINVAL, "invalid device type (%d)\n",
+ info->type);
+ mcp->reg_shift = info->reg_shift;
+ mcp->chip.ngpio = info->ngpio;
+ mcp->chip.label = info->label;
+ mcp->regmap = devm_regmap_init_i2c(client, info->regmap);
if (IS_ERR(mcp->regmap))
return PTR_ERR(mcp->regmap);
mcp->irq = client->irq;
mcp->pinctrl_desc.name = "mcp23xxx-pinctrl";
- ret = mcp23s08_probe_one(mcp, dev, client->addr, type, -1);
+ ret = mcp23s08_probe_one(mcp, dev, client->addr, info->type, -1);
if (ret)
return ret;
@@ -62,36 +51,45 @@ static int mcp230xx_probe(struct i2c_client *client)
return 0;
}
+static const struct mcp23s08_i2c_info mcp23s08_i2c_0008 = {
+ .regmap = &mcp23x08_regmap,
+ .label = "mcp23008",
+ .type = MCP_TYPE_008,
+ .ngpio = 8,
+ .reg_shift = 0,
+};
+
+static const struct mcp23s08_i2c_info mcp23s08_i2c_0017 = {
+ .regmap = &mcp23x17_regmap,
+ .label = "mcp23017",
+ .type = MCP_TYPE_017,
+ .ngpio = 16,
+ .reg_shift = 1,
+};
+
+static const struct mcp23s08_i2c_info mcp23s08_i2c_0018 = {
+ .regmap = &mcp23x17_regmap,
+ .label = "mcp23018",
+ .type = MCP_TYPE_018,
+ .ngpio = 16,
+ .reg_shift = 1,
+};
+
static const struct i2c_device_id mcp230xx_id[] = {
- { "mcp23008", MCP_TYPE_008 },
- { "mcp23017", MCP_TYPE_017 },
- { "mcp23018", MCP_TYPE_018 },
+ { "mcp23008", (kernel_ulong_t)&mcp23s08_i2c_0008 },
+ { "mcp23017", (kernel_ulong_t)&mcp23s08_i2c_0017 },
+ { "mcp23018", (kernel_ulong_t)&mcp23s08_i2c_0018 },
{ }
};
MODULE_DEVICE_TABLE(i2c, mcp230xx_id);
static const struct of_device_id mcp23s08_i2c_of_match[] = {
- {
- .compatible = "microchip,mcp23008",
- .data = (void *) MCP_TYPE_008,
- },
- {
- .compatible = "microchip,mcp23017",
- .data = (void *) MCP_TYPE_017,
- },
- {
- .compatible = "microchip,mcp23018",
- .data = (void *) MCP_TYPE_018,
- },
+ { .compatible = "microchip,mcp23008", .data = &mcp23s08_i2c_0008 },
+ { .compatible = "microchip,mcp23017", .data = &mcp23s08_i2c_0017 },
+ { .compatible = "microchip,mcp23018", .data = &mcp23s08_i2c_0018 },
/* NOTE: The use of the mcp prefix is deprecated and will be removed. */
- {
- .compatible = "mcp,mcp23008",
- .data = (void *) MCP_TYPE_008,
- },
- {
- .compatible = "mcp,mcp23017",
- .data = (void *) MCP_TYPE_017,
- },
+ { .compatible = "mcp,mcp23008", .data = &mcp23s08_i2c_0008 },
+ { .compatible = "mcp,mcp23017", .data = &mcp23s08_i2c_0017 },
{ }
};
MODULE_DEVICE_TABLE(of, mcp23s08_i2c_of_match);
--
2.25.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] pinctrl: mcp23s08: Extend match support for OF tables
2023-09-02 9:09 ` [PATCH 1/2] pinctrl: mcp23s08: Extend match support for OF tables Biju Das
@ 2023-09-04 9:09 ` Andy Shevchenko
0 siblings, 0 replies; 7+ messages in thread
From: Andy Shevchenko @ 2023-09-04 9:09 UTC (permalink / raw)
To: Biju Das; +Cc: Linus Walleij, linux-gpio, linux-kernel, Biju Das
On Sat, Sep 02, 2023 at 10:09:36AM +0100, Biju Das wrote:
> The driver has OF match table, still it uses ID lookup table for
> retrieving match data. Currently the driver is working on the
> assumption that a I2C device registered via OF will always match a
> legacy I2C device ID. The correct approach is to have an OF device ID
> table using of_device_match_data() if the devices are registered via OF.
...
> - const struct i2c_device_id *id = i2c_client_get_device_id(client);
> struct device *dev = &client->dev;
> - unsigned int type = id->driver_data;
> + unsigned int type;
Now it's shorter than below line, so move it further.
> struct mcp23s08 *mcp;
> int ret;
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/2] pinctrl: mcp23s08: Simplify probe()
2023-09-02 9:09 ` [PATCH 2/2] pinctrl: mcp23s08: Simplify probe() Biju Das
@ 2023-09-04 9:12 ` Andy Shevchenko
2023-09-05 11:31 ` Dan Carpenter
1 sibling, 0 replies; 7+ messages in thread
From: Andy Shevchenko @ 2023-09-04 9:12 UTC (permalink / raw)
To: Biju Das; +Cc: Linus Walleij, linux-gpio, linux-kernel, Biju Das
On Sat, Sep 02, 2023 at 10:09:37AM +0100, Biju Das wrote:
> Add struct mcp23s08_i2c_info and simplify probe() by replacing
> match data 'type' with 'struct mcp23s08_i2c_info'.
>
> While at it, replace dev_err()->dev_err_probe().
'->' --> ' --> '
...
> + info = i2c_get_match_data(client);
> + if (!info)
> + return dev_err_probe(dev, -EINVAL, "invalid device type (%d)\n",
> + info->type);
Huh?! Please, think about it...
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 0/2] Match data improvements for mcp23s08 driver
2023-09-02 9:09 [PATCH 0/2] Match data improvements for mcp23s08 driver Biju Das
2023-09-02 9:09 ` [PATCH 1/2] pinctrl: mcp23s08: Extend match support for OF tables Biju Das
2023-09-02 9:09 ` [PATCH 2/2] pinctrl: mcp23s08: Simplify probe() Biju Das
@ 2023-09-04 9:14 ` Andy Shevchenko
2 siblings, 0 replies; 7+ messages in thread
From: Andy Shevchenko @ 2023-09-04 9:14 UTC (permalink / raw)
To: Biju Das; +Cc: Linus Walleij, linux-gpio, linux-kernel, Biju Das
On Sat, Sep 02, 2023 at 10:09:35AM +0100, Biju Das wrote:
> This patch series aims to add match data improvements for mcp23s08 driver.
>
> This patch series is only compile tested.
When driver has SPI and I2C parts, always take into account both of them.
There is more work needed here.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/2] pinctrl: mcp23s08: Simplify probe()
2023-09-02 9:09 ` [PATCH 2/2] pinctrl: mcp23s08: Simplify probe() Biju Das
2023-09-04 9:12 ` Andy Shevchenko
@ 2023-09-05 11:31 ` Dan Carpenter
1 sibling, 0 replies; 7+ messages in thread
From: Dan Carpenter @ 2023-09-05 11:31 UTC (permalink / raw)
To: oe-kbuild, Biju Das, Linus Walleij
Cc: lkp, oe-kbuild-all, Biju Das, linux-gpio, linux-kernel,
Andy Shevchenko
Hi Biju,
kernel test robot noticed the following build warnings:
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Biju-Das/pinctrl-mcp23s08-Extend-match-support-for-OF-tables/20230902-171023
base: https://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-pinctrl.git devel
patch link: https://lore.kernel.org/r/20230902090937.32195-3-biju.das.jz%40bp.renesas.com
patch subject: [PATCH 2/2] pinctrl: mcp23s08: Simplify probe()
config: i386-randconfig-141-20230902 (https://download.01.org/0day-ci/archive/20230903/202309030751.GQvtrZnS-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce: (https://download.01.org/0day-ci/archive/20230903/202309030751.GQvtrZnS-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
| Closes: https://lore.kernel.org/r/202309030751.GQvtrZnS-lkp@intel.com/
smatch warnings:
drivers/pinctrl/pinctrl-mcp23s08_i2c.c:33 mcp230xx_probe() error: we previously assumed 'info' could be null (see line 31)
vim +/info +33 drivers/pinctrl/pinctrl-mcp23s08_i2c.c
8bb5811129f9e4 Uwe Kleine-König 2022-11-18 19 static int mcp230xx_probe(struct i2c_client *client)
0f04a81784fe3d Andy Shevchenko 2020-04-07 20 {
b5f259f6fc5912 Biju Das 2023-09-02 21 const struct mcp23s08_i2c_info *info;
0f04a81784fe3d Andy Shevchenko 2020-04-07 22 struct device *dev = &client->dev;
0f04a81784fe3d Andy Shevchenko 2020-04-07 23 struct mcp23s08 *mcp;
0f04a81784fe3d Andy Shevchenko 2020-04-07 24 int ret;
0f04a81784fe3d Andy Shevchenko 2020-04-07 25
0f04a81784fe3d Andy Shevchenko 2020-04-07 26 mcp = devm_kzalloc(dev, sizeof(*mcp), GFP_KERNEL);
0f04a81784fe3d Andy Shevchenko 2020-04-07 27 if (!mcp)
0f04a81784fe3d Andy Shevchenko 2020-04-07 28 return -ENOMEM;
0f04a81784fe3d Andy Shevchenko 2020-04-07 29
b5f259f6fc5912 Biju Das 2023-09-02 30 info = i2c_get_match_data(client);
b5f259f6fc5912 Biju Das 2023-09-02 @31 if (!info)
b5f259f6fc5912 Biju Das 2023-09-02 32 return dev_err_probe(dev, -EINVAL, "invalid device type (%d)\n",
b5f259f6fc5912 Biju Das 2023-09-02 @33 info->type);
^^^^^^^^^^
info is NULL.
0f04a81784fe3d Andy Shevchenko 2020-04-07 34
b5f259f6fc5912 Biju Das 2023-09-02 35 mcp->reg_shift = info->reg_shift;
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2023-09-05 16:51 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-02 9:09 [PATCH 0/2] Match data improvements for mcp23s08 driver Biju Das
2023-09-02 9:09 ` [PATCH 1/2] pinctrl: mcp23s08: Extend match support for OF tables Biju Das
2023-09-04 9:09 ` Andy Shevchenko
2023-09-02 9:09 ` [PATCH 2/2] pinctrl: mcp23s08: Simplify probe() Biju Das
2023-09-04 9:12 ` Andy Shevchenko
2023-09-05 11:31 ` Dan Carpenter
2023-09-04 9:14 ` [PATCH 0/2] Match data improvements for mcp23s08 driver Andy Shevchenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox