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()
223 ret = iio_read_channel_processed(power->vbus_v, in axp20x_usb_power_get_property()
229 * IIO framework gives mV but Power Supply framework in axp20x_usb_power_get_property()
236 ret = axp20x_read_variable_width(power->regmap, in axp20x_usb_power_get_property()
244 ret = regmap_field_read(power->curr_lim_fld, &v); in axp20x_usb_power_get_property()
248 if (v < power->axp_data->curr_lim_table_size) in axp20x_usb_power_get_property()
249 val->intval = power->axp_data->curr_lim_table[v]; in axp20x_usb_power_get_property()
251 val->intval = power->axp_data->curr_lim_table[ in axp20x_usb_power_get_property()
252 power->axp_data->curr_lim_table_size - 1]; in axp20x_usb_power_get_property()
256 ret = iio_read_channel_processed(power->vbus_i, in axp20x_usb_power_get_property()
262 * IIO framework gives mA but Power Supply framework in axp20x_usb_power_get_property()
269 ret = axp20x_read_variable_width(power->regmap, in axp20x_usb_power_get_property()
278 return axp20x_get_usb_type(power, val); in axp20x_usb_power_get_property()
284 ret = regmap_read(power->regmap, AXP20X_PWR_INPUT_STATUS, &input); in axp20x_usb_power_get_property()
297 if (power->vbus_valid_bit) { in axp20x_usb_power_get_property()
298 ret = regmap_field_read(power->vbus_valid_bit, &v); in axp20x_usb_power_get_property()
323 struct axp20x_usb_power *power = power_supply_get_drvdata(psy); in axp717_usb_power_get_property() local
330 ret = regmap_read(power->regmap, AXP717_ON_INDICATE, &v); in axp717_usb_power_get_property()
337 ret = regmap_read(power->regmap, AXP717_PMU_FAULT_VBUS, &v); in axp717_usb_power_get_property()
344 regmap_write(power->regmap, AXP717_PMU_FAULT_VBUS, v); in axp717_usb_power_get_property()
349 ret = regmap_read(power->regmap, AXP717_INPUT_CUR_LIMIT_CTRL, &v); in axp717_usb_power_get_property()
359 ret = regmap_read(power->regmap, AXP717_ON_INDICATE, &v); in axp717_usb_power_get_property()
365 return axp20x_get_usb_type(power, val); in axp717_usb_power_get_property()
367 ret = regmap_read(power->regmap, AXP717_INPUT_VOL_LIMIT_CTRL, &v); in axp717_usb_power_get_property()
377 ret = iio_read_channel_processed(power->vbus_v, in axp717_usb_power_get_property()
383 * IIO framework gives mV but Power Supply framework in axp717_usb_power_get_property()
390 ret = axp20x_read_variable_width(power->regmap, in axp717_usb_power_get_property()
405 static int axp20x_usb_power_set_voltage_min(struct axp20x_usb_power *power, in axp20x_usb_power_set_voltage_min() argument
420 return regmap_update_bits(power->regmap, in axp20x_usb_power_set_voltage_min()
431 static int axp717_usb_power_set_voltage_min(struct axp20x_usb_power *power, in axp717_usb_power_set_voltage_min() argument
442 return regmap_update_bits(power->regmap, in axp717_usb_power_set_voltage_min()
447 static int axp20x_usb_power_set_input_current_limit(struct axp20x_usb_power *power, in axp20x_usb_power_set_input_current_limit() argument
452 const unsigned int max = power->axp_data->curr_lim_table_size; in axp20x_usb_power_set_input_current_limit()
457 if (power->max_input_cur && (intval > power->max_input_cur)) { in axp20x_usb_power_set_input_current_limit()
458 dev_warn(power->dev, in axp20x_usb_power_set_input_current_limit()
460 intval, power->max_input_cur); in axp20x_usb_power_set_input_current_limit()
461 intval = power->max_input_cur; in axp20x_usb_power_set_input_current_limit()
469 if (power->usb_bc_en_bit) { in axp20x_usb_power_set_input_current_limit()
470 dev_dbg(power->dev, in axp20x_usb_power_set_input_current_limit()
472 ret = regmap_field_write(power->usb_bc_en_bit, 0); in axp20x_usb_power_set_input_current_limit()
478 if (power->axp_data->curr_lim_table[reg] <= intval) in axp20x_usb_power_set_input_current_limit()
481 dev_dbg(power->dev, "setting input current limit reg to %d (%d uA), requested %d uA", in axp20x_usb_power_set_input_current_limit()
482 reg, power->axp_data->curr_lim_table[reg], intval); in axp20x_usb_power_set_input_current_limit()
484 return regmap_field_write(power->curr_lim_fld, reg); in axp20x_usb_power_set_input_current_limit()
487 static int axp717_usb_power_set_input_current_limit(struct axp20x_usb_power *power, in axp717_usb_power_set_input_current_limit() argument
496 if (power->max_input_cur && (intval > power->max_input_cur)) { in axp717_usb_power_set_input_current_limit()
497 dev_warn(power->dev, in axp717_usb_power_set_input_current_limit()
499 intval, power->max_input_cur); in axp717_usb_power_set_input_current_limit()
500 intval = power->max_input_cur; in axp717_usb_power_set_input_current_limit()
505 return regmap_update_bits(power->regmap, in axp717_usb_power_set_input_current_limit()
514 struct axp20x_usb_power *power = power_supply_get_drvdata(psy); in axp20x_usb_power_set_property() local
518 if (!power->vbus_disable_bit) in axp20x_usb_power_set_property()
521 return regmap_field_write(power->vbus_disable_bit, !val->intval); in axp20x_usb_power_set_property()
524 return axp20x_usb_power_set_voltage_min(power, val->intval); in axp20x_usb_power_set_property()
527 return axp20x_usb_power_set_input_current_limit(power, val->intval); in axp20x_usb_power_set_property()
538 struct axp20x_usb_power *power = power_supply_get_drvdata(psy); in axp717_usb_power_set_property() local
542 return axp717_usb_power_set_input_current_limit(power, val->intval); in axp717_usb_power_set_property()
545 return axp717_usb_power_set_voltage_min(power, val->intval); in axp717_usb_power_set_property()
557 struct axp20x_usb_power *power = power_supply_get_drvdata(psy); in axp20x_usb_power_prop_writeable() local
567 return power->vbus_disable_bit != NULL; in axp20x_usb_power_prop_writeable()
581 struct axp20x_usb_power *power) in axp20x_configure_iio_channels() argument
583 power->vbus_v = devm_iio_channel_get(&pdev->dev, "vbus_v"); in axp20x_configure_iio_channels()
584 if (IS_ERR(power->vbus_v)) { in axp20x_configure_iio_channels()
585 if (PTR_ERR(power->vbus_v) == -ENODEV) in axp20x_configure_iio_channels()
587 return PTR_ERR(power->vbus_v); in axp20x_configure_iio_channels()
590 power->vbus_i = devm_iio_channel_get(&pdev->dev, "vbus_i"); in axp20x_configure_iio_channels()
591 if (IS_ERR(power->vbus_i)) { in axp20x_configure_iio_channels()
592 if (PTR_ERR(power->vbus_i) == -ENODEV) in axp20x_configure_iio_channels()
594 return PTR_ERR(power->vbus_i); in axp20x_configure_iio_channels()
601 struct axp20x_usb_power *power) in axp717_configure_iio_channels() argument
603 power->vbus_v = devm_iio_channel_get(&pdev->dev, "vbus_v"); in axp717_configure_iio_channels()
604 if (IS_ERR(power->vbus_v)) { in axp717_configure_iio_channels()
605 if (PTR_ERR(power->vbus_v) == -ENODEV) in axp717_configure_iio_channels()
607 return PTR_ERR(power->vbus_v); in axp717_configure_iio_channels()
613 static int axp20x_configure_adc_registers(struct axp20x_usb_power *power) in axp20x_configure_adc_registers() argument
616 return regmap_update_bits(power->regmap, AXP20X_ADC_EN1, in axp20x_configure_adc_registers()
623 static int axp717_configure_adc_registers(struct axp20x_usb_power *power) in axp717_configure_adc_registers() argument
626 return regmap_update_bits(power->regmap, AXP717_ADC_CH_EN_CONTROL, in axp717_configure_adc_registers()
854 struct axp20x_usb_power *power = dev_get_drvdata(dev); in axp20x_usb_power_suspend() local
863 if (device_may_wakeup(&power->supply->dev)) in axp20x_usb_power_suspend()
864 enable_irq_wake(power->irqs[i++]); in axp20x_usb_power_suspend()
865 while (i < power->num_irqs) in axp20x_usb_power_suspend()
866 disable_irq(power->irqs[i++]); in axp20x_usb_power_suspend()
873 struct axp20x_usb_power *power = dev_get_drvdata(dev); in axp20x_usb_power_resume() local
876 if (device_may_wakeup(&power->supply->dev)) in axp20x_usb_power_resume()
877 disable_irq_wake(power->irqs[i++]); in axp20x_usb_power_resume()
878 while (i < power->num_irqs) in axp20x_usb_power_resume()
879 enable_irq(power->irqs[i++]); in axp20x_usb_power_resume()
881 mod_delayed_work(system_power_efficient_wq, &power->vbus_detect, DEBOUNCE_TIME); in axp20x_usb_power_resume()
912 struct axp20x_usb_power *power) in axp20x_usb_power_parse_dt() argument
917 &power->max_input_cur); in axp20x_usb_power_parse_dt()
926 struct axp20x_usb_power *power; in axp20x_usb_power_probe() local
940 power = devm_kzalloc(&pdev->dev, in axp20x_usb_power_probe()
941 struct_size(power, irqs, axp_data->num_irq_names), in axp20x_usb_power_probe()
943 if (!power) in axp20x_usb_power_probe()
946 platform_set_drvdata(pdev, power); in axp20x_usb_power_probe()
948 power->dev = &pdev->dev; in axp20x_usb_power_probe()
949 power->axp_data = axp_data; in axp20x_usb_power_probe()
950 power->regmap = axp20x->regmap; in axp20x_usb_power_probe()
951 power->num_irqs = axp_data->num_irq_names; in axp20x_usb_power_probe()
953 power->curr_lim_fld = devm_regmap_field_alloc(&pdev->dev, power->regmap, in axp20x_usb_power_probe()
955 if (IS_ERR(power->curr_lim_fld)) in axp20x_usb_power_probe()
956 return PTR_ERR(power->curr_lim_fld); in axp20x_usb_power_probe()
958 axp20x_usb_power_parse_dt(&pdev->dev, power); in axp20x_usb_power_probe()
960 ret = axp20x_regmap_field_alloc_optional(&pdev->dev, power->regmap, in axp20x_usb_power_probe()
962 &power->vbus_valid_bit); in axp20x_usb_power_probe()
966 ret = axp20x_regmap_field_alloc_optional(&pdev->dev, power->regmap, in axp20x_usb_power_probe()
968 &power->vbus_mon_bit); in axp20x_usb_power_probe()
972 ret = axp20x_regmap_field_alloc_optional(&pdev->dev, power->regmap, in axp20x_usb_power_probe()
974 &power->usb_bc_en_bit); in axp20x_usb_power_probe()
978 ret = axp20x_regmap_field_alloc_optional(&pdev->dev, power->regmap, in axp20x_usb_power_probe()
980 &power->usb_bc_det_fld); in axp20x_usb_power_probe()
984 ret = axp20x_regmap_field_alloc_optional(&pdev->dev, power->regmap, in axp20x_usb_power_probe()
986 &power->vbus_disable_bit); in axp20x_usb_power_probe()
990 ret = devm_delayed_work_autocancel(&pdev->dev, &power->vbus_detect, in axp20x_usb_power_probe()
995 if (power->vbus_mon_bit) { in axp20x_usb_power_probe()
997 ret = regmap_field_write(power->vbus_mon_bit, 1); in axp20x_usb_power_probe()
1002 ret = axp_data->axp20x_cfg_iio_chan(pdev, power); in axp20x_usb_power_probe()
1004 ret = axp_data->axp20x_cfg_adc_reg(power); in axp20x_usb_power_probe()
1010 if (power->usb_bc_en_bit) { in axp20x_usb_power_probe()
1012 ret = regmap_field_write(power->usb_bc_en_bit, 1); in axp20x_usb_power_probe()
1018 psy_cfg.drv_data = power; in axp20x_usb_power_probe()
1020 power->supply = devm_power_supply_register(&pdev->dev, in axp20x_usb_power_probe()
1023 if (IS_ERR(power->supply)) in axp20x_usb_power_probe()
1024 return PTR_ERR(power->supply); in axp20x_usb_power_probe()
1032 power->irqs[i] = regmap_irq_get_virq(axp20x->regmap_irqc, irq); in axp20x_usb_power_probe()
1033 ret = devm_request_any_context_irq(&pdev->dev, power->irqs[i], in axp20x_usb_power_probe()
1035 DRVNAME, power); in axp20x_usb_power_probe()
1043 if (axp20x_usb_vbus_needs_polling(power)) in axp20x_usb_power_probe()
1044 queue_delayed_work(system_power_efficient_wq, &power->vbus_detect, 0); in axp20x_usb_power_probe()
1051 .compatible = "x-powers,axp192-usb-power-supply",
1054 .compatible = "x-powers,axp202-usb-power-supply",
1057 .compatible = "x-powers,axp221-usb-power-supply",
1060 .compatible = "x-powers,axp223-usb-power-supply",
1063 .compatible = "x-powers,axp717-usb-power-supply",
1066 .compatible = "x-powers,axp813-usb-power-supply",
1084 MODULE_DESCRIPTION("AXP20x PMIC USB power supply status driver");