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()
367 int value = val->intval; in rt9471_charger_set_property()
371 return regmap_field_write(chip->rm_fields[F_CHG_EN], !!value); in rt9471_charger_set_property()
373 return regmap_field_write(chip->rm_fields[F_HZ], !value); in rt9471_charger_set_property()
385 return rt9471_set_ieoc(chip, val->intval); in rt9471_charger_set_property()
387 return -EINVAL; in rt9471_charger_set_property()
399 int *pvalue = &val->intval; in rt9471_charger_get_property()
416 val->intval = RT9471_VCHG_MAXUV; in rt9471_charger_get_property()
429 val->strval = rt9471_model; in rt9471_charger_get_property()
432 val->strval = rt9471_manufacturer; in rt9471_charger_get_property()
435 return -ENODATA; in rt9471_charger_get_property()
443 power_supply_changed(chip->psy); in rt9471_vbus_gd_handler()
454 ret = regmap_field_read(chip->rm_fields[F_ST_VBUS_GD], &vbus_gd); in rt9471_detach_handler()
462 mutex_lock(&chip->var_lock); in rt9471_detach_handler()
463 chip->psy_usb_type = POWER_SUPPLY_USB_TYPE_UNKNOWN; in rt9471_detach_handler()
464 chip->psy_usb_curr = 0; in rt9471_detach_handler()
465 mutex_unlock(&chip->var_lock); in rt9471_detach_handler()
467 power_supply_changed(chip->psy); in rt9471_detach_handler()
479 ret = regmap_field_read(chip->rm_fields[F_PORT_STAT], &port_stat); in rt9471_bc12_done_handler()
519 mutex_lock(&chip->var_lock); in rt9471_bc12_done_handler()
520 chip->psy_usb_type = usb_type; in rt9471_bc12_done_handler()
521 chip->psy_usb_curr = usb_curr; in rt9471_bc12_done_handler()
522 mutex_unlock(&chip->var_lock); in rt9471_bc12_done_handler()
524 power_supply_changed(chip->psy); in rt9471_bc12_done_handler()
534 ret = regmap_field_write(chip->rm_fields[F_WDT_RST], 1); in rt9471_wdt_handler()
543 regulator_notifier_call_chain(chip->otg_rdev, REGULATOR_EVENT_FAIL, NULL); in rt9471_otg_fault_handler()
557 struct device *dev = chip->dev; in rt9471_register_interrupts()
574 virq = regmap_irq_get_virq(chip->irq_chip_data, curr->hwirq); in rt9471_register_interrupts()
578 ret = devm_request_threaded_irq(dev, virq, NULL, curr->handler, in rt9471_register_interrupts()
579 IRQF_ONESHOT, curr->name, chip); in rt9471_register_interrupts()
582 curr->name); in rt9471_register_interrupts()
602 .of_match = of_match_ptr("usb-otg-vbus-regulator"),
603 .name = "rt9471-otg-vbus",
622 struct device *dev = chip->dev; in rt9471_register_otg_regulator()
625 chip->otg_rdev = devm_regulator_register(dev, &rt9471_otg_rdesc, &cfg); in rt9471_register_otg_regulator()
627 return PTR_ERR_OR_ZERO(chip->otg_rdev); in rt9471_register_otg_regulator()
642 ret = regmap_field_read(chip->rm_fields[F_BATFET_DIS], &sysoff_enable); in sysoff_enable_show()
661 ret = regmap_field_write(chip->rm_fields[F_BATFET_DIS], !!tmp); in sysoff_enable_store()
675 ret = regmap_field_read(chip->rm_fields[F_BC12_EN], &bc12_enable); in port_detect_enable_show()
694 ret = regmap_field_write(chip->rm_fields[F_BC12_EN], !!tmp); in port_detect_enable_store()
714 struct device *dev = chip->dev; in rt9471_register_psy()
715 struct power_supply_desc *desc = &chip->psy_desc; in rt9471_register_psy()
720 cfg.of_node = dev->of_node; in rt9471_register_psy()
723 psy_name = devm_kasprintf(dev, GFP_KERNEL, "rt9471-%s", dev_name(dev)); in rt9471_register_psy()
725 return -ENOMEM; in rt9471_register_psy()
727 desc->name = psy_name; in rt9471_register_psy()
728 desc->type = POWER_SUPPLY_TYPE_USB; in rt9471_register_psy()
729 desc->usb_types = rt9471_charger_usb_types; in rt9471_register_psy()
730 desc->num_usb_types = ARRAY_SIZE(rt9471_charger_usb_types); in rt9471_register_psy()
731 desc->properties = rt9471_charger_properties; in rt9471_register_psy()
732 desc->num_properties = ARRAY_SIZE(rt9471_charger_properties); in rt9471_register_psy()
733 desc->get_property = rt9471_charger_get_property; in rt9471_register_psy()
734 desc->set_property = rt9471_charger_set_property; in rt9471_register_psy()
735 desc->property_is_writeable = rt9471_charger_property_is_writeable; in rt9471_register_psy()
737 chip->psy = devm_power_supply_register(dev, desc, &cfg); in rt9471_register_psy()
739 return PTR_ERR_OR_ZERO(chip->psy); in rt9471_register_psy()
775 .name = "rt9471-irqs",
795 struct device *dev = chip->dev; in rt9471_check_devinfo()
799 ret = regmap_field_read(chip->rm_fields[F_DEVICE_ID], &dev_id); in rt9471_check_devinfo()
810 return dev_err_probe(dev, -ENODEV, "Incorrect device id\n"); in rt9471_check_devinfo()
837 struct device *dev = &i2c->dev; in rt9471_probe()
845 return -ENOMEM; in rt9471_probe()
847 chip->dev = dev; in rt9471_probe()
848 mutex_init(&chip->var_lock); in rt9471_probe()
852 ce_gpio = devm_gpiod_get_optional(dev, "charge-enable", GPIOD_OUT_HIGH); in rt9471_probe()
861 chip->regmap = regmap; in rt9471_probe()
863 ret = devm_regmap_field_bulk_alloc(dev, regmap, chip->rm_fields, in rt9471_probe()
878 ret = devm_regmap_add_irq_chip(dev, regmap, i2c->irq, in rt9471_probe()
880 &rt9471_irq_chip, &chip->irq_chip_data); in rt9471_probe()
897 return regmap_field_write(chip->rm_fields[F_BC12_EN], 1); in rt9471_probe()
908 regmap_field_write(chip->rm_fields[F_REG_RST], 1); in rt9471_shutdown()