Add MFD and regulator drivers for Hi6421 PMIC SoC
Subsystems (3)
v6 cover Add MFD and regulator drivers for Hi6421 PMIC SoC
This patchset adds an MFD core driver and a regulator driver for Hi6421 PMIC SoC.
Hi6421 is a PMIC SoC designed and manufactured by HiSilicon Ltd. It includes multi-functions, such as regulators, codec, ADCs, Coulomb counter, etc. Hi6421 can be used in various Hi3620 SoC based boards. Registers in Hi6421 are memory bus mapped, so in this design they are accessed by regmap-mmio APIs.
Hi6421 has a requirement to keep a guard delay between its regulator's disable and next enable. Implement this requirement in regulator core, per Mark Brown's suggestion.
---
changes in v6:
* rebase to v3.17-rc1:
- use devm_ioremap_resource in hi6421 mfd driver
- add 'const' before var regulator_ops in new funcs in regulator core
* fix build error in drivers/regulator/mc13892-regulator.c due to 'const' in regulator_desc.ops
* remove patch to hi3xxx_defconfig
changes in v5:
* rename _regulator_delay to _regulator_enable_delay
* clean up hi6421_regulator_enable(), add 100us protective gap into regulator_desc's .enable_time
* code clean up, fixes for style checking
changes in v4:
* regulator: core:
- add const qualifier to ops in struct regulator_desc
- factor out _regulator_delay from _regulator_do_enable
- add guard delay between calling regulator_disable and _enable
* hi6421 regulator:
- bug fix: missing min_uV for linear regualtor BUCK0~2
- bug fix: wrong volt values in buck_3_voltages table
- add const to hi6421 regulator_ops
- use ldo_linear and ldo_linear_range in applicable LDOs.
- rename regulator-name to conform to names in board schematics.
changes in v3:
* hi6421: regulator: remove setting of constraints on board-specific capabilities
* delete unecessary compatible property "hisilicon,hi6421-regulators"
* change regulator enable/disable callback APIs to support protection
gaps, as
required by hi6421 spec
* split regulator set_mode/get_mode callback APIs to LDOs and BUCKs
* delete hi6421.dtsi, mfd and regulator nodes are now in board config .dts
changes in v2:
* use MFD APIs to manage sub-devices of Hi6421
* use regmap-mmio for register access
* use only generic regulator device tree property
* rewrite regulator driver using helper APIs from both regulator and regmap
v1: first drop
Guodong Xu (6):
regulator: core: add const qualifier to ops in struct regulator_desc
regulator: core: factor out delay function from _regulator_do_enable
regulator: core: add guard delay between calling regulator_disable and
_enable
mfd: Add hi6421 PMIC core driver
regulator: add driver for hi6421 voltage regulator
ARM: dts: hi3620-hi4511: Add HI6421 MFD and regulator nodes
Documentation/devicetree/bindings/mfd/hi6421.txt | 37 ++ arch/arm/boot/dts/hi3620-hi4511.dts | 233 ++++++++ drivers/mfd/Kconfig | 13 + drivers/mfd/Makefile | 1 + drivers/mfd/hi6421-pmic-core.c | 117 ++++ drivers/regulator/Kconfig | 10 + drivers/regulator/Makefile | 1 + drivers/regulator/core.c | 137 +++-- drivers/regulator/hi6421-regulator.c | 657 +++++++++++++++++++++++ drivers/regulator/mc13892-regulator.c | 11 +- include/linux/mfd/hi6421-pmic.h | 39 ++ include/linux/regulator/driver.h | 8 +- 12 files changed, 1209 insertions(+), 55 deletions(-) create mode 100644 Documentation/devicetree/bindings/mfd/hi6421.txt create mode 100644 drivers/mfd/hi6421-pmic-core.c create mode 100644 drivers/regulator/hi6421-regulator.c create mode 100644 include/linux/mfd/hi6421-pmic.h
Signature · 1 line
1.9.1
PATCH v6 1/6 regulator: core: add const qualifier to ops in struct regulator_desc
struct regulator_ops *ops is a member in struct regulator_desc, which gets its value from individual regulator driver upon regulator_register() and is used by regulator core APIs. It's not allowed for regulator core to modify any of these callbacks in *ops. Add 'const' qualifier to enforce that.
--- drivers/regulator/core.c | 32 ++++++++++++++++---------------- drivers/regulator/mc13892-regulator.c | 11 +++++++---- include/linux/regulator/driver.h | 2 +- 3 files changed, 24 insertions(+), 21 deletions(-)
drivers/regulator/core.c +16 -16
@@ -839,7 +839,7 @@ static void print_constraints(struct regulator_dev *rdev)static int machine_constraints_voltage (struct regulator_dev *rdev,struct regulation_constraints *constraints) { -struct regulator_ops *ops = rdev->desc->ops; +const struct regulator_ops *ops = rdev->desc->ops;int ret;/* do we need to apply the constraint voltage */
@@ -938,7 +938,7 @@ static int machine_constraints_voltage(struct regulator_dev *rdev,static int machine_constraints_current (struct regulator_dev *rdev,struct regulation_constraints *constraints) { -struct regulator_ops *ops = rdev->desc->ops; +const struct regulator_ops *ops = rdev->desc->ops;int ret;if (!constraints->min_uA && !constraints->max_uA)
@@ -982,7 +982,7 @@ static int set_machine_constraints(struct regulator_dev *rdev, const struct regulation_constraints *constraints) {int ret =0 ; -struct regulator_ops *ops = rdev->desc->ops; +const struct regulator_ops *ops = rdev->desc->ops;if (constraints) rdev->constraints = kmemdup(constraints, sizeof(*constraints),
@@ -2208,9 +2208,9 @@ EXPORT_SYMBOL_GPL(regulator_count_voltages);*/ int regulator_list_voltage (struct regulator *regulator,unsigned selector) { -struct regulator_dev *rdev = regulator->rdev; -struct regulator_ops *ops = rdev->desc->ops; -int ret; +struct regulator_dev *rdev = regulator->rdev; +const struct regulator_ops *ops = rdev->desc->ops; +int ret;if (rdev->desc->fixed_uV && rdev->desc->n_voltages ==1 && !selector)return rdev->desc->fixed_uV;
@@ -2270,8 +2270,8 @@ int regulator_get_hardware_vsel_register(struct regulator *regulator,unsigned *vsel_reg, unsigned *vsel_mask) { - struct regulator_dev *rdev = regulator->rdev; -struct regulator_ops *ops = rdev->desc->ops; + struct regulator_dev *rdev = regulator->rdev; +const struct regulator_ops *ops = rdev->desc->ops;if (ops->set_voltage_sel != regulator_set_voltage_sel_regmap)return -EOPNOTSUPP ;
@@ -2297,8 +2297,8 @@ EXPORT_SYMBOL_GPL(regulator_get_hardware_vsel_register);int regulator_list_hardware_vsel (struct regulator *regulator,unsigned selector) { -struct regulator_dev *rdev = regulator->rdev; -struct regulator_ops *ops = rdev->desc->ops; +struct regulator_dev *rdev = regulator->rdev; +const struct regulator_ops *ops = rdev->desc->ops;if (selector >= rdev->desc->n_voltages)return -EINVAL ;
@@ -2572,8 +2572,8 @@ EXPORT_SYMBOL_GPL(regulator_set_voltage);int regulator_set_voltage_time (struct regulator *regulator,int old_uV,int new_uV) { -struct regulator_dev *rdev = regulator->rdev; -struct regulator_ops *ops = rdev->desc->ops; +struct regulator_dev *rdev = regulator->rdev; +const struct regulator_ops *ops = rdev->desc->ops;int old_sel =-1 ;int new_sel =-1 ;int voltage;
@@ -3336,9 +3336,9 @@ EXPORT_SYMBOL_GPL(regulator_mode_to_status);*/ static int add_regulator_attributes (struct regulator_dev *rdev) { -struct device *dev = &rdev->dev; -struct regulator_ops *ops = rdev->desc->ops; -int status =0 ; +struct device *dev = &rdev->dev; +const struct regulator_ops *ops = rdev->desc->ops; +int status =0 ;/* some attributes need specific methods to be displayed */ if ((ops->get_voltage && ops->get_voltage(rdev) >= 0) ||
@@ -3905,7 +3905,7 @@ core_initcall(regulator_init);static int __init regulator_init_complete (void ) {struct regulator_dev *rdev; -struct regulator_ops *ops; +const struct regulator_ops *ops;struct regulation_constraints *c;int enabled, ret;
drivers/regulator/mc13892-regulator.c +7 -4
@@ -526,6 +526,7 @@ static unsigned int mc13892_vcam_get_mode(struct regulator_dev *rdev)return REGULATOR_MODE_NORMAL ; } +static struct regulator_ops mc13892_vcam_ops;static int mc13892_regulator_probe (struct platform_device *pdev) {
@@ -582,10 +583,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev) }mc13xxx_unlock (mc13892); - mc13892_regulators[MC13892_VCAM ].desc.ops->set_mode - = mc13892_vcam_set_mode; - mc13892_regulators[MC13892_VCAM ].desc.ops->get_mode - = mc13892_vcam_get_mode; +/* update mc13892_vcam ops */ +memcpy (&mc13892_vcam_ops, mc13892_regulators[MC13892_VCAM ].desc.ops, +sizeof (struct regulator_ops )); + mc13892_vcam_ops.set_mode = mc13892_vcam_set_mode, + mc13892_vcam_ops.get_mode = mc13892_vcam_get_mode, + mc13892_regulators[MC13892_VCAM ].desc.ops = &mc13892_vcam_ops; mc13xxx_data =mc13xxx_parse_regulators_dt (pdev, mc13892_regulators,ARRAY_SIZE (mc13892_regulators));
include/linux/regulator/driver.h +1 -1
@@ -245,7 +245,7 @@ struct regulator_desc {int id;bool continuous_voltage_range;unsigned n_voltages; -struct regulator_ops *ops; +const struct regulator_ops *ops;int irq;enum regulator_type type;struct module *owner;
Signature · 1 line
1.9.1
PATCH v6 2/6 regulator: core: factor out delay function from _regulator_do_enable
In reply to Guodong XuA common delay function can be helpful when implementing new features. Factor it out to maximize code reusability.
--- drivers/regulator/core.c | 74 ++++++++++++++++++++++++++---------------------- 1 file changed, 40 insertions(+), 34 deletions(-)
drivers/regulator/core.c +40 -34
@@ -1759,6 +1759,45 @@ static int regulator_ena_gpio_ctrl(struct regulator_dev *rdev, bool enable)return 0 ; } +/** +* _regulator_enable_delay - a delay helper function +* @delay: time to delay in microseconds +* +* Delay for the requested amount of time as per the guidelines in: +* +* Documentation/timers/timers-howto.txt +* +* The assumption here is that regulators will never be enabled in +* atomic context and therefore sleeping functions can be used. +*/ +static void _regulator_enable_delay (unsigned int delay) +{ +unsigned int ms = delay /1000 ; +unsigned int us = delay %1000 ; + +if (ms >0 ) { +/* +* For small enough values, handle super-millisecond +* delays in the usleep_range() call below. +*/ +if (ms <20 ) + us += ms *1000 ; +else +msleep (ms); + } + +/* +* Give the scheduler some room to coalesce with any other +* wakeup sources. For delays shorter than 10 us, don't even +* bother setting up high-resolution timers and just busy- +* loop. +*/ +if (us >=10 ) +usleep_range (us, us +100 ); +else +udelay (us); +} +static int _regulator_do_enable (struct regulator_dev *rdev) {int ret, delay;
@@ -1792,40 +1831,7 @@ static int _regulator_do_enable(struct regulator_dev *rdev)* together. */ trace_regulator_enable_delay (rdev_get_name (rdev)); -/* -* Delay for the requested amount of time as per the guidelines in: -* -* Documentation/timers/timers-howto.txt -* -* The assumption here is that regulators will never be enabled in -* atomic context and therefore sleeping functions can be used. -*/ -if (delay) { -unsigned int ms = delay /1000 ; -unsigned int us = delay %1000 ; - -if (ms >0 ) { -/* -* For small enough values, handle super-millisecond -* delays in the usleep_range() call below. -*/ -if (ms <20 ) - us += ms *1000 ; -else -msleep (ms); - } - -/* -* Give the scheduler some room to coalesce with any other -* wakeup sources. For delays shorter than 10 us, don't even -* bother setting up high-resolution timers and just busy- -* loop. -*/ -if (us >=10 ) -usleep_range (us, us +100 ); -else -udelay (us); - } +_regulator_enable_delay (delay);trace_regulator_enable_complete (rdev_get_name (rdev));
Signature · 1 line
1.9.1
PATCH v6 3/6 regulator: core: add guard delay between calling regulator_disable and _enable
In reply to Guodong XuSome regulator require a minimum delay between its disable and next enable. This is to avoid damages when out-of-range frequent disable/enable of a single regulator can bring to the regulator chip.
Add @off_on_delay to struct regulator_desc. Device drivers' can use this field to set this guard time.
Add @last_off_jiffy to struct regulator_dev. When @off_on_delay is set by driver, regulator core can store its last off (disable) time into this field.
--- drivers/regulator/core.c | 31 +++++++++++++++++++++++++++++++ include/linux/regulator/driver.h | 6 ++++++ 2 files changed, 37 insertions(+)
drivers/regulator/core.c +31 -0
@@ -1813,6 +1813,31 @@ static int _regulator_do_enable(struct regulator_dev *rdev)trace_regulator_enable (rdev_get_name (rdev)); +if (rdev->desc->off_on_delay) { +/* if needed, keep a distance of off_on_delay from last time +* this regulator was disabled. +*/ +unsigned long start_jiffy = jiffies; +unsigned long intended, max_delay, remaining; + + max_delay =usecs_to_jiffies (rdev->desc->off_on_delay); + intended = rdev->last_off_jiffy + max_delay; + +if (time_before (start_jiffy, intended)) { +/* calc remaining jiffies to deal with one-time +* timer wrapping. +* in case of multiple timer wrapping, either it can be +* detected by out-of-range remaining, or it cannot be +* detected and we gets a panelty of +* _regulator_enable_delay(). +*/ + remaining = intended - start_jiffy; +if (remaining <= max_delay) +_regulator_enable_delay ( +jiffies_to_usecs (remaining)); + } + } +if (rdev->ena_pin) { ret =regulator_ena_gpio_ctrl (rdev, true);if (ret <0 )
@@ -1925,6 +1950,12 @@ static int _regulator_do_disable(struct regulator_dev *rdev)return ret; } +/* cares about last_off_jiffy only if off_on_delay is required by +* device. +*/ +if (rdev->desc->off_on_delay) + rdev->last_off_jiffy = jiffies; +trace_regulator_disable_complete (rdev_get_name (rdev));return 0 ;
include/linux/regulator/driver.h +6 -0
@@ -238,6 +238,7 @@ enum regulator_type {* @bypass_val_off: Disabling value for control when using regmap set_bypass * * @enable_time: Time taken for initial enable of regulator (in uS). +* @off_on_delay: guard time (in uS), before re-enabling a regulator */ struct regulator_desc {const char *name;
@@ -276,6 +277,8 @@ struct regulator_desc {unsigned int bypass_val_off;unsigned int enable_time; + +unsigned int off_on_delay; };/**
@@ -348,6 +351,9 @@ struct regulator_dev {struct regulator_enable_gpio *ena_pin; unsigned int ena_gpio_state:1; + +/* time when this regulator was disabled last time */ +unsigned long last_off_jiffy; }; struct regulator_dev *
Signature · 1 line
1.9.1
PATCH v6 4/6 mfd: Add hi6421 PMIC core driver
In reply to Guodong XuThis adds driver to support HiSilicon Hi6421 PMIC. Hi6421 includes multi- functions, such as regulators, codec, ADCs, Coulomb counter, etc. This driver includes core APIs _only_.
Drivers for individul components, like voltage regulators, are implemented in corresponding driver directories and files.
Registers in Hi6421 are memory mapped, so using regmap-mmio API.
--- Documentation/devicetree/bindings/mfd/hi6421.txt | 37 +++++++ drivers/mfd/Kconfig | 13 +++ drivers/mfd/Makefile | 1 + drivers/mfd/hi6421-pmic-core.c | 117 +++++++++++++++++++++++ include/linux/mfd/hi6421-pmic.h | 39 ++++++++ 5 files changed, 207 insertions(+) create mode 100644 Documentation/devicetree/bindings/mfd/hi6421.txt create mode 100644 drivers/mfd/hi6421-pmic-core.c create mode 100644 include/linux/mfd/hi6421-pmic.h
Documentation/devicetree/bindings/mfd/hi6421.txt new file +37 -0
@@ -0,0 +1,37 @@ +* HI6421 Multi-Functional Device (MFD), by HiSilicon Ltd. + +Required parent device properties: +- reg : register range space of hi6421; + +Supported Hi6421 sub-devices include: + +Device IRQ Names Supply Names Description +------ --------- ------------ ----------- +regulators : : : Regulators + +Required child device properties: +None. + +Example: + pmic: pmic at c00000 { + compatible = "hisilicon,hi6421-pmic"; + reg = <0xc00000 0x0180>; /* 0x60 << 2 */ + + regulators { + // supply for MLC NAND/ eMMC + hi6421_vout0_reg: hi6421_vout0 { + regulator-name = "VOUT0"; + regulator-min-microvolt = <2850000>; + regulator-max-microvolt = <2850000>; + }; + + // supply for 26M Oscillator + hi6421_vout1_reg: hi6421_vout1 { + regulator-name = "VOUT1"; + regulator-min-microvolt = <1700000>; + regulator-max-microvolt = <2000000>; + regulator-boot-on; + regulator-always-on; + }; + }; + };
drivers/mfd/Kconfig +13 -0
@@ -210,6 +210,19 @@ config MFD_MC13XXX_I2C help Select this if your MC13xxx is connected via an I2C bus. +config MFD_HI6421_PMIC + tristate "HiSilicon Hi6421 PMU/Codec IC" + depends on OF + select MFD_CORE + select REGMAP_MMIO + help + This driver supports HiSilicon Hi6421 PMIC. Hi6421 includes multi- + functions, such as regulators, codec, ADCs, Coulomb counter, etc. + This driver includes core APIs _only_. You have to select + individul components like voltage regulators under corresponding + menus in order to enable them. + Memory-mapped I/O is the way to communicate with Hi6421. + config HTC_EGPIO bool "HTC EGPIO support" depends on GPIOLIB && ARM
drivers/mfd/Makefile +1 -0
@@ -169,6 +169,7 @@ obj-$(CONFIG_MFD_AS3711) += as3711.o obj-$(CONFIG_MFD_AS3722) += as3722.o obj-$(CONFIG_MFD_STW481X) += stw481x.o obj-$(CONFIG_MFD_IPAQ_MICRO) += ipaq-micro.o +obj-$(CONFIG_MFD_HI6421_PMIC) += hi6421-pmic-core.o intel-soc-pmic-objs := intel_soc_pmic_core.o intel_soc_pmic_crc.o obj-$(CONFIG_INTEL_SOC_PMIC) += intel-soc-pmic.o
drivers/mfd/hi6421-pmic-core.c new file +117 -0
117 lines not on this page · raw message
include/linux/mfd/hi6421-pmic.h new file +39 -0
@@ -0,0 +1,39 @@ +/* +* Header file for device driver Hi6421 PMIC +* +* Copyright (c) <2011-2014> HiSilicon Technologies Co., Ltd. +* http://www.hisilicon.com +* Copyright (c) <2013-2014> Linaro Ltd. +* http://www.linaro.org +* +* Author: Guodong Xu <[email protected]> +* +* 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. +*/ + +#ifndef __HI6421_PMIC_H +#define __HI6421_PMIC_H + +/* Hi6421 registers are mapped to memory bus in 4 bytes stride */ +#define HI6421_REG_TO_BUS_ADDR (x) (x << 2) + +/* Hi6421 OCP (over current protection) and DEB (debounce) control register */ +#define HI6421_OCP_DEB_CTRL_REG HI6421_REG_TO_BUS_ADDR(0x51) +#define HI6421_OCP_DEB_SEL_MASK (0x0C) +#define HI6421_OCP_DEB_SEL_8MS (0x00) +#define HI6421_OCP_DEB_SEL_16MS (0x04) +#define HI6421_OCP_DEB_SEL_32MS (0x08) +#define HI6421_OCP_DEB_SEL_64MS (0x0C) +#define HI6421_OCP_EN_DEBOUNCE_MASK (0x02) +#define HI6421_OCP_EN_DEBOUNCE_ENABLE (0x02) +#define HI6421_OCP_AUTO_STOP_MASK (0x01) +#define HI6421_OCP_AUTO_STOP_ENABLE (0x01) + +struct hi6421_pmic { +struct device *dev; +struct regmap *regmap; +}; + +#endif /* __HI6421_PMIC_H */
Signature · 1 line
1.9.1
Mark Brown
maintainerRe: [PATCH v6 4/6] mfd: Add hi6421 PMIC core driver
Quoted 3 lines · Guodong Xu
This adds driver to support HiSilicon Hi6421 PMIC. Hi6421 includes multi- functions, such as regulators, codec, ADCs, Coulomb counter, etc. This driver includes core APIs _only_.
Please don't resend already applied patches, if there are any updates
that need applying please send incremental patches.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20140818/b093e459/attachment.sig>
Re: [PATCH v6 4/6] mfd: Add hi6421 PMIC core driver
In reply to Guodong XuQuoted 4 lines · Guodong Xu
This adds driver to support HiSilicon Hi6421 PMIC. Hi6421 includes multi- functions, such as regulators, codec, ADCs, Coulomb counter, etc. This driver includes core APIs _only_.
Quoted 8 lines
Drivers for individul components, like voltage regulators, are implemented in corresponding driver directories and files.
Registers in Hi6421 are memory mapped, so using regmap-mmio API.
Signed-off-by Guodong Xu <[email protected]>--- Documentation/devicetree/bindings/mfd/hi6421.txt | 37 +++++++
DT documentation should be in a patch of its own.
See: Documentation/devicetree/bindings/submitting-patches.txt
Quoted 15 lines
drivers/mfd/Kconfig | 13 +++ drivers/mfd/Makefile | 1 + drivers/mfd/hi6421-pmic-core.c | 117 +++++++++++++++++++++++ include/linux/mfd/hi6421-pmic.h | 39 ++++++++ 5 files changed, 207 insertions(+) create mode 100644 Documentation/devicetree/bindings/mfd/hi6421.txt create mode 100644 drivers/mfd/hi6421-pmic-core.c create mode 100644 include/linux/mfd/hi6421-pmic.hDocumentation/devicetree/bindings/mfd/hi6421.txt new file +0
-0
Documentation/devicetree/bindings/mfd/hi6421.txt line 4
Quoted 4 lines
Documentation/devicetree/bindings/mfd/hi6421.txt new file +4
-0@@ -0,0 +1,37 @@ +* HI6421 Multi-Functional Device (MFD), by HiSilicon Ltd. + +Required parent device properties: +- reg : register range space of hi6421;
You need to describe the compatible string here.
Documentation/devicetree/bindings/mfd/hi6421.txt line 10
Quoted 5 lines
Documentation/devicetree/bindings/mfd/hi6421.txt new file +5
-0+Supported Hi6421 sub-devices include: + +Device IRQ Names Supply Names Description +------ --------- ------------ ----------- +regulators : : : Regulators
If a cell has been intentionally left blank, put 'None' to be clear.
When will the other devices be added?
Documentation/devicetree/bindings/mfd/hi6421.txt line 16
Quoted 5 lines
Documentation/devicetree/bindings/mfd/hi6421.txt new file +5
-0+Required child device properties: +None. + +Example: + pmic: pmic at c00000 {
24bit addressing?
Is this node referenced by another node via phandle? If not, you can drop the "pmic" label. If it is referenced by another node, but there is more than one PMIC, label "pmic" won't do.
Documentation/devicetree/bindings/mfd/hi6421.txt line 23
Quoted 7 lines
Documentation/devicetree/bindings/mfd/hi6421.txt new file +7
-0+ compatible = "hisilicon,hi6421-pmic"; + reg = <0xc00000 0x0180>; /* 0x60 << 2 */ + + regulators { + // supply for MLC NAND/ eMMC + hi6421_vout0_reg: hi6421_vout0 { + regulator-name = "VOUT0";
I may be mistaken, but "vout0" doesn't come across as a very good regulator name to me.
Documentation/devicetree/bindings/mfd/hi6421.txt line 34
Quoted 11 lines
Documentation/devicetree/bindings/mfd/hi6421.txt new file +11
-0+ regulator-min-microvolt = <2850000>; + regulator-max-microvolt = <2850000>; + }; + + // supply for 26M Oscillator + hi6421_vout1_reg: hi6421_vout1 { + regulator-name = "VOUT1"; + regulator-min-microvolt = <1700000>; + regulator-max-microvolt = <2000000>; + regulator-boot-on; + regulator-always-on;
Again an assumption here, but doesn't 'egulator-always-on' insinuate 'regulator-boot-on', or does it simply mean "once it's on, it must stay on"?
Documentation/devicetree/bindings/mfd/hi6421.txt line 36
Quoted 3 lines
Documentation/devicetree/bindings/mfd/hi6421.txt new file +3
-0+ }; + }; + };
Your tabbing is out here.
Quoted 5 lines
drivers/mfd/Kconfig +0
-0
drivers/mfd/Kconfig config MFD_MC13XXX_I2C · line 219
Quoted 10 lines
drivers/mfd/Kconfig +7
-0@@ -210,6 +210,19 @@ config MFD_MC13XXX_I2C help Select this if your MC13xxx is connected via an I2C bus. +config MFD_HI6421_PMIC + tristate "HiSilicon Hi6421 PMU/Codec IC" + depends on OF + select MFD_CORE + select REGMAP_MMIO + help + This driver supports HiSilicon Hi6421 PMIC. Hi6421 includes multi-
It doesn't support it, it adds support for it - subtle difference.
drivers/mfd/Kconfig config MFD_MC13XXX_I2C · line 224
Quoted 5 lines
drivers/mfd/Kconfig +5
-0+ functions, such as regulators, codec, ADCs, Coulomb counter, etc. + This driver includes core APIs _only_. You have to select + individul components like voltage regulators under corresponding + menus in order to enable them. + Memory-mapped I/O is the way to communicate with Hi6421.
"We communicate with the Hi6421 via memory-mapped I/O."
Quoted 21 lines
drivers/mfd/Kconfig +0
-0config HTC_EGPIO bool "HTC EGPIO support" depends on GPIOLIB && ARMdrivers/mfd/Makefile +1
-0@@ -169,6 +169,7 @@ obj-$(CONFIG_MFD_AS3711) += as3711.o obj-$(CONFIG_MFD_AS3722) += as3722.o obj-$(CONFIG_MFD_STW481X) += stw481x.o obj-$(CONFIG_MFD_IPAQ_MICRO) += ipaq-micro.o +obj-$(CONFIG_MFD_HI6421_PMIC) += hi6421-pmic-core.o intel-soc-pmic-objs := intel_soc_pmic_core.o intel_soc_pmic_crc.o obj-$(CONFIG_INTEL_SOC_PMIC) += intel-soc-pmic.odrivers/mfd/hi6421-pmic-core.c new file +0
-0
drivers/mfd/hi6421-pmic-core.c line 7
Quoted 7 lines
drivers/mfd/hi6421-pmic-core.c new file +7
-0@@ -0,0 +1,117 @@ +/* +* Device driver for Hi6421 IC +* +* Copyright (c) <2011-2014> HiSilicon Technologies Co., Ltd. +* http://www.hisilicon.com +* Copyright (c) <2013-2014> Linaro Ltd. +* http://www.linaro.org
I'm not sure Linaro own the copyright to this driver. It should still belong to HiSilicon.
drivers/mfd/hi6421-pmic-core.c line 13
Quoted 5 lines
drivers/mfd/hi6421-pmic-core.c new file +5
-0+* Author: Guodong Xu <[email protected]> +* +* 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.
This should also contain a link to the full licence.
See: COPYING
Quoted 9 lines
drivers/mfd/hi6421-pmic-core.c new file +9
-0+*/ + +#include <linux/device.h> +#include <linux/err.h> +#include <linux/io.h> +#include <linux/mfd/core.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/of_device.h>
drivers/mfd/hi6421-pmic-core.c line 32
Quoted 10 lines
drivers/mfd/hi6421-pmic-core.c new file +10
-0+#include <linux/of_address.h> +#include <linux/platform_device.h> +#include <linux/regmap.h> +#include <linux/slab.h> +#include <linux/mfd/hi6421-pmic.h> + +static struct of_device_id of_hi6421_pmic_match_tbl[] = { + { + .compatible ="hisilicon,hi6421-pmic" , + },
This can be just one line.
drivers/mfd/hi6421-pmic-core.c line 33
Quoted 1 line
drivers/mfd/hi6421-pmic-core.c new file +1
-0+ {/* end */ }
No real need for this comment.
drivers/mfd/hi6421-pmic-core.c line 39
Quoted 6 lines
drivers/mfd/hi6421-pmic-core.c new file +6
-0+}; + +static const struct mfd_cell hi6421_devs[] = { + { + .name ="hi6421-regulator" , + },
Again, one line.
drivers/mfd/hi6421-pmic-core.c line 46
Quoted 7 lines
drivers/mfd/hi6421-pmic-core.c new file +7
-0+}; + +static struct regmap_config hi6421_regmap_config = { + .reg_bits =32 , + .reg_stride =4 , + .val_bits =8 , + .max_register =HI6421_REG_TO_BUS_ADDR (0xFF ),
0xFF should really be defined.
drivers/mfd/hi6421-pmic-core.c line 51
Quoted 5 lines
drivers/mfd/hi6421-pmic-core.c new file +5
-0+}; + +static int hi6421_pmic_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev;
You only use this a couple of times. You use '&pdev->dev' more regularly. May as well remove it and just use '&pdev->dev' all the time.
drivers/mfd/hi6421-pmic-core.c line 52
Quoted 1 line
drivers/mfd/hi6421-pmic-core.c new file +1
-0+struct hi6421_pmic *pmic =NULL ;
No need to initialise this.
drivers/mfd/hi6421-pmic-core.c line 59
Quoted 7 lines
drivers/mfd/hi6421-pmic-core.c new file +7
-0+struct resource *res; +void __iomem *base; +int ret; + + pmic =devm_kzalloc (dev,sizeof (*pmic),GFP_KERNEL ); +if (!pmic) { +dev_err (dev,"cannot allocate hi6421_pmic device info\n" );
No need to print out messages on OOM, the OS will do that for you.
drivers/mfd/hi6421-pmic-core.c line 63
Quoted 4 lines
drivers/mfd/hi6421-pmic-core.c new file +4
-0+return -ENOMEM ; + } + +/* get resources */
This comment doesn't add to the code. The name of the function call is clear enough.
drivers/mfd/hi6421-pmic-core.c line 65
Quoted 2 lines
drivers/mfd/hi6421-pmic-core.c new file +2
-0+ res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +if (unlikely (!res)) {
Only 21 out of 1718 uses of platform_get_resource() use unlikely() to check the return value. I think it's okay to drop it.
drivers/mfd/hi6421-pmic-core.c line 66
Quoted 1 line
drivers/mfd/hi6421-pmic-core.c new file +1
-0+dev_err (&pdev->dev,"Invalid mem resource.\n" );
"No memory resource specified"?
drivers/mfd/hi6421-pmic-core.c line 67
Quoted 2 lines
drivers/mfd/hi6421-pmic-core.c new file +2
-0+return -ENODEV ; + }
Actually, scrap all that. You can remove error checking altogether for platform_get_resource(), as devm_ioremap_resource() does it for you. Code should read:
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); base = devm_ioremap_resource(dev, res);
if (IS_ERR(base))
return PTR_ERR(base);
drivers/mfd/hi6421-pmic-core.c line 78
Quoted 9 lines
drivers/mfd/hi6421-pmic-core.c new file +9
-0+ base =devm_ioremap_resource (dev, res); +if (IS_ERR (base)) +return PTR_ERR (base); + + 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));
Can you break the line at the first ',/' and line up against '('?
drivers/mfd/hi6421-pmic-core.c line 83
Quoted 5 lines
drivers/mfd/hi6421-pmic-core.c new file +5
-0+return PTR_ERR (pmic->regmap); + } + + pmic->dev = dev; +platform_set_drvdata (pdev, pmic);
It's not _that_ important, but I like to see this at the end after you know everything else has succeeded.
drivers/mfd/hi6421-pmic-core.c line 85
Quoted 1 line
drivers/mfd/hi6421-pmic-core.c new file +1
-0+/* set over-current protection debounce 8ms*/
Should be a ' ' between '8ms' and '*/'.
drivers/mfd/hi6421-pmic-core.c line 92
Quoted 7 lines
drivers/mfd/hi6421-pmic-core.c new file +7
-0+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 )); + + ret =mfd_add_devices (dev,0 , hi6421_devs, +ARRAY_SIZE (hi6421_devs),NULL ,0 ,NULL );
I'd like to see an error message if mfd_add_devices() fails.
Quoted 4 lines
drivers/mfd/hi6421-pmic-core.c new file +4
-0+return ret; +} + +static int hi6421_pmic_remove (struct platform_device *pdev)
drivers/mfd/hi6421-pmic-core.c line 107
Quoted 10 lines
drivers/mfd/hi6421-pmic-core.c new file +10
-0+{ +mfd_remove_devices (&pdev->dev); + +return 0 ; +} + +static struct platform_driver hi6421_pmic_driver = { + .driver = { + .name ="hi6421_pmic" , + .owner =THIS_MODULE ,
This is taken care of for you, you can remove it.
Quoted 38 lines
drivers/mfd/hi6421-pmic-core.c new file +10
-0+ .of_match_table = of_hi6421_pmic_match_tbl, + }, + .probe = hi6421_pmic_probe, + .remove = hi6421_pmic_remove, +}; +module_platform_driver (hi6421_pmic_driver); + +MODULE_AUTHOR ("Guodong Xu <[email protected]>" ); +MODULE_DESCRIPTION ("Hi6421 PMIC driver" ); +MODULE_LICENSE ("GPL v2" );include/linux/mfd/hi6421-pmic.h new file +22
-0@@ -0,0 +1,39 @@ +/* +* Header file for device driver Hi6421 PMIC +* +* Copyright (c) <2011-2014> HiSilicon Technologies Co., Ltd. +* http://www.hisilicon.com +* Copyright (c) <2013-2014> Linaro Ltd. +* http://www.linaro.org +* +* Author: Guodong Xu <[email protected]> +* +* 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. +*/ + +#ifndef __HI6421_PMIC_H +#define __HI6421_PMIC_H + +/* Hi6421 registers are mapped to memory bus in 4 bytes stride */ +#define HI6421_REG_TO_BUS_ADDR (x) (x << 2) + +/* Hi6421 OCP (over current protection) and DEB (debounce) control register */
include/linux/mfd/hi6421-pmic.h line 32
Quoted 10 lines
include/linux/mfd/hi6421-pmic.h new file +10
-0+#define HI6421_OCP_DEB_CTRL_REG HI6421_REG_TO_BUS_ADDR(0x51) +#define HI6421_OCP_DEB_SEL_MASK (0x0C) +#define HI6421_OCP_DEB_SEL_8MS (0x00) +#define HI6421_OCP_DEB_SEL_16MS (0x04) +#define HI6421_OCP_DEB_SEL_32MS (0x08) +#define HI6421_OCP_DEB_SEL_64MS (0x0C) +#define HI6421_OCP_EN_DEBOUNCE_MASK (0x02) +#define HI6421_OCP_EN_DEBOUNCE_ENABLE (0x02) +#define HI6421_OCP_AUTO_STOP_MASK (0x01) +#define HI6421_OCP_AUTO_STOP_ENABLE (0x01)
Remove the ()'s.
Quoted 6 lines
include/linux/mfd/hi6421-pmic.h new file +6
-0+struct hi6421_pmic { +struct device *dev; +struct regmap *regmap; +}; + +#endif /* __HI6421_PMIC_H */
Signature · 4 lines
Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org ? Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog
Re: [PATCH v6 4/6] mfd: Add hi6421 PMIC core driver
Hi, Lee
Thanks. I added for most of your comments. Some items, I have a different understanding. I added in below.
Quoted 10 lines · Lee Jones
Quoted 9 lines · Guodong Xu
This adds driver to support HiSilicon Hi6421 PMIC. Hi6421 includes multi- functions, such as regulators, codec, ADCs, Coulomb counter, etc. This driver includes core APIs _only_.
Drivers for individul components, like voltage regulators, are implemented in corresponding driver directories and files.
Registers in Hi6421 are memory mapped, so using regmap-mmio API.
Quoted 8 lines
Quoted 3 lines
Signed-off-by Guodong Xu <[email protected]>--- Documentation/devicetree/bindings/mfd/hi6421.txt | 37 +++++++DT documentation should be in a patch of its own.
See:
Documentation/devicetree/bindings/submitting-patches.txt
Thanks. Will do.
Quoted 9 lines
Quoted 9 lines
drivers/mfd/Kconfig | 13 +++ drivers/mfd/Makefile | 1 + drivers/mfd/hi6421-pmic-core.c | 117 +++++++++++++++++++++++ include/linux/mfd/hi6421-pmic.h | 39 ++++++++ 5 files changed, 207 insertions(+) create mode 100644 Documentation/devicetree/bindings/mfd/hi6421.txt create mode 100644 drivers/mfd/hi6421-pmic-core.c create mode 100644 include/linux/mfd/hi6421-pmic.h
Quoted 13 lines
Documentation/devicetree/bindings/mfd/hi6421.txt line 4
Quoted 10 lines
Documentation/devicetree/bindings/mfd/hi6421.txt new file +4
-0@@ -0,0 +1,37 @@ +* HI6421 Multi-Functional Device (MFD), by HiSilicon Ltd. + +Required parent device properties: +- reg : register range space of hi6421;You need to describe the compatible string here.
Yes.
Quoted 10 lines
Documentation/devicetree/bindings/mfd/hi6421.txt line 10
Quoted 5 lines
Documentation/devicetree/bindings/mfd/hi6421.txt new file +5
-0+Supported Hi6421 sub-devices include: + +Device IRQ Names Supply Names Description +------ --------- ------------ ----------- +regulators : : : RegulatorsIf a cell has been intentionally left blank, put 'None' to be clear.
When will the other devices be added?
RTC and irq will follow up next Month.
Quoted 8 lines
Documentation/devicetree/bindings/mfd/hi6421.txt line 16
Quoted 5 lines
Documentation/devicetree/bindings/mfd/hi6421.txt new file +5
-0+Required child device properties: +None. + +Example: + pmic: pmic at c00000 {24bit addressing?
No. that's due to a range property in parent node. I will change it to 32-bit address.
Quoted 4 lines
Is this node referenced by another node via phandle? If not, you can drop the "pmic" label. If it is referenced by another node, but there is more than one PMIC, label "pmic" won't do.
ok. Will change node name to
+ hi6421 {
...
Quoted 11 lines
Documentation/devicetree/bindings/mfd/hi6421.txt line 23
Quoted 7 lines
Documentation/devicetree/bindings/mfd/hi6421.txt new file +7
-0+ compatible = "hisilicon,hi6421-pmic"; + reg = <0xc00000 0x0180>; /* 0x60 << 2 */ + + regulators { + // supply for MLC NAND/ eMMC + hi6421_vout0_reg: hi6421_vout0 { + regulator-name = "VOUT0";I may be mistaken, but "vout0" doesn't come across as a very good regulator name to me.
Right, but 'VOUT0' is the name used in hi4511 boards' schematic. So I used this name to facilitate dts and board design matching.
Quoted 17 lines
Documentation/devicetree/bindings/mfd/hi6421.txt line 34
Quoted 11 lines
Documentation/devicetree/bindings/mfd/hi6421.txt new file +11
-0+ regulator-min-microvolt = <2850000>; + regulator-max-microvolt = <2850000>; + }; + + // supply for 26M Oscillator + hi6421_vout1_reg: hi6421_vout1 { + regulator-name = "VOUT1"; + regulator-min-microvolt = <1700000>; + regulator-max-microvolt = <2000000>; + regulator-boot-on; + regulator-always-on;Again an assumption here, but doesn't 'egulator-always-on' insinuate 'regulator-boot-on', or does it simply mean "once it's on, it must stay on"?
Quoted 1 line
From
Documentation/devicetree/bindings/regulator/regulator.txt,
- regulator-boot-on: bootloader/firmware enabled regulator
- regulator-always-on: boolean, regulator should never be disabled
'regulator-boot-on' is describing a board status, so I added it into dts file. Although in kernel code there is no much operation depending on it.
Quoted 6 lines
Documentation/devicetree/bindings/mfd/hi6421.txt line 36
Quoted 3 lines
Documentation/devicetree/bindings/mfd/hi6421.txt new file +3
-0+ }; + }; + };Your tabbing is out here.
Sorry. will fix.
Quoted 8 lines
Quoted 8 lines
drivers/mfd/Kconfig +0
-0@@ -210,6 +210,19 @@ config MFD_MC13XXX_I2C help Select this if your MC13xxx is connected via an I2C bus.
Quoted 10 lines
drivers/mfd/Kconfig config MFD_MC13XXX_I2C · line 219
Quoted 7 lines
drivers/mfd/Kconfig +7
-0+config MFD_HI6421_PMIC + tristate "HiSilicon Hi6421 PMU/Codec IC" + depends on OF + select MFD_CORE + select REGMAP_MMIO + help + This driver supports HiSilicon Hi6421 PMIC. Hi6421 includes multi-It doesn't support it, it adds support for it - subtle difference.
Thanks, will fix.
Quoted 31 lines
drivers/mfd/Kconfig config MFD_MC13XXX_I2C · line 224
Quoted 5 lines
drivers/mfd/Kconfig +5
-0+ functions, such as regulators, codec, ADCs, Coulomb counter, etc. + This driver includes core APIs _only_. You have to select + individul components like voltage regulators under corresponding + menus in order to enable them. + Memory-mapped I/O is the way to communicate with Hi6421."We communicate with the Hi6421 via memory-mapped I/O."
Quoted 23 lines
drivers/mfd/Kconfig +0
-0config HTC_EGPIO bool "HTC EGPIO support" depends on GPIOLIB && ARMdrivers/mfd/Makefile +1
-0@@ -169,6 +169,7 @@ obj-$(CONFIG_MFD_AS3711) += as3711.o obj-$(CONFIG_MFD_AS3722) += as3722.o obj-$(CONFIG_MFD_STW481X) += stw481x.o obj-$(CONFIG_MFD_IPAQ_MICRO) += ipaq-micro.o +obj-$(CONFIG_MFD_HI6421_PMIC) += hi6421-pmic-core.o intel-soc-pmic-objs := intel_soc_pmic_core.o intel_soc_pmic_crc.o obj-$(CONFIG_INTEL_SOC_PMIC) += intel-soc-pmic.odrivers/mfd/hi6421-pmic-core.c new file +2
-0@@ -0,0 +1,117 @@ +/* +* Device driver for Hi6421 IC
Quoted 9 lines
drivers/mfd/hi6421-pmic-core.c line 7
Quoted 5 lines
drivers/mfd/hi6421-pmic-core.c new file +5
-0+* +* Copyright (c) <2011-2014> HiSilicon Technologies Co., Ltd. +* http://www.hisilicon.com +* Copyright (c) <2013-2014> Linaro Ltd. +* http://www.linaro.org I'm not sure Linaro own the copyright to this driver. It should still belong to HiSilicon.
That was discussed with HiSilicon and agreement was we need both. The driver code is a complete re-write by me. HiSilicon original driver is reference for functionality understanding purpose.
Quoted 10 lines
drivers/mfd/hi6421-pmic-core.c line 13
Quoted 5 lines
drivers/mfd/hi6421-pmic-core.c new file +5
-0+* Author: Guodong Xu <[email protected]> +* +* 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. This should also contain a link to the full licence.
See: COPYING
Thanks. I checked COPYING, but there is no 'link' to full license. I copied a link from other c source: http://www.gnu.org/licenses/
is that OK?
Quoted 22 lines
Quoted 9 lines
drivers/mfd/hi6421-pmic-core.c new file +9
-0+*/ + +#include <linux/device.h> +#include <linux/err.h> +#include <linux/io.h> +#include <linux/mfd/core.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/of_device.h> drivers/mfd/hi6421-pmic-core.c line 32
Quoted 10 lines
drivers/mfd/hi6421-pmic-core.c new file +10
-0+#include <linux/of_address.h> +#include <linux/platform_device.h> +#include <linux/regmap.h> +#include <linux/slab.h> +#include <linux/mfd/hi6421-pmic.h> + +static struct of_device_id of_hi6421_pmic_match_tbl[] = { + { + .compatible ="hisilicon,hi6421-pmic" , + },This can be just one line.
Quoted 4 lines
drivers/mfd/hi6421-pmic-core.c line 33
Quoted 1 line
drivers/mfd/hi6421-pmic-core.c new file +1
-0+ {/* end */ }No real need for this comment.
Fixed.
Quoted 19 lines
drivers/mfd/hi6421-pmic-core.c line 39
Quoted 6 lines
drivers/mfd/hi6421-pmic-core.c new file +6
-0+}; + +static const struct mfd_cell hi6421_devs[] = { + { + .name ="hi6421-regulator" , + },Again, one line.
drivers/mfd/hi6421-pmic-core.c line 46
Quoted 7 lines
drivers/mfd/hi6421-pmic-core.c new file +7
-0+}; + +static struct regmap_config hi6421_regmap_config = { + .reg_bits =32 , + .reg_stride =4 , + .val_bits =8 , + .max_register =HI6421_REG_TO_BUS_ADDR (0xFF ),
0xFFshould really be defined.
Quoted 10 lines
drivers/mfd/hi6421-pmic-core.c line 51
Quoted 5 lines
drivers/mfd/hi6421-pmic-core.c new file +5
-0+}; + +static int hi6421_pmic_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev;You only use this a couple of times. You use '
&pdev->dev' more regularly. May as well remove it and just use '&pdev->dev' all the time.
Right. Will fix.
Quoted 32 lines
drivers/mfd/hi6421-pmic-core.c line 52
Quoted 1 line
drivers/mfd/hi6421-pmic-core.c new file +1
-0+struct hi6421_pmic *pmic =NULL ;No need to initialise this.
drivers/mfd/hi6421-pmic-core.c line 59
Quoted 7 lines
drivers/mfd/hi6421-pmic-core.c new file +7
-0+struct resource *res; +void __iomem *base; +int ret; + + pmic =devm_kzalloc (dev,sizeof (*pmic),GFP_KERNEL ); +if (!pmic) { +dev_err (dev,"cannot allocate hi6421_pmic device info\n" );No need to print out messages on OOM, the OS will do that for you.
drivers/mfd/hi6421-pmic-core.c line 63
Quoted 4 lines
drivers/mfd/hi6421-pmic-core.c new file +4
-0+return -ENOMEM ; + } + +/* get resources */ This comment doesn't add to the code. The name of the function call is clear enough.
drivers/mfd/hi6421-pmic-core.c line 65
Quoted 2 lines
drivers/mfd/hi6421-pmic-core.c new file +2
-0+ res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +if (unlikely (!res)) {Only 21 out of 1718 uses of
platform_get_resource()useunlikely()to check the return value. I think it's okay to drop it.drivers/mfd/hi6421-pmic-core.c line 66
Quoted 1 line
drivers/mfd/hi6421-pmic-core.c new file +1
-0+dev_err (&pdev->dev,"Invalid mem resource.\n" );"No memory resource specified"?
Quoted 7 lines
drivers/mfd/hi6421-pmic-core.c line 67
Quoted 2 lines
drivers/mfd/hi6421-pmic-core.c new file +2
-0+return -ENODEV ; + }Actually, scrap all that. You can remove error checking altogether for
platform_get_resource(), asdevm_ioremap_resource()does it for you. Code should read:
Thanks. Will do.
Quoted 17 lines
res =
platform_get_resource(pdev, IORESOURCE_MEM, 0); base =devm_ioremap_resource(dev, res);
if (IS_ERR(base))return PTR_ERR(base);drivers/mfd/hi6421-pmic-core.c line 78
Quoted 9 lines
drivers/mfd/hi6421-pmic-core.c new file +9
-0+ base =devm_ioremap_resource (dev, res); +if (IS_ERR (base)) +return PTR_ERR (base); + + 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));Can you break the line at the first ',/' and line up against '('?
Quoted 9 lines
drivers/mfd/hi6421-pmic-core.c line 83
Quoted 5 lines
drivers/mfd/hi6421-pmic-core.c new file +5
-0+return PTR_ERR (pmic->regmap); + } + + pmic->dev = dev; +platform_set_drvdata (pdev, pmic);It's not _that_ important, but I like to see this at the end after you know everything else has succeeded.
When I move this after mfd_add_devices(), it fails to boot. In mfd devices's probe, pmic->regmap is used.
Quoted 4 lines
drivers/mfd/hi6421-pmic-core.c line 85
Quoted 1 line
drivers/mfd/hi6421-pmic-core.c new file +1
-0+/* set over-current protection debounce 8ms*/ Should be a ' ' between '8ms' and '*/'.
Quoted 10 lines
drivers/mfd/hi6421-pmic-core.c line 92
Quoted 7 lines
drivers/mfd/hi6421-pmic-core.c new file +7
-0+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 )); + + ret =mfd_add_devices (dev,0 , hi6421_devs, +ARRAY_SIZE (hi6421_devs),NULL ,0 ,NULL );I'd like to see an error message if
mfd_add_devices()fails.
Will do.
Quoted 8 lines
Quoted 8 lines
drivers/mfd/hi6421-pmic-core.c new file +8
-0+return ret; +} + +static int hi6421_pmic_remove (struct platform_device *pdev) +{ +mfd_remove_devices (&pdev->dev); + +return 0 ;
Quoted 9 lines
drivers/mfd/hi6421-pmic-core.c line 107
Quoted 6 lines
drivers/mfd/hi6421-pmic-core.c new file +6
-0+} + +static struct platform_driver hi6421_pmic_driver = { + .driver = { + .name ="hi6421_pmic" , + .owner =THIS_MODULE ,This is taken care of for you, you can remove it.
Will do.
Quoted 42 lines
Quoted 42 lines
drivers/mfd/hi6421-pmic-core.c new file +10
-0+ .of_match_table = of_hi6421_pmic_match_tbl, + }, + .probe = hi6421_pmic_probe, + .remove = hi6421_pmic_remove, +}; +module_platform_driver (hi6421_pmic_driver); + +MODULE_AUTHOR ("Guodong Xu <[email protected]>" ); +MODULE_DESCRIPTION ("Hi6421 PMIC driver" ); +MODULE_LICENSE ("GPL v2" );include/linux/mfd/hi6421-pmic.h new file +26
-0@@ -0,0 +1,39 @@ +/* +* Header file for device driver Hi6421 PMIC +* +* Copyright (c) <2011-2014> HiSilicon Technologies Co., Ltd. +* http://www.hisilicon.com +* Copyright (c) <2013-2014> Linaro Ltd. +* http://www.linaro.org +* +* Author: Guodong Xu <[email protected]> +* +* 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. +*/ + +#ifndef __HI6421_PMIC_H +#define __HI6421_PMIC_H + +/* Hi6421 registers are mapped to memory bus in 4 bytes stride */ +#define HI6421_REG_TO_BUS_ADDR (x) (x << 2) + +/* Hi6421 OCP (over current protection) and DEB (debounce) control register */ +#define HI6421_OCP_DEB_CTRL_REG HI6421_REG_TO_BUS_ADDR(0x51) +#define HI6421_OCP_DEB_SEL_MASK (0x0C) +#define HI6421_OCP_DEB_SEL_8MS (0x00) +#define HI6421_OCP_DEB_SEL_16MS (0x04)
Quoted 9 lines
include/linux/mfd/hi6421-pmic.h line 32
Quoted 6 lines
include/linux/mfd/hi6421-pmic.h new file +6
-0+#define HI6421_OCP_DEB_SEL_32MS (0x08) +#define HI6421_OCP_DEB_SEL_64MS (0x0C) +#define HI6421_OCP_EN_DEBOUNCE_MASK (0x02) +#define HI6421_OCP_EN_DEBOUNCE_ENABLE (0x02) +#define HI6421_OCP_AUTO_STOP_MASK (0x01) +#define HI6421_OCP_AUTO_STOP_ENABLE (0x01)Remove the ()'s.
Will do.
Thanks.
Guodong
Quoted 7 lines
Quoted 6 lines
include/linux/mfd/hi6421-pmic.h new file +6
-0+struct hi6421_pmic { +struct device *dev; +struct regmap *regmap; +}; + +#endif /* __HI6421_PMIC_H */
Re: [PATCH v6 4/6] mfd: Add hi6421 PMIC core driver
Quoted 14 lines · Guodong Xu
Quoted 13 lines · Lee Jones
Quoted 12 lines · Guodong Xu
This adds driver to support HiSilicon Hi6421 PMIC. Hi6421 includes multi- functions, such as regulators, codec, ADCs, Coulomb counter, etc. This driver includes core APIs _only_.
Drivers for individul components, like voltage regulators, are implemented in corresponding driver directories and files.
Registers in Hi6421 are memory mapped, so using regmap-mmio API.
Signed-off-by Guodong Xu <[email protected]>--- Documentation/devicetree/bindings/mfd/hi6421.txt | 37 +++++++
[...]
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
+ * Author: Guodong Xu <[email protected]>
+ *
+ * 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.
Quoted 6 lines
Quoted 4 lines
This should also contain a link to the full licence.
See: COPYING
Thanks. I checked COPYING, but there is no 'link' to full license. I
I was making reference to the fact that COPYING tells you to provide a link to the full notice:
"To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found."
Quoted 2 lines
copied a link from other c source: http://www.gnu.org/licenses/
is that OK?
Yes, that's fine.
Quoted 7 lines
Quoted 4 lines
drivers/mfd/hi6421-pmic-core.c line 83
Quoted 1 line
drivers/mfd/hi6421-pmic-core.c new file +1
-0+platform_set_drvdata (pdev, pmic);It's not _that_ important, but I like to see this at the end after you know everything else has succeeded.
When I move this after
mfd_add_devices(), it fails to boot. In mfd devices's probe,pmic->regmapis used.
You can move it to just before mfd_add_devices().
Signature · 4 lines
Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org ? Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog
PATCH v6 5/6 regulator: add driver for hi6421 voltage regulator
In reply to Guodong XuAdd driver support for HiSilicon Hi6421 voltage regulators.
Two rules for regulator enabling are defined in hi6421 spec:
1) Between disable and enable of each regulator (LDOs or BUCKs), there must be a protection gap. Use @off_on_delay of regulator core to implement this.
2) No two regulators can be enabled at the same time. Use mutex in hi6421_regulator_pdata to ensure this. A protection gap of 100us is added into each LDO/BUCK's .enable_time.
--- drivers/regulator/Kconfig | 10 + drivers/regulator/Makefile | 1 + drivers/regulator/hi6421-regulator.c | 657 +++++++++++++++++++++++++++++++++++ 3 files changed, 668 insertions(+) create mode 100644 drivers/regulator/hi6421-regulator.c
drivers/regulator/Kconfig +10 -0
@@ -240,6 +240,16 @@ config REGULATOR_GPIO and the platform has to provide a mapping of GPIO-states to target volts/amps. +config REGULATOR_HI6421 + tristate "HiSilicon Hi6421 PMIC voltage regulator support" + depends on MFD_HI6421_PMIC && OF + help + This driver provides support for the voltage regulators on the + HiSilicon Hi6421 PMU / Codec IC. + Hi6421 is a multi-function device which, on regulator part, provides + 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_ISL6271A tristate "Intersil ISL6271A Power regulator" depends on I2C
drivers/regulator/Makefile +1 -0
@@ -32,6 +32,7 @@ obj-$(CONFIG_REGULATOR_DBX500_PRCMU) += dbx500-prcmu.o 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_ISL6271A) += isl6271a-regulator.o obj-$(CONFIG_REGULATOR_LP3971) += lp3971.o obj-$(CONFIG_REGULATOR_LP3972) += lp3972.o
drivers/regulator/hi6421-regulator.c new file +657 -0
657 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH v6 6/6 ARM: dts: hi3620-hi4511: Add HI6421 MFD and regulator nodes
In reply to Guodong XuAdd Hi6421 MFD dts node and regulator nodes into hi3620-hi4511 board config dts file.
--- arch/arm/boot/dts/hi3620-hi4511.dts | 233 ++++++++++++++++++++++++++++++++++++ 1 file changed, 233 insertions(+)
arch/arm/boot/dts/hi3620-hi4511.dts +233 -0
@@ -635,6 +635,239 @@ pinctrl-single,bias-pullup = <0 1 0 1>; }; }; + + pmic: pmic at c00000 { + compatible = "hisilicon,hi6421-pmic"; + reg = <0xc00000 0x0180>; /* 0x60 << 2 */ + + regulators { + // supply for MLC NAND/ eMMC + hi6421_vout0_reg: hi6421_vout0 { + regulator-name = "VOUT0"; + regulator-min-microvolt = <2850000>; + regulator-max-microvolt = <2850000>; + }; + + // supply for 26M Oscillator + hi6421_vout1_reg: hi6421_vout1 { + regulator-name = "VOUT1"; + regulator-min-microvolt = <1700000>; + regulator-max-microvolt = <2000000>; + regulator-boot-on; + regulator-always-on; + }; + + // supply for AP system + hi6421_vout2_reg: hi6421_vout2 { + regulator-name = "VOUT2"; + regulator-min-microvolt = <1050000>; + regulator-max-microvolt = <1400000>; + regulator-boot-on; + regulator-always-on; + }; + + // supply for DDR PHY I/O + hi6421_vout3_reg: hi6421_vout3 { + regulator-name = "VOUT3"; + regulator-min-microvolt = <1050000>; + regulator-max-microvolt = <1400000>; + regulator-boot-on; + regulator-always-on; + }; + + // supply for MIPI, USB2.0, PCIe, PLL Analog + hi6421_vout4_reg: hi6421_vout4 { + regulator-name = "VOUT4"; + regulator-min-microvolt = <1500000>; + regulator-max-microvolt = <3000000>; + regulator-boot-on; + regulator-always-on; + }; + + // supply for I/O 1.8V + hi6421_vout5_reg: hi6421_vout5 { + regulator-name = "VOUT5"; + regulator-min-microvolt = <1500000>; + regulator-max-microvolt = <3000000>; + regulator-boot-on; + regulator-always-on; + }; + + // supply for I/O 2.6V + hi6421_vout6_reg: hi6421_vout6 { + regulator-name = "VOUT6"; + regulator-min-microvolt = <1500000>; + regulator-max-microvolt = <3000000>; + regulator-boot-on; + regulator-always-on; + }; + + // supply for SD I/O + hi6421_vout7_reg: hi6421_vout7 { + regulator-name = "VOUT7"; + regulator-min-microvolt = <1500000>; + regulator-max-microvolt = <3000000>; + regulator-boot-on; + regulator-always-on; + }; + + // supply for USB PHY + hi6421_vout8_reg: hi6421_vout8 { + regulator-name = "VOUT8"; + regulator-min-microvolt = <1500000>; + regulator-max-microvolt = <3300000>; + regulator-boot-on; + regulator-always-on; + }; + + // supply for Efuse power + hi6421_vout9_reg: hi6421_vout9 { + regulator-name = "VOUT9"; + regulator-min-microvolt = <1500000>; + regulator-max-microvolt = <3000000>; + }; + + // supply for BT RF&PA + hi6421_vout10_reg: hi6421_vout10 { + regulator-name = "VOUT10"; + regulator-min-microvolt = <1500000>; + regulator-max-microvolt = <3000000>; + }; + + // supply for GPS RF&PA + hi6421_vout11_reg: hi6421_vout11 { + regulator-name = "VOUT11"; + regulator-min-microvolt = <1500000>; + regulator-max-microvolt = <3000000>; + }; + + // supply for SD card + hi6421_vout12_reg: hi6421_vout12 { + regulator-name = "VOUT12"; + regulator-min-microvolt = <2850000>; + regulator-max-microvolt = <2850000>; + }; + + // supply for CMMB + hi6421_vout13_reg: hi6421_vout13 { + regulator-name = "VOUT13"; + regulator-min-microvolt = <1500000>; + regulator-max-microvolt = <3000000>; + }; + + // supply for WIFI I/O + hi6421_vout14_reg: hi6421_vout14 { + regulator-name = "VOUT14"; + regulator-min-microvolt = <1500000>; + regulator-max-microvolt = <3000000>; + }; + + // supply for WIFI core & PA + hi6421_vout15_reg: hi6421_vout15 { + regulator-name = "VOUT15"; + regulator-min-microvolt = <1500000>; + regulator-max-microvolt = <3300000>; + }; + + // supply for LCD I/O + hi6421_vout16_reg: hi6421_vout16 { + regulator-name = "VOUT16"; + regulator-min-microvolt = <1500000>; + regulator-max-microvolt = <3000000>; + regulator-always-on; + }; + + // supply for LCD Ananlog + hi6421_vout17_reg: hi6421_vout17 { + regulator-name = "VOUT17"; + regulator-min-microvolt = <1500000>; + regulator-max-microvolt = <3000000>; + regulator-always-on; + }; + + // supply for Camera I/O + hi6421_vout18_reg: hi6421_vout18 { + regulator-name = "VOUT18"; + regulator-min-microvolt = <1500000>; + regulator-max-microvolt = <3000000>; + }; + + // supply for Camera Analog + hi6421_vout19_reg: hi6421_vout19 { + regulator-name = "VOUT19"; + regulator-min-microvolt = <1500000>; + regulator-max-microvolt = <3000000>; + }; + + // supply for Camera VCM + hi6421_vout20_reg: hi6421_vout20 { + regulator-name = "VOUT20"; + regulator-min-microvolt = <1500000>; + regulator-max-microvolt = <3000000>; + }; + + // supply for Audio, incl. HKADC + hi6421_vout_audio_reg: hi6421_vout_audio { + regulator-name = "AVDD2"; + regulator-min-microvolt = <2800000>; + regulator-max-microvolt = <3300000>; + }; + + // supply for Cortex-A9 CPU core + hi6421_buck0_reg: hi6421_buck0 { + regulator-name = "VBUCK0"; + regulator-min-microvolt = <700000>; + regulator-max-microvolt = <1600000>; + regulator-boot-on; + regulator-always-on; + }; + + // supply for Cortex-A9 CPU core + hi6421_buck1_reg: hi6421_buck1 { + regulator-name = "VBUCK1"; + regulator-min-microvolt = <700000>; + regulator-max-microvolt = <1600000>; + regulator-boot-on; + regulator-always-on; + }; + + // supply for GPU + hi6421_buck2_reg: hi6421_buck2 { + regulator-name = "VBUCK2"; + regulator-min-microvolt = <700000>; + regulator-max-microvolt = <1600000>; + regulator-boot-on; + }; + + // supply for Peripheral + hi6421_buck3_reg: hi6421_buck3 { + regulator-name = "VBUCK3"; + regulator-min-microvolt = <950000>; + regulator-max-microvolt = <1200000>; + regulator-boot-on; + regulator-always-on; + }; + + // supply for LPDDR2 and AP I/O + hi6421_buck4_reg: hi6421_buck4 { + regulator-name = "VBUCK4"; + regulator-min-microvolt = <1150000>; + regulator-max-microvolt = <2000000>; + regulator-boot-on; + regulator-always-on; + }; + + // supply for Low voltage + hi6421_buck5_reg: hi6421_buck5 { + regulator-name = "VBUCK5"; + regulator-min-microvolt = <1150000>; + regulator-max-microvolt = <1900000>; + regulator-boot-on; + regulator-always-on; + }; + }; + }; + }; gpio-keys {
Signature · 1 line
1.9.1