mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tobias Schramm <t.schramm@manjaro.org>
To: Sebastian Reichel <sre@kernel.org>
Cc: Rob Herring <robh+dt@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	linux-pm@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [RESEND 1/2] power: supply: add CW2015 Fuel Gauge driver
Date: Tue, 14 Jan 2020 08:17:55 +0100	[thread overview]
Message-ID: <9e24dab6-2e53-b3b4-c323-ab9bf10df3af@manjaro.org> (raw)
In-Reply-To: <20200114020616.3pg4yssrtuwxjd32@earth.universe>

Hi Sebastian,

thanks for the review!

>> +#ifdef CONFIG_OF
>> +static int cw2015_parse_dt(struct cw_battery *cw_bat)
>> +{
>> +	struct device *dev = &cw_bat->client->dev;
>> +	struct device_node *node = dev->of_node;
>> +	struct property *prop;
>> +	int length;
>> +	u32 value;
>> +	int ret;
>> +	struct cw_bat_platform_data *data = &cw_bat->plat_data;
>> +
>> +	if (!node)
>> +		return -ENODEV;
>> +
>> +	memset(data, 0, sizeof(*data));
>> +
>> +	/* determine the number of config info */
>> +	prop = of_find_property(node, PREFIX"bat-config-info", &length);
>> +	if (!prop)
>> +		return -EINVAL;
>> +
>> +	length /= sizeof(u32);
>> +
>> +	if (length > 0) {
>> +		size_t size = sizeof(*data->cw_bat_config_info) * length;
>> +
>> +		data->cw_bat_config_info = devm_kzalloc(dev, size, GFP_KERNEL);
>> +		if (!data->cw_bat_config_info)
>> +			return -ENOMEM;
>> +
>> +		ret = of_property_read_u32_array(node, PREFIX"bat-config-info",
>> +						 data->cw_bat_config_info,
>> +						 length);
>> +		if (ret < 0)
>> +			return ret;
>> +	}
> 
> In its current state it does not look like data for DT. What
> information is stored in this "config info"?
>
Truth is: I don't know. The format of this blob is neither disclosed nor 
even mentioned by publicly available datasheets.
As far as I can tell it is information about the battery used, most 
likely data on chemistry and design capacity of the pack.
Since this depends on the cell built into a device I'd expect it to be 
located in the DT.

>> +	cw_bat->bat_mode = MODE_BATTERY;
>> +	cw_bat->monitor_sec = CW2015_DEFAULT_MONITOR_SEC *
>> +			      CW2015_TIMER_MS_COUNTS;
>> +
>> +	prop = of_find_property(node, PREFIX"voltage-divider", &length);
>> +	if (prop) {
>> +		length /= sizeof(u32);
>> +		if (length != 2) {
>> +			dev_err(dev, "Length of voltage divider array must be "
>> +				"2, not %u\n", length);
>> +			return -EINVAL;
>> +		}
>> +		ret = of_property_read_u32_index(node, PREFIX"voltage-divider",
>> +						 0, &data->divider_high);
>> +		if (ret) {
>> +			dev_err(dev, "Failed to read value of high side "
>> +				"voltage divider resistor: %d\n", ret);
>> +			return ret;
>> +		}
>> +		ret = of_property_read_u32_index(node, PREFIX"voltage-divider",
>> +						 1, &data->divider_low);
>> +		if (ret) {
>> +			dev_err(dev, "Failed to read value of low side "
>> +				"voltage divider resistor: %d\n", ret);
>> +			return ret;
>> +		}
>> +	}
>> +
>> +	ret = of_property_read_u32(node, PREFIX"divider-res2", &value);
>> +	if (ret < 0)
>> +		value = 0;
>> +	data->divider_low = value;
>> +
>> +	ret = of_property_read_u32(node, PREFIX"virtual-power", &value);
>> +	if (ret < 0)
>> +		value = 0;
>> +	cw_bat->bat_mode = value;
> 
> of_property_read_bool
> 
>> +	ret = of_property_read_u32(node, PREFIX"monitor-interval", &value);
>> +	if (ret < 0)
>> +		dev_err(dev, "monitor-interval missing!\n");
>> +	else
>> +		cw_bat->monitor_sec = value * CW2015_TIMER_MS_COUNTS;
>> +
>> +	ret = of_property_read_u32(node, PREFIX"design-capacity", &value);
>> +	if (ret < 0) {
>> +		dev_err(dev, "design-capacity missing!\n");
>> +		data->design_capacity = 2000;
>> +	} else {
>> +		data->design_capacity = value;
>> +	}
>> +
>> +	of_property_read_u8(node, PREFIX"alert-level", &cw_bat->alert_level);
>> +	if (cw_bat->alert_level > 100) {
>> +		dev_err(dev, "invalid alert_level, clamping to 100 %%\n");
>> +		cw_bat->alert_level = 100;
>> +	}
> 
> This does not belong into DT.
>
Is there any interface that allows setting a hardware battery alert 
level? Or should I just drop it altogether?

Tobias

  reply	other threads:[~2020-01-14  7:18 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-09 11:39 [RESEND 0/2] power: supply: add support for CW2015 fuel gauge Tobias Schramm
2020-01-09 11:39 ` [RESEND 1/2] power: supply: add CW2015 Fuel Gauge driver Tobias Schramm
2020-01-14  2:06   ` Sebastian Reichel
2020-01-14  7:17     ` Tobias Schramm [this message]
2020-01-09 11:39 ` [RESEND 2/2] dt-bindings: power: supply: cw2015_battery: add device tree binding documentation Tobias Schramm
2020-01-15  2:01   ` Rob Herring

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=9e24dab6-2e53-b3b4-c323-ab9bf10df3af@manjaro.org \
    --to=t.schramm@manjaro.org \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=robh+dt@kernel.org \
    --cc=sre@kernel.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

all inboxes | Powered by JetHome®