mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] nvmem: sc27xx: add sc2730 efuse support
@ 2020-06-15  3:23 Chunyan Zhang
  2020-06-15  9:39 ` Srinivas Kandagatla
  2020-06-15 13:50 ` Baolin Wang
  0 siblings, 2 replies; 3+ messages in thread
From: Chunyan Zhang @ 2020-06-15  3:23 UTC (permalink / raw)
  To: Srinivas Kandagatla
  Cc: linux-kernel, Orson Zhai, Baolin Wang, Chunyan Zhang,
	Chunyan Zhang, Freeman Liu

From: Freeman Liu <freeman.liu@unisoc.com>

Add support to the new efuse IP which is integrated in the SC2730
which includes multiple blocks in a single chip.

Signed-off-by: Freeman Liu <freeman.liu@unisoc.com>
Signed-off-by: Chunyan Zhang <chunyan.zhang@unisoc.com>
---
 drivers/nvmem/sc27xx-efuse.c | 34 +++++++++++++++++++++++++++++++---
 1 file changed, 31 insertions(+), 3 deletions(-)

diff --git a/drivers/nvmem/sc27xx-efuse.c b/drivers/nvmem/sc27xx-efuse.c
index ab5e7e0bc3d8..7d453c9d80da 100644
--- a/drivers/nvmem/sc27xx-efuse.c
+++ b/drivers/nvmem/sc27xx-efuse.c
@@ -4,12 +4,14 @@
 #include <linux/hwspinlock.h>
 #include <linux/module.h>
 #include <linux/of.h>
+#include <linux/of_device.h>
 #include <linux/platform_device.h>
 #include <linux/regmap.h>
 #include <linux/nvmem-provider.h>
 
 /* PMIC global registers definition */
 #define SC27XX_MODULE_EN		0xc08
+#define SC2730_MODULE_EN		0x1808
 #define SC27XX_EFUSE_EN			BIT(6)
 
 /* Efuse controller registers definition */
@@ -49,12 +51,29 @@
 #define SC27XX_EFUSE_POLL_TIMEOUT	3000000
 #define SC27XX_EFUSE_POLL_DELAY_US	10000
 
+/*
+ * Since different PMICs of SC27xx series can have different
+ * address , we should save address in the device data structure.
+ */
+struct sc27xx_efuse_variant_data {
+	u32 module_en;
+};
+
 struct sc27xx_efuse {
 	struct device *dev;
 	struct regmap *regmap;
 	struct hwspinlock *hwlock;
 	struct mutex mutex;
 	u32 base;
+	const struct sc27xx_efuse_variant_data *var_data;
+};
+
+static const struct sc27xx_efuse_variant_data sc2731_edata = {
+	.module_en = SC27XX_MODULE_EN,
+};
+
+static const struct sc27xx_efuse_variant_data sc2730_edata = {
+	.module_en = SC2730_MODULE_EN,
 };
 
 /*
@@ -119,7 +138,7 @@ static int sc27xx_efuse_read(void *context, u32 offset, void *val, size_t bytes)
 		return ret;
 
 	/* Enable the efuse controller. */
-	ret = regmap_update_bits(efuse->regmap, SC27XX_MODULE_EN,
+	ret = regmap_update_bits(efuse->regmap, efuse->var_data->module_en,
 				 SC27XX_EFUSE_EN, SC27XX_EFUSE_EN);
 	if (ret)
 		goto unlock_efuse;
@@ -169,7 +188,7 @@ static int sc27xx_efuse_read(void *context, u32 offset, void *val, size_t bytes)
 
 disable_efuse:
 	/* Disable the efuse controller after reading. */
-	regmap_update_bits(efuse->regmap, SC27XX_MODULE_EN, SC27XX_EFUSE_EN, 0);
+	regmap_update_bits(efuse->regmap, efuse->var_data->module_en, SC27XX_EFUSE_EN, 0);
 unlock_efuse:
 	sc27xx_efuse_unlock(efuse);
 
@@ -187,8 +206,15 @@ static int sc27xx_efuse_probe(struct platform_device *pdev)
 	struct nvmem_config econfig = { };
 	struct nvmem_device *nvmem;
 	struct sc27xx_efuse *efuse;
+	const struct sc27xx_efuse_variant_data *pdata;
 	int ret;
 
+	pdata = of_device_get_match_data(&pdev->dev);
+	if (!pdata) {
+		dev_err(&pdev->dev, "No matching driver data found\n");
+		return -EINVAL;
+	}
+
 	efuse = devm_kzalloc(&pdev->dev, sizeof(*efuse), GFP_KERNEL);
 	if (!efuse)
 		return -ENOMEM;
@@ -219,6 +245,7 @@ static int sc27xx_efuse_probe(struct platform_device *pdev)
 
 	mutex_init(&efuse->mutex);
 	efuse->dev = &pdev->dev;
+	efuse->var_data = pdata;
 
 	econfig.stride = 1;
 	econfig.word_size = 1;
@@ -238,7 +265,8 @@ static int sc27xx_efuse_probe(struct platform_device *pdev)
 }
 
 static const struct of_device_id sc27xx_efuse_of_match[] = {
-	{ .compatible = "sprd,sc2731-efuse" },
+	{ .compatible = "sprd,sc2731-efuse", .data = &sc2731_edata},
+	{ .compatible = "sprd,sc2730-efuse", .data = &sc2730_edata},
 	{ }
 };
 
