Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 1 | /* |
Kim, Milo | f7bae49 | 2012-01-26 22:59:08 -0800 | [diff] [blame] | 2 | * Driver for LP8727 Micro/Mini USB IC with integrated charger |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 3 | * |
Kim, Milo | e39b828 | 2012-01-29 17:28:18 -0800 | [diff] [blame] | 4 | * Copyright (C) 2011 Texas Instruments |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 5 | * Copyright (C) 2011 National Semiconductor |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License version 2 as |
| 9 | * published by the Free Software Foundation. |
| 10 | * |
| 11 | */ |
| 12 | |
| 13 | #include <linux/module.h> |
| 14 | #include <linux/slab.h> |
| 15 | #include <linux/interrupt.h> |
| 16 | #include <linux/i2c.h> |
| 17 | #include <linux/power_supply.h> |
Kim, Milo | 1aebb09 | 2012-07-03 01:19:03 +0000 | [diff] [blame] | 18 | #include <linux/platform_data/lp8727.h> |
Kim, Milo | 17b4565 | 2013-05-10 07:17:51 +0000 | [diff] [blame] | 19 | #include <linux/of.h> |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 20 | |
Kim, Milo | 638555d | 2012-08-31 09:24:09 +0000 | [diff] [blame] | 21 | #define LP8788_NUM_INTREGS 2 |
Kim, Milo | 60fd57e | 2012-08-31 09:23:25 +0000 | [diff] [blame] | 22 | #define DEFAULT_DEBOUNCE_MSEC 270 |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 23 | |
| 24 | /* Registers */ |
Kim, Milo | 6029719 | 2012-08-31 09:24:51 +0000 | [diff] [blame] | 25 | #define LP8727_CTRL1 0x1 |
| 26 | #define LP8727_CTRL2 0x2 |
| 27 | #define LP8727_SWCTRL 0x3 |
| 28 | #define LP8727_INT1 0x4 |
| 29 | #define LP8727_INT2 0x5 |
| 30 | #define LP8727_STATUS1 0x6 |
| 31 | #define LP8727_STATUS2 0x7 |
| 32 | #define LP8727_CHGCTRL2 0x9 |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 33 | |
| 34 | /* CTRL1 register */ |
Kim, Milo | 6029719 | 2012-08-31 09:24:51 +0000 | [diff] [blame] | 35 | #define LP8727_CP_EN BIT(0) |
| 36 | #define LP8727_ADC_EN BIT(1) |
| 37 | #define LP8727_ID200_EN BIT(4) |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 38 | |
| 39 | /* CTRL2 register */ |
Kim, Milo | 6029719 | 2012-08-31 09:24:51 +0000 | [diff] [blame] | 40 | #define LP8727_CHGDET_EN BIT(1) |
| 41 | #define LP8727_INT_EN BIT(6) |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 42 | |
| 43 | /* SWCTRL register */ |
Kim, Milo | 6029719 | 2012-08-31 09:24:51 +0000 | [diff] [blame] | 44 | #define LP8727_SW_DM1_DM (0x0 << 0) |
| 45 | #define LP8727_SW_DM1_HiZ (0x7 << 0) |
| 46 | #define LP8727_SW_DP2_DP (0x0 << 3) |
| 47 | #define LP8727_SW_DP2_HiZ (0x7 << 3) |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 48 | |
| 49 | /* INT1 register */ |
Kim, Milo | 6029719 | 2012-08-31 09:24:51 +0000 | [diff] [blame] | 50 | #define LP8727_IDNO (0xF << 0) |
| 51 | #define LP8727_VBUS BIT(4) |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 52 | |
| 53 | /* STATUS1 register */ |
Kim, Milo | 6029719 | 2012-08-31 09:24:51 +0000 | [diff] [blame] | 54 | #define LP8727_CHGSTAT (3 << 4) |
| 55 | #define LP8727_CHPORT BIT(6) |
| 56 | #define LP8727_DCPORT BIT(7) |
| 57 | #define LP8727_STAT_EOC 0x30 |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 58 | |
| 59 | /* STATUS2 register */ |
Kim, Milo | 6029719 | 2012-08-31 09:24:51 +0000 | [diff] [blame] | 60 | #define LP8727_TEMP_STAT (3 << 5) |
| 61 | #define LP8727_TEMP_SHIFT 5 |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 62 | |
Kim, Milo | 18763a3 | 2012-08-31 09:25:07 +0000 | [diff] [blame] | 63 | /* CHGCTRL2 register */ |
| 64 | #define LP8727_ICHG_SHIFT 4 |
| 65 | |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 66 | enum lp8727_dev_id { |
Kim, Milo | 6029719 | 2012-08-31 09:24:51 +0000 | [diff] [blame] | 67 | LP8727_ID_NONE, |
| 68 | LP8727_ID_TA, |
| 69 | LP8727_ID_DEDICATED_CHG, |
| 70 | LP8727_ID_USB_CHG, |
| 71 | LP8727_ID_USB_DS, |
| 72 | LP8727_ID_MAX, |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 73 | }; |
| 74 | |
Kim, Milo | b1ad079 | 2012-08-31 09:24:28 +0000 | [diff] [blame] | 75 | enum lp8727_die_temp { |
| 76 | LP8788_TEMP_75C, |
| 77 | LP8788_TEMP_95C, |
| 78 | LP8788_TEMP_115C, |
| 79 | LP8788_TEMP_135C, |
| 80 | }; |
| 81 | |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 82 | struct lp8727_psy { |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 83 | struct power_supply *ac; |
| 84 | struct power_supply *usb; |
| 85 | struct power_supply *batt; |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 86 | }; |
| 87 | |
| 88 | struct lp8727_chg { |
| 89 | struct device *dev; |
| 90 | struct i2c_client *client; |
| 91 | struct mutex xfer_lock; |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 92 | struct lp8727_psy *psy; |
Kim, Milo | 1ae9df7 | 2012-08-31 09:27:04 +0000 | [diff] [blame] | 93 | struct lp8727_platform_data *pdata; |
| 94 | |
| 95 | /* Charger Data */ |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 96 | enum lp8727_dev_id devid; |
Kim, Milo | 1ae9df7 | 2012-08-31 09:27:04 +0000 | [diff] [blame] | 97 | struct lp8727_chg_param *chg_param; |
| 98 | |
| 99 | /* Interrupt Handling */ |
Kim, Milo | d71fda0 | 2012-08-31 09:23:57 +0000 | [diff] [blame] | 100 | int irq; |
Kim, Milo | 1ae9df7 | 2012-08-31 09:27:04 +0000 | [diff] [blame] | 101 | struct delayed_work work; |
| 102 | unsigned long debounce_jiffies; |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 103 | }; |
| 104 | |
Kim, Milo | 27aefa3 | 2012-01-26 22:58:39 -0800 | [diff] [blame] | 105 | static int lp8727_read_bytes(struct lp8727_chg *pchg, u8 reg, u8 *data, u8 len) |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 106 | { |
| 107 | s32 ret; |
| 108 | |
| 109 | mutex_lock(&pchg->xfer_lock); |
| 110 | ret = i2c_smbus_read_i2c_block_data(pchg->client, reg, len, data); |
| 111 | mutex_unlock(&pchg->xfer_lock); |
| 112 | |
| 113 | return (ret != len) ? -EIO : 0; |
| 114 | } |
| 115 | |
Kim, Milo | 27aefa3 | 2012-01-26 22:58:39 -0800 | [diff] [blame] | 116 | static inline int lp8727_read_byte(struct lp8727_chg *pchg, u8 reg, u8 *data) |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 117 | { |
Kim, Milo | 27aefa3 | 2012-01-26 22:58:39 -0800 | [diff] [blame] | 118 | return lp8727_read_bytes(pchg, reg, data, 1); |
| 119 | } |
| 120 | |
| 121 | static int lp8727_write_byte(struct lp8727_chg *pchg, u8 reg, u8 data) |
| 122 | { |
| 123 | int ret; |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 124 | |
| 125 | mutex_lock(&pchg->xfer_lock); |
Kim, Milo | 27aefa3 | 2012-01-26 22:58:39 -0800 | [diff] [blame] | 126 | ret = i2c_smbus_write_byte_data(pchg->client, reg, data); |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 127 | mutex_unlock(&pchg->xfer_lock); |
| 128 | |
| 129 | return ret; |
| 130 | } |
| 131 | |
Kim, Milo | 65272ba | 2012-08-31 09:25:22 +0000 | [diff] [blame] | 132 | static bool lp8727_is_charger_attached(const char *name, int id) |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 133 | { |
Kim, Milo | 65272ba | 2012-08-31 09:25:22 +0000 | [diff] [blame] | 134 | if (!strcmp(name, "ac")) |
| 135 | return id == LP8727_ID_TA || id == LP8727_ID_DEDICATED_CHG; |
| 136 | else if (!strcmp(name, "usb")) |
| 137 | return id == LP8727_ID_USB_CHG; |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 138 | |
Kim, Milo | 65272ba | 2012-08-31 09:25:22 +0000 | [diff] [blame] | 139 | return id >= LP8727_ID_TA && id <= LP8727_ID_USB_CHG; |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 140 | } |
| 141 | |
Kim, Milo | 7da6334 | 2012-01-26 22:58:30 -0800 | [diff] [blame] | 142 | static int lp8727_init_device(struct lp8727_chg *pchg) |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 143 | { |
| 144 | u8 val; |
Kim, Milo | 7da6334 | 2012-01-26 22:58:30 -0800 | [diff] [blame] | 145 | int ret; |
Kim, Milo | 638555d | 2012-08-31 09:24:09 +0000 | [diff] [blame] | 146 | u8 intstat[LP8788_NUM_INTREGS]; |
| 147 | |
| 148 | /* clear interrupts */ |
Kim, Milo | 6029719 | 2012-08-31 09:24:51 +0000 | [diff] [blame] | 149 | ret = lp8727_read_bytes(pchg, LP8727_INT1, intstat, LP8788_NUM_INTREGS); |
Kim, Milo | 638555d | 2012-08-31 09:24:09 +0000 | [diff] [blame] | 150 | if (ret) |
| 151 | return ret; |
| 152 | |
Kim, Milo | 6029719 | 2012-08-31 09:24:51 +0000 | [diff] [blame] | 153 | val = LP8727_ID200_EN | LP8727_ADC_EN | LP8727_CP_EN; |
| 154 | ret = lp8727_write_byte(pchg, LP8727_CTRL1, val); |
Kim, Milo | 7da6334 | 2012-01-26 22:58:30 -0800 | [diff] [blame] | 155 | if (ret) |
| 156 | return ret; |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 157 | |
Kim, Milo | 6029719 | 2012-08-31 09:24:51 +0000 | [diff] [blame] | 158 | val = LP8727_INT_EN | LP8727_CHGDET_EN; |
Kim, Milo | 70be130 | 2012-08-31 09:25:34 +0000 | [diff] [blame] | 159 | return lp8727_write_byte(pchg, LP8727_CTRL2, val); |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | static int lp8727_is_dedicated_charger(struct lp8727_chg *pchg) |
| 163 | { |
| 164 | u8 val; |
Kim, Milo | b9633ef | 2012-08-31 09:27:22 +0000 | [diff] [blame] | 165 | |
Kim, Milo | 6029719 | 2012-08-31 09:24:51 +0000 | [diff] [blame] | 166 | lp8727_read_byte(pchg, LP8727_STATUS1, &val); |
| 167 | return val & LP8727_DCPORT; |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | static int lp8727_is_usb_charger(struct lp8727_chg *pchg) |
| 171 | { |
| 172 | u8 val; |
Kim, Milo | b9633ef | 2012-08-31 09:27:22 +0000 | [diff] [blame] | 173 | |
Kim, Milo | 6029719 | 2012-08-31 09:24:51 +0000 | [diff] [blame] | 174 | lp8727_read_byte(pchg, LP8727_STATUS1, &val); |
| 175 | return val & LP8727_CHPORT; |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 176 | } |
| 177 | |
Kim, Milo | 91a6963 | 2012-08-31 09:25:45 +0000 | [diff] [blame] | 178 | static inline void lp8727_ctrl_switch(struct lp8727_chg *pchg, u8 sw) |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 179 | { |
Kim, Milo | 6029719 | 2012-08-31 09:24:51 +0000 | [diff] [blame] | 180 | lp8727_write_byte(pchg, LP8727_SWCTRL, sw); |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | static void lp8727_id_detection(struct lp8727_chg *pchg, u8 id, int vbusin) |
| 184 | { |
Kim, Milo | 318cb38 | 2012-08-31 09:23:12 +0000 | [diff] [blame] | 185 | struct lp8727_platform_data *pdata = pchg->pdata; |
Kim, Milo | 6029719 | 2012-08-31 09:24:51 +0000 | [diff] [blame] | 186 | u8 devid = LP8727_ID_NONE; |
| 187 | u8 swctrl = LP8727_SW_DM1_HiZ | LP8727_SW_DP2_HiZ; |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 188 | |
| 189 | switch (id) { |
| 190 | case 0x5: |
Kim, Milo | 6029719 | 2012-08-31 09:24:51 +0000 | [diff] [blame] | 191 | devid = LP8727_ID_TA; |
Kim, Milo | 56d99ed | 2012-08-31 09:26:49 +0000 | [diff] [blame] | 192 | pchg->chg_param = pdata ? pdata->ac : NULL; |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 193 | break; |
| 194 | case 0xB: |
| 195 | if (lp8727_is_dedicated_charger(pchg)) { |
Kim, Milo | 56d99ed | 2012-08-31 09:26:49 +0000 | [diff] [blame] | 196 | pchg->chg_param = pdata ? pdata->ac : NULL; |
Kim, Milo | 6029719 | 2012-08-31 09:24:51 +0000 | [diff] [blame] | 197 | devid = LP8727_ID_DEDICATED_CHG; |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 198 | } else if (lp8727_is_usb_charger(pchg)) { |
Kim, Milo | 56d99ed | 2012-08-31 09:26:49 +0000 | [diff] [blame] | 199 | pchg->chg_param = pdata ? pdata->usb : NULL; |
Kim, Milo | 6029719 | 2012-08-31 09:24:51 +0000 | [diff] [blame] | 200 | devid = LP8727_ID_USB_CHG; |
| 201 | swctrl = LP8727_SW_DM1_DM | LP8727_SW_DP2_DP; |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 202 | } else if (vbusin) { |
Kim, Milo | 6029719 | 2012-08-31 09:24:51 +0000 | [diff] [blame] | 203 | devid = LP8727_ID_USB_DS; |
| 204 | swctrl = LP8727_SW_DM1_DM | LP8727_SW_DP2_DP; |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 205 | } |
| 206 | break; |
| 207 | default: |
Kim, Milo | 6029719 | 2012-08-31 09:24:51 +0000 | [diff] [blame] | 208 | devid = LP8727_ID_NONE; |
Kim, Milo | 56d99ed | 2012-08-31 09:26:49 +0000 | [diff] [blame] | 209 | pchg->chg_param = NULL; |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 210 | break; |
| 211 | } |
| 212 | |
| 213 | pchg->devid = devid; |
| 214 | lp8727_ctrl_switch(pchg, swctrl); |
| 215 | } |
| 216 | |
| 217 | static void lp8727_enable_chgdet(struct lp8727_chg *pchg) |
| 218 | { |
| 219 | u8 val; |
| 220 | |
Kim, Milo | 6029719 | 2012-08-31 09:24:51 +0000 | [diff] [blame] | 221 | lp8727_read_byte(pchg, LP8727_CTRL2, &val); |
| 222 | val |= LP8727_CHGDET_EN; |
| 223 | lp8727_write_byte(pchg, LP8727_CTRL2, val); |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | static void lp8727_delayed_func(struct work_struct *_work) |
| 227 | { |
Kim, Milo | 5e00b97 | 2012-08-31 09:26:33 +0000 | [diff] [blame] | 228 | struct lp8727_chg *pchg = container_of(_work, struct lp8727_chg, |
| 229 | work.work); |
| 230 | u8 intstat[LP8788_NUM_INTREGS]; |
| 231 | u8 idno; |
| 232 | u8 vbus; |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 233 | |
Kim, Milo | 18763a3 | 2012-08-31 09:25:07 +0000 | [diff] [blame] | 234 | if (lp8727_read_bytes(pchg, LP8727_INT1, intstat, LP8788_NUM_INTREGS)) { |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 235 | dev_err(pchg->dev, "can not read INT registers\n"); |
| 236 | return; |
| 237 | } |
| 238 | |
Kim, Milo | 6029719 | 2012-08-31 09:24:51 +0000 | [diff] [blame] | 239 | idno = intstat[0] & LP8727_IDNO; |
| 240 | vbus = intstat[0] & LP8727_VBUS; |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 241 | |
| 242 | lp8727_id_detection(pchg, idno, vbus); |
| 243 | lp8727_enable_chgdet(pchg); |
| 244 | |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 245 | power_supply_changed(pchg->psy->ac); |
| 246 | power_supply_changed(pchg->psy->usb); |
| 247 | power_supply_changed(pchg->psy->batt); |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | static irqreturn_t lp8727_isr_func(int irq, void *ptr) |
| 251 | { |
| 252 | struct lp8727_chg *pchg = ptr; |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 253 | |
Kim, Milo | 2a09258 | 2012-08-31 09:23:41 +0000 | [diff] [blame] | 254 | schedule_delayed_work(&pchg->work, pchg->debounce_jiffies); |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 255 | return IRQ_HANDLED; |
| 256 | } |
| 257 | |
Kim, Milo | d71fda0 | 2012-08-31 09:23:57 +0000 | [diff] [blame] | 258 | static int lp8727_setup_irq(struct lp8727_chg *pchg) |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 259 | { |
Kim, Milo | d71fda0 | 2012-08-31 09:23:57 +0000 | [diff] [blame] | 260 | int ret; |
| 261 | int irq = pchg->client->irq; |
Kim, Milo | 60fd57e | 2012-08-31 09:23:25 +0000 | [diff] [blame] | 262 | unsigned delay_msec = pchg->pdata ? pchg->pdata->debounce_msec : |
| 263 | DEFAULT_DEBOUNCE_MSEC; |
| 264 | |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 265 | INIT_DELAYED_WORK(&pchg->work, lp8727_delayed_func); |
| 266 | |
Kim, Milo | d71fda0 | 2012-08-31 09:23:57 +0000 | [diff] [blame] | 267 | if (irq <= 0) { |
| 268 | dev_warn(pchg->dev, "invalid irq number: %d\n", irq); |
| 269 | return 0; |
| 270 | } |
| 271 | |
| 272 | ret = request_threaded_irq(irq, NULL, lp8727_isr_func, |
| 273 | IRQF_TRIGGER_FALLING | IRQF_ONESHOT, |
| 274 | "lp8727_irq", pchg); |
| 275 | |
| 276 | if (ret) |
| 277 | return ret; |
| 278 | |
| 279 | pchg->irq = irq; |
Kim, Milo | 60fd57e | 2012-08-31 09:23:25 +0000 | [diff] [blame] | 280 | pchg->debounce_jiffies = msecs_to_jiffies(delay_msec); |
| 281 | |
Kim, Milo | d71fda0 | 2012-08-31 09:23:57 +0000 | [diff] [blame] | 282 | return 0; |
| 283 | } |
| 284 | |
| 285 | static void lp8727_release_irq(struct lp8727_chg *pchg) |
| 286 | { |
| 287 | cancel_delayed_work_sync(&pchg->work); |
| 288 | |
| 289 | if (pchg->irq) |
| 290 | free_irq(pchg->irq, pchg); |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | static enum power_supply_property lp8727_charger_prop[] = { |
| 294 | POWER_SUPPLY_PROP_ONLINE, |
| 295 | }; |
| 296 | |
| 297 | static enum power_supply_property lp8727_battery_prop[] = { |
| 298 | POWER_SUPPLY_PROP_STATUS, |
| 299 | POWER_SUPPLY_PROP_HEALTH, |
| 300 | POWER_SUPPLY_PROP_PRESENT, |
| 301 | POWER_SUPPLY_PROP_VOLTAGE_NOW, |
| 302 | POWER_SUPPLY_PROP_CAPACITY, |
| 303 | POWER_SUPPLY_PROP_TEMP, |
| 304 | }; |
| 305 | |
| 306 | static char *battery_supplied_to[] = { |
| 307 | "main_batt", |
| 308 | }; |
| 309 | |
| 310 | static int lp8727_charger_get_property(struct power_supply *psy, |
| 311 | enum power_supply_property psp, |
| 312 | union power_supply_propval *val) |
| 313 | { |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 314 | struct lp8727_chg *pchg = dev_get_drvdata(psy->dev.parent); |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 315 | |
Kim, Milo | b59c93c0 | 2012-08-31 09:25:55 +0000 | [diff] [blame] | 316 | if (psp != POWER_SUPPLY_PROP_ONLINE) |
| 317 | return -EINVAL; |
| 318 | |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 319 | val->intval = lp8727_is_charger_attached(psy->desc->name, pchg->devid); |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 320 | |
| 321 | return 0; |
| 322 | } |
| 323 | |
Kim, Milo | b1ad079 | 2012-08-31 09:24:28 +0000 | [diff] [blame] | 324 | static bool lp8727_is_high_temperature(enum lp8727_die_temp temp) |
| 325 | { |
| 326 | switch (temp) { |
| 327 | case LP8788_TEMP_95C: |
| 328 | case LP8788_TEMP_115C: |
| 329 | case LP8788_TEMP_135C: |
| 330 | return true; |
| 331 | default: |
| 332 | return false; |
| 333 | } |
| 334 | } |
| 335 | |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 336 | static int lp8727_battery_get_property(struct power_supply *psy, |
| 337 | enum power_supply_property psp, |
| 338 | union power_supply_propval *val) |
| 339 | { |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 340 | struct lp8727_chg *pchg = dev_get_drvdata(psy->dev.parent); |
Kim, Milo | 318cb38 | 2012-08-31 09:23:12 +0000 | [diff] [blame] | 341 | struct lp8727_platform_data *pdata = pchg->pdata; |
Kim, Milo | b1ad079 | 2012-08-31 09:24:28 +0000 | [diff] [blame] | 342 | enum lp8727_die_temp temp; |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 343 | u8 read; |
| 344 | |
| 345 | switch (psp) { |
| 346 | case POWER_SUPPLY_PROP_STATUS: |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 347 | if (!lp8727_is_charger_attached(psy->desc->name, pchg->devid)) { |
Kim, Milo | e06374b | 2012-08-31 09:26:06 +0000 | [diff] [blame] | 348 | val->intval = POWER_SUPPLY_STATUS_DISCHARGING; |
| 349 | return 0; |
| 350 | } |
Kim, Milo | faaae9b | 2012-08-31 09:24:37 +0000 | [diff] [blame] | 351 | |
Kim, Milo | e06374b | 2012-08-31 09:26:06 +0000 | [diff] [blame] | 352 | lp8727_read_byte(pchg, LP8727_STATUS1, &read); |
| 353 | |
| 354 | val->intval = (read & LP8727_CHGSTAT) == LP8727_STAT_EOC ? |
Kim, Milo | faaae9b | 2012-08-31 09:24:37 +0000 | [diff] [blame] | 355 | POWER_SUPPLY_STATUS_FULL : |
| 356 | POWER_SUPPLY_STATUS_CHARGING; |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 357 | break; |
| 358 | case POWER_SUPPLY_PROP_HEALTH: |
Kim, Milo | 6029719 | 2012-08-31 09:24:51 +0000 | [diff] [blame] | 359 | lp8727_read_byte(pchg, LP8727_STATUS2, &read); |
| 360 | temp = (read & LP8727_TEMP_STAT) >> LP8727_TEMP_SHIFT; |
Kim, Milo | b1ad079 | 2012-08-31 09:24:28 +0000 | [diff] [blame] | 361 | |
| 362 | val->intval = lp8727_is_high_temperature(temp) ? |
| 363 | POWER_SUPPLY_HEALTH_OVERHEAT : |
| 364 | POWER_SUPPLY_HEALTH_GOOD; |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 365 | break; |
| 366 | case POWER_SUPPLY_PROP_PRESENT: |
Kim, Milo | 318cb38 | 2012-08-31 09:23:12 +0000 | [diff] [blame] | 367 | if (!pdata) |
| 368 | return -EINVAL; |
| 369 | |
| 370 | if (pdata->get_batt_present) |
Dan Carpenter | f96b307 | 2013-01-25 18:43:50 +0300 | [diff] [blame] | 371 | val->intval = pdata->get_batt_present(); |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 372 | break; |
| 373 | case POWER_SUPPLY_PROP_VOLTAGE_NOW: |
Kim, Milo | 318cb38 | 2012-08-31 09:23:12 +0000 | [diff] [blame] | 374 | if (!pdata) |
| 375 | return -EINVAL; |
| 376 | |
| 377 | if (pdata->get_batt_level) |
Dan Carpenter | f96b307 | 2013-01-25 18:43:50 +0300 | [diff] [blame] | 378 | val->intval = pdata->get_batt_level(); |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 379 | break; |
| 380 | case POWER_SUPPLY_PROP_CAPACITY: |
Kim, Milo | 318cb38 | 2012-08-31 09:23:12 +0000 | [diff] [blame] | 381 | if (!pdata) |
| 382 | return -EINVAL; |
| 383 | |
| 384 | if (pdata->get_batt_capacity) |
Dan Carpenter | f96b307 | 2013-01-25 18:43:50 +0300 | [diff] [blame] | 385 | val->intval = pdata->get_batt_capacity(); |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 386 | break; |
| 387 | case POWER_SUPPLY_PROP_TEMP: |
Kim, Milo | 318cb38 | 2012-08-31 09:23:12 +0000 | [diff] [blame] | 388 | if (!pdata) |
| 389 | return -EINVAL; |
| 390 | |
| 391 | if (pdata->get_batt_temp) |
Dan Carpenter | f96b307 | 2013-01-25 18:43:50 +0300 | [diff] [blame] | 392 | val->intval = pdata->get_batt_temp(); |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 393 | break; |
| 394 | default: |
| 395 | break; |
| 396 | } |
| 397 | |
| 398 | return 0; |
| 399 | } |
| 400 | |
| 401 | static void lp8727_charger_changed(struct power_supply *psy) |
| 402 | { |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 403 | struct lp8727_chg *pchg = dev_get_drvdata(psy->dev.parent); |
Kim, Milo | 20414e2 | 2012-08-31 09:26:22 +0000 | [diff] [blame] | 404 | u8 eoc_level; |
| 405 | u8 ichg; |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 406 | u8 val; |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 407 | |
Kim, Milo | 20414e2 | 2012-08-31 09:26:22 +0000 | [diff] [blame] | 408 | /* skip if no charger exists */ |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 409 | if (!lp8727_is_charger_attached(psy->desc->name, pchg->devid)) |
Kim, Milo | 20414e2 | 2012-08-31 09:26:22 +0000 | [diff] [blame] | 410 | return; |
| 411 | |
| 412 | /* update charging parameters */ |
Kim, Milo | 56d99ed | 2012-08-31 09:26:49 +0000 | [diff] [blame] | 413 | if (pchg->chg_param) { |
| 414 | eoc_level = pchg->chg_param->eoc_level; |
| 415 | ichg = pchg->chg_param->ichg; |
Kim, Milo | 20414e2 | 2012-08-31 09:26:22 +0000 | [diff] [blame] | 416 | val = (ichg << LP8727_ICHG_SHIFT) | eoc_level; |
| 417 | lp8727_write_byte(pchg, LP8727_CHGCTRL2, val); |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 418 | } |
| 419 | } |
| 420 | |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 421 | static const struct power_supply_desc lp8727_ac_desc = { |
| 422 | .name = "ac", |
| 423 | .type = POWER_SUPPLY_TYPE_MAINS, |
| 424 | .properties = lp8727_charger_prop, |
| 425 | .num_properties = ARRAY_SIZE(lp8727_charger_prop), |
| 426 | .get_property = lp8727_charger_get_property, |
| 427 | }; |
| 428 | |
| 429 | static const struct power_supply_desc lp8727_usb_desc = { |
| 430 | .name = "usb", |
| 431 | .type = POWER_SUPPLY_TYPE_USB, |
| 432 | .properties = lp8727_charger_prop, |
| 433 | .num_properties = ARRAY_SIZE(lp8727_charger_prop), |
| 434 | .get_property = lp8727_charger_get_property, |
| 435 | }; |
| 436 | |
| 437 | static const struct power_supply_desc lp8727_batt_desc = { |
| 438 | .name = "main_batt", |
| 439 | .type = POWER_SUPPLY_TYPE_BATTERY, |
| 440 | .properties = lp8727_battery_prop, |
| 441 | .num_properties = ARRAY_SIZE(lp8727_battery_prop), |
| 442 | .get_property = lp8727_battery_get_property, |
| 443 | .external_power_changed = lp8727_charger_changed, |
| 444 | }; |
| 445 | |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 446 | static int lp8727_register_psy(struct lp8727_chg *pchg) |
| 447 | { |
Krzysztof Kozlowski | 2dc9215 | 2015-03-12 08:44:02 +0100 | [diff] [blame] | 448 | struct power_supply_config psy_cfg = {}; /* Only for ac and usb */ |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 449 | struct lp8727_psy *psy; |
| 450 | |
Kim, Milo | 74727c5 | 2012-08-31 09:22:46 +0000 | [diff] [blame] | 451 | psy = devm_kzalloc(pchg->dev, sizeof(*psy), GFP_KERNEL); |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 452 | if (!psy) |
Devendra Naga | 6297b5e | 2012-07-29 23:31:55 +0545 | [diff] [blame] | 453 | return -ENOMEM; |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 454 | |
| 455 | pchg->psy = psy; |
| 456 | |
Krzysztof Kozlowski | 2dc9215 | 2015-03-12 08:44:02 +0100 | [diff] [blame] | 457 | psy_cfg.supplied_to = battery_supplied_to; |
| 458 | psy_cfg.num_supplicants = ARRAY_SIZE(battery_supplied_to); |
| 459 | |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 460 | psy->ac = power_supply_register(pchg->dev, &lp8727_ac_desc, &psy_cfg); |
| 461 | if (IS_ERR(psy->ac)) |
Devendra Naga | 6297b5e | 2012-07-29 23:31:55 +0545 | [diff] [blame] | 462 | goto err_psy_ac; |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 463 | |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 464 | psy->usb = power_supply_register(pchg->dev, &lp8727_usb_desc, |
| 465 | &psy_cfg); |
| 466 | if (IS_ERR(psy->usb)) |
Devendra Naga | 6297b5e | 2012-07-29 23:31:55 +0545 | [diff] [blame] | 467 | goto err_psy_usb; |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 468 | |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 469 | psy->batt = power_supply_register(pchg->dev, &lp8727_batt_desc, NULL); |
| 470 | if (IS_ERR(psy->batt)) |
Devendra Naga | 6297b5e | 2012-07-29 23:31:55 +0545 | [diff] [blame] | 471 | goto err_psy_batt; |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 472 | |
| 473 | return 0; |
| 474 | |
Devendra Naga | 6297b5e | 2012-07-29 23:31:55 +0545 | [diff] [blame] | 475 | err_psy_batt: |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 476 | power_supply_unregister(psy->usb); |
Devendra Naga | 6297b5e | 2012-07-29 23:31:55 +0545 | [diff] [blame] | 477 | err_psy_usb: |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 478 | power_supply_unregister(psy->ac); |
Devendra Naga | 6297b5e | 2012-07-29 23:31:55 +0545 | [diff] [blame] | 479 | err_psy_ac: |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 480 | return -EPERM; |
| 481 | } |
| 482 | |
| 483 | static void lp8727_unregister_psy(struct lp8727_chg *pchg) |
| 484 | { |
| 485 | struct lp8727_psy *psy = pchg->psy; |
| 486 | |
Kim, Milo | ce09aff | 2012-01-04 09:03:18 +0400 | [diff] [blame] | 487 | if (!psy) |
| 488 | return; |
| 489 | |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 490 | power_supply_unregister(psy->ac); |
| 491 | power_supply_unregister(psy->usb); |
| 492 | power_supply_unregister(psy->batt); |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 493 | } |
| 494 | |
Kim, Milo | 17b4565 | 2013-05-10 07:17:51 +0000 | [diff] [blame] | 495 | #ifdef CONFIG_OF |
| 496 | static struct lp8727_chg_param |
| 497 | *lp8727_parse_charge_pdata(struct device *dev, struct device_node *np) |
| 498 | { |
| 499 | struct lp8727_chg_param *param; |
| 500 | |
| 501 | param = devm_kzalloc(dev, sizeof(*param), GFP_KERNEL); |
| 502 | if (!param) |
| 503 | goto out; |
| 504 | |
| 505 | of_property_read_u8(np, "eoc-level", (u8 *)¶m->eoc_level); |
| 506 | of_property_read_u8(np, "charging-current", (u8 *)¶m->ichg); |
| 507 | out: |
| 508 | return param; |
| 509 | } |
| 510 | |
Milo Kim | 87d931d | 2015-08-25 15:07:07 +0900 | [diff] [blame] | 511 | static struct lp8727_platform_data *lp8727_parse_dt(struct device *dev) |
Kim, Milo | 17b4565 | 2013-05-10 07:17:51 +0000 | [diff] [blame] | 512 | { |
| 513 | struct device_node *np = dev->of_node; |
| 514 | struct device_node *child; |
| 515 | struct lp8727_platform_data *pdata; |
| 516 | const char *type; |
| 517 | |
Kim, Milo | 17b4565 | 2013-05-10 07:17:51 +0000 | [diff] [blame] | 518 | pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); |
| 519 | if (!pdata) |
Milo Kim | 87d931d | 2015-08-25 15:07:07 +0900 | [diff] [blame] | 520 | return ERR_PTR(-ENOMEM); |
Kim, Milo | 17b4565 | 2013-05-10 07:17:51 +0000 | [diff] [blame] | 521 | |
| 522 | of_property_read_u32(np, "debounce-ms", &pdata->debounce_msec); |
| 523 | |
Milo Kim | 9615a29 | 2015-08-25 15:07:08 +0900 | [diff] [blame] | 524 | /* If charging parameter is not defined, just skip parsing the dt */ |
| 525 | if (of_get_child_count(np) == 0) |
| 526 | return pdata; |
| 527 | |
Kim, Milo | 17b4565 | 2013-05-10 07:17:51 +0000 | [diff] [blame] | 528 | for_each_child_of_node(np, child) { |
| 529 | of_property_read_string(child, "charger-type", &type); |
| 530 | |
| 531 | if (!strcmp(type, "ac")) |
| 532 | pdata->ac = lp8727_parse_charge_pdata(dev, child); |
| 533 | |
| 534 | if (!strcmp(type, "usb")) |
| 535 | pdata->usb = lp8727_parse_charge_pdata(dev, child); |
| 536 | } |
| 537 | |
Milo Kim | 87d931d | 2015-08-25 15:07:07 +0900 | [diff] [blame] | 538 | return pdata; |
Kim, Milo | 17b4565 | 2013-05-10 07:17:51 +0000 | [diff] [blame] | 539 | } |
| 540 | #else |
Milo Kim | 87d931d | 2015-08-25 15:07:07 +0900 | [diff] [blame] | 541 | static struct lp8727_platform_data *lp8727_parse_dt(struct device *dev) |
Kim, Milo | 17b4565 | 2013-05-10 07:17:51 +0000 | [diff] [blame] | 542 | { |
Milo Kim | 87d931d | 2015-08-25 15:07:07 +0900 | [diff] [blame] | 543 | return NULL; |
Kim, Milo | 17b4565 | 2013-05-10 07:17:51 +0000 | [diff] [blame] | 544 | } |
| 545 | #endif |
| 546 | |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 547 | static int lp8727_probe(struct i2c_client *cl, const struct i2c_device_id *id) |
| 548 | { |
| 549 | struct lp8727_chg *pchg; |
Milo Kim | 87d931d | 2015-08-25 15:07:07 +0900 | [diff] [blame] | 550 | struct lp8727_platform_data *pdata; |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 551 | int ret; |
| 552 | |
Kim, Milo | 998a8e7 | 2011-11-17 21:43:06 -0800 | [diff] [blame] | 553 | if (!i2c_check_functionality(cl->adapter, I2C_FUNC_SMBUS_I2C_BLOCK)) |
| 554 | return -EIO; |
| 555 | |
Kim, Milo | 17b4565 | 2013-05-10 07:17:51 +0000 | [diff] [blame] | 556 | if (cl->dev.of_node) { |
Milo Kim | 87d931d | 2015-08-25 15:07:07 +0900 | [diff] [blame] | 557 | pdata = lp8727_parse_dt(&cl->dev); |
| 558 | if (IS_ERR(pdata)) |
| 559 | return PTR_ERR(pdata); |
| 560 | } else { |
| 561 | pdata = dev_get_platdata(&cl->dev); |
Kim, Milo | 17b4565 | 2013-05-10 07:17:51 +0000 | [diff] [blame] | 562 | } |
| 563 | |
Kim, Milo | 74727c5 | 2012-08-31 09:22:46 +0000 | [diff] [blame] | 564 | pchg = devm_kzalloc(&cl->dev, sizeof(*pchg), GFP_KERNEL); |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 565 | if (!pchg) |
| 566 | return -ENOMEM; |
| 567 | |
| 568 | pchg->client = cl; |
| 569 | pchg->dev = &cl->dev; |
Milo Kim | 87d931d | 2015-08-25 15:07:07 +0900 | [diff] [blame] | 570 | pchg->pdata = pdata; |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 571 | i2c_set_clientdata(cl, pchg); |
| 572 | |
| 573 | mutex_init(&pchg->xfer_lock); |
| 574 | |
Kim, Milo | 7da6334 | 2012-01-26 22:58:30 -0800 | [diff] [blame] | 575 | ret = lp8727_init_device(pchg); |
| 576 | if (ret) { |
| 577 | dev_err(pchg->dev, "i2c communication err: %d", ret); |
Kim, Milo | fb9adc5 | 2012-08-31 09:23:03 +0000 | [diff] [blame] | 578 | return ret; |
Kim, Milo | 7da6334 | 2012-01-26 22:58:30 -0800 | [diff] [blame] | 579 | } |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 580 | |
| 581 | ret = lp8727_register_psy(pchg); |
Kim, Milo | 7da6334 | 2012-01-26 22:58:30 -0800 | [diff] [blame] | 582 | if (ret) { |
| 583 | dev_err(pchg->dev, "power supplies register err: %d", ret); |
Kim, Milo | fb9adc5 | 2012-08-31 09:23:03 +0000 | [diff] [blame] | 584 | return ret; |
| 585 | } |
| 586 | |
Kim, Milo | d71fda0 | 2012-08-31 09:23:57 +0000 | [diff] [blame] | 587 | ret = lp8727_setup_irq(pchg); |
Kim, Milo | fb9adc5 | 2012-08-31 09:23:03 +0000 | [diff] [blame] | 588 | if (ret) { |
| 589 | dev_err(pchg->dev, "irq handler err: %d", ret); |
| 590 | lp8727_unregister_psy(pchg); |
| 591 | return ret; |
Kim, Milo | 7da6334 | 2012-01-26 22:58:30 -0800 | [diff] [blame] | 592 | } |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 593 | |
| 594 | return 0; |
| 595 | } |
| 596 | |
Bill Pemberton | 415ec69 | 2012-11-19 13:26:07 -0500 | [diff] [blame] | 597 | static int lp8727_remove(struct i2c_client *cl) |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 598 | { |
| 599 | struct lp8727_chg *pchg = i2c_get_clientdata(cl); |
| 600 | |
Kim, Milo | d71fda0 | 2012-08-31 09:23:57 +0000 | [diff] [blame] | 601 | lp8727_release_irq(pchg); |
Kim, Milo | fb9adc5 | 2012-08-31 09:23:03 +0000 | [diff] [blame] | 602 | lp8727_unregister_psy(pchg); |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 603 | return 0; |
| 604 | } |
| 605 | |
Kim, Milo | 17b4565 | 2013-05-10 07:17:51 +0000 | [diff] [blame] | 606 | static const struct of_device_id lp8727_dt_ids[] = { |
| 607 | { .compatible = "ti,lp8727", }, |
| 608 | { } |
| 609 | }; |
| 610 | MODULE_DEVICE_TABLE(of, lp8727_dt_ids); |
| 611 | |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 612 | static const struct i2c_device_id lp8727_ids[] = { |
| 613 | {"lp8727", 0}, |
Axel Lin | 455a0e2 | 2012-01-16 13:48:20 +0800 | [diff] [blame] | 614 | { } |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 615 | }; |
Axel Lin | e2c5f7d | 2012-01-12 20:45:02 +0800 | [diff] [blame] | 616 | MODULE_DEVICE_TABLE(i2c, lp8727_ids); |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 617 | |
| 618 | static struct i2c_driver lp8727_driver = { |
| 619 | .driver = { |
| 620 | .name = "lp8727", |
Kim, Milo | 17b4565 | 2013-05-10 07:17:51 +0000 | [diff] [blame] | 621 | .of_match_table = of_match_ptr(lp8727_dt_ids), |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 622 | }, |
| 623 | .probe = lp8727_probe, |
Bill Pemberton | 28ea73f | 2012-11-19 13:20:40 -0500 | [diff] [blame] | 624 | .remove = lp8727_remove, |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 625 | .id_table = lp8727_ids, |
| 626 | }; |
Axel Lin | 5ff92e7 | 2012-01-21 14:42:54 +0800 | [diff] [blame] | 627 | module_i2c_driver(lp8727_driver); |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 628 | |
Kim, Milo | e39b828 | 2012-01-29 17:28:18 -0800 | [diff] [blame] | 629 | MODULE_DESCRIPTION("TI/National Semiconductor LP8727 charger driver"); |
Kim, Milo | 18259ca | 2012-08-31 09:27:12 +0000 | [diff] [blame] | 630 | MODULE_AUTHOR("Milo Kim <milo.kim@ti.com>, Daniel Jeong <daniel.jeong@ti.com>"); |
Woogyom Kim | 2165c8a | 2012-01-04 08:27:43 +0400 | [diff] [blame] | 631 | MODULE_LICENSE("GPL"); |