Lines Matching full:power

3  * AXP20x PMIC USB power supply status driver
26 #define DRVNAME "axp20x-usb-power-supply"
76 static bool axp20x_usb_vbus_needs_polling(struct axp20x_usb_power *power) in axp20x_usb_vbus_needs_polling() argument
83 if (power->axp20x_id >= AXP221_ID && !power->online) in axp20x_usb_vbus_needs_polling()
91 struct axp20x_usb_power *power = devid; in axp20x_usb_power_irq() local
93 power_supply_changed(power->supply); in axp20x_usb_power_irq()
95 mod_delayed_work(system_wq, &power->vbus_detect, DEBOUNCE_TIME); in axp20x_usb_power_irq()
102 struct axp20x_usb_power *power = in axp20x_usb_power_poll_vbus() local
107 ret = regmap_read(power->regmap, AXP20X_PWR_INPUT_STATUS, &val); in axp20x_usb_power_poll_vbus()
112 if (val != power->old_status) in axp20x_usb_power_poll_vbus()
113 power_supply_changed(power->supply); in axp20x_usb_power_poll_vbus()
115 power->old_status = val; in axp20x_usb_power_poll_vbus()
116 power->online = val & AXP20X_PWR_STATUS_VBUS_USED; in axp20x_usb_power_poll_vbus()
119 if (axp20x_usb_vbus_needs_polling(power)) in axp20x_usb_power_poll_vbus()
120 mod_delayed_work(system_wq, &power->vbus_detect, DEBOUNCE_TIME); in axp20x_usb_power_poll_vbus()
123 static int axp20x_get_current_max(struct axp20x_usb_power *power, int *val) in axp20x_get_current_max() argument
126 int ret = regmap_read(power->regmap, AXP20X_VBUS_IPSOUT_MGMT, &v); in axp20x_get_current_max()
133 if (power->axp20x_id == AXP221_ID) in axp20x_get_current_max()
152 static int axp813_get_current_max(struct axp20x_usb_power *power, int *val) in axp813_get_current_max() argument
155 int ret = regmap_read(power->regmap, AXP20X_VBUS_IPSOUT_MGMT, &v); in axp813_get_current_max()
180 struct axp20x_usb_power *power = power_supply_get_drvdata(psy); in axp20x_usb_power_get_property() local
186 ret = regmap_read(power->regmap, AXP20X_VBUS_IPSOUT_MGMT, &v); in axp20x_usb_power_get_property()
194 ret = iio_read_channel_processed(power->vbus_v, in axp20x_usb_power_get_property()
200 * IIO framework gives mV but Power Supply framework in axp20x_usb_power_get_property()
207 ret = axp20x_read_variable_width(power->regmap, in axp20x_usb_power_get_property()
215 if (power->axp20x_id == AXP813_ID) in axp20x_usb_power_get_property()
216 return axp813_get_current_max(power, &val->intval); in axp20x_usb_power_get_property()
217 return axp20x_get_current_max(power, &val->intval); in axp20x_usb_power_get_property()
220 ret = iio_read_channel_processed(power->vbus_i, in axp20x_usb_power_get_property()
226 * IIO framework gives mA but Power Supply framework in axp20x_usb_power_get_property()
233 ret = axp20x_read_variable_width(power->regmap, in axp20x_usb_power_get_property()
245 ret = regmap_read(power->regmap, AXP20X_PWR_INPUT_STATUS, &input); in axp20x_usb_power_get_property()
258 if (power->axp20x_id == AXP202_ID) { in axp20x_usb_power_get_property()
259 ret = regmap_read(power->regmap, in axp20x_usb_power_get_property()
282 static int axp813_usb_power_set_online(struct axp20x_usb_power *power, in axp813_usb_power_set_online() argument
287 return regmap_update_bits(power->regmap, in axp813_usb_power_set_online()
292 static int axp20x_usb_power_set_voltage_min(struct axp20x_usb_power *power, in axp20x_usb_power_set_voltage_min() argument
307 return regmap_update_bits(power->regmap, in axp20x_usb_power_set_voltage_min()
318 static int axp813_usb_power_set_current_max(struct axp20x_usb_power *power, in axp813_usb_power_set_current_max() argument
325 return regmap_update_bits(power->regmap, in axp813_usb_power_set_current_max()
333 return regmap_update_bits(power->regmap, in axp813_usb_power_set_current_max()
343 static int axp20x_usb_power_set_current_max(struct axp20x_usb_power *power, in axp20x_usb_power_set_current_max() argument
350 if (power->axp20x_id == AXP221_ID) in axp20x_usb_power_set_current_max()
356 return regmap_update_bits(power->regmap, in axp20x_usb_power_set_current_max()
370 struct axp20x_usb_power *power = power_supply_get_drvdata(psy); in axp20x_usb_power_set_property() local
374 if (power->axp20x_id != AXP813_ID) in axp20x_usb_power_set_property()
376 return axp813_usb_power_set_online(power, val->intval); in axp20x_usb_power_set_property()
379 return axp20x_usb_power_set_voltage_min(power, val->intval); in axp20x_usb_power_set_property()
382 if (power->axp20x_id == AXP813_ID) in axp20x_usb_power_set_property()
383 return axp813_usb_power_set_current_max(power, in axp20x_usb_power_set_property()
385 return axp20x_usb_power_set_current_max(power, val->intval); in axp20x_usb_power_set_property()
397 struct axp20x_usb_power *power = power_supply_get_drvdata(psy); in axp20x_usb_power_prop_writeable() local
407 return power->axp20x_id == AXP813_ID; in axp20x_usb_power_prop_writeable()
501 struct axp20x_usb_power *power = dev_get_drvdata(dev); in axp20x_usb_power_suspend() local
510 if (device_may_wakeup(&power->supply->dev)) in axp20x_usb_power_suspend()
511 enable_irq_wake(power->irqs[i++]); in axp20x_usb_power_suspend()
512 while (i < power->num_irqs) in axp20x_usb_power_suspend()
513 disable_irq(power->irqs[i++]); in axp20x_usb_power_suspend()
520 struct axp20x_usb_power *power = dev_get_drvdata(dev); in axp20x_usb_power_resume() local
523 if (device_may_wakeup(&power->supply->dev)) in axp20x_usb_power_resume()
524 disable_irq_wake(power->irqs[i++]); in axp20x_usb_power_resume()
525 while (i < power->num_irqs) in axp20x_usb_power_resume()
526 enable_irq(power->irqs[i++]); in axp20x_usb_power_resume()
528 mod_delayed_work(system_wq, &power->vbus_detect, DEBOUNCE_TIME); in axp20x_usb_power_resume()
538 struct axp20x_usb_power *power) in configure_iio_channels() argument
540 power->vbus_v = devm_iio_channel_get(&pdev->dev, "vbus_v"); in configure_iio_channels()
541 if (IS_ERR(power->vbus_v)) { in configure_iio_channels()
542 if (PTR_ERR(power->vbus_v) == -ENODEV) in configure_iio_channels()
544 return PTR_ERR(power->vbus_v); in configure_iio_channels()
547 power->vbus_i = devm_iio_channel_get(&pdev->dev, "vbus_i"); in configure_iio_channels()
548 if (IS_ERR(power->vbus_i)) { in configure_iio_channels()
549 if (PTR_ERR(power->vbus_i) == -ENODEV) in configure_iio_channels()
551 return PTR_ERR(power->vbus_i); in configure_iio_channels()
557 static int configure_adc_registers(struct axp20x_usb_power *power) in configure_adc_registers() argument
560 return regmap_update_bits(power->regmap, AXP20X_ADC_EN1, in configure_adc_registers()
571 struct axp20x_usb_power *power; in axp20x_usb_power_probe() local
585 power = devm_kzalloc(&pdev->dev, in axp20x_usb_power_probe()
586 struct_size(power, irqs, axp_data->num_irq_names), in axp20x_usb_power_probe()
588 if (!power) in axp20x_usb_power_probe()
591 platform_set_drvdata(pdev, power); in axp20x_usb_power_probe()
593 power->axp20x_id = axp_data->axp20x_id; in axp20x_usb_power_probe()
594 power->regmap = axp20x->regmap; in axp20x_usb_power_probe()
595 power->num_irqs = axp_data->num_irq_names; in axp20x_usb_power_probe()
597 if (power->axp20x_id == AXP202_ID) { in axp20x_usb_power_probe()
599 ret = regmap_update_bits(power->regmap, AXP20X_VBUS_MON, 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->axp20x_id == AXP813_ID) { in axp20x_usb_power_probe()
621 psy_cfg.drv_data = power; in axp20x_usb_power_probe()
623 power->supply = devm_power_supply_register(&pdev->dev, in axp20x_usb_power_probe()
626 if (IS_ERR(power->supply)) in axp20x_usb_power_probe()
627 return PTR_ERR(power->supply); in axp20x_usb_power_probe()
637 power->irqs[i] = regmap_irq_get_virq(axp20x->regmap_irqc, irq); in axp20x_usb_power_probe()
638 ret = devm_request_any_context_irq(&pdev->dev, power->irqs[i], in axp20x_usb_power_probe()
640 DRVNAME, power); in axp20x_usb_power_probe()
648 INIT_DELAYED_WORK(&power->vbus_detect, axp20x_usb_power_poll_vbus); in axp20x_usb_power_probe()
649 if (axp20x_usb_vbus_needs_polling(power)) in axp20x_usb_power_probe()
650 queue_delayed_work(system_wq, &power->vbus_detect, 0); in axp20x_usb_power_probe()
657 struct axp20x_usb_power *power = platform_get_drvdata(pdev); in axp20x_usb_power_remove() local
659 cancel_delayed_work_sync(&power->vbus_detect); in axp20x_usb_power_remove()
666 .compatible = "x-powers,axp202-usb-power-supply",
669 .compatible = "x-powers,axp221-usb-power-supply",
672 .compatible = "x-powers,axp223-usb-power-supply",
675 .compatible = "x-powers,axp813-usb-power-supply",
694 MODULE_DESCRIPTION("AXP20x PMIC USB power supply status driver");