Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1701472 > unrolled thread

[RFC PATCH 2/5] power: generic-adc-battery: Parse more properties from DT

Started byMarek Belisko <marek.belisko@open-nandra.com>
First post2017-08-01 23:00 +0200
Last post2017-08-02 14:00 +0200
Articles 3 — 3 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [RFC PATCH 2/5] power: generic-adc-battery: Parse more properties from DT Marek Belisko <marek.belisko@open-nandra.com> - 2017-08-01 23:00 +0200
    Re: [RFC PATCH 2/5] power: generic-adc-battery: Parse more properties  from DT Belisko Marek <marek.belisko@gmail.com> - 2017-08-02 14:00 +0200
    Re: [RFC PATCH 2/5] power: generic-adc-battery: Parse more  properties from DT Pavel Machek <pavel@ucw.cz> - 2017-08-02 14:00 +0200

#1701472 — [RFC PATCH 2/5] power: generic-adc-battery: Parse more properties from DT

FromMarek Belisko <marek.belisko@open-nandra.com>
Date2017-08-01 23:00 +0200
Subject[RFC PATCH 2/5] power: generic-adc-battery: Parse more properties from DT
Message-ID<u9MqL-nk-29@gated-at.bofh.it>
From: Marek Belisko <marek.belisko@gmail.com>

Signed-off-by: Marek Belisko <marek.belisko@gmail.com>
---
 drivers/power/supply/generic-adc-battery.c | 68 ++++++++++++++++++++++++++++++
 1 file changed, 68 insertions(+)

diff --git a/drivers/power/supply/generic-adc-battery.c b/drivers/power/supply/generic-adc-battery.c
index b5e9208..d4daa6a 100644
--- a/drivers/power/supply/generic-adc-battery.c
+++ b/drivers/power/supply/generic-adc-battery.c
@@ -23,6 +23,7 @@
 #include <linux/iio/consumer.h>
 #include <linux/iio/types.h>
 #include <linux/power/generic-adc-battery.h>
+#include <linux/of_gpio.h>
 
 #define JITTER_DEFAULT 10 /* hope 10ms is enough */
 
@@ -241,6 +242,69 @@ static irqreturn_t gab_charged(int irq, void *dev_id)
 	return IRQ_HANDLED;
 }
 
+#ifdef CONFIG_OF
+static struct gab_platform_data *gab_dt_probe(struct platform_device *pdev)
+{
+	struct gab_platform_data *pdata;
+	struct device_node *np = pdev->dev.of_node;
+	const char *name;
+	u32 val;
+	int err;
+
+	pdata = devm_kzalloc(&pdev->dev,
+			sizeof(struct gab_platform_data),
+			GFP_KERNEL);
+	if (!pdata)
+		return ERR_PTR(-ENOMEM);
+
+	pdata->gpio_charge_finished  = of_get_gpio(np, 0);
+
+	/* parse and fill power_supply_info struct */
+	err = of_property_read_u32(np, "technology", &val);
+	if (err) {
+		dev_info(&pdev->dev, "Battery technology unknown\n");
+		val = 0;
+	}
+	pdata->battery_info.technology = val;
+
+	err = of_property_read_string(np, "battery-name", &name);
+	if (err) {
+		dev_info(&pdev->dev, "Battery name empty, setting default\n");
+	}
+	pdata->battery_info.name = name;
+
+	val = 0;
+	err = of_property_read_u32(np, "charge_empty_design", &val);
+	pdata->battery_info.charge_empty_design = val;
+
+	val = 0;
+	err = of_property_read_u32(np, "charge_full_design", &val);
+	pdata->battery_info.charge_full_design = val;
+
+	val = 0;
+	err = of_property_read_u32(np, "voltage_min_design", &val);
+	pdata->battery_info.voltage_min_design = val;
+
+	val = 0;
+	err = of_property_read_u32(np, "voltage_max-design", &val);
+	pdata->battery_info.voltage_max_design = val;
+
+	return pdata;
+}
+
+static const struct of_device_id of_gab_match[] = {
+	{ .compatible = "linux,generic-adc-battery", },
+	{},
+};
+MODULE_DEVICE_TABLE(of, of_gab_match);
+
+#else
+static struct gab_platform_data gab_dt_probe(struct platform_device *pdev)
+{
+	ERR_PTR(-ENODEV);
+}
+#endif
+
 static int gab_probe(struct platform_device *pdev)
 {
 	struct gab *adc_bat;
@@ -258,6 +322,9 @@ static int gab_probe(struct platform_device *pdev)
 		return -ENOMEM;
 	}
 
+	if (pdata == NULL)
+		pdata = gab_dt_probe(pdev);
+
 	psy_cfg.drv_data = adc_bat;
 	psy_desc = &adc_bat->psy_desc;
 	psy_desc->name = "generic-adc-batt";//pdata->battery_info.name;
