4 * Copyright (C) 2011 Samsung Electronics
5 * Ikkeun Kim <iks.kim@samsung.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
12 #include <linux/power/smb328_charger.h>
13 #include <linux/regulator/driver.h>
14 #include <plat/gpio-core.h>
15 #include <linux/switch.h>
18 #define SMB328_USB_MAX_CURRENT 450000
19 #define SMB328_TA_TYP_CURRENT 650000
29 static int smb328_i2c_read(struct i2c_client *client, u8 reg, u8 *data)
36 ret = i2c_smbus_read_byte_data(client, reg);
44 static int smb328_i2c_write(struct i2c_client *client, u8 reg, u8 data)
49 return i2c_smbus_write_byte_data(client, reg, data);
52 static void smb328_test_read(struct i2c_client *client)
54 struct smb328_chip * chg = i2c_get_clientdata(client);
58 for(addr=0;addr<0x0c;addr++)
60 smb328_i2c_read(chg->client, addr, &data);
61 dev_info(&client->dev, "smb328 addr : 0x%02x data : 0x%02x\n", addr,data);
64 for(addr=0x31;addr<0x3D;addr++)
66 smb328_i2c_read(chg->client, addr, &data);
67 dev_info(&client->dev, "smb328 addr : 0x%02x data : 0x%02x\n", addr,data);
71 static int smb328_get_charging_status(struct i2c_client *client)
73 struct smb328_chip *chg = i2c_get_clientdata(client);
74 int status = POWER_SUPPLY_STATUS_UNKNOWN;
79 smb328_i2c_read(chg->client, SMB328A_BATTERY_CHARGING_STATUS_A, &data_a);
80 dev_info(&client->dev, "%s : charging status A(0x%02x)\n",
82 smb328_i2c_read(chg->client, SMB328A_BATTERY_CHARGING_STATUS_B, &data_b);
83 dev_info(&client->dev, "%s : charging status B(0x%02x)\n",
85 smb328_i2c_read(chg->client, SMB328A_BATTERY_CHARGING_STATUS_C, &data_c);
86 dev_info(&client->dev, "%s : charging status C(0x%02x)\n",
89 /* At least one charge cycle terminated, Charge current < Termination Current */
90 if ((data_c & 0xc0) == 0xc0) {
91 status = POWER_SUPPLY_STATUS_FULL; /* top-off by full charging */
92 goto charging_status_end;
97 /* check for 0x30 : 'safety timer' (0b01 or 0b10) or 'waiting to begin charging' (0b11) */
98 /* check for 0x06 : no charging (0b00) */
99 if ((data_c & 0x30) || !(data_c & 0x06)) { /* not charging */
100 status = POWER_SUPPLY_STATUS_NOT_CHARGING;
101 goto charging_status_end;
103 status = POWER_SUPPLY_STATUS_CHARGING;
104 goto charging_status_end;
107 status = POWER_SUPPLY_STATUS_DISCHARGING;
113 static int smb328_get_charging_health(struct i2c_client *client)
115 struct smb328_chip *chg = i2c_get_clientdata(client);
116 int health = POWER_SUPPLY_HEALTH_GOOD;
121 smb328_i2c_read(chg->client, SMB328A_BATTERY_CHARGING_STATUS_A, &data_a);
122 dev_info(&client->dev, "%s : charging status A(0x%02x)\n",
124 smb328_i2c_read(chg->client, SMB328A_BATTERY_CHARGING_STATUS_B, &data_b);
125 dev_info(&client->dev, "%s : charging status B(0x%02x)\n",
127 smb328_i2c_read(chg->client, SMB328A_BATTERY_CHARGING_STATUS_C, &data_c);
128 dev_info(&client->dev, "%s : charging status C(0x%02x)\n",
133 if(!(data_a & 0x02)) /* Input current is NOT OK */
134 health = POWER_SUPPLY_HEALTH_OVERVOLTAGE;
140 static void smb328a_allow_volatile_writes(struct i2c_client *client)
145 reg = SMB328A_COMMAND;
146 val = smb328_i2c_read(client, reg, &data);
147 if ((val >= 0) && !(val&0x80)) {
149 dev_info(&client->dev, "%s : reg (0x%x) = 0x%x\n",
150 __func__, reg, data);
152 if (smb328_i2c_write(client, reg, data) < 0)
153 pr_err("%s : error!\n", __func__);
154 val = smb328_i2c_read(client, reg, &data);
157 pr_info("%s : => reg (0x%x) = 0x%x\n", __func__, reg, data);
162 static void smb328a_charger_function_conrol(struct i2c_client *client)
164 struct smb328_chip *chip = i2c_get_clientdata(client);
169 dev_info(&client->dev, "%s : OTG is activated. Ignore command! (type:%d, enable:%s)\n",
170 __func__, chip->cable_type, chip->is_enable?"true":"false");
174 smb328a_allow_volatile_writes(client);
176 if(!chip->is_enable) {
177 reg = SMB328A_FUNCTION_CONTROL_B;
178 val = smb328_i2c_read(client, reg, &data);
181 dev_info(&client->dev, "%s : reg (0x%x) = 0x%x\n",
182 __func__, reg, data);
185 if (smb328_i2c_write(client, reg, data) < 0)
186 pr_err("%s : error!\n", __func__);
187 val = smb328_i2c_read(client, reg, &data);
190 dev_info(&client->dev, "%s : => reg (0x%x) = 0x%x\n",
191 __func__, reg, data);
196 reg = SMB328A_COMMAND;
197 val = smb328_i2c_read(client, reg, &data);
200 dev_info(&client->dev, "%s : reg (0x%x) = 0x%x\n",
201 __func__, reg, data);
202 data = 0x98; /* turn off charger */
203 if (smb328_i2c_write(client, reg, data) < 0)
204 pr_err("%s : error!\n", __func__);
205 val = smb328_i2c_read(client, reg, &data);
208 dev_info(&client->dev, "%s : => reg (0x%x) = 0x%x\n",
209 __func__, reg, data);
213 reg = SMB328A_INPUT_AND_CHARGE_CURRENTS;
214 val = smb328_i2c_read(client, reg, &data);
217 dev_info(&client->dev, "%s : reg (0x%x) = 0x%x\n",
218 __func__, reg, data);
219 if (chip->cable_type == CABLE_TYPE_AC) {
220 set_data = 0xb7; /* fast 1000mA, termination 200mA */
221 } else if (chip->cable_type == CABLE_TYPE_MISC) {
222 set_data = 0x57; /* fast 700mA, termination 200mA */
224 set_data = 0x17; /* fast 500mA, termination 200mA */
225 if (data != set_data) { /* this can be changed with top-off setting */
227 if (smb328_i2c_write(client, reg, data) < 0)
228 pr_err("%s : error!\n", __func__);
229 val = smb328_i2c_read(client, reg, &data);
232 dev_info(&client->dev, "%s : => reg (0x%x) = 0x%x\n",
233 __func__, reg, data);
238 reg = SMB328A_CURRENT_TERMINATION;
239 val = smb328_i2c_read(client, reg, &data);
242 dev_info(&client->dev, "%s : reg (0x%x) = 0x%x\n",
243 __func__, reg, data);
244 if (chip->cable_type == CABLE_TYPE_AC) {
245 set_data = 0xb0; /* input 1A, threshold 4.25V */
246 } else if (chip->cable_type == CABLE_TYPE_MISC) {
247 set_data = 0x50; /* input 700mA, threshold 4.25V */
249 set_data = 0x10; /* input 450mA, threshold 4.25V */
250 if (data != set_data) { /* AICL enable */
252 if (smb328_i2c_write(client, reg, data) < 0)
253 pr_err("%s : error!\n", __func__);
254 val = smb328_i2c_read(client, reg, &data);
257 dev_info(&client->dev, "%s : => reg (0x%x) = 0x%x\n",
258 __func__, reg, data);
263 reg = SMB328A_FLOAT_VOLTAGE;
264 val = smb328_i2c_read(client, reg, &data);
267 dev_info(&client->dev, "%s : reg (0x%x) = 0x%x\n",
268 __func__, reg, data);
270 data = 0xca; /* 4.2V float voltage */
271 if (smb328_i2c_write(client, reg, data) < 0)
272 pr_err("%s : error!\n", __func__);
273 val = smb328_i2c_read(client, reg, &data);
276 dev_info(&client->dev, "%s : => reg (0x%x) = 0x%x\n",
277 __func__, reg, data);
282 reg = SMB328A_FUNCTION_CONTROL_A1;
283 val = smb328_i2c_read(client, reg, &data);
286 dev_info(&client->dev, "%s : reg (0x%x) = 0x%x\n",
287 __func__, reg, data);
290 data = 0xda; /* top-off by ADC */
293 data = 0x9a; /* top-off by charger */
295 if (smb328_i2c_write(client, reg, data) < 0)
296 pr_err("%s : error!\n", __func__);
297 val = smb328_i2c_read(client, reg, &data);
300 dev_info(&client->dev, "%s : => reg (0x%x) = 0x%x\n",
301 __func__, reg, data);
306 reg = SMB328A_FUNCTION_CONTROL_A2;
307 val = smb328_i2c_read(client, reg, &data);
310 dev_info(&client->dev, "%s : reg (0x%x) = 0x%x\n",
311 __func__, reg, data);
314 if (smb328_i2c_write(client, reg, data) < 0)
315 pr_err("%s : error!\n", __func__);
316 val = smb328_i2c_read(client, reg, &data);
319 dev_info(&client->dev, "%s : => reg (0x%x) = 0x%x\n",
320 __func__, reg, data);
325 reg = SMB328A_FUNCTION_CONTROL_B;
326 val = smb328_i2c_read(client, reg, &data);
329 dev_info(&client->dev, "%s : reg (0x%x) = 0x%x\n",
330 __func__, reg, data);
333 if (smb328_i2c_write(client, reg, data) < 0)
334 pr_err("%s : error!\n", __func__);
335 val = smb328_i2c_read(client, reg, &data);
338 dev_info(&client->dev, "%s : => reg (0x%x) = 0x%x\n",
339 __func__, reg, data);
344 reg = SMB328A_OTG_PWR_AND_LDO_CONTROL;
345 val = smb328_i2c_read(client, reg, &data);
348 dev_info(&client->dev, "%s : reg (0x%x) = 0x%x\n",
349 __func__, reg, data);
351 if (chip->cable_type == CABLE_TYPE_AC) {
353 } else if (chip->cable_type == CABLE_TYPE_MISC) {
357 if (data != set_data) {
359 if (smb328_i2c_write(client, reg, data) < 0)
360 pr_err("%s : error!\n", __func__);
361 val = smb328_i2c_read(client, reg, &data);
364 dev_info(&client->dev, "%s : => reg (0x%x) = 0x%x\n",
365 __func__, reg, data);
370 reg = SMB328A_VARIOUS_CONTROL_FUNCTION_A;
371 val = smb328_i2c_read(client, reg, &data);
374 dev_info(&client->dev, "%s : reg (0x%x) = 0x%x\n",
375 __func__, reg, data);
376 if (data != 0xf6) { /* this can be changed with top-off setting */
378 if (smb328_i2c_write(client, reg, data) < 0)
379 pr_err("%s : error!\n", __func__);
380 val = smb328_i2c_read(client, reg, &data);
383 dev_info(&client->dev, "%s : => reg (0x%x) = 0x%x\n",
384 __func__, reg, data);
389 reg = SMB328A_CELL_TEMPERATURE_MONITOR;
390 val = smb328_i2c_read(client, reg, &data);
393 dev_info(&client->dev, "%s : reg (0x%x) = 0x%x\n",
394 __func__, reg, data);
397 if (smb328_i2c_write(client, reg, data) < 0)
398 pr_err("%s : error!\n", __func__);
399 val = smb328_i2c_read(client, reg, &data);
402 dev_info(&client->dev, "%s : => reg (0x%x) = 0x%x\n",
403 __func__, reg, data);
408 reg = SMB328A_INTERRUPT_SIGNAL_SELECTION;
409 val = smb328_i2c_read(client, reg, &data);
412 dev_info(&client->dev, "%s : reg (0x%x) = 0x%x\n",
413 __func__, reg, data);
416 if (smb328_i2c_write(client, reg, data) < 0)
417 pr_err("%s : error!\n", __func__);
418 val = smb328_i2c_read(client, reg, &data);
421 dev_info(&client->dev, "%s : => reg (0x%x) = 0x%x\n",
422 __func__, reg, data);
427 reg = SMB328A_COMMAND;
428 val = smb328_i2c_read(client, reg, &data);
431 dev_info(&client->dev, "%s : reg (0x%x) = 0x%x\n",
432 __func__, reg, data);
433 if (chip->cable_type == CABLE_TYPE_AC) { /* turn on charger */
435 } else if (chip->cable_type == CABLE_TYPE_MISC) {
438 data = 0x88; /* USB */
439 if (smb328_i2c_write(client, reg, data) < 0)
440 pr_err("%s : error!\n", __func__);
441 val = smb328_i2c_read(client, reg, &data);
444 dev_info(&client->dev, "%s : => reg (0x%x) = 0x%x\n",
445 __func__, reg, data);
451 static void smb328a_charger_otg_conrol(struct i2c_client *client)
453 struct smb328_chip *chip = i2c_get_clientdata(client);
457 smb328a_allow_volatile_writes(client);
460 reg = SMB328A_FUNCTION_CONTROL_B;
461 val = smb328_i2c_read(client, reg, &data);
464 dev_info(&client->dev, "%s : reg (0x%x) = 0x%x\n",
465 __func__, reg, data);
468 if (smb328_i2c_write(client, reg, data) < 0)
469 pr_err("%s : error!\n", __func__);
470 val = smb328_i2c_read(client, reg, &data);
473 dev_info(&client->dev, "%s : => reg (0x%x) = 0x%x\n",
474 __func__, reg, data);
479 /* delay for reset of charger */
482 reg = SMB328A_COMMAND;
483 val = smb328_i2c_read(client, reg, &data);
486 dev_info(&client->dev, "%s : reg (0x%x) = 0x%x\n",
487 __func__, reg, data);
488 data = 0x9a; /* turn on OTG */
489 if (smb328_i2c_write(client, reg, data) < 0)
490 pr_err("%s : error!\n", __func__);
491 val = smb328_i2c_read(client, reg, &data);
494 dev_info(&client->dev, "%s : => reg (0x%x) = 0x%x\n",
495 __func__, reg, data);
499 reg = SMB328A_FUNCTION_CONTROL_B;
500 val = smb328_i2c_read(client, reg, &data);
503 dev_info(&client->dev, "%s : reg (0x%x) = 0x%x\n",
504 __func__, reg, data);
506 data = 0x0c; /* turn off charger */
507 if (smb328_i2c_write(client, reg, data) < 0)
508 pr_err("%s : error!\n", __func__);
509 val = smb328_i2c_read(client, reg, &data);
512 dev_info(&client->dev, "%s : => reg (0x%x) = 0x%x\n",
513 __func__, reg, data);
518 /* delay for reset of charger */
521 reg = SMB328A_COMMAND;
522 val = smb328_i2c_read(client, reg, &data);
525 dev_info(&client->dev, "%s : reg (0x%x) = 0x%x\n",
526 __func__, reg, data);
527 data = 0x98; /* turn off OTG */
528 if (smb328_i2c_write(client, reg, data) < 0)
529 pr_err("%s : error!\n", __func__);
530 val = smb328_i2c_read(client, reg, &data);
533 dev_info(&client->dev, "%s : => reg (0x%x) = 0x%x\n",
534 __func__, reg, data);
540 static int smb328_get_property(struct power_supply *psy,
541 enum power_supply_property psp,
542 union power_supply_propval *val)
544 struct smb328_chip *chip = container_of(psy,
550 case POWER_SUPPLY_PROP_STATUS:
551 val->intval = smb328_get_charging_status(chip->client);
553 case POWER_SUPPLY_PROP_CHARGE_TYPE:
554 val->intval = chip->cable_type;
556 case POWER_SUPPLY_PROP_HEALTH:
557 val->intval = smb328_get_charging_health(chip->client);
559 case POWER_SUPPLY_PROP_ONLINE:
560 val->intval = chip->is_enable;
562 case POWER_SUPPLY_PROP_CURRENT_NOW:
563 if (chip->is_enable) {
564 smb328_i2c_read(chip->client, SMB328A_INPUT_AND_CHARGE_CURRENTS, &data);
598 dev_info(&chip->client->dev, "%s: smb328_get_property (%d,%d)\n",
599 __func__, psp, val->intval);
604 static int smb328_set_property(struct power_supply *psy,
605 enum power_supply_property psp,
606 const union power_supply_propval *val)
608 struct smb328_chip *chip = container_of(psy,
612 dev_info(&chip->client->dev, "%s: smb328_set_property (%d,%d)\n",
613 __func__, psp, val->intval);
616 case POWER_SUPPLY_PROP_STATUS:
617 chip->is_enable = (val->intval == POWER_SUPPLY_STATUS_CHARGING);
618 smb328a_charger_function_conrol(chip->client);
620 case POWER_SUPPLY_PROP_CHARGE_TYPE: /* only for OTG support */
621 chip->is_otg = val->intval;
622 smb328a_charger_otg_conrol(chip->client);
623 smb328_test_read(chip->client);
625 case POWER_SUPPLY_PROP_HEALTH:
627 case POWER_SUPPLY_PROP_ONLINE:
628 chip->is_enable = (bool)val->intval;
629 smb328a_charger_function_conrol(chip->client);
631 case POWER_SUPPLY_PROP_CURRENT_NOW:
632 if (val->intval <= 450)
633 chip->cable_type = CABLE_TYPE_USB; /* USB */
635 chip->cable_type = CABLE_TYPE_AC; /* TA */
643 static irqreturn_t smb328_irq_thread(int irq, void *data)
645 struct smb328_chip *chip = data;
648 dev_info(&chip->client->dev, "%s: chg_ing IRQ occurred!\n", __func__);
650 if (chip->pdata->topoff_cb)
651 ret = chip->pdata->topoff_cb();
654 dev_err(&chip->client->dev, "%s: error from topoff_cb(%d)\n",
662 static int smb328_irq_init(struct smb328_chip *chip)
664 struct i2c_client *client = chip->client;
668 ret = request_threaded_irq(client->irq, NULL,
670 IRQF_TRIGGER_RISING | IRQF_ONESHOT,
671 "SMB328 charger", chip);
673 dev_err(&client->dev, "failed to reqeust IRQ\n");
677 ret = enable_irq_wake(client->irq);
679 dev_err(&client->dev,
680 "failed to enable wakeup src %d\n", ret);
686 static int smb328_is_enabled(struct regulator_dev *rdev)
688 struct smb328_chip *smb328 = rdev_get_drvdata(rdev);
690 return smb328->is_enable;
693 static int smb328_enable(struct regulator_dev *rdev)
695 struct smb328_chip *smb328 = rdev_get_drvdata(rdev);
697 smb328->is_enable = 1;
698 // smb328a_charger_function_conrol(smb328->client);
703 static int smb328_disable(struct regulator_dev *rdev)
705 struct smb328_chip *smb328 = rdev_get_drvdata(rdev);
707 smb328->is_enable = 0;
708 // smb328a_charger_function_conrol(smb328->client);
713 static int smb328_get_current_limit(struct regulator_dev *rdev)
715 struct smb328_chip *smb328 = rdev_get_drvdata(rdev);
717 return smb328->max_uA;
720 static int smb328_set_current_limit(struct regulator_dev *rdev,
721 int min_uA, int max_uA)
723 struct smb328_chip *smb328 = rdev_get_drvdata(rdev);
725 if (smb328->max_uA != max_uA) {
726 smb328->max_uA = max_uA;
729 /* Reset charger if it was already enabled */
730 if (smb328->is_enable) {
731 smb328->is_enable = 0;
732 smb328a_charger_function_conrol(smb328->client);
733 smb328->is_enable = 1;
734 smb328a_charger_function_conrol(smb328->client);
743 static struct regulator_ops smb328_ops = {
744 .is_enabled = smb328_is_enabled,
745 .enable = smb328_enable,
746 .disable = smb328_disable,
747 .get_current_limit = smb328_get_current_limit,
748 .set_current_limit = smb328_set_current_limit,
751 static struct regulator_desc regulator = {
752 .name = "SMB328_CHARGER",
755 .type = REGULATOR_CURRENT,
756 .owner = THIS_MODULE,
759 static int smb328_charger_notifier(struct notifier_block *self,
760 unsigned long event, void *ptr)
762 struct smb328_chip *chip =
763 container_of(self, struct smb328_chip, nb);
764 bool charger_enable = false;
765 int cable_type = CABLE_TYPE_NONE;
767 if (chip->event_code_ta > 0) {
768 if (event & chip->event_code_ta) {
769 cable_type = CABLE_TYPE_AC;
770 chip->max_uA = SMB328_TA_TYP_CURRENT;
771 charger_enable = true;
775 if (chip->event_code_usb > 0) {
776 if (event & chip->event_code_usb) {
777 cable_type = CABLE_TYPE_USB;
778 chip->max_uA = SMB328_USB_MAX_CURRENT;
779 charger_enable = true;
783 // if (charger_enable)
784 // smb328a_charger_function_conrol(chip->client);
786 chip->cable_type = cable_type;
791 static struct notifier_block smb328_charger_nb = {
792 .notifier_call = smb328_charger_notifier,
795 static int smb328_probe(struct i2c_client *client, const struct i2c_device_id *id)
797 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
798 struct smb328_chip *chip;
803 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE))
806 if (smb328_i2c_read(client, 0x36, &data)<0) /* check HW */
809 dev_info(&client->dev, "%s : SMB328 Charger Driver Loading\n", __func__);
811 chip = kzalloc(sizeof(struct smb328_chip), GFP_KERNEL);
815 chip->client = client;
816 chip->pdata = client->dev.platform_data;
818 i2c_set_clientdata(client, chip);
821 dev_err(&client->dev, "%s : No platform data supplied\n", __func__);
826 if (chip->pdata->set_charger_name)
827 chip->pdata->set_charger_name();
829 chip->is_otg = false;
830 chip->is_enable = false;
831 chip->cable_type = CABLE_TYPE_NONE;
833 chip->charger.name = "smb328-charger";
834 chip->charger.type = POWER_SUPPLY_TYPE_BATTERY;
835 chip->charger.get_property = smb328_get_property;
836 chip->charger.set_property = smb328_set_property;
837 chip->charger.properties = smb328_charger_props;
838 chip->charger.num_properties = ARRAY_SIZE(smb328_charger_props);
840 ret = power_supply_register(&client->dev, &chip->charger);
842 dev_err(&client->dev, "failed: power supply register\n");
847 /* CHG_EN pin control - active low */
848 if (chip->pdata->gpio_chg_en) {
849 s3c_gpio_cfgpin(chip->pdata->gpio_chg_en, S3C_GPIO_OUTPUT);
850 s3c_gpio_setpull(chip->pdata->gpio_chg_en, S3C_GPIO_PULL_NONE);
852 gpio = gpio_request(chip->pdata->gpio_chg_en, "CHG_EN");
854 gpio_direction_output(chip->pdata->gpio_chg_en, GPIO_LEVEL_HIGH);
855 gpio_free(chip->pdata->gpio_chg_en);
857 dev_err(&client->dev,
858 "faile to request gpio(CHG_EN)\n");
861 if (chip->pdata->gpio_otg_en) {
862 s3c_gpio_cfgpin(chip->pdata->gpio_otg_en, S3C_GPIO_OUTPUT);
863 s3c_gpio_setpull(chip->pdata->gpio_otg_en, S3C_GPIO_PULL_NONE);
865 gpio = gpio_request(chip->pdata->gpio_otg_en, "OTG_EN");
867 gpio_direction_output(chip->pdata->gpio_otg_en, GPIO_LEVEL_LOW);
868 gpio_free(chip->pdata->gpio_otg_en);
870 dev_err(&client->dev,
871 "faile to request gpio(OTG_EN)\n");
874 if (chip->pdata->gpio_ta_nconnected) {
875 s3c_gpio_cfgpin(chip->pdata->gpio_ta_nconnected, S3C_GPIO_INPUT);
876 s3c_gpio_setpull(chip->pdata->gpio_ta_nconnected, S3C_GPIO_PULL_NONE);
879 if (chip->pdata->gpio_chg_ing) {
881 client->irq = gpio_to_irq(chip->pdata->gpio_chg_ing);
882 ret = smb328_irq_init(chip);
886 s3c_gpio_cfgpin(chip->pdata->gpio_chg_ing, S3C_GPIO_INPUT);
887 s3c_gpio_setpull(chip->pdata->gpio_chg_ing, S3C_GPIO_PULL_NONE);
891 chip->rdev = regulator_register(®ulator, chip->pdata->dev,
892 chip->pdata->init_data, chip);
894 if (IS_ERR(chip->rdev)) {
895 ret = PTR_ERR(chip->rdev);
896 dev_err(chip->pdata->dev, "regulator init failed (%d)\n", ret);
900 chip->nb = smb328_charger_nb;
901 chip->switch_dev = switch_get_switch_dev("switch-usb");
902 if (chip->switch_dev) {
903 switch_register_notifier(chip->switch_dev, &chip->nb);
904 chip->event_code_ta =
905 switch_get_event_code(chip->switch_dev, "TA");
906 chip->event_code_usb =
907 switch_get_event_code(chip->switch_dev, "USB");
910 chip->cable_type = CABLE_TYPE_NONE;
912 smb328_test_read(client);
921 static int __devexit smb328_remove(struct i2c_client *client)
923 struct smb328_chip *chip = i2c_get_clientdata(client);
929 static const struct i2c_device_id smb328_id[] = {
930 {"smb328-charger", 0},
934 MODULE_DEVICE_TABLE(i2c, smb328_id);
936 static struct i2c_driver smb328_i2c_driver = {
938 .owner = THIS_MODULE,
939 .name = "smb328-charger",
941 .probe = smb328_probe,
942 .remove = __devexit_p(smb328_remove),
944 .id_table = smb328_id,
947 static int __init smb328_init(void)
949 return i2c_add_driver(&smb328_i2c_driver);
952 static void __exit smb328_exit(void)
954 i2c_del_driver(&smb328_i2c_driver);
957 module_init(smb328_init);
958 module_exit(smb328_exit);
960 MODULE_AUTHOR("Ikkeun Kim <iks.kim@samsung.com>");
961 MODULE_DESCRIPTION("smb328 charger driver");
962 MODULE_LICENSE("GPL");