bcm27xx: add support for linux v5.15
[openwrt/staging/chunkeey.git] / target / linux / bcm27xx / patches-5.15 / 950-0084-Add-support-for-all-the-downstream-rpi-sound-card-dr.patch
1 From ee4cf9296b88a4c40b1b8a41a159a587585b2414 Mon Sep 17 00:00:00 2001
2 From: Florian Meier <florian.meier@koalo.de>
3 Date: Mon, 25 Jan 2016 15:48:59 +0000
4 Subject: [PATCH] Add support for all the downstream rpi sound card
5 drivers
6 MIME-Version: 1.0
7 Content-Type: text/plain; charset=UTF-8
8 Content-Transfer-Encoding: 8bit
9
10 ASoC: Add support for Rpi-DAC
11
12 ASoC: Add prompt for ICS43432 codec
13
14 Without a prompt string, a config setting can't be included in a
15 defconfig. Give CONFIG_SND_SOC_ICS43432 a prompt so that Pi soundcards
16 can use the driver.
17
18 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
19
20 Add IQaudIO Sound Card support for Raspberry Pi
21
22 Set a limit of 0dB on Digital Volume Control
23
24 The main volume control in the PCM512x DAC has a range up to
25 +24dB. This is dangerously loud and can potentially cause massive
26 clipping in the output stages. Therefore this sets a sensible
27 limit of 0dB for this control.
28
29 Allow up to 24dB digital gain to be applied when using IQAudIO DAC+
30
31 24db_digital_gain DT param can be used to specify that PCM512x
32 codec "Digital" volume control should not be limited to 0dB gain,
33 and if specified will allow the full 24dB gain.
34
35 Modify IQAudIO DAC+ ASoC driver to set card/dai config from dt
36
37 Add the ability to set the card name, dai name and dai stream name, from
38 dt config.
39
40 Signed-off-by: DigitalDreamtime <clive.messer@digitaldreamtime.co.uk>
41
42 IQaudIO: auto-mute for AMP+ and DigiAMP+
43
44 IQAudIO amplifier mute via GPIO22. Add dt params for "one-shot" unmute
45 and auto mute.
46
47 Revision 2, auto mute implementing HiassofT suggestion to mute/unmute
48 using set_bias_level, rather than startup/shutdown....
49 "By default DAPM waits 5 seconds (pmdown_time) before shutting down
50 playback streams so a close/stop immediately followed by open/start
51 doesn't trigger an amp mute+unmute."
52
53 Tested on both AMP+ (via DAC+) and DigiAMP+, with both options...
54
55 dtoverlay=iqaudio-dacplus,unmute_amp
56 "one-shot" unmute when kernel module loads.
57
58 dtoverlay=iqaudio-dacplus,auto_mute_amp
59 Unmute amp when ALSA device opened by a client. Mute, with 5 second delay
60 when ALSA device closed. (Re-opening the device within the 5 second close
61 window, will cancel mute.)
62
63 Revision 4, using gpiod.
64
65 Revision 5, clean-up formatting before adding mute code.
66 - Convert tab plus 4 space formatting to 2x tab
67 - Remove '// NOT USED' commented code
68
69 Revision 6, don't attempt to "one-shot" unmute amp, unless card is
70 successfully registered.
71
72 Signed-off-by: DigitalDreamtime <clive.messer@digitaldreamtime.co.uk>
73
74 ASoC: iqaudio-dac: fix S24_LE format
75
76 Remove set_bclk_ratio call so 24-bit data is transmitted in
77 24 bclk cycles.
78
79 Signed-off-by: Matthias Reichl <hias@horus.com>
80
81 ASoC: iqaudio-dac: use modern dai_link style
82
83 Signed-off-by: Matthias Reichl <hias@horus.com>
84
85 Added support for HiFiBerry DAC+
86
87 The driver is based on the HiFiBerry DAC driver. However HiFiBerry DAC+ uses
88 a different codec chip (PCM5122), therefore a new driver is necessary.
89
90 Add support for the HiFiBerry DAC+ Pro.
91
92 The HiFiBerry DAC+ and DAC+ Pro products both use the existing bcm sound driver with the DAC+ Pro having a special clock device driver representing the two high precision oscillators.
93
94 An addition bug fix is included for the PCM512x codec where by the physical size of the sample frame is used in the calculation of the LRCK divisor as it was found to be wrong when using 24-bit depth sample contained in a little endian 4-byte sample frame.
95
96 Limit PCM512x "Digital" gain to 0dB by default with HiFiBerry DAC+
97
98 24db_digital_gain DT param can be used to specify that PCM512x
99 codec "Digital" volume control should not be limited to 0dB gain,
100 and if specified will allow the full 24dB gain.
101
102 Add dt param to force HiFiBerry DAC+ Pro into slave mode
103
104 "dtoverlay=hifiberry-dacplus,slave"
105
106 Add 'slave' param to use HiFiBerry DAC+ Pro in slave mode,
107 with Pi as master for bit and frame clock.
108
109 Signed-off-by: DigitalDreamtime <clive.messer@digitaldreamtime.co.uk>
110
111 Fixed a bug when using 352.8kHz sample rate
112
113 Signed-off-by: Daniel Matuschek <daniel@hifiberry.com>
114
115 ASoC: pcm512x: revert downstream changes
116
117 This partially reverts commit 185ea05465aac8bf02a0d2b2f4289d42c72870b7
118 which was added by https://github.com/raspberrypi/linux/pull/1152
119
120 The downstream pcm512x changes caused a regression, it broke normal
121 use of the 24bit format with the codec, eg when using simple-audio-card.
122
123 The actual bug with 24bit playback is the incorrect usage
124 of physical_width in various drivers in the downstream tree
125 which causes 24bit data to be transmitted with 32 clock
126 cycles. So it's not the pcm512x that needs fixing, it's the
127 soundcard drivers.
128
129 Signed-off-by: Matthias Reichl <hias@horus.com>
130
131 ASoC: hifiberry_dacplus: fix S24_LE format
132
133 Remove set_bclk_ratio call so 24-bit data is transmitted in
134 24 bclk cycles.
135
136 Signed-off-by: Matthias Reichl <hias@horus.com>
137
138 ASoC: hifiberry_dacplus: transmit S24_LE with 64 BCLK cycles
139
140 Signed-off-by: Matthias Reichl <hias@horus.com>
141
142 hifiberry_dacplus: switch to snd_soc_dai_set_bclk_ratio
143
144 Signed-off-by: Matthias Reichl <hias@horus.com>
145
146 ASoC: hifiberry_dacplus: use modern dai_link style
147
148 Signed-off-by: Hui Wang <hui.wang@canonical.com>
149
150 Add driver for rpi-proto
151
152 Forward port of 3.10.x driver from https://github.com/koalo
153 We are using a custom board and would like to use rpi 3.18.x
154 kernel. Patch works fine for our embedded system.
155
156 URL to the audio chip:
157 http://www.mikroe.com/add-on-boards/audio-voice/audio-codec-proto/
158
159 Playback tested with devicetree enabled.
160
161 Signed-off-by: Waldemar Brodkorb <wbrodkorb@conet.de>
162
163 ASoC: rpi-proto: use modern dai_link style
164
165 Signed-off-by: Hui Wang <hui.wang@canonical.com>
166
167 Add Support for JustBoom Audio boards
168
169 justboom-dac: Adjust for ALSA API change
170
171 As of 4.4, snd_soc_limit_volume now takes a struct snd_soc_card *
172 rather than a struct snd_soc_codec *.
173
174 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
175
176 ASoC: justboom-dac: fix S24_LE format
177
178 Remove set_bclk_ratio call so 24-bit data is transmitted in
179 24 bclk cycles.
180
181 Also remove hw_params as it's no longer needed.
182
183 Signed-off-by: Matthias Reichl <hias@horus.com>
184
185 ASoC: justboom-dac: use modern dai_link style
186
187 Signed-off-by: Matthias Reichl <hias@horus.com>
188
189 New AudioInjector.net Pi soundcard with low jitter audio in and out.
190
191 Contains the sound/soc/bcm ALSA machine driver and necessary alterations to the Kconfig and Makefile.
192 Adds the dts overlay and updates the Makefile and README.
193 Updates the relevant defconfig files to enable building for the Raspberry Pi.
194 Thanks to Phil Elwell (pelwell) for the review, simple-card concepts and discussion. Thanks to Clive Messer for overlay naming suggestions.
195
196 Added support for headphones, microphone and bclk_ratio settings.
197
198 This patch adds headphone and microphone capability to the Audio Injector sound card. The patch also sets the bit clock ratio for use in the bcm2835-i2s driver. The bcm2835-i2s can't handle an 8 kHz sample rate when the bit clock is at 12 MHz because its register is only 10 bits wide which can't represent the ch2 offset of 1508. For that reason, the rate constraint is added.
199
200 ASoC: audioinjector-pi-soundcard: use modern dai_link style
201
202 Signed-off-by: Hui Wang <hui.wang@canonical.com>
203
204 New driver for RRA DigiDAC1 soundcard using WM8741 + WM8804
205
206 ASoC: digidac1-soundcard: use modern dai_link style
207
208 Signed-off-by: Hui Wang <hui.wang@canonical.com>
209
210 Add support for Dion Audio LOCO DAC-AMP HAT
211
212 Using dedicated machine driver and pcm5102a codec driver.
213
214 Signed-off-by: DigitalDreamtime <clive.messer@digitaldreamtime.co.uk>
215
216 ASoC: dionaudio_loco: use modern dai_link style
217
218 Signed-off-by: Hui Wang <hui.wang@canonical.com>
219
220 Allo Piano DAC boards: Initial 2 channel (stereo) support (#1645)
221
222 Add initial 2 channel (stereo) support for Allo Piano DAC (2.0/2.1) boards,
223 using allo-piano-dac-pcm512x-audio overlay and allo-piano-dac ALSA ASoC
224 machine driver.
225
226 NB. The initial support is 2 channel (stereo) ONLY!
227 (The Piano DAC 2.1 will only support 2 channel (stereo) left/right output,
228 pending an update to the upstream pcm512x codec driver, which will have
229 to be submitted via upstream. With the initial downstream support,
230 provided by this patch, the Piano DAC 2.1 subwoofer outputs will
231 not function.)
232
233 Signed-off-by: Baswaraj K <jaikumar@cem-solutions.net>
234 Signed-off-by: Clive Messer <clive.messer@digitaldreamtime.co.uk>
235 Tested-by: Clive Messer <clive.messer@digitaldreamtime.co.uk>
236
237 ASoC: allo-piano-dac: fix S24_LE format
238
239 Remove set_bclk_ratio call so 24-bit data is transmitted in
240 24 bclk cycles.
241
242 Also remove hw_params and ops as they are no longer needed.
243
244 Signed-off-by: Matthias Reichl <hias@horus.com>
245
246 ASoC: allo-piano-dac: use modern dai_link style
247
248 Signed-off-by: Hui Wang <hui.wang@canonical.com>
249
250 Add support for Allo Piano DAC 2.1 plus add-on board for Raspberry Pi.
251
252 The Piano DAC 2.1 has support for 4 channels with subwoofer.
253
254 Signed-off-by: Baswaraj K <jaikumar@cem-solutions.net>
255 Reviewed-by: Vijay Kumar B. <vijaykumar@zilogic.com>
256 Reviewed-by: Raashid Muhammed <raashidmuhammed@zilogic.com>
257
258 Add clock changes and mute gpios (#1938)
259
260 Also improve code style and adhere to ALSA coding conventions.
261
262 Signed-off-by: Baswaraj K <jaikumar@cem-solutions.net>
263 Reviewed-by: Vijay Kumar B. <vijaykumar@zilogic.com>
264 Reviewed-by: Raashid Muhammed <raashidmuhammed@zilogic.com>
265
266 PianoPlus: Dual Mono & Dual Stereo features added (#2069)
267
268 allo-piano-dac-plus: Master volume added + fixes
269
270 Master volume added, which controls both DACs volumes.
271
272 See: https://github.com/raspberrypi/linux/pull/2149
273
274 Also fix initial max volume, default mode value, and unmute.
275
276 Signed-off-by: allocom <sparky-dev@allo.com>
277
278 ASoC: allo-piano-dac-plus: fix S24_LE format
279
280 Remove set_bclk_ratio call so 24-bit data is transmitted in
281 24 bclk cycles.
282
283 Signed-off-by: Matthias Reichl <hias@horus.com>
284
285 sound: bcm: Fix memset dereference warning
286
287 This warning appears with GCC 6.4.0 from toolchains.bootlin.com:
288
289 ../sound/soc/bcm/allo-piano-dac-plus.c: In function ‘snd_allo_piano_dac_init’:
290 ../sound/soc/bcm/allo-piano-dac-plus.c:711:30: warning: argument to ‘sizeof’ in ‘memset’ call is the same expression as the destination; did you mean to dereference it? [-Wsizeof-pointer-memaccess]
291 memset(glb_ptr, 0x00, sizeof(glb_ptr));
292 ^
293
294 Suggested-by: Phil Elwell <phil@raspberrypi.org>
295 Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
296
297 ASoC: allo-piano-dac-plus: use modern dai_link style
298
299 Signed-off-by: Hui Wang <hui.wang@canonical.com>
300
301 Add support for Allo Boss DAC add-on board for Raspberry Pi. (#1924)
302
303 Signed-off-by: Baswaraj K <jaikumar@cem-solutions.net>
304 Reviewed-by: Deepak <deepak@zilogic.com>
305 Reviewed-by: BabuSubashChandar <babusubashchandar@zilogic.com>
306
307 Add support for new clock rate and mute gpios.
308
309 Signed-off-by: Baswaraj K <jaikumar@cem-solutions.net>
310 Reviewed-by: Deepak <deepak@zilogic.com>
311 Reviewed-by: BabuSubashChandar <babusubashchandar@zilogic.com>
312
313 ASoC: allo-boss-dac: fix S24_LE format
314
315 Remove set_bclk_ratio call so 24-bit data is transmitted in
316 24 bclk cycles.
317
318 Signed-off-by: Matthias Reichl <hias@horus.com>
319
320 ASoC: allo-boss-dac: transmit S24_LE with 64 BCLK cycles
321
322 Signed-off-by: Matthias Reichl <hias@horus.com>
323
324 allo-boss-dac: switch to snd_soc_dai_set_bclk_ratio
325
326 Signed-off-by: Matthias Reichl <hias@horus.com>
327
328 ASoC: allo-boss-dac: use modern dai_link style
329
330 Signed-off-by: Hui Wang <hui.wang@canonical.com>
331
332 Support for Blokas Labs pisound board
333
334 Pisound dynamic overlay (#1760)
335
336 Restructuring pisound-overlay.dts, so it can be loaded and unloaded dynamically using dtoverlay.
337
338 Print a logline when the kernel module is removed.
339
340 pisound improvements:
341
342 * Added a writable sysfs object to enable scripts / user space software
343 to blink MIDI activity LEDs for variable duration.
344 * Improved hw_param constraints setting.
345 * Added compatibility with S16_LE sample format.
346 * Exposed some simple placeholder volume controls, so the card appears
347 in volumealsa widget.
348
349 Add missing SND_PISOUND selects dependency to SND_RAWMIDI
350
351 Without it the Pisound module fails to compile.
352 See https://github.com/raspberrypi/linux/issues/2366
353
354 Updates for Pisound module code:
355
356 * Merged 'Fix a warning in DEBUG builds' (1c8b82b).
357 * Updating some strings and copyright information.
358 * Fix for handling high load of MIDI input and output.
359 * Use dual rate oversampling ratio for 96kHz instead of single
360 rate one.
361
362 Signed-off-by: Giedrius Trainavicius <giedrius@blokas.io>
363
364 Fixing memset call in pisound.c
365
366 Signed-off-by: Giedrius Trainavicius <giedrius@blokas.io>
367
368 Fix for Pisound's MIDI Input getting blocked for a while in rare cases.
369
370 There was a possible race condition which could lead to Input's FIFO queue
371 to be underflown, causing high amount of processing in the worker thread for
372 some period of time.
373
374 Signed-off-by: Giedrius Trainavicius <giedrius@blokas.io>
375
376 Fix for Pisound kernel module in Real Time kernel configuration.
377
378 When handler of data_available interrupt is fired, queue_work ends up
379 getting called and it can block on a spin lock which is not allowed in
380 interrupt context. The fix was to run the handler from a thread context
381 instead.
382
383 Pisound: Remove spinlock usage around spi_sync
384
385 ASoC: pisound: use modern dai_link style
386
387 Signed-off-by: Hui Wang <hui.wang@canonical.com>
388
389 ASoC: pisound: fix the parameter for spi_device_match
390
391 Signed-off-by: Hui Wang <hui.wang@canonical.com>
392
393 ASoC: Add driver for Cirrus Logic Audio Card
394
395 Note: due to problems with deferred probing of regulators
396 the following softdep should be added to a modprobe.d file
397
398 softdep arizona-spi pre: arizona-ldo1
399
400 Signed-off-by: Matthias Reichl <hias@horus.com>
401
402 ASoC: rpi-cirrus: use modern dai_link style
403
404 Signed-off-by: Matthias Reichl <hias@horus.com>
405
406 sound: Support for Dion Audio LOCO-V2 DAC-AMP HAT
407
408 Signed-off-by: Miquel Blauw <info@dionaudio.nl>
409
410 ASoC: dionaudio_loco-v2: fix S24_LE format
411
412 Remove set_bclk_ratio call so 24-bit data is transmitted in
413 24 bclk cycles.
414
415 Also remove hw_params and ops as they are no longer needed.
416
417 Signed-off-by: Matthias Reichl <hias@horus.com>
418
419 ASoC: dionaudio_loco-v2: use modern dai_link style
420
421 Signed-off-by: Hui Wang <hui.wang@canonical.com>
422
423 Add support for Fe-Pi audio sound card. (#1867)
424
425 Fe-Pi Audio Sound Card is based on NXP SGTL5000 codec.
426 Mechanical specification of the board is the same the Raspberry Pi Zero.
427 3.5mm jacks for Headphone/Mic, Line In, and Line Out.
428
429 Signed-off-by: Henry Kupis <fe-pi@cox.net>
430
431 ASoC: fe-pi-audio: use modern dai_link style
432
433 Signed-off-by: Hui Wang <hui.wang@canonical.com>
434
435 Add support for the AudioInjector.net Octo sound card
436
437 AudioInjector Octo: sample rates, regulators, reset
438
439 This patch adds new sample rates to the Audioinjector Octo sound card. The
440 new supported rates are (in kHz) :
441 96, 48, 32, 24, 16, 8, 88.2, 44.1, 29.4, 22.05, 14.7
442
443 Reference the bcm270x DT regulators in the overlay.
444
445 This patch adds a reset GPIO for the AudioInjector.net octo sound card.
446
447 Audioinjector octo : Make the playback and capture symmetric
448
449 This patch ensures that the sample rate and channel count of the audioinjector
450 octo sound card are symmetric.
451
452 audioinjector-octo: Add continuous clock feature
453
454 By user request, add a switch to prevent the clocks being stopped when
455 the stream is paused, stopped or shutdown. Provide access to the switch
456 by adding a 'non-stop-clocks' parameter to the audioinjector-addons
457 overlay.
458
459 See: https://github.com/raspberrypi/linux/issues/2409
460
461 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
462
463 sound: Fixes for audioinjector-octo under 4.19
464
465 1. Move the DT alias declaration to the I2C shim in the cases
466 where the shim is enabled. This works around a problem caused by a
467 4.19 commit [1] that generates DT/OF uevents for I2C drivers.
468
469 2. Fix the diagnostics in an error path of the soundcard driver to
470 correctly identify the reason for the failure to load.
471
472 3. Move the declaration of the clock node in the overlay outside
473 the I2C node to avoid warnings.
474
475 4. Sort the overlay nodes so that dependencies are only to earlier
476 fragments, in an attempt to get runtime dtoverlay application to
477 work (it still doesn't...)
478
479 See: https://github.com/Audio-Injector/Octo/issues/14
480 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
481
482 [1] af503716ac14 ("i2c: core: report OF style module alias for devices registered via OF")
483
484 ASoC: audioinjector-octo-soundcard: use modern dai_link style
485
486 Signed-off-by: Hui Wang <hui.wang@canonical.com>
487
488 Driver support for Google voiceHAT soundcard.
489
490 ASoC: googlevoicehat-codec: Use correct device when grabbing GPIO
491
492 The fixup for the VoiceHAT in 4.18 incorrectly tried to find the
493 sdmode GPIO pin under the card device, not the codec device.
494 This failed, and therefore caused the device probe to fail.
495
496 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
497
498 ASoC: googlevoicehat-codec: Reformat for kernel coding standards
499
500 Fix all whitespace, indentation, and bracing errors.
501
502 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
503
504 ASoC: googlevoicehat-codec: Make driver function structure const
505
506 Make voicehat_component_driver a const structure.
507
508 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
509
510 ASoC: googlevoicehat-codec: Only convert from ms to jiffies once
511
512 Minor optimisation and allows to become checkpatch clean.
513 A msec value is read out of DT or from a define, and convert once to
514 jiffies, rather than every time that it is used.
515
516 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
517
518 Driver and overlay for Allo Katana DAC
519
520 Allo Katana DAC: Updated default values
521
522 Signed-off-by: Jaikumar <jaikumar@cem-solutions.com>
523
524 Added mute stream func
525
526 Signed-off-by: Jaikumar <jaikumar@cem-solutions.net>
527
528 codecs: Correct Katana minimum volume
529
530 Update Katana minimum volume to get the exact 0.5 dB value in each step.
531
532 Signed-off-by: Sudeep Kumar <sudeepkumar@cem-solutions.net>
533
534 ASoC: Add generic RPI driver for simple soundcards.
535
536 The RPI simple sound card driver provides a generic ALSA SOC card driver
537 supporting a variety of Pi HAT soundcards. The intention is to avoid
538 the duplication of code for cards that can't be fully supported by
539 the soc simple/graph cards but are otherwise almost identical.
540
541 This initial commit adds support for the ADAU1977 ADC, Google VoiceHat,
542 HifiBerry AMP, HifiBerry DAC and RPI DAC.
543
544 Signed-off-by: Tim Gover <tim.gover@raspberrypi.org>
545
546 ASoC: Use correct card name in rpi-simple driver
547
548 Use the specific card name from drvdata instead of the snd_rpi_simple
549
550 rpi-simple-soundcard: Use nicer driver name "RPi-simple"
551
552 Rename the driver from "RPI simple soundcard" to "RPi-simple" so that
553 the driver name won't be mangled allowing to be used unaltered as the
554 card conf filename.
555
556 ASoC: rpi-simple-soundcard: use modern dai_link style
557
558 Signed-off-by: Hui Wang <hui.wang@canonical.com>
559
560 ASoC: Add Kconfig and Makefile for sound/soc/bcm
561
562 Signed-off-by: popcornmix <popcornmix@gmail.com>
563
564 ASoC: Create a generic Pi Hat WM8804 driver
565
566 Reduce the amount of duplicated code by creating a generic driver for
567 Pi Hat digi cards using the WM8804 codec.
568
569 This replaces the
570 Allo DigiOne, Hifiberry Digi/Pro, JustBoom Digi and IQAudIO Digi
571 dedicate soundcard drivers with a generic driver.
572
573 There are no significant changes to the runtime behavior of the drivers
574 and end users should not have to change any configuration settings
575 after upgrading.
576
577 Minor changes
578 * Check the return value of snd_soc_component_update_bits
579 * Added some pr_debug tracing
580 * Various checkpatch tidyups
581 * Updated allodigi-one to use use 128FS at > 96 Khz. This appears to
582 be an omission in the original driver code so followed the Hifiberry
583 DAC driver approach.
584
585 ASoC: rpi-wm8804-soundcard: use modern dai_link style
586
587 Signed-off-by: Matthias Reichl <hias@horus.com>
588
589 rpi-wm8804-soundcard: drop PWRDN register writes
590
591 Since kernel 4.0 the PWRDN register bits are under DAPM
592 control from the wm8804 driver.
593
594 Drop code that modifies that register to avoid interfering
595 with DAPM.
596
597 Signed-off-by: Matthias Reichl <hias@horus.com>
598
599 rpi-wm8804-soundcard: configure wm8804 clocks only on rate change
600
601 This should avoid clicks when stopping and immediately afterwards
602 starting a stream with the same samplerate as before.
603
604 Signed-off-by: Matthias Reichl <hias@horus.com>
605
606 rpi-wm8804-soundcard: Fixed MCLKDIV for Allo Digione
607
608 The Allo Digione board wants a fixed MCLKDIV of 256.
609
610 See: https://github.com/raspberrypi/linux/issues/3296
611
612 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
613
614 ASoC: Add support for AudioSense-Pi add-on soundcard
615
616 AudioSense-Pi is a RPi HAT based on a TI's TLV320AIC32x4 stereo codec
617
618 This hardware provides multiple audio I/O capabilities to the RPi.
619 The codec connects to the RPi's SoC through the I2S Bus.
620
621 The following devices can be connected through a 3.5mm jack
622 1. Line-In: Plain old audio in from mobile phones, PCs, etc.,
623 2. Mic-In: Connect a microphone
624 3. Line-Out: Connect the output to a speaker
625 4. Headphones: Connect a Headphone w or w/o microphones
626
627 Multiple Inputs:
628 It supports the following combinations
629 1. Two stereo Line-Inputs and a microphone
630 2. One stereo Line-Input and two microphones
631 3. Two stereo Line-Inputs, a microphone and
632 one mono line-input (with h/w hack)
633 4. One stereo Line-Input, two microphones and
634 one mono line-input (with h/w hack)
635
636 Multiple Outputs:
637 Audio output can be routed to the headphones or
638 speakers (with additional hardware)
639
640 Signed-off-by: b-ak <anur.bhargav@gmail.com>
641
642 ASoC: audiosense-pi: use modern dai_link style
643
644 Signed-off-by: Hui Wang <hui.wang@canonical.com>
645
646 Added driver for the HiFiBerry DAC+ ADC (#2694)
647
648 Signed-off-by: Daniel Matuschek <daniel@hifiberry.com>
649
650 hifiberry_dacplusadc: switch to snd_soc_dai_set_bclk_ratio
651
652 Signed-off-by: Matthias Reichl <hias@horus.com>
653
654 ASoC: hifiberry_dacplusadc: fix DAI link setup
655
656 The driver only defines a single DAI link and the code that tries
657 to setup the second (non-existent) DAI link looks wrong - using dmic
658 as a CPU/platform driver doesn't make any sense.
659
660 The DT overlay doesn't define a dmic property, so the code was never
661 executed (otherwise it would have resulted in a memory corruption).
662
663 So drop the offending code to prevent issues if a dmic property
664 should be added to the DT overlay.
665
666 Signed-off-by: Matthias Reichl <hias@horus.com>
667
668 ASoC: hifiberry_dacplusadc: use modern dai_link style
669
670 Signed-off-by: Matthias Reichl <hias@horus.com>
671
672 Audiophonics I-Sabre 9038Q2M DAC driver
673
674 Signed-off-by: Audiophonics <contact@audiophonics.fr>
675
676 ASoC: i-sabre-q2m: use modern dai_link style
677
678 Signed-off-by: Hui Wang <hui.wang@canonical.com>
679
680 Added IQaudIO Pi-Codec board support (#2969)
681
682 Add support for the IQaudIO Pi-Codec board.
683
684 Signed-off-by: Gordon <gordon@iqaudio.com>
685
686 Fixed 48k timing issue
687
688 ASoC: iqaudio-codec: use modern dai_link style
689
690 Signed-off-by: Hui Wang <hui.wang@canonical.com>
691
692 adds the Hifiberry DAC+ADC PRO version
693
694 This adds the driver for the DAC+ADC PRO version of the Hifiberry soundcard with software controlled PCM1863 ADC
695 Signed-off-by: Joerg Schambacher joerg@i2audio.com
696
697 Add Hifiberry DAC+DSP soundcard driver (#3224)
698
699 Adds the driver for the Hifiberry DAC+DSP. It supports capture and
700 playback depending on the DSP firmware.
701
702 Signed-off-by: Joerg Schambacher <joerg@i2audio.com>
703
704 Allow simultaneous use of JustBoom DAC and Digi
705
706 Signed-off-by: Johannes Krude <johannes@krude.de>
707
708 Pisound: MIDI communication fixes for scaled down CPU.
709
710 * Increased maximum SPI communication speed to avoid running too slow
711 when the CPU is scaled down and losing MIDI data.
712
713 * Keep track of buffer usage in millibytes for higher precision.
714
715 Signed-off-by: Giedrius Trainavičius <giedrius@blokas.io>
716
717 sound: Add the HiFiBerry DAC+HD version
718
719 This adds the driver for the DAC+HD version supporting HiFiBerry's
720 PCM179x based DACs. It also adds PLL control for clock generation.
721
722 Signed-off-by: Joerg Schambacher <joerg@i2audio.com>
723
724 Fix master mode settings of HiFiBerry DAC+ADC PRO card (#3424)
725
726 This patch fixes the board DAI setting when in master-mode.
727 Wrong setting could have caused random pop noise.
728
729 Signed-off-by: Joerg Schambacher <joerg@i2audio.com>
730
731 adds LED OFF feature to HiFiBerry DAC+ADC PRO sound card
732
733 This adds a DT overlay parameter 'leds_off' which allows
734 to switch off the onboard activity LEDs at all times
735 which has been requested by some users.
736
737 Signed-off-by: Joerg Schambacher <joerg@i2audio.com>
738
739 adds LED OFF feature to HiFiBerry DAC+ADC sound card
740
741 This adds a DT overlay parameter 'leds_off' which allows
742 to switch off the onboard activity LEDs at all times
743 which has been requested by some users.
744
745 Signed-off-by: Joerg Schambacher <joerg@i2audio.com>
746
747 adds LED OFF feature to HiFiBerry DAC+/DAC+PRO sound cards
748
749 This adds a DT overlay parameter 'leds_off' which allows
750 to switch off the onboard activity LEDs at all times
751 which has been requested by some users.
752
753 Signed-off-by: Joerg Schambacher <joerg@i2audio.com>
754
755 pisound: Added reading Pisound board hardware revision and exposing it (#3425)
756
757 pisound: Added reading Pisound board hardware revision and exposing it in kernel log and sysfs file:
758
759 /sys/kernel/pisound/hw_version
760
761 Signed-off-by: Giedrius <giedrius@blokas.io>
762
763 Added driver for HiFiBerry Amp amplifier add-on board
764
765 The driver contains a low-level hardware driver for the TAS5713 and the
766 drivers for the Raspberry Pi I2S subsystem.
767
768 TAS5713: return error if initialisation fails
769
770 Existing TAS5713 driver logs errors during initialisation, but does not return
771 an error code. Therefore even if initialisation fails, the driver will still be
772 loaded, but won't work. This patch fixes this. I2C communication error will now
773 reported correctly by a non-zero return code.
774
775 HiFiBerry Amp: fix device-tree problems
776
777 Some code to load the driver based on device-tree-overlays was missing. This is added by this patch.
778
779 According to 5713 pdf doc CLOCK_CTRL is a readonly status register, and it behaves so. Remove useless setting
780
781 sound: pcm512x-codec: Adding 352.8kHz samplerate support
782
783 sound/soc: only first codec is master in multicodec setup
784
785 When using multiple codecs, at most one codec should generate the master
786 clock. All codecs except the first are therefore configured for slave
787 mode.
788
789 Signed-off-by: Johannes Krude <johannes@krude.de>
790
791 ASoC: Fix snd_soc_get_pcm_runtime usage
792
793 Commit [1] changed the snd_soc_get_pcm_runtime to take a dai_link
794 pointer instead of a string. Patch up the downstream drivers to use
795 the modified API.
796
797 Signed-off-by: Phil Elwell <phil@raspberrypi.com>
798
799 [1] 4468189ff307 ("ASoC: soc-core: find rtd via dai_link pointer at snd_soc_get_pcm_runtime()")
800
801 Add support for the AudioInjector.net Isolated sound card
802
803 This patch adds support for the Audio Injector Isolated sound card.
804
805 Signed-off-by: Matt Flax <flatmax@flatmax.org>
806
807 Add support for merus-amp soundcard and ma120x0p codec
808
809 Add 96KHz rate support to MA120X0P codec and make enable and mute gpio
810 pins optional.
811
812 Signed-off-by: AMuszkat <ariel.muszkat@gmail.com>
813
814 Fixes a problem with clock settings of HiFiBerry DAC+ADC PRO (#3545)
815
816 This patch fixes a problem of the re-calculation of
817 i2s-clock and -parameter settings when only the ADC is activated.
818
819 Signed-off-by: Joerg Schambacher <joerg@i2audio.com>
820
821 configs: Enable the AD193x codecs
822
823 See: https://github.com/raspberrypi/linux/issues/2850
824
825 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
826
827 Switch to snd_soc_dai_set_bclk_ratio
828 Replaces obsolete function snd_soc_dai_set_tdm_slot
829
830 Signed-off-by: Joerg Schambacher <joerg@i2audio.com>
831
832 Enhances the DAC+ driver to control the optional headphone amplifier
833
834 Probes on the I2C bus for TPA6130A2, if successful, it sets DT-parameter
835 'status' from 'disabled' to 'okay' using change_sets to enable
836 the headphone control.
837
838 Signed-off-by: Joerg Schambacher joerg@i2audio.com
839
840 Update Allo Piano Dac Driver
841
842 Add unique names to the individual dac coded drivers
843 Remove some of the codec controls that are not used.
844
845 Signed-off-by: Paul Hermann <paul@picoreplayer.org>
846
847 Fixes an onboard clock detection problem of the PRO versions
848
849 Increasing the sleep time after clock selection to 3-4ms
850 allows the correct detection of all combinations of DAC+ Pro
851 and DAC+ADC Pro sound cards and the various PI revisions.
852
853 Signed-off-by: Joerg Schambacher <joerg@hifiberry.com>
854 ---
855 .../devicetree/bindings/vendor-prefixes.txt | 463 ++++++
856 .../devicetree/bindings/vendor-prefixes.yaml | 2 +
857 drivers/clk/Kconfig | 6 +
858 drivers/clk/Makefile | 3 +
859 drivers/clk/clk-allo-dac.c | 161 ++
860 drivers/clk/clk-hifiberry-dachd.c | 333 ++++
861 drivers/clk/clk-hifiberry-dacpro.c | 160 ++
862 sound/soc/bcm/Kconfig | 291 ++++
863 sound/soc/bcm/Makefile | 68 +-
864 sound/soc/bcm/allo-boss-dac.c | 456 ++++++
865 sound/soc/bcm/allo-boss2-dac.c | 1133 ++++++++++++++
866 sound/soc/bcm/allo-katana-codec.c | 388 +++++
867 sound/soc/bcm/allo-piano-dac-plus.c | 1063 +++++++++++++
868 sound/soc/bcm/allo-piano-dac.c | 122 ++
869 .../bcm/audioinjector-isolated-soundcard.c | 183 +++
870 sound/soc/bcm/audioinjector-octo-soundcard.c | 346 +++++
871 sound/soc/bcm/audioinjector-pi-soundcard.c | 187 +++
872 sound/soc/bcm/audiosense-pi.c | 248 +++
873 sound/soc/bcm/digidac1-soundcard.c | 421 +++++
874 sound/soc/bcm/dionaudio_loco-v2.c | 117 ++
875 sound/soc/bcm/dionaudio_loco.c | 117 ++
876 sound/soc/bcm/fe-pi-audio.c | 154 ++
877 sound/soc/bcm/googlevoicehat-codec.c | 214 +++
878 sound/soc/bcm/hifiberry_dacplus.c | 527 +++++++
879 sound/soc/bcm/hifiberry_dacplusadc.c | 398 +++++
880 sound/soc/bcm/hifiberry_dacplusadcpro.c | 537 +++++++
881 sound/soc/bcm/hifiberry_dacplusdsp.c | 90 ++
882 sound/soc/bcm/hifiberry_dacplushd.c | 238 +++
883 sound/soc/bcm/i-sabre-q2m.c | 158 ++
884 sound/soc/bcm/iqaudio-codec.c | 274 ++++
885 sound/soc/bcm/iqaudio-dac.c | 223 +++
886 sound/soc/bcm/justboom-both.c | 266 ++++
887 sound/soc/bcm/justboom-dac.c | 147 ++
888 sound/soc/bcm/pifi-40.c | 283 ++++
889 sound/soc/bcm/pisound.c | 1240 +++++++++++++++
890 sound/soc/bcm/rpi-cirrus.c | 1025 ++++++++++++
891 sound/soc/bcm/rpi-proto.c | 147 ++
892 sound/soc/bcm/rpi-simple-soundcard.c | 419 +++++
893 sound/soc/bcm/rpi-wm8804-soundcard.c | 410 +++++
894 sound/soc/codecs/Kconfig | 26 +-
895 sound/soc/codecs/Makefile | 8 +
896 sound/soc/codecs/cs42xx8-i2c.c | 9 +-
897 sound/soc/codecs/cs42xx8.c | 2 +
898 sound/soc/codecs/i-sabre-codec.c | 392 +++++
899 sound/soc/codecs/i-sabre-codec.h | 42 +
900 sound/soc/codecs/ma120x0p.c | 1384 +++++++++++++++++
901 sound/soc/codecs/pcm1794a.c | 69 +
902 sound/soc/codecs/pcm512x.c | 2 +-
903 sound/soc/codecs/tas5713.c | 363 +++++
904 sound/soc/codecs/tas5713.h | 210 +++
905 sound/soc/soc-core.c | 29 +-
906 51 files changed, 15545 insertions(+), 9 deletions(-)
907 create mode 100644 Documentation/devicetree/bindings/vendor-prefixes.txt
908 create mode 100644 drivers/clk/clk-allo-dac.c
909 create mode 100644 drivers/clk/clk-hifiberry-dachd.c
910 create mode 100644 drivers/clk/clk-hifiberry-dacpro.c
911 create mode 100644 sound/soc/bcm/allo-boss-dac.c
912 create mode 100644 sound/soc/bcm/allo-boss2-dac.c
913 create mode 100644 sound/soc/bcm/allo-katana-codec.c
914 create mode 100644 sound/soc/bcm/allo-piano-dac-plus.c
915 create mode 100644 sound/soc/bcm/allo-piano-dac.c
916 create mode 100644 sound/soc/bcm/audioinjector-isolated-soundcard.c
917 create mode 100644 sound/soc/bcm/audioinjector-octo-soundcard.c
918 create mode 100644 sound/soc/bcm/audioinjector-pi-soundcard.c
919 create mode 100644 sound/soc/bcm/audiosense-pi.c
920 create mode 100644 sound/soc/bcm/digidac1-soundcard.c
921 create mode 100644 sound/soc/bcm/dionaudio_loco-v2.c
922 create mode 100644 sound/soc/bcm/dionaudio_loco.c
923 create mode 100644 sound/soc/bcm/fe-pi-audio.c
924 create mode 100644 sound/soc/bcm/googlevoicehat-codec.c
925 create mode 100644 sound/soc/bcm/hifiberry_dacplus.c
926 create mode 100644 sound/soc/bcm/hifiberry_dacplusadc.c
927 create mode 100644 sound/soc/bcm/hifiberry_dacplusadcpro.c
928 create mode 100644 sound/soc/bcm/hifiberry_dacplusdsp.c
929 create mode 100644 sound/soc/bcm/hifiberry_dacplushd.c
930 create mode 100644 sound/soc/bcm/i-sabre-q2m.c
931 create mode 100644 sound/soc/bcm/iqaudio-codec.c
932 create mode 100644 sound/soc/bcm/iqaudio-dac.c
933 create mode 100644 sound/soc/bcm/justboom-both.c
934 create mode 100644 sound/soc/bcm/justboom-dac.c
935 create mode 100644 sound/soc/bcm/pifi-40.c
936 create mode 100644 sound/soc/bcm/pisound.c
937 create mode 100644 sound/soc/bcm/rpi-cirrus.c
938 create mode 100644 sound/soc/bcm/rpi-proto.c
939 create mode 100644 sound/soc/bcm/rpi-simple-soundcard.c
940 create mode 100644 sound/soc/bcm/rpi-wm8804-soundcard.c
941 create mode 100644 sound/soc/codecs/i-sabre-codec.c
942 create mode 100644 sound/soc/codecs/i-sabre-codec.h
943 create mode 100644 sound/soc/codecs/ma120x0p.c
944 create mode 100644 sound/soc/codecs/pcm1794a.c
945 create mode 100644 sound/soc/codecs/tas5713.c
946 create mode 100644 sound/soc/codecs/tas5713.h
947
948 --- /dev/null
949 +++ b/Documentation/devicetree/bindings/vendor-prefixes.txt
950 @@ -0,0 +1,463 @@
951 +Device tree binding vendor prefix registry. Keep list in alphabetical order.
952 +
953 +This isn't an exhaustive list, but you should add new prefixes to it before
954 +using them to avoid name-space collisions.
955 +
956 +abilis Abilis Systems
957 +abracon Abracon Corporation
958 +actions Actions Semiconductor Co., Ltd.
959 +active-semi Active-Semi International Inc
960 +ad Avionic Design GmbH
961 +adafruit Adafruit Industries, LLC
962 +adapteva Adapteva, Inc.
963 +adaptrum Adaptrum, Inc.
964 +adh AD Holdings Plc.
965 +adi Analog Devices, Inc.
966 +advantech Advantech Corporation
967 +aeroflexgaisler Aeroflex Gaisler AB
968 +al Annapurna Labs
969 +allo Allo.com
970 +allwinner Allwinner Technology Co., Ltd.
971 +alphascale AlphaScale Integrated Circuits Systems, Inc.
972 +altr Altera Corp.
973 +amarula Amarula Solutions
974 +amazon Amazon.com, Inc.
975 +amcc Applied Micro Circuits Corporation (APM, formally AMCC)
976 +amd Advanced Micro Devices (AMD), Inc.
977 +amediatech Shenzhen Amediatech Technology Co., Ltd
978 +amlogic Amlogic, Inc.
979 +ampire Ampire Co., Ltd.
980 +ams AMS AG
981 +amstaos AMS-Taos Inc.
982 +analogix Analogix Semiconductor, Inc.
983 +andestech Andes Technology Corporation
984 +apm Applied Micro Circuits Corporation (APM)
985 +aptina Aptina Imaging
986 +arasan Arasan Chip Systems
987 +archermind ArcherMind Technology (Nanjing) Co., Ltd.
988 +arctic Arctic Sand
989 +aries Aries Embedded GmbH
990 +arm ARM Ltd.
991 +armadeus ARMadeus Systems SARL
992 +arrow Arrow Electronics
993 +artesyn Artesyn Embedded Technologies Inc.
994 +asahi-kasei Asahi Kasei Corp.
995 +aspeed ASPEED Technology Inc.
996 +asus AsusTek Computer Inc.
997 +atlas Atlas Scientific LLC
998 +atmel Atmel Corporation
999 +auo AU Optronics Corporation
1000 +auvidea Auvidea GmbH
1001 +avago Avago Technologies
1002 +avia avia semiconductor
1003 +avic Shanghai AVIC Optoelectronics Co., Ltd.
1004 +avnet Avnet, Inc.
1005 +axentia Axentia Technologies AB
1006 +axis Axis Communications AB
1007 +bananapi BIPAI KEJI LIMITED
1008 +bhf Beckhoff Automation GmbH & Co. KG
1009 +bitmain Bitmain Technologies
1010 +blokaslabs Vilniaus Blokas UAB
1011 +boe BOE Technology Group Co., Ltd.
1012 +bosch Bosch Sensortec GmbH
1013 +boundary Boundary Devices Inc.
1014 +brcm Broadcom Corporation
1015 +buffalo Buffalo, Inc.
1016 +bticino Bticino International
1017 +calxeda Calxeda
1018 +capella Capella Microsystems, Inc
1019 +cascoda Cascoda, Ltd.
1020 +catalyst Catalyst Semiconductor, Inc.
1021 +cavium Cavium, Inc.
1022 +cdns Cadence Design Systems Inc.
1023 +cdtech CDTech(H.K.) Electronics Limited
1024 +ceva Ceva, Inc.
1025 +chipidea Chipidea, Inc
1026 +chipone ChipOne
1027 +chipspark ChipSPARK
1028 +chrp Common Hardware Reference Platform
1029 +chunghwa Chunghwa Picture Tubes Ltd.
1030 +ciaa Computadora Industrial Abierta Argentina
1031 +cirrus Cirrus Logic, Inc.
1032 +cloudengines Cloud Engines, Inc.
1033 +cnm Chips&Media, Inc.
1034 +cnxt Conexant Systems, Inc.
1035 +compulab CompuLab Ltd.
1036 +cortina Cortina Systems, Inc.
1037 +cosmic Cosmic Circuits
1038 +crane Crane Connectivity Solutions
1039 +creative Creative Technology Ltd
1040 +crystalfontz Crystalfontz America, Inc.
1041 +csky Hangzhou C-SKY Microsystems Co., Ltd
1042 +cubietech Cubietech, Ltd.
1043 +cypress Cypress Semiconductor Corporation
1044 +cznic CZ.NIC, z.s.p.o.
1045 +dallas Maxim Integrated Products (formerly Dallas Semiconductor)
1046 +dataimage DataImage, Inc.
1047 +davicom DAVICOM Semiconductor, Inc.
1048 +delta Delta Electronics, Inc.
1049 +denx Denx Software Engineering
1050 +devantech Devantech, Ltd.
1051 +dh DH electronics GmbH
1052 +digi Digi International Inc.
1053 +digilent Diglent, Inc.
1054 +dioo Dioo Microcircuit Co., Ltd
1055 +dlc DLC Display Co., Ltd.
1056 +dlg Dialog Semiconductor
1057 +dlink D-Link Corporation
1058 +dmo Data Modul AG
1059 +domintech Domintech Co., Ltd.
1060 +dongwoon Dongwoon Anatech
1061 +dptechnics DPTechnics
1062 +dragino Dragino Technology Co., Limited
1063 +ea Embedded Artists AB
1064 +ebs-systart EBS-SYSTART GmbH
1065 +ebv EBV Elektronik
1066 +eckelmann Eckelmann AG
1067 +edt Emerging Display Technologies
1068 +eeti eGalax_eMPIA Technology Inc
1069 +elan Elan Microelectronic Corp.
1070 +elgin Elgin S/A.
1071 +embest Shenzhen Embest Technology Co., Ltd.
1072 +emlid Emlid, Ltd.
1073 +emmicro EM Microelectronic
1074 +emtrion emtrion GmbH
1075 +endless Endless Mobile, Inc.
1076 +energymicro Silicon Laboratories (formerly Energy Micro AS)
1077 +engicam Engicam S.r.l.
1078 +epcos EPCOS AG
1079 +epfl Ecole Polytechnique Fédérale de Lausanne
1080 +epson Seiko Epson Corp.
1081 +est ESTeem Wireless Modems
1082 +ettus NI Ettus Research
1083 +eukrea Eukréa Electromatique
1084 +everest Everest Semiconductor Co. Ltd.
1085 +everspin Everspin Technologies, Inc.
1086 +exar Exar Corporation
1087 +excito Excito
1088 +ezchip EZchip Semiconductor
1089 +facebook Facebook
1090 +fairphone Fairphone B.V.
1091 +faraday Faraday Technology Corporation
1092 +fastrax Fastrax Oy
1093 +fcs Fairchild Semiconductor
1094 +feiyang Shenzhen Fly Young Technology Co.,LTD.
1095 +firefly Firefly
1096 +focaltech FocalTech Systems Co.,Ltd
1097 +friendlyarm Guangzhou FriendlyARM Computer Tech Co., Ltd
1098 +fsl Freescale Semiconductor
1099 +fujitsu Fujitsu Ltd.
1100 +gateworks Gateworks Corporation
1101 +gcw Game Consoles Worldwide
1102 +ge General Electric Company
1103 +geekbuying GeekBuying
1104 +gef GE Fanuc Intelligent Platforms Embedded Systems, Inc.
1105 +GEFanuc GE Fanuc Intelligent Platforms Embedded Systems, Inc.
1106 +geniatech Geniatech, Inc.
1107 +giantec Giantec Semiconductor, Inc.
1108 +giantplus Giantplus Technology Co., Ltd.
1109 +globalscale Globalscale Technologies, Inc.
1110 +globaltop GlobalTop Technology, Inc.
1111 +gmt Global Mixed-mode Technology, Inc.
1112 +goodix Shenzhen Huiding Technology Co., Ltd.
1113 +google Google, Inc.
1114 +grinn Grinn
1115 +grmn Garmin Limited
1116 +gumstix Gumstix, Inc.
1117 +gw Gateworks Corporation
1118 +hannstar HannStar Display Corporation
1119 +haoyu Haoyu Microelectronic Co. Ltd.
1120 +hardkernel Hardkernel Co., Ltd
1121 +hideep HiDeep Inc.
1122 +himax Himax Technologies, Inc.
1123 +hisilicon Hisilicon Limited.
1124 +hit Hitachi Ltd.
1125 +hitex Hitex Development Tools
1126 +holt Holt Integrated Circuits, Inc.
1127 +honeywell Honeywell
1128 +hp Hewlett Packard
1129 +holtek Holtek Semiconductor, Inc.
1130 +hwacom HwaCom Systems Inc.
1131 +i2se I2SE GmbH
1132 +ibm International Business Machines (IBM)
1133 +icplus IC Plus Corp.
1134 +idt Integrated Device Technologies, Inc.
1135 +ifi Ingenieurburo Fur Ic-Technologie (I/F/I)
1136 +ilitek ILI Technology Corporation (ILITEK)
1137 +img Imagination Technologies Ltd.
1138 +infineon Infineon Technologies
1139 +inforce Inforce Computing
1140 +ingenic Ingenic Semiconductor
1141 +innolux Innolux Corporation
1142 +inside-secure INSIDE Secure
1143 +intel Intel Corporation
1144 +intercontrol Inter Control Group
1145 +invensense InvenSense Inc.
1146 +inversepath Inverse Path
1147 +iom Iomega Corporation
1148 +isee ISEE 2007 S.L.
1149 +isil Intersil
1150 +issi Integrated Silicon Solutions Inc.
1151 +itead ITEAD Intelligent Systems Co.Ltd
1152 +iwave iWave Systems Technologies Pvt. Ltd.
1153 +jdi Japan Display Inc.
1154 +jedec JEDEC Solid State Technology Association
1155 +jianda Jiandangjing Technology Co., Ltd.
1156 +karo Ka-Ro electronics GmbH
1157 +keithkoep Keith & Koep GmbH
1158 +keymile Keymile GmbH
1159 +khadas Khadas
1160 +kiebackpeter Kieback & Peter GmbH
1161 +kinetic Kinetic Technologies
1162 +kingdisplay King & Display Technology Co., Ltd.
1163 +kingnovel Kingnovel Technology Co., Ltd.
1164 +koe Kaohsiung Opto-Electronics Inc.
1165 +kosagi Sutajio Ko-Usagi PTE Ltd.
1166 +kyo Kyocera Corporation
1167 +lacie LaCie
1168 +laird Laird PLC
1169 +lantiq Lantiq Semiconductor
1170 +lattice Lattice Semiconductor
1171 +lego LEGO Systems A/S
1172 +lemaker Shenzhen LeMaker Technology Co., Ltd.
1173 +lenovo Lenovo Group Ltd.
1174 +lg LG Corporation
1175 +libretech Shenzhen Libre Technology Co., Ltd
1176 +licheepi Lichee Pi
1177 +linaro Linaro Limited
1178 +linksys Belkin International, Inc. (Linksys)
1179 +linux Linux-specific binding
1180 +linx Linx Technologies
1181 +lltc Linear Technology Corporation
1182 +logicpd Logic PD, Inc.
1183 +lsi LSI Corp. (LSI Logic)
1184 +lwn Liebherr-Werk Nenzing GmbH
1185 +macnica Macnica Americas
1186 +marvell Marvell Technology Group Ltd.
1187 +maxim Maxim Integrated Products
1188 +mbvl Mobiveil Inc.
1189 +mcube mCube
1190 +meas Measurement Specialties
1191 +mediatek MediaTek Inc.
1192 +megachips MegaChips
1193 +mele Shenzhen MeLE Digital Technology Ltd.
1194 +melexis Melexis N.V.
1195 +melfas MELFAS Inc.
1196 +mellanox Mellanox Technologies
1197 +memsic MEMSIC Inc.
1198 +merrii Merrii Technology Co., Ltd.
1199 +micrel Micrel Inc.
1200 +microchip Microchip Technology Inc.
1201 +microcrystal Micro Crystal AG
1202 +micron Micron Technology Inc.
1203 +mikroe MikroElektronika d.o.o.
1204 +minix MINIX Technology Ltd.
1205 +miramems MiraMEMS Sensing Technology Co., Ltd.
1206 +mitsubishi Mitsubishi Electric Corporation
1207 +mosaixtech Mosaix Technologies, Inc.
1208 +motorola Motorola, Inc.
1209 +moxa Moxa Inc.
1210 +mpl MPL AG
1211 +mqmaker mqmaker Inc.
1212 +mscc Microsemi Corporation
1213 +msi Micro-Star International Co. Ltd.
1214 +mti Imagination Technologies Ltd. (formerly MIPS Technologies Inc.)
1215 +multi-inno Multi-Inno Technology Co.,Ltd
1216 +mundoreader Mundo Reader S.L.
1217 +murata Murata Manufacturing Co., Ltd.
1218 +mxicy Macronix International Co., Ltd.
1219 +myir MYIR Tech Limited
1220 +national National Semiconductor
1221 +nec NEC LCD Technologies, Ltd.
1222 +neonode Neonode Inc.
1223 +netgear NETGEAR
1224 +netlogic Broadcom Corporation (formerly NetLogic Microsystems)
1225 +netron-dy Netron DY
1226 +netxeon Shenzhen Netxeon Technology CO., LTD
1227 +nexbox Nexbox
1228 +nextthing Next Thing Co.
1229 +newhaven Newhaven Display International
1230 +ni National Instruments
1231 +nintendo Nintendo
1232 +nlt NLT Technologies, Ltd.
1233 +nokia Nokia
1234 +nordic Nordic Semiconductor
1235 +novtech NovTech, Inc.
1236 +nutsboard NutsBoard
1237 +nuvoton Nuvoton Technology Corporation
1238 +nvd New Vision Display
1239 +nvidia NVIDIA
1240 +nxp NXP Semiconductors
1241 +okaya Okaya Electric America, Inc.
1242 +oki Oki Electric Industry Co., Ltd.
1243 +olimex OLIMEX Ltd.
1244 +olpc One Laptop Per Child
1245 +onion Onion Corporation
1246 +onnn ON Semiconductor Corp.
1247 +ontat On Tat Industrial Company
1248 +opalkelly Opal Kelly Incorporated
1249 +opencores OpenCores.org
1250 +openrisc OpenRISC.io
1251 +option Option NV
1252 +oranth Shenzhen Oranth Technology Co., Ltd.
1253 +ORCL Oracle Corporation
1254 +orisetech Orise Technology
1255 +ortustech Ortus Technology Co., Ltd.
1256 +ovti OmniVision Technologies
1257 +oxsemi Oxford Semiconductor, Ltd.
1258 +panasonic Panasonic Corporation
1259 +parade Parade Technologies Inc.
1260 +pda Precision Design Associates, Inc.
1261 +pericom Pericom Technology Inc.
1262 +pervasive Pervasive Displays, Inc.
1263 +phicomm PHICOMM Co., Ltd.
1264 +phytec PHYTEC Messtechnik GmbH
1265 +picochip Picochip Ltd
1266 +pine64 Pine64
1267 +pixcir PIXCIR MICROELECTRONICS Co., Ltd
1268 +plantower Plantower Co., Ltd
1269 +plathome Plat'Home Co., Ltd.
1270 +plda PLDA
1271 +plx Broadcom Corporation (formerly PLX Technology)
1272 +pni PNI Sensor Corporation
1273 +portwell Portwell Inc.
1274 +poslab Poslab Technology Co., Ltd.
1275 +powervr PowerVR (deprecated, use img)
1276 +probox2 PROBOX2 (by W2COMP Co., Ltd.)
1277 +pulsedlight PulsedLight, Inc
1278 +qca Qualcomm Atheros, Inc.
1279 +qcom Qualcomm Technologies, Inc
1280 +qemu QEMU, a generic and open source machine emulator and virtualizer
1281 +qi Qi Hardware
1282 +qiaodian QiaoDian XianShi Corporation
1283 +qnap QNAP Systems, Inc.
1284 +radxa Radxa
1285 +raidsonic RaidSonic Technology GmbH
1286 +ralink Mediatek/Ralink Technology Corp.
1287 +ramtron Ramtron International
1288 +raspberrypi Raspberry Pi Foundation
1289 +raydium Raydium Semiconductor Corp.
1290 +rda Unisoc Communications, Inc.
1291 +realtek Realtek Semiconductor Corp.
1292 +renesas Renesas Electronics Corporation
1293 +richtek Richtek Technology Corporation
1294 +ricoh Ricoh Co. Ltd.
1295 +rikomagic Rikomagic Tech Corp. Ltd
1296 +riscv RISC-V Foundation
1297 +rockchip Fuzhou Rockchip Electronics Co., Ltd
1298 +rohm ROHM Semiconductor Co., Ltd
1299 +roofull Shenzhen Roofull Technology Co, Ltd
1300 +samsung Samsung Semiconductor
1301 +samtec Samtec/Softing company
1302 +sancloud Sancloud Ltd
1303 +sandisk Sandisk Corporation
1304 +sbs Smart Battery System
1305 +schindler Schindler
1306 +seagate Seagate Technology PLC
1307 +semtech Semtech Corporation
1308 +sensirion Sensirion AG
1309 +sff Small Form Factor Committee
1310 +sgd Solomon Goldentek Display Corporation
1311 +sgx SGX Sensortech
1312 +sharp Sharp Corporation
1313 +shimafuji Shimafuji Electric, Inc.
1314 +si-en Si-En Technology Ltd.
1315 +sifive SiFive, Inc.
1316 +sigma Sigma Designs, Inc.
1317 +sii Seiko Instruments, Inc.
1318 +sil Silicon Image
1319 +silabs Silicon Laboratories
1320 +silead Silead Inc.
1321 +silergy Silergy Corp.
1322 +siliconmitus Silicon Mitus, Inc.
1323 +simtek
1324 +sirf SiRF Technology, Inc.
1325 +sis Silicon Integrated Systems Corp.
1326 +sitronix Sitronix Technology Corporation
1327 +skyworks Skyworks Solutions, Inc.
1328 +smsc Standard Microsystems Corporation
1329 +snps Synopsys, Inc.
1330 +socionext Socionext Inc.
1331 +solidrun SolidRun
1332 +solomon Solomon Systech Limited
1333 +sony Sony Corporation
1334 +spansion Spansion Inc.
1335 +sprd Spreadtrum Communications Inc.
1336 +sst Silicon Storage Technology, Inc.
1337 +st STMicroelectronics
1338 +starry Starry Electronic Technology (ShenZhen) Co., LTD
1339 +startek Startek
1340 +ste ST-Ericsson
1341 +stericsson ST-Ericsson
1342 +summit Summit microelectronics
1343 +sunchip Shenzhen Sunchip Technology Co., Ltd
1344 +SUNW Sun Microsystems, Inc
1345 +swir Sierra Wireless
1346 +syna Synaptics Inc.
1347 +synology Synology, Inc.
1348 +tbs TBS Technologies
1349 +tbs-biometrics Touchless Biometric Systems AG
1350 +tcg Trusted Computing Group
1351 +tcl Toby Churchill Ltd.
1352 +technexion TechNexion
1353 +technologic Technologic Systems
1354 +tempo Tempo Semiconductor
1355 +techstar Shenzhen Techstar Electronics Co., Ltd.
1356 +terasic Terasic Inc.
1357 +thine THine Electronics, Inc.
1358 +ti Texas Instruments
1359 +tianma Tianma Micro-electronics Co., Ltd.
1360 +tlm Trusted Logic Mobility
1361 +tmt Tecon Microprocessor Technologies, LLC.
1362 +topeet Topeet
1363 +toradex Toradex AG
1364 +toshiba Toshiba Corporation
1365 +toumaz Toumaz
1366 +tpk TPK U.S.A. LLC
1367 +tplink TP-LINK Technologies Co., Ltd.
1368 +tpo TPO
1369 +tronfy Tronfy
1370 +tronsmart Tronsmart
1371 +truly Truly Semiconductors Limited
1372 +tsd Theobroma Systems Design und Consulting GmbH
1373 +tyan Tyan Computer Corporation
1374 +u-blox u-blox
1375 +ucrobotics uCRobotics
1376 +ubnt Ubiquiti Networks
1377 +udoo Udoo
1378 +uniwest United Western Technologies Corp (UniWest)
1379 +upisemi uPI Semiconductor Corp.
1380 +urt United Radiant Technology Corporation
1381 +usi Universal Scientific Industrial Co., Ltd.
1382 +v3 V3 Semiconductor
1383 +vamrs Vamrs Ltd.
1384 +variscite Variscite Ltd.
1385 +via VIA Technologies, Inc.
1386 +virtio Virtual I/O Device Specification, developed by the OASIS consortium
1387 +vishay Vishay Intertechnology, Inc
1388 +vitesse Vitesse Semiconductor Corporation
1389 +vivante Vivante Corporation
1390 +vocore VoCore Studio
1391 +voipac Voipac Technologies s.r.o.
1392 +vot Vision Optical Technology Co., Ltd.
1393 +wd Western Digital Corp.
1394 +wetek WeTek Electronics, limited.
1395 +wexler Wexler
1396 +whwave Shenzhen whwave Electronics, Inc.
1397 +wi2wi Wi2Wi, Inc.
1398 +winbond Winbond Electronics corp.
1399 +winstar Winstar Display Corp.
1400 +wlf Wolfson Microelectronics
1401 +wm Wondermedia Technologies, Inc.
1402 +x-powers X-Powers
1403 +xes Extreme Engineering Solutions (X-ES)
1404 +xillybus Xillybus Ltd.
1405 +xlnx Xilinx
1406 +xunlong Shenzhen Xunlong Software CO.,Limited
1407 +ysoft Y Soft Corporation a.s.
1408 +zarlink Zarlink Semiconductor
1409 +zeitec ZEITEC Semiconductor Co., LTD.
1410 +zidoo Shenzhen Zidoo Technology Co., Ltd.
1411 +zii Zodiac Inflight Innovations
1412 +zte ZTE Corp.
1413 +zyxel ZyXEL Communications Corp.
1414 --- a/Documentation/devicetree/bindings/vendor-prefixes.yaml
1415 +++ b/Documentation/devicetree/bindings/vendor-prefixes.yaml
1416 @@ -173,6 +173,8 @@ patternProperties:
1417 description: Beckhoff Automation GmbH & Co. KG
1418 "^bitmain,.*":
1419 description: Bitmain Technologies
1420 + "^blokaslabs,.*":
1421 + description: Vilniaus Blokas UAB
1422 "^blutek,.*":
1423 description: BluTek Power
1424 "^boe,.*":
1425 --- a/drivers/clk/Kconfig
1426 +++ b/drivers/clk/Kconfig
1427 @@ -90,6 +90,12 @@ config COMMON_CLK_HI655X
1428 multi-function device has one fixed-rate oscillator, clocked
1429 at 32KHz.
1430
1431 +config COMMON_CLK_HIFIBERRY_DACPLUSHD
1432 + tristate
1433 +
1434 +config COMMON_CLK_HIFIBERRY_DACPRO
1435 + tristate
1436 +
1437 config COMMON_CLK_SCMI
1438 tristate "Clock driver controlled via SCMI interface"
1439 depends on ARM_SCMI_PROTOCOL || COMPILE_TEST
1440 --- a/drivers/clk/Makefile
1441 +++ b/drivers/clk/Makefile
1442 @@ -17,6 +17,7 @@ endif
1443
1444 # hardware specific clock types
1445 # please keep this section sorted lexicographically by file path name
1446 +obj-$(CONFIG_SND_BCM2708_SOC_ALLO_BOSS_DAC) += clk-allo-dac.o
1447 obj-$(CONFIG_MACH_ASM9260) += clk-asm9260.o
1448 obj-$(CONFIG_COMMON_CLK_AXI_CLKGEN) += clk-axi-clkgen.o
1449 obj-$(CONFIG_ARCH_AXXIA) += clk-axm5516.o
1450 @@ -38,6 +39,8 @@ obj-$(CONFIG_CLK_HSDK) += clk-hsdk-pll
1451 obj-$(CONFIG_COMMON_CLK_K210) += clk-k210.o
1452 obj-$(CONFIG_LMK04832) += clk-lmk04832.o
1453 obj-$(CONFIG_COMMON_CLK_LOCHNAGAR) += clk-lochnagar.o
1454 +obj-$(CONFIG_COMMON_CLK_HIFIBERRY_DACPRO) += clk-hifiberry-dacpro.o
1455 +obj-$(CONFIG_COMMON_CLK_HIFIBERRY_DACPLUSHD) += clk-hifiberry-dachd.o
1456 obj-$(CONFIG_COMMON_CLK_MAX77686) += clk-max77686.o
1457 obj-$(CONFIG_COMMON_CLK_MAX9485) += clk-max9485.o
1458 obj-$(CONFIG_ARCH_MILBEAUT_M10V) += clk-milbeaut.o
1459 --- /dev/null
1460 +++ b/drivers/clk/clk-allo-dac.c
1461 @@ -0,0 +1,161 @@
1462 +/*
1463 + * Clock Driver for Allo DAC
1464 + *
1465 + * Author: Baswaraj K <jaikumar@cem-solutions.net>
1466 + * Copyright 2016
1467 + * based on code by Stuart MacLean
1468 + *
1469 + * This program is free software; you can redistribute it and/or
1470 + * modify it under the terms of the GNU General Public License
1471 + * version 2 as published by the Free Software Foundation.
1472 + *
1473 + * This program is distributed in the hope that it will be useful, but
1474 + * WITHOUT ANY WARRANTY; without even the implied warranty of
1475 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1476 + * General Public License for more details.
1477 + */
1478 +
1479 +#include <linux/clk-provider.h>
1480 +#include <linux/clkdev.h>
1481 +#include <linux/kernel.h>
1482 +#include <linux/module.h>
1483 +#include <linux/of.h>
1484 +#include <linux/slab.h>
1485 +#include <linux/platform_device.h>
1486 +
1487 +/* Clock rate of CLK44EN attached to GPIO6 pin */
1488 +#define CLK_44EN_RATE 45158400UL
1489 +/* Clock rate of CLK48EN attached to GPIO3 pin */
1490 +#define CLK_48EN_RATE 49152000UL
1491 +
1492 +/**
1493 + * struct allo_dac_clk - Common struct to the Allo DAC
1494 + * @hw: clk_hw for the common clk framework
1495 + * @mode: 0 => CLK44EN, 1 => CLK48EN
1496 + */
1497 +struct clk_allo_hw {
1498 + struct clk_hw hw;
1499 + uint8_t mode;
1500 +};
1501 +
1502 +#define to_allo_clk(_hw) container_of(_hw, struct clk_allo_hw, hw)
1503 +
1504 +static const struct of_device_id clk_allo_dac_dt_ids[] = {
1505 + { .compatible = "allo,dac-clk",},
1506 + { }
1507 +};
1508 +MODULE_DEVICE_TABLE(of, clk_allo_dac_dt_ids);
1509 +
1510 +static unsigned long clk_allo_dac_recalc_rate(struct clk_hw *hw,
1511 + unsigned long parent_rate)
1512 +{
1513 + return (to_allo_clk(hw)->mode == 0) ? CLK_44EN_RATE :
1514 + CLK_48EN_RATE;
1515 +}
1516 +
1517 +static long clk_allo_dac_round_rate(struct clk_hw *hw,
1518 + unsigned long rate, unsigned long *parent_rate)
1519 +{
1520 + long actual_rate;
1521 +
1522 + if (rate <= CLK_44EN_RATE) {
1523 + actual_rate = (long)CLK_44EN_RATE;
1524 + } else if (rate >= CLK_48EN_RATE) {
1525 + actual_rate = (long)CLK_48EN_RATE;
1526 + } else {
1527 + long diff44Rate = (long)(rate - CLK_44EN_RATE);
1528 + long diff48Rate = (long)(CLK_48EN_RATE - rate);
1529 +
1530 + if (diff44Rate < diff48Rate)
1531 + actual_rate = (long)CLK_44EN_RATE;
1532 + else
1533 + actual_rate = (long)CLK_48EN_RATE;
1534 + }
1535 + return actual_rate;
1536 +}
1537 +
1538 +
1539 +static int clk_allo_dac_set_rate(struct clk_hw *hw,
1540 + unsigned long rate, unsigned long parent_rate)
1541 +{
1542 + unsigned long actual_rate;
1543 + struct clk_allo_hw *clk = to_allo_clk(hw);
1544 +
1545 + actual_rate = (unsigned long)clk_allo_dac_round_rate(hw, rate,
1546 + &parent_rate);
1547 + clk->mode = (actual_rate == CLK_44EN_RATE) ? 0 : 1;
1548 + return 0;
1549 +}
1550 +
1551 +
1552 +const struct clk_ops clk_allo_dac_rate_ops = {
1553 + .recalc_rate = clk_allo_dac_recalc_rate,
1554 + .round_rate = clk_allo_dac_round_rate,
1555 + .set_rate = clk_allo_dac_set_rate,
1556 +};
1557 +
1558 +static int clk_allo_dac_probe(struct platform_device *pdev)
1559 +{
1560 + int ret;
1561 + struct clk_allo_hw *proclk;
1562 + struct clk *clk;
1563 + struct device *dev;
1564 + struct clk_init_data init;
1565 +
1566 + dev = &pdev->dev;
1567 +
1568 + proclk = kzalloc(sizeof(struct clk_allo_hw), GFP_KERNEL);
1569 + if (!proclk)
1570 + return -ENOMEM;
1571 +
1572 + init.name = "clk-allo-dac";
1573 + init.ops = &clk_allo_dac_rate_ops;
1574 + init.flags = 0;
1575 + init.parent_names = NULL;
1576 + init.num_parents = 0;
1577 +
1578 + proclk->mode = 0;
1579 + proclk->hw.init = &init;
1580 +
1581 + clk = devm_clk_register(dev, &proclk->hw);
1582 + if (!IS_ERR(clk)) {
1583 + ret = of_clk_add_provider(dev->of_node, of_clk_src_simple_get,
1584 + clk);
1585 + } else {
1586 + dev_err(dev, "Fail to register clock driver\n");
1587 + kfree(proclk);
1588 + ret = PTR_ERR(clk);
1589 + }
1590 + return ret;
1591 +}
1592 +
1593 +static int clk_allo_dac_remove(struct platform_device *pdev)
1594 +{
1595 + of_clk_del_provider(pdev->dev.of_node);
1596 + return 0;
1597 +}
1598 +
1599 +static struct platform_driver clk_allo_dac_driver = {
1600 + .probe = clk_allo_dac_probe,
1601 + .remove = clk_allo_dac_remove,
1602 + .driver = {
1603 + .name = "clk-allo-dac",
1604 + .of_match_table = clk_allo_dac_dt_ids,
1605 + },
1606 +};
1607 +
1608 +static int __init clk_allo_dac_init(void)
1609 +{
1610 + return platform_driver_register(&clk_allo_dac_driver);
1611 +}
1612 +core_initcall(clk_allo_dac_init);
1613 +
1614 +static void __exit clk_allo_dac_exit(void)
1615 +{
1616 + platform_driver_unregister(&clk_allo_dac_driver);
1617 +}
1618 +module_exit(clk_allo_dac_exit);
1619 +
1620 +MODULE_DESCRIPTION("Allo DAC clock driver");
1621 +MODULE_LICENSE("GPL v2");
1622 +MODULE_ALIAS("platform:clk-allo-dac");
1623 --- /dev/null
1624 +++ b/drivers/clk/clk-hifiberry-dachd.c
1625 @@ -0,0 +1,333 @@
1626 +// SPDX-License-Identifier: GPL-2.0
1627 +/*
1628 + * Clock Driver for HiFiBerry DAC+ HD
1629 + *
1630 + * Author: Joerg Schambacher, i2Audio GmbH for HiFiBerry
1631 + * Copyright 2020
1632 + *
1633 + * This program is free software; you can redistribute it and/or
1634 + * modify it under the terms of the GNU General Public License
1635 + * version 2 as published by the Free Software Foundation.
1636 + *
1637 + * This program is distributed in the hope that it will be useful, but
1638 + * WITHOUT ANY WARRANTY; without even the implied warranty of
1639 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1640 + * General Public License for more details.
1641 + */
1642 +
1643 +#include <linux/clk-provider.h>
1644 +#include <linux/clk.h>
1645 +#include <linux/kernel.h>
1646 +#include <linux/module.h>
1647 +#include <linux/of.h>
1648 +#include <linux/slab.h>
1649 +#include <linux/platform_device.h>
1650 +#include <linux/i2c.h>
1651 +#include <linux/regmap.h>
1652 +
1653 +#define NO_PLL_RESET 0
1654 +#define PLL_RESET 1
1655 +#define HIFIBERRY_PLL_MAX_REGISTER 256
1656 +#define DEFAULT_RATE 44100
1657 +
1658 +static struct reg_default hifiberry_pll_reg_defaults[] = {
1659 + {0x02, 0x53}, {0x03, 0x00}, {0x07, 0x20}, {0x0F, 0x00},
1660 + {0x10, 0x0D}, {0x11, 0x1D}, {0x12, 0x0D}, {0x13, 0x8C},
1661 + {0x14, 0x8C}, {0x15, 0x8C}, {0x16, 0x8C}, {0x17, 0x8C},
1662 + {0x18, 0x2A}, {0x1C, 0x00}, {0x1D, 0x0F}, {0x1F, 0x00},
1663 + {0x2A, 0x00}, {0x2C, 0x00}, {0x2F, 0x00}, {0x30, 0x00},
1664 + {0x31, 0x00}, {0x32, 0x00}, {0x34, 0x00}, {0x37, 0x00},
1665 + {0x38, 0x00}, {0x39, 0x00}, {0x3A, 0x00}, {0x3B, 0x01},
1666 + {0x3E, 0x00}, {0x3F, 0x00}, {0x40, 0x00}, {0x41, 0x00},
1667 + {0x5A, 0x00}, {0x5B, 0x00}, {0x95, 0x00}, {0x96, 0x00},
1668 + {0x97, 0x00}, {0x98, 0x00}, {0x99, 0x00}, {0x9A, 0x00},
1669 + {0x9B, 0x00}, {0xA2, 0x00}, {0xA3, 0x00}, {0xA4, 0x00},
1670 + {0xB7, 0x92},
1671 + {0x1A, 0x3D}, {0x1B, 0x09}, {0x1E, 0xF3}, {0x20, 0x13},
1672 + {0x21, 0x75}, {0x2B, 0x04}, {0x2D, 0x11}, {0x2E, 0xE0},
1673 + {0x3D, 0x7A},
1674 + {0x35, 0x9D}, {0x36, 0x00}, {0x3C, 0x42},
1675 + { 177, 0xAC},
1676 +};
1677 +static struct reg_default common_pll_regs[HIFIBERRY_PLL_MAX_REGISTER];
1678 +static int num_common_pll_regs;
1679 +static struct reg_default dedicated_192k_pll_regs[HIFIBERRY_PLL_MAX_REGISTER];
1680 +static int num_dedicated_192k_pll_regs;
1681 +static struct reg_default dedicated_96k_pll_regs[HIFIBERRY_PLL_MAX_REGISTER];
1682 +static int num_dedicated_96k_pll_regs;
1683 +static struct reg_default dedicated_48k_pll_regs[HIFIBERRY_PLL_MAX_REGISTER];
1684 +static int num_dedicated_48k_pll_regs;
1685 +static struct reg_default dedicated_176k4_pll_regs[HIFIBERRY_PLL_MAX_REGISTER];
1686 +static int num_dedicated_176k4_pll_regs;
1687 +static struct reg_default dedicated_88k2_pll_regs[HIFIBERRY_PLL_MAX_REGISTER];
1688 +static int num_dedicated_88k2_pll_regs;
1689 +static struct reg_default dedicated_44k1_pll_regs[HIFIBERRY_PLL_MAX_REGISTER];
1690 +static int num_dedicated_44k1_pll_regs;
1691 +
1692 +/**
1693 + * struct clk_hifiberry_drvdata - Common struct to the HiFiBerry DAC HD Clk
1694 + * @hw: clk_hw for the common clk framework
1695 + */
1696 +struct clk_hifiberry_drvdata {
1697 + struct regmap *regmap;
1698 + struct clk *clk;
1699 + struct clk_hw hw;
1700 + unsigned long rate;
1701 +};
1702 +
1703 +#define to_hifiberry_clk(_hw) \
1704 + container_of(_hw, struct clk_hifiberry_drvdata, hw)
1705 +
1706 +static int clk_hifiberry_dachd_write_pll_regs(struct regmap *regmap,
1707 + struct reg_default *regs,
1708 + int num, int do_pll_reset)
1709 +{
1710 + int i;
1711 + int ret = 0;
1712 + char pll_soft_reset[] = { 177, 0xAC, };
1713 +
1714 + for (i = 0; i < num; i++) {
1715 + ret |= regmap_write(regmap, regs[i].reg, regs[i].def);
1716 + if (ret)
1717 + return ret;
1718 + }
1719 + if (do_pll_reset) {
1720 + ret |= regmap_write(regmap, pll_soft_reset[0],
1721 + pll_soft_reset[1]);
1722 + mdelay(10);
1723 + }
1724 + return ret;
1725 +}
1726 +
1727 +static unsigned long clk_hifiberry_dachd_recalc_rate(struct clk_hw *hw,
1728 + unsigned long parent_rate)
1729 +{
1730 + return to_hifiberry_clk(hw)->rate;
1731 +}
1732 +
1733 +static long clk_hifiberry_dachd_round_rate(struct clk_hw *hw,
1734 + unsigned long rate, unsigned long *parent_rate)
1735 +{
1736 + return rate;
1737 +}
1738 +
1739 +static int clk_hifiberry_dachd_set_rate(struct clk_hw *hw,
1740 + unsigned long rate, unsigned long parent_rate)
1741 +{
1742 + int ret;
1743 + struct clk_hifiberry_drvdata *drvdata = to_hifiberry_clk(hw);
1744 +
1745 + switch (rate) {
1746 + case 44100:
1747 + ret = clk_hifiberry_dachd_write_pll_regs(drvdata->regmap,
1748 + dedicated_44k1_pll_regs, num_dedicated_44k1_pll_regs,
1749 + PLL_RESET);
1750 + break;
1751 + case 88200:
1752 + ret = clk_hifiberry_dachd_write_pll_regs(drvdata->regmap,
1753 + dedicated_88k2_pll_regs, num_dedicated_88k2_pll_regs,
1754 + PLL_RESET);
1755 + break;
1756 + case 176400:
1757 + ret = clk_hifiberry_dachd_write_pll_regs(drvdata->regmap,
1758 + dedicated_176k4_pll_regs, num_dedicated_176k4_pll_regs,
1759 + PLL_RESET);
1760 + break;
1761 + case 48000:
1762 + ret = clk_hifiberry_dachd_write_pll_regs(drvdata->regmap,
1763 + dedicated_48k_pll_regs, num_dedicated_48k_pll_regs,
1764 + PLL_RESET);
1765 + break;
1766 + case 96000:
1767 + ret = clk_hifiberry_dachd_write_pll_regs(drvdata->regmap,
1768 + dedicated_96k_pll_regs, num_dedicated_96k_pll_regs,
1769 + PLL_RESET);
1770 + break;
1771 + case 192000:
1772 + ret = clk_hifiberry_dachd_write_pll_regs(drvdata->regmap,
1773 + dedicated_192k_pll_regs, num_dedicated_192k_pll_regs,
1774 + PLL_RESET);
1775 + break;
1776 + default:
1777 + ret = -EINVAL;
1778 + break;
1779 + }
1780 + to_hifiberry_clk(hw)->rate = rate;
1781 +
1782 + return ret;
1783 +}
1784 +
1785 +const struct clk_ops clk_hifiberry_dachd_rate_ops = {
1786 + .recalc_rate = clk_hifiberry_dachd_recalc_rate,
1787 + .round_rate = clk_hifiberry_dachd_round_rate,
1788 + .set_rate = clk_hifiberry_dachd_set_rate,
1789 +};
1790 +
1791 +static int clk_hifiberry_get_prop_values(struct device *dev,
1792 + char *prop_name,
1793 + struct reg_default *regs)
1794 +{
1795 + int ret;
1796 + int i;
1797 + u8 tmp[2 * HIFIBERRY_PLL_MAX_REGISTER];
1798 +
1799 + ret = of_property_read_variable_u8_array(dev->of_node, prop_name,
1800 + tmp, 0, 2 * HIFIBERRY_PLL_MAX_REGISTER);
1801 + if (ret < 0)
1802 + return ret;
1803 + if (ret & 1) {
1804 + dev_err(dev,
1805 + "%s <%s> -> #%i odd number of bytes for reg/val pairs!",
1806 + __func__,
1807 + prop_name,
1808 + ret);
1809 + return -EINVAL;
1810 + }
1811 + ret /= 2;
1812 + for (i = 0; i < ret; i++) {
1813 + regs[i].reg = (u32)tmp[2 * i];
1814 + regs[i].def = (u32)tmp[2 * i + 1];
1815 + }
1816 + return ret;
1817 +}
1818 +
1819 +
1820 +static int clk_hifiberry_dachd_dt_parse(struct device *dev)
1821 +{
1822 + num_common_pll_regs = clk_hifiberry_get_prop_values(dev,
1823 + "common_pll_regs", common_pll_regs);
1824 + num_dedicated_44k1_pll_regs = clk_hifiberry_get_prop_values(dev,
1825 + "44k1_pll_regs", dedicated_44k1_pll_regs);
1826 + num_dedicated_88k2_pll_regs = clk_hifiberry_get_prop_values(dev,
1827 + "88k2_pll_regs", dedicated_88k2_pll_regs);
1828 + num_dedicated_176k4_pll_regs = clk_hifiberry_get_prop_values(dev,
1829 + "176k4_pll_regs", dedicated_176k4_pll_regs);
1830 + num_dedicated_48k_pll_regs = clk_hifiberry_get_prop_values(dev,
1831 + "48k_pll_regs", dedicated_48k_pll_regs);
1832 + num_dedicated_96k_pll_regs = clk_hifiberry_get_prop_values(dev,
1833 + "96k_pll_regs", dedicated_96k_pll_regs);
1834 + num_dedicated_192k_pll_regs = clk_hifiberry_get_prop_values(dev,
1835 + "192k_pll_regs", dedicated_192k_pll_regs);
1836 + return 0;
1837 +}
1838 +
1839 +
1840 +static int clk_hifiberry_dachd_remove(struct device *dev)
1841 +{
1842 + of_clk_del_provider(dev->of_node);
1843 + return 0;
1844 +}
1845 +
1846 +const struct regmap_config hifiberry_pll_regmap = {
1847 + .reg_bits = 8,
1848 + .val_bits = 8,
1849 + .max_register = HIFIBERRY_PLL_MAX_REGISTER,
1850 + .reg_defaults = hifiberry_pll_reg_defaults,
1851 + .num_reg_defaults = ARRAY_SIZE(hifiberry_pll_reg_defaults),
1852 + .cache_type = REGCACHE_RBTREE,
1853 +};
1854 +EXPORT_SYMBOL_GPL(hifiberry_pll_regmap);
1855 +
1856 +
1857 +static int clk_hifiberry_dachd_i2c_probe(struct i2c_client *i2c,
1858 + const struct i2c_device_id *id)
1859 +{
1860 + struct clk_hifiberry_drvdata *hdclk;
1861 + int ret = 0;
1862 + struct clk_init_data init;
1863 + struct device *dev = &i2c->dev;
1864 + struct device_node *dev_node = dev->of_node;
1865 + struct regmap_config config = hifiberry_pll_regmap;
1866 +
1867 + hdclk = devm_kzalloc(&i2c->dev,
1868 + sizeof(struct clk_hifiberry_drvdata), GFP_KERNEL);
1869 + if (!hdclk)
1870 + return -ENOMEM;
1871 +
1872 + i2c_set_clientdata(i2c, hdclk);
1873 +
1874 + hdclk->regmap = devm_regmap_init_i2c(i2c, &config);
1875 +
1876 + if (IS_ERR(hdclk->regmap))
1877 + return PTR_ERR(hdclk->regmap);
1878 +
1879 + /* start PLL to allow detection of DAC */
1880 + ret = clk_hifiberry_dachd_write_pll_regs(hdclk->regmap,
1881 + hifiberry_pll_reg_defaults,
1882 + ARRAY_SIZE(hifiberry_pll_reg_defaults),
1883 + PLL_RESET);
1884 + if (ret)
1885 + return ret;
1886 +
1887 + clk_hifiberry_dachd_dt_parse(dev);
1888 +
1889 + /* restart PLL with configs from DTB */
1890 + ret = clk_hifiberry_dachd_write_pll_regs(hdclk->regmap, common_pll_regs,
1891 + num_common_pll_regs, PLL_RESET);
1892 + if (ret)
1893 + return ret;
1894 +
1895 + init.name = "clk-hifiberry-dachd";
1896 + init.ops = &clk_hifiberry_dachd_rate_ops;
1897 + init.flags = 0;
1898 + init.parent_names = NULL;
1899 + init.num_parents = 0;
1900 +
1901 + hdclk->hw.init = &init;
1902 +
1903 + hdclk->clk = devm_clk_register(dev, &hdclk->hw);
1904 + if (IS_ERR(hdclk->clk)) {
1905 + dev_err(dev, "unable to register %s\n", init.name);
1906 + return PTR_ERR(hdclk->clk);
1907 + }
1908 +
1909 + ret = of_clk_add_provider(dev_node, of_clk_src_simple_get, hdclk->clk);
1910 + if (ret != 0) {
1911 + dev_err(dev, "Cannot of_clk_add_provider");
1912 + return ret;
1913 + }
1914 +
1915 + ret = clk_set_rate(hdclk->hw.clk, DEFAULT_RATE);
1916 + if (ret != 0) {
1917 + dev_err(dev, "Cannot set rate : %d\n", ret);
1918 + return -EINVAL;
1919 + }
1920 +
1921 + return ret;
1922 +}
1923 +
1924 +static int clk_hifiberry_dachd_i2c_remove(struct i2c_client *i2c)
1925 +{
1926 + clk_hifiberry_dachd_remove(&i2c->dev);
1927 + return 0;
1928 +}
1929 +
1930 +static const struct i2c_device_id clk_hifiberry_dachd_i2c_id[] = {
1931 + { "dachd-clk", },
1932 + { }
1933 +};
1934 +MODULE_DEVICE_TABLE(i2c, clk_hifiberry_dachd_i2c_id);
1935 +
1936 +static const struct of_device_id clk_hifiberry_dachd_of_match[] = {
1937 + { .compatible = "hifiberry,dachd-clk", },
1938 + { }
1939 +};
1940 +MODULE_DEVICE_TABLE(of, clk_hifiberry_dachd_of_match);
1941 +
1942 +static struct i2c_driver clk_hifiberry_dachd_i2c_driver = {
1943 + .probe = clk_hifiberry_dachd_i2c_probe,
1944 + .remove = clk_hifiberry_dachd_i2c_remove,
1945 + .id_table = clk_hifiberry_dachd_i2c_id,
1946 + .driver = {
1947 + .name = "dachd-clk",
1948 + .of_match_table = of_match_ptr(clk_hifiberry_dachd_of_match),
1949 + },
1950 +};
1951 +
1952 +module_i2c_driver(clk_hifiberry_dachd_i2c_driver);
1953 +
1954 +
1955 +MODULE_DESCRIPTION("HiFiBerry DAC+ HD clock driver");
1956 +MODULE_AUTHOR("Joerg Schambacher <joerg@i2audio.com>");
1957 +MODULE_LICENSE("GPL v2");
1958 +MODULE_ALIAS("platform:clk-hifiberry-dachd");
1959 --- /dev/null
1960 +++ b/drivers/clk/clk-hifiberry-dacpro.c
1961 @@ -0,0 +1,160 @@
1962 +/*
1963 + * Clock Driver for HiFiBerry DAC Pro
1964 + *
1965 + * Author: Stuart MacLean
1966 + * Copyright 2015
1967 + *
1968 + * This program is free software; you can redistribute it and/or
1969 + * modify it under the terms of the GNU General Public License
1970 + * version 2 as published by the Free Software Foundation.
1971 + *
1972 + * This program is distributed in the hope that it will be useful, but
1973 + * WITHOUT ANY WARRANTY; without even the implied warranty of
1974 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1975 + * General Public License for more details.
1976 + */
1977 +
1978 +#include <linux/clk-provider.h>
1979 +#include <linux/clkdev.h>
1980 +#include <linux/kernel.h>
1981 +#include <linux/module.h>
1982 +#include <linux/of.h>
1983 +#include <linux/slab.h>
1984 +#include <linux/platform_device.h>
1985 +
1986 +/* Clock rate of CLK44EN attached to GPIO6 pin */
1987 +#define CLK_44EN_RATE 22579200UL
1988 +/* Clock rate of CLK48EN attached to GPIO3 pin */
1989 +#define CLK_48EN_RATE 24576000UL
1990 +
1991 +/**
1992 + * struct hifiberry_dacpro_clk - Common struct to the HiFiBerry DAC Pro
1993 + * @hw: clk_hw for the common clk framework
1994 + * @mode: 0 => CLK44EN, 1 => CLK48EN
1995 + */
1996 +struct clk_hifiberry_hw {
1997 + struct clk_hw hw;
1998 + uint8_t mode;
1999 +};
2000 +
2001 +#define to_hifiberry_clk(_hw) container_of(_hw, struct clk_hifiberry_hw, hw)
2002 +
2003 +static const struct of_device_id clk_hifiberry_dacpro_dt_ids[] = {
2004 + { .compatible = "hifiberry,dacpro-clk",},
2005 + { }
2006 +};
2007 +MODULE_DEVICE_TABLE(of, clk_hifiberry_dacpro_dt_ids);
2008 +
2009 +static unsigned long clk_hifiberry_dacpro_recalc_rate(struct clk_hw *hw,
2010 + unsigned long parent_rate)
2011 +{
2012 + return (to_hifiberry_clk(hw)->mode == 0) ? CLK_44EN_RATE :
2013 + CLK_48EN_RATE;
2014 +}
2015 +
2016 +static long clk_hifiberry_dacpro_round_rate(struct clk_hw *hw,
2017 + unsigned long rate, unsigned long *parent_rate)
2018 +{
2019 + long actual_rate;
2020 +
2021 + if (rate <= CLK_44EN_RATE) {
2022 + actual_rate = (long)CLK_44EN_RATE;
2023 + } else if (rate >= CLK_48EN_RATE) {
2024 + actual_rate = (long)CLK_48EN_RATE;
2025 + } else {
2026 + long diff44Rate = (long)(rate - CLK_44EN_RATE);
2027 + long diff48Rate = (long)(CLK_48EN_RATE - rate);
2028 +
2029 + if (diff44Rate < diff48Rate)
2030 + actual_rate = (long)CLK_44EN_RATE;
2031 + else
2032 + actual_rate = (long)CLK_48EN_RATE;
2033 + }
2034 + return actual_rate;
2035 +}
2036 +
2037 +
2038 +static int clk_hifiberry_dacpro_set_rate(struct clk_hw *hw,
2039 + unsigned long rate, unsigned long parent_rate)
2040 +{
2041 + unsigned long actual_rate;
2042 + struct clk_hifiberry_hw *clk = to_hifiberry_clk(hw);
2043 +
2044 + actual_rate = (unsigned long)clk_hifiberry_dacpro_round_rate(hw, rate,
2045 + &parent_rate);
2046 + clk->mode = (actual_rate == CLK_44EN_RATE) ? 0 : 1;
2047 + return 0;
2048 +}
2049 +
2050 +
2051 +const struct clk_ops clk_hifiberry_dacpro_rate_ops = {
2052 + .recalc_rate = clk_hifiberry_dacpro_recalc_rate,
2053 + .round_rate = clk_hifiberry_dacpro_round_rate,
2054 + .set_rate = clk_hifiberry_dacpro_set_rate,
2055 +};
2056 +
2057 +static int clk_hifiberry_dacpro_probe(struct platform_device *pdev)
2058 +{
2059 + int ret;
2060 + struct clk_hifiberry_hw *proclk;
2061 + struct clk *clk;
2062 + struct device *dev;
2063 + struct clk_init_data init;
2064 +
2065 + dev = &pdev->dev;
2066 +
2067 + proclk = kzalloc(sizeof(struct clk_hifiberry_hw), GFP_KERNEL);
2068 + if (!proclk)
2069 + return -ENOMEM;
2070 +
2071 + init.name = "clk-hifiberry-dacpro";
2072 + init.ops = &clk_hifiberry_dacpro_rate_ops;
2073 + init.flags = 0;
2074 + init.parent_names = NULL;
2075 + init.num_parents = 0;
2076 +
2077 + proclk->mode = 0;
2078 + proclk->hw.init = &init;
2079 +
2080 + clk = devm_clk_register(dev, &proclk->hw);
2081 + if (!IS_ERR(clk)) {
2082 + ret = of_clk_add_provider(dev->of_node, of_clk_src_simple_get,
2083 + clk);
2084 + } else {
2085 + dev_err(dev, "Fail to register clock driver\n");
2086 + kfree(proclk);
2087 + ret = PTR_ERR(clk);
2088 + }
2089 + return ret;
2090 +}
2091 +
2092 +static int clk_hifiberry_dacpro_remove(struct platform_device *pdev)
2093 +{
2094 + of_clk_del_provider(pdev->dev.of_node);
2095 + return 0;
2096 +}
2097 +
2098 +static struct platform_driver clk_hifiberry_dacpro_driver = {
2099 + .probe = clk_hifiberry_dacpro_probe,
2100 + .remove = clk_hifiberry_dacpro_remove,
2101 + .driver = {
2102 + .name = "clk-hifiberry-dacpro",
2103 + .of_match_table = clk_hifiberry_dacpro_dt_ids,
2104 + },
2105 +};
2106 +
2107 +static int __init clk_hifiberry_dacpro_init(void)
2108 +{
2109 + return platform_driver_register(&clk_hifiberry_dacpro_driver);
2110 +}
2111 +core_initcall(clk_hifiberry_dacpro_init);
2112 +
2113 +static void __exit clk_hifiberry_dacpro_exit(void)
2114 +{
2115 + platform_driver_unregister(&clk_hifiberry_dacpro_driver);
2116 +}
2117 +module_exit(clk_hifiberry_dacpro_exit);
2118 +
2119 +MODULE_DESCRIPTION("HiFiBerry DAC Pro clock driver");
2120 +MODULE_LICENSE("GPL v2");
2121 +MODULE_ALIAS("platform:clk-hifiberry-dacpro");
2122 --- a/sound/soc/bcm/Kconfig
2123 +++ b/sound/soc/bcm/Kconfig
2124 @@ -26,3 +26,294 @@ config SND_BCM63XX_I2S_WHISTLER
2125 DSL/PON chips (bcm63158, bcm63178)
2126
2127 If you don't know what to do here, say N
2128 +
2129 +config SND_BCM2708_SOC_GOOGLEVOICEHAT_SOUNDCARD
2130 + tristate "Support for Google voiceHAT soundcard"
2131 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2132 + select SND_SOC_VOICEHAT
2133 + select SND_RPI_SIMPLE_SOUNDCARD
2134 + help
2135 + Say Y or M if you want to add support for voiceHAT soundcard.
2136 +
2137 +config SND_BCM2708_SOC_HIFIBERRY_DAC
2138 + tristate "Support for HifiBerry DAC"
2139 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2140 + select SND_SOC_PCM5102A
2141 + select SND_RPI_SIMPLE_SOUNDCARD
2142 + help
2143 + Say Y or M if you want to add support for HifiBerry DAC.
2144 +
2145 +config SND_BCM2708_SOC_HIFIBERRY_DACPLUS
2146 + tristate "Support for HifiBerry DAC+"
2147 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2148 + select SND_SOC_PCM512x
2149 + select SND_SOC_TPA6130A2
2150 + select COMMON_CLK_HIFIBERRY_DACPRO
2151 + help
2152 + Say Y or M if you want to add support for HifiBerry DAC+.
2153 +
2154 +config SND_BCM2708_SOC_HIFIBERRY_DACPLUSHD
2155 + tristate "Support for HifiBerry DAC+ HD"
2156 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2157 + select SND_SOC_PCM179X_I2C
2158 + select COMMON_CLK_HIFIBERRY_DACPLUSHD
2159 + help
2160 + Say Y or M if you want to add support for HifiBerry DAC+ HD.
2161 +
2162 +config SND_BCM2708_SOC_HIFIBERRY_DACPLUSADC
2163 + tristate "Support for HifiBerry DAC+ADC"
2164 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2165 + select SND_SOC_PCM512x_I2C
2166 + select SND_SOC_DMIC
2167 + select COMMON_CLK_HIFIBERRY_DACPRO
2168 + help
2169 + Say Y or M if you want to add support for HifiBerry DAC+ADC.
2170 +
2171 +config SND_BCM2708_SOC_HIFIBERRY_DACPLUSADCPRO
2172 + tristate "Support for HifiBerry DAC+ADC PRO"
2173 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2174 + select SND_SOC_PCM512x_I2C
2175 + select SND_SOC_PCM186X_I2C
2176 + select COMMON_CLK_HIFIBERRY_DACPRO
2177 + help
2178 + Say Y or M if you want to add support for HifiBerry DAC+ADC PRO.
2179 +
2180 +config SND_BCM2708_SOC_HIFIBERRY_DACPLUSDSP
2181 + tristate "Support for HifiBerry DAC+DSP"
2182 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2183 + select SND_RPI_SIMPLE_SOUNDCARD
2184 + help
2185 + Say Y or M if you want to add support for HifiBerry DSP-DAC.
2186 +
2187 +config SND_BCM2708_SOC_HIFIBERRY_DIGI
2188 + tristate "Support for HifiBerry Digi"
2189 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2190 + select SND_SOC_WM8804
2191 + help
2192 + Say Y or M if you want to add support for HifiBerry Digi S/PDIF output board.
2193 +
2194 +config SND_BCM2708_SOC_HIFIBERRY_AMP
2195 + tristate "Support for the HifiBerry Amp"
2196 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2197 + select SND_SOC_TAS5713
2198 + select SND_RPI_SIMPLE_SOUNDCARD
2199 + help
2200 + Say Y or M if you want to add support for the HifiBerry Amp amplifier board.
2201 +
2202 + config SND_BCM2708_SOC_PIFI_40
2203 + tristate "Support for the PiFi-40 amp"
2204 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2205 + select SND_SOC_TAS571X
2206 + select SND_PIFI_40
2207 + help
2208 + Say Y or M if you want to add support for the PiFi40 amp board
2209 +
2210 +config SND_BCM2708_SOC_RPI_CIRRUS
2211 + tristate "Support for Cirrus Logic Audio Card"
2212 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2213 + select SND_SOC_WM5102
2214 + select SND_SOC_WM8804
2215 + help
2216 + Say Y or M if you want to add support for the Wolfson and
2217 + Cirrus Logic audio cards.
2218 +
2219 +config SND_BCM2708_SOC_RPI_DAC
2220 + tristate "Support for RPi-DAC"
2221 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2222 + select SND_SOC_PCM1794A
2223 + select SND_RPI_SIMPLE_SOUNDCARD
2224 + help
2225 + Say Y or M if you want to add support for RPi-DAC.
2226 +
2227 +config SND_BCM2708_SOC_RPI_PROTO
2228 + tristate "Support for Rpi-PROTO"
2229 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2230 + select SND_SOC_WM8731
2231 + help
2232 + Say Y or M if you want to add support for Audio Codec Board PROTO (WM8731).
2233 +
2234 +config SND_BCM2708_SOC_JUSTBOOM_BOTH
2235 + tristate "Support for simultaneous JustBoom Digi and JustBoom DAC"
2236 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2237 + select SND_SOC_WM8804
2238 + select SND_SOC_PCM512x
2239 + help
2240 + Say Y or M if you want to add support for simultaneous
2241 + JustBoom Digi and JustBoom DAC.
2242 +
2243 + This is not the right choice if you only have one but both of
2244 + these cards.
2245 +
2246 +config SND_BCM2708_SOC_JUSTBOOM_DAC
2247 + tristate "Support for JustBoom DAC"
2248 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2249 + select SND_SOC_PCM512x
2250 + help
2251 + Say Y or M if you want to add support for JustBoom DAC.
2252 +
2253 +config SND_BCM2708_SOC_JUSTBOOM_DIGI
2254 + tristate "Support for JustBoom Digi"
2255 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2256 + select SND_SOC_WM8804
2257 + select SND_RPI_WM8804_SOUNDCARD
2258 + help
2259 + Say Y or M if you want to add support for JustBoom Digi.
2260 +
2261 +config SND_BCM2708_SOC_IQAUDIO_CODEC
2262 + tristate "Support for IQaudIO-CODEC"
2263 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2264 + select SND_SOC_DA7213
2265 + help
2266 + Say Y or M if you want to add support for IQaudIO-CODEC.
2267 +
2268 +config SND_BCM2708_SOC_IQAUDIO_DAC
2269 + tristate "Support for IQaudIO-DAC"
2270 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2271 + select SND_SOC_PCM512x_I2C
2272 + help
2273 + Say Y or M if you want to add support for IQaudIO-DAC.
2274 +
2275 +config SND_BCM2708_SOC_IQAUDIO_DIGI
2276 + tristate "Support for IQAudIO Digi"
2277 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2278 + select SND_SOC_WM8804
2279 + select SND_RPI_WM8804_SOUNDCARD
2280 + help
2281 + Say Y or M if you want to add support for IQAudIO Digital IO board.
2282 +
2283 +config SND_BCM2708_SOC_I_SABRE_Q2M
2284 + tristate "Support for Audiophonics I-Sabre Q2M DAC"
2285 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2286 + select SND_SOC_I_SABRE_CODEC
2287 + help
2288 + Say Y or M if you want to add support for Audiophonics I-SABRE Q2M DAC
2289 +
2290 +config SND_BCM2708_SOC_ADAU1977_ADC
2291 + tristate "Support for ADAU1977 ADC"
2292 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2293 + select SND_SOC_ADAU1977_I2C
2294 + select SND_RPI_SIMPLE_SOUNDCARD
2295 + help
2296 + Say Y or M if you want to add support for ADAU1977 ADC.
2297 +
2298 +config SND_AUDIOINJECTOR_PI_SOUNDCARD
2299 + tristate "Support for audioinjector.net Pi add on soundcard"
2300 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2301 + select SND_SOC_WM8731
2302 + help
2303 + Say Y or M if you want to add support for audioinjector.net Pi Hat
2304 +
2305 +config SND_AUDIOINJECTOR_OCTO_SOUNDCARD
2306 + tristate "Support for audioinjector.net Octo channel (Hat) soundcard"
2307 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2308 + select SND_SOC_CS42XX8_I2C
2309 + help
2310 + Say Y or M if you want to add support for audioinjector.net octo add on
2311 +
2312 +config SND_AUDIOINJECTOR_ISOLATED_SOUNDCARD
2313 + tristate "Support for audioinjector.net isolated DAC and ADC soundcard"
2314 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2315 + select SND_SOC_CS4271_I2C
2316 + help
2317 + Say Y or M if you want to add support for audioinjector.net isolated soundcard
2318 +
2319 +config SND_AUDIOSENSE_PI
2320 + tristate "Support for AudioSense Add-On Soundcard"
2321 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2322 + select SND_SOC_TLV320AIC32X4_I2C
2323 + help
2324 + Say Y or M if you want to add support for tlv320aic32x4 add-on
2325 +
2326 +config SND_DIGIDAC1_SOUNDCARD
2327 + tristate "Support for Red Rocks Audio DigiDAC1"
2328 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2329 + select SND_SOC_WM8804
2330 + select SND_SOC_WM8741
2331 + help
2332 + Say Y or M if you want to add support for Red Rocks Audio DigiDAC1 board.
2333 +
2334 +config SND_BCM2708_SOC_DIONAUDIO_LOCO
2335 + tristate "Support for Dion Audio LOCO DAC-AMP"
2336 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2337 + select SND_SOC_PCM5102a
2338 + help
2339 + Say Y or M if you want to add support for Dion Audio LOCO.
2340 +
2341 +config SND_BCM2708_SOC_DIONAUDIO_LOCO_V2
2342 + tristate "Support for Dion Audio LOCO-V2 DAC-AMP"
2343 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2344 + select SND_SOC_PCM5122
2345 + help
2346 + Say Y or M if you want to add support for Dion Audio LOCO-V2.
2347 +
2348 +config SND_BCM2708_SOC_ALLO_PIANO_DAC
2349 + tristate "Support for Allo Piano DAC"
2350 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2351 + select SND_SOC_PCM512x_I2C
2352 + help
2353 + Say Y or M if you want to add support for Allo Piano DAC.
2354 +
2355 +config SND_BCM2708_SOC_ALLO_PIANO_DAC_PLUS
2356 + tristate "Support for Allo Piano DAC Plus"
2357 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2358 + select SND_SOC_PCM512x_I2C
2359 + help
2360 + Say Y or M if you want to add support for Allo Piano DAC Plus.
2361 +
2362 +config SND_BCM2708_SOC_ALLO_BOSS_DAC
2363 + tristate "Support for Allo Boss DAC"
2364 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2365 + select SND_SOC_PCM512x_I2C
2366 + help
2367 + Say Y or M if you want to add support for Allo Boss DAC.
2368 +
2369 +config SND_BCM2708_SOC_ALLO_BOSS2_DAC
2370 + tristate "Support for Allo Boss2 DAC"
2371 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2372 + depends on I2C
2373 + select REGMAP_I2C
2374 + select SND_AUDIO_GRAPH_CARD
2375 + help
2376 + Say Y or M if you want to add support for Allo Boss2 DAC.
2377 +
2378 +config SND_BCM2708_SOC_ALLO_DIGIONE
2379 + tristate "Support for Allo DigiOne"
2380 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2381 + select SND_SOC_WM8804
2382 + select SND_RPI_WM8804_SOUNDCARD
2383 + help
2384 + Say Y or M if you want to add support for Allo DigiOne.
2385 +
2386 +config SND_BCM2708_SOC_ALLO_KATANA_DAC
2387 + tristate "Support for Allo Katana DAC"
2388 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2389 + depends on I2C
2390 + select REGMAP_I2C
2391 + select SND_AUDIO_GRAPH_CARD
2392 + help
2393 + Say Y or M if you want to add support for Allo Katana DAC.
2394 +
2395 +config SND_BCM2708_SOC_FE_PI_AUDIO
2396 + tristate "Support for Fe-Pi-Audio"
2397 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2398 + select SND_SOC_SGTL5000
2399 + help
2400 + Say Y or M if you want to add support for Fe-Pi-Audio.
2401 +
2402 +config SND_PISOUND
2403 + tristate "Support for Blokas Labs pisound"
2404 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2405 + select SND_RAWMIDI
2406 + help
2407 + Say Y or M if you want to add support for Blokas Labs pisound.
2408 +
2409 +config SND_RPI_SIMPLE_SOUNDCARD
2410 + tristate "Support for Raspberry Pi simple soundcards"
2411 + help
2412 + Say Y or M if you want to add support Raspbery Pi simple soundcards
2413 +
2414 +config SND_RPI_WM8804_SOUNDCARD
2415 + tristate "Support for Raspberry Pi generic WM8804 soundcards"
2416 + help
2417 + Say Y or M if you want to add support for the Raspberry Pi
2418 + generic driver for WM8804 based soundcards.
2419 --- a/sound/soc/bcm/Makefile
2420 +++ b/sound/soc/bcm/Makefile
2421 @@ -12,4 +12,70 @@ obj-$(CONFIG_SND_SOC_CYGNUS) += snd-soc-
2422 # BCM63XX Platform Support
2423 snd-soc-63xx-objs := bcm63xx-i2s-whistler.o bcm63xx-pcm-whistler.o
2424
2425 -obj-$(CONFIG_SND_BCM63XX_I2S_WHISTLER) += snd-soc-63xx.o
2426 \ No newline at end of file
2427 +obj-$(CONFIG_SND_BCM63XX_I2S_WHISTLER) += snd-soc-63xx.o
2428 +
2429 +# Google voiceHAT custom codec support
2430 +snd-soc-googlevoicehat-codec-objs := googlevoicehat-codec.o
2431 +
2432 +# BCM2708 Machine Support
2433 +snd-soc-hifiberry-dacplus-objs := hifiberry_dacplus.o
2434 +snd-soc-hifiberry-dacplushd-objs := hifiberry_dacplushd.o
2435 +snd-soc-hifiberry-dacplusadc-objs := hifiberry_dacplusadc.o
2436 +snd-soc-hifiberry-dacplusadcpro-objs := hifiberry_dacplusadcpro.o
2437 +snd-soc-hifiberry-dacplusdsp-objs := hifiberry_dacplusdsp.o
2438 +snd-soc-justboom-both-objs := justboom-both.o
2439 +snd-soc-justboom-dac-objs := justboom-dac.o
2440 +snd-soc-rpi-cirrus-objs := rpi-cirrus.o
2441 +snd-soc-rpi-proto-objs := rpi-proto.o
2442 +snd-soc-iqaudio-codec-objs := iqaudio-codec.o
2443 +snd-soc-iqaudio-dac-objs := iqaudio-dac.o
2444 + snd-soc-i-sabre-q2m-objs := i-sabre-q2m.o
2445 +snd-soc-audioinjector-pi-soundcard-objs := audioinjector-pi-soundcard.o
2446 +snd-soc-audioinjector-octo-soundcard-objs := audioinjector-octo-soundcard.o
2447 +snd-soc-audioinjector-isolated-soundcard-objs := audioinjector-isolated-soundcard.o
2448 +snd-soc-audiosense-pi-objs := audiosense-pi.o
2449 +snd-soc-digidac1-soundcard-objs := digidac1-soundcard.o
2450 +snd-soc-dionaudio-loco-objs := dionaudio_loco.o
2451 +snd-soc-dionaudio-loco-v2-objs := dionaudio_loco-v2.o
2452 +snd-soc-allo-boss-dac-objs := allo-boss-dac.o
2453 +snd-soc-allo-boss2-dac-objs := allo-boss2-dac.o
2454 +snd-soc-allo-piano-dac-objs := allo-piano-dac.o
2455 +snd-soc-allo-piano-dac-plus-objs := allo-piano-dac-plus.o
2456 +snd-soc-allo-katana-codec-objs := allo-katana-codec.o
2457 +snd-soc-pisound-objs := pisound.o
2458 +snd-soc-fe-pi-audio-objs := fe-pi-audio.o
2459 +snd-soc-rpi-simple-soundcard-objs := rpi-simple-soundcard.o
2460 +snd-soc-rpi-wm8804-soundcard-objs := rpi-wm8804-soundcard.o
2461 +snd-soc-pifi-40-objs := pifi-40.o
2462 +
2463 +obj-$(CONFIG_SND_BCM2708_SOC_GOOGLEVOICEHAT_SOUNDCARD) += snd-soc-googlevoicehat-codec.o
2464 +obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS) += snd-soc-hifiberry-dacplus.o
2465 +obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUSHD) += snd-soc-hifiberry-dacplushd.o
2466 +obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUSADC) += snd-soc-hifiberry-dacplusadc.o
2467 +obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUSADCPRO) += snd-soc-hifiberry-dacplusadcpro.o
2468 +obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUSDSP) += snd-soc-hifiberry-dacplusdsp.o
2469 +obj-$(CONFIG_SND_BCM2708_SOC_JUSTBOOM_BOTH) += snd-soc-justboom-both.o
2470 +obj-$(CONFIG_SND_BCM2708_SOC_JUSTBOOM_DAC) += snd-soc-justboom-dac.o
2471 +obj-$(CONFIG_SND_BCM2708_SOC_RPI_CIRRUS) += snd-soc-rpi-cirrus.o
2472 +obj-$(CONFIG_SND_BCM2708_SOC_RPI_PROTO) += snd-soc-rpi-proto.o
2473 +obj-$(CONFIG_SND_BCM2708_SOC_IQAUDIO_CODEC) += snd-soc-iqaudio-codec.o
2474 +obj-$(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) += snd-soc-iqaudio-dac.o
2475 +obj-$(CONFIG_SND_BCM2708_SOC_I_SABRE_Q2M) += snd-soc-i-sabre-q2m.o
2476 +obj-$(CONFIG_SND_AUDIOINJECTOR_PI_SOUNDCARD) += snd-soc-audioinjector-pi-soundcard.o
2477 +obj-$(CONFIG_SND_AUDIOINJECTOR_OCTO_SOUNDCARD) += snd-soc-audioinjector-octo-soundcard.o
2478 +obj-$(CONFIG_SND_AUDIOINJECTOR_ISOLATED_SOUNDCARD) += snd-soc-audioinjector-isolated-soundcard.o
2479 +obj-$(CONFIG_SND_AUDIOSENSE_PI) += snd-soc-audiosense-pi.o
2480 +obj-$(CONFIG_SND_DIGIDAC1_SOUNDCARD) += snd-soc-digidac1-soundcard.o
2481 +obj-$(CONFIG_SND_BCM2708_SOC_DIONAUDIO_LOCO) += snd-soc-dionaudio-loco.o
2482 +obj-$(CONFIG_SND_BCM2708_SOC_DIONAUDIO_LOCO_V2) += snd-soc-dionaudio-loco-v2.o
2483 +obj-$(CONFIG_SND_BCM2708_SOC_ALLO_BOSS_DAC) += snd-soc-allo-boss-dac.o
2484 +obj-$(CONFIG_SND_BCM2708_SOC_ALLO_BOSS2_DAC) += snd-soc-allo-boss2-dac.o
2485 +obj-$(CONFIG_SND_BCM2708_SOC_ALLO_PIANO_DAC) += snd-soc-allo-piano-dac.o
2486 +obj-$(CONFIG_SND_BCM2708_SOC_ALLO_PIANO_DAC_PLUS) += snd-soc-allo-piano-dac-plus.o
2487 +obj-$(CONFIG_SND_BCM2708_SOC_ALLO_KATANA_DAC) += snd-soc-allo-katana-codec.o
2488 +obj-$(CONFIG_SND_PISOUND) += snd-soc-pisound.o
2489 +obj-$(CONFIG_SND_BCM2708_SOC_FE_PI_AUDIO) += snd-soc-fe-pi-audio.o
2490 +obj-$(CONFIG_SND_RPI_SIMPLE_SOUNDCARD) += snd-soc-rpi-simple-soundcard.o
2491 +obj-$(CONFIG_SND_RPI_WM8804_SOUNDCARD) += snd-soc-rpi-wm8804-soundcard.o
2492 +obj-$(CONFIG_SND_BCM2708_SOC_PIFI_40) += snd-soc-pifi-40.o
2493 +
2494 --- /dev/null
2495 +++ b/sound/soc/bcm/allo-boss-dac.c
2496 @@ -0,0 +1,456 @@
2497 +/*
2498 + * ALSA ASoC Machine Driver for Allo Boss DAC
2499 + *
2500 + * Author: Baswaraj K <jaikumar@cem-solutions.net>
2501 + * Copyright 2017
2502 + * based on code by Daniel Matuschek,
2503 + * Stuart MacLean <stuart@hifiberry.com>
2504 + * based on code by Florian Meier <florian.meier@koalo.de>
2505 + *
2506 + * This program is free software; you can redistribute it and/or
2507 + * modify it under the terms of the GNU General Public License
2508 + * version 2 as published by the Free Software Foundation.
2509 + *
2510 + * This program is distributed in the hope that it will be useful, but
2511 + * WITHOUT ANY WARRANTY; without even the implied warranty of
2512 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2513 + * General Public License for more details.
2514 + */
2515 +
2516 +#include <linux/module.h>
2517 +#include <linux/gpio/consumer.h>
2518 +#include <linux/platform_device.h>
2519 +#include <linux/clk.h>
2520 +#include <linux/delay.h>
2521 +
2522 +#include <sound/core.h>
2523 +#include <sound/pcm.h>
2524 +#include <sound/pcm_params.h>
2525 +#include <sound/soc.h>
2526 +#include "../codecs/pcm512x.h"
2527 +
2528 +#define ALLO_BOSS_NOCLOCK 0
2529 +#define ALLO_BOSS_CLK44EN 1
2530 +#define ALLO_BOSS_CLK48EN 2
2531 +
2532 +struct pcm512x_priv {
2533 + struct regmap *regmap;
2534 + struct clk *sclk;
2535 +};
2536 +
2537 +static struct gpio_desc *mute_gpio;
2538 +
2539 +/* Clock rate of CLK44EN attached to GPIO6 pin */
2540 +#define CLK_44EN_RATE 45158400UL
2541 +/* Clock rate of CLK48EN attached to GPIO3 pin */
2542 +#define CLK_48EN_RATE 49152000UL
2543 +
2544 +static bool slave;
2545 +static bool snd_soc_allo_boss_master;
2546 +static bool digital_gain_0db_limit = true;
2547 +
2548 +static void snd_allo_boss_select_clk(struct snd_soc_component *component,
2549 + int clk_id)
2550 +{
2551 + switch (clk_id) {
2552 + case ALLO_BOSS_NOCLOCK:
2553 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x24, 0x00);
2554 + break;
2555 + case ALLO_BOSS_CLK44EN:
2556 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x24, 0x20);
2557 + break;
2558 + case ALLO_BOSS_CLK48EN:
2559 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x24, 0x04);
2560 + break;
2561 + }
2562 +}
2563 +
2564 +static void snd_allo_boss_clk_gpio(struct snd_soc_component *component)
2565 +{
2566 + snd_soc_component_update_bits(component, PCM512x_GPIO_EN, 0x24, 0x24);
2567 + snd_soc_component_update_bits(component, PCM512x_GPIO_OUTPUT_3, 0x0f, 0x02);
2568 + snd_soc_component_update_bits(component, PCM512x_GPIO_OUTPUT_6, 0x0f, 0x02);
2569 +}
2570 +
2571 +static bool snd_allo_boss_is_sclk(struct snd_soc_component *component)
2572 +{
2573 + unsigned int sck;
2574 +
2575 + sck = snd_soc_component_read(component, PCM512x_RATE_DET_4);
2576 + return (!(sck & 0x40));
2577 +}
2578 +
2579 +static bool snd_allo_boss_is_sclk_sleep(
2580 + struct snd_soc_component *component)
2581 +{
2582 + msleep(2);
2583 + return snd_allo_boss_is_sclk(component);
2584 +}
2585 +
2586 +static bool snd_allo_boss_is_master_card(struct snd_soc_component *component)
2587 +{
2588 + bool isClk44EN, isClk48En, isNoClk;
2589 +
2590 + snd_allo_boss_clk_gpio(component);
2591 +
2592 + snd_allo_boss_select_clk(component, ALLO_BOSS_CLK44EN);
2593 + isClk44EN = snd_allo_boss_is_sclk_sleep(component);
2594 +
2595 + snd_allo_boss_select_clk(component, ALLO_BOSS_NOCLOCK);
2596 + isNoClk = snd_allo_boss_is_sclk_sleep(component);
2597 +
2598 + snd_allo_boss_select_clk(component, ALLO_BOSS_CLK48EN);
2599 + isClk48En = snd_allo_boss_is_sclk_sleep(component);
2600 +
2601 + return (isClk44EN && isClk48En && !isNoClk);
2602 +}
2603 +
2604 +static int snd_allo_boss_clk_for_rate(int sample_rate)
2605 +{
2606 + int type;
2607 +
2608 + switch (sample_rate) {
2609 + case 11025:
2610 + case 22050:
2611 + case 44100:
2612 + case 88200:
2613 + case 176400:
2614 + case 352800:
2615 + type = ALLO_BOSS_CLK44EN;
2616 + break;
2617 + default:
2618 + type = ALLO_BOSS_CLK48EN;
2619 + break;
2620 + }
2621 + return type;
2622 +}
2623 +
2624 +static void snd_allo_boss_set_sclk(struct snd_soc_component *component,
2625 + int sample_rate)
2626 +{
2627 + struct pcm512x_priv *pcm512x = snd_soc_component_get_drvdata(component);
2628 +
2629 + if (!IS_ERR(pcm512x->sclk)) {
2630 + int ctype;
2631 +
2632 + ctype = snd_allo_boss_clk_for_rate(sample_rate);
2633 + clk_set_rate(pcm512x->sclk, (ctype == ALLO_BOSS_CLK44EN)
2634 + ? CLK_44EN_RATE : CLK_48EN_RATE);
2635 + snd_allo_boss_select_clk(component, ctype);
2636 + }
2637 +}
2638 +
2639 +static int snd_allo_boss_init(struct snd_soc_pcm_runtime *rtd)
2640 +{
2641 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
2642 + struct pcm512x_priv *priv = snd_soc_component_get_drvdata(component);
2643 +
2644 + if (slave)
2645 + snd_soc_allo_boss_master = false;
2646 + else
2647 + snd_soc_allo_boss_master =
2648 + snd_allo_boss_is_master_card(component);
2649 +
2650 + if (snd_soc_allo_boss_master) {
2651 + struct snd_soc_dai_link *dai = rtd->dai_link;
2652 +
2653 + dai->name = "BossDAC";
2654 + dai->stream_name = "Boss DAC HiFi [Master]";
2655 + dai->dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
2656 + | SND_SOC_DAIFMT_CBM_CFM;
2657 +
2658 + snd_soc_component_update_bits(component, PCM512x_BCLK_LRCLK_CFG, 0x31, 0x11);
2659 + snd_soc_component_update_bits(component, PCM512x_MASTER_MODE, 0x03, 0x03);
2660 + snd_soc_component_update_bits(component, PCM512x_MASTER_CLKDIV_2, 0x7f, 63);
2661 + /*
2662 + * Default sclk to CLK_48EN_RATE, otherwise codec
2663 + * pcm512x_dai_startup_master method could call
2664 + * snd_pcm_hw_constraint_ratnums using CLK_44EN/64
2665 + * which will mask 384k sample rate.
2666 + */
2667 + if (!IS_ERR(priv->sclk))
2668 + clk_set_rate(priv->sclk, CLK_48EN_RATE);
2669 + } else {
2670 + priv->sclk = ERR_PTR(-ENOENT);
2671 + }
2672 +
2673 + snd_soc_component_update_bits(component, PCM512x_GPIO_EN, 0x08, 0x08);
2674 + snd_soc_component_update_bits(component, PCM512x_GPIO_OUTPUT_4, 0x0f, 0x02);
2675 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x08, 0x08);
2676 +
2677 + if (digital_gain_0db_limit) {
2678 + int ret;
2679 + struct snd_soc_card *card = rtd->card;
2680 +
2681 + ret = snd_soc_limit_volume(card, "Digital Playback Volume",
2682 + 207);
2683 + if (ret < 0)
2684 + dev_warn(card->dev, "Failed to set volume limit: %d\n",
2685 + ret);
2686 + }
2687 +
2688 + return 0;
2689 +}
2690 +
2691 +static int snd_allo_boss_update_rate_den(
2692 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
2693 +{
2694 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
2695 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
2696 + struct pcm512x_priv *pcm512x = snd_soc_component_get_drvdata(component);
2697 + struct snd_ratnum *rats_no_pll;
2698 + unsigned int num = 0, den = 0;
2699 + int err;
2700 +
2701 + rats_no_pll = devm_kzalloc(rtd->dev, sizeof(*rats_no_pll), GFP_KERNEL);
2702 + if (!rats_no_pll)
2703 + return -ENOMEM;
2704 +
2705 + rats_no_pll->num = clk_get_rate(pcm512x->sclk) / 64;
2706 + rats_no_pll->den_min = 1;
2707 + rats_no_pll->den_max = 128;
2708 + rats_no_pll->den_step = 1;
2709 +
2710 + err = snd_interval_ratnum(hw_param_interval(params,
2711 + SNDRV_PCM_HW_PARAM_RATE), 1, rats_no_pll, &num, &den);
2712 + if (err >= 0 && den) {
2713 + params->rate_num = num;
2714 + params->rate_den = den;
2715 + }
2716 +
2717 + devm_kfree(rtd->dev, rats_no_pll);
2718 + return 0;
2719 +}
2720 +
2721 +static void snd_allo_boss_gpio_mute(struct snd_soc_card *card)
2722 +{
2723 + if (mute_gpio)
2724 + gpiod_set_value_cansleep(mute_gpio, 1);
2725 +}
2726 +
2727 +static void snd_allo_boss_gpio_unmute(struct snd_soc_card *card)
2728 +{
2729 + if (mute_gpio)
2730 + gpiod_set_value_cansleep(mute_gpio, 0);
2731 +}
2732 +
2733 +static int snd_allo_boss_set_bias_level(struct snd_soc_card *card,
2734 + struct snd_soc_dapm_context *dapm, enum snd_soc_bias_level level)
2735 +{
2736 + struct snd_soc_pcm_runtime *rtd;
2737 + struct snd_soc_dai *codec_dai;
2738 +
2739 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
2740 + codec_dai = asoc_rtd_to_codec(rtd, 0);
2741 +
2742 + if (dapm->dev != codec_dai->dev)
2743 + return 0;
2744 +
2745 + switch (level) {
2746 + case SND_SOC_BIAS_PREPARE:
2747 + if (dapm->bias_level != SND_SOC_BIAS_STANDBY)
2748 + break;
2749 + /* UNMUTE DAC */
2750 + snd_allo_boss_gpio_unmute(card);
2751 + break;
2752 +
2753 + case SND_SOC_BIAS_STANDBY:
2754 + if (dapm->bias_level != SND_SOC_BIAS_PREPARE)
2755 + break;
2756 + /* MUTE DAC */
2757 + snd_allo_boss_gpio_mute(card);
2758 + break;
2759 +
2760 + default:
2761 + break;
2762 + }
2763 +
2764 + return 0;
2765 +}
2766 +
2767 +static int snd_allo_boss_hw_params(
2768 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
2769 +{
2770 + int ret = 0;
2771 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
2772 + int channels = params_channels(params);
2773 + int width = snd_pcm_format_physical_width(params_format(params));
2774 +
2775 + if (snd_soc_allo_boss_master) {
2776 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
2777 +
2778 + snd_allo_boss_set_sclk(component,
2779 + params_rate(params));
2780 +
2781 + ret = snd_allo_boss_update_rate_den(
2782 + substream, params);
2783 + if (ret)
2784 + return ret;
2785 + }
2786 +
2787 + ret = snd_soc_dai_set_bclk_ratio(asoc_rtd_to_cpu(rtd, 0), channels * width);
2788 + if (ret)
2789 + return ret;
2790 + ret = snd_soc_dai_set_bclk_ratio(asoc_rtd_to_codec(rtd, 0), channels * width);
2791 + return ret;
2792 +}
2793 +
2794 +static int snd_allo_boss_startup(
2795 + struct snd_pcm_substream *substream)
2796 +{
2797 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
2798 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
2799 + struct snd_soc_card *card = rtd->card;
2800 +
2801 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x08, 0x08);
2802 + snd_allo_boss_gpio_mute(card);
2803 +
2804 + if (snd_soc_allo_boss_master) {
2805 + struct pcm512x_priv *priv = snd_soc_component_get_drvdata(component);
2806 + /*
2807 + * Default sclk to CLK_48EN_RATE, otherwise codec
2808 + * pcm512x_dai_startup_master method could call
2809 + * snd_pcm_hw_constraint_ratnums using CLK_44EN/64
2810 + * which will mask 384k sample rate.
2811 + */
2812 + if (!IS_ERR(priv->sclk))
2813 + clk_set_rate(priv->sclk, CLK_48EN_RATE);
2814 + }
2815 +
2816 + return 0;
2817 +}
2818 +
2819 +static void snd_allo_boss_shutdown(
2820 + struct snd_pcm_substream *substream)
2821 +{
2822 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
2823 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
2824 +
2825 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x08, 0x00);
2826 +}
2827 +
2828 +static int snd_allo_boss_prepare(
2829 + struct snd_pcm_substream *substream)
2830 +{
2831 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
2832 + struct snd_soc_card *card = rtd->card;
2833 +
2834 + snd_allo_boss_gpio_unmute(card);
2835 + return 0;
2836 +}
2837 +/* machine stream operations */
2838 +static struct snd_soc_ops snd_allo_boss_ops = {
2839 + .hw_params = snd_allo_boss_hw_params,
2840 + .startup = snd_allo_boss_startup,
2841 + .shutdown = snd_allo_boss_shutdown,
2842 + .prepare = snd_allo_boss_prepare,
2843 +};
2844 +
2845 +SND_SOC_DAILINK_DEFS(allo_boss,
2846 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
2847 + DAILINK_COMP_ARRAY(COMP_CODEC("pcm512x.1-004d", "pcm512x-hifi")),
2848 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
2849 +
2850 +static struct snd_soc_dai_link snd_allo_boss_dai[] = {
2851 +{
2852 + .name = "Boss DAC",
2853 + .stream_name = "Boss DAC HiFi",
2854 + .dai_fmt = SND_SOC_DAIFMT_I2S |
2855 + SND_SOC_DAIFMT_NB_NF |
2856 + SND_SOC_DAIFMT_CBS_CFS,
2857 + .ops = &snd_allo_boss_ops,
2858 + .init = snd_allo_boss_init,
2859 + SND_SOC_DAILINK_REG(allo_boss),
2860 +},
2861 +};
2862 +
2863 +/* audio machine driver */
2864 +static struct snd_soc_card snd_allo_boss = {
2865 + .name = "BossDAC",
2866 + .owner = THIS_MODULE,
2867 + .dai_link = snd_allo_boss_dai,
2868 + .num_links = ARRAY_SIZE(snd_allo_boss_dai),
2869 +};
2870 +
2871 +static int snd_allo_boss_probe(struct platform_device *pdev)
2872 +{
2873 + int ret = 0;
2874 +
2875 + snd_allo_boss.dev = &pdev->dev;
2876 +
2877 + if (pdev->dev.of_node) {
2878 + struct device_node *i2s_node;
2879 + struct snd_soc_dai_link *dai;
2880 +
2881 + dai = &snd_allo_boss_dai[0];
2882 + i2s_node = of_parse_phandle(pdev->dev.of_node,
2883 + "i2s-controller", 0);
2884 +
2885 + if (i2s_node) {
2886 + dai->cpus->dai_name = NULL;
2887 + dai->cpus->of_node = i2s_node;
2888 + dai->platforms->name = NULL;
2889 + dai->platforms->of_node = i2s_node;
2890 + }
2891 +
2892 + digital_gain_0db_limit = !of_property_read_bool(
2893 + pdev->dev.of_node, "allo,24db_digital_gain");
2894 + slave = of_property_read_bool(pdev->dev.of_node,
2895 + "allo,slave");
2896 +
2897 + mute_gpio = devm_gpiod_get_optional(&pdev->dev, "mute",
2898 + GPIOD_OUT_LOW);
2899 + if (IS_ERR(mute_gpio)) {
2900 + ret = PTR_ERR(mute_gpio);
2901 + dev_err(&pdev->dev,
2902 + "failed to get mute gpio: %d\n", ret);
2903 + return ret;
2904 + }
2905 +
2906 + if (mute_gpio)
2907 + snd_allo_boss.set_bias_level =
2908 + snd_allo_boss_set_bias_level;
2909 +
2910 + ret = snd_soc_register_card(&snd_allo_boss);
2911 + if (ret) {
2912 + dev_err(&pdev->dev,
2913 + "snd_soc_register_card() failed: %d\n", ret);
2914 + return ret;
2915 + }
2916 +
2917 + if (mute_gpio)
2918 + snd_allo_boss_gpio_mute(&snd_allo_boss);
2919 +
2920 + return 0;
2921 + }
2922 +
2923 + return -EINVAL;
2924 +}
2925 +
2926 +static int snd_allo_boss_remove(struct platform_device *pdev)
2927 +{
2928 + snd_allo_boss_gpio_mute(&snd_allo_boss);
2929 + return snd_soc_unregister_card(&snd_allo_boss);
2930 +}
2931 +
2932 +static const struct of_device_id snd_allo_boss_of_match[] = {
2933 + { .compatible = "allo,boss-dac", },
2934 + { /* sentinel */ },
2935 +};
2936 +MODULE_DEVICE_TABLE(of, snd_allo_boss_of_match);
2937 +
2938 +static struct platform_driver snd_allo_boss_driver = {
2939 + .driver = {
2940 + .name = "snd-allo-boss-dac",
2941 + .owner = THIS_MODULE,
2942 + .of_match_table = snd_allo_boss_of_match,
2943 + },
2944 + .probe = snd_allo_boss_probe,
2945 + .remove = snd_allo_boss_remove,
2946 +};
2947 +
2948 +module_platform_driver(snd_allo_boss_driver);
2949 +
2950 +MODULE_AUTHOR("Baswaraj K <jaikumar@cem-solutions.net>");
2951 +MODULE_DESCRIPTION("ALSA ASoC Machine Driver for Allo Boss DAC");
2952 +MODULE_LICENSE("GPL v2");
2953 --- /dev/null
2954 +++ b/sound/soc/bcm/allo-boss2-dac.c
2955 @@ -0,0 +1,1133 @@
2956 +/*
2957 + * Driver for the ALLO KATANA CODEC
2958 + *
2959 + * Author: Jaikumar <sudeepkumar@cem-solutions.net>
2960 + * Copyright 2018
2961 + *
2962 + * This program is free software; you can redistribute it and/or
2963 + * modify it under the terms of the GNU General Public License
2964 + * version 2 as published by the Free Software Foundation.
2965 + *
2966 + * This program is distributed in the hope that it will be useful, but
2967 + * WITHOUT ANY WARRANTY; without even the implied warranty of
2968 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2969 + * General Public License for more details.
2970 + */
2971 +
2972 +#include <linux/module.h>
2973 +#include <linux/moduleparam.h>
2974 +#include <linux/kernel.h>
2975 +#include <linux/init.h>
2976 +#include <linux/delay.h>
2977 +#include <linux/gpio.h>
2978 +#include <linux/gpio/consumer.h>
2979 +#include <linux/platform_device.h>
2980 +#include <linux/pm.h>
2981 +#include <linux/i2c.h>
2982 +#include <linux/of_device.h>
2983 +#include <linux/regmap.h>
2984 +#include <linux/slab.h>
2985 +#include <sound/core.h>
2986 +#include <sound/pcm.h>
2987 +#include <sound/pcm_params.h>
2988 +#include <sound/soc.h>
2989 +#include <sound/soc-dapm.h>
2990 +#include <sound/initval.h>
2991 +#include <sound/tlv.h>
2992 +#include <linux/of_gpio.h>
2993 +#include <linux/regulator/consumer.h>
2994 +#include <linux/pm_runtime.h>
2995 +#include <linux/of_irq.h>
2996 +#include <linux/completion.h>
2997 +#include <linux/mutex.h>
2998 +#include <linux/workqueue.h>
2999 +#include <sound/jack.h>
3000 +
3001 +#include "../codecs/cs43130.h"
3002 +
3003 +#include <linux/clk.h>
3004 +#include <linux/gcd.h>
3005 +#define DEBUG
3006 +
3007 +#define CS43130_DSD_EN_MASK 0x10
3008 +#define CS43130_PDN_DONE_INT_MASK 0x00
3009 +
3010 +static struct gpio_desc *snd_allo_clk44gpio;
3011 +static struct gpio_desc *snd_allo_clk48gpio;
3012 +
3013 +struct cs43130_priv {
3014 + struct snd_soc_component *component;
3015 + struct regmap *regmap;
3016 + struct regulator_bulk_data supplies[CS43130_NUM_SUPPLIES];
3017 + struct gpio_desc *reset_gpio;
3018 + unsigned int dev_id; /* codec device ID */
3019 + int xtal_ibias;
3020 + /* shared by both DAIs */
3021 + struct mutex clk_mutex;
3022 + int clk_req;
3023 + bool pll_bypass;
3024 + struct completion xtal_rdy;
3025 + struct completion pll_rdy;
3026 + unsigned int mclk;
3027 + unsigned int mclk_int;
3028 + int mclk_int_src;
3029 +
3030 + /* DAI specific */
3031 + struct cs43130_dai dais[CS43130_DAI_ID_MAX];
3032 +
3033 + /* HP load specific */
3034 + bool dc_meas;
3035 + bool ac_meas;
3036 + bool hpload_done;
3037 + struct completion hpload_evt;
3038 + unsigned int hpload_stat;
3039 + u16 hpload_dc[2];
3040 + u16 dc_threshold[CS43130_DC_THRESHOLD];
3041 + u16 ac_freq[CS43130_AC_FREQ];
3042 + u16 hpload_ac[CS43130_AC_FREQ][2];
3043 + struct workqueue_struct *wq;
3044 + struct work_struct work;
3045 + struct snd_soc_jack jack;
3046 +};
3047 +
3048 +static const struct reg_default cs43130_reg_defaults[] = {
3049 + {CS43130_SYS_CLK_CTL_1, 0x06},
3050 + {CS43130_SP_SRATE, 0x01},
3051 + {CS43130_SP_BITSIZE, 0x05},
3052 + {CS43130_PAD_INT_CFG, 0x03},
3053 + {CS43130_PWDN_CTL, 0xFE},
3054 + {CS43130_CRYSTAL_SET, 0x04},
3055 + {CS43130_PLL_SET_1, 0x00},
3056 + {CS43130_PLL_SET_2, 0x00},
3057 + {CS43130_PLL_SET_3, 0x00},
3058 + {CS43130_PLL_SET_4, 0x00},
3059 + {CS43130_PLL_SET_5, 0x40},
3060 + {CS43130_PLL_SET_6, 0x10},
3061 + {CS43130_PLL_SET_7, 0x80},
3062 + {CS43130_PLL_SET_8, 0x03},
3063 + {CS43130_PLL_SET_9, 0x02},
3064 + {CS43130_PLL_SET_10, 0x02},
3065 + {CS43130_CLKOUT_CTL, 0x00},
3066 + {CS43130_ASP_NUM_1, 0x01},
3067 + {CS43130_ASP_NUM_2, 0x00},
3068 + {CS43130_ASP_DEN_1, 0x08},
3069 + {CS43130_ASP_DEN_2, 0x00},
3070 + {CS43130_ASP_LRCK_HI_TIME_1, 0x1F},
3071 + {CS43130_ASP_LRCK_HI_TIME_2, 0x00},
3072 + {CS43130_ASP_LRCK_PERIOD_1, 0x3F},
3073 + {CS43130_ASP_LRCK_PERIOD_2, 0x00},
3074 + {CS43130_ASP_CLOCK_CONF, 0x0C},
3075 + {CS43130_ASP_FRAME_CONF, 0x0A},
3076 + {CS43130_XSP_NUM_1, 0x01},
3077 + {CS43130_XSP_NUM_2, 0x00},
3078 + {CS43130_XSP_DEN_1, 0x02},
3079 + {CS43130_XSP_DEN_2, 0x00},
3080 + {CS43130_XSP_LRCK_HI_TIME_1, 0x1F},
3081 + {CS43130_XSP_LRCK_HI_TIME_2, 0x00},
3082 + {CS43130_XSP_LRCK_PERIOD_1, 0x3F},
3083 + {CS43130_XSP_LRCK_PERIOD_2, 0x00},
3084 + {CS43130_XSP_CLOCK_CONF, 0x0C},
3085 + {CS43130_XSP_FRAME_CONF, 0x0A},
3086 + {CS43130_ASP_CH_1_LOC, 0x00},
3087 + {CS43130_ASP_CH_2_LOC, 0x00},
3088 + {CS43130_ASP_CH_1_SZ_EN, 0x06},
3089 + {CS43130_ASP_CH_2_SZ_EN, 0x0E},
3090 + {CS43130_XSP_CH_1_LOC, 0x00},
3091 + {CS43130_XSP_CH_2_LOC, 0x00},
3092 + {CS43130_XSP_CH_1_SZ_EN, 0x06},
3093 + {CS43130_XSP_CH_2_SZ_EN, 0x0E},
3094 + {CS43130_DSD_VOL_B, 0x78},
3095 + {CS43130_DSD_VOL_A, 0x78},
3096 + {CS43130_DSD_PATH_CTL_1, 0xA8},
3097 + {CS43130_DSD_INT_CFG, 0x00},
3098 + {CS43130_DSD_PATH_CTL_2, 0x02},
3099 + {CS43130_DSD_PCM_MIX_CTL, 0x00},
3100 + {CS43130_DSD_PATH_CTL_3, 0x40},
3101 + {CS43130_HP_OUT_CTL_1, 0x30},
3102 + {CS43130_PCM_FILT_OPT, 0x02},
3103 + {CS43130_PCM_VOL_B, 0x78},
3104 + {CS43130_PCM_VOL_A, 0x78},
3105 + {CS43130_PCM_PATH_CTL_1, 0xA8},
3106 + {CS43130_PCM_PATH_CTL_2, 0x00},
3107 + {CS43130_CLASS_H_CTL, 0x1E},
3108 + {CS43130_HP_DETECT, 0x04},
3109 + {CS43130_HP_LOAD_1, 0x00},
3110 + {CS43130_HP_MEAS_LOAD_1, 0x00},
3111 + {CS43130_HP_MEAS_LOAD_2, 0x00},
3112 + {CS43130_INT_MASK_1, 0xFF},
3113 + {CS43130_INT_MASK_2, 0xFF},
3114 + {CS43130_INT_MASK_3, 0xFF},
3115 + {CS43130_INT_MASK_4, 0xFF},
3116 + {CS43130_INT_MASK_5, 0xFF},
3117 +};
3118 +static bool cs43130_volatile_register(struct device *dev, unsigned int reg)
3119 +{
3120 + switch (reg) {
3121 + case CS43130_INT_STATUS_1 ... CS43130_INT_STATUS_5:
3122 + case CS43130_HP_DC_STAT_1 ... CS43130_HP_DC_STAT_2:
3123 + case CS43130_HP_AC_STAT_1 ... CS43130_HP_AC_STAT_2:
3124 + return true;
3125 + default:
3126 + return false;
3127 + }
3128 +}
3129 +
3130 +static const char * const pcm_spd_texts[] = {
3131 + "Fast",
3132 + "Slow",
3133 +};
3134 +
3135 +static SOC_ENUM_SINGLE_DECL(pcm_spd_enum, CS43130_PCM_FILT_OPT, 7,
3136 + pcm_spd_texts);
3137 +
3138 +static const SNDRV_CTL_TLVD_DECLARE_DB_MINMAX(master_tlv, -12750, 0);
3139 +
3140 +static const struct snd_kcontrol_new cs43130_controls[] = {
3141 + SOC_DOUBLE_R_TLV("Master Playback Volume", CS43130_PCM_VOL_B,
3142 + CS43130_PCM_VOL_A, 0, 255, 1, master_tlv),
3143 + SOC_DOUBLE("Master Playback Switch", CS43130_PCM_PATH_CTL_1,
3144 + 0, 1, 1, 1),
3145 + SOC_DOUBLE_R_TLV("Digital Playback Volume", CS43130_DSD_VOL_B,
3146 + CS43130_DSD_VOL_A, 0, 255, 1, master_tlv),
3147 + SOC_DOUBLE("Digital Playback Switch", CS43130_DSD_PATH_CTL_1,
3148 + 0, 1, 1, 1),
3149 + SOC_SINGLE("HV_Enable", CS43130_HP_OUT_CTL_1, 0, 1, 0),
3150 + SOC_ENUM("PCM Filter Speed", pcm_spd_enum),
3151 + SOC_SINGLE("PCM Phase Compensation", CS43130_PCM_FILT_OPT, 6, 1, 0),
3152 + SOC_SINGLE("PCM Nonoversample Emulate", CS43130_PCM_FILT_OPT, 5, 1, 0),
3153 + SOC_SINGLE("PCM High-pass Filter", CS43130_PCM_FILT_OPT, 1, 1, 0),
3154 + SOC_SINGLE("PCM De-emphasis Filter", CS43130_PCM_FILT_OPT, 0, 1, 0),
3155 +};
3156 +
3157 +static bool cs43130_readable_register(struct device *dev, unsigned int reg)
3158 +{
3159 + switch (reg) {
3160 + case CS43130_DEVID_AB ... CS43130_SYS_CLK_CTL_1:
3161 + case CS43130_SP_SRATE ... CS43130_PAD_INT_CFG:
3162 + case CS43130_PWDN_CTL:
3163 + case CS43130_CRYSTAL_SET:
3164 + case CS43130_PLL_SET_1 ... CS43130_PLL_SET_5:
3165 + case CS43130_PLL_SET_6:
3166 + case CS43130_PLL_SET_7:
3167 + case CS43130_PLL_SET_8:
3168 + case CS43130_PLL_SET_9:
3169 + case CS43130_PLL_SET_10:
3170 + case CS43130_CLKOUT_CTL:
3171 + case CS43130_ASP_NUM_1 ... CS43130_ASP_FRAME_CONF:
3172 + case CS43130_XSP_NUM_1 ... CS43130_XSP_FRAME_CONF:
3173 + case CS43130_ASP_CH_1_LOC:
3174 + case CS43130_ASP_CH_2_LOC:
3175 + case CS43130_ASP_CH_1_SZ_EN:
3176 + case CS43130_ASP_CH_2_SZ_EN:
3177 + case CS43130_XSP_CH_1_LOC:
3178 + case CS43130_XSP_CH_2_LOC:
3179 + case CS43130_XSP_CH_1_SZ_EN:
3180 + case CS43130_XSP_CH_2_SZ_EN:
3181 + case CS43130_DSD_VOL_B ... CS43130_DSD_PATH_CTL_3:
3182 + case CS43130_HP_OUT_CTL_1:
3183 + case CS43130_PCM_FILT_OPT ... CS43130_PCM_PATH_CTL_2:
3184 + case CS43130_CLASS_H_CTL:
3185 + case CS43130_HP_DETECT:
3186 + case CS43130_HP_STATUS:
3187 + case CS43130_HP_LOAD_1:
3188 + case CS43130_HP_MEAS_LOAD_1:
3189 + case CS43130_HP_MEAS_LOAD_2:
3190 + case CS43130_HP_DC_STAT_1:
3191 + case CS43130_HP_DC_STAT_2:
3192 + case CS43130_HP_AC_STAT_1:
3193 + case CS43130_HP_AC_STAT_2:
3194 + case CS43130_HP_LOAD_STAT:
3195 + case CS43130_INT_STATUS_1 ... CS43130_INT_STATUS_5:
3196 + case CS43130_INT_MASK_1 ... CS43130_INT_MASK_5:
3197 + return true;
3198 + default:
3199 + return false;
3200 + }
3201 +}
3202 +static bool cs43130_precious_register(struct device *dev, unsigned int reg)
3203 +{
3204 + switch (reg) {
3205 + case CS43130_INT_STATUS_1 ... CS43130_INT_STATUS_5:
3206 + return true;
3207 + default:
3208 + return false;
3209 + }
3210 +}
3211 +static int cs43130_pcm_pdn(struct snd_soc_component *component)
3212 +{
3213 + struct cs43130_priv *cs43130 =
3214 + snd_soc_component_get_drvdata(component);
3215 + int ret;
3216 + unsigned int reg, pdn_int;
3217 +
3218 + regmap_write(cs43130->regmap, CS43130_DSD_PATH_CTL_2, 0x02);
3219 + regmap_update_bits(cs43130->regmap, CS43130_INT_MASK_1,
3220 + CS43130_PDN_DONE_INT_MASK, 0);
3221 + regmap_update_bits(cs43130->regmap, CS43130_PWDN_CTL,
3222 + CS43130_PDN_HP_MASK, 1 << CS43130_PDN_HP_SHIFT);
3223 + usleep_range(10, 50);
3224 + ret = regmap_read(cs43130->regmap, CS43130_INT_STATUS_1, &reg);
3225 + pdn_int = reg & 0xFE;
3226 + regmap_update_bits(cs43130->regmap, CS43130_PWDN_CTL,
3227 + CS43130_PDN_ASP_MASK, 1 << CS43130_PDN_ASP_SHIFT);
3228 + return 0;
3229 +
3230 +}
3231 +static int cs43130_pwr_up_asp_dac(struct snd_soc_component *component)
3232 +{
3233 + struct cs43130_priv *cs43130 =
3234 + snd_soc_component_get_drvdata(component);
3235 +
3236 + regmap_update_bits(cs43130->regmap, CS43130_PAD_INT_CFG,
3237 + CS43130_ASP_3ST_MASK, 0);
3238 + regmap_write(cs43130->regmap, CS43130_DXD1, 0x99);
3239 + regmap_write(cs43130->regmap, CS43130_DXD13, 0x20);
3240 + regmap_update_bits(cs43130->regmap, CS43130_PWDN_CTL,
3241 + CS43130_PDN_ASP_MASK, 0);
3242 + regmap_update_bits(cs43130->regmap, CS43130_PWDN_CTL,
3243 + CS43130_PDN_HP_MASK, 0);
3244 + usleep_range(10000, 12000);
3245 + regmap_write(cs43130->regmap, CS43130_DXD1, 0x00);
3246 + regmap_write(cs43130->regmap, CS43130_DXD13, 0x00);
3247 + return 0;
3248 +}
3249 +static int cs43130_change_clksrc(struct snd_soc_component *component,
3250 + enum cs43130_mclk_src_sel src)
3251 +{
3252 + int ret;
3253 + struct cs43130_priv *cs43130 =
3254 + snd_soc_component_get_drvdata(component);
3255 + int mclk_int_decoded;
3256 +
3257 + if (src == cs43130->mclk_int_src) {
3258 + /* clk source has not changed */
3259 + return 0;
3260 + }
3261 + switch (cs43130->mclk_int) {
3262 + case CS43130_MCLK_22M:
3263 + mclk_int_decoded = CS43130_MCLK_22P5;
3264 + break;
3265 + case CS43130_MCLK_24M:
3266 + mclk_int_decoded = CS43130_MCLK_24P5;
3267 + break;
3268 + default:
3269 + dev_err(component->dev, "Invalid MCLK INT freq: %u\n",
3270 + cs43130->mclk_int);
3271 + return -EINVAL;
3272 + }
3273 +
3274 + switch (src) {
3275 + case CS43130_MCLK_SRC_EXT:
3276 + cs43130->pll_bypass = true;
3277 + cs43130->mclk_int_src = CS43130_MCLK_SRC_EXT;
3278 + if (cs43130->xtal_ibias == CS43130_XTAL_UNUSED) {
3279 + regmap_update_bits(cs43130->regmap, CS43130_PWDN_CTL,
3280 + CS43130_PDN_XTAL_MASK,
3281 + 1 << CS43130_PDN_XTAL_SHIFT);
3282 + } else {
3283 + reinit_completion(&cs43130->xtal_rdy);
3284 + regmap_update_bits(cs43130->regmap, CS43130_INT_MASK_1,
3285 + CS43130_XTAL_RDY_INT_MASK, 0);
3286 + regmap_update_bits(cs43130->regmap, CS43130_PWDN_CTL,
3287 + CS43130_PDN_XTAL_MASK, 0);
3288 + ret = wait_for_completion_timeout(&cs43130->xtal_rdy,
3289 + msecs_to_jiffies(100));
3290 + regmap_update_bits(cs43130->regmap, CS43130_INT_MASK_1,
3291 + CS43130_XTAL_RDY_INT_MASK,
3292 + 1 << CS43130_XTAL_RDY_INT_SHIFT);
3293 + if (ret == 0) {
3294 + dev_err(component->dev, "Timeout waiting for XTAL_READY interrupt\n");
3295 + return -ETIMEDOUT;
3296 + }
3297 + }
3298 + regmap_update_bits(cs43130->regmap, CS43130_SYS_CLK_CTL_1,
3299 + CS43130_MCLK_SRC_SEL_MASK,
3300 + src << CS43130_MCLK_SRC_SEL_SHIFT);
3301 + regmap_update_bits(cs43130->regmap, CS43130_SYS_CLK_CTL_1,
3302 + CS43130_MCLK_INT_MASK,
3303 + mclk_int_decoded << CS43130_MCLK_INT_SHIFT);
3304 + usleep_range(150, 200);
3305 + regmap_update_bits(cs43130->regmap, CS43130_PWDN_CTL,
3306 + CS43130_PDN_PLL_MASK,
3307 + 1 << CS43130_PDN_PLL_SHIFT);
3308 + break;
3309 + case CS43130_MCLK_SRC_RCO:
3310 + cs43130->mclk_int_src = CS43130_MCLK_SRC_RCO;
3311 +
3312 + regmap_update_bits(cs43130->regmap, CS43130_SYS_CLK_CTL_1,
3313 + CS43130_MCLK_SRC_SEL_MASK,
3314 + src << CS43130_MCLK_SRC_SEL_SHIFT);
3315 + regmap_update_bits(cs43130->regmap, CS43130_SYS_CLK_CTL_1,
3316 + CS43130_MCLK_INT_MASK,
3317 + CS43130_MCLK_22P5 << CS43130_MCLK_INT_SHIFT);
3318 + usleep_range(150, 200);
3319 + regmap_update_bits(cs43130->regmap, CS43130_PWDN_CTL,
3320 + CS43130_PDN_XTAL_MASK,
3321 + 1 << CS43130_PDN_XTAL_SHIFT);
3322 + regmap_update_bits(cs43130->regmap, CS43130_PWDN_CTL,
3323 + CS43130_PDN_PLL_MASK,
3324 + 1 << CS43130_PDN_PLL_SHIFT);
3325 + break;
3326 + default:
3327 + dev_err(component->dev, "Invalid MCLK source value\n");
3328 + return -EINVAL;
3329 + }
3330 +
3331 + return 0;
3332 +}
3333 +static const struct cs43130_bitwidth_map cs43130_bitwidth_table[] = {
3334 + {8, CS43130_SP_BIT_SIZE_8, CS43130_CH_BIT_SIZE_8},
3335 + {16, CS43130_SP_BIT_SIZE_16, CS43130_CH_BIT_SIZE_16},
3336 + {24, CS43130_SP_BIT_SIZE_24, CS43130_CH_BIT_SIZE_24},
3337 + {32, CS43130_SP_BIT_SIZE_32, CS43130_CH_BIT_SIZE_32},
3338 +};
3339 +
3340 +static const struct cs43130_bitwidth_map *cs43130_get_bitwidth_table(
3341 + unsigned int bitwidth)
3342 +{
3343 + int i;
3344 +
3345 + for (i = 0; i < ARRAY_SIZE(cs43130_bitwidth_table); i++) {
3346 + if (cs43130_bitwidth_table[i].bitwidth == bitwidth)
3347 + return &cs43130_bitwidth_table[i];
3348 + }
3349 +
3350 + return NULL;
3351 +}
3352 +static int cs43130_set_bitwidth(int dai_id, unsigned int bitwidth_dai,
3353 + struct regmap *regmap)
3354 +{
3355 + const struct cs43130_bitwidth_map *bw_map;
3356 +
3357 + bw_map = cs43130_get_bitwidth_table(bitwidth_dai);
3358 + if (!bw_map)
3359 + return -EINVAL;
3360 +
3361 + switch (dai_id) {
3362 + case CS43130_ASP_PCM_DAI:
3363 + case CS43130_ASP_DOP_DAI:
3364 + regmap_update_bits(regmap, CS43130_ASP_CH_1_SZ_EN,
3365 + CS43130_CH_BITSIZE_MASK, bw_map->ch_bit);
3366 + regmap_update_bits(regmap, CS43130_ASP_CH_2_SZ_EN,
3367 + CS43130_CH_BITSIZE_MASK, bw_map->ch_bit);
3368 + regmap_update_bits(regmap, CS43130_SP_BITSIZE,
3369 + CS43130_ASP_BITSIZE_MASK, bw_map->sp_bit);
3370 + break;
3371 + case CS43130_XSP_DOP_DAI:
3372 + regmap_update_bits(regmap, CS43130_XSP_CH_1_SZ_EN,
3373 + CS43130_CH_BITSIZE_MASK, bw_map->ch_bit);
3374 + regmap_update_bits(regmap, CS43130_XSP_CH_2_SZ_EN,
3375 + CS43130_CH_BITSIZE_MASK, bw_map->ch_bit);
3376 + regmap_update_bits(regmap, CS43130_SP_BITSIZE,
3377 + CS43130_XSP_BITSIZE_MASK, bw_map->sp_bit <<
3378 + CS43130_XSP_BITSIZE_SHIFT);
3379 + break;
3380 + default:
3381 + return -EINVAL;
3382 + }
3383 +
3384 + return 0;
3385 +}
3386 +static const struct cs43130_rate_map cs43130_rate_table[] = {
3387 + {32000, CS43130_ASP_SPRATE_32K},
3388 + {44100, CS43130_ASP_SPRATE_44_1K},
3389 + {48000, CS43130_ASP_SPRATE_48K},
3390 + {88200, CS43130_ASP_SPRATE_88_2K},
3391 + {96000, CS43130_ASP_SPRATE_96K},
3392 + {176400, CS43130_ASP_SPRATE_176_4K},
3393 + {192000, CS43130_ASP_SPRATE_192K},
3394 + {352800, CS43130_ASP_SPRATE_352_8K},
3395 + {384000, CS43130_ASP_SPRATE_384K},
3396 +};
3397 +
3398 +static const struct cs43130_rate_map *cs43130_get_rate_table(int fs)
3399 +{
3400 + int i;
3401 +
3402 + for (i = 0; i < ARRAY_SIZE(cs43130_rate_table); i++) {
3403 + if (cs43130_rate_table[i].fs == fs)
3404 + return &cs43130_rate_table[i];
3405 + }
3406 +
3407 + return NULL;
3408 +}
3409 +
3410 +static const struct cs43130_clk_gen *cs43130_get_clk_gen(int mclk_int, int fs,
3411 + const struct cs43130_clk_gen *clk_gen_table, int len_clk_gen_table)
3412 +{
3413 + int i;
3414 +
3415 + for (i = 0; i < len_clk_gen_table; i++) {
3416 + if (clk_gen_table[i].mclk_int == mclk_int &&
3417 + clk_gen_table[i].fs == fs)
3418 + return &clk_gen_table[i];
3419 + }
3420 + return NULL;
3421 +}
3422 +
3423 +static int cs43130_set_sp_fmt(int dai_id, unsigned int bitwidth_sclk,
3424 + struct snd_pcm_hw_params *params,
3425 + struct cs43130_priv *cs43130)
3426 +{
3427 + u16 frm_size;
3428 + u16 hi_size;
3429 + u8 frm_delay;
3430 + u8 frm_phase;
3431 + u8 frm_data;
3432 + u8 sclk_edge;
3433 + u8 lrck_edge;
3434 + u8 clk_data;
3435 + u8 loc_ch1;
3436 + u8 loc_ch2;
3437 + u8 dai_mode_val;
3438 + const struct cs43130_clk_gen *clk_gen;
3439 +
3440 + switch (cs43130->dais[dai_id].dai_format) {
3441 + case SND_SOC_DAIFMT_I2S:
3442 + hi_size = bitwidth_sclk;
3443 + frm_delay = 2;
3444 + frm_phase = 0;
3445 + break;
3446 + case SND_SOC_DAIFMT_LEFT_J:
3447 + hi_size = bitwidth_sclk;
3448 + frm_delay = 2;
3449 + frm_phase = 1;
3450 + break;
3451 + case SND_SOC_DAIFMT_DSP_A:
3452 + hi_size = 1;
3453 + frm_delay = 2;
3454 + frm_phase = 1;
3455 + break;
3456 + case SND_SOC_DAIFMT_DSP_B:
3457 + hi_size = 1;
3458 + frm_delay = 0;
3459 + frm_phase = 1;
3460 + break;
3461 + default:
3462 + return -EINVAL;
3463 + }
3464 + switch (cs43130->dais[dai_id].dai_mode) {
3465 + case SND_SOC_DAIFMT_CBS_CFS:
3466 + dai_mode_val = 0;
3467 + break;
3468 + case SND_SOC_DAIFMT_CBM_CFM:
3469 + dai_mode_val = 1;
3470 + break;
3471 + default:
3472 + return -EINVAL;
3473 + }
3474 +
3475 + frm_size = bitwidth_sclk * params_channels(params);
3476 + sclk_edge = 1;
3477 + lrck_edge = 0;
3478 + loc_ch1 = 0;
3479 + loc_ch2 = bitwidth_sclk * (params_channels(params) - 1);
3480 +
3481 + frm_data = frm_delay & CS43130_SP_FSD_MASK;
3482 + frm_data |= (frm_phase << CS43130_SP_STP_SHIFT) & CS43130_SP_STP_MASK;
3483 +
3484 + clk_data = lrck_edge & CS43130_SP_LCPOL_IN_MASK;
3485 + clk_data |= (lrck_edge << CS43130_SP_LCPOL_OUT_SHIFT) &
3486 + CS43130_SP_LCPOL_OUT_MASK;
3487 + clk_data |= (sclk_edge << CS43130_SP_SCPOL_IN_SHIFT) &
3488 + CS43130_SP_SCPOL_IN_MASK;
3489 + clk_data |= (sclk_edge << CS43130_SP_SCPOL_OUT_SHIFT) &
3490 + CS43130_SP_SCPOL_OUT_MASK;
3491 + clk_data |= (dai_mode_val << CS43130_SP_MODE_SHIFT) &
3492 + CS43130_SP_MODE_MASK;
3493 + switch (dai_id) {
3494 + case CS43130_ASP_PCM_DAI:
3495 + case CS43130_ASP_DOP_DAI:
3496 + regmap_update_bits(cs43130->regmap, CS43130_ASP_LRCK_PERIOD_1,
3497 + CS43130_SP_LCPR_DATA_MASK, (frm_size - 1) >>
3498 + CS43130_SP_LCPR_LSB_DATA_SHIFT);
3499 + regmap_update_bits(cs43130->regmap, CS43130_ASP_LRCK_PERIOD_2,
3500 + CS43130_SP_LCPR_DATA_MASK, (frm_size - 1) >>
3501 + CS43130_SP_LCPR_MSB_DATA_SHIFT);
3502 + regmap_update_bits(cs43130->regmap, CS43130_ASP_LRCK_HI_TIME_1,
3503 + CS43130_SP_LCHI_DATA_MASK, (hi_size - 1) >>
3504 + CS43130_SP_LCHI_LSB_DATA_SHIFT);
3505 + regmap_update_bits(cs43130->regmap, CS43130_ASP_LRCK_HI_TIME_2,
3506 + CS43130_SP_LCHI_DATA_MASK, (hi_size - 1) >>
3507 + CS43130_SP_LCHI_MSB_DATA_SHIFT);
3508 + regmap_write(cs43130->regmap, CS43130_ASP_FRAME_CONF, frm_data);
3509 + regmap_write(cs43130->regmap, CS43130_ASP_CH_1_LOC, loc_ch1);
3510 + regmap_write(cs43130->regmap, CS43130_ASP_CH_2_LOC, loc_ch2);
3511 + regmap_update_bits(cs43130->regmap, CS43130_ASP_CH_1_SZ_EN,
3512 + CS43130_CH_EN_MASK, 1 << CS43130_CH_EN_SHIFT);
3513 + regmap_update_bits(cs43130->regmap, CS43130_ASP_CH_2_SZ_EN,
3514 + CS43130_CH_EN_MASK, 1 << CS43130_CH_EN_SHIFT);
3515 + regmap_write(cs43130->regmap, CS43130_ASP_CLOCK_CONF, clk_data);
3516 + break;
3517 + case CS43130_XSP_DOP_DAI:
3518 + regmap_update_bits(cs43130->regmap, CS43130_XSP_LRCK_PERIOD_1,
3519 + CS43130_SP_LCPR_DATA_MASK, (frm_size - 1) >>
3520 + CS43130_SP_LCPR_LSB_DATA_SHIFT);
3521 + regmap_update_bits(cs43130->regmap, CS43130_XSP_LRCK_PERIOD_2,
3522 + CS43130_SP_LCPR_DATA_MASK, (frm_size - 1) >>
3523 + CS43130_SP_LCPR_MSB_DATA_SHIFT);
3524 + regmap_update_bits(cs43130->regmap, CS43130_XSP_LRCK_HI_TIME_1,
3525 + CS43130_SP_LCHI_DATA_MASK, (hi_size - 1) >>
3526 + CS43130_SP_LCHI_LSB_DATA_SHIFT);
3527 + regmap_update_bits(cs43130->regmap, CS43130_XSP_LRCK_HI_TIME_2,
3528 + CS43130_SP_LCHI_DATA_MASK, (hi_size - 1) >>
3529 + CS43130_SP_LCHI_MSB_DATA_SHIFT);
3530 + regmap_write(cs43130->regmap, CS43130_XSP_FRAME_CONF, frm_data);
3531 + regmap_write(cs43130->regmap, CS43130_XSP_CH_1_LOC, loc_ch1);
3532 + regmap_write(cs43130->regmap, CS43130_XSP_CH_2_LOC, loc_ch2);
3533 + regmap_update_bits(cs43130->regmap, CS43130_XSP_CH_1_SZ_EN,
3534 + CS43130_CH_EN_MASK, 1 << CS43130_CH_EN_SHIFT);
3535 + regmap_update_bits(cs43130->regmap, CS43130_XSP_CH_2_SZ_EN,
3536 + CS43130_CH_EN_MASK, 1 << CS43130_CH_EN_SHIFT);
3537 + regmap_write(cs43130->regmap, CS43130_XSP_CLOCK_CONF, clk_data);
3538 + break;
3539 + default:
3540 + return -EINVAL;
3541 + }
3542 + switch (frm_size) {
3543 + case 16:
3544 + clk_gen = cs43130_get_clk_gen(cs43130->mclk_int,
3545 + params_rate(params),
3546 + cs43130_16_clk_gen,
3547 + ARRAY_SIZE(cs43130_16_clk_gen));
3548 + break;
3549 + case 32:
3550 + clk_gen = cs43130_get_clk_gen(cs43130->mclk_int,
3551 + params_rate(params),
3552 + cs43130_32_clk_gen,
3553 + ARRAY_SIZE(cs43130_32_clk_gen));
3554 + break;
3555 + case 48:
3556 + clk_gen = cs43130_get_clk_gen(cs43130->mclk_int,
3557 + params_rate(params),
3558 + cs43130_48_clk_gen,
3559 + ARRAY_SIZE(cs43130_48_clk_gen));
3560 + break;
3561 + case 64:
3562 + clk_gen = cs43130_get_clk_gen(cs43130->mclk_int,
3563 + params_rate(params),
3564 + cs43130_64_clk_gen,
3565 + ARRAY_SIZE(cs43130_64_clk_gen));
3566 + break;
3567 + default:
3568 + return -EINVAL;
3569 + }
3570 + if (!clk_gen)
3571 + return -EINVAL;
3572 + switch (dai_id) {
3573 + case CS43130_ASP_PCM_DAI:
3574 + case CS43130_ASP_DOP_DAI:
3575 + regmap_write(cs43130->regmap, CS43130_ASP_DEN_1,
3576 + (clk_gen->den & CS43130_SP_M_LSB_DATA_MASK) >>
3577 + CS43130_SP_M_LSB_DATA_SHIFT);
3578 + regmap_write(cs43130->regmap, CS43130_ASP_DEN_2,
3579 + (clk_gen->den & CS43130_SP_M_MSB_DATA_MASK) >>
3580 + CS43130_SP_M_MSB_DATA_SHIFT);
3581 + regmap_write(cs43130->regmap, CS43130_ASP_NUM_1,
3582 + (clk_gen->num & CS43130_SP_N_LSB_DATA_MASK) >>
3583 + CS43130_SP_N_LSB_DATA_SHIFT);
3584 + regmap_write(cs43130->regmap, CS43130_ASP_NUM_2,
3585 + (clk_gen->num & CS43130_SP_N_MSB_DATA_MASK) >>
3586 + CS43130_SP_N_MSB_DATA_SHIFT);
3587 + break;
3588 + case CS43130_XSP_DOP_DAI:
3589 + regmap_write(cs43130->regmap, CS43130_XSP_DEN_1,
3590 + (clk_gen->den & CS43130_SP_M_LSB_DATA_MASK) >>
3591 + CS43130_SP_M_LSB_DATA_SHIFT);
3592 + regmap_write(cs43130->regmap, CS43130_XSP_DEN_2,
3593 + (clk_gen->den & CS43130_SP_M_MSB_DATA_MASK) >>
3594 + CS43130_SP_M_MSB_DATA_SHIFT);
3595 + regmap_write(cs43130->regmap, CS43130_XSP_NUM_1,
3596 + (clk_gen->num & CS43130_SP_N_LSB_DATA_MASK) >>
3597 + CS43130_SP_N_LSB_DATA_SHIFT);
3598 + regmap_write(cs43130->regmap, CS43130_XSP_NUM_2,
3599 + (clk_gen->num & CS43130_SP_N_MSB_DATA_MASK) >>
3600 + CS43130_SP_N_MSB_DATA_SHIFT);
3601 + break;
3602 + default:
3603 + return -EINVAL;
3604 + }
3605 + return 0;
3606 +}
3607 +
3608 +static int cs43130_hw_params(struct snd_pcm_substream *substream,
3609 + struct snd_pcm_hw_params *params,
3610 + struct snd_soc_dai *dai)
3611 +{
3612 + struct snd_soc_component *component = dai->component;
3613 + struct cs43130_priv *cs43130 =
3614 + snd_soc_component_get_drvdata(component);
3615 + const struct cs43130_rate_map *rate_map;
3616 + unsigned int sclk = cs43130->dais[dai->id].sclk;
3617 + unsigned int bitwidth_sclk;
3618 + unsigned int bitwidth_dai = (unsigned int)(params_width(params));
3619 + unsigned int dop_rate = (unsigned int)(params_rate(params));
3620 + unsigned int required_clk, ret;
3621 + u8 dsd_speed;
3622 +
3623 + cs43130->pll_bypass = true;
3624 + cs43130_pcm_pdn(component);
3625 + mutex_lock(&cs43130->clk_mutex);
3626 + if (!cs43130->clk_req) {
3627 + /* no DAI is currently using clk */
3628 + if (!(CS43130_MCLK_22M % params_rate(params))) {
3629 + required_clk = CS43130_MCLK_22M;
3630 + cs43130->mclk_int = CS43130_MCLK_22M;
3631 + gpiod_set_value_cansleep(snd_allo_clk44gpio, 1);
3632 + gpiod_set_value_cansleep(snd_allo_clk48gpio, 0);
3633 + usleep_range(13500, 14000);
3634 + } else {
3635 + required_clk = CS43130_MCLK_24M;
3636 + cs43130->mclk_int = CS43130_MCLK_24M;
3637 + gpiod_set_value_cansleep(snd_allo_clk48gpio, 1);
3638 + gpiod_set_value_cansleep(snd_allo_clk44gpio, 0);
3639 + usleep_range(13500, 14000);
3640 + }
3641 + if (cs43130->pll_bypass)
3642 + cs43130_change_clksrc(component, CS43130_MCLK_SRC_EXT);
3643 + else
3644 + cs43130_change_clksrc(component, CS43130_MCLK_SRC_PLL);
3645 + }
3646 +
3647 + cs43130->clk_req++;
3648 + mutex_unlock(&cs43130->clk_mutex);
3649 +
3650 + switch (dai->id) {
3651 + case CS43130_ASP_DOP_DAI:
3652 + case CS43130_XSP_DOP_DAI:
3653 + /* DoP bitwidth is always 24-bit */
3654 + bitwidth_dai = 24;
3655 + sclk = params_rate(params) * bitwidth_dai *
3656 + params_channels(params);
3657 +
3658 + switch (params_rate(params)) {
3659 + case 176400:
3660 + dsd_speed = 0;
3661 + break;
3662 + case 352800:
3663 + dsd_speed = 1;
3664 + break;
3665 + default:
3666 + dev_err(component->dev, "Rate(%u) not supported\n",
3667 + params_rate(params));
3668 + return -EINVAL;
3669 + }
3670 +
3671 + regmap_update_bits(cs43130->regmap, CS43130_DSD_PATH_CTL_2,
3672 + CS43130_DSD_SPEED_MASK,
3673 + dsd_speed << CS43130_DSD_SPEED_SHIFT);
3674 + break;
3675 + case CS43130_ASP_PCM_DAI:
3676 + rate_map = cs43130_get_rate_table(params_rate(params));
3677 + if (!rate_map)
3678 + return -EINVAL;
3679 +
3680 + regmap_write(cs43130->regmap, CS43130_SP_SRATE, rate_map->val);
3681 + if ((dop_rate == 176400) && (bitwidth_dai == 24)) {
3682 + dsd_speed = 0;
3683 + regmap_update_bits(cs43130->regmap,
3684 + CS43130_DSD_PATH_CTL_2,
3685 + CS43130_DSD_SPEED_MASK,
3686 + dsd_speed << CS43130_DSD_SPEED_SHIFT);
3687 + regmap_update_bits(cs43130->regmap,
3688 + CS43130_DSD_PATH_CTL_2,
3689 + CS43130_DSD_SRC_MASK,
3690 + CS43130_DSD_SRC_ASP <<
3691 + CS43130_DSD_SRC_SHIFT);
3692 + regmap_update_bits(cs43130->regmap,
3693 + CS43130_DSD_PATH_CTL_2,
3694 + CS43130_DSD_EN_MASK, 0x01 <<
3695 + CS43130_DSD_EN_SHIFT);
3696 + }
3697 + break;
3698 + default:
3699 + dev_err(component->dev, "Invalid DAI (%d)\n", dai->id);
3700 + return -EINVAL;
3701 + }
3702 +
3703 + switch (dai->id) {
3704 + case CS43130_ASP_DOP_DAI:
3705 + regmap_update_bits(cs43130->regmap, CS43130_DSD_PATH_CTL_2,
3706 + CS43130_DSD_SRC_MASK, CS43130_DSD_SRC_ASP <<
3707 + CS43130_DSD_SRC_SHIFT);
3708 + regmap_update_bits(cs43130->regmap, CS43130_DSD_PATH_CTL_2,
3709 + CS43130_DSD_EN_MASK, 0x01 <<
3710 + CS43130_DSD_EN_SHIFT);
3711 + break;
3712 + case CS43130_XSP_DOP_DAI:
3713 + regmap_update_bits(cs43130->regmap, CS43130_DSD_PATH_CTL_2,
3714 + CS43130_DSD_SRC_MASK, CS43130_DSD_SRC_XSP <<
3715 + CS43130_DSD_SRC_SHIFT);
3716 + break;
3717 + }
3718 + if (!sclk && cs43130->dais[dai->id].dai_mode ==
3719 + SND_SOC_DAIFMT_CBM_CFM) {
3720 + /* Calculate SCLK in master mode if unassigned */
3721 + sclk = params_rate(params) * bitwidth_dai *
3722 + params_channels(params);
3723 + }
3724 + if (!sclk) {
3725 + /* at this point, SCLK must be set */
3726 + dev_err(component->dev, "SCLK freq is not set\n");
3727 + return -EINVAL;
3728 + }
3729 +
3730 + bitwidth_sclk = (sclk / params_rate(params)) / params_channels(params);
3731 + if (bitwidth_sclk < bitwidth_dai) {
3732 + dev_err(component->dev, "Format not supported: SCLK freq is too low\n");
3733 + return -EINVAL;
3734 + }
3735 +
3736 + dev_dbg(component->dev,
3737 + "sclk = %u, fs = %d, bitwidth_dai = %u\n",
3738 + sclk, params_rate(params), bitwidth_dai);
3739 +
3740 + dev_dbg(component->dev,
3741 + "bitwidth_sclk = %u, num_ch = %u\n",
3742 + bitwidth_sclk, params_channels(params));
3743 +
3744 + cs43130_set_bitwidth(dai->id, bitwidth_dai, cs43130->regmap);
3745 + cs43130_set_sp_fmt(dai->id, bitwidth_sclk, params, cs43130);
3746 + ret = cs43130_pwr_up_asp_dac(component);
3747 + return 0;
3748 +}
3749 +
3750 +static int cs43130_hw_free(struct snd_pcm_substream *substream,
3751 + struct snd_soc_dai *dai)
3752 +{
3753 + struct snd_soc_component *component = dai->component;
3754 + struct cs43130_priv *cs43130 =
3755 + snd_soc_component_get_drvdata(component);
3756 +
3757 + mutex_lock(&cs43130->clk_mutex);
3758 + cs43130->clk_req--;
3759 + if (!cs43130->clk_req) {
3760 + /* no DAI is currently using clk */
3761 + cs43130_change_clksrc(component, CS43130_MCLK_SRC_RCO);
3762 + cs43130_pcm_pdn(component);
3763 + }
3764 + mutex_unlock(&cs43130->clk_mutex);
3765 +
3766 + return 0;
3767 +}
3768 +
3769 +static const unsigned int cs43130_asp_src_rates[] = {
3770 + 32000, 44100, 48000, 88200, 96000, 176400, 192000
3771 +};
3772 +
3773 +static const struct snd_pcm_hw_constraint_list cs43130_asp_constraints = {
3774 + .count = ARRAY_SIZE(cs43130_asp_src_rates),
3775 + .list = cs43130_asp_src_rates,
3776 +};
3777 +
3778 +static int cs43130_pcm_startup(struct snd_pcm_substream *substream,
3779 + struct snd_soc_dai *dai)
3780 +{
3781 + return snd_pcm_hw_constraint_list(substream->runtime, 0,
3782 + SNDRV_PCM_HW_PARAM_RATE,
3783 + &cs43130_asp_constraints);
3784 +}
3785 +
3786 +static int cs43130_pcm_set_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
3787 +{
3788 + struct snd_soc_component *component = codec_dai->component;
3789 + struct cs43130_priv *cs43130 =
3790 + snd_soc_component_get_drvdata(component);
3791 +
3792 + switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
3793 + case SND_SOC_DAIFMT_CBS_CFS:
3794 + cs43130->dais[codec_dai->id].dai_mode = SND_SOC_DAIFMT_CBS_CFS;
3795 + break;
3796 + case SND_SOC_DAIFMT_CBM_CFM:
3797 + cs43130->dais[codec_dai->id].dai_mode = SND_SOC_DAIFMT_CBM_CFM;
3798 + break;
3799 + default:
3800 + dev_err(component->dev, "unsupported mode\n");
3801 + return -EINVAL;
3802 + }
3803 +
3804 + switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
3805 + case SND_SOC_DAIFMT_I2S:
3806 + cs43130->dais[codec_dai->id].dai_format = SND_SOC_DAIFMT_I2S;
3807 + break;
3808 + case SND_SOC_DAIFMT_LEFT_J:
3809 + cs43130->dais[codec_dai->id].dai_format = SND_SOC_DAIFMT_LEFT_J;
3810 + break;
3811 + default:
3812 + dev_err(component->dev,
3813 + "unsupported audio format\n");
3814 + return -EINVAL;
3815 + }
3816 +
3817 + dev_dbg(component->dev, "dai_id = %d, dai_mode = %u, dai_format = %u\n",
3818 + codec_dai->id,
3819 + cs43130->dais[codec_dai->id].dai_mode,
3820 + cs43130->dais[codec_dai->id].dai_format);
3821 +
3822 + return 0;
3823 +}
3824 +
3825 +static int cs43130_set_sysclk(struct snd_soc_dai *codec_dai,
3826 + int clk_id, unsigned int freq, int dir)
3827 +{
3828 + struct snd_soc_component *component = codec_dai->component;
3829 + struct cs43130_priv *cs43130 =
3830 + snd_soc_component_get_drvdata(component);
3831 +
3832 + cs43130->dais[codec_dai->id].sclk = freq;
3833 + dev_dbg(component->dev, "dai_id = %d, sclk = %u\n", codec_dai->id,
3834 + cs43130->dais[codec_dai->id].sclk);
3835 +
3836 + return 0;
3837 +}
3838 +
3839 +static int cs43130_component_set_sysclk(struct snd_soc_component *component,
3840 + int clk_id, int source,
3841 + unsigned int freq, int dir)
3842 +{
3843 + struct cs43130_priv *cs43130 =
3844 + snd_soc_component_get_drvdata(component);
3845 +
3846 + dev_dbg(component->dev, "clk_id = %d, source = %d, freq = %d, dir = %d\n",
3847 + clk_id, source, freq, dir);
3848 +
3849 + switch (freq) {
3850 + case CS43130_MCLK_22M:
3851 + case CS43130_MCLK_24M:
3852 + cs43130->mclk = freq;
3853 + break;
3854 + default:
3855 + dev_err(component->dev, "Invalid MCLK INT freq: %u\n", freq);
3856 + return -EINVAL;
3857 + }
3858 +
3859 + if (source == CS43130_MCLK_SRC_EXT) {
3860 + cs43130->pll_bypass = true;
3861 + } else {
3862 + dev_err(component->dev, "Invalid MCLK source\n");
3863 + return -EINVAL;
3864 + }
3865 +
3866 + return 0;
3867 +}
3868 +static u16 const cs43130_ac_freq[CS43130_AC_FREQ] = {
3869 + 24,
3870 + 43,
3871 + 93,
3872 + 200,
3873 + 431,
3874 + 928,
3875 + 2000,
3876 + 4309,
3877 + 9283,
3878 + 20000,
3879 +};
3880 +static const struct snd_soc_dai_ops cs43130_dai_ops = {
3881 + .startup = cs43130_pcm_startup,
3882 + .hw_params = cs43130_hw_params,
3883 + .hw_free = cs43130_hw_free,
3884 + .set_sysclk = cs43130_set_sysclk,
3885 + .set_fmt = cs43130_pcm_set_fmt,
3886 +};
3887 +
3888 +static struct snd_soc_dai_driver cs43130_codec_dai = {
3889 + .name = "allo-cs43130",
3890 + .playback = {
3891 + .stream_name = "Playback",
3892 + .channels_min = 2,
3893 + .channels_max = 2,
3894 + .rates = SNDRV_PCM_RATE_CONTINUOUS,
3895 + .rate_min = 44100,
3896 + .rate_max = 192000,
3897 + .formats = SNDRV_PCM_FMTBIT_S16_LE |
3898 + SNDRV_PCM_FMTBIT_S24_LE |
3899 + SNDRV_PCM_FMTBIT_S32_LE
3900 +
3901 + },
3902 + .ops = &cs43130_dai_ops,
3903 +};
3904 +
3905 +static struct snd_soc_component_driver cs43130_component_driver = {
3906 + .idle_bias_on = true,
3907 + .controls = cs43130_controls,
3908 + .num_controls = ARRAY_SIZE(cs43130_controls),
3909 + .set_sysclk = cs43130_component_set_sysclk,
3910 + .idle_bias_on = 1,
3911 + .use_pmdown_time = 1,
3912 + .endianness = 1,
3913 + .non_legacy_dai_naming = 1,
3914 +};
3915 +
3916 +static const struct regmap_config cs43130_regmap = {
3917 + .reg_bits = 24,
3918 + .pad_bits = 8,
3919 + .val_bits = 8,
3920 +
3921 + .max_register = CS43130_LASTREG,
3922 + .reg_defaults = cs43130_reg_defaults,
3923 + .num_reg_defaults = ARRAY_SIZE(cs43130_reg_defaults),
3924 + .readable_reg = cs43130_readable_register,
3925 + .precious_reg = cs43130_precious_register,
3926 + .volatile_reg = cs43130_volatile_register,
3927 + .cache_type = REGCACHE_RBTREE,
3928 + /* needed for regcache_sync */
3929 + .use_single_read = true,
3930 + .use_single_write = true,
3931 +};
3932 +
3933 +static u16 const cs43130_dc_threshold[CS43130_DC_THRESHOLD] = {
3934 + 50,
3935 + 120,
3936 +};
3937 +
3938 +static int cs43130_handle_device_data(struct i2c_client *i2c_client,
3939 + struct cs43130_priv *cs43130)
3940 +{
3941 + struct device_node *np = i2c_client->dev.of_node;
3942 + unsigned int val;
3943 + int i;
3944 +
3945 + if (of_property_read_u32(np, "cirrus,xtal-ibias", &val) < 0) {
3946 + /* Crystal is unused. System clock is used for external MCLK */
3947 + cs43130->xtal_ibias = CS43130_XTAL_UNUSED;
3948 + return 0;
3949 + }
3950 +
3951 + switch (val) {
3952 + case 1:
3953 + cs43130->xtal_ibias = CS43130_XTAL_IBIAS_7_5UA;
3954 + break;
3955 + case 2:
3956 + cs43130->xtal_ibias = CS43130_XTAL_IBIAS_12_5UA;
3957 + break;
3958 + case 3:
3959 + cs43130->xtal_ibias = CS43130_XTAL_IBIAS_15UA;
3960 + break;
3961 + default:
3962 + dev_err(&i2c_client->dev,
3963 + "Invalid cirrus,xtal-ibias value: %d\n", val);
3964 + return -EINVAL;
3965 + }
3966 +
3967 + cs43130->dc_meas = of_property_read_bool(np, "cirrus,dc-measure");
3968 + cs43130->ac_meas = of_property_read_bool(np, "cirrus,ac-measure");
3969 +
3970 + if (of_property_read_u16_array(np, "cirrus,ac-freq", cs43130->ac_freq,
3971 + CS43130_AC_FREQ) < 0) {
3972 + for (i = 0; i < CS43130_AC_FREQ; i++)
3973 + cs43130->ac_freq[i] = cs43130_ac_freq[i];
3974 + }
3975 +
3976 + if (of_property_read_u16_array(np, "cirrus,dc-threshold",
3977 + cs43130->dc_threshold,
3978 + CS43130_DC_THRESHOLD) < 0) {
3979 + for (i = 0; i < CS43130_DC_THRESHOLD; i++)
3980 + cs43130->dc_threshold[i] = cs43130_dc_threshold[i];
3981 + }
3982 +
3983 + return 0;
3984 +}
3985 +
3986 +
3987 +static int allo_cs43130_component_probe(struct i2c_client *i2c,
3988 + const struct i2c_device_id *id)
3989 +{
3990 + struct regmap *regmap;
3991 + struct regmap_config config = cs43130_regmap;
3992 + struct device *dev = &i2c->dev;
3993 + struct cs43130_priv *cs43130;
3994 + unsigned int devid = 0;
3995 + unsigned int reg;
3996 + int ret;
3997 +
3998 + regmap = devm_regmap_init_i2c(i2c, &config);
3999 + if (IS_ERR(regmap))
4000 + return PTR_ERR(regmap);
4001 +
4002 + cs43130 = devm_kzalloc(dev, sizeof(struct cs43130_priv),
4003 + GFP_KERNEL);
4004 + if (!cs43130)
4005 + return -ENOMEM;
4006 +
4007 + dev_set_drvdata(dev, cs43130);
4008 + cs43130->regmap = regmap;
4009 +
4010 + if (i2c->dev.of_node) {
4011 + ret = cs43130_handle_device_data(i2c, cs43130);
4012 + if (ret != 0)
4013 + return ret;
4014 + }
4015 + usleep_range(2000, 2050);
4016 +
4017 + ret = regmap_read(cs43130->regmap, CS43130_DEVID_AB, &reg);
4018 + devid = (reg & 0xFF) << 12;
4019 + ret = regmap_read(cs43130->regmap, CS43130_DEVID_CD, &reg);
4020 + devid |= (reg & 0xFF) << 4;
4021 + ret = regmap_read(cs43130->regmap, CS43130_DEVID_E, &reg);
4022 + devid |= (reg & 0xF0) >> 4;
4023 + if (devid != CS43198_CHIP_ID) {
4024 + dev_err(dev, "Failed to read Chip or wrong Chip id: %d\n", ret);
4025 + return ret;
4026 + }
4027 +
4028 + cs43130->mclk_int_src = CS43130_MCLK_SRC_RCO;
4029 + msleep(20);
4030 +
4031 + ret = snd_soc_register_component(dev, &cs43130_component_driver,
4032 + &cs43130_codec_dai, 1);
4033 + if (ret != 0) {
4034 + dev_err(dev, "failed to register codec: %d\n", ret);
4035 + return ret;
4036 + }
4037 + regmap_update_bits(cs43130->regmap, CS43130_PAD_INT_CFG,
4038 + CS43130_ASP_3ST_MASK, 0);
4039 + regmap_update_bits(cs43130->regmap, CS43130_PAD_INT_CFG,
4040 + CS43130_XSP_3ST_MASK, 1);
4041 + regmap_update_bits(cs43130->regmap, CS43130_PWDN_CTL,
4042 + CS43130_PDN_HP_MASK, 1 << CS43130_PDN_HP_SHIFT);
4043 + msleep(20);
4044 + regmap_write(cs43130->regmap, CS43130_CLASS_H_CTL, 0x06);
4045 + snd_allo_clk44gpio = devm_gpiod_get(dev, "clock44", GPIOD_OUT_HIGH);
4046 + if (IS_ERR(snd_allo_clk44gpio))
4047 + dev_err(dev, "devm_gpiod_get() failed\n");
4048 +
4049 + snd_allo_clk48gpio = devm_gpiod_get(dev, "clock48", GPIOD_OUT_LOW);
4050 + if (IS_ERR(snd_allo_clk48gpio))
4051 + dev_err(dev, "devm_gpiod_get() failed\n");
4052 +
4053 + return 0;
4054 +}
4055 +
4056 +static int allo_cs43130_component_remove(struct i2c_client *i2c)
4057 +{
4058 + snd_soc_unregister_component(&i2c->dev);
4059 + return 0;
4060 +}
4061 +
4062 +static const struct i2c_device_id allo_cs43130_component_id[] = {
4063 + { "allo-cs43198", },
4064 + { }
4065 +};
4066 +MODULE_DEVICE_TABLE(i2c, allo_cs43130_component_id);
4067 +
4068 +static const struct of_device_id allo_cs43130_codec_of_match[] = {
4069 + { .compatible = "allo,allo-cs43198", },
4070 + { }
4071 +};
4072 +MODULE_DEVICE_TABLE(of, allo_cs43130_codec_of_match);
4073 +
4074 +static struct i2c_driver allo_cs43130_component_driver = {
4075 + .probe = allo_cs43130_component_probe,
4076 + .remove = allo_cs43130_component_remove,
4077 + .id_table = allo_cs43130_component_id,
4078 + .driver = {
4079 + .name = "allo-cs43198",
4080 + .of_match_table = allo_cs43130_codec_of_match,
4081 + },
4082 +};
4083 +
4084 +module_i2c_driver(allo_cs43130_component_driver);
4085 +
4086 +MODULE_DESCRIPTION("ASoC Allo Boss2 Codec Driver");
4087 +MODULE_AUTHOR("Sudeepkumar <sudeepkumar@cem-solutions.net>");
4088 +MODULE_LICENSE("GPL v2");
4089 --- /dev/null
4090 +++ b/sound/soc/bcm/allo-katana-codec.c
4091 @@ -0,0 +1,388 @@
4092 +/*
4093 + * Driver for the ALLO KATANA CODEC
4094 + *
4095 + * Author: Jaikumar <jaikumar@cem-solutions.net>
4096 + * Copyright 2018
4097 + *
4098 + * This program is free software; you can redistribute it and/or
4099 + * modify it under the terms of the GNU General Public License
4100 + * version 2 as published by the Free Software Foundation.
4101 + *
4102 + * This program is distributed in the hope that it will be useful, but
4103 + * WITHOUT ANY WARRANTY; without even the implied warranty of
4104 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4105 + * General Public License for more details.
4106 + */
4107 +
4108 +
4109 +#include <linux/init.h>
4110 +#include <linux/module.h>
4111 +#include <linux/clk.h>
4112 +#include <linux/kernel.h>
4113 +#include <linux/regmap.h>
4114 +#include <linux/regulator/consumer.h>
4115 +#include <linux/gcd.h>
4116 +#include <sound/soc.h>
4117 +#include <sound/soc-dapm.h>
4118 +#include <sound/pcm_params.h>
4119 +#include <sound/tlv.h>
4120 +#include <linux/i2c.h>
4121 +
4122 +
4123 +#define KATANA_CODEC_CHIP_ID 0x30
4124 +#define KATANA_CODEC_VIRT_BASE 0x100
4125 +#define KATANA_CODEC_PAGE 0
4126 +
4127 +#define KATANA_CODEC_CHIP_ID_REG (KATANA_CODEC_VIRT_BASE + 0)
4128 +#define KATANA_CODEC_RESET (KATANA_CODEC_VIRT_BASE + 1)
4129 +#define KATANA_CODEC_VOLUME_1 (KATANA_CODEC_VIRT_BASE + 2)
4130 +#define KATANA_CODEC_VOLUME_2 (KATANA_CODEC_VIRT_BASE + 3)
4131 +#define KATANA_CODEC_MUTE (KATANA_CODEC_VIRT_BASE + 4)
4132 +#define KATANA_CODEC_DSP_PROGRAM (KATANA_CODEC_VIRT_BASE + 5)
4133 +#define KATANA_CODEC_DEEMPHASIS (KATANA_CODEC_VIRT_BASE + 6)
4134 +#define KATANA_CODEC_DOP (KATANA_CODEC_VIRT_BASE + 7)
4135 +#define KATANA_CODEC_FORMAT (KATANA_CODEC_VIRT_BASE + 8)
4136 +#define KATANA_CODEC_COMMAND (KATANA_CODEC_VIRT_BASE + 9)
4137 +#define KATANA_CODEC_MUTE_STREAM (KATANA_CODEC_VIRT_BASE + 10)
4138 +
4139 +#define KATANA_CODEC_MAX_REGISTER (KATANA_CODEC_VIRT_BASE + 10)
4140 +
4141 +#define KATANA_CODEC_FMT 0xff
4142 +#define KATANA_CODEC_CHAN_MONO 0x00
4143 +#define KATANA_CODEC_CHAN_STEREO 0x80
4144 +#define KATANA_CODEC_ALEN_16 0x10
4145 +#define KATANA_CODEC_ALEN_24 0x20
4146 +#define KATANA_CODEC_ALEN_32 0x30
4147 +#define KATANA_CODEC_RATE_11025 0x01
4148 +#define KATANA_CODEC_RATE_22050 0x02
4149 +#define KATANA_CODEC_RATE_32000 0x03
4150 +#define KATANA_CODEC_RATE_44100 0x04
4151 +#define KATANA_CODEC_RATE_48000 0x05
4152 +#define KATANA_CODEC_RATE_88200 0x06
4153 +#define KATANA_CODEC_RATE_96000 0x07
4154 +#define KATANA_CODEC_RATE_176400 0x08
4155 +#define KATANA_CODEC_RATE_192000 0x09
4156 +#define KATANA_CODEC_RATE_352800 0x0a
4157 +#define KATANA_CODEC_RATE_384000 0x0b
4158 +
4159 +
4160 +struct katana_codec_priv {
4161 + struct regmap *regmap;
4162 + int fmt;
4163 +};
4164 +
4165 +static const struct reg_default katana_codec_reg_defaults[] = {
4166 + { KATANA_CODEC_RESET, 0x00 },
4167 + { KATANA_CODEC_VOLUME_1, 0xF0 },
4168 + { KATANA_CODEC_VOLUME_2, 0xF0 },
4169 + { KATANA_CODEC_MUTE, 0x00 },
4170 + { KATANA_CODEC_DSP_PROGRAM, 0x04 },
4171 + { KATANA_CODEC_DEEMPHASIS, 0x00 },
4172 + { KATANA_CODEC_DOP, 0x00 },
4173 + { KATANA_CODEC_FORMAT, 0xb4 },
4174 +};
4175 +
4176 +static const char * const katana_codec_dsp_program_texts[] = {
4177 + "Linear Phase Fast Roll-off Filter",
4178 + "Linear Phase Slow Roll-off Filter",
4179 + "Minimum Phase Fast Roll-off Filter",
4180 + "Minimum Phase Slow Roll-off Filter",
4181 + "Apodizing Fast Roll-off Filter",
4182 + "Corrected Minimum Phase Fast Roll-off Filter",
4183 + "Brick Wall Filter",
4184 +};
4185 +
4186 +static const unsigned int katana_codec_dsp_program_values[] = {
4187 + 0,
4188 + 1,
4189 + 2,
4190 + 3,
4191 + 4,
4192 + 6,
4193 + 7,
4194 +};
4195 +
4196 +static SOC_VALUE_ENUM_SINGLE_DECL(katana_codec_dsp_program,
4197 + KATANA_CODEC_DSP_PROGRAM, 0, 0x07,
4198 + katana_codec_dsp_program_texts,
4199 + katana_codec_dsp_program_values);
4200 +
4201 +static const char * const katana_codec_deemphasis_texts[] = {
4202 + "Bypass",
4203 + "32kHz",
4204 + "44.1kHz",
4205 + "48kHz",
4206 +};
4207 +
4208 +static const unsigned int katana_codec_deemphasis_values[] = {
4209 + 0,
4210 + 1,
4211 + 2,
4212 + 3,
4213 +};
4214 +
4215 +static SOC_VALUE_ENUM_SINGLE_DECL(katana_codec_deemphasis,
4216 + KATANA_CODEC_DEEMPHASIS, 0, 0x03,
4217 + katana_codec_deemphasis_texts,
4218 + katana_codec_deemphasis_values);
4219 +
4220 +static const SNDRV_CTL_TLVD_DECLARE_DB_MINMAX(master_tlv, -12750, 0);
4221 +
4222 +static const struct snd_kcontrol_new katana_codec_controls[] = {
4223 + SOC_DOUBLE_R_TLV("Master Playback Volume", KATANA_CODEC_VOLUME_1,
4224 + KATANA_CODEC_VOLUME_2, 0, 255, 1, master_tlv),
4225 + SOC_DOUBLE("Master Playback Switch", KATANA_CODEC_MUTE, 0, 0, 1, 1),
4226 + SOC_ENUM("DSP Program Route", katana_codec_dsp_program),
4227 + SOC_ENUM("Deemphasis Route", katana_codec_deemphasis),
4228 + SOC_SINGLE("DoP Playback Switch", KATANA_CODEC_DOP, 0, 1, 1)
4229 +};
4230 +
4231 +static bool katana_codec_readable_register(struct device *dev,
4232 + unsigned int reg)
4233 +{
4234 + switch (reg) {
4235 + case KATANA_CODEC_CHIP_ID_REG:
4236 + return true;
4237 + default:
4238 + return reg < 0xff;
4239 + }
4240 +}
4241 +
4242 +static int katana_codec_hw_params(struct snd_pcm_substream *substream,
4243 + struct snd_pcm_hw_params *params,
4244 + struct snd_soc_dai *dai)
4245 +{
4246 + struct snd_soc_component *component = dai->component;
4247 + struct katana_codec_priv *katana_codec =
4248 + snd_soc_component_get_drvdata(component);
4249 + int fmt = 0;
4250 + int ret;
4251 +
4252 + dev_dbg(component->card->dev, "hw_params %u Hz, %u channels, %u bits\n",
4253 + params_rate(params),
4254 + params_channels(params),
4255 + params_width(params));
4256 +
4257 + switch (katana_codec->fmt & SND_SOC_DAIFMT_MASTER_MASK) {
4258 + case SND_SOC_DAIFMT_CBM_CFM: // master
4259 + if (params_channels(params) == 2)
4260 + fmt = KATANA_CODEC_CHAN_STEREO;
4261 + else
4262 + fmt = KATANA_CODEC_CHAN_MONO;
4263 +
4264 + switch (params_width(params)) {
4265 + case 16:
4266 + fmt |= KATANA_CODEC_ALEN_16;
4267 + break;
4268 + case 24:
4269 + fmt |= KATANA_CODEC_ALEN_24;
4270 + break;
4271 + case 32:
4272 + fmt |= KATANA_CODEC_ALEN_32;
4273 + break;
4274 + default:
4275 + dev_err(component->card->dev, "Bad frame size: %d\n",
4276 + params_width(params));
4277 + return -EINVAL;
4278 + }
4279 +
4280 + switch (params_rate(params)) {
4281 + case 44100:
4282 + fmt |= KATANA_CODEC_RATE_44100;
4283 + break;
4284 + case 48000:
4285 + fmt |= KATANA_CODEC_RATE_48000;
4286 + break;
4287 + case 88200:
4288 + fmt |= KATANA_CODEC_RATE_88200;
4289 + break;
4290 + case 96000:
4291 + fmt |= KATANA_CODEC_RATE_96000;
4292 + break;
4293 + case 176400:
4294 + fmt |= KATANA_CODEC_RATE_176400;
4295 + break;
4296 + case 192000:
4297 + fmt |= KATANA_CODEC_RATE_192000;
4298 + break;
4299 + case 352800:
4300 + fmt |= KATANA_CODEC_RATE_352800;
4301 + break;
4302 + case 384000:
4303 + fmt |= KATANA_CODEC_RATE_384000;
4304 + break;
4305 + default:
4306 + dev_err(component->card->dev, "Bad sample rate: %d\n",
4307 + params_rate(params));
4308 + return -EINVAL;
4309 + }
4310 +
4311 + ret = regmap_write(katana_codec->regmap, KATANA_CODEC_FORMAT,
4312 + fmt);
4313 + if (ret != 0) {
4314 + dev_err(component->card->dev, "Failed to set format: %d\n", ret);
4315 + return ret;
4316 + }
4317 + break;
4318 +
4319 + case SND_SOC_DAIFMT_CBS_CFS:
4320 + break;
4321 +
4322 + default:
4323 + return -EINVAL;
4324 + }
4325 +
4326 + return 0;
4327 +}
4328 +
4329 +static int katana_codec_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
4330 +{
4331 + struct snd_soc_component *component = dai->component;
4332 + struct katana_codec_priv *katana_codec =
4333 + snd_soc_component_get_drvdata(component);
4334 +
4335 + katana_codec->fmt = fmt;
4336 +
4337 + return 0;
4338 +}
4339 +
4340 +int katana_codec_dai_mute_stream(struct snd_soc_dai *dai, int mute,
4341 + int stream)
4342 +{
4343 + struct snd_soc_component *component = dai->component;
4344 + struct katana_codec_priv *katana_codec =
4345 + snd_soc_component_get_drvdata(component);
4346 + int ret = 0;
4347 +
4348 + ret = regmap_write(katana_codec->regmap, KATANA_CODEC_MUTE_STREAM,
4349 + mute);
4350 + if (ret != 0) {
4351 + dev_err(component->card->dev, "Failed to set mute: %d\n", ret);
4352 + return ret;
4353 + }
4354 + return ret;
4355 +}
4356 +
4357 +static const struct snd_soc_dai_ops katana_codec_dai_ops = {
4358 + .mute_stream = katana_codec_dai_mute_stream,
4359 + .hw_params = katana_codec_hw_params,
4360 + .set_fmt = katana_codec_set_fmt,
4361 +};
4362 +
4363 +static struct snd_soc_dai_driver katana_codec_dai = {
4364 + .name = "allo-katana-codec",
4365 + .playback = {
4366 + .stream_name = "Playback",
4367 + .channels_min = 2,
4368 + .channels_max = 2,
4369 + .rates = SNDRV_PCM_RATE_CONTINUOUS,
4370 + .rate_min = 44100,
4371 + .rate_max = 384000,
4372 + .formats = SNDRV_PCM_FMTBIT_S16_LE |
4373 + SNDRV_PCM_FMTBIT_S32_LE
4374 + },
4375 + .ops = &katana_codec_dai_ops,
4376 +};
4377 +
4378 +static struct snd_soc_component_driver katana_codec_component_driver = {
4379 + .idle_bias_on = true,
4380 +
4381 + .controls = katana_codec_controls,
4382 + .num_controls = ARRAY_SIZE(katana_codec_controls),
4383 +};
4384 +
4385 +static const struct regmap_range_cfg katana_codec_range = {
4386 + .name = "Pages", .range_min = KATANA_CODEC_VIRT_BASE,
4387 + .range_max = KATANA_CODEC_MAX_REGISTER,
4388 + .selector_reg = KATANA_CODEC_PAGE,
4389 + .selector_mask = 0xff,
4390 + .window_start = 0, .window_len = 0x100,
4391 +};
4392 +
4393 +const struct regmap_config katana_codec_regmap = {
4394 + .reg_bits = 8,
4395 + .val_bits = 8,
4396 +
4397 + .ranges = &katana_codec_range,
4398 + .num_ranges = 1,
4399 +
4400 + .max_register = KATANA_CODEC_MAX_REGISTER,
4401 + .readable_reg = katana_codec_readable_register,
4402 + .reg_defaults = katana_codec_reg_defaults,
4403 + .num_reg_defaults = ARRAY_SIZE(katana_codec_reg_defaults),
4404 + .cache_type = REGCACHE_RBTREE,
4405 +};
4406 +
4407 +static int allo_katana_component_probe(struct i2c_client *i2c,
4408 + const struct i2c_device_id *id)
4409 +{
4410 + struct regmap *regmap;
4411 + struct regmap_config config = katana_codec_regmap;
4412 + struct device *dev = &i2c->dev;
4413 + struct katana_codec_priv *katana_codec;
4414 + unsigned int chip_id = 0;
4415 + int ret;
4416 +
4417 + regmap = devm_regmap_init_i2c(i2c, &config);
4418 + if (IS_ERR(regmap))
4419 + return PTR_ERR(regmap);
4420 +
4421 + katana_codec = devm_kzalloc(dev, sizeof(struct katana_codec_priv),
4422 + GFP_KERNEL);
4423 + if (!katana_codec)
4424 + return -ENOMEM;
4425 +
4426 + dev_set_drvdata(dev, katana_codec);
4427 + katana_codec->regmap = regmap;
4428 +
4429 + ret = regmap_read(regmap, KATANA_CODEC_CHIP_ID_REG, &chip_id);
4430 + if ((ret != 0) || (chip_id != KATANA_CODEC_CHIP_ID)) {
4431 + dev_err(dev, "Failed to read Chip or wrong Chip id: %d\n", ret);
4432 + return ret;
4433 + }
4434 + regmap_update_bits(regmap, KATANA_CODEC_RESET, 0x01, 0x01);
4435 + msleep(10);
4436 +
4437 + ret = snd_soc_register_component(dev, &katana_codec_component_driver,
4438 + &katana_codec_dai, 1);
4439 + if (ret != 0) {
4440 + dev_err(dev, "failed to register codec: %d\n", ret);
4441 + return ret;
4442 + }
4443 +
4444 + return 0;
4445 +}
4446 +
4447 +static int allo_katana_component_remove(struct i2c_client *i2c)
4448 +{
4449 + snd_soc_unregister_component(&i2c->dev);
4450 + return 0;
4451 +}
4452 +
4453 +static const struct i2c_device_id allo_katana_component_id[] = {
4454 + { "allo-katana-codec", },
4455 + { }
4456 +};
4457 +MODULE_DEVICE_TABLE(i2c, allo_katana_component_id);
4458 +
4459 +static const struct of_device_id allo_katana_codec_of_match[] = {
4460 + { .compatible = "allo,allo-katana-codec", },
4461 + { }
4462 +};
4463 +MODULE_DEVICE_TABLE(of, allo_katana_codec_of_match);
4464 +
4465 +static struct i2c_driver allo_katana_component_driver = {
4466 + .probe = allo_katana_component_probe,
4467 + .remove = allo_katana_component_remove,
4468 + .id_table = allo_katana_component_id,
4469 + .driver = {
4470 + .name = "allo-katana-codec",
4471 + .of_match_table = allo_katana_codec_of_match,
4472 + },
4473 +};
4474 +
4475 +module_i2c_driver(allo_katana_component_driver);
4476 +
4477 +MODULE_DESCRIPTION("ASoC Allo Katana Codec Driver");
4478 +MODULE_AUTHOR("Jaikumar <jaikumar@cem-solutions.net>");
4479 +MODULE_LICENSE("GPL v2");
4480 --- /dev/null
4481 +++ b/sound/soc/bcm/allo-piano-dac-plus.c
4482 @@ -0,0 +1,1063 @@
4483 +/*
4484 + * ALSA ASoC Machine Driver for Allo Piano DAC Plus Subwoofer
4485 + *
4486 + * Author: Baswaraj K <jaikumar@cem-solutions.net>
4487 + * Copyright 2020
4488 + * based on code by David Knell <david.knell@gmail.com)
4489 + * based on code by Daniel Matuschek <info@crazy-audio.com>
4490 + * based on code by Florian Meier <florian.meier@koalo.de>
4491 + *
4492 + * This program is free software; you can redistribute it and/or
4493 + * modify it under the terms of the GNU General Public License
4494 + * version 2 as published by the Free Software Foundation.
4495 + *
4496 + * This program is distributed in the hope that it will be useful, but
4497 + * WITHOUT ANY WARRANTY; without even the implied warranty of
4498 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4499 + * General Public License for more details.
4500 + */
4501 +
4502 +#include <linux/module.h>
4503 +#include <linux/platform_device.h>
4504 +#include <linux/gpio/consumer.h>
4505 +#include <sound/core.h>
4506 +#include <sound/pcm.h>
4507 +#include <sound/pcm_params.h>
4508 +#include <sound/soc.h>
4509 +#include <linux/firmware.h>
4510 +#include <linux/delay.h>
4511 +#include <sound/tlv.h>
4512 +#include "../codecs/pcm512x.h"
4513 +
4514 +#define P_DAC_LEFT_MUTE 0x10
4515 +#define P_DAC_RIGHT_MUTE 0x01
4516 +#define P_DAC_MUTE 0x11
4517 +#define P_DAC_UNMUTE 0x00
4518 +#define P_MUTE 1
4519 +#define P_UNMUTE 0
4520 +
4521 +struct dsp_code {
4522 + char i2c_addr;
4523 + char offset;
4524 + char val;
4525 +};
4526 +
4527 +struct glb_pool {
4528 + struct mutex lock;
4529 + unsigned int dual_mode;
4530 + unsigned int set_lowpass;
4531 + unsigned int set_mode;
4532 + unsigned int set_rate;
4533 + unsigned int dsp_page_number;
4534 +};
4535 +
4536 +static bool digital_gain_0db_limit = true;
4537 +bool glb_mclk;
4538 +
4539 +static struct gpio_desc *mute_gpio[2];
4540 +
4541 +static const char * const allo_piano_mode_texts[] = {
4542 + "None",
4543 + "2.0",
4544 + "2.1",
4545 + "2.2",
4546 +};
4547 +
4548 +static const SOC_ENUM_SINGLE_DECL(allo_piano_mode_enum,
4549 + 0, 0, allo_piano_mode_texts);
4550 +
4551 +static const char * const allo_piano_dual_mode_texts[] = {
4552 + "None",
4553 + "Dual-Mono",
4554 + "Dual-Stereo",
4555 +};
4556 +
4557 +static const SOC_ENUM_SINGLE_DECL(allo_piano_dual_mode_enum,
4558 + 0, 0, allo_piano_dual_mode_texts);
4559 +
4560 +static const char * const allo_piano_dsp_low_pass_texts[] = {
4561 + "60",
4562 + "70",
4563 + "80",
4564 + "90",
4565 + "100",
4566 + "110",
4567 + "120",
4568 + "130",
4569 + "140",
4570 + "150",
4571 + "160",
4572 + "170",
4573 + "180",
4574 + "190",
4575 + "200",
4576 +};
4577 +
4578 +static const SOC_ENUM_SINGLE_DECL(allo_piano_enum,
4579 + 0, 0, allo_piano_dsp_low_pass_texts);
4580 +
4581 +static int __snd_allo_piano_dsp_program(struct snd_soc_pcm_runtime *rtd,
4582 + unsigned int mode, unsigned int rate, unsigned int lowpass)
4583 +{
4584 + const struct firmware *fw;
4585 + struct snd_soc_card *card = rtd->card;
4586 + struct glb_pool *glb_ptr = card->drvdata;
4587 + char firmware_name[60];
4588 + int ret = 0, dac = 0;
4589 +
4590 + if (rate <= 46000)
4591 + rate = 44100;
4592 + else if (rate <= 68000)
4593 + rate = 48000;
4594 + else if (rate <= 92000)
4595 + rate = 88200;
4596 + else if (rate <= 136000)
4597 + rate = 96000;
4598 + else if (rate <= 184000)
4599 + rate = 176400;
4600 + else
4601 + rate = 192000;
4602 +
4603 + if (lowpass > 14)
4604 + glb_ptr->set_lowpass = lowpass = 0;
4605 +
4606 + if (mode > 3)
4607 + glb_ptr->set_mode = mode = 0;
4608 +
4609 + if (mode > 0)
4610 + glb_ptr->dual_mode = 0;
4611 +
4612 + /* same configuration loaded */
4613 + if ((rate == glb_ptr->set_rate) && (lowpass == glb_ptr->set_lowpass)
4614 + && (mode == glb_ptr->set_mode))
4615 + return 0;
4616 +
4617 + switch (mode) {
4618 + case 0: /* None */
4619 + return 1;
4620 +
4621 + case 1: /* 2.0 */
4622 + snd_soc_component_write(asoc_rtd_to_codec(rtd, 0)->component,
4623 + PCM512x_MUTE, P_DAC_UNMUTE);
4624 + snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component,
4625 + PCM512x_MUTE, P_DAC_MUTE);
4626 + glb_ptr->set_rate = rate;
4627 + glb_ptr->set_mode = mode;
4628 + glb_ptr->set_lowpass = lowpass;
4629 + return 1;
4630 +
4631 + default:
4632 + snd_soc_component_write(asoc_rtd_to_codec(rtd, 0)->component,
4633 + PCM512x_MUTE, P_DAC_UNMUTE);
4634 + snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component,
4635 + PCM512x_MUTE, P_DAC_UNMUTE);
4636 + }
4637 +
4638 + for (dac = 0; dac < rtd->num_codecs; dac++) {
4639 + struct dsp_code *dsp_code_read;
4640 + int i = 1;
4641 +
4642 + if (dac == 0) { /* high */
4643 + snprintf(firmware_name, sizeof(firmware_name),
4644 + "allo/piano/2.2/allo-piano-dsp-%d-%d-%d.bin",
4645 + rate, ((lowpass * 10) + 60), dac);
4646 + } else { /* low */
4647 + snprintf(firmware_name, sizeof(firmware_name),
4648 + "allo/piano/2.%d/allo-piano-dsp-%d-%d-%d.bin",
4649 + (mode - 1), rate, ((lowpass * 10) + 60), dac);
4650 + }
4651 +
4652 + dev_info(rtd->card->dev, "Dsp Firmware File Name: %s\n",
4653 + firmware_name);
4654 +
4655 + ret = request_firmware(&fw, firmware_name, rtd->card->dev);
4656 + if (ret < 0) {
4657 + dev_err(rtd->card->dev,
4658 + "Error: Allo Piano Firmware %s missing. %d\n",
4659 + firmware_name, ret);
4660 + goto err;
4661 + }
4662 +
4663 + while (i < (fw->size - 1)) {
4664 + dsp_code_read = (struct dsp_code *)&fw->data[i];
4665 +
4666 + if (dsp_code_read->offset == 0) {
4667 + glb_ptr->dsp_page_number = dsp_code_read->val;
4668 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, dac)->component,
4669 + PCM512x_PAGE_BASE(0),
4670 + dsp_code_read->val);
4671 +
4672 + } else if (dsp_code_read->offset != 0) {
4673 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, dac)->component,
4674 + (PCM512x_PAGE_BASE(
4675 + glb_ptr->dsp_page_number) +
4676 + dsp_code_read->offset),
4677 + dsp_code_read->val);
4678 + }
4679 + if (ret < 0) {
4680 + dev_err(rtd->card->dev,
4681 + "Failed to write Register: %d\n", ret);
4682 + release_firmware(fw);
4683 + goto err;
4684 + }
4685 + i = i + 3;
4686 + }
4687 + release_firmware(fw);
4688 + }
4689 + glb_ptr->set_rate = rate;
4690 + glb_ptr->set_mode = mode;
4691 + glb_ptr->set_lowpass = lowpass;
4692 + return 1;
4693 +
4694 +err:
4695 + return ret;
4696 +}
4697 +
4698 +static int snd_allo_piano_dsp_program(struct snd_soc_pcm_runtime *rtd,
4699 + unsigned int mode, unsigned int rate, unsigned int lowpass)
4700 +{
4701 + struct snd_soc_card *card = rtd->card;
4702 + struct glb_pool *glb_ptr = card->drvdata;
4703 + int ret = 0;
4704 +
4705 + mutex_lock(&glb_ptr->lock);
4706 +
4707 + ret = __snd_allo_piano_dsp_program(rtd, mode, rate, lowpass);
4708 +
4709 + mutex_unlock(&glb_ptr->lock);
4710 +
4711 + return ret;
4712 +}
4713 +
4714 +static int snd_allo_piano_dual_mode_get(struct snd_kcontrol *kcontrol,
4715 + struct snd_ctl_elem_value *ucontrol)
4716 +{
4717 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
4718 + struct glb_pool *glb_ptr = card->drvdata;
4719 +
4720 + ucontrol->value.integer.value[0] = glb_ptr->dual_mode;
4721 +
4722 + return 0;
4723 +}
4724 +
4725 +static int snd_allo_piano_dual_mode_put(struct snd_kcontrol *kcontrol,
4726 + struct snd_ctl_elem_value *ucontrol)
4727 +{
4728 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
4729 + struct glb_pool *glb_ptr = card->drvdata;
4730 + struct snd_soc_pcm_runtime *rtd;
4731 + struct snd_card *snd_card_ptr = card->snd_card;
4732 + struct snd_kcontrol *kctl;
4733 + struct soc_mixer_control *mc;
4734 + unsigned int left_val = 0, right_val = 0;
4735 +
4736 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
4737 +
4738 + if (ucontrol->value.integer.value[0] > 0) {
4739 + glb_ptr->dual_mode = ucontrol->value.integer.value[0];
4740 + glb_ptr->set_mode = 0;
4741 + } else {
4742 + if (glb_ptr->set_mode <= 0) {
4743 + glb_ptr->dual_mode = 1;
4744 + glb_ptr->set_mode = 0;
4745 + } else {
4746 + glb_ptr->dual_mode = 0;
4747 + return 0;
4748 + }
4749 + }
4750 +
4751 + if (glb_ptr->dual_mode == 1) { // Dual Mono
4752 + snd_soc_component_write(asoc_rtd_to_codec(rtd, 0)->component,
4753 + PCM512x_MUTE, P_DAC_RIGHT_MUTE);
4754 + snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component,
4755 + PCM512x_MUTE, P_DAC_LEFT_MUTE);
4756 + snd_soc_component_write(asoc_rtd_to_codec(rtd, 0)->component,
4757 + PCM512x_DIGITAL_VOLUME_3, 0xff);
4758 + snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component,
4759 + PCM512x_DIGITAL_VOLUME_2, 0xff);
4760 +
4761 + list_for_each_entry(kctl, &snd_card_ptr->controls, list) {
4762 + if (!strncmp(kctl->id.name, "Main Digital Playback Volume",
4763 + sizeof(kctl->id.name))) {
4764 + mc = (struct soc_mixer_control *)
4765 + kctl->private_value;
4766 + mc->rreg = mc->reg;
4767 + break;
4768 + }
4769 + if (!strncmp(kctl->id.name, "Sub Digital Playback Volume",
4770 + sizeof(kctl->id.name))) {
4771 + mc = (struct soc_mixer_control *)
4772 + kctl->private_value;
4773 + mc->rreg = mc->reg;
4774 + break;
4775 + }
4776 + }
4777 + } else {
4778 + left_val = snd_soc_component_read(asoc_rtd_to_codec(rtd, 0)->component,
4779 + PCM512x_DIGITAL_VOLUME_2);
4780 + right_val = snd_soc_component_read(asoc_rtd_to_codec(rtd, 1)->component,
4781 + PCM512x_DIGITAL_VOLUME_3);
4782 +
4783 + list_for_each_entry(kctl, &snd_card_ptr->controls, list) {
4784 + if (!strncmp(kctl->id.name, "Main Digital Playback Volume",
4785 + sizeof(kctl->id.name))) {
4786 + mc = (struct soc_mixer_control *)
4787 + kctl->private_value;
4788 + mc->rreg = PCM512x_DIGITAL_VOLUME_3;
4789 + break;
4790 + }
4791 + if (!strncmp(kctl->id.name, "Sub Digital Playback Volume",
4792 + sizeof(kctl->id.name))) {
4793 + mc = (struct soc_mixer_control *)
4794 + kctl->private_value;
4795 + mc->rreg = PCM512x_DIGITAL_VOLUME_2;
4796 + break;
4797 + }
4798 + }
4799 +
4800 + snd_soc_component_write(asoc_rtd_to_codec(rtd, 0)->component,
4801 + PCM512x_DIGITAL_VOLUME_3, left_val);
4802 + snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component,
4803 + PCM512x_DIGITAL_VOLUME_2, right_val);
4804 + snd_soc_component_write(asoc_rtd_to_codec(rtd, 0)->component,
4805 + PCM512x_MUTE, P_DAC_UNMUTE);
4806 + snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component,
4807 + PCM512x_MUTE, P_DAC_UNMUTE);
4808 + }
4809 +
4810 + return 0;
4811 +}
4812 +
4813 +static int snd_allo_piano_mode_get(struct snd_kcontrol *kcontrol,
4814 + struct snd_ctl_elem_value *ucontrol)
4815 +{
4816 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
4817 + struct glb_pool *glb_ptr = card->drvdata;
4818 +
4819 + ucontrol->value.integer.value[0] = glb_ptr->set_mode;
4820 + return 0;
4821 +}
4822 +
4823 +static int snd_allo_piano_mode_put(struct snd_kcontrol *kcontrol,
4824 + struct snd_ctl_elem_value *ucontrol)
4825 +{
4826 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
4827 + struct snd_soc_pcm_runtime *rtd;
4828 + struct glb_pool *glb_ptr = card->drvdata;
4829 + struct snd_card *snd_card_ptr = card->snd_card;
4830 + struct snd_kcontrol *kctl;
4831 + struct soc_mixer_control *mc;
4832 + unsigned int left_val = 0, right_val = 0;
4833 +
4834 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
4835 +
4836 + if ((glb_ptr->dual_mode == 1) &&
4837 + (ucontrol->value.integer.value[0] > 0)) {
4838 + left_val = snd_soc_component_read(asoc_rtd_to_codec(rtd, 0)->component,
4839 + PCM512x_DIGITAL_VOLUME_2);
4840 + right_val = snd_soc_component_read(asoc_rtd_to_codec(rtd, 1)->component,
4841 + PCM512x_DIGITAL_VOLUME_2);
4842 +
4843 + list_for_each_entry(kctl, &snd_card_ptr->controls, list) {
4844 + if (!strncmp(kctl->id.name, "Main Digital Playback Volume",
4845 + sizeof(kctl->id.name))) {
4846 + mc = (struct soc_mixer_control *)
4847 + kctl->private_value;
4848 + mc->rreg = PCM512x_DIGITAL_VOLUME_3;
4849 + break;
4850 + }
4851 + if (!strncmp(kctl->id.name, "Sub Digital Playback Volume",
4852 + sizeof(kctl->id.name))) {
4853 + mc = (struct soc_mixer_control *)
4854 + kctl->private_value;
4855 + mc->rreg = PCM512x_DIGITAL_VOLUME_2;
4856 + break;
4857 + }
4858 + }
4859 + snd_soc_component_write(asoc_rtd_to_codec(rtd, 0)->component,
4860 + PCM512x_DIGITAL_VOLUME_3, left_val);
4861 + snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component,
4862 + PCM512x_DIGITAL_VOLUME_3, right_val);
4863 + }
4864 +
4865 + return(snd_allo_piano_dsp_program(rtd,
4866 + ucontrol->value.integer.value[0],
4867 + glb_ptr->set_rate, glb_ptr->set_lowpass));
4868 +}
4869 +
4870 +static int snd_allo_piano_lowpass_get(struct snd_kcontrol *kcontrol,
4871 + struct snd_ctl_elem_value *ucontrol)
4872 +{
4873 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
4874 + struct glb_pool *glb_ptr = card->drvdata;
4875 +
4876 + ucontrol->value.integer.value[0] = glb_ptr->set_lowpass;
4877 + return 0;
4878 +}
4879 +
4880 +static int snd_allo_piano_lowpass_put(struct snd_kcontrol *kcontrol,
4881 + struct snd_ctl_elem_value *ucontrol)
4882 +{
4883 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
4884 + struct snd_soc_pcm_runtime *rtd;
4885 + struct glb_pool *glb_ptr = card->drvdata;
4886 +
4887 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
4888 + return(snd_allo_piano_dsp_program(rtd,
4889 + glb_ptr->set_mode, glb_ptr->set_rate,
4890 + ucontrol->value.integer.value[0]));
4891 +}
4892 +
4893 +static int pcm512x_get_reg_sub(struct snd_kcontrol *kcontrol,
4894 + struct snd_ctl_elem_value *ucontrol)
4895 +{
4896 + struct soc_mixer_control *mc =
4897 + (struct soc_mixer_control *)kcontrol->private_value;
4898 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
4899 + struct glb_pool *glb_ptr = card->drvdata;
4900 + struct snd_soc_pcm_runtime *rtd;
4901 + unsigned int left_val = 0;
4902 + unsigned int right_val = 0;
4903 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
4904 +
4905 + right_val = snd_soc_component_read(asoc_rtd_to_codec(rtd, 1)->component,
4906 + PCM512x_DIGITAL_VOLUME_3);
4907 + if (glb_ptr->dual_mode != 1) {
4908 + left_val = snd_soc_component_read(asoc_rtd_to_codec(rtd, 1)->component,
4909 + PCM512x_DIGITAL_VOLUME_2);
4910 +
4911 + } else {
4912 + left_val = right_val;
4913 + }
4914 +
4915 + ucontrol->value.integer.value[0] =
4916 + (~(left_val >> mc->shift)) & mc->max;
4917 + ucontrol->value.integer.value[1] =
4918 + (~(right_val >> mc->shift)) & mc->max;
4919 +
4920 + return 0;
4921 +}
4922 +
4923 +static int pcm512x_set_reg_sub(struct snd_kcontrol *kcontrol,
4924 + struct snd_ctl_elem_value *ucontrol)
4925 +{
4926 + struct soc_mixer_control *mc =
4927 + (struct soc_mixer_control *)kcontrol->private_value;
4928 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
4929 + struct glb_pool *glb_ptr = card->drvdata;
4930 + struct snd_soc_pcm_runtime *rtd;
4931 + unsigned int left_val = (ucontrol->value.integer.value[0] & mc->max);
4932 + unsigned int right_val = (ucontrol->value.integer.value[1] & mc->max);
4933 + int ret = 0;
4934 +
4935 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
4936 +
4937 + if (digital_gain_0db_limit) {
4938 + ret = snd_soc_limit_volume(card, "Subwoofer Playback Volume",
4939 + 207);
4940 + if (ret < 0)
4941 + dev_warn(card->dev, "Failed to set volume limit: %d\n",
4942 + ret);
4943 + }
4944 +
4945 + // When in Dual Mono, Sub vol control should not set anything.
4946 + if (glb_ptr->dual_mode != 1) { //Not in Dual Mono mode
4947 +
4948 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component,
4949 + PCM512x_DIGITAL_VOLUME_2, (~left_val));
4950 + if (ret < 0)
4951 + return ret;
4952 +
4953 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component,
4954 + PCM512x_DIGITAL_VOLUME_3, (~right_val));
4955 + if (ret < 0)
4956 + return ret;
4957 +
4958 + }
4959 +
4960 + return 1;
4961 +}
4962 +
4963 +static int pcm512x_get_reg_sub_switch(struct snd_kcontrol *kcontrol,
4964 + struct snd_ctl_elem_value *ucontrol)
4965 +{
4966 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
4967 + struct snd_soc_pcm_runtime *rtd;
4968 + int val = 0;
4969 +
4970 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
4971 + val = snd_soc_component_read(asoc_rtd_to_codec(rtd, 1)->component, PCM512x_MUTE);
4972 +
4973 + ucontrol->value.integer.value[0] =
4974 + (val & P_DAC_LEFT_MUTE) ? P_UNMUTE : P_MUTE;
4975 + ucontrol->value.integer.value[1] =
4976 + (val & P_DAC_RIGHT_MUTE) ? P_UNMUTE : P_MUTE;
4977 +
4978 + return val;
4979 +}
4980 +
4981 +static int pcm512x_set_reg_sub_switch(struct snd_kcontrol *kcontrol,
4982 + struct snd_ctl_elem_value *ucontrol)
4983 +{
4984 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
4985 + struct snd_soc_pcm_runtime *rtd;
4986 + struct glb_pool *glb_ptr = card->drvdata;
4987 + unsigned int left_val = (ucontrol->value.integer.value[0]);
4988 + unsigned int right_val = (ucontrol->value.integer.value[1]);
4989 + int ret = 0;
4990 +
4991 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
4992 + if (glb_ptr->set_mode != 1) {
4993 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component, PCM512x_MUTE,
4994 + ~((left_val & 0x01)<<4 | (right_val & 0x01)));
4995 + if (ret < 0)
4996 + return ret;
4997 + }
4998 + return 1;
4999 +
5000 +}
5001 +
5002 +static int pcm512x_get_reg_master(struct snd_kcontrol *kcontrol,
5003 + struct snd_ctl_elem_value *ucontrol)
5004 +{
5005 + struct soc_mixer_control *mc =
5006 + (struct soc_mixer_control *)kcontrol->private_value;
5007 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
5008 + struct glb_pool *glb_ptr = card->drvdata;
5009 + struct snd_soc_pcm_runtime *rtd;
5010 + unsigned int left_val = 0, right_val = 0;
5011 +
5012 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
5013 +
5014 + left_val = snd_soc_component_read(asoc_rtd_to_codec(rtd, 0)->component,
5015 + PCM512x_DIGITAL_VOLUME_2);
5016 +
5017 + if (glb_ptr->dual_mode == 1) { // in Dual Mono mode
5018 + right_val = snd_soc_component_read(asoc_rtd_to_codec(rtd, 1)->component,
5019 + PCM512x_DIGITAL_VOLUME_3);
5020 + } else {
5021 + right_val = snd_soc_component_read(asoc_rtd_to_codec(rtd, 0)->component,
5022 + PCM512x_DIGITAL_VOLUME_3);
5023 + }
5024 +
5025 + ucontrol->value.integer.value[0] =
5026 + (~(left_val >> mc->shift)) & mc->max;
5027 + ucontrol->value.integer.value[1] =
5028 + (~(right_val >> mc->shift)) & mc->max;
5029 +
5030 + return 0;
5031 +}
5032 +
5033 +static int pcm512x_set_reg_master(struct snd_kcontrol *kcontrol,
5034 + struct snd_ctl_elem_value *ucontrol)
5035 +{
5036 + struct soc_mixer_control *mc =
5037 + (struct soc_mixer_control *)kcontrol->private_value;
5038 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
5039 + struct glb_pool *glb_ptr = card->drvdata;
5040 + struct snd_soc_pcm_runtime *rtd;
5041 + unsigned int left_val = (ucontrol->value.integer.value[0] & mc->max);
5042 + unsigned int right_val = (ucontrol->value.integer.value[1] & mc->max);
5043 + int ret = 0;
5044 +
5045 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
5046 +
5047 + if (digital_gain_0db_limit) {
5048 + ret = snd_soc_limit_volume(card, "Master Playback Volume",
5049 + 207);
5050 + if (ret < 0)
5051 + dev_warn(card->dev, "Failed to set volume limit: %d\n",
5052 + ret);
5053 + }
5054 +
5055 + if (glb_ptr->dual_mode == 1) { //in Dual Mono Mode
5056 +
5057 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 0)->component,
5058 + PCM512x_DIGITAL_VOLUME_2, (~left_val));
5059 + if (ret < 0)
5060 + return ret;
5061 +
5062 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component,
5063 + PCM512x_DIGITAL_VOLUME_3, (~right_val));
5064 + if (ret < 0)
5065 + return ret;
5066 +
5067 + } else {
5068 +
5069 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 0)->component,
5070 + PCM512x_DIGITAL_VOLUME_2, (~left_val));
5071 + if (ret < 0)
5072 + return ret;
5073 +
5074 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 0)->component,
5075 + PCM512x_DIGITAL_VOLUME_3, (~right_val));
5076 + if (ret < 0)
5077 + return ret;
5078 +
5079 + }
5080 + return 1;
5081 +}
5082 +
5083 +static int pcm512x_get_reg_master_switch(struct snd_kcontrol *kcontrol,
5084 + struct snd_ctl_elem_value *ucontrol)
5085 +{
5086 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
5087 + struct glb_pool *glb_ptr = card->drvdata;
5088 + struct snd_soc_pcm_runtime *rtd;
5089 + int val = 0;
5090 +
5091 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
5092 +
5093 + val = snd_soc_component_read(asoc_rtd_to_codec(rtd, 0)->component, PCM512x_MUTE);
5094 +
5095 + ucontrol->value.integer.value[0] =
5096 + (val & P_DAC_LEFT_MUTE) ? P_UNMUTE : P_MUTE;
5097 +
5098 + if (glb_ptr->dual_mode == 1) {
5099 + val = snd_soc_component_read(asoc_rtd_to_codec(rtd, 1)->component, PCM512x_MUTE);
5100 + }
5101 + ucontrol->value.integer.value[1] =
5102 + (val & P_DAC_RIGHT_MUTE) ? P_UNMUTE : P_MUTE;
5103 +
5104 + return val;
5105 +}
5106 +
5107 +static int pcm512x_set_reg_master_switch(struct snd_kcontrol *kcontrol,
5108 + struct snd_ctl_elem_value *ucontrol)
5109 +{
5110 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
5111 + struct snd_soc_pcm_runtime *rtd;
5112 + struct glb_pool *glb_ptr = card->drvdata;
5113 + unsigned int left_val = (ucontrol->value.integer.value[0]);
5114 + unsigned int right_val = (ucontrol->value.integer.value[1]);
5115 + int ret = 0;
5116 +
5117 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
5118 + if (glb_ptr->dual_mode == 1) {
5119 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 0)->component, PCM512x_MUTE,
5120 + ~((left_val & 0x01)<<4));
5121 + if (ret < 0)
5122 + return ret;
5123 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component, PCM512x_MUTE,
5124 + ~((right_val & 0x01)));
5125 + if (ret < 0)
5126 + return ret;
5127 +
5128 + } else if (glb_ptr->set_mode == 1) {
5129 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 0)->component, PCM512x_MUTE,
5130 + ~((left_val & 0x01)<<4 | (right_val & 0x01)));
5131 + if (ret < 0)
5132 + return ret;
5133 +
5134 + } else {
5135 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 0)->component, PCM512x_MUTE,
5136 + ~((left_val & 0x01)<<4 | (right_val & 0x01)));
5137 + if (ret < 0)
5138 + return ret;
5139 +
5140 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component, PCM512x_MUTE,
5141 + ~((left_val & 0x01)<<4 | (right_val & 0x01)));
5142 + if (ret < 0)
5143 + return ret;
5144 + }
5145 + return 1;
5146 +}
5147 +
5148 +static const DECLARE_TLV_DB_SCALE(digital_tlv_sub, -10350, 50, 1);
5149 +static const DECLARE_TLV_DB_SCALE(digital_tlv_master, -10350, 50, 1);
5150 +
5151 +static const struct snd_kcontrol_new allo_piano_controls[] = {
5152 + SOC_ENUM_EXT("Subwoofer mode Route",
5153 + allo_piano_mode_enum,
5154 + snd_allo_piano_mode_get,
5155 + snd_allo_piano_mode_put),
5156 +
5157 + SOC_ENUM_EXT("Dual Mode Route",
5158 + allo_piano_dual_mode_enum,
5159 + snd_allo_piano_dual_mode_get,
5160 + snd_allo_piano_dual_mode_put),
5161 +
5162 + SOC_ENUM_EXT("Lowpass Route", allo_piano_enum,
5163 + snd_allo_piano_lowpass_get,
5164 + snd_allo_piano_lowpass_put),
5165 +
5166 + SOC_DOUBLE_R_EXT_TLV("Subwoofer Playback Volume",
5167 + PCM512x_DIGITAL_VOLUME_2,
5168 + PCM512x_DIGITAL_VOLUME_3, 0, 255, 1,
5169 + pcm512x_get_reg_sub,
5170 + pcm512x_set_reg_sub,
5171 + digital_tlv_sub),
5172 +
5173 + SOC_DOUBLE_EXT("Subwoofer Playback Switch",
5174 + PCM512x_MUTE,
5175 + PCM512x_RQML_SHIFT,
5176 + PCM512x_RQMR_SHIFT, 1, 1,
5177 + pcm512x_get_reg_sub_switch,
5178 + pcm512x_set_reg_sub_switch),
5179 +
5180 + SOC_DOUBLE_R_EXT_TLV("Master Playback Volume",
5181 + PCM512x_DIGITAL_VOLUME_2,
5182 + PCM512x_DIGITAL_VOLUME_3, 0, 255, 1,
5183 + pcm512x_get_reg_master,
5184 + pcm512x_set_reg_master,
5185 + digital_tlv_master),
5186 +
5187 + SOC_DOUBLE_EXT("Master Playback Switch",
5188 + PCM512x_MUTE,
5189 + PCM512x_RQML_SHIFT,
5190 + PCM512x_RQMR_SHIFT, 1, 1,
5191 + pcm512x_get_reg_master_switch,
5192 + pcm512x_set_reg_master_switch),
5193 +};
5194 +
5195 +static const char * const codec_ctl_pfx[] = { "Main", "Sub" };
5196 +static const char * const codec_ctl_name[] = {
5197 + "Digital Playback Volume",
5198 + "Digital Playback Switch",
5199 + "Auto Mute Mono Switch",
5200 + "Auto Mute Switch",
5201 + "Auto Mute Time Left",
5202 + "Auto Mute Time Right",
5203 + "Clock Missing Period",
5204 + "Max Overclock DAC",
5205 + "Max Overclock DSP",
5206 + "Max Overclock PLL",
5207 + "Volume Ramp Down Emergency Rate",
5208 + "Volume Ramp Down Emergency Step",
5209 + "Volume Ramp Up Rate",
5210 + "Volume Ramp Down Rate",
5211 + "Volume Ramp Up Step",
5212 + "Volume Ramp Down Step"
5213 +};
5214 +
5215 +static int snd_allo_piano_dac_init(struct snd_soc_pcm_runtime *rtd)
5216 +{
5217 + struct snd_soc_card *card = rtd->card;
5218 + struct glb_pool *glb_ptr;
5219 + struct snd_kcontrol *kctl;
5220 + int i, j;
5221 +
5222 + glb_ptr = kzalloc(sizeof(struct glb_pool), GFP_KERNEL);
5223 + if (!glb_ptr)
5224 + return -ENOMEM;
5225 +
5226 + card->drvdata = glb_ptr;
5227 + glb_ptr->dual_mode = 2;
5228 + glb_ptr->set_mode = 0;
5229 +
5230 + mutex_init(&glb_ptr->lock);
5231 +
5232 + if (digital_gain_0db_limit) {
5233 + int ret;
5234 +
5235 + //Set volume limit on both dacs
5236 + for (i = 0; i < ARRAY_SIZE(codec_ctl_pfx); i++) {
5237 + char cname[256];
5238 +
5239 + sprintf(cname, "%s %s", codec_ctl_pfx[i], codec_ctl_name[0]);
5240 + ret = snd_soc_limit_volume(card, cname, 207);
5241 + if (ret < 0)
5242 + dev_warn(card->dev, "Failed to set volume limit: %d\n",
5243 + ret);
5244 + }
5245 + }
5246 +
5247 + // Remove codec controls
5248 + for (i = 0; i < ARRAY_SIZE(codec_ctl_pfx); i++) {
5249 + for (j = 0; j < ARRAY_SIZE(codec_ctl_name); j++) {
5250 + char cname[256];
5251 +
5252 + sprintf(cname, "%s %s", codec_ctl_pfx[i], codec_ctl_name[j]);
5253 + kctl = snd_soc_card_get_kcontrol(card, cname);
5254 + if (!kctl) {
5255 + dev_err(rtd->card->dev, "Control %s not found\n",
5256 + cname);
5257 + } else {
5258 + kctl->vd[0].access =
5259 + SNDRV_CTL_ELEM_ACCESS_READWRITE;
5260 + snd_ctl_remove(card->snd_card, kctl);
5261 + }
5262 + }
5263 + }
5264 +
5265 + return 0;
5266 +}
5267 +
5268 +static void snd_allo_piano_gpio_mute(struct snd_soc_card *card)
5269 +{
5270 + if (mute_gpio[0])
5271 + gpiod_set_value_cansleep(mute_gpio[0], P_MUTE);
5272 +
5273 + if (mute_gpio[1])
5274 + gpiod_set_value_cansleep(mute_gpio[1], P_MUTE);
5275 +}
5276 +
5277 +static void snd_allo_piano_gpio_unmute(struct snd_soc_card *card)
5278 +{
5279 + if (mute_gpio[0])
5280 + gpiod_set_value_cansleep(mute_gpio[0], P_UNMUTE);
5281 +
5282 + if (mute_gpio[1])
5283 + gpiod_set_value_cansleep(mute_gpio[1], P_UNMUTE);
5284 +}
5285 +
5286 +static int snd_allo_piano_set_bias_level(struct snd_soc_card *card,
5287 + struct snd_soc_dapm_context *dapm, enum snd_soc_bias_level level)
5288 +{
5289 + struct snd_soc_pcm_runtime *rtd;
5290 + struct snd_soc_dai *codec_dai;
5291 +
5292 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
5293 + codec_dai = asoc_rtd_to_codec(rtd, 0);
5294 +
5295 + if (dapm->dev != codec_dai->dev)
5296 + return 0;
5297 +
5298 + switch (level) {
5299 + case SND_SOC_BIAS_PREPARE:
5300 + if (dapm->bias_level != SND_SOC_BIAS_STANDBY)
5301 + break;
5302 + /* UNMUTE DAC */
5303 + snd_allo_piano_gpio_unmute(card);
5304 + break;
5305 +
5306 + case SND_SOC_BIAS_STANDBY:
5307 + if (dapm->bias_level != SND_SOC_BIAS_PREPARE)
5308 + break;
5309 + /* MUTE DAC */
5310 + snd_allo_piano_gpio_mute(card);
5311 + break;
5312 +
5313 + default:
5314 + break;
5315 + }
5316 +
5317 + return 0;
5318 +}
5319 +
5320 +static int snd_allo_piano_dac_startup(
5321 + struct snd_pcm_substream *substream)
5322 +{
5323 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
5324 + struct snd_soc_card *card = rtd->card;
5325 +
5326 + snd_allo_piano_gpio_mute(card);
5327 +
5328 + return 0;
5329 +}
5330 +
5331 +static int snd_allo_piano_dac_hw_params(
5332 + struct snd_pcm_substream *substream,
5333 + struct snd_pcm_hw_params *params)
5334 +{
5335 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
5336 + unsigned int rate = params_rate(params);
5337 + struct snd_soc_card *card = rtd->card;
5338 + struct glb_pool *glb_ptr = card->drvdata;
5339 + int ret = 0, val = 0, dac;
5340 +
5341 + for (dac = 0; (glb_mclk && dac < 2); dac++) {
5342 + /* Configure the PLL clock reference for both the Codecs */
5343 + val = snd_soc_component_read(asoc_rtd_to_codec(rtd, dac)->component,
5344 + PCM512x_RATE_DET_4);
5345 +
5346 + if (val & 0x40) {
5347 + snd_soc_component_write(asoc_rtd_to_codec(rtd, dac)->component,
5348 + PCM512x_PLL_REF,
5349 + PCM512x_SREF_BCK);
5350 +
5351 + dev_info(asoc_rtd_to_codec(rtd, dac)->component->dev,
5352 + "Setting BCLK as input clock & Enable PLL\n");
5353 + } else {
5354 + snd_soc_component_write(asoc_rtd_to_codec(rtd, dac)->component,
5355 + PCM512x_PLL_EN,
5356 + 0x00);
5357 +
5358 + snd_soc_component_write(asoc_rtd_to_codec(rtd, dac)->component,
5359 + PCM512x_PLL_REF,
5360 + PCM512x_SREF_SCK);
5361 +
5362 + dev_info(asoc_rtd_to_codec(rtd, dac)->component->dev,
5363 + "Setting SCLK as input clock & disabled PLL\n");
5364 + }
5365 + }
5366 +
5367 + ret = snd_allo_piano_dsp_program(rtd, glb_ptr->set_mode, rate,
5368 + glb_ptr->set_lowpass);
5369 + if (ret < 0)
5370 + return ret;
5371 +
5372 + return ret;
5373 +}
5374 +
5375 +static int snd_allo_piano_dac_prepare(
5376 + struct snd_pcm_substream *substream)
5377 +{
5378 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
5379 + struct snd_soc_card *card = rtd->card;
5380 +
5381 + snd_allo_piano_gpio_unmute(card);
5382 +
5383 + return 0;
5384 +}
5385 +
5386 +/* machine stream operations */
5387 +static struct snd_soc_ops snd_allo_piano_dac_ops = {
5388 + .startup = snd_allo_piano_dac_startup,
5389 + .hw_params = snd_allo_piano_dac_hw_params,
5390 + .prepare = snd_allo_piano_dac_prepare,
5391 +};
5392 +
5393 +static struct snd_soc_dai_link_component allo_piano_2_1_codecs[] = {
5394 + {
5395 + .dai_name = "pcm512x-hifi",
5396 + },
5397 + {
5398 + .dai_name = "pcm512x-hifi",
5399 + },
5400 +};
5401 +
5402 +SND_SOC_DAILINK_DEFS(allo_piano_dai_plus,
5403 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
5404 + DAILINK_COMP_ARRAY(COMP_CODEC("pcm512x.1-004c", "pcm512x-hifi"),
5405 + COMP_CODEC("pcm512x.1-004d", "pcm512x-hifi")),
5406 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
5407 +
5408 +static struct snd_soc_dai_link snd_allo_piano_dac_dai[] = {
5409 + {
5410 + .name = "PianoDACPlus",
5411 + .stream_name = "PianoDACPlus",
5412 + .dai_fmt = SND_SOC_DAIFMT_I2S |
5413 + SND_SOC_DAIFMT_NB_NF |
5414 + SND_SOC_DAIFMT_CBS_CFS,
5415 + .ops = &snd_allo_piano_dac_ops,
5416 + .init = snd_allo_piano_dac_init,
5417 + SND_SOC_DAILINK_REG(allo_piano_dai_plus),
5418 + },
5419 +};
5420 +
5421 +/* audio machine driver */
5422 +static struct snd_soc_card snd_allo_piano_dac = {
5423 + .name = "PianoDACPlus",
5424 + .owner = THIS_MODULE,
5425 + .dai_link = snd_allo_piano_dac_dai,
5426 + .num_links = ARRAY_SIZE(snd_allo_piano_dac_dai),
5427 + .controls = allo_piano_controls,
5428 + .num_controls = ARRAY_SIZE(allo_piano_controls),
5429 +};
5430 +
5431 +static int snd_allo_piano_dac_probe(struct platform_device *pdev)
5432 +{
5433 + struct snd_soc_card *card = &snd_allo_piano_dac;
5434 + int ret = 0, i = 0;
5435 +
5436 + card->dev = &pdev->dev;
5437 + platform_set_drvdata(pdev, &snd_allo_piano_dac);
5438 +
5439 + if (pdev->dev.of_node) {
5440 + struct device_node *i2s_node;
5441 + struct snd_soc_dai_link *dai;
5442 +
5443 + dai = &snd_allo_piano_dac_dai[0];
5444 + i2s_node = of_parse_phandle(pdev->dev.of_node,
5445 + "i2s-controller", 0);
5446 + if (i2s_node) {
5447 + for (i = 0; i < card->num_links; i++) {
5448 + dai->cpus->dai_name = NULL;
5449 + dai->cpus->of_node = i2s_node;
5450 + dai->platforms->name = NULL;
5451 + dai->platforms->of_node = i2s_node;
5452 + }
5453 + }
5454 + digital_gain_0db_limit =
5455 + !of_property_read_bool(pdev->dev.of_node,
5456 + "allo,24db_digital_gain");
5457 +
5458 + glb_mclk = of_property_read_bool(pdev->dev.of_node,
5459 + "allo,glb_mclk");
5460 +
5461 + allo_piano_2_1_codecs[0].of_node =
5462 + of_parse_phandle(pdev->dev.of_node, "audio-codec", 0);
5463 + if (!allo_piano_2_1_codecs[0].of_node) {
5464 + dev_err(&pdev->dev,
5465 + "Property 'audio-codec' missing or invalid\n");
5466 + return -EINVAL;
5467 + }
5468 +
5469 + allo_piano_2_1_codecs[1].of_node =
5470 + of_parse_phandle(pdev->dev.of_node, "audio-codec", 1);
5471 + if (!allo_piano_2_1_codecs[1].of_node) {
5472 + dev_err(&pdev->dev,
5473 + "Property 'audio-codec' missing or invalid\n");
5474 + return -EINVAL;
5475 + }
5476 +
5477 + mute_gpio[0] = devm_gpiod_get_optional(&pdev->dev, "mute1",
5478 + GPIOD_OUT_LOW);
5479 + if (IS_ERR(mute_gpio[0])) {
5480 + ret = PTR_ERR(mute_gpio[0]);
5481 + dev_err(&pdev->dev,
5482 + "failed to get mute1 gpio6: %d\n", ret);
5483 + return ret;
5484 + }
5485 +
5486 + mute_gpio[1] = devm_gpiod_get_optional(&pdev->dev, "mute2",
5487 + GPIOD_OUT_LOW);
5488 + if (IS_ERR(mute_gpio[1])) {
5489 + ret = PTR_ERR(mute_gpio[1]);
5490 + dev_err(&pdev->dev,
5491 + "failed to get mute2 gpio25: %d\n", ret);
5492 + return ret;
5493 + }
5494 +
5495 + if (mute_gpio[0] && mute_gpio[1])
5496 + snd_allo_piano_dac.set_bias_level =
5497 + snd_allo_piano_set_bias_level;
5498 +
5499 + ret = snd_soc_register_card(&snd_allo_piano_dac);
5500 + if (ret < 0) {
5501 + dev_err(&pdev->dev,
5502 + "snd_soc_register_card() failed: %d\n", ret);
5503 + return ret;
5504 + }
5505 +
5506 + if ((mute_gpio[0]) && (mute_gpio[1]))
5507 + snd_allo_piano_gpio_mute(&snd_allo_piano_dac);
5508 +
5509 + return 0;
5510 + }
5511 +
5512 + return -EINVAL;
5513 +}
5514 +
5515 +static int snd_allo_piano_dac_remove(struct platform_device *pdev)
5516 +{
5517 + struct snd_soc_card *card = platform_get_drvdata(pdev);
5518 +
5519 + kfree(&card->drvdata);
5520 + snd_allo_piano_gpio_mute(&snd_allo_piano_dac);
5521 + return snd_soc_unregister_card(&snd_allo_piano_dac);
5522 +}
5523 +
5524 +static const struct of_device_id snd_allo_piano_dac_of_match[] = {
5525 + { .compatible = "allo,piano-dac-plus", },
5526 + { /* sentinel */ },
5527 +};
5528 +
5529 +MODULE_DEVICE_TABLE(of, snd_allo_piano_dac_of_match);
5530 +
5531 +static struct platform_driver snd_allo_piano_dac_driver = {
5532 + .driver = {
5533 + .name = "snd-allo-piano-dac-plus",
5534 + .owner = THIS_MODULE,
5535 + .of_match_table = snd_allo_piano_dac_of_match,
5536 + },
5537 + .probe = snd_allo_piano_dac_probe,
5538 + .remove = snd_allo_piano_dac_remove,
5539 +};
5540 +
5541 +module_platform_driver(snd_allo_piano_dac_driver);
5542 +
5543 +MODULE_AUTHOR("Baswaraj K <jaikumar@cem-solutions.net>");
5544 +MODULE_DESCRIPTION("ALSA ASoC Machine Driver for Allo Piano DAC Plus");
5545 +MODULE_LICENSE("GPL v2");
5546 --- /dev/null
5547 +++ b/sound/soc/bcm/allo-piano-dac.c
5548 @@ -0,0 +1,122 @@
5549 +/*
5550 + * ALSA ASoC Machine Driver for Allo Piano DAC
5551 + *
5552 + * Author: Baswaraj K <jaikumar@cem-solutions.net>
5553 + * Copyright 2016
5554 + * based on code by Daniel Matuschek <info@crazy-audio.com>
5555 + * based on code by Florian Meier <florian.meier@koalo.de>
5556 + *
5557 + * This program is free software; you can redistribute it and/or
5558 + * modify it under the terms of the GNU General Public License
5559 + * version 2 as published by the Free Software Foundation.
5560 + *
5561 + * This program is distributed in the hope that it will be useful, but
5562 + * WITHOUT ANY WARRANTY; without even the implied warranty of
5563 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5564 + * General Public License for more details.
5565 + */
5566 +
5567 +#include <linux/module.h>
5568 +#include <linux/platform_device.h>
5569 +
5570 +#include <sound/core.h>
5571 +#include <sound/pcm.h>
5572 +#include <sound/pcm_params.h>
5573 +#include <sound/soc.h>
5574 +
5575 +static bool digital_gain_0db_limit = true;
5576 +
5577 +static int snd_allo_piano_dac_init(struct snd_soc_pcm_runtime *rtd)
5578 +{
5579 + if (digital_gain_0db_limit) {
5580 + int ret;
5581 + struct snd_soc_card *card = rtd->card;
5582 +
5583 + ret = snd_soc_limit_volume(card, "Digital Playback Volume",
5584 + 207);
5585 + if (ret < 0)
5586 + dev_warn(card->dev, "Failed to set volume limit: %d\n",
5587 + ret);
5588 + }
5589 +
5590 + return 0;
5591 +}
5592 +
5593 +SND_SOC_DAILINK_DEFS(allo_piano_dai,
5594 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
5595 + DAILINK_COMP_ARRAY(COMP_CODEC("pcm512x.1-004c", "pcm512x-hifi")),
5596 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
5597 +
5598 +static struct snd_soc_dai_link snd_allo_piano_dac_dai[] = {
5599 +{
5600 + .name = "Piano DAC",
5601 + .stream_name = "Piano DAC HiFi",
5602 + .dai_fmt = SND_SOC_DAIFMT_I2S |
5603 + SND_SOC_DAIFMT_NB_NF |
5604 + SND_SOC_DAIFMT_CBS_CFS,
5605 + .init = snd_allo_piano_dac_init,
5606 + SND_SOC_DAILINK_REG(allo_piano_dai),
5607 +},
5608 +};
5609 +
5610 +/* audio machine driver */
5611 +static struct snd_soc_card snd_allo_piano_dac = {
5612 + .name = "PianoDAC",
5613 + .owner = THIS_MODULE,
5614 + .dai_link = snd_allo_piano_dac_dai,
5615 + .num_links = ARRAY_SIZE(snd_allo_piano_dac_dai),
5616 +};
5617 +
5618 +static int snd_allo_piano_dac_probe(struct platform_device *pdev)
5619 +{
5620 + int ret = 0;
5621 +
5622 + snd_allo_piano_dac.dev = &pdev->dev;
5623 +
5624 + if (pdev->dev.of_node) {
5625 + struct device_node *i2s_node;
5626 + struct snd_soc_dai_link *dai;
5627 +
5628 + dai = &snd_allo_piano_dac_dai[0];
5629 + i2s_node = of_parse_phandle(pdev->dev.of_node,
5630 + "i2s-controller", 0);
5631 +
5632 + if (i2s_node) {
5633 + dai->cpus->dai_name = NULL;
5634 + dai->cpus->of_node = i2s_node;
5635 + dai->platforms->name = NULL;
5636 + dai->platforms->of_node = i2s_node;
5637 + }
5638 +
5639 + digital_gain_0db_limit = !of_property_read_bool(
5640 + pdev->dev.of_node, "allo,24db_digital_gain");
5641 + }
5642 +
5643 + ret = devm_snd_soc_register_card(&pdev->dev, &snd_allo_piano_dac);
5644 + if (ret && ret != -EPROBE_DEFER)
5645 + dev_err(&pdev->dev,
5646 + "snd_soc_register_card() failed: %d\n", ret);
5647 +
5648 + return ret;
5649 +}
5650 +
5651 +static const struct of_device_id snd_allo_piano_dac_of_match[] = {
5652 + { .compatible = "allo,piano-dac", },
5653 + { /* sentinel */ },
5654 +};
5655 +MODULE_DEVICE_TABLE(of, snd_allo_piano_dac_of_match);
5656 +
5657 +static struct platform_driver snd_allo_piano_dac_driver = {
5658 + .driver = {
5659 + .name = "snd-allo-piano-dac",
5660 + .owner = THIS_MODULE,
5661 + .of_match_table = snd_allo_piano_dac_of_match,
5662 + },
5663 + .probe = snd_allo_piano_dac_probe,
5664 +};
5665 +
5666 +module_platform_driver(snd_allo_piano_dac_driver);
5667 +
5668 +MODULE_AUTHOR("Baswaraj K <jaikumar@cem-solutions.net>");
5669 +MODULE_DESCRIPTION("ALSA ASoC Machine Driver for Allo Piano DAC");
5670 +MODULE_LICENSE("GPL v2");
5671 --- /dev/null
5672 +++ b/sound/soc/bcm/audioinjector-isolated-soundcard.c
5673 @@ -0,0 +1,183 @@
5674 +/*
5675 + * ASoC Driver for AudioInjector.net isolated soundcard
5676 + *
5677 + * Created on: 20-February-2020
5678 + * Author: flatmax@flatmax.org
5679 + * based on audioinjector-octo-soundcard.c
5680 + *
5681 + * Copyright (C) 2020 Flatmax Pty. Ltd.
5682 + *
5683 + * This program is free software; you can redistribute it and/or
5684 + * modify it under the terms of the GNU General Public License
5685 + * version 2 as published by the Free Software Foundation.
5686 + *
5687 + * This program is distributed in the hope that it will be useful, but
5688 + * WITHOUT ANY WARRANTY; without even the implied warranty of
5689 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5690 + * General Public License for more details.
5691 + */
5692 +
5693 +#include <linux/module.h>
5694 +#include <linux/types.h>
5695 +#include <linux/gpio/consumer.h>
5696 +
5697 +#include <sound/core.h>
5698 +#include <sound/soc.h>
5699 +#include <sound/pcm_params.h>
5700 +#include <sound/control.h>
5701 +
5702 +static struct gpio_desc *mute_gpio;
5703 +
5704 +static const unsigned int audioinjector_isolated_rates[] = {
5705 + 192000, 96000, 48000, 32000, 24000, 16000, 8000
5706 +};
5707 +
5708 +static struct snd_pcm_hw_constraint_list audioinjector_isolated_constraints = {
5709 + .list = audioinjector_isolated_rates,
5710 + .count = ARRAY_SIZE(audioinjector_isolated_rates),
5711 +};
5712 +
5713 +static int audioinjector_isolated_dai_init(struct snd_soc_pcm_runtime *rtd)
5714 +{
5715 + int ret=snd_soc_dai_set_sysclk(asoc_rtd_to_codec(rtd, 0), 0, 24576000, 0);
5716 + if (ret)
5717 + return ret;
5718 +
5719 + return snd_soc_dai_set_bclk_ratio(asoc_rtd_to_cpu(rtd, 0), 64);
5720 +}
5721 +
5722 +static int audioinjector_isolated_startup(struct snd_pcm_substream *substream)
5723 +{
5724 + snd_pcm_hw_constraint_list(substream->runtime, 0,
5725 + SNDRV_PCM_HW_PARAM_RATE, &audioinjector_isolated_constraints);
5726 +
5727 + return 0;
5728 +}
5729 +
5730 +static int audioinjector_isolated_trigger(struct snd_pcm_substream *substream,
5731 + int cmd){
5732 +
5733 + switch (cmd) {
5734 + case SNDRV_PCM_TRIGGER_STOP:
5735 + case SNDRV_PCM_TRIGGER_SUSPEND:
5736 + case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
5737 + gpiod_set_value(mute_gpio, 0);
5738 + break;
5739 + case SNDRV_PCM_TRIGGER_START:
5740 + case SNDRV_PCM_TRIGGER_RESUME:
5741 + case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
5742 + gpiod_set_value(mute_gpio, 1);
5743 + break;
5744 + default:
5745 + return -EINVAL;
5746 + }
5747 + return 0;
5748 +}
5749 +
5750 +static struct snd_soc_ops audioinjector_isolated_ops = {
5751 + .startup = audioinjector_isolated_startup,
5752 + .trigger = audioinjector_isolated_trigger,
5753 +};
5754 +
5755 +SND_SOC_DAILINK_DEFS(audioinjector_isolated,
5756 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
5757 + DAILINK_COMP_ARRAY(COMP_CODEC("cs4271.1-0010", "cs4271-hifi")),
5758 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
5759 +
5760 +static struct snd_soc_dai_link audioinjector_isolated_dai[] = {
5761 + {
5762 + .name = "AudioInjector ISO",
5763 + .stream_name = "AI-HIFI",
5764 + .ops = &audioinjector_isolated_ops,
5765 + .init = audioinjector_isolated_dai_init,
5766 + .symmetric_rate = 1,
5767 + .symmetric_channels = 1,
5768 + .dai_fmt = SND_SOC_DAIFMT_CBM_CFM|SND_SOC_DAIFMT_I2S|SND_SOC_DAIFMT_NB_NF,
5769 + SND_SOC_DAILINK_REG(audioinjector_isolated),
5770 + }
5771 +};
5772 +
5773 +static const struct snd_soc_dapm_widget audioinjector_isolated_widgets[] = {
5774 + SND_SOC_DAPM_OUTPUT("OUTPUTS"),
5775 + SND_SOC_DAPM_INPUT("INPUTS"),
5776 +};
5777 +
5778 +static const struct snd_soc_dapm_route audioinjector_isolated_route[] = {
5779 + /* Balanced outputs */
5780 + {"OUTPUTS", NULL, "AOUTA+"},
5781 + {"OUTPUTS", NULL, "AOUTA-"},
5782 + {"OUTPUTS", NULL, "AOUTB+"},
5783 + {"OUTPUTS", NULL, "AOUTB-"},
5784 +
5785 + /* Balanced inputs */
5786 + {"AINA", NULL, "INPUTS"},
5787 + {"AINB", NULL, "INPUTS"},
5788 +};
5789 +
5790 +static struct snd_soc_card snd_soc_audioinjector_isolated = {
5791 + .name = "audioinjector-isolated-soundcard",
5792 + .dai_link = audioinjector_isolated_dai,
5793 + .num_links = ARRAY_SIZE(audioinjector_isolated_dai),
5794 +
5795 + .dapm_widgets = audioinjector_isolated_widgets,
5796 + .num_dapm_widgets = ARRAY_SIZE(audioinjector_isolated_widgets),
5797 + .dapm_routes = audioinjector_isolated_route,
5798 + .num_dapm_routes = ARRAY_SIZE(audioinjector_isolated_route),
5799 +};
5800 +
5801 +static int audioinjector_isolated_probe(struct platform_device *pdev)
5802 +{
5803 + struct snd_soc_card *card = &snd_soc_audioinjector_isolated;
5804 + int ret;
5805 +
5806 + card->dev = &pdev->dev;
5807 +
5808 + if (pdev->dev.of_node) {
5809 + struct snd_soc_dai_link *dai = &audioinjector_isolated_dai[0];
5810 + struct device_node *i2s_node =
5811 + of_parse_phandle(pdev->dev.of_node, "i2s-controller", 0);
5812 +
5813 + if (i2s_node) {
5814 + dai->cpus->dai_name = NULL;
5815 + dai->cpus->of_node = i2s_node;
5816 + dai->platforms->name = NULL;
5817 + dai->platforms->of_node = i2s_node;
5818 + } else {
5819 + dev_err(&pdev->dev,
5820 + "i2s-controller missing or invalid in DT\n");
5821 + return -EINVAL;
5822 + }
5823 +
5824 + mute_gpio = devm_gpiod_get_optional(&pdev->dev, "mute", GPIOD_OUT_LOW);
5825 + if (IS_ERR(mute_gpio)){
5826 + dev_err(&pdev->dev, "mute gpio not found in dt overlay\n");
5827 + return PTR_ERR(mute_gpio);
5828 + }
5829 + }
5830 +
5831 + ret = devm_snd_soc_register_card(&pdev->dev, card);
5832 + if (ret && ret != -EPROBE_DEFER)
5833 + dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret);
5834 + return ret;
5835 +}
5836 +
5837 +static const struct of_device_id audioinjector_isolated_of_match[] = {
5838 + { .compatible = "ai,audioinjector-isolated-soundcard", },
5839 + {},
5840 +};
5841 +MODULE_DEVICE_TABLE(of, audioinjector_isolated_of_match);
5842 +
5843 +static struct platform_driver audioinjector_isolated_driver = {
5844 + .driver = {
5845 + .name = "audioinjector-isolated",
5846 + .owner = THIS_MODULE,
5847 + .of_match_table = audioinjector_isolated_of_match,
5848 + },
5849 + .probe = audioinjector_isolated_probe,
5850 +};
5851 +
5852 +module_platform_driver(audioinjector_isolated_driver);
5853 +MODULE_AUTHOR("Matt Flax <flatmax@flatmax.org>");
5854 +MODULE_DESCRIPTION("AudioInjector.net isolated Soundcard");
5855 +MODULE_LICENSE("GPL v2");
5856 +MODULE_ALIAS("platform:audioinjector-isolated-soundcard");
5857 --- /dev/null
5858 +++ b/sound/soc/bcm/audioinjector-octo-soundcard.c
5859 @@ -0,0 +1,346 @@
5860 +/*
5861 + * ASoC Driver for AudioInjector Pi octo channel soundcard (hat)
5862 + *
5863 + * Created on: 27-October-2016
5864 + * Author: flatmax@flatmax.org
5865 + * based on audioinjector-pi-soundcard.c
5866 + *
5867 + * Copyright (C) 2016 Flatmax Pty. Ltd.
5868 + *
5869 + * This program is free software; you can redistribute it and/or
5870 + * modify it under the terms of the GNU General Public License
5871 + * version 2 as published by the Free Software Foundation.
5872 + *
5873 + * This program is distributed in the hope that it will be useful, but
5874 + * WITHOUT ANY WARRANTY; without even the implied warranty of
5875 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5876 + * General Public License for more details.
5877 + */
5878 +
5879 +#include <linux/module.h>
5880 +#include <linux/types.h>
5881 +#include <linux/gpio/consumer.h>
5882 +
5883 +#include <sound/core.h>
5884 +#include <sound/soc.h>
5885 +#include <sound/pcm_params.h>
5886 +#include <sound/control.h>
5887 +
5888 +static struct gpio_descs *mult_gpios;
5889 +static struct gpio_desc *codec_rst_gpio;
5890 +static unsigned int audioinjector_octo_rate;
5891 +static bool non_stop_clocks;
5892 +
5893 +static const unsigned int audioinjector_octo_rates[] = {
5894 + 96000, 48000, 32000, 24000, 16000, 8000, 88200, 44100, 29400, 22050, 14700,
5895 +};
5896 +
5897 +static struct snd_pcm_hw_constraint_list audioinjector_octo_constraints = {
5898 + .list = audioinjector_octo_rates,
5899 + .count = ARRAY_SIZE(audioinjector_octo_rates),
5900 +};
5901 +
5902 +static int audioinjector_octo_dai_init(struct snd_soc_pcm_runtime *rtd)
5903 +{
5904 + return snd_soc_dai_set_bclk_ratio(asoc_rtd_to_cpu(rtd, 0), 64);
5905 +}
5906 +
5907 +static int audioinjector_octo_startup(struct snd_pcm_substream *substream)
5908 +{
5909 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
5910 + asoc_rtd_to_cpu(rtd, 0)->driver->playback.channels_min = 8;
5911 + asoc_rtd_to_cpu(rtd, 0)->driver->playback.channels_max = 8;
5912 + asoc_rtd_to_cpu(rtd, 0)->driver->capture.channels_min = 8;
5913 + asoc_rtd_to_cpu(rtd, 0)->driver->capture.channels_max = 8;
5914 + asoc_rtd_to_codec(rtd, 0)->driver->capture.channels_max = 8;
5915 +
5916 + snd_pcm_hw_constraint_list(substream->runtime, 0,
5917 + SNDRV_PCM_HW_PARAM_RATE,
5918 + &audioinjector_octo_constraints);
5919 +
5920 + return 0;
5921 +}
5922 +
5923 +static void audioinjector_octo_shutdown(struct snd_pcm_substream *substream)
5924 +{
5925 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
5926 + asoc_rtd_to_cpu(rtd, 0)->driver->playback.channels_min = 2;
5927 + asoc_rtd_to_cpu(rtd, 0)->driver->playback.channels_max = 2;
5928 + asoc_rtd_to_cpu(rtd, 0)->driver->capture.channels_min = 2;
5929 + asoc_rtd_to_cpu(rtd, 0)->driver->capture.channels_max = 2;
5930 + asoc_rtd_to_codec(rtd, 0)->driver->capture.channels_max = 6;
5931 +}
5932 +
5933 +static int audioinjector_octo_hw_params(struct snd_pcm_substream *substream,
5934 + struct snd_pcm_hw_params *params)
5935 +{
5936 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
5937 +
5938 + // set codec DAI configuration
5939 + int ret = snd_soc_dai_set_fmt(asoc_rtd_to_codec(rtd, 0),
5940 + SND_SOC_DAIFMT_CBS_CFS|SND_SOC_DAIFMT_DSP_A|
5941 + SND_SOC_DAIFMT_NB_NF);
5942 + if (ret < 0)
5943 + return ret;
5944 +
5945 + // set cpu DAI configuration
5946 + ret = snd_soc_dai_set_fmt(asoc_rtd_to_cpu(rtd, 0),
5947 + SND_SOC_DAIFMT_CBM_CFM|SND_SOC_DAIFMT_I2S|
5948 + SND_SOC_DAIFMT_NB_NF);
5949 + if (ret < 0)
5950 + return ret;
5951 +
5952 + audioinjector_octo_rate = params_rate(params);
5953 +
5954 + // Set the correct sysclock for the codec
5955 + switch (audioinjector_octo_rate) {
5956 + case 96000:
5957 + case 48000:
5958 + return snd_soc_dai_set_sysclk(asoc_rtd_to_codec(rtd, 0), 0, 49152000,
5959 + 0);
5960 + break;
5961 + case 24000:
5962 + return snd_soc_dai_set_sysclk(asoc_rtd_to_codec(rtd, 0), 0, 49152000/2,
5963 + 0);
5964 + break;
5965 + case 32000:
5966 + case 16000:
5967 + return snd_soc_dai_set_sysclk(asoc_rtd_to_codec(rtd, 0), 0, 49152000/3,
5968 + 0);
5969 + break;
5970 + case 8000:
5971 + return snd_soc_dai_set_sysclk(asoc_rtd_to_codec(rtd, 0), 0, 49152000/6,
5972 + 0);
5973 + break;
5974 + case 88200:
5975 + case 44100:
5976 + return snd_soc_dai_set_sysclk(asoc_rtd_to_codec(rtd, 0), 0, 45185400,
5977 + 0);
5978 + break;
5979 + case 22050:
5980 + return snd_soc_dai_set_sysclk(asoc_rtd_to_codec(rtd, 0), 0, 45185400/2,
5981 + 0);
5982 + break;
5983 + case 29400:
5984 + case 14700:
5985 + return snd_soc_dai_set_sysclk(asoc_rtd_to_codec(rtd, 0), 0, 45185400/3,
5986 + 0);
5987 + break;
5988 + default:
5989 + return -EINVAL;
5990 + }
5991 +}
5992 +
5993 +static int audioinjector_octo_trigger(struct snd_pcm_substream *substream,
5994 + int cmd){
5995 + DECLARE_BITMAP(mult, 4);
5996 +
5997 + memset(mult, 0, sizeof(mult));
5998 +
5999 + switch (cmd) {
6000 + case SNDRV_PCM_TRIGGER_STOP:
6001 + case SNDRV_PCM_TRIGGER_SUSPEND:
6002 + case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
6003 + if (!non_stop_clocks)
6004 + break;
6005 + /* fall through */
6006 + case SNDRV_PCM_TRIGGER_START:
6007 + case SNDRV_PCM_TRIGGER_RESUME:
6008 + case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
6009 + switch (audioinjector_octo_rate) {
6010 + case 96000:
6011 + __assign_bit(3, mult, 1);
6012 + /* fall through */
6013 + case 88200:
6014 + __assign_bit(1, mult, 1);
6015 + __assign_bit(2, mult, 1);
6016 + break;
6017 + case 48000:
6018 + __assign_bit(3, mult, 1);
6019 + /* fall through */
6020 + case 44100:
6021 + __assign_bit(2, mult, 1);
6022 + break;
6023 + case 32000:
6024 + __assign_bit(3, mult, 1);
6025 + /* fall through */
6026 + case 29400:
6027 + __assign_bit(0, mult, 1);
6028 + __assign_bit(1, mult, 1);
6029 + break;
6030 + case 24000:
6031 + __assign_bit(3, mult, 1);
6032 + /* fall through */
6033 + case 22050:
6034 + __assign_bit(1, mult, 1);
6035 + break;
6036 + case 16000:
6037 + __assign_bit(3, mult, 1);
6038 + /* fall through */
6039 + case 14700:
6040 + __assign_bit(0, mult, 1);
6041 + break;
6042 + case 8000:
6043 + __assign_bit(3, mult, 1);
6044 + break;
6045 + default:
6046 + return -EINVAL;
6047 + }
6048 + break;
6049 + default:
6050 + return -EINVAL;
6051 + }
6052 + gpiod_set_array_value_cansleep(mult_gpios->ndescs, mult_gpios->desc,
6053 + NULL, mult);
6054 +
6055 + return 0;
6056 +}
6057 +
6058 +static struct snd_soc_ops audioinjector_octo_ops = {
6059 + .startup = audioinjector_octo_startup,
6060 + .shutdown = audioinjector_octo_shutdown,
6061 + .hw_params = audioinjector_octo_hw_params,
6062 + .trigger = audioinjector_octo_trigger,
6063 +};
6064 +
6065 +SND_SOC_DAILINK_DEFS(audioinjector_octo,
6066 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
6067 + DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "cs42448")),
6068 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
6069 +
6070 +static struct snd_soc_dai_link audioinjector_octo_dai[] = {
6071 + {
6072 + .name = "AudioInjector Octo",
6073 + .stream_name = "AudioInject-HIFI",
6074 + .ops = &audioinjector_octo_ops,
6075 + .init = audioinjector_octo_dai_init,
6076 + .symmetric_rate = 1,
6077 + .symmetric_channels = 1,
6078 + SND_SOC_DAILINK_REG(audioinjector_octo),
6079 + },
6080 +};
6081 +
6082 +static const struct snd_soc_dapm_widget audioinjector_octo_widgets[] = {
6083 + SND_SOC_DAPM_OUTPUT("OUTPUTS0"),
6084 + SND_SOC_DAPM_OUTPUT("OUTPUTS1"),
6085 + SND_SOC_DAPM_OUTPUT("OUTPUTS2"),
6086 + SND_SOC_DAPM_OUTPUT("OUTPUTS3"),
6087 + SND_SOC_DAPM_INPUT("INPUTS0"),
6088 + SND_SOC_DAPM_INPUT("INPUTS1"),
6089 + SND_SOC_DAPM_INPUT("INPUTS2"),
6090 +};
6091 +
6092 +static const struct snd_soc_dapm_route audioinjector_octo_route[] = {
6093 + /* Balanced outputs */
6094 + {"OUTPUTS0", NULL, "AOUT1L"},
6095 + {"OUTPUTS0", NULL, "AOUT1R"},
6096 + {"OUTPUTS1", NULL, "AOUT2L"},
6097 + {"OUTPUTS1", NULL, "AOUT2R"},
6098 + {"OUTPUTS2", NULL, "AOUT3L"},
6099 + {"OUTPUTS2", NULL, "AOUT3R"},
6100 + {"OUTPUTS3", NULL, "AOUT4L"},
6101 + {"OUTPUTS3", NULL, "AOUT4R"},
6102 +
6103 + /* Balanced inputs */
6104 + {"AIN1L", NULL, "INPUTS0"},
6105 + {"AIN1R", NULL, "INPUTS0"},
6106 + {"AIN2L", NULL, "INPUTS1"},
6107 + {"AIN2R", NULL, "INPUTS1"},
6108 + {"AIN3L", NULL, "INPUTS2"},
6109 + {"AIN3R", NULL, "INPUTS2"},
6110 +};
6111 +
6112 +static struct snd_soc_card snd_soc_audioinjector_octo = {
6113 + .name = "audioinjector-octo-soundcard",
6114 + .dai_link = audioinjector_octo_dai,
6115 + .num_links = ARRAY_SIZE(audioinjector_octo_dai),
6116 +
6117 + .dapm_widgets = audioinjector_octo_widgets,
6118 + .num_dapm_widgets = ARRAY_SIZE(audioinjector_octo_widgets),
6119 + .dapm_routes = audioinjector_octo_route,
6120 + .num_dapm_routes = ARRAY_SIZE(audioinjector_octo_route),
6121 +};
6122 +
6123 +static int audioinjector_octo_probe(struct platform_device *pdev)
6124 +{
6125 + struct snd_soc_card *card = &snd_soc_audioinjector_octo;
6126 + int ret;
6127 +
6128 + card->dev = &pdev->dev;
6129 +
6130 + if (pdev->dev.of_node) {
6131 + struct snd_soc_dai_link *dai = &audioinjector_octo_dai[0];
6132 + struct device_node *i2s_node =
6133 + of_parse_phandle(pdev->dev.of_node,
6134 + "i2s-controller", 0);
6135 + struct device_node *codec_node =
6136 + of_parse_phandle(pdev->dev.of_node,
6137 + "codec", 0);
6138 +
6139 + mult_gpios = devm_gpiod_get_array_optional(&pdev->dev, "mult",
6140 + GPIOD_OUT_LOW);
6141 + if (IS_ERR(mult_gpios))
6142 + return PTR_ERR(mult_gpios);
6143 +
6144 + codec_rst_gpio = devm_gpiod_get_optional(&pdev->dev, "reset",
6145 + GPIOD_OUT_LOW);
6146 + if (IS_ERR(codec_rst_gpio))
6147 + return PTR_ERR(codec_rst_gpio);
6148 +
6149 + non_stop_clocks = of_property_read_bool(pdev->dev.of_node, "non-stop-clocks");
6150 +
6151 + if (codec_rst_gpio)
6152 + gpiod_set_value(codec_rst_gpio, 1);
6153 + msleep(500);
6154 + if (codec_rst_gpio)
6155 + gpiod_set_value(codec_rst_gpio, 0);
6156 + msleep(500);
6157 + if (codec_rst_gpio)
6158 + gpiod_set_value(codec_rst_gpio, 1);
6159 + msleep(500);
6160 +
6161 + if (i2s_node && codec_node) {
6162 + dai->cpus->dai_name = NULL;
6163 + dai->cpus->of_node = i2s_node;
6164 + dai->platforms->name = NULL;
6165 + dai->platforms->of_node = i2s_node;
6166 + dai->codecs->name = NULL;
6167 + dai->codecs->of_node = codec_node;
6168 + } else
6169 + if (!i2s_node) {
6170 + dev_err(&pdev->dev,
6171 + "i2s-controller missing or invalid in DT\n");
6172 + return -EINVAL;
6173 + } else {
6174 + dev_err(&pdev->dev,
6175 + "Property 'codec' missing or invalid\n");
6176 + return -EINVAL;
6177 + }
6178 + }
6179 +
6180 + ret = devm_snd_soc_register_card(&pdev->dev, card);
6181 + if (ret != 0)
6182 + dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret);
6183 + return ret;
6184 +}
6185 +
6186 +static const struct of_device_id audioinjector_octo_of_match[] = {
6187 + { .compatible = "ai,audioinjector-octo-soundcard", },
6188 + {},
6189 +};
6190 +MODULE_DEVICE_TABLE(of, audioinjector_octo_of_match);
6191 +
6192 +static struct platform_driver audioinjector_octo_driver = {
6193 + .driver = {
6194 + .name = "audioinjector-octo",
6195 + .owner = THIS_MODULE,
6196 + .of_match_table = audioinjector_octo_of_match,
6197 + },
6198 + .probe = audioinjector_octo_probe,
6199 +};
6200 +
6201 +module_platform_driver(audioinjector_octo_driver);
6202 +MODULE_AUTHOR("Matt Flax <flatmax@flatmax.org>");
6203 +MODULE_DESCRIPTION("AudioInjector.net octo Soundcard");
6204 +MODULE_LICENSE("GPL v2");
6205 +MODULE_ALIAS("platform:audioinjector-octo-soundcard");
6206 --- /dev/null
6207 +++ b/sound/soc/bcm/audioinjector-pi-soundcard.c
6208 @@ -0,0 +1,187 @@
6209 +/*
6210 + * ASoC Driver for AudioInjector Pi add on soundcard
6211 + *
6212 + * Created on: 13-May-2016
6213 + * Author: flatmax@flatmax.org
6214 + * based on code by Cliff Cai <Cliff.Cai@analog.com> for the ssm2602 machine blackfin.
6215 + * with help from Lars-Peter Clausen for simplifying the original code to use the dai_fmt field.
6216 + * i2s_node code taken from the other sound/soc/bcm machine drivers.
6217 + *
6218 + * Copyright (C) 2016 Flatmax Pty. Ltd.
6219 + *
6220 + * This program is free software; you can redistribute it and/or
6221 + * modify it under the terms of the GNU General Public License
6222 + * version 2 as published by the Free Software Foundation.
6223 + *
6224 + * This program is distributed in the hope that it will be useful, but
6225 + * WITHOUT ANY WARRANTY; without even the implied warranty of
6226 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6227 + * General Public License for more details.
6228 + */
6229 +
6230 +#include <linux/module.h>
6231 +#include <linux/types.h>
6232 +
6233 +#include <sound/core.h>
6234 +#include <sound/soc.h>
6235 +#include <sound/pcm_params.h>
6236 +#include <sound/control.h>
6237 +
6238 +#include "../codecs/wm8731.h"
6239 +
6240 +static const unsigned int bcm2835_rates_12000000[] = {
6241 + 8000, 16000, 32000, 44100, 48000, 96000, 88200,
6242 +};
6243 +
6244 +static struct snd_pcm_hw_constraint_list bcm2835_constraints_12000000 = {
6245 + .list = bcm2835_rates_12000000,
6246 + .count = ARRAY_SIZE(bcm2835_rates_12000000),
6247 +};
6248 +
6249 +static int snd_audioinjector_pi_soundcard_startup(struct snd_pcm_substream *substream)
6250 +{
6251 + /* Setup constraints, because there is a 12 MHz XTAL on the board */
6252 + snd_pcm_hw_constraint_list(substream->runtime, 0,
6253 + SNDRV_PCM_HW_PARAM_RATE,
6254 + &bcm2835_constraints_12000000);
6255 + return 0;
6256 +}
6257 +
6258 +static int snd_audioinjector_pi_soundcard_hw_params(struct snd_pcm_substream *substream,
6259 + struct snd_pcm_hw_params *params)
6260 +{
6261 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
6262 + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
6263 +
6264 + switch (params_rate(params)){
6265 + case 8000:
6266 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 1);
6267 + case 16000:
6268 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 750);
6269 + case 32000:
6270 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 375);
6271 + case 44100:
6272 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 272);
6273 + case 48000:
6274 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 250);
6275 + case 88200:
6276 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 136);
6277 + case 96000:
6278 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 125);
6279 + default:
6280 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 125);
6281 + }
6282 +}
6283 +
6284 +/* machine stream operations */
6285 +static struct snd_soc_ops snd_audioinjector_pi_soundcard_ops = {
6286 + .startup = snd_audioinjector_pi_soundcard_startup,
6287 + .hw_params = snd_audioinjector_pi_soundcard_hw_params,
6288 +};
6289 +
6290 +static int audioinjector_pi_soundcard_dai_init(struct snd_soc_pcm_runtime *rtd)
6291 +{
6292 + return snd_soc_dai_set_sysclk(asoc_rtd_to_codec(rtd, 0), WM8731_SYSCLK_XTAL, 12000000, SND_SOC_CLOCK_IN);
6293 +}
6294 +
6295 +SND_SOC_DAILINK_DEFS(audioinjector_pi,
6296 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
6297 + DAILINK_COMP_ARRAY(COMP_CODEC("wm8731.1-001a", "wm8731-hifi")),
6298 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2835-i2s.0")));
6299 +
6300 +static struct snd_soc_dai_link audioinjector_pi_soundcard_dai[] = {
6301 + {
6302 + .name = "AudioInjector audio",
6303 + .stream_name = "AudioInjector audio",
6304 + .ops = &snd_audioinjector_pi_soundcard_ops,
6305 + .init = audioinjector_pi_soundcard_dai_init,
6306 + .dai_fmt = SND_SOC_DAIFMT_CBM_CFM|SND_SOC_DAIFMT_I2S|SND_SOC_DAIFMT_NB_NF,
6307 + SND_SOC_DAILINK_REG(audioinjector_pi),
6308 + },
6309 +};
6310 +
6311 +static const struct snd_soc_dapm_widget wm8731_dapm_widgets[] = {
6312 + SND_SOC_DAPM_HP("Headphone Jack", NULL),
6313 + SND_SOC_DAPM_SPK("Ext Spk", NULL),
6314 + SND_SOC_DAPM_LINE("Line In Jacks", NULL),
6315 + SND_SOC_DAPM_MIC("Microphone", NULL),
6316 +};
6317 +
6318 +static const struct snd_soc_dapm_route audioinjector_audio_map[] = {
6319 + /* headphone connected to LHPOUT, RHPOUT */
6320 + {"Headphone Jack", NULL, "LHPOUT"},
6321 + {"Headphone Jack", NULL, "RHPOUT"},
6322 +
6323 + /* speaker connected to LOUT, ROUT */
6324 + {"Ext Spk", NULL, "ROUT"},
6325 + {"Ext Spk", NULL, "LOUT"},
6326 +
6327 + /* line inputs */
6328 + {"Line In Jacks", NULL, "Line Input"},
6329 +
6330 + /* mic is connected to Mic Jack, with WM8731 Mic Bias */
6331 + {"Microphone", NULL, "Mic Bias"},
6332 +};
6333 +
6334 +static struct snd_soc_card snd_soc_audioinjector = {
6335 + .name = "audioinjector-pi-soundcard",
6336 + .dai_link = audioinjector_pi_soundcard_dai,
6337 + .num_links = ARRAY_SIZE(audioinjector_pi_soundcard_dai),
6338 +
6339 + .dapm_widgets = wm8731_dapm_widgets,
6340 + .num_dapm_widgets = ARRAY_SIZE(wm8731_dapm_widgets),
6341 + .dapm_routes = audioinjector_audio_map,
6342 + .num_dapm_routes = ARRAY_SIZE(audioinjector_audio_map),
6343 +};
6344 +
6345 +static int audioinjector_pi_soundcard_probe(struct platform_device *pdev)
6346 +{
6347 + struct snd_soc_card *card = &snd_soc_audioinjector;
6348 + int ret;
6349 +
6350 + card->dev = &pdev->dev;
6351 +
6352 + if (pdev->dev.of_node) {
6353 + struct snd_soc_dai_link *dai = &audioinjector_pi_soundcard_dai[0];
6354 + struct device_node *i2s_node = of_parse_phandle(pdev->dev.of_node,
6355 + "i2s-controller", 0);
6356 +
6357 + if (i2s_node) {
6358 + dai->cpus->dai_name = NULL;
6359 + dai->cpus->of_node = i2s_node;
6360 + dai->platforms->name = NULL;
6361 + dai->platforms->of_node = i2s_node;
6362 + } else
6363 + if (!dai->cpus->of_node) {
6364 + dev_err(&pdev->dev, "Property 'i2s-controller' missing or invalid\n");
6365 + return -EINVAL;
6366 + }
6367 + }
6368 +
6369 + if ((ret = devm_snd_soc_register_card(&pdev->dev, card))) {
6370 + dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret);
6371 + }
6372 + return ret;
6373 +}
6374 +
6375 +static const struct of_device_id audioinjector_pi_soundcard_of_match[] = {
6376 + { .compatible = "ai,audioinjector-pi-soundcard", },
6377 + {},
6378 +};
6379 +MODULE_DEVICE_TABLE(of, audioinjector_pi_soundcard_of_match);
6380 +
6381 +static struct platform_driver audioinjector_pi_soundcard_driver = {
6382 + .driver = {
6383 + .name = "audioinjector-stereo",
6384 + .owner = THIS_MODULE,
6385 + .of_match_table = audioinjector_pi_soundcard_of_match,
6386 + },
6387 + .probe = audioinjector_pi_soundcard_probe,
6388 +};
6389 +
6390 +module_platform_driver(audioinjector_pi_soundcard_driver);
6391 +MODULE_AUTHOR("Matt Flax <flatmax@flatmax.org>");
6392 +MODULE_DESCRIPTION("AudioInjector.net Pi Soundcard");
6393 +MODULE_LICENSE("GPL v2");
6394 +MODULE_ALIAS("platform:audioinjector-pi-soundcard");
6395 +
6396 --- /dev/null
6397 +++ b/sound/soc/bcm/audiosense-pi.c
6398 @@ -0,0 +1,248 @@
6399 +/*
6400 + * ASoC Driver for AudioSense add on soundcard
6401 + * Author:
6402 + * Bhargav A K <anur.bhargav@gmail.com>
6403 + * Copyright 2017
6404 + *
6405 + * This program is free software; you can redistribute it and/or
6406 + * modify it under the terms of the GNU General Public License
6407 + * version 2 as published by the Free Software Foundation.
6408 + *
6409 + * This program is distributed in the hope that it will be useful, but
6410 + * WITHOUT ANY WARRANTY; without even the implied warranty of
6411 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6412 + * General Public License for more details.
6413 + */
6414 +
6415 +#include <linux/module.h>
6416 +#include <linux/platform_device.h>
6417 +#include <linux/clk.h>
6418 +#include <linux/i2c.h>
6419 +#include <sound/core.h>
6420 +#include <sound/pcm.h>
6421 +#include <sound/pcm_params.h>
6422 +#include <sound/soc.h>
6423 +#include <sound/jack.h>
6424 +#include <sound/control.h>
6425 +
6426 +#include <sound/tlv320aic32x4.h>
6427 +#include "../codecs/tlv320aic32x4.h"
6428 +
6429 +#define AIC32X4_SYSCLK_XTAL 0x00
6430 +
6431 +/*
6432 + * Setup Codec Sample Rates and Channels
6433 + * Supported Rates:
6434 + * 8000, 11025, 16000, 22050, 32000, 44100, 48000, 64000, 88200, 96000,
6435 + */
6436 +static const unsigned int audiosense_pi_rate[] = {
6437 + 48000,
6438 +};
6439 +
6440 +static struct snd_pcm_hw_constraint_list audiosense_constraints_rates = {
6441 + .list = audiosense_pi_rate,
6442 + .count = ARRAY_SIZE(audiosense_pi_rate),
6443 +};
6444 +
6445 +static const unsigned int audiosense_pi_channels[] = {
6446 + 2,
6447 +};
6448 +
6449 +static struct snd_pcm_hw_constraint_list audiosense_constraints_ch = {
6450 + .count = ARRAY_SIZE(audiosense_pi_channels),
6451 + .list = audiosense_pi_channels,
6452 + .mask = 0,
6453 +};
6454 +
6455 +/* Setup DAPM widgets and paths */
6456 +static const struct snd_soc_dapm_widget audiosense_pi_dapm_widgets[] = {
6457 + SND_SOC_DAPM_HP("Headphone Jack", NULL),
6458 + SND_SOC_DAPM_LINE("Line Out", NULL),
6459 + SND_SOC_DAPM_LINE("Line In", NULL),
6460 + SND_SOC_DAPM_INPUT("CM_L"),
6461 + SND_SOC_DAPM_INPUT("CM_R"),
6462 +};
6463 +
6464 +static const struct snd_soc_dapm_route audiosense_pi_audio_map[] = {
6465 + /* Line Inputs are connected to
6466 + * (IN1_L | IN1_R)
6467 + * (IN2_L | IN2_R)
6468 + * (IN3_L | IN3_R)
6469 + */
6470 + {"IN1_L", NULL, "Line In"},
6471 + {"IN1_R", NULL, "Line In"},
6472 + {"IN2_L", NULL, "Line In"},
6473 + {"IN2_R", NULL, "Line In"},
6474 + {"IN3_L", NULL, "Line In"},
6475 + {"IN3_R", NULL, "Line In"},
6476 +
6477 + /* Mic is connected to IN2_L and IN2_R */
6478 + {"Left ADC", NULL, "Mic Bias"},
6479 + {"Right ADC", NULL, "Mic Bias"},
6480 +
6481 + /* Headphone connected to HPL, HPR */
6482 + {"Headphone Jack", NULL, "HPL"},
6483 + {"Headphone Jack", NULL, "HPR"},
6484 +
6485 + /* Speakers connected to LOL and LOR */
6486 + {"Line Out", NULL, "LOL"},
6487 + {"Line Out", NULL, "LOR"},
6488 +};
6489 +
6490 +static int audiosense_pi_card_init(struct snd_soc_pcm_runtime *rtd)
6491 +{
6492 + /* TODO: init of the codec specific dapm data, ignore suspend/resume */
6493 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
6494 +
6495 + snd_soc_component_update_bits(component, AIC32X4_MICBIAS, 0x78,
6496 + AIC32X4_MICBIAS_LDOIN |
6497 + AIC32X4_MICBIAS_2075V);
6498 + snd_soc_component_update_bits(component, AIC32X4_PWRCFG, 0x08,
6499 + AIC32X4_AVDDWEAKDISABLE);
6500 + snd_soc_component_update_bits(component, AIC32X4_LDOCTL, 0x01,
6501 + AIC32X4_LDOCTLEN);
6502 +
6503 + return 0;
6504 +}
6505 +
6506 +static int audiosense_pi_card_hw_params(
6507 + struct snd_pcm_substream *substream,
6508 + struct snd_pcm_hw_params *params)
6509 +{
6510 + int ret = 0;
6511 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
6512 + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
6513 +
6514 + /* Set the codec system clock, there is a 12 MHz XTAL on the board */
6515 + ret = snd_soc_dai_set_sysclk(codec_dai, AIC32X4_SYSCLK_XTAL,
6516 + 12000000, SND_SOC_CLOCK_IN);
6517 + if (ret) {
6518 + dev_err(rtd->card->dev,
6519 + "could not set codec driver clock params\n");
6520 + return ret;
6521 + }
6522 + return 0;
6523 +}
6524 +
6525 +static int audiosense_pi_card_startup(struct snd_pcm_substream *substream)
6526 +{
6527 + struct snd_pcm_runtime *runtime = substream->runtime;
6528 +
6529 + /*
6530 + * Set codec to 48Khz Sampling, Stereo I/O and 16 bit audio
6531 + */
6532 + runtime->hw.channels_max = 2;
6533 + snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
6534 + &audiosense_constraints_ch);
6535 +
6536 + runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE;
6537 + snd_pcm_hw_constraint_msbits(runtime, 0, 16, 16);
6538 +
6539 +
6540 + snd_pcm_hw_constraint_list(substream->runtime, 0,
6541 + SNDRV_PCM_HW_PARAM_RATE,
6542 + &audiosense_constraints_rates);
6543 + return 0;
6544 +}
6545 +
6546 +static struct snd_soc_ops audiosense_pi_card_ops = {
6547 + .startup = audiosense_pi_card_startup,
6548 + .hw_params = audiosense_pi_card_hw_params,
6549 +};
6550 +
6551 +SND_SOC_DAILINK_DEFS(audiosense_pi,
6552 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
6553 + DAILINK_COMP_ARRAY(COMP_CODEC("tlv320aic32x4.1-0018", "tlv320aic32x4-hifi")),
6554 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
6555 +
6556 +static struct snd_soc_dai_link audiosense_pi_card_dai[] = {
6557 + {
6558 + .name = "TLV320AIC3204 Audio",
6559 + .stream_name = "TLV320AIC3204 Hifi Audio",
6560 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
6561 + SND_SOC_DAIFMT_CBM_CFM,
6562 + .ops = &audiosense_pi_card_ops,
6563 + .init = audiosense_pi_card_init,
6564 + SND_SOC_DAILINK_REG(audiosense_pi),
6565 + },
6566 +};
6567 +
6568 +static struct snd_soc_card audiosense_pi_card = {
6569 + .name = "audiosense-pi",
6570 + .driver_name = "audiosense-pi",
6571 + .dai_link = audiosense_pi_card_dai,
6572 + .owner = THIS_MODULE,
6573 + .num_links = ARRAY_SIZE(audiosense_pi_card_dai),
6574 + .dapm_widgets = audiosense_pi_dapm_widgets,
6575 + .num_dapm_widgets = ARRAY_SIZE(audiosense_pi_dapm_widgets),
6576 + .dapm_routes = audiosense_pi_audio_map,
6577 + .num_dapm_routes = ARRAY_SIZE(audiosense_pi_audio_map),
6578 +};
6579 +
6580 +static int audiosense_pi_card_probe(struct platform_device *pdev)
6581 +{
6582 + int ret = 0;
6583 + struct snd_soc_card *card = &audiosense_pi_card;
6584 + struct snd_soc_dai_link *dai = &audiosense_pi_card_dai[0];
6585 + struct device_node *i2s_node = pdev->dev.of_node;
6586 +
6587 + card->dev = &pdev->dev;
6588 +
6589 + if (!dai) {
6590 + dev_err(&pdev->dev, "DAI not found. Missing or Invalid\n");
6591 + return -EINVAL;
6592 + }
6593 +
6594 + i2s_node = of_parse_phandle(pdev->dev.of_node, "i2s-controller", 0);
6595 + if (!i2s_node) {
6596 + dev_err(&pdev->dev,
6597 + "Property 'i2s-controller' missing or invalid\n");
6598 + return -EINVAL;
6599 + }
6600 +
6601 + dai->cpus->dai_name = NULL;
6602 + dai->cpus->of_node = i2s_node;
6603 + dai->platforms->name = NULL;
6604 + dai->platforms->of_node = i2s_node;
6605 +
6606 + of_node_put(i2s_node);
6607 +
6608 + ret = snd_soc_register_card(card);
6609 + if (ret && ret != -EPROBE_DEFER)
6610 + dev_err(&pdev->dev,
6611 + "snd_soc_register_card() failed: %d\n", ret);
6612 +
6613 + return ret;
6614 +}
6615 +
6616 +static int audiosense_pi_card_remove(struct platform_device *pdev)
6617 +{
6618 + struct snd_soc_card *card = platform_get_drvdata(pdev);
6619 +
6620 + return snd_soc_unregister_card(card);
6621 +
6622 +}
6623 +
6624 +static const struct of_device_id audiosense_pi_card_of_match[] = {
6625 + { .compatible = "as,audiosense-pi", },
6626 + {},
6627 +};
6628 +MODULE_DEVICE_TABLE(of, audiosense_pi_card_of_match);
6629 +
6630 +static struct platform_driver audiosense_pi_card_driver = {
6631 + .driver = {
6632 + .name = "audiosense-snd-card",
6633 + .owner = THIS_MODULE,
6634 + .of_match_table = audiosense_pi_card_of_match,
6635 + },
6636 + .probe = audiosense_pi_card_probe,
6637 + .remove = audiosense_pi_card_remove,
6638 +};
6639 +
6640 +module_platform_driver(audiosense_pi_card_driver);
6641 +
6642 +MODULE_AUTHOR("Bhargav AK <anur.bhargav@gmail.com>");
6643 +MODULE_DESCRIPTION("ASoC Driver for TLV320AIC3204 Audio");
6644 +MODULE_LICENSE("GPL v2");
6645 +MODULE_ALIAS("platform:audiosense-pi");
6646 +
6647 --- /dev/null
6648 +++ b/sound/soc/bcm/digidac1-soundcard.c
6649 @@ -0,0 +1,421 @@
6650 +/*
6651 + * ASoC Driver for RRA DigiDAC1
6652 + * Copyright 2016
6653 + * Author: José M. Tasende <vintage@redrocksaudio.es>
6654 + * based on the HifiBerry DAC driver by Florian Meier <florian.meier@koalo.de>
6655 + * and the Wolfson card driver by Nikesh Oswal, <Nikesh.Oswal@wolfsonmicro.com>
6656 + * This program is free software; you can redistribute it and/or
6657 + * modify it under the terms of the GNU General Public License
6658 + * version 2 as published by the Free Software Foundation.
6659 + *
6660 + * This program is distributed in the hope that it will be useful, but
6661 + * WITHOUT ANY WARRANTY; without even the implied warranty of
6662 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6663 + * General Public License for more details.
6664 + */
6665 +
6666 +#include <linux/module.h>
6667 +#include <linux/platform_device.h>
6668 +#include <linux/i2c.h>
6669 +#include <sound/core.h>
6670 +#include <sound/pcm.h>
6671 +#include <sound/pcm_params.h>
6672 +#include <sound/soc.h>
6673 +#include <sound/jack.h>
6674 +#include <sound/soc-dapm.h>
6675 +#include <sound/tlv.h>
6676 +#include <linux/regulator/consumer.h>
6677 +
6678 +#include "../codecs/wm8804.h"
6679 +#include "../codecs/wm8741.h"
6680 +
6681 +#define WM8741_NUM_SUPPLIES 2
6682 +
6683 +/* codec private data */
6684 +struct wm8741_priv {
6685 + struct wm8741_platform_data pdata;
6686 + struct regmap *regmap;
6687 + struct regulator_bulk_data supplies[WM8741_NUM_SUPPLIES];
6688 + unsigned int sysclk;
6689 + const struct snd_pcm_hw_constraint_list *sysclk_constraints;
6690 +};
6691 +
6692 +static int samplerate = 44100;
6693 +
6694 +/* New Alsa Controls not exposed by original wm8741 codec driver */
6695 +/* in actual driver the att. adjustment is wrong because */
6696 +/* this DAC has a coarse attenuation register with 4dB steps */
6697 +/* and a fine level register with 0.125dB steps */
6698 +/* each register has 32 steps so combining both we have 1024 steps */
6699 +/* of 0.125 dB. */
6700 +/* The original level controls from driver are removed at startup */
6701 +/* and replaced by the corrected ones. */
6702 +/* The same wm8741 driver can be used for wm8741 and wm8742 devices */
6703 +
6704 +static const DECLARE_TLV_DB_SCALE(dac_tlv_fine, 0, 13, 0);
6705 +static const DECLARE_TLV_DB_SCALE(dac_tlv_coarse, -12700, 400, 1);
6706 +static const char *w8741_dither[4] = {"Off", "RPDF", "TPDF", "HPDF"};
6707 +static const char *w8741_filter[5] = {
6708 + "Type 1", "Type 2", "Type 3", "Type 4", "Type 5"};
6709 +static const char *w8741_switch[2] = {"Off", "On"};
6710 +static const struct soc_enum w8741_enum[] = {
6711 +SOC_ENUM_SINGLE(WM8741_MODE_CONTROL_2, 0, 4, w8741_dither),/* dithering type */
6712 +SOC_ENUM_SINGLE(WM8741_FILTER_CONTROL, 0, 5, w8741_filter),/* filter type */
6713 +SOC_ENUM_SINGLE(WM8741_FORMAT_CONTROL, 6, 2, w8741_switch),/* phase invert */
6714 +SOC_ENUM_SINGLE(WM8741_VOLUME_CONTROL, 0, 2, w8741_switch),/* volume ramp */
6715 +SOC_ENUM_SINGLE(WM8741_VOLUME_CONTROL, 3, 2, w8741_switch),/* soft mute */
6716 +};
6717 +
6718 +static const struct snd_kcontrol_new w8741_snd_controls_stereo[] = {
6719 +SOC_DOUBLE_R_TLV("DAC Fine Playback Volume", WM8741_DACLLSB_ATTENUATION,
6720 + WM8741_DACRLSB_ATTENUATION, 0, 31, 1, dac_tlv_fine),
6721 +SOC_DOUBLE_R_TLV("Digital Playback Volume", WM8741_DACLMSB_ATTENUATION,
6722 + WM8741_DACRMSB_ATTENUATION, 0, 31, 1, dac_tlv_coarse),
6723 +SOC_ENUM("DAC Dither", w8741_enum[0]),
6724 +SOC_ENUM("DAC Digital Filter", w8741_enum[1]),
6725 +SOC_ENUM("DAC Phase Invert", w8741_enum[2]),
6726 +SOC_ENUM("DAC Volume Ramp", w8741_enum[3]),
6727 +SOC_ENUM("DAC Soft Mute", w8741_enum[4]),
6728 +};
6729 +
6730 +static const struct snd_kcontrol_new w8741_snd_controls_mono_left[] = {
6731 +SOC_SINGLE_TLV("DAC Fine Playback Volume", WM8741_DACLLSB_ATTENUATION,
6732 + 0, 31, 0, dac_tlv_fine),
6733 +SOC_SINGLE_TLV("Digital Playback Volume", WM8741_DACLMSB_ATTENUATION,
6734 + 0, 31, 1, dac_tlv_coarse),
6735 +SOC_ENUM("DAC Dither", w8741_enum[0]),
6736 +SOC_ENUM("DAC Digital Filter", w8741_enum[1]),
6737 +SOC_ENUM("DAC Phase Invert", w8741_enum[2]),
6738 +SOC_ENUM("DAC Volume Ramp", w8741_enum[3]),
6739 +SOC_ENUM("DAC Soft Mute", w8741_enum[4]),
6740 +};
6741 +
6742 +static const struct snd_kcontrol_new w8741_snd_controls_mono_right[] = {
6743 +SOC_SINGLE_TLV("DAC Fine Playback Volume", WM8741_DACRLSB_ATTENUATION,
6744 + 0, 31, 0, dac_tlv_fine),
6745 +SOC_SINGLE_TLV("Digital Playback Volume", WM8741_DACRMSB_ATTENUATION,
6746 + 0, 31, 1, dac_tlv_coarse),
6747 +SOC_ENUM("DAC Dither", w8741_enum[0]),
6748 +SOC_ENUM("DAC Digital Filter", w8741_enum[1]),
6749 +SOC_ENUM("DAC Phase Invert", w8741_enum[2]),
6750 +SOC_ENUM("DAC Volume Ramp", w8741_enum[3]),
6751 +SOC_ENUM("DAC Soft Mute", w8741_enum[4]),
6752 +};
6753 +
6754 +static int w8741_add_controls(struct snd_soc_component *component)
6755 +{
6756 + struct wm8741_priv *wm8741 = snd_soc_component_get_drvdata(component);
6757 +
6758 + switch (wm8741->pdata.diff_mode) {
6759 + case WM8741_DIFF_MODE_STEREO:
6760 + case WM8741_DIFF_MODE_STEREO_REVERSED:
6761 + snd_soc_add_component_controls(component,
6762 + w8741_snd_controls_stereo,
6763 + ARRAY_SIZE(w8741_snd_controls_stereo));
6764 + break;
6765 + case WM8741_DIFF_MODE_MONO_LEFT:
6766 + snd_soc_add_component_controls(component,
6767 + w8741_snd_controls_mono_left,
6768 + ARRAY_SIZE(w8741_snd_controls_mono_left));
6769 + break;
6770 + case WM8741_DIFF_MODE_MONO_RIGHT:
6771 + snd_soc_add_component_controls(component,
6772 + w8741_snd_controls_mono_right,
6773 + ARRAY_SIZE(w8741_snd_controls_mono_right));
6774 + break;
6775 + default:
6776 + return -EINVAL;
6777 + }
6778 +
6779 + return 0;
6780 +}
6781 +
6782 +static int digidac1_soundcard_init(struct snd_soc_pcm_runtime *rtd)
6783 +{
6784 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
6785 + struct snd_soc_card *card = rtd->card;
6786 + struct snd_soc_pcm_runtime *wm8741_rtd;
6787 + struct snd_soc_component *wm8741_component;
6788 + struct snd_card *sound_card = card->snd_card;
6789 + struct snd_kcontrol *kctl;
6790 + int ret;
6791 +
6792 + wm8741_rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[1]);
6793 + if (!wm8741_rtd) {
6794 + dev_warn(card->dev, "digidac1_soundcard_init: couldn't get wm8741 rtd\n");
6795 + return -EFAULT;
6796 + }
6797 + wm8741_component = asoc_rtd_to_codec(wm8741_rtd, 0)->component;
6798 + ret = w8741_add_controls(wm8741_component);
6799 + if (ret < 0)
6800 + dev_warn(card->dev, "Failed to add new wm8741 controls: %d\n",
6801 + ret);
6802 +
6803 + /* enable TX output */
6804 + snd_soc_component_update_bits(component, WM8804_PWRDN, 0x4, 0x0);
6805 +
6806 + kctl = snd_soc_card_get_kcontrol(card,
6807 + "Playback Volume");
6808 + if (kctl) {
6809 + kctl->vd[0].access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
6810 + snd_ctl_remove(sound_card, kctl);
6811 + }
6812 + kctl = snd_soc_card_get_kcontrol(card,
6813 + "Fine Playback Volume");
6814 + if (kctl) {
6815 + kctl->vd[0].access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
6816 + snd_ctl_remove(sound_card, kctl);
6817 + }
6818 + return 0;
6819 +}
6820 +
6821 +static int digidac1_soundcard_startup(struct snd_pcm_substream *substream)
6822 +{
6823 + /* turn on wm8804 digital output */
6824 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
6825 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
6826 + struct snd_soc_card *card = rtd->card;
6827 + struct snd_soc_pcm_runtime *wm8741_rtd;
6828 + struct snd_soc_component *wm8741_component;
6829 +
6830 + snd_soc_component_update_bits(component, WM8804_PWRDN, 0x3c, 0x00);
6831 + wm8741_rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[1]);
6832 + if (!wm8741_rtd) {
6833 + dev_warn(card->dev, "digidac1_soundcard_startup: couldn't get WM8741 rtd\n");
6834 + return -EFAULT;
6835 + }
6836 + wm8741_component = asoc_rtd_to_codec(wm8741_rtd, 0)->component;
6837 +
6838 + /* latch wm8741 level */
6839 + snd_soc_component_update_bits(wm8741_component, WM8741_DACLLSB_ATTENUATION,
6840 + WM8741_UPDATELL, WM8741_UPDATELL);
6841 + snd_soc_component_update_bits(wm8741_component, WM8741_DACLMSB_ATTENUATION,
6842 + WM8741_UPDATELM, WM8741_UPDATELM);
6843 + snd_soc_component_update_bits(wm8741_component, WM8741_DACRLSB_ATTENUATION,
6844 + WM8741_UPDATERL, WM8741_UPDATERL);
6845 + snd_soc_component_update_bits(wm8741_component, WM8741_DACRMSB_ATTENUATION,
6846 + WM8741_UPDATERM, WM8741_UPDATERM);
6847 +
6848 + return 0;
6849 +}
6850 +
6851 +static void digidac1_soundcard_shutdown(struct snd_pcm_substream *substream)
6852 +{
6853 + /* turn off wm8804 digital output */
6854 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
6855 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
6856 +
6857 + snd_soc_component_update_bits(component, WM8804_PWRDN, 0x3c, 0x3c);
6858 +}
6859 +
6860 +static int digidac1_soundcard_hw_params(struct snd_pcm_substream *substream,
6861 + struct snd_pcm_hw_params *params)
6862 +{
6863 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
6864 + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
6865 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
6866 + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
6867 + struct snd_soc_card *card = rtd->card;
6868 + struct snd_soc_pcm_runtime *wm8741_rtd;
6869 + struct snd_soc_component *wm8741_component;
6870 +
6871 + int sysclk = 27000000;
6872 + long mclk_freq = 0;
6873 + int mclk_div = 1;
6874 + int sampling_freq = 1;
6875 + int ret;
6876 +
6877 + wm8741_rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[1]);
6878 + if (!wm8741_rtd) {
6879 + dev_warn(card->dev, "digidac1_soundcard_hw_params: couldn't get WM8741 rtd\n");
6880 + return -EFAULT;
6881 + }
6882 + wm8741_component = asoc_rtd_to_codec(wm8741_rtd, 0)->component;
6883 + samplerate = params_rate(params);
6884 +
6885 + if (samplerate <= 96000) {
6886 + mclk_freq = samplerate*256;
6887 + mclk_div = WM8804_MCLKDIV_256FS;
6888 + } else {
6889 + mclk_freq = samplerate*128;
6890 + mclk_div = WM8804_MCLKDIV_128FS;
6891 + }
6892 +
6893 + switch (samplerate) {
6894 + case 32000:
6895 + sampling_freq = 0x03;
6896 + break;
6897 + case 44100:
6898 + sampling_freq = 0x00;
6899 + break;
6900 + case 48000:
6901 + sampling_freq = 0x02;
6902 + break;
6903 + case 88200:
6904 + sampling_freq = 0x08;
6905 + break;
6906 + case 96000:
6907 + sampling_freq = 0x0a;
6908 + break;
6909 + case 176400:
6910 + sampling_freq = 0x0c;
6911 + break;
6912 + case 192000:
6913 + sampling_freq = 0x0e;
6914 + break;
6915 + default:
6916 + dev_err(card->dev,
6917 + "Failed to set WM8804 SYSCLK, unsupported samplerate %d\n",
6918 + samplerate);
6919 + }
6920 +
6921 + snd_soc_dai_set_clkdiv(codec_dai, WM8804_MCLK_DIV, mclk_div);
6922 + snd_soc_dai_set_pll(codec_dai, 0, 0, sysclk, mclk_freq);
6923 +
6924 + ret = snd_soc_dai_set_sysclk(codec_dai, WM8804_TX_CLKSRC_PLL,
6925 + sysclk, SND_SOC_CLOCK_OUT);
6926 + if (ret < 0) {
6927 + dev_err(card->dev,
6928 + "Failed to set WM8804 SYSCLK: %d\n", ret);
6929 + return ret;
6930 + }
6931 + /* Enable wm8804 TX output */
6932 + snd_soc_component_update_bits(component, WM8804_PWRDN, 0x4, 0x0);
6933 +
6934 + /* wm8804 Power on */
6935 + snd_soc_component_update_bits(component, WM8804_PWRDN, 0x9, 0);
6936 +
6937 + /* wm8804 set sampling frequency status bits */
6938 + snd_soc_component_update_bits(component, WM8804_SPDTX4, 0x0f, sampling_freq);
6939 +
6940 + /* Now update wm8741 registers for the correct oversampling */
6941 + if (samplerate <= 48000)
6942 + snd_soc_component_update_bits(wm8741_component, WM8741_MODE_CONTROL_1,
6943 + WM8741_OSR_MASK, 0x00);
6944 + else if (samplerate <= 96000)
6945 + snd_soc_component_update_bits(wm8741_component, WM8741_MODE_CONTROL_1,
6946 + WM8741_OSR_MASK, 0x20);
6947 + else
6948 + snd_soc_component_update_bits(wm8741_component, WM8741_MODE_CONTROL_1,
6949 + WM8741_OSR_MASK, 0x40);
6950 +
6951 + /* wm8741 bit size */
6952 + switch (params_width(params)) {
6953 + case 16:
6954 + snd_soc_component_update_bits(wm8741_component, WM8741_FORMAT_CONTROL,
6955 + WM8741_IWL_MASK, 0x00);
6956 + break;
6957 + case 20:
6958 + snd_soc_component_update_bits(wm8741_component, WM8741_FORMAT_CONTROL,
6959 + WM8741_IWL_MASK, 0x01);
6960 + break;
6961 + case 24:
6962 + snd_soc_component_update_bits(wm8741_component, WM8741_FORMAT_CONTROL,
6963 + WM8741_IWL_MASK, 0x02);
6964 + break;
6965 + case 32:
6966 + snd_soc_component_update_bits(wm8741_component, WM8741_FORMAT_CONTROL,
6967 + WM8741_IWL_MASK, 0x03);
6968 + break;
6969 + default:
6970 + dev_dbg(card->dev, "wm8741_hw_params: Unsupported bit size param = %d",
6971 + params_width(params));
6972 + return -EINVAL;
6973 + }
6974 +
6975 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 64);
6976 +}
6977 +/* machine stream operations */
6978 +static struct snd_soc_ops digidac1_soundcard_ops = {
6979 + .hw_params = digidac1_soundcard_hw_params,
6980 + .startup = digidac1_soundcard_startup,
6981 + .shutdown = digidac1_soundcard_shutdown,
6982 +};
6983 +
6984 +SND_SOC_DAILINK_DEFS(digidac1,
6985 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
6986 + DAILINK_COMP_ARRAY(COMP_CODEC("wm8804.1-003b", "wm8804-spdif")),
6987 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2835-i2s.0")));
6988 +
6989 +SND_SOC_DAILINK_DEFS(digidac11,
6990 + DAILINK_COMP_ARRAY(COMP_CPU("wm8804-spdif")),
6991 + DAILINK_COMP_ARRAY(COMP_CODEC("wm8741.1-001a", "wm8741")),
6992 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
6993 +
6994 +static struct snd_soc_dai_link digidac1_soundcard_dai[] = {
6995 + {
6996 + .name = "RRA DigiDAC1",
6997 + .stream_name = "RRA DigiDAC1 HiFi",
6998 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
6999 + SND_SOC_DAIFMT_CBM_CFM,
7000 + .ops = &digidac1_soundcard_ops,
7001 + .init = digidac1_soundcard_init,
7002 + SND_SOC_DAILINK_REG(digidac1),
7003 + },
7004 + {
7005 + .name = "RRA DigiDAC11",
7006 + .stream_name = "RRA DigiDAC11 HiFi",
7007 + .dai_fmt = SND_SOC_DAIFMT_I2S
7008 + | SND_SOC_DAIFMT_NB_NF
7009 + | SND_SOC_DAIFMT_CBS_CFS,
7010 + SND_SOC_DAILINK_REG(digidac11),
7011 + },
7012 +};
7013 +
7014 +/* audio machine driver */
7015 +static struct snd_soc_card digidac1_soundcard = {
7016 + .name = "digidac1-soundcard",
7017 + .owner = THIS_MODULE,
7018 + .dai_link = digidac1_soundcard_dai,
7019 + .num_links = ARRAY_SIZE(digidac1_soundcard_dai),
7020 +};
7021 +
7022 +static int digidac1_soundcard_probe(struct platform_device *pdev)
7023 +{
7024 + int ret = 0;
7025 +
7026 + digidac1_soundcard.dev = &pdev->dev;
7027 +
7028 + if (pdev->dev.of_node) {
7029 + struct device_node *i2s_node;
7030 + struct snd_soc_dai_link *dai = &digidac1_soundcard_dai[0];
7031 +
7032 + i2s_node = of_parse_phandle(pdev->dev.of_node,
7033 + "i2s-controller", 0);
7034 +
7035 + if (i2s_node) {
7036 + dai->cpus->dai_name = NULL;
7037 + dai->cpus->of_node = i2s_node;
7038 + dai->platforms->name = NULL;
7039 + dai->platforms->of_node = i2s_node;
7040 + }
7041 + }
7042 +
7043 + ret = devm_snd_soc_register_card(&pdev->dev, &digidac1_soundcard);
7044 + if (ret && ret != -EPROBE_DEFER)
7045 + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
7046 + ret);
7047 +
7048 + return ret;
7049 +}
7050 +
7051 +static const struct of_device_id digidac1_soundcard_of_match[] = {
7052 + { .compatible = "rra,digidac1-soundcard", },
7053 + {},
7054 +};
7055 +MODULE_DEVICE_TABLE(of, digidac1_soundcard_of_match);
7056 +
7057 +static struct platform_driver digidac1_soundcard_driver = {
7058 + .driver = {
7059 + .name = "digidac1-audio",
7060 + .owner = THIS_MODULE,
7061 + .of_match_table = digidac1_soundcard_of_match,
7062 + },
7063 + .probe = digidac1_soundcard_probe,
7064 +};
7065 +
7066 +module_platform_driver(digidac1_soundcard_driver);
7067 +
7068 +MODULE_AUTHOR("José M. Tasende <vintage@redrocksaudio.es>");
7069 +MODULE_DESCRIPTION("ASoC Driver for RRA DigiDAC1");
7070 +MODULE_LICENSE("GPL v2");
7071 --- /dev/null
7072 +++ b/sound/soc/bcm/dionaudio_loco-v2.c
7073 @@ -0,0 +1,117 @@
7074 +/*
7075 + * ASoC Driver for Dion Audio LOCO-V2 DAC-AMP
7076 + *
7077 + * Author: Miquel Blauw <info@dionaudio.nl>
7078 + * Copyright 2017
7079 + *
7080 + * Based on the software of the RPi-DAC writen by Florian Meier
7081 + *
7082 + * This program is free software; you can redistribute it and/or
7083 + * modify it under the terms of the GNU General Public License
7084 + * version 2 as published by the Free Software Foundation.
7085 + *
7086 + * This program is distributed in the hope that it will be useful, but
7087 + * WITHOUT ANY WARRANTY; without even the implied warranty of
7088 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7089 + * General Public License for more details.
7090 + */
7091 +
7092 +#include <linux/module.h>
7093 +#include <linux/platform_device.h>
7094 +
7095 +#include <sound/core.h>
7096 +#include <sound/pcm.h>
7097 +#include <sound/pcm_params.h>
7098 +#include <sound/soc.h>
7099 +#include <sound/jack.h>
7100 +
7101 +static bool digital_gain_0db_limit = true;
7102 +
7103 +static int snd_rpi_dionaudio_loco_v2_init(struct snd_soc_pcm_runtime *rtd)
7104 +{
7105 + if (digital_gain_0db_limit) {
7106 + int ret;
7107 + struct snd_soc_card *card = rtd->card;
7108 +
7109 + ret = snd_soc_limit_volume(card, "Digital Playback Volume", 207);
7110 + if (ret < 0)
7111 + dev_warn(card->dev, "Failed to set volume limit: %d\n", ret);
7112 + }
7113 +
7114 + return 0;
7115 +}
7116 +
7117 +SND_SOC_DAILINK_DEFS(dionaudio_loco_v2,
7118 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
7119 + DAILINK_COMP_ARRAY(COMP_CODEC("pcm512x.1-004d", "pcm512x-hifi")),
7120 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
7121 +
7122 +static struct snd_soc_dai_link snd_rpi_dionaudio_loco_v2_dai[] = {
7123 +{
7124 + .name = "DionAudio LOCO-V2",
7125 + .stream_name = "DionAudio LOCO-V2 DAC-AMP",
7126 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
7127 + SND_SOC_DAIFMT_CBS_CFS,
7128 + .init = snd_rpi_dionaudio_loco_v2_init,
7129 + SND_SOC_DAILINK_REG(dionaudio_loco_v2),
7130 +},};
7131 +
7132 +/* audio machine driver */
7133 +static struct snd_soc_card snd_rpi_dionaudio_loco_v2 = {
7134 + .name = "Dion Audio LOCO-V2",
7135 + .dai_link = snd_rpi_dionaudio_loco_v2_dai,
7136 + .num_links = ARRAY_SIZE(snd_rpi_dionaudio_loco_v2_dai),
7137 +};
7138 +
7139 +static int snd_rpi_dionaudio_loco_v2_probe(struct platform_device *pdev)
7140 +{
7141 + int ret = 0;
7142 +
7143 + snd_rpi_dionaudio_loco_v2.dev = &pdev->dev;
7144 +
7145 + if (pdev->dev.of_node) {
7146 + struct device_node *i2s_node;
7147 + struct snd_soc_dai_link *dai =
7148 + &snd_rpi_dionaudio_loco_v2_dai[0];
7149 +
7150 + i2s_node = of_parse_phandle(pdev->dev.of_node,
7151 + "i2s-controller", 0);
7152 + if (i2s_node) {
7153 + dai->cpus->dai_name = NULL;
7154 + dai->cpus->of_node = i2s_node;
7155 + dai->platforms->name = NULL;
7156 + dai->platforms->of_node = i2s_node;
7157 + }
7158 +
7159 + digital_gain_0db_limit = !of_property_read_bool(
7160 + pdev->dev.of_node, "dionaudio,24db_digital_gain");
7161 + }
7162 +
7163 + ret = devm_snd_soc_register_card(&pdev->dev, &snd_rpi_dionaudio_loco_v2);
7164 + if (ret)
7165 + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
7166 + ret);
7167 +
7168 + return ret;
7169 +}
7170 +
7171 +static const struct of_device_id dionaudio_of_match[] = {
7172 + { .compatible = "dionaudio,dionaudio-loco-v2", },
7173 + {},
7174 +};
7175 +MODULE_DEVICE_TABLE(of, dionaudio_of_match);
7176 +
7177 +static struct platform_driver snd_rpi_dionaudio_loco_v2_driver = {
7178 + .driver = {
7179 + .name = "snd-rpi-dionaudio-loco-v2",
7180 + .owner = THIS_MODULE,
7181 + .of_match_table = dionaudio_of_match,
7182 + },
7183 + .probe = snd_rpi_dionaudio_loco_v2_probe,
7184 +};
7185 +
7186 +module_platform_driver(snd_rpi_dionaudio_loco_v2_driver);
7187 +
7188 +MODULE_AUTHOR("Miquel Blauw <info@dionaudio.nl>");
7189 +MODULE_DESCRIPTION("ASoC Driver for DionAudio LOCO-V2");
7190 +MODULE_LICENSE("GPL v2");
7191 --- /dev/null
7192 +++ b/sound/soc/bcm/dionaudio_loco.c
7193 @@ -0,0 +1,117 @@
7194 +/*
7195 + * ASoC Driver for Dion Audio LOCO DAC-AMP
7196 + *
7197 + * Author: Miquel Blauw <info@dionaudio.nl>
7198 + * Copyright 2016
7199 + *
7200 + * Based on the software of the RPi-DAC writen by Florian Meier
7201 + *
7202 + * This program is free software; you can redistribute it and/or
7203 + * modify it under the terms of the GNU General Public License
7204 + * version 2 as published by the Free Software Foundation.
7205 + *
7206 + * This program is distributed in the hope that it will be useful, but
7207 + * WITHOUT ANY WARRANTY; without even the implied warranty of
7208 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7209 + * General Public License for more details.
7210 + */
7211 +
7212 +#include <linux/module.h>
7213 +#include <linux/platform_device.h>
7214 +
7215 +#include <sound/core.h>
7216 +#include <sound/pcm.h>
7217 +#include <sound/pcm_params.h>
7218 +#include <sound/soc.h>
7219 +#include <sound/jack.h>
7220 +
7221 +static int snd_rpi_dionaudio_loco_hw_params(
7222 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
7223 +{
7224 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
7225 + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
7226 +
7227 + unsigned int sample_bits =
7228 + snd_pcm_format_physical_width(params_format(params));
7229 +
7230 + return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);
7231 +}
7232 +
7233 +/* machine stream operations */
7234 +static struct snd_soc_ops snd_rpi_dionaudio_loco_ops = {
7235 + .hw_params = snd_rpi_dionaudio_loco_hw_params,
7236 +};
7237 +
7238 +SND_SOC_DAILINK_DEFS(dionaudio_loco,
7239 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
7240 + DAILINK_COMP_ARRAY(COMP_CODEC("pcm5102a-codec", "pcm5102a-hifi")),
7241 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
7242 +
7243 +static struct snd_soc_dai_link snd_rpi_dionaudio_loco_dai[] = {
7244 +{
7245 + .name = "DionAudio LOCO",
7246 + .stream_name = "DionAudio LOCO DAC-AMP",
7247 + .dai_fmt = SND_SOC_DAIFMT_I2S |
7248 + SND_SOC_DAIFMT_NB_NF |
7249 + SND_SOC_DAIFMT_CBS_CFS,
7250 + .ops = &snd_rpi_dionaudio_loco_ops,
7251 + SND_SOC_DAILINK_REG(dionaudio_loco),
7252 +},
7253 +};
7254 +
7255 +/* audio machine driver */
7256 +static struct snd_soc_card snd_rpi_dionaudio_loco = {
7257 + .name = "snd_rpi_dionaudio_loco",
7258 + .dai_link = snd_rpi_dionaudio_loco_dai,
7259 + .num_links = ARRAY_SIZE(snd_rpi_dionaudio_loco_dai),
7260 +};
7261 +
7262 +static int snd_rpi_dionaudio_loco_probe(struct platform_device *pdev)
7263 +{
7264 + struct device_node *np;
7265 + int ret = 0;
7266 +
7267 + snd_rpi_dionaudio_loco.dev = &pdev->dev;
7268 +
7269 + np = pdev->dev.of_node;
7270 + if (np) {
7271 + struct snd_soc_dai_link *dai = &snd_rpi_dionaudio_loco_dai[0];
7272 + struct device_node *i2s_np;
7273 +
7274 + i2s_np = of_parse_phandle(np, "i2s-controller", 0);
7275 + if (i2s_np) {
7276 + dai->cpus->dai_name = NULL;
7277 + dai->cpus->of_node = i2s_np;
7278 + dai->platforms->name = NULL;
7279 + dai->platforms->of_node = i2s_np;
7280 + }
7281 + }
7282 +
7283 + ret = devm_snd_soc_register_card(&pdev->dev, &snd_rpi_dionaudio_loco);
7284 + if (ret && ret != -EPROBE_DEFER)
7285 + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
7286 + ret);
7287 +
7288 + return ret;
7289 +}
7290 +
7291 +static const struct of_device_id snd_rpi_dionaudio_loco_of_match[] = {
7292 + { .compatible = "dionaudio,loco-pcm5242-tpa3118", },
7293 + { /* sentinel */ },
7294 +};
7295 +MODULE_DEVICE_TABLE(of, snd_rpi_dionaudio_loco_of_match);
7296 +
7297 +static struct platform_driver snd_rpi_dionaudio_loco_driver = {
7298 + .driver = {
7299 + .name = "snd-dionaudio-loco",
7300 + .owner = THIS_MODULE,
7301 + .of_match_table = snd_rpi_dionaudio_loco_of_match,
7302 + },
7303 + .probe = snd_rpi_dionaudio_loco_probe,
7304 +};
7305 +
7306 +module_platform_driver(snd_rpi_dionaudio_loco_driver);
7307 +
7308 +MODULE_AUTHOR("Miquel Blauw <info@dionaudio.nl>");
7309 +MODULE_DESCRIPTION("ASoC Driver for DionAudio LOCO");
7310 +MODULE_LICENSE("GPL v2");
7311 --- /dev/null
7312 +++ b/sound/soc/bcm/fe-pi-audio.c
7313 @@ -0,0 +1,154 @@
7314 +/*
7315 + * ASoC Driver for Fe-Pi Audio Sound Card
7316 + *
7317 + * Author: Henry Kupis <kuupaz@gmail.com>
7318 + * Copyright 2016
7319 + * based on code by Florian Meier <florian.meier@koalo.de>
7320 + * based on code by Shawn Guo <shawn.guo@linaro.org>
7321 + *
7322 + * This program is free software; you can redistribute it and/or
7323 + * modify it under the terms of the GNU General Public License
7324 + * version 2 as published by the Free Software Foundation.
7325 + *
7326 + * This program is distributed in the hope that it will be useful, but
7327 + * WITHOUT ANY WARRANTY; without even the implied warranty of
7328 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7329 + * General Public License for more details.
7330 + */
7331 +
7332 +#include <linux/module.h>
7333 +#include <linux/platform_device.h>
7334 +#include <linux/io.h>
7335 +
7336 +#include <sound/core.h>
7337 +#include <sound/pcm.h>
7338 +#include <sound/pcm_params.h>
7339 +#include <sound/soc.h>
7340 +#include <sound/jack.h>
7341 +
7342 +#include "../codecs/sgtl5000.h"
7343 +
7344 +static int snd_fe_pi_audio_init(struct snd_soc_pcm_runtime *rtd)
7345 +{
7346 + struct snd_soc_card *card = rtd->card;
7347 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
7348 +
7349 + snd_soc_dapm_force_enable_pin(&card->dapm, "LO");
7350 + snd_soc_dapm_force_enable_pin(&card->dapm, "ADC");
7351 + snd_soc_dapm_force_enable_pin(&card->dapm, "DAC");
7352 + snd_soc_dapm_force_enable_pin(&card->dapm, "HP");
7353 + snd_soc_component_update_bits(component, SGTL5000_CHIP_ANA_POWER,
7354 + SGTL5000_VAG_POWERUP, SGTL5000_VAG_POWERUP);
7355 +
7356 + return 0;
7357 +}
7358 +
7359 +static int snd_fe_pi_audio_hw_params(struct snd_pcm_substream *substream,
7360 + struct snd_pcm_hw_params *params)
7361 +{
7362 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
7363 + struct device *dev = rtd->card->dev;
7364 + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
7365 +
7366 + int ret;
7367 +
7368 + /* Set SGTL5000's SYSCLK */
7369 + ret = snd_soc_dai_set_sysclk(codec_dai, SGTL5000_SYSCLK, 12288000, SND_SOC_CLOCK_IN);
7370 + if (ret) {
7371 + dev_err(dev, "could not set codec driver clock params\n");
7372 + return ret;
7373 + }
7374 +
7375 + return 0;
7376 +}
7377 +
7378 +
7379 +static struct snd_soc_ops snd_fe_pi_audio_ops = {
7380 + .hw_params = snd_fe_pi_audio_hw_params,
7381 +};
7382 +
7383 +SND_SOC_DAILINK_DEFS(fe_pi,
7384 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
7385 + DAILINK_COMP_ARRAY(COMP_CODEC("sgtl5000.1-000a", "sgtl5000")),
7386 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
7387 +
7388 +static struct snd_soc_dai_link snd_fe_pi_audio_dai[] = {
7389 + {
7390 + .name = "FE-PI",
7391 + .stream_name = "Fe-Pi HiFi",
7392 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
7393 + SND_SOC_DAIFMT_CBM_CFM,
7394 + .ops = &snd_fe_pi_audio_ops,
7395 + .init = snd_fe_pi_audio_init,
7396 + SND_SOC_DAILINK_REG(fe_pi),
7397 + },
7398 +};
7399 +
7400 +static const struct snd_soc_dapm_route fe_pi_audio_dapm_routes[] = {
7401 + {"ADC", NULL, "Mic Bias"},
7402 +};
7403 +
7404 +
7405 +static struct snd_soc_card fe_pi_audio = {
7406 + .name = "Fe-Pi Audio",
7407 + .owner = THIS_MODULE,
7408 + .dai_link = snd_fe_pi_audio_dai,
7409 + .num_links = ARRAY_SIZE(snd_fe_pi_audio_dai),
7410 +
7411 + .dapm_routes = fe_pi_audio_dapm_routes,
7412 + .num_dapm_routes = ARRAY_SIZE(fe_pi_audio_dapm_routes),
7413 +};
7414 +
7415 +static int snd_fe_pi_audio_probe(struct platform_device *pdev)
7416 +{
7417 + int ret = 0;
7418 + struct snd_soc_card *card = &fe_pi_audio;
7419 + struct device_node *np = pdev->dev.of_node;
7420 + struct device_node *i2s_node;
7421 + struct snd_soc_dai_link *dai = &snd_fe_pi_audio_dai[0];
7422 +
7423 + fe_pi_audio.dev = &pdev->dev;
7424 +
7425 + i2s_node = of_parse_phandle(np, "i2s-controller", 0);
7426 + if (!i2s_node) {
7427 + dev_err(&pdev->dev, "i2s_node phandle missing or invalid\n");
7428 + return -EINVAL;
7429 + }
7430 +
7431 + dai->cpus->dai_name = NULL;
7432 + dai->cpus->of_node = i2s_node;
7433 + dai->platforms->name = NULL;
7434 + dai->platforms->of_node = i2s_node;
7435 +
7436 + of_node_put(i2s_node);
7437 +
7438 + card->dev = &pdev->dev;
7439 + platform_set_drvdata(pdev, card);
7440 +
7441 + ret = devm_snd_soc_register_card(&pdev->dev, card);
7442 + if (ret && ret != -EPROBE_DEFER)
7443 + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
7444 +
7445 + return ret;
7446 +}
7447 +
7448 +static const struct of_device_id snd_fe_pi_audio_of_match[] = {
7449 + { .compatible = "fe-pi,fe-pi-audio", },
7450 + {},
7451 +};
7452 +MODULE_DEVICE_TABLE(of, snd_fe_pi_audio_of_match);
7453 +
7454 +static struct platform_driver snd_fe_pi_audio_driver = {
7455 + .driver = {
7456 + .name = "snd-fe-pi-audio",
7457 + .owner = THIS_MODULE,
7458 + .of_match_table = snd_fe_pi_audio_of_match,
7459 + },
7460 + .probe = snd_fe_pi_audio_probe,
7461 +};
7462 +
7463 +module_platform_driver(snd_fe_pi_audio_driver);
7464 +
7465 +MODULE_AUTHOR("Henry Kupis <fe-pi@cox.net>");
7466 +MODULE_DESCRIPTION("ASoC Driver for Fe-Pi Audio");
7467 +MODULE_LICENSE("GPL v2");
7468 --- /dev/null
7469 +++ b/sound/soc/bcm/googlevoicehat-codec.c
7470 @@ -0,0 +1,214 @@
7471 +/*
7472 + * Driver for the Google voiceHAT audio codec for Raspberry Pi.
7473 + *
7474 + * Author: Peter Malkin <petermalkin@google.com>
7475 + * Copyright 2016
7476 + *
7477 + * This program is free software; you can redistribute it and/or
7478 + * modify it under the terms of the GNU General Public License
7479 + * version 2 as published by the Free Software Foundation.
7480 + *
7481 + * This program is distributed in the hope that it will be useful, but
7482 + * WITHOUT ANY WARRANTY; without even the implied warranty of
7483 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7484 + * General Public License for more details.
7485 + */
7486 +
7487 +#include <linux/device.h>
7488 +#include <linux/err.h>
7489 +#include <linux/gpio.h>
7490 +#include <linux/gpio/consumer.h>
7491 +#include <linux/init.h>
7492 +#include <linux/kernel.h>
7493 +#include <linux/mod_devicetable.h>
7494 +#include <linux/module.h>
7495 +#include <linux/of.h>
7496 +#include <linux/platform_device.h>
7497 +#include <linux/version.h>
7498 +#include <sound/pcm.h>
7499 +#include <sound/soc.h>
7500 +#include <sound/soc-dai.h>
7501 +#include <sound/soc-dapm.h>
7502 +
7503 +#define ICS43432_RATE_MIN_HZ 7190 /* from data sheet */
7504 +#define ICS43432_RATE_MAX_HZ 52800 /* from data sheet */
7505 +/* Delay in enabling SDMODE after clock settles to remove pop */
7506 +#define SDMODE_DELAY_MS 5
7507 +
7508 +struct voicehat_priv {
7509 + struct delayed_work enable_sdmode_work;
7510 + struct gpio_desc *sdmode_gpio;
7511 + unsigned long sdmode_delay_jiffies;
7512 +};
7513 +
7514 +static void voicehat_enable_sdmode_work(struct work_struct *work)
7515 +{
7516 + struct voicehat_priv *voicehat = container_of(work,
7517 + struct voicehat_priv,
7518 + enable_sdmode_work.work);
7519 + gpiod_set_value(voicehat->sdmode_gpio, 1);
7520 +}
7521 +
7522 +static int voicehat_component_probe(struct snd_soc_component *component)
7523 +{
7524 + struct voicehat_priv *voicehat =
7525 + snd_soc_component_get_drvdata(component);
7526 +
7527 + voicehat->sdmode_gpio = devm_gpiod_get(component->dev, "sdmode",
7528 + GPIOD_OUT_LOW);
7529 + if (IS_ERR(voicehat->sdmode_gpio)) {
7530 + dev_err(component->dev, "Unable to allocate GPIO pin\n");
7531 + return PTR_ERR(voicehat->sdmode_gpio);
7532 + }
7533 +
7534 + INIT_DELAYED_WORK(&voicehat->enable_sdmode_work,
7535 + voicehat_enable_sdmode_work);
7536 + return 0;
7537 +}
7538 +
7539 +static void voicehat_component_remove(struct snd_soc_component *component)
7540 +{
7541 + struct voicehat_priv *voicehat =
7542 + snd_soc_component_get_drvdata(component);
7543 +
7544 + cancel_delayed_work_sync(&voicehat->enable_sdmode_work);
7545 +}
7546 +
7547 +static const struct snd_soc_dapm_widget voicehat_dapm_widgets[] = {
7548 + SND_SOC_DAPM_OUTPUT("Speaker"),
7549 +};
7550 +
7551 +static const struct snd_soc_dapm_route voicehat_dapm_routes[] = {
7552 + {"Speaker", NULL, "HiFi Playback"},
7553 +};
7554 +
7555 +static const struct snd_soc_component_driver voicehat_component_driver = {
7556 + .probe = voicehat_component_probe,
7557 + .remove = voicehat_component_remove,
7558 + .dapm_widgets = voicehat_dapm_widgets,
7559 + .num_dapm_widgets = ARRAY_SIZE(voicehat_dapm_widgets),
7560 + .dapm_routes = voicehat_dapm_routes,
7561 + .num_dapm_routes = ARRAY_SIZE(voicehat_dapm_routes),
7562 +};
7563 +
7564 +static int voicehat_daiops_trigger(struct snd_pcm_substream *substream, int cmd,
7565 + struct snd_soc_dai *dai)
7566 +{
7567 + struct snd_soc_component *component = dai->component;
7568 + struct voicehat_priv *voicehat =
7569 + snd_soc_component_get_drvdata(component);
7570 +
7571 + if (voicehat->sdmode_delay_jiffies == 0)
7572 + return 0;
7573 +
7574 + dev_dbg(dai->dev, "CMD %d", cmd);
7575 + dev_dbg(dai->dev, "Playback Active %d", dai->stream_active[SNDRV_PCM_STREAM_PLAYBACK]);
7576 + dev_dbg(dai->dev, "Capture Active %d", dai->stream_active[SNDRV_PCM_STREAM_CAPTURE]);
7577 +
7578 + switch (cmd) {
7579 + case SNDRV_PCM_TRIGGER_START:
7580 + case SNDRV_PCM_TRIGGER_RESUME:
7581 + case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
7582 + if (dai->stream_active[SNDRV_PCM_STREAM_PLAYBACK]) {
7583 + dev_info(dai->dev, "Enabling audio amp...\n");
7584 + queue_delayed_work(
7585 + system_power_efficient_wq,
7586 + &voicehat->enable_sdmode_work,
7587 + voicehat->sdmode_delay_jiffies);
7588 + }
7589 + break;
7590 + case SNDRV_PCM_TRIGGER_STOP:
7591 + case SNDRV_PCM_TRIGGER_SUSPEND:
7592 + case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
7593 + if (dai->stream_active[SNDRV_PCM_STREAM_PLAYBACK]) {
7594 + cancel_delayed_work(&voicehat->enable_sdmode_work);
7595 + dev_info(dai->dev, "Disabling audio amp...\n");
7596 + gpiod_set_value(voicehat->sdmode_gpio, 0);
7597 + }
7598 + break;
7599 + }
7600 + return 0;
7601 +}
7602 +
7603 +static const struct snd_soc_dai_ops voicehat_dai_ops = {
7604 + .trigger = voicehat_daiops_trigger,
7605 +};
7606 +
7607 +static struct snd_soc_dai_driver voicehat_dai = {
7608 + .name = "voicehat-hifi",
7609 + .capture = {
7610 + .stream_name = "HiFi Capture",
7611 + .channels_min = 2,
7612 + .channels_max = 2,
7613 + .rates = SNDRV_PCM_RATE_48000,
7614 + .formats = SNDRV_PCM_FMTBIT_S32_LE
7615 + },
7616 + .playback = {
7617 + .stream_name = "HiFi Playback",
7618 + .channels_min = 2,
7619 + .channels_max = 2,
7620 + .rates = SNDRV_PCM_RATE_48000,
7621 + .formats = SNDRV_PCM_FMTBIT_S32_LE
7622 + },
7623 + .ops = &voicehat_dai_ops,
7624 + .symmetric_rate = 1
7625 +};
7626 +
7627 +#ifdef CONFIG_OF
7628 +static const struct of_device_id voicehat_ids[] = {
7629 + { .compatible = "google,voicehat", }, {}
7630 + };
7631 + MODULE_DEVICE_TABLE(of, voicehat_ids);
7632 +#endif
7633 +
7634 +static int voicehat_platform_probe(struct platform_device *pdev)
7635 +{
7636 + struct voicehat_priv *voicehat;
7637 + unsigned int sdmode_delay;
7638 + int ret;
7639 +
7640 + voicehat = devm_kzalloc(&pdev->dev, sizeof(*voicehat), GFP_KERNEL);
7641 + if (!voicehat)
7642 + return -ENOMEM;
7643 +
7644 + ret = device_property_read_u32(&pdev->dev, "voicehat_sdmode_delay",
7645 + &sdmode_delay);
7646 +
7647 + if (ret) {
7648 + sdmode_delay = SDMODE_DELAY_MS;
7649 + dev_info(&pdev->dev,
7650 + "property 'voicehat_sdmode_delay' not found default 5 mS");
7651 + } else {
7652 + dev_info(&pdev->dev, "property 'voicehat_sdmode_delay' found delay= %d mS",
7653 + sdmode_delay);
7654 + }
7655 + voicehat->sdmode_delay_jiffies = msecs_to_jiffies(sdmode_delay);
7656 +
7657 + dev_set_drvdata(&pdev->dev, voicehat);
7658 +
7659 + return snd_soc_register_component(&pdev->dev,
7660 + &voicehat_component_driver,
7661 + &voicehat_dai,
7662 + 1);
7663 +}
7664 +
7665 +static int voicehat_platform_remove(struct platform_device *pdev)
7666 +{
7667 + snd_soc_unregister_component(&pdev->dev);
7668 + return 0;
7669 +}
7670 +
7671 +static struct platform_driver voicehat_driver = {
7672 + .driver = {
7673 + .name = "voicehat-codec",
7674 + .of_match_table = of_match_ptr(voicehat_ids),
7675 + },
7676 + .probe = voicehat_platform_probe,
7677 + .remove = voicehat_platform_remove,
7678 +};
7679 +
7680 +module_platform_driver(voicehat_driver);
7681 +
7682 +MODULE_DESCRIPTION("Google voiceHAT Codec driver");
7683 +MODULE_AUTHOR("Peter Malkin <petermalkin@google.com>");
7684 +MODULE_LICENSE("GPL v2");
7685 --- /dev/null
7686 +++ b/sound/soc/bcm/hifiberry_dacplus.c
7687 @@ -0,0 +1,527 @@
7688 +/*
7689 + * ASoC Driver for HiFiBerry DAC+ / DAC Pro / AMP100
7690 + *
7691 + * Author: Daniel Matuschek, Stuart MacLean <stuart@hifiberry.com>
7692 + * Copyright 2014-2015
7693 + * based on code by Florian Meier <florian.meier@koalo.de>
7694 + * Headphone/AMP100 Joerg Schambacher <joerg@hifiberry.com>
7695 + *
7696 + * This program is free software; you can redistribute it and/or
7697 + * modify it under the terms of the GNU General Public License
7698 + * version 2 as published by the Free Software Foundation.
7699 + *
7700 + * This program is distributed in the hope that it will be useful, but
7701 + * WITHOUT ANY WARRANTY; without even the implied warranty of
7702 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7703 + * General Public License for more details.
7704 + */
7705 +
7706 +#include <linux/module.h>
7707 +#include <linux/gpio/consumer.h>
7708 +#include <../drivers/gpio/gpiolib.h>
7709 +#include <linux/platform_device.h>
7710 +#include <linux/kernel.h>
7711 +#include <linux/clk.h>
7712 +#include <linux/kernel.h>
7713 +#include <linux/module.h>
7714 +#include <linux/of.h>
7715 +#include <linux/slab.h>
7716 +#include <linux/delay.h>
7717 +#include <linux/i2c.h>
7718 +
7719 +#include <sound/core.h>
7720 +#include <sound/pcm.h>
7721 +#include <sound/pcm_params.h>
7722 +#include <sound/soc.h>
7723 +#include <sound/jack.h>
7724 +
7725 +#include "../codecs/pcm512x.h"
7726 +
7727 +#define HIFIBERRY_DACPRO_NOCLOCK 0
7728 +#define HIFIBERRY_DACPRO_CLK44EN 1
7729 +#define HIFIBERRY_DACPRO_CLK48EN 2
7730 +
7731 +struct pcm512x_priv {
7732 + struct regmap *regmap;
7733 + struct clk *sclk;
7734 +};
7735 +
7736 +/* Clock rate of CLK44EN attached to GPIO6 pin */
7737 +#define CLK_44EN_RATE 22579200UL
7738 +/* Clock rate of CLK48EN attached to GPIO3 pin */
7739 +#define CLK_48EN_RATE 24576000UL
7740 +
7741 +static bool slave;
7742 +static bool snd_rpi_hifiberry_is_dacpro;
7743 +static bool digital_gain_0db_limit = true;
7744 +static bool leds_off;
7745 +static bool auto_mute;
7746 +static int mute_ext_ctl;
7747 +static int mute_ext;
7748 +static struct gpio_desc *snd_mute_gpio;
7749 +static struct gpio_desc *snd_reset_gpio;
7750 +static struct snd_soc_card snd_rpi_hifiberry_dacplus;
7751 +
7752 +static int snd_rpi_hifiberry_dacplus_mute_set(int mute)
7753 +{
7754 + gpiod_set_value_cansleep(snd_mute_gpio, mute);
7755 + return 1;
7756 +}
7757 +
7758 +static int snd_rpi_hifiberry_dacplus_mute_get(struct snd_kcontrol *kcontrol,
7759 + struct snd_ctl_elem_value *ucontrol)
7760 +{
7761 + ucontrol->value.integer.value[0] = mute_ext;
7762 +
7763 + return 0;
7764 +}
7765 +
7766 +static int snd_rpi_hifiberry_dacplus_mute_put(struct snd_kcontrol *kcontrol,
7767 + struct snd_ctl_elem_value *ucontrol)
7768 +{
7769 + if (mute_ext == ucontrol->value.integer.value[0])
7770 + return 0;
7771 +
7772 + mute_ext = ucontrol->value.integer.value[0];
7773 +
7774 + return snd_rpi_hifiberry_dacplus_mute_set(mute_ext);
7775 +}
7776 +
7777 +static const char * const mute_text[] = {"Play", "Mute"};
7778 +static const struct soc_enum hb_dacplus_opt_mute_enum =
7779 + SOC_ENUM_SINGLE_EXT(2, mute_text);
7780 +
7781 +static const struct snd_kcontrol_new hb_dacplus_opt_mute_controls[] = {
7782 + SOC_ENUM_EXT("Mute(ext)", hb_dacplus_opt_mute_enum,
7783 + snd_rpi_hifiberry_dacplus_mute_get,
7784 + snd_rpi_hifiberry_dacplus_mute_put),
7785 +};
7786 +
7787 +static void snd_rpi_hifiberry_dacplus_select_clk(struct snd_soc_component *component,
7788 + int clk_id)
7789 +{
7790 + switch (clk_id) {
7791 + case HIFIBERRY_DACPRO_NOCLOCK:
7792 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x24, 0x00);
7793 + break;
7794 + case HIFIBERRY_DACPRO_CLK44EN:
7795 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x24, 0x20);
7796 + break;
7797 + case HIFIBERRY_DACPRO_CLK48EN:
7798 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x24, 0x04);
7799 + break;
7800 + }
7801 + usleep_range(3000, 4000);
7802 +}
7803 +
7804 +static void snd_rpi_hifiberry_dacplus_clk_gpio(struct snd_soc_component *component)
7805 +{
7806 + snd_soc_component_update_bits(component, PCM512x_GPIO_EN, 0x24, 0x24);
7807 + snd_soc_component_update_bits(component, PCM512x_GPIO_OUTPUT_3, 0x0f, 0x02);
7808 + snd_soc_component_update_bits(component, PCM512x_GPIO_OUTPUT_6, 0x0f, 0x02);
7809 +}
7810 +
7811 +static bool snd_rpi_hifiberry_dacplus_is_sclk(struct snd_soc_component *component)
7812 +{
7813 + unsigned int sck;
7814 +
7815 + sck = snd_soc_component_read(component, PCM512x_RATE_DET_4);
7816 + return (!(sck & 0x40));
7817 +}
7818 +
7819 +static bool snd_rpi_hifiberry_dacplus_is_pro_card(struct snd_soc_component *component)
7820 +{
7821 + bool isClk44EN, isClk48En, isNoClk;
7822 +
7823 + snd_rpi_hifiberry_dacplus_clk_gpio(component);
7824 +
7825 + snd_rpi_hifiberry_dacplus_select_clk(component, HIFIBERRY_DACPRO_CLK44EN);
7826 + isClk44EN = snd_rpi_hifiberry_dacplus_is_sclk(component);
7827 +
7828 + snd_rpi_hifiberry_dacplus_select_clk(component, HIFIBERRY_DACPRO_NOCLOCK);
7829 + isNoClk = snd_rpi_hifiberry_dacplus_is_sclk(component);
7830 +
7831 + snd_rpi_hifiberry_dacplus_select_clk(component, HIFIBERRY_DACPRO_CLK48EN);
7832 + isClk48En = snd_rpi_hifiberry_dacplus_is_sclk(component);
7833 +
7834 + return (isClk44EN && isClk48En && !isNoClk);
7835 +}
7836 +
7837 +static int snd_rpi_hifiberry_dacplus_clk_for_rate(int sample_rate)
7838 +{
7839 + int type;
7840 +
7841 + switch (sample_rate) {
7842 + case 11025:
7843 + case 22050:
7844 + case 44100:
7845 + case 88200:
7846 + case 176400:
7847 + case 352800:
7848 + type = HIFIBERRY_DACPRO_CLK44EN;
7849 + break;
7850 + default:
7851 + type = HIFIBERRY_DACPRO_CLK48EN;
7852 + break;
7853 + }
7854 + return type;
7855 +}
7856 +
7857 +static void snd_rpi_hifiberry_dacplus_set_sclk(struct snd_soc_component *component,
7858 + int sample_rate)
7859 +{
7860 + struct pcm512x_priv *pcm512x = snd_soc_component_get_drvdata(component);
7861 +
7862 + if (!IS_ERR(pcm512x->sclk)) {
7863 + int ctype;
7864 +
7865 + ctype = snd_rpi_hifiberry_dacplus_clk_for_rate(sample_rate);
7866 + clk_set_rate(pcm512x->sclk, (ctype == HIFIBERRY_DACPRO_CLK44EN)
7867 + ? CLK_44EN_RATE : CLK_48EN_RATE);
7868 + snd_rpi_hifiberry_dacplus_select_clk(component, ctype);
7869 + }
7870 +}
7871 +
7872 +static int snd_rpi_hifiberry_dacplus_init(struct snd_soc_pcm_runtime *rtd)
7873 +{
7874 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
7875 + struct pcm512x_priv *priv;
7876 + struct snd_soc_card *card = &snd_rpi_hifiberry_dacplus;
7877 +
7878 + if (slave)
7879 + snd_rpi_hifiberry_is_dacpro = false;
7880 + else
7881 + snd_rpi_hifiberry_is_dacpro =
7882 + snd_rpi_hifiberry_dacplus_is_pro_card(component);
7883 +
7884 + if (snd_rpi_hifiberry_is_dacpro) {
7885 + struct snd_soc_dai_link *dai = rtd->dai_link;
7886 +
7887 + dai->name = "HiFiBerry DAC+ Pro";
7888 + dai->stream_name = "HiFiBerry DAC+ Pro HiFi";
7889 + dai->dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
7890 + | SND_SOC_DAIFMT_CBM_CFM;
7891 +
7892 + snd_soc_component_update_bits(component, PCM512x_BCLK_LRCLK_CFG, 0x31, 0x11);
7893 + snd_soc_component_update_bits(component, PCM512x_MASTER_MODE, 0x03, 0x03);
7894 + snd_soc_component_update_bits(component, PCM512x_MASTER_CLKDIV_2, 0x7f, 63);
7895 + } else {
7896 + priv = snd_soc_component_get_drvdata(component);
7897 + priv->sclk = ERR_PTR(-ENOENT);
7898 + }
7899 +
7900 + snd_soc_component_update_bits(component, PCM512x_GPIO_EN, 0x08, 0x08);
7901 + snd_soc_component_update_bits(component, PCM512x_GPIO_OUTPUT_4, 0x0f, 0x02);
7902 + if (leds_off)
7903 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x08, 0x00);
7904 + else
7905 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x08, 0x08);
7906 +
7907 + if (digital_gain_0db_limit) {
7908 + int ret;
7909 + struct snd_soc_card *card = rtd->card;
7910 +
7911 + ret = snd_soc_limit_volume(card, "Digital Playback Volume", 207);
7912 + if (ret < 0)
7913 + dev_warn(card->dev, "Failed to set volume limit: %d\n", ret);
7914 + }
7915 + if (snd_reset_gpio) {
7916 + gpiod_set_value_cansleep(snd_reset_gpio, 0);
7917 + msleep(1);
7918 + gpiod_set_value_cansleep(snd_reset_gpio, 1);
7919 + msleep(1);
7920 + gpiod_set_value_cansleep(snd_reset_gpio, 0);
7921 + }
7922 +
7923 + if (mute_ext_ctl)
7924 + snd_soc_add_card_controls(card, hb_dacplus_opt_mute_controls,
7925 + ARRAY_SIZE(hb_dacplus_opt_mute_controls));
7926 +
7927 + if (snd_mute_gpio)
7928 + gpiod_set_value_cansleep(snd_mute_gpio, mute_ext);
7929 +
7930 + return 0;
7931 +}
7932 +
7933 +static int snd_rpi_hifiberry_dacplus_update_rate_den(
7934 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
7935 +{
7936 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
7937 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
7938 + struct pcm512x_priv *pcm512x = snd_soc_component_get_drvdata(component);
7939 + struct snd_ratnum *rats_no_pll;
7940 + unsigned int num = 0, den = 0;
7941 + int err;
7942 +
7943 + rats_no_pll = devm_kzalloc(rtd->dev, sizeof(*rats_no_pll), GFP_KERNEL);
7944 + if (!rats_no_pll)
7945 + return -ENOMEM;
7946 +
7947 + rats_no_pll->num = clk_get_rate(pcm512x->sclk) / 64;
7948 + rats_no_pll->den_min = 1;
7949 + rats_no_pll->den_max = 128;
7950 + rats_no_pll->den_step = 1;
7951 +
7952 + err = snd_interval_ratnum(hw_param_interval(params,
7953 + SNDRV_PCM_HW_PARAM_RATE), 1, rats_no_pll, &num, &den);
7954 + if (err >= 0 && den) {
7955 + params->rate_num = num;
7956 + params->rate_den = den;
7957 + }
7958 +
7959 + devm_kfree(rtd->dev, rats_no_pll);
7960 + return 0;
7961 +}
7962 +
7963 +static int snd_rpi_hifiberry_dacplus_hw_params(
7964 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
7965 +{
7966 + int ret = 0;
7967 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
7968 + int channels = params_channels(params);
7969 + int width = 32;
7970 +
7971 + if (snd_rpi_hifiberry_is_dacpro) {
7972 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
7973 +
7974 + width = snd_pcm_format_physical_width(params_format(params));
7975 +
7976 + snd_rpi_hifiberry_dacplus_set_sclk(component,
7977 + params_rate(params));
7978 +
7979 + ret = snd_rpi_hifiberry_dacplus_update_rate_den(
7980 + substream, params);
7981 + }
7982 +
7983 + ret = snd_soc_dai_set_bclk_ratio(asoc_rtd_to_cpu(rtd, 0), channels * width);
7984 + if (ret)
7985 + return ret;
7986 + ret = snd_soc_dai_set_bclk_ratio(asoc_rtd_to_codec(rtd, 0), channels * width);
7987 + return ret;
7988 +}
7989 +
7990 +static int snd_rpi_hifiberry_dacplus_startup(
7991 + struct snd_pcm_substream *substream)
7992 +{
7993 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
7994 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
7995 +
7996 + if (auto_mute)
7997 + gpiod_set_value_cansleep(snd_mute_gpio, 0);
7998 + if (leds_off)
7999 + return 0;
8000 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x08, 0x08);
8001 + return 0;
8002 +}
8003 +
8004 +static void snd_rpi_hifiberry_dacplus_shutdown(
8005 + struct snd_pcm_substream *substream)
8006 +{
8007 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
8008 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
8009 +
8010 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x08, 0x00);
8011 + if (auto_mute)
8012 + gpiod_set_value_cansleep(snd_mute_gpio, 1);
8013 +}
8014 +
8015 +/* machine stream operations */
8016 +static struct snd_soc_ops snd_rpi_hifiberry_dacplus_ops = {
8017 + .hw_params = snd_rpi_hifiberry_dacplus_hw_params,
8018 + .startup = snd_rpi_hifiberry_dacplus_startup,
8019 + .shutdown = snd_rpi_hifiberry_dacplus_shutdown,
8020 +};
8021 +
8022 +SND_SOC_DAILINK_DEFS(rpi_hifiberry_dacplus,
8023 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
8024 + DAILINK_COMP_ARRAY(COMP_CODEC("pcm512x.1-004d", "pcm512x-hifi")),
8025 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
8026 +
8027 +static struct snd_soc_dai_link snd_rpi_hifiberry_dacplus_dai[] = {
8028 +{
8029 + .name = "HiFiBerry DAC+",
8030 + .stream_name = "HiFiBerry DAC+ HiFi",
8031 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
8032 + SND_SOC_DAIFMT_CBS_CFS,
8033 + .ops = &snd_rpi_hifiberry_dacplus_ops,
8034 + .init = snd_rpi_hifiberry_dacplus_init,
8035 + SND_SOC_DAILINK_REG(rpi_hifiberry_dacplus),
8036 +},
8037 +};
8038 +
8039 +/* aux device for optional headphone amp */
8040 +static struct snd_soc_aux_dev hifiberry_dacplus_aux_devs[] = {
8041 + {
8042 + .dlc = {
8043 + .name = "tpa6130a2.1-0060",
8044 + },
8045 + },
8046 +};
8047 +
8048 +/* audio machine driver */
8049 +static struct snd_soc_card snd_rpi_hifiberry_dacplus = {
8050 + .name = "snd_rpi_hifiberry_dacplus",
8051 + .driver_name = "HifiberryDacp",
8052 + .owner = THIS_MODULE,
8053 + .dai_link = snd_rpi_hifiberry_dacplus_dai,
8054 + .num_links = ARRAY_SIZE(snd_rpi_hifiberry_dacplus_dai),
8055 +};
8056 +
8057 +static int hb_hp_detect(void)
8058 +{
8059 + struct i2c_adapter *adap = i2c_get_adapter(1);
8060 + int ret;
8061 + struct i2c_client tpa_i2c_client = {
8062 + .addr = 0x60,
8063 + .adapter = adap,
8064 + };
8065 +
8066 + if (!adap)
8067 + return -EPROBE_DEFER; /* I2C module not yet available */
8068 +
8069 + ret = i2c_smbus_read_byte(&tpa_i2c_client) >= 0;
8070 + i2c_put_adapter(adap);
8071 + return ret;
8072 +};
8073 +
8074 +static struct property tpa_enable_prop = {
8075 + .name = "status",
8076 + .length = 4 + 1, /* length 'okay' + 1 */
8077 + .value = "okay",
8078 + };
8079 +
8080 +static int snd_rpi_hifiberry_dacplus_probe(struct platform_device *pdev)
8081 +{
8082 + int ret = 0;
8083 + struct snd_soc_card *card = &snd_rpi_hifiberry_dacplus;
8084 + int len;
8085 + struct device_node *tpa_node;
8086 + struct property *tpa_prop;
8087 + struct of_changeset ocs;
8088 + struct property *pp;
8089 + int tmp;
8090 +
8091 + /* probe for head phone amp */
8092 + ret = hb_hp_detect();
8093 + if (ret < 0)
8094 + return ret;
8095 + if (ret) {
8096 + card->aux_dev = hifiberry_dacplus_aux_devs;
8097 + card->num_aux_devs =
8098 + ARRAY_SIZE(hifiberry_dacplus_aux_devs);
8099 + tpa_node = of_find_compatible_node(NULL, NULL, "ti,tpa6130a2");
8100 + tpa_prop = of_find_property(tpa_node, "status", &len);
8101 +
8102 + if (strcmp((char *)tpa_prop->value, "okay")) {
8103 + /* and activate headphone using change_sets */
8104 + dev_info(&pdev->dev, "activating headphone amplifier");
8105 + of_changeset_init(&ocs);
8106 + ret = of_changeset_update_property(&ocs, tpa_node,
8107 + &tpa_enable_prop);
8108 + if (ret) {
8109 + dev_err(&pdev->dev,
8110 + "cannot activate headphone amplifier\n");
8111 + return -ENODEV;
8112 + }
8113 + ret = of_changeset_apply(&ocs);
8114 + if (ret) {
8115 + dev_err(&pdev->dev,
8116 + "cannot activate headphone amplifier\n");
8117 + return -ENODEV;
8118 + }
8119 + }
8120 + }
8121 +
8122 + snd_rpi_hifiberry_dacplus.dev = &pdev->dev;
8123 + if (pdev->dev.of_node) {
8124 + struct device_node *i2s_node;
8125 + struct snd_soc_dai_link *dai;
8126 +
8127 + dai = &snd_rpi_hifiberry_dacplus_dai[0];
8128 + i2s_node = of_parse_phandle(pdev->dev.of_node,
8129 + "i2s-controller", 0);
8130 +
8131 + if (i2s_node) {
8132 + dai->cpus->dai_name = NULL;
8133 + dai->cpus->of_node = i2s_node;
8134 + dai->platforms->name = NULL;
8135 + dai->platforms->of_node = i2s_node;
8136 + }
8137 +
8138 + digital_gain_0db_limit = !of_property_read_bool(
8139 + pdev->dev.of_node, "hifiberry,24db_digital_gain");
8140 + slave = of_property_read_bool(pdev->dev.of_node,
8141 + "hifiberry-dacplus,slave");
8142 + leds_off = of_property_read_bool(pdev->dev.of_node,
8143 + "hifiberry-dacplus,leds_off");
8144 + auto_mute = of_property_read_bool(pdev->dev.of_node,
8145 + "hifiberry-dacplus,auto_mute");
8146 +
8147 + /*
8148 + * check for HW MUTE as defined in DT-overlay
8149 + * active high, therefore default to HIGH to MUTE
8150 + */
8151 + snd_mute_gpio = devm_gpiod_get_optional(&pdev->dev,
8152 + "mute", GPIOD_OUT_HIGH);
8153 + if (IS_ERR(snd_mute_gpio)) {
8154 + dev_err(&pdev->dev, "Can't allocate GPIO (HW-MUTE)");
8155 + return PTR_ERR(snd_mute_gpio);
8156 + }
8157 +
8158 + /* add ALSA control if requested in DT-overlay (AMP100) */
8159 + pp = of_find_property(pdev->dev.of_node,
8160 + "hifiberry-dacplus,mute_ext_ctl", &tmp);
8161 + if (pp) {
8162 + if (!of_property_read_u32(pdev->dev.of_node,
8163 + "hifiberry-dacplus,mute_ext_ctl", &mute_ext)) {
8164 + /* ALSA control will be used */
8165 + mute_ext_ctl = 1;
8166 + }
8167 + }
8168 +
8169 + /* check for HW RESET (AMP100) */
8170 + snd_reset_gpio = devm_gpiod_get_optional(&pdev->dev,
8171 + "reset", GPIOD_OUT_HIGH);
8172 + if (IS_ERR(snd_reset_gpio)) {
8173 + dev_err(&pdev->dev, "Can't allocate GPIO (HW-RESET)");
8174 + return PTR_ERR(snd_reset_gpio);
8175 + }
8176 +
8177 + }
8178 +
8179 + ret = devm_snd_soc_register_card(&pdev->dev,
8180 + &snd_rpi_hifiberry_dacplus);
8181 + if (ret && ret != -EPROBE_DEFER)
8182 + dev_err(&pdev->dev,
8183 + "snd_soc_register_card() failed: %d\n", ret);
8184 + if (!ret) {
8185 + if (snd_mute_gpio)
8186 + dev_info(&pdev->dev, "GPIO%i for HW-MUTE selected",
8187 + gpio_chip_hwgpio(snd_mute_gpio));
8188 + if (snd_reset_gpio)
8189 + dev_info(&pdev->dev, "GPIO%i for HW-RESET selected",
8190 + gpio_chip_hwgpio(snd_reset_gpio));
8191 + }
8192 + return ret;
8193 +}
8194 +
8195 +static const struct of_device_id snd_rpi_hifiberry_dacplus_of_match[] = {
8196 + { .compatible = "hifiberry,hifiberry-dacplus", },
8197 + {},
8198 +};
8199 +MODULE_DEVICE_TABLE(of, snd_rpi_hifiberry_dacplus_of_match);
8200 +
8201 +static struct platform_driver snd_rpi_hifiberry_dacplus_driver = {
8202 + .driver = {
8203 + .name = "snd-rpi-hifiberry-dacplus",
8204 + .owner = THIS_MODULE,
8205 + .of_match_table = snd_rpi_hifiberry_dacplus_of_match,
8206 + },
8207 + .probe = snd_rpi_hifiberry_dacplus_probe,
8208 +};
8209 +
8210 +module_platform_driver(snd_rpi_hifiberry_dacplus_driver);
8211 +
8212 +MODULE_AUTHOR("Daniel Matuschek <daniel@hifiberry.com>");
8213 +MODULE_DESCRIPTION("ASoC Driver for HiFiBerry DAC+");
8214 +MODULE_LICENSE("GPL v2");
8215 --- /dev/null
8216 +++ b/sound/soc/bcm/hifiberry_dacplusadc.c
8217 @@ -0,0 +1,398 @@
8218 +/*
8219 + * ASoC Driver for HiFiBerry DAC+ / DAC Pro with ADC
8220 + *
8221 + * Author: Daniel Matuschek, Stuart MacLean <stuart@hifiberry.com>
8222 + * Copyright 2014-2015
8223 + * based on code by Florian Meier <florian.meier@koalo.de>
8224 + * ADC added by Joerg Schambacher <joscha@schambacher.com>
8225 + * Copyright 2018
8226 + *
8227 + * This program is free software; you can redistribute it and/or
8228 + * modify it under the terms of the GNU General Public License
8229 + * version 2 as published by the Free Software Foundation.
8230 + *
8231 + * This program is distributed in the hope that it will be useful, but
8232 + * WITHOUT ANY WARRANTY; without even the implied warranty of
8233 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
8234 + * General Public License for more details.
8235 + */
8236 +
8237 +#include <linux/module.h>
8238 +#include <linux/platform_device.h>
8239 +#include <linux/kernel.h>
8240 +#include <linux/clk.h>
8241 +#include <linux/kernel.h>
8242 +#include <linux/module.h>
8243 +#include <linux/of.h>
8244 +#include <linux/slab.h>
8245 +#include <linux/delay.h>
8246 +
8247 +#include <sound/core.h>
8248 +#include <sound/pcm.h>
8249 +#include <sound/pcm_params.h>
8250 +#include <sound/soc.h>
8251 +#include <sound/jack.h>
8252 +
8253 +#include "../codecs/pcm512x.h"
8254 +
8255 +#define HIFIBERRY_DACPRO_NOCLOCK 0
8256 +#define HIFIBERRY_DACPRO_CLK44EN 1
8257 +#define HIFIBERRY_DACPRO_CLK48EN 2
8258 +
8259 +struct platform_device *dmic_codec_dev;
8260 +
8261 +struct pcm512x_priv {
8262 + struct regmap *regmap;
8263 + struct clk *sclk;
8264 +};
8265 +
8266 +/* Clock rate of CLK44EN attached to GPIO6 pin */
8267 +#define CLK_44EN_RATE 22579200UL
8268 +/* Clock rate of CLK48EN attached to GPIO3 pin */
8269 +#define CLK_48EN_RATE 24576000UL
8270 +
8271 +static bool slave;
8272 +static bool snd_rpi_hifiberry_is_dacpro;
8273 +static bool digital_gain_0db_limit = true;
8274 +static bool leds_off;
8275 +
8276 +static void snd_rpi_hifiberry_dacplusadc_select_clk(struct snd_soc_component *component,
8277 + int clk_id)
8278 +{
8279 + switch (clk_id) {
8280 + case HIFIBERRY_DACPRO_NOCLOCK:
8281 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x24, 0x00);
8282 + break;
8283 + case HIFIBERRY_DACPRO_CLK44EN:
8284 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x24, 0x20);
8285 + break;
8286 + case HIFIBERRY_DACPRO_CLK48EN:
8287 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x24, 0x04);
8288 + break;
8289 + }
8290 +}
8291 +
8292 +static void snd_rpi_hifiberry_dacplusadc_clk_gpio(struct snd_soc_component *component)
8293 +{
8294 + snd_soc_component_update_bits(component, PCM512x_GPIO_EN, 0x24, 0x24);
8295 + snd_soc_component_update_bits(component, PCM512x_GPIO_OUTPUT_3, 0x0f, 0x02);
8296 + snd_soc_component_update_bits(component, PCM512x_GPIO_OUTPUT_6, 0x0f, 0x02);
8297 +}
8298 +
8299 +static bool snd_rpi_hifiberry_dacplusadc_is_sclk(struct snd_soc_component *component)
8300 +{
8301 + unsigned int sck;
8302 +
8303 + sck = snd_soc_component_read(component, PCM512x_RATE_DET_4);
8304 + return (!(sck & 0x40));
8305 +}
8306 +
8307 +static bool snd_rpi_hifiberry_dacplusadc_is_sclk_sleep(
8308 + struct snd_soc_component *component)
8309 +{
8310 + msleep(2);
8311 + return snd_rpi_hifiberry_dacplusadc_is_sclk(component);
8312 +}
8313 +
8314 +static bool snd_rpi_hifiberry_dacplusadc_is_pro_card(struct snd_soc_component *component)
8315 +{
8316 + bool isClk44EN, isClk48En, isNoClk;
8317 +
8318 + snd_rpi_hifiberry_dacplusadc_clk_gpio(component);
8319 +
8320 + snd_rpi_hifiberry_dacplusadc_select_clk(component, HIFIBERRY_DACPRO_CLK44EN);
8321 + isClk44EN = snd_rpi_hifiberry_dacplusadc_is_sclk_sleep(component);
8322 +
8323 + snd_rpi_hifiberry_dacplusadc_select_clk(component, HIFIBERRY_DACPRO_NOCLOCK);
8324 + isNoClk = snd_rpi_hifiberry_dacplusadc_is_sclk_sleep(component);
8325 +
8326 + snd_rpi_hifiberry_dacplusadc_select_clk(component, HIFIBERRY_DACPRO_CLK48EN);
8327 + isClk48En = snd_rpi_hifiberry_dacplusadc_is_sclk_sleep(component);
8328 +
8329 + return (isClk44EN && isClk48En && !isNoClk);
8330 +}
8331 +
8332 +static int snd_rpi_hifiberry_dacplusadc_clk_for_rate(int sample_rate)
8333 +{
8334 + int type;
8335 +
8336 + switch (sample_rate) {
8337 + case 11025:
8338 + case 22050:
8339 + case 44100:
8340 + case 88200:
8341 + case 176400:
8342 + case 352800:
8343 + type = HIFIBERRY_DACPRO_CLK44EN;
8344 + break;
8345 + default:
8346 + type = HIFIBERRY_DACPRO_CLK48EN;
8347 + break;
8348 + }
8349 + return type;
8350 +}
8351 +
8352 +static void snd_rpi_hifiberry_dacplusadc_set_sclk(struct snd_soc_component *component,
8353 + int sample_rate)
8354 +{
8355 + struct pcm512x_priv *pcm512x = snd_soc_component_get_drvdata(component);
8356 +
8357 + if (!IS_ERR(pcm512x->sclk)) {
8358 + int ctype;
8359 +
8360 + ctype = snd_rpi_hifiberry_dacplusadc_clk_for_rate(sample_rate);
8361 + clk_set_rate(pcm512x->sclk, (ctype == HIFIBERRY_DACPRO_CLK44EN)
8362 + ? CLK_44EN_RATE : CLK_48EN_RATE);
8363 + snd_rpi_hifiberry_dacplusadc_select_clk(component, ctype);
8364 + }
8365 +}
8366 +
8367 +static int snd_rpi_hifiberry_dacplusadc_init(struct snd_soc_pcm_runtime *rtd)
8368 +{
8369 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
8370 + struct pcm512x_priv *priv;
8371 +
8372 + if (slave)
8373 + snd_rpi_hifiberry_is_dacpro = false;
8374 + else
8375 + snd_rpi_hifiberry_is_dacpro =
8376 + snd_rpi_hifiberry_dacplusadc_is_pro_card(component);
8377 +
8378 + if (snd_rpi_hifiberry_is_dacpro) {
8379 + struct snd_soc_dai_link *dai = rtd->dai_link;
8380 +
8381 + dai->name = "HiFiBerry ADCDAC+ Pro";
8382 + dai->stream_name = "HiFiBerry ADCDAC+ Pro HiFi";
8383 + dai->dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
8384 + | SND_SOC_DAIFMT_CBM_CFM;
8385 +
8386 + snd_soc_component_update_bits(component, PCM512x_BCLK_LRCLK_CFG, 0x31, 0x11);
8387 + snd_soc_component_update_bits(component, PCM512x_MASTER_MODE, 0x03, 0x03);
8388 + snd_soc_component_update_bits(component, PCM512x_MASTER_CLKDIV_2, 0x7f, 63);
8389 + } else {
8390 + priv = snd_soc_component_get_drvdata(component);
8391 + priv->sclk = ERR_PTR(-ENOENT);
8392 + }
8393 +
8394 + snd_soc_component_update_bits(component, PCM512x_GPIO_EN, 0x08, 0x08);
8395 + snd_soc_component_update_bits(component, PCM512x_GPIO_OUTPUT_4, 0x0f, 0x02);
8396 + if (leds_off)
8397 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x08, 0x00);
8398 + else
8399 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x08, 0x08);
8400 +
8401 + if (digital_gain_0db_limit) {
8402 + int ret;
8403 + struct snd_soc_card *card = rtd->card;
8404 +
8405 + ret = snd_soc_limit_volume(card, "Digital Playback Volume", 207);
8406 + if (ret < 0)
8407 + dev_warn(card->dev, "Failed to set volume limit: %d\n", ret);
8408 + }
8409 +
8410 + return 0;
8411 +}
8412 +
8413 +static int snd_rpi_hifiberry_dacplusadc_update_rate_den(
8414 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
8415 +{
8416 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
8417 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
8418 + struct pcm512x_priv *pcm512x = snd_soc_component_get_drvdata(component);
8419 + struct snd_ratnum *rats_no_pll;
8420 + unsigned int num = 0, den = 0;
8421 + int err;
8422 +
8423 + rats_no_pll = devm_kzalloc(rtd->dev, sizeof(*rats_no_pll), GFP_KERNEL);
8424 + if (!rats_no_pll)
8425 + return -ENOMEM;
8426 +
8427 + rats_no_pll->num = clk_get_rate(pcm512x->sclk) / 64;
8428 + rats_no_pll->den_min = 1;
8429 + rats_no_pll->den_max = 128;
8430 + rats_no_pll->den_step = 1;
8431 +
8432 + err = snd_interval_ratnum(hw_param_interval(params,
8433 + SNDRV_PCM_HW_PARAM_RATE), 1, rats_no_pll, &num, &den);
8434 + if (err >= 0 && den) {
8435 + params->rate_num = num;
8436 + params->rate_den = den;
8437 + }
8438 +
8439 + devm_kfree(rtd->dev, rats_no_pll);
8440 + return 0;
8441 +}
8442 +
8443 +static int snd_rpi_hifiberry_dacplusadc_hw_params(
8444 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
8445 +{
8446 + int ret = 0;
8447 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
8448 + int channels = params_channels(params);
8449 + int width = 32;
8450 +
8451 + if (snd_rpi_hifiberry_is_dacpro) {
8452 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
8453 +
8454 + width = snd_pcm_format_physical_width(params_format(params));
8455 +
8456 + snd_rpi_hifiberry_dacplusadc_set_sclk(component,
8457 + params_rate(params));
8458 +
8459 + ret = snd_rpi_hifiberry_dacplusadc_update_rate_den(
8460 + substream, params);
8461 + }
8462 +
8463 + ret = snd_soc_dai_set_bclk_ratio(asoc_rtd_to_cpu(rtd, 0), channels * width);
8464 + if (ret)
8465 + return ret;
8466 + ret = snd_soc_dai_set_bclk_ratio(asoc_rtd_to_codec(rtd, 0), channels * width);
8467 + return ret;
8468 +}
8469 +
8470 +static int hifiberry_dacplusadc_LED_cnt;
8471 +
8472 +static int snd_rpi_hifiberry_dacplusadc_startup(
8473 + struct snd_pcm_substream *substream)
8474 +{
8475 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
8476 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
8477 +
8478 + if (leds_off)
8479 + return 0;
8480 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1,
8481 + 0x08, 0x08);
8482 + hifiberry_dacplusadc_LED_cnt++;
8483 + return 0;
8484 +}
8485 +
8486 +static void snd_rpi_hifiberry_dacplusadc_shutdown(
8487 + struct snd_pcm_substream *substream)
8488 +{
8489 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
8490 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
8491 +
8492 + hifiberry_dacplusadc_LED_cnt--;
8493 + if (!hifiberry_dacplusadc_LED_cnt)
8494 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1,
8495 + 0x08, 0x00);
8496 +}
8497 +
8498 +/* machine stream operations */
8499 +static struct snd_soc_ops snd_rpi_hifiberry_dacplusadc_ops = {
8500 + .hw_params = snd_rpi_hifiberry_dacplusadc_hw_params,
8501 + .startup = snd_rpi_hifiberry_dacplusadc_startup,
8502 + .shutdown = snd_rpi_hifiberry_dacplusadc_shutdown,
8503 +};
8504 +
8505 +SND_SOC_DAILINK_DEFS(hifi,
8506 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
8507 + DAILINK_COMP_ARRAY(COMP_CODEC("pcm512x.1-004d", "pcm512x-hifi"),
8508 + COMP_CODEC("dmic-codec", "dmic-hifi")),
8509 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
8510 +
8511 +static struct snd_soc_dai_link snd_rpi_hifiberry_dacplusadc_dai[] = {
8512 +{
8513 + .name = "HiFiBerry DAC+ADC",
8514 + .stream_name = "HiFiBerry DAC+ADC HiFi",
8515 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
8516 + SND_SOC_DAIFMT_CBS_CFS,
8517 + .ops = &snd_rpi_hifiberry_dacplusadc_ops,
8518 + .init = snd_rpi_hifiberry_dacplusadc_init,
8519 + SND_SOC_DAILINK_REG(hifi),
8520 +},
8521 +};
8522 +
8523 +/* audio machine driver */
8524 +static struct snd_soc_card snd_rpi_hifiberry_dacplusadc = {
8525 + .name = "snd_rpi_hifiberry_dacplusadc",
8526 + .driver_name = "HifiberryDacpAdc",
8527 + .owner = THIS_MODULE,
8528 + .dai_link = snd_rpi_hifiberry_dacplusadc_dai,
8529 + .num_links = ARRAY_SIZE(snd_rpi_hifiberry_dacplusadc_dai),
8530 +};
8531 +
8532 +
8533 +static int snd_rpi_hifiberry_dacplusadc_probe(struct platform_device *pdev)
8534 +{
8535 + int ret = 0;
8536 +
8537 + snd_rpi_hifiberry_dacplusadc.dev = &pdev->dev;
8538 + if (pdev->dev.of_node) {
8539 + struct device_node *i2s_node;
8540 + struct snd_soc_dai_link *dai;
8541 +
8542 + dai = &snd_rpi_hifiberry_dacplusadc_dai[0];
8543 + i2s_node = of_parse_phandle(pdev->dev.of_node,
8544 + "i2s-controller", 0);
8545 + if (i2s_node) {
8546 + dai->cpus->of_node = i2s_node;
8547 + dai->platforms->of_node = i2s_node;
8548 + dai->cpus->dai_name = NULL;
8549 + dai->platforms->name = NULL;
8550 + }
8551 + }
8552 + digital_gain_0db_limit = !of_property_read_bool(
8553 + pdev->dev.of_node, "hifiberry,24db_digital_gain");
8554 + slave = of_property_read_bool(pdev->dev.of_node,
8555 + "hifiberry-dacplusadc,slave");
8556 + leds_off = of_property_read_bool(pdev->dev.of_node,
8557 + "hifiberry-dacplusadc,leds_off");
8558 +
8559 + ret = devm_snd_soc_register_card(&pdev->dev,
8560 + &snd_rpi_hifiberry_dacplusadc);
8561 + if (ret && ret != -EPROBE_DEFER)
8562 + dev_err(&pdev->dev,
8563 + "snd_soc_register_card() failed: %d\n", ret);
8564 +
8565 + return ret;
8566 +}
8567 +
8568 +static const struct of_device_id snd_rpi_hifiberry_dacplusadc_of_match[] = {
8569 + { .compatible = "hifiberry,hifiberry-dacplusadc", },
8570 + {},
8571 +};
8572 +
8573 +MODULE_DEVICE_TABLE(of, snd_rpi_hifiberry_dacplusadc_of_match);
8574 +
8575 +static struct platform_driver snd_rpi_hifiberry_dacplusadc_driver = {
8576 + .driver = {
8577 + .name = "snd-rpi-hifiberry-dacplusadc",
8578 + .owner = THIS_MODULE,
8579 + .of_match_table = snd_rpi_hifiberry_dacplusadc_of_match,
8580 + },
8581 + .probe = snd_rpi_hifiberry_dacplusadc_probe,
8582 +};
8583 +
8584 +static int __init hifiberry_dacplusadc_init(void)
8585 +{
8586 + int ret;
8587 +
8588 + dmic_codec_dev = platform_device_register_simple("dmic-codec", -1, NULL,
8589 + 0);
8590 + if (IS_ERR(dmic_codec_dev)) {
8591 + pr_err("%s: dmic-codec device registration failed\n", __func__);
8592 + return PTR_ERR(dmic_codec_dev);
8593 + }
8594 +
8595 + ret = platform_driver_register(&snd_rpi_hifiberry_dacplusadc_driver);
8596 + if (ret) {
8597 + pr_err("%s: platform driver registration failed\n", __func__);
8598 + platform_device_unregister(dmic_codec_dev);
8599 + }
8600 +
8601 + return ret;
8602 +}
8603 +module_init(hifiberry_dacplusadc_init);
8604 +
8605 +static void __exit hifiberry_dacplusadc_exit(void)
8606 +{
8607 + platform_driver_unregister(&snd_rpi_hifiberry_dacplusadc_driver);
8608 + platform_device_unregister(dmic_codec_dev);
8609 +}
8610 +module_exit(hifiberry_dacplusadc_exit);
8611 +
8612 +MODULE_AUTHOR("Joerg Schambacher <joscha@schambacher.com>");
8613 +MODULE_AUTHOR("Daniel Matuschek <daniel@hifiberry.com>");
8614 +MODULE_DESCRIPTION("ASoC Driver for HiFiBerry DAC+ADC");
8615 +MODULE_LICENSE("GPL v2");
8616 --- /dev/null
8617 +++ b/sound/soc/bcm/hifiberry_dacplusadcpro.c
8618 @@ -0,0 +1,537 @@
8619 +/*
8620 + * ASoC Driver for HiFiBerry DAC+ / DAC Pro with ADC PRO Version (SW control)
8621 + *
8622 + * Author: Daniel Matuschek, Stuart MacLean <stuart@hifiberry.com>
8623 + * Copyright 2014-2015
8624 + * based on code by Florian Meier <florian.meier@koalo.de>
8625 + * ADC added by Joerg Schambacher <joerg@i2audio.com>
8626 + * Copyright 2018-19
8627 + *
8628 + * This program is free software; you can redistribute it and/or
8629 + * modify it under the terms of the GNU General Public License
8630 + * version 2 as published by the Free Software Foundation.
8631 + *
8632 + * This program is distributed in the hope that it will be useful, but
8633 + * WITHOUT ANY WARRANTY; without even the implied warranty of
8634 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
8635 + * General Public License for more details.
8636 + */
8637 +
8638 +#include <linux/module.h>
8639 +#include <linux/platform_device.h>
8640 +#include <linux/kernel.h>
8641 +#include <linux/clk.h>
8642 +#include <linux/kernel.h>
8643 +#include <linux/module.h>
8644 +#include <linux/of.h>
8645 +#include <linux/slab.h>
8646 +#include <linux/delay.h>
8647 +
8648 +#include <sound/core.h>
8649 +#include <sound/pcm.h>
8650 +#include <sound/pcm_params.h>
8651 +#include <sound/soc.h>
8652 +#include <sound/jack.h>
8653 +#include <sound/tlv.h>
8654 +
8655 +#include "../codecs/pcm512x.h"
8656 +#include "../codecs/pcm186x.h"
8657 +
8658 +#define HIFIBERRY_DACPRO_NOCLOCK 0
8659 +#define HIFIBERRY_DACPRO_CLK44EN 1
8660 +#define HIFIBERRY_DACPRO_CLK48EN 2
8661 +
8662 +struct pcm512x_priv {
8663 + struct regmap *regmap;
8664 + struct clk *sclk;
8665 +};
8666 +
8667 +/* Clock rate of CLK44EN attached to GPIO6 pin */
8668 +#define CLK_44EN_RATE 22579200UL
8669 +/* Clock rate of CLK48EN attached to GPIO3 pin */
8670 +#define CLK_48EN_RATE 24576000UL
8671 +
8672 +static bool slave;
8673 +static bool snd_rpi_hifiberry_is_dacpro;
8674 +static bool digital_gain_0db_limit = true;
8675 +static bool leds_off;
8676 +
8677 +static const unsigned int pcm186x_adc_input_channel_sel_value[] = {
8678 + 0x00, 0x01, 0x02, 0x03, 0x10
8679 +};
8680 +
8681 +static const char * const pcm186x_adcl_input_channel_sel_text[] = {
8682 + "No Select",
8683 + "VINL1[SE]", /* Default for ADCL */
8684 + "VINL2[SE]",
8685 + "VINL2[SE] + VINL1[SE]",
8686 + "{VIN1P, VIN1M}[DIFF]"
8687 +};
8688 +
8689 +static const char * const pcm186x_adcr_input_channel_sel_text[] = {
8690 + "No Select",
8691 + "VINR1[SE]", /* Default for ADCR */
8692 + "VINR2[SE]",
8693 + "VINR2[SE] + VINR1[SE]",
8694 + "{VIN2P, VIN2M}[DIFF]"
8695 +};
8696 +
8697 +static const struct soc_enum pcm186x_adc_input_channel_sel[] = {
8698 + SOC_VALUE_ENUM_SINGLE(PCM186X_ADC1_INPUT_SEL_L, 0,
8699 + PCM186X_ADC_INPUT_SEL_MASK,
8700 + ARRAY_SIZE(pcm186x_adcl_input_channel_sel_text),
8701 + pcm186x_adcl_input_channel_sel_text,
8702 + pcm186x_adc_input_channel_sel_value),
8703 + SOC_VALUE_ENUM_SINGLE(PCM186X_ADC1_INPUT_SEL_R, 0,
8704 + PCM186X_ADC_INPUT_SEL_MASK,
8705 + ARRAY_SIZE(pcm186x_adcr_input_channel_sel_text),
8706 + pcm186x_adcr_input_channel_sel_text,
8707 + pcm186x_adc_input_channel_sel_value),
8708 +};
8709 +
8710 +static const unsigned int pcm186x_mic_bias_sel_value[] = {
8711 + 0x00, 0x01, 0x11
8712 +};
8713 +
8714 +static const char * const pcm186x_mic_bias_sel_text[] = {
8715 + "Mic Bias off",
8716 + "Mic Bias on",
8717 + "Mic Bias with Bypass Resistor"
8718 +};
8719 +
8720 +static const struct soc_enum pcm186x_mic_bias_sel[] = {
8721 + SOC_VALUE_ENUM_SINGLE(PCM186X_MIC_BIAS_CTRL, 0,
8722 + GENMASK(4, 0),
8723 + ARRAY_SIZE(pcm186x_mic_bias_sel_text),
8724 + pcm186x_mic_bias_sel_text,
8725 + pcm186x_mic_bias_sel_value),
8726 +};
8727 +
8728 +static const unsigned int pcm186x_gain_sel_value[] = {
8729 + 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
8730 + 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
8731 + 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
8732 + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
8733 + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
8734 + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
8735 + 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
8736 + 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
8737 + 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
8738 + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
8739 + 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
8740 + 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
8741 + 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
8742 + 0x50
8743 +};
8744 +
8745 +static const char * const pcm186x_gain_sel_text[] = {
8746 + "-12.0dB", "-11.5dB", "-11.0dB", "-10.5dB", "-10.0dB", "-9.5dB",
8747 + "-9.0dB", "-8.5dB", "-8.0dB", "-7.5dB", "-7.0dB", "-6.5dB",
8748 + "-6.0dB", "-5.5dB", "-5.0dB", "-4.5dB", "-4.0dB", "-3.5dB",
8749 + "-3.0dB", "-2.5dB", "-2.0dB", "-1.5dB", "-1.0dB", "-0.5dB",
8750 + "0.0dB", "0.5dB", "1.0dB", "1.5dB", "2.0dB", "2.5dB",
8751 + "3.0dB", "3.5dB", "4.0dB", "4.5dB", "5.0dB", "5.5dB",
8752 + "6.0dB", "6.5dB", "7.0dB", "7.5dB", "8.0dB", "8.5dB",
8753 + "9.0dB", "9.5dB", "10.0dB", "10.5dB", "11.0dB", "11.5dB",
8754 + "12.0dB", "12.5dB", "13.0dB", "13.5dB", "14.0dB", "14.5dB",
8755 + "15.0dB", "15.5dB", "16.0dB", "16.5dB", "17.0dB", "17.5dB",
8756 + "18.0dB", "18.5dB", "19.0dB", "19.5dB", "20.0dB", "20.5dB",
8757 + "21.0dB", "21.5dB", "22.0dB", "22.5dB", "23.0dB", "23.5dB",
8758 + "24.0dB", "24.5dB", "25.0dB", "25.5dB", "26.0dB", "26.5dB",
8759 + "27.0dB", "27.5dB", "28.0dB", "28.5dB", "29.0dB", "29.5dB",
8760 + "30.0dB", "30.5dB", "31.0dB", "31.5dB", "32.0dB", "32.5dB",
8761 + "33.0dB", "33.5dB", "34.0dB", "34.5dB", "35.0dB", "35.5dB",
8762 + "36.0dB", "36.5dB", "37.0dB", "37.5dB", "38.0dB", "38.5dB",
8763 + "39.0dB", "39.5dB", "40.0dB"};
8764 +
8765 +static const struct soc_enum pcm186x_gain_sel[] = {
8766 + SOC_VALUE_ENUM_SINGLE(PCM186X_PGA_VAL_CH1_L, 0,
8767 + 0xff,
8768 + ARRAY_SIZE(pcm186x_gain_sel_text),
8769 + pcm186x_gain_sel_text,
8770 + pcm186x_gain_sel_value),
8771 + SOC_VALUE_ENUM_SINGLE(PCM186X_PGA_VAL_CH1_R, 0,
8772 + 0xff,
8773 + ARRAY_SIZE(pcm186x_gain_sel_text),
8774 + pcm186x_gain_sel_text,
8775 + pcm186x_gain_sel_value),
8776 +};
8777 +
8778 +static const struct snd_kcontrol_new pcm1863_snd_controls_card[] = {
8779 + SOC_ENUM("ADC Left Input", pcm186x_adc_input_channel_sel[0]),
8780 + SOC_ENUM("ADC Right Input", pcm186x_adc_input_channel_sel[1]),
8781 + SOC_ENUM("ADC Mic Bias", pcm186x_mic_bias_sel),
8782 + SOC_ENUM("PGA Gain Left", pcm186x_gain_sel[0]),
8783 + SOC_ENUM("PGA Gain Right", pcm186x_gain_sel[1]),
8784 +};
8785 +
8786 +static int pcm1863_add_controls(struct snd_soc_component *component)
8787 +{
8788 + snd_soc_add_component_controls(component,
8789 + pcm1863_snd_controls_card,
8790 + ARRAY_SIZE(pcm1863_snd_controls_card));
8791 + return 0;
8792 +}
8793 +
8794 +static void snd_rpi_hifiberry_dacplusadcpro_select_clk(
8795 + struct snd_soc_component *component, int clk_id)
8796 +{
8797 + switch (clk_id) {
8798 + case HIFIBERRY_DACPRO_NOCLOCK:
8799 + snd_soc_component_update_bits(component,
8800 + PCM512x_GPIO_CONTROL_1, 0x24, 0x00);
8801 + break;
8802 + case HIFIBERRY_DACPRO_CLK44EN:
8803 + snd_soc_component_update_bits(component,
8804 + PCM512x_GPIO_CONTROL_1, 0x24, 0x20);
8805 + break;
8806 + case HIFIBERRY_DACPRO_CLK48EN:
8807 + snd_soc_component_update_bits(component,
8808 + PCM512x_GPIO_CONTROL_1, 0x24, 0x04);
8809 + break;
8810 + }
8811 + usleep_range(3000, 4000);
8812 +}
8813 +
8814 +static void snd_rpi_hifiberry_dacplusadcpro_clk_gpio(struct snd_soc_component *component)
8815 +{
8816 + snd_soc_component_update_bits(component, PCM512x_GPIO_EN, 0x24, 0x24);
8817 + snd_soc_component_update_bits(component, PCM512x_GPIO_OUTPUT_3, 0x0f, 0x02);
8818 + snd_soc_component_update_bits(component, PCM512x_GPIO_OUTPUT_6, 0x0f, 0x02);
8819 +}
8820 +
8821 +static bool snd_rpi_hifiberry_dacplusadcpro_is_sclk(struct snd_soc_component *component)
8822 +{
8823 + unsigned int sck;
8824 +
8825 + sck = snd_soc_component_read(component, PCM512x_RATE_DET_4);
8826 + return (!(sck & 0x40));
8827 +}
8828 +
8829 +static bool snd_rpi_hifiberry_dacplusadcpro_is_pro_card(struct snd_soc_component *component)
8830 +{
8831 + bool isClk44EN, isClk48En, isNoClk;
8832 +
8833 + snd_rpi_hifiberry_dacplusadcpro_clk_gpio(component);
8834 +
8835 + snd_rpi_hifiberry_dacplusadcpro_select_clk(component, HIFIBERRY_DACPRO_CLK44EN);
8836 + isClk44EN = snd_rpi_hifiberry_dacplusadcpro_is_sclk(component);
8837 +
8838 + snd_rpi_hifiberry_dacplusadcpro_select_clk(component, HIFIBERRY_DACPRO_NOCLOCK);
8839 + isNoClk = snd_rpi_hifiberry_dacplusadcpro_is_sclk(component);
8840 +
8841 + snd_rpi_hifiberry_dacplusadcpro_select_clk(component, HIFIBERRY_DACPRO_CLK48EN);
8842 + isClk48En = snd_rpi_hifiberry_dacplusadcpro_is_sclk(component);
8843 +
8844 + return (isClk44EN && isClk48En && !isNoClk);
8845 +}
8846 +
8847 +static int snd_rpi_hifiberry_dacplusadcpro_clk_for_rate(int sample_rate)
8848 +{
8849 + int type;
8850 +
8851 + switch (sample_rate) {
8852 + case 11025:
8853 + case 22050:
8854 + case 44100:
8855 + case 88200:
8856 + case 176400:
8857 + case 352800:
8858 + type = HIFIBERRY_DACPRO_CLK44EN;
8859 + break;
8860 + default:
8861 + type = HIFIBERRY_DACPRO_CLK48EN;
8862 + break;
8863 + }
8864 + return type;
8865 +}
8866 +
8867 +static void snd_rpi_hifiberry_dacplusadcpro_set_sclk(struct snd_soc_component *component,
8868 + int sample_rate)
8869 +{
8870 + struct pcm512x_priv *pcm512x = snd_soc_component_get_drvdata(component);
8871 +
8872 + if (!IS_ERR(pcm512x->sclk)) {
8873 + int ctype;
8874 +
8875 + ctype = snd_rpi_hifiberry_dacplusadcpro_clk_for_rate(sample_rate);
8876 + clk_set_rate(pcm512x->sclk, (ctype == HIFIBERRY_DACPRO_CLK44EN)
8877 + ? CLK_44EN_RATE : CLK_48EN_RATE);
8878 + snd_rpi_hifiberry_dacplusadcpro_select_clk(component, ctype);
8879 + }
8880 +}
8881 +
8882 +static int snd_rpi_hifiberry_dacplusadcpro_init(struct snd_soc_pcm_runtime *rtd)
8883 +{
8884 + struct snd_soc_component *dac = asoc_rtd_to_codec(rtd, 0)->component;
8885 + struct snd_soc_component *adc = asoc_rtd_to_codec(rtd, 1)->component;
8886 + struct snd_soc_dai_driver *adc_driver = asoc_rtd_to_codec(rtd, 1)->driver;
8887 + struct pcm512x_priv *priv;
8888 + int ret;
8889 +
8890 + if (slave)
8891 + snd_rpi_hifiberry_is_dacpro = false;
8892 + else
8893 + snd_rpi_hifiberry_is_dacpro =
8894 + snd_rpi_hifiberry_dacplusadcpro_is_pro_card(dac);
8895 +
8896 + if (snd_rpi_hifiberry_is_dacpro) {
8897 + struct snd_soc_dai_link *dai = rtd->dai_link;
8898 +
8899 + dai->name = "HiFiBerry DAC+ADC Pro";
8900 + dai->stream_name = "HiFiBerry DAC+ADC Pro HiFi";
8901 + dai->dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
8902 + | SND_SOC_DAIFMT_CBM_CFM;
8903 +
8904 + // set DAC DAI configuration
8905 + ret = snd_soc_dai_set_fmt(asoc_rtd_to_codec(rtd, 0),
8906 + SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
8907 + | SND_SOC_DAIFMT_CBM_CFM);
8908 + if (ret < 0)
8909 + return ret;
8910 +
8911 + // set ADC DAI configuration
8912 + ret = snd_soc_dai_set_fmt(asoc_rtd_to_codec(rtd, 1),
8913 + SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
8914 + | SND_SOC_DAIFMT_CBS_CFS);
8915 + if (ret < 0)
8916 + return ret;
8917 +
8918 + // set CPU DAI configuration
8919 + ret = snd_soc_dai_set_fmt(asoc_rtd_to_cpu(rtd, 0),
8920 + SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
8921 + if (ret < 0)
8922 + return ret;
8923 +
8924 + snd_soc_component_update_bits(dac, PCM512x_BCLK_LRCLK_CFG, 0x31, 0x11);
8925 + snd_soc_component_update_bits(dac, PCM512x_MASTER_MODE, 0x03, 0x03);
8926 + snd_soc_component_update_bits(dac, PCM512x_MASTER_CLKDIV_2, 0x7f, 63);
8927 + } else {
8928 + priv = snd_soc_component_get_drvdata(dac);
8929 + priv->sclk = ERR_PTR(-ENOENT);
8930 + }
8931 +
8932 + /* disable 24bit mode as long as I2S module does not have sign extension fixed */
8933 + adc_driver->capture.formats = SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S16_LE;
8934 +
8935 + snd_soc_component_update_bits(dac, PCM512x_GPIO_EN, 0x08, 0x08);
8936 + snd_soc_component_update_bits(dac, PCM512x_GPIO_OUTPUT_4, 0x0f, 0x02);
8937 + if (leds_off)
8938 + snd_soc_component_update_bits(dac, PCM512x_GPIO_CONTROL_1, 0x08, 0x00);
8939 + else
8940 + snd_soc_component_update_bits(dac, PCM512x_GPIO_CONTROL_1, 0x08, 0x08);
8941 +
8942 + ret = pcm1863_add_controls(adc);
8943 + if (ret < 0)
8944 + dev_warn(rtd->dev, "Failed to add pcm1863 controls: %d\n",
8945 + ret);
8946 +
8947 + /* set GPIO2 to output, GPIO3 input */
8948 + snd_soc_component_write(adc, PCM186X_GPIO3_2_CTRL, 0x00);
8949 + snd_soc_component_write(adc, PCM186X_GPIO3_2_DIR_CTRL, 0x04);
8950 + if (leds_off)
8951 + snd_soc_component_update_bits(adc, PCM186X_GPIO_IN_OUT, 0x40, 0x00);
8952 + else
8953 + snd_soc_component_update_bits(adc, PCM186X_GPIO_IN_OUT, 0x40, 0x40);
8954 +
8955 + if (digital_gain_0db_limit) {
8956 + int ret;
8957 + struct snd_soc_card *card = rtd->card;
8958 +
8959 + ret = snd_soc_limit_volume(card, "Digital Playback Volume", 207);
8960 + if (ret < 0)
8961 + dev_warn(card->dev, "Failed to set volume limit: %d\n", ret);
8962 + }
8963 +
8964 + return 0;
8965 +}
8966 +
8967 +static int snd_rpi_hifiberry_dacplusadcpro_update_rate_den(
8968 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
8969 +{
8970 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
8971 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component; /* only use DAC */
8972 + struct pcm512x_priv *pcm512x = snd_soc_component_get_drvdata(component);
8973 + struct snd_ratnum *rats_no_pll;
8974 + unsigned int num = 0, den = 0;
8975 + int err;
8976 +
8977 + rats_no_pll = devm_kzalloc(rtd->dev, sizeof(*rats_no_pll), GFP_KERNEL);
8978 + if (!rats_no_pll)
8979 + return -ENOMEM;
8980 +
8981 + rats_no_pll->num = clk_get_rate(pcm512x->sclk) / 64;
8982 + rats_no_pll->den_min = 1;
8983 + rats_no_pll->den_max = 128;
8984 + rats_no_pll->den_step = 1;
8985 +
8986 + err = snd_interval_ratnum(hw_param_interval(params,
8987 + SNDRV_PCM_HW_PARAM_RATE), 1, rats_no_pll, &num, &den);
8988 + if (err >= 0 && den) {
8989 + params->rate_num = num;
8990 + params->rate_den = den;
8991 + }
8992 +
8993 + devm_kfree(rtd->dev, rats_no_pll);
8994 + return 0;
8995 +}
8996 +
8997 +static int snd_rpi_hifiberry_dacplusadcpro_hw_params(
8998 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
8999 +{
9000 + int ret = 0;
9001 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
9002 + int channels = params_channels(params);
9003 + int width = 32;
9004 + struct snd_soc_component *dac = asoc_rtd_to_codec(rtd, 0)->component;
9005 + struct snd_soc_dai *dai = asoc_rtd_to_codec(rtd, 0);
9006 + struct snd_soc_dai_driver *drv = dai->driver;
9007 + const struct snd_soc_dai_ops *ops = drv->ops;
9008 +
9009 + if (snd_rpi_hifiberry_is_dacpro) {
9010 + width = snd_pcm_format_physical_width(params_format(params));
9011 +
9012 + snd_rpi_hifiberry_dacplusadcpro_set_sclk(dac,
9013 + params_rate(params));
9014 +
9015 + ret = snd_rpi_hifiberry_dacplusadcpro_update_rate_den(
9016 + substream, params);
9017 + if (ret)
9018 + return ret;
9019 + }
9020 +
9021 + ret = snd_soc_dai_set_bclk_ratio(asoc_rtd_to_cpu(rtd, 0), channels * width);
9022 + if (ret)
9023 + return ret;
9024 + ret = snd_soc_dai_set_bclk_ratio(asoc_rtd_to_codec(rtd, 0), channels * width);
9025 + if (ret)
9026 + return ret;
9027 + if (snd_rpi_hifiberry_is_dacpro && ops->hw_params)
9028 + ret = ops->hw_params(substream, params, dai);
9029 + return ret;
9030 +}
9031 +
9032 +static int snd_rpi_hifiberry_dacplusadcpro_startup(
9033 + struct snd_pcm_substream *substream)
9034 +{
9035 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
9036 + struct snd_soc_component *dac = asoc_rtd_to_codec(rtd, 0)->component;
9037 + struct snd_soc_component *adc = asoc_rtd_to_codec(rtd, 1)->component;
9038 +
9039 + if (leds_off)
9040 + return 0;
9041 + /* switch on respective LED */
9042 + if (!substream->stream)
9043 + snd_soc_component_update_bits(dac, PCM512x_GPIO_CONTROL_1, 0x08, 0x08);
9044 + else
9045 + snd_soc_component_update_bits(adc, PCM186X_GPIO_IN_OUT, 0x40, 0x40);
9046 + return 0;
9047 +}
9048 +
9049 +static void snd_rpi_hifiberry_dacplusadcpro_shutdown(
9050 + struct snd_pcm_substream *substream)
9051 +{
9052 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
9053 + struct snd_soc_component *dac = asoc_rtd_to_codec(rtd, 0)->component;
9054 + struct snd_soc_component *adc = asoc_rtd_to_codec(rtd, 1)->component;
9055 +
9056 + /* switch off respective LED */
9057 + if (!substream->stream)
9058 + snd_soc_component_update_bits(dac, PCM512x_GPIO_CONTROL_1, 0x08, 0x00);
9059 + else
9060 + snd_soc_component_update_bits(adc, PCM186X_GPIO_IN_OUT, 0x40, 0x00);
9061 +}
9062 +
9063 +
9064 +/* machine stream operations */
9065 +static struct snd_soc_ops snd_rpi_hifiberry_dacplusadcpro_ops = {
9066 + .hw_params = snd_rpi_hifiberry_dacplusadcpro_hw_params,
9067 + .startup = snd_rpi_hifiberry_dacplusadcpro_startup,
9068 + .shutdown = snd_rpi_hifiberry_dacplusadcpro_shutdown,
9069 +};
9070 +
9071 +SND_SOC_DAILINK_DEFS(hifi,
9072 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
9073 + DAILINK_COMP_ARRAY(COMP_CODEC("pcm512x.1-004d", "pcm512x-hifi"),
9074 + COMP_CODEC("pcm186x.1-004a", "pcm1863-aif")),
9075 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
9076 +
9077 +static struct snd_soc_dai_link snd_rpi_hifiberry_dacplusadcpro_dai[] = {
9078 +{
9079 + .name = "HiFiBerry DAC+ADC PRO",
9080 + .stream_name = "HiFiBerry DAC+ADC PRO HiFi",
9081 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
9082 + SND_SOC_DAIFMT_CBS_CFS,
9083 + .ops = &snd_rpi_hifiberry_dacplusadcpro_ops,
9084 + .init = snd_rpi_hifiberry_dacplusadcpro_init,
9085 + SND_SOC_DAILINK_REG(hifi),
9086 +},
9087 +};
9088 +
9089 +/* audio machine driver */
9090 +static struct snd_soc_card snd_rpi_hifiberry_dacplusadcpro = {
9091 + .name = "snd_rpi_hifiberry_dacplusadcpro",
9092 + .driver_name = "HifiberryDacpAdcPro",
9093 + .owner = THIS_MODULE,
9094 + .dai_link = snd_rpi_hifiberry_dacplusadcpro_dai,
9095 + .num_links = ARRAY_SIZE(snd_rpi_hifiberry_dacplusadcpro_dai),
9096 +};
9097 +
9098 +static int snd_rpi_hifiberry_dacplusadcpro_probe(struct platform_device *pdev)
9099 +{
9100 + int ret = 0, i = 0;
9101 + struct snd_soc_card *card = &snd_rpi_hifiberry_dacplusadcpro;
9102 +
9103 + snd_rpi_hifiberry_dacplusadcpro.dev = &pdev->dev;
9104 + if (pdev->dev.of_node) {
9105 + struct device_node *i2s_node;
9106 + struct snd_soc_dai_link *dai;
9107 +
9108 + dai = &snd_rpi_hifiberry_dacplusadcpro_dai[0];
9109 + i2s_node = of_parse_phandle(pdev->dev.of_node,
9110 + "i2s-controller", 0);
9111 + if (i2s_node) {
9112 + for (i = 0; i < card->num_links; i++) {
9113 + dai->cpus->dai_name = NULL;
9114 + dai->cpus->of_node = i2s_node;
9115 + dai->platforms->name = NULL;
9116 + dai->platforms->of_node = i2s_node;
9117 + }
9118 + }
9119 + }
9120 + digital_gain_0db_limit = !of_property_read_bool(
9121 + pdev->dev.of_node, "hifiberry-dacplusadcpro,24db_digital_gain");
9122 + slave = of_property_read_bool(pdev->dev.of_node,
9123 + "hifiberry-dacplusadcpro,slave");
9124 + leds_off = of_property_read_bool(pdev->dev.of_node,
9125 + "hifiberry-dacplusadcpro,leds_off");
9126 + ret = snd_soc_register_card(&snd_rpi_hifiberry_dacplusadcpro);
9127 + if (ret && ret != -EPROBE_DEFER)
9128 + dev_err(&pdev->dev,
9129 + "snd_soc_register_card() failed: %d\n", ret);
9130 +
9131 + return ret;
9132 +}
9133 +
9134 +static const struct of_device_id snd_rpi_hifiberry_dacplusadcpro_of_match[] = {
9135 + { .compatible = "hifiberry,hifiberry-dacplusadcpro", },
9136 + {},
9137 +};
9138 +
9139 +MODULE_DEVICE_TABLE(of, snd_rpi_hifiberry_dacplusadcpro_of_match);
9140 +
9141 +static struct platform_driver snd_rpi_hifiberry_dacplusadcpro_driver = {
9142 + .driver = {
9143 + .name = "snd-rpi-hifiberry-dacplusadcpro",
9144 + .owner = THIS_MODULE,
9145 + .of_match_table = snd_rpi_hifiberry_dacplusadcpro_of_match,
9146 + },
9147 + .probe = snd_rpi_hifiberry_dacplusadcpro_probe,
9148 +};
9149 +
9150 +module_platform_driver(snd_rpi_hifiberry_dacplusadcpro_driver);
9151 +
9152 +MODULE_AUTHOR("Joerg Schambacher <joerg@i2audio.com>");
9153 +MODULE_AUTHOR("Daniel Matuschek <daniel@hifiberry.com>");
9154 +MODULE_DESCRIPTION("ASoC Driver for HiFiBerry DAC+ADC");
9155 +MODULE_LICENSE("GPL v2");
9156 --- /dev/null
9157 +++ b/sound/soc/bcm/hifiberry_dacplusdsp.c
9158 @@ -0,0 +1,90 @@
9159 +// SPDX-License-Identifier: GPL-2.0
9160 +/*
9161 + * ASoC Driver for HiFiBerry DAC + DSP
9162 + *
9163 + * Author: Joerg Schambacher <joscha@schambacher.com>
9164 + * Copyright 2018
9165 + *
9166 + * This program is free software; you can redistribute it and/or
9167 + * modify it under the terms of the GNU General Public License
9168 + * version 2 as published by the Free Software Foundation.
9169 + *
9170 + * This program is distributed in the hope that it will be useful, but
9171 + * WITHOUT ANY WARRANTY; without even the implied warranty of
9172 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9173 + * General Public License for more details.
9174 + */
9175 +
9176 +#include <linux/init.h>
9177 +#include <linux/module.h>
9178 +#include <linux/of.h>
9179 +#include <linux/platform_device.h>
9180 +#include <sound/soc.h>
9181 +
9182 +static struct snd_soc_component_driver dacplusdsp_component_driver;
9183 +
9184 +static struct snd_soc_dai_driver dacplusdsp_dai = {
9185 + .name = "dacplusdsp-hifi",
9186 + .capture = {
9187 + .stream_name = "DAC+DSP Capture",
9188 + .channels_min = 2,
9189 + .channels_max = 2,
9190 + .rates = SNDRV_PCM_RATE_CONTINUOUS,
9191 + .formats = SNDRV_PCM_FMTBIT_S16_LE |
9192 + SNDRV_PCM_FMTBIT_S24_LE |
9193 + SNDRV_PCM_FMTBIT_S32_LE,
9194 + },
9195 + .playback = {
9196 + .stream_name = "DACP+DSP Playback",
9197 + .channels_min = 2,
9198 + .channels_max = 2,
9199 + .rates = SNDRV_PCM_RATE_CONTINUOUS,
9200 + .formats = SNDRV_PCM_FMTBIT_S16_LE |
9201 + SNDRV_PCM_FMTBIT_S24_LE |
9202 + SNDRV_PCM_FMTBIT_S32_LE,
9203 + },
9204 + .symmetric_rate = 1};
9205 +
9206 +#ifdef CONFIG_OF
9207 +static const struct of_device_id dacplusdsp_ids[] = {
9208 + {
9209 + .compatible = "hifiberry,dacplusdsp",
9210 + },
9211 + {} };
9212 +MODULE_DEVICE_TABLE(of, dacplusdsp_ids);
9213 +#endif
9214 +
9215 +static int dacplusdsp_platform_probe(struct platform_device *pdev)
9216 +{
9217 + int ret;
9218 +
9219 + ret = snd_soc_register_component(&pdev->dev,
9220 + &dacplusdsp_component_driver, &dacplusdsp_dai, 1);
9221 + if (ret) {
9222 + pr_alert("snd_soc_register_component failed\n");
9223 + return ret;
9224 + }
9225 +
9226 + return 0;
9227 +}
9228 +
9229 +static int dacplusdsp_platform_remove(struct platform_device *pdev)
9230 +{
9231 + snd_soc_unregister_component(&pdev->dev);
9232 + return 0;
9233 +}
9234 +
9235 +static struct platform_driver dacplusdsp_driver = {
9236 + .driver = {
9237 + .name = "hifiberry-dacplusdsp-codec",
9238 + .of_match_table = of_match_ptr(dacplusdsp_ids),
9239 + },
9240 + .probe = dacplusdsp_platform_probe,
9241 + .remove = dacplusdsp_platform_remove,
9242 +};
9243 +
9244 +module_platform_driver(dacplusdsp_driver);
9245 +
9246 +MODULE_AUTHOR("Joerg Schambacher <joerg@i2audio.com>");
9247 +MODULE_DESCRIPTION("ASoC Driver for HiFiBerry DAC+DSP");
9248 +MODULE_LICENSE("GPL v2");
9249 --- /dev/null
9250 +++ b/sound/soc/bcm/hifiberry_dacplushd.c
9251 @@ -0,0 +1,238 @@
9252 +// SPDX-License-Identifier: GPL-2.0
9253 +/*
9254 + * ASoC Driver for HiFiBerry DAC+ HD
9255 + *
9256 + * Author: Joerg Schambacher, i2Audio GmbH for HiFiBerry
9257 + * Copyright 2020
9258 + *
9259 + * This program is free software; you can redistribute it and/or
9260 + * modify it under the terms of the GNU General Public License
9261 + * version 2 as published by the Free Software Foundation.
9262 + *
9263 + * This program is distributed in the hope that it will be useful, but
9264 + * WITHOUT ANY WARRANTY; without even the implied warranty of
9265 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9266 + * General Public License for more details.
9267 + */
9268 +
9269 +#include <linux/module.h>
9270 +#include <linux/platform_device.h>
9271 +#include <linux/kernel.h>
9272 +#include <linux/delay.h>
9273 +#include <linux/module.h>
9274 +#include <linux/of.h>
9275 +#include <linux/delay.h>
9276 +#include <linux/gpio.h>
9277 +#include <linux/gpio/consumer.h>
9278 +#include <sound/core.h>
9279 +#include <sound/pcm.h>
9280 +#include <sound/pcm_params.h>
9281 +#include <sound/soc.h>
9282 +#include <linux/i2c.h>
9283 +#include <linux/clk.h>
9284 +
9285 +#include "../codecs/pcm179x.h"
9286 +
9287 +#define DEFAULT_RATE 44100
9288 +
9289 +struct brd_drv_data {
9290 + struct regmap *regmap;
9291 + struct clk *sclk;
9292 +};
9293 +
9294 +static struct brd_drv_data drvdata;
9295 +static struct gpio_desc *reset_gpio;
9296 +static const unsigned int hb_dacplushd_rates[] = {
9297 + 192000, 96000, 48000, 176400, 88200, 44100,
9298 +};
9299 +
9300 +static struct snd_pcm_hw_constraint_list hb_dacplushd_constraints = {
9301 + .list = hb_dacplushd_rates,
9302 + .count = ARRAY_SIZE(hb_dacplushd_rates),
9303 +};
9304 +
9305 +static int snd_rpi_hb_dacplushd_startup(struct snd_pcm_substream *substream)
9306 +{
9307 + /* constraints for standard sample rates */
9308 + snd_pcm_hw_constraint_list(substream->runtime, 0,
9309 + SNDRV_PCM_HW_PARAM_RATE,
9310 + &hb_dacplushd_constraints);
9311 + return 0;
9312 +}
9313 +
9314 +static void snd_rpi_hifiberry_dacplushd_set_sclk(
9315 + struct snd_soc_component *component,
9316 + int sample_rate)
9317 +{
9318 + if (!IS_ERR(drvdata.sclk))
9319 + clk_set_rate(drvdata.sclk, sample_rate);
9320 +}
9321 +
9322 +static int snd_rpi_hifiberry_dacplushd_init(struct snd_soc_pcm_runtime *rtd)
9323 +{
9324 + struct snd_soc_dai_link *dai = rtd->dai_link;
9325 + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
9326 +
9327 + dai->name = "HiFiBerry DAC+ HD";
9328 + dai->stream_name = "HiFiBerry DAC+ HD HiFi";
9329 + dai->dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
9330 + | SND_SOC_DAIFMT_CBM_CFM;
9331 +
9332 + /* allow only fixed 32 clock counts per channel */
9333 + snd_soc_dai_set_bclk_ratio(cpu_dai, 32*2);
9334 +
9335 + return 0;
9336 +}
9337 +
9338 +static int snd_rpi_hifiberry_dacplushd_hw_params(
9339 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
9340 +{
9341 + int ret = 0;
9342 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
9343 +
9344 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
9345 +
9346 + snd_rpi_hifiberry_dacplushd_set_sclk(component, params_rate(params));
9347 + return ret;
9348 +}
9349 +
9350 +/* machine stream operations */
9351 +static struct snd_soc_ops snd_rpi_hifiberry_dacplushd_ops = {
9352 + .startup = snd_rpi_hb_dacplushd_startup,
9353 + .hw_params = snd_rpi_hifiberry_dacplushd_hw_params,
9354 +};
9355 +
9356 +SND_SOC_DAILINK_DEFS(hifi,
9357 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
9358 + DAILINK_COMP_ARRAY(COMP_CODEC("pcm179x.1-004c", "pcm179x-hifi")),
9359 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
9360 +
9361 +
9362 +static struct snd_soc_dai_link snd_rpi_hifiberry_dacplushd_dai[] = {
9363 +{
9364 + .name = "HiFiBerry DAC+ HD",
9365 + .stream_name = "HiFiBerry DAC+ HD HiFi",
9366 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
9367 + SND_SOC_DAIFMT_CBS_CFS,
9368 + .ops = &snd_rpi_hifiberry_dacplushd_ops,
9369 + .init = snd_rpi_hifiberry_dacplushd_init,
9370 + SND_SOC_DAILINK_REG(hifi),
9371 +},
9372 +};
9373 +
9374 +/* audio machine driver */
9375 +static struct snd_soc_card snd_rpi_hifiberry_dacplushd = {
9376 + .name = "snd_rpi_hifiberry_dacplushd",
9377 + .driver_name = "HifiberryDacplusHD",
9378 + .owner = THIS_MODULE,
9379 + .dai_link = snd_rpi_hifiberry_dacplushd_dai,
9380 + .num_links = ARRAY_SIZE(snd_rpi_hifiberry_dacplushd_dai),
9381 +};
9382 +
9383 +static int snd_rpi_hifiberry_dacplushd_probe(struct platform_device *pdev)
9384 +{
9385 + int ret = 0;
9386 + static int dac_reset_done;
9387 + struct device *dev = &pdev->dev;
9388 + struct device_node *dev_node = dev->of_node;
9389 +
9390 + snd_rpi_hifiberry_dacplushd.dev = &pdev->dev;
9391 +
9392 + /* get GPIO and release DAC from RESET */
9393 + if (!dac_reset_done) {
9394 + reset_gpio = gpiod_get(&pdev->dev, "reset", GPIOD_OUT_LOW);
9395 + if (IS_ERR(reset_gpio)) {
9396 + dev_err(&pdev->dev, "gpiod_get() failed\n");
9397 + return -EINVAL;
9398 + }
9399 + dac_reset_done = 1;
9400 + }
9401 + if (!IS_ERR(reset_gpio))
9402 + gpiod_set_value(reset_gpio, 0);
9403 + msleep(1);
9404 + if (!IS_ERR(reset_gpio))
9405 + gpiod_set_value(reset_gpio, 1);
9406 + msleep(1);
9407 + if (!IS_ERR(reset_gpio))
9408 + gpiod_set_value(reset_gpio, 0);
9409 +
9410 + if (pdev->dev.of_node) {
9411 + struct device_node *i2s_node;
9412 + struct snd_soc_dai_link *dai;
9413 +
9414 + dai = &snd_rpi_hifiberry_dacplushd_dai[0];
9415 + i2s_node = of_parse_phandle(pdev->dev.of_node,
9416 + "i2s-controller", 0);
9417 +
9418 + if (i2s_node) {
9419 + dai->cpus->of_node = i2s_node;
9420 + dai->platforms->of_node = i2s_node;
9421 + dai->cpus->dai_name = NULL;
9422 + dai->platforms->name = NULL;
9423 + } else {
9424 + return -EPROBE_DEFER;
9425 + }
9426 +
9427 + }
9428 +
9429 + ret = devm_snd_soc_register_card(&pdev->dev,
9430 + &snd_rpi_hifiberry_dacplushd);
9431 + if (ret && ret != -EPROBE_DEFER) {
9432 + dev_err(&pdev->dev,
9433 + "snd_soc_register_card() failed: %d\n", ret);
9434 + return ret;
9435 + }
9436 + if (ret == -EPROBE_DEFER)
9437 + return ret;
9438 +
9439 + dev_set_drvdata(dev, &drvdata);
9440 + if (dev_node == NULL) {
9441 + dev_err(&pdev->dev, "Device tree node not found\n");
9442 + return -ENODEV;
9443 + }
9444 +
9445 + drvdata.sclk = devm_clk_get(dev, NULL);
9446 + if (IS_ERR(drvdata.sclk)) {
9447 + drvdata.sclk = ERR_PTR(-ENOENT);
9448 + return -ENODEV;
9449 + }
9450 +
9451 + clk_set_rate(drvdata.sclk, DEFAULT_RATE);
9452 +
9453 + return ret;
9454 +}
9455 +
9456 +static int snd_rpi_hifiberry_dacplushd_remove(struct platform_device *pdev)
9457 +{
9458 + if (IS_ERR(reset_gpio))
9459 + return -EINVAL;
9460 +
9461 + /* put DAC into RESET and release GPIO */
9462 + gpiod_set_value(reset_gpio, 0);
9463 + gpiod_put(reset_gpio);
9464 +
9465 + return 0;
9466 +}
9467 +
9468 +static const struct of_device_id snd_rpi_hifiberry_dacplushd_of_match[] = {
9469 + { .compatible = "hifiberry,hifiberry-dacplushd", },
9470 + {},
9471 +};
9472 +
9473 +MODULE_DEVICE_TABLE(of, snd_rpi_hifiberry_dacplushd_of_match);
9474 +
9475 +static struct platform_driver snd_rpi_hifiberry_dacplushd_driver = {
9476 + .driver = {
9477 + .name = "snd-rpi-hifiberry-dacplushd",
9478 + .owner = THIS_MODULE,
9479 + .of_match_table = snd_rpi_hifiberry_dacplushd_of_match,
9480 + },
9481 + .probe = snd_rpi_hifiberry_dacplushd_probe,
9482 + .remove = snd_rpi_hifiberry_dacplushd_remove,
9483 +};
9484 +
9485 +module_platform_driver(snd_rpi_hifiberry_dacplushd_driver);
9486 +
9487 +MODULE_AUTHOR("Joerg Schambacher <joerg@i2audio.com>");
9488 +MODULE_DESCRIPTION("ASoC Driver for HiFiBerry DAC+ HD");
9489 +MODULE_LICENSE("GPL v2");
9490 --- /dev/null
9491 +++ b/sound/soc/bcm/i-sabre-q2m.c
9492 @@ -0,0 +1,158 @@
9493 +/*
9494 + * ASoC Driver for I-Sabre Q2M
9495 + *
9496 + * Author: Satoru Kawase
9497 + * Modified by: Xiao Qingyong
9498 + * Update kernel v4.18+ by : Audiophonics
9499 + * Copyright 2018 Audiophonics
9500 + *
9501 + * This program is free software; you can redistribute it and/or
9502 + * modify it under the terms of the GNU General Public License
9503 + * version 2 as published by the Free Software Foundation.
9504 + *
9505 + * This program is distributed in the hope that it will be useful, but
9506 + * WITHOUT ANY WARRANTY; without even the implied warranty of
9507 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9508 + * General Public License for more details.
9509 + */
9510 +
9511 +#include <linux/kernel.h>
9512 +#include <linux/init.h>
9513 +#include <linux/module.h>
9514 +#include <linux/delay.h>
9515 +#include <linux/fs.h>
9516 +#include <asm/uaccess.h>
9517 +#include <sound/core.h>
9518 +#include <sound/soc.h>
9519 +#include <sound/pcm.h>
9520 +#include <sound/pcm_params.h>
9521 +
9522 +#include "../codecs/i-sabre-codec.h"
9523 +
9524 +
9525 +static int snd_rpi_i_sabre_q2m_init(struct snd_soc_pcm_runtime *rtd)
9526 +{
9527 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
9528 + unsigned int value;
9529 +
9530 + /* Device ID */
9531 + value = snd_soc_component_read(component, ISABRECODEC_REG_01);
9532 + dev_info(component->card->dev, "Audiophonics Device ID : %02X\n", value);
9533 +
9534 + /* API revision */
9535 + value = snd_soc_component_read(component, ISABRECODEC_REG_02);
9536 + dev_info(component->card->dev, "Audiophonics API revision : %02X\n", value);
9537 +
9538 + return 0;
9539 +}
9540 +
9541 +static int snd_rpi_i_sabre_q2m_hw_params(
9542 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
9543 +{
9544 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
9545 + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
9546 + int bclk_ratio;
9547 +
9548 + bclk_ratio = snd_pcm_format_physical_width(
9549 + params_format(params)) * params_channels(params);
9550 + return snd_soc_dai_set_bclk_ratio(cpu_dai, bclk_ratio);
9551 +}
9552 +
9553 +/* machine stream operations */
9554 +static struct snd_soc_ops snd_rpi_i_sabre_q2m_ops = {
9555 + .hw_params = snd_rpi_i_sabre_q2m_hw_params,
9556 +};
9557 +
9558 +SND_SOC_DAILINK_DEFS(rpi_i_sabre_q2m,
9559 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
9560 + DAILINK_COMP_ARRAY(COMP_CODEC("i-sabre-codec-i2c.1-0048", "i-sabre-codec-dai")),
9561 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
9562 +
9563 +static struct snd_soc_dai_link snd_rpi_i_sabre_q2m_dai[] = {
9564 + {
9565 + .name = "I-Sabre Q2M",
9566 + .stream_name = "I-Sabre Q2M DAC",
9567 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
9568 + | SND_SOC_DAIFMT_CBS_CFS,
9569 + .init = snd_rpi_i_sabre_q2m_init,
9570 + .ops = &snd_rpi_i_sabre_q2m_ops,
9571 + SND_SOC_DAILINK_REG(rpi_i_sabre_q2m),
9572 + }
9573 +};
9574 +
9575 +/* audio machine driver */
9576 +static struct snd_soc_card snd_rpi_i_sabre_q2m = {
9577 + .name = "I-Sabre Q2M DAC",
9578 + .owner = THIS_MODULE,
9579 + .dai_link = snd_rpi_i_sabre_q2m_dai,
9580 + .num_links = ARRAY_SIZE(snd_rpi_i_sabre_q2m_dai)
9581 +};
9582 +
9583 +
9584 +static int snd_rpi_i_sabre_q2m_probe(struct platform_device *pdev)
9585 +{
9586 + int ret = 0;
9587 +
9588 + snd_rpi_i_sabre_q2m.dev = &pdev->dev;
9589 + if (pdev->dev.of_node) {
9590 + struct device_node *i2s_node;
9591 + struct snd_soc_dai_link *dai;
9592 +
9593 + dai = &snd_rpi_i_sabre_q2m_dai[0];
9594 + i2s_node = of_parse_phandle(pdev->dev.of_node,
9595 + "i2s-controller", 0);
9596 + if (i2s_node) {
9597 + dai->cpus->dai_name = NULL;
9598 + dai->cpus->of_node = i2s_node;
9599 + dai->platforms->name = NULL;
9600 + dai->platforms->of_node = i2s_node;
9601 + } else {
9602 + dev_err(&pdev->dev,
9603 + "Property 'i2s-controller' missing or invalid\n");
9604 + return (-EINVAL);
9605 + }
9606 +
9607 + dai->name = "I-Sabre Q2M";
9608 + dai->stream_name = "I-Sabre Q2M DAC";
9609 + dai->dai_fmt = SND_SOC_DAIFMT_I2S
9610 + | SND_SOC_DAIFMT_NB_NF
9611 + | SND_SOC_DAIFMT_CBS_CFS;
9612 + }
9613 +
9614 + /* Wait for registering codec driver */
9615 + mdelay(50);
9616 +
9617 + ret = snd_soc_register_card(&snd_rpi_i_sabre_q2m);
9618 + if (ret) {
9619 + dev_err(&pdev->dev,
9620 + "snd_soc_register_card() failed: %d\n", ret);
9621 + }
9622 +
9623 + return ret;
9624 +}
9625 +
9626 +static int snd_rpi_i_sabre_q2m_remove(struct platform_device *pdev)
9627 +{
9628 + return snd_soc_unregister_card(&snd_rpi_i_sabre_q2m);
9629 +}
9630 +
9631 +static const struct of_device_id snd_rpi_i_sabre_q2m_of_match[] = {
9632 + { .compatible = "audiophonics,i-sabre-q2m", },
9633 + {}
9634 +};
9635 +MODULE_DEVICE_TABLE(of, snd_rpi_i_sabre_q2m_of_match);
9636 +
9637 +static struct platform_driver snd_rpi_i_sabre_q2m_driver = {
9638 + .driver = {
9639 + .name = "snd-rpi-i-sabre-q2m",
9640 + .owner = THIS_MODULE,
9641 + .of_match_table = snd_rpi_i_sabre_q2m_of_match,
9642 + },
9643 + .probe = snd_rpi_i_sabre_q2m_probe,
9644 + .remove = snd_rpi_i_sabre_q2m_remove,
9645 +};
9646 +module_platform_driver(snd_rpi_i_sabre_q2m_driver);
9647 +
9648 +MODULE_DESCRIPTION("ASoC Driver for I-Sabre Q2M");
9649 +MODULE_AUTHOR("Audiophonics <http://www.audiophonics.fr>");
9650 +MODULE_LICENSE("GPL");
9651 --- /dev/null
9652 +++ b/sound/soc/bcm/iqaudio-codec.c
9653 @@ -0,0 +1,274 @@
9654 +/*
9655 + * ASoC Driver for IQaudIO Raspberry Pi Codec board
9656 + *
9657 + * Author: Gordon Garrity <gordon@iqaudio.com>
9658 + * (C) Copyright IQaudio Limited, 2017-2019
9659 + *
9660 + * This program is free software; you can redistribute it and/or
9661 + * modify it under the terms of the GNU General Public License
9662 + * version 2 as published by the Free Software Foundation.
9663 + *
9664 + * This program is distributed in the hope that it will be useful, but
9665 + * WITHOUT ANY WARRANTY; without even the implied warranty of
9666 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9667 + * General Public License for more details.
9668 + */
9669 +
9670 +#include <linux/module.h>
9671 +#include <linux/gpio/consumer.h>
9672 +#include <linux/platform_device.h>
9673 +
9674 +#include <sound/core.h>
9675 +#include <sound/pcm.h>
9676 +#include <sound/pcm_params.h>
9677 +#include <sound/soc.h>
9678 +#include <sound/jack.h>
9679 +
9680 +#include <linux/acpi.h>
9681 +#include <linux/slab.h>
9682 +#include "../codecs/da7213.h"
9683 +
9684 +static int pll_out = DA7213_PLL_FREQ_OUT_90316800;
9685 +
9686 +static int snd_rpi_iqaudio_pll_control(struct snd_soc_dapm_widget *w,
9687 + struct snd_kcontrol *k, int event)
9688 +{
9689 + int ret = 0;
9690 + struct snd_soc_dapm_context *dapm = w->dapm;
9691 + struct snd_soc_card *card = dapm->card;
9692 + struct snd_soc_pcm_runtime *rtd =
9693 + snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
9694 + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
9695 +
9696 + if (SND_SOC_DAPM_EVENT_OFF(event)) {
9697 + ret = snd_soc_dai_set_pll(codec_dai, 0, DA7213_SYSCLK_MCLK, 0,
9698 + 0);
9699 + if (ret)
9700 + dev_err(card->dev, "Failed to bypass PLL: %d\n", ret);
9701 + /* Allow PLL time to bypass */
9702 + msleep(100);
9703 + } else if (SND_SOC_DAPM_EVENT_ON(event)) {
9704 + ret = snd_soc_dai_set_pll(codec_dai, 0, DA7213_SYSCLK_PLL, 0,
9705 + pll_out);
9706 + if (ret)
9707 + dev_err(card->dev, "Failed to enable PLL: %d\n", ret);
9708 + /* Allow PLL time to lock */
9709 + msleep(100);
9710 + }
9711 +
9712 + return ret;
9713 +}
9714 +
9715 +static int snd_rpi_iqaudio_post_dapm_event(struct snd_soc_dapm_widget *w,
9716 + struct snd_kcontrol *kcontrol,
9717 + int event)
9718 +{
9719 + switch (event) {
9720 + case SND_SOC_DAPM_POST_PMU:
9721 + /* Delay for mic bias ramp */
9722 + msleep(1000);
9723 + break;
9724 + default:
9725 + break;
9726 + }
9727 +
9728 + return 0;
9729 +}
9730 +
9731 +static const struct snd_kcontrol_new dapm_controls[] = {
9732 + SOC_DAPM_PIN_SWITCH("HP Jack"),
9733 + SOC_DAPM_PIN_SWITCH("MIC Jack"),
9734 + SOC_DAPM_PIN_SWITCH("Onboard MIC"),
9735 + SOC_DAPM_PIN_SWITCH("AUX Jack"),
9736 +};
9737 +
9738 +static const struct snd_soc_dapm_widget dapm_widgets[] = {
9739 + SND_SOC_DAPM_HP("HP Jack", NULL),
9740 + SND_SOC_DAPM_MIC("MIC Jack", NULL),
9741 + SND_SOC_DAPM_MIC("Onboard MIC", NULL),
9742 + SND_SOC_DAPM_LINE("AUX Jack", NULL),
9743 + SND_SOC_DAPM_SUPPLY("PLL Control", SND_SOC_NOPM, 0, 0,
9744 + snd_rpi_iqaudio_pll_control,
9745 + SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
9746 + SND_SOC_DAPM_POST("Post Power Up Event", snd_rpi_iqaudio_post_dapm_event),
9747 +};
9748 +
9749 +static const struct snd_soc_dapm_route audio_map[] = {
9750 + {"HP Jack", NULL, "HPL"},
9751 + {"HP Jack", NULL, "HPR"},
9752 + {"HP Jack", NULL, "PLL Control"},
9753 +
9754 + {"AUXR", NULL, "AUX Jack"},
9755 + {"AUXL", NULL, "AUX Jack"},
9756 + {"AUX Jack", NULL, "PLL Control"},
9757 +
9758 + /* Assume Mic1 is linked to Headset and Mic2 to on-board mic */
9759 + {"MIC1", NULL, "MIC Jack"},
9760 + {"MIC Jack", NULL, "PLL Control"},
9761 + {"MIC2", NULL, "Onboard MIC"},
9762 + {"Onboard MIC", NULL, "PLL Control"},
9763 +};
9764 +
9765 +/* machine stream operations */
9766 +
9767 +static int snd_rpi_iqaudio_codec_init(struct snd_soc_pcm_runtime *rtd)
9768 +{
9769 + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
9770 + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
9771 + int ret;
9772 +
9773 + /*
9774 + * Disable AUX Jack Pin by default to prevent PLL being enabled at
9775 + * startup. This avoids holding the PLL to a fixed SR config for
9776 + * subsequent streams.
9777 + *
9778 + * This pin can still be enabled later, as required by user-space.
9779 + */
9780 + snd_soc_dapm_disable_pin(&rtd->card->dapm, "AUX Jack");
9781 + snd_soc_dapm_sync(&rtd->card->dapm);
9782 +
9783 + /* Set bclk ratio to align with codec's BCLK rate */
9784 + ret = snd_soc_dai_set_bclk_ratio(cpu_dai, 64);
9785 + if (ret) {
9786 + dev_err(rtd->dev, "Failed to set CPU BLCK ratio\n");
9787 + return ret;
9788 + }
9789 +
9790 + /* Set MCLK frequency to codec, onboard 11.2896MHz clock */
9791 + return snd_soc_dai_set_sysclk(codec_dai, DA7213_CLKSRC_MCLK, 11289600,
9792 + SND_SOC_CLOCK_OUT);
9793 +}
9794 +
9795 +static int snd_rpi_iqaudio_codec_hw_params(struct snd_pcm_substream *substream,
9796 + struct snd_pcm_hw_params *params)
9797 +{
9798 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
9799 + unsigned int samplerate = params_rate(params);
9800 +
9801 + switch (samplerate) {
9802 + case 8000:
9803 + case 16000:
9804 + case 32000:
9805 + case 48000:
9806 + case 96000:
9807 + pll_out = DA7213_PLL_FREQ_OUT_98304000;
9808 + return 0;
9809 + case 44100:
9810 + case 88200:
9811 + pll_out = DA7213_PLL_FREQ_OUT_90316800;
9812 + return 0;
9813 + default:
9814 + dev_err(rtd->dev,"Unsupported samplerate %d\n", samplerate);
9815 + return -EINVAL;
9816 + }
9817 +}
9818 +
9819 +static const struct snd_soc_ops snd_rpi_iqaudio_codec_ops = {
9820 + .hw_params = snd_rpi_iqaudio_codec_hw_params,
9821 +};
9822 +
9823 +SND_SOC_DAILINK_DEFS(rpi_iqaudio,
9824 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
9825 + DAILINK_COMP_ARRAY(COMP_CODEC("da7213.1-001a", "da7213-hifi")),
9826 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2835-i2s.0")));
9827 +
9828 +static struct snd_soc_dai_link snd_rpi_iqaudio_codec_dai[] = {
9829 +{
9830 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
9831 + SND_SOC_DAIFMT_CBM_CFM,
9832 + .init = snd_rpi_iqaudio_codec_init,
9833 + .ops = &snd_rpi_iqaudio_codec_ops,
9834 + .symmetric_rate = 1,
9835 + .symmetric_channels = 1,
9836 + .symmetric_sample_bits = 1,
9837 + SND_SOC_DAILINK_REG(rpi_iqaudio),
9838 +},
9839 +};
9840 +
9841 +/* audio machine driver */
9842 +static struct snd_soc_card snd_rpi_iqaudio_codec = {
9843 + .owner = THIS_MODULE,
9844 + .dai_link = snd_rpi_iqaudio_codec_dai,
9845 + .num_links = ARRAY_SIZE(snd_rpi_iqaudio_codec_dai),
9846 + .controls = dapm_controls,
9847 + .num_controls = ARRAY_SIZE(dapm_controls),
9848 + .dapm_widgets = dapm_widgets,
9849 + .num_dapm_widgets = ARRAY_SIZE(dapm_widgets),
9850 + .dapm_routes = audio_map,
9851 + .num_dapm_routes = ARRAY_SIZE(audio_map),
9852 +};
9853 +
9854 +static int snd_rpi_iqaudio_codec_probe(struct platform_device *pdev)
9855 +{
9856 + int ret = 0;
9857 +
9858 + snd_rpi_iqaudio_codec.dev = &pdev->dev;
9859 +
9860 + if (pdev->dev.of_node) {
9861 + struct device_node *i2s_node;
9862 + struct snd_soc_card *card = &snd_rpi_iqaudio_codec;
9863 + struct snd_soc_dai_link *dai = &snd_rpi_iqaudio_codec_dai[0];
9864 +
9865 + i2s_node = of_parse_phandle(pdev->dev.of_node,
9866 + "i2s-controller", 0);
9867 + if (i2s_node) {
9868 + dai->cpus->dai_name = NULL;
9869 + dai->cpus->of_node = i2s_node;
9870 + dai->platforms->name = NULL;
9871 + dai->platforms->of_node = i2s_node;
9872 + }
9873 +
9874 + if (of_property_read_string(pdev->dev.of_node, "card_name",
9875 + &card->name))
9876 + card->name = "IQaudIOCODEC";
9877 +
9878 + if (of_property_read_string(pdev->dev.of_node, "dai_name",
9879 + &dai->name))
9880 + dai->name = "IQaudIO CODEC";
9881 +
9882 + if (of_property_read_string(pdev->dev.of_node,
9883 + "dai_stream_name", &dai->stream_name))
9884 + dai->stream_name = "IQaudIO CODEC HiFi v1.2";
9885 +
9886 + }
9887 +
9888 + ret = snd_soc_register_card(&snd_rpi_iqaudio_codec);
9889 + if (ret) {
9890 + if (ret != -EPROBE_DEFER)
9891 + dev_err(&pdev->dev,
9892 + "snd_soc_register_card() failed: %d\n", ret);
9893 + return ret;
9894 + }
9895 +
9896 + return 0;
9897 +}
9898 +
9899 +static int snd_rpi_iqaudio_codec_remove(struct platform_device *pdev)
9900 +{
9901 + return snd_soc_unregister_card(&snd_rpi_iqaudio_codec);
9902 +}
9903 +
9904 +static const struct of_device_id iqaudio_of_match[] = {
9905 + { .compatible = "iqaudio,iqaudio-codec", },
9906 + {},
9907 +};
9908 +
9909 +MODULE_DEVICE_TABLE(of, iqaudio_of_match);
9910 +
9911 +static struct platform_driver snd_rpi_iqaudio_codec_driver = {
9912 + .driver = {
9913 + .name = "snd-rpi-iqaudio-codec",
9914 + .owner = THIS_MODULE,
9915 + .of_match_table = iqaudio_of_match,
9916 + },
9917 + .probe = snd_rpi_iqaudio_codec_probe,
9918 + .remove = snd_rpi_iqaudio_codec_remove,
9919 +};
9920 +
9921 +
9922 +
9923 +module_platform_driver(snd_rpi_iqaudio_codec_driver);
9924 +
9925 +MODULE_AUTHOR("Gordon Garrity <gordon@iqaudio.com>");
9926 +MODULE_DESCRIPTION("ASoC Driver for IQaudIO CODEC");
9927 +MODULE_LICENSE("GPL v2");
9928 --- /dev/null
9929 +++ b/sound/soc/bcm/iqaudio-dac.c
9930 @@ -0,0 +1,223 @@
9931 +/*
9932 + * ASoC Driver for IQaudIO DAC
9933 + *
9934 + * Author: Florian Meier <florian.meier@koalo.de>
9935 + * Copyright 2013
9936 + *
9937 + * This program is free software; you can redistribute it and/or
9938 + * modify it under the terms of the GNU General Public License
9939 + * version 2 as published by the Free Software Foundation.
9940 + *
9941 + * This program is distributed in the hope that it will be useful, but
9942 + * WITHOUT ANY WARRANTY; without even the implied warranty of
9943 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9944 + * General Public License for more details.
9945 + */
9946 +
9947 +#include <linux/module.h>
9948 +#include <linux/gpio/consumer.h>
9949 +#include <linux/platform_device.h>
9950 +
9951 +#include <sound/core.h>
9952 +#include <sound/pcm.h>
9953 +#include <sound/pcm_params.h>
9954 +#include <sound/soc.h>
9955 +#include <sound/jack.h>
9956 +
9957 +static bool digital_gain_0db_limit = true;
9958 +
9959 +static struct gpio_desc *mute_gpio;
9960 +
9961 +static int snd_rpi_iqaudio_dac_init(struct snd_soc_pcm_runtime *rtd)
9962 +{
9963 + if (digital_gain_0db_limit)
9964 + {
9965 + int ret;
9966 + struct snd_soc_card *card = rtd->card;
9967 +
9968 + ret = snd_soc_limit_volume(card, "Digital Playback Volume", 207);
9969 + if (ret < 0)
9970 + dev_warn(card->dev, "Failed to set volume limit: %d\n", ret);
9971 + }
9972 +
9973 + return 0;
9974 +}
9975 +
9976 +static void snd_rpi_iqaudio_gpio_mute(struct snd_soc_card *card)
9977 +{
9978 + if (mute_gpio) {
9979 + dev_info(card->dev, "%s: muting amp using GPIO22\n",
9980 + __func__);
9981 + gpiod_set_value_cansleep(mute_gpio, 0);
9982 + }
9983 +}
9984 +
9985 +static void snd_rpi_iqaudio_gpio_unmute(struct snd_soc_card *card)
9986 +{
9987 + if (mute_gpio) {
9988 + dev_info(card->dev, "%s: un-muting amp using GPIO22\n",
9989 + __func__);
9990 + gpiod_set_value_cansleep(mute_gpio, 1);
9991 + }
9992 +}
9993 +
9994 +static int snd_rpi_iqaudio_set_bias_level(struct snd_soc_card *card,
9995 + struct snd_soc_dapm_context *dapm, enum snd_soc_bias_level level)
9996 +{
9997 + struct snd_soc_pcm_runtime *rtd;
9998 + struct snd_soc_dai *codec_dai;
9999 +
10000 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
10001 + codec_dai = asoc_rtd_to_codec(rtd, 0);
10002 +
10003 + if (dapm->dev != codec_dai->dev)
10004 + return 0;
10005 +
10006 + switch (level) {
10007 + case SND_SOC_BIAS_PREPARE:
10008 + if (dapm->bias_level != SND_SOC_BIAS_STANDBY)
10009 + break;
10010 +
10011 + /* UNMUTE AMP */
10012 + snd_rpi_iqaudio_gpio_unmute(card);
10013 +
10014 + break;
10015 + case SND_SOC_BIAS_STANDBY:
10016 + if (dapm->bias_level != SND_SOC_BIAS_PREPARE)
10017 + break;
10018 +
10019 + /* MUTE AMP */
10020 + snd_rpi_iqaudio_gpio_mute(card);
10021 +
10022 + break;
10023 + default:
10024 + break;
10025 + }
10026 +
10027 + return 0;
10028 +}
10029 +
10030 +SND_SOC_DAILINK_DEFS(hifi,
10031 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
10032 + DAILINK_COMP_ARRAY(COMP_CODEC("pcm512x.1-004c", "pcm512x-hifi")),
10033 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
10034 +
10035 +static struct snd_soc_dai_link snd_rpi_iqaudio_dac_dai[] = {
10036 +{
10037 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
10038 + SND_SOC_DAIFMT_CBS_CFS,
10039 + .init = snd_rpi_iqaudio_dac_init,
10040 + SND_SOC_DAILINK_REG(hifi),
10041 +},
10042 +};
10043 +
10044 +/* audio machine driver */
10045 +static struct snd_soc_card snd_rpi_iqaudio_dac = {
10046 + .owner = THIS_MODULE,
10047 + .dai_link = snd_rpi_iqaudio_dac_dai,
10048 + .num_links = ARRAY_SIZE(snd_rpi_iqaudio_dac_dai),
10049 +};
10050 +
10051 +static int snd_rpi_iqaudio_dac_probe(struct platform_device *pdev)
10052 +{
10053 + int ret = 0;
10054 + bool gpio_unmute = false;
10055 +
10056 + snd_rpi_iqaudio_dac.dev = &pdev->dev;
10057 +
10058 + if (pdev->dev.of_node) {
10059 + struct device_node *i2s_node;
10060 + struct snd_soc_card *card = &snd_rpi_iqaudio_dac;
10061 + struct snd_soc_dai_link *dai = &snd_rpi_iqaudio_dac_dai[0];
10062 + bool auto_gpio_mute = false;
10063 +
10064 + i2s_node = of_parse_phandle(pdev->dev.of_node,
10065 + "i2s-controller", 0);
10066 + if (i2s_node) {
10067 + dai->cpus->dai_name = NULL;
10068 + dai->cpus->of_node = i2s_node;
10069 + dai->platforms->name = NULL;
10070 + dai->platforms->of_node = i2s_node;
10071 + }
10072 +
10073 + digital_gain_0db_limit = !of_property_read_bool(
10074 + pdev->dev.of_node, "iqaudio,24db_digital_gain");
10075 +
10076 + if (of_property_read_string(pdev->dev.of_node, "card_name",
10077 + &card->name))
10078 + card->name = "IQaudIODAC";
10079 +
10080 + if (of_property_read_string(pdev->dev.of_node, "dai_name",
10081 + &dai->name))
10082 + dai->name = "IQaudIO DAC";
10083 +
10084 + if (of_property_read_string(pdev->dev.of_node,
10085 + "dai_stream_name", &dai->stream_name))
10086 + dai->stream_name = "IQaudIO DAC HiFi";
10087 +
10088 + /* gpio_unmute - one time unmute amp using GPIO */
10089 + gpio_unmute = of_property_read_bool(pdev->dev.of_node,
10090 + "iqaudio-dac,unmute-amp");
10091 +
10092 + /* auto_gpio_mute - mute/unmute amp using GPIO */
10093 + auto_gpio_mute = of_property_read_bool(pdev->dev.of_node,
10094 + "iqaudio-dac,auto-mute-amp");
10095 +
10096 + if (auto_gpio_mute || gpio_unmute) {
10097 + mute_gpio = devm_gpiod_get_optional(&pdev->dev, "mute",
10098 + GPIOD_OUT_LOW);
10099 + if (IS_ERR(mute_gpio)) {
10100 + ret = PTR_ERR(mute_gpio);
10101 + dev_err(&pdev->dev,
10102 + "Failed to get mute gpio: %d\n", ret);
10103 + return ret;
10104 + }
10105 +
10106 + if (auto_gpio_mute && mute_gpio)
10107 + snd_rpi_iqaudio_dac.set_bias_level =
10108 + snd_rpi_iqaudio_set_bias_level;
10109 + }
10110 + }
10111 +
10112 + ret = snd_soc_register_card(&snd_rpi_iqaudio_dac);
10113 + if (ret) {
10114 + if (ret != -EPROBE_DEFER)
10115 + dev_err(&pdev->dev,
10116 + "snd_soc_register_card() failed: %d\n", ret);
10117 + return ret;
10118 + }
10119 +
10120 + if (gpio_unmute && mute_gpio)
10121 + snd_rpi_iqaudio_gpio_unmute(&snd_rpi_iqaudio_dac);
10122 +
10123 + return 0;
10124 +}
10125 +
10126 +static int snd_rpi_iqaudio_dac_remove(struct platform_device *pdev)
10127 +{
10128 + snd_rpi_iqaudio_gpio_mute(&snd_rpi_iqaudio_dac);
10129 +
10130 + return snd_soc_unregister_card(&snd_rpi_iqaudio_dac);
10131 +}
10132 +
10133 +static const struct of_device_id iqaudio_of_match[] = {
10134 + { .compatible = "iqaudio,iqaudio-dac", },
10135 + {},
10136 +};
10137 +MODULE_DEVICE_TABLE(of, iqaudio_of_match);
10138 +
10139 +static struct platform_driver snd_rpi_iqaudio_dac_driver = {
10140 + .driver = {
10141 + .name = "snd-rpi-iqaudio-dac",
10142 + .owner = THIS_MODULE,
10143 + .of_match_table = iqaudio_of_match,
10144 + },
10145 + .probe = snd_rpi_iqaudio_dac_probe,
10146 + .remove = snd_rpi_iqaudio_dac_remove,
10147 +};
10148 +
10149 +module_platform_driver(snd_rpi_iqaudio_dac_driver);
10150 +
10151 +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
10152 +MODULE_DESCRIPTION("ASoC Driver for IQAudio DAC");
10153 +MODULE_LICENSE("GPL v2");
10154 --- /dev/null
10155 +++ b/sound/soc/bcm/justboom-both.c
10156 @@ -0,0 +1,266 @@
10157 +// SPDX-License-Identifier: GPL-2.0
10158 +/*
10159 + * rpi--wm8804.c -- ALSA SoC Raspberry Pi soundcard.
10160 + *
10161 + * Authors: Johannes Krude <johannes@krude.de
10162 + *
10163 + * Driver for when connecting simultaneously justboom-digi and justboom-dac
10164 + *
10165 + * Based upon code from:
10166 + * justboom-digi.c
10167 + * by Milan Neskovic <info@justboom.co>
10168 + * justboom-dac.c
10169 + * by Milan Neskovic <info@justboom.co>
10170 + *
10171 + * This program is free software; you can redistribute it and/or
10172 + * modify it under the terms of the GNU General Public License
10173 + * version 2 as published by the Free Software Foundation.
10174 + *
10175 + * This program is distributed in the hope that it will be useful, but
10176 + * WITHOUT ANY WARRANTY; without even the implied warranty of
10177 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10178 + * General Public License for more details.
10179 + */
10180 +
10181 +#include <linux/module.h>
10182 +#include <linux/platform_device.h>
10183 +
10184 +#include <sound/core.h>
10185 +#include <sound/pcm.h>
10186 +#include <sound/pcm_params.h>
10187 +#include <sound/soc.h>
10188 +#include <sound/jack.h>
10189 +
10190 +#include "../codecs/wm8804.h"
10191 +#include "../codecs/pcm512x.h"
10192 +
10193 +
10194 +static bool digital_gain_0db_limit = true;
10195 +
10196 +static int snd_rpi_justboom_both_init(struct snd_soc_pcm_runtime *rtd)
10197 +{
10198 + struct snd_soc_component *digi = asoc_rtd_to_codec(rtd, 0)->component;
10199 + struct snd_soc_component *dac = asoc_rtd_to_codec(rtd, 1)->component;
10200 +
10201 + /* enable TX output */
10202 + snd_soc_component_update_bits(digi, WM8804_PWRDN, 0x4, 0x0);
10203 +
10204 + snd_soc_component_update_bits(dac, PCM512x_GPIO_EN, 0x08, 0x08);
10205 + snd_soc_component_update_bits(dac, PCM512x_GPIO_OUTPUT_4, 0xf, 0x02);
10206 + snd_soc_component_update_bits(dac, PCM512x_GPIO_CONTROL_1, 0x08, 0x08);
10207 +
10208 + if (digital_gain_0db_limit) {
10209 + int ret;
10210 + struct snd_soc_card *card = rtd->card;
10211 +
10212 + ret = snd_soc_limit_volume(card, "Digital Playback Volume",
10213 + 207);
10214 + if (ret < 0)
10215 + dev_warn(card->dev, "Failed to set volume limit: %d\n",
10216 + ret);
10217 + }
10218 +
10219 + return 0;
10220 +}
10221 +
10222 +static int snd_rpi_justboom_both_hw_params(struct snd_pcm_substream *substream,
10223 + struct snd_pcm_hw_params *params)
10224 +{
10225 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
10226 + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
10227 + struct snd_soc_component *digi = asoc_rtd_to_codec(rtd, 0)->component;
10228 + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
10229 +
10230 + int sysclk = 27000000; /* This is fixed on this board */
10231 +
10232 + long mclk_freq = 0;
10233 + int mclk_div = 1;
10234 + int sampling_freq = 1;
10235 +
10236 + int ret;
10237 +
10238 + int samplerate = params_rate(params);
10239 +
10240 + if (samplerate <= 96000) {
10241 + mclk_freq = samplerate*256;
10242 + mclk_div = WM8804_MCLKDIV_256FS;
10243 + } else {
10244 + mclk_freq = samplerate*128;
10245 + mclk_div = WM8804_MCLKDIV_128FS;
10246 + }
10247 +
10248 + switch (samplerate) {
10249 + case 32000:
10250 + sampling_freq = 0x03;
10251 + break;
10252 + case 44100:
10253 + sampling_freq = 0x00;
10254 + break;
10255 + case 48000:
10256 + sampling_freq = 0x02;
10257 + break;
10258 + case 88200:
10259 + sampling_freq = 0x08;
10260 + break;
10261 + case 96000:
10262 + sampling_freq = 0x0a;
10263 + break;
10264 + case 176400:
10265 + sampling_freq = 0x0c;
10266 + break;
10267 + case 192000:
10268 + sampling_freq = 0x0e;
10269 + break;
10270 + default:
10271 + dev_err(rtd->card->dev,
10272 + "Failed to set WM8804 SYSCLK, unsupported samplerate %d\n",
10273 + samplerate);
10274 + }
10275 +
10276 + snd_soc_dai_set_clkdiv(codec_dai, WM8804_MCLK_DIV, mclk_div);
10277 + snd_soc_dai_set_pll(codec_dai, 0, 0, sysclk, mclk_freq);
10278 +
10279 + ret = snd_soc_dai_set_sysclk(codec_dai, WM8804_TX_CLKSRC_PLL,
10280 + sysclk, SND_SOC_CLOCK_OUT);
10281 + if (ret < 0) {
10282 + dev_err(rtd->card->dev,
10283 + "Failed to set WM8804 SYSCLK: %d\n", ret);
10284 + return ret;
10285 + }
10286 +
10287 + /* Enable TX output */
10288 + snd_soc_component_update_bits(digi, WM8804_PWRDN, 0x4, 0x0);
10289 +
10290 + /* Power on */
10291 + snd_soc_component_update_bits(digi, WM8804_PWRDN, 0x9, 0);
10292 +
10293 + /* set sampling frequency status bits */
10294 + snd_soc_component_update_bits(digi, WM8804_SPDTX4, 0x0f, sampling_freq);
10295 +
10296 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 64);
10297 +}
10298 +
10299 +static int snd_rpi_justboom_both_startup(struct snd_pcm_substream *substream)
10300 +{
10301 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
10302 + struct snd_soc_component *digi = asoc_rtd_to_codec(rtd, 0)->component;
10303 + struct snd_soc_component *dac = asoc_rtd_to_codec(rtd, 1)->component;
10304 +
10305 + /* turn on digital output */
10306 + snd_soc_component_update_bits(digi, WM8804_PWRDN, 0x3c, 0x00);
10307 +
10308 + snd_soc_component_update_bits(dac, PCM512x_GPIO_CONTROL_1, 0x08, 0x08);
10309 +
10310 + return 0;
10311 +}
10312 +
10313 +static void snd_rpi_justboom_both_shutdown(struct snd_pcm_substream *substream)
10314 +{
10315 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
10316 + struct snd_soc_component *digi = asoc_rtd_to_codec(rtd, 0)->component;
10317 + struct snd_soc_component *dac = asoc_rtd_to_codec(rtd, 1)->component;
10318 +
10319 + snd_soc_component_update_bits(dac, PCM512x_GPIO_CONTROL_1, 0x08, 0x00);
10320 +
10321 + /* turn off output */
10322 + snd_soc_component_update_bits(digi, WM8804_PWRDN, 0x3c, 0x3c);
10323 +}
10324 +
10325 +/* machine stream operations */
10326 +static struct snd_soc_ops snd_rpi_justboom_both_ops = {
10327 + .hw_params = snd_rpi_justboom_both_hw_params,
10328 + .startup = snd_rpi_justboom_both_startup,
10329 + .shutdown = snd_rpi_justboom_both_shutdown,
10330 +};
10331 +
10332 +SND_SOC_DAILINK_DEFS(rpi_justboom_both,
10333 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
10334 + DAILINK_COMP_ARRAY(COMP_CODEC("pcm512x.1-004d", "pcm512x-hifi"),
10335 + COMP_CODEC("wm8804.1-003b", "wm8804-spdif")),
10336 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
10337 +
10338 +static struct snd_soc_dai_link snd_rpi_justboom_both_dai[] = {
10339 +{
10340 + .name = "JustBoom Digi",
10341 + .stream_name = "JustBoom Digi HiFi",
10342 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
10343 + SND_SOC_DAIFMT_CBM_CFM,
10344 + .ops = &snd_rpi_justboom_both_ops,
10345 + .init = snd_rpi_justboom_both_init,
10346 + SND_SOC_DAILINK_REG(rpi_justboom_both),
10347 +},
10348 +};
10349 +
10350 +/* audio machine driver */
10351 +static struct snd_soc_card snd_rpi_justboom_both = {
10352 + .name = "snd_rpi_justboom_both",
10353 + .driver_name = "JustBoomBoth",
10354 + .owner = THIS_MODULE,
10355 + .dai_link = snd_rpi_justboom_both_dai,
10356 + .num_links = ARRAY_SIZE(snd_rpi_justboom_both_dai),
10357 +};
10358 +
10359 +static int snd_rpi_justboom_both_probe(struct platform_device *pdev)
10360 +{
10361 + int ret = 0;
10362 + struct snd_soc_card *card = &snd_rpi_justboom_both;
10363 +
10364 + snd_rpi_justboom_both.dev = &pdev->dev;
10365 +
10366 + if (pdev->dev.of_node) {
10367 + struct device_node *i2s_node;
10368 + struct snd_soc_dai_link *dai = &snd_rpi_justboom_both_dai[0];
10369 +
10370 + i2s_node = of_parse_phandle(pdev->dev.of_node,
10371 + "i2s-controller", 0);
10372 +
10373 + if (i2s_node) {
10374 + int i;
10375 +
10376 + for (i = 0; i < card->num_links; i++) {
10377 + dai->cpus->dai_name = NULL;
10378 + dai->cpus->of_node = i2s_node;
10379 + dai->platforms->name = NULL;
10380 + dai->platforms->of_node = i2s_node;
10381 + }
10382 + }
10383 +
10384 + digital_gain_0db_limit = !of_property_read_bool(
10385 + pdev->dev.of_node, "justboom,24db_digital_gain");
10386 + }
10387 +
10388 + ret = snd_soc_register_card(card);
10389 + if (ret && ret != -EPROBE_DEFER) {
10390 + dev_err(&pdev->dev,
10391 + "snd_soc_register_card() failed: %d\n", ret);
10392 + }
10393 +
10394 + return ret;
10395 +}
10396 +
10397 +static int snd_rpi_justboom_both_remove(struct platform_device *pdev)
10398 +{
10399 + return snd_soc_unregister_card(&snd_rpi_justboom_both);
10400 +}
10401 +
10402 +static const struct of_device_id snd_rpi_justboom_both_of_match[] = {
10403 + { .compatible = "justboom,justboom-both", },
10404 + {},
10405 +};
10406 +MODULE_DEVICE_TABLE(of, snd_rpi_justboom_both_of_match);
10407 +
10408 +static struct platform_driver snd_rpi_justboom_both_driver = {
10409 + .driver = {
10410 + .name = "snd-rpi-justboom-both",
10411 + .owner = THIS_MODULE,
10412 + .of_match_table = snd_rpi_justboom_both_of_match,
10413 + },
10414 + .probe = snd_rpi_justboom_both_probe,
10415 + .remove = snd_rpi_justboom_both_remove,
10416 +};
10417 +
10418 +module_platform_driver(snd_rpi_justboom_both_driver);
10419 +
10420 +MODULE_AUTHOR("Johannes Krude <johannes@krude.de>");
10421 +MODULE_DESCRIPTION("ASoC Driver for simultaneous use of JustBoom PI Digi & DAC HAT Sound Cards");
10422 +MODULE_LICENSE("GPL v2");
10423 --- /dev/null
10424 +++ b/sound/soc/bcm/justboom-dac.c
10425 @@ -0,0 +1,147 @@
10426 +/*
10427 + * ASoC Driver for JustBoom DAC Raspberry Pi HAT Sound Card
10428 + *
10429 + * Author: Milan Neskovic
10430 + * Copyright 2016
10431 + * based on code by Daniel Matuschek <info@crazy-audio.com>
10432 + * based on code by Florian Meier <florian.meier@koalo.de>
10433 + *
10434 + * This program is free software; you can redistribute it and/or
10435 + * modify it under the terms of the GNU General Public License
10436 + * version 2 as published by the Free Software Foundation.
10437 + *
10438 + * This program is distributed in the hope that it will be useful, but
10439 + * WITHOUT ANY WARRANTY; without even the implied warranty of
10440 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10441 + * General Public License for more details.
10442 + */
10443 +
10444 +#include <linux/module.h>
10445 +#include <linux/platform_device.h>
10446 +
10447 +#include <sound/core.h>
10448 +#include <sound/pcm.h>
10449 +#include <sound/pcm_params.h>
10450 +#include <sound/soc.h>
10451 +#include <sound/jack.h>
10452 +
10453 +#include "../codecs/pcm512x.h"
10454 +
10455 +static bool digital_gain_0db_limit = true;
10456 +
10457 +static int snd_rpi_justboom_dac_init(struct snd_soc_pcm_runtime *rtd)
10458 +{
10459 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
10460 + snd_soc_component_update_bits(component, PCM512x_GPIO_EN, 0x08, 0x08);
10461 + snd_soc_component_update_bits(component, PCM512x_GPIO_OUTPUT_4, 0xf, 0x02);
10462 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x08,0x08);
10463 +
10464 + if (digital_gain_0db_limit)
10465 + {
10466 + int ret;
10467 + struct snd_soc_card *card = rtd->card;
10468 +
10469 + ret = snd_soc_limit_volume(card, "Digital Playback Volume", 207);
10470 + if (ret < 0)
10471 + dev_warn(card->dev, "Failed to set volume limit: %d\n", ret);
10472 + }
10473 +
10474 + return 0;
10475 +}
10476 +
10477 +static int snd_rpi_justboom_dac_startup(struct snd_pcm_substream *substream) {
10478 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
10479 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
10480 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x08,0x08);
10481 + return 0;
10482 +}
10483 +
10484 +static void snd_rpi_justboom_dac_shutdown(struct snd_pcm_substream *substream) {
10485 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
10486 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
10487 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x08,0x00);
10488 +}
10489 +
10490 +/* machine stream operations */
10491 +static struct snd_soc_ops snd_rpi_justboom_dac_ops = {
10492 + .startup = snd_rpi_justboom_dac_startup,
10493 + .shutdown = snd_rpi_justboom_dac_shutdown,
10494 +};
10495 +
10496 +SND_SOC_DAILINK_DEFS(hifi,
10497 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
10498 + DAILINK_COMP_ARRAY(COMP_CODEC("pcm512x.1-004d", "pcm512x-hifi")),
10499 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
10500 +
10501 +static struct snd_soc_dai_link snd_rpi_justboom_dac_dai[] = {
10502 +{
10503 + .name = "JustBoom DAC",
10504 + .stream_name = "JustBoom DAC HiFi",
10505 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
10506 + SND_SOC_DAIFMT_CBS_CFS,
10507 + .ops = &snd_rpi_justboom_dac_ops,
10508 + .init = snd_rpi_justboom_dac_init,
10509 + SND_SOC_DAILINK_REG(hifi),
10510 +},
10511 +};
10512 +
10513 +/* audio machine driver */
10514 +static struct snd_soc_card snd_rpi_justboom_dac = {
10515 + .name = "snd_rpi_justboom_dac",
10516 + .driver_name = "JustBoomDac",
10517 + .owner = THIS_MODULE,
10518 + .dai_link = snd_rpi_justboom_dac_dai,
10519 + .num_links = ARRAY_SIZE(snd_rpi_justboom_dac_dai),
10520 +};
10521 +
10522 +static int snd_rpi_justboom_dac_probe(struct platform_device *pdev)
10523 +{
10524 + int ret = 0;
10525 +
10526 + snd_rpi_justboom_dac.dev = &pdev->dev;
10527 +
10528 + if (pdev->dev.of_node) {
10529 + struct device_node *i2s_node;
10530 + struct snd_soc_dai_link *dai = &snd_rpi_justboom_dac_dai[0];
10531 + i2s_node = of_parse_phandle(pdev->dev.of_node,
10532 + "i2s-controller", 0);
10533 +
10534 + if (i2s_node) {
10535 + dai->cpus->dai_name = NULL;
10536 + dai->cpus->of_node = i2s_node;
10537 + dai->platforms->name = NULL;
10538 + dai->platforms->of_node = i2s_node;
10539 + }
10540 +
10541 + digital_gain_0db_limit = !of_property_read_bool(
10542 + pdev->dev.of_node, "justboom,24db_digital_gain");
10543 + }
10544 +
10545 + ret = devm_snd_soc_register_card(&pdev->dev, &snd_rpi_justboom_dac);
10546 + if (ret && ret != -EPROBE_DEFER)
10547 + dev_err(&pdev->dev,
10548 + "snd_soc_register_card() failed: %d\n", ret);
10549 +
10550 + return ret;
10551 +}
10552 +
10553 +static const struct of_device_id snd_rpi_justboom_dac_of_match[] = {
10554 + { .compatible = "justboom,justboom-dac", },
10555 + {},
10556 +};
10557 +MODULE_DEVICE_TABLE(of, snd_rpi_justboom_dac_of_match);
10558 +
10559 +static struct platform_driver snd_rpi_justboom_dac_driver = {
10560 + .driver = {
10561 + .name = "snd-rpi-justboom-dac",
10562 + .owner = THIS_MODULE,
10563 + .of_match_table = snd_rpi_justboom_dac_of_match,
10564 + },
10565 + .probe = snd_rpi_justboom_dac_probe,
10566 +};
10567 +
10568 +module_platform_driver(snd_rpi_justboom_dac_driver);
10569 +
10570 +MODULE_AUTHOR("Milan Neskovic <info@justboom.co>");
10571 +MODULE_DESCRIPTION("ASoC Driver for JustBoom PI DAC HAT Sound Card");
10572 +MODULE_LICENSE("GPL v2");
10573 --- /dev/null
10574 +++ b/sound/soc/bcm/pifi-40.c
10575 @@ -0,0 +1,283 @@
10576 +// SPDX-License-Identifier: GPL-2.0-only
10577 +/*
10578 + * ALSA ASoC Machine Driver for PiFi-40
10579 + *
10580 + * Author: David Knell <david.knell@gmail.com)
10581 + * based on code by Daniel Matuschek <info@crazy-audio.com>
10582 + * based on code by Florian Meier <florian.meier@koalo.de>
10583 + * Copyright (C) 2020
10584 + *
10585 + * This program is free software; you can redistribute it and/or
10586 + * modify it under the terms of the GNU General Public License
10587 + * version 2 as published by the Free Software Foundation.
10588 + *
10589 + * This program is distributed in the hope that it will be useful, but
10590 + * WITHOUT ANY WARRANTY; without even the implied warranty of
10591 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10592 + * General Public License for more details.
10593 + */
10594 +
10595 +#include <linux/module.h>
10596 +#include <linux/platform_device.h>
10597 +#include <linux/gpio/consumer.h>
10598 +#include <sound/core.h>
10599 +#include <sound/pcm.h>
10600 +#include <sound/pcm_params.h>
10601 +#include <sound/soc.h>
10602 +#include <linux/firmware.h>
10603 +#include <linux/delay.h>
10604 +#include <sound/tlv.h>
10605 +
10606 +static struct gpio_desc *pdn_gpio;
10607 +static int vol = 0x30;
10608 +
10609 +// Volume control
10610 +static int pifi_40_vol_get(struct snd_kcontrol *kcontrol,
10611 + struct snd_ctl_elem_value *ucontrol)
10612 +{
10613 + ucontrol->value.integer.value[0] = vol;
10614 + ucontrol->value.integer.value[1] = vol;
10615 + return 0;
10616 +}
10617 +
10618 +static int pifi_40_vol_set(struct snd_kcontrol *kcontrol,
10619 + struct snd_ctl_elem_value *ucontrol)
10620 +{
10621 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
10622 + struct snd_soc_pcm_runtime *rtd;
10623 + unsigned int v = ucontrol->value.integer.value[0];
10624 + struct snd_soc_component *dac[2];
10625 +
10626 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
10627 + dac[0] = asoc_rtd_to_codec(rtd, 0)->component;
10628 + dac[1] = asoc_rtd_to_codec(rtd, 1)->component;
10629 +
10630 + snd_soc_component_write(dac[0], 0x07, 255 - v);
10631 + snd_soc_component_write(dac[1], 0x07, 255 - v);
10632 +
10633 + vol = v;
10634 + return 1;
10635 +}
10636 +
10637 +static const DECLARE_TLV_DB_SCALE(digital_tlv_master, -10350, 50, 1);
10638 +static const struct snd_kcontrol_new pifi_40_controls[] = {
10639 + SOC_DOUBLE_R_EXT_TLV("Master Volume", 0x00, 0x01,
10640 + 0x00, // Min
10641 + 0xff, // Max
10642 + 0x01, // Invert
10643 + pifi_40_vol_get, pifi_40_vol_set,
10644 + digital_tlv_master)
10645 +};
10646 +
10647 +static const char * const codec_ctl_pfx[] = { "Left", "Right" };
10648 +
10649 +static const char * const codec_ctl_name[] = { "Master Volume",
10650 + "Speaker Volume",
10651 + "Speaker Switch" };
10652 +
10653 +static int snd_pifi_40_init(struct snd_soc_pcm_runtime *rtd)
10654 +{
10655 + struct snd_soc_card *card = rtd->card;
10656 + struct snd_soc_component *dac[2];
10657 + struct snd_kcontrol *kctl;
10658 + int i, j;
10659 +
10660 + dac[0] = asoc_rtd_to_codec(rtd, 0)->component;
10661 + dac[1] = asoc_rtd_to_codec(rtd, 1)->component;
10662 +
10663 +
10664 + // Set up cards - pulse power down first
10665 + gpiod_set_value_cansleep(pdn_gpio, 1);
10666 + usleep_range(1000, 10000);
10667 + gpiod_set_value_cansleep(pdn_gpio, 0);
10668 + usleep_range(20000, 30000);
10669 +
10670 + // Oscillator trim
10671 + snd_soc_component_write(dac[0], 0x1b, 0);
10672 + snd_soc_component_write(dac[1], 0x1b, 0);
10673 + usleep_range(60000, 80000);
10674 +
10675 + // Common setup
10676 + for (i = 0; i < 2; i++) {
10677 + // MCLK at 64fs, sample rate 44.1 or 48kHz
10678 + snd_soc_component_write(dac[i], 0x00, 0x60);
10679 +
10680 + // Set up for PBTL
10681 + snd_soc_component_write(dac[i], 0x19, 0x3A);
10682 + snd_soc_component_write(dac[i], 0x25, 0x01103245);
10683 +
10684 + // Master vol to -10db
10685 + snd_soc_component_write(dac[i], 0x07, 0x44);
10686 + }
10687 + // Inputs set to L and R respectively
10688 + snd_soc_component_write(dac[0], 0x20, 0x00017772);
10689 + snd_soc_component_write(dac[1], 0x20, 0x00107772);
10690 +
10691 + // Remove codec controls
10692 + for (i = 0; i < 2; i++) {
10693 + for (j = 0; j < 3; j++) {
10694 + char cname[256];
10695 +
10696 + sprintf(cname, "%s %s", codec_ctl_pfx[i],
10697 + codec_ctl_name[j]);
10698 + kctl = snd_soc_card_get_kcontrol(card, cname);
10699 + if (!kctl) {
10700 + pr_info("Control %s not found\n",
10701 + cname);
10702 + } else {
10703 + kctl->vd[0].access =
10704 + SNDRV_CTL_ELEM_ACCESS_READWRITE;
10705 + snd_ctl_remove(card->snd_card, kctl);
10706 + }
10707 + }
10708 + }
10709 +
10710 + return 0;
10711 +}
10712 +
10713 +static int snd_pifi_40_hw_params(struct snd_pcm_substream *substream,
10714 + struct snd_pcm_hw_params *params)
10715 +{
10716 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
10717 + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
10718 + unsigned int sample_bits;
10719 +
10720 + sample_bits = snd_pcm_format_physical_width(params_format(params));
10721 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 64);
10722 +}
10723 +
10724 +static struct snd_soc_ops snd_pifi_40_ops = { .hw_params =
10725 + snd_pifi_40_hw_params };
10726 +
10727 +static struct snd_soc_dai_link_component pifi_40_codecs[] = {
10728 + {
10729 + .dai_name = "tas571x-hifi",
10730 + },
10731 + {
10732 + .dai_name = "tas571x-hifi",
10733 + },
10734 +};
10735 +
10736 +SND_SOC_DAILINK_DEFS(
10737 + pifi_40_dai, DAILINK_COMP_ARRAY(COMP_EMPTY()),
10738 + DAILINK_COMP_ARRAY(COMP_CODEC("tas571x.1-001a", "tas571x-hifi"),
10739 + COMP_CODEC("tas571x.1-001b", "tas571x-hifi")),
10740 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
10741 +
10742 +static struct snd_soc_dai_link snd_pifi_40_dai[] = {
10743 + {
10744 + .name = "PiFi40",
10745 + .stream_name = "PiFi40",
10746 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
10747 + SND_SOC_DAIFMT_CBS_CFS,
10748 + .ops = &snd_pifi_40_ops,
10749 + .init = snd_pifi_40_init,
10750 + SND_SOC_DAILINK_REG(pifi_40_dai),
10751 + },
10752 +};
10753 +
10754 +// Machine driver
10755 +static struct snd_soc_card snd_pifi_40 = {
10756 + .name = "PiFi40",
10757 + .owner = THIS_MODULE,
10758 + .dai_link = snd_pifi_40_dai,
10759 + .num_links = ARRAY_SIZE(snd_pifi_40_dai),
10760 + .controls = pifi_40_controls,
10761 + .num_controls = ARRAY_SIZE(pifi_40_controls)
10762 +};
10763 +
10764 +static void snd_pifi_40_pdn(struct snd_soc_card *card, int on)
10765 +{
10766 + if (pdn_gpio)
10767 + gpiod_set_value_cansleep(pdn_gpio, on ? 0 : 1);
10768 +}
10769 +
10770 +static int snd_pifi_40_probe(struct platform_device *pdev)
10771 +{
10772 + struct snd_soc_card *card = &snd_pifi_40;
10773 + int ret = 0, i = 0;
10774 +
10775 + card->dev = &pdev->dev;
10776 + platform_set_drvdata(pdev, &snd_pifi_40);
10777 +
10778 + if (pdev->dev.of_node) {
10779 + struct device_node *i2s_node;
10780 + struct snd_soc_dai_link *dai;
10781 +
10782 + dai = &snd_pifi_40_dai[0];
10783 + i2s_node = of_parse_phandle(pdev->dev.of_node, "i2s-controller",
10784 + 0);
10785 + if (i2s_node) {
10786 + for (i = 0; i < card->num_links; i++) {
10787 + dai->cpus->dai_name = NULL;
10788 + dai->cpus->of_node = i2s_node;
10789 + dai->platforms->name = NULL;
10790 + dai->platforms->of_node = i2s_node;
10791 + }
10792 + }
10793 +
10794 + pifi_40_codecs[0].of_node =
10795 + of_parse_phandle(pdev->dev.of_node, "audio-codec", 0);
10796 + pifi_40_codecs[1].of_node =
10797 + of_parse_phandle(pdev->dev.of_node, "audio-codec", 1);
10798 + if (!pifi_40_codecs[0].of_node || !pifi_40_codecs[1].of_node) {
10799 + dev_err(&pdev->dev,
10800 + "Property 'audio-codec' missing or invalid\n");
10801 + return -EINVAL;
10802 + }
10803 +
10804 + pdn_gpio = devm_gpiod_get_optional(&pdev->dev, "pdn",
10805 + GPIOD_OUT_LOW);
10806 + if (IS_ERR(pdn_gpio)) {
10807 + ret = PTR_ERR(pdn_gpio);
10808 + dev_err(&pdev->dev, "failed to get pdn gpio: %d\n",
10809 + ret);
10810 + return ret;
10811 + }
10812 +
10813 + ret = snd_soc_register_card(&snd_pifi_40);
10814 + if (ret < 0) {
10815 + dev_err(&pdev->dev,
10816 + "snd_soc_register_card() failed: %d\n", ret);
10817 + return ret;
10818 + }
10819 +
10820 + return 0;
10821 + }
10822 +
10823 + return -EINVAL;
10824 +}
10825 +
10826 +static int snd_pifi_40_remove(struct platform_device *pdev)
10827 +{
10828 + struct snd_soc_card *card = platform_get_drvdata(pdev);
10829 +
10830 + kfree(&card->drvdata);
10831 + snd_pifi_40_pdn(&snd_pifi_40, 0);
10832 + return snd_soc_unregister_card(&snd_pifi_40);
10833 +}
10834 +
10835 +static const struct of_device_id snd_pifi_40_of_match[] = {
10836 + {
10837 + .compatible = "pifi,pifi-40",
10838 + },
10839 + { /* sentinel */ },
10840 +};
10841 +
10842 +MODULE_DEVICE_TABLE(of, snd_pifi_40_of_match);
10843 +
10844 +static struct platform_driver snd_pifi_40_driver = {
10845 + .driver = {
10846 + .name = "snd-pifi-40",
10847 + .owner = THIS_MODULE,
10848 + .of_match_table = snd_pifi_40_of_match,
10849 + },
10850 + .probe = snd_pifi_40_probe,
10851 + .remove = snd_pifi_40_remove,
10852 +};
10853 +
10854 +module_platform_driver(snd_pifi_40_driver);
10855 +
10856 +MODULE_AUTHOR("David Knell <david.knell@gmail.com>");
10857 +MODULE_DESCRIPTION("ALSA ASoC Machine Driver for PiFi-40");
10858 +MODULE_LICENSE("GPL v2");
10859 --- /dev/null
10860 +++ b/sound/soc/bcm/pisound.c
10861 @@ -0,0 +1,1240 @@
10862 +/*
10863 + * Pisound Linux kernel module.
10864 + * Copyright (C) 2016-2020 Vilniaus Blokas UAB, https://blokas.io/pisound
10865 + *
10866 + * This program is free software; you can redistribute it and/or
10867 + * modify it under the terms of the GNU General Public License
10868 + * as published by the Free Software Foundation; version 2 of the
10869 + * License.
10870 + *
10871 + * This program is distributed in the hope that it will be useful,
10872 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10873 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10874 + * GNU General Public License for more details.
10875 + *
10876 + * You should have received a copy of the GNU General Public License
10877 + * along with this program; if not, write to the Free Software
10878 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
10879 + * MA 02110-1301, USA.
10880 + */
10881 +
10882 +#include <linux/init.h>
10883 +#include <linux/module.h>
10884 +#include <linux/platform_device.h>
10885 +#include <linux/gpio.h>
10886 +#include <linux/kobject.h>
10887 +#include <linux/sysfs.h>
10888 +#include <linux/delay.h>
10889 +#include <linux/spi/spi.h>
10890 +#include <linux/interrupt.h>
10891 +#include <linux/kfifo.h>
10892 +#include <linux/jiffies.h>
10893 +
10894 +#include <sound/core.h>
10895 +#include <sound/pcm.h>
10896 +#include <sound/pcm_params.h>
10897 +#include <sound/soc.h>
10898 +#include <sound/jack.h>
10899 +#include <sound/rawmidi.h>
10900 +#include <sound/asequencer.h>
10901 +#include <sound/control.h>
10902 +
10903 +static int pisnd_spi_init(struct device *dev);
10904 +static void pisnd_spi_uninit(void);
10905 +
10906 +static void pisnd_spi_flush(void);
10907 +static void pisnd_spi_start(void);
10908 +static uint8_t pisnd_spi_recv(uint8_t *buffer, uint8_t length);
10909 +
10910 +typedef void (*pisnd_spi_recv_cb)(void *data);
10911 +static void pisnd_spi_set_callback(pisnd_spi_recv_cb cb, void *data);
10912 +
10913 +static const char *pisnd_spi_get_serial(void);
10914 +static const char *pisnd_spi_get_id(void);
10915 +static const char *pisnd_spi_get_fw_version(void);
10916 +static const char *pisnd_spi_get_hw_version(void);
10917 +
10918 +static int pisnd_midi_init(struct snd_card *card);
10919 +static void pisnd_midi_uninit(void);
10920 +
10921 +enum task_e {
10922 + TASK_PROCESS = 0,
10923 +};
10924 +
10925 +static void pisnd_schedule_process(enum task_e task);
10926 +
10927 +#define PISOUND_LOG_PREFIX "pisound: "
10928 +
10929 +#ifdef PISOUND_DEBUG
10930 +# define printd(...) pr_alert(PISOUND_LOG_PREFIX __VA_ARGS__)
10931 +#else
10932 +# define printd(...) do {} while (0)
10933 +#endif
10934 +
10935 +#define printe(...) pr_err(PISOUND_LOG_PREFIX __VA_ARGS__)
10936 +#define printi(...) pr_info(PISOUND_LOG_PREFIX __VA_ARGS__)
10937 +
10938 +static struct snd_rawmidi *g_rmidi;
10939 +static struct snd_rawmidi_substream *g_midi_output_substream;
10940 +
10941 +static int pisnd_output_open(struct snd_rawmidi_substream *substream)
10942 +{
10943 + g_midi_output_substream = substream;
10944 + return 0;
10945 +}
10946 +
10947 +static int pisnd_output_close(struct snd_rawmidi_substream *substream)
10948 +{
10949 + g_midi_output_substream = NULL;
10950 + return 0;
10951 +}
10952 +
10953 +static void pisnd_output_trigger(
10954 + struct snd_rawmidi_substream *substream,
10955 + int up
10956 + )
10957 +{
10958 + if (substream != g_midi_output_substream) {
10959 + printe("MIDI output trigger called for an unexpected stream!");
10960 + return;
10961 + }
10962 +
10963 + if (!up)
10964 + return;
10965 +
10966 + pisnd_spi_start();
10967 +}
10968 +
10969 +static void pisnd_output_drain(struct snd_rawmidi_substream *substream)
10970 +{
10971 + pisnd_spi_flush();
10972 +}
10973 +
10974 +static int pisnd_input_open(struct snd_rawmidi_substream *substream)
10975 +{
10976 + return 0;
10977 +}
10978 +
10979 +static int pisnd_input_close(struct snd_rawmidi_substream *substream)
10980 +{
10981 + return 0;
10982 +}
10983 +
10984 +static void pisnd_midi_recv_callback(void *substream)
10985 +{
10986 + uint8_t data[128];
10987 + uint8_t n = 0;
10988 +
10989 + while ((n = pisnd_spi_recv(data, sizeof(data)))) {
10990 + int res = snd_rawmidi_receive(substream, data, n);
10991 + (void)res;
10992 + printd("midi recv %u bytes, res = %d\n", n, res);
10993 + }
10994 +}
10995 +
10996 +static void pisnd_input_trigger(struct snd_rawmidi_substream *substream, int up)
10997 +{
10998 + if (up) {
10999 + pisnd_spi_set_callback(pisnd_midi_recv_callback, substream);
11000 + pisnd_schedule_process(TASK_PROCESS);
11001 + } else {
11002 + pisnd_spi_set_callback(NULL, NULL);
11003 + }
11004 +}
11005 +
11006 +static struct snd_rawmidi_ops pisnd_output_ops = {
11007 + .open = pisnd_output_open,
11008 + .close = pisnd_output_close,
11009 + .trigger = pisnd_output_trigger,
11010 + .drain = pisnd_output_drain,
11011 +};
11012 +
11013 +static struct snd_rawmidi_ops pisnd_input_ops = {
11014 + .open = pisnd_input_open,
11015 + .close = pisnd_input_close,
11016 + .trigger = pisnd_input_trigger,
11017 +};
11018 +
11019 +static void pisnd_get_port_info(
11020 + struct snd_rawmidi *rmidi,
11021 + int number,
11022 + struct snd_seq_port_info *seq_port_info
11023 + )
11024 +{
11025 + seq_port_info->type =
11026 + SNDRV_SEQ_PORT_TYPE_MIDI_GENERIC |
11027 + SNDRV_SEQ_PORT_TYPE_HARDWARE |
11028 + SNDRV_SEQ_PORT_TYPE_PORT;
11029 + seq_port_info->midi_voices = 0;
11030 +}
11031 +
11032 +static struct snd_rawmidi_global_ops pisnd_global_ops = {
11033 + .get_port_info = pisnd_get_port_info,
11034 +};
11035 +
11036 +static int pisnd_midi_init(struct snd_card *card)
11037 +{
11038 + int err;
11039 +
11040 + g_midi_output_substream = NULL;
11041 +
11042 + err = snd_rawmidi_new(card, "pisound MIDI", 0, 1, 1, &g_rmidi);
11043 +
11044 + if (err < 0) {
11045 + printe("snd_rawmidi_new failed: %d\n", err);
11046 + return err;
11047 + }
11048 +
11049 + strcpy(g_rmidi->name, "pisound MIDI ");
11050 + strcat(g_rmidi->name, pisnd_spi_get_serial());
11051 +
11052 + g_rmidi->info_flags =
11053 + SNDRV_RAWMIDI_INFO_OUTPUT |
11054 + SNDRV_RAWMIDI_INFO_INPUT |
11055 + SNDRV_RAWMIDI_INFO_DUPLEX;
11056 +
11057 + g_rmidi->ops = &pisnd_global_ops;
11058 +
11059 + g_rmidi->private_data = (void *)0;
11060 +
11061 + snd_rawmidi_set_ops(
11062 + g_rmidi,
11063 + SNDRV_RAWMIDI_STREAM_OUTPUT,
11064 + &pisnd_output_ops
11065 + );
11066 +
11067 + snd_rawmidi_set_ops(
11068 + g_rmidi,
11069 + SNDRV_RAWMIDI_STREAM_INPUT,
11070 + &pisnd_input_ops
11071 + );
11072 +
11073 + return 0;
11074 +}
11075 +
11076 +static void pisnd_midi_uninit(void)
11077 +{
11078 +}
11079 +
11080 +static void *g_recvData;
11081 +static pisnd_spi_recv_cb g_recvCallback;
11082 +
11083 +#define FIFO_SIZE 4096
11084 +
11085 +static char g_serial_num[11];
11086 +static char g_id[25];
11087 +enum { MAX_VERSION_STR_LEN = 6 };
11088 +static char g_fw_version[MAX_VERSION_STR_LEN];
11089 +static char g_hw_version[MAX_VERSION_STR_LEN];
11090 +
11091 +static uint8_t g_ledFlashDuration;
11092 +static bool g_ledFlashDurationChanged;
11093 +
11094 +DEFINE_KFIFO(spi_fifo_in, uint8_t, FIFO_SIZE);
11095 +DEFINE_KFIFO(spi_fifo_out, uint8_t, FIFO_SIZE);
11096 +
11097 +static struct gpio_desc *data_available;
11098 +static struct gpio_desc *spi_reset;
11099 +
11100 +static struct spi_device *pisnd_spi_device;
11101 +
11102 +static struct workqueue_struct *pisnd_workqueue;
11103 +static struct work_struct pisnd_work_process;
11104 +
11105 +static void pisnd_work_handler(struct work_struct *work);
11106 +
11107 +static void spi_transfer(const uint8_t *txbuf, uint8_t *rxbuf, int len);
11108 +static uint16_t spi_transfer16(uint16_t val);
11109 +
11110 +static int pisnd_init_workqueues(void)
11111 +{
11112 + pisnd_workqueue = create_singlethread_workqueue("pisnd_workqueue");
11113 + INIT_WORK(&pisnd_work_process, pisnd_work_handler);
11114 +
11115 + return 0;
11116 +}
11117 +
11118 +static void pisnd_uninit_workqueues(void)
11119 +{
11120 + flush_workqueue(pisnd_workqueue);
11121 + destroy_workqueue(pisnd_workqueue);
11122 +
11123 + pisnd_workqueue = NULL;
11124 +}
11125 +
11126 +static bool pisnd_spi_has_more(void)
11127 +{
11128 + return gpiod_get_value(data_available);
11129 +}
11130 +
11131 +static void pisnd_schedule_process(enum task_e task)
11132 +{
11133 + if (pisnd_spi_device != NULL &&
11134 + pisnd_workqueue != NULL &&
11135 + !work_pending(&pisnd_work_process)
11136 + ) {
11137 + printd("schedule: has more = %d\n", pisnd_spi_has_more());
11138 + if (task == TASK_PROCESS)
11139 + queue_work(pisnd_workqueue, &pisnd_work_process);
11140 + }
11141 +}
11142 +
11143 +static irqreturn_t data_available_interrupt_handler(int irq, void *dev_id)
11144 +{
11145 + if (irq == gpiod_to_irq(data_available) && pisnd_spi_has_more()) {
11146 + printd("schedule from irq\n");
11147 + pisnd_schedule_process(TASK_PROCESS);
11148 + }
11149 +
11150 + return IRQ_HANDLED;
11151 +}
11152 +
11153 +static uint16_t spi_transfer16(uint16_t val)
11154 +{
11155 + uint8_t txbuf[2];
11156 + uint8_t rxbuf[2];
11157 +
11158 + if (!pisnd_spi_device) {
11159 + printe("pisnd_spi_device null, returning\n");
11160 + return 0;
11161 + }
11162 +
11163 + txbuf[0] = val >> 8;
11164 + txbuf[1] = val & 0xff;
11165 +
11166 + spi_transfer(txbuf, rxbuf, sizeof(txbuf));
11167 +
11168 + printd("received: %02x%02x\n", rxbuf[0], rxbuf[1]);
11169 +
11170 + return (rxbuf[0] << 8) | rxbuf[1];
11171 +}
11172 +
11173 +static void spi_transfer(const uint8_t *txbuf, uint8_t *rxbuf, int len)
11174 +{
11175 + int err;
11176 + struct spi_transfer transfer;
11177 + struct spi_message msg;
11178 +
11179 + memset(rxbuf, 0, len);
11180 +
11181 + if (!pisnd_spi_device) {
11182 + printe("pisnd_spi_device null, returning\n");
11183 + return;
11184 + }
11185 +
11186 + spi_message_init(&msg);
11187 +
11188 + memset(&transfer, 0, sizeof(transfer));
11189 +
11190 + transfer.tx_buf = txbuf;
11191 + transfer.rx_buf = rxbuf;
11192 + transfer.len = len;
11193 + transfer.speed_hz = 150000;
11194 + transfer.delay.value = 10;
11195 + transfer.delay.unit = SPI_DELAY_UNIT_USECS;
11196 +
11197 + spi_message_add_tail(&transfer, &msg);
11198 +
11199 + err = spi_sync(pisnd_spi_device, &msg);
11200 +
11201 + if (err < 0) {
11202 + printe("spi_sync error %d\n", err);
11203 + return;
11204 + }
11205 +
11206 + printd("hasMore %d\n", pisnd_spi_has_more());
11207 +}
11208 +
11209 +static int spi_read_bytes(char *dst, size_t length, uint8_t *bytesRead)
11210 +{
11211 + uint16_t rx;
11212 + uint8_t size;
11213 + uint8_t i;
11214 +
11215 + memset(dst, 0, length);
11216 + *bytesRead = 0;
11217 +
11218 + rx = spi_transfer16(0);
11219 + if (!(rx >> 8))
11220 + return -EINVAL;
11221 +
11222 + size = rx & 0xff;
11223 +
11224 + if (size > length)
11225 + return -EINVAL;
11226 +
11227 + for (i = 0; i < size; ++i) {
11228 + rx = spi_transfer16(0);
11229 + if (!(rx >> 8))
11230 + return -EINVAL;
11231 +
11232 + dst[i] = rx & 0xff;
11233 + }
11234 +
11235 + *bytesRead = i;
11236 +
11237 + return 0;
11238 +}
11239 +
11240 +static int spi_device_match(struct device *dev, const void *data)
11241 +{
11242 + struct spi_device *spi = container_of(dev, struct spi_device, dev);
11243 +
11244 + printd(" %s %s %dkHz %d bits mode=0x%02X\n",
11245 + spi->modalias, dev_name(dev), spi->max_speed_hz/1000,
11246 + spi->bits_per_word, spi->mode);
11247 +
11248 + if (strcmp("pisound-spi", spi->modalias) == 0) {
11249 + printi("\tFound!\n");
11250 + return 1;
11251 + }
11252 +
11253 + printe("\tNot found!\n");
11254 + return 0;
11255 +}
11256 +
11257 +static struct spi_device *pisnd_spi_find_device(void)
11258 +{
11259 + struct device *dev;
11260 +
11261 + printi("Searching for spi device...\n");
11262 + dev = bus_find_device(&spi_bus_type, NULL, NULL, spi_device_match);
11263 + if (dev != NULL)
11264 + return container_of(dev, struct spi_device, dev);
11265 + else
11266 + return NULL;
11267 +}
11268 +
11269 +static void pisnd_work_handler(struct work_struct *work)
11270 +{
11271 + enum { TRANSFER_SIZE = 4 };
11272 + enum { PISOUND_OUTPUT_BUFFER_SIZE_MILLIBYTES = 127 * 1000 };
11273 + enum { MIDI_MILLIBYTES_PER_JIFFIE = (3125 * 1000) / HZ };
11274 + int out_buffer_used_millibytes = 0;
11275 + unsigned long now;
11276 + uint8_t val;
11277 + uint8_t txbuf[TRANSFER_SIZE];
11278 + uint8_t rxbuf[TRANSFER_SIZE];
11279 + uint8_t midibuf[TRANSFER_SIZE];
11280 + int i, n;
11281 + bool had_data;
11282 +
11283 + unsigned long last_transfer_at = jiffies;
11284 +
11285 + if (work == &pisnd_work_process) {
11286 + if (pisnd_spi_device == NULL)
11287 + return;
11288 +
11289 + do {
11290 + if (g_midi_output_substream &&
11291 + kfifo_avail(&spi_fifo_out) >= sizeof(midibuf)) {
11292 +
11293 + n = snd_rawmidi_transmit_peek(
11294 + g_midi_output_substream,
11295 + midibuf, sizeof(midibuf)
11296 + );
11297 +
11298 + if (n > 0) {
11299 + for (i = 0; i < n; ++i)
11300 + kfifo_put(
11301 + &spi_fifo_out,
11302 + midibuf[i]
11303 + );
11304 + snd_rawmidi_transmit_ack(
11305 + g_midi_output_substream,
11306 + i
11307 + );
11308 + }
11309 + }
11310 +
11311 + had_data = false;
11312 + memset(txbuf, 0, sizeof(txbuf));
11313 + for (i = 0; i < sizeof(txbuf) &&
11314 + ((out_buffer_used_millibytes+1000 <
11315 + PISOUND_OUTPUT_BUFFER_SIZE_MILLIBYTES) ||
11316 + g_ledFlashDurationChanged);
11317 + i += 2) {
11318 +
11319 + val = 0;
11320 +
11321 + if (g_ledFlashDurationChanged) {
11322 + txbuf[i+0] = 0xf0;
11323 + txbuf[i+1] = g_ledFlashDuration;
11324 + g_ledFlashDuration = 0;
11325 + g_ledFlashDurationChanged = false;
11326 + } else if (kfifo_get(&spi_fifo_out, &val)) {
11327 + txbuf[i+0] = 0x0f;
11328 + txbuf[i+1] = val;
11329 + out_buffer_used_millibytes += 1000;
11330 + }
11331 + }
11332 +
11333 + spi_transfer(txbuf, rxbuf, sizeof(txbuf));
11334 + /* Estimate the Pisound's MIDI output buffer usage, so
11335 + * that we don't overflow it. Space in the buffer should
11336 + * be becoming available at the UART MIDI byte transfer
11337 + * rate.
11338 + */
11339 + now = jiffies;
11340 + if (now != last_transfer_at) {
11341 + out_buffer_used_millibytes -=
11342 + (now - last_transfer_at) *
11343 + MIDI_MILLIBYTES_PER_JIFFIE;
11344 + if (out_buffer_used_millibytes < 0)
11345 + out_buffer_used_millibytes = 0;
11346 + last_transfer_at = now;
11347 + }
11348 +
11349 + for (i = 0; i < sizeof(rxbuf); i += 2) {
11350 + if (rxbuf[i]) {
11351 + kfifo_put(&spi_fifo_in, rxbuf[i+1]);
11352 + if (kfifo_len(&spi_fifo_in) > 16 &&
11353 + g_recvCallback)
11354 + g_recvCallback(g_recvData);
11355 + had_data = true;
11356 + }
11357 + }
11358 + } while (had_data
11359 + || !kfifo_is_empty(&spi_fifo_out)
11360 + || pisnd_spi_has_more()
11361 + || g_ledFlashDurationChanged
11362 + || out_buffer_used_millibytes != 0
11363 + );
11364 +
11365 + if (!kfifo_is_empty(&spi_fifo_in) && g_recvCallback)
11366 + g_recvCallback(g_recvData);
11367 + }
11368 +}
11369 +
11370 +static int pisnd_spi_gpio_init(struct device *dev)
11371 +{
11372 + spi_reset = gpiod_get_index(dev, "reset", 1, GPIOD_ASIS);
11373 + data_available = gpiod_get_index(dev, "data_available", 0, GPIOD_ASIS);
11374 +
11375 + gpiod_direction_output(spi_reset, 1);
11376 + gpiod_direction_input(data_available);
11377 +
11378 + /* Reset the slave. */
11379 + gpiod_set_value(spi_reset, false);
11380 + mdelay(1);
11381 + gpiod_set_value(spi_reset, true);
11382 +
11383 + /* Give time for spi slave to start. */
11384 + mdelay(64);
11385 +
11386 + return 0;
11387 +}
11388 +
11389 +static void pisnd_spi_gpio_uninit(void)
11390 +{
11391 + gpiod_set_value(spi_reset, false);
11392 + gpiod_put(spi_reset);
11393 + spi_reset = NULL;
11394 +
11395 + gpiod_put(data_available);
11396 + data_available = NULL;
11397 +}
11398 +
11399 +static int pisnd_spi_gpio_irq_init(struct device *dev)
11400 +{
11401 + return request_threaded_irq(
11402 + gpiod_to_irq(data_available), NULL,
11403 + data_available_interrupt_handler,
11404 + IRQF_TIMER | IRQF_TRIGGER_RISING | IRQF_ONESHOT,
11405 + "data_available_int",
11406 + NULL
11407 + );
11408 +}
11409 +
11410 +static void pisnd_spi_gpio_irq_uninit(void)
11411 +{
11412 + free_irq(gpiod_to_irq(data_available), NULL);
11413 +}
11414 +
11415 +static int spi_read_info(void)
11416 +{
11417 + uint16_t tmp;
11418 + uint8_t count;
11419 + uint8_t n;
11420 + uint8_t i;
11421 + uint8_t j;
11422 + char buffer[257];
11423 + int ret;
11424 + char *p;
11425 +
11426 + memset(g_serial_num, 0, sizeof(g_serial_num));
11427 + memset(g_fw_version, 0, sizeof(g_fw_version));
11428 + strcpy(g_hw_version, "1.0"); // Assume 1.0 hw version.
11429 + memset(g_id, 0, sizeof(g_id));
11430 +
11431 + tmp = spi_transfer16(0);
11432 +
11433 + if (!(tmp >> 8))
11434 + return -EINVAL;
11435 +
11436 + count = tmp & 0xff;
11437 +
11438 + for (i = 0; i < count; ++i) {
11439 + memset(buffer, 0, sizeof(buffer));
11440 + ret = spi_read_bytes(buffer, sizeof(buffer)-1, &n);
11441 +
11442 + if (ret < 0)
11443 + return ret;
11444 +
11445 + switch (i) {
11446 + case 0:
11447 + if (n != 2)
11448 + return -EINVAL;
11449 +
11450 + snprintf(
11451 + g_fw_version,
11452 + MAX_VERSION_STR_LEN,
11453 + "%x.%02x",
11454 + buffer[0],
11455 + buffer[1]
11456 + );
11457 +
11458 + g_fw_version[MAX_VERSION_STR_LEN-1] = '\0';
11459 + break;
11460 + case 3:
11461 + if (n != 2)
11462 + return -EINVAL;
11463 +
11464 + snprintf(
11465 + g_hw_version,
11466 + MAX_VERSION_STR_LEN,
11467 + "%x.%x",
11468 + buffer[0],
11469 + buffer[1]
11470 + );
11471 +
11472 + g_hw_version[MAX_VERSION_STR_LEN-1] = '\0';
11473 + break;
11474 + case 1:
11475 + if (n >= sizeof(g_serial_num))
11476 + return -EINVAL;
11477 +
11478 + memcpy(g_serial_num, buffer, sizeof(g_serial_num));
11479 + break;
11480 + case 2:
11481 + {
11482 + if (n*2 >= sizeof(g_id))
11483 + return -EINVAL;
11484 +
11485 + p = g_id;
11486 + for (j = 0; j < n; ++j)
11487 + p += sprintf(p, "%02x", buffer[j]);
11488 +
11489 + *p = '\0';
11490 + }
11491 + break;
11492 + default:
11493 + break;
11494 + }
11495 + }
11496 +
11497 + return 0;
11498 +}
11499 +
11500 +static int pisnd_spi_init(struct device *dev)
11501 +{
11502 + int ret;
11503 + struct spi_device *spi;
11504 +
11505 + memset(g_serial_num, 0, sizeof(g_serial_num));
11506 + memset(g_id, 0, sizeof(g_id));
11507 + memset(g_fw_version, 0, sizeof(g_fw_version));
11508 + memset(g_hw_version, 0, sizeof(g_hw_version));
11509 +
11510 + spi = pisnd_spi_find_device();
11511 +
11512 + if (spi != NULL) {
11513 + printd("initializing spi!\n");
11514 + pisnd_spi_device = spi;
11515 + ret = spi_setup(pisnd_spi_device);
11516 + } else {
11517 + printe("SPI device not found, deferring!\n");
11518 + return -EPROBE_DEFER;
11519 + }
11520 +
11521 + ret = pisnd_spi_gpio_init(dev);
11522 +
11523 + if (ret < 0) {
11524 + printe("SPI GPIO init failed: %d\n", ret);
11525 + spi_dev_put(pisnd_spi_device);
11526 + pisnd_spi_device = NULL;
11527 + pisnd_spi_gpio_uninit();
11528 + return ret;
11529 + }
11530 +
11531 + ret = spi_read_info();
11532 +
11533 + if (ret < 0) {
11534 + printe("Reading card info failed: %d\n", ret);
11535 + spi_dev_put(pisnd_spi_device);
11536 + pisnd_spi_device = NULL;
11537 + pisnd_spi_gpio_uninit();
11538 + return ret;
11539 + }
11540 +
11541 + /* Flash the LEDs. */
11542 + spi_transfer16(0xf008);
11543 +
11544 + ret = pisnd_spi_gpio_irq_init(dev);
11545 + if (ret < 0) {
11546 + printe("SPI irq request failed: %d\n", ret);
11547 + spi_dev_put(pisnd_spi_device);
11548 + pisnd_spi_device = NULL;
11549 + pisnd_spi_gpio_irq_uninit();
11550 + pisnd_spi_gpio_uninit();
11551 + }
11552 +
11553 + ret = pisnd_init_workqueues();
11554 + if (ret != 0) {
11555 + printe("Workqueue initialization failed: %d\n", ret);
11556 + spi_dev_put(pisnd_spi_device);
11557 + pisnd_spi_device = NULL;
11558 + pisnd_spi_gpio_irq_uninit();
11559 + pisnd_spi_gpio_uninit();
11560 + pisnd_uninit_workqueues();
11561 + return ret;
11562 + }
11563 +
11564 + if (pisnd_spi_has_more()) {
11565 + printd("data is available, scheduling from init\n");
11566 + pisnd_schedule_process(TASK_PROCESS);
11567 + }
11568 +
11569 + return 0;
11570 +}
11571 +
11572 +static void pisnd_spi_uninit(void)
11573 +{
11574 + pisnd_uninit_workqueues();
11575 +
11576 + spi_dev_put(pisnd_spi_device);
11577 + pisnd_spi_device = NULL;
11578 +
11579 + pisnd_spi_gpio_irq_uninit();
11580 + pisnd_spi_gpio_uninit();
11581 +}
11582 +
11583 +static void pisnd_spi_flash_leds(uint8_t duration)
11584 +{
11585 + g_ledFlashDuration = duration;
11586 + g_ledFlashDurationChanged = true;
11587 + printd("schedule from spi_flash_leds\n");
11588 + pisnd_schedule_process(TASK_PROCESS);
11589 +}
11590 +
11591 +static void pisnd_spi_flush(void)
11592 +{
11593 + while (!kfifo_is_empty(&spi_fifo_out)) {
11594 + pisnd_spi_start();
11595 + flush_workqueue(pisnd_workqueue);
11596 + }
11597 +}
11598 +
11599 +static void pisnd_spi_start(void)
11600 +{
11601 + printd("schedule from spi_start\n");
11602 + pisnd_schedule_process(TASK_PROCESS);
11603 +}
11604 +
11605 +static uint8_t pisnd_spi_recv(uint8_t *buffer, uint8_t length)
11606 +{
11607 + return kfifo_out(&spi_fifo_in, buffer, length);
11608 +}
11609 +
11610 +static void pisnd_spi_set_callback(pisnd_spi_recv_cb cb, void *data)
11611 +{
11612 + g_recvData = data;
11613 + g_recvCallback = cb;
11614 +}
11615 +
11616 +static const char *pisnd_spi_get_serial(void)
11617 +{
11618 + return g_serial_num;
11619 +}
11620 +
11621 +static const char *pisnd_spi_get_id(void)
11622 +{
11623 + return g_id;
11624 +}
11625 +
11626 +static const char *pisnd_spi_get_fw_version(void)
11627 +{
11628 + return g_fw_version;
11629 +}
11630 +
11631 +static const char *pisnd_spi_get_hw_version(void)
11632 +{
11633 + return g_hw_version;
11634 +}
11635 +
11636 +static const struct of_device_id pisound_of_match[] = {
11637 + { .compatible = "blokaslabs,pisound", },
11638 + { .compatible = "blokaslabs,pisound-spi", },
11639 + {},
11640 +};
11641 +
11642 +enum {
11643 + SWITCH = 0,
11644 + VOLUME = 1,
11645 +};
11646 +
11647 +static int pisnd_ctl_info(struct snd_kcontrol *kcontrol,
11648 + struct snd_ctl_elem_info *uinfo)
11649 +{
11650 + if (kcontrol->private_value == SWITCH) {
11651 + uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
11652 + uinfo->count = 1;
11653 + uinfo->value.integer.min = 0;
11654 + uinfo->value.integer.max = 1;
11655 + return 0;
11656 + } else if (kcontrol->private_value == VOLUME) {
11657 + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
11658 + uinfo->count = 1;
11659 + uinfo->value.integer.min = 0;
11660 + uinfo->value.integer.max = 100;
11661 + return 0;
11662 + }
11663 + return -EINVAL;
11664 +}
11665 +
11666 +static int pisnd_ctl_get(struct snd_kcontrol *kcontrol,
11667 + struct snd_ctl_elem_value *ucontrol)
11668 +{
11669 + if (kcontrol->private_value == SWITCH) {
11670 + ucontrol->value.integer.value[0] = 1;
11671 + return 0;
11672 + } else if (kcontrol->private_value == VOLUME) {
11673 + ucontrol->value.integer.value[0] = 100;
11674 + return 0;
11675 + }
11676 +
11677 + return -EINVAL;
11678 +}
11679 +
11680 +static struct snd_kcontrol_new pisnd_ctl[] = {
11681 + {
11682 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11683 + .name = "PCM Playback Switch",
11684 + .index = 0,
11685 + .private_value = SWITCH,
11686 + .access = SNDRV_CTL_ELEM_ACCESS_READ,
11687 + .info = pisnd_ctl_info,
11688 + .get = pisnd_ctl_get,
11689 + },
11690 + {
11691 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11692 + .name = "PCM Playback Volume",
11693 + .index = 0,
11694 + .private_value = VOLUME,
11695 + .access = SNDRV_CTL_ELEM_ACCESS_READ,
11696 + .info = pisnd_ctl_info,
11697 + .get = pisnd_ctl_get,
11698 + },
11699 +};
11700 +
11701 +static int pisnd_ctl_init(struct snd_card *card)
11702 +{
11703 + int err, i;
11704 +
11705 + for (i = 0; i < ARRAY_SIZE(pisnd_ctl); ++i) {
11706 + err = snd_ctl_add(card, snd_ctl_new1(&pisnd_ctl[i], NULL));
11707 + if (err < 0)
11708 + return err;
11709 + }
11710 +
11711 + return 0;
11712 +}
11713 +
11714 +static int pisnd_ctl_uninit(void)
11715 +{
11716 + return 0;
11717 +}
11718 +
11719 +static struct gpio_desc *osr0, *osr1, *osr2;
11720 +static struct gpio_desc *reset;
11721 +static struct gpio_desc *button;
11722 +
11723 +static int pisnd_hw_params(
11724 + struct snd_pcm_substream *substream,
11725 + struct snd_pcm_hw_params *params
11726 + )
11727 +{
11728 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
11729 + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
11730 +
11731 + /* Pisound runs on fixed 32 clock counts per channel,
11732 + * as generated by the master ADC.
11733 + */
11734 + snd_soc_dai_set_bclk_ratio(cpu_dai, 32*2);
11735 +
11736 + printd("rate = %d\n", params_rate(params));
11737 + printd("ch = %d\n", params_channels(params));
11738 + printd("bits = %u\n",
11739 + snd_pcm_format_physical_width(params_format(params)));
11740 + printd("format = %d\n", params_format(params));
11741 +
11742 + gpiod_set_value(reset, false);
11743 +
11744 + switch (params_rate(params)) {
11745 + case 48000:
11746 + gpiod_set_value(osr0, true);
11747 + gpiod_set_value(osr1, false);
11748 + gpiod_set_value(osr2, false);
11749 + break;
11750 + case 96000:
11751 + gpiod_set_value(osr0, true);
11752 + gpiod_set_value(osr1, false);
11753 + gpiod_set_value(osr2, true);
11754 + break;
11755 + case 192000:
11756 + gpiod_set_value(osr0, true);
11757 + gpiod_set_value(osr1, true);
11758 + gpiod_set_value(osr2, true);
11759 + break;
11760 + default:
11761 + printe("Unsupported rate %u!\n", params_rate(params));
11762 + return -EINVAL;
11763 + }
11764 +
11765 + gpiod_set_value(reset, true);
11766 +
11767 + return 0;
11768 +}
11769 +
11770 +static unsigned int rates[3] = {
11771 + 48000, 96000, 192000
11772 +};
11773 +
11774 +static struct snd_pcm_hw_constraint_list constraints_rates = {
11775 + .count = ARRAY_SIZE(rates),
11776 + .list = rates,
11777 + .mask = 0,
11778 +};
11779 +
11780 +static int pisnd_startup(struct snd_pcm_substream *substream)
11781 +{
11782 + int err = snd_pcm_hw_constraint_list(
11783 + substream->runtime,
11784 + 0,
11785 + SNDRV_PCM_HW_PARAM_RATE,
11786 + &constraints_rates
11787 + );
11788 +
11789 + if (err < 0)
11790 + return err;
11791 +
11792 + err = snd_pcm_hw_constraint_single(
11793 + substream->runtime,
11794 + SNDRV_PCM_HW_PARAM_CHANNELS,
11795 + 2
11796 + );
11797 +
11798 + if (err < 0)
11799 + return err;
11800 +
11801 + err = snd_pcm_hw_constraint_mask64(
11802 + substream->runtime,
11803 + SNDRV_PCM_HW_PARAM_FORMAT,
11804 + SNDRV_PCM_FMTBIT_S16_LE |
11805 + SNDRV_PCM_FMTBIT_S24_LE |
11806 + SNDRV_PCM_FMTBIT_S32_LE
11807 + );
11808 +
11809 + if (err < 0)
11810 + return err;
11811 +
11812 + return 0;
11813 +}
11814 +
11815 +static struct snd_soc_ops pisnd_ops = {
11816 + .startup = pisnd_startup,
11817 + .hw_params = pisnd_hw_params,
11818 +};
11819 +
11820 +SND_SOC_DAILINK_DEFS(pisnd,
11821 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
11822 + DAILINK_COMP_ARRAY(COMP_DUMMY()),
11823 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
11824 +
11825 +static struct snd_soc_dai_link pisnd_dai[] = {
11826 + {
11827 + .name = "pisound",
11828 + .stream_name = "pisound",
11829 + .dai_fmt =
11830 + SND_SOC_DAIFMT_I2S |
11831 + SND_SOC_DAIFMT_NB_NF |
11832 + SND_SOC_DAIFMT_CBM_CFM,
11833 + .ops = &pisnd_ops,
11834 + SND_SOC_DAILINK_REG(pisnd),
11835 + },
11836 +};
11837 +
11838 +static int pisnd_card_probe(struct snd_soc_card *card)
11839 +{
11840 + int err = pisnd_midi_init(card->snd_card);
11841 +
11842 + if (err < 0) {
11843 + printe("pisnd_midi_init failed: %d\n", err);
11844 + return err;
11845 + }
11846 +
11847 + err = pisnd_ctl_init(card->snd_card);
11848 + if (err < 0) {
11849 + printe("pisnd_ctl_init failed: %d\n", err);
11850 + return err;
11851 + }
11852 +
11853 + return 0;
11854 +}
11855 +
11856 +static int pisnd_card_remove(struct snd_soc_card *card)
11857 +{
11858 + pisnd_ctl_uninit();
11859 + pisnd_midi_uninit();
11860 + return 0;
11861 +}
11862 +
11863 +static struct snd_soc_card pisnd_card = {
11864 + .name = "pisound",
11865 + .owner = THIS_MODULE,
11866 + .dai_link = pisnd_dai,
11867 + .num_links = ARRAY_SIZE(pisnd_dai),
11868 + .probe = pisnd_card_probe,
11869 + .remove = pisnd_card_remove,
11870 +};
11871 +
11872 +static int pisnd_init_gpio(struct device *dev)
11873 +{
11874 + osr0 = gpiod_get_index(dev, "osr", 0, GPIOD_ASIS);
11875 + osr1 = gpiod_get_index(dev, "osr", 1, GPIOD_ASIS);
11876 + osr2 = gpiod_get_index(dev, "osr", 2, GPIOD_ASIS);
11877 +
11878 + reset = gpiod_get_index(dev, "reset", 0, GPIOD_ASIS);
11879 +
11880 + button = gpiod_get_index(dev, "button", 0, GPIOD_ASIS);
11881 +
11882 + gpiod_direction_output(osr0, 1);
11883 + gpiod_direction_output(osr1, 1);
11884 + gpiod_direction_output(osr2, 1);
11885 + gpiod_direction_output(reset, 1);
11886 +
11887 + gpiod_set_value(reset, false);
11888 + gpiod_set_value(osr0, true);
11889 + gpiod_set_value(osr1, false);
11890 + gpiod_set_value(osr2, false);
11891 + gpiod_set_value(reset, true);
11892 +
11893 + gpiod_export(button, false);
11894 +
11895 + return 0;
11896 +}
11897 +
11898 +static int pisnd_uninit_gpio(void)
11899 +{
11900 + int i;
11901 +
11902 + struct gpio_desc **gpios[] = {
11903 + &osr0, &osr1, &osr2, &reset, &button,
11904 + };
11905 +
11906 + gpiod_unexport(button);
11907 +
11908 + for (i = 0; i < ARRAY_SIZE(gpios); ++i) {
11909 + if (*gpios[i] == NULL) {
11910 + printd("weird, GPIO[%d] is NULL already\n", i);
11911 + continue;
11912 + }
11913 +
11914 + gpiod_put(*gpios[i]);
11915 + *gpios[i] = NULL;
11916 + }
11917 +
11918 + return 0;
11919 +}
11920 +
11921 +static struct kobject *pisnd_kobj;
11922 +
11923 +static ssize_t pisnd_serial_show(
11924 + struct kobject *kobj,
11925 + struct kobj_attribute *attr,
11926 + char *buf
11927 + )
11928 +{
11929 + return sprintf(buf, "%s\n", pisnd_spi_get_serial());
11930 +}
11931 +
11932 +static ssize_t pisnd_id_show(
11933 + struct kobject *kobj,
11934 + struct kobj_attribute *attr,
11935 + char *buf
11936 + )
11937 +{
11938 + return sprintf(buf, "%s\n", pisnd_spi_get_id());
11939 +}
11940 +
11941 +static ssize_t pisnd_fw_version_show(
11942 + struct kobject *kobj,
11943 + struct kobj_attribute *attr,
11944 + char *buf
11945 + )
11946 +{
11947 + return sprintf(buf, "%s\n", pisnd_spi_get_fw_version());
11948 +}
11949 +
11950 +static ssize_t pisnd_hw_version_show(
11951 + struct kobject *kobj,
11952 + struct kobj_attribute *attr,
11953 + char *buf
11954 +)
11955 +{
11956 + return sprintf(buf, "%s\n", pisnd_spi_get_hw_version());
11957 +}
11958 +
11959 +static ssize_t pisnd_led_store(
11960 + struct kobject *kobj,
11961 + struct kobj_attribute *attr,
11962 + const char *buf,
11963 + size_t length
11964 + )
11965 +{
11966 + uint32_t timeout;
11967 + int err;
11968 +
11969 + err = kstrtou32(buf, 10, &timeout);
11970 +
11971 + if (err == 0 && timeout <= 255)
11972 + pisnd_spi_flash_leds(timeout);
11973 +
11974 + return length;
11975 +}
11976 +
11977 +static struct kobj_attribute pisnd_serial_attribute =
11978 + __ATTR(serial, 0444, pisnd_serial_show, NULL);
11979 +static struct kobj_attribute pisnd_id_attribute =
11980 + __ATTR(id, 0444, pisnd_id_show, NULL);
11981 +static struct kobj_attribute pisnd_fw_version_attribute =
11982 + __ATTR(version, 0444, pisnd_fw_version_show, NULL);
11983 +static struct kobj_attribute pisnd_hw_version_attribute =
11984 +__ATTR(hw_version, 0444, pisnd_hw_version_show, NULL);
11985 +static struct kobj_attribute pisnd_led_attribute =
11986 + __ATTR(led, 0644, NULL, pisnd_led_store);
11987 +
11988 +static struct attribute *attrs[] = {
11989 + &pisnd_serial_attribute.attr,
11990 + &pisnd_id_attribute.attr,
11991 + &pisnd_fw_version_attribute.attr,
11992 + &pisnd_hw_version_attribute.attr,
11993 + &pisnd_led_attribute.attr,
11994 + NULL
11995 +};
11996 +
11997 +static struct attribute_group attr_group = { .attrs = attrs };
11998 +
11999 +static int pisnd_probe(struct platform_device *pdev)
12000 +{
12001 + int ret = 0;
12002 + int i;
12003 +
12004 + ret = pisnd_spi_init(&pdev->dev);
12005 + if (ret < 0) {
12006 + printe("pisnd_spi_init failed: %d\n", ret);
12007 + return ret;
12008 + }
12009 +
12010 + printi("Detected Pisound card:\n");
12011 + printi("\tSerial: %s\n", pisnd_spi_get_serial());
12012 + printi("\tFirmware Version: %s\n", pisnd_spi_get_fw_version());
12013 + printi("\tHardware Version: %s\n", pisnd_spi_get_hw_version());
12014 + printi("\tId: %s\n", pisnd_spi_get_id());
12015 +
12016 + pisnd_kobj = kobject_create_and_add("pisound", kernel_kobj);
12017 + if (!pisnd_kobj) {
12018 + pisnd_spi_uninit();
12019 + return -ENOMEM;
12020 + }
12021 +
12022 + ret = sysfs_create_group(pisnd_kobj, &attr_group);
12023 + if (ret < 0) {
12024 + pisnd_spi_uninit();
12025 + kobject_put(pisnd_kobj);
12026 + return -ENOMEM;
12027 + }
12028 +
12029 + pisnd_init_gpio(&pdev->dev);
12030 + pisnd_card.dev = &pdev->dev;
12031 +
12032 + if (pdev->dev.of_node) {
12033 + struct device_node *i2s_node;
12034 +
12035 + i2s_node = of_parse_phandle(
12036 + pdev->dev.of_node,
12037 + "i2s-controller",
12038 + 0
12039 + );
12040 +
12041 + for (i = 0; i < pisnd_card.num_links; ++i) {
12042 + struct snd_soc_dai_link *dai = &pisnd_dai[i];
12043 +
12044 + if (i2s_node) {
12045 + dai->cpus->dai_name = NULL;
12046 + dai->cpus->of_node = i2s_node;
12047 + dai->platforms->name = NULL;
12048 + dai->platforms->of_node = i2s_node;
12049 + dai->stream_name = pisnd_spi_get_serial();
12050 + }
12051 + }
12052 + }
12053 +
12054 + ret = snd_soc_register_card(&pisnd_card);
12055 +
12056 + if (ret < 0) {
12057 + if (ret != -EPROBE_DEFER)
12058 + printe("snd_soc_register_card() failed: %d\n", ret);
12059 + pisnd_uninit_gpio();
12060 + kobject_put(pisnd_kobj);
12061 + pisnd_spi_uninit();
12062 + }
12063 +
12064 + return ret;
12065 +}
12066 +
12067 +static int pisnd_remove(struct platform_device *pdev)
12068 +{
12069 + printi("Unloading.\n");
12070 +
12071 + if (pisnd_kobj) {
12072 + kobject_put(pisnd_kobj);
12073 + pisnd_kobj = NULL;
12074 + }
12075 +
12076 + pisnd_spi_uninit();
12077 +
12078 + /* Turn off */
12079 + gpiod_set_value(reset, false);
12080 + pisnd_uninit_gpio();
12081 +
12082 + return snd_soc_unregister_card(&pisnd_card);
12083 +}
12084 +
12085 +MODULE_DEVICE_TABLE(of, pisound_of_match);
12086 +
12087 +static struct platform_driver pisnd_driver = {
12088 + .driver = {
12089 + .name = "snd-rpi-pisound",
12090 + .owner = THIS_MODULE,
12091 + .of_match_table = pisound_of_match,
12092 + },
12093 + .probe = pisnd_probe,
12094 + .remove = pisnd_remove,
12095 +};
12096 +
12097 +module_platform_driver(pisnd_driver);
12098 +
12099 +MODULE_AUTHOR("Giedrius Trainavicius <giedrius@blokas.io>");
12100 +MODULE_DESCRIPTION("ASoC Driver for Pisound, https://blokas.io/pisound");
12101 +MODULE_LICENSE("GPL v2");
12102 --- /dev/null
12103 +++ b/sound/soc/bcm/rpi-cirrus.c
12104 @@ -0,0 +1,1025 @@
12105 +/*
12106 + * ASoC machine driver for Cirrus Logic Audio Card
12107 + * (with WM5102 and WM8804 codecs)
12108 + *
12109 + * Copyright 2015-2017 Matthias Reichl <hias@horus.com>
12110 + *
12111 + * Based on rpi-cirrus-sound-pi driver (c) Wolfson / Cirrus Logic Inc.
12112 + *
12113 + * This program is free software; you can redistribute it and/or modify
12114 + * it under the terms of the GNU General Public License version 2 as
12115 + * published by the Free Software Foundation.
12116 + */
12117 +
12118 +#include <linux/module.h>
12119 +#include <linux/mutex.h>
12120 +#include <linux/slab.h>
12121 +#include <linux/list.h>
12122 +#include <linux/delay.h>
12123 +#include <sound/pcm_params.h>
12124 +
12125 +#include <linux/mfd/arizona/registers.h>
12126 +
12127 +#include "../codecs/wm5102.h"
12128 +#include "../codecs/wm8804.h"
12129 +
12130 +#define WM8804_CLKOUT_HZ 12000000
12131 +
12132 +#define RPI_CIRRUS_DEFAULT_RATE 44100
12133 +#define WM5102_MAX_SYSCLK_1 49152000 /* max sysclk for 4K family */
12134 +#define WM5102_MAX_SYSCLK_2 45158400 /* max sysclk for 11.025K family */
12135 +
12136 +static inline unsigned int calc_sysclk(unsigned int rate)
12137 +{
12138 + return (rate % 4000) ? WM5102_MAX_SYSCLK_2 : WM5102_MAX_SYSCLK_1;
12139 +}
12140 +
12141 +enum {
12142 + DAI_WM5102 = 0,
12143 + DAI_WM8804,
12144 +};
12145 +
12146 +struct rpi_cirrus_priv {
12147 + /* mutex for synchronzing FLL1 access with DAPM */
12148 + struct mutex lock;
12149 + unsigned int card_rate;
12150 + int sync_path_enable;
12151 + int fll1_freq; /* negative means RefClock in spdif rx case */
12152 +
12153 + /* track hw params/free for substreams */
12154 + unsigned int params_set;
12155 + unsigned int min_rate_idx, max_rate_idx;
12156 + unsigned char iec958_status[4];
12157 +};
12158 +
12159 +/* helper functions */
12160 +static inline struct snd_soc_pcm_runtime *get_wm5102_runtime(
12161 + struct snd_soc_card *card) {
12162 + return snd_soc_get_pcm_runtime(card, &card->dai_link[DAI_WM5102]);
12163 +}
12164 +
12165 +static inline struct snd_soc_pcm_runtime *get_wm8804_runtime(
12166 + struct snd_soc_card *card) {
12167 + return snd_soc_get_pcm_runtime(card, &card->dai_link[DAI_WM8804]);
12168 +}
12169 +
12170 +
12171 +struct rate_info {
12172 + unsigned int value;
12173 + char *text;
12174 +};
12175 +
12176 +static struct rate_info min_rates[] = {
12177 + { 0, "off"},
12178 + { 32000, "32kHz"},
12179 + { 44100, "44.1kHz"}
12180 +};
12181 +
12182 +#define NUM_MIN_RATES ARRAY_SIZE(min_rates)
12183 +
12184 +static int rpi_cirrus_min_rate_info(struct snd_kcontrol *kcontrol,
12185 + struct snd_ctl_elem_info *uinfo)
12186 +{
12187 + uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
12188 + uinfo->count = 1;
12189 + uinfo->value.enumerated.items = NUM_MIN_RATES;
12190 +
12191 + if (uinfo->value.enumerated.item >= NUM_MIN_RATES)
12192 + uinfo->value.enumerated.item = NUM_MIN_RATES - 1;
12193 + strcpy(uinfo->value.enumerated.name,
12194 + min_rates[uinfo->value.enumerated.item].text);
12195 + return 0;
12196 +}
12197 +
12198 +static int rpi_cirrus_min_rate_get(struct snd_kcontrol *kcontrol,
12199 + struct snd_ctl_elem_value *ucontrol)
12200 +{
12201 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
12202 + struct rpi_cirrus_priv *priv = snd_soc_card_get_drvdata(card);
12203 +
12204 + ucontrol->value.enumerated.item[0] = priv->min_rate_idx;
12205 + return 0;
12206 +}
12207 +
12208 +static int rpi_cirrus_min_rate_put(struct snd_kcontrol *kcontrol,
12209 + struct snd_ctl_elem_value *ucontrol)
12210 +{
12211 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
12212 + struct rpi_cirrus_priv *priv = snd_soc_card_get_drvdata(card);
12213 + int changed = 0;
12214 +
12215 + if (priv->min_rate_idx != ucontrol->value.enumerated.item[0]) {
12216 + changed = 1;
12217 + priv->min_rate_idx = ucontrol->value.enumerated.item[0];
12218 + }
12219 +
12220 + return changed;
12221 +}
12222 +
12223 +static struct rate_info max_rates[] = {
12224 + { 0, "off"},
12225 + { 48000, "48kHz"},
12226 + { 96000, "96kHz"}
12227 +};
12228 +
12229 +#define NUM_MAX_RATES ARRAY_SIZE(max_rates)
12230 +
12231 +static int rpi_cirrus_max_rate_info(struct snd_kcontrol *kcontrol,
12232 + struct snd_ctl_elem_info *uinfo)
12233 +{
12234 + uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
12235 + uinfo->count = 1;
12236 + uinfo->value.enumerated.items = NUM_MAX_RATES;
12237 + if (uinfo->value.enumerated.item >= NUM_MAX_RATES)
12238 + uinfo->value.enumerated.item = NUM_MAX_RATES - 1;
12239 + strcpy(uinfo->value.enumerated.name,
12240 + max_rates[uinfo->value.enumerated.item].text);
12241 + return 0;
12242 +}
12243 +
12244 +static int rpi_cirrus_max_rate_get(struct snd_kcontrol *kcontrol,
12245 + struct snd_ctl_elem_value *ucontrol)
12246 +{
12247 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
12248 + struct rpi_cirrus_priv *priv = snd_soc_card_get_drvdata(card);
12249 +
12250 + ucontrol->value.enumerated.item[0] = priv->max_rate_idx;
12251 + return 0;
12252 +}
12253 +
12254 +static int rpi_cirrus_max_rate_put(struct snd_kcontrol *kcontrol,
12255 + struct snd_ctl_elem_value *ucontrol)
12256 +{
12257 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
12258 + struct rpi_cirrus_priv *priv = snd_soc_card_get_drvdata(card);
12259 + int changed = 0;
12260 +
12261 + if (priv->max_rate_idx != ucontrol->value.enumerated.item[0]) {
12262 + changed = 1;
12263 + priv->max_rate_idx = ucontrol->value.enumerated.item[0];
12264 + }
12265 +
12266 + return changed;
12267 +}
12268 +
12269 +static int rpi_cirrus_spdif_info(struct snd_kcontrol *kcontrol,
12270 + struct snd_ctl_elem_info *uinfo)
12271 +{
12272 + uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
12273 + uinfo->count = 1;
12274 + return 0;
12275 +}
12276 +
12277 +static int rpi_cirrus_spdif_playback_get(struct snd_kcontrol *kcontrol,
12278 + struct snd_ctl_elem_value *ucontrol)
12279 +{
12280 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
12281 + struct rpi_cirrus_priv *priv = snd_soc_card_get_drvdata(card);
12282 + int i;
12283 +
12284 + for (i = 0; i < 4; i++)
12285 + ucontrol->value.iec958.status[i] = priv->iec958_status[i];
12286 +
12287 + return 0;
12288 +}
12289 +
12290 +static int rpi_cirrus_spdif_playback_put(struct snd_kcontrol *kcontrol,
12291 + struct snd_ctl_elem_value *ucontrol)
12292 +{
12293 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
12294 + struct snd_soc_component *wm8804_component =
12295 + asoc_rtd_to_codec(get_wm8804_runtime(card), 0)->component;
12296 + struct rpi_cirrus_priv *priv = snd_soc_card_get_drvdata(card);
12297 + unsigned char *stat = priv->iec958_status;
12298 + unsigned char *ctrl_stat = ucontrol->value.iec958.status;
12299 + unsigned int mask;
12300 + int i, changed = 0;
12301 +
12302 + for (i = 0; i < 4; i++) {
12303 + mask = (i == 3) ? 0x3f : 0xff;
12304 + if ((ctrl_stat[i] & mask) != (stat[i] & mask)) {
12305 + changed = 1;
12306 + stat[i] = ctrl_stat[i] & mask;
12307 + snd_soc_component_update_bits(wm8804_component,
12308 + WM8804_SPDTX1 + i, mask, stat[i]);
12309 + }
12310 + }
12311 +
12312 + return changed;
12313 +}
12314 +
12315 +static int rpi_cirrus_spdif_mask_get(struct snd_kcontrol *kcontrol,
12316 + struct snd_ctl_elem_value *ucontrol)
12317 +{
12318 + ucontrol->value.iec958.status[0] = 0xff;
12319 + ucontrol->value.iec958.status[1] = 0xff;
12320 + ucontrol->value.iec958.status[2] = 0xff;
12321 + ucontrol->value.iec958.status[3] = 0x3f;
12322 +
12323 + return 0;
12324 +}
12325 +
12326 +static int rpi_cirrus_spdif_capture_get(struct snd_kcontrol *kcontrol,
12327 + struct snd_ctl_elem_value *ucontrol)
12328 +{
12329 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
12330 + struct snd_soc_component *wm8804_component =
12331 + asoc_rtd_to_codec(get_wm8804_runtime(card), 0)->component;
12332 + unsigned int val, mask;
12333 + int i;
12334 +
12335 + for (i = 0; i < 4; i++) {
12336 + val = snd_soc_component_read(wm8804_component,
12337 + WM8804_RXCHAN1 + i);
12338 + mask = (i == 3) ? 0x3f : 0xff;
12339 + ucontrol->value.iec958.status[i] = val & mask;
12340 + }
12341 +
12342 + return 0;
12343 +}
12344 +
12345 +#define SPDIF_FLAG_CTRL(desc, reg, bit, invert) \
12346 +{ \
12347 + .access = SNDRV_CTL_ELEM_ACCESS_READ \
12348 + | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
12349 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
12350 + .name = SNDRV_CTL_NAME_IEC958("", CAPTURE, NONE) \
12351 + desc " Flag", \
12352 + .info = snd_ctl_boolean_mono_info, \
12353 + .get = rpi_cirrus_spdif_status_flag_get, \
12354 + .private_value = \
12355 + (bit) | ((reg) << 8) | ((invert) << 16) \
12356 +}
12357 +
12358 +static int rpi_cirrus_spdif_status_flag_get(struct snd_kcontrol *kcontrol,
12359 + struct snd_ctl_elem_value *ucontrol)
12360 +{
12361 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
12362 + struct snd_soc_component *wm8804_component =
12363 + asoc_rtd_to_codec(get_wm8804_runtime(card), 0)->component;
12364 +
12365 + unsigned int bit = kcontrol->private_value & 0xff;
12366 + unsigned int reg = (kcontrol->private_value >> 8) & 0xff;
12367 + unsigned int invert = (kcontrol->private_value >> 16) & 0xff;
12368 + unsigned int val;
12369 + bool flag;
12370 +
12371 + val = snd_soc_component_read(wm8804_component, reg);
12372 +
12373 + flag = val & (1 << bit);
12374 +
12375 + ucontrol->value.integer.value[0] = invert ? !flag : flag;
12376 +
12377 + return 0;
12378 +}
12379 +
12380 +static const char * const recovered_frequency_texts[] = {
12381 + "176.4/192 kHz",
12382 + "88.2/96 kHz",
12383 + "44.1/48 kHz",
12384 + "32 kHz"
12385 +};
12386 +
12387 +#define NUM_RECOVERED_FREQUENCIES \
12388 + ARRAY_SIZE(recovered_frequency_texts)
12389 +
12390 +static int rpi_cirrus_recovered_frequency_info(struct snd_kcontrol *kcontrol,
12391 + struct snd_ctl_elem_info *uinfo)
12392 +{
12393 + uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
12394 + uinfo->count = 1;
12395 + uinfo->value.enumerated.items = NUM_RECOVERED_FREQUENCIES;
12396 + if (uinfo->value.enumerated.item >= NUM_RECOVERED_FREQUENCIES)
12397 + uinfo->value.enumerated.item = NUM_RECOVERED_FREQUENCIES - 1;
12398 + strcpy(uinfo->value.enumerated.name,
12399 + recovered_frequency_texts[uinfo->value.enumerated.item]);
12400 + return 0;
12401 +}
12402 +
12403 +static int rpi_cirrus_recovered_frequency_get(struct snd_kcontrol *kcontrol,
12404 + struct snd_ctl_elem_value *ucontrol)
12405 +{
12406 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
12407 + struct snd_soc_component *wm8804_component =
12408 + asoc_rtd_to_codec(get_wm8804_runtime(card), 0)->component;
12409 + unsigned int val;
12410 +
12411 + val = snd_soc_component_read(wm8804_component, WM8804_SPDSTAT);
12412 +
12413 + ucontrol->value.enumerated.item[0] = (val >> 4) & 0x03;
12414 + return 0;
12415 +}
12416 +
12417 +static const struct snd_kcontrol_new rpi_cirrus_controls[] = {
12418 + {
12419 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12420 + .name = "Min Sample Rate",
12421 + .info = rpi_cirrus_min_rate_info,
12422 + .get = rpi_cirrus_min_rate_get,
12423 + .put = rpi_cirrus_min_rate_put,
12424 + },
12425 + {
12426 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12427 + .name = "Max Sample Rate",
12428 + .info = rpi_cirrus_max_rate_info,
12429 + .get = rpi_cirrus_max_rate_get,
12430 + .put = rpi_cirrus_max_rate_put,
12431 + },
12432 + {
12433 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12434 + .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT),
12435 + .info = rpi_cirrus_spdif_info,
12436 + .get = rpi_cirrus_spdif_playback_get,
12437 + .put = rpi_cirrus_spdif_playback_put,
12438 + },
12439 + {
12440 + .access = SNDRV_CTL_ELEM_ACCESS_READ
12441 + | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
12442 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12443 + .name = SNDRV_CTL_NAME_IEC958("", CAPTURE, DEFAULT),
12444 + .info = rpi_cirrus_spdif_info,
12445 + .get = rpi_cirrus_spdif_capture_get,
12446 + },
12447 + {
12448 + .access = SNDRV_CTL_ELEM_ACCESS_READ,
12449 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12450 + .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, MASK),
12451 + .info = rpi_cirrus_spdif_info,
12452 + .get = rpi_cirrus_spdif_mask_get,
12453 + },
12454 + {
12455 + .access = SNDRV_CTL_ELEM_ACCESS_READ
12456 + | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
12457 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12458 + .name = SNDRV_CTL_NAME_IEC958("", CAPTURE, NONE)
12459 + "Recovered Frequency",
12460 + .info = rpi_cirrus_recovered_frequency_info,
12461 + .get = rpi_cirrus_recovered_frequency_get,
12462 + },
12463 + SPDIF_FLAG_CTRL("Audio", WM8804_SPDSTAT, 0, 1),
12464 + SPDIF_FLAG_CTRL("Non-PCM", WM8804_SPDSTAT, 1, 0),
12465 + SPDIF_FLAG_CTRL("Copyright", WM8804_SPDSTAT, 2, 1),
12466 + SPDIF_FLAG_CTRL("De-Emphasis", WM8804_SPDSTAT, 3, 0),
12467 + SPDIF_FLAG_CTRL("Lock", WM8804_SPDSTAT, 6, 1),
12468 + SPDIF_FLAG_CTRL("Invalid", WM8804_INTSTAT, 1, 0),
12469 + SPDIF_FLAG_CTRL("TransErr", WM8804_INTSTAT, 3, 0),
12470 +};
12471 +
12472 +static const char * const linein_micbias_texts[] = {
12473 + "off", "on",
12474 +};
12475 +
12476 +static SOC_ENUM_SINGLE_VIRT_DECL(linein_micbias_enum,
12477 + linein_micbias_texts);
12478 +
12479 +static const struct snd_kcontrol_new linein_micbias_mux =
12480 + SOC_DAPM_ENUM("Route", linein_micbias_enum);
12481 +
12482 +static int rpi_cirrus_spdif_rx_enable_event(struct snd_soc_dapm_widget *w,
12483 + struct snd_kcontrol *kcontrol, int event);
12484 +
12485 +const struct snd_soc_dapm_widget rpi_cirrus_dapm_widgets[] = {
12486 + SND_SOC_DAPM_MIC("DMIC", NULL),
12487 + SND_SOC_DAPM_MIC("Headset Mic", NULL),
12488 + SND_SOC_DAPM_INPUT("Line Input"),
12489 + SND_SOC_DAPM_MIC("Line Input with Micbias", NULL),
12490 + SND_SOC_DAPM_MUX("Line Input Micbias", SND_SOC_NOPM, 0, 0,
12491 + &linein_micbias_mux),
12492 + SND_SOC_DAPM_INPUT("dummy SPDIF in"),
12493 + SND_SOC_DAPM_PGA_E("dummy SPDIFRX", SND_SOC_NOPM, 0, 0, NULL, 0,
12494 + rpi_cirrus_spdif_rx_enable_event,
12495 + SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
12496 + SND_SOC_DAPM_INPUT("Dummy Input"),
12497 + SND_SOC_DAPM_OUTPUT("Dummy Output"),
12498 +};
12499 +
12500 +const struct snd_soc_dapm_route rpi_cirrus_dapm_routes[] = {
12501 + { "IN1L", NULL, "Headset Mic" },
12502 + { "IN1R", NULL, "Headset Mic" },
12503 + { "Headset Mic", NULL, "MICBIAS1" },
12504 +
12505 + { "IN2L", NULL, "DMIC" },
12506 + { "IN2R", NULL, "DMIC" },
12507 + { "DMIC", NULL, "MICBIAS2" },
12508 +
12509 + { "IN3L", NULL, "Line Input Micbias" },
12510 + { "IN3R", NULL, "Line Input Micbias" },
12511 +
12512 + { "Line Input Micbias", "off", "Line Input" },
12513 + { "Line Input Micbias", "on", "Line Input with Micbias" },
12514 +
12515 + /* Make sure MICVDD is enabled, otherwise we get noise */
12516 + { "Line Input", NULL, "MICVDD" },
12517 + { "Line Input with Micbias", NULL, "MICBIAS3" },
12518 +
12519 + /* Dummy routes to check whether SPDIF RX is enabled or not */
12520 + {"dummy SPDIFRX", NULL, "dummy SPDIF in"},
12521 + {"AIFTX", NULL, "dummy SPDIFRX"},
12522 +
12523 + /*
12524 + * Dummy routes to keep wm5102 from staying off on
12525 + * playback/capture if all mixers are off.
12526 + */
12527 + { "Dummy Output", NULL, "AIF1RX1" },
12528 + { "Dummy Output", NULL, "AIF1RX2" },
12529 + { "AIF1TX1", NULL, "Dummy Input" },
12530 + { "AIF1TX2", NULL, "Dummy Input" },
12531 +};
12532 +
12533 +static int rpi_cirrus_clear_flls(struct snd_soc_card *card,
12534 + struct snd_soc_component *wm5102_component) {
12535 +
12536 + int ret1, ret2;
12537 +
12538 + ret1 = snd_soc_component_set_pll(wm5102_component,
12539 + WM5102_FLL1, ARIZONA_FLL_SRC_NONE, 0, 0);
12540 + ret2 = snd_soc_component_set_pll(wm5102_component,
12541 + WM5102_FLL1_REFCLK, ARIZONA_FLL_SRC_NONE, 0, 0);
12542 +
12543 + if (ret1) {
12544 + dev_warn(card->dev,
12545 + "setting FLL1 to zero failed: %d\n", ret1);
12546 + return ret1;
12547 + }
12548 + if (ret2) {
12549 + dev_warn(card->dev,
12550 + "setting FLL1_REFCLK to zero failed: %d\n", ret2);
12551 + return ret2;
12552 + }
12553 + return 0;
12554 +}
12555 +
12556 +static int rpi_cirrus_set_fll(struct snd_soc_card *card,
12557 + struct snd_soc_component *wm5102_component, unsigned int clk_freq)
12558 +{
12559 + int ret = snd_soc_component_set_pll(wm5102_component,
12560 + WM5102_FLL1,
12561 + ARIZONA_CLK_SRC_MCLK1,
12562 + WM8804_CLKOUT_HZ,
12563 + clk_freq);
12564 + if (ret)
12565 + dev_err(card->dev, "Failed to set FLL1 to %d: %d\n",
12566 + clk_freq, ret);
12567 +
12568 + usleep_range(1000, 2000);
12569 + return ret;
12570 +}
12571 +
12572 +static int rpi_cirrus_set_fll_refclk(struct snd_soc_card *card,
12573 + struct snd_soc_component *wm5102_component,
12574 + unsigned int clk_freq, unsigned int aif2_freq)
12575 +{
12576 + int ret = snd_soc_component_set_pll(wm5102_component,
12577 + WM5102_FLL1_REFCLK,
12578 + ARIZONA_CLK_SRC_MCLK1,
12579 + WM8804_CLKOUT_HZ,
12580 + clk_freq);
12581 + if (ret) {
12582 + dev_err(card->dev,
12583 + "Failed to set FLL1_REFCLK to %d: %d\n",
12584 + clk_freq, ret);
12585 + return ret;
12586 + }
12587 +
12588 + ret = snd_soc_component_set_pll(wm5102_component,
12589 + WM5102_FLL1,
12590 + ARIZONA_CLK_SRC_AIF2BCLK,
12591 + aif2_freq, clk_freq);
12592 + if (ret)
12593 + dev_err(card->dev,
12594 + "Failed to set FLL1 with Sync Clock %d to %d: %d\n",
12595 + aif2_freq, clk_freq, ret);
12596 +
12597 + usleep_range(1000, 2000);
12598 + return ret;
12599 +}
12600 +
12601 +static int rpi_cirrus_spdif_rx_enable_event(struct snd_soc_dapm_widget *w,
12602 + struct snd_kcontrol *kcontrol, int event)
12603 +{
12604 + struct snd_soc_card *card = w->dapm->card;
12605 + struct rpi_cirrus_priv *priv = snd_soc_card_get_drvdata(card);
12606 + struct snd_soc_component *wm5102_component =
12607 + asoc_rtd_to_codec(get_wm5102_runtime(card), 0)->component;
12608 +
12609 + unsigned int clk_freq, aif2_freq;
12610 + int ret = 0;
12611 +
12612 + switch (event) {
12613 + case SND_SOC_DAPM_POST_PMU:
12614 + mutex_lock(&priv->lock);
12615 +
12616 + /* Enable sync path in case of SPDIF capture use case */
12617 +
12618 + clk_freq = calc_sysclk(priv->card_rate);
12619 + aif2_freq = 64 * priv->card_rate;
12620 +
12621 + dev_dbg(card->dev,
12622 + "spdif_rx: changing FLL1 to use Ref Clock clk: %d spdif: %d\n",
12623 + clk_freq, aif2_freq);
12624 +
12625 + ret = rpi_cirrus_clear_flls(card, wm5102_component);
12626 + if (ret) {
12627 + dev_err(card->dev, "spdif_rx: failed to clear FLLs\n");
12628 + goto out;
12629 + }
12630 +
12631 + ret = rpi_cirrus_set_fll_refclk(card, wm5102_component,
12632 + clk_freq, aif2_freq);
12633 +
12634 + if (ret) {
12635 + dev_err(card->dev, "spdif_rx: failed to set FLLs\n");
12636 + goto out;
12637 + }
12638 +
12639 + /* set to negative to indicate we're doing spdif rx */
12640 + priv->fll1_freq = -clk_freq;
12641 + priv->sync_path_enable = 1;
12642 + break;
12643 +
12644 + case SND_SOC_DAPM_POST_PMD:
12645 + mutex_lock(&priv->lock);
12646 + priv->sync_path_enable = 0;
12647 + break;
12648 +
12649 + default:
12650 + return 0;
12651 + }
12652 +
12653 +out:
12654 + mutex_unlock(&priv->lock);
12655 + return ret;
12656 +}
12657 +
12658 +static int rpi_cirrus_set_bias_level(struct snd_soc_card *card,
12659 + struct snd_soc_dapm_context *dapm,
12660 + enum snd_soc_bias_level level)
12661 +{
12662 + struct rpi_cirrus_priv *priv = snd_soc_card_get_drvdata(card);
12663 + struct snd_soc_pcm_runtime *wm5102_runtime = get_wm5102_runtime(card);
12664 + struct snd_soc_component *wm5102_component =
12665 + asoc_rtd_to_codec(wm5102_runtime, 0)->component;
12666 +
12667 + int ret = 0;
12668 + unsigned int clk_freq;
12669 +
12670 + if (dapm->dev != asoc_rtd_to_codec(wm5102_runtime, 0)->dev)
12671 + return 0;
12672 +
12673 + switch (level) {
12674 + case SND_SOC_BIAS_PREPARE:
12675 + if (dapm->bias_level == SND_SOC_BIAS_ON)
12676 + break;
12677 +
12678 + mutex_lock(&priv->lock);
12679 +
12680 + if (!priv->sync_path_enable) {
12681 + clk_freq = calc_sysclk(priv->card_rate);
12682 +
12683 + dev_dbg(card->dev,
12684 + "set_bias: changing FLL1 from %d to %d\n",
12685 + priv->fll1_freq, clk_freq);
12686 +
12687 + ret = rpi_cirrus_set_fll(card,
12688 + wm5102_component, clk_freq);
12689 + if (ret)
12690 + dev_err(card->dev,
12691 + "set_bias: Failed to set FLL1\n");
12692 + else
12693 + priv->fll1_freq = clk_freq;
12694 + }
12695 + mutex_unlock(&priv->lock);
12696 + break;
12697 + default:
12698 + break;
12699 + }
12700 +
12701 + return ret;
12702 +}
12703 +
12704 +static int rpi_cirrus_set_bias_level_post(struct snd_soc_card *card,
12705 + struct snd_soc_dapm_context *dapm,
12706 + enum snd_soc_bias_level level)
12707 +{
12708 + struct rpi_cirrus_priv *priv = snd_soc_card_get_drvdata(card);
12709 + struct snd_soc_pcm_runtime *wm5102_runtime = get_wm5102_runtime(card);
12710 + struct snd_soc_component *wm5102_component =
12711 + asoc_rtd_to_codec(wm5102_runtime, 0)->component;
12712 +
12713 + if (dapm->dev != asoc_rtd_to_codec(wm5102_runtime, 0)->dev)
12714 + return 0;
12715 +
12716 + switch (level) {
12717 + case SND_SOC_BIAS_STANDBY:
12718 + mutex_lock(&priv->lock);
12719 +
12720 + dev_dbg(card->dev,
12721 + "set_bias_post: changing FLL1 from %d to off\n",
12722 + priv->fll1_freq);
12723 +
12724 + if (rpi_cirrus_clear_flls(card, wm5102_component))
12725 + dev_err(card->dev,
12726 + "set_bias_post: failed to clear FLLs\n");
12727 + else
12728 + priv->fll1_freq = 0;
12729 +
12730 + mutex_unlock(&priv->lock);
12731 +
12732 + break;
12733 + default:
12734 + break;
12735 + }
12736 +
12737 + return 0;
12738 +}
12739 +
12740 +static int rpi_cirrus_set_wm8804_pll(struct snd_soc_card *card,
12741 + struct snd_soc_dai *wm8804_dai, unsigned int rate)
12742 +{
12743 + int ret;
12744 +
12745 + /* use 256fs */
12746 + unsigned int clk_freq = rate * 256;
12747 +
12748 + ret = snd_soc_dai_set_pll(wm8804_dai, 0, 0,
12749 + WM8804_CLKOUT_HZ, clk_freq);
12750 + if (ret) {
12751 + dev_err(card->dev,
12752 + "Failed to set WM8804 PLL to %d: %d\n", clk_freq, ret);
12753 + return ret;
12754 + }
12755 +
12756 + /* Set MCLK as PLL Output */
12757 + ret = snd_soc_dai_set_sysclk(wm8804_dai,
12758 + WM8804_TX_CLKSRC_PLL, clk_freq, 0);
12759 + if (ret) {
12760 + dev_err(card->dev,
12761 + "Failed to set MCLK as PLL Output: %d\n", ret);
12762 + return ret;
12763 + }
12764 +
12765 + return ret;
12766 +}
12767 +
12768 +static int rpi_cirrus_startup(struct snd_pcm_substream *substream)
12769 +{
12770 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
12771 + struct snd_soc_card *card = rtd->card;
12772 + struct rpi_cirrus_priv *priv = snd_soc_card_get_drvdata(card);
12773 + unsigned int min_rate = min_rates[priv->min_rate_idx].value;
12774 + unsigned int max_rate = max_rates[priv->max_rate_idx].value;
12775 +
12776 + if (min_rate || max_rate) {
12777 + if (max_rate == 0)
12778 + max_rate = UINT_MAX;
12779 +
12780 + dev_dbg(card->dev,
12781 + "startup: limiting rate to %u-%u\n",
12782 + min_rate, max_rate);
12783 +
12784 + snd_pcm_hw_constraint_minmax(substream->runtime,
12785 + SNDRV_PCM_HW_PARAM_RATE, min_rate, max_rate);
12786 + }
12787 +
12788 + return 0;
12789 +}
12790 +
12791 +static struct snd_soc_pcm_stream rpi_cirrus_dai_link2_params = {
12792 + .formats = SNDRV_PCM_FMTBIT_S24_LE,
12793 + .channels_min = 2,
12794 + .channels_max = 2,
12795 + .rate_min = RPI_CIRRUS_DEFAULT_RATE,
12796 + .rate_max = RPI_CIRRUS_DEFAULT_RATE,
12797 +};
12798 +
12799 +static int rpi_cirrus_hw_params(struct snd_pcm_substream *substream,
12800 + struct snd_pcm_hw_params *params)
12801 +{
12802 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
12803 + struct snd_soc_card *card = rtd->card;
12804 + struct rpi_cirrus_priv *priv = snd_soc_card_get_drvdata(card);
12805 + struct snd_soc_dai *bcm_i2s_dai = asoc_rtd_to_cpu(rtd, 0);
12806 + struct snd_soc_component *wm5102_component = asoc_rtd_to_codec(rtd, 0)->component;
12807 + struct snd_soc_dai *wm8804_dai = asoc_rtd_to_codec(get_wm8804_runtime(card), 0);
12808 +
12809 + int ret;
12810 +
12811 + unsigned int width = snd_pcm_format_physical_width(
12812 + params_format(params));
12813 + unsigned int rate = params_rate(params);
12814 + unsigned int clk_freq = calc_sysclk(rate);
12815 +
12816 + mutex_lock(&priv->lock);
12817 +
12818 + dev_dbg(card->dev, "hw_params: setting rate to %d\n", rate);
12819 +
12820 + ret = snd_soc_dai_set_bclk_ratio(bcm_i2s_dai, 2 * width);
12821 + if (ret) {
12822 + dev_err(card->dev, "set_bclk_ratio failed: %d\n", ret);
12823 + goto out;
12824 + }
12825 +
12826 + ret = snd_soc_dai_set_tdm_slot(asoc_rtd_to_codec(rtd, 0), 0x03, 0x03, 2, width);
12827 + if (ret) {
12828 + dev_err(card->dev, "set_tdm_slot failed: %d\n", ret);
12829 + goto out;
12830 + }
12831 +
12832 + /* WM8804 supports sample rates from 32k only */
12833 + if (rate >= 32000) {
12834 + ret = rpi_cirrus_set_wm8804_pll(card, wm8804_dai, rate);
12835 + if (ret)
12836 + goto out;
12837 + }
12838 +
12839 + ret = snd_soc_component_set_sysclk(wm5102_component,
12840 + ARIZONA_CLK_SYSCLK,
12841 + ARIZONA_CLK_SRC_FLL1,
12842 + clk_freq,
12843 + SND_SOC_CLOCK_IN);
12844 + if (ret) {
12845 + dev_err(card->dev, "Failed to set SYSCLK: %d\n", ret);
12846 + goto out;
12847 + }
12848 +
12849 + if ((priv->fll1_freq > 0) && (priv->fll1_freq != clk_freq)) {
12850 + dev_dbg(card->dev,
12851 + "hw_params: changing FLL1 from %d to %d\n",
12852 + priv->fll1_freq, clk_freq);
12853 +
12854 + if (rpi_cirrus_clear_flls(card, wm5102_component)) {
12855 + dev_err(card->dev, "hw_params: failed to clear FLLs\n");
12856 + goto out;
12857 + }
12858 +
12859 + if (rpi_cirrus_set_fll(card, wm5102_component, clk_freq)) {
12860 + dev_err(card->dev, "hw_params: failed to set FLL\n");
12861 + goto out;
12862 + }
12863 +
12864 + priv->fll1_freq = clk_freq;
12865 + }
12866 +
12867 + priv->card_rate = rate;
12868 + rpi_cirrus_dai_link2_params.rate_min = rate;
12869 + rpi_cirrus_dai_link2_params.rate_max = rate;
12870 +
12871 + priv->params_set |= 1 << substream->stream;
12872 +
12873 +out:
12874 + mutex_unlock(&priv->lock);
12875 +
12876 + return ret;
12877 +}
12878 +
12879 +static int rpi_cirrus_hw_free(struct snd_pcm_substream *substream)
12880 +{
12881 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
12882 + struct snd_soc_card *card = rtd->card;
12883 + struct rpi_cirrus_priv *priv = snd_soc_card_get_drvdata(card);
12884 + struct snd_soc_component *wm5102_component = asoc_rtd_to_codec(rtd, 0)->component;
12885 + int ret;
12886 + unsigned int old_params_set = priv->params_set;
12887 +
12888 + priv->params_set &= ~(1 << substream->stream);
12889 +
12890 + /* disable sysclk if this was the last open stream */
12891 + if (priv->params_set == 0 && old_params_set) {
12892 + dev_dbg(card->dev,
12893 + "hw_free: Setting SYSCLK to Zero\n");
12894 +
12895 + ret = snd_soc_component_set_sysclk(wm5102_component,
12896 + ARIZONA_CLK_SYSCLK,
12897 + ARIZONA_CLK_SRC_FLL1,
12898 + 0,
12899 + SND_SOC_CLOCK_IN);
12900 + if (ret)
12901 + dev_err(card->dev,
12902 + "hw_free: Failed to set SYSCLK to Zero: %d\n",
12903 + ret);
12904 + }
12905 + return 0;
12906 +}
12907 +
12908 +static int rpi_cirrus_init_wm5102(struct snd_soc_pcm_runtime *rtd)
12909 +{
12910 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
12911 + int ret;
12912 +
12913 + /* no 32kHz input, derive it from sysclk if needed */
12914 + snd_soc_component_update_bits(component,
12915 + ARIZONA_CLOCK_32K_1, ARIZONA_CLK_32K_SRC_MASK, 2);
12916 +
12917 + if (rpi_cirrus_clear_flls(rtd->card, component))
12918 + dev_warn(rtd->card->dev,
12919 + "init_wm5102: failed to clear FLLs\n");
12920 +
12921 + ret = snd_soc_component_set_sysclk(component,
12922 + ARIZONA_CLK_SYSCLK, ARIZONA_CLK_SRC_FLL1,
12923 + 0, SND_SOC_CLOCK_IN);
12924 + if (ret) {
12925 + dev_err(rtd->card->dev,
12926 + "Failed to set SYSCLK to Zero: %d\n", ret);
12927 + return ret;
12928 + }
12929 +
12930 + return 0;
12931 +}
12932 +
12933 +static int rpi_cirrus_init_wm8804(struct snd_soc_pcm_runtime *rtd)
12934 +{
12935 + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
12936 + struct snd_soc_component *component = codec_dai->component;
12937 + struct snd_soc_card *card = rtd->card;
12938 + struct rpi_cirrus_priv *priv = snd_soc_card_get_drvdata(card);
12939 + unsigned int val, mask;
12940 + int i, ret;
12941 +
12942 + for (i = 0; i < 4; i++) {
12943 + val = snd_soc_component_read(component,
12944 + WM8804_SPDTX1 + i);
12945 + mask = (i == 3) ? 0x3f : 0xff;
12946 + priv->iec958_status[i] = val & mask;
12947 + }
12948 +
12949 + /* Setup for 256fs */
12950 + ret = snd_soc_dai_set_clkdiv(codec_dai,
12951 + WM8804_MCLK_DIV, WM8804_MCLKDIV_256FS);
12952 + if (ret) {
12953 + dev_err(card->dev,
12954 + "init_wm8804: Failed to set MCLK_DIV to 256fs: %d\n",
12955 + ret);
12956 + return ret;
12957 + }
12958 +
12959 + /* Output OSC on CLKOUT */
12960 + ret = snd_soc_dai_set_sysclk(codec_dai,
12961 + WM8804_CLKOUT_SRC_OSCCLK, WM8804_CLKOUT_HZ, 0);
12962 + if (ret)
12963 + dev_err(card->dev,
12964 + "init_wm8804: Failed to set CLKOUT as OSC Frequency: %d\n",
12965 + ret);
12966 +
12967 + /* Init PLL with default samplerate */
12968 + ret = rpi_cirrus_set_wm8804_pll(card, codec_dai,
12969 + RPI_CIRRUS_DEFAULT_RATE);
12970 + if (ret)
12971 + dev_err(card->dev,
12972 + "init_wm8804: Failed to setup PLL for %dHz: %d\n",
12973 + RPI_CIRRUS_DEFAULT_RATE, ret);
12974 +
12975 + return ret;
12976 +}
12977 +
12978 +static struct snd_soc_ops rpi_cirrus_ops = {
12979 + .startup = rpi_cirrus_startup,
12980 + .hw_params = rpi_cirrus_hw_params,
12981 + .hw_free = rpi_cirrus_hw_free,
12982 +};
12983 +
12984 +SND_SOC_DAILINK_DEFS(wm5102,
12985 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
12986 + DAILINK_COMP_ARRAY(COMP_CODEC("wm5102-codec", "wm5102-aif1")),
12987 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
12988 +
12989 +SND_SOC_DAILINK_DEFS(wm8804,
12990 + DAILINK_COMP_ARRAY(COMP_CPU("wm5102-aif2")),
12991 + DAILINK_COMP_ARRAY(COMP_CODEC("wm8804.1-003b", "wm8804-spdif")));
12992 +
12993 +static struct snd_soc_dai_link rpi_cirrus_dai[] = {
12994 + [DAI_WM5102] = {
12995 + .name = "WM5102",
12996 + .stream_name = "WM5102 AiFi",
12997 + .dai_fmt = SND_SOC_DAIFMT_I2S
12998 + | SND_SOC_DAIFMT_NB_NF
12999 + | SND_SOC_DAIFMT_CBM_CFM,
13000 + .ops = &rpi_cirrus_ops,
13001 + .init = rpi_cirrus_init_wm5102,
13002 + SND_SOC_DAILINK_REG(wm5102),
13003 + },
13004 + [DAI_WM8804] = {
13005 + .name = "WM5102 SPDIF",
13006 + .stream_name = "SPDIF Tx/Rx",
13007 + .dai_fmt = SND_SOC_DAIFMT_I2S
13008 + | SND_SOC_DAIFMT_NB_NF
13009 + | SND_SOC_DAIFMT_CBM_CFM,
13010 + .ignore_suspend = 1,
13011 + .params = &rpi_cirrus_dai_link2_params,
13012 + .init = rpi_cirrus_init_wm8804,
13013 + SND_SOC_DAILINK_REG(wm8804),
13014 + },
13015 +};
13016 +
13017 +
13018 +static int rpi_cirrus_late_probe(struct snd_soc_card *card)
13019 +{
13020 + struct rpi_cirrus_priv *priv = snd_soc_card_get_drvdata(card);
13021 + struct snd_soc_pcm_runtime *wm5102_runtime = get_wm5102_runtime(card);
13022 + struct snd_soc_pcm_runtime *wm8804_runtime = get_wm8804_runtime(card);
13023 + int ret;
13024 +
13025 + dev_dbg(card->dev, "iec958_bits: %02x %02x %02x %02x\n",
13026 + priv->iec958_status[0],
13027 + priv->iec958_status[1],
13028 + priv->iec958_status[2],
13029 + priv->iec958_status[3]);
13030 +
13031 + ret = snd_soc_dai_set_sysclk(
13032 + asoc_rtd_to_codec(wm5102_runtime, 0), ARIZONA_CLK_SYSCLK, 0, 0);
13033 + if (ret) {
13034 + dev_err(card->dev,
13035 + "Failed to set WM5102 codec dai clk domain: %d\n", ret);
13036 + return ret;
13037 + }
13038 +
13039 + ret = snd_soc_dai_set_sysclk(
13040 + asoc_rtd_to_cpu(wm8804_runtime, 0), ARIZONA_CLK_SYSCLK, 0, 0);
13041 + if (ret)
13042 + dev_err(card->dev,
13043 + "Failed to set WM8804 codec dai clk domain: %d\n", ret);
13044 +
13045 + return ret;
13046 +}
13047 +
13048 +/* audio machine driver */
13049 +static struct snd_soc_card rpi_cirrus_card = {
13050 + .name = "RPi-Cirrus",
13051 + .driver_name = "RPiCirrus",
13052 + .owner = THIS_MODULE,
13053 + .dai_link = rpi_cirrus_dai,
13054 + .num_links = ARRAY_SIZE(rpi_cirrus_dai),
13055 + .late_probe = rpi_cirrus_late_probe,
13056 + .controls = rpi_cirrus_controls,
13057 + .num_controls = ARRAY_SIZE(rpi_cirrus_controls),
13058 + .dapm_widgets = rpi_cirrus_dapm_widgets,
13059 + .num_dapm_widgets = ARRAY_SIZE(rpi_cirrus_dapm_widgets),
13060 + .dapm_routes = rpi_cirrus_dapm_routes,
13061 + .num_dapm_routes = ARRAY_SIZE(rpi_cirrus_dapm_routes),
13062 + .set_bias_level = rpi_cirrus_set_bias_level,
13063 + .set_bias_level_post = rpi_cirrus_set_bias_level_post,
13064 +};
13065 +
13066 +static int rpi_cirrus_probe(struct platform_device *pdev)
13067 +{
13068 + int ret = 0;
13069 + struct rpi_cirrus_priv *priv;
13070 + struct device_node *i2s_node;
13071 +
13072 + priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
13073 + if (!priv)
13074 + return -ENOMEM;
13075 +
13076 + priv->min_rate_idx = 1; /* min samplerate 32kHz */
13077 + priv->card_rate = RPI_CIRRUS_DEFAULT_RATE;
13078 +
13079 + mutex_init(&priv->lock);
13080 +
13081 + snd_soc_card_set_drvdata(&rpi_cirrus_card, priv);
13082 +
13083 + if (!pdev->dev.of_node)
13084 + return -ENODEV;
13085 +
13086 + i2s_node = of_parse_phandle(
13087 + pdev->dev.of_node, "i2s-controller", 0);
13088 + if (!i2s_node) {
13089 + dev_err(&pdev->dev, "i2s-controller missing in DT\n");
13090 + return -ENODEV;
13091 + }
13092 +
13093 + rpi_cirrus_dai[DAI_WM5102].cpus->of_node = i2s_node;
13094 + rpi_cirrus_dai[DAI_WM5102].platforms->of_node = i2s_node;
13095 +
13096 + rpi_cirrus_card.dev = &pdev->dev;
13097 +
13098 + ret = devm_snd_soc_register_card(&pdev->dev, &rpi_cirrus_card);
13099 + if (ret) {
13100 + if (ret == -EPROBE_DEFER)
13101 + dev_dbg(&pdev->dev,
13102 + "register card requested probe deferral\n");
13103 + else
13104 + dev_err(&pdev->dev,
13105 + "Failed to register card: %d\n", ret);
13106 + }
13107 +
13108 + return ret;
13109 +}
13110 +
13111 +static const struct of_device_id rpi_cirrus_of_match[] = {
13112 + { .compatible = "wlf,rpi-cirrus", },
13113 + {},
13114 +};
13115 +MODULE_DEVICE_TABLE(of, rpi_cirrus_of_match);
13116 +
13117 +static struct platform_driver rpi_cirrus_driver = {
13118 + .driver = {
13119 + .name = "snd-rpi-cirrus",
13120 + .of_match_table = of_match_ptr(rpi_cirrus_of_match),
13121 + },
13122 + .probe = rpi_cirrus_probe,
13123 +};
13124 +
13125 +module_platform_driver(rpi_cirrus_driver);
13126 +
13127 +MODULE_AUTHOR("Matthias Reichl <hias@horus.com>");
13128 +MODULE_DESCRIPTION("ASoC driver for Cirrus Logic Audio Card");
13129 +MODULE_LICENSE("GPL");
13130 --- /dev/null
13131 +++ b/sound/soc/bcm/rpi-proto.c
13132 @@ -0,0 +1,147 @@
13133 +/*
13134 + * ASoC driver for PROTO AudioCODEC (with a WM8731)
13135 + * connected to a Raspberry Pi
13136 + *
13137 + * Author: Florian Meier, <koalo@koalo.de>
13138 + * Copyright 2013
13139 + *
13140 + * This program is free software; you can redistribute it and/or modify
13141 + * it under the terms of the GNU General Public License version 2 as
13142 + * published by the Free Software Foundation.
13143 + */
13144 +
13145 +#include <linux/module.h>
13146 +#include <linux/platform_device.h>
13147 +
13148 +#include <sound/core.h>
13149 +#include <sound/pcm.h>
13150 +#include <sound/soc.h>
13151 +#include <sound/jack.h>
13152 +
13153 +#include "../codecs/wm8731.h"
13154 +
13155 +static const unsigned int wm8731_rates_12288000[] = {
13156 + 8000, 32000, 48000, 96000,
13157 +};
13158 +
13159 +static struct snd_pcm_hw_constraint_list wm8731_constraints_12288000 = {
13160 + .list = wm8731_rates_12288000,
13161 + .count = ARRAY_SIZE(wm8731_rates_12288000),
13162 +};
13163 +
13164 +static int snd_rpi_proto_startup(struct snd_pcm_substream *substream)
13165 +{
13166 + /* Setup constraints, because there is a 12.288 MHz XTAL on the board */
13167 + snd_pcm_hw_constraint_list(substream->runtime, 0,
13168 + SNDRV_PCM_HW_PARAM_RATE,
13169 + &wm8731_constraints_12288000);
13170 + return 0;
13171 +}
13172 +
13173 +static int snd_rpi_proto_hw_params(struct snd_pcm_substream *substream,
13174 + struct snd_pcm_hw_params *params)
13175 +{
13176 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
13177 + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
13178 + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
13179 + int sysclk = 12288000; /* This is fixed on this board */
13180 +
13181 + /* Set proto bclk */
13182 + int ret = snd_soc_dai_set_bclk_ratio(cpu_dai,32*2);
13183 + if (ret < 0){
13184 + dev_err(rtd->card->dev,
13185 + "Failed to set BCLK ratio %d\n", ret);
13186 + return ret;
13187 + }
13188 +
13189 + /* Set proto sysclk */
13190 + ret = snd_soc_dai_set_sysclk(codec_dai, WM8731_SYSCLK_XTAL,
13191 + sysclk, SND_SOC_CLOCK_IN);
13192 + if (ret < 0) {
13193 + dev_err(rtd->card->dev,
13194 + "Failed to set WM8731 SYSCLK: %d\n", ret);
13195 + return ret;
13196 + }
13197 +
13198 + return 0;
13199 +}
13200 +
13201 +/* machine stream operations */
13202 +static struct snd_soc_ops snd_rpi_proto_ops = {
13203 + .startup = snd_rpi_proto_startup,
13204 + .hw_params = snd_rpi_proto_hw_params,
13205 +};
13206 +
13207 +SND_SOC_DAILINK_DEFS(rpi_proto,
13208 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
13209 + DAILINK_COMP_ARRAY(COMP_CODEC("wm8731.1-001a", "wm8731-hifi")),
13210 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
13211 +
13212 +static struct snd_soc_dai_link snd_rpi_proto_dai[] = {
13213 +{
13214 + .name = "WM8731",
13215 + .stream_name = "WM8731 HiFi",
13216 + .dai_fmt = SND_SOC_DAIFMT_I2S
13217 + | SND_SOC_DAIFMT_NB_NF
13218 + | SND_SOC_DAIFMT_CBM_CFM,
13219 + .ops = &snd_rpi_proto_ops,
13220 + SND_SOC_DAILINK_REG(rpi_proto),
13221 +},
13222 +};
13223 +
13224 +/* audio machine driver */
13225 +static struct snd_soc_card snd_rpi_proto = {
13226 + .name = "snd_rpi_proto",
13227 + .owner = THIS_MODULE,
13228 + .dai_link = snd_rpi_proto_dai,
13229 + .num_links = ARRAY_SIZE(snd_rpi_proto_dai),
13230 +};
13231 +
13232 +static int snd_rpi_proto_probe(struct platform_device *pdev)
13233 +{
13234 + int ret = 0;
13235 +
13236 + snd_rpi_proto.dev = &pdev->dev;
13237 +
13238 + if (pdev->dev.of_node) {
13239 + struct device_node *i2s_node;
13240 + struct snd_soc_dai_link *dai = &snd_rpi_proto_dai[0];
13241 + i2s_node = of_parse_phandle(pdev->dev.of_node,
13242 + "i2s-controller", 0);
13243 +
13244 + if (i2s_node) {
13245 + dai->cpus->dai_name = NULL;
13246 + dai->cpus->of_node = i2s_node;
13247 + dai->platforms->name = NULL;
13248 + dai->platforms->of_node = i2s_node;
13249 + }
13250 + }
13251 +
13252 + ret = devm_snd_soc_register_card(&pdev->dev, &snd_rpi_proto);
13253 + if (ret && ret != -EPROBE_DEFER)
13254 + dev_err(&pdev->dev,
13255 + "snd_soc_register_card() failed: %d\n", ret);
13256 +
13257 + return ret;
13258 +}
13259 +
13260 +static const struct of_device_id snd_rpi_proto_of_match[] = {
13261 + { .compatible = "rpi,rpi-proto", },
13262 + {},
13263 +};
13264 +MODULE_DEVICE_TABLE(of, snd_rpi_proto_of_match);
13265 +
13266 +static struct platform_driver snd_rpi_proto_driver = {
13267 + .driver = {
13268 + .name = "snd-rpi-proto",
13269 + .owner = THIS_MODULE,
13270 + .of_match_table = snd_rpi_proto_of_match,
13271 + },
13272 + .probe = snd_rpi_proto_probe,
13273 +};
13274 +
13275 +module_platform_driver(snd_rpi_proto_driver);
13276 +
13277 +MODULE_AUTHOR("Florian Meier");
13278 +MODULE_DESCRIPTION("ASoC Driver for Raspberry Pi connected to PROTO board (WM8731)");
13279 +MODULE_LICENSE("GPL");
13280 --- /dev/null
13281 +++ b/sound/soc/bcm/rpi-simple-soundcard.c
13282 @@ -0,0 +1,419 @@
13283 +// SPDX-License-Identifier: GPL-2.0
13284 +/*
13285 + * rpi-simple-soundcard.c -- ALSA SoC Raspberry Pi soundcard.
13286 + *
13287 + * Copyright (C) 2018 Raspberry Pi.
13288 + *
13289 + * Authors: Tim Gover <tim.gover@raspberrypi.org>
13290 + *
13291 + * Based on code:
13292 + * hifiberry_amp.c, hifiberry_dac.c, rpi-dac.c
13293 + * by Florian Meier <florian.meier@koalo.de>
13294 + *
13295 + * googlevoicehat-soundcard.c
13296 + * by Peter Malkin <petermalkin@google.com>
13297 + *
13298 + * adau1977-adc.c
13299 + * by Andrey Grodzovsky <andrey2805@gmail.com>
13300 + *
13301 + * merus-amp.c
13302 + * by Ariel Muszkat <ariel.muszkat@gmail.com>
13303 + * Jorgen Kragh Jakobsen <jorgen.kraghjakobsen@infineon.com>
13304 + *
13305 + * This program is free software; you can redistribute it and/or
13306 + * modify it under the terms of the GNU General Public License
13307 + * version 2 as published by the Free Software Foundation.
13308 + *
13309 + * This program is distributed in the hope that it will be useful, but
13310 + * WITHOUT ANY WARRANTY; without even the implied warranty of
13311 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13312 + * General Public License for more details.
13313 + */
13314 +
13315 +#include <linux/module.h>
13316 +#include <linux/platform_device.h>
13317 +#include <linux/gpio/consumer.h>
13318 +
13319 +#include <sound/core.h>
13320 +#include <sound/pcm.h>
13321 +#include <sound/pcm_params.h>
13322 +#include <sound/soc.h>
13323 +
13324 +/* Parameters for generic RPI functions */
13325 +struct snd_rpi_simple_drvdata {
13326 + struct snd_soc_dai_link *dai;
13327 + const char* card_name;
13328 + unsigned int fixed_bclk_ratio;
13329 +};
13330 +
13331 +static struct snd_soc_card snd_rpi_simple = {
13332 + .driver_name = "RPi-simple",
13333 + .owner = THIS_MODULE,
13334 + .dai_link = NULL,
13335 + .num_links = 1, /* Only a single DAI supported at the moment */
13336 +};
13337 +
13338 +static int snd_rpi_simple_init(struct snd_soc_pcm_runtime *rtd)
13339 +{
13340 + struct snd_rpi_simple_drvdata *drvdata =
13341 + snd_soc_card_get_drvdata(rtd->card);
13342 + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
13343 +
13344 + if (drvdata->fixed_bclk_ratio > 0)
13345 + return snd_soc_dai_set_bclk_ratio(cpu_dai,
13346 + drvdata->fixed_bclk_ratio);
13347 +
13348 + return 0;
13349 +}
13350 +
13351 +static int pifi_mini_210_init(struct snd_soc_pcm_runtime *rtd)
13352 +{
13353 + struct snd_soc_component *dac;
13354 + struct gpio_desc *pdn_gpio, *rst_gpio;
13355 + struct snd_soc_dai *codec_dai;
13356 + int ret;
13357 +
13358 + snd_rpi_simple_init(rtd);
13359 + codec_dai = asoc_rtd_to_codec(rtd, 0);
13360 +
13361 + dac = codec_dai[0].component;
13362 +
13363 + pdn_gpio = devm_gpiod_get_optional(snd_rpi_simple.dev, "pdn",
13364 + GPIOD_OUT_LOW);
13365 + if (IS_ERR(pdn_gpio)) {
13366 + ret = PTR_ERR(pdn_gpio);
13367 + dev_err(snd_rpi_simple.dev, "failed to get pdn gpio: %d\n", ret);
13368 + return ret;
13369 + }
13370 +
13371 + rst_gpio = devm_gpiod_get_optional(snd_rpi_simple.dev, "rst",
13372 + GPIOD_OUT_LOW);
13373 + if (IS_ERR(rst_gpio)) {
13374 + ret = PTR_ERR(rst_gpio);
13375 + dev_err(snd_rpi_simple.dev, "failed to get rst gpio: %d\n", ret);
13376 + return ret;
13377 + }
13378 +
13379 + // Set up cards - pulse power down and reset first, then
13380 + // set up according to datasheet
13381 + gpiod_set_value_cansleep(pdn_gpio, 1);
13382 + gpiod_set_value_cansleep(rst_gpio, 1);
13383 + usleep_range(1000, 10000);
13384 + gpiod_set_value_cansleep(pdn_gpio, 0);
13385 + usleep_range(20000, 30000);
13386 + gpiod_set_value_cansleep(rst_gpio, 0);
13387 + usleep_range(20000, 30000);
13388 +
13389 + // Oscillator trim
13390 + snd_soc_component_write(dac, 0x1b, 0);
13391 + usleep_range(60000, 80000);
13392 +
13393 + // MCLK at 64fs, sample rate 44.1 or 48kHz
13394 + snd_soc_component_write(dac, 0x00, 0x60);
13395 +
13396 + // Set up for BTL - AD/BD mode - AD is 0x00107772, BD is 0x00987772
13397 + snd_soc_component_write(dac, 0x20, 0x00107772);
13398 +
13399 + // End mute
13400 + snd_soc_component_write(dac, 0x05, 0x00);
13401 +
13402 + return 0;
13403 +}
13404 +
13405 +static int snd_rpi_simple_hw_params(struct snd_pcm_substream *substream,
13406 + struct snd_pcm_hw_params *params)
13407 +{
13408 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
13409 + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
13410 + struct snd_rpi_simple_drvdata *drvdata;
13411 + unsigned int sample_bits;
13412 +
13413 + drvdata = snd_soc_card_get_drvdata(rtd->card);
13414 +
13415 + if (drvdata->fixed_bclk_ratio > 0)
13416 + return 0; // BCLK is configured in .init
13417 +
13418 + /* The simple drivers just set the bclk_ratio to sample_bits * 2 so
13419 + * hard-code this for now. More complex drivers could just replace
13420 + * the hw_params routine.
13421 + */
13422 + sample_bits = snd_pcm_format_physical_width(params_format(params));
13423 + return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);
13424 +}
13425 +
13426 +static struct snd_soc_ops snd_rpi_simple_ops = {
13427 + .hw_params = snd_rpi_simple_hw_params,
13428 +};
13429 +
13430 +enum adau1977_clk_id {
13431 + ADAU1977_SYSCLK,
13432 +};
13433 +
13434 +enum adau1977_sysclk_src {
13435 + ADAU1977_SYSCLK_SRC_MCLK,
13436 + ADAU1977_SYSCLK_SRC_LRCLK,
13437 +};
13438 +
13439 +static int adau1977_init(struct snd_soc_pcm_runtime *rtd)
13440 +{
13441 + int ret;
13442 + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
13443 +
13444 + ret = snd_soc_dai_set_tdm_slot(codec_dai, 0, 0, 0, 0);
13445 + if (ret < 0)
13446 + return ret;
13447 +
13448 + return snd_soc_component_set_sysclk(codec_dai->component,
13449 + ADAU1977_SYSCLK, ADAU1977_SYSCLK_SRC_MCLK,
13450 + 11289600, SND_SOC_CLOCK_IN);
13451 +}
13452 +
13453 +SND_SOC_DAILINK_DEFS(adau1977,
13454 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
13455 + DAILINK_COMP_ARRAY(COMP_CODEC("adau1977.1-0011", "adau1977-hifi")),
13456 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
13457 +
13458 +static struct snd_soc_dai_link snd_rpi_adau1977_dai[] = {
13459 + {
13460 + .name = "adau1977",
13461 + .stream_name = "ADAU1977",
13462 + .init = adau1977_init,
13463 + .dai_fmt = SND_SOC_DAIFMT_I2S |
13464 + SND_SOC_DAIFMT_NB_NF |
13465 + SND_SOC_DAIFMT_CBM_CFM,
13466 + SND_SOC_DAILINK_REG(adau1977),
13467 + },
13468 +};
13469 +
13470 +static struct snd_rpi_simple_drvdata drvdata_adau1977 = {
13471 + .card_name = "snd_rpi_adau1977_adc",
13472 + .dai = snd_rpi_adau1977_dai,
13473 +};
13474 +
13475 +SND_SOC_DAILINK_DEFS(gvchat,
13476 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
13477 + DAILINK_COMP_ARRAY(COMP_CODEC("voicehat-codec", "voicehat-hifi")),
13478 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
13479 +
13480 +static struct snd_soc_dai_link snd_googlevoicehat_soundcard_dai[] = {
13481 +{
13482 + .name = "Google voiceHAT SoundCard",
13483 + .stream_name = "Google voiceHAT SoundCard HiFi",
13484 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
13485 + SND_SOC_DAIFMT_CBS_CFS,
13486 + SND_SOC_DAILINK_REG(gvchat),
13487 +},
13488 +};
13489 +
13490 +static struct snd_rpi_simple_drvdata drvdata_googlevoicehat = {
13491 + .card_name = "snd_rpi_googlevoicehat_soundcard",
13492 + .dai = snd_googlevoicehat_soundcard_dai,
13493 +};
13494 +
13495 +SND_SOC_DAILINK_DEFS(hifiberry_dacplusdsp,
13496 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
13497 + DAILINK_COMP_ARRAY(COMP_CODEC("dacplusdsp-codec", "dacplusdsp-hifi")),
13498 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
13499 +
13500 +static struct snd_soc_dai_link snd_hifiberrydacplusdsp_soundcard_dai[] = {
13501 +{
13502 + .name = "Hifiberry DAC+DSP SoundCard",
13503 + .stream_name = "Hifiberry DAC+DSP SoundCard HiFi",
13504 + .dai_fmt = SND_SOC_DAIFMT_I2S |
13505 + SND_SOC_DAIFMT_NB_NF |
13506 + SND_SOC_DAIFMT_CBS_CFS,
13507 + SND_SOC_DAILINK_REG(hifiberry_dacplusdsp),
13508 +},
13509 +};
13510 +
13511 +static struct snd_rpi_simple_drvdata drvdata_hifiberrydacplusdsp = {
13512 + .card_name = "snd_rpi_hifiberrydacplusdsp_soundcard",
13513 + .dai = snd_hifiberrydacplusdsp_soundcard_dai,
13514 +};
13515 +
13516 +SND_SOC_DAILINK_DEFS(hifiberry_amp,
13517 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
13518 + DAILINK_COMP_ARRAY(COMP_CODEC("tas5713.1-001b", "tas5713-hifi")),
13519 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
13520 +
13521 +static struct snd_soc_dai_link snd_hifiberry_amp_dai[] = {
13522 + {
13523 + .name = "HifiBerry AMP",
13524 + .stream_name = "HifiBerry AMP HiFi",
13525 + .dai_fmt = SND_SOC_DAIFMT_I2S |
13526 + SND_SOC_DAIFMT_NB_NF |
13527 + SND_SOC_DAIFMT_CBS_CFS,
13528 + SND_SOC_DAILINK_REG(hifiberry_amp),
13529 + },
13530 +};
13531 +
13532 +static struct snd_rpi_simple_drvdata drvdata_hifiberry_amp = {
13533 + .card_name = "snd_rpi_hifiberry_amp",
13534 + .dai = snd_hifiberry_amp_dai,
13535 + .fixed_bclk_ratio = 64,
13536 +};
13537 +
13538 +SND_SOC_DAILINK_DEFS(hifiberry_dac,
13539 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
13540 + DAILINK_COMP_ARRAY(COMP_CODEC("pcm5102a-codec", "pcm5102a-hifi")),
13541 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
13542 +
13543 +static struct snd_soc_dai_link snd_hifiberry_dac_dai[] = {
13544 + {
13545 + .name = "HifiBerry DAC",
13546 + .stream_name = "HifiBerry DAC HiFi",
13547 + .dai_fmt = SND_SOC_DAIFMT_I2S |
13548 + SND_SOC_DAIFMT_NB_NF |
13549 + SND_SOC_DAIFMT_CBS_CFS,
13550 + SND_SOC_DAILINK_REG(hifiberry_dac),
13551 + },
13552 +};
13553 +
13554 +static struct snd_rpi_simple_drvdata drvdata_hifiberry_dac = {
13555 + .card_name = "snd_rpi_hifiberry_dac",
13556 + .dai = snd_hifiberry_dac_dai,
13557 +};
13558 +
13559 +SND_SOC_DAILINK_DEFS(rpi_dac,
13560 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
13561 + DAILINK_COMP_ARRAY(COMP_CODEC("pcm1794a-codec", "pcm1794a-hifi")),
13562 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
13563 +
13564 +static struct snd_soc_dai_link snd_rpi_dac_dai[] = {
13565 +{
13566 + .name = "RPi-DAC",
13567 + .stream_name = "RPi-DAC HiFi",
13568 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
13569 + SND_SOC_DAIFMT_CBS_CFS,
13570 + SND_SOC_DAILINK_REG(rpi_dac),
13571 +},
13572 +};
13573 +
13574 +static struct snd_rpi_simple_drvdata drvdata_rpi_dac = {
13575 + .card_name = "snd_rpi_rpi_dac",
13576 + .dai = snd_rpi_dac_dai,
13577 + .fixed_bclk_ratio = 64,
13578 +};
13579 +
13580 +SND_SOC_DAILINK_DEFS(merus_amp,
13581 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
13582 + DAILINK_COMP_ARRAY(COMP_CODEC("ma120x0p.1-0020","ma120x0p-amp")),
13583 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
13584 +
13585 +static struct snd_soc_dai_link snd_merus_amp_dai[] = {
13586 + {
13587 + .name = "MerusAmp",
13588 + .stream_name = "Merus Audio Amp",
13589 + .dai_fmt = SND_SOC_DAIFMT_I2S |
13590 + SND_SOC_DAIFMT_NB_NF |
13591 + SND_SOC_DAIFMT_CBS_CFS,
13592 + SND_SOC_DAILINK_REG(merus_amp),
13593 + },
13594 +};
13595 +
13596 +static struct snd_rpi_simple_drvdata drvdata_merus_amp = {
13597 + .card_name = "snd_rpi_merus_amp",
13598 + .dai = snd_merus_amp_dai,
13599 + .fixed_bclk_ratio = 64,
13600 +};
13601 +
13602 +SND_SOC_DAILINK_DEFS(pifi_mini_210,
13603 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
13604 + DAILINK_COMP_ARRAY(COMP_CODEC("tas571x.1-001a", "tas571x-hifi")),
13605 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
13606 +
13607 +static struct snd_soc_dai_link snd_pifi_mini_210_dai[] = {
13608 + {
13609 + .name = "PiFi Mini 210",
13610 + .stream_name = "PiFi Mini 210 HiFi",
13611 + .init = pifi_mini_210_init,
13612 + .dai_fmt = SND_SOC_DAIFMT_I2S |
13613 + SND_SOC_DAIFMT_NB_NF |
13614 + SND_SOC_DAIFMT_CBS_CFS,
13615 + SND_SOC_DAILINK_REG(pifi_mini_210),
13616 + },
13617 +};
13618 +
13619 +static struct snd_rpi_simple_drvdata drvdata_pifi_mini_210 = {
13620 + .card_name = "snd_pifi_mini_210",
13621 + .dai = snd_pifi_mini_210_dai,
13622 + .fixed_bclk_ratio = 64,
13623 +};
13624 +
13625 +static const struct of_device_id snd_rpi_simple_of_match[] = {
13626 + { .compatible = "adi,adau1977-adc",
13627 + .data = (void *) &drvdata_adau1977 },
13628 + { .compatible = "googlevoicehat,googlevoicehat-soundcard",
13629 + .data = (void *) &drvdata_googlevoicehat },
13630 + { .compatible = "hifiberrydacplusdsp,hifiberrydacplusdsp-soundcard",
13631 + .data = (void *) &drvdata_hifiberrydacplusdsp },
13632 + { .compatible = "hifiberry,hifiberry-amp",
13633 + .data = (void *) &drvdata_hifiberry_amp },
13634 + { .compatible = "hifiberry,hifiberry-dac",
13635 + .data = (void *) &drvdata_hifiberry_dac },
13636 + { .compatible = "rpi,rpi-dac", &drvdata_rpi_dac},
13637 + { .compatible = "merus,merus-amp",
13638 + .data = (void *) &drvdata_merus_amp },
13639 + { .compatible = "pifi,pifi-mini-210",
13640 + .data = (void *) &drvdata_pifi_mini_210 },
13641 + {},
13642 +};
13643 +
13644 +static int snd_rpi_simple_probe(struct platform_device *pdev)
13645 +{
13646 + int ret = 0;
13647 + const struct of_device_id *of_id;
13648 +
13649 + snd_rpi_simple.dev = &pdev->dev;
13650 + of_id = of_match_node(snd_rpi_simple_of_match, pdev->dev.of_node);
13651 +
13652 + if (pdev->dev.of_node && of_id->data) {
13653 + struct device_node *i2s_node;
13654 + struct snd_rpi_simple_drvdata *drvdata =
13655 + (struct snd_rpi_simple_drvdata *) of_id->data;
13656 + struct snd_soc_dai_link *dai = drvdata->dai;
13657 +
13658 + snd_soc_card_set_drvdata(&snd_rpi_simple, drvdata);
13659 +
13660 + /* More complex drivers might override individual functions */
13661 + if (!dai->init)
13662 + dai->init = snd_rpi_simple_init;
13663 + if (!dai->ops)
13664 + dai->ops = &snd_rpi_simple_ops;
13665 +
13666 + snd_rpi_simple.name = drvdata->card_name;
13667 +
13668 + snd_rpi_simple.dai_link = dai;
13669 + i2s_node = of_parse_phandle(pdev->dev.of_node,
13670 + "i2s-controller", 0);
13671 + if (!i2s_node) {
13672 + pr_err("Failed to find i2s-controller DT node\n");
13673 + return -ENODEV;
13674 + }
13675 +
13676 + dai->cpus->of_node = i2s_node;
13677 + dai->platforms->of_node = i2s_node;
13678 + }
13679 +
13680 + ret = devm_snd_soc_register_card(&pdev->dev, &snd_rpi_simple);
13681 + if (ret && ret != -EPROBE_DEFER)
13682 + dev_err(&pdev->dev, "Failed to register card %d\n", ret);
13683 +
13684 + return ret;
13685 +}
13686 +
13687 +static struct platform_driver snd_rpi_simple_driver = {
13688 + .driver = {
13689 + .name = "snd-rpi-simple",
13690 + .owner = THIS_MODULE,
13691 + .of_match_table = snd_rpi_simple_of_match,
13692 + },
13693 + .probe = snd_rpi_simple_probe,
13694 +};
13695 +MODULE_DEVICE_TABLE(of, snd_rpi_simple_of_match);
13696 +
13697 +module_platform_driver(snd_rpi_simple_driver);
13698 +
13699 +MODULE_AUTHOR("Tim Gover <tim.gover@raspberrypi.org>");
13700 +MODULE_DESCRIPTION("ASoC Raspberry Pi simple soundcard driver ");
13701 +MODULE_LICENSE("GPL v2");
13702 --- /dev/null
13703 +++ b/sound/soc/bcm/rpi-wm8804-soundcard.c
13704 @@ -0,0 +1,410 @@
13705 +// SPDX-License-Identifier: GPL-2.0
13706 +/*
13707 + * rpi--wm8804.c -- ALSA SoC Raspberry Pi soundcard.
13708 + *
13709 + * Copyright (C) 2018 Raspberry Pi.
13710 + *
13711 + * Authors: Tim Gover <tim.gover@raspberrypi.org>
13712 + *
13713 + * Generic driver for Pi Hat WM8804 digi sounds cards
13714 + *
13715 + * Based upon code from:
13716 + * justboom-digi.c
13717 + * by Milan Neskovic <info@justboom.co>
13718 + *
13719 + * iqaudio_digi.c
13720 + * by Daniel Matuschek <info@crazy-audio.com>
13721 + *
13722 + * allo-digione.c
13723 + * by Baswaraj <jaikumar@cem-solutions.net>
13724 + *
13725 + * hifiberry-digi.c
13726 + * Daniel Matuschek <info@crazy-audio.com>
13727 + *
13728 + * This program is free software; you can redistribute it and/or
13729 + * modify it under the terms of the GNU General Public License
13730 + * version 2 as published by the Free Software Foundation.
13731 + *
13732 + * This program is distributed in the hope that it will be useful, but
13733 + * WITHOUT ANY WARRANTY; without even the implied warranty of
13734 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13735 + * General Public License for more details.
13736 + */
13737 +
13738 +#include <linux/gpio/consumer.h>
13739 +#include <linux/platform_device.h>
13740 +#include <linux/module.h>
13741 +
13742 +#include <sound/core.h>
13743 +#include <sound/pcm.h>
13744 +#include <sound/pcm_params.h>
13745 +#include <sound/soc.h>
13746 +
13747 +#include "../codecs/wm8804.h"
13748 +
13749 +struct wm8804_clk_cfg {
13750 + unsigned int sysclk_freq;
13751 + unsigned int mclk_freq;
13752 + unsigned int mclk_div;
13753 +};
13754 +
13755 +/* Parameters for generic functions */
13756 +struct snd_rpi_wm8804_drvdata {
13757 + /* Required - pointer to the DAI structure */
13758 + struct snd_soc_dai_link *dai;
13759 + /* Required - snd_soc_card name */
13760 + const char *card_name;
13761 + /* Optional DT node names if card info is defined in DT */
13762 + const char *card_name_dt;
13763 + const char *dai_name_dt;
13764 + const char *dai_stream_name_dt;
13765 + /* Optional probe extension - called prior to register_card */
13766 + int (*probe)(struct platform_device *pdev);
13767 +};
13768 +
13769 +static struct gpio_desc *snd_clk44gpio;
13770 +static struct gpio_desc *snd_clk48gpio;
13771 +static int wm8804_samplerate = 0;
13772 +
13773 +/* Forward declarations */
13774 +static struct snd_soc_dai_link snd_allo_digione_dai[];
13775 +static struct snd_soc_card snd_rpi_wm8804;
13776 +
13777 +
13778 +#define CLK_44EN_RATE 22579200UL
13779 +#define CLK_48EN_RATE 24576000UL
13780 +
13781 +static unsigned int snd_rpi_wm8804_enable_clock(unsigned int samplerate)
13782 +{
13783 + switch (samplerate) {
13784 + case 11025:
13785 + case 22050:
13786 + case 44100:
13787 + case 88200:
13788 + case 176400:
13789 + gpiod_set_value_cansleep(snd_clk44gpio, 1);
13790 + gpiod_set_value_cansleep(snd_clk48gpio, 0);
13791 + return CLK_44EN_RATE;
13792 + default:
13793 + gpiod_set_value_cansleep(snd_clk48gpio, 1);
13794 + gpiod_set_value_cansleep(snd_clk44gpio, 0);
13795 + return CLK_48EN_RATE;
13796 + }
13797 +}
13798 +
13799 +static void snd_rpi_wm8804_clk_cfg(unsigned int samplerate,
13800 + struct wm8804_clk_cfg *clk_cfg)
13801 +{
13802 + clk_cfg->sysclk_freq = 27000000;
13803 +
13804 + if (samplerate <= 96000 ||
13805 + snd_rpi_wm8804.dai_link == snd_allo_digione_dai) {
13806 + clk_cfg->mclk_freq = samplerate * 256;
13807 + clk_cfg->mclk_div = WM8804_MCLKDIV_256FS;
13808 + } else {
13809 + clk_cfg->mclk_freq = samplerate * 128;
13810 + clk_cfg->mclk_div = WM8804_MCLKDIV_128FS;
13811 + }
13812 +
13813 + if (!(IS_ERR(snd_clk44gpio) || IS_ERR(snd_clk48gpio)))
13814 + clk_cfg->sysclk_freq = snd_rpi_wm8804_enable_clock(samplerate);
13815 +}
13816 +
13817 +static int snd_rpi_wm8804_hw_params(struct snd_pcm_substream *substream,
13818 + struct snd_pcm_hw_params *params)
13819 +{
13820 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
13821 + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
13822 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
13823 + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
13824 + int sampling_freq = 1;
13825 + int ret;
13826 + struct wm8804_clk_cfg clk_cfg;
13827 + int samplerate = params_rate(params);
13828 +
13829 + if (samplerate == wm8804_samplerate)
13830 + return 0;
13831 +
13832 + /* clear until all clocks are setup properly */
13833 + wm8804_samplerate = 0;
13834 +
13835 + snd_rpi_wm8804_clk_cfg(samplerate, &clk_cfg);
13836 +
13837 + pr_debug("%s samplerate: %d mclk_freq: %u mclk_div: %u sysclk: %u\n",
13838 + __func__, samplerate, clk_cfg.mclk_freq,
13839 + clk_cfg.mclk_div, clk_cfg.sysclk_freq);
13840 +
13841 + switch (samplerate) {
13842 + case 32000:
13843 + sampling_freq = 0x03;
13844 + break;
13845 + case 44100:
13846 + sampling_freq = 0x00;
13847 + break;
13848 + case 48000:
13849 + sampling_freq = 0x02;
13850 + break;
13851 + case 88200:
13852 + sampling_freq = 0x08;
13853 + break;
13854 + case 96000:
13855 + sampling_freq = 0x0a;
13856 + break;
13857 + case 176400:
13858 + sampling_freq = 0x0c;
13859 + break;
13860 + case 192000:
13861 + sampling_freq = 0x0e;
13862 + break;
13863 + default:
13864 + dev_err(rtd->card->dev,
13865 + "Failed to set WM8804 SYSCLK, unsupported samplerate %d\n",
13866 + samplerate);
13867 + }
13868 +
13869 + snd_soc_dai_set_clkdiv(codec_dai, WM8804_MCLK_DIV, clk_cfg.mclk_div);
13870 + snd_soc_dai_set_pll(codec_dai, 0, 0,
13871 + clk_cfg.sysclk_freq, clk_cfg.mclk_freq);
13872 +
13873 + ret = snd_soc_dai_set_sysclk(codec_dai, WM8804_TX_CLKSRC_PLL,
13874 + clk_cfg.sysclk_freq, SND_SOC_CLOCK_OUT);
13875 + if (ret < 0) {
13876 + dev_err(rtd->card->dev,
13877 + "Failed to set WM8804 SYSCLK: %d\n", ret);
13878 + return ret;
13879 + }
13880 +
13881 + wm8804_samplerate = samplerate;
13882 +
13883 + /* set sampling frequency status bits */
13884 + snd_soc_component_update_bits(component, WM8804_SPDTX4, 0x0f,
13885 + sampling_freq);
13886 +
13887 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 64);
13888 +}
13889 +
13890 +static struct snd_soc_ops snd_rpi_wm8804_ops = {
13891 + .hw_params = snd_rpi_wm8804_hw_params,
13892 +};
13893 +
13894 +SND_SOC_DAILINK_DEFS(justboom_digi,
13895 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
13896 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
13897 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
13898 +
13899 +static struct snd_soc_dai_link snd_justboom_digi_dai[] = {
13900 +{
13901 + .name = "JustBoom Digi",
13902 + .stream_name = "JustBoom Digi HiFi",
13903 + SND_SOC_DAILINK_REG(justboom_digi),
13904 +},
13905 +};
13906 +
13907 +static struct snd_rpi_wm8804_drvdata drvdata_justboom_digi = {
13908 + .card_name = "snd_rpi_justboom_digi",
13909 + .dai = snd_justboom_digi_dai,
13910 +};
13911 +
13912 +SND_SOC_DAILINK_DEFS(iqaudio_digi,
13913 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
13914 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
13915 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
13916 +
13917 +static struct snd_soc_dai_link snd_iqaudio_digi_dai[] = {
13918 +{
13919 + .name = "IQAudIO Digi",
13920 + .stream_name = "IQAudIO Digi HiFi",
13921 + SND_SOC_DAILINK_REG(iqaudio_digi),
13922 +},
13923 +};
13924 +
13925 +static struct snd_rpi_wm8804_drvdata drvdata_iqaudio_digi = {
13926 + .card_name = "IQAudIODigi",
13927 + .dai = snd_iqaudio_digi_dai,
13928 + .card_name_dt = "wm8804-digi,card-name",
13929 + .dai_name_dt = "wm8804-digi,dai-name",
13930 + .dai_stream_name_dt = "wm8804-digi,dai-stream-name",
13931 +};
13932 +
13933 +static int snd_allo_digione_probe(struct platform_device *pdev)
13934 +{
13935 + pr_debug("%s\n", __func__);
13936 +
13937 + if (IS_ERR(snd_clk44gpio) || IS_ERR(snd_clk48gpio)) {
13938 + dev_err(&pdev->dev, "devm_gpiod_get() failed\n");
13939 + return -EINVAL;
13940 + }
13941 + return 0;
13942 +}
13943 +
13944 +SND_SOC_DAILINK_DEFS(allo_digione,
13945 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
13946 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
13947 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
13948 +
13949 +static struct snd_soc_dai_link snd_allo_digione_dai[] = {
13950 +{
13951 + .name = "Allo DigiOne",
13952 + .stream_name = "Allo DigiOne HiFi",
13953 + SND_SOC_DAILINK_REG(allo_digione),
13954 +},
13955 +};
13956 +
13957 +static struct snd_rpi_wm8804_drvdata drvdata_allo_digione = {
13958 + .card_name = "snd_allo_digione",
13959 + .dai = snd_allo_digione_dai,
13960 + .probe = snd_allo_digione_probe,
13961 +};
13962 +
13963 +SND_SOC_DAILINK_DEFS(hifiberry_digi,
13964 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
13965 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
13966 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
13967 +
13968 +static struct snd_soc_dai_link snd_hifiberry_digi_dai[] = {
13969 +{
13970 + .name = "HifiBerry Digi",
13971 + .stream_name = "HifiBerry Digi HiFi",
13972 + SND_SOC_DAILINK_REG(hifiberry_digi),
13973 +},
13974 +};
13975 +
13976 +static int snd_hifiberry_digi_probe(struct platform_device *pdev)
13977 +{
13978 + pr_debug("%s\n", __func__);
13979 +
13980 + if (IS_ERR(snd_clk44gpio) || IS_ERR(snd_clk48gpio))
13981 + return 0;
13982 +
13983 + snd_hifiberry_digi_dai->name = "HiFiBerry Digi+ Pro";
13984 + snd_hifiberry_digi_dai->stream_name = "HiFiBerry Digi+ Pro HiFi";
13985 + return 0;
13986 +}
13987 +
13988 +static struct snd_rpi_wm8804_drvdata drvdata_hifiberry_digi = {
13989 + .card_name = "snd_rpi_hifiberry_digi",
13990 + .dai = snd_hifiberry_digi_dai,
13991 + .probe = snd_hifiberry_digi_probe,
13992 +};
13993 +
13994 +static const struct of_device_id snd_rpi_wm8804_of_match[] = {
13995 + { .compatible = "justboom,justboom-digi",
13996 + .data = (void *) &drvdata_justboom_digi },
13997 + { .compatible = "iqaudio,wm8804-digi",
13998 + .data = (void *) &drvdata_iqaudio_digi },
13999 + { .compatible = "allo,allo-digione",
14000 + .data = (void *) &drvdata_allo_digione },
14001 + { .compatible = "hifiberry,hifiberry-digi",
14002 + .data = (void *) &drvdata_hifiberry_digi },
14003 + {},
14004 +};
14005 +
14006 +static struct snd_soc_card snd_rpi_wm8804 = {
14007 + .driver_name = "RPi-WM8804",
14008 + .owner = THIS_MODULE,
14009 + .dai_link = NULL,
14010 + .num_links = 1,
14011 +};
14012 +
14013 +static int snd_rpi_wm8804_probe(struct platform_device *pdev)
14014 +{
14015 + int ret = 0;
14016 + const struct of_device_id *of_id;
14017 +
14018 + snd_rpi_wm8804.dev = &pdev->dev;
14019 + of_id = of_match_node(snd_rpi_wm8804_of_match, pdev->dev.of_node);
14020 +
14021 + if (pdev->dev.of_node && of_id->data) {
14022 + struct device_node *i2s_node;
14023 + struct snd_rpi_wm8804_drvdata *drvdata =
14024 + (struct snd_rpi_wm8804_drvdata *) of_id->data;
14025 + struct snd_soc_dai_link *dai = drvdata->dai;
14026 +
14027 + snd_soc_card_set_drvdata(&snd_rpi_wm8804, drvdata);
14028 +
14029 + if (!dai->ops)
14030 + dai->ops = &snd_rpi_wm8804_ops;
14031 + if (!dai->codecs->dai_name)
14032 + dai->codecs->dai_name = "wm8804-spdif";
14033 + if (!dai->codecs->name)
14034 + dai->codecs->name = "wm8804.1-003b";
14035 + if (!dai->dai_fmt)
14036 + dai->dai_fmt = SND_SOC_DAIFMT_I2S |
14037 + SND_SOC_DAIFMT_NB_NF |
14038 + SND_SOC_DAIFMT_CBM_CFM;
14039 +
14040 + snd_rpi_wm8804.dai_link = dai;
14041 + i2s_node = of_parse_phandle(pdev->dev.of_node,
14042 + "i2s-controller", 0);
14043 + if (!i2s_node) {
14044 + pr_err("Failed to find i2s-controller DT node\n");
14045 + return -ENODEV;
14046 + }
14047 +
14048 + snd_rpi_wm8804.name = drvdata->card_name;
14049 +
14050 + /* If requested by in drvdata get card & DAI names from DT */
14051 + if (drvdata->card_name_dt)
14052 + of_property_read_string(i2s_node,
14053 + drvdata->card_name_dt,
14054 + &snd_rpi_wm8804.name);
14055 +
14056 + if (drvdata->dai_name_dt)
14057 + of_property_read_string(i2s_node,
14058 + drvdata->dai_name_dt,
14059 + &dai->name);
14060 +
14061 + if (drvdata->dai_stream_name_dt)
14062 + of_property_read_string(i2s_node,
14063 + drvdata->dai_stream_name_dt,
14064 + &dai->stream_name);
14065 +
14066 + dai->cpus->of_node = i2s_node;
14067 + dai->platforms->of_node = i2s_node;
14068 +
14069 + /*
14070 + * clk44gpio and clk48gpio are not required by all cards so
14071 + * don't check the error status.
14072 + */
14073 + snd_clk44gpio =
14074 + devm_gpiod_get(&pdev->dev, "clock44", GPIOD_OUT_LOW);
14075 +
14076 + snd_clk48gpio =
14077 + devm_gpiod_get(&pdev->dev, "clock48", GPIOD_OUT_LOW);
14078 +
14079 + if (drvdata->probe) {
14080 + ret = drvdata->probe(pdev);
14081 + if (ret < 0) {
14082 + dev_err(&pdev->dev, "Custom probe failed %d\n",
14083 + ret);
14084 + return ret;
14085 + }
14086 + }
14087 +
14088 + pr_debug("%s card: %s dai: %s stream: %s\n", __func__,
14089 + snd_rpi_wm8804.name,
14090 + dai->name, dai->stream_name);
14091 + }
14092 +
14093 + ret = devm_snd_soc_register_card(&pdev->dev, &snd_rpi_wm8804);
14094 + if (ret && ret != -EPROBE_DEFER)
14095 + dev_err(&pdev->dev, "Failed to register card %d\n", ret);
14096 +
14097 + return ret;
14098 +}
14099 +
14100 +static struct platform_driver snd_rpi_wm8804_driver = {
14101 + .driver = {
14102 + .name = "snd-rpi-wm8804",
14103 + .owner = THIS_MODULE,
14104 + .of_match_table = snd_rpi_wm8804_of_match,
14105 + },
14106 + .probe = snd_rpi_wm8804_probe,
14107 +};
14108 +MODULE_DEVICE_TABLE(of, snd_rpi_wm8804_of_match);
14109 +
14110 +module_platform_driver(snd_rpi_wm8804_driver);
14111 +
14112 +MODULE_AUTHOR("Tim Gover <tim.gover@raspberrypi.org>");
14113 +MODULE_DESCRIPTION("ASoC Raspberry Pi Hat generic digi driver for WM8804 based cards");
14114 +MODULE_LICENSE("GPL v2");
14115 --- a/sound/soc/codecs/Kconfig
14116 +++ b/sound/soc/codecs/Kconfig
14117 @@ -102,6 +102,7 @@ config SND_SOC_ALL_CODECS
14118 imply SND_SOC_ICS43432
14119 imply SND_SOC_INNO_RK3036
14120 imply SND_SOC_ISABELLE
14121 + imply SND_SOC_I_SABRE_CODEC
14122 imply SND_SOC_JZ4740_CODEC
14123 imply SND_SOC_JZ4725B_CODEC
14124 imply SND_SOC_JZ4760_CODEC
14125 @@ -109,6 +110,7 @@ config SND_SOC_ALL_CODECS
14126 imply SND_SOC_LM4857
14127 imply SND_SOC_LM49453
14128 imply SND_SOC_LOCHNAGAR_SC
14129 + imply SND_SOC_MA120X0P
14130 imply SND_SOC_MAX98088
14131 imply SND_SOC_MAX98090
14132 imply SND_SOC_MAX98095
14133 @@ -146,6 +148,7 @@ config SND_SOC_ALL_CODECS
14134 imply SND_SOC_PCM179X_SPI
14135 imply SND_SOC_PCM186X_I2C
14136 imply SND_SOC_PCM186X_SPI
14137 + imply SND_SOC_PCM1794A
14138 imply SND_SOC_PCM3008
14139 imply SND_SOC_PCM3060_I2C
14140 imply SND_SOC_PCM3060_SPI
14141 @@ -217,6 +220,7 @@ config SND_SOC_ALL_CODECS
14142 imply SND_SOC_TLV320ADCX140
14143 imply SND_SOC_TLV320AIC23_I2C
14144 imply SND_SOC_TLV320AIC23_SPI
14145 + imply SND_SOC_TAS5713
14146 imply SND_SOC_TLV320AIC26
14147 imply SND_SOC_TLV320AIC31XX
14148 imply SND_SOC_TLV320AIC32X4_I2C
14149 @@ -358,12 +362,12 @@ config SND_SOC_AD193X
14150 tristate
14151
14152 config SND_SOC_AD193X_SPI
14153 - tristate
14154 + tristate "Analog Devices AU193X CODEC - SPI"
14155 depends on SPI_MASTER
14156 select SND_SOC_AD193X
14157
14158 config SND_SOC_AD193X_I2C
14159 - tristate
14160 + tristate "Analog Devices AU193X CODEC - I2C"
14161 depends on I2C
14162 select SND_SOC_AD193X
14163
14164 @@ -873,6 +877,13 @@ config SND_SOC_LOCHNAGAR_SC
14165 This driver support the sound card functionality of the Cirrus
14166 Logic Lochnagar audio development board.
14167
14168 +config SND_SOC_MA120X0P
14169 + tristate "Infineon Merus(TM) MA120X0P Multilevel Class-D Audio amplifiers"
14170 + depends on I2C
14171 + help
14172 + Enable support for Infineon MA120X0P Multilevel Class-D audio power
14173 + amplifiers.
14174 +
14175 config SND_SOC_MADERA
14176 tristate
14177 default y if SND_SOC_CS47L15=y
14178 @@ -1189,6 +1200,10 @@ config SND_SOC_RT5616
14179 tristate "Realtek RT5616 CODEC"
14180 depends on I2C
14181
14182 +config SND_SOC_PCM1794A
14183 + tristate
14184 + depends on I2C
14185 +
14186 config SND_SOC_RT5631
14187 tristate "Realtek ALC5631/RT5631 CODEC"
14188 depends on I2C
14189 @@ -1439,6 +1454,9 @@ config SND_SOC_TFA9879
14190 tristate "NXP Semiconductors TFA9879 amplifier"
14191 depends on I2C
14192
14193 +config SND_SOC_TAS5713
14194 + tristate
14195 +
14196 config SND_SOC_TFA989X
14197 tristate "NXP/Goodix TFA989X (TFA1) amplifiers"
14198 depends on I2C
14199 @@ -1945,4 +1963,8 @@ config SND_SOC_LPASS_TX_MACRO
14200 select REGMAP_MMIO
14201 tristate "Qualcomm TX Macro in LPASS(Low Power Audio SubSystem)"
14202
14203 +config SND_SOC_I_SABRE_CODEC
14204 + tristate "Audiophonics I-SABRE Codec"
14205 + depends on I2C
14206 +
14207 endmenu
14208 --- a/sound/soc/codecs/Makefile
14209 +++ b/sound/soc/codecs/Makefile
14210 @@ -99,6 +99,7 @@ snd-soc-hdac-hda-objs := hdac_hda.o
14211 snd-soc-ics43432-objs := ics43432.o
14212 snd-soc-inno-rk3036-objs := inno_rk3036.o
14213 snd-soc-isabelle-objs := isabelle.o
14214 +snd-soc-i-sabre-codec-objs := i-sabre-codec.o
14215 snd-soc-jz4740-codec-objs := jz4740.o
14216 snd-soc-jz4725b-codec-objs := jz4725b.o
14217 snd-soc-jz4760-codec-objs := jz4760.o
14218 @@ -111,6 +112,7 @@ snd-soc-lpass-rx-macro-objs := lpass-rx-
14219 snd-soc-lpass-tx-macro-objs := lpass-tx-macro.o
14220 snd-soc-lpass-wsa-macro-objs := lpass-wsa-macro.o
14221 snd-soc-lpass-va-macro-objs := lpass-va-macro.o
14222 +snd-soc-ma120x0p-objs := ma120x0p.o
14223 snd-soc-madera-objs := madera.o
14224 snd-soc-max9759-objs := max9759.o
14225 snd-soc-max9768-objs := max9768.o
14226 @@ -154,6 +156,7 @@ snd-soc-pcm179x-spi-objs := pcm179x-spi.
14227 snd-soc-pcm186x-objs := pcm186x.o
14228 snd-soc-pcm186x-i2c-objs := pcm186x-i2c.o
14229 snd-soc-pcm186x-spi-objs := pcm186x-spi.o
14230 +snd-soc-pcm1794a-objs := pcm1794a.o
14231 snd-soc-pcm3008-objs := pcm3008.o
14232 snd-soc-pcm3060-objs := pcm3060.o
14233 snd-soc-pcm3060-i2c-objs := pcm3060-i2c.o
14234 @@ -231,6 +234,7 @@ snd-soc-tas6424-objs := tas6424.o
14235 snd-soc-tda7419-objs := tda7419.o
14236 snd-soc-tas2770-objs := tas2770.o
14237 snd-soc-tfa9879-objs := tfa9879.o
14238 +snd-soc-tas5713-objs := tas5713.o
14239 snd-soc-tfa989x-objs := tfa989x.o
14240 snd-soc-tlv320aic23-objs := tlv320aic23.o
14241 snd-soc-tlv320aic23-i2c-objs := tlv320aic23-i2c.o
14242 @@ -430,6 +434,7 @@ obj-$(CONFIG_SND_SOC_HDAC_HDA) += snd-so
14243 obj-$(CONFIG_SND_SOC_ICS43432) += snd-soc-ics43432.o
14244 obj-$(CONFIG_SND_SOC_INNO_RK3036) += snd-soc-inno-rk3036.o
14245 obj-$(CONFIG_SND_SOC_ISABELLE) += snd-soc-isabelle.o
14246 +obj-$(CONFIG_SND_SOC_I_SABRE_CODEC) += snd-soc-i-sabre-codec.o
14247 obj-$(CONFIG_SND_SOC_JZ4740_CODEC) += snd-soc-jz4740-codec.o
14248 obj-$(CONFIG_SND_SOC_JZ4725B_CODEC) += snd-soc-jz4725b-codec.o
14249 obj-$(CONFIG_SND_SOC_JZ4760_CODEC) += snd-soc-jz4760-codec.o
14250 @@ -438,6 +443,7 @@ obj-$(CONFIG_SND_SOC_L3) += snd-soc-l3.o
14251 obj-$(CONFIG_SND_SOC_LM4857) += snd-soc-lm4857.o
14252 obj-$(CONFIG_SND_SOC_LM49453) += snd-soc-lm49453.o
14253 obj-$(CONFIG_SND_SOC_LOCHNAGAR_SC) += snd-soc-lochnagar-sc.o
14254 +obj-$(CONFIG_SND_SOC_MA120X0P) += snd-soc-ma120x0p.o
14255 obj-$(CONFIG_SND_SOC_MADERA) += snd-soc-madera.o
14256 obj-$(CONFIG_SND_SOC_MAX9759) += snd-soc-max9759.o
14257 obj-$(CONFIG_SND_SOC_MAX9768) += snd-soc-max9768.o
14258 @@ -492,6 +498,7 @@ obj-$(CONFIG_SND_SOC_PCM5102A) += snd-so
14259 obj-$(CONFIG_SND_SOC_PCM512x) += snd-soc-pcm512x.o
14260 obj-$(CONFIG_SND_SOC_PCM512x_I2C) += snd-soc-pcm512x-i2c.o
14261 obj-$(CONFIG_SND_SOC_PCM512x_SPI) += snd-soc-pcm512x-spi.o
14262 +obj-$(CONFIG_SND_SOC_PCM1794A) += snd-soc-pcm1794a.o
14263 obj-$(CONFIG_SND_SOC_RK3328) += snd-soc-rk3328.o
14264 obj-$(CONFIG_SND_SOC_RK817) += snd-soc-rk817.o
14265 obj-$(CONFIG_SND_SOC_RL6231) += snd-soc-rl6231.o
14266 @@ -558,6 +565,7 @@ obj-$(CONFIG_SND_SOC_TAS5720) += snd-soc
14267 obj-$(CONFIG_SND_SOC_TAS6424) += snd-soc-tas6424.o
14268 obj-$(CONFIG_SND_SOC_TDA7419) += snd-soc-tda7419.o
14269 obj-$(CONFIG_SND_SOC_TAS2770) += snd-soc-tas2770.o
14270 +obj-$(CONFIG_SND_SOC_TAS5713) += snd-soc-tas5713.o
14271 obj-$(CONFIG_SND_SOC_TFA9879) += snd-soc-tfa9879.o
14272 obj-$(CONFIG_SND_SOC_TFA989X) += snd-soc-tfa989x.o
14273 obj-$(CONFIG_SND_SOC_TLV320AIC23) += snd-soc-tlv320aic23.o
14274 --- a/sound/soc/codecs/cs42xx8-i2c.c
14275 +++ b/sound/soc/codecs/cs42xx8-i2c.c
14276 @@ -45,11 +45,18 @@ static struct i2c_device_id cs42xx8_i2c_
14277 };
14278 MODULE_DEVICE_TABLE(i2c, cs42xx8_i2c_id);
14279
14280 +const struct of_device_id cs42xx8_i2c_of_match[] = {
14281 + { .compatible = "cirrus,cs42448", .data = &cs42448_data, },
14282 + { .compatible = "cirrus,cs42888", .data = &cs42888_data, },
14283 + { /* sentinel */ }
14284 +};
14285 +MODULE_DEVICE_TABLE(of, cs42xx8_i2c_of_match);
14286 +
14287 static struct i2c_driver cs42xx8_i2c_driver = {
14288 .driver = {
14289 .name = "cs42xx8",
14290 .pm = &cs42xx8_pm,
14291 - .of_match_table = cs42xx8_of_match,
14292 + .of_match_table = cs42xx8_i2c_of_match,
14293 },
14294 .probe = cs42xx8_i2c_probe,
14295 .remove = cs42xx8_i2c_remove,
14296 --- a/sound/soc/codecs/cs42xx8.c
14297 +++ b/sound/soc/codecs/cs42xx8.c
14298 @@ -517,8 +517,10 @@ const struct of_device_id cs42xx8_of_mat
14299 { .compatible = "cirrus,cs42888", .data = &cs42888_data, },
14300 { /* sentinel */ }
14301 };
14302 +#if !IS_ENABLED(CONFIG_SND_SOC_CS42XX8_I2C)
14303 MODULE_DEVICE_TABLE(of, cs42xx8_of_match);
14304 EXPORT_SYMBOL_GPL(cs42xx8_of_match);
14305 +#endif
14306
14307 int cs42xx8_probe(struct device *dev, struct regmap *regmap)
14308 {
14309 --- /dev/null
14310 +++ b/sound/soc/codecs/i-sabre-codec.c
14311 @@ -0,0 +1,392 @@
14312 +/*
14313 + * Driver for I-Sabre Q2M
14314 + *
14315 + * Author: Satoru Kawase
14316 + * Modified by: Xiao Qingyong
14317 + * Modified by: JC BARBAUD (Mute)
14318 + * Update kernel v4.18+ by : Audiophonics
14319 + * Copyright 2018 Audiophonics
14320 + *
14321 + * This program is free software; you can redistribute it and/or
14322 + * modify it under the terms of the GNU General Public License
14323 + * version 2 as published by the Free Software Foundation.
14324 + *
14325 + * This program is distributed in the hope that it will be useful, but
14326 + * WITHOUT ANY WARRANTY; without even the implied warranty of
14327 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14328 + * General Public License for more details.
14329 + */
14330 +
14331 +
14332 +#include <linux/init.h>
14333 +#include <linux/module.h>
14334 +#include <linux/regmap.h>
14335 +#include <linux/i2c.h>
14336 +#include <sound/soc.h>
14337 +#include <sound/pcm_params.h>
14338 +#include <sound/tlv.h>
14339 +
14340 +#include "i-sabre-codec.h"
14341 +
14342 +
14343 +/* I-Sabre Q2M Codec Private Data */
14344 +struct i_sabre_codec_priv {
14345 + struct regmap *regmap;
14346 + unsigned int fmt;
14347 +};
14348 +
14349 +
14350 +/* I-Sabre Q2M Codec Default Register Value */
14351 +static const struct reg_default i_sabre_codec_reg_defaults[] = {
14352 + { ISABRECODEC_REG_10, 0x00 },
14353 + { ISABRECODEC_REG_20, 0x00 },
14354 + { ISABRECODEC_REG_21, 0x00 },
14355 + { ISABRECODEC_REG_22, 0x00 },
14356 + { ISABRECODEC_REG_24, 0x00 },
14357 +};
14358 +
14359 +
14360 +static bool i_sabre_codec_writeable(struct device *dev, unsigned int reg)
14361 +{
14362 + switch (reg) {
14363 + case ISABRECODEC_REG_10:
14364 + case ISABRECODEC_REG_20:
14365 + case ISABRECODEC_REG_21:
14366 + case ISABRECODEC_REG_22:
14367 + case ISABRECODEC_REG_24:
14368 + return true;
14369 +
14370 + default:
14371 + return false;
14372 + }
14373 +}
14374 +
14375 +static bool i_sabre_codec_readable(struct device *dev, unsigned int reg)
14376 +{
14377 + switch (reg) {
14378 + case ISABRECODEC_REG_01:
14379 + case ISABRECODEC_REG_02:
14380 + case ISABRECODEC_REG_10:
14381 + case ISABRECODEC_REG_20:
14382 + case ISABRECODEC_REG_21:
14383 + case ISABRECODEC_REG_22:
14384 + case ISABRECODEC_REG_24:
14385 + return true;
14386 +
14387 + default:
14388 + return false;
14389 + }
14390 +}
14391 +
14392 +static bool i_sabre_codec_volatile(struct device *dev, unsigned int reg)
14393 +{
14394 + switch (reg) {
14395 + case ISABRECODEC_REG_01:
14396 + case ISABRECODEC_REG_02:
14397 + return true;
14398 +
14399 + default:
14400 + return false;
14401 + }
14402 +}
14403 +
14404 +
14405 +/* Volume Scale */
14406 +static const DECLARE_TLV_DB_SCALE(volume_tlv, -10000, 100, 0);
14407 +
14408 +
14409 +/* Filter Type */
14410 +static const char * const fir_filter_type_texts[] = {
14411 + "brick wall",
14412 + "corrected minimum phase fast",
14413 + "minimum phase slow",
14414 + "minimum phase fast",
14415 + "linear phase slow",
14416 + "linear phase fast",
14417 + "apodizing fast",
14418 +};
14419 +
14420 +static SOC_ENUM_SINGLE_DECL(i_sabre_fir_filter_type_enum,
14421 + ISABRECODEC_REG_22, 0, fir_filter_type_texts);
14422 +
14423 +
14424 +/* I2S / SPDIF Select */
14425 +static const char * const iis_spdif_sel_texts[] = {
14426 + "I2S",
14427 + "SPDIF",
14428 +};
14429 +
14430 +static SOC_ENUM_SINGLE_DECL(i_sabre_iis_spdif_sel_enum,
14431 + ISABRECODEC_REG_24, 0, iis_spdif_sel_texts);
14432 +
14433 +
14434 +/* Control */
14435 +static const struct snd_kcontrol_new i_sabre_codec_controls[] = {
14436 +SOC_SINGLE_RANGE_TLV("Digital Playback Volume", ISABRECODEC_REG_20, 0, 0, 100, 1, volume_tlv),
14437 +SOC_SINGLE("Digital Playback Switch", ISABRECODEC_REG_21, 0, 1, 1),
14438 +SOC_ENUM("FIR Filter Type", i_sabre_fir_filter_type_enum),
14439 +SOC_ENUM("I2S/SPDIF Select", i_sabre_iis_spdif_sel_enum),
14440 +};
14441 +
14442 +
14443 +static const u32 i_sabre_codec_dai_rates_slave[] = {
14444 + 8000, 11025, 16000, 22050, 32000,
14445 + 44100, 48000, 64000, 88200, 96000,
14446 + 176400, 192000, 352800, 384000,
14447 + 705600, 768000, 1411200, 1536000
14448 +};
14449 +
14450 +static const struct snd_pcm_hw_constraint_list constraints_slave = {
14451 + .list = i_sabre_codec_dai_rates_slave,
14452 + .count = ARRAY_SIZE(i_sabre_codec_dai_rates_slave),
14453 +};
14454 +
14455 +static int i_sabre_codec_dai_startup_slave(
14456 + struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
14457 +{
14458 + struct snd_soc_component *component = dai->component;
14459 + int ret;
14460 +
14461 + ret = snd_pcm_hw_constraint_list(substream->runtime,
14462 + 0, SNDRV_PCM_HW_PARAM_RATE, &constraints_slave);
14463 + if (ret != 0) {
14464 + dev_err(component->card->dev, "Failed to setup rates constraints: %d\n", ret);
14465 + }
14466 +
14467 + return ret;
14468 +}
14469 +
14470 +static int i_sabre_codec_dai_startup(
14471 + struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
14472 +{
14473 + struct snd_soc_component *component = dai->component;
14474 + struct i_sabre_codec_priv *i_sabre_codec
14475 + = snd_soc_component_get_drvdata(component);
14476 +
14477 + switch (i_sabre_codec->fmt & SND_SOC_DAIFMT_MASTER_MASK) {
14478 + case SND_SOC_DAIFMT_CBS_CFS:
14479 + return i_sabre_codec_dai_startup_slave(substream, dai);
14480 +
14481 + default:
14482 + return (-EINVAL);
14483 + }
14484 +}
14485 +
14486 +static int i_sabre_codec_hw_params(
14487 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params,
14488 + struct snd_soc_dai *dai)
14489 +{
14490 + struct snd_soc_component *component = dai->component;
14491 + struct i_sabre_codec_priv *i_sabre_codec
14492 + = snd_soc_component_get_drvdata(component);
14493 + unsigned int daifmt;
14494 + int format_width;
14495 +
14496 + dev_dbg(component->card->dev, "hw_params %u Hz, %u channels\n",
14497 + params_rate(params), params_channels(params));
14498 +
14499 + /* Check I2S Format (Bit Size) */
14500 + format_width = snd_pcm_format_width(params_format(params));
14501 + if ((format_width != 32) && (format_width != 16)) {
14502 + dev_err(component->card->dev, "Bad frame size: %d\n",
14503 + snd_pcm_format_width(params_format(params)));
14504 + return (-EINVAL);
14505 + }
14506 +
14507 + /* Check Slave Mode */
14508 + daifmt = i_sabre_codec->fmt & SND_SOC_DAIFMT_MASTER_MASK;
14509 + if (daifmt != SND_SOC_DAIFMT_CBS_CFS) {
14510 + return (-EINVAL);
14511 + }
14512 +
14513 + /* Notify Sampling Frequency */
14514 + switch (params_rate(params))
14515 + {
14516 + case 44100:
14517 + case 48000:
14518 + case 88200:
14519 + case 96000:
14520 + case 176400:
14521 + case 192000:
14522 + snd_soc_component_update_bits(component, ISABRECODEC_REG_10, 0x01, 0x00);
14523 + break;
14524 +
14525 + case 352800:
14526 + case 384000:
14527 + case 705600:
14528 + case 768000:
14529 + case 1411200:
14530 + case 1536000:
14531 + snd_soc_component_update_bits(component, ISABRECODEC_REG_10, 0x01, 0x01);
14532 + break;
14533 + }
14534 +
14535 + return 0;
14536 +}
14537 +
14538 +static int i_sabre_codec_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
14539 +{
14540 + struct snd_soc_component *component = dai->component;
14541 + struct i_sabre_codec_priv *i_sabre_codec
14542 + = snd_soc_component_get_drvdata(component);
14543 +
14544 + /* interface format */
14545 + switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
14546 + case SND_SOC_DAIFMT_I2S:
14547 + break;
14548 +
14549 + case SND_SOC_DAIFMT_RIGHT_J:
14550 + case SND_SOC_DAIFMT_LEFT_J:
14551 + default:
14552 + return (-EINVAL);
14553 + }
14554 +
14555 + /* clock inversion */
14556 + if ((fmt & SND_SOC_DAIFMT_INV_MASK) != SND_SOC_DAIFMT_NB_NF) {
14557 + return (-EINVAL);
14558 + }
14559 +
14560 + /* Set Audio Data Format */
14561 + i_sabre_codec->fmt = fmt;
14562 +
14563 + return 0;
14564 +}
14565 +
14566 +static int i_sabre_codec_dac_mute(struct snd_soc_dai *dai, int mute, int direction)
14567 +{
14568 + struct snd_soc_component *component = dai->component;
14569 +
14570 + if (mute) {
14571 + snd_soc_component_update_bits(component, ISABRECODEC_REG_21, 0x01, 0x01);
14572 + } else {
14573 + snd_soc_component_update_bits(component, ISABRECODEC_REG_21, 0x01, 0x00);
14574 + }
14575 +
14576 + return 0;
14577 +}
14578 +
14579 +
14580 +static const struct snd_soc_dai_ops i_sabre_codec_dai_ops = {
14581 + .startup = i_sabre_codec_dai_startup,
14582 + .hw_params = i_sabre_codec_hw_params,
14583 + .set_fmt = i_sabre_codec_set_fmt,
14584 + .mute_stream = i_sabre_codec_dac_mute,
14585 +};
14586 +
14587 +static struct snd_soc_dai_driver i_sabre_codec_dai = {
14588 + .name = "i-sabre-codec-dai",
14589 + .playback = {
14590 + .stream_name = "Playback",
14591 + .channels_min = 2,
14592 + .channels_max = 2,
14593 + .rates = SNDRV_PCM_RATE_CONTINUOUS,
14594 + .rate_min = 8000,
14595 + .rate_max = 1536000,
14596 + .formats = SNDRV_PCM_FMTBIT_S16_LE
14597 + | SNDRV_PCM_FMTBIT_S32_LE,
14598 + },
14599 + .ops = &i_sabre_codec_dai_ops,
14600 +};
14601 +
14602 +static struct snd_soc_component_driver i_sabre_codec_codec_driver = {
14603 + .controls = i_sabre_codec_controls,
14604 + .num_controls = ARRAY_SIZE(i_sabre_codec_controls),
14605 +};
14606 +
14607 +
14608 +static const struct regmap_config i_sabre_codec_regmap = {
14609 + .reg_bits = 8,
14610 + .val_bits = 8,
14611 + .max_register = ISABRECODEC_MAX_REG,
14612 +
14613 + .reg_defaults = i_sabre_codec_reg_defaults,
14614 + .num_reg_defaults = ARRAY_SIZE(i_sabre_codec_reg_defaults),
14615 +
14616 + .writeable_reg = i_sabre_codec_writeable,
14617 + .readable_reg = i_sabre_codec_readable,
14618 + .volatile_reg = i_sabre_codec_volatile,
14619 +
14620 + .cache_type = REGCACHE_RBTREE,
14621 +};
14622 +
14623 +
14624 +static int i_sabre_codec_probe(struct device *dev, struct regmap *regmap)
14625 +{
14626 + struct i_sabre_codec_priv *i_sabre_codec;
14627 + int ret;
14628 +
14629 + i_sabre_codec = devm_kzalloc(dev, sizeof(*i_sabre_codec), GFP_KERNEL);
14630 + if (!i_sabre_codec) {
14631 + dev_err(dev, "devm_kzalloc");
14632 + return (-ENOMEM);
14633 + }
14634 +
14635 + i_sabre_codec->regmap = regmap;
14636 +
14637 + dev_set_drvdata(dev, i_sabre_codec);
14638 +
14639 + ret = snd_soc_register_component(dev,
14640 + &i_sabre_codec_codec_driver, &i_sabre_codec_dai, 1);
14641 + if (ret != 0) {
14642 + dev_err(dev, "Failed to register CODEC: %d\n", ret);
14643 + return ret;
14644 + }
14645 +
14646 + return 0;
14647 +}
14648 +
14649 +static void i_sabre_codec_remove(struct device *dev)
14650 +{
14651 + snd_soc_unregister_component(dev);
14652 +}
14653 +
14654 +
14655 +static int i_sabre_codec_i2c_probe(
14656 + struct i2c_client *i2c, const struct i2c_device_id *id)
14657 +{
14658 + struct regmap *regmap;
14659 +
14660 + regmap = devm_regmap_init_i2c(i2c, &i_sabre_codec_regmap);
14661 + if (IS_ERR(regmap)) {
14662 + return PTR_ERR(regmap);
14663 + }
14664 +
14665 + return i_sabre_codec_probe(&i2c->dev, regmap);
14666 +}
14667 +
14668 +static int i_sabre_codec_i2c_remove(struct i2c_client *i2c)
14669 +{
14670 + i_sabre_codec_remove(&i2c->dev);
14671 +
14672 + return 0;
14673 +}
14674 +
14675 +
14676 +static const struct i2c_device_id i_sabre_codec_i2c_id[] = {
14677 + { "i-sabre-codec", },
14678 + { }
14679 +};
14680 +MODULE_DEVICE_TABLE(i2c, i_sabre_codec_i2c_id);
14681 +
14682 +static const struct of_device_id i_sabre_codec_of_match[] = {
14683 + { .compatible = "audiophonics,i-sabre-codec", },
14684 + { }
14685 +};
14686 +MODULE_DEVICE_TABLE(of, i_sabre_codec_of_match);
14687 +
14688 +static struct i2c_driver i_sabre_codec_i2c_driver = {
14689 + .driver = {
14690 + .name = "i-sabre-codec-i2c",
14691 + .owner = THIS_MODULE,
14692 + .of_match_table = of_match_ptr(i_sabre_codec_of_match),
14693 + },
14694 + .probe = i_sabre_codec_i2c_probe,
14695 + .remove = i_sabre_codec_i2c_remove,
14696 + .id_table = i_sabre_codec_i2c_id,
14697 +};
14698 +module_i2c_driver(i_sabre_codec_i2c_driver);
14699 +
14700 +
14701 +MODULE_DESCRIPTION("ASoC I-Sabre Q2M codec driver");
14702 +MODULE_AUTHOR("Audiophonics <http://www.audiophonics.fr>");
14703 +MODULE_LICENSE("GPL");
14704 --- /dev/null
14705 +++ b/sound/soc/codecs/i-sabre-codec.h
14706 @@ -0,0 +1,42 @@
14707 +/*
14708 + * Driver for I-Sabre Q2M
14709 + *
14710 + * Author: Satoru Kawase
14711 + * Modified by: Xiao Qingyong
14712 + * Copyright 2018 Audiophonics
14713 + *
14714 + * This program is free software; you can redistribute it and/or
14715 + * modify it under the terms of the GNU General Public License
14716 + * version 2 as published by the Free Software Foundation.
14717 + *
14718 + * This program is distributed in the hope that it will be useful, but
14719 + * WITHOUT ANY WARRANTY; without even the implied warranty of
14720 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14721 + * General Public License for more details.
14722 + */
14723 +
14724 +#ifndef _SND_SOC_ISABRECODEC
14725 +#define _SND_SOC_ISABRECODEC
14726 +
14727 +
14728 +/* ISABRECODEC Register Address */
14729 +#define ISABRECODEC_REG_01 0x01 /* Virtual Device ID : 0x01 = es9038q2m */
14730 +#define ISABRECODEC_REG_02 0x02 /* API revision : 0x01 = Revision 01 */
14731 +#define ISABRECODEC_REG_10 0x10 /* 0x01 = above 192kHz, 0x00 = otherwise */
14732 +#define ISABRECODEC_REG_20 0x20 /* 0 - 100 (decimal value, 0 = min., 100 = max.) */
14733 +#define ISABRECODEC_REG_21 0x21 /* 0x00 = Mute OFF, 0x01 = Mute ON */
14734 +#define ISABRECODEC_REG_22 0x22
14735 +/*
14736 + 0x00 = brick wall,
14737 + 0x01 = corrected minimum phase fast,
14738 + 0x02 = minimum phase slow,
14739 + 0x03 = minimum phase fast,
14740 + 0x04 = linear phase slow,
14741 + 0x05 = linear phase fast,
14742 + 0x06 = apodizing fast,
14743 +*/
14744 +//#define ISABRECODEC_REG_23 0x23 /* reserved */
14745 +#define ISABRECODEC_REG_24 0x24 /* 0x00 = I2S, 0x01 = SPDIF */
14746 +#define ISABRECODEC_MAX_REG 0x24 /* Maximum Register Number */
14747 +
14748 +#endif /* _SND_SOC_ISABRECODEC */
14749 --- /dev/null
14750 +++ b/sound/soc/codecs/ma120x0p.c
14751 @@ -0,0 +1,1384 @@
14752 +// SPDX-License-Identifier: GPL-2.0-or-later
14753 +/*
14754 + * ASoC Driver for Infineon Merus(TM) ma120x0p multi-level class-D amplifier
14755 + *
14756 + * Authors: Ariel Muszkat <ariel.muszkat@gmail.com>
14757 + * Jorgen Kragh Jakobsen <jorgen.kraghjakobsen@infineon.com>
14758 + *
14759 + * Copyright (C) 2019 Infineon Technologies AG
14760 + *
14761 + */
14762 +#include <linux/module.h>
14763 +#include <linux/moduleparam.h>
14764 +#include <linux/init.h>
14765 +#include <linux/delay.h>
14766 +#include <linux/pm_runtime.h>
14767 +#include <linux/i2c.h>
14768 +#include <linux/of_device.h>
14769 +#include <linux/spi/spi.h>
14770 +#include <linux/regmap.h>
14771 +#include <linux/regulator/consumer.h>
14772 +#include <linux/slab.h>
14773 +#include <linux/gpio/consumer.h>
14774 +#include <linux/gpio.h>
14775 +#include <sound/core.h>
14776 +#include <sound/pcm.h>
14777 +#include <sound/pcm_params.h>
14778 +#include <sound/soc.h>
14779 +#include <sound/soc-dapm.h>
14780 +#include <sound/initval.h>
14781 +#include <sound/tlv.h>
14782 +#include <linux/interrupt.h>
14783 +
14784 +#include <linux/kernel.h>
14785 +#include <linux/string.h>
14786 +#include <linux/fs.h>
14787 +#include <linux/uaccess.h>
14788 +
14789 +#ifndef _MA120X0P_
14790 +#define _MA120X0P_
14791 +//------------------------------------------------------------------manualPM---
14792 +// Select Manual PowerMode control
14793 +#define ma_manualpm__a 0
14794 +#define ma_manualpm__len 1
14795 +#define ma_manualpm__mask 0x40
14796 +#define ma_manualpm__shift 0x06
14797 +#define ma_manualpm__reset 0x00
14798 +//--------------------------------------------------------------------pm_man---
14799 +// manual selected power mode
14800 +#define ma_pm_man__a 0
14801 +#define ma_pm_man__len 2
14802 +#define ma_pm_man__mask 0x30
14803 +#define ma_pm_man__shift 0x04
14804 +#define ma_pm_man__reset 0x03
14805 +//------------------------------------------ ----------------------mthr_1to2---
14806 +// mod. index threshold value for pm1=>pm2 change.
14807 +#define ma_mthr_1to2__a 1
14808 +#define ma_mthr_1to2__len 8
14809 +#define ma_mthr_1to2__mask 0xff
14810 +#define ma_mthr_1to2__shift 0x00
14811 +#define ma_mthr_1to2__reset 0x3c
14812 +//-----------------------------------------------------------------mthr_2to1---
14813 +// mod. index threshold value for pm2=>pm1 change.
14814 +#define ma_mthr_2to1__a 2
14815 +#define ma_mthr_2to1__len 8
14816 +#define ma_mthr_2to1__mask 0xff
14817 +#define ma_mthr_2to1__shift 0x00
14818 +#define ma_mthr_2to1__reset 0x32
14819 +//-----------------------------------------------------------------mthr_2to3---
14820 +// mod. index threshold value for pm2=>pm3 change.
14821 +#define ma_mthr_2to3__a 3
14822 +#define ma_mthr_2to3__len 8
14823 +#define ma_mthr_2to3__mask 0xff
14824 +#define ma_mthr_2to3__shift 0x00
14825 +#define ma_mthr_2to3__reset 0x5a
14826 +//-----------------------------------------------------------------mthr_3to2---
14827 +// mod. index threshold value for pm3=>pm2 change.
14828 +#define ma_mthr_3to2__a 4
14829 +#define ma_mthr_3to2__len 8
14830 +#define ma_mthr_3to2__mask 0xff
14831 +#define ma_mthr_3to2__shift 0x00
14832 +#define ma_mthr_3to2__reset 0x50
14833 +//-------------------------------------------------------------pwmclkdiv_nom---
14834 +// pwm default clock divider value
14835 +#define ma_pwmclkdiv_nom__a 8
14836 +#define ma_pwmclkdiv_nom__len 8
14837 +#define ma_pwmclkdiv_nom__mask 0xff
14838 +#define ma_pwmclkdiv_nom__shift 0x00
14839 +#define ma_pwmclkdiv_nom__reset 0x26
14840 +//--------- ----------------------------------------------------ocp_latch_en---
14841 +// high to use permanently latching level-2 ocp
14842 +#define ma_ocp_latch_en__a 10
14843 +#define ma_ocp_latch_en__len 1
14844 +#define ma_ocp_latch_en__mask 0x02
14845 +#define ma_ocp_latch_en__shift 0x01
14846 +#define ma_ocp_latch_en__reset 0x00
14847 +//---------------------------------------------------------------lf_clamp_en---
14848 +// high (default) to enable lf int2+3 clamping on clip
14849 +#define ma_lf_clamp_en__a 10
14850 +#define ma_lf_clamp_en__len 1
14851 +#define ma_lf_clamp_en__mask 0x80
14852 +#define ma_lf_clamp_en__shift 0x07
14853 +#define ma_lf_clamp_en__reset 0x00
14854 +//-------------------------------------------------------pmcfg_btl_b.modtype---
14855 +//
14856 +#define ma_pmcfg_btl_b__modtype__a 18
14857 +#define ma_pmcfg_btl_b__modtype__len 2
14858 +#define ma_pmcfg_btl_b__modtype__mask 0x18
14859 +#define ma_pmcfg_btl_b__modtype__shift 0x03
14860 +#define ma_pmcfg_btl_b__modtype__reset 0x02
14861 +//-------------------------------------------------------pmcfg_btl_b.freqdiv---
14862 +#define ma_pmcfg_btl_b__freqdiv__a 18
14863 +#define ma_pmcfg_btl_b__freqdiv__len 2
14864 +#define ma_pmcfg_btl_b__freqdiv__mask 0x06
14865 +#define ma_pmcfg_btl_b__freqdiv__shift 0x01
14866 +#define ma_pmcfg_btl_b__freqdiv__reset 0x01
14867 +//----------------------------------------------------pmcfg_btl_b.lf_gain_ol---
14868 +//
14869 +#define ma_pmcfg_btl_b__lf_gain_ol__a 18
14870 +#define ma_pmcfg_btl_b__lf_gain_ol__len 1
14871 +#define ma_pmcfg_btl_b__lf_gain_ol__mask 0x01
14872 +#define ma_pmcfg_btl_b__lf_gain_ol__shift 0x00
14873 +#define ma_pmcfg_btl_b__lf_gain_ol__reset 0x01
14874 +//-------------------------------------------------------pmcfg_btl_c.freqdiv---
14875 +//
14876 +#define ma_pmcfg_btl_c__freqdiv__a 19
14877 +#define ma_pmcfg_btl_c__freqdiv__len 2
14878 +#define ma_pmcfg_btl_c__freqdiv__mask 0x06
14879 +#define ma_pmcfg_btl_c__freqdiv__shift 0x01
14880 +#define ma_pmcfg_btl_c__freqdiv__reset 0x01
14881 +//-------------------------------------------------------pmcfg_btl_c.modtype---
14882 +//
14883 +#define ma_pmcfg_btl_c__modtype__a 19
14884 +#define ma_pmcfg_btl_c__modtype__len 2
14885 +#define ma_pmcfg_btl_c__modtype__mask 0x18
14886 +#define ma_pmcfg_btl_c__modtype__shift 0x03
14887 +#define ma_pmcfg_btl_c__modtype__reset 0x01
14888 +//----------------------------------------------------pmcfg_btl_c.lf_gain_ol---
14889 +//
14890 +#define ma_pmcfg_btl_c__lf_gain_ol__a 19
14891 +#define ma_pmcfg_btl_c__lf_gain_ol__len 1
14892 +#define ma_pmcfg_btl_c__lf_gain_ol__mask 0x01
14893 +#define ma_pmcfg_btl_c__lf_gain_ol__shift 0x00
14894 +#define ma_pmcfg_btl_c__lf_gain_ol__reset 0x00
14895 +//-------------------------------------------------------pmcfg_btl_d.modtype---
14896 +//
14897 +#define ma_pmcfg_btl_d__modtype__a 20
14898 +#define ma_pmcfg_btl_d__modtype__len 2
14899 +#define ma_pmcfg_btl_d__modtype__mask 0x18
14900 +#define ma_pmcfg_btl_d__modtype__shift 0x03
14901 +#define ma_pmcfg_btl_d__modtype__reset 0x02
14902 +//-------------------------------------------------------pmcfg_btl_d.freqdiv---
14903 +//
14904 +#define ma_pmcfg_btl_d__freqdiv__a 20
14905 +#define ma_pmcfg_btl_d__freqdiv__len 2
14906 +#define ma_pmcfg_btl_d__freqdiv__mask 0x06
14907 +#define ma_pmcfg_btl_d__freqdiv__shift 0x01
14908 +#define ma_pmcfg_btl_d__freqdiv__reset 0x02
14909 +//----------------------------------------------------pmcfg_btl_d.lf_gain_ol---
14910 +//
14911 +#define ma_pmcfg_btl_d__lf_gain_ol__a 20
14912 +#define ma_pmcfg_btl_d__lf_gain_ol__len 1
14913 +#define ma_pmcfg_btl_d__lf_gain_ol__mask 0x01
14914 +#define ma_pmcfg_btl_d__lf_gain_ol__shift 0x00
14915 +#define ma_pmcfg_btl_d__lf_gain_ol__reset 0x00
14916 +//------------ -------------------------------------------pmcfg_se_a.modtype---
14917 +//
14918 +#define ma_pmcfg_se_a__modtype__a 21
14919 +#define ma_pmcfg_se_a__modtype__len 2
14920 +#define ma_pmcfg_se_a__modtype__mask 0x18
14921 +#define ma_pmcfg_se_a__modtype__shift 0x03
14922 +#define ma_pmcfg_se_a__modtype__reset 0x01
14923 +//--------------------------------------------------------pmcfg_se_a.freqdiv---
14924 +//
14925 +#define ma_pmcfg_se_a__freqdiv__a 21
14926 +#define ma_pmcfg_se_a__freqdiv__len 2
14927 +#define ma_pmcfg_se_a__freqdiv__mask 0x06
14928 +#define ma_pmcfg_se_a__freqdiv__shift 0x01
14929 +#define ma_pmcfg_se_a__freqdiv__reset 0x00
14930 +//-----------------------------------------------------pmcfg_se_a.lf_gain_ol---
14931 +//
14932 +#define ma_pmcfg_se_a__lf_gain_ol__a 21
14933 +#define ma_pmcfg_se_a__lf_gain_ol__len 1
14934 +#define ma_pmcfg_se_a__lf_gain_ol__mask 0x01
14935 +#define ma_pmcfg_se_a__lf_gain_ol__shift 0x00
14936 +#define ma_pmcfg_se_a__lf_gain_ol__reset 0x01
14937 +//-----------------------------------------------------pmcfg_se_b.lf_gain_ol---
14938 +//
14939 +#define ma_pmcfg_se_b__lf_gain_ol__a 22
14940 +#define ma_pmcfg_se_b__lf_gain_ol__len 1
14941 +#define ma_pmcfg_se_b__lf_gain_ol__mask 0x01
14942 +#define ma_pmcfg_se_b__lf_gain_ol__shift 0x00
14943 +#define ma_pmcfg_se_b__lf_gain_ol__reset 0x00
14944 +//--------------------------------------------------------pmcfg_se_b.freqdiv---
14945 +//
14946 +#define ma_pmcfg_se_b__freqdiv__a 22
14947 +#define ma_pmcfg_se_b__freqdiv__len 2
14948 +#define ma_pmcfg_se_b__freqdiv__mask 0x06
14949 +#define ma_pmcfg_se_b__freqdiv__shift 0x01
14950 +#define ma_pmcfg_se_b__freqdiv__reset 0x01
14951 +//--------------------------------------------------------pmcfg_se_b.modtype---
14952 +//
14953 +#define ma_pmcfg_se_b__modtype__a 22
14954 +#define ma_pmcfg_se_b__modtype__len 2
14955 +#define ma_pmcfg_se_b__modtype__mask 0x18
14956 +#define ma_pmcfg_se_b__modtype__shift 0x03
14957 +#define ma_pmcfg_se_b__modtype__reset 0x01
14958 +//----------------------------------------------------------balwaitcount_pm1---
14959 +// pm1 balancing period.
14960 +#define ma_balwaitcount_pm1__a 23
14961 +#define ma_balwaitcount_pm1__len 8
14962 +#define ma_balwaitcount_pm1__mask 0xff
14963 +#define ma_balwaitcount_pm1__shift 0x00
14964 +#define ma_balwaitcount_pm1__reset 0x14
14965 +//----------------------------------------------------------balwaitcount_pm2---
14966 +// pm2 balancing period.
14967 +#define ma_balwaitcount_pm2__a 24
14968 +#define ma_balwaitcount_pm2__len 8
14969 +#define ma_balwaitcount_pm2__mask 0xff
14970 +#define ma_balwaitcount_pm2__shift 0x00
14971 +#define ma_balwaitcount_pm2__reset 0x14
14972 +//----------------------------------------------------------balwaitcount_pm3---
14973 +// pm3 balancing period.
14974 +#define ma_balwaitcount_pm3__a 25
14975 +#define ma_balwaitcount_pm3__len 8
14976 +#define ma_balwaitcount_pm3__mask 0xff
14977 +#define ma_balwaitcount_pm3__shift 0x00
14978 +#define ma_balwaitcount_pm3__reset 0x1a
14979 +//-------------------------------------------------------------usespread_pm1---
14980 +// pm1 pwm spread-spectrum mode on/off.
14981 +#define ma_usespread_pm1__a 26
14982 +#define ma_usespread_pm1__len 1
14983 +#define ma_usespread_pm1__mask 0x40
14984 +#define ma_usespread_pm1__shift 0x06
14985 +#define ma_usespread_pm1__reset 0x00
14986 +//---------------------------------------------------------------dtsteps_pm1---
14987 +// pm1 dead time setting [10ns steps].
14988 +#define ma_dtsteps_pm1__a 26
14989 +#define ma_dtsteps_pm1__len 3
14990 +#define ma_dtsteps_pm1__mask 0x38
14991 +#define ma_dtsteps_pm1__shift 0x03
14992 +#define ma_dtsteps_pm1__reset 0x04
14993 +//---------------------------------------------------------------baltype_pm1---
14994 +// pm1 balancing sensor scheme.
14995 +#define ma_baltype_pm1__a 26
14996 +#define ma_baltype_pm1__len 3
14997 +#define ma_baltype_pm1__mask 0x07
14998 +#define ma_baltype_pm1__shift 0x00
14999 +#define ma_baltype_pm1__reset 0x00
15000 +//-------------------------------------------------------------usespread_pm2---
15001 +// pm2 pwm spread-spectrum mode on/off.
15002 +#define ma_usespread_pm2__a 27
15003 +#define ma_usespread_pm2__len 1
15004 +#define ma_usespread_pm2__mask 0x40
15005 +#define ma_usespread_pm2__shift 0x06
15006 +#define ma_usespread_pm2__reset 0x00
15007 +//---------------------------------------------------------------dtsteps_pm2---
15008 +// pm2 dead time setting [10ns steps].
15009 +#define ma_dtsteps_pm2__a 27
15010 +#define ma_dtsteps_pm2__len 3
15011 +#define ma_dtsteps_pm2__mask 0x38
15012 +#define ma_dtsteps_pm2__shift 0x03
15013 +#define ma_dtsteps_pm2__reset 0x03
15014 +//---------------------------------------------------------------baltype_pm2---
15015 +// pm2 balancing sensor scheme.
15016 +#define ma_baltype_pm2__a 27
15017 +#define ma_baltype_pm2__len 3
15018 +#define ma_baltype_pm2__mask 0x07
15019 +#define ma_baltype_pm2__shift 0x00
15020 +#define ma_baltype_pm2__reset 0x01
15021 +//-------------------------------------------------------------usespread_pm3---
15022 +// pm3 pwm spread-spectrum mode on/off.
15023 +#define ma_usespread_pm3__a 28
15024 +#define ma_usespread_pm3__len 1
15025 +#define ma_usespread_pm3__mask 0x40
15026 +#define ma_usespread_pm3__shift 0x06
15027 +#define ma_usespread_pm3__reset 0x00
15028 +//---------------------------------------------------------------dtsteps_pm3---
15029 +// pm3 dead time setting [10ns steps].
15030 +#define ma_dtsteps_pm3__a 28
15031 +#define ma_dtsteps_pm3__len 3
15032 +#define ma_dtsteps_pm3__mask 0x38
15033 +#define ma_dtsteps_pm3__shift 0x03
15034 +#define ma_dtsteps_pm3__reset 0x01
15035 +//---------------------------------------------------------------baltype_pm3---
15036 +// pm3 balancing sensor scheme.
15037 +#define ma_baltype_pm3__a 28
15038 +#define ma_baltype_pm3__len 3
15039 +#define ma_baltype_pm3__mask 0x07
15040 +#define ma_baltype_pm3__shift 0x00
15041 +#define ma_baltype_pm3__reset 0x03
15042 +//-----------------------------------------------------------------pmprofile---
15043 +// pm profile select. valid presets: 0-1-2-3-4. 5=> custom profile.
15044 +#define ma_pmprofile__a 29
15045 +#define ma_pmprofile__len 3
15046 +#define ma_pmprofile__mask 0x07
15047 +#define ma_pmprofile__shift 0x00
15048 +#define ma_pmprofile__reset 0x00
15049 +//-------------------------------------------------------------------pm3_man---
15050 +// custom profile pm3 contents. 0=>a, 1=>b, 2=>c, 3=>d
15051 +#define ma_pm3_man__a 30
15052 +#define ma_pm3_man__len 2
15053 +#define ma_pm3_man__mask 0x30
15054 +#define ma_pm3_man__shift 0x04
15055 +#define ma_pm3_man__reset 0x02
15056 +//-------------------------------------------------------------------pm2_man---
15057 +// custom profile pm2 contents. 0=>a, 1=>b, 2=>c, 3=>d
15058 +#define ma_pm2_man__a 30
15059 +#define ma_pm2_man__len 2
15060 +#define ma_pm2_man__mask 0x0c
15061 +#define ma_pm2_man__shift 0x02
15062 +#define ma_pm2_man__reset 0x03
15063 +//-------------------------------------------------------------------pm1_man---
15064 +// custom profile pm1 contents. 0=>a, 1=>b, 2=>c, 3=>d
15065 +#define ma_pm1_man__a 30
15066 +#define ma_pm1_man__len 2
15067 +#define ma_pm1_man__mask 0x03
15068 +#define ma_pm1_man__shift 0x00
15069 +#define ma_pm1_man__reset 0x03
15070 +//-----------------------------------------------------------ocp_latch_clear---
15071 +// low-high clears current ocp latched condition.
15072 +#define ma_ocp_latch_clear__a 32
15073 +#define ma_ocp_latch_clear__len 1
15074 +#define ma_ocp_latch_clear__mask 0x80
15075 +#define ma_ocp_latch_clear__shift 0x07
15076 +#define ma_ocp_latch_clear__reset 0x00
15077 +//-------------------------------------------------------------audio_in_mode---
15078 +// audio input mode; 0-1-2-3-4-5
15079 +#define ma_audio_in_mode__a 37
15080 +#define ma_audio_in_mode__len 3
15081 +#define ma_audio_in_mode__mask 0xe0
15082 +#define ma_audio_in_mode__shift 0x05
15083 +#define ma_audio_in_mode__reset 0x00
15084 +//-----------------------------------------------------------------eh_dcshdn---
15085 +// high to enable dc protection
15086 +#define ma_eh_dcshdn__a 38
15087 +#define ma_eh_dcshdn__len 1
15088 +#define ma_eh_dcshdn__mask 0x04
15089 +#define ma_eh_dcshdn__shift 0x02
15090 +#define ma_eh_dcshdn__reset 0x01
15091 +//---------------------------------------------------------audio_in_mode_ext---
15092 +// if set, audio_in_mode is controlled from audio_in_mode register. if not set
15093 +//audio_in_mode is set from fuse bank setting
15094 +#define ma_audio_in_mode_ext__a 39
15095 +#define ma_audio_in_mode_ext__len 1
15096 +#define ma_audio_in_mode_ext__mask 0x20
15097 +#define ma_audio_in_mode_ext__shift 0x05
15098 +#define ma_audio_in_mode_ext__reset 0x00
15099 +//------------------------------------------------------------------eh_clear---
15100 +// flip to clear error registers
15101 +#define ma_eh_clear__a 45
15102 +#define ma_eh_clear__len 1
15103 +#define ma_eh_clear__mask 0x04
15104 +#define ma_eh_clear__shift 0x02
15105 +#define ma_eh_clear__reset 0x00
15106 +//----------------------------------------------------------thermal_compr_en---
15107 +// enable otw-contr. input compression?
15108 +#define ma_thermal_compr_en__a 45
15109 +#define ma_thermal_compr_en__len 1
15110 +#define ma_thermal_compr_en__mask 0x20
15111 +#define ma_thermal_compr_en__shift 0x05
15112 +#define ma_thermal_compr_en__reset 0x01
15113 +//---------------------------------------------------------------system_mute---
15114 +// 1 = mute system, 0 = normal operation
15115 +#define ma_system_mute__a 45
15116 +#define ma_system_mute__len 1
15117 +#define ma_system_mute__mask 0x40
15118 +#define ma_system_mute__shift 0x06
15119 +#define ma_system_mute__reset 0x00
15120 +//------------------------------------------------------thermal_compr_max_db---
15121 +// audio limiter max thermal reduction
15122 +#define ma_thermal_compr_max_db__a 46
15123 +#define ma_thermal_compr_max_db__len 3
15124 +#define ma_thermal_compr_max_db__mask 0x07
15125 +#define ma_thermal_compr_max_db__shift 0x00
15126 +#define ma_thermal_compr_max_db__reset 0x04
15127 +//---------------------------------------------------------audio_proc_enable---
15128 +// enable audio proc, bypass if not enabled
15129 +#define ma_audio_proc_enable__a 53
15130 +#define ma_audio_proc_enable__len 1
15131 +#define ma_audio_proc_enable__mask 0x08
15132 +#define ma_audio_proc_enable__shift 0x03
15133 +#define ma_audio_proc_enable__reset 0x00
15134 +//--------------------------------------------------------audio_proc_release---
15135 +// 00:slow, 01:normal, 10:fast
15136 +#define ma_audio_proc_release__a 53
15137 +#define ma_audio_proc_release__len 2
15138 +#define ma_audio_proc_release__mask 0x30
15139 +#define ma_audio_proc_release__shift 0x04
15140 +#define ma_audio_proc_release__reset 0x00
15141 +//---------------------------------------------------------audio_proc_attack---
15142 +// 00:slow, 01:normal, 10:fast
15143 +#define ma_audio_proc_attack__a 53
15144 +#define ma_audio_proc_attack__len 2
15145 +#define ma_audio_proc_attack__mask 0xc0
15146 +#define ma_audio_proc_attack__shift 0x06
15147 +#define ma_audio_proc_attack__reset 0x00
15148 +//----------------------------------------------------------------i2s_format---
15149 +// i2s basic data format, 000 = std. i2s, 001 = left justified (default)
15150 +#define ma_i2s_format__a 53
15151 +#define ma_i2s_format__len 3
15152 +#define ma_i2s_format__mask 0x07
15153 +#define ma_i2s_format__shift 0x00
15154 +#define ma_i2s_format__reset 0x01
15155 +//--------------------------------------------------audio_proc_limiterenable---
15156 +// 1: enable limiter, 0: disable limiter
15157 +#define ma_audio_proc_limiterenable__a 54
15158 +#define ma_audio_proc_limiterenable__len 1
15159 +#define ma_audio_proc_limiterenable__mask 0x40
15160 +#define ma_audio_proc_limiterenable__shift 0x06
15161 +#define ma_audio_proc_limiterenable__reset 0x00
15162 +//-----------------------------------------------------------audio_proc_mute---
15163 +// 1: mute, 0: unmute
15164 +#define ma_audio_proc_mute__a 54
15165 +#define ma_audio_proc_mute__len 1
15166 +#define ma_audio_proc_mute__mask 0x80
15167 +#define ma_audio_proc_mute__shift 0x07
15168 +#define ma_audio_proc_mute__reset 0x00
15169 +//---------------------------------------------------------------i2s_sck_pol---
15170 +// i2s sck polarity cfg. 0 = rising edge data change
15171 +#define ma_i2s_sck_pol__a 54
15172 +#define ma_i2s_sck_pol__len 1
15173 +#define ma_i2s_sck_pol__mask 0x01
15174 +#define ma_i2s_sck_pol__shift 0x00
15175 +#define ma_i2s_sck_pol__reset 0x01
15176 +//-------------------------------------------------------------i2s_framesize---
15177 +// i2s word length. 00 = 32bit, 01 = 24bit
15178 +#define ma_i2s_framesize__a 54
15179 +#define ma_i2s_framesize__len 2
15180 +#define ma_i2s_framesize__mask 0x18
15181 +#define ma_i2s_framesize__shift 0x03
15182 +#define ma_i2s_framesize__reset 0x00
15183 +//----------------------------------------------------------------i2s_ws_pol---
15184 +// i2s ws polarity. 0 = low first
15185 +#define ma_i2s_ws_pol__a 54
15186 +#define ma_i2s_ws_pol__len 1
15187 +#define ma_i2s_ws_pol__mask 0x02
15188 +#define ma_i2s_ws_pol__shift 0x01
15189 +#define ma_i2s_ws_pol__reset 0x00
15190 +//-----------------------------------------------------------------i2s_order---
15191 +// i2s word bit order. 0 = msb first
15192 +#define ma_i2s_order__a 54
15193 +#define ma_i2s_order__len 1
15194 +#define ma_i2s_order__mask 0x04
15195 +#define ma_i2s_order__shift 0x02
15196 +#define ma_i2s_order__reset 0x00
15197 +//------------------------------------------------------------i2s_rightfirst---
15198 +// i2s l/r word order; 0 = left first
15199 +#define ma_i2s_rightfirst__a 54
15200 +#define ma_i2s_rightfirst__len 1
15201 +#define ma_i2s_rightfirst__mask 0x20
15202 +#define ma_i2s_rightfirst__shift 0x05
15203 +#define ma_i2s_rightfirst__reset 0x00
15204 +//-------------------------------------------------------------vol_db_master---
15205 +// master volume db
15206 +#define ma_vol_db_master__a 64
15207 +#define ma_vol_db_master__len 8
15208 +#define ma_vol_db_master__mask 0xff
15209 +#define ma_vol_db_master__shift 0x00
15210 +#define ma_vol_db_master__reset 0x18
15211 +//------------------------------------------------------------vol_lsb_master---
15212 +// master volume lsb 1/4 steps
15213 +#define ma_vol_lsb_master__a 65
15214 +#define ma_vol_lsb_master__len 2
15215 +#define ma_vol_lsb_master__mask 0x03
15216 +#define ma_vol_lsb_master__shift 0x00
15217 +#define ma_vol_lsb_master__reset 0x00
15218 +//----------------------------------------------------------------vol_db_ch0---
15219 +// volume channel 0
15220 +#define ma_vol_db_ch0__a 66
15221 +#define ma_vol_db_ch0__len 8
15222 +#define ma_vol_db_ch0__mask 0xff
15223 +#define ma_vol_db_ch0__shift 0x00
15224 +#define ma_vol_db_ch0__reset 0x18
15225 +//----------------------------------------------------------------vol_db_ch1---
15226 +// volume channel 1
15227 +#define ma_vol_db_ch1__a 67
15228 +#define ma_vol_db_ch1__len 8
15229 +#define ma_vol_db_ch1__mask 0xff
15230 +#define ma_vol_db_ch1__shift 0x00
15231 +#define ma_vol_db_ch1__reset 0x18
15232 +//----------------------------------------------------------------vol_db_ch2---
15233 +// volume channel 2
15234 +#define ma_vol_db_ch2__a 68
15235 +#define ma_vol_db_ch2__len 8
15236 +#define ma_vol_db_ch2__mask 0xff
15237 +#define ma_vol_db_ch2__shift 0x00
15238 +#define ma_vol_db_ch2__reset 0x18
15239 +//----------------------------------------------------------------vol_db_ch3---
15240 +// volume channel 3
15241 +#define ma_vol_db_ch3__a 69
15242 +#define ma_vol_db_ch3__len 8
15243 +#define ma_vol_db_ch3__mask 0xff
15244 +#define ma_vol_db_ch3__shift 0x00
15245 +#define ma_vol_db_ch3__reset 0x18
15246 +//---------------------------------------------------------------vol_lsb_ch0---
15247 +// volume channel 1 - 1/4 steps
15248 +#define ma_vol_lsb_ch0__a 70
15249 +#define ma_vol_lsb_ch0__len 2
15250 +#define ma_vol_lsb_ch0__mask 0x03
15251 +#define ma_vol_lsb_ch0__shift 0x00
15252 +#define ma_vol_lsb_ch0__reset 0x00
15253 +//---------------------------------------------------------------vol_lsb_ch1---
15254 +// volume channel 3 - 1/4 steps
15255 +#define ma_vol_lsb_ch1__a 70
15256 +#define ma_vol_lsb_ch1__len 2
15257 +#define ma_vol_lsb_ch1__mask 0x0c
15258 +#define ma_vol_lsb_ch1__shift 0x02
15259 +#define ma_vol_lsb_ch1__reset 0x00
15260 +//---------------------------------------------------------------vol_lsb_ch2---
15261 +// volume channel 2 - 1/4 steps
15262 +#define ma_vol_lsb_ch2__a 70
15263 +#define ma_vol_lsb_ch2__len 2
15264 +#define ma_vol_lsb_ch2__mask 0x30
15265 +#define ma_vol_lsb_ch2__shift 0x04
15266 +#define ma_vol_lsb_ch2__reset 0x00
15267 +//---------------------------------------------------------------vol_lsb_ch3---
15268 +// volume channel 3 - 1/4 steps
15269 +#define ma_vol_lsb_ch3__a 70
15270 +#define ma_vol_lsb_ch3__len 2
15271 +#define ma_vol_lsb_ch3__mask 0xc0
15272 +#define ma_vol_lsb_ch3__shift 0x06
15273 +#define ma_vol_lsb_ch3__reset 0x00
15274 +//----------------------------------------------------------------thr_db_ch0---
15275 +// thr_db channel 0
15276 +#define ma_thr_db_ch0__a 71
15277 +#define ma_thr_db_ch0__len 8
15278 +#define ma_thr_db_ch0__mask 0xff
15279 +#define ma_thr_db_ch0__shift 0x00
15280 +#define ma_thr_db_ch0__reset 0x18
15281 +//----------------------------------------------------------------thr_db_ch1---
15282 +// thr db ch1
15283 +#define ma_thr_db_ch1__a 72
15284 +#define ma_thr_db_ch1__len 8
15285 +#define ma_thr_db_ch1__mask 0xff
15286 +#define ma_thr_db_ch1__shift 0x00
15287 +#define ma_thr_db_ch1__reset 0x18
15288 +//----------------------------------------------------------------thr_db_ch2---
15289 +// thr db ch2
15290 +#define ma_thr_db_ch2__a 73
15291 +#define ma_thr_db_ch2__len 8
15292 +#define ma_thr_db_ch2__mask 0xff
15293 +#define ma_thr_db_ch2__shift 0x00
15294 +#define ma_thr_db_ch2__reset 0x18
15295 +//----------------------------------------------------------------thr_db_ch3---
15296 +// threshold db ch3
15297 +#define ma_thr_db_ch3__a 74
15298 +#define ma_thr_db_ch3__len 8
15299 +#define ma_thr_db_ch3__mask 0xff
15300 +#define ma_thr_db_ch3__shift 0x00
15301 +#define ma_thr_db_ch3__reset 0x18
15302 +//---------------------------------------------------------------thr_lsb_ch0---
15303 +// thr lsb ch0
15304 +#define ma_thr_lsb_ch0__a 75
15305 +#define ma_thr_lsb_ch0__len 2
15306 +#define ma_thr_lsb_ch0__mask 0x03
15307 +#define ma_thr_lsb_ch0__shift 0x00
15308 +#define ma_thr_lsb_ch0__reset 0x00
15309 +//---------------------------------------------------------------thr_lsb_ch1---
15310 +// thr lsb ch1
15311 +#define ma_thr_lsb_ch1__a 75
15312 +#define ma_thr_lsb_ch1__len 2
15313 +#define ma_thr_lsb_ch1__mask 0x0c
15314 +#define ma_thr_lsb_ch1__shift 0x02
15315 +#define ma_thr_lsb_ch1__reset 0x00
15316 +//---------------------------------------------------------------thr_lsb_ch2---
15317 +// thr lsb ch2 1/4 db step
15318 +#define ma_thr_lsb_ch2__a 75
15319 +#define ma_thr_lsb_ch2__len 2
15320 +#define ma_thr_lsb_ch2__mask 0x30
15321 +#define ma_thr_lsb_ch2__shift 0x04
15322 +#define ma_thr_lsb_ch2__reset 0x00
15323 +//---------------------------------------------------------------thr_lsb_ch3---
15324 +// threshold lsb ch3
15325 +#define ma_thr_lsb_ch3__a 75
15326 +#define ma_thr_lsb_ch3__len 2
15327 +#define ma_thr_lsb_ch3__mask 0xc0
15328 +#define ma_thr_lsb_ch3__shift 0x06
15329 +#define ma_thr_lsb_ch3__reset 0x00
15330 +//-----------------------------------------------------------dcu_mon0.pm_mon---
15331 +// power mode monitor channel 0
15332 +#define ma_dcu_mon0__pm_mon__a 96
15333 +#define ma_dcu_mon0__pm_mon__len 2
15334 +#define ma_dcu_mon0__pm_mon__mask 0x03
15335 +#define ma_dcu_mon0__pm_mon__shift 0x00
15336 +#define ma_dcu_mon0__pm_mon__reset 0x00
15337 +//-----------------------------------------------------dcu_mon0.freqmode_mon---
15338 +// frequence mode monitor channel 0
15339 +#define ma_dcu_mon0__freqmode_mon__a 96
15340 +#define ma_dcu_mon0__freqmode_mon__len 3
15341 +#define ma_dcu_mon0__freqmode_mon__mask 0x70
15342 +#define ma_dcu_mon0__freqmode_mon__shift 0x04
15343 +#define ma_dcu_mon0__freqmode_mon__reset 0x00
15344 +//-------------------------------------------------------dcu_mon0.pps_passed---
15345 +// dcu0 pps completion indicator
15346 +#define ma_dcu_mon0__pps_passed__a 96
15347 +#define ma_dcu_mon0__pps_passed__len 1
15348 +#define ma_dcu_mon0__pps_passed__mask 0x80
15349 +#define ma_dcu_mon0__pps_passed__shift 0x07
15350 +#define ma_dcu_mon0__pps_passed__reset 0x00
15351 +//----------------------------------------------------------dcu_mon0.ocp_mon---
15352 +// ocp monitor channel 0
15353 +#define ma_dcu_mon0__ocp_mon__a 97
15354 +#define ma_dcu_mon0__ocp_mon__len 1
15355 +#define ma_dcu_mon0__ocp_mon__mask 0x01
15356 +#define ma_dcu_mon0__ocp_mon__shift 0x00
15357 +#define ma_dcu_mon0__ocp_mon__reset 0x00
15358 +//--------------------------------------------------------dcu_mon0.vcfly1_ok---
15359 +// cfly1 protection monitor channel 0.
15360 +#define ma_dcu_mon0__vcfly1_ok__a 97
15361 +#define ma_dcu_mon0__vcfly1_ok__len 1
15362 +#define ma_dcu_mon0__vcfly1_ok__mask 0x02
15363 +#define ma_dcu_mon0__vcfly1_ok__shift 0x01
15364 +#define ma_dcu_mon0__vcfly1_ok__reset 0x00
15365 +//--------------------------------------------------------dcu_mon0.vcfly2_ok---
15366 +// cfly2 protection monitor channel 0.
15367 +#define ma_dcu_mon0__vcfly2_ok__a 97
15368 +#define ma_dcu_mon0__vcfly2_ok__len 1
15369 +#define ma_dcu_mon0__vcfly2_ok__mask 0x04
15370 +#define ma_dcu_mon0__vcfly2_ok__shift 0x02
15371 +#define ma_dcu_mon0__vcfly2_ok__reset 0x00
15372 +//----------------------------------------------------------dcu_mon0.pvdd_ok---
15373 +// dcu0 pvdd monitor
15374 +#define ma_dcu_mon0__pvdd_ok__a 97
15375 +#define ma_dcu_mon0__pvdd_ok__len 1
15376 +#define ma_dcu_mon0__pvdd_ok__mask 0x08
15377 +#define ma_dcu_mon0__pvdd_ok__shift 0x03
15378 +#define ma_dcu_mon0__pvdd_ok__reset 0x00
15379 +//-----------------------------------------------------------dcu_mon0.vdd_ok---
15380 +// dcu0 vdd monitor
15381 +#define ma_dcu_mon0__vdd_ok__a 97
15382 +#define ma_dcu_mon0__vdd_ok__len 1
15383 +#define ma_dcu_mon0__vdd_ok__mask 0x10
15384 +#define ma_dcu_mon0__vdd_ok__shift 0x04
15385 +#define ma_dcu_mon0__vdd_ok__reset 0x00
15386 +//-------------------------------------------------------------dcu_mon0.mute---
15387 +// dcu0 mute monitor
15388 +#define ma_dcu_mon0__mute__a 97
15389 +#define ma_dcu_mon0__mute__len 1
15390 +#define ma_dcu_mon0__mute__mask 0x20
15391 +#define ma_dcu_mon0__mute__shift 0x05
15392 +#define ma_dcu_mon0__mute__reset 0x00
15393 +//------------------------------------------------------------dcu_mon0.m_mon---
15394 +// m sense monitor channel 0
15395 +#define ma_dcu_mon0__m_mon__a 98
15396 +#define ma_dcu_mon0__m_mon__len 8
15397 +#define ma_dcu_mon0__m_mon__mask 0xff
15398 +#define ma_dcu_mon0__m_mon__shift 0x00
15399 +#define ma_dcu_mon0__m_mon__reset 0x00
15400 +//-----------------------------------------------------------dcu_mon1.pm_mon---
15401 +// power mode monitor channel 1
15402 +#define ma_dcu_mon1__pm_mon__a 100
15403 +#define ma_dcu_mon1__pm_mon__len 2
15404 +#define ma_dcu_mon1__pm_mon__mask 0x03
15405 +#define ma_dcu_mon1__pm_mon__shift 0x00
15406 +#define ma_dcu_mon1__pm_mon__reset 0x00
15407 +//-----------------------------------------------------dcu_mon1.freqmode_mon---
15408 +// frequence mode monitor channel 1
15409 +#define ma_dcu_mon1__freqmode_mon__a 100
15410 +#define ma_dcu_mon1__freqmode_mon__len 3
15411 +#define ma_dcu_mon1__freqmode_mon__mask 0x70
15412 +#define ma_dcu_mon1__freqmode_mon__shift 0x04
15413 +#define ma_dcu_mon1__freqmode_mon__reset 0x00
15414 +//-------------------------------------------------------dcu_mon1.pps_passed---
15415 +// dcu1 pps completion indicator
15416 +#define ma_dcu_mon1__pps_passed__a 100
15417 +#define ma_dcu_mon1__pps_passed__len 1
15418 +#define ma_dcu_mon1__pps_passed__mask 0x80
15419 +#define ma_dcu_mon1__pps_passed__shift 0x07
15420 +#define ma_dcu_mon1__pps_passed__reset 0x00
15421 +//----------------------------------------------------------dcu_mon1.ocp_mon---
15422 +// ocp monitor channel 1
15423 +#define ma_dcu_mon1__ocp_mon__a 101
15424 +#define ma_dcu_mon1__ocp_mon__len 1
15425 +#define ma_dcu_mon1__ocp_mon__mask 0x01
15426 +#define ma_dcu_mon1__ocp_mon__shift 0x00
15427 +#define ma_dcu_mon1__ocp_mon__reset 0x00
15428 +//--------------------------------------------------------dcu_mon1.vcfly1_ok---
15429 +// cfly1 protcetion monitor channel 1
15430 +#define ma_dcu_mon1__vcfly1_ok__a 101
15431 +#define ma_dcu_mon1__vcfly1_ok__len 1
15432 +#define ma_dcu_mon1__vcfly1_ok__mask 0x02
15433 +#define ma_dcu_mon1__vcfly1_ok__shift 0x01
15434 +#define ma_dcu_mon1__vcfly1_ok__reset 0x00
15435 +//--------------------------------------------------------dcu_mon1.vcfly2_ok---
15436 +// cfly2 protection monitor channel 1
15437 +#define ma_dcu_mon1__vcfly2_ok__a 101
15438 +#define ma_dcu_mon1__vcfly2_ok__len 1
15439 +#define ma_dcu_mon1__vcfly2_ok__mask 0x04
15440 +#define ma_dcu_mon1__vcfly2_ok__shift 0x02
15441 +#define ma_dcu_mon1__vcfly2_ok__reset 0x00
15442 +//----------------------------------------------------------dcu_mon1.pvdd_ok---
15443 +// dcu1 pvdd monitor
15444 +#define ma_dcu_mon1__pvdd_ok__a 101
15445 +#define ma_dcu_mon1__pvdd_ok__len 1
15446 +#define ma_dcu_mon1__pvdd_ok__mask 0x08
15447 +#define ma_dcu_mon1__pvdd_ok__shift 0x03
15448 +#define ma_dcu_mon1__pvdd_ok__reset 0x00
15449 +//-----------------------------------------------------------dcu_mon1.vdd_ok---
15450 +// dcu1 vdd monitor
15451 +#define ma_dcu_mon1__vdd_ok__a 101
15452 +#define ma_dcu_mon1__vdd_ok__len 1
15453 +#define ma_dcu_mon1__vdd_ok__mask 0x10
15454 +#define ma_dcu_mon1__vdd_ok__shift 0x04
15455 +#define ma_dcu_mon1__vdd_ok__reset 0x00
15456 +//-------------------------------------------------------------dcu_mon1.mute---
15457 +// dcu1 mute monitor
15458 +#define ma_dcu_mon1__mute__a 101
15459 +#define ma_dcu_mon1__mute__len 1
15460 +#define ma_dcu_mon1__mute__mask 0x20
15461 +#define ma_dcu_mon1__mute__shift 0x05
15462 +#define ma_dcu_mon1__mute__reset 0x00
15463 +//------------------------------------------------------------dcu_mon1.m_mon---
15464 +// m sense monitor channel 1
15465 +#define ma_dcu_mon1__m_mon__a 102
15466 +#define ma_dcu_mon1__m_mon__len 8
15467 +#define ma_dcu_mon1__m_mon__mask 0xff
15468 +#define ma_dcu_mon1__m_mon__shift 0x00
15469 +#define ma_dcu_mon1__m_mon__reset 0x00
15470 +//--------------------------------------------------------dcu_mon0.sw_enable---
15471 +// dcu0 switch enable monitor
15472 +#define ma_dcu_mon0__sw_enable__a 104
15473 +#define ma_dcu_mon0__sw_enable__len 1
15474 +#define ma_dcu_mon0__sw_enable__mask 0x40
15475 +#define ma_dcu_mon0__sw_enable__shift 0x06
15476 +#define ma_dcu_mon0__sw_enable__reset 0x00
15477 +//--------------------------------------------------------dcu_mon1.sw_enable---
15478 +// dcu1 switch enable monitor
15479 +#define ma_dcu_mon1__sw_enable__a 104
15480 +#define ma_dcu_mon1__sw_enable__len 1
15481 +#define ma_dcu_mon1__sw_enable__mask 0x80
15482 +#define ma_dcu_mon1__sw_enable__shift 0x07
15483 +#define ma_dcu_mon1__sw_enable__reset 0x00
15484 +//------------------------------------------------------------hvboot0_ok_mon---
15485 +// hvboot0_ok for test/debug
15486 +#define ma_hvboot0_ok_mon__a 105
15487 +#define ma_hvboot0_ok_mon__len 1
15488 +#define ma_hvboot0_ok_mon__mask 0x40
15489 +#define ma_hvboot0_ok_mon__shift 0x06
15490 +#define ma_hvboot0_ok_mon__reset 0x00
15491 +//------------------------------------------------------------hvboot1_ok_mon---
15492 +// hvboot1_ok for test/debug
15493 +#define ma_hvboot1_ok_mon__a 105
15494 +#define ma_hvboot1_ok_mon__len 1
15495 +#define ma_hvboot1_ok_mon__mask 0x80
15496 +#define ma_hvboot1_ok_mon__shift 0x07
15497 +#define ma_hvboot1_ok_mon__reset 0x00
15498 +//-----------------------------------------------------------------error_acc---
15499 +// accumulated errors, at and after triggering
15500 +#define ma_error_acc__a 109
15501 +#define ma_error_acc__len 8
15502 +#define ma_error_acc__mask 0xff
15503 +#define ma_error_acc__shift 0x00
15504 +#define ma_error_acc__reset 0x00
15505 +//-------------------------------------------------------------i2s_data_rate---
15506 +// detected i2s data rate: 00/01/10 = x1/x2/x4
15507 +#define ma_i2s_data_rate__a 116
15508 +#define ma_i2s_data_rate__len 2
15509 +#define ma_i2s_data_rate__mask 0x03
15510 +#define ma_i2s_data_rate__shift 0x00
15511 +#define ma_i2s_data_rate__reset 0x00
15512 +//---------------------------------------------------------audio_in_mode_mon---
15513 +// audio input mode monitor
15514 +#define ma_audio_in_mode_mon__a 116
15515 +#define ma_audio_in_mode_mon__len 3
15516 +#define ma_audio_in_mode_mon__mask 0x1c
15517 +#define ma_audio_in_mode_mon__shift 0x02
15518 +#define ma_audio_in_mode_mon__reset 0x00
15519 +//------------------------------------------------------------------msel_mon---
15520 +// msel[2:0] monitor register
15521 +#define ma_msel_mon__a 117
15522 +#define ma_msel_mon__len 3
15523 +#define ma_msel_mon__mask 0x07
15524 +#define ma_msel_mon__shift 0x00
15525 +#define ma_msel_mon__reset 0x00
15526 +//---------------------------------------------------------------------error---
15527 +// current error flag monitor reg - for app. ctrl.
15528 +#define ma_error__a 124
15529 +#define ma_error__len 8
15530 +#define ma_error__mask 0xff
15531 +#define ma_error__shift 0x00
15532 +#define ma_error__reset 0x00
15533 +//----------------------------------------------------audio_proc_limiter_mon---
15534 +// b7-b4: channel 3-0 limiter active
15535 +#define ma_audio_proc_limiter_mon__a 126
15536 +#define ma_audio_proc_limiter_mon__len 4
15537 +#define ma_audio_proc_limiter_mon__mask 0xf0
15538 +#define ma_audio_proc_limiter_mon__shift 0x04
15539 +#define ma_audio_proc_limiter_mon__reset 0x00
15540 +//-------------------------------------------------------audio_proc_clip_mon---
15541 +// b3-b0: channel 3-0 clipping monitor
15542 +#define ma_audio_proc_clip_mon__a 126
15543 +#define ma_audio_proc_clip_mon__len 4
15544 +#define ma_audio_proc_clip_mon__mask 0x0f
15545 +#define ma_audio_proc_clip_mon__shift 0x00
15546 +#define ma_audio_proc_clip_mon__reset 0x00
15547 +#endif
15548 +
15549 +#define SOC_ENUM_ERR(xname, xenum)\
15550 +{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
15551 + .access = SNDRV_CTL_ELEM_ACCESS_READ,\
15552 + .info = snd_soc_info_enum_double,\
15553 + .get = snd_soc_get_enum_double, .put = snd_soc_put_enum_double,\
15554 + .private_value = (unsigned long)&(xenum) }
15555 +
15556 +static struct i2c_client *i2c;
15557 +
15558 +struct ma120x0p_priv {
15559 + struct regmap *regmap;
15560 + int mclk_div;
15561 + struct snd_soc_component *component;
15562 + struct gpio_desc *enable_gpio;
15563 + struct gpio_desc *mute_gpio;
15564 + struct gpio_desc *booster_gpio;
15565 + struct gpio_desc *error_gpio;
15566 +};
15567 +
15568 +static struct ma120x0p_priv *priv_data;
15569 +
15570 +//Used to share the IRQ number within this file
15571 +static unsigned int irqNumber;
15572 +
15573 +// Function prototype for the custom IRQ handler function
15574 +static irqreturn_t ma120x0p_irq_handler(int irq, void *data);
15575 +
15576 +//Alsa Controls
15577 +static const char * const limenable_text[] = {"Bypassed", "Enabled"};
15578 +static const char * const limatack_text[] = {"Slow", "Normal", "Fast"};
15579 +static const char * const limrelease_text[] = {"Slow", "Normal", "Fast"};
15580 +
15581 +static const char * const err_flycap_text[] = {"Ok", "Error"};
15582 +static const char * const err_overcurr_text[] = {"Ok", "Error"};
15583 +static const char * const err_pllerr_text[] = {"Ok", "Error"};
15584 +static const char * const err_pvddunder_text[] = {"Ok", "Error"};
15585 +static const char * const err_overtempw_text[] = {"Ok", "Error"};
15586 +static const char * const err_overtempe_text[] = {"Ok", "Error"};
15587 +static const char * const err_pinlowimp_text[] = {"Ok", "Error"};
15588 +static const char * const err_dcprot_text[] = {"Ok", "Error"};
15589 +
15590 +static const char * const pwr_mode_prof_text[] = {"PMF0", "PMF1", "PMF2",
15591 +"PMF3", "PMF4"};
15592 +
15593 +static const struct soc_enum lim_enable_ctrl =
15594 + SOC_ENUM_SINGLE(ma_audio_proc_limiterenable__a,
15595 + ma_audio_proc_limiterenable__shift,
15596 + ma_audio_proc_limiterenable__len + 1,
15597 + limenable_text);
15598 +static const struct soc_enum limatack_ctrl =
15599 + SOC_ENUM_SINGLE(ma_audio_proc_attack__a,
15600 + ma_audio_proc_attack__shift,
15601 + ma_audio_proc_attack__len + 1,
15602 + limatack_text);
15603 +static const struct soc_enum limrelease_ctrl =
15604 + SOC_ENUM_SINGLE(ma_audio_proc_release__a,
15605 + ma_audio_proc_release__shift,
15606 + ma_audio_proc_release__len + 1,
15607 + limrelease_text);
15608 +static const struct soc_enum err_flycap_ctrl =
15609 + SOC_ENUM_SINGLE(ma_error__a, 0, 3, err_flycap_text);
15610 +static const struct soc_enum err_overcurr_ctrl =
15611 + SOC_ENUM_SINGLE(ma_error__a, 1, 3, err_overcurr_text);
15612 +static const struct soc_enum err_pllerr_ctrl =
15613 + SOC_ENUM_SINGLE(ma_error__a, 2, 3, err_pllerr_text);
15614 +static const struct soc_enum err_pvddunder_ctrl =
15615 + SOC_ENUM_SINGLE(ma_error__a, 3, 3, err_pvddunder_text);
15616 +static const struct soc_enum err_overtempw_ctrl =
15617 + SOC_ENUM_SINGLE(ma_error__a, 4, 3, err_overtempw_text);
15618 +static const struct soc_enum err_overtempe_ctrl =
15619 + SOC_ENUM_SINGLE(ma_error__a, 5, 3, err_overtempe_text);
15620 +static const struct soc_enum err_pinlowimp_ctrl =
15621 + SOC_ENUM_SINGLE(ma_error__a, 6, 3, err_pinlowimp_text);
15622 +static const struct soc_enum err_dcprot_ctrl =
15623 + SOC_ENUM_SINGLE(ma_error__a, 7, 3, err_dcprot_text);
15624 +static const struct soc_enum pwr_mode_prof_ctrl =
15625 + SOC_ENUM_SINGLE(ma_pmprofile__a, ma_pmprofile__shift, 5,
15626 + pwr_mode_prof_text);
15627 +
15628 +static const char * const pwr_mode_texts[] = {
15629 + "Dynamic power mode",
15630 + "Power mode 1",
15631 + "Power mode 2",
15632 + "Power mode 3",
15633 + };
15634 +
15635 +static const int pwr_mode_values[] = {
15636 + 0x10,
15637 + 0x50,
15638 + 0x60,
15639 + 0x70,
15640 + };
15641 +
15642 +static const SOC_VALUE_ENUM_SINGLE_DECL(pwr_mode_ctrl,
15643 + ma_pm_man__a, 0, 0x70,
15644 + pwr_mode_texts,
15645 + pwr_mode_values);
15646 +
15647 +static const DECLARE_TLV_DB_SCALE(ma120x0p_vol_tlv, -5000, 100, 0);
15648 +static const DECLARE_TLV_DB_SCALE(ma120x0p_lim_tlv, -5000, 100, 0);
15649 +static const DECLARE_TLV_DB_SCALE(ma120x0p_lr_tlv, -5000, 100, 0);
15650 +
15651 +static const struct snd_kcontrol_new ma120x0p_snd_controls[] = {
15652 + //Master Volume
15653 + SOC_SINGLE_RANGE_TLV("A.Mstr Vol Volume",
15654 + ma_vol_db_master__a, 0, 0x18, 0x4a, 1, ma120x0p_vol_tlv),
15655 +
15656 + //L-R Volume ch0
15657 + SOC_SINGLE_RANGE_TLV("B.L Vol Volume",
15658 + ma_vol_db_ch0__a, 0, 0x18, 0x4a, 1, ma120x0p_lr_tlv),
15659 + SOC_SINGLE_RANGE_TLV("C.R Vol Volume",
15660 + ma_vol_db_ch1__a, 0, 0x18, 0x4a, 1, ma120x0p_lr_tlv),
15661 +
15662 + //L-R Limiter Threshold ch0-ch1
15663 + SOC_DOUBLE_R_RANGE_TLV("D.Lim thresh Volume",
15664 + ma_thr_db_ch0__a, ma_thr_db_ch1__a, 0, 0x0e, 0x4a, 1,
15665 + ma120x0p_lim_tlv),
15666 +
15667 + //Enum Switches/Selectors
15668 + //SOC_ENUM("E.AudioProc Mute", audioproc_mute_ctrl),
15669 + SOC_ENUM("F.Limiter Enable", lim_enable_ctrl),
15670 + SOC_ENUM("G.Limiter Attck", limatack_ctrl),
15671 + SOC_ENUM("H.Limiter Rls", limrelease_ctrl),
15672 +
15673 + //Enum Error Monitor (read-only)
15674 + SOC_ENUM_ERR("I.Err flycap", err_flycap_ctrl),
15675 + SOC_ENUM_ERR("J.Err overcurr", err_overcurr_ctrl),
15676 + SOC_ENUM_ERR("K.Err pllerr", err_pllerr_ctrl),
15677 + SOC_ENUM_ERR("L.Err pvddunder", err_pvddunder_ctrl),
15678 + SOC_ENUM_ERR("M.Err overtempw", err_overtempw_ctrl),
15679 + SOC_ENUM_ERR("N.Err overtempe", err_overtempe_ctrl),
15680 + SOC_ENUM_ERR("O.Err pinlowimp", err_pinlowimp_ctrl),
15681 + SOC_ENUM_ERR("P.Err dcprot", err_dcprot_ctrl),
15682 +
15683 + //Power modes profiles
15684 + SOC_ENUM("Q.PM Prof", pwr_mode_prof_ctrl),
15685 +
15686 + // Power mode selection (Dynamic,1,2,3)
15687 + SOC_ENUM("R.Power Mode", pwr_mode_ctrl),
15688 +};
15689 +
15690 +//Machine Driver
15691 +static int ma120x0p_hw_params(struct snd_pcm_substream *substream,
15692 + struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
15693 +{
15694 + u16 blen = 0x00;
15695 +
15696 + struct snd_soc_component *component = dai->component;
15697 +
15698 + priv_data->component = component;
15699 +
15700 + switch (params_format(params)) {
15701 + case SNDRV_PCM_FORMAT_S16_LE:
15702 + blen = 0x10;
15703 + break;
15704 + case SNDRV_PCM_FORMAT_S24_LE:
15705 + blen = 0x00;
15706 + break;
15707 + case SNDRV_PCM_FORMAT_S32_LE:
15708 + blen = 0x00;
15709 + break;
15710 + default:
15711 + dev_err(dai->dev, "Unsupported word length: %u\n",
15712 + params_format(params));
15713 + return -EINVAL;
15714 + }
15715 +
15716 + // set word length
15717 + snd_soc_component_update_bits(component, ma_i2s_framesize__a,
15718 + ma_i2s_framesize__mask, blen);
15719 +
15720 + return 0;
15721 +}
15722 +
15723 +static int ma120x0p_mute_stream(struct snd_soc_dai *dai, int mute, int stream)
15724 +{
15725 + int val = 0;
15726 +
15727 + struct ma120x0p_priv *ma120x0p;
15728 +
15729 + struct snd_soc_component *component = dai->component;
15730 +
15731 + ma120x0p = snd_soc_component_get_drvdata(component);
15732 +
15733 + if (mute)
15734 + val = 0;
15735 + else
15736 + val = 1;
15737 +
15738 + gpiod_set_value_cansleep(priv_data->mute_gpio, val);
15739 +
15740 + return 0;
15741 +}
15742 +
15743 +static const struct snd_soc_dai_ops ma120x0p_dai_ops = {
15744 + .hw_params = ma120x0p_hw_params,
15745 + .mute_stream = ma120x0p_mute_stream,
15746 +};
15747 +
15748 +static struct snd_soc_dai_driver ma120x0p_dai = {
15749 + .name = "ma120x0p-amp",
15750 + .playback = {
15751 + .stream_name = "Playback",
15752 + .channels_min = 2,
15753 + .channels_max = 2,
15754 + .rates = SNDRV_PCM_RATE_CONTINUOUS,
15755 + .rate_min = 44100,
15756 + .rate_max = 96000,
15757 + .formats = SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE
15758 + },
15759 + .ops = &ma120x0p_dai_ops,
15760 +};
15761 +
15762 +//Codec Driver
15763 +static int ma120x0p_clear_err(struct snd_soc_component *component)
15764 +{
15765 + int ret = 0;
15766 +
15767 + struct ma120x0p_priv *ma120x0p;
15768 +
15769 + ma120x0p = snd_soc_component_get_drvdata(component);
15770 +
15771 + ret = snd_soc_component_update_bits(component,
15772 + ma_eh_clear__a, ma_eh_clear__mask, 0x00);
15773 + if (ret < 0)
15774 + return ret;
15775 +
15776 + ret = snd_soc_component_update_bits(component,
15777 + ma_eh_clear__a, ma_eh_clear__mask, 0x04);
15778 + if (ret < 0)
15779 + return ret;
15780 +
15781 + ret = snd_soc_component_update_bits(component,
15782 + ma_eh_clear__a, ma_eh_clear__mask, 0x00);
15783 + if (ret < 0)
15784 + return ret;
15785 +
15786 + return 0;
15787 +}
15788 +
15789 +static void ma120x0p_remove(struct snd_soc_component *component)
15790 +{
15791 + struct ma120x0p_priv *ma120x0p;
15792 +
15793 + ma120x0p = snd_soc_component_get_drvdata(component);
15794 +}
15795 +
15796 +static int ma120x0p_probe(struct snd_soc_component *component)
15797 +{
15798 + struct ma120x0p_priv *ma120x0p;
15799 +
15800 + int ret = 0;
15801 +
15802 + i2c = container_of(component->dev, struct i2c_client, dev);
15803 +
15804 + ma120x0p = snd_soc_component_get_drvdata(component);
15805 +
15806 + //Reset error
15807 + ma120x0p_clear_err(component);
15808 + if (ret < 0)
15809 + return ret;
15810 +
15811 + // set serial audio format I2S and enable audio processor
15812 + ret = snd_soc_component_write(component, ma_i2s_format__a, 0x08);
15813 + if (ret < 0)
15814 + return ret;
15815 +
15816 + // Enable audio limiter
15817 + ret = snd_soc_component_update_bits(component,
15818 + ma_audio_proc_limiterenable__a,
15819 + ma_audio_proc_limiterenable__mask, 0x40);
15820 + if (ret < 0)
15821 + return ret;
15822 +
15823 + // Set lim attack to fast
15824 + ret = snd_soc_component_update_bits(component,
15825 + ma_audio_proc_attack__a, ma_audio_proc_attack__mask, 0x80);
15826 + if (ret < 0)
15827 + return ret;
15828 +
15829 + // Set lim attack to low
15830 + ret = snd_soc_component_update_bits(component,
15831 + ma_audio_proc_release__a, ma_audio_proc_release__mask, 0x00);
15832 + if (ret < 0)
15833 + return ret;
15834 +
15835 + // set volume to 0dB
15836 + ret = snd_soc_component_write(component, ma_vol_db_master__a, 0x18);
15837 + if (ret < 0)
15838 + return ret;
15839 +
15840 + // set ch0 lim thresh to -15dB
15841 + ret = snd_soc_component_write(component, ma_thr_db_ch0__a, 0x27);
15842 + if (ret < 0)
15843 + return ret;
15844 +
15845 + // set ch1 lim thresh to -15dB
15846 + ret = snd_soc_component_write(component, ma_thr_db_ch1__a, 0x27);
15847 + if (ret < 0)
15848 + return ret;
15849 +
15850 + //Check for errors
15851 + ret = snd_soc_component_test_bits(component, ma_error_acc__a, 0x00, 0);
15852 + if (ret < 0)
15853 + return ret;
15854 + ret = snd_soc_component_test_bits(component, ma_error_acc__a, 0x01, 0);
15855 + if (ret < 0)
15856 + return ret;
15857 + ret = snd_soc_component_test_bits(component, ma_error_acc__a, 0x02, 0);
15858 + if (ret < 0)
15859 + return ret;
15860 + ret = snd_soc_component_test_bits(component, ma_error_acc__a, 0x08, 0);
15861 + if (ret < 0)
15862 + return ret;
15863 + ret = snd_soc_component_test_bits(component, ma_error_acc__a, 0x10, 0);
15864 + if (ret < 0)
15865 + return ret;
15866 + ret = snd_soc_component_test_bits(component, ma_error_acc__a, 0x20, 0);
15867 + if (ret < 0)
15868 + return ret;
15869 + ret = snd_soc_component_test_bits(component, ma_error_acc__a, 0x40, 0);
15870 + if (ret < 0)
15871 + return ret;
15872 + ret = snd_soc_component_test_bits(component, ma_error_acc__a, 0x80, 0);
15873 + if (ret < 0)
15874 + return ret;
15875 +
15876 + return 0;
15877 +}
15878 +
15879 +static int ma120x0p_set_bias_level(struct snd_soc_component *component,
15880 + enum snd_soc_bias_level level)
15881 +{
15882 + int ret = 0;
15883 +
15884 + struct ma120x0p_priv *ma120x0p;
15885 +
15886 + ma120x0p = snd_soc_component_get_drvdata(component);
15887 +
15888 + switch (level) {
15889 + case SND_SOC_BIAS_ON:
15890 + break;
15891 +
15892 + case SND_SOC_BIAS_PREPARE:
15893 + break;
15894 +
15895 + case SND_SOC_BIAS_STANDBY:
15896 + ret = gpiod_get_value_cansleep(priv_data->enable_gpio);
15897 + if (ret != 0) {
15898 + dev_err(component->dev, "Device ma120x0p disabled in STANDBY BIAS: %d\n",
15899 + ret);
15900 + return ret;
15901 + }
15902 + break;
15903 +
15904 + case SND_SOC_BIAS_OFF:
15905 + break;
15906 + }
15907 +
15908 + return 0;
15909 +}
15910 +
15911 +static const struct snd_soc_dapm_widget ma120x0p_dapm_widgets[] = {
15912 + SND_SOC_DAPM_OUTPUT("OUT_A"),
15913 + SND_SOC_DAPM_OUTPUT("OUT_B"),
15914 +};
15915 +
15916 +static const struct snd_soc_dapm_route ma120x0p_dapm_routes[] = {
15917 + { "OUT_B", NULL, "Playback" },
15918 + { "OUT_A", NULL, "Playback" },
15919 +};
15920 +
15921 +static const struct snd_soc_component_driver ma120x0p_component_driver = {
15922 + .probe = ma120x0p_probe,
15923 + .remove = ma120x0p_remove,
15924 + .set_bias_level = ma120x0p_set_bias_level,
15925 + .dapm_widgets = ma120x0p_dapm_widgets,
15926 + .num_dapm_widgets = ARRAY_SIZE(ma120x0p_dapm_widgets),
15927 + .dapm_routes = ma120x0p_dapm_routes,
15928 + .num_dapm_routes = ARRAY_SIZE(ma120x0p_dapm_routes),
15929 + .controls = ma120x0p_snd_controls,
15930 + .num_controls = ARRAY_SIZE(ma120x0p_snd_controls),
15931 + .use_pmdown_time = 1,
15932 + .endianness = 1,
15933 + .non_legacy_dai_naming = 1,
15934 +};
15935 +
15936 +//I2C Driver
15937 +static const struct reg_default ma120x0p_reg_defaults[] = {
15938 + { 0x01, 0x3c },
15939 +};
15940 +
15941 +static bool ma120x0p_reg_volatile(struct device *dev, unsigned int reg)
15942 +{
15943 + switch (reg) {
15944 + case ma_error__a:
15945 + return true;
15946 + default:
15947 + return false;
15948 + }
15949 +}
15950 +
15951 +static const struct of_device_id ma120x0p_of_match[] = {
15952 + { .compatible = "ma,ma120x0p", },
15953 + { }
15954 +};
15955 +
15956 +MODULE_DEVICE_TABLE(of, ma120x0p_of_match);
15957 +
15958 +static struct regmap_config ma120x0p_regmap_config = {
15959 + .reg_bits = 8,
15960 + .val_bits = 8,
15961 +
15962 + .max_register = 255,
15963 + .volatile_reg = ma120x0p_reg_volatile,
15964 +
15965 + .cache_type = REGCACHE_RBTREE,
15966 + .reg_defaults = ma120x0p_reg_defaults,
15967 + .num_reg_defaults = ARRAY_SIZE(ma120x0p_reg_defaults),
15968 +};
15969 +
15970 +static int ma120x0p_i2c_probe(struct i2c_client *i2c,
15971 + const struct i2c_device_id *id)
15972 +{
15973 + int ret;
15974 +
15975 + priv_data = devm_kzalloc(&i2c->dev, sizeof(*priv_data), GFP_KERNEL);
15976 + if (!priv_data)
15977 + return -ENOMEM;
15978 + i2c_set_clientdata(i2c, priv_data);
15979 +
15980 + priv_data->regmap = devm_regmap_init_i2c(i2c, &ma120x0p_regmap_config);
15981 + if (IS_ERR(priv_data->regmap)) {
15982 + ret = PTR_ERR(priv_data->regmap);
15983 + return ret;
15984 + }
15985 +
15986 + //Startup sequence
15987 +
15988 + //Make sure the device is muted
15989 + priv_data->mute_gpio = devm_gpiod_get_optional(&i2c->dev, "mute_gp",
15990 + GPIOD_OUT_LOW);
15991 + if (IS_ERR(priv_data->mute_gpio)) {
15992 + ret = PTR_ERR(priv_data->mute_gpio);
15993 + dev_err(&i2c->dev, "Failed to get mute gpio line: %d\n", ret);
15994 + return ret;
15995 + }
15996 + msleep(50);
15997 +
15998 +// MA120xx0P devices are usually powered by an integrated boost converter.
15999 +// An option GPIO control line is provided to enable the booster properly and
16000 +// in sync with the enable and mute GPIO lines.
16001 + priv_data->booster_gpio = devm_gpiod_get_optional(&i2c->dev,
16002 + "booster_gp", GPIOD_OUT_LOW);
16003 + if (IS_ERR(priv_data->booster_gpio)) {
16004 + ret = PTR_ERR(priv_data->booster_gpio);
16005 + dev_err(&i2c->dev,
16006 + "Failed to get booster enable gpio line: %d\n", ret);
16007 + return ret;
16008 + }
16009 + msleep(50);
16010 +
16011 + //Enable booster and wait 200ms until stable PVDD
16012 + gpiod_set_value_cansleep(priv_data->booster_gpio, 1);
16013 + msleep(200);
16014 +
16015 + //Enable ma120x0pp
16016 + priv_data->enable_gpio = devm_gpiod_get_optional(&i2c->dev,
16017 + "enable_gp", GPIOD_OUT_LOW);
16018 + if (IS_ERR(priv_data->enable_gpio)) {
16019 + ret = PTR_ERR(priv_data->enable_gpio);
16020 + dev_err(&i2c->dev,
16021 + "Failed to get ma120x0p enable gpio line: %d\n", ret);
16022 + return ret;
16023 + }
16024 + msleep(50);
16025 +
16026 + //Optional use of ma120x0pp error line as an interrupt trigger to
16027 + //platform GPIO.
16028 + //Get error input gpio ma120x0p
16029 + priv_data->error_gpio = devm_gpiod_get_optional(&i2c->dev,
16030 + "error_gp", GPIOD_IN);
16031 + if (IS_ERR(priv_data->error_gpio)) {
16032 + ret = PTR_ERR(priv_data->error_gpio);
16033 + dev_err(&i2c->dev,
16034 + "Failed to get ma120x0p error gpio line: %d\n", ret);
16035 + return ret;
16036 + }
16037 +
16038 + if (priv_data->error_gpio != NULL) {
16039 + irqNumber = gpiod_to_irq(priv_data->error_gpio);
16040 +
16041 + ret = devm_request_threaded_irq(&i2c->dev,
16042 + irqNumber, ma120x0p_irq_handler,
16043 + NULL, IRQF_TRIGGER_FALLING,
16044 + "ma120x0p", priv_data);
16045 + if (ret != 0)
16046 + dev_warn(&i2c->dev, "Failed to request IRQ: %d\n",
16047 + ret);
16048 + }
16049 +
16050 + ret = devm_snd_soc_register_component(&i2c->dev,
16051 + &ma120x0p_component_driver, &ma120x0p_dai, 1);
16052 +
16053 + return ret;
16054 +}
16055 +
16056 +static irqreturn_t ma120x0p_irq_handler(int irq, void *data)
16057 +{
16058 + gpiod_set_value_cansleep(priv_data->mute_gpio, 0);
16059 + gpiod_set_value_cansleep(priv_data->enable_gpio, 1);
16060 + return IRQ_HANDLED;
16061 +}
16062 +
16063 +static int ma120x0p_i2c_remove(struct i2c_client *i2c)
16064 +{
16065 + snd_soc_unregister_component(&i2c->dev);
16066 + i2c_set_clientdata(i2c, NULL);
16067 +
16068 + gpiod_set_value_cansleep(priv_data->mute_gpio, 0);
16069 + msleep(30);
16070 + gpiod_set_value_cansleep(priv_data->enable_gpio, 1);
16071 + msleep(200);
16072 + gpiod_set_value_cansleep(priv_data->booster_gpio, 0);
16073 + msleep(200);
16074 +
16075 + kfree(priv_data);
16076 +
16077 + return 0;
16078 +}
16079 +
16080 +static void ma120x0p_i2c_shutdown(struct i2c_client *i2c)
16081 +{
16082 + snd_soc_unregister_component(&i2c->dev);
16083 + i2c_set_clientdata(i2c, NULL);
16084 +
16085 + gpiod_set_value_cansleep(priv_data->mute_gpio, 0);
16086 + msleep(30);
16087 + gpiod_set_value_cansleep(priv_data->enable_gpio, 1);
16088 + msleep(200);
16089 + gpiod_set_value_cansleep(priv_data->booster_gpio, 0);
16090 + msleep(200);
16091 +
16092 + kfree(priv_data);
16093 +}
16094 +
16095 +static const struct i2c_device_id ma120x0p_i2c_id[] = {
16096 + { "ma120x0p", 0 },
16097 + { }
16098 +};
16099 +
16100 +MODULE_DEVICE_TABLE(i2c, ma120x0p_i2c_id);
16101 +
16102 +static struct i2c_driver ma120x0p_i2c_driver = {
16103 + .driver = {
16104 + .name = "ma120x0p",
16105 + .owner = THIS_MODULE,
16106 + .of_match_table = ma120x0p_of_match,
16107 + },
16108 + .probe = ma120x0p_i2c_probe,
16109 + .remove = ma120x0p_i2c_remove,
16110 + .shutdown = ma120x0p_i2c_shutdown,
16111 + .id_table = ma120x0p_i2c_id
16112 +};
16113 +
16114 +static int __init ma120x0p_modinit(void)
16115 +{
16116 + int ret = 0;
16117 +
16118 + ret = i2c_add_driver(&ma120x0p_i2c_driver);
16119 + if (ret != 0) {
16120 + pr_err("Failed to register MA120X0P I2C driver: %d\n", ret);
16121 + return ret;
16122 + }
16123 + return ret;
16124 +}
16125 +module_init(ma120x0p_modinit);
16126 +
16127 +static void __exit ma120x0p_exit(void)
16128 +{
16129 + i2c_del_driver(&ma120x0p_i2c_driver);
16130 +}
16131 +module_exit(ma120x0p_exit);
16132 +
16133 +MODULE_AUTHOR("Ariel Muszkat ariel.muszkat@gmail.com>");
16134 +MODULE_DESCRIPTION("ASoC driver for ma120x0p");
16135 +MODULE_LICENSE("GPL v2");
16136 --- /dev/null
16137 +++ b/sound/soc/codecs/pcm1794a.c
16138 @@ -0,0 +1,69 @@
16139 +/*
16140 + * Driver for the PCM1794A codec
16141 + *
16142 + * Author: Florian Meier <florian.meier@koalo.de>
16143 + * Copyright 2013
16144 + *
16145 + * This program is free software; you can redistribute it and/or
16146 + * modify it under the terms of the GNU General Public License
16147 + * version 2 as published by the Free Software Foundation.
16148 + *
16149 + * This program is distributed in the hope that it will be useful, but
16150 + * WITHOUT ANY WARRANTY; without even the implied warranty of
16151 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16152 + * General Public License for more details.
16153 + */
16154 +
16155 +
16156 +#include <linux/init.h>
16157 +#include <linux/module.h>
16158 +#include <linux/platform_device.h>
16159 +
16160 +#include <sound/soc.h>
16161 +
16162 +static struct snd_soc_dai_driver pcm1794a_dai = {
16163 + .name = "pcm1794a-hifi",
16164 + .playback = {
16165 + .channels_min = 2,
16166 + .channels_max = 2,
16167 + .rates = SNDRV_PCM_RATE_8000_192000,
16168 + .formats = SNDRV_PCM_FMTBIT_S16_LE |
16169 + SNDRV_PCM_FMTBIT_S24_LE
16170 + },
16171 +};
16172 +
16173 +static struct snd_soc_component_driver soc_component_dev_pcm1794a;
16174 +
16175 +static int pcm1794a_probe(struct platform_device *pdev)
16176 +{
16177 + return snd_soc_register_component(&pdev->dev, &soc_component_dev_pcm1794a,
16178 + &pcm1794a_dai, 1);
16179 +}
16180 +
16181 +static int pcm1794a_remove(struct platform_device *pdev)
16182 +{
16183 + snd_soc_unregister_component(&pdev->dev);
16184 + return 0;
16185 +}
16186 +
16187 +static const struct of_device_id pcm1794a_of_match[] = {
16188 + { .compatible = "ti,pcm1794a", },
16189 + { }
16190 +};
16191 +MODULE_DEVICE_TABLE(of, pcm1794a_of_match);
16192 +
16193 +static struct platform_driver pcm1794a_component_driver = {
16194 + .probe = pcm1794a_probe,
16195 + .remove = pcm1794a_remove,
16196 + .driver = {
16197 + .name = "pcm1794a-codec",
16198 + .owner = THIS_MODULE,
16199 + .of_match_table = of_match_ptr(pcm1794a_of_match),
16200 + },
16201 +};
16202 +
16203 +module_platform_driver(pcm1794a_component_driver);
16204 +
16205 +MODULE_DESCRIPTION("ASoC PCM1794A codec driver");
16206 +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
16207 +MODULE_LICENSE("GPL v2");
16208 --- a/sound/soc/codecs/pcm512x.c
16209 +++ b/sound/soc/codecs/pcm512x.c
16210 @@ -536,7 +536,7 @@ static unsigned long pcm512x_ncp_target(
16211
16212 static const u32 pcm512x_dai_rates[] = {
16213 8000, 11025, 16000, 22050, 32000, 44100, 48000, 64000,
16214 - 88200, 96000, 176400, 192000, 384000,
16215 + 88200, 96000, 176400, 192000, 352800, 384000,
16216 };
16217
16218 static const struct snd_pcm_hw_constraint_list constraints_slave = {
16219 --- /dev/null
16220 +++ b/sound/soc/codecs/tas5713.c
16221 @@ -0,0 +1,363 @@
16222 +/*
16223 + * ASoC Driver for TAS5713
16224 + *
16225 + * Author: Sebastian Eickhoff <basti.eickhoff@googlemail.com>
16226 + * Copyright 2014
16227 + *
16228 + * This program is free software; you can redistribute it and/or
16229 + * modify it under the terms of the GNU General Public License
16230 + * version 2 as published by the Free Software Foundation.
16231 + *
16232 + * This program is distributed in the hope that it will be useful, but
16233 + * WITHOUT ANY WARRANTY; without even the implied warranty of
16234 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16235 + * General Public License for more details.
16236 + */
16237 +
16238 +#include <linux/module.h>
16239 +#include <linux/moduleparam.h>
16240 +#include <linux/init.h>
16241 +#include <linux/delay.h>
16242 +#include <linux/pm.h>
16243 +#include <linux/i2c.h>
16244 +#include <linux/of_device.h>
16245 +#include <linux/spi/spi.h>
16246 +#include <linux/regmap.h>
16247 +#include <linux/regulator/consumer.h>
16248 +#include <linux/slab.h>
16249 +#include <sound/core.h>
16250 +#include <sound/pcm.h>
16251 +#include <sound/pcm_params.h>
16252 +#include <sound/soc.h>
16253 +#include <sound/initval.h>
16254 +#include <sound/tlv.h>
16255 +
16256 +#include <linux/kernel.h>
16257 +#include <linux/string.h>
16258 +#include <linux/fs.h>
16259 +#include <asm/uaccess.h>
16260 +
16261 +#include "tas5713.h"
16262 +
16263 +
16264 +static struct i2c_client *i2c;
16265 +
16266 +struct tas5713_priv {
16267 + struct regmap *regmap;
16268 + int mclk_div;
16269 + struct snd_soc_component *component;
16270 +};
16271 +
16272 +static struct tas5713_priv *priv_data;
16273 +
16274 +
16275 +
16276 +
16277 +/*
16278 + * _ _ ___ _ ___ _ _
16279 + * /_\ | | / __| /_\ / __|___ _ _| |_ _ _ ___| |___
16280 + * / _ \| |__\__ \/ _ \ | (__/ _ \ ' \ _| '_/ _ \ (_-<
16281 + * /_/ \_\____|___/_/ \_\ \___\___/_||_\__|_| \___/_/__/
16282 + *
16283 + */
16284 +
16285 +static const DECLARE_TLV_DB_SCALE(tas5713_vol_tlv, -10000, 50, 1);
16286 +
16287 +
16288 +static const struct snd_kcontrol_new tas5713_snd_controls[] = {
16289 + SOC_SINGLE_TLV ("Master" , TAS5713_VOL_MASTER, 0, 248, 1, tas5713_vol_tlv),
16290 + SOC_DOUBLE_R_TLV("Channels" , TAS5713_VOL_CH1, TAS5713_VOL_CH2, 0, 248, 1, tas5713_vol_tlv)
16291 +};
16292 +
16293 +
16294 +
16295 +
16296 +/*
16297 + * __ __ _ _ ___ _
16298 + * | \/ |__ _ __| |_ (_)_ _ ___ | \ _ _(_)_ _____ _ _
16299 + * | |\/| / _` / _| ' \| | ' \/ -_) | |) | '_| \ V / -_) '_|
16300 + * |_| |_\__,_\__|_||_|_|_||_\___| |___/|_| |_|\_/\___|_|
16301 + *
16302 + */
16303 +
16304 +static int tas5713_hw_params(struct snd_pcm_substream *substream,
16305 + struct snd_pcm_hw_params *params,
16306 + struct snd_soc_dai *dai)
16307 +{
16308 + u16 blen = 0x00;
16309 +
16310 + struct snd_soc_component *component = dai->component;
16311 + priv_data->component = component;
16312 +
16313 + switch (params_format(params)) {
16314 + case SNDRV_PCM_FORMAT_S16_LE:
16315 + blen = 0x03;
16316 + break;
16317 + case SNDRV_PCM_FORMAT_S20_3LE:
16318 + blen = 0x1;
16319 + break;
16320 + case SNDRV_PCM_FORMAT_S24_LE:
16321 + blen = 0x04;
16322 + break;
16323 + case SNDRV_PCM_FORMAT_S32_LE:
16324 + blen = 0x05;
16325 + break;
16326 + default:
16327 + dev_err(dai->dev, "Unsupported word length: %u\n",
16328 + params_format(params));
16329 + return -EINVAL;
16330 + }
16331 +
16332 + // set word length
16333 + snd_soc_component_update_bits(component, TAS5713_SERIAL_DATA_INTERFACE, 0x7, blen);
16334 +
16335 + return 0;
16336 +}
16337 +
16338 +
16339 +static int tas5713_mute_stream(struct snd_soc_dai *dai, int mute, int stream)
16340 +{
16341 + unsigned int val = 0;
16342 +
16343 + struct tas5713_priv *tas5713;
16344 + struct snd_soc_component *component = dai->component;
16345 + tas5713 = snd_soc_component_get_drvdata(component);
16346 +
16347 + if (mute) {
16348 + val = TAS5713_SOFT_MUTE_ALL;
16349 + }
16350 +
16351 + return regmap_write(tas5713->regmap, TAS5713_SOFT_MUTE, val);
16352 +}
16353 +
16354 +
16355 +static const struct snd_soc_dai_ops tas5713_dai_ops = {
16356 + .hw_params = tas5713_hw_params,
16357 + .mute_stream = tas5713_mute_stream,
16358 +};
16359 +
16360 +
16361 +static struct snd_soc_dai_driver tas5713_dai = {
16362 + .name = "tas5713-hifi",
16363 + .playback = {
16364 + .stream_name = "Playback",
16365 + .channels_min = 2,
16366 + .channels_max = 2,
16367 + .rates = SNDRV_PCM_RATE_8000_48000,
16368 + .formats = (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE ),
16369 + },
16370 + .ops = &tas5713_dai_ops,
16371 +};
16372 +
16373 +
16374 +
16375 +
16376 +/*
16377 + * ___ _ ___ _
16378 + * / __|___ __| |___ __ | \ _ _(_)_ _____ _ _
16379 + * | (__/ _ \/ _` / -_) _| | |) | '_| \ V / -_) '_|
16380 + * \___\___/\__,_\___\__| |___/|_| |_|\_/\___|_|
16381 + *
16382 + */
16383 +
16384 +static void tas5713_remove(struct snd_soc_component *component)
16385 +{
16386 + struct tas5713_priv *tas5713;
16387 +
16388 + tas5713 = snd_soc_component_get_drvdata(component);
16389 +}
16390 +
16391 +
16392 +static int tas5713_probe(struct snd_soc_component *component)
16393 +{
16394 + struct tas5713_priv *tas5713;
16395 + int i, ret;
16396 +
16397 + i2c = container_of(component->dev, struct i2c_client, dev);
16398 +
16399 + tas5713 = snd_soc_component_get_drvdata(component);
16400 +
16401 + // Reset error
16402 + ret = snd_soc_component_write(component, TAS5713_ERROR_STATUS, 0x00);
16403 + if (ret < 0) return ret;
16404 +
16405 + // Trim oscillator
16406 + ret = snd_soc_component_write(component, TAS5713_OSC_TRIM, 0x00);
16407 + if (ret < 0) return ret;
16408 + msleep(1000);
16409 +
16410 + // Reset error
16411 + ret = snd_soc_component_write(component, TAS5713_ERROR_STATUS, 0x00);
16412 + if (ret < 0) return ret;
16413 +
16414 + // I2S 24bit
16415 + ret = snd_soc_component_write(component, TAS5713_SERIAL_DATA_INTERFACE, 0x05);
16416 + if (ret < 0) return ret;
16417 +
16418 + // Unmute
16419 + ret = snd_soc_component_write(component, TAS5713_SYSTEM_CTRL2, 0x00);
16420 + if (ret < 0) return ret;
16421 + ret = snd_soc_component_write(component, TAS5713_SOFT_MUTE, 0x00);
16422 + if (ret < 0) return ret;
16423 +
16424 + // Set volume to 0db
16425 + ret = snd_soc_component_write(component, TAS5713_VOL_MASTER, 0x00);
16426 + if (ret < 0) return ret;
16427 +
16428 + // Now start programming the default initialization sequence
16429 + for (i = 0; i < ARRAY_SIZE(tas5713_init_sequence); ++i) {
16430 + ret = i2c_master_send(i2c,
16431 + tas5713_init_sequence[i].data,
16432 + tas5713_init_sequence[i].size);
16433 + if (ret < 0) {
16434 + printk(KERN_INFO "TAS5713 CODEC PROBE: InitSeq returns: %d\n", ret);
16435 + }
16436 + }
16437 +
16438 + // Unmute
16439 + ret = snd_soc_component_write(component, TAS5713_SYSTEM_CTRL2, 0x00);
16440 + if (ret < 0) return ret;
16441 +
16442 + return 0;
16443 +}
16444 +
16445 +
16446 +static struct snd_soc_component_driver soc_codec_dev_tas5713 = {
16447 + .probe = tas5713_probe,
16448 + .remove = tas5713_remove,
16449 + .controls = tas5713_snd_controls,
16450 + .num_controls = ARRAY_SIZE(tas5713_snd_controls),
16451 +};
16452 +
16453 +
16454 +
16455 +
16456 +/*
16457 + * ___ ___ ___ ___ _
16458 + * |_ _|_ ) __| | \ _ _(_)_ _____ _ _
16459 + * | | / / (__ | |) | '_| \ V / -_) '_|
16460 + * |___/___\___| |___/|_| |_|\_/\___|_|
16461 + *
16462 + */
16463 +
16464 +static const struct reg_default tas5713_reg_defaults[] = {
16465 + { 0x07 ,0x80 }, // R7 - VOL_MASTER - -40dB
16466 + { 0x08 , 30 }, // R8 - VOL_CH1 - 0dB
16467 + { 0x09 , 30 }, // R9 - VOL_CH2 - 0dB
16468 + { 0x0A ,0x80 }, // R10 - VOL_HEADPHONE - -40dB
16469 +};
16470 +
16471 +
16472 +static bool tas5713_reg_volatile(struct device *dev, unsigned int reg)
16473 +{
16474 + switch (reg) {
16475 + case TAS5713_DEVICE_ID:
16476 + case TAS5713_ERROR_STATUS:
16477 + case TAS5713_CLOCK_CTRL:
16478 + return true;
16479 + default:
16480 + return false;
16481 + }
16482 +}
16483 +
16484 +
16485 +static const struct of_device_id tas5713_of_match[] = {
16486 + { .compatible = "ti,tas5713", },
16487 + { }
16488 +};
16489 +MODULE_DEVICE_TABLE(of, tas5713_of_match);
16490 +
16491 +
16492 +static struct regmap_config tas5713_regmap_config = {
16493 + .reg_bits = 8,
16494 + .val_bits = 8,
16495 +
16496 + .max_register = TAS5713_MAX_REGISTER,
16497 + .volatile_reg = tas5713_reg_volatile,
16498 +
16499 + .cache_type = REGCACHE_RBTREE,
16500 + .reg_defaults = tas5713_reg_defaults,
16501 + .num_reg_defaults = ARRAY_SIZE(tas5713_reg_defaults),
16502 +};
16503 +
16504 +
16505 +static int tas5713_i2c_probe(struct i2c_client *i2c,
16506 + const struct i2c_device_id *id)
16507 +{
16508 + int ret;
16509 +
16510 + priv_data = devm_kzalloc(&i2c->dev, sizeof *priv_data, GFP_KERNEL);
16511 + if (!priv_data)
16512 + return -ENOMEM;
16513 +
16514 + priv_data->regmap = devm_regmap_init_i2c(i2c, &tas5713_regmap_config);
16515 + if (IS_ERR(priv_data->regmap)) {
16516 + ret = PTR_ERR(priv_data->regmap);
16517 + return ret;
16518 + }
16519 +
16520 + i2c_set_clientdata(i2c, priv_data);
16521 +
16522 + ret = snd_soc_register_component(&i2c->dev,
16523 + &soc_codec_dev_tas5713, &tas5713_dai, 1);
16524 +
16525 + return ret;
16526 +}
16527 +
16528 +
16529 +static int tas5713_i2c_remove(struct i2c_client *i2c)
16530 +{
16531 + snd_soc_unregister_component(&i2c->dev);
16532 + i2c_set_clientdata(i2c, NULL);
16533 +
16534 + kfree(priv_data);
16535 +
16536 + return 0;
16537 +}
16538 +
16539 +
16540 +static const struct i2c_device_id tas5713_i2c_id[] = {
16541 + { "tas5713", 0 },
16542 + { }
16543 +};
16544 +
16545 +MODULE_DEVICE_TABLE(i2c, tas5713_i2c_id);
16546 +
16547 +
16548 +static struct i2c_driver tas5713_i2c_driver = {
16549 + .driver = {
16550 + .name = "tas5713",
16551 + .owner = THIS_MODULE,
16552 + .of_match_table = tas5713_of_match,
16553 + },
16554 + .probe = tas5713_i2c_probe,
16555 + .remove = tas5713_i2c_remove,
16556 + .id_table = tas5713_i2c_id
16557 +};
16558 +
16559 +
16560 +static int __init tas5713_modinit(void)
16561 +{
16562 + int ret = 0;
16563 +
16564 + ret = i2c_add_driver(&tas5713_i2c_driver);
16565 + if (ret) {
16566 + printk(KERN_ERR "Failed to register tas5713 I2C driver: %d\n",
16567 + ret);
16568 + }
16569 +
16570 + return ret;
16571 +}
16572 +module_init(tas5713_modinit);
16573 +
16574 +
16575 +static void __exit tas5713_exit(void)
16576 +{
16577 + i2c_del_driver(&tas5713_i2c_driver);
16578 +}
16579 +module_exit(tas5713_exit);
16580 +
16581 +
16582 +MODULE_AUTHOR("Sebastian Eickhoff <basti.eickhoff@googlemail.com>");
16583 +MODULE_DESCRIPTION("ASoC driver for TAS5713");
16584 +MODULE_LICENSE("GPL v2");
16585 --- /dev/null
16586 +++ b/sound/soc/codecs/tas5713.h
16587 @@ -0,0 +1,210 @@
16588 +/*
16589 + * ASoC Driver for TAS5713
16590 + *
16591 + * Author: Sebastian Eickhoff <basti.eickhoff@googlemail.com>
16592 + * Copyright 2014
16593 + *
16594 + * This program is free software; you can redistribute it and/or
16595 + * modify it under the terms of the GNU General Public License
16596 + * version 2 as published by the Free Software Foundation.
16597 + *
16598 + * This program is distributed in the hope that it will be useful, but
16599 + * WITHOUT ANY WARRANTY; without even the implied warranty of
16600 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16601 + * General Public License for more details.
16602 + */
16603 +
16604 +#ifndef _TAS5713_H
16605 +#define _TAS5713_H
16606 +
16607 +
16608 +// TAS5713 I2C-bus register addresses
16609 +
16610 +#define TAS5713_CLOCK_CTRL 0x00
16611 +#define TAS5713_DEVICE_ID 0x01
16612 +#define TAS5713_ERROR_STATUS 0x02
16613 +#define TAS5713_SYSTEM_CTRL1 0x03
16614 +#define TAS5713_SERIAL_DATA_INTERFACE 0x04
16615 +#define TAS5713_SYSTEM_CTRL2 0x05
16616 +#define TAS5713_SOFT_MUTE 0x06
16617 +#define TAS5713_VOL_MASTER 0x07
16618 +#define TAS5713_VOL_CH1 0x08
16619 +#define TAS5713_VOL_CH2 0x09
16620 +#define TAS5713_VOL_HEADPHONE 0x0A
16621 +#define TAS5713_VOL_CONFIG 0x0E
16622 +#define TAS5713_MODULATION_LIMIT 0x10
16623 +#define TAS5713_IC_DLY_CH1 0x11
16624 +#define TAS5713_IC_DLY_CH2 0x12
16625 +#define TAS5713_IC_DLY_CH3 0x13
16626 +#define TAS5713_IC_DLY_CH4 0x14
16627 +
16628 +#define TAS5713_START_STOP_PERIOD 0x1A
16629 +#define TAS5713_OSC_TRIM 0x1B
16630 +#define TAS5713_BKND_ERR 0x1C
16631 +
16632 +#define TAS5713_INPUT_MUX 0x20
16633 +#define TAS5713_SRC_SELECT_CH4 0x21
16634 +#define TAS5713_PWM_MUX 0x25
16635 +
16636 +#define TAS5713_CH1_BQ0 0x29
16637 +#define TAS5713_CH1_BQ1 0x2A
16638 +#define TAS5713_CH1_BQ2 0x2B
16639 +#define TAS5713_CH1_BQ3 0x2C
16640 +#define TAS5713_CH1_BQ4 0x2D
16641 +#define TAS5713_CH1_BQ5 0x2E
16642 +#define TAS5713_CH1_BQ6 0x2F
16643 +#define TAS5713_CH1_BQ7 0x58
16644 +#define TAS5713_CH1_BQ8 0x59
16645 +
16646 +#define TAS5713_CH2_BQ0 0x30
16647 +#define TAS5713_CH2_BQ1 0x31
16648 +#define TAS5713_CH2_BQ2 0x32
16649 +#define TAS5713_CH2_BQ3 0x33
16650 +#define TAS5713_CH2_BQ4 0x34
16651 +#define TAS5713_CH2_BQ5 0x35
16652 +#define TAS5713_CH2_BQ6 0x36
16653 +#define TAS5713_CH2_BQ7 0x5C
16654 +#define TAS5713_CH2_BQ8 0x5D
16655 +
16656 +#define TAS5713_CH4_BQ0 0x5A
16657 +#define TAS5713_CH4_BQ1 0x5B
16658 +#define TAS5713_CH3_BQ0 0x5E
16659 +#define TAS5713_CH3_BQ1 0x5F
16660 +
16661 +#define TAS5713_DRC1_SOFTENING_FILTER_ALPHA_OMEGA 0x3B
16662 +#define TAS5713_DRC1_ATTACK_RELEASE_RATE 0x3C
16663 +#define TAS5713_DRC2_SOFTENING_FILTER_ALPHA_OMEGA 0x3E
16664 +#define TAS5713_DRC2_ATTACK_RELEASE_RATE 0x3F
16665 +#define TAS5713_DRC1_ATTACK_RELEASE_THRES 0x40
16666 +#define TAS5713_DRC2_ATTACK_RELEASE_THRES 0x43
16667 +#define TAS5713_DRC_CTRL 0x46
16668 +
16669 +#define TAS5713_BANK_SW_CTRL 0x50
16670 +#define TAS5713_CH1_OUTPUT_MIXER 0x51
16671 +#define TAS5713_CH2_OUTPUT_MIXER 0x52
16672 +#define TAS5713_CH1_INPUT_MIXER 0x53
16673 +#define TAS5713_CH2_INPUT_MIXER 0x54
16674 +#define TAS5713_OUTPUT_POST_SCALE 0x56
16675 +#define TAS5713_OUTPUT_PRESCALE 0x57
16676 +
16677 +#define TAS5713_IDF_POST_SCALE 0x62
16678 +
16679 +#define TAS5713_CH1_INLINE_MIXER 0x70
16680 +#define TAS5713_CH1_INLINE_DRC_EN_MIXER 0x71
16681 +#define TAS5713_CH1_R_CHANNEL_MIXER 0x72
16682 +#define TAS5713_CH1_L_CHANNEL_MIXER 0x73
16683 +#define TAS5713_CH2_INLINE_MIXER 0x74
16684 +#define TAS5713_CH2_INLINE_DRC_EN_MIXER 0x75
16685 +#define TAS5713_CH2_L_CHANNEL_MIXER 0x76
16686 +#define TAS5713_CH2_R_CHANNEL_MIXER 0x77
16687 +
16688 +#define TAS5713_UPDATE_DEV_ADDR_KEY 0xF8
16689 +#define TAS5713_UPDATE_DEV_ADDR_REG 0xF9
16690 +
16691 +#define TAS5713_REGISTER_COUNT 0x46
16692 +#define TAS5713_MAX_REGISTER 0xF9
16693 +
16694 +
16695 +// Bitmasks for registers
16696 +#define TAS5713_SOFT_MUTE_ALL 0x07
16697 +
16698 +
16699 +
16700 +struct tas5713_init_command {
16701 + const int size;
16702 + const char *const data;
16703 +};
16704 +
16705 +static const struct tas5713_init_command tas5713_init_sequence[] = {
16706 +
16707 + // Trim oscillator
16708 + { .size = 2, .data = "\x1B\x00" },
16709 + // System control register 1 (0x03): block DC
16710 + { .size = 2, .data = "\x03\x80" },
16711 + // Mute everything
16712 + { .size = 2, .data = "\x05\x40" },
16713 + // Modulation limit register (0x10): 97.7%
16714 + { .size = 2, .data = "\x10\x02" },
16715 + // Interchannel delay registers
16716 + // (0x11, 0x12, 0x13, and 0x14): BD mode
16717 + { .size = 2, .data = "\x11\xB8" },
16718 + { .size = 2, .data = "\x12\x60" },
16719 + { .size = 2, .data = "\x13\xA0" },
16720 + { .size = 2, .data = "\x14\x48" },
16721 + // PWM shutdown group register (0x19): no shutdown
16722 + { .size = 2, .data = "\x19\x00" },
16723 + // Input multiplexer register (0x20): BD mode
16724 + { .size = 2, .data = "\x20\x00\x89\x77\x72" },
16725 + // PWM output mux register (0x25)
16726 + // Channel 1 --> OUTA, channel 1 neg --> OUTB
16727 + // Channel 2 --> OUTC, channel 2 neg --> OUTD
16728 + { .size = 5, .data = "\x25\x01\x02\x13\x45" },
16729 + // DRC control (0x46): DRC off
16730 + { .size = 5, .data = "\x46\x00\x00\x00\x00" },
16731 + // BKND_ERR register (0x1C): 299ms reset period
16732 + { .size = 2, .data = "\x1C\x07" },
16733 + // Mute channel 3
16734 + { .size = 2, .data = "\x0A\xFF" },
16735 + // Volume configuration register (0x0E): volume slew 512 steps
16736 + { .size = 2, .data = "\x0E\x90" },
16737 + // Clock control register (0x00): 44/48kHz, MCLK=64xfs
16738 + { .size = 2, .data = "\x00\x60" },
16739 + // Bank switch and eq control (0x50): no bank switching
16740 + { .size = 5, .data = "\x50\x00\x00\x00\x00" },
16741 + // Volume registers (0x07, 0x08, 0x09, 0x0A)
16742 + { .size = 2, .data = "\x07\x20" },
16743 + { .size = 2, .data = "\x08\x30" },
16744 + { .size = 2, .data = "\x09\x30" },
16745 + { .size = 2, .data = "\x0A\xFF" },
16746 + // 0x72, 0x73, 0x76, 0x77 input mixer:
16747 + // no intermix between channels
16748 + { .size = 5, .data = "\x72\x00\x00\x00\x00" },
16749 + { .size = 5, .data = "\x73\x00\x80\x00\x00" },
16750 + { .size = 5, .data = "\x76\x00\x00\x00\x00" },
16751 + { .size = 5, .data = "\x77\x00\x80\x00\x00" },
16752 + // 0x70, 0x71, 0x74, 0x75 inline DRC mixer:
16753 + // no inline DRC inmix
16754 + { .size = 5, .data = "\x70\x00\x80\x00\x00" },
16755 + { .size = 5, .data = "\x71\x00\x00\x00\x00" },
16756 + { .size = 5, .data = "\x74\x00\x80\x00\x00" },
16757 + { .size = 5, .data = "\x75\x00\x00\x00\x00" },
16758 + // 0x56, 0x57 Output scale
16759 + { .size = 5, .data = "\x56\x00\x80\x00\x00" },
16760 + { .size = 5, .data = "\x57\x00\x02\x00\x00" },
16761 + // 0x3B, 0x3c
16762 + { .size = 9, .data = "\x3B\x00\x08\x00\x00\x00\x78\x00\x00" },
16763 + { .size = 9, .data = "\x3C\x00\x00\x01\x00\xFF\xFF\xFF\x00" },
16764 + { .size = 9, .data = "\x3E\x00\x08\x00\x00\x00\x78\x00\x00" },
16765 + { .size = 9, .data = "\x3F\x00\x00\x01\x00\xFF\xFF\xFF\x00" },
16766 + { .size = 9, .data = "\x40\x00\x00\x01\x00\xFF\xFF\xFF\x00" },
16767 + { .size = 9, .data = "\x43\x00\x00\x01\x00\xFF\xFF\xFF\x00" },
16768 + // 0x51, 0x52: output mixer
16769 + { .size = 9, .data = "\x51\x00\x80\x00\x00\x00\x00\x00\x00" },
16770 + { .size = 9, .data = "\x52\x00\x80\x00\x00\x00\x00\x00\x00" },
16771 + // PEQ defaults
16772 + { .size = 21, .data = "\x29\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
16773 + { .size = 21, .data = "\x2A\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
16774 + { .size = 21, .data = "\x2B\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
16775 + { .size = 21, .data = "\x2C\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
16776 + { .size = 21, .data = "\x2D\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
16777 + { .size = 21, .data = "\x2E\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
16778 + { .size = 21, .data = "\x2F\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
16779 + { .size = 21, .data = "\x30\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
16780 + { .size = 21, .data = "\x31\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
16781 + { .size = 21, .data = "\x32\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
16782 + { .size = 21, .data = "\x33\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
16783 + { .size = 21, .data = "\x34\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
16784 + { .size = 21, .data = "\x35\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
16785 + { .size = 21, .data = "\x36\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
16786 + { .size = 21, .data = "\x58\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
16787 + { .size = 21, .data = "\x59\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
16788 + { .size = 21, .data = "\x5C\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
16789 + { .size = 21, .data = "\x5D\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
16790 + { .size = 21, .data = "\x5E\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
16791 + { .size = 21, .data = "\x5F\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
16792 + { .size = 21, .data = "\x5A\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
16793 + { .size = 21, .data = "\x5B\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
16794 +};
16795 +
16796 +
16797 +#endif /* _TAS5713_H */
16798 --- a/sound/soc/soc-core.c
16799 +++ b/sound/soc/soc-core.c
16800 @@ -1231,7 +1231,7 @@ found:
16801 * Returns 0 on success, otherwise a negative error code.
16802 */
16803 int snd_soc_runtime_set_dai_fmt(struct snd_soc_pcm_runtime *rtd,
16804 - unsigned int dai_fmt)
16805 + unsigned int dai_fmt)
16806 {
16807 struct snd_soc_dai *cpu_dai;
16808 struct snd_soc_dai *codec_dai;
16809 @@ -1240,7 +1240,15 @@ int snd_soc_runtime_set_dai_fmt(struct s
16810 int ret;
16811
16812 for_each_rtd_codec_dais(rtd, i, codec_dai) {
16813 - ret = snd_soc_dai_set_fmt(codec_dai, dai_fmt);
16814 + unsigned int codec_dai_fmt = dai_fmt;
16815 +
16816 + // there can only be one master when using multiple codecs
16817 + if (i && (codec_dai_fmt & SND_SOC_DAIFMT_MASTER_MASK)) {
16818 + codec_dai_fmt &= ~SND_SOC_DAIFMT_MASTER_MASK;
16819 + codec_dai_fmt |= SND_SOC_DAIFMT_CBS_CFS;
16820 + }
16821 +
16822 + ret = snd_soc_dai_set_fmt(codec_dai, codec_dai_fmt);
16823 if (ret != 0 && ret != -ENOTSUPP)
16824 return ret;
16825 }
16826 @@ -1249,8 +1257,21 @@ int snd_soc_runtime_set_dai_fmt(struct s
16827 * Flip the polarity for the "CPU" end of a CODEC<->CODEC link
16828 * the component which has non_legacy_dai_naming is Codec
16829 */
16830 - inv_dai_fmt = snd_soc_daifmt_clock_provider_fliped(dai_fmt);
16831 -
16832 + inv_dai_fmt = dai_fmt & ~SND_SOC_DAIFMT_MASTER_MASK;
16833 + switch (dai_fmt & SND_SOC_DAIFMT_MASTER_MASK) {
16834 + case SND_SOC_DAIFMT_CBM_CFM:
16835 + inv_dai_fmt |= SND_SOC_DAIFMT_CBS_CFS;
16836 + break;
16837 + case SND_SOC_DAIFMT_CBM_CFS:
16838 + inv_dai_fmt |= SND_SOC_DAIFMT_CBS_CFM;
16839 + break;
16840 + case SND_SOC_DAIFMT_CBS_CFM:
16841 + inv_dai_fmt |= SND_SOC_DAIFMT_CBM_CFS;
16842 + break;
16843 + case SND_SOC_DAIFMT_CBS_CFS:
16844 + inv_dai_fmt |= SND_SOC_DAIFMT_CBM_CFM;
16845 + break;
16846 + }
16847 for_each_rtd_cpu_dais(rtd, i, cpu_dai) {
16848 unsigned int fmt = dai_fmt;
16849