Skip to contentSkip to conversation

regulator: pfuze100: add pfuze100 regulator driver

PATCH Superseded Robin Gong 2 participants 3 messages Jul 9, 2013 Voltage and current regulator framework

v1 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Robin Gong

author
#0 lore raw

PATCH 1/1 regulator: pfuze100: add pfuze100 regulator driver

Add pfuze100 regulator driver.

---
 drivers/regulator/Kconfig              |    7 +
 drivers/regulator/Makefile             |    2 +
 drivers/regulator/pfuze-regulator.h    |  110 ++++
 drivers/regulator/pfuze100-regulator.c |  993 ++++++++++++++++++++++++++++++++
 include/linux/regulator/pfuze.h        |   50 ++
 5 files changed, 1162 insertions(+), 0 deletions(-)
 create mode 100644 drivers/regulator/pfuze-regulator.h
 create mode 100644 drivers/regulator/pfuze100-regulator.c
 create mode 100644 include/linux/regulator/pfuze.h
drivers/regulator/Kconfig +7 -0
index f1e6ad9..f913172 100644
@@ -158,6 +158,13 @@ config REGULATOR_MC13892
 	  Say y here to support the regulators found on the Freescale MC13892
 	  PMIC.
 
+config REGULATOR_PFUZE100
+	tristate "Support regulators on Freescale PFUZE100 PMIC"
+	depends on I2C
+	help
+	  Say y here to support the regulators found on the Freescale PFUZE100
+	  PMIC.
+
 config REGULATOR_ISL6271A
 	tristate "Intersil ISL6271A Power regulator"
 	depends on I2C
drivers/regulator/Makefile +2 -0
index ba4a3cf..d78eca7 100644
@@ -45,6 +45,7 @@ obj-$(CONFIG_REGULATOR_MAX77693) += max77693.o
 obj-$(CONFIG_REGULATOR_MC13783) += mc13783-regulator.o
 obj-$(CONFIG_REGULATOR_MC13892) += mc13892-regulator.o
 obj-$(CONFIG_REGULATOR_MC13XXX_CORE) +=  mc13xxx-regulator-core.o
+obj-$(CONFIG_REGULATOR_PFUZE100) += pfuze100-regulator.o
 obj-$(CONFIG_REGULATOR_PALMAS) += palmas-regulator.o
 obj-$(CONFIG_REGULATOR_TPS51632) += tps51632-regulator.o
 obj-$(CONFIG_REGULATOR_PCAP) += pcap-regulator.o
@@ -72,6 +73,7 @@ obj-$(CONFIG_REGULATOR_WM831X) += wm831x-ldo.o
 obj-$(CONFIG_REGULATOR_WM8350) += wm8350-regulator.o
 obj-$(CONFIG_REGULATOR_WM8400) += wm8400-regulator.o
 obj-$(CONFIG_REGULATOR_WM8994) += wm8994-regulator.o
+obj-$(CONFIG_REGULATOR_PFUZE100) += pfuze100-regulator.o
 
 
 ccflags-$(CONFIG_REGULATOR_DEBUG) += -DDEBUG
drivers/regulator/pfuze-regulator.h new file +110 -0

110 lines not on this page · raw message

drivers/regulator/pfuze100-regulator.c new file +993 -0

993 lines not on this page · raw message

include/linux/regulator/pfuze.h new file +50 -0

50 lines not on this page · raw message

Signature · 1 line
1.7.5.4
maintainer
#1 lore raw

On Tue, Jul 09, 2013 at 02:38:00PM +0800, Robin Gong wrote:

I've not fully reviewed this, the major thing here is that the driver is not making use of the regmap helpers for anything - most of the code in this driver looks like it duplicates standard code available in the core.

drivers/regulator/Makefile obj-$(CONFIG_REGULATOR_WM831X) += wm831x-ldo.o · line 76

