dd regulator support for pmbus and ltc2978
v2 cover dd regulator support for pmbus and ltc2978
From: Alan Tull <[email protected]>
Version 2 :
* Get regulator_init_data from platform data or device tree.
* One regulator per pmbus part.
* Clean up Kconfig and #includes.
This set of patches adds regulator support to pmbus_core.c and to ltc2978.c. Other pmbus parts can use this to add their own regulator support. Current ltc2978 support is limited to enable/disable.
Tested on ltc2978. Looking at the datasheets for the other parts supported by ltc2978.c, it looks like it should work.
Thanks,
Alan
Alan Tull (2):
pmbus: add regulator support
pmbus: ltc2978: add regulator gating
drivers/hwmon/pmbus/Kconfig | 7 +++++ drivers/hwmon/pmbus/ltc2978.c | 60 ++++++++++++++++++++++++++++++++++++++ drivers/hwmon/pmbus/pmbus.h | 5 ++++ drivers/hwmon/pmbus/pmbus_core.c | 51 ++++++++++++++++++++++++++++++++ include/linux/i2c/pmbus.h | 1 + 5 files changed, 124 insertions(+)
Signature · 7 lines
1.7.9.5 _______________________________________________ lm-sensors mailing list [email protected] http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
PATCH v2 1/2 pmbus: add regulator support
From: Alan Tull <[email protected]>
To add a regulator, the pmbus device driver needs to add regulator_desc information to its pmbus_driver_info struct. The regulator_init_data can be intialized from either platform data or the device tree.
v2: Remove '#include <linux/regulator/machine.h>'
Only one regulator per pmbus device
Get regulator_init_data from pdata or device tree
--- drivers/hwmon/pmbus/pmbus.h | 5 ++++ drivers/hwmon/pmbus/pmbus_core.c | 51 ++++++++++++++++++++++++++++++++++++++ include/linux/i2c/pmbus.h | 1 + 3 files changed, 57 insertions(+)
drivers/hwmon/pmbus/pmbus.h +5 -0
@@ -19,6 +19,8 @@* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#include <linux/regulator/driver.h> +#ifndef PMBUS_H #define PMBUS_H
@@ -365,6 +367,9 @@ struct pmbus_driver_info {*/ int (*identify)(struct i2c_client *client,struct pmbus_driver_info *info); + +/* Regulator functionality, if supported by this chip driver. */ +const struct regulator_desc *reg_desc; };/* Function declarations */
drivers/hwmon/pmbus/pmbus_core.c +51 -0
71 lines not on this page · raw message
include/linux/i2c/pmbus.h +1 -0
@@ -40,6 +40,7 @@struct pmbus_platform_data {u32 flags;/* Device specific flags */ +struct regulator_init_data *reg_init_data; };#endif /* _PMBUS_H_ */
Signature · 7 lines
1.7.9.5 _______________________________________________ lm-sensors mailing list [email protected] http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Re: [PATCH v2 1/2] pmbus: add regulator support
drivers/hwmon/pmbus/pmbus_core.c static int pmbus_init_common(struct i2c_client *client, struct pmbus_data *data, · line 1752
Quoted 7 lines · On Fri, Aug 22, 2014 at 04:11:33PM -0500, [email protected] wrote:
drivers/hwmon/pmbus/pmbus_core.c +7
-0+if (pdata && pdata->reg_init_data) { + config.init_data = pdata->reg_init_data; + }else { + config.init_data =of_get_regulator_init_data (dev, np); +if (!config.init_data) +return -ENOMEM ; + }
It should be fine to start with no init data - just let the regulator core worry about it. This will allow users to read back the state even if they can't change anything which is useful for system bringup or general debugging.
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Re: [PATCH v2 1/2] pmbus: add regulator support
Quoted 15 lines · Mark Brown
drivers/hwmon/pmbus/pmbus_core.c static int pmbus_init_common(struct i2c_client *client, struct pmbus_data *data, · line 1752
Quoted 7 lines · On Fri, Aug 22, 2014 at 04:11:33PM -0500, [email protected] wrote:
drivers/hwmon/pmbus/pmbus_core.c +7
-0+if (pdata && pdata->reg_init_data) { + config.init_data = pdata->reg_init_data; + }else { + config.init_data =of_get_regulator_init_data (dev, np); +if (!config.init_data) +return -ENOMEM ; + }It should be fine to start with no init data - just let the regulator core worry about it. This will allow users to read back the state even if they can't change anything which is useful for system bringup or general debugging.
of_get_regulator_init_data() will only have an error if it cannot alloc the regulator_init_data struct. That's why I did -ENOMEM. If there is no platform data and nothing about the regulator in the device tree, we should end up with a zeroed out regulator_init_data.
Thanks for the review.
Alan
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Guenter Roeck
maintainerRe: [PATCH v2 1/2] pmbus: add regulator support
Quoted 18 lines · atull
Quoted 15 lines · Mark Brown
drivers/hwmon/pmbus/pmbus_core.c static int pmbus_init_common(struct i2c_client *client, struct pmbus_data *data, · line 1752
Quoted 7 lines · On Fri, Aug 22, 2014 at 04:11:33PM -0500, [email protected] wrote:
drivers/hwmon/pmbus/pmbus_core.c +7
-0+if (pdata && pdata->reg_init_data) { + config.init_data = pdata->reg_init_data; + }else { + config.init_data =of_get_regulator_init_data (dev, np); +if (!config.init_data) +return -ENOMEM ; + }It should be fine to start with no init data - just let the regulator core worry about it. This will allow users to read back the state even if they can't change anything which is useful for system bringup or general debugging.
Quoted 5 lines
of_get_regulator_init_data()will only have an error if it cannot alloc theregulator_init_datastruct. That's why I did-ENOMEM. If there is no platform data and nothing about the regulator in the device tree, we should end up with a zeroed outregulator_init_data.
Yes, but if OF is not defined it will return NULL as well. Unless I am missing something, that means that the code will now fail if there is no platform init data and OF is not configured.
Guenter
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Re: [PATCH v2 1/2] pmbus: add regulator support
Quoted 10 lines · Guenter Roeck
Quoted 4 lines · atull
of_get_regulator_init_data()will only have an error if it cannot alloc theregulator_init_datastruct. That's why I did-ENOMEM. If there is no platform data and nothing about the regulator in the device tree, we should end up with a zeroed outregulator_init_data.Yes, but if OF is not defined it will return NULL as well. Unless I am missing something, that means that the code will now fail if there is no platform init data and OF is not configured.
Indeed, and that's the more interesting case than running out of memory.
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Re: [PATCH v2 1/2] pmbus: add regulator support
Quoted 8 lines · Mark Brown
Quoted 6 lines · Guenter Roeck
Quoted 4 lines · atull
of_get_regulator_init_data()will only have an error if it cannot alloc theregulator_init_datastruct. That's why I did-ENOMEM. If there is no platform data and nothing about the regulator in the device tree, we should end up with a zeroed outregulator_init_data.
Quoted 5 lines
Quoted 3 lines
Yes, but if OF is not defined it will return NULL as well. Unless I am missing something, that means that the code will now fail if there is no platform init data and OF is not configured.
Indeed, and that's the more interesting case than running out of memory.
Thanks for catching this. I'll remove the unnecessary check for NULL and the brackets here.
Alan
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
PATCH v2 2/2 pmbus: ltc2978: add regulator gating
In reply to [email protected]From: Alan Tull <[email protected]>
Add regulator with support for enabling or disabling all supplies.
v2: Remove '#include <linux/regulator/machine.h>'
Kconfig fixes
Remove hardwired regulator_init_data
--- drivers/hwmon/pmbus/Kconfig | 7 +++++ drivers/hwmon/pmbus/ltc2978.c | 60 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+)
drivers/hwmon/pmbus/Kconfig +7 -0
@@ -56,6 +56,13 @@ config SENSORS_LTC2978 This driver can also be built as a module. If so, the module will be called ltc2978. +config SENSORS_LTC2978_REGULATOR + boolean "Regulator support for LTC2974, LTC2978, LTC3880, and LTC3883" + depends on SENSORS_LTC2978 && REGULATOR + help + If you say yes here you get regulator support for Linear + Technology LTC2974, LTC2978, LTC3880, and LTC3883. + config SENSORS_MAX16064 tristate "Maxim MAX16064" default n
drivers/hwmon/pmbus/ltc2978.c +60 -0
78 lines not on this page · raw message
Signature · 7 lines
1.7.9.5 _______________________________________________ lm-sensors mailing list [email protected] http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Re: [PATCH v2 2/2] pmbus: ltc2978: add regulator gating
Quoted 4 lines · On Fri, Aug 22, 2014 at 04:11:34PM -0500, [email protected] wrote:
From: Alan Tull <[email protected]>
Add regulator with support for enabling or disabling all supplies.
though it still looks like you should be able to create generic functions for the operations.
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Guenter Roeck
maintainerRe: [PATCH v2 2/2] pmbus: ltc2978: add regulator gating
Quoted 11 lines · Mark Brown
Quoted 4 lines · On Fri, Aug 22, 2014 at 04:11:34PM -0500, [email protected] wrote:
From: Alan Tull <[email protected]>
Add regulator with support for enabling or disabling all supplies.
Reviwed-by Mark Brown <[email protected]>though it still looks like you should be able to create generic functions for the operations.
Sorry I didn't have time to review the code myself. I'll have to check the datasheet about turning regulators on and off. Using page 0xff for the lm2978 looks wrong, as the chip supports up to 8 channels which should be controlled separately (I would assume) instead of turning them all on and off in one go. Maybe I am missing something, but my assumption would have been to have a separate regulator for each channel, and that each channel would have its own regulator which would be turned on and off separately. So I don't really understand the change between v1 and v2 of the core patch, which dropped the per-channel regulators. Someone will have to explain to me why that makes sense, especially since it means that I won't be able to use the regulator expansion in my system (which would require per-channel regulators, and which does not always have all channels enabled on a given chip).
In respect to generic functions, that really depends on the scope of the regulators. As written, where all regulators are turned on in a single operation, per-chip functions are needed. I thought we would only need per-chip configuration values, but that only applies if regulators are turned on one by one, not all in one go.
Either case, a wrapper for ltc2978_write_pmbus_operation needs to be added to pmbus_core.c as pmbus_write_byte_data and exported (as a separate patch). For paged reads, the existing pmbus_read_byte_data should be used. In general, avoid direct accesses to paged registers and use API functions instead if possible.
Thanks,
Guenter
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Re: [PATCH v2 2/2] pmbus: ltc2978: add regulator gating
Quoted 8 lines · Guenter Roeck
Sorry I didn't have time to review the code myself. I'll have to check the datasheet about turning regulators on and off. Using page
0xfffor the lm2978 looks wrong, as the chip supports up to 8 channels which should be controlled separately (I would assume) instead of turning them all on and off in one go. Maybe I am missing something, but my assumption would have been to have a separate regulator for each channel, and that each channel would have its own regulator which would be
BTW I should point out that my review is just for the regulator API aspects of the change, I have no knowledge of this hardware. If what you're saying matches the hardware I'd definitely expect to see one regulator registered per physical regulator rather than a single regulator for everything on the device.
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Re: [PATCH v2 2/2] pmbus: ltc2978: add regulator gating
In reply to Guenter RoeckQuoted 16 lines · Guenter Roeck
Quoted 6 lines · Mark Brown
Quoted 3 lines · On Fri, Aug 22, 2014 at 04:11:34PM -0500, [email protected] wrote:
From: Alan Tull <[email protected]>
Quoted 9 lines
Quoted 2 lines
Add regulator with support for enabling or disabling all supplies.
Reviwed-by Mark Brown <[email protected]>though it still looks like you should be able to create generic functions for the operations.
Quoted 15 lines
Sorry I didn't have time to review the code myself. I'll have to check the datasheet about turning regulators on and off. Using page
0xfffor the lm2978 looks wrong, as the chip supports up to 8 channels which should be controlled separately (I would assume) instead of turning them all on and off in one go. Maybe I am missing something, but my assumption would have been to have a separate regulator for each channel, and that each channel would have its own regulator which would be turned on and off separately. So I don't really understand the change between v1 and v2 of the core patch, which dropped the per-channel regulators. Someone will have to explain to me why that makes sense, especially since it means that I won't be able to use the regulator expansion in my system (which would require per-channel regulators, and which does not always have all channels enabled on a given chip).
The LTC2978 spec says that the OPERATION command register "responds to the global page command (PAGE=0xFF)." I originally took it to mean that it *only* responds to 0xFF. Now I get that yes I could turn on/off each of 8 channels separately.
I will make the change have one regulator for each supply. It would be useful to still have a global regulator for turning them all on/off together if that is not completely odious.
Quoted 6 lines
In respect to generic functions, that really depends on the scope of the regulators. As written, where all regulators are turned on in a single operation, per-chip functions are needed. I thought we would only need per-chip configuration values, but that only applies if regulators are turned on one by one, not all in one go.
For all the parts supported by ltc2978.c, a banked write of 0x80 to the OPERATION register turns a regulator on, writing 0x00 turns it off. I'm not sure how universal that is for other PMBUS parts. I will look at the PMBUS specs when I get back to the office Tuesday.
I'll look into it and see if I can push almost all of this code into pmbus_core.c and just have per-chip config values inpmbus_driver_info. If many PMBUS parts have the same scheme (0x80 or0x00 written to OPERATION register as a banked write) then a flag bit that is turned on in pmbus_driver_info could enable this scheme for this chip. If it is a different register or different on/off values, then I'll need to add those to pmbus_driver_info.
Quoted 7 lines
Either case, a wrapper for
ltc2978_write_pmbus_operationneeds to be added topmbus_core.caspmbus_write_byte_dataand exported (as a separate patch). For paged reads, the existingpmbus_read_byte_datashould be used. In general, avoid direct accesses to paged registers and use API functions instead if possible.
OK. Will add pmbus_write_byte_data as a separate patch and use the existing pmbus_read_byte_data.
Thanks for the review!
Alan
Quoted 4 lines
Thanks,
Guenter
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Guenter Roeck
maintainerRe: [PATCH v2 2/2] pmbus: ltc2978: add regulator gating
Quoted 49 lines · Alan Tull
Quoted 16 lines · Guenter Roeck
Quoted 6 lines · Mark Brown
Quoted 3 lines · On Fri, Aug 22, 2014 at 04:11:34PM -0500, [email protected] wrote:
From: Alan Tull <[email protected]>
Quoted 9 lines
Quoted 2 lines
Add regulator with support for enabling or disabling all supplies.
Reviwed-by Mark Brown <[email protected]>though it still looks like you should be able to create generic functions for the operations.
Quoted 15 lines
Sorry I didn't have time to review the code myself. I'll have to check the datasheet about turning regulators on and off. Using page
0xfffor the lm2978 looks wrong, as the chip supports up to 8 channels which should be controlled separately (I would assume) instead of turning them all on and off in one go. Maybe I am missing something, but my assumption would have been to have a separate regulator for each channel, and that each channel would have its own regulator which would be turned on and off separately. So I don't really understand the change between v1 and v2 of the core patch, which dropped the per-channel regulators. Someone will have to explain to me why that makes sense, especially since it means that I won't be able to use the regulator expansion in my system (which would require per-channel regulators, and which does not always have all channels enabled on a given chip).The LTC2978 spec says that the OPERATION command register "responds to the global page command (PAGE=0xFF)." I originally took it to mean that it *only* responds to
0xFF. Now I get that yes I could turn on/off each of 8 channels separately.I will make the change have one regulator for each supply. It would be useful to still have a global regulator for turning them all on/off together if that is not completely odious.
Quoted 6 lines
In respect to generic functions, that really depends on the scope of the regulators. As written, where all regulators are turned on in a single operation, per-chip functions are needed. I thought we would only need per-chip configuration values, but that only applies if regulators are turned on one by one, not all in one go.
Quoted 5 lines
For all the parts supported by
ltc2978.c, a banked write of0x80to the OPERATION register turns a regulator on, writing0x00turns it off. I'm not sure how universal that is for other PMBUS parts. I will look at the PMBUS specs when I get back to the office Tuesday.
It isn't. Other parts need a different value to be written for on/off. However, that does not mean we need a chip specific _function_ to write the values. All we should need is the values to write for on/off.
Quoted 7 lines
I'll look into it and see if I can push almost all of this code into
pmbus_core.cand just have per-chip config values inpmbus_driver_info. If many PMBUS parts have the same scheme (0x80or0x00written to OPERATION register as a banked write) then a flag bit that is turned on inpmbus_driver_infocould enable this scheme for this chip. If it is a different register or different on/off values, then I'll need to add those topmbus_driver_info.
Values should work, and the writes should all be banked, but a flag is unfortunately insufficient. You should include a per-page flag to enable the functionality (something like PMBUS_HAVE_REGULATOR). Some PMBus chips don't have regulators on all pages.
Quoted 11 lines
Quoted 7 lines
Either case, a wrapper for
ltc2978_write_pmbus_operationneeds to be added topmbus_core.caspmbus_write_byte_dataand exported (as a separate patch). For paged reads, the existingpmbus_read_byte_datashould be used. In general, avoid direct accesses to paged registers and use API functions instead if possible.OK. Will add
pmbus_write_byte_dataas a separate patch and use the existingpmbus_read_byte_data.
If you use per-page flags and values, you should not need those at all.
Thanks,
Guenter
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors