1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2017 Google, Inc
6 * Placeholder regulator driver for as3722.
13 #include <power/as3722.h>
14 #include <power/pmic.h>
15 #include <power/regulator.h>
17 #define AS3722_LDO_CONTROL0_MAX_INDEX 7
19 static int stepdown_get_value(struct udevice *dev)
24 static int stepdown_set_value(struct udevice *dev, int uvolt)
29 static int stepdown_set_enable(struct udevice *dev, bool enable)
31 struct udevice *pmic = dev_get_parent(dev);
32 int sd = dev->driver_data;
35 ret = pmic_clrsetbits(pmic, AS3722_SD_CONTROL, 0, 1 << sd);
37 debug("%s: failed to write SD control register: %d", __func__,
45 static int stepdown_get_enable(struct udevice *dev)
47 struct udevice *pmic = dev_get_parent(dev);
48 int sd = dev->driver_data;
51 ret = pmic_reg_read(pmic, AS3722_SD_CONTROL);
53 debug("%s: failed to read SD control register: %d", __func__,
58 return ret & (1 << sd) ? true : false;
61 static int ldo_get_value(struct udevice *dev)
66 static int ldo_set_value(struct udevice *dev, int uvolt)
71 static int ldo_set_enable(struct udevice *dev, bool enable)
73 struct udevice *pmic = dev_get_parent(dev);
74 u8 ctrl_reg = AS3722_LDO_CONTROL0;
75 int ldo = dev->driver_data;
78 if (ldo > AS3722_LDO_CONTROL0_MAX_INDEX) {
79 ctrl_reg = AS3722_LDO_CONTROL1;
83 ret = pmic_clrsetbits(pmic, ctrl_reg, !enable << ldo, enable << ldo);
85 debug("%s: failed to write LDO control register: %d", __func__,
93 static int ldo_get_enable(struct udevice *dev)
95 struct udevice *pmic = dev_get_parent(dev);
96 u8 ctrl_reg = AS3722_LDO_CONTROL0;
97 int ldo = dev->driver_data;
100 if (ldo > AS3722_LDO_CONTROL0_MAX_INDEX) {
101 ctrl_reg = AS3722_LDO_CONTROL1;
105 ret = pmic_reg_read(pmic, ctrl_reg);
107 debug("%s: failed to read SD control register: %d", __func__,
112 return ret & (1 << ldo) ? true : false;
115 static int as3722_stepdown_probe(struct udevice *dev)
117 struct dm_regulator_uclass_plat *uc_pdata;
119 uc_pdata = dev_get_uclass_plat(dev);
121 uc_pdata->type = REGULATOR_TYPE_BUCK;
126 static int as3722_ldo_probe(struct udevice *dev)
128 struct dm_regulator_uclass_plat *uc_pdata;
130 uc_pdata = dev_get_uclass_plat(dev);
132 uc_pdata->type = REGULATOR_TYPE_LDO;
137 static const struct dm_regulator_ops as3722_stepdown_ops = {
138 .get_value = stepdown_get_value,
139 .set_value = stepdown_set_value,
140 .get_enable = stepdown_get_enable,
141 .set_enable = stepdown_set_enable,
144 static const struct dm_regulator_ops as3722_ldo_ops = {
145 .get_value = ldo_get_value,
146 .set_value = ldo_set_value,
147 .get_enable = ldo_get_enable,
148 .set_enable = ldo_set_enable,
151 U_BOOT_DRIVER(as3722_stepdown) = {
152 .name = "as3722_stepdown",
153 .id = UCLASS_REGULATOR,
154 .ops = &as3722_stepdown_ops,
155 .probe = as3722_stepdown_probe,
158 U_BOOT_DRIVER(as3722_ldo) = {
159 .name = "as3722_ldo",
160 .id = UCLASS_REGULATOR,
161 .ops = &as3722_ldo_ops,
162 .probe = as3722_ldo_probe,