blob: 148f188296a890c192cc0ca0db91f8228f3e3023 [file] [log] [blame]
David Keitelc526ddb2012-02-15 11:32:58 -08001/* Copyright (c) 2012 Code Aurora Forum. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 */
13#define pr_fmt(fmt) "%s: " fmt, __func__
14
15#include <linux/i2c.h>
16#include <linux/gpio.h>
17#include <linux/errno.h>
18#include <linux/delay.h>
19#include <linux/module.h>
20#include <linux/debugfs.h>
21#include <linux/workqueue.h>
22#include <linux/interrupt.h>
23#include <linux/slab.h>
24#include <linux/i2c/smb349.h>
25#include <linux/power_supply.h>
26
27#define SMB349_MASK(BITS, POS) ((unsigned char)(((1 << BITS) - 1) << POS))
28
29/* Register definitions */
30#define CHG_CURRENT_REG 0x00
31#define CHG_OTHER_CURRENT_REG 0x01
32#define VAR_FUNC_REG 0x02
33#define FLOAT_VOLTAGE_REG 0x03
34#define CHG_CTRL_REG 0x04
35#define STAT_TIMER_REG 0x05
36#define PIN_ENABLE_CTRL_REG 0x06
37#define THERM_CTRL_A_REG 0x07
38#define SYSOK_USB3_SELECT_REG 0x08
39#define CTRL_FUNCTIONS_REG 0x09
40#define OTG_TLIM_THERM_CNTRL_REG 0x0A
41#define HARD_SOFT_LIMIT_CELL_TEMP_MONITOR_REG 0x0B
42#define FAULT_IRQ_REG 0x0C
43#define STATUS_IRQ_REG 0x0D
44#define SYSOK_REG 0x0E
45#define CMD_A_REG 0x30
46#define CMD_B_REG 0x31
47#define CMD_C_REG 0x33
48#define IRQ_A_REG 0x35
49#define IRQ_B_REG 0x36
50#define IRQ_C_REG 0x37
51#define IRQ_D_REG 0x38
52#define IRQ_E_REG 0x39
53#define IRQ_F_REG 0x3A
54#define STATUS_A_REG 0x3B
55#define STATUS_B_REG 0x3C
56#define STATUS_C_REG 0x3D
57#define STATUS_D_REG 0x3E
58#define STATUS_E_REG 0x3F
59
60/* Status bits and masks */
61#define CHG_STATUS_MASK SMB349_MASK(2, 1)
62#define CHG_ENABLE_STATUS_BIT BIT(0)
63
64/* Control bits and masks */
65#define FAST_CHG_CURRENT_MASK SMB349_MASK(4, 4)
66#define AC_INPUT_CURRENT_LIMIT_MASK SMB349_MASK(4, 0)
67#define PRE_CHG_CURRENT_MASK SMB349_MASK(3, 5)
68#define TERMINATION_CURRENT_MASK SMB349_MASK(3, 2)
69#define PRE_CHG_TO_FAST_CHG_THRESH_MASK SMB349_MASK(2, 6)
70#define FLOAT_VOLTAGE_MASK SMB349_MASK(6, 0)
71#define CHG_ENABLE_BIT BIT(1)
72#define VOLATILE_W_PERM_BIT BIT(7)
73#define USB_SELECTION_BIT BIT(1)
74#define SYSTEM_FET_ENABLE_BIT BIT(7)
75#define AUTOMATIC_INPUT_CURR_LIMIT_BIT BIT(4)
76#define AUTOMATIC_POWER_SOURCE_DETECTION_BIT BIT(2)
77#define BATT_OV_END_CHG_BIT BIT(1)
78#define VCHG_FUNCTION BIT(0)
79#define CURR_TERM_END_CHG_BIT BIT(6)
80
81struct smb349_struct {
82 struct i2c_client *client;
83 bool charging;
84 bool present;
85 int chg_current_ma;
86
87 int en_n_gpio;
88 int chg_susp_gpio;
89 struct dentry *dent;
90 spinlock_t lock;
91 struct work_struct hwinit_work;
92
93 struct power_supply dc_psy;
94};
95
96struct chg_ma_limit_entry {
97 int fast_chg_ma_limit;
98 int ac_input_ma_limit;
99 u8 chg_current_value;
100};
101
102static struct smb349_struct *the_smb349_chg;
103
104static int smb349_read_reg(struct i2c_client *client, int reg,
105 u8 *val)
106{
107 s32 ret;
108 struct smb349_struct *smb349_chg;
109
110 smb349_chg = i2c_get_clientdata(client);
111 ret = i2c_smbus_read_byte_data(smb349_chg->client, reg);
112 if (ret < 0) {
113 dev_err(&smb349_chg->client->dev,
114 "i2c read fail: can't read from %02x: %d\n", reg, ret);
115 return ret;
116 } else {
117 *val = ret;
118 }
119
120 return 0;
121}
122
123static int smb349_write_reg(struct i2c_client *client, int reg,
124 u8 val)
125{
126 s32 ret;
127 struct smb349_struct *smb349_chg;
128
129 smb349_chg = i2c_get_clientdata(client);
130 ret = i2c_smbus_write_byte_data(smb349_chg->client, reg, val);
131 if (ret < 0) {
132 dev_err(&smb349_chg->client->dev,
133 "i2c write fail: can't write %02x to %02x: %d\n",
134 val, reg, ret);
135 return ret;
136 }
137 return 0;
138}
139
140static int smb349_masked_write(struct i2c_client *client, int reg,
141 u8 mask, u8 val)
142{
143 s32 rc;
144 u8 temp;
145
146 rc = smb349_read_reg(client, reg, &temp);
147 if (rc) {
148 pr_err("smb349_read_reg failed: reg=%03X, rc=%d\n", reg, rc);
149 return rc;
150 }
151 temp &= ~mask;
152 temp |= val & mask;
153 rc = smb349_write_reg(client, reg, temp);
154 if (rc) {
155 pr_err("smb349_write failed: reg=%03X, rc=%d\n", reg, rc);
156 return rc;
157 }
158 return 0;
159}
160
161static enum power_supply_property pm_power_props[] = {
162 POWER_SUPPLY_PROP_ONLINE,
163 POWER_SUPPLY_PROP_CURRENT_MAX,
164 POWER_SUPPLY_PROP_CHARGE_TYPE,
165};
166
167static char *pm_power_supplied_to[] = {
168 "battery",
169};
170
171static int get_prop_charge_type(struct smb349_struct *smb349_chg)
172{
173 if (smb349_chg->charging)
174 return POWER_SUPPLY_CHARGE_TYPE_FAST;
175
176 return POWER_SUPPLY_CHARGE_TYPE_NONE;
177}
178
179static int pm_power_get_property(struct power_supply *psy,
180 enum power_supply_property psp,
181 union power_supply_propval *val)
182{
183 struct smb349_struct *smb349_chg = container_of(psy,
184 struct smb349_struct,
185 dc_psy);
186
187 switch (psp) {
188 case POWER_SUPPLY_PROP_CURRENT_MAX:
189 val->intval = smb349_chg->chg_current_ma;
190 break;
191 case POWER_SUPPLY_PROP_ONLINE:
192 val->intval = (int)smb349_chg->present;
193 break;
194 case POWER_SUPPLY_PROP_CHARGE_TYPE:
195 val->intval = get_prop_charge_type(smb349_chg);
196 break;
197 default:
198 return -EINVAL;
199 }
200 return 0;
201}
202
203#define SMB349_FAST_CHG_MIN_MA 1000
204#define SMB349_FAST_CHG_STEP_MA 200
205#define SMB349_FAST_CHG_MAX_MA 4000
206#define SMB349_FAST_CHG_SHIFT 4
207static int chg_current_set(struct smb349_struct *smb349_chg)
208{
209 u8 temp;
210
211 if ((smb349_chg->chg_current_ma < SMB349_FAST_CHG_MIN_MA) ||
212 (smb349_chg->chg_current_ma > SMB349_FAST_CHG_MAX_MA)) {
213 pr_err("bad mA=%d asked to set\n", smb349_chg->chg_current_ma);
214 return -EINVAL;
215 }
216
217 temp = (smb349_chg->chg_current_ma - SMB349_FAST_CHG_MIN_MA)
218 / SMB349_FAST_CHG_STEP_MA;
219
220 temp = temp << SMB349_FAST_CHG_SHIFT;
221 pr_debug("fastchg limit=%d setting %02x\n",
222 smb349_chg->chg_current_ma, temp);
223 return smb349_masked_write(smb349_chg->client, CHG_CURRENT_REG,
224 FAST_CHG_CURRENT_MASK, temp);
225}
226
227static int set_reg(void *data, u64 val)
228{
229 int addr = (int)data;
230 int ret;
231 u8 temp;
232
233 temp = (u16) val;
234 ret = smb349_write_reg(the_smb349_chg->client, addr, temp);
235
236 if (ret) {
237 pr_err("smb349_write_reg to %x value =%d errored = %d\n",
238 addr, temp, ret);
239 return -EAGAIN;
240 }
241 return 0;
242}
243static int get_reg(void *data, u64 *val)
244{
245 int addr = (int)data;
246 int ret;
247 u8 temp;
248
249 ret = smb349_read_reg(the_smb349_chg->client, addr, &temp);
250 if (ret) {
251 pr_err("smb349_read_reg to %x value =%d errored = %d\n",
252 addr, temp, ret);
253 return -EAGAIN;
254 }
255
256 *val = temp;
257 return 0;
258}
259
260DEFINE_SIMPLE_ATTRIBUTE(reg_fops, get_reg, set_reg, "0x%02llx\n");
261
262static void create_debugfs_entries(struct smb349_struct *smb349_chg)
263{
264 struct dentry *file;
265 smb349_chg->dent = debugfs_create_dir(SMB349_NAME, NULL);
266 if (IS_ERR(smb349_chg->dent)) {
267 pr_err("smb349 driver couldn't create debugfs dir\n");
268 return;
269 }
270
271 file = debugfs_create_file("CHG_CURRENT_REG", 0644, smb349_chg->dent,
272 (void *) CHG_CURRENT_REG, &reg_fops);
273 if (IS_ERR(file)) {
274 pr_err("smb349 driver couldn't create debugfs files\n");
275 return;
276 }
277 file = debugfs_create_file("CHG_OTHER_CURRENT_REG", 0644,
278 smb349_chg->dent, (void *) CHG_OTHER_CURRENT_REG, &reg_fops);
279 if (IS_ERR(file)) {
280 pr_err("smb349 driver couldn't create debugfs files\n");
281 return;
282 }
283 file = debugfs_create_file("VAR_FUNC_REG", 0644, smb349_chg->dent,
284 (void *) VAR_FUNC_REG, &reg_fops);
285 if (IS_ERR(file)) {
286 pr_err("smb349 driver couldn't create debugfs files\n");
287 return;
288 }
289 file = debugfs_create_file("FLOAT_VOLTAGE_REG", 0644, smb349_chg->dent,
290 (void *) FLOAT_VOLTAGE_REG, &reg_fops);
291 if (IS_ERR(file)) {
292 pr_err("smb349 driver couldn't create debugfs files\n");
293 return;
294 }
295 file = debugfs_create_file("CHG_CTRL_REG", 0644, smb349_chg->dent,
296 (void *) CHG_CTRL_REG, &reg_fops);
297 if (IS_ERR(file)) {
298 pr_err("smb349 driver couldn't create debugfs files\n");
299 return;
300 }
301 file = debugfs_create_file("STAT_TIMER_REG", 0644, smb349_chg->dent,
302 (void *) STAT_TIMER_REG, &reg_fops);
303 if (IS_ERR(file)) {
304 pr_err("smb349 driver couldn't create debugfs files\n");
305 return;
306 }
307 file = debugfs_create_file("PIN_ENABLE_CTRL_REG", 0644,
308 smb349_chg->dent, (void *) PIN_ENABLE_CTRL_REG, &reg_fops);
309 if (IS_ERR(file)) {
310 pr_err("smb349 driver couldn't create debugfs files\n");
311 return;
312 }
313 file = debugfs_create_file("PIN_ENABLE_CTRL_REG", 0644,
314 smb349_chg->dent, (void *) PIN_ENABLE_CTRL_REG, &reg_fops);
315 if (IS_ERR(file)) {
316 pr_err("smb349 driver couldn't create debugfs files\n");
317 return;
318 }
319 file = debugfs_create_file("PIN_ENABLE_CTRL_REG", 0644,
320 smb349_chg->dent, (void *) PIN_ENABLE_CTRL_REG, &reg_fops);
321 if (IS_ERR(file)) {
322 pr_err("smb349 driver couldn't create debugfs files\n");
323 return;
324 }
325 file = debugfs_create_file("THERM_CTRL_A_REG", 0644, smb349_chg->dent,
326 (void *) THERM_CTRL_A_REG, &reg_fops);
327 if (IS_ERR(file)) {
328 pr_err("smb349 driver couldn't create debugfs files\n");
329 return;
330 }
331 file = debugfs_create_file("SYSOK_USB3_SELECT_REG", 0644,
332 smb349_chg->dent, (void *) SYSOK_USB3_SELECT_REG, &reg_fops);
333 if (IS_ERR(file)) {
334 pr_err("smb349 driver couldn't create debugfs files\n");
335 return;
336 }
337 file = debugfs_create_file("CTRL_FUNCTIONS_REG", 0644,
338 smb349_chg->dent, (void *) CTRL_FUNCTIONS_REG, &reg_fops);
339 if (IS_ERR(file)) {
340 pr_err("smb349 driver couldn't create debugfs files\n");
341 return;
342 }
343 file = debugfs_create_file("OTG_TLIM_THERM_CNTRL_REG", 0644,
344 smb349_chg->dent, (void *) OTG_TLIM_THERM_CNTRL_REG, &reg_fops);
345 if (IS_ERR(file)) {
346 pr_err("smb349 driver couldn't create debugfs files\n");
347 return;
348 }
349 file = debugfs_create_file("HARD_SOFT_LIMIT_CELL_TEMP_MONITOR_REG",
350 0644, smb349_chg->dent,
351 (void *) HARD_SOFT_LIMIT_CELL_TEMP_MONITOR_REG, &reg_fops);
352 if (IS_ERR(file)) {
353 pr_err("smb349 driver couldn't create debugfs files\n");
354 return;
355 }
356 file = debugfs_create_file("SYSOK_REG", 0644, smb349_chg->dent,
357 (void *) SYSOK_REG, &reg_fops);
358 if (IS_ERR(file)) {
359 pr_err("smb349 driver couldn't create debugfs files\n");
360 return;
361 }
362 file = debugfs_create_file("CMD_A_REG", 0644, smb349_chg->dent,
363 (void *) CMD_A_REG, &reg_fops);
364 if (IS_ERR(file)) {
365 pr_err("smb349 driver couldn't create debugfs files\n");
366 return;
367 }
368 file = debugfs_create_file("CMD_B_REG", 0644, smb349_chg->dent,
369 (void *) CMD_B_REG, &reg_fops);
370 if (IS_ERR(file)) {
371 pr_err("smb349 driver couldn't create debugfs files\n");
372 return;
373 }
374 file = debugfs_create_file("CMD_C_REG", 0644, smb349_chg->dent,
375 (void *) CMD_C_REG, &reg_fops);
376 if (IS_ERR(file)) {
377 pr_err("smb349 driver couldn't create debugfs files\n");
378 return;
379 }
380 file = debugfs_create_file("STATUS_A_REG", 0644, smb349_chg->dent,
381 (void *) STATUS_A_REG, &reg_fops);
382 if (IS_ERR(file)) {
383 pr_err("smb349 driver couldn't create debugfs files\n");
384 return;
385 }
386 file = debugfs_create_file("STATUS_B_REG", 0644, smb349_chg->dent,
387 (void *) STATUS_B_REG, &reg_fops);
388 if (IS_ERR(file)) {
389 pr_err("smb349 driver couldn't create debugfs files\n");
390 return;
391 }
392 file = debugfs_create_file("STATUS_C_REG", 0644, smb349_chg->dent,
393 (void *) STATUS_C_REG, &reg_fops);
394 if (IS_ERR(file)) {
395 pr_err("smb349 driver couldn't create debugfs files\n");
396 return;
397 }
398 file = debugfs_create_file("STATUS_D_REG", 0644, smb349_chg->dent,
399 (void *) STATUS_D_REG, &reg_fops);
400 if (IS_ERR(file)) {
401 pr_err("smb349 driver couldn't create debugfs files\n");
402 return;
403 }
404 file = debugfs_create_file("STATUS_E_REG", 0644, smb349_chg->dent,
405 (void *) STATUS_E_REG, &reg_fops);
406 if (IS_ERR(file)) {
407 pr_err("smb349 driver couldn't create debugfs files\n");
408 return;
409 }
410}
411
412static void remove_debugfs_entries(struct smb349_struct *smb349_chg)
413{
414 if (smb349_chg->dent)
415 debugfs_remove_recursive(smb349_chg->dent);
416}
417
418static int __devinit smb349_hwinit(struct smb349_struct *smb349_chg)
419{
420 int ret;
421
422 ret = smb349_write_reg(smb349_chg->client, CMD_A_REG,
423 VOLATILE_W_PERM_BIT);
424 if (ret) {
425 pr_err("Failed to set VOLATILE_W_PERM_BIT rc=%d\n", ret);
426 return ret;
427 }
428
429 ret = smb349_masked_write(smb349_chg->client, CHG_CTRL_REG,
430 CURR_TERM_END_CHG_BIT, CURR_TERM_END_CHG_BIT);
431 if (ret) {
432 pr_err("Failed to set CURR_TERM_END_CHG_BIT rc=%d\n", ret);
433 return ret;
434 }
435
436 ret = chg_current_set(smb349_chg);
437 if (ret) {
438 pr_err("Failed to set FAST_CHG_CURRENT rc=%d\n", ret);
439 return ret;
440 }
441
442 return 0;
443}
444
445static int smb349_stop_charging(struct smb349_struct *smb349_chg)
446{
447 unsigned long flags;
448
449 if (smb349_chg->charging)
450 gpio_set_value_cansleep(smb349_chg->en_n_gpio, 0);
451
452 spin_lock_irqsave(&smb349_chg->lock, flags);
453 pr_debug("stop charging %d\n", smb349_chg->charging);
454 smb349_chg->charging = 0;
455 spin_unlock_irqrestore(&smb349_chg->lock, flags);
456 power_supply_changed(&smb349_chg->dc_psy);
457 return 0;
458}
459
460static int smb349_start_charging(struct smb349_struct *smb349_chg)
461{
462 unsigned long flags;
463 int rc;
464
465 rc = 0;
466 if (!smb349_chg->charging) {
467 gpio_set_value_cansleep(smb349_chg->en_n_gpio, 1);
468 /*
469 * Write non-default values, charger chip reloads from
470 * non-volatile memory if it was in suspend mode
471 *
472 */
473 rc = schedule_work(&smb349_chg->hwinit_work);
474 }
475
476 spin_lock_irqsave(&smb349_chg->lock, flags);
477 pr_debug("start charging %d\n", smb349_chg->charging);
478 smb349_chg->charging = 1;
479 spin_unlock_irqrestore(&smb349_chg->lock, flags);
480 power_supply_changed(&smb349_chg->dc_psy);
481 return rc;
482}
483
484static int pm_power_set_property(struct power_supply *psy,
485 enum power_supply_property psp,
486 const union power_supply_propval *val)
487{
488 struct smb349_struct *smb349_chg = container_of(psy,
489 struct smb349_struct,
490 dc_psy);
491
492 switch (psp) {
493 case POWER_SUPPLY_PROP_ONLINE:
494 if (val->intval) {
495 smb349_chg->present = val->intval;
496 } else {
497 smb349_chg->present = 0;
498 if (smb349_chg->charging)
499 return smb349_stop_charging(smb349_chg);
500 }
501 break;
502 case POWER_SUPPLY_PROP_CURRENT_MAX:
503 if (val->intval) {
504 if (smb349_chg->chg_current_ma != val->intval)
505 return -EINVAL;
506 }
507 break;
508 case POWER_SUPPLY_PROP_CHARGE_TYPE:
509 if (val->intval && smb349_chg->present) {
510 if (val->intval == POWER_SUPPLY_CHARGE_TYPE_FAST)
511 return smb349_start_charging(smb349_chg);
512 if (val->intval == POWER_SUPPLY_CHARGE_TYPE_NONE)
513 return smb349_stop_charging(smb349_chg);
514 } else {
515 return -EINVAL;
516 }
517 break;
518 default:
519 return -EINVAL;
520 }
521 power_supply_changed(&smb349_chg->dc_psy);
522 return 0;
523}
524
525static void hwinit_worker(struct work_struct *work)
526{
527 int ret;
528 struct smb349_struct *smb349_chg = container_of(work,
529 struct smb349_struct, hwinit_work);
530
531 ret = smb349_hwinit(smb349_chg);
532 if (ret)
533 pr_err("Failed to re-initilaze registers\n");
534}
535
536static int __devinit smb349_init_ext_chg(struct smb349_struct *smb349_chg)
537{
538 int ret;
539
540 smb349_chg->dc_psy.name = "dc";
541 smb349_chg->dc_psy.type = POWER_SUPPLY_TYPE_MAINS;
542 smb349_chg->dc_psy.supplied_to = pm_power_supplied_to;
543 smb349_chg->dc_psy.num_supplicants = ARRAY_SIZE(pm_power_supplied_to);
544 smb349_chg->dc_psy.properties = pm_power_props;
545 smb349_chg->dc_psy.num_properties = ARRAY_SIZE(pm_power_props);
546 smb349_chg->dc_psy.get_property = pm_power_get_property;
547 smb349_chg->dc_psy.set_property = pm_power_set_property;
548
549 ret = power_supply_register(&smb349_chg->client->dev,
550 &smb349_chg->dc_psy);
551 if (ret) {
552 pr_err("failed to register power_supply. ret=%d.\n", ret);
553 return ret;
554 }
555
556 return 0;
557}
558
559static int __devinit smb349_probe(struct i2c_client *client,
560 const struct i2c_device_id *id)
561{
562 const struct smb349_platform_data *pdata;
563 struct smb349_struct *smb349_chg;
564 int ret = 0;
565
566 pdata = client->dev.platform_data;
567
568 if (pdata == NULL) {
569 dev_err(&client->dev, "%s no platform data\n", __func__);
570 ret = -EINVAL;
571 goto out;
572 }
573
574 if (!i2c_check_functionality(client->adapter,
575 I2C_FUNC_SMBUS_BYTE_DATA)) {
576 ret = -EIO;
577 goto out;
578 }
579
580 smb349_chg = kzalloc(sizeof(*smb349_chg), GFP_KERNEL);
581 if (!smb349_chg) {
582 ret = -ENOMEM;
583 goto out;
584 }
585
586 smb349_chg->client = client;
587 smb349_chg->chg_current_ma = pdata->chg_current_ma;
588 ret = gpio_request(pdata->chg_susp_gpio, "smb349_suspend");
589 if (ret) {
590 dev_err(&client->dev, "%s gpio_request failed for %d ret=%d\n",
591 __func__, pdata->chg_susp_gpio, ret);
592 goto free_smb349_chg;
593 }
594 smb349_chg->chg_susp_gpio = pdata->chg_susp_gpio;
595
596 ret = gpio_request(pdata->en_n_gpio, "smb349_charger_enable");
597 if (ret) {
598 dev_err(&client->dev, "%s gpio_request failed for %d ret=%d\n",
599 __func__, pdata->en_n_gpio, ret);
600 goto chg_susp_gpio_fail;
601 }
602 smb349_chg->en_n_gpio = pdata->en_n_gpio;
603
604 i2c_set_clientdata(client, smb349_chg);
605
606 ret = smb349_hwinit(smb349_chg);
607 if (ret)
608 goto free_smb349_chg;
609
610 ret = smb349_init_ext_chg(smb349_chg);
611 if (ret)
612 goto chg_en_gpio_fail;
613
614 the_smb349_chg = smb349_chg;
615
616 create_debugfs_entries(smb349_chg);
617 INIT_WORK(&smb349_chg->hwinit_work, hwinit_worker);
618
619 pr_info("OK connector present = %d\n", smb349_chg->present);
620 return 0;
621
622chg_en_gpio_fail:
623 gpio_free(smb349_chg->en_n_gpio);
624chg_susp_gpio_fail:
625 gpio_free(smb349_chg->chg_susp_gpio);
626free_smb349_chg:
627 kfree(smb349_chg);
628out:
629 return ret;
630}
631
632static int __devexit smb349_remove(struct i2c_client *client)
633{
634 const struct smb349_platform_data *pdata;
635 struct smb349_struct *smb349_chg = i2c_get_clientdata(client);
636
637 flush_work(&smb349_chg->hwinit_work);
638 pdata = client->dev.platform_data;
639 power_supply_unregister(&smb349_chg->dc_psy);
640 gpio_free(pdata->en_n_gpio);
641 gpio_free(pdata->chg_susp_gpio);
642 remove_debugfs_entries(smb349_chg);
643 kfree(smb349_chg);
644 return 0;
645}
646
647static int smb349_suspend(struct device *dev)
648{
649 struct smb349_struct *smb349_chg = dev_get_drvdata(dev);
650
651 pr_debug("suspend\n");
652 if (smb349_chg->charging)
653 return -EBUSY;
654 return 0;
655}
656
657static int smb349_resume(struct device *dev)
658{
659 pr_debug("resume\n");
660
661 return 0;
662}
663
664static const struct dev_pm_ops smb349_pm_ops = {
665 .suspend = smb349_suspend,
666 .resume = smb349_resume,
667};
668
669static const struct i2c_device_id smb349_id[] = {
670 {SMB349_NAME, 0},
671 {},
672};
673MODULE_DEVICE_TABLE(i2c, smb349_id);
674
675static struct i2c_driver smb349_driver = {
676 .driver = {
677 .name = SMB349_NAME,
678 .owner = THIS_MODULE,
679 .pm = &smb349_pm_ops,
680 },
681 .probe = smb349_probe,
682 .remove = __devexit_p(smb349_remove),
683 .id_table = smb349_id,
684};
685
686static int __init smb349_init(void)
687{
688 return i2c_add_driver(&smb349_driver);
689}
690module_init(smb349_init);
691
692static void __exit smb349_exit(void)
693{
694 return i2c_del_driver(&smb349_driver);
695}
696module_exit(smb349_exit);
697
698MODULE_DESCRIPTION("Driver for SMB349 charger chip");
699MODULE_LICENSE("GPL v2");
700MODULE_ALIAS("i2c:" SMB349_NAME);