Lines Matching refs:mci
167 static int mt6360_get_chrdet_ext_stat(struct mt6360_chg_info *mci, in mt6360_get_chrdet_ext_stat() argument
173 ret = regmap_read(mci->regmap, MT6360_PMU_FOD_STAT, ®val); in mt6360_get_chrdet_ext_stat()
180 static int mt6360_charger_get_online(struct mt6360_chg_info *mci, in mt6360_charger_get_online() argument
186 ret = mt6360_get_chrdet_ext_stat(mci, &pwr_rdy); in mt6360_charger_get_online()
193 static int mt6360_charger_get_status(struct mt6360_chg_info *mci, in mt6360_charger_get_status() argument
200 ret = mt6360_get_chrdet_ext_stat(mci, &pwr_rdy); in mt6360_charger_get_status()
208 ret = regmap_read(mci->regmap, MT6360_PMU_CHG_STAT, ®val); in mt6360_charger_get_status()
232 static int mt6360_charger_get_charge_type(struct mt6360_chg_info *mci, in mt6360_charger_get_charge_type() argument
239 ret = regmap_read(mci->regmap, MT6360_PMU_CHG_STAT, ®val); in mt6360_charger_get_charge_type()
263 static int mt6360_charger_get_ichg(struct mt6360_chg_info *mci, in mt6360_charger_get_ichg() argument
269 ret = regmap_read(mci->regmap, MT6360_PMU_CHG_CTRL7, &sel); in mt6360_charger_get_ichg()
279 static int mt6360_charger_get_max_ichg(struct mt6360_chg_info *mci, in mt6360_charger_get_max_ichg() argument
286 static int mt6360_charger_get_cv(struct mt6360_chg_info *mci, in mt6360_charger_get_cv() argument
292 ret = regmap_read(mci->regmap, MT6360_PMU_CHG_CTRL4, &sel); in mt6360_charger_get_cv()
302 static int mt6360_charger_get_max_cv(struct mt6360_chg_info *mci, in mt6360_charger_get_max_cv() argument
309 static int mt6360_charger_get_aicr(struct mt6360_chg_info *mci, in mt6360_charger_get_aicr() argument
315 ret = regmap_read(mci->regmap, MT6360_PMU_CHG_CTRL3, &sel); in mt6360_charger_get_aicr()
325 static int mt6360_charger_get_mivr(struct mt6360_chg_info *mci, in mt6360_charger_get_mivr() argument
331 ret = regmap_read(mci->regmap, MT6360_PMU_CHG_CTRL6, &sel); in mt6360_charger_get_mivr()
341 static int mt6360_charger_get_iprechg(struct mt6360_chg_info *mci, in mt6360_charger_get_iprechg() argument
347 ret = regmap_read(mci->regmap, MT6360_PMU_CHG_CTRL8, &sel); in mt6360_charger_get_iprechg()
357 static int mt6360_charger_get_ieoc(struct mt6360_chg_info *mci, in mt6360_charger_get_ieoc() argument
363 ret = regmap_read(mci->regmap, MT6360_PMU_CHG_CTRL9, &sel); in mt6360_charger_get_ieoc()
373 static int mt6360_charger_set_online(struct mt6360_chg_info *mci, in mt6360_charger_set_online() argument
378 return regmap_update_bits(mci->regmap, in mt6360_charger_set_online()
384 static int mt6360_charger_set_ichg(struct mt6360_chg_info *mci, in mt6360_charger_set_ichg() argument
390 return regmap_update_bits(mci->regmap, in mt6360_charger_set_ichg()
396 static int mt6360_charger_set_cv(struct mt6360_chg_info *mci, in mt6360_charger_set_cv() argument
402 return regmap_update_bits(mci->regmap, in mt6360_charger_set_cv()
408 static int mt6360_charger_set_aicr(struct mt6360_chg_info *mci, in mt6360_charger_set_aicr() argument
414 return regmap_update_bits(mci->regmap, in mt6360_charger_set_aicr()
420 static int mt6360_charger_set_mivr(struct mt6360_chg_info *mci, in mt6360_charger_set_mivr() argument
426 return regmap_update_bits(mci->regmap, in mt6360_charger_set_mivr()
432 static int mt6360_charger_set_iprechg(struct mt6360_chg_info *mci, in mt6360_charger_set_iprechg() argument
438 return regmap_update_bits(mci->regmap, in mt6360_charger_set_iprechg()
444 static int mt6360_charger_set_ieoc(struct mt6360_chg_info *mci, in mt6360_charger_set_ieoc() argument
450 return regmap_update_bits(mci->regmap, in mt6360_charger_set_ieoc()
460 struct mt6360_chg_info *mci = power_supply_get_drvdata(psy); in mt6360_charger_get_property() local
465 ret = mt6360_charger_get_online(mci, val); in mt6360_charger_get_property()
468 ret = mt6360_charger_get_status(mci, val); in mt6360_charger_get_property()
471 ret = mt6360_charger_get_charge_type(mci, val); in mt6360_charger_get_property()
474 ret = mt6360_charger_get_ichg(mci, val); in mt6360_charger_get_property()
477 ret = mt6360_charger_get_max_ichg(mci, val); in mt6360_charger_get_property()
480 ret = mt6360_charger_get_cv(mci, val); in mt6360_charger_get_property()
483 ret = mt6360_charger_get_max_cv(mci, val); in mt6360_charger_get_property()
486 ret = mt6360_charger_get_aicr(mci, val); in mt6360_charger_get_property()
489 ret = mt6360_charger_get_mivr(mci, val); in mt6360_charger_get_property()
492 ret = mt6360_charger_get_iprechg(mci, val); in mt6360_charger_get_property()
495 ret = mt6360_charger_get_ieoc(mci, val); in mt6360_charger_get_property()
498 val->intval = mci->psy_usb_type; in mt6360_charger_get_property()
510 struct mt6360_chg_info *mci = power_supply_get_drvdata(psy); in mt6360_charger_set_property() local
515 ret = mt6360_charger_set_online(mci, val); in mt6360_charger_set_property()
518 ret = mt6360_charger_set_ichg(mci, val); in mt6360_charger_set_property()
521 ret = mt6360_charger_set_cv(mci, val); in mt6360_charger_set_property()
524 ret = mt6360_charger_set_aicr(mci, val); in mt6360_charger_set_property()
527 ret = mt6360_charger_set_mivr(mci, val); in mt6360_charger_set_property()
530 ret = mt6360_charger_set_iprechg(mci, val); in mt6360_charger_set_property()
533 ret = mt6360_charger_set_ieoc(mci, val); in mt6360_charger_set_property()
610 struct mt6360_chg_info *mci = data; in mt6360_pmu_attach_i_handler() local
615 mutex_lock(&mci->chgdet_lock); in mt6360_pmu_attach_i_handler()
616 if (!mci->bc12_en) { in mt6360_pmu_attach_i_handler()
617 dev_warn(mci->dev, "Received attach interrupt, bc12 disabled, ignore irq\n"); in mt6360_pmu_attach_i_handler()
620 last_usb_type = mci->psy_usb_type; in mt6360_pmu_attach_i_handler()
622 ret = regmap_read(mci->regmap, MT6360_PMU_USB_STATUS1, &usb_status); in mt6360_pmu_attach_i_handler()
629 dev_dbg(mci->dev, "Received attach interrupt, no vbus\n"); in mt6360_pmu_attach_i_handler()
632 dev_dbg(mci->dev, "Received attach interrupt, under going...\n"); in mt6360_pmu_attach_i_handler()
635 mci->psy_usb_type = POWER_SUPPLY_USB_TYPE_SDP; in mt6360_pmu_attach_i_handler()
638 mci->psy_usb_type = POWER_SUPPLY_USB_TYPE_SDP; in mt6360_pmu_attach_i_handler()
641 mci->psy_usb_type = POWER_SUPPLY_USB_TYPE_CDP; in mt6360_pmu_attach_i_handler()
644 mci->psy_usb_type = POWER_SUPPLY_USB_TYPE_DCP; in mt6360_pmu_attach_i_handler()
647 dev_dbg(mci->dev, "Received attach interrupt, bc12 detect not enable\n"); in mt6360_pmu_attach_i_handler()
650 mci->psy_usb_type = POWER_SUPPLY_USB_TYPE_UNKNOWN; in mt6360_pmu_attach_i_handler()
651 dev_dbg(mci->dev, "Received attach interrupt, reserved address\n"); in mt6360_pmu_attach_i_handler()
655 dev_dbg(mci->dev, "Received attach interrupt, chg_type = %d\n", mci->psy_usb_type); in mt6360_pmu_attach_i_handler()
656 if (last_usb_type != mci->psy_usb_type) in mt6360_pmu_attach_i_handler()
657 power_supply_changed(mci->psy); in mt6360_pmu_attach_i_handler()
659 mutex_unlock(&mci->chgdet_lock); in mt6360_pmu_attach_i_handler()
663 static void mt6360_handle_chrdet_ext_evt(struct mt6360_chg_info *mci) in mt6360_handle_chrdet_ext_evt() argument
668 mutex_lock(&mci->chgdet_lock); in mt6360_handle_chrdet_ext_evt()
669 ret = mt6360_get_chrdet_ext_stat(mci, &pwr_rdy); in mt6360_handle_chrdet_ext_evt()
672 if (mci->pwr_rdy == pwr_rdy) { in mt6360_handle_chrdet_ext_evt()
673 dev_dbg(mci->dev, "Received vbus interrupt, pwr_rdy is same(%d)\n", pwr_rdy); in mt6360_handle_chrdet_ext_evt()
676 mci->pwr_rdy = pwr_rdy; in mt6360_handle_chrdet_ext_evt()
677 dev_dbg(mci->dev, "Received vbus interrupt, pwr_rdy = %d\n", pwr_rdy); in mt6360_handle_chrdet_ext_evt()
679 mci->psy_usb_type = POWER_SUPPLY_USB_TYPE_UNKNOWN; in mt6360_handle_chrdet_ext_evt()
680 power_supply_changed(mci->psy); in mt6360_handle_chrdet_ext_evt()
683 ret = regmap_update_bits(mci->regmap, in mt6360_handle_chrdet_ext_evt()
689 mci->bc12_en = pwr_rdy; in mt6360_handle_chrdet_ext_evt()
691 mutex_unlock(&mci->chgdet_lock); in mt6360_handle_chrdet_ext_evt()
696 struct mt6360_chg_info *mci = (struct mt6360_chg_info *)container_of( in mt6360_chrdet_work() local
699 mt6360_handle_chrdet_ext_evt(mci); in mt6360_chrdet_work()
704 struct mt6360_chg_info *mci = data; in mt6360_pmu_chrdet_ext_evt_handler() local
706 mt6360_handle_chrdet_ext_evt(mci); in mt6360_pmu_chrdet_ext_evt_handler()
752 static int mt6360_chg_init_setting(struct mt6360_chg_info *mci) in mt6360_chg_init_setting() argument
757 sel = mt6360_vinovp_trans_to_sel(mci->vinovp); in mt6360_chg_init_setting()
758 ret = regmap_update_bits(mci->regmap, MT6360_PMU_CHG_CTRL19, in mt6360_chg_init_setting()
761 return dev_err_probe(mci->dev, ret, "%s: Failed to apply vinovp\n", __func__); in mt6360_chg_init_setting()
762 ret = regmap_update_bits(mci->regmap, MT6360_PMU_DEVICE_TYPE, in mt6360_chg_init_setting()
765 return dev_err_probe(mci->dev, ret, "%s: Failed to disable bc12\n", __func__); in mt6360_chg_init_setting()
766 ret = regmap_update_bits(mci->regmap, MT6360_PMU_CHG_CTRL2, in mt6360_chg_init_setting()
771 return dev_err_probe(mci->dev, ret, in mt6360_chg_init_setting()
774 ret = regmap_update_bits(mci->regmap, MT6360_PMU_CHG_CTRL3, in mt6360_chg_init_setting()
777 return dev_err_probe(mci->dev, ret, in mt6360_chg_init_setting()
779 ret = regmap_update_bits(mci->regmap, MT6360_PMU_CHG_CTRL10, in mt6360_chg_init_setting()
782 return dev_err_probe(mci->dev, ret, in mt6360_chg_init_setting()
789 struct mt6360_chg_info *mci; in mt6360_charger_probe() local
794 mci = devm_kzalloc(&pdev->dev, sizeof(*mci), GFP_KERNEL); in mt6360_charger_probe()
795 if (!mci) in mt6360_charger_probe()
798 mci->dev = &pdev->dev; in mt6360_charger_probe()
799 mci->vinovp = 6500000; in mt6360_charger_probe()
800 mutex_init(&mci->chgdet_lock); in mt6360_charger_probe()
801 platform_set_drvdata(pdev, mci); in mt6360_charger_probe()
802 ret = devm_work_autocancel(&pdev->dev, &mci->chrdet_work, mt6360_chrdet_work); in mt6360_charger_probe()
806 ret = device_property_read_u32(&pdev->dev, "richtek,vinovp-microvolt", &mci->vinovp); in mt6360_charger_probe()
810 mci->regmap = dev_get_regmap(pdev->dev.parent, NULL); in mt6360_charger_probe()
811 if (!mci->regmap) in mt6360_charger_probe()
814 ret = mt6360_chg_init_setting(mci); in mt6360_charger_probe()
818 memcpy(&mci->psy_desc, &mt6360_charger_desc, sizeof(mci->psy_desc)); in mt6360_charger_probe()
819 mci->psy_desc.name = dev_name(&pdev->dev); in mt6360_charger_probe()
820 charger_cfg.drv_data = mci; in mt6360_charger_probe()
822 mci->psy = devm_power_supply_register(&pdev->dev, in mt6360_charger_probe()
823 &mci->psy_desc, &charger_cfg); in mt6360_charger_probe()
824 if (IS_ERR(mci->psy)) in mt6360_charger_probe()
825 return dev_err_probe(&pdev->dev, PTR_ERR(mci->psy), in mt6360_charger_probe()
834 config.regmap = mci->regmap; in mt6360_charger_probe()
835 mci->otg_rdev = devm_regulator_register(&pdev->dev, &mt6360_otg_rdesc, in mt6360_charger_probe()
837 if (IS_ERR(mci->otg_rdev)) in mt6360_charger_probe()
838 return PTR_ERR(mci->otg_rdev); in mt6360_charger_probe()
840 schedule_work(&mci->chrdet_work); in mt6360_charger_probe()