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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
|
/*
* Copyright (C) 2015 Google, Inc
*
* SPDX-License-Identifier: GPL-2.0+
*/
#include <common.h>
#include <fdtdec.h>
#include <errno.h>
#include <dm.h>
#include <i2c.h>
#include <power/pmic.h>
#include <power/regulator.h>
#include <power/s5m8767.h>
DECLARE_GLOBAL_DATA_PTR;
static const struct sec_voltage_desc buck_v1 = {
.max = 2225000,
.min = 650000,
.step = 6250,
};
static const struct sec_voltage_desc buck_v2 = {
.max = 1600000,
.min = 600000,
.step = 6250,
};
static const struct sec_voltage_desc buck_v3 = {
.max = 3000000,
.min = 750000,
.step = 12500,
};
static const struct sec_voltage_desc ldo_v1 = {
.max = 3950000,
.min = 800000,
.step = 50000,
};
static const struct sec_voltage_desc ldo_v2 = {
.max = 2375000,
.min = 800000,
.step = 25000,
};
static const struct s5m8767_para buck_param[] = {
/*
* | voltage ----| | enable -| voltage
* regnum addr bpos mask addr on desc
*/
{S5M8767_BUCK1, 0x33, 0x0, 0xff, 0x32, 0x3, &buck_v1},
{S5M8767_BUCK2, 0x35, 0x0, 0xff, 0x34, 0x1, &buck_v2},
{S5M8767_BUCK3, 0x3e, 0x0, 0xff, 0x3d, 0x1, &buck_v2},
{S5M8767_BUCK4, 0x47, 0x0, 0xff, 0x46, 0x1, &buck_v2},
{S5M8767_BUCK5, 0x50, 0x0, 0xff, 0x4f, 0x3, &buck_v1},
{S5M8767_BUCK6, 0x55, 0x0, 0xff, 0x54, 0x3, &buck_v1},
{S5M8767_BUCK7, 0x57, 0x0, 0xff, 0x56, 0x3, &buck_v3},
{S5M8767_BUCK8, 0x59, 0x0, 0xff, 0x58, 0x3, &buck_v3},
{S5M8767_BUCK9, 0x5b, 0x0, 0xff, 0x5a, 0x3, &buck_v3},
};
static const struct s5m8767_para ldo_param[] = {
{S5M8767_LDO1, 0x5c, 0x0, 0x3f, 0x5c, 0x3, &ldo_v2},
{S5M8767_LDO2, 0x5d, 0x0, 0x3f, 0x5d, 0x1, &ldo_v2},
{S5M8767_LDO3, 0x61, 0x0, 0x3f, 0x61, 0x3, &ldo_v1},
{S5M8767_LDO4, 0x62, 0x0, 0x3f, 0x62, 0x3, &ldo_v1},
{S5M8767_LDO5, 0x63, 0x0, 0x3f, 0x63, 0x3, &ldo_v1},
{S5M8767_LDO6, 0x64, 0x0, 0x3f, 0x64, 0x1, &ldo_v2},
{S5M8767_LDO7, 0x65, 0x0, 0x3f, 0x65, 0x1, &ldo_v2},
{S5M8767_LDO8, 0x66, 0x0, 0x3f, 0x66, 0x1, &ldo_v2},
{S5M8767_LDO9, 0x67, 0x0, 0x3f, 0x67, 0x3, &ldo_v1},
{S5M8767_LDO10, 0x68, 0x0, 0x3f, 0x68, 0x1, &ldo_v1},
{S5M8767_LDO11, 0x69, 0x0, 0x3f, 0x69, 0x1, &ldo_v1},
{S5M8767_LDO12, 0x6a, 0x0, 0x3f, 0x6a, 0x1, &ldo_v1},
{S5M8767_LDO13, 0x6b, 0x0, 0x3f, 0x6b, 0x3, &ldo_v1},
{S5M8767_LDO14, 0x6c, 0x0, 0x3f, 0x6c, 0x1, &ldo_v1},
{S5M8767_LDO15, 0x6d, 0x0, 0x3f, 0x6d, 0x1, &ldo_v2},
{S5M8767_LDO16, 0x6e, 0x0, 0x3f, 0x6e, 0x1, &ldo_v1},
{S5M8767_LDO17, 0x6f, 0x0, 0x3f, 0x6f, 0x3, &ldo_v1},
{S5M8767_LDO18, 0x70, 0x0, 0x3f, 0x70, 0x3, &ldo_v1},
{S5M8767_LDO19, 0x71, 0x0, 0x3f, 0x71, 0x3, &ldo_v1},
{S5M8767_LDO20, 0x72, 0x0, 0x3f, 0x72, 0x3, &ldo_v1},
{S5M8767_LDO21, 0x73, 0x0, 0x3f, 0x73, 0x3, &ldo_v1},
{S5M8767_LDO22, 0x74, 0x0, 0x3f, 0x74, 0x3, &ldo_v1},
{S5M8767_LDO23, 0x75, 0x0, 0x3f, 0x75, 0x3, &ldo_v1},
{S5M8767_LDO24, 0x76, 0x0, 0x3f, 0x76, 0x3, &ldo_v1},
{S5M8767_LDO25, 0x77, 0x0, 0x3f, 0x77, 0x3, &ldo_v1},
{S5M8767_LDO26, 0x78, 0x0, 0x3f, 0x78, 0x3, &ldo_v1},
{S5M8767_LDO27, 0x79, 0x0, 0x3f, 0x79, 0x3, &ldo_v1},
{S5M8767_LDO28, 0x7a, 0x0, 0x3f, 0x7a, 0x3, &ldo_v1},
};
enum {
ENABLE_SHIFT = 6,
ENABLE_MASK = 3,
};
static int reg_get_value(struct udevice *dev, const struct s5m8767_para *param)
{
const struct sec_voltage_desc *desc;
int ret, uv, val;
ret = pmic_reg_read(dev->parent, param->vol_addr);
if (ret < 0)
return ret;
desc = param->vol;
val = (ret >> param->vol_bitpos) & param->vol_bitmask;
uv = desc->min + val * desc->step;
return uv;
}
static int reg_set_value(struct udevice *dev, const struct s5m8767_para *param,
int uv)
{
const struct sec_voltage_desc *desc;
int ret, val;
desc = param->vol;
if (uv < desc->min || uv > desc->max)
return -EINVAL;
val = (uv - desc->min) / desc->step;
val = (val & param->vol_bitmask) << param->vol_bitpos;
ret = pmic_clrsetbits(dev->parent, param->vol_addr,
param->vol_bitmask << param->vol_bitpos,
val);
return ret;
}
static int s5m8767_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;
uc_pdata->mode_count = 0;
return 0;
}
static int ldo_get_value(struct udevice *dev)
{
int ldo = dev->driver_data;
return reg_get_value(dev, &ldo_param[ldo]);
}
static int ldo_set_value(struct udevice *dev, int uv)
{
int ldo = dev->driver_data;
return reg_set_value(dev, &ldo_param[ldo], uv);
}
static int reg_get_enable(struct udevice *dev, const struct s5m8767_para *param)
{
bool enable;
int ret;
ret = pmic_reg_read(dev->parent, param->reg_enaddr);
if (ret < 0)
return ret;
enable = (ret >> ENABLE_SHIFT) & ENABLE_MASK;
return enable;
}
static int reg_set_enable(struct udevice *dev, const struct s5m8767_para *param,
bool enable)
{
int ret;
ret = pmic_reg_read(dev->parent, param->reg_enaddr);
if (ret < 0)
return ret;
ret = pmic_clrsetbits(dev->parent, param->reg_enaddr,
ENABLE_MASK << ENABLE_SHIFT,
enable ? param->reg_enbiton << ENABLE_SHIFT : 0);
return ret;
}
static bool ldo_get_enable(struct udevice *dev)
{
int ldo = dev->driver_data;
return reg_get_enable(dev, &ldo_param[ldo]);
}
static int ldo_set_enable(struct udevice *dev, bool enable)
{
int ldo = dev->driver_data;
return reg_set_enable(dev, &ldo_param[ldo], enable);
}
static int s5m8767_buck_probe(struct udevice *dev)
{
struct dm_regulator_uclass_platdata *uc_pdata;
uc_pdata = dev_get_uclass_platdata(dev);
uc_pdata->type = REGULATOR_TYPE_BUCK;
uc_pdata->mode_count = 0;
return 0;
}
static int buck_get_value(struct udevice *dev)
{
int buck = dev->driver_data;
return reg_get_value(dev, &buck_param[buck]);
}
static int buck_set_value(struct udevice *dev, int uv)
{
int buck = dev->driver_data;
return reg_set_value(dev, &buck_param[buck], uv);
}
static bool buck_get_enable(struct udevice *dev)
{
int buck = dev->driver_data;
return reg_get_enable(dev, &buck_param[buck]);
}
static int buck_set_enable(struct udevice *dev, bool enable)
{
int buck = dev->driver_data;
return reg_set_enable(dev, &buck_param[buck], enable);
}
static const struct dm_regulator_ops s5m8767_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(s5m8767_ldo) = {
.name = S5M8767_LDO_DRIVER,
.id = UCLASS_REGULATOR,
.ops = &s5m8767_ldo_ops,
.probe = s5m8767_ldo_probe,
};
static const struct dm_regulator_ops s5m8767_buck_ops = {
.get_value = buck_get_value,
.set_value = buck_set_value,
.get_enable = buck_get_enable,
.set_enable = buck_set_enable,
};
U_BOOT_DRIVER(s5m8767_buck) = {
.name = S5M8767_BUCK_DRIVER,
.id = UCLASS_REGULATOR,
.ops = &s5m8767_buck_ops,
.probe = s5m8767_buck_probe,
};
|