Quoted 13 lines
drivers/regulator/Makefile +2 -0
@@ -45,6 +45,7 @@ obj-$(CONFIG_REGULATOR_MAX77693) += max77693.o
 obj-$(CONFIG_REGULATOR_MC13783) += mc13783-regulator.o
 obj-$(CONFIG_REGULATOR_MC13892) += mc13892-regulator.o
 obj-$(CONFIG_REGULATOR_MC13XXX_CORE) +=  mc13xxx-regulator-core.o
+obj-$(CONFIG_REGULATOR_PFUZE100) += pfuze100-regulator.o
 obj-$(CONFIG_REGULATOR_PALMAS) += palmas-regulator.o
 obj-$(CONFIG_REGULATOR_TPS51632) += tps51632-regulator.o
 obj-$(CONFIG_REGULATOR_PCAP) += pcap-regulator.o
@@ -72,6 +73,7 @@ obj-$(CONFIG_REGULATOR_WM831X) += wm831x-ldo.o
 obj-$(CONFIG_REGULATOR_WM8350) += wm8350-regulator.o
 obj-$(CONFIG_REGULATOR_WM8400) += wm8400-regulator.o
 obj-$(CONFIG_REGULATOR_WM8994) += wm8994-regulator.o
+obj-$(CONFIG_REGULATOR_PFUZE100) += pfuze100-regulator.o

This looks broken...

Review

Quoted 2 lines
(quoted diff) +1 -0
+++ b/drivers/regulator/pfuze-regulator.h
@@ -0,0 +1,110 @@

Why is this a separate file?

drivers/regulator/pfuze-regulator.h line 33

