[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <TY2PR01MB369258FAD3F340A046A11525D8C70@TY2PR01MB3692.jpnprd01.prod.outlook.com>
Date: Mon, 14 Dec 2020 06:21:16 +0000
From: Yoshihiro Shimoda <yoshihiro.shimoda.uh@...esas.com>
To: "Vaittinen, Matti" <Matti.Vaittinen@...rohmeurope.com>,
"lgirdwood@...il.com" <lgirdwood@...il.com>,
"marek.vasut+renesas@...il.com" <marek.vasut+renesas@...il.com>,
"broonie@...nel.org" <broonie@...nel.org>,
"bgolaszewski@...libre.com" <bgolaszewski@...libre.com>,
"lee.jones@...aro.org" <lee.jones@...aro.org>,
"linus.walleij@...aro.org" <linus.walleij@...aro.org>
CC: linux-power <linux-power@...rohmeurope.com>,
"linux-gpio@...r.kernel.org" <linux-gpio@...r.kernel.org>,
Khiem Nguyen <khiem.nguyen.xt@...esas.com>,
"linux-renesas-soc@...r.kernel.org"
<linux-renesas-soc@...r.kernel.org>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: RE: [PATCH v2 09/10] mfd: bd9571mwv: Make the driver more generic
Hi Matti-san,
Thank you for your review!
> From: Vaittinen, Matti, Sent: Friday, December 11, 2020 10:29 PM
>
> Hi Yoshihiro-san,
>
> On Fri, 2020-12-11 at 20:27 +0900, Yoshihiro Shimoda wrote:
> > From: Khiem Nguyen <khiem.nguyen.xt@...esas.com>
> >
> > Since the driver supports BD9571MWV PMIC only,
> > this patch makes the functions and data structure become more generic
> > so that it can support other PMIC variants as well.
> >
> > Signed-off-by: Khiem Nguyen <khiem.nguyen.xt@...esas.com>
> > [shimoda: rebase and refactor]
> > Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@...esas.com>
> > ---
> > drivers/mfd/bd9571mwv.c | 71
> > +++++++++++++++++++++++++++++++++++--------
> > include/linux/mfd/bd9571mwv.h | 18 ++---------
> > 2 files changed, 62 insertions(+), 27 deletions(-)
> >
> > diff --git a/drivers/mfd/bd9571mwv.c b/drivers/mfd/bd9571mwv.c
> > index 80c6ef0..adb9e3d 100644
> > --- a/drivers/mfd/bd9571mwv.c
> > +++ b/drivers/mfd/bd9571mwv.c
<snip>
> > +struct bd9571mwv {
> > + struct device *dev;
> > + struct regmap *regmap;
> > + const struct bd957x_data *data;
> > +
> > + /* IRQ Data */
> > + int irq;
> > + struct regmap_irq_chip_data *irq_data;
> > +};
> > +
>
> I still don't see why you actually need this structure?
I'm sorry. I completely forgot that you said we can remove this
structure in the previous patch's review...
> > static const struct mfd_cell bd9571mwv_cells[] = {
> > { .name = "bd9571mwv-regulator", },
> > { .name = "bd9571mwv-gpio", },
> > @@ -102,6 +131,14 @@ static struct regmap_irq_chip bd9571mwv_irq_chip
> > = {
> > .num_irqs = ARRAY_SIZE(bd9571mwv_irqs),
> > };
> >
> > +static const struct bd957x_data bd9571mwv_data = {
> > + .part_name = BD9571MWV_PART_NAME,
> > + .regmap_config = &bd9571mwv_regmap_config,
> > + .irq_chip = &bd9571mwv_irq_chip,
> > + .cells = bd9571mwv_cells,
> > + .num_cells = ARRAY_SIZE(bd9571mwv_cells),
> > +};
> > +
> > static int bd9571mwv_identify(struct bd9571mwv *bd)
> > {
> > struct device *dev = bd->dev;
> > @@ -127,13 +164,6 @@ static int bd9571mwv_identify(struct bd9571mwv
> > *bd)
> > ret);
> > return ret;
> > }
> > -
> > - if (value != BD9571MWV_PRODUCT_CODE_VAL) {
> > - dev_err(dev, "Invalid product code ID %02x (expected
> > %02x)\n",
> > - value, BD9571MWV_PRODUCT_CODE_VAL);
> > - return -EINVAL;
> > - }
> > -
> > ret = regmap_read(bd->regmap, BD9571MWV_PRODUCT_REVISION,
> > &value);
> > if (ret) {
> > dev_err(dev, "Failed to read revision register
> > (ret=%i)\n",
> > @@ -141,7 +171,8 @@ static int bd9571mwv_identify(struct bd9571mwv
> > *bd)
> > return ret;
> > }
> >
> > - dev_info(dev, "Device: BD9571MWV rev. %d\n", value & 0xff);
> > + dev_info(dev, "Device: %s rev. %d\n", bd->data->part_name,
> > + value & 0xff);
> >
> > return 0;
> > }
> > @@ -160,7 +191,23 @@ static int bd9571mwv_probe(struct i2c_client
> > *client,
> > bd->dev = &client->dev;
> > bd->irq = client->irq;
> >
> > - bd->regmap = devm_regmap_init_i2c(client,
> > &bd9571mwv_regmap_config);
> > + /* Read the PMIC product code */
> > + ret = i2c_smbus_read_byte_data(client, BD9571MWV_PRODUCT_CODE);
> > + if (ret < 0) {
> > + dev_err(&client->dev, "failed reading at 0x%02x\n",
> > + BD9571MWV_PRODUCT_CODE);
> > + return ret;
> > + }
> > + switch (ret) {
> > + case BD9571MWV_PRODUCT_CODE_VAL:
> > + bd->data = &bd9571mwv_data;
> > + break;
> > + default:
> > + dev_err(bd->dev, "Unsupported device 0x%x\n", ret);
> > + return -ENOENT;
> > + }
> > +
> > + bd->regmap = devm_regmap_init_i2c(client, bd->data-
> > >regmap_config);
> > if (IS_ERR(bd->regmap)) {
> > dev_err(bd->dev, "Failed to initialize register
> > map\n");
> > return PTR_ERR(bd->regmap);
> > @@ -171,14 +218,14 @@ static int bd9571mwv_probe(struct i2c_client
> > *client,
> > return ret;
> >
> > ret = regmap_add_irq_chip(bd->regmap, bd->irq, IRQF_ONESHOT, 0,
> > - &bd9571mwv_irq_chip, &bd->irq_data);
> > + bd->data->irq_chip, &bd->irq_data);
>
> I think you already did the big task when you cleaned up the sub-
> drivers from using the struct bd9571mwv. Thumbs up for that!
>
> So, as I said in comment to previous version - I don't see this struct
> bd9571mwv being really used anywhere else but as an argument to IC
> identification function and argument for the remove. I think that by
> switching regmap_add_irq_chip to devm_regmap_add_irq_chip you could get
> rid of the remove, error cleanup path and the i2c_clientdata. And if
> you revised the arguments for identification function you could
> probably further clean the struct definitions.
Thank you for the detailed comments. I agreed we can simplify the code
if we use devm_regmap_add_irq_chip. Also, I found a bug in the current
code which we should call devm_mfd_add_devices() instead of
mfd_add_devices(). So, I'll make a fixed patch too.
> But as I previously said - this is only a 'nit' from me. I appreciate
> your work with these drivers!
Thank you very much for your review!
Best regards,
Yoshihiro Shimoda
Powered by blists - more mailing lists