[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <9e24dab6-2e53-b3b4-c323-ab9bf10df3af@manjaro.org>
Date: Tue, 14 Jan 2020 08:17:55 +0100
From: Tobias Schramm <t.schramm@...jaro.org>
To: Sebastian Reichel <sre@...nel.org>
Cc: Rob Herring <robh+dt@...nel.org>,
Mark Rutland <mark.rutland@....com>, linux-pm@...r.kernel.org,
devicetree@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [RESEND 1/2] power: supply: add CW2015 Fuel Gauge driver
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
Powered by blists - more mailing lists