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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
|
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* act8865-regulator.c - Voltage regulation for active-semi ACT88xx PMUs
*
* http://www.active-semi.com/products/power-management-units/act88xx/
*
* Copyright (C) 2013 Atmel Corporation
*/
#include <linux/module.h>
#include <linux/init.h>
#include <linux/i2c.h>
#include <linux/err.h>
#include <linux/platform_device.h>
#include <linux/regulator/driver.h>
#include <linux/regulator/act8865.h>
#include <linux/of.h>
#include <linux/of_device.h>
#include <linux/power_supply.h>
#include <linux/regulator/of_regulator.h>
#include <linux/regmap.h>
/*
* ACT8600 Global Register Map.
*/
#define ACT8600_SYS_MODE 0x00
#define ACT8600_SYS_CTRL 0x01
#define ACT8600_DCDC1_VSET 0x10
#define ACT8600_DCDC1_CTRL 0x12
#define ACT8600_DCDC2_VSET 0x20
#define ACT8600_DCDC2_CTRL 0x22
#define ACT8600_DCDC3_VSET 0x30
#define ACT8600_DCDC3_CTRL 0x32
#define ACT8600_SUDCDC4_VSET 0x40
#define ACT8600_SUDCDC4_CTRL 0x41
#define ACT8600_LDO5_VSET 0x50
#define ACT8600_LDO5_CTRL 0x51
#define ACT8600_LDO6_VSET 0x60
#define ACT8600_LDO6_CTRL 0x61
#define ACT8600_LDO7_VSET 0x70
#define ACT8600_LDO7_CTRL 0x71
#define ACT8600_LDO8_VSET 0x80
#define ACT8600_LDO8_CTRL 0x81
#define ACT8600_LDO910_CTRL 0x91
#define ACT8600_APCH0 0xA1
#define ACT8600_APCH1 0xA8
#define ACT8600_APCH2 0xA9
#define ACT8600_APCH_STAT 0xAA
#define ACT8600_OTG0 0xB0
#define ACT8600_OTG1 0xB2
/*
* ACT8846 Global Register Map.
*/
#define ACT8846_SYS0 0x00
#define ACT8846_SYS1 0x01
#define ACT8846_REG1_VSET 0x10
#define ACT8846_REG1_CTRL 0x12
#define ACT8846_REG2_VSET0 0x20
#define ACT8846_REG2_VSET1 0x21
#define ACT8846_REG2_CTRL 0x22
#define ACT8846_REG3_VSET0 0x30
#define ACT8846_REG3_VSET1 0x31
#define ACT8846_REG3_CTRL 0x32
#define ACT8846_REG4_VSET0 0x40
#define ACT8846_REG4_VSET1 0x41
#define ACT8846_REG4_CTRL 0x42
#define ACT8846_REG5_VSET 0x50
#define ACT8846_REG5_CTRL 0x51
#define ACT8846_REG6_VSET 0x58
#define ACT8846_REG6_CTRL 0x59
#define ACT8846_REG7_VSET 0x60
#define ACT8846_REG7_CTRL 0x61
#define ACT8846_REG8_VSET 0x68
#define ACT8846_REG8_CTRL 0x69
#define ACT8846_REG9_VSET 0x70
#define ACT8846_REG9_CTRL 0x71
#define ACT8846_REG10_VSET 0x80
#define ACT8846_REG10_CTRL 0x81
#define ACT8846_REG11_VSET 0x90
#define ACT8846_REG11_CTRL 0x91
#define ACT8846_REG12_VSET 0xa0
#define ACT8846_REG12_CTRL 0xa1
#define ACT8846_REG13_CTRL 0xb1
#define ACT8846_GLB_OFF_CTRL 0xc3
#define ACT8846_OFF_SYSMASK 0x18
/*
* ACT8865 Global Register Map.
*/
#define ACT8865_SYS_MODE 0x00
#define ACT8865_SYS_CTRL 0x01
#define ACT8865_DCDC1_VSET1 0x20
#define ACT8865_DCDC1_VSET2 0x21
#define ACT8865_DCDC1_CTRL 0x22
#define ACT8865_DCDC2_VSET1 0x30
#define ACT8865_DCDC2_VSET2 0x31
#define ACT8865_DCDC2_CTRL 0x32
#define ACT8865_DCDC3_VSET1 0x40
#define ACT8865_DCDC3_VSET2 0x41
#define ACT8865_DCDC3_CTRL 0x42
#define ACT8865_LDO1_VSET 0x50
#define ACT8865_LDO1_CTRL 0x51
#define ACT8865_LDO2_VSET 0x54
#define ACT8865_LDO2_CTRL 0x55
#define ACT8865_LDO3_VSET 0x60
#define ACT8865_LDO3_CTRL 0x61
#define ACT8865_LDO4_VSET 0x64
#define ACT8865_LDO4_CTRL 0x65
#define ACT8865_MSTROFF 0x20
/*
* Field Definitions.
*/
#define ACT8865_ENA 0x80 /* ON - [7] */
#define ACT8865_VSEL_MASK 0x3F /* VSET - [5:0] */
#define ACT8600_LDO10_ENA 0x40 /* ON - [6] */
#define ACT8600_SUDCDC_VSEL_MASK 0xFF /* SUDCDC VSET - [7:0] */
#define ACT8600_APCH_CHG_ACIN BIT(7)
#define ACT8600_APCH_CHG_USB BIT(6)
#define ACT8600_APCH_CSTATE0 BIT(5)
#define ACT8600_APCH_CSTATE1 BIT(4)
/*
* ACT8865 voltage number
*/
#define ACT8865_VOLTAGE_NUM 64
#define ACT8600_SUDCDC_VOLTAGE_NUM 256
struct act8865 {
struct regmap *regmap;
int off_reg;
int off_mask;
};
static const struct regmap_range act8600_reg_ranges[] = {
regmap_reg_range(0x00, 0x01),
regmap_reg_range(0x10, 0x10),
regmap_reg_range(0x12, 0x12),
regmap_reg_range(0x20, 0x20),
regmap_reg_range(0x22, 0x22),
regmap_reg_range(0x30, 0x30),
regmap_reg_range(0x32, 0x32),
regmap_reg_range(0x40, 0x41),
regmap_reg_range(0x50, 0x51),
regmap_reg_range(0x60, 0x61),
regmap_reg_range(0x70, 0x71),
regmap_reg_range(0x80, 0x81),
regmap_reg_range(0x91, 0x91),
regmap_reg_range(0xA1, 0xA1),
regmap_reg_range(0xA8, 0xAA),
regmap_reg_range(0xB0, 0xB0),
regmap_reg_range(0xB2, 0xB2),
regmap_reg_range(0xC1, 0xC1),
};
static const struct regmap_range act8600_reg_ro_ranges[] = {
regmap_reg_range(0xAA, 0xAA),
regmap_reg_range(0xC1, 0xC1),
};
static const struct regmap_range act8600_reg_volatile_ranges[] = {
regmap_reg_range(0x00, 0x01),
regmap_reg_range(0x12, 0x12),
regmap_reg_range(0x22, 0x22),
regmap_reg_range(0x32, 0x32),
regmap_reg_range(0x41, 0x41),
regmap_reg_range(0x51, 0x51),
regmap_reg_range(0x61, 0x61),
regmap_reg_range(0x71, 0x71),
regmap_reg_range(0x81, 0x81),
regmap_reg_range(0xA8, 0xA8),
regmap_reg_range(0xAA, 0xAA),
regmap_reg_range(0xB0, 0xB0),
regmap_reg_range(0xC1, 0xC1),
};
static const struct regmap_access_table act8600_write_ranges_table = {
.yes_ranges = act8600_reg_ranges,
.n_yes_ranges = ARRAY_SIZE(act8600_reg_ranges),
.no_ranges = act8600_reg_ro_ranges,
.n_no_ranges = ARRAY_SIZE(act8600_reg_ro_ranges),
};
static const struct regmap_access_table act8600_read_ranges_table = {
.yes_ranges = act8600_reg_ranges,
.n_yes_ranges = ARRAY_SIZE(act8600_reg_ranges),
};
static const struct regmap_access_table act8600_volatile_ranges_table = {
.yes_ranges = act8600_reg_volatile_ranges,
.n_yes_ranges = ARRAY_SIZE(act8600_reg_volatile_ranges),
};
static const struct regmap_config act8600_regmap_config = {
.reg_bits = 8,
.val_bits = 8,
.max_register = 0xFF,
.wr_table = &act8600_write_ranges_table,
.rd_table = &act8600_read_ranges_table,
.volatile_table = &act8600_volatile_ranges_table,
};
static const struct regmap_config act8865_regmap_config = {
.reg_bits = 8,
.val_bits = 8,
};
static const struct regulator_linear_range act8865_voltage_ranges[] = {
REGULATOR_LINEAR_RANGE(600000, 0, 23, 25000),
REGULATOR_LINEAR_RANGE(1200000, 24, 47, 50000),
REGULATOR_LINEAR_RANGE(2400000, 48, 63, 100000),
};
static const struct regulator_linear_range act8600_sudcdc_voltage_ranges[] = {
REGULATOR_LINEAR_RANGE(3000000, 0, 63, 0),
REGULATOR_LINEAR_RANGE(3000000, 64, 159, 100000),
REGULATOR_LINEAR_RANGE(12600000, 160, 191, 200000),
REGULATOR_LINEAR_RANGE(19000000, 192, 247, 400000),
REGULATOR_LINEAR_RANGE(41400000, 248, 255, 0),
};
static const struct regulator_ops act8865_ops = {
.list_voltage = regulator_list_voltage_linear_range,
.map_voltage = regulator_map_voltage_linear_range,
.get_voltage_sel = regulator_get_voltage_sel_regmap,
.set_voltage_sel = regulator_set_voltage_sel_regmap,
.enable = regulator_enable_regmap,
.disable = regulator_disable_regmap,
.is_enabled = regulator_is_enabled_regmap,
};
static const struct regulator_ops act8865_ldo_ops = {
.enable = regulator_enable_regmap,
.disable = regulator_disable_regmap,
.is_enabled = regulator_is_enabled_regmap,
};
#define ACT88xx_REG(_name, _family, _id, _vsel_reg, _supply) \
[_family##_ID_##_id] = { \
.name = _name, \
.of_match = of_match_ptr(_name), \
.regulators_node = of_match_ptr("regulators"), \
.supply_name = _supply, \
.id = _family##_ID_##_id, \
.type = REGULATOR_VOLTAGE, \
.ops = &act8865_ops, \
.n_voltages = ACT8865_VOLTAGE_NUM, \
.linear_ranges = act8865_voltage_ranges, \
.n_linear_ranges = ARRAY_SIZE(act8865_voltage_ranges), \
.vsel_reg = _family##_##_id##_##_vsel_reg, \
.vsel_mask = ACT8865_VSEL_MASK, \
.enable_reg = _family##_##_id##_CTRL, \
.enable_mask = ACT8865_ENA, \
.owner = THIS_MODULE, \
}
static const struct regulator_desc act8600_regulators[] = {
ACT88xx_REG("DCDC1", ACT8600, DCDC1, VSET, "vp1"),
ACT88xx_REG("DCDC2", ACT8600, DCDC2, VSET, "vp2"),
ACT88xx_REG("DCDC3", ACT8600, DCDC3, VSET, "vp3"),
{
.name = "SUDCDC_REG4",
.of_match = of_match_ptr("SUDCDC_REG4"),
.regulators_node = of_match_ptr("regulators"),
.id = ACT8600_ID_SUDCDC4,
.ops = &act8865_ops,
.type = REGULATOR_VOLTAGE,
.n_voltages = ACT8600_SUDCDC_VOLTAGE_NUM,
.linear_ranges = act8600_sudcdc_voltage_ranges,
.n_linear_ranges = ARRAY_SIZE(act8600_sudcdc_voltage_ranges),
.vsel_reg = ACT8600_SUDCDC4_VSET,
.vsel_mask = ACT8600_SUDCDC_VSEL_MASK,
.enable_reg = ACT8600_SUDCDC4_CTRL,
.enable_mask = ACT8865_ENA,
.owner = THIS_MODULE,
},
ACT88xx_REG("LDO5", ACT8600, LDO5, VSET, "inl"),
ACT88xx_REG("LDO6", ACT8600, LDO6, VSET, "inl"),
ACT88xx_REG("LDO7", ACT8600, LDO7, VSET, "inl"),
|