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
|
// 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(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol)
{
struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
struct evea_priv *evea = snd_soc_component_get_drvdata(component);
ucontrol->value.integer.value[0] = evea->switch_lin;
return 0;
}
static int evea_set_switch_lin(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol)
{
struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
struct evea_priv *evea = snd_soc_component_get_drvdata(component);
if (evea->switch_lin == ucontrol->value.integer.value[0])
return 0;
evea->switch_lin = ucontrol->value.integer.value[0];
return evea_update_switch_lin(evea);
}
static int evea_get_switch_lo(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol)
{
struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
struct evea_priv *evea = snd_soc_component_get_drvdata(component);
ucontrol->value.integer.value[0] = evea->switch_lo;
return 0;
}
static int evea_set_switch_lo(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol)
{
struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
struct evea_priv *evea = snd_soc_component_get_drvdata(component);
if (evea->switch_lo == ucontrol->value.integer.value[0])
return 0;
evea->switch_lo = ucontrol->value.integer.value[0];
return evea_update_switch_lo(evea);
}
static int evea_get_switch_hp(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol)
{
struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
struct evea_priv *evea = snd_soc_component_get_drvdata(component);
ucontrol->value.integer.value[0] = evea->switch_hp;
return 0;
}
static int evea_set_switch_hp(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol)
{
struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
struct evea_priv *evea = snd_soc_component_get_drvdata(component);
if (evea->switch_hp == ucontrol->value.integer.value[0])
return 0;
evea->switch_hp = ucontrol->value.integer.value[0];
return evea_update_switch_hp(evea);
}
static const struct snd_kcontrol_new evea_controls[] = {
SOC_SINGLE_BOOL_EXT("Line Capture Switch", 0,
evea_get_switch_lin, evea_set_switch_lin),
SOC_SINGLE_BOOL_EXT("Line Playback Switch", 0,
evea_get_switch_lo, evea_set_switch_lo),
SOC_SINGLE_BOOL_EXT("Headphone Playback Switch", 0,
evea_get_switch_hp, evea_set_switch_hp),
};
static int evea_codec_probe(struct snd_soc_component *component)
{
struct evea_priv *evea = snd_soc_component_get_drvdata(component);
evea->switch_lin = 1;
evea->switch_lo = 1;
evea->switch_hp = 1;
evea_set_power_state_on(evea);
evea_update_switch_all(evea);
return 0;
}
static int evea_codec_suspend(struct snd_soc_component *component)
{
struct evea_priv *evea = snd_soc_component_get_drvdata(component);
evea_set_power_state_off(evea);
reset_control_assert(evea->rst_adamv);
reset_control_assert(evea->rst_exiv);
reset_control_assert(evea->rst);
clk_disable_unprepare(evea->clk_exiv);
clk_disable_unprepare(evea->clk);
return 0;
}
static int evea_codec_resume(struct snd_soc_component *component)
{
struct evea_priv *evea = snd_soc_component_get_drvdata(component);
int ret;
ret = clk_prepare_enable(evea->clk);
if (ret)
return ret;
ret = clk_prepare_enable(evea->clk_exiv);
if (ret)
goto err_out_clock;
ret = reset_control_deassert(evea->rst);
if (ret)
goto err_out_clock_exiv;
ret = reset_control_deassert(evea->rst_exiv);
if (ret)
goto err_out_reset;
ret = reset_control_deassert(evea->rst_adamv);
if (ret)
goto err_out_reset_exiv;
evea_set_power_state_on(evea);
evea_update_switch_all(evea);
return 0;
err_out_reset_exiv:
reset_control_assert(evea->rst_exiv);
err_out_reset:
reset_control_assert(evea->rst);
err_out_clock_exiv:
clk_disable_unprepare(evea->clk_exiv);
err_out_clock:
clk_disable_unprepare(evea->clk);
return ret;
}
static const struct snd_soc_component_driver soc_codec_evea = {
.probe = evea_codec_probe,
.suspend = evea_codec_suspend,
.resume = evea_codec_resume,
.dapm_widgets = evea_widgets,
.num_dapm_widgets = ARRAY_SIZE(evea_widgets),
.dapm_routes = evea_routes,
.num_dapm_routes = ARRAY_SIZE(evea_routes),
.controls = evea_controls,
.num_controls = ARRAY_SIZE(evea_controls),
.idle_bias_on = 1,
.use_pmdown_time = 1,
.endianness = 1,
};
static struct snd_soc_dai_driver soc_dai_evea[] = {
{
.name = DRV_NAME "-line1",
.playback = {
.stream_name = "Line Out 1",
.formats = EVEA_FORMATS,
.rates = EVEA_RATES,
.channels_min = 2,
.channels_max = 2,
},
.capture = {
.stream_name = "Line In 1",
.formats = EVEA_FORMATS,
.rates = EVEA_RATES,
.channels_min = 2,
.channels_max = 2,
},
},
{
.name = DRV_NAME "-hp1",
.playback = {
.stream_name = "Headphone 1",
.formats = EVEA_FORMATS,
.rates = EVEA_RATES,
.channels_min = 2,
.channels_max = 2,
},
},
{
.name = DRV_NAME "-lo2",
.playback = {
.stream_name = "Line Out 2",
.formats = EVEA_FORMATS,
.rates = EVEA_RATES,
.channels_min = 2,
.channels_max = 2,
},
},
};
static const struct regmap_config evea_regmap_config = {
.reg_bits = 32,
.reg_stride = 4,
.val_bits = 32,
.max_register = 0xffc,
.cache_type = REGCACHE_NONE,
};
static int evea_probe(struct platform_device *pdev)
{
struct evea_priv *evea;
void __iomem *preg;
int ret;
evea = devm_kzalloc(&pdev->dev, sizeof(struct evea_priv), GFP_KERNEL);
if (!evea)
return -ENOMEM;
evea->clk = devm_clk_get(&pdev->dev, "evea");
if (IS_ERR(evea->clk))
return PTR_ERR(evea->clk);
evea->clk_exiv = devm_clk_get(&pdev->dev, "exiv");
if (IS_ERR(evea->clk_exiv))
return PTR_ERR(evea->clk_exiv);
evea->rst = devm_reset_control_get_shared(&pdev->dev, "evea");
if (IS_ERR(evea->rst))
return PTR_ERR(evea->rst);
evea->rst_exiv = devm_reset_control_get_shared(&pdev->dev, "exiv");
if (IS_ERR(evea->rst_exiv))
return PTR_ERR(evea->rst_exiv);
preg = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(preg))
return PTR_ERR(preg);
evea->regmap = devm_regmap_init_mmio(&pdev->dev, preg,
&evea_regmap_config);
if (IS_ERR(evea->regmap))
return PTR_ERR(evea->regmap);
ret = clk_prepare_enable(evea->clk);
if (ret)
return ret;
ret = clk_prepare_enable(evea->clk_exiv);
if (ret)
goto err_out_clock;
ret = reset_control_deassert(evea->rst);
if (ret)
goto err_out_clock_exiv;
ret = reset_control_deassert(evea->rst_exiv);
if (ret)
goto err_out_reset;
/* ADAMV will hangup if EXIV reset is asserted */
evea->rst_adamv = devm_reset_control_get_shared(&pdev->dev, "adamv");
if (IS_ERR(evea->rst_adamv)) {
ret = PTR_ERR(evea->rst_adamv);
goto err_out_reset_exiv;
}
ret = reset_control_deassert(evea->rst_adamv);
if (ret)
goto err_out_reset_exiv;
platform_set_drvdata(pdev, evea);
ret = devm_snd_soc_register_component(&pdev->dev, &soc_codec_evea,
soc_dai_evea, ARRAY_SIZE(soc_dai_evea));
if (ret)
goto err_out_reset_adamv;
return 0;
err_out_reset_adamv:
reset_control_assert(evea->rst_adamv);
err_out_reset_exiv:
reset_control_assert(evea->rst_exiv);
err_out_reset:
reset_control_assert(evea->rst);
err_out_clock_exiv:
clk_disable_unprepare(evea->clk_exiv);
err_out_clock:
clk_disable_unprepare(evea->clk);
return ret;
}
static void evea_remove(struct platform_device *pdev)
{
struct evea_priv *evea = platform_get_drvdata(pdev);
reset_control_assert(evea->rst_adamv);
reset_control_assert(evea->rst_exiv);
reset_control_assert(evea->rst);
clk_disable_unprepare(evea->clk_exiv);
clk_disable_unprepare(evea->clk);
}
static const struct of_device_id evea_of_match[] __maybe_unused = {
{ .compatible = "socionext,uniphier-evea", },
{}
};
MODULE_DEVICE_TABLE(of, evea_of_match);
static struct platform_driver evea_codec_driver = {
.driver = {
.name = DRV_NAME,
.of_match_table = of_match_ptr(evea_of_match),
},
.probe = evea_probe,
.remove = evea_remove,
};
module_platform_driver(evea_codec_driver);
MODULE_AUTHOR("Katsuhiro Suzuki <suzuki.katsuhiro@socionext.com>");
MODULE_DESCRIPTION("UniPhier EVEA codec driver");
MODULE_LICENSE("GPL v2");
|