Lines Matching +full:ilim +full:- +full:ma
1 // SPDX-License-Identifier: GPL-2.0-only
69 #define RT9467_NUM_VOTG (RT9467_OTG_MAX_uV - RT9467_OTG_MIN_uV + 1)
173 .name = "rt9467-irqs",
289 struct rt9467_chg_data *data = cfg->driver_data; in rt9467_otg_of_parse_cb()
291 cfg->ena_gpiod = fwnode_gpiod_get_index(of_fwnode_handle(of), in rt9467_otg_of_parse_cb()
294 desc->name); in rt9467_otg_of_parse_cb()
295 if (IS_ERR(cfg->ena_gpiod)) { in rt9467_otg_of_parse_cb()
296 cfg->ena_gpiod = NULL; in rt9467_otg_of_parse_cb()
300 return regmap_field_write(data->rm_field[F_OTG_PIN_EN], 1); in rt9467_otg_of_parse_cb()
319 .name = "rt9476-usb-otg-vbus",
320 .of_match = "usb-otg-vbus-regulator",
341 .dev = data->dev, in rt9467_register_otg_regulator()
342 .regmap = data->regmap, in rt9467_register_otg_regulator()
346 data->rdev = devm_regulator_register(data->dev, &rt9467_otg_desc, &cfg); in rt9467_register_otg_regulator()
347 return PTR_ERR_OR_ZERO(data->rdev); in rt9467_register_otg_regulator()
359 ret = regmap_field_read(data->rm_field[field], &sel); in rt9467_get_value_from_ranges()
379 value = range->max_sel; in rt9467_set_value_from_ranges()
384 return regmap_field_write(data->rm_field[field], sel); in rt9467_set_value_from_ranges()
408 return -EINVAL; in rt9467_get_adc_sel()
419 mutex_lock(&data->adc_lock); in rt9467_get_adc_raw_data()
425 ret = regmap_write(data->regmap, RT9467_REG_CHG_ADC, 0); in rt9467_get_adc_raw_data()
427 dev_err(data->dev, "Failed to clear ADC enable\n"); in rt9467_get_adc_raw_data()
432 ret = regmap_write(data->regmap, RT9467_REG_CHG_ADC, reg_val); in rt9467_get_adc_raw_data()
439 ret = regmap_read_poll_timeout(data->regmap, RT9467_REG_CHG_ADC, in rt9467_get_adc_raw_data()
444 dev_err(data->dev, "Failed to wait ADC conversion, chan = %d\n", chan); in rt9467_get_adc_raw_data()
448 ret = regmap_raw_read(data->regmap, RT9467_REG_ADC_DATA_H, in rt9467_get_adc_raw_data()
456 mutex_unlock(&data->adc_lock); in rt9467_get_adc_raw_data()
486 /* UUG MOS turn-on ratio will affect the IBUS adc scale */ in rt9467_get_adc()
495 /* PP MOS turn-on ratio will affect the ICHG adc scale */ in rt9467_get_adc()
505 *val = ((*val * 2) - 40) * 10; in rt9467_get_adc()
508 return -EINVAL; in rt9467_get_adc()
517 ret = regmap_field_read(data->rm_field[F_CHG_STAT], &status); in rt9467_psy_get_status()
541 mutex_lock(&data->ichg_ieoc_lock); in rt9467_psy_set_ichg()
544 dev_err(data->dev, "Minimum value must be 500mA\n"); in rt9467_psy_set_ichg()
553 &data->ichg_ua); in rt9467_psy_set_ichg()
558 mutex_unlock(&data->ichg_ieoc_lock); in rt9467_psy_set_ichg()
569 ret = regmap_read(data->regmap, RT9467_REG_CHG_STATC, &statc); in rt9467_run_aicl()
571 dev_err(data->dev, "Failed to read status\n"); in rt9467_run_aicl()
576 dev_info(data->dev, "Condition not matched %d\n", statc); in rt9467_run_aicl()
583 dev_err(data->dev, "Failed to get mivr\n"); in rt9467_run_aicl()
593 ret = regmap_field_write(data->rm_field[F_AICL_MEAS], 1); in rt9467_run_aicl()
595 dev_err(data->dev, "Failed to set aicl measurement\n"); in rt9467_run_aicl()
599 reinit_completion(&data->aicl_done); in rt9467_run_aicl()
600 ret = wait_for_completion_timeout(&data->aicl_done, msecs_to_jiffies(3500)); in rt9467_run_aicl()
602 return -ETIMEDOUT; in rt9467_run_aicl()
606 dev_err(data->dev, "Failed to get aicr\n"); in rt9467_run_aicl()
610 dev_info(data->dev, "aicr get = %d uA\n", aicr_get); in rt9467_run_aicl()
618 mutex_lock(&data->ichg_ieoc_lock); in rt9467_psy_set_ieoc()
624 ret = rt9467_get_value_from_ranges(data, F_IEOC, RT9467_RANGE_IEOC, &data->ieoc_ua); in rt9467_psy_set_ieoc()
629 mutex_unlock(&data->ichg_ieoc_lock); in rt9467_psy_set_ieoc()
656 return rt9467_psy_get_status(data, &val->intval); in rt9467_psy_get_property()
658 return regmap_field_read(data->rm_field[F_PWR_RDY], &val->intval); in rt9467_psy_get_property()
660 mutex_lock(&data->attach_lock); in rt9467_psy_get_property()
661 if (data->psy_usb_type == POWER_SUPPLY_USB_TYPE_UNKNOWN || in rt9467_psy_get_property()
662 data->psy_usb_type == POWER_SUPPLY_USB_TYPE_SDP) in rt9467_psy_get_property()
663 val->intval = 500000; in rt9467_psy_get_property()
665 val->intval = 1500000; in rt9467_psy_get_property()
666 mutex_unlock(&data->attach_lock); in rt9467_psy_get_property()
669 mutex_lock(&data->ichg_ieoc_lock); in rt9467_psy_get_property()
670 val->intval = data->ichg_ua; in rt9467_psy_get_property()
671 mutex_unlock(&data->ichg_ieoc_lock); in rt9467_psy_get_property()
674 val->intval = RT9467_ICHG_MAX_uA; in rt9467_psy_get_property()
679 &val->intval); in rt9467_psy_get_property()
681 val->intval = RT9467_CV_MAX_uV; in rt9467_psy_get_property()
686 &val->intval); in rt9467_psy_get_property()
690 &val->intval); in rt9467_psy_get_property()
692 mutex_lock(&data->attach_lock); in rt9467_psy_get_property()
693 val->intval = data->psy_usb_type; in rt9467_psy_get_property()
694 mutex_unlock(&data->attach_lock); in rt9467_psy_get_property()
699 &val->intval); in rt9467_psy_get_property()
701 mutex_lock(&data->ichg_ieoc_lock); in rt9467_psy_get_property()
702 val->intval = data->ieoc_ua; in rt9467_psy_get_property()
703 mutex_unlock(&data->ichg_ieoc_lock); in rt9467_psy_get_property()
706 return -ENODATA; in rt9467_psy_get_property()
718 return regmap_field_write(data->rm_field[F_CHG_EN], val->intval); in rt9467_psy_set_property()
720 return regmap_field_write(data->rm_field[F_HZ], val->intval); in rt9467_psy_set_property()
722 return rt9467_psy_set_ichg(data, val->intval); in rt9467_psy_set_property()
725 RT9467_RANGE_VOREG, val->intval); in rt9467_psy_set_property()
727 if (val->intval == -1) in rt9467_psy_set_property()
732 val->intval); in rt9467_psy_set_property()
735 RT9467_RANGE_VMIVR, val->intval); in rt9467_psy_set_property()
738 RT9467_RANGE_IPREC, val->intval); in rt9467_psy_set_property()
740 return rt9467_psy_set_ieoc(data, val->intval); in rt9467_psy_set_property()
742 return -EINVAL; in rt9467_psy_set_property()
765 .name = "rt9467-charger",
790 ret = regmap_field_read(data->rm_field[F_SHIP_MODE], &sysoff_enable); in sysoff_enable_show()
809 ret = regmap_field_write(data->rm_field[F_SHIP_MODE], !!tmp); in sysoff_enable_store()
829 .of_node = dev_of_node(data->dev), in rt9467_register_psy()
833 data->psy = devm_power_supply_register(data->dev, &rt9467_chg_psy_desc, in rt9467_register_psy()
835 return PTR_ERR_OR_ZERO(data->psy); in rt9467_register_psy()
844 * back-boost workaround in rt9467_mivr_handler()
845 * If (mivr_active & ibus < 100mA), toggle cfo bit in rt9467_mivr_handler()
847 ret = regmap_field_read(data->rm_field[F_CHG_MIVR], &mivr_act); in rt9467_mivr_handler()
849 dev_err(data->dev, "Failed to read MIVR stat\n"); in rt9467_mivr_handler()
858 dev_err(data->dev, "Failed to get IBUS\n"); in rt9467_mivr_handler()
863 ret = regmap_field_write(data->rm_field[F_CFO_EN], 0); in rt9467_mivr_handler()
864 ret |= regmap_field_write(data->rm_field[F_CFO_EN], 1); in rt9467_mivr_handler()
866 dev_err(data->dev, "Failed to toggle cfo\n"); in rt9467_mivr_handler()
878 ret = regmap_read(data->regmap, RT9467_REG_CHG_STATC, &new_stat); in rt9467_statc_handler()
880 dev_err(data->dev, "Failed to read chg_statc\n"); in rt9467_statc_handler()
884 evts = data->old_stat ^ new_stat; in rt9467_statc_handler()
885 data->old_stat = new_stat; in rt9467_statc_handler()
890 dev_err(data->dev, "Failed to handle mivr stat\n"); in rt9467_statc_handler()
903 ret = regmap_read(data->regmap, RT9467_REG_DEVICE_ID, &dev_id); in rt9467_wdt_handler()
905 dev_err(data->dev, "Failed to kick wdt (%d)\n", ret); in rt9467_wdt_handler()
918 ret = regmap_field_read(data->rm_field[F_USB_STATUS], &usb_stat); in rt9467_report_usb_state()
919 ret |= regmap_field_read(data->rm_field[F_PWR_RDY], &power_ready); in rt9467_report_usb_state()
926 mutex_lock(&data->attach_lock); in rt9467_report_usb_state()
930 data->psy_usb_type = POWER_SUPPLY_USB_TYPE_UNKNOWN; in rt9467_report_usb_state()
933 data->psy_usb_type = POWER_SUPPLY_USB_TYPE_SDP; in rt9467_report_usb_state()
936 data->psy_usb_type = POWER_SUPPLY_USB_TYPE_DCP; in rt9467_report_usb_state()
939 data->psy_usb_type = POWER_SUPPLY_USB_TYPE_DCP; in rt9467_report_usb_state()
942 data->psy_usb_type = POWER_SUPPLY_USB_TYPE_CDP; in rt9467_report_usb_state()
950 mutex_unlock(&data->attach_lock); in rt9467_report_usb_state()
953 power_supply_changed(data->psy); in rt9467_report_usb_state()
965 dev_err(data->dev, "Failed to report attach type (%d)\n", ret); in rt9467_usb_state_handler()
976 complete(&data->aicl_done); in rt9467_aiclmeas_handler()
989 struct device *dev = data->dev; in rt9467_request_interrupt()
1007 if (data->vid == RT9466_VID) { in rt9467_request_interrupt()
1016 virq = regmap_irq_get_virq(data->irq_chip_data, chg_irqs[i].hwirq); in rt9467_request_interrupt()
1018 return dev_err_probe(dev, -EINVAL, "Failed to get (%s) irq\n", in rt9467_request_interrupt()
1033 struct device *dev = data->dev; in rt9467_do_charger_init()
1036 ret = regmap_write(data->regmap, RT9467_REG_CHG_ADC, 0); in rt9467_do_charger_init()
1041 &data->ichg_ua); in rt9467_do_charger_init()
1043 &data->ieoc_ua); in rt9467_do_charger_init()
1047 ret = regmap_update_bits(data->regmap, RT9467_REG_CHG_STATC_CTRL, in rt9467_do_charger_init()
1053 ret = regmap_field_write(data->rm_field[F_IINLMTSEL], in rt9467_do_charger_init()
1061 /* Disable hardware ILIM */ in rt9467_do_charger_init()
1062 ret = regmap_field_write(data->rm_field[F_ILIM_EN], 0); in rt9467_do_charger_init()
1064 return dev_err_probe(dev, ret, "Failed to disable hardware ILIM\n"); in rt9467_do_charger_init()
1067 ret = regmap_field_write(data->rm_field[F_OCP], 1); in rt9467_do_charger_init()
1072 ret = regmap_field_write(data->rm_field[F_TE], 1); in rt9467_do_charger_init()
1077 ret = regmap_field_write(data->rm_field[F_WT_FC], 4); in rt9467_do_charger_init()
1082 ret = regmap_field_write(data->rm_field[F_USBCHGEN], 0); in rt9467_do_charger_init()
1086 return regmap_field_write(data->rm_field[F_USBCHGEN], 1); in rt9467_do_charger_init()
1118 ret = regmap_field_read(data->rm_field[F_VENDOR], &vid); in rt9467_check_vendor_info()
1120 dev_err(data->dev, "Failed to get vid\n"); in rt9467_check_vendor_info()
1125 return dev_err_probe(data->dev, -ENODEV, in rt9467_check_vendor_info()
1128 data->vid = vid; in rt9467_check_vendor_info()
1137 ret = regmap_field_write(data->rm_field[F_HZ], 0); in rt9467_reset_chip()
1141 return regmap_field_write(data->rm_field[F_RST], 1); in rt9467_reset_chip()
1174 struct device *dev = &i2c->dev; in rt9467_charger_probe()
1181 return -ENOMEM; in rt9467_charger_probe()
1183 data->dev = &i2c->dev; in rt9467_charger_probe()
1187 ceb_gpio = devm_gpiod_get_optional(dev, "charge-enable", GPIOD_OUT_HIGH); in rt9467_charger_probe()
1192 data->regmap = devm_regmap_init_i2c(i2c, &rt9467_regmap_config); in rt9467_charger_probe()
1193 if (IS_ERR(data->regmap)) in rt9467_charger_probe()
1194 return dev_err_probe(dev, PTR_ERR(data->regmap), in rt9467_charger_probe()
1197 ret = devm_regmap_field_bulk_alloc(dev, data->regmap, in rt9467_charger_probe()
1198 data->rm_field, rt9467_chg_fields, in rt9467_charger_probe()
1211 ret = devm_regmap_add_irq_chip(dev, data->regmap, i2c->irq, in rt9467_charger_probe()
1213 &rt9467_irq_chip, &data->irq_chip_data); in rt9467_charger_probe()
1217 mutex_init(&data->adc_lock); in rt9467_charger_probe()
1219 &data->adc_lock); in rt9467_charger_probe()
1223 mutex_init(&data->attach_lock); in rt9467_charger_probe()
1225 &data->attach_lock); in rt9467_charger_probe()
1229 mutex_init(&data->ichg_ieoc_lock); in rt9467_charger_probe()
1231 &data->ichg_ieoc_lock); in rt9467_charger_probe()
1235 init_completion(&data->aicl_done); in rt9467_charger_probe()
1237 &data->aicl_done); in rt9467_charger_probe()
1264 .name = "rt9467-charger",