Lines Matching +full:range +full:- +full:microamp
1 // SPDX-License-Identifier: GPL-2.0-only
192 enum rt9471_ranges range, int val) in rt9471_set_value_by_field_range() argument
197 return -EINVAL; in rt9471_set_value_by_field_range()
199 linear_range_get_selector_within(rt9471_chg_ranges + range, val, &sel); in rt9471_set_value_by_field_range()
201 return regmap_field_write(chip->rm_fields[field], sel); in rt9471_set_value_by_field_range()
207 enum rt9471_ranges range, int *val) in rt9471_get_value_by_field_range() argument
212 ret = regmap_field_read(chip->rm_fields[field], &sel); in rt9471_get_value_by_field_range()
216 ret = linear_range_get_value(rt9471_chg_ranges + range, sel, &rvalue); in rt9471_get_value_by_field_range()
224 static int rt9471_set_ieoc(struct rt9471_chip *chip, int microamp) in rt9471_set_ieoc() argument
228 if (microamp == 0) in rt9471_set_ieoc()
229 return regmap_field_write(chip->rm_fields[F_TE], 0); in rt9471_set_ieoc()
231 ret = rt9471_set_value_by_field_range(chip, F_IEOC_CHG, RT9471_RANGE_IEOC, microamp); in rt9471_set_ieoc()
236 return regmap_field_write(chip->rm_fields[F_TE], 1); in rt9471_set_ieoc()
239 static int rt9471_get_ieoc(struct rt9471_chip *chip, int *microamp) in rt9471_get_ieoc() argument
244 ret = regmap_field_read(chip->rm_fields[F_TE], &chg_term_enable); in rt9471_get_ieoc()
249 *microamp = 0; in rt9471_get_ieoc()
253 return rt9471_get_value_by_field_range(chip, F_IEOC_CHG, RT9471_RANGE_IEOC, microamp); in rt9471_get_ieoc()
261 ret = regmap_field_read(chip->rm_fields[F_ST_CHG_RDY], &chg_ready); in rt9471_get_status()
265 ret = regmap_field_read(chip->rm_fields[F_ST_CHG_DONE], &chg_done); in rt9471_get_status()
269 ret = regmap_read(chip->regmap, RT9471_REG_STAT1, &fault_stat); in rt9471_get_status()
292 ret = regmap_field_read(chip->rm_fields[F_ST_VBUS_GD], &vbus_gd); in rt9471_get_vbus_good()
302 mutex_lock(&chip->var_lock); in rt9471_get_usb_type()
303 *usb_type = chip->psy_usb_type; in rt9471_get_usb_type()
304 mutex_unlock(&chip->var_lock); in rt9471_get_usb_type()
310 int *microamp) in rt9471_get_usb_type_current() argument
312 mutex_lock(&chip->var_lock); in rt9471_get_usb_type_current()
313 *microamp = chip->psy_usb_curr; in rt9471_get_usb_type_current()
314 mutex_unlock(&chip->var_lock); in rt9471_get_usb_type_current()
359 int value = val->intval; in rt9471_charger_set_property()
363 return regmap_field_write(chip->rm_fields[F_CHG_EN], !!value); in rt9471_charger_set_property()
365 return regmap_field_write(chip->rm_fields[F_HZ], !value); in rt9471_charger_set_property()
377 return rt9471_set_ieoc(chip, val->intval); in rt9471_charger_set_property()
379 return -EINVAL; in rt9471_charger_set_property()
391 int *pvalue = &val->intval; in rt9471_charger_get_property()
408 val->intval = RT9471_VCHG_MAXUV; in rt9471_charger_get_property()
421 val->strval = rt9471_model; in rt9471_charger_get_property()
424 val->strval = rt9471_manufacturer; in rt9471_charger_get_property()
427 return -ENODATA; in rt9471_charger_get_property()
435 power_supply_changed(chip->psy); in rt9471_vbus_gd_handler()
446 ret = regmap_field_read(chip->rm_fields[F_ST_VBUS_GD], &vbus_gd); in rt9471_detach_handler()
454 mutex_lock(&chip->var_lock); in rt9471_detach_handler()
455 chip->psy_usb_type = POWER_SUPPLY_USB_TYPE_UNKNOWN; in rt9471_detach_handler()
456 chip->psy_usb_curr = 0; in rt9471_detach_handler()
457 mutex_unlock(&chip->var_lock); in rt9471_detach_handler()
459 power_supply_changed(chip->psy); in rt9471_detach_handler()
471 ret = regmap_field_read(chip->rm_fields[F_PORT_STAT], &port_stat); in rt9471_bc12_done_handler()
511 mutex_lock(&chip->var_lock); in rt9471_bc12_done_handler()
512 chip->psy_usb_type = usb_type; in rt9471_bc12_done_handler()
513 chip->psy_usb_curr = usb_curr; in rt9471_bc12_done_handler()
514 mutex_unlock(&chip->var_lock); in rt9471_bc12_done_handler()
516 power_supply_changed(chip->psy); in rt9471_bc12_done_handler()
526 ret = regmap_field_write(chip->rm_fields[F_WDT_RST], 1); in rt9471_wdt_handler()
535 regulator_notifier_call_chain(chip->otg_rdev, REGULATOR_EVENT_FAIL, NULL); in rt9471_otg_fault_handler()
549 struct device *dev = chip->dev; in rt9471_register_interrupts()
566 virq = regmap_irq_get_virq(chip->irq_chip_data, curr->hwirq); in rt9471_register_interrupts()
570 ret = devm_request_threaded_irq(dev, virq, NULL, curr->handler, in rt9471_register_interrupts()
571 IRQF_ONESHOT, curr->name, chip); in rt9471_register_interrupts()
574 curr->name); in rt9471_register_interrupts()
594 .of_match = of_match_ptr("usb-otg-vbus-regulator"),
595 .name = "rt9471-otg-vbus",
614 struct device *dev = chip->dev; in rt9471_register_otg_regulator()
617 chip->otg_rdev = devm_regulator_register(dev, &rt9471_otg_rdesc, &cfg); in rt9471_register_otg_regulator()
619 return PTR_ERR_OR_ZERO(chip->otg_rdev); in rt9471_register_otg_regulator()
634 ret = regmap_field_read(chip->rm_fields[F_BATFET_DIS], &sysoff_enable); in sysoff_enable_show()
653 ret = regmap_field_write(chip->rm_fields[F_BATFET_DIS], !!tmp); in sysoff_enable_store()
667 ret = regmap_field_read(chip->rm_fields[F_BC12_EN], &bc12_enable); in port_detect_enable_show()
686 ret = regmap_field_write(chip->rm_fields[F_BC12_EN], !!tmp); in port_detect_enable_store()
706 struct device *dev = chip->dev; in rt9471_register_psy()
707 struct power_supply_desc *desc = &chip->psy_desc; in rt9471_register_psy()
712 cfg.of_node = dev->of_node; in rt9471_register_psy()
715 psy_name = devm_kasprintf(dev, GFP_KERNEL, "rt9471-%s", dev_name(dev)); in rt9471_register_psy()
717 return -ENOMEM; in rt9471_register_psy()
719 desc->name = psy_name; in rt9471_register_psy()
720 desc->type = POWER_SUPPLY_TYPE_USB; in rt9471_register_psy()
721 desc->usb_types = BIT(POWER_SUPPLY_USB_TYPE_SDP) | in rt9471_register_psy()
726 desc->properties = rt9471_charger_properties; in rt9471_register_psy()
727 desc->num_properties = ARRAY_SIZE(rt9471_charger_properties); in rt9471_register_psy()
728 desc->get_property = rt9471_charger_get_property; in rt9471_register_psy()
729 desc->set_property = rt9471_charger_set_property; in rt9471_register_psy()
730 desc->property_is_writeable = rt9471_charger_property_is_writeable; in rt9471_register_psy()
732 chip->psy = devm_power_supply_register(dev, desc, &cfg); in rt9471_register_psy()
734 return PTR_ERR_OR_ZERO(chip->psy); in rt9471_register_psy()
770 .name = "rt9471-irqs",
790 struct device *dev = chip->dev; in rt9471_check_devinfo()
794 ret = regmap_field_read(chip->rm_fields[F_DEVICE_ID], &dev_id); in rt9471_check_devinfo()
805 return dev_err_probe(dev, -ENODEV, "Incorrect device id\n"); in rt9471_check_devinfo()
832 struct device *dev = &i2c->dev; in rt9471_probe()
840 return -ENOMEM; in rt9471_probe()
842 chip->dev = dev; in rt9471_probe()
843 mutex_init(&chip->var_lock); in rt9471_probe()
847 ce_gpio = devm_gpiod_get_optional(dev, "charge-enable", GPIOD_OUT_HIGH); in rt9471_probe()
856 chip->regmap = regmap; in rt9471_probe()
858 ret = devm_regmap_field_bulk_alloc(dev, regmap, chip->rm_fields, in rt9471_probe()
873 ret = devm_regmap_add_irq_chip(dev, regmap, i2c->irq, in rt9471_probe()
875 &rt9471_irq_chip, &chip->irq_chip_data); in rt9471_probe()
892 return regmap_field_write(chip->rm_fields[F_BC12_EN], 1); in rt9471_probe()
903 regmap_field_write(chip->rm_fields[F_REG_RST], 1); in rt9471_shutdown()