blob: 63f4615398f50f63ecd7f74888cfd9233491096f [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glass8f189512017-07-25 08:30:10 -06002/*
3 * Copyright (C) 2017 Google, Inc
4 * Written by Simon Glass <sjg@chromium.org>
5 *
6 * Placeholder regulator driver for as3722.
Simon Glass8f189512017-07-25 08:30:10 -06007 */
8
9#include <common.h>
10#include <dm.h>
11#include <errno.h>
12#include <power/as3722.h>
13#include <power/pmic.h>
14#include <power/regulator.h>
15
16static int stepdown_get_value(struct udevice *dev)
17{
18 return -ENOSYS;
19}
20
21static int stepdown_set_value(struct udevice *dev, int uvolt)
22{
23 return -ENOSYS;
24}
25
26static int stepdown_set_enable(struct udevice *dev, bool enable)
27{
28 struct udevice *pmic = dev_get_parent(dev);
29 int sd = dev->driver_data;
30 int ret;
31
32 ret = pmic_clrsetbits(pmic, AS3722_SD_CONTROL, 0, 1 << sd);
33 if (ret < 0) {
34 debug("%s: failed to write SD control register: %d", __func__,
35 ret);
36 return ret;
37 }
38
39 return 0;
40}
41
42static int stepdown_get_enable(struct udevice *dev)
43{
44 struct udevice *pmic = dev_get_parent(dev);
45 int sd = dev->driver_data;
46 int ret;
47
48 ret = pmic_reg_read(pmic, AS3722_SD_CONTROL);
49 if (ret < 0) {
50 debug("%s: failed to read SD control register: %d", __func__,
51 ret);
52 return ret;
53 }
54
55 return ret & (1 << sd) ? true : false;
56}
57
58static int ldo_get_value(struct udevice *dev)
59{
60 return -ENOSYS;
61}
62
63static int ldo_set_value(struct udevice *dev, int uvolt)
64{
65 return -ENOSYS;
66}
67
68static int ldo_set_enable(struct udevice *dev, bool enable)
69{
70 struct udevice *pmic = dev_get_parent(dev);
71 int ldo = dev->driver_data;
72 int ret;
73
74 ret = pmic_clrsetbits(pmic, AS3722_LDO_CONTROL, 0, 1 << ldo);
75 if (ret < 0) {
76 debug("%s: failed to write LDO control register: %d", __func__,
77 ret);
78 return ret;
79 }
80
81 return 0;
82}
83
84static int ldo_get_enable(struct udevice *dev)
85{
86 struct udevice *pmic = dev_get_parent(dev);
87 int ldo = dev->driver_data;
88 int ret;
89
90 ret = pmic_reg_read(pmic, AS3722_LDO_CONTROL);
91 if (ret < 0) {
92 debug("%s: failed to read SD control register: %d", __func__,
93 ret);
94 return ret;
95 }
96
97 return ret & (1 << ldo) ? true : false;
98}
99
100static int as3722_stepdown_probe(struct udevice *dev)
101{
102 struct dm_regulator_uclass_platdata *uc_pdata;
103
104 uc_pdata = dev_get_uclass_platdata(dev);
105
106 uc_pdata->type = REGULATOR_TYPE_BUCK;
107
108 return 0;
109}
110
111static int as3722_ldo_probe(struct udevice *dev)
112{
113 struct dm_regulator_uclass_platdata *uc_pdata;
114
115 uc_pdata = dev_get_uclass_platdata(dev);
116
117 uc_pdata->type = REGULATOR_TYPE_LDO;
118
119 return 0;
120}
121
122static const struct dm_regulator_ops as3722_stepdown_ops = {
123 .get_value = stepdown_get_value,
124 .set_value = stepdown_set_value,
125 .get_enable = stepdown_get_enable,
126 .set_enable = stepdown_set_enable,
127};
128
129static const struct dm_regulator_ops as3722_ldo_ops = {
130 .get_value = ldo_get_value,
131 .set_value = ldo_set_value,
132 .get_enable = ldo_get_enable,
133 .set_enable = ldo_set_enable,
134};
135
136U_BOOT_DRIVER(as3722_stepdown) = {
137 .name = "as3722_stepdown",
138 .id = UCLASS_REGULATOR,
139 .ops = &as3722_stepdown_ops,
140 .probe = as3722_stepdown_probe,
141};
142
143U_BOOT_DRIVER(as3722_ldo) = {
144 .name = "as3722_ldo",
145 .id = UCLASS_REGULATOR,
146 .ops = &as3722_ldo_ops,
147 .probe = as3722_ldo_probe,
148};