Grazvydas Ignotas | 2e727f1 | 2010-09-27 23:18:24 +0300 | [diff] [blame] | 1 | /* |
| 2 | * TWL4030/TPS65950 BCI (Battery Charger Interface) driver |
| 3 | * |
| 4 | * Copyright (C) 2010 Gražvydas Ignotas <notasas@gmail.com> |
| 5 | * |
| 6 | * based on twl4030_bci_battery.c by TI |
| 7 | * Copyright (C) 2008 Texas Instruments, Inc. |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | */ |
| 14 | |
| 15 | #include <linux/init.h> |
| 16 | #include <linux/module.h> |
| 17 | #include <linux/slab.h> |
Kishon Vijay Abraham I | ded017e | 2012-06-26 17:40:32 +0530 | [diff] [blame] | 18 | #include <linux/err.h> |
Grazvydas Ignotas | 2e727f1 | 2010-09-27 23:18:24 +0300 | [diff] [blame] | 19 | #include <linux/platform_device.h> |
| 20 | #include <linux/interrupt.h> |
| 21 | #include <linux/i2c/twl.h> |
| 22 | #include <linux/power_supply.h> |
| 23 | #include <linux/notifier.h> |
| 24 | #include <linux/usb/otg.h> |
NeilBrown | e4ae537 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 25 | #include <linux/i2c/twl4030-madc.h> |
Grazvydas Ignotas | 2e727f1 | 2010-09-27 23:18:24 +0300 | [diff] [blame] | 26 | |
NeilBrown | 7f4a633 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 27 | #define TWL4030_BCIMDEN 0x00 |
| 28 | #define TWL4030_BCIMDKEY 0x01 |
Grazvydas Ignotas | 2e727f1 | 2010-09-27 23:18:24 +0300 | [diff] [blame] | 29 | #define TWL4030_BCIMSTATEC 0x02 |
| 30 | #define TWL4030_BCIICHG 0x08 |
| 31 | #define TWL4030_BCIVAC 0x0a |
| 32 | #define TWL4030_BCIVBUS 0x0c |
Nishanth Menon | 61a7784 | 2014-05-28 16:46:49 -0500 | [diff] [blame] | 33 | #define TWL4030_BCIMFSTS3 0x0F |
Grazvydas Ignotas | 2e727f1 | 2010-09-27 23:18:24 +0300 | [diff] [blame] | 34 | #define TWL4030_BCIMFSTS4 0x10 |
| 35 | #define TWL4030_BCICTL1 0x23 |
NeilBrown | 210d4bc | 2012-05-09 07:40:40 +1000 | [diff] [blame] | 36 | #define TWL4030_BB_CFG 0x12 |
NeilBrown | 1098cb5 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 37 | #define TWL4030_BCIIREF1 0x27 |
| 38 | #define TWL4030_BCIIREF2 0x28 |
| 39 | #define TWL4030_BCIMFKEY 0x11 |
NeilBrown | 7f4a633 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 40 | #define TWL4030_BCIMFEN3 0x14 |
NeilBrown | 1098cb5 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 41 | #define TWL4030_BCIMFTH8 0x1d |
| 42 | #define TWL4030_BCIMFTH9 0x1e |
NeilBrown | 7f4a633 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 43 | #define TWL4030_BCIWDKEY 0x21 |
Grazvydas Ignotas | 2e727f1 | 2010-09-27 23:18:24 +0300 | [diff] [blame] | 44 | |
Nishanth Menon | 61a7784 | 2014-05-28 16:46:49 -0500 | [diff] [blame] | 45 | #define TWL4030_BCIMFSTS1 0x01 |
| 46 | |
Grazvydas Ignotas | 2e727f1 | 2010-09-27 23:18:24 +0300 | [diff] [blame] | 47 | #define TWL4030_BCIAUTOWEN BIT(5) |
| 48 | #define TWL4030_CONFIG_DONE BIT(4) |
NeilBrown | 7f4a633 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 49 | #define TWL4030_CVENAC BIT(2) |
Grazvydas Ignotas | 2e727f1 | 2010-09-27 23:18:24 +0300 | [diff] [blame] | 50 | #define TWL4030_BCIAUTOUSB BIT(1) |
| 51 | #define TWL4030_BCIAUTOAC BIT(0) |
| 52 | #define TWL4030_CGAIN BIT(5) |
| 53 | #define TWL4030_USBFASTMCHG BIT(2) |
| 54 | #define TWL4030_STS_VBUS BIT(7) |
| 55 | #define TWL4030_STS_USB_ID BIT(2) |
NeilBrown | 210d4bc | 2012-05-09 07:40:40 +1000 | [diff] [blame] | 56 | #define TWL4030_BBCHEN BIT(4) |
Il Han | 94b05ca | 2012-08-17 16:49:43 +0900 | [diff] [blame] | 57 | #define TWL4030_BBSEL_MASK 0x0c |
| 58 | #define TWL4030_BBSEL_2V5 0x00 |
| 59 | #define TWL4030_BBSEL_3V0 0x04 |
| 60 | #define TWL4030_BBSEL_3V1 0x08 |
| 61 | #define TWL4030_BBSEL_3V2 0x0c |
| 62 | #define TWL4030_BBISEL_MASK 0x03 |
| 63 | #define TWL4030_BBISEL_25uA 0x00 |
| 64 | #define TWL4030_BBISEL_150uA 0x01 |
| 65 | #define TWL4030_BBISEL_500uA 0x02 |
| 66 | #define TWL4030_BBISEL_1000uA 0x03 |
Grazvydas Ignotas | 2e727f1 | 2010-09-27 23:18:24 +0300 | [diff] [blame] | 67 | |
Nishanth Menon | 61a7784 | 2014-05-28 16:46:49 -0500 | [diff] [blame] | 68 | #define TWL4030_BATSTSPCHG BIT(2) |
| 69 | #define TWL4030_BATSTSMCHG BIT(6) |
| 70 | |
Grazvydas Ignotas | 2e727f1 | 2010-09-27 23:18:24 +0300 | [diff] [blame] | 71 | /* BCI interrupts */ |
| 72 | #define TWL4030_WOVF BIT(0) /* Watchdog overflow */ |
| 73 | #define TWL4030_TMOVF BIT(1) /* Timer overflow */ |
| 74 | #define TWL4030_ICHGHIGH BIT(2) /* Battery charge current high */ |
| 75 | #define TWL4030_ICHGLOW BIT(3) /* Battery cc. low / FSM state change */ |
| 76 | #define TWL4030_ICHGEOC BIT(4) /* Battery current end-of-charge */ |
| 77 | #define TWL4030_TBATOR2 BIT(5) /* Battery temperature out of range 2 */ |
| 78 | #define TWL4030_TBATOR1 BIT(6) /* Battery temperature out of range 1 */ |
| 79 | #define TWL4030_BATSTS BIT(7) /* Battery status */ |
| 80 | |
| 81 | #define TWL4030_VBATLVL BIT(0) /* VBAT level */ |
| 82 | #define TWL4030_VBATOV BIT(1) /* VBAT overvoltage */ |
| 83 | #define TWL4030_VBUSOV BIT(2) /* VBUS overvoltage */ |
| 84 | #define TWL4030_ACCHGOV BIT(3) /* Ac charger overvoltage */ |
| 85 | |
| 86 | #define TWL4030_MSTATEC_USB BIT(4) |
| 87 | #define TWL4030_MSTATEC_AC BIT(5) |
| 88 | #define TWL4030_MSTATEC_MASK 0x0f |
| 89 | #define TWL4030_MSTATEC_QUICK1 0x02 |
| 90 | #define TWL4030_MSTATEC_QUICK7 0x07 |
| 91 | #define TWL4030_MSTATEC_COMPLETE1 0x0b |
| 92 | #define TWL4030_MSTATEC_COMPLETE4 0x0e |
| 93 | |
| 94 | static bool allow_usb; |
Grazvydas Ignotas | 28d48f0 | 2011-06-03 14:43:11 +0300 | [diff] [blame] | 95 | module_param(allow_usb, bool, 0644); |
Grazvydas Ignotas | 2e727f1 | 2010-09-27 23:18:24 +0300 | [diff] [blame] | 96 | MODULE_PARM_DESC(allow_usb, "Allow USB charge drawing default current"); |
| 97 | |
| 98 | struct twl4030_bci { |
| 99 | struct device *dev; |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 100 | struct power_supply *ac; |
| 101 | struct power_supply *usb; |
Heikki Krogerus | 8675381 | 2012-02-13 13:24:02 +0200 | [diff] [blame] | 102 | struct usb_phy *transceiver; |
Heikki Krogerus | fcc8ebc | 2012-02-13 13:24:16 +0200 | [diff] [blame] | 103 | struct notifier_block usb_nb; |
Heikki Krogerus | d6ccc44 | 2011-02-25 13:56:36 +0200 | [diff] [blame] | 104 | struct work_struct work; |
Grazvydas Ignotas | 2e727f1 | 2010-09-27 23:18:24 +0300 | [diff] [blame] | 105 | int irq_chg; |
| 106 | int irq_bci; |
NeilBrown | ab37813 | 2012-05-09 07:40:40 +1000 | [diff] [blame] | 107 | int usb_enabled; |
Heikki Krogerus | d6ccc44 | 2011-02-25 13:56:36 +0200 | [diff] [blame] | 108 | |
NeilBrown | 1098cb5 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 109 | /* |
NeilBrown | e4ae537 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 110 | * ichg_* and *_cur values in uA. If any are 'large', we set |
| 111 | * CGAIN to '1' which doubles the range for half the |
| 112 | * precision. |
NeilBrown | 1098cb5 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 113 | */ |
NeilBrown | e4ae537 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 114 | unsigned int ichg_eoc, ichg_lo, ichg_hi; |
| 115 | unsigned int usb_cur, ac_cur; |
| 116 | bool ac_is_active; |
NeilBrown | b04b908 | 2015-07-30 10:11:24 +1000 | [diff] [blame^] | 117 | int usb_mode, ac_mode; /* charging mode requested */ |
NeilBrown | 22d4c33 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 118 | #define CHARGE_OFF 0 |
| 119 | #define CHARGE_AUTO 1 |
NeilBrown | 7f4a633 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 120 | #define CHARGE_LINEAR 2 |
NeilBrown | 1098cb5 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 121 | |
Heikki Krogerus | d6ccc44 | 2011-02-25 13:56:36 +0200 | [diff] [blame] | 122 | unsigned long event; |
Grazvydas Ignotas | 2e727f1 | 2010-09-27 23:18:24 +0300 | [diff] [blame] | 123 | }; |
| 124 | |
NeilBrown | 22d4c33 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 125 | /* strings for 'usb_mode' values */ |
NeilBrown | 7f4a633 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 126 | static char *modes[] = { "off", "auto", "continuous" }; |
NeilBrown | 22d4c33 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 127 | |
Grazvydas Ignotas | 2e727f1 | 2010-09-27 23:18:24 +0300 | [diff] [blame] | 128 | /* |
| 129 | * clear and set bits on an given register on a given module |
| 130 | */ |
| 131 | static int twl4030_clear_set(u8 mod_no, u8 clear, u8 set, u8 reg) |
| 132 | { |
| 133 | u8 val = 0; |
| 134 | int ret; |
| 135 | |
| 136 | ret = twl_i2c_read_u8(mod_no, &val, reg); |
| 137 | if (ret) |
| 138 | return ret; |
| 139 | |
| 140 | val &= ~clear; |
| 141 | val |= set; |
| 142 | |
| 143 | return twl_i2c_write_u8(mod_no, val, reg); |
| 144 | } |
| 145 | |
| 146 | static int twl4030_bci_read(u8 reg, u8 *val) |
| 147 | { |
Peter Ujfalusi | e9f14c1 | 2012-11-13 10:42:11 +0100 | [diff] [blame] | 148 | return twl_i2c_read_u8(TWL_MODULE_MAIN_CHARGE, val, reg); |
Grazvydas Ignotas | 2e727f1 | 2010-09-27 23:18:24 +0300 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | static int twl4030_clear_set_boot_bci(u8 clear, u8 set) |
| 152 | { |
Peter Ujfalusi | e9f14c1 | 2012-11-13 10:42:11 +0100 | [diff] [blame] | 153 | return twl4030_clear_set(TWL_MODULE_PM_MASTER, clear, |
Grazvydas Ignotas | 2e727f1 | 2010-09-27 23:18:24 +0300 | [diff] [blame] | 154 | TWL4030_CONFIG_DONE | TWL4030_BCIAUTOWEN | set, |
| 155 | TWL4030_PM_MASTER_BOOT_BCI); |
| 156 | } |
| 157 | |
| 158 | static int twl4030bci_read_adc_val(u8 reg) |
| 159 | { |
| 160 | int ret, temp; |
| 161 | u8 val; |
| 162 | |
| 163 | /* read MSB */ |
| 164 | ret = twl4030_bci_read(reg + 1, &val); |
| 165 | if (ret) |
| 166 | return ret; |
| 167 | |
| 168 | temp = (int)(val & 0x03) << 8; |
| 169 | |
| 170 | /* read LSB */ |
| 171 | ret = twl4030_bci_read(reg, &val); |
| 172 | if (ret) |
| 173 | return ret; |
| 174 | |
| 175 | return temp | val; |
| 176 | } |
| 177 | |
| 178 | /* |
Nishanth Menon | 61a7784 | 2014-05-28 16:46:49 -0500 | [diff] [blame] | 179 | * Check if Battery Pack was present |
| 180 | */ |
| 181 | static int twl4030_is_battery_present(struct twl4030_bci *bci) |
| 182 | { |
| 183 | int ret; |
| 184 | u8 val = 0; |
| 185 | |
| 186 | /* Battery presence in Main charge? */ |
| 187 | ret = twl_i2c_read_u8(TWL_MODULE_MAIN_CHARGE, &val, TWL4030_BCIMFSTS3); |
| 188 | if (ret) |
| 189 | return ret; |
| 190 | if (val & TWL4030_BATSTSMCHG) |
| 191 | return 0; |
| 192 | |
| 193 | /* |
| 194 | * OK, It could be that bootloader did not enable main charger, |
| 195 | * pre-charge is h/w auto. So, Battery presence in Pre-charge? |
| 196 | */ |
| 197 | ret = twl_i2c_read_u8(TWL4030_MODULE_PRECHARGE, &val, |
| 198 | TWL4030_BCIMFSTS1); |
| 199 | if (ret) |
| 200 | return ret; |
| 201 | if (val & TWL4030_BATSTSPCHG) |
| 202 | return 0; |
| 203 | |
| 204 | return -ENODEV; |
| 205 | } |
| 206 | |
| 207 | /* |
NeilBrown | 3b542f0 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 208 | * TI provided formulas: |
| 209 | * CGAIN == 0: ICHG = (BCIICHG * 1.7) / (2^10 - 1) - 0.85 |
| 210 | * CGAIN == 1: ICHG = (BCIICHG * 3.4) / (2^10 - 1) - 1.7 |
| 211 | * Here we use integer approximation of: |
| 212 | * CGAIN == 0: val * 1.6618 - 0.85 * 1000 |
| 213 | * CGAIN == 1: (val * 1.6618 - 0.85 * 1000) * 2 |
| 214 | */ |
| 215 | /* |
| 216 | * convert twl register value for currents into uA |
| 217 | */ |
| 218 | static int regval2ua(int regval, bool cgain) |
| 219 | { |
| 220 | if (cgain) |
| 221 | return (regval * 16618 - 8500 * 1000) / 5; |
| 222 | else |
| 223 | return (regval * 16618 - 8500 * 1000) / 10; |
| 224 | } |
| 225 | |
| 226 | /* |
| 227 | * convert uA currents into twl register value |
| 228 | */ |
| 229 | static int ua2regval(int ua, bool cgain) |
| 230 | { |
| 231 | int ret; |
| 232 | if (cgain) |
| 233 | ua /= 2; |
| 234 | ret = (ua * 10 + 8500 * 1000) / 16618; |
| 235 | /* rounding problems */ |
| 236 | if (ret < 512) |
| 237 | ret = 512; |
| 238 | return ret; |
| 239 | } |
| 240 | |
NeilBrown | 1098cb5 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 241 | static int twl4030_charger_update_current(struct twl4030_bci *bci) |
| 242 | { |
| 243 | int status; |
NeilBrown | e4ae537 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 244 | int cur; |
NeilBrown | 1098cb5 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 245 | unsigned reg, cur_reg; |
| 246 | u8 bcictl1, oldreg, fullreg; |
| 247 | bool cgain = false; |
| 248 | u8 boot_bci; |
| 249 | |
NeilBrown | e4ae537 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 250 | /* |
| 251 | * If AC (Accessory Charger) voltage exceeds 4.5V (MADC 11) |
| 252 | * and AC is enabled, set current for 'ac' |
| 253 | */ |
| 254 | if (twl4030_get_madc_conversion(11) > 4500) { |
| 255 | cur = bci->ac_cur; |
| 256 | bci->ac_is_active = true; |
| 257 | } else { |
| 258 | cur = bci->usb_cur; |
| 259 | bci->ac_is_active = false; |
| 260 | } |
| 261 | |
NeilBrown | 1098cb5 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 262 | /* First, check thresholds and see if cgain is needed */ |
| 263 | if (bci->ichg_eoc >= 200000) |
| 264 | cgain = true; |
| 265 | if (bci->ichg_lo >= 400000) |
| 266 | cgain = true; |
| 267 | if (bci->ichg_hi >= 820000) |
| 268 | cgain = true; |
NeilBrown | e4ae537 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 269 | if (cur > 852000) |
NeilBrown | 1098cb5 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 270 | cgain = true; |
| 271 | |
| 272 | status = twl4030_bci_read(TWL4030_BCICTL1, &bcictl1); |
| 273 | if (status < 0) |
| 274 | return status; |
| 275 | if (twl_i2c_read_u8(TWL_MODULE_PM_MASTER, &boot_bci, |
| 276 | TWL4030_PM_MASTER_BOOT_BCI) < 0) |
| 277 | boot_bci = 0; |
| 278 | boot_bci &= 7; |
| 279 | |
| 280 | if ((!!cgain) != !!(bcictl1 & TWL4030_CGAIN)) |
| 281 | /* Need to turn for charging while we change the |
| 282 | * CGAIN bit. Leave it off while everything is |
| 283 | * updated. |
| 284 | */ |
| 285 | twl4030_clear_set_boot_bci(boot_bci, 0); |
| 286 | |
| 287 | /* |
| 288 | * For ichg_eoc, the hardware only supports reg values matching |
| 289 | * 100XXXX000, and requires the XXXX be stored in the high nibble |
| 290 | * of TWL4030_BCIMFTH8. |
| 291 | */ |
| 292 | reg = ua2regval(bci->ichg_eoc, cgain); |
| 293 | if (reg > 0x278) |
| 294 | reg = 0x278; |
| 295 | if (reg < 0x200) |
| 296 | reg = 0x200; |
| 297 | reg = (reg >> 3) & 0xf; |
| 298 | fullreg = reg << 4; |
| 299 | |
| 300 | /* |
| 301 | * For ichg_lo, reg value must match 10XXXX0000. |
| 302 | * XXXX is stored in low nibble of TWL4030_BCIMFTH8. |
| 303 | */ |
| 304 | reg = ua2regval(bci->ichg_lo, cgain); |
| 305 | if (reg > 0x2F0) |
| 306 | reg = 0x2F0; |
| 307 | if (reg < 0x200) |
| 308 | reg = 0x200; |
| 309 | reg = (reg >> 4) & 0xf; |
| 310 | fullreg |= reg; |
| 311 | |
| 312 | /* ichg_eoc and ichg_lo live in same register */ |
| 313 | status = twl4030_bci_read(TWL4030_BCIMFTH8, &oldreg); |
| 314 | if (status < 0) |
| 315 | return status; |
| 316 | if (oldreg != fullreg) { |
| 317 | status = twl_i2c_write_u8(TWL_MODULE_MAIN_CHARGE, 0xF4, |
| 318 | TWL4030_BCIMFKEY); |
| 319 | if (status < 0) |
| 320 | return status; |
| 321 | twl_i2c_write_u8(TWL_MODULE_MAIN_CHARGE, |
| 322 | fullreg, TWL4030_BCIMFTH8); |
| 323 | } |
| 324 | |
| 325 | /* ichg_hi threshold must be 1XXXX01100 (I think) */ |
| 326 | reg = ua2regval(bci->ichg_hi, cgain); |
| 327 | if (reg > 0x3E0) |
| 328 | reg = 0x3E0; |
| 329 | if (reg < 0x200) |
| 330 | reg = 0x200; |
| 331 | fullreg = (reg >> 5) & 0xF; |
| 332 | fullreg <<= 4; |
| 333 | status = twl4030_bci_read(TWL4030_BCIMFTH9, &oldreg); |
| 334 | if (status < 0) |
| 335 | return status; |
| 336 | if ((oldreg & 0xF0) != fullreg) { |
| 337 | fullreg |= (oldreg & 0x0F); |
| 338 | status = twl_i2c_write_u8(TWL_MODULE_MAIN_CHARGE, 0xE7, |
| 339 | TWL4030_BCIMFKEY); |
| 340 | if (status < 0) |
| 341 | return status; |
| 342 | twl_i2c_write_u8(TWL_MODULE_MAIN_CHARGE, |
| 343 | fullreg, TWL4030_BCIMFTH9); |
| 344 | } |
| 345 | |
| 346 | /* |
| 347 | * And finally, set the current. This is stored in |
| 348 | * two registers. |
| 349 | */ |
NeilBrown | e4ae537 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 350 | reg = ua2regval(cur, cgain); |
NeilBrown | 1098cb5 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 351 | /* we have only 10 bits */ |
| 352 | if (reg > 0x3ff) |
| 353 | reg = 0x3ff; |
| 354 | status = twl4030_bci_read(TWL4030_BCIIREF1, &oldreg); |
| 355 | if (status < 0) |
| 356 | return status; |
| 357 | cur_reg = oldreg; |
| 358 | status = twl4030_bci_read(TWL4030_BCIIREF2, &oldreg); |
| 359 | if (status < 0) |
| 360 | return status; |
| 361 | cur_reg |= oldreg << 8; |
| 362 | if (reg != oldreg) { |
| 363 | /* disable write protection for one write access for |
| 364 | * BCIIREF */ |
| 365 | status = twl_i2c_write_u8(TWL_MODULE_MAIN_CHARGE, 0xE7, |
| 366 | TWL4030_BCIMFKEY); |
| 367 | if (status < 0) |
| 368 | return status; |
| 369 | status = twl_i2c_write_u8(TWL_MODULE_MAIN_CHARGE, |
| 370 | (reg & 0x100) ? 3 : 2, |
| 371 | TWL4030_BCIIREF2); |
| 372 | if (status < 0) |
| 373 | return status; |
| 374 | /* disable write protection for one write access for |
| 375 | * BCIIREF */ |
| 376 | status = twl_i2c_write_u8(TWL_MODULE_MAIN_CHARGE, 0xE7, |
| 377 | TWL4030_BCIMFKEY); |
| 378 | if (status < 0) |
| 379 | return status; |
| 380 | status = twl_i2c_write_u8(TWL_MODULE_MAIN_CHARGE, |
| 381 | reg & 0xff, |
| 382 | TWL4030_BCIIREF1); |
| 383 | } |
| 384 | if ((!!cgain) != !!(bcictl1 & TWL4030_CGAIN)) { |
| 385 | /* Flip CGAIN and re-enable charging */ |
| 386 | bcictl1 ^= TWL4030_CGAIN; |
| 387 | twl_i2c_write_u8(TWL_MODULE_MAIN_CHARGE, |
| 388 | bcictl1, TWL4030_BCICTL1); |
| 389 | twl4030_clear_set_boot_bci(0, boot_bci); |
| 390 | } |
| 391 | return 0; |
| 392 | } |
| 393 | |
NeilBrown | 3b542f0 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 394 | /* |
NeilBrown | 9c645d2 | 2012-05-09 07:40:39 +1000 | [diff] [blame] | 395 | * Enable/Disable USB Charge functionality. |
Grazvydas Ignotas | 2e727f1 | 2010-09-27 23:18:24 +0300 | [diff] [blame] | 396 | */ |
| 397 | static int twl4030_charger_enable_usb(struct twl4030_bci *bci, bool enable) |
| 398 | { |
| 399 | int ret; |
| 400 | |
NeilBrown | 22d4c33 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 401 | if (bci->usb_mode == CHARGE_OFF) |
| 402 | enable = false; |
NeilBrown | e57c4a6 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 403 | if (enable && !IS_ERR_OR_NULL(bci->transceiver)) { |
Grazvydas Ignotas | 2e727f1 | 2010-09-27 23:18:24 +0300 | [diff] [blame] | 404 | |
NeilBrown | e4ae537 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 405 | twl4030_charger_update_current(bci); |
| 406 | |
NeilBrown | e57c4a6 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 407 | /* Need to keep phy powered */ |
NeilBrown | ab37813 | 2012-05-09 07:40:40 +1000 | [diff] [blame] | 408 | if (!bci->usb_enabled) { |
NeilBrown | e57c4a6 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 409 | pm_runtime_get_sync(bci->transceiver->dev); |
NeilBrown | ab37813 | 2012-05-09 07:40:40 +1000 | [diff] [blame] | 410 | bci->usb_enabled = 1; |
| 411 | } |
| 412 | |
NeilBrown | 7f4a633 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 413 | if (bci->usb_mode == CHARGE_AUTO) |
| 414 | /* forcing the field BCIAUTOUSB (BOOT_BCI[1]) to 1 */ |
| 415 | ret = twl4030_clear_set_boot_bci(0, TWL4030_BCIAUTOUSB); |
Grazvydas Ignotas | 2e727f1 | 2010-09-27 23:18:24 +0300 | [diff] [blame] | 416 | |
| 417 | /* forcing USBFASTMCHG(BCIMFSTS4[2]) to 1 */ |
Peter Ujfalusi | e9f14c1 | 2012-11-13 10:42:11 +0100 | [diff] [blame] | 418 | ret = twl4030_clear_set(TWL_MODULE_MAIN_CHARGE, 0, |
Grazvydas Ignotas | 2e727f1 | 2010-09-27 23:18:24 +0300 | [diff] [blame] | 419 | TWL4030_USBFASTMCHG, TWL4030_BCIMFSTS4); |
NeilBrown | 7f4a633 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 420 | if (bci->usb_mode == CHARGE_LINEAR) { |
| 421 | twl4030_clear_set_boot_bci(TWL4030_BCIAUTOAC|TWL4030_CVENAC, 0); |
| 422 | /* Watch dog key: WOVF acknowledge */ |
| 423 | ret = twl_i2c_write_u8(TWL_MODULE_MAIN_CHARGE, 0x33, |
| 424 | TWL4030_BCIWDKEY); |
| 425 | /* 0x24 + EKEY6: off mode */ |
| 426 | ret = twl_i2c_write_u8(TWL_MODULE_MAIN_CHARGE, 0x2a, |
| 427 | TWL4030_BCIMDKEY); |
| 428 | /* EKEY2: Linear charge: USB path */ |
| 429 | ret = twl_i2c_write_u8(TWL_MODULE_MAIN_CHARGE, 0x26, |
| 430 | TWL4030_BCIMDKEY); |
| 431 | /* WDKEY5: stop watchdog count */ |
| 432 | ret = twl_i2c_write_u8(TWL_MODULE_MAIN_CHARGE, 0xf3, |
| 433 | TWL4030_BCIWDKEY); |
| 434 | /* enable MFEN3 access */ |
| 435 | ret = twl_i2c_write_u8(TWL_MODULE_MAIN_CHARGE, 0x9c, |
| 436 | TWL4030_BCIMFKEY); |
| 437 | /* ICHGEOCEN - end-of-charge monitor (current < 80mA) |
| 438 | * (charging continues) |
| 439 | * ICHGLOWEN - current level monitor (charge continues) |
| 440 | * don't monitor over-current or heat save |
| 441 | */ |
| 442 | ret = twl_i2c_write_u8(TWL_MODULE_MAIN_CHARGE, 0xf0, |
| 443 | TWL4030_BCIMFEN3); |
| 444 | } |
Grazvydas Ignotas | 2e727f1 | 2010-09-27 23:18:24 +0300 | [diff] [blame] | 445 | } else { |
| 446 | ret = twl4030_clear_set_boot_bci(TWL4030_BCIAUTOUSB, 0); |
NeilBrown | 7f4a633 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 447 | ret |= twl_i2c_write_u8(TWL_MODULE_MAIN_CHARGE, 0x2a, |
| 448 | TWL4030_BCIMDKEY); |
NeilBrown | ab37813 | 2012-05-09 07:40:40 +1000 | [diff] [blame] | 449 | if (bci->usb_enabled) { |
NeilBrown | e57c4a6 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 450 | pm_runtime_mark_last_busy(bci->transceiver->dev); |
| 451 | pm_runtime_put_autosuspend(bci->transceiver->dev); |
NeilBrown | ab37813 | 2012-05-09 07:40:40 +1000 | [diff] [blame] | 452 | bci->usb_enabled = 0; |
| 453 | } |
Grazvydas Ignotas | 2e727f1 | 2010-09-27 23:18:24 +0300 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | return ret; |
| 457 | } |
| 458 | |
| 459 | /* |
| 460 | * Enable/Disable AC Charge funtionality. |
| 461 | */ |
NeilBrown | b04b908 | 2015-07-30 10:11:24 +1000 | [diff] [blame^] | 462 | static int twl4030_charger_enable_ac(struct twl4030_bci *bci, bool enable) |
Grazvydas Ignotas | 2e727f1 | 2010-09-27 23:18:24 +0300 | [diff] [blame] | 463 | { |
| 464 | int ret; |
| 465 | |
NeilBrown | b04b908 | 2015-07-30 10:11:24 +1000 | [diff] [blame^] | 466 | if (bci->ac_mode == CHARGE_OFF) |
| 467 | enable = false; |
| 468 | |
Grazvydas Ignotas | 2e727f1 | 2010-09-27 23:18:24 +0300 | [diff] [blame] | 469 | if (enable) |
| 470 | ret = twl4030_clear_set_boot_bci(0, TWL4030_BCIAUTOAC); |
| 471 | else |
| 472 | ret = twl4030_clear_set_boot_bci(TWL4030_BCIAUTOAC, 0); |
| 473 | |
| 474 | return ret; |
| 475 | } |
| 476 | |
| 477 | /* |
NeilBrown | 210d4bc | 2012-05-09 07:40:40 +1000 | [diff] [blame] | 478 | * Enable/Disable charging of Backup Battery. |
| 479 | */ |
| 480 | static int twl4030_charger_enable_backup(int uvolt, int uamp) |
| 481 | { |
| 482 | int ret; |
| 483 | u8 flags; |
| 484 | |
| 485 | if (uvolt < 2500000 || |
| 486 | uamp < 25) { |
| 487 | /* disable charging of backup battery */ |
Peter Ujfalusi | e9f14c1 | 2012-11-13 10:42:11 +0100 | [diff] [blame] | 488 | ret = twl4030_clear_set(TWL_MODULE_PM_RECEIVER, |
NeilBrown | 210d4bc | 2012-05-09 07:40:40 +1000 | [diff] [blame] | 489 | TWL4030_BBCHEN, 0, TWL4030_BB_CFG); |
| 490 | return ret; |
| 491 | } |
| 492 | |
| 493 | flags = TWL4030_BBCHEN; |
| 494 | if (uvolt >= 3200000) |
| 495 | flags |= TWL4030_BBSEL_3V2; |
| 496 | else if (uvolt >= 3100000) |
| 497 | flags |= TWL4030_BBSEL_3V1; |
| 498 | else if (uvolt >= 3000000) |
| 499 | flags |= TWL4030_BBSEL_3V0; |
| 500 | else |
| 501 | flags |= TWL4030_BBSEL_2V5; |
| 502 | |
| 503 | if (uamp >= 1000) |
| 504 | flags |= TWL4030_BBISEL_1000uA; |
| 505 | else if (uamp >= 500) |
| 506 | flags |= TWL4030_BBISEL_500uA; |
| 507 | else if (uamp >= 150) |
| 508 | flags |= TWL4030_BBISEL_150uA; |
| 509 | else |
| 510 | flags |= TWL4030_BBISEL_25uA; |
| 511 | |
Peter Ujfalusi | e9f14c1 | 2012-11-13 10:42:11 +0100 | [diff] [blame] | 512 | ret = twl4030_clear_set(TWL_MODULE_PM_RECEIVER, |
NeilBrown | 210d4bc | 2012-05-09 07:40:40 +1000 | [diff] [blame] | 513 | TWL4030_BBSEL_MASK | TWL4030_BBISEL_MASK, |
| 514 | flags, |
| 515 | TWL4030_BB_CFG); |
| 516 | |
| 517 | return ret; |
| 518 | } |
| 519 | |
| 520 | /* |
Grazvydas Ignotas | 2e727f1 | 2010-09-27 23:18:24 +0300 | [diff] [blame] | 521 | * TWL4030 CHG_PRES (AC charger presence) events |
| 522 | */ |
| 523 | static irqreturn_t twl4030_charger_interrupt(int irq, void *arg) |
| 524 | { |
| 525 | struct twl4030_bci *bci = arg; |
| 526 | |
| 527 | dev_dbg(bci->dev, "CHG_PRES irq\n"); |
NeilBrown | aca3c35 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 528 | /* reset current on each 'plug' event */ |
| 529 | bci->ac_cur = 500000; |
NeilBrown | e4ae537 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 530 | twl4030_charger_update_current(bci); |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 531 | power_supply_changed(bci->ac); |
| 532 | power_supply_changed(bci->usb); |
Grazvydas Ignotas | 2e727f1 | 2010-09-27 23:18:24 +0300 | [diff] [blame] | 533 | |
| 534 | return IRQ_HANDLED; |
| 535 | } |
| 536 | |
| 537 | /* |
| 538 | * TWL4030 BCI monitoring events |
| 539 | */ |
| 540 | static irqreturn_t twl4030_bci_interrupt(int irq, void *arg) |
| 541 | { |
| 542 | struct twl4030_bci *bci = arg; |
| 543 | u8 irqs1, irqs2; |
| 544 | int ret; |
| 545 | |
| 546 | ret = twl_i2c_read_u8(TWL4030_MODULE_INTERRUPTS, &irqs1, |
| 547 | TWL4030_INTERRUPTS_BCIISR1A); |
| 548 | if (ret < 0) |
| 549 | return IRQ_HANDLED; |
| 550 | |
| 551 | ret = twl_i2c_read_u8(TWL4030_MODULE_INTERRUPTS, &irqs2, |
| 552 | TWL4030_INTERRUPTS_BCIISR2A); |
| 553 | if (ret < 0) |
| 554 | return IRQ_HANDLED; |
| 555 | |
| 556 | dev_dbg(bci->dev, "BCI irq %02x %02x\n", irqs2, irqs1); |
| 557 | |
| 558 | if (irqs1 & (TWL4030_ICHGLOW | TWL4030_ICHGEOC)) { |
| 559 | /* charger state change, inform the core */ |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 560 | power_supply_changed(bci->ac); |
| 561 | power_supply_changed(bci->usb); |
Grazvydas Ignotas | 2e727f1 | 2010-09-27 23:18:24 +0300 | [diff] [blame] | 562 | } |
NeilBrown | e4ae537 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 563 | twl4030_charger_update_current(bci); |
Grazvydas Ignotas | 2e727f1 | 2010-09-27 23:18:24 +0300 | [diff] [blame] | 564 | |
| 565 | /* various monitoring events, for now we just log them here */ |
| 566 | if (irqs1 & (TWL4030_TBATOR2 | TWL4030_TBATOR1)) |
| 567 | dev_warn(bci->dev, "battery temperature out of range\n"); |
| 568 | |
| 569 | if (irqs1 & TWL4030_BATSTS) |
| 570 | dev_crit(bci->dev, "battery disconnected\n"); |
| 571 | |
| 572 | if (irqs2 & TWL4030_VBATOV) |
| 573 | dev_crit(bci->dev, "VBAT overvoltage\n"); |
| 574 | |
| 575 | if (irqs2 & TWL4030_VBUSOV) |
| 576 | dev_crit(bci->dev, "VBUS overvoltage\n"); |
| 577 | |
| 578 | if (irqs2 & TWL4030_ACCHGOV) |
| 579 | dev_crit(bci->dev, "Ac charger overvoltage\n"); |
| 580 | |
| 581 | return IRQ_HANDLED; |
| 582 | } |
| 583 | |
NeilBrown | aca3c35 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 584 | /* |
| 585 | * Provide "max_current" attribute in sysfs. |
| 586 | */ |
| 587 | static ssize_t |
| 588 | twl4030_bci_max_current_store(struct device *dev, struct device_attribute *attr, |
| 589 | const char *buf, size_t n) |
| 590 | { |
| 591 | struct twl4030_bci *bci = dev_get_drvdata(dev->parent); |
| 592 | int cur = 0; |
| 593 | int status = 0; |
| 594 | status = kstrtoint(buf, 10, &cur); |
| 595 | if (status) |
| 596 | return status; |
| 597 | if (cur < 0) |
| 598 | return -EINVAL; |
| 599 | if (dev == &bci->ac->dev) |
| 600 | bci->ac_cur = cur; |
| 601 | else |
| 602 | bci->usb_cur = cur; |
| 603 | |
| 604 | twl4030_charger_update_current(bci); |
| 605 | return n; |
| 606 | } |
| 607 | |
| 608 | /* |
| 609 | * sysfs max_current show |
| 610 | */ |
| 611 | static ssize_t twl4030_bci_max_current_show(struct device *dev, |
| 612 | struct device_attribute *attr, char *buf) |
| 613 | { |
| 614 | int status = 0; |
| 615 | int cur = -1; |
| 616 | u8 bcictl1; |
| 617 | struct twl4030_bci *bci = dev_get_drvdata(dev->parent); |
| 618 | |
| 619 | if (dev == &bci->ac->dev) { |
| 620 | if (!bci->ac_is_active) |
| 621 | cur = bci->ac_cur; |
| 622 | } else { |
| 623 | if (bci->ac_is_active) |
| 624 | cur = bci->usb_cur; |
| 625 | } |
| 626 | if (cur < 0) { |
| 627 | cur = twl4030bci_read_adc_val(TWL4030_BCIIREF1); |
| 628 | if (cur < 0) |
| 629 | return cur; |
| 630 | status = twl4030_bci_read(TWL4030_BCICTL1, &bcictl1); |
| 631 | if (status < 0) |
| 632 | return status; |
| 633 | cur = regval2ua(cur, bcictl1 & TWL4030_CGAIN); |
| 634 | } |
| 635 | return scnprintf(buf, PAGE_SIZE, "%u\n", cur); |
| 636 | } |
| 637 | |
| 638 | static DEVICE_ATTR(max_current, 0644, twl4030_bci_max_current_show, |
| 639 | twl4030_bci_max_current_store); |
| 640 | |
Heikki Krogerus | d6ccc44 | 2011-02-25 13:56:36 +0200 | [diff] [blame] | 641 | static void twl4030_bci_usb_work(struct work_struct *data) |
Grazvydas Ignotas | 2e727f1 | 2010-09-27 23:18:24 +0300 | [diff] [blame] | 642 | { |
Heikki Krogerus | d6ccc44 | 2011-02-25 13:56:36 +0200 | [diff] [blame] | 643 | struct twl4030_bci *bci = container_of(data, struct twl4030_bci, work); |
Grazvydas Ignotas | 2e727f1 | 2010-09-27 23:18:24 +0300 | [diff] [blame] | 644 | |
Heikki Krogerus | d6ccc44 | 2011-02-25 13:56:36 +0200 | [diff] [blame] | 645 | switch (bci->event) { |
Grazvydas Ignotas | 2e727f1 | 2010-09-27 23:18:24 +0300 | [diff] [blame] | 646 | case USB_EVENT_VBUS: |
| 647 | case USB_EVENT_CHARGER: |
| 648 | twl4030_charger_enable_usb(bci, true); |
| 649 | break; |
| 650 | case USB_EVENT_NONE: |
| 651 | twl4030_charger_enable_usb(bci, false); |
| 652 | break; |
| 653 | } |
Heikki Krogerus | d6ccc44 | 2011-02-25 13:56:36 +0200 | [diff] [blame] | 654 | } |
| 655 | |
| 656 | static int twl4030_bci_usb_ncb(struct notifier_block *nb, unsigned long val, |
| 657 | void *priv) |
| 658 | { |
Heikki Krogerus | fcc8ebc | 2012-02-13 13:24:16 +0200 | [diff] [blame] | 659 | struct twl4030_bci *bci = container_of(nb, struct twl4030_bci, usb_nb); |
Heikki Krogerus | d6ccc44 | 2011-02-25 13:56:36 +0200 | [diff] [blame] | 660 | |
| 661 | dev_dbg(bci->dev, "OTG notify %lu\n", val); |
| 662 | |
NeilBrown | aca3c35 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 663 | /* reset current on each 'plug' event */ |
| 664 | if (allow_usb) |
| 665 | bci->usb_cur = 500000; |
| 666 | else |
| 667 | bci->usb_cur = 100000; |
| 668 | |
Heikki Krogerus | d6ccc44 | 2011-02-25 13:56:36 +0200 | [diff] [blame] | 669 | bci->event = val; |
| 670 | schedule_work(&bci->work); |
Grazvydas Ignotas | 2e727f1 | 2010-09-27 23:18:24 +0300 | [diff] [blame] | 671 | |
| 672 | return NOTIFY_OK; |
| 673 | } |
| 674 | |
NeilBrown | 22d4c33 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 675 | /* |
| 676 | * sysfs charger enabled store |
| 677 | */ |
| 678 | static ssize_t |
| 679 | twl4030_bci_mode_store(struct device *dev, struct device_attribute *attr, |
| 680 | const char *buf, size_t n) |
| 681 | { |
| 682 | struct twl4030_bci *bci = dev_get_drvdata(dev->parent); |
| 683 | int mode; |
| 684 | int status; |
| 685 | |
| 686 | if (sysfs_streq(buf, modes[0])) |
| 687 | mode = 0; |
| 688 | else if (sysfs_streq(buf, modes[1])) |
| 689 | mode = 1; |
NeilBrown | 7f4a633 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 690 | else if (sysfs_streq(buf, modes[2])) |
| 691 | mode = 2; |
NeilBrown | 22d4c33 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 692 | else |
| 693 | return -EINVAL; |
NeilBrown | b04b908 | 2015-07-30 10:11:24 +1000 | [diff] [blame^] | 694 | if (dev == &bci->ac->dev) { |
| 695 | if (mode == 2) |
| 696 | return -EINVAL; |
| 697 | twl4030_charger_enable_ac(bci, false); |
| 698 | bci->ac_mode = mode; |
| 699 | status = twl4030_charger_enable_ac(bci, true); |
| 700 | } else { |
| 701 | twl4030_charger_enable_usb(bci, false); |
| 702 | bci->usb_mode = mode; |
| 703 | status = twl4030_charger_enable_usb(bci, true); |
| 704 | } |
NeilBrown | 22d4c33 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 705 | return (status == 0) ? n : status; |
| 706 | } |
| 707 | |
| 708 | /* |
| 709 | * sysfs charger enabled show |
| 710 | */ |
| 711 | static ssize_t |
| 712 | twl4030_bci_mode_show(struct device *dev, |
| 713 | struct device_attribute *attr, char *buf) |
| 714 | { |
| 715 | struct twl4030_bci *bci = dev_get_drvdata(dev->parent); |
| 716 | int len = 0; |
| 717 | int i; |
NeilBrown | b04b908 | 2015-07-30 10:11:24 +1000 | [diff] [blame^] | 718 | int mode = bci->usb_mode; |
| 719 | |
| 720 | if (dev == &bci->ac->dev) |
| 721 | mode = bci->ac_mode; |
NeilBrown | 22d4c33 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 722 | |
| 723 | for (i = 0; i < ARRAY_SIZE(modes); i++) |
NeilBrown | b04b908 | 2015-07-30 10:11:24 +1000 | [diff] [blame^] | 724 | if (mode == i) |
NeilBrown | 22d4c33 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 725 | len += snprintf(buf+len, PAGE_SIZE-len, |
| 726 | "[%s] ", modes[i]); |
| 727 | else |
| 728 | len += snprintf(buf+len, PAGE_SIZE-len, |
| 729 | "%s ", modes[i]); |
| 730 | buf[len-1] = '\n'; |
| 731 | return len; |
| 732 | } |
| 733 | static DEVICE_ATTR(mode, 0644, twl4030_bci_mode_show, |
| 734 | twl4030_bci_mode_store); |
| 735 | |
Grazvydas Ignotas | 2e727f1 | 2010-09-27 23:18:24 +0300 | [diff] [blame] | 736 | static int twl4030_charger_get_current(void) |
| 737 | { |
| 738 | int curr; |
| 739 | int ret; |
| 740 | u8 bcictl1; |
| 741 | |
| 742 | curr = twl4030bci_read_adc_val(TWL4030_BCIICHG); |
| 743 | if (curr < 0) |
| 744 | return curr; |
| 745 | |
| 746 | ret = twl4030_bci_read(TWL4030_BCICTL1, &bcictl1); |
| 747 | if (ret) |
| 748 | return ret; |
| 749 | |
NeilBrown | 3b542f0 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 750 | return regval2ua(curr, bcictl1 & TWL4030_CGAIN); |
Grazvydas Ignotas | 2e727f1 | 2010-09-27 23:18:24 +0300 | [diff] [blame] | 751 | } |
| 752 | |
| 753 | /* |
| 754 | * Returns the main charge FSM state |
| 755 | * Or < 0 on failure. |
| 756 | */ |
| 757 | static int twl4030bci_state(struct twl4030_bci *bci) |
| 758 | { |
| 759 | int ret; |
| 760 | u8 state; |
| 761 | |
| 762 | ret = twl4030_bci_read(TWL4030_BCIMSTATEC, &state); |
| 763 | if (ret) { |
| 764 | pr_err("twl4030_bci: error reading BCIMSTATEC\n"); |
| 765 | return ret; |
| 766 | } |
| 767 | |
| 768 | dev_dbg(bci->dev, "state: %02x\n", state); |
| 769 | |
| 770 | return state; |
| 771 | } |
| 772 | |
| 773 | static int twl4030_bci_state_to_status(int state) |
| 774 | { |
| 775 | state &= TWL4030_MSTATEC_MASK; |
| 776 | if (TWL4030_MSTATEC_QUICK1 <= state && state <= TWL4030_MSTATEC_QUICK7) |
| 777 | return POWER_SUPPLY_STATUS_CHARGING; |
| 778 | else if (TWL4030_MSTATEC_COMPLETE1 <= state && |
| 779 | state <= TWL4030_MSTATEC_COMPLETE4) |
| 780 | return POWER_SUPPLY_STATUS_FULL; |
| 781 | else |
| 782 | return POWER_SUPPLY_STATUS_NOT_CHARGING; |
| 783 | } |
| 784 | |
| 785 | static int twl4030_bci_get_property(struct power_supply *psy, |
| 786 | enum power_supply_property psp, |
| 787 | union power_supply_propval *val) |
| 788 | { |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 789 | struct twl4030_bci *bci = dev_get_drvdata(psy->dev.parent); |
Grazvydas Ignotas | 2e727f1 | 2010-09-27 23:18:24 +0300 | [diff] [blame] | 790 | int is_charging; |
| 791 | int state; |
| 792 | int ret; |
| 793 | |
| 794 | state = twl4030bci_state(bci); |
| 795 | if (state < 0) |
| 796 | return state; |
| 797 | |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 798 | if (psy->desc->type == POWER_SUPPLY_TYPE_USB) |
Grazvydas Ignotas | 2e727f1 | 2010-09-27 23:18:24 +0300 | [diff] [blame] | 799 | is_charging = state & TWL4030_MSTATEC_USB; |
| 800 | else |
| 801 | is_charging = state & TWL4030_MSTATEC_AC; |
NeilBrown | 7f4a633 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 802 | if (!is_charging) { |
| 803 | u8 s; |
| 804 | twl4030_bci_read(TWL4030_BCIMDEN, &s); |
| 805 | if (psy->desc->type == POWER_SUPPLY_TYPE_USB) |
| 806 | is_charging = s & 1; |
| 807 | else |
| 808 | is_charging = s & 2; |
| 809 | if (is_charging) |
| 810 | /* A little white lie */ |
| 811 | state = TWL4030_MSTATEC_QUICK1; |
| 812 | } |
Grazvydas Ignotas | 2e727f1 | 2010-09-27 23:18:24 +0300 | [diff] [blame] | 813 | |
| 814 | switch (psp) { |
| 815 | case POWER_SUPPLY_PROP_STATUS: |
| 816 | if (is_charging) |
| 817 | val->intval = twl4030_bci_state_to_status(state); |
| 818 | else |
| 819 | val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING; |
| 820 | break; |
| 821 | case POWER_SUPPLY_PROP_VOLTAGE_NOW: |
| 822 | /* charging must be active for meaningful result */ |
| 823 | if (!is_charging) |
| 824 | return -ENODATA; |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 825 | if (psy->desc->type == POWER_SUPPLY_TYPE_USB) { |
Grazvydas Ignotas | 2e727f1 | 2010-09-27 23:18:24 +0300 | [diff] [blame] | 826 | ret = twl4030bci_read_adc_val(TWL4030_BCIVBUS); |
| 827 | if (ret < 0) |
| 828 | return ret; |
| 829 | /* BCIVBUS uses ADCIN8, 7/1023 V/step */ |
| 830 | val->intval = ret * 6843; |
| 831 | } else { |
| 832 | ret = twl4030bci_read_adc_val(TWL4030_BCIVAC); |
| 833 | if (ret < 0) |
| 834 | return ret; |
| 835 | /* BCIVAC uses ADCIN11, 10/1023 V/step */ |
| 836 | val->intval = ret * 9775; |
| 837 | } |
| 838 | break; |
| 839 | case POWER_SUPPLY_PROP_CURRENT_NOW: |
| 840 | if (!is_charging) |
| 841 | return -ENODATA; |
| 842 | /* current measurement is shared between AC and USB */ |
| 843 | ret = twl4030_charger_get_current(); |
| 844 | if (ret < 0) |
| 845 | return ret; |
| 846 | val->intval = ret; |
| 847 | break; |
| 848 | case POWER_SUPPLY_PROP_ONLINE: |
| 849 | val->intval = is_charging && |
| 850 | twl4030_bci_state_to_status(state) != |
| 851 | POWER_SUPPLY_STATUS_NOT_CHARGING; |
| 852 | break; |
| 853 | default: |
| 854 | return -EINVAL; |
| 855 | } |
| 856 | |
| 857 | return 0; |
| 858 | } |
| 859 | |
| 860 | static enum power_supply_property twl4030_charger_props[] = { |
| 861 | POWER_SUPPLY_PROP_STATUS, |
| 862 | POWER_SUPPLY_PROP_ONLINE, |
| 863 | POWER_SUPPLY_PROP_VOLTAGE_NOW, |
| 864 | POWER_SUPPLY_PROP_CURRENT_NOW, |
| 865 | }; |
| 866 | |
NeilBrown | ec0b380 | 2013-10-31 17:05:50 +1100 | [diff] [blame] | 867 | #ifdef CONFIG_OF |
| 868 | static const struct twl4030_bci_platform_data * |
| 869 | twl4030_bci_parse_dt(struct device *dev) |
| 870 | { |
| 871 | struct device_node *np = dev->of_node; |
| 872 | struct twl4030_bci_platform_data *pdata; |
| 873 | u32 num; |
| 874 | |
| 875 | if (!np) |
| 876 | return NULL; |
| 877 | pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); |
| 878 | if (!pdata) |
| 879 | return pdata; |
| 880 | |
| 881 | if (of_property_read_u32(np, "ti,bb-uvolt", &num) == 0) |
| 882 | pdata->bb_uvolt = num; |
| 883 | if (of_property_read_u32(np, "ti,bb-uamp", &num) == 0) |
| 884 | pdata->bb_uamp = num; |
| 885 | return pdata; |
| 886 | } |
| 887 | #else |
| 888 | static inline const struct twl4030_bci_platform_data * |
| 889 | twl4030_bci_parse_dt(struct device *dev) |
| 890 | { |
| 891 | return NULL; |
| 892 | } |
| 893 | #endif |
| 894 | |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 895 | static const struct power_supply_desc twl4030_bci_ac_desc = { |
| 896 | .name = "twl4030_ac", |
| 897 | .type = POWER_SUPPLY_TYPE_MAINS, |
| 898 | .properties = twl4030_charger_props, |
| 899 | .num_properties = ARRAY_SIZE(twl4030_charger_props), |
| 900 | .get_property = twl4030_bci_get_property, |
| 901 | }; |
| 902 | |
| 903 | static const struct power_supply_desc twl4030_bci_usb_desc = { |
| 904 | .name = "twl4030_usb", |
| 905 | .type = POWER_SUPPLY_TYPE_USB, |
| 906 | .properties = twl4030_charger_props, |
| 907 | .num_properties = ARRAY_SIZE(twl4030_charger_props), |
| 908 | .get_property = twl4030_bci_get_property, |
| 909 | }; |
| 910 | |
Pavel Machek | 7396f70 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 911 | static int twl4030_bci_probe(struct platform_device *pdev) |
Grazvydas Ignotas | 2e727f1 | 2010-09-27 23:18:24 +0300 | [diff] [blame] | 912 | { |
| 913 | struct twl4030_bci *bci; |
NeilBrown | ec0b380 | 2013-10-31 17:05:50 +1100 | [diff] [blame] | 914 | const struct twl4030_bci_platform_data *pdata = pdev->dev.platform_data; |
Grazvydas Ignotas | 2e727f1 | 2010-09-27 23:18:24 +0300 | [diff] [blame] | 915 | int ret; |
Grazvydas Ignotas | 28d48f0 | 2011-06-03 14:43:11 +0300 | [diff] [blame] | 916 | u32 reg; |
Grazvydas Ignotas | 2e727f1 | 2010-09-27 23:18:24 +0300 | [diff] [blame] | 917 | |
NeilBrown | 325b50a | 2015-03-23 10:20:28 +1100 | [diff] [blame] | 918 | bci = devm_kzalloc(&pdev->dev, sizeof(*bci), GFP_KERNEL); |
Grazvydas Ignotas | 2e727f1 | 2010-09-27 23:18:24 +0300 | [diff] [blame] | 919 | if (bci == NULL) |
| 920 | return -ENOMEM; |
| 921 | |
NeilBrown | ec0b380 | 2013-10-31 17:05:50 +1100 | [diff] [blame] | 922 | if (!pdata) |
| 923 | pdata = twl4030_bci_parse_dt(&pdev->dev); |
| 924 | |
NeilBrown | 1098cb5 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 925 | bci->ichg_eoc = 80100; /* Stop charging when current drops to here */ |
| 926 | bci->ichg_lo = 241000; /* Low threshold */ |
| 927 | bci->ichg_hi = 500000; /* High threshold */ |
NeilBrown | e4ae537 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 928 | bci->ac_cur = 500000; /* 500mA */ |
NeilBrown | 1098cb5 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 929 | if (allow_usb) |
NeilBrown | e4ae537 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 930 | bci->usb_cur = 500000; /* 500mA */ |
NeilBrown | 1098cb5 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 931 | else |
NeilBrown | e4ae537 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 932 | bci->usb_cur = 100000; /* 100mA */ |
NeilBrown | 22d4c33 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 933 | bci->usb_mode = CHARGE_AUTO; |
NeilBrown | b04b908 | 2015-07-30 10:11:24 +1000 | [diff] [blame^] | 934 | bci->ac_mode = CHARGE_AUTO; |
NeilBrown | 1098cb5 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 935 | |
Grazvydas Ignotas | 2e727f1 | 2010-09-27 23:18:24 +0300 | [diff] [blame] | 936 | bci->dev = &pdev->dev; |
| 937 | bci->irq_chg = platform_get_irq(pdev, 0); |
| 938 | bci->irq_bci = platform_get_irq(pdev, 1); |
| 939 | |
Nishanth Menon | 61a7784 | 2014-05-28 16:46:49 -0500 | [diff] [blame] | 940 | /* Only proceed further *IF* battery is physically present */ |
| 941 | ret = twl4030_is_battery_present(bci); |
| 942 | if (ret) { |
| 943 | dev_crit(&pdev->dev, "Battery was not detected:%d\n", ret); |
NeilBrown | 325b50a | 2015-03-23 10:20:28 +1100 | [diff] [blame] | 944 | return ret; |
Nishanth Menon | 61a7784 | 2014-05-28 16:46:49 -0500 | [diff] [blame] | 945 | } |
Grazvydas Ignotas | 2e727f1 | 2010-09-27 23:18:24 +0300 | [diff] [blame] | 946 | |
Nishanth Menon | 61a7784 | 2014-05-28 16:46:49 -0500 | [diff] [blame] | 947 | platform_set_drvdata(pdev, bci); |
Grazvydas Ignotas | 2e727f1 | 2010-09-27 23:18:24 +0300 | [diff] [blame] | 948 | |
NeilBrown | 325b50a | 2015-03-23 10:20:28 +1100 | [diff] [blame] | 949 | bci->ac = devm_power_supply_register(&pdev->dev, &twl4030_bci_ac_desc, |
| 950 | NULL); |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 951 | if (IS_ERR(bci->ac)) { |
| 952 | ret = PTR_ERR(bci->ac); |
Grazvydas Ignotas | 2e727f1 | 2010-09-27 23:18:24 +0300 | [diff] [blame] | 953 | dev_err(&pdev->dev, "failed to register ac: %d\n", ret); |
NeilBrown | 325b50a | 2015-03-23 10:20:28 +1100 | [diff] [blame] | 954 | return ret; |
Grazvydas Ignotas | 2e727f1 | 2010-09-27 23:18:24 +0300 | [diff] [blame] | 955 | } |
| 956 | |
NeilBrown | 325b50a | 2015-03-23 10:20:28 +1100 | [diff] [blame] | 957 | bci->usb = devm_power_supply_register(&pdev->dev, &twl4030_bci_usb_desc, |
| 958 | NULL); |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 959 | if (IS_ERR(bci->usb)) { |
| 960 | ret = PTR_ERR(bci->usb); |
Grazvydas Ignotas | 2e727f1 | 2010-09-27 23:18:24 +0300 | [diff] [blame] | 961 | dev_err(&pdev->dev, "failed to register usb: %d\n", ret); |
NeilBrown | 325b50a | 2015-03-23 10:20:28 +1100 | [diff] [blame] | 962 | return ret; |
Grazvydas Ignotas | 2e727f1 | 2010-09-27 23:18:24 +0300 | [diff] [blame] | 963 | } |
| 964 | |
NeilBrown | 1b7cac2 | 2015-03-23 10:20:28 +1100 | [diff] [blame] | 965 | ret = devm_request_threaded_irq(&pdev->dev, bci->irq_chg, NULL, |
Fengguang Wu | a2778b0 | 2012-08-23 19:56:43 +0800 | [diff] [blame] | 966 | twl4030_charger_interrupt, IRQF_ONESHOT, pdev->name, |
| 967 | bci); |
Grazvydas Ignotas | 2e727f1 | 2010-09-27 23:18:24 +0300 | [diff] [blame] | 968 | if (ret < 0) { |
| 969 | dev_err(&pdev->dev, "could not request irq %d, status %d\n", |
| 970 | bci->irq_chg, ret); |
NeilBrown | 325b50a | 2015-03-23 10:20:28 +1100 | [diff] [blame] | 971 | return ret; |
Grazvydas Ignotas | 2e727f1 | 2010-09-27 23:18:24 +0300 | [diff] [blame] | 972 | } |
| 973 | |
NeilBrown | 1b7cac2 | 2015-03-23 10:20:28 +1100 | [diff] [blame] | 974 | ret = devm_request_threaded_irq(&pdev->dev, bci->irq_bci, NULL, |
Fengguang Wu | a2778b0 | 2012-08-23 19:56:43 +0800 | [diff] [blame] | 975 | twl4030_bci_interrupt, IRQF_ONESHOT, pdev->name, bci); |
Grazvydas Ignotas | 2e727f1 | 2010-09-27 23:18:24 +0300 | [diff] [blame] | 976 | if (ret < 0) { |
| 977 | dev_err(&pdev->dev, "could not request irq %d, status %d\n", |
| 978 | bci->irq_bci, ret); |
NeilBrown | 325b50a | 2015-03-23 10:20:28 +1100 | [diff] [blame] | 979 | return ret; |
Grazvydas Ignotas | 2e727f1 | 2010-09-27 23:18:24 +0300 | [diff] [blame] | 980 | } |
| 981 | |
Heikki Krogerus | d6ccc44 | 2011-02-25 13:56:36 +0200 | [diff] [blame] | 982 | INIT_WORK(&bci->work, twl4030_bci_usb_work); |
| 983 | |
NeilBrown | f5e4edb | 2015-03-23 09:52:48 +1100 | [diff] [blame] | 984 | bci->usb_nb.notifier_call = twl4030_bci_usb_ncb; |
| 985 | if (bci->dev->of_node) { |
| 986 | struct device_node *phynode; |
| 987 | |
| 988 | phynode = of_find_compatible_node(bci->dev->of_node->parent, |
| 989 | NULL, "ti,twl4030-usb"); |
NeilBrown | 3fc3895 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 990 | if (phynode) { |
NeilBrown | f5e4edb | 2015-03-23 09:52:48 +1100 | [diff] [blame] | 991 | bci->transceiver = devm_usb_get_phy_by_node( |
| 992 | bci->dev, phynode, &bci->usb_nb); |
NeilBrown | 3fc3895 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 993 | if (IS_ERR(bci->transceiver) && |
| 994 | PTR_ERR(bci->transceiver) == -EPROBE_DEFER) |
| 995 | return -EPROBE_DEFER; |
| 996 | } |
Grazvydas Ignotas | 2e727f1 | 2010-09-27 23:18:24 +0300 | [diff] [blame] | 997 | } |
| 998 | |
| 999 | /* Enable interrupts now. */ |
Grazvydas Ignotas | 28d48f0 | 2011-06-03 14:43:11 +0300 | [diff] [blame] | 1000 | reg = ~(u32)(TWL4030_ICHGLOW | TWL4030_ICHGEOC | TWL4030_TBATOR2 | |
Grazvydas Ignotas | 2e727f1 | 2010-09-27 23:18:24 +0300 | [diff] [blame] | 1001 | TWL4030_TBATOR1 | TWL4030_BATSTS); |
| 1002 | ret = twl_i2c_write_u8(TWL4030_MODULE_INTERRUPTS, reg, |
| 1003 | TWL4030_INTERRUPTS_BCIIMR1A); |
| 1004 | if (ret < 0) { |
| 1005 | dev_err(&pdev->dev, "failed to unmask interrupts: %d\n", ret); |
NeilBrown | 325b50a | 2015-03-23 10:20:28 +1100 | [diff] [blame] | 1006 | return ret; |
Grazvydas Ignotas | 2e727f1 | 2010-09-27 23:18:24 +0300 | [diff] [blame] | 1007 | } |
| 1008 | |
Grazvydas Ignotas | 28d48f0 | 2011-06-03 14:43:11 +0300 | [diff] [blame] | 1009 | reg = ~(u32)(TWL4030_VBATOV | TWL4030_VBUSOV | TWL4030_ACCHGOV); |
Grazvydas Ignotas | 2e727f1 | 2010-09-27 23:18:24 +0300 | [diff] [blame] | 1010 | ret = twl_i2c_write_u8(TWL4030_MODULE_INTERRUPTS, reg, |
| 1011 | TWL4030_INTERRUPTS_BCIIMR2A); |
| 1012 | if (ret < 0) |
| 1013 | dev_warn(&pdev->dev, "failed to unmask interrupts: %d\n", ret); |
| 1014 | |
NeilBrown | 1098cb5 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 1015 | twl4030_charger_update_current(bci); |
NeilBrown | aca3c35 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 1016 | if (device_create_file(&bci->usb->dev, &dev_attr_max_current)) |
| 1017 | dev_warn(&pdev->dev, "could not create sysfs file\n"); |
NeilBrown | 22d4c33 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 1018 | if (device_create_file(&bci->usb->dev, &dev_attr_mode)) |
| 1019 | dev_warn(&pdev->dev, "could not create sysfs file\n"); |
NeilBrown | b04b908 | 2015-07-30 10:11:24 +1000 | [diff] [blame^] | 1020 | if (device_create_file(&bci->ac->dev, &dev_attr_mode)) |
| 1021 | dev_warn(&pdev->dev, "could not create sysfs file\n"); |
NeilBrown | aca3c35 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 1022 | if (device_create_file(&bci->ac->dev, &dev_attr_max_current)) |
| 1023 | dev_warn(&pdev->dev, "could not create sysfs file\n"); |
| 1024 | |
NeilBrown | b04b908 | 2015-07-30 10:11:24 +1000 | [diff] [blame^] | 1025 | twl4030_charger_enable_ac(bci, true); |
NeilBrown | 6e37ec8 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 1026 | if (!IS_ERR_OR_NULL(bci->transceiver)) |
| 1027 | twl4030_bci_usb_ncb(&bci->usb_nb, |
| 1028 | bci->transceiver->last_event, |
| 1029 | NULL); |
| 1030 | else |
| 1031 | twl4030_charger_enable_usb(bci, false); |
NeilBrown | ec0b380 | 2013-10-31 17:05:50 +1100 | [diff] [blame] | 1032 | if (pdata) |
| 1033 | twl4030_charger_enable_backup(pdata->bb_uvolt, |
| 1034 | pdata->bb_uamp); |
| 1035 | else |
| 1036 | twl4030_charger_enable_backup(0, 0); |
Grazvydas Ignotas | 2e727f1 | 2010-09-27 23:18:24 +0300 | [diff] [blame] | 1037 | |
| 1038 | return 0; |
Grazvydas Ignotas | 2e727f1 | 2010-09-27 23:18:24 +0300 | [diff] [blame] | 1039 | } |
| 1040 | |
| 1041 | static int __exit twl4030_bci_remove(struct platform_device *pdev) |
| 1042 | { |
| 1043 | struct twl4030_bci *bci = platform_get_drvdata(pdev); |
| 1044 | |
NeilBrown | b04b908 | 2015-07-30 10:11:24 +1000 | [diff] [blame^] | 1045 | twl4030_charger_enable_ac(bci, false); |
Grazvydas Ignotas | 2e727f1 | 2010-09-27 23:18:24 +0300 | [diff] [blame] | 1046 | twl4030_charger_enable_usb(bci, false); |
NeilBrown | 210d4bc | 2012-05-09 07:40:40 +1000 | [diff] [blame] | 1047 | twl4030_charger_enable_backup(0, 0); |
Grazvydas Ignotas | 2e727f1 | 2010-09-27 23:18:24 +0300 | [diff] [blame] | 1048 | |
NeilBrown | aca3c35 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 1049 | device_remove_file(&bci->usb->dev, &dev_attr_max_current); |
NeilBrown | 22d4c33 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 1050 | device_remove_file(&bci->usb->dev, &dev_attr_mode); |
NeilBrown | aca3c35 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 1051 | device_remove_file(&bci->ac->dev, &dev_attr_max_current); |
NeilBrown | b04b908 | 2015-07-30 10:11:24 +1000 | [diff] [blame^] | 1052 | device_remove_file(&bci->ac->dev, &dev_attr_mode); |
Grazvydas Ignotas | 2e727f1 | 2010-09-27 23:18:24 +0300 | [diff] [blame] | 1053 | /* mask interrupts */ |
| 1054 | twl_i2c_write_u8(TWL4030_MODULE_INTERRUPTS, 0xff, |
| 1055 | TWL4030_INTERRUPTS_BCIIMR1A); |
| 1056 | twl_i2c_write_u8(TWL4030_MODULE_INTERRUPTS, 0xff, |
| 1057 | TWL4030_INTERRUPTS_BCIIMR2A); |
| 1058 | |
Grazvydas Ignotas | 2e727f1 | 2010-09-27 23:18:24 +0300 | [diff] [blame] | 1059 | return 0; |
| 1060 | } |
| 1061 | |
NeilBrown | ec0b380 | 2013-10-31 17:05:50 +1100 | [diff] [blame] | 1062 | static const struct of_device_id twl_bci_of_match[] = { |
| 1063 | {.compatible = "ti,twl4030-bci", }, |
| 1064 | { } |
| 1065 | }; |
| 1066 | MODULE_DEVICE_TABLE(of, twl_bci_of_match); |
| 1067 | |
Grazvydas Ignotas | 2e727f1 | 2010-09-27 23:18:24 +0300 | [diff] [blame] | 1068 | static struct platform_driver twl4030_bci_driver = { |
Pavel Machek | 7396f70 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 1069 | .probe = twl4030_bci_probe, |
Grazvydas Ignotas | 2e727f1 | 2010-09-27 23:18:24 +0300 | [diff] [blame] | 1070 | .driver = { |
| 1071 | .name = "twl4030_bci", |
NeilBrown | ec0b380 | 2013-10-31 17:05:50 +1100 | [diff] [blame] | 1072 | .of_match_table = of_match_ptr(twl_bci_of_match), |
Grazvydas Ignotas | 2e727f1 | 2010-09-27 23:18:24 +0300 | [diff] [blame] | 1073 | }, |
| 1074 | .remove = __exit_p(twl4030_bci_remove), |
| 1075 | }; |
Pavel Machek | 7396f70 | 2015-07-30 10:11:24 +1000 | [diff] [blame] | 1076 | module_platform_driver(twl4030_bci_driver); |
Grazvydas Ignotas | 2e727f1 | 2010-09-27 23:18:24 +0300 | [diff] [blame] | 1077 | |
Grazvydas Ignotas | 28d48f0 | 2011-06-03 14:43:11 +0300 | [diff] [blame] | 1078 | MODULE_AUTHOR("Gražvydas Ignotas"); |
Grazvydas Ignotas | 2e727f1 | 2010-09-27 23:18:24 +0300 | [diff] [blame] | 1079 | MODULE_DESCRIPTION("TWL4030 Battery Charger Interface driver"); |
| 1080 | MODULE_LICENSE("GPL"); |
| 1081 | MODULE_ALIAS("platform:twl4030_bci"); |