Lines Matching +full:mt6370 +full:- +full:usb +full:- +full:otg +full:- +full:vbus
1 // SPDX-License-Identifier: GPL-2.0-only
10 #include <linux/devm-helpers.h>
184 ret = regmap_field_read(priv->rmap_fields[fd], ®_val); in mt6370_chg_field_get()
210 val = r->max_sel; in mt6370_chg_field_set()
216 return regmap_field_write(priv->rmap_fields[fd], val); in mt6370_chg_field_set()
238 struct mt6370_priv *priv = rcfg->driver_data; in mt6370_chg_otg_of_parse_cb()
240 rcfg->ena_gpiod = fwnode_gpiod_get_index(of_fwnode_handle(of), in mt6370_chg_otg_of_parse_cb()
243 rdesc->name); in mt6370_chg_otg_of_parse_cb()
244 if (IS_ERR(rcfg->ena_gpiod)) { in mt6370_chg_otg_of_parse_cb()
245 rcfg->ena_gpiod = NULL; in mt6370_chg_otg_of_parse_cb()
249 return regmap_update_bits(priv->regmap, MT6370_REG_CHG_CTRL1, in mt6370_chg_otg_of_parse_cb()
262 mutex_lock(&priv->attach_lock); in mt6370_chg_bc12_work_func()
263 attach = priv->attach; in mt6370_chg_bc12_work_func()
272 dev_err(priv->dev, "Failed to enable USB CHG EN\n"); in mt6370_chg_bc12_work_func()
277 dev_err(priv->dev, "Failed to get USB status\n"); in mt6370_chg_bc12_work_func()
282 dev_err(priv->dev, "Invalid attach state\n"); in mt6370_chg_bc12_work_func()
291 priv->psy_usb_type = POWER_SUPPLY_USB_TYPE_SDP; in mt6370_chg_bc12_work_func()
294 priv->psy_usb_type = POWER_SUPPLY_USB_TYPE_DCP; in mt6370_chg_bc12_work_func()
297 priv->psy_usb_type = POWER_SUPPLY_USB_TYPE_CDP; in mt6370_chg_bc12_work_func()
302 priv->psy_usb_type = POWER_SUPPLY_USB_TYPE_UNKNOWN; in mt6370_chg_bc12_work_func()
307 mutex_unlock(&priv->attach_lock); in mt6370_chg_bc12_work_func()
310 power_supply_changed(priv->psy); in mt6370_chg_bc12_work_func()
321 dev_err(priv->dev, "Failed to get FL_STROBE_EN\n"); in mt6370_chg_toggle_cfo()
326 dev_err(priv->dev, "Flash led is still in strobe mode\n"); in mt6370_chg_toggle_cfo()
333 dev_err(priv->dev, "Failed to disable CFO_EN\n"); in mt6370_chg_toggle_cfo()
340 dev_err(priv->dev, "Failed to enable CFO_EN\n"); in mt6370_chg_toggle_cfo()
351 return -EINVAL; in mt6370_chg_read_adc_chan()
353 ret = iio_read_channel_processed(&priv->iio_adcs[chan], val); in mt6370_chg_read_adc_chan()
355 dev_err(priv->dev, "Failed to read ADC\n"); in mt6370_chg_read_adc_chan()
369 dev_err(priv->dev, "Failed to get mivr state\n"); in mt6370_chg_mivr_dwork_func()
378 dev_err(priv->dev, "Failed to get ibus\n"); in mt6370_chg_mivr_dwork_func()
385 dev_err(priv->dev, "Failed to toggle cfo\n"); in mt6370_chg_mivr_dwork_func()
389 enable_irq(priv->irq_nums[MT6370_IRQ_MIVR]); in mt6370_chg_mivr_dwork_func()
390 pm_relax(priv->dev); in mt6370_chg_mivr_dwork_func()
399 /* Check in OTG mode or not */ in mt6370_chg_pwr_rdy_check()
402 dev_err(priv->dev, "Failed to get OTG state\n"); in mt6370_chg_pwr_rdy_check()
411 dev_err(priv->dev, "Failed to get opposite power ready state\n"); in mt6370_chg_pwr_rdy_check()
419 ret = power_supply_set_property(priv->psy, POWER_SUPPLY_PROP_ONLINE, in mt6370_chg_pwr_rdy_check()
422 dev_err(priv->dev, "Failed to start attach/detach flow\n"); in mt6370_chg_pwr_rdy_check()
428 mutex_lock(&priv->attach_lock); in mt6370_chg_get_online()
429 val->intval = !!priv->attach; in mt6370_chg_get_online()
430 mutex_unlock(&priv->attach_lock); in mt6370_chg_get_online()
442 ret = power_supply_get_property(priv->psy, POWER_SUPPLY_PROP_ONLINE, in mt6370_chg_get_status()
445 dev_err(priv->dev, "Failed to get online status\n"); in mt6370_chg_get_status()
450 val->intval = POWER_SUPPLY_STATUS_DISCHARGING; in mt6370_chg_get_status()
461 val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING; in mt6370_chg_get_status()
464 val->intval = POWER_SUPPLY_STATUS_CHARGING; in mt6370_chg_get_status()
467 val->intval = POWER_SUPPLY_STATUS_FULL; in mt6370_chg_get_status()
470 val->intval = POWER_SUPPLY_STATUS_UNKNOWN; in mt6370_chg_get_status()
504 val->intval = type; in mt6370_chg_get_charge_type()
512 bool pwr_rdy = !!val->intval; in mt6370_chg_set_online()
514 mutex_lock(&priv->attach_lock); in mt6370_chg_set_online()
515 if (pwr_rdy == !!priv->attach) { in mt6370_chg_set_online()
516 dev_err(priv->dev, "pwr_rdy is same(%d)\n", pwr_rdy); in mt6370_chg_set_online()
517 mutex_unlock(&priv->attach_lock); in mt6370_chg_set_online()
521 priv->attach = pwr_rdy; in mt6370_chg_set_online()
522 mutex_unlock(&priv->attach_lock); in mt6370_chg_set_online()
524 if (!queue_work(priv->wq, &priv->bc12_work)) in mt6370_chg_set_online()
525 dev_err(priv->dev, "bc12 work has already queued\n"); in mt6370_chg_set_online()
544 return mt6370_chg_field_get(priv, F_ICHG, &val->intval); in mt6370_chg_get_property()
546 val->intval = linear_range_get_max_value(&mt6370_chg_ranges[MT6370_RANGE_F_ICHG]); in mt6370_chg_get_property()
549 return mt6370_chg_field_get(priv, F_VOREG, &val->intval); in mt6370_chg_get_property()
551 val->intval = linear_range_get_max_value(&mt6370_chg_ranges[MT6370_RANGE_F_VOREG]); in mt6370_chg_get_property()
554 return mt6370_chg_field_get(priv, F_IAICR, &val->intval); in mt6370_chg_get_property()
556 return mt6370_chg_field_get(priv, F_VMIVR, &val->intval); in mt6370_chg_get_property()
558 return mt6370_chg_field_get(priv, F_IPREC, &val->intval); in mt6370_chg_get_property()
560 return mt6370_chg_field_get(priv, F_IEOC, &val->intval); in mt6370_chg_get_property()
562 val->intval = priv->psy_usb_type; in mt6370_chg_get_property()
565 return -EINVAL; in mt6370_chg_get_property()
579 return mt6370_chg_field_set(priv, F_ICHG, val->intval); in mt6370_chg_set_property()
581 return mt6370_chg_field_set(priv, F_VOREG, val->intval); in mt6370_chg_set_property()
583 return mt6370_chg_field_set(priv, F_IAICR, val->intval); in mt6370_chg_set_property()
585 return mt6370_chg_field_set(priv, F_VMIVR, val->intval); in mt6370_chg_set_property()
587 return mt6370_chg_field_set(priv, F_IPREC, val->intval); in mt6370_chg_set_property()
589 return mt6370_chg_field_set(priv, F_IEOC, val->intval); in mt6370_chg_set_property()
591 return -EINVAL; in mt6370_chg_set_property()
635 .name = "mt6370-charger",
662 .of_match = "usb-otg-vbus-regulator",
664 .name = "mt6370-usb-otg-vbus",
687 priv->rmap_fields[i] = devm_regmap_field_alloc(priv->dev, in mt6370_chg_init_rmap_fields()
688 priv->regmap, in mt6370_chg_init_rmap_fields()
690 if (IS_ERR(priv->rmap_fields[i])) in mt6370_chg_init_rmap_fields()
691 return dev_err_probe(priv->dev, in mt6370_chg_init_rmap_fields()
692 PTR_ERR(priv->rmap_fields[i]), in mt6370_chg_init_rmap_fields()
707 dev_err(priv->dev, "Failed to disable usb_chg_en\n"); in mt6370_chg_init_setting()
714 dev_err(priv->dev, "Failed to disable input current limit\n"); in mt6370_chg_init_setting()
721 dev_err(priv->dev, "Failed to set ICHG to 900mA"); in mt6370_chg_init_setting()
728 dev_err(priv->dev, "Failed to set IINLMTSEL\n"); in mt6370_chg_init_setting()
737 .name = "mediatek,chg-" #_name, \
745 .dev = priv->dev, in mt6370_chg_init_otg_regulator()
746 .regmap = priv->regmap, in mt6370_chg_init_otg_regulator()
750 priv->rdev = devm_regulator_register(priv->dev, &mt6370_chg_otg_rdesc, in mt6370_chg_init_otg_regulator()
753 return PTR_ERR_OR_ZERO(priv->rdev); in mt6370_chg_init_otg_regulator()
760 .of_node = dev_of_node(priv->dev), in mt6370_chg_init_psy()
763 priv->psy = devm_power_supply_register(priv->dev, &mt6370_chg_psy_desc, in mt6370_chg_init_psy()
766 return PTR_ERR_OR_ZERO(priv->psy); in mt6370_chg_init_psy()
790 /* Check in OTG mode or not */ in mt6370_attach_i_handler()
793 dev_err(priv->dev, "Failed to get OTG state\n"); in mt6370_attach_i_handler()
800 mutex_lock(&priv->attach_lock); in mt6370_attach_i_handler()
801 priv->attach = MT6370_ATTACH_STAT_ATTACH_BC12_DONE; in mt6370_attach_i_handler()
802 mutex_unlock(&priv->attach_lock); in mt6370_attach_i_handler()
804 if (!queue_work(priv->wq, &priv->bc12_work)) in mt6370_attach_i_handler()
805 dev_err(priv->dev, "bc12 work has already queued\n"); in mt6370_attach_i_handler()
823 pm_stay_awake(priv->dev); in mt6370_mivr_handler()
824 disable_irq_nosync(priv->irq_nums[MT6370_IRQ_MIVR]); in mt6370_mivr_handler()
825 schedule_delayed_work(&priv->mivr_dwork, msecs_to_jiffies(200)); in mt6370_mivr_handler()
849 ret = platform_get_irq_byname(to_platform_device(priv->dev), in mt6370_chg_init_irq()
852 return dev_err_probe(priv->dev, ret, in mt6370_chg_init_irq()
856 priv->irq_nums[i] = ret; in mt6370_chg_init_irq()
857 ret = devm_request_threaded_irq(priv->dev, ret, NULL, in mt6370_chg_init_irq()
860 dev_name(priv->dev), priv); in mt6370_chg_init_irq()
862 return dev_err_probe(priv->dev, ret, in mt6370_chg_init_irq()
872 struct device *dev = &pdev->dev; in mt6370_chg_probe()
878 return -ENOMEM; in mt6370_chg_probe()
880 priv->dev = &pdev->dev; in mt6370_chg_probe()
882 priv->regmap = dev_get_regmap(pdev->dev.parent, NULL); in mt6370_chg_probe()
883 if (!priv->regmap) in mt6370_chg_probe()
884 return dev_err_probe(dev, -ENODEV, "Failed to get regmap\n"); in mt6370_chg_probe()
892 priv->iio_adcs = devm_iio_channel_get_all(priv->dev); in mt6370_chg_probe()
893 if (IS_ERR(priv->iio_adcs)) in mt6370_chg_probe()
894 return dev_err_probe(dev, PTR_ERR(priv->iio_adcs), in mt6370_chg_probe()
899 return dev_err_probe(dev, ret, "Failed to init OTG regulator\n"); in mt6370_chg_probe()
905 mutex_init(&priv->attach_lock); in mt6370_chg_probe()
907 &priv->attach_lock); in mt6370_chg_probe()
911 priv->attach = MT6370_ATTACH_STAT_DETACH; in mt6370_chg_probe()
913 priv->wq = create_singlethread_workqueue(dev_name(priv->dev)); in mt6370_chg_probe()
914 if (!priv->wq) in mt6370_chg_probe()
915 return dev_err_probe(dev, -ENOMEM, in mt6370_chg_probe()
918 ret = devm_add_action_or_reset(dev, mt6370_chg_destroy_wq, priv->wq); in mt6370_chg_probe()
922 ret = devm_work_autocancel(dev, &priv->bc12_work, mt6370_chg_bc12_work_func); in mt6370_chg_probe()
926 ret = devm_delayed_work_autocancel(dev, &priv->mivr_dwork, mt6370_chg_mivr_dwork_func); in mt6370_chg_probe()
933 "Failed to init mt6370 charger setting\n"); in mt6370_chg_probe()
945 { .compatible = "mediatek,mt6370-charger", },
953 .name = "mt6370-charger",
960 MODULE_DESCRIPTION("MediaTek MT6370 Charger Driver");