MyungJoo Ham | 359ab9f | 2011-01-14 14:46:11 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Fuel gauge driver for Maxim 17042 / 8966 / 8997 |
| 3 | * Note that Maxim 8966 and 8997 are mfd and this is its subdevice. |
| 4 | * |
| 5 | * Copyright (C) 2011 Samsung Electronics |
| 6 | * MyungJoo Ham <myungjoo.ham@samsung.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 21 | * |
| 22 | * This driver is based on max17040_battery.c |
| 23 | */ |
| 24 | |
| 25 | #include <linux/init.h> |
Paul Gortmaker | 7e6d62d | 2011-07-03 15:28:29 -0400 | [diff] [blame] | 26 | #include <linux/module.h> |
MyungJoo Ham | 359ab9f | 2011-01-14 14:46:11 +0900 | [diff] [blame] | 27 | #include <linux/slab.h> |
| 28 | #include <linux/i2c.h> |
Ramakrishna Pallala | f3a71a6 | 2012-03-13 22:03:52 +0400 | [diff] [blame] | 29 | #include <linux/delay.h> |
Ramakrishna Pallala | e5f3872 | 2012-01-24 09:26:06 -0800 | [diff] [blame] | 30 | #include <linux/interrupt.h> |
Ramakrishna Pallala | 48bc177 | 2012-03-27 02:23:40 +0530 | [diff] [blame] | 31 | #include <linux/pm.h> |
MyungJoo Ham | 359ab9f | 2011-01-14 14:46:11 +0900 | [diff] [blame] | 32 | #include <linux/mod_devicetable.h> |
| 33 | #include <linux/power_supply.h> |
| 34 | #include <linux/power/max17042_battery.h> |
Karol Lewandowski | 3832246 | 2012-02-22 19:06:22 +0100 | [diff] [blame] | 35 | #include <linux/of.h> |
MyungJoo Ham | 359ab9f | 2011-01-14 14:46:11 +0900 | [diff] [blame] | 36 | |
Ramakrishna Pallala | f3a71a6 | 2012-03-13 22:03:52 +0400 | [diff] [blame] | 37 | /* Status register bits */ |
| 38 | #define STATUS_POR_BIT (1 << 1) |
| 39 | #define STATUS_BST_BIT (1 << 3) |
| 40 | #define STATUS_VMN_BIT (1 << 8) |
| 41 | #define STATUS_TMN_BIT (1 << 9) |
| 42 | #define STATUS_SMN_BIT (1 << 10) |
| 43 | #define STATUS_BI_BIT (1 << 11) |
| 44 | #define STATUS_VMX_BIT (1 << 12) |
| 45 | #define STATUS_TMX_BIT (1 << 13) |
| 46 | #define STATUS_SMX_BIT (1 << 14) |
| 47 | #define STATUS_BR_BIT (1 << 15) |
| 48 | |
Ramakrishna Pallala | e5f3872 | 2012-01-24 09:26:06 -0800 | [diff] [blame] | 49 | /* Interrupt mask bits */ |
| 50 | #define CONFIG_ALRT_BIT_ENBL (1 << 2) |
Ramakrishna Pallala | 5cdd4d7 | 2012-03-21 03:03:16 +0530 | [diff] [blame] | 51 | #define STATUS_INTR_SOCMIN_BIT (1 << 10) |
| 52 | #define STATUS_INTR_SOCMAX_BIT (1 << 14) |
Ramakrishna Pallala | e5f3872 | 2012-01-24 09:26:06 -0800 | [diff] [blame] | 53 | |
Ramakrishna Pallala | f3a71a6 | 2012-03-13 22:03:52 +0400 | [diff] [blame] | 54 | #define VFSOC0_LOCK 0x0000 |
| 55 | #define VFSOC0_UNLOCK 0x0080 |
| 56 | #define MODEL_UNLOCK1 0X0059 |
| 57 | #define MODEL_UNLOCK2 0X00C4 |
| 58 | #define MODEL_LOCK1 0X0000 |
| 59 | #define MODEL_LOCK2 0X0000 |
| 60 | |
| 61 | #define dQ_ACC_DIV 0x4 |
| 62 | #define dP_ACC_100 0x1900 |
| 63 | #define dP_ACC_200 0x3200 |
| 64 | |
MyungJoo Ham | 359ab9f | 2011-01-14 14:46:11 +0900 | [diff] [blame] | 65 | struct max17042_chip { |
| 66 | struct i2c_client *client; |
| 67 | struct power_supply battery; |
| 68 | struct max17042_platform_data *pdata; |
Ramakrishna Pallala | f3a71a6 | 2012-03-13 22:03:52 +0400 | [diff] [blame] | 69 | struct work_struct work; |
| 70 | int init_complete; |
MyungJoo Ham | 359ab9f | 2011-01-14 14:46:11 +0900 | [diff] [blame] | 71 | }; |
| 72 | |
| 73 | static int max17042_write_reg(struct i2c_client *client, u8 reg, u16 value) |
| 74 | { |
| 75 | int ret = i2c_smbus_write_word_data(client, reg, value); |
| 76 | |
| 77 | if (ret < 0) |
| 78 | dev_err(&client->dev, "%s: err %d\n", __func__, ret); |
| 79 | |
| 80 | return ret; |
| 81 | } |
| 82 | |
| 83 | static int max17042_read_reg(struct i2c_client *client, u8 reg) |
| 84 | { |
| 85 | int ret = i2c_smbus_read_word_data(client, reg); |
| 86 | |
| 87 | if (ret < 0) |
| 88 | dev_err(&client->dev, "%s: err %d\n", __func__, ret); |
| 89 | |
| 90 | return ret; |
| 91 | } |
| 92 | |
Donggeun Kim | 086ef50 | 2011-06-30 18:07:41 +0900 | [diff] [blame] | 93 | static void max17042_set_reg(struct i2c_client *client, |
| 94 | struct max17042_reg_data *data, int size) |
| 95 | { |
| 96 | int i; |
| 97 | |
| 98 | for (i = 0; i < size; i++) |
| 99 | max17042_write_reg(client, data[i].addr, data[i].data); |
| 100 | } |
| 101 | |
MyungJoo Ham | 359ab9f | 2011-01-14 14:46:11 +0900 | [diff] [blame] | 102 | static enum power_supply_property max17042_battery_props[] = { |
Donggeun Kim | 086ef50 | 2011-06-30 18:07:41 +0900 | [diff] [blame] | 103 | POWER_SUPPLY_PROP_PRESENT, |
| 104 | POWER_SUPPLY_PROP_CYCLE_COUNT, |
| 105 | POWER_SUPPLY_PROP_VOLTAGE_MAX, |
| 106 | POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN, |
MyungJoo Ham | 359ab9f | 2011-01-14 14:46:11 +0900 | [diff] [blame] | 107 | POWER_SUPPLY_PROP_VOLTAGE_NOW, |
| 108 | POWER_SUPPLY_PROP_VOLTAGE_AVG, |
Ramakrishna Pallala | a2ebfe2 | 2012-04-10 16:21:20 +0530 | [diff] [blame] | 109 | POWER_SUPPLY_PROP_VOLTAGE_OCV, |
MyungJoo Ham | 359ab9f | 2011-01-14 14:46:11 +0900 | [diff] [blame] | 110 | POWER_SUPPLY_PROP_CAPACITY, |
Donggeun Kim | 086ef50 | 2011-06-30 18:07:41 +0900 | [diff] [blame] | 111 | POWER_SUPPLY_PROP_CHARGE_FULL, |
| 112 | POWER_SUPPLY_PROP_TEMP, |
| 113 | POWER_SUPPLY_PROP_CURRENT_NOW, |
| 114 | POWER_SUPPLY_PROP_CURRENT_AVG, |
MyungJoo Ham | 359ab9f | 2011-01-14 14:46:11 +0900 | [diff] [blame] | 115 | }; |
| 116 | |
| 117 | static int max17042_get_property(struct power_supply *psy, |
| 118 | enum power_supply_property psp, |
| 119 | union power_supply_propval *val) |
| 120 | { |
| 121 | struct max17042_chip *chip = container_of(psy, |
| 122 | struct max17042_chip, battery); |
Ramakrishna Pallala | 60a1f6e | 2011-11-26 04:11:15 +0400 | [diff] [blame] | 123 | int ret; |
MyungJoo Ham | 359ab9f | 2011-01-14 14:46:11 +0900 | [diff] [blame] | 124 | |
Ramakrishna Pallala | f3a71a6 | 2012-03-13 22:03:52 +0400 | [diff] [blame] | 125 | if (!chip->init_complete) |
| 126 | return -EAGAIN; |
| 127 | |
MyungJoo Ham | 359ab9f | 2011-01-14 14:46:11 +0900 | [diff] [blame] | 128 | switch (psp) { |
Donggeun Kim | 086ef50 | 2011-06-30 18:07:41 +0900 | [diff] [blame] | 129 | case POWER_SUPPLY_PROP_PRESENT: |
Ramakrishna Pallala | 60a1f6e | 2011-11-26 04:11:15 +0400 | [diff] [blame] | 130 | ret = max17042_read_reg(chip->client, MAX17042_STATUS); |
| 131 | if (ret < 0) |
| 132 | return ret; |
| 133 | |
| 134 | if (ret & MAX17042_STATUS_BattAbsent) |
Donggeun Kim | 086ef50 | 2011-06-30 18:07:41 +0900 | [diff] [blame] | 135 | val->intval = 0; |
| 136 | else |
| 137 | val->intval = 1; |
| 138 | break; |
| 139 | case POWER_SUPPLY_PROP_CYCLE_COUNT: |
Ramakrishna Pallala | 60a1f6e | 2011-11-26 04:11:15 +0400 | [diff] [blame] | 140 | ret = max17042_read_reg(chip->client, MAX17042_Cycles); |
| 141 | if (ret < 0) |
| 142 | return ret; |
| 143 | |
| 144 | val->intval = ret; |
Donggeun Kim | 086ef50 | 2011-06-30 18:07:41 +0900 | [diff] [blame] | 145 | break; |
| 146 | case POWER_SUPPLY_PROP_VOLTAGE_MAX: |
Ramakrishna Pallala | 60a1f6e | 2011-11-26 04:11:15 +0400 | [diff] [blame] | 147 | ret = max17042_read_reg(chip->client, MAX17042_MinMaxVolt); |
| 148 | if (ret < 0) |
| 149 | return ret; |
| 150 | |
| 151 | val->intval = ret >> 8; |
Donggeun Kim | 086ef50 | 2011-06-30 18:07:41 +0900 | [diff] [blame] | 152 | val->intval *= 20000; /* Units of LSB = 20mV */ |
| 153 | break; |
| 154 | case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN: |
Ramakrishna Pallala | 60a1f6e | 2011-11-26 04:11:15 +0400 | [diff] [blame] | 155 | ret = max17042_read_reg(chip->client, MAX17042_V_empty); |
| 156 | if (ret < 0) |
| 157 | return ret; |
| 158 | |
| 159 | val->intval = ret >> 7; |
Donggeun Kim | 086ef50 | 2011-06-30 18:07:41 +0900 | [diff] [blame] | 160 | val->intval *= 10000; /* Units of LSB = 10mV */ |
| 161 | break; |
MyungJoo Ham | 359ab9f | 2011-01-14 14:46:11 +0900 | [diff] [blame] | 162 | case POWER_SUPPLY_PROP_VOLTAGE_NOW: |
Ramakrishna Pallala | 60a1f6e | 2011-11-26 04:11:15 +0400 | [diff] [blame] | 163 | ret = max17042_read_reg(chip->client, MAX17042_VCELL); |
| 164 | if (ret < 0) |
| 165 | return ret; |
| 166 | |
| 167 | val->intval = ret * 625 / 8; |
MyungJoo Ham | 359ab9f | 2011-01-14 14:46:11 +0900 | [diff] [blame] | 168 | break; |
| 169 | case POWER_SUPPLY_PROP_VOLTAGE_AVG: |
Ramakrishna Pallala | 60a1f6e | 2011-11-26 04:11:15 +0400 | [diff] [blame] | 170 | ret = max17042_read_reg(chip->client, MAX17042_AvgVCELL); |
| 171 | if (ret < 0) |
| 172 | return ret; |
| 173 | |
| 174 | val->intval = ret * 625 / 8; |
MyungJoo Ham | 359ab9f | 2011-01-14 14:46:11 +0900 | [diff] [blame] | 175 | break; |
Ramakrishna Pallala | a2ebfe2 | 2012-04-10 16:21:20 +0530 | [diff] [blame] | 176 | case POWER_SUPPLY_PROP_VOLTAGE_OCV: |
| 177 | ret = max17042_read_reg(chip->client, MAX17042_OCVInternal); |
| 178 | if (ret < 0) |
| 179 | return ret; |
| 180 | |
| 181 | val->intval = ret * 625 / 8; |
| 182 | break; |
MyungJoo Ham | 359ab9f | 2011-01-14 14:46:11 +0900 | [diff] [blame] | 183 | case POWER_SUPPLY_PROP_CAPACITY: |
Dirk Brandewie | 13e0aa4 | 2012-01-24 09:26:08 -0800 | [diff] [blame] | 184 | ret = max17042_read_reg(chip->client, MAX17042_RepSOC); |
Ramakrishna Pallala | 60a1f6e | 2011-11-26 04:11:15 +0400 | [diff] [blame] | 185 | if (ret < 0) |
| 186 | return ret; |
| 187 | |
| 188 | val->intval = ret >> 8; |
MyungJoo Ham | 359ab9f | 2011-01-14 14:46:11 +0900 | [diff] [blame] | 189 | break; |
Donggeun Kim | 086ef50 | 2011-06-30 18:07:41 +0900 | [diff] [blame] | 190 | case POWER_SUPPLY_PROP_CHARGE_FULL: |
MyungJoo Ham | 6e0e60c | 2012-03-14 03:00:01 +0100 | [diff] [blame] | 191 | ret = max17042_read_reg(chip->client, MAX17042_FullCAP); |
Ramakrishna Pallala | 60a1f6e | 2011-11-26 04:11:15 +0400 | [diff] [blame] | 192 | if (ret < 0) |
| 193 | return ret; |
| 194 | |
MyungJoo Ham | 6e0e60c | 2012-03-14 03:00:01 +0100 | [diff] [blame] | 195 | val->intval = ret * 1000 / 2; |
Donggeun Kim | 086ef50 | 2011-06-30 18:07:41 +0900 | [diff] [blame] | 196 | break; |
| 197 | case POWER_SUPPLY_PROP_TEMP: |
Ramakrishna Pallala | 60a1f6e | 2011-11-26 04:11:15 +0400 | [diff] [blame] | 198 | ret = max17042_read_reg(chip->client, MAX17042_TEMP); |
| 199 | if (ret < 0) |
| 200 | return ret; |
| 201 | |
| 202 | val->intval = ret; |
Donggeun Kim | 086ef50 | 2011-06-30 18:07:41 +0900 | [diff] [blame] | 203 | /* The value is signed. */ |
| 204 | if (val->intval & 0x8000) { |
| 205 | val->intval = (0x7fff & ~val->intval) + 1; |
| 206 | val->intval *= -1; |
| 207 | } |
| 208 | /* The value is converted into deci-centigrade scale */ |
| 209 | /* Units of LSB = 1 / 256 degree Celsius */ |
| 210 | val->intval = val->intval * 10 / 256; |
| 211 | break; |
| 212 | case POWER_SUPPLY_PROP_CURRENT_NOW: |
| 213 | if (chip->pdata->enable_current_sense) { |
Ramakrishna Pallala | 60a1f6e | 2011-11-26 04:11:15 +0400 | [diff] [blame] | 214 | ret = max17042_read_reg(chip->client, MAX17042_Current); |
| 215 | if (ret < 0) |
| 216 | return ret; |
| 217 | |
| 218 | val->intval = ret; |
Donggeun Kim | 086ef50 | 2011-06-30 18:07:41 +0900 | [diff] [blame] | 219 | if (val->intval & 0x8000) { |
| 220 | /* Negative */ |
| 221 | val->intval = ~val->intval & 0x7fff; |
| 222 | val->intval++; |
| 223 | val->intval *= -1; |
| 224 | } |
Philip Rakity | 91d8b0d | 2011-08-12 21:19:57 -0700 | [diff] [blame] | 225 | val->intval *= 1562500 / chip->pdata->r_sns; |
Donggeun Kim | 086ef50 | 2011-06-30 18:07:41 +0900 | [diff] [blame] | 226 | } else { |
| 227 | return -EINVAL; |
| 228 | } |
| 229 | break; |
| 230 | case POWER_SUPPLY_PROP_CURRENT_AVG: |
| 231 | if (chip->pdata->enable_current_sense) { |
Ramakrishna Pallala | 60a1f6e | 2011-11-26 04:11:15 +0400 | [diff] [blame] | 232 | ret = max17042_read_reg(chip->client, |
| 233 | MAX17042_AvgCurrent); |
| 234 | if (ret < 0) |
| 235 | return ret; |
| 236 | |
| 237 | val->intval = ret; |
Donggeun Kim | 086ef50 | 2011-06-30 18:07:41 +0900 | [diff] [blame] | 238 | if (val->intval & 0x8000) { |
| 239 | /* Negative */ |
| 240 | val->intval = ~val->intval & 0x7fff; |
| 241 | val->intval++; |
| 242 | val->intval *= -1; |
| 243 | } |
| 244 | val->intval *= 1562500 / chip->pdata->r_sns; |
| 245 | } else { |
| 246 | return -EINVAL; |
| 247 | } |
| 248 | break; |
MyungJoo Ham | 359ab9f | 2011-01-14 14:46:11 +0900 | [diff] [blame] | 249 | default: |
| 250 | return -EINVAL; |
| 251 | } |
| 252 | return 0; |
| 253 | } |
| 254 | |
Ramakrishna Pallala | f3a71a6 | 2012-03-13 22:03:52 +0400 | [diff] [blame] | 255 | static int max17042_write_verify_reg(struct i2c_client *client, |
| 256 | u8 reg, u16 value) |
| 257 | { |
| 258 | int retries = 8; |
| 259 | int ret; |
| 260 | u16 read_value; |
| 261 | |
| 262 | do { |
| 263 | ret = i2c_smbus_write_word_data(client, reg, value); |
| 264 | read_value = max17042_read_reg(client, reg); |
| 265 | if (read_value != value) { |
| 266 | ret = -EIO; |
| 267 | retries--; |
| 268 | } |
| 269 | } while (retries && read_value != value); |
| 270 | |
| 271 | if (ret < 0) |
| 272 | dev_err(&client->dev, "%s: err %d\n", __func__, ret); |
| 273 | |
| 274 | return ret; |
| 275 | } |
| 276 | |
| 277 | static inline void max17042_override_por( |
| 278 | struct i2c_client *client, u8 reg, u16 value) |
| 279 | { |
| 280 | if (value) |
| 281 | max17042_write_reg(client, reg, value); |
| 282 | } |
| 283 | |
| 284 | static inline void max10742_unlock_model(struct max17042_chip *chip) |
| 285 | { |
| 286 | struct i2c_client *client = chip->client; |
| 287 | max17042_write_reg(client, MAX17042_MLOCKReg1, MODEL_UNLOCK1); |
| 288 | max17042_write_reg(client, MAX17042_MLOCKReg2, MODEL_UNLOCK2); |
| 289 | } |
| 290 | |
| 291 | static inline void max10742_lock_model(struct max17042_chip *chip) |
| 292 | { |
| 293 | struct i2c_client *client = chip->client; |
| 294 | max17042_write_reg(client, MAX17042_MLOCKReg1, MODEL_LOCK1); |
| 295 | max17042_write_reg(client, MAX17042_MLOCKReg2, MODEL_LOCK2); |
| 296 | } |
| 297 | |
| 298 | static inline void max17042_write_model_data(struct max17042_chip *chip, |
| 299 | u8 addr, int size) |
| 300 | { |
| 301 | struct i2c_client *client = chip->client; |
| 302 | int i; |
| 303 | for (i = 0; i < size; i++) |
| 304 | max17042_write_reg(client, addr + i, |
| 305 | chip->pdata->config_data->cell_char_tbl[i]); |
| 306 | } |
| 307 | |
| 308 | static inline void max17042_read_model_data(struct max17042_chip *chip, |
| 309 | u8 addr, u16 *data, int size) |
| 310 | { |
| 311 | struct i2c_client *client = chip->client; |
| 312 | int i; |
| 313 | |
| 314 | for (i = 0; i < size; i++) |
| 315 | data[i] = max17042_read_reg(client, addr + i); |
| 316 | } |
| 317 | |
| 318 | static inline int max17042_model_data_compare(struct max17042_chip *chip, |
| 319 | u16 *data1, u16 *data2, int size) |
| 320 | { |
| 321 | int i; |
| 322 | |
| 323 | if (memcmp(data1, data2, size)) { |
| 324 | dev_err(&chip->client->dev, "%s compare failed\n", __func__); |
| 325 | for (i = 0; i < size; i++) |
| 326 | dev_info(&chip->client->dev, "0x%x, 0x%x", |
| 327 | data1[i], data2[i]); |
| 328 | dev_info(&chip->client->dev, "\n"); |
| 329 | return -EINVAL; |
| 330 | } |
| 331 | return 0; |
| 332 | } |
| 333 | |
| 334 | static int max17042_init_model(struct max17042_chip *chip) |
| 335 | { |
| 336 | int ret; |
Dan Carpenter | 1ef3d8f | 2012-03-15 14:37:32 +0300 | [diff] [blame] | 337 | int table_size = ARRAY_SIZE(chip->pdata->config_data->cell_char_tbl); |
Ramakrishna Pallala | f3a71a6 | 2012-03-13 22:03:52 +0400 | [diff] [blame] | 338 | u16 *temp_data; |
| 339 | |
Dan Carpenter | 1ef3d8f | 2012-03-15 14:37:32 +0300 | [diff] [blame] | 340 | temp_data = kcalloc(table_size, sizeof(*temp_data), GFP_KERNEL); |
Ramakrishna Pallala | f3a71a6 | 2012-03-13 22:03:52 +0400 | [diff] [blame] | 341 | if (!temp_data) |
| 342 | return -ENOMEM; |
| 343 | |
| 344 | max10742_unlock_model(chip); |
| 345 | max17042_write_model_data(chip, MAX17042_MODELChrTbl, |
| 346 | table_size); |
| 347 | max17042_read_model_data(chip, MAX17042_MODELChrTbl, temp_data, |
| 348 | table_size); |
| 349 | |
| 350 | ret = max17042_model_data_compare( |
| 351 | chip, |
| 352 | chip->pdata->config_data->cell_char_tbl, |
| 353 | temp_data, |
| 354 | table_size); |
| 355 | |
| 356 | max10742_lock_model(chip); |
| 357 | kfree(temp_data); |
| 358 | |
| 359 | return ret; |
| 360 | } |
| 361 | |
| 362 | static int max17042_verify_model_lock(struct max17042_chip *chip) |
| 363 | { |
| 364 | int i; |
Dan Carpenter | 1ef3d8f | 2012-03-15 14:37:32 +0300 | [diff] [blame] | 365 | int table_size = ARRAY_SIZE(chip->pdata->config_data->cell_char_tbl); |
Ramakrishna Pallala | f3a71a6 | 2012-03-13 22:03:52 +0400 | [diff] [blame] | 366 | u16 *temp_data; |
| 367 | int ret = 0; |
| 368 | |
Dan Carpenter | 1ef3d8f | 2012-03-15 14:37:32 +0300 | [diff] [blame] | 369 | temp_data = kcalloc(table_size, sizeof(*temp_data), GFP_KERNEL); |
Ramakrishna Pallala | f3a71a6 | 2012-03-13 22:03:52 +0400 | [diff] [blame] | 370 | if (!temp_data) |
| 371 | return -ENOMEM; |
| 372 | |
| 373 | max17042_read_model_data(chip, MAX17042_MODELChrTbl, temp_data, |
| 374 | table_size); |
| 375 | for (i = 0; i < table_size; i++) |
| 376 | if (temp_data[i]) |
| 377 | ret = -EINVAL; |
| 378 | |
| 379 | kfree(temp_data); |
| 380 | return ret; |
| 381 | } |
| 382 | |
| 383 | static void max17042_write_config_regs(struct max17042_chip *chip) |
| 384 | { |
| 385 | struct max17042_config_data *config = chip->pdata->config_data; |
| 386 | |
| 387 | max17042_write_reg(chip->client, MAX17042_CONFIG, config->config); |
| 388 | max17042_write_reg(chip->client, MAX17042_LearnCFG, config->learn_cfg); |
| 389 | max17042_write_reg(chip->client, MAX17042_FilterCFG, |
| 390 | config->filter_cfg); |
| 391 | max17042_write_reg(chip->client, MAX17042_RelaxCFG, config->relax_cfg); |
| 392 | } |
| 393 | |
| 394 | static void max17042_write_custom_regs(struct max17042_chip *chip) |
| 395 | { |
| 396 | struct max17042_config_data *config = chip->pdata->config_data; |
| 397 | |
| 398 | max17042_write_verify_reg(chip->client, MAX17042_RCOMP0, |
| 399 | config->rcomp0); |
| 400 | max17042_write_verify_reg(chip->client, MAX17042_TempCo, |
| 401 | config->tcompc0); |
| 402 | max17042_write_reg(chip->client, MAX17042_EmptyTempCo, |
| 403 | config->empty_tempco); |
| 404 | max17042_write_verify_reg(chip->client, MAX17042_K_empty0, |
| 405 | config->kempty0); |
| 406 | max17042_write_verify_reg(chip->client, MAX17042_ICHGTerm, |
| 407 | config->ichgt_term); |
| 408 | } |
| 409 | |
| 410 | static void max17042_update_capacity_regs(struct max17042_chip *chip) |
| 411 | { |
| 412 | struct max17042_config_data *config = chip->pdata->config_data; |
| 413 | |
| 414 | max17042_write_verify_reg(chip->client, MAX17042_FullCAP, |
| 415 | config->fullcap); |
| 416 | max17042_write_reg(chip->client, MAX17042_DesignCap, |
| 417 | config->design_cap); |
| 418 | max17042_write_verify_reg(chip->client, MAX17042_FullCAPNom, |
| 419 | config->fullcapnom); |
| 420 | } |
| 421 | |
| 422 | static void max17042_reset_vfsoc0_reg(struct max17042_chip *chip) |
| 423 | { |
| 424 | u16 vfSoc; |
| 425 | |
| 426 | vfSoc = max17042_read_reg(chip->client, MAX17042_VFSOC); |
| 427 | max17042_write_reg(chip->client, MAX17042_VFSOC0Enable, VFSOC0_UNLOCK); |
| 428 | max17042_write_verify_reg(chip->client, MAX17042_VFSOC0, vfSoc); |
| 429 | max17042_write_reg(chip->client, MAX17042_VFSOC0Enable, VFSOC0_LOCK); |
| 430 | } |
| 431 | |
| 432 | static void max17042_load_new_capacity_params(struct max17042_chip *chip) |
| 433 | { |
| 434 | u16 full_cap0, rep_cap, dq_acc, vfSoc; |
| 435 | u32 rem_cap; |
| 436 | |
| 437 | struct max17042_config_data *config = chip->pdata->config_data; |
| 438 | |
| 439 | full_cap0 = max17042_read_reg(chip->client, MAX17042_FullCAP0); |
| 440 | vfSoc = max17042_read_reg(chip->client, MAX17042_VFSOC); |
| 441 | |
| 442 | /* fg_vfSoc needs to shifted by 8 bits to get the |
| 443 | * perc in 1% accuracy, to get the right rem_cap multiply |
| 444 | * full_cap0, fg_vfSoc and devide by 100 |
| 445 | */ |
| 446 | rem_cap = ((vfSoc >> 8) * full_cap0) / 100; |
| 447 | max17042_write_verify_reg(chip->client, MAX17042_RemCap, (u16)rem_cap); |
| 448 | |
| 449 | rep_cap = (u16)rem_cap; |
| 450 | max17042_write_verify_reg(chip->client, MAX17042_RepCap, rep_cap); |
| 451 | |
| 452 | /* Write dQ_acc to 200% of Capacity and dP_acc to 200% */ |
| 453 | dq_acc = config->fullcap / dQ_ACC_DIV; |
| 454 | max17042_write_verify_reg(chip->client, MAX17042_dQacc, dq_acc); |
| 455 | max17042_write_verify_reg(chip->client, MAX17042_dPacc, dP_ACC_200); |
| 456 | |
| 457 | max17042_write_verify_reg(chip->client, MAX17042_FullCAP, |
| 458 | config->fullcap); |
| 459 | max17042_write_reg(chip->client, MAX17042_DesignCap, |
| 460 | config->design_cap); |
| 461 | max17042_write_verify_reg(chip->client, MAX17042_FullCAPNom, |
| 462 | config->fullcapnom); |
| 463 | } |
| 464 | |
| 465 | /* |
| 466 | * Block write all the override values coming from platform data. |
| 467 | * This function MUST be called before the POR initialization proceedure |
| 468 | * specified by maxim. |
| 469 | */ |
| 470 | static inline void max17042_override_por_values(struct max17042_chip *chip) |
| 471 | { |
| 472 | struct i2c_client *client = chip->client; |
| 473 | struct max17042_config_data *config = chip->pdata->config_data; |
| 474 | |
| 475 | max17042_override_por(client, MAX17042_TGAIN, config->tgain); |
| 476 | max17042_override_por(client, MAx17042_TOFF, config->toff); |
| 477 | max17042_override_por(client, MAX17042_CGAIN, config->cgain); |
| 478 | max17042_override_por(client, MAX17042_COFF, config->coff); |
| 479 | |
| 480 | max17042_override_por(client, MAX17042_VALRT_Th, config->valrt_thresh); |
| 481 | max17042_override_por(client, MAX17042_TALRT_Th, config->talrt_thresh); |
| 482 | max17042_override_por(client, MAX17042_SALRT_Th, |
| 483 | config->soc_alrt_thresh); |
| 484 | max17042_override_por(client, MAX17042_CONFIG, config->config); |
| 485 | max17042_override_por(client, MAX17042_SHDNTIMER, config->shdntimer); |
| 486 | |
| 487 | max17042_override_por(client, MAX17042_DesignCap, config->design_cap); |
| 488 | max17042_override_por(client, MAX17042_ICHGTerm, config->ichgt_term); |
| 489 | |
| 490 | max17042_override_por(client, MAX17042_AtRate, config->at_rate); |
| 491 | max17042_override_por(client, MAX17042_LearnCFG, config->learn_cfg); |
| 492 | max17042_override_por(client, MAX17042_FilterCFG, config->filter_cfg); |
| 493 | max17042_override_por(client, MAX17042_RelaxCFG, config->relax_cfg); |
| 494 | max17042_override_por(client, MAX17042_MiscCFG, config->misc_cfg); |
| 495 | max17042_override_por(client, MAX17042_MaskSOC, config->masksoc); |
| 496 | |
| 497 | max17042_override_por(client, MAX17042_FullCAP, config->fullcap); |
| 498 | max17042_override_por(client, MAX17042_FullCAPNom, config->fullcapnom); |
| 499 | max17042_override_por(client, MAX17042_SOC_empty, config->socempty); |
| 500 | max17042_override_por(client, MAX17042_LAvg_empty, config->lavg_empty); |
| 501 | max17042_override_por(client, MAX17042_dQacc, config->dqacc); |
| 502 | max17042_override_por(client, MAX17042_dPacc, config->dpacc); |
| 503 | |
| 504 | max17042_override_por(client, MAX17042_V_empty, config->vempty); |
| 505 | max17042_override_por(client, MAX17042_TempNom, config->temp_nom); |
| 506 | max17042_override_por(client, MAX17042_TempLim, config->temp_lim); |
| 507 | max17042_override_por(client, MAX17042_FCTC, config->fctc); |
| 508 | max17042_override_por(client, MAX17042_RCOMP0, config->rcomp0); |
| 509 | max17042_override_por(client, MAX17042_TempCo, config->tcompc0); |
| 510 | max17042_override_por(client, MAX17042_EmptyTempCo, |
| 511 | config->empty_tempco); |
| 512 | max17042_override_por(client, MAX17042_K_empty0, config->kempty0); |
| 513 | } |
| 514 | |
| 515 | static int max17042_init_chip(struct max17042_chip *chip) |
| 516 | { |
| 517 | int ret; |
| 518 | int val; |
| 519 | |
| 520 | max17042_override_por_values(chip); |
| 521 | /* After Power up, the MAX17042 requires 500mS in order |
| 522 | * to perform signal debouncing and initial SOC reporting |
| 523 | */ |
| 524 | msleep(500); |
| 525 | |
| 526 | /* Initialize configaration */ |
| 527 | max17042_write_config_regs(chip); |
| 528 | |
| 529 | /* write cell characterization data */ |
| 530 | ret = max17042_init_model(chip); |
| 531 | if (ret) { |
| 532 | dev_err(&chip->client->dev, "%s init failed\n", |
| 533 | __func__); |
| 534 | return -EIO; |
| 535 | } |
| 536 | max17042_verify_model_lock(chip); |
| 537 | if (ret) { |
| 538 | dev_err(&chip->client->dev, "%s lock verify failed\n", |
| 539 | __func__); |
| 540 | return -EIO; |
| 541 | } |
| 542 | /* write custom parameters */ |
| 543 | max17042_write_custom_regs(chip); |
| 544 | |
| 545 | /* update capacity params */ |
| 546 | max17042_update_capacity_regs(chip); |
| 547 | |
| 548 | /* delay must be atleast 350mS to allow VFSOC |
| 549 | * to be calculated from the new configuration |
| 550 | */ |
| 551 | msleep(350); |
| 552 | |
| 553 | /* reset vfsoc0 reg */ |
| 554 | max17042_reset_vfsoc0_reg(chip); |
| 555 | |
| 556 | /* load new capacity params */ |
| 557 | max17042_load_new_capacity_params(chip); |
| 558 | |
| 559 | /* Init complete, Clear the POR bit */ |
| 560 | val = max17042_read_reg(chip->client, MAX17042_STATUS); |
| 561 | max17042_write_reg(chip->client, MAX17042_STATUS, |
| 562 | val & (~STATUS_POR_BIT)); |
| 563 | return 0; |
| 564 | } |
| 565 | |
Ramakrishna Pallala | e5f3872 | 2012-01-24 09:26:06 -0800 | [diff] [blame] | 566 | static void max17042_set_soc_threshold(struct max17042_chip *chip, u16 off) |
| 567 | { |
| 568 | u16 soc, soc_tr; |
| 569 | |
| 570 | /* program interrupt thesholds such that we should |
| 571 | * get interrupt for every 'off' perc change in the soc |
| 572 | */ |
| 573 | soc = max17042_read_reg(chip->client, MAX17042_RepSOC) >> 8; |
| 574 | soc_tr = (soc + off) << 8; |
| 575 | soc_tr |= (soc - off); |
| 576 | max17042_write_reg(chip->client, MAX17042_SALRT_Th, soc_tr); |
| 577 | } |
| 578 | |
Ramakrishna Pallala | e5f3872 | 2012-01-24 09:26:06 -0800 | [diff] [blame] | 579 | static irqreturn_t max17042_thread_handler(int id, void *dev) |
| 580 | { |
| 581 | struct max17042_chip *chip = dev; |
| 582 | u16 val; |
| 583 | |
| 584 | val = max17042_read_reg(chip->client, MAX17042_STATUS); |
Ramakrishna Pallala | 5cdd4d7 | 2012-03-21 03:03:16 +0530 | [diff] [blame] | 585 | if ((val & STATUS_INTR_SOCMIN_BIT) || |
| 586 | (val & STATUS_INTR_SOCMAX_BIT)) { |
Ramakrishna Pallala | e5f3872 | 2012-01-24 09:26:06 -0800 | [diff] [blame] | 587 | dev_info(&chip->client->dev, "SOC threshold INTR\n"); |
| 588 | max17042_set_soc_threshold(chip, 1); |
| 589 | } |
| 590 | |
| 591 | power_supply_changed(&chip->battery); |
| 592 | return IRQ_HANDLED; |
| 593 | } |
Ramakrishna Pallala | f3a71a6 | 2012-03-13 22:03:52 +0400 | [diff] [blame] | 594 | |
| 595 | static void max17042_init_worker(struct work_struct *work) |
| 596 | { |
| 597 | struct max17042_chip *chip = container_of(work, |
| 598 | struct max17042_chip, work); |
| 599 | int ret; |
| 600 | |
| 601 | /* Initialize registers according to values from the platform data */ |
| 602 | if (chip->pdata->enable_por_init && chip->pdata->config_data) { |
| 603 | ret = max17042_init_chip(chip); |
| 604 | if (ret) |
| 605 | return; |
| 606 | } |
| 607 | |
| 608 | chip->init_complete = 1; |
| 609 | } |
| 610 | |
Karol Lewandowski | 3832246 | 2012-02-22 19:06:22 +0100 | [diff] [blame] | 611 | #ifdef CONFIG_OF |
| 612 | static struct max17042_platform_data * |
| 613 | max17042_get_pdata(struct device *dev) |
| 614 | { |
| 615 | struct device_node *np = dev->of_node; |
| 616 | u32 prop; |
| 617 | struct max17042_platform_data *pdata; |
| 618 | |
| 619 | if (!np) |
| 620 | return dev->platform_data; |
| 621 | |
| 622 | pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); |
| 623 | if (!pdata) |
| 624 | return NULL; |
| 625 | |
| 626 | /* |
| 627 | * Require current sense resistor value to be specified for |
| 628 | * current-sense functionality to be enabled at all. |
| 629 | */ |
| 630 | if (of_property_read_u32(np, "maxim,rsns-microohm", &prop) == 0) { |
| 631 | pdata->r_sns = prop; |
| 632 | pdata->enable_current_sense = true; |
| 633 | } |
| 634 | |
| 635 | return pdata; |
| 636 | } |
| 637 | #else |
| 638 | static struct max17042_platform_data * |
| 639 | max17042_get_pdata(struct device *dev) |
| 640 | { |
| 641 | return dev->platform_data; |
| 642 | } |
| 643 | #endif |
| 644 | |
MyungJoo Ham | 359ab9f | 2011-01-14 14:46:11 +0900 | [diff] [blame] | 645 | static int __devinit max17042_probe(struct i2c_client *client, |
| 646 | const struct i2c_device_id *id) |
| 647 | { |
| 648 | struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); |
| 649 | struct max17042_chip *chip; |
| 650 | int ret; |
Ramakrishna Pallala | f3a71a6 | 2012-03-13 22:03:52 +0400 | [diff] [blame] | 651 | int reg; |
MyungJoo Ham | 359ab9f | 2011-01-14 14:46:11 +0900 | [diff] [blame] | 652 | |
| 653 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WORD_DATA)) |
| 654 | return -EIO; |
| 655 | |
Karol Lewandowski | 2f3b434 | 2012-02-22 19:06:20 +0100 | [diff] [blame] | 656 | chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); |
MyungJoo Ham | 359ab9f | 2011-01-14 14:46:11 +0900 | [diff] [blame] | 657 | if (!chip) |
| 658 | return -ENOMEM; |
| 659 | |
| 660 | chip->client = client; |
Karol Lewandowski | 3832246 | 2012-02-22 19:06:22 +0100 | [diff] [blame] | 661 | chip->pdata = max17042_get_pdata(&client->dev); |
| 662 | if (!chip->pdata) { |
| 663 | dev_err(&client->dev, "no platform data provided\n"); |
| 664 | return -EINVAL; |
| 665 | } |
MyungJoo Ham | 359ab9f | 2011-01-14 14:46:11 +0900 | [diff] [blame] | 666 | |
| 667 | i2c_set_clientdata(client, chip); |
| 668 | |
| 669 | chip->battery.name = "max17042_battery"; |
| 670 | chip->battery.type = POWER_SUPPLY_TYPE_BATTERY; |
| 671 | chip->battery.get_property = max17042_get_property; |
| 672 | chip->battery.properties = max17042_battery_props; |
| 673 | chip->battery.num_properties = ARRAY_SIZE(max17042_battery_props); |
| 674 | |
Donggeun Kim | 086ef50 | 2011-06-30 18:07:41 +0900 | [diff] [blame] | 675 | /* When current is not measured, |
| 676 | * CURRENT_NOW and CURRENT_AVG properties should be invisible. */ |
| 677 | if (!chip->pdata->enable_current_sense) |
| 678 | chip->battery.num_properties -= 2; |
| 679 | |
Philip Rakity | 4cfa892 | 2011-08-12 21:18:18 -0700 | [diff] [blame] | 680 | if (chip->pdata->r_sns == 0) |
| 681 | chip->pdata->r_sns = MAX17042_DEFAULT_SNS_RESISTOR; |
| 682 | |
Donggeun Kim | 086ef50 | 2011-06-30 18:07:41 +0900 | [diff] [blame] | 683 | if (chip->pdata->init_data) |
| 684 | max17042_set_reg(client, chip->pdata->init_data, |
Ramakrishna Pallala | f3a71a6 | 2012-03-13 22:03:52 +0400 | [diff] [blame] | 685 | chip->pdata->num_init_data); |
Donggeun Kim | 086ef50 | 2011-06-30 18:07:41 +0900 | [diff] [blame] | 686 | |
MyungJoo Ham | 359ab9f | 2011-01-14 14:46:11 +0900 | [diff] [blame] | 687 | if (!chip->pdata->enable_current_sense) { |
| 688 | max17042_write_reg(client, MAX17042_CGAIN, 0x0000); |
| 689 | max17042_write_reg(client, MAX17042_MiscCFG, 0x0003); |
| 690 | max17042_write_reg(client, MAX17042_LearnCFG, 0x0007); |
| 691 | } |
| 692 | |
Ramakrishna Pallala | 243e352 | 2012-05-05 03:08:37 +0530 | [diff] [blame] | 693 | ret = power_supply_register(&client->dev, &chip->battery); |
| 694 | if (ret) { |
| 695 | dev_err(&client->dev, "failed: power supply register\n"); |
| 696 | return ret; |
| 697 | } |
| 698 | |
Ramakrishna Pallala | e5f3872 | 2012-01-24 09:26:06 -0800 | [diff] [blame] | 699 | if (client->irq) { |
Ramakrishna Pallala | 5cdd4d7 | 2012-03-21 03:03:16 +0530 | [diff] [blame] | 700 | ret = request_threaded_irq(client->irq, NULL, |
Ramakrishna Pallala | e5f3872 | 2012-01-24 09:26:06 -0800 | [diff] [blame] | 701 | max17042_thread_handler, |
Ramakrishna Pallala | 5cdd4d7 | 2012-03-21 03:03:16 +0530 | [diff] [blame] | 702 | IRQF_TRIGGER_FALLING, |
| 703 | chip->battery.name, chip); |
Ramakrishna Pallala | e5f3872 | 2012-01-24 09:26:06 -0800 | [diff] [blame] | 704 | if (!ret) { |
| 705 | reg = max17042_read_reg(client, MAX17042_CONFIG); |
| 706 | reg |= CONFIG_ALRT_BIT_ENBL; |
| 707 | max17042_write_reg(client, MAX17042_CONFIG, reg); |
| 708 | max17042_set_soc_threshold(chip, 1); |
Ramakrishna Pallala | e5ba50b | 2012-05-05 04:43:10 +0530 | [diff] [blame^] | 709 | } else { |
| 710 | client->irq = 0; |
Ramakrishna Pallala | e5f3872 | 2012-01-24 09:26:06 -0800 | [diff] [blame] | 711 | dev_err(&client->dev, "%s(): cannot get IRQ\n", |
| 712 | __func__); |
Ramakrishna Pallala | e5ba50b | 2012-05-05 04:43:10 +0530 | [diff] [blame^] | 713 | } |
Ramakrishna Pallala | e5f3872 | 2012-01-24 09:26:06 -0800 | [diff] [blame] | 714 | } |
| 715 | |
Ramakrishna Pallala | f3a71a6 | 2012-03-13 22:03:52 +0400 | [diff] [blame] | 716 | reg = max17042_read_reg(chip->client, MAX17042_STATUS); |
Ramakrishna Pallala | f3a71a6 | 2012-03-13 22:03:52 +0400 | [diff] [blame] | 717 | if (reg & STATUS_POR_BIT) { |
| 718 | INIT_WORK(&chip->work, max17042_init_worker); |
| 719 | schedule_work(&chip->work); |
| 720 | } else { |
| 721 | chip->init_complete = 1; |
| 722 | } |
| 723 | |
Ramakrishna Pallala | 243e352 | 2012-05-05 03:08:37 +0530 | [diff] [blame] | 724 | return 0; |
MyungJoo Ham | 359ab9f | 2011-01-14 14:46:11 +0900 | [diff] [blame] | 725 | } |
| 726 | |
| 727 | static int __devexit max17042_remove(struct i2c_client *client) |
| 728 | { |
| 729 | struct max17042_chip *chip = i2c_get_clientdata(client); |
| 730 | |
Ramakrishna Pallala | bb28da9 | 2012-03-26 15:38:26 +0530 | [diff] [blame] | 731 | if (client->irq) |
| 732 | free_irq(client->irq, chip); |
MyungJoo Ham | 359ab9f | 2011-01-14 14:46:11 +0900 | [diff] [blame] | 733 | power_supply_unregister(&chip->battery); |
MyungJoo Ham | 359ab9f | 2011-01-14 14:46:11 +0900 | [diff] [blame] | 734 | return 0; |
| 735 | } |
| 736 | |
Ramakrishna Pallala | 48bc177 | 2012-03-27 02:23:40 +0530 | [diff] [blame] | 737 | #ifdef CONFIG_PM |
| 738 | static int max17042_suspend(struct device *dev) |
| 739 | { |
| 740 | struct max17042_chip *chip = dev_get_drvdata(dev); |
| 741 | |
Anton Vorontsov | 48e41c7 | 2012-05-04 20:38:13 -0700 | [diff] [blame] | 742 | /* |
| 743 | * disable the irq and enable irq_wake |
Ramakrishna Pallala | 48bc177 | 2012-03-27 02:23:40 +0530 | [diff] [blame] | 744 | * capability to the interrupt line. |
| 745 | */ |
| 746 | if (chip->client->irq) { |
| 747 | disable_irq(chip->client->irq); |
| 748 | enable_irq_wake(chip->client->irq); |
| 749 | } |
| 750 | |
| 751 | return 0; |
| 752 | } |
| 753 | |
| 754 | static int max17042_resume(struct device *dev) |
| 755 | { |
| 756 | struct max17042_chip *chip = dev_get_drvdata(dev); |
| 757 | |
| 758 | if (chip->client->irq) { |
| 759 | disable_irq_wake(chip->client->irq); |
| 760 | enable_irq(chip->client->irq); |
| 761 | /* re-program the SOC thresholds to 1% change */ |
| 762 | max17042_set_soc_threshold(chip, 1); |
| 763 | } |
| 764 | |
| 765 | return 0; |
| 766 | } |
Anton Vorontsov | 48e41c7 | 2012-05-04 20:38:13 -0700 | [diff] [blame] | 767 | |
| 768 | static const struct dev_pm_ops max17042_pm_ops = { |
| 769 | .suspend = max17042_suspend, |
| 770 | .resume = max17042_resume, |
| 771 | }; |
| 772 | |
| 773 | #define MAX17042_PM_OPS (&max17042_pm_ops) |
Ramakrishna Pallala | 48bc177 | 2012-03-27 02:23:40 +0530 | [diff] [blame] | 774 | #else |
Anton Vorontsov | 48e41c7 | 2012-05-04 20:38:13 -0700 | [diff] [blame] | 775 | #define MAX17042_PM_OPS NULL |
Ramakrishna Pallala | 48bc177 | 2012-03-27 02:23:40 +0530 | [diff] [blame] | 776 | #endif |
| 777 | |
Karol Lewandowski | 3832246 | 2012-02-22 19:06:22 +0100 | [diff] [blame] | 778 | #ifdef CONFIG_OF |
| 779 | static const struct of_device_id max17042_dt_match[] = { |
| 780 | { .compatible = "maxim,max17042" }, |
| 781 | { }, |
| 782 | }; |
| 783 | MODULE_DEVICE_TABLE(of, max17042_dt_match); |
| 784 | #endif |
| 785 | |
MyungJoo Ham | 359ab9f | 2011-01-14 14:46:11 +0900 | [diff] [blame] | 786 | static const struct i2c_device_id max17042_id[] = { |
| 787 | { "max17042", 0 }, |
| 788 | { } |
| 789 | }; |
| 790 | MODULE_DEVICE_TABLE(i2c, max17042_id); |
| 791 | |
| 792 | static struct i2c_driver max17042_i2c_driver = { |
| 793 | .driver = { |
| 794 | .name = "max17042", |
Karol Lewandowski | 3832246 | 2012-02-22 19:06:22 +0100 | [diff] [blame] | 795 | .of_match_table = of_match_ptr(max17042_dt_match), |
Anton Vorontsov | 48e41c7 | 2012-05-04 20:38:13 -0700 | [diff] [blame] | 796 | .pm = MAX17042_PM_OPS, |
MyungJoo Ham | 359ab9f | 2011-01-14 14:46:11 +0900 | [diff] [blame] | 797 | }, |
| 798 | .probe = max17042_probe, |
| 799 | .remove = __devexit_p(max17042_remove), |
| 800 | .id_table = max17042_id, |
| 801 | }; |
Axel Lin | 5ff92e7 | 2012-01-21 14:42:54 +0800 | [diff] [blame] | 802 | module_i2c_driver(max17042_i2c_driver); |
MyungJoo Ham | 359ab9f | 2011-01-14 14:46:11 +0900 | [diff] [blame] | 803 | |
| 804 | MODULE_AUTHOR("MyungJoo Ham <myungjoo.ham@samsung.com>"); |
| 805 | MODULE_DESCRIPTION("MAX17042 Fuel Gauge"); |
| 806 | MODULE_LICENSE("GPL"); |