Lines Matching refs:pm2
115 static void set_lpn_pin(struct pm2xxx_charger *pm2) in set_lpn_pin() argument
117 if (!pm2->ac.charger_connected && gpio_is_valid(pm2->lpn_pin)) { in set_lpn_pin()
118 gpio_set_value(pm2->lpn_pin, 1); in set_lpn_pin()
123 static void clear_lpn_pin(struct pm2xxx_charger *pm2) in clear_lpn_pin() argument
125 if (!pm2->ac.charger_connected && gpio_is_valid(pm2->lpn_pin)) in clear_lpn_pin()
126 gpio_set_value(pm2->lpn_pin, 0); in clear_lpn_pin()
129 static int pm2xxx_reg_read(struct pm2xxx_charger *pm2, int reg, u8 *val) in pm2xxx_reg_read() argument
134 pm_runtime_get_sync(pm2->dev); in pm2xxx_reg_read()
136 ret = i2c_smbus_read_i2c_block_data(pm2->config.pm2xxx_i2c, reg, in pm2xxx_reg_read()
139 dev_err(pm2->dev, "Error reading register at 0x%x\n", reg); in pm2xxx_reg_read()
143 pm_runtime_put_sync(pm2->dev); in pm2xxx_reg_read()
148 static int pm2xxx_reg_write(struct pm2xxx_charger *pm2, int reg, u8 val) in pm2xxx_reg_write() argument
153 pm_runtime_get_sync(pm2->dev); in pm2xxx_reg_write()
155 ret = i2c_smbus_write_i2c_block_data(pm2->config.pm2xxx_i2c, reg, in pm2xxx_reg_write()
158 dev_err(pm2->dev, "Error writing register at 0x%x\n", reg); in pm2xxx_reg_write()
162 pm_runtime_put_sync(pm2->dev); in pm2xxx_reg_write()
167 static int pm2xxx_charging_enable_mngt(struct pm2xxx_charger *pm2) in pm2xxx_charging_enable_mngt() argument
172 ret = pm2xxx_reg_write(pm2, PM2XXX_BATT_CTRL_REG2, in pm2xxx_charging_enable_mngt()
178 static int pm2xxx_charging_disable_mngt(struct pm2xxx_charger *pm2) in pm2xxx_charging_disable_mngt() argument
183 ret = pm2xxx_reg_write(pm2, PM2XXX_SW_CTRL_REG, PM2XXX_SWCTRL_HW); in pm2xxx_charging_disable_mngt()
185 dev_err(pm2->dev, "%s pm2xxx write failed\n", __func__); in pm2xxx_charging_disable_mngt()
190 ret = pm2xxx_reg_write(pm2, PM2XXX_BATT_CTRL_REG2, in pm2xxx_charging_disable_mngt()
193 dev_err(pm2->dev, "%s pm2xxx write failed\n", __func__); in pm2xxx_charging_disable_mngt()
200 static int pm2xxx_charger_batt_therm_mngt(struct pm2xxx_charger *pm2, int val) in pm2xxx_charger_batt_therm_mngt() argument
202 queue_work(pm2->charger_wq, &pm2->check_main_thermal_prot_work); in pm2xxx_charger_batt_therm_mngt()
208 static int pm2xxx_charger_die_therm_mngt(struct pm2xxx_charger *pm2, int val) in pm2xxx_charger_die_therm_mngt() argument
210 queue_work(pm2->charger_wq, &pm2->check_main_thermal_prot_work); in pm2xxx_charger_die_therm_mngt()
215 static int pm2xxx_charger_ovv_mngt(struct pm2xxx_charger *pm2, int val) in pm2xxx_charger_ovv_mngt() argument
217 dev_err(pm2->dev, "Overvoltage detected\n"); in pm2xxx_charger_ovv_mngt()
218 pm2->flags.ovv = true; in pm2xxx_charger_ovv_mngt()
219 power_supply_changed(pm2->ac_chg.psy); in pm2xxx_charger_ovv_mngt()
222 queue_delayed_work(pm2->charger_wq, &pm2->check_hw_failure_work, 0); in pm2xxx_charger_ovv_mngt()
227 static int pm2xxx_charger_wd_exp_mngt(struct pm2xxx_charger *pm2, int val) in pm2xxx_charger_wd_exp_mngt() argument
229 dev_dbg(pm2->dev , "20 minutes watchdog expired\n"); in pm2xxx_charger_wd_exp_mngt()
231 pm2->ac.wd_expired = true; in pm2xxx_charger_wd_exp_mngt()
232 power_supply_changed(pm2->ac_chg.psy); in pm2xxx_charger_wd_exp_mngt()
237 static int pm2xxx_charger_vbat_lsig_mngt(struct pm2xxx_charger *pm2, int val) in pm2xxx_charger_vbat_lsig_mngt() argument
243 dev_dbg(pm2->dev, "VBAT grows above VBAT_LOW level\n"); in pm2xxx_charger_vbat_lsig_mngt()
245 ret = pm2xxx_reg_write(pm2, PM2XXX_SW_CTRL_REG, in pm2xxx_charger_vbat_lsig_mngt()
248 dev_err(pm2->dev, "%s pm2xxx write failed\n", __func__); in pm2xxx_charger_vbat_lsig_mngt()
254 dev_dbg(pm2->dev, "VBAT drops below VBAT_LOW level\n"); in pm2xxx_charger_vbat_lsig_mngt()
256 ret = pm2xxx_reg_write(pm2, PM2XXX_SW_CTRL_REG, in pm2xxx_charger_vbat_lsig_mngt()
259 dev_err(pm2->dev, "%s pm2xxx write failed\n", __func__); in pm2xxx_charger_vbat_lsig_mngt()
265 dev_err(pm2->dev, "Unknown VBAT level\n"); in pm2xxx_charger_vbat_lsig_mngt()
271 static int pm2xxx_charger_bat_disc_mngt(struct pm2xxx_charger *pm2, int val) in pm2xxx_charger_bat_disc_mngt() argument
273 dev_dbg(pm2->dev, "battery disconnected\n"); in pm2xxx_charger_bat_disc_mngt()
278 static int pm2xxx_charger_detection(struct pm2xxx_charger *pm2, u8 *val) in pm2xxx_charger_detection() argument
282 ret = pm2xxx_reg_read(pm2, PM2XXX_SRCE_REG_INT2, val); in pm2xxx_charger_detection()
285 dev_err(pm2->dev, "Charger detection failed\n"); in pm2xxx_charger_detection()
295 static int pm2xxx_charger_itv_pwr_plug_mngt(struct pm2xxx_charger *pm2, int val) in pm2xxx_charger_itv_pwr_plug_mngt() argument
306 ret = pm2xxx_charger_detection(pm2, &read_val); in pm2xxx_charger_itv_pwr_plug_mngt()
309 pm2->ac.charger_connected = 1; in pm2xxx_charger_itv_pwr_plug_mngt()
310 pm2->ac_conn = true; in pm2xxx_charger_itv_pwr_plug_mngt()
311 queue_work(pm2->charger_wq, &pm2->ac_work); in pm2xxx_charger_itv_pwr_plug_mngt()
318 static int pm2xxx_charger_itv_pwr_unplug_mngt(struct pm2xxx_charger *pm2, in pm2xxx_charger_itv_pwr_unplug_mngt() argument
321 pm2->ac.charger_connected = 0; in pm2xxx_charger_itv_pwr_unplug_mngt()
322 queue_work(pm2->charger_wq, &pm2->ac_work); in pm2xxx_charger_itv_pwr_unplug_mngt()
329 struct pm2xxx_charger *pm2 = pm2_data; in pm2_int_reg0() local
333 ret = pm2xxx_charger_vbat_lsig_mngt(pm2, in pm2_int_reg0()
340 ret = pm2xxx_charger_vbat_lsig_mngt(pm2, in pm2_int_reg0()
347 ret = pm2xxx_charger_bat_disc_mngt(pm2, in pm2_int_reg0()
358 struct pm2xxx_charger *pm2 = pm2_data; in pm2_int_reg1() local
362 dev_dbg(pm2->dev , "Main charger plugged\n"); in pm2_int_reg1()
363 ret = pm2xxx_charger_itv_pwr_plug_mngt(pm2, val & in pm2_int_reg1()
369 dev_dbg(pm2->dev , "Main charger unplugged\n"); in pm2_int_reg1()
370 ret = pm2xxx_charger_itv_pwr_unplug_mngt(pm2, val & in pm2_int_reg1()
380 struct pm2xxx_charger *pm2 = pm2_data; in pm2_int_reg2() local
384 ret = pm2xxx_charger_wd_exp_mngt(pm2, val); in pm2_int_reg2()
388 dev_dbg(pm2->dev, in pm2_int_reg2()
397 struct pm2xxx_charger *pm2 = pm2_data; in pm2_int_reg3() local
401 dev_dbg(pm2->dev , in pm2_int_reg3()
406 dev_dbg(pm2->dev, in pm2_int_reg3()
411 dev_dbg(pm2->dev , "battery fully detected\n"); in pm2_int_reg3()
415 dev_dbg(pm2->dev, "CV phase enter with 0.5C charging\n"); in pm2_int_reg3()
419 pm2->failure_case = VPWR_OVV; in pm2_int_reg3()
420 ret = pm2xxx_charger_ovv_mngt(pm2, val & in pm2_int_reg3()
422 dev_dbg(pm2->dev, "VPWR/VSYSTEM overvoltage detected\n"); in pm2_int_reg3()
427 ret = pm2xxx_charger_batt_therm_mngt(pm2, val & in pm2_int_reg3()
430 dev_dbg(pm2->dev, "BTEMP is too Low/High\n"); in pm2_int_reg3()
438 struct pm2xxx_charger *pm2 = pm2_data; in pm2_int_reg4() local
442 pm2->failure_case = VSYSTEM_OVV; in pm2_int_reg4()
443 ret = pm2xxx_charger_ovv_mngt(pm2, val & in pm2_int_reg4()
445 dev_dbg(pm2->dev, "VSYSTEM overvoltage detected\n"); in pm2_int_reg4()
452 dev_dbg(pm2->dev, "BTEMP die temperature is too Low/High\n"); in pm2_int_reg4()
453 ret = pm2xxx_charger_die_therm_mngt(pm2, val & in pm2_int_reg4()
465 struct pm2xxx_charger *pm2 = pm2_data; in pm2_int_reg5() local
469 dev_dbg(pm2->dev, "VMPWR drop to VBAT level\n"); in pm2_int_reg5()
476 dev_dbg(pm2->dev, "Falling/Rising edge on WPWR1/2\n"); in pm2_int_reg5()
484 struct pm2xxx_charger *pm2 = data; in pm2xxx_irq_int() local
485 struct pm2xxx_interrupts *interrupt = pm2->pm2_int; in pm2xxx_irq_int()
489 pm_runtime_get_sync(pm2->dev); in pm2xxx_irq_int()
493 pm2xxx_reg_read(pm2, in pm2xxx_irq_int()
498 interrupt->handler[i](pm2, interrupt->reg[i]); in pm2xxx_irq_int()
500 } while (gpio_get_value(pm2->pdata->gpio_irq_number) == 0); in pm2xxx_irq_int()
502 pm_runtime_mark_last_busy(pm2->dev); in pm2xxx_irq_int()
503 pm_runtime_put_autosuspend(pm2->dev); in pm2xxx_irq_int()
508 static int pm2xxx_charger_get_ac_cv(struct pm2xxx_charger *pm2) in pm2xxx_charger_get_ac_cv() argument
513 if (pm2->ac.charger_connected && pm2->ac.charger_online) { in pm2xxx_charger_get_ac_cv()
515 ret = pm2xxx_reg_read(pm2, PM2XXX_SRCE_REG_INT4, &val); in pm2xxx_charger_get_ac_cv()
517 dev_err(pm2->dev, "%s pm2xxx read failed\n", __func__); in pm2xxx_charger_get_ac_cv()
573 struct pm2xxx_charger *pm2; in pm2xxx_charger_update_charger_current() local
577 pm2 = to_pm2xxx_charger_ac_device_info(charger); in pm2xxx_charger_update_charger_current()
583 dev_err(pm2->dev, in pm2xxx_charger_update_charger_current()
588 ret = pm2xxx_reg_read(pm2, PM2XXX_BATT_CTRL_REG6, &val); in pm2xxx_charger_update_charger_current()
592 ret = pm2xxx_reg_write(pm2, PM2XXX_BATT_CTRL_REG6, val); in pm2xxx_charger_update_charger_current()
594 dev_err(pm2->dev, in pm2xxx_charger_update_charger_current()
599 dev_err(pm2->dev, "%s read failed\n", __func__); in pm2xxx_charger_update_charger_current()
608 struct pm2xxx_charger *pm2; in pm2xxx_charger_ac_get_property() local
610 pm2 = to_pm2xxx_charger_ac_device_info(psy_to_ux500_charger(psy)); in pm2xxx_charger_ac_get_property()
614 if (pm2->flags.mainextchnotok) in pm2xxx_charger_ac_get_property()
616 else if (pm2->ac.wd_expired) in pm2xxx_charger_ac_get_property()
618 else if (pm2->flags.main_thermal_prot) in pm2xxx_charger_ac_get_property()
620 else if (pm2->flags.ovv) in pm2xxx_charger_ac_get_property()
626 val->intval = pm2->ac.charger_online; in pm2xxx_charger_ac_get_property()
629 val->intval = pm2->ac.charger_connected; in pm2xxx_charger_ac_get_property()
632 pm2->ac.cv_active = pm2xxx_charger_get_ac_cv(pm2); in pm2xxx_charger_ac_get_property()
633 val->intval = pm2->ac.cv_active; in pm2xxx_charger_ac_get_property()
641 static int pm2xxx_charging_init(struct pm2xxx_charger *pm2) in pm2xxx_charging_init() argument
646 ret = pm2xxx_reg_write(pm2, PM2XXX_BATT_CTRL_REG3, in pm2xxx_charging_init()
652 ret = pm2xxx_reg_write(pm2, PM2XXX_BATT_CTRL_REG4, in pm2xxx_charging_init()
656 ret = pm2xxx_reg_write(pm2, PM2XXX_BATT_CTRL_REG5, in pm2xxx_charging_init()
664 ret = pm2xxx_reg_write(pm2, PM2XXX_BATT_CTRL_REG6, in pm2xxx_charging_init()
673 ret = pm2xxx_reg_write(pm2, PM2XXX_BATT_CTRL_REG7, in pm2xxx_charging_init()
677 ret = pm2xxx_reg_write(pm2, PM2XXX_BATT_CTRL_REG8, in pm2xxx_charging_init()
681 ret = pm2xxx_reg_write(pm2, PM2XXX_BATT_CTRL_REG9, in pm2xxx_charging_init()
687 ret = pm2xxx_reg_write(pm2, PM2XXX_INP_VOLT_VPWR2, in pm2xxx_charging_init()
689 ret = pm2xxx_reg_write(pm2, PM2XXX_INP_VOLT_VPWR1, in pm2xxx_charging_init()
693 ret = pm2xxx_reg_write(pm2, PM2XXX_INP_DROP_VPWR2, in pm2xxx_charging_init()
696 ret = pm2xxx_reg_write(pm2, PM2XXX_INP_DROP_VPWR1, in pm2xxx_charging_init()
701 ret = pm2xxx_reg_write(pm2, PM2XXX_BATT_LOW_LEV_COMP_REG, in pm2xxx_charging_init()
715 struct pm2xxx_charger *pm2 = to_pm2xxx_charger_ac_device_info(charger); in pm2xxx_charger_ac_en() local
718 if (!pm2->ac.charger_connected) { in pm2xxx_charger_ac_en()
719 dev_dbg(pm2->dev, "AC charger not connected\n"); in pm2xxx_charger_ac_en()
723 dev_dbg(pm2->dev, "Enable AC: %dmV %dmA\n", vset, iset); in pm2xxx_charger_ac_en()
724 if (!pm2->vddadc_en_ac) { in pm2xxx_charger_ac_en()
725 ret = regulator_enable(pm2->regu); in pm2xxx_charger_ac_en()
727 dev_warn(pm2->dev, in pm2xxx_charger_ac_en()
730 pm2->vddadc_en_ac = true; in pm2xxx_charger_ac_en()
733 ret = pm2xxx_charging_init(pm2); in pm2xxx_charger_ac_en()
735 dev_err(pm2->dev, "%s charging init failed\n", in pm2xxx_charger_ac_en()
744 dev_err(pm2->dev, in pm2xxx_charger_ac_en()
750 ret = pm2xxx_reg_read(pm2, PM2XXX_BATT_CTRL_REG8, &val); in pm2xxx_charger_ac_en()
752 dev_err(pm2->dev, "%s pm2xxx read failed\n", __func__); in pm2xxx_charger_ac_en()
757 ret = pm2xxx_reg_write(pm2, PM2XXX_BATT_CTRL_REG8, val); in pm2xxx_charger_ac_en()
759 dev_err(pm2->dev, "%s pm2xxx write failed\n", __func__); in pm2xxx_charger_ac_en()
763 ret = pm2xxx_reg_read(pm2, PM2XXX_BATT_CTRL_REG6, &val); in pm2xxx_charger_ac_en()
765 dev_err(pm2->dev, "%s pm2xxx read failed\n", __func__); in pm2xxx_charger_ac_en()
770 ret = pm2xxx_reg_write(pm2, PM2XXX_BATT_CTRL_REG6, val); in pm2xxx_charger_ac_en()
772 dev_err(pm2->dev, "%s pm2xxx write failed\n", __func__); in pm2xxx_charger_ac_en()
776 if (!pm2->bat->enable_overshoot) { in pm2xxx_charger_ac_en()
777 ret = pm2xxx_reg_read(pm2, PM2XXX_LED_CTRL_REG, &val); in pm2xxx_charger_ac_en()
779 dev_err(pm2->dev, "%s pm2xxx read failed\n", in pm2xxx_charger_ac_en()
784 ret = pm2xxx_reg_write(pm2, PM2XXX_LED_CTRL_REG, val); in pm2xxx_charger_ac_en()
786 dev_err(pm2->dev, "%s pm2xxx write failed\n", in pm2xxx_charger_ac_en()
792 ret = pm2xxx_charging_enable_mngt(pm2); in pm2xxx_charger_ac_en()
794 dev_err(pm2->dev, "Failed to enable" in pm2xxx_charger_ac_en()
799 pm2->ac.charger_online = 1; in pm2xxx_charger_ac_en()
801 pm2->ac.charger_online = 0; in pm2xxx_charger_ac_en()
802 pm2->ac.wd_expired = false; in pm2xxx_charger_ac_en()
805 if (pm2->vddadc_en_ac) { in pm2xxx_charger_ac_en()
806 regulator_disable(pm2->regu); in pm2xxx_charger_ac_en()
807 pm2->vddadc_en_ac = false; in pm2xxx_charger_ac_en()
810 ret = pm2xxx_charging_disable_mngt(pm2); in pm2xxx_charger_ac_en()
812 dev_err(pm2->dev, "failed to disable" in pm2xxx_charger_ac_en()
817 dev_dbg(pm2->dev, "PM2301: " "Disabled AC charging\n"); in pm2xxx_charger_ac_en()
819 power_supply_changed(pm2->ac_chg.psy); in pm2xxx_charger_ac_en()
828 struct pm2xxx_charger *pm2; in pm2xxx_charger_watchdog_kick() local
831 pm2 = to_pm2xxx_charger_ac_device_info(charger); in pm2xxx_charger_watchdog_kick()
835 ret = pm2xxx_reg_write(pm2, PM2XXX_BATT_WD_KICK, WD_TIMER); in pm2xxx_charger_watchdog_kick()
837 dev_err(pm2->dev, "Failed to kick WD!\n"); in pm2xxx_charger_watchdog_kick()
844 struct pm2xxx_charger *pm2 = container_of(work, in pm2xxx_charger_ac_work() local
848 power_supply_changed(pm2->ac_chg.psy); in pm2xxx_charger_ac_work()
849 sysfs_notify(&pm2->ac_chg.psy->dev.kobj, NULL, "present"); in pm2xxx_charger_ac_work()
856 struct pm2xxx_charger *pm2 = container_of(work, in pm2xxx_charger_check_hw_failure_work() local
859 if (pm2->flags.ovv) { in pm2xxx_charger_check_hw_failure_work()
860 pm2xxx_reg_read(pm2, PM2XXX_SRCE_REG_INT4, ®_value); in pm2xxx_charger_check_hw_failure_work()
864 pm2->flags.ovv = false; in pm2xxx_charger_check_hw_failure_work()
865 power_supply_changed(pm2->ac_chg.psy); in pm2xxx_charger_check_hw_failure_work()
870 if (pm2->flags.ovv) { in pm2xxx_charger_check_hw_failure_work()
871 queue_delayed_work(pm2->charger_wq, in pm2xxx_charger_check_hw_failure_work()
872 &pm2->check_hw_failure_work, round_jiffies(HZ)); in pm2xxx_charger_check_hw_failure_work()
882 struct pm2xxx_charger *pm2 = container_of(work, struct pm2xxx_charger, in pm2xxx_charger_check_main_thermal_prot_work() local
886 ret = pm2xxx_reg_read(pm2, PM2XXX_SRCE_REG_INT5, &val); in pm2xxx_charger_check_main_thermal_prot_work()
888 dev_err(pm2->dev, "%s pm2xxx read failed\n", __func__); in pm2xxx_charger_check_main_thermal_prot_work()
893 pm2->flags.main_thermal_prot = true; in pm2xxx_charger_check_main_thermal_prot_work()
896 pm2->flags.main_thermal_prot = false; in pm2xxx_charger_check_main_thermal_prot_work()
898 power_supply_changed(pm2->ac_chg.psy); in pm2xxx_charger_check_main_thermal_prot_work()
917 struct pm2xxx_charger *pm2; in pm2xxx_wall_charger_resume() local
919 pm2 = (struct pm2xxx_charger *)i2c_get_clientdata(i2c_client); in pm2xxx_wall_charger_resume()
920 set_lpn_pin(pm2); in pm2xxx_wall_charger_resume()
923 if (pm2->flags.ovv) in pm2xxx_wall_charger_resume()
924 queue_delayed_work(pm2->charger_wq, in pm2xxx_wall_charger_resume()
925 &pm2->check_hw_failure_work, 0); in pm2xxx_wall_charger_resume()
933 struct pm2xxx_charger *pm2; in pm2xxx_wall_charger_suspend() local
935 pm2 = (struct pm2xxx_charger *)i2c_get_clientdata(i2c_client); in pm2xxx_wall_charger_suspend()
936 clear_lpn_pin(pm2); in pm2xxx_wall_charger_suspend()
939 if (delayed_work_pending(&pm2->check_hw_failure_work)) in pm2xxx_wall_charger_suspend()
940 cancel_delayed_work(&pm2->check_hw_failure_work); in pm2xxx_wall_charger_suspend()
942 flush_work(&pm2->ac_work); in pm2xxx_wall_charger_suspend()
943 flush_work(&pm2->check_main_thermal_prot_work); in pm2xxx_wall_charger_suspend()
951 struct pm2xxx_charger *pm2; in pm2xxx_runtime_suspend() local
953 pm2 = (struct pm2xxx_charger *)i2c_get_clientdata(pm2xxx_i2c_client); in pm2xxx_runtime_suspend()
954 clear_lpn_pin(pm2); in pm2xxx_runtime_suspend()
962 struct pm2xxx_charger *pm2; in pm2xxx_runtime_resume() local
964 pm2 = (struct pm2xxx_charger *)i2c_get_clientdata(pm2xxx_i2c_client); in pm2xxx_runtime_resume()
966 if (gpio_is_valid(pm2->lpn_pin) && gpio_get_value(pm2->lpn_pin) == 0) in pm2xxx_runtime_resume()
967 set_lpn_pin(pm2); in pm2xxx_runtime_resume()
983 struct pm2xxx_charger *pm2; in pm2xxx_wall_charger_probe() local
993 pm2 = kzalloc(sizeof(struct pm2xxx_charger), GFP_KERNEL); in pm2xxx_wall_charger_probe()
994 if (!pm2) { in pm2xxx_wall_charger_probe()
1000 pm2->dev = &i2c_client->dev; in pm2xxx_wall_charger_probe()
1002 pm2->pm2_int = &pm2xxx_int; in pm2xxx_wall_charger_probe()
1006 dev_err(pm2->dev, "no charger platform data supplied\n"); in pm2xxx_wall_charger_probe()
1011 pm2->pdata = pl_data->wall_charger; in pm2xxx_wall_charger_probe()
1015 dev_err(pm2->dev, "no battery platform data supplied\n"); in pm2xxx_wall_charger_probe()
1020 pm2->bat = pl_data->battery; in pm2xxx_wall_charger_probe()
1026 dev_info(pm2->dev, "pm2301 i2c_check_functionality failed\n"); in pm2xxx_wall_charger_probe()
1030 pm2->config.pm2xxx_i2c = i2c_client; in pm2xxx_wall_charger_probe()
1031 pm2->config.pm2xxx_id = (struct i2c_device_id *) id; in pm2xxx_wall_charger_probe()
1032 i2c_set_clientdata(i2c_client, pm2); in pm2xxx_wall_charger_probe()
1036 pm2->ac_chg_desc.name = pm2->pdata->label; in pm2xxx_wall_charger_probe()
1037 pm2->ac_chg_desc.type = POWER_SUPPLY_TYPE_MAINS; in pm2xxx_wall_charger_probe()
1038 pm2->ac_chg_desc.properties = pm2xxx_charger_ac_props; in pm2xxx_wall_charger_probe()
1039 pm2->ac_chg_desc.num_properties = ARRAY_SIZE(pm2xxx_charger_ac_props); in pm2xxx_wall_charger_probe()
1040 pm2->ac_chg_desc.get_property = pm2xxx_charger_ac_get_property; in pm2xxx_wall_charger_probe()
1042 psy_cfg.supplied_to = pm2->pdata->supplied_to; in pm2xxx_wall_charger_probe()
1043 psy_cfg.num_supplicants = pm2->pdata->num_supplicants; in pm2xxx_wall_charger_probe()
1045 pm2->ac_chg.ops.enable = &pm2xxx_charger_ac_en; in pm2xxx_wall_charger_probe()
1046 pm2->ac_chg.ops.kick_wd = &pm2xxx_charger_watchdog_kick; in pm2xxx_wall_charger_probe()
1047 pm2->ac_chg.ops.update_curr = &pm2xxx_charger_update_charger_current; in pm2xxx_wall_charger_probe()
1048 pm2->ac_chg.max_out_volt = pm2xxx_charger_voltage_map[ in pm2xxx_wall_charger_probe()
1050 pm2->ac_chg.max_out_curr = pm2xxx_charger_current_map[ in pm2xxx_wall_charger_probe()
1052 pm2->ac_chg.wdt_refresh = WD_KICK_INTERVAL; in pm2xxx_wall_charger_probe()
1053 pm2->ac_chg.enabled = true; in pm2xxx_wall_charger_probe()
1054 pm2->ac_chg.external = true; in pm2xxx_wall_charger_probe()
1057 pm2->charger_wq = alloc_ordered_workqueue("pm2xxx_charger_wq", in pm2xxx_wall_charger_probe()
1059 if (pm2->charger_wq == NULL) { in pm2xxx_wall_charger_probe()
1061 dev_err(pm2->dev, "failed to create work queue\n"); in pm2xxx_wall_charger_probe()
1066 INIT_WORK(&pm2->ac_work, pm2xxx_charger_ac_work); in pm2xxx_wall_charger_probe()
1069 INIT_WORK(&pm2->check_main_thermal_prot_work, in pm2xxx_wall_charger_probe()
1073 INIT_DEFERRABLE_WORK(&pm2->check_hw_failure_work, in pm2xxx_wall_charger_probe()
1081 pm2->regu = regulator_get(pm2->dev, "vddadc"); in pm2xxx_wall_charger_probe()
1082 if (IS_ERR(pm2->regu)) { in pm2xxx_wall_charger_probe()
1083 ret = PTR_ERR(pm2->regu); in pm2xxx_wall_charger_probe()
1084 dev_err(pm2->dev, "failed to get vddadc regulator\n"); in pm2xxx_wall_charger_probe()
1089 pm2->ac_chg.psy = power_supply_register(pm2->dev, &pm2->ac_chg_desc, in pm2xxx_wall_charger_probe()
1091 if (IS_ERR(pm2->ac_chg.psy)) { in pm2xxx_wall_charger_probe()
1092 dev_err(pm2->dev, "failed to register AC charger\n"); in pm2xxx_wall_charger_probe()
1093 ret = PTR_ERR(pm2->ac_chg.psy); in pm2xxx_wall_charger_probe()
1098 ret = request_threaded_irq(gpio_to_irq(pm2->pdata->gpio_irq_number), in pm2xxx_wall_charger_probe()
1101 pm2->pdata->irq_type, in pm2xxx_wall_charger_probe()
1102 pm2xxx_charger_irq[0].name, pm2); in pm2xxx_wall_charger_probe()
1105 dev_err(pm2->dev, "failed to request %s IRQ %d: %d\n", in pm2xxx_wall_charger_probe()
1107 gpio_to_irq(pm2->pdata->gpio_irq_number), ret); in pm2xxx_wall_charger_probe()
1111 ret = pm_runtime_set_active(pm2->dev); in pm2xxx_wall_charger_probe()
1113 dev_err(pm2->dev, "set active Error\n"); in pm2xxx_wall_charger_probe()
1115 pm_runtime_enable(pm2->dev); in pm2xxx_wall_charger_probe()
1116 pm_runtime_set_autosuspend_delay(pm2->dev, PM2XXX_AUTOSUSPEND_DELAY); in pm2xxx_wall_charger_probe()
1117 pm_runtime_use_autosuspend(pm2->dev); in pm2xxx_wall_charger_probe()
1118 pm_runtime_resume(pm2->dev); in pm2xxx_wall_charger_probe()
1121 ret = enable_irq_wake(gpio_to_irq(pm2->pdata->gpio_irq_number)); in pm2xxx_wall_charger_probe()
1123 dev_err(pm2->dev, "failed to set irq wake\n"); in pm2xxx_wall_charger_probe()
1127 mutex_init(&pm2->lock); in pm2xxx_wall_charger_probe()
1129 if (gpio_is_valid(pm2->pdata->lpn_gpio)) { in pm2xxx_wall_charger_probe()
1131 pm2->lpn_pin = pm2->pdata->lpn_gpio; in pm2xxx_wall_charger_probe()
1138 ret = gpio_request(pm2->lpn_pin, "pm2301_lpm_gpio"); in pm2xxx_wall_charger_probe()
1141 dev_err(pm2->dev, "pm2301_lpm_gpio request failed\n"); in pm2xxx_wall_charger_probe()
1144 ret = gpio_direction_output(pm2->lpn_pin, 0); in pm2xxx_wall_charger_probe()
1146 dev_err(pm2->dev, "pm2301_lpm_gpio direction failed\n"); in pm2xxx_wall_charger_probe()
1149 set_lpn_pin(pm2); in pm2xxx_wall_charger_probe()
1154 pm2xxx_reg_read(pm2, in pm2xxx_wall_charger_probe()
1158 ret = pm2xxx_charger_detection(pm2, &val); in pm2xxx_wall_charger_probe()
1161 pm2->ac.charger_connected = 1; in pm2xxx_wall_charger_probe()
1164 pm2->ac_conn = true; in pm2xxx_wall_charger_probe()
1165 power_supply_changed(pm2->ac_chg.psy); in pm2xxx_wall_charger_probe()
1166 sysfs_notify(&pm2->ac_chg.psy->dev.kobj, NULL, "present"); in pm2xxx_wall_charger_probe()
1172 if (gpio_is_valid(pm2->lpn_pin)) in pm2xxx_wall_charger_probe()
1173 gpio_free(pm2->lpn_pin); in pm2xxx_wall_charger_probe()
1175 disable_irq_wake(gpio_to_irq(pm2->pdata->gpio_irq_number)); in pm2xxx_wall_charger_probe()
1178 free_irq(gpio_to_irq(pm2->pdata->gpio_irq_number), pm2); in pm2xxx_wall_charger_probe()
1181 power_supply_unregister(pm2->ac_chg.psy); in pm2xxx_wall_charger_probe()
1184 regulator_put(pm2->regu); in pm2xxx_wall_charger_probe()
1186 destroy_workqueue(pm2->charger_wq); in pm2xxx_wall_charger_probe()
1188 kfree(pm2); in pm2xxx_wall_charger_probe()
1195 struct pm2xxx_charger *pm2 = i2c_get_clientdata(i2c_client); in pm2xxx_wall_charger_remove() local
1198 pm_runtime_disable(pm2->dev); in pm2xxx_wall_charger_remove()
1200 pm2xxx_charger_ac_en(&pm2->ac_chg, false, 0, 0); in pm2xxx_wall_charger_remove()
1203 disable_irq_wake(gpio_to_irq(pm2->pdata->gpio_irq_number)); in pm2xxx_wall_charger_remove()
1206 free_irq(gpio_to_irq(pm2->pdata->gpio_irq_number), pm2); in pm2xxx_wall_charger_remove()
1209 destroy_workqueue(pm2->charger_wq); in pm2xxx_wall_charger_remove()
1214 regulator_put(pm2->regu); in pm2xxx_wall_charger_remove()
1216 power_supply_unregister(pm2->ac_chg.psy); in pm2xxx_wall_charger_remove()
1218 if (gpio_is_valid(pm2->lpn_pin)) in pm2xxx_wall_charger_remove()
1219 gpio_free(pm2->lpn_pin); in pm2xxx_wall_charger_remove()
1221 kfree(pm2); in pm2xxx_wall_charger_remove()