Lines Matching +full:power +full:-

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * AXP20X and AXP22X PMICs' ACIN power supply driver
6 * Quentin Schulz <quentin.schulz@free-electrons.com>
30 #define AXP813_VHOLD_UV_TO_BIT(x) ((((x) / 100000) - 40) << 3)
35 #define AXP813_CURR_LIMIT_UA_TO_BIT(x) (((x) / 500000) - 3)
39 #define DRVNAME "axp20x-ac-power-supply"
53 struct axp20x_ac_power *power = devid; in axp20x_ac_power_irq() local
55 power_supply_changed(power->supply); in axp20x_ac_power_irq()
64 struct axp20x_ac_power *power = power_supply_get_drvdata(psy); in axp20x_ac_power_get_property() local
69 ret = regmap_read(power->regmap, AXP20X_PWR_INPUT_STATUS, &reg); in axp20x_ac_power_get_property()
74 val->intval = POWER_SUPPLY_HEALTH_GOOD; in axp20x_ac_power_get_property()
78 val->intval = POWER_SUPPLY_HEALTH_UNKNOWN; in axp20x_ac_power_get_property()
82 ret = regmap_read(power->regmap, AXP20X_PWR_INPUT_STATUS, &reg); in axp20x_ac_power_get_property()
86 val->intval = !!(reg & AXP20X_PWR_STATUS_ACIN_PRESENT); in axp20x_ac_power_get_property()
90 ret = regmap_read(power->regmap, AXP20X_PWR_INPUT_STATUS, &reg); in axp20x_ac_power_get_property()
94 val->intval = !!(reg & AXP20X_PWR_STATUS_ACIN_AVAIL); in axp20x_ac_power_get_property()
97 if (val->intval && power->has_acin_path_sel) { in axp20x_ac_power_get_property()
98 ret = regmap_read(power->regmap, AXP813_ACIN_PATH_CTRL, in axp20x_ac_power_get_property()
103 val->intval = !!(reg & AXP813_ACIN_PATH_SEL); in axp20x_ac_power_get_property()
109 ret = iio_read_channel_processed(power->acin_v, &val->intval); in axp20x_ac_power_get_property()
113 /* IIO framework gives mV but Power Supply framework gives uV */ in axp20x_ac_power_get_property()
114 val->intval *= 1000; in axp20x_ac_power_get_property()
119 ret = iio_read_channel_processed(power->acin_i, &val->intval); in axp20x_ac_power_get_property()
123 /* IIO framework gives mA but Power Supply framework gives uA */ in axp20x_ac_power_get_property()
124 val->intval *= 1000; in axp20x_ac_power_get_property()
129 ret = regmap_read(power->regmap, AXP813_ACIN_PATH_CTRL, &reg); in axp20x_ac_power_get_property()
133 val->intval = AXP813_VHOLD_REG_TO_UV(reg); in axp20x_ac_power_get_property()
138 ret = regmap_read(power->regmap, AXP813_ACIN_PATH_CTRL, &reg); in axp20x_ac_power_get_property()
142 val->intval = AXP813_CURR_LIMIT_REG_TO_UA(reg); in axp20x_ac_power_get_property()
144 if (val->intval > 4000000) in axp20x_ac_power_get_property()
145 val->intval = 4000000; in axp20x_ac_power_get_property()
150 return -EINVAL; in axp20x_ac_power_get_property()
153 return -EINVAL; in axp20x_ac_power_get_property()
160 struct axp20x_ac_power *power = power_supply_get_drvdata(psy); in axp813_ac_power_set_property() local
164 return regmap_update_bits(power->regmap, AXP813_ACIN_PATH_CTRL, in axp813_ac_power_set_property()
166 AXP813_ACIN_PATH_SEL_TO_BIT(val->intval)); in axp813_ac_power_set_property()
169 if (val->intval < 4000000 || val->intval > 4700000) in axp813_ac_power_set_property()
170 return -EINVAL; in axp813_ac_power_set_property()
172 return regmap_update_bits(power->regmap, AXP813_ACIN_PATH_CTRL, in axp813_ac_power_set_property()
174 AXP813_VHOLD_UV_TO_BIT(val->intval)); in axp813_ac_power_set_property()
177 if (val->intval < 1500000 || val->intval > 4000000) in axp813_ac_power_set_property()
178 return -EINVAL; in axp813_ac_power_set_property()
180 return regmap_update_bits(power->regmap, AXP813_ACIN_PATH_CTRL, in axp813_ac_power_set_property()
182 AXP813_CURR_LIMIT_UA_TO_BIT(val->intval)); in axp813_ac_power_set_property()
185 return -EINVAL; in axp813_ac_power_set_property()
188 return -EINVAL; in axp813_ac_power_set_property()
222 .name = "axp20x-ac",
230 .name = "axp22x-ac",
238 .name = "axp813-ac",
287 struct axp20x_ac_power *power = dev_get_drvdata(dev); in axp20x_ac_power_suspend() local
296 if (device_may_wakeup(&power->supply->dev)) in axp20x_ac_power_suspend()
297 enable_irq_wake(power->irqs[i++]); in axp20x_ac_power_suspend()
298 while (i < power->num_irqs) in axp20x_ac_power_suspend()
299 disable_irq(power->irqs[i++]); in axp20x_ac_power_suspend()
306 struct axp20x_ac_power *power = dev_get_drvdata(dev); in axp20x_ac_power_resume() local
309 if (device_may_wakeup(&power->supply->dev)) in axp20x_ac_power_resume()
310 disable_irq_wake(power->irqs[i++]); in axp20x_ac_power_resume()
311 while (i < power->num_irqs) in axp20x_ac_power_resume()
312 enable_irq(power->irqs[i++]); in axp20x_ac_power_resume()
323 struct axp20x_dev *axp20x = dev_get_drvdata(pdev->dev.parent); in axp20x_ac_power_probe()
325 struct axp20x_ac_power *power; in axp20x_ac_power_probe() local
329 if (!of_device_is_available(pdev->dev.of_node)) in axp20x_ac_power_probe()
330 return -ENODEV; in axp20x_ac_power_probe()
333 dev_err(&pdev->dev, "Parent drvdata not set\n"); in axp20x_ac_power_probe()
334 return -EINVAL; in axp20x_ac_power_probe()
337 axp_data = of_device_get_match_data(&pdev->dev); in axp20x_ac_power_probe()
339 power = devm_kzalloc(&pdev->dev, in axp20x_ac_power_probe()
340 struct_size(power, irqs, axp_data->num_irq_names), in axp20x_ac_power_probe()
342 if (!power) in axp20x_ac_power_probe()
343 return -ENOMEM; in axp20x_ac_power_probe()
345 if (axp_data->acin_adc) { in axp20x_ac_power_probe()
346 power->acin_v = devm_iio_channel_get(&pdev->dev, "acin_v"); in axp20x_ac_power_probe()
347 if (IS_ERR(power->acin_v)) { in axp20x_ac_power_probe()
348 if (PTR_ERR(power->acin_v) == -ENODEV) in axp20x_ac_power_probe()
349 return -EPROBE_DEFER; in axp20x_ac_power_probe()
350 return PTR_ERR(power->acin_v); in axp20x_ac_power_probe()
353 power->acin_i = devm_iio_channel_get(&pdev->dev, "acin_i"); in axp20x_ac_power_probe()
354 if (IS_ERR(power->acin_i)) { in axp20x_ac_power_probe()
355 if (PTR_ERR(power->acin_i) == -ENODEV) in axp20x_ac_power_probe()
356 return -EPROBE_DEFER; in axp20x_ac_power_probe()
357 return PTR_ERR(power->acin_i); in axp20x_ac_power_probe()
361 power->regmap = dev_get_regmap(pdev->dev.parent, NULL); in axp20x_ac_power_probe()
362 power->has_acin_path_sel = axp_data->acin_path_sel; in axp20x_ac_power_probe()
363 power->num_irqs = axp_data->num_irq_names; in axp20x_ac_power_probe()
365 platform_set_drvdata(pdev, power); in axp20x_ac_power_probe()
367 psy_cfg.of_node = pdev->dev.of_node; in axp20x_ac_power_probe()
368 psy_cfg.drv_data = power; in axp20x_ac_power_probe()
370 power->supply = devm_power_supply_register(&pdev->dev, in axp20x_ac_power_probe()
371 axp_data->power_desc, in axp20x_ac_power_probe()
373 if (IS_ERR(power->supply)) in axp20x_ac_power_probe()
374 return PTR_ERR(power->supply); in axp20x_ac_power_probe()
377 for (i = 0; i < axp_data->num_irq_names; i++) { in axp20x_ac_power_probe()
378 irq = platform_get_irq_byname(pdev, axp_data->irq_names[i]); in axp20x_ac_power_probe()
382 power->irqs[i] = regmap_irq_get_virq(axp20x->regmap_irqc, irq); in axp20x_ac_power_probe()
383 ret = devm_request_any_context_irq(&pdev->dev, power->irqs[i], in axp20x_ac_power_probe()
385 DRVNAME, power); in axp20x_ac_power_probe()
387 dev_err(&pdev->dev, "Error requesting %s IRQ: %d\n", in axp20x_ac_power_probe()
388 axp_data->irq_names[i], ret); in axp20x_ac_power_probe()
398 .compatible = "x-powers,axp202-ac-power-supply",
401 .compatible = "x-powers,axp221-ac-power-supply",
404 .compatible = "x-powers,axp813-ac-power-supply",
421 MODULE_AUTHOR("Quentin Schulz <quentin.schulz@free-electrons.com>");
422 MODULE_DESCRIPTION("AXP20X and AXP22X PMICs' AC power supply driver");