Lines Matching full:mci
157 static int mt6360_get_chrdet_ext_stat(struct mt6360_chg_info *mci, in mt6360_get_chrdet_ext_stat() argument
163 ret = regmap_read(mci->regmap, MT6360_PMU_FOD_STAT, ®val); in mt6360_get_chrdet_ext_stat()
170 static int mt6360_charger_get_online(struct mt6360_chg_info *mci, in mt6360_charger_get_online() argument
176 ret = mt6360_get_chrdet_ext_stat(mci, &pwr_rdy); in mt6360_charger_get_online()
183 static int mt6360_charger_get_status(struct mt6360_chg_info *mci, in mt6360_charger_get_status() argument
190 ret = mt6360_get_chrdet_ext_stat(mci, &pwr_rdy); in mt6360_charger_get_status()
198 ret = regmap_read(mci->regmap, MT6360_PMU_CHG_STAT, ®val); in mt6360_charger_get_status()
222 static int mt6360_charger_get_charge_type(struct mt6360_chg_info *mci, in mt6360_charger_get_charge_type() argument
229 ret = regmap_read(mci->regmap, MT6360_PMU_CHG_STAT, ®val); in mt6360_charger_get_charge_type()
253 static int mt6360_charger_get_ichg(struct mt6360_chg_info *mci, in mt6360_charger_get_ichg() argument
259 ret = regmap_read(mci->regmap, MT6360_PMU_CHG_CTRL7, &sel); in mt6360_charger_get_ichg()
269 static int mt6360_charger_get_max_ichg(struct mt6360_chg_info *mci, in mt6360_charger_get_max_ichg() argument
276 static int mt6360_charger_get_cv(struct mt6360_chg_info *mci, in mt6360_charger_get_cv() argument
282 ret = regmap_read(mci->regmap, MT6360_PMU_CHG_CTRL4, &sel); in mt6360_charger_get_cv()
292 static int mt6360_charger_get_max_cv(struct mt6360_chg_info *mci, in mt6360_charger_get_max_cv() argument
299 static int mt6360_charger_get_aicr(struct mt6360_chg_info *mci, in mt6360_charger_get_aicr() argument
305 ret = regmap_read(mci->regmap, MT6360_PMU_CHG_CTRL3, &sel); in mt6360_charger_get_aicr()
315 static int mt6360_charger_get_mivr(struct mt6360_chg_info *mci, in mt6360_charger_get_mivr() argument
321 ret = regmap_read(mci->regmap, MT6360_PMU_CHG_CTRL6, &sel); in mt6360_charger_get_mivr()
331 static int mt6360_charger_get_iprechg(struct mt6360_chg_info *mci, in mt6360_charger_get_iprechg() argument
337 ret = regmap_read(mci->regmap, MT6360_PMU_CHG_CTRL8, &sel); in mt6360_charger_get_iprechg()
347 static int mt6360_charger_get_ieoc(struct mt6360_chg_info *mci, in mt6360_charger_get_ieoc() argument
353 ret = regmap_read(mci->regmap, MT6360_PMU_CHG_CTRL9, &sel); in mt6360_charger_get_ieoc()
363 static int mt6360_charger_set_online(struct mt6360_chg_info *mci, in mt6360_charger_set_online() argument
368 return regmap_update_bits(mci->regmap, in mt6360_charger_set_online()
374 static int mt6360_charger_set_ichg(struct mt6360_chg_info *mci, in mt6360_charger_set_ichg() argument
380 return regmap_update_bits(mci->regmap, in mt6360_charger_set_ichg()
386 static int mt6360_charger_set_cv(struct mt6360_chg_info *mci, in mt6360_charger_set_cv() argument
392 return regmap_update_bits(mci->regmap, in mt6360_charger_set_cv()
398 static int mt6360_charger_set_aicr(struct mt6360_chg_info *mci, in mt6360_charger_set_aicr() argument
404 return regmap_update_bits(mci->regmap, in mt6360_charger_set_aicr()
410 static int mt6360_charger_set_mivr(struct mt6360_chg_info *mci, in mt6360_charger_set_mivr() argument
416 return regmap_update_bits(mci->regmap, in mt6360_charger_set_mivr()
422 static int mt6360_charger_set_iprechg(struct mt6360_chg_info *mci, in mt6360_charger_set_iprechg() argument
428 return regmap_update_bits(mci->regmap, in mt6360_charger_set_iprechg()
434 static int mt6360_charger_set_ieoc(struct mt6360_chg_info *mci, in mt6360_charger_set_ieoc() argument
440 return regmap_update_bits(mci->regmap, in mt6360_charger_set_ieoc()
450 struct mt6360_chg_info *mci = power_supply_get_drvdata(psy); in mt6360_charger_get_property() local
455 ret = mt6360_charger_get_online(mci, val); in mt6360_charger_get_property()
458 ret = mt6360_charger_get_status(mci, val); in mt6360_charger_get_property()
461 ret = mt6360_charger_get_charge_type(mci, val); in mt6360_charger_get_property()
464 ret = mt6360_charger_get_ichg(mci, val); in mt6360_charger_get_property()
467 ret = mt6360_charger_get_max_ichg(mci, val); in mt6360_charger_get_property()
470 ret = mt6360_charger_get_cv(mci, val); in mt6360_charger_get_property()
473 ret = mt6360_charger_get_max_cv(mci, val); in mt6360_charger_get_property()
476 ret = mt6360_charger_get_aicr(mci, val); in mt6360_charger_get_property()
479 ret = mt6360_charger_get_mivr(mci, val); in mt6360_charger_get_property()
482 ret = mt6360_charger_get_iprechg(mci, val); in mt6360_charger_get_property()
485 ret = mt6360_charger_get_ieoc(mci, val); in mt6360_charger_get_property()
488 val->intval = mci->psy_usb_type; in mt6360_charger_get_property()
500 struct mt6360_chg_info *mci = power_supply_get_drvdata(psy); in mt6360_charger_set_property() local
505 ret = mt6360_charger_set_online(mci, val); in mt6360_charger_set_property()
508 ret = mt6360_charger_set_ichg(mci, val); in mt6360_charger_set_property()
511 ret = mt6360_charger_set_cv(mci, val); in mt6360_charger_set_property()
514 ret = mt6360_charger_set_aicr(mci, val); in mt6360_charger_set_property()
517 ret = mt6360_charger_set_mivr(mci, val); in mt6360_charger_set_property()
520 ret = mt6360_charger_set_iprechg(mci, val); in mt6360_charger_set_property()
523 ret = mt6360_charger_set_ieoc(mci, val); in mt6360_charger_set_property()
602 struct mt6360_chg_info *mci = data; in mt6360_pmu_attach_i_handler() local
607 mutex_lock(&mci->chgdet_lock); in mt6360_pmu_attach_i_handler()
608 if (!mci->bc12_en) { in mt6360_pmu_attach_i_handler()
609 dev_warn(mci->dev, "Received attach interrupt, bc12 disabled, ignore irq\n"); in mt6360_pmu_attach_i_handler()
612 last_usb_type = mci->psy_usb_type; in mt6360_pmu_attach_i_handler()
614 ret = regmap_read(mci->regmap, MT6360_PMU_USB_STATUS1, &usb_status); in mt6360_pmu_attach_i_handler()
621 dev_dbg(mci->dev, "Received attach interrupt, no vbus\n"); in mt6360_pmu_attach_i_handler()
624 dev_dbg(mci->dev, "Received attach interrupt, under going...\n"); in mt6360_pmu_attach_i_handler()
627 mci->psy_usb_type = POWER_SUPPLY_USB_TYPE_SDP; in mt6360_pmu_attach_i_handler()
630 mci->psy_usb_type = POWER_SUPPLY_USB_TYPE_SDP; in mt6360_pmu_attach_i_handler()
633 mci->psy_usb_type = POWER_SUPPLY_USB_TYPE_CDP; in mt6360_pmu_attach_i_handler()
636 mci->psy_usb_type = POWER_SUPPLY_USB_TYPE_DCP; in mt6360_pmu_attach_i_handler()
639 dev_dbg(mci->dev, "Received attach interrupt, bc12 detect not enable\n"); in mt6360_pmu_attach_i_handler()
642 mci->psy_usb_type = POWER_SUPPLY_USB_TYPE_UNKNOWN; in mt6360_pmu_attach_i_handler()
643 dev_dbg(mci->dev, "Received attach interrupt, reserved address\n"); in mt6360_pmu_attach_i_handler()
647 dev_dbg(mci->dev, "Received attach interrupt, chg_type = %d\n", mci->psy_usb_type); in mt6360_pmu_attach_i_handler()
648 if (last_usb_type != mci->psy_usb_type) in mt6360_pmu_attach_i_handler()
649 power_supply_changed(mci->psy); in mt6360_pmu_attach_i_handler()
651 mutex_unlock(&mci->chgdet_lock); in mt6360_pmu_attach_i_handler()
655 static void mt6360_handle_chrdet_ext_evt(struct mt6360_chg_info *mci) in mt6360_handle_chrdet_ext_evt() argument
660 mutex_lock(&mci->chgdet_lock); in mt6360_handle_chrdet_ext_evt()
661 ret = mt6360_get_chrdet_ext_stat(mci, &pwr_rdy); in mt6360_handle_chrdet_ext_evt()
664 if (mci->pwr_rdy == pwr_rdy) { in mt6360_handle_chrdet_ext_evt()
665 dev_dbg(mci->dev, "Received vbus interrupt, pwr_rdy is same(%d)\n", pwr_rdy); in mt6360_handle_chrdet_ext_evt()
668 mci->pwr_rdy = pwr_rdy; in mt6360_handle_chrdet_ext_evt()
669 dev_dbg(mci->dev, "Received vbus interrupt, pwr_rdy = %d\n", pwr_rdy); in mt6360_handle_chrdet_ext_evt()
671 mci->psy_usb_type = POWER_SUPPLY_USB_TYPE_UNKNOWN; in mt6360_handle_chrdet_ext_evt()
672 power_supply_changed(mci->psy); in mt6360_handle_chrdet_ext_evt()
675 ret = regmap_update_bits(mci->regmap, in mt6360_handle_chrdet_ext_evt()
681 mci->bc12_en = pwr_rdy; in mt6360_handle_chrdet_ext_evt()
683 mutex_unlock(&mci->chgdet_lock); in mt6360_handle_chrdet_ext_evt()
688 struct mt6360_chg_info *mci = (struct mt6360_chg_info *)container_of( in mt6360_chrdet_work() local
691 mt6360_handle_chrdet_ext_evt(mci); in mt6360_chrdet_work()
696 struct mt6360_chg_info *mci = data; in mt6360_pmu_chrdet_ext_evt_handler() local
698 mt6360_handle_chrdet_ext_evt(mci); in mt6360_pmu_chrdet_ext_evt_handler()
744 static int mt6360_chg_init_setting(struct mt6360_chg_info *mci) in mt6360_chg_init_setting() argument
749 sel = mt6360_vinovp_trans_to_sel(mci->vinovp); in mt6360_chg_init_setting()
750 ret = regmap_update_bits(mci->regmap, MT6360_PMU_CHG_CTRL19, in mt6360_chg_init_setting()
753 return dev_err_probe(mci->dev, ret, "%s: Failed to apply vinovp\n", __func__); in mt6360_chg_init_setting()
754 ret = regmap_update_bits(mci->regmap, MT6360_PMU_DEVICE_TYPE, in mt6360_chg_init_setting()
757 return dev_err_probe(mci->dev, ret, "%s: Failed to disable bc12\n", __func__); in mt6360_chg_init_setting()
758 ret = regmap_update_bits(mci->regmap, MT6360_PMU_CHG_CTRL2, in mt6360_chg_init_setting()
763 return dev_err_probe(mci->dev, ret, in mt6360_chg_init_setting()
766 ret = regmap_update_bits(mci->regmap, MT6360_PMU_CHG_CTRL3, in mt6360_chg_init_setting()
769 return dev_err_probe(mci->dev, ret, in mt6360_chg_init_setting()
771 ret = regmap_update_bits(mci->regmap, MT6360_PMU_CHG_CTRL10, in mt6360_chg_init_setting()
774 return dev_err_probe(mci->dev, ret, in mt6360_chg_init_setting()
781 struct mt6360_chg_info *mci; in mt6360_charger_probe() local
786 mci = devm_kzalloc(&pdev->dev, sizeof(*mci), GFP_KERNEL); in mt6360_charger_probe()
787 if (!mci) in mt6360_charger_probe()
790 mci->dev = &pdev->dev; in mt6360_charger_probe()
791 mci->vinovp = 6500000; in mt6360_charger_probe()
792 mutex_init(&mci->chgdet_lock); in mt6360_charger_probe()
793 platform_set_drvdata(pdev, mci); in mt6360_charger_probe()
794 ret = devm_work_autocancel(&pdev->dev, &mci->chrdet_work, mt6360_chrdet_work); in mt6360_charger_probe()
798 ret = device_property_read_u32(&pdev->dev, "richtek,vinovp-microvolt", &mci->vinovp); in mt6360_charger_probe()
802 mci->regmap = dev_get_regmap(pdev->dev.parent, NULL); in mt6360_charger_probe()
803 if (!mci->regmap) in mt6360_charger_probe()
806 ret = mt6360_chg_init_setting(mci); in mt6360_charger_probe()
810 memcpy(&mci->psy_desc, &mt6360_charger_desc, sizeof(mci->psy_desc)); in mt6360_charger_probe()
811 mci->psy_desc.name = dev_name(&pdev->dev); in mt6360_charger_probe()
812 charger_cfg.drv_data = mci; in mt6360_charger_probe()
814 mci->psy = devm_power_supply_register(&pdev->dev, in mt6360_charger_probe()
815 &mci->psy_desc, &charger_cfg); in mt6360_charger_probe()
816 if (IS_ERR(mci->psy)) in mt6360_charger_probe()
817 return dev_err_probe(&pdev->dev, PTR_ERR(mci->psy), in mt6360_charger_probe()
826 config.regmap = mci->regmap; in mt6360_charger_probe()
827 mci->otg_rdev = devm_regulator_register(&pdev->dev, &mt6360_otg_rdesc, in mt6360_charger_probe()
829 if (IS_ERR(mci->otg_rdev)) in mt6360_charger_probe()
830 return PTR_ERR(mci->otg_rdev); in mt6360_charger_probe()
832 schedule_work(&mci->chrdet_work); in mt6360_charger_probe()