devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Vladimir Barinov <vladimir.barinov-M4DtvfQ/ZS1MRgGoP+s0PdBPR1lH4CV8@public.gmane.org>
To: Mark Rutland <mark.rutland-5wv7dgnIgG8@public.gmane.org>
Cc: "anton-9xeibp6oKSgdnm+yROfE0A@public.gmane.org"
	<anton-9xeibp6oKSgdnm+yROfE0A@public.gmane.org>,
	"dwmw2-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org"
	<dwmw2-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>,
	"linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org"
	<linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	"devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org"
	<devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	"mk7.kang-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org"
	<mk7.kang-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
Subject: Re: [PATCH 1/3] power_supply: modelgauge_battery: Maxim ModelGauge ICs gauge
Date: Fri, 10 Jan 2014 18:29:00 +0400	[thread overview]
Message-ID: <52D003AC.3000808@cogentembedded.com> (raw)
In-Reply-To: <20140110111130.GD6798-NuALmloUBlrZROr8t4l/smS4ubULX0JqMm0uRHvK7Nw@public.gmane.org>

Hello,

On 01/10/2014 03:11 PM, Mark Rutland wrote:
> On Thu, Jan 09, 2014 at 04:49:03PM +0000, Vladimir Barinov wrote:
>> Add Maxim ModelGauge ICs gauge driver for MAX17040/41/43/44/48/49/58/59 chips
>>
>> Signed-off-by: Vladimir Barinov<vladimir.barinov-M4DtvfQ/ZS1MRgGoP+s0PdBPR1lH4CV8@public.gmane.org>
>>
>> ---
>>   drivers/power/Kconfig                            |    8
>>   drivers/power/Makefile                           |    1
>>   drivers/power/modelgauge_battery.c               |  875 +++++++++++++++++++++++
>>   include/linux/platform_data/battery-modelgauge.h |   44 +
>>   4 files changed, 928 insertions(+)
> [...]
>
>> +static struct modelgauge_platform_data *modelgauge_parse_dt(struct device *dev)
>> +{
>> +       struct device_node *np = dev->of_node;
>> +       struct modelgauge_platform_data *pdata;
>> +       struct property *prop;
>> +
>> +       if (!of_get_property(np, "maxim,empty_alert_threshold", NULL)&&
>> +           !of_get_property(np, "maxim,soc_change_alert", NULL)&&
>> +           !of_get_property(np, "maxim,hibernate_threshold", NULL)&&
>> +           !of_get_property(np, "maxim,active_threshold", NULL)&&
>> +           !of_get_property(np, "maxim,undervoltage", NULL)&&
>> +           !of_get_property(np, "maxim,overvoltage", NULL)&&
>> +           !of_get_property(np, "maxim,resetvoltage", NULL))
>> +               return NULL;
> These were described as optional in the binding. It wasn't clear that to
> have one you need the others. It would be nice for that to be clarified
> in the binding.
Yes, since they are optional then we'll return NULL here, that means no 
platform data provided.
The "if" statement checked if nothing was provided in DT then there is 
not platform data.

Since, you requested to remove above binding from DT and make the driver 
to take care, then I'll move them to sysfs.
>
>> +
>> +       pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
>> +       if (!pdata)
>> +               return NULL;
>> +
>> +       of_property_read_u8(np, "maxim,empty_alert_threshold",
>> +&pdata->empty_alert_threshold);
>> +       pdata->soc_change_alert =
>> +                       of_property_read_bool(np, "maxim,soc_change_alert");
> As mentioned in my comments on the binding document, I don't think this
> property is necessary at all.
Yes, I will move it into driver.
>
>> +       of_property_read_u8(np, "maxim,hibernate_threshold",
>> +&pdata->hibernate_threshold);
>> +       of_property_read_u8(np, "maxim,active_threshold",
>> +&pdata->active_threshold);
>> +       of_property_read_u16(np, "maxim,undervoltage",&pdata->undervoltage);
>> +       of_property_read_u16(np, "maxim,overvoltage",&pdata->overvoltage);
>> +       of_property_read_u16(np, "maxim,resetvoltage",&pdata->resetvoltage);
Ditto for above.
>> +
>> +       prop = of_find_property(np, "maxim,ocvtest", NULL);
> Here you seem to be using of_find_property to check if a property is
> present, but earlier you used of_get_property for this purpose. It would
> be nice if one or the other were used consistently.
Since above code will be removed then only this parameter will be used 
for battery specific data presence check.
>
>> +       if (prop) {
>> +               pdata->model = devm_kzalloc(dev, sizeof(*pdata->model),
>> +                                           GFP_KERNEL);
>> +               if (!pdata->model)
>> +                       return NULL;
>> +
>> +               of_property_read_u8(np, "maxim,empty_adjustment",
>> +&pdata->model->empty_adjustment);
>> +               of_property_read_u8(np, "maxim,full_adjustment",
>> +&pdata->model->full_adjustment);
>> +               of_property_read_u8(np, "maxim,rcomp0",
>> +&pdata->model->rcomp0);
>> +               prop = of_find_property(np, "maxim,temp_co_up", NULL);
>> +               if (prop)
>> +                       pdata->model->temp_co_up = be32_to_cpup(prop->value);
> Use of_property_read_u32. If it can't read the property it won't
> modify the pointer it's been handed, and it handles the endianness
> conversion.
>
> You seem to be happy to use of_property_read_u{8,16}, so I don't
> understand why you are treating 32-bit differently.
Because the this property is signed. So I can't use of_property_read_u32.
>
>> +               prop = of_find_property(np, "maxim,temp_co_down", NULL);
>> +               if (prop)
>> +                       pdata->model->temp_co_down = be32_to_cpup(prop->value);
> Likewise.
Ditto.
>
>> +               of_property_read_u16(np, "maxim,ocvtest",
>> +&pdata->model->ocvtest);
> While you've checked that this property was present earlier, you don't
> know it's size. You might want to check the return value of
> of_property_read_u16 (and you might want to do so for other accessors
> too).
Ok, I will add checking of of_property_read_XX() return values.
>
>> +               of_property_read_u8(np, "maxim,soc_check_a",
>> +&pdata->model->soc_check_a);
>> +               of_property_read_u8(np, "maxim,soc_check_b",
>> +&pdata->model->soc_check_b);
>> +               of_property_read_u8(np, "maxim,bits",
>> +&pdata->model->bits);
>> +               of_property_read_u16(np, "maxim,rcomp_seg",
>> +&pdata->model->rcomp_seg);
>> +       }
>> +
>> +       prop = of_find_property(np, "maxim,model_data", NULL);
>> +       if (prop&&  prop->length == MODELGAUGE_TABLE_SIZE) {
>> +               pdata->model->model_data = devm_kzalloc(dev,
>> +                                                       MODELGAUGE_TABLE_SIZE,
>> +                                                       GFP_KERNEL);
>> +               if (!pdata->model->model_data)
>> +                       return NULL;
>> +
>> +               of_property_read_u8_array(np, "maxim,model_data",
>> +                                         pdata->model->model_data,
>> +                                         MODELGAUGE_TABLE_SIZE);
>> +       }
> It's probably worth printing a warning or error if this isn't the size
> you expect (perhaps failing to probe).
okay.
>
>> +
>> +       return pdata;
>> +}
> Thanks,
> Mark.
Regards,
Vladimir

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2014-01-10 14:29 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-09 16:49 [PATCH 0/3] power_supply: modelgauge_battery: Add Maxim ModelGauge ICs gauge Vladimir Barinov
     [not found] ` <1389286145-15375-1-git-send-email-vladimir.barinov-M4DtvfQ/ZS1MRgGoP+s0PdBPR1lH4CV8@public.gmane.org>
2014-01-09 16:49   ` [PATCH 1/3] power_supply: modelgauge_battery: " Vladimir Barinov
2014-01-10 11:11     ` Mark Rutland
     [not found]       ` <20140110111130.GD6798-NuALmloUBlrZROr8t4l/smS4ubULX0JqMm0uRHvK7Nw@public.gmane.org>
