From: Hans de Goede <hdegoede@redhat.com>
To: Krzysztof Kozlowski <krzk@kernel.org>
Cc: Sebastian Reichel <sre@kernel.org>,
Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>,
linux-pm@vger.kernel.org
Subject: Re: [PATCH 04/13] power: max17042_battery: Add default platform_data for x86 use
Date: Fri, 14 Apr 2017 19:11:51 +0200 [thread overview]
Message-ID: <f872ad19-397d-3c69-f00e-63a1ff33932e@redhat.com> (raw)
In-Reply-To: <20170414160727.bcpoven53zay42is@kozik-lap>
Hi,
On 14-04-17 17:54, Krzysztof Kozlowski wrote:
> On Fri, Apr 14, 2017 at 05:43:37PM +0200, Hans de Goede wrote:
>> Hi,
>>
>> On 14-04-17 17:35, Krzysztof Kozlowski wrote:
>>> On Fri, Apr 14, 2017 at 02:59:10PM +0200, Hans de Goede wrote:
>>>> Some x86 machines use a max17047 fuel-gauge. X86 does not have board
>>>> files / dt to provide platform data, so add default platform_data
>>>> as fallback option so that the driver can work on x86.
>>>
>>> I am not convinced by this explanation. AFAIR, the x86 boards which use
>>> max17042-family are providing the platform data. See commit edd4ab055931
>>> ("power: max17042_battery: add HEALTH and TEMP_* properties support").
>>
>> Yes that commits adds the members to the struct max17042_platform_data,
>> but if you grep through the mainline kernel there is no code what so
>> ever ever filling such a struct.
>
> Yes, my assumption was they are coming out of tree - through Simple
> Firmware Interface. At least that was how I understood Ramakrishna's
> reply:
> https://patchwork.kernel.org/patch/6326981/
>
> I think the commit message is a little bit non-precise here. How about
> changing the initial sentence adding "might" ("86 might be missing platform_data if
> not provided by SFI" or something similar).
Ok, will do for v2.
>> Since not all boards have a thermistor hooked up, set temp_min to 0 and
>> change the health checks from temp <= temp_min to temp < temp_min to
>> not trigger on such boards (where temp reads 0).
>>
>> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
>> ---
>> drivers/power/supply/max17042_battery.c | 60 +++++++++++++++++++++++++++++----
>> 1 file changed, 53 insertions(+), 7 deletions(-)
>>
>> diff --git a/drivers/power/supply/max17042_battery.c b/drivers/power/supply/max17042_battery.c
>> index a51b296..85a6bf3 100644
>> --- a/drivers/power/supply/max17042_battery.c
>> +++ b/drivers/power/supply/max17042_battery.c
>> @@ -150,12 +150,12 @@ static int max17042_get_battery_health(struct max17042_chip *chip, int *health)
>> if (ret < 0)
>> goto health_error;
>>
>> - if (temp <= chip->pdata->temp_min) {
>> + if (temp < chip->pdata->temp_min) {
>> *health = POWER_SUPPLY_HEALTH_COLD;
>> goto out;
>> }
>>
>> - if (temp >= chip->pdata->temp_max) {
>> + if (temp > chip->pdata->temp_max) {
>> *health = POWER_SUPPLY_HEALTH_OVERHEAT;
>> goto out;
>> }
>> @@ -772,8 +772,9 @@ static void max17042_init_worker(struct work_struct *work)
>>
>> #ifdef CONFIG_OF
>> static struct max17042_platform_data *
>> -max17042_get_pdata(struct device *dev)
>> +max17042_get_pdata(struct max17042_chip *chip)
>> {
>> + struct device *dev = &chip->client->dev;
>> struct device_node *np = dev->of_node;
>> u32 prop;
>> struct max17042_platform_data *pdata;
>> @@ -806,10 +807,55 @@ max17042_get_pdata(struct device *dev)
>> return pdata;
>> }
>> #else
>> +static struct max17042_reg_data max17047_default_pdata_init_regs[] = {
>> + /*
>> + * Some firmwares do not set FullSOCThr, Enable End-of-Charge Detection
>> + * when the voltage FG reports 95%, as recommend in the datasheet.
>> + */
>> + { MAX17047_FullSOCThr, 95 << 8 },
>
> Maybe use MAX17042_BATTERY_FULL (and replace it to 95?). If not the
> MAX17042_BATTERY_FULL can be removed in separate patch.
Ok, will do for v2.
>> +};
>> +
>> static struct max17042_platform_data *
>> -max17042_get_pdata(struct device *dev)
>> +max17042_get_pdata(struct max17042_chip *chip)
>> {
>> - return dev->platform_data;
>> + struct device *dev = &chip->client->dev;
>> + struct max17042_platform_data *pdata;
>> + int ret, misc_cfg;
>> +
>> + if (dev->platform_data)
>> + return dev->platform_data;
>> +
>> + /*
>> + * The MAX17047 gets used on x86 where we've no platform data, assume
>> + * the firmware will already have initialized the fuel-gauge and provide
>> + * default values for the non init bits to make things work.
>> + */
>> + pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
>> + if (!pdata)
>> + return pdata;
>> +
>> + if (chip->chip_type != MAXIM_DEVICE_TYPE_MAX17042) {
>> + pdata->init_data = max17047_default_pdata_init_regs;
>> + pdata->num_init_data =
>> + ARRAY_SIZE(max17047_default_pdata_init_regs);
>> + }
>> +
>> + ret = regmap_read(chip->regmap, MAX17042_MiscCFG, &misc_cfg);
>> + if (ret < 0)
>> + return NULL;
>> +
>> + /* If bits 0-1 are set to 3 then only Voltage readings are used */
>> + if ((misc_cfg & 0x3) == 3)
>
> Mixing 0x3 and 3 looks suspicious. How about " == 0x3"?
Ok, will do for v2.
>> + pdata->enable_current_sense = false;
>> + else
>> + pdata->enable_current_sense = true;
>
> In that case you need to set the r_sns (unless
> MAX17042_DEFAULT_SNS_RESISTOR is okay for you).
The default value is ok for me / my board.
>> +
>> + pdata->vmin = 3000;
>> + pdata->vmax = 4500; /* Some devices use a LiHV cell */
>> + pdata->temp_min = 0; /* Some devices do not have a temp sensor */
>> + pdata->temp_max = 700; /* 70 degrees Celcius */
>
> How about putting all of these hard-coded numbers next to
> MAX17042_DEFAULT_SNS_RESISTOR?
Ok, will also do for v2 :)
Thank you for all the reviews.
Regards,
Hans
next prev parent reply other threads:[~2017-04-14 17:11 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-14 12:59 [PATCH 01/13] power: Make power_supply_am_i_supplied return -ENODEV if there are no suppliers Hans de Goede
2017-04-14 12:59 ` [PATCH 02/13] power: max17042_battery: Use sign_extend32 instead of DIY code Hans de Goede
2017-04-14 15:29 ` Krzysztof Kozlowski
2017-04-14 12:59 ` [PATCH 03/13] power: max17047_battery: The temp alert values are 8-bit 2's complement Hans de Goede
2017-04-14 15:09 ` Krzysztof Kozlowski
2017-04-14 15:16 ` Hans de Goede
2017-04-14 15:26 ` Krzysztof Kozlowski
2017-04-14 15:36 ` Hans de Goede
2017-04-14 15:39 ` Krzysztof Kozlowski
2017-04-14 12:59 ` [PATCH 04/13] power: max17042_battery: Add default platform_data for x86 use Hans de Goede
2017-04-14 15:35 ` Krzysztof Kozlowski
2017-04-14 16:07 ` Krzysztof Kozlowski
2017-04-14 17:11 ` Hans de Goede [this message]
2017-04-14 12:59 ` [PATCH 05/13] power: max17042_battery: Change name in power_supply_desc to "main-battery" Hans de Goede
2017-04-14 15:37 ` Krzysztof Kozlowski
2017-04-14 12:59 ` [PATCH 06/13] power: max17042_battery: Add support for the STATUS property Hans de Goede
2017-04-14 16:11 ` Krzysztof Kozlowski
2017-04-14 17:19 ` Hans de Goede
2017-04-14 12:59 ` [PATCH 07/13] power: max17042_battery: Add external_power_changed callback Hans de Goede
2017-04-14 16:22 ` Krzysztof Kozlowski
2017-04-14 12:59 ` [PATCH 08/13] power: max17042_battery: Add support for the TECHNOLOGY attribute Hans de Goede
2017-04-14 16:26 ` Krzysztof Kozlowski
2017-04-14 18:06 ` Hans de Goede
2017-04-14 18:20 ` Krzysztof Kozlowski
2017-04-14 18:24 ` Hans de Goede
2017-04-14 12:59 ` [PATCH 09/13] power: max17042_battery: Add support for the VOLT_MIN property Hans de Goede
2017-04-14 16:29 ` Krzysztof Kozlowski
2017-04-14 12:59 ` [PATCH 10/13] power: max17042_battery: Add support for the CHARGE_FULL_DESIGN property Hans de Goede
2017-04-14 16:34 ` Krzysztof Kozlowski
2017-04-14 18:08 ` Hans de Goede
2017-04-14 12:59 ` [PATCH 11/13] power: max17042_battery: Add support for CHARGE_NOW property Hans de Goede
2017-04-14 16:42 ` Krzysztof Kozlowski
2017-04-14 12:59 ` [PATCH 12/13] power: max17042_battery: Add support for SCOPE property Hans de Goede
2017-04-14 16:43 ` Krzysztof Kozlowski
2017-04-14 12:59 ` [PATCH 13/13] power: max77693_charger: Add supplied_to info to power_supply_config Hans de Goede
2017-04-14 16:44 ` Krzysztof Kozlowski
2017-04-14 13:56 ` [PATCH 01/13] power: Make power_supply_am_i_supplied return -ENODEV if there are no suppliers Krzysztof Kozlowski
2017-04-14 14:07 ` Hans de Goede
2017-04-14 14:31 ` Krzysztof Kozlowski
2017-04-14 15:21 ` Hans de Goede
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=f872ad19-397d-3c69-f00e-63a1ff33932e@redhat.com \
--to=hdegoede@redhat.com \
--cc=b.zolnierkie@samsung.com \
--cc=krzk@kernel.org \
--cc=linux-pm@vger.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;
as well as URLs for NNTP newsgroup(s).