All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/8 v2] Update TPS65910 to boot using devicetree
@ 2012-04-24 23:36 ` Rhyland Klein
  0 siblings, 0 replies; 26+ messages in thread
From: Rhyland Klein @ 2012-04-24 23:36 UTC (permalink / raw)
  To: Mark Brown, Samuel Ortiz, Grant Likely, Rob Herring, Liam Girdwood
  Cc: linux-kernel, devicetree-discuss, Rhyland Klein

This patch set updates the tps65910 driver to boot using devicetree.

This patch set now includes an addition to the of_regulator code which will
parse out all the regulator init data for a device given a list of the
regulator names it is expecting and a pointer to the array of where to store
the pointers to the regulator_init_data structures.

Rhyland Klein (8):
  regulator: add generic of node parsing for regulators
  regulator: add node validation checks
  mfd: tps65910: Commonize regmap access through header
  regulator: tps65910: Add device tree bindings
  mfd: tps65910: Add device-tree support
  regulator: tps65910 regulator: add device tree support
  mfd: tps65910-irq: Add devicetree init support
  ARM: Tegra: Add support for TPS65910 PMIC

 Documentation/devicetree/bindings/mfd/tps65910.txt |  133 +++++++++++++
 arch/arm/boot/dts/tegra-cardhu.dts                 |   91 +++++++++
 drivers/gpio/gpio-tps65910.c                       |   14 +-
 drivers/mfd/tps65910-irq.c                         |   55 ++++---
 drivers/mfd/tps65910.c                             |  107 ++++++++---
 drivers/regulator/of_regulator.c                   |   80 ++++++++
 drivers/regulator/tps65910-regulator.c             |  195 +++++++++++++++-----
 include/linux/mfd/tps65910.h                       |   29 +++-
 include/linux/regulator/of_regulator.h             |    9 +
 9 files changed, 606 insertions(+), 107 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/mfd/tps65910.txt


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 0/8 v2] Update TPS65910 to boot using devicetree
@ 2012-04-24 23:36 ` Rhyland Klein
  0 siblings, 0 replies; 26+ messages in thread
From: Rhyland Klein @ 2012-04-24 23:36 UTC (permalink / raw)
  To: Mark Brown, Samuel Ortiz, Grant Likely, Rob Herring, Liam Girdwood
  Cc: linux-kernel, devicetree-discuss, Rhyland Klein

This patch set updates the tps65910 driver to boot using devicetree.

This patch set now includes an addition to the of_regulator code which will
parse out all the regulator init data for a device given a list of the
regulator names it is expecting and a pointer to the array of where to store
the pointers to the regulator_init_data structures.

Rhyland Klein (8):
  regulator: add generic of node parsing for regulators
  regulator: add node validation checks
  mfd: tps65910: Commonize regmap access through header
  regulator: tps65910: Add device tree bindings
  mfd: tps65910: Add device-tree support
  regulator: tps65910 regulator: add device tree support
  mfd: tps65910-irq: Add devicetree init support
  ARM: Tegra: Add support for TPS65910 PMIC

 Documentation/devicetree/bindings/mfd/tps65910.txt |  133 +++++++++++++
 arch/arm/boot/dts/tegra-cardhu.dts                 |   91 +++++++++
 drivers/gpio/gpio-tps65910.c                       |   14 +-
 drivers/mfd/tps65910-irq.c                         |   55 ++++---
 drivers/mfd/tps65910.c                             |  107 ++++++++---
 drivers/regulator/of_regulator.c                   |   80 ++++++++
 drivers/regulator/tps65910-regulator.c             |  195 +++++++++++++++-----
 include/linux/mfd/tps65910.h                       |   29 +++-
 include/linux/regulator/of_regulator.h             |    9 +
 9 files changed, 606 insertions(+), 107 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/mfd/tps65910.txt

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 1/8 v2] regulator: add generic of node parsing for regulators
  2012-04-24 23:36 ` Rhyland Klein
@ 2012-04-24 23:36   ` Rhyland Klein
  -1 siblings, 0 replies; 26+ messages in thread
From: Rhyland Klein @ 2012-04-24 23:36 UTC (permalink / raw)
  To: Mark Brown, Samuel Ortiz, Grant Likely, Rob Herring, Liam Girdwood
  Cc: linux-kernel, devicetree-discuss, Rhyland Klein

As more regulators are moved to support dt, more drivers are going to need
to do lookups to find nodes associated with specific regulators. Add this
helper function which will find all the regulator_init_data for a series of
regulators and do some minimal dt validation checks.

Signed-off-by: Rhyland Klein <rklein@nvidia.com>
---
 v2: split off from tps65910 particular code to a more generic form based
     on initial reviews.

 drivers/regulator/of_regulator.c       |   42 ++++++++++++++++++++++++++++++++
 include/linux/regulator/of_regulator.h |    9 +++++++
 2 files changed, 51 insertions(+), 0 deletions(-)

diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c
index 679734d..45a5f85 100644
--- a/drivers/regulator/of_regulator.c
+++ b/drivers/regulator/of_regulator.c
@@ -85,3 +85,45 @@ struct regulator_init_data *of_get_regulator_init_data(struct device *dev,
 	return init_data;
 }
 EXPORT_SYMBOL_GPL(of_get_regulator_init_data);
