* [PATCH v3 0/6] MFD: add driver for HiSilicon Hi6421v530 PMIC
@ 2017-06-02 10:51 Guodong Xu
2017-06-02 10:51 ` [PATCH v3 1/6] dt-bindings: mfd: hi6421: Add hi6421v530 compatible string Guodong Xu
` (5 more replies)
0 siblings, 6 replies; 12+ messages in thread
From: Guodong Xu @ 2017-06-02 10:51 UTC (permalink / raw)
To: linux-arm-kernel
This patchset adds driver for HiSilicon Hi6421v530 PMIC.
Mainline kernel already has driver support to a similar chip, Hi6421.
Hi6421 and Hi6421v530 are both from the same vendor, HiSilicon, but
they are at different revisions. They both use the same Memory-mapped
I/O method to communicate with Main SoC. However, they differ quite a
lot in their regulator designs. Eg. they have completely different LDO
voltage points.
Patch 1 and 2 extends hi6421-pmic-core.c to support Hi6421v530 revision.
Patch 3 add hi6421v530-regulator.c driver for LDO regulators.
Patch 4 fixes an issue for hi6421 regulator, which is not related to v530
but it's found in this review.
Patch 5 is dts change, it depends and can be applied on hi3660/hikey960
patchset [1].
Patch 6 enables the relevant config items.
[1], http://www.spinics.net/lists/devicetree/msg178303.html
Major changes in v3:
- in hi6421-pmic-core.c
* use shorter license script.
* arrange #include in alphabetical order.
* using recommended error log messages from Lee Jones.
- in hi6421v530-regulator.c
* remove unused #include files
* arrange remaining ones in alphabetical order.
Major changes in v2:
- instead of writing a new driver, extend hi6421-pmic-core.c
to support its v530 revision
- update hi6421v530-regulator.c to use modern regulator driver
design logics.
Guodong Xu (4):
dt-bindings: mfd: hi6421: Add hi6421v530 compatible string
mfd: hi6421-pmic: add support for HiSilicon Hi6421v530
regulator: hi6421: Describe consumed platform device
arm64: defconfig: enable support hi6421v530 PMIC
Wang Xiaoyin (2):
regulator: hi6421v530: add driver for hi6421v530 voltage regulator
arm64: dts: hikey960: add device node for pmic and regulators
Documentation/devicetree/bindings/mfd/hi6421.txt | 4 +-
arch/arm64/boot/dts/hisilicon/hi3660-hikey960.dts | 46 +++++
arch/arm64/configs/defconfig | 2 +
drivers/mfd/hi6421-pmic-core.c | 85 +++++----
drivers/regulator/Kconfig | 10 ++
drivers/regulator/Makefile | 1 +
drivers/regulator/hi6421-regulator.c | 7 +
drivers/regulator/hi6421v530-regulator.c | 207 ++++++++++++++++++++++
include/linux/mfd/hi6421-pmic.h | 5 +
9 files changed, 334 insertions(+), 33 deletions(-)
create mode 100644 drivers/regulator/hi6421v530-regulator.c
--
2.10.2
^ permalink raw reply [flat|nested] 12+ messages in thread* [PATCH v3 1/6] dt-bindings: mfd: hi6421: Add hi6421v530 compatible string 2017-06-02 10:51 [PATCH v3 0/6] MFD: add driver for HiSilicon Hi6421v530 PMIC Guodong Xu @ 2017-06-02 10:51 ` Guodong Xu 2017-06-05 8:14 ` Lee Jones 2017-06-02 10:51 ` [PATCH v3 2/6] mfd: hi6421-pmic: add support for HiSilicon Hi6421v530 Guodong Xu ` (4 subsequent siblings) 5 siblings, 1 reply; 12+ messages in thread From: Guodong Xu @ 2017-06-02 10:51 UTC (permalink / raw) To: linux-arm-kernel Add compatible string for HiSilicon Hi6421v530 PMIC. Signed-off-by: Guodong Xu <guodong.xu@linaro.org> --- Documentation/devicetree/bindings/mfd/hi6421.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/mfd/hi6421.txt b/Documentation/devicetree/bindings/mfd/hi6421.txt index 0d5a446..22da96d 100644 --- a/Documentation/devicetree/bindings/mfd/hi6421.txt +++ b/Documentation/devicetree/bindings/mfd/hi6421.txt @@ -1,7 +1,9 @@ * HI6421 Multi-Functional Device (MFD), by HiSilicon Ltd. Required parent device properties: -- compatible : contains "hisilicon,hi6421-pmic"; +- compatible : One of the following chip-specific strings: + "hisilicon,hi6421-pmic"; + "hisilicon,hi6421v530-pmic"; - reg : register range space of hi6421; Supported Hi6421 sub-devices include: -- 2.10.2 ^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v3 1/6] dt-bindings: mfd: hi6421: Add hi6421v530 compatible string 2017-06-02 10:51 ` [PATCH v3 1/6] dt-bindings: mfd: hi6421: Add hi6421v530 compatible string Guodong Xu @ 2017-06-05 8:14 ` Lee Jones 2017-06-05 9:03 ` Guodong Xu 0 siblings, 1 reply; 12+ messages in thread From: Lee Jones @ 2017-06-05 8:14 UTC (permalink / raw) To: linux-arm-kernel On Fri, 02 Jun 2017, Guodong Xu wrote: > Add compatible string for HiSilicon Hi6421v530 PMIC. > > Signed-off-by: Guodong Xu <guodong.xu@linaro.org> > --- > Documentation/devicetree/bindings/mfd/hi6421.txt | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) For my own reference: Acked-for-MFD-by: Lee Jones <lee.jones@linaro.org> > diff --git a/Documentation/devicetree/bindings/mfd/hi6421.txt b/Documentation/devicetree/bindings/mfd/hi6421.txt > index 0d5a446..22da96d 100644 > --- a/Documentation/devicetree/bindings/mfd/hi6421.txt > +++ b/Documentation/devicetree/bindings/mfd/hi6421.txt > @@ -1,7 +1,9 @@ > * HI6421 Multi-Functional Device (MFD), by HiSilicon Ltd. > > Required parent device properties: > -- compatible : contains "hisilicon,hi6421-pmic"; > +- compatible : One of the following chip-specific strings: > + "hisilicon,hi6421-pmic"; > + "hisilicon,hi6421v530-pmic"; > - reg : register range space of hi6421; > > Supported Hi6421 sub-devices include: -- Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org ? Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog ^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v3 1/6] dt-bindings: mfd: hi6421: Add hi6421v530 compatible string 2017-06-05 8:14 ` Lee Jones @ 2017-06-05 9:03 ` Guodong Xu 0 siblings, 0 replies; 12+ messages in thread From: Guodong Xu @ 2017-06-05 9:03 UTC (permalink / raw) To: linux-arm-kernel On Mon, Jun 5, 2017 at 4:14 PM, Lee Jones <lee.jones@linaro.org> wrote: > On Fri, 02 Jun 2017, Guodong Xu wrote: > >> Add compatible string for HiSilicon Hi6421v530 PMIC. >> >> Signed-off-by: Guodong Xu <guodong.xu@linaro.org> >> --- >> Documentation/devicetree/bindings/mfd/hi6421.txt | 4 +++- >> 1 file changed, 3 insertions(+), 1 deletion(-) > > For my own reference: > Acked-for-MFD-by: Lee Jones <lee.jones@linaro.org> > Thanks Lee. >> diff --git a/Documentation/devicetree/bindings/mfd/hi6421.txt b/Documentation/devicetree/bindings/mfd/hi6421.txt >> index 0d5a446..22da96d 100644 >> --- a/Documentation/devicetree/bindings/mfd/hi6421.txt >> +++ b/Documentation/devicetree/bindings/mfd/hi6421.txt >> @@ -1,7 +1,9 @@ >> * HI6421 Multi-Functional Device (MFD), by HiSilicon Ltd. >> >> Required parent device properties: >> -- compatible : contains "hisilicon,hi6421-pmic"; >> +- compatible : One of the following chip-specific strings: >> + "hisilicon,hi6421-pmic"; >> + "hisilicon,hi6421v530-pmic"; >> - reg : register range space of hi6421; >> >> Supported Hi6421 sub-devices include: > > -- > Lee Jones > Linaro STMicroelectronics Landing Team Lead > Linaro.org ? Open source software for ARM SoCs > Follow Linaro: Facebook | Twitter | Blog ^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v3 2/6] mfd: hi6421-pmic: add support for HiSilicon Hi6421v530 2017-06-02 10:51 [PATCH v3 0/6] MFD: add driver for HiSilicon Hi6421v530 PMIC Guodong Xu 2017-06-02 10:51 ` [PATCH v3 1/6] dt-bindings: mfd: hi6421: Add hi6421v530 compatible string Guodong Xu @ 2017-06-02 10:51 ` Guodong Xu 2017-06-05 8:24 ` Lee Jones 2017-06-02 10:51 ` [PATCH v3 3/6] regulator: hi6421v530: add driver for hi6421v530 voltage regulator Guodong Xu ` (3 subsequent siblings) 5 siblings, 1 reply; 12+ messages in thread From: Guodong Xu @ 2017-06-02 10:51 UTC (permalink / raw) To: linux-arm-kernel Add support for HiSilicon Hi6421v530 PMIC. Hi6421v530 communicates with main SoC via memory-mapped I/O. Hi6421v530 and Hi6421 are PMIC chips from the same vendor, HiSilicon, but at different revisions. They share the same memory-mapped I/O design. They differ in integrated devices, such as regulator details, LDO voltage points. Also, changed license to a shorter form, and arranged all #include in alphabetical order. Signed-off-by: Wang Xiaoyin <hw.wangxiaoyin@hisilicon.com> Signed-off-by: Guodong Xu <guodong.xu@linaro.org> --- drivers/mfd/hi6421-pmic-core.c | 85 +++++++++++++++++++++++++---------------- include/linux/mfd/hi6421-pmic.h | 5 +++ 2 files changed, 58 insertions(+), 32 deletions(-) diff --git a/drivers/mfd/hi6421-pmic-core.c b/drivers/mfd/hi6421-pmic-core.c index 3fd703f..b914541 100644 --- a/drivers/mfd/hi6421-pmic-core.c +++ b/drivers/mfd/hi6421-pmic-core.c @@ -1,40 +1,35 @@ /* - * Device driver for Hi6421 IC + * Device driver for Hi6421 PMIC * * Copyright (c) <2011-2014> HiSilicon Technologies Co., Ltd. * http://www.hisilicon.com - * Copyright (c) <2013-2014> Linaro Ltd. + * Copyright (c) <2013-2017> Linaro Ltd. * http://www.linaro.org * * Author: Guodong Xu <guodong.xu@linaro.org> * * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. */ #include <linux/device.h> #include <linux/err.h> #include <linux/mfd/core.h> +#include <linux/mfd/hi6421-pmic.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/mfd/hi6421-pmic.h> static const struct mfd_cell hi6421_devs[] = { { .name = "hi6421-regulator", }, }; +static const struct mfd_cell hi6421v530_devs[] = { + { .name = "hi6421v530-regulator", }, +}; + static const struct regmap_config hi6421_regmap_config = { .reg_bits = 32, .reg_stride = 4, @@ -42,12 +37,30 @@ static const struct regmap_config hi6421_regmap_config = { .max_register = HI6421_REG_TO_BUS_ADDR(HI6421_REG_MAX), }; +static const struct of_device_id of_hi6421_pmic_match[] = { + { .compatible = "hisilicon,hi6421-pmic", + .data = (void *)HI6421 }, + { .compatible = "hisilicon,hi6421v530-pmic", + .data = (void *)HI6421_V530 }, + { }, +}; +MODULE_DEVICE_TABLE(of, of_hi6421_pmic_match); + static int hi6421_pmic_probe(struct platform_device *pdev) { struct hi6421_pmic *pmic; struct resource *res; void __iomem *base; - int ret; + const struct of_device_id *id; + unsigned long type; + const struct mfd_cell *subdevs = NULL; + int n_subdevs, ret; + + id = of_match_device(of_hi6421_pmic_match, &pdev->dev); + if (id) + type = (unsigned long)id->data; + else + return -EINVAL; pmic = devm_kzalloc(&pdev->dev, sizeof(*pmic), GFP_KERNEL); if (!pmic) @@ -61,41 +74,49 @@ static int hi6421_pmic_probe(struct platform_device *pdev) pmic->regmap = devm_regmap_init_mmio_clk(&pdev->dev, NULL, base, &hi6421_regmap_config); if (IS_ERR(pmic->regmap)) { - dev_err(&pdev->dev, - "regmap init failed: %ld\n", PTR_ERR(pmic->regmap)); + dev_err(&pdev->dev, "Failed to initialise Regmap: %ld\n", + PTR_ERR(pmic->regmap)); return PTR_ERR(pmic->regmap); } - /* set over-current protection debounce 8ms */ - regmap_update_bits(pmic->regmap, HI6421_OCP_DEB_CTRL_REG, + platform_set_drvdata(pdev, pmic); + + switch (type) { + case HI6421: + /* set over-current protection debounce 8ms */ + regmap_update_bits(pmic->regmap, HI6421_OCP_DEB_CTRL_REG, (HI6421_OCP_DEB_SEL_MASK | HI6421_OCP_EN_DEBOUNCE_MASK | HI6421_OCP_AUTO_STOP_MASK), (HI6421_OCP_DEB_SEL_8MS | HI6421_OCP_EN_DEBOUNCE_ENABLE)); - platform_set_drvdata(pdev, pmic); + subdevs = hi6421_devs; + n_subdevs = ARRAY_SIZE(hi6421_devs); + break; + case HI6421_V530: + subdevs = hi6421v530_devs; + n_subdevs = ARRAY_SIZE(hi6421v530_devs); + break; + default: + dev_err(&pdev->dev, "Unknown device type %ld\n", type); + return -EINVAL; + } - ret = devm_mfd_add_devices(&pdev->dev, 0, hi6421_devs, - ARRAY_SIZE(hi6421_devs), NULL, 0, NULL); + ret = devm_mfd_add_devices(&pdev->dev, 0, subdevs, + n_subdevs, NULL, 0, NULL); if (ret) { - dev_err(&pdev->dev, "add mfd devices failed: %d\n", ret); + dev_err(&pdev->dev, "Failed to add child devices: %d\n", ret); return ret; } return 0; } -static const struct of_device_id of_hi6421_pmic_match_tbl[] = { - { .compatible = "hisilicon,hi6421-pmic", }, - { }, -}; -MODULE_DEVICE_TABLE(of, of_hi6421_pmic_match_tbl); - static struct platform_driver hi6421_pmic_driver = { .driver = { - .name = "hi6421_pmic", - .of_match_table = of_hi6421_pmic_match_tbl, + .name = "hi6421_pmic", + .of_match_table = of_hi6421_pmic_match, }, .probe = hi6421_pmic_probe, }; diff --git a/include/linux/mfd/hi6421-pmic.h b/include/linux/mfd/hi6421-pmic.h index 587273e..2457438 100644 --- a/include/linux/mfd/hi6421-pmic.h +++ b/include/linux/mfd/hi6421-pmic.h @@ -38,4 +38,9 @@ struct hi6421_pmic { struct regmap *regmap; }; +enum hi6421_type { + HI6421 = 1, + HI6421_V530 = 2, +}; + #endif /* __HI6421_PMIC_H */ -- 2.10.2 ^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v3 2/6] mfd: hi6421-pmic: add support for HiSilicon Hi6421v530 2017-06-02 10:51 ` [PATCH v3 2/6] mfd: hi6421-pmic: add support for HiSilicon Hi6421v530 Guodong Xu @ 2017-06-05 8:24 ` Lee Jones 2017-06-05 11:57 ` Guodong Xu 0 siblings, 1 reply; 12+ messages in thread From: Lee Jones @ 2017-06-05 8:24 UTC (permalink / raw) To: linux-arm-kernel On Fri, 02 Jun 2017, Guodong Xu wrote: > Add support for HiSilicon Hi6421v530 PMIC. Hi6421v530 communicates with > main SoC via memory-mapped I/O. > > Hi6421v530 and Hi6421 are PMIC chips from the same vendor, HiSilicon, > but at different revisions. They share the same memory-mapped I/O > design. They differ in integrated devices, such as regulator details, > LDO voltage points. > > Also, changed license to a shorter form, and arranged all #include in > alphabetical order. > > Signed-off-by: Wang Xiaoyin <hw.wangxiaoyin@hisilicon.com> > Signed-off-by: Guodong Xu <guodong.xu@linaro.org> > --- > drivers/mfd/hi6421-pmic-core.c | 85 +++++++++++++++++++++++++---------------- > include/linux/mfd/hi6421-pmic.h | 5 +++ > 2 files changed, 58 insertions(+), 32 deletions(-) > > diff --git a/drivers/mfd/hi6421-pmic-core.c b/drivers/mfd/hi6421-pmic-core.c > index 3fd703f..b914541 100644 > --- a/drivers/mfd/hi6421-pmic-core.c > +++ b/drivers/mfd/hi6421-pmic-core.c > @@ -1,40 +1,35 @@ > /* > - * Device driver for Hi6421 IC > + * Device driver for Hi6421 PMIC > * > * Copyright (c) <2011-2014> HiSilicon Technologies Co., Ltd. > * http://www.hisilicon.com > - * Copyright (c) <2013-2014> Linaro Ltd. > + * Copyright (c) <2013-2017> Linaro Ltd. > * http://www.linaro.org > * > * Author: Guodong Xu <guodong.xu@linaro.org> > * > * This program is free software; you can redistribute it and/or modify > - * it under the terms of the GNU General Public License as published by > - * the Free Software Foundation; either version 2 of the License, or > - * (at your option) any later version. > - * > - * This program is distributed in the hope it will be useful, but WITHOUT > - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or > - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for > - * more details. > - * > - * You should have received a copy of the GNU General Public License > - * along with this program. If not, see <http://www.gnu.org/licenses/>. > + * it under the terms of the GNU General Public License version 2 as > + * published by the Free Software Foundation. Nice change, but this should be a separate patch. > */ > > #include <linux/device.h> > #include <linux/err.h> > #include <linux/mfd/core.h> > +#include <linux/mfd/hi6421-pmic.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/mfd/hi6421-pmic.h> > > static const struct mfd_cell hi6421_devs[] = { > { .name = "hi6421-regulator", }, > }; > > +static const struct mfd_cell hi6421v530_devs[] = { > + { .name = "hi6421v530-regulator", }, > +}; > + > static const struct regmap_config hi6421_regmap_config = { > .reg_bits = 32, > .reg_stride = 4, > @@ -42,12 +37,30 @@ static const struct regmap_config hi6421_regmap_config = { > .max_register = HI6421_REG_TO_BUS_ADDR(HI6421_REG_MAX), > }; > > +static const struct of_device_id of_hi6421_pmic_match[] = { > + { .compatible = "hisilicon,hi6421-pmic", > + .data = (void *)HI6421 }, > + { .compatible = "hisilicon,hi6421v530-pmic", > + .data = (void *)HI6421_V530 }, > + { }, > +}; > +MODULE_DEVICE_TABLE(of, of_hi6421_pmic_match); This formatting is odd. If both attributes won't fit on a single line, please place them on completely separate lines. This includes the braces. Something like this: { .compatible = "hisilicon,hi6421-pmic", .data = (void *)HI6421 }, { .compatible = "hisilicon,hi6421v530-pmic", .data = (void *)HI6421_V530 }, { }, > static int hi6421_pmic_probe(struct platform_device *pdev) > { > struct hi6421_pmic *pmic; > struct resource *res; > void __iomem *base; > - int ret; > + const struct of_device_id *id; > + unsigned long type; > + const struct mfd_cell *subdevs = NULL; > + int n_subdevs, ret; Better to reorganise this a little. I tend to have the complex data types at the top running down to simple 'int' types at the bottom. > + id = of_match_device(of_hi6421_pmic_match, &pdev->dev); > + if (id) > + type = (unsigned long)id->data; > + else > + return -EINVAL; Place "!id" in the if statement, then you can drop the else. > pmic = devm_kzalloc(&pdev->dev, sizeof(*pmic), GFP_KERNEL); > if (!pmic) > @@ -61,41 +74,49 @@ static int hi6421_pmic_probe(struct platform_device *pdev) > pmic->regmap = devm_regmap_init_mmio_clk(&pdev->dev, NULL, base, > &hi6421_regmap_config); > if (IS_ERR(pmic->regmap)) { > - dev_err(&pdev->dev, > - "regmap init failed: %ld\n", PTR_ERR(pmic->regmap)); > + dev_err(&pdev->dev, "Failed to initialise Regmap: %ld\n", > + PTR_ERR(pmic->regmap)); Separate patch. > return PTR_ERR(pmic->regmap); > } > > - /* set over-current protection debounce 8ms */ > - regmap_update_bits(pmic->regmap, HI6421_OCP_DEB_CTRL_REG, > + platform_set_drvdata(pdev, pmic); > + > + switch (type) { > + case HI6421: > + /* set over-current protection debounce 8ms */ > + regmap_update_bits(pmic->regmap, HI6421_OCP_DEB_CTRL_REG, > (HI6421_OCP_DEB_SEL_MASK > | HI6421_OCP_EN_DEBOUNCE_MASK > | HI6421_OCP_AUTO_STOP_MASK), > (HI6421_OCP_DEB_SEL_8MS > | HI6421_OCP_EN_DEBOUNCE_ENABLE)); > > - platform_set_drvdata(pdev, pmic); > + subdevs = hi6421_devs; > + n_subdevs = ARRAY_SIZE(hi6421_devs); > + break; > + case HI6421_V530: > + subdevs = hi6421v530_devs; > + n_subdevs = ARRAY_SIZE(hi6421v530_devs); > + break; > + default: > + dev_err(&pdev->dev, "Unknown device type %ld\n", type); > + return -EINVAL; > + } > > - ret = devm_mfd_add_devices(&pdev->dev, 0, hi6421_devs, > - ARRAY_SIZE(hi6421_devs), NULL, 0, NULL); > + ret = devm_mfd_add_devices(&pdev->dev, 0, subdevs, Use the proper defines, not '0'. > + n_subdevs, NULL, 0, NULL); > if (ret) { > - dev_err(&pdev->dev, "add mfd devices failed: %d\n", ret); > + dev_err(&pdev->dev, "Failed to add child devices: %d\n", ret); This needs to be grouped with the other error message change above. > return ret; > } > > return 0; > } > > -static const struct of_device_id of_hi6421_pmic_match_tbl[] = { > - { .compatible = "hisilicon,hi6421-pmic", }, > - { }, > -}; > -MODULE_DEVICE_TABLE(of, of_hi6421_pmic_match_tbl); > - > static struct platform_driver hi6421_pmic_driver = { > .driver = { > - .name = "hi6421_pmic", > - .of_match_table = of_hi6421_pmic_match_tbl, > + .name = "hi6421_pmic", > + .of_match_table = of_hi6421_pmic_match, > }, > .probe = hi6421_pmic_probe, > }; > diff --git a/include/linux/mfd/hi6421-pmic.h b/include/linux/mfd/hi6421-pmic.h > index 587273e..2457438 100644 > --- a/include/linux/mfd/hi6421-pmic.h > +++ b/include/linux/mfd/hi6421-pmic.h > @@ -38,4 +38,9 @@ struct hi6421_pmic { > struct regmap *regmap; > }; > > +enum hi6421_type { > + HI6421 = 1, > + HI6421_V530 = 2, Why 1 and 2? > +}; > + > #endif /* __HI6421_PMIC_H */ -- Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org ? Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog ^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v3 2/6] mfd: hi6421-pmic: add support for HiSilicon Hi6421v530 2017-06-05 8:24 ` Lee Jones @ 2017-06-05 11:57 ` Guodong Xu 0 siblings, 0 replies; 12+ messages in thread From: Guodong Xu @ 2017-06-05 11:57 UTC (permalink / raw) To: linux-arm-kernel On Mon, Jun 5, 2017 at 4:24 PM, Lee Jones <lee.jones@linaro.org> wrote: > On Fri, 02 Jun 2017, Guodong Xu wrote: > >> Add support for HiSilicon Hi6421v530 PMIC. Hi6421v530 communicates with >> main SoC via memory-mapped I/O. >> >> Hi6421v530 and Hi6421 are PMIC chips from the same vendor, HiSilicon, >> but at different revisions. They share the same memory-mapped I/O >> design. They differ in integrated devices, such as regulator details, >> LDO voltage points. >> >> Also, changed license to a shorter form, and arranged all #include in >> alphabetical order. >> >> Signed-off-by: Wang Xiaoyin <hw.wangxiaoyin@hisilicon.com> >> Signed-off-by: Guodong Xu <guodong.xu@linaro.org> >> --- >> drivers/mfd/hi6421-pmic-core.c | 85 +++++++++++++++++++++++++---------------- >> include/linux/mfd/hi6421-pmic.h | 5 +++ >> 2 files changed, 58 insertions(+), 32 deletions(-) >> >> diff --git a/drivers/mfd/hi6421-pmic-core.c b/drivers/mfd/hi6421-pmic-core.c >> index 3fd703f..b914541 100644 >> --- a/drivers/mfd/hi6421-pmic-core.c >> +++ b/drivers/mfd/hi6421-pmic-core.c >> @@ -1,40 +1,35 @@ >> /* >> - * Device driver for Hi6421 IC >> + * Device driver for Hi6421 PMIC >> * >> * Copyright (c) <2011-2014> HiSilicon Technologies Co., Ltd. >> * http://www.hisilicon.com >> - * Copyright (c) <2013-2014> Linaro Ltd. >> + * Copyright (c) <2013-2017> Linaro Ltd. >> * http://www.linaro.org >> * >> * Author: Guodong Xu <guodong.xu@linaro.org> >> * >> * This program is free software; you can redistribute it and/or modify >> - * it under the terms of the GNU General Public License as published by >> - * the Free Software Foundation; either version 2 of the License, or >> - * (at your option) any later version. >> - * >> - * This program is distributed in the hope it will be useful, but WITHOUT >> - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or >> - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for >> - * more details. >> - * >> - * You should have received a copy of the GNU General Public License >> - * along with this program. If not, see <http://www.gnu.org/licenses/>. >> + * it under the terms of the GNU General Public License version 2 as >> + * published by the Free Software Foundation. > > Nice change, but this should be a separate patch. > I will add that as a separate patch. >> */ >> >> #include <linux/device.h> >> #include <linux/err.h> >> #include <linux/mfd/core.h> >> +#include <linux/mfd/hi6421-pmic.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/mfd/hi6421-pmic.h> >> >> static const struct mfd_cell hi6421_devs[] = { >> { .name = "hi6421-regulator", }, >> }; >> >> +static const struct mfd_cell hi6421v530_devs[] = { >> + { .name = "hi6421v530-regulator", }, >> +}; >> + >> static const struct regmap_config hi6421_regmap_config = { >> .reg_bits = 32, >> .reg_stride = 4, >> @@ -42,12 +37,30 @@ static const struct regmap_config hi6421_regmap_config = { >> .max_register = HI6421_REG_TO_BUS_ADDR(HI6421_REG_MAX), >> }; >> >> +static const struct of_device_id of_hi6421_pmic_match[] = { >> + { .compatible = "hisilicon,hi6421-pmic", >> + .data = (void *)HI6421 }, >> + { .compatible = "hisilicon,hi6421v530-pmic", >> + .data = (void *)HI6421_V530 }, >> + { }, >> +}; >> +MODULE_DEVICE_TABLE(of, of_hi6421_pmic_match); > > This formatting is odd. If both attributes won't fit on a single > line, please place them on completely separate lines. This includes > the braces. Something like this: > > { > .compatible = "hisilicon,hi6421-pmic", > .data = (void *)HI6421 > }, { > .compatible = "hisilicon,hi6421v530-pmic", > .data = (void *)HI6421_V530 }, > { }, > Thanks, I will change that. >> static int hi6421_pmic_probe(struct platform_device *pdev) >> { >> struct hi6421_pmic *pmic; >> struct resource *res; >> void __iomem *base; >> - int ret; >> + const struct of_device_id *id; >> + unsigned long type; >> + const struct mfd_cell *subdevs = NULL; >> + int n_subdevs, ret; > > Better to reorganise this a little. I tend to have the complex data > types at the top running down to simple 'int' types at the bottom. > Sure. I will update. >> + id = of_match_device(of_hi6421_pmic_match, &pdev->dev); >> + if (id) >> + type = (unsigned long)id->data; >> + else >> + return -EINVAL; > > Place "!id" in the if statement, then you can drop the else. > Thanks. I will update. >> pmic = devm_kzalloc(&pdev->dev, sizeof(*pmic), GFP_KERNEL); >> if (!pmic) >> @@ -61,41 +74,49 @@ static int hi6421_pmic_probe(struct platform_device *pdev) >> pmic->regmap = devm_regmap_init_mmio_clk(&pdev->dev, NULL, base, >> &hi6421_regmap_config); >> if (IS_ERR(pmic->regmap)) { >> - dev_err(&pdev->dev, >> - "regmap init failed: %ld\n", PTR_ERR(pmic->regmap)); >> + dev_err(&pdev->dev, "Failed to initialise Regmap: %ld\n", >> + PTR_ERR(pmic->regmap)); > > Separate patch. > I will do. >> return PTR_ERR(pmic->regmap); >> } >> >> - /* set over-current protection debounce 8ms */ >> - regmap_update_bits(pmic->regmap, HI6421_OCP_DEB_CTRL_REG, >> + platform_set_drvdata(pdev, pmic); >> + >> + switch (type) { >> + case HI6421: >> + /* set over-current protection debounce 8ms */ >> + regmap_update_bits(pmic->regmap, HI6421_OCP_DEB_CTRL_REG, >> (HI6421_OCP_DEB_SEL_MASK >> | HI6421_OCP_EN_DEBOUNCE_MASK >> | HI6421_OCP_AUTO_STOP_MASK), >> (HI6421_OCP_DEB_SEL_8MS >> | HI6421_OCP_EN_DEBOUNCE_ENABLE)); >> >> - platform_set_drvdata(pdev, pmic); >> + subdevs = hi6421_devs; >> + n_subdevs = ARRAY_SIZE(hi6421_devs); >> + break; >> + case HI6421_V530: >> + subdevs = hi6421v530_devs; >> + n_subdevs = ARRAY_SIZE(hi6421v530_devs); >> + break; >> + default: >> + dev_err(&pdev->dev, "Unknown device type %ld\n", type); >> + return -EINVAL; >> + } >> >> - ret = devm_mfd_add_devices(&pdev->dev, 0, hi6421_devs, >> - ARRAY_SIZE(hi6421_devs), NULL, 0, NULL); >> + ret = devm_mfd_add_devices(&pdev->dev, 0, subdevs, > > Use the proper defines, not '0'. I'll change this to PLATFORM_DEVID_NONE > >> + n_subdevs, NULL, 0, NULL); >> if (ret) { >> - dev_err(&pdev->dev, "add mfd devices failed: %d\n", ret); >> + dev_err(&pdev->dev, "Failed to add child devices: %d\n", ret); > > This needs to be grouped with the other error message change above. > will do. >> return ret; >> } >> >> return 0; >> } >> >> -static const struct of_device_id of_hi6421_pmic_match_tbl[] = { >> - { .compatible = "hisilicon,hi6421-pmic", }, >> - { }, >> -}; >> -MODULE_DEVICE_TABLE(of, of_hi6421_pmic_match_tbl); >> - >> static struct platform_driver hi6421_pmic_driver = { >> .driver = { >> - .name = "hi6421_pmic", >> - .of_match_table = of_hi6421_pmic_match_tbl, >> + .name = "hi6421_pmic", >> + .of_match_table = of_hi6421_pmic_match, >> }, >> .probe = hi6421_pmic_probe, >> }; >> diff --git a/include/linux/mfd/hi6421-pmic.h b/include/linux/mfd/hi6421-pmic.h >> index 587273e..2457438 100644 >> --- a/include/linux/mfd/hi6421-pmic.h >> +++ b/include/linux/mfd/hi6421-pmic.h >> @@ -38,4 +38,9 @@ struct hi6421_pmic { >> struct regmap *regmap; >> }; >> >> +enum hi6421_type { >> + HI6421 = 1, >> + HI6421_V530 = 2, > > Why 1 and 2? > I didn't get your point. I have no special reason. Actually, any value should work. I just need two value to differentiate two chips. Did you see any problem if I use 1 and 2? -Guodong >> +}; >> + >> #endif /* __HI6421_PMIC_H */ > > -- > Lee Jones > Linaro STMicroelectronics Landing Team Lead > Linaro.org ? Open source software for ARM SoCs > Follow Linaro: Facebook | Twitter | Blog ^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v3 3/6] regulator: hi6421v530: add driver for hi6421v530 voltage regulator 2017-06-02 10:51 [PATCH v3 0/6] MFD: add driver for HiSilicon Hi6421v530 PMIC Guodong Xu 2017-06-02 10:51 ` [PATCH v3 1/6] dt-bindings: mfd: hi6421: Add hi6421v530 compatible string Guodong Xu 2017-06-02 10:51 ` [PATCH v3 2/6] mfd: hi6421-pmic: add support for HiSilicon Hi6421v530 Guodong Xu @ 2017-06-02 10:51 ` Guodong Xu 2017-06-07 19:32 ` Applied "regulator: hi6421v530: add driver for hi6421v530 voltage regulator" to the regulator tree Mark Brown 2017-06-02 10:51 ` [PATCH v3 4/6] regulator: hi6421: Describe consumed platform device Guodong Xu ` (2 subsequent siblings) 5 siblings, 1 reply; 12+ messages in thread From: Guodong Xu @ 2017-06-02 10:51 UTC (permalink / raw) To: linux-arm-kernel From: Wang Xiaoyin <hw.wangxiaoyin@hisilicon.com> add the driver for hi6421v530 voltage regulator Signed-off-by: Wang Xiaoyin <hw.wangxiaoyin@hisilicon.com> Signed-off-by: Guodong Xu <guodong.xu@linaro.org> --- drivers/regulator/Kconfig | 10 ++ drivers/regulator/Makefile | 1 + drivers/regulator/hi6421v530-regulator.c | 207 +++++++++++++++++++++++++++++++ 3 files changed, 218 insertions(+) create mode 100644 drivers/regulator/hi6421v530-regulator.c diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig index 48db87d..78cd8d8 100644 --- a/drivers/regulator/Kconfig +++ b/drivers/regulator/Kconfig @@ -296,6 +296,16 @@ config REGULATOR_HI6421 21 general purpose LDOs, 3 dedicated LDOs, and 5 BUCKs. All of them come with support to either ECO (idle) or sleep mode. +config REGULATOR_HI6421V530 + tristate "HiSilicon Hi6421v530 PMIC voltage regulator support" + depends on MFD_HI6421_PMIC && OF + help + This driver provides support for the voltage regulators on + HiSilicon Hi6421v530 PMU / Codec IC. + Hi6421v530 is a multi-function device which, on regulator part, + provides 5 general purpose LDOs, and all of them come with support + to either ECO (idle) or sleep mode. + config REGULATOR_HI655X tristate "Hisilicon HI655X PMIC regulators support" depends on ARCH_HISI || COMPILE_TEST diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile index dc3503f..36e2b75 100644 --- a/drivers/regulator/Makefile +++ b/drivers/regulator/Makefile @@ -38,6 +38,7 @@ obj-$(CONFIG_REGULATOR_DB8500_PRCMU) += db8500-prcmu.o obj-$(CONFIG_REGULATOR_FAN53555) += fan53555.o obj-$(CONFIG_REGULATOR_GPIO) += gpio-regulator.o obj-$(CONFIG_REGULATOR_HI6421) += hi6421-regulator.o +obj-$(CONFIG_REGULATOR_HI6421V530) += hi6421v530-regulator.o obj-$(CONFIG_REGULATOR_HI655X) += hi655x-regulator.o obj-$(CONFIG_REGULATOR_ISL6271A) += isl6271a-regulator.o obj-$(CONFIG_REGULATOR_ISL9305) += isl9305.o diff --git a/drivers/regulator/hi6421v530-regulator.c b/drivers/regulator/hi6421v530-regulator.c new file mode 100644 index 0000000..46bbba9 --- /dev/null +++ b/drivers/regulator/hi6421v530-regulator.c @@ -0,0 +1,207 @@ +/* + * Device driver for regulators in Hi6421V530 IC + * + * Copyright (c) <2017> HiSilicon Technologies Co., Ltd. + * http://www.hisilicon.com + * Copyright (c) <2017> Linaro Ltd. + * http://www.linaro.org + * + * Author: Wang Xiaoyin <hw.wangxiaoyin@hisilicon.com> + * Guodong Xu <guodong.xu@linaro.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include <linux/mfd/hi6421-pmic.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/platform_device.h> +#include <linux/regmap.h> +#include <linux/regulator/driver.h> + +/* + * struct hi6421v530_regulator_info - hi6421v530 regulator information + * @desc: regulator description + * @mode_mask: ECO mode bitmask of LDOs; for BUCKs, this masks sleep + * @eco_microamp: eco mode load upper limit (in uA), valid for LDOs only + */ +struct hi6421v530_regulator_info { + struct regulator_desc rdesc; + u8 mode_mask; + u32 eco_microamp; +}; + +/* HI6421v530 regulators */ +enum hi6421v530_regulator_id { + HI6421V530_LDO3, + HI6421V530_LDO9, + HI6421V530_LDO11, + HI6421V530_LDO15, + HI6421V530_LDO16, +}; + +static const unsigned int ldo_3_voltages[] = { + 1800000, 1825000, 1850000, 1875000, + 1900000, 1925000, 1950000, 1975000, + 2000000, 2025000, 2050000, 2075000, + 2100000, 2125000, 2150000, 2200000, +}; + +static const unsigned int ldo_9_11_voltages[] = { + 1750000, 1800000, 1825000, 2800000, + 2850000, 2950000, 3000000, 3300000, +}; + +static const unsigned int ldo_15_16_voltages[] = { + 1750000, 1800000, 2400000, 2600000, + 2700000, 2850000, 2950000, 3000000, +}; + +static const struct regulator_ops hi6421v530_ldo_ops; + +#define HI6421V530_LDO_ENABLE_TIME (350) + +/* + * _id - LDO id name string + * v_table - voltage table + * vreg - voltage select register + * vmask - voltage select mask + * ereg - enable register + * emask - enable mask + * odelay - off/on delay time in uS + * ecomask - eco mode mask + * ecoamp - eco mode load uppler limit in uA + */ +#define HI6421V530_LDO(_ID, v_table, vreg, vmask, ereg, emask, \ + odelay, ecomask, ecoamp) { \ + .rdesc = { \ + .name = #_ID, \ + .of_match = of_match_ptr(#_ID), \ + .regulators_node = of_match_ptr("regulators"), \ + .ops = &hi6421v530_ldo_ops, \ + .type = REGULATOR_VOLTAGE, \ + .id = HI6421V530_##_ID, \ + .owner = THIS_MODULE, \ + .n_voltages = ARRAY_SIZE(v_table), \ + .volt_table = v_table, \ + .vsel_reg = HI6421_REG_TO_BUS_ADDR(vreg), \ + .vsel_mask = vmask, \ + .enable_reg = HI6421_REG_TO_BUS_ADDR(ereg), \ + .enable_mask = emask, \ + .enable_time = HI6421V530_LDO_ENABLE_TIME, \ + .off_on_delay = odelay, \ + }, \ + .mode_mask = ecomask, \ + .eco_microamp = ecoamp, \ +} + +/* HI6421V530 regulator information */ + +static struct hi6421v530_regulator_info hi6421v530_regulator_info[] = { + HI6421V530_LDO(LDO3, ldo_3_voltages, 0x061, 0xf, 0x060, 0x2, + 20000, 0x6, 8000), + HI6421V530_LDO(LDO9, ldo_9_11_voltages, 0x06b, 0x7, 0x06a, 0x2, + 40000, 0x6, 8000), + HI6421V530_LDO(LDO11, ldo_9_11_voltages, 0x06f, 0x7, 0x06e, 0x2, + 40000, 0x6, 8000), + HI6421V530_LDO(LDO15, ldo_15_16_voltages, 0x077, 0x7, 0x076, 0x2, + 40000, 0x6, 8000), + HI6421V530_LDO(LDO16, ldo_15_16_voltages, 0x079, 0x7, 0x078, 0x2, + 40000, 0x6, 8000), +}; + +static unsigned int hi6421v530_regulator_ldo_get_mode( + struct regulator_dev *rdev) +{ + struct hi6421v530_regulator_info *info; + unsigned int reg_val; + + info = rdev_get_drvdata(rdev); + regmap_read(rdev->regmap, rdev->desc->enable_reg, ®_val); + + if (reg_val & (info->mode_mask)) + return REGULATOR_MODE_IDLE; + + return REGULATOR_MODE_NORMAL; +} + +static int hi6421v530_regulator_ldo_set_mode(struct regulator_dev *rdev, + unsigned int mode) +{ + struct hi6421v530_regulator_info *info; + unsigned int new_mode; + + info = rdev_get_drvdata(rdev); + switch (mode) { + case REGULATOR_MODE_NORMAL: + new_mode = 0; + break; + case REGULATOR_MODE_IDLE: + new_mode = info->mode_mask; + break; + default: + return -EINVAL; + } + + regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, + info->mode_mask, new_mode); + + return 0; +} + + +static const struct regulator_ops hi6421v530_ldo_ops = { + .is_enabled = regulator_is_enabled_regmap, + .enable = regulator_enable_regmap, + .disable = regulator_disable_regmap, + .list_voltage = regulator_list_voltage_table, + .map_voltage = regulator_map_voltage_ascend, + .get_voltage_sel = regulator_get_voltage_sel_regmap, + .set_voltage_sel = regulator_set_voltage_sel_regmap, + .get_mode = hi6421v530_regulator_ldo_get_mode, + .set_mode = hi6421v530_regulator_ldo_set_mode, +}; + +static int hi6421v530_regulator_probe(struct platform_device *pdev) +{ + struct hi6421_pmic *pmic; + struct regulator_dev *rdev; + struct regulator_config config = { }; + unsigned int i; + + pmic = dev_get_drvdata(pdev->dev.parent); + if (!pmic) { + dev_err(&pdev->dev, "no pmic in the regulator parent node\n"); + return -ENODEV; + } + + for (i = 0; i < ARRAY_SIZE(hi6421v530_regulator_info); i++) { + config.dev = pdev->dev.parent; + config.regmap = pmic->regmap; + config.driver_data = &hi6421v530_regulator_info[i]; + + rdev = devm_regulator_register(&pdev->dev, + &hi6421v530_regulator_info[i].rdesc, + &config); + if (IS_ERR(rdev)) { + dev_err(&pdev->dev, "failed to register regulator %s\n", + hi6421v530_regulator_info[i].rdesc.name); + return PTR_ERR(rdev); + } + } + return 0; +} + +static struct platform_driver hi6421v530_regulator_driver = { + .driver = { + .name = "hi6421v530-regulator", + }, + .probe = hi6421v530_regulator_probe, +}; +module_platform_driver(hi6421v530_regulator_driver); + +MODULE_AUTHOR("Wang Xiaoyin <hw.wangxiaoyin@hisilicon.com>"); +MODULE_DESCRIPTION("Hi6421v530 regulator driver"); +MODULE_LICENSE("GPL v2"); -- 2.10.2 ^ permalink raw reply related [flat|nested] 12+ messages in thread
* Applied "regulator: hi6421v530: add driver for hi6421v530 voltage regulator" to the regulator tree 2017-06-02 10:51 ` [PATCH v3 3/6] regulator: hi6421v530: add driver for hi6421v530 voltage regulator Guodong Xu @ 2017-06-07 19:32 ` Mark Brown 0 siblings, 0 replies; 12+ messages in thread From: Mark Brown @ 2017-06-07 19:32 UTC (permalink / raw) To: linux-arm-kernel The patch regulator: hi6421v530: add driver for hi6421v530 voltage regulator has been applied to the regulator tree at git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator.git All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted. You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed. If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced. Please add any relevant lists and maintainers to the CCs when replying to this mail. Thanks, Mark >From 5c7024ae7e6787541dd737ba1eba828d5fc74d58 Mon Sep 17 00:00:00 2001 From: Wang Xiaoyin <hw.wangxiaoyin@hisilicon.com> Date: Wed, 7 Jun 2017 15:06:03 +0800 Subject: [PATCH] regulator: hi6421v530: add driver for hi6421v530 voltage regulator add the driver for hi6421v530 voltage regulator Signed-off-by: Wang Xiaoyin <hw.wangxiaoyin@hisilicon.com> Signed-off-by: Guodong Xu <guodong.xu@linaro.org> Signed-off-by: Mark Brown <broonie@kernel.org> --- drivers/regulator/Kconfig | 10 ++ drivers/regulator/Makefile | 1 + drivers/regulator/hi6421v530-regulator.c | 207 +++++++++++++++++++++++++++++++ 3 files changed, 218 insertions(+) create mode 100644 drivers/regulator/hi6421v530-regulator.c diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig index 48db87d6dfef..78cd8d84a2cb 100644 --- a/drivers/regulator/Kconfig +++ b/drivers/regulator/Kconfig @@ -296,6 +296,16 @@ config REGULATOR_HI6421 21 general purpose LDOs, 3 dedicated LDOs, and 5 BUCKs. All of them come with support to either ECO (idle) or sleep mode. +config REGULATOR_HI6421V530 + tristate "HiSilicon Hi6421v530 PMIC voltage regulator support" + depends on MFD_HI6421_PMIC && OF + help + This driver provides support for the voltage regulators on + HiSilicon Hi6421v530 PMU / Codec IC. + Hi6421v530 is a multi-function device which, on regulator part, + provides 5 general purpose LDOs, and all of them come with support + to either ECO (idle) or sleep mode. + config REGULATOR_HI655X tristate "Hisilicon HI655X PMIC regulators support" depends on ARCH_HISI || COMPILE_TEST diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile index dc3503fb3e30..36e2b750b188 100644 --- a/drivers/regulator/Makefile +++ b/drivers/regulator/Makefile @@ -38,6 +38,7 @@ obj-$(CONFIG_REGULATOR_DB8500_PRCMU) += db8500-prcmu.o obj-$(CONFIG_REGULATOR_FAN53555) += fan53555.o obj-$(CONFIG_REGULATOR_GPIO) += gpio-regulator.o obj-$(CONFIG_REGULATOR_HI6421) += hi6421-regulator.o +obj-$(CONFIG_REGULATOR_HI6421V530) += hi6421v530-regulator.o obj-$(CONFIG_REGULATOR_HI655X) += hi655x-regulator.o obj-$(CONFIG_REGULATOR_ISL6271A) += isl6271a-regulator.o obj-$(CONFIG_REGULATOR_ISL9305) += isl9305.o diff --git a/drivers/regulator/hi6421v530-regulator.c b/drivers/regulator/hi6421v530-regulator.c new file mode 100644 index 000000000000..46bbba96307f --- /dev/null +++ b/drivers/regulator/hi6421v530-regulator.c @@ -0,0 +1,207 @@ +/* + * Device driver for regulators in Hi6421V530 IC + * + * Copyright (c) <2017> HiSilicon Technologies Co., Ltd. + * http://www.hisilicon.com + * Copyright (c) <2017> Linaro Ltd. + * http://www.linaro.org + * + * Author: Wang Xiaoyin <hw.wangxiaoyin@hisilicon.com> + * Guodong Xu <guodong.xu@linaro.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include <linux/mfd/hi6421-pmic.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/platform_device.h> +#include <linux/regmap.h> +#include <linux/regulator/driver.h> + +/* + * struct hi6421v530_regulator_info - hi6421v530 regulator information + * @desc: regulator description + * @mode_mask: ECO mode bitmask of LDOs; for BUCKs, this masks sleep + * @eco_microamp: eco mode load upper limit (in uA), valid for LDOs only + */ +struct hi6421v530_regulator_info { + struct regulator_desc rdesc; + u8 mode_mask; + u32 eco_microamp; +}; + +/* HI6421v530 regulators */ +enum hi6421v530_regulator_id { + HI6421V530_LDO3, + HI6421V530_LDO9, + HI6421V530_LDO11, + HI6421V530_LDO15, + HI6421V530_LDO16, +}; + +static const unsigned int ldo_3_voltages[] = { + 1800000, 1825000, 1850000, 1875000, + 1900000, 1925000, 1950000, 1975000, + 2000000, 2025000, 2050000, 2075000, + 2100000, 2125000, 2150000, 2200000, +}; + +static const unsigned int ldo_9_11_voltages[] = { + 1750000, 1800000, 1825000, 2800000, + 2850000, 2950000, 3000000, 3300000, +}; + +static const unsigned int ldo_15_16_voltages[] = { + 1750000, 1800000, 2400000, 2600000, + 2700000, 2850000, 2950000, 3000000, +}; + +static const struct regulator_ops hi6421v530_ldo_ops; + +#define HI6421V530_LDO_ENABLE_TIME (350) + +/* + * _id - LDO id name string + * v_table - voltage table + * vreg - voltage select register + * vmask - voltage select mask + * ereg - enable register + * emask - enable mask + * odelay - off/on delay time in uS + * ecomask - eco mode mask + * ecoamp - eco mode load uppler limit in uA + */ +#define HI6421V530_LDO(_ID, v_table, vreg, vmask, ereg, emask, \ + odelay, ecomask, ecoamp) { \ + .rdesc = { \ + .name = #_ID, \ + .of_match = of_match_ptr(#_ID), \ + .regulators_node = of_match_ptr("regulators"), \ + .ops = &hi6421v530_ldo_ops, \ + .type = REGULATOR_VOLTAGE, \ + .id = HI6421V530_##_ID, \ + .owner = THIS_MODULE, \ + .n_voltages = ARRAY_SIZE(v_table), \ + .volt_table = v_table, \ + .vsel_reg = HI6421_REG_TO_BUS_ADDR(vreg), \ + .vsel_mask = vmask, \ + .enable_reg = HI6421_REG_TO_BUS_ADDR(ereg), \ + .enable_mask = emask, \ + .enable_time = HI6421V530_LDO_ENABLE_TIME, \ + .off_on_delay = odelay, \ + }, \ + .mode_mask = ecomask, \ + .eco_microamp = ecoamp, \ +} + +/* HI6421V530 regulator information */ + +static struct hi6421v530_regulator_info hi6421v530_regulator_info[] = { + HI6421V530_LDO(LDO3, ldo_3_voltages, 0x061, 0xf, 0x060, 0x2, + 20000, 0x6, 8000), + HI6421V530_LDO(LDO9, ldo_9_11_voltages, 0x06b, 0x7, 0x06a, 0x2, + 40000, 0x6, 8000), + HI6421V530_LDO(LDO11, ldo_9_11_voltages, 0x06f, 0x7, 0x06e, 0x2, + 40000, 0x6, 8000), + HI6421V530_LDO(LDO15, ldo_15_16_voltages, 0x077, 0x7, 0x076, 0x2, + 40000, 0x6, 8000), + HI6421V530_LDO(LDO16, ldo_15_16_voltages, 0x079, 0x7, 0x078, 0x2, + 40000, 0x6, 8000), +}; + +static unsigned int hi6421v530_regulator_ldo_get_mode( + struct regulator_dev *rdev) +{ + struct hi6421v530_regulator_info *info; + unsigned int reg_val; + + info = rdev_get_drvdata(rdev); + regmap_read(rdev->regmap, rdev->desc->enable_reg, ®_val); + + if (reg_val & (info->mode_mask)) + return REGULATOR_MODE_IDLE; + + return REGULATOR_MODE_NORMAL; +} + +static int hi6421v530_regulator_ldo_set_mode(struct regulator_dev *rdev, + unsigned int mode) +{ + struct hi6421v530_regulator_info *info; + unsigned int new_mode; + + info = rdev_get_drvdata(rdev); + switch (mode) { + case REGULATOR_MODE_NORMAL: + new_mode = 0; + break; + case REGULATOR_MODE_IDLE: + new_mode = info->mode_mask; + break; + default: + return -EINVAL; + } + + regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, + info->mode_mask, new_mode); + + return 0; +} + + +static const struct regulator_ops hi6421v530_ldo_ops = { + .is_enabled = regulator_is_enabled_regmap, + .enable = regulator_enable_regmap, + .disable = regulator_disable_regmap, + .list_voltage = regulator_list_voltage_table, + .map_voltage = regulator_map_voltage_ascend, + .get_voltage_sel = regulator_get_voltage_sel_regmap, + .set_voltage_sel = regulator_set_voltage_sel_regmap, + .get_mode = hi6421v530_regulator_ldo_get_mode, + .set_mode = hi6421v530_regulator_ldo_set_mode, +}; + +static int hi6421v530_regulator_probe(struct platform_device *pdev) +{ + struct hi6421_pmic *pmic; + struct regulator_dev *rdev; + struct regulator_config config = { }; + unsigned int i; + + pmic = dev_get_drvdata(pdev->dev.parent); + if (!pmic) { + dev_err(&pdev->dev, "no pmic in the regulator parent node\n"); + return -ENODEV; + } + + for (i = 0; i < ARRAY_SIZE(hi6421v530_regulator_info); i++) { + config.dev = pdev->dev.parent; + config.regmap = pmic->regmap; + config.driver_data = &hi6421v530_regulator_info[i]; + + rdev = devm_regulator_register(&pdev->dev, + &hi6421v530_regulator_info[i].rdesc, + &config); + if (IS_ERR(rdev)) { + dev_err(&pdev->dev, "failed to register regulator %s\n", + hi6421v530_regulator_info[i].rdesc.name); + return PTR_ERR(rdev); + } + } + return 0; +} + +static struct platform_driver hi6421v530_regulator_driver = { + .driver = { + .name = "hi6421v530-regulator", + }, + .probe = hi6421v530_regulator_probe, +}; +module_platform_driver(hi6421v530_regulator_driver); + +MODULE_AUTHOR("Wang Xiaoyin <hw.wangxiaoyin@hisilicon.com>"); +MODULE_DESCRIPTION("Hi6421v530 regulator driver"); +MODULE_LICENSE("GPL v2"); -- 2.11.0 ^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v3 4/6] regulator: hi6421: Describe consumed platform device 2017-06-02 10:51 [PATCH v3 0/6] MFD: add driver for HiSilicon Hi6421v530 PMIC Guodong Xu ` (2 preceding siblings ...) 2017-06-02 10:51 ` [PATCH v3 3/6] regulator: hi6421v530: add driver for hi6421v530 voltage regulator Guodong Xu @ 2017-06-02 10:51 ` Guodong Xu 2017-06-02 10:51 ` [PATCH v3 5/6] arm64: dts: hikey960: add device node for pmic and regulators Guodong Xu 2017-06-02 10:51 ` [PATCH v3 6/6] arm64: defconfig: enable support hi6421v530 PMIC Guodong Xu 5 siblings, 0 replies; 12+ messages in thread From: Guodong Xu @ 2017-06-02 10:51 UTC (permalink / raw) To: linux-arm-kernel The hi6421-regulator driver consumes a similarly named platform device. Adding that to the module device table, allows modprobe to locate this driver once the device is created. Cc: Jeremy Linton <lintonrjeremy@gmail.com> Cc: Mark Brown <broonie@kernel.org> Signed-off-by: Guodong Xu <guodong.xu@linaro.org> --- drivers/regulator/hi6421-regulator.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/regulator/hi6421-regulator.c b/drivers/regulator/hi6421-regulator.c index 62c5f54..259c3a8 100644 --- a/drivers/regulator/hi6421-regulator.c +++ b/drivers/regulator/hi6421-regulator.c @@ -621,7 +621,14 @@ static int hi6421_regulator_probe(struct platform_device *pdev) return 0; } +static const struct platform_device_id hi6421_regulator_table[] = { + { .name = "hi6421-regulator" }, + {}, +}; +MODULE_DEVICE_TABLE(platform, hi6421_regulator_table); + static struct platform_driver hi6421_regulator_driver = { + .id_table = hi6421_regulator_table, .driver = { .name = "hi6421-regulator", }, -- 2.10.2 ^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v3 5/6] arm64: dts: hikey960: add device node for pmic and regulators 2017-06-02 10:51 [PATCH v3 0/6] MFD: add driver for HiSilicon Hi6421v530 PMIC Guodong Xu ` (3 preceding siblings ...) 2017-06-02 10:51 ` [PATCH v3 4/6] regulator: hi6421: Describe consumed platform device Guodong Xu @ 2017-06-02 10:51 ` Guodong Xu 2017-06-02 10:51 ` [PATCH v3 6/6] arm64: defconfig: enable support hi6421v530 PMIC Guodong Xu 5 siblings, 0 replies; 12+ messages in thread From: Guodong Xu @ 2017-06-02 10:51 UTC (permalink / raw) To: linux-arm-kernel From: Wang Xiaoyin <hw.wangxiaoyin@hisilicon.com> add device node for hi6421 pmic core and hi6421v530 voltage regulator,include LDO(1,3,9,11,15,16) Signed-off-by: Wang Xiaoyin <hw.wangxiaoyin@hisilicon.com> Signed-off-by: Guodong Xu <guodong.xu@linaro.org> --- arch/arm64/boot/dts/hisilicon/hi3660-hikey960.dts | 46 +++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/arch/arm64/boot/dts/hisilicon/hi3660-hikey960.dts b/arch/arm64/boot/dts/hisilicon/hi3660-hikey960.dts index ca448f0..9da8375 100644 --- a/arch/arm64/boot/dts/hisilicon/hi3660-hikey960.dts +++ b/arch/arm64/boot/dts/hisilicon/hi3660-hikey960.dts @@ -97,6 +97,52 @@ default-state = "off"; }; }; + + pmic: pmic at fff34000 { + compatible = "hisilicon,hi6421v530-pmic"; + reg = <0x0 0xfff34000 0x0 0x1000>; + interrupt-controller; + #interrupt-cells = <2>; + + regulators { + ldo3: LDO3 { /* HDMI */ + regulator-name = "VOUT3_1V85"; + regulator-min-microvolt = <1800000>; + regulator-max-microvolt = <2200000>; + regulator-enable-ramp-delay = <120>; + }; + + ldo9: LDO9 { /* SDCARD I/O */ + regulator-name = "VOUT9_1V8/2V95"; + regulator-min-microvolt = <1750000>; + regulator-max-microvolt = <3300000>; + regulator-enable-ramp-delay = <240>; + }; + + ldo11: LDO11 { /* Low Speed Connector */ + regulator-name = "VOUT11_1V8/2V95"; + regulator-min-microvolt = <1750000>; + regulator-max-microvolt = <3300000>; + regulator-enable-ramp-delay = <240>; + }; + + ldo15: LDO15 { /* UFS VCC */ + regulator-name = "VOUT15_3V0"; + regulator-min-microvolt = <1750000>; + regulator-max-microvolt = <3000000>; + regulator-boot-on; + regulator-always-on; + regulator-enable-ramp-delay = <120>; + }; + + ldo16: LDO16 { /* SD VDD */ + regulator-name = "VOUT16_2V95"; + regulator-min-microvolt = <1750000>; + regulator-max-microvolt = <3000000>; + regulator-enable-ramp-delay = <360>; + }; + }; + }; }; &i2c0 { -- 2.10.2 ^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v3 6/6] arm64: defconfig: enable support hi6421v530 PMIC 2017-06-02 10:51 [PATCH v3 0/6] MFD: add driver for HiSilicon Hi6421v530 PMIC Guodong Xu ` (4 preceding siblings ...) 2017-06-02 10:51 ` [PATCH v3 5/6] arm64: dts: hikey960: add device node for pmic and regulators Guodong Xu @ 2017-06-02 10:51 ` Guodong Xu 5 siblings, 0 replies; 12+ messages in thread From: Guodong Xu @ 2017-06-02 10:51 UTC (permalink / raw) To: linux-arm-kernel Enable configs for hi6421v530 mfd and regulator driver + CONFIG_MFD_HI6421_PMIC=y + CONFIG_REGULATOR_HI6421V530=y Signed-off-by: Guodong Xu <guodong.xu@linaro.org> --- arch/arm64/configs/defconfig | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/arm64/configs/defconfig b/arch/arm64/configs/defconfig index ce07285..867d68c 100644 --- a/arch/arm64/configs/defconfig +++ b/arch/arm64/configs/defconfig @@ -305,6 +305,7 @@ CONFIG_S3C2410_WATCHDOG=y CONFIG_MESON_GXBB_WATCHDOG=m CONFIG_MESON_WATCHDOG=m CONFIG_MFD_EXYNOS_LPASS=m +CONFIG_MFD_HI6421_PMIC=y CONFIG_MFD_MAX77620=y CONFIG_MFD_RK808=y CONFIG_MFD_SPMI_PMIC=y @@ -315,6 +316,7 @@ CONFIG_MFD_CROS_EC=y CONFIG_MFD_CROS_EC_I2C=y CONFIG_REGULATOR_FIXED_VOLTAGE=y CONFIG_REGULATOR_GPIO=y +CONFIG_REGULATOR_HI6421V530=y CONFIG_REGULATOR_HI655X=y CONFIG_REGULATOR_MAX77620=y CONFIG_REGULATOR_PWM=y -- 2.10.2 ^ permalink raw reply related [flat|nested] 12+ messages in thread
end of thread, other threads:[~2017-06-07 19:32 UTC | newest] Thread overview: 12+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2017-06-02 10:51 [PATCH v3 0/6] MFD: add driver for HiSilicon Hi6421v530 PMIC Guodong Xu 2017-06-02 10:51 ` [PATCH v3 1/6] dt-bindings: mfd: hi6421: Add hi6421v530 compatible string Guodong Xu 2017-06-05 8:14 ` Lee Jones 2017-06-05 9:03 ` Guodong Xu 2017-06-02 10:51 ` [PATCH v3 2/6] mfd: hi6421-pmic: add support for HiSilicon Hi6421v530 Guodong Xu 2017-06-05 8:24 ` Lee Jones 2017-06-05 11:57 ` Guodong Xu 2017-06-02 10:51 ` [PATCH v3 3/6] regulator: hi6421v530: add driver for hi6421v530 voltage regulator Guodong Xu 2017-06-07 19:32 ` Applied "regulator: hi6421v530: add driver for hi6421v530 voltage regulator" to the regulator tree Mark Brown 2017-06-02 10:51 ` [PATCH v3 4/6] regulator: hi6421: Describe consumed platform device Guodong Xu 2017-06-02 10:51 ` [PATCH v3 5/6] arm64: dts: hikey960: add device node for pmic and regulators Guodong Xu 2017-06-02 10:51 ` [PATCH v3 6/6] arm64: defconfig: enable support hi6421v530 PMIC Guodong Xu
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).