intel_mid: Intel MSIC battery driver
RFC 1/1 intel_mid: Intel MSIC battery driver
(This is an RFC as it depends upon some USB side power patches heading upstream
via the USB stack and not yet finally merged. However feedback to get this bit ready for when they do would still be useful)
From: Ramakrishna Pallala <[email protected]>
Battery driver for the Intel MID platform devices based on the Medfield chipset. This is a fold up of all the current work on the Medfield MSIC battery driver.
---
drivers/power/Kconfig | 15 drivers/power/Makefile | 3 drivers/power/intel_mdf_battery.c | 2704 +++++++++++++++++++++++++++++++++++++ 3 files changed, 2717 insertions(+), 5 deletions(-) create mode 100644 drivers/power/intel_mdf_battery.c
drivers/power/Kconfig +11 -4
@@ -165,12 +165,19 @@ config BATTERY_JZ4740 This driver can be build as a module. If so, the module will be called jz4740-battery. -config BATTERY_INTEL_MID - tristate "Battery driver for Intel MID platforms" +config BATTERY_INTEL_MID_MRST + tristate "Battery driver for Intel Moorestown MID platforms" depends on INTEL_SCU_IPC && SPI help - Say Y here to enable the battery driver on Intel MID - platforms. + Say Y here to enable the battery driver on Intel Moorestown + based MID platforms. + +config BATTERY_INTEL_MID_MFLD + tristate "Battery driver for Intel Medfield MID platforms" + depends on INTEL_SCU_IPC && USB_PENWELL_OTG + help + Say Y here to enable the battery driver on Intel Medfield + based MID platforms. config CHARGER_ISP1704 tristate "ISP1704 USB Charger Detection"
drivers/power/Makefile +2 -1
@@ -29,7 +29,8 @@ obj-$(CONFIG_BATTERY_Z2) += z2_battery.o obj-$(CONFIG_BATTERY_S3C_ADC) += s3c_adc_battery.o obj-$(CONFIG_CHARGER_PCF50633) += pcf50633-charger.o obj-$(CONFIG_BATTERY_JZ4740) += jz4740-battery.o -obj-$(CONFIG_BATTERY_INTEL_MID) += intel_mid_battery.o +obj-$(CONFIG_BATTERY_INTEL_MID_MRST) += intel_mid_battery.o +obj-$(CONFIG_BATTERY_INTEL_MID_MFLD) += intel_mdf_battery.o obj-$(CONFIG_CHARGER_ISP1704) += isp1704_charger.o obj-$(CONFIG_CHARGER_TWL4030) += twl4030_charger.o obj-$(CONFIG_CHARGER_GPIO) += gpio-charger.o
drivers/power/intel_mdf_battery.c new file +2704 -0
2,704 lines not on this page · raw message
drivers/power/intel_mdf_battery.c line 501
Quoted 11 lines · Alan Cox
drivers/power/intel_mdf_battery.c new file +11
-0+/* +* msic usb properties +*/ +static enum power_supply_property msic_usb_props[] = { +POWER_SUPPLY_PROP_TYPE , +POWER_SUPPLY_PROP_CHARGE_TYPE , +POWER_SUPPLY_PROP_PRESENT , +POWER_SUPPLY_PROP_HEALTH , +POWER_SUPPLY_PROP_VOLTAGE_NOW , +POWER_SUPPLY_PROP_MODEL_NAME , +POWER_SUPPLY_PROP_MANUFACTURER ,
It seems a bit odd that the USB interface has a charge related property
- while it may be the current supply for the charger the thing that's actually being charged is the battery which doesn't have a charge type. See also below...
drivers/power/intel_mdf_battery.c line 797
Quoted 2 lines
drivers/power/intel_mdf_battery.c new file +2
-0+static int mdf_read_adc_regs (int sensor, +struct msic_power_module_info *mbi)
Might it be useful to push these into the core code for whatever you're talking to so that you can expose both power supply and hwmon interface versions of the supply monitoring?
drivers/power/intel_mdf_battery.c line 1313
Quoted 4 lines
drivers/power/intel_mdf_battery.c new file +4
-0+static void msic_handle_exception (struct msic_power_module_info *mbi, +uint8_t CHRINT_reg_value,uint8_t CHRINT1_reg_value) +{ +enum msic_event exception;
I'd expect this to generate a power_supply_changed() too - it's possible I'm just missing the code for that somewhere else, though.
drivers/power/intel_mdf_battery.c line 1529
Quoted 5 lines
drivers/power/intel_mdf_battery.c new file +5
-0+if (mbi->ch_params.vinilmt ==CHRG_CURR_SDP_LOW ) + mbi->usb_chrg_props.charger_type =POWER_SUPPLY_CHARGE_TYPE_TRICKLE ; +else + mbi->usb_chrg_props.charger_type = +POWER_SUPPLY_CHARGE_TYPE_FAST ;
This isn't what fast and trickle charge are, they're not static properties but rather reflect the kind of charging that's being done. Broadly speaking trickle charge means that charge is being fed slowly into the battery (usually at either extreme of the charge curve when the battery is either near full or near discharge) while fast charge means that charge is being pushed into the battery much more rapidly. This will vary throughout the charge cycle.
It's likely that if the supply is constrained (eg, 100mA USB) then there won't be enough current to ever do a fast charge but the availability of more supply doesn't mean that we're in fast charge.
Hi Mark,
Thanks for the comments.
Quoted 5 lines
Quoted 5 lines
drivers/power/intel_mdf_battery.c new file +5
-0+static enum power_supply_property msic_usb_props[] = { +POWER_SUPPLY_PROP_TYPE , +POWER_SUPPLY_PROP_CHARGE_TYPE , +POWER_SUPPLY_PROP_PRESENT , +POWER_SUPPLY_PROP_HEALTH ,
Quoted 8 lines
drivers/power/intel_mdf_battery.c line 501
Quoted 3 lines
drivers/power/intel_mdf_battery.c new file +3
-0+POWER_SUPPLY_PROP_VOLTAGE_NOW , +POWER_SUPPLY_PROP_MODEL_NAME , + POWER_SUPPLY_PROP_MANUFACTURER,It seems a bit odd that the USB interface has a charge related property
- while it may be the current supply for the charger the thing that's actually being charged is the battery which doesn't have a charge type. See also below...
Agreed will fix it.
Quoted 7 lines
drivers/power/intel_mdf_battery.c line 797
Quoted 3 lines
drivers/power/intel_mdf_battery.c new file +2
-0+static int mdf_read_adc_regs (int sensor, +struct msic_power_module_info *mbi)Might it be useful to push these into the core code for whatever you're talking to so that you can expose both power supply and hwmon interface versions of the supply monitoring?
Generic ADC driver development is in progress. I will remove this code as soon as the ADC driver comes in.
Quoted 8 lines
drivers/power/intel_mdf_battery.c line 1313
Quoted 4 lines
drivers/power/intel_mdf_battery.c new file +4
-0+static void msic_handle_exception (struct msic_power_module_info *mbi, +uint8_t CHRINT_reg_value,uint8_t CHRINT1_reg_value) +{ +enum msic_event exception;I'd expect this to generate a
power_supply_changed()too - it's possible I'm just missing the code for that somewhere else, though.
Agreed will fix it.
Quoted 15 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (mbi->ch_params.vinilmt == CHRG_CURR_SDP_LOW) + mbi->usb_chrg_props.charger_type =
POWER_SUPPLY_CHARGE_TYPE_TRICKLE;drivers/power/intel_mdf_battery.c line 1529
Quoted 3 lines
drivers/power/intel_mdf_battery.c new file +3
-0+else + mbi->usb_chrg_props.charger_type = +POWER_SUPPLY_CHARGE_TYPE_FAST ;This isn't what fast and trickle charge are, they're not static properties but rather reflect the kind of charging that's being done. Broadly speaking trickle charge means that charge is being fed slowly into the battery (usually at either extreme of the charge curve when the battery is either near full or near discharge) while fast charge means that charge is being pushed into the battery much more rapidly. This will vary throughout the charge cycle.
Quoted 3 lines
It's likely that if the supply is constrained (eg, 100mA USB) then there won't be enough current to ever do a fast charge but the availability of more supply doesn't mean that we're in fast charge.
If I understand correctly trickle charging will happen during full(or deeply discharge) charge conditions.
But as soon as I hit the charge full condition I am stopping the charging and will go into maintenance mode.
In maintenance mode I will check battery voltage to hit for lower threshold value and then enable the charging. During maintenance mode battery voltage is near to FULL charge value, So can I set the charging type to trickle during maintenance mode?
Quoted 10 lines · Ramakrishna
Quoted 9 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (mbi->ch_params.vinilmt == CHRG_CURR_SDP_LOW) + mbi->usb_chrg_props.charger_type =
POWER_SUPPLY_CHARGE_TYPE_TRICKLE;drivers/power/intel_mdf_battery.c line 1529
Quoted 3 lines
drivers/power/intel_mdf_battery.c new file +3
-0+else + mbi->usb_chrg_props.charger_type = +POWER_SUPPLY_CHARGE_TYPE_FAST ;This isn't what fast and trickle charge are, they're not static properties but rather reflect the kind of charging that's being done.
Quoted 7 lines
If I understand correctly trickle charging will happen during full(or deeply discharge) charge conditions. But as soon as I hit the charge full condition I am stopping the charging and will go into maintenance mode. In maintenance mode I will check battery voltage to hit for lower threshold value and then enable the charging. During maintenance mode battery voltage is near to FULL charge value, So can I set the charging type to trickle during maintenance mode?
Given that it looks like this battery is capable of reporting more detailed information such as the current that's being used to charge at the moment I'm not sure it's worth supporting this property at all. The property exists because with the chargers used in many small embedded devices use this something the hardware reports directly and you don't get much more information than that. If (as it seems) your charger has no directly exported concept of different charge types then it's probably safer to just not report this property and let userspace worry about it.
The normal use for this information is figuring out why the battery is taking longer than expected to charge - if the charger is stuck in trickle charge then charging will take a very long time.