8685508ddf6af7783baa4d0eec44c24e05fdbbdc
[openwrt/staging/wigyori.git] /
1 From 74bd4038e58c360675a25d766634b424239c4b98 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 0106/1085] 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 ASoC:ma120x0p: Increase maximum sample rate to 192KHz
856
857 Change the maximum sample rate for the amplifier to
858 192KHz as given in the Infineon specification.
859
860 Signed-off-by: Joerg Schambacher <joerg@hifiberry.com>
861
862 ASoC: ma120x0p: Remove unnecessary const specifier
863
864 Clang warns:
865
866 sound/soc/codecs/ma120x0p.c:891:14: warning: duplicate 'const' declaration specifier [-Wduplicate-decl-specifier]
867 static const SOC_VALUE_ENUM_SINGLE_DECL(pwr_mode_ctrl,
868 ^
869 ./include/sound/soc.h:362:2: note: expanded from macro 'SOC_VALUE_ENUM_SINGLE_DECL'
870 SOC_VALUE_ENUM_DOUBLE_DECL(name, xreg, xshift, xshift, xmask, xtexts, xvalues)
871 ^
872 ./include/sound/soc.h:359:2: note: expanded from macro 'SOC_VALUE_ENUM_DOUBLE_DECL'
873 const struct soc_enum name = SOC_VALUE_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xmask, \
874 ^
875 1 warning generated.
876
877 SOC_VALUE_ENUM_DOUBLE_DECL already has a const specifier. Remove the duplicate
878 const to clean up the warning.
879
880 Fixes: 42444979e710 ("Add support for all the downstream rpi sound card drivers")
881 Signed-off-by: Nathan Chancellor <nathan@kernel.org>
882
883 ASoC: bcm: allo-piano-dac-plus: Remove unnecessary const specifiers
884
885 Clang warns:
886
887 sound/soc/bcm/allo-piano-dac-plus.c:66:14: warning: duplicate 'const' declaration specifier [-Wduplicate-decl-specifier]
888 static const SOC_ENUM_SINGLE_DECL(allo_piano_mode_enum,
889 ^
890 ./include/sound/soc.h:355:2: note: expanded from macro 'SOC_ENUM_SINGLE_DECL'
891 SOC_ENUM_DOUBLE_DECL(name, xreg, xshift, xshift, xtexts)
892 ^
893 ./include/sound/soc.h:352:2: note: expanded from macro 'SOC_ENUM_DOUBLE_DECL'
894 const struct soc_enum name = SOC_ENUM_DOUBLE(xreg, xshift_l, xshift_r, \
895 ^
896 sound/soc/bcm/allo-piano-dac-plus.c:75:14: warning: duplicate 'const' declaration specifier [-Wduplicate-decl-specifier]
897 static const SOC_ENUM_SINGLE_DECL(allo_piano_dual_mode_enum,
898 ^
899 ./include/sound/soc.h:355:2: note: expanded from macro 'SOC_ENUM_SINGLE_DECL'
900 SOC_ENUM_DOUBLE_DECL(name, xreg, xshift, xshift, xtexts)
901 ^
902 ./include/sound/soc.h:352:2: note: expanded from macro 'SOC_ENUM_DOUBLE_DECL'
903 const struct soc_enum name = SOC_ENUM_DOUBLE(xreg, xshift_l, xshift_r, \
904 ^
905 sound/soc/bcm/allo-piano-dac-plus.c:96:14: warning: duplicate 'const' declaration specifier [-Wduplicate-decl-specifier]
906 static const SOC_ENUM_SINGLE_DECL(allo_piano_enum,
907 ^
908 ./include/sound/soc.h:355:2: note: expanded from macro 'SOC_ENUM_SINGLE_DECL'
909 SOC_ENUM_DOUBLE_DECL(name, xreg, xshift, xshift, xtexts)
910 ^
911 ./include/sound/soc.h:352:2: note: expanded from macro 'SOC_ENUM_DOUBLE_DECL'
912 const struct soc_enum name = SOC_ENUM_DOUBLE(xreg, xshift_l, xshift_r, \
913 ^
914 3 warnings generated.
915
916 SOC_VALUE_ENUM_DOUBLE_DECL already has a const specifier. Remove the duplicate
917 const specifiers to clean up the warnings.
918
919 Fixes: 42444979e710 ("Add support for all the downstream rpi sound card drivers")
920 Signed-off-by: Nathan Chancellor <nathan@kernel.org>
921
922 rpi-simple-soundcard: Add Dion Audio KIWI streamer
923
924 Signed-off-by: Miquel Blauw <miquelblauw@hotmail.com>
925
926 rpi-simple-soundcard: adds definitions for the HiFiBerry AMP3 card
927
928 Uses Infineon MA120x0 amplifier and supports full sample rate of 192ksps.
929
930 Signed-off-by: Joerg Schambacher <joerg@hifiberry.com>
931
932 sound: soc: bcm: Added Sound card driver for Dacberry400 Audio card for Raspberry Pi 400
933
934 Added Sound card driver for DACberry400 Audio card.
935
936 Signed-off-by: Ashish Vara <ashishhvara@gmail.com>
937
938 ASoC:ma120x0p: Corrects the volume level display
939
940 Fixes the wrongly changed 'limiter volume' display back to -50dB minimum
941 and sets the correct minimum volume level to -144dB to be aligned with
942 the controls and display in alsamixer etc.
943
944 Signed-off-by: Joerg Schambacher <joerg@hifiberry.com>
945
946 ASoC: bcm: Fix Rpi-PROTO and audioinjector.net Pi
947
948 As of kernel 5.19 the WM8731 driver has separate I2C and SPI support
949 modules. Change the Kconfig definitions for the audioinjector.net Pi
950 and Rpi-PROTO soundcards to select SND_SOC_WM8731_I2C.
951
952 See: https://github.com/raspberrypi/linux/issues/5364
953
954 Signed-off-by: Phil Elwell <phil@raspberrypi.com>
955
956 ASoC: adau1977: Add correct compatible strings
957
958 Signed-off-by: Phil Elwell <phil@raspberrypi.com>
959
960 ASoC: bcm2835-i2s: Use phys addresses for DAI DMA
961
962 Contrary to what struct snd_dmaengine_dai_dma_data suggests, the
963 configuration of addresses of DMA slave interfaces should be done in
964 CPU physical addresses.
965
966 Signed-off-by: Phil Elwell <phil@raspberrypi.com>
967
968 rpi sound cards: Fix Codec Zero rate switching
969
970 The Raspberry Pi Codec Zero (and IQaudIO Codec) don't notify the DA7213
971 codec when it needs to change PLL frequencies. As a result, audio can
972 be played at the wrong rate - play a 48kHz sound immediately after a
973 44.1kHz sound to see the effect, but in some configurations the codec
974 can lock into the wrong state and always get some rates wrong.
975
976 Add the necessary notification to fix the issue.
977
978 Signed-off-by: Phil Elwell <phil@raspberrypi.com>
979 ---
980 .../devicetree/bindings/vendor-prefixes.txt | 463 ++++++
981 .../devicetree/bindings/vendor-prefixes.yaml | 2 +
982 drivers/clk/Kconfig | 6 +
983 drivers/clk/Makefile | 2 +
984 drivers/clk/clk-hifiberry-dachd.c | 331 ++++
985 drivers/clk/clk-hifiberry-dacpro.c | 181 +++
986 sound/soc/bcm/Kconfig | 306 ++++
987 sound/soc/bcm/Makefile | 71 +-
988 sound/soc/bcm/allo-boss-dac.c | 457 ++++++
989 sound/soc/bcm/allo-boss2-dac.c | 1130 ++++++++++++++
990 sound/soc/bcm/allo-katana-codec.c | 386 +++++
991 sound/soc/bcm/allo-piano-dac-plus.c | 1064 +++++++++++++
992 sound/soc/bcm/allo-piano-dac.c | 122 ++
993 .../bcm/audioinjector-isolated-soundcard.c | 183 +++
994 sound/soc/bcm/audioinjector-octo-soundcard.c | 346 +++++
995 sound/soc/bcm/audioinjector-pi-soundcard.c | 189 +++
996 sound/soc/bcm/audiosense-pi.c | 248 +++
997 sound/soc/bcm/bcm2835-i2s.c | 18 +-
998 sound/soc/bcm/chipdip-dac.c | 275 ++++
999 sound/soc/bcm/dacberry400.c | 259 ++++
1000 sound/soc/bcm/digidac1-soundcard.c | 421 +++++
1001 sound/soc/bcm/dionaudio_loco-v2.c | 117 ++
1002 sound/soc/bcm/dionaudio_loco.c | 117 ++
1003 sound/soc/bcm/fe-pi-audio.c | 154 ++
1004 sound/soc/bcm/googlevoicehat-codec.c | 214 +++
1005 sound/soc/bcm/hifiberry_dacplus.c | 527 +++++++
1006 sound/soc/bcm/hifiberry_dacplusadc.c | 398 +++++
1007 sound/soc/bcm/hifiberry_dacplusadcpro.c | 605 ++++++++
1008 sound/soc/bcm/hifiberry_dacplusdsp.c | 90 ++
1009 sound/soc/bcm/hifiberry_dacplushd.c | 238 +++
1010 sound/soc/bcm/i-sabre-q2m.c | 159 ++
1011 sound/soc/bcm/iqaudio-codec.c | 278 ++++
1012 sound/soc/bcm/iqaudio-dac.c | 224 +++
1013 sound/soc/bcm/justboom-both.c | 267 ++++
1014 sound/soc/bcm/justboom-dac.c | 147 ++
1015 sound/soc/bcm/pifi-40.c | 284 ++++
1016 sound/soc/bcm/pisound.c | 1241 +++++++++++++++
1017 sound/soc/bcm/rpi-cirrus.c | 1025 ++++++++++++
1018 sound/soc/bcm/rpi-proto.c | 147 ++
1019 sound/soc/bcm/rpi-simple-soundcard.c | 487 ++++++
1020 sound/soc/bcm/rpi-wm8804-soundcard.c | 410 +++++
1021 sound/soc/codecs/Kconfig | 26 +-
1022 sound/soc/codecs/Makefile | 8 +
1023 sound/soc/codecs/adau1977-i2c.c | 10 +
1024 sound/soc/codecs/cs42xx8-i2c.c | 9 +-
1025 sound/soc/codecs/cs42xx8.c | 10 +
1026 sound/soc/codecs/i-sabre-codec.c | 389 +++++
1027 sound/soc/codecs/i-sabre-codec.h | 42 +
1028 sound/soc/codecs/ma120x0p.c | 1380 +++++++++++++++++
1029 sound/soc/codecs/pcm1794a.c | 69 +
1030 sound/soc/codecs/pcm512x.c | 2 +-
1031 sound/soc/codecs/tas5713.c | 360 +++++
1032 sound/soc/codecs/tas5713.h | 210 +++
1033 sound/soc/soc-core.c | 10 +-
1034 sound/usb/card.c | 8 +-
1035 sound/usb/quirks.c | 2 +
1036 56 files changed, 16103 insertions(+), 21 deletions(-)
1037 create mode 100644 Documentation/devicetree/bindings/vendor-prefixes.txt
1038 create mode 100644 drivers/clk/clk-hifiberry-dachd.c
1039 create mode 100644 drivers/clk/clk-hifiberry-dacpro.c
1040 create mode 100644 sound/soc/bcm/allo-boss-dac.c
1041 create mode 100644 sound/soc/bcm/allo-boss2-dac.c
1042 create mode 100644 sound/soc/bcm/allo-katana-codec.c
1043 create mode 100644 sound/soc/bcm/allo-piano-dac-plus.c
1044 create mode 100644 sound/soc/bcm/allo-piano-dac.c
1045 create mode 100644 sound/soc/bcm/audioinjector-isolated-soundcard.c
1046 create mode 100644 sound/soc/bcm/audioinjector-octo-soundcard.c
1047 create mode 100644 sound/soc/bcm/audioinjector-pi-soundcard.c
1048 create mode 100644 sound/soc/bcm/audiosense-pi.c
1049 create mode 100644 sound/soc/bcm/chipdip-dac.c
1050 create mode 100644 sound/soc/bcm/dacberry400.c
1051 create mode 100644 sound/soc/bcm/digidac1-soundcard.c
1052 create mode 100644 sound/soc/bcm/dionaudio_loco-v2.c
1053 create mode 100644 sound/soc/bcm/dionaudio_loco.c
1054 create mode 100644 sound/soc/bcm/fe-pi-audio.c
1055 create mode 100644 sound/soc/bcm/googlevoicehat-codec.c
1056 create mode 100644 sound/soc/bcm/hifiberry_dacplus.c
1057 create mode 100644 sound/soc/bcm/hifiberry_dacplusadc.c
1058 create mode 100644 sound/soc/bcm/hifiberry_dacplusadcpro.c
1059 create mode 100644 sound/soc/bcm/hifiberry_dacplusdsp.c
1060 create mode 100644 sound/soc/bcm/hifiberry_dacplushd.c
1061 create mode 100644 sound/soc/bcm/i-sabre-q2m.c
1062 create mode 100644 sound/soc/bcm/iqaudio-codec.c
1063 create mode 100644 sound/soc/bcm/iqaudio-dac.c
1064 create mode 100644 sound/soc/bcm/justboom-both.c
1065 create mode 100644 sound/soc/bcm/justboom-dac.c
1066 create mode 100644 sound/soc/bcm/pifi-40.c
1067 create mode 100644 sound/soc/bcm/pisound.c
1068 create mode 100644 sound/soc/bcm/rpi-cirrus.c
1069 create mode 100644 sound/soc/bcm/rpi-proto.c
1070 create mode 100644 sound/soc/bcm/rpi-simple-soundcard.c
1071 create mode 100644 sound/soc/bcm/rpi-wm8804-soundcard.c
1072 create mode 100644 sound/soc/codecs/i-sabre-codec.c
1073 create mode 100644 sound/soc/codecs/i-sabre-codec.h
1074 create mode 100644 sound/soc/codecs/ma120x0p.c
1075 create mode 100644 sound/soc/codecs/pcm1794a.c
1076 create mode 100644 sound/soc/codecs/tas5713.c
1077 create mode 100644 sound/soc/codecs/tas5713.h
1078
1079 --- /dev/null
1080 +++ b/Documentation/devicetree/bindings/vendor-prefixes.txt
1081 @@ -0,0 +1,463 @@
1082 +Device tree binding vendor prefix registry. Keep list in alphabetical order.
1083 +
1084 +This isn't an exhaustive list, but you should add new prefixes to it before
1085 +using them to avoid name-space collisions.
1086 +
1087 +abilis Abilis Systems
1088 +abracon Abracon Corporation
1089 +actions Actions Semiconductor Co., Ltd.
1090 +active-semi Active-Semi International Inc
1091 +ad Avionic Design GmbH
1092 +adafruit Adafruit Industries, LLC
1093 +adapteva Adapteva, Inc.
1094 +adaptrum Adaptrum, Inc.
1095 +adh AD Holdings Plc.
1096 +adi Analog Devices, Inc.
1097 +advantech Advantech Corporation
1098 +aeroflexgaisler Aeroflex Gaisler AB
1099 +al Annapurna Labs
1100 +allo Allo.com
1101 +allwinner Allwinner Technology Co., Ltd.
1102 +alphascale AlphaScale Integrated Circuits Systems, Inc.
1103 +altr Altera Corp.
1104 +amarula Amarula Solutions
1105 +amazon Amazon.com, Inc.
1106 +amcc Applied Micro Circuits Corporation (APM, formally AMCC)
1107 +amd Advanced Micro Devices (AMD), Inc.
1108 +amediatech Shenzhen Amediatech Technology Co., Ltd
1109 +amlogic Amlogic, Inc.
1110 +ampire Ampire Co., Ltd.
1111 +ams AMS AG
1112 +amstaos AMS-Taos Inc.
1113 +analogix Analogix Semiconductor, Inc.
1114 +andestech Andes Technology Corporation
1115 +apm Applied Micro Circuits Corporation (APM)
1116 +aptina Aptina Imaging
1117 +arasan Arasan Chip Systems
1118 +archermind ArcherMind Technology (Nanjing) Co., Ltd.
1119 +arctic Arctic Sand
1120 +aries Aries Embedded GmbH
1121 +arm ARM Ltd.
1122 +armadeus ARMadeus Systems SARL
1123 +arrow Arrow Electronics
1124 +artesyn Artesyn Embedded Technologies Inc.
1125 +asahi-kasei Asahi Kasei Corp.
1126 +aspeed ASPEED Technology Inc.
1127 +asus AsusTek Computer Inc.
1128 +atlas Atlas Scientific LLC
1129 +atmel Atmel Corporation
1130 +auo AU Optronics Corporation
1131 +auvidea Auvidea GmbH
1132 +avago Avago Technologies
1133 +avia avia semiconductor
1134 +avic Shanghai AVIC Optoelectronics Co., Ltd.
1135 +avnet Avnet, Inc.
1136 +axentia Axentia Technologies AB
1137 +axis Axis Communications AB
1138 +bananapi BIPAI KEJI LIMITED
1139 +bhf Beckhoff Automation GmbH & Co. KG
1140 +bitmain Bitmain Technologies
1141 +blokaslabs Vilniaus Blokas UAB
1142 +boe BOE Technology Group Co., Ltd.
1143 +bosch Bosch Sensortec GmbH
1144 +boundary Boundary Devices Inc.
1145 +brcm Broadcom Corporation
1146 +buffalo Buffalo, Inc.
1147 +bticino Bticino International
1148 +calxeda Calxeda
1149 +capella Capella Microsystems, Inc
1150 +cascoda Cascoda, Ltd.
1151 +catalyst Catalyst Semiconductor, Inc.
1152 +cavium Cavium, Inc.
1153 +cdns Cadence Design Systems Inc.
1154 +cdtech CDTech(H.K.) Electronics Limited
1155 +ceva Ceva, Inc.
1156 +chipidea Chipidea, Inc
1157 +chipone ChipOne
1158 +chipspark ChipSPARK
1159 +chrp Common Hardware Reference Platform
1160 +chunghwa Chunghwa Picture Tubes Ltd.
1161 +ciaa Computadora Industrial Abierta Argentina
1162 +cirrus Cirrus Logic, Inc.
1163 +cloudengines Cloud Engines, Inc.
1164 +cnm Chips&Media, Inc.
1165 +cnxt Conexant Systems, Inc.
1166 +compulab CompuLab Ltd.
1167 +cortina Cortina Systems, Inc.
1168 +cosmic Cosmic Circuits
1169 +crane Crane Connectivity Solutions
1170 +creative Creative Technology Ltd
1171 +crystalfontz Crystalfontz America, Inc.
1172 +csky Hangzhou C-SKY Microsystems Co., Ltd
1173 +cubietech Cubietech, Ltd.
1174 +cypress Cypress Semiconductor Corporation
1175 +cznic CZ.NIC, z.s.p.o.
1176 +dallas Maxim Integrated Products (formerly Dallas Semiconductor)
1177 +dataimage DataImage, Inc.
1178 +davicom DAVICOM Semiconductor, Inc.
1179 +delta Delta Electronics, Inc.
1180 +denx Denx Software Engineering
1181 +devantech Devantech, Ltd.
1182 +dh DH electronics GmbH
1183 +digi Digi International Inc.
1184 +digilent Diglent, Inc.
1185 +dioo Dioo Microcircuit Co., Ltd
1186 +dlc DLC Display Co., Ltd.
1187 +dlg Dialog Semiconductor
1188 +dlink D-Link Corporation
1189 +dmo Data Modul AG
1190 +domintech Domintech Co., Ltd.
1191 +dongwoon Dongwoon Anatech
1192 +dptechnics DPTechnics
1193 +dragino Dragino Technology Co., Limited
1194 +ea Embedded Artists AB
1195 +ebs-systart EBS-SYSTART GmbH
1196 +ebv EBV Elektronik
1197 +eckelmann Eckelmann AG
1198 +edt Emerging Display Technologies
1199 +eeti eGalax_eMPIA Technology Inc
1200 +elan Elan Microelectronic Corp.
1201 +elgin Elgin S/A.
1202 +embest Shenzhen Embest Technology Co., Ltd.
1203 +emlid Emlid, Ltd.
1204 +emmicro EM Microelectronic
1205 +emtrion emtrion GmbH
1206 +endless Endless Mobile, Inc.
1207 +energymicro Silicon Laboratories (formerly Energy Micro AS)
1208 +engicam Engicam S.r.l.
1209 +epcos EPCOS AG
1210 +epfl Ecole Polytechnique Fédérale de Lausanne
1211 +epson Seiko Epson Corp.
1212 +est ESTeem Wireless Modems
1213 +ettus NI Ettus Research
1214 +eukrea Eukréa Electromatique
1215 +everest Everest Semiconductor Co. Ltd.
1216 +everspin Everspin Technologies, Inc.
1217 +exar Exar Corporation
1218 +excito Excito
1219 +ezchip EZchip Semiconductor
1220 +facebook Facebook
1221 +fairphone Fairphone B.V.
1222 +faraday Faraday Technology Corporation
1223 +fastrax Fastrax Oy
1224 +fcs Fairchild Semiconductor
1225 +feiyang Shenzhen Fly Young Technology Co.,LTD.
1226 +firefly Firefly
1227 +focaltech FocalTech Systems Co.,Ltd
1228 +friendlyarm Guangzhou FriendlyARM Computer Tech Co., Ltd
1229 +fsl Freescale Semiconductor
1230 +fujitsu Fujitsu Ltd.
1231 +gateworks Gateworks Corporation
1232 +gcw Game Consoles Worldwide
1233 +ge General Electric Company
1234 +geekbuying GeekBuying
1235 +gef GE Fanuc Intelligent Platforms Embedded Systems, Inc.
1236 +GEFanuc GE Fanuc Intelligent Platforms Embedded Systems, Inc.
1237 +geniatech Geniatech, Inc.
1238 +giantec Giantec Semiconductor, Inc.
1239 +giantplus Giantplus Technology Co., Ltd.
1240 +globalscale Globalscale Technologies, Inc.
1241 +globaltop GlobalTop Technology, Inc.
1242 +gmt Global Mixed-mode Technology, Inc.
1243 +goodix Shenzhen Huiding Technology Co., Ltd.
1244 +google Google, Inc.
1245 +grinn Grinn
1246 +grmn Garmin Limited
1247 +gumstix Gumstix, Inc.
1248 +gw Gateworks Corporation
1249 +hannstar HannStar Display Corporation
1250 +haoyu Haoyu Microelectronic Co. Ltd.
1251 +hardkernel Hardkernel Co., Ltd
1252 +hideep HiDeep Inc.
1253 +himax Himax Technologies, Inc.
1254 +hisilicon Hisilicon Limited.
1255 +hit Hitachi Ltd.
1256 +hitex Hitex Development Tools
1257 +holt Holt Integrated Circuits, Inc.
1258 +honeywell Honeywell
1259 +hp Hewlett Packard
1260 +holtek Holtek Semiconductor, Inc.
1261 +hwacom HwaCom Systems Inc.
1262 +i2se I2SE GmbH
1263 +ibm International Business Machines (IBM)
1264 +icplus IC Plus Corp.
1265 +idt Integrated Device Technologies, Inc.
1266 +ifi Ingenieurburo Fur Ic-Technologie (I/F/I)
1267 +ilitek ILI Technology Corporation (ILITEK)
1268 +img Imagination Technologies Ltd.
1269 +infineon Infineon Technologies
1270 +inforce Inforce Computing
1271 +ingenic Ingenic Semiconductor
1272 +innolux Innolux Corporation
1273 +inside-secure INSIDE Secure
1274 +intel Intel Corporation
1275 +intercontrol Inter Control Group
1276 +invensense InvenSense Inc.
1277 +inversepath Inverse Path
1278 +iom Iomega Corporation
1279 +isee ISEE 2007 S.L.
1280 +isil Intersil
1281 +issi Integrated Silicon Solutions Inc.
1282 +itead ITEAD Intelligent Systems Co.Ltd
1283 +iwave iWave Systems Technologies Pvt. Ltd.
1284 +jdi Japan Display Inc.
1285 +jedec JEDEC Solid State Technology Association
1286 +jianda Jiandangjing Technology Co., Ltd.
1287 +karo Ka-Ro electronics GmbH
1288 +keithkoep Keith & Koep GmbH
1289 +keymile Keymile GmbH
1290 +khadas Khadas
1291 +kiebackpeter Kieback & Peter GmbH
1292 +kinetic Kinetic Technologies
1293 +kingdisplay King & Display Technology Co., Ltd.
1294 +kingnovel Kingnovel Technology Co., Ltd.
1295 +koe Kaohsiung Opto-Electronics Inc.
1296 +kosagi Sutajio Ko-Usagi PTE Ltd.
1297 +kyo Kyocera Corporation
1298 +lacie LaCie
1299 +laird Laird PLC
1300 +lantiq Lantiq Semiconductor
1301 +lattice Lattice Semiconductor
1302 +lego LEGO Systems A/S
1303 +lemaker Shenzhen LeMaker Technology Co., Ltd.
1304 +lenovo Lenovo Group Ltd.
1305 +lg LG Corporation
1306 +libretech Shenzhen Libre Technology Co., Ltd
1307 +licheepi Lichee Pi
1308 +linaro Linaro Limited
1309 +linksys Belkin International, Inc. (Linksys)
1310 +linux Linux-specific binding
1311 +linx Linx Technologies
1312 +lltc Linear Technology Corporation
1313 +logicpd Logic PD, Inc.
1314 +lsi LSI Corp. (LSI Logic)
1315 +lwn Liebherr-Werk Nenzing GmbH
1316 +macnica Macnica Americas
1317 +marvell Marvell Technology Group Ltd.
1318 +maxim Maxim Integrated Products
1319 +mbvl Mobiveil Inc.
1320 +mcube mCube
1321 +meas Measurement Specialties
1322 +mediatek MediaTek Inc.
1323 +megachips MegaChips
1324 +mele Shenzhen MeLE Digital Technology Ltd.
1325 +melexis Melexis N.V.
1326 +melfas MELFAS Inc.
1327 +mellanox Mellanox Technologies
1328 +memsic MEMSIC Inc.
1329 +merrii Merrii Technology Co., Ltd.
1330 +micrel Micrel Inc.
1331 +microchip Microchip Technology Inc.
1332 +microcrystal Micro Crystal AG
1333 +micron Micron Technology Inc.
1334 +mikroe MikroElektronika d.o.o.
1335 +minix MINIX Technology Ltd.
1336 +miramems MiraMEMS Sensing Technology Co., Ltd.
1337 +mitsubishi Mitsubishi Electric Corporation
1338 +mosaixtech Mosaix Technologies, Inc.
1339 +motorola Motorola, Inc.
1340 +moxa Moxa Inc.
1341 +mpl MPL AG
1342 +mqmaker mqmaker Inc.
1343 +mscc Microsemi Corporation
1344 +msi Micro-Star International Co. Ltd.
1345 +mti Imagination Technologies Ltd. (formerly MIPS Technologies Inc.)
1346 +multi-inno Multi-Inno Technology Co.,Ltd
1347 +mundoreader Mundo Reader S.L.
1348 +murata Murata Manufacturing Co., Ltd.
1349 +mxicy Macronix International Co., Ltd.
1350 +myir MYIR Tech Limited
1351 +national National Semiconductor
1352 +nec NEC LCD Technologies, Ltd.
1353 +neonode Neonode Inc.
1354 +netgear NETGEAR
1355 +netlogic Broadcom Corporation (formerly NetLogic Microsystems)
1356 +netron-dy Netron DY
1357 +netxeon Shenzhen Netxeon Technology CO., LTD
1358 +nexbox Nexbox
1359 +nextthing Next Thing Co.
1360 +newhaven Newhaven Display International
1361 +ni National Instruments
1362 +nintendo Nintendo
1363 +nlt NLT Technologies, Ltd.
1364 +nokia Nokia
1365 +nordic Nordic Semiconductor
1366 +novtech NovTech, Inc.
1367 +nutsboard NutsBoard
1368 +nuvoton Nuvoton Technology Corporation
1369 +nvd New Vision Display
1370 +nvidia NVIDIA
1371 +nxp NXP Semiconductors
1372 +okaya Okaya Electric America, Inc.
1373 +oki Oki Electric Industry Co., Ltd.
1374 +olimex OLIMEX Ltd.
1375 +olpc One Laptop Per Child
1376 +onion Onion Corporation
1377 +onnn ON Semiconductor Corp.
1378 +ontat On Tat Industrial Company
1379 +opalkelly Opal Kelly Incorporated
1380 +opencores OpenCores.org
1381 +openrisc OpenRISC.io
1382 +option Option NV
1383 +oranth Shenzhen Oranth Technology Co., Ltd.
1384 +ORCL Oracle Corporation
1385 +orisetech Orise Technology
1386 +ortustech Ortus Technology Co., Ltd.
1387 +ovti OmniVision Technologies
1388 +oxsemi Oxford Semiconductor, Ltd.
1389 +panasonic Panasonic Corporation
1390 +parade Parade Technologies Inc.
1391 +pda Precision Design Associates, Inc.
1392 +pericom Pericom Technology Inc.
1393 +pervasive Pervasive Displays, Inc.
1394 +phicomm PHICOMM Co., Ltd.
1395 +phytec PHYTEC Messtechnik GmbH
1396 +picochip Picochip Ltd
1397 +pine64 Pine64
1398 +pixcir PIXCIR MICROELECTRONICS Co., Ltd
1399 +plantower Plantower Co., Ltd
1400 +plathome Plat'Home Co., Ltd.
1401 +plda PLDA
1402 +plx Broadcom Corporation (formerly PLX Technology)
1403 +pni PNI Sensor Corporation
1404 +portwell Portwell Inc.
1405 +poslab Poslab Technology Co., Ltd.
1406 +powervr PowerVR (deprecated, use img)
1407 +probox2 PROBOX2 (by W2COMP Co., Ltd.)
1408 +pulsedlight PulsedLight, Inc
1409 +qca Qualcomm Atheros, Inc.
1410 +qcom Qualcomm Technologies, Inc
1411 +qemu QEMU, a generic and open source machine emulator and virtualizer
1412 +qi Qi Hardware
1413 +qiaodian QiaoDian XianShi Corporation
1414 +qnap QNAP Systems, Inc.
1415 +radxa Radxa
1416 +raidsonic RaidSonic Technology GmbH
1417 +ralink Mediatek/Ralink Technology Corp.
1418 +ramtron Ramtron International
1419 +raspberrypi Raspberry Pi Foundation
1420 +raydium Raydium Semiconductor Corp.
1421 +rda Unisoc Communications, Inc.
1422 +realtek Realtek Semiconductor Corp.
1423 +renesas Renesas Electronics Corporation
1424 +richtek Richtek Technology Corporation
1425 +ricoh Ricoh Co. Ltd.
1426 +rikomagic Rikomagic Tech Corp. Ltd
1427 +riscv RISC-V Foundation
1428 +rockchip Fuzhou Rockchip Electronics Co., Ltd
1429 +rohm ROHM Semiconductor Co., Ltd
1430 +roofull Shenzhen Roofull Technology Co, Ltd
1431 +samsung Samsung Semiconductor
1432 +samtec Samtec/Softing company
1433 +sancloud Sancloud Ltd
1434 +sandisk Sandisk Corporation
1435 +sbs Smart Battery System
1436 +schindler Schindler
1437 +seagate Seagate Technology PLC
1438 +semtech Semtech Corporation
1439 +sensirion Sensirion AG
1440 +sff Small Form Factor Committee
1441 +sgd Solomon Goldentek Display Corporation
1442 +sgx SGX Sensortech
1443 +sharp Sharp Corporation
1444 +shimafuji Shimafuji Electric, Inc.
1445 +si-en Si-En Technology Ltd.
1446 +sifive SiFive, Inc.
1447 +sigma Sigma Designs, Inc.
1448 +sii Seiko Instruments, Inc.
1449 +sil Silicon Image
1450 +silabs Silicon Laboratories
1451 +silead Silead Inc.
1452 +silergy Silergy Corp.
1453 +siliconmitus Silicon Mitus, Inc.
1454 +simtek
1455 +sirf SiRF Technology, Inc.
1456 +sis Silicon Integrated Systems Corp.
1457 +sitronix Sitronix Technology Corporation
1458 +skyworks Skyworks Solutions, Inc.
1459 +smsc Standard Microsystems Corporation
1460 +snps Synopsys, Inc.
1461 +socionext Socionext Inc.
1462 +solidrun SolidRun
1463 +solomon Solomon Systech Limited
1464 +sony Sony Corporation
1465 +spansion Spansion Inc.
1466 +sprd Spreadtrum Communications Inc.
1467 +sst Silicon Storage Technology, Inc.
1468 +st STMicroelectronics
1469 +starry Starry Electronic Technology (ShenZhen) Co., LTD
1470 +startek Startek
1471 +ste ST-Ericsson
1472 +stericsson ST-Ericsson
1473 +summit Summit microelectronics
1474 +sunchip Shenzhen Sunchip Technology Co., Ltd
1475 +SUNW Sun Microsystems, Inc
1476 +swir Sierra Wireless
1477 +syna Synaptics Inc.
1478 +synology Synology, Inc.
1479 +tbs TBS Technologies
1480 +tbs-biometrics Touchless Biometric Systems AG
1481 +tcg Trusted Computing Group
1482 +tcl Toby Churchill Ltd.
1483 +technexion TechNexion
1484 +technologic Technologic Systems
1485 +tempo Tempo Semiconductor
1486 +techstar Shenzhen Techstar Electronics Co., Ltd.
1487 +terasic Terasic Inc.
1488 +thine THine Electronics, Inc.
1489 +ti Texas Instruments
1490 +tianma Tianma Micro-electronics Co., Ltd.
1491 +tlm Trusted Logic Mobility
1492 +tmt Tecon Microprocessor Technologies, LLC.
1493 +topeet Topeet
1494 +toradex Toradex AG
1495 +toshiba Toshiba Corporation
1496 +toumaz Toumaz
1497 +tpk TPK U.S.A. LLC
1498 +tplink TP-LINK Technologies Co., Ltd.
1499 +tpo TPO
1500 +tronfy Tronfy
1501 +tronsmart Tronsmart
1502 +truly Truly Semiconductors Limited
1503 +tsd Theobroma Systems Design und Consulting GmbH
1504 +tyan Tyan Computer Corporation
1505 +u-blox u-blox
1506 +ucrobotics uCRobotics
1507 +ubnt Ubiquiti Networks
1508 +udoo Udoo
1509 +uniwest United Western Technologies Corp (UniWest)
1510 +upisemi uPI Semiconductor Corp.
1511 +urt United Radiant Technology Corporation
1512 +usi Universal Scientific Industrial Co., Ltd.
1513 +v3 V3 Semiconductor
1514 +vamrs Vamrs Ltd.
1515 +variscite Variscite Ltd.
1516 +via VIA Technologies, Inc.
1517 +virtio Virtual I/O Device Specification, developed by the OASIS consortium
1518 +vishay Vishay Intertechnology, Inc
1519 +vitesse Vitesse Semiconductor Corporation
1520 +vivante Vivante Corporation
1521 +vocore VoCore Studio
1522 +voipac Voipac Technologies s.r.o.
1523 +vot Vision Optical Technology Co., Ltd.
1524 +wd Western Digital Corp.
1525 +wetek WeTek Electronics, limited.
1526 +wexler Wexler
1527 +whwave Shenzhen whwave Electronics, Inc.
1528 +wi2wi Wi2Wi, Inc.
1529 +winbond Winbond Electronics corp.
1530 +winstar Winstar Display Corp.
1531 +wlf Wolfson Microelectronics
1532 +wm Wondermedia Technologies, Inc.
1533 +x-powers X-Powers
1534 +xes Extreme Engineering Solutions (X-ES)
1535 +xillybus Xillybus Ltd.
1536 +xlnx Xilinx
1537 +xunlong Shenzhen Xunlong Software CO.,Limited
1538 +ysoft Y Soft Corporation a.s.
1539 +zarlink Zarlink Semiconductor
1540 +zeitec ZEITEC Semiconductor Co., LTD.
1541 +zidoo Shenzhen Zidoo Technology Co., Ltd.
1542 +zii Zodiac Inflight Innovations
1543 +zte ZTE Corp.
1544 +zyxel Zyxel Communications Corp.
1545 --- a/Documentation/devicetree/bindings/vendor-prefixes.yaml
1546 +++ b/Documentation/devicetree/bindings/vendor-prefixes.yaml
1547 @@ -196,6 +196,8 @@ patternProperties:
1548 description: Beckhoff Automation GmbH & Co. KG
1549 "^bitmain,.*":
1550 description: Bitmain Technologies
1551 + "^blokaslabs,.*":
1552 + description: Vilniaus Blokas UAB
1553 "^blutek,.*":
1554 description: BluTek Power
1555 "^boe,.*":
1556 --- a/drivers/clk/Kconfig
1557 +++ b/drivers/clk/Kconfig
1558 @@ -98,6 +98,12 @@ config COMMON_CLK_HI655X
1559 multi-function device has one fixed-rate oscillator, clocked
1560 at 32KHz.
1561
1562 +config COMMON_CLK_HIFIBERRY_DACPLUSHD
1563 + tristate
1564 +
1565 +config COMMON_CLK_HIFIBERRY_DACPRO
1566 + tristate
1567 +
1568 config COMMON_CLK_SCMI
1569 tristate "Clock driver controlled via SCMI interface"
1570 depends on ARM_SCMI_PROTOCOL || COMPILE_TEST
1571 --- a/drivers/clk/Makefile
1572 +++ b/drivers/clk/Makefile
1573 @@ -45,6 +45,8 @@ obj-$(CONFIG_COMMON_CLK_LAN966X) += clk-
1574 obj-$(CONFIG_COMMON_CLK_LOCHNAGAR) += clk-lochnagar.o
1575 obj-$(CONFIG_MACH_LOONGSON32) += clk-loongson1.o
1576 obj-$(CONFIG_COMMON_CLK_LOONGSON2) += clk-loongson2.o
1577 +obj-$(CONFIG_COMMON_CLK_HIFIBERRY_DACPRO) += clk-hifiberry-dacpro.o
1578 +obj-$(CONFIG_COMMON_CLK_HIFIBERRY_DACPLUSHD) += clk-hifiberry-dachd.o
1579 obj-$(CONFIG_COMMON_CLK_MAX77686) += clk-max77686.o
1580 obj-$(CONFIG_COMMON_CLK_MAX9485) += clk-max9485.o
1581 obj-$(CONFIG_ARCH_MILBEAUT_M10V) += clk-milbeaut.o
1582 --- /dev/null
1583 +++ b/drivers/clk/clk-hifiberry-dachd.c
1584 @@ -0,0 +1,331 @@
1585 +// SPDX-License-Identifier: GPL-2.0
1586 +/*
1587 + * Clock Driver for HiFiBerry DAC+ HD
1588 + *
1589 + * Author: Joerg Schambacher, i2Audio GmbH for HiFiBerry
1590 + * Copyright 2020
1591 + *
1592 + * This program is free software; you can redistribute it and/or
1593 + * modify it under the terms of the GNU General Public License
1594 + * version 2 as published by the Free Software Foundation.
1595 + *
1596 + * This program is distributed in the hope that it will be useful, but
1597 + * WITHOUT ANY WARRANTY; without even the implied warranty of
1598 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1599 + * General Public License for more details.
1600 + */
1601 +
1602 +#include <linux/clk-provider.h>
1603 +#include <linux/clk.h>
1604 +#include <linux/kernel.h>
1605 +#include <linux/module.h>
1606 +#include <linux/of.h>
1607 +#include <linux/slab.h>
1608 +#include <linux/platform_device.h>
1609 +#include <linux/i2c.h>
1610 +#include <linux/regmap.h>
1611 +
1612 +#define NO_PLL_RESET 0
1613 +#define PLL_RESET 1
1614 +#define HIFIBERRY_PLL_MAX_REGISTER 256
1615 +#define DEFAULT_RATE 44100
1616 +
1617 +static struct reg_default hifiberry_pll_reg_defaults[] = {
1618 + {0x02, 0x53}, {0x03, 0x00}, {0x07, 0x20}, {0x0F, 0x00},
1619 + {0x10, 0x0D}, {0x11, 0x1D}, {0x12, 0x0D}, {0x13, 0x8C},
1620 + {0x14, 0x8C}, {0x15, 0x8C}, {0x16, 0x8C}, {0x17, 0x8C},
1621 + {0x18, 0x2A}, {0x1C, 0x00}, {0x1D, 0x0F}, {0x1F, 0x00},
1622 + {0x2A, 0x00}, {0x2C, 0x00}, {0x2F, 0x00}, {0x30, 0x00},
1623 + {0x31, 0x00}, {0x32, 0x00}, {0x34, 0x00}, {0x37, 0x00},
1624 + {0x38, 0x00}, {0x39, 0x00}, {0x3A, 0x00}, {0x3B, 0x01},
1625 + {0x3E, 0x00}, {0x3F, 0x00}, {0x40, 0x00}, {0x41, 0x00},
1626 + {0x5A, 0x00}, {0x5B, 0x00}, {0x95, 0x00}, {0x96, 0x00},
1627 + {0x97, 0x00}, {0x98, 0x00}, {0x99, 0x00}, {0x9A, 0x00},
1628 + {0x9B, 0x00}, {0xA2, 0x00}, {0xA3, 0x00}, {0xA4, 0x00},
1629 + {0xB7, 0x92},
1630 + {0x1A, 0x3D}, {0x1B, 0x09}, {0x1E, 0xF3}, {0x20, 0x13},
1631 + {0x21, 0x75}, {0x2B, 0x04}, {0x2D, 0x11}, {0x2E, 0xE0},
1632 + {0x3D, 0x7A},
1633 + {0x35, 0x9D}, {0x36, 0x00}, {0x3C, 0x42},
1634 + { 177, 0xAC},
1635 +};
1636 +static struct reg_default common_pll_regs[HIFIBERRY_PLL_MAX_REGISTER];
1637 +static int num_common_pll_regs;
1638 +static struct reg_default dedicated_192k_pll_regs[HIFIBERRY_PLL_MAX_REGISTER];
1639 +static int num_dedicated_192k_pll_regs;
1640 +static struct reg_default dedicated_96k_pll_regs[HIFIBERRY_PLL_MAX_REGISTER];
1641 +static int num_dedicated_96k_pll_regs;
1642 +static struct reg_default dedicated_48k_pll_regs[HIFIBERRY_PLL_MAX_REGISTER];
1643 +static int num_dedicated_48k_pll_regs;
1644 +static struct reg_default dedicated_176k4_pll_regs[HIFIBERRY_PLL_MAX_REGISTER];
1645 +static int num_dedicated_176k4_pll_regs;
1646 +static struct reg_default dedicated_88k2_pll_regs[HIFIBERRY_PLL_MAX_REGISTER];
1647 +static int num_dedicated_88k2_pll_regs;
1648 +static struct reg_default dedicated_44k1_pll_regs[HIFIBERRY_PLL_MAX_REGISTER];
1649 +static int num_dedicated_44k1_pll_regs;
1650 +
1651 +/**
1652 + * struct clk_hifiberry_drvdata - Common struct to the HiFiBerry DAC HD Clk
1653 + * @hw: clk_hw for the common clk framework
1654 + */
1655 +struct clk_hifiberry_drvdata {
1656 + struct regmap *regmap;
1657 + struct clk *clk;
1658 + struct clk_hw hw;
1659 + unsigned long rate;
1660 +};
1661 +
1662 +#define to_hifiberry_clk(_hw) \
1663 + container_of(_hw, struct clk_hifiberry_drvdata, hw)
1664 +
1665 +static int clk_hifiberry_dachd_write_pll_regs(struct regmap *regmap,
1666 + struct reg_default *regs,
1667 + int num, int do_pll_reset)
1668 +{
1669 + int i;
1670 + int ret = 0;
1671 + char pll_soft_reset[] = { 177, 0xAC, };
1672 +
1673 + for (i = 0; i < num; i++) {
1674 + ret |= regmap_write(regmap, regs[i].reg, regs[i].def);
1675 + if (ret)
1676 + return ret;
1677 + }
1678 + if (do_pll_reset) {
1679 + ret |= regmap_write(regmap, pll_soft_reset[0],
1680 + pll_soft_reset[1]);
1681 + mdelay(10);
1682 + }
1683 + return ret;
1684 +}
1685 +
1686 +static unsigned long clk_hifiberry_dachd_recalc_rate(struct clk_hw *hw,
1687 + unsigned long parent_rate)
1688 +{
1689 + return to_hifiberry_clk(hw)->rate;
1690 +}
1691 +
1692 +static long clk_hifiberry_dachd_round_rate(struct clk_hw *hw,
1693 + unsigned long rate, unsigned long *parent_rate)
1694 +{
1695 + return rate;
1696 +}
1697 +
1698 +static int clk_hifiberry_dachd_set_rate(struct clk_hw *hw,
1699 + unsigned long rate, unsigned long parent_rate)
1700 +{
1701 + int ret;
1702 + struct clk_hifiberry_drvdata *drvdata = to_hifiberry_clk(hw);
1703 +
1704 + switch (rate) {
1705 + case 44100:
1706 + ret = clk_hifiberry_dachd_write_pll_regs(drvdata->regmap,
1707 + dedicated_44k1_pll_regs, num_dedicated_44k1_pll_regs,
1708 + PLL_RESET);
1709 + break;
1710 + case 88200:
1711 + ret = clk_hifiberry_dachd_write_pll_regs(drvdata->regmap,
1712 + dedicated_88k2_pll_regs, num_dedicated_88k2_pll_regs,
1713 + PLL_RESET);
1714 + break;
1715 + case 176400:
1716 + ret = clk_hifiberry_dachd_write_pll_regs(drvdata->regmap,
1717 + dedicated_176k4_pll_regs, num_dedicated_176k4_pll_regs,
1718 + PLL_RESET);
1719 + break;
1720 + case 48000:
1721 + ret = clk_hifiberry_dachd_write_pll_regs(drvdata->regmap,
1722 + dedicated_48k_pll_regs, num_dedicated_48k_pll_regs,
1723 + PLL_RESET);
1724 + break;
1725 + case 96000:
1726 + ret = clk_hifiberry_dachd_write_pll_regs(drvdata->regmap,
1727 + dedicated_96k_pll_regs, num_dedicated_96k_pll_regs,
1728 + PLL_RESET);
1729 + break;
1730 + case 192000:
1731 + ret = clk_hifiberry_dachd_write_pll_regs(drvdata->regmap,
1732 + dedicated_192k_pll_regs, num_dedicated_192k_pll_regs,
1733 + PLL_RESET);
1734 + break;
1735 + default:
1736 + ret = -EINVAL;
1737 + break;
1738 + }
1739 + to_hifiberry_clk(hw)->rate = rate;
1740 +
1741 + return ret;
1742 +}
1743 +
1744 +const struct clk_ops clk_hifiberry_dachd_rate_ops = {
1745 + .recalc_rate = clk_hifiberry_dachd_recalc_rate,
1746 + .round_rate = clk_hifiberry_dachd_round_rate,
1747 + .set_rate = clk_hifiberry_dachd_set_rate,
1748 +};
1749 +
1750 +static int clk_hifiberry_get_prop_values(struct device *dev,
1751 + char *prop_name,
1752 + struct reg_default *regs)
1753 +{
1754 + int ret;
1755 + int i;
1756 + u8 tmp[2 * HIFIBERRY_PLL_MAX_REGISTER];
1757 +
1758 + ret = of_property_read_variable_u8_array(dev->of_node, prop_name,
1759 + tmp, 0, 2 * HIFIBERRY_PLL_MAX_REGISTER);
1760 + if (ret < 0)
1761 + return ret;
1762 + if (ret & 1) {
1763 + dev_err(dev,
1764 + "%s <%s> -> #%i odd number of bytes for reg/val pairs!",
1765 + __func__,
1766 + prop_name,
1767 + ret);
1768 + return -EINVAL;
1769 + }
1770 + ret /= 2;
1771 + for (i = 0; i < ret; i++) {
1772 + regs[i].reg = (u32)tmp[2 * i];
1773 + regs[i].def = (u32)tmp[2 * i + 1];
1774 + }
1775 + return ret;
1776 +}
1777 +
1778 +
1779 +static int clk_hifiberry_dachd_dt_parse(struct device *dev)
1780 +{
1781 + num_common_pll_regs = clk_hifiberry_get_prop_values(dev,
1782 + "common_pll_regs", common_pll_regs);
1783 + num_dedicated_44k1_pll_regs = clk_hifiberry_get_prop_values(dev,
1784 + "44k1_pll_regs", dedicated_44k1_pll_regs);
1785 + num_dedicated_88k2_pll_regs = clk_hifiberry_get_prop_values(dev,
1786 + "88k2_pll_regs", dedicated_88k2_pll_regs);
1787 + num_dedicated_176k4_pll_regs = clk_hifiberry_get_prop_values(dev,
1788 + "176k4_pll_regs", dedicated_176k4_pll_regs);
1789 + num_dedicated_48k_pll_regs = clk_hifiberry_get_prop_values(dev,
1790 + "48k_pll_regs", dedicated_48k_pll_regs);
1791 + num_dedicated_96k_pll_regs = clk_hifiberry_get_prop_values(dev,
1792 + "96k_pll_regs", dedicated_96k_pll_regs);
1793 + num_dedicated_192k_pll_regs = clk_hifiberry_get_prop_values(dev,
1794 + "192k_pll_regs", dedicated_192k_pll_regs);
1795 + return 0;
1796 +}
1797 +
1798 +
1799 +static int clk_hifiberry_dachd_remove(struct device *dev)
1800 +{
1801 + of_clk_del_provider(dev->of_node);
1802 + return 0;
1803 +}
1804 +
1805 +const struct regmap_config hifiberry_pll_regmap = {
1806 + .reg_bits = 8,
1807 + .val_bits = 8,
1808 + .max_register = HIFIBERRY_PLL_MAX_REGISTER,
1809 + .reg_defaults = hifiberry_pll_reg_defaults,
1810 + .num_reg_defaults = ARRAY_SIZE(hifiberry_pll_reg_defaults),
1811 + .cache_type = REGCACHE_RBTREE,
1812 +};
1813 +EXPORT_SYMBOL_GPL(hifiberry_pll_regmap);
1814 +
1815 +
1816 +static int clk_hifiberry_dachd_i2c_probe(struct i2c_client *i2c)
1817 +{
1818 + struct clk_hifiberry_drvdata *hdclk;
1819 + int ret = 0;
1820 + struct clk_init_data init;
1821 + struct device *dev = &i2c->dev;
1822 + struct device_node *dev_node = dev->of_node;
1823 + struct regmap_config config = hifiberry_pll_regmap;
1824 +
1825 + hdclk = devm_kzalloc(&i2c->dev,
1826 + sizeof(struct clk_hifiberry_drvdata), GFP_KERNEL);
1827 + if (!hdclk)
1828 + return -ENOMEM;
1829 +
1830 + i2c_set_clientdata(i2c, hdclk);
1831 +
1832 + hdclk->regmap = devm_regmap_init_i2c(i2c, &config);
1833 +
1834 + if (IS_ERR(hdclk->regmap))
1835 + return PTR_ERR(hdclk->regmap);
1836 +
1837 + /* start PLL to allow detection of DAC */
1838 + ret = clk_hifiberry_dachd_write_pll_regs(hdclk->regmap,
1839 + hifiberry_pll_reg_defaults,
1840 + ARRAY_SIZE(hifiberry_pll_reg_defaults),
1841 + PLL_RESET);
1842 + if (ret)
1843 + return ret;
1844 +
1845 + clk_hifiberry_dachd_dt_parse(dev);
1846 +
1847 + /* restart PLL with configs from DTB */
1848 + ret = clk_hifiberry_dachd_write_pll_regs(hdclk->regmap, common_pll_regs,
1849 + num_common_pll_regs, PLL_RESET);
1850 + if (ret)
1851 + return ret;
1852 +
1853 + init.name = "clk-hifiberry-dachd";
1854 + init.ops = &clk_hifiberry_dachd_rate_ops;
1855 + init.flags = 0;
1856 + init.parent_names = NULL;
1857 + init.num_parents = 0;
1858 +
1859 + hdclk->hw.init = &init;
1860 +
1861 + hdclk->clk = devm_clk_register(dev, &hdclk->hw);
1862 + if (IS_ERR(hdclk->clk)) {
1863 + dev_err(dev, "unable to register %s\n", init.name);
1864 + return PTR_ERR(hdclk->clk);
1865 + }
1866 +
1867 + ret = of_clk_add_provider(dev_node, of_clk_src_simple_get, hdclk->clk);
1868 + if (ret != 0) {
1869 + dev_err(dev, "Cannot of_clk_add_provider");
1870 + return ret;
1871 + }
1872 +
1873 + ret = clk_set_rate(hdclk->hw.clk, DEFAULT_RATE);
1874 + if (ret != 0) {
1875 + dev_err(dev, "Cannot set rate : %d\n", ret);
1876 + return -EINVAL;
1877 + }
1878 +
1879 + return ret;
1880 +}
1881 +
1882 +static void clk_hifiberry_dachd_i2c_remove(struct i2c_client *i2c)
1883 +{
1884 + clk_hifiberry_dachd_remove(&i2c->dev);
1885 +}
1886 +
1887 +static const struct i2c_device_id clk_hifiberry_dachd_i2c_id[] = {
1888 + { "dachd-clk", },
1889 + { }
1890 +};
1891 +MODULE_DEVICE_TABLE(i2c, clk_hifiberry_dachd_i2c_id);
1892 +
1893 +static const struct of_device_id clk_hifiberry_dachd_of_match[] = {
1894 + { .compatible = "hifiberry,dachd-clk", },
1895 + { }
1896 +};
1897 +MODULE_DEVICE_TABLE(of, clk_hifiberry_dachd_of_match);
1898 +
1899 +static struct i2c_driver clk_hifiberry_dachd_i2c_driver = {
1900 + .probe = clk_hifiberry_dachd_i2c_probe,
1901 + .remove = clk_hifiberry_dachd_i2c_remove,
1902 + .id_table = clk_hifiberry_dachd_i2c_id,
1903 + .driver = {
1904 + .name = "dachd-clk",
1905 + .of_match_table = of_match_ptr(clk_hifiberry_dachd_of_match),
1906 + },
1907 +};
1908 +
1909 +module_i2c_driver(clk_hifiberry_dachd_i2c_driver);
1910 +
1911 +
1912 +MODULE_DESCRIPTION("HiFiBerry DAC+ HD clock driver");
1913 +MODULE_AUTHOR("Joerg Schambacher <joerg@i2audio.com>");
1914 +MODULE_LICENSE("GPL v2");
1915 +MODULE_ALIAS("platform:clk-hifiberry-dachd");
1916 --- /dev/null
1917 +++ b/drivers/clk/clk-hifiberry-dacpro.c
1918 @@ -0,0 +1,181 @@
1919 +/*
1920 + * Clock Driver for HiFiBerry DAC Pro
1921 + *
1922 + * Author: Stuart MacLean
1923 + * Copyright 2015
1924 + *
1925 + * This program is free software; you can redistribute it and/or
1926 + * modify it under the terms of the GNU General Public License
1927 + * version 2 as published by the Free Software Foundation.
1928 + *
1929 + * This program is distributed in the hope that it will be useful, but
1930 + * WITHOUT ANY WARRANTY; without even the implied warranty of
1931 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1932 + * General Public License for more details.
1933 + */
1934 +
1935 +#include <linux/clk-provider.h>
1936 +#include <linux/clkdev.h>
1937 +#include <linux/kernel.h>
1938 +#include <linux/module.h>
1939 +#include <linux/of.h>
1940 +#include <linux/slab.h>
1941 +#include <linux/platform_device.h>
1942 +
1943 +struct ext_clk_rates {
1944 + /* Clock rate of CLK44EN attached to GPIO6 pin */
1945 + unsigned long clk_44en;
1946 + /* Clock rate of CLK48EN attached to GPIO3 pin */
1947 + unsigned long clk_48en;
1948 +};
1949 +
1950 +/**
1951 + * struct hifiberry_dacpro_clk - Common struct to the HiFiBerry DAC Pro
1952 + * @hw: clk_hw for the common clk framework
1953 + * @mode: 0 => CLK44EN, 1 => CLK48EN
1954 + */
1955 +struct clk_hifiberry_hw {
1956 + struct clk_hw hw;
1957 + uint8_t mode;
1958 + struct ext_clk_rates clk_rates;
1959 +};
1960 +
1961 +#define to_hifiberry_clk(_hw) container_of(_hw, struct clk_hifiberry_hw, hw)
1962 +
1963 +static const struct ext_clk_rates hifiberry_dacpro_clks = {
1964 + .clk_44en = 22579200UL,
1965 + .clk_48en = 24576000UL,
1966 +};
1967 +
1968 +static const struct ext_clk_rates allo_dac_clks = {
1969 + .clk_44en = 45158400UL,
1970 + .clk_48en = 49152000UL,
1971 +};
1972 +
1973 +static const struct of_device_id clk_hifiberry_dacpro_dt_ids[] = {
1974 + { .compatible = "hifiberry,dacpro-clk", &hifiberry_dacpro_clks },
1975 + { .compatible = "allo,dac-clk", &allo_dac_clks },
1976 + { }
1977 +};
1978 +MODULE_DEVICE_TABLE(of, clk_hifiberry_dacpro_dt_ids);
1979 +
1980 +static unsigned long clk_hifiberry_dacpro_recalc_rate(struct clk_hw *hw,
1981 + unsigned long parent_rate)
1982 +{
1983 + struct clk_hifiberry_hw *clk = to_hifiberry_clk(hw);
1984 + return (clk->mode == 0) ? clk->clk_rates.clk_44en :
1985 + clk->clk_rates.clk_48en;
1986 +}
1987 +
1988 +static long clk_hifiberry_dacpro_round_rate(struct clk_hw *hw,
1989 + unsigned long rate, unsigned long *parent_rate)
1990 +{
1991 + struct clk_hifiberry_hw *clk = to_hifiberry_clk(hw);
1992 + long actual_rate;
1993 +
1994 + if (rate <= clk->clk_rates.clk_44en) {
1995 + actual_rate = (long)clk->clk_rates.clk_44en;
1996 + } else if (rate >= clk->clk_rates.clk_48en) {
1997 + actual_rate = (long)clk->clk_rates.clk_48en;
1998 + } else {
1999 + long diff44Rate = (long)(rate - clk->clk_rates.clk_44en);
2000 + long diff48Rate = (long)(clk->clk_rates.clk_48en - rate);
2001 +
2002 + if (diff44Rate < diff48Rate)
2003 + actual_rate = (long)clk->clk_rates.clk_44en;
2004 + else
2005 + actual_rate = (long)clk->clk_rates.clk_48en;
2006 + }
2007 + return actual_rate;
2008 +}
2009 +
2010 +
2011 +static int clk_hifiberry_dacpro_set_rate(struct clk_hw *hw,
2012 + unsigned long rate, unsigned long parent_rate)
2013 +{
2014 + struct clk_hifiberry_hw *clk = to_hifiberry_clk(hw);
2015 + unsigned long actual_rate;
2016 +
2017 + actual_rate = (unsigned long)clk_hifiberry_dacpro_round_rate(hw, rate,
2018 + &parent_rate);
2019 + clk->mode = (actual_rate == clk->clk_rates.clk_44en) ? 0 : 1;
2020 + return 0;
2021 +}
2022 +
2023 +
2024 +const struct clk_ops clk_hifiberry_dacpro_rate_ops = {
2025 + .recalc_rate = clk_hifiberry_dacpro_recalc_rate,
2026 + .round_rate = clk_hifiberry_dacpro_round_rate,
2027 + .set_rate = clk_hifiberry_dacpro_set_rate,
2028 +};
2029 +
2030 +static int clk_hifiberry_dacpro_probe(struct platform_device *pdev)
2031 +{
2032 + const struct of_device_id *of_id;
2033 + struct clk_hifiberry_hw *proclk;
2034 + struct clk *clk;
2035 + struct device *dev;
2036 + struct clk_init_data init;
2037 + int ret;
2038 +
2039 + dev = &pdev->dev;
2040 + of_id = of_match_node(clk_hifiberry_dacpro_dt_ids, dev->of_node);
2041 + if (!of_id)
2042 + return -EINVAL;
2043 +
2044 + proclk = kzalloc(sizeof(struct clk_hifiberry_hw), GFP_KERNEL);
2045 + if (!proclk)
2046 + return -ENOMEM;
2047 +
2048 + init.name = "clk-hifiberry-dacpro";
2049 + init.ops = &clk_hifiberry_dacpro_rate_ops;
2050 + init.flags = 0;
2051 + init.parent_names = NULL;
2052 + init.num_parents = 0;
2053 +
2054 + proclk->mode = 0;
2055 + proclk->hw.init = &init;
2056 + memcpy(&proclk->clk_rates, of_id->data, sizeof(proclk->clk_rates));
2057 +
2058 + clk = devm_clk_register(dev, &proclk->hw);
2059 + if (!IS_ERR(clk)) {
2060 + ret = of_clk_add_provider(dev->of_node, of_clk_src_simple_get,
2061 + clk);
2062 + } else {
2063 + dev_err(dev, "Fail to register clock driver\n");
2064 + kfree(proclk);
2065 + ret = PTR_ERR(clk);
2066 + }
2067 + return ret;
2068 +}
2069 +
2070 +static int clk_hifiberry_dacpro_remove(struct platform_device *pdev)
2071 +{
2072 + of_clk_del_provider(pdev->dev.of_node);
2073 + return 0;
2074 +}
2075 +
2076 +static struct platform_driver clk_hifiberry_dacpro_driver = {
2077 + .probe = clk_hifiberry_dacpro_probe,
2078 + .remove = clk_hifiberry_dacpro_remove,
2079 + .driver = {
2080 + .name = "clk-hifiberry-dacpro",
2081 + .of_match_table = clk_hifiberry_dacpro_dt_ids,
2082 + },
2083 +};
2084 +
2085 +static int __init clk_hifiberry_dacpro_init(void)
2086 +{
2087 + return platform_driver_register(&clk_hifiberry_dacpro_driver);
2088 +}
2089 +core_initcall(clk_hifiberry_dacpro_init);
2090 +
2091 +static void __exit clk_hifiberry_dacpro_exit(void)
2092 +{
2093 + platform_driver_unregister(&clk_hifiberry_dacpro_driver);
2094 +}
2095 +module_exit(clk_hifiberry_dacpro_exit);
2096 +
2097 +MODULE_DESCRIPTION("HiFiBerry DAC Pro clock driver");
2098 +MODULE_LICENSE("GPL v2");
2099 +MODULE_ALIAS("platform:clk-hifiberry-dacpro");
2100 --- a/sound/soc/bcm/Kconfig
2101 +++ b/sound/soc/bcm/Kconfig
2102 @@ -26,3 +26,309 @@ config SND_BCM63XX_I2S_WHISTLER
2103 DSL/PON chips (bcm63158, bcm63178)
2104
2105 If you don't know what to do here, say N
2106 +
2107 +config SND_BCM2708_SOC_CHIPDIP_DAC
2108 + tristate "Support for the ChipDip DAC"
2109 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2110 + help
2111 + Say Y or M if you want to add support for the ChipDip DAC soundcard
2112 +
2113 +config SND_BCM2708_SOC_GOOGLEVOICEHAT_SOUNDCARD
2114 + tristate "Support for Google voiceHAT soundcard"
2115 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2116 + select SND_SOC_VOICEHAT
2117 + select SND_RPI_SIMPLE_SOUNDCARD
2118 + help
2119 + Say Y or M if you want to add support for voiceHAT soundcard.
2120 +
2121 +config SND_BCM2708_SOC_HIFIBERRY_DAC
2122 + tristate "Support for HifiBerry DAC"
2123 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2124 + select SND_SOC_PCM5102A
2125 + select SND_RPI_SIMPLE_SOUNDCARD
2126 + help
2127 + Say Y or M if you want to add support for HifiBerry DAC.
2128 +
2129 +config SND_BCM2708_SOC_HIFIBERRY_DACPLUS
2130 + tristate "Support for HifiBerry DAC+"
2131 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2132 + select SND_SOC_PCM512x
2133 + select SND_SOC_TPA6130A2
2134 + select COMMON_CLK_HIFIBERRY_DACPRO
2135 + help
2136 + Say Y or M if you want to add support for HifiBerry DAC+.
2137 +
2138 +config SND_BCM2708_SOC_HIFIBERRY_DACPLUSHD
2139 + tristate "Support for HifiBerry DAC+ HD"
2140 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2141 + select SND_SOC_PCM179X_I2C
2142 + select COMMON_CLK_HIFIBERRY_DACPLUSHD
2143 + help
2144 + Say Y or M if you want to add support for HifiBerry DAC+ HD.
2145 +
2146 +config SND_BCM2708_SOC_HIFIBERRY_DACPLUSADC
2147 + tristate "Support for HifiBerry DAC+ADC"
2148 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2149 + select SND_SOC_PCM512x_I2C
2150 + select SND_SOC_DMIC
2151 + select COMMON_CLK_HIFIBERRY_DACPRO
2152 + help
2153 + Say Y or M if you want to add support for HifiBerry DAC+ADC.
2154 +
2155 +config SND_BCM2708_SOC_HIFIBERRY_DACPLUSADCPRO
2156 + tristate "Support for HifiBerry DAC+ADC PRO"
2157 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2158 + select SND_SOC_PCM512x_I2C
2159 + select SND_SOC_PCM186X_I2C
2160 + select SND_SOC_TPA6130A2
2161 + select COMMON_CLK_HIFIBERRY_DACPRO
2162 + help
2163 + Say Y or M if you want to add support for HifiBerry DAC+ADC PRO.
2164 +
2165 +config SND_BCM2708_SOC_HIFIBERRY_DACPLUSDSP
2166 + tristate "Support for HifiBerry DAC+DSP"
2167 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2168 + select SND_RPI_SIMPLE_SOUNDCARD
2169 + help
2170 + Say Y or M if you want to add support for HifiBerry DSP-DAC.
2171 +
2172 +config SND_BCM2708_SOC_HIFIBERRY_DIGI
2173 + tristate "Support for HifiBerry Digi"
2174 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2175 + select SND_SOC_WM8804
2176 + help
2177 + Say Y or M if you want to add support for HifiBerry Digi S/PDIF output board.
2178 +
2179 +config SND_BCM2708_SOC_HIFIBERRY_AMP
2180 + tristate "Support for the HifiBerry Amp"
2181 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2182 + select SND_SOC_TAS5713
2183 + select SND_RPI_SIMPLE_SOUNDCARD
2184 + help
2185 + Say Y or M if you want to add support for the HifiBerry Amp amplifier board.
2186 +
2187 + config SND_BCM2708_SOC_PIFI_40
2188 + tristate "Support for the PiFi-40 amp"
2189 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2190 + select SND_SOC_TAS571X
2191 + select SND_PIFI_40
2192 + help
2193 + Say Y or M if you want to add support for the PiFi40 amp board
2194 +
2195 +config SND_BCM2708_SOC_RPI_CIRRUS
2196 + tristate "Support for Cirrus Logic Audio Card"
2197 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2198 + select SND_SOC_WM5102
2199 + select SND_SOC_WM8804
2200 + help
2201 + Say Y or M if you want to add support for the Wolfson and
2202 + Cirrus Logic audio cards.
2203 +
2204 +config SND_BCM2708_SOC_RPI_DAC
2205 + tristate "Support for RPi-DAC"
2206 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2207 + select SND_SOC_PCM1794A
2208 + select SND_RPI_SIMPLE_SOUNDCARD
2209 + help
2210 + Say Y or M if you want to add support for RPi-DAC.
2211 +
2212 +config SND_BCM2708_SOC_RPI_PROTO
2213 + tristate "Support for Rpi-PROTO"
2214 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2215 + select SND_SOC_WM8731_I2C
2216 + help
2217 + Say Y or M if you want to add support for Audio Codec Board PROTO (WM8731).
2218 +
2219 +config SND_BCM2708_SOC_JUSTBOOM_BOTH
2220 + tristate "Support for simultaneous JustBoom Digi and JustBoom DAC"
2221 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2222 + select SND_SOC_WM8804
2223 + select SND_SOC_PCM512x
2224 + help
2225 + Say Y or M if you want to add support for simultaneous
2226 + JustBoom Digi and JustBoom DAC.
2227 +
2228 + This is not the right choice if you only have one but both of
2229 + these cards.
2230 +
2231 +config SND_BCM2708_SOC_JUSTBOOM_DAC
2232 + tristate "Support for JustBoom DAC"
2233 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2234 + select SND_SOC_PCM512x
2235 + help
2236 + Say Y or M if you want to add support for JustBoom DAC.
2237 +
2238 +config SND_BCM2708_SOC_JUSTBOOM_DIGI
2239 + tristate "Support for JustBoom Digi"
2240 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2241 + select SND_SOC_WM8804
2242 + select SND_RPI_WM8804_SOUNDCARD
2243 + help
2244 + Say Y or M if you want to add support for JustBoom Digi.
2245 +
2246 +config SND_BCM2708_SOC_IQAUDIO_CODEC
2247 + tristate "Support for IQaudIO-CODEC"
2248 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2249 + select SND_SOC_DA7213
2250 + help
2251 + Say Y or M if you want to add support for IQaudIO-CODEC.
2252 +
2253 +config SND_BCM2708_SOC_IQAUDIO_DAC
2254 + tristate "Support for IQaudIO-DAC"
2255 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2256 + select SND_SOC_PCM512x_I2C
2257 + help
2258 + Say Y or M if you want to add support for IQaudIO-DAC.
2259 +
2260 +config SND_BCM2708_SOC_IQAUDIO_DIGI
2261 + tristate "Support for IQAudIO Digi"
2262 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2263 + select SND_SOC_WM8804
2264 + select SND_RPI_WM8804_SOUNDCARD
2265 + help
2266 + Say Y or M if you want to add support for IQAudIO Digital IO board.
2267 +
2268 +config SND_BCM2708_SOC_I_SABRE_Q2M
2269 + tristate "Support for Audiophonics I-Sabre Q2M DAC"
2270 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2271 + select SND_SOC_I_SABRE_CODEC
2272 + help
2273 + Say Y or M if you want to add support for Audiophonics I-SABRE Q2M DAC
2274 +
2275 +config SND_BCM2708_SOC_ADAU1977_ADC
2276 + tristate "Support for ADAU1977 ADC"
2277 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2278 + select SND_SOC_ADAU1977_I2C
2279 + select SND_RPI_SIMPLE_SOUNDCARD
2280 + help
2281 + Say Y or M if you want to add support for ADAU1977 ADC.
2282 +
2283 +config SND_AUDIOINJECTOR_PI_SOUNDCARD
2284 + tristate "Support for audioinjector.net Pi add on soundcard"
2285 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2286 + select SND_SOC_WM8731_I2C
2287 + help
2288 + Say Y or M if you want to add support for audioinjector.net Pi Hat
2289 +
2290 +config SND_AUDIOINJECTOR_OCTO_SOUNDCARD
2291 + tristate "Support for audioinjector.net Octo channel (Hat) soundcard"
2292 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2293 + select SND_SOC_CS42XX8_I2C
2294 + help
2295 + Say Y or M if you want to add support for audioinjector.net octo add on
2296 +
2297 +config SND_AUDIOINJECTOR_ISOLATED_SOUNDCARD
2298 + tristate "Support for audioinjector.net isolated DAC and ADC soundcard"
2299 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2300 + select SND_SOC_CS4271_I2C
2301 + help
2302 + Say Y or M if you want to add support for audioinjector.net isolated soundcard
2303 +
2304 +config SND_AUDIOSENSE_PI
2305 + tristate "Support for AudioSense Add-On Soundcard"
2306 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2307 + select SND_SOC_TLV320AIC32X4_I2C
2308 + help
2309 + Say Y or M if you want to add support for tlv320aic32x4 add-on
2310 +
2311 +config SND_DIGIDAC1_SOUNDCARD
2312 + tristate "Support for Red Rocks Audio DigiDAC1"
2313 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2314 + select SND_SOC_WM8804
2315 + select SND_SOC_WM8741
2316 + help
2317 + Say Y or M if you want to add support for Red Rocks Audio DigiDAC1 board.
2318 +
2319 +config SND_BCM2708_SOC_DIONAUDIO_LOCO
2320 + tristate "Support for Dion Audio LOCO DAC-AMP"
2321 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2322 + select SND_SOC_PCM5102a
2323 + help
2324 + Say Y or M if you want to add support for Dion Audio LOCO.
2325 +
2326 +config SND_BCM2708_SOC_DIONAUDIO_LOCO_V2
2327 + tristate "Support for Dion Audio LOCO-V2 DAC-AMP"
2328 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2329 + select SND_SOC_PCM5122
2330 + help
2331 + Say Y or M if you want to add support for Dion Audio LOCO-V2.
2332 +
2333 +config SND_BCM2708_SOC_ALLO_PIANO_DAC
2334 + tristate "Support for Allo Piano DAC"
2335 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2336 + select SND_SOC_PCM512x_I2C
2337 + help
2338 + Say Y or M if you want to add support for Allo Piano DAC.
2339 +
2340 +config SND_BCM2708_SOC_ALLO_PIANO_DAC_PLUS
2341 + tristate "Support for Allo Piano DAC Plus"
2342 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2343 + select SND_SOC_PCM512x_I2C
2344 + help
2345 + Say Y or M if you want to add support for Allo Piano DAC Plus.
2346 +
2347 +config SND_BCM2708_SOC_ALLO_BOSS_DAC
2348 + tristate "Support for Allo Boss DAC"
2349 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2350 + select SND_SOC_PCM512x_I2C
2351 + select COMMON_CLK_HIFIBERRY_DACPRO
2352 + help
2353 + Say Y or M if you want to add support for Allo Boss DAC.
2354 +
2355 +config SND_BCM2708_SOC_ALLO_BOSS2_DAC
2356 + tristate "Support for Allo Boss2 DAC"
2357 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2358 + depends on I2C
2359 + select REGMAP_I2C
2360 + select SND_AUDIO_GRAPH_CARD
2361 + help
2362 + Say Y or M if you want to add support for Allo Boss2 DAC.
2363 +
2364 +config SND_BCM2708_SOC_ALLO_DIGIONE
2365 + tristate "Support for Allo DigiOne"
2366 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2367 + select SND_SOC_WM8804
2368 + select SND_RPI_WM8804_SOUNDCARD
2369 + help
2370 + Say Y or M if you want to add support for Allo DigiOne.
2371 +
2372 +config SND_BCM2708_SOC_ALLO_KATANA_DAC
2373 + tristate "Support for Allo Katana DAC"
2374 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2375 + depends on I2C
2376 + select REGMAP_I2C
2377 + select SND_AUDIO_GRAPH_CARD
2378 + help
2379 + Say Y or M if you want to add support for Allo Katana DAC.
2380 +
2381 +config SND_BCM2708_SOC_FE_PI_AUDIO
2382 + tristate "Support for Fe-Pi-Audio"
2383 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2384 + select SND_SOC_SGTL5000
2385 + help
2386 + Say Y or M if you want to add support for Fe-Pi-Audio.
2387 +
2388 +config SND_PISOUND
2389 + tristate "Support for Blokas Labs pisound"
2390 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2391 + select SND_RAWMIDI
2392 + help
2393 + Say Y or M if you want to add support for Blokas Labs pisound.
2394 +
2395 +config SND_RPI_SIMPLE_SOUNDCARD
2396 + tristate "Support for Raspberry Pi simple soundcards"
2397 + help
2398 + Say Y or M if you want to add support Raspbery Pi simple soundcards
2399 +
2400 +config SND_RPI_WM8804_SOUNDCARD
2401 + tristate "Support for Raspberry Pi generic WM8804 soundcards"
2402 + help
2403 + Say Y or M if you want to add support for the Raspberry Pi
2404 + generic driver for WM8804 based soundcards.
2405 +
2406 +config SND_DACBERRY400
2407 + tristate "Support for DACBERRY400 Soundcard"
2408 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2409 + select SND_SOC_TLV320AIC3X_I2C
2410 + help
2411 + Say Y or M if you want to add support for tlv320aic3x add-on
2412 --- a/sound/soc/bcm/Makefile
2413 +++ b/sound/soc/bcm/Makefile
2414 @@ -12,4 +12,73 @@ obj-$(CONFIG_SND_SOC_CYGNUS) += snd-soc-
2415 # BCM63XX Platform Support
2416 snd-soc-63xx-objs := bcm63xx-i2s-whistler.o bcm63xx-pcm-whistler.o
2417
2418 -obj-$(CONFIG_SND_BCM63XX_I2S_WHISTLER) += snd-soc-63xx.o
2419 \ No newline at end of file
2420 +obj-$(CONFIG_SND_BCM63XX_I2S_WHISTLER) += snd-soc-63xx.o
2421 +
2422 +# Google voiceHAT custom codec support
2423 +snd-soc-googlevoicehat-codec-objs := googlevoicehat-codec.o
2424 +
2425 +# BCM2708 Machine Support
2426 +snd-soc-hifiberry-dacplus-objs := hifiberry_dacplus.o
2427 +snd-soc-hifiberry-dacplushd-objs := hifiberry_dacplushd.o
2428 +snd-soc-hifiberry-dacplusadc-objs := hifiberry_dacplusadc.o
2429 +snd-soc-hifiberry-dacplusadcpro-objs := hifiberry_dacplusadcpro.o
2430 +snd-soc-hifiberry-dacplusdsp-objs := hifiberry_dacplusdsp.o
2431 +snd-soc-justboom-both-objs := justboom-both.o
2432 +snd-soc-justboom-dac-objs := justboom-dac.o
2433 +snd-soc-rpi-cirrus-objs := rpi-cirrus.o
2434 +snd-soc-rpi-proto-objs := rpi-proto.o
2435 +snd-soc-iqaudio-codec-objs := iqaudio-codec.o
2436 +snd-soc-iqaudio-dac-objs := iqaudio-dac.o
2437 + snd-soc-i-sabre-q2m-objs := i-sabre-q2m.o
2438 +snd-soc-audioinjector-pi-soundcard-objs := audioinjector-pi-soundcard.o
2439 +snd-soc-audioinjector-octo-soundcard-objs := audioinjector-octo-soundcard.o
2440 +snd-soc-audioinjector-isolated-soundcard-objs := audioinjector-isolated-soundcard.o
2441 +snd-soc-audiosense-pi-objs := audiosense-pi.o
2442 +snd-soc-digidac1-soundcard-objs := digidac1-soundcard.o
2443 +snd-soc-dionaudio-loco-objs := dionaudio_loco.o
2444 +snd-soc-dionaudio-loco-v2-objs := dionaudio_loco-v2.o
2445 +snd-soc-allo-boss-dac-objs := allo-boss-dac.o
2446 +snd-soc-allo-boss2-dac-objs := allo-boss2-dac.o
2447 +snd-soc-allo-piano-dac-objs := allo-piano-dac.o
2448 +snd-soc-allo-piano-dac-plus-objs := allo-piano-dac-plus.o
2449 +snd-soc-allo-katana-codec-objs := allo-katana-codec.o
2450 +snd-soc-pisound-objs := pisound.o
2451 +snd-soc-fe-pi-audio-objs := fe-pi-audio.o
2452 +snd-soc-rpi-simple-soundcard-objs := rpi-simple-soundcard.o
2453 +snd-soc-rpi-wm8804-soundcard-objs := rpi-wm8804-soundcard.o
2454 +snd-soc-pifi-40-objs := pifi-40.o
2455 +snd-soc-chipdip-dac-objs := chipdip-dac.o
2456 +snd-soc-dacberry400-objs := dacberry400.o
2457 +
2458 +obj-$(CONFIG_SND_BCM2708_SOC_GOOGLEVOICEHAT_SOUNDCARD) += snd-soc-googlevoicehat-codec.o
2459 +obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS) += snd-soc-hifiberry-dacplus.o
2460 +obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUSHD) += snd-soc-hifiberry-dacplushd.o
2461 +obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUSADC) += snd-soc-hifiberry-dacplusadc.o
2462 +obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUSADCPRO) += snd-soc-hifiberry-dacplusadcpro.o
2463 +obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUSDSP) += snd-soc-hifiberry-dacplusdsp.o
2464 +obj-$(CONFIG_SND_BCM2708_SOC_JUSTBOOM_BOTH) += snd-soc-justboom-both.o
2465 +obj-$(CONFIG_SND_BCM2708_SOC_JUSTBOOM_DAC) += snd-soc-justboom-dac.o
2466 +obj-$(CONFIG_SND_BCM2708_SOC_RPI_CIRRUS) += snd-soc-rpi-cirrus.o
2467 +obj-$(CONFIG_SND_BCM2708_SOC_RPI_PROTO) += snd-soc-rpi-proto.o
2468 +obj-$(CONFIG_SND_BCM2708_SOC_IQAUDIO_CODEC) += snd-soc-iqaudio-codec.o
2469 +obj-$(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) += snd-soc-iqaudio-dac.o
2470 +obj-$(CONFIG_SND_BCM2708_SOC_I_SABRE_Q2M) += snd-soc-i-sabre-q2m.o
2471 +obj-$(CONFIG_SND_AUDIOINJECTOR_PI_SOUNDCARD) += snd-soc-audioinjector-pi-soundcard.o
2472 +obj-$(CONFIG_SND_AUDIOINJECTOR_OCTO_SOUNDCARD) += snd-soc-audioinjector-octo-soundcard.o
2473 +obj-$(CONFIG_SND_AUDIOINJECTOR_ISOLATED_SOUNDCARD) += snd-soc-audioinjector-isolated-soundcard.o
2474 +obj-$(CONFIG_SND_AUDIOSENSE_PI) += snd-soc-audiosense-pi.o
2475 +obj-$(CONFIG_SND_DIGIDAC1_SOUNDCARD) += snd-soc-digidac1-soundcard.o
2476 +obj-$(CONFIG_SND_BCM2708_SOC_DIONAUDIO_LOCO) += snd-soc-dionaudio-loco.o
2477 +obj-$(CONFIG_SND_BCM2708_SOC_DIONAUDIO_LOCO_V2) += snd-soc-dionaudio-loco-v2.o
2478 +obj-$(CONFIG_SND_BCM2708_SOC_ALLO_BOSS_DAC) += snd-soc-allo-boss-dac.o
2479 +obj-$(CONFIG_SND_BCM2708_SOC_ALLO_BOSS2_DAC) += snd-soc-allo-boss2-dac.o
2480 +obj-$(CONFIG_SND_BCM2708_SOC_ALLO_PIANO_DAC) += snd-soc-allo-piano-dac.o
2481 +obj-$(CONFIG_SND_BCM2708_SOC_ALLO_PIANO_DAC_PLUS) += snd-soc-allo-piano-dac-plus.o
2482 +obj-$(CONFIG_SND_BCM2708_SOC_ALLO_KATANA_DAC) += snd-soc-allo-katana-codec.o
2483 +obj-$(CONFIG_SND_PISOUND) += snd-soc-pisound.o
2484 +obj-$(CONFIG_SND_BCM2708_SOC_FE_PI_AUDIO) += snd-soc-fe-pi-audio.o
2485 +obj-$(CONFIG_SND_RPI_SIMPLE_SOUNDCARD) += snd-soc-rpi-simple-soundcard.o
2486 +obj-$(CONFIG_SND_RPI_WM8804_SOUNDCARD) += snd-soc-rpi-wm8804-soundcard.o
2487 +obj-$(CONFIG_SND_BCM2708_SOC_PIFI_40) += snd-soc-pifi-40.o
2488 +obj-$(CONFIG_SND_BCM2708_SOC_CHIPDIP_DAC) += snd-soc-chipdip-dac.o
2489 +obj-$(CONFIG_SND_DACBERRY400) += snd-soc-dacberry400.o
2490 --- /dev/null
2491 +++ b/sound/soc/bcm/allo-boss-dac.c
2492 @@ -0,0 +1,457 @@
2493 +/*
2494 + * ALSA ASoC Machine Driver for Allo Boss DAC
2495 + *
2496 + * Author: Baswaraj K <jaikumar@cem-solutions.net>
2497 + * Copyright 2017
2498 + * based on code by Daniel Matuschek,
2499 + * Stuart MacLean <stuart@hifiberry.com>
2500 + * based on code by Florian Meier <florian.meier@koalo.de>
2501 + *
2502 + * This program is free software; you can redistribute it and/or
2503 + * modify it under the terms of the GNU General Public License
2504 + * version 2 as published by the Free Software Foundation.
2505 + *
2506 + * This program is distributed in the hope that it will be useful, but
2507 + * WITHOUT ANY WARRANTY; without even the implied warranty of
2508 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2509 + * General Public License for more details.
2510 + */
2511 +
2512 +#include <linux/module.h>
2513 +#include <linux/gpio/consumer.h>
2514 +#include <linux/platform_device.h>
2515 +#include <linux/clk.h>
2516 +#include <linux/delay.h>
2517 +
2518 +#include <sound/core.h>
2519 +#include <sound/pcm.h>
2520 +#include <sound/pcm_params.h>
2521 +#include <sound/soc.h>
2522 +#include "../codecs/pcm512x.h"
2523 +
2524 +#define ALLO_BOSS_NOCLOCK 0
2525 +#define ALLO_BOSS_CLK44EN 1
2526 +#define ALLO_BOSS_CLK48EN 2
2527 +
2528 +struct pcm512x_priv {
2529 + struct regmap *regmap;
2530 + struct clk *sclk;
2531 +};
2532 +
2533 +static struct gpio_desc *mute_gpio;
2534 +
2535 +/* Clock rate of CLK44EN attached to GPIO6 pin */
2536 +#define CLK_44EN_RATE 45158400UL
2537 +/* Clock rate of CLK48EN attached to GPIO3 pin */
2538 +#define CLK_48EN_RATE 49152000UL
2539 +
2540 +static bool slave;
2541 +static bool snd_soc_allo_boss_master;
2542 +static bool digital_gain_0db_limit = true;
2543 +
2544 +static void snd_allo_boss_select_clk(struct snd_soc_component *component,
2545 + int clk_id)
2546 +{
2547 + switch (clk_id) {
2548 + case ALLO_BOSS_NOCLOCK:
2549 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x24, 0x00);
2550 + break;
2551 + case ALLO_BOSS_CLK44EN:
2552 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x24, 0x20);
2553 + break;
2554 + case ALLO_BOSS_CLK48EN:
2555 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x24, 0x04);
2556 + break;
2557 + }
2558 +}
2559 +
2560 +static void snd_allo_boss_clk_gpio(struct snd_soc_component *component)
2561 +{
2562 + snd_soc_component_update_bits(component, PCM512x_GPIO_EN, 0x24, 0x24);
2563 + snd_soc_component_update_bits(component, PCM512x_GPIO_OUTPUT_3, 0x0f, 0x02);
2564 + snd_soc_component_update_bits(component, PCM512x_GPIO_OUTPUT_6, 0x0f, 0x02);
2565 +}
2566 +
2567 +static bool snd_allo_boss_is_sclk(struct snd_soc_component *component)
2568 +{
2569 + unsigned int sck;
2570 +
2571 + sck = snd_soc_component_read(component, PCM512x_RATE_DET_4);
2572 + return (!(sck & 0x40));
2573 +}
2574 +
2575 +static bool snd_allo_boss_is_sclk_sleep(
2576 + struct snd_soc_component *component)
2577 +{
2578 + msleep(2);
2579 + return snd_allo_boss_is_sclk(component);
2580 +}
2581 +
2582 +static bool snd_allo_boss_is_master_card(struct snd_soc_component *component)
2583 +{
2584 + bool isClk44EN, isClk48En, isNoClk;
2585 +
2586 + snd_allo_boss_clk_gpio(component);
2587 +
2588 + snd_allo_boss_select_clk(component, ALLO_BOSS_CLK44EN);
2589 + isClk44EN = snd_allo_boss_is_sclk_sleep(component);
2590 +
2591 + snd_allo_boss_select_clk(component, ALLO_BOSS_NOCLOCK);
2592 + isNoClk = snd_allo_boss_is_sclk_sleep(component);
2593 +
2594 + snd_allo_boss_select_clk(component, ALLO_BOSS_CLK48EN);
2595 + isClk48En = snd_allo_boss_is_sclk_sleep(component);
2596 +
2597 + return (isClk44EN && isClk48En && !isNoClk);
2598 +}
2599 +
2600 +static int snd_allo_boss_clk_for_rate(int sample_rate)
2601 +{
2602 + int type;
2603 +
2604 + switch (sample_rate) {
2605 + case 11025:
2606 + case 22050:
2607 + case 44100:
2608 + case 88200:
2609 + case 176400:
2610 + case 352800:
2611 + type = ALLO_BOSS_CLK44EN;
2612 + break;
2613 + default:
2614 + type = ALLO_BOSS_CLK48EN;
2615 + break;
2616 + }
2617 + return type;
2618 +}
2619 +
2620 +static void snd_allo_boss_set_sclk(struct snd_soc_component *component,
2621 + int sample_rate)
2622 +{
2623 + struct pcm512x_priv *pcm512x = snd_soc_component_get_drvdata(component);
2624 +
2625 + if (!IS_ERR(pcm512x->sclk)) {
2626 + int ctype;
2627 +
2628 + ctype = snd_allo_boss_clk_for_rate(sample_rate);
2629 + clk_set_rate(pcm512x->sclk, (ctype == ALLO_BOSS_CLK44EN)
2630 + ? CLK_44EN_RATE : CLK_48EN_RATE);
2631 + snd_allo_boss_select_clk(component, ctype);
2632 + }
2633 +}
2634 +
2635 +static int snd_allo_boss_init(struct snd_soc_pcm_runtime *rtd)
2636 +{
2637 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
2638 + struct pcm512x_priv *priv = snd_soc_component_get_drvdata(component);
2639 +
2640 + if (slave)
2641 + snd_soc_allo_boss_master = false;
2642 + else
2643 + snd_soc_allo_boss_master =
2644 + snd_allo_boss_is_master_card(component);
2645 +
2646 + if (snd_soc_allo_boss_master) {
2647 + struct snd_soc_dai_link *dai = rtd->dai_link;
2648 +
2649 + dai->name = "BossDAC";
2650 + dai->stream_name = "Boss DAC HiFi [Master]";
2651 + dai->dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
2652 + | SND_SOC_DAIFMT_CBM_CFM;
2653 +
2654 + snd_soc_component_update_bits(component, PCM512x_BCLK_LRCLK_CFG, 0x31, 0x11);
2655 + snd_soc_component_update_bits(component, PCM512x_MASTER_MODE, 0x03, 0x03);
2656 + snd_soc_component_update_bits(component, PCM512x_MASTER_CLKDIV_2, 0x7f, 63);
2657 + /*
2658 + * Default sclk to CLK_48EN_RATE, otherwise codec
2659 + * pcm512x_dai_startup_master method could call
2660 + * snd_pcm_hw_constraint_ratnums using CLK_44EN/64
2661 + * which will mask 384k sample rate.
2662 + */
2663 + if (!IS_ERR(priv->sclk))
2664 + clk_set_rate(priv->sclk, CLK_48EN_RATE);
2665 + } else {
2666 + priv->sclk = ERR_PTR(-ENOENT);
2667 + }
2668 +
2669 + snd_soc_component_update_bits(component, PCM512x_GPIO_EN, 0x08, 0x08);
2670 + snd_soc_component_update_bits(component, PCM512x_GPIO_OUTPUT_4, 0x0f, 0x02);
2671 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x08, 0x08);
2672 +
2673 + if (digital_gain_0db_limit) {
2674 + int ret;
2675 + struct snd_soc_card *card = rtd->card;
2676 +
2677 + ret = snd_soc_limit_volume(card, "Digital Playback Volume",
2678 + 207);
2679 + if (ret < 0)
2680 + dev_warn(card->dev, "Failed to set volume limit: %d\n",
2681 + ret);
2682 + }
2683 +
2684 + return 0;
2685 +}
2686 +
2687 +static int snd_allo_boss_update_rate_den(
2688 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
2689 +{
2690 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
2691 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
2692 + struct pcm512x_priv *pcm512x = snd_soc_component_get_drvdata(component);
2693 + struct snd_ratnum *rats_no_pll;
2694 + unsigned int num = 0, den = 0;
2695 + int err;
2696 +
2697 + rats_no_pll = devm_kzalloc(rtd->dev, sizeof(*rats_no_pll), GFP_KERNEL);
2698 + if (!rats_no_pll)
2699 + return -ENOMEM;
2700 +
2701 + rats_no_pll->num = clk_get_rate(pcm512x->sclk) / 64;
2702 + rats_no_pll->den_min = 1;
2703 + rats_no_pll->den_max = 128;
2704 + rats_no_pll->den_step = 1;
2705 +
2706 + err = snd_interval_ratnum(hw_param_interval(params,
2707 + SNDRV_PCM_HW_PARAM_RATE), 1, rats_no_pll, &num, &den);
2708 + if (err >= 0 && den) {
2709 + params->rate_num = num;
2710 + params->rate_den = den;
2711 + }
2712 +
2713 + devm_kfree(rtd->dev, rats_no_pll);
2714 + return 0;
2715 +}
2716 +
2717 +static void snd_allo_boss_gpio_mute(struct snd_soc_card *card)
2718 +{
2719 + if (mute_gpio)
2720 + gpiod_set_value_cansleep(mute_gpio, 1);
2721 +}
2722 +
2723 +static void snd_allo_boss_gpio_unmute(struct snd_soc_card *card)
2724 +{
2725 + if (mute_gpio)
2726 + gpiod_set_value_cansleep(mute_gpio, 0);
2727 +}
2728 +
2729 +static int snd_allo_boss_set_bias_level(struct snd_soc_card *card,
2730 + struct snd_soc_dapm_context *dapm, enum snd_soc_bias_level level)
2731 +{
2732 + struct snd_soc_pcm_runtime *rtd;
2733 + struct snd_soc_dai *codec_dai;
2734 +
2735 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
2736 + codec_dai = asoc_rtd_to_codec(rtd, 0);
2737 +
2738 + if (dapm->dev != codec_dai->dev)
2739 + return 0;
2740 +
2741 + switch (level) {
2742 + case SND_SOC_BIAS_PREPARE:
2743 + if (dapm->bias_level != SND_SOC_BIAS_STANDBY)
2744 + break;
2745 + /* UNMUTE DAC */
2746 + snd_allo_boss_gpio_unmute(card);
2747 + break;
2748 +
2749 + case SND_SOC_BIAS_STANDBY:
2750 + if (dapm->bias_level != SND_SOC_BIAS_PREPARE)
2751 + break;
2752 + /* MUTE DAC */
2753 + snd_allo_boss_gpio_mute(card);
2754 + break;
2755 +
2756 + default:
2757 + break;
2758 + }
2759 +
2760 + return 0;
2761 +}
2762 +
2763 +static int snd_allo_boss_hw_params(
2764 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
2765 +{
2766 + int ret = 0;
2767 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
2768 + int channels = params_channels(params);
2769 + int width = snd_pcm_format_physical_width(params_format(params));
2770 +
2771 + if (snd_soc_allo_boss_master) {
2772 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
2773 +
2774 + snd_allo_boss_set_sclk(component,
2775 + params_rate(params));
2776 +
2777 + ret = snd_allo_boss_update_rate_den(
2778 + substream, params);
2779 + if (ret)
2780 + return ret;
2781 + }
2782 +
2783 + ret = snd_soc_dai_set_bclk_ratio(asoc_rtd_to_cpu(rtd, 0), channels * width);
2784 + if (ret)
2785 + return ret;
2786 + ret = snd_soc_dai_set_bclk_ratio(asoc_rtd_to_codec(rtd, 0), channels * width);
2787 + return ret;
2788 +}
2789 +
2790 +static int snd_allo_boss_startup(
2791 + struct snd_pcm_substream *substream)
2792 +{
2793 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
2794 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
2795 + struct snd_soc_card *card = rtd->card;
2796 +
2797 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x08, 0x08);
2798 + snd_allo_boss_gpio_mute(card);
2799 +
2800 + if (snd_soc_allo_boss_master) {
2801 + struct pcm512x_priv *priv = snd_soc_component_get_drvdata(component);
2802 + /*
2803 + * Default sclk to CLK_48EN_RATE, otherwise codec
2804 + * pcm512x_dai_startup_master method could call
2805 + * snd_pcm_hw_constraint_ratnums using CLK_44EN/64
2806 + * which will mask 384k sample rate.
2807 + */
2808 + if (!IS_ERR(priv->sclk))
2809 + clk_set_rate(priv->sclk, CLK_48EN_RATE);
2810 + }
2811 +
2812 + return 0;
2813 +}
2814 +
2815 +static void snd_allo_boss_shutdown(
2816 + struct snd_pcm_substream *substream)
2817 +{
2818 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
2819 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
2820 +
2821 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x08, 0x00);
2822 +}
2823 +
2824 +static int snd_allo_boss_prepare(
2825 + struct snd_pcm_substream *substream)
2826 +{
2827 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
2828 + struct snd_soc_card *card = rtd->card;
2829 +
2830 + snd_allo_boss_gpio_unmute(card);
2831 + return 0;
2832 +}
2833 +/* machine stream operations */
2834 +static struct snd_soc_ops snd_allo_boss_ops = {
2835 + .hw_params = snd_allo_boss_hw_params,
2836 + .startup = snd_allo_boss_startup,
2837 + .shutdown = snd_allo_boss_shutdown,
2838 + .prepare = snd_allo_boss_prepare,
2839 +};
2840 +
2841 +SND_SOC_DAILINK_DEFS(allo_boss,
2842 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
2843 + DAILINK_COMP_ARRAY(COMP_CODEC("pcm512x.1-004d", "pcm512x-hifi")),
2844 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
2845 +
2846 +static struct snd_soc_dai_link snd_allo_boss_dai[] = {
2847 +{
2848 + .name = "Boss DAC",
2849 + .stream_name = "Boss DAC HiFi",
2850 + .dai_fmt = SND_SOC_DAIFMT_I2S |
2851 + SND_SOC_DAIFMT_NB_NF |
2852 + SND_SOC_DAIFMT_CBS_CFS,
2853 + .ops = &snd_allo_boss_ops,
2854 + .init = snd_allo_boss_init,
2855 + SND_SOC_DAILINK_REG(allo_boss),
2856 +},
2857 +};
2858 +
2859 +/* audio machine driver */
2860 +static struct snd_soc_card snd_allo_boss = {
2861 + .name = "BossDAC",
2862 + .owner = THIS_MODULE,
2863 + .dai_link = snd_allo_boss_dai,
2864 + .num_links = ARRAY_SIZE(snd_allo_boss_dai),
2865 +};
2866 +
2867 +static int snd_allo_boss_probe(struct platform_device *pdev)
2868 +{
2869 + int ret = 0;
2870 +
2871 + snd_allo_boss.dev = &pdev->dev;
2872 +
2873 + if (pdev->dev.of_node) {
2874 + struct device_node *i2s_node;
2875 + struct snd_soc_dai_link *dai;
2876 +
2877 + dai = &snd_allo_boss_dai[0];
2878 + i2s_node = of_parse_phandle(pdev->dev.of_node,
2879 + "i2s-controller", 0);
2880 +
2881 + if (i2s_node) {
2882 + dai->cpus->dai_name = NULL;
2883 + dai->cpus->of_node = i2s_node;
2884 + dai->platforms->name = NULL;
2885 + dai->platforms->of_node = i2s_node;
2886 + }
2887 +
2888 + digital_gain_0db_limit = !of_property_read_bool(
2889 + pdev->dev.of_node, "allo,24db_digital_gain");
2890 + slave = of_property_read_bool(pdev->dev.of_node,
2891 + "allo,slave");
2892 +
2893 + mute_gpio = devm_gpiod_get_optional(&pdev->dev, "mute",
2894 + GPIOD_OUT_LOW);
2895 + if (IS_ERR(mute_gpio)) {
2896 + ret = PTR_ERR(mute_gpio);
2897 + dev_err(&pdev->dev,
2898 + "failed to get mute gpio: %d\n", ret);
2899 + return ret;
2900 + }
2901 +
2902 + if (mute_gpio)
2903 + snd_allo_boss.set_bias_level =
2904 + snd_allo_boss_set_bias_level;
2905 +
2906 + ret = snd_soc_register_card(&snd_allo_boss);
2907 + if (ret) {
2908 + dev_err(&pdev->dev,
2909 + "snd_soc_register_card() failed: %d\n", ret);
2910 + return ret;
2911 + }
2912 +
2913 + if (mute_gpio)
2914 + snd_allo_boss_gpio_mute(&snd_allo_boss);
2915 +
2916 + return 0;
2917 + }
2918 +
2919 + return -EINVAL;
2920 +}
2921 +
2922 +static int snd_allo_boss_remove(struct platform_device *pdev)
2923 +{
2924 + snd_allo_boss_gpio_mute(&snd_allo_boss);
2925 + snd_soc_unregister_card(&snd_allo_boss);
2926 + return 0;
2927 +}
2928 +
2929 +static const struct of_device_id snd_allo_boss_of_match[] = {
2930 + { .compatible = "allo,boss-dac", },
2931 + { /* sentinel */ },
2932 +};
2933 +MODULE_DEVICE_TABLE(of, snd_allo_boss_of_match);
2934 +
2935 +static struct platform_driver snd_allo_boss_driver = {
2936 + .driver = {
2937 + .name = "snd-allo-boss-dac",
2938 + .owner = THIS_MODULE,
2939 + .of_match_table = snd_allo_boss_of_match,
2940 + },
2941 + .probe = snd_allo_boss_probe,
2942 + .remove = snd_allo_boss_remove,
2943 +};
2944 +
2945 +module_platform_driver(snd_allo_boss_driver);
2946 +
2947 +MODULE_AUTHOR("Baswaraj K <jaikumar@cem-solutions.net>");
2948 +MODULE_DESCRIPTION("ALSA ASoC Machine Driver for Allo Boss DAC");
2949 +MODULE_LICENSE("GPL v2");
2950 --- /dev/null
2951 +++ b/sound/soc/bcm/allo-boss2-dac.c
2952 @@ -0,0 +1,1130 @@
2953 +/*
2954 + * Driver for the ALLO KATANA CODEC
2955 + *
2956 + * Author: Jaikumar <sudeepkumar@cem-solutions.net>
2957 + * Copyright 2018
2958 + *
2959 + * This program is free software; you can redistribute it and/or
2960 + * modify it under the terms of the GNU General Public License
2961 + * version 2 as published by the Free Software Foundation.
2962 + *
2963 + * This program is distributed in the hope that it will be useful, but
2964 + * WITHOUT ANY WARRANTY; without even the implied warranty of
2965 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2966 + * General Public License for more details.
2967 + */
2968 +
2969 +#include <linux/module.h>
2970 +#include <linux/moduleparam.h>
2971 +#include <linux/kernel.h>
2972 +#include <linux/init.h>
2973 +#include <linux/delay.h>
2974 +#include <linux/gpio.h>
2975 +#include <linux/gpio/consumer.h>
2976 +#include <linux/platform_device.h>
2977 +#include <linux/pm.h>
2978 +#include <linux/i2c.h>
2979 +#include <linux/of_device.h>
2980 +#include <linux/regmap.h>
2981 +#include <linux/slab.h>
2982 +#include <sound/core.h>
2983 +#include <sound/pcm.h>
2984 +#include <sound/pcm_params.h>
2985 +#include <sound/soc.h>
2986 +#include <sound/soc-dapm.h>
2987 +#include <sound/initval.h>
2988 +#include <sound/tlv.h>
2989 +#include <linux/of_gpio.h>
2990 +#include <linux/regulator/consumer.h>
2991 +#include <linux/pm_runtime.h>
2992 +#include <linux/of_irq.h>
2993 +#include <linux/completion.h>
2994 +#include <linux/mutex.h>
2995 +#include <linux/workqueue.h>
2996 +#include <sound/jack.h>
2997 +
2998 +#include "../codecs/cs43130.h"
2999 +
3000 +#include <linux/clk.h>
3001 +#include <linux/gcd.h>
3002 +#define DEBUG
3003 +
3004 +#define CS43130_DSD_EN_MASK 0x10
3005 +#define CS43130_PDN_DONE_INT_MASK 0x00
3006 +
3007 +static struct gpio_desc *snd_allo_clk44gpio;
3008 +static struct gpio_desc *snd_allo_clk48gpio;
3009 +
3010 +struct cs43130_priv {
3011 + struct snd_soc_component *component;
3012 + struct regmap *regmap;
3013 + struct regulator_bulk_data supplies[CS43130_NUM_SUPPLIES];
3014 + struct gpio_desc *reset_gpio;
3015 + unsigned int dev_id; /* codec device ID */
3016 + int xtal_ibias;
3017 + /* shared by both DAIs */
3018 + struct mutex clk_mutex;
3019 + int clk_req;
3020 + bool pll_bypass;
3021 + struct completion xtal_rdy;
3022 + struct completion pll_rdy;
3023 + unsigned int mclk;
3024 + unsigned int mclk_int;
3025 + int mclk_int_src;
3026 +
3027 + /* DAI specific */
3028 + struct cs43130_dai dais[CS43130_DAI_ID_MAX];
3029 +
3030 + /* HP load specific */
3031 + bool dc_meas;
3032 + bool ac_meas;
3033 + bool hpload_done;
3034 + struct completion hpload_evt;
3035 + unsigned int hpload_stat;
3036 + u16 hpload_dc[2];
3037 + u16 dc_threshold[CS43130_DC_THRESHOLD];
3038 + u16 ac_freq[CS43130_AC_FREQ];
3039 + u16 hpload_ac[CS43130_AC_FREQ][2];
3040 + struct workqueue_struct *wq;
3041 + struct work_struct work;
3042 + struct snd_soc_jack jack;
3043 +};
3044 +
3045 +static const struct reg_default cs43130_reg_defaults[] = {
3046 + {CS43130_SYS_CLK_CTL_1, 0x06},
3047 + {CS43130_SP_SRATE, 0x01},
3048 + {CS43130_SP_BITSIZE, 0x05},
3049 + {CS43130_PAD_INT_CFG, 0x03},
3050 + {CS43130_PWDN_CTL, 0xFE},
3051 + {CS43130_CRYSTAL_SET, 0x04},
3052 + {CS43130_PLL_SET_1, 0x00},
3053 + {CS43130_PLL_SET_2, 0x00},
3054 + {CS43130_PLL_SET_3, 0x00},
3055 + {CS43130_PLL_SET_4, 0x00},
3056 + {CS43130_PLL_SET_5, 0x40},
3057 + {CS43130_PLL_SET_6, 0x10},
3058 + {CS43130_PLL_SET_7, 0x80},
3059 + {CS43130_PLL_SET_8, 0x03},
3060 + {CS43130_PLL_SET_9, 0x02},
3061 + {CS43130_PLL_SET_10, 0x02},
3062 + {CS43130_CLKOUT_CTL, 0x00},
3063 + {CS43130_ASP_NUM_1, 0x01},
3064 + {CS43130_ASP_NUM_2, 0x00},
3065 + {CS43130_ASP_DEN_1, 0x08},
3066 + {CS43130_ASP_DEN_2, 0x00},
3067 + {CS43130_ASP_LRCK_HI_TIME_1, 0x1F},
3068 + {CS43130_ASP_LRCK_HI_TIME_2, 0x00},
3069 + {CS43130_ASP_LRCK_PERIOD_1, 0x3F},
3070 + {CS43130_ASP_LRCK_PERIOD_2, 0x00},
3071 + {CS43130_ASP_CLOCK_CONF, 0x0C},
3072 + {CS43130_ASP_FRAME_CONF, 0x0A},
3073 + {CS43130_XSP_NUM_1, 0x01},
3074 + {CS43130_XSP_NUM_2, 0x00},
3075 + {CS43130_XSP_DEN_1, 0x02},
3076 + {CS43130_XSP_DEN_2, 0x00},
3077 + {CS43130_XSP_LRCK_HI_TIME_1, 0x1F},
3078 + {CS43130_XSP_LRCK_HI_TIME_2, 0x00},
3079 + {CS43130_XSP_LRCK_PERIOD_1, 0x3F},
3080 + {CS43130_XSP_LRCK_PERIOD_2, 0x00},
3081 + {CS43130_XSP_CLOCK_CONF, 0x0C},
3082 + {CS43130_XSP_FRAME_CONF, 0x0A},
3083 + {CS43130_ASP_CH_1_LOC, 0x00},
3084 + {CS43130_ASP_CH_2_LOC, 0x00},
3085 + {CS43130_ASP_CH_1_SZ_EN, 0x06},
3086 + {CS43130_ASP_CH_2_SZ_EN, 0x0E},
3087 + {CS43130_XSP_CH_1_LOC, 0x00},
3088 + {CS43130_XSP_CH_2_LOC, 0x00},
3089 + {CS43130_XSP_CH_1_SZ_EN, 0x06},
3090 + {CS43130_XSP_CH_2_SZ_EN, 0x0E},
3091 + {CS43130_DSD_VOL_B, 0x78},
3092 + {CS43130_DSD_VOL_A, 0x78},
3093 + {CS43130_DSD_PATH_CTL_1, 0xA8},
3094 + {CS43130_DSD_INT_CFG, 0x00},
3095 + {CS43130_DSD_PATH_CTL_2, 0x02},
3096 + {CS43130_DSD_PCM_MIX_CTL, 0x00},
3097 + {CS43130_DSD_PATH_CTL_3, 0x40},
3098 + {CS43130_HP_OUT_CTL_1, 0x30},
3099 + {CS43130_PCM_FILT_OPT, 0x02},
3100 + {CS43130_PCM_VOL_B, 0x78},
3101 + {CS43130_PCM_VOL_A, 0x78},
3102 + {CS43130_PCM_PATH_CTL_1, 0xA8},
3103 + {CS43130_PCM_PATH_CTL_2, 0x00},
3104 + {CS43130_CLASS_H_CTL, 0x1E},
3105 + {CS43130_HP_DETECT, 0x04},
3106 + {CS43130_HP_LOAD_1, 0x00},
3107 + {CS43130_HP_MEAS_LOAD_1, 0x00},
3108 + {CS43130_HP_MEAS_LOAD_2, 0x00},
3109 + {CS43130_INT_MASK_1, 0xFF},
3110 + {CS43130_INT_MASK_2, 0xFF},
3111 + {CS43130_INT_MASK_3, 0xFF},
3112 + {CS43130_INT_MASK_4, 0xFF},
3113 + {CS43130_INT_MASK_5, 0xFF},
3114 +};
3115 +static bool cs43130_volatile_register(struct device *dev, unsigned int reg)
3116 +{
3117 + switch (reg) {
3118 + case CS43130_INT_STATUS_1 ... CS43130_INT_STATUS_5:
3119 + case CS43130_HP_DC_STAT_1 ... CS43130_HP_DC_STAT_2:
3120 + case CS43130_HP_AC_STAT_1 ... CS43130_HP_AC_STAT_2:
3121 + return true;
3122 + default:
3123 + return false;
3124 + }
3125 +}
3126 +
3127 +static const char * const pcm_spd_texts[] = {
3128 + "Fast",
3129 + "Slow",
3130 +};
3131 +
3132 +static SOC_ENUM_SINGLE_DECL(pcm_spd_enum, CS43130_PCM_FILT_OPT, 7,
3133 + pcm_spd_texts);
3134 +
3135 +static const SNDRV_CTL_TLVD_DECLARE_DB_MINMAX(master_tlv, -12750, 0);
3136 +
3137 +static const struct snd_kcontrol_new cs43130_controls[] = {
3138 + SOC_DOUBLE_R_TLV("Master Playback Volume", CS43130_PCM_VOL_B,
3139 + CS43130_PCM_VOL_A, 0, 255, 1, master_tlv),
3140 + SOC_DOUBLE("Master Playback Switch", CS43130_PCM_PATH_CTL_1,
3141 + 0, 1, 1, 1),
3142 + SOC_DOUBLE_R_TLV("Digital Playback Volume", CS43130_DSD_VOL_B,
3143 + CS43130_DSD_VOL_A, 0, 255, 1, master_tlv),
3144 + SOC_DOUBLE("Digital Playback Switch", CS43130_DSD_PATH_CTL_1,
3145 + 0, 1, 1, 1),
3146 + SOC_SINGLE("HV_Enable", CS43130_HP_OUT_CTL_1, 0, 1, 0),
3147 + SOC_ENUM("PCM Filter Speed", pcm_spd_enum),
3148 + SOC_SINGLE("PCM Phase Compensation", CS43130_PCM_FILT_OPT, 6, 1, 0),
3149 + SOC_SINGLE("PCM Nonoversample Emulate", CS43130_PCM_FILT_OPT, 5, 1, 0),
3150 + SOC_SINGLE("PCM High-pass Filter", CS43130_PCM_FILT_OPT, 1, 1, 0),
3151 + SOC_SINGLE("PCM De-emphasis Filter", CS43130_PCM_FILT_OPT, 0, 1, 0),
3152 +};
3153 +
3154 +static bool cs43130_readable_register(struct device *dev, unsigned int reg)
3155 +{
3156 + switch (reg) {
3157 + case CS43130_DEVID_AB ... CS43130_SYS_CLK_CTL_1:
3158 + case CS43130_SP_SRATE ... CS43130_PAD_INT_CFG:
3159 + case CS43130_PWDN_CTL:
3160 + case CS43130_CRYSTAL_SET:
3161 + case CS43130_PLL_SET_1 ... CS43130_PLL_SET_5:
3162 + case CS43130_PLL_SET_6:
3163 + case CS43130_PLL_SET_7:
3164 + case CS43130_PLL_SET_8:
3165 + case CS43130_PLL_SET_9:
3166 + case CS43130_PLL_SET_10:
3167 + case CS43130_CLKOUT_CTL:
3168 + case CS43130_ASP_NUM_1 ... CS43130_ASP_FRAME_CONF:
3169 + case CS43130_XSP_NUM_1 ... CS43130_XSP_FRAME_CONF:
3170 + case CS43130_ASP_CH_1_LOC:
3171 + case CS43130_ASP_CH_2_LOC:
3172 + case CS43130_ASP_CH_1_SZ_EN:
3173 + case CS43130_ASP_CH_2_SZ_EN:
3174 + case CS43130_XSP_CH_1_LOC:
3175 + case CS43130_XSP_CH_2_LOC:
3176 + case CS43130_XSP_CH_1_SZ_EN:
3177 + case CS43130_XSP_CH_2_SZ_EN:
3178 + case CS43130_DSD_VOL_B ... CS43130_DSD_PATH_CTL_3:
3179 + case CS43130_HP_OUT_CTL_1:
3180 + case CS43130_PCM_FILT_OPT ... CS43130_PCM_PATH_CTL_2:
3181 + case CS43130_CLASS_H_CTL:
3182 + case CS43130_HP_DETECT:
3183 + case CS43130_HP_STATUS:
3184 + case CS43130_HP_LOAD_1:
3185 + case CS43130_HP_MEAS_LOAD_1:
3186 + case CS43130_HP_MEAS_LOAD_2:
3187 + case CS43130_HP_DC_STAT_1:
3188 + case CS43130_HP_DC_STAT_2:
3189 + case CS43130_HP_AC_STAT_1:
3190 + case CS43130_HP_AC_STAT_2:
3191 + case CS43130_HP_LOAD_STAT:
3192 + case CS43130_INT_STATUS_1 ... CS43130_INT_STATUS_5:
3193 + case CS43130_INT_MASK_1 ... CS43130_INT_MASK_5:
3194 + return true;
3195 + default:
3196 + return false;
3197 + }
3198 +}
3199 +static bool cs43130_precious_register(struct device *dev, unsigned int reg)
3200 +{
3201 + switch (reg) {
3202 + case CS43130_INT_STATUS_1 ... CS43130_INT_STATUS_5:
3203 + return true;
3204 + default:
3205 + return false;
3206 + }
3207 +}
3208 +static int cs43130_pcm_pdn(struct snd_soc_component *component)
3209 +{
3210 + struct cs43130_priv *cs43130 =
3211 + snd_soc_component_get_drvdata(component);
3212 + int ret;
3213 + unsigned int reg, pdn_int;
3214 +
3215 + regmap_write(cs43130->regmap, CS43130_DSD_PATH_CTL_2, 0x02);
3216 + regmap_update_bits(cs43130->regmap, CS43130_INT_MASK_1,
3217 + CS43130_PDN_DONE_INT_MASK, 0);
3218 + regmap_update_bits(cs43130->regmap, CS43130_PWDN_CTL,
3219 + CS43130_PDN_HP_MASK, 1 << CS43130_PDN_HP_SHIFT);
3220 + usleep_range(10, 50);
3221 + ret = regmap_read(cs43130->regmap, CS43130_INT_STATUS_1, &reg);
3222 + pdn_int = reg & 0xFE;
3223 + regmap_update_bits(cs43130->regmap, CS43130_PWDN_CTL,
3224 + CS43130_PDN_ASP_MASK, 1 << CS43130_PDN_ASP_SHIFT);
3225 + return 0;
3226 +
3227 +}
3228 +static int cs43130_pwr_up_asp_dac(struct snd_soc_component *component)
3229 +{
3230 + struct cs43130_priv *cs43130 =
3231 + snd_soc_component_get_drvdata(component);
3232 +
3233 + regmap_update_bits(cs43130->regmap, CS43130_PAD_INT_CFG,
3234 + CS43130_ASP_3ST_MASK, 0);
3235 + regmap_write(cs43130->regmap, CS43130_DXD1, 0x99);
3236 + regmap_write(cs43130->regmap, CS43130_DXD13, 0x20);
3237 + regmap_update_bits(cs43130->regmap, CS43130_PWDN_CTL,
3238 + CS43130_PDN_ASP_MASK, 0);
3239 + regmap_update_bits(cs43130->regmap, CS43130_PWDN_CTL,
3240 + CS43130_PDN_HP_MASK, 0);
3241 + usleep_range(10000, 12000);
3242 + regmap_write(cs43130->regmap, CS43130_DXD1, 0x00);
3243 + regmap_write(cs43130->regmap, CS43130_DXD13, 0x00);
3244 + return 0;
3245 +}
3246 +static int cs43130_change_clksrc(struct snd_soc_component *component,
3247 + enum cs43130_mclk_src_sel src)
3248 +{
3249 + int ret;
3250 + struct cs43130_priv *cs43130 =
3251 + snd_soc_component_get_drvdata(component);
3252 + int mclk_int_decoded;
3253 +
3254 + if (src == cs43130->mclk_int_src) {
3255 + /* clk source has not changed */
3256 + return 0;
3257 + }
3258 + switch (cs43130->mclk_int) {
3259 + case CS43130_MCLK_22M:
3260 + mclk_int_decoded = CS43130_MCLK_22P5;
3261 + break;
3262 + case CS43130_MCLK_24M:
3263 + mclk_int_decoded = CS43130_MCLK_24P5;
3264 + break;
3265 + default:
3266 + dev_err(component->dev, "Invalid MCLK INT freq: %u\n",
3267 + cs43130->mclk_int);
3268 + return -EINVAL;
3269 + }
3270 +
3271 + switch (src) {
3272 + case CS43130_MCLK_SRC_EXT:
3273 + cs43130->pll_bypass = true;
3274 + cs43130->mclk_int_src = CS43130_MCLK_SRC_EXT;
3275 + if (cs43130->xtal_ibias == CS43130_XTAL_UNUSED) {
3276 + regmap_update_bits(cs43130->regmap, CS43130_PWDN_CTL,
3277 + CS43130_PDN_XTAL_MASK,
3278 + 1 << CS43130_PDN_XTAL_SHIFT);
3279 + } else {
3280 + reinit_completion(&cs43130->xtal_rdy);
3281 + regmap_update_bits(cs43130->regmap, CS43130_INT_MASK_1,
3282 + CS43130_XTAL_RDY_INT_MASK, 0);
3283 + regmap_update_bits(cs43130->regmap, CS43130_PWDN_CTL,
3284 + CS43130_PDN_XTAL_MASK, 0);
3285 + ret = wait_for_completion_timeout(&cs43130->xtal_rdy,
3286 + msecs_to_jiffies(100));
3287 + regmap_update_bits(cs43130->regmap, CS43130_INT_MASK_1,
3288 + CS43130_XTAL_RDY_INT_MASK,
3289 + 1 << CS43130_XTAL_RDY_INT_SHIFT);
3290 + if (ret == 0) {
3291 + dev_err(component->dev, "Timeout waiting for XTAL_READY interrupt\n");
3292 + return -ETIMEDOUT;
3293 + }
3294 + }
3295 + regmap_update_bits(cs43130->regmap, CS43130_SYS_CLK_CTL_1,
3296 + CS43130_MCLK_SRC_SEL_MASK,
3297 + src << CS43130_MCLK_SRC_SEL_SHIFT);
3298 + regmap_update_bits(cs43130->regmap, CS43130_SYS_CLK_CTL_1,
3299 + CS43130_MCLK_INT_MASK,
3300 + mclk_int_decoded << CS43130_MCLK_INT_SHIFT);
3301 + usleep_range(150, 200);
3302 + regmap_update_bits(cs43130->regmap, CS43130_PWDN_CTL,
3303 + CS43130_PDN_PLL_MASK,
3304 + 1 << CS43130_PDN_PLL_SHIFT);
3305 + break;
3306 + case CS43130_MCLK_SRC_RCO:
3307 + cs43130->mclk_int_src = CS43130_MCLK_SRC_RCO;
3308 +
3309 + regmap_update_bits(cs43130->regmap, CS43130_SYS_CLK_CTL_1,
3310 + CS43130_MCLK_SRC_SEL_MASK,
3311 + src << CS43130_MCLK_SRC_SEL_SHIFT);
3312 + regmap_update_bits(cs43130->regmap, CS43130_SYS_CLK_CTL_1,
3313 + CS43130_MCLK_INT_MASK,
3314 + CS43130_MCLK_22P5 << CS43130_MCLK_INT_SHIFT);
3315 + usleep_range(150, 200);
3316 + regmap_update_bits(cs43130->regmap, CS43130_PWDN_CTL,
3317 + CS43130_PDN_XTAL_MASK,
3318 + 1 << CS43130_PDN_XTAL_SHIFT);
3319 + regmap_update_bits(cs43130->regmap, CS43130_PWDN_CTL,
3320 + CS43130_PDN_PLL_MASK,
3321 + 1 << CS43130_PDN_PLL_SHIFT);
3322 + break;
3323 + default:
3324 + dev_err(component->dev, "Invalid MCLK source value\n");
3325 + return -EINVAL;
3326 + }
3327 +
3328 + return 0;
3329 +}
3330 +static const struct cs43130_bitwidth_map cs43130_bitwidth_table[] = {
3331 + {8, CS43130_SP_BIT_SIZE_8, CS43130_CH_BIT_SIZE_8},
3332 + {16, CS43130_SP_BIT_SIZE_16, CS43130_CH_BIT_SIZE_16},
3333 + {24, CS43130_SP_BIT_SIZE_24, CS43130_CH_BIT_SIZE_24},
3334 + {32, CS43130_SP_BIT_SIZE_32, CS43130_CH_BIT_SIZE_32},
3335 +};
3336 +
3337 +static const struct cs43130_bitwidth_map *cs43130_get_bitwidth_table(
3338 + unsigned int bitwidth)
3339 +{
3340 + int i;
3341 +
3342 + for (i = 0; i < ARRAY_SIZE(cs43130_bitwidth_table); i++) {
3343 + if (cs43130_bitwidth_table[i].bitwidth == bitwidth)
3344 + return &cs43130_bitwidth_table[i];
3345 + }
3346 +
3347 + return NULL;
3348 +}
3349 +static int cs43130_set_bitwidth(int dai_id, unsigned int bitwidth_dai,
3350 + struct regmap *regmap)
3351 +{
3352 + const struct cs43130_bitwidth_map *bw_map;
3353 +
3354 + bw_map = cs43130_get_bitwidth_table(bitwidth_dai);
3355 + if (!bw_map)
3356 + return -EINVAL;
3357 +
3358 + switch (dai_id) {
3359 + case CS43130_ASP_PCM_DAI:
3360 + case CS43130_ASP_DOP_DAI:
3361 + regmap_update_bits(regmap, CS43130_ASP_CH_1_SZ_EN,
3362 + CS43130_CH_BITSIZE_MASK, bw_map->ch_bit);
3363 + regmap_update_bits(regmap, CS43130_ASP_CH_2_SZ_EN,
3364 + CS43130_CH_BITSIZE_MASK, bw_map->ch_bit);
3365 + regmap_update_bits(regmap, CS43130_SP_BITSIZE,
3366 + CS43130_ASP_BITSIZE_MASK, bw_map->sp_bit);
3367 + break;
3368 + case CS43130_XSP_DOP_DAI:
3369 + regmap_update_bits(regmap, CS43130_XSP_CH_1_SZ_EN,
3370 + CS43130_CH_BITSIZE_MASK, bw_map->ch_bit);
3371 + regmap_update_bits(regmap, CS43130_XSP_CH_2_SZ_EN,
3372 + CS43130_CH_BITSIZE_MASK, bw_map->ch_bit);
3373 + regmap_update_bits(regmap, CS43130_SP_BITSIZE,
3374 + CS43130_XSP_BITSIZE_MASK, bw_map->sp_bit <<
3375 + CS43130_XSP_BITSIZE_SHIFT);
3376 + break;
3377 + default:
3378 + return -EINVAL;
3379 + }
3380 +
3381 + return 0;
3382 +}
3383 +static const struct cs43130_rate_map cs43130_rate_table[] = {
3384 + {32000, CS43130_ASP_SPRATE_32K},
3385 + {44100, CS43130_ASP_SPRATE_44_1K},
3386 + {48000, CS43130_ASP_SPRATE_48K},
3387 + {88200, CS43130_ASP_SPRATE_88_2K},
3388 + {96000, CS43130_ASP_SPRATE_96K},
3389 + {176400, CS43130_ASP_SPRATE_176_4K},
3390 + {192000, CS43130_ASP_SPRATE_192K},
3391 + {352800, CS43130_ASP_SPRATE_352_8K},
3392 + {384000, CS43130_ASP_SPRATE_384K},
3393 +};
3394 +
3395 +static const struct cs43130_rate_map *cs43130_get_rate_table(int fs)
3396 +{
3397 + int i;
3398 +
3399 + for (i = 0; i < ARRAY_SIZE(cs43130_rate_table); i++) {
3400 + if (cs43130_rate_table[i].fs == fs)
3401 + return &cs43130_rate_table[i];
3402 + }
3403 +
3404 + return NULL;
3405 +}
3406 +
3407 +static const struct cs43130_clk_gen *cs43130_get_clk_gen(int mclk_int, int fs,
3408 + const struct cs43130_clk_gen *clk_gen_table, int len_clk_gen_table)
3409 +{
3410 + int i;
3411 +
3412 + for (i = 0; i < len_clk_gen_table; i++) {
3413 + if (clk_gen_table[i].mclk_int == mclk_int &&
3414 + clk_gen_table[i].fs == fs)
3415 + return &clk_gen_table[i];
3416 + }
3417 + return NULL;
3418 +}
3419 +
3420 +static int cs43130_set_sp_fmt(int dai_id, unsigned int bitwidth_sclk,
3421 + struct snd_pcm_hw_params *params,
3422 + struct cs43130_priv *cs43130)
3423 +{
3424 + u16 frm_size;
3425 + u16 hi_size;
3426 + u8 frm_delay;
3427 + u8 frm_phase;
3428 + u8 frm_data;
3429 + u8 sclk_edge;
3430 + u8 lrck_edge;
3431 + u8 clk_data;
3432 + u8 loc_ch1;
3433 + u8 loc_ch2;
3434 + u8 dai_mode_val;
3435 + const struct cs43130_clk_gen *clk_gen;
3436 +
3437 + switch (cs43130->dais[dai_id].dai_format) {
3438 + case SND_SOC_DAIFMT_I2S:
3439 + hi_size = bitwidth_sclk;
3440 + frm_delay = 2;
3441 + frm_phase = 0;
3442 + break;
3443 + case SND_SOC_DAIFMT_LEFT_J:
3444 + hi_size = bitwidth_sclk;
3445 + frm_delay = 2;
3446 + frm_phase = 1;
3447 + break;
3448 + case SND_SOC_DAIFMT_DSP_A:
3449 + hi_size = 1;
3450 + frm_delay = 2;
3451 + frm_phase = 1;
3452 + break;
3453 + case SND_SOC_DAIFMT_DSP_B:
3454 + hi_size = 1;
3455 + frm_delay = 0;
3456 + frm_phase = 1;
3457 + break;
3458 + default:
3459 + return -EINVAL;
3460 + }
3461 + switch (cs43130->dais[dai_id].dai_mode) {
3462 + case SND_SOC_DAIFMT_CBS_CFS:
3463 + dai_mode_val = 0;
3464 + break;
3465 + case SND_SOC_DAIFMT_CBM_CFM:
3466 + dai_mode_val = 1;
3467 + break;
3468 + default:
3469 + return -EINVAL;
3470 + }
3471 +
3472 + frm_size = bitwidth_sclk * params_channels(params);
3473 + sclk_edge = 1;
3474 + lrck_edge = 0;
3475 + loc_ch1 = 0;
3476 + loc_ch2 = bitwidth_sclk * (params_channels(params) - 1);
3477 +
3478 + frm_data = frm_delay & CS43130_SP_FSD_MASK;
3479 + frm_data |= (frm_phase << CS43130_SP_STP_SHIFT) & CS43130_SP_STP_MASK;
3480 +
3481 + clk_data = lrck_edge & CS43130_SP_LCPOL_IN_MASK;
3482 + clk_data |= (lrck_edge << CS43130_SP_LCPOL_OUT_SHIFT) &
3483 + CS43130_SP_LCPOL_OUT_MASK;
3484 + clk_data |= (sclk_edge << CS43130_SP_SCPOL_IN_SHIFT) &
3485 + CS43130_SP_SCPOL_IN_MASK;
3486 + clk_data |= (sclk_edge << CS43130_SP_SCPOL_OUT_SHIFT) &
3487 + CS43130_SP_SCPOL_OUT_MASK;
3488 + clk_data |= (dai_mode_val << CS43130_SP_MODE_SHIFT) &
3489 + CS43130_SP_MODE_MASK;
3490 + switch (dai_id) {
3491 + case CS43130_ASP_PCM_DAI:
3492 + case CS43130_ASP_DOP_DAI:
3493 + regmap_update_bits(cs43130->regmap, CS43130_ASP_LRCK_PERIOD_1,
3494 + CS43130_SP_LCPR_DATA_MASK, (frm_size - 1) >>
3495 + CS43130_SP_LCPR_LSB_DATA_SHIFT);
3496 + regmap_update_bits(cs43130->regmap, CS43130_ASP_LRCK_PERIOD_2,
3497 + CS43130_SP_LCPR_DATA_MASK, (frm_size - 1) >>
3498 + CS43130_SP_LCPR_MSB_DATA_SHIFT);
3499 + regmap_update_bits(cs43130->regmap, CS43130_ASP_LRCK_HI_TIME_1,
3500 + CS43130_SP_LCHI_DATA_MASK, (hi_size - 1) >>
3501 + CS43130_SP_LCHI_LSB_DATA_SHIFT);
3502 + regmap_update_bits(cs43130->regmap, CS43130_ASP_LRCK_HI_TIME_2,
3503 + CS43130_SP_LCHI_DATA_MASK, (hi_size - 1) >>
3504 + CS43130_SP_LCHI_MSB_DATA_SHIFT);
3505 + regmap_write(cs43130->regmap, CS43130_ASP_FRAME_CONF, frm_data);
3506 + regmap_write(cs43130->regmap, CS43130_ASP_CH_1_LOC, loc_ch1);
3507 + regmap_write(cs43130->regmap, CS43130_ASP_CH_2_LOC, loc_ch2);
3508 + regmap_update_bits(cs43130->regmap, CS43130_ASP_CH_1_SZ_EN,
3509 + CS43130_CH_EN_MASK, 1 << CS43130_CH_EN_SHIFT);
3510 + regmap_update_bits(cs43130->regmap, CS43130_ASP_CH_2_SZ_EN,
3511 + CS43130_CH_EN_MASK, 1 << CS43130_CH_EN_SHIFT);
3512 + regmap_write(cs43130->regmap, CS43130_ASP_CLOCK_CONF, clk_data);
3513 + break;
3514 + case CS43130_XSP_DOP_DAI:
3515 + regmap_update_bits(cs43130->regmap, CS43130_XSP_LRCK_PERIOD_1,
3516 + CS43130_SP_LCPR_DATA_MASK, (frm_size - 1) >>
3517 + CS43130_SP_LCPR_LSB_DATA_SHIFT);
3518 + regmap_update_bits(cs43130->regmap, CS43130_XSP_LRCK_PERIOD_2,
3519 + CS43130_SP_LCPR_DATA_MASK, (frm_size - 1) >>
3520 + CS43130_SP_LCPR_MSB_DATA_SHIFT);
3521 + regmap_update_bits(cs43130->regmap, CS43130_XSP_LRCK_HI_TIME_1,
3522 + CS43130_SP_LCHI_DATA_MASK, (hi_size - 1) >>
3523 + CS43130_SP_LCHI_LSB_DATA_SHIFT);
3524 + regmap_update_bits(cs43130->regmap, CS43130_XSP_LRCK_HI_TIME_2,
3525 + CS43130_SP_LCHI_DATA_MASK, (hi_size - 1) >>
3526 + CS43130_SP_LCHI_MSB_DATA_SHIFT);
3527 + regmap_write(cs43130->regmap, CS43130_XSP_FRAME_CONF, frm_data);
3528 + regmap_write(cs43130->regmap, CS43130_XSP_CH_1_LOC, loc_ch1);
3529 + regmap_write(cs43130->regmap, CS43130_XSP_CH_2_LOC, loc_ch2);
3530 + regmap_update_bits(cs43130->regmap, CS43130_XSP_CH_1_SZ_EN,
3531 + CS43130_CH_EN_MASK, 1 << CS43130_CH_EN_SHIFT);
3532 + regmap_update_bits(cs43130->regmap, CS43130_XSP_CH_2_SZ_EN,
3533 + CS43130_CH_EN_MASK, 1 << CS43130_CH_EN_SHIFT);
3534 + regmap_write(cs43130->regmap, CS43130_XSP_CLOCK_CONF, clk_data);
3535 + break;
3536 + default:
3537 + return -EINVAL;
3538 + }
3539 + switch (frm_size) {
3540 + case 16:
3541 + clk_gen = cs43130_get_clk_gen(cs43130->mclk_int,
3542 + params_rate(params),
3543 + cs43130_16_clk_gen,
3544 + ARRAY_SIZE(cs43130_16_clk_gen));
3545 + break;
3546 + case 32:
3547 + clk_gen = cs43130_get_clk_gen(cs43130->mclk_int,
3548 + params_rate(params),
3549 + cs43130_32_clk_gen,
3550 + ARRAY_SIZE(cs43130_32_clk_gen));
3551 + break;
3552 + case 48:
3553 + clk_gen = cs43130_get_clk_gen(cs43130->mclk_int,
3554 + params_rate(params),
3555 + cs43130_48_clk_gen,
3556 + ARRAY_SIZE(cs43130_48_clk_gen));
3557 + break;
3558 + case 64:
3559 + clk_gen = cs43130_get_clk_gen(cs43130->mclk_int,
3560 + params_rate(params),
3561 + cs43130_64_clk_gen,
3562 + ARRAY_SIZE(cs43130_64_clk_gen));
3563 + break;
3564 + default:
3565 + return -EINVAL;
3566 + }
3567 + if (!clk_gen)
3568 + return -EINVAL;
3569 + switch (dai_id) {
3570 + case CS43130_ASP_PCM_DAI:
3571 + case CS43130_ASP_DOP_DAI:
3572 + regmap_write(cs43130->regmap, CS43130_ASP_DEN_1,
3573 + (clk_gen->v.denominator & CS43130_SP_M_LSB_DATA_MASK) >>
3574 + CS43130_SP_M_LSB_DATA_SHIFT);
3575 + regmap_write(cs43130->regmap, CS43130_ASP_DEN_2,
3576 + (clk_gen->v.denominator & CS43130_SP_M_MSB_DATA_MASK) >>
3577 + CS43130_SP_M_MSB_DATA_SHIFT);
3578 + regmap_write(cs43130->regmap, CS43130_ASP_NUM_1,
3579 + (clk_gen->v.numerator & CS43130_SP_N_LSB_DATA_MASK) >>
3580 + CS43130_SP_N_LSB_DATA_SHIFT);
3581 + regmap_write(cs43130->regmap, CS43130_ASP_NUM_2,
3582 + (clk_gen->v.numerator & CS43130_SP_N_MSB_DATA_MASK) >>
3583 + CS43130_SP_N_MSB_DATA_SHIFT);
3584 + break;
3585 + case CS43130_XSP_DOP_DAI:
3586 + regmap_write(cs43130->regmap, CS43130_XSP_DEN_1,
3587 + (clk_gen->v.denominator & CS43130_SP_M_LSB_DATA_MASK) >>
3588 + CS43130_SP_M_LSB_DATA_SHIFT);
3589 + regmap_write(cs43130->regmap, CS43130_XSP_DEN_2,
3590 + (clk_gen->v.denominator & CS43130_SP_M_MSB_DATA_MASK) >>
3591 + CS43130_SP_M_MSB_DATA_SHIFT);
3592 + regmap_write(cs43130->regmap, CS43130_XSP_NUM_1,
3593 + (clk_gen->v.numerator & CS43130_SP_N_LSB_DATA_MASK) >>
3594 + CS43130_SP_N_LSB_DATA_SHIFT);
3595 + regmap_write(cs43130->regmap, CS43130_XSP_NUM_2,
3596 + (clk_gen->v.numerator & CS43130_SP_N_MSB_DATA_MASK) >>
3597 + CS43130_SP_N_MSB_DATA_SHIFT);
3598 + break;
3599 + default:
3600 + return -EINVAL;
3601 + }
3602 + return 0;
3603 +}
3604 +
3605 +static int cs43130_hw_params(struct snd_pcm_substream *substream,
3606 + struct snd_pcm_hw_params *params,
3607 + struct snd_soc_dai *dai)
3608 +{
3609 + struct snd_soc_component *component = dai->component;
3610 + struct cs43130_priv *cs43130 =
3611 + snd_soc_component_get_drvdata(component);
3612 + const struct cs43130_rate_map *rate_map;
3613 + unsigned int sclk = cs43130->dais[dai->id].sclk;
3614 + unsigned int bitwidth_sclk;
3615 + unsigned int bitwidth_dai = (unsigned int)(params_width(params));
3616 + unsigned int dop_rate = (unsigned int)(params_rate(params));
3617 + unsigned int required_clk, ret;
3618 + u8 dsd_speed;
3619 +
3620 + cs43130->pll_bypass = true;
3621 + cs43130_pcm_pdn(component);
3622 + mutex_lock(&cs43130->clk_mutex);
3623 + if (!cs43130->clk_req) {
3624 + /* no DAI is currently using clk */
3625 + if (!(CS43130_MCLK_22M % params_rate(params))) {
3626 + required_clk = CS43130_MCLK_22M;
3627 + cs43130->mclk_int = CS43130_MCLK_22M;
3628 + gpiod_set_value_cansleep(snd_allo_clk44gpio, 1);
3629 + gpiod_set_value_cansleep(snd_allo_clk48gpio, 0);
3630 + usleep_range(13500, 14000);
3631 + } else {
3632 + required_clk = CS43130_MCLK_24M;
3633 + cs43130->mclk_int = CS43130_MCLK_24M;
3634 + gpiod_set_value_cansleep(snd_allo_clk48gpio, 1);
3635 + gpiod_set_value_cansleep(snd_allo_clk44gpio, 0);
3636 + usleep_range(13500, 14000);
3637 + }
3638 + if (cs43130->pll_bypass)
3639 + cs43130_change_clksrc(component, CS43130_MCLK_SRC_EXT);
3640 + else
3641 + cs43130_change_clksrc(component, CS43130_MCLK_SRC_PLL);
3642 + }
3643 +
3644 + cs43130->clk_req++;
3645 + mutex_unlock(&cs43130->clk_mutex);
3646 +
3647 + switch (dai->id) {
3648 + case CS43130_ASP_DOP_DAI:
3649 + case CS43130_XSP_DOP_DAI:
3650 + /* DoP bitwidth is always 24-bit */
3651 + bitwidth_dai = 24;
3652 + sclk = params_rate(params) * bitwidth_dai *
3653 + params_channels(params);
3654 +
3655 + switch (params_rate(params)) {
3656 + case 176400:
3657 + dsd_speed = 0;
3658 + break;
3659 + case 352800:
3660 + dsd_speed = 1;
3661 + break;
3662 + default:
3663 + dev_err(component->dev, "Rate(%u) not supported\n",
3664 + params_rate(params));
3665 + return -EINVAL;
3666 + }
3667 +
3668 + regmap_update_bits(cs43130->regmap, CS43130_DSD_PATH_CTL_2,
3669 + CS43130_DSD_SPEED_MASK,
3670 + dsd_speed << CS43130_DSD_SPEED_SHIFT);
3671 + break;
3672 + case CS43130_ASP_PCM_DAI:
3673 + rate_map = cs43130_get_rate_table(params_rate(params));
3674 + if (!rate_map)
3675 + return -EINVAL;
3676 +
3677 + regmap_write(cs43130->regmap, CS43130_SP_SRATE, rate_map->val);
3678 + if ((dop_rate == 176400) && (bitwidth_dai == 24)) {
3679 + dsd_speed = 0;
3680 + regmap_update_bits(cs43130->regmap,
3681 + CS43130_DSD_PATH_CTL_2,
3682 + CS43130_DSD_SPEED_MASK,
3683 + dsd_speed << CS43130_DSD_SPEED_SHIFT);
3684 + regmap_update_bits(cs43130->regmap,
3685 + CS43130_DSD_PATH_CTL_2,
3686 + CS43130_DSD_SRC_MASK,
3687 + CS43130_DSD_SRC_ASP <<
3688 + CS43130_DSD_SRC_SHIFT);
3689 + regmap_update_bits(cs43130->regmap,
3690 + CS43130_DSD_PATH_CTL_2,
3691 + CS43130_DSD_EN_MASK, 0x01 <<
3692 + CS43130_DSD_EN_SHIFT);
3693 + }
3694 + break;
3695 + default:
3696 + dev_err(component->dev, "Invalid DAI (%d)\n", dai->id);
3697 + return -EINVAL;
3698 + }
3699 +
3700 + switch (dai->id) {
3701 + case CS43130_ASP_DOP_DAI:
3702 + regmap_update_bits(cs43130->regmap, CS43130_DSD_PATH_CTL_2,
3703 + CS43130_DSD_SRC_MASK, CS43130_DSD_SRC_ASP <<
3704 + CS43130_DSD_SRC_SHIFT);
3705 + regmap_update_bits(cs43130->regmap, CS43130_DSD_PATH_CTL_2,
3706 + CS43130_DSD_EN_MASK, 0x01 <<
3707 + CS43130_DSD_EN_SHIFT);
3708 + break;
3709 + case CS43130_XSP_DOP_DAI:
3710 + regmap_update_bits(cs43130->regmap, CS43130_DSD_PATH_CTL_2,
3711 + CS43130_DSD_SRC_MASK, CS43130_DSD_SRC_XSP <<
3712 + CS43130_DSD_SRC_SHIFT);
3713 + break;
3714 + }
3715 + if (!sclk && cs43130->dais[dai->id].dai_mode ==
3716 + SND_SOC_DAIFMT_CBM_CFM) {
3717 + /* Calculate SCLK in master mode if unassigned */
3718 + sclk = params_rate(params) * bitwidth_dai *
3719 + params_channels(params);
3720 + }
3721 + if (!sclk) {
3722 + /* at this point, SCLK must be set */
3723 + dev_err(component->dev, "SCLK freq is not set\n");
3724 + return -EINVAL;
3725 + }
3726 +
3727 + bitwidth_sclk = (sclk / params_rate(params)) / params_channels(params);
3728 + if (bitwidth_sclk < bitwidth_dai) {
3729 + dev_err(component->dev, "Format not supported: SCLK freq is too low\n");
3730 + return -EINVAL;
3731 + }
3732 +
3733 + dev_dbg(component->dev,
3734 + "sclk = %u, fs = %d, bitwidth_dai = %u\n",
3735 + sclk, params_rate(params), bitwidth_dai);
3736 +
3737 + dev_dbg(component->dev,
3738 + "bitwidth_sclk = %u, num_ch = %u\n",
3739 + bitwidth_sclk, params_channels(params));
3740 +
3741 + cs43130_set_bitwidth(dai->id, bitwidth_dai, cs43130->regmap);
3742 + cs43130_set_sp_fmt(dai->id, bitwidth_sclk, params, cs43130);
3743 + ret = cs43130_pwr_up_asp_dac(component);
3744 + return 0;
3745 +}
3746 +
3747 +static int cs43130_hw_free(struct snd_pcm_substream *substream,
3748 + struct snd_soc_dai *dai)
3749 +{
3750 + struct snd_soc_component *component = dai->component;
3751 + struct cs43130_priv *cs43130 =
3752 + snd_soc_component_get_drvdata(component);
3753 +
3754 + mutex_lock(&cs43130->clk_mutex);
3755 + cs43130->clk_req--;
3756 + if (!cs43130->clk_req) {
3757 + /* no DAI is currently using clk */
3758 + cs43130_change_clksrc(component, CS43130_MCLK_SRC_RCO);
3759 + cs43130_pcm_pdn(component);
3760 + }
3761 + mutex_unlock(&cs43130->clk_mutex);
3762 +
3763 + return 0;
3764 +}
3765 +
3766 +static const unsigned int cs43130_asp_src_rates[] = {
3767 + 32000, 44100, 48000, 88200, 96000, 176400, 192000
3768 +};
3769 +
3770 +static const struct snd_pcm_hw_constraint_list cs43130_asp_constraints = {
3771 + .count = ARRAY_SIZE(cs43130_asp_src_rates),
3772 + .list = cs43130_asp_src_rates,
3773 +};
3774 +
3775 +static int cs43130_pcm_startup(struct snd_pcm_substream *substream,
3776 + struct snd_soc_dai *dai)
3777 +{
3778 + return snd_pcm_hw_constraint_list(substream->runtime, 0,
3779 + SNDRV_PCM_HW_PARAM_RATE,
3780 + &cs43130_asp_constraints);
3781 +}
3782 +
3783 +static int cs43130_pcm_set_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
3784 +{
3785 + struct snd_soc_component *component = codec_dai->component;
3786 + struct cs43130_priv *cs43130 =
3787 + snd_soc_component_get_drvdata(component);
3788 +
3789 + switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
3790 + case SND_SOC_DAIFMT_CBS_CFS:
3791 + cs43130->dais[codec_dai->id].dai_mode = SND_SOC_DAIFMT_CBS_CFS;
3792 + break;
3793 + case SND_SOC_DAIFMT_CBM_CFM:
3794 + cs43130->dais[codec_dai->id].dai_mode = SND_SOC_DAIFMT_CBM_CFM;
3795 + break;
3796 + default:
3797 + dev_err(component->dev, "unsupported mode\n");
3798 + return -EINVAL;
3799 + }
3800 +
3801 + switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
3802 + case SND_SOC_DAIFMT_I2S:
3803 + cs43130->dais[codec_dai->id].dai_format = SND_SOC_DAIFMT_I2S;
3804 + break;
3805 + case SND_SOC_DAIFMT_LEFT_J:
3806 + cs43130->dais[codec_dai->id].dai_format = SND_SOC_DAIFMT_LEFT_J;
3807 + break;
3808 + default:
3809 + dev_err(component->dev,
3810 + "unsupported audio format\n");
3811 + return -EINVAL;
3812 + }
3813 +
3814 + dev_dbg(component->dev, "dai_id = %d, dai_mode = %u, dai_format = %u\n",
3815 + codec_dai->id,
3816 + cs43130->dais[codec_dai->id].dai_mode,
3817 + cs43130->dais[codec_dai->id].dai_format);
3818 +
3819 + return 0;
3820 +}
3821 +
3822 +static int cs43130_set_sysclk(struct snd_soc_dai *codec_dai,
3823 + int clk_id, unsigned int freq, int dir)
3824 +{
3825 + struct snd_soc_component *component = codec_dai->component;
3826 + struct cs43130_priv *cs43130 =
3827 + snd_soc_component_get_drvdata(component);
3828 +
3829 + cs43130->dais[codec_dai->id].sclk = freq;
3830 + dev_dbg(component->dev, "dai_id = %d, sclk = %u\n", codec_dai->id,
3831 + cs43130->dais[codec_dai->id].sclk);
3832 +
3833 + return 0;
3834 +}
3835 +
3836 +static int cs43130_component_set_sysclk(struct snd_soc_component *component,
3837 + int clk_id, int source,
3838 + unsigned int freq, int dir)
3839 +{
3840 + struct cs43130_priv *cs43130 =
3841 + snd_soc_component_get_drvdata(component);
3842 +
3843 + dev_dbg(component->dev, "clk_id = %d, source = %d, freq = %d, dir = %d\n",
3844 + clk_id, source, freq, dir);
3845 +
3846 + switch (freq) {
3847 + case CS43130_MCLK_22M:
3848 + case CS43130_MCLK_24M:
3849 + cs43130->mclk = freq;
3850 + break;
3851 + default:
3852 + dev_err(component->dev, "Invalid MCLK INT freq: %u\n", freq);
3853 + return -EINVAL;
3854 + }
3855 +
3856 + if (source == CS43130_MCLK_SRC_EXT) {
3857 + cs43130->pll_bypass = true;
3858 + } else {
3859 + dev_err(component->dev, "Invalid MCLK source\n");
3860 + return -EINVAL;
3861 + }
3862 +
3863 + return 0;
3864 +}
3865 +static u16 const cs43130_ac_freq[CS43130_AC_FREQ] = {
3866 + 24,
3867 + 43,
3868 + 93,
3869 + 200,
3870 + 431,
3871 + 928,
3872 + 2000,
3873 + 4309,
3874 + 9283,
3875 + 20000,
3876 +};
3877 +static const struct snd_soc_dai_ops cs43130_dai_ops = {
3878 + .startup = cs43130_pcm_startup,
3879 + .hw_params = cs43130_hw_params,
3880 + .hw_free = cs43130_hw_free,
3881 + .set_sysclk = cs43130_set_sysclk,
3882 + .set_fmt = cs43130_pcm_set_fmt,
3883 +};
3884 +
3885 +static struct snd_soc_dai_driver cs43130_codec_dai = {
3886 + .name = "allo-cs43130",
3887 + .playback = {
3888 + .stream_name = "Playback",
3889 + .channels_min = 2,
3890 + .channels_max = 2,
3891 + .rates = SNDRV_PCM_RATE_CONTINUOUS,
3892 + .rate_min = 44100,
3893 + .rate_max = 192000,
3894 + .formats = SNDRV_PCM_FMTBIT_S16_LE |
3895 + SNDRV_PCM_FMTBIT_S24_LE |
3896 + SNDRV_PCM_FMTBIT_S32_LE
3897 +
3898 + },
3899 + .ops = &cs43130_dai_ops,
3900 +};
3901 +
3902 +static struct snd_soc_component_driver cs43130_component_driver = {
3903 + .idle_bias_on = true,
3904 + .controls = cs43130_controls,
3905 + .num_controls = ARRAY_SIZE(cs43130_controls),
3906 + .set_sysclk = cs43130_component_set_sysclk,
3907 + .idle_bias_on = 1,
3908 + .use_pmdown_time = 1,
3909 + .endianness = 1,
3910 +};
3911 +
3912 +static const struct regmap_config cs43130_regmap = {
3913 + .reg_bits = 24,
3914 + .pad_bits = 8,
3915 + .val_bits = 8,
3916 +
3917 + .max_register = CS43130_LASTREG,
3918 + .reg_defaults = cs43130_reg_defaults,
3919 + .num_reg_defaults = ARRAY_SIZE(cs43130_reg_defaults),
3920 + .readable_reg = cs43130_readable_register,
3921 + .precious_reg = cs43130_precious_register,
3922 + .volatile_reg = cs43130_volatile_register,
3923 + .cache_type = REGCACHE_RBTREE,
3924 + /* needed for regcache_sync */
3925 + .use_single_read = true,
3926 + .use_single_write = true,
3927 +};
3928 +
3929 +static u16 const cs43130_dc_threshold[CS43130_DC_THRESHOLD] = {
3930 + 50,
3931 + 120,
3932 +};
3933 +
3934 +static int cs43130_handle_device_data(struct i2c_client *i2c_client,
3935 + struct cs43130_priv *cs43130)
3936 +{
3937 + struct device_node *np = i2c_client->dev.of_node;
3938 + unsigned int val;
3939 + int i;
3940 +
3941 + if (of_property_read_u32(np, "cirrus,xtal-ibias", &val) < 0) {
3942 + /* Crystal is unused. System clock is used for external MCLK */
3943 + cs43130->xtal_ibias = CS43130_XTAL_UNUSED;
3944 + return 0;
3945 + }
3946 +
3947 + switch (val) {
3948 + case 1:
3949 + cs43130->xtal_ibias = CS43130_XTAL_IBIAS_7_5UA;
3950 + break;
3951 + case 2:
3952 + cs43130->xtal_ibias = CS43130_XTAL_IBIAS_12_5UA;
3953 + break;
3954 + case 3:
3955 + cs43130->xtal_ibias = CS43130_XTAL_IBIAS_15UA;
3956 + break;
3957 + default:
3958 + dev_err(&i2c_client->dev,
3959 + "Invalid cirrus,xtal-ibias value: %d\n", val);
3960 + return -EINVAL;
3961 + }
3962 +
3963 + cs43130->dc_meas = of_property_read_bool(np, "cirrus,dc-measure");
3964 + cs43130->ac_meas = of_property_read_bool(np, "cirrus,ac-measure");
3965 +
3966 + if (of_property_read_u16_array(np, "cirrus,ac-freq", cs43130->ac_freq,
3967 + CS43130_AC_FREQ) < 0) {
3968 + for (i = 0; i < CS43130_AC_FREQ; i++)
3969 + cs43130->ac_freq[i] = cs43130_ac_freq[i];
3970 + }
3971 +
3972 + if (of_property_read_u16_array(np, "cirrus,dc-threshold",
3973 + cs43130->dc_threshold,
3974 + CS43130_DC_THRESHOLD) < 0) {
3975 + for (i = 0; i < CS43130_DC_THRESHOLD; i++)
3976 + cs43130->dc_threshold[i] = cs43130_dc_threshold[i];
3977 + }
3978 +
3979 + return 0;
3980 +}
3981 +
3982 +
3983 +static int allo_cs43130_component_probe(struct i2c_client *i2c)
3984 +{
3985 + struct regmap *regmap;
3986 + struct regmap_config config = cs43130_regmap;
3987 + struct device *dev = &i2c->dev;
3988 + struct cs43130_priv *cs43130;
3989 + unsigned int devid = 0;
3990 + unsigned int reg;
3991 + int ret;
3992 +
3993 + regmap = devm_regmap_init_i2c(i2c, &config);
3994 + if (IS_ERR(regmap))
3995 + return PTR_ERR(regmap);
3996 +
3997 + cs43130 = devm_kzalloc(dev, sizeof(struct cs43130_priv),
3998 + GFP_KERNEL);
3999 + if (!cs43130)
4000 + return -ENOMEM;
4001 +
4002 + dev_set_drvdata(dev, cs43130);
4003 + cs43130->regmap = regmap;
4004 +
4005 + if (i2c->dev.of_node) {
4006 + ret = cs43130_handle_device_data(i2c, cs43130);
4007 + if (ret != 0)
4008 + return ret;
4009 + }
4010 + usleep_range(2000, 2050);
4011 +
4012 + ret = regmap_read(cs43130->regmap, CS43130_DEVID_AB, &reg);
4013 + devid = (reg & 0xFF) << 12;
4014 + ret = regmap_read(cs43130->regmap, CS43130_DEVID_CD, &reg);
4015 + devid |= (reg & 0xFF) << 4;
4016 + ret = regmap_read(cs43130->regmap, CS43130_DEVID_E, &reg);
4017 + devid |= (reg & 0xF0) >> 4;
4018 + if (devid != CS43198_CHIP_ID) {
4019 + dev_err(dev, "Failed to read Chip or wrong Chip id: %d\n", ret);
4020 + return ret;
4021 + }
4022 +
4023 + cs43130->mclk_int_src = CS43130_MCLK_SRC_RCO;
4024 + msleep(20);
4025 +
4026 + ret = snd_soc_register_component(dev, &cs43130_component_driver,
4027 + &cs43130_codec_dai, 1);
4028 + if (ret != 0) {
4029 + dev_err(dev, "failed to register codec: %d\n", ret);
4030 + return ret;
4031 + }
4032 + regmap_update_bits(cs43130->regmap, CS43130_PAD_INT_CFG,
4033 + CS43130_ASP_3ST_MASK, 0);
4034 + regmap_update_bits(cs43130->regmap, CS43130_PAD_INT_CFG,
4035 + CS43130_XSP_3ST_MASK, 1);
4036 + regmap_update_bits(cs43130->regmap, CS43130_PWDN_CTL,
4037 + CS43130_PDN_HP_MASK, 1 << CS43130_PDN_HP_SHIFT);
4038 + msleep(20);
4039 + regmap_write(cs43130->regmap, CS43130_CLASS_H_CTL, 0x06);
4040 + snd_allo_clk44gpio = devm_gpiod_get(dev, "clock44", GPIOD_OUT_HIGH);
4041 + if (IS_ERR(snd_allo_clk44gpio))
4042 + dev_err(dev, "devm_gpiod_get() failed\n");
4043 +
4044 + snd_allo_clk48gpio = devm_gpiod_get(dev, "clock48", GPIOD_OUT_LOW);
4045 + if (IS_ERR(snd_allo_clk48gpio))
4046 + dev_err(dev, "devm_gpiod_get() failed\n");
4047 +
4048 + return 0;
4049 +}
4050 +
4051 +static void allo_cs43130_component_remove(struct i2c_client *i2c)
4052 +{
4053 + snd_soc_unregister_component(&i2c->dev);
4054 +}
4055 +
4056 +static const struct i2c_device_id allo_cs43130_component_id[] = {
4057 + { "allo-cs43198", },
4058 + { }
4059 +};
4060 +MODULE_DEVICE_TABLE(i2c, allo_cs43130_component_id);
4061 +
4062 +static const struct of_device_id allo_cs43130_codec_of_match[] = {
4063 + { .compatible = "allo,allo-cs43198", },
4064 + { }
4065 +};
4066 +MODULE_DEVICE_TABLE(of, allo_cs43130_codec_of_match);
4067 +
4068 +static struct i2c_driver allo_cs43130_component_driver = {
4069 + .probe = allo_cs43130_component_probe,
4070 + .remove = allo_cs43130_component_remove,
4071 + .id_table = allo_cs43130_component_id,
4072 + .driver = {
4073 + .name = "allo-cs43198",
4074 + .of_match_table = allo_cs43130_codec_of_match,
4075 + },
4076 +};
4077 +
4078 +module_i2c_driver(allo_cs43130_component_driver);
4079 +
4080 +MODULE_DESCRIPTION("ASoC Allo Boss2 Codec Driver");
4081 +MODULE_AUTHOR("Sudeepkumar <sudeepkumar@cem-solutions.net>");
4082 +MODULE_LICENSE("GPL v2");
4083 --- /dev/null
4084 +++ b/sound/soc/bcm/allo-katana-codec.c
4085 @@ -0,0 +1,386 @@
4086 +/*
4087 + * Driver for the ALLO KATANA CODEC
4088 + *
4089 + * Author: Jaikumar <jaikumar@cem-solutions.net>
4090 + * Copyright 2018
4091 + *
4092 + * This program is free software; you can redistribute it and/or
4093 + * modify it under the terms of the GNU General Public License
4094 + * version 2 as published by the Free Software Foundation.
4095 + *
4096 + * This program is distributed in the hope that it will be useful, but
4097 + * WITHOUT ANY WARRANTY; without even the implied warranty of
4098 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4099 + * General Public License for more details.
4100 + */
4101 +
4102 +
4103 +#include <linux/init.h>
4104 +#include <linux/module.h>
4105 +#include <linux/clk.h>
4106 +#include <linux/kernel.h>
4107 +#include <linux/regmap.h>
4108 +#include <linux/regulator/consumer.h>
4109 +#include <linux/gcd.h>
4110 +#include <sound/soc.h>
4111 +#include <sound/soc-dapm.h>
4112 +#include <sound/pcm_params.h>
4113 +#include <sound/tlv.h>
4114 +#include <linux/i2c.h>
4115 +
4116 +
4117 +#define KATANA_CODEC_CHIP_ID 0x30
4118 +#define KATANA_CODEC_VIRT_BASE 0x100
4119 +#define KATANA_CODEC_PAGE 0
4120 +
4121 +#define KATANA_CODEC_CHIP_ID_REG (KATANA_CODEC_VIRT_BASE + 0)
4122 +#define KATANA_CODEC_RESET (KATANA_CODEC_VIRT_BASE + 1)
4123 +#define KATANA_CODEC_VOLUME_1 (KATANA_CODEC_VIRT_BASE + 2)
4124 +#define KATANA_CODEC_VOLUME_2 (KATANA_CODEC_VIRT_BASE + 3)
4125 +#define KATANA_CODEC_MUTE (KATANA_CODEC_VIRT_BASE + 4)
4126 +#define KATANA_CODEC_DSP_PROGRAM (KATANA_CODEC_VIRT_BASE + 5)
4127 +#define KATANA_CODEC_DEEMPHASIS (KATANA_CODEC_VIRT_BASE + 6)
4128 +#define KATANA_CODEC_DOP (KATANA_CODEC_VIRT_BASE + 7)
4129 +#define KATANA_CODEC_FORMAT (KATANA_CODEC_VIRT_BASE + 8)
4130 +#define KATANA_CODEC_COMMAND (KATANA_CODEC_VIRT_BASE + 9)
4131 +#define KATANA_CODEC_MUTE_STREAM (KATANA_CODEC_VIRT_BASE + 10)
4132 +
4133 +#define KATANA_CODEC_MAX_REGISTER (KATANA_CODEC_VIRT_BASE + 10)
4134 +
4135 +#define KATANA_CODEC_FMT 0xff
4136 +#define KATANA_CODEC_CHAN_MONO 0x00
4137 +#define KATANA_CODEC_CHAN_STEREO 0x80
4138 +#define KATANA_CODEC_ALEN_16 0x10
4139 +#define KATANA_CODEC_ALEN_24 0x20
4140 +#define KATANA_CODEC_ALEN_32 0x30
4141 +#define KATANA_CODEC_RATE_11025 0x01
4142 +#define KATANA_CODEC_RATE_22050 0x02
4143 +#define KATANA_CODEC_RATE_32000 0x03
4144 +#define KATANA_CODEC_RATE_44100 0x04
4145 +#define KATANA_CODEC_RATE_48000 0x05
4146 +#define KATANA_CODEC_RATE_88200 0x06
4147 +#define KATANA_CODEC_RATE_96000 0x07
4148 +#define KATANA_CODEC_RATE_176400 0x08
4149 +#define KATANA_CODEC_RATE_192000 0x09
4150 +#define KATANA_CODEC_RATE_352800 0x0a
4151 +#define KATANA_CODEC_RATE_384000 0x0b
4152 +
4153 +
4154 +struct katana_codec_priv {
4155 + struct regmap *regmap;
4156 + int fmt;
4157 +};
4158 +
4159 +static const struct reg_default katana_codec_reg_defaults[] = {
4160 + { KATANA_CODEC_RESET, 0x00 },
4161 + { KATANA_CODEC_VOLUME_1, 0xF0 },
4162 + { KATANA_CODEC_VOLUME_2, 0xF0 },
4163 + { KATANA_CODEC_MUTE, 0x00 },
4164 + { KATANA_CODEC_DSP_PROGRAM, 0x04 },
4165 + { KATANA_CODEC_DEEMPHASIS, 0x00 },
4166 + { KATANA_CODEC_DOP, 0x00 },
4167 + { KATANA_CODEC_FORMAT, 0xb4 },
4168 +};
4169 +
4170 +static const char * const katana_codec_dsp_program_texts[] = {
4171 + "Linear Phase Fast Roll-off Filter",
4172 + "Linear Phase Slow Roll-off Filter",
4173 + "Minimum Phase Fast Roll-off Filter",
4174 + "Minimum Phase Slow Roll-off Filter",
4175 + "Apodizing Fast Roll-off Filter",
4176 + "Corrected Minimum Phase Fast Roll-off Filter",
4177 + "Brick Wall Filter",
4178 +};
4179 +
4180 +static const unsigned int katana_codec_dsp_program_values[] = {
4181 + 0,
4182 + 1,
4183 + 2,
4184 + 3,
4185 + 4,
4186 + 6,
4187 + 7,
4188 +};
4189 +
4190 +static SOC_VALUE_ENUM_SINGLE_DECL(katana_codec_dsp_program,
4191 + KATANA_CODEC_DSP_PROGRAM, 0, 0x07,
4192 + katana_codec_dsp_program_texts,
4193 + katana_codec_dsp_program_values);
4194 +
4195 +static const char * const katana_codec_deemphasis_texts[] = {
4196 + "Bypass",
4197 + "32kHz",
4198 + "44.1kHz",
4199 + "48kHz",
4200 +};
4201 +
4202 +static const unsigned int katana_codec_deemphasis_values[] = {
4203 + 0,
4204 + 1,
4205 + 2,
4206 + 3,
4207 +};
4208 +
4209 +static SOC_VALUE_ENUM_SINGLE_DECL(katana_codec_deemphasis,
4210 + KATANA_CODEC_DEEMPHASIS, 0, 0x03,
4211 + katana_codec_deemphasis_texts,
4212 + katana_codec_deemphasis_values);
4213 +
4214 +static const SNDRV_CTL_TLVD_DECLARE_DB_MINMAX(master_tlv, -12750, 0);
4215 +
4216 +static const struct snd_kcontrol_new katana_codec_controls[] = {
4217 + SOC_DOUBLE_R_TLV("Master Playback Volume", KATANA_CODEC_VOLUME_1,
4218 + KATANA_CODEC_VOLUME_2, 0, 255, 1, master_tlv),
4219 + SOC_DOUBLE("Master Playback Switch", KATANA_CODEC_MUTE, 0, 0, 1, 1),
4220 + SOC_ENUM("DSP Program Route", katana_codec_dsp_program),
4221 + SOC_ENUM("Deemphasis Route", katana_codec_deemphasis),
4222 + SOC_SINGLE("DoP Playback Switch", KATANA_CODEC_DOP, 0, 1, 1)
4223 +};
4224 +
4225 +static bool katana_codec_readable_register(struct device *dev,
4226 + unsigned int reg)
4227 +{
4228 + switch (reg) {
4229 + case KATANA_CODEC_CHIP_ID_REG:
4230 + return true;
4231 + default:
4232 + return reg < 0xff;
4233 + }
4234 +}
4235 +
4236 +static int katana_codec_hw_params(struct snd_pcm_substream *substream,
4237 + struct snd_pcm_hw_params *params,
4238 + struct snd_soc_dai *dai)
4239 +{
4240 + struct snd_soc_component *component = dai->component;
4241 + struct katana_codec_priv *katana_codec =
4242 + snd_soc_component_get_drvdata(component);
4243 + int fmt = 0;
4244 + int ret;
4245 +
4246 + dev_dbg(component->card->dev, "hw_params %u Hz, %u channels, %u bits\n",
4247 + params_rate(params),
4248 + params_channels(params),
4249 + params_width(params));
4250 +
4251 + switch (katana_codec->fmt & SND_SOC_DAIFMT_MASTER_MASK) {
4252 + case SND_SOC_DAIFMT_CBM_CFM: // master
4253 + if (params_channels(params) == 2)
4254 + fmt = KATANA_CODEC_CHAN_STEREO;
4255 + else
4256 + fmt = KATANA_CODEC_CHAN_MONO;
4257 +
4258 + switch (params_width(params)) {
4259 + case 16:
4260 + fmt |= KATANA_CODEC_ALEN_16;
4261 + break;
4262 + case 24:
4263 + fmt |= KATANA_CODEC_ALEN_24;
4264 + break;
4265 + case 32:
4266 + fmt |= KATANA_CODEC_ALEN_32;
4267 + break;
4268 + default:
4269 + dev_err(component->card->dev, "Bad frame size: %d\n",
4270 + params_width(params));
4271 + return -EINVAL;
4272 + }
4273 +
4274 + switch (params_rate(params)) {
4275 + case 44100:
4276 + fmt |= KATANA_CODEC_RATE_44100;
4277 + break;
4278 + case 48000:
4279 + fmt |= KATANA_CODEC_RATE_48000;
4280 + break;
4281 + case 88200:
4282 + fmt |= KATANA_CODEC_RATE_88200;
4283 + break;
4284 + case 96000:
4285 + fmt |= KATANA_CODEC_RATE_96000;
4286 + break;
4287 + case 176400:
4288 + fmt |= KATANA_CODEC_RATE_176400;
4289 + break;
4290 + case 192000:
4291 + fmt |= KATANA_CODEC_RATE_192000;
4292 + break;
4293 + case 352800:
4294 + fmt |= KATANA_CODEC_RATE_352800;
4295 + break;
4296 + case 384000:
4297 + fmt |= KATANA_CODEC_RATE_384000;
4298 + break;
4299 + default:
4300 + dev_err(component->card->dev, "Bad sample rate: %d\n",
4301 + params_rate(params));
4302 + return -EINVAL;
4303 + }
4304 +
4305 + ret = regmap_write(katana_codec->regmap, KATANA_CODEC_FORMAT,
4306 + fmt);
4307 + if (ret != 0) {
4308 + dev_err(component->card->dev, "Failed to set format: %d\n", ret);
4309 + return ret;
4310 + }
4311 + break;
4312 +
4313 + case SND_SOC_DAIFMT_CBS_CFS:
4314 + break;
4315 +
4316 + default:
4317 + return -EINVAL;
4318 + }
4319 +
4320 + return 0;
4321 +}
4322 +
4323 +static int katana_codec_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
4324 +{
4325 + struct snd_soc_component *component = dai->component;
4326 + struct katana_codec_priv *katana_codec =
4327 + snd_soc_component_get_drvdata(component);
4328 +
4329 + katana_codec->fmt = fmt;
4330 +
4331 + return 0;
4332 +}
4333 +
4334 +int katana_codec_dai_mute_stream(struct snd_soc_dai *dai, int mute,
4335 + int stream)
4336 +{
4337 + struct snd_soc_component *component = dai->component;
4338 + struct katana_codec_priv *katana_codec =
4339 + snd_soc_component_get_drvdata(component);
4340 + int ret = 0;
4341 +
4342 + ret = regmap_write(katana_codec->regmap, KATANA_CODEC_MUTE_STREAM,
4343 + mute);
4344 + if (ret != 0) {
4345 + dev_err(component->card->dev, "Failed to set mute: %d\n", ret);
4346 + return ret;
4347 + }
4348 + return ret;
4349 +}
4350 +
4351 +static const struct snd_soc_dai_ops katana_codec_dai_ops = {
4352 + .mute_stream = katana_codec_dai_mute_stream,
4353 + .hw_params = katana_codec_hw_params,
4354 + .set_fmt = katana_codec_set_fmt,
4355 +};
4356 +
4357 +static struct snd_soc_dai_driver katana_codec_dai = {
4358 + .name = "allo-katana-codec",
4359 + .playback = {
4360 + .stream_name = "Playback",
4361 + .channels_min = 2,
4362 + .channels_max = 2,
4363 + .rates = SNDRV_PCM_RATE_CONTINUOUS,
4364 + .rate_min = 44100,
4365 + .rate_max = 384000,
4366 + .formats = SNDRV_PCM_FMTBIT_S16_LE |
4367 + SNDRV_PCM_FMTBIT_S32_LE
4368 + },
4369 + .ops = &katana_codec_dai_ops,
4370 +};
4371 +
4372 +static struct snd_soc_component_driver katana_codec_component_driver = {
4373 + .idle_bias_on = true,
4374 +
4375 + .controls = katana_codec_controls,
4376 + .num_controls = ARRAY_SIZE(katana_codec_controls),
4377 +};
4378 +
4379 +static const struct regmap_range_cfg katana_codec_range = {
4380 + .name = "Pages", .range_min = KATANA_CODEC_VIRT_BASE,
4381 + .range_max = KATANA_CODEC_MAX_REGISTER,
4382 + .selector_reg = KATANA_CODEC_PAGE,
4383 + .selector_mask = 0xff,
4384 + .window_start = 0, .window_len = 0x100,
4385 +};
4386 +
4387 +const struct regmap_config katana_codec_regmap = {
4388 + .reg_bits = 8,
4389 + .val_bits = 8,
4390 +
4391 + .ranges = &katana_codec_range,
4392 + .num_ranges = 1,
4393 +
4394 + .max_register = KATANA_CODEC_MAX_REGISTER,
4395 + .readable_reg = katana_codec_readable_register,
4396 + .reg_defaults = katana_codec_reg_defaults,
4397 + .num_reg_defaults = ARRAY_SIZE(katana_codec_reg_defaults),
4398 + .cache_type = REGCACHE_RBTREE,
4399 +};
4400 +
4401 +static int allo_katana_component_probe(struct i2c_client *i2c)
4402 +{
4403 + struct regmap *regmap;
4404 + struct regmap_config config = katana_codec_regmap;
4405 + struct device *dev = &i2c->dev;
4406 + struct katana_codec_priv *katana_codec;
4407 + unsigned int chip_id = 0;
4408 + int ret;
4409 +
4410 + regmap = devm_regmap_init_i2c(i2c, &config);
4411 + if (IS_ERR(regmap))
4412 + return PTR_ERR(regmap);
4413 +
4414 + katana_codec = devm_kzalloc(dev, sizeof(struct katana_codec_priv),
4415 + GFP_KERNEL);
4416 + if (!katana_codec)
4417 + return -ENOMEM;
4418 +
4419 + dev_set_drvdata(dev, katana_codec);
4420 + katana_codec->regmap = regmap;
4421 +
4422 + ret = regmap_read(regmap, KATANA_CODEC_CHIP_ID_REG, &chip_id);
4423 + if ((ret != 0) || (chip_id != KATANA_CODEC_CHIP_ID)) {
4424 + dev_err(dev, "Failed to read Chip or wrong Chip id: %d\n", ret);
4425 + return ret;
4426 + }
4427 + regmap_update_bits(regmap, KATANA_CODEC_RESET, 0x01, 0x01);
4428 + msleep(10);
4429 +
4430 + ret = snd_soc_register_component(dev, &katana_codec_component_driver,
4431 + &katana_codec_dai, 1);
4432 + if (ret != 0) {
4433 + dev_err(dev, "failed to register codec: %d\n", ret);
4434 + return ret;
4435 + }
4436 +
4437 + return 0;
4438 +}
4439 +
4440 +static void allo_katana_component_remove(struct i2c_client *i2c)
4441 +{
4442 + snd_soc_unregister_component(&i2c->dev);
4443 +}
4444 +
4445 +static const struct i2c_device_id allo_katana_component_id[] = {
4446 + { "allo-katana-codec", },
4447 + { }
4448 +};
4449 +MODULE_DEVICE_TABLE(i2c, allo_katana_component_id);
4450 +
4451 +static const struct of_device_id allo_katana_codec_of_match[] = {
4452 + { .compatible = "allo,allo-katana-codec", },
4453 + { }
4454 +};
4455 +MODULE_DEVICE_TABLE(of, allo_katana_codec_of_match);
4456 +
4457 +static struct i2c_driver allo_katana_component_driver = {
4458 + .probe = allo_katana_component_probe,
4459 + .remove = allo_katana_component_remove,
4460 + .id_table = allo_katana_component_id,
4461 + .driver = {
4462 + .name = "allo-katana-codec",
4463 + .of_match_table = allo_katana_codec_of_match,
4464 + },
4465 +};
4466 +
4467 +module_i2c_driver(allo_katana_component_driver);
4468 +
4469 +MODULE_DESCRIPTION("ASoC Allo Katana Codec Driver");
4470 +MODULE_AUTHOR("Jaikumar <jaikumar@cem-solutions.net>");
4471 +MODULE_LICENSE("GPL v2");
4472 --- /dev/null
4473 +++ b/sound/soc/bcm/allo-piano-dac-plus.c
4474 @@ -0,0 +1,1064 @@
4475 +/*
4476 + * ALSA ASoC Machine Driver for Allo Piano DAC Plus Subwoofer
4477 + *
4478 + * Author: Baswaraj K <jaikumar@cem-solutions.net>
4479 + * Copyright 2020
4480 + * based on code by David Knell <david.knell@gmail.com)
4481 + * based on code by Daniel Matuschek <info@crazy-audio.com>
4482 + * based on code by Florian Meier <florian.meier@koalo.de>
4483 + *
4484 + * This program is free software; you can redistribute it and/or
4485 + * modify it under the terms of the GNU General Public License
4486 + * version 2 as published by the Free Software Foundation.
4487 + *
4488 + * This program is distributed in the hope that it will be useful, but
4489 + * WITHOUT ANY WARRANTY; without even the implied warranty of
4490 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4491 + * General Public License for more details.
4492 + */
4493 +
4494 +#include <linux/module.h>
4495 +#include <linux/platform_device.h>
4496 +#include <linux/gpio/consumer.h>
4497 +#include <sound/core.h>
4498 +#include <sound/pcm.h>
4499 +#include <sound/pcm_params.h>
4500 +#include <sound/soc.h>
4501 +#include <linux/firmware.h>
4502 +#include <linux/delay.h>
4503 +#include <sound/tlv.h>
4504 +#include "../codecs/pcm512x.h"
4505 +
4506 +#define P_DAC_LEFT_MUTE 0x10
4507 +#define P_DAC_RIGHT_MUTE 0x01
4508 +#define P_DAC_MUTE 0x11
4509 +#define P_DAC_UNMUTE 0x00
4510 +#define P_MUTE 1
4511 +#define P_UNMUTE 0
4512 +
4513 +struct dsp_code {
4514 + char i2c_addr;
4515 + char offset;
4516 + char val;
4517 +};
4518 +
4519 +struct glb_pool {
4520 + struct mutex lock;
4521 + unsigned int dual_mode;
4522 + unsigned int set_lowpass;
4523 + unsigned int set_mode;
4524 + unsigned int set_rate;
4525 + unsigned int dsp_page_number;
4526 +};
4527 +
4528 +static bool digital_gain_0db_limit = true;
4529 +bool glb_mclk;
4530 +
4531 +static struct gpio_desc *mute_gpio[2];
4532 +
4533 +static const char * const allo_piano_mode_texts[] = {
4534 + "None",
4535 + "2.0",
4536 + "2.1",
4537 + "2.2",
4538 +};
4539 +
4540 +static SOC_ENUM_SINGLE_DECL(allo_piano_mode_enum,
4541 + 0, 0, allo_piano_mode_texts);
4542 +
4543 +static const char * const allo_piano_dual_mode_texts[] = {
4544 + "None",
4545 + "Dual-Mono",
4546 + "Dual-Stereo",
4547 +};
4548 +
4549 +static SOC_ENUM_SINGLE_DECL(allo_piano_dual_mode_enum,
4550 + 0, 0, allo_piano_dual_mode_texts);
4551 +
4552 +static const char * const allo_piano_dsp_low_pass_texts[] = {
4553 + "60",
4554 + "70",
4555 + "80",
4556 + "90",
4557 + "100",
4558 + "110",
4559 + "120",
4560 + "130",
4561 + "140",
4562 + "150",
4563 + "160",
4564 + "170",
4565 + "180",
4566 + "190",
4567 + "200",
4568 +};
4569 +
4570 +static SOC_ENUM_SINGLE_DECL(allo_piano_enum,
4571 + 0, 0, allo_piano_dsp_low_pass_texts);
4572 +
4573 +static int __snd_allo_piano_dsp_program(struct snd_soc_pcm_runtime *rtd,
4574 + unsigned int mode, unsigned int rate, unsigned int lowpass)
4575 +{
4576 + const struct firmware *fw;
4577 + struct snd_soc_card *card = rtd->card;
4578 + struct glb_pool *glb_ptr = card->drvdata;
4579 + char firmware_name[60];
4580 + int ret = 0, dac = 0;
4581 +
4582 + if (rate <= 46000)
4583 + rate = 44100;
4584 + else if (rate <= 68000)
4585 + rate = 48000;
4586 + else if (rate <= 92000)
4587 + rate = 88200;
4588 + else if (rate <= 136000)
4589 + rate = 96000;
4590 + else if (rate <= 184000)
4591 + rate = 176400;
4592 + else
4593 + rate = 192000;
4594 +
4595 + if (lowpass > 14)
4596 + glb_ptr->set_lowpass = lowpass = 0;
4597 +
4598 + if (mode > 3)
4599 + glb_ptr->set_mode = mode = 0;
4600 +
4601 + if (mode > 0)
4602 + glb_ptr->dual_mode = 0;
4603 +
4604 + /* same configuration loaded */
4605 + if ((rate == glb_ptr->set_rate) && (lowpass == glb_ptr->set_lowpass)
4606 + && (mode == glb_ptr->set_mode))
4607 + return 0;
4608 +
4609 + switch (mode) {
4610 + case 0: /* None */
4611 + return 1;
4612 +
4613 + case 1: /* 2.0 */
4614 + snd_soc_component_write(asoc_rtd_to_codec(rtd, 0)->component,
4615 + PCM512x_MUTE, P_DAC_UNMUTE);
4616 + snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component,
4617 + PCM512x_MUTE, P_DAC_MUTE);
4618 + glb_ptr->set_rate = rate;
4619 + glb_ptr->set_mode = mode;
4620 + glb_ptr->set_lowpass = lowpass;
4621 + return 1;
4622 +
4623 + default:
4624 + snd_soc_component_write(asoc_rtd_to_codec(rtd, 0)->component,
4625 + PCM512x_MUTE, P_DAC_UNMUTE);
4626 + snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component,
4627 + PCM512x_MUTE, P_DAC_UNMUTE);
4628 + }
4629 +
4630 + for (dac = 0; dac < rtd->dai_link->num_codecs; dac++) {
4631 + struct dsp_code *dsp_code_read;
4632 + int i = 1;
4633 +
4634 + if (dac == 0) { /* high */
4635 + snprintf(firmware_name, sizeof(firmware_name),
4636 + "allo/piano/2.2/allo-piano-dsp-%d-%d-%d.bin",
4637 + rate, ((lowpass * 10) + 60), dac);
4638 + } else { /* low */
4639 + snprintf(firmware_name, sizeof(firmware_name),
4640 + "allo/piano/2.%d/allo-piano-dsp-%d-%d-%d.bin",
4641 + (mode - 1), rate, ((lowpass * 10) + 60), dac);
4642 + }
4643 +
4644 + dev_info(rtd->card->dev, "Dsp Firmware File Name: %s\n",
4645 + firmware_name);
4646 +
4647 + ret = request_firmware(&fw, firmware_name, rtd->card->dev);
4648 + if (ret < 0) {
4649 + dev_err(rtd->card->dev,
4650 + "Error: Allo Piano Firmware %s missing. %d\n",
4651 + firmware_name, ret);
4652 + goto err;
4653 + }
4654 +
4655 + while (i < (fw->size - 1)) {
4656 + dsp_code_read = (struct dsp_code *)&fw->data[i];
4657 +
4658 + if (dsp_code_read->offset == 0) {
4659 + glb_ptr->dsp_page_number = dsp_code_read->val;
4660 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, dac)->component,
4661 + PCM512x_PAGE_BASE(0),
4662 + dsp_code_read->val);
4663 +
4664 + } else if (dsp_code_read->offset != 0) {
4665 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, dac)->component,
4666 + (PCM512x_PAGE_BASE(
4667 + glb_ptr->dsp_page_number) +
4668 + dsp_code_read->offset),
4669 + dsp_code_read->val);
4670 + }
4671 + if (ret < 0) {
4672 + dev_err(rtd->card->dev,
4673 + "Failed to write Register: %d\n", ret);
4674 + release_firmware(fw);
4675 + goto err;
4676 + }
4677 + i = i + 3;
4678 + }
4679 + release_firmware(fw);
4680 + }
4681 + glb_ptr->set_rate = rate;
4682 + glb_ptr->set_mode = mode;
4683 + glb_ptr->set_lowpass = lowpass;
4684 + return 1;
4685 +
4686 +err:
4687 + return ret;
4688 +}
4689 +
4690 +static int snd_allo_piano_dsp_program(struct snd_soc_pcm_runtime *rtd,
4691 + unsigned int mode, unsigned int rate, unsigned int lowpass)
4692 +{
4693 + struct snd_soc_card *card = rtd->card;
4694 + struct glb_pool *glb_ptr = card->drvdata;
4695 + int ret = 0;
4696 +
4697 + mutex_lock(&glb_ptr->lock);
4698 +
4699 + ret = __snd_allo_piano_dsp_program(rtd, mode, rate, lowpass);
4700 +
4701 + mutex_unlock(&glb_ptr->lock);
4702 +
4703 + return ret;
4704 +}
4705 +
4706 +static int snd_allo_piano_dual_mode_get(struct snd_kcontrol *kcontrol,
4707 + struct snd_ctl_elem_value *ucontrol)
4708 +{
4709 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
4710 + struct glb_pool *glb_ptr = card->drvdata;
4711 +
4712 + ucontrol->value.integer.value[0] = glb_ptr->dual_mode;
4713 +
4714 + return 0;
4715 +}
4716 +
4717 +static int snd_allo_piano_dual_mode_put(struct snd_kcontrol *kcontrol,
4718 + struct snd_ctl_elem_value *ucontrol)
4719 +{
4720 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
4721 + struct glb_pool *glb_ptr = card->drvdata;
4722 + struct snd_soc_pcm_runtime *rtd;
4723 + struct snd_card *snd_card_ptr = card->snd_card;
4724 + struct snd_kcontrol *kctl;
4725 + struct soc_mixer_control *mc;
4726 + unsigned int left_val = 0, right_val = 0;
4727 +
4728 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
4729 +
4730 + if (ucontrol->value.integer.value[0] > 0) {
4731 + glb_ptr->dual_mode = ucontrol->value.integer.value[0];
4732 + glb_ptr->set_mode = 0;
4733 + } else {
4734 + if (glb_ptr->set_mode <= 0) {
4735 + glb_ptr->dual_mode = 1;
4736 + glb_ptr->set_mode = 0;
4737 + } else {
4738 + glb_ptr->dual_mode = 0;
4739 + return 0;
4740 + }
4741 + }
4742 +
4743 + if (glb_ptr->dual_mode == 1) { // Dual Mono
4744 + snd_soc_component_write(asoc_rtd_to_codec(rtd, 0)->component,
4745 + PCM512x_MUTE, P_DAC_RIGHT_MUTE);
4746 + snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component,
4747 + PCM512x_MUTE, P_DAC_LEFT_MUTE);
4748 + snd_soc_component_write(asoc_rtd_to_codec(rtd, 0)->component,
4749 + PCM512x_DIGITAL_VOLUME_3, 0xff);
4750 + snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component,
4751 + PCM512x_DIGITAL_VOLUME_2, 0xff);
4752 +
4753 + list_for_each_entry(kctl, &snd_card_ptr->controls, list) {
4754 + if (!strncmp(kctl->id.name, "Main Digital Playback Volume",
4755 + sizeof(kctl->id.name))) {
4756 + mc = (struct soc_mixer_control *)
4757 + kctl->private_value;
4758 + mc->rreg = mc->reg;
4759 + break;
4760 + }
4761 + if (!strncmp(kctl->id.name, "Sub Digital Playback Volume",
4762 + sizeof(kctl->id.name))) {
4763 + mc = (struct soc_mixer_control *)
4764 + kctl->private_value;
4765 + mc->rreg = mc->reg;
4766 + break;
4767 + }
4768 + }
4769 + } else {
4770 + left_val = snd_soc_component_read(asoc_rtd_to_codec(rtd, 0)->component,
4771 + PCM512x_DIGITAL_VOLUME_2);
4772 + right_val = snd_soc_component_read(asoc_rtd_to_codec(rtd, 1)->component,
4773 + PCM512x_DIGITAL_VOLUME_3);
4774 +
4775 + list_for_each_entry(kctl, &snd_card_ptr->controls, list) {
4776 + if (!strncmp(kctl->id.name, "Main Digital Playback Volume",
4777 + sizeof(kctl->id.name))) {
4778 + mc = (struct soc_mixer_control *)
4779 + kctl->private_value;
4780 + mc->rreg = PCM512x_DIGITAL_VOLUME_3;
4781 + break;
4782 + }
4783 + if (!strncmp(kctl->id.name, "Sub Digital Playback Volume",
4784 + sizeof(kctl->id.name))) {
4785 + mc = (struct soc_mixer_control *)
4786 + kctl->private_value;
4787 + mc->rreg = PCM512x_DIGITAL_VOLUME_2;
4788 + break;
4789 + }
4790 + }
4791 +
4792 + snd_soc_component_write(asoc_rtd_to_codec(rtd, 0)->component,
4793 + PCM512x_DIGITAL_VOLUME_3, left_val);
4794 + snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component,
4795 + PCM512x_DIGITAL_VOLUME_2, right_val);
4796 + snd_soc_component_write(asoc_rtd_to_codec(rtd, 0)->component,
4797 + PCM512x_MUTE, P_DAC_UNMUTE);
4798 + snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component,
4799 + PCM512x_MUTE, P_DAC_UNMUTE);
4800 + }
4801 +
4802 + return 0;
4803 +}
4804 +
4805 +static int snd_allo_piano_mode_get(struct snd_kcontrol *kcontrol,
4806 + struct snd_ctl_elem_value *ucontrol)
4807 +{
4808 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
4809 + struct glb_pool *glb_ptr = card->drvdata;
4810 +
4811 + ucontrol->value.integer.value[0] = glb_ptr->set_mode;
4812 + return 0;
4813 +}
4814 +
4815 +static int snd_allo_piano_mode_put(struct snd_kcontrol *kcontrol,
4816 + struct snd_ctl_elem_value *ucontrol)
4817 +{
4818 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
4819 + struct snd_soc_pcm_runtime *rtd;
4820 + struct glb_pool *glb_ptr = card->drvdata;
4821 + struct snd_card *snd_card_ptr = card->snd_card;
4822 + struct snd_kcontrol *kctl;
4823 + struct soc_mixer_control *mc;
4824 + unsigned int left_val = 0, right_val = 0;
4825 +
4826 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
4827 +
4828 + if ((glb_ptr->dual_mode == 1) &&
4829 + (ucontrol->value.integer.value[0] > 0)) {
4830 + left_val = snd_soc_component_read(asoc_rtd_to_codec(rtd, 0)->component,
4831 + PCM512x_DIGITAL_VOLUME_2);
4832 + right_val = snd_soc_component_read(asoc_rtd_to_codec(rtd, 1)->component,
4833 + PCM512x_DIGITAL_VOLUME_2);
4834 +
4835 + list_for_each_entry(kctl, &snd_card_ptr->controls, list) {
4836 + if (!strncmp(kctl->id.name, "Main Digital Playback Volume",
4837 + sizeof(kctl->id.name))) {
4838 + mc = (struct soc_mixer_control *)
4839 + kctl->private_value;
4840 + mc->rreg = PCM512x_DIGITAL_VOLUME_3;
4841 + break;
4842 + }
4843 + if (!strncmp(kctl->id.name, "Sub Digital Playback Volume",
4844 + sizeof(kctl->id.name))) {
4845 + mc = (struct soc_mixer_control *)
4846 + kctl->private_value;
4847 + mc->rreg = PCM512x_DIGITAL_VOLUME_2;
4848 + break;
4849 + }
4850 + }
4851 + snd_soc_component_write(asoc_rtd_to_codec(rtd, 0)->component,
4852 + PCM512x_DIGITAL_VOLUME_3, left_val);
4853 + snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component,
4854 + PCM512x_DIGITAL_VOLUME_3, right_val);
4855 + }
4856 +
4857 + return(snd_allo_piano_dsp_program(rtd,
4858 + ucontrol->value.integer.value[0],
4859 + glb_ptr->set_rate, glb_ptr->set_lowpass));
4860 +}
4861 +
4862 +static int snd_allo_piano_lowpass_get(struct snd_kcontrol *kcontrol,
4863 + struct snd_ctl_elem_value *ucontrol)
4864 +{
4865 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
4866 + struct glb_pool *glb_ptr = card->drvdata;
4867 +
4868 + ucontrol->value.integer.value[0] = glb_ptr->set_lowpass;
4869 + return 0;
4870 +}
4871 +
4872 +static int snd_allo_piano_lowpass_put(struct snd_kcontrol *kcontrol,
4873 + struct snd_ctl_elem_value *ucontrol)
4874 +{
4875 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
4876 + struct snd_soc_pcm_runtime *rtd;
4877 + struct glb_pool *glb_ptr = card->drvdata;
4878 +
4879 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
4880 + return(snd_allo_piano_dsp_program(rtd,
4881 + glb_ptr->set_mode, glb_ptr->set_rate,
4882 + ucontrol->value.integer.value[0]));
4883 +}
4884 +
4885 +static int pcm512x_get_reg_sub(struct snd_kcontrol *kcontrol,
4886 + struct snd_ctl_elem_value *ucontrol)
4887 +{
4888 + struct soc_mixer_control *mc =
4889 + (struct soc_mixer_control *)kcontrol->private_value;
4890 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
4891 + struct glb_pool *glb_ptr = card->drvdata;
4892 + struct snd_soc_pcm_runtime *rtd;
4893 + unsigned int left_val = 0;
4894 + unsigned int right_val = 0;
4895 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
4896 +
4897 + right_val = snd_soc_component_read(asoc_rtd_to_codec(rtd, 1)->component,
4898 + PCM512x_DIGITAL_VOLUME_3);
4899 + if (glb_ptr->dual_mode != 1) {
4900 + left_val = snd_soc_component_read(asoc_rtd_to_codec(rtd, 1)->component,
4901 + PCM512x_DIGITAL_VOLUME_2);
4902 +
4903 + } else {
4904 + left_val = right_val;
4905 + }
4906 +
4907 + ucontrol->value.integer.value[0] =
4908 + (~(left_val >> mc->shift)) & mc->max;
4909 + ucontrol->value.integer.value[1] =
4910 + (~(right_val >> mc->shift)) & mc->max;
4911 +
4912 + return 0;
4913 +}
4914 +
4915 +static int pcm512x_set_reg_sub(struct snd_kcontrol *kcontrol,
4916 + struct snd_ctl_elem_value *ucontrol)
4917 +{
4918 + struct soc_mixer_control *mc =
4919 + (struct soc_mixer_control *)kcontrol->private_value;
4920 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
4921 + struct glb_pool *glb_ptr = card->drvdata;
4922 + struct snd_soc_pcm_runtime *rtd;
4923 + unsigned int left_val = (ucontrol->value.integer.value[0] & mc->max);
4924 + unsigned int right_val = (ucontrol->value.integer.value[1] & mc->max);
4925 + int ret = 0;
4926 +
4927 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
4928 +
4929 + if (digital_gain_0db_limit) {
4930 + ret = snd_soc_limit_volume(card, "Subwoofer Playback Volume",
4931 + 207);
4932 + if (ret < 0)
4933 + dev_warn(card->dev, "Failed to set volume limit: %d\n",
4934 + ret);
4935 + }
4936 +
4937 + // When in Dual Mono, Sub vol control should not set anything.
4938 + if (glb_ptr->dual_mode != 1) { //Not in Dual Mono mode
4939 +
4940 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component,
4941 + PCM512x_DIGITAL_VOLUME_2, (~left_val));
4942 + if (ret < 0)
4943 + return ret;
4944 +
4945 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component,
4946 + PCM512x_DIGITAL_VOLUME_3, (~right_val));
4947 + if (ret < 0)
4948 + return ret;
4949 +
4950 + }
4951 +
4952 + return 1;
4953 +}
4954 +
4955 +static int pcm512x_get_reg_sub_switch(struct snd_kcontrol *kcontrol,
4956 + struct snd_ctl_elem_value *ucontrol)
4957 +{
4958 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
4959 + struct snd_soc_pcm_runtime *rtd;
4960 + int val = 0;
4961 +
4962 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
4963 + val = snd_soc_component_read(asoc_rtd_to_codec(rtd, 1)->component, PCM512x_MUTE);
4964 +
4965 + ucontrol->value.integer.value[0] =
4966 + (val & P_DAC_LEFT_MUTE) ? P_UNMUTE : P_MUTE;
4967 + ucontrol->value.integer.value[1] =
4968 + (val & P_DAC_RIGHT_MUTE) ? P_UNMUTE : P_MUTE;
4969 +
4970 + return val;
4971 +}
4972 +
4973 +static int pcm512x_set_reg_sub_switch(struct snd_kcontrol *kcontrol,
4974 + struct snd_ctl_elem_value *ucontrol)
4975 +{
4976 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
4977 + struct snd_soc_pcm_runtime *rtd;
4978 + struct glb_pool *glb_ptr = card->drvdata;
4979 + unsigned int left_val = (ucontrol->value.integer.value[0]);
4980 + unsigned int right_val = (ucontrol->value.integer.value[1]);
4981 + int ret = 0;
4982 +
4983 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
4984 + if (glb_ptr->set_mode != 1) {
4985 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component, PCM512x_MUTE,
4986 + ~((left_val & 0x01)<<4 | (right_val & 0x01)));
4987 + if (ret < 0)
4988 + return ret;
4989 + }
4990 + return 1;
4991 +
4992 +}
4993 +
4994 +static int pcm512x_get_reg_master(struct snd_kcontrol *kcontrol,
4995 + struct snd_ctl_elem_value *ucontrol)
4996 +{
4997 + struct soc_mixer_control *mc =
4998 + (struct soc_mixer_control *)kcontrol->private_value;
4999 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
5000 + struct glb_pool *glb_ptr = card->drvdata;
5001 + struct snd_soc_pcm_runtime *rtd;
5002 + unsigned int left_val = 0, right_val = 0;
5003 +
5004 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
5005 +
5006 + left_val = snd_soc_component_read(asoc_rtd_to_codec(rtd, 0)->component,
5007 + PCM512x_DIGITAL_VOLUME_2);
5008 +
5009 + if (glb_ptr->dual_mode == 1) { // in Dual Mono mode
5010 + right_val = snd_soc_component_read(asoc_rtd_to_codec(rtd, 1)->component,
5011 + PCM512x_DIGITAL_VOLUME_3);
5012 + } else {
5013 + right_val = snd_soc_component_read(asoc_rtd_to_codec(rtd, 0)->component,
5014 + PCM512x_DIGITAL_VOLUME_3);
5015 + }
5016 +
5017 + ucontrol->value.integer.value[0] =
5018 + (~(left_val >> mc->shift)) & mc->max;
5019 + ucontrol->value.integer.value[1] =
5020 + (~(right_val >> mc->shift)) & mc->max;
5021 +
5022 + return 0;
5023 +}
5024 +
5025 +static int pcm512x_set_reg_master(struct snd_kcontrol *kcontrol,
5026 + struct snd_ctl_elem_value *ucontrol)
5027 +{
5028 + struct soc_mixer_control *mc =
5029 + (struct soc_mixer_control *)kcontrol->private_value;
5030 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
5031 + struct glb_pool *glb_ptr = card->drvdata;
5032 + struct snd_soc_pcm_runtime *rtd;
5033 + unsigned int left_val = (ucontrol->value.integer.value[0] & mc->max);
5034 + unsigned int right_val = (ucontrol->value.integer.value[1] & mc->max);
5035 + int ret = 0;
5036 +
5037 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
5038 +
5039 + if (digital_gain_0db_limit) {
5040 + ret = snd_soc_limit_volume(card, "Master Playback Volume",
5041 + 207);
5042 + if (ret < 0)
5043 + dev_warn(card->dev, "Failed to set volume limit: %d\n",
5044 + ret);
5045 + }
5046 +
5047 + if (glb_ptr->dual_mode == 1) { //in Dual Mono Mode
5048 +
5049 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 0)->component,
5050 + PCM512x_DIGITAL_VOLUME_2, (~left_val));
5051 + if (ret < 0)
5052 + return ret;
5053 +
5054 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component,
5055 + PCM512x_DIGITAL_VOLUME_3, (~right_val));
5056 + if (ret < 0)
5057 + return ret;
5058 +
5059 + } else {
5060 +
5061 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 0)->component,
5062 + PCM512x_DIGITAL_VOLUME_2, (~left_val));
5063 + if (ret < 0)
5064 + return ret;
5065 +
5066 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 0)->component,
5067 + PCM512x_DIGITAL_VOLUME_3, (~right_val));
5068 + if (ret < 0)
5069 + return ret;
5070 +
5071 + }
5072 + return 1;
5073 +}
5074 +
5075 +static int pcm512x_get_reg_master_switch(struct snd_kcontrol *kcontrol,
5076 + struct snd_ctl_elem_value *ucontrol)
5077 +{
5078 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
5079 + struct glb_pool *glb_ptr = card->drvdata;
5080 + struct snd_soc_pcm_runtime *rtd;
5081 + int val = 0;
5082 +
5083 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
5084 +
5085 + val = snd_soc_component_read(asoc_rtd_to_codec(rtd, 0)->component, PCM512x_MUTE);
5086 +
5087 + ucontrol->value.integer.value[0] =
5088 + (val & P_DAC_LEFT_MUTE) ? P_UNMUTE : P_MUTE;
5089 +
5090 + if (glb_ptr->dual_mode == 1) {
5091 + val = snd_soc_component_read(asoc_rtd_to_codec(rtd, 1)->component, PCM512x_MUTE);
5092 + }
5093 + ucontrol->value.integer.value[1] =
5094 + (val & P_DAC_RIGHT_MUTE) ? P_UNMUTE : P_MUTE;
5095 +
5096 + return val;
5097 +}
5098 +
5099 +static int pcm512x_set_reg_master_switch(struct snd_kcontrol *kcontrol,
5100 + struct snd_ctl_elem_value *ucontrol)
5101 +{
5102 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
5103 + struct snd_soc_pcm_runtime *rtd;
5104 + struct glb_pool *glb_ptr = card->drvdata;
5105 + unsigned int left_val = (ucontrol->value.integer.value[0]);
5106 + unsigned int right_val = (ucontrol->value.integer.value[1]);
5107 + int ret = 0;
5108 +
5109 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
5110 + if (glb_ptr->dual_mode == 1) {
5111 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 0)->component, PCM512x_MUTE,
5112 + ~((left_val & 0x01)<<4));
5113 + if (ret < 0)
5114 + return ret;
5115 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component, PCM512x_MUTE,
5116 + ~((right_val & 0x01)));
5117 + if (ret < 0)
5118 + return ret;
5119 +
5120 + } else if (glb_ptr->set_mode == 1) {
5121 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 0)->component, PCM512x_MUTE,
5122 + ~((left_val & 0x01)<<4 | (right_val & 0x01)));
5123 + if (ret < 0)
5124 + return ret;
5125 +
5126 + } else {
5127 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 0)->component, PCM512x_MUTE,
5128 + ~((left_val & 0x01)<<4 | (right_val & 0x01)));
5129 + if (ret < 0)
5130 + return ret;
5131 +
5132 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component, PCM512x_MUTE,
5133 + ~((left_val & 0x01)<<4 | (right_val & 0x01)));
5134 + if (ret < 0)
5135 + return ret;
5136 + }
5137 + return 1;
5138 +}
5139 +
5140 +static const DECLARE_TLV_DB_SCALE(digital_tlv_sub, -10350, 50, 1);
5141 +static const DECLARE_TLV_DB_SCALE(digital_tlv_master, -10350, 50, 1);
5142 +
5143 +static const struct snd_kcontrol_new allo_piano_controls[] = {
5144 + SOC_ENUM_EXT("Subwoofer mode Route",
5145 + allo_piano_mode_enum,
5146 + snd_allo_piano_mode_get,
5147 + snd_allo_piano_mode_put),
5148 +
5149 + SOC_ENUM_EXT("Dual Mode Route",
5150 + allo_piano_dual_mode_enum,
5151 + snd_allo_piano_dual_mode_get,
5152 + snd_allo_piano_dual_mode_put),
5153 +
5154 + SOC_ENUM_EXT("Lowpass Route", allo_piano_enum,
5155 + snd_allo_piano_lowpass_get,
5156 + snd_allo_piano_lowpass_put),
5157 +
5158 + SOC_DOUBLE_R_EXT_TLV("Subwoofer Playback Volume",
5159 + PCM512x_DIGITAL_VOLUME_2,
5160 + PCM512x_DIGITAL_VOLUME_3, 0, 255, 1,
5161 + pcm512x_get_reg_sub,
5162 + pcm512x_set_reg_sub,
5163 + digital_tlv_sub),
5164 +
5165 + SOC_DOUBLE_EXT("Subwoofer Playback Switch",
5166 + PCM512x_MUTE,
5167 + PCM512x_RQML_SHIFT,
5168 + PCM512x_RQMR_SHIFT, 1, 1,
5169 + pcm512x_get_reg_sub_switch,
5170 + pcm512x_set_reg_sub_switch),
5171 +
5172 + SOC_DOUBLE_R_EXT_TLV("Master Playback Volume",
5173 + PCM512x_DIGITAL_VOLUME_2,
5174 + PCM512x_DIGITAL_VOLUME_3, 0, 255, 1,
5175 + pcm512x_get_reg_master,
5176 + pcm512x_set_reg_master,
5177 + digital_tlv_master),
5178 +
5179 + SOC_DOUBLE_EXT("Master Playback Switch",
5180 + PCM512x_MUTE,
5181 + PCM512x_RQML_SHIFT,
5182 + PCM512x_RQMR_SHIFT, 1, 1,
5183 + pcm512x_get_reg_master_switch,
5184 + pcm512x_set_reg_master_switch),
5185 +};
5186 +
5187 +static const char * const codec_ctl_pfx[] = { "Main", "Sub" };
5188 +static const char * const codec_ctl_name[] = {
5189 + "Digital Playback Volume",
5190 + "Digital Playback Switch",
5191 + "Auto Mute Mono Switch",
5192 + "Auto Mute Switch",
5193 + "Auto Mute Time Left",
5194 + "Auto Mute Time Right",
5195 + "Clock Missing Period",
5196 + "Max Overclock DAC",
5197 + "Max Overclock DSP",
5198 + "Max Overclock PLL",
5199 + "Volume Ramp Down Emergency Rate",
5200 + "Volume Ramp Down Emergency Step",
5201 + "Volume Ramp Up Rate",
5202 + "Volume Ramp Down Rate",
5203 + "Volume Ramp Up Step",
5204 + "Volume Ramp Down Step"
5205 +};
5206 +
5207 +static int snd_allo_piano_dac_init(struct snd_soc_pcm_runtime *rtd)
5208 +{
5209 + struct snd_soc_card *card = rtd->card;
5210 + struct glb_pool *glb_ptr;
5211 + struct snd_kcontrol *kctl;
5212 + int i, j;
5213 +
5214 + glb_ptr = kzalloc(sizeof(struct glb_pool), GFP_KERNEL);
5215 + if (!glb_ptr)
5216 + return -ENOMEM;
5217 +
5218 + card->drvdata = glb_ptr;
5219 + glb_ptr->dual_mode = 2;
5220 + glb_ptr->set_mode = 0;
5221 +
5222 + mutex_init(&glb_ptr->lock);
5223 +
5224 + if (digital_gain_0db_limit) {
5225 + int ret;
5226 +
5227 + //Set volume limit on both dacs
5228 + for (i = 0; i < ARRAY_SIZE(codec_ctl_pfx); i++) {
5229 + char cname[256];
5230 +
5231 + sprintf(cname, "%s %s", codec_ctl_pfx[i], codec_ctl_name[0]);
5232 + ret = snd_soc_limit_volume(card, cname, 207);
5233 + if (ret < 0)
5234 + dev_warn(card->dev, "Failed to set volume limit: %d\n",
5235 + ret);
5236 + }
5237 + }
5238 +
5239 + // Remove codec controls
5240 + for (i = 0; i < ARRAY_SIZE(codec_ctl_pfx); i++) {
5241 + for (j = 0; j < ARRAY_SIZE(codec_ctl_name); j++) {
5242 + char cname[256];
5243 +
5244 + sprintf(cname, "%s %s", codec_ctl_pfx[i], codec_ctl_name[j]);
5245 + kctl = snd_soc_card_get_kcontrol(card, cname);
5246 + if (!kctl) {
5247 + dev_err(rtd->card->dev, "Control %s not found\n",
5248 + cname);
5249 + } else {
5250 + kctl->vd[0].access =
5251 + SNDRV_CTL_ELEM_ACCESS_READWRITE;
5252 + snd_ctl_remove(card->snd_card, kctl);
5253 + }
5254 + }
5255 + }
5256 +
5257 + return 0;
5258 +}
5259 +
5260 +static void snd_allo_piano_gpio_mute(struct snd_soc_card *card)
5261 +{
5262 + if (mute_gpio[0])
5263 + gpiod_set_value_cansleep(mute_gpio[0], P_MUTE);
5264 +
5265 + if (mute_gpio[1])
5266 + gpiod_set_value_cansleep(mute_gpio[1], P_MUTE);
5267 +}
5268 +
5269 +static void snd_allo_piano_gpio_unmute(struct snd_soc_card *card)
5270 +{
5271 + if (mute_gpio[0])
5272 + gpiod_set_value_cansleep(mute_gpio[0], P_UNMUTE);
5273 +
5274 + if (mute_gpio[1])
5275 + gpiod_set_value_cansleep(mute_gpio[1], P_UNMUTE);
5276 +}
5277 +
5278 +static int snd_allo_piano_set_bias_level(struct snd_soc_card *card,
5279 + struct snd_soc_dapm_context *dapm, enum snd_soc_bias_level level)
5280 +{
5281 + struct snd_soc_pcm_runtime *rtd;
5282 + struct snd_soc_dai *codec_dai;
5283 +
5284 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
5285 + codec_dai = asoc_rtd_to_codec(rtd, 0);
5286 +
5287 + if (dapm->dev != codec_dai->dev)
5288 + return 0;
5289 +
5290 + switch (level) {
5291 + case SND_SOC_BIAS_PREPARE:
5292 + if (dapm->bias_level != SND_SOC_BIAS_STANDBY)
5293 + break;
5294 + /* UNMUTE DAC */
5295 + snd_allo_piano_gpio_unmute(card);
5296 + break;
5297 +
5298 + case SND_SOC_BIAS_STANDBY:
5299 + if (dapm->bias_level != SND_SOC_BIAS_PREPARE)
5300 + break;
5301 + /* MUTE DAC */
5302 + snd_allo_piano_gpio_mute(card);
5303 + break;
5304 +
5305 + default:
5306 + break;
5307 + }
5308 +
5309 + return 0;
5310 +}
5311 +
5312 +static int snd_allo_piano_dac_startup(
5313 + struct snd_pcm_substream *substream)
5314 +{
5315 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
5316 + struct snd_soc_card *card = rtd->card;
5317 +
5318 + snd_allo_piano_gpio_mute(card);
5319 +
5320 + return 0;
5321 +}
5322 +
5323 +static int snd_allo_piano_dac_hw_params(
5324 + struct snd_pcm_substream *substream,
5325 + struct snd_pcm_hw_params *params)
5326 +{
5327 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
5328 + unsigned int rate = params_rate(params);
5329 + struct snd_soc_card *card = rtd->card;
5330 + struct glb_pool *glb_ptr = card->drvdata;
5331 + int ret = 0, val = 0, dac;
5332 +
5333 + for (dac = 0; (glb_mclk && dac < 2); dac++) {
5334 + /* Configure the PLL clock reference for both the Codecs */
5335 + val = snd_soc_component_read(asoc_rtd_to_codec(rtd, dac)->component,
5336 + PCM512x_RATE_DET_4);
5337 +
5338 + if (val & 0x40) {
5339 + snd_soc_component_write(asoc_rtd_to_codec(rtd, dac)->component,
5340 + PCM512x_PLL_REF,
5341 + PCM512x_SREF_BCK);
5342 +
5343 + dev_info(asoc_rtd_to_codec(rtd, dac)->component->dev,
5344 + "Setting BCLK as input clock & Enable PLL\n");
5345 + } else {
5346 + snd_soc_component_write(asoc_rtd_to_codec(rtd, dac)->component,
5347 + PCM512x_PLL_EN,
5348 + 0x00);
5349 +
5350 + snd_soc_component_write(asoc_rtd_to_codec(rtd, dac)->component,
5351 + PCM512x_PLL_REF,
5352 + PCM512x_SREF_SCK);
5353 +
5354 + dev_info(asoc_rtd_to_codec(rtd, dac)->component->dev,
5355 + "Setting SCLK as input clock & disabled PLL\n");
5356 + }
5357 + }
5358 +
5359 + ret = snd_allo_piano_dsp_program(rtd, glb_ptr->set_mode, rate,
5360 + glb_ptr->set_lowpass);
5361 + if (ret < 0)
5362 + return ret;
5363 +
5364 + return ret;
5365 +}
5366 +
5367 +static int snd_allo_piano_dac_prepare(
5368 + struct snd_pcm_substream *substream)
5369 +{
5370 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
5371 + struct snd_soc_card *card = rtd->card;
5372 +
5373 + snd_allo_piano_gpio_unmute(card);
5374 +
5375 + return 0;
5376 +}
5377 +
5378 +/* machine stream operations */
5379 +static struct snd_soc_ops snd_allo_piano_dac_ops = {
5380 + .startup = snd_allo_piano_dac_startup,
5381 + .hw_params = snd_allo_piano_dac_hw_params,
5382 + .prepare = snd_allo_piano_dac_prepare,
5383 +};
5384 +
5385 +static struct snd_soc_dai_link_component allo_piano_2_1_codecs[] = {
5386 + {
5387 + .dai_name = "pcm512x-hifi",
5388 + },
5389 + {
5390 + .dai_name = "pcm512x-hifi",
5391 + },
5392 +};
5393 +
5394 +SND_SOC_DAILINK_DEFS(allo_piano_dai_plus,
5395 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
5396 + DAILINK_COMP_ARRAY(COMP_CODEC("pcm512x.1-004c", "pcm512x-hifi"),
5397 + COMP_CODEC("pcm512x.1-004d", "pcm512x-hifi")),
5398 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
5399 +
5400 +static struct snd_soc_dai_link snd_allo_piano_dac_dai[] = {
5401 + {
5402 + .name = "PianoDACPlus",
5403 + .stream_name = "PianoDACPlus",
5404 + .dai_fmt = SND_SOC_DAIFMT_I2S |
5405 + SND_SOC_DAIFMT_NB_NF |
5406 + SND_SOC_DAIFMT_CBS_CFS,
5407 + .ops = &snd_allo_piano_dac_ops,
5408 + .init = snd_allo_piano_dac_init,
5409 + SND_SOC_DAILINK_REG(allo_piano_dai_plus),
5410 + },
5411 +};
5412 +
5413 +/* audio machine driver */
5414 +static struct snd_soc_card snd_allo_piano_dac = {
5415 + .name = "PianoDACPlus",
5416 + .owner = THIS_MODULE,
5417 + .dai_link = snd_allo_piano_dac_dai,
5418 + .num_links = ARRAY_SIZE(snd_allo_piano_dac_dai),
5419 + .controls = allo_piano_controls,
5420 + .num_controls = ARRAY_SIZE(allo_piano_controls),
5421 +};
5422 +
5423 +static int snd_allo_piano_dac_probe(struct platform_device *pdev)
5424 +{
5425 + struct snd_soc_card *card = &snd_allo_piano_dac;
5426 + int ret = 0, i = 0;
5427 +
5428 + card->dev = &pdev->dev;
5429 + platform_set_drvdata(pdev, &snd_allo_piano_dac);
5430 +
5431 + if (pdev->dev.of_node) {
5432 + struct device_node *i2s_node;
5433 + struct snd_soc_dai_link *dai;
5434 +
5435 + dai = &snd_allo_piano_dac_dai[0];
5436 + i2s_node = of_parse_phandle(pdev->dev.of_node,
5437 + "i2s-controller", 0);
5438 + if (i2s_node) {
5439 + for (i = 0; i < card->num_links; i++) {
5440 + dai->cpus->dai_name = NULL;
5441 + dai->cpus->of_node = i2s_node;
5442 + dai->platforms->name = NULL;
5443 + dai->platforms->of_node = i2s_node;
5444 + }
5445 + }
5446 + digital_gain_0db_limit =
5447 + !of_property_read_bool(pdev->dev.of_node,
5448 + "allo,24db_digital_gain");
5449 +
5450 + glb_mclk = of_property_read_bool(pdev->dev.of_node,
5451 + "allo,glb_mclk");
5452 +
5453 + allo_piano_2_1_codecs[0].of_node =
5454 + of_parse_phandle(pdev->dev.of_node, "audio-codec", 0);
5455 + if (!allo_piano_2_1_codecs[0].of_node) {
5456 + dev_err(&pdev->dev,
5457 + "Property 'audio-codec' missing or invalid\n");
5458 + return -EINVAL;
5459 + }
5460 +
5461 + allo_piano_2_1_codecs[1].of_node =
5462 + of_parse_phandle(pdev->dev.of_node, "audio-codec", 1);
5463 + if (!allo_piano_2_1_codecs[1].of_node) {
5464 + dev_err(&pdev->dev,
5465 + "Property 'audio-codec' missing or invalid\n");
5466 + return -EINVAL;
5467 + }
5468 +
5469 + mute_gpio[0] = devm_gpiod_get_optional(&pdev->dev, "mute1",
5470 + GPIOD_OUT_LOW);
5471 + if (IS_ERR(mute_gpio[0])) {
5472 + ret = PTR_ERR(mute_gpio[0]);
5473 + dev_err(&pdev->dev,
5474 + "failed to get mute1 gpio6: %d\n", ret);
5475 + return ret;
5476 + }
5477 +
5478 + mute_gpio[1] = devm_gpiod_get_optional(&pdev->dev, "mute2",
5479 + GPIOD_OUT_LOW);
5480 + if (IS_ERR(mute_gpio[1])) {
5481 + ret = PTR_ERR(mute_gpio[1]);
5482 + dev_err(&pdev->dev,
5483 + "failed to get mute2 gpio25: %d\n", ret);
5484 + return ret;
5485 + }
5486 +
5487 + if (mute_gpio[0] && mute_gpio[1])
5488 + snd_allo_piano_dac.set_bias_level =
5489 + snd_allo_piano_set_bias_level;
5490 +
5491 + ret = snd_soc_register_card(&snd_allo_piano_dac);
5492 + if (ret < 0) {
5493 + dev_err(&pdev->dev,
5494 + "snd_soc_register_card() failed: %d\n", ret);
5495 + return ret;
5496 + }
5497 +
5498 + if ((mute_gpio[0]) && (mute_gpio[1]))
5499 + snd_allo_piano_gpio_mute(&snd_allo_piano_dac);
5500 +
5501 + return 0;
5502 + }
5503 +
5504 + return -EINVAL;
5505 +}
5506 +
5507 +static int snd_allo_piano_dac_remove(struct platform_device *pdev)
5508 +{
5509 + struct snd_soc_card *card = platform_get_drvdata(pdev);
5510 +
5511 + kfree(&card->drvdata);
5512 + snd_allo_piano_gpio_mute(&snd_allo_piano_dac);
5513 + snd_soc_unregister_card(&snd_allo_piano_dac);
5514 + return 0;
5515 +}
5516 +
5517 +static const struct of_device_id snd_allo_piano_dac_of_match[] = {
5518 + { .compatible = "allo,piano-dac-plus", },
5519 + { /* sentinel */ },
5520 +};
5521 +
5522 +MODULE_DEVICE_TABLE(of, snd_allo_piano_dac_of_match);
5523 +
5524 +static struct platform_driver snd_allo_piano_dac_driver = {
5525 + .driver = {
5526 + .name = "snd-allo-piano-dac-plus",
5527 + .owner = THIS_MODULE,
5528 + .of_match_table = snd_allo_piano_dac_of_match,
5529 + },
5530 + .probe = snd_allo_piano_dac_probe,
5531 + .remove = snd_allo_piano_dac_remove,
5532 +};
5533 +
5534 +module_platform_driver(snd_allo_piano_dac_driver);
5535 +
5536 +MODULE_AUTHOR("Baswaraj K <jaikumar@cem-solutions.net>");
5537 +MODULE_DESCRIPTION("ALSA ASoC Machine Driver for Allo Piano DAC Plus");
5538 +MODULE_LICENSE("GPL v2");
5539 --- /dev/null
5540 +++ b/sound/soc/bcm/allo-piano-dac.c
5541 @@ -0,0 +1,122 @@
5542 +/*
5543 + * ALSA ASoC Machine Driver for Allo Piano DAC
5544 + *
5545 + * Author: Baswaraj K <jaikumar@cem-solutions.net>
5546 + * Copyright 2016
5547 + * based on code by Daniel Matuschek <info@crazy-audio.com>
5548 + * based on code by Florian Meier <florian.meier@koalo.de>
5549 + *
5550 + * This program is free software; you can redistribute it and/or
5551 + * modify it under the terms of the GNU General Public License
5552 + * version 2 as published by the Free Software Foundation.
5553 + *
5554 + * This program is distributed in the hope that it will be useful, but
5555 + * WITHOUT ANY WARRANTY; without even the implied warranty of
5556 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5557 + * General Public License for more details.
5558 + */
5559 +
5560 +#include <linux/module.h>
5561 +#include <linux/platform_device.h>
5562 +
5563 +#include <sound/core.h>
5564 +#include <sound/pcm.h>
5565 +#include <sound/pcm_params.h>
5566 +#include <sound/soc.h>
5567 +
5568 +static bool digital_gain_0db_limit = true;
5569 +
5570 +static int snd_allo_piano_dac_init(struct snd_soc_pcm_runtime *rtd)
5571 +{
5572 + if (digital_gain_0db_limit) {
5573 + int ret;
5574 + struct snd_soc_card *card = rtd->card;
5575 +
5576 + ret = snd_soc_limit_volume(card, "Digital Playback Volume",
5577 + 207);
5578 + if (ret < 0)
5579 + dev_warn(card->dev, "Failed to set volume limit: %d\n",
5580 + ret);
5581 + }
5582 +
5583 + return 0;
5584 +}
5585 +
5586 +SND_SOC_DAILINK_DEFS(allo_piano_dai,
5587 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
5588 + DAILINK_COMP_ARRAY(COMP_CODEC("pcm512x.1-004c", "pcm512x-hifi")),
5589 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
5590 +
5591 +static struct snd_soc_dai_link snd_allo_piano_dac_dai[] = {
5592 +{
5593 + .name = "Piano DAC",
5594 + .stream_name = "Piano DAC HiFi",
5595 + .dai_fmt = SND_SOC_DAIFMT_I2S |
5596 + SND_SOC_DAIFMT_NB_NF |
5597 + SND_SOC_DAIFMT_CBS_CFS,
5598 + .init = snd_allo_piano_dac_init,
5599 + SND_SOC_DAILINK_REG(allo_piano_dai),
5600 +},
5601 +};
5602 +
5603 +/* audio machine driver */
5604 +static struct snd_soc_card snd_allo_piano_dac = {
5605 + .name = "PianoDAC",
5606 + .owner = THIS_MODULE,
5607 + .dai_link = snd_allo_piano_dac_dai,
5608 + .num_links = ARRAY_SIZE(snd_allo_piano_dac_dai),
5609 +};
5610 +
5611 +static int snd_allo_piano_dac_probe(struct platform_device *pdev)
5612 +{
5613 + int ret = 0;
5614 +
5615 + snd_allo_piano_dac.dev = &pdev->dev;
5616 +
5617 + if (pdev->dev.of_node) {
5618 + struct device_node *i2s_node;
5619 + struct snd_soc_dai_link *dai;
5620 +
5621 + dai = &snd_allo_piano_dac_dai[0];
5622 + i2s_node = of_parse_phandle(pdev->dev.of_node,
5623 + "i2s-controller", 0);
5624 +
5625 + if (i2s_node) {
5626 + dai->cpus->dai_name = NULL;
5627 + dai->cpus->of_node = i2s_node;
5628 + dai->platforms->name = NULL;
5629 + dai->platforms->of_node = i2s_node;
5630 + }
5631 +
5632 + digital_gain_0db_limit = !of_property_read_bool(
5633 + pdev->dev.of_node, "allo,24db_digital_gain");
5634 + }
5635 +
5636 + ret = devm_snd_soc_register_card(&pdev->dev, &snd_allo_piano_dac);
5637 + if (ret && ret != -EPROBE_DEFER)
5638 + dev_err(&pdev->dev,
5639 + "snd_soc_register_card() failed: %d\n", ret);
5640 +
5641 + return ret;
5642 +}
5643 +
5644 +static const struct of_device_id snd_allo_piano_dac_of_match[] = {
5645 + { .compatible = "allo,piano-dac", },
5646 + { /* sentinel */ },
5647 +};
5648 +MODULE_DEVICE_TABLE(of, snd_allo_piano_dac_of_match);
5649 +
5650 +static struct platform_driver snd_allo_piano_dac_driver = {
5651 + .driver = {
5652 + .name = "snd-allo-piano-dac",
5653 + .owner = THIS_MODULE,
5654 + .of_match_table = snd_allo_piano_dac_of_match,
5655 + },
5656 + .probe = snd_allo_piano_dac_probe,
5657 +};
5658 +
5659 +module_platform_driver(snd_allo_piano_dac_driver);
5660 +
5661 +MODULE_AUTHOR("Baswaraj K <jaikumar@cem-solutions.net>");
5662 +MODULE_DESCRIPTION("ALSA ASoC Machine Driver for Allo Piano DAC");
5663 +MODULE_LICENSE("GPL v2");
5664 --- /dev/null
5665 +++ b/sound/soc/bcm/audioinjector-isolated-soundcard.c
5666 @@ -0,0 +1,183 @@
5667 +/*
5668 + * ASoC Driver for AudioInjector.net isolated soundcard
5669 + *
5670 + * Created on: 20-February-2020
5671 + * Author: flatmax@flatmax.org
5672 + * based on audioinjector-octo-soundcard.c
5673 + *
5674 + * Copyright (C) 2020 Flatmax Pty. Ltd.
5675 + *
5676 + * This program is free software; you can redistribute it and/or
5677 + * modify it under the terms of the GNU General Public License
5678 + * version 2 as published by the Free Software Foundation.
5679 + *
5680 + * This program is distributed in the hope that it will be useful, but
5681 + * WITHOUT ANY WARRANTY; without even the implied warranty of
5682 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5683 + * General Public License for more details.
5684 + */
5685 +
5686 +#include <linux/module.h>
5687 +#include <linux/types.h>
5688 +#include <linux/gpio/consumer.h>
5689 +
5690 +#include <sound/core.h>
5691 +#include <sound/soc.h>
5692 +#include <sound/pcm_params.h>
5693 +#include <sound/control.h>
5694 +
5695 +static struct gpio_desc *mute_gpio;
5696 +
5697 +static const unsigned int audioinjector_isolated_rates[] = {
5698 + 192000, 96000, 48000, 32000, 24000, 16000, 8000
5699 +};
5700 +
5701 +static struct snd_pcm_hw_constraint_list audioinjector_isolated_constraints = {
5702 + .list = audioinjector_isolated_rates,
5703 + .count = ARRAY_SIZE(audioinjector_isolated_rates),
5704 +};
5705 +
5706 +static int audioinjector_isolated_dai_init(struct snd_soc_pcm_runtime *rtd)
5707 +{
5708 + int ret=snd_soc_dai_set_sysclk(asoc_rtd_to_codec(rtd, 0), 0, 24576000, 0);
5709 + if (ret)
5710 + return ret;
5711 +
5712 + return snd_soc_dai_set_bclk_ratio(asoc_rtd_to_cpu(rtd, 0), 64);
5713 +}
5714 +
5715 +static int audioinjector_isolated_startup(struct snd_pcm_substream *substream)
5716 +{
5717 + snd_pcm_hw_constraint_list(substream->runtime, 0,
5718 + SNDRV_PCM_HW_PARAM_RATE, &audioinjector_isolated_constraints);
5719 +
5720 + return 0;
5721 +}
5722 +
5723 +static int audioinjector_isolated_trigger(struct snd_pcm_substream *substream,
5724 + int cmd){
5725 +
5726 + switch (cmd) {
5727 + case SNDRV_PCM_TRIGGER_STOP:
5728 + case SNDRV_PCM_TRIGGER_SUSPEND:
5729 + case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
5730 + gpiod_set_value(mute_gpio, 0);
5731 + break;
5732 + case SNDRV_PCM_TRIGGER_START:
5733 + case SNDRV_PCM_TRIGGER_RESUME:
5734 + case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
5735 + gpiod_set_value(mute_gpio, 1);
5736 + break;
5737 + default:
5738 + return -EINVAL;
5739 + }
5740 + return 0;
5741 +}
5742 +
5743 +static struct snd_soc_ops audioinjector_isolated_ops = {
5744 + .startup = audioinjector_isolated_startup,
5745 + .trigger = audioinjector_isolated_trigger,
5746 +};
5747 +
5748 +SND_SOC_DAILINK_DEFS(audioinjector_isolated,
5749 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
5750 + DAILINK_COMP_ARRAY(COMP_CODEC("cs4271.1-0010", "cs4271-hifi")),
5751 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
5752 +
5753 +static struct snd_soc_dai_link audioinjector_isolated_dai[] = {
5754 + {
5755 + .name = "AudioInjector ISO",
5756 + .stream_name = "AI-HIFI",
5757 + .ops = &audioinjector_isolated_ops,
5758 + .init = audioinjector_isolated_dai_init,
5759 + .symmetric_rate = 1,
5760 + .symmetric_channels = 1,
5761 + .dai_fmt = SND_SOC_DAIFMT_CBM_CFM|SND_SOC_DAIFMT_I2S|SND_SOC_DAIFMT_NB_NF,
5762 + SND_SOC_DAILINK_REG(audioinjector_isolated),
5763 + }
5764 +};
5765 +
5766 +static const struct snd_soc_dapm_widget audioinjector_isolated_widgets[] = {
5767 + SND_SOC_DAPM_OUTPUT("OUTPUTS"),
5768 + SND_SOC_DAPM_INPUT("INPUTS"),
5769 +};
5770 +
5771 +static const struct snd_soc_dapm_route audioinjector_isolated_route[] = {
5772 + /* Balanced outputs */
5773 + {"OUTPUTS", NULL, "AOUTA+"},
5774 + {"OUTPUTS", NULL, "AOUTA-"},
5775 + {"OUTPUTS", NULL, "AOUTB+"},
5776 + {"OUTPUTS", NULL, "AOUTB-"},
5777 +
5778 + /* Balanced inputs */
5779 + {"AINA", NULL, "INPUTS"},
5780 + {"AINB", NULL, "INPUTS"},
5781 +};
5782 +
5783 +static struct snd_soc_card snd_soc_audioinjector_isolated = {
5784 + .name = "audioinjector-isolated-soundcard",
5785 + .dai_link = audioinjector_isolated_dai,
5786 + .num_links = ARRAY_SIZE(audioinjector_isolated_dai),
5787 +
5788 + .dapm_widgets = audioinjector_isolated_widgets,
5789 + .num_dapm_widgets = ARRAY_SIZE(audioinjector_isolated_widgets),
5790 + .dapm_routes = audioinjector_isolated_route,
5791 + .num_dapm_routes = ARRAY_SIZE(audioinjector_isolated_route),
5792 +};
5793 +
5794 +static int audioinjector_isolated_probe(struct platform_device *pdev)
5795 +{
5796 + struct snd_soc_card *card = &snd_soc_audioinjector_isolated;
5797 + int ret;
5798 +
5799 + card->dev = &pdev->dev;
5800 +
5801 + if (pdev->dev.of_node) {
5802 + struct snd_soc_dai_link *dai = &audioinjector_isolated_dai[0];
5803 + struct device_node *i2s_node =
5804 + of_parse_phandle(pdev->dev.of_node, "i2s-controller", 0);
5805 +
5806 + if (i2s_node) {
5807 + dai->cpus->dai_name = NULL;
5808 + dai->cpus->of_node = i2s_node;
5809 + dai->platforms->name = NULL;
5810 + dai->platforms->of_node = i2s_node;
5811 + } else {
5812 + dev_err(&pdev->dev,
5813 + "i2s-controller missing or invalid in DT\n");
5814 + return -EINVAL;
5815 + }
5816 +
5817 + mute_gpio = devm_gpiod_get_optional(&pdev->dev, "mute", GPIOD_OUT_LOW);
5818 + if (IS_ERR(mute_gpio)){
5819 + dev_err(&pdev->dev, "mute gpio not found in dt overlay\n");
5820 + return PTR_ERR(mute_gpio);
5821 + }
5822 + }
5823 +
5824 + ret = devm_snd_soc_register_card(&pdev->dev, card);
5825 + if (ret && ret != -EPROBE_DEFER)
5826 + dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret);
5827 + return ret;
5828 +}
5829 +
5830 +static const struct of_device_id audioinjector_isolated_of_match[] = {
5831 + { .compatible = "ai,audioinjector-isolated-soundcard", },
5832 + {},
5833 +};
5834 +MODULE_DEVICE_TABLE(of, audioinjector_isolated_of_match);
5835 +
5836 +static struct platform_driver audioinjector_isolated_driver = {
5837 + .driver = {
5838 + .name = "audioinjector-isolated",
5839 + .owner = THIS_MODULE,
5840 + .of_match_table = audioinjector_isolated_of_match,
5841 + },
5842 + .probe = audioinjector_isolated_probe,
5843 +};
5844 +
5845 +module_platform_driver(audioinjector_isolated_driver);
5846 +MODULE_AUTHOR("Matt Flax <flatmax@flatmax.org>");
5847 +MODULE_DESCRIPTION("AudioInjector.net isolated Soundcard");
5848 +MODULE_LICENSE("GPL v2");
5849 +MODULE_ALIAS("platform:audioinjector-isolated-soundcard");
5850 --- /dev/null
5851 +++ b/sound/soc/bcm/audioinjector-octo-soundcard.c
5852 @@ -0,0 +1,346 @@
5853 +/*
5854 + * ASoC Driver for AudioInjector Pi octo channel soundcard (hat)
5855 + *
5856 + * Created on: 27-October-2016
5857 + * Author: flatmax@flatmax.org
5858 + * based on audioinjector-pi-soundcard.c
5859 + *
5860 + * Copyright (C) 2016 Flatmax Pty. Ltd.
5861 + *
5862 + * This program is free software; you can redistribute it and/or
5863 + * modify it under the terms of the GNU General Public License
5864 + * version 2 as published by the Free Software Foundation.
5865 + *
5866 + * This program is distributed in the hope that it will be useful, but
5867 + * WITHOUT ANY WARRANTY; without even the implied warranty of
5868 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5869 + * General Public License for more details.
5870 + */
5871 +
5872 +#include <linux/module.h>
5873 +#include <linux/types.h>
5874 +#include <linux/gpio/consumer.h>
5875 +
5876 +#include <sound/core.h>
5877 +#include <sound/soc.h>
5878 +#include <sound/pcm_params.h>
5879 +#include <sound/control.h>
5880 +
5881 +static struct gpio_descs *mult_gpios;
5882 +static struct gpio_desc *codec_rst_gpio;
5883 +static unsigned int audioinjector_octo_rate;
5884 +static bool non_stop_clocks;
5885 +
5886 +static const unsigned int audioinjector_octo_rates[] = {
5887 + 96000, 48000, 32000, 24000, 16000, 8000, 88200, 44100, 29400, 22050, 14700,
5888 +};
5889 +
5890 +static struct snd_pcm_hw_constraint_list audioinjector_octo_constraints = {
5891 + .list = audioinjector_octo_rates,
5892 + .count = ARRAY_SIZE(audioinjector_octo_rates),
5893 +};
5894 +
5895 +static int audioinjector_octo_dai_init(struct snd_soc_pcm_runtime *rtd)
5896 +{
5897 + return snd_soc_dai_set_bclk_ratio(asoc_rtd_to_cpu(rtd, 0), 64);
5898 +}
5899 +
5900 +static int audioinjector_octo_startup(struct snd_pcm_substream *substream)
5901 +{
5902 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
5903 + asoc_rtd_to_cpu(rtd, 0)->driver->playback.channels_min = 8;
5904 + asoc_rtd_to_cpu(rtd, 0)->driver->playback.channels_max = 8;
5905 + asoc_rtd_to_cpu(rtd, 0)->driver->capture.channels_min = 8;
5906 + asoc_rtd_to_cpu(rtd, 0)->driver->capture.channels_max = 8;
5907 + asoc_rtd_to_codec(rtd, 0)->driver->capture.channels_max = 8;
5908 +
5909 + snd_pcm_hw_constraint_list(substream->runtime, 0,
5910 + SNDRV_PCM_HW_PARAM_RATE,
5911 + &audioinjector_octo_constraints);
5912 +
5913 + return 0;
5914 +}
5915 +
5916 +static void audioinjector_octo_shutdown(struct snd_pcm_substream *substream)
5917 +{
5918 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
5919 + asoc_rtd_to_cpu(rtd, 0)->driver->playback.channels_min = 2;
5920 + asoc_rtd_to_cpu(rtd, 0)->driver->playback.channels_max = 2;
5921 + asoc_rtd_to_cpu(rtd, 0)->driver->capture.channels_min = 2;
5922 + asoc_rtd_to_cpu(rtd, 0)->driver->capture.channels_max = 2;
5923 + asoc_rtd_to_codec(rtd, 0)->driver->capture.channels_max = 6;
5924 +}
5925 +
5926 +static int audioinjector_octo_hw_params(struct snd_pcm_substream *substream,
5927 + struct snd_pcm_hw_params *params)
5928 +{
5929 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
5930 +
5931 + // set codec DAI configuration
5932 + int ret = snd_soc_dai_set_fmt(asoc_rtd_to_codec(rtd, 0),
5933 + SND_SOC_DAIFMT_CBS_CFS|SND_SOC_DAIFMT_DSP_A|
5934 + SND_SOC_DAIFMT_NB_NF);
5935 + if (ret < 0)
5936 + return ret;
5937 +
5938 + // set cpu DAI configuration
5939 + ret = snd_soc_dai_set_fmt(asoc_rtd_to_cpu(rtd, 0),
5940 + SND_SOC_DAIFMT_CBM_CFM|SND_SOC_DAIFMT_I2S|
5941 + SND_SOC_DAIFMT_NB_NF);
5942 + if (ret < 0)
5943 + return ret;
5944 +
5945 + audioinjector_octo_rate = params_rate(params);
5946 +
5947 + // Set the correct sysclock for the codec
5948 + switch (audioinjector_octo_rate) {
5949 + case 96000:
5950 + case 48000:
5951 + return snd_soc_dai_set_sysclk(asoc_rtd_to_codec(rtd, 0), 0, 49152000,
5952 + 0);
5953 + break;
5954 + case 24000:
5955 + return snd_soc_dai_set_sysclk(asoc_rtd_to_codec(rtd, 0), 0, 49152000/2,
5956 + 0);
5957 + break;
5958 + case 32000:
5959 + case 16000:
5960 + return snd_soc_dai_set_sysclk(asoc_rtd_to_codec(rtd, 0), 0, 49152000/3,
5961 + 0);
5962 + break;
5963 + case 8000:
5964 + return snd_soc_dai_set_sysclk(asoc_rtd_to_codec(rtd, 0), 0, 49152000/6,
5965 + 0);
5966 + break;
5967 + case 88200:
5968 + case 44100:
5969 + return snd_soc_dai_set_sysclk(asoc_rtd_to_codec(rtd, 0), 0, 45185400,
5970 + 0);
5971 + break;
5972 + case 22050:
5973 + return snd_soc_dai_set_sysclk(asoc_rtd_to_codec(rtd, 0), 0, 45185400/2,
5974 + 0);
5975 + break;
5976 + case 29400:
5977 + case 14700:
5978 + return snd_soc_dai_set_sysclk(asoc_rtd_to_codec(rtd, 0), 0, 45185400/3,
5979 + 0);
5980 + break;
5981 + default:
5982 + return -EINVAL;
5983 + }
5984 +}
5985 +
5986 +static int audioinjector_octo_trigger(struct snd_pcm_substream *substream,
5987 + int cmd){
5988 + DECLARE_BITMAP(mult, 4);
5989 +
5990 + memset(mult, 0, sizeof(mult));
5991 +
5992 + switch (cmd) {
5993 + case SNDRV_PCM_TRIGGER_STOP:
5994 + case SNDRV_PCM_TRIGGER_SUSPEND:
5995 + case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
5996 + if (!non_stop_clocks)
5997 + break;
5998 + fallthrough;
5999 + case SNDRV_PCM_TRIGGER_START:
6000 + case SNDRV_PCM_TRIGGER_RESUME:
6001 + case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
6002 + switch (audioinjector_octo_rate) {
6003 + case 96000:
6004 + __assign_bit(3, mult, 1);
6005 + fallthrough;
6006 + case 88200:
6007 + __assign_bit(1, mult, 1);
6008 + __assign_bit(2, mult, 1);
6009 + break;
6010 + case 48000:
6011 + __assign_bit(3, mult, 1);
6012 + fallthrough;
6013 + case 44100:
6014 + __assign_bit(2, mult, 1);
6015 + break;
6016 + case 32000:
6017 + __assign_bit(3, mult, 1);
6018 + fallthrough;
6019 + case 29400:
6020 + __assign_bit(0, mult, 1);
6021 + __assign_bit(1, mult, 1);
6022 + break;
6023 + case 24000:
6024 + __assign_bit(3, mult, 1);
6025 + fallthrough;
6026 + case 22050:
6027 + __assign_bit(1, mult, 1);
6028 + break;
6029 + case 16000:
6030 + __assign_bit(3, mult, 1);
6031 + fallthrough;
6032 + case 14700:
6033 + __assign_bit(0, mult, 1);
6034 + break;
6035 + case 8000:
6036 + __assign_bit(3, mult, 1);
6037 + break;
6038 + default:
6039 + return -EINVAL;
6040 + }
6041 + break;
6042 + default:
6043 + return -EINVAL;
6044 + }
6045 + gpiod_set_array_value_cansleep(mult_gpios->ndescs, mult_gpios->desc,
6046 + NULL, mult);
6047 +
6048 + return 0;
6049 +}
6050 +
6051 +static struct snd_soc_ops audioinjector_octo_ops = {
6052 + .startup = audioinjector_octo_startup,
6053 + .shutdown = audioinjector_octo_shutdown,
6054 + .hw_params = audioinjector_octo_hw_params,
6055 + .trigger = audioinjector_octo_trigger,
6056 +};
6057 +
6058 +SND_SOC_DAILINK_DEFS(audioinjector_octo,
6059 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
6060 + DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "cs42448")),
6061 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
6062 +
6063 +static struct snd_soc_dai_link audioinjector_octo_dai[] = {
6064 + {
6065 + .name = "AudioInjector Octo",
6066 + .stream_name = "AudioInject-HIFI",
6067 + .ops = &audioinjector_octo_ops,
6068 + .init = audioinjector_octo_dai_init,
6069 + .symmetric_rate = 1,
6070 + .symmetric_channels = 1,
6071 + SND_SOC_DAILINK_REG(audioinjector_octo),
6072 + },
6073 +};
6074 +
6075 +static const struct snd_soc_dapm_widget audioinjector_octo_widgets[] = {
6076 + SND_SOC_DAPM_OUTPUT("OUTPUTS0"),
6077 + SND_SOC_DAPM_OUTPUT("OUTPUTS1"),
6078 + SND_SOC_DAPM_OUTPUT("OUTPUTS2"),
6079 + SND_SOC_DAPM_OUTPUT("OUTPUTS3"),
6080 + SND_SOC_DAPM_INPUT("INPUTS0"),
6081 + SND_SOC_DAPM_INPUT("INPUTS1"),
6082 + SND_SOC_DAPM_INPUT("INPUTS2"),
6083 +};
6084 +
6085 +static const struct snd_soc_dapm_route audioinjector_octo_route[] = {
6086 + /* Balanced outputs */
6087 + {"OUTPUTS0", NULL, "AOUT1L"},
6088 + {"OUTPUTS0", NULL, "AOUT1R"},
6089 + {"OUTPUTS1", NULL, "AOUT2L"},
6090 + {"OUTPUTS1", NULL, "AOUT2R"},
6091 + {"OUTPUTS2", NULL, "AOUT3L"},
6092 + {"OUTPUTS2", NULL, "AOUT3R"},
6093 + {"OUTPUTS3", NULL, "AOUT4L"},
6094 + {"OUTPUTS3", NULL, "AOUT4R"},
6095 +
6096 + /* Balanced inputs */
6097 + {"AIN1L", NULL, "INPUTS0"},
6098 + {"AIN1R", NULL, "INPUTS0"},
6099 + {"AIN2L", NULL, "INPUTS1"},
6100 + {"AIN2R", NULL, "INPUTS1"},
6101 + {"AIN3L", NULL, "INPUTS2"},
6102 + {"AIN3R", NULL, "INPUTS2"},
6103 +};
6104 +
6105 +static struct snd_soc_card snd_soc_audioinjector_octo = {
6106 + .name = "audioinjector-octo-soundcard",
6107 + .dai_link = audioinjector_octo_dai,
6108 + .num_links = ARRAY_SIZE(audioinjector_octo_dai),
6109 +
6110 + .dapm_widgets = audioinjector_octo_widgets,
6111 + .num_dapm_widgets = ARRAY_SIZE(audioinjector_octo_widgets),
6112 + .dapm_routes = audioinjector_octo_route,
6113 + .num_dapm_routes = ARRAY_SIZE(audioinjector_octo_route),
6114 +};
6115 +
6116 +static int audioinjector_octo_probe(struct platform_device *pdev)
6117 +{
6118 + struct snd_soc_card *card = &snd_soc_audioinjector_octo;
6119 + int ret;
6120 +
6121 + card->dev = &pdev->dev;
6122 +
6123 + if (pdev->dev.of_node) {
6124 + struct snd_soc_dai_link *dai = &audioinjector_octo_dai[0];
6125 + struct device_node *i2s_node =
6126 + of_parse_phandle(pdev->dev.of_node,
6127 + "i2s-controller", 0);
6128 + struct device_node *codec_node =
6129 + of_parse_phandle(pdev->dev.of_node,
6130 + "codec", 0);
6131 +
6132 + mult_gpios = devm_gpiod_get_array_optional(&pdev->dev, "mult",
6133 + GPIOD_OUT_LOW);
6134 + if (IS_ERR(mult_gpios))
6135 + return PTR_ERR(mult_gpios);
6136 +
6137 + codec_rst_gpio = devm_gpiod_get_optional(&pdev->dev, "reset",
6138 + GPIOD_OUT_LOW);
6139 + if (IS_ERR(codec_rst_gpio))
6140 + return PTR_ERR(codec_rst_gpio);
6141 +
6142 + non_stop_clocks = of_property_read_bool(pdev->dev.of_node, "non-stop-clocks");
6143 +
6144 + if (codec_rst_gpio)
6145 + gpiod_set_value(codec_rst_gpio, 1);
6146 + msleep(500);
6147 + if (codec_rst_gpio)
6148 + gpiod_set_value(codec_rst_gpio, 0);
6149 + msleep(500);
6150 + if (codec_rst_gpio)
6151 + gpiod_set_value(codec_rst_gpio, 1);
6152 + msleep(500);
6153 +
6154 + if (i2s_node && codec_node) {
6155 + dai->cpus->dai_name = NULL;
6156 + dai->cpus->of_node = i2s_node;
6157 + dai->platforms->name = NULL;
6158 + dai->platforms->of_node = i2s_node;
6159 + dai->codecs->name = NULL;
6160 + dai->codecs->of_node = codec_node;
6161 + } else
6162 + if (!i2s_node) {
6163 + dev_err(&pdev->dev,
6164 + "i2s-controller missing or invalid in DT\n");
6165 + return -EINVAL;
6166 + } else {
6167 + dev_err(&pdev->dev,
6168 + "Property 'codec' missing or invalid\n");
6169 + return -EINVAL;
6170 + }
6171 + }
6172 +
6173 + ret = devm_snd_soc_register_card(&pdev->dev, card);
6174 + if (ret != 0)
6175 + dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret);
6176 + return ret;
6177 +}
6178 +
6179 +static const struct of_device_id audioinjector_octo_of_match[] = {
6180 + { .compatible = "ai,audioinjector-octo-soundcard", },
6181 + {},
6182 +};
6183 +MODULE_DEVICE_TABLE(of, audioinjector_octo_of_match);
6184 +
6185 +static struct platform_driver audioinjector_octo_driver = {
6186 + .driver = {
6187 + .name = "audioinjector-octo",
6188 + .owner = THIS_MODULE,
6189 + .of_match_table = audioinjector_octo_of_match,
6190 + },
6191 + .probe = audioinjector_octo_probe,
6192 +};
6193 +
6194 +module_platform_driver(audioinjector_octo_driver);
6195 +MODULE_AUTHOR("Matt Flax <flatmax@flatmax.org>");
6196 +MODULE_DESCRIPTION("AudioInjector.net octo Soundcard");
6197 +MODULE_LICENSE("GPL v2");
6198 +MODULE_ALIAS("platform:audioinjector-octo-soundcard");
6199 --- /dev/null
6200 +++ b/sound/soc/bcm/audioinjector-pi-soundcard.c
6201 @@ -0,0 +1,189 @@
6202 +/*
6203 + * ASoC Driver for AudioInjector Pi add on soundcard
6204 + *
6205 + * Created on: 13-May-2016
6206 + * Author: flatmax@flatmax.org
6207 + * based on code by Cliff Cai <Cliff.Cai@analog.com> for the ssm2602 machine blackfin.
6208 + * with help from Lars-Peter Clausen for simplifying the original code to use the dai_fmt field.
6209 + * i2s_node code taken from the other sound/soc/bcm machine drivers.
6210 + *
6211 + * Copyright (C) 2016 Flatmax Pty. Ltd.
6212 + *
6213 + * This program is free software; you can redistribute it and/or
6214 + * modify it under the terms of the GNU General Public License
6215 + * version 2 as published by the Free Software Foundation.
6216 + *
6217 + * This program is distributed in the hope that it will be useful, but
6218 + * WITHOUT ANY WARRANTY; without even the implied warranty of
6219 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6220 + * General Public License for more details.
6221 + */
6222 +
6223 +#include <linux/module.h>
6224 +#include <linux/types.h>
6225 +
6226 +#include <sound/core.h>
6227 +#include <sound/soc.h>
6228 +#include <sound/pcm_params.h>
6229 +#include <sound/control.h>
6230 +
6231 +#include "../codecs/wm8731.h"
6232 +
6233 +static const unsigned int bcm2835_rates_12000000[] = {
6234 + 8000, 16000, 32000, 44100, 48000, 96000, 88200,
6235 +};
6236 +
6237 +static struct snd_pcm_hw_constraint_list bcm2835_constraints_12000000 = {
6238 + .list = bcm2835_rates_12000000,
6239 + .count = ARRAY_SIZE(bcm2835_rates_12000000),
6240 +};
6241 +
6242 +static int snd_audioinjector_pi_soundcard_startup(struct snd_pcm_substream *substream)
6243 +{
6244 + /* Setup constraints, because there is a 12 MHz XTAL on the board */
6245 + snd_pcm_hw_constraint_list(substream->runtime, 0,
6246 + SNDRV_PCM_HW_PARAM_RATE,
6247 + &bcm2835_constraints_12000000);
6248 + return 0;
6249 +}
6250 +
6251 +static int snd_audioinjector_pi_soundcard_hw_params(struct snd_pcm_substream *substream,
6252 + struct snd_pcm_hw_params *params)
6253 +{
6254 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
6255 + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
6256 +
6257 + switch (params_rate(params)){
6258 + case 8000:
6259 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 1);
6260 + case 16000:
6261 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 750);
6262 + case 32000:
6263 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 375);
6264 + case 44100:
6265 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 272);
6266 + case 48000:
6267 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 250);
6268 + case 88200:
6269 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 136);
6270 + case 96000:
6271 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 125);
6272 + default:
6273 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 125);
6274 + }
6275 +}
6276 +
6277 +/* machine stream operations */
6278 +static struct snd_soc_ops snd_audioinjector_pi_soundcard_ops = {
6279 + .startup = snd_audioinjector_pi_soundcard_startup,
6280 + .hw_params = snd_audioinjector_pi_soundcard_hw_params,
6281 +};
6282 +
6283 +static int audioinjector_pi_soundcard_dai_init(struct snd_soc_pcm_runtime *rtd)
6284 +{
6285 + return snd_soc_dai_set_sysclk(asoc_rtd_to_codec(rtd, 0), WM8731_SYSCLK_XTAL, 12000000, SND_SOC_CLOCK_IN);
6286 +}
6287 +
6288 +SND_SOC_DAILINK_DEFS(audioinjector_pi,
6289 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
6290 + DAILINK_COMP_ARRAY(COMP_CODEC("wm8731.1-001a", "wm8731-hifi")),
6291 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2835-i2s.0")));
6292 +
6293 +static struct snd_soc_dai_link audioinjector_pi_soundcard_dai[] = {
6294 + {
6295 + .name = "AudioInjector audio",
6296 + .stream_name = "AudioInjector audio",
6297 + .ops = &snd_audioinjector_pi_soundcard_ops,
6298 + .init = audioinjector_pi_soundcard_dai_init,
6299 + .dai_fmt = SND_SOC_DAIFMT_CBM_CFM|SND_SOC_DAIFMT_I2S|SND_SOC_DAIFMT_NB_NF,
6300 + SND_SOC_DAILINK_REG(audioinjector_pi),
6301 + },
6302 +};
6303 +
6304 +static const struct snd_soc_dapm_widget wm8731_dapm_widgets[] = {
6305 + SND_SOC_DAPM_HP("Headphone Jack", NULL),
6306 + SND_SOC_DAPM_SPK("Ext Spk", NULL),
6307 + SND_SOC_DAPM_LINE("Line In Jacks", NULL),
6308 + SND_SOC_DAPM_MIC("Microphone", NULL),
6309 +};
6310 +
6311 +static const struct snd_soc_dapm_route audioinjector_audio_map[] = {
6312 + /* headphone connected to LHPOUT, RHPOUT */
6313 + {"Headphone Jack", NULL, "LHPOUT"},
6314 + {"Headphone Jack", NULL, "RHPOUT"},
6315 +
6316 + /* speaker connected to LOUT, ROUT */
6317 + {"Ext Spk", NULL, "ROUT"},
6318 + {"Ext Spk", NULL, "LOUT"},
6319 +
6320 + /* line inputs */
6321 + {"Line In Jacks", NULL, "Line Input"},
6322 +
6323 + /* mic is connected to Mic Jack, with WM8731 Mic Bias */
6324 + {"Microphone", NULL, "Mic Bias"},
6325 +};
6326 +
6327 +static struct snd_soc_card snd_soc_audioinjector = {
6328 + .name = "audioinjector-pi-soundcard",
6329 + .dai_link = audioinjector_pi_soundcard_dai,
6330 + .num_links = ARRAY_SIZE(audioinjector_pi_soundcard_dai),
6331 +
6332 + .dapm_widgets = wm8731_dapm_widgets,
6333 + .num_dapm_widgets = ARRAY_SIZE(wm8731_dapm_widgets),
6334 + .dapm_routes = audioinjector_audio_map,
6335 + .num_dapm_routes = ARRAY_SIZE(audioinjector_audio_map),
6336 +};
6337 +
6338 +static int audioinjector_pi_soundcard_probe(struct platform_device *pdev)
6339 +{
6340 + struct snd_soc_card *card = &snd_soc_audioinjector;
6341 + int ret;
6342 +
6343 + card->dev = &pdev->dev;
6344 +
6345 + if (pdev->dev.of_node) {
6346 + struct snd_soc_dai_link *dai = &audioinjector_pi_soundcard_dai[0];
6347 + struct device_node *i2s_node = of_parse_phandle(pdev->dev.of_node,
6348 + "i2s-controller", 0);
6349 +
6350 + if (i2s_node) {
6351 + dai->cpus->dai_name = NULL;
6352 + dai->cpus->of_node = i2s_node;
6353 + dai->platforms->name = NULL;
6354 + dai->platforms->of_node = i2s_node;
6355 + } else
6356 + if (!dai->cpus->of_node) {
6357 + dev_err(&pdev->dev, "Property 'i2s-controller' missing or invalid\n");
6358 + return -EINVAL;
6359 + }
6360 + }
6361 +
6362 + if ((ret = devm_snd_soc_register_card(&pdev->dev, card)))
6363 + return dev_err_probe(&pdev->dev, ret, "%s\n", __func__);
6364 +
6365 + dev_info(&pdev->dev, "successfully loaded\n");
6366 +
6367 + return ret;
6368 +}
6369 +
6370 +static const struct of_device_id audioinjector_pi_soundcard_of_match[] = {
6371 + { .compatible = "ai,audioinjector-pi-soundcard", },
6372 + {},
6373 +};
6374 +MODULE_DEVICE_TABLE(of, audioinjector_pi_soundcard_of_match);
6375 +
6376 +static struct platform_driver audioinjector_pi_soundcard_driver = {
6377 + .driver = {
6378 + .name = "audioinjector-stereo",
6379 + .owner = THIS_MODULE,
6380 + .of_match_table = audioinjector_pi_soundcard_of_match,
6381 + },
6382 + .probe = audioinjector_pi_soundcard_probe,
6383 +};
6384 +
6385 +module_platform_driver(audioinjector_pi_soundcard_driver);
6386 +MODULE_AUTHOR("Matt Flax <flatmax@flatmax.org>");
6387 +MODULE_DESCRIPTION("AudioInjector.net Pi Soundcard");
6388 +MODULE_LICENSE("GPL v2");
6389 +MODULE_ALIAS("platform:audioinjector-pi-soundcard");
6390 +
6391 --- /dev/null
6392 +++ b/sound/soc/bcm/audiosense-pi.c
6393 @@ -0,0 +1,248 @@
6394 +/*
6395 + * ASoC Driver for AudioSense add on soundcard
6396 + * Author:
6397 + * Bhargav A K <anur.bhargav@gmail.com>
6398 + * Copyright 2017
6399 + *
6400 + * This program is free software; you can redistribute it and/or
6401 + * modify it under the terms of the GNU General Public License
6402 + * version 2 as published by the Free Software Foundation.
6403 + *
6404 + * This program is distributed in the hope that it will be useful, but
6405 + * WITHOUT ANY WARRANTY; without even the implied warranty of
6406 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6407 + * General Public License for more details.
6408 + */
6409 +
6410 +#include <linux/module.h>
6411 +#include <linux/platform_device.h>
6412 +#include <linux/clk.h>
6413 +#include <linux/i2c.h>
6414 +#include <sound/core.h>
6415 +#include <sound/pcm.h>
6416 +#include <sound/pcm_params.h>
6417 +#include <sound/soc.h>
6418 +#include <sound/jack.h>
6419 +#include <sound/control.h>
6420 +
6421 +#include <sound/tlv320aic32x4.h>
6422 +#include "../codecs/tlv320aic32x4.h"
6423 +
6424 +#define AIC32X4_SYSCLK_XTAL 0x00
6425 +
6426 +/*
6427 + * Setup Codec Sample Rates and Channels
6428 + * Supported Rates:
6429 + * 8000, 11025, 16000, 22050, 32000, 44100, 48000, 64000, 88200, 96000,
6430 + */
6431 +static const unsigned int audiosense_pi_rate[] = {
6432 + 48000,
6433 +};
6434 +
6435 +static struct snd_pcm_hw_constraint_list audiosense_constraints_rates = {
6436 + .list = audiosense_pi_rate,
6437 + .count = ARRAY_SIZE(audiosense_pi_rate),
6438 +};
6439 +
6440 +static const unsigned int audiosense_pi_channels[] = {
6441 + 2,
6442 +};
6443 +
6444 +static struct snd_pcm_hw_constraint_list audiosense_constraints_ch = {
6445 + .count = ARRAY_SIZE(audiosense_pi_channels),
6446 + .list = audiosense_pi_channels,
6447 + .mask = 0,
6448 +};
6449 +
6450 +/* Setup DAPM widgets and paths */
6451 +static const struct snd_soc_dapm_widget audiosense_pi_dapm_widgets[] = {
6452 + SND_SOC_DAPM_HP("Headphone Jack", NULL),
6453 + SND_SOC_DAPM_LINE("Line Out", NULL),
6454 + SND_SOC_DAPM_LINE("Line In", NULL),
6455 + SND_SOC_DAPM_INPUT("CM_L"),
6456 + SND_SOC_DAPM_INPUT("CM_R"),
6457 +};
6458 +
6459 +static const struct snd_soc_dapm_route audiosense_pi_audio_map[] = {
6460 + /* Line Inputs are connected to
6461 + * (IN1_L | IN1_R)
6462 + * (IN2_L | IN2_R)
6463 + * (IN3_L | IN3_R)
6464 + */
6465 + {"IN1_L", NULL, "Line In"},
6466 + {"IN1_R", NULL, "Line In"},
6467 + {"IN2_L", NULL, "Line In"},
6468 + {"IN2_R", NULL, "Line In"},
6469 + {"IN3_L", NULL, "Line In"},
6470 + {"IN3_R", NULL, "Line In"},
6471 +
6472 + /* Mic is connected to IN2_L and IN2_R */
6473 + {"Left ADC", NULL, "Mic Bias"},
6474 + {"Right ADC", NULL, "Mic Bias"},
6475 +
6476 + /* Headphone connected to HPL, HPR */
6477 + {"Headphone Jack", NULL, "HPL"},
6478 + {"Headphone Jack", NULL, "HPR"},
6479 +
6480 + /* Speakers connected to LOL and LOR */
6481 + {"Line Out", NULL, "LOL"},
6482 + {"Line Out", NULL, "LOR"},
6483 +};
6484 +
6485 +static int audiosense_pi_card_init(struct snd_soc_pcm_runtime *rtd)
6486 +{
6487 + /* TODO: init of the codec specific dapm data, ignore suspend/resume */
6488 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
6489 +
6490 + snd_soc_component_update_bits(component, AIC32X4_MICBIAS, 0x78,
6491 + AIC32X4_MICBIAS_LDOIN |
6492 + AIC32X4_MICBIAS_2075V);
6493 + snd_soc_component_update_bits(component, AIC32X4_PWRCFG, 0x08,
6494 + AIC32X4_AVDDWEAKDISABLE);
6495 + snd_soc_component_update_bits(component, AIC32X4_LDOCTL, 0x01,
6496 + AIC32X4_LDOCTLEN);
6497 +
6498 + return 0;
6499 +}
6500 +
6501 +static int audiosense_pi_card_hw_params(
6502 + struct snd_pcm_substream *substream,
6503 + struct snd_pcm_hw_params *params)
6504 +{
6505 + int ret = 0;
6506 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
6507 + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
6508 +
6509 + /* Set the codec system clock, there is a 12 MHz XTAL on the board */
6510 + ret = snd_soc_dai_set_sysclk(codec_dai, AIC32X4_SYSCLK_XTAL,
6511 + 12000000, SND_SOC_CLOCK_IN);
6512 + if (ret) {
6513 + dev_err(rtd->card->dev,
6514 + "could not set codec driver clock params\n");
6515 + return ret;
6516 + }
6517 + return 0;
6518 +}
6519 +
6520 +static int audiosense_pi_card_startup(struct snd_pcm_substream *substream)
6521 +{
6522 + struct snd_pcm_runtime *runtime = substream->runtime;
6523 +
6524 + /*
6525 + * Set codec to 48Khz Sampling, Stereo I/O and 16 bit audio
6526 + */
6527 + runtime->hw.channels_max = 2;
6528 + snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
6529 + &audiosense_constraints_ch);
6530 +
6531 + runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE;
6532 + snd_pcm_hw_constraint_msbits(runtime, 0, 16, 16);
6533 +
6534 +
6535 + snd_pcm_hw_constraint_list(substream->runtime, 0,
6536 + SNDRV_PCM_HW_PARAM_RATE,
6537 + &audiosense_constraints_rates);
6538 + return 0;
6539 +}
6540 +
6541 +static struct snd_soc_ops audiosense_pi_card_ops = {
6542 + .startup = audiosense_pi_card_startup,
6543 + .hw_params = audiosense_pi_card_hw_params,
6544 +};
6545 +
6546 +SND_SOC_DAILINK_DEFS(audiosense_pi,
6547 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
6548 + DAILINK_COMP_ARRAY(COMP_CODEC("tlv320aic32x4.1-0018", "tlv320aic32x4-hifi")),
6549 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
6550 +
6551 +static struct snd_soc_dai_link audiosense_pi_card_dai[] = {
6552 + {
6553 + .name = "TLV320AIC3204 Audio",
6554 + .stream_name = "TLV320AIC3204 Hifi Audio",
6555 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
6556 + SND_SOC_DAIFMT_CBM_CFM,
6557 + .ops = &audiosense_pi_card_ops,
6558 + .init = audiosense_pi_card_init,
6559 + SND_SOC_DAILINK_REG(audiosense_pi),
6560 + },
6561 +};
6562 +
6563 +static struct snd_soc_card audiosense_pi_card = {
6564 + .name = "audiosense-pi",
6565 + .driver_name = "audiosense-pi",
6566 + .dai_link = audiosense_pi_card_dai,
6567 + .owner = THIS_MODULE,
6568 + .num_links = ARRAY_SIZE(audiosense_pi_card_dai),
6569 + .dapm_widgets = audiosense_pi_dapm_widgets,
6570 + .num_dapm_widgets = ARRAY_SIZE(audiosense_pi_dapm_widgets),
6571 + .dapm_routes = audiosense_pi_audio_map,
6572 + .num_dapm_routes = ARRAY_SIZE(audiosense_pi_audio_map),
6573 +};
6574 +
6575 +static int audiosense_pi_card_probe(struct platform_device *pdev)
6576 +{
6577 + int ret = 0;
6578 + struct snd_soc_card *card = &audiosense_pi_card;
6579 + struct snd_soc_dai_link *dai = &audiosense_pi_card_dai[0];
6580 + struct device_node *i2s_node = pdev->dev.of_node;
6581 +
6582 + card->dev = &pdev->dev;
6583 +
6584 + if (!dai) {
6585 + dev_err(&pdev->dev, "DAI not found. Missing or Invalid\n");
6586 + return -EINVAL;
6587 + }
6588 +
6589 + i2s_node = of_parse_phandle(pdev->dev.of_node, "i2s-controller", 0);
6590 + if (!i2s_node) {
6591 + dev_err(&pdev->dev,
6592 + "Property 'i2s-controller' missing or invalid\n");
6593 + return -EINVAL;
6594 + }
6595 +
6596 + dai->cpus->dai_name = NULL;
6597 + dai->cpus->of_node = i2s_node;
6598 + dai->platforms->name = NULL;
6599 + dai->platforms->of_node = i2s_node;
6600 +
6601 + of_node_put(i2s_node);
6602 +
6603 + ret = snd_soc_register_card(card);
6604 + if (ret && ret != -EPROBE_DEFER)
6605 + dev_err(&pdev->dev,
6606 + "snd_soc_register_card() failed: %d\n", ret);
6607 +
6608 + return ret;
6609 +}
6610 +
6611 +static int audiosense_pi_card_remove(struct platform_device *pdev)
6612 +{
6613 + struct snd_soc_card *card = platform_get_drvdata(pdev);
6614 +
6615 + snd_soc_unregister_card(card);
6616 + return 0;
6617 +}
6618 +
6619 +static const struct of_device_id audiosense_pi_card_of_match[] = {
6620 + { .compatible = "as,audiosense-pi", },
6621 + {},
6622 +};
6623 +MODULE_DEVICE_TABLE(of, audiosense_pi_card_of_match);
6624 +
6625 +static struct platform_driver audiosense_pi_card_driver = {
6626 + .driver = {
6627 + .name = "audiosense-snd-card",
6628 + .owner = THIS_MODULE,
6629 + .of_match_table = audiosense_pi_card_of_match,
6630 + },
6631 + .probe = audiosense_pi_card_probe,
6632 + .remove = audiosense_pi_card_remove,
6633 +};
6634 +
6635 +module_platform_driver(audiosense_pi_card_driver);
6636 +
6637 +MODULE_AUTHOR("Bhargav AK <anur.bhargav@gmail.com>");
6638 +MODULE_DESCRIPTION("ASoC Driver for TLV320AIC3204 Audio");
6639 +MODULE_LICENSE("GPL v2");
6640 +MODULE_ALIAS("platform:audiosense-pi");
6641 +
6642 --- a/sound/soc/bcm/bcm2835-i2s.c
6643 +++ b/sound/soc/bcm/bcm2835-i2s.c
6644 @@ -30,7 +30,6 @@
6645 #include <linux/init.h>
6646 #include <linux/io.h>
6647 #include <linux/module.h>
6648 -#include <linux/of_address.h>
6649 #include <linux/slab.h>
6650
6651 #include <sound/core.h>
6652 @@ -830,8 +829,7 @@ static int bcm2835_i2s_probe(struct plat
6653 struct bcm2835_i2s_dev *dev;
6654 int ret;
6655 void __iomem *base;
6656 - const __be32 *addr;
6657 - dma_addr_t dma_base;
6658 + struct resource *res;
6659
6660 dev = devm_kzalloc(&pdev->dev, sizeof(*dev),
6661 GFP_KERNEL);
6662 @@ -846,7 +844,7 @@ static int bcm2835_i2s_probe(struct plat
6663 "could not get clk\n");
6664
6665 /* Request ioarea */
6666 - base = devm_platform_ioremap_resource(pdev, 0);
6667 + base = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
6668 if (IS_ERR(base))
6669 return PTR_ERR(base);
6670
6671 @@ -855,19 +853,11 @@ static int bcm2835_i2s_probe(struct plat
6672 if (IS_ERR(dev->i2s_regmap))
6673 return PTR_ERR(dev->i2s_regmap);
6674
6675 - /* Set the DMA address - we have to parse DT ourselves */
6676 - addr = of_get_address(pdev->dev.of_node, 0, NULL, NULL);
6677 - if (!addr) {
6678 - dev_err(&pdev->dev, "could not get DMA-register address\n");
6679 - return -EINVAL;
6680 - }
6681 - dma_base = be32_to_cpup(addr);
6682 -
6683 dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK].addr =
6684 - dma_base + BCM2835_I2S_FIFO_A_REG;
6685 + res->start + BCM2835_I2S_FIFO_A_REG;
6686
6687 dev->dma_data[SNDRV_PCM_STREAM_CAPTURE].addr =
6688 - dma_base + BCM2835_I2S_FIFO_A_REG;
6689 + res->start + BCM2835_I2S_FIFO_A_REG;
6690
6691 /* Set the bus width */
6692 dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK].addr_width =
6693 --- /dev/null
6694 +++ b/sound/soc/bcm/chipdip-dac.c
6695 @@ -0,0 +1,275 @@
6696 +/*
6697 + * ASoC Driver for ChipDip DAC
6698 + *
6699 + * Author: Evgenij Sapunov
6700 + * Copyright 2021
6701 + * based on code by Milan Neskovic <info@justboom.co>
6702 + * based on code by Jaikumar <jaikumar@cem-solutions.net>
6703 + *
6704 + * Thanks to Phil Elwell (pelwell) for help.
6705 + *
6706 + * This program is free software; you can redistribute it and/or
6707 + * modify it under the terms of the GNU General Public License
6708 + * version 2 as published by the Free Software Foundation.
6709 + *
6710 + * This program is distributed in the hope that it will be useful, but
6711 + * WITHOUT ANY WARRANTY; without even the implied warranty of
6712 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6713 + * General Public License for more details.
6714 + */
6715 +
6716 +#include <linux/module.h>
6717 +#include <linux/gpio/consumer.h>
6718 +#include <linux/platform_device.h>
6719 +#include <linux/delay.h>
6720 +
6721 +#include <sound/core.h>
6722 +#include <sound/pcm.h>
6723 +#include <sound/pcm_params.h>
6724 +#include <sound/soc.h>
6725 +#include <sound/jack.h>
6726 +
6727 +#define SR_BIT_0 0 //sample rate bits
6728 +#define SR_BIT_1 1
6729 +#define SR_BIT_2 2
6730 +#define BD_BIT_0 3 //bit depth bits
6731 +#define BD_BIT_1 4
6732 +
6733 +#define SAMPLE_RATE_MASK_44_1 0
6734 +#define SAMPLE_RATE_MASK_48 (1 << SR_BIT_0)
6735 +#define SAMPLE_RATE_MASK_88_2 ((1 << SR_BIT_2) | (1 << SR_BIT_1))
6736 +#define SAMPLE_RATE_MASK_96 (1 << SR_BIT_1)
6737 +#define SAMPLE_RATE_MASK_176_4 ((1 << SR_BIT_2) | (1 << SR_BIT_1) | (1 << SR_BIT_0))
6738 +#define SAMPLE_RATE_MASK_192 ((1 << SR_BIT_1) | (1 << SR_BIT_0))
6739 +#define SAMPLE_RATE_MASK ((1 << SR_BIT_2) | (1 << SR_BIT_1) | (1 << SR_BIT_0))
6740 +
6741 +#define BIT_DEPTH_MASK_16 0
6742 +#define BIT_DEPTH_MASK_24 (1 << BD_BIT_0)
6743 +#define BIT_DEPTH_MASK_32 (1 << BD_BIT_1)
6744 +#define BIT_DEPTH_MASK ((1 << BD_BIT_1) | (1 << BD_BIT_0))
6745 +
6746 +#define MUTE_ACTIVE 0
6747 +#define MUTE_NOT_ACTIVE 1
6748 +
6749 +#define HW_PARAMS_GPIO_COUNT 5
6750 +
6751 +static struct gpio_desc *mute_gpio;
6752 +static struct gpio_desc *sdwn_gpio;
6753 +static struct gpio_desc *hw_params_gpios[HW_PARAMS_GPIO_COUNT];
6754 +static int current_width;
6755 +static int current_rate;
6756 +
6757 +static void snd_rpi_chipdip_dac_gpio_array_set(int value);
6758 +static void snd_rpi_chipdip_dac_gpio_set(struct gpio_desc *gpio_item, int value);
6759 +
6760 +static void snd_rpi_chipdip_dac_gpio_array_set(int value)
6761 +{
6762 + int i = 0;
6763 +
6764 + for (i = 0; i < HW_PARAMS_GPIO_COUNT; i++)
6765 + snd_rpi_chipdip_dac_gpio_set(hw_params_gpios[i], ((value >> i) & 1));
6766 +}
6767 +
6768 +static void snd_rpi_chipdip_dac_gpio_set(struct gpio_desc *gpio_item, int value)
6769 +{
6770 + if (gpio_item)
6771 + gpiod_set_value_cansleep(gpio_item, value);
6772 +}
6773 +
6774 +static int snd_rpi_chipdip_dac_init(struct snd_soc_pcm_runtime *rtd)
6775 +{
6776 + return 0;
6777 +}
6778 +
6779 +static int snd_rpi_chipdip_dac_hw_params(struct snd_pcm_substream *substream,
6780 + struct snd_pcm_hw_params *params)
6781 +{
6782 + int ret = 0;
6783 + int gpio_change_pending = 0;
6784 + int sample_rate_state = 0;
6785 + int bit_depth_state = 0;
6786 + int param_value = params_width(params);
6787 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
6788 +
6789 + ret = snd_soc_dai_set_bclk_ratio(asoc_rtd_to_cpu(rtd, 0), 2 * 32);
6790 +
6791 + if (current_width != param_value) {
6792 + current_width = param_value;
6793 + gpio_change_pending = 1;
6794 +
6795 + switch (param_value) {
6796 + case 16:
6797 + bit_depth_state = BIT_DEPTH_MASK_16;
6798 + break;
6799 + case 24:
6800 + bit_depth_state = BIT_DEPTH_MASK_24;
6801 + break;
6802 + case 32:
6803 + bit_depth_state = BIT_DEPTH_MASK_32;
6804 + break;
6805 + default:
6806 + return -EINVAL;
6807 + }
6808 + }
6809 +
6810 + param_value = params_rate(params);
6811 + if (current_rate != param_value) {
6812 + current_rate = param_value;
6813 + gpio_change_pending = 1;
6814 +
6815 + switch (param_value) {
6816 + case 44100:
6817 + sample_rate_state = SAMPLE_RATE_MASK_44_1;
6818 + break;
6819 + case 48000:
6820 + sample_rate_state = SAMPLE_RATE_MASK_48;
6821 + break;
6822 + case 88200:
6823 + sample_rate_state = SAMPLE_RATE_MASK_88_2;
6824 + break;
6825 + case 96000:
6826 + sample_rate_state = SAMPLE_RATE_MASK_96;
6827 + break;
6828 + case 176400:
6829 + sample_rate_state = SAMPLE_RATE_MASK_176_4;
6830 + break;
6831 + case 192000:
6832 + sample_rate_state = SAMPLE_RATE_MASK_192;
6833 + break;
6834 + default:
6835 + return -EINVAL;
6836 + }
6837 + }
6838 +
6839 + if (gpio_change_pending) {
6840 + snd_rpi_chipdip_dac_gpio_set(mute_gpio, MUTE_ACTIVE);
6841 + snd_rpi_chipdip_dac_gpio_array_set(bit_depth_state | sample_rate_state);
6842 + msleep(300);
6843 + snd_rpi_chipdip_dac_gpio_set(mute_gpio, MUTE_NOT_ACTIVE);
6844 + }
6845 +
6846 + return ret;
6847 +}
6848 +
6849 +static int snd_rpi_chipdip_dac_startup(struct snd_pcm_substream *substream)
6850 +{
6851 + return 0;
6852 +}
6853 +
6854 +static void snd_rpi_chipdip_dac_shutdown(struct snd_pcm_substream *substream)
6855 +{
6856 +
6857 +}
6858 +
6859 +/* machine stream operations */
6860 +static struct snd_soc_ops snd_rpi_chipdip_dac_ops = {
6861 + .hw_params = snd_rpi_chipdip_dac_hw_params,
6862 + .startup = snd_rpi_chipdip_dac_startup,
6863 + .shutdown = snd_rpi_chipdip_dac_shutdown,
6864 +};
6865 +
6866 +SND_SOC_DAILINK_DEFS(hifi,
6867 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
6868 + DAILINK_COMP_ARRAY(COMP_CODEC("spdif-transmitter", "dit-hifi")),
6869 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
6870 +
6871 +static struct snd_soc_dai_link snd_rpi_chipdip_dac_dai[] = {
6872 +{
6873 + .name = "ChipDip DAC",
6874 + .stream_name = "ChipDip DAC HiFi",
6875 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
6876 + SND_SOC_DAIFMT_CBM_CFM,
6877 + .ops = &snd_rpi_chipdip_dac_ops,
6878 + .init = snd_rpi_chipdip_dac_init,
6879 + SND_SOC_DAILINK_REG(hifi),
6880 +},
6881 +};
6882 +
6883 +/* audio machine driver */
6884 +static struct snd_soc_card snd_rpi_chipdip_dac = {
6885 + .name = "ChipDipDAC",
6886 + .driver_name = "ChipdipDac",
6887 + .owner = THIS_MODULE,
6888 + .dai_link = snd_rpi_chipdip_dac_dai,
6889 + .num_links = ARRAY_SIZE(snd_rpi_chipdip_dac_dai),
6890 +};
6891 +
6892 +static int snd_rpi_chipdip_dac_probe(struct platform_device *pdev)
6893 +{
6894 + int ret = 0;
6895 + int i = 0;
6896 +
6897 + snd_rpi_chipdip_dac.dev = &pdev->dev;
6898 +
6899 + if (pdev->dev.of_node) {
6900 + struct device_node *i2s_node;
6901 + struct snd_soc_dai_link *dai = &snd_rpi_chipdip_dac_dai[0];
6902 + i2s_node = of_parse_phandle(pdev->dev.of_node,
6903 + "i2s-controller", 0);
6904 +
6905 + if (i2s_node) {
6906 + dai->cpus->dai_name = NULL;
6907 + dai->cpus->of_node = i2s_node;
6908 + dai->platforms->name = NULL;
6909 + dai->platforms->of_node = i2s_node;
6910 + }
6911 + }
6912 +
6913 + hw_params_gpios[SR_BIT_0] = devm_gpiod_get_optional(&pdev->dev, "sr0", GPIOD_OUT_LOW);
6914 + hw_params_gpios[SR_BIT_1] = devm_gpiod_get_optional(&pdev->dev, "sr1", GPIOD_OUT_LOW);
6915 + hw_params_gpios[SR_BIT_2] = devm_gpiod_get_optional(&pdev->dev, "sr2", GPIOD_OUT_LOW);
6916 + hw_params_gpios[BD_BIT_0] = devm_gpiod_get_optional(&pdev->dev, "res0", GPIOD_OUT_LOW);
6917 + hw_params_gpios[BD_BIT_1] = devm_gpiod_get_optional(&pdev->dev, "res1", GPIOD_OUT_LOW);
6918 + mute_gpio = devm_gpiod_get_optional(&pdev->dev, "mute", GPIOD_OUT_LOW);
6919 + sdwn_gpio = devm_gpiod_get_optional(&pdev->dev, "sdwn", GPIOD_OUT_HIGH);
6920 +
6921 + for (i = 0; i < HW_PARAMS_GPIO_COUNT; i++) {
6922 + if (IS_ERR(hw_params_gpios[i])) {
6923 + ret = PTR_ERR(hw_params_gpios[i]);
6924 + dev_err(&pdev->dev, "failed to get hw_params gpio: %d\n", ret);
6925 + return ret;
6926 + }
6927 + }
6928 +
6929 + if (IS_ERR(mute_gpio)) {
6930 + ret = PTR_ERR(mute_gpio);
6931 + dev_err(&pdev->dev, "failed to get mute gpio: %d\n", ret);
6932 + return ret;
6933 + }
6934 +
6935 + if (IS_ERR(sdwn_gpio)) {
6936 + ret = PTR_ERR(sdwn_gpio);
6937 + dev_err(&pdev->dev, "failed to get sdwn gpio: %d\n", ret);
6938 + return ret;
6939 + }
6940 +
6941 + snd_rpi_chipdip_dac_gpio_set(sdwn_gpio, 1);
6942 +
6943 + ret = devm_snd_soc_register_card(&pdev->dev, &snd_rpi_chipdip_dac);
6944 + if (ret && ret != -EPROBE_DEFER)
6945 + dev_err(&pdev->dev,
6946 + "snd_soc_register_card() failed: %d\n", ret);
6947 +
6948 + return ret;
6949 +}
6950 +
6951 +static const struct of_device_id snd_rpi_chipdip_dac_of_match[] = {
6952 + { .compatible = "chipdip,chipdip-dac", },
6953 + {},
6954 +};
6955 +MODULE_DEVICE_TABLE(of, snd_rpi_chipdip_dac_of_match);
6956 +
6957 +static struct platform_driver snd_rpi_chipdip_dac_driver = {
6958 + .driver = {
6959 + .name = "snd-rpi-chipdip-dac",
6960 + .owner = THIS_MODULE,
6961 + .of_match_table = snd_rpi_chipdip_dac_of_match,
6962 + },
6963 + .probe = snd_rpi_chipdip_dac_probe,
6964 +};
6965 +
6966 +module_platform_driver(snd_rpi_chipdip_dac_driver);
6967 +
6968 +MODULE_AUTHOR("Evgenij Sapunov <evgenij.sapunov@chipdip.ru>");
6969 +MODULE_DESCRIPTION("ASoC Driver for ChipDip DAC");
6970 +MODULE_LICENSE("GPL v2");
6971 --- /dev/null
6972 +++ b/sound/soc/bcm/dacberry400.c
6973 @@ -0,0 +1,259 @@
6974 +/*
6975 + * ASoC Driver for Dacberry400 soundcard
6976 + * Author:
6977 + * Ashish Vara<ashishhvara@gmail.com>
6978 + * Copyright 2022
6979 + *
6980 + * This program is free software; you can redistribute it and/or
6981 + * modify it under the terms of the GNU General Public License
6982 + * version 2 as published by the Free Software Foundation.
6983 + *
6984 + * This program is distributed in the hope that it will be useful, but
6985 + * WITHOUT ANY WARRANTY; without even the implied warranty of
6986 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6987 + * General Public License for more details.
6988 + */
6989 +
6990 +#include <linux/module.h>
6991 +#include <linux/gpio/consumer.h>
6992 +#include <linux/platform_device.h>
6993 +#include <sound/core.h>
6994 +#include <sound/pcm.h>
6995 +#include <sound/pcm_params.h>
6996 +#include <sound/soc.h>
6997 +#include <sound/jack.h>
6998 +#include <linux/i2c.h>
6999 +#include <linux/acpi.h>
7000 +#include <linux/slab.h>
7001 +#include "../sound/soc/codecs/tlv320aic3x.h"
7002 +
7003 +static const struct snd_kcontrol_new dacberry400_controls[] = {
7004 + SOC_DAPM_PIN_SWITCH("MIC Jack"),
7005 + SOC_DAPM_PIN_SWITCH("Line In"),
7006 + SOC_DAPM_PIN_SWITCH("Line Out"),
7007 + SOC_DAPM_PIN_SWITCH("Headphone Jack"),
7008 +};
7009 +
7010 +static const struct snd_soc_dapm_widget dacberry400_widgets[] = {
7011 + SND_SOC_DAPM_HP("Headphone Jack", NULL),
7012 + SND_SOC_DAPM_MIC("MIC Jack", NULL),
7013 + SND_SOC_DAPM_LINE("Line In", NULL),
7014 + SND_SOC_DAPM_LINE("Line Out", NULL),
7015 +};
7016 +
7017 +static const struct snd_soc_dapm_route dacberry400_audio_map[] = {
7018 + {"Headphone Jack", NULL, "HPLOUT"},
7019 + {"Headphone Jack", NULL, "HPROUT"},
7020 +
7021 + {"LINE1L", NULL, "Line In"},
7022 + {"LINE1R", NULL, "Line In"},
7023 +
7024 + {"Line Out", NULL, "LLOUT"},
7025 + {"Line Out", NULL, "RLOUT"},
7026 +
7027 + {"MIC3L", NULL, "MIC Jack"},
7028 + {"MIC3R", NULL, "MIC Jack"},
7029 +};
7030 +
7031 +static int snd_rpi_dacberry400_init(struct snd_soc_pcm_runtime *rtd)
7032 +{
7033 + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
7034 + struct snd_soc_component *component = codec_dai->component;
7035 + int ret;
7036 +
7037 + ret = snd_soc_dai_set_sysclk(codec_dai, 2, 12000000,
7038 + SND_SOC_CLOCK_OUT);
7039 +
7040 + if (ret && ret != -ENOTSUPP)
7041 + goto err;
7042 +
7043 + snd_soc_component_write(component, HPRCOM_CFG, 0x20);
7044 + snd_soc_component_write(component, DACL1_2_HPLOUT_VOL, 0x80);
7045 + snd_soc_component_write(component, DACR1_2_HPROUT_VOL, 0x80);
7046 +err:
7047 + return ret;
7048 +}
7049 +
7050 +static int snd_rpi_dacberry400_set_bias_level(struct snd_soc_card *card,
7051 + struct snd_soc_dapm_context *dapm, enum snd_soc_bias_level level)
7052 +{
7053 + struct snd_soc_pcm_runtime *rtd;
7054 + struct snd_soc_dai *codec_dai;
7055 + struct snd_soc_component *component;
7056 + struct dacberry_priv *aic3x;
7057 + u8 hpcom_reg = 0;
7058 +
7059 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
7060 + codec_dai = asoc_rtd_to_codec(rtd, 0);
7061 + component = codec_dai->component;
7062 + aic3x = snd_soc_component_get_drvdata(component);
7063 + if (dapm->dev != codec_dai->dev)
7064 + return 0;
7065 +
7066 + switch (level) {
7067 + case SND_SOC_BIAS_PREPARE:
7068 + if (dapm->bias_level != SND_SOC_BIAS_STANDBY)
7069 + break;
7070 + /* UNMUTE ADC/DAC */
7071 + hpcom_reg = snd_soc_component_read(component, HPLCOM_CFG);
7072 + snd_soc_component_write(component, HPLCOM_CFG, hpcom_reg | 0x20);
7073 + snd_soc_component_write(component, LINE1R_2_RADC_CTRL, 0x04);
7074 + snd_soc_component_write(component, LINE1L_2_LADC_CTRL, 0x04);
7075 + snd_soc_component_write(component, LADC_VOL, 0x00);
7076 + snd_soc_component_write(component, RADC_VOL, 0x00);
7077 + pr_info("%s: unmute ADC/DAC\n", __func__);
7078 + break;
7079 +
7080 + case SND_SOC_BIAS_STANDBY:
7081 + if (dapm->bias_level != SND_SOC_BIAS_PREPARE)
7082 + break;
7083 + /* MUTE ADC/DAC */
7084 + snd_soc_component_write(component, LDAC_VOL, 0x80);
7085 + snd_soc_component_write(component, RDAC_VOL, 0x80);
7086 + snd_soc_component_write(component, LADC_VOL, 0x80);
7087 + snd_soc_component_write(component, RADC_VOL, 0x80);
7088 + snd_soc_component_write(component, LINE1R_2_RADC_CTRL, 0x00);
7089 + snd_soc_component_write(component, LINE1L_2_LADC_CTRL, 0x00);
7090 + snd_soc_component_write(component, HPLCOM_CFG, 0x00);
7091 + pr_info("%s: mute ADC/DAC\n", __func__);
7092 + break;
7093 + default:
7094 + break;
7095 + }
7096 +
7097 + return 0;
7098 +}
7099 +
7100 +static int snd_rpi_dacberry400_hw_params(struct snd_pcm_substream *substream,
7101 + struct snd_pcm_hw_params *params)
7102 +{
7103 + int ret = 0;
7104 + u8 data;
7105 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
7106 + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
7107 + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
7108 + struct snd_soc_component *component = codec_dai->component;
7109 + int fsref = (params_rate(params) % 11025 == 0) ? 44100 : 48000;
7110 + int channels = params_channels(params);
7111 + int width = 32;
7112 + u8 clock = 0;
7113 +
7114 + data = (LDAC2LCH | RDAC2RCH);
7115 + data |= (fsref == 44100) ? FSREF_44100 : FSREF_48000;
7116 + if (params_rate(params) >= 64000)
7117 + data |= DUAL_RATE_MODE;
7118 + ret = snd_soc_component_write(component, 0x7, data);
7119 + width = params_width(params);
7120 +
7121 + clock = snd_soc_component_read(component, 2);
7122 +
7123 + ret = snd_soc_dai_set_bclk_ratio(cpu_dai, channels*width);
7124 +
7125 + return ret;
7126 +}
7127 +
7128 +static const struct snd_soc_ops snd_rpi_dacberry400_ops = {
7129 + .hw_params = snd_rpi_dacberry400_hw_params,
7130 +};
7131 +
7132 +
7133 +SND_SOC_DAILINK_DEFS(rpi_dacberry400,
7134 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2835-i2s.0")),
7135 + DAILINK_COMP_ARRAY(COMP_CODEC("tlv320aic3x.1-0018", "tlv320aic3x-hifi")),
7136 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2835-i2s.0")));
7137 +
7138 +static struct snd_soc_dai_link snd_rpi_dacberry400_dai[] = {
7139 +{
7140 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
7141 + SND_SOC_DAIFMT_CBS_CFS,
7142 + .init = snd_rpi_dacberry400_init,
7143 + .ops = &snd_rpi_dacberry400_ops,
7144 + .symmetric_rate = 1,
7145 + SND_SOC_DAILINK_REG(rpi_dacberry400),
7146 +},
7147 +};
7148 +
7149 +static struct snd_soc_card snd_rpi_dacberry400 = {
7150 + .owner = THIS_MODULE,
7151 + .dai_link = snd_rpi_dacberry400_dai,
7152 + .num_links = ARRAY_SIZE(snd_rpi_dacberry400_dai),
7153 + .controls = dacberry400_controls,
7154 + .num_controls = ARRAY_SIZE(dacberry400_controls),
7155 + .dapm_widgets = dacberry400_widgets,
7156 + .num_dapm_widgets = ARRAY_SIZE(dacberry400_widgets),
7157 + .dapm_routes = dacberry400_audio_map,
7158 + .num_dapm_routes = ARRAY_SIZE(dacberry400_audio_map),
7159 + .set_bias_level = snd_rpi_dacberry400_set_bias_level,
7160 +};
7161 +
7162 +static int snd_rpi_dacberry400_probe(struct platform_device *pdev)
7163 +{
7164 + int ret = 0;
7165 +
7166 + snd_rpi_dacberry400.dev = &pdev->dev;
7167 +
7168 + if (pdev->dev.of_node) {
7169 + struct device_node *i2s_node;
7170 + struct snd_soc_card *card = &snd_rpi_dacberry400;
7171 + struct snd_soc_dai_link *dai = &snd_rpi_dacberry400_dai[0];
7172 +
7173 + i2s_node = of_parse_phandle(pdev->dev.of_node,
7174 + "i2s-controller", 0);
7175 + if (i2s_node) {
7176 + dai->cpus->dai_name = NULL;
7177 + dai->cpus->of_node = i2s_node;
7178 + dai->platforms->name = NULL;
7179 + dai->platforms->of_node = i2s_node;
7180 + of_node_put(i2s_node);
7181 + }
7182 +
7183 + if (of_property_read_string(pdev->dev.of_node, "card_name",
7184 + &card->name))
7185 + card->name = "tlvaudioCODEC";
7186 +
7187 + if (of_property_read_string(pdev->dev.of_node, "dai_name",
7188 + &dai->name))
7189 + dai->name = "tlvaudio CODEC";
7190 +
7191 + }
7192 +
7193 + ret = snd_soc_register_card(&snd_rpi_dacberry400);
7194 + if (ret) {
7195 + if (ret != -EPROBE_DEFER)
7196 + dev_err(&pdev->dev,
7197 + "snd_soc_register_card() failed: %d\n", ret);
7198 + return ret;
7199 + }
7200 +
7201 + return 0;
7202 +}
7203 +
7204 +static int snd_rpi_dacberry400_remove(struct platform_device *pdev)
7205 +{
7206 + snd_soc_unregister_card(&snd_rpi_dacberry400);
7207 + return 0;
7208 +}
7209 +
7210 +static const struct of_device_id dacberry400_match_id[] = {
7211 + { .compatible = "osaelectronics,dacberry400",},
7212 + {},
7213 +};
7214 +MODULE_DEVICE_TABLE(of, dacberry400_match_id);
7215 +
7216 +static struct platform_driver snd_rpi_dacberry400_driver = {
7217 + .driver = {
7218 + .name = "snd-rpi-dacberry400",
7219 + .owner = THIS_MODULE,
7220 + .of_match_table = dacberry400_match_id,
7221 + },
7222 + .probe = snd_rpi_dacberry400_probe,
7223 + .remove = snd_rpi_dacberry400_remove,
7224 +};
7225 +
7226 +module_platform_driver(snd_rpi_dacberry400_driver);
7227 +
7228 +MODULE_AUTHOR("Ashish Vara");
7229 +MODULE_DESCRIPTION("Dacberry400 sound card driver");
7230 +MODULE_LICENSE("GPL");
7231 +MODULE_ALIAS("platform:dacberry400");
7232 +MODULE_SOFTDEP("pre: snd-soc-tlv320aic3x");
7233 --- /dev/null
7234 +++ b/sound/soc/bcm/digidac1-soundcard.c
7235 @@ -0,0 +1,421 @@
7236 +/*
7237 + * ASoC Driver for RRA DigiDAC1
7238 + * Copyright 2016
7239 + * Author: José M. Tasende <vintage@redrocksaudio.es>
7240 + * based on the HifiBerry DAC driver by Florian Meier <florian.meier@koalo.de>
7241 + * and the Wolfson card driver by Nikesh Oswal, <Nikesh.Oswal@wolfsonmicro.com>
7242 + * This program is free software; you can redistribute it and/or
7243 + * modify it under the terms of the GNU General Public License
7244 + * version 2 as published by the Free Software Foundation.
7245 + *
7246 + * This program is distributed in the hope that it will be useful, but
7247 + * WITHOUT ANY WARRANTY; without even the implied warranty of
7248 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7249 + * General Public License for more details.
7250 + */
7251 +
7252 +#include <linux/module.h>
7253 +#include <linux/platform_device.h>
7254 +#include <linux/i2c.h>
7255 +#include <sound/core.h>
7256 +#include <sound/pcm.h>
7257 +#include <sound/pcm_params.h>
7258 +#include <sound/soc.h>
7259 +#include <sound/jack.h>
7260 +#include <sound/soc-dapm.h>
7261 +#include <sound/tlv.h>
7262 +#include <linux/regulator/consumer.h>
7263 +
7264 +#include "../codecs/wm8804.h"
7265 +#include "../codecs/wm8741.h"
7266 +
7267 +#define WM8741_NUM_SUPPLIES 2
7268 +
7269 +/* codec private data */
7270 +struct wm8741_priv {
7271 + struct wm8741_platform_data pdata;
7272 + struct regmap *regmap;
7273 + struct regulator_bulk_data supplies[WM8741_NUM_SUPPLIES];
7274 + unsigned int sysclk;
7275 + const struct snd_pcm_hw_constraint_list *sysclk_constraints;
7276 +};
7277 +
7278 +static int samplerate = 44100;
7279 +
7280 +/* New Alsa Controls not exposed by original wm8741 codec driver */
7281 +/* in actual driver the att. adjustment is wrong because */
7282 +/* this DAC has a coarse attenuation register with 4dB steps */
7283 +/* and a fine level register with 0.125dB steps */
7284 +/* each register has 32 steps so combining both we have 1024 steps */
7285 +/* of 0.125 dB. */
7286 +/* The original level controls from driver are removed at startup */
7287 +/* and replaced by the corrected ones. */
7288 +/* The same wm8741 driver can be used for wm8741 and wm8742 devices */
7289 +
7290 +static const DECLARE_TLV_DB_SCALE(dac_tlv_fine, 0, 13, 0);
7291 +static const DECLARE_TLV_DB_SCALE(dac_tlv_coarse, -12700, 400, 1);
7292 +static const char *w8741_dither[4] = {"Off", "RPDF", "TPDF", "HPDF"};
7293 +static const char *w8741_filter[5] = {
7294 + "Type 1", "Type 2", "Type 3", "Type 4", "Type 5"};
7295 +static const char *w8741_switch[2] = {"Off", "On"};
7296 +static const struct soc_enum w8741_enum[] = {
7297 +SOC_ENUM_SINGLE(WM8741_MODE_CONTROL_2, 0, 4, w8741_dither),/* dithering type */
7298 +SOC_ENUM_SINGLE(WM8741_FILTER_CONTROL, 0, 5, w8741_filter),/* filter type */
7299 +SOC_ENUM_SINGLE(WM8741_FORMAT_CONTROL, 6, 2, w8741_switch),/* phase invert */
7300 +SOC_ENUM_SINGLE(WM8741_VOLUME_CONTROL, 0, 2, w8741_switch),/* volume ramp */
7301 +SOC_ENUM_SINGLE(WM8741_VOLUME_CONTROL, 3, 2, w8741_switch),/* soft mute */
7302 +};
7303 +
7304 +static const struct snd_kcontrol_new w8741_snd_controls_stereo[] = {
7305 +SOC_DOUBLE_R_TLV("DAC Fine Playback Volume", WM8741_DACLLSB_ATTENUATION,
7306 + WM8741_DACRLSB_ATTENUATION, 0, 31, 1, dac_tlv_fine),
7307 +SOC_DOUBLE_R_TLV("Digital Playback Volume", WM8741_DACLMSB_ATTENUATION,
7308 + WM8741_DACRMSB_ATTENUATION, 0, 31, 1, dac_tlv_coarse),
7309 +SOC_ENUM("DAC Dither", w8741_enum[0]),
7310 +SOC_ENUM("DAC Digital Filter", w8741_enum[1]),
7311 +SOC_ENUM("DAC Phase Invert", w8741_enum[2]),
7312 +SOC_ENUM("DAC Volume Ramp", w8741_enum[3]),
7313 +SOC_ENUM("DAC Soft Mute", w8741_enum[4]),
7314 +};
7315 +
7316 +static const struct snd_kcontrol_new w8741_snd_controls_mono_left[] = {
7317 +SOC_SINGLE_TLV("DAC Fine Playback Volume", WM8741_DACLLSB_ATTENUATION,
7318 + 0, 31, 0, dac_tlv_fine),
7319 +SOC_SINGLE_TLV("Digital Playback Volume", WM8741_DACLMSB_ATTENUATION,
7320 + 0, 31, 1, dac_tlv_coarse),
7321 +SOC_ENUM("DAC Dither", w8741_enum[0]),
7322 +SOC_ENUM("DAC Digital Filter", w8741_enum[1]),
7323 +SOC_ENUM("DAC Phase Invert", w8741_enum[2]),
7324 +SOC_ENUM("DAC Volume Ramp", w8741_enum[3]),
7325 +SOC_ENUM("DAC Soft Mute", w8741_enum[4]),
7326 +};
7327 +
7328 +static const struct snd_kcontrol_new w8741_snd_controls_mono_right[] = {
7329 +SOC_SINGLE_TLV("DAC Fine Playback Volume", WM8741_DACRLSB_ATTENUATION,
7330 + 0, 31, 0, dac_tlv_fine),
7331 +SOC_SINGLE_TLV("Digital Playback Volume", WM8741_DACRMSB_ATTENUATION,
7332 + 0, 31, 1, dac_tlv_coarse),
7333 +SOC_ENUM("DAC Dither", w8741_enum[0]),
7334 +SOC_ENUM("DAC Digital Filter", w8741_enum[1]),
7335 +SOC_ENUM("DAC Phase Invert", w8741_enum[2]),
7336 +SOC_ENUM("DAC Volume Ramp", w8741_enum[3]),
7337 +SOC_ENUM("DAC Soft Mute", w8741_enum[4]),
7338 +};
7339 +
7340 +static int w8741_add_controls(struct snd_soc_component *component)
7341 +{
7342 + struct wm8741_priv *wm8741 = snd_soc_component_get_drvdata(component);
7343 +
7344 + switch (wm8741->pdata.diff_mode) {
7345 + case WM8741_DIFF_MODE_STEREO:
7346 + case WM8741_DIFF_MODE_STEREO_REVERSED:
7347 + snd_soc_add_component_controls(component,
7348 + w8741_snd_controls_stereo,
7349 + ARRAY_SIZE(w8741_snd_controls_stereo));
7350 + break;
7351 + case WM8741_DIFF_MODE_MONO_LEFT:
7352 + snd_soc_add_component_controls(component,
7353 + w8741_snd_controls_mono_left,
7354 + ARRAY_SIZE(w8741_snd_controls_mono_left));
7355 + break;
7356 + case WM8741_DIFF_MODE_MONO_RIGHT:
7357 + snd_soc_add_component_controls(component,
7358 + w8741_snd_controls_mono_right,
7359 + ARRAY_SIZE(w8741_snd_controls_mono_right));
7360 + break;
7361 + default:
7362 + return -EINVAL;
7363 + }
7364 +
7365 + return 0;
7366 +}
7367 +
7368 +static int digidac1_soundcard_init(struct snd_soc_pcm_runtime *rtd)
7369 +{
7370 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
7371 + struct snd_soc_card *card = rtd->card;
7372 + struct snd_soc_pcm_runtime *wm8741_rtd;
7373 + struct snd_soc_component *wm8741_component;
7374 + struct snd_card *sound_card = card->snd_card;
7375 + struct snd_kcontrol *kctl;
7376 + int ret;
7377 +
7378 + wm8741_rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[1]);
7379 + if (!wm8741_rtd) {
7380 + dev_warn(card->dev, "digidac1_soundcard_init: couldn't get wm8741 rtd\n");
7381 + return -EFAULT;
7382 + }
7383 + wm8741_component = asoc_rtd_to_codec(wm8741_rtd, 0)->component;
7384 + ret = w8741_add_controls(wm8741_component);
7385 + if (ret < 0)
7386 + dev_warn(card->dev, "Failed to add new wm8741 controls: %d\n",
7387 + ret);
7388 +
7389 + /* enable TX output */
7390 + snd_soc_component_update_bits(component, WM8804_PWRDN, 0x4, 0x0);
7391 +
7392 + kctl = snd_soc_card_get_kcontrol(card,
7393 + "Playback Volume");
7394 + if (kctl) {
7395 + kctl->vd[0].access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
7396 + snd_ctl_remove(sound_card, kctl);
7397 + }
7398 + kctl = snd_soc_card_get_kcontrol(card,
7399 + "Fine Playback Volume");
7400 + if (kctl) {
7401 + kctl->vd[0].access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
7402 + snd_ctl_remove(sound_card, kctl);
7403 + }
7404 + return 0;
7405 +}
7406 +
7407 +static int digidac1_soundcard_startup(struct snd_pcm_substream *substream)
7408 +{
7409 + /* turn on wm8804 digital output */
7410 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
7411 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
7412 + struct snd_soc_card *card = rtd->card;
7413 + struct snd_soc_pcm_runtime *wm8741_rtd;
7414 + struct snd_soc_component *wm8741_component;
7415 +
7416 + snd_soc_component_update_bits(component, WM8804_PWRDN, 0x3c, 0x00);
7417 + wm8741_rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[1]);
7418 + if (!wm8741_rtd) {
7419 + dev_warn(card->dev, "digidac1_soundcard_startup: couldn't get WM8741 rtd\n");
7420 + return -EFAULT;
7421 + }
7422 + wm8741_component = asoc_rtd_to_codec(wm8741_rtd, 0)->component;
7423 +
7424 + /* latch wm8741 level */
7425 + snd_soc_component_update_bits(wm8741_component, WM8741_DACLLSB_ATTENUATION,
7426 + WM8741_UPDATELL, WM8741_UPDATELL);
7427 + snd_soc_component_update_bits(wm8741_component, WM8741_DACLMSB_ATTENUATION,
7428 + WM8741_UPDATELM, WM8741_UPDATELM);
7429 + snd_soc_component_update_bits(wm8741_component, WM8741_DACRLSB_ATTENUATION,
7430 + WM8741_UPDATERL, WM8741_UPDATERL);
7431 + snd_soc_component_update_bits(wm8741_component, WM8741_DACRMSB_ATTENUATION,
7432 + WM8741_UPDATERM, WM8741_UPDATERM);
7433 +
7434 + return 0;
7435 +}
7436 +
7437 +static void digidac1_soundcard_shutdown(struct snd_pcm_substream *substream)
7438 +{
7439 + /* turn off wm8804 digital output */
7440 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
7441 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
7442 +
7443 + snd_soc_component_update_bits(component, WM8804_PWRDN, 0x3c, 0x3c);
7444 +}
7445 +
7446 +static int digidac1_soundcard_hw_params(struct snd_pcm_substream *substream,
7447 + struct snd_pcm_hw_params *params)
7448 +{
7449 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
7450 + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
7451 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
7452 + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
7453 + struct snd_soc_card *card = rtd->card;
7454 + struct snd_soc_pcm_runtime *wm8741_rtd;
7455 + struct snd_soc_component *wm8741_component;
7456 +
7457 + int sysclk = 27000000;
7458 + long mclk_freq = 0;
7459 + int mclk_div = 1;
7460 + int sampling_freq = 1;
7461 + int ret;
7462 +
7463 + wm8741_rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[1]);
7464 + if (!wm8741_rtd) {
7465 + dev_warn(card->dev, "digidac1_soundcard_hw_params: couldn't get WM8741 rtd\n");
7466 + return -EFAULT;
7467 + }
7468 + wm8741_component = asoc_rtd_to_codec(wm8741_rtd, 0)->component;
7469 + samplerate = params_rate(params);
7470 +
7471 + if (samplerate <= 96000) {
7472 + mclk_freq = samplerate*256;
7473 + mclk_div = WM8804_MCLKDIV_256FS;
7474 + } else {
7475 + mclk_freq = samplerate*128;
7476 + mclk_div = WM8804_MCLKDIV_128FS;
7477 + }
7478 +
7479 + switch (samplerate) {
7480 + case 32000:
7481 + sampling_freq = 0x03;
7482 + break;
7483 + case 44100:
7484 + sampling_freq = 0x00;
7485 + break;
7486 + case 48000:
7487 + sampling_freq = 0x02;
7488 + break;
7489 + case 88200:
7490 + sampling_freq = 0x08;
7491 + break;
7492 + case 96000:
7493 + sampling_freq = 0x0a;
7494 + break;
7495 + case 176400:
7496 + sampling_freq = 0x0c;
7497 + break;
7498 + case 192000:
7499 + sampling_freq = 0x0e;
7500 + break;
7501 + default:
7502 + dev_err(card->dev,
7503 + "Failed to set WM8804 SYSCLK, unsupported samplerate %d\n",
7504 + samplerate);
7505 + }
7506 +
7507 + snd_soc_dai_set_clkdiv(codec_dai, WM8804_MCLK_DIV, mclk_div);
7508 + snd_soc_dai_set_pll(codec_dai, 0, 0, sysclk, mclk_freq);
7509 +
7510 + ret = snd_soc_dai_set_sysclk(codec_dai, WM8804_TX_CLKSRC_PLL,
7511 + sysclk, SND_SOC_CLOCK_OUT);
7512 + if (ret < 0) {
7513 + dev_err(card->dev,
7514 + "Failed to set WM8804 SYSCLK: %d\n", ret);
7515 + return ret;
7516 + }
7517 + /* Enable wm8804 TX output */
7518 + snd_soc_component_update_bits(component, WM8804_PWRDN, 0x4, 0x0);
7519 +
7520 + /* wm8804 Power on */
7521 + snd_soc_component_update_bits(component, WM8804_PWRDN, 0x9, 0);
7522 +
7523 + /* wm8804 set sampling frequency status bits */
7524 + snd_soc_component_update_bits(component, WM8804_SPDTX4, 0x0f, sampling_freq);
7525 +
7526 + /* Now update wm8741 registers for the correct oversampling */
7527 + if (samplerate <= 48000)
7528 + snd_soc_component_update_bits(wm8741_component, WM8741_MODE_CONTROL_1,
7529 + WM8741_OSR_MASK, 0x00);
7530 + else if (samplerate <= 96000)
7531 + snd_soc_component_update_bits(wm8741_component, WM8741_MODE_CONTROL_1,
7532 + WM8741_OSR_MASK, 0x20);
7533 + else
7534 + snd_soc_component_update_bits(wm8741_component, WM8741_MODE_CONTROL_1,
7535 + WM8741_OSR_MASK, 0x40);
7536 +
7537 + /* wm8741 bit size */
7538 + switch (params_width(params)) {
7539 + case 16:
7540 + snd_soc_component_update_bits(wm8741_component, WM8741_FORMAT_CONTROL,
7541 + WM8741_IWL_MASK, 0x00);
7542 + break;
7543 + case 20:
7544 + snd_soc_component_update_bits(wm8741_component, WM8741_FORMAT_CONTROL,
7545 + WM8741_IWL_MASK, 0x01);
7546 + break;
7547 + case 24:
7548 + snd_soc_component_update_bits(wm8741_component, WM8741_FORMAT_CONTROL,
7549 + WM8741_IWL_MASK, 0x02);
7550 + break;
7551 + case 32:
7552 + snd_soc_component_update_bits(wm8741_component, WM8741_FORMAT_CONTROL,
7553 + WM8741_IWL_MASK, 0x03);
7554 + break;
7555 + default:
7556 + dev_dbg(card->dev, "wm8741_hw_params: Unsupported bit size param = %d",
7557 + params_width(params));
7558 + return -EINVAL;
7559 + }
7560 +
7561 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 64);
7562 +}
7563 +/* machine stream operations */
7564 +static struct snd_soc_ops digidac1_soundcard_ops = {
7565 + .hw_params = digidac1_soundcard_hw_params,
7566 + .startup = digidac1_soundcard_startup,
7567 + .shutdown = digidac1_soundcard_shutdown,
7568 +};
7569 +
7570 +SND_SOC_DAILINK_DEFS(digidac1,
7571 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
7572 + DAILINK_COMP_ARRAY(COMP_CODEC("wm8804.1-003b", "wm8804-spdif")),
7573 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2835-i2s.0")));
7574 +
7575 +SND_SOC_DAILINK_DEFS(digidac11,
7576 + DAILINK_COMP_ARRAY(COMP_CPU("wm8804-spdif")),
7577 + DAILINK_COMP_ARRAY(COMP_CODEC("wm8741.1-001a", "wm8741")),
7578 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
7579 +
7580 +static struct snd_soc_dai_link digidac1_soundcard_dai[] = {
7581 + {
7582 + .name = "RRA DigiDAC1",
7583 + .stream_name = "RRA DigiDAC1 HiFi",
7584 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
7585 + SND_SOC_DAIFMT_CBM_CFM,
7586 + .ops = &digidac1_soundcard_ops,
7587 + .init = digidac1_soundcard_init,
7588 + SND_SOC_DAILINK_REG(digidac1),
7589 + },
7590 + {
7591 + .name = "RRA DigiDAC11",
7592 + .stream_name = "RRA DigiDAC11 HiFi",
7593 + .dai_fmt = SND_SOC_DAIFMT_I2S
7594 + | SND_SOC_DAIFMT_NB_NF
7595 + | SND_SOC_DAIFMT_CBS_CFS,
7596 + SND_SOC_DAILINK_REG(digidac11),
7597 + },
7598 +};
7599 +
7600 +/* audio machine driver */
7601 +static struct snd_soc_card digidac1_soundcard = {
7602 + .name = "digidac1-soundcard",
7603 + .owner = THIS_MODULE,
7604 + .dai_link = digidac1_soundcard_dai,
7605 + .num_links = ARRAY_SIZE(digidac1_soundcard_dai),
7606 +};
7607 +
7608 +static int digidac1_soundcard_probe(struct platform_device *pdev)
7609 +{
7610 + int ret = 0;
7611 +
7612 + digidac1_soundcard.dev = &pdev->dev;
7613 +
7614 + if (pdev->dev.of_node) {
7615 + struct device_node *i2s_node;
7616 + struct snd_soc_dai_link *dai = &digidac1_soundcard_dai[0];
7617 +
7618 + i2s_node = of_parse_phandle(pdev->dev.of_node,
7619 + "i2s-controller", 0);
7620 +
7621 + if (i2s_node) {
7622 + dai->cpus->dai_name = NULL;
7623 + dai->cpus->of_node = i2s_node;
7624 + dai->platforms->name = NULL;
7625 + dai->platforms->of_node = i2s_node;
7626 + }
7627 + }
7628 +
7629 + ret = devm_snd_soc_register_card(&pdev->dev, &digidac1_soundcard);
7630 + if (ret && ret != -EPROBE_DEFER)
7631 + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
7632 + ret);
7633 +
7634 + return ret;
7635 +}
7636 +
7637 +static const struct of_device_id digidac1_soundcard_of_match[] = {
7638 + { .compatible = "rra,digidac1-soundcard", },
7639 + {},
7640 +};
7641 +MODULE_DEVICE_TABLE(of, digidac1_soundcard_of_match);
7642 +
7643 +static struct platform_driver digidac1_soundcard_driver = {
7644 + .driver = {
7645 + .name = "digidac1-audio",
7646 + .owner = THIS_MODULE,
7647 + .of_match_table = digidac1_soundcard_of_match,
7648 + },
7649 + .probe = digidac1_soundcard_probe,
7650 +};
7651 +
7652 +module_platform_driver(digidac1_soundcard_driver);
7653 +
7654 +MODULE_AUTHOR("José M. Tasende <vintage@redrocksaudio.es>");
7655 +MODULE_DESCRIPTION("ASoC Driver for RRA DigiDAC1");
7656 +MODULE_LICENSE("GPL v2");
7657 --- /dev/null
7658 +++ b/sound/soc/bcm/dionaudio_loco-v2.c
7659 @@ -0,0 +1,117 @@
7660 +/*
7661 + * ASoC Driver for Dion Audio LOCO-V2 DAC-AMP
7662 + *
7663 + * Author: Miquel Blauw <info@dionaudio.nl>
7664 + * Copyright 2017
7665 + *
7666 + * Based on the software of the RPi-DAC writen by Florian Meier
7667 + *
7668 + * This program is free software; you can redistribute it and/or
7669 + * modify it under the terms of the GNU General Public License
7670 + * version 2 as published by the Free Software Foundation.
7671 + *
7672 + * This program is distributed in the hope that it will be useful, but
7673 + * WITHOUT ANY WARRANTY; without even the implied warranty of
7674 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7675 + * General Public License for more details.
7676 + */
7677 +
7678 +#include <linux/module.h>
7679 +#include <linux/platform_device.h>
7680 +
7681 +#include <sound/core.h>
7682 +#include <sound/pcm.h>
7683 +#include <sound/pcm_params.h>
7684 +#include <sound/soc.h>
7685 +#include <sound/jack.h>
7686 +
7687 +static bool digital_gain_0db_limit = true;
7688 +
7689 +static int snd_rpi_dionaudio_loco_v2_init(struct snd_soc_pcm_runtime *rtd)
7690 +{
7691 + if (digital_gain_0db_limit) {
7692 + int ret;
7693 + struct snd_soc_card *card = rtd->card;
7694 +
7695 + ret = snd_soc_limit_volume(card, "Digital Playback Volume", 207);
7696 + if (ret < 0)
7697 + dev_warn(card->dev, "Failed to set volume limit: %d\n", ret);
7698 + }
7699 +
7700 + return 0;
7701 +}
7702 +
7703 +SND_SOC_DAILINK_DEFS(dionaudio_loco_v2,
7704 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
7705 + DAILINK_COMP_ARRAY(COMP_CODEC("pcm512x.1-004d", "pcm512x-hifi")),
7706 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
7707 +
7708 +static struct snd_soc_dai_link snd_rpi_dionaudio_loco_v2_dai[] = {
7709 +{
7710 + .name = "DionAudio LOCO-V2",
7711 + .stream_name = "DionAudio LOCO-V2 DAC-AMP",
7712 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
7713 + SND_SOC_DAIFMT_CBS_CFS,
7714 + .init = snd_rpi_dionaudio_loco_v2_init,
7715 + SND_SOC_DAILINK_REG(dionaudio_loco_v2),
7716 +},};
7717 +
7718 +/* audio machine driver */
7719 +static struct snd_soc_card snd_rpi_dionaudio_loco_v2 = {
7720 + .name = "Dion Audio LOCO-V2",
7721 + .dai_link = snd_rpi_dionaudio_loco_v2_dai,
7722 + .num_links = ARRAY_SIZE(snd_rpi_dionaudio_loco_v2_dai),
7723 +};
7724 +
7725 +static int snd_rpi_dionaudio_loco_v2_probe(struct platform_device *pdev)
7726 +{
7727 + int ret = 0;
7728 +
7729 + snd_rpi_dionaudio_loco_v2.dev = &pdev->dev;
7730 +
7731 + if (pdev->dev.of_node) {
7732 + struct device_node *i2s_node;
7733 + struct snd_soc_dai_link *dai =
7734 + &snd_rpi_dionaudio_loco_v2_dai[0];
7735 +
7736 + i2s_node = of_parse_phandle(pdev->dev.of_node,
7737 + "i2s-controller", 0);
7738 + if (i2s_node) {
7739 + dai->cpus->dai_name = NULL;
7740 + dai->cpus->of_node = i2s_node;
7741 + dai->platforms->name = NULL;
7742 + dai->platforms->of_node = i2s_node;
7743 + }
7744 +
7745 + digital_gain_0db_limit = !of_property_read_bool(
7746 + pdev->dev.of_node, "dionaudio,24db_digital_gain");
7747 + }
7748 +
7749 + ret = devm_snd_soc_register_card(&pdev->dev, &snd_rpi_dionaudio_loco_v2);
7750 + if (ret)
7751 + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
7752 + ret);
7753 +
7754 + return ret;
7755 +}
7756 +
7757 +static const struct of_device_id dionaudio_of_match[] = {
7758 + { .compatible = "dionaudio,dionaudio-loco-v2", },
7759 + {},
7760 +};
7761 +MODULE_DEVICE_TABLE(of, dionaudio_of_match);
7762 +
7763 +static struct platform_driver snd_rpi_dionaudio_loco_v2_driver = {
7764 + .driver = {
7765 + .name = "snd-rpi-dionaudio-loco-v2",
7766 + .owner = THIS_MODULE,
7767 + .of_match_table = dionaudio_of_match,
7768 + },
7769 + .probe = snd_rpi_dionaudio_loco_v2_probe,
7770 +};
7771 +
7772 +module_platform_driver(snd_rpi_dionaudio_loco_v2_driver);
7773 +
7774 +MODULE_AUTHOR("Miquel Blauw <info@dionaudio.nl>");
7775 +MODULE_DESCRIPTION("ASoC Driver for DionAudio LOCO-V2");
7776 +MODULE_LICENSE("GPL v2");
7777 --- /dev/null
7778 +++ b/sound/soc/bcm/dionaudio_loco.c
7779 @@ -0,0 +1,117 @@
7780 +/*
7781 + * ASoC Driver for Dion Audio LOCO DAC-AMP
7782 + *
7783 + * Author: Miquel Blauw <info@dionaudio.nl>
7784 + * Copyright 2016
7785 + *
7786 + * Based on the software of the RPi-DAC writen by Florian Meier
7787 + *
7788 + * This program is free software; you can redistribute it and/or
7789 + * modify it under the terms of the GNU General Public License
7790 + * version 2 as published by the Free Software Foundation.
7791 + *
7792 + * This program is distributed in the hope that it will be useful, but
7793 + * WITHOUT ANY WARRANTY; without even the implied warranty of
7794 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7795 + * General Public License for more details.
7796 + */
7797 +
7798 +#include <linux/module.h>
7799 +#include <linux/platform_device.h>
7800 +
7801 +#include <sound/core.h>
7802 +#include <sound/pcm.h>
7803 +#include <sound/pcm_params.h>
7804 +#include <sound/soc.h>
7805 +#include <sound/jack.h>
7806 +
7807 +static int snd_rpi_dionaudio_loco_hw_params(
7808 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
7809 +{
7810 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
7811 + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
7812 +
7813 + unsigned int sample_bits =
7814 + snd_pcm_format_physical_width(params_format(params));
7815 +
7816 + return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);
7817 +}
7818 +
7819 +/* machine stream operations */
7820 +static struct snd_soc_ops snd_rpi_dionaudio_loco_ops = {
7821 + .hw_params = snd_rpi_dionaudio_loco_hw_params,
7822 +};
7823 +
7824 +SND_SOC_DAILINK_DEFS(dionaudio_loco,
7825 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
7826 + DAILINK_COMP_ARRAY(COMP_CODEC("pcm5102a-codec", "pcm5102a-hifi")),
7827 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
7828 +
7829 +static struct snd_soc_dai_link snd_rpi_dionaudio_loco_dai[] = {
7830 +{
7831 + .name = "DionAudio LOCO",
7832 + .stream_name = "DionAudio LOCO DAC-AMP",
7833 + .dai_fmt = SND_SOC_DAIFMT_I2S |
7834 + SND_SOC_DAIFMT_NB_NF |
7835 + SND_SOC_DAIFMT_CBS_CFS,
7836 + .ops = &snd_rpi_dionaudio_loco_ops,
7837 + SND_SOC_DAILINK_REG(dionaudio_loco),
7838 +},
7839 +};
7840 +
7841 +/* audio machine driver */
7842 +static struct snd_soc_card snd_rpi_dionaudio_loco = {
7843 + .name = "snd_rpi_dionaudio_loco",
7844 + .dai_link = snd_rpi_dionaudio_loco_dai,
7845 + .num_links = ARRAY_SIZE(snd_rpi_dionaudio_loco_dai),
7846 +};
7847 +
7848 +static int snd_rpi_dionaudio_loco_probe(struct platform_device *pdev)
7849 +{
7850 + struct device_node *np;
7851 + int ret = 0;
7852 +
7853 + snd_rpi_dionaudio_loco.dev = &pdev->dev;
7854 +
7855 + np = pdev->dev.of_node;
7856 + if (np) {
7857 + struct snd_soc_dai_link *dai = &snd_rpi_dionaudio_loco_dai[0];
7858 + struct device_node *i2s_np;
7859 +
7860 + i2s_np = of_parse_phandle(np, "i2s-controller", 0);
7861 + if (i2s_np) {
7862 + dai->cpus->dai_name = NULL;
7863 + dai->cpus->of_node = i2s_np;
7864 + dai->platforms->name = NULL;
7865 + dai->platforms->of_node = i2s_np;
7866 + }
7867 + }
7868 +
7869 + ret = devm_snd_soc_register_card(&pdev->dev, &snd_rpi_dionaudio_loco);
7870 + if (ret && ret != -EPROBE_DEFER)
7871 + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
7872 + ret);
7873 +
7874 + return ret;
7875 +}
7876 +
7877 +static const struct of_device_id snd_rpi_dionaudio_loco_of_match[] = {
7878 + { .compatible = "dionaudio,loco-pcm5242-tpa3118", },
7879 + { /* sentinel */ },
7880 +};
7881 +MODULE_DEVICE_TABLE(of, snd_rpi_dionaudio_loco_of_match);
7882 +
7883 +static struct platform_driver snd_rpi_dionaudio_loco_driver = {
7884 + .driver = {
7885 + .name = "snd-dionaudio-loco",
7886 + .owner = THIS_MODULE,
7887 + .of_match_table = snd_rpi_dionaudio_loco_of_match,
7888 + },
7889 + .probe = snd_rpi_dionaudio_loco_probe,
7890 +};
7891 +
7892 +module_platform_driver(snd_rpi_dionaudio_loco_driver);
7893 +
7894 +MODULE_AUTHOR("Miquel Blauw <info@dionaudio.nl>");
7895 +MODULE_DESCRIPTION("ASoC Driver for DionAudio LOCO");
7896 +MODULE_LICENSE("GPL v2");
7897 --- /dev/null
7898 +++ b/sound/soc/bcm/fe-pi-audio.c
7899 @@ -0,0 +1,154 @@
7900 +/*
7901 + * ASoC Driver for Fe-Pi Audio Sound Card
7902 + *
7903 + * Author: Henry Kupis <kuupaz@gmail.com>
7904 + * Copyright 2016
7905 + * based on code by Florian Meier <florian.meier@koalo.de>
7906 + * based on code by Shawn Guo <shawn.guo@linaro.org>
7907 + *
7908 + * This program is free software; you can redistribute it and/or
7909 + * modify it under the terms of the GNU General Public License
7910 + * version 2 as published by the Free Software Foundation.
7911 + *
7912 + * This program is distributed in the hope that it will be useful, but
7913 + * WITHOUT ANY WARRANTY; without even the implied warranty of
7914 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7915 + * General Public License for more details.
7916 + */
7917 +
7918 +#include <linux/module.h>
7919 +#include <linux/platform_device.h>
7920 +#include <linux/io.h>
7921 +
7922 +#include <sound/core.h>
7923 +#include <sound/pcm.h>
7924 +#include <sound/pcm_params.h>
7925 +#include <sound/soc.h>
7926 +#include <sound/jack.h>
7927 +
7928 +#include "../codecs/sgtl5000.h"
7929 +
7930 +static int snd_fe_pi_audio_init(struct snd_soc_pcm_runtime *rtd)
7931 +{
7932 + struct snd_soc_card *card = rtd->card;
7933 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
7934 +
7935 + snd_soc_dapm_force_enable_pin(&card->dapm, "LO");
7936 + snd_soc_dapm_force_enable_pin(&card->dapm, "ADC");
7937 + snd_soc_dapm_force_enable_pin(&card->dapm, "DAC");
7938 + snd_soc_dapm_force_enable_pin(&card->dapm, "HP");
7939 + snd_soc_component_update_bits(component, SGTL5000_CHIP_ANA_POWER,
7940 + SGTL5000_VAG_POWERUP, SGTL5000_VAG_POWERUP);
7941 +
7942 + return 0;
7943 +}
7944 +
7945 +static int snd_fe_pi_audio_hw_params(struct snd_pcm_substream *substream,
7946 + struct snd_pcm_hw_params *params)
7947 +{
7948 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
7949 + struct device *dev = rtd->card->dev;
7950 + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
7951 +
7952 + int ret;
7953 +
7954 + /* Set SGTL5000's SYSCLK */
7955 + ret = snd_soc_dai_set_sysclk(codec_dai, SGTL5000_SYSCLK, 12288000, SND_SOC_CLOCK_IN);
7956 + if (ret) {
7957 + dev_err(dev, "could not set codec driver clock params\n");
7958 + return ret;
7959 + }
7960 +
7961 + return 0;
7962 +}
7963 +
7964 +
7965 +static struct snd_soc_ops snd_fe_pi_audio_ops = {
7966 + .hw_params = snd_fe_pi_audio_hw_params,
7967 +};
7968 +
7969 +SND_SOC_DAILINK_DEFS(fe_pi,
7970 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
7971 + DAILINK_COMP_ARRAY(COMP_CODEC("sgtl5000.1-000a", "sgtl5000")),
7972 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
7973 +
7974 +static struct snd_soc_dai_link snd_fe_pi_audio_dai[] = {
7975 + {
7976 + .name = "FE-PI",
7977 + .stream_name = "Fe-Pi HiFi",
7978 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
7979 + SND_SOC_DAIFMT_CBM_CFM,
7980 + .ops = &snd_fe_pi_audio_ops,
7981 + .init = snd_fe_pi_audio_init,
7982 + SND_SOC_DAILINK_REG(fe_pi),
7983 + },
7984 +};
7985 +
7986 +static const struct snd_soc_dapm_route fe_pi_audio_dapm_routes[] = {
7987 + {"ADC", NULL, "Mic Bias"},
7988 +};
7989 +
7990 +
7991 +static struct snd_soc_card fe_pi_audio = {
7992 + .name = "Fe-Pi Audio",
7993 + .owner = THIS_MODULE,
7994 + .dai_link = snd_fe_pi_audio_dai,
7995 + .num_links = ARRAY_SIZE(snd_fe_pi_audio_dai),
7996 +
7997 + .dapm_routes = fe_pi_audio_dapm_routes,
7998 + .num_dapm_routes = ARRAY_SIZE(fe_pi_audio_dapm_routes),
7999 +};
8000 +
8001 +static int snd_fe_pi_audio_probe(struct platform_device *pdev)
8002 +{
8003 + int ret = 0;
8004 + struct snd_soc_card *card = &fe_pi_audio;
8005 + struct device_node *np = pdev->dev.of_node;
8006 + struct device_node *i2s_node;
8007 + struct snd_soc_dai_link *dai = &snd_fe_pi_audio_dai[0];
8008 +
8009 + fe_pi_audio.dev = &pdev->dev;
8010 +
8011 + i2s_node = of_parse_phandle(np, "i2s-controller", 0);
8012 + if (!i2s_node) {
8013 + dev_err(&pdev->dev, "i2s_node phandle missing or invalid\n");
8014 + return -EINVAL;
8015 + }
8016 +
8017 + dai->cpus->dai_name = NULL;
8018 + dai->cpus->of_node = i2s_node;
8019 + dai->platforms->name = NULL;
8020 + dai->platforms->of_node = i2s_node;
8021 +
8022 + of_node_put(i2s_node);
8023 +
8024 + card->dev = &pdev->dev;
8025 + platform_set_drvdata(pdev, card);
8026 +
8027 + ret = devm_snd_soc_register_card(&pdev->dev, card);
8028 + if (ret && ret != -EPROBE_DEFER)
8029 + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
8030 +
8031 + return ret;
8032 +}
8033 +
8034 +static const struct of_device_id snd_fe_pi_audio_of_match[] = {
8035 + { .compatible = "fe-pi,fe-pi-audio", },
8036 + {},
8037 +};
8038 +MODULE_DEVICE_TABLE(of, snd_fe_pi_audio_of_match);
8039 +
8040 +static struct platform_driver snd_fe_pi_audio_driver = {
8041 + .driver = {
8042 + .name = "snd-fe-pi-audio",
8043 + .owner = THIS_MODULE,
8044 + .of_match_table = snd_fe_pi_audio_of_match,
8045 + },
8046 + .probe = snd_fe_pi_audio_probe,
8047 +};
8048 +
8049 +module_platform_driver(snd_fe_pi_audio_driver);
8050 +
8051 +MODULE_AUTHOR("Henry Kupis <fe-pi@cox.net>");
8052 +MODULE_DESCRIPTION("ASoC Driver for Fe-Pi Audio");
8053 +MODULE_LICENSE("GPL v2");
8054 --- /dev/null
8055 +++ b/sound/soc/bcm/googlevoicehat-codec.c
8056 @@ -0,0 +1,214 @@
8057 +/*
8058 + * Driver for the Google voiceHAT audio codec for Raspberry Pi.
8059 + *
8060 + * Author: Peter Malkin <petermalkin@google.com>
8061 + * Copyright 2016
8062 + *
8063 + * This program is free software; you can redistribute it and/or
8064 + * modify it under the terms of the GNU General Public License
8065 + * version 2 as published by the Free Software Foundation.
8066 + *
8067 + * This program is distributed in the hope that it will be useful, but
8068 + * WITHOUT ANY WARRANTY; without even the implied warranty of
8069 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
8070 + * General Public License for more details.
8071 + */
8072 +
8073 +#include <linux/device.h>
8074 +#include <linux/err.h>
8075 +#include <linux/gpio.h>
8076 +#include <linux/gpio/consumer.h>
8077 +#include <linux/init.h>
8078 +#include <linux/kernel.h>
8079 +#include <linux/mod_devicetable.h>
8080 +#include <linux/module.h>
8081 +#include <linux/of.h>
8082 +#include <linux/platform_device.h>
8083 +#include <linux/version.h>
8084 +#include <sound/pcm.h>
8085 +#include <sound/soc.h>
8086 +#include <sound/soc-dai.h>
8087 +#include <sound/soc-dapm.h>
8088 +
8089 +#define ICS43432_RATE_MIN_HZ 7190 /* from data sheet */
8090 +#define ICS43432_RATE_MAX_HZ 52800 /* from data sheet */
8091 +/* Delay in enabling SDMODE after clock settles to remove pop */
8092 +#define SDMODE_DELAY_MS 5
8093 +
8094 +struct voicehat_priv {
8095 + struct delayed_work enable_sdmode_work;
8096 + struct gpio_desc *sdmode_gpio;
8097 + unsigned long sdmode_delay_jiffies;
8098 +};
8099 +
8100 +static void voicehat_enable_sdmode_work(struct work_struct *work)
8101 +{
8102 + struct voicehat_priv *voicehat = container_of(work,
8103 + struct voicehat_priv,
8104 + enable_sdmode_work.work);
8105 + gpiod_set_value(voicehat->sdmode_gpio, 1);
8106 +}
8107 +
8108 +static int voicehat_component_probe(struct snd_soc_component *component)
8109 +{
8110 + struct voicehat_priv *voicehat =
8111 + snd_soc_component_get_drvdata(component);
8112 +
8113 + voicehat->sdmode_gpio = devm_gpiod_get(component->dev, "sdmode",
8114 + GPIOD_OUT_LOW);
8115 + if (IS_ERR(voicehat->sdmode_gpio)) {
8116 + dev_err(component->dev, "Unable to allocate GPIO pin\n");
8117 + return PTR_ERR(voicehat->sdmode_gpio);
8118 + }
8119 +
8120 + INIT_DELAYED_WORK(&voicehat->enable_sdmode_work,
8121 + voicehat_enable_sdmode_work);
8122 + return 0;
8123 +}
8124 +
8125 +static void voicehat_component_remove(struct snd_soc_component *component)
8126 +{
8127 + struct voicehat_priv *voicehat =
8128 + snd_soc_component_get_drvdata(component);
8129 +
8130 + cancel_delayed_work_sync(&voicehat->enable_sdmode_work);
8131 +}
8132 +
8133 +static const struct snd_soc_dapm_widget voicehat_dapm_widgets[] = {
8134 + SND_SOC_DAPM_OUTPUT("Speaker"),
8135 +};
8136 +
8137 +static const struct snd_soc_dapm_route voicehat_dapm_routes[] = {
8138 + {"Speaker", NULL, "HiFi Playback"},
8139 +};
8140 +
8141 +static const struct snd_soc_component_driver voicehat_component_driver = {
8142 + .probe = voicehat_component_probe,
8143 + .remove = voicehat_component_remove,
8144 + .dapm_widgets = voicehat_dapm_widgets,
8145 + .num_dapm_widgets = ARRAY_SIZE(voicehat_dapm_widgets),
8146 + .dapm_routes = voicehat_dapm_routes,
8147 + .num_dapm_routes = ARRAY_SIZE(voicehat_dapm_routes),
8148 +};
8149 +
8150 +static int voicehat_daiops_trigger(struct snd_pcm_substream *substream, int cmd,
8151 + struct snd_soc_dai *dai)
8152 +{
8153 + struct snd_soc_component *component = dai->component;
8154 + struct voicehat_priv *voicehat =
8155 + snd_soc_component_get_drvdata(component);
8156 +
8157 + if (voicehat->sdmode_delay_jiffies == 0)
8158 + return 0;
8159 +
8160 + dev_dbg(dai->dev, "CMD %d", cmd);
8161 + dev_dbg(dai->dev, "Playback Active %d", dai->stream[SNDRV_PCM_STREAM_PLAYBACK].active);
8162 + dev_dbg(dai->dev, "Capture Active %d", dai->stream[SNDRV_PCM_STREAM_CAPTURE].active);
8163 +
8164 + switch (cmd) {
8165 + case SNDRV_PCM_TRIGGER_START:
8166 + case SNDRV_PCM_TRIGGER_RESUME:
8167 + case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
8168 + if (dai->stream[SNDRV_PCM_STREAM_PLAYBACK].active) {
8169 + dev_info(dai->dev, "Enabling audio amp...\n");
8170 + queue_delayed_work(
8171 + system_power_efficient_wq,
8172 + &voicehat->enable_sdmode_work,
8173 + voicehat->sdmode_delay_jiffies);
8174 + }
8175 + break;
8176 + case SNDRV_PCM_TRIGGER_STOP:
8177 + case SNDRV_PCM_TRIGGER_SUSPEND:
8178 + case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
8179 + if (dai->stream[SNDRV_PCM_STREAM_PLAYBACK].active) {
8180 + cancel_delayed_work(&voicehat->enable_sdmode_work);
8181 + dev_info(dai->dev, "Disabling audio amp...\n");
8182 + gpiod_set_value(voicehat->sdmode_gpio, 0);
8183 + }
8184 + break;
8185 + }
8186 + return 0;
8187 +}
8188 +
8189 +static const struct snd_soc_dai_ops voicehat_dai_ops = {
8190 + .trigger = voicehat_daiops_trigger,
8191 +};
8192 +
8193 +static struct snd_soc_dai_driver voicehat_dai = {
8194 + .name = "voicehat-hifi",
8195 + .capture = {
8196 + .stream_name = "HiFi Capture",
8197 + .channels_min = 2,
8198 + .channels_max = 2,
8199 + .rates = SNDRV_PCM_RATE_48000,
8200 + .formats = SNDRV_PCM_FMTBIT_S32_LE
8201 + },
8202 + .playback = {
8203 + .stream_name = "HiFi Playback",
8204 + .channels_min = 2,
8205 + .channels_max = 2,
8206 + .rates = SNDRV_PCM_RATE_48000,
8207 + .formats = SNDRV_PCM_FMTBIT_S32_LE
8208 + },
8209 + .ops = &voicehat_dai_ops,
8210 + .symmetric_rate = 1
8211 +};
8212 +
8213 +#ifdef CONFIG_OF
8214 +static const struct of_device_id voicehat_ids[] = {
8215 + { .compatible = "google,voicehat", }, {}
8216 + };
8217 + MODULE_DEVICE_TABLE(of, voicehat_ids);
8218 +#endif
8219 +
8220 +static int voicehat_platform_probe(struct platform_device *pdev)
8221 +{
8222 + struct voicehat_priv *voicehat;
8223 + unsigned int sdmode_delay;
8224 + int ret;
8225 +
8226 + voicehat = devm_kzalloc(&pdev->dev, sizeof(*voicehat), GFP_KERNEL);
8227 + if (!voicehat)
8228 + return -ENOMEM;
8229 +
8230 + ret = device_property_read_u32(&pdev->dev, "voicehat_sdmode_delay",
8231 + &sdmode_delay);
8232 +
8233 + if (ret) {
8234 + sdmode_delay = SDMODE_DELAY_MS;
8235 + dev_info(&pdev->dev,
8236 + "property 'voicehat_sdmode_delay' not found default 5 mS");
8237 + } else {
8238 + dev_info(&pdev->dev, "property 'voicehat_sdmode_delay' found delay= %d mS",
8239 + sdmode_delay);
8240 + }
8241 + voicehat->sdmode_delay_jiffies = msecs_to_jiffies(sdmode_delay);
8242 +
8243 + dev_set_drvdata(&pdev->dev, voicehat);
8244 +
8245 + return snd_soc_register_component(&pdev->dev,
8246 + &voicehat_component_driver,
8247 + &voicehat_dai,
8248 + 1);
8249 +}
8250 +
8251 +static int voicehat_platform_remove(struct platform_device *pdev)
8252 +{
8253 + snd_soc_unregister_component(&pdev->dev);
8254 + return 0;
8255 +}
8256 +
8257 +static struct platform_driver voicehat_driver = {
8258 + .driver = {
8259 + .name = "voicehat-codec",
8260 + .of_match_table = of_match_ptr(voicehat_ids),
8261 + },
8262 + .probe = voicehat_platform_probe,
8263 + .remove = voicehat_platform_remove,
8264 +};
8265 +
8266 +module_platform_driver(voicehat_driver);
8267 +
8268 +MODULE_DESCRIPTION("Google voiceHAT Codec driver");
8269 +MODULE_AUTHOR("Peter Malkin <petermalkin@google.com>");
8270 +MODULE_LICENSE("GPL v2");
8271 --- /dev/null
8272 +++ b/sound/soc/bcm/hifiberry_dacplus.c
8273 @@ -0,0 +1,527 @@
8274 +/*
8275 + * ASoC Driver for HiFiBerry DAC+ / DAC Pro / AMP100
8276 + *
8277 + * Author: Daniel Matuschek, Stuart MacLean <stuart@hifiberry.com>
8278 + * Copyright 2014-2015
8279 + * based on code by Florian Meier <florian.meier@koalo.de>
8280 + * Headphone/AMP100 Joerg Schambacher <joerg@hifiberry.com>
8281 + *
8282 + * This program is free software; you can redistribute it and/or
8283 + * modify it under the terms of the GNU General Public License
8284 + * version 2 as published by the Free Software Foundation.
8285 + *
8286 + * This program is distributed in the hope that it will be useful, but
8287 + * WITHOUT ANY WARRANTY; without even the implied warranty of
8288 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
8289 + * General Public License for more details.
8290 + */
8291 +
8292 +#include <linux/module.h>
8293 +#include <linux/gpio/consumer.h>
8294 +#include <../drivers/gpio/gpiolib.h>
8295 +#include <linux/platform_device.h>
8296 +#include <linux/kernel.h>
8297 +#include <linux/clk.h>
8298 +#include <linux/kernel.h>
8299 +#include <linux/module.h>
8300 +#include <linux/of.h>
8301 +#include <linux/slab.h>
8302 +#include <linux/delay.h>
8303 +#include <linux/i2c.h>
8304 +
8305 +#include <sound/core.h>
8306 +#include <sound/pcm.h>
8307 +#include <sound/pcm_params.h>
8308 +#include <sound/soc.h>
8309 +#include <sound/jack.h>
8310 +
8311 +#include "../codecs/pcm512x.h"
8312 +
8313 +#define HIFIBERRY_DACPRO_NOCLOCK 0
8314 +#define HIFIBERRY_DACPRO_CLK44EN 1
8315 +#define HIFIBERRY_DACPRO_CLK48EN 2
8316 +
8317 +struct pcm512x_priv {
8318 + struct regmap *regmap;
8319 + struct clk *sclk;
8320 +};
8321 +
8322 +/* Clock rate of CLK44EN attached to GPIO6 pin */
8323 +#define CLK_44EN_RATE 22579200UL
8324 +/* Clock rate of CLK48EN attached to GPIO3 pin */
8325 +#define CLK_48EN_RATE 24576000UL
8326 +
8327 +static bool slave;
8328 +static bool snd_rpi_hifiberry_is_dacpro;
8329 +static bool digital_gain_0db_limit = true;
8330 +static bool leds_off;
8331 +static bool auto_mute;
8332 +static int mute_ext_ctl;
8333 +static int mute_ext;
8334 +static struct gpio_desc *snd_mute_gpio;
8335 +static struct gpio_desc *snd_reset_gpio;
8336 +static struct snd_soc_card snd_rpi_hifiberry_dacplus;
8337 +
8338 +static int snd_rpi_hifiberry_dacplus_mute_set(int mute)
8339 +{
8340 + gpiod_set_value_cansleep(snd_mute_gpio, mute);
8341 + return 1;
8342 +}
8343 +
8344 +static int snd_rpi_hifiberry_dacplus_mute_get(struct snd_kcontrol *kcontrol,
8345 + struct snd_ctl_elem_value *ucontrol)
8346 +{
8347 + ucontrol->value.integer.value[0] = mute_ext;
8348 +
8349 + return 0;
8350 +}
8351 +
8352 +static int snd_rpi_hifiberry_dacplus_mute_put(struct snd_kcontrol *kcontrol,
8353 + struct snd_ctl_elem_value *ucontrol)
8354 +{
8355 + if (mute_ext == ucontrol->value.integer.value[0])
8356 + return 0;
8357 +
8358 + mute_ext = ucontrol->value.integer.value[0];
8359 +
8360 + return snd_rpi_hifiberry_dacplus_mute_set(mute_ext);
8361 +}
8362 +
8363 +static const char * const mute_text[] = {"Play", "Mute"};
8364 +static const struct soc_enum hb_dacplus_opt_mute_enum =
8365 + SOC_ENUM_SINGLE_EXT(2, mute_text);
8366 +
8367 +static const struct snd_kcontrol_new hb_dacplus_opt_mute_controls[] = {
8368 + SOC_ENUM_EXT("Mute(ext)", hb_dacplus_opt_mute_enum,
8369 + snd_rpi_hifiberry_dacplus_mute_get,
8370 + snd_rpi_hifiberry_dacplus_mute_put),
8371 +};
8372 +
8373 +static void snd_rpi_hifiberry_dacplus_select_clk(struct snd_soc_component *component,
8374 + int clk_id)
8375 +{
8376 + switch (clk_id) {
8377 + case HIFIBERRY_DACPRO_NOCLOCK:
8378 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x24, 0x00);
8379 + break;
8380 + case HIFIBERRY_DACPRO_CLK44EN:
8381 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x24, 0x20);
8382 + break;
8383 + case HIFIBERRY_DACPRO_CLK48EN:
8384 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x24, 0x04);
8385 + break;
8386 + }
8387 + usleep_range(3000, 4000);
8388 +}
8389 +
8390 +static void snd_rpi_hifiberry_dacplus_clk_gpio(struct snd_soc_component *component)
8391 +{
8392 + snd_soc_component_update_bits(component, PCM512x_GPIO_EN, 0x24, 0x24);
8393 + snd_soc_component_update_bits(component, PCM512x_GPIO_OUTPUT_3, 0x0f, 0x02);
8394 + snd_soc_component_update_bits(component, PCM512x_GPIO_OUTPUT_6, 0x0f, 0x02);
8395 +}
8396 +
8397 +static bool snd_rpi_hifiberry_dacplus_is_sclk(struct snd_soc_component *component)
8398 +{
8399 + unsigned int sck;
8400 +
8401 + sck = snd_soc_component_read(component, PCM512x_RATE_DET_4);
8402 + return (!(sck & 0x40));
8403 +}
8404 +
8405 +static bool snd_rpi_hifiberry_dacplus_is_pro_card(struct snd_soc_component *component)
8406 +{
8407 + bool isClk44EN, isClk48En, isNoClk;
8408 +
8409 + snd_rpi_hifiberry_dacplus_clk_gpio(component);
8410 +
8411 + snd_rpi_hifiberry_dacplus_select_clk(component, HIFIBERRY_DACPRO_CLK44EN);
8412 + isClk44EN = snd_rpi_hifiberry_dacplus_is_sclk(component);
8413 +
8414 + snd_rpi_hifiberry_dacplus_select_clk(component, HIFIBERRY_DACPRO_NOCLOCK);
8415 + isNoClk = snd_rpi_hifiberry_dacplus_is_sclk(component);
8416 +
8417 + snd_rpi_hifiberry_dacplus_select_clk(component, HIFIBERRY_DACPRO_CLK48EN);
8418 + isClk48En = snd_rpi_hifiberry_dacplus_is_sclk(component);
8419 +
8420 + return (isClk44EN && isClk48En && !isNoClk);
8421 +}
8422 +
8423 +static int snd_rpi_hifiberry_dacplus_clk_for_rate(int sample_rate)
8424 +{
8425 + int type;
8426 +
8427 + switch (sample_rate) {
8428 + case 11025:
8429 + case 22050:
8430 + case 44100:
8431 + case 88200:
8432 + case 176400:
8433 + case 352800:
8434 + type = HIFIBERRY_DACPRO_CLK44EN;
8435 + break;
8436 + default:
8437 + type = HIFIBERRY_DACPRO_CLK48EN;
8438 + break;
8439 + }
8440 + return type;
8441 +}
8442 +
8443 +static void snd_rpi_hifiberry_dacplus_set_sclk(struct snd_soc_component *component,
8444 + int sample_rate)
8445 +{
8446 + struct pcm512x_priv *pcm512x = snd_soc_component_get_drvdata(component);
8447 +
8448 + if (!IS_ERR(pcm512x->sclk)) {
8449 + int ctype;
8450 +
8451 + ctype = snd_rpi_hifiberry_dacplus_clk_for_rate(sample_rate);
8452 + clk_set_rate(pcm512x->sclk, (ctype == HIFIBERRY_DACPRO_CLK44EN)
8453 + ? CLK_44EN_RATE : CLK_48EN_RATE);
8454 + snd_rpi_hifiberry_dacplus_select_clk(component, ctype);
8455 + }
8456 +}
8457 +
8458 +static int snd_rpi_hifiberry_dacplus_init(struct snd_soc_pcm_runtime *rtd)
8459 +{
8460 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
8461 + struct pcm512x_priv *priv;
8462 + struct snd_soc_card *card = &snd_rpi_hifiberry_dacplus;
8463 +
8464 + if (slave)
8465 + snd_rpi_hifiberry_is_dacpro = false;
8466 + else
8467 + snd_rpi_hifiberry_is_dacpro =
8468 + snd_rpi_hifiberry_dacplus_is_pro_card(component);
8469 +
8470 + if (snd_rpi_hifiberry_is_dacpro) {
8471 + struct snd_soc_dai_link *dai = rtd->dai_link;
8472 +
8473 + dai->name = "HiFiBerry DAC+ Pro";
8474 + dai->stream_name = "HiFiBerry DAC+ Pro HiFi";
8475 + dai->dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
8476 + | SND_SOC_DAIFMT_CBM_CFM;
8477 +
8478 + snd_soc_component_update_bits(component, PCM512x_BCLK_LRCLK_CFG, 0x31, 0x11);
8479 + snd_soc_component_update_bits(component, PCM512x_MASTER_MODE, 0x03, 0x03);
8480 + snd_soc_component_update_bits(component, PCM512x_MASTER_CLKDIV_2, 0x7f, 63);
8481 + } else {
8482 + priv = snd_soc_component_get_drvdata(component);
8483 + priv->sclk = ERR_PTR(-ENOENT);
8484 + }
8485 +
8486 + snd_soc_component_update_bits(component, PCM512x_GPIO_EN, 0x08, 0x08);
8487 + snd_soc_component_update_bits(component, PCM512x_GPIO_OUTPUT_4, 0x0f, 0x02);
8488 + if (leds_off)
8489 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x08, 0x00);
8490 + else
8491 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x08, 0x08);
8492 +
8493 + if (digital_gain_0db_limit) {
8494 + int ret;
8495 + struct snd_soc_card *card = rtd->card;
8496 +
8497 + ret = snd_soc_limit_volume(card, "Digital Playback Volume", 207);
8498 + if (ret < 0)
8499 + dev_warn(card->dev, "Failed to set volume limit: %d\n", ret);
8500 + }
8501 + if (snd_reset_gpio) {
8502 + gpiod_set_value_cansleep(snd_reset_gpio, 0);
8503 + msleep(1);
8504 + gpiod_set_value_cansleep(snd_reset_gpio, 1);
8505 + msleep(1);
8506 + gpiod_set_value_cansleep(snd_reset_gpio, 0);
8507 + }
8508 +
8509 + if (mute_ext_ctl)
8510 + snd_soc_add_card_controls(card, hb_dacplus_opt_mute_controls,
8511 + ARRAY_SIZE(hb_dacplus_opt_mute_controls));
8512 +
8513 + if (snd_mute_gpio)
8514 + gpiod_set_value_cansleep(snd_mute_gpio, mute_ext);
8515 +
8516 + return 0;
8517 +}
8518 +
8519 +static int snd_rpi_hifiberry_dacplus_update_rate_den(
8520 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
8521 +{
8522 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
8523 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
8524 + struct pcm512x_priv *pcm512x = snd_soc_component_get_drvdata(component);
8525 + struct snd_ratnum *rats_no_pll;
8526 + unsigned int num = 0, den = 0;
8527 + int err;
8528 +
8529 + rats_no_pll = devm_kzalloc(rtd->dev, sizeof(*rats_no_pll), GFP_KERNEL);
8530 + if (!rats_no_pll)
8531 + return -ENOMEM;
8532 +
8533 + rats_no_pll->num = clk_get_rate(pcm512x->sclk) / 64;
8534 + rats_no_pll->den_min = 1;
8535 + rats_no_pll->den_max = 128;
8536 + rats_no_pll->den_step = 1;
8537 +
8538 + err = snd_interval_ratnum(hw_param_interval(params,
8539 + SNDRV_PCM_HW_PARAM_RATE), 1, rats_no_pll, &num, &den);
8540 + if (err >= 0 && den) {
8541 + params->rate_num = num;
8542 + params->rate_den = den;
8543 + }
8544 +
8545 + devm_kfree(rtd->dev, rats_no_pll);
8546 + return 0;
8547 +}
8548 +
8549 +static int snd_rpi_hifiberry_dacplus_hw_params(
8550 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
8551 +{
8552 + int ret = 0;
8553 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
8554 + int channels = params_channels(params);
8555 + int width = 32;
8556 +
8557 + if (snd_rpi_hifiberry_is_dacpro) {
8558 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
8559 +
8560 + width = snd_pcm_format_physical_width(params_format(params));
8561 +
8562 + snd_rpi_hifiberry_dacplus_set_sclk(component,
8563 + params_rate(params));
8564 +
8565 + ret = snd_rpi_hifiberry_dacplus_update_rate_den(
8566 + substream, params);
8567 + }
8568 +
8569 + ret = snd_soc_dai_set_bclk_ratio(asoc_rtd_to_cpu(rtd, 0), channels * width);
8570 + if (ret)
8571 + return ret;
8572 + ret = snd_soc_dai_set_bclk_ratio(asoc_rtd_to_codec(rtd, 0), channels * width);
8573 + return ret;
8574 +}
8575 +
8576 +static int snd_rpi_hifiberry_dacplus_startup(
8577 + struct snd_pcm_substream *substream)
8578 +{
8579 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
8580 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
8581 +
8582 + if (auto_mute)
8583 + gpiod_set_value_cansleep(snd_mute_gpio, 0);
8584 + if (leds_off)
8585 + return 0;
8586 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x08, 0x08);
8587 + return 0;
8588 +}
8589 +
8590 +static void snd_rpi_hifiberry_dacplus_shutdown(
8591 + struct snd_pcm_substream *substream)
8592 +{
8593 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
8594 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
8595 +
8596 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x08, 0x00);
8597 + if (auto_mute)
8598 + gpiod_set_value_cansleep(snd_mute_gpio, 1);
8599 +}
8600 +
8601 +/* machine stream operations */
8602 +static struct snd_soc_ops snd_rpi_hifiberry_dacplus_ops = {
8603 + .hw_params = snd_rpi_hifiberry_dacplus_hw_params,
8604 + .startup = snd_rpi_hifiberry_dacplus_startup,
8605 + .shutdown = snd_rpi_hifiberry_dacplus_shutdown,
8606 +};
8607 +
8608 +SND_SOC_DAILINK_DEFS(rpi_hifiberry_dacplus,
8609 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
8610 + DAILINK_COMP_ARRAY(COMP_CODEC("pcm512x.1-004d", "pcm512x-hifi")),
8611 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
8612 +
8613 +static struct snd_soc_dai_link snd_rpi_hifiberry_dacplus_dai[] = {
8614 +{
8615 + .name = "HiFiBerry DAC+",
8616 + .stream_name = "HiFiBerry DAC+ HiFi",
8617 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
8618 + SND_SOC_DAIFMT_CBS_CFS,
8619 + .ops = &snd_rpi_hifiberry_dacplus_ops,
8620 + .init = snd_rpi_hifiberry_dacplus_init,
8621 + SND_SOC_DAILINK_REG(rpi_hifiberry_dacplus),
8622 +},
8623 +};
8624 +
8625 +/* aux device for optional headphone amp */
8626 +static struct snd_soc_aux_dev hifiberry_dacplus_aux_devs[] = {
8627 + {
8628 + .dlc = {
8629 + .name = "tpa6130a2.1-0060",
8630 + },
8631 + },
8632 +};
8633 +
8634 +/* audio machine driver */
8635 +static struct snd_soc_card snd_rpi_hifiberry_dacplus = {
8636 + .name = "snd_rpi_hifiberry_dacplus",
8637 + .driver_name = "HifiberryDacp",
8638 + .owner = THIS_MODULE,
8639 + .dai_link = snd_rpi_hifiberry_dacplus_dai,
8640 + .num_links = ARRAY_SIZE(snd_rpi_hifiberry_dacplus_dai),
8641 +};
8642 +
8643 +static int hb_hp_detect(void)
8644 +{
8645 + struct i2c_adapter *adap = i2c_get_adapter(1);
8646 + int ret;
8647 + struct i2c_client tpa_i2c_client = {
8648 + .addr = 0x60,
8649 + .adapter = adap,
8650 + };
8651 +
8652 + if (!adap)
8653 + return -EPROBE_DEFER; /* I2C module not yet available */
8654 +
8655 + ret = i2c_smbus_read_byte(&tpa_i2c_client) >= 0;
8656 + i2c_put_adapter(adap);
8657 + return ret;
8658 +};
8659 +
8660 +static struct property tpa_enable_prop = {
8661 + .name = "status",
8662 + .length = 4 + 1, /* length 'okay' + 1 */
8663 + .value = "okay",
8664 + };
8665 +
8666 +static int snd_rpi_hifiberry_dacplus_probe(struct platform_device *pdev)
8667 +{
8668 + int ret = 0;
8669 + struct snd_soc_card *card = &snd_rpi_hifiberry_dacplus;
8670 + int len;
8671 + struct device_node *tpa_node;
8672 + struct property *tpa_prop;
8673 + struct of_changeset ocs;
8674 + struct property *pp;
8675 + int tmp;
8676 +
8677 + /* probe for head phone amp */
8678 + ret = hb_hp_detect();
8679 + if (ret < 0)
8680 + return ret;
8681 + if (ret) {
8682 + card->aux_dev = hifiberry_dacplus_aux_devs;
8683 + card->num_aux_devs =
8684 + ARRAY_SIZE(hifiberry_dacplus_aux_devs);
8685 + tpa_node = of_find_compatible_node(NULL, NULL, "ti,tpa6130a2");
8686 + tpa_prop = of_find_property(tpa_node, "status", &len);
8687 +
8688 + if (strcmp((char *)tpa_prop->value, "okay")) {
8689 + /* and activate headphone using change_sets */
8690 + dev_info(&pdev->dev, "activating headphone amplifier");
8691 + of_changeset_init(&ocs);
8692 + ret = of_changeset_update_property(&ocs, tpa_node,
8693 + &tpa_enable_prop);
8694 + if (ret) {
8695 + dev_err(&pdev->dev,
8696 + "cannot activate headphone amplifier\n");
8697 + return -ENODEV;
8698 + }
8699 + ret = of_changeset_apply(&ocs);
8700 + if (ret) {
8701 + dev_err(&pdev->dev,
8702 + "cannot activate headphone amplifier\n");
8703 + return -ENODEV;
8704 + }
8705 + }
8706 + }
8707 +
8708 + snd_rpi_hifiberry_dacplus.dev = &pdev->dev;
8709 + if (pdev->dev.of_node) {
8710 + struct device_node *i2s_node;
8711 + struct snd_soc_dai_link *dai;
8712 +
8713 + dai = &snd_rpi_hifiberry_dacplus_dai[0];
8714 + i2s_node = of_parse_phandle(pdev->dev.of_node,
8715 + "i2s-controller", 0);
8716 +
8717 + if (i2s_node) {
8718 + dai->cpus->dai_name = NULL;
8719 + dai->cpus->of_node = i2s_node;
8720 + dai->platforms->name = NULL;
8721 + dai->platforms->of_node = i2s_node;
8722 + }
8723 +
8724 + digital_gain_0db_limit = !of_property_read_bool(
8725 + pdev->dev.of_node, "hifiberry,24db_digital_gain");
8726 + slave = of_property_read_bool(pdev->dev.of_node,
8727 + "hifiberry-dacplus,slave");
8728 + leds_off = of_property_read_bool(pdev->dev.of_node,
8729 + "hifiberry-dacplus,leds_off");
8730 + auto_mute = of_property_read_bool(pdev->dev.of_node,
8731 + "hifiberry-dacplus,auto_mute");
8732 +
8733 + /*
8734 + * check for HW MUTE as defined in DT-overlay
8735 + * active high, therefore default to HIGH to MUTE
8736 + */
8737 + snd_mute_gpio = devm_gpiod_get_optional(&pdev->dev,
8738 + "mute", GPIOD_OUT_HIGH);
8739 + if (IS_ERR(snd_mute_gpio)) {
8740 + dev_err(&pdev->dev, "Can't allocate GPIO (HW-MUTE)");
8741 + return PTR_ERR(snd_mute_gpio);
8742 + }
8743 +
8744 + /* add ALSA control if requested in DT-overlay (AMP100) */
8745 + pp = of_find_property(pdev->dev.of_node,
8746 + "hifiberry-dacplus,mute_ext_ctl", &tmp);
8747 + if (pp) {
8748 + if (!of_property_read_u32(pdev->dev.of_node,
8749 + "hifiberry-dacplus,mute_ext_ctl", &mute_ext)) {
8750 + /* ALSA control will be used */
8751 + mute_ext_ctl = 1;
8752 + }
8753 + }
8754 +
8755 + /* check for HW RESET (AMP100) */
8756 + snd_reset_gpio = devm_gpiod_get_optional(&pdev->dev,
8757 + "reset", GPIOD_OUT_HIGH);
8758 + if (IS_ERR(snd_reset_gpio)) {
8759 + dev_err(&pdev->dev, "Can't allocate GPIO (HW-RESET)");
8760 + return PTR_ERR(snd_reset_gpio);
8761 + }
8762 +
8763 + }
8764 +
8765 + ret = devm_snd_soc_register_card(&pdev->dev,
8766 + &snd_rpi_hifiberry_dacplus);
8767 + if (ret && ret != -EPROBE_DEFER)
8768 + dev_err(&pdev->dev,
8769 + "snd_soc_register_card() failed: %d\n", ret);
8770 + if (!ret) {
8771 + if (snd_mute_gpio)
8772 + dev_info(&pdev->dev, "GPIO%i for HW-MUTE selected",
8773 + gpio_chip_hwgpio(snd_mute_gpio));
8774 + if (snd_reset_gpio)
8775 + dev_info(&pdev->dev, "GPIO%i for HW-RESET selected",
8776 + gpio_chip_hwgpio(snd_reset_gpio));
8777 + }
8778 + return ret;
8779 +}
8780 +
8781 +static const struct of_device_id snd_rpi_hifiberry_dacplus_of_match[] = {
8782 + { .compatible = "hifiberry,hifiberry-dacplus", },
8783 + {},
8784 +};
8785 +MODULE_DEVICE_TABLE(of, snd_rpi_hifiberry_dacplus_of_match);
8786 +
8787 +static struct platform_driver snd_rpi_hifiberry_dacplus_driver = {
8788 + .driver = {
8789 + .name = "snd-rpi-hifiberry-dacplus",
8790 + .owner = THIS_MODULE,
8791 + .of_match_table = snd_rpi_hifiberry_dacplus_of_match,
8792 + },
8793 + .probe = snd_rpi_hifiberry_dacplus_probe,
8794 +};
8795 +
8796 +module_platform_driver(snd_rpi_hifiberry_dacplus_driver);
8797 +
8798 +MODULE_AUTHOR("Daniel Matuschek <daniel@hifiberry.com>");
8799 +MODULE_DESCRIPTION("ASoC Driver for HiFiBerry DAC+");
8800 +MODULE_LICENSE("GPL v2");
8801 --- /dev/null
8802 +++ b/sound/soc/bcm/hifiberry_dacplusadc.c
8803 @@ -0,0 +1,398 @@
8804 +/*
8805 + * ASoC Driver for HiFiBerry DAC+ / DAC Pro with ADC
8806 + *
8807 + * Author: Daniel Matuschek, Stuart MacLean <stuart@hifiberry.com>
8808 + * Copyright 2014-2015
8809 + * based on code by Florian Meier <florian.meier@koalo.de>
8810 + * ADC added by Joerg Schambacher <joscha@schambacher.com>
8811 + * Copyright 2018
8812 + *
8813 + * This program is free software; you can redistribute it and/or
8814 + * modify it under the terms of the GNU General Public License
8815 + * version 2 as published by the Free Software Foundation.
8816 + *
8817 + * This program is distributed in the hope that it will be useful, but
8818 + * WITHOUT ANY WARRANTY; without even the implied warranty of
8819 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
8820 + * General Public License for more details.
8821 + */
8822 +
8823 +#include <linux/module.h>
8824 +#include <linux/platform_device.h>
8825 +#include <linux/kernel.h>
8826 +#include <linux/clk.h>
8827 +#include <linux/kernel.h>
8828 +#include <linux/module.h>
8829 +#include <linux/of.h>
8830 +#include <linux/slab.h>
8831 +#include <linux/delay.h>
8832 +
8833 +#include <sound/core.h>
8834 +#include <sound/pcm.h>
8835 +#include <sound/pcm_params.h>
8836 +#include <sound/soc.h>
8837 +#include <sound/jack.h>
8838 +
8839 +#include "../codecs/pcm512x.h"
8840 +
8841 +#define HIFIBERRY_DACPRO_NOCLOCK 0
8842 +#define HIFIBERRY_DACPRO_CLK44EN 1
8843 +#define HIFIBERRY_DACPRO_CLK48EN 2
8844 +
8845 +struct platform_device *dmic_codec_dev;
8846 +
8847 +struct pcm512x_priv {
8848 + struct regmap *regmap;
8849 + struct clk *sclk;
8850 +};
8851 +
8852 +/* Clock rate of CLK44EN attached to GPIO6 pin */
8853 +#define CLK_44EN_RATE 22579200UL
8854 +/* Clock rate of CLK48EN attached to GPIO3 pin */
8855 +#define CLK_48EN_RATE 24576000UL
8856 +
8857 +static bool slave;
8858 +static bool snd_rpi_hifiberry_is_dacpro;
8859 +static bool digital_gain_0db_limit = true;
8860 +static bool leds_off;
8861 +
8862 +static void snd_rpi_hifiberry_dacplusadc_select_clk(struct snd_soc_component *component,
8863 + int clk_id)
8864 +{
8865 + switch (clk_id) {
8866 + case HIFIBERRY_DACPRO_NOCLOCK:
8867 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x24, 0x00);
8868 + break;
8869 + case HIFIBERRY_DACPRO_CLK44EN:
8870 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x24, 0x20);
8871 + break;
8872 + case HIFIBERRY_DACPRO_CLK48EN:
8873 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x24, 0x04);
8874 + break;
8875 + }
8876 +}
8877 +
8878 +static void snd_rpi_hifiberry_dacplusadc_clk_gpio(struct snd_soc_component *component)
8879 +{
8880 + snd_soc_component_update_bits(component, PCM512x_GPIO_EN, 0x24, 0x24);
8881 + snd_soc_component_update_bits(component, PCM512x_GPIO_OUTPUT_3, 0x0f, 0x02);
8882 + snd_soc_component_update_bits(component, PCM512x_GPIO_OUTPUT_6, 0x0f, 0x02);
8883 +}
8884 +
8885 +static bool snd_rpi_hifiberry_dacplusadc_is_sclk(struct snd_soc_component *component)
8886 +{
8887 + unsigned int sck;
8888 +
8889 + sck = snd_soc_component_read(component, PCM512x_RATE_DET_4);
8890 + return (!(sck & 0x40));
8891 +}
8892 +
8893 +static bool snd_rpi_hifiberry_dacplusadc_is_sclk_sleep(
8894 + struct snd_soc_component *component)
8895 +{
8896 + msleep(2);
8897 + return snd_rpi_hifiberry_dacplusadc_is_sclk(component);
8898 +}
8899 +
8900 +static bool snd_rpi_hifiberry_dacplusadc_is_pro_card(struct snd_soc_component *component)
8901 +{
8902 + bool isClk44EN, isClk48En, isNoClk;
8903 +
8904 + snd_rpi_hifiberry_dacplusadc_clk_gpio(component);
8905 +
8906 + snd_rpi_hifiberry_dacplusadc_select_clk(component, HIFIBERRY_DACPRO_CLK44EN);
8907 + isClk44EN = snd_rpi_hifiberry_dacplusadc_is_sclk_sleep(component);
8908 +
8909 + snd_rpi_hifiberry_dacplusadc_select_clk(component, HIFIBERRY_DACPRO_NOCLOCK);
8910 + isNoClk = snd_rpi_hifiberry_dacplusadc_is_sclk_sleep(component);
8911 +
8912 + snd_rpi_hifiberry_dacplusadc_select_clk(component, HIFIBERRY_DACPRO_CLK48EN);
8913 + isClk48En = snd_rpi_hifiberry_dacplusadc_is_sclk_sleep(component);
8914 +
8915 + return (isClk44EN && isClk48En && !isNoClk);
8916 +}
8917 +
8918 +static int snd_rpi_hifiberry_dacplusadc_clk_for_rate(int sample_rate)
8919 +{
8920 + int type;
8921 +
8922 + switch (sample_rate) {
8923 + case 11025:
8924 + case 22050:
8925 + case 44100:
8926 + case 88200:
8927 + case 176400:
8928 + case 352800:
8929 + type = HIFIBERRY_DACPRO_CLK44EN;
8930 + break;
8931 + default:
8932 + type = HIFIBERRY_DACPRO_CLK48EN;
8933 + break;
8934 + }
8935 + return type;
8936 +}
8937 +
8938 +static void snd_rpi_hifiberry_dacplusadc_set_sclk(struct snd_soc_component *component,
8939 + int sample_rate)
8940 +{
8941 + struct pcm512x_priv *pcm512x = snd_soc_component_get_drvdata(component);
8942 +
8943 + if (!IS_ERR(pcm512x->sclk)) {
8944 + int ctype;
8945 +
8946 + ctype = snd_rpi_hifiberry_dacplusadc_clk_for_rate(sample_rate);
8947 + clk_set_rate(pcm512x->sclk, (ctype == HIFIBERRY_DACPRO_CLK44EN)
8948 + ? CLK_44EN_RATE : CLK_48EN_RATE);
8949 + snd_rpi_hifiberry_dacplusadc_select_clk(component, ctype);
8950 + }
8951 +}
8952 +
8953 +static int snd_rpi_hifiberry_dacplusadc_init(struct snd_soc_pcm_runtime *rtd)
8954 +{
8955 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
8956 + struct pcm512x_priv *priv;
8957 +
8958 + if (slave)
8959 + snd_rpi_hifiberry_is_dacpro = false;
8960 + else
8961 + snd_rpi_hifiberry_is_dacpro =
8962 + snd_rpi_hifiberry_dacplusadc_is_pro_card(component);
8963 +
8964 + if (snd_rpi_hifiberry_is_dacpro) {
8965 + struct snd_soc_dai_link *dai = rtd->dai_link;
8966 +
8967 + dai->name = "HiFiBerry ADCDAC+ Pro";
8968 + dai->stream_name = "HiFiBerry ADCDAC+ Pro HiFi";
8969 + dai->dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
8970 + | SND_SOC_DAIFMT_CBM_CFM;
8971 +
8972 + snd_soc_component_update_bits(component, PCM512x_BCLK_LRCLK_CFG, 0x31, 0x11);
8973 + snd_soc_component_update_bits(component, PCM512x_MASTER_MODE, 0x03, 0x03);
8974 + snd_soc_component_update_bits(component, PCM512x_MASTER_CLKDIV_2, 0x7f, 63);
8975 + } else {
8976 + priv = snd_soc_component_get_drvdata(component);
8977 + priv->sclk = ERR_PTR(-ENOENT);
8978 + }
8979 +
8980 + snd_soc_component_update_bits(component, PCM512x_GPIO_EN, 0x08, 0x08);
8981 + snd_soc_component_update_bits(component, PCM512x_GPIO_OUTPUT_4, 0x0f, 0x02);
8982 + if (leds_off)
8983 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x08, 0x00);
8984 + else
8985 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x08, 0x08);
8986 +
8987 + if (digital_gain_0db_limit) {
8988 + int ret;
8989 + struct snd_soc_card *card = rtd->card;
8990 +
8991 + ret = snd_soc_limit_volume(card, "Digital Playback Volume", 207);
8992 + if (ret < 0)
8993 + dev_warn(card->dev, "Failed to set volume limit: %d\n", ret);
8994 + }
8995 +
8996 + return 0;
8997 +}
8998 +
8999 +static int snd_rpi_hifiberry_dacplusadc_update_rate_den(
9000 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
9001 +{
9002 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
9003 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
9004 + struct pcm512x_priv *pcm512x = snd_soc_component_get_drvdata(component);
9005 + struct snd_ratnum *rats_no_pll;
9006 + unsigned int num = 0, den = 0;
9007 + int err;
9008 +
9009 + rats_no_pll = devm_kzalloc(rtd->dev, sizeof(*rats_no_pll), GFP_KERNEL);
9010 + if (!rats_no_pll)
9011 + return -ENOMEM;
9012 +
9013 + rats_no_pll->num = clk_get_rate(pcm512x->sclk) / 64;
9014 + rats_no_pll->den_min = 1;
9015 + rats_no_pll->den_max = 128;
9016 + rats_no_pll->den_step = 1;
9017 +
9018 + err = snd_interval_ratnum(hw_param_interval(params,
9019 + SNDRV_PCM_HW_PARAM_RATE), 1, rats_no_pll, &num, &den);
9020 + if (err >= 0 && den) {
9021 + params->rate_num = num;
9022 + params->rate_den = den;
9023 + }
9024 +
9025 + devm_kfree(rtd->dev, rats_no_pll);
9026 + return 0;
9027 +}
9028 +
9029 +static int snd_rpi_hifiberry_dacplusadc_hw_params(
9030 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
9031 +{
9032 + int ret = 0;
9033 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
9034 + int channels = params_channels(params);
9035 + int width = 32;
9036 +
9037 + if (snd_rpi_hifiberry_is_dacpro) {
9038 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
9039 +
9040 + width = snd_pcm_format_physical_width(params_format(params));
9041 +
9042 + snd_rpi_hifiberry_dacplusadc_set_sclk(component,
9043 + params_rate(params));
9044 +
9045 + ret = snd_rpi_hifiberry_dacplusadc_update_rate_den(
9046 + substream, params);
9047 + }
9048 +
9049 + ret = snd_soc_dai_set_bclk_ratio(asoc_rtd_to_cpu(rtd, 0), channels * width);
9050 + if (ret)
9051 + return ret;
9052 + ret = snd_soc_dai_set_bclk_ratio(asoc_rtd_to_codec(rtd, 0), channels * width);
9053 + return ret;
9054 +}
9055 +
9056 +static int hifiberry_dacplusadc_LED_cnt;
9057 +
9058 +static int snd_rpi_hifiberry_dacplusadc_startup(
9059 + struct snd_pcm_substream *substream)
9060 +{
9061 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
9062 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
9063 +
9064 + if (leds_off)
9065 + return 0;
9066 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1,
9067 + 0x08, 0x08);
9068 + hifiberry_dacplusadc_LED_cnt++;
9069 + return 0;
9070 +}
9071 +
9072 +static void snd_rpi_hifiberry_dacplusadc_shutdown(
9073 + struct snd_pcm_substream *substream)
9074 +{
9075 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
9076 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
9077 +
9078 + hifiberry_dacplusadc_LED_cnt--;
9079 + if (!hifiberry_dacplusadc_LED_cnt)
9080 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1,
9081 + 0x08, 0x00);
9082 +}
9083 +
9084 +/* machine stream operations */
9085 +static struct snd_soc_ops snd_rpi_hifiberry_dacplusadc_ops = {
9086 + .hw_params = snd_rpi_hifiberry_dacplusadc_hw_params,
9087 + .startup = snd_rpi_hifiberry_dacplusadc_startup,
9088 + .shutdown = snd_rpi_hifiberry_dacplusadc_shutdown,
9089 +};
9090 +
9091 +SND_SOC_DAILINK_DEFS(hifi,
9092 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
9093 + DAILINK_COMP_ARRAY(COMP_CODEC("pcm512x.1-004d", "pcm512x-hifi"),
9094 + COMP_CODEC("dmic-codec", "dmic-hifi")),
9095 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
9096 +
9097 +static struct snd_soc_dai_link snd_rpi_hifiberry_dacplusadc_dai[] = {
9098 +{
9099 + .name = "HiFiBerry DAC+ADC",
9100 + .stream_name = "HiFiBerry DAC+ADC HiFi",
9101 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
9102 + SND_SOC_DAIFMT_CBS_CFS,
9103 + .ops = &snd_rpi_hifiberry_dacplusadc_ops,
9104 + .init = snd_rpi_hifiberry_dacplusadc_init,
9105 + SND_SOC_DAILINK_REG(hifi),
9106 +},
9107 +};
9108 +
9109 +/* audio machine driver */
9110 +static struct snd_soc_card snd_rpi_hifiberry_dacplusadc = {
9111 + .name = "snd_rpi_hifiberry_dacplusadc",
9112 + .driver_name = "HifiberryDacpAdc",
9113 + .owner = THIS_MODULE,
9114 + .dai_link = snd_rpi_hifiberry_dacplusadc_dai,
9115 + .num_links = ARRAY_SIZE(snd_rpi_hifiberry_dacplusadc_dai),
9116 +};
9117 +
9118 +
9119 +static int snd_rpi_hifiberry_dacplusadc_probe(struct platform_device *pdev)
9120 +{
9121 + int ret = 0;
9122 +
9123 + snd_rpi_hifiberry_dacplusadc.dev = &pdev->dev;
9124 + if (pdev->dev.of_node) {
9125 + struct device_node *i2s_node;
9126 + struct snd_soc_dai_link *dai;
9127 +
9128 + dai = &snd_rpi_hifiberry_dacplusadc_dai[0];
9129 + i2s_node = of_parse_phandle(pdev->dev.of_node,
9130 + "i2s-controller", 0);
9131 + if (i2s_node) {
9132 + dai->cpus->of_node = i2s_node;
9133 + dai->platforms->of_node = i2s_node;
9134 + dai->cpus->dai_name = NULL;
9135 + dai->platforms->name = NULL;
9136 + }
9137 + }
9138 + digital_gain_0db_limit = !of_property_read_bool(
9139 + pdev->dev.of_node, "hifiberry,24db_digital_gain");
9140 + slave = of_property_read_bool(pdev->dev.of_node,
9141 + "hifiberry-dacplusadc,slave");
9142 + leds_off = of_property_read_bool(pdev->dev.of_node,
9143 + "hifiberry-dacplusadc,leds_off");
9144 +
9145 + ret = devm_snd_soc_register_card(&pdev->dev,
9146 + &snd_rpi_hifiberry_dacplusadc);
9147 + if (ret && ret != -EPROBE_DEFER)
9148 + dev_err(&pdev->dev,
9149 + "snd_soc_register_card() failed: %d\n", ret);
9150 +
9151 + return ret;
9152 +}
9153 +
9154 +static const struct of_device_id snd_rpi_hifiberry_dacplusadc_of_match[] = {
9155 + { .compatible = "hifiberry,hifiberry-dacplusadc", },
9156 + {},
9157 +};
9158 +
9159 +MODULE_DEVICE_TABLE(of, snd_rpi_hifiberry_dacplusadc_of_match);
9160 +
9161 +static struct platform_driver snd_rpi_hifiberry_dacplusadc_driver = {
9162 + .driver = {
9163 + .name = "snd-rpi-hifiberry-dacplusadc",
9164 + .owner = THIS_MODULE,
9165 + .of_match_table = snd_rpi_hifiberry_dacplusadc_of_match,
9166 + },
9167 + .probe = snd_rpi_hifiberry_dacplusadc_probe,
9168 +};
9169 +
9170 +static int __init hifiberry_dacplusadc_init(void)
9171 +{
9172 + int ret;
9173 +
9174 + dmic_codec_dev = platform_device_register_simple("dmic-codec", -1, NULL,
9175 + 0);
9176 + if (IS_ERR(dmic_codec_dev)) {
9177 + pr_err("%s: dmic-codec device registration failed\n", __func__);
9178 + return PTR_ERR(dmic_codec_dev);
9179 + }
9180 +
9181 + ret = platform_driver_register(&snd_rpi_hifiberry_dacplusadc_driver);
9182 + if (ret) {
9183 + pr_err("%s: platform driver registration failed\n", __func__);
9184 + platform_device_unregister(dmic_codec_dev);
9185 + }
9186 +
9187 + return ret;
9188 +}
9189 +module_init(hifiberry_dacplusadc_init);
9190 +
9191 +static void __exit hifiberry_dacplusadc_exit(void)
9192 +{
9193 + platform_driver_unregister(&snd_rpi_hifiberry_dacplusadc_driver);
9194 + platform_device_unregister(dmic_codec_dev);
9195 +}
9196 +module_exit(hifiberry_dacplusadc_exit);
9197 +
9198 +MODULE_AUTHOR("Joerg Schambacher <joscha@schambacher.com>");
9199 +MODULE_AUTHOR("Daniel Matuschek <daniel@hifiberry.com>");
9200 +MODULE_DESCRIPTION("ASoC Driver for HiFiBerry DAC+ADC");
9201 +MODULE_LICENSE("GPL v2");
9202 --- /dev/null
9203 +++ b/sound/soc/bcm/hifiberry_dacplusadcpro.c
9204 @@ -0,0 +1,605 @@
9205 +/*
9206 + * ASoC Driver for HiFiBerry DAC+ / DAC Pro with ADC PRO Version (SW control)
9207 + *
9208 + * Author: Daniel Matuschek, Stuart MacLean <stuart@hifiberry.com>
9209 + * Copyright 2014-2015
9210 + * based on code by Florian Meier <florian.meier@koalo.de>
9211 + * ADC, HP added by Joerg Schambacher <joerg@hifiberry.com>
9212 + * Copyright 2018-21
9213 + *
9214 + * This program is free software; you can redistribute it and/or
9215 + * modify it under the terms of the GNU General Public License
9216 + * version 2 as published by the Free Software Foundation.
9217 + *
9218 + * This program is distributed in the hope that it will be useful, but
9219 + * WITHOUT ANY WARRANTY; without even the implied warranty of
9220 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9221 + * General Public License for more details.
9222 + */
9223 +
9224 +#include <linux/module.h>
9225 +#include <linux/platform_device.h>
9226 +#include <linux/kernel.h>
9227 +#include <linux/clk.h>
9228 +#include <linux/kernel.h>
9229 +#include <linux/module.h>
9230 +#include <linux/of.h>
9231 +#include <linux/slab.h>
9232 +#include <linux/delay.h>
9233 +#include <linux/i2c.h>
9234 +
9235 +#include <sound/core.h>
9236 +#include <sound/pcm.h>
9237 +#include <sound/pcm_params.h>
9238 +#include <sound/soc.h>
9239 +#include <sound/jack.h>
9240 +#include <sound/tlv.h>
9241 +
9242 +#include "../codecs/pcm512x.h"
9243 +#include "../codecs/pcm186x.h"
9244 +
9245 +#define HIFIBERRY_DACPRO_NOCLOCK 0
9246 +#define HIFIBERRY_DACPRO_CLK44EN 1
9247 +#define HIFIBERRY_DACPRO_CLK48EN 2
9248 +
9249 +struct pcm512x_priv {
9250 + struct regmap *regmap;
9251 + struct clk *sclk;
9252 +};
9253 +
9254 +/* Clock rate of CLK44EN attached to GPIO6 pin */
9255 +#define CLK_44EN_RATE 22579200UL
9256 +/* Clock rate of CLK48EN attached to GPIO3 pin */
9257 +#define CLK_48EN_RATE 24576000UL
9258 +
9259 +static bool slave;
9260 +static bool snd_rpi_hifiberry_is_dacpro;
9261 +static bool digital_gain_0db_limit = true;
9262 +static bool leds_off;
9263 +
9264 +static const unsigned int pcm186x_adc_input_channel_sel_value[] = {
9265 + 0x00, 0x01, 0x02, 0x03, 0x10
9266 +};
9267 +
9268 +static const char * const pcm186x_adcl_input_channel_sel_text[] = {
9269 + "No Select",
9270 + "VINL1[SE]", /* Default for ADCL */
9271 + "VINL2[SE]",
9272 + "VINL2[SE] + VINL1[SE]",
9273 + "{VIN1P, VIN1M}[DIFF]"
9274 +};
9275 +
9276 +static const char * const pcm186x_adcr_input_channel_sel_text[] = {
9277 + "No Select",
9278 + "VINR1[SE]", /* Default for ADCR */
9279 + "VINR2[SE]",
9280 + "VINR2[SE] + VINR1[SE]",
9281 + "{VIN2P, VIN2M}[DIFF]"
9282 +};
9283 +
9284 +static const struct soc_enum pcm186x_adc_input_channel_sel[] = {
9285 + SOC_VALUE_ENUM_SINGLE(PCM186X_ADC1_INPUT_SEL_L, 0,
9286 + PCM186X_ADC_INPUT_SEL_MASK,
9287 + ARRAY_SIZE(pcm186x_adcl_input_channel_sel_text),
9288 + pcm186x_adcl_input_channel_sel_text,
9289 + pcm186x_adc_input_channel_sel_value),
9290 + SOC_VALUE_ENUM_SINGLE(PCM186X_ADC1_INPUT_SEL_R, 0,
9291 + PCM186X_ADC_INPUT_SEL_MASK,
9292 + ARRAY_SIZE(pcm186x_adcr_input_channel_sel_text),
9293 + pcm186x_adcr_input_channel_sel_text,
9294 + pcm186x_adc_input_channel_sel_value),
9295 +};
9296 +
9297 +static const unsigned int pcm186x_mic_bias_sel_value[] = {
9298 + 0x00, 0x01, 0x11
9299 +};
9300 +
9301 +static const char * const pcm186x_mic_bias_sel_text[] = {
9302 + "Mic Bias off",
9303 + "Mic Bias on",
9304 + "Mic Bias with Bypass Resistor"
9305 +};
9306 +
9307 +static const struct soc_enum pcm186x_mic_bias_sel[] = {
9308 + SOC_VALUE_ENUM_SINGLE(PCM186X_MIC_BIAS_CTRL, 0,
9309 + GENMASK(4, 0),
9310 + ARRAY_SIZE(pcm186x_mic_bias_sel_text),
9311 + pcm186x_mic_bias_sel_text,
9312 + pcm186x_mic_bias_sel_value),
9313 +};
9314 +
9315 +static const unsigned int pcm186x_gain_sel_value[] = {
9316 + 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
9317 + 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
9318 + 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
9319 + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
9320 + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
9321 + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
9322 + 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
9323 + 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
9324 + 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
9325 + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
9326 + 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
9327 + 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
9328 + 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
9329 + 0x50
9330 +};
9331 +
9332 +static const char * const pcm186x_gain_sel_text[] = {
9333 + "-12.0dB", "-11.5dB", "-11.0dB", "-10.5dB", "-10.0dB", "-9.5dB",
9334 + "-9.0dB", "-8.5dB", "-8.0dB", "-7.5dB", "-7.0dB", "-6.5dB",
9335 + "-6.0dB", "-5.5dB", "-5.0dB", "-4.5dB", "-4.0dB", "-3.5dB",
9336 + "-3.0dB", "-2.5dB", "-2.0dB", "-1.5dB", "-1.0dB", "-0.5dB",
9337 + "0.0dB", "0.5dB", "1.0dB", "1.5dB", "2.0dB", "2.5dB",
9338 + "3.0dB", "3.5dB", "4.0dB", "4.5dB", "5.0dB", "5.5dB",
9339 + "6.0dB", "6.5dB", "7.0dB", "7.5dB", "8.0dB", "8.5dB",
9340 + "9.0dB", "9.5dB", "10.0dB", "10.5dB", "11.0dB", "11.5dB",
9341 + "12.0dB", "12.5dB", "13.0dB", "13.5dB", "14.0dB", "14.5dB",
9342 + "15.0dB", "15.5dB", "16.0dB", "16.5dB", "17.0dB", "17.5dB",
9343 + "18.0dB", "18.5dB", "19.0dB", "19.5dB", "20.0dB", "20.5dB",
9344 + "21.0dB", "21.5dB", "22.0dB", "22.5dB", "23.0dB", "23.5dB",
9345 + "24.0dB", "24.5dB", "25.0dB", "25.5dB", "26.0dB", "26.5dB",
9346 + "27.0dB", "27.5dB", "28.0dB", "28.5dB", "29.0dB", "29.5dB",
9347 + "30.0dB", "30.5dB", "31.0dB", "31.5dB", "32.0dB", "32.5dB",
9348 + "33.0dB", "33.5dB", "34.0dB", "34.5dB", "35.0dB", "35.5dB",
9349 + "36.0dB", "36.5dB", "37.0dB", "37.5dB", "38.0dB", "38.5dB",
9350 + "39.0dB", "39.5dB", "40.0dB"};
9351 +
9352 +static const struct soc_enum pcm186x_gain_sel[] = {
9353 + SOC_VALUE_ENUM_SINGLE(PCM186X_PGA_VAL_CH1_L, 0,
9354 + 0xff,
9355 + ARRAY_SIZE(pcm186x_gain_sel_text),
9356 + pcm186x_gain_sel_text,
9357 + pcm186x_gain_sel_value),
9358 + SOC_VALUE_ENUM_SINGLE(PCM186X_PGA_VAL_CH1_R, 0,
9359 + 0xff,
9360 + ARRAY_SIZE(pcm186x_gain_sel_text),
9361 + pcm186x_gain_sel_text,
9362 + pcm186x_gain_sel_value),
9363 +};
9364 +
9365 +static const struct snd_kcontrol_new pcm1863_snd_controls_card[] = {
9366 + SOC_ENUM("ADC Left Input", pcm186x_adc_input_channel_sel[0]),
9367 + SOC_ENUM("ADC Right Input", pcm186x_adc_input_channel_sel[1]),
9368 + SOC_ENUM("ADC Mic Bias", pcm186x_mic_bias_sel),
9369 + SOC_ENUM("PGA Gain Left", pcm186x_gain_sel[0]),
9370 + SOC_ENUM("PGA Gain Right", pcm186x_gain_sel[1]),
9371 +};
9372 +
9373 +static int pcm1863_add_controls(struct snd_soc_component *component)
9374 +{
9375 + snd_soc_add_component_controls(component,
9376 + pcm1863_snd_controls_card,
9377 + ARRAY_SIZE(pcm1863_snd_controls_card));
9378 + return 0;
9379 +}
9380 +
9381 +static void snd_rpi_hifiberry_dacplusadcpro_select_clk(
9382 + struct snd_soc_component *component, int clk_id)
9383 +{
9384 + switch (clk_id) {
9385 + case HIFIBERRY_DACPRO_NOCLOCK:
9386 + snd_soc_component_update_bits(component,
9387 + PCM512x_GPIO_CONTROL_1, 0x24, 0x00);
9388 + break;
9389 + case HIFIBERRY_DACPRO_CLK44EN:
9390 + snd_soc_component_update_bits(component,
9391 + PCM512x_GPIO_CONTROL_1, 0x24, 0x20);
9392 + break;
9393 + case HIFIBERRY_DACPRO_CLK48EN:
9394 + snd_soc_component_update_bits(component,
9395 + PCM512x_GPIO_CONTROL_1, 0x24, 0x04);
9396 + break;
9397 + }
9398 + usleep_range(3000, 4000);
9399 +}
9400 +
9401 +static void snd_rpi_hifiberry_dacplusadcpro_clk_gpio(struct snd_soc_component *component)
9402 +{
9403 + snd_soc_component_update_bits(component, PCM512x_GPIO_EN, 0x24, 0x24);
9404 + snd_soc_component_update_bits(component, PCM512x_GPIO_OUTPUT_3, 0x0f, 0x02);
9405 + snd_soc_component_update_bits(component, PCM512x_GPIO_OUTPUT_6, 0x0f, 0x02);
9406 +}
9407 +
9408 +static bool snd_rpi_hifiberry_dacplusadcpro_is_sclk(struct snd_soc_component *component)
9409 +{
9410 + unsigned int sck;
9411 +
9412 + sck = snd_soc_component_read(component, PCM512x_RATE_DET_4);
9413 + return (!(sck & 0x40));
9414 +}
9415 +
9416 +static bool snd_rpi_hifiberry_dacplusadcpro_is_pro_card(struct snd_soc_component *component)
9417 +{
9418 + bool isClk44EN, isClk48En, isNoClk;
9419 +
9420 + snd_rpi_hifiberry_dacplusadcpro_clk_gpio(component);
9421 +
9422 + snd_rpi_hifiberry_dacplusadcpro_select_clk(component, HIFIBERRY_DACPRO_CLK44EN);
9423 + isClk44EN = snd_rpi_hifiberry_dacplusadcpro_is_sclk(component);
9424 +
9425 + snd_rpi_hifiberry_dacplusadcpro_select_clk(component, HIFIBERRY_DACPRO_NOCLOCK);
9426 + isNoClk = snd_rpi_hifiberry_dacplusadcpro_is_sclk(component);
9427 +
9428 + snd_rpi_hifiberry_dacplusadcpro_select_clk(component, HIFIBERRY_DACPRO_CLK48EN);
9429 + isClk48En = snd_rpi_hifiberry_dacplusadcpro_is_sclk(component);
9430 +
9431 + return (isClk44EN && isClk48En && !isNoClk);
9432 +}
9433 +
9434 +static int snd_rpi_hifiberry_dacplusadcpro_clk_for_rate(int sample_rate)
9435 +{
9436 + int type;
9437 +
9438 + switch (sample_rate) {
9439 + case 11025:
9440 + case 22050:
9441 + case 44100:
9442 + case 88200:
9443 + case 176400:
9444 + case 352800:
9445 + type = HIFIBERRY_DACPRO_CLK44EN;
9446 + break;
9447 + default:
9448 + type = HIFIBERRY_DACPRO_CLK48EN;
9449 + break;
9450 + }
9451 + return type;
9452 +}
9453 +
9454 +static void snd_rpi_hifiberry_dacplusadcpro_set_sclk(struct snd_soc_component *component,
9455 + int sample_rate)
9456 +{
9457 + struct pcm512x_priv *pcm512x = snd_soc_component_get_drvdata(component);
9458 +
9459 + if (!IS_ERR(pcm512x->sclk)) {
9460 + int ctype;
9461 +
9462 + ctype = snd_rpi_hifiberry_dacplusadcpro_clk_for_rate(sample_rate);
9463 + clk_set_rate(pcm512x->sclk, (ctype == HIFIBERRY_DACPRO_CLK44EN)
9464 + ? CLK_44EN_RATE : CLK_48EN_RATE);
9465 + snd_rpi_hifiberry_dacplusadcpro_select_clk(component, ctype);
9466 + }
9467 +}
9468 +
9469 +static int snd_rpi_hifiberry_dacplusadcpro_init(struct snd_soc_pcm_runtime *rtd)
9470 +{
9471 + struct snd_soc_component *dac = asoc_rtd_to_codec(rtd, 0)->component;
9472 + struct snd_soc_component *adc = asoc_rtd_to_codec(rtd, 1)->component;
9473 + struct snd_soc_dai_driver *adc_driver = asoc_rtd_to_codec(rtd, 1)->driver;
9474 + struct pcm512x_priv *priv;
9475 + int ret;
9476 +
9477 + if (slave)
9478 + snd_rpi_hifiberry_is_dacpro = false;
9479 + else
9480 + snd_rpi_hifiberry_is_dacpro =
9481 + snd_rpi_hifiberry_dacplusadcpro_is_pro_card(dac);
9482 +
9483 + if (snd_rpi_hifiberry_is_dacpro) {
9484 + struct snd_soc_dai_link *dai = rtd->dai_link;
9485 +
9486 + dai->name = "HiFiBerry DAC+ADC Pro";
9487 + dai->stream_name = "HiFiBerry DAC+ADC Pro HiFi";
9488 + dai->dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
9489 + | SND_SOC_DAIFMT_CBM_CFM;
9490 +
9491 + // set DAC DAI configuration
9492 + ret = snd_soc_dai_set_fmt(asoc_rtd_to_codec(rtd, 0),
9493 + SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
9494 + | SND_SOC_DAIFMT_CBM_CFM);
9495 + if (ret < 0)
9496 + return ret;
9497 +
9498 + // set ADC DAI configuration
9499 + ret = snd_soc_dai_set_fmt(asoc_rtd_to_codec(rtd, 1),
9500 + SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
9501 + | SND_SOC_DAIFMT_CBS_CFS);
9502 + if (ret < 0)
9503 + return ret;
9504 +
9505 + // set CPU DAI configuration
9506 + ret = snd_soc_dai_set_fmt(asoc_rtd_to_cpu(rtd, 0),
9507 + SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
9508 + if (ret < 0)
9509 + return ret;
9510 +
9511 + snd_soc_component_update_bits(dac, PCM512x_BCLK_LRCLK_CFG, 0x31, 0x11);
9512 + snd_soc_component_update_bits(dac, PCM512x_MASTER_MODE, 0x03, 0x03);
9513 + snd_soc_component_update_bits(dac, PCM512x_MASTER_CLKDIV_2, 0x7f, 63);
9514 + } else {
9515 + priv = snd_soc_component_get_drvdata(dac);
9516 + priv->sclk = ERR_PTR(-ENOENT);
9517 + }
9518 +
9519 + /* disable 24bit mode as long as I2S module does not have sign extension fixed */
9520 + adc_driver->capture.formats = SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S16_LE;
9521 +
9522 + snd_soc_component_update_bits(dac, PCM512x_GPIO_EN, 0x08, 0x08);
9523 + snd_soc_component_update_bits(dac, PCM512x_GPIO_OUTPUT_4, 0x0f, 0x02);
9524 + if (leds_off)
9525 + snd_soc_component_update_bits(dac, PCM512x_GPIO_CONTROL_1, 0x08, 0x00);
9526 + else
9527 + snd_soc_component_update_bits(dac, PCM512x_GPIO_CONTROL_1, 0x08, 0x08);
9528 +
9529 + ret = pcm1863_add_controls(adc);
9530 + if (ret < 0)
9531 + dev_warn(rtd->dev, "Failed to add pcm1863 controls: %d\n",
9532 + ret);
9533 +
9534 + /* set GPIO2 to output, GPIO3 input */
9535 + snd_soc_component_write(adc, PCM186X_GPIO3_2_CTRL, 0x00);
9536 + snd_soc_component_write(adc, PCM186X_GPIO3_2_DIR_CTRL, 0x04);
9537 + if (leds_off)
9538 + snd_soc_component_update_bits(adc, PCM186X_GPIO_IN_OUT, 0x40, 0x00);
9539 + else
9540 + snd_soc_component_update_bits(adc, PCM186X_GPIO_IN_OUT, 0x40, 0x40);
9541 +
9542 + if (digital_gain_0db_limit) {
9543 + int ret;
9544 + struct snd_soc_card *card = rtd->card;
9545 +
9546 + ret = snd_soc_limit_volume(card, "Digital Playback Volume", 207);
9547 + if (ret < 0)
9548 + dev_warn(card->dev, "Failed to set volume limit: %d\n", ret);
9549 + }
9550 +
9551 + return 0;
9552 +}
9553 +
9554 +static int snd_rpi_hifiberry_dacplusadcpro_update_rate_den(
9555 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
9556 +{
9557 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
9558 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component; /* only use DAC */
9559 + struct pcm512x_priv *pcm512x = snd_soc_component_get_drvdata(component);
9560 + struct snd_ratnum *rats_no_pll;
9561 + unsigned int num = 0, den = 0;
9562 + int err;
9563 +
9564 + rats_no_pll = devm_kzalloc(rtd->dev, sizeof(*rats_no_pll), GFP_KERNEL);
9565 + if (!rats_no_pll)
9566 + return -ENOMEM;
9567 +
9568 + rats_no_pll->num = clk_get_rate(pcm512x->sclk) / 64;
9569 + rats_no_pll->den_min = 1;
9570 + rats_no_pll->den_max = 128;
9571 + rats_no_pll->den_step = 1;
9572 +
9573 + err = snd_interval_ratnum(hw_param_interval(params,
9574 + SNDRV_PCM_HW_PARAM_RATE), 1, rats_no_pll, &num, &den);
9575 + if (err >= 0 && den) {
9576 + params->rate_num = num;
9577 + params->rate_den = den;
9578 + }
9579 +
9580 + devm_kfree(rtd->dev, rats_no_pll);
9581 + return 0;
9582 +}
9583 +
9584 +static int snd_rpi_hifiberry_dacplusadcpro_hw_params(
9585 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
9586 +{
9587 + int ret = 0;
9588 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
9589 + int channels = params_channels(params);
9590 + int width = 32;
9591 + struct snd_soc_component *dac = asoc_rtd_to_codec(rtd, 0)->component;
9592 + struct snd_soc_dai *dai = asoc_rtd_to_codec(rtd, 0);
9593 + struct snd_soc_dai_driver *drv = dai->driver;
9594 + const struct snd_soc_dai_ops *ops = drv->ops;
9595 +
9596 + if (snd_rpi_hifiberry_is_dacpro) {
9597 + width = snd_pcm_format_physical_width(params_format(params));
9598 +
9599 + snd_rpi_hifiberry_dacplusadcpro_set_sclk(dac,
9600 + params_rate(params));
9601 +
9602 + ret = snd_rpi_hifiberry_dacplusadcpro_update_rate_den(
9603 + substream, params);
9604 + if (ret)
9605 + return ret;
9606 + }
9607 +
9608 + ret = snd_soc_dai_set_bclk_ratio(asoc_rtd_to_cpu(rtd, 0), channels * width);
9609 + if (ret)
9610 + return ret;
9611 + ret = snd_soc_dai_set_bclk_ratio(asoc_rtd_to_codec(rtd, 0), channels * width);
9612 + if (ret)
9613 + return ret;
9614 + if (snd_rpi_hifiberry_is_dacpro && ops->hw_params)
9615 + ret = ops->hw_params(substream, params, dai);
9616 + return ret;
9617 +}
9618 +
9619 +static int snd_rpi_hifiberry_dacplusadcpro_startup(
9620 + struct snd_pcm_substream *substream)
9621 +{
9622 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
9623 + struct snd_soc_component *dac = asoc_rtd_to_codec(rtd, 0)->component;
9624 + struct snd_soc_component *adc = asoc_rtd_to_codec(rtd, 1)->component;
9625 +
9626 + if (leds_off)
9627 + return 0;
9628 + /* switch on respective LED */
9629 + if (!substream->stream)
9630 + snd_soc_component_update_bits(dac, PCM512x_GPIO_CONTROL_1, 0x08, 0x08);
9631 + else
9632 + snd_soc_component_update_bits(adc, PCM186X_GPIO_IN_OUT, 0x40, 0x40);
9633 + return 0;
9634 +}
9635 +
9636 +static void snd_rpi_hifiberry_dacplusadcpro_shutdown(
9637 + struct snd_pcm_substream *substream)
9638 +{
9639 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
9640 + struct snd_soc_component *dac = asoc_rtd_to_codec(rtd, 0)->component;
9641 + struct snd_soc_component *adc = asoc_rtd_to_codec(rtd, 1)->component;
9642 +
9643 + /* switch off respective LED */
9644 + if (!substream->stream)
9645 + snd_soc_component_update_bits(dac, PCM512x_GPIO_CONTROL_1, 0x08, 0x00);
9646 + else
9647 + snd_soc_component_update_bits(adc, PCM186X_GPIO_IN_OUT, 0x40, 0x00);
9648 +}
9649 +
9650 +
9651 +/* machine stream operations */
9652 +static struct snd_soc_ops snd_rpi_hifiberry_dacplusadcpro_ops = {
9653 + .hw_params = snd_rpi_hifiberry_dacplusadcpro_hw_params,
9654 + .startup = snd_rpi_hifiberry_dacplusadcpro_startup,
9655 + .shutdown = snd_rpi_hifiberry_dacplusadcpro_shutdown,
9656 +};
9657 +
9658 +SND_SOC_DAILINK_DEFS(hifi,
9659 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
9660 + DAILINK_COMP_ARRAY(COMP_CODEC("pcm512x.1-004d", "pcm512x-hifi"),
9661 + COMP_CODEC("pcm186x.1-004a", "pcm1863-aif")),
9662 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
9663 +
9664 +static struct snd_soc_dai_link snd_rpi_hifiberry_dacplusadcpro_dai[] = {
9665 +{
9666 + .name = "HiFiBerry DAC+ADC PRO",
9667 + .stream_name = "HiFiBerry DAC+ADC PRO HiFi",
9668 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
9669 + SND_SOC_DAIFMT_CBS_CFS,
9670 + .ops = &snd_rpi_hifiberry_dacplusadcpro_ops,
9671 + .init = snd_rpi_hifiberry_dacplusadcpro_init,
9672 + SND_SOC_DAILINK_REG(hifi),
9673 +},
9674 +};
9675 +
9676 +/* aux device for optional headphone amp */
9677 +static struct snd_soc_aux_dev hifiberry_dacplusadcpro_aux_devs[] = {
9678 + {
9679 + .dlc = {
9680 + .name = "tpa6130a2.1-0060",
9681 + },
9682 + },
9683 +};
9684 +
9685 +/* audio machine driver */
9686 +static struct snd_soc_card snd_rpi_hifiberry_dacplusadcpro = {
9687 + .name = "snd_rpi_hifiberry_dacplusadcpro",
9688 + .driver_name = "HifiberryDacpAdcPro",
9689 + .owner = THIS_MODULE,
9690 + .dai_link = snd_rpi_hifiberry_dacplusadcpro_dai,
9691 + .num_links = ARRAY_SIZE(snd_rpi_hifiberry_dacplusadcpro_dai),
9692 +};
9693 +
9694 +static int hb_hp_detect(void)
9695 +{
9696 + struct i2c_adapter *adap = i2c_get_adapter(1);
9697 + int ret;
9698 + struct i2c_client tpa_i2c_client = {
9699 + .addr = 0x60,
9700 + .adapter = adap,
9701 + };
9702 +
9703 + if (!adap)
9704 + return -EPROBE_DEFER; /* I2C module not yet available */
9705 +
9706 + ret = i2c_smbus_read_byte(&tpa_i2c_client) >= 0;
9707 + i2c_put_adapter(adap);
9708 + return ret;
9709 +};
9710 +
9711 +static struct property tpa_enable_prop = {
9712 + .name = "status",
9713 + .length = 4 + 1, /* length 'okay' + 1 */
9714 + .value = "okay",
9715 + };
9716 +
9717 +static int snd_rpi_hifiberry_dacplusadcpro_probe(struct platform_device *pdev)
9718 +{
9719 + int ret = 0, i = 0;
9720 + struct snd_soc_card *card = &snd_rpi_hifiberry_dacplusadcpro;
9721 + struct device_node *tpa_node;
9722 + struct property *tpa_prop;
9723 + struct of_changeset ocs;
9724 + int len;
9725 +
9726 + /* probe for head phone amp */
9727 + ret = hb_hp_detect();
9728 + if (ret < 0)
9729 + return ret;
9730 + if (ret) {
9731 + card->aux_dev = hifiberry_dacplusadcpro_aux_devs;
9732 + card->num_aux_devs =
9733 + ARRAY_SIZE(hifiberry_dacplusadcpro_aux_devs);
9734 + tpa_node = of_find_compatible_node(NULL, NULL, "ti,tpa6130a2");
9735 + tpa_prop = of_find_property(tpa_node, "status", &len);
9736 +
9737 + if (strcmp((char *)tpa_prop->value, "okay")) {
9738 + /* and activate headphone using change_sets */
9739 + dev_info(&pdev->dev, "activating headphone amplifier");
9740 + of_changeset_init(&ocs);
9741 + ret = of_changeset_update_property(&ocs, tpa_node,
9742 + &tpa_enable_prop);
9743 + if (ret) {
9744 + dev_err(&pdev->dev,
9745 + "cannot activate headphone amplifier\n");
9746 + return -ENODEV;
9747 + }
9748 + ret = of_changeset_apply(&ocs);
9749 + if (ret) {
9750 + dev_err(&pdev->dev,
9751 + "cannot activate headphone amplifier\n");
9752 + return -ENODEV;
9753 + }
9754 + }
9755 + }
9756 +
9757 + snd_rpi_hifiberry_dacplusadcpro.dev = &pdev->dev;
9758 + if (pdev->dev.of_node) {
9759 + struct device_node *i2s_node;
9760 + struct snd_soc_dai_link *dai;
9761 +
9762 + dai = &snd_rpi_hifiberry_dacplusadcpro_dai[0];
9763 + i2s_node = of_parse_phandle(pdev->dev.of_node,
9764 + "i2s-controller", 0);
9765 + if (i2s_node) {
9766 + for (i = 0; i < card->num_links; i++) {
9767 + dai->cpus->dai_name = NULL;
9768 + dai->cpus->of_node = i2s_node;
9769 + dai->platforms->name = NULL;
9770 + dai->platforms->of_node = i2s_node;
9771 + }
9772 + }
9773 + }
9774 + digital_gain_0db_limit = !of_property_read_bool(
9775 + pdev->dev.of_node, "hifiberry-dacplusadcpro,24db_digital_gain");
9776 + slave = of_property_read_bool(pdev->dev.of_node,
9777 + "hifiberry-dacplusadcpro,slave");
9778 + leds_off = of_property_read_bool(pdev->dev.of_node,
9779 + "hifiberry-dacplusadcpro,leds_off");
9780 + ret = snd_soc_register_card(&snd_rpi_hifiberry_dacplusadcpro);
9781 + if (ret && ret != -EPROBE_DEFER)
9782 + dev_err(&pdev->dev,
9783 + "snd_soc_register_card() failed: %d\n", ret);
9784 +
9785 + return ret;
9786 +}
9787 +
9788 +static const struct of_device_id snd_rpi_hifiberry_dacplusadcpro_of_match[] = {
9789 + { .compatible = "hifiberry,hifiberry-dacplusadcpro", },
9790 + {},
9791 +};
9792 +
9793 +MODULE_DEVICE_TABLE(of, snd_rpi_hifiberry_dacplusadcpro_of_match);
9794 +
9795 +static struct platform_driver snd_rpi_hifiberry_dacplusadcpro_driver = {
9796 + .driver = {
9797 + .name = "snd-rpi-hifiberry-dacplusadcpro",
9798 + .owner = THIS_MODULE,
9799 + .of_match_table = snd_rpi_hifiberry_dacplusadcpro_of_match,
9800 + },
9801 + .probe = snd_rpi_hifiberry_dacplusadcpro_probe,
9802 +};
9803 +
9804 +module_platform_driver(snd_rpi_hifiberry_dacplusadcpro_driver);
9805 +
9806 +MODULE_AUTHOR("Joerg Schambacher <joerg@hifiberry.com>");
9807 +MODULE_AUTHOR("Daniel Matuschek <daniel@hifiberry.com>");
9808 +MODULE_DESCRIPTION("ASoC Driver for HiFiBerry DAC+ADC");
9809 +MODULE_LICENSE("GPL v2");
9810 --- /dev/null
9811 +++ b/sound/soc/bcm/hifiberry_dacplusdsp.c
9812 @@ -0,0 +1,90 @@
9813 +// SPDX-License-Identifier: GPL-2.0
9814 +/*
9815 + * ASoC Driver for HiFiBerry DAC + DSP
9816 + *
9817 + * Author: Joerg Schambacher <joscha@schambacher.com>
9818 + * Copyright 2018
9819 + *
9820 + * This program is free software; you can redistribute it and/or
9821 + * modify it under the terms of the GNU General Public License
9822 + * version 2 as published by the Free Software Foundation.
9823 + *
9824 + * This program is distributed in the hope that it will be useful, but
9825 + * WITHOUT ANY WARRANTY; without even the implied warranty of
9826 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9827 + * General Public License for more details.
9828 + */
9829 +
9830 +#include <linux/init.h>
9831 +#include <linux/module.h>
9832 +#include <linux/of.h>
9833 +#include <linux/platform_device.h>
9834 +#include <sound/soc.h>
9835 +
9836 +static struct snd_soc_component_driver dacplusdsp_component_driver;
9837 +
9838 +static struct snd_soc_dai_driver dacplusdsp_dai = {
9839 + .name = "dacplusdsp-hifi",
9840 + .capture = {
9841 + .stream_name = "DAC+DSP Capture",
9842 + .channels_min = 2,
9843 + .channels_max = 2,
9844 + .rates = SNDRV_PCM_RATE_CONTINUOUS,
9845 + .formats = SNDRV_PCM_FMTBIT_S16_LE |
9846 + SNDRV_PCM_FMTBIT_S24_LE |
9847 + SNDRV_PCM_FMTBIT_S32_LE,
9848 + },
9849 + .playback = {
9850 + .stream_name = "DACP+DSP Playback",
9851 + .channels_min = 2,
9852 + .channels_max = 2,
9853 + .rates = SNDRV_PCM_RATE_CONTINUOUS,
9854 + .formats = SNDRV_PCM_FMTBIT_S16_LE |
9855 + SNDRV_PCM_FMTBIT_S24_LE |
9856 + SNDRV_PCM_FMTBIT_S32_LE,
9857 + },
9858 + .symmetric_rate = 1};
9859 +
9860 +#ifdef CONFIG_OF
9861 +static const struct of_device_id dacplusdsp_ids[] = {
9862 + {
9863 + .compatible = "hifiberry,dacplusdsp",
9864 + },
9865 + {} };
9866 +MODULE_DEVICE_TABLE(of, dacplusdsp_ids);
9867 +#endif
9868 +
9869 +static int dacplusdsp_platform_probe(struct platform_device *pdev)
9870 +{
9871 + int ret;
9872 +
9873 + ret = snd_soc_register_component(&pdev->dev,
9874 + &dacplusdsp_component_driver, &dacplusdsp_dai, 1);
9875 + if (ret) {
9876 + pr_alert("snd_soc_register_component failed\n");
9877 + return ret;
9878 + }
9879 +
9880 + return 0;
9881 +}
9882 +
9883 +static int dacplusdsp_platform_remove(struct platform_device *pdev)
9884 +{
9885 + snd_soc_unregister_component(&pdev->dev);
9886 + return 0;
9887 +}
9888 +
9889 +static struct platform_driver dacplusdsp_driver = {
9890 + .driver = {
9891 + .name = "hifiberry-dacplusdsp-codec",
9892 + .of_match_table = of_match_ptr(dacplusdsp_ids),
9893 + },
9894 + .probe = dacplusdsp_platform_probe,
9895 + .remove = dacplusdsp_platform_remove,
9896 +};
9897 +
9898 +module_platform_driver(dacplusdsp_driver);
9899 +
9900 +MODULE_AUTHOR("Joerg Schambacher <joerg@i2audio.com>");
9901 +MODULE_DESCRIPTION("ASoC Driver for HiFiBerry DAC+DSP");
9902 +MODULE_LICENSE("GPL v2");
9903 --- /dev/null
9904 +++ b/sound/soc/bcm/hifiberry_dacplushd.c
9905 @@ -0,0 +1,238 @@
9906 +// SPDX-License-Identifier: GPL-2.0
9907 +/*
9908 + * ASoC Driver for HiFiBerry DAC+ HD
9909 + *
9910 + * Author: Joerg Schambacher, i2Audio GmbH for HiFiBerry
9911 + * Copyright 2020
9912 + *
9913 + * This program is free software; you can redistribute it and/or
9914 + * modify it under the terms of the GNU General Public License
9915 + * version 2 as published by the Free Software Foundation.
9916 + *
9917 + * This program is distributed in the hope that it will be useful, but
9918 + * WITHOUT ANY WARRANTY; without even the implied warranty of
9919 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9920 + * General Public License for more details.
9921 + */
9922 +
9923 +#include <linux/module.h>
9924 +#include <linux/platform_device.h>
9925 +#include <linux/kernel.h>
9926 +#include <linux/delay.h>
9927 +#include <linux/module.h>
9928 +#include <linux/of.h>
9929 +#include <linux/delay.h>
9930 +#include <linux/gpio.h>
9931 +#include <linux/gpio/consumer.h>
9932 +#include <sound/core.h>
9933 +#include <sound/pcm.h>
9934 +#include <sound/pcm_params.h>
9935 +#include <sound/soc.h>
9936 +#include <linux/i2c.h>
9937 +#include <linux/clk.h>
9938 +
9939 +#include "../codecs/pcm179x.h"
9940 +
9941 +#define DEFAULT_RATE 44100
9942 +
9943 +struct brd_drv_data {
9944 + struct regmap *regmap;
9945 + struct clk *sclk;
9946 +};
9947 +
9948 +static struct brd_drv_data drvdata;
9949 +static struct gpio_desc *reset_gpio;
9950 +static const unsigned int hb_dacplushd_rates[] = {
9951 + 192000, 96000, 48000, 176400, 88200, 44100,
9952 +};
9953 +
9954 +static struct snd_pcm_hw_constraint_list hb_dacplushd_constraints = {
9955 + .list = hb_dacplushd_rates,
9956 + .count = ARRAY_SIZE(hb_dacplushd_rates),
9957 +};
9958 +
9959 +static int snd_rpi_hb_dacplushd_startup(struct snd_pcm_substream *substream)
9960 +{
9961 + /* constraints for standard sample rates */
9962 + snd_pcm_hw_constraint_list(substream->runtime, 0,
9963 + SNDRV_PCM_HW_PARAM_RATE,
9964 + &hb_dacplushd_constraints);
9965 + return 0;
9966 +}
9967 +
9968 +static void snd_rpi_hifiberry_dacplushd_set_sclk(
9969 + struct snd_soc_component *component,
9970 + int sample_rate)
9971 +{
9972 + if (!IS_ERR(drvdata.sclk))
9973 + clk_set_rate(drvdata.sclk, sample_rate);
9974 +}
9975 +
9976 +static int snd_rpi_hifiberry_dacplushd_init(struct snd_soc_pcm_runtime *rtd)
9977 +{
9978 + struct snd_soc_dai_link *dai = rtd->dai_link;
9979 + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
9980 +
9981 + dai->name = "HiFiBerry DAC+ HD";
9982 + dai->stream_name = "HiFiBerry DAC+ HD HiFi";
9983 + dai->dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
9984 + | SND_SOC_DAIFMT_CBM_CFM;
9985 +
9986 + /* allow only fixed 32 clock counts per channel */
9987 + snd_soc_dai_set_bclk_ratio(cpu_dai, 32*2);
9988 +
9989 + return 0;
9990 +}
9991 +
9992 +static int snd_rpi_hifiberry_dacplushd_hw_params(
9993 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
9994 +{
9995 + int ret = 0;
9996 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
9997 +
9998 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
9999 +
10000 + snd_rpi_hifiberry_dacplushd_set_sclk(component, params_rate(params));
10001 + return ret;
10002 +}
10003 +
10004 +/* machine stream operations */
10005 +static struct snd_soc_ops snd_rpi_hifiberry_dacplushd_ops = {
10006 + .startup = snd_rpi_hb_dacplushd_startup,
10007 + .hw_params = snd_rpi_hifiberry_dacplushd_hw_params,
10008 +};
10009 +
10010 +SND_SOC_DAILINK_DEFS(hifi,
10011 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
10012 + DAILINK_COMP_ARRAY(COMP_CODEC("pcm179x.1-004c", "pcm179x-hifi")),
10013 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
10014 +
10015 +
10016 +static struct snd_soc_dai_link snd_rpi_hifiberry_dacplushd_dai[] = {
10017 +{
10018 + .name = "HiFiBerry DAC+ HD",
10019 + .stream_name = "HiFiBerry DAC+ HD HiFi",
10020 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
10021 + SND_SOC_DAIFMT_CBS_CFS,
10022 + .ops = &snd_rpi_hifiberry_dacplushd_ops,
10023 + .init = snd_rpi_hifiberry_dacplushd_init,
10024 + SND_SOC_DAILINK_REG(hifi),
10025 +},
10026 +};
10027 +
10028 +/* audio machine driver */
10029 +static struct snd_soc_card snd_rpi_hifiberry_dacplushd = {
10030 + .name = "snd_rpi_hifiberry_dacplushd",
10031 + .driver_name = "HifiberryDacplusHD",
10032 + .owner = THIS_MODULE,
10033 + .dai_link = snd_rpi_hifiberry_dacplushd_dai,
10034 + .num_links = ARRAY_SIZE(snd_rpi_hifiberry_dacplushd_dai),
10035 +};
10036 +
10037 +static int snd_rpi_hifiberry_dacplushd_probe(struct platform_device *pdev)
10038 +{
10039 + int ret = 0;
10040 + static int dac_reset_done;
10041 + struct device *dev = &pdev->dev;
10042 + struct device_node *dev_node = dev->of_node;
10043 +
10044 + snd_rpi_hifiberry_dacplushd.dev = &pdev->dev;
10045 +
10046 + /* get GPIO and release DAC from RESET */
10047 + if (!dac_reset_done) {
10048 + reset_gpio = gpiod_get(&pdev->dev, "reset", GPIOD_OUT_LOW);
10049 + if (IS_ERR(reset_gpio)) {
10050 + dev_err(&pdev->dev, "gpiod_get() failed\n");
10051 + return -EINVAL;
10052 + }
10053 + dac_reset_done = 1;
10054 + }
10055 + if (!IS_ERR(reset_gpio))
10056 + gpiod_set_value(reset_gpio, 0);
10057 + msleep(1);
10058 + if (!IS_ERR(reset_gpio))
10059 + gpiod_set_value(reset_gpio, 1);
10060 + msleep(1);
10061 + if (!IS_ERR(reset_gpio))
10062 + gpiod_set_value(reset_gpio, 0);
10063 +
10064 + if (pdev->dev.of_node) {
10065 + struct device_node *i2s_node;
10066 + struct snd_soc_dai_link *dai;
10067 +
10068 + dai = &snd_rpi_hifiberry_dacplushd_dai[0];
10069 + i2s_node = of_parse_phandle(pdev->dev.of_node,
10070 + "i2s-controller", 0);
10071 +
10072 + if (i2s_node) {
10073 + dai->cpus->of_node = i2s_node;
10074 + dai->platforms->of_node = i2s_node;
10075 + dai->cpus->dai_name = NULL;
10076 + dai->platforms->name = NULL;
10077 + } else {
10078 + return -EPROBE_DEFER;
10079 + }
10080 +
10081 + }
10082 +
10083 + ret = devm_snd_soc_register_card(&pdev->dev,
10084 + &snd_rpi_hifiberry_dacplushd);
10085 + if (ret && ret != -EPROBE_DEFER) {
10086 + dev_err(&pdev->dev,
10087 + "snd_soc_register_card() failed: %d\n", ret);
10088 + return ret;
10089 + }
10090 + if (ret == -EPROBE_DEFER)
10091 + return ret;
10092 +
10093 + dev_set_drvdata(dev, &drvdata);
10094 + if (dev_node == NULL) {
10095 + dev_err(&pdev->dev, "Device tree node not found\n");
10096 + return -ENODEV;
10097 + }
10098 +
10099 + drvdata.sclk = devm_clk_get(dev, NULL);
10100 + if (IS_ERR(drvdata.sclk)) {
10101 + drvdata.sclk = ERR_PTR(-ENOENT);
10102 + return -ENODEV;
10103 + }
10104 +
10105 + clk_set_rate(drvdata.sclk, DEFAULT_RATE);
10106 +
10107 + return ret;
10108 +}
10109 +
10110 +static int snd_rpi_hifiberry_dacplushd_remove(struct platform_device *pdev)
10111 +{
10112 + if (IS_ERR(reset_gpio))
10113 + return -EINVAL;
10114 +
10115 + /* put DAC into RESET and release GPIO */
10116 + gpiod_set_value(reset_gpio, 0);
10117 + gpiod_put(reset_gpio);
10118 +
10119 + return 0;
10120 +}
10121 +
10122 +static const struct of_device_id snd_rpi_hifiberry_dacplushd_of_match[] = {
10123 + { .compatible = "hifiberry,hifiberry-dacplushd", },
10124 + {},
10125 +};
10126 +
10127 +MODULE_DEVICE_TABLE(of, snd_rpi_hifiberry_dacplushd_of_match);
10128 +
10129 +static struct platform_driver snd_rpi_hifiberry_dacplushd_driver = {
10130 + .driver = {
10131 + .name = "snd-rpi-hifiberry-dacplushd",
10132 + .owner = THIS_MODULE,
10133 + .of_match_table = snd_rpi_hifiberry_dacplushd_of_match,
10134 + },
10135 + .probe = snd_rpi_hifiberry_dacplushd_probe,
10136 + .remove = snd_rpi_hifiberry_dacplushd_remove,
10137 +};
10138 +
10139 +module_platform_driver(snd_rpi_hifiberry_dacplushd_driver);
10140 +
10141 +MODULE_AUTHOR("Joerg Schambacher <joerg@i2audio.com>");
10142 +MODULE_DESCRIPTION("ASoC Driver for HiFiBerry DAC+ HD");
10143 +MODULE_LICENSE("GPL v2");
10144 --- /dev/null
10145 +++ b/sound/soc/bcm/i-sabre-q2m.c
10146 @@ -0,0 +1,159 @@
10147 +/*
10148 + * ASoC Driver for I-Sabre Q2M
10149 + *
10150 + * Author: Satoru Kawase
10151 + * Modified by: Xiao Qingyong
10152 + * Update kernel v4.18+ by : Audiophonics
10153 + * Copyright 2018 Audiophonics
10154 + *
10155 + * This program is free software; you can redistribute it and/or
10156 + * modify it under the terms of the GNU General Public License
10157 + * version 2 as published by the Free Software Foundation.
10158 + *
10159 + * This program is distributed in the hope that it will be useful, but
10160 + * WITHOUT ANY WARRANTY; without even the implied warranty of
10161 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10162 + * General Public License for more details.
10163 + */
10164 +
10165 +#include <linux/kernel.h>
10166 +#include <linux/init.h>
10167 +#include <linux/module.h>
10168 +#include <linux/delay.h>
10169 +#include <linux/fs.h>
10170 +#include <asm/uaccess.h>
10171 +#include <sound/core.h>
10172 +#include <sound/soc.h>
10173 +#include <sound/pcm.h>
10174 +#include <sound/pcm_params.h>
10175 +
10176 +#include "../codecs/i-sabre-codec.h"
10177 +
10178 +
10179 +static int snd_rpi_i_sabre_q2m_init(struct snd_soc_pcm_runtime *rtd)
10180 +{
10181 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
10182 + unsigned int value;
10183 +
10184 + /* Device ID */
10185 + value = snd_soc_component_read(component, ISABRECODEC_REG_01);
10186 + dev_info(component->card->dev, "Audiophonics Device ID : %02X\n", value);
10187 +
10188 + /* API revision */
10189 + value = snd_soc_component_read(component, ISABRECODEC_REG_02);
10190 + dev_info(component->card->dev, "Audiophonics API revision : %02X\n", value);
10191 +
10192 + return 0;
10193 +}
10194 +
10195 +static int snd_rpi_i_sabre_q2m_hw_params(
10196 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
10197 +{
10198 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
10199 + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
10200 + int bclk_ratio;
10201 +
10202 + bclk_ratio = snd_pcm_format_physical_width(
10203 + params_format(params)) * params_channels(params);
10204 + return snd_soc_dai_set_bclk_ratio(cpu_dai, bclk_ratio);
10205 +}
10206 +
10207 +/* machine stream operations */
10208 +static struct snd_soc_ops snd_rpi_i_sabre_q2m_ops = {
10209 + .hw_params = snd_rpi_i_sabre_q2m_hw_params,
10210 +};
10211 +
10212 +SND_SOC_DAILINK_DEFS(rpi_i_sabre_q2m,
10213 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
10214 + DAILINK_COMP_ARRAY(COMP_CODEC("i-sabre-codec-i2c.1-0048", "i-sabre-codec-dai")),
10215 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
10216 +
10217 +static struct snd_soc_dai_link snd_rpi_i_sabre_q2m_dai[] = {
10218 + {
10219 + .name = "I-Sabre Q2M",
10220 + .stream_name = "I-Sabre Q2M DAC",
10221 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
10222 + | SND_SOC_DAIFMT_CBS_CFS,
10223 + .init = snd_rpi_i_sabre_q2m_init,
10224 + .ops = &snd_rpi_i_sabre_q2m_ops,
10225 + SND_SOC_DAILINK_REG(rpi_i_sabre_q2m),
10226 + }
10227 +};
10228 +
10229 +/* audio machine driver */
10230 +static struct snd_soc_card snd_rpi_i_sabre_q2m = {
10231 + .name = "I-Sabre Q2M DAC",
10232 + .owner = THIS_MODULE,
10233 + .dai_link = snd_rpi_i_sabre_q2m_dai,
10234 + .num_links = ARRAY_SIZE(snd_rpi_i_sabre_q2m_dai)
10235 +};
10236 +
10237 +
10238 +static int snd_rpi_i_sabre_q2m_probe(struct platform_device *pdev)
10239 +{
10240 + int ret = 0;
10241 +
10242 + snd_rpi_i_sabre_q2m.dev = &pdev->dev;
10243 + if (pdev->dev.of_node) {
10244 + struct device_node *i2s_node;
10245 + struct snd_soc_dai_link *dai;
10246 +
10247 + dai = &snd_rpi_i_sabre_q2m_dai[0];
10248 + i2s_node = of_parse_phandle(pdev->dev.of_node,
10249 + "i2s-controller", 0);
10250 + if (i2s_node) {
10251 + dai->cpus->dai_name = NULL;
10252 + dai->cpus->of_node = i2s_node;
10253 + dai->platforms->name = NULL;
10254 + dai->platforms->of_node = i2s_node;
10255 + } else {
10256 + dev_err(&pdev->dev,
10257 + "Property 'i2s-controller' missing or invalid\n");
10258 + return (-EINVAL);
10259 + }
10260 +
10261 + dai->name = "I-Sabre Q2M";
10262 + dai->stream_name = "I-Sabre Q2M DAC";
10263 + dai->dai_fmt = SND_SOC_DAIFMT_I2S
10264 + | SND_SOC_DAIFMT_NB_NF
10265 + | SND_SOC_DAIFMT_CBS_CFS;
10266 + }
10267 +
10268 + /* Wait for registering codec driver */
10269 + mdelay(50);
10270 +
10271 + ret = snd_soc_register_card(&snd_rpi_i_sabre_q2m);
10272 + if (ret) {
10273 + dev_err(&pdev->dev,
10274 + "snd_soc_register_card() failed: %d\n", ret);
10275 + }
10276 +
10277 + return ret;
10278 +}
10279 +
10280 +static int snd_rpi_i_sabre_q2m_remove(struct platform_device *pdev)
10281 +{
10282 + snd_soc_unregister_card(&snd_rpi_i_sabre_q2m);
10283 + return 0;
10284 +}
10285 +
10286 +static const struct of_device_id snd_rpi_i_sabre_q2m_of_match[] = {
10287 + { .compatible = "audiophonics,i-sabre-q2m", },
10288 + {}
10289 +};
10290 +MODULE_DEVICE_TABLE(of, snd_rpi_i_sabre_q2m_of_match);
10291 +
10292 +static struct platform_driver snd_rpi_i_sabre_q2m_driver = {
10293 + .driver = {
10294 + .name = "snd-rpi-i-sabre-q2m",
10295 + .owner = THIS_MODULE,
10296 + .of_match_table = snd_rpi_i_sabre_q2m_of_match,
10297 + },
10298 + .probe = snd_rpi_i_sabre_q2m_probe,
10299 + .remove = snd_rpi_i_sabre_q2m_remove,
10300 +};
10301 +module_platform_driver(snd_rpi_i_sabre_q2m_driver);
10302 +
10303 +MODULE_DESCRIPTION("ASoC Driver for I-Sabre Q2M");
10304 +MODULE_AUTHOR("Audiophonics <http://www.audiophonics.fr>");
10305 +MODULE_LICENSE("GPL");
10306 --- /dev/null
10307 +++ b/sound/soc/bcm/iqaudio-codec.c
10308 @@ -0,0 +1,278 @@
10309 +/*
10310 + * ASoC Driver for IQaudIO Raspberry Pi Codec board
10311 + *
10312 + * Author: Gordon Garrity <gordon@iqaudio.com>
10313 + * (C) Copyright IQaudio Limited, 2017-2019
10314 + *
10315 + * This program is free software; you can redistribute it and/or
10316 + * modify it under the terms of the GNU General Public License
10317 + * version 2 as published by the Free Software Foundation.
10318 + *
10319 + * This program is distributed in the hope that it will be useful, but
10320 + * WITHOUT ANY WARRANTY; without even the implied warranty of
10321 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10322 + * General Public License for more details.
10323 + */
10324 +
10325 +#include <linux/module.h>
10326 +#include <linux/gpio/consumer.h>
10327 +#include <linux/platform_device.h>
10328 +
10329 +#include <sound/core.h>
10330 +#include <sound/pcm.h>
10331 +#include <sound/pcm_params.h>
10332 +#include <sound/soc.h>
10333 +#include <sound/jack.h>
10334 +
10335 +#include <linux/acpi.h>
10336 +#include <linux/slab.h>
10337 +#include "../codecs/da7213.h"
10338 +
10339 +static int pll_out = DA7213_PLL_FREQ_OUT_90316800;
10340 +
10341 +static int snd_rpi_iqaudio_pll_control(struct snd_soc_dapm_widget *w,
10342 + struct snd_kcontrol *k, int event)
10343 +{
10344 + int ret = 0;
10345 + struct snd_soc_dapm_context *dapm = w->dapm;
10346 + struct snd_soc_card *card = dapm->card;
10347 + struct snd_soc_pcm_runtime *rtd =
10348 + snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
10349 + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
10350 +
10351 + if (SND_SOC_DAPM_EVENT_OFF(event)) {
10352 + ret = snd_soc_dai_set_pll(codec_dai, 0, DA7213_SYSCLK_MCLK, 0,
10353 + 0);
10354 + if (ret)
10355 + dev_err(card->dev, "Failed to bypass PLL: %d\n", ret);
10356 + /* Allow PLL time to bypass */
10357 + msleep(100);
10358 + } else if (SND_SOC_DAPM_EVENT_ON(event)) {
10359 + ret = snd_soc_dai_set_pll(codec_dai, 0, DA7213_SYSCLK_PLL, 0,
10360 + pll_out);
10361 + if (ret)
10362 + dev_err(card->dev, "Failed to enable PLL: %d\n", ret);
10363 + /* Allow PLL time to lock */
10364 + msleep(100);
10365 + }
10366 +
10367 + return ret;
10368 +}
10369 +
10370 +static int snd_rpi_iqaudio_post_dapm_event(struct snd_soc_dapm_widget *w,
10371 + struct snd_kcontrol *kcontrol,
10372 + int event)
10373 +{
10374 + switch (event) {
10375 + case SND_SOC_DAPM_POST_PMU:
10376 + /* Delay for mic bias ramp */
10377 + msleep(1000);
10378 + break;
10379 + default:
10380 + break;
10381 + }
10382 +
10383 + return 0;
10384 +}
10385 +
10386 +static const struct snd_kcontrol_new dapm_controls[] = {
10387 + SOC_DAPM_PIN_SWITCH("HP Jack"),
10388 + SOC_DAPM_PIN_SWITCH("MIC Jack"),
10389 + SOC_DAPM_PIN_SWITCH("Onboard MIC"),
10390 + SOC_DAPM_PIN_SWITCH("AUX Jack"),
10391 +};
10392 +
10393 +static const struct snd_soc_dapm_widget dapm_widgets[] = {
10394 + SND_SOC_DAPM_HP("HP Jack", NULL),
10395 + SND_SOC_DAPM_MIC("MIC Jack", NULL),
10396 + SND_SOC_DAPM_MIC("Onboard MIC", NULL),
10397 + SND_SOC_DAPM_LINE("AUX Jack", NULL),
10398 + SND_SOC_DAPM_SUPPLY("PLL Control", SND_SOC_NOPM, 0, 0,
10399 + snd_rpi_iqaudio_pll_control,
10400 + SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
10401 + SND_SOC_DAPM_POST("Post Power Up Event", snd_rpi_iqaudio_post_dapm_event),
10402 +};
10403 +
10404 +static const struct snd_soc_dapm_route audio_map[] = {
10405 + {"HP Jack", NULL, "HPL"},
10406 + {"HP Jack", NULL, "HPR"},
10407 + {"HP Jack", NULL, "PLL Control"},
10408 +
10409 + {"AUXR", NULL, "AUX Jack"},
10410 + {"AUXL", NULL, "AUX Jack"},
10411 + {"AUX Jack", NULL, "PLL Control"},
10412 +
10413 + /* Assume Mic1 is linked to Headset and Mic2 to on-board mic */
10414 + {"MIC1", NULL, "MIC Jack"},
10415 + {"MIC Jack", NULL, "PLL Control"},
10416 + {"MIC2", NULL, "Onboard MIC"},
10417 + {"Onboard MIC", NULL, "PLL Control"},
10418 +};
10419 +
10420 +/* machine stream operations */
10421 +
10422 +static int snd_rpi_iqaudio_codec_init(struct snd_soc_pcm_runtime *rtd)
10423 +{
10424 + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
10425 + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
10426 + int ret;
10427 +
10428 + /*
10429 + * Disable AUX Jack Pin by default to prevent PLL being enabled at
10430 + * startup. This avoids holding the PLL to a fixed SR config for
10431 + * subsequent streams.
10432 + *
10433 + * This pin can still be enabled later, as required by user-space.
10434 + */
10435 + snd_soc_dapm_disable_pin(&rtd->card->dapm, "AUX Jack");
10436 + snd_soc_dapm_sync(&rtd->card->dapm);
10437 +
10438 + /* Set bclk ratio to align with codec's BCLK rate */
10439 + ret = snd_soc_dai_set_bclk_ratio(cpu_dai, 64);
10440 + if (ret) {
10441 + dev_err(rtd->dev, "Failed to set CPU BLCK ratio\n");
10442 + return ret;
10443 + }
10444 +
10445 + /* Set MCLK frequency to codec, onboard 11.2896MHz clock */
10446 + return snd_soc_dai_set_sysclk(codec_dai, DA7213_CLKSRC_MCLK, 11289600,
10447 + SND_SOC_CLOCK_OUT);
10448 +}
10449 +
10450 +static int snd_rpi_iqaudio_codec_hw_params(struct snd_pcm_substream *substream,
10451 + struct snd_pcm_hw_params *params)
10452 +{
10453 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
10454 + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
10455 + unsigned int samplerate = params_rate(params);
10456 +
10457 + switch (samplerate) {
10458 + case 8000:
10459 + case 16000:
10460 + case 32000:
10461 + case 48000:
10462 + case 96000:
10463 + pll_out = DA7213_PLL_FREQ_OUT_98304000;
10464 + break;
10465 + case 44100:
10466 + case 88200:
10467 + pll_out = DA7213_PLL_FREQ_OUT_90316800;
10468 + break;
10469 + default:
10470 + dev_err(rtd->dev,"Unsupported samplerate %d\n", samplerate);
10471 + return -EINVAL;
10472 + }
10473 +
10474 + return snd_soc_dai_set_pll(codec_dai, 0, DA7213_SYSCLK_PLL, 0, pll_out);
10475 +}
10476 +
10477 +static const struct snd_soc_ops snd_rpi_iqaudio_codec_ops = {
10478 + .hw_params = snd_rpi_iqaudio_codec_hw_params,
10479 +};
10480 +
10481 +SND_SOC_DAILINK_DEFS(rpi_iqaudio,
10482 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
10483 + DAILINK_COMP_ARRAY(COMP_CODEC("da7213.1-001a", "da7213-hifi")),
10484 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2835-i2s.0")));
10485 +
10486 +static struct snd_soc_dai_link snd_rpi_iqaudio_codec_dai[] = {
10487 +{
10488 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
10489 + SND_SOC_DAIFMT_CBM_CFM,
10490 + .init = snd_rpi_iqaudio_codec_init,
10491 + .ops = &snd_rpi_iqaudio_codec_ops,
10492 + .symmetric_rate = 1,
10493 + .symmetric_channels = 1,
10494 + .symmetric_sample_bits = 1,
10495 + SND_SOC_DAILINK_REG(rpi_iqaudio),
10496 +},
10497 +};
10498 +
10499 +/* audio machine driver */
10500 +static struct snd_soc_card snd_rpi_iqaudio_codec = {
10501 + .owner = THIS_MODULE,
10502 + .dai_link = snd_rpi_iqaudio_codec_dai,
10503 + .num_links = ARRAY_SIZE(snd_rpi_iqaudio_codec_dai),
10504 + .controls = dapm_controls,
10505 + .num_controls = ARRAY_SIZE(dapm_controls),
10506 + .dapm_widgets = dapm_widgets,
10507 + .num_dapm_widgets = ARRAY_SIZE(dapm_widgets),
10508 + .dapm_routes = audio_map,
10509 + .num_dapm_routes = ARRAY_SIZE(audio_map),
10510 +};
10511 +
10512 +static int snd_rpi_iqaudio_codec_probe(struct platform_device *pdev)
10513 +{
10514 + int ret = 0;
10515 +
10516 + snd_rpi_iqaudio_codec.dev = &pdev->dev;
10517 +
10518 + if (pdev->dev.of_node) {
10519 + struct device_node *i2s_node;
10520 + struct snd_soc_card *card = &snd_rpi_iqaudio_codec;
10521 + struct snd_soc_dai_link *dai = &snd_rpi_iqaudio_codec_dai[0];
10522 +
10523 + i2s_node = of_parse_phandle(pdev->dev.of_node,
10524 + "i2s-controller", 0);
10525 + if (i2s_node) {
10526 + dai->cpus->dai_name = NULL;
10527 + dai->cpus->of_node = i2s_node;
10528 + dai->platforms->name = NULL;
10529 + dai->platforms->of_node = i2s_node;
10530 + }
10531 +
10532 + if (of_property_read_string(pdev->dev.of_node, "card_name",
10533 + &card->name))
10534 + card->name = "IQaudIOCODEC";
10535 +
10536 + if (of_property_read_string(pdev->dev.of_node, "dai_name",
10537 + &dai->name))
10538 + dai->name = "IQaudIO CODEC";
10539 +
10540 + if (of_property_read_string(pdev->dev.of_node,
10541 + "dai_stream_name", &dai->stream_name))
10542 + dai->stream_name = "IQaudIO CODEC HiFi v1.2";
10543 +
10544 + }
10545 +
10546 + ret = snd_soc_register_card(&snd_rpi_iqaudio_codec);
10547 + if (ret) {
10548 + if (ret != -EPROBE_DEFER)
10549 + dev_err(&pdev->dev,
10550 + "snd_soc_register_card() failed: %d\n", ret);
10551 + return ret;
10552 + }
10553 +
10554 + return 0;
10555 +}
10556 +
10557 +static int snd_rpi_iqaudio_codec_remove(struct platform_device *pdev)
10558 +{
10559 + snd_soc_unregister_card(&snd_rpi_iqaudio_codec);
10560 + return 0;
10561 +}
10562 +
10563 +static const struct of_device_id iqaudio_of_match[] = {
10564 + { .compatible = "iqaudio,iqaudio-codec", },
10565 + {},
10566 +};
10567 +
10568 +MODULE_DEVICE_TABLE(of, iqaudio_of_match);
10569 +
10570 +static struct platform_driver snd_rpi_iqaudio_codec_driver = {
10571 + .driver = {
10572 + .name = "snd-rpi-iqaudio-codec",
10573 + .owner = THIS_MODULE,
10574 + .of_match_table = iqaudio_of_match,
10575 + },
10576 + .probe = snd_rpi_iqaudio_codec_probe,
10577 + .remove = snd_rpi_iqaudio_codec_remove,
10578 +};
10579 +
10580 +
10581 +
10582 +module_platform_driver(snd_rpi_iqaudio_codec_driver);
10583 +
10584 +MODULE_AUTHOR("Gordon Garrity <gordon@iqaudio.com>");
10585 +MODULE_DESCRIPTION("ASoC Driver for IQaudIO CODEC");
10586 +MODULE_LICENSE("GPL v2");
10587 --- /dev/null
10588 +++ b/sound/soc/bcm/iqaudio-dac.c
10589 @@ -0,0 +1,224 @@
10590 +/*
10591 + * ASoC Driver for IQaudIO DAC
10592 + *
10593 + * Author: Florian Meier <florian.meier@koalo.de>
10594 + * Copyright 2013
10595 + *
10596 + * This program is free software; you can redistribute it and/or
10597 + * modify it under the terms of the GNU General Public License
10598 + * version 2 as published by the Free Software Foundation.
10599 + *
10600 + * This program is distributed in the hope that it will be useful, but
10601 + * WITHOUT ANY WARRANTY; without even the implied warranty of
10602 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10603 + * General Public License for more details.
10604 + */
10605 +
10606 +#include <linux/module.h>
10607 +#include <linux/gpio/consumer.h>
10608 +#include <linux/platform_device.h>
10609 +
10610 +#include <sound/core.h>
10611 +#include <sound/pcm.h>
10612 +#include <sound/pcm_params.h>
10613 +#include <sound/soc.h>
10614 +#include <sound/jack.h>
10615 +
10616 +static bool digital_gain_0db_limit = true;
10617 +
10618 +static struct gpio_desc *mute_gpio;
10619 +
10620 +static int snd_rpi_iqaudio_dac_init(struct snd_soc_pcm_runtime *rtd)
10621 +{
10622 + if (digital_gain_0db_limit)
10623 + {
10624 + int ret;
10625 + struct snd_soc_card *card = rtd->card;
10626 +
10627 + ret = snd_soc_limit_volume(card, "Digital Playback Volume", 207);
10628 + if (ret < 0)
10629 + dev_warn(card->dev, "Failed to set volume limit: %d\n", ret);
10630 + }
10631 +
10632 + return 0;
10633 +}
10634 +
10635 +static void snd_rpi_iqaudio_gpio_mute(struct snd_soc_card *card)
10636 +{
10637 + if (mute_gpio) {
10638 + dev_info(card->dev, "%s: muting amp using GPIO22\n",
10639 + __func__);
10640 + gpiod_set_value_cansleep(mute_gpio, 0);
10641 + }
10642 +}
10643 +
10644 +static void snd_rpi_iqaudio_gpio_unmute(struct snd_soc_card *card)
10645 +{
10646 + if (mute_gpio) {
10647 + dev_info(card->dev, "%s: un-muting amp using GPIO22\n",
10648 + __func__);
10649 + gpiod_set_value_cansleep(mute_gpio, 1);
10650 + }
10651 +}
10652 +
10653 +static int snd_rpi_iqaudio_set_bias_level(struct snd_soc_card *card,
10654 + struct snd_soc_dapm_context *dapm, enum snd_soc_bias_level level)
10655 +{
10656 + struct snd_soc_pcm_runtime *rtd;
10657 + struct snd_soc_dai *codec_dai;
10658 +
10659 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
10660 + codec_dai = asoc_rtd_to_codec(rtd, 0);
10661 +
10662 + if (dapm->dev != codec_dai->dev)
10663 + return 0;
10664 +
10665 + switch (level) {
10666 + case SND_SOC_BIAS_PREPARE:
10667 + if (dapm->bias_level != SND_SOC_BIAS_STANDBY)
10668 + break;
10669 +
10670 + /* UNMUTE AMP */
10671 + snd_rpi_iqaudio_gpio_unmute(card);
10672 +
10673 + break;
10674 + case SND_SOC_BIAS_STANDBY:
10675 + if (dapm->bias_level != SND_SOC_BIAS_PREPARE)
10676 + break;
10677 +
10678 + /* MUTE AMP */
10679 + snd_rpi_iqaudio_gpio_mute(card);
10680 +
10681 + break;
10682 + default:
10683 + break;
10684 + }
10685 +
10686 + return 0;
10687 +}
10688 +
10689 +SND_SOC_DAILINK_DEFS(hifi,
10690 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
10691 + DAILINK_COMP_ARRAY(COMP_CODEC("pcm512x.1-004c", "pcm512x-hifi")),
10692 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
10693 +
10694 +static struct snd_soc_dai_link snd_rpi_iqaudio_dac_dai[] = {
10695 +{
10696 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
10697 + SND_SOC_DAIFMT_CBS_CFS,
10698 + .init = snd_rpi_iqaudio_dac_init,
10699 + SND_SOC_DAILINK_REG(hifi),
10700 +},
10701 +};
10702 +
10703 +/* audio machine driver */
10704 +static struct snd_soc_card snd_rpi_iqaudio_dac = {
10705 + .owner = THIS_MODULE,
10706 + .dai_link = snd_rpi_iqaudio_dac_dai,
10707 + .num_links = ARRAY_SIZE(snd_rpi_iqaudio_dac_dai),
10708 +};
10709 +
10710 +static int snd_rpi_iqaudio_dac_probe(struct platform_device *pdev)
10711 +{
10712 + int ret = 0;
10713 + bool gpio_unmute = false;
10714 +
10715 + snd_rpi_iqaudio_dac.dev = &pdev->dev;
10716 +
10717 + if (pdev->dev.of_node) {
10718 + struct device_node *i2s_node;
10719 + struct snd_soc_card *card = &snd_rpi_iqaudio_dac;
10720 + struct snd_soc_dai_link *dai = &snd_rpi_iqaudio_dac_dai[0];
10721 + bool auto_gpio_mute = false;
10722 +
10723 + i2s_node = of_parse_phandle(pdev->dev.of_node,
10724 + "i2s-controller", 0);
10725 + if (i2s_node) {
10726 + dai->cpus->dai_name = NULL;
10727 + dai->cpus->of_node = i2s_node;
10728 + dai->platforms->name = NULL;
10729 + dai->platforms->of_node = i2s_node;
10730 + }
10731 +
10732 + digital_gain_0db_limit = !of_property_read_bool(
10733 + pdev->dev.of_node, "iqaudio,24db_digital_gain");
10734 +
10735 + if (of_property_read_string(pdev->dev.of_node, "card_name",
10736 + &card->name))
10737 + card->name = "IQaudIODAC";
10738 +
10739 + if (of_property_read_string(pdev->dev.of_node, "dai_name",
10740 + &dai->name))
10741 + dai->name = "IQaudIO DAC";
10742 +
10743 + if (of_property_read_string(pdev->dev.of_node,
10744 + "dai_stream_name", &dai->stream_name))
10745 + dai->stream_name = "IQaudIO DAC HiFi";
10746 +
10747 + /* gpio_unmute - one time unmute amp using GPIO */
10748 + gpio_unmute = of_property_read_bool(pdev->dev.of_node,
10749 + "iqaudio-dac,unmute-amp");
10750 +
10751 + /* auto_gpio_mute - mute/unmute amp using GPIO */
10752 + auto_gpio_mute = of_property_read_bool(pdev->dev.of_node,
10753 + "iqaudio-dac,auto-mute-amp");
10754 +
10755 + if (auto_gpio_mute || gpio_unmute) {
10756 + mute_gpio = devm_gpiod_get_optional(&pdev->dev, "mute",
10757 + GPIOD_OUT_LOW);
10758 + if (IS_ERR(mute_gpio)) {
10759 + ret = PTR_ERR(mute_gpio);
10760 + dev_err(&pdev->dev,
10761 + "Failed to get mute gpio: %d\n", ret);
10762 + return ret;
10763 + }
10764 +
10765 + if (auto_gpio_mute && mute_gpio)
10766 + snd_rpi_iqaudio_dac.set_bias_level =
10767 + snd_rpi_iqaudio_set_bias_level;
10768 + }
10769 + }
10770 +
10771 + ret = snd_soc_register_card(&snd_rpi_iqaudio_dac);
10772 + if (ret) {
10773 + if (ret != -EPROBE_DEFER)
10774 + dev_err(&pdev->dev,
10775 + "snd_soc_register_card() failed: %d\n", ret);
10776 + return ret;
10777 + }
10778 +
10779 + if (gpio_unmute && mute_gpio)
10780 + snd_rpi_iqaudio_gpio_unmute(&snd_rpi_iqaudio_dac);
10781 +
10782 + return 0;
10783 +}
10784 +
10785 +static int snd_rpi_iqaudio_dac_remove(struct platform_device *pdev)
10786 +{
10787 + snd_rpi_iqaudio_gpio_mute(&snd_rpi_iqaudio_dac);
10788 +
10789 + snd_soc_unregister_card(&snd_rpi_iqaudio_dac);
10790 + return 0;
10791 +}
10792 +
10793 +static const struct of_device_id iqaudio_of_match[] = {
10794 + { .compatible = "iqaudio,iqaudio-dac", },
10795 + {},
10796 +};
10797 +MODULE_DEVICE_TABLE(of, iqaudio_of_match);
10798 +
10799 +static struct platform_driver snd_rpi_iqaudio_dac_driver = {
10800 + .driver = {
10801 + .name = "snd-rpi-iqaudio-dac",
10802 + .owner = THIS_MODULE,
10803 + .of_match_table = iqaudio_of_match,
10804 + },
10805 + .probe = snd_rpi_iqaudio_dac_probe,
10806 + .remove = snd_rpi_iqaudio_dac_remove,
10807 +};
10808 +
10809 +module_platform_driver(snd_rpi_iqaudio_dac_driver);
10810 +
10811 +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
10812 +MODULE_DESCRIPTION("ASoC Driver for IQAudio DAC");
10813 +MODULE_LICENSE("GPL v2");
10814 --- /dev/null
10815 +++ b/sound/soc/bcm/justboom-both.c
10816 @@ -0,0 +1,267 @@
10817 +// SPDX-License-Identifier: GPL-2.0
10818 +/*
10819 + * rpi--wm8804.c -- ALSA SoC Raspberry Pi soundcard.
10820 + *
10821 + * Authors: Johannes Krude <johannes@krude.de
10822 + *
10823 + * Driver for when connecting simultaneously justboom-digi and justboom-dac
10824 + *
10825 + * Based upon code from:
10826 + * justboom-digi.c
10827 + * by Milan Neskovic <info@justboom.co>
10828 + * justboom-dac.c
10829 + * by Milan Neskovic <info@justboom.co>
10830 + *
10831 + * This program is free software; you can redistribute it and/or
10832 + * modify it under the terms of the GNU General Public License
10833 + * version 2 as published by the Free Software Foundation.
10834 + *
10835 + * This program is distributed in the hope that it will be useful, but
10836 + * WITHOUT ANY WARRANTY; without even the implied warranty of
10837 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10838 + * General Public License for more details.
10839 + */
10840 +
10841 +#include <linux/module.h>
10842 +#include <linux/platform_device.h>
10843 +
10844 +#include <sound/core.h>
10845 +#include <sound/pcm.h>
10846 +#include <sound/pcm_params.h>
10847 +#include <sound/soc.h>
10848 +#include <sound/jack.h>
10849 +
10850 +#include "../codecs/wm8804.h"
10851 +#include "../codecs/pcm512x.h"
10852 +
10853 +
10854 +static bool digital_gain_0db_limit = true;
10855 +
10856 +static int snd_rpi_justboom_both_init(struct snd_soc_pcm_runtime *rtd)
10857 +{
10858 + struct snd_soc_component *digi = asoc_rtd_to_codec(rtd, 0)->component;
10859 + struct snd_soc_component *dac = asoc_rtd_to_codec(rtd, 1)->component;
10860 +
10861 + /* enable TX output */
10862 + snd_soc_component_update_bits(digi, WM8804_PWRDN, 0x4, 0x0);
10863 +
10864 + snd_soc_component_update_bits(dac, PCM512x_GPIO_EN, 0x08, 0x08);
10865 + snd_soc_component_update_bits(dac, PCM512x_GPIO_OUTPUT_4, 0xf, 0x02);
10866 + snd_soc_component_update_bits(dac, PCM512x_GPIO_CONTROL_1, 0x08, 0x08);
10867 +
10868 + if (digital_gain_0db_limit) {
10869 + int ret;
10870 + struct snd_soc_card *card = rtd->card;
10871 +
10872 + ret = snd_soc_limit_volume(card, "Digital Playback Volume",
10873 + 207);
10874 + if (ret < 0)
10875 + dev_warn(card->dev, "Failed to set volume limit: %d\n",
10876 + ret);
10877 + }
10878 +
10879 + return 0;
10880 +}
10881 +
10882 +static int snd_rpi_justboom_both_hw_params(struct snd_pcm_substream *substream,
10883 + struct snd_pcm_hw_params *params)
10884 +{
10885 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
10886 + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
10887 + struct snd_soc_component *digi = asoc_rtd_to_codec(rtd, 0)->component;
10888 + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
10889 +
10890 + int sysclk = 27000000; /* This is fixed on this board */
10891 +
10892 + long mclk_freq = 0;
10893 + int mclk_div = 1;
10894 + int sampling_freq = 1;
10895 +
10896 + int ret;
10897 +
10898 + int samplerate = params_rate(params);
10899 +
10900 + if (samplerate <= 96000) {
10901 + mclk_freq = samplerate*256;
10902 + mclk_div = WM8804_MCLKDIV_256FS;
10903 + } else {
10904 + mclk_freq = samplerate*128;
10905 + mclk_div = WM8804_MCLKDIV_128FS;
10906 + }
10907 +
10908 + switch (samplerate) {
10909 + case 32000:
10910 + sampling_freq = 0x03;
10911 + break;
10912 + case 44100:
10913 + sampling_freq = 0x00;
10914 + break;
10915 + case 48000:
10916 + sampling_freq = 0x02;
10917 + break;
10918 + case 88200:
10919 + sampling_freq = 0x08;
10920 + break;
10921 + case 96000:
10922 + sampling_freq = 0x0a;
10923 + break;
10924 + case 176400:
10925 + sampling_freq = 0x0c;
10926 + break;
10927 + case 192000:
10928 + sampling_freq = 0x0e;
10929 + break;
10930 + default:
10931 + dev_err(rtd->card->dev,
10932 + "Failed to set WM8804 SYSCLK, unsupported samplerate %d\n",
10933 + samplerate);
10934 + }
10935 +
10936 + snd_soc_dai_set_clkdiv(codec_dai, WM8804_MCLK_DIV, mclk_div);
10937 + snd_soc_dai_set_pll(codec_dai, 0, 0, sysclk, mclk_freq);
10938 +
10939 + ret = snd_soc_dai_set_sysclk(codec_dai, WM8804_TX_CLKSRC_PLL,
10940 + sysclk, SND_SOC_CLOCK_OUT);
10941 + if (ret < 0) {
10942 + dev_err(rtd->card->dev,
10943 + "Failed to set WM8804 SYSCLK: %d\n", ret);
10944 + return ret;
10945 + }
10946 +
10947 + /* Enable TX output */
10948 + snd_soc_component_update_bits(digi, WM8804_PWRDN, 0x4, 0x0);
10949 +
10950 + /* Power on */
10951 + snd_soc_component_update_bits(digi, WM8804_PWRDN, 0x9, 0);
10952 +
10953 + /* set sampling frequency status bits */
10954 + snd_soc_component_update_bits(digi, WM8804_SPDTX4, 0x0f, sampling_freq);
10955 +
10956 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 64);
10957 +}
10958 +
10959 +static int snd_rpi_justboom_both_startup(struct snd_pcm_substream *substream)
10960 +{
10961 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
10962 + struct snd_soc_component *digi = asoc_rtd_to_codec(rtd, 0)->component;
10963 + struct snd_soc_component *dac = asoc_rtd_to_codec(rtd, 1)->component;
10964 +
10965 + /* turn on digital output */
10966 + snd_soc_component_update_bits(digi, WM8804_PWRDN, 0x3c, 0x00);
10967 +
10968 + snd_soc_component_update_bits(dac, PCM512x_GPIO_CONTROL_1, 0x08, 0x08);
10969 +
10970 + return 0;
10971 +}
10972 +
10973 +static void snd_rpi_justboom_both_shutdown(struct snd_pcm_substream *substream)
10974 +{
10975 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
10976 + struct snd_soc_component *digi = asoc_rtd_to_codec(rtd, 0)->component;
10977 + struct snd_soc_component *dac = asoc_rtd_to_codec(rtd, 1)->component;
10978 +
10979 + snd_soc_component_update_bits(dac, PCM512x_GPIO_CONTROL_1, 0x08, 0x00);
10980 +
10981 + /* turn off output */
10982 + snd_soc_component_update_bits(digi, WM8804_PWRDN, 0x3c, 0x3c);
10983 +}
10984 +
10985 +/* machine stream operations */
10986 +static struct snd_soc_ops snd_rpi_justboom_both_ops = {
10987 + .hw_params = snd_rpi_justboom_both_hw_params,
10988 + .startup = snd_rpi_justboom_both_startup,
10989 + .shutdown = snd_rpi_justboom_both_shutdown,
10990 +};
10991 +
10992 +SND_SOC_DAILINK_DEFS(rpi_justboom_both,
10993 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
10994 + DAILINK_COMP_ARRAY(COMP_CODEC("pcm512x.1-004d", "pcm512x-hifi"),
10995 + COMP_CODEC("wm8804.1-003b", "wm8804-spdif")),
10996 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
10997 +
10998 +static struct snd_soc_dai_link snd_rpi_justboom_both_dai[] = {
10999 +{
11000 + .name = "JustBoom Digi",
11001 + .stream_name = "JustBoom Digi HiFi",
11002 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
11003 + SND_SOC_DAIFMT_CBM_CFM,
11004 + .ops = &snd_rpi_justboom_both_ops,
11005 + .init = snd_rpi_justboom_both_init,
11006 + SND_SOC_DAILINK_REG(rpi_justboom_both),
11007 +},
11008 +};
11009 +
11010 +/* audio machine driver */
11011 +static struct snd_soc_card snd_rpi_justboom_both = {
11012 + .name = "snd_rpi_justboom_both",
11013 + .driver_name = "JustBoomBoth",
11014 + .owner = THIS_MODULE,
11015 + .dai_link = snd_rpi_justboom_both_dai,
11016 + .num_links = ARRAY_SIZE(snd_rpi_justboom_both_dai),
11017 +};
11018 +
11019 +static int snd_rpi_justboom_both_probe(struct platform_device *pdev)
11020 +{
11021 + int ret = 0;
11022 + struct snd_soc_card *card = &snd_rpi_justboom_both;
11023 +
11024 + snd_rpi_justboom_both.dev = &pdev->dev;
11025 +
11026 + if (pdev->dev.of_node) {
11027 + struct device_node *i2s_node;
11028 + struct snd_soc_dai_link *dai = &snd_rpi_justboom_both_dai[0];
11029 +
11030 + i2s_node = of_parse_phandle(pdev->dev.of_node,
11031 + "i2s-controller", 0);
11032 +
11033 + if (i2s_node) {
11034 + int i;
11035 +
11036 + for (i = 0; i < card->num_links; i++) {
11037 + dai->cpus->dai_name = NULL;
11038 + dai->cpus->of_node = i2s_node;
11039 + dai->platforms->name = NULL;
11040 + dai->platforms->of_node = i2s_node;
11041 + }
11042 + }
11043 +
11044 + digital_gain_0db_limit = !of_property_read_bool(
11045 + pdev->dev.of_node, "justboom,24db_digital_gain");
11046 + }
11047 +
11048 + ret = snd_soc_register_card(card);
11049 + if (ret && ret != -EPROBE_DEFER) {
11050 + dev_err(&pdev->dev,
11051 + "snd_soc_register_card() failed: %d\n", ret);
11052 + }
11053 +
11054 + return ret;
11055 +}
11056 +
11057 +static int snd_rpi_justboom_both_remove(struct platform_device *pdev)
11058 +{
11059 + snd_soc_unregister_card(&snd_rpi_justboom_both);
11060 + return 0;
11061 +}
11062 +
11063 +static const struct of_device_id snd_rpi_justboom_both_of_match[] = {
11064 + { .compatible = "justboom,justboom-both", },
11065 + {},
11066 +};
11067 +MODULE_DEVICE_TABLE(of, snd_rpi_justboom_both_of_match);
11068 +
11069 +static struct platform_driver snd_rpi_justboom_both_driver = {
11070 + .driver = {
11071 + .name = "snd-rpi-justboom-both",
11072 + .owner = THIS_MODULE,
11073 + .of_match_table = snd_rpi_justboom_both_of_match,
11074 + },
11075 + .probe = snd_rpi_justboom_both_probe,
11076 + .remove = snd_rpi_justboom_both_remove,
11077 +};
11078 +
11079 +module_platform_driver(snd_rpi_justboom_both_driver);
11080 +
11081 +MODULE_AUTHOR("Johannes Krude <johannes@krude.de>");
11082 +MODULE_DESCRIPTION("ASoC Driver for simultaneous use of JustBoom PI Digi & DAC HAT Sound Cards");
11083 +MODULE_LICENSE("GPL v2");
11084 --- /dev/null
11085 +++ b/sound/soc/bcm/justboom-dac.c
11086 @@ -0,0 +1,147 @@
11087 +/*
11088 + * ASoC Driver for JustBoom DAC Raspberry Pi HAT Sound Card
11089 + *
11090 + * Author: Milan Neskovic
11091 + * Copyright 2016
11092 + * based on code by Daniel Matuschek <info@crazy-audio.com>
11093 + * based on code by Florian Meier <florian.meier@koalo.de>
11094 + *
11095 + * This program is free software; you can redistribute it and/or
11096 + * modify it under the terms of the GNU General Public License
11097 + * version 2 as published by the Free Software Foundation.
11098 + *
11099 + * This program is distributed in the hope that it will be useful, but
11100 + * WITHOUT ANY WARRANTY; without even the implied warranty of
11101 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11102 + * General Public License for more details.
11103 + */
11104 +
11105 +#include <linux/module.h>
11106 +#include <linux/platform_device.h>
11107 +
11108 +#include <sound/core.h>
11109 +#include <sound/pcm.h>
11110 +#include <sound/pcm_params.h>
11111 +#include <sound/soc.h>
11112 +#include <sound/jack.h>
11113 +
11114 +#include "../codecs/pcm512x.h"
11115 +
11116 +static bool digital_gain_0db_limit = true;
11117 +
11118 +static int snd_rpi_justboom_dac_init(struct snd_soc_pcm_runtime *rtd)
11119 +{
11120 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
11121 + snd_soc_component_update_bits(component, PCM512x_GPIO_EN, 0x08, 0x08);
11122 + snd_soc_component_update_bits(component, PCM512x_GPIO_OUTPUT_4, 0xf, 0x02);
11123 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x08,0x08);
11124 +
11125 + if (digital_gain_0db_limit)
11126 + {
11127 + int ret;
11128 + struct snd_soc_card *card = rtd->card;
11129 +
11130 + ret = snd_soc_limit_volume(card, "Digital Playback Volume", 207);
11131 + if (ret < 0)
11132 + dev_warn(card->dev, "Failed to set volume limit: %d\n", ret);
11133 + }
11134 +
11135 + return 0;
11136 +}
11137 +
11138 +static int snd_rpi_justboom_dac_startup(struct snd_pcm_substream *substream) {
11139 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
11140 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
11141 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x08,0x08);
11142 + return 0;
11143 +}
11144 +
11145 +static void snd_rpi_justboom_dac_shutdown(struct snd_pcm_substream *substream) {
11146 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
11147 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
11148 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x08,0x00);
11149 +}
11150 +
11151 +/* machine stream operations */
11152 +static struct snd_soc_ops snd_rpi_justboom_dac_ops = {
11153 + .startup = snd_rpi_justboom_dac_startup,
11154 + .shutdown = snd_rpi_justboom_dac_shutdown,
11155 +};
11156 +
11157 +SND_SOC_DAILINK_DEFS(hifi,
11158 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
11159 + DAILINK_COMP_ARRAY(COMP_CODEC("pcm512x.1-004d", "pcm512x-hifi")),
11160 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
11161 +
11162 +static struct snd_soc_dai_link snd_rpi_justboom_dac_dai[] = {
11163 +{
11164 + .name = "JustBoom DAC",
11165 + .stream_name = "JustBoom DAC HiFi",
11166 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
11167 + SND_SOC_DAIFMT_CBS_CFS,
11168 + .ops = &snd_rpi_justboom_dac_ops,
11169 + .init = snd_rpi_justboom_dac_init,
11170 + SND_SOC_DAILINK_REG(hifi),
11171 +},
11172 +};
11173 +
11174 +/* audio machine driver */
11175 +static struct snd_soc_card snd_rpi_justboom_dac = {
11176 + .name = "snd_rpi_justboom_dac",
11177 + .driver_name = "JustBoomDac",
11178 + .owner = THIS_MODULE,
11179 + .dai_link = snd_rpi_justboom_dac_dai,
11180 + .num_links = ARRAY_SIZE(snd_rpi_justboom_dac_dai),
11181 +};
11182 +
11183 +static int snd_rpi_justboom_dac_probe(struct platform_device *pdev)
11184 +{
11185 + int ret = 0;
11186 +
11187 + snd_rpi_justboom_dac.dev = &pdev->dev;
11188 +
11189 + if (pdev->dev.of_node) {
11190 + struct device_node *i2s_node;
11191 + struct snd_soc_dai_link *dai = &snd_rpi_justboom_dac_dai[0];
11192 + i2s_node = of_parse_phandle(pdev->dev.of_node,
11193 + "i2s-controller", 0);
11194 +
11195 + if (i2s_node) {
11196 + dai->cpus->dai_name = NULL;
11197 + dai->cpus->of_node = i2s_node;
11198 + dai->platforms->name = NULL;
11199 + dai->platforms->of_node = i2s_node;
11200 + }
11201 +
11202 + digital_gain_0db_limit = !of_property_read_bool(
11203 + pdev->dev.of_node, "justboom,24db_digital_gain");
11204 + }
11205 +
11206 + ret = devm_snd_soc_register_card(&pdev->dev, &snd_rpi_justboom_dac);
11207 + if (ret && ret != -EPROBE_DEFER)
11208 + dev_err(&pdev->dev,
11209 + "snd_soc_register_card() failed: %d\n", ret);
11210 +
11211 + return ret;
11212 +}
11213 +
11214 +static const struct of_device_id snd_rpi_justboom_dac_of_match[] = {
11215 + { .compatible = "justboom,justboom-dac", },
11216 + {},
11217 +};
11218 +MODULE_DEVICE_TABLE(of, snd_rpi_justboom_dac_of_match);
11219 +
11220 +static struct platform_driver snd_rpi_justboom_dac_driver = {
11221 + .driver = {
11222 + .name = "snd-rpi-justboom-dac",
11223 + .owner = THIS_MODULE,
11224 + .of_match_table = snd_rpi_justboom_dac_of_match,
11225 + },
11226 + .probe = snd_rpi_justboom_dac_probe,
11227 +};
11228 +
11229 +module_platform_driver(snd_rpi_justboom_dac_driver);
11230 +
11231 +MODULE_AUTHOR("Milan Neskovic <info@justboom.co>");
11232 +MODULE_DESCRIPTION("ASoC Driver for JustBoom PI DAC HAT Sound Card");
11233 +MODULE_LICENSE("GPL v2");
11234 --- /dev/null
11235 +++ b/sound/soc/bcm/pifi-40.c
11236 @@ -0,0 +1,284 @@
11237 +// SPDX-License-Identifier: GPL-2.0-only
11238 +/*
11239 + * ALSA ASoC Machine Driver for PiFi-40
11240 + *
11241 + * Author: David Knell <david.knell@gmail.com)
11242 + * based on code by Daniel Matuschek <info@crazy-audio.com>
11243 + * based on code by Florian Meier <florian.meier@koalo.de>
11244 + * Copyright (C) 2020
11245 + *
11246 + * This program is free software; you can redistribute it and/or
11247 + * modify it under the terms of the GNU General Public License
11248 + * version 2 as published by the Free Software Foundation.
11249 + *
11250 + * This program is distributed in the hope that it will be useful, but
11251 + * WITHOUT ANY WARRANTY; without even the implied warranty of
11252 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11253 + * General Public License for more details.
11254 + */
11255 +
11256 +#include <linux/module.h>
11257 +#include <linux/platform_device.h>
11258 +#include <linux/gpio/consumer.h>
11259 +#include <sound/core.h>
11260 +#include <sound/pcm.h>
11261 +#include <sound/pcm_params.h>
11262 +#include <sound/soc.h>
11263 +#include <linux/firmware.h>
11264 +#include <linux/delay.h>
11265 +#include <sound/tlv.h>
11266 +
11267 +static struct gpio_desc *pdn_gpio;
11268 +static int vol = 0x30;
11269 +
11270 +// Volume control
11271 +static int pifi_40_vol_get(struct snd_kcontrol *kcontrol,
11272 + struct snd_ctl_elem_value *ucontrol)
11273 +{
11274 + ucontrol->value.integer.value[0] = vol;
11275 + ucontrol->value.integer.value[1] = vol;
11276 + return 0;
11277 +}
11278 +
11279 +static int pifi_40_vol_set(struct snd_kcontrol *kcontrol,
11280 + struct snd_ctl_elem_value *ucontrol)
11281 +{
11282 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
11283 + struct snd_soc_pcm_runtime *rtd;
11284 + unsigned int v = ucontrol->value.integer.value[0];
11285 + struct snd_soc_component *dac[2];
11286 +
11287 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
11288 + dac[0] = asoc_rtd_to_codec(rtd, 0)->component;
11289 + dac[1] = asoc_rtd_to_codec(rtd, 1)->component;
11290 +
11291 + snd_soc_component_write(dac[0], 0x07, 255 - v);
11292 + snd_soc_component_write(dac[1], 0x07, 255 - v);
11293 +
11294 + vol = v;
11295 + return 1;
11296 +}
11297 +
11298 +static const DECLARE_TLV_DB_SCALE(digital_tlv_master, -10350, 50, 1);
11299 +static const struct snd_kcontrol_new pifi_40_controls[] = {
11300 + SOC_DOUBLE_R_EXT_TLV("Master Volume", 0x00, 0x01,
11301 + 0x00, // Min
11302 + 0xff, // Max
11303 + 0x01, // Invert
11304 + pifi_40_vol_get, pifi_40_vol_set,
11305 + digital_tlv_master)
11306 +};
11307 +
11308 +static const char * const codec_ctl_pfx[] = { "Left", "Right" };
11309 +
11310 +static const char * const codec_ctl_name[] = { "Master Volume",
11311 + "Speaker Volume",
11312 + "Speaker Switch" };
11313 +
11314 +static int snd_pifi_40_init(struct snd_soc_pcm_runtime *rtd)
11315 +{
11316 + struct snd_soc_card *card = rtd->card;
11317 + struct snd_soc_component *dac[2];
11318 + struct snd_kcontrol *kctl;
11319 + int i, j;
11320 +
11321 + dac[0] = asoc_rtd_to_codec(rtd, 0)->component;
11322 + dac[1] = asoc_rtd_to_codec(rtd, 1)->component;
11323 +
11324 +
11325 + // Set up cards - pulse power down first
11326 + gpiod_set_value_cansleep(pdn_gpio, 1);
11327 + usleep_range(1000, 10000);
11328 + gpiod_set_value_cansleep(pdn_gpio, 0);
11329 + usleep_range(20000, 30000);
11330 +
11331 + // Oscillator trim
11332 + snd_soc_component_write(dac[0], 0x1b, 0);
11333 + snd_soc_component_write(dac[1], 0x1b, 0);
11334 + usleep_range(60000, 80000);
11335 +
11336 + // Common setup
11337 + for (i = 0; i < 2; i++) {
11338 + // MCLK at 64fs, sample rate 44.1 or 48kHz
11339 + snd_soc_component_write(dac[i], 0x00, 0x60);
11340 +
11341 + // Set up for PBTL
11342 + snd_soc_component_write(dac[i], 0x19, 0x3A);
11343 + snd_soc_component_write(dac[i], 0x25, 0x01103245);
11344 +
11345 + // Master vol to -10db
11346 + snd_soc_component_write(dac[i], 0x07, 0x44);
11347 + }
11348 + // Inputs set to L and R respectively
11349 + snd_soc_component_write(dac[0], 0x20, 0x00017772);
11350 + snd_soc_component_write(dac[1], 0x20, 0x00107772);
11351 +
11352 + // Remove codec controls
11353 + for (i = 0; i < 2; i++) {
11354 + for (j = 0; j < 3; j++) {
11355 + char cname[256];
11356 +
11357 + sprintf(cname, "%s %s", codec_ctl_pfx[i],
11358 + codec_ctl_name[j]);
11359 + kctl = snd_soc_card_get_kcontrol(card, cname);
11360 + if (!kctl) {
11361 + pr_info("Control %s not found\n",
11362 + cname);
11363 + } else {
11364 + kctl->vd[0].access =
11365 + SNDRV_CTL_ELEM_ACCESS_READWRITE;
11366 + snd_ctl_remove(card->snd_card, kctl);
11367 + }
11368 + }
11369 + }
11370 +
11371 + return 0;
11372 +}
11373 +
11374 +static int snd_pifi_40_hw_params(struct snd_pcm_substream *substream,
11375 + struct snd_pcm_hw_params *params)
11376 +{
11377 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
11378 + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
11379 + unsigned int sample_bits;
11380 +
11381 + sample_bits = snd_pcm_format_physical_width(params_format(params));
11382 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 64);
11383 +}
11384 +
11385 +static struct snd_soc_ops snd_pifi_40_ops = { .hw_params =
11386 + snd_pifi_40_hw_params };
11387 +
11388 +static struct snd_soc_dai_link_component pifi_40_codecs[] = {
11389 + {
11390 + .dai_name = "tas571x-hifi",
11391 + },
11392 + {
11393 + .dai_name = "tas571x-hifi",
11394 + },
11395 +};
11396 +
11397 +SND_SOC_DAILINK_DEFS(
11398 + pifi_40_dai, DAILINK_COMP_ARRAY(COMP_EMPTY()),
11399 + DAILINK_COMP_ARRAY(COMP_CODEC("tas571x.1-001a", "tas571x-hifi"),
11400 + COMP_CODEC("tas571x.1-001b", "tas571x-hifi")),
11401 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
11402 +
11403 +static struct snd_soc_dai_link snd_pifi_40_dai[] = {
11404 + {
11405 + .name = "PiFi40",
11406 + .stream_name = "PiFi40",
11407 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
11408 + SND_SOC_DAIFMT_CBS_CFS,
11409 + .ops = &snd_pifi_40_ops,
11410 + .init = snd_pifi_40_init,
11411 + SND_SOC_DAILINK_REG(pifi_40_dai),
11412 + },
11413 +};
11414 +
11415 +// Machine driver
11416 +static struct snd_soc_card snd_pifi_40 = {
11417 + .name = "PiFi40",
11418 + .owner = THIS_MODULE,
11419 + .dai_link = snd_pifi_40_dai,
11420 + .num_links = ARRAY_SIZE(snd_pifi_40_dai),
11421 + .controls = pifi_40_controls,
11422 + .num_controls = ARRAY_SIZE(pifi_40_controls)
11423 +};
11424 +
11425 +static void snd_pifi_40_pdn(struct snd_soc_card *card, int on)
11426 +{
11427 + if (pdn_gpio)
11428 + gpiod_set_value_cansleep(pdn_gpio, on ? 0 : 1);
11429 +}
11430 +
11431 +static int snd_pifi_40_probe(struct platform_device *pdev)
11432 +{
11433 + struct snd_soc_card *card = &snd_pifi_40;
11434 + int ret = 0, i = 0;
11435 +
11436 + card->dev = &pdev->dev;
11437 + platform_set_drvdata(pdev, &snd_pifi_40);
11438 +
11439 + if (pdev->dev.of_node) {
11440 + struct device_node *i2s_node;
11441 + struct snd_soc_dai_link *dai;
11442 +
11443 + dai = &snd_pifi_40_dai[0];
11444 + i2s_node = of_parse_phandle(pdev->dev.of_node, "i2s-controller",
11445 + 0);
11446 + if (i2s_node) {
11447 + for (i = 0; i < card->num_links; i++) {
11448 + dai->cpus->dai_name = NULL;
11449 + dai->cpus->of_node = i2s_node;
11450 + dai->platforms->name = NULL;
11451 + dai->platforms->of_node = i2s_node;
11452 + }
11453 + }
11454 +
11455 + pifi_40_codecs[0].of_node =
11456 + of_parse_phandle(pdev->dev.of_node, "audio-codec", 0);
11457 + pifi_40_codecs[1].of_node =
11458 + of_parse_phandle(pdev->dev.of_node, "audio-codec", 1);
11459 + if (!pifi_40_codecs[0].of_node || !pifi_40_codecs[1].of_node) {
11460 + dev_err(&pdev->dev,
11461 + "Property 'audio-codec' missing or invalid\n");
11462 + return -EINVAL;
11463 + }
11464 +
11465 + pdn_gpio = devm_gpiod_get_optional(&pdev->dev, "pdn",
11466 + GPIOD_OUT_LOW);
11467 + if (IS_ERR(pdn_gpio)) {
11468 + ret = PTR_ERR(pdn_gpio);
11469 + dev_err(&pdev->dev, "failed to get pdn gpio: %d\n",
11470 + ret);
11471 + return ret;
11472 + }
11473 +
11474 + ret = snd_soc_register_card(&snd_pifi_40);
11475 + if (ret < 0) {
11476 + dev_err(&pdev->dev,
11477 + "snd_soc_register_card() failed: %d\n", ret);
11478 + return ret;
11479 + }
11480 +
11481 + return 0;
11482 + }
11483 +
11484 + return -EINVAL;
11485 +}
11486 +
11487 +static int snd_pifi_40_remove(struct platform_device *pdev)
11488 +{
11489 + struct snd_soc_card *card = platform_get_drvdata(pdev);
11490 +
11491 + kfree(&card->drvdata);
11492 + snd_pifi_40_pdn(&snd_pifi_40, 0);
11493 + snd_soc_unregister_card(&snd_pifi_40);
11494 + return 0;
11495 +}
11496 +
11497 +static const struct of_device_id snd_pifi_40_of_match[] = {
11498 + {
11499 + .compatible = "pifi,pifi-40",
11500 + },
11501 + { /* sentinel */ },
11502 +};
11503 +
11504 +MODULE_DEVICE_TABLE(of, snd_pifi_40_of_match);
11505 +
11506 +static struct platform_driver snd_pifi_40_driver = {
11507 + .driver = {
11508 + .name = "snd-pifi-40",
11509 + .owner = THIS_MODULE,
11510 + .of_match_table = snd_pifi_40_of_match,
11511 + },
11512 + .probe = snd_pifi_40_probe,
11513 + .remove = snd_pifi_40_remove,
11514 +};
11515 +
11516 +module_platform_driver(snd_pifi_40_driver);
11517 +
11518 +MODULE_AUTHOR("David Knell <david.knell@gmail.com>");
11519 +MODULE_DESCRIPTION("ALSA ASoC Machine Driver for PiFi-40");
11520 +MODULE_LICENSE("GPL v2");
11521 --- /dev/null
11522 +++ b/sound/soc/bcm/pisound.c
11523 @@ -0,0 +1,1241 @@
11524 +/*
11525 + * Pisound Linux kernel module.
11526 + * Copyright (C) 2016-2020 Vilniaus Blokas UAB, https://blokas.io/pisound
11527 + *
11528 + * This program is free software; you can redistribute it and/or
11529 + * modify it under the terms of the GNU General Public License
11530 + * as published by the Free Software Foundation; version 2 of the
11531 + * License.
11532 + *
11533 + * This program is distributed in the hope that it will be useful,
11534 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11535 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11536 + * GNU General Public License for more details.
11537 + *
11538 + * You should have received a copy of the GNU General Public License
11539 + * along with this program; if not, write to the Free Software
11540 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
11541 + * MA 02110-1301, USA.
11542 + */
11543 +
11544 +#include <linux/init.h>
11545 +#include <linux/module.h>
11546 +#include <linux/platform_device.h>
11547 +#include <linux/gpio.h>
11548 +#include <linux/kobject.h>
11549 +#include <linux/sysfs.h>
11550 +#include <linux/delay.h>
11551 +#include <linux/spi/spi.h>
11552 +#include <linux/interrupt.h>
11553 +#include <linux/kfifo.h>
11554 +#include <linux/jiffies.h>
11555 +
11556 +#include <sound/core.h>
11557 +#include <sound/pcm.h>
11558 +#include <sound/pcm_params.h>
11559 +#include <sound/soc.h>
11560 +#include <sound/jack.h>
11561 +#include <sound/rawmidi.h>
11562 +#include <sound/asequencer.h>
11563 +#include <sound/control.h>
11564 +
11565 +static int pisnd_spi_init(struct device *dev);
11566 +static void pisnd_spi_uninit(void);
11567 +
11568 +static void pisnd_spi_flush(void);
11569 +static void pisnd_spi_start(void);
11570 +static uint8_t pisnd_spi_recv(uint8_t *buffer, uint8_t length);
11571 +
11572 +typedef void (*pisnd_spi_recv_cb)(void *data);
11573 +static void pisnd_spi_set_callback(pisnd_spi_recv_cb cb, void *data);
11574 +
11575 +static const char *pisnd_spi_get_serial(void);
11576 +static const char *pisnd_spi_get_id(void);
11577 +static const char *pisnd_spi_get_fw_version(void);
11578 +static const char *pisnd_spi_get_hw_version(void);
11579 +
11580 +static int pisnd_midi_init(struct snd_card *card);
11581 +static void pisnd_midi_uninit(void);
11582 +
11583 +enum task_e {
11584 + TASK_PROCESS = 0,
11585 +};
11586 +
11587 +static void pisnd_schedule_process(enum task_e task);
11588 +
11589 +#define PISOUND_LOG_PREFIX "pisound: "
11590 +
11591 +#ifdef PISOUND_DEBUG
11592 +# define printd(...) pr_alert(PISOUND_LOG_PREFIX __VA_ARGS__)
11593 +#else
11594 +# define printd(...) do {} while (0)
11595 +#endif
11596 +
11597 +#define printe(...) pr_err(PISOUND_LOG_PREFIX __VA_ARGS__)
11598 +#define printi(...) pr_info(PISOUND_LOG_PREFIX __VA_ARGS__)
11599 +
11600 +static struct snd_rawmidi *g_rmidi;
11601 +static struct snd_rawmidi_substream *g_midi_output_substream;
11602 +
11603 +static int pisnd_output_open(struct snd_rawmidi_substream *substream)
11604 +{
11605 + g_midi_output_substream = substream;
11606 + return 0;
11607 +}
11608 +
11609 +static int pisnd_output_close(struct snd_rawmidi_substream *substream)
11610 +{
11611 + g_midi_output_substream = NULL;
11612 + return 0;
11613 +}
11614 +
11615 +static void pisnd_output_trigger(
11616 + struct snd_rawmidi_substream *substream,
11617 + int up
11618 + )
11619 +{
11620 + if (substream != g_midi_output_substream) {
11621 + printe("MIDI output trigger called for an unexpected stream!");
11622 + return;
11623 + }
11624 +
11625 + if (!up)
11626 + return;
11627 +
11628 + pisnd_spi_start();
11629 +}
11630 +
11631 +static void pisnd_output_drain(struct snd_rawmidi_substream *substream)
11632 +{
11633 + pisnd_spi_flush();
11634 +}
11635 +
11636 +static int pisnd_input_open(struct snd_rawmidi_substream *substream)
11637 +{
11638 + return 0;
11639 +}
11640 +
11641 +static int pisnd_input_close(struct snd_rawmidi_substream *substream)
11642 +{
11643 + return 0;
11644 +}
11645 +
11646 +static void pisnd_midi_recv_callback(void *substream)
11647 +{
11648 + uint8_t data[128];
11649 + uint8_t n = 0;
11650 +
11651 + while ((n = pisnd_spi_recv(data, sizeof(data)))) {
11652 + int res = snd_rawmidi_receive(substream, data, n);
11653 + (void)res;
11654 + printd("midi recv %u bytes, res = %d\n", n, res);
11655 + }
11656 +}
11657 +
11658 +static void pisnd_input_trigger(struct snd_rawmidi_substream *substream, int up)
11659 +{
11660 + if (up) {
11661 + pisnd_spi_set_callback(pisnd_midi_recv_callback, substream);
11662 + pisnd_schedule_process(TASK_PROCESS);
11663 + } else {
11664 + pisnd_spi_set_callback(NULL, NULL);
11665 + }
11666 +}
11667 +
11668 +static struct snd_rawmidi_ops pisnd_output_ops = {
11669 + .open = pisnd_output_open,
11670 + .close = pisnd_output_close,
11671 + .trigger = pisnd_output_trigger,
11672 + .drain = pisnd_output_drain,
11673 +};
11674 +
11675 +static struct snd_rawmidi_ops pisnd_input_ops = {
11676 + .open = pisnd_input_open,
11677 + .close = pisnd_input_close,
11678 + .trigger = pisnd_input_trigger,
11679 +};
11680 +
11681 +static void pisnd_get_port_info(
11682 + struct snd_rawmidi *rmidi,
11683 + int number,
11684 + struct snd_seq_port_info *seq_port_info
11685 + )
11686 +{
11687 + seq_port_info->type =
11688 + SNDRV_SEQ_PORT_TYPE_MIDI_GENERIC |
11689 + SNDRV_SEQ_PORT_TYPE_HARDWARE |
11690 + SNDRV_SEQ_PORT_TYPE_PORT;
11691 + seq_port_info->midi_voices = 0;
11692 +}
11693 +
11694 +static struct snd_rawmidi_global_ops pisnd_global_ops = {
11695 + .get_port_info = pisnd_get_port_info,
11696 +};
11697 +
11698 +static int pisnd_midi_init(struct snd_card *card)
11699 +{
11700 + int err;
11701 +
11702 + g_midi_output_substream = NULL;
11703 +
11704 + err = snd_rawmidi_new(card, "pisound MIDI", 0, 1, 1, &g_rmidi);
11705 +
11706 + if (err < 0) {
11707 + printe("snd_rawmidi_new failed: %d\n", err);
11708 + return err;
11709 + }
11710 +
11711 + strcpy(g_rmidi->name, "pisound MIDI ");
11712 + strcat(g_rmidi->name, pisnd_spi_get_serial());
11713 +
11714 + g_rmidi->info_flags =
11715 + SNDRV_RAWMIDI_INFO_OUTPUT |
11716 + SNDRV_RAWMIDI_INFO_INPUT |
11717 + SNDRV_RAWMIDI_INFO_DUPLEX;
11718 +
11719 + g_rmidi->ops = &pisnd_global_ops;
11720 +
11721 + g_rmidi->private_data = (void *)0;
11722 +
11723 + snd_rawmidi_set_ops(
11724 + g_rmidi,
11725 + SNDRV_RAWMIDI_STREAM_OUTPUT,
11726 + &pisnd_output_ops
11727 + );
11728 +
11729 + snd_rawmidi_set_ops(
11730 + g_rmidi,
11731 + SNDRV_RAWMIDI_STREAM_INPUT,
11732 + &pisnd_input_ops
11733 + );
11734 +
11735 + return 0;
11736 +}
11737 +
11738 +static void pisnd_midi_uninit(void)
11739 +{
11740 +}
11741 +
11742 +static void *g_recvData;
11743 +static pisnd_spi_recv_cb g_recvCallback;
11744 +
11745 +#define FIFO_SIZE 4096
11746 +
11747 +static char g_serial_num[11];
11748 +static char g_id[25];
11749 +enum { MAX_VERSION_STR_LEN = 6 };
11750 +static char g_fw_version[MAX_VERSION_STR_LEN];
11751 +static char g_hw_version[MAX_VERSION_STR_LEN];
11752 +
11753 +static uint8_t g_ledFlashDuration;
11754 +static bool g_ledFlashDurationChanged;
11755 +
11756 +DEFINE_KFIFO(spi_fifo_in, uint8_t, FIFO_SIZE);
11757 +DEFINE_KFIFO(spi_fifo_out, uint8_t, FIFO_SIZE);
11758 +
11759 +static struct gpio_desc *data_available;
11760 +static struct gpio_desc *spi_reset;
11761 +
11762 +static struct spi_device *pisnd_spi_device;
11763 +
11764 +static struct workqueue_struct *pisnd_workqueue;
11765 +static struct work_struct pisnd_work_process;
11766 +
11767 +static void pisnd_work_handler(struct work_struct *work);
11768 +
11769 +static void spi_transfer(const uint8_t *txbuf, uint8_t *rxbuf, int len);
11770 +static uint16_t spi_transfer16(uint16_t val);
11771 +
11772 +static int pisnd_init_workqueues(void)
11773 +{
11774 + pisnd_workqueue = create_singlethread_workqueue("pisnd_workqueue");
11775 + INIT_WORK(&pisnd_work_process, pisnd_work_handler);
11776 +
11777 + return 0;
11778 +}
11779 +
11780 +static void pisnd_uninit_workqueues(void)
11781 +{
11782 + flush_workqueue(pisnd_workqueue);
11783 + destroy_workqueue(pisnd_workqueue);
11784 +
11785 + pisnd_workqueue = NULL;
11786 +}
11787 +
11788 +static bool pisnd_spi_has_more(void)
11789 +{
11790 + return gpiod_get_value(data_available);
11791 +}
11792 +
11793 +static void pisnd_schedule_process(enum task_e task)
11794 +{
11795 + if (pisnd_spi_device != NULL &&
11796 + pisnd_workqueue != NULL &&
11797 + !work_pending(&pisnd_work_process)
11798 + ) {
11799 + printd("schedule: has more = %d\n", pisnd_spi_has_more());
11800 + if (task == TASK_PROCESS)
11801 + queue_work(pisnd_workqueue, &pisnd_work_process);
11802 + }
11803 +}
11804 +
11805 +static irqreturn_t data_available_interrupt_handler(int irq, void *dev_id)
11806 +{
11807 + if (irq == gpiod_to_irq(data_available) && pisnd_spi_has_more()) {
11808 + printd("schedule from irq\n");
11809 + pisnd_schedule_process(TASK_PROCESS);
11810 + }
11811 +
11812 + return IRQ_HANDLED;
11813 +}
11814 +
11815 +static uint16_t spi_transfer16(uint16_t val)
11816 +{
11817 + uint8_t txbuf[2];
11818 + uint8_t rxbuf[2];
11819 +
11820 + if (!pisnd_spi_device) {
11821 + printe("pisnd_spi_device null, returning\n");
11822 + return 0;
11823 + }
11824 +
11825 + txbuf[0] = val >> 8;
11826 + txbuf[1] = val & 0xff;
11827 +
11828 + spi_transfer(txbuf, rxbuf, sizeof(txbuf));
11829 +
11830 + printd("received: %02x%02x\n", rxbuf[0], rxbuf[1]);
11831 +
11832 + return (rxbuf[0] << 8) | rxbuf[1];
11833 +}
11834 +
11835 +static void spi_transfer(const uint8_t *txbuf, uint8_t *rxbuf, int len)
11836 +{
11837 + int err;
11838 + struct spi_transfer transfer;
11839 + struct spi_message msg;
11840 +
11841 + memset(rxbuf, 0, len);
11842 +
11843 + if (!pisnd_spi_device) {
11844 + printe("pisnd_spi_device null, returning\n");
11845 + return;
11846 + }
11847 +
11848 + spi_message_init(&msg);
11849 +
11850 + memset(&transfer, 0, sizeof(transfer));
11851 +
11852 + transfer.tx_buf = txbuf;
11853 + transfer.rx_buf = rxbuf;
11854 + transfer.len = len;
11855 + transfer.speed_hz = 150000;
11856 + transfer.delay.value = 10;
11857 + transfer.delay.unit = SPI_DELAY_UNIT_USECS;
11858 +
11859 + spi_message_add_tail(&transfer, &msg);
11860 +
11861 + err = spi_sync(pisnd_spi_device, &msg);
11862 +
11863 + if (err < 0) {
11864 + printe("spi_sync error %d\n", err);
11865 + return;
11866 + }
11867 +
11868 + printd("hasMore %d\n", pisnd_spi_has_more());
11869 +}
11870 +
11871 +static int spi_read_bytes(char *dst, size_t length, uint8_t *bytesRead)
11872 +{
11873 + uint16_t rx;
11874 + uint8_t size;
11875 + uint8_t i;
11876 +
11877 + memset(dst, 0, length);
11878 + *bytesRead = 0;
11879 +
11880 + rx = spi_transfer16(0);
11881 + if (!(rx >> 8))
11882 + return -EINVAL;
11883 +
11884 + size = rx & 0xff;
11885 +
11886 + if (size > length)
11887 + return -EINVAL;
11888 +
11889 + for (i = 0; i < size; ++i) {
11890 + rx = spi_transfer16(0);
11891 + if (!(rx >> 8))
11892 + return -EINVAL;
11893 +
11894 + dst[i] = rx & 0xff;
11895 + }
11896 +
11897 + *bytesRead = i;
11898 +
11899 + return 0;
11900 +}
11901 +
11902 +static int spi_device_match(struct device *dev, const void *data)
11903 +{
11904 + struct spi_device *spi = container_of(dev, struct spi_device, dev);
11905 +
11906 + printd(" %s %s %dkHz %d bits mode=0x%02X\n",
11907 + spi->modalias, dev_name(dev), spi->max_speed_hz/1000,
11908 + spi->bits_per_word, spi->mode);
11909 +
11910 + if (strcmp("pisound-spi", spi->modalias) == 0) {
11911 + printi("\tFound!\n");
11912 + return 1;
11913 + }
11914 +
11915 + printe("\tNot found!\n");
11916 + return 0;
11917 +}
11918 +
11919 +static struct spi_device *pisnd_spi_find_device(void)
11920 +{
11921 + struct device *dev;
11922 +
11923 + printi("Searching for spi device...\n");
11924 + dev = bus_find_device(&spi_bus_type, NULL, NULL, spi_device_match);
11925 + if (dev != NULL)
11926 + return container_of(dev, struct spi_device, dev);
11927 + else
11928 + return NULL;
11929 +}
11930 +
11931 +static void pisnd_work_handler(struct work_struct *work)
11932 +{
11933 + enum { TRANSFER_SIZE = 4 };
11934 + enum { PISOUND_OUTPUT_BUFFER_SIZE_MILLIBYTES = 127 * 1000 };
11935 + enum { MIDI_MILLIBYTES_PER_JIFFIE = (3125 * 1000) / HZ };
11936 + int out_buffer_used_millibytes = 0;
11937 + unsigned long now;
11938 + uint8_t val;
11939 + uint8_t txbuf[TRANSFER_SIZE];
11940 + uint8_t rxbuf[TRANSFER_SIZE];
11941 + uint8_t midibuf[TRANSFER_SIZE];
11942 + int i, n;
11943 + bool had_data;
11944 +
11945 + unsigned long last_transfer_at = jiffies;
11946 +
11947 + if (work == &pisnd_work_process) {
11948 + if (pisnd_spi_device == NULL)
11949 + return;
11950 +
11951 + do {
11952 + if (g_midi_output_substream &&
11953 + kfifo_avail(&spi_fifo_out) >= sizeof(midibuf)) {
11954 +
11955 + n = snd_rawmidi_transmit_peek(
11956 + g_midi_output_substream,
11957 + midibuf, sizeof(midibuf)
11958 + );
11959 +
11960 + if (n > 0) {
11961 + for (i = 0; i < n; ++i)
11962 + kfifo_put(
11963 + &spi_fifo_out,
11964 + midibuf[i]
11965 + );
11966 + snd_rawmidi_transmit_ack(
11967 + g_midi_output_substream,
11968 + i
11969 + );
11970 + }
11971 + }
11972 +
11973 + had_data = false;
11974 + memset(txbuf, 0, sizeof(txbuf));
11975 + for (i = 0; i < sizeof(txbuf) &&
11976 + ((out_buffer_used_millibytes+1000 <
11977 + PISOUND_OUTPUT_BUFFER_SIZE_MILLIBYTES) ||
11978 + g_ledFlashDurationChanged);
11979 + i += 2) {
11980 +
11981 + val = 0;
11982 +
11983 + if (g_ledFlashDurationChanged) {
11984 + txbuf[i+0] = 0xf0;
11985 + txbuf[i+1] = g_ledFlashDuration;
11986 + g_ledFlashDuration = 0;
11987 + g_ledFlashDurationChanged = false;
11988 + } else if (kfifo_get(&spi_fifo_out, &val)) {
11989 + txbuf[i+0] = 0x0f;
11990 + txbuf[i+1] = val;
11991 + out_buffer_used_millibytes += 1000;
11992 + }
11993 + }
11994 +
11995 + spi_transfer(txbuf, rxbuf, sizeof(txbuf));
11996 + /* Estimate the Pisound's MIDI output buffer usage, so
11997 + * that we don't overflow it. Space in the buffer should
11998 + * be becoming available at the UART MIDI byte transfer
11999 + * rate.
12000 + */
12001 + now = jiffies;
12002 + if (now != last_transfer_at) {
12003 + out_buffer_used_millibytes -=
12004 + (now - last_transfer_at) *
12005 + MIDI_MILLIBYTES_PER_JIFFIE;
12006 + if (out_buffer_used_millibytes < 0)
12007 + out_buffer_used_millibytes = 0;
12008 + last_transfer_at = now;
12009 + }
12010 +
12011 + for (i = 0; i < sizeof(rxbuf); i += 2) {
12012 + if (rxbuf[i]) {
12013 + kfifo_put(&spi_fifo_in, rxbuf[i+1]);
12014 + if (kfifo_len(&spi_fifo_in) > 16 &&
12015 + g_recvCallback)
12016 + g_recvCallback(g_recvData);
12017 + had_data = true;
12018 + }
12019 + }
12020 + } while (had_data
12021 + || !kfifo_is_empty(&spi_fifo_out)
12022 + || pisnd_spi_has_more()
12023 + || g_ledFlashDurationChanged
12024 + || out_buffer_used_millibytes != 0
12025 + );
12026 +
12027 + if (!kfifo_is_empty(&spi_fifo_in) && g_recvCallback)
12028 + g_recvCallback(g_recvData);
12029 + }
12030 +}
12031 +
12032 +static int pisnd_spi_gpio_init(struct device *dev)
12033 +{
12034 + spi_reset = gpiod_get_index(dev, "reset", 1, GPIOD_ASIS);
12035 + data_available = gpiod_get_index(dev, "data_available", 0, GPIOD_ASIS);
12036 +
12037 + gpiod_direction_output(spi_reset, 1);
12038 + gpiod_direction_input(data_available);
12039 +
12040 + /* Reset the slave. */
12041 + gpiod_set_value(spi_reset, false);
12042 + mdelay(1);
12043 + gpiod_set_value(spi_reset, true);
12044 +
12045 + /* Give time for spi slave to start. */
12046 + mdelay(64);
12047 +
12048 + return 0;
12049 +}
12050 +
12051 +static void pisnd_spi_gpio_uninit(void)
12052 +{
12053 + gpiod_set_value(spi_reset, false);
12054 + gpiod_put(spi_reset);
12055 + spi_reset = NULL;
12056 +
12057 + gpiod_put(data_available);
12058 + data_available = NULL;
12059 +}
12060 +
12061 +static int pisnd_spi_gpio_irq_init(struct device *dev)
12062 +{
12063 + return request_threaded_irq(
12064 + gpiod_to_irq(data_available), NULL,
12065 + data_available_interrupt_handler,
12066 + IRQF_TIMER | IRQF_TRIGGER_RISING | IRQF_ONESHOT,
12067 + "data_available_int",
12068 + NULL
12069 + );
12070 +}
12071 +
12072 +static void pisnd_spi_gpio_irq_uninit(void)
12073 +{
12074 + free_irq(gpiod_to_irq(data_available), NULL);
12075 +}
12076 +
12077 +static int spi_read_info(void)
12078 +{
12079 + uint16_t tmp;
12080 + uint8_t count;
12081 + uint8_t n;
12082 + uint8_t i;
12083 + uint8_t j;
12084 + char buffer[257];
12085 + int ret;
12086 + char *p;
12087 +
12088 + memset(g_serial_num, 0, sizeof(g_serial_num));
12089 + memset(g_fw_version, 0, sizeof(g_fw_version));
12090 + strcpy(g_hw_version, "1.0"); // Assume 1.0 hw version.
12091 + memset(g_id, 0, sizeof(g_id));
12092 +
12093 + tmp = spi_transfer16(0);
12094 +
12095 + if (!(tmp >> 8))
12096 + return -EINVAL;
12097 +
12098 + count = tmp & 0xff;
12099 +
12100 + for (i = 0; i < count; ++i) {
12101 + memset(buffer, 0, sizeof(buffer));
12102 + ret = spi_read_bytes(buffer, sizeof(buffer)-1, &n);
12103 +
12104 + if (ret < 0)
12105 + return ret;
12106 +
12107 + switch (i) {
12108 + case 0:
12109 + if (n != 2)
12110 + return -EINVAL;
12111 +
12112 + snprintf(
12113 + g_fw_version,
12114 + MAX_VERSION_STR_LEN,
12115 + "%x.%02x",
12116 + buffer[0],
12117 + buffer[1]
12118 + );
12119 +
12120 + g_fw_version[MAX_VERSION_STR_LEN-1] = '\0';
12121 + break;
12122 + case 3:
12123 + if (n != 2)
12124 + return -EINVAL;
12125 +
12126 + snprintf(
12127 + g_hw_version,
12128 + MAX_VERSION_STR_LEN,
12129 + "%x.%x",
12130 + buffer[0],
12131 + buffer[1]
12132 + );
12133 +
12134 + g_hw_version[MAX_VERSION_STR_LEN-1] = '\0';
12135 + break;
12136 + case 1:
12137 + if (n >= sizeof(g_serial_num))
12138 + return -EINVAL;
12139 +
12140 + memcpy(g_serial_num, buffer, sizeof(g_serial_num));
12141 + break;
12142 + case 2:
12143 + {
12144 + if (n*2 >= sizeof(g_id))
12145 + return -EINVAL;
12146 +
12147 + p = g_id;
12148 + for (j = 0; j < n; ++j)
12149 + p += sprintf(p, "%02x", buffer[j]);
12150 +
12151 + *p = '\0';
12152 + }
12153 + break;
12154 + default:
12155 + break;
12156 + }
12157 + }
12158 +
12159 + return 0;
12160 +}
12161 +
12162 +static int pisnd_spi_init(struct device *dev)
12163 +{
12164 + int ret;
12165 + struct spi_device *spi;
12166 +
12167 + memset(g_serial_num, 0, sizeof(g_serial_num));
12168 + memset(g_id, 0, sizeof(g_id));
12169 + memset(g_fw_version, 0, sizeof(g_fw_version));
12170 + memset(g_hw_version, 0, sizeof(g_hw_version));
12171 +
12172 + spi = pisnd_spi_find_device();
12173 +
12174 + if (spi != NULL) {
12175 + printd("initializing spi!\n");
12176 + pisnd_spi_device = spi;
12177 + ret = spi_setup(pisnd_spi_device);
12178 + } else {
12179 + printe("SPI device not found, deferring!\n");
12180 + return -EPROBE_DEFER;
12181 + }
12182 +
12183 + ret = pisnd_spi_gpio_init(dev);
12184 +
12185 + if (ret < 0) {
12186 + printe("SPI GPIO init failed: %d\n", ret);
12187 + spi_dev_put(pisnd_spi_device);
12188 + pisnd_spi_device = NULL;
12189 + pisnd_spi_gpio_uninit();
12190 + return ret;
12191 + }
12192 +
12193 + ret = spi_read_info();
12194 +
12195 + if (ret < 0) {
12196 + printe("Reading card info failed: %d\n", ret);
12197 + spi_dev_put(pisnd_spi_device);
12198 + pisnd_spi_device = NULL;
12199 + pisnd_spi_gpio_uninit();
12200 + return ret;
12201 + }
12202 +
12203 + /* Flash the LEDs. */
12204 + spi_transfer16(0xf008);
12205 +
12206 + ret = pisnd_spi_gpio_irq_init(dev);
12207 + if (ret < 0) {
12208 + printe("SPI irq request failed: %d\n", ret);
12209 + spi_dev_put(pisnd_spi_device);
12210 + pisnd_spi_device = NULL;
12211 + pisnd_spi_gpio_irq_uninit();
12212 + pisnd_spi_gpio_uninit();
12213 + }
12214 +
12215 + ret = pisnd_init_workqueues();
12216 + if (ret != 0) {
12217 + printe("Workqueue initialization failed: %d\n", ret);
12218 + spi_dev_put(pisnd_spi_device);
12219 + pisnd_spi_device = NULL;
12220 + pisnd_spi_gpio_irq_uninit();
12221 + pisnd_spi_gpio_uninit();
12222 + pisnd_uninit_workqueues();
12223 + return ret;
12224 + }
12225 +
12226 + if (pisnd_spi_has_more()) {
12227 + printd("data is available, scheduling from init\n");
12228 + pisnd_schedule_process(TASK_PROCESS);
12229 + }
12230 +
12231 + return 0;
12232 +}
12233 +
12234 +static void pisnd_spi_uninit(void)
12235 +{
12236 + pisnd_uninit_workqueues();
12237 +
12238 + spi_dev_put(pisnd_spi_device);
12239 + pisnd_spi_device = NULL;
12240 +
12241 + pisnd_spi_gpio_irq_uninit();
12242 + pisnd_spi_gpio_uninit();
12243 +}
12244 +
12245 +static void pisnd_spi_flash_leds(uint8_t duration)
12246 +{
12247 + g_ledFlashDuration = duration;
12248 + g_ledFlashDurationChanged = true;
12249 + printd("schedule from spi_flash_leds\n");
12250 + pisnd_schedule_process(TASK_PROCESS);
12251 +}
12252 +
12253 +static void pisnd_spi_flush(void)
12254 +{
12255 + while (!kfifo_is_empty(&spi_fifo_out)) {
12256 + pisnd_spi_start();
12257 + flush_workqueue(pisnd_workqueue);
12258 + }
12259 +}
12260 +
12261 +static void pisnd_spi_start(void)
12262 +{
12263 + printd("schedule from spi_start\n");
12264 + pisnd_schedule_process(TASK_PROCESS);
12265 +}
12266 +
12267 +static uint8_t pisnd_spi_recv(uint8_t *buffer, uint8_t length)
12268 +{
12269 + return kfifo_out(&spi_fifo_in, buffer, length);
12270 +}
12271 +
12272 +static void pisnd_spi_set_callback(pisnd_spi_recv_cb cb, void *data)
12273 +{
12274 + g_recvData = data;
12275 + g_recvCallback = cb;
12276 +}
12277 +
12278 +static const char *pisnd_spi_get_serial(void)
12279 +{
12280 + return g_serial_num;
12281 +}
12282 +
12283 +static const char *pisnd_spi_get_id(void)
12284 +{
12285 + return g_id;
12286 +}
12287 +
12288 +static const char *pisnd_spi_get_fw_version(void)
12289 +{
12290 + return g_fw_version;
12291 +}
12292 +
12293 +static const char *pisnd_spi_get_hw_version(void)
12294 +{
12295 + return g_hw_version;
12296 +}
12297 +
12298 +static const struct of_device_id pisound_of_match[] = {
12299 + { .compatible = "blokaslabs,pisound", },
12300 + { .compatible = "blokaslabs,pisound-spi", },
12301 + {},
12302 +};
12303 +
12304 +enum {
12305 + SWITCH = 0,
12306 + VOLUME = 1,
12307 +};
12308 +
12309 +static int pisnd_ctl_info(struct snd_kcontrol *kcontrol,
12310 + struct snd_ctl_elem_info *uinfo)
12311 +{
12312 + if (kcontrol->private_value == SWITCH) {
12313 + uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
12314 + uinfo->count = 1;
12315 + uinfo->value.integer.min = 0;
12316 + uinfo->value.integer.max = 1;
12317 + return 0;
12318 + } else if (kcontrol->private_value == VOLUME) {
12319 + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
12320 + uinfo->count = 1;
12321 + uinfo->value.integer.min = 0;
12322 + uinfo->value.integer.max = 100;
12323 + return 0;
12324 + }
12325 + return -EINVAL;
12326 +}
12327 +
12328 +static int pisnd_ctl_get(struct snd_kcontrol *kcontrol,
12329 + struct snd_ctl_elem_value *ucontrol)
12330 +{
12331 + if (kcontrol->private_value == SWITCH) {
12332 + ucontrol->value.integer.value[0] = 1;
12333 + return 0;
12334 + } else if (kcontrol->private_value == VOLUME) {
12335 + ucontrol->value.integer.value[0] = 100;
12336 + return 0;
12337 + }
12338 +
12339 + return -EINVAL;
12340 +}
12341 +
12342 +static struct snd_kcontrol_new pisnd_ctl[] = {
12343 + {
12344 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12345 + .name = "PCM Playback Switch",
12346 + .index = 0,
12347 + .private_value = SWITCH,
12348 + .access = SNDRV_CTL_ELEM_ACCESS_READ,
12349 + .info = pisnd_ctl_info,
12350 + .get = pisnd_ctl_get,
12351 + },
12352 + {
12353 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12354 + .name = "PCM Playback Volume",
12355 + .index = 0,
12356 + .private_value = VOLUME,
12357 + .access = SNDRV_CTL_ELEM_ACCESS_READ,
12358 + .info = pisnd_ctl_info,
12359 + .get = pisnd_ctl_get,
12360 + },
12361 +};
12362 +
12363 +static int pisnd_ctl_init(struct snd_card *card)
12364 +{
12365 + int err, i;
12366 +
12367 + for (i = 0; i < ARRAY_SIZE(pisnd_ctl); ++i) {
12368 + err = snd_ctl_add(card, snd_ctl_new1(&pisnd_ctl[i], NULL));
12369 + if (err < 0)
12370 + return err;
12371 + }
12372 +
12373 + return 0;
12374 +}
12375 +
12376 +static int pisnd_ctl_uninit(void)
12377 +{
12378 + return 0;
12379 +}
12380 +
12381 +static struct gpio_desc *osr0, *osr1, *osr2;
12382 +static struct gpio_desc *reset;
12383 +static struct gpio_desc *button;
12384 +
12385 +static int pisnd_hw_params(
12386 + struct snd_pcm_substream *substream,
12387 + struct snd_pcm_hw_params *params
12388 + )
12389 +{
12390 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
12391 + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
12392 +
12393 + /* Pisound runs on fixed 32 clock counts per channel,
12394 + * as generated by the master ADC.
12395 + */
12396 + snd_soc_dai_set_bclk_ratio(cpu_dai, 32*2);
12397 +
12398 + printd("rate = %d\n", params_rate(params));
12399 + printd("ch = %d\n", params_channels(params));
12400 + printd("bits = %u\n",
12401 + snd_pcm_format_physical_width(params_format(params)));
12402 + printd("format = %d\n", params_format(params));
12403 +
12404 + gpiod_set_value(reset, false);
12405 +
12406 + switch (params_rate(params)) {
12407 + case 48000:
12408 + gpiod_set_value(osr0, true);
12409 + gpiod_set_value(osr1, false);
12410 + gpiod_set_value(osr2, false);
12411 + break;
12412 + case 96000:
12413 + gpiod_set_value(osr0, true);
12414 + gpiod_set_value(osr1, false);
12415 + gpiod_set_value(osr2, true);
12416 + break;
12417 + case 192000:
12418 + gpiod_set_value(osr0, true);
12419 + gpiod_set_value(osr1, true);
12420 + gpiod_set_value(osr2, true);
12421 + break;
12422 + default:
12423 + printe("Unsupported rate %u!\n", params_rate(params));
12424 + return -EINVAL;
12425 + }
12426 +
12427 + gpiod_set_value(reset, true);
12428 +
12429 + return 0;
12430 +}
12431 +
12432 +static unsigned int rates[3] = {
12433 + 48000, 96000, 192000
12434 +};
12435 +
12436 +static struct snd_pcm_hw_constraint_list constraints_rates = {
12437 + .count = ARRAY_SIZE(rates),
12438 + .list = rates,
12439 + .mask = 0,
12440 +};
12441 +
12442 +static int pisnd_startup(struct snd_pcm_substream *substream)
12443 +{
12444 + int err = snd_pcm_hw_constraint_list(
12445 + substream->runtime,
12446 + 0,
12447 + SNDRV_PCM_HW_PARAM_RATE,
12448 + &constraints_rates
12449 + );
12450 +
12451 + if (err < 0)
12452 + return err;
12453 +
12454 + err = snd_pcm_hw_constraint_single(
12455 + substream->runtime,
12456 + SNDRV_PCM_HW_PARAM_CHANNELS,
12457 + 2
12458 + );
12459 +
12460 + if (err < 0)
12461 + return err;
12462 +
12463 + err = snd_pcm_hw_constraint_mask64(
12464 + substream->runtime,
12465 + SNDRV_PCM_HW_PARAM_FORMAT,
12466 + SNDRV_PCM_FMTBIT_S16_LE |
12467 + SNDRV_PCM_FMTBIT_S24_LE |
12468 + SNDRV_PCM_FMTBIT_S32_LE
12469 + );
12470 +
12471 + if (err < 0)
12472 + return err;
12473 +
12474 + return 0;
12475 +}
12476 +
12477 +static struct snd_soc_ops pisnd_ops = {
12478 + .startup = pisnd_startup,
12479 + .hw_params = pisnd_hw_params,
12480 +};
12481 +
12482 +SND_SOC_DAILINK_DEFS(pisnd,
12483 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
12484 + DAILINK_COMP_ARRAY(COMP_DUMMY()),
12485 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
12486 +
12487 +static struct snd_soc_dai_link pisnd_dai[] = {
12488 + {
12489 + .name = "pisound",
12490 + .stream_name = "pisound",
12491 + .dai_fmt =
12492 + SND_SOC_DAIFMT_I2S |
12493 + SND_SOC_DAIFMT_NB_NF |
12494 + SND_SOC_DAIFMT_CBM_CFM,
12495 + .ops = &pisnd_ops,
12496 + SND_SOC_DAILINK_REG(pisnd),
12497 + },
12498 +};
12499 +
12500 +static int pisnd_card_probe(struct snd_soc_card *card)
12501 +{
12502 + int err = pisnd_midi_init(card->snd_card);
12503 +
12504 + if (err < 0) {
12505 + printe("pisnd_midi_init failed: %d\n", err);
12506 + return err;
12507 + }
12508 +
12509 + err = pisnd_ctl_init(card->snd_card);
12510 + if (err < 0) {
12511 + printe("pisnd_ctl_init failed: %d\n", err);
12512 + return err;
12513 + }
12514 +
12515 + return 0;
12516 +}
12517 +
12518 +static int pisnd_card_remove(struct snd_soc_card *card)
12519 +{
12520 + pisnd_ctl_uninit();
12521 + pisnd_midi_uninit();
12522 + return 0;
12523 +}
12524 +
12525 +static struct snd_soc_card pisnd_card = {
12526 + .name = "pisound",
12527 + .owner = THIS_MODULE,
12528 + .dai_link = pisnd_dai,
12529 + .num_links = ARRAY_SIZE(pisnd_dai),
12530 + .probe = pisnd_card_probe,
12531 + .remove = pisnd_card_remove,
12532 +};
12533 +
12534 +static int pisnd_init_gpio(struct device *dev)
12535 +{
12536 + osr0 = gpiod_get_index(dev, "osr", 0, GPIOD_ASIS);
12537 + osr1 = gpiod_get_index(dev, "osr", 1, GPIOD_ASIS);
12538 + osr2 = gpiod_get_index(dev, "osr", 2, GPIOD_ASIS);
12539 +
12540 + reset = gpiod_get_index(dev, "reset", 0, GPIOD_ASIS);
12541 +
12542 + button = gpiod_get_index(dev, "button", 0, GPIOD_ASIS);
12543 +
12544 + gpiod_direction_output(osr0, 1);
12545 + gpiod_direction_output(osr1, 1);
12546 + gpiod_direction_output(osr2, 1);
12547 + gpiod_direction_output(reset, 1);
12548 +
12549 + gpiod_set_value(reset, false);
12550 + gpiod_set_value(osr0, true);
12551 + gpiod_set_value(osr1, false);
12552 + gpiod_set_value(osr2, false);
12553 + gpiod_set_value(reset, true);
12554 +
12555 + gpiod_export(button, false);
12556 +
12557 + return 0;
12558 +}
12559 +
12560 +static int pisnd_uninit_gpio(void)
12561 +{
12562 + int i;
12563 +
12564 + struct gpio_desc **gpios[] = {
12565 + &osr0, &osr1, &osr2, &reset, &button,
12566 + };
12567 +
12568 + gpiod_unexport(button);
12569 +
12570 + for (i = 0; i < ARRAY_SIZE(gpios); ++i) {
12571 + if (*gpios[i] == NULL) {
12572 + printd("weird, GPIO[%d] is NULL already\n", i);
12573 + continue;
12574 + }
12575 +
12576 + gpiod_put(*gpios[i]);
12577 + *gpios[i] = NULL;
12578 + }
12579 +
12580 + return 0;
12581 +}
12582 +
12583 +static struct kobject *pisnd_kobj;
12584 +
12585 +static ssize_t pisnd_serial_show(
12586 + struct kobject *kobj,
12587 + struct kobj_attribute *attr,
12588 + char *buf
12589 + )
12590 +{
12591 + return sprintf(buf, "%s\n", pisnd_spi_get_serial());
12592 +}
12593 +
12594 +static ssize_t pisnd_id_show(
12595 + struct kobject *kobj,
12596 + struct kobj_attribute *attr,
12597 + char *buf
12598 + )
12599 +{
12600 + return sprintf(buf, "%s\n", pisnd_spi_get_id());
12601 +}
12602 +
12603 +static ssize_t pisnd_fw_version_show(
12604 + struct kobject *kobj,
12605 + struct kobj_attribute *attr,
12606 + char *buf
12607 + )
12608 +{
12609 + return sprintf(buf, "%s\n", pisnd_spi_get_fw_version());
12610 +}
12611 +
12612 +static ssize_t pisnd_hw_version_show(
12613 + struct kobject *kobj,
12614 + struct kobj_attribute *attr,
12615 + char *buf
12616 +)
12617 +{
12618 + return sprintf(buf, "%s\n", pisnd_spi_get_hw_version());
12619 +}
12620 +
12621 +static ssize_t pisnd_led_store(
12622 + struct kobject *kobj,
12623 + struct kobj_attribute *attr,
12624 + const char *buf,
12625 + size_t length
12626 + )
12627 +{
12628 + uint32_t timeout;
12629 + int err;
12630 +
12631 + err = kstrtou32(buf, 10, &timeout);
12632 +
12633 + if (err == 0 && timeout <= 255)
12634 + pisnd_spi_flash_leds(timeout);
12635 +
12636 + return length;
12637 +}
12638 +
12639 +static struct kobj_attribute pisnd_serial_attribute =
12640 + __ATTR(serial, 0444, pisnd_serial_show, NULL);
12641 +static struct kobj_attribute pisnd_id_attribute =
12642 + __ATTR(id, 0444, pisnd_id_show, NULL);
12643 +static struct kobj_attribute pisnd_fw_version_attribute =
12644 + __ATTR(version, 0444, pisnd_fw_version_show, NULL);
12645 +static struct kobj_attribute pisnd_hw_version_attribute =
12646 +__ATTR(hw_version, 0444, pisnd_hw_version_show, NULL);
12647 +static struct kobj_attribute pisnd_led_attribute =
12648 + __ATTR(led, 0644, NULL, pisnd_led_store);
12649 +
12650 +static struct attribute *attrs[] = {
12651 + &pisnd_serial_attribute.attr,
12652 + &pisnd_id_attribute.attr,
12653 + &pisnd_fw_version_attribute.attr,
12654 + &pisnd_hw_version_attribute.attr,
12655 + &pisnd_led_attribute.attr,
12656 + NULL
12657 +};
12658 +
12659 +static struct attribute_group attr_group = { .attrs = attrs };
12660 +
12661 +static int pisnd_probe(struct platform_device *pdev)
12662 +{
12663 + int ret = 0;
12664 + int i;
12665 +
12666 + ret = pisnd_spi_init(&pdev->dev);
12667 + if (ret < 0) {
12668 + printe("pisnd_spi_init failed: %d\n", ret);
12669 + return ret;
12670 + }
12671 +
12672 + printi("Detected Pisound card:\n");
12673 + printi("\tSerial: %s\n", pisnd_spi_get_serial());
12674 + printi("\tFirmware Version: %s\n", pisnd_spi_get_fw_version());
12675 + printi("\tHardware Version: %s\n", pisnd_spi_get_hw_version());
12676 + printi("\tId: %s\n", pisnd_spi_get_id());
12677 +
12678 + pisnd_kobj = kobject_create_and_add("pisound", kernel_kobj);
12679 + if (!pisnd_kobj) {
12680 + pisnd_spi_uninit();
12681 + return -ENOMEM;
12682 + }
12683 +
12684 + ret = sysfs_create_group(pisnd_kobj, &attr_group);
12685 + if (ret < 0) {
12686 + pisnd_spi_uninit();
12687 + kobject_put(pisnd_kobj);
12688 + return -ENOMEM;
12689 + }
12690 +
12691 + pisnd_init_gpio(&pdev->dev);
12692 + pisnd_card.dev = &pdev->dev;
12693 +
12694 + if (pdev->dev.of_node) {
12695 + struct device_node *i2s_node;
12696 +
12697 + i2s_node = of_parse_phandle(
12698 + pdev->dev.of_node,
12699 + "i2s-controller",
12700 + 0
12701 + );
12702 +
12703 + for (i = 0; i < pisnd_card.num_links; ++i) {
12704 + struct snd_soc_dai_link *dai = &pisnd_dai[i];
12705 +
12706 + if (i2s_node) {
12707 + dai->cpus->dai_name = NULL;
12708 + dai->cpus->of_node = i2s_node;
12709 + dai->platforms->name = NULL;
12710 + dai->platforms->of_node = i2s_node;
12711 + dai->stream_name = pisnd_spi_get_serial();
12712 + }
12713 + }
12714 + }
12715 +
12716 + ret = snd_soc_register_card(&pisnd_card);
12717 +
12718 + if (ret < 0) {
12719 + if (ret != -EPROBE_DEFER)
12720 + printe("snd_soc_register_card() failed: %d\n", ret);
12721 + pisnd_uninit_gpio();
12722 + kobject_put(pisnd_kobj);
12723 + pisnd_spi_uninit();
12724 + }
12725 +
12726 + return ret;
12727 +}
12728 +
12729 +static int pisnd_remove(struct platform_device *pdev)
12730 +{
12731 + printi("Unloading.\n");
12732 +
12733 + if (pisnd_kobj) {
12734 + kobject_put(pisnd_kobj);
12735 + pisnd_kobj = NULL;
12736 + }
12737 +
12738 + pisnd_spi_uninit();
12739 +
12740 + /* Turn off */
12741 + gpiod_set_value(reset, false);
12742 + pisnd_uninit_gpio();
12743 +
12744 + snd_soc_unregister_card(&pisnd_card);
12745 + return 0;
12746 +}
12747 +
12748 +MODULE_DEVICE_TABLE(of, pisound_of_match);
12749 +
12750 +static struct platform_driver pisnd_driver = {
12751 + .driver = {
12752 + .name = "snd-rpi-pisound",
12753 + .owner = THIS_MODULE,
12754 + .of_match_table = pisound_of_match,
12755 + },
12756 + .probe = pisnd_probe,
12757 + .remove = pisnd_remove,
12758 +};
12759 +
12760 +module_platform_driver(pisnd_driver);
12761 +
12762 +MODULE_AUTHOR("Giedrius Trainavicius <giedrius@blokas.io>");
12763 +MODULE_DESCRIPTION("ASoC Driver for Pisound, https://blokas.io/pisound");
12764 +MODULE_LICENSE("GPL v2");
12765 --- /dev/null
12766 +++ b/sound/soc/bcm/rpi-cirrus.c
12767 @@ -0,0 +1,1025 @@
12768 +/*
12769 + * ASoC machine driver for Cirrus Logic Audio Card
12770 + * (with WM5102 and WM8804 codecs)
12771 + *
12772 + * Copyright 2015-2017 Matthias Reichl <hias@horus.com>
12773 + *
12774 + * Based on rpi-cirrus-sound-pi driver (c) Wolfson / Cirrus Logic Inc.
12775 + *
12776 + * This program is free software; you can redistribute it and/or modify
12777 + * it under the terms of the GNU General Public License version 2 as
12778 + * published by the Free Software Foundation.
12779 + */
12780 +
12781 +#include <linux/module.h>
12782 +#include <linux/mutex.h>
12783 +#include <linux/slab.h>
12784 +#include <linux/list.h>
12785 +#include <linux/delay.h>
12786 +#include <sound/pcm_params.h>
12787 +
12788 +#include <linux/mfd/arizona/registers.h>
12789 +
12790 +#include "../codecs/wm5102.h"
12791 +#include "../codecs/wm8804.h"
12792 +
12793 +#define WM8804_CLKOUT_HZ 12000000
12794 +
12795 +#define RPI_CIRRUS_DEFAULT_RATE 44100
12796 +#define WM5102_MAX_SYSCLK_1 49152000 /* max sysclk for 4K family */
12797 +#define WM5102_MAX_SYSCLK_2 45158400 /* max sysclk for 11.025K family */
12798 +
12799 +static inline unsigned int calc_sysclk(unsigned int rate)
12800 +{
12801 + return (rate % 4000) ? WM5102_MAX_SYSCLK_2 : WM5102_MAX_SYSCLK_1;
12802 +}
12803 +
12804 +enum {
12805 + DAI_WM5102 = 0,
12806 + DAI_WM8804,
12807 +};
12808 +
12809 +struct rpi_cirrus_priv {
12810 + /* mutex for synchronzing FLL1 access with DAPM */
12811 + struct mutex lock;
12812 + unsigned int card_rate;
12813 + int sync_path_enable;
12814 + int fll1_freq; /* negative means RefClock in spdif rx case */
12815 +
12816 + /* track hw params/free for substreams */
12817 + unsigned int params_set;
12818 + unsigned int min_rate_idx, max_rate_idx;
12819 + unsigned char iec958_status[4];
12820 +};
12821 +
12822 +/* helper functions */
12823 +static inline struct snd_soc_pcm_runtime *get_wm5102_runtime(
12824 + struct snd_soc_card *card) {
12825 + return snd_soc_get_pcm_runtime(card, &card->dai_link[DAI_WM5102]);
12826 +}
12827 +
12828 +static inline struct snd_soc_pcm_runtime *get_wm8804_runtime(
12829 + struct snd_soc_card *card) {
12830 + return snd_soc_get_pcm_runtime(card, &card->dai_link[DAI_WM8804]);
12831 +}
12832 +
12833 +
12834 +struct rate_info {
12835 + unsigned int value;
12836 + char *text;
12837 +};
12838 +
12839 +static struct rate_info min_rates[] = {
12840 + { 0, "off"},
12841 + { 32000, "32kHz"},
12842 + { 44100, "44.1kHz"}
12843 +};
12844 +
12845 +#define NUM_MIN_RATES ARRAY_SIZE(min_rates)
12846 +
12847 +static int rpi_cirrus_min_rate_info(struct snd_kcontrol *kcontrol,
12848 + struct snd_ctl_elem_info *uinfo)
12849 +{
12850 + uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
12851 + uinfo->count = 1;
12852 + uinfo->value.enumerated.items = NUM_MIN_RATES;
12853 +
12854 + if (uinfo->value.enumerated.item >= NUM_MIN_RATES)
12855 + uinfo->value.enumerated.item = NUM_MIN_RATES - 1;
12856 + strcpy(uinfo->value.enumerated.name,
12857 + min_rates[uinfo->value.enumerated.item].text);
12858 + return 0;
12859 +}
12860 +
12861 +static int rpi_cirrus_min_rate_get(struct snd_kcontrol *kcontrol,
12862 + struct snd_ctl_elem_value *ucontrol)
12863 +{
12864 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
12865 + struct rpi_cirrus_priv *priv = snd_soc_card_get_drvdata(card);
12866 +
12867 + ucontrol->value.enumerated.item[0] = priv->min_rate_idx;
12868 + return 0;
12869 +}
12870 +
12871 +static int rpi_cirrus_min_rate_put(struct snd_kcontrol *kcontrol,
12872 + struct snd_ctl_elem_value *ucontrol)
12873 +{
12874 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
12875 + struct rpi_cirrus_priv *priv = snd_soc_card_get_drvdata(card);
12876 + int changed = 0;
12877 +
12878 + if (priv->min_rate_idx != ucontrol->value.enumerated.item[0]) {
12879 + changed = 1;
12880 + priv->min_rate_idx = ucontrol->value.enumerated.item[0];
12881 + }
12882 +
12883 + return changed;
12884 +}
12885 +
12886 +static struct rate_info max_rates[] = {
12887 + { 0, "off"},
12888 + { 48000, "48kHz"},
12889 + { 96000, "96kHz"}
12890 +};
12891 +
12892 +#define NUM_MAX_RATES ARRAY_SIZE(max_rates)
12893 +
12894 +static int rpi_cirrus_max_rate_info(struct snd_kcontrol *kcontrol,
12895 + struct snd_ctl_elem_info *uinfo)
12896 +{
12897 + uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
12898 + uinfo->count = 1;
12899 + uinfo->value.enumerated.items = NUM_MAX_RATES;
12900 + if (uinfo->value.enumerated.item >= NUM_MAX_RATES)
12901 + uinfo->value.enumerated.item = NUM_MAX_RATES - 1;
12902 + strcpy(uinfo->value.enumerated.name,
12903 + max_rates[uinfo->value.enumerated.item].text);
12904 + return 0;
12905 +}
12906 +
12907 +static int rpi_cirrus_max_rate_get(struct snd_kcontrol *kcontrol,
12908 + struct snd_ctl_elem_value *ucontrol)
12909 +{
12910 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
12911 + struct rpi_cirrus_priv *priv = snd_soc_card_get_drvdata(card);
12912 +
12913 + ucontrol->value.enumerated.item[0] = priv->max_rate_idx;
12914 + return 0;
12915 +}
12916 +
12917 +static int rpi_cirrus_max_rate_put(struct snd_kcontrol *kcontrol,
12918 + struct snd_ctl_elem_value *ucontrol)
12919 +{
12920 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
12921 + struct rpi_cirrus_priv *priv = snd_soc_card_get_drvdata(card);
12922 + int changed = 0;
12923 +
12924 + if (priv->max_rate_idx != ucontrol->value.enumerated.item[0]) {
12925 + changed = 1;
12926 + priv->max_rate_idx = ucontrol->value.enumerated.item[0];
12927 + }
12928 +
12929 + return changed;
12930 +}
12931 +
12932 +static int rpi_cirrus_spdif_info(struct snd_kcontrol *kcontrol,
12933 + struct snd_ctl_elem_info *uinfo)
12934 +{
12935 + uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
12936 + uinfo->count = 1;
12937 + return 0;
12938 +}
12939 +
12940 +static int rpi_cirrus_spdif_playback_get(struct snd_kcontrol *kcontrol,
12941 + struct snd_ctl_elem_value *ucontrol)
12942 +{
12943 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
12944 + struct rpi_cirrus_priv *priv = snd_soc_card_get_drvdata(card);
12945 + int i;
12946 +
12947 + for (i = 0; i < 4; i++)
12948 + ucontrol->value.iec958.status[i] = priv->iec958_status[i];
12949 +
12950 + return 0;
12951 +}
12952 +
12953 +static int rpi_cirrus_spdif_playback_put(struct snd_kcontrol *kcontrol,
12954 + struct snd_ctl_elem_value *ucontrol)
12955 +{
12956 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
12957 + struct snd_soc_component *wm8804_component =
12958 + asoc_rtd_to_codec(get_wm8804_runtime(card), 0)->component;
12959 + struct rpi_cirrus_priv *priv = snd_soc_card_get_drvdata(card);
12960 + unsigned char *stat = priv->iec958_status;
12961 + unsigned char *ctrl_stat = ucontrol->value.iec958.status;
12962 + unsigned int mask;
12963 + int i, changed = 0;
12964 +
12965 + for (i = 0; i < 4; i++) {
12966 + mask = (i == 3) ? 0x3f : 0xff;
12967 + if ((ctrl_stat[i] & mask) != (stat[i] & mask)) {
12968 + changed = 1;
12969 + stat[i] = ctrl_stat[i] & mask;
12970 + snd_soc_component_update_bits(wm8804_component,
12971 + WM8804_SPDTX1 + i, mask, stat[i]);
12972 + }
12973 + }
12974 +
12975 + return changed;
12976 +}
12977 +
12978 +static int rpi_cirrus_spdif_mask_get(struct snd_kcontrol *kcontrol,
12979 + struct snd_ctl_elem_value *ucontrol)
12980 +{
12981 + ucontrol->value.iec958.status[0] = 0xff;
12982 + ucontrol->value.iec958.status[1] = 0xff;
12983 + ucontrol->value.iec958.status[2] = 0xff;
12984 + ucontrol->value.iec958.status[3] = 0x3f;
12985 +
12986 + return 0;
12987 +}
12988 +
12989 +static int rpi_cirrus_spdif_capture_get(struct snd_kcontrol *kcontrol,
12990 + struct snd_ctl_elem_value *ucontrol)
12991 +{
12992 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
12993 + struct snd_soc_component *wm8804_component =
12994 + asoc_rtd_to_codec(get_wm8804_runtime(card), 0)->component;
12995 + unsigned int val, mask;
12996 + int i;
12997 +
12998 + for (i = 0; i < 4; i++) {
12999 + val = snd_soc_component_read(wm8804_component,
13000 + WM8804_RXCHAN1 + i);
13001 + mask = (i == 3) ? 0x3f : 0xff;
13002 + ucontrol->value.iec958.status[i] = val & mask;
13003 + }
13004 +
13005 + return 0;
13006 +}
13007 +
13008 +#define SPDIF_FLAG_CTRL(desc, reg, bit, invert) \
13009 +{ \
13010 + .access = SNDRV_CTL_ELEM_ACCESS_READ \
13011 + | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
13012 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
13013 + .name = SNDRV_CTL_NAME_IEC958("", CAPTURE, NONE) \
13014 + desc " Flag", \
13015 + .info = snd_ctl_boolean_mono_info, \
13016 + .get = rpi_cirrus_spdif_status_flag_get, \
13017 + .private_value = \
13018 + (bit) | ((reg) << 8) | ((invert) << 16) \
13019 +}
13020 +
13021 +static int rpi_cirrus_spdif_status_flag_get(struct snd_kcontrol *kcontrol,
13022 + struct snd_ctl_elem_value *ucontrol)
13023 +{
13024 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
13025 + struct snd_soc_component *wm8804_component =
13026 + asoc_rtd_to_codec(get_wm8804_runtime(card), 0)->component;
13027 +
13028 + unsigned int bit = kcontrol->private_value & 0xff;
13029 + unsigned int reg = (kcontrol->private_value >> 8) & 0xff;
13030 + unsigned int invert = (kcontrol->private_value >> 16) & 0xff;
13031 + unsigned int val;
13032 + bool flag;
13033 +
13034 + val = snd_soc_component_read(wm8804_component, reg);
13035 +
13036 + flag = val & (1 << bit);
13037 +
13038 + ucontrol->value.integer.value[0] = invert ? !flag : flag;
13039 +
13040 + return 0;
13041 +}
13042 +
13043 +static const char * const recovered_frequency_texts[] = {
13044 + "176.4/192 kHz",
13045 + "88.2/96 kHz",
13046 + "44.1/48 kHz",
13047 + "32 kHz"
13048 +};
13049 +
13050 +#define NUM_RECOVERED_FREQUENCIES \
13051 + ARRAY_SIZE(recovered_frequency_texts)
13052 +
13053 +static int rpi_cirrus_recovered_frequency_info(struct snd_kcontrol *kcontrol,
13054 + struct snd_ctl_elem_info *uinfo)
13055 +{
13056 + uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
13057 + uinfo->count = 1;
13058 + uinfo->value.enumerated.items = NUM_RECOVERED_FREQUENCIES;
13059 + if (uinfo->value.enumerated.item >= NUM_RECOVERED_FREQUENCIES)
13060 + uinfo->value.enumerated.item = NUM_RECOVERED_FREQUENCIES - 1;
13061 + strcpy(uinfo->value.enumerated.name,
13062 + recovered_frequency_texts[uinfo->value.enumerated.item]);
13063 + return 0;
13064 +}
13065 +
13066 +static int rpi_cirrus_recovered_frequency_get(struct snd_kcontrol *kcontrol,
13067 + struct snd_ctl_elem_value *ucontrol)
13068 +{
13069 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
13070 + struct snd_soc_component *wm8804_component =
13071 + asoc_rtd_to_codec(get_wm8804_runtime(card), 0)->component;
13072 + unsigned int val;
13073 +
13074 + val = snd_soc_component_read(wm8804_component, WM8804_SPDSTAT);
13075 +
13076 + ucontrol->value.enumerated.item[0] = (val >> 4) & 0x03;
13077 + return 0;
13078 +}
13079 +
13080 +static const struct snd_kcontrol_new rpi_cirrus_controls[] = {
13081 + {
13082 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13083 + .name = "Min Sample Rate",
13084 + .info = rpi_cirrus_min_rate_info,
13085 + .get = rpi_cirrus_min_rate_get,
13086 + .put = rpi_cirrus_min_rate_put,
13087 + },
13088 + {
13089 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13090 + .name = "Max Sample Rate",
13091 + .info = rpi_cirrus_max_rate_info,
13092 + .get = rpi_cirrus_max_rate_get,
13093 + .put = rpi_cirrus_max_rate_put,
13094 + },
13095 + {
13096 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13097 + .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT),
13098 + .info = rpi_cirrus_spdif_info,
13099 + .get = rpi_cirrus_spdif_playback_get,
13100 + .put = rpi_cirrus_spdif_playback_put,
13101 + },
13102 + {
13103 + .access = SNDRV_CTL_ELEM_ACCESS_READ
13104 + | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
13105 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13106 + .name = SNDRV_CTL_NAME_IEC958("", CAPTURE, DEFAULT),
13107 + .info = rpi_cirrus_spdif_info,
13108 + .get = rpi_cirrus_spdif_capture_get,
13109 + },
13110 + {
13111 + .access = SNDRV_CTL_ELEM_ACCESS_READ,
13112 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13113 + .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, MASK),
13114 + .info = rpi_cirrus_spdif_info,
13115 + .get = rpi_cirrus_spdif_mask_get,
13116 + },
13117 + {
13118 + .access = SNDRV_CTL_ELEM_ACCESS_READ
13119 + | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
13120 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13121 + .name = SNDRV_CTL_NAME_IEC958("", CAPTURE, NONE)
13122 + "Recovered Frequency",
13123 + .info = rpi_cirrus_recovered_frequency_info,
13124 + .get = rpi_cirrus_recovered_frequency_get,
13125 + },
13126 + SPDIF_FLAG_CTRL("Audio", WM8804_SPDSTAT, 0, 1),
13127 + SPDIF_FLAG_CTRL("Non-PCM", WM8804_SPDSTAT, 1, 0),
13128 + SPDIF_FLAG_CTRL("Copyright", WM8804_SPDSTAT, 2, 1),
13129 + SPDIF_FLAG_CTRL("De-Emphasis", WM8804_SPDSTAT, 3, 0),
13130 + SPDIF_FLAG_CTRL("Lock", WM8804_SPDSTAT, 6, 1),
13131 + SPDIF_FLAG_CTRL("Invalid", WM8804_INTSTAT, 1, 0),
13132 + SPDIF_FLAG_CTRL("TransErr", WM8804_INTSTAT, 3, 0),
13133 +};
13134 +
13135 +static const char * const linein_micbias_texts[] = {
13136 + "off", "on",
13137 +};
13138 +
13139 +static SOC_ENUM_SINGLE_VIRT_DECL(linein_micbias_enum,
13140 + linein_micbias_texts);
13141 +
13142 +static const struct snd_kcontrol_new linein_micbias_mux =
13143 + SOC_DAPM_ENUM("Route", linein_micbias_enum);
13144 +
13145 +static int rpi_cirrus_spdif_rx_enable_event(struct snd_soc_dapm_widget *w,
13146 + struct snd_kcontrol *kcontrol, int event);
13147 +
13148 +const struct snd_soc_dapm_widget rpi_cirrus_dapm_widgets[] = {
13149 + SND_SOC_DAPM_MIC("DMIC", NULL),
13150 + SND_SOC_DAPM_MIC("Headset Mic", NULL),
13151 + SND_SOC_DAPM_INPUT("Line Input"),
13152 + SND_SOC_DAPM_MIC("Line Input with Micbias", NULL),
13153 + SND_SOC_DAPM_MUX("Line Input Micbias", SND_SOC_NOPM, 0, 0,
13154 + &linein_micbias_mux),
13155 + SND_SOC_DAPM_INPUT("dummy SPDIF in"),
13156 + SND_SOC_DAPM_PGA_E("dummy SPDIFRX", SND_SOC_NOPM, 0, 0, NULL, 0,
13157 + rpi_cirrus_spdif_rx_enable_event,
13158 + SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
13159 + SND_SOC_DAPM_INPUT("Dummy Input"),
13160 + SND_SOC_DAPM_OUTPUT("Dummy Output"),
13161 +};
13162 +
13163 +const struct snd_soc_dapm_route rpi_cirrus_dapm_routes[] = {
13164 + { "IN1L", NULL, "Headset Mic" },
13165 + { "IN1R", NULL, "Headset Mic" },
13166 + { "Headset Mic", NULL, "MICBIAS1" },
13167 +
13168 + { "IN2L", NULL, "DMIC" },
13169 + { "IN2R", NULL, "DMIC" },
13170 + { "DMIC", NULL, "MICBIAS2" },
13171 +
13172 + { "IN3L", NULL, "Line Input Micbias" },
13173 + { "IN3R", NULL, "Line Input Micbias" },
13174 +
13175 + { "Line Input Micbias", "off", "Line Input" },
13176 + { "Line Input Micbias", "on", "Line Input with Micbias" },
13177 +
13178 + /* Make sure MICVDD is enabled, otherwise we get noise */
13179 + { "Line Input", NULL, "MICVDD" },
13180 + { "Line Input with Micbias", NULL, "MICBIAS3" },
13181 +
13182 + /* Dummy routes to check whether SPDIF RX is enabled or not */
13183 + {"dummy SPDIFRX", NULL, "dummy SPDIF in"},
13184 + {"AIFTX", NULL, "dummy SPDIFRX"},
13185 +
13186 + /*
13187 + * Dummy routes to keep wm5102 from staying off on
13188 + * playback/capture if all mixers are off.
13189 + */
13190 + { "Dummy Output", NULL, "AIF1RX1" },
13191 + { "Dummy Output", NULL, "AIF1RX2" },
13192 + { "AIF1TX1", NULL, "Dummy Input" },
13193 + { "AIF1TX2", NULL, "Dummy Input" },
13194 +};
13195 +
13196 +static int rpi_cirrus_clear_flls(struct snd_soc_card *card,
13197 + struct snd_soc_component *wm5102_component) {
13198 +
13199 + int ret1, ret2;
13200 +
13201 + ret1 = snd_soc_component_set_pll(wm5102_component,
13202 + WM5102_FLL1, ARIZONA_FLL_SRC_NONE, 0, 0);
13203 + ret2 = snd_soc_component_set_pll(wm5102_component,
13204 + WM5102_FLL1_REFCLK, ARIZONA_FLL_SRC_NONE, 0, 0);
13205 +
13206 + if (ret1) {
13207 + dev_warn(card->dev,
13208 + "setting FLL1 to zero failed: %d\n", ret1);
13209 + return ret1;
13210 + }
13211 + if (ret2) {
13212 + dev_warn(card->dev,
13213 + "setting FLL1_REFCLK to zero failed: %d\n", ret2);
13214 + return ret2;
13215 + }
13216 + return 0;
13217 +}
13218 +
13219 +static int rpi_cirrus_set_fll(struct snd_soc_card *card,
13220 + struct snd_soc_component *wm5102_component, unsigned int clk_freq)
13221 +{
13222 + int ret = snd_soc_component_set_pll(wm5102_component,
13223 + WM5102_FLL1,
13224 + ARIZONA_CLK_SRC_MCLK1,
13225 + WM8804_CLKOUT_HZ,
13226 + clk_freq);
13227 + if (ret)
13228 + dev_err(card->dev, "Failed to set FLL1 to %d: %d\n",
13229 + clk_freq, ret);
13230 +
13231 + usleep_range(1000, 2000);
13232 + return ret;
13233 +}
13234 +
13235 +static int rpi_cirrus_set_fll_refclk(struct snd_soc_card *card,
13236 + struct snd_soc_component *wm5102_component,
13237 + unsigned int clk_freq, unsigned int aif2_freq)
13238 +{
13239 + int ret = snd_soc_component_set_pll(wm5102_component,
13240 + WM5102_FLL1_REFCLK,
13241 + ARIZONA_CLK_SRC_MCLK1,
13242 + WM8804_CLKOUT_HZ,
13243 + clk_freq);
13244 + if (ret) {
13245 + dev_err(card->dev,
13246 + "Failed to set FLL1_REFCLK to %d: %d\n",
13247 + clk_freq, ret);
13248 + return ret;
13249 + }
13250 +
13251 + ret = snd_soc_component_set_pll(wm5102_component,
13252 + WM5102_FLL1,
13253 + ARIZONA_CLK_SRC_AIF2BCLK,
13254 + aif2_freq, clk_freq);
13255 + if (ret)
13256 + dev_err(card->dev,
13257 + "Failed to set FLL1 with Sync Clock %d to %d: %d\n",
13258 + aif2_freq, clk_freq, ret);
13259 +
13260 + usleep_range(1000, 2000);
13261 + return ret;
13262 +}
13263 +
13264 +static int rpi_cirrus_spdif_rx_enable_event(struct snd_soc_dapm_widget *w,
13265 + struct snd_kcontrol *kcontrol, int event)
13266 +{
13267 + struct snd_soc_card *card = w->dapm->card;
13268 + struct rpi_cirrus_priv *priv = snd_soc_card_get_drvdata(card);
13269 + struct snd_soc_component *wm5102_component =
13270 + asoc_rtd_to_codec(get_wm5102_runtime(card), 0)->component;
13271 +
13272 + unsigned int clk_freq, aif2_freq;
13273 + int ret = 0;
13274 +
13275 + switch (event) {
13276 + case SND_SOC_DAPM_POST_PMU:
13277 + mutex_lock(&priv->lock);
13278 +
13279 + /* Enable sync path in case of SPDIF capture use case */
13280 +
13281 + clk_freq = calc_sysclk(priv->card_rate);
13282 + aif2_freq = 64 * priv->card_rate;
13283 +
13284 + dev_dbg(card->dev,
13285 + "spdif_rx: changing FLL1 to use Ref Clock clk: %d spdif: %d\n",
13286 + clk_freq, aif2_freq);
13287 +
13288 + ret = rpi_cirrus_clear_flls(card, wm5102_component);
13289 + if (ret) {
13290 + dev_err(card->dev, "spdif_rx: failed to clear FLLs\n");
13291 + goto out;
13292 + }
13293 +
13294 + ret = rpi_cirrus_set_fll_refclk(card, wm5102_component,
13295 + clk_freq, aif2_freq);
13296 +
13297 + if (ret) {
13298 + dev_err(card->dev, "spdif_rx: failed to set FLLs\n");
13299 + goto out;
13300 + }
13301 +
13302 + /* set to negative to indicate we're doing spdif rx */
13303 + priv->fll1_freq = -clk_freq;
13304 + priv->sync_path_enable = 1;
13305 + break;
13306 +
13307 + case SND_SOC_DAPM_POST_PMD:
13308 + mutex_lock(&priv->lock);
13309 + priv->sync_path_enable = 0;
13310 + break;
13311 +
13312 + default:
13313 + return 0;
13314 + }
13315 +
13316 +out:
13317 + mutex_unlock(&priv->lock);
13318 + return ret;
13319 +}
13320 +
13321 +static int rpi_cirrus_set_bias_level(struct snd_soc_card *card,
13322 + struct snd_soc_dapm_context *dapm,
13323 + enum snd_soc_bias_level level)
13324 +{
13325 + struct rpi_cirrus_priv *priv = snd_soc_card_get_drvdata(card);
13326 + struct snd_soc_pcm_runtime *wm5102_runtime = get_wm5102_runtime(card);
13327 + struct snd_soc_component *wm5102_component =
13328 + asoc_rtd_to_codec(wm5102_runtime, 0)->component;
13329 +
13330 + int ret = 0;
13331 + unsigned int clk_freq;
13332 +
13333 + if (dapm->dev != asoc_rtd_to_codec(wm5102_runtime, 0)->dev)
13334 + return 0;
13335 +
13336 + switch (level) {
13337 + case SND_SOC_BIAS_PREPARE:
13338 + if (dapm->bias_level == SND_SOC_BIAS_ON)
13339 + break;
13340 +
13341 + mutex_lock(&priv->lock);
13342 +
13343 + if (!priv->sync_path_enable) {
13344 + clk_freq = calc_sysclk(priv->card_rate);
13345 +
13346 + dev_dbg(card->dev,
13347 + "set_bias: changing FLL1 from %d to %d\n",
13348 + priv->fll1_freq, clk_freq);
13349 +
13350 + ret = rpi_cirrus_set_fll(card,
13351 + wm5102_component, clk_freq);
13352 + if (ret)
13353 + dev_err(card->dev,
13354 + "set_bias: Failed to set FLL1\n");
13355 + else
13356 + priv->fll1_freq = clk_freq;
13357 + }
13358 + mutex_unlock(&priv->lock);
13359 + break;
13360 + default:
13361 + break;
13362 + }
13363 +
13364 + return ret;
13365 +}
13366 +
13367 +static int rpi_cirrus_set_bias_level_post(struct snd_soc_card *card,
13368 + struct snd_soc_dapm_context *dapm,
13369 + enum snd_soc_bias_level level)
13370 +{
13371 + struct rpi_cirrus_priv *priv = snd_soc_card_get_drvdata(card);
13372 + struct snd_soc_pcm_runtime *wm5102_runtime = get_wm5102_runtime(card);
13373 + struct snd_soc_component *wm5102_component =
13374 + asoc_rtd_to_codec(wm5102_runtime, 0)->component;
13375 +
13376 + if (dapm->dev != asoc_rtd_to_codec(wm5102_runtime, 0)->dev)
13377 + return 0;
13378 +
13379 + switch (level) {
13380 + case SND_SOC_BIAS_STANDBY:
13381 + mutex_lock(&priv->lock);
13382 +
13383 + dev_dbg(card->dev,
13384 + "set_bias_post: changing FLL1 from %d to off\n",
13385 + priv->fll1_freq);
13386 +
13387 + if (rpi_cirrus_clear_flls(card, wm5102_component))
13388 + dev_err(card->dev,
13389 + "set_bias_post: failed to clear FLLs\n");
13390 + else
13391 + priv->fll1_freq = 0;
13392 +
13393 + mutex_unlock(&priv->lock);
13394 +
13395 + break;
13396 + default:
13397 + break;
13398 + }
13399 +
13400 + return 0;
13401 +}
13402 +
13403 +static int rpi_cirrus_set_wm8804_pll(struct snd_soc_card *card,
13404 + struct snd_soc_dai *wm8804_dai, unsigned int rate)
13405 +{
13406 + int ret;
13407 +
13408 + /* use 256fs */
13409 + unsigned int clk_freq = rate * 256;
13410 +
13411 + ret = snd_soc_dai_set_pll(wm8804_dai, 0, 0,
13412 + WM8804_CLKOUT_HZ, clk_freq);
13413 + if (ret) {
13414 + dev_err(card->dev,
13415 + "Failed to set WM8804 PLL to %d: %d\n", clk_freq, ret);
13416 + return ret;
13417 + }
13418 +
13419 + /* Set MCLK as PLL Output */
13420 + ret = snd_soc_dai_set_sysclk(wm8804_dai,
13421 + WM8804_TX_CLKSRC_PLL, clk_freq, 0);
13422 + if (ret) {
13423 + dev_err(card->dev,
13424 + "Failed to set MCLK as PLL Output: %d\n", ret);
13425 + return ret;
13426 + }
13427 +
13428 + return ret;
13429 +}
13430 +
13431 +static int rpi_cirrus_startup(struct snd_pcm_substream *substream)
13432 +{
13433 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
13434 + struct snd_soc_card *card = rtd->card;
13435 + struct rpi_cirrus_priv *priv = snd_soc_card_get_drvdata(card);
13436 + unsigned int min_rate = min_rates[priv->min_rate_idx].value;
13437 + unsigned int max_rate = max_rates[priv->max_rate_idx].value;
13438 +
13439 + if (min_rate || max_rate) {
13440 + if (max_rate == 0)
13441 + max_rate = UINT_MAX;
13442 +
13443 + dev_dbg(card->dev,
13444 + "startup: limiting rate to %u-%u\n",
13445 + min_rate, max_rate);
13446 +
13447 + snd_pcm_hw_constraint_minmax(substream->runtime,
13448 + SNDRV_PCM_HW_PARAM_RATE, min_rate, max_rate);
13449 + }
13450 +
13451 + return 0;
13452 +}
13453 +
13454 +static struct snd_soc_pcm_stream rpi_cirrus_dai_link2_params = {
13455 + .formats = SNDRV_PCM_FMTBIT_S24_LE,
13456 + .channels_min = 2,
13457 + .channels_max = 2,
13458 + .rate_min = RPI_CIRRUS_DEFAULT_RATE,
13459 + .rate_max = RPI_CIRRUS_DEFAULT_RATE,
13460 +};
13461 +
13462 +static int rpi_cirrus_hw_params(struct snd_pcm_substream *substream,
13463 + struct snd_pcm_hw_params *params)
13464 +{
13465 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
13466 + struct snd_soc_card *card = rtd->card;
13467 + struct rpi_cirrus_priv *priv = snd_soc_card_get_drvdata(card);
13468 + struct snd_soc_dai *bcm_i2s_dai = asoc_rtd_to_cpu(rtd, 0);
13469 + struct snd_soc_component *wm5102_component = asoc_rtd_to_codec(rtd, 0)->component;
13470 + struct snd_soc_dai *wm8804_dai = asoc_rtd_to_codec(get_wm8804_runtime(card), 0);
13471 +
13472 + int ret;
13473 +
13474 + unsigned int width = snd_pcm_format_physical_width(
13475 + params_format(params));
13476 + unsigned int rate = params_rate(params);
13477 + unsigned int clk_freq = calc_sysclk(rate);
13478 +
13479 + mutex_lock(&priv->lock);
13480 +
13481 + dev_dbg(card->dev, "hw_params: setting rate to %d\n", rate);
13482 +
13483 + ret = snd_soc_dai_set_bclk_ratio(bcm_i2s_dai, 2 * width);
13484 + if (ret) {
13485 + dev_err(card->dev, "set_bclk_ratio failed: %d\n", ret);
13486 + goto out;
13487 + }
13488 +
13489 + ret = snd_soc_dai_set_tdm_slot(asoc_rtd_to_codec(rtd, 0), 0x03, 0x03, 2, width);
13490 + if (ret) {
13491 + dev_err(card->dev, "set_tdm_slot failed: %d\n", ret);
13492 + goto out;
13493 + }
13494 +
13495 + /* WM8804 supports sample rates from 32k only */
13496 + if (rate >= 32000) {
13497 + ret = rpi_cirrus_set_wm8804_pll(card, wm8804_dai, rate);
13498 + if (ret)
13499 + goto out;
13500 + }
13501 +
13502 + ret = snd_soc_component_set_sysclk(wm5102_component,
13503 + ARIZONA_CLK_SYSCLK,
13504 + ARIZONA_CLK_SRC_FLL1,
13505 + clk_freq,
13506 + SND_SOC_CLOCK_IN);
13507 + if (ret) {
13508 + dev_err(card->dev, "Failed to set SYSCLK: %d\n", ret);
13509 + goto out;
13510 + }
13511 +
13512 + if ((priv->fll1_freq > 0) && (priv->fll1_freq != clk_freq)) {
13513 + dev_dbg(card->dev,
13514 + "hw_params: changing FLL1 from %d to %d\n",
13515 + priv->fll1_freq, clk_freq);
13516 +
13517 + if (rpi_cirrus_clear_flls(card, wm5102_component)) {
13518 + dev_err(card->dev, "hw_params: failed to clear FLLs\n");
13519 + goto out;
13520 + }
13521 +
13522 + if (rpi_cirrus_set_fll(card, wm5102_component, clk_freq)) {
13523 + dev_err(card->dev, "hw_params: failed to set FLL\n");
13524 + goto out;
13525 + }
13526 +
13527 + priv->fll1_freq = clk_freq;
13528 + }
13529 +
13530 + priv->card_rate = rate;
13531 + rpi_cirrus_dai_link2_params.rate_min = rate;
13532 + rpi_cirrus_dai_link2_params.rate_max = rate;
13533 +
13534 + priv->params_set |= 1 << substream->stream;
13535 +
13536 +out:
13537 + mutex_unlock(&priv->lock);
13538 +
13539 + return ret;
13540 +}
13541 +
13542 +static int rpi_cirrus_hw_free(struct snd_pcm_substream *substream)
13543 +{
13544 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
13545 + struct snd_soc_card *card = rtd->card;
13546 + struct rpi_cirrus_priv *priv = snd_soc_card_get_drvdata(card);
13547 + struct snd_soc_component *wm5102_component = asoc_rtd_to_codec(rtd, 0)->component;
13548 + int ret;
13549 + unsigned int old_params_set = priv->params_set;
13550 +
13551 + priv->params_set &= ~(1 << substream->stream);
13552 +
13553 + /* disable sysclk if this was the last open stream */
13554 + if (priv->params_set == 0 && old_params_set) {
13555 + dev_dbg(card->dev,
13556 + "hw_free: Setting SYSCLK to Zero\n");
13557 +
13558 + ret = snd_soc_component_set_sysclk(wm5102_component,
13559 + ARIZONA_CLK_SYSCLK,
13560 + ARIZONA_CLK_SRC_FLL1,
13561 + 0,
13562 + SND_SOC_CLOCK_IN);
13563 + if (ret)
13564 + dev_err(card->dev,
13565 + "hw_free: Failed to set SYSCLK to Zero: %d\n",
13566 + ret);
13567 + }
13568 + return 0;
13569 +}
13570 +
13571 +static int rpi_cirrus_init_wm5102(struct snd_soc_pcm_runtime *rtd)
13572 +{
13573 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
13574 + int ret;
13575 +
13576 + /* no 32kHz input, derive it from sysclk if needed */
13577 + snd_soc_component_update_bits(component,
13578 + ARIZONA_CLOCK_32K_1, ARIZONA_CLK_32K_SRC_MASK, 2);
13579 +
13580 + if (rpi_cirrus_clear_flls(rtd->card, component))
13581 + dev_warn(rtd->card->dev,
13582 + "init_wm5102: failed to clear FLLs\n");
13583 +
13584 + ret = snd_soc_component_set_sysclk(component,
13585 + ARIZONA_CLK_SYSCLK, ARIZONA_CLK_SRC_FLL1,
13586 + 0, SND_SOC_CLOCK_IN);
13587 + if (ret) {
13588 + dev_err(rtd->card->dev,
13589 + "Failed to set SYSCLK to Zero: %d\n", ret);
13590 + return ret;
13591 + }
13592 +
13593 + return 0;
13594 +}
13595 +
13596 +static int rpi_cirrus_init_wm8804(struct snd_soc_pcm_runtime *rtd)
13597 +{
13598 + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
13599 + struct snd_soc_component *component = codec_dai->component;
13600 + struct snd_soc_card *card = rtd->card;
13601 + struct rpi_cirrus_priv *priv = snd_soc_card_get_drvdata(card);
13602 + unsigned int val, mask;
13603 + int i, ret;
13604 +
13605 + for (i = 0; i < 4; i++) {
13606 + val = snd_soc_component_read(component,
13607 + WM8804_SPDTX1 + i);
13608 + mask = (i == 3) ? 0x3f : 0xff;
13609 + priv->iec958_status[i] = val & mask;
13610 + }
13611 +
13612 + /* Setup for 256fs */
13613 + ret = snd_soc_dai_set_clkdiv(codec_dai,
13614 + WM8804_MCLK_DIV, WM8804_MCLKDIV_256FS);
13615 + if (ret) {
13616 + dev_err(card->dev,
13617 + "init_wm8804: Failed to set MCLK_DIV to 256fs: %d\n",
13618 + ret);
13619 + return ret;
13620 + }
13621 +
13622 + /* Output OSC on CLKOUT */
13623 + ret = snd_soc_dai_set_sysclk(codec_dai,
13624 + WM8804_CLKOUT_SRC_OSCCLK, WM8804_CLKOUT_HZ, 0);
13625 + if (ret)
13626 + dev_err(card->dev,
13627 + "init_wm8804: Failed to set CLKOUT as OSC Frequency: %d\n",
13628 + ret);
13629 +
13630 + /* Init PLL with default samplerate */
13631 + ret = rpi_cirrus_set_wm8804_pll(card, codec_dai,
13632 + RPI_CIRRUS_DEFAULT_RATE);
13633 + if (ret)
13634 + dev_err(card->dev,
13635 + "init_wm8804: Failed to setup PLL for %dHz: %d\n",
13636 + RPI_CIRRUS_DEFAULT_RATE, ret);
13637 +
13638 + return ret;
13639 +}
13640 +
13641 +static struct snd_soc_ops rpi_cirrus_ops = {
13642 + .startup = rpi_cirrus_startup,
13643 + .hw_params = rpi_cirrus_hw_params,
13644 + .hw_free = rpi_cirrus_hw_free,
13645 +};
13646 +
13647 +SND_SOC_DAILINK_DEFS(wm5102,
13648 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
13649 + DAILINK_COMP_ARRAY(COMP_CODEC("wm5102-codec", "wm5102-aif1")),
13650 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
13651 +
13652 +SND_SOC_DAILINK_DEFS(wm8804,
13653 + DAILINK_COMP_ARRAY(COMP_CPU("wm5102-aif2")),
13654 + DAILINK_COMP_ARRAY(COMP_CODEC("wm8804.1-003b", "wm8804-spdif")));
13655 +
13656 +static struct snd_soc_dai_link rpi_cirrus_dai[] = {
13657 + [DAI_WM5102] = {
13658 + .name = "WM5102",
13659 + .stream_name = "WM5102 AiFi",
13660 + .dai_fmt = SND_SOC_DAIFMT_I2S
13661 + | SND_SOC_DAIFMT_NB_NF
13662 + | SND_SOC_DAIFMT_CBM_CFM,
13663 + .ops = &rpi_cirrus_ops,
13664 + .init = rpi_cirrus_init_wm5102,
13665 + SND_SOC_DAILINK_REG(wm5102),
13666 + },
13667 + [DAI_WM8804] = {
13668 + .name = "WM5102 SPDIF",
13669 + .stream_name = "SPDIF Tx/Rx",
13670 + .dai_fmt = SND_SOC_DAIFMT_I2S
13671 + | SND_SOC_DAIFMT_NB_NF
13672 + | SND_SOC_DAIFMT_CBM_CFM,
13673 + .ignore_suspend = 1,
13674 + .c2c_params = &rpi_cirrus_dai_link2_params,
13675 + .init = rpi_cirrus_init_wm8804,
13676 + SND_SOC_DAILINK_REG(wm8804),
13677 + },
13678 +};
13679 +
13680 +
13681 +static int rpi_cirrus_late_probe(struct snd_soc_card *card)
13682 +{
13683 + struct rpi_cirrus_priv *priv = snd_soc_card_get_drvdata(card);
13684 + struct snd_soc_pcm_runtime *wm5102_runtime = get_wm5102_runtime(card);
13685 + struct snd_soc_pcm_runtime *wm8804_runtime = get_wm8804_runtime(card);
13686 + int ret;
13687 +
13688 + dev_dbg(card->dev, "iec958_bits: %02x %02x %02x %02x\n",
13689 + priv->iec958_status[0],
13690 + priv->iec958_status[1],
13691 + priv->iec958_status[2],
13692 + priv->iec958_status[3]);
13693 +
13694 + ret = snd_soc_dai_set_sysclk(
13695 + asoc_rtd_to_codec(wm5102_runtime, 0), ARIZONA_CLK_SYSCLK, 0, 0);
13696 + if (ret) {
13697 + dev_err(card->dev,
13698 + "Failed to set WM5102 codec dai clk domain: %d\n", ret);
13699 + return ret;
13700 + }
13701 +
13702 + ret = snd_soc_dai_set_sysclk(
13703 + asoc_rtd_to_cpu(wm8804_runtime, 0), ARIZONA_CLK_SYSCLK, 0, 0);
13704 + if (ret)
13705 + dev_err(card->dev,
13706 + "Failed to set WM8804 codec dai clk domain: %d\n", ret);
13707 +
13708 + return ret;
13709 +}
13710 +
13711 +/* audio machine driver */
13712 +static struct snd_soc_card rpi_cirrus_card = {
13713 + .name = "RPi-Cirrus",
13714 + .driver_name = "RPiCirrus",
13715 + .owner = THIS_MODULE,
13716 + .dai_link = rpi_cirrus_dai,
13717 + .num_links = ARRAY_SIZE(rpi_cirrus_dai),
13718 + .late_probe = rpi_cirrus_late_probe,
13719 + .controls = rpi_cirrus_controls,
13720 + .num_controls = ARRAY_SIZE(rpi_cirrus_controls),
13721 + .dapm_widgets = rpi_cirrus_dapm_widgets,
13722 + .num_dapm_widgets = ARRAY_SIZE(rpi_cirrus_dapm_widgets),
13723 + .dapm_routes = rpi_cirrus_dapm_routes,
13724 + .num_dapm_routes = ARRAY_SIZE(rpi_cirrus_dapm_routes),
13725 + .set_bias_level = rpi_cirrus_set_bias_level,
13726 + .set_bias_level_post = rpi_cirrus_set_bias_level_post,
13727 +};
13728 +
13729 +static int rpi_cirrus_probe(struct platform_device *pdev)
13730 +{
13731 + int ret = 0;
13732 + struct rpi_cirrus_priv *priv;
13733 + struct device_node *i2s_node;
13734 +
13735 + priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
13736 + if (!priv)
13737 + return -ENOMEM;
13738 +
13739 + priv->min_rate_idx = 1; /* min samplerate 32kHz */
13740 + priv->card_rate = RPI_CIRRUS_DEFAULT_RATE;
13741 +
13742 + mutex_init(&priv->lock);
13743 +
13744 + snd_soc_card_set_drvdata(&rpi_cirrus_card, priv);
13745 +
13746 + if (!pdev->dev.of_node)
13747 + return -ENODEV;
13748 +
13749 + i2s_node = of_parse_phandle(
13750 + pdev->dev.of_node, "i2s-controller", 0);
13751 + if (!i2s_node) {
13752 + dev_err(&pdev->dev, "i2s-controller missing in DT\n");
13753 + return -ENODEV;
13754 + }
13755 +
13756 + rpi_cirrus_dai[DAI_WM5102].cpus->of_node = i2s_node;
13757 + rpi_cirrus_dai[DAI_WM5102].platforms->of_node = i2s_node;
13758 +
13759 + rpi_cirrus_card.dev = &pdev->dev;
13760 +
13761 + ret = devm_snd_soc_register_card(&pdev->dev, &rpi_cirrus_card);
13762 + if (ret) {
13763 + if (ret == -EPROBE_DEFER)
13764 + dev_dbg(&pdev->dev,
13765 + "register card requested probe deferral\n");
13766 + else
13767 + dev_err(&pdev->dev,
13768 + "Failed to register card: %d\n", ret);
13769 + }
13770 +
13771 + return ret;
13772 +}
13773 +
13774 +static const struct of_device_id rpi_cirrus_of_match[] = {
13775 + { .compatible = "wlf,rpi-cirrus", },
13776 + {},
13777 +};
13778 +MODULE_DEVICE_TABLE(of, rpi_cirrus_of_match);
13779 +
13780 +static struct platform_driver rpi_cirrus_driver = {
13781 + .driver = {
13782 + .name = "snd-rpi-cirrus",
13783 + .of_match_table = of_match_ptr(rpi_cirrus_of_match),
13784 + },
13785 + .probe = rpi_cirrus_probe,
13786 +};
13787 +
13788 +module_platform_driver(rpi_cirrus_driver);
13789 +
13790 +MODULE_AUTHOR("Matthias Reichl <hias@horus.com>");
13791 +MODULE_DESCRIPTION("ASoC driver for Cirrus Logic Audio Card");
13792 +MODULE_LICENSE("GPL");
13793 --- /dev/null
13794 +++ b/sound/soc/bcm/rpi-proto.c
13795 @@ -0,0 +1,147 @@
13796 +/*
13797 + * ASoC driver for PROTO AudioCODEC (with a WM8731)
13798 + * connected to a Raspberry Pi
13799 + *
13800 + * Author: Florian Meier, <koalo@koalo.de>
13801 + * Copyright 2013
13802 + *
13803 + * This program is free software; you can redistribute it and/or modify
13804 + * it under the terms of the GNU General Public License version 2 as
13805 + * published by the Free Software Foundation.
13806 + */
13807 +
13808 +#include <linux/module.h>
13809 +#include <linux/platform_device.h>
13810 +
13811 +#include <sound/core.h>
13812 +#include <sound/pcm.h>
13813 +#include <sound/soc.h>
13814 +#include <sound/jack.h>
13815 +
13816 +#include "../codecs/wm8731.h"
13817 +
13818 +static const unsigned int wm8731_rates_12288000[] = {
13819 + 8000, 32000, 48000, 96000,
13820 +};
13821 +
13822 +static struct snd_pcm_hw_constraint_list wm8731_constraints_12288000 = {
13823 + .list = wm8731_rates_12288000,
13824 + .count = ARRAY_SIZE(wm8731_rates_12288000),
13825 +};
13826 +
13827 +static int snd_rpi_proto_startup(struct snd_pcm_substream *substream)
13828 +{
13829 + /* Setup constraints, because there is a 12.288 MHz XTAL on the board */
13830 + snd_pcm_hw_constraint_list(substream->runtime, 0,
13831 + SNDRV_PCM_HW_PARAM_RATE,
13832 + &wm8731_constraints_12288000);
13833 + return 0;
13834 +}
13835 +
13836 +static int snd_rpi_proto_hw_params(struct snd_pcm_substream *substream,
13837 + struct snd_pcm_hw_params *params)
13838 +{
13839 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
13840 + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
13841 + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
13842 + int sysclk = 12288000; /* This is fixed on this board */
13843 +
13844 + /* Set proto bclk */
13845 + int ret = snd_soc_dai_set_bclk_ratio(cpu_dai,32*2);
13846 + if (ret < 0){
13847 + dev_err(rtd->card->dev,
13848 + "Failed to set BCLK ratio %d\n", ret);
13849 + return ret;
13850 + }
13851 +
13852 + /* Set proto sysclk */
13853 + ret = snd_soc_dai_set_sysclk(codec_dai, WM8731_SYSCLK_XTAL,
13854 + sysclk, SND_SOC_CLOCK_IN);
13855 + if (ret < 0) {
13856 + dev_err(rtd->card->dev,
13857 + "Failed to set WM8731 SYSCLK: %d\n", ret);
13858 + return ret;
13859 + }
13860 +
13861 + return 0;
13862 +}
13863 +
13864 +/* machine stream operations */
13865 +static struct snd_soc_ops snd_rpi_proto_ops = {
13866 + .startup = snd_rpi_proto_startup,
13867 + .hw_params = snd_rpi_proto_hw_params,
13868 +};
13869 +
13870 +SND_SOC_DAILINK_DEFS(rpi_proto,
13871 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
13872 + DAILINK_COMP_ARRAY(COMP_CODEC("wm8731.1-001a", "wm8731-hifi")),
13873 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
13874 +
13875 +static struct snd_soc_dai_link snd_rpi_proto_dai[] = {
13876 +{
13877 + .name = "WM8731",
13878 + .stream_name = "WM8731 HiFi",
13879 + .dai_fmt = SND_SOC_DAIFMT_I2S
13880 + | SND_SOC_DAIFMT_NB_NF
13881 + | SND_SOC_DAIFMT_CBM_CFM,
13882 + .ops = &snd_rpi_proto_ops,
13883 + SND_SOC_DAILINK_REG(rpi_proto),
13884 +},
13885 +};
13886 +
13887 +/* audio machine driver */
13888 +static struct snd_soc_card snd_rpi_proto = {
13889 + .name = "snd_rpi_proto",
13890 + .owner = THIS_MODULE,
13891 + .dai_link = snd_rpi_proto_dai,
13892 + .num_links = ARRAY_SIZE(snd_rpi_proto_dai),
13893 +};
13894 +
13895 +static int snd_rpi_proto_probe(struct platform_device *pdev)
13896 +{
13897 + int ret = 0;
13898 +
13899 + snd_rpi_proto.dev = &pdev->dev;
13900 +
13901 + if (pdev->dev.of_node) {
13902 + struct device_node *i2s_node;
13903 + struct snd_soc_dai_link *dai = &snd_rpi_proto_dai[0];
13904 + i2s_node = of_parse_phandle(pdev->dev.of_node,
13905 + "i2s-controller", 0);
13906 +
13907 + if (i2s_node) {
13908 + dai->cpus->dai_name = NULL;
13909 + dai->cpus->of_node = i2s_node;
13910 + dai->platforms->name = NULL;
13911 + dai->platforms->of_node = i2s_node;
13912 + }
13913 + }
13914 +
13915 + ret = devm_snd_soc_register_card(&pdev->dev, &snd_rpi_proto);
13916 + if (ret && ret != -EPROBE_DEFER)
13917 + dev_err(&pdev->dev,
13918 + "snd_soc_register_card() failed: %d\n", ret);
13919 +
13920 + return ret;
13921 +}
13922 +
13923 +static const struct of_device_id snd_rpi_proto_of_match[] = {
13924 + { .compatible = "rpi,rpi-proto", },
13925 + {},
13926 +};
13927 +MODULE_DEVICE_TABLE(of, snd_rpi_proto_of_match);
13928 +
13929 +static struct platform_driver snd_rpi_proto_driver = {
13930 + .driver = {
13931 + .name = "snd-rpi-proto",
13932 + .owner = THIS_MODULE,
13933 + .of_match_table = snd_rpi_proto_of_match,
13934 + },
13935 + .probe = snd_rpi_proto_probe,
13936 +};
13937 +
13938 +module_platform_driver(snd_rpi_proto_driver);
13939 +
13940 +MODULE_AUTHOR("Florian Meier");
13941 +MODULE_DESCRIPTION("ASoC Driver for Raspberry Pi connected to PROTO board (WM8731)");
13942 +MODULE_LICENSE("GPL");
13943 --- /dev/null
13944 +++ b/sound/soc/bcm/rpi-simple-soundcard.c
13945 @@ -0,0 +1,487 @@
13946 +// SPDX-License-Identifier: GPL-2.0
13947 +/*
13948 + * rpi-simple-soundcard.c -- ALSA SoC Raspberry Pi soundcard.
13949 + *
13950 + * Copyright (C) 2018 Raspberry Pi.
13951 + *
13952 + * Authors: Tim Gover <tim.gover@raspberrypi.org>
13953 + *
13954 + * Based on code:
13955 + * hifiberry_amp.c, hifiberry_dac.c, rpi-dac.c
13956 + * by Florian Meier <florian.meier@koalo.de>
13957 + *
13958 + * googlevoicehat-soundcard.c
13959 + * by Peter Malkin <petermalkin@google.com>
13960 + *
13961 + * adau1977-adc.c
13962 + * by Andrey Grodzovsky <andrey2805@gmail.com>
13963 + *
13964 + * merus-amp.c
13965 + * by Ariel Muszkat <ariel.muszkat@gmail.com>
13966 + * Jorgen Kragh Jakobsen <jorgen.kraghjakobsen@infineon.com>
13967 + *
13968 + * This program is free software; you can redistribute it and/or
13969 + * modify it under the terms of the GNU General Public License
13970 + * version 2 as published by the Free Software Foundation.
13971 + *
13972 + * This program is distributed in the hope that it will be useful, but
13973 + * WITHOUT ANY WARRANTY; without even the implied warranty of
13974 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13975 + * General Public License for more details.
13976 + */
13977 +
13978 +#include <linux/module.h>
13979 +#include <linux/platform_device.h>
13980 +#include <linux/gpio/consumer.h>
13981 +
13982 +#include <sound/core.h>
13983 +#include <sound/pcm.h>
13984 +#include <sound/pcm_params.h>
13985 +#include <sound/soc.h>
13986 +
13987 +/* Parameters for generic RPI functions */
13988 +struct snd_rpi_simple_drvdata {
13989 + struct snd_soc_dai_link *dai;
13990 + const char* card_name;
13991 + unsigned int fixed_bclk_ratio;
13992 +};
13993 +
13994 +static struct snd_soc_card snd_rpi_simple = {
13995 + .driver_name = "RPi-simple",
13996 + .owner = THIS_MODULE,
13997 + .dai_link = NULL,
13998 + .num_links = 1, /* Only a single DAI supported at the moment */
13999 +};
14000 +
14001 +static int snd_rpi_simple_init(struct snd_soc_pcm_runtime *rtd)
14002 +{
14003 + struct snd_rpi_simple_drvdata *drvdata =
14004 + snd_soc_card_get_drvdata(rtd->card);
14005 + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
14006 +
14007 + if (drvdata->fixed_bclk_ratio > 0)
14008 + return snd_soc_dai_set_bclk_ratio(cpu_dai,
14009 + drvdata->fixed_bclk_ratio);
14010 +
14011 + return 0;
14012 +}
14013 +
14014 +static int pifi_mini_210_init(struct snd_soc_pcm_runtime *rtd)
14015 +{
14016 + struct snd_soc_component *dac;
14017 + struct gpio_desc *pdn_gpio, *rst_gpio;
14018 + struct snd_soc_dai *codec_dai;
14019 + int ret;
14020 +
14021 + snd_rpi_simple_init(rtd);
14022 + codec_dai = asoc_rtd_to_codec(rtd, 0);
14023 +
14024 + dac = codec_dai[0].component;
14025 +
14026 + pdn_gpio = devm_gpiod_get_optional(snd_rpi_simple.dev, "pdn",
14027 + GPIOD_OUT_LOW);
14028 + if (IS_ERR(pdn_gpio)) {
14029 + ret = PTR_ERR(pdn_gpio);
14030 + dev_err(snd_rpi_simple.dev, "failed to get pdn gpio: %d\n", ret);
14031 + return ret;
14032 + }
14033 +
14034 + rst_gpio = devm_gpiod_get_optional(snd_rpi_simple.dev, "rst",
14035 + GPIOD_OUT_LOW);
14036 + if (IS_ERR(rst_gpio)) {
14037 + ret = PTR_ERR(rst_gpio);
14038 + dev_err(snd_rpi_simple.dev, "failed to get rst gpio: %d\n", ret);
14039 + return ret;
14040 + }
14041 +
14042 + // Set up cards - pulse power down and reset first, then
14043 + // set up according to datasheet
14044 + gpiod_set_value_cansleep(pdn_gpio, 1);
14045 + gpiod_set_value_cansleep(rst_gpio, 1);
14046 + usleep_range(1000, 10000);
14047 + gpiod_set_value_cansleep(pdn_gpio, 0);
14048 + usleep_range(20000, 30000);
14049 + gpiod_set_value_cansleep(rst_gpio, 0);
14050 + usleep_range(20000, 30000);
14051 +
14052 + // Oscillator trim
14053 + snd_soc_component_write(dac, 0x1b, 0);
14054 + usleep_range(60000, 80000);
14055 +
14056 + // MCLK at 64fs, sample rate 44.1 or 48kHz
14057 + snd_soc_component_write(dac, 0x00, 0x60);
14058 +
14059 + // Set up for BTL - AD/BD mode - AD is 0x00107772, BD is 0x00987772
14060 + snd_soc_component_write(dac, 0x20, 0x00107772);
14061 +
14062 + // End mute
14063 + snd_soc_component_write(dac, 0x05, 0x00);
14064 +
14065 + return 0;
14066 +}
14067 +
14068 +static int snd_rpi_simple_hw_params(struct snd_pcm_substream *substream,
14069 + struct snd_pcm_hw_params *params)
14070 +{
14071 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
14072 + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
14073 + struct snd_rpi_simple_drvdata *drvdata;
14074 + unsigned int sample_bits;
14075 +
14076 + drvdata = snd_soc_card_get_drvdata(rtd->card);
14077 +
14078 + if (drvdata->fixed_bclk_ratio > 0)
14079 + return 0; // BCLK is configured in .init
14080 +
14081 + /* The simple drivers just set the bclk_ratio to sample_bits * 2 so
14082 + * hard-code this for now. More complex drivers could just replace
14083 + * the hw_params routine.
14084 + */
14085 + sample_bits = snd_pcm_format_physical_width(params_format(params));
14086 + return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);
14087 +}
14088 +
14089 +static struct snd_soc_ops snd_rpi_simple_ops = {
14090 + .hw_params = snd_rpi_simple_hw_params,
14091 +};
14092 +
14093 +static int snd_merus_amp_hw_params(struct snd_pcm_substream *substream,
14094 + struct snd_pcm_hw_params *params)
14095 +{
14096 + struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
14097 + int rate;
14098 +
14099 + rate = params_rate(params);
14100 + if (rate > 48000) {
14101 + dev_err(rtd->card->dev,
14102 + "Unsupported samplerate %d\n",
14103 + rate);
14104 + return -EINVAL;
14105 + }
14106 + return 0;
14107 +}
14108 +
14109 +static struct snd_soc_ops snd_merus_amp_ops = {
14110 + .hw_params = snd_merus_amp_hw_params,
14111 +};
14112 +
14113 +enum adau1977_clk_id {
14114 + ADAU1977_SYSCLK,
14115 +};
14116 +
14117 +enum adau1977_sysclk_src {
14118 + ADAU1977_SYSCLK_SRC_MCLK,
14119 + ADAU1977_SYSCLK_SRC_LRCLK,
14120 +};
14121 +
14122 +static int adau1977_init(struct snd_soc_pcm_runtime *rtd)
14123 +{
14124 + int ret;
14125 + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
14126 +
14127 + ret = snd_soc_dai_set_tdm_slot(codec_dai, 0, 0, 0, 0);
14128 + if (ret < 0)
14129 + return ret;
14130 +
14131 + return snd_soc_component_set_sysclk(codec_dai->component,
14132 + ADAU1977_SYSCLK, ADAU1977_SYSCLK_SRC_MCLK,
14133 + 11289600, SND_SOC_CLOCK_IN);
14134 +}
14135 +
14136 +SND_SOC_DAILINK_DEFS(adau1977,
14137 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
14138 + DAILINK_COMP_ARRAY(COMP_CODEC("adau1977.1-0011", "adau1977-hifi")),
14139 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
14140 +
14141 +static struct snd_soc_dai_link snd_rpi_adau1977_dai[] = {
14142 + {
14143 + .name = "adau1977",
14144 + .stream_name = "ADAU1977",
14145 + .init = adau1977_init,
14146 + .dai_fmt = SND_SOC_DAIFMT_I2S |
14147 + SND_SOC_DAIFMT_NB_NF |
14148 + SND_SOC_DAIFMT_CBM_CFM,
14149 + SND_SOC_DAILINK_REG(adau1977),
14150 + },
14151 +};
14152 +
14153 +static struct snd_rpi_simple_drvdata drvdata_adau1977 = {
14154 + .card_name = "snd_rpi_adau1977_adc",
14155 + .dai = snd_rpi_adau1977_dai,
14156 +};
14157 +
14158 +SND_SOC_DAILINK_DEFS(gvchat,
14159 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
14160 + DAILINK_COMP_ARRAY(COMP_CODEC("voicehat-codec", "voicehat-hifi")),
14161 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
14162 +
14163 +static struct snd_soc_dai_link snd_googlevoicehat_soundcard_dai[] = {
14164 +{
14165 + .name = "Google voiceHAT SoundCard",
14166 + .stream_name = "Google voiceHAT SoundCard HiFi",
14167 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
14168 + SND_SOC_DAIFMT_CBS_CFS,
14169 + SND_SOC_DAILINK_REG(gvchat),
14170 +},
14171 +};
14172 +
14173 +static struct snd_rpi_simple_drvdata drvdata_googlevoicehat = {
14174 + .card_name = "snd_rpi_googlevoicehat_soundcard",
14175 + .dai = snd_googlevoicehat_soundcard_dai,
14176 +};
14177 +
14178 +SND_SOC_DAILINK_DEFS(hifiberry_dacplusdsp,
14179 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
14180 + DAILINK_COMP_ARRAY(COMP_CODEC("dacplusdsp-codec", "dacplusdsp-hifi")),
14181 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
14182 +
14183 +static struct snd_soc_dai_link snd_hifiberrydacplusdsp_soundcard_dai[] = {
14184 +{
14185 + .name = "Hifiberry DAC+DSP SoundCard",
14186 + .stream_name = "Hifiberry DAC+DSP SoundCard HiFi",
14187 + .dai_fmt = SND_SOC_DAIFMT_I2S |
14188 + SND_SOC_DAIFMT_NB_NF |
14189 + SND_SOC_DAIFMT_CBS_CFS,
14190 + SND_SOC_DAILINK_REG(hifiberry_dacplusdsp),
14191 +},
14192 +};
14193 +
14194 +static struct snd_rpi_simple_drvdata drvdata_hifiberrydacplusdsp = {
14195 + .card_name = "snd_rpi_hifiberrydacplusdsp_soundcard",
14196 + .dai = snd_hifiberrydacplusdsp_soundcard_dai,
14197 +};
14198 +
14199 +SND_SOC_DAILINK_DEFS(hifiberry_amp,
14200 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
14201 + DAILINK_COMP_ARRAY(COMP_CODEC("tas5713.1-001b", "tas5713-hifi")),
14202 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
14203 +
14204 +static struct snd_soc_dai_link snd_hifiberry_amp_dai[] = {
14205 + {
14206 + .name = "HifiBerry AMP",
14207 + .stream_name = "HifiBerry AMP HiFi",
14208 + .dai_fmt = SND_SOC_DAIFMT_I2S |
14209 + SND_SOC_DAIFMT_NB_NF |
14210 + SND_SOC_DAIFMT_CBS_CFS,
14211 + SND_SOC_DAILINK_REG(hifiberry_amp),
14212 + },
14213 +};
14214 +
14215 +static struct snd_rpi_simple_drvdata drvdata_hifiberry_amp = {
14216 + .card_name = "snd_rpi_hifiberry_amp",
14217 + .dai = snd_hifiberry_amp_dai,
14218 + .fixed_bclk_ratio = 64,
14219 +};
14220 +
14221 +SND_SOC_DAILINK_DEFS(hifiberry_amp3,
14222 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
14223 + DAILINK_COMP_ARRAY(COMP_CODEC("ma120x0p.1-0020", "ma120x0p-amp")),
14224 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
14225 +
14226 +static struct snd_soc_dai_link snd_hifiberry_amp3_dai[] = {
14227 + {
14228 + .name = "HifiberryAmp3",
14229 + .stream_name = "Hifiberry Amp3",
14230 + .dai_fmt = SND_SOC_DAIFMT_I2S |
14231 + SND_SOC_DAIFMT_NB_NF |
14232 + SND_SOC_DAIFMT_CBS_CFS,
14233 + SND_SOC_DAILINK_REG(hifiberry_amp3),
14234 + },
14235 +};
14236 +
14237 +static struct snd_rpi_simple_drvdata drvdata_hifiberry_amp3 = {
14238 + .card_name = "snd_rpi_hifiberry_amp3",
14239 + .dai = snd_hifiberry_amp3_dai,
14240 + .fixed_bclk_ratio = 64,
14241 +};
14242 +
14243 +SND_SOC_DAILINK_DEFS(hifiberry_dac,
14244 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
14245 + DAILINK_COMP_ARRAY(COMP_CODEC("pcm5102a-codec", "pcm5102a-hifi")),
14246 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
14247 +
14248 +static struct snd_soc_dai_link snd_hifiberry_dac_dai[] = {
14249 + {
14250 + .name = "HifiBerry DAC",
14251 + .stream_name = "HifiBerry DAC HiFi",
14252 + .dai_fmt = SND_SOC_DAIFMT_I2S |
14253 + SND_SOC_DAIFMT_NB_NF |
14254 + SND_SOC_DAIFMT_CBS_CFS,
14255 + SND_SOC_DAILINK_REG(hifiberry_dac),
14256 + },
14257 +};
14258 +
14259 +static struct snd_rpi_simple_drvdata drvdata_hifiberry_dac = {
14260 + .card_name = "snd_rpi_hifiberry_dac",
14261 + .dai = snd_hifiberry_dac_dai,
14262 +};
14263 +
14264 +SND_SOC_DAILINK_DEFS(dionaudio_kiwi,
14265 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
14266 + DAILINK_COMP_ARRAY(COMP_CODEC("pcm1794a-codec", "pcm1794a-hifi")),
14267 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
14268 +
14269 +static struct snd_soc_dai_link snd_dionaudio_kiwi_dai[] = {
14270 +{
14271 + .name = "DionAudio KIWI",
14272 + .stream_name = "DionAudio KIWI STREAMER",
14273 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
14274 + SND_SOC_DAIFMT_CBS_CFS,
14275 + SND_SOC_DAILINK_REG(dionaudio_kiwi),
14276 +},
14277 +};
14278 +
14279 +static struct snd_rpi_simple_drvdata drvdata_dionaudio_kiwi = {
14280 + .card_name = "snd_rpi_dionaudio_kiwi",
14281 + .dai = snd_dionaudio_kiwi_dai,
14282 + .fixed_bclk_ratio = 64,
14283 +};
14284 +
14285 +SND_SOC_DAILINK_DEFS(rpi_dac,
14286 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
14287 + DAILINK_COMP_ARRAY(COMP_CODEC("pcm1794a-codec", "pcm1794a-hifi")),
14288 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
14289 +
14290 +static struct snd_soc_dai_link snd_rpi_dac_dai[] = {
14291 +{
14292 + .name = "RPi-DAC",
14293 + .stream_name = "RPi-DAC HiFi",
14294 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
14295 + SND_SOC_DAIFMT_CBS_CFS,
14296 + SND_SOC_DAILINK_REG(rpi_dac),
14297 +},
14298 +};
14299 +
14300 +static struct snd_rpi_simple_drvdata drvdata_rpi_dac = {
14301 + .card_name = "snd_rpi_rpi_dac",
14302 + .dai = snd_rpi_dac_dai,
14303 + .fixed_bclk_ratio = 64,
14304 +};
14305 +
14306 +SND_SOC_DAILINK_DEFS(merus_amp,
14307 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
14308 + DAILINK_COMP_ARRAY(COMP_CODEC("ma120x0p.1-0020", "ma120x0p-amp")),
14309 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
14310 +
14311 +static struct snd_soc_dai_link snd_merus_amp_dai[] = {
14312 + {
14313 + .name = "MerusAmp",
14314 + .stream_name = "Merus Audio Amp",
14315 + .ops = &snd_merus_amp_ops,
14316 + .dai_fmt = SND_SOC_DAIFMT_I2S |
14317 + SND_SOC_DAIFMT_NB_NF |
14318 + SND_SOC_DAIFMT_CBS_CFS,
14319 + SND_SOC_DAILINK_REG(merus_amp),
14320 + },
14321 +};
14322 +
14323 +static struct snd_rpi_simple_drvdata drvdata_merus_amp = {
14324 + .card_name = "snd_rpi_merus_amp",
14325 + .dai = snd_merus_amp_dai,
14326 + .fixed_bclk_ratio = 64,
14327 +};
14328 +
14329 +SND_SOC_DAILINK_DEFS(pifi_mini_210,
14330 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
14331 + DAILINK_COMP_ARRAY(COMP_CODEC("tas571x.1-001a", "tas571x-hifi")),
14332 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
14333 +
14334 +static struct snd_soc_dai_link snd_pifi_mini_210_dai[] = {
14335 + {
14336 + .name = "PiFi Mini 210",
14337 + .stream_name = "PiFi Mini 210 HiFi",
14338 + .init = pifi_mini_210_init,
14339 + .dai_fmt = SND_SOC_DAIFMT_I2S |
14340 + SND_SOC_DAIFMT_NB_NF |
14341 + SND_SOC_DAIFMT_CBS_CFS,
14342 + SND_SOC_DAILINK_REG(pifi_mini_210),
14343 + },
14344 +};
14345 +
14346 +static struct snd_rpi_simple_drvdata drvdata_pifi_mini_210 = {
14347 + .card_name = "snd_pifi_mini_210",
14348 + .dai = snd_pifi_mini_210_dai,
14349 + .fixed_bclk_ratio = 64,
14350 +};
14351 +
14352 +static const struct of_device_id snd_rpi_simple_of_match[] = {
14353 + { .compatible = "adi,adau1977-adc",
14354 + .data = (void *) &drvdata_adau1977 },
14355 + { .compatible = "googlevoicehat,googlevoicehat-soundcard",
14356 + .data = (void *) &drvdata_googlevoicehat },
14357 + { .compatible = "hifiberrydacplusdsp,hifiberrydacplusdsp-soundcard",
14358 + .data = (void *) &drvdata_hifiberrydacplusdsp },
14359 + { .compatible = "hifiberry,hifiberry-amp",
14360 + .data = (void *) &drvdata_hifiberry_amp },
14361 + { .compatible = "hifiberry,hifiberry-amp3",
14362 + .data = (void *) &drvdata_hifiberry_amp3 },
14363 + { .compatible = "hifiberry,hifiberry-dac",
14364 + .data = (void *) &drvdata_hifiberry_dac },
14365 + { .compatible = "dionaudio,dionaudio-kiwi",
14366 + .data = (void *) &drvdata_dionaudio_kiwi },
14367 + { .compatible = "rpi,rpi-dac", &drvdata_rpi_dac},
14368 + { .compatible = "merus,merus-amp",
14369 + .data = (void *) &drvdata_merus_amp },
14370 + { .compatible = "pifi,pifi-mini-210",
14371 + .data = (void *) &drvdata_pifi_mini_210 },
14372 + {},
14373 +};
14374 +
14375 +static int snd_rpi_simple_probe(struct platform_device *pdev)
14376 +{
14377 + int ret = 0;
14378 + const struct of_device_id *of_id;
14379 +
14380 + snd_rpi_simple.dev = &pdev->dev;
14381 + of_id = of_match_node(snd_rpi_simple_of_match, pdev->dev.of_node);
14382 +
14383 + if (pdev->dev.of_node && of_id->data) {
14384 + struct device_node *i2s_node;
14385 + struct snd_rpi_simple_drvdata *drvdata =
14386 + (struct snd_rpi_simple_drvdata *) of_id->data;
14387 + struct snd_soc_dai_link *dai = drvdata->dai;
14388 +
14389 + snd_soc_card_set_drvdata(&snd_rpi_simple, drvdata);
14390 +
14391 + /* More complex drivers might override individual functions */
14392 + if (!dai->init)
14393 + dai->init = snd_rpi_simple_init;
14394 + if (!dai->ops)
14395 + dai->ops = &snd_rpi_simple_ops;
14396 +
14397 + snd_rpi_simple.name = drvdata->card_name;
14398 +
14399 + snd_rpi_simple.dai_link = dai;
14400 + i2s_node = of_parse_phandle(pdev->dev.of_node,
14401 + "i2s-controller", 0);
14402 + if (!i2s_node) {
14403 + pr_err("Failed to find i2s-controller DT node\n");
14404 + return -ENODEV;
14405 + }
14406 +
14407 + dai->cpus->of_node = i2s_node;
14408 + dai->platforms->of_node = i2s_node;
14409 + }
14410 +
14411 + ret = devm_snd_soc_register_card(&pdev->dev, &snd_rpi_simple);
14412 + if (ret && ret != -EPROBE_DEFER)
14413 + dev_err(&pdev->dev, "Failed to register card %d\n", ret);
14414 +
14415 + return ret;
14416 +}
14417 +
14418 +static struct platform_driver snd_rpi_simple_driver = {
14419 + .driver = {
14420 + .name = "snd-rpi-simple",
14421 + .owner = THIS_MODULE,
14422 + .of_match_table = snd_rpi_simple_of_match,
14423 + },
14424 + .probe = snd_rpi_simple_probe,
14425 +};
14426 +MODULE_DEVICE_TABLE(of, snd_rpi_simple_of_match);
14427 +
14428 +module_platform_driver(snd_rpi_simple_driver);
14429 +
14430 +MODULE_AUTHOR("Tim Gover <tim.gover@raspberrypi.org>");
14431 +MODULE_DESCRIPTION("ASoC Raspberry Pi simple soundcard driver ");
14432 +MODULE_LICENSE("GPL v2");
14433 --- /dev/null
14434 +++ b/sound/soc/bcm/rpi-wm8804-soundcard.c
14435 @@ -0,0 +1,410 @@
14436 +// SPDX-License-Identifier: GPL-2.0
14437 +/*
14438 + * rpi--wm8804.c -- ALSA SoC Raspberry Pi soundcard.
14439 + *
14440 + * Copyright (C) 2018 Raspberry Pi.
14441 + *
14442 + * Authors: Tim Gover <tim.gover@raspberrypi.org>
14443 + *
14444 + * Generic driver for Pi Hat WM8804 digi sounds cards
14445 + *
14446 + * Based upon code from:
14447 + * justboom-digi.c
14448 + * by Milan Neskovic <info@justboom.co>
14449 + *
14450 + * iqaudio_digi.c
14451 + * by Daniel Matuschek <info@crazy-audio.com>
14452 + *
14453 + * allo-digione.c
14454 + * by Baswaraj <jaikumar@cem-solutions.net>
14455 + *
14456 + * hifiberry-digi.c
14457 + * Daniel Matuschek <info@crazy-audio.com>
14458 + *
14459 + * This program is free software; you can redistribute it and/or
14460 + * modify it under the terms of the GNU General Public License
14461 + * version 2 as published by the Free Software Foundation.
14462 + *
14463 + * This program is distributed in the hope that it will be useful, but
14464 + * WITHOUT ANY WARRANTY; without even the implied warranty of
14465 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14466 + * General Public License for more details.
14467 + */
14468 +
14469 +#include <linux/gpio/consumer.h>
14470 +#include <linux/platform_device.h>
14471 +#include <linux/module.h>
14472 +
14473 +#include <sound/core.h>
14474 +#include <sound/pcm.h>
14475 +#include <sound/pcm_params.h>
14476 +#include <sound/soc.h>
14477 +
14478 +#include "../codecs/wm8804.h"
14479 +
14480 +struct wm8804_clk_cfg {
14481 + unsigned int sysclk_freq;
14482 + unsigned int mclk_freq;
14483 + unsigned int mclk_div;
14484 +};
14485 +
14486 +/* Parameters for generic functions */
14487 +struct snd_rpi_wm8804_drvdata {
14488 + /* Required - pointer to the DAI structure */
14489 + struct snd_soc_dai_link *dai;
14490 + /* Required - snd_soc_card name */
14491 + const char *card_name;
14492 + /* Optional DT node names if card info is defined in DT */
14493 + const char *card_name_dt;
14494 + const char *dai_name_dt;
14495 + const char *dai_stream_name_dt;
14496 + /* Optional probe extension - called prior to register_card */
14497 + int (*probe)(struct platform_device *pdev);
14498 +};
14499 +
14500 +static struct gpio_desc *snd_clk44gpio;
14501 +static struct gpio_desc *snd_clk48gpio;
14502 +static int wm8804_samplerate = 0;
14503 +
14504 +/* Forward declarations */
14505 +static struct snd_soc_dai_link snd_allo_digione_dai[];
14506 +static struct snd_soc_card snd_rpi_wm8804;
14507 +
14508 +
14509 +#define CLK_44EN_RATE 22579200UL
14510 +#define CLK_48EN_RATE 24576000UL
14511 +
14512 +static unsigned int snd_rpi_wm8804_enable_clock(unsigned int samplerate)
14513 +{
14514 + switch (samplerate) {
14515 + case 11025:
14516 + case 22050:
14517 + case 44100:
14518 + case 88200:
14519 + case 176400:
14520 + gpiod_set_value_cansleep(snd_clk44gpio, 1);
14521 + gpiod_set_value_cansleep(snd_clk48gpio, 0);
14522 + return CLK_44EN_RATE;
14523 + default:
14524 + gpiod_set_value_cansleep(snd_clk48gpio, 1);
14525 + gpiod_set_value_cansleep(snd_clk44gpio, 0);
14526 + return CLK_48EN_RATE;
14527 + }
14528 +}
14529 +
14530 +static void snd_rpi_wm8804_clk_cfg(unsigned int samplerate,
14531 + struct wm8804_clk_cfg *clk_cfg)
14532 +{
14533 + clk_cfg->sysclk_freq = 27000000;
14534 +
14535 + if (samplerate <= 96000 ||
14536 + snd_rpi_wm8804.dai_link == snd_allo_digione_dai) {
14537 + clk_cfg->mclk_freq = samplerate * 256;
14538 + clk_cfg->mclk_div = WM8804_MCLKDIV_256FS;
14539 + } else {
14540 + clk_cfg->mclk_freq = samplerate * 128;
14541 + clk_cfg->mclk_div = WM8804_MCLKDIV_128FS;
14542 + }
14543 +
14544 + if (!(IS_ERR(snd_clk44gpio) || IS_ERR(snd_clk48gpio)))
14545 + clk_cfg->sysclk_freq = snd_rpi_wm8804_enable_clock(samplerate);
14546 +}
14547 +
14548 +static int snd_rpi_wm8804_hw_params(struct snd_pcm_substream *substream,
14549 + struct snd_pcm_hw_params *params)
14550 +{
14551 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
14552 + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
14553 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
14554 + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
14555 + int sampling_freq = 1;
14556 + int ret;
14557 + struct wm8804_clk_cfg clk_cfg;
14558 + int samplerate = params_rate(params);
14559 +
14560 + if (samplerate == wm8804_samplerate)
14561 + return 0;
14562 +
14563 + /* clear until all clocks are setup properly */
14564 + wm8804_samplerate = 0;
14565 +
14566 + snd_rpi_wm8804_clk_cfg(samplerate, &clk_cfg);
14567 +
14568 + pr_debug("%s samplerate: %d mclk_freq: %u mclk_div: %u sysclk: %u\n",
14569 + __func__, samplerate, clk_cfg.mclk_freq,
14570 + clk_cfg.mclk_div, clk_cfg.sysclk_freq);
14571 +
14572 + switch (samplerate) {
14573 + case 32000:
14574 + sampling_freq = 0x03;
14575 + break;
14576 + case 44100:
14577 + sampling_freq = 0x00;
14578 + break;
14579 + case 48000:
14580 + sampling_freq = 0x02;
14581 + break;
14582 + case 88200:
14583 + sampling_freq = 0x08;
14584 + break;
14585 + case 96000:
14586 + sampling_freq = 0x0a;
14587 + break;
14588 + case 176400:
14589 + sampling_freq = 0x0c;
14590 + break;
14591 + case 192000:
14592 + sampling_freq = 0x0e;
14593 + break;
14594 + default:
14595 + dev_err(rtd->card->dev,
14596 + "Failed to set WM8804 SYSCLK, unsupported samplerate %d\n",
14597 + samplerate);
14598 + }
14599 +
14600 + snd_soc_dai_set_clkdiv(codec_dai, WM8804_MCLK_DIV, clk_cfg.mclk_div);
14601 + snd_soc_dai_set_pll(codec_dai, 0, 0,
14602 + clk_cfg.sysclk_freq, clk_cfg.mclk_freq);
14603 +
14604 + ret = snd_soc_dai_set_sysclk(codec_dai, WM8804_TX_CLKSRC_PLL,
14605 + clk_cfg.sysclk_freq, SND_SOC_CLOCK_OUT);
14606 + if (ret < 0) {
14607 + dev_err(rtd->card->dev,
14608 + "Failed to set WM8804 SYSCLK: %d\n", ret);
14609 + return ret;
14610 + }
14611 +
14612 + wm8804_samplerate = samplerate;
14613 +
14614 + /* set sampling frequency status bits */
14615 + snd_soc_component_update_bits(component, WM8804_SPDTX4, 0x0f,
14616 + sampling_freq);
14617 +
14618 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 64);
14619 +}
14620 +
14621 +static struct snd_soc_ops snd_rpi_wm8804_ops = {
14622 + .hw_params = snd_rpi_wm8804_hw_params,
14623 +};
14624 +
14625 +SND_SOC_DAILINK_DEFS(justboom_digi,
14626 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
14627 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
14628 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
14629 +
14630 +static struct snd_soc_dai_link snd_justboom_digi_dai[] = {
14631 +{
14632 + .name = "JustBoom Digi",
14633 + .stream_name = "JustBoom Digi HiFi",
14634 + SND_SOC_DAILINK_REG(justboom_digi),
14635 +},
14636 +};
14637 +
14638 +static struct snd_rpi_wm8804_drvdata drvdata_justboom_digi = {
14639 + .card_name = "snd_rpi_justboom_digi",
14640 + .dai = snd_justboom_digi_dai,
14641 +};
14642 +
14643 +SND_SOC_DAILINK_DEFS(iqaudio_digi,
14644 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
14645 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
14646 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
14647 +
14648 +static struct snd_soc_dai_link snd_iqaudio_digi_dai[] = {
14649 +{
14650 + .name = "IQAudIO Digi",
14651 + .stream_name = "IQAudIO Digi HiFi",
14652 + SND_SOC_DAILINK_REG(iqaudio_digi),
14653 +},
14654 +};
14655 +
14656 +static struct snd_rpi_wm8804_drvdata drvdata_iqaudio_digi = {
14657 + .card_name = "IQAudIODigi",
14658 + .dai = snd_iqaudio_digi_dai,
14659 + .card_name_dt = "wm8804-digi,card-name",
14660 + .dai_name_dt = "wm8804-digi,dai-name",
14661 + .dai_stream_name_dt = "wm8804-digi,dai-stream-name",
14662 +};
14663 +
14664 +static int snd_allo_digione_probe(struct platform_device *pdev)
14665 +{
14666 + pr_debug("%s\n", __func__);
14667 +
14668 + if (IS_ERR(snd_clk44gpio) || IS_ERR(snd_clk48gpio)) {
14669 + dev_err(&pdev->dev, "devm_gpiod_get() failed\n");
14670 + return -EINVAL;
14671 + }
14672 + return 0;
14673 +}
14674 +
14675 +SND_SOC_DAILINK_DEFS(allo_digione,
14676 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
14677 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
14678 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
14679 +
14680 +static struct snd_soc_dai_link snd_allo_digione_dai[] = {
14681 +{
14682 + .name = "Allo DigiOne",
14683 + .stream_name = "Allo DigiOne HiFi",
14684 + SND_SOC_DAILINK_REG(allo_digione),
14685 +},
14686 +};
14687 +
14688 +static struct snd_rpi_wm8804_drvdata drvdata_allo_digione = {
14689 + .card_name = "snd_allo_digione",
14690 + .dai = snd_allo_digione_dai,
14691 + .probe = snd_allo_digione_probe,
14692 +};
14693 +
14694 +SND_SOC_DAILINK_DEFS(hifiberry_digi,
14695 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
14696 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
14697 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
14698 +
14699 +static struct snd_soc_dai_link snd_hifiberry_digi_dai[] = {
14700 +{
14701 + .name = "HifiBerry Digi",
14702 + .stream_name = "HifiBerry Digi HiFi",
14703 + SND_SOC_DAILINK_REG(hifiberry_digi),
14704 +},
14705 +};
14706 +
14707 +static int snd_hifiberry_digi_probe(struct platform_device *pdev)
14708 +{
14709 + pr_debug("%s\n", __func__);
14710 +
14711 + if (IS_ERR(snd_clk44gpio) || IS_ERR(snd_clk48gpio))
14712 + return 0;
14713 +
14714 + snd_hifiberry_digi_dai->name = "HiFiBerry Digi+ Pro";
14715 + snd_hifiberry_digi_dai->stream_name = "HiFiBerry Digi+ Pro HiFi";
14716 + return 0;
14717 +}
14718 +
14719 +static struct snd_rpi_wm8804_drvdata drvdata_hifiberry_digi = {
14720 + .card_name = "snd_rpi_hifiberry_digi",
14721 + .dai = snd_hifiberry_digi_dai,
14722 + .probe = snd_hifiberry_digi_probe,
14723 +};
14724 +
14725 +static const struct of_device_id snd_rpi_wm8804_of_match[] = {
14726 + { .compatible = "justboom,justboom-digi",
14727 + .data = (void *) &drvdata_justboom_digi },
14728 + { .compatible = "iqaudio,wm8804-digi",
14729 + .data = (void *) &drvdata_iqaudio_digi },
14730 + { .compatible = "allo,allo-digione",
14731 + .data = (void *) &drvdata_allo_digione },
14732 + { .compatible = "hifiberry,hifiberry-digi",
14733 + .data = (void *) &drvdata_hifiberry_digi },
14734 + {},
14735 +};
14736 +
14737 +static struct snd_soc_card snd_rpi_wm8804 = {
14738 + .driver_name = "RPi-WM8804",
14739 + .owner = THIS_MODULE,
14740 + .dai_link = NULL,
14741 + .num_links = 1,
14742 +};
14743 +
14744 +static int snd_rpi_wm8804_probe(struct platform_device *pdev)
14745 +{
14746 + int ret = 0;
14747 + const struct of_device_id *of_id;
14748 +
14749 + snd_rpi_wm8804.dev = &pdev->dev;
14750 + of_id = of_match_node(snd_rpi_wm8804_of_match, pdev->dev.of_node);
14751 +
14752 + if (pdev->dev.of_node && of_id->data) {
14753 + struct device_node *i2s_node;
14754 + struct snd_rpi_wm8804_drvdata *drvdata =
14755 + (struct snd_rpi_wm8804_drvdata *) of_id->data;
14756 + struct snd_soc_dai_link *dai = drvdata->dai;
14757 +
14758 + snd_soc_card_set_drvdata(&snd_rpi_wm8804, drvdata);
14759 +
14760 + if (!dai->ops)
14761 + dai->ops = &snd_rpi_wm8804_ops;
14762 + if (!dai->codecs->dai_name)
14763 + dai->codecs->dai_name = "wm8804-spdif";
14764 + if (!dai->codecs->name)
14765 + dai->codecs->name = "wm8804.1-003b";
14766 + if (!dai->dai_fmt)
14767 + dai->dai_fmt = SND_SOC_DAIFMT_I2S |
14768 + SND_SOC_DAIFMT_NB_NF |
14769 + SND_SOC_DAIFMT_CBM_CFM;
14770 +
14771 + snd_rpi_wm8804.dai_link = dai;
14772 + i2s_node = of_parse_phandle(pdev->dev.of_node,
14773 + "i2s-controller", 0);
14774 + if (!i2s_node) {
14775 + pr_err("Failed to find i2s-controller DT node\n");
14776 + return -ENODEV;
14777 + }
14778 +
14779 + snd_rpi_wm8804.name = drvdata->card_name;
14780 +
14781 + /* If requested by in drvdata get card & DAI names from DT */
14782 + if (drvdata->card_name_dt)
14783 + of_property_read_string(i2s_node,
14784 + drvdata->card_name_dt,
14785 + &snd_rpi_wm8804.name);
14786 +
14787 + if (drvdata->dai_name_dt)
14788 + of_property_read_string(i2s_node,
14789 + drvdata->dai_name_dt,
14790 + &dai->name);
14791 +
14792 + if (drvdata->dai_stream_name_dt)
14793 + of_property_read_string(i2s_node,
14794 + drvdata->dai_stream_name_dt,
14795 + &dai->stream_name);
14796 +
14797 + dai->cpus->of_node = i2s_node;
14798 + dai->platforms->of_node = i2s_node;
14799 +
14800 + /*
14801 + * clk44gpio and clk48gpio are not required by all cards so
14802 + * don't check the error status.
14803 + */
14804 + snd_clk44gpio =
14805 + devm_gpiod_get(&pdev->dev, "clock44", GPIOD_OUT_LOW);
14806 +
14807 + snd_clk48gpio =
14808 + devm_gpiod_get(&pdev->dev, "clock48", GPIOD_OUT_LOW);
14809 +
14810 + if (drvdata->probe) {
14811 + ret = drvdata->probe(pdev);
14812 + if (ret < 0) {
14813 + dev_err(&pdev->dev, "Custom probe failed %d\n",
14814 + ret);
14815 + return ret;
14816 + }
14817 + }
14818 +
14819 + pr_debug("%s card: %s dai: %s stream: %s\n", __func__,
14820 + snd_rpi_wm8804.name,
14821 + dai->name, dai->stream_name);
14822 + }
14823 +
14824 + ret = devm_snd_soc_register_card(&pdev->dev, &snd_rpi_wm8804);
14825 + if (ret && ret != -EPROBE_DEFER)
14826 + dev_err(&pdev->dev, "Failed to register card %d\n", ret);
14827 +
14828 + return ret;
14829 +}
14830 +
14831 +static struct platform_driver snd_rpi_wm8804_driver = {
14832 + .driver = {
14833 + .name = "snd-rpi-wm8804",
14834 + .owner = THIS_MODULE,
14835 + .of_match_table = snd_rpi_wm8804_of_match,
14836 + },
14837 + .probe = snd_rpi_wm8804_probe,
14838 +};
14839 +MODULE_DEVICE_TABLE(of, snd_rpi_wm8804_of_match);
14840 +
14841 +module_platform_driver(snd_rpi_wm8804_driver);
14842 +
14843 +MODULE_AUTHOR("Tim Gover <tim.gover@raspberrypi.org>");
14844 +MODULE_DESCRIPTION("ASoC Raspberry Pi Hat generic digi driver for WM8804 based cards");
14845 +MODULE_LICENSE("GPL v2");
14846 --- a/sound/soc/codecs/Kconfig
14847 +++ b/sound/soc/codecs/Kconfig
14848 @@ -119,6 +119,7 @@ config SND_SOC_ALL_CODECS
14849 imply SND_SOC_IDT821034
14850 imply SND_SOC_INNO_RK3036
14851 imply SND_SOC_ISABELLE
14852 + imply SND_SOC_I_SABRE_CODEC
14853 imply SND_SOC_JZ4740_CODEC
14854 imply SND_SOC_JZ4725B_CODEC
14855 imply SND_SOC_JZ4760_CODEC
14856 @@ -126,6 +127,7 @@ config SND_SOC_ALL_CODECS
14857 imply SND_SOC_LM4857
14858 imply SND_SOC_LM49453
14859 imply SND_SOC_LOCHNAGAR_SC
14860 + imply SND_SOC_MA120X0P
14861 imply SND_SOC_MAX98088
14862 imply SND_SOC_MAX98090
14863 imply SND_SOC_MAX98095
14864 @@ -168,6 +170,7 @@ config SND_SOC_ALL_CODECS
14865 imply SND_SOC_PCM179X_SPI
14866 imply SND_SOC_PCM186X_I2C
14867 imply SND_SOC_PCM186X_SPI
14868 + imply SND_SOC_PCM1794A
14869 imply SND_SOC_PCM3008
14870 imply SND_SOC_PCM3060_I2C
14871 imply SND_SOC_PCM3060_SPI
14872 @@ -255,6 +258,7 @@ config SND_SOC_ALL_CODECS
14873 imply SND_SOC_TLV320ADCX140
14874 imply SND_SOC_TLV320AIC23_I2C
14875 imply SND_SOC_TLV320AIC23_SPI
14876 + imply SND_SOC_TAS5713
14877 imply SND_SOC_TLV320AIC26
14878 imply SND_SOC_TLV320AIC31XX
14879 imply SND_SOC_TLV320AIC32X4_I2C
14880 @@ -410,12 +414,12 @@ config SND_SOC_AD193X
14881 tristate
14882
14883 config SND_SOC_AD193X_SPI
14884 - tristate
14885 + tristate "Analog Devices AU193X CODEC - SPI"
14886 depends on SPI_MASTER
14887 select SND_SOC_AD193X
14888
14889 config SND_SOC_AD193X_I2C
14890 - tristate
14891 + tristate "Analog Devices AU193X CODEC - I2C"
14892 depends on I2C
14893 select SND_SOC_AD193X
14894
14895 @@ -1126,6 +1130,13 @@ config SND_SOC_LOCHNAGAR_SC
14896 This driver support the sound card functionality of the Cirrus
14897 Logic Lochnagar audio development board.
14898
14899 +config SND_SOC_MA120X0P
14900 + tristate "Infineon Merus(TM) MA120X0P Multilevel Class-D Audio amplifiers"
14901 + depends on I2C
14902 + help
14903 + Enable support for Infineon MA120X0P Multilevel Class-D audio power
14904 + amplifiers.
14905 +
14906 config SND_SOC_MADERA
14907 tristate
14908 default y if SND_SOC_CS47L15=y
14909 @@ -1503,6 +1514,10 @@ config SND_SOC_RT5616
14910 tristate "Realtek RT5616 CODEC"
14911 depends on I2C
14912
14913 +config SND_SOC_PCM1794A
14914 + tristate
14915 + depends on I2C
14916 +
14917 config SND_SOC_RT5631
14918 tristate "Realtek ALC5631/RT5631 CODEC"
14919 depends on I2C
14920 @@ -1846,6 +1861,9 @@ config SND_SOC_TFA9879
14921 tristate "NXP Semiconductors TFA9879 amplifier"
14922 depends on I2C
14923
14924 +config SND_SOC_TAS5713
14925 + tristate
14926 +
14927 config SND_SOC_TFA989X
14928 tristate "NXP/Goodix TFA989X (TFA1) amplifiers"
14929 depends on I2C
14930 @@ -2404,4 +2422,8 @@ config SND_SOC_LPASS_TX_MACRO
14931 select SND_SOC_LPASS_MACRO_COMMON
14932 tristate "Qualcomm TX Macro in LPASS(Low Power Audio SubSystem)"
14933
14934 +config SND_SOC_I_SABRE_CODEC
14935 + tristate "Audiophonics I-SABRE Codec"
14936 + depends on I2C
14937 +
14938 endmenu
14939 --- a/sound/soc/codecs/Makefile
14940 +++ b/sound/soc/codecs/Makefile
14941 @@ -127,6 +127,7 @@ snd-soc-ics43432-objs := ics43432.o
14942 snd-soc-idt821034-objs := idt821034.o
14943 snd-soc-inno-rk3036-objs := inno_rk3036.o
14944 snd-soc-isabelle-objs := isabelle.o
14945 +snd-soc-i-sabre-codec-objs := i-sabre-codec.o
14946 snd-soc-jz4740-codec-objs := jz4740.o
14947 snd-soc-jz4725b-codec-objs := jz4725b.o
14948 snd-soc-jz4760-codec-objs := jz4760.o
14949 @@ -139,6 +140,7 @@ snd-soc-lpass-rx-macro-objs := lpass-rx-
14950 snd-soc-lpass-tx-macro-objs := lpass-tx-macro.o
14951 snd-soc-lpass-wsa-macro-objs := lpass-wsa-macro.o
14952 snd-soc-lpass-va-macro-objs := lpass-va-macro.o
14953 +snd-soc-ma120x0p-objs := ma120x0p.o
14954 snd-soc-madera-objs := madera.o
14955 snd-soc-max9759-objs := max9759.o
14956 snd-soc-max9768-objs := max9768.o
14957 @@ -187,6 +189,7 @@ snd-soc-pcm179x-spi-objs := pcm179x-spi.
14958 snd-soc-pcm186x-objs := pcm186x.o
14959 snd-soc-pcm186x-i2c-objs := pcm186x-i2c.o
14960 snd-soc-pcm186x-spi-objs := pcm186x-spi.o
14961 +snd-soc-pcm1794a-objs := pcm1794a.o
14962 snd-soc-pcm3008-objs := pcm3008.o
14963 snd-soc-pcm3060-objs := pcm3060.o
14964 snd-soc-pcm3060-i2c-objs := pcm3060-i2c.o
14965 @@ -271,6 +274,7 @@ snd-soc-sta529-objs := sta529.o
14966 snd-soc-stac9766-objs := stac9766.o
14967 snd-soc-sti-sas-objs := sti-sas.o
14968 snd-soc-tas5086-objs := tas5086.o
14969 +snd-soc-tas5713-objs := tas5713.o
14970 snd-soc-tas571x-objs := tas571x.o
14971 snd-soc-tas5720-objs := tas5720.o
14972 snd-soc-tas5805m-objs := tas5805m.o
14973 @@ -513,6 +517,7 @@ obj-$(CONFIG_SND_SOC_ICS43432) += snd-so
14974 obj-$(CONFIG_SND_SOC_IDT821034) += snd-soc-idt821034.o
14975 obj-$(CONFIG_SND_SOC_INNO_RK3036) += snd-soc-inno-rk3036.o
14976 obj-$(CONFIG_SND_SOC_ISABELLE) += snd-soc-isabelle.o
14977 +obj-$(CONFIG_SND_SOC_I_SABRE_CODEC) += snd-soc-i-sabre-codec.o
14978 obj-$(CONFIG_SND_SOC_JZ4740_CODEC) += snd-soc-jz4740-codec.o
14979 obj-$(CONFIG_SND_SOC_JZ4725B_CODEC) += snd-soc-jz4725b-codec.o
14980 obj-$(CONFIG_SND_SOC_JZ4760_CODEC) += snd-soc-jz4760-codec.o
14981 @@ -520,6 +525,7 @@ obj-$(CONFIG_SND_SOC_JZ4770_CODEC) += sn
14982 obj-$(CONFIG_SND_SOC_LM4857) += snd-soc-lm4857.o
14983 obj-$(CONFIG_SND_SOC_LM49453) += snd-soc-lm49453.o
14984 obj-$(CONFIG_SND_SOC_LOCHNAGAR_SC) += snd-soc-lochnagar-sc.o
14985 +obj-$(CONFIG_SND_SOC_MA120X0P) += snd-soc-ma120x0p.o
14986 obj-$(CONFIG_SND_SOC_MADERA) += snd-soc-madera.o
14987 obj-$(CONFIG_SND_SOC_MAX9759) += snd-soc-max9759.o
14988 obj-$(CONFIG_SND_SOC_MAX9768) += snd-soc-max9768.o
14989 @@ -563,6 +569,7 @@ obj-$(CONFIG_SND_SOC_PCM1681) += snd-soc
14990 obj-$(CONFIG_SND_SOC_PCM179X) += snd-soc-pcm179x-codec.o
14991 obj-$(CONFIG_SND_SOC_PCM1789_I2C) += snd-soc-pcm1789-i2c.o
14992 obj-$(CONFIG_SND_SOC_PCM1789) += snd-soc-pcm1789-codec.o
14993 +obj-$(CONFIG_SND_SOC_PCM1794A) += snd-soc-pcm1794a.o
14994 obj-$(CONFIG_SND_SOC_PCM179X_I2C) += snd-soc-pcm179x-i2c.o
14995 obj-$(CONFIG_SND_SOC_PCM179X_SPI) += snd-soc-pcm179x-spi.o
14996 obj-$(CONFIG_SND_SOC_PCM186X) += snd-soc-pcm186x.o
14997 @@ -663,6 +670,7 @@ obj-$(CONFIG_SND_SOC_TAS5805M) += snd-so
14998 obj-$(CONFIG_SND_SOC_TAS6424) += snd-soc-tas6424.o
14999 obj-$(CONFIG_SND_SOC_TDA7419) += snd-soc-tda7419.o
15000 obj-$(CONFIG_SND_SOC_TAS2770) += snd-soc-tas2770.o
15001 +obj-$(CONFIG_SND_SOC_TAS5713) += snd-soc-tas5713.o
15002 obj-$(CONFIG_SND_SOC_TFA9879) += snd-soc-tfa9879.o
15003 obj-$(CONFIG_SND_SOC_TFA989X) += snd-soc-tfa989x.o
15004 obj-$(CONFIG_SND_SOC_TLV320ADC3XXX) += snd-soc-tlv320adc3xxx.o
15005 --- a/sound/soc/codecs/adau1977-i2c.c
15006 +++ b/sound/soc/codecs/adau1977-i2c.c
15007 @@ -38,9 +38,19 @@ static const struct i2c_device_id adau19
15008 };
15009 MODULE_DEVICE_TABLE(i2c, adau1977_i2c_ids);
15010
15011 +static const struct of_device_id adau1977_of_ids[] = {
15012 + { .compatible = "adi,adau1977", },
15013 + { .compatible = "adi,adau1978", },
15014 + { .compatible = "adi,adau1979", },
15015 + { }
15016 +};
15017 +MODULE_DEVICE_TABLE(of, adau1977_of_ids);
15018 +
15019 +
15020 static struct i2c_driver adau1977_i2c_driver = {
15021 .driver = {
15022 .name = "adau1977",
15023 + .of_match_table = adau1977_of_ids,
15024 },
15025 .probe = adau1977_i2c_probe,
15026 .id_table = adau1977_i2c_ids,
15027 --- a/sound/soc/codecs/cs42xx8-i2c.c
15028 +++ b/sound/soc/codecs/cs42xx8-i2c.c
15029 @@ -64,11 +64,18 @@ static const struct i2c_device_id cs42xx
15030 };
15031 MODULE_DEVICE_TABLE(i2c, cs42xx8_i2c_id);
15032
15033 +const struct of_device_id cs42xx8_i2c_of_match[] = {
15034 + { .compatible = "cirrus,cs42448", .data = &cs42448_data, },
15035 + { .compatible = "cirrus,cs42888", .data = &cs42888_data, },
15036 + { /* sentinel */ }
15037 +};
15038 +MODULE_DEVICE_TABLE(of, cs42xx8_i2c_of_match);
15039 +
15040 static struct i2c_driver cs42xx8_i2c_driver = {
15041 .driver = {
15042 .name = "cs42xx8",
15043 .pm = &cs42xx8_pm,
15044 - .of_match_table = cs42xx8_of_match,
15045 + .of_match_table = cs42xx8_i2c_of_match,
15046 },
15047 .probe = cs42xx8_i2c_probe,
15048 .remove = cs42xx8_i2c_remove,
15049 --- a/sound/soc/codecs/cs42xx8.c
15050 +++ b/sound/soc/codecs/cs42xx8.c
15051 @@ -510,6 +510,16 @@ const struct cs42xx8_driver_data cs42888
15052 };
15053 EXPORT_SYMBOL_GPL(cs42888_data);
15054
15055 +const struct of_device_id cs42xx8_of_match[] = {
15056 + { .compatible = "cirrus,cs42448", .data = &cs42448_data, },
15057 + { .compatible = "cirrus,cs42888", .data = &cs42888_data, },
15058 + { /* sentinel */ }
15059 +};
15060 +#if !IS_ENABLED(CONFIG_SND_SOC_CS42XX8_I2C)
15061 +MODULE_DEVICE_TABLE(of, cs42xx8_of_match);
15062 +EXPORT_SYMBOL_GPL(cs42xx8_of_match);
15063 +#endif
15064 +
15065 int cs42xx8_probe(struct device *dev, struct regmap *regmap, struct cs42xx8_driver_data *drvdata)
15066 {
15067 struct cs42xx8_priv *cs42xx8;
15068 --- /dev/null
15069 +++ b/sound/soc/codecs/i-sabre-codec.c
15070 @@ -0,0 +1,389 @@
15071 +/*
15072 + * Driver for I-Sabre Q2M
15073 + *
15074 + * Author: Satoru Kawase
15075 + * Modified by: Xiao Qingyong
15076 + * Modified by: JC BARBAUD (Mute)
15077 + * Update kernel v4.18+ by : Audiophonics
15078 + * Copyright 2018 Audiophonics
15079 + *
15080 + * This program is free software; you can redistribute it and/or
15081 + * modify it under the terms of the GNU General Public License
15082 + * version 2 as published by the Free Software Foundation.
15083 + *
15084 + * This program is distributed in the hope that it will be useful, but
15085 + * WITHOUT ANY WARRANTY; without even the implied warranty of
15086 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15087 + * General Public License for more details.
15088 + */
15089 +
15090 +
15091 +#include <linux/init.h>
15092 +#include <linux/module.h>
15093 +#include <linux/regmap.h>
15094 +#include <linux/i2c.h>
15095 +#include <sound/soc.h>
15096 +#include <sound/pcm_params.h>
15097 +#include <sound/tlv.h>
15098 +
15099 +#include "i-sabre-codec.h"
15100 +
15101 +
15102 +/* I-Sabre Q2M Codec Private Data */
15103 +struct i_sabre_codec_priv {
15104 + struct regmap *regmap;
15105 + unsigned int fmt;
15106 +};
15107 +
15108 +
15109 +/* I-Sabre Q2M Codec Default Register Value */
15110 +static const struct reg_default i_sabre_codec_reg_defaults[] = {
15111 + { ISABRECODEC_REG_10, 0x00 },
15112 + { ISABRECODEC_REG_20, 0x00 },
15113 + { ISABRECODEC_REG_21, 0x00 },
15114 + { ISABRECODEC_REG_22, 0x00 },
15115 + { ISABRECODEC_REG_24, 0x00 },
15116 +};
15117 +
15118 +
15119 +static bool i_sabre_codec_writeable(struct device *dev, unsigned int reg)
15120 +{
15121 + switch (reg) {
15122 + case ISABRECODEC_REG_10:
15123 + case ISABRECODEC_REG_20:
15124 + case ISABRECODEC_REG_21:
15125 + case ISABRECODEC_REG_22:
15126 + case ISABRECODEC_REG_24:
15127 + return true;
15128 +
15129 + default:
15130 + return false;
15131 + }
15132 +}
15133 +
15134 +static bool i_sabre_codec_readable(struct device *dev, unsigned int reg)
15135 +{
15136 + switch (reg) {
15137 + case ISABRECODEC_REG_01:
15138 + case ISABRECODEC_REG_02:
15139 + case ISABRECODEC_REG_10:
15140 + case ISABRECODEC_REG_20:
15141 + case ISABRECODEC_REG_21:
15142 + case ISABRECODEC_REG_22:
15143 + case ISABRECODEC_REG_24:
15144 + return true;
15145 +
15146 + default:
15147 + return false;
15148 + }
15149 +}
15150 +
15151 +static bool i_sabre_codec_volatile(struct device *dev, unsigned int reg)
15152 +{
15153 + switch (reg) {
15154 + case ISABRECODEC_REG_01:
15155 + case ISABRECODEC_REG_02:
15156 + return true;
15157 +
15158 + default:
15159 + return false;
15160 + }
15161 +}
15162 +
15163 +
15164 +/* Volume Scale */
15165 +static const DECLARE_TLV_DB_SCALE(volume_tlv, -10000, 100, 0);
15166 +
15167 +
15168 +/* Filter Type */
15169 +static const char * const fir_filter_type_texts[] = {
15170 + "brick wall",
15171 + "corrected minimum phase fast",
15172 + "minimum phase slow",
15173 + "minimum phase fast",
15174 + "linear phase slow",
15175 + "linear phase fast",
15176 + "apodizing fast",
15177 +};
15178 +
15179 +static SOC_ENUM_SINGLE_DECL(i_sabre_fir_filter_type_enum,
15180 + ISABRECODEC_REG_22, 0, fir_filter_type_texts);
15181 +
15182 +
15183 +/* I2S / SPDIF Select */
15184 +static const char * const iis_spdif_sel_texts[] = {
15185 + "I2S",
15186 + "SPDIF",
15187 +};
15188 +
15189 +static SOC_ENUM_SINGLE_DECL(i_sabre_iis_spdif_sel_enum,
15190 + ISABRECODEC_REG_24, 0, iis_spdif_sel_texts);
15191 +
15192 +
15193 +/* Control */
15194 +static const struct snd_kcontrol_new i_sabre_codec_controls[] = {
15195 +SOC_SINGLE_RANGE_TLV("Digital Playback Volume", ISABRECODEC_REG_20, 0, 0, 100, 1, volume_tlv),
15196 +SOC_SINGLE("Digital Playback Switch", ISABRECODEC_REG_21, 0, 1, 1),
15197 +SOC_ENUM("FIR Filter Type", i_sabre_fir_filter_type_enum),
15198 +SOC_ENUM("I2S/SPDIF Select", i_sabre_iis_spdif_sel_enum),
15199 +};
15200 +
15201 +
15202 +static const u32 i_sabre_codec_dai_rates_slave[] = {
15203 + 8000, 11025, 16000, 22050, 32000,
15204 + 44100, 48000, 64000, 88200, 96000,
15205 + 176400, 192000, 352800, 384000,
15206 + 705600, 768000, 1411200, 1536000
15207 +};
15208 +
15209 +static const struct snd_pcm_hw_constraint_list constraints_slave = {
15210 + .list = i_sabre_codec_dai_rates_slave,
15211 + .count = ARRAY_SIZE(i_sabre_codec_dai_rates_slave),
15212 +};
15213 +
15214 +static int i_sabre_codec_dai_startup_slave(
15215 + struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
15216 +{
15217 + struct snd_soc_component *component = dai->component;
15218 + int ret;
15219 +
15220 + ret = snd_pcm_hw_constraint_list(substream->runtime,
15221 + 0, SNDRV_PCM_HW_PARAM_RATE, &constraints_slave);
15222 + if (ret != 0) {
15223 + dev_err(component->card->dev, "Failed to setup rates constraints: %d\n", ret);
15224 + }
15225 +
15226 + return ret;
15227 +}
15228 +
15229 +static int i_sabre_codec_dai_startup(
15230 + struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
15231 +{
15232 + struct snd_soc_component *component = dai->component;
15233 + struct i_sabre_codec_priv *i_sabre_codec
15234 + = snd_soc_component_get_drvdata(component);
15235 +
15236 + switch (i_sabre_codec->fmt & SND_SOC_DAIFMT_MASTER_MASK) {
15237 + case SND_SOC_DAIFMT_CBS_CFS:
15238 + return i_sabre_codec_dai_startup_slave(substream, dai);
15239 +
15240 + default:
15241 + return (-EINVAL);
15242 + }
15243 +}
15244 +
15245 +static int i_sabre_codec_hw_params(
15246 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params,
15247 + struct snd_soc_dai *dai)
15248 +{
15249 + struct snd_soc_component *component = dai->component;
15250 + struct i_sabre_codec_priv *i_sabre_codec
15251 + = snd_soc_component_get_drvdata(component);
15252 + unsigned int daifmt;
15253 + int format_width;
15254 +
15255 + dev_dbg(component->card->dev, "hw_params %u Hz, %u channels\n",
15256 + params_rate(params), params_channels(params));
15257 +
15258 + /* Check I2S Format (Bit Size) */
15259 + format_width = snd_pcm_format_width(params_format(params));
15260 + if ((format_width != 32) && (format_width != 16)) {
15261 + dev_err(component->card->dev, "Bad frame size: %d\n",
15262 + snd_pcm_format_width(params_format(params)));
15263 + return (-EINVAL);
15264 + }
15265 +
15266 + /* Check Slave Mode */
15267 + daifmt = i_sabre_codec->fmt & SND_SOC_DAIFMT_MASTER_MASK;
15268 + if (daifmt != SND_SOC_DAIFMT_CBS_CFS) {
15269 + return (-EINVAL);
15270 + }
15271 +
15272 + /* Notify Sampling Frequency */
15273 + switch (params_rate(params))
15274 + {
15275 + case 44100:
15276 + case 48000:
15277 + case 88200:
15278 + case 96000:
15279 + case 176400:
15280 + case 192000:
15281 + snd_soc_component_update_bits(component, ISABRECODEC_REG_10, 0x01, 0x00);
15282 + break;
15283 +
15284 + case 352800:
15285 + case 384000:
15286 + case 705600:
15287 + case 768000:
15288 + case 1411200:
15289 + case 1536000:
15290 + snd_soc_component_update_bits(component, ISABRECODEC_REG_10, 0x01, 0x01);
15291 + break;
15292 + }
15293 +
15294 + return 0;
15295 +}
15296 +
15297 +static int i_sabre_codec_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
15298 +{
15299 + struct snd_soc_component *component = dai->component;
15300 + struct i_sabre_codec_priv *i_sabre_codec
15301 + = snd_soc_component_get_drvdata(component);
15302 +
15303 + /* interface format */
15304 + switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
15305 + case SND_SOC_DAIFMT_I2S:
15306 + break;
15307 +
15308 + case SND_SOC_DAIFMT_RIGHT_J:
15309 + case SND_SOC_DAIFMT_LEFT_J:
15310 + default:
15311 + return (-EINVAL);
15312 + }
15313 +
15314 + /* clock inversion */
15315 + if ((fmt & SND_SOC_DAIFMT_INV_MASK) != SND_SOC_DAIFMT_NB_NF) {
15316 + return (-EINVAL);
15317 + }
15318 +
15319 + /* Set Audio Data Format */
15320 + i_sabre_codec->fmt = fmt;
15321 +
15322 + return 0;
15323 +}
15324 +
15325 +static int i_sabre_codec_dac_mute(struct snd_soc_dai *dai, int mute, int direction)
15326 +{
15327 + struct snd_soc_component *component = dai->component;
15328 +
15329 + if (mute) {
15330 + snd_soc_component_update_bits(component, ISABRECODEC_REG_21, 0x01, 0x01);
15331 + } else {
15332 + snd_soc_component_update_bits(component, ISABRECODEC_REG_21, 0x01, 0x00);
15333 + }
15334 +
15335 + return 0;
15336 +}
15337 +
15338 +
15339 +static const struct snd_soc_dai_ops i_sabre_codec_dai_ops = {
15340 + .startup = i_sabre_codec_dai_startup,
15341 + .hw_params = i_sabre_codec_hw_params,
15342 + .set_fmt = i_sabre_codec_set_fmt,
15343 + .mute_stream = i_sabre_codec_dac_mute,
15344 +};
15345 +
15346 +static struct snd_soc_dai_driver i_sabre_codec_dai = {
15347 + .name = "i-sabre-codec-dai",
15348 + .playback = {
15349 + .stream_name = "Playback",
15350 + .channels_min = 2,
15351 + .channels_max = 2,
15352 + .rates = SNDRV_PCM_RATE_CONTINUOUS,
15353 + .rate_min = 8000,
15354 + .rate_max = 1536000,
15355 + .formats = SNDRV_PCM_FMTBIT_S16_LE
15356 + | SNDRV_PCM_FMTBIT_S32_LE,
15357 + },
15358 + .ops = &i_sabre_codec_dai_ops,
15359 +};
15360 +
15361 +static struct snd_soc_component_driver i_sabre_codec_codec_driver = {
15362 + .controls = i_sabre_codec_controls,
15363 + .num_controls = ARRAY_SIZE(i_sabre_codec_controls),
15364 +};
15365 +
15366 +
15367 +static const struct regmap_config i_sabre_codec_regmap = {
15368 + .reg_bits = 8,
15369 + .val_bits = 8,
15370 + .max_register = ISABRECODEC_MAX_REG,
15371 +
15372 + .reg_defaults = i_sabre_codec_reg_defaults,
15373 + .num_reg_defaults = ARRAY_SIZE(i_sabre_codec_reg_defaults),
15374 +
15375 + .writeable_reg = i_sabre_codec_writeable,
15376 + .readable_reg = i_sabre_codec_readable,
15377 + .volatile_reg = i_sabre_codec_volatile,
15378 +
15379 + .cache_type = REGCACHE_RBTREE,
15380 +};
15381 +
15382 +
15383 +static int i_sabre_codec_probe(struct device *dev, struct regmap *regmap)
15384 +{
15385 + struct i_sabre_codec_priv *i_sabre_codec;
15386 + int ret;
15387 +
15388 + i_sabre_codec = devm_kzalloc(dev, sizeof(*i_sabre_codec), GFP_KERNEL);
15389 + if (!i_sabre_codec) {
15390 + dev_err(dev, "devm_kzalloc");
15391 + return (-ENOMEM);
15392 + }
15393 +
15394 + i_sabre_codec->regmap = regmap;
15395 +
15396 + dev_set_drvdata(dev, i_sabre_codec);
15397 +
15398 + ret = snd_soc_register_component(dev,
15399 + &i_sabre_codec_codec_driver, &i_sabre_codec_dai, 1);
15400 + if (ret != 0) {
15401 + dev_err(dev, "Failed to register CODEC: %d\n", ret);
15402 + return ret;
15403 + }
15404 +
15405 + return 0;
15406 +}
15407 +
15408 +static void i_sabre_codec_remove(struct device *dev)
15409 +{
15410 + snd_soc_unregister_component(dev);
15411 +}
15412 +
15413 +
15414 +static int i_sabre_codec_i2c_probe(struct i2c_client *i2c)
15415 +{
15416 + struct regmap *regmap;
15417 +
15418 + regmap = devm_regmap_init_i2c(i2c, &i_sabre_codec_regmap);
15419 + if (IS_ERR(regmap)) {
15420 + return PTR_ERR(regmap);
15421 + }
15422 +
15423 + return i_sabre_codec_probe(&i2c->dev, regmap);
15424 +}
15425 +
15426 +static void i_sabre_codec_i2c_remove(struct i2c_client *i2c)
15427 +{
15428 + i_sabre_codec_remove(&i2c->dev);
15429 +}
15430 +
15431 +
15432 +static const struct i2c_device_id i_sabre_codec_i2c_id[] = {
15433 + { "i-sabre-codec", },
15434 + { }
15435 +};
15436 +MODULE_DEVICE_TABLE(i2c, i_sabre_codec_i2c_id);
15437 +
15438 +static const struct of_device_id i_sabre_codec_of_match[] = {
15439 + { .compatible = "audiophonics,i-sabre-codec", },
15440 + { }
15441 +};
15442 +MODULE_DEVICE_TABLE(of, i_sabre_codec_of_match);
15443 +
15444 +static struct i2c_driver i_sabre_codec_i2c_driver = {
15445 + .driver = {
15446 + .name = "i-sabre-codec-i2c",
15447 + .owner = THIS_MODULE,
15448 + .of_match_table = of_match_ptr(i_sabre_codec_of_match),
15449 + },
15450 + .probe = i_sabre_codec_i2c_probe,
15451 + .remove = i_sabre_codec_i2c_remove,
15452 + .id_table = i_sabre_codec_i2c_id,
15453 +};
15454 +module_i2c_driver(i_sabre_codec_i2c_driver);
15455 +
15456 +
15457 +MODULE_DESCRIPTION("ASoC I-Sabre Q2M codec driver");
15458 +MODULE_AUTHOR("Audiophonics <http://www.audiophonics.fr>");
15459 +MODULE_LICENSE("GPL");
15460 --- /dev/null
15461 +++ b/sound/soc/codecs/i-sabre-codec.h
15462 @@ -0,0 +1,42 @@
15463 +/*
15464 + * Driver for I-Sabre Q2M
15465 + *
15466 + * Author: Satoru Kawase
15467 + * Modified by: Xiao Qingyong
15468 + * Copyright 2018 Audiophonics
15469 + *
15470 + * This program is free software; you can redistribute it and/or
15471 + * modify it under the terms of the GNU General Public License
15472 + * version 2 as published by the Free Software Foundation.
15473 + *
15474 + * This program is distributed in the hope that it will be useful, but
15475 + * WITHOUT ANY WARRANTY; without even the implied warranty of
15476 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15477 + * General Public License for more details.
15478 + */
15479 +
15480 +#ifndef _SND_SOC_ISABRECODEC
15481 +#define _SND_SOC_ISABRECODEC
15482 +
15483 +
15484 +/* ISABRECODEC Register Address */
15485 +#define ISABRECODEC_REG_01 0x01 /* Virtual Device ID : 0x01 = es9038q2m */
15486 +#define ISABRECODEC_REG_02 0x02 /* API revision : 0x01 = Revision 01 */
15487 +#define ISABRECODEC_REG_10 0x10 /* 0x01 = above 192kHz, 0x00 = otherwise */
15488 +#define ISABRECODEC_REG_20 0x20 /* 0 - 100 (decimal value, 0 = min., 100 = max.) */
15489 +#define ISABRECODEC_REG_21 0x21 /* 0x00 = Mute OFF, 0x01 = Mute ON */
15490 +#define ISABRECODEC_REG_22 0x22
15491 +/*
15492 + 0x00 = brick wall,
15493 + 0x01 = corrected minimum phase fast,
15494 + 0x02 = minimum phase slow,
15495 + 0x03 = minimum phase fast,
15496 + 0x04 = linear phase slow,
15497 + 0x05 = linear phase fast,
15498 + 0x06 = apodizing fast,
15499 +*/
15500 +//#define ISABRECODEC_REG_23 0x23 /* reserved */
15501 +#define ISABRECODEC_REG_24 0x24 /* 0x00 = I2S, 0x01 = SPDIF */
15502 +#define ISABRECODEC_MAX_REG 0x24 /* Maximum Register Number */
15503 +
15504 +#endif /* _SND_SOC_ISABRECODEC */
15505 --- /dev/null
15506 +++ b/sound/soc/codecs/ma120x0p.c
15507 @@ -0,0 +1,1380 @@
15508 +// SPDX-License-Identifier: GPL-2.0-or-later
15509 +/*
15510 + * ASoC Driver for Infineon Merus(TM) ma120x0p multi-level class-D amplifier
15511 + *
15512 + * Authors: Ariel Muszkat <ariel.muszkat@gmail.com>
15513 + * Jorgen Kragh Jakobsen <jorgen.kraghjakobsen@infineon.com>
15514 + *
15515 + * Copyright (C) 2019 Infineon Technologies AG
15516 + *
15517 + */
15518 +#include <linux/module.h>
15519 +#include <linux/moduleparam.h>
15520 +#include <linux/init.h>
15521 +#include <linux/delay.h>
15522 +#include <linux/pm_runtime.h>
15523 +#include <linux/i2c.h>
15524 +#include <linux/of_device.h>
15525 +#include <linux/spi/spi.h>
15526 +#include <linux/regmap.h>
15527 +#include <linux/regulator/consumer.h>
15528 +#include <linux/slab.h>
15529 +#include <linux/gpio/consumer.h>
15530 +#include <linux/gpio.h>
15531 +#include <sound/core.h>
15532 +#include <sound/pcm.h>
15533 +#include <sound/pcm_params.h>
15534 +#include <sound/soc.h>
15535 +#include <sound/soc-dapm.h>
15536 +#include <sound/initval.h>
15537 +#include <sound/tlv.h>
15538 +#include <linux/interrupt.h>
15539 +
15540 +#include <linux/kernel.h>
15541 +#include <linux/string.h>
15542 +#include <linux/fs.h>
15543 +#include <linux/uaccess.h>
15544 +
15545 +#ifndef _MA120X0P_
15546 +#define _MA120X0P_
15547 +//------------------------------------------------------------------manualPM---
15548 +// Select Manual PowerMode control
15549 +#define ma_manualpm__a 0
15550 +#define ma_manualpm__len 1
15551 +#define ma_manualpm__mask 0x40
15552 +#define ma_manualpm__shift 0x06
15553 +#define ma_manualpm__reset 0x00
15554 +//--------------------------------------------------------------------pm_man---
15555 +// manual selected power mode
15556 +#define ma_pm_man__a 0
15557 +#define ma_pm_man__len 2
15558 +#define ma_pm_man__mask 0x30
15559 +#define ma_pm_man__shift 0x04
15560 +#define ma_pm_man__reset 0x03
15561 +//------------------------------------------ ----------------------mthr_1to2---
15562 +// mod. index threshold value for pm1=>pm2 change.
15563 +#define ma_mthr_1to2__a 1
15564 +#define ma_mthr_1to2__len 8
15565 +#define ma_mthr_1to2__mask 0xff
15566 +#define ma_mthr_1to2__shift 0x00
15567 +#define ma_mthr_1to2__reset 0x3c
15568 +//-----------------------------------------------------------------mthr_2to1---
15569 +// mod. index threshold value for pm2=>pm1 change.
15570 +#define ma_mthr_2to1__a 2
15571 +#define ma_mthr_2to1__len 8
15572 +#define ma_mthr_2to1__mask 0xff
15573 +#define ma_mthr_2to1__shift 0x00
15574 +#define ma_mthr_2to1__reset 0x32
15575 +//-----------------------------------------------------------------mthr_2to3---
15576 +// mod. index threshold value for pm2=>pm3 change.
15577 +#define ma_mthr_2to3__a 3
15578 +#define ma_mthr_2to3__len 8
15579 +#define ma_mthr_2to3__mask 0xff
15580 +#define ma_mthr_2to3__shift 0x00
15581 +#define ma_mthr_2to3__reset 0x5a
15582 +//-----------------------------------------------------------------mthr_3to2---
15583 +// mod. index threshold value for pm3=>pm2 change.
15584 +#define ma_mthr_3to2__a 4
15585 +#define ma_mthr_3to2__len 8
15586 +#define ma_mthr_3to2__mask 0xff
15587 +#define ma_mthr_3to2__shift 0x00
15588 +#define ma_mthr_3to2__reset 0x50
15589 +//-------------------------------------------------------------pwmclkdiv_nom---
15590 +// pwm default clock divider value
15591 +#define ma_pwmclkdiv_nom__a 8
15592 +#define ma_pwmclkdiv_nom__len 8
15593 +#define ma_pwmclkdiv_nom__mask 0xff
15594 +#define ma_pwmclkdiv_nom__shift 0x00
15595 +#define ma_pwmclkdiv_nom__reset 0x26
15596 +//--------- ----------------------------------------------------ocp_latch_en---
15597 +// high to use permanently latching level-2 ocp
15598 +#define ma_ocp_latch_en__a 10
15599 +#define ma_ocp_latch_en__len 1
15600 +#define ma_ocp_latch_en__mask 0x02
15601 +#define ma_ocp_latch_en__shift 0x01
15602 +#define ma_ocp_latch_en__reset 0x00
15603 +//---------------------------------------------------------------lf_clamp_en---
15604 +// high (default) to enable lf int2+3 clamping on clip
15605 +#define ma_lf_clamp_en__a 10
15606 +#define ma_lf_clamp_en__len 1
15607 +#define ma_lf_clamp_en__mask 0x80
15608 +#define ma_lf_clamp_en__shift 0x07
15609 +#define ma_lf_clamp_en__reset 0x00
15610 +//-------------------------------------------------------pmcfg_btl_b.modtype---
15611 +//
15612 +#define ma_pmcfg_btl_b__modtype__a 18
15613 +#define ma_pmcfg_btl_b__modtype__len 2
15614 +#define ma_pmcfg_btl_b__modtype__mask 0x18
15615 +#define ma_pmcfg_btl_b__modtype__shift 0x03
15616 +#define ma_pmcfg_btl_b__modtype__reset 0x02
15617 +//-------------------------------------------------------pmcfg_btl_b.freqdiv---
15618 +#define ma_pmcfg_btl_b__freqdiv__a 18
15619 +#define ma_pmcfg_btl_b__freqdiv__len 2
15620 +#define ma_pmcfg_btl_b__freqdiv__mask 0x06
15621 +#define ma_pmcfg_btl_b__freqdiv__shift 0x01
15622 +#define ma_pmcfg_btl_b__freqdiv__reset 0x01
15623 +//----------------------------------------------------pmcfg_btl_b.lf_gain_ol---
15624 +//
15625 +#define ma_pmcfg_btl_b__lf_gain_ol__a 18
15626 +#define ma_pmcfg_btl_b__lf_gain_ol__len 1
15627 +#define ma_pmcfg_btl_b__lf_gain_ol__mask 0x01
15628 +#define ma_pmcfg_btl_b__lf_gain_ol__shift 0x00
15629 +#define ma_pmcfg_btl_b__lf_gain_ol__reset 0x01
15630 +//-------------------------------------------------------pmcfg_btl_c.freqdiv---
15631 +//
15632 +#define ma_pmcfg_btl_c__freqdiv__a 19
15633 +#define ma_pmcfg_btl_c__freqdiv__len 2
15634 +#define ma_pmcfg_btl_c__freqdiv__mask 0x06
15635 +#define ma_pmcfg_btl_c__freqdiv__shift 0x01
15636 +#define ma_pmcfg_btl_c__freqdiv__reset 0x01
15637 +//-------------------------------------------------------pmcfg_btl_c.modtype---
15638 +//
15639 +#define ma_pmcfg_btl_c__modtype__a 19
15640 +#define ma_pmcfg_btl_c__modtype__len 2
15641 +#define ma_pmcfg_btl_c__modtype__mask 0x18
15642 +#define ma_pmcfg_btl_c__modtype__shift 0x03
15643 +#define ma_pmcfg_btl_c__modtype__reset 0x01
15644 +//----------------------------------------------------pmcfg_btl_c.lf_gain_ol---
15645 +//
15646 +#define ma_pmcfg_btl_c__lf_gain_ol__a 19
15647 +#define ma_pmcfg_btl_c__lf_gain_ol__len 1
15648 +#define ma_pmcfg_btl_c__lf_gain_ol__mask 0x01
15649 +#define ma_pmcfg_btl_c__lf_gain_ol__shift 0x00
15650 +#define ma_pmcfg_btl_c__lf_gain_ol__reset 0x00
15651 +//-------------------------------------------------------pmcfg_btl_d.modtype---
15652 +//
15653 +#define ma_pmcfg_btl_d__modtype__a 20
15654 +#define ma_pmcfg_btl_d__modtype__len 2
15655 +#define ma_pmcfg_btl_d__modtype__mask 0x18
15656 +#define ma_pmcfg_btl_d__modtype__shift 0x03
15657 +#define ma_pmcfg_btl_d__modtype__reset 0x02
15658 +//-------------------------------------------------------pmcfg_btl_d.freqdiv---
15659 +//
15660 +#define ma_pmcfg_btl_d__freqdiv__a 20
15661 +#define ma_pmcfg_btl_d__freqdiv__len 2
15662 +#define ma_pmcfg_btl_d__freqdiv__mask 0x06
15663 +#define ma_pmcfg_btl_d__freqdiv__shift 0x01
15664 +#define ma_pmcfg_btl_d__freqdiv__reset 0x02
15665 +//----------------------------------------------------pmcfg_btl_d.lf_gain_ol---
15666 +//
15667 +#define ma_pmcfg_btl_d__lf_gain_ol__a 20
15668 +#define ma_pmcfg_btl_d__lf_gain_ol__len 1
15669 +#define ma_pmcfg_btl_d__lf_gain_ol__mask 0x01
15670 +#define ma_pmcfg_btl_d__lf_gain_ol__shift 0x00
15671 +#define ma_pmcfg_btl_d__lf_gain_ol__reset 0x00
15672 +//------------ -------------------------------------------pmcfg_se_a.modtype---
15673 +//
15674 +#define ma_pmcfg_se_a__modtype__a 21
15675 +#define ma_pmcfg_se_a__modtype__len 2
15676 +#define ma_pmcfg_se_a__modtype__mask 0x18
15677 +#define ma_pmcfg_se_a__modtype__shift 0x03
15678 +#define ma_pmcfg_se_a__modtype__reset 0x01
15679 +//--------------------------------------------------------pmcfg_se_a.freqdiv---
15680 +//
15681 +#define ma_pmcfg_se_a__freqdiv__a 21
15682 +#define ma_pmcfg_se_a__freqdiv__len 2
15683 +#define ma_pmcfg_se_a__freqdiv__mask 0x06
15684 +#define ma_pmcfg_se_a__freqdiv__shift 0x01
15685 +#define ma_pmcfg_se_a__freqdiv__reset 0x00
15686 +//-----------------------------------------------------pmcfg_se_a.lf_gain_ol---
15687 +//
15688 +#define ma_pmcfg_se_a__lf_gain_ol__a 21
15689 +#define ma_pmcfg_se_a__lf_gain_ol__len 1
15690 +#define ma_pmcfg_se_a__lf_gain_ol__mask 0x01
15691 +#define ma_pmcfg_se_a__lf_gain_ol__shift 0x00
15692 +#define ma_pmcfg_se_a__lf_gain_ol__reset 0x01
15693 +//-----------------------------------------------------pmcfg_se_b.lf_gain_ol---
15694 +//
15695 +#define ma_pmcfg_se_b__lf_gain_ol__a 22
15696 +#define ma_pmcfg_se_b__lf_gain_ol__len 1
15697 +#define ma_pmcfg_se_b__lf_gain_ol__mask 0x01
15698 +#define ma_pmcfg_se_b__lf_gain_ol__shift 0x00
15699 +#define ma_pmcfg_se_b__lf_gain_ol__reset 0x00
15700 +//--------------------------------------------------------pmcfg_se_b.freqdiv---
15701 +//
15702 +#define ma_pmcfg_se_b__freqdiv__a 22
15703 +#define ma_pmcfg_se_b__freqdiv__len 2
15704 +#define ma_pmcfg_se_b__freqdiv__mask 0x06
15705 +#define ma_pmcfg_se_b__freqdiv__shift 0x01
15706 +#define ma_pmcfg_se_b__freqdiv__reset 0x01
15707 +//--------------------------------------------------------pmcfg_se_b.modtype---
15708 +//
15709 +#define ma_pmcfg_se_b__modtype__a 22
15710 +#define ma_pmcfg_se_b__modtype__len 2
15711 +#define ma_pmcfg_se_b__modtype__mask 0x18
15712 +#define ma_pmcfg_se_b__modtype__shift 0x03
15713 +#define ma_pmcfg_se_b__modtype__reset 0x01
15714 +//----------------------------------------------------------balwaitcount_pm1---
15715 +// pm1 balancing period.
15716 +#define ma_balwaitcount_pm1__a 23
15717 +#define ma_balwaitcount_pm1__len 8
15718 +#define ma_balwaitcount_pm1__mask 0xff
15719 +#define ma_balwaitcount_pm1__shift 0x00
15720 +#define ma_balwaitcount_pm1__reset 0x14
15721 +//----------------------------------------------------------balwaitcount_pm2---
15722 +// pm2 balancing period.
15723 +#define ma_balwaitcount_pm2__a 24
15724 +#define ma_balwaitcount_pm2__len 8
15725 +#define ma_balwaitcount_pm2__mask 0xff
15726 +#define ma_balwaitcount_pm2__shift 0x00
15727 +#define ma_balwaitcount_pm2__reset 0x14
15728 +//----------------------------------------------------------balwaitcount_pm3---
15729 +// pm3 balancing period.
15730 +#define ma_balwaitcount_pm3__a 25
15731 +#define ma_balwaitcount_pm3__len 8
15732 +#define ma_balwaitcount_pm3__mask 0xff
15733 +#define ma_balwaitcount_pm3__shift 0x00
15734 +#define ma_balwaitcount_pm3__reset 0x1a
15735 +//-------------------------------------------------------------usespread_pm1---
15736 +// pm1 pwm spread-spectrum mode on/off.
15737 +#define ma_usespread_pm1__a 26
15738 +#define ma_usespread_pm1__len 1
15739 +#define ma_usespread_pm1__mask 0x40
15740 +#define ma_usespread_pm1__shift 0x06
15741 +#define ma_usespread_pm1__reset 0x00
15742 +//---------------------------------------------------------------dtsteps_pm1---
15743 +// pm1 dead time setting [10ns steps].
15744 +#define ma_dtsteps_pm1__a 26
15745 +#define ma_dtsteps_pm1__len 3
15746 +#define ma_dtsteps_pm1__mask 0x38
15747 +#define ma_dtsteps_pm1__shift 0x03
15748 +#define ma_dtsteps_pm1__reset 0x04
15749 +//---------------------------------------------------------------baltype_pm1---
15750 +// pm1 balancing sensor scheme.
15751 +#define ma_baltype_pm1__a 26
15752 +#define ma_baltype_pm1__len 3
15753 +#define ma_baltype_pm1__mask 0x07
15754 +#define ma_baltype_pm1__shift 0x00
15755 +#define ma_baltype_pm1__reset 0x00
15756 +//-------------------------------------------------------------usespread_pm2---
15757 +// pm2 pwm spread-spectrum mode on/off.
15758 +#define ma_usespread_pm2__a 27
15759 +#define ma_usespread_pm2__len 1
15760 +#define ma_usespread_pm2__mask 0x40
15761 +#define ma_usespread_pm2__shift 0x06
15762 +#define ma_usespread_pm2__reset 0x00
15763 +//---------------------------------------------------------------dtsteps_pm2---
15764 +// pm2 dead time setting [10ns steps].
15765 +#define ma_dtsteps_pm2__a 27
15766 +#define ma_dtsteps_pm2__len 3
15767 +#define ma_dtsteps_pm2__mask 0x38
15768 +#define ma_dtsteps_pm2__shift 0x03
15769 +#define ma_dtsteps_pm2__reset 0x03
15770 +//---------------------------------------------------------------baltype_pm2---
15771 +// pm2 balancing sensor scheme.
15772 +#define ma_baltype_pm2__a 27
15773 +#define ma_baltype_pm2__len 3
15774 +#define ma_baltype_pm2__mask 0x07
15775 +#define ma_baltype_pm2__shift 0x00
15776 +#define ma_baltype_pm2__reset 0x01
15777 +//-------------------------------------------------------------usespread_pm3---
15778 +// pm3 pwm spread-spectrum mode on/off.
15779 +#define ma_usespread_pm3__a 28
15780 +#define ma_usespread_pm3__len 1
15781 +#define ma_usespread_pm3__mask 0x40
15782 +#define ma_usespread_pm3__shift 0x06
15783 +#define ma_usespread_pm3__reset 0x00
15784 +//---------------------------------------------------------------dtsteps_pm3---
15785 +// pm3 dead time setting [10ns steps].
15786 +#define ma_dtsteps_pm3__a 28
15787 +#define ma_dtsteps_pm3__len 3
15788 +#define ma_dtsteps_pm3__mask 0x38
15789 +#define ma_dtsteps_pm3__shift 0x03
15790 +#define ma_dtsteps_pm3__reset 0x01
15791 +//---------------------------------------------------------------baltype_pm3---
15792 +// pm3 balancing sensor scheme.
15793 +#define ma_baltype_pm3__a 28
15794 +#define ma_baltype_pm3__len 3
15795 +#define ma_baltype_pm3__mask 0x07
15796 +#define ma_baltype_pm3__shift 0x00
15797 +#define ma_baltype_pm3__reset 0x03
15798 +//-----------------------------------------------------------------pmprofile---
15799 +// pm profile select. valid presets: 0-1-2-3-4. 5=> custom profile.
15800 +#define ma_pmprofile__a 29
15801 +#define ma_pmprofile__len 3
15802 +#define ma_pmprofile__mask 0x07
15803 +#define ma_pmprofile__shift 0x00
15804 +#define ma_pmprofile__reset 0x00
15805 +//-------------------------------------------------------------------pm3_man---
15806 +// custom profile pm3 contents. 0=>a, 1=>b, 2=>c, 3=>d
15807 +#define ma_pm3_man__a 30
15808 +#define ma_pm3_man__len 2
15809 +#define ma_pm3_man__mask 0x30
15810 +#define ma_pm3_man__shift 0x04
15811 +#define ma_pm3_man__reset 0x02
15812 +//-------------------------------------------------------------------pm2_man---
15813 +// custom profile pm2 contents. 0=>a, 1=>b, 2=>c, 3=>d
15814 +#define ma_pm2_man__a 30
15815 +#define ma_pm2_man__len 2
15816 +#define ma_pm2_man__mask 0x0c
15817 +#define ma_pm2_man__shift 0x02
15818 +#define ma_pm2_man__reset 0x03
15819 +//-------------------------------------------------------------------pm1_man---
15820 +// custom profile pm1 contents. 0=>a, 1=>b, 2=>c, 3=>d
15821 +#define ma_pm1_man__a 30
15822 +#define ma_pm1_man__len 2
15823 +#define ma_pm1_man__mask 0x03
15824 +#define ma_pm1_man__shift 0x00
15825 +#define ma_pm1_man__reset 0x03
15826 +//-----------------------------------------------------------ocp_latch_clear---
15827 +// low-high clears current ocp latched condition.
15828 +#define ma_ocp_latch_clear__a 32
15829 +#define ma_ocp_latch_clear__len 1
15830 +#define ma_ocp_latch_clear__mask 0x80
15831 +#define ma_ocp_latch_clear__shift 0x07
15832 +#define ma_ocp_latch_clear__reset 0x00
15833 +//-------------------------------------------------------------audio_in_mode---
15834 +// audio input mode; 0-1-2-3-4-5
15835 +#define ma_audio_in_mode__a 37
15836 +#define ma_audio_in_mode__len 3
15837 +#define ma_audio_in_mode__mask 0xe0
15838 +#define ma_audio_in_mode__shift 0x05
15839 +#define ma_audio_in_mode__reset 0x00
15840 +//-----------------------------------------------------------------eh_dcshdn---
15841 +// high to enable dc protection
15842 +#define ma_eh_dcshdn__a 38
15843 +#define ma_eh_dcshdn__len 1
15844 +#define ma_eh_dcshdn__mask 0x04
15845 +#define ma_eh_dcshdn__shift 0x02
15846 +#define ma_eh_dcshdn__reset 0x01
15847 +//---------------------------------------------------------audio_in_mode_ext---
15848 +// if set, audio_in_mode is controlled from audio_in_mode register. if not set
15849 +//audio_in_mode is set from fuse bank setting
15850 +#define ma_audio_in_mode_ext__a 39
15851 +#define ma_audio_in_mode_ext__len 1
15852 +#define ma_audio_in_mode_ext__mask 0x20
15853 +#define ma_audio_in_mode_ext__shift 0x05
15854 +#define ma_audio_in_mode_ext__reset 0x00
15855 +//------------------------------------------------------------------eh_clear---
15856 +// flip to clear error registers
15857 +#define ma_eh_clear__a 45
15858 +#define ma_eh_clear__len 1
15859 +#define ma_eh_clear__mask 0x04
15860 +#define ma_eh_clear__shift 0x02
15861 +#define ma_eh_clear__reset 0x00
15862 +//----------------------------------------------------------thermal_compr_en---
15863 +// enable otw-contr. input compression?
15864 +#define ma_thermal_compr_en__a 45
15865 +#define ma_thermal_compr_en__len 1
15866 +#define ma_thermal_compr_en__mask 0x20
15867 +#define ma_thermal_compr_en__shift 0x05
15868 +#define ma_thermal_compr_en__reset 0x01
15869 +//---------------------------------------------------------------system_mute---
15870 +// 1 = mute system, 0 = normal operation
15871 +#define ma_system_mute__a 45
15872 +#define ma_system_mute__len 1
15873 +#define ma_system_mute__mask 0x40
15874 +#define ma_system_mute__shift 0x06
15875 +#define ma_system_mute__reset 0x00
15876 +//------------------------------------------------------thermal_compr_max_db---
15877 +// audio limiter max thermal reduction
15878 +#define ma_thermal_compr_max_db__a 46
15879 +#define ma_thermal_compr_max_db__len 3
15880 +#define ma_thermal_compr_max_db__mask 0x07
15881 +#define ma_thermal_compr_max_db__shift 0x00
15882 +#define ma_thermal_compr_max_db__reset 0x04
15883 +//---------------------------------------------------------audio_proc_enable---
15884 +// enable audio proc, bypass if not enabled
15885 +#define ma_audio_proc_enable__a 53
15886 +#define ma_audio_proc_enable__len 1
15887 +#define ma_audio_proc_enable__mask 0x08
15888 +#define ma_audio_proc_enable__shift 0x03
15889 +#define ma_audio_proc_enable__reset 0x00
15890 +//--------------------------------------------------------audio_proc_release---
15891 +// 00:slow, 01:normal, 10:fast
15892 +#define ma_audio_proc_release__a 53
15893 +#define ma_audio_proc_release__len 2
15894 +#define ma_audio_proc_release__mask 0x30
15895 +#define ma_audio_proc_release__shift 0x04
15896 +#define ma_audio_proc_release__reset 0x00
15897 +//---------------------------------------------------------audio_proc_attack---
15898 +// 00:slow, 01:normal, 10:fast
15899 +#define ma_audio_proc_attack__a 53
15900 +#define ma_audio_proc_attack__len 2
15901 +#define ma_audio_proc_attack__mask 0xc0
15902 +#define ma_audio_proc_attack__shift 0x06
15903 +#define ma_audio_proc_attack__reset 0x00
15904 +//----------------------------------------------------------------i2s_format---
15905 +// i2s basic data format, 000 = std. i2s, 001 = left justified (default)
15906 +#define ma_i2s_format__a 53
15907 +#define ma_i2s_format__len 3
15908 +#define ma_i2s_format__mask 0x07
15909 +#define ma_i2s_format__shift 0x00
15910 +#define ma_i2s_format__reset 0x01
15911 +//--------------------------------------------------audio_proc_limiterenable---
15912 +// 1: enable limiter, 0: disable limiter
15913 +#define ma_audio_proc_limiterenable__a 54
15914 +#define ma_audio_proc_limiterenable__len 1
15915 +#define ma_audio_proc_limiterenable__mask 0x40
15916 +#define ma_audio_proc_limiterenable__shift 0x06
15917 +#define ma_audio_proc_limiterenable__reset 0x00
15918 +//-----------------------------------------------------------audio_proc_mute---
15919 +// 1: mute, 0: unmute
15920 +#define ma_audio_proc_mute__a 54
15921 +#define ma_audio_proc_mute__len 1
15922 +#define ma_audio_proc_mute__mask 0x80
15923 +#define ma_audio_proc_mute__shift 0x07
15924 +#define ma_audio_proc_mute__reset 0x00
15925 +//---------------------------------------------------------------i2s_sck_pol---
15926 +// i2s sck polarity cfg. 0 = rising edge data change
15927 +#define ma_i2s_sck_pol__a 54
15928 +#define ma_i2s_sck_pol__len 1
15929 +#define ma_i2s_sck_pol__mask 0x01
15930 +#define ma_i2s_sck_pol__shift 0x00
15931 +#define ma_i2s_sck_pol__reset 0x01
15932 +//-------------------------------------------------------------i2s_framesize---
15933 +// i2s word length. 00 = 32bit, 01 = 24bit
15934 +#define ma_i2s_framesize__a 54
15935 +#define ma_i2s_framesize__len 2
15936 +#define ma_i2s_framesize__mask 0x18
15937 +#define ma_i2s_framesize__shift 0x03
15938 +#define ma_i2s_framesize__reset 0x00
15939 +//----------------------------------------------------------------i2s_ws_pol---
15940 +// i2s ws polarity. 0 = low first
15941 +#define ma_i2s_ws_pol__a 54
15942 +#define ma_i2s_ws_pol__len 1
15943 +#define ma_i2s_ws_pol__mask 0x02
15944 +#define ma_i2s_ws_pol__shift 0x01
15945 +#define ma_i2s_ws_pol__reset 0x00
15946 +//-----------------------------------------------------------------i2s_order---
15947 +// i2s word bit order. 0 = msb first
15948 +#define ma_i2s_order__a 54
15949 +#define ma_i2s_order__len 1
15950 +#define ma_i2s_order__mask 0x04
15951 +#define ma_i2s_order__shift 0x02
15952 +#define ma_i2s_order__reset 0x00
15953 +//------------------------------------------------------------i2s_rightfirst---
15954 +// i2s l/r word order; 0 = left first
15955 +#define ma_i2s_rightfirst__a 54
15956 +#define ma_i2s_rightfirst__len 1
15957 +#define ma_i2s_rightfirst__mask 0x20
15958 +#define ma_i2s_rightfirst__shift 0x05
15959 +#define ma_i2s_rightfirst__reset 0x00
15960 +//-------------------------------------------------------------vol_db_master---
15961 +// master volume db
15962 +#define ma_vol_db_master__a 64
15963 +#define ma_vol_db_master__len 8
15964 +#define ma_vol_db_master__mask 0xff
15965 +#define ma_vol_db_master__shift 0x00
15966 +#define ma_vol_db_master__reset 0x18
15967 +//------------------------------------------------------------vol_lsb_master---
15968 +// master volume lsb 1/4 steps
15969 +#define ma_vol_lsb_master__a 65
15970 +#define ma_vol_lsb_master__len 2
15971 +#define ma_vol_lsb_master__mask 0x03
15972 +#define ma_vol_lsb_master__shift 0x00
15973 +#define ma_vol_lsb_master__reset 0x00
15974 +//----------------------------------------------------------------vol_db_ch0---
15975 +// volume channel 0
15976 +#define ma_vol_db_ch0__a 66
15977 +#define ma_vol_db_ch0__len 8
15978 +#define ma_vol_db_ch0__mask 0xff
15979 +#define ma_vol_db_ch0__shift 0x00
15980 +#define ma_vol_db_ch0__reset 0x18
15981 +//----------------------------------------------------------------vol_db_ch1---
15982 +// volume channel 1
15983 +#define ma_vol_db_ch1__a 67
15984 +#define ma_vol_db_ch1__len 8
15985 +#define ma_vol_db_ch1__mask 0xff
15986 +#define ma_vol_db_ch1__shift 0x00
15987 +#define ma_vol_db_ch1__reset 0x18
15988 +//----------------------------------------------------------------vol_db_ch2---
15989 +// volume channel 2
15990 +#define ma_vol_db_ch2__a 68
15991 +#define ma_vol_db_ch2__len 8
15992 +#define ma_vol_db_ch2__mask 0xff
15993 +#define ma_vol_db_ch2__shift 0x00
15994 +#define ma_vol_db_ch2__reset 0x18
15995 +//----------------------------------------------------------------vol_db_ch3---
15996 +// volume channel 3
15997 +#define ma_vol_db_ch3__a 69
15998 +#define ma_vol_db_ch3__len 8
15999 +#define ma_vol_db_ch3__mask 0xff
16000 +#define ma_vol_db_ch3__shift 0x00
16001 +#define ma_vol_db_ch3__reset 0x18
16002 +//---------------------------------------------------------------vol_lsb_ch0---
16003 +// volume channel 1 - 1/4 steps
16004 +#define ma_vol_lsb_ch0__a 70
16005 +#define ma_vol_lsb_ch0__len 2
16006 +#define ma_vol_lsb_ch0__mask 0x03
16007 +#define ma_vol_lsb_ch0__shift 0x00
16008 +#define ma_vol_lsb_ch0__reset 0x00
16009 +//---------------------------------------------------------------vol_lsb_ch1---
16010 +// volume channel 3 - 1/4 steps
16011 +#define ma_vol_lsb_ch1__a 70
16012 +#define ma_vol_lsb_ch1__len 2
16013 +#define ma_vol_lsb_ch1__mask 0x0c
16014 +#define ma_vol_lsb_ch1__shift 0x02
16015 +#define ma_vol_lsb_ch1__reset 0x00
16016 +//---------------------------------------------------------------vol_lsb_ch2---
16017 +// volume channel 2 - 1/4 steps
16018 +#define ma_vol_lsb_ch2__a 70
16019 +#define ma_vol_lsb_ch2__len 2
16020 +#define ma_vol_lsb_ch2__mask 0x30
16021 +#define ma_vol_lsb_ch2__shift 0x04
16022 +#define ma_vol_lsb_ch2__reset 0x00
16023 +//---------------------------------------------------------------vol_lsb_ch3---
16024 +// volume channel 3 - 1/4 steps
16025 +#define ma_vol_lsb_ch3__a 70
16026 +#define ma_vol_lsb_ch3__len 2
16027 +#define ma_vol_lsb_ch3__mask 0xc0
16028 +#define ma_vol_lsb_ch3__shift 0x06
16029 +#define ma_vol_lsb_ch3__reset 0x00
16030 +//----------------------------------------------------------------thr_db_ch0---
16031 +// thr_db channel 0
16032 +#define ma_thr_db_ch0__a 71
16033 +#define ma_thr_db_ch0__len 8
16034 +#define ma_thr_db_ch0__mask 0xff
16035 +#define ma_thr_db_ch0__shift 0x00
16036 +#define ma_thr_db_ch0__reset 0x18
16037 +//----------------------------------------------------------------thr_db_ch1---
16038 +// thr db ch1
16039 +#define ma_thr_db_ch1__a 72
16040 +#define ma_thr_db_ch1__len 8
16041 +#define ma_thr_db_ch1__mask 0xff
16042 +#define ma_thr_db_ch1__shift 0x00
16043 +#define ma_thr_db_ch1__reset 0x18
16044 +//----------------------------------------------------------------thr_db_ch2---
16045 +// thr db ch2
16046 +#define ma_thr_db_ch2__a 73
16047 +#define ma_thr_db_ch2__len 8
16048 +#define ma_thr_db_ch2__mask 0xff
16049 +#define ma_thr_db_ch2__shift 0x00
16050 +#define ma_thr_db_ch2__reset 0x18
16051 +//----------------------------------------------------------------thr_db_ch3---
16052 +// threshold db ch3
16053 +#define ma_thr_db_ch3__a 74
16054 +#define ma_thr_db_ch3__len 8
16055 +#define ma_thr_db_ch3__mask 0xff
16056 +#define ma_thr_db_ch3__shift 0x00
16057 +#define ma_thr_db_ch3__reset 0x18
16058 +//---------------------------------------------------------------thr_lsb_ch0---
16059 +// thr lsb ch0
16060 +#define ma_thr_lsb_ch0__a 75
16061 +#define ma_thr_lsb_ch0__len 2
16062 +#define ma_thr_lsb_ch0__mask 0x03
16063 +#define ma_thr_lsb_ch0__shift 0x00
16064 +#define ma_thr_lsb_ch0__reset 0x00
16065 +//---------------------------------------------------------------thr_lsb_ch1---
16066 +// thr lsb ch1
16067 +#define ma_thr_lsb_ch1__a 75
16068 +#define ma_thr_lsb_ch1__len 2
16069 +#define ma_thr_lsb_ch1__mask 0x0c
16070 +#define ma_thr_lsb_ch1__shift 0x02
16071 +#define ma_thr_lsb_ch1__reset 0x00
16072 +//---------------------------------------------------------------thr_lsb_ch2---
16073 +// thr lsb ch2 1/4 db step
16074 +#define ma_thr_lsb_ch2__a 75
16075 +#define ma_thr_lsb_ch2__len 2
16076 +#define ma_thr_lsb_ch2__mask 0x30
16077 +#define ma_thr_lsb_ch2__shift 0x04
16078 +#define ma_thr_lsb_ch2__reset 0x00
16079 +//---------------------------------------------------------------thr_lsb_ch3---
16080 +// threshold lsb ch3
16081 +#define ma_thr_lsb_ch3__a 75
16082 +#define ma_thr_lsb_ch3__len 2
16083 +#define ma_thr_lsb_ch3__mask 0xc0
16084 +#define ma_thr_lsb_ch3__shift 0x06
16085 +#define ma_thr_lsb_ch3__reset 0x00
16086 +//-----------------------------------------------------------dcu_mon0.pm_mon---
16087 +// power mode monitor channel 0
16088 +#define ma_dcu_mon0__pm_mon__a 96
16089 +#define ma_dcu_mon0__pm_mon__len 2
16090 +#define ma_dcu_mon0__pm_mon__mask 0x03
16091 +#define ma_dcu_mon0__pm_mon__shift 0x00
16092 +#define ma_dcu_mon0__pm_mon__reset 0x00
16093 +//-----------------------------------------------------dcu_mon0.freqmode_mon---
16094 +// frequence mode monitor channel 0
16095 +#define ma_dcu_mon0__freqmode_mon__a 96
16096 +#define ma_dcu_mon0__freqmode_mon__len 3
16097 +#define ma_dcu_mon0__freqmode_mon__mask 0x70
16098 +#define ma_dcu_mon0__freqmode_mon__shift 0x04
16099 +#define ma_dcu_mon0__freqmode_mon__reset 0x00
16100 +//-------------------------------------------------------dcu_mon0.pps_passed---
16101 +// dcu0 pps completion indicator
16102 +#define ma_dcu_mon0__pps_passed__a 96
16103 +#define ma_dcu_mon0__pps_passed__len 1
16104 +#define ma_dcu_mon0__pps_passed__mask 0x80
16105 +#define ma_dcu_mon0__pps_passed__shift 0x07
16106 +#define ma_dcu_mon0__pps_passed__reset 0x00
16107 +//----------------------------------------------------------dcu_mon0.ocp_mon---
16108 +// ocp monitor channel 0
16109 +#define ma_dcu_mon0__ocp_mon__a 97
16110 +#define ma_dcu_mon0__ocp_mon__len 1
16111 +#define ma_dcu_mon0__ocp_mon__mask 0x01
16112 +#define ma_dcu_mon0__ocp_mon__shift 0x00
16113 +#define ma_dcu_mon0__ocp_mon__reset 0x00
16114 +//--------------------------------------------------------dcu_mon0.vcfly1_ok---
16115 +// cfly1 protection monitor channel 0.
16116 +#define ma_dcu_mon0__vcfly1_ok__a 97
16117 +#define ma_dcu_mon0__vcfly1_ok__len 1
16118 +#define ma_dcu_mon0__vcfly1_ok__mask 0x02
16119 +#define ma_dcu_mon0__vcfly1_ok__shift 0x01
16120 +#define ma_dcu_mon0__vcfly1_ok__reset 0x00
16121 +//--------------------------------------------------------dcu_mon0.vcfly2_ok---
16122 +// cfly2 protection monitor channel 0.
16123 +#define ma_dcu_mon0__vcfly2_ok__a 97
16124 +#define ma_dcu_mon0__vcfly2_ok__len 1
16125 +#define ma_dcu_mon0__vcfly2_ok__mask 0x04
16126 +#define ma_dcu_mon0__vcfly2_ok__shift 0x02
16127 +#define ma_dcu_mon0__vcfly2_ok__reset 0x00
16128 +//----------------------------------------------------------dcu_mon0.pvdd_ok---
16129 +// dcu0 pvdd monitor
16130 +#define ma_dcu_mon0__pvdd_ok__a 97
16131 +#define ma_dcu_mon0__pvdd_ok__len 1
16132 +#define ma_dcu_mon0__pvdd_ok__mask 0x08
16133 +#define ma_dcu_mon0__pvdd_ok__shift 0x03
16134 +#define ma_dcu_mon0__pvdd_ok__reset 0x00
16135 +//-----------------------------------------------------------dcu_mon0.vdd_ok---
16136 +// dcu0 vdd monitor
16137 +#define ma_dcu_mon0__vdd_ok__a 97
16138 +#define ma_dcu_mon0__vdd_ok__len 1
16139 +#define ma_dcu_mon0__vdd_ok__mask 0x10
16140 +#define ma_dcu_mon0__vdd_ok__shift 0x04
16141 +#define ma_dcu_mon0__vdd_ok__reset 0x00
16142 +//-------------------------------------------------------------dcu_mon0.mute---
16143 +// dcu0 mute monitor
16144 +#define ma_dcu_mon0__mute__a 97
16145 +#define ma_dcu_mon0__mute__len 1
16146 +#define ma_dcu_mon0__mute__mask 0x20
16147 +#define ma_dcu_mon0__mute__shift 0x05
16148 +#define ma_dcu_mon0__mute__reset 0x00
16149 +//------------------------------------------------------------dcu_mon0.m_mon---
16150 +// m sense monitor channel 0
16151 +#define ma_dcu_mon0__m_mon__a 98
16152 +#define ma_dcu_mon0__m_mon__len 8
16153 +#define ma_dcu_mon0__m_mon__mask 0xff
16154 +#define ma_dcu_mon0__m_mon__shift 0x00
16155 +#define ma_dcu_mon0__m_mon__reset 0x00
16156 +//-----------------------------------------------------------dcu_mon1.pm_mon---
16157 +// power mode monitor channel 1
16158 +#define ma_dcu_mon1__pm_mon__a 100
16159 +#define ma_dcu_mon1__pm_mon__len 2
16160 +#define ma_dcu_mon1__pm_mon__mask 0x03
16161 +#define ma_dcu_mon1__pm_mon__shift 0x00
16162 +#define ma_dcu_mon1__pm_mon__reset 0x00
16163 +//-----------------------------------------------------dcu_mon1.freqmode_mon---
16164 +// frequence mode monitor channel 1
16165 +#define ma_dcu_mon1__freqmode_mon__a 100
16166 +#define ma_dcu_mon1__freqmode_mon__len 3
16167 +#define ma_dcu_mon1__freqmode_mon__mask 0x70
16168 +#define ma_dcu_mon1__freqmode_mon__shift 0x04
16169 +#define ma_dcu_mon1__freqmode_mon__reset 0x00
16170 +//-------------------------------------------------------dcu_mon1.pps_passed---
16171 +// dcu1 pps completion indicator
16172 +#define ma_dcu_mon1__pps_passed__a 100
16173 +#define ma_dcu_mon1__pps_passed__len 1
16174 +#define ma_dcu_mon1__pps_passed__mask 0x80
16175 +#define ma_dcu_mon1__pps_passed__shift 0x07
16176 +#define ma_dcu_mon1__pps_passed__reset 0x00
16177 +//----------------------------------------------------------dcu_mon1.ocp_mon---
16178 +// ocp monitor channel 1
16179 +#define ma_dcu_mon1__ocp_mon__a 101
16180 +#define ma_dcu_mon1__ocp_mon__len 1
16181 +#define ma_dcu_mon1__ocp_mon__mask 0x01
16182 +#define ma_dcu_mon1__ocp_mon__shift 0x00
16183 +#define ma_dcu_mon1__ocp_mon__reset 0x00
16184 +//--------------------------------------------------------dcu_mon1.vcfly1_ok---
16185 +// cfly1 protcetion monitor channel 1
16186 +#define ma_dcu_mon1__vcfly1_ok__a 101
16187 +#define ma_dcu_mon1__vcfly1_ok__len 1
16188 +#define ma_dcu_mon1__vcfly1_ok__mask 0x02
16189 +#define ma_dcu_mon1__vcfly1_ok__shift 0x01
16190 +#define ma_dcu_mon1__vcfly1_ok__reset 0x00
16191 +//--------------------------------------------------------dcu_mon1.vcfly2_ok---
16192 +// cfly2 protection monitor channel 1
16193 +#define ma_dcu_mon1__vcfly2_ok__a 101
16194 +#define ma_dcu_mon1__vcfly2_ok__len 1
16195 +#define ma_dcu_mon1__vcfly2_ok__mask 0x04
16196 +#define ma_dcu_mon1__vcfly2_ok__shift 0x02
16197 +#define ma_dcu_mon1__vcfly2_ok__reset 0x00
16198 +//----------------------------------------------------------dcu_mon1.pvdd_ok---
16199 +// dcu1 pvdd monitor
16200 +#define ma_dcu_mon1__pvdd_ok__a 101
16201 +#define ma_dcu_mon1__pvdd_ok__len 1
16202 +#define ma_dcu_mon1__pvdd_ok__mask 0x08
16203 +#define ma_dcu_mon1__pvdd_ok__shift 0x03
16204 +#define ma_dcu_mon1__pvdd_ok__reset 0x00
16205 +//-----------------------------------------------------------dcu_mon1.vdd_ok---
16206 +// dcu1 vdd monitor
16207 +#define ma_dcu_mon1__vdd_ok__a 101
16208 +#define ma_dcu_mon1__vdd_ok__len 1
16209 +#define ma_dcu_mon1__vdd_ok__mask 0x10
16210 +#define ma_dcu_mon1__vdd_ok__shift 0x04
16211 +#define ma_dcu_mon1__vdd_ok__reset 0x00
16212 +//-------------------------------------------------------------dcu_mon1.mute---
16213 +// dcu1 mute monitor
16214 +#define ma_dcu_mon1__mute__a 101
16215 +#define ma_dcu_mon1__mute__len 1
16216 +#define ma_dcu_mon1__mute__mask 0x20
16217 +#define ma_dcu_mon1__mute__shift 0x05
16218 +#define ma_dcu_mon1__mute__reset 0x00
16219 +//------------------------------------------------------------dcu_mon1.m_mon---
16220 +// m sense monitor channel 1
16221 +#define ma_dcu_mon1__m_mon__a 102
16222 +#define ma_dcu_mon1__m_mon__len 8
16223 +#define ma_dcu_mon1__m_mon__mask 0xff
16224 +#define ma_dcu_mon1__m_mon__shift 0x00
16225 +#define ma_dcu_mon1__m_mon__reset 0x00
16226 +//--------------------------------------------------------dcu_mon0.sw_enable---
16227 +// dcu0 switch enable monitor
16228 +#define ma_dcu_mon0__sw_enable__a 104
16229 +#define ma_dcu_mon0__sw_enable__len 1
16230 +#define ma_dcu_mon0__sw_enable__mask 0x40
16231 +#define ma_dcu_mon0__sw_enable__shift 0x06
16232 +#define ma_dcu_mon0__sw_enable__reset 0x00
16233 +//--------------------------------------------------------dcu_mon1.sw_enable---
16234 +// dcu1 switch enable monitor
16235 +#define ma_dcu_mon1__sw_enable__a 104
16236 +#define ma_dcu_mon1__sw_enable__len 1
16237 +#define ma_dcu_mon1__sw_enable__mask 0x80
16238 +#define ma_dcu_mon1__sw_enable__shift 0x07
16239 +#define ma_dcu_mon1__sw_enable__reset 0x00
16240 +//------------------------------------------------------------hvboot0_ok_mon---
16241 +// hvboot0_ok for test/debug
16242 +#define ma_hvboot0_ok_mon__a 105
16243 +#define ma_hvboot0_ok_mon__len 1
16244 +#define ma_hvboot0_ok_mon__mask 0x40
16245 +#define ma_hvboot0_ok_mon__shift 0x06
16246 +#define ma_hvboot0_ok_mon__reset 0x00
16247 +//------------------------------------------------------------hvboot1_ok_mon---
16248 +// hvboot1_ok for test/debug
16249 +#define ma_hvboot1_ok_mon__a 105
16250 +#define ma_hvboot1_ok_mon__len 1
16251 +#define ma_hvboot1_ok_mon__mask 0x80
16252 +#define ma_hvboot1_ok_mon__shift 0x07
16253 +#define ma_hvboot1_ok_mon__reset 0x00
16254 +//-----------------------------------------------------------------error_acc---
16255 +// accumulated errors, at and after triggering
16256 +#define ma_error_acc__a 109
16257 +#define ma_error_acc__len 8
16258 +#define ma_error_acc__mask 0xff
16259 +#define ma_error_acc__shift 0x00
16260 +#define ma_error_acc__reset 0x00
16261 +//-------------------------------------------------------------i2s_data_rate---
16262 +// detected i2s data rate: 00/01/10 = x1/x2/x4
16263 +#define ma_i2s_data_rate__a 116
16264 +#define ma_i2s_data_rate__len 2
16265 +#define ma_i2s_data_rate__mask 0x03
16266 +#define ma_i2s_data_rate__shift 0x00
16267 +#define ma_i2s_data_rate__reset 0x00
16268 +//---------------------------------------------------------audio_in_mode_mon---
16269 +// audio input mode monitor
16270 +#define ma_audio_in_mode_mon__a 116
16271 +#define ma_audio_in_mode_mon__len 3
16272 +#define ma_audio_in_mode_mon__mask 0x1c
16273 +#define ma_audio_in_mode_mon__shift 0x02
16274 +#define ma_audio_in_mode_mon__reset 0x00
16275 +//------------------------------------------------------------------msel_mon---
16276 +// msel[2:0] monitor register
16277 +#define ma_msel_mon__a 117
16278 +#define ma_msel_mon__len 3
16279 +#define ma_msel_mon__mask 0x07
16280 +#define ma_msel_mon__shift 0x00
16281 +#define ma_msel_mon__reset 0x00
16282 +//---------------------------------------------------------------------error---
16283 +// current error flag monitor reg - for app. ctrl.
16284 +#define ma_error__a 124
16285 +#define ma_error__len 8
16286 +#define ma_error__mask 0xff
16287 +#define ma_error__shift 0x00
16288 +#define ma_error__reset 0x00
16289 +//----------------------------------------------------audio_proc_limiter_mon---
16290 +// b7-b4: channel 3-0 limiter active
16291 +#define ma_audio_proc_limiter_mon__a 126
16292 +#define ma_audio_proc_limiter_mon__len 4
16293 +#define ma_audio_proc_limiter_mon__mask 0xf0
16294 +#define ma_audio_proc_limiter_mon__shift 0x04
16295 +#define ma_audio_proc_limiter_mon__reset 0x00
16296 +//-------------------------------------------------------audio_proc_clip_mon---
16297 +// b3-b0: channel 3-0 clipping monitor
16298 +#define ma_audio_proc_clip_mon__a 126
16299 +#define ma_audio_proc_clip_mon__len 4
16300 +#define ma_audio_proc_clip_mon__mask 0x0f
16301 +#define ma_audio_proc_clip_mon__shift 0x00
16302 +#define ma_audio_proc_clip_mon__reset 0x00
16303 +#endif
16304 +
16305 +#define SOC_ENUM_ERR(xname, xenum)\
16306 +{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
16307 + .access = SNDRV_CTL_ELEM_ACCESS_READ,\
16308 + .info = snd_soc_info_enum_double,\
16309 + .get = snd_soc_get_enum_double, .put = snd_soc_put_enum_double,\
16310 + .private_value = (unsigned long)&(xenum) }
16311 +
16312 +static struct i2c_client *i2c;
16313 +
16314 +struct ma120x0p_priv {
16315 + struct regmap *regmap;
16316 + int mclk_div;
16317 + struct snd_soc_component *component;
16318 + struct gpio_desc *enable_gpio;
16319 + struct gpio_desc *mute_gpio;
16320 + struct gpio_desc *booster_gpio;
16321 + struct gpio_desc *error_gpio;
16322 +};
16323 +
16324 +static struct ma120x0p_priv *priv_data;
16325 +
16326 +//Used to share the IRQ number within this file
16327 +static unsigned int irqNumber;
16328 +
16329 +// Function prototype for the custom IRQ handler function
16330 +static irqreturn_t ma120x0p_irq_handler(int irq, void *data);
16331 +
16332 +//Alsa Controls
16333 +static const char * const limenable_text[] = {"Bypassed", "Enabled"};
16334 +static const char * const limatack_text[] = {"Slow", "Normal", "Fast"};
16335 +static const char * const limrelease_text[] = {"Slow", "Normal", "Fast"};
16336 +
16337 +static const char * const err_flycap_text[] = {"Ok", "Error"};
16338 +static const char * const err_overcurr_text[] = {"Ok", "Error"};
16339 +static const char * const err_pllerr_text[] = {"Ok", "Error"};
16340 +static const char * const err_pvddunder_text[] = {"Ok", "Error"};
16341 +static const char * const err_overtempw_text[] = {"Ok", "Error"};
16342 +static const char * const err_overtempe_text[] = {"Ok", "Error"};
16343 +static const char * const err_pinlowimp_text[] = {"Ok", "Error"};
16344 +static const char * const err_dcprot_text[] = {"Ok", "Error"};
16345 +
16346 +static const char * const pwr_mode_prof_text[] = {"PMF0", "PMF1", "PMF2",
16347 +"PMF3", "PMF4"};
16348 +
16349 +static const struct soc_enum lim_enable_ctrl =
16350 + SOC_ENUM_SINGLE(ma_audio_proc_limiterenable__a,
16351 + ma_audio_proc_limiterenable__shift,
16352 + ma_audio_proc_limiterenable__len + 1,
16353 + limenable_text);
16354 +static const struct soc_enum limatack_ctrl =
16355 + SOC_ENUM_SINGLE(ma_audio_proc_attack__a,
16356 + ma_audio_proc_attack__shift,
16357 + ma_audio_proc_attack__len + 1,
16358 + limatack_text);
16359 +static const struct soc_enum limrelease_ctrl =
16360 + SOC_ENUM_SINGLE(ma_audio_proc_release__a,
16361 + ma_audio_proc_release__shift,
16362 + ma_audio_proc_release__len + 1,
16363 + limrelease_text);
16364 +static const struct soc_enum err_flycap_ctrl =
16365 + SOC_ENUM_SINGLE(ma_error__a, 0, 3, err_flycap_text);
16366 +static const struct soc_enum err_overcurr_ctrl =
16367 + SOC_ENUM_SINGLE(ma_error__a, 1, 3, err_overcurr_text);
16368 +static const struct soc_enum err_pllerr_ctrl =
16369 + SOC_ENUM_SINGLE(ma_error__a, 2, 3, err_pllerr_text);
16370 +static const struct soc_enum err_pvddunder_ctrl =
16371 + SOC_ENUM_SINGLE(ma_error__a, 3, 3, err_pvddunder_text);
16372 +static const struct soc_enum err_overtempw_ctrl =
16373 + SOC_ENUM_SINGLE(ma_error__a, 4, 3, err_overtempw_text);
16374 +static const struct soc_enum err_overtempe_ctrl =
16375 + SOC_ENUM_SINGLE(ma_error__a, 5, 3, err_overtempe_text);
16376 +static const struct soc_enum err_pinlowimp_ctrl =
16377 + SOC_ENUM_SINGLE(ma_error__a, 6, 3, err_pinlowimp_text);
16378 +static const struct soc_enum err_dcprot_ctrl =
16379 + SOC_ENUM_SINGLE(ma_error__a, 7, 3, err_dcprot_text);
16380 +static const struct soc_enum pwr_mode_prof_ctrl =
16381 + SOC_ENUM_SINGLE(ma_pmprofile__a, ma_pmprofile__shift, 5,
16382 + pwr_mode_prof_text);
16383 +
16384 +static const char * const pwr_mode_texts[] = {
16385 + "Dynamic power mode",
16386 + "Power mode 1",
16387 + "Power mode 2",
16388 + "Power mode 3",
16389 + };
16390 +
16391 +static const int pwr_mode_values[] = {
16392 + 0x10,
16393 + 0x50,
16394 + 0x60,
16395 + 0x70,
16396 + };
16397 +
16398 +static SOC_VALUE_ENUM_SINGLE_DECL(pwr_mode_ctrl,
16399 + ma_pm_man__a, 0, 0x70,
16400 + pwr_mode_texts,
16401 + pwr_mode_values);
16402 +
16403 +static const DECLARE_TLV_DB_SCALE(ma120x0p_vol_tlv, -14400, 100, 0);
16404 +static const DECLARE_TLV_DB_SCALE(ma120x0p_lim_tlv, -5000, 100, 0);
16405 +static const DECLARE_TLV_DB_SCALE(ma120x0p_lr_tlv, -5000, 100, 0);
16406 +
16407 +static const struct snd_kcontrol_new ma120x0p_snd_controls[] = {
16408 + //Master Volume
16409 + SOC_SINGLE_RANGE_TLV("A.Mstr Vol Volume",
16410 + ma_vol_db_master__a, 0, 0x18, 0xa8, 1, ma120x0p_vol_tlv),
16411 +
16412 + //L-R Volume ch0
16413 + SOC_SINGLE_RANGE_TLV("B.L Vol Volume",
16414 + ma_vol_db_ch0__a, 0, 0x18, 0x4a, 1, ma120x0p_lr_tlv),
16415 + SOC_SINGLE_RANGE_TLV("C.R Vol Volume",
16416 + ma_vol_db_ch1__a, 0, 0x18, 0x4a, 1, ma120x0p_lr_tlv),
16417 +
16418 + //L-R Limiter Threshold ch0-ch1
16419 + SOC_DOUBLE_R_RANGE_TLV("D.Lim thresh Volume",
16420 + ma_thr_db_ch0__a, ma_thr_db_ch1__a, 0, 0x0e, 0x4a, 1,
16421 + ma120x0p_lim_tlv),
16422 +
16423 + //Enum Switches/Selectors
16424 + //SOC_ENUM("E.AudioProc Mute", audioproc_mute_ctrl),
16425 + SOC_ENUM("F.Limiter Enable", lim_enable_ctrl),
16426 + SOC_ENUM("G.Limiter Attck", limatack_ctrl),
16427 + SOC_ENUM("H.Limiter Rls", limrelease_ctrl),
16428 +
16429 + //Enum Error Monitor (read-only)
16430 + SOC_ENUM_ERR("I.Err flycap", err_flycap_ctrl),
16431 + SOC_ENUM_ERR("J.Err overcurr", err_overcurr_ctrl),
16432 + SOC_ENUM_ERR("K.Err pllerr", err_pllerr_ctrl),
16433 + SOC_ENUM_ERR("L.Err pvddunder", err_pvddunder_ctrl),
16434 + SOC_ENUM_ERR("M.Err overtempw", err_overtempw_ctrl),
16435 + SOC_ENUM_ERR("N.Err overtempe", err_overtempe_ctrl),
16436 + SOC_ENUM_ERR("O.Err pinlowimp", err_pinlowimp_ctrl),
16437 + SOC_ENUM_ERR("P.Err dcprot", err_dcprot_ctrl),
16438 +
16439 + //Power modes profiles
16440 + SOC_ENUM("Q.PM Prof", pwr_mode_prof_ctrl),
16441 +
16442 + // Power mode selection (Dynamic,1,2,3)
16443 + SOC_ENUM("R.Power Mode", pwr_mode_ctrl),
16444 +};
16445 +
16446 +//Machine Driver
16447 +static int ma120x0p_hw_params(struct snd_pcm_substream *substream,
16448 + struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
16449 +{
16450 + u16 blen = 0x00;
16451 +
16452 + struct snd_soc_component *component = dai->component;
16453 +
16454 + priv_data->component = component;
16455 +
16456 + switch (params_format(params)) {
16457 + case SNDRV_PCM_FORMAT_S16_LE:
16458 + blen = 0x10;
16459 + break;
16460 + case SNDRV_PCM_FORMAT_S24_LE:
16461 + blen = 0x00;
16462 + break;
16463 + case SNDRV_PCM_FORMAT_S32_LE:
16464 + blen = 0x00;
16465 + break;
16466 + default:
16467 + dev_err(dai->dev, "Unsupported word length: %u\n",
16468 + params_format(params));
16469 + return -EINVAL;
16470 + }
16471 +
16472 + // set word length
16473 + snd_soc_component_update_bits(component, ma_i2s_framesize__a,
16474 + ma_i2s_framesize__mask, blen);
16475 +
16476 + return 0;
16477 +}
16478 +
16479 +static int ma120x0p_mute_stream(struct snd_soc_dai *dai, int mute, int stream)
16480 +{
16481 + int val = 0;
16482 +
16483 + struct ma120x0p_priv *ma120x0p;
16484 +
16485 + struct snd_soc_component *component = dai->component;
16486 +
16487 + ma120x0p = snd_soc_component_get_drvdata(component);
16488 +
16489 + if (mute)
16490 + val = 0;
16491 + else
16492 + val = 1;
16493 +
16494 + gpiod_set_value_cansleep(priv_data->mute_gpio, val);
16495 +
16496 + return 0;
16497 +}
16498 +
16499 +static const struct snd_soc_dai_ops ma120x0p_dai_ops = {
16500 + .hw_params = ma120x0p_hw_params,
16501 + .mute_stream = ma120x0p_mute_stream,
16502 +};
16503 +
16504 +static struct snd_soc_dai_driver ma120x0p_dai = {
16505 + .name = "ma120x0p-amp",
16506 + .playback = {
16507 + .stream_name = "Playback",
16508 + .channels_min = 2,
16509 + .channels_max = 2,
16510 + .rates = SNDRV_PCM_RATE_CONTINUOUS,
16511 + .rate_min = 44100,
16512 + .rate_max = 192000,
16513 + .formats = SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE
16514 + },
16515 + .ops = &ma120x0p_dai_ops,
16516 +};
16517 +
16518 +//Codec Driver
16519 +static int ma120x0p_clear_err(struct snd_soc_component *component)
16520 +{
16521 + int ret = 0;
16522 +
16523 + struct ma120x0p_priv *ma120x0p;
16524 +
16525 + ma120x0p = snd_soc_component_get_drvdata(component);
16526 +
16527 + ret = snd_soc_component_update_bits(component,
16528 + ma_eh_clear__a, ma_eh_clear__mask, 0x00);
16529 + if (ret < 0)
16530 + return ret;
16531 +
16532 + ret = snd_soc_component_update_bits(component,
16533 + ma_eh_clear__a, ma_eh_clear__mask, 0x04);
16534 + if (ret < 0)
16535 + return ret;
16536 +
16537 + ret = snd_soc_component_update_bits(component,
16538 + ma_eh_clear__a, ma_eh_clear__mask, 0x00);
16539 + if (ret < 0)
16540 + return ret;
16541 +
16542 + return 0;
16543 +}
16544 +
16545 +static void ma120x0p_remove(struct snd_soc_component *component)
16546 +{
16547 + struct ma120x0p_priv *ma120x0p;
16548 +
16549 + ma120x0p = snd_soc_component_get_drvdata(component);
16550 +}
16551 +
16552 +static int ma120x0p_probe(struct snd_soc_component *component)
16553 +{
16554 + struct ma120x0p_priv *ma120x0p;
16555 +
16556 + int ret = 0;
16557 +
16558 + i2c = container_of(component->dev, struct i2c_client, dev);
16559 +
16560 + ma120x0p = snd_soc_component_get_drvdata(component);
16561 +
16562 + //Reset error
16563 + ma120x0p_clear_err(component);
16564 + if (ret < 0)
16565 + return ret;
16566 +
16567 + // set serial audio format I2S and enable audio processor
16568 + ret = snd_soc_component_write(component, ma_i2s_format__a, 0x08);
16569 + if (ret < 0)
16570 + return ret;
16571 +
16572 + // Enable audio limiter
16573 + ret = snd_soc_component_update_bits(component,
16574 + ma_audio_proc_limiterenable__a,
16575 + ma_audio_proc_limiterenable__mask, 0x40);
16576 + if (ret < 0)
16577 + return ret;
16578 +
16579 + // Set lim attack to fast
16580 + ret = snd_soc_component_update_bits(component,
16581 + ma_audio_proc_attack__a, ma_audio_proc_attack__mask, 0x80);
16582 + if (ret < 0)
16583 + return ret;
16584 +
16585 + // Set lim attack to low
16586 + ret = snd_soc_component_update_bits(component,
16587 + ma_audio_proc_release__a, ma_audio_proc_release__mask, 0x00);
16588 + if (ret < 0)
16589 + return ret;
16590 +
16591 + // set volume to 0dB
16592 + ret = snd_soc_component_write(component, ma_vol_db_master__a, 0x18);
16593 + if (ret < 0)
16594 + return ret;
16595 +
16596 + // set ch0 lim thresh to -15dB
16597 + ret = snd_soc_component_write(component, ma_thr_db_ch0__a, 0x27);
16598 + if (ret < 0)
16599 + return ret;
16600 +
16601 + // set ch1 lim thresh to -15dB
16602 + ret = snd_soc_component_write(component, ma_thr_db_ch1__a, 0x27);
16603 + if (ret < 0)
16604 + return ret;
16605 +
16606 + //Check for errors
16607 + ret = snd_soc_component_test_bits(component, ma_error_acc__a, 0x00, 0);
16608 + if (ret < 0)
16609 + return ret;
16610 + ret = snd_soc_component_test_bits(component, ma_error_acc__a, 0x01, 0);
16611 + if (ret < 0)
16612 + return ret;
16613 + ret = snd_soc_component_test_bits(component, ma_error_acc__a, 0x02, 0);
16614 + if (ret < 0)
16615 + return ret;
16616 + ret = snd_soc_component_test_bits(component, ma_error_acc__a, 0x08, 0);
16617 + if (ret < 0)
16618 + return ret;
16619 + ret = snd_soc_component_test_bits(component, ma_error_acc__a, 0x10, 0);
16620 + if (ret < 0)
16621 + return ret;
16622 + ret = snd_soc_component_test_bits(component, ma_error_acc__a, 0x20, 0);
16623 + if (ret < 0)
16624 + return ret;
16625 + ret = snd_soc_component_test_bits(component, ma_error_acc__a, 0x40, 0);
16626 + if (ret < 0)
16627 + return ret;
16628 + ret = snd_soc_component_test_bits(component, ma_error_acc__a, 0x80, 0);
16629 + if (ret < 0)
16630 + return ret;
16631 +
16632 + return 0;
16633 +}
16634 +
16635 +static int ma120x0p_set_bias_level(struct snd_soc_component *component,
16636 + enum snd_soc_bias_level level)
16637 +{
16638 + int ret = 0;
16639 +
16640 + struct ma120x0p_priv *ma120x0p;
16641 +
16642 + ma120x0p = snd_soc_component_get_drvdata(component);
16643 +
16644 + switch (level) {
16645 + case SND_SOC_BIAS_ON:
16646 + break;
16647 +
16648 + case SND_SOC_BIAS_PREPARE:
16649 + break;
16650 +
16651 + case SND_SOC_BIAS_STANDBY:
16652 + ret = gpiod_get_value_cansleep(priv_data->enable_gpio);
16653 + if (ret != 0) {
16654 + dev_err(component->dev, "Device ma120x0p disabled in STANDBY BIAS: %d\n",
16655 + ret);
16656 + return ret;
16657 + }
16658 + break;
16659 +
16660 + case SND_SOC_BIAS_OFF:
16661 + break;
16662 + }
16663 +
16664 + return 0;
16665 +}
16666 +
16667 +static const struct snd_soc_dapm_widget ma120x0p_dapm_widgets[] = {
16668 + SND_SOC_DAPM_OUTPUT("OUT_A"),
16669 + SND_SOC_DAPM_OUTPUT("OUT_B"),
16670 +};
16671 +
16672 +static const struct snd_soc_dapm_route ma120x0p_dapm_routes[] = {
16673 + { "OUT_B", NULL, "Playback" },
16674 + { "OUT_A", NULL, "Playback" },
16675 +};
16676 +
16677 +static const struct snd_soc_component_driver ma120x0p_component_driver = {
16678 + .probe = ma120x0p_probe,
16679 + .remove = ma120x0p_remove,
16680 + .set_bias_level = ma120x0p_set_bias_level,
16681 + .dapm_widgets = ma120x0p_dapm_widgets,
16682 + .num_dapm_widgets = ARRAY_SIZE(ma120x0p_dapm_widgets),
16683 + .dapm_routes = ma120x0p_dapm_routes,
16684 + .num_dapm_routes = ARRAY_SIZE(ma120x0p_dapm_routes),
16685 + .controls = ma120x0p_snd_controls,
16686 + .num_controls = ARRAY_SIZE(ma120x0p_snd_controls),
16687 + .use_pmdown_time = 1,
16688 + .endianness = 1,
16689 +};
16690 +
16691 +//I2C Driver
16692 +static const struct reg_default ma120x0p_reg_defaults[] = {
16693 + { 0x01, 0x3c },
16694 +};
16695 +
16696 +static bool ma120x0p_reg_volatile(struct device *dev, unsigned int reg)
16697 +{
16698 + switch (reg) {
16699 + case ma_error__a:
16700 + return true;
16701 + default:
16702 + return false;
16703 + }
16704 +}
16705 +
16706 +static const struct of_device_id ma120x0p_of_match[] = {
16707 + { .compatible = "ma,ma120x0p", },
16708 + { }
16709 +};
16710 +
16711 +MODULE_DEVICE_TABLE(of, ma120x0p_of_match);
16712 +
16713 +static struct regmap_config ma120x0p_regmap_config = {
16714 + .reg_bits = 8,
16715 + .val_bits = 8,
16716 +
16717 + .max_register = 255,
16718 + .volatile_reg = ma120x0p_reg_volatile,
16719 +
16720 + .cache_type = REGCACHE_RBTREE,
16721 + .reg_defaults = ma120x0p_reg_defaults,
16722 + .num_reg_defaults = ARRAY_SIZE(ma120x0p_reg_defaults),
16723 +};
16724 +
16725 +static int ma120x0p_i2c_probe(struct i2c_client *i2c)
16726 +{
16727 + int ret;
16728 +
16729 + priv_data = devm_kzalloc(&i2c->dev, sizeof(*priv_data), GFP_KERNEL);
16730 + if (!priv_data)
16731 + return -ENOMEM;
16732 + i2c_set_clientdata(i2c, priv_data);
16733 +
16734 + priv_data->regmap = devm_regmap_init_i2c(i2c, &ma120x0p_regmap_config);
16735 + if (IS_ERR(priv_data->regmap)) {
16736 + ret = PTR_ERR(priv_data->regmap);
16737 + return ret;
16738 + }
16739 +
16740 + //Startup sequence
16741 +
16742 + //Make sure the device is muted
16743 + priv_data->mute_gpio = devm_gpiod_get_optional(&i2c->dev, "mute_gp",
16744 + GPIOD_OUT_LOW);
16745 + if (IS_ERR(priv_data->mute_gpio)) {
16746 + ret = PTR_ERR(priv_data->mute_gpio);
16747 + dev_err(&i2c->dev, "Failed to get mute gpio line: %d\n", ret);
16748 + return ret;
16749 + }
16750 + msleep(50);
16751 +
16752 +// MA120xx0P devices are usually powered by an integrated boost converter.
16753 +// An option GPIO control line is provided to enable the booster properly and
16754 +// in sync with the enable and mute GPIO lines.
16755 + priv_data->booster_gpio = devm_gpiod_get_optional(&i2c->dev,
16756 + "booster_gp", GPIOD_OUT_LOW);
16757 + if (IS_ERR(priv_data->booster_gpio)) {
16758 + ret = PTR_ERR(priv_data->booster_gpio);
16759 + dev_err(&i2c->dev,
16760 + "Failed to get booster enable gpio line: %d\n", ret);
16761 + return ret;
16762 + }
16763 + msleep(50);
16764 +
16765 + //Enable booster and wait 200ms until stable PVDD
16766 + gpiod_set_value_cansleep(priv_data->booster_gpio, 1);
16767 + msleep(200);
16768 +
16769 + //Enable ma120x0pp
16770 + priv_data->enable_gpio = devm_gpiod_get_optional(&i2c->dev,
16771 + "enable_gp", GPIOD_OUT_LOW);
16772 + if (IS_ERR(priv_data->enable_gpio)) {
16773 + ret = PTR_ERR(priv_data->enable_gpio);
16774 + dev_err(&i2c->dev,
16775 + "Failed to get ma120x0p enable gpio line: %d\n", ret);
16776 + return ret;
16777 + }
16778 + msleep(50);
16779 +
16780 + //Optional use of ma120x0pp error line as an interrupt trigger to
16781 + //platform GPIO.
16782 + //Get error input gpio ma120x0p
16783 + priv_data->error_gpio = devm_gpiod_get_optional(&i2c->dev,
16784 + "error_gp", GPIOD_IN);
16785 + if (IS_ERR(priv_data->error_gpio)) {
16786 + ret = PTR_ERR(priv_data->error_gpio);
16787 + dev_err(&i2c->dev,
16788 + "Failed to get ma120x0p error gpio line: %d\n", ret);
16789 + return ret;
16790 + }
16791 +
16792 + if (priv_data->error_gpio != NULL) {
16793 + irqNumber = gpiod_to_irq(priv_data->error_gpio);
16794 +
16795 + ret = devm_request_threaded_irq(&i2c->dev,
16796 + irqNumber, ma120x0p_irq_handler,
16797 + NULL, IRQF_TRIGGER_FALLING,
16798 + "ma120x0p", priv_data);
16799 + if (ret != 0)
16800 + dev_warn(&i2c->dev, "Failed to request IRQ: %d\n",
16801 + ret);
16802 + }
16803 +
16804 + ret = devm_snd_soc_register_component(&i2c->dev,
16805 + &ma120x0p_component_driver, &ma120x0p_dai, 1);
16806 +
16807 + return ret;
16808 +}
16809 +
16810 +static irqreturn_t ma120x0p_irq_handler(int irq, void *data)
16811 +{
16812 + gpiod_set_value_cansleep(priv_data->mute_gpio, 0);
16813 + gpiod_set_value_cansleep(priv_data->enable_gpio, 1);
16814 + return IRQ_HANDLED;
16815 +}
16816 +
16817 +static void ma120x0p_i2c_remove(struct i2c_client *i2c)
16818 +{
16819 + snd_soc_unregister_component(&i2c->dev);
16820 + i2c_set_clientdata(i2c, NULL);
16821 +
16822 + gpiod_set_value_cansleep(priv_data->mute_gpio, 0);
16823 + msleep(30);
16824 + gpiod_set_value_cansleep(priv_data->enable_gpio, 1);
16825 + msleep(200);
16826 + gpiod_set_value_cansleep(priv_data->booster_gpio, 0);
16827 + msleep(200);
16828 +
16829 + kfree(priv_data);
16830 +}
16831 +
16832 +static void ma120x0p_i2c_shutdown(struct i2c_client *i2c)
16833 +{
16834 + snd_soc_unregister_component(&i2c->dev);
16835 + i2c_set_clientdata(i2c, NULL);
16836 +
16837 + gpiod_set_value_cansleep(priv_data->mute_gpio, 0);
16838 + msleep(30);
16839 + gpiod_set_value_cansleep(priv_data->enable_gpio, 1);
16840 + msleep(200);
16841 + gpiod_set_value_cansleep(priv_data->booster_gpio, 0);
16842 + msleep(200);
16843 +
16844 + kfree(priv_data);
16845 +}
16846 +
16847 +static const struct i2c_device_id ma120x0p_i2c_id[] = {
16848 + { "ma120x0p", 0 },
16849 + { }
16850 +};
16851 +
16852 +MODULE_DEVICE_TABLE(i2c, ma120x0p_i2c_id);
16853 +
16854 +static struct i2c_driver ma120x0p_i2c_driver = {
16855 + .driver = {
16856 + .name = "ma120x0p",
16857 + .owner = THIS_MODULE,
16858 + .of_match_table = ma120x0p_of_match,
16859 + },
16860 + .probe = ma120x0p_i2c_probe,
16861 + .remove = ma120x0p_i2c_remove,
16862 + .shutdown = ma120x0p_i2c_shutdown,
16863 + .id_table = ma120x0p_i2c_id
16864 +};
16865 +
16866 +static int __init ma120x0p_modinit(void)
16867 +{
16868 + int ret = 0;
16869 +
16870 + ret = i2c_add_driver(&ma120x0p_i2c_driver);
16871 + if (ret != 0) {
16872 + pr_err("Failed to register MA120X0P I2C driver: %d\n", ret);
16873 + return ret;
16874 + }
16875 + return ret;
16876 +}
16877 +module_init(ma120x0p_modinit);
16878 +
16879 +static void __exit ma120x0p_exit(void)
16880 +{
16881 + i2c_del_driver(&ma120x0p_i2c_driver);
16882 +}
16883 +module_exit(ma120x0p_exit);
16884 +
16885 +MODULE_AUTHOR("Ariel Muszkat ariel.muszkat@gmail.com>");
16886 +MODULE_DESCRIPTION("ASoC driver for ma120x0p");
16887 +MODULE_LICENSE("GPL v2");
16888 --- /dev/null
16889 +++ b/sound/soc/codecs/pcm1794a.c
16890 @@ -0,0 +1,69 @@
16891 +/*
16892 + * Driver for the PCM1794A codec
16893 + *
16894 + * Author: Florian Meier <florian.meier@koalo.de>
16895 + * Copyright 2013
16896 + *
16897 + * This program is free software; you can redistribute it and/or
16898 + * modify it under the terms of the GNU General Public License
16899 + * version 2 as published by the Free Software Foundation.
16900 + *
16901 + * This program is distributed in the hope that it will be useful, but
16902 + * WITHOUT ANY WARRANTY; without even the implied warranty of
16903 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16904 + * General Public License for more details.
16905 + */
16906 +
16907 +
16908 +#include <linux/init.h>
16909 +#include <linux/module.h>
16910 +#include <linux/platform_device.h>
16911 +
16912 +#include <sound/soc.h>
16913 +
16914 +static struct snd_soc_dai_driver pcm1794a_dai = {
16915 + .name = "pcm1794a-hifi",
16916 + .playback = {
16917 + .channels_min = 2,
16918 + .channels_max = 2,
16919 + .rates = SNDRV_PCM_RATE_8000_192000,
16920 + .formats = SNDRV_PCM_FMTBIT_S16_LE |
16921 + SNDRV_PCM_FMTBIT_S24_LE
16922 + },
16923 +};
16924 +
16925 +static struct snd_soc_component_driver soc_component_dev_pcm1794a;
16926 +
16927 +static int pcm1794a_probe(struct platform_device *pdev)
16928 +{
16929 + return snd_soc_register_component(&pdev->dev, &soc_component_dev_pcm1794a,
16930 + &pcm1794a_dai, 1);
16931 +}
16932 +
16933 +static int pcm1794a_remove(struct platform_device *pdev)
16934 +{
16935 + snd_soc_unregister_component(&pdev->dev);
16936 + return 0;
16937 +}
16938 +
16939 +static const struct of_device_id pcm1794a_of_match[] = {
16940 + { .compatible = "ti,pcm1794a", },
16941 + { }
16942 +};
16943 +MODULE_DEVICE_TABLE(of, pcm1794a_of_match);
16944 +
16945 +static struct platform_driver pcm1794a_component_driver = {
16946 + .probe = pcm1794a_probe,
16947 + .remove = pcm1794a_remove,
16948 + .driver = {
16949 + .name = "pcm1794a-codec",
16950 + .owner = THIS_MODULE,
16951 + .of_match_table = of_match_ptr(pcm1794a_of_match),
16952 + },
16953 +};
16954 +
16955 +module_platform_driver(pcm1794a_component_driver);
16956 +
16957 +MODULE_DESCRIPTION("ASoC PCM1794A codec driver");
16958 +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
16959 +MODULE_LICENSE("GPL v2");
16960 --- a/sound/soc/codecs/pcm512x.c
16961 +++ b/sound/soc/codecs/pcm512x.c
16962 @@ -536,7 +536,7 @@ static unsigned long pcm512x_ncp_target(
16963
16964 static const u32 pcm512x_dai_rates[] = {
16965 8000, 11025, 16000, 22050, 32000, 44100, 48000, 64000,
16966 - 88200, 96000, 176400, 192000, 384000,
16967 + 88200, 96000, 176400, 192000, 352800, 384000,
16968 };
16969
16970 static const struct snd_pcm_hw_constraint_list constraints_slave = {
16971 --- /dev/null
16972 +++ b/sound/soc/codecs/tas5713.c
16973 @@ -0,0 +1,360 @@
16974 +/*
16975 + * ASoC Driver for TAS5713
16976 + *
16977 + * Author: Sebastian Eickhoff <basti.eickhoff@googlemail.com>
16978 + * Copyright 2014
16979 + *
16980 + * This program is free software; you can redistribute it and/or
16981 + * modify it under the terms of the GNU General Public License
16982 + * version 2 as published by the Free Software Foundation.
16983 + *
16984 + * This program is distributed in the hope that it will be useful, but
16985 + * WITHOUT ANY WARRANTY; without even the implied warranty of
16986 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16987 + * General Public License for more details.
16988 + */
16989 +
16990 +#include <linux/module.h>
16991 +#include <linux/moduleparam.h>
16992 +#include <linux/init.h>
16993 +#include <linux/delay.h>
16994 +#include <linux/pm.h>
16995 +#include <linux/i2c.h>
16996 +#include <linux/of_device.h>
16997 +#include <linux/spi/spi.h>
16998 +#include <linux/regmap.h>
16999 +#include <linux/regulator/consumer.h>
17000 +#include <linux/slab.h>
17001 +#include <sound/core.h>
17002 +#include <sound/pcm.h>
17003 +#include <sound/pcm_params.h>
17004 +#include <sound/soc.h>
17005 +#include <sound/initval.h>
17006 +#include <sound/tlv.h>
17007 +
17008 +#include <linux/kernel.h>
17009 +#include <linux/string.h>
17010 +#include <linux/fs.h>
17011 +#include <asm/uaccess.h>
17012 +
17013 +#include "tas5713.h"
17014 +
17015 +
17016 +static struct i2c_client *i2c;
17017 +
17018 +struct tas5713_priv {
17019 + struct regmap *regmap;
17020 + int mclk_div;
17021 + struct snd_soc_component *component;
17022 +};
17023 +
17024 +static struct tas5713_priv *priv_data;
17025 +
17026 +
17027 +
17028 +
17029 +/*
17030 + * _ _ ___ _ ___ _ _
17031 + * /_\ | | / __| /_\ / __|___ _ _| |_ _ _ ___| |___
17032 + * / _ \| |__\__ \/ _ \ | (__/ _ \ ' \ _| '_/ _ \ (_-<
17033 + * /_/ \_\____|___/_/ \_\ \___\___/_||_\__|_| \___/_/__/
17034 + *
17035 + */
17036 +
17037 +static const DECLARE_TLV_DB_SCALE(tas5713_vol_tlv, -10000, 50, 1);
17038 +
17039 +
17040 +static const struct snd_kcontrol_new tas5713_snd_controls[] = {
17041 + SOC_SINGLE_TLV ("Master" , TAS5713_VOL_MASTER, 0, 248, 1, tas5713_vol_tlv),
17042 + SOC_DOUBLE_R_TLV("Channels" , TAS5713_VOL_CH1, TAS5713_VOL_CH2, 0, 248, 1, tas5713_vol_tlv)
17043 +};
17044 +
17045 +
17046 +
17047 +
17048 +/*
17049 + * __ __ _ _ ___ _
17050 + * | \/ |__ _ __| |_ (_)_ _ ___ | \ _ _(_)_ _____ _ _
17051 + * | |\/| / _` / _| ' \| | ' \/ -_) | |) | '_| \ V / -_) '_|
17052 + * |_| |_\__,_\__|_||_|_|_||_\___| |___/|_| |_|\_/\___|_|
17053 + *
17054 + */
17055 +
17056 +static int tas5713_hw_params(struct snd_pcm_substream *substream,
17057 + struct snd_pcm_hw_params *params,
17058 + struct snd_soc_dai *dai)
17059 +{
17060 + u16 blen = 0x00;
17061 +
17062 + struct snd_soc_component *component = dai->component;
17063 + priv_data->component = component;
17064 +
17065 + switch (params_format(params)) {
17066 + case SNDRV_PCM_FORMAT_S16_LE:
17067 + blen = 0x03;
17068 + break;
17069 + case SNDRV_PCM_FORMAT_S20_3LE:
17070 + blen = 0x1;
17071 + break;
17072 + case SNDRV_PCM_FORMAT_S24_LE:
17073 + blen = 0x04;
17074 + break;
17075 + case SNDRV_PCM_FORMAT_S32_LE:
17076 + blen = 0x05;
17077 + break;
17078 + default:
17079 + dev_err(dai->dev, "Unsupported word length: %u\n",
17080 + params_format(params));
17081 + return -EINVAL;
17082 + }
17083 +
17084 + // set word length
17085 + snd_soc_component_update_bits(component, TAS5713_SERIAL_DATA_INTERFACE, 0x7, blen);
17086 +
17087 + return 0;
17088 +}
17089 +
17090 +
17091 +static int tas5713_mute_stream(struct snd_soc_dai *dai, int mute, int stream)
17092 +{
17093 + unsigned int val = 0;
17094 +
17095 + struct tas5713_priv *tas5713;
17096 + struct snd_soc_component *component = dai->component;
17097 + tas5713 = snd_soc_component_get_drvdata(component);
17098 +
17099 + if (mute) {
17100 + val = TAS5713_SOFT_MUTE_ALL;
17101 + }
17102 +
17103 + return regmap_write(tas5713->regmap, TAS5713_SOFT_MUTE, val);
17104 +}
17105 +
17106 +
17107 +static const struct snd_soc_dai_ops tas5713_dai_ops = {
17108 + .hw_params = tas5713_hw_params,
17109 + .mute_stream = tas5713_mute_stream,
17110 +};
17111 +
17112 +
17113 +static struct snd_soc_dai_driver tas5713_dai = {
17114 + .name = "tas5713-hifi",
17115 + .playback = {
17116 + .stream_name = "Playback",
17117 + .channels_min = 2,
17118 + .channels_max = 2,
17119 + .rates = SNDRV_PCM_RATE_8000_48000,
17120 + .formats = (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE ),
17121 + },
17122 + .ops = &tas5713_dai_ops,
17123 +};
17124 +
17125 +
17126 +
17127 +
17128 +/*
17129 + * ___ _ ___ _
17130 + * / __|___ __| |___ __ | \ _ _(_)_ _____ _ _
17131 + * | (__/ _ \/ _` / -_) _| | |) | '_| \ V / -_) '_|
17132 + * \___\___/\__,_\___\__| |___/|_| |_|\_/\___|_|
17133 + *
17134 + */
17135 +
17136 +static void tas5713_remove(struct snd_soc_component *component)
17137 +{
17138 + struct tas5713_priv *tas5713;
17139 +
17140 + tas5713 = snd_soc_component_get_drvdata(component);
17141 +}
17142 +
17143 +
17144 +static int tas5713_probe(struct snd_soc_component *component)
17145 +{
17146 + struct tas5713_priv *tas5713;
17147 + int i, ret;
17148 +
17149 + i2c = container_of(component->dev, struct i2c_client, dev);
17150 +
17151 + tas5713 = snd_soc_component_get_drvdata(component);
17152 +
17153 + // Reset error
17154 + ret = snd_soc_component_write(component, TAS5713_ERROR_STATUS, 0x00);
17155 + if (ret < 0) return ret;
17156 +
17157 + // Trim oscillator
17158 + ret = snd_soc_component_write(component, TAS5713_OSC_TRIM, 0x00);
17159 + if (ret < 0) return ret;
17160 + msleep(1000);
17161 +
17162 + // Reset error
17163 + ret = snd_soc_component_write(component, TAS5713_ERROR_STATUS, 0x00);
17164 + if (ret < 0) return ret;
17165 +
17166 + // I2S 24bit
17167 + ret = snd_soc_component_write(component, TAS5713_SERIAL_DATA_INTERFACE, 0x05);
17168 + if (ret < 0) return ret;
17169 +
17170 + // Unmute
17171 + ret = snd_soc_component_write(component, TAS5713_SYSTEM_CTRL2, 0x00);
17172 + if (ret < 0) return ret;
17173 + ret = snd_soc_component_write(component, TAS5713_SOFT_MUTE, 0x00);
17174 + if (ret < 0) return ret;
17175 +
17176 + // Set volume to 0db
17177 + ret = snd_soc_component_write(component, TAS5713_VOL_MASTER, 0x00);
17178 + if (ret < 0) return ret;
17179 +
17180 + // Now start programming the default initialization sequence
17181 + for (i = 0; i < ARRAY_SIZE(tas5713_init_sequence); ++i) {
17182 + ret = i2c_master_send(i2c,
17183 + tas5713_init_sequence[i].data,
17184 + tas5713_init_sequence[i].size);
17185 + if (ret < 0) {
17186 + printk(KERN_INFO "TAS5713 CODEC PROBE: InitSeq returns: %d\n", ret);
17187 + }
17188 + }
17189 +
17190 + // Unmute
17191 + ret = snd_soc_component_write(component, TAS5713_SYSTEM_CTRL2, 0x00);
17192 + if (ret < 0) return ret;
17193 +
17194 + return 0;
17195 +}
17196 +
17197 +
17198 +static struct snd_soc_component_driver soc_codec_dev_tas5713 = {
17199 + .probe = tas5713_probe,
17200 + .remove = tas5713_remove,
17201 + .controls = tas5713_snd_controls,
17202 + .num_controls = ARRAY_SIZE(tas5713_snd_controls),
17203 +};
17204 +
17205 +
17206 +
17207 +
17208 +/*
17209 + * ___ ___ ___ ___ _
17210 + * |_ _|_ ) __| | \ _ _(_)_ _____ _ _
17211 + * | | / / (__ | |) | '_| \ V / -_) '_|
17212 + * |___/___\___| |___/|_| |_|\_/\___|_|
17213 + *
17214 + */
17215 +
17216 +static const struct reg_default tas5713_reg_defaults[] = {
17217 + { 0x07 ,0x80 }, // R7 - VOL_MASTER - -40dB
17218 + { 0x08 , 30 }, // R8 - VOL_CH1 - 0dB
17219 + { 0x09 , 30 }, // R9 - VOL_CH2 - 0dB
17220 + { 0x0A ,0x80 }, // R10 - VOL_HEADPHONE - -40dB
17221 +};
17222 +
17223 +
17224 +static bool tas5713_reg_volatile(struct device *dev, unsigned int reg)
17225 +{
17226 + switch (reg) {
17227 + case TAS5713_DEVICE_ID:
17228 + case TAS5713_ERROR_STATUS:
17229 + case TAS5713_CLOCK_CTRL:
17230 + return true;
17231 + default:
17232 + return false;
17233 + }
17234 +}
17235 +
17236 +
17237 +static const struct of_device_id tas5713_of_match[] = {
17238 + { .compatible = "ti,tas5713", },
17239 + { }
17240 +};
17241 +MODULE_DEVICE_TABLE(of, tas5713_of_match);
17242 +
17243 +
17244 +static struct regmap_config tas5713_regmap_config = {
17245 + .reg_bits = 8,
17246 + .val_bits = 8,
17247 +
17248 + .max_register = TAS5713_MAX_REGISTER,
17249 + .volatile_reg = tas5713_reg_volatile,
17250 +
17251 + .cache_type = REGCACHE_RBTREE,
17252 + .reg_defaults = tas5713_reg_defaults,
17253 + .num_reg_defaults = ARRAY_SIZE(tas5713_reg_defaults),
17254 +};
17255 +
17256 +
17257 +static int tas5713_i2c_probe(struct i2c_client *i2c)
17258 +{
17259 + int ret;
17260 +
17261 + priv_data = devm_kzalloc(&i2c->dev, sizeof *priv_data, GFP_KERNEL);
17262 + if (!priv_data)
17263 + return -ENOMEM;
17264 +
17265 + priv_data->regmap = devm_regmap_init_i2c(i2c, &tas5713_regmap_config);
17266 + if (IS_ERR(priv_data->regmap)) {
17267 + ret = PTR_ERR(priv_data->regmap);
17268 + return ret;
17269 + }
17270 +
17271 + i2c_set_clientdata(i2c, priv_data);
17272 +
17273 + ret = snd_soc_register_component(&i2c->dev,
17274 + &soc_codec_dev_tas5713, &tas5713_dai, 1);
17275 +
17276 + return ret;
17277 +}
17278 +
17279 +
17280 +static void tas5713_i2c_remove(struct i2c_client *i2c)
17281 +{
17282 + snd_soc_unregister_component(&i2c->dev);
17283 + i2c_set_clientdata(i2c, NULL);
17284 +
17285 + kfree(priv_data);
17286 +}
17287 +
17288 +
17289 +static const struct i2c_device_id tas5713_i2c_id[] = {
17290 + { "tas5713", 0 },
17291 + { }
17292 +};
17293 +
17294 +MODULE_DEVICE_TABLE(i2c, tas5713_i2c_id);
17295 +
17296 +
17297 +static struct i2c_driver tas5713_i2c_driver = {
17298 + .driver = {
17299 + .name = "tas5713",
17300 + .owner = THIS_MODULE,
17301 + .of_match_table = tas5713_of_match,
17302 + },
17303 + .probe = tas5713_i2c_probe,
17304 + .remove = tas5713_i2c_remove,
17305 + .id_table = tas5713_i2c_id
17306 +};
17307 +
17308 +
17309 +static int __init tas5713_modinit(void)
17310 +{
17311 + int ret = 0;
17312 +
17313 + ret = i2c_add_driver(&tas5713_i2c_driver);
17314 + if (ret) {
17315 + printk(KERN_ERR "Failed to register tas5713 I2C driver: %d\n",
17316 + ret);
17317 + }
17318 +
17319 + return ret;
17320 +}
17321 +module_init(tas5713_modinit);
17322 +
17323 +
17324 +static void __exit tas5713_exit(void)
17325 +{
17326 + i2c_del_driver(&tas5713_i2c_driver);
17327 +}
17328 +module_exit(tas5713_exit);
17329 +
17330 +
17331 +MODULE_AUTHOR("Sebastian Eickhoff <basti.eickhoff@googlemail.com>");
17332 +MODULE_DESCRIPTION("ASoC driver for TAS5713");
17333 +MODULE_LICENSE("GPL v2");
17334 --- /dev/null
17335 +++ b/sound/soc/codecs/tas5713.h
17336 @@ -0,0 +1,210 @@
17337 +/*
17338 + * ASoC Driver for TAS5713
17339 + *
17340 + * Author: Sebastian Eickhoff <basti.eickhoff@googlemail.com>
17341 + * Copyright 2014
17342 + *
17343 + * This program is free software; you can redistribute it and/or
17344 + * modify it under the terms of the GNU General Public License
17345 + * version 2 as published by the Free Software Foundation.
17346 + *
17347 + * This program is distributed in the hope that it will be useful, but
17348 + * WITHOUT ANY WARRANTY; without even the implied warranty of
17349 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17350 + * General Public License for more details.
17351 + */
17352 +
17353 +#ifndef _TAS5713_H
17354 +#define _TAS5713_H
17355 +
17356 +
17357 +// TAS5713 I2C-bus register addresses
17358 +
17359 +#define TAS5713_CLOCK_CTRL 0x00
17360 +#define TAS5713_DEVICE_ID 0x01
17361 +#define TAS5713_ERROR_STATUS 0x02
17362 +#define TAS5713_SYSTEM_CTRL1 0x03
17363 +#define TAS5713_SERIAL_DATA_INTERFACE 0x04
17364 +#define TAS5713_SYSTEM_CTRL2 0x05
17365 +#define TAS5713_SOFT_MUTE 0x06
17366 +#define TAS5713_VOL_MASTER 0x07
17367 +#define TAS5713_VOL_CH1 0x08
17368 +#define TAS5713_VOL_CH2 0x09
17369 +#define TAS5713_VOL_HEADPHONE 0x0A
17370 +#define TAS5713_VOL_CONFIG 0x0E
17371 +#define TAS5713_MODULATION_LIMIT 0x10
17372 +#define TAS5713_IC_DLY_CH1 0x11
17373 +#define TAS5713_IC_DLY_CH2 0x12
17374 +#define TAS5713_IC_DLY_CH3 0x13
17375 +#define TAS5713_IC_DLY_CH4 0x14
17376 +
17377 +#define TAS5713_START_STOP_PERIOD 0x1A
17378 +#define TAS5713_OSC_TRIM 0x1B
17379 +#define TAS5713_BKND_ERR 0x1C
17380 +
17381 +#define TAS5713_INPUT_MUX 0x20
17382 +#define TAS5713_SRC_SELECT_CH4 0x21
17383 +#define TAS5713_PWM_MUX 0x25
17384 +
17385 +#define TAS5713_CH1_BQ0 0x29
17386 +#define TAS5713_CH1_BQ1 0x2A
17387 +#define TAS5713_CH1_BQ2 0x2B
17388 +#define TAS5713_CH1_BQ3 0x2C
17389 +#define TAS5713_CH1_BQ4 0x2D
17390 +#define TAS5713_CH1_BQ5 0x2E
17391 +#define TAS5713_CH1_BQ6 0x2F
17392 +#define TAS5713_CH1_BQ7 0x58
17393 +#define TAS5713_CH1_BQ8 0x59
17394 +
17395 +#define TAS5713_CH2_BQ0 0x30
17396 +#define TAS5713_CH2_BQ1 0x31
17397 +#define TAS5713_CH2_BQ2 0x32
17398 +#define TAS5713_CH2_BQ3 0x33
17399 +#define TAS5713_CH2_BQ4 0x34
17400 +#define TAS5713_CH2_BQ5 0x35
17401 +#define TAS5713_CH2_BQ6 0x36
17402 +#define TAS5713_CH2_BQ7 0x5C
17403 +#define TAS5713_CH2_BQ8 0x5D
17404 +
17405 +#define TAS5713_CH4_BQ0 0x5A
17406 +#define TAS5713_CH4_BQ1 0x5B
17407 +#define TAS5713_CH3_BQ0 0x5E
17408 +#define TAS5713_CH3_BQ1 0x5F
17409 +
17410 +#define TAS5713_DRC1_SOFTENING_FILTER_ALPHA_OMEGA 0x3B
17411 +#define TAS5713_DRC1_ATTACK_RELEASE_RATE 0x3C
17412 +#define TAS5713_DRC2_SOFTENING_FILTER_ALPHA_OMEGA 0x3E
17413 +#define TAS5713_DRC2_ATTACK_RELEASE_RATE 0x3F
17414 +#define TAS5713_DRC1_ATTACK_RELEASE_THRES 0x40
17415 +#define TAS5713_DRC2_ATTACK_RELEASE_THRES 0x43
17416 +#define TAS5713_DRC_CTRL 0x46
17417 +
17418 +#define TAS5713_BANK_SW_CTRL 0x50
17419 +#define TAS5713_CH1_OUTPUT_MIXER 0x51
17420 +#define TAS5713_CH2_OUTPUT_MIXER 0x52
17421 +#define TAS5713_CH1_INPUT_MIXER 0x53
17422 +#define TAS5713_CH2_INPUT_MIXER 0x54
17423 +#define TAS5713_OUTPUT_POST_SCALE 0x56
17424 +#define TAS5713_OUTPUT_PRESCALE 0x57
17425 +
17426 +#define TAS5713_IDF_POST_SCALE 0x62
17427 +
17428 +#define TAS5713_CH1_INLINE_MIXER 0x70
17429 +#define TAS5713_CH1_INLINE_DRC_EN_MIXER 0x71
17430 +#define TAS5713_CH1_R_CHANNEL_MIXER 0x72
17431 +#define TAS5713_CH1_L_CHANNEL_MIXER 0x73
17432 +#define TAS5713_CH2_INLINE_MIXER 0x74
17433 +#define TAS5713_CH2_INLINE_DRC_EN_MIXER 0x75
17434 +#define TAS5713_CH2_L_CHANNEL_MIXER 0x76
17435 +#define TAS5713_CH2_R_CHANNEL_MIXER 0x77
17436 +
17437 +#define TAS5713_UPDATE_DEV_ADDR_KEY 0xF8
17438 +#define TAS5713_UPDATE_DEV_ADDR_REG 0xF9
17439 +
17440 +#define TAS5713_REGISTER_COUNT 0x46
17441 +#define TAS5713_MAX_REGISTER 0xF9
17442 +
17443 +
17444 +// Bitmasks for registers
17445 +#define TAS5713_SOFT_MUTE_ALL 0x07
17446 +
17447 +
17448 +
17449 +struct tas5713_init_command {
17450 + const int size;
17451 + const char *const data;
17452 +};
17453 +
17454 +static const struct tas5713_init_command tas5713_init_sequence[] = {
17455 +
17456 + // Trim oscillator
17457 + { .size = 2, .data = "\x1B\x00" },
17458 + // System control register 1 (0x03): block DC
17459 + { .size = 2, .data = "\x03\x80" },
17460 + // Mute everything
17461 + { .size = 2, .data = "\x05\x40" },
17462 + // Modulation limit register (0x10): 97.7%
17463 + { .size = 2, .data = "\x10\x02" },
17464 + // Interchannel delay registers
17465 + // (0x11, 0x12, 0x13, and 0x14): BD mode
17466 + { .size = 2, .data = "\x11\xB8" },
17467 + { .size = 2, .data = "\x12\x60" },
17468 + { .size = 2, .data = "\x13\xA0" },
17469 + { .size = 2, .data = "\x14\x48" },
17470 + // PWM shutdown group register (0x19): no shutdown
17471 + { .size = 2, .data = "\x19\x00" },
17472 + // Input multiplexer register (0x20): BD mode
17473 + { .size = 2, .data = "\x20\x00\x89\x77\x72" },
17474 + // PWM output mux register (0x25)
17475 + // Channel 1 --> OUTA, channel 1 neg --> OUTB
17476 + // Channel 2 --> OUTC, channel 2 neg --> OUTD
17477 + { .size = 5, .data = "\x25\x01\x02\x13\x45" },
17478 + // DRC control (0x46): DRC off
17479 + { .size = 5, .data = "\x46\x00\x00\x00\x00" },
17480 + // BKND_ERR register (0x1C): 299ms reset period
17481 + { .size = 2, .data = "\x1C\x07" },
17482 + // Mute channel 3
17483 + { .size = 2, .data = "\x0A\xFF" },
17484 + // Volume configuration register (0x0E): volume slew 512 steps
17485 + { .size = 2, .data = "\x0E\x90" },
17486 + // Clock control register (0x00): 44/48kHz, MCLK=64xfs
17487 + { .size = 2, .data = "\x00\x60" },
17488 + // Bank switch and eq control (0x50): no bank switching
17489 + { .size = 5, .data = "\x50\x00\x00\x00\x00" },
17490 + // Volume registers (0x07, 0x08, 0x09, 0x0A)
17491 + { .size = 2, .data = "\x07\x20" },
17492 + { .size = 2, .data = "\x08\x30" },
17493 + { .size = 2, .data = "\x09\x30" },
17494 + { .size = 2, .data = "\x0A\xFF" },
17495 + // 0x72, 0x73, 0x76, 0x77 input mixer:
17496 + // no intermix between channels
17497 + { .size = 5, .data = "\x72\x00\x00\x00\x00" },
17498 + { .size = 5, .data = "\x73\x00\x80\x00\x00" },
17499 + { .size = 5, .data = "\x76\x00\x00\x00\x00" },
17500 + { .size = 5, .data = "\x77\x00\x80\x00\x00" },
17501 + // 0x70, 0x71, 0x74, 0x75 inline DRC mixer:
17502 + // no inline DRC inmix
17503 + { .size = 5, .data = "\x70\x00\x80\x00\x00" },
17504 + { .size = 5, .data = "\x71\x00\x00\x00\x00" },
17505 + { .size = 5, .data = "\x74\x00\x80\x00\x00" },
17506 + { .size = 5, .data = "\x75\x00\x00\x00\x00" },
17507 + // 0x56, 0x57 Output scale
17508 + { .size = 5, .data = "\x56\x00\x80\x00\x00" },
17509 + { .size = 5, .data = "\x57\x00\x02\x00\x00" },
17510 + // 0x3B, 0x3c
17511 + { .size = 9, .data = "\x3B\x00\x08\x00\x00\x00\x78\x00\x00" },
17512 + { .size = 9, .data = "\x3C\x00\x00\x01\x00\xFF\xFF\xFF\x00" },
17513 + { .size = 9, .data = "\x3E\x00\x08\x00\x00\x00\x78\x00\x00" },
17514 + { .size = 9, .data = "\x3F\x00\x00\x01\x00\xFF\xFF\xFF\x00" },
17515 + { .size = 9, .data = "\x40\x00\x00\x01\x00\xFF\xFF\xFF\x00" },
17516 + { .size = 9, .data = "\x43\x00\x00\x01\x00\xFF\xFF\xFF\x00" },
17517 + // 0x51, 0x52: output mixer
17518 + { .size = 9, .data = "\x51\x00\x80\x00\x00\x00\x00\x00\x00" },
17519 + { .size = 9, .data = "\x52\x00\x80\x00\x00\x00\x00\x00\x00" },
17520 + // PEQ defaults
17521 + { .size = 21, .data = "\x29\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
17522 + { .size = 21, .data = "\x2A\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
17523 + { .size = 21, .data = "\x2B\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
17524 + { .size = 21, .data = "\x2C\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
17525 + { .size = 21, .data = "\x2D\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
17526 + { .size = 21, .data = "\x2E\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
17527 + { .size = 21, .data = "\x2F\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
17528 + { .size = 21, .data = "\x30\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
17529 + { .size = 21, .data = "\x31\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
17530 + { .size = 21, .data = "\x32\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
17531 + { .size = 21, .data = "\x33\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
17532 + { .size = 21, .data = "\x34\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
17533 + { .size = 21, .data = "\x35\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
17534 + { .size = 21, .data = "\x36\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
17535 + { .size = 21, .data = "\x58\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
17536 + { .size = 21, .data = "\x59\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
17537 + { .size = 21, .data = "\x5C\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
17538 + { .size = 21, .data = "\x5D\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
17539 + { .size = 21, .data = "\x5E\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
17540 + { .size = 21, .data = "\x5F\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
17541 + { .size = 21, .data = "\x5A\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
17542 + { .size = 21, .data = "\x5B\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
17543 +};
17544 +
17545 +
17546 +#endif /* _TAS5713_H */
17547 --- a/sound/soc/soc-core.c
17548 +++ b/sound/soc/soc-core.c
17549 @@ -1316,7 +1316,15 @@ int snd_soc_runtime_set_dai_fmt(struct s
17550 return 0;
17551
17552 for_each_rtd_codec_dais(rtd, i, codec_dai) {
17553 - ret = snd_soc_dai_set_fmt(codec_dai, dai_fmt);
17554 + unsigned int codec_dai_fmt = dai_fmt;
17555 +
17556 + // there can only be one master when using multiple codecs
17557 + if (i && (codec_dai_fmt & SND_SOC_DAIFMT_MASTER_MASK)) {
17558 + codec_dai_fmt &= ~SND_SOC_DAIFMT_MASTER_MASK;
17559 + codec_dai_fmt |= SND_SOC_DAIFMT_CBS_CFS;
17560 + }
17561 +
17562 + ret = snd_soc_dai_set_fmt(codec_dai, codec_dai_fmt);
17563 if (ret != 0 && ret != -ENOTSUPP)
17564 return ret;
17565 }
17566 --- a/sound/usb/card.c
17567 +++ b/sound/usb/card.c
17568 @@ -863,8 +863,14 @@ static int usb_audio_probe(struct usb_in
17569 if (ignore_ctl_error)
17570 chip->quirk_flags |= QUIRK_FLAG_IGNORE_CTL_ERROR;
17571
17572 - if (chip->quirk_flags & QUIRK_FLAG_DISABLE_AUTOSUSPEND)
17573 + if (chip->quirk_flags & QUIRK_FLAG_DISABLE_AUTOSUSPEND) {
17574 + /*
17575 + * Grab the interface, because on a webcam uvcvideo may race
17576 + * with snd-usb-audio during probe and re-enable autosuspend.
17577 + */
17578 + usb_autopm_get_interface(intf);
17579 usb_disable_autosuspend(interface_to_usbdev(intf));
17580 + }
17581
17582 /*
17583 * For devices with more than one control interface, we assume the
17584 --- a/sound/usb/quirks.c
17585 +++ b/sound/usb/quirks.c
17586 @@ -2195,6 +2195,8 @@ static const struct usb_audio_quirk_flag
17587 QUIRK_FLAG_ALIGN_TRANSFER),
17588 DEVICE_FLG(0x534d, 0x2109, /* MacroSilicon MS2109 */
17589 QUIRK_FLAG_ALIGN_TRANSFER),
17590 + DEVICE_FLG(0x09da, 0x2695, /* A4Tech FHD 1080p webcam */
17591 + QUIRK_FLAG_DISABLE_AUTOSUSPEND | QUIRK_FLAG_GET_SAMPLE_RATE),
17592
17593 /* Vendor matches */
17594 VENDOR_FLG(0x045e, /* MS Lifecam */