Lines Matching +full:chg +full:- +full:int
1 // SPDX-License-Identifier: GPL-2.0
6 #include <linux/devm-helpers.h>
135 int psy_usb_type;
157 static int mt6360_get_chrdet_ext_stat(struct mt6360_chg_info *mci, in mt6360_get_chrdet_ext_stat()
160 int ret; in mt6360_get_chrdet_ext_stat()
161 unsigned int regval; in mt6360_get_chrdet_ext_stat()
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()
173 int ret; in mt6360_charger_get_online()
179 val->intval = pwr_rdy ? true : false; in mt6360_charger_get_online()
183 static int mt6360_charger_get_status(struct mt6360_chg_info *mci, in mt6360_charger_get_status()
186 int status, ret; in mt6360_charger_get_status()
187 unsigned int regval; in mt6360_charger_get_status()
198 ret = regmap_read(mci->regmap, MT6360_PMU_CHG_STAT, ®val); in mt6360_charger_get_status()
214 ret = -EIO; in mt6360_charger_get_status()
218 val->intval = status; in mt6360_charger_get_status()
222 static int mt6360_charger_get_charge_type(struct mt6360_chg_info *mci, in mt6360_charger_get_charge_type()
225 int type, ret; in mt6360_charger_get_charge_type()
226 unsigned int regval; in mt6360_charger_get_charge_type()
229 ret = regmap_read(mci->regmap, MT6360_PMU_CHG_STAT, ®val); in mt6360_charger_get_charge_type()
249 val->intval = type; in mt6360_charger_get_charge_type()
253 static int mt6360_charger_get_ichg(struct mt6360_chg_info *mci, in mt6360_charger_get_ichg()
256 int ret; in mt6360_charger_get_ichg()
259 ret = regmap_read(mci->regmap, MT6360_PMU_CHG_CTRL7, &sel); in mt6360_charger_get_ichg()
265 val->intval = value; in mt6360_charger_get_ichg()
269 static int mt6360_charger_get_max_ichg(struct mt6360_chg_info *mci, in mt6360_charger_get_max_ichg()
272 val->intval = MT6360_ICHG_MAX; in mt6360_charger_get_max_ichg()
276 static int mt6360_charger_get_cv(struct mt6360_chg_info *mci, in mt6360_charger_get_cv()
279 int ret; in mt6360_charger_get_cv()
282 ret = regmap_read(mci->regmap, MT6360_PMU_CHG_CTRL4, &sel); in mt6360_charger_get_cv()
288 val->intval = value; in mt6360_charger_get_cv()
292 static int mt6360_charger_get_max_cv(struct mt6360_chg_info *mci, in mt6360_charger_get_max_cv()
295 val->intval = MT6360_VOREG_MAX; in mt6360_charger_get_max_cv()
299 static int mt6360_charger_get_aicr(struct mt6360_chg_info *mci, in mt6360_charger_get_aicr()
302 int ret; in mt6360_charger_get_aicr()
305 ret = regmap_read(mci->regmap, MT6360_PMU_CHG_CTRL3, &sel); in mt6360_charger_get_aicr()
311 val->intval = value; in mt6360_charger_get_aicr()
315 static int mt6360_charger_get_mivr(struct mt6360_chg_info *mci, in mt6360_charger_get_mivr()
318 int ret; in mt6360_charger_get_mivr()
321 ret = regmap_read(mci->regmap, MT6360_PMU_CHG_CTRL6, &sel); in mt6360_charger_get_mivr()
327 val->intval = value; in mt6360_charger_get_mivr()
331 static int mt6360_charger_get_iprechg(struct mt6360_chg_info *mci, in mt6360_charger_get_iprechg()
334 int ret; in mt6360_charger_get_iprechg()
337 ret = regmap_read(mci->regmap, MT6360_PMU_CHG_CTRL8, &sel); in mt6360_charger_get_iprechg()
343 val->intval = value; in mt6360_charger_get_iprechg()
347 static int mt6360_charger_get_ieoc(struct mt6360_chg_info *mci, in mt6360_charger_get_ieoc()
350 int ret; in mt6360_charger_get_ieoc()
353 ret = regmap_read(mci->regmap, MT6360_PMU_CHG_CTRL9, &sel); in mt6360_charger_get_ieoc()
359 val->intval = value; in mt6360_charger_get_ieoc()
363 static int mt6360_charger_set_online(struct mt6360_chg_info *mci, in mt6360_charger_set_online()
366 u8 force_sleep = val->intval ? 0 : 1; in mt6360_charger_set_online()
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()
379 linear_range_get_selector_within(&mt6360_chg_range[MT6360_RANGE_ICHG], val->intval, &sel); in mt6360_charger_set_ichg()
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()
391 linear_range_get_selector_within(&mt6360_chg_range[MT6360_RANGE_VOREG], val->intval, &sel); in mt6360_charger_set_cv()
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()
403 linear_range_get_selector_within(&mt6360_chg_range[MT6360_RANGE_AICR], val->intval, &sel); in mt6360_charger_set_aicr()
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()
415 linear_range_get_selector_within(&mt6360_chg_range[MT6360_RANGE_VMIVR], val->intval, &sel); in mt6360_charger_set_mivr()
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()
427 linear_range_get_selector_within(&mt6360_chg_range[MT6360_RANGE_IPREC], val->intval, &sel); in mt6360_charger_set_iprechg()
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()
439 linear_range_get_selector_within(&mt6360_chg_range[MT6360_RANGE_IEOC], val->intval, &sel); in mt6360_charger_set_ieoc()
440 return regmap_update_bits(mci->regmap, in mt6360_charger_set_ieoc()
446 static int mt6360_charger_get_property(struct power_supply *psy, in mt6360_charger_get_property()
451 int ret = 0; in mt6360_charger_get_property()
488 val->intval = mci->psy_usb_type; in mt6360_charger_get_property()
491 ret = -ENODATA; in mt6360_charger_get_property()
496 static int mt6360_charger_set_property(struct power_supply *psy, in mt6360_charger_set_property()
501 int ret; in mt6360_charger_set_property()
526 ret = -EINVAL; in mt6360_charger_set_property()
531 static int mt6360_charger_property_is_writeable(struct power_supply *psy, in mt6360_charger_property_is_writeable()
586 .of_match = "usb-otg-vbus-regulator",
587 .name = "usb-otg-vbus",
600 static irqreturn_t mt6360_pmu_attach_i_handler(int irq, void *data) in mt6360_pmu_attach_i_handler()
603 int ret; in mt6360_pmu_attach_i_handler()
604 unsigned int usb_status; in mt6360_pmu_attach_i_handler()
605 int last_usb_type; in mt6360_pmu_attach_i_handler()
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()
657 int ret; in mt6360_handle_chrdet_ext_evt()
660 mutex_lock(&mci->chgdet_lock); 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()
694 static irqreturn_t mt6360_pmu_chrdet_ext_evt_handler(int irq, void *data) in mt6360_pmu_chrdet_ext_evt_handler()
702 static int mt6360_chg_irq_register(struct platform_device *pdev) in mt6360_chg_irq_register()
711 int i, ret; in mt6360_chg_irq_register()
718 ret = devm_request_threaded_irq(&pdev->dev, ret, NULL, in mt6360_chg_irq_register()
724 return dev_err_probe(&pdev->dev, ret, "Failed to request %s irq\n", in mt6360_chg_irq_register()
734 int i; in mt6360_vinovp_trans_to_sel()
737 for (i = 0; i < ARRAY_SIZE(vinovp_tbl)-1; i++) { in mt6360_vinovp_trans_to_sel()
744 static int mt6360_chg_init_setting(struct mt6360_chg_info *mci) in mt6360_chg_init_setting()
746 int ret; in mt6360_chg_init_setting()
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()
779 static int mt6360_charger_probe(struct platform_device *pdev) in mt6360_charger_probe()
784 int ret; in mt6360_charger_probe()
786 mci = devm_kzalloc(&pdev->dev, sizeof(*mci), GFP_KERNEL); in mt6360_charger_probe()
788 return -ENOMEM; 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()
794 ret = devm_work_autocancel(&pdev->dev, &mci->chrdet_work, mt6360_chrdet_work); in mt6360_charger_probe()
796 return dev_err_probe(&pdev->dev, ret, "Failed to set delayed work\n"); in mt6360_charger_probe()
798 ret = device_property_read_u32(&pdev->dev, "richtek,vinovp-microvolt", &mci->vinovp); in mt6360_charger_probe()
800 dev_warn(&pdev->dev, "Failed to parse vinovp in DT, keep default 6.5v\n"); 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()
804 return dev_err_probe(&pdev->dev, -ENODEV, "Failed to get parent regmap\n"); in mt6360_charger_probe()
808 return dev_err_probe(&pdev->dev, ret, "Failed to initial setting\n"); 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()
813 charger_cfg.of_node = pdev->dev.of_node; 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()
823 return dev_err_probe(&pdev->dev, ret, "Failed to register irqs\n"); in mt6360_charger_probe()
825 config.dev = &pdev->dev; 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()
838 { .compatible = "mediatek,mt6360-chg", },
844 { "mt6360-chg", 0 },
851 .name = "mt6360-chg",