Quoted 11 lines
drivers/regulator/pfuze-regulator.h new file +11 -0
+struct pfuze_regulator {
+	struct regulator_desc desc;
+	unsigned int reg;
+	unsigned int stby_reg;
+	unsigned char enable_bit;
+	unsigned char stby_bit;
+	unsigned char vsel_shift;
+	unsigned char vsel_mask;
+	unsigned char stby_vsel_shift;
+	unsigned char stby_vsel_mask;
+	int const *voltages;

This pretty much all looks like you are duplicating standard framework features - things like the vsels for example.

drivers/regulator/pfuze100-regulator.c line 339

Quoted 10 lines
drivers/regulator/pfuze100-regulator.c new file +10 -0
+static const int pfuze100_sw1[] = {
+	300000, 325000, 350000, 375000, 400000, 425000, 450000, 475000,
+	500000, 525000, 550000, 575000, 600000, 625000, 650000, 675000,
+	700000, 725000, 750000, 775000, 800000, 825000, 850000, 875000,
+	900000, 925000, 950000, 975000, 1000000, 1025000, 1050000, 1075000,
+	1100000, 1125000, 1150000, 1175000, 1200000, 1225000, 1250000, 1275000,
+	1300000, 1325000, 1350000, 1375000, 1400000, 1425000, 1450000, 1475000,
+	1500000, 1525000, 1550000, 1575000, 1600000, 1625000, 1650000, 1675000,
+	1700000, 1725000, 1750000, 1775000, 1800000, 1825000, 1850000, 1875000,
+};

This looks like a linear map, use one if you can. Similarly for a bunch of the other tables (possibly all of them).

drivers/regulator/pfuze100-regulator.c line 409

Quoted 7 lines
drivers/regulator/pfuze100-regulator.c new file +7 -0
+#if defined(CONFIG_OF)
+static const struct of_device_id pfuze_dt_ids[] = {
+	{ .compatible = "fsl,pfuze100", .data = (void *)PFUZE_ID_PFUZE100},
+	{},
+};
+MODULE_DEVICE_TABLE(of, pfuze_dt_ids);
+#endif

No need for ifdefs.

drivers/regulator/pfuze100-regulator.c line 429

Quoted 1 line
drivers/regulator/pfuze100-regulator.c new file +1 -0
+static int pfuze100_regulator_enable(struct regulator_dev *rdev)

You should be using the standard regmap helpers for this.

Review line 31

Quoted 2 lines
(quoted diff) +2 -0
+int pfuze100_regulator_list_voltage(struct regulator_dev *rdev,
+				    unsigned selector)

This too (even if you need to use the tables there are helpers for that too).

drivers/regulator/pfuze100-regulator.c line 728

Quoted 9 lines
drivers/regulator/pfuze100-regulator.c new file +9 -0
+static int pfuze100_regulator_sw_standby_enable(struct regulator_dev *rdev)
+{
+	return 0;
+}
+static int pfuze100_regulator_sw_standby_disable(struct regulator_dev *rdev)
+{
+	return 0;
+}
+static struct regulator_ops pfuze100_sw_regulator_ops = {

Coding style and you shouldn't have any empty functions.

drivers/regulator/pfuze100-regulator.c line 743

Quoted 4 lines
drivers/regulator/pfuze100-regulator.c new file +4 -0
+#ifdef CONFIG_OF
+
+static int  pfuze_get_num_regulators_dt(struct device *dev)
+{

You need to document any new device tree bindings.

drivers/regulator/pfuze100-regulator.c line 848

Quoted 7 lines
drivers/regulator/pfuze100-regulator.c new file +7 -0
+static struct regmap_config pfuze_regmap_config = {
+	.reg_bits = 8,
+	.val_bits = 8,
+
+	.max_register = PFUZE_NUMREGS,
+
+	.cache_type = REGCACHE_NONE,

This is the defualt, though you should consider caching for performance reasons.

drivers/regulator/pfuze100-regulator.c line 982

Quoted 1 line
drivers/regulator/pfuze100-regulator.c new file +1 -0
+subsys_initcall(pfuze100_regulator_init);

Use module_i2c_driver() (and watch out for coding style).

#2 lore raw

Thanks Mark. The pfuze driver refer to the mc13xxx regulator driver, so I didn't notice regulator core make some changes and some work have been done by regulator core. Sorry.. I will update the patch later.

-----Original Message-----
From: Mark Brown [mailto:[email protected]]
Sent: Tuesday, July 09, 2013 5:44 PM
To: Gong Yibin-B38343
Cc: [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v1] regulator: pfuze100: add pfuze100 regulator driver

On Tue, Jul 09, 2013 at 02:38:00PM +0800, Robin Gong wrote:

I've not fully reviewed this, the major thing here is that the driver is not making use of the regmap helpers for anything - most of the code in this driver looks like it duplicates standard code available in the core.

Quoted 8 lines
drivers/regulator/Makefile +1 -0
@@ -45,6 +45,7 @@ obj-$(CONFIG_REGULATOR_MAX77693) += max77693.o
 obj-$(CONFIG_REGULATOR_MC13783) += mc13783-regulator.o
 obj-$(CONFIG_REGULATOR_MC13892) += mc13892-regulator.o
 obj-$(CONFIG_REGULATOR_MC13XXX_CORE) +=  mc13xxx-regulator-core.o
+obj-$(CONFIG_REGULATOR_PFUZE100) += pfuze100-regulator.o
 obj-$(CONFIG_REGULATOR_PALMAS) += palmas-regulator.o
 obj-$(CONFIG_REGULATOR_TPS51632) += tps51632-regulator.o
 obj-$(CONFIG_REGULATOR_PCAP) += pcap-regulator.o @@ -72,6 +73,7 @@ 
Quoted 5 lines

obj-$(CONFIG_REGULATOR_WM831X) += wm831x-ldo.o
obj-$(CONFIG_REGULATOR_WM8350) += wm8350-regulator.o obj-$(CONFIG_REGULATOR_WM8400) += wm8400-regulator.o obj-$(CONFIG_REGULATOR_WM8994) += wm8994-regulator.o
+obj-$(CONFIG_REGULATOR_PFUZE100) += pfuze100-regulator.o

This looks broken...

Review

Quoted 2 lines

+++ b/drivers/regulator/pfuze-regulator.h

(quoted diff) +0 -0
@@ -0,0 +1,110 @@

Why is this a separate file?

drivers/regulator/pfuze-regulator.h line 33

Quoted 11 lines
drivers/regulator/pfuze-regulator.h new file +11 -0
+struct pfuze_regulator {
+	struct regulator_desc desc;
+	unsigned int reg;
+	unsigned int stby_reg;
+	unsigned char enable_bit;
+	unsigned char stby_bit;
+	unsigned char vsel_shift;
+	unsigned char vsel_mask;
+	unsigned char stby_vsel_shift;
+	unsigned char stby_vsel_mask;
+	int const *voltages;

This pretty much all looks like you are duplicating standard framework features - things like the vsels for example.

drivers/regulator/pfuze100-regulator.c

Quoted 10 lines
drivers/regulator/pfuze100-regulator.c new file +10 -0
+static const int pfuze100_sw1[] = {
+	300000, 325000, 350000, 375000, 400000, 425000, 450000, 475000,
+	500000, 525000, 550000, 575000, 600000, 625000, 650000, 675000,
+	700000, 725000, 750000, 775000, 800000, 825000, 850000, 875000,
+	900000, 925000, 950000, 975000, 1000000, 1025000, 1050000, 1075000,
+	1100000, 1125000, 1150000, 1175000, 1200000, 1225000, 1250000, 1275000,
+	1300000, 1325000, 1350000, 1375000, 1400000, 1425000, 1450000, 1475000,
+	1500000, 1525000, 1550000, 1575000, 1600000, 1625000, 1650000, 1675000,
+	1700000, 1725000, 1750000, 1775000, 1800000, 1825000, 1850000, 
+1875000, };

This looks like a linear map, use one if you can. Similarly for a bunch of the other tables (possibly all of them).

drivers/regulator/pfuze100-regulator.c

Quoted 6 lines
drivers/regulator/pfuze100-regulator.c new file +6 -0
+#if defined(CONFIG_OF)
+static const struct of_device_id pfuze_dt_ids[] = {
+	{ .compatible = "fsl,pfuze100", .data = (void *)PFUZE_ID_PFUZE100},
+	{},
+};
+MODULE_DEVICE_TABLE(of, pfuze_dt_ids); #endif

No need for ifdefs.

drivers/regulator/pfuze100-regulator.c line 429

Quoted 1 line
drivers/regulator/pfuze100-regulator.c new file +1 -0
+static int pfuze100_regulator_enable(struct regulator_dev *rdev)

You should be using the standard regmap helpers for this.

Review line 30

Quoted 2 lines
(quoted diff) +2 -0
+int pfuze100_regulator_list_voltage(struct regulator_dev *rdev,
+				    unsigned selector)

This too (even if you need to use the tables there are helpers for that too).

drivers/regulator/pfuze100-regulator.c line 728

Quoted 9 lines
drivers/regulator/pfuze100-regulator.c new file +9 -0
+static int pfuze100_regulator_sw_standby_enable(struct regulator_dev 
+*rdev) {
+	return 0;
+}
+static int pfuze100_regulator_sw_standby_disable(struct regulator_dev 
+*rdev) {
+	return 0;
+}
+static struct regulator_ops pfuze100_sw_regulator_ops = {

Coding style and you shouldn't have any empty functions.

drivers/regulator/pfuze100-regulator.c

Quoted 3 lines
drivers/regulator/pfuze100-regulator.c new file +3 -0
+#ifdef CONFIG_OF
+
+static int  pfuze_get_num_regulators_dt(struct device *dev) {

You need to document any new device tree bindings.

drivers/regulator/pfuze100-regulator.c line 848

Quoted 7 lines
drivers/regulator/pfuze100-regulator.c new file +7 -0
+static struct regmap_config pfuze_regmap_config = {
+	.reg_bits = 8,
+	.val_bits = 8,
+
+	.max_register = PFUZE_NUMREGS,
+
+	.cache_type = REGCACHE_NONE,

This is the defualt, though you should consider caching for performance reasons.

drivers/regulator/pfuze100-regulator.c line 982

Quoted 1 line
drivers/regulator/pfuze100-regulator.c new file +1 -0
+subsys_initcall(pfuze100_regulator_init);

Use module_i2c_driver() (and watch out for coding style).