blob: 0f2b24a8b5f312b6153e26ad4f52397978f200b0 [file] [log] [blame]
Samuel Holland3f902612021-10-08 00:17:16 -05001// SPDX-License-Identifier: GPL-2.0+
2
Samuel Holland5afa5cd2021-10-24 21:00:10 -05003#include <axp_pmic.h>
Samuel Holland3f902612021-10-08 00:17:16 -05004#include <dm.h>
Samuel Holland5afa5cd2021-10-24 21:00:10 -05005#include <dm/lists.h>
Samuel Holland3f902612021-10-08 00:17:16 -05006#include <i2c.h>
7#include <power/pmic.h>
Samuel Holland5afa5cd2021-10-24 21:00:10 -05008#include <sysreset.h>
9
10#if CONFIG_IS_ENABLED(SYSRESET)
11static int axp_sysreset_request(struct udevice *dev, enum sysreset_t type)
12{
13 int ret;
14
15 if (type != SYSRESET_POWER_OFF)
16 return -EPROTONOSUPPORT;
17
18 ret = pmic_clrsetbits(dev->parent, AXP152_SHUTDOWN, 0, AXP152_POWEROFF);
19 if (ret < 0)
20 return ret;
21
22 return -EINPROGRESS;
23}
24
25static struct sysreset_ops axp_sysreset_ops = {
26 .request = axp_sysreset_request,
27};
28
29U_BOOT_DRIVER(axp_sysreset) = {
30 .name = "axp_sysreset",
31 .id = UCLASS_SYSRESET,
32 .ops = &axp_sysreset_ops,
33};
34#endif
Samuel Holland3f902612021-10-08 00:17:16 -050035
36static int axp_pmic_reg_count(struct udevice *dev)
37{
38 /* TODO: Get the specific value from driver data. */
39 return 0x100;
40}
41
42static struct dm_pmic_ops axp_pmic_ops = {
43 .reg_count = axp_pmic_reg_count,
44 .read = dm_i2c_read,
45 .write = dm_i2c_write,
46};
47
Samuel Holland5afa5cd2021-10-24 21:00:10 -050048static int axp_pmic_bind(struct udevice *dev)
49{
50 int ret;
51
52 ret = dm_scan_fdt_dev(dev);
53 if (ret)
54 return ret;
55
56 if (CONFIG_IS_ENABLED(SYSRESET)) {
57 ret = device_bind_driver_to_node(dev, "axp_sysreset", "axp_sysreset",
58 dev_ofnode(dev), NULL);
59 if (ret)
60 return ret;
61 }
62
63 return 0;
64}
65
Samuel Holland3f902612021-10-08 00:17:16 -050066static const struct udevice_id axp_pmic_ids[] = {
67 { .compatible = "x-powers,axp152" },
68 { .compatible = "x-powers,axp202" },
69 { .compatible = "x-powers,axp209" },
70 { .compatible = "x-powers,axp221" },
71 { .compatible = "x-powers,axp223" },
72 { .compatible = "x-powers,axp803" },
73 { .compatible = "x-powers,axp806" },
74 { .compatible = "x-powers,axp809" },
75 { .compatible = "x-powers,axp813" },
76 { }
77};
78
79U_BOOT_DRIVER(axp_pmic) = {
80 .name = "axp_pmic",
81 .id = UCLASS_PMIC,
82 .of_match = axp_pmic_ids,
Samuel Holland5afa5cd2021-10-24 21:00:10 -050083 .bind = axp_pmic_bind,
Samuel Holland3f902612021-10-08 00:17:16 -050084 .ops = &axp_pmic_ops,
85};