2 * Copyright (C) 2014 NVIDIA Corporation
4 * SPDX-License-Identifier: GPL-2.0+
7 #define pr_fmt(fmt) "as3722: " fmt
15 #include <power/as3722.h>
16 #include <power/pmic.h>
18 #define AS3722_NUM_OF_REGS 0x92
20 static int as3722_read(struct udevice
*dev
, uint reg
, uint8_t *buff
, int len
)
24 ret
= dm_i2c_read(dev
, reg
, buff
, len
);
31 static int as3722_write(struct udevice
*dev
, uint reg
, const uint8_t *buff
,
36 ret
= dm_i2c_write(dev
, reg
, buff
, len
);
43 static int as3722_read_id(struct udevice
*dev
, uint
*idp
, uint
*revisionp
)
47 ret
= pmic_reg_read(dev
, AS3722_ASIC_ID1
);
49 error("failed to read ID1 register: %d", ret
);
54 ret
= pmic_reg_read(dev
, AS3722_ASIC_ID2
);
56 error("failed to read ID2 register: %d", ret
);
64 /* TODO(treding@nvidia.com): Add proper regulator support to avoid this */
65 int as3722_sd_set_voltage(struct udevice
*dev
, unsigned int sd
, u8 value
)
72 ret
= pmic_reg_write(dev
, AS3722_SD_VOLTAGE(sd
), value
);
74 error("failed to write SD%u voltage register: %d", sd
, ret
);
81 int as3722_ldo_set_voltage(struct udevice
*dev
, unsigned int ldo
, u8 value
)
88 ret
= pmic_reg_write(dev
, AS3722_LDO_VOLTAGE(ldo
), value
);
90 error("failed to write LDO%u voltage register: %d", ldo
,
98 static int as3722_probe(struct udevice
*dev
)
103 ret
= as3722_read_id(dev
, &id
, &revision
);
105 error("failed to read ID: %d", ret
);
109 if (id
!= AS3722_DEVICE_ID
) {
110 error("unknown device");
114 debug("AS3722 revision %#x found on I2C bus %s\n", revision
, dev
->name
);
119 #if CONFIG_IS_ENABLED(PMIC_CHILDREN)
120 static const struct pmic_child_info pmic_children_info
[] = {
121 { .prefix
= "sd", .driver
= "as3722_stepdown"},
122 { .prefix
= "ldo", .driver
= "as3722_ldo"},
126 static int as3722_bind(struct udevice
*dev
)
128 struct udevice
*gpio_dev
;
129 ofnode regulators_node
;
133 regulators_node
= dev_read_subnode(dev
, "regulators");
134 if (!ofnode_valid(regulators_node
)) {
135 debug("%s: %s regulators subnode not found\n", __func__
,
140 children
= pmic_bind_children(dev
, regulators_node
, pmic_children_info
);
142 debug("%s: %s - no child found\n", __func__
, dev
->name
);
143 ret
= device_bind_driver(dev
, "gpio_as3722", "gpio_as3722", &gpio_dev
);
145 debug("%s: Cannot bind GPIOs (ret=%d)\n", __func__
, ret
);
153 static int as3722_reg_count(struct udevice
*dev
)
155 return AS3722_NUM_OF_REGS
;
158 static struct dm_pmic_ops as3722_ops
= {
159 .reg_count
= as3722_reg_count
,
161 .write
= as3722_write
,
164 static const struct udevice_id as3722_ids
[] = {
165 { .compatible
= "ams,as3722" },
169 U_BOOT_DRIVER(pmic_as3722
) = {
170 .name
= "as3722_pmic",
172 .of_match
= as3722_ids
,
173 #if CONFIG_IS_ENABLED(PMIC_CHILDREN)
176 .probe
= as3722_probe
,