regulator: msm: Add PM8921 regulator driver
Subsystems (5)
cover regulator: msm: Add PM8921 regulator driver
This patch set adds a new regulator driver to control the regulators in Qualcomm PM8921 PMIC chips. It also introduces board file changes to use this new driver with the Qualcomm MSM 8960 platform.
This patch set depends upon the following outstanding PM8XXX and PM8921 patches:
https://patchwork.kernel.org/patch/643231/
https://patchwork.kernel.org/patch/643221/
https://patchwork.kernel.org/patch/643201/
https://patchwork.kernel.org/patch/643211/
https://patchwork.kernel.org/patch/643241/
David Collins (2):
regulator: pm8921-regulator: Add regulator driver for PM8921
msm: board-8960: Add support for pm8921-regulator
arch/arm/mach-msm/Makefile | 1 + arch/arm/mach-msm/board-msm8960-regulator.c | 303 ++++ arch/arm/mach-msm/board-msm8960.c | 6 + arch/arm/mach-msm/board-msm8960.h | 23 + drivers/mfd/pm8921-core.c | 32 +- drivers/regulator/Kconfig | 10 + drivers/regulator/Makefile | 1 + drivers/regulator/pm8921-regulator.c | 2211 +++++++++++++++++++++++++++ include/linux/mfd/pm8xxx/pm8921.h | 3 + include/linux/regulator/pm8921-regulator.h | 97 ++ 10 files changed, 2686 insertions(+), 1 deletions(-) create mode 100644 arch/arm/mach-msm/board-msm8960-regulator.c create mode 100644 arch/arm/mach-msm/board-msm8960.h create mode 100644 drivers/regulator/pm8921-regulator.c create mode 100644 include/linux/regulator/pm8921-regulator.h
Signature · 2 lines
Sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
PATCH 1/2 regulator: pm8921-regulator: Add regulator driver for PM8921
Create a regulator driver to control all regulators on the Qualcomm PM8921 PMIC chip. This chip contains many different types of regulators with a wide range of abilities and voltage ranges.
Eight different regulator types are available on the PM8921. These are managed via 7 different type values in the driver:
LDO - low drop out regulator (supports both NMOS and PMOS LDOs)
NLDO1200 - 1.2A NMOS LDO (different control structure than other LDOs)
SMPS - switched-mode power supply FTSMPS - fast transient SMPS VS - voltage switch VS300 - 300mA voltage switch (different control structure than
other switches)
NCP - negative charge pump
The driver interfaces with the PMIC using Qualcomm's SSBI bus. Calls to this bus are abtracted through the pm8xxx_readb/writeb API.
Regulator framework operation callback functions work as expected with one exception: pm8921_vreg_get_mode and pm8921_vreg_set_mode. These callbacks are shared by all regulator types in the driver. The mode setting scheme was modified from the normal framework usage to accommodate pin control. Pin control allows a regulator that has been disabled by software writing to its control registers to become enabled by a hardware pin. Many of the PM8921 regulators support pin control (as do those on other Qualcomm PMIC chips). It is primarily used by peripheral devices that need to be able to actively manage power usage while the main processor which is connected to the PMIC SSBI bus is asleep.
Pin control is handled in the PM8921 regulator driver via the set_mode callback function pm8921_vreg_set_mode. It treats mode values as follows:
REGULATOR_MODE_FAST - set to high power mode (HPM) REGULATOR_MODE_NORMAL - remove a vote for pin control REGULATOR_MODE_IDLE - vote for pin control (ref-counted)
REGULATOR_MODE_STANDBY - set to low power mode (LPM)
There is an additional caveat that pin control mode will override LPM such that, a set mode call for LPM will be ignored if the pin control reference count is greater than 0. Similarly, HPM will override pin control mode. Transitivity is not maintained though, because the mode can be changed from HPM to LPM. This ensures that it is still possible to transition freely between LPM and HPM with calls to regulator_set_optimum_mode.
--- drivers/mfd/pm8921-core.c | 32 +- drivers/regulator/Kconfig | 10 + drivers/regulator/Makefile | 1 + drivers/regulator/pm8921-regulator.c | 2211 ++++++++++++++++++++++++++++ include/linux/mfd/pm8xxx/pm8921.h | 3 + include/linux/regulator/pm8921-regulator.h | 97 ++ 6 files changed, 2353 insertions(+), 1 deletions(-) create mode 100644 drivers/regulator/pm8921-regulator.c create mode 100644 include/linux/regulator/pm8921-regulator.h
drivers/mfd/pm8921-core.c +31 -1
@@ -119,8 +119,9 @@ static int __devinit pm8921_add_subdevices(const struct pm8921_platform_datastruct pm8921 *pmic, u32 rev) { - int ret = 0, irq_base = 0; + int ret = 0, irq_base = 0, i;struct pm_irq_chip *irq_chip; +static struct mfd_cell *mfd_regulators;if (pdata->irq_pdata) { pdata->irq_pdata->irq_cdata.nirqs =PM8921_NR_IRQS ;
@@ -162,6 +163,35 @@ static int __devinit pm8921_add_subdevices(const struct pm8921_platform_data } } +/* Add one device for each regulator used by the board. */ +if (pdata->num_regulators >0 && pdata->regulator_pdatas) { + mfd_regulators =kzalloc (sizeof (struct mfd_cell ) + * (pdata->num_regulators),GFP_KERNEL ); +if (!mfd_regulators) { +pr_err ("Cannot allocate %d bytes for pm8921 regulator " +"mfd cells\n" ,sizeof (struct mfd_cell ) + * (pdata->num_regulators)); + ret = -ENOMEM ; + goto bail; + } +for (i =0 ; i < pdata->num_regulators; i++) { + mfd_regulators[i].name =PM8921_REGULATOR_DEV_NAME ; + mfd_regulators[i].id = pdata->regulator_pdatas[i].id; + mfd_regulators[i].platform_data = + &(pdata->regulator_pdatas[i]); + mfd_regulators[i].data_size = +sizeof (struct pm8921_regulator_platform_data ); + } + ret =mfd_add_devices (pmic->dev,0 , mfd_regulators, + pdata->num_regulators,NULL , irq_base); +kfree (mfd_regulators); +if (ret) { +pr_err ("Failed to add regulator subdevices ret=%d\n" , + ret); + goto bail; + } + } +return 0 ; bail:if (pmic->irq_chip) {
drivers/regulator/Kconfig +10 -0
@@ -272,5 +272,15 @@ config REGULATOR_TPS6524X serial interface currently supported on the sequencer serial port controller. +config REGULATOR_PM8921 + tristate "Qualcomm PM8921 PMIC Power regulators" + depends on MFD_PM8921_CORE + default y if MFD_PM8921_CORE + help + This driver supports voltage regulators in the Qualcomm PM8921 PMIC + chip. The PM8921 provides several different varieties of LDO and + switching regulators. It also provides a negative charge pump and + voltage switches. + endif
drivers/regulator/Makefile +1 -0
@@ -40,5 +40,6 @@ obj-$(CONFIG_REGULATOR_TPS6524X) += tps6524x-regulator.o obj-$(CONFIG_REGULATOR_88PM8607) += 88pm8607.o obj-$(CONFIG_REGULATOR_ISL6271A) += isl6271a-regulator.o obj-$(CONFIG_REGULATOR_AB8500) += ab8500.o +obj-$(CONFIG_REGULATOR_PM8921) += pm8921-regulator.o ccflags-$(CONFIG_REGULATOR_DEBUG) += -DDEBUG
drivers/regulator/pm8921-regulator.c new file +2211 -0
2,211 lines not on this page · raw message
include/linux/mfd/pm8xxx/pm8921.h +3 -0
@@ -22,6 +22,7 @@#include <linux/mfd/pm8xxx/irq.h> #include <linux/mfd/pm8xxx/gpio.h> #include <linux/mfd/pm8xxx/mpp.h> +#include <linux/regulator/pm8921-regulator.h> #define PM8921_NR_IRQS 256
@@ -44,6 +45,8 @@ struct pm8921_platform_data {struct pm8xxx_irq_platform_data *irq_pdata;struct pm8xxx_gpio_platform_data *gpio_pdata;struct pm8xxx_mpp_platform_data *mpp_pdata; +struct pm8921_regulator_platform_data *regulator_pdatas; + int num_regulators; };#endif
include/linux/regulator/pm8921-regulator.h new file +97 -0
97 lines not on this page · raw message
Signature · 2 lines
Sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
Re: [PATCH 1/2] regulator: pm8921-regulator: Add regulator driver for PM8921
Quoted 7 lines · David Collins
Regulator framework operation callback functions work as expected with one exception:
pm8921_vreg_get_modeandpm8921_vreg_set_mode. These callbacks are shared by all regulator types in the driver. The mode setting scheme was modified from the normal framework usage to accommodate pin control. Pin control allows a regulator that has been disabled by software writing to its control registers to become enabled by a hardware pin. Many of the PM8921 regulators support pin
Don't do this. There's two problems with it. One is that you're abusing a standard API for an unrelated purpose which will confuse anything that tries to use the API as normal, the other is that this sounds like a fairly widely supported feature (although normally one that is used with a GPIO on the CPU, there's a few examples of this in mainline).
Quoted 5 lines
REGULATOR_MODE_FAST - set to high power mode (HPM) REGULATOR_MODE_NORMAL - remove a vote for pin control REGULATOR_MODE_IDLE - vote for pin control (ref-counted)
REGULATOR_MODE_STANDBY- set to low power mode (LPM)
Quoted 7 lines
There is an additional caveat that pin control mode will override LPM such that, a set mode call for LPM will be ignored if the pin control reference count is greater than 0. Similarly, HPM will override pin control mode. Transitivity is not maintained though, because the mode can be changed from HPM to LPM. This ensures that it is still possible to transition freely between LPM and HPM with calls to
regulator_set_optimum_mode.
What is the voting that's been referred to here?
drivers/mfd/pm8921-core.c static int __devinit pm8921_add_subdevices(const struct pm8921_platform_data · line 123
Quoted 9 lines
drivers/mfd/pm8921-core.c +1
-1@@ -119,8 +119,9 @@ static int __devinit pm8921_add_subdevices(const struct pm8921_platform_datastruct pm8921 *pmic, u32 rev) { - int ret = 0, irq_base = 0; + int ret = 0, irq_base = 0, i;struct pm_irq_chip *irq_chip;
Don't mix initialised and non-initialised definitions.
drivers/mfd/pm8921-core.c static int __devinit pm8921_add_subdevices(const struct pm8921_platform_data · line 176
Quoted 11 lines
drivers/mfd/pm8921-core.c +11
-0+/* Add one device for each regulator used by the board. */ +if (pdata->num_regulators >0 && pdata->regulator_pdatas) { + mfd_regulators =kzalloc (sizeof (struct mfd_cell ) + * (pdata->num_regulators),GFP_KERNEL ); +if (!mfd_regulators) { +pr_err ("Cannot allocate %d bytes for pm8921 regulator " +"mfd cells\n" ,sizeof (struct mfd_cell ) + * (pdata->num_regulators)); + ret = -ENOMEM ; + goto bail; + }
I know some devices do follow this pattern but it's simpler to just register the regulators that are physically present on the device unconditionally.
drivers/mfd/pm8921-core.c
Quoted 2 lines
drivers/mfd/pm8921-core.c +2
-0+static int pm8921_vreg_write (struct pm8921_vreg *vreg,u16 addr,u8 val, +u8 mask,u8 *reg_save)
The function is confusingly named - it's actually a bitmask update but write() would normally suggest a straight write of an absolute value.
Quoted 5 lines
drivers/mfd/pm8921-core.c +5
-0+{ +int rc =0 ; +u8 reg; + + reg = (*reg_save & ~mask) | (val & mask);
drivers/mfd/pm8921-core.c
Quoted 10 lines
drivers/mfd/pm8921-core.c +10
-0+if (reg != *reg_save) + rc =pm8xxx_writeb (vreg->dev->parent, addr, reg); + +if (rc) +pr_err ("pm8xxx_writeb failed; addr=0x%03X, rc=%d\n" , addr, rc); +else + *reg_save = reg; + +return rc; +}
This needs locking if any registers are shared between multiple regulators.
drivers/mfd/pm8921-core.c
Quoted 3 lines
drivers/mfd/pm8921-core.c +3
-0+if (min_uV <PLDO_LOW_UV_MIN || min_uV >PLDO_HIGH_UV_MAX ) { +vreg_err (vreg,"requested voltage %d is outside of allowed " +"range.\n" , min_uV);
Don't split text over multiple lines, it's not helpful when grepping.
drivers/mfd/pm8921-core.c
Quoted 7 lines
drivers/mfd/pm8921-core.c +7
-0+static int pm8921_nldo1200_set_voltage (struct regulator_dev *rdev,int min_uV, +int max_uV,unsigned *selector) +{ +struct pm8921_vreg *vreg =rdev_get_drvdata (rdev); + +return _pm8921_nldo1200_set_voltage (vreg, min_uV); +}
I have to say I'm not finding the indirection to the _ functions is actually adding anything to the code here.
drivers/mfd/pm8921-core.c
Quoted 6 lines
drivers/mfd/pm8921-core.c +6
-0+/* Round down for set points in the gaps between bands. */ +if (uV >FTSMPS_BAND1_UV_MAX && uV <FTSMPS_BAND2_UV_MIN ) + uV =FTSMPS_BAND1_UV_MAX ; +else if (uV >FTSMPS_BAND2_UV_MAX + && uV <FTSMPS_BAND3_UV_SETPOINT_MIN ) + uV =FTSMPS_BAND2_UV_MAX ;
That seems broken - it means you'll go under voltage on what was requested. You should ensure that you're always within the requested range so if the higher band minimum is in the range you should select that, otherwise you should error out.
In general you're not checking that your voltage selection actually satisfies the request that went in...
drivers/mfd/pm8921-core.c
Quoted 7 lines
drivers/mfd/pm8921-core.c +7
-0+static int pm8921_ftsmps_set_voltage (struct regulator_dev *rdev,int min_uV, +int max_uV,unsigned *selector) +{ +struct pm8921_vreg *vreg =rdev_get_drvdata (rdev); + +return _pm8921_ftsmps_set_voltage (vreg, min_uV,0 ); +}
...note how you discard the upper limit on the requested voltage here before going into the implementation.
drivers/mfd/pm8921-core.c
Quoted 6 lines
drivers/mfd/pm8921-core.c +6
-0+static unsigned int pm8921_vreg_get_optimum_mode (struct regulator_dev *rdev, +int input_uV,int output_uV,int load_uA) +{ +struct pm8921_vreg *vreg =rdev_get_drvdata (rdev); + + vreg->save_uA = load_uA;
What's this about? There's no other references to save_uA in the driver and it looks suspicous.
drivers/mfd/pm8921-core.c
Quoted 4 lines
drivers/mfd/pm8921-core.c +4
-0+if (load_uA >= vreg->hpm_min_load) +return REGULATOR_MODE_FAST ; + +return REGULATOR_MODE_STANDBY ;
Using an else would be clearer and less error prone.
Quoted 4 lines
drivers/mfd/pm8921-core.c +4
-0+static int pm8921_vreg_enable (struct regulator_dev *rdev) +{ +struct pm8921_vreg *vreg =rdev_get_drvdata (rdev); +int mode, rc =0 ;
drivers/mfd/pm8921-core.c
Quoted 10 lines
drivers/mfd/pm8921-core.c +10
-0+ + mode =pm8921_vreg_get_mode (rdev); + +if (mode ==REGULATOR_MODE_IDLE ) { +/* Turn on pin control. */ + rc =pm8921_vreg_set_pin_ctrl (vreg,1 ); +if (rc) + goto bail; +return rc; + }
This looks wrong, it's not actually enabling the regulator but putting it into pin control mode instead. If something actually wanted the regulator enabling it's going to be disappointed.
drivers/mfd/pm8921-core.c
Quoted 9 lines
drivers/mfd/pm8921-core.c +9
-0+/* Disable in local control register. */ +if (vreg->type ==REGULATOR_TYPE_SMPS &&SMPS_IN_ADVANCED_MODE (vreg)) { +/* Change SMPS to legacy mode before disabling. */ + rc =pm8921_smps_set_voltage_legacy (vreg, vreg->save_uV); +if (rc) + goto bail; + rc =pm8921_vreg_write (vreg, vreg->ctrl_addr,REGULATOR_DISABLE , +REGULATOR_ENABLE_MASK , &vreg->ctrl_reg); + }else if (vreg->type ==REGULATOR_TYPE_FTSMPS ) {
This would all be a lot more legible with a switch statement for the regulator types.
Quoted 13 lines
drivers/mfd/pm8921-core.c +13
-0+static int __devinit pm8921_vreg_probe (struct platform_device *pdev) +{ +struct regulator_desc *rdesc; +struct pm8921_vreg *vreg; +const char *reg_name ="" ; +int rc =0 ; + +if (pdev ==NULL ) +return -EINVAL ; + +if (pdev->id >=0 && pdev->id <PM8921_VREG_ID_MAX ) { + rdesc = &pm8921_vreg_description[pdev->id]; + vreg = &pm8921_vreg[pdev->id];
drivers/mfd/pm8921-core.c
Quoted 10 lines
drivers/mfd/pm8921-core.c +10
-0+memcpy (&(vreg->pdata), pdev->dev.platform_data, +sizeof (struct pm8921_regulator_platform_data )); + reg_name = pm8921_vreg_description[pdev->id].name; + vreg->name = reg_name; + vreg->dev = &pdev->dev; + + rc =pm8921_init_regulator (vreg); +if (rc) + goto bail; +
This function is just a switch statement per regulator, may aswell expan ithere. Or restructure things so that you've got a driver per regulator type - that would also mean you'd be able to get the device IDs to correspond to the regulator numbers which would probably be clearer.
drivers/mfd/pm8921-core.c
Quoted 5 lines
drivers/mfd/pm8921-core.c +5
-0+static int __init pm8921_vreg_init (void ) +{ +return platform_driver_register (&pm8921_vreg_driver); +} +module_init (pm8921_vreg_init);
subsys_initcall().
Re: [PATCH 1/2] regulator: pm8921-regulator: Add regulator driver for PM8921
Quoted 10 lines · Mark Brown
Quoted 7 lines · David Collins
Regulator framework operation callback functions work as expected with one exception:
pm8921_vreg_get_modeandpm8921_vreg_set_mode. These callbacks are shared by all regulator types in the driver. The mode setting scheme was modified from the normal framework usage to accommodate pin control. Pin control allows a regulator that has been disabled by software writing to its control registers to become enabled by a hardware pin. Many of the PM8921 regulators support pin
Quoted 6 lines
Don't do this. There's two problems with it. One is that you're abusing a standard API for an unrelated purpose which will confuse anything that tries to use the API as normal, the other is that this sounds like a fairly widely supported feature (although normally one that is used with a GPIO on the CPU, there's a few examples of this in mainline).
Could you point out an example of a better way to handle pin control? I agree that regulator_set_mode is not the way to do it. Could some new regulator framework API be created to handle it? I'm not sure about the best way to generalize the interface.
Quoted 13 lines
Quoted 5 lines
REGULATOR_MODE_FAST - set to high power mode (HPM) REGULATOR_MODE_NORMAL - remove a vote for pin control REGULATOR_MODE_IDLE - vote for pin control (ref-counted)
REGULATOR_MODE_STANDBY- set to low power mode (LPM)Quoted 7 lines
There is an additional caveat that pin control mode will override LPM such that, a set mode call for LPM will be ignored if the pin control reference count is greater than 0. Similarly, HPM will override pin control mode. Transitivity is not maintained though, because the mode can be changed from HPM to LPM. This ensures that it is still possible to transition freely between LPM and HPM with calls to
regulator_set_optimum_mode.
Quoted 1 line
What is the voting that's been referred to here?
Voting here means calling regulator_set_mode(reg, REGULATOR_MODE_IDLE). These calls into the pm8921-regulator driver set_mode call back function are ref-counted to decide when to actually set pin control mode.
Quoted 11 lines
drivers/mfd/pm8921-core.c static int __devinit pm8921_add_subdevices(const struct pm8921_platform_data · line 123
Quoted 9 lines
drivers/mfd/pm8921-core.c +1
-1@@ -119,8 +119,9 @@ static int __devinit pm8921_add_subdevices(const struct pm8921_platform_datastruct pm8921 *pmic, u32 rev) { - int ret = 0, irq_base = 0; + int ret = 0, irq_base = 0, i;struct pm_irq_chip *irq_chip;Don't mix initialised and non-initialised definitions.
I will update this.
Quoted 7 lines
Quoted 7 lines
drivers/mfd/pm8921-core.c +7
-0+/* Add one device for each regulator used by the board. */ +if (pdata->num_regulators >0 && pdata->regulator_pdatas) { + mfd_regulators =kzalloc (sizeof (struct mfd_cell ) + * (pdata->num_regulators),GFP_KERNEL ); +if (!mfd_regulators) { +pr_err ("Cannot allocate %d bytes for pm8921 regulator " + "mfd cells\n", sizeof(struct mfd_cell)
Quoted 8 lines
drivers/mfd/pm8921-core.c static int __devinit pm8921_add_subdevices(const struct pm8921_platform_data · line 176
Quoted 4 lines
drivers/mfd/pm8921-core.c +4
-0+ * (pdata->num_regulators)); + ret = -ENOMEM ; + goto bail; + }I know some devices do follow this pattern but it's simpler to just register the regulators that are physically present on the device unconditionally.
Regulator registration needs to continue being based on which regulators are configured via the board file platform data because there will be need in our system in the near future to use a different (shared) regulator driver to access some of the same physical regulators.
We consider this to be the native PMIC 8921 regulator driver because it accesses the PMIC directly. There will be a subsequent PMIC 8921 regulator driver which issues requests to a separate processor which aggregates our requests with those of other SOC processors.
Quoted 5 lines
drivers/mfd/pm8921-core.c
Quoted 2 lines
drivers/mfd/pm8921-core.c +2
-0+static int pm8921_vreg_write (struct pm8921_vreg *vreg,u16 addr,u8 val, +u8 mask,u8 *reg_save)The function is confusingly named - it's actually a bitmask update but
write()would normally suggest a straight write of an absolute value.
I will change this to something more sane.
Quoted 10 lines
Quoted 10 lines
drivers/mfd/pm8921-core.c +10
-0+{ +int rc =0 ; +u8 reg; + + reg = (*reg_save & ~mask) | (val & mask); +if (reg != *reg_save) + rc =pm8xxx_writeb (vreg->dev->parent, addr, reg); + +if (rc) +pr_err ("pm8xxx_writeb failed; addr=0x%03X, rc=%d\n" , addr, rc);
Quoted 8 lines
drivers/mfd/pm8921-core.c
Quoted 5 lines
drivers/mfd/pm8921-core.c +5
-0+else + *reg_save = reg; + +return rc; +}This needs locking if any registers are shared between multiple regulators.
There are no registers shared between multiple regulators. The mutex locks held inside of the regulator framework should be sufficient.
Quoted 5 lines
drivers/mfd/pm8921-core.c
Quoted 3 lines
drivers/mfd/pm8921-core.c +3
-0+if (min_uV <PLDO_LOW_UV_MIN || min_uV >PLDO_HIGH_UV_MAX ) { +vreg_err (vreg,"requested voltage %d is outside of allowed " +"range.\n" , min_uV);Don't split text over multiple lines, it's not helpful when grepping.
I can change this, I'll just have to be ready to ignore checkpatch.pl errors.
Quoted 10 lines
drivers/mfd/pm8921-core.c
Quoted 7 lines
drivers/mfd/pm8921-core.c +7
-0+static int pm8921_nldo1200_set_voltage (struct regulator_dev *rdev,int min_uV, +int max_uV,unsigned *selector) +{ +struct pm8921_vreg *vreg =rdev_get_drvdata (rdev); + +return _pm8921_nldo1200_set_voltage (vreg, min_uV); +}I have to say I'm not finding the indirection to the _ functions is actually adding anything to the code here.
The _* functions are used so that only relevant data needs to be passed. It is preferable to grab vreg from rdev only once in the call chain.
Quoted 11 lines
drivers/mfd/pm8921-core.c
Quoted 6 lines
drivers/mfd/pm8921-core.c +6
-0+/* Round down for set points in the gaps between bands. */ +if (uV >FTSMPS_BAND1_UV_MAX && uV <FTSMPS_BAND2_UV_MIN ) + uV =FTSMPS_BAND1_UV_MAX ; +else if (uV >FTSMPS_BAND2_UV_MAX + && uV <FTSMPS_BAND3_UV_SETPOINT_MIN ) + uV =FTSMPS_BAND2_UV_MAX ;That seems broken - it means you'll go under voltage on what was requested. You should ensure that you're always within the requested range so if the higher band minimum is in the range you should select that, otherwise you should error out.
This rounding is done to ensure that the calculations below always yield a register program voltage that is valid. I could change this to pick the minimum of the higher band instead.
In this example, consider the second condition which is checking for min_uV in the range (1400000, 1500000). What should the correct result be if a consumer calls regulator_set_voltage(reg, 1450000, 1450000) (assuming that it is the only consumer so far and that the constraints step for the regulator allow the value)? As the driver is written, it would set the voltage to 1.4V. However, I think that 1.5V is more reasonable. Returning an error for this seems counter productive.
Quoted 13 lines
In general you're not checking that your voltage selection actually satisfies the request that went in...
drivers/mfd/pm8921-core.c
Quoted 7 lines
drivers/mfd/pm8921-core.c +7
-0+static int pm8921_ftsmps_set_voltage (struct regulator_dev *rdev,int min_uV, +int max_uV,unsigned *selector) +{ +struct pm8921_vreg *vreg =rdev_get_drvdata (rdev); + +return _pm8921_ftsmps_set_voltage (vreg, min_uV,0 ); +}...note how you discard the upper limit on the requested voltage here before going into the implementation.
Yes, it sets the voltage based exclusively on min_uV.
Quoted 9 lines
drivers/mfd/pm8921-core.c
Quoted 6 lines
drivers/mfd/pm8921-core.c +6
-0+static unsigned int pm8921_vreg_get_optimum_mode (struct regulator_dev *rdev, +int input_uV,int output_uV,int load_uA) +{ +struct pm8921_vreg *vreg =rdev_get_drvdata (rdev); + + vreg->save_uA = load_uA;What's this about? There's no other references to
save_uAin the driver and it looks suspicous.
save_uA should be removed.
Quoted 6 lines
drivers/mfd/pm8921-core.c
Quoted 4 lines
drivers/mfd/pm8921-core.c +4
-0+if (load_uA >= vreg->hpm_min_load) +return REGULATOR_MODE_FAST ; + +return REGULATOR_MODE_STANDBY ;Using an else would be clearer and less error prone.
I'll change it.
Quoted 10 lines
Quoted 10 lines
drivers/mfd/pm8921-core.c +10
-0+static int pm8921_vreg_enable (struct regulator_dev *rdev) +{ +struct pm8921_vreg *vreg =rdev_get_drvdata (rdev); +int mode, rc =0 ; + + mode =pm8921_vreg_get_mode (rdev); + +if (mode ==REGULATOR_MODE_IDLE ) { +/* Turn on pin control. */ + rc =pm8921_vreg_set_pin_ctrl (vreg,1 );
Quoted 8 lines
drivers/mfd/pm8921-core.c
Quoted 4 lines
drivers/mfd/pm8921-core.c +4
-0+if (rc) + goto bail; +return rc; + }This looks wrong, it's not actually enabling the regulator but putting it into pin control mode instead. If something actually wanted the regulator enabling it's going to be disappointed.
This comes back to the way that priorities are handled in order to get into pin control mode. If the regulator is set to pin control mode before regulator_enable is called, then pin control should be set instead of enabling the regulator normally. If it was in HPM instead (which would override pin control) then it would be enabled normally. regulator_disable turns off the regulator and also turns off pin control so that it is guaranteed to not output any voltage.
This setup will be improved with the addition of a better API to manipulate pin control.
Quoted 4 lines
Quoted 4 lines
drivers/mfd/pm8921-core.c +4
-0+/* Disable in local control register. */ +if (vreg->type ==REGULATOR_TYPE_SMPS &&SMPS_IN_ADVANCED_MODE (vreg)) { +/* Change SMPS to legacy mode before disabling. */ + rc =pm8921_smps_set_voltage_legacy (vreg, vreg->save_uV);
Quoted 8 lines
drivers/mfd/pm8921-core.c
Quoted 5 lines
drivers/mfd/pm8921-core.c +5
-0+if (rc) + goto bail; + rc =pm8921_vreg_write (vreg, vreg->ctrl_addr,REGULATOR_DISABLE , +REGULATOR_ENABLE_MASK , &vreg->ctrl_reg); + }else if (vreg->type ==REGULATOR_TYPE_FTSMPS ) {This would all be a lot more legible with a switch statement for the regulator types.
I'll change it to a switch statement.
Quoted 20 lines
Quoted 20 lines
drivers/mfd/pm8921-core.c +20
-0+static int __devinit pm8921_vreg_probe (struct platform_device *pdev) +{ +struct regulator_desc *rdesc; +struct pm8921_vreg *vreg; +const char *reg_name ="" ; +int rc =0 ; + +if (pdev ==NULL ) +return -EINVAL ; + +if (pdev->id >=0 && pdev->id <PM8921_VREG_ID_MAX ) { + rdesc = &pm8921_vreg_description[pdev->id]; + vreg = &pm8921_vreg[pdev->id]; +memcpy (&(vreg->pdata), pdev->dev.platform_data, +sizeof (struct pm8921_regulator_platform_data )); + reg_name = pm8921_vreg_description[pdev->id].name; + vreg->name = reg_name; + vreg->dev = &pdev->dev; + + rc =pm8921_init_regulator (vreg);
Quoted 8 lines
drivers/mfd/pm8921-core.c
Quoted 3 lines
drivers/mfd/pm8921-core.c +3
-0+if (rc) + goto bail; +This function is just a switch statement per regulator, may aswell expan ithere. Or restructure things so that you've got a driver per regulator type - that would also mean you'd be able to get the device IDs to correspond to the regulator numbers which would probably be clearer.
I separated out the type specific init functions because they are relatively lengthy and independent. Wouldn't putting that code directly into a switch statement in the probe function be hard to follow?
Quoted 7 lines
drivers/mfd/pm8921-core.c
Quoted 5 lines
drivers/mfd/pm8921-core.c +5
-0+static int __init pm8921_vreg_init (void ) +{ +return platform_driver_register (&pm8921_vreg_driver); +} +module_init (pm8921_vreg_init);
subsys_initcall().
I'll change it.
- David
Signature · 2 lines
Sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
Re: [PATCH 1/2] regulator: pm8921-regulator: Add regulator driver for PM8921
Quoted 9 lines · David Collins
Quoted 6 lines · Mark Brown
Don't do this. There's two problems with it. One is that you're abusing a standard API for an unrelated purpose which will confuse anything that tries to use the API as normal, the other is that this sounds like a fairly widely supported feature (although normally one that is used with a GPIO on the CPU, there's a few examples of this in mainline).
Quoted 4 lines
Could you point out an example of a better way to handle pin control? I agree that
regulator_set_modeis not the way to do it. Could some new regulator framework API be created to handle it? I'm not sure about the best way to generalize the interface.
The wm831x DCDCs and several of the Maxim PMICs have GPIO based control, though as indicated it's currently set up for CPU control rather than for control from an external device. In the case of the wm831x this could be switched to and from hardware control at runtime though that's not a feature that's currently used. There's also some devices which have seperate controls for different users that do contention control in hardware.
Without actually knowing what the pin control implementation you have does and how it's used it's hard to suggest something specific. I still don't have a good handle on what is voting, what is actually being controlled or how it interacts with software control by Linux. We've jumped to discussion of the implementation without understanding the problem. Could you perhaps go back to square one and explain what exactly you mean when you say "pin control"?
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
REGULATOR_MODE_NORMAL- remove a vote for pin controlREGULATOR_MODE_IDLE- vote for pin control (ref-counted)What is the voting that's been referred to here?
Voting here means calling
regulator_set_mode(reg, REGULATOR_MODE_IDLE). These calls into the pm8921-regulator driverset_modecall back function are ref-counted to decide when to actually set pin control mode.
OK, that's definitely not going to work well with set_mode() - it relies on nothing except drivers that know about your reference counting scheme ever calling set_mode() and the core code never learning how to do things like suppress duplicate sets.
Quoted 9 lines
Quoted 3 lines
I know some devices do follow this pattern but it's simpler to just register the regulators that are physically present on the device unconditionally.
Regulator registration needs to continue being based on which regulators are configured via the board file platform data because there will be need in our system in the near future to use a different (shared) regulator driver to access some of the same physical regulators.
Quoted 4 lines
We consider this to be the native PMIC 8921 regulator driver because it accesses the PMIC directly. There will be a subsequent PMIC 8921 regulator driver which issues requests to a separate processor which aggregates our requests with those of other SOC processors.
That's not an issue - the regulator API won't write to the regulators unless the machine driver explicitly tells it that this is OK so all that will happen is that we'll be able to read back the state of the regulators directly. If your driver is modifying the state of the regulators without the API telling it to then we should fix that as the no-write behaviour is an important safety feature.
Quoted 5 lines
Quoted 2 lines
This needs locking if any registers are shared between multiple regulators.
There are no registers shared between multiple regulators. The mutex locks held inside of the regulator framework should be sufficient.
OK, a comment would help - this is a very common error in regulator drivers as many regulators put all the enable bits for the system in a single register.
Quoted 7 lines
Quoted 5 lines
drivers/regulator/pm8921-regulator.c line 586
Quoted 3 lines
drivers/regulator/pm8921-regulator.c new file +3
-0+if (min_uV <PLDO_LOW_UV_MIN || min_uV >PLDO_HIGH_UV_MAX ) { +vreg_err (vreg,"requested voltage %d is outside of allowed " +"range.\n" , min_uV);Don't split text over multiple lines, it's not helpful when grepping.
I can change this, I'll just have to be ready to ignore checkpatch.pl errors.
checkpatch isn't always right on style issues. In this particular case having the string on a line by itself will probably avoid the issue.
Quoted 12 lines
Quoted 11 lines
drivers/regulator/pm8921-regulator.c line 1024
Quoted 6 lines
drivers/regulator/pm8921-regulator.c new file +6
-0+/* Round down for set points in the gaps between bands. */ +if (uV >FTSMPS_BAND1_UV_MAX && uV <FTSMPS_BAND2_UV_MIN ) + uV =FTSMPS_BAND1_UV_MAX ; +else if (uV >FTSMPS_BAND2_UV_MAX + && uV <FTSMPS_BAND3_UV_SETPOINT_MIN ) + uV =FTSMPS_BAND2_UV_MAX ;That seems broken - it means you'll go under voltage on what was requested. You should ensure that you're always within the requested range so if the higher band minimum is in the range you should select that, otherwise you should error out.
Quoted 3 lines
This rounding is done to ensure that the calculations below always yield a register program voltage that is valid. I could change this to pick the minimum of the higher band instead.
Note the thing about rechecking against the bounds - you need to look at *both* limits.
Quoted 7 lines
In this example, consider the second condition which is checking for
min_uVin the range (1400000, 1500000). What should the correct result be if a consumer callsregulator_set_voltage(reg, 1450000, 1450000)(assuming that it is the only consumer so far and that the constraints step for the regulator allow the value)? As the driver is written, it would set the voltage to 1.4V. However, I think that 1.5V is more reasonable. Returning an error for this seems counter productive.
The driver should return an error. If the consumer wanted exactly 1.45V then that's what the system should deliver, if the consumer is happy with other voltages then it should say so. The specification by range is there because some consumers are sensitive to particular voltages and need to get what they asked for, or they may have much more flexibility in one direction or the other (like DVFS where it's usually no problem to be overvoltage but being undervoltage will usually fail). By allowing the consumer to specify a range we allow the consumer to control this, having the API or the drivers take guesses on behalf of the consumer means it's hard for a consumer driver to reliably interoperate with different regulators.
The API provides a mechanism for enumerating the set of supported voltages (which IIRC you're not implementing - you should) which consumers can use to ensure good interoperation.
Quoted 8 lines
Quoted 4 lines
This function is just a switch statement per regulator, may aswell expan ithere. Or restructure things so that you've got a driver per regulator type - that would also mean you'd be able to get the device IDs to correspond to the regulator numbers which would probably be clearer.
I separated out the type specific init functions because they are relatively lengthy and independent. Wouldn't putting that code directly into a switch statement in the probe function be hard to follow?
Right, but the _init() function is basically just a switch statement which calls these functions AFAIR - inlining the switch statement doesn't mean inlining the functions too.
Re: [PATCH 1/2] regulator: pm8921-regulator: Add regulator driver for PM8921
Quoted 7 lines · Mark Brown
Without actually knowing what the pin control implementation you have does and how it's used it's hard to suggest something specific. I still don't have a good handle on what is voting, what is actually being controlled or how it interacts with software control by Linux. We've jumped to discussion of the implementation without understanding the problem. Could you perhaps go back to square one and explain what exactly you mean when you say "pin control"?
The PMIC 8921 has 4 pin control input pins named: A0, A1, D0, D1 (as noted in pm8921-regulator.h from my patch). Each regulator has a pin control register which provides 8 configuration bits. 4 of these bits correspond to transitioning the regulator from off to on when the corresponding pin control input(s) is/are active. The physical enable state of the regulator thus becomes the logical OR of the control register enable bit and any pin control inputs that have been masked for use.
The other 4 bits in the pin control register for a given regulator decide if the regulator should transition into high power mode (HPM) when the selected pin control input is asserted. Any combination of pin control inputs may be masked for use. The important use cases then become: OFF -> ON (HPM) and ON (LPM) -> ON (HPM). These correspond to PM8921_VREG_PIN_FN_ENABLE and PM8921_VREG_PIN_FN_MODE respectively in the header file.
Pin control is typically used by external chips (not the PMIC or the main CPU) that need to have some say in the state of a regulator. An example would be a wifi chip that can enable and disable the regulator powering its radio circuitry while the main processor is asleep. It would then wake the main processor up with an interrupt when new data was available to processor.
There are cases in which multiple consumer devices are supplied by one regulator where one consumer is controlled by a driver on the main processor and another consumer is an independent chip that utilizes pin control on the regulator. The first consumer would desire the regulator to be disabled during sleep because there is no way for it to respond to the device while asleep. However, the regulator would need to be configured for pin control to ensure that it is enabled when the second consumer expects it to be. It is also normal to mask off pin control if the second consumer is to be disabled.
The end result is that three quantities need to be controlled for the regulator which aren't entirely orthogonal: enable/disable, LPM/HPM, pin control ON/pin control OFF. (It would also be useful if the type of pin control (OFF/HPM or LPM/HPM) could be configured at runtime, but it is ok if it is statically configured via platform data.)
Do you know of a generic (or specific it is ok to do so) API that I can add to the regulator framework to support pin control?
Quoted 10 lines
Quoted 9 lines
Regulator registration needs to continue being based on which regulators are configured via the board file platform data because there will be need in our system in the near future to use a different (shared) regulator driver to access some of the same physical regulators.
We consider this to be the native PMIC 8921 regulator driver because it accesses the PMIC directly. There will be a subsequent PMIC 8921 regulator driver which issues requests to a separate processor which aggregates our requests with those of other SOC processors.
Quoted 6 lines
That's not an issue - the regulator API won't write to the regulators unless the machine driver explicitly tells it that this is OK so all that will happen is that we'll be able to read back the state of the regulators directly. If your driver is modifying the state of the regulators without the API telling it to then we should fix that as the no-write behaviour is an important safety feature.
The regulator probe function reads the regulator register values to figure out the initial hardware state. It also sets some regulator controls not handled by other regulator framework callback functions; e.g.: pull down enable. I'm not sure if this could be moved into an init_data regulator_init callback because that pointer would need to be specified in the board file where the function would be unknown.
Also, it would pollute the system with unusable devices if all natively controlled regulator devices were registered if the shared driver was being used for many regulators.
Quoted 9 lines
Quoted 5 lines
Quoted 2 lines
This needs locking if any registers are shared between multiple regulators.
There are no registers shared between multiple regulators. The mutex locks held inside of the regulator framework should be sufficient.
OK, a comment would help - this is a very common error in regulator drivers as many regulators put all the enable bits for the system in a single register.
I'll add a comment.
Quoted 27 lines
Quoted 12 lines
Quoted 11 lines
drivers/regulator/pm8921-regulator.c line 1024
Quoted 6 lines
drivers/regulator/pm8921-regulator.c new file +6
-0+/* Round down for set points in the gaps between bands. */ +if (uV >FTSMPS_BAND1_UV_MAX && uV <FTSMPS_BAND2_UV_MIN ) + uV =FTSMPS_BAND1_UV_MAX ; +else if (uV >FTSMPS_BAND2_UV_MAX + && uV <FTSMPS_BAND3_UV_SETPOINT_MIN ) + uV =FTSMPS_BAND2_UV_MAX ;That seems broken - it means you'll go under voltage on what was requested. You should ensure that you're always within the requested range so if the higher band minimum is in the range you should select that, otherwise you should error out.
Quoted 3 lines
This rounding is done to ensure that the calculations below always yield a register program voltage that is valid. I could change this to pick the minimum of the higher band instead.
Note the thing about rechecking against the bounds - you need to look at *both* limits.
Quoted 7 lines
In this example, consider the second condition which is checking for
min_uVin the range (1400000, 1500000). What should the correct result be if a consumer callsregulator_set_voltage(reg, 1450000, 1450000)(assuming that it is the only consumer so far and that the constraints step for the regulator allow the value)? As the driver is written, it would set the voltage to 1.4V. However, I think that 1.5V is more reasonable. Returning an error for this seems counter productive.
Quoted 11 lines
The driver should return an error. If the consumer wanted exactly 1.45V then that's what the system should deliver, if the consumer is happy with other voltages then it should say so. The specification by range is there because some consumers are sensitive to particular voltages and need to get what they asked for, or they may have much more flexibility in one direction or the other (like DVFS where it's usually no problem to be overvoltage but being undervoltage will usually fail). By allowing the consumer to specify a range we allow the consumer to control this, having the API or the drivers take guesses on behalf of the consumer means it's hard for a consumer driver to reliably interoperate with different regulators.
I guess I will change the set voltage callbacks so that they round up the vprog value:
vprog = (min_uV - band_min_uV + step_size - 1) / step_size
instead of
vprog = (min_uV - band_min_uV) / step_size
It will also check that the resulting output voltage is <= max_uV.
Quoted 3 lines
The API provides a mechanism for enumerating the set of supported voltages (which IIRC you're not implementing - you should) which consumers can use to ensure good interoperation.
I should be able to provide a list_voltage callback in the driver.
Quoted 5 lines
Quoted 4 lines
Quoted 4 lines
This function is just a switch statement per regulator, may aswell expan ithere. Or restructure things so that you've got a driver per regulator type - that would also mean you'd be able to get the device IDs to correspond to the regulator numbers which would probably be clearer.
Quoted 7 lines
Quoted 3 lines
I separated out the type specific init functions because they are relatively lengthy and independent. Wouldn't putting that code directly into a switch statement in the probe function be hard to follow?
Right, but the
_init()function is basically just a switch statement which calls these functions AFAIR - inlining the switch statement doesn't mean inlining the functions too.
I misunderstood before. I will move the switch statement.
- David
Signature · 2 lines
Sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
Re: [PATCH 1/2] regulator: pm8921-regulator: Add regulator driver for PM8921
Quoted 4 lines · David Collins
the device while asleep. However, the regulator would need to be configured for pin control to ensure that it is enabled when the second consumer expects it to be. It is also normal to mask off pin control if the second consumer is to be disabled.
This all seems fairly standard and like many other regulators except for the the masking off the pin control. The only unusual thing is that the hardware control is being managed by software at runtime, usually it's set up and then left alone by software.
The first thing I'm thinking here is that this maps fairly well onto a semi-virtual regulator where the operations map onto the control for the hardware mode. The enable/disable control via the pin is totally orthogonal to the control via the regular register interface, and it sounds like the mode control is too though that was less clear to me. Enabling would then translate into turning pin control on rather than actually enabling but that seems OK. Does that sound like it'd work?
Quoted 12 lines
Quoted 11 lines
Quoted 4 lines
We consider this to be the native PMIC 8921 regulator driver because it accesses the PMIC directly. There will be a subsequent PMIC 8921 regulator driver which issues requests to a separate processor which aggregates our requests with those of other SOC processors.
That's not an issue - the regulator API won't write to the regulators unless the machine driver explicitly tells it that this is OK so all that will happen is that we'll be able to read back the state of the regulators directly. If your driver is modifying the state of the regulators without the API telling it to then we should fix that as the no-write behaviour is an important safety feature.
Quoted 3 lines
The regulator probe function reads the regulator register values to figure out the initial hardware state. It also sets some regulator controls not handled by other regulator framework callback functions; e.g.: pull down
That just sounds like platform data which could just work in the same way as the regulator core - no platform data would mean nothing gets changed.
Quoted 3 lines
enable. I'm not sure if this could be moved into an
init_dataregulator_initcallback because that pointer would need to be specified in the board file where the function would be unknown.
I'm sorry, I don't understand what you're saying here. Could you clarify?
Quoted 3 lines
Also, it would pollute the system with unusable devices if all natively controlled regulator devices were registered if the shared driver was being used for many regulators.
Depends if you view it as pollution or not; also note that the devices aren't totally unusuable as you can still use them for readback.
Quoted 6 lines
I guess I will change the set voltage callbacks so that they round up the vprog value:
vprog = (min_uV-band_min_uV+step_size- 1) /step_size
instead of
vprog = (min_uV-band_min_uV) /step_size
It will also check that the resulting output voltage is <=max_uV.
That sounds right, yes.
Re: [PATCH 1/2] regulator: pm8921-regulator: Add regulator driver for PM8921
Quoted 5 lines · Mark Brown
This all seems fairly standard and like many other regulators except for the the masking off the pin control. The only unusual thing is that the hardware control is being managed by software at runtime, usually it's set up and then left alone by software.
Quoted 7 lines
The first thing I'm thinking here is that this maps fairly well onto a semi-virtual regulator where the operations map onto the control for the hardware mode. The enable/disable control via the pin is totally orthogonal to the control via the regular register interface, and it sounds like the mode control is too though that was less clear to me. Enabling would then translate into turning pin control on rather than actually enabling but that seems OK. Does that sound like it'd work?
So what you are suggesting is that two regulators are registered for a single physical regulator. The first operates normally with respect to enable, set mode, set voltage, etc. The second will be used exclusively for pin control in which regulator_enable and regulator_disable will map to enabling and disabling pin control. I suppose that this should be ok as long as it isn't confusing for consumers to utilize. However, I will definitely only register pin control regulators which are marked for use with pin control via some of the platform data values. Otherwise the number of regulators registered would double unnecessarily.
Also, while conceptually pin control should be independent of other regulator features, it becomes nonorthogonal in practice. For instance, some regulators have finer voltage stepping available in advanced operating mode, but pin control cannot be used in this advanced mode. The result is that set_voltage becomes tried to pin control for these regulators. The outcome is that the new pin control semi-virtual regulator would be tightly coupled to its real sibling regulator. Implementing it in this manner may get complicated.
I suppose there is also a question of what regulator_disable should mean in terms of outcome regulator state. Thus far, I have interpreted it to mean that the regulator is definitely turned off physically. As such, pin control must be disabled if it was previously enabled. Do you think this is the best approach to take, or should the concepts of regulator enable and regulator pin control enable be orthogonal?
Quoted 7 lines
Quoted 3 lines
The regulator probe function reads the regulator register values to figure out the initial hardware state. It also sets some regulator controls not handled by other regulator framework callback functions; e.g.: pull down
That just sounds like platform data which could just work in the same way as the regulator core - no platform data would mean nothing gets changed.
That is more or less how the patch already works. If platform data for a given regulator is not passed to the pm8921-core, then that regulator is never probed (via platform device) and the regulator_dev is not created for it (in the platform driver probe). The loop in pm8921_add_subdevices which adds the pm8921-regulator devices is important because it must iterate in topological order with respect to the regulator supply chain. This ordering is arbitrary and unknown to either the pm8921-core or the pm8921-regulator. If there is no strong requirement for this to change, I would prefer to keep it as is.
Quoted 6 lines
Quoted 3 lines
enable. I'm not sure if this could be moved into an
init_dataregulator_initcallback because that pointer would need to be specified in the board file where the function would be unknown.I'm sorry, I don't understand what you're saying here. Could you clarify?
struct regulator_init_data has a member: regulator_init. However, I don't think there is a good way to make use of it for this system because that function pointer must be specified statically in a board file, but the regulator register init function is private to the pm8921-regulator driver.
Quoted 6 lines
Quoted 3 lines
Also, it would pollute the system with unusable devices if all natively controlled regulator devices were registered if the shared driver was being used for many regulators.
Depends if you view it as pollution or not; also note that the devices aren't totally unusuable as you can still use them for readback.
They wouldn't be useful for readback either because register values are only read during initialization. The remainder of the regulator usage is write-only. This works under the assumption that PMIC registers will not be modified by any other writers. This assumption is true except in the case of a regulator managed via the shared interface.
- David
Signature · 2 lines
Sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
Re: [PATCH 1/2] regulator: pm8921-regulator: Add regulator driver for PM8921
Quoted 4 lines · David Collins
as long as it isn't confusing for consumers to utilize. However, I will definitely only register pin control regulators which are marked for use with pin control via some of the platform data values. Otherwise the number of regulators registered would double unnecessarily.
That's what I'd expect - in a very real sense the extra regulators don't exist unless a pin is assigned to them.
Quoted 8 lines
Also, while conceptually pin control should be independent of other regulator features, it becomes nonorthogonal in practice. For instance, some regulators have finer voltage stepping available in advanced operating mode, but pin control cannot be used in this advanced mode. The result is that
set_voltagebecomes tried to pin control for these regulators. The outcome is that the new pin control semi-virtual regulator would be tightly coupled to its real sibling regulator. Implementing it in this manner may get complicated.
The pin and non-pin control are tied together anyway.
Quoted 6 lines
I suppose there is also a question of what
regulator_disableshould mean in terms of outcome regulator state. Thus far, I have interpreted it to mean that the regulator is definitely turned off physically. As such, pin control must be disabled if it was previously enabled. Do you think this is the best approach to take, or should the concepts of regulator enable and regulator pin control enable be orthogonal?
I'd keep them orthogonal - regulator_disable() doesn't mean disable the regulator, it means that the consumer no longer requires that the regulator be enabled. Constraints or other consumers may still keep it enabled. Ensuring that the consumer can actually power the regulator off is a system design issue that'd apply either way.
Quoted 4 lines
Quoted 3 lines
That just sounds like platform data which could just work in the same way as the regulator core - no platform data would mean nothing gets changed.
Quoted 9 lines
That is more or less how the patch already works. If platform data for a given regulator is not passed to the pm8921-core, then that regulator is never probed (via platform device) and the
regulator_devis not created for it (in the platform driver probe). The loop inpm8921_add_subdeviceswhich adds the pm8921-regulator devices is important because it must iterate in topological order with respect to the regulator supply chain. This ordering is arbitrary and unknown to either the pm8921-core or the pm8921-regulator. If there is no strong requirement for this to change, I would prefer to keep it as is.
It does correlate with drivers that feel fragile, usually to do with neither the MFD core nor the regulator driver being sure quite which regulators actually exist.
Quoted 11 lines
Quoted 6 lines
Quoted 3 lines
enable. I'm not sure if this could be moved into an
init_dataregulator_initcallback because that pointer would need to be specified in the board file where the function would be unknown.I'm sorry, I don't understand what you're saying here. Could you clarify?
struct
regulator_init_datahas a member:regulator_init. However, I don't think there is a good way to make use of it for this system because that function pointer must be specified statically in a board file, but the regulator register init function is private to the pm8921-regulator driver.
I don't follow how this is connected to the above - why would one wish to configure this with a callback rather than data?
Quoted 8 lines
Quoted 2 lines
Depends if you view it as pollution or not; also note that the devices aren't totally unusuable as you can still use them for readback.
They wouldn't be useful for readback either because register values are only read during initialization. The remainder of the regulator usage is write-only. This works under the assumption that PMIC registers will not be modified by any other writers. This assumption is true except in the case of a regulator managed via the shared interface.
Is this enforced in hardware?
PATCH 2/2 msm: board-8960: Add support for pm8921-regulator
In reply to David CollinsAdd board-msm8960-regulator.c to contain pm8921-regulator structure declarations. NULL consumer names in the regulator_consumer_supply lists are used for debugging and as place holders. They will eventually be changed to use more appropriate debug device names. The primary configuration table msm_pm8921_regulator_pdata specifies the following characteristics for each regulator: if it is always on, if it should have its pull down set when disabled, its min and max voltage constraints, its supply regulator, and its pin control pins.
--- arch/arm/mach-msm/Makefile | 1 + arch/arm/mach-msm/board-msm8960-regulator.c | 303 +++++++++++++++++++++++++++ arch/arm/mach-msm/board-msm8960.c | 6 + arch/arm/mach-msm/board-msm8960.h | 23 ++ 4 files changed, 333 insertions(+), 0 deletions(-) create mode 100644 arch/arm/mach-msm/board-msm8960-regulator.c create mode 100644 arch/arm/mach-msm/board-msm8960.h
arch/arm/mach-msm/Makefile +1 -0
@@ -26,6 +26,7 @@ obj-$(CONFIG_ARCH_MSM7X30) += board-msm7x30.o devices-msm7x30.o obj-$(CONFIG_ARCH_QSD8X50) += board-qsd8x50.o devices-qsd8x50.o obj-$(CONFIG_ARCH_MSM8X60) += board-msm8x60.o obj-$(CONFIG_ARCH_MSM8960) += board-msm8960.o devices-msm8960.o +obj-$(CONFIG_ARCH_MSM8960) += board-msm8960-regulator.o obj-$(CONFIG_ARCH_MSM7X30) += gpiomux-v1.o gpiomux.o obj-$(CONFIG_ARCH_QSD8X50) += gpiomux-v1.o gpiomux.o
arch/arm/mach-msm/board-msm8960-regulator.c new file +303 -0
303 lines not on this page · raw message
arch/arm/mach-msm/board-msm8960.c +6 -0
@@ -27,6 +27,7 @@#include <mach/irqs.h> #include "devices.h" +#include "board-msm8960.h" /* Macros assume PMIC GPIOs and MPPs start at 1 */ #define PM8921_GPIO_BASE NR_GPIO_IRQS
@@ -91,6 +92,7 @@ static struct pm8921_platform_data pm8921_platform_data __devinitdata = { .irq_pdata = &pm8xxx_irq_pdata, .gpio_pdata = &pm8xxx_gpio_pdata, .mpp_pdata = &pm8xxx_mpp_pdata, + .regulator_pdatas = msm_pm8921_regulator_pdata, };static struct msm_ssbi_platform_data msm8960_ssbi_pm8921_pdata__initdata = {
@@ -107,6 +109,8 @@ static void __init msm8960_sim_init(void) msm8960_device_ssbi_pm8921.dev.platform_data = &msm8960_ssbi_pm8921_pdata; + pm8921_platform_data.num_regulators = msm_pm8921_regulator_pdata_len; +platform_add_devices (sim_devices,ARRAY_SIZE (sim_devices)); }
@@ -116,6 +120,8 @@ static void __init msm8960_rumi3_init(void) msm8960_device_ssbi_pm8921.dev.platform_data = &msm8960_ssbi_pm8921_pdata; + pm8921_platform_data.num_regulators = msm_pm8921_regulator_pdata_len; +platform_add_devices (rumi3_devices,ARRAY_SIZE (rumi3_devices)); }
arch/arm/mach-msm/board-msm8960.h new file +23 -0
@@ -0,0 +1,23 @@ +/* Copyright (c) 2011, Code Aurora Forum. All rights reserved. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 and +* only version 2 as published by the Free Software Foundation. +* +* This program is distributed in the hope that 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. +*/ + +#ifndef __ARCH_ARM_MACH_MSM_BOARD_MSM8960_H +#define __ARCH_ARM_MACH_MSM_BOARD_MSM8960_H + +#include <linux/mfd/pm8xxx/pm8921.h> + +extern struct pm8921_regulator_platform_data + msm_pm8921_regulator_pdata[]__devinitdata ; + +extern int msm_pm8921_regulator_pdata_len__devinitdata ; + +#endif
Signature · 2 lines
Sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
Re: [PATCH 2/2] msm: board-8960: Add support for pm8921-regulator
arch/arm/mach-msm/board-msm8960-regulator.c line 28
Quoted 3 lines · David Collins
arch/arm/mach-msm/board-msm8960-regulator.c new file +3
-0+VREG_CONSUMERS (L1 ) = { +REGULATOR_SUPPLY ("8921_l1" ,NULL ), +};
All these supplies named after the regulator name should be removed. Supplies define the mapping from the regulators on the board to the supplies on the devices on the board, if any driver is requesting a specific regulator name then there's an abstraction issue which means that these should be redundant.
In general if you've got a supply that doesn't have a dev_name associated with it something is wrong.
v2 cover regulator: msm: Add PM8921 regulator driver
In reply to David CollinsThis patch set adds a new regulator driver to control the regulators in Qualcomm PM8921 PMIC chips. It also introduces board file changes to use this new driver with the Qualcomm MSM 8960 platform.
This patch set depends upon the following outstanding PM8XXX and PM8921 patches:
https://patchwork.kernel.org/patch/688832/
https://patchwork.kernel.org/patch/688882/
https://patchwork.kernel.org/patch/735362/
https://patchwork.kernel.org/patch/735372/
https://patchwork.kernel.org/patch/688842/
Updates from V1:
Major modifications were made based on Mark Brown's suggestions.
Major changes:
1. A set of semi-virtual regulators were added to support pin-control.
2. The set_mode callbacks were modified so that they act normal and do not control pin-control.
3. Changed set_voltage callbacks to round up min_uV to the next available set point and to bail out if that set point is greater than max_uV.
4. Added list_voltage callbacks.
5. Enable and disable callbacks were separated out per regualtor type to handle differing requirements for pin controllable regulators.
Minor changes:
1. Moved kfree of regulator mfd_cells to the PMIC core remove function.
2. Simplified handling of unknown voltages in regulators in which enable state and output voltage are set using the same bits.
3. Made symbol names more consistent.
4. Modified how overlapping voltage ranges are handled to ensure most efficient operation.
5. Corrected names used for PMIC 8921 pin control inputs.
6. Removed unused member: struct pm8921_vreg.state
7. Renamed pm8921_vreg_write to pm8921_vreg_masked_write to better illustrate its functionality.
8. Added pm8921_vreg_masked_write_forced to handle registers that must be overwritten even if their value is unchanged in order for hardware to change state.
9. Mutex locking was added for all callback functions which touch pin controllable regulators because the regulator framework will have no way of knowing that two separate regualtor_dev's modify the same physical regulators.
10. Debug/error messages were moved so that they do not span multiple lines.
11. pm8921_init_regulator was removed and the switch statement in it was moved
into pm8921_vreg_probe.
12. pm8921_vreg_init was changed from module_init to subsys_init.
13. Comments were added describing the enums and structs in pm8921-regulator.h.
14. system_uA platform data was added to quantify the max current draw intrinsic to a system that is not associated with any consumer.
15. Changed NULL to "reg-debug-consumer" in the board file.
16. Remove pin-control column in board file for normal regulator constraints.
David Collins (2):
regulator: pm8921-regulator: Add regulator driver for PM8921
msm: board-8960: Add support for pm8921-regulator
arch/arm/mach-msm/Makefile | 1 + arch/arm/mach-msm/board-msm8960-regulator.c | 306 +++ arch/arm/mach-msm/board-msm8960.c | 4 + arch/arm/mach-msm/board-msm8960.h | 23 + drivers/mfd/pm8921-core.c | 34 + drivers/regulator/Kconfig | 10 + drivers/regulator/Makefile | 1 + drivers/regulator/pm8921-regulator.c | 3025 +++++++++++++++++++++++++++ include/linux/mfd/pm8xxx/pm8921.h | 3 + include/linux/regulator/pm8921-regulator.h | 155 ++ 10 files changed, 3562 insertions(+), 0 deletions(-) create mode 100644 arch/arm/mach-msm/board-msm8960-regulator.c create mode 100644 arch/arm/mach-msm/board-msm8960.h create mode 100644 drivers/regulator/pm8921-regulator.c create mode 100644 include/linux/regulator/pm8921-regulator.h
Signature · 2 lines
Sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
PATCH v2 1/2 regulator: pm8921-regulator: Add regulator driver for PM8921
Create a regulator driver to control all regulators on a Qualcomm PM8921 PMIC chip. This chip contains many different types of regulators with a wide range of abilities and voltage ranges.
Eight different regulator types are available on the PM8921. These are managed via 7 different type values in the driver:
LDO - low drop out regulator (supports both NMOS and PMOS LDOs)
NLDO1200 - 1.2A NMOS LDO (different control structure than other LDOs)
SMPS - switched-mode power supply FTSMPS - fast transient SMPS VS - voltage switch VS300 - 300mA voltage switch (different control structure than
other switches)
NCP - negative charge pump
The driver interfaces with the PMIC using Qualcomm's SSBI bus. Calls to this bus are abstracted through the pm8xxx_readb/writeb API.
Pin control of the regulators which support it (LDO, SMPS, VS) is provided via a secondary set of semi-virtual regulator devices. These use the enable and disable callbacks to enable and disable pin control of their associated regulator.
--- drivers/mfd/pm8921-core.c | 34 + drivers/regulator/Kconfig | 10 + drivers/regulator/Makefile | 1 + drivers/regulator/pm8921-regulator.c | 3025 ++++++++++++++++++++++++++++ include/linux/mfd/pm8xxx/pm8921.h | 3 + include/linux/regulator/pm8921-regulator.h | 155 ++ 6 files changed, 3228 insertions(+), 0 deletions(-) create mode 100644 drivers/regulator/pm8921-regulator.c create mode 100644 include/linux/regulator/pm8921-regulator.h
drivers/mfd/pm8921-core.c +34 -0
@@ -30,6 +30,7 @@struct pm8921 {struct device *dev;struct pm_irq_chip *irq_chip; +struct mfd_cell *mfd_regulators; };static int pm8921_readb (const struct device *dev,u16 addr,u8 *val)
@@ -121,6 +122,8 @@ static int __devinit pm8921_add_subdevices(const struct pm8921_platform_data {int ret =0 , irq_base =0 ;struct pm_irq_chip *irq_chip; +static struct mfd_cell *mfd_regulators; +int i;if (pdata->irq_pdata) { pdata->irq_pdata->irq_cdata.nirqs =PM8921_NR_IRQS ;
@@ -160,6 +163,36 @@ static int __devinit pm8921_add_subdevices(const struct pm8921_platform_data } } +/* Add one device for each regulator used by the board. */ +if (pdata->num_regulators >0 && pdata->regulator_pdatas) { + mfd_regulators =kzalloc (sizeof (struct mfd_cell ) + * (pdata->num_regulators),GFP_KERNEL ); +if (!mfd_regulators) { +pr_err ("Cannot allocate %d bytes for pm8921 regulator " +"mfd cells\n" ,sizeof (struct mfd_cell ) + * (pdata->num_regulators)); + ret = -ENOMEM ; + goto bail; + } +for (i =0 ; i < pdata->num_regulators; i++) { + mfd_regulators[i].name =PM8921_REGULATOR_DEV_NAME ; + mfd_regulators[i].id = pdata->regulator_pdatas[i].id; + mfd_regulators[i].platform_data = + &(pdata->regulator_pdatas[i]); + mfd_regulators[i].pdata_size = +sizeof (struct pm8921_regulator_platform_data ); + } + ret =mfd_add_devices (pmic->dev,0 , mfd_regulators, + pdata->num_regulators,NULL , irq_base); +if (ret) { +pr_err ("Failed to add regulator subdevices ret=%d\n" , + ret); +kfree (mfd_regulators); + goto bail; + } + pmic->mfd_regulators = mfd_regulators; + } +return 0 ; bail:if (pmic->irq_chip) {
@@ -245,6 +278,7 @@ static int __devexit pm8921_remove(struct platform_device *pdev) pmic->irq_chip =NULL ; }platform_set_drvdata (pdev,NULL ); +kfree (pmic->mfd_regulators);kfree (pmic);return 0 ;
drivers/regulator/Kconfig +10 -0
@@ -290,5 +290,15 @@ config REGULATOR_TPS6524X serial interface currently supported on the sequencer serial port controller. +config REGULATOR_PM8921 + tristate "Qualcomm PM8921 PMIC Power regulators" + depends on MFD_PM8921_CORE + default y if MFD_PM8921_CORE + help + This driver supports voltage regulators in the Qualcomm PM8921 PMIC + chip. The PM8921 provides several different varieties of LDO and + switching regulators. It also provides a negative charge pump and + voltage switches. + endif
drivers/regulator/Makefile +1 -0
@@ -41,5 +41,6 @@ obj-$(CONFIG_REGULATOR_TPS6524X) += tps6524x-regulator.o obj-$(CONFIG_REGULATOR_88PM8607) += 88pm8607.o obj-$(CONFIG_REGULATOR_ISL6271A) += isl6271a-regulator.o obj-$(CONFIG_REGULATOR_AB8500) += ab8500.o +obj-$(CONFIG_REGULATOR_PM8921) += pm8921-regulator.o ccflags-$(CONFIG_REGULATOR_DEBUG) += -DDEBUG
drivers/regulator/pm8921-regulator.c new file +3025 -0
2,921 lines not on this page · raw message
include/linux/regulator/pm8921-regulator.h new file +155 -0
155 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 2 lines
Sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
Part of the diff is not shown here. View the raw message.
PATCH v2 2/2 msm: board-8960: Add support for pm8921-regulator
In reply to David CollinsAdd board-msm8960-regulator.c to contain pm8921-regulator structure declarations. The primary configuration table msm_pm8921_regulator_pdata specifies the following characteristics for each regulator: if it is always on, if it should have its pull down set when disabled, its min and max voltage constraints, and its supply regulator.
--- arch/arm/mach-msm/Makefile | 1 + arch/arm/mach-msm/board-msm8960-regulator.c | 306 +++++++++++++++++++++++++++ arch/arm/mach-msm/board-msm8960.c | 4 + arch/arm/mach-msm/board-msm8960.h | 23 ++ 4 files changed, 334 insertions(+), 0 deletions(-) create mode 100644 arch/arm/mach-msm/board-msm8960-regulator.c create mode 100644 arch/arm/mach-msm/board-msm8960.h
arch/arm/mach-msm/Makefile +1 -0
@@ -28,6 +28,7 @@ obj-$(CONFIG_ARCH_MSM7X30) += board-msm7x30.o devices-msm7x30.o obj-$(CONFIG_ARCH_QSD8X50) += board-qsd8x50.o devices-qsd8x50.o obj-$(CONFIG_ARCH_MSM8X60) += board-msm8x60.o devices-msm8x60.o obj-$(CONFIG_ARCH_MSM8960) += board-msm8960.o devices-msm8960.o +obj-$(CONFIG_ARCH_MSM8960) += board-msm8960-regulator.o obj-$(CONFIG_ARCH_MSM7X30) += gpiomux-v1.o gpiomux.o obj-$(CONFIG_ARCH_QSD8X50) += gpiomux-8x50.o gpiomux-v1.o gpiomux.o
arch/arm/mach-msm/board-msm8960-regulator.c new file +306 -0
306 lines not on this page · raw message
arch/arm/mach-msm/board-msm8960.c +4 -0
@@ -34,6 +34,7 @@#include "devices.h" #include "gpiomux.h" +#include "board-msm8960.h" struct msm_gpiomux_config msm_gpiomux_configs[GPIOMUX_NGPIOS ] = {};/* Macros assume PMIC GPIOs and MPPs start at 1 */
@@ -102,6 +103,7 @@ static struct pm8921_platform_data pm8921_platform_data __devinitdata = { .irq_pdata = &pm8xxx_irq_pdata, .gpio_pdata = &pm8xxx_gpio_pdata, .mpp_pdata = &pm8xxx_mpp_pdata, + .regulator_pdatas = msm_pm8921_regulator_pdata, };static struct platform_device *devices[]__initdata = {
@@ -122,6 +124,8 @@ static void __init msm8960_init(void) msm8960_device_ssbi_pm8921.dev.platform_data = &msm8960_ssbi_pm8921_pdata; + pm8921_platform_data.num_regulators = msm_pm8921_regulator_pdata_len; +platform_add_devices (devices,ARRAY_SIZE (devices)); }
arch/arm/mach-msm/board-msm8960.h new file +23 -0
@@ -0,0 +1,23 @@ +/* Copyright (c) 2011, Code Aurora Forum. All rights reserved. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 and +* only version 2 as published by the Free Software Foundation. +* +* This program is distributed in the hope that 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. +*/ + +#ifndef __ARCH_ARM_MACH_MSM_BOARD_MSM8960_H +#define __ARCH_ARM_MACH_MSM_BOARD_MSM8960_H + +#include <linux/mfd/pm8xxx/pm8921.h> + +extern struct pm8921_regulator_platform_data + msm_pm8921_regulator_pdata[]__devinitdata ; + +extern int msm_pm8921_regulator_pdata_len__devinitdata ; + +#endif
Signature · 2 lines
Sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
Re: [PATCH v2 2/2] msm: board-8960: Add support for pm8921-regulator
arch/arm/mach-msm/board-msm8960-regulator.c line 28
Quoted 3 lines · David Collins
arch/arm/mach-msm/board-msm8960-regulator.c new file +3
-0+PM8921_VREG_CONSUMERS (L1 ) = { +REGULATOR_SUPPLY ("8921_l1" ,"reg-debug-consumer" ), +};
Uh, no. There's no such thing in mainline and having such a thing enabled in production builds is crazy. If such a thing *did* exist it should still be doing the same thing everything else does and requesting a fixed supply name.
Quoted 3 lines · David Collins
This patch set adds a new regulator driver to control the regulators in Qualcomm PM8921 PMIC chips. It also introduces board file changes to use this new driver with the Qualcomm MSM 8960 platform.
Please don't send patches as followups to old threads, this makes them hard to find in mail archives.