regulator: Add helper function to get "poweroff-source" property
Subsystems (3)
RFC PATCH 1/4 regulator: Add helper function to get "poweroff-source" property
Several drivers create their own devicetree property when they register poweroff capabilites. This is for example the case for mfd, regulator or power drivers which define "vendor,system-power-controller" property. This patch adds support for a standard property "poweroff-source" which marks the device as able to shutdown the system.
--- drivers/regulator/of_regulator.c | 12 ++++++++++++ include/linux/regulator/of_regulator.h | 6 ++++++ 2 files changed, 18 insertions(+)
drivers/regulator/of_regulator.c +12 -0
@@ -240,3 +240,15 @@ struct regulator_init_data *regulator_of_get_init_data(struct device *dev,return init_data; } + +/** +* of_get_regulator_poweroff_source - Get poweroff-source for given device_node +* @np: Pointer to the given device_node +* +* return true if present false otherwise +*/ +bool of_get_regulator_poweroff_source (const struct device_node *np) +{ +return of_property_read_bool (np,"poweroff-source" ); +} +EXPORT_SYMBOL_GPL (of_get_regulator_poweroff_source);
include/linux/regulator/of_regulator.h +6 -0
@@ -20,6 +20,7 @@ extern struct regulator_init_dataextern int of_regulator_match (struct device *dev,struct device_node *node,struct of_regulator_match *matches,unsigned int num_matches); +extern bool of_get_regulator_poweroff_source (const struct device_node *np);#else static inline struct regulator_init_data *of_get_regulator_init_data(struct device *dev,
@@ -35,6 +36,11 @@ static inline int of_regulator_match(struct device *dev, {return 0 ; } + +static inline bool of_get_regulator_poweroff_source (const struct device_node *np) +{ +return false; +}#endif /* CONFIG_OF */ #endif /* __LINUX_OF_REG_H */
Signature · 1 line
1.9.1
RFC PATCH 3/4 ARM: dts: rockchip: Enable power off in pmic for Radxa Rock
Add "poweroff-source" property to act8846 node. shutdown/poweroff commands are now handled for this board.
--- arch/arm/boot/dts/rk3188-radxarock.dts | 2 ++ 1 file changed, 2 insertions(+)
arch/arm/boot/dts/rk3188-radxarock.dts +2 -0
@@ -115,6 +115,8 @@ pinctrl-names = "default"; pinctrl-0 = <&act8846_dvs0_ctl>; + poweroff-source; + regulators { vcc_ddr: REG1 { regulator-name = "VCC_DDR";
Signature · 1 line
1.9.1
RFC PATCH 2/4 regulator: act8865: Add support to turn off all outputs
In reply to Romain PerierWhen the property "poweroff-source" is found in the devicetree, the function pm_power_off is defined. This function sends the rights bit fields to the global off control register. shutdown/poweroff commands are now supported for hardware components which use these PMU.
--- drivers/regulator/act8865-regulator.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
drivers/regulator/act8865-regulator.c +28 -0
@@ -61,6 +61,8 @@#define ACT8846_REG12_VSET 0xa0#define ACT8846_REG12_CTRL 0xa1#define ACT8846_REG13_CTRL 0xb1 +#define ACT8846_GLB_OFF_CTRL 0xc3 +#define ACT8846_OFF_SYSMASK 0x18/* * ACT8865 Global Register Map.
@@ -84,6 +86,7 @@#define ACT8865_LDO3_CTRL 0x61#define ACT8865_LDO4_VSET 0x64#define ACT8865_LDO4_CTRL 0x65 +#define ACT8865_MSTROFF 0x20/* * Field Definitions.
@@ -98,6 +101,8 @@struct act8865 {struct regmap *regmap; +int off_reg; +int off_mask; };static const struct regmap_config act8865_regmap_config = {
@@ -275,6 +280,16 @@ static struct regulator_init_datareturn NULL ; } +static struct i2c_client *act8865_i2c_client; +static void act8865_power_off (void ) +{ +struct act8865 *act8865; + + act8865 =i2c_get_clientdata (act8865_i2c_client); +regmap_write (act8865->regmap, act8865->off_reg, act8865->off_mask); +while (1 ); +} +static int act8865_pmic_probe (struct i2c_client *client,const struct i2c_device_id *i2c_id) {
@@ -285,6 +300,7 @@ static int act8865_pmic_probe(struct i2c_client *client,int i, ret, num_regulators;struct act8865 *act8865;unsigned long type; +int off_reg, off_mask; pdata =dev_get_platdata (dev);
@@ -304,10 +320,14 @@ static int act8865_pmic_probe(struct i2c_client *client,case ACT8846 : regulators = act8846_regulators; num_regulators =ARRAY_SIZE (act8846_regulators); + off_reg =ACT8846_GLB_OFF_CTRL ; + off_mask =ACT8846_OFF_SYSMASK ;break ;case ACT8865 : regulators = act8865_regulators; num_regulators =ARRAY_SIZE (act8865_regulators); + off_reg =ACT8865_SYS_CTRL ; + off_mask =ACT8865_MSTROFF ;break ;default :dev_err (dev,"invalid device id %lu\n" , type);
@@ -345,6 +365,14 @@ static int act8865_pmic_probe(struct i2c_client *client,return ret; } +if (dev->of_node &&of_get_regulator_poweroff_source (dev->of_node) && + !pm_power_off) { + act8865_i2c_client = client; + act8865->off_reg = off_reg; + act8865->off_mask = off_mask; + pm_power_off = act8865_power_off; + } +/* Finally register devices */ for (i =0 ; i < num_regulators; i++) {const struct regulator_desc *desc = ®ulators[i];
Signature · 1 line
1.9.1
RFC PATCH 4/4 dt-bindings: Document the property poweroff-source for act8865 regulator
In reply to Romain Perier--- Documentation/devicetree/bindings/regulator/act8865-regulator.txt | 4 ++++ 1 file changed, 4 insertions(+)
Documentation/devicetree/bindings/regulator/act8865-regulator.txt +4 -0
@@ -5,6 +5,10 @@ Required properties: - compatible: "active-semi,act8846" or "active-semi,act8865" - reg: I2C slave address +Optional properties: +- poweroff-source: Telling whether or not this pmic is controlling + the system power + Any standard regulator properties can be used to configure the single regulator. The valid names for regulators are:
Signature · 1 line
1.9.1
Mark Brown
maintainerdrivers/regulator/of_regulator.c struct regulator_init_data *regulator_of_get_init_data(struct device *dev, · line 254
Quoted 11 lines · Romain Perier
drivers/regulator/of_regulator.c +11
-0+/** +* of_get_regulator_poweroff_source - Get poweroff-source for given device_node +* @np: Pointer to the given device_node +* +* return true if present false otherwise +*/ +bool of_get_regulator_poweroff_source (const struct device_node *np) +{ +return of_property_read_bool (np,"poweroff-source" ); +} +EXPORT_SYMBOL_GPL (of_get_regulator_poweroff_source);
This isn't really a regulator specific thing - it's common for the actual implementation to be to simply cut power but it could be something that doesn't look like a regulator doing it like a system monitor. I'd rename this to something like is_system_poweroff_source().
You probably also want to CC the DT maintainers on this and add some documentation of this as a standard property, not entirely sure where exactly but I'm sure the DT people could advise.
Adding the corresponding drivers and DT maintainers to the loop (parts of the kernel which use this property)
Quoted 21 lines · Mark Brown
drivers/regulator/of_regulator.c struct regulator_init_data *regulator_of_get_init_data(struct device *dev, · line 254
Quoted 11 lines · Romain Perier
drivers/regulator/of_regulator.c +11
-0+/** +* of_get_regulator_poweroff_source - Get poweroff-source for given device_node +* @np: Pointer to the given device_node +* +* return true if present false otherwise +*/ +bool of_get_regulator_poweroff_source (const struct device_node *np) +{ +return of_property_read_bool (np,"poweroff-source" ); +} +EXPORT_SYMBOL_GPL (of_get_regulator_poweroff_source);This isn't really a regulator specific thing - it's common for the actual implementation to be to simply cut power but it could be something that doesn't look like a regulator doing it like a system monitor. I'd rename this to something like
is_system_poweroff_source().You probably also want to CC the DT maintainers on this and add some documentation of this as a standard property, not entirely sure where exactly but I'm sure the DT people could advise.