Re: [PATCH v1] power: regulator: Add support for NPCM845

2022-11-04 Thread Jim Liu
Hi Jaehoon

Thanks for your review.
and sorry for regulator-force-microvolt.  It's a wrong description for
this driver.

The driver followed normal  property use
-regulator-min-microvolt
-regulator-max-microvolt

It is our npcm845 bmc feature  and no pmic for this regulator.
i will followed your suggestion to modify and upstream v2 patch.

Your comments are all welcome.

Best regards,
Jim


On Thu, Nov 3, 2022 at 6:14 AM Jaehoon Chung  wrote:
>
> Hi,
>
> > -Original Message-
> > From: Jim Liu [mailto:jim.t90...@gmail.com]
> > Sent: Tuesday, November 1, 2022 11:21 AM
> > To: jim.t90...@gmail.com; jjl...@nuvoton.com; ys...@nuvoton.com; 
> > kw...@nuvoton.com;
> > jh80.ch...@samsung.com
> > Cc: u-boot@lists.denx.de
> > Subject: [PATCH v1] power: regulator: Add support for NPCM845
> >
> > Add support for setting NPCM845 voltage supply
> >
> > regulator-force-microvolt is npcm proprietary property to
> > set the voltage level.
>
> What is regulator-force-microvolt. I didn't find this property in u-boot / 
> kernel side.
> If I missed something, could you explain it?
>
> And Is there  no pmic for this regulator?
>
> >
> > Signed-off-by: Jim Liu 
> > ---
> >  drivers/power/regulator/Kconfig |   8 ++
> >  drivers/power/regulator/Makefile|   1 +
> >  drivers/power/regulator/npcm8xx_regulator.c | 133 
> >  3 files changed, 142 insertions(+)
> >  create mode 100644 drivers/power/regulator/npcm8xx_regulator.c
> >
> > diff --git a/drivers/power/regulator/Kconfig 
> > b/drivers/power/regulator/Kconfig
> > index c519e066ef..e5f06874de 100644
> > --- a/drivers/power/regulator/Kconfig
> > +++ b/drivers/power/regulator/Kconfig
> > @@ -128,6 +128,14 @@ config DM_REGULATOR_MAX77686
> >   features for REGULATOR MAX77686. The driver implements get/set api 
> > for:
> >   value, enable and mode.
> >
> > +config DM_REGULATOR_NPCM8XX
> > + bool "Enable driver for NPCM8xx voltage supply"
>
> "Enable Driver Model for "
>
>
> > + depends on DM_REGULATOR && ARCH_NPCM8XX
> > + help
> > +   Enable support for configuring voltage supply on NPCM8XX SoC. The
> > +   voltage supplies support two voltage levels and the driver 
> > implements
> > +   get/set api for setting the value.
> > +
> >  config DM_REGULATOR_FAN53555
> >   bool "Enable Driver Model for REGULATOR FAN53555"
> >   depends on DM_PMIC_FAN53555
> > diff --git a/drivers/power/regulator/Makefile 
> > b/drivers/power/regulator/Makefile
> > index bc736068bc..68e4c0f9dd 100644
> > --- a/drivers/power/regulator/Makefile
> > +++ b/drivers/power/regulator/Makefile
> > @@ -9,6 +9,7 @@ obj-$(CONFIG_REGULATOR_ACT8846) += act8846.o
> >  obj-$(CONFIG_REGULATOR_AS3722)   += as3722_regulator.o
> >  obj-$(CONFIG_$(SPL_)DM_REGULATOR_DA9063) += da9063.o
> >  obj-$(CONFIG_DM_REGULATOR_MAX77686) += max77686.o
> > +obj-$(CONFIG_DM_REGULATOR_NPCM8XX) += npcm8xx_regulator.o
> >  obj-$(CONFIG_$(SPL_)DM_PMIC_PFUZE100) += pfuze100.o
> >  obj-$(CONFIG_$(SPL_)DM_REGULATOR_BD71837) += bd71837.o
> >  obj-$(CONFIG_$(SPL_)DM_REGULATOR_PCA9450) += pca9450.o
> > diff --git a/drivers/power/regulator/npcm8xx_regulator.c
> > b/drivers/power/regulator/npcm8xx_regulator.c
> > new file mode 100644
> > index 00..7903287132
> > --- /dev/null
> > +++ b/drivers/power/regulator/npcm8xx_regulator.c
> > @@ -0,0 +1,133 @@
> > +// SPDX-License-Identifier: GPL-2.0+
> > +/*
> > + * Copyright (c) 2022 Nuvoton Technology Corp.
> > + */
> > +
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +#define REG_VSRCR0xf08000e8  /* Voltage Supply Control Register */
> > +
> > +/* Supported voltage levels (uV) */
> > +static const u32 volts_type1[] = { 330, 180 };
> > +static const u32 volts_type2[] = { 100, 180 };
> > +#define VOLT_LEV00
> > +#define VOLT_LEV11
> > +
> > +struct volt_supply {
> > + char *name;
> > + const u32 *volts;
> > + u32 reg_shift;  /* Register bit offset for setting voltage */
> > +};
> > +
> > +static const struct volt_supply npcm8xx_volt_supps[] = {
> > + {"v1", volts_type1, 0},
> > + {"v2", volts_type1, 1},
> > + {"v3", volts_type1, 2},
> > + {"v4", volts_type1, 3},
> > + {"v5", volts_type1, 4},
> > + {"v6", volts_type1, 5},
> > + {"v7", volts_type1, 6},
> > + {"v8", volts_type1, 7},
> > + {"v9", volts_type1, 8},
> > + {"v10", volts_type1, 9},
> > + {"v11", volts_type2, 10},
> > + {"v12", volts_type1, 11},
> > + {"v13", volts_type1, 12},
> > + {"v14", volts_type2, 13},
> > + {"vsif", volts_type1, 14},
> > + {"vr2", volts_type1, 30},
> > +};
> > +
> > +static const struct volt_supply *npcm8xx_volt_supply_get(const char *name)
> > +{
> > + int i;
> > +
> > + for (i = 0; i < ARRAY_SIZE(npcm8xx_volt_supps); i++) {
> > + if (!strcmp(npcm8xx_volt_supps[i].name, name))
> > + return &npcm8xx_volt_supps[i];
> > + }
> > +
> > +  

RE: [PATCH v1] power: regulator: Add support for NPCM845

2022-11-02 Thread Jaehoon Chung
Hi,

> -Original Message-
> From: Jim Liu [mailto:jim.t90...@gmail.com]
> Sent: Tuesday, November 1, 2022 11:21 AM
> To: jim.t90...@gmail.com; jjl...@nuvoton.com; ys...@nuvoton.com; 
> kw...@nuvoton.com;
> jh80.ch...@samsung.com
> Cc: u-boot@lists.denx.de
> Subject: [PATCH v1] power: regulator: Add support for NPCM845
> 
> Add support for setting NPCM845 voltage supply
> 
> regulator-force-microvolt is npcm proprietary property to
> set the voltage level.

What is regulator-force-microvolt. I didn't find this property in u-boot / 
kernel side.
If I missed something, could you explain it?

And Is there  no pmic for this regulator?

> 
> Signed-off-by: Jim Liu 
> ---
>  drivers/power/regulator/Kconfig |   8 ++
>  drivers/power/regulator/Makefile|   1 +
>  drivers/power/regulator/npcm8xx_regulator.c | 133 
>  3 files changed, 142 insertions(+)
>  create mode 100644 drivers/power/regulator/npcm8xx_regulator.c
> 
> diff --git a/drivers/power/regulator/Kconfig b/drivers/power/regulator/Kconfig
> index c519e066ef..e5f06874de 100644
> --- a/drivers/power/regulator/Kconfig
> +++ b/drivers/power/regulator/Kconfig
> @@ -128,6 +128,14 @@ config DM_REGULATOR_MAX77686
>   features for REGULATOR MAX77686. The driver implements get/set api for:
>   value, enable and mode.
> 
> +config DM_REGULATOR_NPCM8XX
> + bool "Enable driver for NPCM8xx voltage supply"

"Enable Driver Model for "


> + depends on DM_REGULATOR && ARCH_NPCM8XX
> + help
> +   Enable support for configuring voltage supply on NPCM8XX SoC. The
> +   voltage supplies support two voltage levels and the driver implements
> +   get/set api for setting the value.
> +
>  config DM_REGULATOR_FAN53555
>   bool "Enable Driver Model for REGULATOR FAN53555"
>   depends on DM_PMIC_FAN53555
> diff --git a/drivers/power/regulator/Makefile 
> b/drivers/power/regulator/Makefile
> index bc736068bc..68e4c0f9dd 100644
> --- a/drivers/power/regulator/Makefile
> +++ b/drivers/power/regulator/Makefile
> @@ -9,6 +9,7 @@ obj-$(CONFIG_REGULATOR_ACT8846) += act8846.o
>  obj-$(CONFIG_REGULATOR_AS3722)   += as3722_regulator.o
>  obj-$(CONFIG_$(SPL_)DM_REGULATOR_DA9063) += da9063.o
>  obj-$(CONFIG_DM_REGULATOR_MAX77686) += max77686.o
> +obj-$(CONFIG_DM_REGULATOR_NPCM8XX) += npcm8xx_regulator.o
>  obj-$(CONFIG_$(SPL_)DM_PMIC_PFUZE100) += pfuze100.o
>  obj-$(CONFIG_$(SPL_)DM_REGULATOR_BD71837) += bd71837.o
>  obj-$(CONFIG_$(SPL_)DM_REGULATOR_PCA9450) += pca9450.o
> diff --git a/drivers/power/regulator/npcm8xx_regulator.c
> b/drivers/power/regulator/npcm8xx_regulator.c
> new file mode 100644
> index 00..7903287132
> --- /dev/null
> +++ b/drivers/power/regulator/npcm8xx_regulator.c
> @@ -0,0 +1,133 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * Copyright (c) 2022 Nuvoton Technology Corp.
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#define REG_VSRCR0xf08000e8  /* Voltage Supply Control Register */
> +
> +/* Supported voltage levels (uV) */
> +static const u32 volts_type1[] = { 330, 180 };
> +static const u32 volts_type2[] = { 100, 180 };
> +#define VOLT_LEV00
> +#define VOLT_LEV11
> +
> +struct volt_supply {
> + char *name;
> + const u32 *volts;
> + u32 reg_shift;  /* Register bit offset for setting voltage */
> +};
> +
> +static const struct volt_supply npcm8xx_volt_supps[] = {
> + {"v1", volts_type1, 0},
> + {"v2", volts_type1, 1},
> + {"v3", volts_type1, 2},
> + {"v4", volts_type1, 3},
> + {"v5", volts_type1, 4},
> + {"v6", volts_type1, 5},
> + {"v7", volts_type1, 6},
> + {"v8", volts_type1, 7},
> + {"v9", volts_type1, 8},
> + {"v10", volts_type1, 9},
> + {"v11", volts_type2, 10},
> + {"v12", volts_type1, 11},
> + {"v13", volts_type1, 12},
> + {"v14", volts_type2, 13},
> + {"vsif", volts_type1, 14},
> + {"vr2", volts_type1, 30},
> +};
> +
> +static const struct volt_supply *npcm8xx_volt_supply_get(const char *name)
> +{
> + int i;
> +
> + for (i = 0; i < ARRAY_SIZE(npcm8xx_volt_supps); i++) {
> + if (!strcmp(npcm8xx_volt_supps[i].name, name))
> + return &npcm8xx_volt_supps[i];
> + }
> +
> + return NULL;
> +}
> +
> +static int npcm8xx_regulator_set_value(struct udevice *dev, int uV)
> +{
> + struct dm_regulator_uclass_plat *uc_pdata;
> + const struct volt_supply *supp;
> + u32 val, level;
> +
> + uc_pdata = dev_get_uclass_plat(dev);
> + if (!uc_pdata)
> + return -ENXIO;
> +
> + dev_dbg(dev, "%s set_value: %d\n", uc_pdata->name, uV);
> + supp = npcm8xx_volt_supply_get(uc_pdata->name);
> + if (!supp)
> + return -ENOENT;
> +
> + if (uV == supp->volts[VOLT_LEV0])
> + level = VOLT_LEV0;
> + else if (uV == supp->volts[VOLT_LEV1])
> + level = VOLT_LEV1;
> + else
> + return -EINVAL;
> +
>