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