1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2014 NVIDIA Corporation
6 #define pr_fmt(fmt) "as3722: " fmt
14 #include <power/as3722.h>
15 #include <power/pmic.h>
17 #define AS3722_NUM_OF_REGS 0x92
19 static int as3722_read(struct udevice
*dev
, uint reg
, uint8_t *buff
, int len
)
23 ret
= dm_i2c_read(dev
, reg
, buff
, len
);
30 static int as3722_write(struct udevice
*dev
, uint reg
, const uint8_t *buff
,
35 ret
= dm_i2c_write(dev
, reg
, buff
, len
);
42 static int as3722_read_id(struct udevice
*dev
, uint
*idp
, uint
*revisionp
)
46 ret
= pmic_reg_read(dev
, AS3722_ASIC_ID1
);
48 pr_err("failed to read ID1 register: %d", ret
);
53 ret
= pmic_reg_read(dev
, AS3722_ASIC_ID2
);
55 pr_err("failed to read ID2 register: %d", ret
);
63 /* TODO(treding@nvidia.com): Add proper regulator support to avoid this */
64 int as3722_sd_set_voltage(struct udevice
*dev
, unsigned int sd
, u8 value
)
71 ret
= pmic_reg_write(dev
, AS3722_SD_VOLTAGE(sd
), value
);
73 pr_err("failed to write SD%u voltage register: %d", sd
, ret
);
80 int as3722_ldo_set_voltage(struct udevice
*dev
, unsigned int ldo
, u8 value
)
87 ret
= pmic_reg_write(dev
, AS3722_LDO_VOLTAGE(ldo
), value
);
89 pr_err("failed to write LDO%u voltage register: %d", ldo
,
97 static int as3722_probe(struct udevice
*dev
)
102 ret
= as3722_read_id(dev
, &id
, &revision
);
104 pr_err("failed to read ID: %d", ret
);
108 if (id
!= AS3722_DEVICE_ID
) {
109 pr_err("unknown device");
113 debug("AS3722 revision %#x found on I2C bus %s\n", revision
, dev
->name
);
118 #if CONFIG_IS_ENABLED(PMIC_CHILDREN)
119 static const struct pmic_child_info pmic_children_info
[] = {
120 { .prefix
= "sd", .driver
= "as3722_stepdown"},
121 { .prefix
= "ldo", .driver
= "as3722_ldo"},
125 static int as3722_bind(struct udevice
*dev
)
127 struct udevice
*gpio_dev
;
128 ofnode regulators_node
;
132 regulators_node
= dev_read_subnode(dev
, "regulators");
133 if (!ofnode_valid(regulators_node
)) {
134 debug("%s: %s regulators subnode not found\n", __func__
,
139 children
= pmic_bind_children(dev
, regulators_node
, pmic_children_info
);
141 debug("%s: %s - no child found\n", __func__
, dev
->name
);
142 ret
= device_bind_driver(dev
, "gpio_as3722", "gpio_as3722", &gpio_dev
);
144 debug("%s: Cannot bind GPIOs (ret=%d)\n", __func__
, ret
);
152 static int as3722_reg_count(struct udevice
*dev
)
154 return AS3722_NUM_OF_REGS
;
157 static struct dm_pmic_ops as3722_ops
= {
158 .reg_count
= as3722_reg_count
,
160 .write
= as3722_write
,
163 static const struct udevice_id as3722_ids
[] = {
164 { .compatible
= "ams,as3722" },
168 U_BOOT_DRIVER(pmic_as3722
) = {
169 .name
= "as3722_pmic",
171 .of_match
= as3722_ids
,
172 #if CONFIG_IS_ENABLED(PMIC_CHILDREN)
175 .probe
= as3722_probe
,