@@ -418,6 +485,7 @@ static struct platform_driver gab_driver = {
 	.driver		= {
 		.name	= "generic-adc-battery",
 		.pm	= &gab_pm_ops,
+		.of_match_table = of_gab_match,
 	},
 	.probe		= gab_probe,
 	.remove		= gab_remove,
-- 
2.7.4

[toc] | [next] | [standalone]


#1702049 — Re: [RFC PATCH 2/5] power: generic-adc-battery: Parse more properties from DT

FromBelisko Marek <marek.belisko@gmail.com>
Date2017-08-02 14:00 +0200
SubjectRe: [RFC PATCH 2/5] power: generic-adc-battery: Parse more properties from DT
Message-ID<ua0tI-Vn-27@gated-at.bofh.it>
In reply to#1701472
Hi Pavel,

On Wed, Aug 2, 2017 at 1:56 PM, Pavel Machek <pavel@ucw.cz> wrote:
> Hi!
>
>> +#ifdef CONFIG_OF
>> +static struct gab_platform_data *gab_dt_probe(struct platform_device *pdev)
>> +{
>> +     struct gab_platform_data *pdata;
>> +     struct device_node *np = pdev->dev.of_node;
>> +     const char *name;
>> +     u32 val;
>> +     int err;
>> +
>> +     pdata = devm_kzalloc(&pdev->dev,
>> +                     sizeof(struct gab_platform_data),
>> +                     GFP_KERNEL);
>> +     if (!pdata)
>> +             return ERR_PTR(-ENOMEM);
>> +
>> +     pdata->gpio_charge_finished  = of_get_gpio(np, 0);
>> +
>> +     /* parse and fill power_supply_info struct */
>> +     err = of_property_read_u32(np, "technology", &val);
>> +     if (err) {
>> +             dev_info(&pdev->dev, "Battery technology unknown\n");
>> +             val = 0;
>> +     }
>> +     pdata->battery_info.technology = val;
>> +
>> +     err = of_property_read_string(np, "battery-name", &name);
>> +     if (err) {
>> +             dev_info(&pdev->dev, "Battery name empty, setting default\n");
>> +     }
>> +     pdata->battery_info.name = name;
>
> Actually ... looking at this once more. These are new properties,
> right?
>
> They'll need to be documented:
>
> pavel@duo:/data/l/linux$ grep -ri battery-name Documentation/devicetree/
>
> shows empty.
You're right. I'll add bindings documentation. Thanks.
>                                                                         Pavel
> --
> (english) http://www.livejournal.com/~pavelmachek
> (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

BR,

marek

-- 
as simple and primitive as possible
-------------------------------------------------
Marek Belisko - OPEN-NANDRA
Freelance Developer

Ruska Nova Ves 219 | Presov, 08005 Slovak Republic
Tel: +421 915 052 184
skype: marekwhite
twitter: #opennandra
web: http://open-nandra.com

[toc] | [prev] | [next] | [standalone]


#1702051 — Re: [RFC PATCH 2/5] power: generic-adc-battery: Parse more properties from DT

FromPavel Machek <pavel@ucw.cz>
Date2017-08-02 14:00 +0200
SubjectRe: [RFC PATCH 2/5] power: generic-adc-battery: Parse more properties from DT
Message-ID<ua0tI-Vn-29@gated-at.bofh.it>
In reply to#1701472

[Multipart message — attachments visible in raw view] — view raw

Hi!

> +#ifdef CONFIG_OF
> +static struct gab_platform_data *gab_dt_probe(struct platform_device *pdev)
> +{
> +	struct gab_platform_data *pdata;
> +	struct device_node *np = pdev->dev.of_node;
> +	const char *name;
> +	u32 val;
> +	int err;
> +
> +	pdata = devm_kzalloc(&pdev->dev,
> +			sizeof(struct gab_platform_data),
> +			GFP_KERNEL);
> +	if (!pdata)
> +		return ERR_PTR(-ENOMEM);
> +
> +	pdata->gpio_charge_finished  = of_get_gpio(np, 0);
> +
> +	/* parse and fill power_supply_info struct */
> +	err = of_property_read_u32(np, "technology", &val);
> +	if (err) {
> +		dev_info(&pdev->dev, "Battery technology unknown\n");
> +		val = 0;
> +	}
> +	pdata->battery_info.technology = val;
> +
> +	err = of_property_read_string(np, "battery-name", &name);
> +	if (err) {
> +		dev_info(&pdev->dev, "Battery name empty, setting default\n");
> +	}
> +	pdata->battery_info.name = name;

Actually ... looking at this once more. These are new properties,
right?

They'll need to be documented:

pavel@duo:/data/l/linux$ grep -ri battery-name Documentation/devicetree/

shows empty.
									Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web