regulator: msm: Add PM8921 regulator driver
Subsystems (5)
v2 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/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 1/2] regulator: pm8921-regulator: Add regulator driver for PM8921
In reply to David CollinsQuoted 3 lines · David Collins
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.
This is basically OK but a few comments below.
Quoted 11 lines
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 thanother switches)
NCP - negative charge pump
Given that I'm not seeing much code sharing except is_enabled() it might be nice to split the driver up by regulator, it's very large.
drivers/mfd/pm8921-core.c static int __devinit pm8921_add_subdevices(const struct pm8921_platform_data · line 186
Quoted 10 lines
drivers/mfd/pm8921-core.c +10
-0+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);
I'm having a hard time liking this.
drivers/regulator/pm8921-regulator.c line 562
Quoted 12 lines
drivers/regulator/pm8921-regulator.c new file +12
-0+static int pm8921_vreg_masked_write (struct pm8921_vreg *vreg,u16 addr,u8 val, +u8 mask,u8 *reg_save) +{ +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);
dev_err or one of your custom error macros.
drivers/regulator/pm8921-regulator.c line 639
Quoted 9 lines
drivers/regulator/pm8921-regulator.c new file +9
-0+static int _pm8921_vreg_is_enabled (struct pm8921_vreg *vreg) +{ +int rc =0 ; + +/* +* All regulator types except advanced mode SMPS, FTSMPS, and VS300 have +* enable bit in bit 7 of the control register. +*/ +switch (vreg->type) {
If they're all checking bit 7 the switch statement feels a bit odd...
drivers/regulator/pm8921-regulator.c line 867
Quoted 5 lines
drivers/regulator/pm8921-regulator.c new file +5
-0+static int pm8921_nldo_list_voltage (struct regulator_dev *rdev, +unsigned selector) +{ +if (selector >=NLDO_SET_POINTS ) +return 0 ;
That looks like it should be returning an error. 0 is for things that are in range but can't be set for some reason (it's more intended for values knocked out by constraints or similar).
Quoted 8 lines
drivers/regulator/pm8921-regulator.c new file +8
-0+static int _pm8921_nldo1200_get_voltage (struct pm8921_vreg *vreg) +{ +int uV =0 ; +int vprog; + +if (!NLDO1200_IN_ADVANCED_MODE (vreg)) { +pr_warn ("%s: currently in legacy mode; voltage unknown.\n" , + vreg->name);
drivers/regulator/pm8921-regulator.c line 955
Quoted 10 lines
drivers/regulator/pm8921-regulator.c new file +10
-0+return vreg->save_uV; + } + + vprog = vreg->ctrl_reg &NLDO1200_CTRL_VPROG_MASK ; + +if ((vreg->ctrl_reg &NLDO1200_CTRL_RANGE_MASK ) + ==NLDO1200_CTRL_RANGE_LOW ) + uV = vprog *NLDO1200_LOW_UV_STEP +NLDO1200_LOW_UV_MIN ; +else + uV = vprog *NLDO1200_HIGH_UV_STEP +NLDO1200_HIGH_UV_MIN ;
Just implement get_voltage_sel() - the same thing applies to most of the other regulators that have meaningful selectors.
drivers/regulator/pm8921-regulator.c line 1577
Quoted 3 lines
drivers/regulator/pm8921-regulator.c new file +3
-0+/* Advanced mode */ +if ((vreg->test_reg[2 ] &NLDO1200_ADVANCED_PM_MASK ) + ==NLDO1200_ADVANCED_PM_LPM )
Do we need #defines for the indexes into these arrays? It's a bit magic and the code is complicated enough.
drivers/regulator/pm8921-regulator.c line 1533
Quoted 4 lines
drivers/regulator/pm8921-regulator.c new file +4
-0+if (mode !=REGULATOR_MODE_NORMAL && mode !=REGULATOR_MODE_IDLE ) { +vreg_err (vreg,"invalid mode: %u\n" , mode); +return -EINVAL ; + }
switch would be clearer.
Quoted 10 lines
+/**
+ * structpm8921_regulator_platform_data- PMIC 8921 regulator platform data
+ * @init_data: regulator constraints
+ * @id: regulator id; from enumpm8921_vreg_id
+ * @pull_down_enable: 0 = no pulldown, 1 = pulldown when regulator disabled
+ * @pin_ctrl: pin control inputs to use for the regulator; should be
+ * a combination of PM8921_VREG_PIN_CTRL_* values
+ * @pin_fn: action to perform when pin control pin is active
+ * @system_uA: current drawn from regulator not accounted for by any
+ * regulator framework consumer
Having system_uA here seems wrong, this is hardly something that is specific to this chip.