2014-01-10 14:29         ` Vladimir Barinov [this message]
2014-01-14 16:31     ` Krzysztof Kozlowski
2014-01-15 10:20       ` Vladimir Barinov
2014-01-09 16:49   ` [PATCH 3/3] power_supply: modelgauge_battery: Remove Maxim MAX17040 gauge Vladimir Barinov
2014-01-09 16:49 ` [PATCH 2/3] dt: Document ModelGauge gauge bindings Vladimir Barinov
     [not found]   ` <1389286145-15375-3-git-send-email-vladimir.barinov-M4DtvfQ/ZS1MRgGoP+s0PdBPR1lH4CV8@public.gmane.org>
2014-01-10  1:00     ` Kyungmin Park
2014-01-10 12:59       ` Vladimir Barinov
2014-01-10 10:56     ` Mark Rutland
2014-01-10 14:08       ` Vladimir Barinov
2014-01-14 15:59 ` [PATCH 0/3] power_supply: modelgauge_battery: Add Maxim ModelGauge ICs gauge Krzysztof Kozlowski
2014-01-14 16:29 ` Krzysztof Kozlowski
     [not found]   ` <52D565D5.4050704-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2014-01-15 10:16     ` Vladimir Barinov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=52D003AC.3000808@cogentembedded.com \
    --to=vladimir.barinov-m4dtvfq/zs1mrggop+s0pdbpr1lh4cv8@public.gmane.org \
    --cc=anton-9xeibp6oKSgdnm+yROfE0A@public.gmane.org \
    --cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=dwmw2-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=mark.rutland-5wv7dgnIgG8@public.gmane.org \
    --cc=mk7.kang-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).