+
+/**
+ * of_find_regulator_init_data_from_device - extract all regulator_init_data
+ * @dev: device requesting for regulator_init_data
+ * @node: device node from which to look for the regulators
+ * @names: array of the names of the regulators for which to look for nodes
+ * @init_data: array of regulator_init_data structure pointers to populate
+ * @num_regulators: the max number of regulators expected
+ *
+ * This function populates the array of regulator_init_data structures by
+ * finding the device_nodes which respresent each regulator and extracting
+ * data. Returns 0 on success.
+ */
+int of_find_regulator_init_data_from_device(struct device *dev,
+	struct device_node *node, const char * const names[],
+	struct regulator_init_data **init_data, int num_regulators)
+{
+	struct device_node *child = NULL;
+	int idx = 0;
+
+	if (!dev || !node)
+		return -EINVAL;
+
+	for (idx = 0; idx < num_regulators; idx++) {
+		struct device_node *np = of_find_node_by_name(node, names[idx]);
+
+		/* didn't find a match, thats fine */
+		if (!np)
+			continue;
+
+		/* parse regulator init data from node */
+		init_data[idx] = of_get_regulator_init_data(dev, np);
+		if (!init_data[idx]) {
+			dev_err(dev, "failed to parse dt for regulator %s\n",
+				child->name);
+			return -EINVAL;
+		}
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(of_find_regulator_init_data_from_device);
diff --git a/include/linux/regulator/of_regulator.h b/include/linux/regulator/of_regulator.h
index 769704f..0c65dcb 100644
--- a/include/linux/regulator/of_regulator.h
+++ b/include/linux/regulator/of_regulator.h
@@ -10,6 +10,9 @@
 extern struct regulator_init_data
 	*of_get_regulator_init_data(struct device *dev,
 				    struct device_node *node);
+extern int of_find_regulator_init_data_from_device(struct device *dev,
+	struct device_node *node, const char * const names[],
+	struct regulator_init_data **init_data, int num_regulators);
 #else
 static inline struct regulator_init_data
 	*of_get_regulator_init_data(struct device *dev,
@@ -17,6 +20,12 @@ static inline struct regulator_init_data
 {
 	return NULL;
 }
+static inline int of_find_regulator_init_data_from_device(struct device *dev,
+	struct device_node *node, const char * const names[],
+	struct regulator_init_data **init_data, int num_regulators)
+{
+	return 0;
+}
 #endif /* CONFIG_OF */
 
 #endif /* __LINUX_OF_REG_H */
-- 
1.7.0.4


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 1/8 v2] regulator: add generic of node parsing for regulators
@ 2012-04-24 23:36   ` Rhyland Klein
  0 siblings, 0 replies; 26+ messages in thread
From: Rhyland Klein @ 2012-04-24 23:36 UTC (permalink / raw)
  To: Mark Brown, Samuel Ortiz, Grant Likely, Rob Herring, Liam Girdwood
  Cc: linux-kernel, devicetree-discuss, Rhyland Klein

As more regulators are moved to support dt, more drivers are going to need
to do lookups to find nodes associated with specific regulators. Add this
helper function which will find all the regulator_init_data for a series of
regulators and do some minimal dt validation checks.

Signed-off-by: Rhyland Klein <rklein@nvidia.com>
---
 v2: split off from tps65910 particular code to a more generic form based
     on initial reviews.

 drivers/regulator/of_regulator.c       |   42 ++++++++++++++++++++++++++++++++
 include/linux/regulator/of_regulator.h |    9 +++++++
 2 files changed, 51 insertions(+), 0 deletions(-)

diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c
index 679734d..45a5f85 100644
--- a/drivers/regulator/of_regulator.c
+++ b/drivers/regulator/of_regulator.c
@@ -85,3 +85,45 @@ struct regulator_init_data *of_get_regulator_init_data(struct device *dev,
 	return init_data;
 }
 EXPORT_SYMBOL_GPL(of_get_regulator_init_data);
+
+/**
+ * of_find_regulator_init_data_from_device - extract all regulator_init_data
+ * @dev: device requesting for regulator_init_data
+ * @node: device node from which to look for the regulators
+ * @names: array of the names of the regulators for which to look for nodes
+ * @init_data: array of regulator_init_data structure pointers to populate
+ * @num_regulators: the max number of regulators expected
+ *
+ * This function populates the array of regulator_init_data structures by
+ * finding the device_nodes which respresent each regulator and extracting
+ * data. Returns 0 on success.
+ */
+int of_find_regulator_init_data_from_device(struct device *dev,
+	struct device_node *node, const char * const names[],
+	struct regulator_init_data **init_data, int num_regulators)
+{
+	struct device_node *child = NULL;
+	int idx = 0;
+
+	if (!dev || !node)
+		return -EINVAL;
+
+	for (idx = 0; idx < num_regulators; idx++) {
+		struct device_node *np = of_find_node_by_name(node, names[idx]);
+
+		/* didn't find a match, thats fine */
+		if (!np)
+			continue;
+
+		/* parse regulator init data from node */
+		init_data[idx] = of_get_regulator_init_data(dev, np);
+		if (!init_data[idx]) {
+			dev_err(dev, "failed to parse dt for regulator %s\n",
+				child->name);
+			return -EINVAL;
+		}
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(of_find_regulator_init_data_from_device);
diff --git a/include/linux/regulator/of_regulator.h b/include/linux/regulator/of_regulator.h
index 769704f..0c65dcb 100644
--- a/include/linux/regulator/of_regulator.h
+++ b/include/linux/regulator/of_regulator.h
@@ -10,6 +10,9 @@
 extern struct regulator_init_data
 	*of_get_regulator_init_data(struct device *dev,
 				    struct device_node *node);
+extern int of_find_regulator_init_data_from_device(struct device *dev,
+	struct device_node *node, const char * const names[],
+	struct regulator_init_data **init_data, int num_regulators);
 #else
 static inline struct regulator_init_data
 	*of_get_regulator_init_data(struct device *dev,
@@ -17,6 +20,12 @@ static inline struct regulator_init_data
 {
 	return NULL;
 }
+static inline int of_find_regulator_init_data_from_device(struct device *dev,
+	struct device_node *node, const char * const names[],
+	struct regulator_init_data **init_data, int num_regulators)
+{
+	return 0;
+}
 #endif /* CONFIG_OF */
 
 #endif /* __LINUX_OF_REG_H */
-- 
1.7.0.4

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 2/8 v2] regulator: add node validation checks
@ 2012-04-24 23:36   ` Rhyland Klein
  0 siblings, 0 replies; 26+ messages in thread
From: Rhyland Klein @ 2012-04-24 23:36 UTC (permalink / raw)
  To: Mark Brown, Samuel Ortiz, Grant Likely, Rob Herring, Liam Girdwood
  Cc: linux-kernel, devicetree-discuss, Rhyland Klein

This change adds some validation logic to the logic for parsing nodes for
regulator init data. The idea is to catch nodes that are defined but not used
which likely means invalid nodes.

Signed-off-by: Rhyland Klein <rklein@nvidia.com>
---
 v2: split off some node validation checks from original patch which implemented
     them specifically for the tps65910

 drivers/regulator/of_regulator.c |   38 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 38 insertions(+), 0 deletions(-)

diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c
index 45a5f85..4d5eb06 100644
--- a/drivers/regulator/of_regulator.c
+++ b/drivers/regulator/of_regulator.c
@@ -86,6 +86,12 @@ struct regulator_init_data *of_get_regulator_init_data(struct device *dev,
 }
 EXPORT_SYMBOL_GPL(of_get_regulator_init_data);
 
+/* structure used for verifying regulator nodes */
+struct of_regulator_node_info {
+	struct device_node *np;
+	int count;
+};
+
 /**
  * of_find_regulator_init_data_from_device - extract all regulator_init_data
  * @dev: device requesting for regulator_init_data
@@ -103,13 +109,27 @@ int of_find_regulator_init_data_from_device(struct device *dev,
 	struct regulator_init_data **init_data, int num_regulators)
 {
 	struct device_node *child = NULL;
+	struct of_regulator_node_info *ninfo;
+	int node_cnt = 0;
 	int idx = 0;
 
 	if (!dev || !node)
 		return -EINVAL;
 
+	for_each_child_of_node(node, child)
+		node_cnt++;
+
+	ninfo = kzalloc(sizeof(*ninfo) * node_cnt, GFP_KERNEL);
+	if (!ninfo)
+		return -ENOMEM;
+
+	/* initialize list to have node addresses */
+	for_each_child_of_node(node, child)
+		ninfo[idx++].np = child;
+
 	for (idx = 0; idx < num_regulators; idx++) {
 		struct device_node *np = of_find_node_by_name(node, names[idx]);
+		int node_idx = 0;
 
 		/* didn't find a match, thats fine */
 		if (!np)
@@ -120,10 +140,28 @@ int of_find_regulator_init_data_from_device(struct device *dev,
 		if (!init_data[idx]) {
 			dev_err(dev, "failed to parse dt for regulator %s\n",
 				child->name);
+			kfree(ninfo);
 			return -EINVAL;
 		}
+
+		/* mark node as used for later checks */
+		for (node_idx = 0; node_idx < node_cnt; node_idx++) {
+			if (np == ninfo[node_idx].np) {
+				ninfo[node_idx].count++;
+				break;
+			}
+		}
+	}
+
+	/* look for unused nodes */
+	for (idx = 0; idx < node_cnt; idx++) {
+		if (ninfo[idx].count == 0)
+			dev_warn(dev, "unused regulator node found: %s\n",
+					ninfo[idx].np->name);
 	}
 
+	kfree(ninfo);
+
 	return 0;
 }
 EXPORT_SYMBOL_GPL(of_find_regulator_init_data_from_device);
-- 
1.7.0.4


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 2/8 v2] regulator: add node validation checks
@ 2012-04-24 23:36   ` Rhyland Klein
  0 siblings, 0 replies; 26+ messages in thread
From: Rhyland Klein @ 2012-04-24 23:36 UTC (permalink / raw)
  To: Mark Brown, Samuel Ortiz, Grant Likely, Rob Herring, Liam Girdwood
  Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

This change adds some validation logic to the logic for parsing nodes for
regulator init data. The idea is to catch nodes that are defined but not used
which likely means invalid nodes.

Signed-off-by: Rhyland Klein <rklein-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
---
 v2: split off some node validation checks from original patch which implemented
     them specifically for the tps65910

 drivers/regulator/of_regulator.c |   38 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 38 insertions(+), 0 deletions(-)

diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c
index 45a5f85..4d5eb06 100644
--- a/drivers/regulator/of_regulator.c
+++ b/drivers/regulator/of_regulator.c
@@ -86,6 +86,12 @@ struct regulator_init_data *of_get_regulator_init_data(struct device *dev,
 }
 EXPORT_SYMBOL_GPL(of_get_regulator_init_data);
 
+/* structure used for verifying regulator nodes */
+struct of_regulator_node_info {
+	struct device_node *np;
+	int count;
+};
+
 /**
  * of_find_regulator_init_data_from_device - extract all regulator_init_data
  * @dev: device requesting for regulator_init_data
@@ -103,13 +109,27 @@ int of_find_regulator_init_data_from_device(struct device *dev,
 	struct regulator_init_data **init_data, int num_regulators)
 {
 	struct device_node *child = NULL;
+	struct of_regulator_node_info *ninfo;
+	int node_cnt = 0;
 	int idx = 0;
 
 	if (!dev || !node)
 		return -EINVAL;
 
+	for_each_child_of_node(node, child)
+		node_cnt++;
+
+	ninfo = kzalloc(sizeof(*ninfo) * node_cnt, GFP_KERNEL);
+	if (!ninfo)
+		return -ENOMEM;
+
+	/* initialize list to have node addresses */
+	for_each_child_of_node(node, child)
+		ninfo[idx++].np = child;
+
 	for (idx = 0; idx < num_regulators; idx++) {
 		struct device_node *np = of_find_node_by_name(node, names[idx]);
+		int node_idx = 0;
 
 		/* didn't find a match, thats fine */
 		if (!np)
@@ -120,10 +140,28 @@ int of_find_regulator_init_data_from_device(struct device *dev,
 		if (!init_data[idx]) {
 			dev_err(dev, "failed to parse dt for regulator %s\n",
 				child->name);
+			kfree(ninfo);
 			return -EINVAL;
 		}
+
+		/* mark node as used for later checks */
+		for (node_idx = 0; node_idx < node_cnt; node_idx++) {
+			if (np == ninfo[node_idx].np) {
+				ninfo[node_idx].count++;
+				break;
+			}
+		}
+	}
+
+	/* look for unused nodes */
+	for (idx = 0; idx < node_cnt; idx++) {
+		if (ninfo[idx].count == 0)
+			dev_warn(dev, "unused regulator node found: %s\n",
+					ninfo[idx].np->name);
 	}
 
+	kfree(ninfo);
+
 	return 0;
 }
 EXPORT_SYMBOL_GPL(of_find_regulator_init_data_from_device);
-- 
1.7.0.4

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 3/8 v2] mfd: tps65910: Commonize regmap access through header
  2012-04-24 23:36 ` Rhyland Klein
@ 2012-04-24 23:36   ` Rhyland Klein
  -1 siblings, 0 replies; 26+ messages in thread
From: Rhyland Klein @ 2012-04-24 23:36 UTC (permalink / raw)
  To: Mark Brown, Samuel Ortiz, Grant Likely, Rob Herring, Liam Girdwood
  Cc: linux-kernel, devicetree-discuss, Rhyland Klein

This change removes the read/write callback functions in favor of common
regmap accessors inside the header file. This change also makes use of
regmap_read/write for single register access which maps better onto what this
driver actually needs.

Signed-off-by: Rhyland Klein <rklein@nvidia.com>
---
 v2: implemented switching tps65910 drivers over to more directly accessing
     the regmap rather than going through utility functions.

 drivers/gpio/gpio-tps65910.c           |   14 +++---
 drivers/mfd/tps65910-irq.c             |   34 ++++++------
 drivers/mfd/tps65910.c                 |   26 ---------
 drivers/regulator/tps65910-regulator.c |   88 +++++++++++++++-----------------
 include/linux/mfd/tps65910.h           |   29 +++++++++--
 5 files changed, 91 insertions(+), 100 deletions(-)

diff --git a/drivers/gpio/gpio-tps65910.c b/drivers/gpio/gpio-tps65910.c
index 7eef648..bc155f2 100644
--- a/drivers/gpio/gpio-tps65910.c
+++ b/drivers/gpio/gpio-tps65910.c
@@ -23,9 +23,9 @@
 static int tps65910_gpio_get(struct gpio_chip *gc, unsigned offset)
 {
 	struct tps65910 *tps65910 = container_of(gc, struct tps65910, gpio);
-	uint8_t val;
+	unsigned int val;
 
-	tps65910->read(tps65910, TPS65910_GPIO0 + offset, 1, &val);
+	tps65910_reg_read(tps65910, TPS65910_GPIO0 + offset, &val);
 
 	if (val & GPIO_STS_MASK)
 		return 1;
@@ -39,10 +39,10 @@ static void tps65910_gpio_set(struct gpio_chip *gc, unsigned offset,
 	struct tps65910 *tps65910 = container_of(gc, struct tps65910, gpio);
 
 	if (value)
-		tps65910_set_bits(tps65910, TPS65910_GPIO0 + offset,
+		tps65910_reg_set_bits(tps65910, TPS65910_GPIO0 + offset,
 						GPIO_SET_MASK);
 	else
-		tps65910_clear_bits(tps65910, TPS65910_GPIO0 + offset,
+		tps65910_reg_clear_bits(tps65910, TPS65910_GPIO0 + offset,
 						GPIO_SET_MASK);
 }
 
@@ -54,7 +54,7 @@ static int tps65910_gpio_output(struct gpio_chip *gc, unsigned offset,
 	/* Set the initial value */
 	tps65910_gpio_set(gc, offset, value);
 
-	return tps65910_set_bits(tps65910, TPS65910_GPIO0 + offset,
+	return tps65910_reg_set_bits(tps65910, TPS65910_GPIO0 + offset,
 						GPIO_CFG_MASK);
 }
 
@@ -62,7 +62,7 @@ static int tps65910_gpio_input(struct gpio_chip *gc, unsigned offset)
 {
 	struct tps65910 *tps65910 = container_of(gc, struct tps65910, gpio);
 
-	return tps65910_clear_bits(tps65910, TPS65910_GPIO0 + offset,
+	return tps65910_reg_clear_bits(tps65910, TPS65910_GPIO0 + offset,
 						GPIO_CFG_MASK);
 }
 
@@ -102,7 +102,7 @@ void tps65910_gpio_init(struct tps65910 *tps65910, int gpio_base)
 		int i;
 		for (i = 0; i < tps65910->gpio.ngpio; ++i) {
 			if (board_data->en_gpio_sleep[i]) {
-				ret = tps65910_set_bits(tps65910,
+				ret = tps65910_reg_set_bits(tps65910,
 					TPS65910_GPIO0 + i, GPIO_SLEEP_MASK);
 				if (ret < 0)
 					dev_warn(tps65910->dev,
diff --git a/drivers/mfd/tps65910-irq.c b/drivers/mfd/tps65910-irq.c
index c9ed5c0..0f1ff7f 100644
--- a/drivers/mfd/tps65910-irq.c
+++ b/drivers/mfd/tps65910-irq.c
@@ -41,28 +41,28 @@ static inline int irq_to_tps65910_irq(struct tps65910 *tps65910,
 static irqreturn_t tps65910_irq(int irq, void *irq_data)
 {
 	struct tps65910 *tps65910 = irq_data;
+	unsigned int reg;
 	u32 irq_sts;
 	u32 irq_mask;
-	u8 reg;
 	int i;
 
-	tps65910->read(tps65910, TPS65910_INT_STS, 1, &reg);
+	tps65910_reg_read(tps65910, TPS65910_INT_STS, &reg);
 	irq_sts = reg;
-	tps65910->read(tps65910, TPS65910_INT_STS2, 1, &reg);
+	tps65910_reg_read(tps65910, TPS65910_INT_STS2, &reg);
 	irq_sts |= reg << 8;
 	switch (tps65910_chip_id(tps65910)) {
 	case TPS65911:
-		tps65910->read(tps65910, TPS65910_INT_STS3, 1, &reg);
+		tps65910_reg_read(tps65910, TPS65910_INT_STS3, &reg);
 		irq_sts |= reg << 16;
 	}
 
-	tps65910->read(tps65910, TPS65910_INT_MSK, 1, &reg);
+	tps65910_reg_read(tps65910, TPS65910_INT_MSK, &reg);
 	irq_mask = reg;
-	tps65910->read(tps65910, TPS65910_INT_MSK2, 1, &reg);
+	tps65910_reg_read(tps65910, TPS65910_INT_MSK2, &reg);
 	irq_mask |= reg << 8;
 	switch (tps65910_chip_id(tps65910)) {
 	case TPS65911:
-		tps65910->read(tps65910, TPS65910_INT_MSK3, 1, &reg);
+		tps65910_reg_read(tps65910, TPS65910_INT_MSK3, &reg);
 		irq_mask |= reg << 16;
 	}
 
@@ -82,13 +82,13 @@ static irqreturn_t tps65910_irq(int irq, void *irq_data)
 	/* Write the STS register back to clear IRQs we handled */
 	reg = irq_sts & 0xFF;
 	irq_sts >>= 8;
-	tps65910->write(tps65910, TPS65910_INT_STS, 1, &reg);
+	tps65910_reg_write(tps65910, TPS65910_INT_STS, reg);
 	reg = irq_sts & 0xFF;
-	tps65910->write(tps65910, TPS65910_INT_STS2, 1, &reg);
+	tps65910_reg_write(tps65910, TPS65910_INT_STS2, reg);
 	switch (tps65910_chip_id(tps65910)) {
 	case TPS65911:
 		reg = irq_sts >> 8;
-		tps65910->write(tps65910, TPS65910_INT_STS3, 1, &reg);
+		tps65910_reg_write(tps65910, TPS65910_INT_STS3, reg);
 	}
 
 	return IRQ_HANDLED;
@@ -105,27 +105,27 @@ static void tps65910_irq_sync_unlock(struct irq_data *data)
 {
 	struct tps65910 *tps65910 = irq_data_get_irq_chip_data(data);
 	u32 reg_mask;
-	u8 reg;
+	unsigned int reg;
 
-	tps65910->read(tps65910, TPS65910_INT_MSK, 1, &reg);
+	tps65910_reg_read(tps65910, TPS65910_INT_MSK, &reg);
 	reg_mask = reg;
-	tps65910->read(tps65910, TPS65910_INT_MSK2, 1, &reg);
+	tps65910_reg_read(tps65910, TPS65910_INT_MSK2, &reg);
 	reg_mask |= reg << 8;
 	switch (tps65910_chip_id(tps65910)) {
 	case TPS65911:
-		tps65910->read(tps65910, TPS65910_INT_MSK3, 1, &reg);
+		tps65910_reg_read(tps65910, TPS65910_INT_MSK3, &reg);
 		reg_mask |= reg << 16;
 	}
 
 	if (tps65910->irq_mask != reg_mask) {
 		reg = tps65910->irq_mask & 0xFF;
-		tps65910->write(tps65910, TPS65910_INT_MSK, 1, &reg);
+		tps65910_reg_write(tps65910, TPS65910_INT_MSK, reg);
 		reg = tps65910->irq_mask >> 8 & 0xFF;
-		tps65910->write(tps65910, TPS65910_INT_MSK2, 1, &reg);
+		tps65910_reg_write(tps65910, TPS65910_INT_MSK2, reg);
 		switch (tps65910_chip_id(tps65910)) {
 		case TPS65911:
 			reg = tps65910->irq_mask >> 16;
-			tps65910->write(tps65910, TPS65910_INT_MSK3, 1, &reg);
+			tps65910_reg_write(tps65910, TPS65910_INT_MSK3, reg);
 		}
 	}
 	mutex_unlock(&tps65910->irq_lock);
diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
index bf2b25e..70a8079 100644
--- a/drivers/mfd/tps65910.c
+++ b/drivers/mfd/tps65910.c
@@ -37,30 +37,6 @@ static struct mfd_cell tps65910s[] = {
 };
 
 
-static int tps65910_i2c_read(struct tps65910 *tps65910, u8 reg,
-				  int bytes, void *dest)
-{
-	return regmap_bulk_read(tps65910->regmap, reg, dest, bytes);
-}
-
-static int tps65910_i2c_write(struct tps65910 *tps65910, u8 reg,
-				  int bytes, void *src)
-{
-	return regmap_bulk_write(tps65910->regmap, reg, src, bytes);
-}
-
-int tps65910_set_bits(struct tps65910 *tps65910, u8 reg, u8 mask)
-{
-	return regmap_update_bits(tps65910->regmap, reg, mask, mask);
-}
-EXPORT_SYMBOL_GPL(tps65910_set_bits);
-
-int tps65910_clear_bits(struct tps65910 *tps65910, u8 reg, u8 mask)
-{
-	return regmap_update_bits(tps65910->regmap, reg, mask, 0);
-}
-EXPORT_SYMBOL_GPL(tps65910_clear_bits);
-
 static bool is_volatile_reg(struct device *dev, unsigned int reg)
 {
 	struct tps65910 *tps65910 = dev_get_drvdata(dev);
@@ -116,8 +92,6 @@ static int tps65910_i2c_probe(struct i2c_client *i2c,
 	tps65910->dev = &i2c->dev;
 	tps65910->i2c_client = i2c;
 	tps65910->id = id->driver_data;
-	tps65910->read = tps65910_i2c_read;
-	tps65910->write = tps65910_i2c_write;
 	mutex_init(&tps65910->io_mutex);
 
 	tps65910->regmap = regmap_init_i2c(i2c, &tps65910_regmap_config);
diff --git a/drivers/regulator/tps65910-regulator.c b/drivers/regulator/tps65910-regulator.c
index 747bf57..855bbec 100644
--- a/drivers/regulator/tps65910-regulator.c
+++ b/drivers/regulator/tps65910-regulator.c
@@ -331,21 +331,16 @@ struct tps65910_reg {
 
 static inline int tps65910_read(struct tps65910_reg *pmic, u8 reg)
 {
-	u8 val;
+	unsigned int val;
 	int err;
 
-	err = pmic->mfd->read(pmic->mfd, reg, 1, &val);
+	err = tps65910_reg_read(pmic->mfd, reg, &val);
 	if (err)
 		return err;
 
 	return val;
 }
 
-static inline int tps65910_write(struct tps65910_reg *pmic, u8 reg, u8 val)
-{
-	return pmic->mfd->write(pmic->mfd, reg, 1, &val);
-}
-
 static int tps65910_modify_bits(struct tps65910_reg *pmic, u8 reg,
 					u8 set_mask, u8 clear_mask)
 {
@@ -362,7 +357,7 @@ static int tps65910_modify_bits(struct tps65910_reg *pmic, u8 reg,
 
 	data &= ~clear_mask;
 	data |= set_mask;
-	err = tps65910_write(pmic, reg, data);
+	err = tps65910_reg_write(pmic->mfd, reg, data);
 	if (err)
 		dev_err(pmic->mfd->dev, "Write for reg 0x%x failed\n", reg);
 
@@ -371,7 +366,7 @@ out:
 	return err;
 }
 
-static int tps65910_reg_read(struct tps65910_reg *pmic, u8 reg)
+static int tps65910_reg_read_locked(struct tps65910_reg *pmic, u8 reg)
 {
 	int data;
 
@@ -385,13 +380,13 @@ static int tps65910_reg_read(struct tps65910_reg *pmic, u8 reg)
 	return data;
 }
 
-static int tps65910_reg_write(struct tps65910_reg *pmic, u8 reg, u8 val)
+static int tps65910_reg_write_locked(struct tps65910_reg *pmic, u8 reg, u8 val)
 {
 	int err;
 
 	mutex_lock(&pmic->mutex);
 
-	err = tps65910_write(pmic, reg, val);
+	err = tps65910_reg_write(pmic->mfd, reg, val);
 	if (err < 0)
 		dev_err(pmic->mfd->dev, "Write for reg 0x%x failed\n", reg);
 
@@ -476,7 +471,7 @@ static int tps65910_is_enabled(struct regulator_dev *dev)
 	if (reg < 0)
 		return reg;
 
-	value = tps65910_reg_read(pmic, reg);
+	value = tps65910_reg_read_locked(pmic, reg);
 	if (value < 0)
 		return value;
 
@@ -493,7 +488,7 @@ static int tps65910_enable(struct regulator_dev *dev)
 	if (reg < 0)
 		return reg;
 
-	return tps65910_set_bits(mfd, reg, TPS65910_SUPPLY_STATE_ENABLED);
+	return tps65910_reg_set_bits(mfd, reg, TPS65910_SUPPLY_STATE_ENABLED);
 }
 
 static int tps65910_disable(struct regulator_dev *dev)
@@ -506,7 +501,7 @@ static int tps65910_disable(struct regulator_dev *dev)
 	if (reg < 0)
 		return reg;
 
-	return tps65910_clear_bits(mfd, reg, TPS65910_SUPPLY_STATE_ENABLED);
+	return tps65910_reg_clear_bits(mfd, reg, TPS65910_SUPPLY_STATE_ENABLED);
 }
 
 static int tps65910_enable_time(struct regulator_dev *dev)
@@ -532,9 +527,9 @@ static int tps65910_set_mode(struct regulator_dev *dev, unsigned int mode)
 							LDO_ST_MODE_BIT);
 	case REGULATOR_MODE_IDLE:
 		value = LDO_ST_ON_BIT | LDO_ST_MODE_BIT;
-		return tps65910_set_bits(mfd, reg, value);
+		return tps65910_reg_set_bits(mfd, reg, value);
 	case REGULATOR_MODE_STANDBY:
-		return tps65910_clear_bits(mfd, reg, LDO_ST_ON_BIT);
+		return tps65910_reg_clear_bits(mfd, reg, LDO_ST_ON_BIT);
 	}
 
 	return -EINVAL;
@@ -549,7 +544,7 @@ static unsigned int tps65910_get_mode(struct regulator_dev *dev)
 	if (reg < 0)
 		return reg;
 
-	value = tps65910_reg_read(pmic, reg);
+	value = tps65910_reg_read_locked(pmic, reg);
 	if (value < 0)
 		return value;
 
@@ -569,28 +564,28 @@ static int tps65910_get_voltage_dcdc_sel(struct regulator_dev *dev)
 
 	switch (id) {
 	case TPS65910_REG_VDD1:
-		opvsel = tps65910_reg_read(pmic, TPS65910_VDD1_OP);
-		mult = tps65910_reg_read(pmic, TPS65910_VDD1);
+		opvsel = tps65910_reg_read_locked(pmic, TPS65910_VDD1_OP);
+		mult = tps65910_reg_read_locked(pmic, TPS65910_VDD1);
 		mult = (mult & VDD1_VGAIN_SEL_MASK) >> VDD1_VGAIN_SEL_SHIFT;
-		srvsel = tps65910_reg_read(pmic, TPS65910_VDD1_SR);
+		srvsel = tps65910_reg_read_locked(pmic, TPS65910_VDD1_SR);
 		sr = opvsel & VDD1_OP_CMD_MASK;
 		opvsel &= VDD1_OP_SEL_MASK;
 		srvsel &= VDD1_SR_SEL_MASK;
 		vselmax = 75;
 		break;
 	case TPS65910_REG_VDD2:
-		opvsel = tps65910_reg_read(pmic, TPS65910_VDD2_OP);
-		mult = tps65910_reg_read(pmic, TPS65910_VDD2);
+		opvsel = tps65910_reg_read_locked(pmic, TPS65910_VDD2_OP);
+		mult = tps65910_reg_read_locked(pmic, TPS65910_VDD2);
 		mult = (mult & VDD2_VGAIN_SEL_MASK) >> VDD2_VGAIN_SEL_SHIFT;
-		srvsel = tps65910_reg_read(pmic, TPS65910_VDD2_SR);
+		srvsel = tps65910_reg_read_locked(pmic, TPS65910_VDD2_SR);
 		sr = opvsel & VDD2_OP_CMD_MASK;
 		opvsel &= VDD2_OP_SEL_MASK;
 		srvsel &= VDD2_SR_SEL_MASK;
 		vselmax = 75;
 		break;
 	case TPS65911_REG_VDDCTRL:
-		opvsel = tps65910_reg_read(pmic, TPS65911_VDDCTRL_OP);
-		srvsel = tps65910_reg_read(pmic, TPS65911_VDDCTRL_SR);
+		opvsel = tps65910_reg_read_locked(pmic, TPS65911_VDDCTRL_OP);
+		srvsel = tps65910_reg_read_locked(pmic, TPS65911_VDDCTRL_SR);
 		sr = opvsel & VDDCTRL_OP_CMD_MASK;
 		opvsel &= VDDCTRL_OP_SEL_MASK;
 		srvsel &= VDDCTRL_SR_SEL_MASK;
@@ -630,7 +625,7 @@ static int tps65910_get_voltage(struct regulator_dev *dev)
 	if (reg < 0)
 		return reg;
 
-	value = tps65910_reg_read(pmic, reg);
+	value = tps65910_reg_read_locked(pmic, reg);
 	if (value < 0)
 		return value;
 
@@ -669,7 +664,7 @@ static int tps65911_get_voltage(struct regulator_dev *dev)
 
 	reg = pmic->get_ctrl_reg(id);
 
-	value = tps65910_reg_read(pmic, reg);
+	value = tps65910_reg_read_locked(pmic, reg);
 
 	switch (id) {
 	case TPS65911_REG_LDO1:
@@ -728,7 +723,7 @@ static int tps65910_set_voltage_dcdc_sel(struct regulator_dev *dev,
 		tps65910_modify_bits(pmic, TPS65910_VDD1,
 				(dcdc_mult << VDD1_VGAIN_SEL_SHIFT),
 						VDD1_VGAIN_SEL_MASK);
-		tps65910_reg_write(pmic, TPS65910_VDD1_OP, vsel);
+		tps65910_reg_write_locked(pmic, TPS65910_VDD1_OP, vsel);
 		break;
 	case TPS65910_REG_VDD2:
 		dcdc_mult = (selector / VDD1_2_NUM_VOLT_FINE) + 1;
@@ -739,11 +734,11 @@ static int tps65910_set_voltage_dcdc_sel(struct regulator_dev *dev,
 		tps65910_modify_bits(pmic, TPS65910_VDD2,
 				(dcdc_mult << VDD2_VGAIN_SEL_SHIFT),
 						VDD1_VGAIN_SEL_MASK);
-		tps65910_reg_write(pmic, TPS65910_VDD2_OP, vsel);
+		tps65910_reg_write_locked(pmic, TPS65910_VDD2_OP, vsel);
 		break;
 	case TPS65911_REG_VDDCTRL:
 		vsel = selector + 3;
-		tps65910_reg_write(pmic, TPS65911_VDDCTRL_OP, vsel);
+		tps65910_reg_write_locked(pmic, TPS65911_VDDCTRL_OP, vsel);
 	}
 
 	return 0;
@@ -994,10 +989,10 @@ static int tps65910_set_ext_sleep_config(struct tps65910_reg *pmic,
 
 	/* External EN1 control */
 	if (ext_sleep_config & TPS65910_SLEEP_CONTROL_EXT_INPUT_EN1)
-		ret = tps65910_set_bits(mfd,
+		ret = tps65910_reg_set_bits(mfd,
 				TPS65910_EN1_LDO_ASS + regoffs, bit_pos);
 	else
-		ret = tps65910_clear_bits(mfd,
+		ret = tps65910_reg_clear_bits(mfd,
 				TPS65910_EN1_LDO_ASS + regoffs, bit_pos);
 	if (ret < 0) {
 		dev_err(mfd->dev,
@@ -1007,10 +1002,10 @@ static int tps65910_set_ext_sleep_config(struct tps65910_reg *pmic,
 
 	/* External EN2 control */
 	if (ext_sleep_config & TPS65910_SLEEP_CONTROL_EXT_INPUT_EN2)
-		ret = tps65910_set_bits(mfd,
+		ret = tps65910_reg_set_bits(mfd,
 				TPS65910_EN2_LDO_ASS + regoffs, bit_pos);
 	else
-		ret = tps65910_clear_bits(mfd,
+		ret = tps65910_reg_clear_bits(mfd,
 				TPS65910_EN2_LDO_ASS + regoffs, bit_pos);
 	if (ret < 0) {
 		dev_err(mfd->dev,
@@ -1022,10 +1017,10 @@ static int tps65910_set_ext_sleep_config(struct tps65910_reg *pmic,
 	if ((tps65910_chip_id(mfd) == TPS65910) &&
 			(id >= TPS65910_REG_VDIG1)) {
 		if (ext_sleep_config & TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3)
-			ret = tps65910_set_bits(mfd,
+			ret = tps65910_reg_set_bits(mfd,
 				TPS65910_EN3_LDO_ASS + regoffs, bit_pos);
 		else
-			ret = tps65910_clear_bits(mfd,
+			ret = tps65910_reg_clear_bits(mfd,
 				TPS65910_EN3_LDO_ASS + regoffs, bit_pos);
 		if (ret < 0) {
 			dev_err(mfd->dev,
@@ -1037,10 +1032,10 @@ static int tps65910_set_ext_sleep_config(struct tps65910_reg *pmic,
 	/* Return if no external control is selected */
 	if (!(ext_sleep_config & EXT_SLEEP_CONTROL)) {
 		/* Clear all sleep controls */
-		ret = tps65910_clear_bits(mfd,
+		ret = tps65910_reg_clear_bits(mfd,
 			TPS65910_SLEEP_KEEP_LDO_ON + regoffs, bit_pos);
 		if (!ret)
-			ret = tps65910_clear_bits(mfd,
+			ret = tps65910_reg_clear_bits(mfd,
 				TPS65910_SLEEP_SET_LDO_OFF + regoffs, bit_pos);
 		if (ret < 0)
 			dev_err(mfd->dev,
@@ -1059,32 +1054,33 @@ static int tps65910_set_ext_sleep_config(struct tps65910_reg *pmic,
 				(tps65910_chip_id(mfd) == TPS65911))) {
 		int op_reg_add = pmic->get_ctrl_reg(id) + 1;
 		int sr_reg_add = pmic->get_ctrl_reg(id) + 2;
-		int opvsel = tps65910_reg_read(pmic, op_reg_add);
-		int srvsel = tps65910_reg_read(pmic, sr_reg_add);
+		int opvsel = tps65910_reg_read_locked(pmic, op_reg_add);
+		int srvsel = tps65910_reg_read_locked(pmic, sr_reg_add);
 		if (opvsel & VDD1_OP_CMD_MASK) {
 			u8 reg_val = srvsel & VDD1_OP_SEL_MASK;
-			ret = tps65910_reg_write(pmic, op_reg_add, reg_val);
+			ret = tps65910_reg_write_locked(pmic, op_reg_add,
+							reg_val);
 			if (ret < 0) {
 				dev_err(mfd->dev,
 					"Error in configuring op register\n");
 				return ret;
 			}
 		}
-		ret = tps65910_reg_write(pmic, sr_reg_add, 0);
+		ret = tps65910_reg_write_locked(pmic, sr_reg_add, 0);
 		if (ret < 0) {
 			dev_err(mfd->dev, "Error in settting sr register\n");
 			return ret;
 		}
 	}
 
-	ret = tps65910_clear_bits(mfd,
+	ret = tps65910_reg_clear_bits(mfd,
 			TPS65910_SLEEP_KEEP_LDO_ON + regoffs, bit_pos);
 	if (!ret) {
 		if (ext_sleep_config & TPS65911_SLEEP_CONTROL_EXT_INPUT_SLEEP)
-			ret = tps65910_set_bits(mfd,
+			ret = tps65910_reg_set_bits(mfd,
 				TPS65910_SLEEP_SET_LDO_OFF + regoffs, bit_pos);
 		else
-			ret = tps65910_clear_bits(mfd,
+			ret = tps65910_reg_clear_bits(mfd,
 				TPS65910_SLEEP_SET_LDO_OFF + regoffs, bit_pos);
 	}
 	if (ret < 0)
@@ -1118,7 +1114,7 @@ static __devinit int tps65910_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, pmic);
 
 	/* Give control of all register to control port */
-	tps65910_set_bits(pmic->mfd, TPS65910_DEVCTRL,
+	tps65910_reg_set_bits(pmic->mfd, TPS65910_DEVCTRL,
 				DEVCTRL_SR_CTL_I2C_SEL_MASK);
 
 	switch(tps65910_chip_id(tps65910)) {
diff --git a/include/linux/mfd/tps65910.h b/include/linux/mfd/tps65910.h
index 1c6c286..e004de1 100644
--- a/include/linux/mfd/tps65910.h
+++ b/include/linux/mfd/tps65910.h
@@ -18,6 +18,7 @@
 #define __LINUX_MFD_TPS65910_H
 
 #include <linux/gpio.h>
+#include <linux/regmap.h>
 
 /* TPS chip id list */
 #define TPS65910			0
@@ -809,8 +810,6 @@ struct tps65910 {
 	struct regmap *regmap;
 	struct mutex io_mutex;
 	unsigned int id;
-	int (*read)(struct tps65910 *tps65910, u8 reg, int size, void *dest);
-	int (*write)(struct tps65910 *tps65910, u8 reg, int size, void *src);
 
 	/* Client devices */
 	struct tps65910_pmic *pmic;
@@ -833,8 +832,6 @@ struct tps65910_platform_data {
 	int irq_base;
 };
 
-int tps65910_set_bits(struct tps65910 *tps65910, u8 reg, u8 mask);
-int tps65910_clear_bits(struct tps65910 *tps65910, u8 reg, u8 mask);
 void tps65910_gpio_init(struct tps65910 *tps65910, int gpio_base);
 int tps65910_irq_init(struct tps65910 *tps65910, int irq,
 		struct tps65910_platform_data *pdata);
@@ -845,4 +842,28 @@ static inline int tps65910_chip_id(struct tps65910 *tps65910)
 	return tps65910->id;
 }
 
+static inline int tps65910_reg_read(struct tps65910 *tps65910, u8 reg,
+		unsigned int *val)
+{
+	return regmap_read(tps65910->regmap, reg, val);
+}
+
+static inline int tps65910_reg_write(struct tps65910 *tps65910, u8 reg,
+		unsigned int val)
+{
+	return regmap_write(tps65910->regmap, reg, val);
+}
+
+static inline int tps65910_reg_set_bits(struct tps65910 *tps65910, u8 reg,
+		u8 mask)
+{
+	return regmap_update_bits(tps65910->regmap, reg, mask, mask);
+}
+
+static inline int tps65910_reg_clear_bits(struct tps65910 *tps65910, u8 reg,
+		u8 mask)
+{
+	return regmap_update_bits(tps65910->regmap, reg, mask, 0);
+}
+
 #endif /*  __LINUX_MFD_TPS65910_H */
-- 
1.7.0.4


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 3/8 v2] mfd: tps65910: Commonize regmap access through header
@ 2012-04-24 23:36   ` Rhyland Klein
  0 siblings, 0 replies; 26+ messages in thread
From: Rhyland Klein @ 2012-04-24 23:36 UTC (permalink / raw)
  To: Mark Brown, Samuel Ortiz, Grant Likely, Rob Herring, Liam Girdwood
  Cc: linux-kernel, devicetree-discuss, Rhyland Klein

This change removes the read/write callback functions in favor of common
regmap accessors inside the header file. This change also makes use of
regmap_read/write for single register access which maps better onto what this
driver actually needs.

Signed-off-by: Rhyland Klein <rklein@nvidia.com>
---
 v2: implemented switching tps65910 drivers over to more directly accessing
     the regmap rather than going through utility functions.

 drivers/gpio/gpio-tps65910.c           |   14 +++---
 drivers/mfd/tps65910-irq.c             |   34 ++++++------
 drivers/mfd/tps65910.c                 |   26 ---------
 drivers/regulator/tps65910-regulator.c |   88 +++++++++++++++-----------------
 include/linux/mfd/tps65910.h           |   29 +++++++++--
 5 files changed, 91 insertions(+), 100 deletions(-)

diff --git a/drivers/gpio/gpio-tps65910.c b/drivers/gpio/gpio-tps65910.c
index 7eef648..bc155f2 100644
--- a/drivers/gpio/gpio-tps65910.c
+++ b/drivers/gpio/gpio-tps65910.c
@@ -23,9 +23,9 @@
 static int tps65910_gpio_get(struct gpio_chip *gc, unsigned offset)
 {
 	struct tps65910 *tps65910 = container_of(gc, struct tps65910, gpio);
-	uint8_t val;
+	unsigned int val;
 
-	tps65910->read(tps65910, TPS65910_GPIO0 + offset, 1, &val);
+	tps65910_reg_read(tps65910, TPS65910_GPIO0 + offset, &val);
 
 	if (val & GPIO_STS_MASK)
 		return 1;
@@ -39,10 +39,10 @@ static void tps65910_gpio_set(struct gpio_chip *gc, unsigned offset,
 	struct tps65910 *tps65910 = container_of(gc, struct tps65910, gpio);
 
 	if (value)
-		tps65910_set_bits(tps65910, TPS65910_GPIO0 + offset,
+		tps65910_reg_set_bits(tps65910, TPS65910_GPIO0 + offset,
 						GPIO_SET_MASK);
 	else
-		tps65910_clear_bits(tps65910, TPS65910_GPIO0 + offset,
+		tps65910_reg_clear_bits(tps65910, TPS65910_GPIO0 + offset,
 						GPIO_SET_MASK);
 }
 
@@ -54,7 +54,7 @@ static int tps65910_gpio_output(struct gpio_chip *gc, unsigned offset,
 	/* Set the initial value */
 	tps65910_gpio_set(gc, offset, value);
 
-	return tps65910_set_bits(tps65910, TPS65910_GPIO0 + offset,
+	return tps65910_reg_set_bits(tps65910, TPS65910_GPIO0 + offset,
 						GPIO_CFG_MASK);
 }
 
@@ -62,7 +62,7 @@ static int tps65910_gpio_input(struct gpio_chip *gc, unsigned offset)
 {
 	struct tps65910 *tps65910 = container_of(gc, struct tps65910, gpio);
 
-	return tps65910_clear_bits(tps65910, TPS65910_GPIO0 + offset,
+	return tps65910_reg_clear_bits(tps65910, TPS65910_GPIO0 + offset,
 						GPIO_CFG_MASK);
 }
 
@@ -102,7 +102,7 @@ void tps65910_gpio_init(struct tps65910 *tps65910, int gpio_base)
 		int i;
 		for (i = 0; i < tps65910->gpio.ngpio; ++i) {
 			if (board_data->en_gpio_sleep[i]) {
-				ret = tps65910_set_bits(tps65910,
+				ret = tps65910_reg_set_bits(tps65910,
 					TPS65910_GPIO0 + i, GPIO_SLEEP_MASK);
 				if (ret < 0)
 					dev_warn(tps65910->dev,
diff --git a/drivers/mfd/tps65910-irq.c b/drivers/mfd/tps65910-irq.c
index c9ed5c0..0f1ff7f 100644
--- a/drivers/mfd/tps65910-irq.c
+++ b/drivers/mfd/tps65910-irq.c
@@ -41,28 +41,28 @@ static inline int irq_to_tps65910_irq(struct tps65910 *tps65910,
 static irqreturn_t tps65910_irq(int irq, void *irq_data)
 {
 	struct tps65910 *tps65910 = irq_data;
+	unsigned int reg;
 	u32 irq_sts;
 	u32 irq_mask;
-	u8 reg;
 	int i;
 
-	tps65910->read(tps65910, TPS65910_INT_STS, 1, &reg);
+	tps65910_reg_read(tps65910, TPS65910_INT_STS, &reg);
 	irq_sts = reg;
-	tps65910->read(tps65910, TPS65910_INT_STS2, 1, &reg);
+	tps65910_reg_read(tps65910, TPS65910_INT_STS2, &reg);
 	irq_sts |= reg << 8;
 	switch (tps65910_chip_id(tps65910)) {
 	case TPS65911:
-		tps65910->read(tps65910, TPS65910_INT_STS3, 1, &reg);
+		tps65910_reg_read(tps65910, TPS65910_INT_STS3, &reg);
 		irq_sts |= reg << 16;
 	}
 
-	tps65910->read(tps65910, TPS65910_INT_MSK, 1, &reg);
+	tps65910_reg_read(tps65910, TPS65910_INT_MSK, &reg);
 	irq_mask = reg;
-	tps65910->read(tps65910, TPS65910_INT_MSK2, 1, &reg);
+	tps65910_reg_read(tps65910, TPS65910_INT_MSK2, &reg);
 	irq_mask |= reg << 8;
 	switch (tps65910_chip_id(tps65910)) {
 	case TPS65911:
-		tps65910->read(tps65910, TPS65910_INT_MSK3, 1, &reg);
+		tps65910_reg_read(tps65910, TPS65910_INT_MSK3, &reg);
 		irq_mask |= reg << 16;
 	}
 
@@ -82,13 +82,13 @@ static irqreturn_t tps65910_irq(int irq, void *irq_data)
 	/* Write the STS register back to clear IRQs we handled */
 	reg = irq_sts & 0xFF;
 	irq_sts >>= 8;
-	tps65910->write(tps65910, TPS65910_INT_STS, 1, &reg);
+	tps65910_reg_write(tps65910, TPS65910_INT_STS, reg);
 	reg = irq_sts & 0xFF;
-	tps65910->write(tps65910, TPS65910_INT_STS2, 1, &reg);
+	tps65910_reg_write(tps65910, TPS65910_INT_STS2, reg);
 	switch (tps65910_chip_id(tps65910)) {
 	case TPS65911:
 		reg = irq_sts >> 8;
-		tps65910->write(tps65910, TPS65910_INT_STS3, 1, &reg);
+		tps65910_reg_write(tps65910, TPS65910_INT_STS3, reg);
 	}
 
 	return IRQ_HANDLED;
@@ -105,27 +105,27 @@ static void tps65910_irq_sync_unlock(struct irq_data *data)
 {
 	struct tps65910 *tps65910 = irq_data_get_irq_chip_data(data);
 	u32 reg_mask;
-	u8 reg;
+	unsigned int reg;
 
-	tps65910->read(tps65910, TPS65910_INT_MSK, 1, &reg);
+	tps65910_reg_read(tps65910, TPS65910_INT_MSK, &reg);
 	reg_mask = reg;
-	tps65910->read(tps65910, TPS65910_INT_MSK2, 1, &reg);
+	tps65910_reg_read(tps65910, TPS65910_INT_MSK2, &reg);
 	reg_mask |= reg << 8;
 	switch (tps65910_chip_id(tps65910)) {
 	case TPS65911:
-		tps65910->read(tps65910, TPS65910_INT_MSK3, 1, &reg);
+		tps65910_reg_read(tps65910, TPS65910_INT_MSK3, &reg);
 		reg_mask |= reg << 16;
 	}
 
 	if (tps65910->irq_mask != reg_mask) {
 		reg = tps65910->irq_mask & 0xFF;
-		tps65910->write(tps65910, TPS65910_INT_MSK, 1, &reg);
+		tps65910_reg_write(tps65910, TPS65910_INT_MSK, reg);
 		reg = tps65910->irq_mask >> 8 & 0xFF;
-		tps65910->write(tps65910, TPS65910_INT_MSK2, 1, &reg);
+		tps65910_reg_write(tps65910, TPS65910_INT_MSK2, reg);
 		switch (tps65910_chip_id(tps65910)) {
 		case TPS65911:
 			reg = tps65910->irq_mask >> 16;
-			tps65910->write(tps65910, TPS65910_INT_MSK3, 1, &reg);
+			tps65910_reg_write(tps65910, TPS65910_INT_MSK3, reg);
 		}
 	}
 	mutex_unlock(&tps65910->irq_lock);
diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
index bf2b25e..70a8079 100644
--- a/drivers/mfd/tps65910.c
+++ b/drivers/mfd/tps65910.c
@@ -37,30 +37,6 @@ static struct mfd_cell tps65910s[] = {
 };
 
 
-static int tps65910_i2c_read(struct tps65910 *tps65910, u8 reg,
-				  int bytes, void *dest)
-{
-	return regmap_bulk_read(tps65910->regmap, reg, dest, bytes);
-}
-
-static int tps65910_i2c_write(struct tps65910 *tps65910, u8 reg,
-				  int bytes, void *src)
-{
-	return regmap_bulk_write(tps65910->regmap, reg, src, bytes);
-}
-
-int tps65910_set_bits(struct tps65910 *tps65910, u8 reg, u8 mask)
-{
-	return regmap_update_bits(tps65910->regmap, reg, mask, mask);
-}
-EXPORT_SYMBOL_GPL(tps65910_set_bits);
-
-int tps65910_clear_bits(struct tps65910 *tps65910, u8 reg, u8 mask)
-{
-	return regmap_update_bits(tps65910->regmap, reg, mask, 0);
-}
-EXPORT_SYMBOL_GPL(tps65910_clear_bits);
-
 static bool is_volatile_reg(struct device *dev, unsigned int reg)
 {
 	struct tps65910 *tps65910 = dev_get_drvdata(dev);
@@ -116,8 +92,6 @@ static int tps65910_i2c_probe(struct i2c_client *i2c,
 	tps65910->dev = &i2c->dev;
 	tps65910->i2c_client = i2c;
 	tps65910->id = id->driver_data;
-	tps65910->read = tps65910_i2c_read;
-	tps65910->write = tps65910_i2c_write;
 	mutex_init(&tps65910->io_mutex);
 
 	tps65910->regmap = regmap_init_i2c(i2c, &tps65910_regmap_config);
diff --git a/drivers/regulator/tps65910-regulator.c b/drivers/regulator/tps65910-regulator.c
index 747bf57..855bbec 100644
--- a/drivers/regulator/tps65910-regulator.c
+++ b/drivers/regulator/tps65910-regulator.c
@@ -331,21 +331,16 @@ struct tps65910_reg {
 
 static inline int tps65910_read(struct tps65910_reg *pmic, u8 reg)
 {
-	u8 val;
+	unsigned int val;
 	int err;
 
-	err = pmic->mfd->read(pmic->mfd, reg, 1, &val);
+	err = tps65910_reg_read(pmic->mfd, reg, &val);
 	if (err)
 		return err;
 
 	return val;
 }
 
-static inline int tps65910_write(struct tps65910_reg *pmic, u8 reg, u8 val)
-{
-	return pmic->mfd->write(pmic->mfd, reg, 1, &val);
-}
-
 static int tps65910_modify_bits(struct tps65910_reg *pmic, u8 reg,
 					u8 set_mask, u8 clear_mask)
 {
@@ -362,7 +357,7 @@ static int tps65910_modify_bits(struct tps65910_reg *pmic, u8 reg,
 
 	data &= ~clear_mask;
 	data |= set_mask;
-	err = tps65910_write(pmic, reg, data);
+	err = tps65910_reg_write(pmic->mfd, reg, data);
 	if (err)
 		dev_err(pmic->mfd->dev, "Write for reg 0x%x failed\n", reg);
 
@@ -371,7 +366,7 @@ out:
 	return err;
 }
 
-static int tps65910_reg_read(struct tps65910_reg *pmic, u8 reg)
+static int tps65910_reg_read_locked(struct tps65910_reg *pmic, u8 reg)
 {
 	int data;
 
@@ -385,13 +380,13 @@ static int tps65910_reg_read(struct tps65910_reg *pmic, u8 reg)
 	return data;
 }
 
-static int tps65910_reg_write(struct tps65910_reg *pmic, u8 reg, u8 val)
+static int tps65910_reg_write_locked(struct tps65910_reg *pmic, u8 reg, u8 val)
 {
 	int err;
 
 	mutex_lock(&pmic->mutex);
 
-	err = tps65910_write(pmic, reg, val);
+	err = tps65910_reg_write(pmic->mfd, reg, val);
 	if (err < 0)
 		dev_err(pmic->mfd->dev, "Write for reg 0x%x failed\n", reg);
 
@@ -476,7 +471,7 @@ static int tps65910_is_enabled(struct regulator_dev *dev)
 	if (reg < 0)
 		return reg;
 
-	value = tps65910_reg_read(pmic, reg);
+	value = tps65910_reg_read_locked(pmic, reg);
 	if (value < 0)
 		return value;
 
@@ -493,7 +488,7 @@ static int tps65910_enable(struct regulator_dev *dev)
 	if (reg < 0)
 		return reg;
 
-	return tps65910_set_bits(mfd, reg, TPS65910_SUPPLY_STATE_ENABLED);
+	return tps65910_reg_set_bits(mfd, reg, TPS65910_SUPPLY_STATE_ENABLED);
 }
 
 static int tps65910_disable(struct regulator_dev *dev)
@@ -506,7 +501,7 @@ static int tps65910_disable(struct regulator_dev *dev)
 	if (reg < 0)
 		return reg;
 
-	return tps65910_clear_bits(mfd, reg, TPS65910_SUPPLY_STATE_ENABLED);
+	return tps65910_reg_clear_bits(mfd, reg, TPS65910_SUPPLY_STATE_ENABLED);
 }
 
 static int tps65910_enable_time(struct regulator_dev *dev)
@@ -532,9 +527,9 @@ static int tps65910_set_mode(struct regulator_dev *dev, unsigned int mode)
 							LDO_ST_MODE_BIT);
 	case REGULATOR_MODE_IDLE:
 		value = LDO_ST_ON_BIT | LDO_ST_MODE_BIT;
-		return tps65910_set_bits(mfd, reg, value);
+		return tps65910_reg_set_bits(mfd, reg, value);
 	case REGULATOR_MODE_STANDBY:
-		return tps65910_clear_bits(mfd, reg, LDO_ST_ON_BIT);
+		return tps65910_reg_clear_bits(mfd, reg, LDO_ST_ON_BIT);
 	}
 
 	return -EINVAL;
@@ -549,7 +544,7 @@ static unsigned int tps65910_get_mode(struct regulator_dev *dev)
 	if (reg < 0)
 		return reg;
 
-	value = tps65910_reg_read(pmic, reg);
+	value = tps65910_reg_read_locked(pmic, reg);
 	if (value < 0)
 		return value;
 
@@ -569,28 +564,28 @@ static int tps65910_get_voltage_dcdc_sel(struct regulator_dev *dev)
 
 	switch (id) {
 	case TPS65910_REG_VDD1:
-		opvsel = tps65910_reg_read(pmic, TPS65910_VDD1_OP);
-		mult = tps65910_reg_read(pmic, TPS65910_VDD1);
+		opvsel = tps65910_reg_read_locked(pmic, TPS65910_VDD1_OP);
+		mult = tps65910_reg_read_locked(pmic, TPS65910_VDD1);
 		mult = (mult & VDD1_VGAIN_SEL_MASK) >> VDD1_VGAIN_SEL_SHIFT;
-		srvsel = tps65910_reg_read(pmic, TPS65910_VDD1_SR);
+		srvsel = tps65910_reg_read_locked(pmic, TPS65910_VDD1_SR);
 		sr = opvsel & VDD1_OP_CMD_MASK;
 		opvsel &= VDD1_OP_SEL_MASK;
 		srvsel &= VDD1_SR_SEL_MASK;
 		vselmax = 75;
 		break;
 	case TPS65910_REG_VDD2:
-		opvsel = tps65910_reg_read(pmic, TPS65910_VDD2_OP);
-		mult = tps65910_reg_read(pmic, TPS65910_VDD2);
+		opvsel = tps65910_reg_read_locked(pmic, TPS65910_VDD2_OP);
+		mult = tps65910_reg_read_locked(pmic, TPS65910_VDD2);
 		mult = (mult & VDD2_VGAIN_SEL_MASK) >> VDD2_VGAIN_SEL_SHIFT;
-		srvsel = tps65910_reg_read(pmic, TPS65910_VDD2_SR);
+		srvsel = tps65910_reg_read_locked(pmic, TPS65910_VDD2_SR);
 		sr = opvsel & VDD2_OP_CMD_MASK;
 		opvsel &= VDD2_OP_SEL_MASK;
 		srvsel &= VDD2_SR_SEL_MASK;
 		vselmax = 75;
 		break;
 	case TPS65911_REG_VDDCTRL:
-		opvsel = tps65910_reg_read(pmic, TPS65911_VDDCTRL_OP);
-		srvsel = tps65910_reg_read(pmic, TPS65911_VDDCTRL_SR);
+		opvsel = tps65910_reg_read_locked(pmic, TPS65911_VDDCTRL_OP);
+		srvsel = tps65910_reg_read_locked(pmic, TPS65911_VDDCTRL_SR);
 		sr = opvsel & VDDCTRL_OP_CMD_MASK;
 		opvsel &= VDDCTRL_OP_SEL_MASK;
 		srvsel &= VDDCTRL_SR_SEL_MASK;
@@ -630,7 +625,7 @@ static int tps65910_get_voltage(struct regulator_dev *dev)
 	if (reg < 0)
 		return reg;
 
-	value = tps65910_reg_read(pmic, reg);
+	value = tps65910_reg_read_locked(pmic, reg);
 	if (value < 0)
 		return value;
 
@@ -669,7 +664,7 @@ static int tps65911_get_voltage(struct regulator_dev *dev)
 
 	reg = pmic->get_ctrl_reg(id);
 
-	value = tps65910_reg_read(pmic, reg);
+	value = tps65910_reg_read_locked(pmic, reg);
 
 	switch (id) {
 	case TPS65911_REG_LDO1:
@@ -728,7 +723,7 @@ static int tps65910_set_voltage_dcdc_sel(struct regulator_dev *dev,
 		tps65910_modify_bits(pmic, TPS65910_VDD1,
 				(dcdc_mult << VDD1_VGAIN_SEL_SHIFT),
 						VDD1_VGAIN_SEL_MASK);
-		tps65910_reg_write(pmic, TPS65910_VDD1_OP, vsel);
+		tps65910_reg_write_locked(pmic, TPS65910_VDD1_OP, vsel);
 		break;
 	case TPS65910_REG_VDD2:
 		dcdc_mult = (selector / VDD1_2_NUM_VOLT_FINE) + 1;
@@ -739,11 +734,11 @@ static int tps65910_set_voltage_dcdc_sel(struct regulator_dev *dev,
 		tps65910_modify_bits(pmic, TPS65910_VDD2,
 				(dcdc_mult << VDD2_VGAIN_SEL_SHIFT),
 						VDD1_VGAIN_SEL_MASK);
-		tps65910_reg_write(pmic, TPS65910_VDD2_OP, vsel);
+		tps65910_reg_write_locked(pmic, TPS65910_VDD2_OP, vsel);
 		break;
 	case TPS65911_REG_VDDCTRL:
 		vsel = selector + 3;
-		tps65910_reg_write(pmic, TPS65911_VDDCTRL_OP, vsel);
+		tps65910_reg_write_locked(pmic, TPS65911_VDDCTRL_OP, vsel);
 	}
 
 	return 0;
@@ -994,10 +989,10 @@ static int tps65910_set_ext_sleep_config(struct tps65910_reg *pmic,
 
 	/* External EN1 control */
 	if (ext_sleep_config & TPS65910_SLEEP_CONTROL_EXT_INPUT_EN1)
-		ret = tps65910_set_bits(mfd,
+		ret = tps65910_reg_set_bits(mfd,
 				TPS65910_EN1_LDO_ASS + regoffs, bit_pos);
 	else
-		ret = tps65910_clear_bits(mfd,
+		ret = tps65910_reg_clear_bits(mfd,
 				TPS65910_EN1_LDO_ASS + regoffs, bit_pos);
 	if (ret < 0) {
 		dev_err(mfd->dev,
@@ -1007,10 +1002,10 @@ static int tps65910_set_ext_sleep_config(struct tps65910_reg *pmic,
 
 	/* External EN2 control */
 	if (ext_sleep_config & TPS65910_SLEEP_CONTROL_EXT_INPUT_EN2)
-		ret = tps65910_set_bits(mfd,
+		ret = tps65910_reg_set_bits(mfd,
 				TPS65910_EN2_LDO_ASS + regoffs, bit_pos);
 	else
-		ret = tps65910_clear_bits(mfd,
+		ret = tps65910_reg_clear_bits(mfd,
 				TPS65910_EN2_LDO_ASS + regoffs, bit_pos);
 	if (ret < 0) {
 		dev_err(mfd->dev,
@@ -1022,10 +1017,10 @@ static int tps65910_set_ext_sleep_config(struct tps65910_reg *pmic,
 	if ((tps65910_chip_id(mfd) == TPS65910) &&
 			(id >= TPS65910_REG_VDIG1)) {
 		if (ext_sleep_config & TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3)
-			ret = tps65910_set_bits(mfd,
+			ret = tps65910_reg_set_bits(mfd,
 				TPS65910_EN3_LDO_ASS + regoffs, bit_pos);
 		else
-			ret = tps65910_clear_bits(mfd,
+			ret = tps65910_reg_clear_bits(mfd,
 				TPS65910_EN3_LDO_ASS + regoffs, bit_pos);
 		if (ret < 0) {
 			dev_err(mfd->dev,
@@ -1037,10 +1032,10 @@ static int tps65910_set_ext_sleep_config(struct tps65910_reg *pmic,
 	/* Return if no external control is selected */
 	if (!(ext_sleep_config & EXT_SLEEP_CONTROL)) {
 		/* Clear all sleep controls */
-		ret = tps65910_clear_bits(mfd,
+		ret = tps65910_reg_clear_bits(mfd,
 			TPS65910_SLEEP_KEEP_LDO_ON + regoffs, bit_pos);
 		if (!ret)
-			ret = tps65910_clear_bits(mfd,
+			ret = tps65910_reg_clear_bits(mfd,
 				TPS65910_SLEEP_SET_LDO_OFF + regoffs, bit_pos);
 		if (ret < 0)
 			dev_err(mfd->dev,
@@ -1059,32 +1054,33 @@ static int tps65910_set_ext_sleep_config(struct tps65910_reg *pmic,
 				(tps65910_chip_id(mfd) == TPS65911))) {
 		int op_reg_add = pmic->get_ctrl_reg(id) + 1;
 		int sr_reg_add = pmic->get_ctrl_reg(id) + 2;
-		int opvsel = tps65910_reg_read(pmic, op_reg_add);
-		int srvsel = tps65910_reg_read(pmic, sr_reg_add);
+		int opvsel = tps65910_reg_read_locked(pmic, op_reg_add);
+		int srvsel = tps65910_reg_read_locked(pmic, sr_reg_add);
 		if (opvsel & VDD1_OP_CMD_MASK) {
 			u8 reg_val = srvsel & VDD1_OP_SEL_MASK;
-			ret = tps65910_reg_write(pmic, op_reg_add, reg_val);
+			ret = tps65910_reg_write_locked(pmic, op_reg_add,
+							reg_val);
 			if (ret < 0) {
 				dev_err(mfd->dev,
 					"Error in configuring op register\n");
 				return ret;
 			}
 		}
-		ret = tps65910_reg_write(pmic, sr_reg_add, 0);
+		ret = tps65910_reg_write_locked(pmic, sr_reg_add, 0);
 		if (ret < 0) {
 			dev_err(mfd->dev, "Error in settting sr register\n");
 			return ret;
 		}
 	}
 
-	ret = tps65910_clear_bits(mfd,
+	ret = tps65910_reg_clear_bits(mfd,
 			TPS65910_SLEEP_KEEP_LDO_ON + regoffs, bit_pos);
 	if (!ret) {
 		if (ext_sleep_config & TPS65911_SLEEP_CONTROL_EXT_INPUT_SLEEP)
-			ret = tps65910_set_bits(mfd,
+			ret = tps65910_reg_set_bits(mfd,
 				TPS65910_SLEEP_SET_LDO_OFF + regoffs, bit_pos);
 		else
-			ret = tps65910_clear_bits(mfd,
+			ret = tps65910_reg_clear_bits(mfd,
 				TPS65910_SLEEP_SET_LDO_OFF + regoffs, bit_pos);
 	}
 	if (ret < 0)
@@ -1118,7 +1114,7 @@ static __devinit int tps65910_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, pmic);
 
 	/* Give control of all register to control port */
-	tps65910_set_bits(pmic->mfd, TPS65910_DEVCTRL,
+	tps65910_reg_set_bits(pmic->mfd, TPS65910_DEVCTRL,
 				DEVCTRL_SR_CTL_I2C_SEL_MASK);
 
 	switch(tps65910_chip_id(tps65910)) {
diff --git a/include/linux/mfd/tps65910.h b/include/linux/mfd/tps65910.h
index 1c6c286..e004de1 100644
--- a/include/linux/mfd/tps65910.h
+++ b/include/linux/mfd/tps65910.h
@@ -18,6 +18,7 @@
 #define __LINUX_MFD_TPS65910_H
 
 #include <linux/gpio.h>
+#include <linux/regmap.h>
 
 /* TPS chip id list */
 #define TPS65910			0
@@ -809,8 +810,6 @@ struct tps65910 {
 	struct regmap *regmap;
 	struct mutex io_mutex;
 	unsigned int id;
-	int (*read)(struct tps65910 *tps65910, u8 reg, int size, void *dest);
-	int (*write)(struct tps65910 *tps65910, u8 reg, int size, void *src);
 
 	/* Client devices */
 	struct tps65910_pmic *pmic;
@@ -833,8 +832,6 @@ struct tps65910_platform_data {
 	int irq_base;
 };
 
-int tps65910_set_bits(struct tps65910 *tps65910, u8 reg, u8 mask);
-int tps65910_clear_bits(struct tps65910 *tps65910, u8 reg, u8 mask);
 void tps65910_gpio_init(struct tps65910 *tps65910, int gpio_base);
 int tps65910_irq_init(struct tps65910 *tps65910, int irq,
 		struct tps65910_platform_data *pdata);
@@ -845,4 +842,28 @@ static inline int tps65910_chip_id(struct tps65910 *tps65910)
 	return tps65910->id;
 }
 
+static inline int tps65910_reg_read(struct tps65910 *tps65910, u8 reg,
+		unsigned int *val)
+{
+	return regmap_read(tps65910->regmap, reg, val);
+}
+
+static inline int tps65910_reg_write(struct tps65910 *tps65910, u8 reg,
+		unsigned int val)
+{
+	return regmap_write(tps65910->regmap, reg, val);
+}
+
+static inline int tps65910_reg_set_bits(struct tps65910 *tps65910, u8 reg,
+		u8 mask)
+{
+	return regmap_update_bits(tps65910->regmap, reg, mask, mask);
+}
+
+static inline int tps65910_reg_clear_bits(struct tps65910 *tps65910, u8 reg,
+		u8 mask)
+{
+	return regmap_update_bits(tps65910->regmap, reg, mask, 0);
+}
+
 #endif /*  __LINUX_MFD_TPS65910_H */
-- 
1.7.0.4

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 4/8 v2] regulator: tps65910: Add device tree bindings
  2012-04-24 23:36 ` Rhyland Klein
@ 2012-04-24 23:36   ` Rhyland Klein
  -1 siblings, 0 replies; 26+ messages in thread
From: Rhyland Klein @ 2012-04-24 23:36 UTC (permalink / raw)
  To: Mark Brown, Samuel Ortiz, Grant Likely, Rob Herring, Liam Girdwood
  Cc: linux-kernel, devicetree-discuss, Rhyland Klein

Add device tree bindings for TI's tps65910 pmic.

Signed-off-by: Rhyland Klein <rklein@nvidia.com>
---
 v2: Moved ext-sleep-control into regulator nodes

 Documentation/devicetree/bindings/mfd/tps65910.txt |  133 ++++++++++++++++++++
 1 files changed, 133 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/mfd/tps65910.txt

diff --git a/Documentation/devicetree/bindings/mfd/tps65910.txt b/Documentation/devicetree/bindings/mfd/tps65910.txt
new file mode 100644
index 0000000..645f5ea
--- /dev/null
+++ b/Documentation/devicetree/bindings/mfd/tps65910.txt
@@ -0,0 +1,133 @@
+TPS65910 Power Management Integrated Circuit
+
+Required properties:
+- compatible: "ti,tps65910" or "ti,tps65911"
+- reg: I2C slave address
+- interrupts: the interrupt outputs of the controller
+- #gpio-cells: number of cells to describe a GPIO, this should be 2.
+  The first cell is the GPIO number.
+  The second cell is used to specify additional options <unused>.
+- gpio-controller: mark the device as a GPIO controller
+- #interrupt-cells: the number of cells to describe an IRQ, this should be 2.
+  The first cell is the IRQ number.
+  The second cell is the flags, encoded as the trigger masks from
+  Documentation/devicetree/bindings/interrupts.txt
+- regulators: This is the list of child nodes that specify the regulator
+  initialization data for defined regulators. Not all regulators for the given
+  device need to be present. The definition for each of these nodes is defined
+  using the standard binding for regulators found at
+  Documentation/devicetree/bindings/regulator/regulator.txt.
+
+  The valid names for regulators are:
+  tps65910: vrtc, vio, vdd1, vdd2, vdd3, vdig1, vdig2, vpll, vdac, vaux1,
+            vaux2, vaux33, vmmc
+  tps65911: vrtc, vio, vdd1, vdd3, vddctrl, ldo1, ldo2, ldo3, ldo4, ldo5,
+            ldo6, ldo7, ldo8
+
+Optional properties:
+- ti,vmbch-threshold: (tps65911) main battery charged threshold
+  comparator. (see VMBCH_VSEL in TPS65910 datasheet)
+- ti,vmbch2-threshold: (tps65911) main battery discharged threshold
+  comparator. (see VMBCH_VSEL in TPS65910 datasheet)
+- ti,en-gpio-sleep: enable sleep control for gpios
+  There should be 9 entries here, one for each gpio.
+
+Regulator Optional properties:
+- ti,regulator-ext-sleep-control: enable external sleep
+  control through external inputs [0 (not enabled), 1 (EN1), 2 (EN2) or 4(EN3)]
+  If this property is not defined, it defaults to 0 (not enabled).
+
+Example:
+
+	pmu: tps65910@d2 {
+		compatible = "ti,tps65910";
+		reg = <0xd2>;
+		interrupt-parent = <&intc>;
+		interrupts = < 0 118 0x04 >;
+
+		#gpio-cells = <2>;
+		gpio-controller;
+
+		#interrupt-cells = <2>;
+		interrupt-controller;
+
+		ti,vmbch-threshold = 0;
+		ti,vmbch2-threshold = 0;
+
+		ti,en-gpio-sleep = <0 0 1 0 0 0 0 0 0>;
+
+		regulators {
+			vdd1_reg: vdd1 {
+				regulator-min-microvolt = < 600000>;
+				regulator-max-microvolt = <1500000>;
+				regulator-always-on;
+				regulator-boot-on;
+				ti,regulator-ext-sleep-control = <0>;
+			};
+			vdd2_reg: vdd2 {
+				regulator-min-microvolt = < 600000>;
+				regulator-max-microvolt = <1500000>;
+				regulator-always-on;
+				regulator-boot-on;
+				ti,regulator-ext-sleep-control = <4>;
+			};
+			vddctrl_reg: vddctrl {
+				regulator-min-microvolt = < 600000>;
+				regulator-max-microvolt = <1400000>;
+				regulator-always-on;
+				regulator-boot-on;
+				ti,regulator-ext-sleep-control = <0>;
+			};
+			vio_reg: vio {
+				regulator-min-microvolt = <1500000>;
+				regulator-max-microvolt = <1800000>;
+				regulator-always-on;
+				regulator-boot-on;
+				ti,regulator-ext-sleep-control = <1>;
+			};
+			ldo1_reg: ldo1 {
+				regulator-min-microvolt = <1000000>;
+				regulator-max-microvolt = <3300000>;
+				ti,regulator-ext-sleep-control = <0>;
+			};
+			ldo2_reg: ldo2 {
+				regulator-min-microvolt = <1050000>;
+				regulator-max-microvolt = <1050000>;
+				ti,regulator-ext-sleep-control = <0>;
+			};
+			ldo3_reg: ldo3 {
+				regulator-min-microvolt = <1000000>;
+				regulator-max-microvolt = <3300000>;
+				ti,regulator-ext-sleep-control = <0>;
+			};
+			ldo4_reg: ldo4 {
+				regulator-min-microvolt = <1000000>;
+				regulator-max-microvolt = <3300000>;
+				regulator-always-on;
+				ti,regulator-ext-sleep-control = <0>;
+			};
+			ldo5_reg: ldo5 {
+				regulator-min-microvolt = <1000000>;
+				regulator-max-microvolt = <3300000>;
+				ti,regulator-ext-sleep-control = <0>;
+			};
+			ldo6_reg: ldo6 {
+				regulator-min-microvolt = <1200000>;
+				regulator-max-microvolt = <1200000>;
+				ti,regulator-ext-sleep-control = <0>;
+			};
+			ldo7_reg: ldo7 {
+				regulator-min-microvolt = <1200000>;
+				regulator-max-microvolt = <1200000>;
+				regulator-always-on;
+				regulator-boot-on;
+				ti,regulator-ext-sleep-control = <1>;
+			};
+			ldo8_reg: ldo8 {
+				regulator-min-microvolt = <1000000>;
+				regulator-max-microvolt = <3300000>;
+				regulator-always-on;
+				ti,regulator-ext-sleep-control = <1>;
+			};
+		};
+	};
-- 
1.7.0.4


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 4/8 v2] regulator: tps65910: Add device tree bindings
@ 2012-04-24 23:36   ` Rhyland Klein
  0 siblings, 0 replies; 26+ messages in thread
From: Rhyland Klein @ 2012-04-24 23:36 UTC (permalink / raw)
  To: Mark Brown, Samuel Ortiz, Grant Likely, Rob Herring, Liam Girdwood
  Cc: linux-kernel, devicetree-discuss, Rhyland Klein

Add device tree bindings for TI's tps65910 pmic.

Signed-off-by: Rhyland Klein <rklein@nvidia.com>
---
 v2: Moved ext-sleep-control into regulator nodes

 Documentation/devicetree/bindings/mfd/tps65910.txt |  133 ++++++++++++++++++++
 1 files changed, 133 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/mfd/tps65910.txt

diff --git a/Documentation/devicetree/bindings/mfd/tps65910.txt b/Documentation/devicetree/bindings/mfd/tps65910.txt
new file mode 100644
index 0000000..645f5ea
--- /dev/null
+++ b/Documentation/devicetree/bindings/mfd/tps65910.txt
@@ -0,0 +1,133 @@
+TPS65910 Power Management Integrated Circuit
+
+Required properties:
+- compatible: "ti,tps65910" or "ti,tps65911"
+- reg: I2C slave address
+- interrupts: the interrupt outputs of the controller
+- #gpio-cells: number of cells to describe a GPIO, this should be 2.
+  The first cell is the GPIO number.
+  The second cell is used to specify additional options <unused>.
+- gpio-controller: mark the device as a GPIO controller
+- #interrupt-cells: the number of cells to describe an IRQ, this should be 2.
+  The first cell is the IRQ number.
+  The second cell is the flags, encoded as the trigger masks from
+  Documentation/devicetree/bindings/interrupts.txt
+- regulators: This is the list of child nodes that specify the regulator
+  initialization data for defined regulators. Not all regulators for the given
+  device need to be present. The definition for each of these nodes is defined
+  using the standard binding for regulators found at
+  Documentation/devicetree/bindings/regulator/regulator.txt.
+
+  The valid names for regulators are:
+  tps65910: vrtc, vio, vdd1, vdd2, vdd3, vdig1, vdig2, vpll, vdac, vaux1,
+            vaux2, vaux33, vmmc
+  tps65911: vrtc, vio, vdd1, vdd3, vddctrl, ldo1, ldo2, ldo3, ldo4, ldo5,
+            ldo6, ldo7, ldo8
+
+Optional properties:
+- ti,vmbch-threshold: (tps65911) main battery charged threshold
+  comparator. (see VMBCH_VSEL in TPS65910 datasheet)
+- ti,vmbch2-threshold: (tps65911) main battery discharged threshold
+  comparator. (see VMBCH_VSEL in TPS65910 datasheet)
+- ti,en-gpio-sleep: enable sleep control for gpios
+  There should be 9 entries here, one for each gpio.
+
+Regulator Optional properties:
+- ti,regulator-ext-sleep-control: enable external sleep
+  control through external inputs [0 (not enabled), 1 (EN1), 2 (EN2) or 4(EN3)]
+  If this property is not defined, it defaults to 0 (not enabled).
+
+Example:
+
+	pmu: tps65910@d2 {
+		compatible = "ti,tps65910";
+		reg = <0xd2>;
+		interrupt-parent = <&intc>;
+		interrupts = < 0 118 0x04 >;
+
+		#gpio-cells = <2>;
+		gpio-controller;
+
+		#interrupt-cells = <2>;
+		interrupt-controller;
+
+		ti,vmbch-threshold = 0;
+		ti,vmbch2-threshold = 0;
+
+		ti,en-gpio-sleep = <0 0 1 0 0 0 0 0 0>;
+
+		regulators {
+			vdd1_reg: vdd1 {
+				regulator-min-microvolt = < 600000>;
+				regulator-max-microvolt = <1500000>;
+				regulator-always-on;
+				regulator-boot-on;
+				ti,regulator-ext-sleep-control = <0>;
+			};
+			vdd2_reg: vdd2 {
+				regulator-min-microvolt = < 600000>;
+				regulator-max-microvolt = <1500000>;
+				regulator-always-on;
+				regulator-boot-on;
+				ti,regulator-ext-sleep-control = <4>;
+			};
+			vddctrl_reg: vddctrl {
+				regulator-min-microvolt = < 600000>;
+				regulator-max-microvolt = <1400000>;
+				regulator-always-on;
+				regulator-boot-on;
+				ti,regulator-ext-sleep-control = <0>;
+			};
+			vio_reg: vio {
+				regulator-min-microvolt = <1500000>;
+				regulator-max-microvolt = <1800000>;
+				regulator-always-on;
+				regulator-boot-on;
+				ti,regulator-ext-sleep-control = <1>;
+			};
+			ldo1_reg: ldo1 {
+				regulator-min-microvolt = <1000000>;
+				regulator-max-microvolt = <3300000>;
+				ti,regulator-ext-sleep-control = <0>;
+			};
+			ldo2_reg: ldo2 {
+				regulator-min-microvolt = <1050000>;
+				regulator-max-microvolt = <1050000>;
+				ti,regulator-ext-sleep-control = <0>;
+			};
+			ldo3_reg: ldo3 {
+				regulator-min-microvolt = <1000000>;
+				regulator-max-microvolt = <3300000>;
+				ti,regulator-ext-sleep-control = <0>;
+			};
+			ldo4_reg: ldo4 {
+				regulator-min-microvolt = <1000000>;
+				regulator-max-microvolt = <3300000>;
+				regulator-always-on;
+				ti,regulator-ext-sleep-control = <0>;
+			};
+			ldo5_reg: ldo5 {
+				regulator-min-microvolt = <1000000>;
+				regulator-max-microvolt = <3300000>;
+				ti,regulator-ext-sleep-control = <0>;
+			};
+			ldo6_reg: ldo6 {
+				regulator-min-microvolt = <1200000>;
+				regulator-max-microvolt = <1200000>;
+				ti,regulator-ext-sleep-control = <0>;
+			};
+			ldo7_reg: ldo7 {
+				regulator-min-microvolt = <1200000>;
+				regulator-max-microvolt = <1200000>;
+				regulator-always-on;
+				regulator-boot-on;
+				ti,regulator-ext-sleep-control = <1>;
+			};
+			ldo8_reg: ldo8 {
+				regulator-min-microvolt = <1000000>;
+				regulator-max-microvolt = <3300000>;
+				regulator-always-on;
+				ti,regulator-ext-sleep-control = <1>;
+			};
+		};
+	};
-- 
1.7.0.4

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 5/8 v2] mfd: tps65910: Add device-tree support
  2012-04-24 23:36 ` Rhyland Klein
@ 2012-04-24 23:36   ` Rhyland Klein
  -1 siblings, 0 replies; 26+ messages in thread
From: Rhyland Klein @ 2012-04-24 23:36 UTC (permalink / raw)
  To: Mark Brown, Samuel Ortiz, Grant Likely, Rob Herring, Liam Girdwood
  Cc: linux-kernel, devicetree-discuss, Rhyland Klein

Add device tree based initialization support for TI's tps65910 pmic.

Signed-off-by: Rhyland Klein <rklein@nvidia.com>
---
 v2: split mfd portion into single change to add dt support
     added of_node to config before calling regulator_register
     removed passing pdata to mfd_cell child devices
     removed use_dt_for_init_data flag

 drivers/mfd/tps65910.c |   81 +++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 80 insertions(+), 1 deletions(-)

diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
index 70a8079..248fe9f 100644
--- a/drivers/mfd/tps65910.c
+++ b/drivers/mfd/tps65910.c
@@ -23,6 +23,7 @@
 #include <linux/mfd/core.h>
 #include <linux/regmap.h>
 #include <linux/mfd/tps65910.h>
+#include <linux/of_device.h>
 
 static struct mfd_cell tps65910s[] = {
 	{
@@ -66,6 +67,78 @@ static const struct regmap_config tps65910_regmap_config = {
 	.cache_type = REGCACHE_RBTREE,
 };
 
+#ifdef CONFIG_OF
+static struct of_device_id tps65910_of_match[] = {
+	{ .compatible = "ti,tps65910", .data = (void *)TPS65910},
+	{ .compatible = "ti,tps65911", .data = (void *)TPS65911},
+	{ },
+};
+MODULE_DEVICE_TABLE(of, tps65910_of_match);
+
+static struct tps65910_board *tps65910_parse_dt(struct i2c_client *client,
+						int *chip_id)
+{
+	struct device_node *np = client->dev.of_node;
+	struct tps65910_board *board_info;
+	unsigned int prop;
+	const struct of_device_id *match;
+	unsigned int prop_array[TPS6591X_MAX_NUM_GPIO];
+	int ret = 0;
+	int idx;
+
+	match = of_match_device(tps65910_of_match, &client->dev);
+	if (!match) {
+		dev_err(&client->dev, "Failed to find matching dt id\n");
+		return NULL;
+	}
+
+	*chip_id  = (int)match->data;
+
+	board_info = devm_kzalloc(&client->dev, sizeof(*board_info),
+			GFP_KERNEL);
+	if (!board_info) {
+		dev_err(&client->dev, "Failed to allocate pdata\n");
+		return NULL;
+	}
+
+	ret = of_property_read_u32(np, "ti,vmbch-threshold", &prop);
+	if (!ret)
+		board_info->vmbch_threshold = prop;
+	else if (*chip_id == TPS65911)
+		dev_warn(&client->dev, "VMBCH-Threshold not specified");
+
+	ret = of_property_read_u32(np, "ti,vmbch2-threshold", &prop);
+	if (!ret)
+		board_info->vmbch2_threshold = prop;
+	else if (*chip_id == TPS65911)
+		dev_warn(&client->dev, "VMBCH2-Threshold not specified");
+
+	ret = of_property_read_u32_array(np, "ti,en-gpio-sleep",
+				   prop_array, TPS6591X_MAX_NUM_GPIO);
+	if (!ret)
+		for (idx = 0; idx < ARRAY_SIZE(prop_array); idx++)
+			board_info->en_gpio_sleep[idx] = (prop_array[idx] != 0);
+	else if (ret != -EINVAL) {
+		dev_err(&client->dev,
+			"error reading property ti,en-gpio-sleep: %d\n.", ret);
+		return NULL;
+	}
+
+
+	board_info->irq = client->irq;
+	board_info->irq_base = -1;
+	board_info->gpio_base = -1;
+
+	return board_info;
+}
+#else
+static inline struct tps65910_board *tps65910_parse_dt(
+					struct i2c_client *client)
+{
+	return NULL;
+}
+#endif
+
 static int tps65910_i2c_probe(struct i2c_client *i2c,
 			    const struct i2c_device_id *id)
 {
@@ -73,8 +146,13 @@ static int tps65910_i2c_probe(struct i2c_client *i2c,
 	struct tps65910_board *pmic_plat_data;
 	struct tps65910_platform_data *init_data;
 	int ret = 0;
+	int chip_id = id->driver_data;
 
 	pmic_plat_data = dev_get_platdata(&i2c->dev);
+
+	if (!pmic_plat_data && i2c->dev.of_node)
+		pmic_plat_data = tps65910_parse_dt(i2c, &chip_id);
+
 	if (!pmic_plat_data)
 		return -EINVAL;
 
@@ -91,7 +169,7 @@ static int tps65910_i2c_probe(struct i2c_client *i2c,
 	i2c_set_clientdata(i2c, tps65910);
 	tps65910->dev = &i2c->dev;
 	tps65910->i2c_client = i2c;
-	tps65910->id = id->driver_data;
+	tps65910->id = chip_id;
 	mutex_init(&tps65910->io_mutex);
 
 	tps65910->regmap = regmap_init_i2c(i2c, &tps65910_regmap_config);
@@ -149,6 +227,7 @@ static struct i2c_driver tps65910_i2c_driver = {
 	.driver = {
 		   .name = "tps65910",
 		   .owner = THIS_MODULE,
+		   .of_match_table = of_match_ptr(tps65910_of_match),
 	},
 	.probe = tps65910_i2c_probe,
 	.remove = tps65910_i2c_remove,
-- 
1.7.0.4


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 5/8 v2] mfd: tps65910: Add device-tree support
@ 2012-04-24 23:36   ` Rhyland Klein
  0 siblings, 0 replies; 26+ messages in thread
From: Rhyland Klein @ 2012-04-24 23:36 UTC (permalink / raw)
  To: Mark Brown, Samuel Ortiz, Grant Likely, Rob Herring, Liam Girdwood
  Cc: linux-kernel, devicetree-discuss, Rhyland Klein

Add device tree based initialization support for TI's tps65910 pmic.

Signed-off-by: Rhyland Klein <rklein@nvidia.com>
---
 v2: split mfd portion into single change to add dt support
     added of_node to config before calling regulator_register
     removed passing pdata to mfd_cell child devices
     removed use_dt_for_init_data flag

 drivers/mfd/tps65910.c |   81 +++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 80 insertions(+), 1 deletions(-)

diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
index 70a8079..248fe9f 100644
--- a/drivers/mfd/tps65910.c
+++ b/drivers/mfd/tps65910.c
@@ -23,6 +23,7 @@
 #include <linux/mfd/core.h>
 #include <linux/regmap.h>
 #include <linux/mfd/tps65910.h>
+#include <linux/of_device.h>
 
 static struct mfd_cell tps65910s[] = {
 	{
@@ -66,6 +67,78 @@ static const struct regmap_config tps65910_regmap_config = {
 	.cache_type = REGCACHE_RBTREE,
 };
 
+#ifdef CONFIG_OF
+static struct of_device_id tps65910_of_match[] = {
+	{ .compatible = "ti,tps65910", .data = (void *)TPS65910},
+	{ .compatible = "ti,tps65911", .data = (void *)TPS65911},
+	{ },
+};
+MODULE_DEVICE_TABLE(of, tps65910_of_match);
+
+static struct tps65910_board *tps65910_parse_dt(struct i2c_client *client,
+						int *chip_id)
+{
+	struct device_node *np = client->dev.of_node;
+	struct tps65910_board *board_info;
+	unsigned int prop;
+	const struct of_device_id *match;
+	unsigned int prop_array[TPS6591X_MAX_NUM_GPIO];
+	int ret = 0;
+	int idx;
+
+	match = of_match_device(tps65910_of_match, &client->dev);
+	if (!match) {
+		dev_err(&client->dev, "Failed to find matching dt id\n");
+		return NULL;
+	}
+
+	*chip_id  = (int)match->data;
+
+	board_info = devm_kzalloc(&client->dev, sizeof(*board_info),
+			GFP_KERNEL);
+	if (!board_info) {
+		dev_err(&client->dev, "Failed to allocate pdata\n");
+		return NULL;
+	}
+
+	ret = of_property_read_u32(np, "ti,vmbch-threshold", &prop);
+	if (!ret)
+		board_info->vmbch_threshold = prop;
+	else if (*chip_id == TPS65911)
+		dev_warn(&client->dev, "VMBCH-Threshold not specified");
+
+	ret = of_property_read_u32(np, "ti,vmbch2-threshold", &prop);
+	if (!ret)
+		board_info->vmbch2_threshold = prop;
+	else if (*chip_id == TPS65911)
+		dev_warn(&client->dev, "VMBCH2-Threshold not specified");
+
+	ret = of_property_read_u32_array(np, "ti,en-gpio-sleep",
+				   prop_array, TPS6591X_MAX_NUM_GPIO);
+	if (!ret)
+		for (idx = 0; idx < ARRAY_SIZE(prop_array); idx++)
+			board_info->en_gpio_sleep[idx] = (prop_array[idx] != 0);
+	else if (ret != -EINVAL) {
+		dev_err(&client->dev,
+			"error reading property ti,en-gpio-sleep: %d\n.", ret);
+		return NULL;
+	}
+
+
+	board_info->irq = client->irq;
+	board_info->irq_base = -1;
+	board_info->gpio_base = -1;
+
+	return board_info;
+}
+#else
+static inline struct tps65910_board *tps65910_parse_dt(
+					struct i2c_client *client)
+{
+	return NULL;
+}
+#endif
+
 static int tps65910_i2c_probe(struct i2c_client *i2c,
 			    const struct i2c_device_id *id)
 {
@@ -73,8 +146,13 @@ static int tps65910_i2c_probe(struct i2c_client *i2c,
 	struct tps65910_board *pmic_plat_data;
 	struct tps65910_platform_data *init_data;
 	int ret = 0;
+	int chip_id = id->driver_data;
 
 	pmic_plat_data = dev_get_platdata(&i2c->dev);
+
+	if (!pmic_plat_data && i2c->dev.of_node)
+		pmic_plat_data = tps65910_parse_dt(i2c, &chip_id);
+
 	if (!pmic_plat_data)
 		return -EINVAL;
 
@@ -91,7 +169,7 @@ static int tps65910_i2c_probe(struct i2c_client *i2c,
 	i2c_set_clientdata(i2c, tps65910);
 	tps65910->dev = &i2c->dev;
 	tps65910->i2c_client = i2c;
-	tps65910->id = id->driver_data;
+	tps65910->id = chip_id;
 	mutex_init(&tps65910->io_mutex);
 
 	tps65910->regmap = regmap_init_i2c(i2c, &tps65910_regmap_config);
@@ -149,6 +227,7 @@ static struct i2c_driver tps65910_i2c_driver = {
 	.driver = {
 		   .name = "tps65910",
 		   .owner = THIS_MODULE,
+		   .of_match_table = of_match_ptr(tps65910_of_match),
 	},
 	.probe = tps65910_i2c_probe,
 	.remove = tps65910_i2c_remove,
-- 
1.7.0.4

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 6/8 v2] regulator: tps65910 regulator: add device tree support
  2012-04-24 23:36 ` Rhyland Klein
@ 2012-04-24 23:36   ` Rhyland Klein
  -1 siblings, 0 replies; 26+ messages in thread
From: Rhyland Klein @ 2012-04-24 23:36 UTC (permalink / raw)
  To: Mark Brown, Samuel Ortiz, Grant Likely, Rob Herring, Liam Girdwood
  Cc: linux-kernel, devicetree-discuss, Rhyland Klein

Add devicetree based initialization support for TI tps65910 regulators.

Signed-off-by: Rhyland Klein <rklein@nvidia.com>
---
 v2: split off regulator specific dt initialization
     made use of new function to match regulator nodes to names to fill in
       init_data

 drivers/regulator/tps65910-regulator.c |  106 ++++++++++++++++++++++++++++++++
 1 files changed, 106 insertions(+), 0 deletions(-)

diff --git a/drivers/regulator/tps65910-regulator.c b/drivers/regulator/tps65910-regulator.c
index 855bbec..519be51 100644
--- a/drivers/regulator/tps65910-regulator.c
+++ b/drivers/regulator/tps65910-regulator.c
@@ -24,6 +24,7 @@
 #include <linux/slab.h>
 #include <linux/gpio.h>
 #include <linux/mfd/tps65910.h>
+#include <linux/regulator/of_regulator.h>
 
 #define TPS65910_SUPPLY_STATE_ENABLED	0x1
 #define EXT_SLEEP_CONTROL (TPS65910_SLEEP_CONTROL_EXT_INPUT_EN1 |	\
@@ -1090,6 +1091,104 @@ static int tps65910_set_ext_sleep_config(struct tps65910_reg *pmic,
 	return ret;
 }
 
+#ifdef CONFIG_OF
+
+static const char * const tps65910_reg_names[] = {
+	"VRTC",
+	"VIO",
+	"VDD1",
+	"VDD2",
+	"VDD3",
+	"VDIG1",
+	"VDIG2",
+	"VPLL",
+	"VDAC",
+	"VAUX1",
+	"VAUX2",
+	"VAUX33",
+	"VMMC",
+};
+
+static const char * const tps65911_reg_names[] = {
+	"VRTC",
+	"VIO",
+	"VDD1",
+	"VDD2",
+	"VDDCTRL",
+	"LDO1",
+	"LDO2",
+	"LDO3",
+	"LDO4",
+	"LDO5",
+	"LDO6",
+	"LDO7",
+	"LDO8",
+};
+
+static struct tps65910_board *tps65910_parse_dt_reg_data(
+				struct platform_device *pdev)
+{
+	struct tps65910_board *pmic_plat_data;
+	struct tps65910 *tps65910 = dev_get_drvdata(pdev->dev.parent);
+	struct device_node *np = pdev->dev.parent->of_node;
+	struct device_node *regulators, *child;
+	unsigned int prop;
+	struct regulator_init_data **all_data;
+	int idx = 0, ret;
+
+	pmic_plat_data = devm_kzalloc(&pdev->dev, sizeof(*pmic_plat_data),
+					GFP_KERNEL);
+
+	if (!pmic_plat_data) {
+		dev_err(&pdev->dev, "Failure to alloc pdata for regulators.\n");
+		return NULL;
+	}
+
+	all_data = pmic_plat_data->tps65910_pmic_init_data;
+
+	regulators = of_find_node_by_name(np, "regulators");
+
+	switch (tps65910_chip_id(tps65910)) {
+	case TPS65910:
+		ret = of_find_regulator_init_data_from_device(pdev->dev.parent,
+			regulators, tps65910_reg_names, all_data,
+			ARRAY_SIZE(tps65910_reg_names));
+		break;
+	case TPS65911:
+		ret = of_find_regulator_init_data_from_device(pdev->dev.parent,
+			regulators, tps65911_reg_names, all_data,
+			ARRAY_SIZE(tps65911_reg_names));
+		break;
+	default:
+		pr_err("Invalid tps chip version\n");
+		return NULL;
+	}
+
+	if (ret) {
+		dev_err(&pdev->dev, "Error parsing regulator init data: %d\n",
+			ret);
+		return NULL;
+	}
+
+	idx = 0;
+	for_each_child_of_node(regulators, child) {
+		ret = of_property_read_u32(child,
+				"ti,regulator-ext-sleep-control", &prop);
+		if (!ret)
+			pmic_plat_data->regulator_ext_sleep_control[idx] = prop;
+		idx++;
+	}
+
+	return pmic_plat_data;
+}
+#else
+static inline struct tps65910_board *tps65910_parse_dt_reg_data(
+				struct platform_device *pdev)
+{
+	return 0;
+}
+#endif
+
 static __devinit int tps65910_probe(struct platform_device *pdev)
 {
 	struct tps65910 *tps65910 = dev_get_drvdata(pdev->dev.parent);
@@ -1102,6 +1201,9 @@ static __devinit int tps65910_probe(struct platform_device *pdev)
 	int i, err;
 
 	pmic_plat_data = dev_get_platdata(tps65910->dev);
+	if (!pmic_plat_data && tps65910->dev->of_node)
+		pmic_plat_data = tps65910_parse_dt_reg_data(pdev);
+
 	if (!pmic_plat_data)
 		return -EINVAL;
 
@@ -1205,6 +1307,10 @@ static __devinit int tps65910_probe(struct platform_device *pdev)
 		config.dev = tps65910->dev;
 		config.init_data = reg_data;
 		config.driver_data = pmic;
+#ifdef CONFIG_OF
+		config.of_node = of_find_node_by_name(tps65910->dev->of_node,
+							info->name);
+#endif
 
 		rdev = regulator_register(&pmic->desc[i], &config);
 		if (IS_ERR(rdev)) {
-- 
1.7.0.4


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 6/8 v2] regulator: tps65910 regulator: add device tree support
@ 2012-04-24 23:36   ` Rhyland Klein
  0 siblings, 0 replies; 26+ messages in thread
From: Rhyland Klein @ 2012-04-24 23:36 UTC (permalink / raw)
  To: Mark Brown, Samuel Ortiz, Grant Likely, Rob Herring, Liam Girdwood
  Cc: linux-kernel, devicetree-discuss, Rhyland Klein

Add devicetree based initialization support for TI tps65910 regulators.

Signed-off-by: Rhyland Klein <rklein@nvidia.com>
---
 v2: split off regulator specific dt initialization
     made use of new function to match regulator nodes to names to fill in
       init_data

 drivers/regulator/tps65910-regulator.c |  106 ++++++++++++++++++++++++++++++++
 1 files changed, 106 insertions(+), 0 deletions(-)

diff --git a/drivers/regulator/tps65910-regulator.c b/drivers/regulator/tps65910-regulator.c
index 855bbec..519be51 100644
--- a/drivers/regulator/tps65910-regulator.c
+++ b/drivers/regulator/tps65910-regulator.c
@@ -24,6 +24,7 @@
 #include <linux/slab.h>
 #include <linux/gpio.h>
 #include <linux/mfd/tps65910.h>
+#include <linux/regulator/of_regulator.h>
 
 #define TPS65910_SUPPLY_STATE_ENABLED	0x1
 #define EXT_SLEEP_CONTROL (TPS65910_SLEEP_CONTROL_EXT_INPUT_EN1 |	\
@@ -1090,6 +1091,104 @@ static int tps65910_set_ext_sleep_config(struct tps65910_reg *pmic,
 	return ret;
 }
 
+#ifdef CONFIG_OF
+
+static const char * const tps65910_reg_names[] = {
+	"VRTC",
+	"VIO",
+	"VDD1",
+	"VDD2",
+	"VDD3",
+	"VDIG1",
+	"VDIG2",
+	"VPLL",
+	"VDAC",
+	"VAUX1",
+	"VAUX2",
+	"VAUX33",
+	"VMMC",
+};
+
+static const char * const tps65911_reg_names[] = {
+	"VRTC",
+	"VIO",
+	"VDD1",
+	"VDD2",
+	"VDDCTRL",
+	"LDO1",
+	"LDO2",
+	"LDO3",
+	"LDO4",
+	"LDO5",
+	"LDO6",
+	"LDO7",
+	"LDO8",
+};
+
+static struct tps65910_board *tps65910_parse_dt_reg_data(
+				struct platform_device *pdev)
+{
+	struct tps65910_board *pmic_plat_data;
+	struct tps65910 *tps65910 = dev_get_drvdata(pdev->dev.parent);
+	struct device_node *np = pdev->dev.parent->of_node;
+	struct device_node *regulators, *child;
+	unsigned int prop;
+	struct regulator_init_data **all_data;
+	int idx = 0, ret;
+
+	pmic_plat_data = devm_kzalloc(&pdev->dev, sizeof(*pmic_plat_data),
+					GFP_KERNEL);
+
+	if (!pmic_plat_data) {
+		dev_err(&pdev->dev, "Failure to alloc pdata for regulators.\n");
+		return NULL;
+	}
+
+	all_data = pmic_plat_data->tps65910_pmic_init_data;
+
+	regulators = of_find_node_by_name(np, "regulators");
+
+	switch (tps65910_chip_id(tps65910)) {
+	case TPS65910:
+		ret = of_find_regulator_init_data_from_device(pdev->dev.parent,
+			regulators, tps65910_reg_names, all_data,
+			ARRAY_SIZE(tps65910_reg_names));
+		break;
+	case TPS65911:
+		ret = of_find_regulator_init_data_from_device(pdev->dev.parent,
+			regulators, tps65911_reg_names, all_data,
+			ARRAY_SIZE(tps65911_reg_names));
+		break;
+	default:
+		pr_err("Invalid tps chip version\n");
+		return NULL;
+	}
+
+	if (ret) {
+		dev_err(&pdev->dev, "Error parsing regulator init data: %d\n",
+			ret);
+		return NULL;
+	}
+
+	idx = 0;
+	for_each_child_of_node(regulators, child) {
+		ret = of_property_read_u32(child,
+				"ti,regulator-ext-sleep-control", &prop);
+		if (!ret)
+			pmic_plat_data->regulator_ext_sleep_control[idx] = prop;
+		idx++;
+	}
+
+	return pmic_plat_data;
+}
+#else
+static inline struct tps65910_board *tps65910_parse_dt_reg_data(
+				struct platform_device *pdev)
+{
+	return 0;
+}
+#endif
+
 static __devinit int tps65910_probe(struct platform_device *pdev)
 {
 	struct tps65910 *tps65910 = dev_get_drvdata(pdev->dev.parent);
@@ -1102,6 +1201,9 @@ static __devinit int tps65910_probe(struct platform_device *pdev)
 	int i, err;
 
 	pmic_plat_data = dev_get_platdata(tps65910->dev);
+	if (!pmic_plat_data && tps65910->dev->of_node)
+		pmic_plat_data = tps65910_parse_dt_reg_data(pdev);
+
 	if (!pmic_plat_data)
 		return -EINVAL;
 
@@ -1205,6 +1307,10 @@ static __devinit int tps65910_probe(struct platform_device *pdev)
 		config.dev = tps65910->dev;
 		config.init_data = reg_data;
 		config.driver_data = pmic;
+#ifdef CONFIG_OF
+		config.of_node = of_find_node_by_name(tps65910->dev->of_node,
+							info->name);
+#endif
 
 		rdev = regulator_register(&pmic->desc[i], &config);
 		if (IS_ERR(rdev)) {
-- 
1.7.0.4

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 7/8 v2] mfd: tps65910-irq: Add devicetree init support
  2012-04-24 23:36 ` Rhyland Klein
@ 2012-04-24 23:36   ` Rhyland Klein
  -1 siblings, 0 replies; 26+ messages in thread
From: Rhyland Klein @ 2012-04-24 23:36 UTC (permalink / raw)
  To: Mark Brown, Samuel Ortiz, Grant Likely, Rob Herring, Liam Girdwood
  Cc: linux-kernel, devicetree-discuss, Rhyland Klein

Add support for initializing when boot using devicetree. The main difference
is that the irq_base will not be setup, so it needs to be manually handled.

Signed-off-by: Rhyland Klein <rklein@nvidia.com>
---
 v2: split off irq specific changes based on previous review comments

 drivers/mfd/tps65910-irq.c |   21 +++++++++++++++------
 1 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/drivers/mfd/tps65910-irq.c b/drivers/mfd/tps65910-irq.c
index 0f1ff7f..066a30f 100644
--- a/drivers/mfd/tps65910-irq.c
+++ b/drivers/mfd/tps65910-irq.c
@@ -180,12 +180,6 @@ int tps65910_irq_init(struct tps65910 *tps65910, int irq,
 		return -EINVAL;
 	}
 
-	tps65910->irq_mask = 0xFFFFFF;
-
-	mutex_init(&tps65910->irq_lock);
-	tps65910->chip_irq = irq;
-	tps65910->irq_base = pdata->irq_base;
-
 	switch (tps65910_chip_id(tps65910)) {
 	case TPS65910:
 		tps65910->irq_num = TPS65910_NUM_IRQ;
@@ -195,6 +189,21 @@ int tps65910_irq_init(struct tps65910 *tps65910, int irq,
 		break;
 	}
 
+	if (pdata->irq_base <= 0)
+		pdata->irq_base = irq_alloc_descs(-1, 0, tps65910->irq_num, -1);
+
+	if (pdata->irq_base <= 0) {
+		dev_err(tps65910->dev, "Failed to allocate irq descs: %d\n",
+			pdata->irq_base);
+		return pdata->irq_base;
+	}
+
+	tps65910->irq_mask = 0xFFFFFF;
+
+	mutex_init(&tps65910->irq_lock);
+	tps65910->chip_irq = irq;
+	tps65910->irq_base = pdata->irq_base;
+
 	/* Register with genirq */
 	for (cur_irq = tps65910->irq_base;
 	     cur_irq < tps65910->irq_num + tps65910->irq_base;
-- 
1.7.0.4


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 7/8 v2] mfd: tps65910-irq: Add devicetree init support
@ 2012-04-24 23:36   ` Rhyland Klein
  0 siblings, 0 replies; 26+ messages in thread
From: Rhyland Klein @ 2012-04-24 23:36 UTC (permalink / raw)
  To: Mark Brown, Samuel Ortiz, Grant Likely, Rob Herring, Liam Girdwood
  Cc: linux-kernel, devicetree-discuss, Rhyland Klein

Add support for initializing when boot using devicetree. The main difference
is that the irq_base will not be setup, so it needs to be manually handled.

Signed-off-by: Rhyland Klein <rklein@nvidia.com>
---
 v2: split off irq specific changes based on previous review comments

 drivers/mfd/tps65910-irq.c |   21 +++++++++++++++------
 1 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/drivers/mfd/tps65910-irq.c b/drivers/mfd/tps65910-irq.c
index 0f1ff7f..066a30f 100644
--- a/drivers/mfd/tps65910-irq.c
+++ b/drivers/mfd/tps65910-irq.c
@@ -180,12 +180,6 @@ int tps65910_irq_init(struct tps65910 *tps65910, int irq,
 		return -EINVAL;
 	}
 
-	tps65910->irq_mask = 0xFFFFFF;
-
-	mutex_init(&tps65910->irq_lock);
-	tps65910->chip_irq = irq;
-	tps65910->irq_base = pdata->irq_base;
-
 	switch (tps65910_chip_id(tps65910)) {
 	case TPS65910:
 		tps65910->irq_num = TPS65910_NUM_IRQ;
@@ -195,6 +189,21 @@ int tps65910_irq_init(struct tps65910 *tps65910, int irq,
 		break;
 	}
 
+	if (pdata->irq_base <= 0)
+		pdata->irq_base = irq_alloc_descs(-1, 0, tps65910->irq_num, -1);
+
+	if (pdata->irq_base <= 0) {
+		dev_err(tps65910->dev, "Failed to allocate irq descs: %d\n",
+			pdata->irq_base);
+		return pdata->irq_base;
+	}
+
+	tps65910->irq_mask = 0xFFFFFF;
+
+	mutex_init(&tps65910->irq_lock);
+	tps65910->chip_irq = irq;
+	tps65910->irq_base = pdata->irq_base;
+
 	/* Register with genirq */
 	for (cur_irq = tps65910->irq_base;
 	     cur_irq < tps65910->irq_num + tps65910->irq_base;
-- 
1.7.0.4

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 8/8 v2] ARM: Tegra: Add support for TPS65910 PMIC
  2012-04-24 23:36 ` Rhyland Klein
@ 2012-04-24 23:36   ` Rhyland Klein
  -1 siblings, 0 replies; 26+ messages in thread
From: Rhyland Klein @ 2012-04-24 23:36 UTC (permalink / raw)
  To: Mark Brown, Samuel Ortiz, Grant Likely, Rob Herring, Liam Girdwood
  Cc: linux-kernel, devicetree-discuss, Rhyland Klein

Add support for the tps65910 pmic on cardhu.

Signed-off-by: Rhyland Klein <rklein@nvidia.com>
---
 v2: updated to move the ext-sleep-control into the regulator nodes

 arch/arm/boot/dts/tegra-cardhu.dts |   91 ++++++++++++++++++++++++++++++++++++
 1 files changed, 91 insertions(+), 0 deletions(-)

diff --git a/arch/arm/boot/dts/tegra-cardhu.dts b/arch/arm/boot/dts/tegra-cardhu.dts
index ab8d901..ed02abb 100644
--- a/arch/arm/boot/dts/tegra-cardhu.dts
+++ b/arch/arm/boot/dts/tegra-cardhu.dts
@@ -115,6 +115,97 @@
 			micdet-delay = <100>;
 			gpio-cfg = <0xffffffff 0xffffffff 0 0xffffffff 0xffffffff>;
 		};
+
+		pmic: tps65911@2d {
+			compatible = "ti,tps65911";
+			reg = <0x2d>;
+			interrupts = < 0 118 0x04 >;
+
+			#gpio-cells = <2>;
+			gpio-controller;
+
+			#interrupt-cells = <2>;
+			interrupt-controller;
+
+			ti,vmbch-threshold = <0>;
+			ti,vmbch2-threshold = <0>;
+			ti,en-gpio-sleep = <0 0 1 0 0 0 0 0 0>;
+
+			regulators {
+				vdd1_reg: vdd1 {
+					regulator-min-microvolt = < 600000>;
+					regulator-max-microvolt = <1500000>;
+					regulator-always-on;
+					regulator-boot-on;
+					ti,regulator-ext-sleep-control = <4>;
+				};
+				vdd2_reg: vdd2 {
+					regulator-min-microvolt = < 600000>;
+					regulator-max-microvolt = <1500000>;
+					regulator-always-on;
+					regulator-boot-on;
+					ti,regulator-ext-sleep-control = <0>;
+				};
+				vddctrl_reg: vddctrl {
+					regulator-min-microvolt = < 600000>;
+					regulator-max-microvolt = <1400000>;
+					regulator-always-on;
+					regulator-boot-on;
+					ti,regulator-ext-sleep-control = <1>;
+				};
+				vio_reg: vio {
+					regulator-min-microvolt = <1500000>;
+					regulator-max-microvolt = <1800000>;
+					regulator-always-on;
+					regulator-boot-on;
+					ti,regulator-ext-sleep-control = <0>;
+				};
+				ldo1_reg: ldo1 {
+					regulator-min-microvolt = <1000000>;
+					regulator-max-microvolt = <3300000>;
+					ti,regulator-ext-sleep-control = <0>;
+				};
+				ldo2_reg: ldo2 {
+					regulator-min-microvolt = <1050000>;
+					regulator-max-microvolt = <1050000>;
+					ti,regulator-ext-sleep-control = <0>;
+				};
+				ldo3_reg: ldo3 {
+					regulator-min-microvolt = <1000000>;
+					regulator-max-microvolt = <3300000>;
+					ti,regulator-ext-sleep-control = <0>;
+				};
+				ldo4_reg: ldo4 {
+					regulator-min-microvolt = <1000000>;
+					regulator-max-microvolt = <3300000>;
+					regulator-always-on;
+					ti,regulator-ext-sleep-control = <0>;
+				};
+				ldo5_reg: ldo5 {
+					regulator-min-microvolt = <1000000>;
+					regulator-max-microvolt = <3300000>;
+					ti,regulator-ext-sleep-control = <0>;
+				};
+				ldo6_reg: ldo6 {
+					regulator-min-microvolt = <1200000>;
+					regulator-max-microvolt = <1200000>;
+					ti,regulator-ext-sleep-control = <0>;
+				};
+				ldo7_reg: ldo7 {
+					regulator-min-microvolt = <1200000>;
+					regulator-max-microvolt = <1200000>;
+					regulator-always-on;
+					regulator-boot-on;
+					ti,regulator-ext-sleep-control = <1>;
+				};
+				ldo8_reg: ldo8 {
+					regulator-min-microvolt = <1000000>;
+					regulator-max-microvolt = <3300000>;
+					regulator-always-on;
+					ti,regulator-ext-sleep-control = <1>;
+				};
+			};
+		};
 	};
 
 	sdhci@78000000 {
-- 
1.7.0.4


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 8/8 v2] ARM: Tegra: Add support for TPS65910 PMIC
@ 2012-04-24 23:36   ` Rhyland Klein
  0 siblings, 0 replies; 26+ messages in thread
From: Rhyland Klein @ 2012-04-24 23:36 UTC (permalink / raw)
  To: Mark Brown, Samuel Ortiz, Grant Likely, Rob Herring, Liam Girdwood
  Cc: linux-kernel, devicetree-discuss, Rhyland Klein

Add support for the tps65910 pmic on cardhu.

Signed-off-by: Rhyland Klein <rklein@nvidia.com>
---
 v2: updated to move the ext-sleep-control into the regulator nodes

 arch/arm/boot/dts/tegra-cardhu.dts |   91 ++++++++++++++++++++++++++++++++++++
 1 files changed, 91 insertions(+), 0 deletions(-)

diff --git a/arch/arm/boot/dts/tegra-cardhu.dts b/arch/arm/boot/dts/tegra-cardhu.dts
index ab8d901..ed02abb 100644
--- a/arch/arm/boot/dts/tegra-cardhu.dts
+++ b/arch/arm/boot/dts/tegra-cardhu.dts
@@ -115,6 +115,97 @@
 			micdet-delay = <100>;
 			gpio-cfg = <0xffffffff 0xffffffff 0 0xffffffff 0xffffffff>;
 		};
+
+		pmic: tps65911@2d {
+			compatible = "ti,tps65911";
+			reg = <0x2d>;
+			interrupts = < 0 118 0x04 >;
+
+			#gpio-cells = <2>;
+			gpio-controller;
+
+			#interrupt-cells = <2>;
+			interrupt-controller;
+
+			ti,vmbch-threshold = <0>;
+			ti,vmbch2-threshold = <0>;
+			ti,en-gpio-sleep = <0 0 1 0 0 0 0 0 0>;
+
+			regulators {
+				vdd1_reg: vdd1 {
+					regulator-min-microvolt = < 600000>;
+					regulator-max-microvolt = <1500000>;
+					regulator-always-on;
+					regulator-boot-on;
+					ti,regulator-ext-sleep-control = <4>;
+				};
+				vdd2_reg: vdd2 {
+					regulator-min-microvolt = < 600000>;
+					regulator-max-microvolt = <1500000>;
+					regulator-always-on;
+					regulator-boot-on;
+					ti,regulator-ext-sleep-control = <0>;
+				};
+				vddctrl_reg: vddctrl {
+					regulator-min-microvolt = < 600000>;
+					regulator-max-microvolt = <1400000>;
+					regulator-always-on;
+					regulator-boot-on;
+					ti,regulator-ext-sleep-control = <1>;
+				};
+				vio_reg: vio {
+					regulator-min-microvolt = <1500000>;
+					regulator-max-microvolt = <1800000>;
+					regulator-always-on;
+					regulator-boot-on;
+					ti,regulator-ext-sleep-control = <0>;
+				};
+				ldo1_reg: ldo1 {
+					regulator-min-microvolt = <1000000>;
+					regulator-max-microvolt = <3300000>;
+					ti,regulator-ext-sleep-control = <0>;
+				};
+				ldo2_reg: ldo2 {
+					regulator-min-microvolt = <1050000>;
+					regulator-max-microvolt = <1050000>;
+					ti,regulator-ext-sleep-control = <0>;
+				};
+				ldo3_reg: ldo3 {
+					regulator-min-microvolt = <1000000>;
+					regulator-max-microvolt = <3300000>;
+					ti,regulator-ext-sleep-control = <0>;
+				};
+				ldo4_reg: ldo4 {
+					regulator-min-microvolt = <1000000>;
+					regulator-max-microvolt = <3300000>;
+					regulator-always-on;
+					ti,regulator-ext-sleep-control = <0>;
+				};
+				ldo5_reg: ldo5 {
+					regulator-min-microvolt = <1000000>;
+					regulator-max-microvolt = <3300000>;
+					ti,regulator-ext-sleep-control = <0>;
+				};
+				ldo6_reg: ldo6 {
+					regulator-min-microvolt = <1200000>;
+					regulator-max-microvolt = <1200000>;
+					ti,regulator-ext-sleep-control = <0>;
+				};
+				ldo7_reg: ldo7 {
+					regulator-min-microvolt = <1200000>;
+					regulator-max-microvolt = <1200000>;
+					regulator-always-on;
+					regulator-boot-on;
+					ti,regulator-ext-sleep-control = <1>;
+				};
+				ldo8_reg: ldo8 {
+					regulator-min-microvolt = <1000000>;
+					regulator-max-microvolt = <3300000>;
+					regulator-always-on;
+					ti,regulator-ext-sleep-control = <1>;
+				};
+			};
+		};
 	};
 
 	sdhci@78000000 {
-- 
1.7.0.4

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* Re: [PATCH 3/8 v2] mfd: tps65910: Commonize regmap access through header
  2012-04-24 23:36   ` Rhyland Klein
@ 2012-05-17 23:52     ` Grant Likely
  -1 siblings, 0 replies; 26+ messages in thread
From: Grant Likely @ 2012-05-17 23:52 UTC (permalink / raw)
  To: Rhyland Klein, Mark Brown, Samuel Ortiz, Rob Herring, Liam Girdwood
  Cc: linux-kernel, devicetree-discuss, Rhyland Klein

On Tue, 24 Apr 2012 16:36:05 -0700, Rhyland Klein <rklein@nvidia.com> wrote:
> This change removes the read/write callback functions in favor of common
> regmap accessors inside the header file. This change also makes use of
> regmap_read/write for single register access which maps better onto what this
> driver actually needs.
> 
> Signed-off-by: Rhyland Klein <rklein@nvidia.com>

for the gpio bits:

Acked-by: Grant Likely <grant.likely@secretlab.ca>

> ---
>  v2: implemented switching tps65910 drivers over to more directly accessing
>      the regmap rather than going through utility functions.
> 
>  drivers/gpio/gpio-tps65910.c           |   14 +++---
>  drivers/mfd/tps65910-irq.c             |   34 ++++++------
>  drivers/mfd/tps65910.c                 |   26 ---------
>  drivers/regulator/tps65910-regulator.c |   88 +++++++++++++++-----------------
>  include/linux/mfd/tps65910.h           |   29 +++++++++--
>  5 files changed, 91 insertions(+), 100 deletions(-)
> 
> diff --git a/drivers/gpio/gpio-tps65910.c b/drivers/gpio/gpio-tps65910.c
> index 7eef648..bc155f2 100644
> --- a/drivers/gpio/gpio-tps65910.c
> +++ b/drivers/gpio/gpio-tps65910.c
> @@ -23,9 +23,9 @@
>  static int tps65910_gpio_get(struct gpio_chip *gc, unsigned offset)
>  {
>  	struct tps65910 *tps65910 = container_of(gc, struct tps65910, gpio);
> -	uint8_t val;
> +	unsigned int val;
>  
> -	tps65910->read(tps65910, TPS65910_GPIO0 + offset, 1, &val);
> +	tps65910_reg_read(tps65910, TPS65910_GPIO0 + offset, &val);
>  
>  	if (val & GPIO_STS_MASK)
>  		return 1;
> @@ -39,10 +39,10 @@ static void tps65910_gpio_set(struct gpio_chip *gc, unsigned offset,
>  	struct tps65910 *tps65910 = container_of(gc, struct tps65910, gpio);
>  
>  	if (value)
> -		tps65910_set_bits(tps65910, TPS65910_GPIO0 + offset,
> +		tps65910_reg_set_bits(tps65910, TPS65910_GPIO0 + offset,
>  						GPIO_SET_MASK);
>  	else
> -		tps65910_clear_bits(tps65910, TPS65910_GPIO0 + offset,
> +		tps65910_reg_clear_bits(tps65910, TPS65910_GPIO0 + offset,
>  						GPIO_SET_MASK);
>  }
>  
> @@ -54,7 +54,7 @@ static int tps65910_gpio_output(struct gpio_chip *gc, unsigned offset,
>  	/* Set the initial value */
>  	tps65910_gpio_set(gc, offset, value);
>  
> -	return tps65910_set_bits(tps65910, TPS65910_GPIO0 + offset,
> +	return tps65910_reg_set_bits(tps65910, TPS65910_GPIO0 + offset,
>  						GPIO_CFG_MASK);
>  }
>  
> @@ -62,7 +62,7 @@ static int tps65910_gpio_input(struct gpio_chip *gc, unsigned offset)
>  {
>  	struct tps65910 *tps65910 = container_of(gc, struct tps65910, gpio);
>  
> -	return tps65910_clear_bits(tps65910, TPS65910_GPIO0 + offset,
> +	return tps65910_reg_clear_bits(tps65910, TPS65910_GPIO0 + offset,
>  						GPIO_CFG_MASK);
>  }
>  
> @@ -102,7 +102,7 @@ void tps65910_gpio_init(struct tps65910 *tps65910, int gpio_base)
>  		int i;
>  		for (i = 0; i < tps65910->gpio.ngpio; ++i) {
>  			if (board_data->en_gpio_sleep[i]) {
> -				ret = tps65910_set_bits(tps65910,
> +				ret = tps65910_reg_set_bits(tps65910,
>  					TPS65910_GPIO0 + i, GPIO_SLEEP_MASK);
>  				if (ret < 0)
>  					dev_warn(tps65910->dev,
> diff --git a/drivers/mfd/tps65910-irq.c b/drivers/mfd/tps65910-irq.c
> index c9ed5c0..0f1ff7f 100644
> --- a/drivers/mfd/tps65910-irq.c
> +++ b/drivers/mfd/tps65910-irq.c
> @@ -41,28 +41,28 @@ static inline int irq_to_tps65910_irq(struct tps65910 *tps65910,
>  static irqreturn_t tps65910_irq(int irq, void *irq_data)
>  {
>  	struct tps65910 *tps65910 = irq_data;
> +	unsigned int reg;
>  	u32 irq_sts;
>  	u32 irq_mask;
> -	u8 reg;
>  	int i;
>  
> -	tps65910->read(tps65910, TPS65910_INT_STS, 1, &reg);
> +	tps65910_reg_read(tps65910, TPS65910_INT_STS, &reg);
>  	irq_sts = reg;
> -	tps65910->read(tps65910, TPS65910_INT_STS2, 1, &reg);
> +	tps65910_reg_read(tps65910, TPS65910_INT_STS2, &reg);
>  	irq_sts |= reg << 8;
>  	switch (tps65910_chip_id(tps65910)) {
>  	case TPS65911:
> -		tps65910->read(tps65910, TPS65910_INT_STS3, 1, &reg);
> +		tps65910_reg_read(tps65910, TPS65910_INT_STS3, &reg);
>  		irq_sts |= reg << 16;
>  	}
>  
> -	tps65910->read(tps65910, TPS65910_INT_MSK, 1, &reg);
> +	tps65910_reg_read(tps65910, TPS65910_INT_MSK, &reg);
>  	irq_mask = reg;
> -	tps65910->read(tps65910, TPS65910_INT_MSK2, 1, &reg);
> +	tps65910_reg_read(tps65910, TPS65910_INT_MSK2, &reg);
>  	irq_mask |= reg << 8;
>  	switch (tps65910_chip_id(tps65910)) {
>  	case TPS65911:
> -		tps65910->read(tps65910, TPS65910_INT_MSK3, 1, &reg);
> +		tps65910_reg_read(tps65910, TPS65910_INT_MSK3, &reg);
>  		irq_mask |= reg << 16;
>  	}
>  
> @@ -82,13 +82,13 @@ static irqreturn_t tps65910_irq(int irq, void *irq_data)
>  	/* Write the STS register back to clear IRQs we handled */
>  	reg = irq_sts & 0xFF;
>  	irq_sts >>= 8;
> -	tps65910->write(tps65910, TPS65910_INT_STS, 1, &reg);
> +	tps65910_reg_write(tps65910, TPS65910_INT_STS, reg);
>  	reg = irq_sts & 0xFF;
> -	tps65910->write(tps65910, TPS65910_INT_STS2, 1, &reg);
> +	tps65910_reg_write(tps65910, TPS65910_INT_STS2, reg);
>  	switch (tps65910_chip_id(tps65910)) {
>  	case TPS65911:
>  		reg = irq_sts >> 8;
> -		tps65910->write(tps65910, TPS65910_INT_STS3, 1, &reg);
> +		tps65910_reg_write(tps65910, TPS65910_INT_STS3, reg);
>  	}
>  
>  	return IRQ_HANDLED;
> @@ -105,27 +105,27 @@ static void tps65910_irq_sync_unlock(struct irq_data *data)
>  {
>  	struct tps65910 *tps65910 = irq_data_get_irq_chip_data(data);
>  	u32 reg_mask;
> -	u8 reg;
> +	unsigned int reg;
>  
> -	tps65910->read(tps65910, TPS65910_INT_MSK, 1, &reg);
> +	tps65910_reg_read(tps65910, TPS65910_INT_MSK, &reg);
>  	reg_mask = reg;
> -	tps65910->read(tps65910, TPS65910_INT_MSK2, 1, &reg);
> +	tps65910_reg_read(tps65910, TPS65910_INT_MSK2, &reg);
>  	reg_mask |= reg << 8;
>  	switch (tps65910_chip_id(tps65910)) {
>  	case TPS65911:
> -		tps65910->read(tps65910, TPS65910_INT_MSK3, 1, &reg);
> +		tps65910_reg_read(tps65910, TPS65910_INT_MSK3, &reg);
>  		reg_mask |= reg << 16;
>  	}
>  
>  	if (tps65910->irq_mask != reg_mask) {
>  		reg = tps65910->irq_mask & 0xFF;
> -		tps65910->write(tps65910, TPS65910_INT_MSK, 1, &reg);
> +		tps65910_reg_write(tps65910, TPS65910_INT_MSK, reg);
>  		reg = tps65910->irq_mask >> 8 & 0xFF;
> -		tps65910->write(tps65910, TPS65910_INT_MSK2, 1, &reg);
> +		tps65910_reg_write(tps65910, TPS65910_INT_MSK2, reg);
>  		switch (tps65910_chip_id(tps65910)) {
>  		case TPS65911:
>  			reg = tps65910->irq_mask >> 16;
> -			tps65910->write(tps65910, TPS65910_INT_MSK3, 1, &reg);
> +			tps65910_reg_write(tps65910, TPS65910_INT_MSK3, reg);
>  		}
>  	}
>  	mutex_unlock(&tps65910->irq_lock);
> diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
> index bf2b25e..70a8079 100644
> --- a/drivers/mfd/tps65910.c
> +++ b/drivers/mfd/tps65910.c
> @@ -37,30 +37,6 @@ static struct mfd_cell tps65910s[] = {
>  };
>  
>  
> -static int tps65910_i2c_read(struct tps65910 *tps65910, u8 reg,
> -				  int bytes, void *dest)
> -{
> -	return regmap_bulk_read(tps65910->regmap, reg, dest, bytes);
> -}
> -
> -static int tps65910_i2c_write(struct tps65910 *tps65910, u8 reg,
> -				  int bytes, void *src)
> -{
> -	return regmap_bulk_write(tps65910->regmap, reg, src, bytes);
> -}
> -
> -int tps65910_set_bits(struct tps65910 *tps65910, u8 reg, u8 mask)
> -{
> -	return regmap_update_bits(tps65910->regmap, reg, mask, mask);
> -}
> -EXPORT_SYMBOL_GPL(tps65910_set_bits);
> -
> -int tps65910_clear_bits(struct tps65910 *tps65910, u8 reg, u8 mask)
> -{
> -	return regmap_update_bits(tps65910->regmap, reg, mask, 0);
> -}
> -EXPORT_SYMBOL_GPL(tps65910_clear_bits);
> -
>  static bool is_volatile_reg(struct device *dev, unsigned int reg)
>  {
>  	struct tps65910 *tps65910 = dev_get_drvdata(dev);
> @@ -116,8 +92,6 @@ static int tps65910_i2c_probe(struct i2c_client *i2c,
>  	tps65910->dev = &i2c->dev;
>  	tps65910->i2c_client = i2c;
>  	tps65910->id = id->driver_data;
> -	tps65910->read = tps65910_i2c_read;
> -	tps65910->write = tps65910_i2c_write;
>  	mutex_init(&tps65910->io_mutex);
>  
>  	tps65910->regmap = regmap_init_i2c(i2c, &tps65910_regmap_config);
> diff --git a/drivers/regulator/tps65910-regulator.c b/drivers/regulator/tps65910-regulator.c
> index 747bf57..855bbec 100644
> --- a/drivers/regulator/tps65910-regulator.c
> +++ b/drivers/regulator/tps65910-regulator.c
> @@ -331,21 +331,16 @@ struct tps65910_reg {
>  
>  static inline int tps65910_read(struct tps65910_reg *pmic, u8 reg)
>  {
> -	u8 val;
> +	unsigned int val;
>  	int err;
>  
> -	err = pmic->mfd->read(pmic->mfd, reg, 1, &val);
> +	err = tps65910_reg_read(pmic->mfd, reg, &val);
>  	if (err)
>  		return err;
>  
>  	return val;
>  }
>  
> -static inline int tps65910_write(struct tps65910_reg *pmic, u8 reg, u8 val)
> -{
> -	return pmic->mfd->write(pmic->mfd, reg, 1, &val);
> -}
> -
>  static int tps65910_modify_bits(struct tps65910_reg *pmic, u8 reg,
>  					u8 set_mask, u8 clear_mask)
>  {
> @@ -362,7 +357,7 @@ static int tps65910_modify_bits(struct tps65910_reg *pmic, u8 reg,
>  
>  	data &= ~clear_mask;
>  	data |= set_mask;
> -	err = tps65910_write(pmic, reg, data);
> +	err = tps65910_reg_write(pmic->mfd, reg, data);
>  	if (err)
>  		dev_err(pmic->mfd->dev, "Write for reg 0x%x failed\n", reg);
>  
> @@ -371,7 +366,7 @@ out:
>  	return err;
>  }
>  
> -static int tps65910_reg_read(struct tps65910_reg *pmic, u8 reg)
> +static int tps65910_reg_read_locked(struct tps65910_reg *pmic, u8 reg)
>  {
>  	int data;
>  
> @@ -385,13 +380,13 @@ static int tps65910_reg_read(struct tps65910_reg *pmic, u8 reg)
>  	return data;
>  }
>  
> -static int tps65910_reg_write(struct tps65910_reg *pmic, u8 reg, u8 val)
> +static int tps65910_reg_write_locked(struct tps65910_reg *pmic, u8 reg, u8 val)
>  {
>  	int err;
>  
>  	mutex_lock(&pmic->mutex);
>  
> -	err = tps65910_write(pmic, reg, val);
> +	err = tps65910_reg_write(pmic->mfd, reg, val);
>  	if (err < 0)
>  		dev_err(pmic->mfd->dev, "Write for reg 0x%x failed\n", reg);
>  
> @@ -476,7 +471,7 @@ static int tps65910_is_enabled(struct regulator_dev *dev)
>  	if (reg < 0)
>  		return reg;
>  
> -	value = tps65910_reg_read(pmic, reg);
> +	value = tps65910_reg_read_locked(pmic, reg);
>  	if (value < 0)
>  		return value;
>  
> @@ -493,7 +488,7 @@ static int tps65910_enable(struct regulator_dev *dev)
>  	if (reg < 0)
>  		return reg;
>  
> -	return tps65910_set_bits(mfd, reg, TPS65910_SUPPLY_STATE_ENABLED);
> +	return tps65910_reg_set_bits(mfd, reg, TPS65910_SUPPLY_STATE_ENABLED);
>  }
>  
>  static int tps65910_disable(struct regulator_dev *dev)
> @@ -506,7 +501,7 @@ static int tps65910_disable(struct regulator_dev *dev)
>  	if (reg < 0)
>  		return reg;
>  
> -	return tps65910_clear_bits(mfd, reg, TPS65910_SUPPLY_STATE_ENABLED);
> +	return tps65910_reg_clear_bits(mfd, reg, TPS65910_SUPPLY_STATE_ENABLED);
>  }
>  
>  static int tps65910_enable_time(struct regulator_dev *dev)
> @@ -532,9 +527,9 @@ static int tps65910_set_mode(struct regulator_dev *dev, unsigned int mode)
>  							LDO_ST_MODE_BIT);
>  	case REGULATOR_MODE_IDLE:
>  		value = LDO_ST_ON_BIT | LDO_ST_MODE_BIT;
> -		return tps65910_set_bits(mfd, reg, value);
> +		return tps65910_reg_set_bits(mfd, reg, value);
>  	case REGULATOR_MODE_STANDBY:
> -		return tps65910_clear_bits(mfd, reg, LDO_ST_ON_BIT);
> +		return tps65910_reg_clear_bits(mfd, reg, LDO_ST_ON_BIT);
>  	}
>  
>  	return -EINVAL;
> @@ -549,7 +544,7 @@ static unsigned int tps65910_get_mode(struct regulator_dev *dev)
>  	if (reg < 0)
>  		return reg;
>  
> -	value = tps65910_reg_read(pmic, reg);
> +	value = tps65910_reg_read_locked(pmic, reg);
>  	if (value < 0)
>  		return value;
>  
> @@ -569,28 +564,28 @@ static int tps65910_get_voltage_dcdc_sel(struct regulator_dev *dev)
>  
>  	switch (id) {
>  	case TPS65910_REG_VDD1:
> -		opvsel = tps65910_reg_read(pmic, TPS65910_VDD1_OP);
> -		mult = tps65910_reg_read(pmic, TPS65910_VDD1);
> +		opvsel = tps65910_reg_read_locked(pmic, TPS65910_VDD1_OP);
> +		mult = tps65910_reg_read_locked(pmic, TPS65910_VDD1);
>  		mult = (mult & VDD1_VGAIN_SEL_MASK) >> VDD1_VGAIN_SEL_SHIFT;
> -		srvsel = tps65910_reg_read(pmic, TPS65910_VDD1_SR);
> +		srvsel = tps65910_reg_read_locked(pmic, TPS65910_VDD1_SR);
>  		sr = opvsel & VDD1_OP_CMD_MASK;
>  		opvsel &= VDD1_OP_SEL_MASK;
>  		srvsel &= VDD1_SR_SEL_MASK;
>  		vselmax = 75;
>  		break;
>  	case TPS65910_REG_VDD2:
> -		opvsel = tps65910_reg_read(pmic, TPS65910_VDD2_OP);
> -		mult = tps65910_reg_read(pmic, TPS65910_VDD2);
> +		opvsel = tps65910_reg_read_locked(pmic, TPS65910_VDD2_OP);
> +		mult = tps65910_reg_read_locked(pmic, TPS65910_VDD2);
>  		mult = (mult & VDD2_VGAIN_SEL_MASK) >> VDD2_VGAIN_SEL_SHIFT;
> -		srvsel = tps65910_reg_read(pmic, TPS65910_VDD2_SR);
> +		srvsel = tps65910_reg_read_locked(pmic, TPS65910_VDD2_SR);
>  		sr = opvsel & VDD2_OP_CMD_MASK;
>  		opvsel &= VDD2_OP_SEL_MASK;
>  		srvsel &= VDD2_SR_SEL_MASK;
>  		vselmax = 75;
>  		break;
>  	case TPS65911_REG_VDDCTRL:
> -		opvsel = tps65910_reg_read(pmic, TPS65911_VDDCTRL_OP);
> -		srvsel = tps65910_reg_read(pmic, TPS65911_VDDCTRL_SR);
> +		opvsel = tps65910_reg_read_locked(pmic, TPS65911_VDDCTRL_OP);
> +		srvsel = tps65910_reg_read_locked(pmic, TPS65911_VDDCTRL_SR);
>  		sr = opvsel & VDDCTRL_OP_CMD_MASK;
>  		opvsel &= VDDCTRL_OP_SEL_MASK;
>  		srvsel &= VDDCTRL_SR_SEL_MASK;
> @@ -630,7 +625,7 @@ static int tps65910_get_voltage(struct regulator_dev *dev)
>  	if (reg < 0)
>  		return reg;
>  
> -	value = tps65910_reg_read(pmic, reg);
> +	value = tps65910_reg_read_locked(pmic, reg);
>  	if (value < 0)
>  		return value;
>  
> @@ -669,7 +664,7 @@ static int tps65911_get_voltage(struct regulator_dev *dev)
>  
>  	reg = pmic->get_ctrl_reg(id);
>  
> -	value = tps65910_reg_read(pmic, reg);
> +	value = tps65910_reg_read_locked(pmic, reg);
>  
>  	switch (id) {
>  	case TPS65911_REG_LDO1:
> @@ -728,7 +723,7 @@ static int tps65910_set_voltage_dcdc_sel(struct regulator_dev *dev,
>  		tps65910_modify_bits(pmic, TPS65910_VDD1,
>  				(dcdc_mult << VDD1_VGAIN_SEL_SHIFT),
>  						VDD1_VGAIN_SEL_MASK);
> -		tps65910_reg_write(pmic, TPS65910_VDD1_OP, vsel);
> +		tps65910_reg_write_locked(pmic, TPS65910_VDD1_OP, vsel);
>  		break;
>  	case TPS65910_REG_VDD2:
>  		dcdc_mult = (selector / VDD1_2_NUM_VOLT_FINE) + 1;
> @@ -739,11 +734,11 @@ static int tps65910_set_voltage_dcdc_sel(struct regulator_dev *dev,
>  		tps65910_modify_bits(pmic, TPS65910_VDD2,
>  				(dcdc_mult << VDD2_VGAIN_SEL_SHIFT),
>  						VDD1_VGAIN_SEL_MASK);
> -		tps65910_reg_write(pmic, TPS65910_VDD2_OP, vsel);
> +		tps65910_reg_write_locked(pmic, TPS65910_VDD2_OP, vsel);
>  		break;
>  	case TPS65911_REG_VDDCTRL:
>  		vsel = selector + 3;
> -		tps65910_reg_write(pmic, TPS65911_VDDCTRL_OP, vsel);
> +		tps65910_reg_write_locked(pmic, TPS65911_VDDCTRL_OP, vsel);
>  	}
>  
>  	return 0;
> @@ -994,10 +989,10 @@ static int tps65910_set_ext_sleep_config(struct tps65910_reg *pmic,
>  
>  	/* External EN1 control */
>  	if (ext_sleep_config & TPS65910_SLEEP_CONTROL_EXT_INPUT_EN1)
> -		ret = tps65910_set_bits(mfd,
> +		ret = tps65910_reg_set_bits(mfd,
>  				TPS65910_EN1_LDO_ASS + regoffs, bit_pos);
>  	else
> -		ret = tps65910_clear_bits(mfd,
> +		ret = tps65910_reg_clear_bits(mfd,
>  				TPS65910_EN1_LDO_ASS + regoffs, bit_pos);
>  	if (ret < 0) {
>  		dev_err(mfd->dev,
> @@ -1007,10 +1002,10 @@ static int tps65910_set_ext_sleep_config(struct tps65910_reg *pmic,
>  
>  	/* External EN2 control */
>  	if (ext_sleep_config & TPS65910_SLEEP_CONTROL_EXT_INPUT_EN2)
> -		ret = tps65910_set_bits(mfd,
> +		ret = tps65910_reg_set_bits(mfd,
>  				TPS65910_EN2_LDO_ASS + regoffs, bit_pos);
>  	else
> -		ret = tps65910_clear_bits(mfd,
> +		ret = tps65910_reg_clear_bits(mfd,
>  				TPS65910_EN2_LDO_ASS + regoffs, bit_pos);
>  	if (ret < 0) {
>  		dev_err(mfd->dev,
> @@ -1022,10 +1017,10 @@ static int tps65910_set_ext_sleep_config(struct tps65910_reg *pmic,
>  	if ((tps65910_chip_id(mfd) == TPS65910) &&
>  			(id >= TPS65910_REG_VDIG1)) {
>  		if (ext_sleep_config & TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3)
> -			ret = tps65910_set_bits(mfd,
> +			ret = tps65910_reg_set_bits(mfd,
>  				TPS65910_EN3_LDO_ASS + regoffs, bit_pos);
>  		else
> -			ret = tps65910_clear_bits(mfd,
> +			ret = tps65910_reg_clear_bits(mfd,
>  				TPS65910_EN3_LDO_ASS + regoffs, bit_pos);
>  		if (ret < 0) {
>  			dev_err(mfd->dev,
> @@ -1037,10 +1032,10 @@ static int tps65910_set_ext_sleep_config(struct tps65910_reg *pmic,
>  	/* Return if no external control is selected */
>  	if (!(ext_sleep_config & EXT_SLEEP_CONTROL)) {
>  		/* Clear all sleep controls */
> -		ret = tps65910_clear_bits(mfd,
> +		ret = tps65910_reg_clear_bits(mfd,
>  			TPS65910_SLEEP_KEEP_LDO_ON + regoffs, bit_pos);
>  		if (!ret)
> -			ret = tps65910_clear_bits(mfd,
> +			ret = tps65910_reg_clear_bits(mfd,
>  				TPS65910_SLEEP_SET_LDO_OFF + regoffs, bit_pos);
>  		if (ret < 0)
>  			dev_err(mfd->dev,
> @@ -1059,32 +1054,33 @@ static int tps65910_set_ext_sleep_config(struct tps65910_reg *pmic,
>  				(tps65910_chip_id(mfd) == TPS65911))) {
>  		int op_reg_add = pmic->get_ctrl_reg(id) + 1;
>  		int sr_reg_add = pmic->get_ctrl_reg(id) + 2;
> -		int opvsel = tps65910_reg_read(pmic, op_reg_add);
> -		int srvsel = tps65910_reg_read(pmic, sr_reg_add);
> +		int opvsel = tps65910_reg_read_locked(pmic, op_reg_add);
> +		int srvsel = tps65910_reg_read_locked(pmic, sr_reg_add);
>  		if (opvsel & VDD1_OP_CMD_MASK) {
>  			u8 reg_val = srvsel & VDD1_OP_SEL_MASK;
> -			ret = tps65910_reg_write(pmic, op_reg_add, reg_val);
> +			ret = tps65910_reg_write_locked(pmic, op_reg_add,
> +							reg_val);
>  			if (ret < 0) {
>  				dev_err(mfd->dev,
>  					"Error in configuring op register\n");
>  				return ret;
>  			}
>  		}
> -		ret = tps65910_reg_write(pmic, sr_reg_add, 0);
> +		ret = tps65910_reg_write_locked(pmic, sr_reg_add, 0);
>  		if (ret < 0) {
>  			dev_err(mfd->dev, "Error in settting sr register\n");
>  			return ret;
>  		}
>  	}
>  
> -	ret = tps65910_clear_bits(mfd,
> +	ret = tps65910_reg_clear_bits(mfd,
>  			TPS65910_SLEEP_KEEP_LDO_ON + regoffs, bit_pos);
>  	if (!ret) {
>  		if (ext_sleep_config & TPS65911_SLEEP_CONTROL_EXT_INPUT_SLEEP)
> -			ret = tps65910_set_bits(mfd,
> +			ret = tps65910_reg_set_bits(mfd,
>  				TPS65910_SLEEP_SET_LDO_OFF + regoffs, bit_pos);
>  		else
> -			ret = tps65910_clear_bits(mfd,
> +			ret = tps65910_reg_clear_bits(mfd,
>  				TPS65910_SLEEP_SET_LDO_OFF + regoffs, bit_pos);
>  	}
>  	if (ret < 0)
> @@ -1118,7 +1114,7 @@ static __devinit int tps65910_probe(struct platform_device *pdev)
>  	platform_set_drvdata(pdev, pmic);
>  
>  	/* Give control of all register to control port */
> -	tps65910_set_bits(pmic->mfd, TPS65910_DEVCTRL,
> +	tps65910_reg_set_bits(pmic->mfd, TPS65910_DEVCTRL,
>  				DEVCTRL_SR_CTL_I2C_SEL_MASK);
>  
>  	switch(tps65910_chip_id(tps65910)) {
> diff --git a/include/linux/mfd/tps65910.h b/include/linux/mfd/tps65910.h
> index 1c6c286..e004de1 100644
> --- a/include/linux/mfd/tps65910.h
> +++ b/include/linux/mfd/tps65910.h
> @@ -18,6 +18,7 @@
>  #define __LINUX_MFD_TPS65910_H
>  
>  #include <linux/gpio.h>
> +#include <linux/regmap.h>
>  
>  /* TPS chip id list */
>  #define TPS65910			0
> @@ -809,8 +810,6 @@ struct tps65910 {
>  	struct regmap *regmap;
>  	struct mutex io_mutex;
>  	unsigned int id;
> -	int (*read)(struct tps65910 *tps65910, u8 reg, int size, void *dest);
> -	int (*write)(struct tps65910 *tps65910, u8 reg, int size, void *src);
>  
>  	/* Client devices */
>  	struct tps65910_pmic *pmic;
> @@ -833,8 +832,6 @@ struct tps65910_platform_data {
>  	int irq_base;
>  };
>  
> -int tps65910_set_bits(struct tps65910 *tps65910, u8 reg, u8 mask);
> -int tps65910_clear_bits(struct tps65910 *tps65910, u8 reg, u8 mask);
>  void tps65910_gpio_init(struct tps65910 *tps65910, int gpio_base);
>  int tps65910_irq_init(struct tps65910 *tps65910, int irq,
>  		struct tps65910_platform_data *pdata);
> @@ -845,4 +842,28 @@ static inline int tps65910_chip_id(struct tps65910 *tps65910)
>  	return tps65910->id;
>  }
>  
> +static inline int tps65910_reg_read(struct tps65910 *tps65910, u8 reg,
> +		unsigned int *val)
> +{
> +	return regmap_read(tps65910->regmap, reg, val);
> +}
> +
> +static inline int tps65910_reg_write(struct tps65910 *tps65910, u8 reg,
> +		unsigned int val)
> +{
> +	return regmap_write(tps65910->regmap, reg, val);
> +}
> +
> +static inline int tps65910_reg_set_bits(struct tps65910 *tps65910, u8 reg,
> +		u8 mask)
> +{
> +	return regmap_update_bits(tps65910->regmap, reg, mask, mask);
> +}
> +
> +static inline int tps65910_reg_clear_bits(struct tps65910 *tps65910, u8 reg,
> +		u8 mask)
> +{
> +	return regmap_update_bits(tps65910->regmap, reg, mask, 0);
> +}
> +
>  #endif /*  __LINUX_MFD_TPS65910_H */
> -- 
> 1.7.0.4
> 

-- 
Grant Likely, B.Sc, P.Eng.
Secret Lab Technologies, Ltd.

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 3/8 v2] mfd: tps65910: Commonize regmap access through header
@ 2012-05-17 23:52     ` Grant Likely
  0 siblings, 0 replies; 26+ messages in thread
From: Grant Likely @ 2012-05-17 23:52 UTC (permalink / raw)
  To: Mark Brown, Samuel Ortiz, Rob Herring, Liam Girdwood
  Cc: linux-kernel, devicetree-discuss, Rhyland Klein

On Tue, 24 Apr 2012 16:36:05 -0700, Rhyland Klein <rklein@nvidia.com> wrote:
> This change removes the read/write callback functions in favor of common
> regmap accessors inside the header file. This change also makes use of
> regmap_read/write for single register access which maps better onto what this
> driver actually needs.
> 
> Signed-off-by: Rhyland Klein <rklein@nvidia.com>

for the gpio bits:

Acked-by: Grant Likely <grant.likely@secretlab.ca>

> ---
>  v2: implemented switching tps65910 drivers over to more directly accessing
>      the regmap rather than going through utility functions.
> 
>  drivers/gpio/gpio-tps65910.c           |   14 +++---
>  drivers/mfd/tps65910-irq.c             |   34 ++++++------
>  drivers/mfd/tps65910.c                 |   26 ---------
>  drivers/regulator/tps65910-regulator.c |   88 +++++++++++++++-----------------
>  include/linux/mfd/tps65910.h           |   29 +++++++++--
>  5 files changed, 91 insertions(+), 100 deletions(-)
> 
> diff --git a/drivers/gpio/gpio-tps65910.c b/drivers/gpio/gpio-tps65910.c
> index 7eef648..bc155f2 100644
> --- a/drivers/gpio/gpio-tps65910.c
> +++ b/drivers/gpio/gpio-tps65910.c
> @@ -23,9 +23,9 @@
>  static int tps65910_gpio_get(struct gpio_chip *gc, unsigned offset)
>  {
>  	struct tps65910 *tps65910 = container_of(gc, struct tps65910, gpio);
> -	uint8_t val;
> +	unsigned int val;
>  
> -	tps65910->read(tps65910, TPS65910_GPIO0 + offset, 1, &val);
> +	tps65910_reg_read(tps65910, TPS65910_GPIO0 + offset, &val);
>  
>  	if (val & GPIO_STS_MASK)
>  		return 1;
> @@ -39,10 +39,10 @@ static void tps65910_gpio_set(struct gpio_chip *gc, unsigned offset,
>  	struct tps65910 *tps65910 = container_of(gc, struct tps65910, gpio);
>  
>  	if (value)
> -		tps65910_set_bits(tps65910, TPS65910_GPIO0 + offset,
> +		tps65910_reg_set_bits(tps65910, TPS65910_GPIO0 + offset,
>  						GPIO_SET_MASK);
>  	else
> -		tps65910_clear_bits(tps65910, TPS65910_GPIO0 + offset,
> +		tps65910_reg_clear_bits(tps65910, TPS65910_GPIO0 + offset,
>  						GPIO_SET_MASK);
>  }
>  
> @@ -54,7 +54,7 @@ static int tps65910_gpio_output(struct gpio_chip *gc, unsigned offset,
>  	/* Set the initial value */
>  	tps65910_gpio_set(gc, offset, value);
>  
> -	return tps65910_set_bits(tps65910, TPS65910_GPIO0 + offset,
> +	return tps65910_reg_set_bits(tps65910, TPS65910_GPIO0 + offset,
>  						GPIO_CFG_MASK);
>  }
>  
> @@ -62,7 +62,7 @@ static int tps65910_gpio_input(struct gpio_chip *gc, unsigned offset)
>  {
>  	struct tps65910 *tps65910 = container_of(gc, struct tps65910, gpio);
>  
> -	return tps65910_clear_bits(tps65910, TPS65910_GPIO0 + offset,
> +	return tps65910_reg_clear_bits(tps65910, TPS65910_GPIO0 + offset,
>  						GPIO_CFG_MASK);
>  }
>  
> @@ -102,7 +102,7 @@ void tps65910_gpio_init(struct tps65910 *tps65910, int gpio_base)
>  		int i;
>  		for (i = 0; i < tps65910->gpio.ngpio; ++i) {
>  			if (board_data->en_gpio_sleep[i]) {
> -				ret = tps65910_set_bits(tps65910,
> +				ret = tps65910_reg_set_bits(tps65910,
>  					TPS65910_GPIO0 + i, GPIO_SLEEP_MASK);
>  				if (ret < 0)
>  					dev_warn(tps65910->dev,
> diff --git a/drivers/mfd/tps65910-irq.c b/drivers/mfd/tps65910-irq.c
> index c9ed5c0..0f1ff7f 100644
> --- a/drivers/mfd/tps65910-irq.c
> +++ b/drivers/mfd/tps65910-irq.c
> @@ -41,28 +41,28 @@ static inline int irq_to_tps65910_irq(struct tps65910 *tps65910,
>  static irqreturn_t tps65910_irq(int irq, void *irq_data)
>  {
>  	struct tps65910 *tps65910 = irq_data;
> +	unsigned int reg;
>  	u32 irq_sts;
>  	u32 irq_mask;
> -	u8 reg;
>  	int i;
>  
> -	tps65910->read(tps65910, TPS65910_INT_STS, 1, &reg);
> +	tps65910_reg_read(tps65910, TPS65910_INT_STS, &reg);
>  	irq_sts = reg;
> -	tps65910->read(tps65910, TPS65910_INT_STS2, 1, &reg);
> +	tps65910_reg_read(tps65910, TPS65910_INT_STS2, &reg);
>  	irq_sts |= reg << 8;
>  	switch (tps65910_chip_id(tps65910)) {
>  	case TPS65911:
> -		tps65910->read(tps65910, TPS65910_INT_STS3, 1, &reg);
> +		tps65910_reg_read(tps65910, TPS65910_INT_STS3, &reg);
>  		irq_sts |= reg << 16;
>  	}
>  
> -	tps65910->read(tps65910, TPS65910_INT_MSK, 1, &reg);
> +	tps65910_reg_read(tps65910, TPS65910_INT_MSK, &reg);
>  	irq_mask = reg;
> -	tps65910->read(tps65910, TPS65910_INT_MSK2, 1, &reg);
> +	tps65910_reg_read(tps65910, TPS65910_INT_MSK2, &reg);
>  	irq_mask |= reg << 8;
>  	switch (tps65910_chip_id(tps65910)) {
>  	case TPS65911:
> -		tps65910->read(tps65910, TPS65910_INT_MSK3, 1, &reg);
> +		tps65910_reg_read(tps65910, TPS65910_INT_MSK3, &reg);
>  		irq_mask |= reg << 16;
>  	}
>  
> @@ -82,13 +82,13 @@ static irqreturn_t tps65910_irq(int irq, void *irq_data)
>  	/* Write the STS register back to clear IRQs we handled */
>  	reg = irq_sts & 0xFF;
>  	irq_sts >>= 8;
> -	tps65910->write(tps65910, TPS65910_INT_STS, 1, &reg);
> +	tps65910_reg_write(tps65910, TPS65910_INT_STS, reg);
>  	reg = irq_sts & 0xFF;
> -	tps65910->write(tps65910, TPS65910_INT_STS2, 1, &reg);
> +	tps65910_reg_write(tps65910, TPS65910_INT_STS2, reg);
>  	switch (tps65910_chip_id(tps65910)) {
>  	case TPS65911:
>  		reg = irq_sts >> 8;
> -		tps65910->write(tps65910, TPS65910_INT_STS3, 1, &reg);
> +		tps65910_reg_write(tps65910, TPS65910_INT_STS3, reg);
>  	}
>  
>  	return IRQ_HANDLED;
> @@ -105,27 +105,27 @@ static void tps65910_irq_sync_unlock(struct irq_data *data)
>  {
>  	struct tps65910 *tps65910 = irq_data_get_irq_chip_data(data);
>  	u32 reg_mask;
> -	u8 reg;
> +	unsigned int reg;
>  
> -	tps65910->read(tps65910, TPS65910_INT_MSK, 1, &reg);
> +	tps65910_reg_read(tps65910, TPS65910_INT_MSK, &reg);
>  	reg_mask = reg;
> -	tps65910->read(tps65910, TPS65910_INT_MSK2, 1, &reg);
> +	tps65910_reg_read(tps65910, TPS65910_INT_MSK2, &reg);
>  	reg_mask |= reg << 8;
>  	switch (tps65910_chip_id(tps65910)) {
>  	case TPS65911:
> -		tps65910->read(tps65910, TPS65910_INT_MSK3, 1, &reg);
> +		tps65910_reg_read(tps65910, TPS65910_INT_MSK3, &reg);
>  		reg_mask |= reg << 16;
>  	}
>  
>  	if (tps65910->irq_mask != reg_mask) {
>  		reg = tps65910->irq_mask & 0xFF;
> -		tps65910->write(tps65910, TPS65910_INT_MSK, 1, &reg);
> +		tps65910_reg_write(tps65910, TPS65910_INT_MSK, reg);
>  		reg = tps65910->irq_mask >> 8 & 0xFF;
> -		tps65910->write(tps65910, TPS65910_INT_MSK2, 1, &reg);
> +		tps65910_reg_write(tps65910, TPS65910_INT_MSK2, reg);
>  		switch (tps65910_chip_id(tps65910)) {
>  		case TPS65911:
>  			reg = tps65910->irq_mask >> 16;
> -			tps65910->write(tps65910, TPS65910_INT_MSK3, 1, &reg);
> +			tps65910_reg_write(tps65910, TPS65910_INT_MSK3, reg);
>  		}
>  	}
>  	mutex_unlock(&tps65910->irq_lock);
> diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
> index bf2b25e..70a8079 100644
> --- a/drivers/mfd/tps65910.c
> +++ b/drivers/mfd/tps65910.c
> @@ -37,30 +37,6 @@ static struct mfd_cell tps65910s[] = {
>  };
>  
>  
> -static int tps65910_i2c_read(struct tps65910 *tps65910, u8 reg,
> -				  int bytes, void *dest)
> -{
> -	return regmap_bulk_read(tps65910->regmap, reg, dest, bytes);
> -}
> -
> -static int tps65910_i2c_write(struct tps65910 *tps65910, u8 reg,
> -				  int bytes, void *src)
> -{
> -	return regmap_bulk_write(tps65910->regmap, reg, src, bytes);
> -}
> -
> -int tps65910_set_bits(struct tps65910 *tps65910, u8 reg, u8 mask)
> -{
> -	return regmap_update_bits(tps65910->regmap, reg, mask, mask);
> -}
> -EXPORT_SYMBOL_GPL(tps65910_set_bits);
> -
> -int tps65910_clear_bits(struct tps65910 *tps65910, u8 reg, u8 mask)
> -{
> -	return regmap_update_bits(tps65910->regmap, reg, mask, 0);
> -}
> -EXPORT_SYMBOL_GPL(tps65910_clear_bits);
> -
>  static bool is_volatile_reg(struct device *dev, unsigned int reg)
>  {
>  	struct tps65910 *tps65910 = dev_get_drvdata(dev);
> @@ -116,8 +92,6 @@ static int tps65910_i2c_probe(struct i2c_client *i2c,
>  	tps65910->dev = &i2c->dev;
>  	tps65910->i2c_client = i2c;
>  	tps65910->id = id->driver_data;
> -	tps65910->read = tps65910_i2c_read;
> -	tps65910->write = tps65910_i2c_write;
>  	mutex_init(&tps65910->io_mutex);
>  
>  	tps65910->regmap = regmap_init_i2c(i2c, &tps65910_regmap_config);
> diff --git a/drivers/regulator/tps65910-regulator.c b/drivers/regulator/tps65910-regulator.c
> index 747bf57..855bbec 100644
> --- a/drivers/regulator/tps65910-regulator.c
> +++ b/drivers/regulator/tps65910-regulator.c
> @@ -331,21 +331,16 @@ struct tps65910_reg {
>  
>  static inline int tps65910_read(struct tps65910_reg *pmic, u8 reg)
>  {
> -	u8 val;
> +	unsigned int val;
>  	int err;
>  
> -	err = pmic->mfd->read(pmic->mfd, reg, 1, &val);
> +	err = tps65910_reg_read(pmic->mfd, reg, &val);
>  	if (err)
>  		return err;
>  
>  	return val;
>  }
>  
> -static inline int tps65910_write(struct tps65910_reg *pmic, u8 reg, u8 val)
> -{
> -	return pmic->mfd->write(pmic->mfd, reg, 1, &val);
> -}
> -
>  static int tps65910_modify_bits(struct tps65910_reg *pmic, u8 reg,
>  					u8 set_mask, u8 clear_mask)
>  {
> @@ -362,7 +357,7 @@ static int tps65910_modify_bits(struct tps65910_reg *pmic, u8 reg,
>  
>  	data &= ~clear_mask;
>  	data |= set_mask;
> -	err = tps65910_write(pmic, reg, data);
> +	err = tps65910_reg_write(pmic->mfd, reg, data);
>  	if (err)
>  		dev_err(pmic->mfd->dev, "Write for reg 0x%x failed\n", reg);
>  
> @@ -371,7 +366,7 @@ out:
>  	return err;
>  }
>  
> -static int tps65910_reg_read(struct tps65910_reg *pmic, u8 reg)
> +static int tps65910_reg_read_locked(struct tps65910_reg *pmic, u8 reg)
>  {
>  	int data;
>  
> @@ -385,13 +380,13 @@ static int tps65910_reg_read(struct tps65910_reg *pmic, u8 reg)
>  	return data;
>  }
>  
> -static int tps65910_reg_write(struct tps65910_reg *pmic, u8 reg, u8 val)
> +static int tps65910_reg_write_locked(struct tps65910_reg *pmic, u8 reg, u8 val)
>  {
>  	int err;
>  
>  	mutex_lock(&pmic->mutex);
>  
> -	err = tps65910_write(pmic, reg, val);
> +	err = tps65910_reg_write(pmic->mfd, reg, val);
>  	if (err < 0)
>  		dev_err(pmic->mfd->dev, "Write for reg 0x%x failed\n", reg);
>  
> @@ -476,7 +471,7 @@ static int tps65910_is_enabled(struct regulator_dev *dev)
>  	if (reg < 0)
>  		return reg;
>  
> -	value = tps65910_reg_read(pmic, reg);
> +	value = tps65910_reg_read_locked(pmic, reg);
>  	if (value < 0)
>  		return value;
>  
> @@ -493,7 +488,7 @@ static int tps65910_enable(struct regulator_dev *dev)
>  	if (reg < 0)
>  		return reg;
>  
> -	return tps65910_set_bits(mfd, reg, TPS65910_SUPPLY_STATE_ENABLED);
> +	return tps65910_reg_set_bits(mfd, reg, TPS65910_SUPPLY_STATE_ENABLED);
>  }
>  
>  static int tps65910_disable(struct regulator_dev *dev)
> @@ -506,7 +501,7 @@ static int tps65910_disable(struct regulator_dev *dev)
>  	if (reg < 0)
>  		return reg;
>  
> -	return tps65910_clear_bits(mfd, reg, TPS65910_SUPPLY_STATE_ENABLED);
> +	return tps65910_reg_clear_bits(mfd, reg, TPS65910_SUPPLY_STATE_ENABLED);
>  }
>  
>  static int tps65910_enable_time(struct regulator_dev *dev)
> @@ -532,9 +527,9 @@ static int tps65910_set_mode(struct regulator_dev *dev, unsigned int mode)
>  							LDO_ST_MODE_BIT);
>  	case REGULATOR_MODE_IDLE:
>  		value = LDO_ST_ON_BIT | LDO_ST_MODE_BIT;
> -		return tps65910_set_bits(mfd, reg, value);
> +		return tps65910_reg_set_bits(mfd, reg, value);
>  	case REGULATOR_MODE_STANDBY:
> -		return tps65910_clear_bits(mfd, reg, LDO_ST_ON_BIT);
> +		return tps65910_reg_clear_bits(mfd, reg, LDO_ST_ON_BIT);
>  	}
>  
>  	return -EINVAL;
> @@ -549,7 +544,7 @@ static unsigned int tps65910_get_mode(struct regulator_dev *dev)
>  	if (reg < 0)
>  		return reg;
>  
> -	value = tps65910_reg_read(pmic, reg);
> +	value = tps65910_reg_read_locked(pmic, reg);
>  	if (value < 0)
>  		return value;
>  
> @@ -569,28 +564,28 @@ static int tps65910_get_voltage_dcdc_sel(struct regulator_dev *dev)
>  
>  	switch (id) {
>  	case TPS65910_REG_VDD1:
> -		opvsel = tps65910_reg_read(pmic, TPS65910_VDD1_OP);
> -		mult = tps65910_reg_read(pmic, TPS65910_VDD1);
> +		opvsel = tps65910_reg_read_locked(pmic, TPS65910_VDD1_OP);
> +		mult = tps65910_reg_read_locked(pmic, TPS65910_VDD1);
>  		mult = (mult & VDD1_VGAIN_SEL_MASK) >> VDD1_VGAIN_SEL_SHIFT;
> -		srvsel = tps65910_reg_read(pmic, TPS65910_VDD1_SR);
> +		srvsel = tps65910_reg_read_locked(pmic, TPS65910_VDD1_SR);
>  		sr = opvsel & VDD1_OP_CMD_MASK;
>  		opvsel &= VDD1_OP_SEL_MASK;
>  		srvsel &= VDD1_SR_SEL_MASK;
>  		vselmax = 75;
>  		break;
>  	case TPS65910_REG_VDD2:
> -		opvsel = tps65910_reg_read(pmic, TPS65910_VDD2_OP);
> -		mult = tps65910_reg_read(pmic, TPS65910_VDD2);
> +		opvsel = tps65910_reg_read_locked(pmic, TPS65910_VDD2_OP);
> +		mult = tps65910_reg_read_locked(pmic, TPS65910_VDD2);
>  		mult = (mult & VDD2_VGAIN_SEL_MASK) >> VDD2_VGAIN_SEL_SHIFT;
> -		srvsel = tps65910_reg_read(pmic, TPS65910_VDD2_SR);
> +		srvsel = tps65910_reg_read_locked(pmic, TPS65910_VDD2_SR);
>  		sr = opvsel & VDD2_OP_CMD_MASK;
>  		opvsel &= VDD2_OP_SEL_MASK;
>  		srvsel &= VDD2_SR_SEL_MASK;
>  		vselmax = 75;
>  		break;
>  	case TPS65911_REG_VDDCTRL:
> -		opvsel = tps65910_reg_read(pmic, TPS65911_VDDCTRL_OP);
> -		srvsel = tps65910_reg_read(pmic, TPS65911_VDDCTRL_SR);
> +		opvsel = tps65910_reg_read_locked(pmic, TPS65911_VDDCTRL_OP);
> +		srvsel = tps65910_reg_read_locked(pmic, TPS65911_VDDCTRL_SR);
>  		sr = opvsel & VDDCTRL_OP_CMD_MASK;
>  		opvsel &= VDDCTRL_OP_SEL_MASK;
>  		srvsel &= VDDCTRL_SR_SEL_MASK;
> @@ -630,7 +625,7 @@ static int tps65910_get_voltage(struct regulator_dev *dev)
>  	if (reg < 0)
>  		return reg;
>  
> -	value = tps65910_reg_read(pmic, reg);
> +	value = tps65910_reg_read_locked(pmic, reg);
>  	if (value < 0)
>  		return value;
>  
> @@ -669,7 +664,7 @@ static int tps65911_get_voltage(struct regulator_dev *dev)
>  
>  	reg = pmic->get_ctrl_reg(id);
>  
> -	value = tps65910_reg_read(pmic, reg);
> +	value = tps65910_reg_read_locked(pmic, reg);
>  
>  	switch (id) {
>  	case TPS65911_REG_LDO1:
> @@ -728,7 +723,7 @@ static int tps65910_set_voltage_dcdc_sel(struct regulator_dev *dev,
>  		tps65910_modify_bits(pmic, TPS65910_VDD1,
>  				(dcdc_mult << VDD1_VGAIN_SEL_SHIFT),
>  						VDD1_VGAIN_SEL_MASK);
> -		tps65910_reg_write(pmic, TPS65910_VDD1_OP, vsel);
> +		tps65910_reg_write_locked(pmic, TPS65910_VDD1_OP, vsel);
>  		break;
>  	case TPS65910_REG_VDD2:
>  		dcdc_mult = (selector / VDD1_2_NUM_VOLT_FINE) + 1;
> @@ -739,11 +734,11 @@ static int tps65910_set_voltage_dcdc_sel(struct regulator_dev *dev,
>  		tps65910_modify_bits(pmic, TPS65910_VDD2,
>  				(dcdc_mult << VDD2_VGAIN_SEL_SHIFT),
>  						VDD1_VGAIN_SEL_MASK);
> -		tps65910_reg_write(pmic, TPS65910_VDD2_OP, vsel);
> +		tps65910_reg_write_locked(pmic, TPS65910_VDD2_OP, vsel);
>  		break;
>  	case TPS65911_REG_VDDCTRL:
>  		vsel = selector + 3;
> -		tps65910_reg_write(pmic, TPS65911_VDDCTRL_OP, vsel);
> +		tps65910_reg_write_locked(pmic, TPS65911_VDDCTRL_OP, vsel);
>  	}
>  
>  	return 0;
> @@ -994,10 +989,10 @@ static int tps65910_set_ext_sleep_config(struct tps65910_reg *pmic,
>  
>  	/* External EN1 control */
>  	if (ext_sleep_config & TPS65910_SLEEP_CONTROL_EXT_INPUT_EN1)
> -		ret = tps65910_set_bits(mfd,
> +		ret = tps65910_reg_set_bits(mfd,
>  				TPS65910_EN1_LDO_ASS + regoffs, bit_pos);
>  	else
> -		ret = tps65910_clear_bits(mfd,
> +		ret = tps65910_reg_clear_bits(mfd,
>  				TPS65910_EN1_LDO_ASS + regoffs, bit_pos);
>  	if (ret < 0) {
>  		dev_err(mfd->dev,
> @@ -1007,10 +1002,10 @@ static int tps65910_set_ext_sleep_config(struct tps65910_reg *pmic,
>  
>  	/* External EN2 control */
>  	if (ext_sleep_config & TPS65910_SLEEP_CONTROL_EXT_INPUT_EN2)
> -		ret = tps65910_set_bits(mfd,
> +		ret = tps65910_reg_set_bits(mfd,
>  				TPS65910_EN2_LDO_ASS + regoffs, bit_pos);
>  	else
> -		ret = tps65910_clear_bits(mfd,
> +		ret = tps65910_reg_clear_bits(mfd,
>  				TPS65910_EN2_LDO_ASS + regoffs, bit_pos);
>  	if (ret < 0) {
>  		dev_err(mfd->dev,
> @@ -1022,10 +1017,10 @@ static int tps65910_set_ext_sleep_config(struct tps65910_reg *pmic,
>  	if ((tps65910_chip_id(mfd) == TPS65910) &&
>  			(id >= TPS65910_REG_VDIG1)) {
>  		if (ext_sleep_config & TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3)
> -			ret = tps65910_set_bits(mfd,
> +			ret = tps65910_reg_set_bits(mfd,
>  				TPS65910_EN3_LDO_ASS + regoffs, bit_pos);
>  		else
> -			ret = tps65910_clear_bits(mfd,
> +			ret = tps65910_reg_clear_bits(mfd,
>  				TPS65910_EN3_LDO_ASS + regoffs, bit_pos);
>  		if (ret < 0) {
>  			dev_err(mfd->dev,
> @@ -1037,10 +1032,10 @@ static int tps65910_set_ext_sleep_config(struct tps65910_reg *pmic,
>  	/* Return if no external control is selected */
>  	if (!(ext_sleep_config & EXT_SLEEP_CONTROL)) {
>  		/* Clear all sleep controls */
> -		ret = tps65910_clear_bits(mfd,
> +		ret = tps65910_reg_clear_bits(mfd,
>  			TPS65910_SLEEP_KEEP_LDO_ON + regoffs, bit_pos);
>  		if (!ret)
> -			ret = tps65910_clear_bits(mfd,
> +			ret = tps65910_reg_clear_bits(mfd,
>  				TPS65910_SLEEP_SET_LDO_OFF + regoffs, bit_pos);
>  		if (ret < 0)
>  			dev_err(mfd->dev,
> @@ -1059,32 +1054,33 @@ static int tps65910_set_ext_sleep_config(struct tps65910_reg *pmic,
>  				(tps65910_chip_id(mfd) == TPS65911))) {
>  		int op_reg_add = pmic->get_ctrl_reg(id) + 1;
>  		int sr_reg_add = pmic->get_ctrl_reg(id) + 2;
> -		int opvsel = tps65910_reg_read(pmic, op_reg_add);
> -		int srvsel = tps65910_reg_read(pmic, sr_reg_add);
> +		int opvsel = tps65910_reg_read_locked(pmic, op_reg_add);
> +		int srvsel = tps65910_reg_read_locked(pmic, sr_reg_add);
>  		if (opvsel & VDD1_OP_CMD_MASK) {
>  			u8 reg_val = srvsel & VDD1_OP_SEL_MASK;
> -			ret = tps65910_reg_write(pmic, op_reg_add, reg_val);
> +			ret = tps65910_reg_write_locked(pmic, op_reg_add,
> +							reg_val);
>  			if (ret < 0) {
>  				dev_err(mfd->dev,
>  					"Error in configuring op register\n");
>  				return ret;
>  			}
>  		}
> -		ret = tps65910_reg_write(pmic, sr_reg_add, 0);
> +		ret = tps65910_reg_write_locked(pmic, sr_reg_add, 0);
>  		if (ret < 0) {
>  			dev_err(mfd->dev, "Error in settting sr register\n");
>  			return ret;
>  		}
>  	}
>  
> -	ret = tps65910_clear_bits(mfd,
> +	ret = tps65910_reg_clear_bits(mfd,
>  			TPS65910_SLEEP_KEEP_LDO_ON + regoffs, bit_pos);
>  	if (!ret) {
>  		if (ext_sleep_config & TPS65911_SLEEP_CONTROL_EXT_INPUT_SLEEP)
> -			ret = tps65910_set_bits(mfd,
> +			ret = tps65910_reg_set_bits(mfd,
>  				TPS65910_SLEEP_SET_LDO_OFF + regoffs, bit_pos);
>  		else
> -			ret = tps65910_clear_bits(mfd,
> +			ret = tps65910_reg_clear_bits(mfd,
>  				TPS65910_SLEEP_SET_LDO_OFF + regoffs, bit_pos);
>  	}
>  	if (ret < 0)
> @@ -1118,7 +1114,7 @@ static __devinit int tps65910_probe(struct platform_device *pdev)
>  	platform_set_drvdata(pdev, pmic);
>  
>  	/* Give control of all register to control port */
> -	tps65910_set_bits(pmic->mfd, TPS65910_DEVCTRL,
> +	tps65910_reg_set_bits(pmic->mfd, TPS65910_DEVCTRL,
>  				DEVCTRL_SR_CTL_I2C_SEL_MASK);
>  
>  	switch(tps65910_chip_id(tps65910)) {
> diff --git a/include/linux/mfd/tps65910.h b/include/linux/mfd/tps65910.h
> index 1c6c286..e004de1 100644
> --- a/include/linux/mfd/tps65910.h
> +++ b/include/linux/mfd/tps65910.h
> @@ -18,6 +18,7 @@
>  #define __LINUX_MFD_TPS65910_H
>  
>  #include <linux/gpio.h>
> +#include <linux/regmap.h>
>  
>  /* TPS chip id list */
>  #define TPS65910			0
> @@ -809,8 +810,6 @@ struct tps65910 {
>  	struct regmap *regmap;
>  	struct mutex io_mutex;
>  	unsigned int id;
> -	int (*read)(struct tps65910 *tps65910, u8 reg, int size, void *dest);
> -	int (*write)(struct tps65910 *tps65910, u8 reg, int size, void *src);
>  
>  	/* Client devices */
>  	struct tps65910_pmic *pmic;
> @@ -833,8 +832,6 @@ struct tps65910_platform_data {
>  	int irq_base;
>  };
>  
> -int tps65910_set_bits(struct tps65910 *tps65910, u8 reg, u8 mask);
> -int tps65910_clear_bits(struct tps65910 *tps65910, u8 reg, u8 mask);
>  void tps65910_gpio_init(struct tps65910 *tps65910, int gpio_base);
>  int tps65910_irq_init(struct tps65910 *tps65910, int irq,
>  		struct tps65910_platform_data *pdata);
> @@ -845,4 +842,28 @@ static inline int tps65910_chip_id(struct tps65910 *tps65910)
>  	return tps65910->id;
>  }
>  
> +static inline int tps65910_reg_read(struct tps65910 *tps65910, u8 reg,
> +		unsigned int *val)
> +{
> +	return regmap_read(tps65910->regmap, reg, val);
> +}
> +
> +static inline int tps65910_reg_write(struct tps65910 *tps65910, u8 reg,
> +		unsigned int val)
> +{
> +	return regmap_write(tps65910->regmap, reg, val);
> +}
> +
> +static inline int tps65910_reg_set_bits(struct tps65910 *tps65910, u8 reg,
> +		u8 mask)
> +{
> +	return regmap_update_bits(tps65910->regmap, reg, mask, mask);
> +}
> +
> +static inline int tps65910_reg_clear_bits(struct tps65910 *tps65910, u8 reg,
> +		u8 mask)
> +{
> +	return regmap_update_bits(tps65910->regmap, reg, mask, 0);
> +}
> +
>  #endif /*  __LINUX_MFD_TPS65910_H */
> -- 
> 1.7.0.4
> 

-- 
Grant Likely, B.Sc, P.Eng.
Secret Lab Technologies, Ltd.

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 4/8 v2] regulator: tps65910: Add device tree bindings
  2012-04-24 23:36   ` Rhyland Klein
@ 2012-05-17 23:53     ` Grant Likely
  -1 siblings, 0 replies; 26+ messages in thread
From: Grant Likely @ 2012-05-17 23:53 UTC (permalink / raw)
  To: Rhyland Klein, Mark Brown, Samuel Ortiz, Rob Herring, Liam Girdwood
  Cc: linux-kernel, devicetree-discuss, Rhyland Klein

On Tue, 24 Apr 2012 16:36:06 -0700, Rhyland Klein <rklein@nvidia.com> wrote:
> Add device tree bindings for TI's tps65910 pmic.
> 
> Signed-off-by: Rhyland Klein <rklein@nvidia.com>

Acked-by: Grant Likely <grant.likely@secretlab.ca>


^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 4/8 v2] regulator: tps65910: Add device tree bindings
@ 2012-05-17 23:53     ` Grant Likely
  0 siblings, 0 replies; 26+ messages in thread
From: Grant Likely @ 2012-05-17 23:53 UTC (permalink / raw)
  To: Mark Brown, Samuel Ortiz, Rob Herring, Liam Girdwood
  Cc: linux-kernel, devicetree-discuss, Rhyland Klein

On Tue, 24 Apr 2012 16:36:06 -0700, Rhyland Klein <rklein@nvidia.com> wrote:
> Add device tree bindings for TI's tps65910 pmic.
> 
> Signed-off-by: Rhyland Klein <rklein@nvidia.com>

Acked-by: Grant Likely <grant.likely@secretlab.ca>

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 5/8 v2] mfd: tps65910: Add device-tree support
  2012-04-24 23:36   ` Rhyland Klein
@ 2012-05-17 23:55     ` Grant Likely
  -1 siblings, 0 replies; 26+ messages in thread
From: Grant Likely @ 2012-05-17 23:55 UTC (permalink / raw)
  To: Rhyland Klein, Mark Brown, Samuel Ortiz, Rob Herring, Liam Girdwood
  Cc: linux-kernel, devicetree-discuss, Rhyland Klein

On Tue, 24 Apr 2012 16:36:07 -0700, Rhyland Klein <rklein@nvidia.com> wrote:
> Add device tree based initialization support for TI's tps65910 pmic.
> 
> Signed-off-by: Rhyland Klein <rklein@nvidia.com>

Patch description is rather light. I like to see some more details
about what the patch changes and testing details are nice too, but
I'll ack it anyway:

Acked-by: Grant Likely <grant.likely@secretlab.ca>

> ---
>  v2: split mfd portion into single change to add dt support
>      added of_node to config before calling regulator_register
>      removed passing pdata to mfd_cell child devices
>      removed use_dt_for_init_data flag
> 
>  drivers/mfd/tps65910.c |   81 +++++++++++++++++++++++++++++++++++++++++++++++-
>  1 files changed, 80 insertions(+), 1 deletions(-)
> 
> diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
> index 70a8079..248fe9f 100644
> --- a/drivers/mfd/tps65910.c
> +++ b/drivers/mfd/tps65910.c
> @@ -23,6 +23,7 @@
>  #include <linux/mfd/core.h>
>  #include <linux/regmap.h>
>  #include <linux/mfd/tps65910.h>
> +#include <linux/of_device.h>
>  
>  static struct mfd_cell tps65910s[] = {
>  	{
> @@ -66,6 +67,78 @@ static const struct regmap_config tps65910_regmap_config = {
>  	.cache_type = REGCACHE_RBTREE,
>  };
>  
> +#ifdef CONFIG_OF
> +static struct of_device_id tps65910_of_match[] = {
> +	{ .compatible = "ti,tps65910", .data = (void *)TPS65910},
> +	{ .compatible = "ti,tps65911", .data = (void *)TPS65911},
> +	{ },
> +};
> +MODULE_DEVICE_TABLE(of, tps65910_of_match);
> +
> +static struct tps65910_board *tps65910_parse_dt(struct i2c_client *client,
> +						int *chip_id)
> +{
> +	struct device_node *np = client->dev.of_node;
> +	struct tps65910_board *board_info;
> +	unsigned int prop;
> +	const struct of_device_id *match;
> +	unsigned int prop_array[TPS6591X_MAX_NUM_GPIO];
> +	int ret = 0;
> +	int idx;
> +
> +	match = of_match_device(tps65910_of_match, &client->dev);
> +	if (!match) {
> +		dev_err(&client->dev, "Failed to find matching dt id\n");
> +		return NULL;
> +	}
> +
> +	*chip_id  = (int)match->data;
> +
> +	board_info = devm_kzalloc(&client->dev, sizeof(*board_info),
> +			GFP_KERNEL);
> +	if (!board_info) {
> +		dev_err(&client->dev, "Failed to allocate pdata\n");
> +		return NULL;
> +	}
> +
> +	ret = of_property_read_u32(np, "ti,vmbch-threshold", &prop);
> +	if (!ret)
> +		board_info->vmbch_threshold = prop;
> +	else if (*chip_id == TPS65911)
> +		dev_warn(&client->dev, "VMBCH-Threshold not specified");
> +
> +	ret = of_property_read_u32(np, "ti,vmbch2-threshold", &prop);
> +	if (!ret)
> +		board_info->vmbch2_threshold = prop;
> +	else if (*chip_id == TPS65911)
> +		dev_warn(&client->dev, "VMBCH2-Threshold not specified");
> +
> +	ret = of_property_read_u32_array(np, "ti,en-gpio-sleep",
> +				   prop_array, TPS6591X_MAX_NUM_GPIO);
> +	if (!ret)
> +		for (idx = 0; idx < ARRAY_SIZE(prop_array); idx++)
> +			board_info->en_gpio_sleep[idx] = (prop_array[idx] != 0);
> +	else if (ret != -EINVAL) {
> +		dev_err(&client->dev,
> +			"error reading property ti,en-gpio-sleep: %d\n.", ret);
> +		return NULL;
> +	}
> +
> +
> +	board_info->irq = client->irq;
> +	board_info->irq_base = -1;
> +	board_info->gpio_base = -1;
> +
> +	return board_info;
> +}
> +#else
> +static inline struct tps65910_board *tps65910_parse_dt(
> +					struct i2c_client *client)
> +{
> +	return NULL;
> +}
> +#endif
> +
>  static int tps65910_i2c_probe(struct i2c_client *i2c,
>  			    const struct i2c_device_id *id)
>  {
> @@ -73,8 +146,13 @@ static int tps65910_i2c_probe(struct i2c_client *i2c,
>  	struct tps65910_board *pmic_plat_data;
>  	struct tps65910_platform_data *init_data;
>  	int ret = 0;
> +	int chip_id = id->driver_data;
>  
>  	pmic_plat_data = dev_get_platdata(&i2c->dev);
> +
> +	if (!pmic_plat_data && i2c->dev.of_node)
> +		pmic_plat_data = tps65910_parse_dt(i2c, &chip_id);
> +
>  	if (!pmic_plat_data)
>  		return -EINVAL;
>  
> @@ -91,7 +169,7 @@ static int tps65910_i2c_probe(struct i2c_client *i2c,
>  	i2c_set_clientdata(i2c, tps65910);
>  	tps65910->dev = &i2c->dev;
>  	tps65910->i2c_client = i2c;
> -	tps65910->id = id->driver_data;
> +	tps65910->id = chip_id;
>  	mutex_init(&tps65910->io_mutex);
>  
>  	tps65910->regmap = regmap_init_i2c(i2c, &tps65910_regmap_config);
> @@ -149,6 +227,7 @@ static struct i2c_driver tps65910_i2c_driver = {
>  	.driver = {
>  		   .name = "tps65910",
>  		   .owner = THIS_MODULE,
> +		   .of_match_table = of_match_ptr(tps65910_of_match),
>  	},
>  	.probe = tps65910_i2c_probe,
>  	.remove = tps65910_i2c_remove,
> -- 
> 1.7.0.4
> 

-- 
Grant Likely, B.Sc, P.Eng.
Secret Lab Technologies, Ltd.

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 5/8 v2] mfd: tps65910: Add device-tree support
@ 2012-05-17 23:55     ` Grant Likely
  0 siblings, 0 replies; 26+ messages in thread
From: Grant Likely @ 2012-05-17 23:55 UTC (permalink / raw)
  To: Mark Brown, Samuel Ortiz, Rob Herring, Liam Girdwood
  Cc: linux-kernel, devicetree-discuss, Rhyland Klein

On Tue, 24 Apr 2012 16:36:07 -0700, Rhyland Klein <rklein@nvidia.com> wrote:
> Add device tree based initialization support for TI's tps65910 pmic.
> 
> Signed-off-by: Rhyland Klein <rklein@nvidia.com>

Patch description is rather light. I like to see some more details
about what the patch changes and testing details are nice too, but
I'll ack it anyway:

Acked-by: Grant Likely <grant.likely@secretlab.ca>

> ---
>  v2: split mfd portion into single change to add dt support
>      added of_node to config before calling regulator_register
>      removed passing pdata to mfd_cell child devices
>      removed use_dt_for_init_data flag
> 
>  drivers/mfd/tps65910.c |   81 +++++++++++++++++++++++++++++++++++++++++++++++-
>  1 files changed, 80 insertions(+), 1 deletions(-)
> 
> diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
> index 70a8079..248fe9f 100644
> --- a/drivers/mfd/tps65910.c
> +++ b/drivers/mfd/tps65910.c
> @@ -23,6 +23,7 @@
>  #include <linux/mfd/core.h>
>  #include <linux/regmap.h>
>  #include <linux/mfd/tps65910.h>
> +#include <linux/of_device.h>
>  
>  static struct mfd_cell tps65910s[] = {
>  	{
> @@ -66,6 +67,78 @@ static const struct regmap_config tps65910_regmap_config = {
>  	.cache_type = REGCACHE_RBTREE,
>  };
>  
> +#ifdef CONFIG_OF
> +static struct of_device_id tps65910_of_match[] = {
> +	{ .compatible = "ti,tps65910", .data = (void *)TPS65910},
> +	{ .compatible = "ti,tps65911", .data = (void *)TPS65911},
> +	{ },
> +};
> +MODULE_DEVICE_TABLE(of, tps65910_of_match);
> +
> +static struct tps65910_board *tps65910_parse_dt(struct i2c_client *client,
> +						int *chip_id)
> +{
> +	struct device_node *np = client->dev.of_node;
> +	struct tps65910_board *board_info;
> +	unsigned int prop;
> +	const struct of_device_id *match;
> +	unsigned int prop_array[TPS6591X_MAX_NUM_GPIO];
> +	int ret = 0;
> +	int idx;
> +
> +	match = of_match_device(tps65910_of_match, &client->dev);
> +	if (!match) {
> +		dev_err(&client->dev, "Failed to find matching dt id\n");
> +		return NULL;
> +	}
> +
> +	*chip_id  = (int)match->data;
> +
> +	board_info = devm_kzalloc(&client->dev, sizeof(*board_info),
> +			GFP_KERNEL);
> +	if (!board_info) {
> +		dev_err(&client->dev, "Failed to allocate pdata\n");
> +		return NULL;
> +	}
> +
> +	ret = of_property_read_u32(np, "ti,vmbch-threshold", &prop);
> +	if (!ret)
> +		board_info->vmbch_threshold = prop;
> +	else if (*chip_id == TPS65911)
> +		dev_warn(&client->dev, "VMBCH-Threshold not specified");
> +
> +	ret = of_property_read_u32(np, "ti,vmbch2-threshold", &prop);
> +	if (!ret)
> +		board_info->vmbch2_threshold = prop;
> +	else if (*chip_id == TPS65911)
> +		dev_warn(&client->dev, "VMBCH2-Threshold not specified");
> +
> +	ret = of_property_read_u32_array(np, "ti,en-gpio-sleep",
> +				   prop_array, TPS6591X_MAX_NUM_GPIO);
> +	if (!ret)
> +		for (idx = 0; idx < ARRAY_SIZE(prop_array); idx++)
> +			board_info->en_gpio_sleep[idx] = (prop_array[idx] != 0);
> +	else if (ret != -EINVAL) {
> +		dev_err(&client->dev,
> +			"error reading property ti,en-gpio-sleep: %d\n.", ret);
> +		return NULL;
> +	}
> +
> +
> +	board_info->irq = client->irq;
> +	board_info->irq_base = -1;
> +	board_info->gpio_base = -1;
> +
> +	return board_info;
> +}
> +#else
> +static inline struct tps65910_board *tps65910_parse_dt(
> +					struct i2c_client *client)
> +{
> +	return NULL;
> +}
> +#endif
> +
>  static int tps65910_i2c_probe(struct i2c_client *i2c,
>  			    const struct i2c_device_id *id)
>  {
> @@ -73,8 +146,13 @@ static int tps65910_i2c_probe(struct i2c_client *i2c,
>  	struct tps65910_board *pmic_plat_data;
>  	struct tps65910_platform_data *init_data;
>  	int ret = 0;
> +	int chip_id = id->driver_data;
>  
>  	pmic_plat_data = dev_get_platdata(&i2c->dev);
> +
> +	if (!pmic_plat_data && i2c->dev.of_node)
> +		pmic_plat_data = tps65910_parse_dt(i2c, &chip_id);
> +
>  	if (!pmic_plat_data)
>  		return -EINVAL;
>  
> @@ -91,7 +169,7 @@ static int tps65910_i2c_probe(struct i2c_client *i2c,
>  	i2c_set_clientdata(i2c, tps65910);
>  	tps65910->dev = &i2c->dev;
>  	tps65910->i2c_client = i2c;
> -	tps65910->id = id->driver_data;
> +	tps65910->id = chip_id;
>  	mutex_init(&tps65910->io_mutex);
>  
>  	tps65910->regmap = regmap_init_i2c(i2c, &tps65910_regmap_config);
> @@ -149,6 +227,7 @@ static struct i2c_driver tps65910_i2c_driver = {
>  	.driver = {
>  		   .name = "tps65910",
>  		   .owner = THIS_MODULE,
> +		   .of_match_table = of_match_ptr(tps65910_of_match),
>  	},
>  	.probe = tps65910_i2c_probe,
>  	.remove = tps65910_i2c_remove,
> -- 
> 1.7.0.4
> 

-- 
Grant Likely, B.Sc, P.Eng.
Secret Lab Technologies, Ltd.

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 7/8 v2] mfd: tps65910-irq: Add devicetree init support
  2012-04-24 23:36   ` Rhyland Klein
@ 2012-05-18  0:00     ` Grant Likely
  -1 siblings, 0 replies; 26+ messages in thread
From: Grant Likely @ 2012-05-18  0:00 UTC (permalink / raw)
  To: Rhyland Klein, Mark Brown, Samuel Ortiz, Rob Herring, Liam Girdwood
  Cc: linux-kernel, devicetree-discuss, Rhyland Klein

On Tue, 24 Apr 2012 16:36:09 -0700, Rhyland Klein <rklein@nvidia.com> wrote:
> Add support for initializing when boot using devicetree. The main difference
> is that the irq_base will not be setup, so it needs to be manually handled.
> 
> Signed-off-by: Rhyland Klein <rklein@nvidia.com>
> ---
>  v2: split off irq specific changes based on previous review comments
> 
>  drivers/mfd/tps65910-irq.c |   21 +++++++++++++++------
>  1 files changed, 15 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/mfd/tps65910-irq.c b/drivers/mfd/tps65910-irq.c
> index 0f1ff7f..066a30f 100644
> --- a/drivers/mfd/tps65910-irq.c
> +++ b/drivers/mfd/tps65910-irq.c
> @@ -180,12 +180,6 @@ int tps65910_irq_init(struct tps65910 *tps65910, int irq,
>  		return -EINVAL;
>  	}
>  
> -	tps65910->irq_mask = 0xFFFFFF;
> -
> -	mutex_init(&tps65910->irq_lock);
> -	tps65910->chip_irq = irq;
> -	tps65910->irq_base = pdata->irq_base;
> -
>  	switch (tps65910_chip_id(tps65910)) {
>  	case TPS65910:
>  		tps65910->irq_num = TPS65910_NUM_IRQ;
> @@ -195,6 +189,21 @@ int tps65910_irq_init(struct tps65910 *tps65910, int irq,
>  		break;
>  	}
>  
> +	if (pdata->irq_base <= 0)
> +		pdata->irq_base = irq_alloc_descs(-1, 0, tps65910->irq_num, -1);

Actually, if irqs are being dynamically allocated, then a irq_domain
linear mapping should be used instead of the legacy one so that sparse
allocations can be used.  The api isn't particularly friendly for that
right now because it means conditionally calling either
irq_domain_add_legacy() vs. irq_domain_add_linear(), but I'll try to
tidy that up for the next merge window.

Regardless, please use the linear mapping when irq_base is not set.

g.


^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 7/8 v2] mfd: tps65910-irq: Add devicetree init support
@ 2012-05-18  0:00     ` Grant Likely
  0 siblings, 0 replies; 26+ messages in thread
From: Grant Likely @ 2012-05-18  0:00 UTC (permalink / raw)
  To: Mark Brown, Samuel Ortiz, Rob Herring, Liam Girdwood
  Cc: linux-kernel, devicetree-discuss, Rhyland Klein

On Tue, 24 Apr 2012 16:36:09 -0700, Rhyland Klein <rklein@nvidia.com> wrote:
> Add support for initializing when boot using devicetree. The main difference
> is that the irq_base will not be setup, so it needs to be manually handled.
> 
> Signed-off-by: Rhyland Klein <rklein@nvidia.com>
> ---
>  v2: split off irq specific changes based on previous review comments
> 
>  drivers/mfd/tps65910-irq.c |   21 +++++++++++++++------
>  1 files changed, 15 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/mfd/tps65910-irq.c b/drivers/mfd/tps65910-irq.c
> index 0f1ff7f..066a30f 100644
> --- a/drivers/mfd/tps65910-irq.c
> +++ b/drivers/mfd/tps65910-irq.c
> @@ -180,12 +180,6 @@ int tps65910_irq_init(struct tps65910 *tps65910, int irq,
>  		return -EINVAL;
>  	}
>  
> -	tps65910->irq_mask = 0xFFFFFF;
> -
> -	mutex_init(&tps65910->irq_lock);
> -	tps65910->chip_irq = irq;
> -	tps65910->irq_base = pdata->irq_base;
> -
>  	switch (tps65910_chip_id(tps65910)) {
>  	case TPS65910:
>  		tps65910->irq_num = TPS65910_NUM_IRQ;
> @@ -195,6 +189,21 @@ int tps65910_irq_init(struct tps65910 *tps65910, int irq,
>  		break;
>  	}
>  
> +	if (pdata->irq_base <= 0)
> +		pdata->irq_base = irq_alloc_descs(-1, 0, tps65910->irq_num, -1);

Actually, if irqs are being dynamically allocated, then a irq_domain
linear mapping should be used instead of the legacy one so that sparse
allocations can be used.  The api isn't particularly friendly for that
right now because it means conditionally calling either
irq_domain_add_legacy() vs. irq_domain_add_linear(), but I'll try to
tidy that up for the next merge window.

Regardless, please use the linear mapping when irq_base is not set.

g.

^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2012-05-18  0:00 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-24 23:36 [PATCH 0/8 v2] Update TPS65910 to boot using devicetree Rhyland Klein
2012-04-24 23:36 ` Rhyland Klein
2012-04-24 23:36 ` [PATCH 1/8 v2] regulator: add generic of node parsing for regulators Rhyland Klein
2012-04-24 23:36   ` Rhyland Klein
2012-04-24 23:36 ` [PATCH 2/8 v2] regulator: add node validation checks Rhyland Klein
2012-04-24 23:36   ` Rhyland Klein
2012-04-24 23:36 ` [PATCH 3/8 v2] mfd: tps65910: Commonize regmap access through header Rhyland Klein
2012-04-24 23:36   ` Rhyland Klein
2012-05-17 23:52   ` Grant Likely
2012-05-17 23:52     ` Grant Likely
2012-04-24 23:36 ` [PATCH 4/8 v2] regulator: tps65910: Add device tree bindings Rhyland Klein
2012-04-24 23:36   ` Rhyland Klein
2012-05-17 23:53   ` Grant Likely
2012-05-17 23:53     ` Grant Likely
2012-04-24 23:36 ` [PATCH 5/8 v2] mfd: tps65910: Add device-tree support Rhyland Klein
2012-04-24 23:36   ` Rhyland Klein
2012-05-17 23:55   ` Grant Likely
2012-05-17 23:55     ` Grant Likely
2012-04-24 23:36 ` [PATCH 6/8 v2] regulator: tps65910 regulator: add device tree support Rhyland Klein
2012-04-24 23:36   ` Rhyland Klein
2012-04-24 23:36 ` [PATCH 7/8 v2] mfd: tps65910-irq: Add devicetree init support Rhyland Klein
2012-04-24 23:36   ` Rhyland Klein
2012-05-18  0:00   ` Grant Likely
2012-05-18  0:00     ` Grant Likely
2012-04-24 23:36 ` [PATCH 8/8 v2] ARM: Tegra: Add support for TPS65910 PMIC Rhyland Klein
2012-04-24 23:36   ` Rhyland Klein

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.