Lines Matching full:power
3 * AXP20x PMIC USB power supply status driver
26 #define DRVNAME "axp20x-usb-power-supply"
79 static bool axp20x_usb_vbus_needs_polling(struct axp20x_usb_power *power) in axp20x_usb_vbus_needs_polling() argument
86 if (power->axp_data->vbus_needs_polling && !power->online) in axp20x_usb_vbus_needs_polling()
94 struct axp20x_usb_power *power = devid; in axp20x_usb_power_irq() local
96 power_supply_changed(power->supply); in axp20x_usb_power_irq()
98 mod_delayed_work(system_power_efficient_wq, &power->vbus_detect, DEBOUNCE_TIME); in axp20x_usb_power_irq()
105 struct axp20x_usb_power *power = in axp20x_usb_power_poll_vbus() local
110 ret = regmap_read(power->regmap, AXP20X_PWR_INPUT_STATUS, &val); in axp20x_usb_power_poll_vbus()
115 if (val != power->old_status) in axp20x_usb_power_poll_vbus()
116 power_supply_changed(power->supply); in axp20x_usb_power_poll_vbus()
118 power->old_status = val; in axp20x_usb_power_poll_vbus()
119 power->online = val & AXP20X_PWR_STATUS_VBUS_USED; in axp20x_usb_power_poll_vbus()
122 if (axp20x_usb_vbus_needs_polling(power)) in axp20x_usb_power_poll_vbus()
123 mod_delayed_work(system_power_efficient_wq, &power->vbus_detect, DEBOUNCE_TIME); in axp20x_usb_power_poll_vbus()
129 struct axp20x_usb_power *power = power_supply_get_drvdata(psy); in axp20x_usb_power_get_property() local
135 ret = regmap_read(power->regmap, AXP20X_VBUS_IPSOUT_MGMT, &v); in axp20x_usb_power_get_property()
143 ret = iio_read_channel_processed(power->vbus_v, in axp20x_usb_power_get_property()
149 * IIO framework gives mV but Power Supply framework in axp20x_usb_power_get_property()
156 ret = axp20x_read_variable_width(power->regmap, in axp20x_usb_power_get_property()
164 ret = regmap_field_read(power->curr_lim_fld, &v); in axp20x_usb_power_get_property()
168 val->intval = power->axp_data->curr_lim_table[v]; in axp20x_usb_power_get_property()
172 ret = iio_read_channel_processed(power->vbus_i, in axp20x_usb_power_get_property()
178 * IIO framework gives mA but Power Supply framework in axp20x_usb_power_get_property()
185 ret = axp20x_read_variable_width(power->regmap, in axp20x_usb_power_get_property()
197 ret = regmap_read(power->regmap, AXP20X_PWR_INPUT_STATUS, &input); in axp20x_usb_power_get_property()
210 if (power->vbus_valid_bit) { in axp20x_usb_power_get_property()
211 ret = regmap_field_read(power->vbus_valid_bit, &v); in axp20x_usb_power_get_property()
233 static int axp20x_usb_power_set_voltage_min(struct axp20x_usb_power *power, in axp20x_usb_power_set_voltage_min() argument
248 return regmap_update_bits(power->regmap, in axp20x_usb_power_set_voltage_min()
259 static int axp20x_usb_power_set_current_max(struct axp20x_usb_power *power, int intval) in axp20x_usb_power_set_current_max() argument
261 const unsigned int max = GENMASK(power->axp_data->curr_lim_fld.msb, in axp20x_usb_power_set_current_max()
262 power->axp_data->curr_lim_fld.lsb); in axp20x_usb_power_set_current_max()
268 if (power->axp_data->curr_lim_table[i] == intval) in axp20x_usb_power_set_current_max()
269 return regmap_field_write(power->curr_lim_fld, i); in axp20x_usb_power_set_current_max()
278 struct axp20x_usb_power *power = power_supply_get_drvdata(psy); in axp20x_usb_power_set_property() local
282 if (!power->vbus_disable_bit) in axp20x_usb_power_set_property()
285 return regmap_field_write(power->vbus_disable_bit, !val->intval); in axp20x_usb_power_set_property()
288 return axp20x_usb_power_set_voltage_min(power, val->intval); in axp20x_usb_power_set_property()
291 return axp20x_usb_power_set_current_max(power, val->intval); in axp20x_usb_power_set_property()
303 struct axp20x_usb_power *power = power_supply_get_drvdata(psy); in axp20x_usb_power_prop_writeable() local
313 return power->vbus_disable_bit != NULL; in axp20x_usb_power_prop_writeable()
449 struct axp20x_usb_power *power = dev_get_drvdata(dev); in axp20x_usb_power_suspend() local
458 if (device_may_wakeup(&power->supply->dev)) in axp20x_usb_power_suspend()
459 enable_irq_wake(power->irqs[i++]); in axp20x_usb_power_suspend()
460 while (i < power->num_irqs) in axp20x_usb_power_suspend()
461 disable_irq(power->irqs[i++]); in axp20x_usb_power_suspend()
468 struct axp20x_usb_power *power = dev_get_drvdata(dev); in axp20x_usb_power_resume() local
471 if (device_may_wakeup(&power->supply->dev)) in axp20x_usb_power_resume()
472 disable_irq_wake(power->irqs[i++]); in axp20x_usb_power_resume()
473 while (i < power->num_irqs) in axp20x_usb_power_resume()
474 enable_irq(power->irqs[i++]); in axp20x_usb_power_resume()
476 mod_delayed_work(system_power_efficient_wq, &power->vbus_detect, DEBOUNCE_TIME); in axp20x_usb_power_resume()
486 struct axp20x_usb_power *power) in configure_iio_channels() argument
488 power->vbus_v = devm_iio_channel_get(&pdev->dev, "vbus_v"); in configure_iio_channels()
489 if (IS_ERR(power->vbus_v)) { in configure_iio_channels()
490 if (PTR_ERR(power->vbus_v) == -ENODEV) in configure_iio_channels()
492 return PTR_ERR(power->vbus_v); in configure_iio_channels()
495 power->vbus_i = devm_iio_channel_get(&pdev->dev, "vbus_i"); in configure_iio_channels()
496 if (IS_ERR(power->vbus_i)) { in configure_iio_channels()
497 if (PTR_ERR(power->vbus_i) == -ENODEV) in configure_iio_channels()
499 return PTR_ERR(power->vbus_i); in configure_iio_channels()
505 static int configure_adc_registers(struct axp20x_usb_power *power) in configure_adc_registers() argument
508 return regmap_update_bits(power->regmap, AXP20X_ADC_EN1, in configure_adc_registers()
539 struct axp20x_usb_power *power; in axp20x_usb_power_probe() local
553 power = devm_kzalloc(&pdev->dev, in axp20x_usb_power_probe()
554 struct_size(power, irqs, axp_data->num_irq_names), in axp20x_usb_power_probe()
556 if (!power) in axp20x_usb_power_probe()
559 platform_set_drvdata(pdev, power); in axp20x_usb_power_probe()
561 power->axp_data = axp_data; in axp20x_usb_power_probe()
562 power->regmap = axp20x->regmap; in axp20x_usb_power_probe()
563 power->num_irqs = axp_data->num_irq_names; in axp20x_usb_power_probe()
565 power->curr_lim_fld = devm_regmap_field_alloc(&pdev->dev, power->regmap, in axp20x_usb_power_probe()
567 if (IS_ERR(power->curr_lim_fld)) in axp20x_usb_power_probe()
568 return PTR_ERR(power->curr_lim_fld); in axp20x_usb_power_probe()
570 ret = axp20x_regmap_field_alloc_optional(&pdev->dev, power->regmap, in axp20x_usb_power_probe()
572 &power->vbus_valid_bit); in axp20x_usb_power_probe()
576 ret = axp20x_regmap_field_alloc_optional(&pdev->dev, power->regmap, in axp20x_usb_power_probe()
578 &power->vbus_mon_bit); in axp20x_usb_power_probe()
582 ret = axp20x_regmap_field_alloc_optional(&pdev->dev, power->regmap, in axp20x_usb_power_probe()
584 &power->usb_bc_en_bit); in axp20x_usb_power_probe()
588 ret = axp20x_regmap_field_alloc_optional(&pdev->dev, power->regmap, in axp20x_usb_power_probe()
590 &power->vbus_disable_bit); in axp20x_usb_power_probe()
594 ret = devm_delayed_work_autocancel(&pdev->dev, &power->vbus_detect, in axp20x_usb_power_probe()
599 if (power->vbus_mon_bit) { in axp20x_usb_power_probe()
601 ret = regmap_field_write(power->vbus_mon_bit, 1); in axp20x_usb_power_probe()
606 ret = configure_iio_channels(pdev, power); in axp20x_usb_power_probe()
608 ret = configure_adc_registers(power); in axp20x_usb_power_probe()
614 if (power->usb_bc_en_bit) { in axp20x_usb_power_probe()
616 ret = regmap_field_write(power->usb_bc_en_bit, 1); in axp20x_usb_power_probe()
622 psy_cfg.drv_data = power; in axp20x_usb_power_probe()
624 power->supply = devm_power_supply_register(&pdev->dev, in axp20x_usb_power_probe()
627 if (IS_ERR(power->supply)) in axp20x_usb_power_probe()
628 return PTR_ERR(power->supply); in axp20x_usb_power_probe()
636 power->irqs[i] = regmap_irq_get_virq(axp20x->regmap_irqc, irq); in axp20x_usb_power_probe()
637 ret = devm_request_any_context_irq(&pdev->dev, power->irqs[i], in axp20x_usb_power_probe()
639 DRVNAME, power); in axp20x_usb_power_probe()
647 if (axp20x_usb_vbus_needs_polling(power)) in axp20x_usb_power_probe()
648 queue_delayed_work(system_power_efficient_wq, &power->vbus_detect, 0); in axp20x_usb_power_probe()
655 .compatible = "x-powers,axp192-usb-power-supply",
658 .compatible = "x-powers,axp202-usb-power-supply",
661 .compatible = "x-powers,axp221-usb-power-supply",
664 .compatible = "x-powers,axp223-usb-power-supply",
667 .compatible = "x-powers,axp813-usb-power-supply",
685 MODULE_DESCRIPTION("AXP20x PMIC USB power supply status driver");