-- 
2.20.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] nvmem: sc27xx: add sc2730 efuse support
  2020-06-15  3:23 [PATCH] nvmem: sc27xx: add sc2730 efuse support Chunyan Zhang
@ 2020-06-15  9:39 ` Srinivas Kandagatla
  2020-06-15 13:50 ` Baolin Wang
  1 sibling, 0 replies; 3+ messages in thread
From: Srinivas Kandagatla @ 2020-06-15  9:39 UTC (permalink / raw)
  To: Chunyan Zhang
  Cc: linux-kernel, Orson Zhai, Baolin Wang, Chunyan Zhang, Freeman Liu



On 15/06/2020 04:23, Chunyan Zhang wrote:
> From: Freeman Liu <freeman.liu@unisoc.com>
> 
> Add support to the new efuse IP which is integrated in the SC2730
> which includes multiple blocks in a single chip.
> 
> Signed-off-by: Freeman Liu <freeman.liu@unisoc.com>
> Signed-off-by: Chunyan Zhang <chunyan.zhang@unisoc.com>
> ---
>   drivers/nvmem/sc27xx-efuse.c | 34 +++++++++++++++++++++++++++++++---
>   1 file changed, 31 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/nvmem/sc27xx-efuse.c b/drivers/nvmem/sc27xx-efuse.c
> index ab5e7e0bc3d8..7d453c9d80da 100644
> --- a/drivers/nvmem/sc27xx-efuse.c
> +++ b/drivers/nvmem/sc27xx-efuse.c

...

>   
> @@ -187,8 +206,15 @@ static int sc27xx_efuse_probe(struct platform_device *pdev)
>   	struct nvmem_config econfig = { };
>   	struct nvmem_device *nvmem;
>   	struct sc27xx_efuse *efuse;
> +	const struct sc27xx_efuse_variant_data *pdata;
>   	int ret;
>   
> +	pdata = of_device_get_match_data(&pdev->dev);
> +	if (!pdata) {

This check is totally unnecessary as you would not end up here unless 
there is a matching compatible!


You could move this after kmalloc and assign efuse->var_data directly!!


--srini

> +		dev_err(&pdev->dev, "No matching driver data found\n");
> +		return -EINVAL;
> +	}
> +
>   	efuse = devm_kzalloc(&pdev->dev, sizeof(*efuse), GFP_KERNEL);
>   	if (!efuse)
>   		return -ENOMEM;
> @@ -219,6 +245,7 @@ static int sc27xx_efuse_probe(struct platform_device *pdev)
>   
>   	mutex_init(&efuse->mutex);
>   	efuse->dev = &pdev->dev;
> +	efuse->var_data = pdata;
>   

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] nvmem: sc27xx: add sc2730 efuse support
  2020-06-15  3:23 [PATCH] nvmem: sc27xx: add sc2730 efuse support Chunyan Zhang
  2020-06-15  9:39 ` Srinivas Kandagatla
@ 2020-06-15 13:50 ` Baolin Wang
  1 sibling, 0 replies; 3+ messages in thread
From: Baolin Wang @ 2020-06-15 13:50 UTC (permalink / raw)
  To: Chunyan Zhang
  Cc: Srinivas Kandagatla, LKML, Orson Zhai, Chunyan Zhang, Freeman Liu

On Mon, Jun 15, 2020 at 11:23 AM Chunyan Zhang <zhang.lyra@gmail.com> wrote:
>
> From: Freeman Liu <freeman.liu@unisoc.com>
>
> Add support to the new efuse IP which is integrated in the SC2730
> which includes multiple blocks in a single chip.
>
> Signed-off-by: Freeman Liu <freeman.liu@unisoc.com>
> Signed-off-by: Chunyan Zhang <chunyan.zhang@unisoc.com>

Looks good to me. You can add my reviewed-by tag after fixing the
comment from Srinivas.
Reviewed-by: Baolin Wang <baolin.wang7@gmail.com>

