Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1606767
| From | Hans de Goede <hdegoede@redhat.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH 14/15] power: supply: Add driver for Cherry Trail Whiskey Cove PMIC Fuel Gauge |
| Date | 2017-03-22 18:10 +0100 |
| Message-ID | <tnRVM-5RD-27@gated-at.bofh.it> (permalink) |
| References | <tlWPT-4pa-5@gated-at.bofh.it> <tlWPT-4pa-11@gated-at.bofh.it> <tm4kq-1GF-33@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
Hi,
On 17-03-17 18:58, Andy Shevchenko wrote:
> On Fri, 2017-03-17 at 10:55 +0100, Hans de Goede wrote:
>> Add a driver for the Cherry Trail Whiskey Cove PMIC Fuel Gauge, note
>> the Cherry Trail Whiskey Cove PMIC Fuel Gauge block is purely a fuel
>> gauge
>> and not a full battery controller. As such it offers a platform_data
>> callback for extra power_supply properties for the actual external-
>> charger
>> ic driver and does not register a power_supply itself.
>
> ic -> IC
>
> Can we move to something like built-in device properties for additional
> properties instead of extending platform data?
>
>> +config CHT_WC_FUEL_GAUGE
>
> I would use similar pattern:
>
> FUEL_GAUGE_INTEL_CHTWC (or FUEL_GAUGE_CHTWC, but this might be less
> obvious about vendor)
Good point, although all the fuel-gauge's seem to use
BATTERY as prefix, so I've gone with that.
>
>> --- /dev/null
>> +++ b/drivers/power/supply/cht_wc_fuel_gauge.c
>> @@ -0,0 +1,209 @@
>> +/*
>> + * Intel CHT Whiskey Cove Fuel Gauge driver
>
> CHT -> Cherry Trail
Fixed.
>
>> + *
>> + * Cherrytrail Whiskey Cove devices have 2 functional blocks which
>> interact
>> + * with the battery.
>
> Cherry Trail?
Since after discussion about how to deal with the charger / fuel_gauge
comment v2 is going to be a stand-alone power_supply driver this
comment has been dropped.
>
>> +#define REG_CHARGE_NOW 0x05
>> +#define REG_VOLTAGE_NOW 0x09
>> +#define REG_CURRENT_NOW 0x0a
>> +#define REG_CURRENT_AVG 0x0b
>> +#define REG_CHARGE_FULL 0x10
>> +#define REG_CHARGE_DESIGN 0x18
>> +#define REG_VOLTAGE_AVG 0x19
>
>> +#define REG_VOLTAGE_OCV 0x1b /* Only updated during
>> charging */
>
> I think comment makes more sense where actual update is happening in the
> code.
>
>> +
>> +static int cht_wc_fg_read(struct cht_wc_fg_data *fg, u8 reg,
>> + union power_supply_propval *val, int scale,
>> + int sign_extend)
>> +{
>> + int ret;
>> +
>> + ret = i2c_smbus_read_word_data(fg->client, reg);
>> + if (ret < 0)
>> + return ret;
>> +
>> + if (sign_extend)
>> + ret = sign_extend32(ret, 15);
>
> Magic?
Nope just simply dealing with i2c_smbus_read_word_data always
returning 16 bit unsigned data (or a negative error code)
and some of the registers being 16 bit signed.
>
>> +
>> + val->intval = ret * scale;
>> +
>> + return 0;
>> +}
>
>
>> +
>> +int cht_wc_fg_get_property(enum power_supply_property prop,
>> + union power_supply_propval *val)
>> +{
>> + int ret = 0;
>
> Sounds like redundant assignment...
No longer redundant in v2.
>
>> +
>> + mutex_lock(&cht_wc_fg_mutex);
>> +
>>
>
>> + if (!cht_wc_fg) {
>> + ret = -ENXIO;
>> + goto out_unlock;
>> + }
>
> ...otherwise maybe
>
> ret = cht_wc_fg ? 0 : -ENXIO;
> if (ret)
> goto ...;
>
> ?
With the stand-alone power_supply driver version this ugliness is gone.
>
>> + default:
>> + ret = -ENODATA;
>> + }
>> +out_unlock:
>> + mutex_unlock(&cht_wc_fg_mutex);
>> + return ret;
>> +}
>> +EXPORT_SYMBOL_GPL(cht_wc_fg_get_property);
>
>> +
>> +static int cht_wc_fg_probe(struct i2c_client *client,
>> + const struct i2c_device_id *i2c_id)
>> +{
>> + struct device *dev = &client->dev;
>> + struct cht_wc_fg_data *fg;
>> + acpi_status status;
>> + unsigned long long ptyp;
>
>> + status = acpi_evaluate_integer(ACPI_HANDLE(dev), "PTYP",
>> NULL, &ptyp);
>> + if (ACPI_FAILURE(status)) {
>> + dev_err(dev, "Failed to get PTYPE\n");
>> + return -ENODEV;
>> + }
>> +
>> + /*
>> + * The same ACPI HID is used with different PMICs check PTYP
>> to
>> + * ensure that we are dealing with a Whiskey Cove PMIC.
>> + */
>> + if (ptyp != CHT_WC_FG_PTYPE)
>> + return -ENODEV;
>
> Logically I would split this part to be a main driver for device which
> would use actual driver based on this, though I think it too much churn
> for no benefit right now.
Ack.
>
>> + mutex_lock(&cht_wc_fg_mutex);
>> + cht_wc_fg = fg;
>> + mutex_unlock(&cht_wc_fg_mutex);
>
> It's pity we have no common storage of single possible present device
> drivers in the kernel. I would use some kind of framework rather then
> keeping all those global variables with locking. Perhaps radix / RB
> tree.
With the stand-alone power_supply driver version this ugliness is gone.
Regards,
Hans
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH 00/15] Add Intel Cherry Trail Whiskey Cove PMIC support Hans de Goede <hdegoede@redhat.com> - 2017-03-17 11:00 +0100
[PATCH 02/15] ACPI / PMIC: Add opregion driver for Intel CHT Whiskey Cove PMIC Hans de Goede <hdegoede@redhat.com> - 2017-03-17 11:00 +0100
[PATCH 14/15] power: supply: Add driver for Cherry Trail Whiskey Cove PMIC Fuel Gauge Hans de Goede <hdegoede@redhat.com> - 2017-03-17 11:00 +0100
Re: [PATCH 14/15] power: supply: Add driver for Cherry Trail Whiskey Cove PMIC Fuel Gauge Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2017-03-17 19:00 +0100
Re: [PATCH 14/15] power: supply: Add driver for Cherry Trail Whiskey Cove PMIC Fuel Gauge Hans de Goede <hdegoede@redhat.com> - 2017-03-22 18:10 +0100
Re: [PATCH 14/15] power: supply: Add driver for Cherry Trail Whiskey Cove PMIC Fuel Gauge Sebastian Reichel <sre@kernel.org> - 2017-03-20 06:10 +0100
[PATCH 13/15] i2c: core: Allow drivers to specify index for irq to get from of / ACPI Hans de Goede <hdegoede@redhat.com> - 2017-03-17 11:00 +0100
Re: [PATCH 13/15] i2c: core: Allow drivers to specify index for irq to get from of / ACPI Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2017-03-17 18:50 +0100
Re: [PATCH 13/15] i2c: core: Allow drivers to specify index for irq to get from of / ACPI kbuild test robot <lkp@intel.com> - 2017-03-20 10:40 +0100
[PATCH 01/15] mfd: Add Cherry Trail Whiskey Cove PMIC driver Hans de Goede <hdegoede@redhat.com> - 2017-03-17 11:00 +0100
Re: [PATCH 01/15] mfd: Add Cherry Trail Whiskey Cove PMIC driver Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2017-03-17 18:20 +0100
Re: [PATCH 01/15] mfd: Add Cherry Trail Whiskey Cove PMIC driver Lee Jones <lee.jones@linaro.org> - 2017-03-20 11:50 +0100
Re: [PATCH 01/15] mfd: Add Cherry Trail Whiskey Cove PMIC driver Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2017-03-20 14:00 +0100
[PATCH 15/15] i2c-cht-wc: Add Intel Cherry Trail Whiskey Cove SMBUS controller driver Hans de Goede <hdegoede@redhat.com> - 2017-03-17 11:00 +0100
Re: [PATCH 15/15] i2c-cht-wc: Add Intel Cherry Trail Whiskey Cove SMBUS controller driver Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2017-03-17 19:30 +0100
Re: [PATCH 15/15] i2c-cht-wc: Add Intel Cherry Trail Whiskey Cove SMBUS controller driver Hans de Goede <hdegoede@redhat.com> - 2017-03-23 15:00 +0100
[PATCH 11/15] i2c: core: Allow getting ACPI info by index Hans de Goede <hdegoede@redhat.com> - 2017-03-17 11:00 +0100
Re: [PATCH 11/15] i2c: core: Allow getting ACPI info by index Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2017-03-17 18:40 +0100
[PATCH 10/15] power: supply: bq24190_charger: Use extcon to determine ilimit, 5v boost Hans de Goede <hdegoede@redhat.com> - 2017-03-17 11:00 +0100
Re: [PATCH 10/15] power: supply: bq24190_charger: Use extcon to determine ilimit, 5v boost Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2017-03-17 18:40 +0100
Re: [PATCH 10/15] power: supply: bq24190_charger: Use extcon to determine ilimit, 5v boost Hans de Goede <hdegoede@redhat.com> - 2017-03-20 23:40 +0100
Re: [PATCH 10/15] power: supply: bq24190_charger: Use extcon to determine ilimit, 5v boost Sebastian Reichel <sre@kernel.org> - 2017-03-20 06:00 +0100
[PATCH 12/15] i2c: core: Add new i2c_acpi_new_device helper function Hans de Goede <hdegoede@redhat.com> - 2017-03-17 11:00 +0100
Re: [PATCH 12/15] i2c: core: Add new i2c_acpi_new_device helper function Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2017-03-17 18:50 +0100
Re: [PATCH 12/15] i2c: core: Add new i2c_acpi_new_device helper function Hans de Goede <hdegoede@redhat.com> - 2017-03-22 17:00 +0100
[PATCH 04/15] power: supply: bq24190_charger: Add no_register_reset pdata flag Hans de Goede <hdegoede@redhat.com> - 2017-03-17 11:10 +0100
Re: [PATCH 04/15] power: supply: bq24190_charger: Add no_register_reset pdata flag Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2017-03-17 18:30 +0100
[PATCH 07/15] power: supply: bq24190_charger: Add support for bq24192[i] Hans de Goede <hdegoede@redhat.com> - 2017-03-17 11:10 +0100
[PATCH 05/15] power: supply: bq24190_charger: Limit charging voltage to 4.3V Hans de Goede <hdegoede@redhat.com> - 2017-03-17 11:10 +0100
[PATCH 09/15] power: supply: bq24190_charger: Add voltage_max_design prop to battery Hans de Goede <hdegoede@redhat.com> - 2017-03-17 11:10 +0100
Re: [PATCH 09/15] power: supply: bq24190_charger: Add voltage_max_design prop to battery Sebastian Reichel <sre@kernel.org> - 2017-03-20 06:20 +0100
[PATCH 06/15] power: supply: bq24190_charger: Use i2c-core irq-mapping code Hans de Goede <hdegoede@redhat.com> - 2017-03-17 11:10 +0100
Re: [PATCH 06/15] power: supply: bq24190_charger: Use i2c-core irq-mapping code Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2017-03-17 18:30 +0100
Re: [PATCH 06/15] power: supply: bq24190_charger: Use i2c-core irq-mapping code Sebastian Reichel <sre@kernel.org> - 2017-03-20 05:50 +0100
[PATCH 08/15] power: supply: bq24190_charger: Add support for external fuel gauge Hans de Goede <hdegoede@redhat.com> - 2017-03-17 11:10 +0100
csiph-web