Putting TPS6235x into the power regulator framework
Quoted 3 lines · On Thu, Dec 04, 2008 at 03:55:06PM +0530, [email protected] wrote:
(quoted diff) +3
-0+ }, + .num_consumer_supplies = 1, + .consumer_supplies = &tps6235x_consumers[0],
...
Review
Quoted 2 lines
(quoted diff) +2
-0+ .num_consumer_supplies = 1, + .consumer_supplies = &tps6235x_consumers[1],
This code will work but flags up alarm bells when doing review - it would be clearer to declare two separate variables, which is also less error prone if someone takes your code and uses it as a template for another board.
Review
Quoted 7 lines
(quoted diff) +7
-0+config REGULATOR_TPS6235X + bool "TPS6235X Power regulator for OMAP3EVM" + depends on PR785 + help + This driver supports the voltage regulators provided by TPS6235x chips. + The TPS62352 and TPS62353 are mounted on PR785 Power module card for + providing voltage regulator functions.
This should probably be two drivers: a driver for the TPS6235x and a driver for the power module card, otherwise systems that use the chip on a different board won't be able to do so. Looking at the code it seems you've got something fairly close to this structure already, it just needs exposing.
Quoted 4 lines
index 02a7744..901f402 100644
drivers/regulator/core.c static LIST_HEAD(regulator_list); · line 39
Quoted 10 lines
drivers/regulator/core.c +0
-7@@ -30,33 +30,6 @@ static LIST_HEAD(regulator_list);static LIST_HEAD (regulator_map_list);/** -* struct regulator_dev -* -* Voltage / Current regulator class device. One for each regulator. -*/ -struct regulator_dev { -struct regulator_desc *desc; -int use_count;
This is... interesting? I think all you're doing is looking inside to get the driver data rather than using regulator_get_drvdata() - is there anything else?
drivers/regulator/tps6235x-regulator.c
Quoted 10 lines
new file mode 100644
index 0000000..8a900dbdrivers/regulator/tps6235x-regulator.c new file +5
-0+#include <linux/regulator/driver.h> +#include <linux/regulator/machine.h> +#include <linux/i2c.h> +#include <linux/delay.h> +#include <linux/regulator/consumer.h>
Do you need the consumer header here?
drivers/regulator/tps6235x-regulator.c
Quoted 2 lines
drivers/regulator/tps6235x-regulator.c new file +2
-0+ +#define MODULE_NAME "tps6235x_power"
Really?
drivers/regulator/tps6235x-regulator.c
Quoted 10 lines
drivers/regulator/tps6235x-regulator.c new file +10
-0+/* Debug functions */ +#ifdef DEBUG + +#define dump_reg (client, reg, val) \ + do { \ + tps6235x_read_reg(client, reg, &val); \ + dev_dbg(&(client)->dev, "Reg(0x%.2X): 0x%.2X\n", reg, val); \ + } while (0) + +#endif /* #ifdef DEBUG */
static inline?
drivers/regulator/tps6235x-regulator.c
Quoted 2 lines
drivers/regulator/tps6235x-regulator.c new file +2
-0+/* Maximum number of bytes to be read in a single read */ +#define PR785_RETRY_COUNT 0x3
The name and comment don't seem to match up very well...
drivers/regulator/tps6235x-regulator.c
Quoted 4 lines
drivers/regulator/tps6235x-regulator.c new file +4
-0+static int tps6235x_dcdc_is_enabled (struct regulator_dev *dev) +{ +struct tps_6235x_info *tps_info = + (struct tps_6235x_info *)dev->reg_data;
Should use regulator_get_drvdata() for this.
drivers/regulator/tps6235x-regulator.c
Quoted 12 lines
drivers/regulator/tps6235x-regulator.c new file +11
-0+return tps_info->state; +} +static int tps6235x_dcdc_set_voltage (struct regulator_dev *dev, +int min_uV,int max_uV) +{ +struct tps_6235x_info *tps_info = + (struct tps_6235x_info *)dev->reg_data; +unsigned int millivolts = max_uV /1000 ; + +return pr785_set_dcdc_volt (tps_info->tps_i2c_addr, millivolts) ; +}
Normally you'd want to go for the lowest voltage you can in the range rather than the highest voltage. A driver doing voltage scaling for power saving would be likely to call set_voltage() with a range from the minimum that could currently be used to the maximum rated for the chip since it's only trying to save power, it doesn't specifically *need* the lower voltage. This allows the driver to run on systems where there are additional constraints which prevent the use of the lowest voltages.