aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/power
diff options
context:
space:
mode:
authorSebastian Reichel <sre@kernel.org>2014-09-24 19:55:14 -0400
committerSebastian Reichel <sre@kernel.org>2014-09-24 19:55:14 -0400
commitfd642bb94c75f08ed15111a7fe75027da6abdd07 (patch)
tree0940fb421270eb0fb80f9700f90335c8acf6672a /drivers/power
parent4d96fb1ec81118c6406fe6d3670f172b2faaedf3 (diff)
parentd6cc1f5824cbca392d099f3bb0c441efd9e54de9 (diff)
Merge tag 'tags/mfd-power-charger-regulator-v3.18' into next
Immutable branch between MFD, Power, Charger and Regulator for v3.18
Diffstat (limited to 'drivers/power')
-rw-r--r--drivers/power/Kconfig5
-rw-r--r--drivers/power/max14577_charger.c370
-rw-r--r--drivers/power/max17040_battery.c3
3 files changed, 341 insertions, 37 deletions
diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig
index 73cfcdf28a36..04e1d2fe2201 100644
--- a/drivers/power/Kconfig
+++ b/drivers/power/Kconfig
@@ -325,11 +325,12 @@ config CHARGER_MANAGER
325 with help of suspend_again support. 325 with help of suspend_again support.
326 326
327config CHARGER_MAX14577 327config CHARGER_MAX14577
328 tristate "Maxim MAX14577 MUIC battery charger driver" 328 tristate "Maxim MAX14577/77836 battery charger driver"
329 depends on MFD_MAX14577 329 depends on MFD_MAX14577
330 select SYSFS
330 help 331 help
331 Say Y to enable support for the battery charger control sysfs and 332 Say Y to enable support for the battery charger control sysfs and
332 platform data of MAX14577 MUICs. 333 platform data of MAX14577/77836 MUICs.
333 334
334config CHARGER_MAX8997 335config CHARGER_MAX8997
335 tristate "Maxim MAX8997/MAX8966 PMIC battery charger driver" 336 tristate "Maxim MAX8997/MAX8966 PMIC battery charger driver"
diff --git a/drivers/power/max14577_charger.c b/drivers/power/max14577_charger.c
index fad2a75b3604..0a2bc7277026 100644
--- a/drivers/power/max14577_charger.c
+++ b/drivers/power/max14577_charger.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Battery charger driver for the Maxim 14577 2 * max14577_charger.c - Battery charger driver for the Maxim 14577/77836
3 * 3 *
4 * Copyright (C) 2013 Samsung Electronics 4 * Copyright (C) 2013,2014 Samsung Electronics
5 * Krzysztof Kozlowski <k.kozlowski@samsung.com> 5 * Krzysztof Kozlowski <k.kozlowski@samsung.com>
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify 7 * This program is free software; you can redistribute it and/or modify
@@ -19,16 +19,44 @@
19#include <linux/platform_device.h> 19#include <linux/platform_device.h>
20#include <linux/power_supply.h> 20#include <linux/power_supply.h>
21#include <linux/mfd/max14577-private.h> 21#include <linux/mfd/max14577-private.h>
22#include <linux/mfd/max14577.h>
22 23
23struct max14577_charger { 24struct max14577_charger {
24 struct device *dev; 25 struct device *dev;
25 struct max14577 *max14577; 26 struct max14577 *max14577;
26 struct power_supply charger; 27 struct power_supply charger;
27 28
28 unsigned int charging_state; 29 unsigned int charging_state;
29 unsigned int battery_state; 30 unsigned int battery_state;
31
32 struct max14577_charger_platform_data *pdata;
30}; 33};
31 34
35/*
36 * Helper function for mapping values of STATUS2/CHGTYP register on max14577
37 * and max77836 chipsets to enum maxim_muic_charger_type.
38 */
39static enum max14577_muic_charger_type maxim_get_charger_type(
40 enum maxim_device_type dev_type, u8 val) {
41 switch (val) {
42 case MAX14577_CHARGER_TYPE_NONE:
43 case MAX14577_CHARGER_TYPE_USB:
44 case MAX14577_CHARGER_TYPE_DOWNSTREAM_PORT:
45 case MAX14577_CHARGER_TYPE_DEDICATED_CHG:
46 case MAX14577_CHARGER_TYPE_SPECIAL_500MA:
47 case MAX14577_CHARGER_TYPE_SPECIAL_1A:
48 return val;
49 case MAX14577_CHARGER_TYPE_DEAD_BATTERY:
50 case MAX14577_CHARGER_TYPE_RESERVED:
51 if (dev_type == MAXIM_DEVICE_TYPE_MAX77836)
52 val |= 0x8;
53 return val;
54 default:
55 WARN_ONCE(1, "max14577: Unsupported chgtyp register value 0x%02x", val);
56 return val;
57 }
58}
59
32static int max14577_get_charger_state(struct max14577_charger *chg) 60static int max14577_get_charger_state(struct max14577_charger *chg)
33{ 61{
34 struct regmap *rmap = chg->max14577->regmap; 62 struct regmap *rmap = chg->max14577->regmap;
@@ -89,19 +117,23 @@ static int max14577_get_online(struct max14577_charger *chg)
89{ 117{
90 struct regmap *rmap = chg->max14577->regmap; 118 struct regmap *rmap = chg->max14577->regmap;
91 u8 reg_data; 119 u8 reg_data;
120 enum max14577_muic_charger_type chg_type;
92 121
93 max14577_read_reg(rmap, MAX14577_MUIC_REG_STATUS2, &reg_data); 122 max14577_read_reg(rmap, MAX14577_MUIC_REG_STATUS2, &reg_data);
94 reg_data = ((reg_data & STATUS2_CHGTYP_MASK) >> STATUS2_CHGTYP_SHIFT); 123 reg_data = ((reg_data & STATUS2_CHGTYP_MASK) >> STATUS2_CHGTYP_SHIFT);
95 switch (reg_data) { 124 chg_type = maxim_get_charger_type(chg->max14577->dev_type, reg_data);
125 switch (chg_type) {
96 case MAX14577_CHARGER_TYPE_USB: 126 case MAX14577_CHARGER_TYPE_USB:
97 case MAX14577_CHARGER_TYPE_DEDICATED_CHG: 127 case MAX14577_CHARGER_TYPE_DEDICATED_CHG:
98 case MAX14577_CHARGER_TYPE_SPECIAL_500MA: 128 case MAX14577_CHARGER_TYPE_SPECIAL_500MA:
99 case MAX14577_CHARGER_TYPE_SPECIAL_1A: 129 case MAX14577_CHARGER_TYPE_SPECIAL_1A:
100 case MAX14577_CHARGER_TYPE_DEAD_BATTERY: 130 case MAX14577_CHARGER_TYPE_DEAD_BATTERY:
131 case MAX77836_CHARGER_TYPE_SPECIAL_BIAS:
101 return 1; 132 return 1;
102 case MAX14577_CHARGER_TYPE_NONE: 133 case MAX14577_CHARGER_TYPE_NONE:
103 case MAX14577_CHARGER_TYPE_DOWNSTREAM_PORT: 134 case MAX14577_CHARGER_TYPE_DOWNSTREAM_PORT:
104 case MAX14577_CHARGER_TYPE_RESERVED: 135 case MAX14577_CHARGER_TYPE_RESERVED:
136 case MAX77836_CHARGER_TYPE_RESERVED:
105 default: 137 default:
106 return 0; 138 return 0;
107 } 139 }
@@ -118,10 +150,12 @@ static int max14577_get_battery_health(struct max14577_charger *chg)
118 struct regmap *rmap = chg->max14577->regmap; 150 struct regmap *rmap = chg->max14577->regmap;
119 int state = POWER_SUPPLY_HEALTH_GOOD; 151 int state = POWER_SUPPLY_HEALTH_GOOD;
120 u8 reg_data; 152 u8 reg_data;
153 enum max14577_muic_charger_type chg_type;
121 154
122 max14577_read_reg(rmap, MAX14577_MUIC_REG_STATUS2, &reg_data); 155 max14577_read_reg(rmap, MAX14577_MUIC_REG_STATUS2, &reg_data);
123 reg_data = ((reg_data & STATUS2_CHGTYP_MASK) >> STATUS2_CHGTYP_SHIFT); 156 reg_data = ((reg_data & STATUS2_CHGTYP_MASK) >> STATUS2_CHGTYP_SHIFT);
124 if (reg_data == MAX14577_CHARGER_TYPE_DEAD_BATTERY) { 157 chg_type = maxim_get_charger_type(chg->max14577->dev_type, reg_data);
158 if (chg_type == MAX14577_CHARGER_TYPE_DEAD_BATTERY) {
125 state = POWER_SUPPLY_HEALTH_DEAD; 159 state = POWER_SUPPLY_HEALTH_DEAD;
126 goto state_set; 160 goto state_set;
127 } 161 }
@@ -147,15 +181,131 @@ static int max14577_get_present(struct max14577_charger *chg)
147 return 1; 181 return 1;
148} 182}
149 183
184static int max14577_set_fast_charge_timer(struct max14577_charger *chg,
185 unsigned long hours)
186{
187 u8 reg_data;
188
189 switch (hours) {
190 case 5 ... 7:
191 reg_data = hours - 3;
192 break;
193 case 0:
194 /* Disable */
195 reg_data = 0x7;
196 break;
197 default:
198 dev_err(chg->dev, "Wrong value for Fast-Charge Timer: %lu\n",
199 hours);
200 return -EINVAL;
201 }
202 reg_data <<= CHGCTRL1_TCHW_SHIFT;
203
204 return max14577_update_reg(chg->max14577->regmap,
205 MAX14577_REG_CHGCTRL1, CHGCTRL1_TCHW_MASK, reg_data);
206}
207
208static int max14577_init_constant_voltage(struct max14577_charger *chg,
209 unsigned int uvolt)
210{
211 u8 reg_data;
212
213 if (uvolt < MAXIM_CHARGER_CONSTANT_VOLTAGE_MIN ||
214 uvolt > MAXIM_CHARGER_CONSTANT_VOLTAGE_MAX)
215 return -EINVAL;
216
217 if (uvolt == 4200000)
218 reg_data = 0x0;
219 else if (uvolt == MAXIM_CHARGER_CONSTANT_VOLTAGE_MAX)
220 reg_data = 0x1f;
221 else if (uvolt <= 4280000) {
222 unsigned int val = uvolt;
223
224 val -= MAXIM_CHARGER_CONSTANT_VOLTAGE_MIN;
225 val /= MAXIM_CHARGER_CONSTANT_VOLTAGE_STEP;
226 if (uvolt <= 4180000)
227 reg_data = 0x1 + val;
228 else
229 reg_data = val; /* Fix for gap between 4.18V and 4.22V */
230 } else
231 return -EINVAL;
232
233 reg_data <<= CHGCTRL3_MBCCVWRC_SHIFT;
234
235 return max14577_write_reg(chg->max14577->regmap,
236 MAX14577_CHG_REG_CHG_CTRL3, reg_data);
237}
238
239static int max14577_init_eoc(struct max14577_charger *chg,
240 unsigned int uamp)
241{
242 unsigned int current_bits = 0xf;
243 u8 reg_data;
244
245 switch (chg->max14577->dev_type) {
246 case MAXIM_DEVICE_TYPE_MAX77836:
247 if (uamp < 5000)
248 return -EINVAL; /* Requested current is too low */
249
250 if (uamp >= 7500 && uamp < 10000)
251 current_bits = 0x0;
252 else if (uamp <= 50000) {
253 /* <5000, 7499> and <10000, 50000> */
254 current_bits = uamp / 5000;
255 } else {
256 uamp = min(uamp, 100000U) - 50000U;
257 current_bits = 0xa + uamp / 10000;
258 }
259 break;
260
261 case MAXIM_DEVICE_TYPE_MAX14577:
262 default:
263 if (uamp < MAX14577_CHARGER_EOC_CURRENT_LIMIT_MIN)
264 return -EINVAL; /* Requested current is too low */
265
266 uamp = min(uamp, MAX14577_CHARGER_EOC_CURRENT_LIMIT_MAX);
267 uamp -= MAX14577_CHARGER_EOC_CURRENT_LIMIT_MIN;
268 current_bits = uamp / MAX14577_CHARGER_EOC_CURRENT_LIMIT_STEP;
269 break;
270 }
271
272 reg_data = current_bits << CHGCTRL5_EOCS_SHIFT;
273
274 return max14577_update_reg(chg->max14577->regmap,
275 MAX14577_CHG_REG_CHG_CTRL5, CHGCTRL5_EOCS_MASK,
276 reg_data);
277}
278
279static int max14577_init_fast_charge(struct max14577_charger *chg,
280 unsigned int uamp)
281{
282 u8 reg_data;
283 int ret;
284 const struct maxim_charger_current *limits =
285 &maxim_charger_currents[chg->max14577->dev_type];
286
287 ret = maxim_charger_calc_reg_current(limits, uamp, uamp, &reg_data);
288 if (ret) {
289 dev_err(chg->dev, "Wrong value for fast charge: %u\n", uamp);
290 return ret;
291 }
292
293 return max14577_update_reg(chg->max14577->regmap,
294 MAX14577_CHG_REG_CHG_CTRL4,
295 CHGCTRL4_MBCICHWRCL_MASK | CHGCTRL4_MBCICHWRCH_MASK,
296 reg_data);
297}
298
150/* 299/*
151 * Sets charger registers to proper and safe default values. 300 * Sets charger registers to proper and safe default values.
152 * Some of these values are equal to defaults in MAX14577E 301 * Some of these values are equal to defaults in MAX14577E
153 * data sheet but there are minor differences. 302 * data sheet but there are minor differences.
154 */ 303 */
155static void max14577_charger_reg_init(struct max14577_charger *chg) 304static int max14577_charger_reg_init(struct max14577_charger *chg)
156{ 305{
157 struct regmap *rmap = chg->max14577->regmap; 306 struct regmap *rmap = chg->max14577->regmap;
158 u8 reg_data; 307 u8 reg_data;
308 int ret;
159 309
160 /* 310 /*
161 * Charger-Type Manual Detection, default off (set CHGTYPMAN to 0) 311 * Charger-Type Manual Detection, default off (set CHGTYPMAN to 0)
@@ -167,10 +317,6 @@ static void max14577_charger_reg_init(struct max14577_charger *chg)
167 CDETCTRL1_CHGDETEN_MASK | CDETCTRL1_CHGTYPMAN_MASK, 317 CDETCTRL1_CHGDETEN_MASK | CDETCTRL1_CHGTYPMAN_MASK,
168 reg_data); 318 reg_data);
169 319
170 /* Battery Fast-Charge Timer, from SM-V700: 6hrs */
171 reg_data = 0x3 << CHGCTRL1_TCHW_SHIFT;
172 max14577_write_reg(rmap, MAX14577_REG_CHGCTRL1, reg_data);
173
174 /* 320 /*
175 * Wall-Adapter Rapid Charge, default on 321 * Wall-Adapter Rapid Charge, default on
176 * Battery-Charger, default on 322 * Battery-Charger, default on
@@ -179,29 +325,46 @@ static void max14577_charger_reg_init(struct max14577_charger *chg)
179 reg_data |= 0x1 << CHGCTRL2_MBCHOSTEN_SHIFT; 325 reg_data |= 0x1 << CHGCTRL2_MBCHOSTEN_SHIFT;
180 max14577_write_reg(rmap, MAX14577_REG_CHGCTRL2, reg_data); 326 max14577_write_reg(rmap, MAX14577_REG_CHGCTRL2, reg_data);
181 327
182 /* Battery-Charger Constant Voltage (CV) Mode, from SM-V700: 4.35V */
183 reg_data = 0xf << CHGCTRL3_MBCCVWRC_SHIFT;
184 max14577_write_reg(rmap, MAX14577_REG_CHGCTRL3, reg_data);
185
186 /*
187 * Fast Battery-Charge Current Low, default 200-950mA
188 * Fast Battery-Charge Current High, from SM-V700: 450mA
189 */
190 reg_data = 0x1 << CHGCTRL4_MBCICHWRCL_SHIFT;
191 reg_data |= 0x5 << CHGCTRL4_MBCICHWRCH_SHIFT;
192 max14577_write_reg(rmap, MAX14577_REG_CHGCTRL4, reg_data);
193
194 /* End-of-Charge Current, from SM-V700: 50mA */
195 reg_data = 0x0 << CHGCTRL5_EOCS_SHIFT;
196 max14577_write_reg(rmap, MAX14577_REG_CHGCTRL5, reg_data);
197
198 /* Auto Charging Stop, default off */ 328 /* Auto Charging Stop, default off */
199 reg_data = 0x0 << CHGCTRL6_AUTOSTOP_SHIFT; 329 reg_data = 0x0 << CHGCTRL6_AUTOSTOP_SHIFT;
200 max14577_write_reg(rmap, MAX14577_REG_CHGCTRL6, reg_data); 330 max14577_write_reg(rmap, MAX14577_REG_CHGCTRL6, reg_data);
201 331
202 /* Overvoltage-Protection Threshold, from SM-V700: 6.5V */ 332 ret = max14577_init_constant_voltage(chg, chg->pdata->constant_uvolt);
203 reg_data = 0x2 << CHGCTRL7_OTPCGHCVS_SHIFT; 333 if (ret)
334 return ret;
335
336 ret = max14577_init_eoc(chg, chg->pdata->eoc_uamp);
337 if (ret)
338 return ret;
339
340 ret = max14577_init_fast_charge(chg, chg->pdata->fast_charge_uamp);
341 if (ret)
342 return ret;
343
344 ret = max14577_set_fast_charge_timer(chg,
345 MAXIM_CHARGER_FAST_CHARGE_TIMER_DEFAULT);
346 if (ret)
347 return ret;
348
349 /* Initialize Overvoltage-Protection Threshold */
350 switch (chg->pdata->ovp_uvolt) {
351 case 7500000:
352 reg_data = 0x0;
353 break;
354 case 6000000:
355 case 6500000:
356 case 7000000:
357 reg_data = 0x1 + (chg->pdata->ovp_uvolt - 6000000) / 500000;
358 break;
359 default:
360 dev_err(chg->dev, "Wrong value for OVP: %u\n",
361 chg->pdata->ovp_uvolt);
362 return -EINVAL;
363 }
364 reg_data <<= CHGCTRL7_OTPCGHCVS_SHIFT;
204 max14577_write_reg(rmap, MAX14577_REG_CHGCTRL7, reg_data); 365 max14577_write_reg(rmap, MAX14577_REG_CHGCTRL7, reg_data);
366
367 return 0;
205} 368}
206 369
207/* Support property from charger */ 370/* Support property from charger */
@@ -215,7 +378,11 @@ static enum power_supply_property max14577_charger_props[] = {
215 POWER_SUPPLY_PROP_MANUFACTURER, 378 POWER_SUPPLY_PROP_MANUFACTURER,
216}; 379};
217 380
218static const char *model_name = "MAX14577"; 381static const char * const model_names[] = {
382 [MAXIM_DEVICE_TYPE_UNKNOWN] = "MAX14577-like",
383 [MAXIM_DEVICE_TYPE_MAX14577] = "MAX14577",
384 [MAXIM_DEVICE_TYPE_MAX77836] = "MAX77836",
385};
219static const char *manufacturer = "Maxim Integrated"; 386static const char *manufacturer = "Maxim Integrated";
220 387
221static int max14577_charger_get_property(struct power_supply *psy, 388static int max14577_charger_get_property(struct power_supply *psy,
@@ -244,7 +411,8 @@ static int max14577_charger_get_property(struct power_supply *psy,
244 val->intval = max14577_get_online(chg); 411 val->intval = max14577_get_online(chg);
245 break; 412 break;
246 case POWER_SUPPLY_PROP_MODEL_NAME: 413 case POWER_SUPPLY_PROP_MODEL_NAME:
247 val->strval = model_name; 414 BUILD_BUG_ON(ARRAY_SIZE(model_names) != MAXIM_DEVICE_TYPE_NUM);
415 val->strval = model_names[chg->max14577->dev_type];
248 break; 416 break;
249 case POWER_SUPPLY_PROP_MANUFACTURER: 417 case POWER_SUPPLY_PROP_MANUFACTURER:
250 val->strval = manufacturer; 418 val->strval = manufacturer;
@@ -256,6 +424,110 @@ static int max14577_charger_get_property(struct power_supply *psy,
256 return ret; 424 return ret;
257} 425}
258 426
427#ifdef CONFIG_OF
428static struct max14577_charger_platform_data *max14577_charger_dt_init(
429 struct platform_device *pdev)
430{
431 struct max14577_charger_platform_data *pdata;
432 struct device_node *np = pdev->dev.of_node;
433 int ret;
434
435 if (!np) {
436 dev_err(&pdev->dev, "No charger OF node\n");
437 return ERR_PTR(-EINVAL);
438 }
439
440 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
441 if (!pdata)
442 return ERR_PTR(-ENOMEM);
443
444 ret = of_property_read_u32(np, "maxim,constant-uvolt",
445 &pdata->constant_uvolt);
446 if (ret) {
447 dev_err(&pdev->dev, "Cannot parse maxim,constant-uvolt field from DT\n");
448 return ERR_PTR(ret);
449 }
450
451 ret = of_property_read_u32(np, "maxim,fast-charge-uamp",
452 &pdata->fast_charge_uamp);
453 if (ret) {
454 dev_err(&pdev->dev, "Cannot parse maxim,fast-charge-uamp field from DT\n");
455 return ERR_PTR(ret);
456 }
457
458 ret = of_property_read_u32(np, "maxim,eoc-uamp", &pdata->eoc_uamp);
459 if (ret) {
460 dev_err(&pdev->dev, "Cannot parse maxim,eoc-uamp field from DT\n");
461 return ERR_PTR(ret);
462 }
463
464 ret = of_property_read_u32(np, "maxim,ovp-uvolt", &pdata->ovp_uvolt);
465 if (ret) {
466 dev_err(&pdev->dev, "Cannot parse maxim,ovp-uvolt field from DT\n");
467 return ERR_PTR(ret);
468 }
469
470 return pdata;
471}
472#else /* CONFIG_OF */
473static struct max14577_charger_platform_data *max14577_charger_dt_init(
474 struct platform_device *pdev)
475{
476 return NULL;
477}
478#endif /* CONFIG_OF */
479
480static ssize_t show_fast_charge_timer(struct device *dev,
481 struct device_attribute *attr, char *buf)
482{
483 struct max14577_charger *chg = dev_get_drvdata(dev);
484 u8 reg_data;
485 int ret;
486 unsigned int val;
487
488 ret = max14577_read_reg(chg->max14577->regmap, MAX14577_REG_CHGCTRL1,
489 &reg_data);
490 if (ret)
491 return ret;
492
493 reg_data &= CHGCTRL1_TCHW_MASK;
494 reg_data >>= CHGCTRL1_TCHW_SHIFT;
495 switch (reg_data) {
496 case 0x2 ... 0x4:
497 val = reg_data + 3;
498 break;
499 case 0x7:
500 val = 0;
501 break;
502 default:
503 val = 5;
504 break;
505 }
506
507 return scnprintf(buf, PAGE_SIZE, "%u\n", val);
508}
509
510static ssize_t store_fast_charge_timer(struct device *dev,
511 struct device_attribute *attr, const char *buf, size_t count)
512{
513 struct max14577_charger *chg = dev_get_drvdata(dev);
514 unsigned long val;
515 int ret;
516
517 ret = kstrtoul(buf, 10, &val);
518 if (ret)
519 return ret;
520
521 ret = max14577_set_fast_charge_timer(chg, val);
522 if (ret)
523 return ret;
524
525 return count;
526}
527
528static DEVICE_ATTR(fast_charge_timer, S_IRUGO | S_IWUSR,
529 show_fast_charge_timer, store_fast_charge_timer);
530
259static int max14577_charger_probe(struct platform_device *pdev) 531static int max14577_charger_probe(struct platform_device *pdev)
260{ 532{
261 struct max14577_charger *chg; 533 struct max14577_charger *chg;
@@ -270,7 +542,13 @@ static int max14577_charger_probe(struct platform_device *pdev)
270 chg->dev = &pdev->dev; 542 chg->dev = &pdev->dev;
271 chg->max14577 = max14577; 543 chg->max14577 = max14577;
272 544
273 max14577_charger_reg_init(chg); 545 chg->pdata = max14577_charger_dt_init(pdev);
546 if (IS_ERR_OR_NULL(chg->pdata))
547 return PTR_ERR(chg->pdata);
548
549 ret = max14577_charger_reg_init(chg);
550 if (ret)
551 return ret;
274 552
275 chg->charger.name = "max14577-charger", 553 chg->charger.name = "max14577-charger",
276 chg->charger.type = POWER_SUPPLY_TYPE_BATTERY, 554 chg->charger.type = POWER_SUPPLY_TYPE_BATTERY,
@@ -278,24 +556,47 @@ static int max14577_charger_probe(struct platform_device *pdev)
278 chg->charger.num_properties = ARRAY_SIZE(max14577_charger_props), 556 chg->charger.num_properties = ARRAY_SIZE(max14577_charger_props),
279 chg->charger.get_property = max14577_charger_get_property, 557 chg->charger.get_property = max14577_charger_get_property,
280 558
559 ret = device_create_file(&pdev->dev, &dev_attr_fast_charge_timer);
560 if (ret) {
561 dev_err(&pdev->dev, "failed: create sysfs entry\n");
562 return ret;
563 }
564
281 ret = power_supply_register(&pdev->dev, &chg->charger); 565 ret = power_supply_register(&pdev->dev, &chg->charger);
282 if (ret) { 566 if (ret) {
283 dev_err(&pdev->dev, "failed: power supply register\n"); 567 dev_err(&pdev->dev, "failed: power supply register\n");
284 return ret; 568 goto err;
285 } 569 }
286 570
571 /* Check for valid values for charger */
572 BUILD_BUG_ON(MAX14577_CHARGER_EOC_CURRENT_LIMIT_MIN +
573 MAX14577_CHARGER_EOC_CURRENT_LIMIT_STEP * 0xf !=
574 MAX14577_CHARGER_EOC_CURRENT_LIMIT_MAX);
287 return 0; 575 return 0;
576
577err:
578 device_remove_file(&pdev->dev, &dev_attr_fast_charge_timer);
579
580 return ret;
288} 581}
289 582
290static int max14577_charger_remove(struct platform_device *pdev) 583static int max14577_charger_remove(struct platform_device *pdev)
291{ 584{
292 struct max14577_charger *chg = platform_get_drvdata(pdev); 585 struct max14577_charger *chg = platform_get_drvdata(pdev);
293 586
587 device_remove_file(&pdev->dev, &dev_attr_fast_charge_timer);
294 power_supply_unregister(&chg->charger); 588 power_supply_unregister(&chg->charger);
295 589
296 return 0; 590 return 0;
297} 591}
298 592
593static const struct platform_device_id max14577_charger_id[] = {
594 { "max14577-charger", MAXIM_DEVICE_TYPE_MAX14577, },
595 { "max77836-charger", MAXIM_DEVICE_TYPE_MAX77836, },
596 { }
597};
598MODULE_DEVICE_TABLE(platform, max14577_charger_id);
599
299static struct platform_driver max14577_charger_driver = { 600static struct platform_driver max14577_charger_driver = {
300 .driver = { 601 .driver = {
301 .owner = THIS_MODULE, 602 .owner = THIS_MODULE,
@@ -303,9 +604,10 @@ static struct platform_driver max14577_charger_driver = {
303 }, 604 },
304 .probe = max14577_charger_probe, 605 .probe = max14577_charger_probe,
305 .remove = max14577_charger_remove, 606 .remove = max14577_charger_remove,
607 .id_table = max14577_charger_id,
306}; 608};
307module_platform_driver(max14577_charger_driver); 609module_platform_driver(max14577_charger_driver);
308 610
309MODULE_AUTHOR("Krzysztof Kozlowski <k.kozlowski@samsung.com>"); 611MODULE_AUTHOR("Krzysztof Kozlowski <k.kozlowski@samsung.com>");
310MODULE_DESCRIPTION("MAXIM 14577 charger driver"); 612MODULE_DESCRIPTION("Maxim 14577/77836 charger driver");
311MODULE_LICENSE("GPL"); 613MODULE_LICENSE("GPL");
diff --git a/drivers/power/max17040_battery.c b/drivers/power/max17040_battery.c
index 0fbac861080d..14d44706327b 100644
--- a/drivers/power/max17040_battery.c
+++ b/drivers/power/max17040_battery.c
@@ -277,7 +277,8 @@ static SIMPLE_DEV_PM_OPS(max17040_pm_ops, max17040_suspend, max17040_resume);
277#endif /* CONFIG_PM_SLEEP */ 277#endif /* CONFIG_PM_SLEEP */
278 278
279static const struct i2c_device_id max17040_id[] = { 279static const struct i2c_device_id max17040_id[] = {
280 { "max17040", 0 }, 280 { "max17040" },
281 { "max77836-battery" },
281 { } 282 { }
282}; 283};
283MODULE_DEVICE_TABLE(i2c, max17040_id); 284MODULE_DEVICE_TABLE(i2c, max17040_id);