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