From: Lee Jones <lee.jones@linaro.org>
To: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Cc: marek.vasut+renesas@gmail.com, matti.vaittinen@fi.rohmeurope.com,
	lgirdwood@gmail.com, broonie@kernel.org,
	linus.walleij@linaro.org, bgolaszewski@baylibre.com,
	khiem.nguyen.xt@renesas.com, linux-power@fi.rohmeurope.com,
	linux-gpio@vger.kernel.org, linux-renesas-soc@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 11/12] mfd: bd9571mwv: Make the driver more generic
Date: Wed, 16 Dec 2020 15:35:25 +0000	[thread overview]
Message-ID: <20201216153525.GM207743@dell> (raw)
In-Reply-To: <1608104275-13174-12-git-send-email-yoshihiro.shimoda.uh@renesas.com>
On Wed, 16 Dec 2020, Yoshihiro Shimoda wrote:
> From: Khiem Nguyen <khiem.nguyen.xt@renesas.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@renesas.com>
> [shimoda: rebase and refactor]
This is kind of expected.  Please just add Co-developed-by instead.
> Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
> ---
>  drivers/mfd/bd9571mwv.c       | 95 +++++++++++++++++++++++++++----------------
>  include/linux/mfd/bd9571mwv.h | 18 ++------
>  2 files changed, 63 insertions(+), 50 deletions(-)
> 
> diff --git a/drivers/mfd/bd9571mwv.c b/drivers/mfd/bd9571mwv.c
> index 49e968e..ccf1a60 100644
> --- a/drivers/mfd/bd9571mwv.c
> +++ b/drivers/mfd/bd9571mwv.c
> @@ -3,6 +3,7 @@
>   * ROHM BD9571MWV-M MFD driver
>   *
>   * Copyright (C) 2017 Marek Vasut <marek.vasut+renesas@gmail.com>
> + * Copyright (C) 2020 Renesas Electronics Corporation
>   *
>   * Based on the TPS65086 driver
>   */
> @@ -14,6 +15,19 @@
>  
>  #include <linux/mfd/bd9571mwv.h>
>  
> +/**
This is wrong.  Please do not abuse kernel-doc formatting.
> + * struct bd957x_data - internal data for the bd957x driverbd957x_data
> + *
> + * Internal data to distinguish bd957x variants
> + */
> +struct bd957x_data {
Call this bd957x_ddata please.
ddata == driver data.
> +	char *part_name;
What is this used for besides a print?  Those kinds of log messages
are usually frowned upon anyway.  Probably best to just remove the
print, along with the variable.
> +	const struct regmap_config *regmap_config;
> +	const struct regmap_irq_chip *irq_chip;
> +	const struct mfd_cell *cells;
> +	int num_cells;
> +};
> +
>  static const struct mfd_cell bd9571mwv_cells[] = {
>  	{ .name = "bd9571mwv-regulator", },
>  	{ .name = "bd9571mwv-gpio", },
> @@ -102,13 +116,21 @@ static struct regmap_irq_chip bd9571mwv_irq_chip = {
>  	.num_irqs	= ARRAY_SIZE(bd9571mwv_irqs),
>  };
>  
> -static int bd9571mwv_identify(struct bd9571mwv *bd)
> +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 device *dev, struct regmap *regmap,
I guess this function name also needs to change?
And all other occurences of bd9571mwv?
> +			      const char *part_name)
>  {
> -	struct device *dev = bd->dev;
>  	unsigned int value;
>  	int ret;
>  
> -	ret = regmap_read(bd->regmap, BD9571MWV_VENDOR_CODE, &value);
> +	ret = regmap_read(regmap, BD9571MWV_VENDOR_CODE, &value);
>  	if (ret) {
>  		dev_err(dev, "Failed to read vendor code register (ret=%i)\n",
>  			ret);
> @@ -121,27 +143,20 @@ static int bd9571mwv_identify(struct bd9571mwv *bd)
>  		return -EINVAL;
>  	}
>  
> -	ret = regmap_read(bd->regmap, BD9571MWV_PRODUCT_CODE, &value);
> +	ret = regmap_read(regmap, BD9571MWV_PRODUCT_CODE, &value);
>  	if (ret) {
>  		dev_err(dev, "Failed to read product code register (ret=%i)\n",
>  			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);
> +	ret = regmap_read(regmap, BD9571MWV_PRODUCT_REVISION, &value);
>  	if (ret) {
>  		dev_err(dev, "Failed to read revision register (ret=%i)\n",
>  			ret);
>  		return ret;
>  	}
>  
> -	dev_info(dev, "Device: BD9571MWV rev. %d\n", value & 0xff);
> +	dev_info(dev, "Device: %s rev. %d\n", part_name, value & 0xff);
>  
>  	return 0;
>  }
> @@ -149,38 +164,48 @@ static int bd9571mwv_identify(struct bd9571mwv *bd)
>  static int bd9571mwv_probe(struct i2c_client *client,
>  			  const struct i2c_device_id *ids)
>  {
> -	struct bd9571mwv *bd;
> -	int ret;
> -
> -	bd = devm_kzalloc(&client->dev, sizeof(*bd), GFP_KERNEL);
> -	if (!bd)
> -		return -ENOMEM;
> -
> -	i2c_set_clientdata(client, bd);
> -	bd->dev = &client->dev;
> -	bd->irq = client->irq;
> +	const struct bd957x_data *data;
ddata
> +	struct device *dev = &client->dev;
> +	struct regmap *regmap;
> +	struct regmap_irq_chip_data *irq_data;
> +	int ret, irq = client->irq;
> +
> +	/* Read the PMIC product code */
> +	ret = i2c_smbus_read_byte_data(client, BD9571MWV_PRODUCT_CODE);
> +	if (ret < 0) {
> +		dev_err(dev, "failed reading at 0x%02x\n",
> +			BD9571MWV_PRODUCT_CODE);
"Failed to read product code" is more user friendly.
> +		return ret;
> +	}
> +	switch (ret) {
> +	case BD9571MWV_PRODUCT_CODE_VAL:
Suggest:
s/BD9571MWV_PRODUCT_CODE/BD9571MWV_PRODUCT_CODE_CMD/
  then
s/BD9571MWV_PRODUCT_CODE_VAL/BD9571MWV_PRODUCT_CODE/
> +		data = &bd9571mwv_data;
> +		break;
> +	default:
> +		dev_err(dev, "Unsupported device 0x%x\n", ret);
> +		return -ENOENT;
ENOENT == "No such file or directory"
I think you mean -ENODEV.
> +	}
>  
> -	bd->regmap = devm_regmap_init_i2c(client, &bd9571mwv_regmap_config);
> -	if (IS_ERR(bd->regmap)) {
> -		dev_err(bd->dev, "Failed to initialize register map\n");
> -		return PTR_ERR(bd->regmap);
> +	regmap = devm_regmap_init_i2c(client, data->regmap_config);
> +	if (IS_ERR(regmap)) {
> +		dev_err(dev, "Failed to initialize register map\n");
> +		return PTR_ERR(regmap);
>  	}
>  
> -	ret = bd9571mwv_identify(bd);
> +	ret = bd9571mwv_identify(dev, regmap, data->part_name);
Just pass ddata, then you'll have 'dev' and 'regmap'.
I'd remove 'part_name' completely.
>  	if (ret)
>  		return ret;
>  
> -	ret = devm_regmap_add_irq_chip(bd->dev, bd->regmap, bd->irq,
> -				       IRQF_ONESHOT, 0, &bd9571mwv_irq_chip,
> -				       &bd->irq_data);
> +	ret = devm_regmap_add_irq_chip(dev, regmap, irq, IRQF_ONESHOT, 0,
> +				       data->irq_chip, &irq_data);
>  	if (ret) {
> -		dev_err(bd->dev, "Failed to register IRQ chip\n");
> +		dev_err(dev, "Failed to register IRQ chip\n");
>  		return ret;
>  	}
>  
> -	return devm_mfd_add_devices(bd->dev, PLATFORM_DEVID_AUTO,
> -				    bd9571mwv_cells, ARRAY_SIZE(bd9571mwv_cells),
> -				    NULL, 0, regmap_irq_get_domain(bd->irq_data));
> +	return devm_mfd_add_devices(dev, PLATFORM_DEVID_AUTO, data->cells,
> +				    data->num_cells, NULL, 0,
> +				    regmap_irq_get_domain(irq_data));
>  }
>  
>  static const struct of_device_id bd9571mwv_of_match_table[] = {
> diff --git a/include/linux/mfd/bd9571mwv.h b/include/linux/mfd/bd9571mwv.h
> index bcc7092..5ab976a 100644
> --- a/include/linux/mfd/bd9571mwv.h
> +++ b/include/linux/mfd/bd9571mwv.h
> @@ -3,6 +3,7 @@
>   * ROHM BD9571MWV-M driver
>   *
>   * Copyright (C) 2017 Marek Vasut <marek.vasut+renesas@gmail.com>
> + * Copyright (C) 2020 Renesas Electronics Corporation
>   *
>   * Based on the TPS65086 driver
>   */
> @@ -83,6 +84,8 @@
>  
>  #define BD9571MWV_ACCESS_KEY			0xff
>  
> +#define BD9571MWV_PART_NAME			"BD9571MWV"
> +
>  /* Define the BD9571MWV IRQ numbers */
>  enum bd9571mwv_irqs {
>  	BD9571MWV_IRQ_MD1,
> @@ -94,19 +97,4 @@ enum bd9571mwv_irqs {
>  	BD9571MWV_IRQ_WDT_OF,
>  	BD9571MWV_IRQ_BKUP_TRG,
>  };
> -
> -/**
> - * struct bd9571mwv - state holder for the bd9571mwv driver
> - *
> - * Device data may be used to access the BD9571MWV chip
> - */
> -struct bd9571mwv {
> -	struct device *dev;
> -	struct regmap *regmap;
> -
> -	/* IRQ Data */
> -	int irq;
> -	struct regmap_irq_chip_data *irq_data;
> -};
> -
>  #endif /* __LINUX_MFD_BD9571MWV_H */
-- 
Lee Jones [李琼斯]
Senior Technical Lead - Developer Services
Linaro.org │ Open source software for Arm SoCs
Follow Linaro: Facebook | Twitter | Blog
next prev parent reply	other threads:[~2020-12-16 15:36 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-16  7:37 [PATCH v3 00/12] treewide: bd9571mwv: Add support for BD9574MWF Yoshihiro Shimoda
2020-12-16  7:37 ` [PATCH v3 01/12] mfd: bd9571mwv: Use devm_mfd_add_devices() Yoshihiro Shimoda
2020-12-16 15:08   ` Lee Jones
2020-12-16  7:37 ` [PATCH v3 02/12] dt-bindings: mfd: bd9571mwv: Document BD9574MWF Yoshihiro Shimoda
2020-12-16  7:37 ` [PATCH v3 03/12] mfd: rohm-generic: Add BD9571 and BD9574 Yoshihiro Shimoda
2020-12-16 15:09   ` Lee Jones
2020-12-16  7:37 ` [PATCH v3 04/12] regulator: bd9571mwv: rid of using struct bd9571mwv Yoshihiro Shimoda
2020-12-16  7:37 ` [PATCH v3 05/12] regulator: bd9571mwv: Add BD9574MWF support Yoshihiro Shimoda
2020-12-16  7:37 ` [PATCH v3 06/12] gpio: bd9571mwv: Use the SPDX license identifier Yoshihiro Shimoda
2020-12-16  7:37 ` [PATCH v3 07/12] gpio: bd9571mwv: rid of using struct bd9571mwv Yoshihiro Shimoda
2020-12-16  7:37 ` [PATCH v3 08/12] gpio: bd9571mwv: Add BD9574MWF support Yoshihiro Shimoda
2020-12-16  7:37 ` [PATCH v3 09/12] mfd: bd9571mwv: Use the SPDX license identifier Yoshihiro Shimoda
2020-12-16 15:10   ` Lee Jones
2020-12-16  7:37 ` [PATCH v3 10/12] mfd: bd9571mwv: Use devm_regmap_add_irq_chip() Yoshihiro Shimoda
2020-12-16  8:13   ` Vaittinen, Matti
2020-12-16 15:12   ` Lee Jones
2020-12-16  7:37 ` [PATCH v3 11/12] mfd: bd9571mwv: Make the driver more generic Yoshihiro Shimoda
2020-12-16  8:25   ` Vaittinen, Matti
2020-12-16  8:45     ` Vaittinen, Matti
2020-12-16  9:00     ` Lee Jones
2020-12-16  9:09       ` Vaittinen, Matti
2020-12-16 15:35   ` Lee Jones [this message]
2020-12-17 11:44     ` Yoshihiro Shimoda
2020-12-16  7:37 ` [PATCH v3 12/12] mfd: bd9571mwv: Add support for BD9574MWF Yoshihiro Shimoda
2020-12-16  8:45   ` Vaittinen, Matti
2020-12-16  9:02     ` Lee Jones
2020-12-16  9:29       ` Vaittinen, Matti
2020-12-16 15:37   ` Lee Jones
2020-12-17 11:44     ` Yoshihiro Shimoda
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=20201216153525.GM207743@dell \
    --to=lee.jones@linaro.org \
    --cc=bgolaszewski@baylibre.com \
    --cc=broonie@kernel.org \
    --cc=khiem.nguyen.xt@renesas.com \
    --cc=lgirdwood@gmail.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-power@fi.rohmeurope.com \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=marek.vasut+renesas@gmail.com \
    --cc=matti.vaittinen@fi.rohmeurope.com \
    --cc=yoshihiro.shimoda.uh@renesas.com \
    /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).