Lines Matching full:power

3  * AXP20x PMIC USB power supply status driver
26 #define DRVNAME "axp20x-usb-power-supply"
76 struct axp20x_usb_power *power);
77 int (*axp20x_cfg_adc_reg)(struct axp20x_usb_power *power);
101 static bool axp20x_usb_vbus_needs_polling(struct axp20x_usb_power *power) in axp20x_usb_vbus_needs_polling() argument
108 if (power->axp_data->vbus_needs_polling && !power->online) in axp20x_usb_vbus_needs_polling()
116 struct axp20x_usb_power *power = devid; in axp20x_usb_power_irq() local
118 power_supply_changed(power->supply); in axp20x_usb_power_irq()
120 mod_delayed_work(system_power_efficient_wq, &power->vbus_detect, DEBOUNCE_TIME); in axp20x_usb_power_irq()
127 struct axp20x_usb_power *power = in axp20x_usb_power_poll_vbus() local
132 ret = regmap_read(power->regmap, AXP20X_PWR_INPUT_STATUS, &val); in axp20x_usb_power_poll_vbus()
137 if (val != power->old_status) in axp20x_usb_power_poll_vbus()
138 power_supply_changed(power->supply); in axp20x_usb_power_poll_vbus()
140 if (power->usb_bc_en_bit && (val & AXP20X_PWR_STATUS_VBUS_PRESENT) != in axp20x_usb_power_poll_vbus()
141 (power->old_status & AXP20X_PWR_STATUS_VBUS_PRESENT)) { in axp20x_usb_power_poll_vbus()
142 dev_dbg(power->dev, "Cable status changed, re-enabling USB BC"); in axp20x_usb_power_poll_vbus()
143 ret = regmap_field_write(power->usb_bc_en_bit, 1); in axp20x_usb_power_poll_vbus()
145 dev_err(power->dev, "failed to enable USB BC: errno %d", in axp20x_usb_power_poll_vbus()
149 power->old_status = val; in axp20x_usb_power_poll_vbus()
150 power->online = val & AXP20X_PWR_STATUS_VBUS_USED; in axp20x_usb_power_poll_vbus()
153 if (axp20x_usb_vbus_needs_polling(power)) in axp20x_usb_power_poll_vbus()
154 mod_delayed_work(system_power_efficient_wq, &power->vbus_detect, DEBOUNCE_TIME); in axp20x_usb_power_poll_vbus()
159 struct axp20x_usb_power *power = in axp717_usb_power_poll_vbus() local
164 ret = regmap_read(power->regmap, AXP717_ON_INDICATE, &val); in axp717_usb_power_poll_vbus()
169 if (val != power->old_status) in axp717_usb_power_poll_vbus()
170 power_supply_changed(power->supply); in axp717_usb_power_poll_vbus()
172 power->old_status = val; in axp717_usb_power_poll_vbus()
175 static int axp20x_get_usb_type(struct axp20x_usb_power *power, in axp20x_get_usb_type() argument
181 if (!power->usb_bc_det_fld) in axp20x_get_usb_type()
184 ret = regmap_field_read(power->usb_bc_det_fld, &reg); in axp20x_get_usb_type()
209 struct axp20x_usb_power *power = power_supply_get_drvdata(psy); in axp20x_usb_power_get_property() local
215 ret = regmap_read(power->regmap, AXP20X_VBUS_IPSOUT_MGMT, &v); in axp20x_usb_power_get_property()
224 * IIO framework gives mV but Power Supply framework in axp20x_usb_power_get_property()
227 ret = iio_read_channel_processed_scale(power->vbus_v, in axp20x_usb_power_get_property()
235 ret = axp20x_read_variable_width(power->regmap, in axp20x_usb_power_get_property()
243 ret = regmap_field_read(power->curr_lim_fld, &v); in axp20x_usb_power_get_property()
247 if (v < power->axp_data->curr_lim_table_size) in axp20x_usb_power_get_property()
248 val->intval = power->axp_data->curr_lim_table[v]; in axp20x_usb_power_get_property()
250 val->intval = power->axp_data->curr_lim_table[ in axp20x_usb_power_get_property()
251 power->axp_data->curr_lim_table_size - 1]; in axp20x_usb_power_get_property()
256 * IIO framework gives mA but Power Supply framework in axp20x_usb_power_get_property()
259 ret = iio_read_channel_processed_scale(power->vbus_i, in axp20x_usb_power_get_property()
267 ret = axp20x_read_variable_width(power->regmap, in axp20x_usb_power_get_property()
276 return axp20x_get_usb_type(power, val); in axp20x_usb_power_get_property()
282 ret = regmap_read(power->regmap, AXP20X_PWR_INPUT_STATUS, &input); in axp20x_usb_power_get_property()
295 if (power->vbus_valid_bit) { in axp20x_usb_power_get_property()
296 ret = regmap_field_read(power->vbus_valid_bit, &v); in axp20x_usb_power_get_property()
321 struct axp20x_usb_power *power = power_supply_get_drvdata(psy); in axp717_usb_power_get_property() local
328 ret = regmap_read(power->regmap, AXP717_ON_INDICATE, &v); in axp717_usb_power_get_property()
335 ret = regmap_read(power->regmap, AXP717_PMU_FAULT_VBUS, &v); in axp717_usb_power_get_property()
342 regmap_write(power->regmap, AXP717_PMU_FAULT_VBUS, v); in axp717_usb_power_get_property()
347 ret = regmap_read(power->regmap, AXP717_INPUT_CUR_LIMIT_CTRL, &v); in axp717_usb_power_get_property()
357 ret = regmap_read(power->regmap, AXP717_ON_INDICATE, &v); in axp717_usb_power_get_property()
363 return axp20x_get_usb_type(power, val); in axp717_usb_power_get_property()
365 ret = regmap_read(power->regmap, AXP717_INPUT_VOL_LIMIT_CTRL, &v); in axp717_usb_power_get_property()
376 * IIO framework gives mV but Power Supply framework in axp717_usb_power_get_property()
379 ret = iio_read_channel_processed_scale(power->vbus_v, in axp717_usb_power_get_property()
387 ret = axp20x_read_variable_width(power->regmap, in axp717_usb_power_get_property()
402 static int axp20x_usb_power_set_voltage_min(struct axp20x_usb_power *power, in axp20x_usb_power_set_voltage_min() argument
417 return regmap_update_bits(power->regmap, in axp20x_usb_power_set_voltage_min()
428 static int axp717_usb_power_set_voltage_min(struct axp20x_usb_power *power, in axp717_usb_power_set_voltage_min() argument
439 return regmap_update_bits(power->regmap, in axp717_usb_power_set_voltage_min()
444 static int axp20x_usb_power_set_input_current_limit(struct axp20x_usb_power *power, in axp20x_usb_power_set_input_current_limit() argument
449 const unsigned int max = power->axp_data->curr_lim_table_size; in axp20x_usb_power_set_input_current_limit()
454 if (power->max_input_cur && (intval > power->max_input_cur)) { in axp20x_usb_power_set_input_current_limit()
455 dev_warn(power->dev, in axp20x_usb_power_set_input_current_limit()
457 intval, power->max_input_cur); in axp20x_usb_power_set_input_current_limit()
458 intval = power->max_input_cur; in axp20x_usb_power_set_input_current_limit()
466 if (power->usb_bc_en_bit) { in axp20x_usb_power_set_input_current_limit()
467 dev_dbg(power->dev, in axp20x_usb_power_set_input_current_limit()
469 ret = regmap_field_write(power->usb_bc_en_bit, 0); in axp20x_usb_power_set_input_current_limit()
475 if (power->axp_data->curr_lim_table[reg] <= intval) in axp20x_usb_power_set_input_current_limit()
478 dev_dbg(power->dev, "setting input current limit reg to %d (%d uA), requested %d uA", in axp20x_usb_power_set_input_current_limit()
479 reg, power->axp_data->curr_lim_table[reg], intval); in axp20x_usb_power_set_input_current_limit()
481 return regmap_field_write(power->curr_lim_fld, reg); in axp20x_usb_power_set_input_current_limit()
484 static int axp717_usb_power_set_input_current_limit(struct axp20x_usb_power *power, in axp717_usb_power_set_input_current_limit() argument
493 if (power->max_input_cur && (intval > power->max_input_cur)) { in axp717_usb_power_set_input_current_limit()
494 dev_warn(power->dev, in axp717_usb_power_set_input_current_limit()
496 intval, power->max_input_cur); in axp717_usb_power_set_input_current_limit()
497 intval = power->max_input_cur; in axp717_usb_power_set_input_current_limit()
502 return regmap_update_bits(power->regmap, in axp717_usb_power_set_input_current_limit()
511 struct axp20x_usb_power *power = power_supply_get_drvdata(psy); in axp20x_usb_power_set_property() local
515 if (!power->vbus_disable_bit) in axp20x_usb_power_set_property()
518 return regmap_field_write(power->vbus_disable_bit, !val->intval); in axp20x_usb_power_set_property()
521 return axp20x_usb_power_set_voltage_min(power, val->intval); in axp20x_usb_power_set_property()
524 return axp20x_usb_power_set_input_current_limit(power, val->intval); in axp20x_usb_power_set_property()
535 struct axp20x_usb_power *power = power_supply_get_drvdata(psy); in axp717_usb_power_set_property() local
539 return axp717_usb_power_set_input_current_limit(power, val->intval); in axp717_usb_power_set_property()
542 return axp717_usb_power_set_voltage_min(power, val->intval); in axp717_usb_power_set_property()
554 struct axp20x_usb_power *power = power_supply_get_drvdata(psy); in axp20x_usb_power_prop_writeable() local
564 return power->vbus_disable_bit != NULL; in axp20x_usb_power_prop_writeable()
578 struct axp20x_usb_power *power) in axp20x_configure_iio_channels() argument
580 power->vbus_v = devm_iio_channel_get(&pdev->dev, "vbus_v"); in axp20x_configure_iio_channels()
581 if (IS_ERR(power->vbus_v)) { in axp20x_configure_iio_channels()
582 if (PTR_ERR(power->vbus_v) == -ENODEV) in axp20x_configure_iio_channels()
584 return PTR_ERR(power->vbus_v); in axp20x_configure_iio_channels()
587 power->vbus_i = devm_iio_channel_get(&pdev->dev, "vbus_i"); in axp20x_configure_iio_channels()
588 if (IS_ERR(power->vbus_i)) { in axp20x_configure_iio_channels()
589 if (PTR_ERR(power->vbus_i) == -ENODEV) in axp20x_configure_iio_channels()
591 return PTR_ERR(power->vbus_i); in axp20x_configure_iio_channels()
598 struct axp20x_usb_power *power) in axp717_configure_iio_channels() argument
600 power->vbus_v = devm_iio_channel_get(&pdev->dev, "vbus_v"); in axp717_configure_iio_channels()
601 if (IS_ERR(power->vbus_v)) { in axp717_configure_iio_channels()
602 if (PTR_ERR(power->vbus_v) == -ENODEV) in axp717_configure_iio_channels()
604 return PTR_ERR(power->vbus_v); in axp717_configure_iio_channels()
610 static int axp20x_configure_adc_registers(struct axp20x_usb_power *power) in axp20x_configure_adc_registers() argument
613 return regmap_update_bits(power->regmap, AXP20X_ADC_EN1, in axp20x_configure_adc_registers()
620 static int axp717_configure_adc_registers(struct axp20x_usb_power *power) in axp717_configure_adc_registers() argument
623 return regmap_update_bits(power->regmap, AXP717_ADC_CH_EN_CONTROL, in axp717_configure_adc_registers()
851 struct axp20x_usb_power *power = dev_get_drvdata(dev); in axp20x_usb_power_suspend() local
860 if (device_may_wakeup(&power->supply->dev)) in axp20x_usb_power_suspend()
861 enable_irq_wake(power->irqs[i++]); in axp20x_usb_power_suspend()
862 while (i < power->num_irqs) in axp20x_usb_power_suspend()
863 disable_irq(power->irqs[i++]); in axp20x_usb_power_suspend()
870 struct axp20x_usb_power *power = dev_get_drvdata(dev); in axp20x_usb_power_resume() local
873 if (device_may_wakeup(&power->supply->dev)) in axp20x_usb_power_resume()
874 disable_irq_wake(power->irqs[i++]); in axp20x_usb_power_resume()
875 while (i < power->num_irqs) in axp20x_usb_power_resume()
876 enable_irq(power->irqs[i++]); in axp20x_usb_power_resume()
878 mod_delayed_work(system_power_efficient_wq, &power->vbus_detect, DEBOUNCE_TIME); in axp20x_usb_power_resume()
909 struct axp20x_usb_power *power) in axp20x_usb_power_parse_dt() argument
914 &power->max_input_cur); in axp20x_usb_power_parse_dt()
923 struct axp20x_usb_power *power; in axp20x_usb_power_probe() local
937 power = devm_kzalloc(&pdev->dev, in axp20x_usb_power_probe()
938 struct_size(power, irqs, axp_data->num_irq_names), in axp20x_usb_power_probe()
940 if (!power) in axp20x_usb_power_probe()
943 platform_set_drvdata(pdev, power); in axp20x_usb_power_probe()
945 power->dev = &pdev->dev; in axp20x_usb_power_probe()
946 power->axp_data = axp_data; in axp20x_usb_power_probe()
947 power->regmap = axp20x->regmap; in axp20x_usb_power_probe()
948 power->num_irqs = axp_data->num_irq_names; in axp20x_usb_power_probe()
950 power->curr_lim_fld = devm_regmap_field_alloc(&pdev->dev, power->regmap, in axp20x_usb_power_probe()
952 if (IS_ERR(power->curr_lim_fld)) in axp20x_usb_power_probe()
953 return PTR_ERR(power->curr_lim_fld); in axp20x_usb_power_probe()
955 axp20x_usb_power_parse_dt(&pdev->dev, power); in axp20x_usb_power_probe()
957 ret = axp20x_regmap_field_alloc_optional(&pdev->dev, power->regmap, in axp20x_usb_power_probe()
959 &power->vbus_valid_bit); in axp20x_usb_power_probe()
963 ret = axp20x_regmap_field_alloc_optional(&pdev->dev, power->regmap, in axp20x_usb_power_probe()
965 &power->vbus_mon_bit); in axp20x_usb_power_probe()
969 ret = axp20x_regmap_field_alloc_optional(&pdev->dev, power->regmap, in axp20x_usb_power_probe()
971 &power->usb_bc_en_bit); in axp20x_usb_power_probe()
975 ret = axp20x_regmap_field_alloc_optional(&pdev->dev, power->regmap, in axp20x_usb_power_probe()
977 &power->usb_bc_det_fld); in axp20x_usb_power_probe()
981 ret = axp20x_regmap_field_alloc_optional(&pdev->dev, power->regmap, in axp20x_usb_power_probe()
983 &power->vbus_disable_bit); in axp20x_usb_power_probe()
987 ret = devm_delayed_work_autocancel(&pdev->dev, &power->vbus_detect, in axp20x_usb_power_probe()
992 if (power->vbus_mon_bit) { in axp20x_usb_power_probe()
994 ret = regmap_field_write(power->vbus_mon_bit, 1); in axp20x_usb_power_probe()
999 ret = axp_data->axp20x_cfg_iio_chan(pdev, power); in axp20x_usb_power_probe()
1001 ret = axp_data->axp20x_cfg_adc_reg(power); in axp20x_usb_power_probe()
1007 if (power->usb_bc_en_bit) { in axp20x_usb_power_probe()
1009 ret = regmap_field_write(power->usb_bc_en_bit, 1); in axp20x_usb_power_probe()
1015 psy_cfg.drv_data = power; in axp20x_usb_power_probe()
1017 power->supply = devm_power_supply_register(&pdev->dev, in axp20x_usb_power_probe()
1020 if (IS_ERR(power->supply)) in axp20x_usb_power_probe()
1021 return PTR_ERR(power->supply); in axp20x_usb_power_probe()
1029 power->irqs[i] = regmap_irq_get_virq(axp20x->regmap_irqc, irq); in axp20x_usb_power_probe()
1030 ret = devm_request_any_context_irq(&pdev->dev, power->irqs[i], in axp20x_usb_power_probe()
1032 DRVNAME, power); in axp20x_usb_power_probe()
1040 if (axp20x_usb_vbus_needs_polling(power)) in axp20x_usb_power_probe()
1041 queue_delayed_work(system_power_efficient_wq, &power->vbus_detect, 0); in axp20x_usb_power_probe()
1048 .compatible = "x-powers,axp192-usb-power-supply",
1051 .compatible = "x-powers,axp202-usb-power-supply",
1054 .compatible = "x-powers,axp221-usb-power-supply",
1057 .compatible = "x-powers,axp223-usb-power-supply",
1060 .compatible = "x-powers,axp717-usb-power-supply",
1063 .compatible = "x-powers,axp813-usb-power-supply",
1081 MODULE_DESCRIPTION("AXP20x PMIC USB power supply status driver");