197fb5e8dSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
28c0984e5SSebastian Reichel /* Copyright (c) 2014, Sony Mobile Communications Inc.
38c0984e5SSebastian Reichel *
48c0984e5SSebastian Reichel * This driver is for the multi-block Switch-Mode Battery Charger and Boost
58c0984e5SSebastian Reichel * (SMBB) hardware, found in Qualcomm PM8941 PMICs. The charger is an
68c0984e5SSebastian Reichel * integrated, single-cell lithium-ion battery charger.
78c0984e5SSebastian Reichel *
88c0984e5SSebastian Reichel * Sub-components:
98c0984e5SSebastian Reichel * - Charger core
108c0984e5SSebastian Reichel * - Buck
118c0984e5SSebastian Reichel * - DC charge-path
128c0984e5SSebastian Reichel * - USB charge-path
138c0984e5SSebastian Reichel * - Battery interface
148c0984e5SSebastian Reichel * - Boost (not implemented)
158c0984e5SSebastian Reichel * - Misc
168c0984e5SSebastian Reichel * - HF-Buck
178c0984e5SSebastian Reichel */
188c0984e5SSebastian Reichel
198c0984e5SSebastian Reichel #include <linux/errno.h>
208c0984e5SSebastian Reichel #include <linux/interrupt.h>
218c0984e5SSebastian Reichel #include <linux/kernel.h>
228c0984e5SSebastian Reichel #include <linux/module.h>
238c0984e5SSebastian Reichel #include <linux/mutex.h>
248c0984e5SSebastian Reichel #include <linux/of.h>
258c0984e5SSebastian Reichel #include <linux/platform_device.h>
268c0984e5SSebastian Reichel #include <linux/power_supply.h>
278c0984e5SSebastian Reichel #include <linux/regmap.h>
288c0984e5SSebastian Reichel #include <linux/slab.h>
29176aa360SChanwoo Choi #include <linux/extcon-provider.h>
3061274effSBird, Tim #include <linux/regulator/driver.h>
318c0984e5SSebastian Reichel
328c0984e5SSebastian Reichel #define SMBB_CHG_VMAX 0x040
338c0984e5SSebastian Reichel #define SMBB_CHG_VSAFE 0x041
348c0984e5SSebastian Reichel #define SMBB_CHG_CFG 0x043
358c0984e5SSebastian Reichel #define SMBB_CHG_IMAX 0x044
368c0984e5SSebastian Reichel #define SMBB_CHG_ISAFE 0x045
378c0984e5SSebastian Reichel #define SMBB_CHG_VIN_MIN 0x047
388c0984e5SSebastian Reichel #define SMBB_CHG_CTRL 0x049
398c0984e5SSebastian Reichel #define CTRL_EN BIT(7)
408c0984e5SSebastian Reichel #define SMBB_CHG_VBAT_WEAK 0x052
418c0984e5SSebastian Reichel #define SMBB_CHG_IBAT_TERM_CHG 0x05b
428c0984e5SSebastian Reichel #define IBAT_TERM_CHG_IEOC BIT(7)
438c0984e5SSebastian Reichel #define IBAT_TERM_CHG_IEOC_BMS BIT(7)
448c0984e5SSebastian Reichel #define IBAT_TERM_CHG_IEOC_CHG 0
458c0984e5SSebastian Reichel #define SMBB_CHG_VBAT_DET 0x05d
468c0984e5SSebastian Reichel #define SMBB_CHG_TCHG_MAX_EN 0x060
478c0984e5SSebastian Reichel #define TCHG_MAX_EN BIT(7)
488c0984e5SSebastian Reichel #define SMBB_CHG_WDOG_TIME 0x062
498c0984e5SSebastian Reichel #define SMBB_CHG_WDOG_EN 0x065
508c0984e5SSebastian Reichel #define WDOG_EN BIT(7)
518c0984e5SSebastian Reichel
528c0984e5SSebastian Reichel #define SMBB_BUCK_REG_MODE 0x174
538c0984e5SSebastian Reichel #define BUCK_REG_MODE BIT(0)
548c0984e5SSebastian Reichel #define BUCK_REG_MODE_VBAT BIT(0)
558c0984e5SSebastian Reichel #define BUCK_REG_MODE_VSYS 0
568c0984e5SSebastian Reichel
578c0984e5SSebastian Reichel #define SMBB_BAT_PRES_STATUS 0x208
588c0984e5SSebastian Reichel #define PRES_STATUS_BAT_PRES BIT(7)
598c0984e5SSebastian Reichel #define SMBB_BAT_TEMP_STATUS 0x209
608c0984e5SSebastian Reichel #define TEMP_STATUS_OK BIT(7)
618c0984e5SSebastian Reichel #define TEMP_STATUS_HOT BIT(6)
628c0984e5SSebastian Reichel #define SMBB_BAT_BTC_CTRL 0x249
638c0984e5SSebastian Reichel #define BTC_CTRL_COMP_EN BIT(7)
648c0984e5SSebastian Reichel #define BTC_CTRL_COLD_EXT BIT(1)
658c0984e5SSebastian Reichel #define BTC_CTRL_HOT_EXT_N BIT(0)
668c0984e5SSebastian Reichel
678c0984e5SSebastian Reichel #define SMBB_USB_IMAX 0x344
6861274effSBird, Tim #define SMBB_USB_OTG_CTL 0x348
6961274effSBird, Tim #define OTG_CTL_EN BIT(0)
708c0984e5SSebastian Reichel #define SMBB_USB_ENUM_TIMER_STOP 0x34e
718c0984e5SSebastian Reichel #define ENUM_TIMER_STOP BIT(0)
728c0984e5SSebastian Reichel #define SMBB_USB_SEC_ACCESS 0x3d0
738c0984e5SSebastian Reichel #define SEC_ACCESS_MAGIC 0xa5
748c0984e5SSebastian Reichel #define SMBB_USB_REV_BST 0x3ed
758c0984e5SSebastian Reichel #define REV_BST_CHG_GONE BIT(7)
768c0984e5SSebastian Reichel
778c0984e5SSebastian Reichel #define SMBB_DC_IMAX 0x444
788c0984e5SSebastian Reichel
798c0984e5SSebastian Reichel #define SMBB_MISC_REV2 0x601
808c0984e5SSebastian Reichel #define SMBB_MISC_BOOT_DONE 0x642
818c0984e5SSebastian Reichel #define BOOT_DONE BIT(7)
828c0984e5SSebastian Reichel
838c0984e5SSebastian Reichel #define STATUS_USBIN_VALID BIT(0) /* USB connection is valid */
848c0984e5SSebastian Reichel #define STATUS_DCIN_VALID BIT(1) /* DC connection is valid */
858c0984e5SSebastian Reichel #define STATUS_BAT_HOT BIT(2) /* Battery temp 1=Hot, 0=Cold */
868c0984e5SSebastian Reichel #define STATUS_BAT_OK BIT(3) /* Battery temp OK */
878c0984e5SSebastian Reichel #define STATUS_BAT_PRESENT BIT(4) /* Battery is present */
888c0984e5SSebastian Reichel #define STATUS_CHG_DONE BIT(5) /* Charge cycle is complete */
898c0984e5SSebastian Reichel #define STATUS_CHG_TRKL BIT(6) /* Trickle charging */
908c0984e5SSebastian Reichel #define STATUS_CHG_FAST BIT(7) /* Fast charging */
918c0984e5SSebastian Reichel #define STATUS_CHG_GONE BIT(8) /* No charger is connected */
928c0984e5SSebastian Reichel
938c0984e5SSebastian Reichel enum smbb_attr {
948c0984e5SSebastian Reichel ATTR_BAT_ISAFE,
958c0984e5SSebastian Reichel ATTR_BAT_IMAX,
968c0984e5SSebastian Reichel ATTR_USBIN_IMAX,
978c0984e5SSebastian Reichel ATTR_DCIN_IMAX,
988c0984e5SSebastian Reichel ATTR_BAT_VSAFE,
998c0984e5SSebastian Reichel ATTR_BAT_VMAX,
1008c0984e5SSebastian Reichel ATTR_BAT_VMIN,
1018c0984e5SSebastian Reichel ATTR_CHG_VDET,
1028c0984e5SSebastian Reichel ATTR_VIN_MIN,
1038c0984e5SSebastian Reichel _ATTR_CNT,
1048c0984e5SSebastian Reichel };
1058c0984e5SSebastian Reichel
1068c0984e5SSebastian Reichel struct smbb_charger {
1078c0984e5SSebastian Reichel unsigned int revision;
1088c0984e5SSebastian Reichel unsigned int addr;
1098c0984e5SSebastian Reichel struct device *dev;
1108c0984e5SSebastian Reichel struct extcon_dev *edev;
1118c0984e5SSebastian Reichel
1128c0984e5SSebastian Reichel bool dc_disabled;
1138c0984e5SSebastian Reichel bool jeita_ext_temp;
1148c0984e5SSebastian Reichel unsigned long status;
1158c0984e5SSebastian Reichel struct mutex statlock;
1168c0984e5SSebastian Reichel
1178c0984e5SSebastian Reichel unsigned int attr[_ATTR_CNT];
1188c0984e5SSebastian Reichel
1198c0984e5SSebastian Reichel struct power_supply *usb_psy;
1208c0984e5SSebastian Reichel struct power_supply *dc_psy;
1218c0984e5SSebastian Reichel struct power_supply *bat_psy;
1228c0984e5SSebastian Reichel struct regmap *regmap;
12361274effSBird, Tim
12461274effSBird, Tim struct regulator_desc otg_rdesc;
12561274effSBird, Tim struct regulator_dev *otg_reg;
1268c0984e5SSebastian Reichel };
1278c0984e5SSebastian Reichel
1288c0984e5SSebastian Reichel static const unsigned int smbb_usb_extcon_cable[] = {
1298c0984e5SSebastian Reichel EXTCON_USB,
1308c0984e5SSebastian Reichel EXTCON_NONE,
1318c0984e5SSebastian Reichel };
1328c0984e5SSebastian Reichel
smbb_vbat_weak_fn(unsigned int index)1338c0984e5SSebastian Reichel static int smbb_vbat_weak_fn(unsigned int index)
1348c0984e5SSebastian Reichel {
1358c0984e5SSebastian Reichel return 2100000 + index * 100000;
1368c0984e5SSebastian Reichel }
1378c0984e5SSebastian Reichel
smbb_vin_fn(unsigned int index)1388c0984e5SSebastian Reichel static int smbb_vin_fn(unsigned int index)
1398c0984e5SSebastian Reichel {
1408c0984e5SSebastian Reichel if (index > 42)
1418c0984e5SSebastian Reichel return 5600000 + (index - 43) * 200000;
1428c0984e5SSebastian Reichel return 3400000 + index * 50000;
1438c0984e5SSebastian Reichel }
1448c0984e5SSebastian Reichel
smbb_vmax_fn(unsigned int index)1458c0984e5SSebastian Reichel static int smbb_vmax_fn(unsigned int index)
1468c0984e5SSebastian Reichel {
1478c0984e5SSebastian Reichel return 3240000 + index * 10000;
1488c0984e5SSebastian Reichel }
1498c0984e5SSebastian Reichel
smbb_vbat_det_fn(unsigned int index)1508c0984e5SSebastian Reichel static int smbb_vbat_det_fn(unsigned int index)
1518c0984e5SSebastian Reichel {
1528c0984e5SSebastian Reichel return 3240000 + index * 20000;
1538c0984e5SSebastian Reichel }
1548c0984e5SSebastian Reichel
smbb_imax_fn(unsigned int index)1558c0984e5SSebastian Reichel static int smbb_imax_fn(unsigned int index)
1568c0984e5SSebastian Reichel {
1578c0984e5SSebastian Reichel if (index < 2)
1588c0984e5SSebastian Reichel return 100000 + index * 50000;
1598c0984e5SSebastian Reichel return index * 100000;
1608c0984e5SSebastian Reichel }
1618c0984e5SSebastian Reichel
smbb_bat_imax_fn(unsigned int index)1628c0984e5SSebastian Reichel static int smbb_bat_imax_fn(unsigned int index)
1638c0984e5SSebastian Reichel {
1648c0984e5SSebastian Reichel return index * 50000;
1658c0984e5SSebastian Reichel }
1668c0984e5SSebastian Reichel
smbb_hw_lookup(unsigned int val,int (* fn)(unsigned int))1678c0984e5SSebastian Reichel static unsigned int smbb_hw_lookup(unsigned int val, int (*fn)(unsigned int))
1688c0984e5SSebastian Reichel {
1698c0984e5SSebastian Reichel unsigned int widx;
1708c0984e5SSebastian Reichel unsigned int sel;
1718c0984e5SSebastian Reichel
1728c0984e5SSebastian Reichel for (widx = sel = 0; (*fn)(widx) <= val; ++widx)
1738c0984e5SSebastian Reichel sel = widx;
1748c0984e5SSebastian Reichel
1758c0984e5SSebastian Reichel return sel;
1768c0984e5SSebastian Reichel }
1778c0984e5SSebastian Reichel
1788c0984e5SSebastian Reichel static const struct smbb_charger_attr {
1798c0984e5SSebastian Reichel const char *name;
1808c0984e5SSebastian Reichel unsigned int reg;
1818c0984e5SSebastian Reichel unsigned int safe_reg;
1828c0984e5SSebastian Reichel unsigned int max;
1838c0984e5SSebastian Reichel unsigned int min;
1848c0984e5SSebastian Reichel unsigned int fail_ok;
1858c0984e5SSebastian Reichel int (*hw_fn)(unsigned int);
1868c0984e5SSebastian Reichel } smbb_charger_attrs[] = {
1878c0984e5SSebastian Reichel [ATTR_BAT_ISAFE] = {
1888c0984e5SSebastian Reichel .name = "qcom,fast-charge-safe-current",
1898c0984e5SSebastian Reichel .reg = SMBB_CHG_ISAFE,
1908c0984e5SSebastian Reichel .max = 3000000,
1918c0984e5SSebastian Reichel .min = 200000,
1928c0984e5SSebastian Reichel .hw_fn = smbb_bat_imax_fn,
1938c0984e5SSebastian Reichel .fail_ok = 1,
1948c0984e5SSebastian Reichel },
1958c0984e5SSebastian Reichel [ATTR_BAT_IMAX] = {
1968c0984e5SSebastian Reichel .name = "qcom,fast-charge-current-limit",
1978c0984e5SSebastian Reichel .reg = SMBB_CHG_IMAX,
1988c0984e5SSebastian Reichel .safe_reg = SMBB_CHG_ISAFE,
1998c0984e5SSebastian Reichel .max = 3000000,
2008c0984e5SSebastian Reichel .min = 200000,
2018c0984e5SSebastian Reichel .hw_fn = smbb_bat_imax_fn,
2028c0984e5SSebastian Reichel },
2038c0984e5SSebastian Reichel [ATTR_DCIN_IMAX] = {
2048c0984e5SSebastian Reichel .name = "qcom,dc-current-limit",
2058c0984e5SSebastian Reichel .reg = SMBB_DC_IMAX,
2068c0984e5SSebastian Reichel .max = 2500000,
2078c0984e5SSebastian Reichel .min = 100000,
2088c0984e5SSebastian Reichel .hw_fn = smbb_imax_fn,
2098c0984e5SSebastian Reichel },
2108c0984e5SSebastian Reichel [ATTR_BAT_VSAFE] = {
2118c0984e5SSebastian Reichel .name = "qcom,fast-charge-safe-voltage",
2128c0984e5SSebastian Reichel .reg = SMBB_CHG_VSAFE,
2138c0984e5SSebastian Reichel .max = 5000000,
2148c0984e5SSebastian Reichel .min = 3240000,
2158c0984e5SSebastian Reichel .hw_fn = smbb_vmax_fn,
2168c0984e5SSebastian Reichel .fail_ok = 1,
2178c0984e5SSebastian Reichel },
2188c0984e5SSebastian Reichel [ATTR_BAT_VMAX] = {
2198c0984e5SSebastian Reichel .name = "qcom,fast-charge-high-threshold-voltage",
2208c0984e5SSebastian Reichel .reg = SMBB_CHG_VMAX,
2218c0984e5SSebastian Reichel .safe_reg = SMBB_CHG_VSAFE,
2228c0984e5SSebastian Reichel .max = 5000000,
2238c0984e5SSebastian Reichel .min = 3240000,
2248c0984e5SSebastian Reichel .hw_fn = smbb_vmax_fn,
2258c0984e5SSebastian Reichel },
2268c0984e5SSebastian Reichel [ATTR_BAT_VMIN] = {
2278c0984e5SSebastian Reichel .name = "qcom,fast-charge-low-threshold-voltage",
2288c0984e5SSebastian Reichel .reg = SMBB_CHG_VBAT_WEAK,
2298c0984e5SSebastian Reichel .max = 3600000,
2308c0984e5SSebastian Reichel .min = 2100000,
2318c0984e5SSebastian Reichel .hw_fn = smbb_vbat_weak_fn,
2328c0984e5SSebastian Reichel },
2338c0984e5SSebastian Reichel [ATTR_CHG_VDET] = {
2348c0984e5SSebastian Reichel .name = "qcom,auto-recharge-threshold-voltage",
2358c0984e5SSebastian Reichel .reg = SMBB_CHG_VBAT_DET,
2368c0984e5SSebastian Reichel .max = 5000000,
2378c0984e5SSebastian Reichel .min = 3240000,
2388c0984e5SSebastian Reichel .hw_fn = smbb_vbat_det_fn,
2398c0984e5SSebastian Reichel },
2408c0984e5SSebastian Reichel [ATTR_VIN_MIN] = {
2418c0984e5SSebastian Reichel .name = "qcom,minimum-input-voltage",
2428c0984e5SSebastian Reichel .reg = SMBB_CHG_VIN_MIN,
2438c0984e5SSebastian Reichel .max = 9600000,
2448c0984e5SSebastian Reichel .min = 4200000,
2458c0984e5SSebastian Reichel .hw_fn = smbb_vin_fn,
2468c0984e5SSebastian Reichel },
2478c0984e5SSebastian Reichel [ATTR_USBIN_IMAX] = {
2488c0984e5SSebastian Reichel .name = "usb-charge-current-limit",
2498c0984e5SSebastian Reichel .reg = SMBB_USB_IMAX,
2508c0984e5SSebastian Reichel .max = 2500000,
2518c0984e5SSebastian Reichel .min = 100000,
2528c0984e5SSebastian Reichel .hw_fn = smbb_imax_fn,
2538c0984e5SSebastian Reichel },
2548c0984e5SSebastian Reichel };
2558c0984e5SSebastian Reichel
smbb_charger_attr_write(struct smbb_charger * chg,enum smbb_attr which,unsigned int val)2568c0984e5SSebastian Reichel static int smbb_charger_attr_write(struct smbb_charger *chg,
2578c0984e5SSebastian Reichel enum smbb_attr which, unsigned int val)
2588c0984e5SSebastian Reichel {
2598c0984e5SSebastian Reichel const struct smbb_charger_attr *prop;
2608c0984e5SSebastian Reichel unsigned int wval;
2618c0984e5SSebastian Reichel unsigned int out;
2628c0984e5SSebastian Reichel int rc;
2638c0984e5SSebastian Reichel
2648c0984e5SSebastian Reichel prop = &smbb_charger_attrs[which];
2658c0984e5SSebastian Reichel
2668c0984e5SSebastian Reichel if (val > prop->max || val < prop->min) {
2678c0984e5SSebastian Reichel dev_err(chg->dev, "value out of range for %s [%u:%u]\n",
2688c0984e5SSebastian Reichel prop->name, prop->min, prop->max);
2698c0984e5SSebastian Reichel return -EINVAL;
2708c0984e5SSebastian Reichel }
2718c0984e5SSebastian Reichel
2728c0984e5SSebastian Reichel if (prop->safe_reg) {
2738c0984e5SSebastian Reichel rc = regmap_read(chg->regmap,
2748c0984e5SSebastian Reichel chg->addr + prop->safe_reg, &wval);
2758c0984e5SSebastian Reichel if (rc) {
2768c0984e5SSebastian Reichel dev_err(chg->dev,
2778c0984e5SSebastian Reichel "unable to read safe value for '%s'\n",
2788c0984e5SSebastian Reichel prop->name);
2798c0984e5SSebastian Reichel return rc;
2808c0984e5SSebastian Reichel }
2818c0984e5SSebastian Reichel
2828c0984e5SSebastian Reichel wval = prop->hw_fn(wval);
2838c0984e5SSebastian Reichel
2848c0984e5SSebastian Reichel if (val > wval) {
2858c0984e5SSebastian Reichel dev_warn(chg->dev,
2868c0984e5SSebastian Reichel "%s above safe value, clamping at %u\n",
2878c0984e5SSebastian Reichel prop->name, wval);
2888c0984e5SSebastian Reichel val = wval;
2898c0984e5SSebastian Reichel }
2908c0984e5SSebastian Reichel }
2918c0984e5SSebastian Reichel
2928c0984e5SSebastian Reichel wval = smbb_hw_lookup(val, prop->hw_fn);
2938c0984e5SSebastian Reichel
2948c0984e5SSebastian Reichel rc = regmap_write(chg->regmap, chg->addr + prop->reg, wval);
2958c0984e5SSebastian Reichel if (rc) {
2968c0984e5SSebastian Reichel dev_err(chg->dev, "unable to update %s", prop->name);
2978c0984e5SSebastian Reichel return rc;
2988c0984e5SSebastian Reichel }
2998c0984e5SSebastian Reichel out = prop->hw_fn(wval);
3008c0984e5SSebastian Reichel if (out != val) {
3018c0984e5SSebastian Reichel dev_warn(chg->dev,
3028c0984e5SSebastian Reichel "%s inaccurate, rounded to %u\n",
3038c0984e5SSebastian Reichel prop->name, out);
3048c0984e5SSebastian Reichel }
3058c0984e5SSebastian Reichel
3068c0984e5SSebastian Reichel dev_dbg(chg->dev, "%s <= %d\n", prop->name, out);
3078c0984e5SSebastian Reichel
3088c0984e5SSebastian Reichel chg->attr[which] = out;
3098c0984e5SSebastian Reichel
3108c0984e5SSebastian Reichel return 0;
3118c0984e5SSebastian Reichel }
3128c0984e5SSebastian Reichel
smbb_charger_attr_read(struct smbb_charger * chg,enum smbb_attr which)3138c0984e5SSebastian Reichel static int smbb_charger_attr_read(struct smbb_charger *chg,
3148c0984e5SSebastian Reichel enum smbb_attr which)
3158c0984e5SSebastian Reichel {
3168c0984e5SSebastian Reichel const struct smbb_charger_attr *prop;
3178c0984e5SSebastian Reichel unsigned int val;
3188c0984e5SSebastian Reichel int rc;
3198c0984e5SSebastian Reichel
3208c0984e5SSebastian Reichel prop = &smbb_charger_attrs[which];
3218c0984e5SSebastian Reichel
3228c0984e5SSebastian Reichel rc = regmap_read(chg->regmap, chg->addr + prop->reg, &val);
3238c0984e5SSebastian Reichel if (rc) {
3248c0984e5SSebastian Reichel dev_err(chg->dev, "failed to read %s\n", prop->name);
3258c0984e5SSebastian Reichel return rc;
3268c0984e5SSebastian Reichel }
3278c0984e5SSebastian Reichel val = prop->hw_fn(val);
3288c0984e5SSebastian Reichel dev_dbg(chg->dev, "%s => %d\n", prop->name, val);
3298c0984e5SSebastian Reichel
3308c0984e5SSebastian Reichel chg->attr[which] = val;
3318c0984e5SSebastian Reichel
3328c0984e5SSebastian Reichel return 0;
3338c0984e5SSebastian Reichel }
3348c0984e5SSebastian Reichel
smbb_charger_attr_parse(struct smbb_charger * chg,enum smbb_attr which)3358c0984e5SSebastian Reichel static int smbb_charger_attr_parse(struct smbb_charger *chg,
3368c0984e5SSebastian Reichel enum smbb_attr which)
3378c0984e5SSebastian Reichel {
3388c0984e5SSebastian Reichel const struct smbb_charger_attr *prop;
3398c0984e5SSebastian Reichel unsigned int val;
3408c0984e5SSebastian Reichel int rc;
3418c0984e5SSebastian Reichel
3428c0984e5SSebastian Reichel prop = &smbb_charger_attrs[which];
3438c0984e5SSebastian Reichel
3448c0984e5SSebastian Reichel rc = of_property_read_u32(chg->dev->of_node, prop->name, &val);
3458c0984e5SSebastian Reichel if (rc == 0) {
3468c0984e5SSebastian Reichel rc = smbb_charger_attr_write(chg, which, val);
3478c0984e5SSebastian Reichel if (!rc || !prop->fail_ok)
3488c0984e5SSebastian Reichel return rc;
3498c0984e5SSebastian Reichel }
3508c0984e5SSebastian Reichel return smbb_charger_attr_read(chg, which);
3518c0984e5SSebastian Reichel }
3528c0984e5SSebastian Reichel
smbb_set_line_flag(struct smbb_charger * chg,int irq,int flag)3538c0984e5SSebastian Reichel static void smbb_set_line_flag(struct smbb_charger *chg, int irq, int flag)
3548c0984e5SSebastian Reichel {
3558c0984e5SSebastian Reichel bool state;
3568c0984e5SSebastian Reichel int ret;
3578c0984e5SSebastian Reichel
3588c0984e5SSebastian Reichel ret = irq_get_irqchip_state(irq, IRQCHIP_STATE_LINE_LEVEL, &state);
3598c0984e5SSebastian Reichel if (ret < 0) {
3608c0984e5SSebastian Reichel dev_err(chg->dev, "failed to read irq line\n");
3618c0984e5SSebastian Reichel return;
3628c0984e5SSebastian Reichel }
3638c0984e5SSebastian Reichel
3648c0984e5SSebastian Reichel mutex_lock(&chg->statlock);
3658c0984e5SSebastian Reichel if (state)
3668c0984e5SSebastian Reichel chg->status |= flag;
3678c0984e5SSebastian Reichel else
3688c0984e5SSebastian Reichel chg->status &= ~flag;
3698c0984e5SSebastian Reichel mutex_unlock(&chg->statlock);
3708c0984e5SSebastian Reichel
3718c0984e5SSebastian Reichel dev_dbg(chg->dev, "status = %03lx\n", chg->status);
3728c0984e5SSebastian Reichel }
3738c0984e5SSebastian Reichel
smbb_usb_valid_handler(int irq,void * _data)3748c0984e5SSebastian Reichel static irqreturn_t smbb_usb_valid_handler(int irq, void *_data)
3758c0984e5SSebastian Reichel {
3768c0984e5SSebastian Reichel struct smbb_charger *chg = _data;
3778c0984e5SSebastian Reichel
3788c0984e5SSebastian Reichel smbb_set_line_flag(chg, irq, STATUS_USBIN_VALID);
379bdca5d9eSChanwoo Choi extcon_set_state_sync(chg->edev, EXTCON_USB,
3808c0984e5SSebastian Reichel chg->status & STATUS_USBIN_VALID);
3818c0984e5SSebastian Reichel power_supply_changed(chg->usb_psy);
3828c0984e5SSebastian Reichel
3838c0984e5SSebastian Reichel return IRQ_HANDLED;
3848c0984e5SSebastian Reichel }
3858c0984e5SSebastian Reichel
smbb_dc_valid_handler(int irq,void * _data)3868c0984e5SSebastian Reichel static irqreturn_t smbb_dc_valid_handler(int irq, void *_data)
3878c0984e5SSebastian Reichel {
3888c0984e5SSebastian Reichel struct smbb_charger *chg = _data;
3898c0984e5SSebastian Reichel
3908c0984e5SSebastian Reichel smbb_set_line_flag(chg, irq, STATUS_DCIN_VALID);
3918c0984e5SSebastian Reichel if (!chg->dc_disabled)
3928c0984e5SSebastian Reichel power_supply_changed(chg->dc_psy);
3938c0984e5SSebastian Reichel
3948c0984e5SSebastian Reichel return IRQ_HANDLED;
3958c0984e5SSebastian Reichel }
3968c0984e5SSebastian Reichel
smbb_bat_temp_handler(int irq,void * _data)3978c0984e5SSebastian Reichel static irqreturn_t smbb_bat_temp_handler(int irq, void *_data)
3988c0984e5SSebastian Reichel {
3998c0984e5SSebastian Reichel struct smbb_charger *chg = _data;
4008c0984e5SSebastian Reichel unsigned int val;
4018c0984e5SSebastian Reichel int rc;
4028c0984e5SSebastian Reichel
4038c0984e5SSebastian Reichel rc = regmap_read(chg->regmap, chg->addr + SMBB_BAT_TEMP_STATUS, &val);
4048c0984e5SSebastian Reichel if (rc)
4058c0984e5SSebastian Reichel return IRQ_HANDLED;
4068c0984e5SSebastian Reichel
4078c0984e5SSebastian Reichel mutex_lock(&chg->statlock);
4088c0984e5SSebastian Reichel if (val & TEMP_STATUS_OK) {
4098c0984e5SSebastian Reichel chg->status |= STATUS_BAT_OK;
4108c0984e5SSebastian Reichel } else {
4118c0984e5SSebastian Reichel chg->status &= ~STATUS_BAT_OK;
4128c0984e5SSebastian Reichel if (val & TEMP_STATUS_HOT)
4138c0984e5SSebastian Reichel chg->status |= STATUS_BAT_HOT;
4148c0984e5SSebastian Reichel }
4158c0984e5SSebastian Reichel mutex_unlock(&chg->statlock);
4168c0984e5SSebastian Reichel
4178c0984e5SSebastian Reichel power_supply_changed(chg->bat_psy);
4188c0984e5SSebastian Reichel return IRQ_HANDLED;
4198c0984e5SSebastian Reichel }
4208c0984e5SSebastian Reichel
smbb_bat_present_handler(int irq,void * _data)4218c0984e5SSebastian Reichel static irqreturn_t smbb_bat_present_handler(int irq, void *_data)
4228c0984e5SSebastian Reichel {
4238c0984e5SSebastian Reichel struct smbb_charger *chg = _data;
4248c0984e5SSebastian Reichel
4258c0984e5SSebastian Reichel smbb_set_line_flag(chg, irq, STATUS_BAT_PRESENT);
4268c0984e5SSebastian Reichel power_supply_changed(chg->bat_psy);
4278c0984e5SSebastian Reichel
4288c0984e5SSebastian Reichel return IRQ_HANDLED;
4298c0984e5SSebastian Reichel }
4308c0984e5SSebastian Reichel
smbb_chg_done_handler(int irq,void * _data)4318c0984e5SSebastian Reichel static irqreturn_t smbb_chg_done_handler(int irq, void *_data)
4328c0984e5SSebastian Reichel {
4338c0984e5SSebastian Reichel struct smbb_charger *chg = _data;
4348c0984e5SSebastian Reichel
4358c0984e5SSebastian Reichel smbb_set_line_flag(chg, irq, STATUS_CHG_DONE);
4368c0984e5SSebastian Reichel power_supply_changed(chg->bat_psy);
4378c0984e5SSebastian Reichel
4388c0984e5SSebastian Reichel return IRQ_HANDLED;
4398c0984e5SSebastian Reichel }
4408c0984e5SSebastian Reichel
smbb_chg_gone_handler(int irq,void * _data)4418c0984e5SSebastian Reichel static irqreturn_t smbb_chg_gone_handler(int irq, void *_data)
4428c0984e5SSebastian Reichel {
4438c0984e5SSebastian Reichel struct smbb_charger *chg = _data;
4448c0984e5SSebastian Reichel
4458c0984e5SSebastian Reichel smbb_set_line_flag(chg, irq, STATUS_CHG_GONE);
4468c0984e5SSebastian Reichel power_supply_changed(chg->bat_psy);
4478c0984e5SSebastian Reichel power_supply_changed(chg->usb_psy);
4488c0984e5SSebastian Reichel if (!chg->dc_disabled)
4498c0984e5SSebastian Reichel power_supply_changed(chg->dc_psy);
4508c0984e5SSebastian Reichel
4518c0984e5SSebastian Reichel return IRQ_HANDLED;
4528c0984e5SSebastian Reichel }
4538c0984e5SSebastian Reichel
smbb_chg_fast_handler(int irq,void * _data)4548c0984e5SSebastian Reichel static irqreturn_t smbb_chg_fast_handler(int irq, void *_data)
4558c0984e5SSebastian Reichel {
4568c0984e5SSebastian Reichel struct smbb_charger *chg = _data;
4578c0984e5SSebastian Reichel
4588c0984e5SSebastian Reichel smbb_set_line_flag(chg, irq, STATUS_CHG_FAST);
4598c0984e5SSebastian Reichel power_supply_changed(chg->bat_psy);
4608c0984e5SSebastian Reichel
4618c0984e5SSebastian Reichel return IRQ_HANDLED;
4628c0984e5SSebastian Reichel }
4638c0984e5SSebastian Reichel
smbb_chg_trkl_handler(int irq,void * _data)4648c0984e5SSebastian Reichel static irqreturn_t smbb_chg_trkl_handler(int irq, void *_data)
4658c0984e5SSebastian Reichel {
4668c0984e5SSebastian Reichel struct smbb_charger *chg = _data;
4678c0984e5SSebastian Reichel
4688c0984e5SSebastian Reichel smbb_set_line_flag(chg, irq, STATUS_CHG_TRKL);
4698c0984e5SSebastian Reichel power_supply_changed(chg->bat_psy);
4708c0984e5SSebastian Reichel
4718c0984e5SSebastian Reichel return IRQ_HANDLED;
4728c0984e5SSebastian Reichel }
4738c0984e5SSebastian Reichel
4748c0984e5SSebastian Reichel static const struct smbb_irq {
4758c0984e5SSebastian Reichel const char *name;
4768c0984e5SSebastian Reichel irqreturn_t (*handler)(int, void *);
4778c0984e5SSebastian Reichel } smbb_charger_irqs[] = {
4788c0984e5SSebastian Reichel { "chg-done", smbb_chg_done_handler },
4798c0984e5SSebastian Reichel { "chg-fast", smbb_chg_fast_handler },
4808c0984e5SSebastian Reichel { "chg-trkl", smbb_chg_trkl_handler },
4818c0984e5SSebastian Reichel { "bat-temp-ok", smbb_bat_temp_handler },
4828c0984e5SSebastian Reichel { "bat-present", smbb_bat_present_handler },
4838c0984e5SSebastian Reichel { "chg-gone", smbb_chg_gone_handler },
4848c0984e5SSebastian Reichel { "usb-valid", smbb_usb_valid_handler },
4858c0984e5SSebastian Reichel { "dc-valid", smbb_dc_valid_handler },
4868c0984e5SSebastian Reichel };
4878c0984e5SSebastian Reichel
smbb_usbin_get_property(struct power_supply * psy,enum power_supply_property psp,union power_supply_propval * val)4888c0984e5SSebastian Reichel static int smbb_usbin_get_property(struct power_supply *psy,
4898c0984e5SSebastian Reichel enum power_supply_property psp,
4908c0984e5SSebastian Reichel union power_supply_propval *val)
4918c0984e5SSebastian Reichel {
4928c0984e5SSebastian Reichel struct smbb_charger *chg = power_supply_get_drvdata(psy);
4938c0984e5SSebastian Reichel int rc = 0;
4948c0984e5SSebastian Reichel
4958c0984e5SSebastian Reichel switch (psp) {
4968c0984e5SSebastian Reichel case POWER_SUPPLY_PROP_ONLINE:
4978c0984e5SSebastian Reichel mutex_lock(&chg->statlock);
4988c0984e5SSebastian Reichel val->intval = !(chg->status & STATUS_CHG_GONE) &&
4998c0984e5SSebastian Reichel (chg->status & STATUS_USBIN_VALID);
5008c0984e5SSebastian Reichel mutex_unlock(&chg->statlock);
5018c0984e5SSebastian Reichel break;
5028c0984e5SSebastian Reichel case POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT:
5038c0984e5SSebastian Reichel val->intval = chg->attr[ATTR_USBIN_IMAX];
5048c0984e5SSebastian Reichel break;
5058c0984e5SSebastian Reichel case POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT_MAX:
5068c0984e5SSebastian Reichel val->intval = 2500000;
5078c0984e5SSebastian Reichel break;
5088c0984e5SSebastian Reichel default:
5098c0984e5SSebastian Reichel rc = -EINVAL;
5108c0984e5SSebastian Reichel break;
5118c0984e5SSebastian Reichel }
5128c0984e5SSebastian Reichel
5138c0984e5SSebastian Reichel return rc;
5148c0984e5SSebastian Reichel }
5158c0984e5SSebastian Reichel
smbb_usbin_set_property(struct power_supply * psy,enum power_supply_property psp,const union power_supply_propval * val)5168c0984e5SSebastian Reichel static int smbb_usbin_set_property(struct power_supply *psy,
5178c0984e5SSebastian Reichel enum power_supply_property psp,
5188c0984e5SSebastian Reichel const union power_supply_propval *val)
5198c0984e5SSebastian Reichel {
5208c0984e5SSebastian Reichel struct smbb_charger *chg = power_supply_get_drvdata(psy);
5218c0984e5SSebastian Reichel int rc;
5228c0984e5SSebastian Reichel
5238c0984e5SSebastian Reichel switch (psp) {
5248c0984e5SSebastian Reichel case POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT:
5258c0984e5SSebastian Reichel rc = smbb_charger_attr_write(chg, ATTR_USBIN_IMAX,
5268c0984e5SSebastian Reichel val->intval);
5278c0984e5SSebastian Reichel break;
5288c0984e5SSebastian Reichel default:
5298c0984e5SSebastian Reichel rc = -EINVAL;
5308c0984e5SSebastian Reichel break;
5318c0984e5SSebastian Reichel }
5328c0984e5SSebastian Reichel
5338c0984e5SSebastian Reichel return rc;
5348c0984e5SSebastian Reichel }
5358c0984e5SSebastian Reichel
smbb_dcin_get_property(struct power_supply * psy,enum power_supply_property psp,union power_supply_propval * val)5368c0984e5SSebastian Reichel static int smbb_dcin_get_property(struct power_supply *psy,
5378c0984e5SSebastian Reichel enum power_supply_property psp,
5388c0984e5SSebastian Reichel union power_supply_propval *val)
5398c0984e5SSebastian Reichel {
5408c0984e5SSebastian Reichel struct smbb_charger *chg = power_supply_get_drvdata(psy);
5418c0984e5SSebastian Reichel int rc = 0;
5428c0984e5SSebastian Reichel
5438c0984e5SSebastian Reichel switch (psp) {
5448c0984e5SSebastian Reichel case POWER_SUPPLY_PROP_ONLINE:
5458c0984e5SSebastian Reichel mutex_lock(&chg->statlock);
5468c0984e5SSebastian Reichel val->intval = !(chg->status & STATUS_CHG_GONE) &&
5478c0984e5SSebastian Reichel (chg->status & STATUS_DCIN_VALID);
5488c0984e5SSebastian Reichel mutex_unlock(&chg->statlock);
5498c0984e5SSebastian Reichel break;
5508c0984e5SSebastian Reichel case POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT:
5518c0984e5SSebastian Reichel val->intval = chg->attr[ATTR_DCIN_IMAX];
5528c0984e5SSebastian Reichel break;
5538c0984e5SSebastian Reichel case POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT_MAX:
5548c0984e5SSebastian Reichel val->intval = 2500000;
5558c0984e5SSebastian Reichel break;
5568c0984e5SSebastian Reichel default:
5578c0984e5SSebastian Reichel rc = -EINVAL;
5588c0984e5SSebastian Reichel break;
5598c0984e5SSebastian Reichel }
5608c0984e5SSebastian Reichel
5618c0984e5SSebastian Reichel return rc;
5628c0984e5SSebastian Reichel }
5638c0984e5SSebastian Reichel
smbb_dcin_set_property(struct power_supply * psy,enum power_supply_property psp,const union power_supply_propval * val)5648c0984e5SSebastian Reichel static int smbb_dcin_set_property(struct power_supply *psy,
5658c0984e5SSebastian Reichel enum power_supply_property psp,
5668c0984e5SSebastian Reichel const union power_supply_propval *val)
5678c0984e5SSebastian Reichel {
5688c0984e5SSebastian Reichel struct smbb_charger *chg = power_supply_get_drvdata(psy);
5698c0984e5SSebastian Reichel int rc;
5708c0984e5SSebastian Reichel
5718c0984e5SSebastian Reichel switch (psp) {
5728c0984e5SSebastian Reichel case POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT:
5738c0984e5SSebastian Reichel rc = smbb_charger_attr_write(chg, ATTR_DCIN_IMAX,
5748c0984e5SSebastian Reichel val->intval);
5758c0984e5SSebastian Reichel break;
5768c0984e5SSebastian Reichel default:
5778c0984e5SSebastian Reichel rc = -EINVAL;
5788c0984e5SSebastian Reichel break;
5798c0984e5SSebastian Reichel }
5808c0984e5SSebastian Reichel
5818c0984e5SSebastian Reichel return rc;
5828c0984e5SSebastian Reichel }
5838c0984e5SSebastian Reichel
smbb_charger_writable_property(struct power_supply * psy,enum power_supply_property psp)5848c0984e5SSebastian Reichel static int smbb_charger_writable_property(struct power_supply *psy,
5858c0984e5SSebastian Reichel enum power_supply_property psp)
5868c0984e5SSebastian Reichel {
5878c0984e5SSebastian Reichel return psp == POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT;
5888c0984e5SSebastian Reichel }
5898c0984e5SSebastian Reichel
smbb_battery_get_property(struct power_supply * psy,enum power_supply_property psp,union power_supply_propval * val)5908c0984e5SSebastian Reichel static int smbb_battery_get_property(struct power_supply *psy,
5918c0984e5SSebastian Reichel enum power_supply_property psp,
5928c0984e5SSebastian Reichel union power_supply_propval *val)
5938c0984e5SSebastian Reichel {
5948c0984e5SSebastian Reichel struct smbb_charger *chg = power_supply_get_drvdata(psy);
5958c0984e5SSebastian Reichel unsigned long status;
5968c0984e5SSebastian Reichel int rc = 0;
5978c0984e5SSebastian Reichel
5988c0984e5SSebastian Reichel mutex_lock(&chg->statlock);
5998c0984e5SSebastian Reichel status = chg->status;
6008c0984e5SSebastian Reichel mutex_unlock(&chg->statlock);
6018c0984e5SSebastian Reichel
6028c0984e5SSebastian Reichel switch (psp) {
6038c0984e5SSebastian Reichel case POWER_SUPPLY_PROP_STATUS:
6048c0984e5SSebastian Reichel if (status & STATUS_CHG_GONE)
6058c0984e5SSebastian Reichel val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
6068c0984e5SSebastian Reichel else if (!(status & (STATUS_DCIN_VALID | STATUS_USBIN_VALID)))
6078c0984e5SSebastian Reichel val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
6088c0984e5SSebastian Reichel else if (status & STATUS_CHG_DONE)
6098c0984e5SSebastian Reichel val->intval = POWER_SUPPLY_STATUS_FULL;
6108c0984e5SSebastian Reichel else if (!(status & STATUS_BAT_OK))
6118c0984e5SSebastian Reichel val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
6128c0984e5SSebastian Reichel else if (status & (STATUS_CHG_FAST | STATUS_CHG_TRKL))
6138c0984e5SSebastian Reichel val->intval = POWER_SUPPLY_STATUS_CHARGING;
6148c0984e5SSebastian Reichel else /* everything is ok for charging, but we are not... */
6158c0984e5SSebastian Reichel val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
6168c0984e5SSebastian Reichel break;
6178c0984e5SSebastian Reichel case POWER_SUPPLY_PROP_HEALTH:
6188c0984e5SSebastian Reichel if (status & STATUS_BAT_OK)
6198c0984e5SSebastian Reichel val->intval = POWER_SUPPLY_HEALTH_GOOD;
6208c0984e5SSebastian Reichel else if (status & STATUS_BAT_HOT)
6218c0984e5SSebastian Reichel val->intval = POWER_SUPPLY_HEALTH_OVERHEAT;
6228c0984e5SSebastian Reichel else
6238c0984e5SSebastian Reichel val->intval = POWER_SUPPLY_HEALTH_COLD;
6248c0984e5SSebastian Reichel break;
6258c0984e5SSebastian Reichel case POWER_SUPPLY_PROP_CHARGE_TYPE:
6268c0984e5SSebastian Reichel if (status & STATUS_CHG_FAST)
6278c0984e5SSebastian Reichel val->intval = POWER_SUPPLY_CHARGE_TYPE_FAST;
6288c0984e5SSebastian Reichel else if (status & STATUS_CHG_TRKL)
6298c0984e5SSebastian Reichel val->intval = POWER_SUPPLY_CHARGE_TYPE_TRICKLE;
6308c0984e5SSebastian Reichel else
6318c0984e5SSebastian Reichel val->intval = POWER_SUPPLY_CHARGE_TYPE_NONE;
6328c0984e5SSebastian Reichel break;
6338c0984e5SSebastian Reichel case POWER_SUPPLY_PROP_PRESENT:
6348c0984e5SSebastian Reichel val->intval = !!(status & STATUS_BAT_PRESENT);
6358c0984e5SSebastian Reichel break;
6368c0984e5SSebastian Reichel case POWER_SUPPLY_PROP_CURRENT_MAX:
6378c0984e5SSebastian Reichel val->intval = chg->attr[ATTR_BAT_IMAX];
6388c0984e5SSebastian Reichel break;
6398c0984e5SSebastian Reichel case POWER_SUPPLY_PROP_VOLTAGE_MAX:
6408c0984e5SSebastian Reichel val->intval = chg->attr[ATTR_BAT_VMAX];
6418c0984e5SSebastian Reichel break;
6428c0984e5SSebastian Reichel case POWER_SUPPLY_PROP_TECHNOLOGY:
6438c0984e5SSebastian Reichel /* this charger is a single-cell lithium-ion battery charger
6448c0984e5SSebastian Reichel * only. If you hook up some other technology, there will be
6458c0984e5SSebastian Reichel * fireworks.
6468c0984e5SSebastian Reichel */
6478c0984e5SSebastian Reichel val->intval = POWER_SUPPLY_TECHNOLOGY_LION;
6488c0984e5SSebastian Reichel break;
6498c0984e5SSebastian Reichel case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN:
6508c0984e5SSebastian Reichel val->intval = 3000000; /* single-cell li-ion low end */
6518c0984e5SSebastian Reichel break;
6528c0984e5SSebastian Reichel default:
6538c0984e5SSebastian Reichel rc = -EINVAL;
6548c0984e5SSebastian Reichel break;
6558c0984e5SSebastian Reichel }
6568c0984e5SSebastian Reichel
6578c0984e5SSebastian Reichel return rc;
6588c0984e5SSebastian Reichel }
6598c0984e5SSebastian Reichel
smbb_battery_set_property(struct power_supply * psy,enum power_supply_property psp,const union power_supply_propval * val)6608c0984e5SSebastian Reichel static int smbb_battery_set_property(struct power_supply *psy,
6618c0984e5SSebastian Reichel enum power_supply_property psp,
6628c0984e5SSebastian Reichel const union power_supply_propval *val)
6638c0984e5SSebastian Reichel {
6648c0984e5SSebastian Reichel struct smbb_charger *chg = power_supply_get_drvdata(psy);
6658c0984e5SSebastian Reichel int rc;
6668c0984e5SSebastian Reichel
6678c0984e5SSebastian Reichel switch (psp) {
6688c0984e5SSebastian Reichel case POWER_SUPPLY_PROP_CURRENT_MAX:
6698c0984e5SSebastian Reichel rc = smbb_charger_attr_write(chg, ATTR_BAT_IMAX, val->intval);
6708c0984e5SSebastian Reichel break;
6718c0984e5SSebastian Reichel case POWER_SUPPLY_PROP_VOLTAGE_MAX:
6728c0984e5SSebastian Reichel rc = smbb_charger_attr_write(chg, ATTR_BAT_VMAX, val->intval);
6738c0984e5SSebastian Reichel break;
6748c0984e5SSebastian Reichel default:
6758c0984e5SSebastian Reichel rc = -EINVAL;
6768c0984e5SSebastian Reichel break;
6778c0984e5SSebastian Reichel }
6788c0984e5SSebastian Reichel
6798c0984e5SSebastian Reichel return rc;
6808c0984e5SSebastian Reichel }
6818c0984e5SSebastian Reichel
smbb_battery_writable_property(struct power_supply * psy,enum power_supply_property psp)6828c0984e5SSebastian Reichel static int smbb_battery_writable_property(struct power_supply *psy,
6838c0984e5SSebastian Reichel enum power_supply_property psp)
6848c0984e5SSebastian Reichel {
6858c0984e5SSebastian Reichel switch (psp) {
6868c0984e5SSebastian Reichel case POWER_SUPPLY_PROP_CURRENT_MAX:
6878c0984e5SSebastian Reichel case POWER_SUPPLY_PROP_VOLTAGE_MAX:
6888c0984e5SSebastian Reichel return 1;
6898c0984e5SSebastian Reichel default:
6908c0984e5SSebastian Reichel return 0;
6918c0984e5SSebastian Reichel }
6928c0984e5SSebastian Reichel }
6938c0984e5SSebastian Reichel
6948c0984e5SSebastian Reichel static enum power_supply_property smbb_charger_properties[] = {
6958c0984e5SSebastian Reichel POWER_SUPPLY_PROP_ONLINE,
6968c0984e5SSebastian Reichel POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT,
6978c0984e5SSebastian Reichel POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT_MAX,
6988c0984e5SSebastian Reichel };
6998c0984e5SSebastian Reichel
7008c0984e5SSebastian Reichel static enum power_supply_property smbb_battery_properties[] = {
7018c0984e5SSebastian Reichel POWER_SUPPLY_PROP_STATUS,
7028c0984e5SSebastian Reichel POWER_SUPPLY_PROP_HEALTH,
7038c0984e5SSebastian Reichel POWER_SUPPLY_PROP_PRESENT,
7048c0984e5SSebastian Reichel POWER_SUPPLY_PROP_CHARGE_TYPE,
7058c0984e5SSebastian Reichel POWER_SUPPLY_PROP_CURRENT_MAX,
7068c0984e5SSebastian Reichel POWER_SUPPLY_PROP_VOLTAGE_MAX,
7078c0984e5SSebastian Reichel POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN,
7088c0984e5SSebastian Reichel POWER_SUPPLY_PROP_TECHNOLOGY,
7098c0984e5SSebastian Reichel };
7108c0984e5SSebastian Reichel
7118c0984e5SSebastian Reichel static const struct reg_off_mask_default {
7128c0984e5SSebastian Reichel unsigned int offset;
7138c0984e5SSebastian Reichel unsigned int mask;
7148c0984e5SSebastian Reichel unsigned int value;
7158c0984e5SSebastian Reichel unsigned int rev_mask;
7168c0984e5SSebastian Reichel } smbb_charger_setup[] = {
7178c0984e5SSebastian Reichel /* The bootloader is supposed to set this... make sure anyway. */
7188c0984e5SSebastian Reichel { SMBB_MISC_BOOT_DONE, BOOT_DONE, BOOT_DONE },
7198c0984e5SSebastian Reichel
7208c0984e5SSebastian Reichel /* Disable software timer */
7218c0984e5SSebastian Reichel { SMBB_CHG_TCHG_MAX_EN, TCHG_MAX_EN, 0 },
7228c0984e5SSebastian Reichel
7238c0984e5SSebastian Reichel /* Clear and disable watchdog */
7248c0984e5SSebastian Reichel { SMBB_CHG_WDOG_TIME, 0xff, 160 },
7258c0984e5SSebastian Reichel { SMBB_CHG_WDOG_EN, WDOG_EN, 0 },
7268c0984e5SSebastian Reichel
7278c0984e5SSebastian Reichel /* Use charger based EoC detection */
7288c0984e5SSebastian Reichel { SMBB_CHG_IBAT_TERM_CHG, IBAT_TERM_CHG_IEOC, IBAT_TERM_CHG_IEOC_CHG },
7298c0984e5SSebastian Reichel
7308c0984e5SSebastian Reichel /* Disable GSM PA load adjustment.
7318c0984e5SSebastian Reichel * The PA signal is incorrectly connected on v2.
7328c0984e5SSebastian Reichel */
7338c0984e5SSebastian Reichel { SMBB_CHG_CFG, 0xff, 0x00, BIT(3) },
7348c0984e5SSebastian Reichel
7358c0984e5SSebastian Reichel /* Use VBAT (not VSYS) to compensate for IR drop during fast charging */
7368c0984e5SSebastian Reichel { SMBB_BUCK_REG_MODE, BUCK_REG_MODE, BUCK_REG_MODE_VBAT },
7378c0984e5SSebastian Reichel
7388c0984e5SSebastian Reichel /* Enable battery temperature comparators */
7398c0984e5SSebastian Reichel { SMBB_BAT_BTC_CTRL, BTC_CTRL_COMP_EN, BTC_CTRL_COMP_EN },
7408c0984e5SSebastian Reichel
7418c0984e5SSebastian Reichel /* Stop USB enumeration timer */
7428c0984e5SSebastian Reichel { SMBB_USB_ENUM_TIMER_STOP, ENUM_TIMER_STOP, ENUM_TIMER_STOP },
7438c0984e5SSebastian Reichel
7448c0984e5SSebastian Reichel #if 0 /* FIXME supposedly only to disable hardware ARB termination */
7458c0984e5SSebastian Reichel { SMBB_USB_SEC_ACCESS, SEC_ACCESS_MAGIC },
7468c0984e5SSebastian Reichel { SMBB_USB_REV_BST, 0xff, REV_BST_CHG_GONE },
7478c0984e5SSebastian Reichel #endif
7488c0984e5SSebastian Reichel
7498c0984e5SSebastian Reichel /* Stop USB enumeration timer, again */
7508c0984e5SSebastian Reichel { SMBB_USB_ENUM_TIMER_STOP, ENUM_TIMER_STOP, ENUM_TIMER_STOP },
7518c0984e5SSebastian Reichel
7528c0984e5SSebastian Reichel /* Enable charging */
7538c0984e5SSebastian Reichel { SMBB_CHG_CTRL, CTRL_EN, CTRL_EN },
7548c0984e5SSebastian Reichel };
7558c0984e5SSebastian Reichel
7568c0984e5SSebastian Reichel static char *smbb_bif[] = { "smbb-bif" };
7578c0984e5SSebastian Reichel
7588c0984e5SSebastian Reichel static const struct power_supply_desc bat_psy_desc = {
7598c0984e5SSebastian Reichel .name = "smbb-bif",
7608c0984e5SSebastian Reichel .type = POWER_SUPPLY_TYPE_BATTERY,
7618c0984e5SSebastian Reichel .properties = smbb_battery_properties,
7628c0984e5SSebastian Reichel .num_properties = ARRAY_SIZE(smbb_battery_properties),
7638c0984e5SSebastian Reichel .get_property = smbb_battery_get_property,
7648c0984e5SSebastian Reichel .set_property = smbb_battery_set_property,
7658c0984e5SSebastian Reichel .property_is_writeable = smbb_battery_writable_property,
7668c0984e5SSebastian Reichel };
7678c0984e5SSebastian Reichel
7688c0984e5SSebastian Reichel static const struct power_supply_desc usb_psy_desc = {
7698c0984e5SSebastian Reichel .name = "smbb-usbin",
7708c0984e5SSebastian Reichel .type = POWER_SUPPLY_TYPE_USB,
7718c0984e5SSebastian Reichel .properties = smbb_charger_properties,
7728c0984e5SSebastian Reichel .num_properties = ARRAY_SIZE(smbb_charger_properties),
7738c0984e5SSebastian Reichel .get_property = smbb_usbin_get_property,
7748c0984e5SSebastian Reichel .set_property = smbb_usbin_set_property,
7758c0984e5SSebastian Reichel .property_is_writeable = smbb_charger_writable_property,
7768c0984e5SSebastian Reichel };
7778c0984e5SSebastian Reichel
7788c0984e5SSebastian Reichel static const struct power_supply_desc dc_psy_desc = {
7798c0984e5SSebastian Reichel .name = "smbb-dcin",
7808c0984e5SSebastian Reichel .type = POWER_SUPPLY_TYPE_MAINS,
7818c0984e5SSebastian Reichel .properties = smbb_charger_properties,
7828c0984e5SSebastian Reichel .num_properties = ARRAY_SIZE(smbb_charger_properties),
7838c0984e5SSebastian Reichel .get_property = smbb_dcin_get_property,
7848c0984e5SSebastian Reichel .set_property = smbb_dcin_set_property,
7858c0984e5SSebastian Reichel .property_is_writeable = smbb_charger_writable_property,
7868c0984e5SSebastian Reichel };
7878c0984e5SSebastian Reichel
smbb_chg_otg_enable(struct regulator_dev * rdev)78861274effSBird, Tim static int smbb_chg_otg_enable(struct regulator_dev *rdev)
78961274effSBird, Tim {
79061274effSBird, Tim struct smbb_charger *chg = rdev_get_drvdata(rdev);
79161274effSBird, Tim int rc;
79261274effSBird, Tim
79361274effSBird, Tim rc = regmap_update_bits(chg->regmap, chg->addr + SMBB_USB_OTG_CTL,
79461274effSBird, Tim OTG_CTL_EN, OTG_CTL_EN);
79561274effSBird, Tim if (rc)
79661274effSBird, Tim dev_err(chg->dev, "failed to update OTG_CTL\n");
79761274effSBird, Tim return rc;
79861274effSBird, Tim }
79961274effSBird, Tim
smbb_chg_otg_disable(struct regulator_dev * rdev)80061274effSBird, Tim static int smbb_chg_otg_disable(struct regulator_dev *rdev)
80161274effSBird, Tim {
80261274effSBird, Tim struct smbb_charger *chg = rdev_get_drvdata(rdev);
80361274effSBird, Tim int rc;
80461274effSBird, Tim
80561274effSBird, Tim rc = regmap_update_bits(chg->regmap, chg->addr + SMBB_USB_OTG_CTL,
80661274effSBird, Tim OTG_CTL_EN, 0);
80761274effSBird, Tim if (rc)
80861274effSBird, Tim dev_err(chg->dev, "failed to update OTG_CTL\n");
80961274effSBird, Tim return rc;
81061274effSBird, Tim }
81161274effSBird, Tim
smbb_chg_otg_is_enabled(struct regulator_dev * rdev)81261274effSBird, Tim static int smbb_chg_otg_is_enabled(struct regulator_dev *rdev)
81361274effSBird, Tim {
81461274effSBird, Tim struct smbb_charger *chg = rdev_get_drvdata(rdev);
81561274effSBird, Tim unsigned int value = 0;
81661274effSBird, Tim int rc;
81761274effSBird, Tim
81861274effSBird, Tim rc = regmap_read(chg->regmap, chg->addr + SMBB_USB_OTG_CTL, &value);
81961274effSBird, Tim if (rc)
82061274effSBird, Tim dev_err(chg->dev, "failed to read OTG_CTL\n");
82161274effSBird, Tim
82261274effSBird, Tim return !!(value & OTG_CTL_EN);
82361274effSBird, Tim }
82461274effSBird, Tim
82561274effSBird, Tim static const struct regulator_ops smbb_chg_otg_ops = {
82661274effSBird, Tim .enable = smbb_chg_otg_enable,
82761274effSBird, Tim .disable = smbb_chg_otg_disable,
82861274effSBird, Tim .is_enabled = smbb_chg_otg_is_enabled,
82961274effSBird, Tim };
83061274effSBird, Tim
smbb_charger_probe(struct platform_device * pdev)8318c0984e5SSebastian Reichel static int smbb_charger_probe(struct platform_device *pdev)
8328c0984e5SSebastian Reichel {
8338c0984e5SSebastian Reichel struct power_supply_config bat_cfg = {};
8348c0984e5SSebastian Reichel struct power_supply_config usb_cfg = {};
8358c0984e5SSebastian Reichel struct power_supply_config dc_cfg = {};
8368c0984e5SSebastian Reichel struct smbb_charger *chg;
83761274effSBird, Tim struct regulator_config config = { };
8388c0984e5SSebastian Reichel int rc, i;
8398c0984e5SSebastian Reichel
8408c0984e5SSebastian Reichel chg = devm_kzalloc(&pdev->dev, sizeof(*chg), GFP_KERNEL);
8418c0984e5SSebastian Reichel if (!chg)
8428c0984e5SSebastian Reichel return -ENOMEM;
8438c0984e5SSebastian Reichel
8448c0984e5SSebastian Reichel chg->dev = &pdev->dev;
8458c0984e5SSebastian Reichel mutex_init(&chg->statlock);
8468c0984e5SSebastian Reichel
8478c0984e5SSebastian Reichel chg->regmap = dev_get_regmap(pdev->dev.parent, NULL);
8488c0984e5SSebastian Reichel if (!chg->regmap) {
8498c0984e5SSebastian Reichel dev_err(&pdev->dev, "failed to locate regmap\n");
8508c0984e5SSebastian Reichel return -ENODEV;
8518c0984e5SSebastian Reichel }
8528c0984e5SSebastian Reichel
8538c0984e5SSebastian Reichel rc = of_property_read_u32(pdev->dev.of_node, "reg", &chg->addr);
8548c0984e5SSebastian Reichel if (rc) {
8558c0984e5SSebastian Reichel dev_err(&pdev->dev, "missing or invalid 'reg' property\n");
8568c0984e5SSebastian Reichel return rc;
8578c0984e5SSebastian Reichel }
8588c0984e5SSebastian Reichel
8598c0984e5SSebastian Reichel rc = regmap_read(chg->regmap, chg->addr + SMBB_MISC_REV2, &chg->revision);
8608c0984e5SSebastian Reichel if (rc) {
8618c0984e5SSebastian Reichel dev_err(&pdev->dev, "unable to read revision\n");
8628c0984e5SSebastian Reichel return rc;
8638c0984e5SSebastian Reichel }
8648c0984e5SSebastian Reichel
8658c0984e5SSebastian Reichel chg->revision += 1;
866*0838a3bfSLuca Weiss if (chg->revision != 1 && chg->revision != 2 && chg->revision != 3) {
867*0838a3bfSLuca Weiss dev_err(&pdev->dev, "v%d hardware not supported\n", chg->revision);
8688c0984e5SSebastian Reichel return -ENODEV;
8698c0984e5SSebastian Reichel }
8708c0984e5SSebastian Reichel dev_info(&pdev->dev, "Initializing SMBB rev %u", chg->revision);
8718c0984e5SSebastian Reichel
8728c0984e5SSebastian Reichel chg->dc_disabled = of_property_read_bool(pdev->dev.of_node, "qcom,disable-dc");
8738c0984e5SSebastian Reichel
8748c0984e5SSebastian Reichel for (i = 0; i < _ATTR_CNT; ++i) {
8758c0984e5SSebastian Reichel rc = smbb_charger_attr_parse(chg, i);
8768c0984e5SSebastian Reichel if (rc) {
8778c0984e5SSebastian Reichel dev_err(&pdev->dev, "failed to parse/apply settings\n");
8788c0984e5SSebastian Reichel return rc;
8798c0984e5SSebastian Reichel }
8808c0984e5SSebastian Reichel }
8818c0984e5SSebastian Reichel
8828c0984e5SSebastian Reichel bat_cfg.drv_data = chg;
8838c0984e5SSebastian Reichel bat_cfg.of_node = pdev->dev.of_node;
8848c0984e5SSebastian Reichel chg->bat_psy = devm_power_supply_register(&pdev->dev,
8858c0984e5SSebastian Reichel &bat_psy_desc,
8868c0984e5SSebastian Reichel &bat_cfg);
8878c0984e5SSebastian Reichel if (IS_ERR(chg->bat_psy)) {
8888c0984e5SSebastian Reichel dev_err(&pdev->dev, "failed to register battery\n");
8898c0984e5SSebastian Reichel return PTR_ERR(chg->bat_psy);
8908c0984e5SSebastian Reichel }
8918c0984e5SSebastian Reichel
8928c0984e5SSebastian Reichel usb_cfg.drv_data = chg;
8938c0984e5SSebastian Reichel usb_cfg.supplied_to = smbb_bif;
8948c0984e5SSebastian Reichel usb_cfg.num_supplicants = ARRAY_SIZE(smbb_bif);
8958c0984e5SSebastian Reichel chg->usb_psy = devm_power_supply_register(&pdev->dev,
8968c0984e5SSebastian Reichel &usb_psy_desc,
8978c0984e5SSebastian Reichel &usb_cfg);
8988c0984e5SSebastian Reichel if (IS_ERR(chg->usb_psy)) {
8998c0984e5SSebastian Reichel dev_err(&pdev->dev, "failed to register USB power supply\n");
9008c0984e5SSebastian Reichel return PTR_ERR(chg->usb_psy);
9018c0984e5SSebastian Reichel }
9028c0984e5SSebastian Reichel
9038c0984e5SSebastian Reichel chg->edev = devm_extcon_dev_allocate(&pdev->dev, smbb_usb_extcon_cable);
9048c0984e5SSebastian Reichel if (IS_ERR(chg->edev)) {
9058c0984e5SSebastian Reichel dev_err(&pdev->dev, "failed to allocate extcon device\n");
9068c0984e5SSebastian Reichel return -ENOMEM;
9078c0984e5SSebastian Reichel }
9088c0984e5SSebastian Reichel
9098c0984e5SSebastian Reichel rc = devm_extcon_dev_register(&pdev->dev, chg->edev);
9108c0984e5SSebastian Reichel if (rc < 0) {
9118c0984e5SSebastian Reichel dev_err(&pdev->dev, "failed to register extcon device\n");
9128c0984e5SSebastian Reichel return rc;
9138c0984e5SSebastian Reichel }
9148c0984e5SSebastian Reichel
9158c0984e5SSebastian Reichel if (!chg->dc_disabled) {
9168c0984e5SSebastian Reichel dc_cfg.drv_data = chg;
9178c0984e5SSebastian Reichel dc_cfg.supplied_to = smbb_bif;
9188c0984e5SSebastian Reichel dc_cfg.num_supplicants = ARRAY_SIZE(smbb_bif);
9198c0984e5SSebastian Reichel chg->dc_psy = devm_power_supply_register(&pdev->dev,
9208c0984e5SSebastian Reichel &dc_psy_desc,
9218c0984e5SSebastian Reichel &dc_cfg);
9228c0984e5SSebastian Reichel if (IS_ERR(chg->dc_psy)) {
9238c0984e5SSebastian Reichel dev_err(&pdev->dev, "failed to register DC power supply\n");
9248c0984e5SSebastian Reichel return PTR_ERR(chg->dc_psy);
9258c0984e5SSebastian Reichel }
9268c0984e5SSebastian Reichel }
9278c0984e5SSebastian Reichel
9288c0984e5SSebastian Reichel for (i = 0; i < ARRAY_SIZE(smbb_charger_irqs); ++i) {
9298c0984e5SSebastian Reichel int irq;
9308c0984e5SSebastian Reichel
9318c0984e5SSebastian Reichel irq = platform_get_irq_byname(pdev, smbb_charger_irqs[i].name);
932391719dcSTang Bin if (irq < 0)
9338c0984e5SSebastian Reichel return irq;
9348c0984e5SSebastian Reichel
9358c0984e5SSebastian Reichel smbb_charger_irqs[i].handler(irq, chg);
9368c0984e5SSebastian Reichel
9378c0984e5SSebastian Reichel rc = devm_request_threaded_irq(&pdev->dev, irq, NULL,
9388c0984e5SSebastian Reichel smbb_charger_irqs[i].handler, IRQF_ONESHOT,
9398c0984e5SSebastian Reichel smbb_charger_irqs[i].name, chg);
9408c0984e5SSebastian Reichel if (rc) {
9418c0984e5SSebastian Reichel dev_err(&pdev->dev, "failed to request irq '%s'\n",
9428c0984e5SSebastian Reichel smbb_charger_irqs[i].name);
9438c0984e5SSebastian Reichel return rc;
9448c0984e5SSebastian Reichel }
9458c0984e5SSebastian Reichel }
9468c0984e5SSebastian Reichel
94761274effSBird, Tim /*
94861274effSBird, Tim * otg regulator is used to control VBUS voltage direction
94961274effSBird, Tim * when USB switches between host and gadget mode
95061274effSBird, Tim */
95161274effSBird, Tim chg->otg_rdesc.id = -1;
95261274effSBird, Tim chg->otg_rdesc.name = "otg-vbus";
95361274effSBird, Tim chg->otg_rdesc.ops = &smbb_chg_otg_ops;
95461274effSBird, Tim chg->otg_rdesc.owner = THIS_MODULE;
95561274effSBird, Tim chg->otg_rdesc.type = REGULATOR_VOLTAGE;
95661274effSBird, Tim chg->otg_rdesc.supply_name = "usb-otg-in";
95761274effSBird, Tim chg->otg_rdesc.of_match = "otg-vbus";
95861274effSBird, Tim
95961274effSBird, Tim config.dev = &pdev->dev;
96061274effSBird, Tim config.driver_data = chg;
96161274effSBird, Tim
96261274effSBird, Tim chg->otg_reg = devm_regulator_register(&pdev->dev, &chg->otg_rdesc,
96361274effSBird, Tim &config);
96461274effSBird, Tim if (IS_ERR(chg->otg_reg))
96561274effSBird, Tim return PTR_ERR(chg->otg_reg);
96661274effSBird, Tim
9678c0984e5SSebastian Reichel chg->jeita_ext_temp = of_property_read_bool(pdev->dev.of_node,
9688c0984e5SSebastian Reichel "qcom,jeita-extended-temp-range");
9698c0984e5SSebastian Reichel
9708c0984e5SSebastian Reichel /* Set temperature range to [35%:70%] or [25%:80%] accordingly */
9718c0984e5SSebastian Reichel rc = regmap_update_bits(chg->regmap, chg->addr + SMBB_BAT_BTC_CTRL,
9728c0984e5SSebastian Reichel BTC_CTRL_COLD_EXT | BTC_CTRL_HOT_EXT_N,
9738c0984e5SSebastian Reichel chg->jeita_ext_temp ?
9748c0984e5SSebastian Reichel BTC_CTRL_COLD_EXT :
9758c0984e5SSebastian Reichel BTC_CTRL_HOT_EXT_N);
9768c0984e5SSebastian Reichel if (rc) {
9778c0984e5SSebastian Reichel dev_err(&pdev->dev,
9788c0984e5SSebastian Reichel "unable to set %s temperature range\n",
9798c0984e5SSebastian Reichel chg->jeita_ext_temp ? "JEITA extended" : "normal");
9808c0984e5SSebastian Reichel return rc;
9818c0984e5SSebastian Reichel }
9828c0984e5SSebastian Reichel
9838c0984e5SSebastian Reichel for (i = 0; i < ARRAY_SIZE(smbb_charger_setup); ++i) {
9848c0984e5SSebastian Reichel const struct reg_off_mask_default *r = &smbb_charger_setup[i];
9858c0984e5SSebastian Reichel
9868c0984e5SSebastian Reichel if (r->rev_mask & BIT(chg->revision))
9878c0984e5SSebastian Reichel continue;
9888c0984e5SSebastian Reichel
9898c0984e5SSebastian Reichel rc = regmap_update_bits(chg->regmap, chg->addr + r->offset,
9908c0984e5SSebastian Reichel r->mask, r->value);
9918c0984e5SSebastian Reichel if (rc) {
9928c0984e5SSebastian Reichel dev_err(&pdev->dev,
9938c0984e5SSebastian Reichel "unable to initializing charging, bailing\n");
9948c0984e5SSebastian Reichel return rc;
9958c0984e5SSebastian Reichel }
9968c0984e5SSebastian Reichel }
9978c0984e5SSebastian Reichel
9988c0984e5SSebastian Reichel platform_set_drvdata(pdev, chg);
9998c0984e5SSebastian Reichel
10008c0984e5SSebastian Reichel return 0;
10018c0984e5SSebastian Reichel }
10028c0984e5SSebastian Reichel
smbb_charger_remove(struct platform_device * pdev)10038c0984e5SSebastian Reichel static int smbb_charger_remove(struct platform_device *pdev)
10048c0984e5SSebastian Reichel {
10058c0984e5SSebastian Reichel struct smbb_charger *chg;
10068c0984e5SSebastian Reichel
10078c0984e5SSebastian Reichel chg = platform_get_drvdata(pdev);
10088c0984e5SSebastian Reichel
10098c0984e5SSebastian Reichel regmap_update_bits(chg->regmap, chg->addr + SMBB_CHG_CTRL, CTRL_EN, 0);
10108c0984e5SSebastian Reichel
10118c0984e5SSebastian Reichel return 0;
10128c0984e5SSebastian Reichel }
10138c0984e5SSebastian Reichel
10148c0984e5SSebastian Reichel static const struct of_device_id smbb_charger_id_table[] = {
1015*0838a3bfSLuca Weiss { .compatible = "qcom,pm8226-charger" },
10168c0984e5SSebastian Reichel { .compatible = "qcom,pm8941-charger" },
10178c0984e5SSebastian Reichel { }
10188c0984e5SSebastian Reichel };
10198c0984e5SSebastian Reichel MODULE_DEVICE_TABLE(of, smbb_charger_id_table);
10208c0984e5SSebastian Reichel
10218c0984e5SSebastian Reichel static struct platform_driver smbb_charger_driver = {
10228c0984e5SSebastian Reichel .probe = smbb_charger_probe,
10238c0984e5SSebastian Reichel .remove = smbb_charger_remove,
10248c0984e5SSebastian Reichel .driver = {
10258c0984e5SSebastian Reichel .name = "qcom-smbb",
10268c0984e5SSebastian Reichel .of_match_table = smbb_charger_id_table,
10278c0984e5SSebastian Reichel },
10288c0984e5SSebastian Reichel };
10298c0984e5SSebastian Reichel module_platform_driver(smbb_charger_driver);
10308c0984e5SSebastian Reichel
10318c0984e5SSebastian Reichel MODULE_DESCRIPTION("Qualcomm Switch-Mode Battery Charger and Boost driver");
10328c0984e5SSebastian Reichel MODULE_LICENSE("GPL v2");
1033