blob: f32fb6a92dc295c04fd31162e373beb713ee16ce [file] [log] [blame]
Samuel Hollanda24ef882023-01-22 17:46:20 -06001// SPDX-License-Identifier: GPL-2.0+
2
3#include <dm/device.h>
4#include <errno.h>
5#include <power/pmic.h>
6#include <power/regulator.h>
7
8#define AXP_POWER_STATUS 0x00
9#define AXP_POWER_STATUS_VBUS_PRESENT BIT(5)
10
11static int axp_usb_power_get_enable(struct udevice *dev)
12{
13 int ret;
14
15 ret = pmic_reg_read(dev->parent, AXP_POWER_STATUS);
16 if (ret < 0)
17 return ret;
18
19 return !!(ret & AXP_POWER_STATUS_VBUS_PRESENT);
20}
21
22static const struct dm_regulator_ops axp_usb_power_ops = {
23 .get_enable = axp_usb_power_get_enable,
24};
25
26static int axp_usb_power_probe(struct udevice *dev)
27{
28 struct dm_regulator_uclass_plat *uc_plat = dev_get_uclass_plat(dev);
29
30 uc_plat->type = REGULATOR_TYPE_FIXED;
31
32 return 0;
33}
34
35static const struct udevice_id axp_usb_power_ids[] = {
36 { .compatible = "x-powers,axp202-usb-power-supply" },
37 { .compatible = "x-powers,axp221-usb-power-supply" },
38 { .compatible = "x-powers,axp223-usb-power-supply" },
39 { .compatible = "x-powers,axp813-usb-power-supply" },
40 { }
41};
42
43U_BOOT_DRIVER(axp_usb_power) = {
44 .name = "axp_usb_power",
45 .id = UCLASS_REGULATOR,
46 .of_match = axp_usb_power_ids,
47 .probe = axp_usb_power_probe,
48 .ops = &axp_usb_power_ops,
49};