linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2 v2] power: bq20z75: devicetree init support
@ 2011-09-10  0:47 Rhyland Klein
  2011-09-10  0:47 ` [PATCH 2/2 v2] power: bq20z75: Add Device Tree Binding Rhyland Klein
  2011-09-12 20:45 ` [PATCH 1/2 v2] power: bq20z75: devicetree init support Grant Likely
  0 siblings, 2 replies; 4+ messages in thread
From: Rhyland Klein @ 2011-09-10  0:47 UTC (permalink / raw)
  To: linux-arm-kernel

Adding support to generate platform data when kernel is configured
through device tree.

Signed-off-by: Rhyland Klein <rklein@nvidia.com>
---
	v2: Fixed typo in binding description

 drivers/power/bq20z75.c |   73 +++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 73 insertions(+), 0 deletions(-)

diff --git a/drivers/power/bq20z75.c b/drivers/power/bq20z75.c
index 9c5e5be..922f725 100644
--- a/drivers/power/bq20z75.c
+++ b/drivers/power/bq20z75.c
@@ -613,6 +613,76 @@ static void bq20z75_delayed_work(struct work_struct *work)
 	}
 }
 
+#if defined(CONFIG_OF)
+#include <linux/of_device.h>
+static const struct of_device_id bq20z75_dt_ids[] = {
+	{ .compatible = "ti,bq20z75" },
+	{ }
+};
+MODULE_DEVICE_TABLE(platform, bq20z75_dt_ids);
+
+static struct bq20z75_platform_data *bq20z75_of_populate_pdata(
+	struct i2c_client *client)
+{
+	const struct of_device_id *dtid;
+	struct device_node *of_node = client->dev.of_node;
+	struct bq20z75_platform_data *pdata = client->dev.platform_data;
+	int rc;
+	u32 prop;
+
+	/* verify this driver matches this device */
+	dtid = of_match_device(bq20z75_dt_ids, &client->dev);
+	if (!dtid)
+		return NULL;
+
+	/* if platform data is set, honor it */
+	if (pdata)
+		return pdata;
+
+	/* first make sure at least one property is set, otherwise
+	 * it won't change behavior from running without pdata.
+	 */
+	if (!of_get_property(of_node, "i2c-retry-count", NULL) &&
+		!of_get_property(of_node, "poll-retry-count", NULL) &&
+		!of_get_property(of_node, "battery-detect", NULL) &&
+		!of_get_property(of_node, "battery-detect-present", NULL))
+		goto of_out;
+
+	pdata = devm_kzalloc(&client->dev, sizeof(struct bq20z75_platform_data),
+				GFP_KERNEL);
+	if (!pdata)
+		goto of_out;
+
+	rc = of_property_read_u32(of_node, "i2c-retry-count", &prop);
+	if (!rc)
+		pdata->i2c_retry_count = prop;
+
+	rc = of_property_read_u32(of_node, "battery-detect", &prop);
+	if (!rc)
+		pdata->battery_detect = prop;
+	else
+		pdata->battery_detect = -1; /*default is no gpio */
+
+	rc = of_property_read_u32(of_node, "battery-detect-present", &prop);
+	if (!rc)
+		pdata->battery_detect_present = prop;
+
+	rc = of_property_read_u32(of_node, "poll-retry-count", &prop);
+	if (!rc)
+		pdata->poll_retry_count = prop;
+
+of_out:
+	return pdata;
+}
+#else
+#define bq20z75_dt_ids NULL
+static struct bq20z75_platform_data *bq20z75_of_populate_pdata(
+	struct i2c_client *client)
+{
+	return NULL;
+}
+#endif
+
 static int __devinit bq20z75_probe(struct i2c_client *client,
 	const struct i2c_device_id *id)
 {
@@ -642,6 +712,8 @@ static int __devinit bq20z75_probe(struct i2c_client *client,
 	bq20z75_device->power_supply.external_power_changed =
 		bq20z75_external_power_changed;
 
+	pdata = bq20z75_of_populate_pdata(client);
+
 	if (pdata) {
 		bq20z75_device->gpio_detect =
 			gpio_is_valid(pdata->battery_detect);
@@ -775,6 +847,7 @@ static struct i2c_driver bq20z75_battery_driver = {
 	.id_table	= bq20z75_id,
 	.driver = {
 		.name	= "bq20z75-battery",
+		.of_match_table = bq20z75_dt_ids,
 	},
 };
 
-- 
1.7.6

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

* [PATCH 2/2 v2] power: bq20z75: Add Device Tree Binding
  2011-09-10  0:47 [PATCH 1/2 v2] power: bq20z75: devicetree init support Rhyland Klein
@ 2011-09-10  0:47 ` Rhyland Klein
  2011-09-12 20:43   ` Grant Likely
  2011-09-12 20:45 ` [PATCH 1/2 v2] power: bq20z75: devicetree init support Grant Likely
  1 sibling, 1 reply; 4+ messages in thread
From: Rhyland Klein @ 2011-09-10  0:47 UTC (permalink / raw)
  To: linux-arm-kernel

Adding the binding for the TI bq20z75 fuel gadge and the
bq20z75 driver.

Signed-off-by: Rhyland Klein <rklein@nvidia.com>
---
 .../bindings/power_supply/ti_bq20z75.txt           |   25 ++++++++++++++++++++
 1 files changed, 25 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/power_supply/ti_bq20z75.txt

diff --git a/Documentation/devicetree/bindings/power_supply/ti_bq20z75.txt b/Documentation/devicetree/bindings/power_supply/ti_bq20z75.txt
new file mode 100644
index 0000000..3deccfe
--- /dev/null
+++ b/Documentation/devicetree/bindings/power_supply/ti_bq20z75.txt
@@ -0,0 +1,25 @@
+TI bq20z75
+~~~~~~~~~~
+
+Required properties :
+ - compatible : "ti,bq20z75"
+
+Optional properties :
+ - i2c-retry-count : The number of times to retry i2c transactions on i2c
+   IO failure.
+ - poll-retry-count : The number of times to try looking for new status
+   after an external change notification.
+ - battery-detect : The GPIO which is used to detect battery presence.
+ - battery-detect-present : The state of the GPIO when the battery is
+   present ( 0 or 1).
+
+Example:
+
+	bq20z75 at b {
+		compatible = "ti,bq20z75";
+		reg = < 0xb >;
+		i2c-retry-count = <2>;
+		poll-retry-count = <10>;
+		battery-detect = <314>;
+		battery-detect-present = <0>;
+	}
-- 
1.7.6

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

* [PATCH 2/2 v2] power: bq20z75: Add Device Tree Binding
  2011-09-10  0:47 ` [PATCH 2/2 v2] power: bq20z75: Add Device Tree Binding Rhyland Klein
@ 2011-09-12 20:43   ` Grant Likely
  0 siblings, 0 replies; 4+ messages in thread
From: Grant Likely @ 2011-09-12 20:43 UTC (permalink / raw)
  To: linux-arm-kernel

On Fri, Sep 09, 2011 at 05:47:49PM -0700, Rhyland Klein wrote:
> Adding the binding for the TI bq20z75 fuel gadge and the
> bq20z75 driver.
> 
> Signed-off-by: Rhyland Klein <rklein@nvidia.com>
> ---
>  .../bindings/power_supply/ti_bq20z75.txt           |   25 ++++++++++++++++++++
>  1 files changed, 25 insertions(+), 0 deletions(-)
>  create mode 100644 Documentation/devicetree/bindings/power_supply/ti_bq20z75.txt
> 
> diff --git a/Documentation/devicetree/bindings/power_supply/ti_bq20z75.txt b/Documentation/devicetree/bindings/power_supply/ti_bq20z75.txt
> new file mode 100644
> index 0000000..3deccfe
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/power_supply/ti_bq20z75.txt
> @@ -0,0 +1,25 @@
> +TI bq20z75
> +~~~~~~~~~~
> +
> +Required properties :
> + - compatible : "ti,bq20z75"
> +
> +Optional properties :
> + - i2c-retry-count : The number of times to retry i2c transactions on i2c
> +   IO failure.
> + - poll-retry-count : The number of times to try looking for new status
> +   after an external change notification.

Prefix custom properties with a vendor string.  ie. "ti,"

> + - battery-detect : The GPIO which is used to detect battery presence.
> + - battery-detect-present : The state of the GPIO when the battery is
> +   present ( 0 or 1).

Use the gpios binding here.  Should be encoded as a single property
that uses the flags field for the polarity.  Something like:

	battery-detect-gpios = <&gpio-controller 10 0>;

g.

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

* [PATCH 1/2 v2] power: bq20z75: devicetree init support
  2011-09-10  0:47 [PATCH 1/2 v2] power: bq20z75: devicetree init support Rhyland Klein
  2011-09-10  0:47 ` [PATCH 2/2 v2] power: bq20z75: Add Device Tree Binding Rhyland Klein
@ 2011-09-12 20:45 ` Grant Likely
  1 sibling, 0 replies; 4+ messages in thread
From: Grant Likely @ 2011-09-12 20:45 UTC (permalink / raw)
  To: linux-arm-kernel

On Fri, Sep 09, 2011 at 05:47:48PM -0700, Rhyland Klein wrote:
> Adding support to generate platform data when kernel is configured
> through device tree.
> 
> Signed-off-by: Rhyland Klein <rklein@nvidia.com>
> ---
> 	v2: Fixed typo in binding description
> 
>  drivers/power/bq20z75.c |   73 +++++++++++++++++++++++++++++++++++++++++++++++
>  1 files changed, 73 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/power/bq20z75.c b/drivers/power/bq20z75.c
> index 9c5e5be..922f725 100644
> --- a/drivers/power/bq20z75.c
> +++ b/drivers/power/bq20z75.c
> @@ -613,6 +613,76 @@ static void bq20z75_delayed_work(struct work_struct *work)
>  	}
>  }
>  
> +#if defined(CONFIG_OF)
> +#include <linux/of_device.h>
> +static const struct of_device_id bq20z75_dt_ids[] = {
> +	{ .compatible = "ti,bq20z75" },
> +	{ }
> +};
> +MODULE_DEVICE_TABLE(platform, bq20z75_dt_ids);
> +
> +static struct bq20z75_platform_data *bq20z75_of_populate_pdata(
> +	struct i2c_client *client)
> +{
> +	const struct of_device_id *dtid;
> +	struct device_node *of_node = client->dev.of_node;
> +	struct bq20z75_platform_data *pdata = client->dev.platform_data;
> +	int rc;
> +	u32 prop;
> +
> +	/* verify this driver matches this device */
> +	dtid = of_match_device(bq20z75_dt_ids, &client->dev);
> +	if (!dtid)
> +		return NULL;

Just the fact that of_node pointer is set means that a match was made
against the table.  No need for calling of_match_device.

> +
> +	/* if platform data is set, honor it */
> +	if (pdata)
> +		return pdata;
> +
> +	/* first make sure at least one property is set, otherwise
> +	 * it won't change behavior from running without pdata.
> +	 */
> +	if (!of_get_property(of_node, "i2c-retry-count", NULL) &&
> +		!of_get_property(of_node, "poll-retry-count", NULL) &&
> +		!of_get_property(of_node, "battery-detect", NULL) &&
> +		!of_get_property(of_node, "battery-detect-present", NULL))
> +		goto of_out;
> +
> +	pdata = devm_kzalloc(&client->dev, sizeof(struct bq20z75_platform_data),
> +				GFP_KERNEL);
> +	if (!pdata)
> +		goto of_out;
> +
> +	rc = of_property_read_u32(of_node, "i2c-retry-count", &prop);
> +	if (!rc)
> +		pdata->i2c_retry_count = prop;
> +
> +	rc = of_property_read_u32(of_node, "battery-detect", &prop);
> +	if (!rc)
> +		pdata->battery_detect = prop;
> +	else
> +		pdata->battery_detect = -1; /*default is no gpio */
> +
> +	rc = of_property_read_u32(of_node, "battery-detect-present", &prop);
> +	if (!rc)
> +		pdata->battery_detect_present = prop;
> +
> +	rc = of_property_read_u32(of_node, "poll-retry-count", &prop);
> +	if (!rc)
> +		pdata->poll_retry_count = prop;
> +
> +of_out:
> +	return pdata;
> +}
> +#else
> +#define bq20z75_dt_ids NULL
> +static struct bq20z75_platform_data *bq20z75_of_populate_pdata(
> +	struct i2c_client *client)
> +{
> +	return NULL;
> +}
> +#endif
> +
>  static int __devinit bq20z75_probe(struct i2c_client *client,
>  	const struct i2c_device_id *id)
>  {
> @@ -642,6 +712,8 @@ static int __devinit bq20z75_probe(struct i2c_client *client,
>  	bq20z75_device->power_supply.external_power_changed =
>  		bq20z75_external_power_changed;
>  
> +	pdata = bq20z75_of_populate_pdata(client);
> +
>  	if (pdata) {
>  		bq20z75_device->gpio_detect =
>  			gpio_is_valid(pdata->battery_detect);
> @@ -775,6 +847,7 @@ static struct i2c_driver bq20z75_battery_driver = {
>  	.id_table	= bq20z75_id,
>  	.driver = {
>  		.name	= "bq20z75-battery",
> +		.of_match_table = bq20z75_dt_ids,
>  	},
>  };
>  
> -- 
> 1.7.6
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo at vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/

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

end of thread, other threads:[~2011-09-12 20:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-09-10  0:47 [PATCH 1/2 v2] power: bq20z75: devicetree init support Rhyland Klein
2011-09-10  0:47 ` [PATCH 2/2 v2] power: bq20z75: Add Device Tree Binding Rhyland Klein
2011-09-12 20:43   ` Grant Likely
2011-09-12 20:45 ` [PATCH 1/2 v2] power: bq20z75: devicetree init support Grant Likely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).