Lines Matching +full:mt6360 +full:- +full:regulator

1 // SPDX-License-Identifier: GPL-2.0
6 #include <linux/devm-helpers.h>
17 #include <linux/regulator/driver.h>
173 ret = regmap_read(mci->regmap, MT6360_PMU_FOD_STAT, &regval); in mt6360_get_chrdet_ext_stat()
189 val->intval = pwr_rdy ? true : false; in mt6360_charger_get_online()
208 ret = regmap_read(mci->regmap, MT6360_PMU_CHG_STAT, &regval); in mt6360_charger_get_status()
224 ret = -EIO; in mt6360_charger_get_status()
228 val->intval = status; in mt6360_charger_get_status()
239 ret = regmap_read(mci->regmap, MT6360_PMU_CHG_STAT, &regval); in mt6360_charger_get_charge_type()
259 val->intval = type; in mt6360_charger_get_charge_type()
269 ret = regmap_read(mci->regmap, MT6360_PMU_CHG_CTRL7, &sel); in mt6360_charger_get_ichg()
275 val->intval = value; in mt6360_charger_get_ichg()
282 val->intval = MT6360_ICHG_MAX; in mt6360_charger_get_max_ichg()
292 ret = regmap_read(mci->regmap, MT6360_PMU_CHG_CTRL4, &sel); in mt6360_charger_get_cv()
298 val->intval = value; in mt6360_charger_get_cv()
305 val->intval = MT6360_VOREG_MAX; in mt6360_charger_get_max_cv()
315 ret = regmap_read(mci->regmap, MT6360_PMU_CHG_CTRL3, &sel); in mt6360_charger_get_aicr()
321 val->intval = value; in mt6360_charger_get_aicr()
331 ret = regmap_read(mci->regmap, MT6360_PMU_CHG_CTRL6, &sel); in mt6360_charger_get_mivr()
337 val->intval = value; in mt6360_charger_get_mivr()
347 ret = regmap_read(mci->regmap, MT6360_PMU_CHG_CTRL8, &sel); in mt6360_charger_get_iprechg()
353 val->intval = value; in mt6360_charger_get_iprechg()
363 ret = regmap_read(mci->regmap, MT6360_PMU_CHG_CTRL9, &sel); in mt6360_charger_get_ieoc()
369 val->intval = value; in mt6360_charger_get_ieoc()
376 u8 force_sleep = val->intval ? 0 : 1; in mt6360_charger_set_online()
378 return regmap_update_bits(mci->regmap, in mt6360_charger_set_online()
389 linear_range_get_selector_within(&mt6360_chg_range[MT6360_RANGE_ICHG], val->intval, &sel); in mt6360_charger_set_ichg()
390 return regmap_update_bits(mci->regmap, in mt6360_charger_set_ichg()
401 linear_range_get_selector_within(&mt6360_chg_range[MT6360_RANGE_VOREG], val->intval, &sel); in mt6360_charger_set_cv()
402 return regmap_update_bits(mci->regmap, in mt6360_charger_set_cv()
413 linear_range_get_selector_within(&mt6360_chg_range[MT6360_RANGE_AICR], val->intval, &sel); in mt6360_charger_set_aicr()
414 return regmap_update_bits(mci->regmap, in mt6360_charger_set_aicr()
425 linear_range_get_selector_within(&mt6360_chg_range[MT6360_RANGE_VMIVR], val->intval, &sel); in mt6360_charger_set_mivr()
426 return regmap_update_bits(mci->regmap, in mt6360_charger_set_mivr()
437 linear_range_get_selector_within(&mt6360_chg_range[MT6360_RANGE_IPREC], val->intval, &sel); in mt6360_charger_set_iprechg()
438 return regmap_update_bits(mci->regmap, in mt6360_charger_set_iprechg()
449 linear_range_get_selector_within(&mt6360_chg_range[MT6360_RANGE_IEOC], val->intval, &sel); in mt6360_charger_set_ieoc()
450 return regmap_update_bits(mci->regmap, in mt6360_charger_set_ieoc()
498 val->intval = mci->psy_usb_type; in mt6360_charger_get_property()
501 ret = -ENODATA; in mt6360_charger_get_property()
536 ret = -EINVAL; in mt6360_charger_set_property()
594 .of_match = "usb-otg-vbus",
595 .name = "usb-otg-vbus",
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()
668 mutex_lock(&mci->chgdet_lock); 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()
726 ret = devm_request_threaded_irq(&pdev->dev, ret, NULL, in mt6360_chg_irq_register()
732 return dev_err_probe(&pdev->dev, ret, "Failed to request %s irq\n", in mt6360_chg_irq_register()
745 for (i = 0; i < ARRAY_SIZE(vinovp_tbl)-1; i++) { in mt6360_vinovp_trans_to_sel()
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()
794 mci = devm_kzalloc(&pdev->dev, sizeof(*mci), GFP_KERNEL); in mt6360_charger_probe()
796 return -ENOMEM; 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()
802 devm_work_autocancel(&pdev->dev, &mci->chrdet_work, mt6360_chrdet_work); in mt6360_charger_probe()
804 ret = device_property_read_u32(&pdev->dev, "richtek,vinovp-microvolt", &mci->vinovp); in mt6360_charger_probe()
806 dev_warn(&pdev->dev, "Failed to parse vinovp in DT, keep default 6.5v\n"); in mt6360_charger_probe()
808 mci->regmap = dev_get_regmap(pdev->dev.parent, NULL); in mt6360_charger_probe()
809 if (!mci->regmap) in mt6360_charger_probe()
810 return dev_err_probe(&pdev->dev, -ENODEV, "Failed to get parent regmap\n"); in mt6360_charger_probe()
814 return dev_err_probe(&pdev->dev, ret, "Failed to initial setting\n"); in mt6360_charger_probe()
816 memcpy(&mci->psy_desc, &mt6360_charger_desc, sizeof(mci->psy_desc)); in mt6360_charger_probe()
817 mci->psy_desc.name = dev_name(&pdev->dev); in mt6360_charger_probe()
819 charger_cfg.of_node = pdev->dev.of_node; in mt6360_charger_probe()
820 mci->psy = devm_power_supply_register(&pdev->dev, in mt6360_charger_probe()
821 &mci->psy_desc, &charger_cfg); in mt6360_charger_probe()
822 if (IS_ERR(mci->psy)) in mt6360_charger_probe()
823 return dev_err_probe(&pdev->dev, PTR_ERR(mci->psy), in mt6360_charger_probe()
829 return dev_err_probe(&pdev->dev, ret, "Failed to register irqs\n"); in mt6360_charger_probe()
831 config.dev = &pdev->dev; in mt6360_charger_probe()
832 config.regmap = mci->regmap; in mt6360_charger_probe()
833 mci->otg_rdev = devm_regulator_register(&pdev->dev, &mt6360_otg_rdesc, in mt6360_charger_probe()
835 if (IS_ERR(mci->otg_rdev)) in mt6360_charger_probe()
836 return PTR_ERR(mci->otg_rdev); in mt6360_charger_probe()
838 schedule_work(&mci->chrdet_work); in mt6360_charger_probe()
844 { .compatible = "mediatek,mt6360-chg", },
850 { "mt6360-chg", 0 },
857 .name = "mt6360-chg",
866 MODULE_DESCRIPTION("MT6360 Charger Driver");