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
|
// SPDX-License-Identifier: GPL-2.0
//
// Socionext UniPhier EVEA ADC/DAC codec driver.
//
// Copyright (c) 2016-2017 Socionext Inc.
#include <linux/clk.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/regmap.h>
#include <linux/reset.h>
#include <sound/pcm.h>
#include <sound/soc.h>
#define DRV_NAME "evea"
#define EVEA_RATES SNDRV_PCM_RATE_48000
#define EVEA_FORMATS SNDRV_PCM_FMTBIT_S32_LE
#define AADCPOW(n) (0x0078 + 0x04 * (n))
#define AADCPOW_AADC_POWD BIT(0)
#define ALINSW1 0x0088
#define ALINSW1_SEL1_SHIFT 3
#define AHPOUTPOW 0x0098
#define AHPOUTPOW_HP_ON BIT(4)
#define ALINEPOW 0x009c
#define ALINEPOW_LIN2_POWD BIT(3)
#define ALINEPOW_LIN1_POWD BIT(4)
#define ALO1OUTPOW 0x00a8
#define ALO1OUTPOW_LO1_ON BIT(4)
#define ALO2OUTPOW 0x00ac
#define ALO2OUTPOW_ADAC2_MUTE BIT(0)
#define ALO2OUTPOW_LO2_ON BIT(4)
#define AANAPOW 0x00b8
#define AANAPOW_A_POWD BIT(4)
#define ADACSEQ1(n) (0x0144 + 0x40 * (n))
#define ADACSEQ1_MMUTE BIT(1)
#define ADACSEQ2(n) (0x0160 + 0x40 * (n))
#define ADACSEQ2_ADACIN_FIX BIT(0)
#define ADAC1ODC 0x0200
#define ADAC1ODC_HP_DIS_RES_MASK GENMASK(2, 1)
#define ADAC1ODC_HP_DIS_RES_OFF (0x0 << 1)
#define ADAC1ODC_HP_DIS_RES_ON (0x3 << 1)
#define ADAC1ODC_ADAC_RAMPCLT_MASK GENMASK(8, 7)
#define ADAC1ODC_ADAC_RAMPCLT_NORMAL (0x0 << 7)
#define ADAC1ODC_ADAC_RAMPCLT_REDUCE (0x1 << 7)
struct evea_priv {
struct clk *clk, *clk_exiv;
struct reset_control *rst, *rst_exiv, *rst_adamv;
struct regmap *regmap;
int switch_lin;
int switch_lo;
int switch_hp;
};
static const char * const linsw1_sel1_text[] = {
"LIN1", "LIN2", "LIN3"
};
static SOC_ENUM_SINGLE_DECL(linsw1_sel1_enum,
ALINSW1, ALINSW1_SEL1_SHIFT,
linsw1_sel1_text);
static const struct snd_kcontrol_new linesw1_mux[] = {
SOC_DAPM_ENUM("Line In 1 Source", linsw1_sel1_enum),
};
static const struct snd_soc_dapm_widget evea_widgets[] = {
SND_SOC_DAPM_ADC("ADC", NULL, SND_SOC_NOPM, 0, 0),
SND_SOC_DAPM_MUX("Line In 1 Mux", SND_SOC_NOPM, 0, 0, linesw1_mux),
SND_SOC_DAPM_INPUT("LIN1_LP"),
SND_SOC_DAPM_INPUT("LIN1_RP"),
SND_SOC_DAPM_INPUT("LIN2_LP"),
SND_SOC_DAPM_INPUT("LIN2_RP"),
SND_SOC_DAPM_INPUT("LIN3_LP"),
SND_SOC_DAPM_INPUT("LIN3_RP"),
SND_SOC_DAPM_DAC("DAC HP", NULL, SND_SOC_NOPM, 0, 0),
SND_SOC_DAPM_DAC("DAC LO1", NULL, SND_SOC_NOPM, 0, 0),
SND_SOC_DAPM_DAC("DAC LO2", NULL, SND_SOC_NOPM, 0, 0),
SND_SOC_DAPM_OUTPUT("HP1_L"),
SND_SOC_DAPM_OUTPUT("HP1_R"),
SND_SOC_DAPM_OUTPUT("LO2_L"),
SND_SOC_DAPM_OUTPUT("LO2_R"),
};
static const struct snd_soc_dapm_route evea_routes[] = {
{ "Line In 1", NULL, "ADC" },
{ "ADC", NULL, "Line In 1 Mux" },
{ "Line In 1 Mux", "LIN1", "LIN1_LP" },
{ "Line In 1 Mux", "LIN1", "LIN1_RP" },
{ "Line In 1 Mux", "LIN2", "LIN2_LP" },
{ "Line In 1 Mux", "LIN2", "LIN2_RP" },
{ "Line In 1 Mux", "LIN3", "LIN3_LP" },
{ "Line In 1 Mux", "LIN3", "LIN3_RP" },
{ "DAC HP", NULL, "Headphone 1" },
{ "DAC LO1", NULL, "Line Out 1" },
{ "DAC LO2", NULL, "Line Out 2" },
{ "HP1_L", NULL, "DAC HP" },
{ "HP1_R", NULL, "DAC HP" },
{ "LO2_L", NULL, "DAC LO2" },
{ "LO2_R", NULL, "DAC LO2" },
};
static void evea_set_power_state_on(struct evea_priv *evea)
{
struct regmap *map = evea->regmap;
regmap_update_bits(map, AANAPOW, AANAPOW_A_POWD,
AANAPOW_A_POWD);
regmap_update_bits(map, ADAC1ODC, ADAC1ODC_HP_DIS_RES_MASK,
ADAC1ODC_HP_DIS_RES_ON);
regmap_update_bits(map, ADAC1ODC, ADAC1ODC_ADAC_RAMPCLT_MASK,
ADAC1ODC_ADAC_RAMPCLT_REDUCE);
regmap_update_bits(map, ADACSEQ2(0), ADACSEQ2_ADACIN_FIX, 0);
regmap_update_bits(map, ADACSEQ2(1), ADACSEQ2_ADACIN_FIX, 0);
regmap_update_bits(map, ADACSEQ2(2), ADACSEQ2_ADACIN_FIX, 0);
}
static void evea_set_power_state_off(struct evea_priv *evea)
{
struct regmap *map = evea->regmap;
regmap_update_bits(map, ADAC1ODC, ADAC1ODC_HP_DIS_RES_MASK,
ADAC1ODC_HP_DIS_RES_ON);
regmap_update_bits(map, ADACSEQ1(0), ADACSEQ1_MMUTE,
ADACSEQ1_MMUTE);
regmap_update_bits(map, ADACSEQ1(1), ADACSEQ1_MMUTE,
ADACSEQ1_MMUTE);
regmap_update_bits(map, ADACSEQ1(2), ADACSEQ1_MMUTE,
ADACSEQ1_MMUTE);
regmap_update_bits(map, ALO1OUTPOW, ALO1OUTPOW_LO1_ON, 0);
regmap_update_bits(map, ALO2OUTPOW, ALO2OUTPOW_LO2_ON, 0);
regmap_update_bits(map, AHPOUTPOW, AHPOUTPOW_HP_ON, 0);
}
static int evea_update_switch_lin(struct evea_priv *evea)
{
struct regmap *map = evea->regmap;
if (evea->switch_lin) {
regmap_update_bits(map, ALINEPOW,
ALINEPOW_LIN2_POWD | ALINEPOW_LIN1_POWD,
ALINEPOW_LIN2_POWD | ALINEPOW_LIN1_POWD);
regmap_update_bits(map, AADCPOW(0), AADCPOW_AADC_POWD,
AADCPOW_AADC_POWD);
regmap_update_bits(map, AADCPOW(1), AADCPOW_AADC_POWD,
AADCPOW_AADC_POWD);
} else {
regmap_update_bits(map, AADCPOW(0), AADCPOW_AADC_POWD, 0);
regmap_update_bits(map, AADCPOW(1), AADCPOW_AADC_POWD, 0);
regmap_update_bits(map, ALINEPOW,
ALINEPOW_LIN2_POWD | ALINEPOW_LIN1_POWD, 0);
}
return 0;
}
static int evea_update_switch_lo(struct evea_priv *evea)
{
struct regmap *map = evea->regmap;
if (evea->switch_lo) {
regmap_update_bits(map, ADACSEQ1(0), ADACSEQ1_MMUTE, 0);
regmap_update_bits(map, ADACSEQ1(2), ADACSEQ1_MMUTE, 0);
regmap_update_bits(map, ALO1OUTPOW, ALO1OUTPOW_LO1_ON,
ALO1OUTPOW_LO1_ON);
regmap_update_bits(map, ALO2OUTPOW,
ALO2OUTPOW_ADAC2_MUTE | ALO2OUTPOW_LO2_ON,
ALO2OUTPOW_ADAC2_MUTE | ALO2OUTPOW_LO2_ON);
} else {
regmap_update_bits(map, ADACSEQ1(0), ADACSEQ1_MMUTE,
ADACSEQ1_MMUTE);
regmap_update_bits(map, ADACSEQ1(2), ADACSEQ1_MMUTE,
ADACSEQ1_MMUTE);
regmap_update_bits(map, ALO1OUTPOW, ALO1OUTPOW_LO1_ON, 0);
regmap_update_bits(map, ALO2OUTPOW,
ALO2OUTPOW_ADAC2_MUTE | ALO2OUTPOW_LO2_ON,
0);
}
return 0;
}
static int evea_update_switch_hp(struct evea_priv *evea)
{
struct regmap *map = evea->regmap;
if (evea->switch_hp) {
regmap_update_bits(map, ADACSEQ1(1), ADACSEQ1_MMUTE, 0);
regmap_update_bits(map, AHPOUTPOW, AHPOUTPOW_HP_ON,
AHPOUTPOW_HP_ON);
regmap_update_bits(map, ADAC1ODC, ADAC1ODC_HP_DIS_RES_MASK,
ADAC1ODC_HP_DIS_RES_OFF);
} else {
regmap_update_bits(map, ADAC1ODC, ADAC1ODC_HP_DIS_RES_MASK,
ADAC1ODC_HP_DIS_RES_ON);
regmap_update_bits(map, ADACSEQ1(1), ADACSEQ1_MMUTE,
ADACSEQ1_MMUTE);
regmap_update_bits(map, AHPOUTPOW, AHPOUTPOW_HP_ON, 0);
}
return 0;
}
static void evea_update_switch_all(struct evea_priv *evea)
{
evea_update_switch_lin(evea);
evea_update_switch_lo(evea);
evea_update_switch_hp(evea);
}
static int evea_get_switch_lin
|