* [PATCH v2 0/5] power/mfd: Add max77693 charger driver @ 2014-10-20 12:34 Krzysztof Kozlowski [not found] ` <1413808489-3524-1-git-send-email-k.kozlowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org> ` (3 more replies) 0 siblings, 4 replies; 14+ messages in thread From: Krzysztof Kozlowski @ 2014-10-20 12:34 UTC (permalink / raw) To: Sebastian Reichel, Dmitry Eremin-Solenikov, David Woodhouse, linux-kernel-u79uwXL29TY76Z2rM5mHXA, linux-pm-u79uwXL29TY76Z2rM5mHXA, Samuel Ortiz, Lee Jones, linux-api-u79uwXL29TY76Z2rM5mHXA, devicetree-u79uwXL29TY76Z2rM5mHXA Cc: Kyungmin Park, Marek Szyprowski, Bartlomiej Zolnierkiewicz, Krzysztof Kozlowski Hi, Changes since v1 ================ 1. Add patch 2/5: mfd: max77693: Map charger device to its own of_node (forgot to send it in v1) 2. Remove patches for DTS and configs. I'll send them later. 3. Add ack from Lee Jones (patch 3/5). Description =========== The patchset adds max77693 charger driver present on Trats2 board (and Galaxy S III). The driver configures battery charger and exposes power supply interface. Driver is necessary to provide full charging stack on Trats2 device (extcon, charger-manager etc.). Everything rebased on next-20141020. Best regards, Krzysztof Krzysztof Kozlowski (5): devicetree: mfd: max77693: Document new bindings for charger mfd: max77693: Map charger device to its own of_node mfd: max77693: Add defines for MAX77693 charger driver power: max77693: Add charger driver for Maxim 77693 Documentation: charger: max77693: Document exported sysfs entry Documentation/ABI/testing/sysfs-class-power | 42 ++ Documentation/devicetree/bindings/mfd/max77693.txt | 46 ++ drivers/mfd/max77693.c | 5 +- drivers/power/Kconfig | 6 + drivers/power/Makefile | 1 + drivers/power/max77693_charger.c | 763 +++++++++++++++++++++ include/linux/mfd/max77693-private.h | 108 +++ include/linux/mfd/max77693.h | 8 + 8 files changed, 978 insertions(+), 1 deletion(-) create mode 100644 drivers/power/max77693_charger.c -- 1.9.1 ^ permalink raw reply [flat|nested] 14+ messages in thread
[parent not found: <1413808489-3524-1-git-send-email-k.kozlowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>]
* [PATCH v2 1/5] devicetree: mfd: max77693: Document new bindings for charger [not found] ` <1413808489-3524-1-git-send-email-k.kozlowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org> @ 2014-10-20 12:34 ` Krzysztof Kozlowski 2014-10-20 12:34 ` [PATCH v2 4/5] power: max77693: Add charger driver for Maxim 77693 Krzysztof Kozlowski 1 sibling, 0 replies; 14+ messages in thread From: Krzysztof Kozlowski @ 2014-10-20 12:34 UTC (permalink / raw) To: Sebastian Reichel, Dmitry Eremin-Solenikov, David Woodhouse, linux-kernel-u79uwXL29TY76Z2rM5mHXA, linux-pm-u79uwXL29TY76Z2rM5mHXA, Samuel Ortiz, Lee Jones, linux-api-u79uwXL29TY76Z2rM5mHXA, devicetree-u79uwXL29TY76Z2rM5mHXA Cc: Kyungmin Park, Marek Szyprowski, Bartlomiej Zolnierkiewicz, Krzysztof Kozlowski Document new device tree bindings for Maxim 77693 charger driver. Signed-off-by: Krzysztof Kozlowski <k.kozlowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org> --- Documentation/devicetree/bindings/mfd/max77693.txt | 46 ++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/Documentation/devicetree/bindings/mfd/max77693.txt b/Documentation/devicetree/bindings/mfd/max77693.txt index 11921cc417bf..d0c3d787df12 100644 --- a/Documentation/devicetree/bindings/mfd/max77693.txt +++ b/Documentation/devicetree/bindings/mfd/max77693.txt @@ -27,6 +27,42 @@ Optional properties: [*] refer Documentation/devicetree/bindings/regulator/regulator.txt +- charger : Node configuring the charger driver. + If present, required properties: + - compatible : Must be "maxim,max77693-charger". + + Optional properties (if not set, defaults will be used): + - maxim,constant-microvolt : Battery constant voltage in uV. The charger + will operate in fast charge constant current mode till battery voltage + reaches this level. Then the charger will switch to fast charge constant + voltage mode. Also vsys (system voltage) will be set to this value when + DC power is supplied but charger is not enabled. + Valid values: 3650000 - 4400000, step by 25000 (rounded down) + Default: 4200000 + + - maxim,min-system-microvolt : Minimal system voltage in uV. + Valid values: 3000000 - 3700000, step by 100000 (rounded down) + Default: 3600000 + + - maxim,thermal-regulation-celsius : Temperature in Celsius for entering + high temperature charging mode. If die temperature exceeds this value + the charging current will be reduced by 105 mA/Celsius. + Valid values: 70, 85, 100, 115 + Default: 100 + + - maxim,battery-overcurrent-microamp : Overcurrent protection threshold + in uA (current from battery to system). + Valid values: 2000000 - 3500000, step by 250000 (rounded down) + Default: 3500000 + + - maxim,charge-input-threshold-microvolt : Threshold voltage in uV for + triggering input voltage regulation loop. If input voltage decreases + below this value, the input current will be reduced to reach the + threshold voltage. + Valid values: 4300000, 4700000, 4800000, 4900000 + Default: 4300000 + + Example: max77693@66 { compatible = "maxim,max77693"; @@ -52,4 +88,14 @@ Example: regulator-boot-on; }; }; + + charger { + compatible = "maxim,max77693-charger"; + + maxim,constant-microvolt = <4200000>; + maxim,min-system-microvolt = <3600000>; + maxim,thermal-regulation-celsius = <75>; + maxim,battery-overcurrent-microamp = <3000000>; + maxim,charge-input-threshold-microvolt = <4300000>; + }; }; -- 1.9.1 ^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH v2 4/5] power: max77693: Add charger driver for Maxim 77693 [not found] ` <1413808489-3524-1-git-send-email-k.kozlowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org> 2014-10-20 12:34 ` [PATCH v2 1/5] devicetree: mfd: max77693: Document new bindings for charger Krzysztof Kozlowski @ 2014-10-20 12:34 ` Krzysztof Kozlowski 2014-10-27 18:56 ` Sebastian Reichel 1 sibling, 1 reply; 14+ messages in thread From: Krzysztof Kozlowski @ 2014-10-20 12:34 UTC (permalink / raw) To: Sebastian Reichel, Dmitry Eremin-Solenikov, David Woodhouse, linux-kernel-u79uwXL29TY76Z2rM5mHXA, linux-pm-u79uwXL29TY76Z2rM5mHXA, Samuel Ortiz, Lee Jones, linux-api-u79uwXL29TY76Z2rM5mHXA, devicetree-u79uwXL29TY76Z2rM5mHXA Cc: Kyungmin Park, Marek Szyprowski, Bartlomiej Zolnierkiewicz, Krzysztof Kozlowski Add new driver for Maxim 77693 switch-mode charger (part of max77693 MFD driver) providing power supply class information to userspace. The charger has +20V tolerant input. Current input can be set from 0 to 2.58 A. The charger can deliver up to 2.1 A to the battery or 3.5 A to the system (when supplying additional current from battery to system). The driver is configured through DTS (battery and system related settings) and sysfs entries (timers and top-off charging threshold). Signed-off-by: Krzysztof Kozlowski <k.kozlowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org> --- drivers/power/Kconfig | 6 + drivers/power/Makefile | 1 + drivers/power/max77693_charger.c | 763 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 770 insertions(+) create mode 100644 drivers/power/max77693_charger.c diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig index 0108c2af005b..77e6cd7bb801 100644 --- a/drivers/power/Kconfig +++ b/drivers/power/Kconfig @@ -332,6 +332,12 @@ config CHARGER_MAX14577 Say Y to enable support for the battery charger control sysfs and platform data of MAX14577/77836 MUICs. +config CHARGER_MAX77693 + tristate "Maxim MAX77693 battery charger driver" + depends on MFD_MAX77693 + help + Say Y to enable support for the Maxim MAX77693 battery charger. + config CHARGER_MAX8997 tristate "Maxim MAX8997/MAX8966 PMIC battery charger driver" depends on MFD_MAX8997 && REGULATOR_MAX8997 diff --git a/drivers/power/Makefile b/drivers/power/Makefile index dfa894273926..2d7ad66cc7d6 100644 --- a/drivers/power/Makefile +++ b/drivers/power/Makefile @@ -50,6 +50,7 @@ obj-$(CONFIG_CHARGER_LP8788) += lp8788-charger.o obj-$(CONFIG_CHARGER_GPIO) += gpio-charger.o obj-$(CONFIG_CHARGER_MANAGER) += charger-manager.o obj-$(CONFIG_CHARGER_MAX14577) += max14577_charger.o +obj-$(CONFIG_CHARGER_MAX77693) += max77693_charger.o obj-$(CONFIG_CHARGER_MAX8997) += max8997_charger.o obj-$(CONFIG_CHARGER_MAX8998) += max8998_charger.o obj-$(CONFIG_CHARGER_BQ2415X) += bq2415x_charger.o diff --git a/drivers/power/max77693_charger.c b/drivers/power/max77693_charger.c new file mode 100644 index 000000000000..dfdbcc2f0795 --- /dev/null +++ b/drivers/power/max77693_charger.c @@ -0,0 +1,763 @@ +/* + * max77693_charger.c - Battery charger driver for the Maxim 77693 + * + * Copyright (C) 2014 Samsung Electronics + * Krzysztof Kozlowski <k.kozlowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include <linux/module.h> +#include <linux/platform_device.h> +#include <linux/power_supply.h> +#include <linux/regmap.h> +#include <linux/mfd/max77693.h> +#include <linux/mfd/max77693-private.h> + +static const char *max77693_charger_name = "max77693-charger"; +static const char *max77693_charger_model = "MAX77693"; +static const char *max77693_charger_manufacturer = "Maxim Integrated"; + +struct max77693_charger { + struct device *dev; + struct max77693_dev *max77693; + struct power_supply charger; + + struct max77693_charger_platform_data *pdata; +}; + +static int max77693_get_charger_state(struct regmap *regmap) +{ + int state; + unsigned int data; + + if (regmap_read(regmap, MAX77693_CHG_REG_CHG_DETAILS_01, &data) < 0) + return POWER_SUPPLY_STATUS_UNKNOWN; + + data &= CHG_DETAILS_01_CHG_MASK; + data >>= CHG_DETAILS_01_CHG_SHIFT; + + switch (data) { + case MAX77693_CHARGING_PREQUALIFICATION: + case MAX77693_CHARGING_FAST_CONST_CURRENT: + case MAX77693_CHARGING_FAST_CONST_VOLTAGE: + case MAX77693_CHARGING_TOP_OFF: + /* In high temp the charging current is reduced, but still charging */ + case MAX77693_CHARGING_HIGH_TEMP: + state = POWER_SUPPLY_STATUS_CHARGING; + break; + case MAX77693_CHARGING_DONE: + state = POWER_SUPPLY_STATUS_FULL; + break; + case MAX77693_CHARGING_TIMER_EXPIRED: + case MAX77693_CHARGING_THERMISTOR_SUSPEND: + state = POWER_SUPPLY_STATUS_NOT_CHARGING; + break; + case MAX77693_CHARGING_OFF: + case MAX77693_CHARGING_OVER_TEMP: + case MAX77693_CHARGING_WATCHDOG_EXPIRED: + state = POWER_SUPPLY_STATUS_DISCHARGING; + break; + case MAX77693_CHARGING_RESERVED: + default: + state = POWER_SUPPLY_STATUS_UNKNOWN; + } + + return state; +} + +static int max77693_get_charge_type(struct regmap *regmap) +{ + int state; + unsigned int data; + + if (regmap_read(regmap, MAX77693_CHG_REG_CHG_DETAILS_01, &data) < 0) + return POWER_SUPPLY_CHARGE_TYPE_UNKNOWN; + + data &= CHG_DETAILS_01_CHG_MASK; + data >>= CHG_DETAILS_01_CHG_SHIFT; + + switch (data) { + case MAX77693_CHARGING_PREQUALIFICATION: + /* + * Top-off: trickle or fast? In top-off the current varies between + * 100 and 250 mA. It is higher than prequalification current. + */ + case MAX77693_CHARGING_TOP_OFF: + state = POWER_SUPPLY_CHARGE_TYPE_TRICKLE; + break; + case MAX77693_CHARGING_FAST_CONST_CURRENT: + case MAX77693_CHARGING_FAST_CONST_VOLTAGE: + /* In high temp the charging current is reduced, but still charging */ + case MAX77693_CHARGING_HIGH_TEMP: + state = POWER_SUPPLY_CHARGE_TYPE_FAST; + break; + case MAX77693_CHARGING_DONE: + case MAX77693_CHARGING_TIMER_EXPIRED: + case MAX77693_CHARGING_THERMISTOR_SUSPEND: + case MAX77693_CHARGING_OFF: + case MAX77693_CHARGING_OVER_TEMP: + case MAX77693_CHARGING_WATCHDOG_EXPIRED: + state = POWER_SUPPLY_CHARGE_TYPE_NONE; + break; + case MAX77693_CHARGING_RESERVED: + default: + state = POWER_SUPPLY_CHARGE_TYPE_UNKNOWN; + } + + return state; +} + +/* + * Supported health statuses: + * - POWER_SUPPLY_HEALTH_DEAD + * - POWER_SUPPLY_HEALTH_GOOD + * - POWER_SUPPLY_HEALTH_OVERVOLTAGE + * - POWER_SUPPLY_HEALTH_SAFETY_TIMER_EXPIRE + * - POWER_SUPPLY_HEALTH_UNKNOWN + * - POWER_SUPPLY_HEALTH_UNSPEC_FAILURE + */ +static int max77693_get_battery_health(struct regmap *regmap) +{ + int state; + unsigned int data; + + if (regmap_read(regmap, MAX77693_CHG_REG_CHG_DETAILS_01, &data) < 0) + return POWER_SUPPLY_HEALTH_UNKNOWN; + + data &= CHG_DETAILS_01_BAT_MASK; + data >>= CHG_DETAILS_01_BAT_SHIFT; + + switch (data) { + case MAX77693_BATTERY_NOBAT: + state = POWER_SUPPLY_HEALTH_DEAD; + break; + case MAX77693_BATTERY_PREQUALIFICATION: + case MAX77693_BATTERY_GOOD: + case MAX77693_BATTERY_LOWVOLTAGE: + state = POWER_SUPPLY_HEALTH_GOOD; + break; + case MAX77693_BATTERY_TIMER_EXPIRED: + /* + * Took longer to charge than expected, charging suspended. + * Damaged battery? + */ + state = POWER_SUPPLY_HEALTH_SAFETY_TIMER_EXPIRE; + break; + case MAX77693_BATTERY_OVERVOLTAGE: + state = POWER_SUPPLY_HEALTH_OVERVOLTAGE; + break; + case MAX77693_BATTERY_OVERCURRENT: + state = POWER_SUPPLY_HEALTH_UNSPEC_FAILURE; + break; + case MAX77693_BATTERY_RESERVED: + default: + state = POWER_SUPPLY_HEALTH_UNKNOWN; + break; + } + + return state; +} + +static int max77693_get_present(struct regmap *regmap) +{ + unsigned int data; + + /* + * Read CHG_INT_OK register. High DETBAT bit here should be + * equal to value 0x0 in CHG_DETAILS_01/BAT field. + */ + regmap_read(regmap, MAX77693_CHG_REG_CHG_INT_OK, &data); + if (data & CHG_INT_OK_DETBAT_MASK) + return 0; + return 1; +} + +static int max77693_get_online(struct regmap *regmap) +{ + unsigned int data; + + regmap_read(regmap, MAX77693_CHG_REG_CHG_INT_OK, &data); + if (data & CHG_INT_OK_CHGIN_MASK) + return 1; + return 0; +} + +static enum power_supply_property max77693_charger_props[] = { + POWER_SUPPLY_PROP_STATUS, + POWER_SUPPLY_PROP_CHARGE_TYPE, + POWER_SUPPLY_PROP_HEALTH, + POWER_SUPPLY_PROP_PRESENT, + POWER_SUPPLY_PROP_ONLINE, + POWER_SUPPLY_PROP_MODEL_NAME, + POWER_SUPPLY_PROP_MANUFACTURER, +}; + +static int max77693_charger_get_property(struct power_supply *psy, + enum power_supply_property psp, + union power_supply_propval *val) +{ + struct max77693_charger *chg = container_of(psy, + struct max77693_charger, + charger); + struct regmap *regmap = chg->max77693->regmap; + int ret = 0; + + switch (psp) { + case POWER_SUPPLY_PROP_STATUS: + val->intval = max77693_get_charger_state(regmap); + break; + case POWER_SUPPLY_PROP_CHARGE_TYPE: + val->intval = max77693_get_charge_type(regmap); + break; + case POWER_SUPPLY_PROP_HEALTH: + val->intval = max77693_get_battery_health(regmap); + break; + case POWER_SUPPLY_PROP_PRESENT: + val->intval = max77693_get_present(regmap); + break; + case POWER_SUPPLY_PROP_ONLINE: + val->intval = max77693_get_online(regmap); + break; + case POWER_SUPPLY_PROP_MODEL_NAME: + val->strval = max77693_charger_model; + break; + case POWER_SUPPLY_PROP_MANUFACTURER: + val->strval = max77693_charger_manufacturer; + break; + default: + return -EINVAL; + } + + return ret; +} + +static ssize_t device_attr_store(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count, + int (*fn)(struct max77693_charger *, unsigned long)) +{ + struct max77693_charger *chg = dev_get_drvdata(dev); + unsigned long val; + int ret; + + ret = kstrtoul(buf, 10, &val); + if (ret) + return ret; + + ret = fn(chg, val); + if (ret) + return ret; + + return count; +} + +static ssize_t fast_charge_timer_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct max77693_charger *chg = dev_get_drvdata(dev); + unsigned int data, val; + int ret; + + ret = regmap_read(chg->max77693->regmap, MAX77693_CHG_REG_CHG_CNFG_01, + &data); + if (ret < 0) + return ret; + + data &= CHG_CNFG_01_FCHGTIME_MASK; + data >>= CHG_CNFG_01_FCHGTIME_SHIFT; + switch (data) { + case 0x1 ... 0x7: + /* Starting from 4 hours, step by 2 hours */ + val = 4 + (data - 1) * 2; + break; + case 0x0: + default: + val = 0; + break; + } + + return scnprintf(buf, PAGE_SIZE, "%u\n", val); +} + +static int max77693_set_fast_charge_timer(struct max77693_charger *chg, + unsigned long hours) +{ + unsigned int data; + + /* + * 0x00 - disable + * 0x01 - 4h + * 0x02 - 6h + * ... + * 0x07 - 16h + * Round down odd values. + */ + switch (hours) { + case 4 ... 16: + data = (hours - 4) / 2 + 1; + break; + case 0: + /* Disable */ + data = 0; + break; + default: + return -EINVAL; + } + data <<= CHG_CNFG_01_FCHGTIME_SHIFT; + + return regmap_update_bits(chg->max77693->regmap, + MAX77693_CHG_REG_CHG_CNFG_01, + CHG_CNFG_01_FCHGTIME_MASK, data); +} + +static ssize_t fast_charge_timer_store(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) +{ + return device_attr_store(dev, attr, buf, count, + max77693_set_fast_charge_timer); +} + +static ssize_t top_off_threshold_current_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct max77693_charger *chg = dev_get_drvdata(dev); + unsigned int data, val; + int ret; + + ret = regmap_read(chg->max77693->regmap, MAX77693_CHG_REG_CHG_CNFG_03, + &data); + if (ret < 0) + return ret; + + data &= CHG_CNFG_03_TOITH_MASK; + data >>= CHG_CNFG_03_TOITH_SHIFT; + + if (data <= 0x04) + val = 100000 + data * 25000; + else + val = data * 50000; + + return scnprintf(buf, PAGE_SIZE, "%u\n", val); +} + +static int max77693_set_top_off_threshold_current(struct max77693_charger *chg, + unsigned long uamp) +{ + unsigned int data; + + if (uamp < 100000 || uamp > 350000) + return -EINVAL; + + if (uamp <= 200000) + data = (uamp - 100000) / 25000; + else + /* (200000, 350000> */ + data = uamp / 50000; + + data <<= CHG_CNFG_03_TOITH_SHIFT; + + return regmap_update_bits(chg->max77693->regmap, + MAX77693_CHG_REG_CHG_CNFG_03, + CHG_CNFG_03_TOITH_MASK, data); +} + +static ssize_t top_off_threshold_current_store(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) +{ + return device_attr_store(dev, attr, buf, count, + max77693_set_top_off_threshold_current); +} + +static ssize_t top_off_timer_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct max77693_charger *chg = dev_get_drvdata(dev); + unsigned int data, val; + int ret; + + ret = regmap_read(chg->max77693->regmap, MAX77693_CHG_REG_CHG_CNFG_03, + &data); + if (ret < 0) + return ret; + + data &= CHG_CNFG_03_TOTIME_MASK; + data >>= CHG_CNFG_03_TOTIME_SHIFT; + + val = data * 10; + + return scnprintf(buf, PAGE_SIZE, "%u\n", val); +} + +static int max77693_set_top_off_timer(struct max77693_charger *chg, + unsigned long minutes) +{ + unsigned int data; + + if (minutes > 70) + return -EINVAL; + + data = minutes / 10; + data <<= CHG_CNFG_03_TOTIME_SHIFT; + + return regmap_update_bits(chg->max77693->regmap, + MAX77693_CHG_REG_CHG_CNFG_03, + CHG_CNFG_03_TOTIME_MASK, data); +} + +static ssize_t top_off_timer_store(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) +{ + return device_attr_store(dev, attr, buf, count, + max77693_set_top_off_timer); +} + +static DEVICE_ATTR_RW(fast_charge_timer); +static DEVICE_ATTR_RW(top_off_threshold_current); +static DEVICE_ATTR_RW(top_off_timer); + +static int max77693_set_constant_volt(struct max77693_charger *chg, + unsigned int uvolt) +{ + unsigned int data; + + /* + * 0x00 - 3.650 V + * 0x01 - 3.675 V + * ... + * 0x1b - 4.325 V + * 0x1c - 4.340 V + * 0x1d - 4.350 V + * 0x1e - 4.375 V + * 0x1f - 4.400 V + */ + if (uvolt >= 3650000 && uvolt < 4340000) + data = (uvolt - 3650000) / 25000; + else if (uvolt >= 4340000 && uvolt < 4350000) + data = 0x1c; + else if (uvolt >= 4350000 && uvolt <= 4400000) + data = 0x1d + (uvolt - 4350000) / 25000; + else { + dev_err(chg->dev, "Wrong value for charging constant voltage\n"); + return -EINVAL; + } + + data <<= CHG_CNFG_04_CHGCVPRM_SHIFT; + + dev_dbg(chg->dev, "Charging constant voltage: %u (0x%x)\n", uvolt, + data); + + return regmap_update_bits(chg->max77693->regmap, + MAX77693_CHG_REG_CHG_CNFG_04, + CHG_CNFG_04_CHGCVPRM_MASK, data); +} + +static int max77693_set_min_system_volt(struct max77693_charger *chg, + unsigned int uvolt) +{ + unsigned int data; + + if (uvolt < 3000000 || uvolt > 3700000) { + dev_err(chg->dev, "Wrong value for minimum system regulation voltage\n"); + return -EINVAL; + } + + data = (uvolt - 3000000) / 100000; + + data <<= CHG_CNFG_04_MINVSYS_SHIFT; + + dev_dbg(chg->dev, "Minimum system regulation voltage: %u (0x%x)\n", + uvolt, data); + + return regmap_update_bits(chg->max77693->regmap, + MAX77693_CHG_REG_CHG_CNFG_04, + CHG_CNFG_04_MINVSYS_MASK, data); +} + +static int max77693_set_thermal_regulation_temp(struct max77693_charger *chg, + unsigned int cels) +{ + unsigned int data; + + switch (cels) { + case 70: + case 85: + case 100: + case 115: + data = (cels - 70) / 15; + break; + default: + dev_err(chg->dev, "Wrong value for thermal regulation loop temperature\n"); + return -EINVAL; + } + + data <<= CHG_CNFG_07_REGTEMP_SHIFT; + + dev_dbg(chg->dev, "Thermal regulation loop temperature: %u (0x%x)\n", + cels, data); + + return regmap_update_bits(chg->max77693->regmap, + MAX77693_CHG_REG_CHG_CNFG_07, + CHG_CNFG_07_REGTEMP_MASK, data); +} + +static int max77693_set_batttery_overcurrent(struct max77693_charger *chg, + unsigned int uamp) +{ + unsigned int data; + + if (uamp && (uamp < 2000000 || uamp > 3500000)) { + dev_err(chg->dev, "Wrong value for battery overcurrent\n"); + return -EINVAL; + } + + if (uamp) + data = ((uamp - 2000000) / 250000) + 1; + else + data = 0; /* disable */ + + data <<= CHG_CNFG_12_B2SOVRC_SHIFT; + + dev_dbg(chg->dev, "Battery overcurrent: %u (0x%x)\n", uamp, data); + + return regmap_update_bits(chg->max77693->regmap, + MAX77693_CHG_REG_CHG_CNFG_12, + CHG_CNFG_12_B2SOVRC_MASK, data); +} + +static int max77693_set_charge_input_threshold_volt(struct max77693_charger *chg, + unsigned int uvolt) +{ + unsigned int data; + + switch (uvolt) { + case 4300000: + data = 0x0; + break; + case 4700000: + case 4800000: + case 4900000: + data = (uvolt - 4700000) / 100000; + default: + dev_err(chg->dev, "Wrong value for charge input voltage regulation threshold\n"); + return -EINVAL; + } + + data <<= CHG_CNFG_12_VCHGINREG_SHIFT; + + dev_dbg(chg->dev, "Charge input voltage regulation threshold: %u (0x%x)\n", + uvolt, data); + + return regmap_update_bits(chg->max77693->regmap, + MAX77693_CHG_REG_CHG_CNFG_12, + CHG_CNFG_12_VCHGINREG_MASK, data); +} + +/* + * Sets charger registers to proper and safe default values. + */ +static int max77693_reg_init(struct max77693_charger *chg) +{ + int ret; + unsigned int data; + + /* Unlock charger register protection */ + data = (0x3 << CHG_CNFG_06_CHGPROT_SHIFT); + ret = regmap_update_bits(chg->max77693->regmap, + MAX77693_CHG_REG_CHG_CNFG_06, + CHG_CNFG_06_CHGPROT_MASK, data); + if (ret) { + dev_err(chg->dev, "Error unlocking registers: %d\n", ret); + return ret; + } + + ret = max77693_set_fast_charge_timer(chg, DEFAULT_FAST_CHARGE_TIMER); + if (ret) + return ret; + + ret = max77693_set_top_off_threshold_current(chg, + DEFAULT_TOP_OFF_THRESHOLD_CURRENT); + if (ret) + return ret; + + ret = max77693_set_top_off_timer(chg, DEFAULT_TOP_OFF_TIMER); + if (ret) + return ret; + + if (!chg->pdata) + return 0; + + ret = max77693_set_constant_volt(chg, + chg->pdata->constant_volt); + if (ret) + return ret; + + ret = max77693_set_min_system_volt(chg, + chg->pdata->min_system_volt); + if (ret) + return ret; + + ret = max77693_set_thermal_regulation_temp(chg, + chg->pdata->thermal_regulation_temp); + if (ret) + return ret; + + ret = max77693_set_batttery_overcurrent(chg, + chg->pdata->batttery_overcurrent); + if (ret) + return ret; + + ret = max77693_set_charge_input_threshold_volt(chg, + chg->pdata->charge_input_threshold_volt); + if (ret) + return ret; + + return 0; +} + +#ifdef CONFIG_OF +static struct max77693_charger_platform_data *max77693_dt_init( + struct device *dev) +{ + struct max77693_charger_platform_data *pdata; + struct device_node *np = dev->of_node; + + if (!np) + return NULL; + + pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + if (!pdata) + return NULL; + + if (of_property_read_u32(np, "maxim,constant-microvolt", + &pdata->constant_volt)) + pdata->constant_volt = DEFAULT_CONSTANT_VOLT; + + if (of_property_read_u32(np, "maxim,min-system-microvolt", + &pdata->min_system_volt)) + pdata->min_system_volt = DEFAULT_MIN_SYSTEM_VOLT; + + if (of_property_read_u32(np, "maxim,thermal-regulation-celsius", + &pdata->thermal_regulation_temp)) + pdata->thermal_regulation_temp = DEFAULT_THERMAL_REGULATION_TEMP; + + if (of_property_read_u32(np, "maxim,battery-overcurrent-microamp", + &pdata->batttery_overcurrent)) + pdata->batttery_overcurrent = DEFAULT_BATTERY_OVERCURRENT; + + if (of_property_read_u32(np, "maxim,charge-input-threshold-microvolt", + &pdata->charge_input_threshold_volt)) + pdata->charge_input_threshold_volt = + DEFAULT_CHARGER_INPUT_THRESHOLD_VOLT; + + return pdata; +} +#else /* CONFIG_OF */ +static struct max77693_charger_platform_data *max77693_dt_init( + struct device *dev) +{ + return NULL; +} +#endif /* CONFIG_OF */ + +static int max77693_charger_probe(struct platform_device *pdev) +{ + struct max77693_charger *chg; + struct max77693_dev *max77693 = dev_get_drvdata(pdev->dev.parent); + int ret; + + chg = devm_kzalloc(&pdev->dev, sizeof(*chg), GFP_KERNEL); + if (!chg) + return -ENOMEM; + + platform_set_drvdata(pdev, chg); + chg->dev = &pdev->dev; + chg->max77693 = max77693; + + chg->pdata = max77693_dt_init(&pdev->dev); + + ret = max77693_reg_init(chg); + if (ret) + return ret; + + chg->charger.name = max77693_charger_name; + chg->charger.type = POWER_SUPPLY_TYPE_BATTERY; + chg->charger.properties = max77693_charger_props; + chg->charger.num_properties = ARRAY_SIZE(max77693_charger_props); + chg->charger.get_property = max77693_charger_get_property; + + ret = device_create_file(&pdev->dev, &dev_attr_fast_charge_timer); + if (ret) { + dev_err(&pdev->dev, "failed: create fast charge timer sysfs entry\n"); + goto err; + } + + ret = device_create_file(&pdev->dev, + &dev_attr_top_off_threshold_current); + if (ret) { + dev_err(&pdev->dev, "failed: create top off current sysfs entry\n"); + goto err; + } + + ret = device_create_file(&pdev->dev, &dev_attr_top_off_timer); + if (ret) { + dev_err(&pdev->dev, "failed: create top off timer sysfs entry\n"); + goto err; + } + + ret = power_supply_register(&pdev->dev, &chg->charger); + if (ret) { + dev_err(&pdev->dev, "failed: power supply register\n"); + goto err; + } + + return 0; + +err: + device_remove_file(&pdev->dev, &dev_attr_top_off_timer); + device_remove_file(&pdev->dev, &dev_attr_top_off_threshold_current); + device_remove_file(&pdev->dev, &dev_attr_fast_charge_timer); + + return ret; +} + +static int max77693_charger_remove(struct platform_device *pdev) +{ + struct max77693_charger *chg = platform_get_drvdata(pdev); + + device_remove_file(&pdev->dev, &dev_attr_top_off_timer); + device_remove_file(&pdev->dev, &dev_attr_top_off_threshold_current); + device_remove_file(&pdev->dev, &dev_attr_fast_charge_timer); + + power_supply_unregister(&chg->charger); + + return 0; +} + +static const struct platform_device_id max77693_charger_id[] = { + { "max77693-charger", 0, }, + { } +}; +MODULE_DEVICE_TABLE(platform, max77693_charger_id); + +static struct platform_driver max77693_charger_driver = { + .driver = { + .owner = THIS_MODULE, + .name = "max77693-charger", + }, + .probe = max77693_charger_probe, + .remove = max77693_charger_remove, + .id_table = max77693_charger_id, +}; +module_platform_driver(max77693_charger_driver); + +MODULE_AUTHOR("Krzysztof Kozlowski <k.kozlowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>"); +MODULE_DESCRIPTION("Maxim 77693 charger driver"); +MODULE_LICENSE("GPL"); -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [PATCH v2 4/5] power: max77693: Add charger driver for Maxim 77693 2014-10-20 12:34 ` [PATCH v2 4/5] power: max77693: Add charger driver for Maxim 77693 Krzysztof Kozlowski @ 2014-10-27 18:56 ` Sebastian Reichel [not found] ` <20141027185656.GB18965-SfvFxonMDyemK9LvCR3Hrw@public.gmane.org> 0 siblings, 1 reply; 14+ messages in thread From: Sebastian Reichel @ 2014-10-27 18:56 UTC (permalink / raw) To: Krzysztof Kozlowski Cc: Dmitry Eremin-Solenikov, David Woodhouse, linux-kernel, linux-pm, Samuel Ortiz, Lee Jones, linux-api, devicetree, Kyungmin Park, Marek Szyprowski, Bartlomiej Zolnierkiewicz [-- Attachment #1: Type: text/plain, Size: 791 bytes --] Hi, On Mon, Oct 20, 2014 at 02:34:48PM +0200, Krzysztof Kozlowski wrote: > Add new driver for Maxim 77693 switch-mode charger (part of max77693 > MFD driver) providing power supply class information to userspace. > > The charger has +20V tolerant input. Current input can be set from 0 to > 2.58 A. The charger can deliver up to 2.1 A to the battery or 3.5 A to > the system (when supplying additional current from battery to system). > > The driver is configured through DTS (battery and system related > settings) and sysfs entries (timers and top-off charging threshold). > > Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com> I guess it makes sense to queue this together with the mfd parts. Acked-By: Sebastian Reichel <sre@kernel.org> -- Sebastian [-- Attachment #2: Digital signature --] [-- Type: application/pgp-signature, Size: 819 bytes --] ^ permalink raw reply [flat|nested] 14+ messages in thread
[parent not found: <20141027185656.GB18965-SfvFxonMDyemK9LvCR3Hrw@public.gmane.org>]
* Re: [PATCH v2 4/5] power: max77693: Add charger driver for Maxim 77693 [not found] ` <20141027185656.GB18965-SfvFxonMDyemK9LvCR3Hrw@public.gmane.org> @ 2014-10-28 9:16 ` Krzysztof Kozlowski 0 siblings, 0 replies; 14+ messages in thread From: Krzysztof Kozlowski @ 2014-10-28 9:16 UTC (permalink / raw) To: Sebastian Reichel Cc: Dmitry Eremin-Solenikov, David Woodhouse, linux-kernel-u79uwXL29TY76Z2rM5mHXA, linux-pm-u79uwXL29TY76Z2rM5mHXA, Samuel Ortiz, Lee Jones, linux-api-u79uwXL29TY76Z2rM5mHXA, devicetree-u79uwXL29TY76Z2rM5mHXA, Kyungmin Park, Marek Szyprowski, Bartlomiej Zolnierkiewicz On pon, 2014-10-27 at 19:56 +0100, Sebastian Reichel wrote: > Hi, > > On Mon, Oct 20, 2014 at 02:34:48PM +0200, Krzysztof Kozlowski wrote: > > Add new driver for Maxim 77693 switch-mode charger (part of max77693 > > MFD driver) providing power supply class information to userspace. > > > > The charger has +20V tolerant input. Current input can be set from 0 to > > 2.58 A. The charger can deliver up to 2.1 A to the battery or 3.5 A to > > the system (when supplying additional current from battery to system). > > > > The driver is configured through DTS (battery and system related > > settings) and sysfs entries (timers and top-off charging threshold). > > > > Signed-off-by: Krzysztof Kozlowski <k.kozlowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org> > > I guess it makes sense to queue this together with the mfd parts. > > Acked-By: Sebastian Reichel <sre-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> Thank you. Could you also look at documentation change, patch 5/5: Documentation: charger: max77693: Document exported sysfs entry https://lkml.org/lkml/2014/10/20/232 I think that one also needs your ack as this is power supply related ABI. Best regards, Krzysztof ^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH v2 2/5] mfd: max77693: Map charger device to its own of_node 2014-10-20 12:34 [PATCH v2 0/5] power/mfd: Add max77693 charger driver Krzysztof Kozlowski [not found] ` <1413808489-3524-1-git-send-email-k.kozlowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org> @ 2014-10-20 12:34 ` Krzysztof Kozlowski 2014-10-20 15:06 ` Lee Jones 2014-10-21 10:17 ` Lee Jones 2014-10-20 12:34 ` [PATCH v2 3/5] mfd: max77693: Add defines for MAX77693 charger driver Krzysztof Kozlowski 2014-10-20 12:34 ` [PATCH v2 5/5] Documentation: charger: max77693: Document exported sysfs entry Krzysztof Kozlowski 3 siblings, 2 replies; 14+ messages in thread From: Krzysztof Kozlowski @ 2014-10-20 12:34 UTC (permalink / raw) To: Sebastian Reichel, Dmitry Eremin-Solenikov, David Woodhouse, linux-kernel, linux-pm, Samuel Ortiz, Lee Jones, linux-api, devicetree Cc: Kyungmin Park, Marek Szyprowski, Bartlomiej Zolnierkiewicz, Krzysztof Kozlowski Add a "maxim,max77693-charger" of_compatible to the mfd_cell so the MFD child device (the charger) will have its own of_node set. This will be used by the max77693 charger driver in next patches to obtain battery configuration from DTS. Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com> --- drivers/mfd/max77693.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/mfd/max77693.c b/drivers/mfd/max77693.c index cf008f45968c..2277a11b6629 100644 --- a/drivers/mfd/max77693.c +++ b/drivers/mfd/max77693.c @@ -43,7 +43,10 @@ static const struct mfd_cell max77693_devs[] = { { .name = "max77693-pmic", }, - { .name = "max77693-charger", }, + { + .name = "max77693-charger", + .of_compatible = "maxim,max77693-charger", + }, { .name = "max77693-muic", }, { .name = "max77693-haptic", }, { -- 1.9.1 ^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [PATCH v2 2/5] mfd: max77693: Map charger device to its own of_node 2014-10-20 12:34 ` [PATCH v2 2/5] mfd: max77693: Map charger device to its own of_node Krzysztof Kozlowski @ 2014-10-20 15:06 ` Lee Jones 2014-10-20 15:09 ` Krzysztof Kozlowski 2014-10-21 10:17 ` Lee Jones 1 sibling, 1 reply; 14+ messages in thread From: Lee Jones @ 2014-10-20 15:06 UTC (permalink / raw) To: Krzysztof Kozlowski Cc: Sebastian Reichel, Dmitry Eremin-Solenikov, David Woodhouse, linux-kernel, linux-pm, Samuel Ortiz, linux-api, devicetree, Kyungmin Park, Marek Szyprowski, Bartlomiej Zolnierkiewicz On Mon, 20 Oct 2014, Krzysztof Kozlowski wrote: > Add a "maxim,max77693-charger" of_compatible to the mfd_cell so the MFD > child device (the charger) will have its own of_node set. This will be > used by the max77693 charger driver in next patches to obtain battery > configuration from DTS. > > Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com> > --- > drivers/mfd/max77693.c | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) > > diff --git a/drivers/mfd/max77693.c b/drivers/mfd/max77693.c > index cf008f45968c..2277a11b6629 100644 > --- a/drivers/mfd/max77693.c > +++ b/drivers/mfd/max77693.c > @@ -43,7 +43,10 @@ > > static const struct mfd_cell max77693_devs[] = { > { .name = "max77693-pmic", }, > - { .name = "max77693-charger", }, > + { > + .name = "max77693-charger", > + .of_compatible = "maxim,max77693-charger", > + }, > { .name = "max77693-muic", }, > { .name = "max77693-haptic", }, > { I'm guessing this can be applied separately? -- Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v2 2/5] mfd: max77693: Map charger device to its own of_node 2014-10-20 15:06 ` Lee Jones @ 2014-10-20 15:09 ` Krzysztof Kozlowski 2014-10-21 10:17 ` Lee Jones 0 siblings, 1 reply; 14+ messages in thread From: Krzysztof Kozlowski @ 2014-10-20 15:09 UTC (permalink / raw) To: Lee Jones Cc: Sebastian Reichel, Dmitry Eremin-Solenikov, David Woodhouse, linux-kernel-u79uwXL29TY76Z2rM5mHXA, linux-pm-u79uwXL29TY76Z2rM5mHXA, Samuel Ortiz, linux-api-u79uwXL29TY76Z2rM5mHXA, devicetree-u79uwXL29TY76Z2rM5mHXA, Kyungmin Park, Marek Szyprowski, Bartlomiej Zolnierkiewicz On pon, 2014-10-20 at 16:06 +0100, Lee Jones wrote: > On Mon, 20 Oct 2014, Krzysztof Kozlowski wrote: > > > Add a "maxim,max77693-charger" of_compatible to the mfd_cell so the MFD > > child device (the charger) will have its own of_node set. This will be > > used by the max77693 charger driver in next patches to obtain battery > > configuration from DTS. > > > > Signed-off-by: Krzysztof Kozlowski <k.kozlowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org> > > --- > > drivers/mfd/max77693.c | 5 ++++- > > 1 file changed, 4 insertions(+), 1 deletion(-) > > > > diff --git a/drivers/mfd/max77693.c b/drivers/mfd/max77693.c > > index cf008f45968c..2277a11b6629 100644 > > --- a/drivers/mfd/max77693.c > > +++ b/drivers/mfd/max77693.c > > @@ -43,7 +43,10 @@ > > > > static const struct mfd_cell max77693_devs[] = { > > { .name = "max77693-pmic", }, > > - { .name = "max77693-charger", }, > > + { > > + .name = "max77693-charger", > > + .of_compatible = "maxim,max77693-charger", > > + }, > > { .name = "max77693-muic", }, > > { .name = "max77693-haptic", }, > > { > > I'm guessing this can be applied separately? Yes. Patch 3/5 also (it adds necessary defines and symbols for chargers). Best regards, Krzysztof ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v2 2/5] mfd: max77693: Map charger device to its own of_node 2014-10-20 15:09 ` Krzysztof Kozlowski @ 2014-10-21 10:17 ` Lee Jones 2014-10-21 10:20 ` Krzysztof Kozlowski 0 siblings, 1 reply; 14+ messages in thread From: Lee Jones @ 2014-10-21 10:17 UTC (permalink / raw) To: Krzysztof Kozlowski Cc: Sebastian Reichel, Dmitry Eremin-Solenikov, David Woodhouse, linux-kernel, linux-pm, Samuel Ortiz, linux-api, devicetree, Kyungmin Park, Marek Szyprowski, Bartlomiej Zolnierkiewicz On Mon, 20 Oct 2014, Krzysztof Kozlowski wrote: > On pon, 2014-10-20 at 16:06 +0100, Lee Jones wrote: > > On Mon, 20 Oct 2014, Krzysztof Kozlowski wrote: > > > > > Add a "maxim,max77693-charger" of_compatible to the mfd_cell so the MFD > > > child device (the charger) will have its own of_node set. This will be > > > used by the max77693 charger driver in next patches to obtain battery > > > configuration from DTS. > > > > > > Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com> > > > --- > > > drivers/mfd/max77693.c | 5 ++++- > > > 1 file changed, 4 insertions(+), 1 deletion(-) > > > > > > diff --git a/drivers/mfd/max77693.c b/drivers/mfd/max77693.c > > > index cf008f45968c..2277a11b6629 100644 > > > --- a/drivers/mfd/max77693.c > > > +++ b/drivers/mfd/max77693.c > > > @@ -43,7 +43,10 @@ > > > > > > static const struct mfd_cell max77693_devs[] = { > > > { .name = "max77693-pmic", }, > > > - { .name = "max77693-charger", }, > > > + { > > > + .name = "max77693-charger", > > > + .of_compatible = "maxim,max77693-charger", > > > + }, > > > { .name = "max77693-muic", }, > > > { .name = "max77693-haptic", }, > > > { > > > > I'm guessing this can be applied separately? > > Yes. Patch 3/5 also (it adds necessary defines and symbols for > chargers). I'll take this patch, but I think 3/5 is required by some of the other patches in the set, no? -- Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v2 2/5] mfd: max77693: Map charger device to its own of_node 2014-10-21 10:17 ` Lee Jones @ 2014-10-21 10:20 ` Krzysztof Kozlowski 2014-10-21 10:27 ` Lee Jones 0 siblings, 1 reply; 14+ messages in thread From: Krzysztof Kozlowski @ 2014-10-21 10:20 UTC (permalink / raw) To: Lee Jones Cc: Sebastian Reichel, Dmitry Eremin-Solenikov, David Woodhouse, linux-kernel-u79uwXL29TY76Z2rM5mHXA, linux-pm-u79uwXL29TY76Z2rM5mHXA, Samuel Ortiz, linux-api-u79uwXL29TY76Z2rM5mHXA, devicetree-u79uwXL29TY76Z2rM5mHXA, Kyungmin Park, Marek Szyprowski, Bartlomiej Zolnierkiewicz On wto, 2014-10-21 at 11:17 +0100, Lee Jones wrote: > On Mon, 20 Oct 2014, Krzysztof Kozlowski wrote: > > > On pon, 2014-10-20 at 16:06 +0100, Lee Jones wrote: > > > On Mon, 20 Oct 2014, Krzysztof Kozlowski wrote: > > > > > > > Add a "maxim,max77693-charger" of_compatible to the mfd_cell so the MFD > > > > child device (the charger) will have its own of_node set. This will be > > > > used by the max77693 charger driver in next patches to obtain battery > > > > configuration from DTS. > > > > > > > > Signed-off-by: Krzysztof Kozlowski <k.kozlowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org> > > > > --- > > > > drivers/mfd/max77693.c | 5 ++++- > > > > 1 file changed, 4 insertions(+), 1 deletion(-) > > > > > > > > diff --git a/drivers/mfd/max77693.c b/drivers/mfd/max77693.c > > > > index cf008f45968c..2277a11b6629 100644 > > > > --- a/drivers/mfd/max77693.c > > > > +++ b/drivers/mfd/max77693.c > > > > @@ -43,7 +43,10 @@ > > > > > > > > static const struct mfd_cell max77693_devs[] = { > > > > { .name = "max77693-pmic", }, > > > > - { .name = "max77693-charger", }, > > > > + { > > > > + .name = "max77693-charger", > > > > + .of_compatible = "maxim,max77693-charger", > > > > + }, > > > > { .name = "max77693-muic", }, > > > > { .name = "max77693-haptic", }, > > > > { > > > > > > I'm guessing this can be applied separately? > > > > Yes. Patch 3/5 also (it adds necessary defines and symbols for > > chargers). > > I'll take this patch, but I think 3/5 is required by some of the other > patches in the set, no? Yes, it is required by 4/5 (charger driver). Best regards, Krzysztof ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v2 2/5] mfd: max77693: Map charger device to its own of_node 2014-10-21 10:20 ` Krzysztof Kozlowski @ 2014-10-21 10:27 ` Lee Jones 0 siblings, 0 replies; 14+ messages in thread From: Lee Jones @ 2014-10-21 10:27 UTC (permalink / raw) To: Krzysztof Kozlowski Cc: Sebastian Reichel, Dmitry Eremin-Solenikov, David Woodhouse, linux-kernel-u79uwXL29TY76Z2rM5mHXA, linux-pm-u79uwXL29TY76Z2rM5mHXA, Samuel Ortiz, linux-api-u79uwXL29TY76Z2rM5mHXA, devicetree-u79uwXL29TY76Z2rM5mHXA, Kyungmin Park, Marek Szyprowski, Bartlomiej Zolnierkiewicz On Tue, 21 Oct 2014, Krzysztof Kozlowski wrote: > On wto, 2014-10-21 at 11:17 +0100, Lee Jones wrote: > > On Mon, 20 Oct 2014, Krzysztof Kozlowski wrote: > > > > > On pon, 2014-10-20 at 16:06 +0100, Lee Jones wrote: > > > > On Mon, 20 Oct 2014, Krzysztof Kozlowski wrote: > > > > > > > > > Add a "maxim,max77693-charger" of_compatible to the mfd_cell so the MFD > > > > > child device (the charger) will have its own of_node set. This will be > > > > > used by the max77693 charger driver in next patches to obtain battery > > > > > configuration from DTS. > > > > > > > > > > Signed-off-by: Krzysztof Kozlowski <k.kozlowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org> > > > > > --- > > > > > drivers/mfd/max77693.c | 5 ++++- > > > > > 1 file changed, 4 insertions(+), 1 deletion(-) > > > > > > > > > > diff --git a/drivers/mfd/max77693.c b/drivers/mfd/max77693.c > > > > > index cf008f45968c..2277a11b6629 100644 > > > > > --- a/drivers/mfd/max77693.c > > > > > +++ b/drivers/mfd/max77693.c > > > > > @@ -43,7 +43,10 @@ > > > > > > > > > > static const struct mfd_cell max77693_devs[] = { > > > > > { .name = "max77693-pmic", }, > > > > > - { .name = "max77693-charger", }, > > > > > + { > > > > > + .name = "max77693-charger", > > > > > + .of_compatible = "maxim,max77693-charger", > > > > > + }, > > > > > { .name = "max77693-muic", }, > > > > > { .name = "max77693-haptic", }, > > > > > { > > > > > > > > I'm guessing this can be applied separately? > > > > > > Yes. Patch 3/5 also (it adds necessary defines and symbols for > > > chargers). > > > > I'll take this patch, but I think 3/5 is required by some of the other > > patches in the set, no? > > Yes, it is required by 4/5 (charger driver). Okay, so it must go in with the others then. I need Acks for that. -- Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v2 2/5] mfd: max77693: Map charger device to its own of_node 2014-10-20 12:34 ` [PATCH v2 2/5] mfd: max77693: Map charger device to its own of_node Krzysztof Kozlowski 2014-10-20 15:06 ` Lee Jones @ 2014-10-21 10:17 ` Lee Jones 1 sibling, 0 replies; 14+ messages in thread From: Lee Jones @ 2014-10-21 10:17 UTC (permalink / raw) To: Krzysztof Kozlowski Cc: Sebastian Reichel, Dmitry Eremin-Solenikov, David Woodhouse, linux-kernel, linux-pm, Samuel Ortiz, linux-api, devicetree, Kyungmin Park, Marek Szyprowski, Bartlomiej Zolnierkiewicz On Mon, 20 Oct 2014, Krzysztof Kozlowski wrote: > Add a "maxim,max77693-charger" of_compatible to the mfd_cell so the MFD > child device (the charger) will have its own of_node set. This will be > used by the max77693 charger driver in next patches to obtain battery > configuration from DTS. > > Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com> > --- > drivers/mfd/max77693.c | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) Applied, thanks. > diff --git a/drivers/mfd/max77693.c b/drivers/mfd/max77693.c > index cf008f45968c..2277a11b6629 100644 > --- a/drivers/mfd/max77693.c > +++ b/drivers/mfd/max77693.c > @@ -43,7 +43,10 @@ > > static const struct mfd_cell max77693_devs[] = { > { .name = "max77693-pmic", }, > - { .name = "max77693-charger", }, > + { > + .name = "max77693-charger", > + .of_compatible = "maxim,max77693-charger", > + }, > { .name = "max77693-muic", }, > { .name = "max77693-haptic", }, > { -- Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog ^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH v2 3/5] mfd: max77693: Add defines for MAX77693 charger driver 2014-10-20 12:34 [PATCH v2 0/5] power/mfd: Add max77693 charger driver Krzysztof Kozlowski [not found] ` <1413808489-3524-1-git-send-email-k.kozlowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org> 2014-10-20 12:34 ` [PATCH v2 2/5] mfd: max77693: Map charger device to its own of_node Krzysztof Kozlowski @ 2014-10-20 12:34 ` Krzysztof Kozlowski 2014-10-20 12:34 ` [PATCH v2 5/5] Documentation: charger: max77693: Document exported sysfs entry Krzysztof Kozlowski 3 siblings, 0 replies; 14+ messages in thread From: Krzysztof Kozlowski @ 2014-10-20 12:34 UTC (permalink / raw) To: Sebastian Reichel, Dmitry Eremin-Solenikov, David Woodhouse, linux-kernel, linux-pm, Samuel Ortiz, Lee Jones, linux-api, devicetree Cc: Kyungmin Park, Marek Szyprowski, Bartlomiej Zolnierkiewicz, Krzysztof Kozlowski Prepare for adding support for Maxim 77693 charger by adding necessary new defines and structure for device tree parsed data. Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com> Acked-by: Lee Jones <lee.jones@linaro.org> --- include/linux/mfd/max77693-private.h | 108 +++++++++++++++++++++++++++++++++++ include/linux/mfd/max77693.h | 8 +++ 2 files changed, 116 insertions(+) diff --git a/include/linux/mfd/max77693-private.h b/include/linux/mfd/max77693-private.h index fc17d56581b2..e1b2b61285b9 100644 --- a/include/linux/mfd/max77693-private.h +++ b/include/linux/mfd/max77693-private.h @@ -144,10 +144,118 @@ enum max77693_pmic_reg { #define FLASH_INT_FLED1_SHORT BIT(3) #define FLASH_INT_OVER_CURRENT BIT(4) +/* Fast charge timer in in hours */ +#define DEFAULT_FAST_CHARGE_TIMER 4 +/* microamps */ +#define DEFAULT_TOP_OFF_THRESHOLD_CURRENT 150000 +/* minutes */ +#define DEFAULT_TOP_OFF_TIMER 30 +/* microvolts */ +#define DEFAULT_CONSTANT_VOLT 4200000 +/* microvolts */ +#define DEFAULT_MIN_SYSTEM_VOLT 3600000 +/* celsius */ +#define DEFAULT_THERMAL_REGULATION_TEMP 100 +/* microamps */ +#define DEFAULT_BATTERY_OVERCURRENT 3500000 +/* microvolts */ +#define DEFAULT_CHARGER_INPUT_THRESHOLD_VOLT 4300000 + +/* MAX77693_CHG_REG_CHG_INT_OK register */ +#define CHG_INT_OK_BYP_SHIFT 0 +#define CHG_INT_OK_BAT_SHIFT 3 +#define CHG_INT_OK_CHG_SHIFT 4 +#define CHG_INT_OK_CHGIN_SHIFT 6 +#define CHG_INT_OK_DETBAT_SHIFT 7 +#define CHG_INT_OK_BYP_MASK BIT(CHG_INT_OK_BYP_SHIFT) +#define CHG_INT_OK_BAT_MASK BIT(CHG_INT_OK_BAT_SHIFT) +#define CHG_INT_OK_CHG_MASK BIT(CHG_INT_OK_CHG_SHIFT) +#define CHG_INT_OK_CHGIN_MASK BIT(CHG_INT_OK_CHGIN_SHIFT) +#define CHG_INT_OK_DETBAT_MASK BIT(CHG_INT_OK_DETBAT_SHIFT) + +/* MAX77693_CHG_REG_CHG_DETAILS_00 register */ +#define CHG_DETAILS_00_CHGIN_SHIFT 5 +#define CHG_DETAILS_00_CHGIN_MASK (0x3 << CHG_DETAILS_00_CHGIN_SHIFT) + +/* MAX77693_CHG_REG_CHG_DETAILS_01 register */ +#define CHG_DETAILS_01_CHG_SHIFT 0 +#define CHG_DETAILS_01_BAT_SHIFT 4 +#define CHG_DETAILS_01_TREG_SHIFT 7 +#define CHG_DETAILS_01_CHG_MASK (0xf << CHG_DETAILS_01_CHG_SHIFT) +#define CHG_DETAILS_01_BAT_MASK (0x7 << CHG_DETAILS_01_BAT_SHIFT) +#define CHG_DETAILS_01_TREG_MASK BIT(7) + +/* MAX77693_CHG_REG_CHG_DETAILS_01/CHG field */ +enum max77693_charger_charging_state { + MAX77693_CHARGING_PREQUALIFICATION = 0x0, + MAX77693_CHARGING_FAST_CONST_CURRENT, + MAX77693_CHARGING_FAST_CONST_VOLTAGE, + MAX77693_CHARGING_TOP_OFF, + MAX77693_CHARGING_DONE, + MAX77693_CHARGING_HIGH_TEMP, + MAX77693_CHARGING_TIMER_EXPIRED, + MAX77693_CHARGING_THERMISTOR_SUSPEND, + MAX77693_CHARGING_OFF, + MAX77693_CHARGING_RESERVED, + MAX77693_CHARGING_OVER_TEMP, + MAX77693_CHARGING_WATCHDOG_EXPIRED, +}; + +/* MAX77693_CHG_REG_CHG_DETAILS_01/BAT field */ +enum max77693_charger_battery_state { + MAX77693_BATTERY_NOBAT = 0x0, + /* Dead-battery or low-battery prequalification */ + MAX77693_BATTERY_PREQUALIFICATION, + MAX77693_BATTERY_TIMER_EXPIRED, + MAX77693_BATTERY_GOOD, + MAX77693_BATTERY_LOWVOLTAGE, + MAX77693_BATTERY_OVERVOLTAGE, + MAX77693_BATTERY_OVERCURRENT, + MAX77693_BATTERY_RESERVED, +}; + +/* MAX77693_CHG_REG_CHG_DETAILS_02 register */ +#define CHG_DETAILS_02_BYP_SHIFT 0 +#define CHG_DETAILS_02_BYP_MASK (0xf << CHG_DETAILS_02_BYP_SHIFT) + /* MAX77693 CHG_CNFG_00 register */ #define CHG_CNFG_00_CHG_MASK 0x1 #define CHG_CNFG_00_BUCK_MASK 0x4 +/* MAX77693_CHG_REG_CHG_CNFG_01 register */ +#define CHG_CNFG_01_FCHGTIME_SHIFT 0 +#define CHG_CNFG_01_CHGRSTRT_SHIFT 4 +#define CHG_CNFG_01_PQEN_SHIFT 7 +#define CHG_CNFG_01_FCHGTIME_MASK (0x7 << CHG_CNFG_01_FCHGTIME_SHIFT) +#define CHG_CNFG_01_CHGRSTRT_MASK (0x3 << CHG_CNFG_01_CHGRSTRT_SHIFT) +#define CHG_CNFG_01_PQEN_MAKS BIT(CHG_CNFG_01_PQEN_SHIFT) + +/* MAX77693_CHG_REG_CHG_CNFG_03 register */ +#define CHG_CNFG_03_TOITH_SHIFT 0 +#define CHG_CNFG_03_TOTIME_SHIFT 3 +#define CHG_CNFG_03_TOITH_MASK (0x7 << CHG_CNFG_03_TOITH_SHIFT) +#define CHG_CNFG_03_TOTIME_MASK (0x7 << CHG_CNFG_03_TOTIME_SHIFT) + +/* MAX77693_CHG_REG_CHG_CNFG_04 register */ +#define CHG_CNFG_04_CHGCVPRM_SHIFT 0 +#define CHG_CNFG_04_MINVSYS_SHIFT 5 +#define CHG_CNFG_04_CHGCVPRM_MASK (0x1f << CHG_CNFG_04_CHGCVPRM_SHIFT) +#define CHG_CNFG_04_MINVSYS_MASK (0x7 << CHG_CNFG_04_MINVSYS_SHIFT) + +/* MAX77693_CHG_REG_CHG_CNFG_06 register */ +#define CHG_CNFG_06_CHGPROT_SHIFT 2 +#define CHG_CNFG_06_CHGPROT_MASK (0x3 << CHG_CNFG_06_CHGPROT_SHIFT) + +/* MAX77693_CHG_REG_CHG_CNFG_07 register */ +#define CHG_CNFG_07_REGTEMP_SHIFT 5 +#define CHG_CNFG_07_REGTEMP_MASK (0x3 << CHG_CNFG_07_REGTEMP_SHIFT) + +/* MAX77693_CHG_REG_CHG_CNFG_12 register */ +#define CHG_CNFG_12_B2SOVRC_SHIFT 0 +#define CHG_CNFG_12_VCHGINREG_SHIFT 3 +#define CHG_CNFG_12_B2SOVRC_MASK (0x7 << CHG_CNFG_12_B2SOVRC_SHIFT) +#define CHG_CNFG_12_VCHGINREG_MASK (0x3 << CHG_CNFG_12_VCHGINREG_SHIFT) + /* MAX77693 CHG_CNFG_09 Register */ #define CHG_CNFG_09_CHGIN_ILIM_MASK 0x7F diff --git a/include/linux/mfd/max77693.h b/include/linux/mfd/max77693.h index f0b6585cd874..88ef24b28294 100644 --- a/include/linux/mfd/max77693.h +++ b/include/linux/mfd/max77693.h @@ -63,6 +63,14 @@ struct max77693_muic_platform_data { int path_uart; }; +struct max77693_charger_platform_data { + u32 constant_volt; + u32 min_system_volt; + u32 thermal_regulation_temp; + u32 batttery_overcurrent; + u32 charge_input_threshold_volt; +}; + /* MAX77693 led flash */ /* triggers */ -- 1.9.1 ^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH v2 5/5] Documentation: charger: max77693: Document exported sysfs entry 2014-10-20 12:34 [PATCH v2 0/5] power/mfd: Add max77693 charger driver Krzysztof Kozlowski ` (2 preceding siblings ...) 2014-10-20 12:34 ` [PATCH v2 3/5] mfd: max77693: Add defines for MAX77693 charger driver Krzysztof Kozlowski @ 2014-10-20 12:34 ` Krzysztof Kozlowski 3 siblings, 0 replies; 14+ messages in thread From: Krzysztof Kozlowski @ 2014-10-20 12:34 UTC (permalink / raw) To: Sebastian Reichel, Dmitry Eremin-Solenikov, David Woodhouse, linux-kernel, linux-pm, Samuel Ortiz, Lee Jones, linux-api, devicetree Cc: Kyungmin Park, Marek Szyprowski, Bartlomiej Zolnierkiewicz, Krzysztof Kozlowski Document the settings exported by max77693 charger driver through sysfs entries: - fast_charge_timer - top_off_threshold_current - top_off_timer Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com> --- Documentation/ABI/testing/sysfs-class-power | 42 +++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-class-power b/Documentation/ABI/testing/sysfs-class-power index 909e7602c717..369d2a2d7d3e 100644 --- a/Documentation/ABI/testing/sysfs-class-power +++ b/Documentation/ABI/testing/sysfs-class-power @@ -32,3 +32,45 @@ Description: Valid values: - 5, 6 or 7 (hours), - 0: disabled. + +What: /sys/class/power_supply/max77693-charger/device/fast_charge_timer +Date: January 2015 +KernelVersion: 3.19.0 +Contact: Krzysztof Kozlowski <k.kozlowski@samsung.com> +Description: + This entry shows and sets the maximum time the max77693 + charger operates in fast-charge mode. When the timer expires + the device will terminate fast-charge mode (charging current + will drop to 0 A) and will trigger interrupt. + + Valid values: + - 4 - 16 (hours), step by 2 (rounded down) + - 0: disabled. + +What: /sys/class/power_supply/max77693-charger/device/top_off_threshold_current +Date: January 2015 +KernelVersion: 3.19.0 +Contact: Krzysztof Kozlowski <k.kozlowski@samsung.com> +Description: + This entry shows and sets the charging current threshold for + entering top-off charging mode. When charging current in fast + charge mode drops below this value, the charger will trigger + interrupt and start top-off charging mode. + + Valid values: + - 100000 - 200000 (microamps), step by 25000 (rounded down) + - 200000 - 350000 (microamps), step by 50000 (rounded down) + - 0: disabled. + +What: /sys/class/power_supply/max77693-charger/device/top_off_timer +Date: January 2015 +KernelVersion: 3.19.0 +Contact: Krzysztof Kozlowski <k.kozlowski@samsung.com> +Description: + This entry shows and sets the maximum time the max77693 + charger operates in top-off charge mode. When the timer expires + the device will terminate top-off charge mode (charging current + will drop to 0 A) and will trigger interrupt. + + Valid values: + - 0 - 70 (minutes), step by 10 (rounded down) -- 1.9.1 ^ permalink raw reply related [flat|nested] 14+ messages in thread
end of thread, other threads:[~2014-10-28 9:16 UTC | newest] Thread overview: 14+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2014-10-20 12:34 [PATCH v2 0/5] power/mfd: Add max77693 charger driver Krzysztof Kozlowski [not found] ` <1413808489-3524-1-git-send-email-k.kozlowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org> 2014-10-20 12:34 ` [PATCH v2 1/5] devicetree: mfd: max77693: Document new bindings for charger Krzysztof Kozlowski 2014-10-20 12:34 ` [PATCH v2 4/5] power: max77693: Add charger driver for Maxim 77693 Krzysztof Kozlowski 2014-10-27 18:56 ` Sebastian Reichel [not found] ` <20141027185656.GB18965-SfvFxonMDyemK9LvCR3Hrw@public.gmane.org> 2014-10-28 9:16 ` Krzysztof Kozlowski 2014-10-20 12:34 ` [PATCH v2 2/5] mfd: max77693: Map charger device to its own of_node Krzysztof Kozlowski 2014-10-20 15:06 ` Lee Jones 2014-10-20 15:09 ` Krzysztof Kozlowski 2014-10-21 10:17 ` Lee Jones 2014-10-21 10:20 ` Krzysztof Kozlowski 2014-10-21 10:27 ` Lee Jones 2014-10-21 10:17 ` Lee Jones 2014-10-20 12:34 ` [PATCH v2 3/5] mfd: max77693: Add defines for MAX77693 charger driver Krzysztof Kozlowski 2014-10-20 12:34 ` [PATCH v2 5/5] Documentation: charger: max77693: Document exported sysfs entry Krzysztof Kozlowski
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).