> ---
>  drivers/nvmem/sc27xx-efuse.c | 34 +++++++++++++++++++++++++++++++---
>  1 file changed, 31 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/nvmem/sc27xx-efuse.c b/drivers/nvmem/sc27xx-efuse.c
> index ab5e7e0bc3d8..7d453c9d80da 100644
> --- a/drivers/nvmem/sc27xx-efuse.c
> +++ b/drivers/nvmem/sc27xx-efuse.c
> @@ -4,12 +4,14 @@
>  #include <linux/hwspinlock.h>
>  #include <linux/module.h>
>  #include <linux/of.h>
> +#include <linux/of_device.h>
>  #include <linux/platform_device.h>
>  #include <linux/regmap.h>
>  #include <linux/nvmem-provider.h>
>
>  /* PMIC global registers definition */
>  #define SC27XX_MODULE_EN               0xc08
> +#define SC2730_MODULE_EN               0x1808
>  #define SC27XX_EFUSE_EN                        BIT(6)
>
>  /* Efuse controller registers definition */
> @@ -49,12 +51,29 @@
>  #define SC27XX_EFUSE_POLL_TIMEOUT      3000000
>  #define SC27XX_EFUSE_POLL_DELAY_US     10000
>
> +/*
> + * Since different PMICs of SC27xx series can have different
> + * address , we should save address in the device data structure.
> + */
> +struct sc27xx_efuse_variant_data {
> +       u32 module_en;
> +};
> +
>  struct sc27xx_efuse {
>         struct device *dev;
>         struct regmap *regmap;
>         struct hwspinlock *hwlock;
>         struct mutex mutex;
>         u32 base;
> +       const struct sc27xx_efuse_variant_data *var_data;
> +};
> +
> +static const struct sc27xx_efuse_variant_data sc2731_edata = {
> +       .module_en = SC27XX_MODULE_EN,
> +};
> +
> +static const struct sc27xx_efuse_variant_data sc2730_edata = {
> +       .module_en = SC2730_MODULE_EN,
>  };
>
>  /*
> @@ -119,7 +138,7 @@ static int sc27xx_efuse_read(void *context, u32 offset, void *val, size_t bytes)
>                 return ret;
>
>         /* Enable the efuse controller. */
> -       ret = regmap_update_bits(efuse->regmap, SC27XX_MODULE_EN,
> +       ret = regmap_update_bits(efuse->regmap, efuse->var_data->module_en,
>                                  SC27XX_EFUSE_EN, SC27XX_EFUSE_EN);
>         if (ret)
>                 goto unlock_efuse;
> @@ -169,7 +188,7 @@ static int sc27xx_efuse_read(void *context, u32 offset, void *val, size_t bytes)
>
>  disable_efuse:
>         /* Disable the efuse controller after reading. */
> -       regmap_update_bits(efuse->regmap, SC27XX_MODULE_EN, SC27XX_EFUSE_EN, 0);
> +       regmap_update_bits(efuse->regmap, efuse->var_data->module_en, SC27XX_EFUSE_EN, 0);
>  unlock_efuse:
>         sc27xx_efuse_unlock(efuse);
>
> @@ -187,8 +206,15 @@ static int sc27xx_efuse_probe(struct platform_device *pdev)
>         struct nvmem_config econfig = { };
>         struct nvmem_device *nvmem;
>         struct sc27xx_efuse *efuse;
> +       const struct sc27xx_efuse_variant_data *pdata;
>         int ret;
>
> +       pdata = of_device_get_match_data(&pdev->dev);
> +       if (!pdata) {
> +               dev_err(&pdev->dev, "No matching driver data found\n");
> +               return -EINVAL;
> +       }
> +
>         efuse = devm_kzalloc(&pdev->dev, sizeof(*efuse), GFP_KERNEL);
>         if (!efuse)
>                 return -ENOMEM;
> @@ -219,6 +245,7 @@ static int sc27xx_efuse_probe(struct platform_device *pdev)
>
>         mutex_init(&efuse->mutex);
>         efuse->dev = &pdev->dev;
> +       efuse->var_data = pdata;
>
>         econfig.stride = 1;
>         econfig.word_size = 1;
> @@ -238,7 +265,8 @@ static int sc27xx_efuse_probe(struct platform_device *pdev)
>  }
>
>  static const struct of_device_id sc27xx_efuse_of_match[] = {
> -       { .compatible = "sprd,sc2731-efuse" },
> +       { .compatible = "sprd,sc2731-efuse", .data = &sc2731_edata},
> +       { .compatible = "sprd,sc2730-efuse", .data = &sc2730_edata},
>         { }
>  };
>
> --
> 2.20.1
>


-- 
Baolin Wang

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-06-15 13:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-15  3:23 [PATCH] nvmem: sc27xx: add sc2730 efuse support Chunyan Zhang
2020-06-15  9:39 ` Srinivas Kandagatla
2020-06-15 13:50 ` Baolin Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®