e384710da135083147bde72df735d8fac137169b
[openwrt/staging/pepe2k.git] /
1 From c30c73263981026201fc45fcc54d6e58d061b61e Mon Sep 17 00:00:00 2001
2 From: Florian Meier <florian.meier@koalo.de>
3 Date: Mon, 25 Jan 2016 15:48:59 +0000
4 Subject: [PATCH] Add support for all the downstream rpi sound card
5 drivers
6 MIME-Version: 1.0
7 Content-Type: text/plain; charset=UTF-8
8 Content-Transfer-Encoding: 8bit
9
10 ASoC: Add support for Rpi-DAC
11
12 ASoC: Add prompt for ICS43432 codec
13
14 Without a prompt string, a config setting can't be included in a
15 defconfig. Give CONFIG_SND_SOC_ICS43432 a prompt so that Pi soundcards
16 can use the driver.
17
18 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
19
20 Add IQaudIO Sound Card support for Raspberry Pi
21
22 Set a limit of 0dB on Digital Volume Control
23
24 The main volume control in the PCM512x DAC has a range up to
25 +24dB. This is dangerously loud and can potentially cause massive
26 clipping in the output stages. Therefore this sets a sensible
27 limit of 0dB for this control.
28
29 Allow up to 24dB digital gain to be applied when using IQAudIO DAC+
30
31 24db_digital_gain DT param can be used to specify that PCM512x
32 codec "Digital" volume control should not be limited to 0dB gain,
33 and if specified will allow the full 24dB gain.
34
35 Modify IQAudIO DAC+ ASoC driver to set card/dai config from dt
36
37 Add the ability to set the card name, dai name and dai stream name, from
38 dt config.
39
40 Signed-off-by: DigitalDreamtime <clive.messer@digitaldreamtime.co.uk>
41
42 IQaudIO: auto-mute for AMP+ and DigiAMP+
43
44 IQAudIO amplifier mute via GPIO22. Add dt params for "one-shot" unmute
45 and auto mute.
46
47 Revision 2, auto mute implementing HiassofT suggestion to mute/unmute
48 using set_bias_level, rather than startup/shutdown....
49 "By default DAPM waits 5 seconds (pmdown_time) before shutting down
50 playback streams so a close/stop immediately followed by open/start
51 doesn't trigger an amp mute+unmute."
52
53 Tested on both AMP+ (via DAC+) and DigiAMP+, with both options...
54
55 dtoverlay=iqaudio-dacplus,unmute_amp
56 "one-shot" unmute when kernel module loads.
57
58 dtoverlay=iqaudio-dacplus,auto_mute_amp
59 Unmute amp when ALSA device opened by a client. Mute, with 5 second delay
60 when ALSA device closed. (Re-opening the device within the 5 second close
61 window, will cancel mute.)
62
63 Revision 4, using gpiod.
64
65 Revision 5, clean-up formatting before adding mute code.
66 - Convert tab plus 4 space formatting to 2x tab
67 - Remove '// NOT USED' commented code
68
69 Revision 6, don't attempt to "one-shot" unmute amp, unless card is
70 successfully registered.
71
72 Signed-off-by: DigitalDreamtime <clive.messer@digitaldreamtime.co.uk>
73
74 ASoC: iqaudio-dac: fix S24_LE format
75
76 Remove set_bclk_ratio call so 24-bit data is transmitted in
77 24 bclk cycles.
78
79 Signed-off-by: Matthias Reichl <hias@horus.com>
80
81 ASoC: iqaudio-dac: use modern dai_link style
82
83 Signed-off-by: Matthias Reichl <hias@horus.com>
84
85 Added support for HiFiBerry DAC+
86
87 The driver is based on the HiFiBerry DAC driver. However HiFiBerry DAC+ uses
88 a different codec chip (PCM5122), therefore a new driver is necessary.
89
90 Add support for the HiFiBerry DAC+ Pro.
91
92 The HiFiBerry DAC+ and DAC+ Pro products both use the existing bcm sound driver with the DAC+ Pro having a special clock device driver representing the two high precision oscillators.
93
94 An addition bug fix is included for the PCM512x codec where by the physical size of the sample frame is used in the calculation of the LRCK divisor as it was found to be wrong when using 24-bit depth sample contained in a little endian 4-byte sample frame.
95
96 Limit PCM512x "Digital" gain to 0dB by default with HiFiBerry DAC+
97
98 24db_digital_gain DT param can be used to specify that PCM512x
99 codec "Digital" volume control should not be limited to 0dB gain,
100 and if specified will allow the full 24dB gain.
101
102 Add dt param to force HiFiBerry DAC+ Pro into slave mode
103
104 "dtoverlay=hifiberry-dacplus,slave"
105
106 Add 'slave' param to use HiFiBerry DAC+ Pro in slave mode,
107 with Pi as master for bit and frame clock.
108
109 Signed-off-by: DigitalDreamtime <clive.messer@digitaldreamtime.co.uk>
110
111 Fixed a bug when using 352.8kHz sample rate
112
113 Signed-off-by: Daniel Matuschek <daniel@hifiberry.com>
114
115 ASoC: pcm512x: revert downstream changes
116
117 This partially reverts commit 185ea05465aac8bf02a0d2b2f4289d42c72870b7
118 which was added by https://github.com/raspberrypi/linux/pull/1152
119
120 The downstream pcm512x changes caused a regression, it broke normal
121 use of the 24bit format with the codec, eg when using simple-audio-card.
122
123 The actual bug with 24bit playback is the incorrect usage
124 of physical_width in various drivers in the downstream tree
125 which causes 24bit data to be transmitted with 32 clock
126 cycles. So it's not the pcm512x that needs fixing, it's the
127 soundcard drivers.
128
129 Signed-off-by: Matthias Reichl <hias@horus.com>
130
131 ASoC: hifiberry_dacplus: fix S24_LE format
132
133 Remove set_bclk_ratio call so 24-bit data is transmitted in
134 24 bclk cycles.
135
136 Signed-off-by: Matthias Reichl <hias@horus.com>
137
138 ASoC: hifiberry_dacplus: transmit S24_LE with 64 BCLK cycles
139
140 Signed-off-by: Matthias Reichl <hias@horus.com>
141
142 hifiberry_dacplus: switch to snd_soc_dai_set_bclk_ratio
143
144 Signed-off-by: Matthias Reichl <hias@horus.com>
145
146 ASoC: hifiberry_dacplus: use modern dai_link style
147
148 Signed-off-by: Hui Wang <hui.wang@canonical.com>
149
150 Add driver for rpi-proto
151
152 Forward port of 3.10.x driver from https://github.com/koalo
153 We are using a custom board and would like to use rpi 3.18.x
154 kernel. Patch works fine for our embedded system.
155
156 URL to the audio chip:
157 http://www.mikroe.com/add-on-boards/audio-voice/audio-codec-proto/
158
159 Playback tested with devicetree enabled.
160
161 Signed-off-by: Waldemar Brodkorb <wbrodkorb@conet.de>
162
163 ASoC: rpi-proto: use modern dai_link style
164
165 Signed-off-by: Hui Wang <hui.wang@canonical.com>
166
167 Add Support for JustBoom Audio boards
168
169 justboom-dac: Adjust for ALSA API change
170
171 As of 4.4, snd_soc_limit_volume now takes a struct snd_soc_card *
172 rather than a struct snd_soc_codec *.
173
174 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
175
176 ASoC: justboom-dac: fix S24_LE format
177
178 Remove set_bclk_ratio call so 24-bit data is transmitted in
179 24 bclk cycles.
180
181 Also remove hw_params as it's no longer needed.
182
183 Signed-off-by: Matthias Reichl <hias@horus.com>
184
185 ASoC: justboom-dac: use modern dai_link style
186
187 Signed-off-by: Matthias Reichl <hias@horus.com>
188
189 New AudioInjector.net Pi soundcard with low jitter audio in and out.
190
191 Contains the sound/soc/bcm ALSA machine driver and necessary alterations to the Kconfig and Makefile.
192 Adds the dts overlay and updates the Makefile and README.
193 Updates the relevant defconfig files to enable building for the Raspberry Pi.
194 Thanks to Phil Elwell (pelwell) for the review, simple-card concepts and discussion. Thanks to Clive Messer for overlay naming suggestions.
195
196 Added support for headphones, microphone and bclk_ratio settings.
197
198 This patch adds headphone and microphone capability to the Audio Injector sound card. The patch also sets the bit clock ratio for use in the bcm2835-i2s driver. The bcm2835-i2s can't handle an 8 kHz sample rate when the bit clock is at 12 MHz because its register is only 10 bits wide which can't represent the ch2 offset of 1508. For that reason, the rate constraint is added.
199
200 ASoC: audioinjector-pi-soundcard: use modern dai_link style
201
202 Signed-off-by: Hui Wang <hui.wang@canonical.com>
203
204 New driver for RRA DigiDAC1 soundcard using WM8741 + WM8804
205
206 ASoC: digidac1-soundcard: use modern dai_link style
207
208 Signed-off-by: Hui Wang <hui.wang@canonical.com>
209
210 Add support for Dion Audio LOCO DAC-AMP HAT
211
212 Using dedicated machine driver and pcm5102a codec driver.
213
214 Signed-off-by: DigitalDreamtime <clive.messer@digitaldreamtime.co.uk>
215
216 ASoC: dionaudio_loco: use modern dai_link style
217
218 Signed-off-by: Hui Wang <hui.wang@canonical.com>
219
220 Allo Piano DAC boards: Initial 2 channel (stereo) support (#1645)
221
222 Add initial 2 channel (stereo) support for Allo Piano DAC (2.0/2.1) boards,
223 using allo-piano-dac-pcm512x-audio overlay and allo-piano-dac ALSA ASoC
224 machine driver.
225
226 NB. The initial support is 2 channel (stereo) ONLY!
227 (The Piano DAC 2.1 will only support 2 channel (stereo) left/right output,
228 pending an update to the upstream pcm512x codec driver, which will have
229 to be submitted via upstream. With the initial downstream support,
230 provided by this patch, the Piano DAC 2.1 subwoofer outputs will
231 not function.)
232
233 Signed-off-by: Baswaraj K <jaikumar@cem-solutions.net>
234 Signed-off-by: Clive Messer <clive.messer@digitaldreamtime.co.uk>
235 Tested-by: Clive Messer <clive.messer@digitaldreamtime.co.uk>
236
237 ASoC: allo-piano-dac: fix S24_LE format
238
239 Remove set_bclk_ratio call so 24-bit data is transmitted in
240 24 bclk cycles.
241
242 Also remove hw_params and ops as they are no longer needed.
243
244 Signed-off-by: Matthias Reichl <hias@horus.com>
245
246 ASoC: allo-piano-dac: use modern dai_link style
247
248 Signed-off-by: Hui Wang <hui.wang@canonical.com>
249
250 Add support for Allo Piano DAC 2.1 plus add-on board for Raspberry Pi.
251
252 The Piano DAC 2.1 has support for 4 channels with subwoofer.
253
254 Signed-off-by: Baswaraj K <jaikumar@cem-solutions.net>
255 Reviewed-by: Vijay Kumar B. <vijaykumar@zilogic.com>
256 Reviewed-by: Raashid Muhammed <raashidmuhammed@zilogic.com>
257
258 Add clock changes and mute gpios (#1938)
259
260 Also improve code style and adhere to ALSA coding conventions.
261
262 Signed-off-by: Baswaraj K <jaikumar@cem-solutions.net>
263 Reviewed-by: Vijay Kumar B. <vijaykumar@zilogic.com>
264 Reviewed-by: Raashid Muhammed <raashidmuhammed@zilogic.com>
265
266 PianoPlus: Dual Mono & Dual Stereo features added (#2069)
267
268 allo-piano-dac-plus: Master volume added + fixes
269
270 Master volume added, which controls both DACs volumes.
271
272 See: https://github.com/raspberrypi/linux/pull/2149
273
274 Also fix initial max volume, default mode value, and unmute.
275
276 Signed-off-by: allocom <sparky-dev@allo.com>
277
278 ASoC: allo-piano-dac-plus: fix S24_LE format
279
280 Remove set_bclk_ratio call so 24-bit data is transmitted in
281 24 bclk cycles.
282
283 Signed-off-by: Matthias Reichl <hias@horus.com>
284
285 sound: bcm: Fix memset dereference warning
286
287 This warning appears with GCC 6.4.0 from toolchains.bootlin.com:
288
289 ../sound/soc/bcm/allo-piano-dac-plus.c: In function ‘snd_allo_piano_dac_init’:
290 ../sound/soc/bcm/allo-piano-dac-plus.c:711:30: warning: argument to ‘sizeof’ in ‘memset’ call is the same expression as the destination; did you mean to dereference it? [-Wsizeof-pointer-memaccess]
291 memset(glb_ptr, 0x00, sizeof(glb_ptr));
292 ^
293
294 Suggested-by: Phil Elwell <phil@raspberrypi.org>
295 Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
296
297 ASoC: allo-piano-dac-plus: use modern dai_link style
298
299 Signed-off-by: Hui Wang <hui.wang@canonical.com>
300
301 Add support for Allo Boss DAC add-on board for Raspberry Pi. (#1924)
302
303 Signed-off-by: Baswaraj K <jaikumar@cem-solutions.net>
304 Reviewed-by: Deepak <deepak@zilogic.com>
305 Reviewed-by: BabuSubashChandar <babusubashchandar@zilogic.com>
306
307 Add support for new clock rate and mute gpios.
308
309 Signed-off-by: Baswaraj K <jaikumar@cem-solutions.net>
310 Reviewed-by: Deepak <deepak@zilogic.com>
311 Reviewed-by: BabuSubashChandar <babusubashchandar@zilogic.com>
312
313 ASoC: allo-boss-dac: fix S24_LE format
314
315 Remove set_bclk_ratio call so 24-bit data is transmitted in
316 24 bclk cycles.
317
318 Signed-off-by: Matthias Reichl <hias@horus.com>
319
320 ASoC: allo-boss-dac: transmit S24_LE with 64 BCLK cycles
321
322 Signed-off-by: Matthias Reichl <hias@horus.com>
323
324 allo-boss-dac: switch to snd_soc_dai_set_bclk_ratio
325
326 Signed-off-by: Matthias Reichl <hias@horus.com>
327
328 ASoC: allo-boss-dac: use modern dai_link style
329
330 Signed-off-by: Hui Wang <hui.wang@canonical.com>
331
332 Support for Blokas Labs pisound board
333
334 Pisound dynamic overlay (#1760)
335
336 Restructuring pisound-overlay.dts, so it can be loaded and unloaded dynamically using dtoverlay.
337
338 Print a logline when the kernel module is removed.
339
340 pisound improvements:
341
342 * Added a writable sysfs object to enable scripts / user space software
343 to blink MIDI activity LEDs for variable duration.
344 * Improved hw_param constraints setting.
345 * Added compatibility with S16_LE sample format.
346 * Exposed some simple placeholder volume controls, so the card appears
347 in volumealsa widget.
348
349 Add missing SND_PISOUND selects dependency to SND_RAWMIDI
350
351 Without it the Pisound module fails to compile.
352 See https://github.com/raspberrypi/linux/issues/2366
353
354 Updates for Pisound module code:
355
356 * Merged 'Fix a warning in DEBUG builds' (1c8b82b).
357 * Updating some strings and copyright information.
358 * Fix for handling high load of MIDI input and output.
359 * Use dual rate oversampling ratio for 96kHz instead of single
360 rate one.
361
362 Signed-off-by: Giedrius Trainavicius <giedrius@blokas.io>
363
364 Fixing memset call in pisound.c
365
366 Signed-off-by: Giedrius Trainavicius <giedrius@blokas.io>
367
368 Fix for Pisound's MIDI Input getting blocked for a while in rare cases.
369
370 There was a possible race condition which could lead to Input's FIFO queue
371 to be underflown, causing high amount of processing in the worker thread for
372 some period of time.
373
374 Signed-off-by: Giedrius Trainavicius <giedrius@blokas.io>
375
376 Fix for Pisound kernel module in Real Time kernel configuration.
377
378 When handler of data_available interrupt is fired, queue_work ends up
379 getting called and it can block on a spin lock which is not allowed in
380 interrupt context. The fix was to run the handler from a thread context
381 instead.
382
383 Pisound: Remove spinlock usage around spi_sync
384
385 ASoC: pisound: use modern dai_link style
386
387 Signed-off-by: Hui Wang <hui.wang@canonical.com>
388
389 ASoC: pisound: fix the parameter for spi_device_match
390
391 Signed-off-by: Hui Wang <hui.wang@canonical.com>
392
393 ASoC: Add driver for Cirrus Logic Audio Card
394
395 Note: due to problems with deferred probing of regulators
396 the following softdep should be added to a modprobe.d file
397
398 softdep arizona-spi pre: arizona-ldo1
399
400 Signed-off-by: Matthias Reichl <hias@horus.com>
401
402 ASoC: rpi-cirrus: use modern dai_link style
403
404 Signed-off-by: Matthias Reichl <hias@horus.com>
405
406 sound: Support for Dion Audio LOCO-V2 DAC-AMP HAT
407
408 Signed-off-by: Miquel Blauw <info@dionaudio.nl>
409
410 ASoC: dionaudio_loco-v2: fix S24_LE format
411
412 Remove set_bclk_ratio call so 24-bit data is transmitted in
413 24 bclk cycles.
414
415 Also remove hw_params and ops as they are no longer needed.
416
417 Signed-off-by: Matthias Reichl <hias@horus.com>
418
419 ASoC: dionaudio_loco-v2: use modern dai_link style
420
421 Signed-off-by: Hui Wang <hui.wang@canonical.com>
422
423 Add support for Fe-Pi audio sound card. (#1867)
424
425 Fe-Pi Audio Sound Card is based on NXP SGTL5000 codec.
426 Mechanical specification of the board is the same the Raspberry Pi Zero.
427 3.5mm jacks for Headphone/Mic, Line In, and Line Out.
428
429 Signed-off-by: Henry Kupis <fe-pi@cox.net>
430
431 ASoC: fe-pi-audio: use modern dai_link style
432
433 Signed-off-by: Hui Wang <hui.wang@canonical.com>
434
435 Add support for the AudioInjector.net Octo sound card
436
437 AudioInjector Octo: sample rates, regulators, reset
438
439 This patch adds new sample rates to the Audioinjector Octo sound card. The
440 new supported rates are (in kHz) :
441 96, 48, 32, 24, 16, 8, 88.2, 44.1, 29.4, 22.05, 14.7
442
443 Reference the bcm270x DT regulators in the overlay.
444
445 This patch adds a reset GPIO for the AudioInjector.net octo sound card.
446
447 Audioinjector octo : Make the playback and capture symmetric
448
449 This patch ensures that the sample rate and channel count of the audioinjector
450 octo sound card are symmetric.
451
452 audioinjector-octo: Add continuous clock feature
453
454 By user request, add a switch to prevent the clocks being stopped when
455 the stream is paused, stopped or shutdown. Provide access to the switch
456 by adding a 'non-stop-clocks' parameter to the audioinjector-addons
457 overlay.
458
459 See: https://github.com/raspberrypi/linux/issues/2409
460
461 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
462
463 sound: Fixes for audioinjector-octo under 4.19
464
465 1. Move the DT alias declaration to the I2C shim in the cases
466 where the shim is enabled. This works around a problem caused by a
467 4.19 commit [1] that generates DT/OF uevents for I2C drivers.
468
469 2. Fix the diagnostics in an error path of the soundcard driver to
470 correctly identify the reason for the failure to load.
471
472 3. Move the declaration of the clock node in the overlay outside
473 the I2C node to avoid warnings.
474
475 4. Sort the overlay nodes so that dependencies are only to earlier
476 fragments, in an attempt to get runtime dtoverlay application to
477 work (it still doesn't...)
478
479 See: https://github.com/Audio-Injector/Octo/issues/14
480 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
481
482 [1] af503716ac14 ("i2c: core: report OF style module alias for devices registered via OF")
483
484 ASoC: audioinjector-octo-soundcard: use modern dai_link style
485
486 Signed-off-by: Hui Wang <hui.wang@canonical.com>
487
488 Driver support for Google voiceHAT soundcard.
489
490 ASoC: googlevoicehat-codec: Use correct device when grabbing GPIO
491
492 The fixup for the VoiceHAT in 4.18 incorrectly tried to find the
493 sdmode GPIO pin under the card device, not the codec device.
494 This failed, and therefore caused the device probe to fail.
495
496 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
497
498 ASoC: googlevoicehat-codec: Reformat for kernel coding standards
499
500 Fix all whitespace, indentation, and bracing errors.
501
502 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
503
504 ASoC: googlevoicehat-codec: Make driver function structure const
505
506 Make voicehat_component_driver a const structure.
507
508 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
509
510 ASoC: googlevoicehat-codec: Only convert from ms to jiffies once
511
512 Minor optimisation and allows to become checkpatch clean.
513 A msec value is read out of DT or from a define, and convert once to
514 jiffies, rather than every time that it is used.
515
516 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
517
518 Driver and overlay for Allo Katana DAC
519
520 Allo Katana DAC: Updated default values
521
522 Signed-off-by: Jaikumar <jaikumar@cem-solutions.com>
523
524 Added mute stream func
525
526 Signed-off-by: Jaikumar <jaikumar@cem-solutions.net>
527
528 codecs: Correct Katana minimum volume
529
530 Update Katana minimum volume to get the exact 0.5 dB value in each step.
531
532 Signed-off-by: Sudeep Kumar <sudeepkumar@cem-solutions.net>
533
534 ASoC: Add generic RPI driver for simple soundcards.
535
536 The RPI simple sound card driver provides a generic ALSA SOC card driver
537 supporting a variety of Pi HAT soundcards. The intention is to avoid
538 the duplication of code for cards that can't be fully supported by
539 the soc simple/graph cards but are otherwise almost identical.
540
541 This initial commit adds support for the ADAU1977 ADC, Google VoiceHat,
542 HifiBerry AMP, HifiBerry DAC and RPI DAC.
543
544 Signed-off-by: Tim Gover <tim.gover@raspberrypi.org>
545
546 ASoC: Use correct card name in rpi-simple driver
547
548 Use the specific card name from drvdata instead of the snd_rpi_simple
549
550 rpi-simple-soundcard: Use nicer driver name "RPi-simple"
551
552 Rename the driver from "RPI simple soundcard" to "RPi-simple" so that
553 the driver name won't be mangled allowing to be used unaltered as the
554 card conf filename.
555
556 ASoC: rpi-simple-soundcard: use modern dai_link style
557
558 Signed-off-by: Hui Wang <hui.wang@canonical.com>
559
560 ASoC: Add Kconfig and Makefile for sound/soc/bcm
561
562 Signed-off-by: popcornmix <popcornmix@gmail.com>
563
564 ASoC: Create a generic Pi Hat WM8804 driver
565
566 Reduce the amount of duplicated code by creating a generic driver for
567 Pi Hat digi cards using the WM8804 codec.
568
569 This replaces the
570 Allo DigiOne, Hifiberry Digi/Pro, JustBoom Digi and IQAudIO Digi
571 dedicate soundcard drivers with a generic driver.
572
573 There are no significant changes to the runtime behavior of the drivers
574 and end users should not have to change any configuration settings
575 after upgrading.
576
577 Minor changes
578 * Check the return value of snd_soc_component_update_bits
579 * Added some pr_debug tracing
580 * Various checkpatch tidyups
581 * Updated allodigi-one to use use 128FS at > 96 Khz. This appears to
582 be an omission in the original driver code so followed the Hifiberry
583 DAC driver approach.
584
585 ASoC: rpi-wm8804-soundcard: use modern dai_link style
586
587 Signed-off-by: Matthias Reichl <hias@horus.com>
588
589 rpi-wm8804-soundcard: drop PWRDN register writes
590
591 Since kernel 4.0 the PWRDN register bits are under DAPM
592 control from the wm8804 driver.
593
594 Drop code that modifies that register to avoid interfering
595 with DAPM.
596
597 Signed-off-by: Matthias Reichl <hias@horus.com>
598
599 rpi-wm8804-soundcard: configure wm8804 clocks only on rate change
600
601 This should avoid clicks when stopping and immediately afterwards
602 starting a stream with the same samplerate as before.
603
604 Signed-off-by: Matthias Reichl <hias@horus.com>
605
606 rpi-wm8804-soundcard: Fixed MCLKDIV for Allo Digione
607
608 The Allo Digione board wants a fixed MCLKDIV of 256.
609
610 See: https://github.com/raspberrypi/linux/issues/3296
611
612 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
613
614 ASoC: Add support for AudioSense-Pi add-on soundcard
615
616 AudioSense-Pi is a RPi HAT based on a TI's TLV320AIC32x4 stereo codec
617
618 This hardware provides multiple audio I/O capabilities to the RPi.
619 The codec connects to the RPi's SoC through the I2S Bus.
620
621 The following devices can be connected through a 3.5mm jack
622 1. Line-In: Plain old audio in from mobile phones, PCs, etc.,
623 2. Mic-In: Connect a microphone
624 3. Line-Out: Connect the output to a speaker
625 4. Headphones: Connect a Headphone w or w/o microphones
626
627 Multiple Inputs:
628 It supports the following combinations
629 1. Two stereo Line-Inputs and a microphone
630 2. One stereo Line-Input and two microphones
631 3. Two stereo Line-Inputs, a microphone and
632 one mono line-input (with h/w hack)
633 4. One stereo Line-Input, two microphones and
634 one mono line-input (with h/w hack)
635
636 Multiple Outputs:
637 Audio output can be routed to the headphones or
638 speakers (with additional hardware)
639
640 Signed-off-by: b-ak <anur.bhargav@gmail.com>
641
642 ASoC: audiosense-pi: use modern dai_link style
643
644 Signed-off-by: Hui Wang <hui.wang@canonical.com>
645
646 Added driver for the HiFiBerry DAC+ ADC (#2694)
647
648 Signed-off-by: Daniel Matuschek <daniel@hifiberry.com>
649
650 hifiberry_dacplusadc: switch to snd_soc_dai_set_bclk_ratio
651
652 Signed-off-by: Matthias Reichl <hias@horus.com>
653
654 ASoC: hifiberry_dacplusadc: fix DAI link setup
655
656 The driver only defines a single DAI link and the code that tries
657 to setup the second (non-existent) DAI link looks wrong - using dmic
658 as a CPU/platform driver doesn't make any sense.
659
660 The DT overlay doesn't define a dmic property, so the code was never
661 executed (otherwise it would have resulted in a memory corruption).
662
663 So drop the offending code to prevent issues if a dmic property
664 should be added to the DT overlay.
665
666 Signed-off-by: Matthias Reichl <hias@horus.com>
667
668 ASoC: hifiberry_dacplusadc: use modern dai_link style
669
670 Signed-off-by: Matthias Reichl <hias@horus.com>
671
672 Audiophonics I-Sabre 9038Q2M DAC driver
673
674 Signed-off-by: Audiophonics <contact@audiophonics.fr>
675
676 ASoC: i-sabre-q2m: use modern dai_link style
677
678 Signed-off-by: Hui Wang <hui.wang@canonical.com>
679
680 Added IQaudIO Pi-Codec board support (#2969)
681
682 Add support for the IQaudIO Pi-Codec board.
683
684 Signed-off-by: Gordon <gordon@iqaudio.com>
685
686 Fixed 48k timing issue
687
688 ASoC: iqaudio-codec: use modern dai_link style
689
690 Signed-off-by: Hui Wang <hui.wang@canonical.com>
691
692 adds the Hifiberry DAC+ADC PRO version
693
694 This adds the driver for the DAC+ADC PRO version of the Hifiberry soundcard with software controlled PCM1863 ADC
695 Signed-off-by: Joerg Schambacher joerg@i2audio.com
696
697 Add Hifiberry DAC+DSP soundcard driver (#3224)
698
699 Adds the driver for the Hifiberry DAC+DSP. It supports capture and
700 playback depending on the DSP firmware.
701
702 Signed-off-by: Joerg Schambacher <joerg@i2audio.com>
703
704 Allow simultaneous use of JustBoom DAC and Digi
705
706 Signed-off-by: Johannes Krude <johannes@krude.de>
707
708 Pisound: MIDI communication fixes for scaled down CPU.
709
710 * Increased maximum SPI communication speed to avoid running too slow
711 when the CPU is scaled down and losing MIDI data.
712
713 * Keep track of buffer usage in millibytes for higher precision.
714
715 Signed-off-by: Giedrius Trainavičius <giedrius@blokas.io>
716
717 sound: Add the HiFiBerry DAC+HD version
718
719 This adds the driver for the DAC+HD version supporting HiFiBerry's
720 PCM179x based DACs. It also adds PLL control for clock generation.
721
722 Signed-off-by: Joerg Schambacher <joerg@i2audio.com>
723
724 Fix master mode settings of HiFiBerry DAC+ADC PRO card (#3424)
725
726 This patch fixes the board DAI setting when in master-mode.
727 Wrong setting could have caused random pop noise.
728
729 Signed-off-by: Joerg Schambacher <joerg@i2audio.com>
730
731 adds LED OFF feature to HiFiBerry DAC+ADC PRO sound card
732
733 This adds a DT overlay parameter 'leds_off' which allows
734 to switch off the onboard activity LEDs at all times
735 which has been requested by some users.
736
737 Signed-off-by: Joerg Schambacher <joerg@i2audio.com>
738
739 adds LED OFF feature to HiFiBerry DAC+ADC sound card
740
741 This adds a DT overlay parameter 'leds_off' which allows
742 to switch off the onboard activity LEDs at all times
743 which has been requested by some users.
744
745 Signed-off-by: Joerg Schambacher <joerg@i2audio.com>
746
747 adds LED OFF feature to HiFiBerry DAC+/DAC+PRO sound cards
748
749 This adds a DT overlay parameter 'leds_off' which allows
750 to switch off the onboard activity LEDs at all times
751 which has been requested by some users.
752
753 Signed-off-by: Joerg Schambacher <joerg@i2audio.com>
754
755 pisound: Added reading Pisound board hardware revision and exposing it (#3425)
756
757 pisound: Added reading Pisound board hardware revision and exposing it in kernel log and sysfs file:
758
759 /sys/kernel/pisound/hw_version
760
761 Signed-off-by: Giedrius <giedrius@blokas.io>
762
763 Added driver for HiFiBerry Amp amplifier add-on board
764
765 The driver contains a low-level hardware driver for the TAS5713 and the
766 drivers for the Raspberry Pi I2S subsystem.
767
768 TAS5713: return error if initialisation fails
769
770 Existing TAS5713 driver logs errors during initialisation, but does not return
771 an error code. Therefore even if initialisation fails, the driver will still be
772 loaded, but won't work. This patch fixes this. I2C communication error will now
773 reported correctly by a non-zero return code.
774
775 HiFiBerry Amp: fix device-tree problems
776
777 Some code to load the driver based on device-tree-overlays was missing. This is added by this patch.
778
779 According to 5713 pdf doc CLOCK_CTRL is a readonly status register, and it behaves so. Remove useless setting
780
781 sound: pcm512x-codec: Adding 352.8kHz samplerate support
782
783 sound/soc: only first codec is master in multicodec setup
784
785 When using multiple codecs, at most one codec should generate the master
786 clock. All codecs except the first are therefore configured for slave
787 mode.
788
789 Signed-off-by: Johannes Krude <johannes@krude.de>
790
791 ASoC: Fix snd_soc_get_pcm_runtime usage
792
793 Commit [1] changed the snd_soc_get_pcm_runtime to take a dai_link
794 pointer instead of a string. Patch up the downstream drivers to use
795 the modified API.
796
797 Signed-off-by: Phil Elwell <phil@raspberrypi.com>
798
799 [1] 4468189ff307 ("ASoC: soc-core: find rtd via dai_link pointer at snd_soc_get_pcm_runtime()")
800
801 Add support for the AudioInjector.net Isolated sound card
802
803 This patch adds support for the Audio Injector Isolated sound card.
804
805 Signed-off-by: Matt Flax <flatmax@flatmax.org>
806
807 Add support for merus-amp soundcard and ma120x0p codec
808
809 Add 96KHz rate support to MA120X0P codec and make enable and mute gpio
810 pins optional.
811
812 Signed-off-by: AMuszkat <ariel.muszkat@gmail.com>
813
814 Fixes a problem with clock settings of HiFiBerry DAC+ADC PRO (#3545)
815
816 This patch fixes a problem of the re-calculation of
817 i2s-clock and -parameter settings when only the ADC is activated.
818
819 Signed-off-by: Joerg Schambacher <joerg@i2audio.com>
820
821 configs: Enable the AD193x codecs
822
823 See: https://github.com/raspberrypi/linux/issues/2850
824
825 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
826
827 Switch to snd_soc_dai_set_bclk_ratio
828 Replaces obsolete function snd_soc_dai_set_tdm_slot
829
830 Signed-off-by: Joerg Schambacher <joerg@i2audio.com>
831
832 Enhances the DAC+ driver to control the optional headphone amplifier
833
834 Probes on the I2C bus for TPA6130A2, if successful, it sets DT-parameter
835 'status' from 'disabled' to 'okay' using change_sets to enable
836 the headphone control.
837
838 Signed-off-by: Joerg Schambacher joerg@i2audio.com
839
840 Update Allo Piano Dac Driver
841
842 Add unique names to the individual dac coded drivers
843 Remove some of the codec controls that are not used.
844
845 Signed-off-by: Paul Hermann <paul@picoreplayer.org>
846
847 Fixes an onboard clock detection problem of the PRO versions
848
849 Increasing the sleep time after clock selection to 3-4ms
850 allows the correct detection of all combinations of DAC+ Pro
851 and DAC+ADC Pro sound cards and the various PI revisions.
852
853 Signed-off-by: Joerg Schambacher <joerg@hifiberry.com>
854
855 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 .../devicetree/bindings/vendor-prefixes.txt | 463 ++++++
939 .../devicetree/bindings/vendor-prefixes.yaml | 2 +
940 drivers/clk/Kconfig | 6 +
941 drivers/clk/Makefile | 3 +
942 drivers/clk/clk-allo-dac.c | 161 ++
943 drivers/clk/clk-hifiberry-dachd.c | 332 ++++
944 drivers/clk/clk-hifiberry-dacpro.c | 160 ++
945 sound/soc/bcm/Kconfig | 305 ++++
946 sound/soc/bcm/Makefile | 71 +-
947 sound/soc/bcm/allo-boss-dac.c | 457 ++++++
948 sound/soc/bcm/allo-boss2-dac.c | 1131 ++++++++++++++
949 sound/soc/bcm/allo-katana-codec.c | 387 +++++
950 sound/soc/bcm/allo-piano-dac-plus.c | 1064 +++++++++++++
951 sound/soc/bcm/allo-piano-dac.c | 122 ++
952 .../bcm/audioinjector-isolated-soundcard.c | 183 +++
953 sound/soc/bcm/audioinjector-octo-soundcard.c | 346 +++++
954 sound/soc/bcm/audioinjector-pi-soundcard.c | 189 +++
955 sound/soc/bcm/audiosense-pi.c | 248 +++
956 sound/soc/bcm/chipdip-dac.c | 275 ++++
957 sound/soc/bcm/dacberry400.c | 259 ++++
958 sound/soc/bcm/digidac1-soundcard.c | 421 +++++
959 sound/soc/bcm/dionaudio_loco-v2.c | 117 ++
960 sound/soc/bcm/dionaudio_loco.c | 117 ++
961 sound/soc/bcm/fe-pi-audio.c | 154 ++
962 sound/soc/bcm/googlevoicehat-codec.c | 214 +++
963 sound/soc/bcm/hifiberry_dacplus.c | 527 +++++++
964 sound/soc/bcm/hifiberry_dacplusadc.c | 398 +++++
965 sound/soc/bcm/hifiberry_dacplusadcpro.c | 605 ++++++++
966 sound/soc/bcm/hifiberry_dacplusdsp.c | 90 ++
967 sound/soc/bcm/hifiberry_dacplushd.c | 238 +++
968 sound/soc/bcm/i-sabre-q2m.c | 159 ++
969 sound/soc/bcm/iqaudio-codec.c | 275 ++++
970 sound/soc/bcm/iqaudio-dac.c | 224 +++
971 sound/soc/bcm/justboom-both.c | 267 ++++
972 sound/soc/bcm/justboom-dac.c | 147 ++
973 sound/soc/bcm/pifi-40.c | 284 ++++
974 sound/soc/bcm/pisound.c | 1241 +++++++++++++++
975 sound/soc/bcm/rpi-cirrus.c | 1025 ++++++++++++
976 sound/soc/bcm/rpi-proto.c | 147 ++
977 sound/soc/bcm/rpi-simple-soundcard.c | 487 ++++++
978 sound/soc/bcm/rpi-wm8804-soundcard.c | 410 +++++
979 sound/soc/codecs/Kconfig | 26 +-
980 sound/soc/codecs/Makefile | 8 +
981 sound/soc/codecs/cs42xx8-i2c.c | 9 +-
982 sound/soc/codecs/cs42xx8.c | 2 +
983 sound/soc/codecs/i-sabre-codec.c | 390 +++++
984 sound/soc/codecs/i-sabre-codec.h | 42 +
985 sound/soc/codecs/ma120x0p.c | 1381 +++++++++++++++++
986 sound/soc/codecs/pcm1794a.c | 69 +
987 sound/soc/codecs/pcm512x.c | 2 +-
988 sound/soc/codecs/tas5713.c | 361 +++++
989 sound/soc/codecs/tas5713.h | 210 +++
990 sound/soc/soc-core.c | 10 +-
991 sound/usb/card.c | 8 +-
992 sound/usb/quirks.c | 2 +
993 55 files changed, 16224 insertions(+), 7 deletions(-)
994 create mode 100644 Documentation/devicetree/bindings/vendor-prefixes.txt
995 create mode 100644 drivers/clk/clk-allo-dac.c
996 create mode 100644 drivers/clk/clk-hifiberry-dachd.c
997 create mode 100644 drivers/clk/clk-hifiberry-dacpro.c
998 create mode 100644 sound/soc/bcm/allo-boss-dac.c
999 create mode 100644 sound/soc/bcm/allo-boss2-dac.c
1000 create mode 100644 sound/soc/bcm/allo-katana-codec.c
1001 create mode 100644 sound/soc/bcm/allo-piano-dac-plus.c
1002 create mode 100644 sound/soc/bcm/allo-piano-dac.c
1003 create mode 100644 sound/soc/bcm/audioinjector-isolated-soundcard.c
1004 create mode 100644 sound/soc/bcm/audioinjector-octo-soundcard.c
1005 create mode 100644 sound/soc/bcm/audioinjector-pi-soundcard.c
1006 create mode 100644 sound/soc/bcm/audiosense-pi.c
1007 create mode 100644 sound/soc/bcm/chipdip-dac.c
1008 create mode 100644 sound/soc/bcm/dacberry400.c
1009 create mode 100644 sound/soc/bcm/digidac1-soundcard.c
1010 create mode 100644 sound/soc/bcm/dionaudio_loco-v2.c
1011 create mode 100644 sound/soc/bcm/dionaudio_loco.c
1012 create mode 100644 sound/soc/bcm/fe-pi-audio.c
1013 create mode 100644 sound/soc/bcm/googlevoicehat-codec.c
1014 create mode 100644 sound/soc/bcm/hifiberry_dacplus.c
1015 create mode 100644 sound/soc/bcm/hifiberry_dacplusadc.c
1016 create mode 100644 sound/soc/bcm/hifiberry_dacplusadcpro.c
1017 create mode 100644 sound/soc/bcm/hifiberry_dacplusdsp.c
1018 create mode 100644 sound/soc/bcm/hifiberry_dacplushd.c
1019 create mode 100644 sound/soc/bcm/i-sabre-q2m.c
1020 create mode 100644 sound/soc/bcm/iqaudio-codec.c
1021 create mode 100644 sound/soc/bcm/iqaudio-dac.c
1022 create mode 100644 sound/soc/bcm/justboom-both.c
1023 create mode 100644 sound/soc/bcm/justboom-dac.c
1024 create mode 100644 sound/soc/bcm/pifi-40.c
1025 create mode 100644 sound/soc/bcm/pisound.c
1026 create mode 100644 sound/soc/bcm/rpi-cirrus.c
1027 create mode 100644 sound/soc/bcm/rpi-proto.c
1028 create mode 100644 sound/soc/bcm/rpi-simple-soundcard.c
1029 create mode 100644 sound/soc/bcm/rpi-wm8804-soundcard.c
1030 create mode 100644 sound/soc/codecs/i-sabre-codec.c
1031 create mode 100644 sound/soc/codecs/i-sabre-codec.h
1032 create mode 100644 sound/soc/codecs/ma120x0p.c
1033 create mode 100644 sound/soc/codecs/pcm1794a.c
1034 create mode 100644 sound/soc/codecs/tas5713.c
1035 create mode 100644 sound/soc/codecs/tas5713.h
1036
1037 --- /dev/null
1038 +++ b/Documentation/devicetree/bindings/vendor-prefixes.txt
1039 @@ -0,0 +1,463 @@
1040 +Device tree binding vendor prefix registry. Keep list in alphabetical order.
1041 +
1042 +This isn't an exhaustive list, but you should add new prefixes to it before
1043 +using them to avoid name-space collisions.
1044 +
1045 +abilis Abilis Systems
1046 +abracon Abracon Corporation
1047 +actions Actions Semiconductor Co., Ltd.
1048 +active-semi Active-Semi International Inc
1049 +ad Avionic Design GmbH
1050 +adafruit Adafruit Industries, LLC
1051 +adapteva Adapteva, Inc.
1052 +adaptrum Adaptrum, Inc.
1053 +adh AD Holdings Plc.
1054 +adi Analog Devices, Inc.
1055 +advantech Advantech Corporation
1056 +aeroflexgaisler Aeroflex Gaisler AB
1057 +al Annapurna Labs
1058 +allo Allo.com
1059 +allwinner Allwinner Technology Co., Ltd.
1060 +alphascale AlphaScale Integrated Circuits Systems, Inc.
1061 +altr Altera Corp.
1062 +amarula Amarula Solutions
1063 +amazon Amazon.com, Inc.
1064 +amcc Applied Micro Circuits Corporation (APM, formally AMCC)
1065 +amd Advanced Micro Devices (AMD), Inc.
1066 +amediatech Shenzhen Amediatech Technology Co., Ltd
1067 +amlogic Amlogic, Inc.
1068 +ampire Ampire Co., Ltd.
1069 +ams AMS AG
1070 +amstaos AMS-Taos Inc.
1071 +analogix Analogix Semiconductor, Inc.
1072 +andestech Andes Technology Corporation
1073 +apm Applied Micro Circuits Corporation (APM)
1074 +aptina Aptina Imaging
1075 +arasan Arasan Chip Systems
1076 +archermind ArcherMind Technology (Nanjing) Co., Ltd.
1077 +arctic Arctic Sand
1078 +aries Aries Embedded GmbH
1079 +arm ARM Ltd.
1080 +armadeus ARMadeus Systems SARL
1081 +arrow Arrow Electronics
1082 +artesyn Artesyn Embedded Technologies Inc.
1083 +asahi-kasei Asahi Kasei Corp.
1084 +aspeed ASPEED Technology Inc.
1085 +asus AsusTek Computer Inc.
1086 +atlas Atlas Scientific LLC
1087 +atmel Atmel Corporation
1088 +auo AU Optronics Corporation
1089 +auvidea Auvidea GmbH
1090 +avago Avago Technologies
1091 +avia avia semiconductor
1092 +avic Shanghai AVIC Optoelectronics Co., Ltd.
1093 +avnet Avnet, Inc.
1094 +axentia Axentia Technologies AB
1095 +axis Axis Communications AB
1096 +bananapi BIPAI KEJI LIMITED
1097 +bhf Beckhoff Automation GmbH & Co. KG
1098 +bitmain Bitmain Technologies
1099 +blokaslabs Vilniaus Blokas UAB
1100 +boe BOE Technology Group Co., Ltd.
1101 +bosch Bosch Sensortec GmbH
1102 +boundary Boundary Devices Inc.
1103 +brcm Broadcom Corporation
1104 +buffalo Buffalo, Inc.
1105 +bticino Bticino International
1106 +calxeda Calxeda
1107 +capella Capella Microsystems, Inc
1108 +cascoda Cascoda, Ltd.
1109 +catalyst Catalyst Semiconductor, Inc.
1110 +cavium Cavium, Inc.
1111 +cdns Cadence Design Systems Inc.
1112 +cdtech CDTech(H.K.) Electronics Limited
1113 +ceva Ceva, Inc.
1114 +chipidea Chipidea, Inc
1115 +chipone ChipOne
1116 +chipspark ChipSPARK
1117 +chrp Common Hardware Reference Platform
1118 +chunghwa Chunghwa Picture Tubes Ltd.
1119 +ciaa Computadora Industrial Abierta Argentina
1120 +cirrus Cirrus Logic, Inc.
1121 +cloudengines Cloud Engines, Inc.
1122 +cnm Chips&Media, Inc.
1123 +cnxt Conexant Systems, Inc.
1124 +compulab CompuLab Ltd.
1125 +cortina Cortina Systems, Inc.
1126 +cosmic Cosmic Circuits
1127 +crane Crane Connectivity Solutions
1128 +creative Creative Technology Ltd
1129 +crystalfontz Crystalfontz America, Inc.
1130 +csky Hangzhou C-SKY Microsystems Co., Ltd
1131 +cubietech Cubietech, Ltd.
1132 +cypress Cypress Semiconductor Corporation
1133 +cznic CZ.NIC, z.s.p.o.
1134 +dallas Maxim Integrated Products (formerly Dallas Semiconductor)
1135 +dataimage DataImage, Inc.
1136 +davicom DAVICOM Semiconductor, Inc.
1137 +delta Delta Electronics, Inc.
1138 +denx Denx Software Engineering
1139 +devantech Devantech, Ltd.
1140 +dh DH electronics GmbH
1141 +digi Digi International Inc.
1142 +digilent Diglent, Inc.
1143 +dioo Dioo Microcircuit Co., Ltd
1144 +dlc DLC Display Co., Ltd.
1145 +dlg Dialog Semiconductor
1146 +dlink D-Link Corporation
1147 +dmo Data Modul AG
1148 +domintech Domintech Co., Ltd.
1149 +dongwoon Dongwoon Anatech
1150 +dptechnics DPTechnics
1151 +dragino Dragino Technology Co., Limited
1152 +ea Embedded Artists AB
1153 +ebs-systart EBS-SYSTART GmbH
1154 +ebv EBV Elektronik
1155 +eckelmann Eckelmann AG
1156 +edt Emerging Display Technologies
1157 +eeti eGalax_eMPIA Technology Inc
1158 +elan Elan Microelectronic Corp.
1159 +elgin Elgin S/A.
1160 +embest Shenzhen Embest Technology Co., Ltd.
1161 +emlid Emlid, Ltd.
1162 +emmicro EM Microelectronic
1163 +emtrion emtrion GmbH
1164 +endless Endless Mobile, Inc.
1165 +energymicro Silicon Laboratories (formerly Energy Micro AS)
1166 +engicam Engicam S.r.l.
1167 +epcos EPCOS AG
1168 +epfl Ecole Polytechnique Fédérale de Lausanne
1169 +epson Seiko Epson Corp.
1170 +est ESTeem Wireless Modems
1171 +ettus NI Ettus Research
1172 +eukrea Eukréa Electromatique
1173 +everest Everest Semiconductor Co. Ltd.
1174 +everspin Everspin Technologies, Inc.
1175 +exar Exar Corporation
1176 +excito Excito
1177 +ezchip EZchip Semiconductor
1178 +facebook Facebook
1179 +fairphone Fairphone B.V.
1180 +faraday Faraday Technology Corporation
1181 +fastrax Fastrax Oy
1182 +fcs Fairchild Semiconductor
1183 +feiyang Shenzhen Fly Young Technology Co.,LTD.
1184 +firefly Firefly
1185 +focaltech FocalTech Systems Co.,Ltd
1186 +friendlyarm Guangzhou FriendlyARM Computer Tech Co., Ltd
1187 +fsl Freescale Semiconductor
1188 +fujitsu Fujitsu Ltd.
1189 +gateworks Gateworks Corporation
1190 +gcw Game Consoles Worldwide
1191 +ge General Electric Company
1192 +geekbuying GeekBuying
1193 +gef GE Fanuc Intelligent Platforms Embedded Systems, Inc.
1194 +GEFanuc GE Fanuc Intelligent Platforms Embedded Systems, Inc.
1195 +geniatech Geniatech, Inc.
1196 +giantec Giantec Semiconductor, Inc.
1197 +giantplus Giantplus Technology Co., Ltd.
1198 +globalscale Globalscale Technologies, Inc.
1199 +globaltop GlobalTop Technology, Inc.
1200 +gmt Global Mixed-mode Technology, Inc.
1201 +goodix Shenzhen Huiding Technology Co., Ltd.
1202 +google Google, Inc.
1203 +grinn Grinn
1204 +grmn Garmin Limited
1205 +gumstix Gumstix, Inc.
1206 +gw Gateworks Corporation
1207 +hannstar HannStar Display Corporation
1208 +haoyu Haoyu Microelectronic Co. Ltd.
1209 +hardkernel Hardkernel Co., Ltd
1210 +hideep HiDeep Inc.
1211 +himax Himax Technologies, Inc.
1212 +hisilicon Hisilicon Limited.
1213 +hit Hitachi Ltd.
1214 +hitex Hitex Development Tools
1215 +holt Holt Integrated Circuits, Inc.
1216 +honeywell Honeywell
1217 +hp Hewlett Packard
1218 +holtek Holtek Semiconductor, Inc.
1219 +hwacom HwaCom Systems Inc.
1220 +i2se I2SE GmbH
1221 +ibm International Business Machines (IBM)
1222 +icplus IC Plus Corp.
1223 +idt Integrated Device Technologies, Inc.
1224 +ifi Ingenieurburo Fur Ic-Technologie (I/F/I)
1225 +ilitek ILI Technology Corporation (ILITEK)
1226 +img Imagination Technologies Ltd.
1227 +infineon Infineon Technologies
1228 +inforce Inforce Computing
1229 +ingenic Ingenic Semiconductor
1230 +innolux Innolux Corporation
1231 +inside-secure INSIDE Secure
1232 +intel Intel Corporation
1233 +intercontrol Inter Control Group
1234 +invensense InvenSense Inc.
1235 +inversepath Inverse Path
1236 +iom Iomega Corporation
1237 +isee ISEE 2007 S.L.
1238 +isil Intersil
1239 +issi Integrated Silicon Solutions Inc.
1240 +itead ITEAD Intelligent Systems Co.Ltd
1241 +iwave iWave Systems Technologies Pvt. Ltd.
1242 +jdi Japan Display Inc.
1243 +jedec JEDEC Solid State Technology Association
1244 +jianda Jiandangjing Technology Co., Ltd.
1245 +karo Ka-Ro electronics GmbH
1246 +keithkoep Keith & Koep GmbH
1247 +keymile Keymile GmbH
1248 +khadas Khadas
1249 +kiebackpeter Kieback & Peter GmbH
1250 +kinetic Kinetic Technologies
1251 +kingdisplay King & Display Technology Co., Ltd.
1252 +kingnovel Kingnovel Technology Co., Ltd.
1253 +koe Kaohsiung Opto-Electronics Inc.
1254 +kosagi Sutajio Ko-Usagi PTE Ltd.
1255 +kyo Kyocera Corporation
1256 +lacie LaCie
1257 +laird Laird PLC
1258 +lantiq Lantiq Semiconductor
1259 +lattice Lattice Semiconductor
1260 +lego LEGO Systems A/S
1261 +lemaker Shenzhen LeMaker Technology Co., Ltd.
1262 +lenovo Lenovo Group Ltd.
1263 +lg LG Corporation
1264 +libretech Shenzhen Libre Technology Co., Ltd
1265 +licheepi Lichee Pi
1266 +linaro Linaro Limited
1267 +linksys Belkin International, Inc. (Linksys)
1268 +linux Linux-specific binding
1269 +linx Linx Technologies
1270 +lltc Linear Technology Corporation
1271 +logicpd Logic PD, Inc.
1272 +lsi LSI Corp. (LSI Logic)
1273 +lwn Liebherr-Werk Nenzing GmbH
1274 +macnica Macnica Americas
1275 +marvell Marvell Technology Group Ltd.
1276 +maxim Maxim Integrated Products
1277 +mbvl Mobiveil Inc.
1278 +mcube mCube
1279 +meas Measurement Specialties
1280 +mediatek MediaTek Inc.
1281 +megachips MegaChips
1282 +mele Shenzhen MeLE Digital Technology Ltd.
1283 +melexis Melexis N.V.
1284 +melfas MELFAS Inc.
1285 +mellanox Mellanox Technologies
1286 +memsic MEMSIC Inc.
1287 +merrii Merrii Technology Co., Ltd.
1288 +micrel Micrel Inc.
1289 +microchip Microchip Technology Inc.
1290 +microcrystal Micro Crystal AG
1291 +micron Micron Technology Inc.
1292 +mikroe MikroElektronika d.o.o.
1293 +minix MINIX Technology Ltd.
1294 +miramems MiraMEMS Sensing Technology Co., Ltd.
1295 +mitsubishi Mitsubishi Electric Corporation
1296 +mosaixtech Mosaix Technologies, Inc.
1297 +motorola Motorola, Inc.
1298 +moxa Moxa Inc.
1299 +mpl MPL AG
1300 +mqmaker mqmaker Inc.
1301 +mscc Microsemi Corporation
1302 +msi Micro-Star International Co. Ltd.
1303 +mti Imagination Technologies Ltd. (formerly MIPS Technologies Inc.)
1304 +multi-inno Multi-Inno Technology Co.,Ltd
1305 +mundoreader Mundo Reader S.L.
1306 +murata Murata Manufacturing Co., Ltd.
1307 +mxicy Macronix International Co., Ltd.
1308 +myir MYIR Tech Limited
1309 +national National Semiconductor
1310 +nec NEC LCD Technologies, Ltd.
1311 +neonode Neonode Inc.
1312 +netgear NETGEAR
1313 +netlogic Broadcom Corporation (formerly NetLogic Microsystems)
1314 +netron-dy Netron DY
1315 +netxeon Shenzhen Netxeon Technology CO., LTD
1316 +nexbox Nexbox
1317 +nextthing Next Thing Co.
1318 +newhaven Newhaven Display International
1319 +ni National Instruments
1320 +nintendo Nintendo
1321 +nlt NLT Technologies, Ltd.
1322 +nokia Nokia
1323 +nordic Nordic Semiconductor
1324 +novtech NovTech, Inc.
1325 +nutsboard NutsBoard
1326 +nuvoton Nuvoton Technology Corporation
1327 +nvd New Vision Display
1328 +nvidia NVIDIA
1329 +nxp NXP Semiconductors
1330 +okaya Okaya Electric America, Inc.
1331 +oki Oki Electric Industry Co., Ltd.
1332 +olimex OLIMEX Ltd.
1333 +olpc One Laptop Per Child
1334 +onion Onion Corporation
1335 +onnn ON Semiconductor Corp.
1336 +ontat On Tat Industrial Company
1337 +opalkelly Opal Kelly Incorporated
1338 +opencores OpenCores.org
1339 +openrisc OpenRISC.io
1340 +option Option NV
1341 +oranth Shenzhen Oranth Technology Co., Ltd.
1342 +ORCL Oracle Corporation
1343 +orisetech Orise Technology
1344 +ortustech Ortus Technology Co., Ltd.
1345 +ovti OmniVision Technologies
1346 +oxsemi Oxford Semiconductor, Ltd.
1347 +panasonic Panasonic Corporation
1348 +parade Parade Technologies Inc.
1349 +pda Precision Design Associates, Inc.
1350 +pericom Pericom Technology Inc.
1351 +pervasive Pervasive Displays, Inc.
1352 +phicomm PHICOMM Co., Ltd.
1353 +phytec PHYTEC Messtechnik GmbH
1354 +picochip Picochip Ltd
1355 +pine64 Pine64
1356 +pixcir PIXCIR MICROELECTRONICS Co., Ltd
1357 +plantower Plantower Co., Ltd
1358 +plathome Plat'Home Co., Ltd.
1359 +plda PLDA
1360 +plx Broadcom Corporation (formerly PLX Technology)
1361 +pni PNI Sensor Corporation
1362 +portwell Portwell Inc.
1363 +poslab Poslab Technology Co., Ltd.
1364 +powervr PowerVR (deprecated, use img)
1365 +probox2 PROBOX2 (by W2COMP Co., Ltd.)
1366 +pulsedlight PulsedLight, Inc
1367 +qca Qualcomm Atheros, Inc.
1368 +qcom Qualcomm Technologies, Inc
1369 +qemu QEMU, a generic and open source machine emulator and virtualizer
1370 +qi Qi Hardware
1371 +qiaodian QiaoDian XianShi Corporation
1372 +qnap QNAP Systems, Inc.
1373 +radxa Radxa
1374 +raidsonic RaidSonic Technology GmbH
1375 +ralink Mediatek/Ralink Technology Corp.
1376 +ramtron Ramtron International
1377 +raspberrypi Raspberry Pi Foundation
1378 +raydium Raydium Semiconductor Corp.
1379 +rda Unisoc Communications, Inc.
1380 +realtek Realtek Semiconductor Corp.
1381 +renesas Renesas Electronics Corporation
1382 +richtek Richtek Technology Corporation
1383 +ricoh Ricoh Co. Ltd.
1384 +rikomagic Rikomagic Tech Corp. Ltd
1385 +riscv RISC-V Foundation
1386 +rockchip Fuzhou Rockchip Electronics Co., Ltd
1387 +rohm ROHM Semiconductor Co., Ltd
1388 +roofull Shenzhen Roofull Technology Co, Ltd
1389 +samsung Samsung Semiconductor
1390 +samtec Samtec/Softing company
1391 +sancloud Sancloud Ltd
1392 +sandisk Sandisk Corporation
1393 +sbs Smart Battery System
1394 +schindler Schindler
1395 +seagate Seagate Technology PLC
1396 +semtech Semtech Corporation
1397 +sensirion Sensirion AG
1398 +sff Small Form Factor Committee
1399 +sgd Solomon Goldentek Display Corporation
1400 +sgx SGX Sensortech
1401 +sharp Sharp Corporation
1402 +shimafuji Shimafuji Electric, Inc.
1403 +si-en Si-En Technology Ltd.
1404 +sifive SiFive, Inc.
1405 +sigma Sigma Designs, Inc.
1406 +sii Seiko Instruments, Inc.
1407 +sil Silicon Image
1408 +silabs Silicon Laboratories
1409 +silead Silead Inc.
1410 +silergy Silergy Corp.
1411 +siliconmitus Silicon Mitus, Inc.
1412 +simtek
1413 +sirf SiRF Technology, Inc.
1414 +sis Silicon Integrated Systems Corp.
1415 +sitronix Sitronix Technology Corporation
1416 +skyworks Skyworks Solutions, Inc.
1417 +smsc Standard Microsystems Corporation
1418 +snps Synopsys, Inc.
1419 +socionext Socionext Inc.
1420 +solidrun SolidRun
1421 +solomon Solomon Systech Limited
1422 +sony Sony Corporation
1423 +spansion Spansion Inc.
1424 +sprd Spreadtrum Communications Inc.
1425 +sst Silicon Storage Technology, Inc.
1426 +st STMicroelectronics
1427 +starry Starry Electronic Technology (ShenZhen) Co., LTD
1428 +startek Startek
1429 +ste ST-Ericsson
1430 +stericsson ST-Ericsson
1431 +summit Summit microelectronics
1432 +sunchip Shenzhen Sunchip Technology Co., Ltd
1433 +SUNW Sun Microsystems, Inc
1434 +swir Sierra Wireless
1435 +syna Synaptics Inc.
1436 +synology Synology, Inc.
1437 +tbs TBS Technologies
1438 +tbs-biometrics Touchless Biometric Systems AG
1439 +tcg Trusted Computing Group
1440 +tcl Toby Churchill Ltd.
1441 +technexion TechNexion
1442 +technologic Technologic Systems
1443 +tempo Tempo Semiconductor
1444 +techstar Shenzhen Techstar Electronics Co., Ltd.
1445 +terasic Terasic Inc.
1446 +thine THine Electronics, Inc.
1447 +ti Texas Instruments
1448 +tianma Tianma Micro-electronics Co., Ltd.
1449 +tlm Trusted Logic Mobility
1450 +tmt Tecon Microprocessor Technologies, LLC.
1451 +topeet Topeet
1452 +toradex Toradex AG
1453 +toshiba Toshiba Corporation
1454 +toumaz Toumaz
1455 +tpk TPK U.S.A. LLC
1456 +tplink TP-LINK Technologies Co., Ltd.
1457 +tpo TPO
1458 +tronfy Tronfy
1459 +tronsmart Tronsmart
1460 +truly Truly Semiconductors Limited
1461 +tsd Theobroma Systems Design und Consulting GmbH
1462 +tyan Tyan Computer Corporation
1463 +u-blox u-blox
1464 +ucrobotics uCRobotics
1465 +ubnt Ubiquiti Networks
1466 +udoo Udoo
1467 +uniwest United Western Technologies Corp (UniWest)
1468 +upisemi uPI Semiconductor Corp.
1469 +urt United Radiant Technology Corporation
1470 +usi Universal Scientific Industrial Co., Ltd.
1471 +v3 V3 Semiconductor
1472 +vamrs Vamrs Ltd.
1473 +variscite Variscite Ltd.
1474 +via VIA Technologies, Inc.
1475 +virtio Virtual I/O Device Specification, developed by the OASIS consortium
1476 +vishay Vishay Intertechnology, Inc
1477 +vitesse Vitesse Semiconductor Corporation
1478 +vivante Vivante Corporation
1479 +vocore VoCore Studio
1480 +voipac Voipac Technologies s.r.o.
1481 +vot Vision Optical Technology Co., Ltd.
1482 +wd Western Digital Corp.
1483 +wetek WeTek Electronics, limited.
1484 +wexler Wexler
1485 +whwave Shenzhen whwave Electronics, Inc.
1486 +wi2wi Wi2Wi, Inc.
1487 +winbond Winbond Electronics corp.
1488 +winstar Winstar Display Corp.
1489 +wlf Wolfson Microelectronics
1490 +wm Wondermedia Technologies, Inc.
1491 +x-powers X-Powers
1492 +xes Extreme Engineering Solutions (X-ES)
1493 +xillybus Xillybus Ltd.
1494 +xlnx Xilinx
1495 +xunlong Shenzhen Xunlong Software CO.,Limited
1496 +ysoft Y Soft Corporation a.s.
1497 +zarlink Zarlink Semiconductor
1498 +zeitec ZEITEC Semiconductor Co., LTD.
1499 +zidoo Shenzhen Zidoo Technology Co., Ltd.
1500 +zii Zodiac Inflight Innovations
1501 +zte ZTE Corp.
1502 +zyxel ZyXEL Communications Corp.
1503 --- a/Documentation/devicetree/bindings/vendor-prefixes.yaml
1504 +++ b/Documentation/devicetree/bindings/vendor-prefixes.yaml
1505 @@ -188,6 +188,8 @@ patternProperties:
1506 description: Beckhoff Automation GmbH & Co. KG
1507 "^bitmain,.*":
1508 description: Bitmain Technologies
1509 + "^blokaslabs,.*":
1510 + description: Vilniaus Blokas UAB
1511 "^blutek,.*":
1512 description: BluTek Power
1513 "^boe,.*":
1514 --- a/drivers/clk/Kconfig
1515 +++ b/drivers/clk/Kconfig
1516 @@ -99,6 +99,12 @@ config COMMON_CLK_HI655X
1517 multi-function device has one fixed-rate oscillator, clocked
1518 at 32KHz.
1519
1520 +config COMMON_CLK_HIFIBERRY_DACPLUSHD
1521 + tristate
1522 +
1523 +config COMMON_CLK_HIFIBERRY_DACPRO
1524 + tristate
1525 +
1526 config COMMON_CLK_SCMI
1527 tristate "Clock driver controlled via SCMI interface"
1528 depends on ARM_SCMI_PROTOCOL || COMPILE_TEST
1529 --- a/drivers/clk/Makefile
1530 +++ b/drivers/clk/Makefile
1531 @@ -19,6 +19,7 @@ endif
1532
1533 # hardware specific clock types
1534 # please keep this section sorted lexicographically by file path name
1535 +obj-$(CONFIG_SND_BCM2708_SOC_ALLO_BOSS_DAC) += clk-allo-dac.o
1536 obj-$(CONFIG_COMMON_CLK_APPLE_NCO) += clk-apple-nco.o
1537 obj-$(CONFIG_MACH_ASM9260) += clk-asm9260.o
1538 obj-$(CONFIG_COMMON_CLK_AXI_CLKGEN) += clk-axi-clkgen.o
1539 @@ -43,6 +44,8 @@ obj-$(CONFIG_COMMON_CLK_K210) += clk-k2
1540 obj-$(CONFIG_LMK04832) += clk-lmk04832.o
1541 obj-$(CONFIG_COMMON_CLK_LAN966X) += clk-lan966x.o
1542 obj-$(CONFIG_COMMON_CLK_LOCHNAGAR) += clk-lochnagar.o
1543 +obj-$(CONFIG_COMMON_CLK_HIFIBERRY_DACPRO) += clk-hifiberry-dacpro.o
1544 +obj-$(CONFIG_COMMON_CLK_HIFIBERRY_DACPLUSHD) += clk-hifiberry-dachd.o
1545 obj-$(CONFIG_COMMON_CLK_MAX77686) += clk-max77686.o
1546 obj-$(CONFIG_COMMON_CLK_MAX9485) += clk-max9485.o
1547 obj-$(CONFIG_ARCH_MILBEAUT_M10V) += clk-milbeaut.o
1548 --- /dev/null
1549 +++ b/drivers/clk/clk-allo-dac.c
1550 @@ -0,0 +1,161 @@
1551 +/*
1552 + * Clock Driver for Allo DAC
1553 + *
1554 + * Author: Baswaraj K <jaikumar@cem-solutions.net>
1555 + * Copyright 2016
1556 + * based on code by Stuart MacLean
1557 + *
1558 + * This program is free software; you can redistribute it and/or
1559 + * modify it under the terms of the GNU General Public License
1560 + * version 2 as published by the Free Software Foundation.
1561 + *
1562 + * This program is distributed in the hope that it will be useful, but
1563 + * WITHOUT ANY WARRANTY; without even the implied warranty of
1564 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1565 + * General Public License for more details.
1566 + */
1567 +
1568 +#include <linux/clk-provider.h>
1569 +#include <linux/clkdev.h>
1570 +#include <linux/kernel.h>
1571 +#include <linux/module.h>
1572 +#include <linux/of.h>
1573 +#include <linux/slab.h>
1574 +#include <linux/platform_device.h>
1575 +
1576 +/* Clock rate of CLK44EN attached to GPIO6 pin */
1577 +#define CLK_44EN_RATE 45158400UL
1578 +/* Clock rate of CLK48EN attached to GPIO3 pin */
1579 +#define CLK_48EN_RATE 49152000UL
1580 +
1581 +/**
1582 + * struct allo_dac_clk - Common struct to the Allo DAC
1583 + * @hw: clk_hw for the common clk framework
1584 + * @mode: 0 => CLK44EN, 1 => CLK48EN
1585 + */
1586 +struct clk_allo_hw {
1587 + struct clk_hw hw;
1588 + uint8_t mode;
1589 +};
1590 +
1591 +#define to_allo_clk(_hw) container_of(_hw, struct clk_allo_hw, hw)
1592 +
1593 +static const struct of_device_id clk_allo_dac_dt_ids[] = {
1594 + { .compatible = "allo,dac-clk",},
1595 + { }
1596 +};
1597 +MODULE_DEVICE_TABLE(of, clk_allo_dac_dt_ids);
1598 +
1599 +static unsigned long clk_allo_dac_recalc_rate(struct clk_hw *hw,
1600 + unsigned long parent_rate)
1601 +{
1602 + return (to_allo_clk(hw)->mode == 0) ? CLK_44EN_RATE :
1603 + CLK_48EN_RATE;
1604 +}
1605 +
1606 +static long clk_allo_dac_round_rate(struct clk_hw *hw,
1607 + unsigned long rate, unsigned long *parent_rate)
1608 +{
1609 + long actual_rate;
1610 +
1611 + if (rate <= CLK_44EN_RATE) {
1612 + actual_rate = (long)CLK_44EN_RATE;
1613 + } else if (rate >= CLK_48EN_RATE) {
1614 + actual_rate = (long)CLK_48EN_RATE;
1615 + } else {
1616 + long diff44Rate = (long)(rate - CLK_44EN_RATE);
1617 + long diff48Rate = (long)(CLK_48EN_RATE - rate);
1618 +
1619 + if (diff44Rate < diff48Rate)
1620 + actual_rate = (long)CLK_44EN_RATE;
1621 + else
1622 + actual_rate = (long)CLK_48EN_RATE;
1623 + }
1624 + return actual_rate;
1625 +}
1626 +
1627 +
1628 +static int clk_allo_dac_set_rate(struct clk_hw *hw,
1629 + unsigned long rate, unsigned long parent_rate)
1630 +{
1631 + unsigned long actual_rate;
1632 + struct clk_allo_hw *clk = to_allo_clk(hw);
1633 +
1634 + actual_rate = (unsigned long)clk_allo_dac_round_rate(hw, rate,
1635 + &parent_rate);
1636 + clk->mode = (actual_rate == CLK_44EN_RATE) ? 0 : 1;
1637 + return 0;
1638 +}
1639 +
1640 +
1641 +const struct clk_ops clk_allo_dac_rate_ops = {
1642 + .recalc_rate = clk_allo_dac_recalc_rate,
1643 + .round_rate = clk_allo_dac_round_rate,
1644 + .set_rate = clk_allo_dac_set_rate,
1645 +};
1646 +
1647 +static int clk_allo_dac_probe(struct platform_device *pdev)
1648 +{
1649 + int ret;
1650 + struct clk_allo_hw *proclk;
1651 + struct clk *clk;
1652 + struct device *dev;
1653 + struct clk_init_data init;
1654 +
1655 + dev = &pdev->dev;
1656 +
1657 + proclk = kzalloc(sizeof(struct clk_allo_hw), GFP_KERNEL);
1658 + if (!proclk)
1659 + return -ENOMEM;
1660 +
1661 + init.name = "clk-allo-dac";
1662 + init.ops = &clk_allo_dac_rate_ops;
1663 + init.flags = 0;
1664 + init.parent_names = NULL;
1665 + init.num_parents = 0;
1666 +
1667 + proclk->mode = 0;
1668 + proclk->hw.init = &init;
1669 +
1670 + clk = devm_clk_register(dev, &proclk->hw);
1671 + if (!IS_ERR(clk)) {
1672 + ret = of_clk_add_provider(dev->of_node, of_clk_src_simple_get,
1673 + clk);
1674 + } else {
1675 + dev_err(dev, "Fail to register clock driver\n");
1676 + kfree(proclk);
1677 + ret = PTR_ERR(clk);
1678 + }
1679 + return ret;
1680 +}
1681 +
1682 +static int clk_allo_dac_remove(struct platform_device *pdev)
1683 +{
1684 + of_clk_del_provider(pdev->dev.of_node);
1685 + return 0;
1686 +}
1687 +
1688 +static struct platform_driver clk_allo_dac_driver = {
1689 + .probe = clk_allo_dac_probe,
1690 + .remove = clk_allo_dac_remove,
1691 + .driver = {
1692 + .name = "clk-allo-dac",
1693 + .of_match_table = clk_allo_dac_dt_ids,
1694 + },
1695 +};
1696 +
1697 +static int __init clk_allo_dac_init(void)
1698 +{
1699 + return platform_driver_register(&clk_allo_dac_driver);
1700 +}
1701 +core_initcall(clk_allo_dac_init);
1702 +
1703 +static void __exit clk_allo_dac_exit(void)
1704 +{
1705 + platform_driver_unregister(&clk_allo_dac_driver);
1706 +}
1707 +module_exit(clk_allo_dac_exit);
1708 +
1709 +MODULE_DESCRIPTION("Allo DAC clock driver");
1710 +MODULE_LICENSE("GPL v2");
1711 +MODULE_ALIAS("platform:clk-allo-dac");
1712 --- /dev/null
1713 +++ b/drivers/clk/clk-hifiberry-dachd.c
1714 @@ -0,0 +1,332 @@
1715 +// SPDX-License-Identifier: GPL-2.0
1716 +/*
1717 + * Clock Driver for HiFiBerry DAC+ HD
1718 + *
1719 + * Author: Joerg Schambacher, i2Audio GmbH for HiFiBerry
1720 + * Copyright 2020
1721 + *
1722 + * This program is free software; you can redistribute it and/or
1723 + * modify it under the terms of the GNU General Public License
1724 + * version 2 as published by the Free Software Foundation.
1725 + *
1726 + * This program is distributed in the hope that it will be useful, but
1727 + * WITHOUT ANY WARRANTY; without even the implied warranty of
1728 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1729 + * General Public License for more details.
1730 + */
1731 +
1732 +#include <linux/clk-provider.h>
1733 +#include <linux/clk.h>
1734 +#include <linux/kernel.h>
1735 +#include <linux/module.h>
1736 +#include <linux/of.h>
1737 +#include <linux/slab.h>
1738 +#include <linux/platform_device.h>
1739 +#include <linux/i2c.h>
1740 +#include <linux/regmap.h>
1741 +
1742 +#define NO_PLL_RESET 0
1743 +#define PLL_RESET 1
1744 +#define HIFIBERRY_PLL_MAX_REGISTER 256
1745 +#define DEFAULT_RATE 44100
1746 +
1747 +static struct reg_default hifiberry_pll_reg_defaults[] = {
1748 + {0x02, 0x53}, {0x03, 0x00}, {0x07, 0x20}, {0x0F, 0x00},
1749 + {0x10, 0x0D}, {0x11, 0x1D}, {0x12, 0x0D}, {0x13, 0x8C},
1750 + {0x14, 0x8C}, {0x15, 0x8C}, {0x16, 0x8C}, {0x17, 0x8C},
1751 + {0x18, 0x2A}, {0x1C, 0x00}, {0x1D, 0x0F}, {0x1F, 0x00},
1752 + {0x2A, 0x00}, {0x2C, 0x00}, {0x2F, 0x00}, {0x30, 0x00},
1753 + {0x31, 0x00}, {0x32, 0x00}, {0x34, 0x00}, {0x37, 0x00},
1754 + {0x38, 0x00}, {0x39, 0x00}, {0x3A, 0x00}, {0x3B, 0x01},
1755 + {0x3E, 0x00}, {0x3F, 0x00}, {0x40, 0x00}, {0x41, 0x00},
1756 + {0x5A, 0x00}, {0x5B, 0x00}, {0x95, 0x00}, {0x96, 0x00},
1757 + {0x97, 0x00}, {0x98, 0x00}, {0x99, 0x00}, {0x9A, 0x00},
1758 + {0x9B, 0x00}, {0xA2, 0x00}, {0xA3, 0x00}, {0xA4, 0x00},
1759 + {0xB7, 0x92},
1760 + {0x1A, 0x3D}, {0x1B, 0x09}, {0x1E, 0xF3}, {0x20, 0x13},
1761 + {0x21, 0x75}, {0x2B, 0x04}, {0x2D, 0x11}, {0x2E, 0xE0},
1762 + {0x3D, 0x7A},
1763 + {0x35, 0x9D}, {0x36, 0x00}, {0x3C, 0x42},
1764 + { 177, 0xAC},
1765 +};
1766 +static struct reg_default common_pll_regs[HIFIBERRY_PLL_MAX_REGISTER];
1767 +static int num_common_pll_regs;
1768 +static struct reg_default dedicated_192k_pll_regs[HIFIBERRY_PLL_MAX_REGISTER];
1769 +static int num_dedicated_192k_pll_regs;
1770 +static struct reg_default dedicated_96k_pll_regs[HIFIBERRY_PLL_MAX_REGISTER];
1771 +static int num_dedicated_96k_pll_regs;
1772 +static struct reg_default dedicated_48k_pll_regs[HIFIBERRY_PLL_MAX_REGISTER];
1773 +static int num_dedicated_48k_pll_regs;
1774 +static struct reg_default dedicated_176k4_pll_regs[HIFIBERRY_PLL_MAX_REGISTER];
1775 +static int num_dedicated_176k4_pll_regs;
1776 +static struct reg_default dedicated_88k2_pll_regs[HIFIBERRY_PLL_MAX_REGISTER];
1777 +static int num_dedicated_88k2_pll_regs;
1778 +static struct reg_default dedicated_44k1_pll_regs[HIFIBERRY_PLL_MAX_REGISTER];
1779 +static int num_dedicated_44k1_pll_regs;
1780 +
1781 +/**
1782 + * struct clk_hifiberry_drvdata - Common struct to the HiFiBerry DAC HD Clk
1783 + * @hw: clk_hw for the common clk framework
1784 + */
1785 +struct clk_hifiberry_drvdata {
1786 + struct regmap *regmap;
1787 + struct clk *clk;
1788 + struct clk_hw hw;
1789 + unsigned long rate;
1790 +};
1791 +
1792 +#define to_hifiberry_clk(_hw) \
1793 + container_of(_hw, struct clk_hifiberry_drvdata, hw)
1794 +
1795 +static int clk_hifiberry_dachd_write_pll_regs(struct regmap *regmap,
1796 + struct reg_default *regs,
1797 + int num, int do_pll_reset)
1798 +{
1799 + int i;
1800 + int ret = 0;
1801 + char pll_soft_reset[] = { 177, 0xAC, };
1802 +
1803 + for (i = 0; i < num; i++) {
1804 + ret |= regmap_write(regmap, regs[i].reg, regs[i].def);
1805 + if (ret)
1806 + return ret;
1807 + }
1808 + if (do_pll_reset) {
1809 + ret |= regmap_write(regmap, pll_soft_reset[0],
1810 + pll_soft_reset[1]);
1811 + mdelay(10);
1812 + }
1813 + return ret;
1814 +}
1815 +
1816 +static unsigned long clk_hifiberry_dachd_recalc_rate(struct clk_hw *hw,
1817 + unsigned long parent_rate)
1818 +{
1819 + return to_hifiberry_clk(hw)->rate;
1820 +}
1821 +
1822 +static long clk_hifiberry_dachd_round_rate(struct clk_hw *hw,
1823 + unsigned long rate, unsigned long *parent_rate)
1824 +{
1825 + return rate;
1826 +}
1827 +
1828 +static int clk_hifiberry_dachd_set_rate(struct clk_hw *hw,
1829 + unsigned long rate, unsigned long parent_rate)
1830 +{
1831 + int ret;
1832 + struct clk_hifiberry_drvdata *drvdata = to_hifiberry_clk(hw);
1833 +
1834 + switch (rate) {
1835 + case 44100:
1836 + ret = clk_hifiberry_dachd_write_pll_regs(drvdata->regmap,
1837 + dedicated_44k1_pll_regs, num_dedicated_44k1_pll_regs,
1838 + PLL_RESET);
1839 + break;
1840 + case 88200:
1841 + ret = clk_hifiberry_dachd_write_pll_regs(drvdata->regmap,
1842 + dedicated_88k2_pll_regs, num_dedicated_88k2_pll_regs,
1843 + PLL_RESET);
1844 + break;
1845 + case 176400:
1846 + ret = clk_hifiberry_dachd_write_pll_regs(drvdata->regmap,
1847 + dedicated_176k4_pll_regs, num_dedicated_176k4_pll_regs,
1848 + PLL_RESET);
1849 + break;
1850 + case 48000:
1851 + ret = clk_hifiberry_dachd_write_pll_regs(drvdata->regmap,
1852 + dedicated_48k_pll_regs, num_dedicated_48k_pll_regs,
1853 + PLL_RESET);
1854 + break;
1855 + case 96000:
1856 + ret = clk_hifiberry_dachd_write_pll_regs(drvdata->regmap,
1857 + dedicated_96k_pll_regs, num_dedicated_96k_pll_regs,
1858 + PLL_RESET);
1859 + break;
1860 + case 192000:
1861 + ret = clk_hifiberry_dachd_write_pll_regs(drvdata->regmap,
1862 + dedicated_192k_pll_regs, num_dedicated_192k_pll_regs,
1863 + PLL_RESET);
1864 + break;
1865 + default:
1866 + ret = -EINVAL;
1867 + break;
1868 + }
1869 + to_hifiberry_clk(hw)->rate = rate;
1870 +
1871 + return ret;
1872 +}
1873 +
1874 +const struct clk_ops clk_hifiberry_dachd_rate_ops = {
1875 + .recalc_rate = clk_hifiberry_dachd_recalc_rate,
1876 + .round_rate = clk_hifiberry_dachd_round_rate,
1877 + .set_rate = clk_hifiberry_dachd_set_rate,
1878 +};
1879 +
1880 +static int clk_hifiberry_get_prop_values(struct device *dev,
1881 + char *prop_name,
1882 + struct reg_default *regs)
1883 +{
1884 + int ret;
1885 + int i;
1886 + u8 tmp[2 * HIFIBERRY_PLL_MAX_REGISTER];
1887 +
1888 + ret = of_property_read_variable_u8_array(dev->of_node, prop_name,
1889 + tmp, 0, 2 * HIFIBERRY_PLL_MAX_REGISTER);
1890 + if (ret < 0)
1891 + return ret;
1892 + if (ret & 1) {
1893 + dev_err(dev,
1894 + "%s <%s> -> #%i odd number of bytes for reg/val pairs!",
1895 + __func__,
1896 + prop_name,
1897 + ret);
1898 + return -EINVAL;
1899 + }
1900 + ret /= 2;
1901 + for (i = 0; i < ret; i++) {
1902 + regs[i].reg = (u32)tmp[2 * i];
1903 + regs[i].def = (u32)tmp[2 * i + 1];
1904 + }
1905 + return ret;
1906 +}
1907 +
1908 +
1909 +static int clk_hifiberry_dachd_dt_parse(struct device *dev)
1910 +{
1911 + num_common_pll_regs = clk_hifiberry_get_prop_values(dev,
1912 + "common_pll_regs", common_pll_regs);
1913 + num_dedicated_44k1_pll_regs = clk_hifiberry_get_prop_values(dev,
1914 + "44k1_pll_regs", dedicated_44k1_pll_regs);
1915 + num_dedicated_88k2_pll_regs = clk_hifiberry_get_prop_values(dev,
1916 + "88k2_pll_regs", dedicated_88k2_pll_regs);
1917 + num_dedicated_176k4_pll_regs = clk_hifiberry_get_prop_values(dev,
1918 + "176k4_pll_regs", dedicated_176k4_pll_regs);
1919 + num_dedicated_48k_pll_regs = clk_hifiberry_get_prop_values(dev,
1920 + "48k_pll_regs", dedicated_48k_pll_regs);
1921 + num_dedicated_96k_pll_regs = clk_hifiberry_get_prop_values(dev,
1922 + "96k_pll_regs", dedicated_96k_pll_regs);
1923 + num_dedicated_192k_pll_regs = clk_hifiberry_get_prop_values(dev,
1924 + "192k_pll_regs", dedicated_192k_pll_regs);
1925 + return 0;
1926 +}
1927 +
1928 +
1929 +static int clk_hifiberry_dachd_remove(struct device *dev)
1930 +{
1931 + of_clk_del_provider(dev->of_node);
1932 + return 0;
1933 +}
1934 +
1935 +const struct regmap_config hifiberry_pll_regmap = {
1936 + .reg_bits = 8,
1937 + .val_bits = 8,
1938 + .max_register = HIFIBERRY_PLL_MAX_REGISTER,
1939 + .reg_defaults = hifiberry_pll_reg_defaults,
1940 + .num_reg_defaults = ARRAY_SIZE(hifiberry_pll_reg_defaults),
1941 + .cache_type = REGCACHE_RBTREE,
1942 +};
1943 +EXPORT_SYMBOL_GPL(hifiberry_pll_regmap);
1944 +
1945 +
1946 +static int clk_hifiberry_dachd_i2c_probe(struct i2c_client *i2c,
1947 + const struct i2c_device_id *id)
1948 +{
1949 + struct clk_hifiberry_drvdata *hdclk;
1950 + int ret = 0;
1951 + struct clk_init_data init;
1952 + struct device *dev = &i2c->dev;
1953 + struct device_node *dev_node = dev->of_node;
1954 + struct regmap_config config = hifiberry_pll_regmap;
1955 +
1956 + hdclk = devm_kzalloc(&i2c->dev,
1957 + sizeof(struct clk_hifiberry_drvdata), GFP_KERNEL);
1958 + if (!hdclk)
1959 + return -ENOMEM;
1960 +
1961 + i2c_set_clientdata(i2c, hdclk);
1962 +
1963 + hdclk->regmap = devm_regmap_init_i2c(i2c, &config);
1964 +
1965 + if (IS_ERR(hdclk->regmap))
1966 + return PTR_ERR(hdclk->regmap);
1967 +
1968 + /* start PLL to allow detection of DAC */
1969 + ret = clk_hifiberry_dachd_write_pll_regs(hdclk->regmap,
1970 + hifiberry_pll_reg_defaults,
1971 + ARRAY_SIZE(hifiberry_pll_reg_defaults),
1972 + PLL_RESET);
1973 + if (ret)
1974 + return ret;
1975 +
1976 + clk_hifiberry_dachd_dt_parse(dev);
1977 +
1978 + /* restart PLL with configs from DTB */
1979 + ret = clk_hifiberry_dachd_write_pll_regs(hdclk->regmap, common_pll_regs,
1980 + num_common_pll_regs, PLL_RESET);
1981 + if (ret)
1982 + return ret;
1983 +
1984 + init.name = "clk-hifiberry-dachd";
1985 + init.ops = &clk_hifiberry_dachd_rate_ops;
1986 + init.flags = 0;
1987 + init.parent_names = NULL;
1988 + init.num_parents = 0;
1989 +
1990 + hdclk->hw.init = &init;
1991 +
1992 + hdclk->clk = devm_clk_register(dev, &hdclk->hw);
1993 + if (IS_ERR(hdclk->clk)) {
1994 + dev_err(dev, "unable to register %s\n", init.name);
1995 + return PTR_ERR(hdclk->clk);
1996 + }
1997 +
1998 + ret = of_clk_add_provider(dev_node, of_clk_src_simple_get, hdclk->clk);
1999 + if (ret != 0) {
2000 + dev_err(dev, "Cannot of_clk_add_provider");
2001 + return ret;
2002 + }
2003 +
2004 + ret = clk_set_rate(hdclk->hw.clk, DEFAULT_RATE);
2005 + if (ret != 0) {
2006 + dev_err(dev, "Cannot set rate : %d\n", ret);
2007 + return -EINVAL;
2008 + }
2009 +
2010 + return ret;
2011 +}
2012 +
2013 +static void clk_hifiberry_dachd_i2c_remove(struct i2c_client *i2c)
2014 +{
2015 + clk_hifiberry_dachd_remove(&i2c->dev);
2016 +}
2017 +
2018 +static const struct i2c_device_id clk_hifiberry_dachd_i2c_id[] = {
2019 + { "dachd-clk", },
2020 + { }
2021 +};
2022 +MODULE_DEVICE_TABLE(i2c, clk_hifiberry_dachd_i2c_id);
2023 +
2024 +static const struct of_device_id clk_hifiberry_dachd_of_match[] = {
2025 + { .compatible = "hifiberry,dachd-clk", },
2026 + { }
2027 +};
2028 +MODULE_DEVICE_TABLE(of, clk_hifiberry_dachd_of_match);
2029 +
2030 +static struct i2c_driver clk_hifiberry_dachd_i2c_driver = {
2031 + .probe = clk_hifiberry_dachd_i2c_probe,
2032 + .remove = clk_hifiberry_dachd_i2c_remove,
2033 + .id_table = clk_hifiberry_dachd_i2c_id,
2034 + .driver = {
2035 + .name = "dachd-clk",
2036 + .of_match_table = of_match_ptr(clk_hifiberry_dachd_of_match),
2037 + },
2038 +};
2039 +
2040 +module_i2c_driver(clk_hifiberry_dachd_i2c_driver);
2041 +
2042 +
2043 +MODULE_DESCRIPTION("HiFiBerry DAC+ HD clock driver");
2044 +MODULE_AUTHOR("Joerg Schambacher <joerg@i2audio.com>");
2045 +MODULE_LICENSE("GPL v2");
2046 +MODULE_ALIAS("platform:clk-hifiberry-dachd");
2047 --- /dev/null
2048 +++ b/drivers/clk/clk-hifiberry-dacpro.c
2049 @@ -0,0 +1,160 @@
2050 +/*
2051 + * Clock Driver for HiFiBerry DAC Pro
2052 + *
2053 + * Author: Stuart MacLean
2054 + * Copyright 2015
2055 + *
2056 + * This program is free software; you can redistribute it and/or
2057 + * modify it under the terms of the GNU General Public License
2058 + * version 2 as published by the Free Software Foundation.
2059 + *
2060 + * This program is distributed in the hope that it will be useful, but
2061 + * WITHOUT ANY WARRANTY; without even the implied warranty of
2062 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2063 + * General Public License for more details.
2064 + */
2065 +
2066 +#include <linux/clk-provider.h>
2067 +#include <linux/clkdev.h>
2068 +#include <linux/kernel.h>
2069 +#include <linux/module.h>
2070 +#include <linux/of.h>
2071 +#include <linux/slab.h>
2072 +#include <linux/platform_device.h>
2073 +
2074 +/* Clock rate of CLK44EN attached to GPIO6 pin */
2075 +#define CLK_44EN_RATE 22579200UL
2076 +/* Clock rate of CLK48EN attached to GPIO3 pin */
2077 +#define CLK_48EN_RATE 24576000UL
2078 +
2079 +/**
2080 + * struct hifiberry_dacpro_clk - Common struct to the HiFiBerry DAC Pro
2081 + * @hw: clk_hw for the common clk framework
2082 + * @mode: 0 => CLK44EN, 1 => CLK48EN
2083 + */
2084 +struct clk_hifiberry_hw {
2085 + struct clk_hw hw;
2086 + uint8_t mode;
2087 +};
2088 +
2089 +#define to_hifiberry_clk(_hw) container_of(_hw, struct clk_hifiberry_hw, hw)
2090 +
2091 +static const struct of_device_id clk_hifiberry_dacpro_dt_ids[] = {
2092 + { .compatible = "hifiberry,dacpro-clk",},
2093 + { }
2094 +};
2095 +MODULE_DEVICE_TABLE(of, clk_hifiberry_dacpro_dt_ids);
2096 +
2097 +static unsigned long clk_hifiberry_dacpro_recalc_rate(struct clk_hw *hw,
2098 + unsigned long parent_rate)
2099 +{
2100 + return (to_hifiberry_clk(hw)->mode == 0) ? CLK_44EN_RATE :
2101 + CLK_48EN_RATE;
2102 +}
2103 +
2104 +static long clk_hifiberry_dacpro_round_rate(struct clk_hw *hw,
2105 + unsigned long rate, unsigned long *parent_rate)
2106 +{
2107 + long actual_rate;
2108 +
2109 + if (rate <= CLK_44EN_RATE) {
2110 + actual_rate = (long)CLK_44EN_RATE;
2111 + } else if (rate >= CLK_48EN_RATE) {
2112 + actual_rate = (long)CLK_48EN_RATE;
2113 + } else {
2114 + long diff44Rate = (long)(rate - CLK_44EN_RATE);
2115 + long diff48Rate = (long)(CLK_48EN_RATE - rate);
2116 +
2117 + if (diff44Rate < diff48Rate)
2118 + actual_rate = (long)CLK_44EN_RATE;
2119 + else
2120 + actual_rate = (long)CLK_48EN_RATE;
2121 + }
2122 + return actual_rate;
2123 +}
2124 +
2125 +
2126 +static int clk_hifiberry_dacpro_set_rate(struct clk_hw *hw,
2127 + unsigned long rate, unsigned long parent_rate)
2128 +{
2129 + unsigned long actual_rate;
2130 + struct clk_hifiberry_hw *clk = to_hifiberry_clk(hw);
2131 +
2132 + actual_rate = (unsigned long)clk_hifiberry_dacpro_round_rate(hw, rate,
2133 + &parent_rate);
2134 + clk->mode = (actual_rate == CLK_44EN_RATE) ? 0 : 1;
2135 + return 0;
2136 +}
2137 +
2138 +
2139 +const struct clk_ops clk_hifiberry_dacpro_rate_ops = {
2140 + .recalc_rate = clk_hifiberry_dacpro_recalc_rate,
2141 + .round_rate = clk_hifiberry_dacpro_round_rate,
2142 + .set_rate = clk_hifiberry_dacpro_set_rate,
2143 +};
2144 +
2145 +static int clk_hifiberry_dacpro_probe(struct platform_device *pdev)
2146 +{
2147 + int ret;
2148 + struct clk_hifiberry_hw *proclk;
2149 + struct clk *clk;
2150 + struct device *dev;
2151 + struct clk_init_data init;
2152 +
2153 + dev = &pdev->dev;
2154 +
2155 + proclk = kzalloc(sizeof(struct clk_hifiberry_hw), GFP_KERNEL);
2156 + if (!proclk)
2157 + return -ENOMEM;
2158 +
2159 + init.name = "clk-hifiberry-dacpro";
2160 + init.ops = &clk_hifiberry_dacpro_rate_ops;
2161 + init.flags = 0;
2162 + init.parent_names = NULL;
2163 + init.num_parents = 0;
2164 +
2165 + proclk->mode = 0;
2166 + proclk->hw.init = &init;
2167 +
2168 + clk = devm_clk_register(dev, &proclk->hw);
2169 + if (!IS_ERR(clk)) {
2170 + ret = of_clk_add_provider(dev->of_node, of_clk_src_simple_get,
2171 + clk);
2172 + } else {
2173 + dev_err(dev, "Fail to register clock driver\n");
2174 + kfree(proclk);
2175 + ret = PTR_ERR(clk);
2176 + }
2177 + return ret;
2178 +}
2179 +
2180 +static int clk_hifiberry_dacpro_remove(struct platform_device *pdev)
2181 +{
2182 + of_clk_del_provider(pdev->dev.of_node);
2183 + return 0;
2184 +}
2185 +
2186 +static struct platform_driver clk_hifiberry_dacpro_driver = {
2187 + .probe = clk_hifiberry_dacpro_probe,
2188 + .remove = clk_hifiberry_dacpro_remove,
2189 + .driver = {
2190 + .name = "clk-hifiberry-dacpro",
2191 + .of_match_table = clk_hifiberry_dacpro_dt_ids,
2192 + },
2193 +};
2194 +
2195 +static int __init clk_hifiberry_dacpro_init(void)
2196 +{
2197 + return platform_driver_register(&clk_hifiberry_dacpro_driver);
2198 +}
2199 +core_initcall(clk_hifiberry_dacpro_init);
2200 +
2201 +static void __exit clk_hifiberry_dacpro_exit(void)
2202 +{
2203 + platform_driver_unregister(&clk_hifiberry_dacpro_driver);
2204 +}
2205 +module_exit(clk_hifiberry_dacpro_exit);
2206 +
2207 +MODULE_DESCRIPTION("HiFiBerry DAC Pro clock driver");
2208 +MODULE_LICENSE("GPL v2");
2209 +MODULE_ALIAS("platform:clk-hifiberry-dacpro");
2210 --- a/sound/soc/bcm/Kconfig
2211 +++ b/sound/soc/bcm/Kconfig
2212 @@ -26,3 +26,308 @@ config SND_BCM63XX_I2S_WHISTLER
2213 DSL/PON chips (bcm63158, bcm63178)
2214
2215 If you don't know what to do here, say N
2216 +
2217 +config SND_BCM2708_SOC_CHIPDIP_DAC
2218 + tristate "Support for the ChipDip DAC"
2219 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2220 + help
2221 + Say Y or M if you want to add support for the ChipDip DAC soundcard
2222 +
2223 +config SND_BCM2708_SOC_GOOGLEVOICEHAT_SOUNDCARD
2224 + tristate "Support for Google voiceHAT soundcard"
2225 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2226 + select SND_SOC_VOICEHAT
2227 + select SND_RPI_SIMPLE_SOUNDCARD
2228 + help
2229 + Say Y or M if you want to add support for voiceHAT soundcard.
2230 +
2231 +config SND_BCM2708_SOC_HIFIBERRY_DAC
2232 + tristate "Support for HifiBerry DAC"
2233 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2234 + select SND_SOC_PCM5102A
2235 + select SND_RPI_SIMPLE_SOUNDCARD
2236 + help
2237 + Say Y or M if you want to add support for HifiBerry DAC.
2238 +
2239 +config SND_BCM2708_SOC_HIFIBERRY_DACPLUS
2240 + tristate "Support for HifiBerry DAC+"
2241 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2242 + select SND_SOC_PCM512x
2243 + select SND_SOC_TPA6130A2
2244 + select COMMON_CLK_HIFIBERRY_DACPRO
2245 + help
2246 + Say Y or M if you want to add support for HifiBerry DAC+.
2247 +
2248 +config SND_BCM2708_SOC_HIFIBERRY_DACPLUSHD
2249 + tristate "Support for HifiBerry DAC+ HD"
2250 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2251 + select SND_SOC_PCM179X_I2C
2252 + select COMMON_CLK_HIFIBERRY_DACPLUSHD
2253 + help
2254 + Say Y or M if you want to add support for HifiBerry DAC+ HD.
2255 +
2256 +config SND_BCM2708_SOC_HIFIBERRY_DACPLUSADC
2257 + tristate "Support for HifiBerry DAC+ADC"
2258 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2259 + select SND_SOC_PCM512x_I2C
2260 + select SND_SOC_DMIC
2261 + select COMMON_CLK_HIFIBERRY_DACPRO
2262 + help
2263 + Say Y or M if you want to add support for HifiBerry DAC+ADC.
2264 +
2265 +config SND_BCM2708_SOC_HIFIBERRY_DACPLUSADCPRO
2266 + tristate "Support for HifiBerry DAC+ADC PRO"
2267 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2268 + select SND_SOC_PCM512x_I2C
2269 + select SND_SOC_PCM186X_I2C
2270 + select SND_SOC_TPA6130A2
2271 + select COMMON_CLK_HIFIBERRY_DACPRO
2272 + help
2273 + Say Y or M if you want to add support for HifiBerry DAC+ADC PRO.
2274 +
2275 +config SND_BCM2708_SOC_HIFIBERRY_DACPLUSDSP
2276 + tristate "Support for HifiBerry DAC+DSP"
2277 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2278 + select SND_RPI_SIMPLE_SOUNDCARD
2279 + help
2280 + Say Y or M if you want to add support for HifiBerry DSP-DAC.
2281 +
2282 +config SND_BCM2708_SOC_HIFIBERRY_DIGI
2283 + tristate "Support for HifiBerry Digi"
2284 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2285 + select SND_SOC_WM8804
2286 + help
2287 + Say Y or M if you want to add support for HifiBerry Digi S/PDIF output board.
2288 +
2289 +config SND_BCM2708_SOC_HIFIBERRY_AMP
2290 + tristate "Support for the HifiBerry Amp"
2291 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2292 + select SND_SOC_TAS5713
2293 + select SND_RPI_SIMPLE_SOUNDCARD
2294 + help
2295 + Say Y or M if you want to add support for the HifiBerry Amp amplifier board.
2296 +
2297 + config SND_BCM2708_SOC_PIFI_40
2298 + tristate "Support for the PiFi-40 amp"
2299 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2300 + select SND_SOC_TAS571X
2301 + select SND_PIFI_40
2302 + help
2303 + Say Y or M if you want to add support for the PiFi40 amp board
2304 +
2305 +config SND_BCM2708_SOC_RPI_CIRRUS
2306 + tristate "Support for Cirrus Logic Audio Card"
2307 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2308 + select SND_SOC_WM5102
2309 + select SND_SOC_WM8804
2310 + help
2311 + Say Y or M if you want to add support for the Wolfson and
2312 + Cirrus Logic audio cards.
2313 +
2314 +config SND_BCM2708_SOC_RPI_DAC
2315 + tristate "Support for RPi-DAC"
2316 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2317 + select SND_SOC_PCM1794A
2318 + select SND_RPI_SIMPLE_SOUNDCARD
2319 + help
2320 + Say Y or M if you want to add support for RPi-DAC.
2321 +
2322 +config SND_BCM2708_SOC_RPI_PROTO
2323 + tristate "Support for Rpi-PROTO"
2324 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2325 + select SND_SOC_WM8731
2326 + help
2327 + Say Y or M if you want to add support for Audio Codec Board PROTO (WM8731).
2328 +
2329 +config SND_BCM2708_SOC_JUSTBOOM_BOTH
2330 + tristate "Support for simultaneous JustBoom Digi and JustBoom DAC"
2331 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2332 + select SND_SOC_WM8804
2333 + select SND_SOC_PCM512x
2334 + help
2335 + Say Y or M if you want to add support for simultaneous
2336 + JustBoom Digi and JustBoom DAC.
2337 +
2338 + This is not the right choice if you only have one but both of
2339 + these cards.
2340 +
2341 +config SND_BCM2708_SOC_JUSTBOOM_DAC
2342 + tristate "Support for JustBoom DAC"
2343 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2344 + select SND_SOC_PCM512x
2345 + help
2346 + Say Y or M if you want to add support for JustBoom DAC.
2347 +
2348 +config SND_BCM2708_SOC_JUSTBOOM_DIGI
2349 + tristate "Support for JustBoom Digi"
2350 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2351 + select SND_SOC_WM8804
2352 + select SND_RPI_WM8804_SOUNDCARD
2353 + help
2354 + Say Y or M if you want to add support for JustBoom Digi.
2355 +
2356 +config SND_BCM2708_SOC_IQAUDIO_CODEC
2357 + tristate "Support for IQaudIO-CODEC"
2358 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2359 + select SND_SOC_DA7213
2360 + help
2361 + Say Y or M if you want to add support for IQaudIO-CODEC.
2362 +
2363 +config SND_BCM2708_SOC_IQAUDIO_DAC
2364 + tristate "Support for IQaudIO-DAC"
2365 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2366 + select SND_SOC_PCM512x_I2C
2367 + help
2368 + Say Y or M if you want to add support for IQaudIO-DAC.
2369 +
2370 +config SND_BCM2708_SOC_IQAUDIO_DIGI
2371 + tristate "Support for IQAudIO Digi"
2372 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2373 + select SND_SOC_WM8804
2374 + select SND_RPI_WM8804_SOUNDCARD
2375 + help
2376 + Say Y or M if you want to add support for IQAudIO Digital IO board.
2377 +
2378 +config SND_BCM2708_SOC_I_SABRE_Q2M
2379 + tristate "Support for Audiophonics I-Sabre Q2M DAC"
2380 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2381 + select SND_SOC_I_SABRE_CODEC
2382 + help
2383 + Say Y or M if you want to add support for Audiophonics I-SABRE Q2M DAC
2384 +
2385 +config SND_BCM2708_SOC_ADAU1977_ADC
2386 + tristate "Support for ADAU1977 ADC"
2387 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2388 + select SND_SOC_ADAU1977_I2C
2389 + select SND_RPI_SIMPLE_SOUNDCARD
2390 + help
2391 + Say Y or M if you want to add support for ADAU1977 ADC.
2392 +
2393 +config SND_AUDIOINJECTOR_PI_SOUNDCARD
2394 + tristate "Support for audioinjector.net Pi add on soundcard"
2395 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2396 + select SND_SOC_WM8731
2397 + help
2398 + Say Y or M if you want to add support for audioinjector.net Pi Hat
2399 +
2400 +config SND_AUDIOINJECTOR_OCTO_SOUNDCARD
2401 + tristate "Support for audioinjector.net Octo channel (Hat) soundcard"
2402 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2403 + select SND_SOC_CS42XX8_I2C
2404 + help
2405 + Say Y or M if you want to add support for audioinjector.net octo add on
2406 +
2407 +config SND_AUDIOINJECTOR_ISOLATED_SOUNDCARD
2408 + tristate "Support for audioinjector.net isolated DAC and ADC soundcard"
2409 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2410 + select SND_SOC_CS4271_I2C
2411 + help
2412 + Say Y or M if you want to add support for audioinjector.net isolated soundcard
2413 +
2414 +config SND_AUDIOSENSE_PI
2415 + tristate "Support for AudioSense Add-On Soundcard"
2416 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2417 + select SND_SOC_TLV320AIC32X4_I2C
2418 + help
2419 + Say Y or M if you want to add support for tlv320aic32x4 add-on
2420 +
2421 +config SND_DIGIDAC1_SOUNDCARD
2422 + tristate "Support for Red Rocks Audio DigiDAC1"
2423 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2424 + select SND_SOC_WM8804
2425 + select SND_SOC_WM8741
2426 + help
2427 + Say Y or M if you want to add support for Red Rocks Audio DigiDAC1 board.
2428 +
2429 +config SND_BCM2708_SOC_DIONAUDIO_LOCO
2430 + tristate "Support for Dion Audio LOCO DAC-AMP"
2431 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2432 + select SND_SOC_PCM5102a
2433 + help
2434 + Say Y or M if you want to add support for Dion Audio LOCO.
2435 +
2436 +config SND_BCM2708_SOC_DIONAUDIO_LOCO_V2
2437 + tristate "Support for Dion Audio LOCO-V2 DAC-AMP"
2438 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2439 + select SND_SOC_PCM5122
2440 + help
2441 + Say Y or M if you want to add support for Dion Audio LOCO-V2.
2442 +
2443 +config SND_BCM2708_SOC_ALLO_PIANO_DAC
2444 + tristate "Support for Allo Piano DAC"
2445 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2446 + select SND_SOC_PCM512x_I2C
2447 + help
2448 + Say Y or M if you want to add support for Allo Piano DAC.
2449 +
2450 +config SND_BCM2708_SOC_ALLO_PIANO_DAC_PLUS
2451 + tristate "Support for Allo Piano DAC Plus"
2452 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2453 + select SND_SOC_PCM512x_I2C
2454 + help
2455 + Say Y or M if you want to add support for Allo Piano DAC Plus.
2456 +
2457 +config SND_BCM2708_SOC_ALLO_BOSS_DAC
2458 + tristate "Support for Allo Boss DAC"
2459 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2460 + select SND_SOC_PCM512x_I2C
2461 + help
2462 + Say Y or M if you want to add support for Allo Boss DAC.
2463 +
2464 +config SND_BCM2708_SOC_ALLO_BOSS2_DAC
2465 + tristate "Support for Allo Boss2 DAC"
2466 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2467 + depends on I2C
2468 + select REGMAP_I2C
2469 + select SND_AUDIO_GRAPH_CARD
2470 + help
2471 + Say Y or M if you want to add support for Allo Boss2 DAC.
2472 +
2473 +config SND_BCM2708_SOC_ALLO_DIGIONE
2474 + tristate "Support for Allo DigiOne"
2475 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2476 + select SND_SOC_WM8804
2477 + select SND_RPI_WM8804_SOUNDCARD
2478 + help
2479 + Say Y or M if you want to add support for Allo DigiOne.
2480 +
2481 +config SND_BCM2708_SOC_ALLO_KATANA_DAC
2482 + tristate "Support for Allo Katana DAC"
2483 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2484 + depends on I2C
2485 + select REGMAP_I2C
2486 + select SND_AUDIO_GRAPH_CARD
2487 + help
2488 + Say Y or M if you want to add support for Allo Katana DAC.
2489 +
2490 +config SND_BCM2708_SOC_FE_PI_AUDIO
2491 + tristate "Support for Fe-Pi-Audio"
2492 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2493 + select SND_SOC_SGTL5000
2494 + help
2495 + Say Y or M if you want to add support for Fe-Pi-Audio.
2496 +
2497 +config SND_PISOUND
2498 + tristate "Support for Blokas Labs pisound"
2499 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2500 + select SND_RAWMIDI
2501 + help
2502 + Say Y or M if you want to add support for Blokas Labs pisound.
2503 +
2504 +config SND_RPI_SIMPLE_SOUNDCARD
2505 + tristate "Support for Raspberry Pi simple soundcards"
2506 + help
2507 + Say Y or M if you want to add support Raspbery Pi simple soundcards
2508 +
2509 +config SND_RPI_WM8804_SOUNDCARD
2510 + tristate "Support for Raspberry Pi generic WM8804 soundcards"
2511 + help
2512 + Say Y or M if you want to add support for the Raspberry Pi
2513 + generic driver for WM8804 based soundcards.
2514 +
2515 +config SND_DACBERRY400
2516 + tristate "Support for DACBERRY400 Soundcard"
2517 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2518 + select SND_SOC_TLV320AIC3X_I2C
2519 + help
2520 + Say Y or M if you want to add support for tlv320aic3x add-on
2521 --- a/sound/soc/bcm/Makefile
2522 +++ b/sound/soc/bcm/Makefile
2523 @@ -12,4 +12,73 @@ obj-$(CONFIG_SND_SOC_CYGNUS) += snd-soc-
2524 # BCM63XX Platform Support
2525 snd-soc-63xx-objs := bcm63xx-i2s-whistler.o bcm63xx-pcm-whistler.o
2526
2527 -obj-$(CONFIG_SND_BCM63XX_I2S_WHISTLER) += snd-soc-63xx.o
2528 \ No newline at end of file
2529 +obj-$(CONFIG_SND_BCM63XX_I2S_WHISTLER) += snd-soc-63xx.o
2530 +
2531 +# Google voiceHAT custom codec support
2532 +snd-soc-googlevoicehat-codec-objs := googlevoicehat-codec.o
2533 +
2534 +# BCM2708 Machine Support
2535 +snd-soc-hifiberry-dacplus-objs := hifiberry_dacplus.o
2536 +snd-soc-hifiberry-dacplushd-objs := hifiberry_dacplushd.o
2537 +snd-soc-hifiberry-dacplusadc-objs := hifiberry_dacplusadc.o
2538 +snd-soc-hifiberry-dacplusadcpro-objs := hifiberry_dacplusadcpro.o
2539 +snd-soc-hifiberry-dacplusdsp-objs := hifiberry_dacplusdsp.o
2540 +snd-soc-justboom-both-objs := justboom-both.o
2541 +snd-soc-justboom-dac-objs := justboom-dac.o
2542 +snd-soc-rpi-cirrus-objs := rpi-cirrus.o
2543 +snd-soc-rpi-proto-objs := rpi-proto.o
2544 +snd-soc-iqaudio-codec-objs := iqaudio-codec.o
2545 +snd-soc-iqaudio-dac-objs := iqaudio-dac.o
2546 + snd-soc-i-sabre-q2m-objs := i-sabre-q2m.o
2547 +snd-soc-audioinjector-pi-soundcard-objs := audioinjector-pi-soundcard.o
2548 +snd-soc-audioinjector-octo-soundcard-objs := audioinjector-octo-soundcard.o
2549 +snd-soc-audioinjector-isolated-soundcard-objs := audioinjector-isolated-soundcard.o
2550 +snd-soc-audiosense-pi-objs := audiosense-pi.o
2551 +snd-soc-digidac1-soundcard-objs := digidac1-soundcard.o
2552 +snd-soc-dionaudio-loco-objs := dionaudio_loco.o
2553 +snd-soc-dionaudio-loco-v2-objs := dionaudio_loco-v2.o
2554 +snd-soc-allo-boss-dac-objs := allo-boss-dac.o
2555 +snd-soc-allo-boss2-dac-objs := allo-boss2-dac.o
2556 +snd-soc-allo-piano-dac-objs := allo-piano-dac.o
2557 +snd-soc-allo-piano-dac-plus-objs := allo-piano-dac-plus.o
2558 +snd-soc-allo-katana-codec-objs := allo-katana-codec.o
2559 +snd-soc-pisound-objs := pisound.o
2560 +snd-soc-fe-pi-audio-objs := fe-pi-audio.o
2561 +snd-soc-rpi-simple-soundcard-objs := rpi-simple-soundcard.o
2562 +snd-soc-rpi-wm8804-soundcard-objs := rpi-wm8804-soundcard.o
2563 +snd-soc-pifi-40-objs := pifi-40.o
2564 +snd-soc-chipdip-dac-objs := chipdip-dac.o
2565 +snd-soc-dacberry400-objs := dacberry400.o
2566 +
2567 +obj-$(CONFIG_SND_BCM2708_SOC_GOOGLEVOICEHAT_SOUNDCARD) += snd-soc-googlevoicehat-codec.o
2568 +obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS) += snd-soc-hifiberry-dacplus.o
2569 +obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUSHD) += snd-soc-hifiberry-dacplushd.o
2570 +obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUSADC) += snd-soc-hifiberry-dacplusadc.o
2571 +obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUSADCPRO) += snd-soc-hifiberry-dacplusadcpro.o
2572 +obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUSDSP) += snd-soc-hifiberry-dacplusdsp.o
2573 +obj-$(CONFIG_SND_BCM2708_SOC_JUSTBOOM_BOTH) += snd-soc-justboom-both.o
2574 +obj-$(CONFIG_SND_BCM2708_SOC_JUSTBOOM_DAC) += snd-soc-justboom-dac.o
2575 +obj-$(CONFIG_SND_BCM2708_SOC_RPI_CIRRUS) += snd-soc-rpi-cirrus.o
2576 +obj-$(CONFIG_SND_BCM2708_SOC_RPI_PROTO) += snd-soc-rpi-proto.o
2577 +obj-$(CONFIG_SND_BCM2708_SOC_IQAUDIO_CODEC) += snd-soc-iqaudio-codec.o
2578 +obj-$(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) += snd-soc-iqaudio-dac.o
2579 +obj-$(CONFIG_SND_BCM2708_SOC_I_SABRE_Q2M) += snd-soc-i-sabre-q2m.o
2580 +obj-$(CONFIG_SND_AUDIOINJECTOR_PI_SOUNDCARD) += snd-soc-audioinjector-pi-soundcard.o
2581 +obj-$(CONFIG_SND_AUDIOINJECTOR_OCTO_SOUNDCARD) += snd-soc-audioinjector-octo-soundcard.o
2582 +obj-$(CONFIG_SND_AUDIOINJECTOR_ISOLATED_SOUNDCARD) += snd-soc-audioinjector-isolated-soundcard.o
2583 +obj-$(CONFIG_SND_AUDIOSENSE_PI) += snd-soc-audiosense-pi.o
2584 +obj-$(CONFIG_SND_DIGIDAC1_SOUNDCARD) += snd-soc-digidac1-soundcard.o
2585 +obj-$(CONFIG_SND_BCM2708_SOC_DIONAUDIO_LOCO) += snd-soc-dionaudio-loco.o
2586 +obj-$(CONFIG_SND_BCM2708_SOC_DIONAUDIO_LOCO_V2) += snd-soc-dionaudio-loco-v2.o
2587 +obj-$(CONFIG_SND_BCM2708_SOC_ALLO_BOSS_DAC) += snd-soc-allo-boss-dac.o
2588 +obj-$(CONFIG_SND_BCM2708_SOC_ALLO_BOSS2_DAC) += snd-soc-allo-boss2-dac.o
2589 +obj-$(CONFIG_SND_BCM2708_SOC_ALLO_PIANO_DAC) += snd-soc-allo-piano-dac.o
2590 +obj-$(CONFIG_SND_BCM2708_SOC_ALLO_PIANO_DAC_PLUS) += snd-soc-allo-piano-dac-plus.o
2591 +obj-$(CONFIG_SND_BCM2708_SOC_ALLO_KATANA_DAC) += snd-soc-allo-katana-codec.o
2592 +obj-$(CONFIG_SND_PISOUND) += snd-soc-pisound.o
2593 +obj-$(CONFIG_SND_BCM2708_SOC_FE_PI_AUDIO) += snd-soc-fe-pi-audio.o
2594 +obj-$(CONFIG_SND_RPI_SIMPLE_SOUNDCARD) += snd-soc-rpi-simple-soundcard.o
2595 +obj-$(CONFIG_SND_RPI_WM8804_SOUNDCARD) += snd-soc-rpi-wm8804-soundcard.o
2596 +obj-$(CONFIG_SND_BCM2708_SOC_PIFI_40) += snd-soc-pifi-40.o
2597 +obj-$(CONFIG_SND_BCM2708_SOC_CHIPDIP_DAC) += snd-soc-chipdip-dac.o
2598 +obj-$(CONFIG_SND_DACBERRY400) += snd-soc-dacberry400.o
2599 --- /dev/null
2600 +++ b/sound/soc/bcm/allo-boss-dac.c
2601 @@ -0,0 +1,457 @@
2602 +/*
2603 + * ALSA ASoC Machine Driver for Allo Boss DAC
2604 + *
2605 + * Author: Baswaraj K <jaikumar@cem-solutions.net>
2606 + * Copyright 2017
2607 + * based on code by Daniel Matuschek,
2608 + * Stuart MacLean <stuart@hifiberry.com>
2609 + * based on code by Florian Meier <florian.meier@koalo.de>
2610 + *
2611 + * This program is free software; you can redistribute it and/or
2612 + * modify it under the terms of the GNU General Public License
2613 + * version 2 as published by the Free Software Foundation.
2614 + *
2615 + * This program is distributed in the hope that it will be useful, but
2616 + * WITHOUT ANY WARRANTY; without even the implied warranty of
2617 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2618 + * General Public License for more details.
2619 + */
2620 +
2621 +#include <linux/module.h>
2622 +#include <linux/gpio/consumer.h>
2623 +#include <linux/platform_device.h>
2624 +#include <linux/clk.h>
2625 +#include <linux/delay.h>
2626 +
2627 +#include <sound/core.h>
2628 +#include <sound/pcm.h>
2629 +#include <sound/pcm_params.h>
2630 +#include <sound/soc.h>
2631 +#include "../codecs/pcm512x.h"
2632 +
2633 +#define ALLO_BOSS_NOCLOCK 0
2634 +#define ALLO_BOSS_CLK44EN 1
2635 +#define ALLO_BOSS_CLK48EN 2
2636 +
2637 +struct pcm512x_priv {
2638 + struct regmap *regmap;
2639 + struct clk *sclk;
2640 +};
2641 +
2642 +static struct gpio_desc *mute_gpio;
2643 +
2644 +/* Clock rate of CLK44EN attached to GPIO6 pin */
2645 +#define CLK_44EN_RATE 45158400UL
2646 +/* Clock rate of CLK48EN attached to GPIO3 pin */
2647 +#define CLK_48EN_RATE 49152000UL
2648 +
2649 +static bool slave;
2650 +static bool snd_soc_allo_boss_master;
2651 +static bool digital_gain_0db_limit = true;
2652 +
2653 +static void snd_allo_boss_select_clk(struct snd_soc_component *component,
2654 + int clk_id)
2655 +{
2656 + switch (clk_id) {
2657 + case ALLO_BOSS_NOCLOCK:
2658 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x24, 0x00);
2659 + break;
2660 + case ALLO_BOSS_CLK44EN:
2661 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x24, 0x20);
2662 + break;
2663 + case ALLO_BOSS_CLK48EN:
2664 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x24, 0x04);
2665 + break;
2666 + }
2667 +}
2668 +
2669 +static void snd_allo_boss_clk_gpio(struct snd_soc_component *component)
2670 +{
2671 + snd_soc_component_update_bits(component, PCM512x_GPIO_EN, 0x24, 0x24);
2672 + snd_soc_component_update_bits(component, PCM512x_GPIO_OUTPUT_3, 0x0f, 0x02);
2673 + snd_soc_component_update_bits(component, PCM512x_GPIO_OUTPUT_6, 0x0f, 0x02);
2674 +}
2675 +
2676 +static bool snd_allo_boss_is_sclk(struct snd_soc_component *component)
2677 +{
2678 + unsigned int sck;
2679 +
2680 + sck = snd_soc_component_read(component, PCM512x_RATE_DET_4);
2681 + return (!(sck & 0x40));
2682 +}
2683 +
2684 +static bool snd_allo_boss_is_sclk_sleep(
2685 + struct snd_soc_component *component)
2686 +{
2687 + msleep(2);
2688 + return snd_allo_boss_is_sclk(component);
2689 +}
2690 +
2691 +static bool snd_allo_boss_is_master_card(struct snd_soc_component *component)
2692 +{
2693 + bool isClk44EN, isClk48En, isNoClk;
2694 +
2695 + snd_allo_boss_clk_gpio(component);
2696 +
2697 + snd_allo_boss_select_clk(component, ALLO_BOSS_CLK44EN);
2698 + isClk44EN = snd_allo_boss_is_sclk_sleep(component);
2699 +
2700 + snd_allo_boss_select_clk(component, ALLO_BOSS_NOCLOCK);
2701 + isNoClk = snd_allo_boss_is_sclk_sleep(component);
2702 +
2703 + snd_allo_boss_select_clk(component, ALLO_BOSS_CLK48EN);
2704 + isClk48En = snd_allo_boss_is_sclk_sleep(component);
2705 +
2706 + return (isClk44EN && isClk48En && !isNoClk);
2707 +}
2708 +
2709 +static int snd_allo_boss_clk_for_rate(int sample_rate)
2710 +{
2711 + int type;
2712 +
2713 + switch (sample_rate) {
2714 + case 11025:
2715 + case 22050:
2716 + case 44100:
2717 + case 88200:
2718 + case 176400:
2719 + case 352800:
2720 + type = ALLO_BOSS_CLK44EN;
2721 + break;
2722 + default:
2723 + type = ALLO_BOSS_CLK48EN;
2724 + break;
2725 + }
2726 + return type;
2727 +}
2728 +
2729 +static void snd_allo_boss_set_sclk(struct snd_soc_component *component,
2730 + int sample_rate)
2731 +{
2732 + struct pcm512x_priv *pcm512x = snd_soc_component_get_drvdata(component);
2733 +
2734 + if (!IS_ERR(pcm512x->sclk)) {
2735 + int ctype;
2736 +
2737 + ctype = snd_allo_boss_clk_for_rate(sample_rate);
2738 + clk_set_rate(pcm512x->sclk, (ctype == ALLO_BOSS_CLK44EN)
2739 + ? CLK_44EN_RATE : CLK_48EN_RATE);
2740 + snd_allo_boss_select_clk(component, ctype);
2741 + }
2742 +}
2743 +
2744 +static int snd_allo_boss_init(struct snd_soc_pcm_runtime *rtd)
2745 +{
2746 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
2747 + struct pcm512x_priv *priv = snd_soc_component_get_drvdata(component);
2748 +
2749 + if (slave)
2750 + snd_soc_allo_boss_master = false;
2751 + else
2752 + snd_soc_allo_boss_master =
2753 + snd_allo_boss_is_master_card(component);
2754 +
2755 + if (snd_soc_allo_boss_master) {
2756 + struct snd_soc_dai_link *dai = rtd->dai_link;
2757 +
2758 + dai->name = "BossDAC";
2759 + dai->stream_name = "Boss DAC HiFi [Master]";
2760 + dai->dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
2761 + | SND_SOC_DAIFMT_CBM_CFM;
2762 +
2763 + snd_soc_component_update_bits(component, PCM512x_BCLK_LRCLK_CFG, 0x31, 0x11);
2764 + snd_soc_component_update_bits(component, PCM512x_MASTER_MODE, 0x03, 0x03);
2765 + snd_soc_component_update_bits(component, PCM512x_MASTER_CLKDIV_2, 0x7f, 63);
2766 + /*
2767 + * Default sclk to CLK_48EN_RATE, otherwise codec
2768 + * pcm512x_dai_startup_master method could call
2769 + * snd_pcm_hw_constraint_ratnums using CLK_44EN/64
2770 + * which will mask 384k sample rate.
2771 + */
2772 + if (!IS_ERR(priv->sclk))
2773 + clk_set_rate(priv->sclk, CLK_48EN_RATE);
2774 + } else {
2775 + priv->sclk = ERR_PTR(-ENOENT);
2776 + }
2777 +
2778 + snd_soc_component_update_bits(component, PCM512x_GPIO_EN, 0x08, 0x08);
2779 + snd_soc_component_update_bits(component, PCM512x_GPIO_OUTPUT_4, 0x0f, 0x02);
2780 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x08, 0x08);
2781 +
2782 + if (digital_gain_0db_limit) {
2783 + int ret;
2784 + struct snd_soc_card *card = rtd->card;
2785 +
2786 + ret = snd_soc_limit_volume(card, "Digital Playback Volume",
2787 + 207);
2788 + if (ret < 0)
2789 + dev_warn(card->dev, "Failed to set volume limit: %d\n",
2790 + ret);
2791 + }
2792 +
2793 + return 0;
2794 +}
2795 +
2796 +static int snd_allo_boss_update_rate_den(
2797 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
2798 +{
2799 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
2800 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
2801 + struct pcm512x_priv *pcm512x = snd_soc_component_get_drvdata(component);
2802 + struct snd_ratnum *rats_no_pll;
2803 + unsigned int num = 0, den = 0;
2804 + int err;
2805 +
2806 + rats_no_pll = devm_kzalloc(rtd->dev, sizeof(*rats_no_pll), GFP_KERNEL);
2807 + if (!rats_no_pll)
2808 + return -ENOMEM;
2809 +
2810 + rats_no_pll->num = clk_get_rate(pcm512x->sclk) / 64;
2811 + rats_no_pll->den_min = 1;
2812 + rats_no_pll->den_max = 128;
2813 + rats_no_pll->den_step = 1;
2814 +
2815 + err = snd_interval_ratnum(hw_param_interval(params,
2816 + SNDRV_PCM_HW_PARAM_RATE), 1, rats_no_pll, &num, &den);
2817 + if (err >= 0 && den) {
2818 + params->rate_num = num;
2819 + params->rate_den = den;
2820 + }
2821 +
2822 + devm_kfree(rtd->dev, rats_no_pll);
2823 + return 0;
2824 +}
2825 +
2826 +static void snd_allo_boss_gpio_mute(struct snd_soc_card *card)
2827 +{
2828 + if (mute_gpio)
2829 + gpiod_set_value_cansleep(mute_gpio, 1);
2830 +}
2831 +
2832 +static void snd_allo_boss_gpio_unmute(struct snd_soc_card *card)
2833 +{
2834 + if (mute_gpio)
2835 + gpiod_set_value_cansleep(mute_gpio, 0);
2836 +}
2837 +
2838 +static int snd_allo_boss_set_bias_level(struct snd_soc_card *card,
2839 + struct snd_soc_dapm_context *dapm, enum snd_soc_bias_level level)
2840 +{
2841 + struct snd_soc_pcm_runtime *rtd;
2842 + struct snd_soc_dai *codec_dai;
2843 +
2844 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
2845 + codec_dai = asoc_rtd_to_codec(rtd, 0);
2846 +
2847 + if (dapm->dev != codec_dai->dev)
2848 + return 0;
2849 +
2850 + switch (level) {
2851 + case SND_SOC_BIAS_PREPARE:
2852 + if (dapm->bias_level != SND_SOC_BIAS_STANDBY)
2853 + break;
2854 + /* UNMUTE DAC */
2855 + snd_allo_boss_gpio_unmute(card);
2856 + break;
2857 +
2858 + case SND_SOC_BIAS_STANDBY:
2859 + if (dapm->bias_level != SND_SOC_BIAS_PREPARE)
2860 + break;
2861 + /* MUTE DAC */
2862 + snd_allo_boss_gpio_mute(card);
2863 + break;
2864 +
2865 + default:
2866 + break;
2867 + }
2868 +
2869 + return 0;
2870 +}
2871 +
2872 +static int snd_allo_boss_hw_params(
2873 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
2874 +{
2875 + int ret = 0;
2876 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
2877 + int channels = params_channels(params);
2878 + int width = snd_pcm_format_physical_width(params_format(params));
2879 +
2880 + if (snd_soc_allo_boss_master) {
2881 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
2882 +
2883 + snd_allo_boss_set_sclk(component,
2884 + params_rate(params));
2885 +
2886 + ret = snd_allo_boss_update_rate_den(
2887 + substream, params);
2888 + if (ret)
2889 + return ret;
2890 + }
2891 +
2892 + ret = snd_soc_dai_set_bclk_ratio(asoc_rtd_to_cpu(rtd, 0), channels * width);
2893 + if (ret)
2894 + return ret;
2895 + ret = snd_soc_dai_set_bclk_ratio(asoc_rtd_to_codec(rtd, 0), channels * width);
2896 + return ret;
2897 +}
2898 +
2899 +static int snd_allo_boss_startup(
2900 + struct snd_pcm_substream *substream)
2901 +{
2902 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
2903 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
2904 + struct snd_soc_card *card = rtd->card;
2905 +
2906 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x08, 0x08);
2907 + snd_allo_boss_gpio_mute(card);
2908 +
2909 + if (snd_soc_allo_boss_master) {
2910 + struct pcm512x_priv *priv = snd_soc_component_get_drvdata(component);
2911 + /*
2912 + * Default sclk to CLK_48EN_RATE, otherwise codec
2913 + * pcm512x_dai_startup_master method could call
2914 + * snd_pcm_hw_constraint_ratnums using CLK_44EN/64
2915 + * which will mask 384k sample rate.
2916 + */
2917 + if (!IS_ERR(priv->sclk))
2918 + clk_set_rate(priv->sclk, CLK_48EN_RATE);
2919 + }
2920 +
2921 + return 0;
2922 +}
2923 +
2924 +static void snd_allo_boss_shutdown(
2925 + struct snd_pcm_substream *substream)
2926 +{
2927 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
2928 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
2929 +
2930 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x08, 0x00);
2931 +}
2932 +
2933 +static int snd_allo_boss_prepare(
2934 + struct snd_pcm_substream *substream)
2935 +{
2936 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
2937 + struct snd_soc_card *card = rtd->card;
2938 +
2939 + snd_allo_boss_gpio_unmute(card);
2940 + return 0;
2941 +}
2942 +/* machine stream operations */
2943 +static struct snd_soc_ops snd_allo_boss_ops = {
2944 + .hw_params = snd_allo_boss_hw_params,
2945 + .startup = snd_allo_boss_startup,
2946 + .shutdown = snd_allo_boss_shutdown,
2947 + .prepare = snd_allo_boss_prepare,
2948 +};
2949 +
2950 +SND_SOC_DAILINK_DEFS(allo_boss,
2951 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
2952 + DAILINK_COMP_ARRAY(COMP_CODEC("pcm512x.1-004d", "pcm512x-hifi")),
2953 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
2954 +
2955 +static struct snd_soc_dai_link snd_allo_boss_dai[] = {
2956 +{
2957 + .name = "Boss DAC",
2958 + .stream_name = "Boss DAC HiFi",
2959 + .dai_fmt = SND_SOC_DAIFMT_I2S |
2960 + SND_SOC_DAIFMT_NB_NF |
2961 + SND_SOC_DAIFMT_CBS_CFS,
2962 + .ops = &snd_allo_boss_ops,
2963 + .init = snd_allo_boss_init,
2964 + SND_SOC_DAILINK_REG(allo_boss),
2965 +},
2966 +};
2967 +
2968 +/* audio machine driver */
2969 +static struct snd_soc_card snd_allo_boss = {
2970 + .name = "BossDAC",
2971 + .owner = THIS_MODULE,
2972 + .dai_link = snd_allo_boss_dai,
2973 + .num_links = ARRAY_SIZE(snd_allo_boss_dai),
2974 +};
2975 +
2976 +static int snd_allo_boss_probe(struct platform_device *pdev)
2977 +{
2978 + int ret = 0;
2979 +
2980 + snd_allo_boss.dev = &pdev->dev;
2981 +
2982 + if (pdev->dev.of_node) {
2983 + struct device_node *i2s_node;
2984 + struct snd_soc_dai_link *dai;
2985 +
2986 + dai = &snd_allo_boss_dai[0];
2987 + i2s_node = of_parse_phandle(pdev->dev.of_node,
2988 + "i2s-controller", 0);
2989 +
2990 + if (i2s_node) {
2991 + dai->cpus->dai_name = NULL;
2992 + dai->cpus->of_node = i2s_node;
2993 + dai->platforms->name = NULL;
2994 + dai->platforms->of_node = i2s_node;
2995 + }
2996 +
2997 + digital_gain_0db_limit = !of_property_read_bool(
2998 + pdev->dev.of_node, "allo,24db_digital_gain");
2999 + slave = of_property_read_bool(pdev->dev.of_node,
3000 + "allo,slave");
3001 +
3002 + mute_gpio = devm_gpiod_get_optional(&pdev->dev, "mute",
3003 + GPIOD_OUT_LOW);
3004 + if (IS_ERR(mute_gpio)) {
3005 + ret = PTR_ERR(mute_gpio);
3006 + dev_err(&pdev->dev,
3007 + "failed to get mute gpio: %d\n", ret);
3008 + return ret;
3009 + }
3010 +
3011 + if (mute_gpio)
3012 + snd_allo_boss.set_bias_level =
3013 + snd_allo_boss_set_bias_level;
3014 +
3015 + ret = snd_soc_register_card(&snd_allo_boss);
3016 + if (ret) {
3017 + dev_err(&pdev->dev,
3018 + "snd_soc_register_card() failed: %d\n", ret);
3019 + return ret;
3020 + }
3021 +
3022 + if (mute_gpio)
3023 + snd_allo_boss_gpio_mute(&snd_allo_boss);
3024 +
3025 + return 0;
3026 + }
3027 +
3028 + return -EINVAL;
3029 +}
3030 +
3031 +static int snd_allo_boss_remove(struct platform_device *pdev)
3032 +{
3033 + snd_allo_boss_gpio_mute(&snd_allo_boss);
3034 + snd_soc_unregister_card(&snd_allo_boss);
3035 + return 0;
3036 +}
3037 +
3038 +static const struct of_device_id snd_allo_boss_of_match[] = {
3039 + { .compatible = "allo,boss-dac", },
3040 + { /* sentinel */ },
3041 +};
3042 +MODULE_DEVICE_TABLE(of, snd_allo_boss_of_match);
3043 +
3044 +static struct platform_driver snd_allo_boss_driver = {
3045 + .driver = {
3046 + .name = "snd-allo-boss-dac",
3047 + .owner = THIS_MODULE,
3048 + .of_match_table = snd_allo_boss_of_match,
3049 + },
3050 + .probe = snd_allo_boss_probe,
3051 + .remove = snd_allo_boss_remove,
3052 +};
3053 +
3054 +module_platform_driver(snd_allo_boss_driver);
3055 +
3056 +MODULE_AUTHOR("Baswaraj K <jaikumar@cem-solutions.net>");
3057 +MODULE_DESCRIPTION("ALSA ASoC Machine Driver for Allo Boss DAC");
3058 +MODULE_LICENSE("GPL v2");
3059 --- /dev/null
3060 +++ b/sound/soc/bcm/allo-boss2-dac.c
3061 @@ -0,0 +1,1131 @@
3062 +/*
3063 + * Driver for the ALLO KATANA CODEC
3064 + *
3065 + * Author: Jaikumar <sudeepkumar@cem-solutions.net>
3066 + * Copyright 2018
3067 + *
3068 + * This program is free software; you can redistribute it and/or
3069 + * modify it under the terms of the GNU General Public License
3070 + * version 2 as published by the Free Software Foundation.
3071 + *
3072 + * This program is distributed in the hope that it will be useful, but
3073 + * WITHOUT ANY WARRANTY; without even the implied warranty of
3074 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3075 + * General Public License for more details.
3076 + */
3077 +
3078 +#include <linux/module.h>
3079 +#include <linux/moduleparam.h>
3080 +#include <linux/kernel.h>
3081 +#include <linux/init.h>
3082 +#include <linux/delay.h>
3083 +#include <linux/gpio.h>
3084 +#include <linux/gpio/consumer.h>
3085 +#include <linux/platform_device.h>
3086 +#include <linux/pm.h>
3087 +#include <linux/i2c.h>
3088 +#include <linux/of_device.h>
3089 +#include <linux/regmap.h>
3090 +#include <linux/slab.h>
3091 +#include <sound/core.h>
3092 +#include <sound/pcm.h>
3093 +#include <sound/pcm_params.h>
3094 +#include <sound/soc.h>
3095 +#include <sound/soc-dapm.h>
3096 +#include <sound/initval.h>
3097 +#include <sound/tlv.h>
3098 +#include <linux/of_gpio.h>
3099 +#include <linux/regulator/consumer.h>
3100 +#include <linux/pm_runtime.h>
3101 +#include <linux/of_irq.h>
3102 +#include <linux/completion.h>
3103 +#include <linux/mutex.h>
3104 +#include <linux/workqueue.h>
3105 +#include <sound/jack.h>
3106 +
3107 +#include "../codecs/cs43130.h"
3108 +
3109 +#include <linux/clk.h>
3110 +#include <linux/gcd.h>
3111 +#define DEBUG
3112 +
3113 +#define CS43130_DSD_EN_MASK 0x10
3114 +#define CS43130_PDN_DONE_INT_MASK 0x00
3115 +
3116 +static struct gpio_desc *snd_allo_clk44gpio;
3117 +static struct gpio_desc *snd_allo_clk48gpio;
3118 +
3119 +struct cs43130_priv {
3120 + struct snd_soc_component *component;
3121 + struct regmap *regmap;
3122 + struct regulator_bulk_data supplies[CS43130_NUM_SUPPLIES];
3123 + struct gpio_desc *reset_gpio;
3124 + unsigned int dev_id; /* codec device ID */
3125 + int xtal_ibias;
3126 + /* shared by both DAIs */
3127 + struct mutex clk_mutex;
3128 + int clk_req;
3129 + bool pll_bypass;
3130 + struct completion xtal_rdy;
3131 + struct completion pll_rdy;
3132 + unsigned int mclk;
3133 + unsigned int mclk_int;
3134 + int mclk_int_src;
3135 +
3136 + /* DAI specific */
3137 + struct cs43130_dai dais[CS43130_DAI_ID_MAX];
3138 +
3139 + /* HP load specific */
3140 + bool dc_meas;
3141 + bool ac_meas;
3142 + bool hpload_done;
3143 + struct completion hpload_evt;
3144 + unsigned int hpload_stat;
3145 + u16 hpload_dc[2];
3146 + u16 dc_threshold[CS43130_DC_THRESHOLD];
3147 + u16 ac_freq[CS43130_AC_FREQ];
3148 + u16 hpload_ac[CS43130_AC_FREQ][2];
3149 + struct workqueue_struct *wq;
3150 + struct work_struct work;
3151 + struct snd_soc_jack jack;
3152 +};
3153 +
3154 +static const struct reg_default cs43130_reg_defaults[] = {
3155 + {CS43130_SYS_CLK_CTL_1, 0x06},
3156 + {CS43130_SP_SRATE, 0x01},
3157 + {CS43130_SP_BITSIZE, 0x05},
3158 + {CS43130_PAD_INT_CFG, 0x03},
3159 + {CS43130_PWDN_CTL, 0xFE},
3160 + {CS43130_CRYSTAL_SET, 0x04},
3161 + {CS43130_PLL_SET_1, 0x00},
3162 + {CS43130_PLL_SET_2, 0x00},
3163 + {CS43130_PLL_SET_3, 0x00},
3164 + {CS43130_PLL_SET_4, 0x00},
3165 + {CS43130_PLL_SET_5, 0x40},
3166 + {CS43130_PLL_SET_6, 0x10},
3167 + {CS43130_PLL_SET_7, 0x80},
3168 + {CS43130_PLL_SET_8, 0x03},
3169 + {CS43130_PLL_SET_9, 0x02},
3170 + {CS43130_PLL_SET_10, 0x02},
3171 + {CS43130_CLKOUT_CTL, 0x00},
3172 + {CS43130_ASP_NUM_1, 0x01},
3173 + {CS43130_ASP_NUM_2, 0x00},
3174 + {CS43130_ASP_DEN_1, 0x08},
3175 + {CS43130_ASP_DEN_2, 0x00},
3176 + {CS43130_ASP_LRCK_HI_TIME_1, 0x1F},
3177 + {CS43130_ASP_LRCK_HI_TIME_2, 0x00},
3178 + {CS43130_ASP_LRCK_PERIOD_1, 0x3F},
3179 + {CS43130_ASP_LRCK_PERIOD_2, 0x00},
3180 + {CS43130_ASP_CLOCK_CONF, 0x0C},
3181 + {CS43130_ASP_FRAME_CONF, 0x0A},
3182 + {CS43130_XSP_NUM_1, 0x01},
3183 + {CS43130_XSP_NUM_2, 0x00},
3184 + {CS43130_XSP_DEN_1, 0x02},
3185 + {CS43130_XSP_DEN_2, 0x00},
3186 + {CS43130_XSP_LRCK_HI_TIME_1, 0x1F},
3187 + {CS43130_XSP_LRCK_HI_TIME_2, 0x00},
3188 + {CS43130_XSP_LRCK_PERIOD_1, 0x3F},
3189 + {CS43130_XSP_LRCK_PERIOD_2, 0x00},
3190 + {CS43130_XSP_CLOCK_CONF, 0x0C},
3191 + {CS43130_XSP_FRAME_CONF, 0x0A},
3192 + {CS43130_ASP_CH_1_LOC, 0x00},
3193 + {CS43130_ASP_CH_2_LOC, 0x00},
3194 + {CS43130_ASP_CH_1_SZ_EN, 0x06},
3195 + {CS43130_ASP_CH_2_SZ_EN, 0x0E},
3196 + {CS43130_XSP_CH_1_LOC, 0x00},
3197 + {CS43130_XSP_CH_2_LOC, 0x00},
3198 + {CS43130_XSP_CH_1_SZ_EN, 0x06},
3199 + {CS43130_XSP_CH_2_SZ_EN, 0x0E},
3200 + {CS43130_DSD_VOL_B, 0x78},
3201 + {CS43130_DSD_VOL_A, 0x78},
3202 + {CS43130_DSD_PATH_CTL_1, 0xA8},
3203 + {CS43130_DSD_INT_CFG, 0x00},
3204 + {CS43130_DSD_PATH_CTL_2, 0x02},
3205 + {CS43130_DSD_PCM_MIX_CTL, 0x00},
3206 + {CS43130_DSD_PATH_CTL_3, 0x40},
3207 + {CS43130_HP_OUT_CTL_1, 0x30},
3208 + {CS43130_PCM_FILT_OPT, 0x02},
3209 + {CS43130_PCM_VOL_B, 0x78},
3210 + {CS43130_PCM_VOL_A, 0x78},
3211 + {CS43130_PCM_PATH_CTL_1, 0xA8},
3212 + {CS43130_PCM_PATH_CTL_2, 0x00},
3213 + {CS43130_CLASS_H_CTL, 0x1E},
3214 + {CS43130_HP_DETECT, 0x04},
3215 + {CS43130_HP_LOAD_1, 0x00},
3216 + {CS43130_HP_MEAS_LOAD_1, 0x00},
3217 + {CS43130_HP_MEAS_LOAD_2, 0x00},
3218 + {CS43130_INT_MASK_1, 0xFF},
3219 + {CS43130_INT_MASK_2, 0xFF},
3220 + {CS43130_INT_MASK_3, 0xFF},
3221 + {CS43130_INT_MASK_4, 0xFF},
3222 + {CS43130_INT_MASK_5, 0xFF},
3223 +};
3224 +static bool cs43130_volatile_register(struct device *dev, unsigned int reg)
3225 +{
3226 + switch (reg) {
3227 + case CS43130_INT_STATUS_1 ... CS43130_INT_STATUS_5:
3228 + case CS43130_HP_DC_STAT_1 ... CS43130_HP_DC_STAT_2:
3229 + case CS43130_HP_AC_STAT_1 ... CS43130_HP_AC_STAT_2:
3230 + return true;
3231 + default:
3232 + return false;
3233 + }
3234 +}
3235 +
3236 +static const char * const pcm_spd_texts[] = {
3237 + "Fast",
3238 + "Slow",
3239 +};
3240 +
3241 +static SOC_ENUM_SINGLE_DECL(pcm_spd_enum, CS43130_PCM_FILT_OPT, 7,
3242 + pcm_spd_texts);
3243 +
3244 +static const SNDRV_CTL_TLVD_DECLARE_DB_MINMAX(master_tlv, -12750, 0);
3245 +
3246 +static const struct snd_kcontrol_new cs43130_controls[] = {
3247 + SOC_DOUBLE_R_TLV("Master Playback Volume", CS43130_PCM_VOL_B,
3248 + CS43130_PCM_VOL_A, 0, 255, 1, master_tlv),
3249 + SOC_DOUBLE("Master Playback Switch", CS43130_PCM_PATH_CTL_1,
3250 + 0, 1, 1, 1),
3251 + SOC_DOUBLE_R_TLV("Digital Playback Volume", CS43130_DSD_VOL_B,
3252 + CS43130_DSD_VOL_A, 0, 255, 1, master_tlv),
3253 + SOC_DOUBLE("Digital Playback Switch", CS43130_DSD_PATH_CTL_1,
3254 + 0, 1, 1, 1),
3255 + SOC_SINGLE("HV_Enable", CS43130_HP_OUT_CTL_1, 0, 1, 0),
3256 + SOC_ENUM("PCM Filter Speed", pcm_spd_enum),
3257 + SOC_SINGLE("PCM Phase Compensation", CS43130_PCM_FILT_OPT, 6, 1, 0),
3258 + SOC_SINGLE("PCM Nonoversample Emulate", CS43130_PCM_FILT_OPT, 5, 1, 0),
3259 + SOC_SINGLE("PCM High-pass Filter", CS43130_PCM_FILT_OPT, 1, 1, 0),
3260 + SOC_SINGLE("PCM De-emphasis Filter", CS43130_PCM_FILT_OPT, 0, 1, 0),
3261 +};
3262 +
3263 +static bool cs43130_readable_register(struct device *dev, unsigned int reg)
3264 +{
3265 + switch (reg) {
3266 + case CS43130_DEVID_AB ... CS43130_SYS_CLK_CTL_1:
3267 + case CS43130_SP_SRATE ... CS43130_PAD_INT_CFG:
3268 + case CS43130_PWDN_CTL:
3269 + case CS43130_CRYSTAL_SET:
3270 + case CS43130_PLL_SET_1 ... CS43130_PLL_SET_5:
3271 + case CS43130_PLL_SET_6:
3272 + case CS43130_PLL_SET_7:
3273 + case CS43130_PLL_SET_8:
3274 + case CS43130_PLL_SET_9:
3275 + case CS43130_PLL_SET_10:
3276 + case CS43130_CLKOUT_CTL:
3277 + case CS43130_ASP_NUM_1 ... CS43130_ASP_FRAME_CONF:
3278 + case CS43130_XSP_NUM_1 ... CS43130_XSP_FRAME_CONF:
3279 + case CS43130_ASP_CH_1_LOC:
3280 + case CS43130_ASP_CH_2_LOC:
3281 + case CS43130_ASP_CH_1_SZ_EN:
3282 + case CS43130_ASP_CH_2_SZ_EN:
3283 + case CS43130_XSP_CH_1_LOC:
3284 + case CS43130_XSP_CH_2_LOC:
3285 + case CS43130_XSP_CH_1_SZ_EN:
3286 + case CS43130_XSP_CH_2_SZ_EN:
3287 + case CS43130_DSD_VOL_B ... CS43130_DSD_PATH_CTL_3:
3288 + case CS43130_HP_OUT_CTL_1:
3289 + case CS43130_PCM_FILT_OPT ... CS43130_PCM_PATH_CTL_2:
3290 + case CS43130_CLASS_H_CTL:
3291 + case CS43130_HP_DETECT:
3292 + case CS43130_HP_STATUS:
3293 + case CS43130_HP_LOAD_1:
3294 + case CS43130_HP_MEAS_LOAD_1:
3295 + case CS43130_HP_MEAS_LOAD_2:
3296 + case CS43130_HP_DC_STAT_1:
3297 + case CS43130_HP_DC_STAT_2:
3298 + case CS43130_HP_AC_STAT_1:
3299 + case CS43130_HP_AC_STAT_2:
3300 + case CS43130_HP_LOAD_STAT:
3301 + case CS43130_INT_STATUS_1 ... CS43130_INT_STATUS_5:
3302 + case CS43130_INT_MASK_1 ... CS43130_INT_MASK_5:
3303 + return true;
3304 + default:
3305 + return false;
3306 + }
3307 +}
3308 +static bool cs43130_precious_register(struct device *dev, unsigned int reg)
3309 +{
3310 + switch (reg) {
3311 + case CS43130_INT_STATUS_1 ... CS43130_INT_STATUS_5:
3312 + return true;
3313 + default:
3314 + return false;
3315 + }
3316 +}
3317 +static int cs43130_pcm_pdn(struct snd_soc_component *component)
3318 +{
3319 + struct cs43130_priv *cs43130 =
3320 + snd_soc_component_get_drvdata(component);
3321 + int ret;
3322 + unsigned int reg, pdn_int;
3323 +
3324 + regmap_write(cs43130->regmap, CS43130_DSD_PATH_CTL_2, 0x02);
3325 + regmap_update_bits(cs43130->regmap, CS43130_INT_MASK_1,
3326 + CS43130_PDN_DONE_INT_MASK, 0);
3327 + regmap_update_bits(cs43130->regmap, CS43130_PWDN_CTL,
3328 + CS43130_PDN_HP_MASK, 1 << CS43130_PDN_HP_SHIFT);
3329 + usleep_range(10, 50);
3330 + ret = regmap_read(cs43130->regmap, CS43130_INT_STATUS_1, &reg);
3331 + pdn_int = reg & 0xFE;
3332 + regmap_update_bits(cs43130->regmap, CS43130_PWDN_CTL,
3333 + CS43130_PDN_ASP_MASK, 1 << CS43130_PDN_ASP_SHIFT);
3334 + return 0;
3335 +
3336 +}
3337 +static int cs43130_pwr_up_asp_dac(struct snd_soc_component *component)
3338 +{
3339 + struct cs43130_priv *cs43130 =
3340 + snd_soc_component_get_drvdata(component);
3341 +
3342 + regmap_update_bits(cs43130->regmap, CS43130_PAD_INT_CFG,
3343 + CS43130_ASP_3ST_MASK, 0);
3344 + regmap_write(cs43130->regmap, CS43130_DXD1, 0x99);
3345 + regmap_write(cs43130->regmap, CS43130_DXD13, 0x20);
3346 + regmap_update_bits(cs43130->regmap, CS43130_PWDN_CTL,
3347 + CS43130_PDN_ASP_MASK, 0);
3348 + regmap_update_bits(cs43130->regmap, CS43130_PWDN_CTL,
3349 + CS43130_PDN_HP_MASK, 0);
3350 + usleep_range(10000, 12000);
3351 + regmap_write(cs43130->regmap, CS43130_DXD1, 0x00);
3352 + regmap_write(cs43130->regmap, CS43130_DXD13, 0x00);
3353 + return 0;
3354 +}
3355 +static int cs43130_change_clksrc(struct snd_soc_component *component,
3356 + enum cs43130_mclk_src_sel src)
3357 +{
3358 + int ret;
3359 + struct cs43130_priv *cs43130 =
3360 + snd_soc_component_get_drvdata(component);
3361 + int mclk_int_decoded;
3362 +
3363 + if (src == cs43130->mclk_int_src) {
3364 + /* clk source has not changed */
3365 + return 0;
3366 + }
3367 + switch (cs43130->mclk_int) {
3368 + case CS43130_MCLK_22M:
3369 + mclk_int_decoded = CS43130_MCLK_22P5;
3370 + break;
3371 + case CS43130_MCLK_24M:
3372 + mclk_int_decoded = CS43130_MCLK_24P5;
3373 + break;
3374 + default:
3375 + dev_err(component->dev, "Invalid MCLK INT freq: %u\n",
3376 + cs43130->mclk_int);
3377 + return -EINVAL;
3378 + }
3379 +
3380 + switch (src) {
3381 + case CS43130_MCLK_SRC_EXT:
3382 + cs43130->pll_bypass = true;
3383 + cs43130->mclk_int_src = CS43130_MCLK_SRC_EXT;
3384 + if (cs43130->xtal_ibias == CS43130_XTAL_UNUSED) {
3385 + regmap_update_bits(cs43130->regmap, CS43130_PWDN_CTL,
3386 + CS43130_PDN_XTAL_MASK,
3387 + 1 << CS43130_PDN_XTAL_SHIFT);
3388 + } else {
3389 + reinit_completion(&cs43130->xtal_rdy);
3390 + regmap_update_bits(cs43130->regmap, CS43130_INT_MASK_1,
3391 + CS43130_XTAL_RDY_INT_MASK, 0);
3392 + regmap_update_bits(cs43130->regmap, CS43130_PWDN_CTL,
3393 + CS43130_PDN_XTAL_MASK, 0);
3394 + ret = wait_for_completion_timeout(&cs43130->xtal_rdy,
3395 + msecs_to_jiffies(100));
3396 + regmap_update_bits(cs43130->regmap, CS43130_INT_MASK_1,
3397 + CS43130_XTAL_RDY_INT_MASK,
3398 + 1 << CS43130_XTAL_RDY_INT_SHIFT);
3399 + if (ret == 0) {
3400 + dev_err(component->dev, "Timeout waiting for XTAL_READY interrupt\n");
3401 + return -ETIMEDOUT;
3402 + }
3403 + }
3404 + regmap_update_bits(cs43130->regmap, CS43130_SYS_CLK_CTL_1,
3405 + CS43130_MCLK_SRC_SEL_MASK,
3406 + src << CS43130_MCLK_SRC_SEL_SHIFT);
3407 + regmap_update_bits(cs43130->regmap, CS43130_SYS_CLK_CTL_1,
3408 + CS43130_MCLK_INT_MASK,
3409 + mclk_int_decoded << CS43130_MCLK_INT_SHIFT);
3410 + usleep_range(150, 200);
3411 + regmap_update_bits(cs43130->regmap, CS43130_PWDN_CTL,
3412 + CS43130_PDN_PLL_MASK,
3413 + 1 << CS43130_PDN_PLL_SHIFT);
3414 + break;
3415 + case CS43130_MCLK_SRC_RCO:
3416 + cs43130->mclk_int_src = CS43130_MCLK_SRC_RCO;
3417 +
3418 + regmap_update_bits(cs43130->regmap, CS43130_SYS_CLK_CTL_1,
3419 + CS43130_MCLK_SRC_SEL_MASK,
3420 + src << CS43130_MCLK_SRC_SEL_SHIFT);
3421 + regmap_update_bits(cs43130->regmap, CS43130_SYS_CLK_CTL_1,
3422 + CS43130_MCLK_INT_MASK,
3423 + CS43130_MCLK_22P5 << CS43130_MCLK_INT_SHIFT);
3424 + usleep_range(150, 200);
3425 + regmap_update_bits(cs43130->regmap, CS43130_PWDN_CTL,
3426 + CS43130_PDN_XTAL_MASK,
3427 + 1 << CS43130_PDN_XTAL_SHIFT);
3428 + regmap_update_bits(cs43130->regmap, CS43130_PWDN_CTL,
3429 + CS43130_PDN_PLL_MASK,
3430 + 1 << CS43130_PDN_PLL_SHIFT);
3431 + break;
3432 + default:
3433 + dev_err(component->dev, "Invalid MCLK source value\n");
3434 + return -EINVAL;
3435 + }
3436 +
3437 + return 0;
3438 +}
3439 +static const struct cs43130_bitwidth_map cs43130_bitwidth_table[] = {
3440 + {8, CS43130_SP_BIT_SIZE_8, CS43130_CH_BIT_SIZE_8},
3441 + {16, CS43130_SP_BIT_SIZE_16, CS43130_CH_BIT_SIZE_16},
3442 + {24, CS43130_SP_BIT_SIZE_24, CS43130_CH_BIT_SIZE_24},
3443 + {32, CS43130_SP_BIT_SIZE_32, CS43130_CH_BIT_SIZE_32},
3444 +};
3445 +
3446 +static const struct cs43130_bitwidth_map *cs43130_get_bitwidth_table(
3447 + unsigned int bitwidth)
3448 +{
3449 + int i;
3450 +
3451 + for (i = 0; i < ARRAY_SIZE(cs43130_bitwidth_table); i++) {
3452 + if (cs43130_bitwidth_table[i].bitwidth == bitwidth)
3453 + return &cs43130_bitwidth_table[i];
3454 + }
3455 +
3456 + return NULL;
3457 +}
3458 +static int cs43130_set_bitwidth(int dai_id, unsigned int bitwidth_dai,
3459 + struct regmap *regmap)
3460 +{
3461 + const struct cs43130_bitwidth_map *bw_map;
3462 +
3463 + bw_map = cs43130_get_bitwidth_table(bitwidth_dai);
3464 + if (!bw_map)
3465 + return -EINVAL;
3466 +
3467 + switch (dai_id) {
3468 + case CS43130_ASP_PCM_DAI:
3469 + case CS43130_ASP_DOP_DAI:
3470 + regmap_update_bits(regmap, CS43130_ASP_CH_1_SZ_EN,
3471 + CS43130_CH_BITSIZE_MASK, bw_map->ch_bit);
3472 + regmap_update_bits(regmap, CS43130_ASP_CH_2_SZ_EN,
3473 + CS43130_CH_BITSIZE_MASK, bw_map->ch_bit);
3474 + regmap_update_bits(regmap, CS43130_SP_BITSIZE,
3475 + CS43130_ASP_BITSIZE_MASK, bw_map->sp_bit);
3476 + break;
3477 + case CS43130_XSP_DOP_DAI:
3478 + regmap_update_bits(regmap, CS43130_XSP_CH_1_SZ_EN,
3479 + CS43130_CH_BITSIZE_MASK, bw_map->ch_bit);
3480 + regmap_update_bits(regmap, CS43130_XSP_CH_2_SZ_EN,
3481 + CS43130_CH_BITSIZE_MASK, bw_map->ch_bit);
3482 + regmap_update_bits(regmap, CS43130_SP_BITSIZE,
3483 + CS43130_XSP_BITSIZE_MASK, bw_map->sp_bit <<
3484 + CS43130_XSP_BITSIZE_SHIFT);
3485 + break;
3486 + default:
3487 + return -EINVAL;
3488 + }
3489 +
3490 + return 0;
3491 +}
3492 +static const struct cs43130_rate_map cs43130_rate_table[] = {
3493 + {32000, CS43130_ASP_SPRATE_32K},
3494 + {44100, CS43130_ASP_SPRATE_44_1K},
3495 + {48000, CS43130_ASP_SPRATE_48K},
3496 + {88200, CS43130_ASP_SPRATE_88_2K},
3497 + {96000, CS43130_ASP_SPRATE_96K},
3498 + {176400, CS43130_ASP_SPRATE_176_4K},
3499 + {192000, CS43130_ASP_SPRATE_192K},
3500 + {352800, CS43130_ASP_SPRATE_352_8K},
3501 + {384000, CS43130_ASP_SPRATE_384K},
3502 +};
3503 +
3504 +static const struct cs43130_rate_map *cs43130_get_rate_table(int fs)
3505 +{
3506 + int i;
3507 +
3508 + for (i = 0; i < ARRAY_SIZE(cs43130_rate_table); i++) {
3509 + if (cs43130_rate_table[i].fs == fs)
3510 + return &cs43130_rate_table[i];
3511 + }
3512 +
3513 + return NULL;
3514 +}
3515 +
3516 +static const struct cs43130_clk_gen *cs43130_get_clk_gen(int mclk_int, int fs,
3517 + const struct cs43130_clk_gen *clk_gen_table, int len_clk_gen_table)
3518 +{
3519 + int i;
3520 +
3521 + for (i = 0; i < len_clk_gen_table; i++) {
3522 + if (clk_gen_table[i].mclk_int == mclk_int &&
3523 + clk_gen_table[i].fs == fs)
3524 + return &clk_gen_table[i];
3525 + }
3526 + return NULL;
3527 +}
3528 +
3529 +static int cs43130_set_sp_fmt(int dai_id, unsigned int bitwidth_sclk,
3530 + struct snd_pcm_hw_params *params,
3531 + struct cs43130_priv *cs43130)
3532 +{
3533 + u16 frm_size;
3534 + u16 hi_size;
3535 + u8 frm_delay;
3536 + u8 frm_phase;
3537 + u8 frm_data;
3538 + u8 sclk_edge;
3539 + u8 lrck_edge;
3540 + u8 clk_data;
3541 + u8 loc_ch1;
3542 + u8 loc_ch2;
3543 + u8 dai_mode_val;
3544 + const struct cs43130_clk_gen *clk_gen;
3545 +
3546 + switch (cs43130->dais[dai_id].dai_format) {
3547 + case SND_SOC_DAIFMT_I2S:
3548 + hi_size = bitwidth_sclk;
3549 + frm_delay = 2;
3550 + frm_phase = 0;
3551 + break;
3552 + case SND_SOC_DAIFMT_LEFT_J:
3553 + hi_size = bitwidth_sclk;
3554 + frm_delay = 2;
3555 + frm_phase = 1;
3556 + break;
3557 + case SND_SOC_DAIFMT_DSP_A:
3558 + hi_size = 1;
3559 + frm_delay = 2;
3560 + frm_phase = 1;
3561 + break;
3562 + case SND_SOC_DAIFMT_DSP_B:
3563 + hi_size = 1;
3564 + frm_delay = 0;
3565 + frm_phase = 1;
3566 + break;
3567 + default:
3568 + return -EINVAL;
3569 + }
3570 + switch (cs43130->dais[dai_id].dai_mode) {
3571 + case SND_SOC_DAIFMT_CBS_CFS:
3572 + dai_mode_val = 0;
3573 + break;
3574 + case SND_SOC_DAIFMT_CBM_CFM:
3575 + dai_mode_val = 1;
3576 + break;
3577 + default:
3578 + return -EINVAL;
3579 + }
3580 +
3581 + frm_size = bitwidth_sclk * params_channels(params);
3582 + sclk_edge = 1;
3583 + lrck_edge = 0;
3584 + loc_ch1 = 0;
3585 + loc_ch2 = bitwidth_sclk * (params_channels(params) - 1);
3586 +
3587 + frm_data = frm_delay & CS43130_SP_FSD_MASK;
3588 + frm_data |= (frm_phase << CS43130_SP_STP_SHIFT) & CS43130_SP_STP_MASK;
3589 +
3590 + clk_data = lrck_edge & CS43130_SP_LCPOL_IN_MASK;
3591 + clk_data |= (lrck_edge << CS43130_SP_LCPOL_OUT_SHIFT) &
3592 + CS43130_SP_LCPOL_OUT_MASK;
3593 + clk_data |= (sclk_edge << CS43130_SP_SCPOL_IN_SHIFT) &
3594 + CS43130_SP_SCPOL_IN_MASK;
3595 + clk_data |= (sclk_edge << CS43130_SP_SCPOL_OUT_SHIFT) &
3596 + CS43130_SP_SCPOL_OUT_MASK;
3597 + clk_data |= (dai_mode_val << CS43130_SP_MODE_SHIFT) &
3598 + CS43130_SP_MODE_MASK;
3599 + switch (dai_id) {
3600 + case CS43130_ASP_PCM_DAI:
3601 + case CS43130_ASP_DOP_DAI:
3602 + regmap_update_bits(cs43130->regmap, CS43130_ASP_LRCK_PERIOD_1,
3603 + CS43130_SP_LCPR_DATA_MASK, (frm_size - 1) >>
3604 + CS43130_SP_LCPR_LSB_DATA_SHIFT);
3605 + regmap_update_bits(cs43130->regmap, CS43130_ASP_LRCK_PERIOD_2,
3606 + CS43130_SP_LCPR_DATA_MASK, (frm_size - 1) >>
3607 + CS43130_SP_LCPR_MSB_DATA_SHIFT);
3608 + regmap_update_bits(cs43130->regmap, CS43130_ASP_LRCK_HI_TIME_1,
3609 + CS43130_SP_LCHI_DATA_MASK, (hi_size - 1) >>
3610 + CS43130_SP_LCHI_LSB_DATA_SHIFT);
3611 + regmap_update_bits(cs43130->regmap, CS43130_ASP_LRCK_HI_TIME_2,
3612 + CS43130_SP_LCHI_DATA_MASK, (hi_size - 1) >>
3613 + CS43130_SP_LCHI_MSB_DATA_SHIFT);
3614 + regmap_write(cs43130->regmap, CS43130_ASP_FRAME_CONF, frm_data);
3615 + regmap_write(cs43130->regmap, CS43130_ASP_CH_1_LOC, loc_ch1);
3616 + regmap_write(cs43130->regmap, CS43130_ASP_CH_2_LOC, loc_ch2);
3617 + regmap_update_bits(cs43130->regmap, CS43130_ASP_CH_1_SZ_EN,
3618 + CS43130_CH_EN_MASK, 1 << CS43130_CH_EN_SHIFT);
3619 + regmap_update_bits(cs43130->regmap, CS43130_ASP_CH_2_SZ_EN,
3620 + CS43130_CH_EN_MASK, 1 << CS43130_CH_EN_SHIFT);
3621 + regmap_write(cs43130->regmap, CS43130_ASP_CLOCK_CONF, clk_data);
3622 + break;
3623 + case CS43130_XSP_DOP_DAI:
3624 + regmap_update_bits(cs43130->regmap, CS43130_XSP_LRCK_PERIOD_1,
3625 + CS43130_SP_LCPR_DATA_MASK, (frm_size - 1) >>
3626 + CS43130_SP_LCPR_LSB_DATA_SHIFT);
3627 + regmap_update_bits(cs43130->regmap, CS43130_XSP_LRCK_PERIOD_2,
3628 + CS43130_SP_LCPR_DATA_MASK, (frm_size - 1) >>
3629 + CS43130_SP_LCPR_MSB_DATA_SHIFT);
3630 + regmap_update_bits(cs43130->regmap, CS43130_XSP_LRCK_HI_TIME_1,
3631 + CS43130_SP_LCHI_DATA_MASK, (hi_size - 1) >>
3632 + CS43130_SP_LCHI_LSB_DATA_SHIFT);
3633 + regmap_update_bits(cs43130->regmap, CS43130_XSP_LRCK_HI_TIME_2,
3634 + CS43130_SP_LCHI_DATA_MASK, (hi_size - 1) >>
3635 + CS43130_SP_LCHI_MSB_DATA_SHIFT);
3636 + regmap_write(cs43130->regmap, CS43130_XSP_FRAME_CONF, frm_data);
3637 + regmap_write(cs43130->regmap, CS43130_XSP_CH_1_LOC, loc_ch1);
3638 + regmap_write(cs43130->regmap, CS43130_XSP_CH_2_LOC, loc_ch2);
3639 + regmap_update_bits(cs43130->regmap, CS43130_XSP_CH_1_SZ_EN,
3640 + CS43130_CH_EN_MASK, 1 << CS43130_CH_EN_SHIFT);
3641 + regmap_update_bits(cs43130->regmap, CS43130_XSP_CH_2_SZ_EN,
3642 + CS43130_CH_EN_MASK, 1 << CS43130_CH_EN_SHIFT);
3643 + regmap_write(cs43130->regmap, CS43130_XSP_CLOCK_CONF, clk_data);
3644 + break;
3645 + default:
3646 + return -EINVAL;
3647 + }
3648 + switch (frm_size) {
3649 + case 16:
3650 + clk_gen = cs43130_get_clk_gen(cs43130->mclk_int,
3651 + params_rate(params),
3652 + cs43130_16_clk_gen,
3653 + ARRAY_SIZE(cs43130_16_clk_gen));
3654 + break;
3655 + case 32:
3656 + clk_gen = cs43130_get_clk_gen(cs43130->mclk_int,
3657 + params_rate(params),
3658 + cs43130_32_clk_gen,
3659 + ARRAY_SIZE(cs43130_32_clk_gen));
3660 + break;
3661 + case 48:
3662 + clk_gen = cs43130_get_clk_gen(cs43130->mclk_int,
3663 + params_rate(params),
3664 + cs43130_48_clk_gen,
3665 + ARRAY_SIZE(cs43130_48_clk_gen));
3666 + break;
3667 + case 64:
3668 + clk_gen = cs43130_get_clk_gen(cs43130->mclk_int,
3669 + params_rate(params),
3670 + cs43130_64_clk_gen,
3671 + ARRAY_SIZE(cs43130_64_clk_gen));
3672 + break;
3673 + default:
3674 + return -EINVAL;
3675 + }
3676 + if (!clk_gen)
3677 + return -EINVAL;
3678 + switch (dai_id) {
3679 + case CS43130_ASP_PCM_DAI:
3680 + case CS43130_ASP_DOP_DAI:
3681 + regmap_write(cs43130->regmap, CS43130_ASP_DEN_1,
3682 + (clk_gen->v.denominator & CS43130_SP_M_LSB_DATA_MASK) >>
3683 + CS43130_SP_M_LSB_DATA_SHIFT);
3684 + regmap_write(cs43130->regmap, CS43130_ASP_DEN_2,
3685 + (clk_gen->v.denominator & CS43130_SP_M_MSB_DATA_MASK) >>
3686 + CS43130_SP_M_MSB_DATA_SHIFT);
3687 + regmap_write(cs43130->regmap, CS43130_ASP_NUM_1,
3688 + (clk_gen->v.numerator & CS43130_SP_N_LSB_DATA_MASK) >>
3689 + CS43130_SP_N_LSB_DATA_SHIFT);
3690 + regmap_write(cs43130->regmap, CS43130_ASP_NUM_2,
3691 + (clk_gen->v.numerator & CS43130_SP_N_MSB_DATA_MASK) >>
3692 + CS43130_SP_N_MSB_DATA_SHIFT);
3693 + break;
3694 + case CS43130_XSP_DOP_DAI:
3695 + regmap_write(cs43130->regmap, CS43130_XSP_DEN_1,
3696 + (clk_gen->v.denominator & CS43130_SP_M_LSB_DATA_MASK) >>
3697 + CS43130_SP_M_LSB_DATA_SHIFT);
3698 + regmap_write(cs43130->regmap, CS43130_XSP_DEN_2,
3699 + (clk_gen->v.denominator & CS43130_SP_M_MSB_DATA_MASK) >>
3700 + CS43130_SP_M_MSB_DATA_SHIFT);
3701 + regmap_write(cs43130->regmap, CS43130_XSP_NUM_1,
3702 + (clk_gen->v.numerator & CS43130_SP_N_LSB_DATA_MASK) >>
3703 + CS43130_SP_N_LSB_DATA_SHIFT);
3704 + regmap_write(cs43130->regmap, CS43130_XSP_NUM_2,
3705 + (clk_gen->v.numerator & CS43130_SP_N_MSB_DATA_MASK) >>
3706 + CS43130_SP_N_MSB_DATA_SHIFT);
3707 + break;
3708 + default:
3709 + return -EINVAL;
3710 + }
3711 + return 0;
3712 +}
3713 +
3714 +static int cs43130_hw_params(struct snd_pcm_substream *substream,
3715 + struct snd_pcm_hw_params *params,
3716 + struct snd_soc_dai *dai)
3717 +{
3718 + struct snd_soc_component *component = dai->component;
3719 + struct cs43130_priv *cs43130 =
3720 + snd_soc_component_get_drvdata(component);
3721 + const struct cs43130_rate_map *rate_map;
3722 + unsigned int sclk = cs43130->dais[dai->id].sclk;
3723 + unsigned int bitwidth_sclk;
3724 + unsigned int bitwidth_dai = (unsigned int)(params_width(params));
3725 + unsigned int dop_rate = (unsigned int)(params_rate(params));
3726 + unsigned int required_clk, ret;
3727 + u8 dsd_speed;
3728 +
3729 + cs43130->pll_bypass = true;
3730 + cs43130_pcm_pdn(component);
3731 + mutex_lock(&cs43130->clk_mutex);
3732 + if (!cs43130->clk_req) {
3733 + /* no DAI is currently using clk */
3734 + if (!(CS43130_MCLK_22M % params_rate(params))) {
3735 + required_clk = CS43130_MCLK_22M;
3736 + cs43130->mclk_int = CS43130_MCLK_22M;
3737 + gpiod_set_value_cansleep(snd_allo_clk44gpio, 1);
3738 + gpiod_set_value_cansleep(snd_allo_clk48gpio, 0);
3739 + usleep_range(13500, 14000);
3740 + } else {
3741 + required_clk = CS43130_MCLK_24M;
3742 + cs43130->mclk_int = CS43130_MCLK_24M;
3743 + gpiod_set_value_cansleep(snd_allo_clk48gpio, 1);
3744 + gpiod_set_value_cansleep(snd_allo_clk44gpio, 0);
3745 + usleep_range(13500, 14000);
3746 + }
3747 + if (cs43130->pll_bypass)
3748 + cs43130_change_clksrc(component, CS43130_MCLK_SRC_EXT);
3749 + else
3750 + cs43130_change_clksrc(component, CS43130_MCLK_SRC_PLL);
3751 + }
3752 +
3753 + cs43130->clk_req++;
3754 + mutex_unlock(&cs43130->clk_mutex);
3755 +
3756 + switch (dai->id) {
3757 + case CS43130_ASP_DOP_DAI:
3758 + case CS43130_XSP_DOP_DAI:
3759 + /* DoP bitwidth is always 24-bit */
3760 + bitwidth_dai = 24;
3761 + sclk = params_rate(params) * bitwidth_dai *
3762 + params_channels(params);
3763 +
3764 + switch (params_rate(params)) {
3765 + case 176400:
3766 + dsd_speed = 0;
3767 + break;
3768 + case 352800:
3769 + dsd_speed = 1;
3770 + break;
3771 + default:
3772 + dev_err(component->dev, "Rate(%u) not supported\n",
3773 + params_rate(params));
3774 + return -EINVAL;
3775 + }
3776 +
3777 + regmap_update_bits(cs43130->regmap, CS43130_DSD_PATH_CTL_2,
3778 + CS43130_DSD_SPEED_MASK,
3779 + dsd_speed << CS43130_DSD_SPEED_SHIFT);
3780 + break;
3781 + case CS43130_ASP_PCM_DAI:
3782 + rate_map = cs43130_get_rate_table(params_rate(params));
3783 + if (!rate_map)
3784 + return -EINVAL;
3785 +
3786 + regmap_write(cs43130->regmap, CS43130_SP_SRATE, rate_map->val);
3787 + if ((dop_rate == 176400) && (bitwidth_dai == 24)) {
3788 + dsd_speed = 0;
3789 + regmap_update_bits(cs43130->regmap,
3790 + CS43130_DSD_PATH_CTL_2,
3791 + CS43130_DSD_SPEED_MASK,
3792 + dsd_speed << CS43130_DSD_SPEED_SHIFT);
3793 + regmap_update_bits(cs43130->regmap,
3794 + CS43130_DSD_PATH_CTL_2,
3795 + CS43130_DSD_SRC_MASK,
3796 + CS43130_DSD_SRC_ASP <<
3797 + CS43130_DSD_SRC_SHIFT);
3798 + regmap_update_bits(cs43130->regmap,
3799 + CS43130_DSD_PATH_CTL_2,
3800 + CS43130_DSD_EN_MASK, 0x01 <<
3801 + CS43130_DSD_EN_SHIFT);
3802 + }
3803 + break;
3804 + default:
3805 + dev_err(component->dev, "Invalid DAI (%d)\n", dai->id);
3806 + return -EINVAL;
3807 + }
3808 +
3809 + switch (dai->id) {
3810 + case CS43130_ASP_DOP_DAI:
3811 + regmap_update_bits(cs43130->regmap, CS43130_DSD_PATH_CTL_2,
3812 + CS43130_DSD_SRC_MASK, CS43130_DSD_SRC_ASP <<
3813 + CS43130_DSD_SRC_SHIFT);
3814 + regmap_update_bits(cs43130->regmap, CS43130_DSD_PATH_CTL_2,
3815 + CS43130_DSD_EN_MASK, 0x01 <<
3816 + CS43130_DSD_EN_SHIFT);
3817 + break;
3818 + case CS43130_XSP_DOP_DAI:
3819 + regmap_update_bits(cs43130->regmap, CS43130_DSD_PATH_CTL_2,
3820 + CS43130_DSD_SRC_MASK, CS43130_DSD_SRC_XSP <<
3821 + CS43130_DSD_SRC_SHIFT);
3822 + break;
3823 + }
3824 + if (!sclk && cs43130->dais[dai->id].dai_mode ==
3825 + SND_SOC_DAIFMT_CBM_CFM) {
3826 + /* Calculate SCLK in master mode if unassigned */
3827 + sclk = params_rate(params) * bitwidth_dai *
3828 + params_channels(params);
3829 + }
3830 + if (!sclk) {
3831 + /* at this point, SCLK must be set */
3832 + dev_err(component->dev, "SCLK freq is not set\n");
3833 + return -EINVAL;
3834 + }
3835 +
3836 + bitwidth_sclk = (sclk / params_rate(params)) / params_channels(params);
3837 + if (bitwidth_sclk < bitwidth_dai) {
3838 + dev_err(component->dev, "Format not supported: SCLK freq is too low\n");
3839 + return -EINVAL;
3840 + }
3841 +
3842 + dev_dbg(component->dev,
3843 + "sclk = %u, fs = %d, bitwidth_dai = %u\n",
3844 + sclk, params_rate(params), bitwidth_dai);
3845 +
3846 + dev_dbg(component->dev,
3847 + "bitwidth_sclk = %u, num_ch = %u\n",
3848 + bitwidth_sclk, params_channels(params));
3849 +
3850 + cs43130_set_bitwidth(dai->id, bitwidth_dai, cs43130->regmap);
3851 + cs43130_set_sp_fmt(dai->id, bitwidth_sclk, params, cs43130);
3852 + ret = cs43130_pwr_up_asp_dac(component);
3853 + return 0;
3854 +}
3855 +
3856 +static int cs43130_hw_free(struct snd_pcm_substream *substream,
3857 + struct snd_soc_dai *dai)
3858 +{
3859 + struct snd_soc_component *component = dai->component;
3860 + struct cs43130_priv *cs43130 =
3861 + snd_soc_component_get_drvdata(component);
3862 +
3863 + mutex_lock(&cs43130->clk_mutex);
3864 + cs43130->clk_req--;
3865 + if (!cs43130->clk_req) {
3866 + /* no DAI is currently using clk */
3867 + cs43130_change_clksrc(component, CS43130_MCLK_SRC_RCO);
3868 + cs43130_pcm_pdn(component);
3869 + }
3870 + mutex_unlock(&cs43130->clk_mutex);
3871 +
3872 + return 0;
3873 +}
3874 +
3875 +static const unsigned int cs43130_asp_src_rates[] = {
3876 + 32000, 44100, 48000, 88200, 96000, 176400, 192000
3877 +};
3878 +
3879 +static const struct snd_pcm_hw_constraint_list cs43130_asp_constraints = {
3880 + .count = ARRAY_SIZE(cs43130_asp_src_rates),
3881 + .list = cs43130_asp_src_rates,
3882 +};
3883 +
3884 +static int cs43130_pcm_startup(struct snd_pcm_substream *substream,
3885 + struct snd_soc_dai *dai)
3886 +{
3887 + return snd_pcm_hw_constraint_list(substream->runtime, 0,
3888 + SNDRV_PCM_HW_PARAM_RATE,
3889 + &cs43130_asp_constraints);
3890 +}
3891 +
3892 +static int cs43130_pcm_set_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
3893 +{
3894 + struct snd_soc_component *component = codec_dai->component;
3895 + struct cs43130_priv *cs43130 =
3896 + snd_soc_component_get_drvdata(component);
3897 +
3898 + switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
3899 + case SND_SOC_DAIFMT_CBS_CFS:
3900 + cs43130->dais[codec_dai->id].dai_mode = SND_SOC_DAIFMT_CBS_CFS;
3901 + break;
3902 + case SND_SOC_DAIFMT_CBM_CFM:
3903 + cs43130->dais[codec_dai->id].dai_mode = SND_SOC_DAIFMT_CBM_CFM;
3904 + break;
3905 + default:
3906 + dev_err(component->dev, "unsupported mode\n");
3907 + return -EINVAL;
3908 + }
3909 +
3910 + switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
3911 + case SND_SOC_DAIFMT_I2S:
3912 + cs43130->dais[codec_dai->id].dai_format = SND_SOC_DAIFMT_I2S;
3913 + break;
3914 + case SND_SOC_DAIFMT_LEFT_J:
3915 + cs43130->dais[codec_dai->id].dai_format = SND_SOC_DAIFMT_LEFT_J;
3916 + break;
3917 + default:
3918 + dev_err(component->dev,
3919 + "unsupported audio format\n");
3920 + return -EINVAL;
3921 + }
3922 +
3923 + dev_dbg(component->dev, "dai_id = %d, dai_mode = %u, dai_format = %u\n",
3924 + codec_dai->id,
3925 + cs43130->dais[codec_dai->id].dai_mode,
3926 + cs43130->dais[codec_dai->id].dai_format);
3927 +
3928 + return 0;
3929 +}
3930 +
3931 +static int cs43130_set_sysclk(struct snd_soc_dai *codec_dai,
3932 + int clk_id, unsigned int freq, int dir)
3933 +{
3934 + struct snd_soc_component *component = codec_dai->component;
3935 + struct cs43130_priv *cs43130 =
3936 + snd_soc_component_get_drvdata(component);
3937 +
3938 + cs43130->dais[codec_dai->id].sclk = freq;
3939 + dev_dbg(component->dev, "dai_id = %d, sclk = %u\n", codec_dai->id,
3940 + cs43130->dais[codec_dai->id].sclk);
3941 +
3942 + return 0;
3943 +}
3944 +
3945 +static int cs43130_component_set_sysclk(struct snd_soc_component *component,
3946 + int clk_id, int source,
3947 + unsigned int freq, int dir)
3948 +{
3949 + struct cs43130_priv *cs43130 =
3950 + snd_soc_component_get_drvdata(component);
3951 +
3952 + dev_dbg(component->dev, "clk_id = %d, source = %d, freq = %d, dir = %d\n",
3953 + clk_id, source, freq, dir);
3954 +
3955 + switch (freq) {
3956 + case CS43130_MCLK_22M:
3957 + case CS43130_MCLK_24M:
3958 + cs43130->mclk = freq;
3959 + break;
3960 + default:
3961 + dev_err(component->dev, "Invalid MCLK INT freq: %u\n", freq);
3962 + return -EINVAL;
3963 + }
3964 +
3965 + if (source == CS43130_MCLK_SRC_EXT) {
3966 + cs43130->pll_bypass = true;
3967 + } else {
3968 + dev_err(component->dev, "Invalid MCLK source\n");
3969 + return -EINVAL;
3970 + }
3971 +
3972 + return 0;
3973 +}
3974 +static u16 const cs43130_ac_freq[CS43130_AC_FREQ] = {
3975 + 24,
3976 + 43,
3977 + 93,
3978 + 200,
3979 + 431,
3980 + 928,
3981 + 2000,
3982 + 4309,
3983 + 9283,
3984 + 20000,
3985 +};
3986 +static const struct snd_soc_dai_ops cs43130_dai_ops = {
3987 + .startup = cs43130_pcm_startup,
3988 + .hw_params = cs43130_hw_params,
3989 + .hw_free = cs43130_hw_free,
3990 + .set_sysclk = cs43130_set_sysclk,
3991 + .set_fmt = cs43130_pcm_set_fmt,
3992 +};
3993 +
3994 +static struct snd_soc_dai_driver cs43130_codec_dai = {
3995 + .name = "allo-cs43130",
3996 + .playback = {
3997 + .stream_name = "Playback",
3998 + .channels_min = 2,
3999 + .channels_max = 2,
4000 + .rates = SNDRV_PCM_RATE_CONTINUOUS,
4001 + .rate_min = 44100,
4002 + .rate_max = 192000,
4003 + .formats = SNDRV_PCM_FMTBIT_S16_LE |
4004 + SNDRV_PCM_FMTBIT_S24_LE |
4005 + SNDRV_PCM_FMTBIT_S32_LE
4006 +
4007 + },
4008 + .ops = &cs43130_dai_ops,
4009 +};
4010 +
4011 +static struct snd_soc_component_driver cs43130_component_driver = {
4012 + .idle_bias_on = true,
4013 + .controls = cs43130_controls,
4014 + .num_controls = ARRAY_SIZE(cs43130_controls),
4015 + .set_sysclk = cs43130_component_set_sysclk,
4016 + .idle_bias_on = 1,
4017 + .use_pmdown_time = 1,
4018 + .endianness = 1,
4019 +};
4020 +
4021 +static const struct regmap_config cs43130_regmap = {
4022 + .reg_bits = 24,
4023 + .pad_bits = 8,
4024 + .val_bits = 8,
4025 +
4026 + .max_register = CS43130_LASTREG,
4027 + .reg_defaults = cs43130_reg_defaults,
4028 + .num_reg_defaults = ARRAY_SIZE(cs43130_reg_defaults),
4029 + .readable_reg = cs43130_readable_register,
4030 + .precious_reg = cs43130_precious_register,
4031 + .volatile_reg = cs43130_volatile_register,
4032 + .cache_type = REGCACHE_RBTREE,
4033 + /* needed for regcache_sync */
4034 + .use_single_read = true,
4035 + .use_single_write = true,
4036 +};
4037 +
4038 +static u16 const cs43130_dc_threshold[CS43130_DC_THRESHOLD] = {
4039 + 50,
4040 + 120,
4041 +};
4042 +
4043 +static int cs43130_handle_device_data(struct i2c_client *i2c_client,
4044 + struct cs43130_priv *cs43130)
4045 +{
4046 + struct device_node *np = i2c_client->dev.of_node;
4047 + unsigned int val;
4048 + int i;
4049 +
4050 + if (of_property_read_u32(np, "cirrus,xtal-ibias", &val) < 0) {
4051 + /* Crystal is unused. System clock is used for external MCLK */
4052 + cs43130->xtal_ibias = CS43130_XTAL_UNUSED;
4053 + return 0;
4054 + }
4055 +
4056 + switch (val) {
4057 + case 1:
4058 + cs43130->xtal_ibias = CS43130_XTAL_IBIAS_7_5UA;
4059 + break;
4060 + case 2:
4061 + cs43130->xtal_ibias = CS43130_XTAL_IBIAS_12_5UA;
4062 + break;
4063 + case 3:
4064 + cs43130->xtal_ibias = CS43130_XTAL_IBIAS_15UA;
4065 + break;
4066 + default:
4067 + dev_err(&i2c_client->dev,
4068 + "Invalid cirrus,xtal-ibias value: %d\n", val);
4069 + return -EINVAL;
4070 + }
4071 +
4072 + cs43130->dc_meas = of_property_read_bool(np, "cirrus,dc-measure");
4073 + cs43130->ac_meas = of_property_read_bool(np, "cirrus,ac-measure");
4074 +
4075 + if (of_property_read_u16_array(np, "cirrus,ac-freq", cs43130->ac_freq,
4076 + CS43130_AC_FREQ) < 0) {
4077 + for (i = 0; i < CS43130_AC_FREQ; i++)
4078 + cs43130->ac_freq[i] = cs43130_ac_freq[i];
4079 + }
4080 +
4081 + if (of_property_read_u16_array(np, "cirrus,dc-threshold",
4082 + cs43130->dc_threshold,
4083 + CS43130_DC_THRESHOLD) < 0) {
4084 + for (i = 0; i < CS43130_DC_THRESHOLD; i++)
4085 + cs43130->dc_threshold[i] = cs43130_dc_threshold[i];
4086 + }
4087 +
4088 + return 0;
4089 +}
4090 +
4091 +
4092 +static int allo_cs43130_component_probe(struct i2c_client *i2c,
4093 + const struct i2c_device_id *id)
4094 +{
4095 + struct regmap *regmap;
4096 + struct regmap_config config = cs43130_regmap;
4097 + struct device *dev = &i2c->dev;
4098 + struct cs43130_priv *cs43130;
4099 + unsigned int devid = 0;
4100 + unsigned int reg;
4101 + int ret;
4102 +
4103 + regmap = devm_regmap_init_i2c(i2c, &config);
4104 + if (IS_ERR(regmap))
4105 + return PTR_ERR(regmap);
4106 +
4107 + cs43130 = devm_kzalloc(dev, sizeof(struct cs43130_priv),
4108 + GFP_KERNEL);
4109 + if (!cs43130)
4110 + return -ENOMEM;
4111 +
4112 + dev_set_drvdata(dev, cs43130);
4113 + cs43130->regmap = regmap;
4114 +
4115 + if (i2c->dev.of_node) {
4116 + ret = cs43130_handle_device_data(i2c, cs43130);
4117 + if (ret != 0)
4118 + return ret;
4119 + }
4120 + usleep_range(2000, 2050);
4121 +
4122 + ret = regmap_read(cs43130->regmap, CS43130_DEVID_AB, &reg);
4123 + devid = (reg & 0xFF) << 12;
4124 + ret = regmap_read(cs43130->regmap, CS43130_DEVID_CD, &reg);
4125 + devid |= (reg & 0xFF) << 4;
4126 + ret = regmap_read(cs43130->regmap, CS43130_DEVID_E, &reg);
4127 + devid |= (reg & 0xF0) >> 4;
4128 + if (devid != CS43198_CHIP_ID) {
4129 + dev_err(dev, "Failed to read Chip or wrong Chip id: %d\n", ret);
4130 + return ret;
4131 + }
4132 +
4133 + cs43130->mclk_int_src = CS43130_MCLK_SRC_RCO;
4134 + msleep(20);
4135 +
4136 + ret = snd_soc_register_component(dev, &cs43130_component_driver,
4137 + &cs43130_codec_dai, 1);
4138 + if (ret != 0) {
4139 + dev_err(dev, "failed to register codec: %d\n", ret);
4140 + return ret;
4141 + }
4142 + regmap_update_bits(cs43130->regmap, CS43130_PAD_INT_CFG,
4143 + CS43130_ASP_3ST_MASK, 0);
4144 + regmap_update_bits(cs43130->regmap, CS43130_PAD_INT_CFG,
4145 + CS43130_XSP_3ST_MASK, 1);
4146 + regmap_update_bits(cs43130->regmap, CS43130_PWDN_CTL,
4147 + CS43130_PDN_HP_MASK, 1 << CS43130_PDN_HP_SHIFT);
4148 + msleep(20);
4149 + regmap_write(cs43130->regmap, CS43130_CLASS_H_CTL, 0x06);
4150 + snd_allo_clk44gpio = devm_gpiod_get(dev, "clock44", GPIOD_OUT_HIGH);
4151 + if (IS_ERR(snd_allo_clk44gpio))
4152 + dev_err(dev, "devm_gpiod_get() failed\n");
4153 +
4154 + snd_allo_clk48gpio = devm_gpiod_get(dev, "clock48", GPIOD_OUT_LOW);
4155 + if (IS_ERR(snd_allo_clk48gpio))
4156 + dev_err(dev, "devm_gpiod_get() failed\n");
4157 +
4158 + return 0;
4159 +}
4160 +
4161 +static void allo_cs43130_component_remove(struct i2c_client *i2c)
4162 +{
4163 + snd_soc_unregister_component(&i2c->dev);
4164 +}
4165 +
4166 +static const struct i2c_device_id allo_cs43130_component_id[] = {
4167 + { "allo-cs43198", },
4168 + { }
4169 +};
4170 +MODULE_DEVICE_TABLE(i2c, allo_cs43130_component_id);
4171 +
4172 +static const struct of_device_id allo_cs43130_codec_of_match[] = {
4173 + { .compatible = "allo,allo-cs43198", },
4174 + { }
4175 +};
4176 +MODULE_DEVICE_TABLE(of, allo_cs43130_codec_of_match);
4177 +
4178 +static struct i2c_driver allo_cs43130_component_driver = {
4179 + .probe = allo_cs43130_component_probe,
4180 + .remove = allo_cs43130_component_remove,
4181 + .id_table = allo_cs43130_component_id,
4182 + .driver = {
4183 + .name = "allo-cs43198",
4184 + .of_match_table = allo_cs43130_codec_of_match,
4185 + },
4186 +};
4187 +
4188 +module_i2c_driver(allo_cs43130_component_driver);
4189 +
4190 +MODULE_DESCRIPTION("ASoC Allo Boss2 Codec Driver");
4191 +MODULE_AUTHOR("Sudeepkumar <sudeepkumar@cem-solutions.net>");
4192 +MODULE_LICENSE("GPL v2");
4193 --- /dev/null
4194 +++ b/sound/soc/bcm/allo-katana-codec.c
4195 @@ -0,0 +1,387 @@
4196 +/*
4197 + * Driver for the ALLO KATANA CODEC
4198 + *
4199 + * Author: Jaikumar <jaikumar@cem-solutions.net>
4200 + * Copyright 2018
4201 + *
4202 + * This program is free software; you can redistribute it and/or
4203 + * modify it under the terms of the GNU General Public License
4204 + * version 2 as published by the Free Software Foundation.
4205 + *
4206 + * This program is distributed in the hope that it will be useful, but
4207 + * WITHOUT ANY WARRANTY; without even the implied warranty of
4208 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4209 + * General Public License for more details.
4210 + */
4211 +
4212 +
4213 +#include <linux/init.h>
4214 +#include <linux/module.h>
4215 +#include <linux/clk.h>
4216 +#include <linux/kernel.h>
4217 +#include <linux/regmap.h>
4218 +#include <linux/regulator/consumer.h>
4219 +#include <linux/gcd.h>
4220 +#include <sound/soc.h>
4221 +#include <sound/soc-dapm.h>
4222 +#include <sound/pcm_params.h>
4223 +#include <sound/tlv.h>
4224 +#include <linux/i2c.h>
4225 +
4226 +
4227 +#define KATANA_CODEC_CHIP_ID 0x30
4228 +#define KATANA_CODEC_VIRT_BASE 0x100
4229 +#define KATANA_CODEC_PAGE 0
4230 +
4231 +#define KATANA_CODEC_CHIP_ID_REG (KATANA_CODEC_VIRT_BASE + 0)
4232 +#define KATANA_CODEC_RESET (KATANA_CODEC_VIRT_BASE + 1)
4233 +#define KATANA_CODEC_VOLUME_1 (KATANA_CODEC_VIRT_BASE + 2)
4234 +#define KATANA_CODEC_VOLUME_2 (KATANA_CODEC_VIRT_BASE + 3)
4235 +#define KATANA_CODEC_MUTE (KATANA_CODEC_VIRT_BASE + 4)
4236 +#define KATANA_CODEC_DSP_PROGRAM (KATANA_CODEC_VIRT_BASE + 5)
4237 +#define KATANA_CODEC_DEEMPHASIS (KATANA_CODEC_VIRT_BASE + 6)
4238 +#define KATANA_CODEC_DOP (KATANA_CODEC_VIRT_BASE + 7)
4239 +#define KATANA_CODEC_FORMAT (KATANA_CODEC_VIRT_BASE + 8)
4240 +#define KATANA_CODEC_COMMAND (KATANA_CODEC_VIRT_BASE + 9)
4241 +#define KATANA_CODEC_MUTE_STREAM (KATANA_CODEC_VIRT_BASE + 10)
4242 +
4243 +#define KATANA_CODEC_MAX_REGISTER (KATANA_CODEC_VIRT_BASE + 10)
4244 +
4245 +#define KATANA_CODEC_FMT 0xff
4246 +#define KATANA_CODEC_CHAN_MONO 0x00
4247 +#define KATANA_CODEC_CHAN_STEREO 0x80
4248 +#define KATANA_CODEC_ALEN_16 0x10
4249 +#define KATANA_CODEC_ALEN_24 0x20
4250 +#define KATANA_CODEC_ALEN_32 0x30
4251 +#define KATANA_CODEC_RATE_11025 0x01
4252 +#define KATANA_CODEC_RATE_22050 0x02
4253 +#define KATANA_CODEC_RATE_32000 0x03
4254 +#define KATANA_CODEC_RATE_44100 0x04
4255 +#define KATANA_CODEC_RATE_48000 0x05
4256 +#define KATANA_CODEC_RATE_88200 0x06
4257 +#define KATANA_CODEC_RATE_96000 0x07
4258 +#define KATANA_CODEC_RATE_176400 0x08
4259 +#define KATANA_CODEC_RATE_192000 0x09
4260 +#define KATANA_CODEC_RATE_352800 0x0a
4261 +#define KATANA_CODEC_RATE_384000 0x0b
4262 +
4263 +
4264 +struct katana_codec_priv {
4265 + struct regmap *regmap;
4266 + int fmt;
4267 +};
4268 +
4269 +static const struct reg_default katana_codec_reg_defaults[] = {
4270 + { KATANA_CODEC_RESET, 0x00 },
4271 + { KATANA_CODEC_VOLUME_1, 0xF0 },
4272 + { KATANA_CODEC_VOLUME_2, 0xF0 },
4273 + { KATANA_CODEC_MUTE, 0x00 },
4274 + { KATANA_CODEC_DSP_PROGRAM, 0x04 },
4275 + { KATANA_CODEC_DEEMPHASIS, 0x00 },
4276 + { KATANA_CODEC_DOP, 0x00 },
4277 + { KATANA_CODEC_FORMAT, 0xb4 },
4278 +};
4279 +
4280 +static const char * const katana_codec_dsp_program_texts[] = {
4281 + "Linear Phase Fast Roll-off Filter",
4282 + "Linear Phase Slow Roll-off Filter",
4283 + "Minimum Phase Fast Roll-off Filter",
4284 + "Minimum Phase Slow Roll-off Filter",
4285 + "Apodizing Fast Roll-off Filter",
4286 + "Corrected Minimum Phase Fast Roll-off Filter",
4287 + "Brick Wall Filter",
4288 +};
4289 +
4290 +static const unsigned int katana_codec_dsp_program_values[] = {
4291 + 0,
4292 + 1,
4293 + 2,
4294 + 3,
4295 + 4,
4296 + 6,
4297 + 7,
4298 +};
4299 +
4300 +static SOC_VALUE_ENUM_SINGLE_DECL(katana_codec_dsp_program,
4301 + KATANA_CODEC_DSP_PROGRAM, 0, 0x07,
4302 + katana_codec_dsp_program_texts,
4303 + katana_codec_dsp_program_values);
4304 +
4305 +static const char * const katana_codec_deemphasis_texts[] = {
4306 + "Bypass",
4307 + "32kHz",
4308 + "44.1kHz",
4309 + "48kHz",
4310 +};
4311 +
4312 +static const unsigned int katana_codec_deemphasis_values[] = {
4313 + 0,
4314 + 1,
4315 + 2,
4316 + 3,
4317 +};
4318 +
4319 +static SOC_VALUE_ENUM_SINGLE_DECL(katana_codec_deemphasis,
4320 + KATANA_CODEC_DEEMPHASIS, 0, 0x03,
4321 + katana_codec_deemphasis_texts,
4322 + katana_codec_deemphasis_values);
4323 +
4324 +static const SNDRV_CTL_TLVD_DECLARE_DB_MINMAX(master_tlv, -12750, 0);
4325 +
4326 +static const struct snd_kcontrol_new katana_codec_controls[] = {
4327 + SOC_DOUBLE_R_TLV("Master Playback Volume", KATANA_CODEC_VOLUME_1,
4328 + KATANA_CODEC_VOLUME_2, 0, 255, 1, master_tlv),
4329 + SOC_DOUBLE("Master Playback Switch", KATANA_CODEC_MUTE, 0, 0, 1, 1),
4330 + SOC_ENUM("DSP Program Route", katana_codec_dsp_program),
4331 + SOC_ENUM("Deemphasis Route", katana_codec_deemphasis),
4332 + SOC_SINGLE("DoP Playback Switch", KATANA_CODEC_DOP, 0, 1, 1)
4333 +};
4334 +
4335 +static bool katana_codec_readable_register(struct device *dev,
4336 + unsigned int reg)
4337 +{
4338 + switch (reg) {
4339 + case KATANA_CODEC_CHIP_ID_REG:
4340 + return true;
4341 + default:
4342 + return reg < 0xff;
4343 + }
4344 +}
4345 +
4346 +static int katana_codec_hw_params(struct snd_pcm_substream *substream,
4347 + struct snd_pcm_hw_params *params,
4348 + struct snd_soc_dai *dai)
4349 +{
4350 + struct snd_soc_component *component = dai->component;
4351 + struct katana_codec_priv *katana_codec =
4352 + snd_soc_component_get_drvdata(component);
4353 + int fmt = 0;
4354 + int ret;
4355 +
4356 + dev_dbg(component->card->dev, "hw_params %u Hz, %u channels, %u bits\n",
4357 + params_rate(params),
4358 + params_channels(params),
4359 + params_width(params));
4360 +
4361 + switch (katana_codec->fmt & SND_SOC_DAIFMT_MASTER_MASK) {
4362 + case SND_SOC_DAIFMT_CBM_CFM: // master
4363 + if (params_channels(params) == 2)
4364 + fmt = KATANA_CODEC_CHAN_STEREO;
4365 + else
4366 + fmt = KATANA_CODEC_CHAN_MONO;
4367 +
4368 + switch (params_width(params)) {
4369 + case 16:
4370 + fmt |= KATANA_CODEC_ALEN_16;
4371 + break;
4372 + case 24:
4373 + fmt |= KATANA_CODEC_ALEN_24;
4374 + break;
4375 + case 32:
4376 + fmt |= KATANA_CODEC_ALEN_32;
4377 + break;
4378 + default:
4379 + dev_err(component->card->dev, "Bad frame size: %d\n",
4380 + params_width(params));
4381 + return -EINVAL;
4382 + }
4383 +
4384 + switch (params_rate(params)) {
4385 + case 44100:
4386 + fmt |= KATANA_CODEC_RATE_44100;
4387 + break;
4388 + case 48000:
4389 + fmt |= KATANA_CODEC_RATE_48000;
4390 + break;
4391 + case 88200:
4392 + fmt |= KATANA_CODEC_RATE_88200;
4393 + break;
4394 + case 96000:
4395 + fmt |= KATANA_CODEC_RATE_96000;
4396 + break;
4397 + case 176400:
4398 + fmt |= KATANA_CODEC_RATE_176400;
4399 + break;
4400 + case 192000:
4401 + fmt |= KATANA_CODEC_RATE_192000;
4402 + break;
4403 + case 352800:
4404 + fmt |= KATANA_CODEC_RATE_352800;
4405 + break;
4406 + case 384000:
4407 + fmt |= KATANA_CODEC_RATE_384000;
4408 + break;
4409 + default:
4410 + dev_err(component->card->dev, "Bad sample rate: %d\n",
4411 + params_rate(params));
4412 + return -EINVAL;
4413 + }
4414 +
4415 + ret = regmap_write(katana_codec->regmap, KATANA_CODEC_FORMAT,
4416 + fmt);
4417 + if (ret != 0) {
4418 + dev_err(component->card->dev, "Failed to set format: %d\n", ret);
4419 + return ret;
4420 + }
4421 + break;
4422 +
4423 + case SND_SOC_DAIFMT_CBS_CFS:
4424 + break;
4425 +
4426 + default:
4427 + return -EINVAL;
4428 + }
4429 +
4430 + return 0;
4431 +}
4432 +
4433 +static int katana_codec_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
4434 +{
4435 + struct snd_soc_component *component = dai->component;
4436 + struct katana_codec_priv *katana_codec =
4437 + snd_soc_component_get_drvdata(component);
4438 +
4439 + katana_codec->fmt = fmt;
4440 +
4441 + return 0;
4442 +}
4443 +
4444 +int katana_codec_dai_mute_stream(struct snd_soc_dai *dai, int mute,
4445 + int stream)
4446 +{
4447 + struct snd_soc_component *component = dai->component;
4448 + struct katana_codec_priv *katana_codec =
4449 + snd_soc_component_get_drvdata(component);
4450 + int ret = 0;
4451 +
4452 + ret = regmap_write(katana_codec->regmap, KATANA_CODEC_MUTE_STREAM,
4453 + mute);
4454 + if (ret != 0) {
4455 + dev_err(component->card->dev, "Failed to set mute: %d\n", ret);
4456 + return ret;
4457 + }
4458 + return ret;
4459 +}
4460 +
4461 +static const struct snd_soc_dai_ops katana_codec_dai_ops = {
4462 + .mute_stream = katana_codec_dai_mute_stream,
4463 + .hw_params = katana_codec_hw_params,
4464 + .set_fmt = katana_codec_set_fmt,
4465 +};
4466 +
4467 +static struct snd_soc_dai_driver katana_codec_dai = {
4468 + .name = "allo-katana-codec",
4469 + .playback = {
4470 + .stream_name = "Playback",
4471 + .channels_min = 2,
4472 + .channels_max = 2,
4473 + .rates = SNDRV_PCM_RATE_CONTINUOUS,
4474 + .rate_min = 44100,
4475 + .rate_max = 384000,
4476 + .formats = SNDRV_PCM_FMTBIT_S16_LE |
4477 + SNDRV_PCM_FMTBIT_S32_LE
4478 + },
4479 + .ops = &katana_codec_dai_ops,
4480 +};
4481 +
4482 +static struct snd_soc_component_driver katana_codec_component_driver = {
4483 + .idle_bias_on = true,
4484 +
4485 + .controls = katana_codec_controls,
4486 + .num_controls = ARRAY_SIZE(katana_codec_controls),
4487 +};
4488 +
4489 +static const struct regmap_range_cfg katana_codec_range = {
4490 + .name = "Pages", .range_min = KATANA_CODEC_VIRT_BASE,
4491 + .range_max = KATANA_CODEC_MAX_REGISTER,
4492 + .selector_reg = KATANA_CODEC_PAGE,
4493 + .selector_mask = 0xff,
4494 + .window_start = 0, .window_len = 0x100,
4495 +};
4496 +
4497 +const struct regmap_config katana_codec_regmap = {
4498 + .reg_bits = 8,
4499 + .val_bits = 8,
4500 +
4501 + .ranges = &katana_codec_range,
4502 + .num_ranges = 1,
4503 +
4504 + .max_register = KATANA_CODEC_MAX_REGISTER,
4505 + .readable_reg = katana_codec_readable_register,
4506 + .reg_defaults = katana_codec_reg_defaults,
4507 + .num_reg_defaults = ARRAY_SIZE(katana_codec_reg_defaults),
4508 + .cache_type = REGCACHE_RBTREE,
4509 +};
4510 +
4511 +static int allo_katana_component_probe(struct i2c_client *i2c,
4512 + const struct i2c_device_id *id)
4513 +{
4514 + struct regmap *regmap;
4515 + struct regmap_config config = katana_codec_regmap;
4516 + struct device *dev = &i2c->dev;
4517 + struct katana_codec_priv *katana_codec;
4518 + unsigned int chip_id = 0;
4519 + int ret;
4520 +
4521 + regmap = devm_regmap_init_i2c(i2c, &config);
4522 + if (IS_ERR(regmap))
4523 + return PTR_ERR(regmap);
4524 +
4525 + katana_codec = devm_kzalloc(dev, sizeof(struct katana_codec_priv),
4526 + GFP_KERNEL);
4527 + if (!katana_codec)
4528 + return -ENOMEM;
4529 +
4530 + dev_set_drvdata(dev, katana_codec);
4531 + katana_codec->regmap = regmap;
4532 +
4533 + ret = regmap_read(regmap, KATANA_CODEC_CHIP_ID_REG, &chip_id);
4534 + if ((ret != 0) || (chip_id != KATANA_CODEC_CHIP_ID)) {
4535 + dev_err(dev, "Failed to read Chip or wrong Chip id: %d\n", ret);
4536 + return ret;
4537 + }
4538 + regmap_update_bits(regmap, KATANA_CODEC_RESET, 0x01, 0x01);
4539 + msleep(10);
4540 +
4541 + ret = snd_soc_register_component(dev, &katana_codec_component_driver,
4542 + &katana_codec_dai, 1);
4543 + if (ret != 0) {
4544 + dev_err(dev, "failed to register codec: %d\n", ret);
4545 + return ret;
4546 + }
4547 +
4548 + return 0;
4549 +}
4550 +
4551 +static void allo_katana_component_remove(struct i2c_client *i2c)
4552 +{
4553 + snd_soc_unregister_component(&i2c->dev);
4554 +}
4555 +
4556 +static const struct i2c_device_id allo_katana_component_id[] = {
4557 + { "allo-katana-codec", },
4558 + { }
4559 +};
4560 +MODULE_DEVICE_TABLE(i2c, allo_katana_component_id);
4561 +
4562 +static const struct of_device_id allo_katana_codec_of_match[] = {
4563 + { .compatible = "allo,allo-katana-codec", },
4564 + { }
4565 +};
4566 +MODULE_DEVICE_TABLE(of, allo_katana_codec_of_match);
4567 +
4568 +static struct i2c_driver allo_katana_component_driver = {
4569 + .probe = allo_katana_component_probe,
4570 + .remove = allo_katana_component_remove,
4571 + .id_table = allo_katana_component_id,
4572 + .driver = {
4573 + .name = "allo-katana-codec",
4574 + .of_match_table = allo_katana_codec_of_match,
4575 + },
4576 +};
4577 +
4578 +module_i2c_driver(allo_katana_component_driver);
4579 +
4580 +MODULE_DESCRIPTION("ASoC Allo Katana Codec Driver");
4581 +MODULE_AUTHOR("Jaikumar <jaikumar@cem-solutions.net>");
4582 +MODULE_LICENSE("GPL v2");
4583 --- /dev/null
4584 +++ b/sound/soc/bcm/allo-piano-dac-plus.c
4585 @@ -0,0 +1,1064 @@
4586 +/*
4587 + * ALSA ASoC Machine Driver for Allo Piano DAC Plus Subwoofer
4588 + *
4589 + * Author: Baswaraj K <jaikumar@cem-solutions.net>
4590 + * Copyright 2020
4591 + * based on code by David Knell <david.knell@gmail.com)
4592 + * based on code by Daniel Matuschek <info@crazy-audio.com>
4593 + * based on code by Florian Meier <florian.meier@koalo.de>
4594 + *
4595 + * This program is free software; you can redistribute it and/or
4596 + * modify it under the terms of the GNU General Public License
4597 + * version 2 as published by the Free Software Foundation.
4598 + *
4599 + * This program is distributed in the hope that it will be useful, but
4600 + * WITHOUT ANY WARRANTY; without even the implied warranty of
4601 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4602 + * General Public License for more details.
4603 + */
4604 +
4605 +#include <linux/module.h>
4606 +#include <linux/platform_device.h>
4607 +#include <linux/gpio/consumer.h>
4608 +#include <sound/core.h>
4609 +#include <sound/pcm.h>
4610 +#include <sound/pcm_params.h>
4611 +#include <sound/soc.h>
4612 +#include <linux/firmware.h>
4613 +#include <linux/delay.h>
4614 +#include <sound/tlv.h>
4615 +#include "../codecs/pcm512x.h"
4616 +
4617 +#define P_DAC_LEFT_MUTE 0x10
4618 +#define P_DAC_RIGHT_MUTE 0x01
4619 +#define P_DAC_MUTE 0x11
4620 +#define P_DAC_UNMUTE 0x00
4621 +#define P_MUTE 1
4622 +#define P_UNMUTE 0
4623 +
4624 +struct dsp_code {
4625 + char i2c_addr;
4626 + char offset;
4627 + char val;
4628 +};
4629 +
4630 +struct glb_pool {
4631 + struct mutex lock;
4632 + unsigned int dual_mode;
4633 + unsigned int set_lowpass;
4634 + unsigned int set_mode;
4635 + unsigned int set_rate;
4636 + unsigned int dsp_page_number;
4637 +};
4638 +
4639 +static bool digital_gain_0db_limit = true;
4640 +bool glb_mclk;
4641 +
4642 +static struct gpio_desc *mute_gpio[2];
4643 +
4644 +static const char * const allo_piano_mode_texts[] = {
4645 + "None",
4646 + "2.0",
4647 + "2.1",
4648 + "2.2",
4649 +};
4650 +
4651 +static SOC_ENUM_SINGLE_DECL(allo_piano_mode_enum,
4652 + 0, 0, allo_piano_mode_texts);
4653 +
4654 +static const char * const allo_piano_dual_mode_texts[] = {
4655 + "None",
4656 + "Dual-Mono",
4657 + "Dual-Stereo",
4658 +};
4659 +
4660 +static SOC_ENUM_SINGLE_DECL(allo_piano_dual_mode_enum,
4661 + 0, 0, allo_piano_dual_mode_texts);
4662 +
4663 +static const char * const allo_piano_dsp_low_pass_texts[] = {
4664 + "60",
4665 + "70",
4666 + "80",
4667 + "90",
4668 + "100",
4669 + "110",
4670 + "120",
4671 + "130",
4672 + "140",
4673 + "150",
4674 + "160",
4675 + "170",
4676 + "180",
4677 + "190",
4678 + "200",
4679 +};
4680 +
4681 +static SOC_ENUM_SINGLE_DECL(allo_piano_enum,
4682 + 0, 0, allo_piano_dsp_low_pass_texts);
4683 +
4684 +static int __snd_allo_piano_dsp_program(struct snd_soc_pcm_runtime *rtd,
4685 + unsigned int mode, unsigned int rate, unsigned int lowpass)
4686 +{
4687 + const struct firmware *fw;
4688 + struct snd_soc_card *card = rtd->card;
4689 + struct glb_pool *glb_ptr = card->drvdata;
4690 + char firmware_name[60];
4691 + int ret = 0, dac = 0;
4692 +
4693 + if (rate <= 46000)
4694 + rate = 44100;
4695 + else if (rate <= 68000)
4696 + rate = 48000;
4697 + else if (rate <= 92000)
4698 + rate = 88200;
4699 + else if (rate <= 136000)
4700 + rate = 96000;
4701 + else if (rate <= 184000)
4702 + rate = 176400;
4703 + else
4704 + rate = 192000;
4705 +
4706 + if (lowpass > 14)
4707 + glb_ptr->set_lowpass = lowpass = 0;
4708 +
4709 + if (mode > 3)
4710 + glb_ptr->set_mode = mode = 0;
4711 +
4712 + if (mode > 0)
4713 + glb_ptr->dual_mode = 0;
4714 +
4715 + /* same configuration loaded */
4716 + if ((rate == glb_ptr->set_rate) && (lowpass == glb_ptr->set_lowpass)
4717 + && (mode == glb_ptr->set_mode))
4718 + return 0;
4719 +
4720 + switch (mode) {
4721 + case 0: /* None */
4722 + return 1;
4723 +
4724 + case 1: /* 2.0 */
4725 + snd_soc_component_write(asoc_rtd_to_codec(rtd, 0)->component,
4726 + PCM512x_MUTE, P_DAC_UNMUTE);
4727 + snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component,
4728 + PCM512x_MUTE, P_DAC_MUTE);
4729 + glb_ptr->set_rate = rate;
4730 + glb_ptr->set_mode = mode;
4731 + glb_ptr->set_lowpass = lowpass;
4732 + return 1;
4733 +
4734 + default:
4735 + snd_soc_component_write(asoc_rtd_to_codec(rtd, 0)->component,
4736 + PCM512x_MUTE, P_DAC_UNMUTE);
4737 + snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component,
4738 + PCM512x_MUTE, P_DAC_UNMUTE);
4739 + }
4740 +
4741 + for (dac = 0; dac < rtd->dai_link->num_codecs; dac++) {
4742 + struct dsp_code *dsp_code_read;
4743 + int i = 1;
4744 +
4745 + if (dac == 0) { /* high */
4746 + snprintf(firmware_name, sizeof(firmware_name),
4747 + "allo/piano/2.2/allo-piano-dsp-%d-%d-%d.bin",
4748 + rate, ((lowpass * 10) + 60), dac);
4749 + } else { /* low */
4750 + snprintf(firmware_name, sizeof(firmware_name),
4751 + "allo/piano/2.%d/allo-piano-dsp-%d-%d-%d.bin",
4752 + (mode - 1), rate, ((lowpass * 10) + 60), dac);
4753 + }
4754 +
4755 + dev_info(rtd->card->dev, "Dsp Firmware File Name: %s\n",
4756 + firmware_name);
4757 +
4758 + ret = request_firmware(&fw, firmware_name, rtd->card->dev);
4759 + if (ret < 0) {
4760 + dev_err(rtd->card->dev,
4761 + "Error: Allo Piano Firmware %s missing. %d\n",
4762 + firmware_name, ret);
4763 + goto err;
4764 + }
4765 +
4766 + while (i < (fw->size - 1)) {
4767 + dsp_code_read = (struct dsp_code *)&fw->data[i];
4768 +
4769 + if (dsp_code_read->offset == 0) {
4770 + glb_ptr->dsp_page_number = dsp_code_read->val;
4771 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, dac)->component,
4772 + PCM512x_PAGE_BASE(0),
4773 + dsp_code_read->val);
4774 +
4775 + } else if (dsp_code_read->offset != 0) {
4776 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, dac)->component,
4777 + (PCM512x_PAGE_BASE(
4778 + glb_ptr->dsp_page_number) +
4779 + dsp_code_read->offset),
4780 + dsp_code_read->val);
4781 + }
4782 + if (ret < 0) {
4783 + dev_err(rtd->card->dev,
4784 + "Failed to write Register: %d\n", ret);
4785 + release_firmware(fw);
4786 + goto err;
4787 + }
4788 + i = i + 3;
4789 + }
4790 + release_firmware(fw);
4791 + }
4792 + glb_ptr->set_rate = rate;
4793 + glb_ptr->set_mode = mode;
4794 + glb_ptr->set_lowpass = lowpass;
4795 + return 1;
4796 +
4797 +err:
4798 + return ret;
4799 +}
4800 +
4801 +static int snd_allo_piano_dsp_program(struct snd_soc_pcm_runtime *rtd,
4802 + unsigned int mode, unsigned int rate, unsigned int lowpass)
4803 +{
4804 + struct snd_soc_card *card = rtd->card;
4805 + struct glb_pool *glb_ptr = card->drvdata;
4806 + int ret = 0;
4807 +
4808 + mutex_lock(&glb_ptr->lock);
4809 +
4810 + ret = __snd_allo_piano_dsp_program(rtd, mode, rate, lowpass);
4811 +
4812 + mutex_unlock(&glb_ptr->lock);
4813 +
4814 + return ret;
4815 +}
4816 +
4817 +static int snd_allo_piano_dual_mode_get(struct snd_kcontrol *kcontrol,
4818 + struct snd_ctl_elem_value *ucontrol)
4819 +{
4820 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
4821 + struct glb_pool *glb_ptr = card->drvdata;
4822 +
4823 + ucontrol->value.integer.value[0] = glb_ptr->dual_mode;
4824 +
4825 + return 0;
4826 +}
4827 +
4828 +static int snd_allo_piano_dual_mode_put(struct snd_kcontrol *kcontrol,
4829 + struct snd_ctl_elem_value *ucontrol)
4830 +{
4831 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
4832 + struct glb_pool *glb_ptr = card->drvdata;
4833 + struct snd_soc_pcm_runtime *rtd;
4834 + struct snd_card *snd_card_ptr = card->snd_card;
4835 + struct snd_kcontrol *kctl;
4836 + struct soc_mixer_control *mc;
4837 + unsigned int left_val = 0, right_val = 0;
4838 +
4839 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
4840 +
4841 + if (ucontrol->value.integer.value[0] > 0) {
4842 + glb_ptr->dual_mode = ucontrol->value.integer.value[0];
4843 + glb_ptr->set_mode = 0;
4844 + } else {
4845 + if (glb_ptr->set_mode <= 0) {
4846 + glb_ptr->dual_mode = 1;
4847 + glb_ptr->set_mode = 0;
4848 + } else {
4849 + glb_ptr->dual_mode = 0;
4850 + return 0;
4851 + }
4852 + }
4853 +
4854 + if (glb_ptr->dual_mode == 1) { // Dual Mono
4855 + snd_soc_component_write(asoc_rtd_to_codec(rtd, 0)->component,
4856 + PCM512x_MUTE, P_DAC_RIGHT_MUTE);
4857 + snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component,
4858 + PCM512x_MUTE, P_DAC_LEFT_MUTE);
4859 + snd_soc_component_write(asoc_rtd_to_codec(rtd, 0)->component,
4860 + PCM512x_DIGITAL_VOLUME_3, 0xff);
4861 + snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component,
4862 + PCM512x_DIGITAL_VOLUME_2, 0xff);
4863 +
4864 + list_for_each_entry(kctl, &snd_card_ptr->controls, list) {
4865 + if (!strncmp(kctl->id.name, "Main Digital Playback Volume",
4866 + sizeof(kctl->id.name))) {
4867 + mc = (struct soc_mixer_control *)
4868 + kctl->private_value;
4869 + mc->rreg = mc->reg;
4870 + break;
4871 + }
4872 + if (!strncmp(kctl->id.name, "Sub Digital Playback Volume",
4873 + sizeof(kctl->id.name))) {
4874 + mc = (struct soc_mixer_control *)
4875 + kctl->private_value;
4876 + mc->rreg = mc->reg;
4877 + break;
4878 + }
4879 + }
4880 + } else {
4881 + left_val = snd_soc_component_read(asoc_rtd_to_codec(rtd, 0)->component,
4882 + PCM512x_DIGITAL_VOLUME_2);
4883 + right_val = snd_soc_component_read(asoc_rtd_to_codec(rtd, 1)->component,
4884 + PCM512x_DIGITAL_VOLUME_3);
4885 +
4886 + list_for_each_entry(kctl, &snd_card_ptr->controls, list) {
4887 + if (!strncmp(kctl->id.name, "Main Digital Playback Volume",
4888 + sizeof(kctl->id.name))) {
4889 + mc = (struct soc_mixer_control *)
4890 + kctl->private_value;
4891 + mc->rreg = PCM512x_DIGITAL_VOLUME_3;
4892 + break;
4893 + }
4894 + if (!strncmp(kctl->id.name, "Sub Digital Playback Volume",
4895 + sizeof(kctl->id.name))) {
4896 + mc = (struct soc_mixer_control *)
4897 + kctl->private_value;
4898 + mc->rreg = PCM512x_DIGITAL_VOLUME_2;
4899 + break;
4900 + }
4901 + }
4902 +
4903 + snd_soc_component_write(asoc_rtd_to_codec(rtd, 0)->component,
4904 + PCM512x_DIGITAL_VOLUME_3, left_val);
4905 + snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component,
4906 + PCM512x_DIGITAL_VOLUME_2, right_val);
4907 + snd_soc_component_write(asoc_rtd_to_codec(rtd, 0)->component,
4908 + PCM512x_MUTE, P_DAC_UNMUTE);
4909 + snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component,
4910 + PCM512x_MUTE, P_DAC_UNMUTE);
4911 + }
4912 +
4913 + return 0;
4914 +}
4915 +
4916 +static int snd_allo_piano_mode_get(struct snd_kcontrol *kcontrol,
4917 + struct snd_ctl_elem_value *ucontrol)
4918 +{
4919 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
4920 + struct glb_pool *glb_ptr = card->drvdata;
4921 +
4922 + ucontrol->value.integer.value[0] = glb_ptr->set_mode;
4923 + return 0;
4924 +}
4925 +
4926 +static int snd_allo_piano_mode_put(struct snd_kcontrol *kcontrol,
4927 + struct snd_ctl_elem_value *ucontrol)
4928 +{
4929 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
4930 + struct snd_soc_pcm_runtime *rtd;
4931 + struct glb_pool *glb_ptr = card->drvdata;
4932 + struct snd_card *snd_card_ptr = card->snd_card;
4933 + struct snd_kcontrol *kctl;
4934 + struct soc_mixer_control *mc;
4935 + unsigned int left_val = 0, right_val = 0;
4936 +
4937 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
4938 +
4939 + if ((glb_ptr->dual_mode == 1) &&
4940 + (ucontrol->value.integer.value[0] > 0)) {
4941 + left_val = snd_soc_component_read(asoc_rtd_to_codec(rtd, 0)->component,
4942 + PCM512x_DIGITAL_VOLUME_2);
4943 + right_val = snd_soc_component_read(asoc_rtd_to_codec(rtd, 1)->component,
4944 + PCM512x_DIGITAL_VOLUME_2);
4945 +
4946 + list_for_each_entry(kctl, &snd_card_ptr->controls, list) {
4947 + if (!strncmp(kctl->id.name, "Main Digital Playback Volume",
4948 + sizeof(kctl->id.name))) {
4949 + mc = (struct soc_mixer_control *)
4950 + kctl->private_value;
4951 + mc->rreg = PCM512x_DIGITAL_VOLUME_3;
4952 + break;
4953 + }
4954 + if (!strncmp(kctl->id.name, "Sub Digital Playback Volume",
4955 + sizeof(kctl->id.name))) {
4956 + mc = (struct soc_mixer_control *)
4957 + kctl->private_value;
4958 + mc->rreg = PCM512x_DIGITAL_VOLUME_2;
4959 + break;
4960 + }
4961 + }
4962 + snd_soc_component_write(asoc_rtd_to_codec(rtd, 0)->component,
4963 + PCM512x_DIGITAL_VOLUME_3, left_val);
4964 + snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component,
4965 + PCM512x_DIGITAL_VOLUME_3, right_val);
4966 + }
4967 +
4968 + return(snd_allo_piano_dsp_program(rtd,
4969 + ucontrol->value.integer.value[0],
4970 + glb_ptr->set_rate, glb_ptr->set_lowpass));
4971 +}
4972 +
4973 +static int snd_allo_piano_lowpass_get(struct snd_kcontrol *kcontrol,
4974 + struct snd_ctl_elem_value *ucontrol)
4975 +{
4976 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
4977 + struct glb_pool *glb_ptr = card->drvdata;
4978 +
4979 + ucontrol->value.integer.value[0] = glb_ptr->set_lowpass;
4980 + return 0;
4981 +}
4982 +
4983 +static int snd_allo_piano_lowpass_put(struct snd_kcontrol *kcontrol,
4984 + struct snd_ctl_elem_value *ucontrol)
4985 +{
4986 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
4987 + struct snd_soc_pcm_runtime *rtd;
4988 + struct glb_pool *glb_ptr = card->drvdata;
4989 +
4990 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
4991 + return(snd_allo_piano_dsp_program(rtd,
4992 + glb_ptr->set_mode, glb_ptr->set_rate,
4993 + ucontrol->value.integer.value[0]));
4994 +}
4995 +
4996 +static int pcm512x_get_reg_sub(struct snd_kcontrol *kcontrol,
4997 + struct snd_ctl_elem_value *ucontrol)
4998 +{
4999 + struct soc_mixer_control *mc =
5000 + (struct soc_mixer_control *)kcontrol->private_value;
5001 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
5002 + struct glb_pool *glb_ptr = card->drvdata;
5003 + struct snd_soc_pcm_runtime *rtd;
5004 + unsigned int left_val = 0;
5005 + unsigned int right_val = 0;
5006 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
5007 +
5008 + right_val = snd_soc_component_read(asoc_rtd_to_codec(rtd, 1)->component,
5009 + PCM512x_DIGITAL_VOLUME_3);
5010 + if (glb_ptr->dual_mode != 1) {
5011 + left_val = snd_soc_component_read(asoc_rtd_to_codec(rtd, 1)->component,
5012 + PCM512x_DIGITAL_VOLUME_2);
5013 +
5014 + } else {
5015 + left_val = right_val;
5016 + }
5017 +
5018 + ucontrol->value.integer.value[0] =
5019 + (~(left_val >> mc->shift)) & mc->max;
5020 + ucontrol->value.integer.value[1] =
5021 + (~(right_val >> mc->shift)) & mc->max;
5022 +
5023 + return 0;
5024 +}
5025 +
5026 +static int pcm512x_set_reg_sub(struct snd_kcontrol *kcontrol,
5027 + struct snd_ctl_elem_value *ucontrol)
5028 +{
5029 + struct soc_mixer_control *mc =
5030 + (struct soc_mixer_control *)kcontrol->private_value;
5031 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
5032 + struct glb_pool *glb_ptr = card->drvdata;
5033 + struct snd_soc_pcm_runtime *rtd;
5034 + unsigned int left_val = (ucontrol->value.integer.value[0] & mc->max);
5035 + unsigned int right_val = (ucontrol->value.integer.value[1] & mc->max);
5036 + int ret = 0;
5037 +
5038 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
5039 +
5040 + if (digital_gain_0db_limit) {
5041 + ret = snd_soc_limit_volume(card, "Subwoofer Playback Volume",
5042 + 207);
5043 + if (ret < 0)
5044 + dev_warn(card->dev, "Failed to set volume limit: %d\n",
5045 + ret);
5046 + }
5047 +
5048 + // When in Dual Mono, Sub vol control should not set anything.
5049 + if (glb_ptr->dual_mode != 1) { //Not in Dual Mono mode
5050 +
5051 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component,
5052 + PCM512x_DIGITAL_VOLUME_2, (~left_val));
5053 + if (ret < 0)
5054 + return ret;
5055 +
5056 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component,
5057 + PCM512x_DIGITAL_VOLUME_3, (~right_val));
5058 + if (ret < 0)
5059 + return ret;
5060 +
5061 + }
5062 +
5063 + return 1;
5064 +}
5065 +
5066 +static int pcm512x_get_reg_sub_switch(struct snd_kcontrol *kcontrol,
5067 + struct snd_ctl_elem_value *ucontrol)
5068 +{
5069 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
5070 + struct snd_soc_pcm_runtime *rtd;
5071 + int val = 0;
5072 +
5073 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
5074 + val = snd_soc_component_read(asoc_rtd_to_codec(rtd, 1)->component, PCM512x_MUTE);
5075 +
5076 + ucontrol->value.integer.value[0] =
5077 + (val & P_DAC_LEFT_MUTE) ? P_UNMUTE : P_MUTE;
5078 + ucontrol->value.integer.value[1] =
5079 + (val & P_DAC_RIGHT_MUTE) ? P_UNMUTE : P_MUTE;
5080 +
5081 + return val;
5082 +}
5083 +
5084 +static int pcm512x_set_reg_sub_switch(struct snd_kcontrol *kcontrol,
5085 + struct snd_ctl_elem_value *ucontrol)
5086 +{
5087 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
5088 + struct snd_soc_pcm_runtime *rtd;
5089 + struct glb_pool *glb_ptr = card->drvdata;
5090 + unsigned int left_val = (ucontrol->value.integer.value[0]);
5091 + unsigned int right_val = (ucontrol->value.integer.value[1]);
5092 + int ret = 0;
5093 +
5094 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
5095 + if (glb_ptr->set_mode != 1) {
5096 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component, PCM512x_MUTE,
5097 + ~((left_val & 0x01)<<4 | (right_val & 0x01)));
5098 + if (ret < 0)
5099 + return ret;
5100 + }
5101 + return 1;
5102 +
5103 +}
5104 +
5105 +static int pcm512x_get_reg_master(struct snd_kcontrol *kcontrol,
5106 + struct snd_ctl_elem_value *ucontrol)
5107 +{
5108 + struct soc_mixer_control *mc =
5109 + (struct soc_mixer_control *)kcontrol->private_value;
5110 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
5111 + struct glb_pool *glb_ptr = card->drvdata;
5112 + struct snd_soc_pcm_runtime *rtd;
5113 + unsigned int left_val = 0, right_val = 0;
5114 +
5115 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
5116 +
5117 + left_val = snd_soc_component_read(asoc_rtd_to_codec(rtd, 0)->component,
5118 + PCM512x_DIGITAL_VOLUME_2);
5119 +
5120 + if (glb_ptr->dual_mode == 1) { // in Dual Mono mode
5121 + right_val = snd_soc_component_read(asoc_rtd_to_codec(rtd, 1)->component,
5122 + PCM512x_DIGITAL_VOLUME_3);
5123 + } else {
5124 + right_val = snd_soc_component_read(asoc_rtd_to_codec(rtd, 0)->component,
5125 + PCM512x_DIGITAL_VOLUME_3);
5126 + }
5127 +
5128 + ucontrol->value.integer.value[0] =
5129 + (~(left_val >> mc->shift)) & mc->max;
5130 + ucontrol->value.integer.value[1] =
5131 + (~(right_val >> mc->shift)) & mc->max;
5132 +
5133 + return 0;
5134 +}
5135 +
5136 +static int pcm512x_set_reg_master(struct snd_kcontrol *kcontrol,
5137 + struct snd_ctl_elem_value *ucontrol)
5138 +{
5139 + struct soc_mixer_control *mc =
5140 + (struct soc_mixer_control *)kcontrol->private_value;
5141 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
5142 + struct glb_pool *glb_ptr = card->drvdata;
5143 + struct snd_soc_pcm_runtime *rtd;
5144 + unsigned int left_val = (ucontrol->value.integer.value[0] & mc->max);
5145 + unsigned int right_val = (ucontrol->value.integer.value[1] & mc->max);
5146 + int ret = 0;
5147 +
5148 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
5149 +
5150 + if (digital_gain_0db_limit) {
5151 + ret = snd_soc_limit_volume(card, "Master Playback Volume",
5152 + 207);
5153 + if (ret < 0)
5154 + dev_warn(card->dev, "Failed to set volume limit: %d\n",
5155 + ret);
5156 + }
5157 +
5158 + if (glb_ptr->dual_mode == 1) { //in Dual Mono Mode
5159 +
5160 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 0)->component,
5161 + PCM512x_DIGITAL_VOLUME_2, (~left_val));
5162 + if (ret < 0)
5163 + return ret;
5164 +
5165 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component,
5166 + PCM512x_DIGITAL_VOLUME_3, (~right_val));
5167 + if (ret < 0)
5168 + return ret;
5169 +
5170 + } else {
5171 +
5172 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 0)->component,
5173 + PCM512x_DIGITAL_VOLUME_2, (~left_val));
5174 + if (ret < 0)
5175 + return ret;
5176 +
5177 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 0)->component,
5178 + PCM512x_DIGITAL_VOLUME_3, (~right_val));
5179 + if (ret < 0)
5180 + return ret;
5181 +
5182 + }
5183 + return 1;
5184 +}
5185 +
5186 +static int pcm512x_get_reg_master_switch(struct snd_kcontrol *kcontrol,
5187 + struct snd_ctl_elem_value *ucontrol)
5188 +{
5189 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
5190 + struct glb_pool *glb_ptr = card->drvdata;
5191 + struct snd_soc_pcm_runtime *rtd;
5192 + int val = 0;
5193 +
5194 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
5195 +
5196 + val = snd_soc_component_read(asoc_rtd_to_codec(rtd, 0)->component, PCM512x_MUTE);
5197 +
5198 + ucontrol->value.integer.value[0] =
5199 + (val & P_DAC_LEFT_MUTE) ? P_UNMUTE : P_MUTE;
5200 +
5201 + if (glb_ptr->dual_mode == 1) {
5202 + val = snd_soc_component_read(asoc_rtd_to_codec(rtd, 1)->component, PCM512x_MUTE);
5203 + }
5204 + ucontrol->value.integer.value[1] =
5205 + (val & P_DAC_RIGHT_MUTE) ? P_UNMUTE : P_MUTE;
5206 +
5207 + return val;
5208 +}
5209 +
5210 +static int pcm512x_set_reg_master_switch(struct snd_kcontrol *kcontrol,
5211 + struct snd_ctl_elem_value *ucontrol)
5212 +{
5213 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
5214 + struct snd_soc_pcm_runtime *rtd;
5215 + struct glb_pool *glb_ptr = card->drvdata;
5216 + unsigned int left_val = (ucontrol->value.integer.value[0]);
5217 + unsigned int right_val = (ucontrol->value.integer.value[1]);
5218 + int ret = 0;
5219 +
5220 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
5221 + if (glb_ptr->dual_mode == 1) {
5222 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 0)->component, PCM512x_MUTE,
5223 + ~((left_val & 0x01)<<4));
5224 + if (ret < 0)
5225 + return ret;
5226 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component, PCM512x_MUTE,
5227 + ~((right_val & 0x01)));
5228 + if (ret < 0)
5229 + return ret;
5230 +
5231 + } else if (glb_ptr->set_mode == 1) {
5232 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 0)->component, PCM512x_MUTE,
5233 + ~((left_val & 0x01)<<4 | (right_val & 0x01)));
5234 + if (ret < 0)
5235 + return ret;
5236 +
5237 + } else {
5238 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 0)->component, PCM512x_MUTE,
5239 + ~((left_val & 0x01)<<4 | (right_val & 0x01)));
5240 + if (ret < 0)
5241 + return ret;
5242 +
5243 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component, PCM512x_MUTE,
5244 + ~((left_val & 0x01)<<4 | (right_val & 0x01)));
5245 + if (ret < 0)
5246 + return ret;
5247 + }
5248 + return 1;
5249 +}
5250 +
5251 +static const DECLARE_TLV_DB_SCALE(digital_tlv_sub, -10350, 50, 1);
5252 +static const DECLARE_TLV_DB_SCALE(digital_tlv_master, -10350, 50, 1);
5253 +
5254 +static const struct snd_kcontrol_new allo_piano_controls[] = {
5255 + SOC_ENUM_EXT("Subwoofer mode Route",
5256 + allo_piano_mode_enum,
5257 + snd_allo_piano_mode_get,
5258 + snd_allo_piano_mode_put),
5259 +
5260 + SOC_ENUM_EXT("Dual Mode Route",
5261 + allo_piano_dual_mode_enum,
5262 + snd_allo_piano_dual_mode_get,
5263 + snd_allo_piano_dual_mode_put),
5264 +
5265 + SOC_ENUM_EXT("Lowpass Route", allo_piano_enum,
5266 + snd_allo_piano_lowpass_get,
5267 + snd_allo_piano_lowpass_put),
5268 +
5269 + SOC_DOUBLE_R_EXT_TLV("Subwoofer Playback Volume",
5270 + PCM512x_DIGITAL_VOLUME_2,
5271 + PCM512x_DIGITAL_VOLUME_3, 0, 255, 1,
5272 + pcm512x_get_reg_sub,
5273 + pcm512x_set_reg_sub,
5274 + digital_tlv_sub),
5275 +
5276 + SOC_DOUBLE_EXT("Subwoofer Playback Switch",
5277 + PCM512x_MUTE,
5278 + PCM512x_RQML_SHIFT,
5279 + PCM512x_RQMR_SHIFT, 1, 1,
5280 + pcm512x_get_reg_sub_switch,
5281 + pcm512x_set_reg_sub_switch),
5282 +
5283 + SOC_DOUBLE_R_EXT_TLV("Master Playback Volume",
5284 + PCM512x_DIGITAL_VOLUME_2,
5285 + PCM512x_DIGITAL_VOLUME_3, 0, 255, 1,
5286 + pcm512x_get_reg_master,
5287 + pcm512x_set_reg_master,
5288 + digital_tlv_master),
5289 +
5290 + SOC_DOUBLE_EXT("Master Playback Switch",
5291 + PCM512x_MUTE,
5292 + PCM512x_RQML_SHIFT,
5293 + PCM512x_RQMR_SHIFT, 1, 1,
5294 + pcm512x_get_reg_master_switch,
5295 + pcm512x_set_reg_master_switch),
5296 +};
5297 +
5298 +static const char * const codec_ctl_pfx[] = { "Main", "Sub" };
5299 +static const char * const codec_ctl_name[] = {
5300 + "Digital Playback Volume",
5301 + "Digital Playback Switch",
5302 + "Auto Mute Mono Switch",
5303 + "Auto Mute Switch",
5304 + "Auto Mute Time Left",
5305 + "Auto Mute Time Right",
5306 + "Clock Missing Period",
5307 + "Max Overclock DAC",
5308 + "Max Overclock DSP",
5309 + "Max Overclock PLL",
5310 + "Volume Ramp Down Emergency Rate",
5311 + "Volume Ramp Down Emergency Step",
5312 + "Volume Ramp Up Rate",
5313 + "Volume Ramp Down Rate",
5314 + "Volume Ramp Up Step",
5315 + "Volume Ramp Down Step"
5316 +};
5317 +
5318 +static int snd_allo_piano_dac_init(struct snd_soc_pcm_runtime *rtd)
5319 +{
5320 + struct snd_soc_card *card = rtd->card;
5321 + struct glb_pool *glb_ptr;
5322 + struct snd_kcontrol *kctl;
5323 + int i, j;
5324 +
5325 + glb_ptr = kzalloc(sizeof(struct glb_pool), GFP_KERNEL);
5326 + if (!glb_ptr)
5327 + return -ENOMEM;
5328 +
5329 + card->drvdata = glb_ptr;
5330 + glb_ptr->dual_mode = 2;
5331 + glb_ptr->set_mode = 0;
5332 +
5333 + mutex_init(&glb_ptr->lock);
5334 +
5335 + if (digital_gain_0db_limit) {
5336 + int ret;
5337 +
5338 + //Set volume limit on both dacs
5339 + for (i = 0; i < ARRAY_SIZE(codec_ctl_pfx); i++) {
5340 + char cname[256];
5341 +
5342 + sprintf(cname, "%s %s", codec_ctl_pfx[i], codec_ctl_name[0]);
5343 + ret = snd_soc_limit_volume(card, cname, 207);
5344 + if (ret < 0)
5345 + dev_warn(card->dev, "Failed to set volume limit: %d\n",
5346 + ret);
5347 + }
5348 + }
5349 +
5350 + // Remove codec controls
5351 + for (i = 0; i < ARRAY_SIZE(codec_ctl_pfx); i++) {
5352 + for (j = 0; j < ARRAY_SIZE(codec_ctl_name); j++) {
5353 + char cname[256];
5354 +
5355 + sprintf(cname, "%s %s", codec_ctl_pfx[i], codec_ctl_name[j]);
5356 + kctl = snd_soc_card_get_kcontrol(card, cname);
5357 + if (!kctl) {
5358 + dev_err(rtd->card->dev, "Control %s not found\n",
5359 + cname);
5360 + } else {
5361 + kctl->vd[0].access =
5362 + SNDRV_CTL_ELEM_ACCESS_READWRITE;
5363 + snd_ctl_remove(card->snd_card, kctl);
5364 + }
5365 + }
5366 + }
5367 +
5368 + return 0;
5369 +}
5370 +
5371 +static void snd_allo_piano_gpio_mute(struct snd_soc_card *card)
5372 +{
5373 + if (mute_gpio[0])
5374 + gpiod_set_value_cansleep(mute_gpio[0], P_MUTE);
5375 +
5376 + if (mute_gpio[1])
5377 + gpiod_set_value_cansleep(mute_gpio[1], P_MUTE);
5378 +}
5379 +
5380 +static void snd_allo_piano_gpio_unmute(struct snd_soc_card *card)
5381 +{
5382 + if (mute_gpio[0])
5383 + gpiod_set_value_cansleep(mute_gpio[0], P_UNMUTE);
5384 +
5385 + if (mute_gpio[1])
5386 + gpiod_set_value_cansleep(mute_gpio[1], P_UNMUTE);
5387 +}
5388 +
5389 +static int snd_allo_piano_set_bias_level(struct snd_soc_card *card,
5390 + struct snd_soc_dapm_context *dapm, enum snd_soc_bias_level level)
5391 +{
5392 + struct snd_soc_pcm_runtime *rtd;
5393 + struct snd_soc_dai *codec_dai;
5394 +
5395 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
5396 + codec_dai = asoc_rtd_to_codec(rtd, 0);
5397 +
5398 + if (dapm->dev != codec_dai->dev)
5399 + return 0;
5400 +
5401 + switch (level) {
5402 + case SND_SOC_BIAS_PREPARE:
5403 + if (dapm->bias_level != SND_SOC_BIAS_STANDBY)
5404 + break;
5405 + /* UNMUTE DAC */
5406 + snd_allo_piano_gpio_unmute(card);
5407 + break;
5408 +
5409 + case SND_SOC_BIAS_STANDBY:
5410 + if (dapm->bias_level != SND_SOC_BIAS_PREPARE)
5411 + break;
5412 + /* MUTE DAC */
5413 + snd_allo_piano_gpio_mute(card);
5414 + break;
5415 +
5416 + default:
5417 + break;
5418 + }
5419 +
5420 + return 0;
5421 +}
5422 +
5423 +static int snd_allo_piano_dac_startup(
5424 + struct snd_pcm_substream *substream)
5425 +{
5426 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
5427 + struct snd_soc_card *card = rtd->card;
5428 +
5429 + snd_allo_piano_gpio_mute(card);
5430 +
5431 + return 0;
5432 +}
5433 +
5434 +static int snd_allo_piano_dac_hw_params(
5435 + struct snd_pcm_substream *substream,
5436 + struct snd_pcm_hw_params *params)
5437 +{
5438 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
5439 + unsigned int rate = params_rate(params);
5440 + struct snd_soc_card *card = rtd->card;
5441 + struct glb_pool *glb_ptr = card->drvdata;
5442 + int ret = 0, val = 0, dac;
5443 +
5444 + for (dac = 0; (glb_mclk && dac < 2); dac++) {
5445 + /* Configure the PLL clock reference for both the Codecs */
5446 + val = snd_soc_component_read(asoc_rtd_to_codec(rtd, dac)->component,
5447 + PCM512x_RATE_DET_4);
5448 +
5449 + if (val & 0x40) {
5450 + snd_soc_component_write(asoc_rtd_to_codec(rtd, dac)->component,
5451 + PCM512x_PLL_REF,
5452 + PCM512x_SREF_BCK);
5453 +
5454 + dev_info(asoc_rtd_to_codec(rtd, dac)->component->dev,
5455 + "Setting BCLK as input clock & Enable PLL\n");
5456 + } else {
5457 + snd_soc_component_write(asoc_rtd_to_codec(rtd, dac)->component,
5458 + PCM512x_PLL_EN,
5459 + 0x00);
5460 +
5461 + snd_soc_component_write(asoc_rtd_to_codec(rtd, dac)->component,
5462 + PCM512x_PLL_REF,
5463 + PCM512x_SREF_SCK);
5464 +
5465 + dev_info(asoc_rtd_to_codec(rtd, dac)->component->dev,
5466 + "Setting SCLK as input clock & disabled PLL\n");
5467 + }
5468 + }
5469 +
5470 + ret = snd_allo_piano_dsp_program(rtd, glb_ptr->set_mode, rate,
5471 + glb_ptr->set_lowpass);
5472 + if (ret < 0)
5473 + return ret;
5474 +
5475 + return ret;
5476 +}
5477 +
5478 +static int snd_allo_piano_dac_prepare(
5479 + struct snd_pcm_substream *substream)
5480 +{
5481 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
5482 + struct snd_soc_card *card = rtd->card;
5483 +
5484 + snd_allo_piano_gpio_unmute(card);
5485 +
5486 + return 0;
5487 +}
5488 +
5489 +/* machine stream operations */
5490 +static struct snd_soc_ops snd_allo_piano_dac_ops = {
5491 + .startup = snd_allo_piano_dac_startup,
5492 + .hw_params = snd_allo_piano_dac_hw_params,
5493 + .prepare = snd_allo_piano_dac_prepare,
5494 +};
5495 +
5496 +static struct snd_soc_dai_link_component allo_piano_2_1_codecs[] = {
5497 + {
5498 + .dai_name = "pcm512x-hifi",
5499 + },
5500 + {
5501 + .dai_name = "pcm512x-hifi",
5502 + },
5503 +};
5504 +
5505 +SND_SOC_DAILINK_DEFS(allo_piano_dai_plus,
5506 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
5507 + DAILINK_COMP_ARRAY(COMP_CODEC("pcm512x.1-004c", "pcm512x-hifi"),
5508 + COMP_CODEC("pcm512x.1-004d", "pcm512x-hifi")),
5509 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
5510 +
5511 +static struct snd_soc_dai_link snd_allo_piano_dac_dai[] = {
5512 + {
5513 + .name = "PianoDACPlus",
5514 + .stream_name = "PianoDACPlus",
5515 + .dai_fmt = SND_SOC_DAIFMT_I2S |
5516 + SND_SOC_DAIFMT_NB_NF |
5517 + SND_SOC_DAIFMT_CBS_CFS,
5518 + .ops = &snd_allo_piano_dac_ops,
5519 + .init = snd_allo_piano_dac_init,
5520 + SND_SOC_DAILINK_REG(allo_piano_dai_plus),
5521 + },
5522 +};
5523 +
5524 +/* audio machine driver */
5525 +static struct snd_soc_card snd_allo_piano_dac = {
5526 + .name = "PianoDACPlus",
5527 + .owner = THIS_MODULE,
5528 + .dai_link = snd_allo_piano_dac_dai,
5529 + .num_links = ARRAY_SIZE(snd_allo_piano_dac_dai),
5530 + .controls = allo_piano_controls,
5531 + .num_controls = ARRAY_SIZE(allo_piano_controls),
5532 +};
5533 +
5534 +static int snd_allo_piano_dac_probe(struct platform_device *pdev)
5535 +{
5536 + struct snd_soc_card *card = &snd_allo_piano_dac;
5537 + int ret = 0, i = 0;
5538 +
5539 + card->dev = &pdev->dev;
5540 + platform_set_drvdata(pdev, &snd_allo_piano_dac);
5541 +
5542 + if (pdev->dev.of_node) {
5543 + struct device_node *i2s_node;
5544 + struct snd_soc_dai_link *dai;
5545 +
5546 + dai = &snd_allo_piano_dac_dai[0];
5547 + i2s_node = of_parse_phandle(pdev->dev.of_node,
5548 + "i2s-controller", 0);
5549 + if (i2s_node) {
5550 + for (i = 0; i < card->num_links; i++) {
5551 + dai->cpus->dai_name = NULL;
5552 + dai->cpus->of_node = i2s_node;
5553 + dai->platforms->name = NULL;
5554 + dai->platforms->of_node = i2s_node;
5555 + }
5556 + }
5557 + digital_gain_0db_limit =
5558 + !of_property_read_bool(pdev->dev.of_node,
5559 + "allo,24db_digital_gain");
5560 +
5561 + glb_mclk = of_property_read_bool(pdev->dev.of_node,
5562 + "allo,glb_mclk");
5563 +
5564 + allo_piano_2_1_codecs[0].of_node =
5565 + of_parse_phandle(pdev->dev.of_node, "audio-codec", 0);
5566 + if (!allo_piano_2_1_codecs[0].of_node) {
5567 + dev_err(&pdev->dev,
5568 + "Property 'audio-codec' missing or invalid\n");
5569 + return -EINVAL;
5570 + }
5571 +
5572 + allo_piano_2_1_codecs[1].of_node =
5573 + of_parse_phandle(pdev->dev.of_node, "audio-codec", 1);
5574 + if (!allo_piano_2_1_codecs[1].of_node) {
5575 + dev_err(&pdev->dev,
5576 + "Property 'audio-codec' missing or invalid\n");
5577 + return -EINVAL;
5578 + }
5579 +
5580 + mute_gpio[0] = devm_gpiod_get_optional(&pdev->dev, "mute1",
5581 + GPIOD_OUT_LOW);
5582 + if (IS_ERR(mute_gpio[0])) {
5583 + ret = PTR_ERR(mute_gpio[0]);
5584 + dev_err(&pdev->dev,
5585 + "failed to get mute1 gpio6: %d\n", ret);
5586 + return ret;
5587 + }
5588 +
5589 + mute_gpio[1] = devm_gpiod_get_optional(&pdev->dev, "mute2",
5590 + GPIOD_OUT_LOW);
5591 + if (IS_ERR(mute_gpio[1])) {
5592 + ret = PTR_ERR(mute_gpio[1]);
5593 + dev_err(&pdev->dev,
5594 + "failed to get mute2 gpio25: %d\n", ret);
5595 + return ret;
5596 + }
5597 +
5598 + if (mute_gpio[0] && mute_gpio[1])
5599 + snd_allo_piano_dac.set_bias_level =
5600 + snd_allo_piano_set_bias_level;
5601 +
5602 + ret = snd_soc_register_card(&snd_allo_piano_dac);
5603 + if (ret < 0) {
5604 + dev_err(&pdev->dev,
5605 + "snd_soc_register_card() failed: %d\n", ret);
5606 + return ret;
5607 + }
5608 +
5609 + if ((mute_gpio[0]) && (mute_gpio[1]))
5610 + snd_allo_piano_gpio_mute(&snd_allo_piano_dac);
5611 +
5612 + return 0;
5613 + }
5614 +
5615 + return -EINVAL;
5616 +}
5617 +
5618 +static int snd_allo_piano_dac_remove(struct platform_device *pdev)
5619 +{
5620 + struct snd_soc_card *card = platform_get_drvdata(pdev);
5621 +
5622 + kfree(&card->drvdata);
5623 + snd_allo_piano_gpio_mute(&snd_allo_piano_dac);
5624 + snd_soc_unregister_card(&snd_allo_piano_dac);
5625 + return 0;
5626 +}
5627 +
5628 +static const struct of_device_id snd_allo_piano_dac_of_match[] = {
5629 + { .compatible = "allo,piano-dac-plus", },
5630 + { /* sentinel */ },
5631 +};
5632 +
5633 +MODULE_DEVICE_TABLE(of, snd_allo_piano_dac_of_match);
5634 +
5635 +static struct platform_driver snd_allo_piano_dac_driver = {
5636 + .driver = {
5637 + .name = "snd-allo-piano-dac-plus",
5638 + .owner = THIS_MODULE,
5639 + .of_match_table = snd_allo_piano_dac_of_match,
5640 + },
5641 + .probe = snd_allo_piano_dac_probe,
5642 + .remove = snd_allo_piano_dac_remove,
5643 +};
5644 +
5645 +module_platform_driver(snd_allo_piano_dac_driver);
5646 +
5647 +MODULE_AUTHOR("Baswaraj K <jaikumar@cem-solutions.net>");
5648 +MODULE_DESCRIPTION("ALSA ASoC Machine Driver for Allo Piano DAC Plus");
5649 +MODULE_LICENSE("GPL v2");
5650 --- /dev/null
5651 +++ b/sound/soc/bcm/allo-piano-dac.c
5652 @@ -0,0 +1,122 @@
5653 +/*
5654 + * ALSA ASoC Machine Driver for Allo Piano DAC
5655 + *
5656 + * Author: Baswaraj K <jaikumar@cem-solutions.net>
5657 + * Copyright 2016
5658 + * based on code by Daniel Matuschek <info@crazy-audio.com>
5659 + * based on code by Florian Meier <florian.meier@koalo.de>
5660 + *
5661 + * This program is free software; you can redistribute it and/or
5662 + * modify it under the terms of the GNU General Public License
5663 + * version 2 as published by the Free Software Foundation.
5664 + *
5665 + * This program is distributed in the hope that it will be useful, but
5666 + * WITHOUT ANY WARRANTY; without even the implied warranty of
5667 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5668 + * General Public License for more details.
5669 + */
5670 +
5671 +#include <linux/module.h>
5672 +#include <linux/platform_device.h>
5673 +
5674 +#include <sound/core.h>
5675 +#include <sound/pcm.h>
5676 +#include <sound/pcm_params.h>
5677 +#include <sound/soc.h>
5678 +
5679 +static bool digital_gain_0db_limit = true;
5680 +
5681 +static int snd_allo_piano_dac_init(struct snd_soc_pcm_runtime *rtd)
5682 +{
5683 + if (digital_gain_0db_limit) {
5684 + int ret;
5685 + struct snd_soc_card *card = rtd->card;
5686 +
5687 + ret = snd_soc_limit_volume(card, "Digital Playback Volume",
5688 + 207);
5689 + if (ret < 0)
5690 + dev_warn(card->dev, "Failed to set volume limit: %d\n",
5691 + ret);
5692 + }
5693 +
5694 + return 0;
5695 +}
5696 +
5697 +SND_SOC_DAILINK_DEFS(allo_piano_dai,
5698 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
5699 + DAILINK_COMP_ARRAY(COMP_CODEC("pcm512x.1-004c", "pcm512x-hifi")),
5700 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
5701 +
5702 +static struct snd_soc_dai_link snd_allo_piano_dac_dai[] = {
5703 +{
5704 + .name = "Piano DAC",
5705 + .stream_name = "Piano DAC HiFi",
5706 + .dai_fmt = SND_SOC_DAIFMT_I2S |
5707 + SND_SOC_DAIFMT_NB_NF |
5708 + SND_SOC_DAIFMT_CBS_CFS,
5709 + .init = snd_allo_piano_dac_init,
5710 + SND_SOC_DAILINK_REG(allo_piano_dai),
5711 +},
5712 +};
5713 +
5714 +/* audio machine driver */
5715 +static struct snd_soc_card snd_allo_piano_dac = {
5716 + .name = "PianoDAC",
5717 + .owner = THIS_MODULE,
5718 + .dai_link = snd_allo_piano_dac_dai,
5719 + .num_links = ARRAY_SIZE(snd_allo_piano_dac_dai),
5720 +};
5721 +
5722 +static int snd_allo_piano_dac_probe(struct platform_device *pdev)
5723 +{
5724 + int ret = 0;
5725 +
5726 + snd_allo_piano_dac.dev = &pdev->dev;
5727 +
5728 + if (pdev->dev.of_node) {
5729 + struct device_node *i2s_node;
5730 + struct snd_soc_dai_link *dai;
5731 +
5732 + dai = &snd_allo_piano_dac_dai[0];
5733 + i2s_node = of_parse_phandle(pdev->dev.of_node,
5734 + "i2s-controller", 0);
5735 +
5736 + if (i2s_node) {
5737 + dai->cpus->dai_name = NULL;
5738 + dai->cpus->of_node = i2s_node;
5739 + dai->platforms->name = NULL;
5740 + dai->platforms->of_node = i2s_node;
5741 + }
5742 +
5743 + digital_gain_0db_limit = !of_property_read_bool(
5744 + pdev->dev.of_node, "allo,24db_digital_gain");
5745 + }
5746 +
5747 + ret = devm_snd_soc_register_card(&pdev->dev, &snd_allo_piano_dac);
5748 + if (ret && ret != -EPROBE_DEFER)
5749 + dev_err(&pdev->dev,
5750 + "snd_soc_register_card() failed: %d\n", ret);
5751 +
5752 + return ret;
5753 +}
5754 +
5755 +static const struct of_device_id snd_allo_piano_dac_of_match[] = {
5756 + { .compatible = "allo,piano-dac", },
5757 + { /* sentinel */ },
5758 +};
5759 +MODULE_DEVICE_TABLE(of, snd_allo_piano_dac_of_match);
5760 +
5761 +static struct platform_driver snd_allo_piano_dac_driver = {
5762 + .driver = {
5763 + .name = "snd-allo-piano-dac",
5764 + .owner = THIS_MODULE,
5765 + .of_match_table = snd_allo_piano_dac_of_match,
5766 + },
5767 + .probe = snd_allo_piano_dac_probe,
5768 +};
5769 +
5770 +module_platform_driver(snd_allo_piano_dac_driver);
5771 +
5772 +MODULE_AUTHOR("Baswaraj K <jaikumar@cem-solutions.net>");
5773 +MODULE_DESCRIPTION("ALSA ASoC Machine Driver for Allo Piano DAC");
5774 +MODULE_LICENSE("GPL v2");
5775 --- /dev/null
5776 +++ b/sound/soc/bcm/audioinjector-isolated-soundcard.c
5777 @@ -0,0 +1,183 @@
5778 +/*
5779 + * ASoC Driver for AudioInjector.net isolated soundcard
5780 + *
5781 + * Created on: 20-February-2020
5782 + * Author: flatmax@flatmax.org
5783 + * based on audioinjector-octo-soundcard.c
5784 + *
5785 + * Copyright (C) 2020 Flatmax Pty. Ltd.
5786 + *
5787 + * This program is free software; you can redistribute it and/or
5788 + * modify it under the terms of the GNU General Public License
5789 + * version 2 as published by the Free Software Foundation.
5790 + *
5791 + * This program is distributed in the hope that it will be useful, but
5792 + * WITHOUT ANY WARRANTY; without even the implied warranty of
5793 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5794 + * General Public License for more details.
5795 + */
5796 +
5797 +#include <linux/module.h>
5798 +#include <linux/types.h>
5799 +#include <linux/gpio/consumer.h>
5800 +
5801 +#include <sound/core.h>
5802 +#include <sound/soc.h>
5803 +#include <sound/pcm_params.h>
5804 +#include <sound/control.h>
5805 +
5806 +static struct gpio_desc *mute_gpio;
5807 +
5808 +static const unsigned int audioinjector_isolated_rates[] = {
5809 + 192000, 96000, 48000, 32000, 24000, 16000, 8000
5810 +};
5811 +
5812 +static struct snd_pcm_hw_constraint_list audioinjector_isolated_constraints = {
5813 + .list = audioinjector_isolated_rates,
5814 + .count = ARRAY_SIZE(audioinjector_isolated_rates),
5815 +};
5816 +
5817 +static int audioinjector_isolated_dai_init(struct snd_soc_pcm_runtime *rtd)
5818 +{
5819 + int ret=snd_soc_dai_set_sysclk(asoc_rtd_to_codec(rtd, 0), 0, 24576000, 0);
5820 + if (ret)
5821 + return ret;
5822 +
5823 + return snd_soc_dai_set_bclk_ratio(asoc_rtd_to_cpu(rtd, 0), 64);
5824 +}
5825 +
5826 +static int audioinjector_isolated_startup(struct snd_pcm_substream *substream)
5827 +{
5828 + snd_pcm_hw_constraint_list(substream->runtime, 0,
5829 + SNDRV_PCM_HW_PARAM_RATE, &audioinjector_isolated_constraints);
5830 +
5831 + return 0;
5832 +}
5833 +
5834 +static int audioinjector_isolated_trigger(struct snd_pcm_substream *substream,
5835 + int cmd){
5836 +
5837 + switch (cmd) {
5838 + case SNDRV_PCM_TRIGGER_STOP:
5839 + case SNDRV_PCM_TRIGGER_SUSPEND:
5840 + case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
5841 + gpiod_set_value(mute_gpio, 0);
5842 + break;
5843 + case SNDRV_PCM_TRIGGER_START:
5844 + case SNDRV_PCM_TRIGGER_RESUME:
5845 + case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
5846 + gpiod_set_value(mute_gpio, 1);
5847 + break;
5848 + default:
5849 + return -EINVAL;
5850 + }
5851 + return 0;
5852 +}
5853 +
5854 +static struct snd_soc_ops audioinjector_isolated_ops = {
5855 + .startup = audioinjector_isolated_startup,
5856 + .trigger = audioinjector_isolated_trigger,
5857 +};
5858 +
5859 +SND_SOC_DAILINK_DEFS(audioinjector_isolated,
5860 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
5861 + DAILINK_COMP_ARRAY(COMP_CODEC("cs4271.1-0010", "cs4271-hifi")),
5862 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
5863 +
5864 +static struct snd_soc_dai_link audioinjector_isolated_dai[] = {
5865 + {
5866 + .name = "AudioInjector ISO",
5867 + .stream_name = "AI-HIFI",
5868 + .ops = &audioinjector_isolated_ops,
5869 + .init = audioinjector_isolated_dai_init,
5870 + .symmetric_rate = 1,
5871 + .symmetric_channels = 1,
5872 + .dai_fmt = SND_SOC_DAIFMT_CBM_CFM|SND_SOC_DAIFMT_I2S|SND_SOC_DAIFMT_NB_NF,
5873 + SND_SOC_DAILINK_REG(audioinjector_isolated),
5874 + }
5875 +};
5876 +
5877 +static const struct snd_soc_dapm_widget audioinjector_isolated_widgets[] = {
5878 + SND_SOC_DAPM_OUTPUT("OUTPUTS"),
5879 + SND_SOC_DAPM_INPUT("INPUTS"),
5880 +};
5881 +
5882 +static const struct snd_soc_dapm_route audioinjector_isolated_route[] = {
5883 + /* Balanced outputs */
5884 + {"OUTPUTS", NULL, "AOUTA+"},
5885 + {"OUTPUTS", NULL, "AOUTA-"},
5886 + {"OUTPUTS", NULL, "AOUTB+"},
5887 + {"OUTPUTS", NULL, "AOUTB-"},
5888 +
5889 + /* Balanced inputs */
5890 + {"AINA", NULL, "INPUTS"},
5891 + {"AINB", NULL, "INPUTS"},
5892 +};
5893 +
5894 +static struct snd_soc_card snd_soc_audioinjector_isolated = {
5895 + .name = "audioinjector-isolated-soundcard",
5896 + .dai_link = audioinjector_isolated_dai,
5897 + .num_links = ARRAY_SIZE(audioinjector_isolated_dai),
5898 +
5899 + .dapm_widgets = audioinjector_isolated_widgets,
5900 + .num_dapm_widgets = ARRAY_SIZE(audioinjector_isolated_widgets),
5901 + .dapm_routes = audioinjector_isolated_route,
5902 + .num_dapm_routes = ARRAY_SIZE(audioinjector_isolated_route),
5903 +};
5904 +
5905 +static int audioinjector_isolated_probe(struct platform_device *pdev)
5906 +{
5907 + struct snd_soc_card *card = &snd_soc_audioinjector_isolated;
5908 + int ret;
5909 +
5910 + card->dev = &pdev->dev;
5911 +
5912 + if (pdev->dev.of_node) {
5913 + struct snd_soc_dai_link *dai = &audioinjector_isolated_dai[0];
5914 + struct device_node *i2s_node =
5915 + of_parse_phandle(pdev->dev.of_node, "i2s-controller", 0);
5916 +
5917 + if (i2s_node) {
5918 + dai->cpus->dai_name = NULL;
5919 + dai->cpus->of_node = i2s_node;
5920 + dai->platforms->name = NULL;
5921 + dai->platforms->of_node = i2s_node;
5922 + } else {
5923 + dev_err(&pdev->dev,
5924 + "i2s-controller missing or invalid in DT\n");
5925 + return -EINVAL;
5926 + }
5927 +
5928 + mute_gpio = devm_gpiod_get_optional(&pdev->dev, "mute", GPIOD_OUT_LOW);
5929 + if (IS_ERR(mute_gpio)){
5930 + dev_err(&pdev->dev, "mute gpio not found in dt overlay\n");
5931 + return PTR_ERR(mute_gpio);
5932 + }
5933 + }
5934 +
5935 + ret = devm_snd_soc_register_card(&pdev->dev, card);
5936 + if (ret && ret != -EPROBE_DEFER)
5937 + dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret);
5938 + return ret;
5939 +}
5940 +
5941 +static const struct of_device_id audioinjector_isolated_of_match[] = {
5942 + { .compatible = "ai,audioinjector-isolated-soundcard", },
5943 + {},
5944 +};
5945 +MODULE_DEVICE_TABLE(of, audioinjector_isolated_of_match);
5946 +
5947 +static struct platform_driver audioinjector_isolated_driver = {
5948 + .driver = {
5949 + .name = "audioinjector-isolated",
5950 + .owner = THIS_MODULE,
5951 + .of_match_table = audioinjector_isolated_of_match,
5952 + },
5953 + .probe = audioinjector_isolated_probe,
5954 +};
5955 +
5956 +module_platform_driver(audioinjector_isolated_driver);
5957 +MODULE_AUTHOR("Matt Flax <flatmax@flatmax.org>");
5958 +MODULE_DESCRIPTION("AudioInjector.net isolated Soundcard");
5959 +MODULE_LICENSE("GPL v2");
5960 +MODULE_ALIAS("platform:audioinjector-isolated-soundcard");
5961 --- /dev/null
5962 +++ b/sound/soc/bcm/audioinjector-octo-soundcard.c
5963 @@ -0,0 +1,346 @@
5964 +/*
5965 + * ASoC Driver for AudioInjector Pi octo channel soundcard (hat)
5966 + *
5967 + * Created on: 27-October-2016
5968 + * Author: flatmax@flatmax.org
5969 + * based on audioinjector-pi-soundcard.c
5970 + *
5971 + * Copyright (C) 2016 Flatmax Pty. Ltd.
5972 + *
5973 + * This program is free software; you can redistribute it and/or
5974 + * modify it under the terms of the GNU General Public License
5975 + * version 2 as published by the Free Software Foundation.
5976 + *
5977 + * This program is distributed in the hope that it will be useful, but
5978 + * WITHOUT ANY WARRANTY; without even the implied warranty of
5979 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5980 + * General Public License for more details.
5981 + */
5982 +
5983 +#include <linux/module.h>
5984 +#include <linux/types.h>
5985 +#include <linux/gpio/consumer.h>
5986 +
5987 +#include <sound/core.h>
5988 +#include <sound/soc.h>
5989 +#include <sound/pcm_params.h>
5990 +#include <sound/control.h>
5991 +
5992 +static struct gpio_descs *mult_gpios;
5993 +static struct gpio_desc *codec_rst_gpio;
5994 +static unsigned int audioinjector_octo_rate;
5995 +static bool non_stop_clocks;
5996 +
5997 +static const unsigned int audioinjector_octo_rates[] = {
5998 + 96000, 48000, 32000, 24000, 16000, 8000, 88200, 44100, 29400, 22050, 14700,
5999 +};
6000 +
6001 +static struct snd_pcm_hw_constraint_list audioinjector_octo_constraints = {
6002 + .list = audioinjector_octo_rates,
6003 + .count = ARRAY_SIZE(audioinjector_octo_rates),
6004 +};
6005 +
6006 +static int audioinjector_octo_dai_init(struct snd_soc_pcm_runtime *rtd)
6007 +{
6008 + return snd_soc_dai_set_bclk_ratio(asoc_rtd_to_cpu(rtd, 0), 64);
6009 +}
6010 +
6011 +static int audioinjector_octo_startup(struct snd_pcm_substream *substream)
6012 +{
6013 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
6014 + asoc_rtd_to_cpu(rtd, 0)->driver->playback.channels_min = 8;
6015 + asoc_rtd_to_cpu(rtd, 0)->driver->playback.channels_max = 8;
6016 + asoc_rtd_to_cpu(rtd, 0)->driver->capture.channels_min = 8;
6017 + asoc_rtd_to_cpu(rtd, 0)->driver->capture.channels_max = 8;
6018 + asoc_rtd_to_codec(rtd, 0)->driver->capture.channels_max = 8;
6019 +
6020 + snd_pcm_hw_constraint_list(substream->runtime, 0,
6021 + SNDRV_PCM_HW_PARAM_RATE,
6022 + &audioinjector_octo_constraints);
6023 +
6024 + return 0;
6025 +}
6026 +
6027 +static void audioinjector_octo_shutdown(struct snd_pcm_substream *substream)
6028 +{
6029 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
6030 + asoc_rtd_to_cpu(rtd, 0)->driver->playback.channels_min = 2;
6031 + asoc_rtd_to_cpu(rtd, 0)->driver->playback.channels_max = 2;
6032 + asoc_rtd_to_cpu(rtd, 0)->driver->capture.channels_min = 2;
6033 + asoc_rtd_to_cpu(rtd, 0)->driver->capture.channels_max = 2;
6034 + asoc_rtd_to_codec(rtd, 0)->driver->capture.channels_max = 6;
6035 +}
6036 +
6037 +static int audioinjector_octo_hw_params(struct snd_pcm_substream *substream,
6038 + struct snd_pcm_hw_params *params)
6039 +{
6040 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
6041 +
6042 + // set codec DAI configuration
6043 + int ret = snd_soc_dai_set_fmt(asoc_rtd_to_codec(rtd, 0),
6044 + SND_SOC_DAIFMT_CBS_CFS|SND_SOC_DAIFMT_DSP_A|
6045 + SND_SOC_DAIFMT_NB_NF);
6046 + if (ret < 0)
6047 + return ret;
6048 +
6049 + // set cpu DAI configuration
6050 + ret = snd_soc_dai_set_fmt(asoc_rtd_to_cpu(rtd, 0),
6051 + SND_SOC_DAIFMT_CBM_CFM|SND_SOC_DAIFMT_I2S|
6052 + SND_SOC_DAIFMT_NB_NF);
6053 + if (ret < 0)
6054 + return ret;
6055 +
6056 + audioinjector_octo_rate = params_rate(params);
6057 +
6058 + // Set the correct sysclock for the codec
6059 + switch (audioinjector_octo_rate) {
6060 + case 96000:
6061 + case 48000:
6062 + return snd_soc_dai_set_sysclk(asoc_rtd_to_codec(rtd, 0), 0, 49152000,
6063 + 0);
6064 + break;
6065 + case 24000:
6066 + return snd_soc_dai_set_sysclk(asoc_rtd_to_codec(rtd, 0), 0, 49152000/2,
6067 + 0);
6068 + break;
6069 + case 32000:
6070 + case 16000:
6071 + return snd_soc_dai_set_sysclk(asoc_rtd_to_codec(rtd, 0), 0, 49152000/3,
6072 + 0);
6073 + break;
6074 + case 8000:
6075 + return snd_soc_dai_set_sysclk(asoc_rtd_to_codec(rtd, 0), 0, 49152000/6,
6076 + 0);
6077 + break;
6078 + case 88200:
6079 + case 44100:
6080 + return snd_soc_dai_set_sysclk(asoc_rtd_to_codec(rtd, 0), 0, 45185400,
6081 + 0);
6082 + break;
6083 + case 22050:
6084 + return snd_soc_dai_set_sysclk(asoc_rtd_to_codec(rtd, 0), 0, 45185400/2,
6085 + 0);
6086 + break;
6087 + case 29400:
6088 + case 14700:
6089 + return snd_soc_dai_set_sysclk(asoc_rtd_to_codec(rtd, 0), 0, 45185400/3,
6090 + 0);
6091 + break;
6092 + default:
6093 + return -EINVAL;
6094 + }
6095 +}
6096 +
6097 +static int audioinjector_octo_trigger(struct snd_pcm_substream *substream,
6098 + int cmd){
6099 + DECLARE_BITMAP(mult, 4);
6100 +
6101 + memset(mult, 0, sizeof(mult));
6102 +
6103 + switch (cmd) {
6104 + case SNDRV_PCM_TRIGGER_STOP:
6105 + case SNDRV_PCM_TRIGGER_SUSPEND:
6106 + case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
6107 + if (!non_stop_clocks)
6108 + break;
6109 + fallthrough;
6110 + case SNDRV_PCM_TRIGGER_START:
6111 + case SNDRV_PCM_TRIGGER_RESUME:
6112 + case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
6113 + switch (audioinjector_octo_rate) {
6114 + case 96000:
6115 + __assign_bit(3, mult, 1);
6116 + fallthrough;
6117 + case 88200:
6118 + __assign_bit(1, mult, 1);
6119 + __assign_bit(2, mult, 1);
6120 + break;
6121 + case 48000:
6122 + __assign_bit(3, mult, 1);
6123 + fallthrough;
6124 + case 44100:
6125 + __assign_bit(2, mult, 1);
6126 + break;
6127 + case 32000:
6128 + __assign_bit(3, mult, 1);
6129 + fallthrough;
6130 + case 29400:
6131 + __assign_bit(0, mult, 1);
6132 + __assign_bit(1, mult, 1);
6133 + break;
6134 + case 24000:
6135 + __assign_bit(3, mult, 1);
6136 + fallthrough;
6137 + case 22050:
6138 + __assign_bit(1, mult, 1);
6139 + break;
6140 + case 16000:
6141 + __assign_bit(3, mult, 1);
6142 + fallthrough;
6143 + case 14700:
6144 + __assign_bit(0, mult, 1);
6145 + break;
6146 + case 8000:
6147 + __assign_bit(3, mult, 1);
6148 + break;
6149 + default:
6150 + return -EINVAL;
6151 + }
6152 + break;
6153 + default:
6154 + return -EINVAL;
6155 + }
6156 + gpiod_set_array_value_cansleep(mult_gpios->ndescs, mult_gpios->desc,
6157 + NULL, mult);
6158 +
6159 + return 0;
6160 +}
6161 +
6162 +static struct snd_soc_ops audioinjector_octo_ops = {
6163 + .startup = audioinjector_octo_startup,
6164 + .shutdown = audioinjector_octo_shutdown,
6165 + .hw_params = audioinjector_octo_hw_params,
6166 + .trigger = audioinjector_octo_trigger,
6167 +};
6168 +
6169 +SND_SOC_DAILINK_DEFS(audioinjector_octo,
6170 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
6171 + DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "cs42448")),
6172 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
6173 +
6174 +static struct snd_soc_dai_link audioinjector_octo_dai[] = {
6175 + {
6176 + .name = "AudioInjector Octo",
6177 + .stream_name = "AudioInject-HIFI",
6178 + .ops = &audioinjector_octo_ops,
6179 + .init = audioinjector_octo_dai_init,
6180 + .symmetric_rate = 1,
6181 + .symmetric_channels = 1,
6182 + SND_SOC_DAILINK_REG(audioinjector_octo),
6183 + },
6184 +};
6185 +
6186 +static const struct snd_soc_dapm_widget audioinjector_octo_widgets[] = {
6187 + SND_SOC_DAPM_OUTPUT("OUTPUTS0"),
6188 + SND_SOC_DAPM_OUTPUT("OUTPUTS1"),
6189 + SND_SOC_DAPM_OUTPUT("OUTPUTS2"),
6190 + SND_SOC_DAPM_OUTPUT("OUTPUTS3"),
6191 + SND_SOC_DAPM_INPUT("INPUTS0"),
6192 + SND_SOC_DAPM_INPUT("INPUTS1"),
6193 + SND_SOC_DAPM_INPUT("INPUTS2"),
6194 +};
6195 +
6196 +static const struct snd_soc_dapm_route audioinjector_octo_route[] = {
6197 + /* Balanced outputs */
6198 + {"OUTPUTS0", NULL, "AOUT1L"},
6199 + {"OUTPUTS0", NULL, "AOUT1R"},
6200 + {"OUTPUTS1", NULL, "AOUT2L"},
6201 + {"OUTPUTS1", NULL, "AOUT2R"},
6202 + {"OUTPUTS2", NULL, "AOUT3L"},
6203 + {"OUTPUTS2", NULL, "AOUT3R"},
6204 + {"OUTPUTS3", NULL, "AOUT4L"},
6205 + {"OUTPUTS3", NULL, "AOUT4R"},
6206 +
6207 + /* Balanced inputs */
6208 + {"AIN1L", NULL, "INPUTS0"},
6209 + {"AIN1R", NULL, "INPUTS0"},
6210 + {"AIN2L", NULL, "INPUTS1"},
6211 + {"AIN2R", NULL, "INPUTS1"},
6212 + {"AIN3L", NULL, "INPUTS2"},
6213 + {"AIN3R", NULL, "INPUTS2"},
6214 +};
6215 +
6216 +static struct snd_soc_card snd_soc_audioinjector_octo = {
6217 + .name = "audioinjector-octo-soundcard",
6218 + .dai_link = audioinjector_octo_dai,
6219 + .num_links = ARRAY_SIZE(audioinjector_octo_dai),
6220 +
6221 + .dapm_widgets = audioinjector_octo_widgets,
6222 + .num_dapm_widgets = ARRAY_SIZE(audioinjector_octo_widgets),
6223 + .dapm_routes = audioinjector_octo_route,
6224 + .num_dapm_routes = ARRAY_SIZE(audioinjector_octo_route),
6225 +};
6226 +
6227 +static int audioinjector_octo_probe(struct platform_device *pdev)
6228 +{
6229 + struct snd_soc_card *card = &snd_soc_audioinjector_octo;
6230 + int ret;
6231 +
6232 + card->dev = &pdev->dev;
6233 +
6234 + if (pdev->dev.of_node) {
6235 + struct snd_soc_dai_link *dai = &audioinjector_octo_dai[0];
6236 + struct device_node *i2s_node =
6237 + of_parse_phandle(pdev->dev.of_node,
6238 + "i2s-controller", 0);
6239 + struct device_node *codec_node =
6240 + of_parse_phandle(pdev->dev.of_node,
6241 + "codec", 0);
6242 +
6243 + mult_gpios = devm_gpiod_get_array_optional(&pdev->dev, "mult",
6244 + GPIOD_OUT_LOW);
6245 + if (IS_ERR(mult_gpios))
6246 + return PTR_ERR(mult_gpios);
6247 +
6248 + codec_rst_gpio = devm_gpiod_get_optional(&pdev->dev, "reset",
6249 + GPIOD_OUT_LOW);
6250 + if (IS_ERR(codec_rst_gpio))
6251 + return PTR_ERR(codec_rst_gpio);
6252 +
6253 + non_stop_clocks = of_property_read_bool(pdev->dev.of_node, "non-stop-clocks");
6254 +
6255 + if (codec_rst_gpio)
6256 + gpiod_set_value(codec_rst_gpio, 1);
6257 + msleep(500);
6258 + if (codec_rst_gpio)
6259 + gpiod_set_value(codec_rst_gpio, 0);
6260 + msleep(500);
6261 + if (codec_rst_gpio)
6262 + gpiod_set_value(codec_rst_gpio, 1);
6263 + msleep(500);
6264 +
6265 + if (i2s_node && codec_node) {
6266 + dai->cpus->dai_name = NULL;
6267 + dai->cpus->of_node = i2s_node;
6268 + dai->platforms->name = NULL;
6269 + dai->platforms->of_node = i2s_node;
6270 + dai->codecs->name = NULL;
6271 + dai->codecs->of_node = codec_node;
6272 + } else
6273 + if (!i2s_node) {
6274 + dev_err(&pdev->dev,
6275 + "i2s-controller missing or invalid in DT\n");
6276 + return -EINVAL;
6277 + } else {
6278 + dev_err(&pdev->dev,
6279 + "Property 'codec' missing or invalid\n");
6280 + return -EINVAL;
6281 + }
6282 + }
6283 +
6284 + ret = devm_snd_soc_register_card(&pdev->dev, card);
6285 + if (ret != 0)
6286 + dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret);
6287 + return ret;
6288 +}
6289 +
6290 +static const struct of_device_id audioinjector_octo_of_match[] = {
6291 + { .compatible = "ai,audioinjector-octo-soundcard", },
6292 + {},
6293 +};
6294 +MODULE_DEVICE_TABLE(of, audioinjector_octo_of_match);
6295 +
6296 +static struct platform_driver audioinjector_octo_driver = {
6297 + .driver = {
6298 + .name = "audioinjector-octo",
6299 + .owner = THIS_MODULE,
6300 + .of_match_table = audioinjector_octo_of_match,
6301 + },
6302 + .probe = audioinjector_octo_probe,
6303 +};
6304 +
6305 +module_platform_driver(audioinjector_octo_driver);
6306 +MODULE_AUTHOR("Matt Flax <flatmax@flatmax.org>");
6307 +MODULE_DESCRIPTION("AudioInjector.net octo Soundcard");
6308 +MODULE_LICENSE("GPL v2");
6309 +MODULE_ALIAS("platform:audioinjector-octo-soundcard");
6310 --- /dev/null
6311 +++ b/sound/soc/bcm/audioinjector-pi-soundcard.c
6312 @@ -0,0 +1,189 @@
6313 +/*
6314 + * ASoC Driver for AudioInjector Pi add on soundcard
6315 + *
6316 + * Created on: 13-May-2016
6317 + * Author: flatmax@flatmax.org
6318 + * based on code by Cliff Cai <Cliff.Cai@analog.com> for the ssm2602 machine blackfin.
6319 + * with help from Lars-Peter Clausen for simplifying the original code to use the dai_fmt field.
6320 + * i2s_node code taken from the other sound/soc/bcm machine drivers.
6321 + *
6322 + * Copyright (C) 2016 Flatmax Pty. Ltd.
6323 + *
6324 + * This program is free software; you can redistribute it and/or
6325 + * modify it under the terms of the GNU General Public License
6326 + * version 2 as published by the Free Software Foundation.
6327 + *
6328 + * This program is distributed in the hope that it will be useful, but
6329 + * WITHOUT ANY WARRANTY; without even the implied warranty of
6330 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6331 + * General Public License for more details.
6332 + */
6333 +
6334 +#include <linux/module.h>
6335 +#include <linux/types.h>
6336 +
6337 +#include <sound/core.h>
6338 +#include <sound/soc.h>
6339 +#include <sound/pcm_params.h>
6340 +#include <sound/control.h>
6341 +
6342 +#include "../codecs/wm8731.h"
6343 +
6344 +static const unsigned int bcm2835_rates_12000000[] = {
6345 + 8000, 16000, 32000, 44100, 48000, 96000, 88200,
6346 +};
6347 +
6348 +static struct snd_pcm_hw_constraint_list bcm2835_constraints_12000000 = {
6349 + .list = bcm2835_rates_12000000,
6350 + .count = ARRAY_SIZE(bcm2835_rates_12000000),
6351 +};
6352 +
6353 +static int snd_audioinjector_pi_soundcard_startup(struct snd_pcm_substream *substream)
6354 +{
6355 + /* Setup constraints, because there is a 12 MHz XTAL on the board */
6356 + snd_pcm_hw_constraint_list(substream->runtime, 0,
6357 + SNDRV_PCM_HW_PARAM_RATE,
6358 + &bcm2835_constraints_12000000);
6359 + return 0;
6360 +}
6361 +
6362 +static int snd_audioinjector_pi_soundcard_hw_params(struct snd_pcm_substream *substream,
6363 + struct snd_pcm_hw_params *params)
6364 +{
6365 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
6366 + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
6367 +
6368 + switch (params_rate(params)){
6369 + case 8000:
6370 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 1);
6371 + case 16000:
6372 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 750);
6373 + case 32000:
6374 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 375);
6375 + case 44100:
6376 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 272);
6377 + case 48000:
6378 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 250);
6379 + case 88200:
6380 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 136);
6381 + case 96000:
6382 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 125);
6383 + default:
6384 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 125);
6385 + }
6386 +}
6387 +
6388 +/* machine stream operations */
6389 +static struct snd_soc_ops snd_audioinjector_pi_soundcard_ops = {
6390 + .startup = snd_audioinjector_pi_soundcard_startup,
6391 + .hw_params = snd_audioinjector_pi_soundcard_hw_params,
6392 +};
6393 +
6394 +static int audioinjector_pi_soundcard_dai_init(struct snd_soc_pcm_runtime *rtd)
6395 +{
6396 + return snd_soc_dai_set_sysclk(asoc_rtd_to_codec(rtd, 0), WM8731_SYSCLK_XTAL, 12000000, SND_SOC_CLOCK_IN);
6397 +}
6398 +
6399 +SND_SOC_DAILINK_DEFS(audioinjector_pi,
6400 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
6401 + DAILINK_COMP_ARRAY(COMP_CODEC("wm8731.1-001a", "wm8731-hifi")),
6402 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2835-i2s.0")));
6403 +
6404 +static struct snd_soc_dai_link audioinjector_pi_soundcard_dai[] = {
6405 + {
6406 + .name = "AudioInjector audio",
6407 + .stream_name = "AudioInjector audio",
6408 + .ops = &snd_audioinjector_pi_soundcard_ops,
6409 + .init = audioinjector_pi_soundcard_dai_init,
6410 + .dai_fmt = SND_SOC_DAIFMT_CBM_CFM|SND_SOC_DAIFMT_I2S|SND_SOC_DAIFMT_NB_NF,
6411 + SND_SOC_DAILINK_REG(audioinjector_pi),
6412 + },
6413 +};
6414 +
6415 +static const struct snd_soc_dapm_widget wm8731_dapm_widgets[] = {
6416 + SND_SOC_DAPM_HP("Headphone Jack", NULL),
6417 + SND_SOC_DAPM_SPK("Ext Spk", NULL),
6418 + SND_SOC_DAPM_LINE("Line In Jacks", NULL),
6419 + SND_SOC_DAPM_MIC("Microphone", NULL),
6420 +};
6421 +
6422 +static const struct snd_soc_dapm_route audioinjector_audio_map[] = {
6423 + /* headphone connected to LHPOUT, RHPOUT */
6424 + {"Headphone Jack", NULL, "LHPOUT"},
6425 + {"Headphone Jack", NULL, "RHPOUT"},
6426 +
6427 + /* speaker connected to LOUT, ROUT */
6428 + {"Ext Spk", NULL, "ROUT"},
6429 + {"Ext Spk", NULL, "LOUT"},
6430 +
6431 + /* line inputs */
6432 + {"Line In Jacks", NULL, "Line Input"},
6433 +
6434 + /* mic is connected to Mic Jack, with WM8731 Mic Bias */
6435 + {"Microphone", NULL, "Mic Bias"},
6436 +};
6437 +
6438 +static struct snd_soc_card snd_soc_audioinjector = {
6439 + .name = "audioinjector-pi-soundcard",
6440 + .dai_link = audioinjector_pi_soundcard_dai,
6441 + .num_links = ARRAY_SIZE(audioinjector_pi_soundcard_dai),
6442 +
6443 + .dapm_widgets = wm8731_dapm_widgets,
6444 + .num_dapm_widgets = ARRAY_SIZE(wm8731_dapm_widgets),
6445 + .dapm_routes = audioinjector_audio_map,
6446 + .num_dapm_routes = ARRAY_SIZE(audioinjector_audio_map),
6447 +};
6448 +
6449 +static int audioinjector_pi_soundcard_probe(struct platform_device *pdev)
6450 +{
6451 + struct snd_soc_card *card = &snd_soc_audioinjector;
6452 + int ret;
6453 +
6454 + card->dev = &pdev->dev;
6455 +
6456 + if (pdev->dev.of_node) {
6457 + struct snd_soc_dai_link *dai = &audioinjector_pi_soundcard_dai[0];
6458 + struct device_node *i2s_node = of_parse_phandle(pdev->dev.of_node,
6459 + "i2s-controller", 0);
6460 +
6461 + if (i2s_node) {
6462 + dai->cpus->dai_name = NULL;
6463 + dai->cpus->of_node = i2s_node;
6464 + dai->platforms->name = NULL;
6465 + dai->platforms->of_node = i2s_node;
6466 + } else
6467 + if (!dai->cpus->of_node) {
6468 + dev_err(&pdev->dev, "Property 'i2s-controller' missing or invalid\n");
6469 + return -EINVAL;
6470 + }
6471 + }
6472 +
6473 + if ((ret = devm_snd_soc_register_card(&pdev->dev, card)))
6474 + return dev_err_probe(&pdev->dev, ret, "%s\n", __func__);
6475 +
6476 + dev_info(&pdev->dev, "successfully loaded\n");
6477 +
6478 + return ret;
6479 +}
6480 +
6481 +static const struct of_device_id audioinjector_pi_soundcard_of_match[] = {
6482 + { .compatible = "ai,audioinjector-pi-soundcard", },
6483 + {},
6484 +};
6485 +MODULE_DEVICE_TABLE(of, audioinjector_pi_soundcard_of_match);
6486 +
6487 +static struct platform_driver audioinjector_pi_soundcard_driver = {
6488 + .driver = {
6489 + .name = "audioinjector-stereo",
6490 + .owner = THIS_MODULE,
6491 + .of_match_table = audioinjector_pi_soundcard_of_match,
6492 + },
6493 + .probe = audioinjector_pi_soundcard_probe,
6494 +};
6495 +
6496 +module_platform_driver(audioinjector_pi_soundcard_driver);
6497 +MODULE_AUTHOR("Matt Flax <flatmax@flatmax.org>");
6498 +MODULE_DESCRIPTION("AudioInjector.net Pi Soundcard");
6499 +MODULE_LICENSE("GPL v2");
6500 +MODULE_ALIAS("platform:audioinjector-pi-soundcard");
6501 +
6502 --- /dev/null
6503 +++ b/sound/soc/bcm/audiosense-pi.c
6504 @@ -0,0 +1,248 @@
6505 +/*
6506 + * ASoC Driver for AudioSense add on soundcard
6507 + * Author:
6508 + * Bhargav A K <anur.bhargav@gmail.com>
6509 + * Copyright 2017
6510 + *
6511 + * This program is free software; you can redistribute it and/or
6512 + * modify it under the terms of the GNU General Public License
6513 + * version 2 as published by the Free Software Foundation.
6514 + *
6515 + * This program is distributed in the hope that it will be useful, but
6516 + * WITHOUT ANY WARRANTY; without even the implied warranty of
6517 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6518 + * General Public License for more details.
6519 + */
6520 +
6521 +#include <linux/module.h>
6522 +#include <linux/platform_device.h>
6523 +#include <linux/clk.h>
6524 +#include <linux/i2c.h>
6525 +#include <sound/core.h>
6526 +#include <sound/pcm.h>
6527 +#include <sound/pcm_params.h>
6528 +#include <sound/soc.h>
6529 +#include <sound/jack.h>
6530 +#include <sound/control.h>
6531 +
6532 +#include <sound/tlv320aic32x4.h>
6533 +#include "../codecs/tlv320aic32x4.h"
6534 +
6535 +#define AIC32X4_SYSCLK_XTAL 0x00
6536 +
6537 +/*
6538 + * Setup Codec Sample Rates and Channels
6539 + * Supported Rates:
6540 + * 8000, 11025, 16000, 22050, 32000, 44100, 48000, 64000, 88200, 96000,
6541 + */
6542 +static const unsigned int audiosense_pi_rate[] = {
6543 + 48000,
6544 +};
6545 +
6546 +static struct snd_pcm_hw_constraint_list audiosense_constraints_rates = {
6547 + .list = audiosense_pi_rate,
6548 + .count = ARRAY_SIZE(audiosense_pi_rate),
6549 +};
6550 +
6551 +static const unsigned int audiosense_pi_channels[] = {
6552 + 2,
6553 +};
6554 +
6555 +static struct snd_pcm_hw_constraint_list audiosense_constraints_ch = {
6556 + .count = ARRAY_SIZE(audiosense_pi_channels),
6557 + .list = audiosense_pi_channels,
6558 + .mask = 0,
6559 +};
6560 +
6561 +/* Setup DAPM widgets and paths */
6562 +static const struct snd_soc_dapm_widget audiosense_pi_dapm_widgets[] = {
6563 + SND_SOC_DAPM_HP("Headphone Jack", NULL),
6564 + SND_SOC_DAPM_LINE("Line Out", NULL),
6565 + SND_SOC_DAPM_LINE("Line In", NULL),
6566 + SND_SOC_DAPM_INPUT("CM_L"),
6567 + SND_SOC_DAPM_INPUT("CM_R"),
6568 +};
6569 +
6570 +static const struct snd_soc_dapm_route audiosense_pi_audio_map[] = {
6571 + /* Line Inputs are connected to
6572 + * (IN1_L | IN1_R)
6573 + * (IN2_L | IN2_R)
6574 + * (IN3_L | IN3_R)
6575 + */
6576 + {"IN1_L", NULL, "Line In"},
6577 + {"IN1_R", NULL, "Line In"},
6578 + {"IN2_L", NULL, "Line In"},
6579 + {"IN2_R", NULL, "Line In"},
6580 + {"IN3_L", NULL, "Line In"},
6581 + {"IN3_R", NULL, "Line In"},
6582 +
6583 + /* Mic is connected to IN2_L and IN2_R */
6584 + {"Left ADC", NULL, "Mic Bias"},
6585 + {"Right ADC", NULL, "Mic Bias"},
6586 +
6587 + /* Headphone connected to HPL, HPR */
6588 + {"Headphone Jack", NULL, "HPL"},
6589 + {"Headphone Jack", NULL, "HPR"},
6590 +
6591 + /* Speakers connected to LOL and LOR */
6592 + {"Line Out", NULL, "LOL"},
6593 + {"Line Out", NULL, "LOR"},
6594 +};
6595 +
6596 +static int audiosense_pi_card_init(struct snd_soc_pcm_runtime *rtd)
6597 +{
6598 + /* TODO: init of the codec specific dapm data, ignore suspend/resume */
6599 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
6600 +
6601 + snd_soc_component_update_bits(component, AIC32X4_MICBIAS, 0x78,
6602 + AIC32X4_MICBIAS_LDOIN |
6603 + AIC32X4_MICBIAS_2075V);
6604 + snd_soc_component_update_bits(component, AIC32X4_PWRCFG, 0x08,
6605 + AIC32X4_AVDDWEAKDISABLE);
6606 + snd_soc_component_update_bits(component, AIC32X4_LDOCTL, 0x01,
6607 + AIC32X4_LDOCTLEN);
6608 +
6609 + return 0;
6610 +}
6611 +
6612 +static int audiosense_pi_card_hw_params(
6613 + struct snd_pcm_substream *substream,
6614 + struct snd_pcm_hw_params *params)
6615 +{
6616 + int ret = 0;
6617 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
6618 + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
6619 +
6620 + /* Set the codec system clock, there is a 12 MHz XTAL on the board */
6621 + ret = snd_soc_dai_set_sysclk(codec_dai, AIC32X4_SYSCLK_XTAL,
6622 + 12000000, SND_SOC_CLOCK_IN);
6623 + if (ret) {
6624 + dev_err(rtd->card->dev,
6625 + "could not set codec driver clock params\n");
6626 + return ret;
6627 + }
6628 + return 0;
6629 +}
6630 +
6631 +static int audiosense_pi_card_startup(struct snd_pcm_substream *substream)
6632 +{
6633 + struct snd_pcm_runtime *runtime = substream->runtime;
6634 +
6635 + /*
6636 + * Set codec to 48Khz Sampling, Stereo I/O and 16 bit audio
6637 + */
6638 + runtime->hw.channels_max = 2;
6639 + snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
6640 + &audiosense_constraints_ch);
6641 +
6642 + runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE;
6643 + snd_pcm_hw_constraint_msbits(runtime, 0, 16, 16);
6644 +
6645 +
6646 + snd_pcm_hw_constraint_list(substream->runtime, 0,
6647 + SNDRV_PCM_HW_PARAM_RATE,
6648 + &audiosense_constraints_rates);
6649 + return 0;
6650 +}
6651 +
6652 +static struct snd_soc_ops audiosense_pi_card_ops = {
6653 + .startup = audiosense_pi_card_startup,
6654 + .hw_params = audiosense_pi_card_hw_params,
6655 +};
6656 +
6657 +SND_SOC_DAILINK_DEFS(audiosense_pi,
6658 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
6659 + DAILINK_COMP_ARRAY(COMP_CODEC("tlv320aic32x4.1-0018", "tlv320aic32x4-hifi")),
6660 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
6661 +
6662 +static struct snd_soc_dai_link audiosense_pi_card_dai[] = {
6663 + {
6664 + .name = "TLV320AIC3204 Audio",
6665 + .stream_name = "TLV320AIC3204 Hifi Audio",
6666 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
6667 + SND_SOC_DAIFMT_CBM_CFM,
6668 + .ops = &audiosense_pi_card_ops,
6669 + .init = audiosense_pi_card_init,
6670 + SND_SOC_DAILINK_REG(audiosense_pi),
6671 + },
6672 +};
6673 +
6674 +static struct snd_soc_card audiosense_pi_card = {
6675 + .name = "audiosense-pi",
6676 + .driver_name = "audiosense-pi",
6677 + .dai_link = audiosense_pi_card_dai,
6678 + .owner = THIS_MODULE,
6679 + .num_links = ARRAY_SIZE(audiosense_pi_card_dai),
6680 + .dapm_widgets = audiosense_pi_dapm_widgets,
6681 + .num_dapm_widgets = ARRAY_SIZE(audiosense_pi_dapm_widgets),
6682 + .dapm_routes = audiosense_pi_audio_map,
6683 + .num_dapm_routes = ARRAY_SIZE(audiosense_pi_audio_map),
6684 +};
6685 +
6686 +static int audiosense_pi_card_probe(struct platform_device *pdev)
6687 +{
6688 + int ret = 0;
6689 + struct snd_soc_card *card = &audiosense_pi_card;
6690 + struct snd_soc_dai_link *dai = &audiosense_pi_card_dai[0];
6691 + struct device_node *i2s_node = pdev->dev.of_node;
6692 +
6693 + card->dev = &pdev->dev;
6694 +
6695 + if (!dai) {
6696 + dev_err(&pdev->dev, "DAI not found. Missing or Invalid\n");
6697 + return -EINVAL;
6698 + }
6699 +
6700 + i2s_node = of_parse_phandle(pdev->dev.of_node, "i2s-controller", 0);
6701 + if (!i2s_node) {
6702 + dev_err(&pdev->dev,
6703 + "Property 'i2s-controller' missing or invalid\n");
6704 + return -EINVAL;
6705 + }
6706 +
6707 + dai->cpus->dai_name = NULL;
6708 + dai->cpus->of_node = i2s_node;
6709 + dai->platforms->name = NULL;
6710 + dai->platforms->of_node = i2s_node;
6711 +
6712 + of_node_put(i2s_node);
6713 +
6714 + ret = snd_soc_register_card(card);
6715 + if (ret && ret != -EPROBE_DEFER)
6716 + dev_err(&pdev->dev,
6717 + "snd_soc_register_card() failed: %d\n", ret);
6718 +
6719 + return ret;
6720 +}
6721 +
6722 +static int audiosense_pi_card_remove(struct platform_device *pdev)
6723 +{
6724 + struct snd_soc_card *card = platform_get_drvdata(pdev);
6725 +
6726 + snd_soc_unregister_card(card);
6727 + return 0;
6728 +}
6729 +
6730 +static const struct of_device_id audiosense_pi_card_of_match[] = {
6731 + { .compatible = "as,audiosense-pi", },
6732 + {},
6733 +};
6734 +MODULE_DEVICE_TABLE(of, audiosense_pi_card_of_match);
6735 +
6736 +static struct platform_driver audiosense_pi_card_driver = {
6737 + .driver = {
6738 + .name = "audiosense-snd-card",
6739 + .owner = THIS_MODULE,
6740 + .of_match_table = audiosense_pi_card_of_match,
6741 + },
6742 + .probe = audiosense_pi_card_probe,
6743 + .remove = audiosense_pi_card_remove,
6744 +};
6745 +
6746 +module_platform_driver(audiosense_pi_card_driver);
6747 +
6748 +MODULE_AUTHOR("Bhargav AK <anur.bhargav@gmail.com>");
6749 +MODULE_DESCRIPTION("ASoC Driver for TLV320AIC3204 Audio");
6750 +MODULE_LICENSE("GPL v2");
6751 +MODULE_ALIAS("platform:audiosense-pi");
6752 +
6753 --- /dev/null
6754 +++ b/sound/soc/bcm/chipdip-dac.c
6755 @@ -0,0 +1,275 @@
6756 +/*
6757 + * ASoC Driver for ChipDip DAC
6758 + *
6759 + * Author: Evgenij Sapunov
6760 + * Copyright 2021
6761 + * based on code by Milan Neskovic <info@justboom.co>
6762 + * based on code by Jaikumar <jaikumar@cem-solutions.net>
6763 + *
6764 + * Thanks to Phil Elwell (pelwell) for help.
6765 + *
6766 + * This program is free software; you can redistribute it and/or
6767 + * modify it under the terms of the GNU General Public License
6768 + * version 2 as published by the Free Software Foundation.
6769 + *
6770 + * This program is distributed in the hope that it will be useful, but
6771 + * WITHOUT ANY WARRANTY; without even the implied warranty of
6772 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6773 + * General Public License for more details.
6774 + */
6775 +
6776 +#include <linux/module.h>
6777 +#include <linux/gpio/consumer.h>
6778 +#include <linux/platform_device.h>
6779 +#include <linux/delay.h>
6780 +
6781 +#include <sound/core.h>
6782 +#include <sound/pcm.h>
6783 +#include <sound/pcm_params.h>
6784 +#include <sound/soc.h>
6785 +#include <sound/jack.h>
6786 +
6787 +#define SR_BIT_0 0 //sample rate bits
6788 +#define SR_BIT_1 1
6789 +#define SR_BIT_2 2
6790 +#define BD_BIT_0 3 //bit depth bits
6791 +#define BD_BIT_1 4
6792 +
6793 +#define SAMPLE_RATE_MASK_44_1 0
6794 +#define SAMPLE_RATE_MASK_48 (1 << SR_BIT_0)
6795 +#define SAMPLE_RATE_MASK_88_2 ((1 << SR_BIT_2) | (1 << SR_BIT_1))
6796 +#define SAMPLE_RATE_MASK_96 (1 << SR_BIT_1)
6797 +#define SAMPLE_RATE_MASK_176_4 ((1 << SR_BIT_2) | (1 << SR_BIT_1) | (1 << SR_BIT_0))
6798 +#define SAMPLE_RATE_MASK_192 ((1 << SR_BIT_1) | (1 << SR_BIT_0))
6799 +#define SAMPLE_RATE_MASK ((1 << SR_BIT_2) | (1 << SR_BIT_1) | (1 << SR_BIT_0))
6800 +
6801 +#define BIT_DEPTH_MASK_16 0
6802 +#define BIT_DEPTH_MASK_24 (1 << BD_BIT_0)
6803 +#define BIT_DEPTH_MASK_32 (1 << BD_BIT_1)
6804 +#define BIT_DEPTH_MASK ((1 << BD_BIT_1) | (1 << BD_BIT_0))
6805 +
6806 +#define MUTE_ACTIVE 0
6807 +#define MUTE_NOT_ACTIVE 1
6808 +
6809 +#define HW_PARAMS_GPIO_COUNT 5
6810 +
6811 +static struct gpio_desc *mute_gpio;
6812 +static struct gpio_desc *sdwn_gpio;
6813 +static struct gpio_desc *hw_params_gpios[HW_PARAMS_GPIO_COUNT];
6814 +static int current_width;
6815 +static int current_rate;
6816 +
6817 +static void snd_rpi_chipdip_dac_gpio_array_set(int value);
6818 +static void snd_rpi_chipdip_dac_gpio_set(struct gpio_desc *gpio_item, int value);
6819 +
6820 +static void snd_rpi_chipdip_dac_gpio_array_set(int value)
6821 +{
6822 + int i = 0;
6823 +
6824 + for (i = 0; i < HW_PARAMS_GPIO_COUNT; i++)
6825 + snd_rpi_chipdip_dac_gpio_set(hw_params_gpios[i], ((value >> i) & 1));
6826 +}
6827 +
6828 +static void snd_rpi_chipdip_dac_gpio_set(struct gpio_desc *gpio_item, int value)
6829 +{
6830 + if (gpio_item)
6831 + gpiod_set_value_cansleep(gpio_item, value);
6832 +}
6833 +
6834 +static int snd_rpi_chipdip_dac_init(struct snd_soc_pcm_runtime *rtd)
6835 +{
6836 + return 0;
6837 +}
6838 +
6839 +static int snd_rpi_chipdip_dac_hw_params(struct snd_pcm_substream *substream,
6840 + struct snd_pcm_hw_params *params)
6841 +{
6842 + int ret = 0;
6843 + int gpio_change_pending = 0;
6844 + int sample_rate_state = 0;
6845 + int bit_depth_state = 0;
6846 + int param_value = params_width(params);
6847 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
6848 +
6849 + ret = snd_soc_dai_set_bclk_ratio(asoc_rtd_to_cpu(rtd, 0), 2 * 32);
6850 +
6851 + if (current_width != param_value) {
6852 + current_width = param_value;
6853 + gpio_change_pending = 1;
6854 +
6855 + switch (param_value) {
6856 + case 16:
6857 + bit_depth_state = BIT_DEPTH_MASK_16;
6858 + break;
6859 + case 24:
6860 + bit_depth_state = BIT_DEPTH_MASK_24;
6861 + break;
6862 + case 32:
6863 + bit_depth_state = BIT_DEPTH_MASK_32;
6864 + break;
6865 + default:
6866 + return -EINVAL;
6867 + }
6868 + }
6869 +
6870 + param_value = params_rate(params);
6871 + if (current_rate != param_value) {
6872 + current_rate = param_value;
6873 + gpio_change_pending = 1;
6874 +
6875 + switch (param_value) {
6876 + case 44100:
6877 + sample_rate_state = SAMPLE_RATE_MASK_44_1;
6878 + break;
6879 + case 48000:
6880 + sample_rate_state = SAMPLE_RATE_MASK_48;
6881 + break;
6882 + case 88200:
6883 + sample_rate_state = SAMPLE_RATE_MASK_88_2;
6884 + break;
6885 + case 96000:
6886 + sample_rate_state = SAMPLE_RATE_MASK_96;
6887 + break;
6888 + case 176400:
6889 + sample_rate_state = SAMPLE_RATE_MASK_176_4;
6890 + break;
6891 + case 192000:
6892 + sample_rate_state = SAMPLE_RATE_MASK_192;
6893 + break;
6894 + default:
6895 + return -EINVAL;
6896 + }
6897 + }
6898 +
6899 + if (gpio_change_pending) {
6900 + snd_rpi_chipdip_dac_gpio_set(mute_gpio, MUTE_ACTIVE);
6901 + snd_rpi_chipdip_dac_gpio_array_set(bit_depth_state | sample_rate_state);
6902 + msleep(300);
6903 + snd_rpi_chipdip_dac_gpio_set(mute_gpio, MUTE_NOT_ACTIVE);
6904 + }
6905 +
6906 + return ret;
6907 +}
6908 +
6909 +static int snd_rpi_chipdip_dac_startup(struct snd_pcm_substream *substream)
6910 +{
6911 + return 0;
6912 +}
6913 +
6914 +static void snd_rpi_chipdip_dac_shutdown(struct snd_pcm_substream *substream)
6915 +{
6916 +
6917 +}
6918 +
6919 +/* machine stream operations */
6920 +static struct snd_soc_ops snd_rpi_chipdip_dac_ops = {
6921 + .hw_params = snd_rpi_chipdip_dac_hw_params,
6922 + .startup = snd_rpi_chipdip_dac_startup,
6923 + .shutdown = snd_rpi_chipdip_dac_shutdown,
6924 +};
6925 +
6926 +SND_SOC_DAILINK_DEFS(hifi,
6927 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
6928 + DAILINK_COMP_ARRAY(COMP_CODEC("spdif-transmitter", "dit-hifi")),
6929 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
6930 +
6931 +static struct snd_soc_dai_link snd_rpi_chipdip_dac_dai[] = {
6932 +{
6933 + .name = "ChipDip DAC",
6934 + .stream_name = "ChipDip DAC HiFi",
6935 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
6936 + SND_SOC_DAIFMT_CBM_CFM,
6937 + .ops = &snd_rpi_chipdip_dac_ops,
6938 + .init = snd_rpi_chipdip_dac_init,
6939 + SND_SOC_DAILINK_REG(hifi),
6940 +},
6941 +};
6942 +
6943 +/* audio machine driver */
6944 +static struct snd_soc_card snd_rpi_chipdip_dac = {
6945 + .name = "ChipDipDAC",
6946 + .driver_name = "ChipdipDac",
6947 + .owner = THIS_MODULE,
6948 + .dai_link = snd_rpi_chipdip_dac_dai,
6949 + .num_links = ARRAY_SIZE(snd_rpi_chipdip_dac_dai),
6950 +};
6951 +
6952 +static int snd_rpi_chipdip_dac_probe(struct platform_device *pdev)
6953 +{
6954 + int ret = 0;
6955 + int i = 0;
6956 +
6957 + snd_rpi_chipdip_dac.dev = &pdev->dev;
6958 +
6959 + if (pdev->dev.of_node) {
6960 + struct device_node *i2s_node;
6961 + struct snd_soc_dai_link *dai = &snd_rpi_chipdip_dac_dai[0];
6962 + i2s_node = of_parse_phandle(pdev->dev.of_node,
6963 + "i2s-controller", 0);
6964 +
6965 + if (i2s_node) {
6966 + dai->cpus->dai_name = NULL;
6967 + dai->cpus->of_node = i2s_node;
6968 + dai->platforms->name = NULL;
6969 + dai->platforms->of_node = i2s_node;
6970 + }
6971 + }
6972 +
6973 + hw_params_gpios[SR_BIT_0] = devm_gpiod_get_optional(&pdev->dev, "sr0", GPIOD_OUT_LOW);
6974 + hw_params_gpios[SR_BIT_1] = devm_gpiod_get_optional(&pdev->dev, "sr1", GPIOD_OUT_LOW);
6975 + hw_params_gpios[SR_BIT_2] = devm_gpiod_get_optional(&pdev->dev, "sr2", GPIOD_OUT_LOW);
6976 + hw_params_gpios[BD_BIT_0] = devm_gpiod_get_optional(&pdev->dev, "res0", GPIOD_OUT_LOW);
6977 + hw_params_gpios[BD_BIT_1] = devm_gpiod_get_optional(&pdev->dev, "res1", GPIOD_OUT_LOW);
6978 + mute_gpio = devm_gpiod_get_optional(&pdev->dev, "mute", GPIOD_OUT_LOW);
6979 + sdwn_gpio = devm_gpiod_get_optional(&pdev->dev, "sdwn", GPIOD_OUT_HIGH);
6980 +
6981 + for (i = 0; i < HW_PARAMS_GPIO_COUNT; i++) {
6982 + if (IS_ERR(hw_params_gpios[i])) {
6983 + ret = PTR_ERR(hw_params_gpios[i]);
6984 + dev_err(&pdev->dev, "failed to get hw_params gpio: %d\n", ret);
6985 + return ret;
6986 + }
6987 + }
6988 +
6989 + if (IS_ERR(mute_gpio)) {
6990 + ret = PTR_ERR(mute_gpio);
6991 + dev_err(&pdev->dev, "failed to get mute gpio: %d\n", ret);
6992 + return ret;
6993 + }
6994 +
6995 + if (IS_ERR(sdwn_gpio)) {
6996 + ret = PTR_ERR(sdwn_gpio);
6997 + dev_err(&pdev->dev, "failed to get sdwn gpio: %d\n", ret);
6998 + return ret;
6999 + }
7000 +
7001 + snd_rpi_chipdip_dac_gpio_set(sdwn_gpio, 1);
7002 +
7003 + ret = devm_snd_soc_register_card(&pdev->dev, &snd_rpi_chipdip_dac);
7004 + if (ret && ret != -EPROBE_DEFER)
7005 + dev_err(&pdev->dev,
7006 + "snd_soc_register_card() failed: %d\n", ret);
7007 +
7008 + return ret;
7009 +}
7010 +
7011 +static const struct of_device_id snd_rpi_chipdip_dac_of_match[] = {
7012 + { .compatible = "chipdip,chipdip-dac", },
7013 + {},
7014 +};
7015 +MODULE_DEVICE_TABLE(of, snd_rpi_chipdip_dac_of_match);
7016 +
7017 +static struct platform_driver snd_rpi_chipdip_dac_driver = {
7018 + .driver = {
7019 + .name = "snd-rpi-chipdip-dac",
7020 + .owner = THIS_MODULE,
7021 + .of_match_table = snd_rpi_chipdip_dac_of_match,
7022 + },
7023 + .probe = snd_rpi_chipdip_dac_probe,
7024 +};
7025 +
7026 +module_platform_driver(snd_rpi_chipdip_dac_driver);
7027 +
7028 +MODULE_AUTHOR("Evgenij Sapunov <evgenij.sapunov@chipdip.ru>");
7029 +MODULE_DESCRIPTION("ASoC Driver for ChipDip DAC");
7030 +MODULE_LICENSE("GPL v2");
7031 --- /dev/null
7032 +++ b/sound/soc/bcm/dacberry400.c
7033 @@ -0,0 +1,259 @@
7034 +/*
7035 + * ASoC Driver for Dacberry400 soundcard
7036 + * Author:
7037 + * Ashish Vara<ashishhvara@gmail.com>
7038 + * Copyright 2022
7039 + *
7040 + * This program is free software; you can redistribute it and/or
7041 + * modify it under the terms of the GNU General Public License
7042 + * version 2 as published by the Free Software Foundation.
7043 + *
7044 + * This program is distributed in the hope that it will be useful, but
7045 + * WITHOUT ANY WARRANTY; without even the implied warranty of
7046 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7047 + * General Public License for more details.
7048 + */
7049 +
7050 +#include <linux/module.h>
7051 +#include <linux/gpio/consumer.h>
7052 +#include <linux/platform_device.h>
7053 +#include <sound/core.h>
7054 +#include <sound/pcm.h>
7055 +#include <sound/pcm_params.h>
7056 +#include <sound/soc.h>
7057 +#include <sound/jack.h>
7058 +#include <linux/i2c.h>
7059 +#include <linux/acpi.h>
7060 +#include <linux/slab.h>
7061 +#include "../sound/soc/codecs/tlv320aic3x.h"
7062 +
7063 +static const struct snd_kcontrol_new dacberry400_controls[] = {
7064 + SOC_DAPM_PIN_SWITCH("MIC Jack"),
7065 + SOC_DAPM_PIN_SWITCH("Line In"),
7066 + SOC_DAPM_PIN_SWITCH("Line Out"),
7067 + SOC_DAPM_PIN_SWITCH("Headphone Jack"),
7068 +};
7069 +
7070 +static const struct snd_soc_dapm_widget dacberry400_widgets[] = {
7071 + SND_SOC_DAPM_HP("Headphone Jack", NULL),
7072 + SND_SOC_DAPM_MIC("MIC Jack", NULL),
7073 + SND_SOC_DAPM_LINE("Line In", NULL),
7074 + SND_SOC_DAPM_LINE("Line Out", NULL),
7075 +};
7076 +
7077 +static const struct snd_soc_dapm_route dacberry400_audio_map[] = {
7078 + {"Headphone Jack", NULL, "HPLOUT"},
7079 + {"Headphone Jack", NULL, "HPROUT"},
7080 +
7081 + {"LINE1L", NULL, "Line In"},
7082 + {"LINE1R", NULL, "Line In"},
7083 +
7084 + {"Line Out", NULL, "LLOUT"},
7085 + {"Line Out", NULL, "RLOUT"},
7086 +
7087 + {"MIC3L", NULL, "MIC Jack"},
7088 + {"MIC3R", NULL, "MIC Jack"},
7089 +};
7090 +
7091 +static int snd_rpi_dacberry400_init(struct snd_soc_pcm_runtime *rtd)
7092 +{
7093 + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
7094 + struct snd_soc_component *component = codec_dai->component;
7095 + int ret;
7096 +
7097 + ret = snd_soc_dai_set_sysclk(codec_dai, 2, 12000000,
7098 + SND_SOC_CLOCK_OUT);
7099 +
7100 + if (ret && ret != -ENOTSUPP)
7101 + goto err;
7102 +
7103 + snd_soc_component_write(component, HPRCOM_CFG, 0x20);
7104 + snd_soc_component_write(component, DACL1_2_HPLOUT_VOL, 0x80);
7105 + snd_soc_component_write(component, DACR1_2_HPROUT_VOL, 0x80);
7106 +err:
7107 + return ret;
7108 +}
7109 +
7110 +static int snd_rpi_dacberry400_set_bias_level(struct snd_soc_card *card,
7111 + struct snd_soc_dapm_context *dapm, enum snd_soc_bias_level level)
7112 +{
7113 + struct snd_soc_pcm_runtime *rtd;
7114 + struct snd_soc_dai *codec_dai;
7115 + struct snd_soc_component *component;
7116 + struct dacberry_priv *aic3x;
7117 + u8 hpcom_reg = 0;
7118 +
7119 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
7120 + codec_dai = asoc_rtd_to_codec(rtd, 0);
7121 + component = codec_dai->component;
7122 + aic3x = snd_soc_component_get_drvdata(component);
7123 + if (dapm->dev != codec_dai->dev)
7124 + return 0;
7125 +
7126 + switch (level) {
7127 + case SND_SOC_BIAS_PREPARE:
7128 + if (dapm->bias_level != SND_SOC_BIAS_STANDBY)
7129 + break;
7130 + /* UNMUTE ADC/DAC */
7131 + hpcom_reg = snd_soc_component_read(component, HPLCOM_CFG);
7132 + snd_soc_component_write(component, HPLCOM_CFG, hpcom_reg | 0x20);
7133 + snd_soc_component_write(component, LINE1R_2_RADC_CTRL, 0x04);
7134 + snd_soc_component_write(component, LINE1L_2_LADC_CTRL, 0x04);
7135 + snd_soc_component_write(component, LADC_VOL, 0x00);
7136 + snd_soc_component_write(component, RADC_VOL, 0x00);
7137 + pr_info("%s: unmute ADC/DAC\n", __func__);
7138 + break;
7139 +
7140 + case SND_SOC_BIAS_STANDBY:
7141 + if (dapm->bias_level != SND_SOC_BIAS_PREPARE)
7142 + break;
7143 + /* MUTE ADC/DAC */
7144 + snd_soc_component_write(component, LDAC_VOL, 0x80);
7145 + snd_soc_component_write(component, RDAC_VOL, 0x80);
7146 + snd_soc_component_write(component, LADC_VOL, 0x80);
7147 + snd_soc_component_write(component, RADC_VOL, 0x80);
7148 + snd_soc_component_write(component, LINE1R_2_RADC_CTRL, 0x00);
7149 + snd_soc_component_write(component, LINE1L_2_LADC_CTRL, 0x00);
7150 + snd_soc_component_write(component, HPLCOM_CFG, 0x00);
7151 + pr_info("%s: mute ADC/DAC\n", __func__);
7152 + break;
7153 + default:
7154 + break;
7155 + }
7156 +
7157 + return 0;
7158 +}
7159 +
7160 +static int snd_rpi_dacberry400_hw_params(struct snd_pcm_substream *substream,
7161 + struct snd_pcm_hw_params *params)
7162 +{
7163 + int ret = 0;
7164 + u8 data;
7165 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
7166 + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
7167 + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
7168 + struct snd_soc_component *component = codec_dai->component;
7169 + int fsref = (params_rate(params) % 11025 == 0) ? 44100 : 48000;
7170 + int channels = params_channels(params);
7171 + int width = 32;
7172 + u8 clock = 0;
7173 +
7174 + data = (LDAC2LCH | RDAC2RCH);
7175 + data |= (fsref == 44100) ? FSREF_44100 : FSREF_48000;
7176 + if (params_rate(params) >= 64000)
7177 + data |= DUAL_RATE_MODE;
7178 + ret = snd_soc_component_write(component, 0x7, data);
7179 + width = params_width(params);
7180 +
7181 + clock = snd_soc_component_read(component, 2);
7182 +
7183 + ret = snd_soc_dai_set_bclk_ratio(cpu_dai, channels*width);
7184 +
7185 + return ret;
7186 +}
7187 +
7188 +static const struct snd_soc_ops snd_rpi_dacberry400_ops = {
7189 + .hw_params = snd_rpi_dacberry400_hw_params,
7190 +};
7191 +
7192 +
7193 +SND_SOC_DAILINK_DEFS(rpi_dacberry400,
7194 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2835-i2s.0")),
7195 + DAILINK_COMP_ARRAY(COMP_CODEC("tlv320aic3x.1-0018", "tlv320aic3x-hifi")),
7196 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2835-i2s.0")));
7197 +
7198 +static struct snd_soc_dai_link snd_rpi_dacberry400_dai[] = {
7199 +{
7200 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
7201 + SND_SOC_DAIFMT_CBS_CFS,
7202 + .init = snd_rpi_dacberry400_init,
7203 + .ops = &snd_rpi_dacberry400_ops,
7204 + .symmetric_rate = 1,
7205 + SND_SOC_DAILINK_REG(rpi_dacberry400),
7206 +},
7207 +};
7208 +
7209 +static struct snd_soc_card snd_rpi_dacberry400 = {
7210 + .owner = THIS_MODULE,
7211 + .dai_link = snd_rpi_dacberry400_dai,
7212 + .num_links = ARRAY_SIZE(snd_rpi_dacberry400_dai),
7213 + .controls = dacberry400_controls,
7214 + .num_controls = ARRAY_SIZE(dacberry400_controls),
7215 + .dapm_widgets = dacberry400_widgets,
7216 + .num_dapm_widgets = ARRAY_SIZE(dacberry400_widgets),
7217 + .dapm_routes = dacberry400_audio_map,
7218 + .num_dapm_routes = ARRAY_SIZE(dacberry400_audio_map),
7219 + .set_bias_level = snd_rpi_dacberry400_set_bias_level,
7220 +};
7221 +
7222 +static int snd_rpi_dacberry400_probe(struct platform_device *pdev)
7223 +{
7224 + int ret = 0;
7225 +
7226 + snd_rpi_dacberry400.dev = &pdev->dev;
7227 +
7228 + if (pdev->dev.of_node) {
7229 + struct device_node *i2s_node;
7230 + struct snd_soc_card *card = &snd_rpi_dacberry400;
7231 + struct snd_soc_dai_link *dai = &snd_rpi_dacberry400_dai[0];
7232 +
7233 + i2s_node = of_parse_phandle(pdev->dev.of_node,
7234 + "i2s-controller", 0);
7235 + if (i2s_node) {
7236 + dai->cpus->dai_name = NULL;
7237 + dai->cpus->of_node = i2s_node;
7238 + dai->platforms->name = NULL;
7239 + dai->platforms->of_node = i2s_node;
7240 + of_node_put(i2s_node);
7241 + }
7242 +
7243 + if (of_property_read_string(pdev->dev.of_node, "card_name",
7244 + &card->name))
7245 + card->name = "tlvaudioCODEC";
7246 +
7247 + if (of_property_read_string(pdev->dev.of_node, "dai_name",
7248 + &dai->name))
7249 + dai->name = "tlvaudio CODEC";
7250 +
7251 + }
7252 +
7253 + ret = snd_soc_register_card(&snd_rpi_dacberry400);
7254 + if (ret) {
7255 + if (ret != -EPROBE_DEFER)
7256 + dev_err(&pdev->dev,
7257 + "snd_soc_register_card() failed: %d\n", ret);
7258 + return ret;
7259 + }
7260 +
7261 + return 0;
7262 +}
7263 +
7264 +static int snd_rpi_dacberry400_remove(struct platform_device *pdev)
7265 +{
7266 + snd_soc_unregister_card(&snd_rpi_dacberry400);
7267 + return 0;
7268 +}
7269 +
7270 +static const struct of_device_id dacberry400_match_id[] = {
7271 + { .compatible = "osaelectronics,dacberry400",},
7272 + {},
7273 +};
7274 +MODULE_DEVICE_TABLE(of, dacberry400_match_id);
7275 +
7276 +static struct platform_driver snd_rpi_dacberry400_driver = {
7277 + .driver = {
7278 + .name = "snd-rpi-dacberry400",
7279 + .owner = THIS_MODULE,
7280 + .of_match_table = dacberry400_match_id,
7281 + },
7282 + .probe = snd_rpi_dacberry400_probe,
7283 + .remove = snd_rpi_dacberry400_remove,
7284 +};
7285 +
7286 +module_platform_driver(snd_rpi_dacberry400_driver);
7287 +
7288 +MODULE_AUTHOR("Ashish Vara");
7289 +MODULE_DESCRIPTION("Dacberry400 sound card driver");
7290 +MODULE_LICENSE("GPL");
7291 +MODULE_ALIAS("platform:dacberry400");
7292 +MODULE_SOFTDEP("pre: snd-soc-tlv320aic3x");
7293 --- /dev/null
7294 +++ b/sound/soc/bcm/digidac1-soundcard.c
7295 @@ -0,0 +1,421 @@
7296 +/*
7297 + * ASoC Driver for RRA DigiDAC1
7298 + * Copyright 2016
7299 + * Author: José M. Tasende <vintage@redrocksaudio.es>
7300 + * based on the HifiBerry DAC driver by Florian Meier <florian.meier@koalo.de>
7301 + * and the Wolfson card driver by Nikesh Oswal, <Nikesh.Oswal@wolfsonmicro.com>
7302 + * This program is free software; you can redistribute it and/or
7303 + * modify it under the terms of the GNU General Public License
7304 + * version 2 as published by the Free Software Foundation.
7305 + *
7306 + * This program is distributed in the hope that it will be useful, but
7307 + * WITHOUT ANY WARRANTY; without even the implied warranty of
7308 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7309 + * General Public License for more details.
7310 + */
7311 +
7312 +#include <linux/module.h>
7313 +#include <linux/platform_device.h>
7314 +#include <linux/i2c.h>
7315 +#include <sound/core.h>
7316 +#include <sound/pcm.h>
7317 +#include <sound/pcm_params.h>
7318 +#include <sound/soc.h>
7319 +#include <sound/jack.h>
7320 +#include <sound/soc-dapm.h>
7321 +#include <sound/tlv.h>
7322 +#include <linux/regulator/consumer.h>
7323 +
7324 +#include "../codecs/wm8804.h"
7325 +#include "../codecs/wm8741.h"
7326 +
7327 +#define WM8741_NUM_SUPPLIES 2
7328 +
7329 +/* codec private data */
7330 +struct wm8741_priv {
7331 + struct wm8741_platform_data pdata;
7332 + struct regmap *regmap;
7333 + struct regulator_bulk_data supplies[WM8741_NUM_SUPPLIES];
7334 + unsigned int sysclk;
7335 + const struct snd_pcm_hw_constraint_list *sysclk_constraints;
7336 +};
7337 +
7338 +static int samplerate = 44100;
7339 +
7340 +/* New Alsa Controls not exposed by original wm8741 codec driver */
7341 +/* in actual driver the att. adjustment is wrong because */
7342 +/* this DAC has a coarse attenuation register with 4dB steps */
7343 +/* and a fine level register with 0.125dB steps */
7344 +/* each register has 32 steps so combining both we have 1024 steps */
7345 +/* of 0.125 dB. */
7346 +/* The original level controls from driver are removed at startup */
7347 +/* and replaced by the corrected ones. */
7348 +/* The same wm8741 driver can be used for wm8741 and wm8742 devices */
7349 +
7350 +static const DECLARE_TLV_DB_SCALE(dac_tlv_fine, 0, 13, 0);
7351 +static const DECLARE_TLV_DB_SCALE(dac_tlv_coarse, -12700, 400, 1);
7352 +static const char *w8741_dither[4] = {"Off", "RPDF", "TPDF", "HPDF"};
7353 +static const char *w8741_filter[5] = {
7354 + "Type 1", "Type 2", "Type 3", "Type 4", "Type 5"};
7355 +static const char *w8741_switch[2] = {"Off", "On"};
7356 +static const struct soc_enum w8741_enum[] = {
7357 +SOC_ENUM_SINGLE(WM8741_MODE_CONTROL_2, 0, 4, w8741_dither),/* dithering type */
7358 +SOC_ENUM_SINGLE(WM8741_FILTER_CONTROL, 0, 5, w8741_filter),/* filter type */
7359 +SOC_ENUM_SINGLE(WM8741_FORMAT_CONTROL, 6, 2, w8741_switch),/* phase invert */
7360 +SOC_ENUM_SINGLE(WM8741_VOLUME_CONTROL, 0, 2, w8741_switch),/* volume ramp */
7361 +SOC_ENUM_SINGLE(WM8741_VOLUME_CONTROL, 3, 2, w8741_switch),/* soft mute */
7362 +};
7363 +
7364 +static const struct snd_kcontrol_new w8741_snd_controls_stereo[] = {
7365 +SOC_DOUBLE_R_TLV("DAC Fine Playback Volume", WM8741_DACLLSB_ATTENUATION,
7366 + WM8741_DACRLSB_ATTENUATION, 0, 31, 1, dac_tlv_fine),
7367 +SOC_DOUBLE_R_TLV("Digital Playback Volume", WM8741_DACLMSB_ATTENUATION,
7368 + WM8741_DACRMSB_ATTENUATION, 0, 31, 1, dac_tlv_coarse),
7369 +SOC_ENUM("DAC Dither", w8741_enum[0]),
7370 +SOC_ENUM("DAC Digital Filter", w8741_enum[1]),
7371 +SOC_ENUM("DAC Phase Invert", w8741_enum[2]),
7372 +SOC_ENUM("DAC Volume Ramp", w8741_enum[3]),
7373 +SOC_ENUM("DAC Soft Mute", w8741_enum[4]),
7374 +};
7375 +
7376 +static const struct snd_kcontrol_new w8741_snd_controls_mono_left[] = {
7377 +SOC_SINGLE_TLV("DAC Fine Playback Volume", WM8741_DACLLSB_ATTENUATION,
7378 + 0, 31, 0, dac_tlv_fine),
7379 +SOC_SINGLE_TLV("Digital Playback Volume", WM8741_DACLMSB_ATTENUATION,
7380 + 0, 31, 1, dac_tlv_coarse),
7381 +SOC_ENUM("DAC Dither", w8741_enum[0]),
7382 +SOC_ENUM("DAC Digital Filter", w8741_enum[1]),
7383 +SOC_ENUM("DAC Phase Invert", w8741_enum[2]),
7384 +SOC_ENUM("DAC Volume Ramp", w8741_enum[3]),
7385 +SOC_ENUM("DAC Soft Mute", w8741_enum[4]),
7386 +};
7387 +
7388 +static const struct snd_kcontrol_new w8741_snd_controls_mono_right[] = {
7389 +SOC_SINGLE_TLV("DAC Fine Playback Volume", WM8741_DACRLSB_ATTENUATION,
7390 + 0, 31, 0, dac_tlv_fine),
7391 +SOC_SINGLE_TLV("Digital Playback Volume", WM8741_DACRMSB_ATTENUATION,
7392 + 0, 31, 1, dac_tlv_coarse),
7393 +SOC_ENUM("DAC Dither", w8741_enum[0]),
7394 +SOC_ENUM("DAC Digital Filter", w8741_enum[1]),
7395 +SOC_ENUM("DAC Phase Invert", w8741_enum[2]),
7396 +SOC_ENUM("DAC Volume Ramp", w8741_enum[3]),
7397 +SOC_ENUM("DAC Soft Mute", w8741_enum[4]),
7398 +};
7399 +
7400 +static int w8741_add_controls(struct snd_soc_component *component)
7401 +{
7402 + struct wm8741_priv *wm8741 = snd_soc_component_get_drvdata(component);
7403 +
7404 + switch (wm8741->pdata.diff_mode) {
7405 + case WM8741_DIFF_MODE_STEREO:
7406 + case WM8741_DIFF_MODE_STEREO_REVERSED:
7407 + snd_soc_add_component_controls(component,
7408 + w8741_snd_controls_stereo,
7409 + ARRAY_SIZE(w8741_snd_controls_stereo));
7410 + break;
7411 + case WM8741_DIFF_MODE_MONO_LEFT:
7412 + snd_soc_add_component_controls(component,
7413 + w8741_snd_controls_mono_left,
7414 + ARRAY_SIZE(w8741_snd_controls_mono_left));
7415 + break;
7416 + case WM8741_DIFF_MODE_MONO_RIGHT:
7417 + snd_soc_add_component_controls(component,
7418 + w8741_snd_controls_mono_right,
7419 + ARRAY_SIZE(w8741_snd_controls_mono_right));
7420 + break;
7421 + default:
7422 + return -EINVAL;
7423 + }
7424 +
7425 + return 0;
7426 +}
7427 +
7428 +static int digidac1_soundcard_init(struct snd_soc_pcm_runtime *rtd)
7429 +{
7430 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
7431 + struct snd_soc_card *card = rtd->card;
7432 + struct snd_soc_pcm_runtime *wm8741_rtd;
7433 + struct snd_soc_component *wm8741_component;
7434 + struct snd_card *sound_card = card->snd_card;
7435 + struct snd_kcontrol *kctl;
7436 + int ret;
7437 +
7438 + wm8741_rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[1]);
7439 + if (!wm8741_rtd) {
7440 + dev_warn(card->dev, "digidac1_soundcard_init: couldn't get wm8741 rtd\n");
7441 + return -EFAULT;
7442 + }
7443 + wm8741_component = asoc_rtd_to_codec(wm8741_rtd, 0)->component;
7444 + ret = w8741_add_controls(wm8741_component);
7445 + if (ret < 0)
7446 + dev_warn(card->dev, "Failed to add new wm8741 controls: %d\n",
7447 + ret);
7448 +
7449 + /* enable TX output */
7450 + snd_soc_component_update_bits(component, WM8804_PWRDN, 0x4, 0x0);
7451 +
7452 + kctl = snd_soc_card_get_kcontrol(card,
7453 + "Playback Volume");
7454 + if (kctl) {
7455 + kctl->vd[0].access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
7456 + snd_ctl_remove(sound_card, kctl);
7457 + }
7458 + kctl = snd_soc_card_get_kcontrol(card,
7459 + "Fine Playback Volume");
7460 + if (kctl) {
7461 + kctl->vd[0].access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
7462 + snd_ctl_remove(sound_card, kctl);
7463 + }
7464 + return 0;
7465 +}
7466 +
7467 +static int digidac1_soundcard_startup(struct snd_pcm_substream *substream)
7468 +{
7469 + /* turn on wm8804 digital output */
7470 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
7471 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
7472 + struct snd_soc_card *card = rtd->card;
7473 + struct snd_soc_pcm_runtime *wm8741_rtd;
7474 + struct snd_soc_component *wm8741_component;
7475 +
7476 + snd_soc_component_update_bits(component, WM8804_PWRDN, 0x3c, 0x00);
7477 + wm8741_rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[1]);
7478 + if (!wm8741_rtd) {
7479 + dev_warn(card->dev, "digidac1_soundcard_startup: couldn't get WM8741 rtd\n");
7480 + return -EFAULT;
7481 + }
7482 + wm8741_component = asoc_rtd_to_codec(wm8741_rtd, 0)->component;
7483 +
7484 + /* latch wm8741 level */
7485 + snd_soc_component_update_bits(wm8741_component, WM8741_DACLLSB_ATTENUATION,
7486 + WM8741_UPDATELL, WM8741_UPDATELL);
7487 + snd_soc_component_update_bits(wm8741_component, WM8741_DACLMSB_ATTENUATION,
7488 + WM8741_UPDATELM, WM8741_UPDATELM);
7489 + snd_soc_component_update_bits(wm8741_component, WM8741_DACRLSB_ATTENUATION,
7490 + WM8741_UPDATERL, WM8741_UPDATERL);
7491 + snd_soc_component_update_bits(wm8741_component, WM8741_DACRMSB_ATTENUATION,
7492 + WM8741_UPDATERM, WM8741_UPDATERM);
7493 +
7494 + return 0;
7495 +}
7496 +
7497 +static void digidac1_soundcard_shutdown(struct snd_pcm_substream *substream)
7498 +{
7499 + /* turn off wm8804 digital output */
7500 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
7501 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
7502 +
7503 + snd_soc_component_update_bits(component, WM8804_PWRDN, 0x3c, 0x3c);
7504 +}
7505 +
7506 +static int digidac1_soundcard_hw_params(struct snd_pcm_substream *substream,
7507 + struct snd_pcm_hw_params *params)
7508 +{
7509 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
7510 + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
7511 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
7512 + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
7513 + struct snd_soc_card *card = rtd->card;
7514 + struct snd_soc_pcm_runtime *wm8741_rtd;
7515 + struct snd_soc_component *wm8741_component;
7516 +
7517 + int sysclk = 27000000;
7518 + long mclk_freq = 0;
7519 + int mclk_div = 1;
7520 + int sampling_freq = 1;
7521 + int ret;
7522 +
7523 + wm8741_rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[1]);
7524 + if (!wm8741_rtd) {
7525 + dev_warn(card->dev, "digidac1_soundcard_hw_params: couldn't get WM8741 rtd\n");
7526 + return -EFAULT;
7527 + }
7528 + wm8741_component = asoc_rtd_to_codec(wm8741_rtd, 0)->component;
7529 + samplerate = params_rate(params);
7530 +
7531 + if (samplerate <= 96000) {
7532 + mclk_freq = samplerate*256;
7533 + mclk_div = WM8804_MCLKDIV_256FS;
7534 + } else {
7535 + mclk_freq = samplerate*128;
7536 + mclk_div = WM8804_MCLKDIV_128FS;
7537 + }
7538 +
7539 + switch (samplerate) {
7540 + case 32000:
7541 + sampling_freq = 0x03;
7542 + break;
7543 + case 44100:
7544 + sampling_freq = 0x00;
7545 + break;
7546 + case 48000:
7547 + sampling_freq = 0x02;
7548 + break;
7549 + case 88200:
7550 + sampling_freq = 0x08;
7551 + break;
7552 + case 96000:
7553 + sampling_freq = 0x0a;
7554 + break;
7555 + case 176400:
7556 + sampling_freq = 0x0c;
7557 + break;
7558 + case 192000:
7559 + sampling_freq = 0x0e;
7560 + break;
7561 + default:
7562 + dev_err(card->dev,
7563 + "Failed to set WM8804 SYSCLK, unsupported samplerate %d\n",
7564 + samplerate);
7565 + }
7566 +
7567 + snd_soc_dai_set_clkdiv(codec_dai, WM8804_MCLK_DIV, mclk_div);
7568 + snd_soc_dai_set_pll(codec_dai, 0, 0, sysclk, mclk_freq);
7569 +
7570 + ret = snd_soc_dai_set_sysclk(codec_dai, WM8804_TX_CLKSRC_PLL,
7571 + sysclk, SND_SOC_CLOCK_OUT);
7572 + if (ret < 0) {
7573 + dev_err(card->dev,
7574 + "Failed to set WM8804 SYSCLK: %d\n", ret);
7575 + return ret;
7576 + }
7577 + /* Enable wm8804 TX output */
7578 + snd_soc_component_update_bits(component, WM8804_PWRDN, 0x4, 0x0);
7579 +
7580 + /* wm8804 Power on */
7581 + snd_soc_component_update_bits(component, WM8804_PWRDN, 0x9, 0);
7582 +
7583 + /* wm8804 set sampling frequency status bits */
7584 + snd_soc_component_update_bits(component, WM8804_SPDTX4, 0x0f, sampling_freq);
7585 +
7586 + /* Now update wm8741 registers for the correct oversampling */
7587 + if (samplerate <= 48000)
7588 + snd_soc_component_update_bits(wm8741_component, WM8741_MODE_CONTROL_1,
7589 + WM8741_OSR_MASK, 0x00);
7590 + else if (samplerate <= 96000)
7591 + snd_soc_component_update_bits(wm8741_component, WM8741_MODE_CONTROL_1,
7592 + WM8741_OSR_MASK, 0x20);
7593 + else
7594 + snd_soc_component_update_bits(wm8741_component, WM8741_MODE_CONTROL_1,
7595 + WM8741_OSR_MASK, 0x40);
7596 +
7597 + /* wm8741 bit size */
7598 + switch (params_width(params)) {
7599 + case 16:
7600 + snd_soc_component_update_bits(wm8741_component, WM8741_FORMAT_CONTROL,
7601 + WM8741_IWL_MASK, 0x00);
7602 + break;
7603 + case 20:
7604 + snd_soc_component_update_bits(wm8741_component, WM8741_FORMAT_CONTROL,
7605 + WM8741_IWL_MASK, 0x01);
7606 + break;
7607 + case 24:
7608 + snd_soc_component_update_bits(wm8741_component, WM8741_FORMAT_CONTROL,
7609 + WM8741_IWL_MASK, 0x02);
7610 + break;
7611 + case 32:
7612 + snd_soc_component_update_bits(wm8741_component, WM8741_FORMAT_CONTROL,
7613 + WM8741_IWL_MASK, 0x03);
7614 + break;
7615 + default:
7616 + dev_dbg(card->dev, "wm8741_hw_params: Unsupported bit size param = %d",
7617 + params_width(params));
7618 + return -EINVAL;
7619 + }
7620 +
7621 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 64);
7622 +}
7623 +/* machine stream operations */
7624 +static struct snd_soc_ops digidac1_soundcard_ops = {
7625 + .hw_params = digidac1_soundcard_hw_params,
7626 + .startup = digidac1_soundcard_startup,
7627 + .shutdown = digidac1_soundcard_shutdown,
7628 +};
7629 +
7630 +SND_SOC_DAILINK_DEFS(digidac1,
7631 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
7632 + DAILINK_COMP_ARRAY(COMP_CODEC("wm8804.1-003b", "wm8804-spdif")),
7633 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2835-i2s.0")));
7634 +
7635 +SND_SOC_DAILINK_DEFS(digidac11,
7636 + DAILINK_COMP_ARRAY(COMP_CPU("wm8804-spdif")),
7637 + DAILINK_COMP_ARRAY(COMP_CODEC("wm8741.1-001a", "wm8741")),
7638 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
7639 +
7640 +static struct snd_soc_dai_link digidac1_soundcard_dai[] = {
7641 + {
7642 + .name = "RRA DigiDAC1",
7643 + .stream_name = "RRA DigiDAC1 HiFi",
7644 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
7645 + SND_SOC_DAIFMT_CBM_CFM,
7646 + .ops = &digidac1_soundcard_ops,
7647 + .init = digidac1_soundcard_init,
7648 + SND_SOC_DAILINK_REG(digidac1),
7649 + },
7650 + {
7651 + .name = "RRA DigiDAC11",
7652 + .stream_name = "RRA DigiDAC11 HiFi",
7653 + .dai_fmt = SND_SOC_DAIFMT_I2S
7654 + | SND_SOC_DAIFMT_NB_NF
7655 + | SND_SOC_DAIFMT_CBS_CFS,
7656 + SND_SOC_DAILINK_REG(digidac11),
7657 + },
7658 +};
7659 +
7660 +/* audio machine driver */
7661 +static struct snd_soc_card digidac1_soundcard = {
7662 + .name = "digidac1-soundcard",
7663 + .owner = THIS_MODULE,
7664 + .dai_link = digidac1_soundcard_dai,
7665 + .num_links = ARRAY_SIZE(digidac1_soundcard_dai),
7666 +};
7667 +
7668 +static int digidac1_soundcard_probe(struct platform_device *pdev)
7669 +{
7670 + int ret = 0;
7671 +
7672 + digidac1_soundcard.dev = &pdev->dev;
7673 +
7674 + if (pdev->dev.of_node) {
7675 + struct device_node *i2s_node;
7676 + struct snd_soc_dai_link *dai = &digidac1_soundcard_dai[0];
7677 +
7678 + i2s_node = of_parse_phandle(pdev->dev.of_node,
7679 + "i2s-controller", 0);
7680 +
7681 + if (i2s_node) {
7682 + dai->cpus->dai_name = NULL;
7683 + dai->cpus->of_node = i2s_node;
7684 + dai->platforms->name = NULL;
7685 + dai->platforms->of_node = i2s_node;
7686 + }
7687 + }
7688 +
7689 + ret = devm_snd_soc_register_card(&pdev->dev, &digidac1_soundcard);
7690 + if (ret && ret != -EPROBE_DEFER)
7691 + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
7692 + ret);
7693 +
7694 + return ret;
7695 +}
7696 +
7697 +static const struct of_device_id digidac1_soundcard_of_match[] = {
7698 + { .compatible = "rra,digidac1-soundcard", },
7699 + {},
7700 +};
7701 +MODULE_DEVICE_TABLE(of, digidac1_soundcard_of_match);
7702 +
7703 +static struct platform_driver digidac1_soundcard_driver = {
7704 + .driver = {
7705 + .name = "digidac1-audio",
7706 + .owner = THIS_MODULE,
7707 + .of_match_table = digidac1_soundcard_of_match,
7708 + },
7709 + .probe = digidac1_soundcard_probe,
7710 +};
7711 +
7712 +module_platform_driver(digidac1_soundcard_driver);
7713 +
7714 +MODULE_AUTHOR("José M. Tasende <vintage@redrocksaudio.es>");
7715 +MODULE_DESCRIPTION("ASoC Driver for RRA DigiDAC1");
7716 +MODULE_LICENSE("GPL v2");
7717 --- /dev/null
7718 +++ b/sound/soc/bcm/dionaudio_loco-v2.c
7719 @@ -0,0 +1,117 @@
7720 +/*
7721 + * ASoC Driver for Dion Audio LOCO-V2 DAC-AMP
7722 + *
7723 + * Author: Miquel Blauw <info@dionaudio.nl>
7724 + * Copyright 2017
7725 + *
7726 + * Based on the software of the RPi-DAC writen by Florian Meier
7727 + *
7728 + * This program is free software; you can redistribute it and/or
7729 + * modify it under the terms of the GNU General Public License
7730 + * version 2 as published by the Free Software Foundation.
7731 + *
7732 + * This program is distributed in the hope that it will be useful, but
7733 + * WITHOUT ANY WARRANTY; without even the implied warranty of
7734 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7735 + * General Public License for more details.
7736 + */
7737 +
7738 +#include <linux/module.h>
7739 +#include <linux/platform_device.h>
7740 +
7741 +#include <sound/core.h>
7742 +#include <sound/pcm.h>
7743 +#include <sound/pcm_params.h>
7744 +#include <sound/soc.h>
7745 +#include <sound/jack.h>
7746 +
7747 +static bool digital_gain_0db_limit = true;
7748 +
7749 +static int snd_rpi_dionaudio_loco_v2_init(struct snd_soc_pcm_runtime *rtd)
7750 +{
7751 + if (digital_gain_0db_limit) {
7752 + int ret;
7753 + struct snd_soc_card *card = rtd->card;
7754 +
7755 + ret = snd_soc_limit_volume(card, "Digital Playback Volume", 207);
7756 + if (ret < 0)
7757 + dev_warn(card->dev, "Failed to set volume limit: %d\n", ret);
7758 + }
7759 +
7760 + return 0;
7761 +}
7762 +
7763 +SND_SOC_DAILINK_DEFS(dionaudio_loco_v2,
7764 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
7765 + DAILINK_COMP_ARRAY(COMP_CODEC("pcm512x.1-004d", "pcm512x-hifi")),
7766 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
7767 +
7768 +static struct snd_soc_dai_link snd_rpi_dionaudio_loco_v2_dai[] = {
7769 +{
7770 + .name = "DionAudio LOCO-V2",
7771 + .stream_name = "DionAudio LOCO-V2 DAC-AMP",
7772 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
7773 + SND_SOC_DAIFMT_CBS_CFS,
7774 + .init = snd_rpi_dionaudio_loco_v2_init,
7775 + SND_SOC_DAILINK_REG(dionaudio_loco_v2),
7776 +},};
7777 +
7778 +/* audio machine driver */
7779 +static struct snd_soc_card snd_rpi_dionaudio_loco_v2 = {
7780 + .name = "Dion Audio LOCO-V2",
7781 + .dai_link = snd_rpi_dionaudio_loco_v2_dai,
7782 + .num_links = ARRAY_SIZE(snd_rpi_dionaudio_loco_v2_dai),
7783 +};
7784 +
7785 +static int snd_rpi_dionaudio_loco_v2_probe(struct platform_device *pdev)
7786 +{
7787 + int ret = 0;
7788 +
7789 + snd_rpi_dionaudio_loco_v2.dev = &pdev->dev;
7790 +
7791 + if (pdev->dev.of_node) {
7792 + struct device_node *i2s_node;
7793 + struct snd_soc_dai_link *dai =
7794 + &snd_rpi_dionaudio_loco_v2_dai[0];
7795 +
7796 + i2s_node = of_parse_phandle(pdev->dev.of_node,
7797 + "i2s-controller", 0);
7798 + if (i2s_node) {
7799 + dai->cpus->dai_name = NULL;
7800 + dai->cpus->of_node = i2s_node;
7801 + dai->platforms->name = NULL;
7802 + dai->platforms->of_node = i2s_node;
7803 + }
7804 +
7805 + digital_gain_0db_limit = !of_property_read_bool(
7806 + pdev->dev.of_node, "dionaudio,24db_digital_gain");
7807 + }
7808 +
7809 + ret = devm_snd_soc_register_card(&pdev->dev, &snd_rpi_dionaudio_loco_v2);
7810 + if (ret)
7811 + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
7812 + ret);
7813 +
7814 + return ret;
7815 +}
7816 +
7817 +static const struct of_device_id dionaudio_of_match[] = {
7818 + { .compatible = "dionaudio,dionaudio-loco-v2", },
7819 + {},
7820 +};
7821 +MODULE_DEVICE_TABLE(of, dionaudio_of_match);
7822 +
7823 +static struct platform_driver snd_rpi_dionaudio_loco_v2_driver = {
7824 + .driver = {
7825 + .name = "snd-rpi-dionaudio-loco-v2",
7826 + .owner = THIS_MODULE,
7827 + .of_match_table = dionaudio_of_match,
7828 + },
7829 + .probe = snd_rpi_dionaudio_loco_v2_probe,
7830 +};
7831 +
7832 +module_platform_driver(snd_rpi_dionaudio_loco_v2_driver);
7833 +
7834 +MODULE_AUTHOR("Miquel Blauw <info@dionaudio.nl>");
7835 +MODULE_DESCRIPTION("ASoC Driver for DionAudio LOCO-V2");
7836 +MODULE_LICENSE("GPL v2");
7837 --- /dev/null
7838 +++ b/sound/soc/bcm/dionaudio_loco.c
7839 @@ -0,0 +1,117 @@
7840 +/*
7841 + * ASoC Driver for Dion Audio LOCO DAC-AMP
7842 + *
7843 + * Author: Miquel Blauw <info@dionaudio.nl>
7844 + * Copyright 2016
7845 + *
7846 + * Based on the software of the RPi-DAC writen by Florian Meier
7847 + *
7848 + * This program is free software; you can redistribute it and/or
7849 + * modify it under the terms of the GNU General Public License
7850 + * version 2 as published by the Free Software Foundation.
7851 + *
7852 + * This program is distributed in the hope that it will be useful, but
7853 + * WITHOUT ANY WARRANTY; without even the implied warranty of
7854 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7855 + * General Public License for more details.
7856 + */
7857 +
7858 +#include <linux/module.h>
7859 +#include <linux/platform_device.h>
7860 +
7861 +#include <sound/core.h>
7862 +#include <sound/pcm.h>
7863 +#include <sound/pcm_params.h>
7864 +#include <sound/soc.h>
7865 +#include <sound/jack.h>
7866 +
7867 +static int snd_rpi_dionaudio_loco_hw_params(
7868 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
7869 +{
7870 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
7871 + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
7872 +
7873 + unsigned int sample_bits =
7874 + snd_pcm_format_physical_width(params_format(params));
7875 +
7876 + return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);
7877 +}
7878 +
7879 +/* machine stream operations */
7880 +static struct snd_soc_ops snd_rpi_dionaudio_loco_ops = {
7881 + .hw_params = snd_rpi_dionaudio_loco_hw_params,
7882 +};
7883 +
7884 +SND_SOC_DAILINK_DEFS(dionaudio_loco,
7885 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
7886 + DAILINK_COMP_ARRAY(COMP_CODEC("pcm5102a-codec", "pcm5102a-hifi")),
7887 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
7888 +
7889 +static struct snd_soc_dai_link snd_rpi_dionaudio_loco_dai[] = {
7890 +{
7891 + .name = "DionAudio LOCO",
7892 + .stream_name = "DionAudio LOCO DAC-AMP",
7893 + .dai_fmt = SND_SOC_DAIFMT_I2S |
7894 + SND_SOC_DAIFMT_NB_NF |
7895 + SND_SOC_DAIFMT_CBS_CFS,
7896 + .ops = &snd_rpi_dionaudio_loco_ops,
7897 + SND_SOC_DAILINK_REG(dionaudio_loco),
7898 +},
7899 +};
7900 +
7901 +/* audio machine driver */
7902 +static struct snd_soc_card snd_rpi_dionaudio_loco = {
7903 + .name = "snd_rpi_dionaudio_loco",
7904 + .dai_link = snd_rpi_dionaudio_loco_dai,
7905 + .num_links = ARRAY_SIZE(snd_rpi_dionaudio_loco_dai),
7906 +};
7907 +
7908 +static int snd_rpi_dionaudio_loco_probe(struct platform_device *pdev)
7909 +{
7910 + struct device_node *np;
7911 + int ret = 0;
7912 +
7913 + snd_rpi_dionaudio_loco.dev = &pdev->dev;
7914 +
7915 + np = pdev->dev.of_node;
7916 + if (np) {
7917 + struct snd_soc_dai_link *dai = &snd_rpi_dionaudio_loco_dai[0];
7918 + struct device_node *i2s_np;
7919 +
7920 + i2s_np = of_parse_phandle(np, "i2s-controller", 0);
7921 + if (i2s_np) {
7922 + dai->cpus->dai_name = NULL;
7923 + dai->cpus->of_node = i2s_np;
7924 + dai->platforms->name = NULL;
7925 + dai->platforms->of_node = i2s_np;
7926 + }
7927 + }
7928 +
7929 + ret = devm_snd_soc_register_card(&pdev->dev, &snd_rpi_dionaudio_loco);
7930 + if (ret && ret != -EPROBE_DEFER)
7931 + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
7932 + ret);
7933 +
7934 + return ret;
7935 +}
7936 +
7937 +static const struct of_device_id snd_rpi_dionaudio_loco_of_match[] = {
7938 + { .compatible = "dionaudio,loco-pcm5242-tpa3118", },
7939 + { /* sentinel */ },
7940 +};
7941 +MODULE_DEVICE_TABLE(of, snd_rpi_dionaudio_loco_of_match);
7942 +
7943 +static struct platform_driver snd_rpi_dionaudio_loco_driver = {
7944 + .driver = {
7945 + .name = "snd-dionaudio-loco",
7946 + .owner = THIS_MODULE,
7947 + .of_match_table = snd_rpi_dionaudio_loco_of_match,
7948 + },
7949 + .probe = snd_rpi_dionaudio_loco_probe,
7950 +};
7951 +
7952 +module_platform_driver(snd_rpi_dionaudio_loco_driver);
7953 +
7954 +MODULE_AUTHOR("Miquel Blauw <info@dionaudio.nl>");
7955 +MODULE_DESCRIPTION("ASoC Driver for DionAudio LOCO");
7956 +MODULE_LICENSE("GPL v2");
7957 --- /dev/null
7958 +++ b/sound/soc/bcm/fe-pi-audio.c
7959 @@ -0,0 +1,154 @@
7960 +/*
7961 + * ASoC Driver for Fe-Pi Audio Sound Card
7962 + *
7963 + * Author: Henry Kupis <kuupaz@gmail.com>
7964 + * Copyright 2016
7965 + * based on code by Florian Meier <florian.meier@koalo.de>
7966 + * based on code by Shawn Guo <shawn.guo@linaro.org>
7967 + *
7968 + * This program is free software; you can redistribute it and/or
7969 + * modify it under the terms of the GNU General Public License
7970 + * version 2 as published by the Free Software Foundation.
7971 + *
7972 + * This program is distributed in the hope that it will be useful, but
7973 + * WITHOUT ANY WARRANTY; without even the implied warranty of
7974 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7975 + * General Public License for more details.
7976 + */
7977 +
7978 +#include <linux/module.h>
7979 +#include <linux/platform_device.h>
7980 +#include <linux/io.h>
7981 +
7982 +#include <sound/core.h>
7983 +#include <sound/pcm.h>
7984 +#include <sound/pcm_params.h>
7985 +#include <sound/soc.h>
7986 +#include <sound/jack.h>
7987 +
7988 +#include "../codecs/sgtl5000.h"
7989 +
7990 +static int snd_fe_pi_audio_init(struct snd_soc_pcm_runtime *rtd)
7991 +{
7992 + struct snd_soc_card *card = rtd->card;
7993 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
7994 +
7995 + snd_soc_dapm_force_enable_pin(&card->dapm, "LO");
7996 + snd_soc_dapm_force_enable_pin(&card->dapm, "ADC");
7997 + snd_soc_dapm_force_enable_pin(&card->dapm, "DAC");
7998 + snd_soc_dapm_force_enable_pin(&card->dapm, "HP");
7999 + snd_soc_component_update_bits(component, SGTL5000_CHIP_ANA_POWER,
8000 + SGTL5000_VAG_POWERUP, SGTL5000_VAG_POWERUP);
8001 +
8002 + return 0;
8003 +}
8004 +
8005 +static int snd_fe_pi_audio_hw_params(struct snd_pcm_substream *substream,
8006 + struct snd_pcm_hw_params *params)
8007 +{
8008 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
8009 + struct device *dev = rtd->card->dev;
8010 + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
8011 +
8012 + int ret;
8013 +
8014 + /* Set SGTL5000's SYSCLK */
8015 + ret = snd_soc_dai_set_sysclk(codec_dai, SGTL5000_SYSCLK, 12288000, SND_SOC_CLOCK_IN);
8016 + if (ret) {
8017 + dev_err(dev, "could not set codec driver clock params\n");
8018 + return ret;
8019 + }
8020 +
8021 + return 0;
8022 +}
8023 +
8024 +
8025 +static struct snd_soc_ops snd_fe_pi_audio_ops = {
8026 + .hw_params = snd_fe_pi_audio_hw_params,
8027 +};
8028 +
8029 +SND_SOC_DAILINK_DEFS(fe_pi,
8030 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
8031 + DAILINK_COMP_ARRAY(COMP_CODEC("sgtl5000.1-000a", "sgtl5000")),
8032 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
8033 +
8034 +static struct snd_soc_dai_link snd_fe_pi_audio_dai[] = {
8035 + {
8036 + .name = "FE-PI",
8037 + .stream_name = "Fe-Pi HiFi",
8038 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
8039 + SND_SOC_DAIFMT_CBM_CFM,
8040 + .ops = &snd_fe_pi_audio_ops,
8041 + .init = snd_fe_pi_audio_init,
8042 + SND_SOC_DAILINK_REG(fe_pi),
8043 + },
8044 +};
8045 +
8046 +static const struct snd_soc_dapm_route fe_pi_audio_dapm_routes[] = {
8047 + {"ADC", NULL, "Mic Bias"},
8048 +};
8049 +
8050 +
8051 +static struct snd_soc_card fe_pi_audio = {
8052 + .name = "Fe-Pi Audio",
8053 + .owner = THIS_MODULE,
8054 + .dai_link = snd_fe_pi_audio_dai,
8055 + .num_links = ARRAY_SIZE(snd_fe_pi_audio_dai),
8056 +
8057 + .dapm_routes = fe_pi_audio_dapm_routes,
8058 + .num_dapm_routes = ARRAY_SIZE(fe_pi_audio_dapm_routes),
8059 +};
8060 +
8061 +static int snd_fe_pi_audio_probe(struct platform_device *pdev)
8062 +{
8063 + int ret = 0;
8064 + struct snd_soc_card *card = &fe_pi_audio;
8065 + struct device_node *np = pdev->dev.of_node;
8066 + struct device_node *i2s_node;
8067 + struct snd_soc_dai_link *dai = &snd_fe_pi_audio_dai[0];
8068 +
8069 + fe_pi_audio.dev = &pdev->dev;
8070 +
8071 + i2s_node = of_parse_phandle(np, "i2s-controller", 0);
8072 + if (!i2s_node) {
8073 + dev_err(&pdev->dev, "i2s_node phandle missing or invalid\n");
8074 + return -EINVAL;
8075 + }
8076 +
8077 + dai->cpus->dai_name = NULL;
8078 + dai->cpus->of_node = i2s_node;
8079 + dai->platforms->name = NULL;
8080 + dai->platforms->of_node = i2s_node;
8081 +
8082 + of_node_put(i2s_node);
8083 +
8084 + card->dev = &pdev->dev;
8085 + platform_set_drvdata(pdev, card);
8086 +
8087 + ret = devm_snd_soc_register_card(&pdev->dev, card);
8088 + if (ret && ret != -EPROBE_DEFER)
8089 + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
8090 +
8091 + return ret;
8092 +}
8093 +
8094 +static const struct of_device_id snd_fe_pi_audio_of_match[] = {
8095 + { .compatible = "fe-pi,fe-pi-audio", },
8096 + {},
8097 +};
8098 +MODULE_DEVICE_TABLE(of, snd_fe_pi_audio_of_match);
8099 +
8100 +static struct platform_driver snd_fe_pi_audio_driver = {
8101 + .driver = {
8102 + .name = "snd-fe-pi-audio",
8103 + .owner = THIS_MODULE,
8104 + .of_match_table = snd_fe_pi_audio_of_match,
8105 + },
8106 + .probe = snd_fe_pi_audio_probe,
8107 +};
8108 +
8109 +module_platform_driver(snd_fe_pi_audio_driver);
8110 +
8111 +MODULE_AUTHOR("Henry Kupis <fe-pi@cox.net>");
8112 +MODULE_DESCRIPTION("ASoC Driver for Fe-Pi Audio");
8113 +MODULE_LICENSE("GPL v2");
8114 --- /dev/null
8115 +++ b/sound/soc/bcm/googlevoicehat-codec.c
8116 @@ -0,0 +1,214 @@
8117 +/*
8118 + * Driver for the Google voiceHAT audio codec for Raspberry Pi.
8119 + *
8120 + * Author: Peter Malkin <petermalkin@google.com>
8121 + * Copyright 2016
8122 + *
8123 + * This program is free software; you can redistribute it and/or
8124 + * modify it under the terms of the GNU General Public License
8125 + * version 2 as published by the Free Software Foundation.
8126 + *
8127 + * This program is distributed in the hope that it will be useful, but
8128 + * WITHOUT ANY WARRANTY; without even the implied warranty of
8129 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
8130 + * General Public License for more details.
8131 + */
8132 +
8133 +#include <linux/device.h>
8134 +#include <linux/err.h>
8135 +#include <linux/gpio.h>
8136 +#include <linux/gpio/consumer.h>
8137 +#include <linux/init.h>
8138 +#include <linux/kernel.h>
8139 +#include <linux/mod_devicetable.h>
8140 +#include <linux/module.h>
8141 +#include <linux/of.h>
8142 +#include <linux/platform_device.h>
8143 +#include <linux/version.h>
8144 +#include <sound/pcm.h>
8145 +#include <sound/soc.h>
8146 +#include <sound/soc-dai.h>
8147 +#include <sound/soc-dapm.h>
8148 +
8149 +#define ICS43432_RATE_MIN_HZ 7190 /* from data sheet */
8150 +#define ICS43432_RATE_MAX_HZ 52800 /* from data sheet */
8151 +/* Delay in enabling SDMODE after clock settles to remove pop */
8152 +#define SDMODE_DELAY_MS 5
8153 +
8154 +struct voicehat_priv {
8155 + struct delayed_work enable_sdmode_work;
8156 + struct gpio_desc *sdmode_gpio;
8157 + unsigned long sdmode_delay_jiffies;
8158 +};
8159 +
8160 +static void voicehat_enable_sdmode_work(struct work_struct *work)
8161 +{
8162 + struct voicehat_priv *voicehat = container_of(work,
8163 + struct voicehat_priv,
8164 + enable_sdmode_work.work);
8165 + gpiod_set_value(voicehat->sdmode_gpio, 1);
8166 +}
8167 +
8168 +static int voicehat_component_probe(struct snd_soc_component *component)
8169 +{
8170 + struct voicehat_priv *voicehat =
8171 + snd_soc_component_get_drvdata(component);
8172 +
8173 + voicehat->sdmode_gpio = devm_gpiod_get(component->dev, "sdmode",
8174 + GPIOD_OUT_LOW);
8175 + if (IS_ERR(voicehat->sdmode_gpio)) {
8176 + dev_err(component->dev, "Unable to allocate GPIO pin\n");
8177 + return PTR_ERR(voicehat->sdmode_gpio);
8178 + }
8179 +
8180 + INIT_DELAYED_WORK(&voicehat->enable_sdmode_work,
8181 + voicehat_enable_sdmode_work);
8182 + return 0;
8183 +}
8184 +
8185 +static void voicehat_component_remove(struct snd_soc_component *component)
8186 +{
8187 + struct voicehat_priv *voicehat =
8188 + snd_soc_component_get_drvdata(component);
8189 +
8190 + cancel_delayed_work_sync(&voicehat->enable_sdmode_work);
8191 +}
8192 +
8193 +static const struct snd_soc_dapm_widget voicehat_dapm_widgets[] = {
8194 + SND_SOC_DAPM_OUTPUT("Speaker"),
8195 +};
8196 +
8197 +static const struct snd_soc_dapm_route voicehat_dapm_routes[] = {
8198 + {"Speaker", NULL, "HiFi Playback"},
8199 +};
8200 +
8201 +static const struct snd_soc_component_driver voicehat_component_driver = {
8202 + .probe = voicehat_component_probe,
8203 + .remove = voicehat_component_remove,
8204 + .dapm_widgets = voicehat_dapm_widgets,
8205 + .num_dapm_widgets = ARRAY_SIZE(voicehat_dapm_widgets),
8206 + .dapm_routes = voicehat_dapm_routes,
8207 + .num_dapm_routes = ARRAY_SIZE(voicehat_dapm_routes),
8208 +};
8209 +
8210 +static int voicehat_daiops_trigger(struct snd_pcm_substream *substream, int cmd,
8211 + struct snd_soc_dai *dai)
8212 +{
8213 + struct snd_soc_component *component = dai->component;
8214 + struct voicehat_priv *voicehat =
8215 + snd_soc_component_get_drvdata(component);
8216 +
8217 + if (voicehat->sdmode_delay_jiffies == 0)
8218 + return 0;
8219 +
8220 + dev_dbg(dai->dev, "CMD %d", cmd);
8221 + dev_dbg(dai->dev, "Playback Active %d", dai->stream_active[SNDRV_PCM_STREAM_PLAYBACK]);
8222 + dev_dbg(dai->dev, "Capture Active %d", dai->stream_active[SNDRV_PCM_STREAM_CAPTURE]);
8223 +
8224 + switch (cmd) {
8225 + case SNDRV_PCM_TRIGGER_START:
8226 + case SNDRV_PCM_TRIGGER_RESUME:
8227 + case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
8228 + if (dai->stream_active[SNDRV_PCM_STREAM_PLAYBACK]) {
8229 + dev_info(dai->dev, "Enabling audio amp...\n");
8230 + queue_delayed_work(
8231 + system_power_efficient_wq,
8232 + &voicehat->enable_sdmode_work,
8233 + voicehat->sdmode_delay_jiffies);
8234 + }
8235 + break;
8236 + case SNDRV_PCM_TRIGGER_STOP:
8237 + case SNDRV_PCM_TRIGGER_SUSPEND:
8238 + case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
8239 + if (dai->stream_active[SNDRV_PCM_STREAM_PLAYBACK]) {
8240 + cancel_delayed_work(&voicehat->enable_sdmode_work);
8241 + dev_info(dai->dev, "Disabling audio amp...\n");
8242 + gpiod_set_value(voicehat->sdmode_gpio, 0);
8243 + }
8244 + break;
8245 + }
8246 + return 0;
8247 +}
8248 +
8249 +static const struct snd_soc_dai_ops voicehat_dai_ops = {
8250 + .trigger = voicehat_daiops_trigger,
8251 +};
8252 +
8253 +static struct snd_soc_dai_driver voicehat_dai = {
8254 + .name = "voicehat-hifi",
8255 + .capture = {
8256 + .stream_name = "HiFi Capture",
8257 + .channels_min = 2,
8258 + .channels_max = 2,
8259 + .rates = SNDRV_PCM_RATE_48000,
8260 + .formats = SNDRV_PCM_FMTBIT_S32_LE
8261 + },
8262 + .playback = {
8263 + .stream_name = "HiFi Playback",
8264 + .channels_min = 2,
8265 + .channels_max = 2,
8266 + .rates = SNDRV_PCM_RATE_48000,
8267 + .formats = SNDRV_PCM_FMTBIT_S32_LE
8268 + },
8269 + .ops = &voicehat_dai_ops,
8270 + .symmetric_rate = 1
8271 +};
8272 +
8273 +#ifdef CONFIG_OF
8274 +static const struct of_device_id voicehat_ids[] = {
8275 + { .compatible = "google,voicehat", }, {}
8276 + };
8277 + MODULE_DEVICE_TABLE(of, voicehat_ids);
8278 +#endif
8279 +
8280 +static int voicehat_platform_probe(struct platform_device *pdev)
8281 +{
8282 + struct voicehat_priv *voicehat;
8283 + unsigned int sdmode_delay;
8284 + int ret;
8285 +
8286 + voicehat = devm_kzalloc(&pdev->dev, sizeof(*voicehat), GFP_KERNEL);
8287 + if (!voicehat)
8288 + return -ENOMEM;
8289 +
8290 + ret = device_property_read_u32(&pdev->dev, "voicehat_sdmode_delay",
8291 + &sdmode_delay);
8292 +
8293 + if (ret) {
8294 + sdmode_delay = SDMODE_DELAY_MS;
8295 + dev_info(&pdev->dev,
8296 + "property 'voicehat_sdmode_delay' not found default 5 mS");
8297 + } else {
8298 + dev_info(&pdev->dev, "property 'voicehat_sdmode_delay' found delay= %d mS",
8299 + sdmode_delay);
8300 + }
8301 + voicehat->sdmode_delay_jiffies = msecs_to_jiffies(sdmode_delay);
8302 +
8303 + dev_set_drvdata(&pdev->dev, voicehat);
8304 +
8305 + return snd_soc_register_component(&pdev->dev,
8306 + &voicehat_component_driver,
8307 + &voicehat_dai,
8308 + 1);
8309 +}
8310 +
8311 +static int voicehat_platform_remove(struct platform_device *pdev)
8312 +{
8313 + snd_soc_unregister_component(&pdev->dev);
8314 + return 0;
8315 +}
8316 +
8317 +static struct platform_driver voicehat_driver = {
8318 + .driver = {
8319 + .name = "voicehat-codec",
8320 + .of_match_table = of_match_ptr(voicehat_ids),
8321 + },
8322 + .probe = voicehat_platform_probe,
8323 + .remove = voicehat_platform_remove,
8324 +};
8325 +
8326 +module_platform_driver(voicehat_driver);
8327 +
8328 +MODULE_DESCRIPTION("Google voiceHAT Codec driver");
8329 +MODULE_AUTHOR("Peter Malkin <petermalkin@google.com>");
8330 +MODULE_LICENSE("GPL v2");
8331 --- /dev/null
8332 +++ b/sound/soc/bcm/hifiberry_dacplus.c
8333 @@ -0,0 +1,527 @@
8334 +/*
8335 + * ASoC Driver for HiFiBerry DAC+ / DAC Pro / AMP100
8336 + *
8337 + * Author: Daniel Matuschek, Stuart MacLean <stuart@hifiberry.com>
8338 + * Copyright 2014-2015
8339 + * based on code by Florian Meier <florian.meier@koalo.de>
8340 + * Headphone/AMP100 Joerg Schambacher <joerg@hifiberry.com>
8341 + *
8342 + * This program is free software; you can redistribute it and/or
8343 + * modify it under the terms of the GNU General Public License
8344 + * version 2 as published by the Free Software Foundation.
8345 + *
8346 + * This program is distributed in the hope that it will be useful, but
8347 + * WITHOUT ANY WARRANTY; without even the implied warranty of
8348 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
8349 + * General Public License for more details.
8350 + */
8351 +
8352 +#include <linux/module.h>
8353 +#include <linux/gpio/consumer.h>
8354 +#include <../drivers/gpio/gpiolib.h>
8355 +#include <linux/platform_device.h>
8356 +#include <linux/kernel.h>
8357 +#include <linux/clk.h>
8358 +#include <linux/kernel.h>
8359 +#include <linux/module.h>
8360 +#include <linux/of.h>
8361 +#include <linux/slab.h>
8362 +#include <linux/delay.h>
8363 +#include <linux/i2c.h>
8364 +
8365 +#include <sound/core.h>
8366 +#include <sound/pcm.h>
8367 +#include <sound/pcm_params.h>
8368 +#include <sound/soc.h>
8369 +#include <sound/jack.h>
8370 +
8371 +#include "../codecs/pcm512x.h"
8372 +
8373 +#define HIFIBERRY_DACPRO_NOCLOCK 0
8374 +#define HIFIBERRY_DACPRO_CLK44EN 1
8375 +#define HIFIBERRY_DACPRO_CLK48EN 2
8376 +
8377 +struct pcm512x_priv {
8378 + struct regmap *regmap;
8379 + struct clk *sclk;
8380 +};
8381 +
8382 +/* Clock rate of CLK44EN attached to GPIO6 pin */
8383 +#define CLK_44EN_RATE 22579200UL
8384 +/* Clock rate of CLK48EN attached to GPIO3 pin */
8385 +#define CLK_48EN_RATE 24576000UL
8386 +
8387 +static bool slave;
8388 +static bool snd_rpi_hifiberry_is_dacpro;
8389 +static bool digital_gain_0db_limit = true;
8390 +static bool leds_off;
8391 +static bool auto_mute;
8392 +static int mute_ext_ctl;
8393 +static int mute_ext;
8394 +static struct gpio_desc *snd_mute_gpio;
8395 +static struct gpio_desc *snd_reset_gpio;
8396 +static struct snd_soc_card snd_rpi_hifiberry_dacplus;
8397 +
8398 +static int snd_rpi_hifiberry_dacplus_mute_set(int mute)
8399 +{
8400 + gpiod_set_value_cansleep(snd_mute_gpio, mute);
8401 + return 1;
8402 +}
8403 +
8404 +static int snd_rpi_hifiberry_dacplus_mute_get(struct snd_kcontrol *kcontrol,
8405 + struct snd_ctl_elem_value *ucontrol)
8406 +{
8407 + ucontrol->value.integer.value[0] = mute_ext;
8408 +
8409 + return 0;
8410 +}
8411 +
8412 +static int snd_rpi_hifiberry_dacplus_mute_put(struct snd_kcontrol *kcontrol,
8413 + struct snd_ctl_elem_value *ucontrol)
8414 +{
8415 + if (mute_ext == ucontrol->value.integer.value[0])
8416 + return 0;
8417 +
8418 + mute_ext = ucontrol->value.integer.value[0];
8419 +
8420 + return snd_rpi_hifiberry_dacplus_mute_set(mute_ext);
8421 +}
8422 +
8423 +static const char * const mute_text[] = {"Play", "Mute"};
8424 +static const struct soc_enum hb_dacplus_opt_mute_enum =
8425 + SOC_ENUM_SINGLE_EXT(2, mute_text);
8426 +
8427 +static const struct snd_kcontrol_new hb_dacplus_opt_mute_controls[] = {
8428 + SOC_ENUM_EXT("Mute(ext)", hb_dacplus_opt_mute_enum,
8429 + snd_rpi_hifiberry_dacplus_mute_get,
8430 + snd_rpi_hifiberry_dacplus_mute_put),
8431 +};
8432 +
8433 +static void snd_rpi_hifiberry_dacplus_select_clk(struct snd_soc_component *component,
8434 + int clk_id)
8435 +{
8436 + switch (clk_id) {
8437 + case HIFIBERRY_DACPRO_NOCLOCK:
8438 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x24, 0x00);
8439 + break;
8440 + case HIFIBERRY_DACPRO_CLK44EN:
8441 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x24, 0x20);
8442 + break;
8443 + case HIFIBERRY_DACPRO_CLK48EN:
8444 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x24, 0x04);
8445 + break;
8446 + }
8447 + usleep_range(3000, 4000);
8448 +}
8449 +
8450 +static void snd_rpi_hifiberry_dacplus_clk_gpio(struct snd_soc_component *component)
8451 +{
8452 + snd_soc_component_update_bits(component, PCM512x_GPIO_EN, 0x24, 0x24);
8453 + snd_soc_component_update_bits(component, PCM512x_GPIO_OUTPUT_3, 0x0f, 0x02);
8454 + snd_soc_component_update_bits(component, PCM512x_GPIO_OUTPUT_6, 0x0f, 0x02);
8455 +}
8456 +
8457 +static bool snd_rpi_hifiberry_dacplus_is_sclk(struct snd_soc_component *component)
8458 +{
8459 + unsigned int sck;
8460 +
8461 + sck = snd_soc_component_read(component, PCM512x_RATE_DET_4);
8462 + return (!(sck & 0x40));
8463 +}
8464 +
8465 +static bool snd_rpi_hifiberry_dacplus_is_pro_card(struct snd_soc_component *component)
8466 +{
8467 + bool isClk44EN, isClk48En, isNoClk;
8468 +
8469 + snd_rpi_hifiberry_dacplus_clk_gpio(component);
8470 +
8471 + snd_rpi_hifiberry_dacplus_select_clk(component, HIFIBERRY_DACPRO_CLK44EN);
8472 + isClk44EN = snd_rpi_hifiberry_dacplus_is_sclk(component);
8473 +
8474 + snd_rpi_hifiberry_dacplus_select_clk(component, HIFIBERRY_DACPRO_NOCLOCK);
8475 + isNoClk = snd_rpi_hifiberry_dacplus_is_sclk(component);
8476 +
8477 + snd_rpi_hifiberry_dacplus_select_clk(component, HIFIBERRY_DACPRO_CLK48EN);
8478 + isClk48En = snd_rpi_hifiberry_dacplus_is_sclk(component);
8479 +
8480 + return (isClk44EN && isClk48En && !isNoClk);
8481 +}
8482 +
8483 +static int snd_rpi_hifiberry_dacplus_clk_for_rate(int sample_rate)
8484 +{
8485 + int type;
8486 +
8487 + switch (sample_rate) {
8488 + case 11025:
8489 + case 22050:
8490 + case 44100:
8491 + case 88200:
8492 + case 176400:
8493 + case 352800:
8494 + type = HIFIBERRY_DACPRO_CLK44EN;
8495 + break;
8496 + default:
8497 + type = HIFIBERRY_DACPRO_CLK48EN;
8498 + break;
8499 + }
8500 + return type;
8501 +}
8502 +
8503 +static void snd_rpi_hifiberry_dacplus_set_sclk(struct snd_soc_component *component,
8504 + int sample_rate)
8505 +{
8506 + struct pcm512x_priv *pcm512x = snd_soc_component_get_drvdata(component);
8507 +
8508 + if (!IS_ERR(pcm512x->sclk)) {
8509 + int ctype;
8510 +
8511 + ctype = snd_rpi_hifiberry_dacplus_clk_for_rate(sample_rate);
8512 + clk_set_rate(pcm512x->sclk, (ctype == HIFIBERRY_DACPRO_CLK44EN)
8513 + ? CLK_44EN_RATE : CLK_48EN_RATE);
8514 + snd_rpi_hifiberry_dacplus_select_clk(component, ctype);
8515 + }
8516 +}
8517 +
8518 +static int snd_rpi_hifiberry_dacplus_init(struct snd_soc_pcm_runtime *rtd)
8519 +{
8520 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
8521 + struct pcm512x_priv *priv;
8522 + struct snd_soc_card *card = &snd_rpi_hifiberry_dacplus;
8523 +
8524 + if (slave)
8525 + snd_rpi_hifiberry_is_dacpro = false;
8526 + else
8527 + snd_rpi_hifiberry_is_dacpro =
8528 + snd_rpi_hifiberry_dacplus_is_pro_card(component);
8529 +
8530 + if (snd_rpi_hifiberry_is_dacpro) {
8531 + struct snd_soc_dai_link *dai = rtd->dai_link;
8532 +
8533 + dai->name = "HiFiBerry DAC+ Pro";
8534 + dai->stream_name = "HiFiBerry DAC+ Pro HiFi";
8535 + dai->dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
8536 + | SND_SOC_DAIFMT_CBM_CFM;
8537 +
8538 + snd_soc_component_update_bits(component, PCM512x_BCLK_LRCLK_CFG, 0x31, 0x11);
8539 + snd_soc_component_update_bits(component, PCM512x_MASTER_MODE, 0x03, 0x03);
8540 + snd_soc_component_update_bits(component, PCM512x_MASTER_CLKDIV_2, 0x7f, 63);
8541 + } else {
8542 + priv = snd_soc_component_get_drvdata(component);
8543 + priv->sclk = ERR_PTR(-ENOENT);
8544 + }
8545 +
8546 + snd_soc_component_update_bits(component, PCM512x_GPIO_EN, 0x08, 0x08);
8547 + snd_soc_component_update_bits(component, PCM512x_GPIO_OUTPUT_4, 0x0f, 0x02);
8548 + if (leds_off)
8549 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x08, 0x00);
8550 + else
8551 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x08, 0x08);
8552 +
8553 + if (digital_gain_0db_limit) {
8554 + int ret;
8555 + struct snd_soc_card *card = rtd->card;
8556 +
8557 + ret = snd_soc_limit_volume(card, "Digital Playback Volume", 207);
8558 + if (ret < 0)
8559 + dev_warn(card->dev, "Failed to set volume limit: %d\n", ret);
8560 + }
8561 + if (snd_reset_gpio) {
8562 + gpiod_set_value_cansleep(snd_reset_gpio, 0);
8563 + msleep(1);
8564 + gpiod_set_value_cansleep(snd_reset_gpio, 1);
8565 + msleep(1);
8566 + gpiod_set_value_cansleep(snd_reset_gpio, 0);
8567 + }
8568 +
8569 + if (mute_ext_ctl)
8570 + snd_soc_add_card_controls(card, hb_dacplus_opt_mute_controls,
8571 + ARRAY_SIZE(hb_dacplus_opt_mute_controls));
8572 +
8573 + if (snd_mute_gpio)
8574 + gpiod_set_value_cansleep(snd_mute_gpio, mute_ext);
8575 +
8576 + return 0;
8577 +}
8578 +
8579 +static int snd_rpi_hifiberry_dacplus_update_rate_den(
8580 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
8581 +{
8582 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
8583 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
8584 + struct pcm512x_priv *pcm512x = snd_soc_component_get_drvdata(component);
8585 + struct snd_ratnum *rats_no_pll;
8586 + unsigned int num = 0, den = 0;
8587 + int err;
8588 +
8589 + rats_no_pll = devm_kzalloc(rtd->dev, sizeof(*rats_no_pll), GFP_KERNEL);
8590 + if (!rats_no_pll)
8591 + return -ENOMEM;
8592 +
8593 + rats_no_pll->num = clk_get_rate(pcm512x->sclk) / 64;
8594 + rats_no_pll->den_min = 1;
8595 + rats_no_pll->den_max = 128;
8596 + rats_no_pll->den_step = 1;
8597 +
8598 + err = snd_interval_ratnum(hw_param_interval(params,
8599 + SNDRV_PCM_HW_PARAM_RATE), 1, rats_no_pll, &num, &den);
8600 + if (err >= 0 && den) {
8601 + params->rate_num = num;
8602 + params->rate_den = den;
8603 + }
8604 +
8605 + devm_kfree(rtd->dev, rats_no_pll);
8606 + return 0;
8607 +}
8608 +
8609 +static int snd_rpi_hifiberry_dacplus_hw_params(
8610 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
8611 +{
8612 + int ret = 0;
8613 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
8614 + int channels = params_channels(params);
8615 + int width = 32;
8616 +
8617 + if (snd_rpi_hifiberry_is_dacpro) {
8618 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
8619 +
8620 + width = snd_pcm_format_physical_width(params_format(params));
8621 +
8622 + snd_rpi_hifiberry_dacplus_set_sclk(component,
8623 + params_rate(params));
8624 +
8625 + ret = snd_rpi_hifiberry_dacplus_update_rate_den(
8626 + substream, params);
8627 + }
8628 +
8629 + ret = snd_soc_dai_set_bclk_ratio(asoc_rtd_to_cpu(rtd, 0), channels * width);
8630 + if (ret)
8631 + return ret;
8632 + ret = snd_soc_dai_set_bclk_ratio(asoc_rtd_to_codec(rtd, 0), channels * width);
8633 + return ret;
8634 +}
8635 +
8636 +static int snd_rpi_hifiberry_dacplus_startup(
8637 + struct snd_pcm_substream *substream)
8638 +{
8639 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
8640 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
8641 +
8642 + if (auto_mute)
8643 + gpiod_set_value_cansleep(snd_mute_gpio, 0);
8644 + if (leds_off)
8645 + return 0;
8646 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x08, 0x08);
8647 + return 0;
8648 +}
8649 +
8650 +static void snd_rpi_hifiberry_dacplus_shutdown(
8651 + struct snd_pcm_substream *substream)
8652 +{
8653 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
8654 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
8655 +
8656 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x08, 0x00);
8657 + if (auto_mute)
8658 + gpiod_set_value_cansleep(snd_mute_gpio, 1);
8659 +}
8660 +
8661 +/* machine stream operations */
8662 +static struct snd_soc_ops snd_rpi_hifiberry_dacplus_ops = {
8663 + .hw_params = snd_rpi_hifiberry_dacplus_hw_params,
8664 + .startup = snd_rpi_hifiberry_dacplus_startup,
8665 + .shutdown = snd_rpi_hifiberry_dacplus_shutdown,
8666 +};
8667 +
8668 +SND_SOC_DAILINK_DEFS(rpi_hifiberry_dacplus,
8669 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
8670 + DAILINK_COMP_ARRAY(COMP_CODEC("pcm512x.1-004d", "pcm512x-hifi")),
8671 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
8672 +
8673 +static struct snd_soc_dai_link snd_rpi_hifiberry_dacplus_dai[] = {
8674 +{
8675 + .name = "HiFiBerry DAC+",
8676 + .stream_name = "HiFiBerry DAC+ HiFi",
8677 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
8678 + SND_SOC_DAIFMT_CBS_CFS,
8679 + .ops = &snd_rpi_hifiberry_dacplus_ops,
8680 + .init = snd_rpi_hifiberry_dacplus_init,
8681 + SND_SOC_DAILINK_REG(rpi_hifiberry_dacplus),
8682 +},
8683 +};
8684 +
8685 +/* aux device for optional headphone amp */
8686 +static struct snd_soc_aux_dev hifiberry_dacplus_aux_devs[] = {
8687 + {
8688 + .dlc = {
8689 + .name = "tpa6130a2.1-0060",
8690 + },
8691 + },
8692 +};
8693 +
8694 +/* audio machine driver */
8695 +static struct snd_soc_card snd_rpi_hifiberry_dacplus = {
8696 + .name = "snd_rpi_hifiberry_dacplus",
8697 + .driver_name = "HifiberryDacp",
8698 + .owner = THIS_MODULE,
8699 + .dai_link = snd_rpi_hifiberry_dacplus_dai,
8700 + .num_links = ARRAY_SIZE(snd_rpi_hifiberry_dacplus_dai),
8701 +};
8702 +
8703 +static int hb_hp_detect(void)
8704 +{
8705 + struct i2c_adapter *adap = i2c_get_adapter(1);
8706 + int ret;
8707 + struct i2c_client tpa_i2c_client = {
8708 + .addr = 0x60,
8709 + .adapter = adap,
8710 + };
8711 +
8712 + if (!adap)
8713 + return -EPROBE_DEFER; /* I2C module not yet available */
8714 +
8715 + ret = i2c_smbus_read_byte(&tpa_i2c_client) >= 0;
8716 + i2c_put_adapter(adap);
8717 + return ret;
8718 +};
8719 +
8720 +static struct property tpa_enable_prop = {
8721 + .name = "status",
8722 + .length = 4 + 1, /* length 'okay' + 1 */
8723 + .value = "okay",
8724 + };
8725 +
8726 +static int snd_rpi_hifiberry_dacplus_probe(struct platform_device *pdev)
8727 +{
8728 + int ret = 0;
8729 + struct snd_soc_card *card = &snd_rpi_hifiberry_dacplus;
8730 + int len;
8731 + struct device_node *tpa_node;
8732 + struct property *tpa_prop;
8733 + struct of_changeset ocs;
8734 + struct property *pp;
8735 + int tmp;
8736 +
8737 + /* probe for head phone amp */
8738 + ret = hb_hp_detect();
8739 + if (ret < 0)
8740 + return ret;
8741 + if (ret) {
8742 + card->aux_dev = hifiberry_dacplus_aux_devs;
8743 + card->num_aux_devs =
8744 + ARRAY_SIZE(hifiberry_dacplus_aux_devs);
8745 + tpa_node = of_find_compatible_node(NULL, NULL, "ti,tpa6130a2");
8746 + tpa_prop = of_find_property(tpa_node, "status", &len);
8747 +
8748 + if (strcmp((char *)tpa_prop->value, "okay")) {
8749 + /* and activate headphone using change_sets */
8750 + dev_info(&pdev->dev, "activating headphone amplifier");
8751 + of_changeset_init(&ocs);
8752 + ret = of_changeset_update_property(&ocs, tpa_node,
8753 + &tpa_enable_prop);
8754 + if (ret) {
8755 + dev_err(&pdev->dev,
8756 + "cannot activate headphone amplifier\n");
8757 + return -ENODEV;
8758 + }
8759 + ret = of_changeset_apply(&ocs);
8760 + if (ret) {
8761 + dev_err(&pdev->dev,
8762 + "cannot activate headphone amplifier\n");
8763 + return -ENODEV;
8764 + }
8765 + }
8766 + }
8767 +
8768 + snd_rpi_hifiberry_dacplus.dev = &pdev->dev;
8769 + if (pdev->dev.of_node) {
8770 + struct device_node *i2s_node;
8771 + struct snd_soc_dai_link *dai;
8772 +
8773 + dai = &snd_rpi_hifiberry_dacplus_dai[0];
8774 + i2s_node = of_parse_phandle(pdev->dev.of_node,
8775 + "i2s-controller", 0);
8776 +
8777 + if (i2s_node) {
8778 + dai->cpus->dai_name = NULL;
8779 + dai->cpus->of_node = i2s_node;
8780 + dai->platforms->name = NULL;
8781 + dai->platforms->of_node = i2s_node;
8782 + }
8783 +
8784 + digital_gain_0db_limit = !of_property_read_bool(
8785 + pdev->dev.of_node, "hifiberry,24db_digital_gain");
8786 + slave = of_property_read_bool(pdev->dev.of_node,
8787 + "hifiberry-dacplus,slave");
8788 + leds_off = of_property_read_bool(pdev->dev.of_node,
8789 + "hifiberry-dacplus,leds_off");
8790 + auto_mute = of_property_read_bool(pdev->dev.of_node,
8791 + "hifiberry-dacplus,auto_mute");
8792 +
8793 + /*
8794 + * check for HW MUTE as defined in DT-overlay
8795 + * active high, therefore default to HIGH to MUTE
8796 + */
8797 + snd_mute_gpio = devm_gpiod_get_optional(&pdev->dev,
8798 + "mute", GPIOD_OUT_HIGH);
8799 + if (IS_ERR(snd_mute_gpio)) {
8800 + dev_err(&pdev->dev, "Can't allocate GPIO (HW-MUTE)");
8801 + return PTR_ERR(snd_mute_gpio);
8802 + }
8803 +
8804 + /* add ALSA control if requested in DT-overlay (AMP100) */
8805 + pp = of_find_property(pdev->dev.of_node,
8806 + "hifiberry-dacplus,mute_ext_ctl", &tmp);
8807 + if (pp) {
8808 + if (!of_property_read_u32(pdev->dev.of_node,
8809 + "hifiberry-dacplus,mute_ext_ctl", &mute_ext)) {
8810 + /* ALSA control will be used */
8811 + mute_ext_ctl = 1;
8812 + }
8813 + }
8814 +
8815 + /* check for HW RESET (AMP100) */
8816 + snd_reset_gpio = devm_gpiod_get_optional(&pdev->dev,
8817 + "reset", GPIOD_OUT_HIGH);
8818 + if (IS_ERR(snd_reset_gpio)) {
8819 + dev_err(&pdev->dev, "Can't allocate GPIO (HW-RESET)");
8820 + return PTR_ERR(snd_reset_gpio);
8821 + }
8822 +
8823 + }
8824 +
8825 + ret = devm_snd_soc_register_card(&pdev->dev,
8826 + &snd_rpi_hifiberry_dacplus);
8827 + if (ret && ret != -EPROBE_DEFER)
8828 + dev_err(&pdev->dev,
8829 + "snd_soc_register_card() failed: %d\n", ret);
8830 + if (!ret) {
8831 + if (snd_mute_gpio)
8832 + dev_info(&pdev->dev, "GPIO%i for HW-MUTE selected",
8833 + gpio_chip_hwgpio(snd_mute_gpio));
8834 + if (snd_reset_gpio)
8835 + dev_info(&pdev->dev, "GPIO%i for HW-RESET selected",
8836 + gpio_chip_hwgpio(snd_reset_gpio));
8837 + }
8838 + return ret;
8839 +}
8840 +
8841 +static const struct of_device_id snd_rpi_hifiberry_dacplus_of_match[] = {
8842 + { .compatible = "hifiberry,hifiberry-dacplus", },
8843 + {},
8844 +};
8845 +MODULE_DEVICE_TABLE(of, snd_rpi_hifiberry_dacplus_of_match);
8846 +
8847 +static struct platform_driver snd_rpi_hifiberry_dacplus_driver = {
8848 + .driver = {
8849 + .name = "snd-rpi-hifiberry-dacplus",
8850 + .owner = THIS_MODULE,
8851 + .of_match_table = snd_rpi_hifiberry_dacplus_of_match,
8852 + },
8853 + .probe = snd_rpi_hifiberry_dacplus_probe,
8854 +};
8855 +
8856 +module_platform_driver(snd_rpi_hifiberry_dacplus_driver);
8857 +
8858 +MODULE_AUTHOR("Daniel Matuschek <daniel@hifiberry.com>");
8859 +MODULE_DESCRIPTION("ASoC Driver for HiFiBerry DAC+");
8860 +MODULE_LICENSE("GPL v2");
8861 --- /dev/null
8862 +++ b/sound/soc/bcm/hifiberry_dacplusadc.c
8863 @@ -0,0 +1,398 @@
8864 +/*
8865 + * ASoC Driver for HiFiBerry DAC+ / DAC Pro with ADC
8866 + *
8867 + * Author: Daniel Matuschek, Stuart MacLean <stuart@hifiberry.com>
8868 + * Copyright 2014-2015
8869 + * based on code by Florian Meier <florian.meier@koalo.de>
8870 + * ADC added by Joerg Schambacher <joscha@schambacher.com>
8871 + * Copyright 2018
8872 + *
8873 + * This program is free software; you can redistribute it and/or
8874 + * modify it under the terms of the GNU General Public License
8875 + * version 2 as published by the Free Software Foundation.
8876 + *
8877 + * This program is distributed in the hope that it will be useful, but
8878 + * WITHOUT ANY WARRANTY; without even the implied warranty of
8879 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
8880 + * General Public License for more details.
8881 + */
8882 +
8883 +#include <linux/module.h>
8884 +#include <linux/platform_device.h>
8885 +#include <linux/kernel.h>
8886 +#include <linux/clk.h>
8887 +#include <linux/kernel.h>
8888 +#include <linux/module.h>
8889 +#include <linux/of.h>
8890 +#include <linux/slab.h>
8891 +#include <linux/delay.h>
8892 +
8893 +#include <sound/core.h>
8894 +#include <sound/pcm.h>
8895 +#include <sound/pcm_params.h>
8896 +#include <sound/soc.h>
8897 +#include <sound/jack.h>
8898 +
8899 +#include "../codecs/pcm512x.h"
8900 +
8901 +#define HIFIBERRY_DACPRO_NOCLOCK 0
8902 +#define HIFIBERRY_DACPRO_CLK44EN 1
8903 +#define HIFIBERRY_DACPRO_CLK48EN 2
8904 +
8905 +struct platform_device *dmic_codec_dev;
8906 +
8907 +struct pcm512x_priv {
8908 + struct regmap *regmap;
8909 + struct clk *sclk;
8910 +};
8911 +
8912 +/* Clock rate of CLK44EN attached to GPIO6 pin */
8913 +#define CLK_44EN_RATE 22579200UL
8914 +/* Clock rate of CLK48EN attached to GPIO3 pin */
8915 +#define CLK_48EN_RATE 24576000UL
8916 +
8917 +static bool slave;
8918 +static bool snd_rpi_hifiberry_is_dacpro;
8919 +static bool digital_gain_0db_limit = true;
8920 +static bool leds_off;
8921 +
8922 +static void snd_rpi_hifiberry_dacplusadc_select_clk(struct snd_soc_component *component,
8923 + int clk_id)
8924 +{
8925 + switch (clk_id) {
8926 + case HIFIBERRY_DACPRO_NOCLOCK:
8927 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x24, 0x00);
8928 + break;
8929 + case HIFIBERRY_DACPRO_CLK44EN:
8930 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x24, 0x20);
8931 + break;
8932 + case HIFIBERRY_DACPRO_CLK48EN:
8933 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x24, 0x04);
8934 + break;
8935 + }
8936 +}
8937 +
8938 +static void snd_rpi_hifiberry_dacplusadc_clk_gpio(struct snd_soc_component *component)
8939 +{
8940 + snd_soc_component_update_bits(component, PCM512x_GPIO_EN, 0x24, 0x24);
8941 + snd_soc_component_update_bits(component, PCM512x_GPIO_OUTPUT_3, 0x0f, 0x02);
8942 + snd_soc_component_update_bits(component, PCM512x_GPIO_OUTPUT_6, 0x0f, 0x02);
8943 +}
8944 +
8945 +static bool snd_rpi_hifiberry_dacplusadc_is_sclk(struct snd_soc_component *component)
8946 +{
8947 + unsigned int sck;
8948 +
8949 + sck = snd_soc_component_read(component, PCM512x_RATE_DET_4);
8950 + return (!(sck & 0x40));
8951 +}
8952 +
8953 +static bool snd_rpi_hifiberry_dacplusadc_is_sclk_sleep(
8954 + struct snd_soc_component *component)
8955 +{
8956 + msleep(2);
8957 + return snd_rpi_hifiberry_dacplusadc_is_sclk(component);
8958 +}
8959 +
8960 +static bool snd_rpi_hifiberry_dacplusadc_is_pro_card(struct snd_soc_component *component)
8961 +{
8962 + bool isClk44EN, isClk48En, isNoClk;
8963 +
8964 + snd_rpi_hifiberry_dacplusadc_clk_gpio(component);
8965 +
8966 + snd_rpi_hifiberry_dacplusadc_select_clk(component, HIFIBERRY_DACPRO_CLK44EN);
8967 + isClk44EN = snd_rpi_hifiberry_dacplusadc_is_sclk_sleep(component);
8968 +
8969 + snd_rpi_hifiberry_dacplusadc_select_clk(component, HIFIBERRY_DACPRO_NOCLOCK);
8970 + isNoClk = snd_rpi_hifiberry_dacplusadc_is_sclk_sleep(component);
8971 +
8972 + snd_rpi_hifiberry_dacplusadc_select_clk(component, HIFIBERRY_DACPRO_CLK48EN);
8973 + isClk48En = snd_rpi_hifiberry_dacplusadc_is_sclk_sleep(component);
8974 +
8975 + return (isClk44EN && isClk48En && !isNoClk);
8976 +}
8977 +
8978 +static int snd_rpi_hifiberry_dacplusadc_clk_for_rate(int sample_rate)
8979 +{
8980 + int type;
8981 +
8982 + switch (sample_rate) {
8983 + case 11025:
8984 + case 22050:
8985 + case 44100:
8986 + case 88200:
8987 + case 176400:
8988 + case 352800:
8989 + type = HIFIBERRY_DACPRO_CLK44EN;
8990 + break;
8991 + default:
8992 + type = HIFIBERRY_DACPRO_CLK48EN;
8993 + break;
8994 + }
8995 + return type;
8996 +}
8997 +
8998 +static void snd_rpi_hifiberry_dacplusadc_set_sclk(struct snd_soc_component *component,
8999 + int sample_rate)
9000 +{
9001 + struct pcm512x_priv *pcm512x = snd_soc_component_get_drvdata(component);
9002 +
9003 + if (!IS_ERR(pcm512x->sclk)) {
9004 + int ctype;
9005 +
9006 + ctype = snd_rpi_hifiberry_dacplusadc_clk_for_rate(sample_rate);
9007 + clk_set_rate(pcm512x->sclk, (ctype == HIFIBERRY_DACPRO_CLK44EN)
9008 + ? CLK_44EN_RATE : CLK_48EN_RATE);
9009 + snd_rpi_hifiberry_dacplusadc_select_clk(component, ctype);
9010 + }
9011 +}
9012 +
9013 +static int snd_rpi_hifiberry_dacplusadc_init(struct snd_soc_pcm_runtime *rtd)
9014 +{
9015 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
9016 + struct pcm512x_priv *priv;
9017 +
9018 + if (slave)
9019 + snd_rpi_hifiberry_is_dacpro = false;
9020 + else
9021 + snd_rpi_hifiberry_is_dacpro =
9022 + snd_rpi_hifiberry_dacplusadc_is_pro_card(component);
9023 +
9024 + if (snd_rpi_hifiberry_is_dacpro) {
9025 + struct snd_soc_dai_link *dai = rtd->dai_link;
9026 +
9027 + dai->name = "HiFiBerry ADCDAC+ Pro";
9028 + dai->stream_name = "HiFiBerry ADCDAC+ Pro HiFi";
9029 + dai->dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
9030 + | SND_SOC_DAIFMT_CBM_CFM;
9031 +
9032 + snd_soc_component_update_bits(component, PCM512x_BCLK_LRCLK_CFG, 0x31, 0x11);
9033 + snd_soc_component_update_bits(component, PCM512x_MASTER_MODE, 0x03, 0x03);
9034 + snd_soc_component_update_bits(component, PCM512x_MASTER_CLKDIV_2, 0x7f, 63);
9035 + } else {
9036 + priv = snd_soc_component_get_drvdata(component);
9037 + priv->sclk = ERR_PTR(-ENOENT);
9038 + }
9039 +
9040 + snd_soc_component_update_bits(component, PCM512x_GPIO_EN, 0x08, 0x08);
9041 + snd_soc_component_update_bits(component, PCM512x_GPIO_OUTPUT_4, 0x0f, 0x02);
9042 + if (leds_off)
9043 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x08, 0x00);
9044 + else
9045 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x08, 0x08);
9046 +
9047 + if (digital_gain_0db_limit) {
9048 + int ret;
9049 + struct snd_soc_card *card = rtd->card;
9050 +
9051 + ret = snd_soc_limit_volume(card, "Digital Playback Volume", 207);
9052 + if (ret < 0)
9053 + dev_warn(card->dev, "Failed to set volume limit: %d\n", ret);
9054 + }
9055 +
9056 + return 0;
9057 +}
9058 +
9059 +static int snd_rpi_hifiberry_dacplusadc_update_rate_den(
9060 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
9061 +{
9062 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
9063 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
9064 + struct pcm512x_priv *pcm512x = snd_soc_component_get_drvdata(component);
9065 + struct snd_ratnum *rats_no_pll;
9066 + unsigned int num = 0, den = 0;
9067 + int err;
9068 +
9069 + rats_no_pll = devm_kzalloc(rtd->dev, sizeof(*rats_no_pll), GFP_KERNEL);
9070 + if (!rats_no_pll)
9071 + return -ENOMEM;
9072 +
9073 + rats_no_pll->num = clk_get_rate(pcm512x->sclk) / 64;
9074 + rats_no_pll->den_min = 1;
9075 + rats_no_pll->den_max = 128;
9076 + rats_no_pll->den_step = 1;
9077 +
9078 + err = snd_interval_ratnum(hw_param_interval(params,
9079 + SNDRV_PCM_HW_PARAM_RATE), 1, rats_no_pll, &num, &den);
9080 + if (err >= 0 && den) {
9081 + params->rate_num = num;
9082 + params->rate_den = den;
9083 + }
9084 +
9085 + devm_kfree(rtd->dev, rats_no_pll);
9086 + return 0;
9087 +}
9088 +
9089 +static int snd_rpi_hifiberry_dacplusadc_hw_params(
9090 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
9091 +{
9092 + int ret = 0;
9093 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
9094 + int channels = params_channels(params);
9095 + int width = 32;
9096 +
9097 + if (snd_rpi_hifiberry_is_dacpro) {
9098 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
9099 +
9100 + width = snd_pcm_format_physical_width(params_format(params));
9101 +
9102 + snd_rpi_hifiberry_dacplusadc_set_sclk(component,
9103 + params_rate(params));
9104 +
9105 + ret = snd_rpi_hifiberry_dacplusadc_update_rate_den(
9106 + substream, params);
9107 + }
9108 +
9109 + ret = snd_soc_dai_set_bclk_ratio(asoc_rtd_to_cpu(rtd, 0), channels * width);
9110 + if (ret)
9111 + return ret;
9112 + ret = snd_soc_dai_set_bclk_ratio(asoc_rtd_to_codec(rtd, 0), channels * width);
9113 + return ret;
9114 +}
9115 +
9116 +static int hifiberry_dacplusadc_LED_cnt;
9117 +
9118 +static int snd_rpi_hifiberry_dacplusadc_startup(
9119 + struct snd_pcm_substream *substream)
9120 +{
9121 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
9122 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
9123 +
9124 + if (leds_off)
9125 + return 0;
9126 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1,
9127 + 0x08, 0x08);
9128 + hifiberry_dacplusadc_LED_cnt++;
9129 + return 0;
9130 +}
9131 +
9132 +static void snd_rpi_hifiberry_dacplusadc_shutdown(
9133 + struct snd_pcm_substream *substream)
9134 +{
9135 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
9136 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
9137 +
9138 + hifiberry_dacplusadc_LED_cnt--;
9139 + if (!hifiberry_dacplusadc_LED_cnt)
9140 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1,
9141 + 0x08, 0x00);
9142 +}
9143 +
9144 +/* machine stream operations */
9145 +static struct snd_soc_ops snd_rpi_hifiberry_dacplusadc_ops = {
9146 + .hw_params = snd_rpi_hifiberry_dacplusadc_hw_params,
9147 + .startup = snd_rpi_hifiberry_dacplusadc_startup,
9148 + .shutdown = snd_rpi_hifiberry_dacplusadc_shutdown,
9149 +};
9150 +
9151 +SND_SOC_DAILINK_DEFS(hifi,
9152 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
9153 + DAILINK_COMP_ARRAY(COMP_CODEC("pcm512x.1-004d", "pcm512x-hifi"),
9154 + COMP_CODEC("dmic-codec", "dmic-hifi")),
9155 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
9156 +
9157 +static struct snd_soc_dai_link snd_rpi_hifiberry_dacplusadc_dai[] = {
9158 +{
9159 + .name = "HiFiBerry DAC+ADC",
9160 + .stream_name = "HiFiBerry DAC+ADC HiFi",
9161 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
9162 + SND_SOC_DAIFMT_CBS_CFS,
9163 + .ops = &snd_rpi_hifiberry_dacplusadc_ops,
9164 + .init = snd_rpi_hifiberry_dacplusadc_init,
9165 + SND_SOC_DAILINK_REG(hifi),
9166 +},
9167 +};
9168 +
9169 +/* audio machine driver */
9170 +static struct snd_soc_card snd_rpi_hifiberry_dacplusadc = {
9171 + .name = "snd_rpi_hifiberry_dacplusadc",
9172 + .driver_name = "HifiberryDacpAdc",
9173 + .owner = THIS_MODULE,
9174 + .dai_link = snd_rpi_hifiberry_dacplusadc_dai,
9175 + .num_links = ARRAY_SIZE(snd_rpi_hifiberry_dacplusadc_dai),
9176 +};
9177 +
9178 +
9179 +static int snd_rpi_hifiberry_dacplusadc_probe(struct platform_device *pdev)
9180 +{
9181 + int ret = 0;
9182 +
9183 + snd_rpi_hifiberry_dacplusadc.dev = &pdev->dev;
9184 + if (pdev->dev.of_node) {
9185 + struct device_node *i2s_node;
9186 + struct snd_soc_dai_link *dai;
9187 +
9188 + dai = &snd_rpi_hifiberry_dacplusadc_dai[0];
9189 + i2s_node = of_parse_phandle(pdev->dev.of_node,
9190 + "i2s-controller", 0);
9191 + if (i2s_node) {
9192 + dai->cpus->of_node = i2s_node;
9193 + dai->platforms->of_node = i2s_node;
9194 + dai->cpus->dai_name = NULL;
9195 + dai->platforms->name = NULL;
9196 + }
9197 + }
9198 + digital_gain_0db_limit = !of_property_read_bool(
9199 + pdev->dev.of_node, "hifiberry,24db_digital_gain");
9200 + slave = of_property_read_bool(pdev->dev.of_node,
9201 + "hifiberry-dacplusadc,slave");
9202 + leds_off = of_property_read_bool(pdev->dev.of_node,
9203 + "hifiberry-dacplusadc,leds_off");
9204 +
9205 + ret = devm_snd_soc_register_card(&pdev->dev,
9206 + &snd_rpi_hifiberry_dacplusadc);
9207 + if (ret && ret != -EPROBE_DEFER)
9208 + dev_err(&pdev->dev,
9209 + "snd_soc_register_card() failed: %d\n", ret);
9210 +
9211 + return ret;
9212 +}
9213 +
9214 +static const struct of_device_id snd_rpi_hifiberry_dacplusadc_of_match[] = {
9215 + { .compatible = "hifiberry,hifiberry-dacplusadc", },
9216 + {},
9217 +};
9218 +
9219 +MODULE_DEVICE_TABLE(of, snd_rpi_hifiberry_dacplusadc_of_match);
9220 +
9221 +static struct platform_driver snd_rpi_hifiberry_dacplusadc_driver = {
9222 + .driver = {
9223 + .name = "snd-rpi-hifiberry-dacplusadc",
9224 + .owner = THIS_MODULE,
9225 + .of_match_table = snd_rpi_hifiberry_dacplusadc_of_match,
9226 + },
9227 + .probe = snd_rpi_hifiberry_dacplusadc_probe,
9228 +};
9229 +
9230 +static int __init hifiberry_dacplusadc_init(void)
9231 +{
9232 + int ret;
9233 +
9234 + dmic_codec_dev = platform_device_register_simple("dmic-codec", -1, NULL,
9235 + 0);
9236 + if (IS_ERR(dmic_codec_dev)) {
9237 + pr_err("%s: dmic-codec device registration failed\n", __func__);
9238 + return PTR_ERR(dmic_codec_dev);
9239 + }
9240 +
9241 + ret = platform_driver_register(&snd_rpi_hifiberry_dacplusadc_driver);
9242 + if (ret) {
9243 + pr_err("%s: platform driver registration failed\n", __func__);
9244 + platform_device_unregister(dmic_codec_dev);
9245 + }
9246 +
9247 + return ret;
9248 +}
9249 +module_init(hifiberry_dacplusadc_init);
9250 +
9251 +static void __exit hifiberry_dacplusadc_exit(void)
9252 +{
9253 + platform_driver_unregister(&snd_rpi_hifiberry_dacplusadc_driver);
9254 + platform_device_unregister(dmic_codec_dev);
9255 +}
9256 +module_exit(hifiberry_dacplusadc_exit);
9257 +
9258 +MODULE_AUTHOR("Joerg Schambacher <joscha@schambacher.com>");
9259 +MODULE_AUTHOR("Daniel Matuschek <daniel@hifiberry.com>");
9260 +MODULE_DESCRIPTION("ASoC Driver for HiFiBerry DAC+ADC");
9261 +MODULE_LICENSE("GPL v2");
9262 --- /dev/null
9263 +++ b/sound/soc/bcm/hifiberry_dacplusadcpro.c
9264 @@ -0,0 +1,605 @@
9265 +/*
9266 + * ASoC Driver for HiFiBerry DAC+ / DAC Pro with ADC PRO Version (SW control)
9267 + *
9268 + * Author: Daniel Matuschek, Stuart MacLean <stuart@hifiberry.com>
9269 + * Copyright 2014-2015
9270 + * based on code by Florian Meier <florian.meier@koalo.de>
9271 + * ADC, HP added by Joerg Schambacher <joerg@hifiberry.com>
9272 + * Copyright 2018-21
9273 + *
9274 + * This program is free software; you can redistribute it and/or
9275 + * modify it under the terms of the GNU General Public License
9276 + * version 2 as published by the Free Software Foundation.
9277 + *
9278 + * This program is distributed in the hope that it will be useful, but
9279 + * WITHOUT ANY WARRANTY; without even the implied warranty of
9280 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9281 + * General Public License for more details.
9282 + */
9283 +
9284 +#include <linux/module.h>
9285 +#include <linux/platform_device.h>
9286 +#include <linux/kernel.h>
9287 +#include <linux/clk.h>
9288 +#include <linux/kernel.h>
9289 +#include <linux/module.h>
9290 +#include <linux/of.h>
9291 +#include <linux/slab.h>
9292 +#include <linux/delay.h>
9293 +#include <linux/i2c.h>
9294 +
9295 +#include <sound/core.h>
9296 +#include <sound/pcm.h>
9297 +#include <sound/pcm_params.h>
9298 +#include <sound/soc.h>
9299 +#include <sound/jack.h>
9300 +#include <sound/tlv.h>
9301 +
9302 +#include "../codecs/pcm512x.h"
9303 +#include "../codecs/pcm186x.h"
9304 +
9305 +#define HIFIBERRY_DACPRO_NOCLOCK 0
9306 +#define HIFIBERRY_DACPRO_CLK44EN 1
9307 +#define HIFIBERRY_DACPRO_CLK48EN 2
9308 +
9309 +struct pcm512x_priv {
9310 + struct regmap *regmap;
9311 + struct clk *sclk;
9312 +};
9313 +
9314 +/* Clock rate of CLK44EN attached to GPIO6 pin */
9315 +#define CLK_44EN_RATE 22579200UL
9316 +/* Clock rate of CLK48EN attached to GPIO3 pin */
9317 +#define CLK_48EN_RATE 24576000UL
9318 +
9319 +static bool slave;
9320 +static bool snd_rpi_hifiberry_is_dacpro;
9321 +static bool digital_gain_0db_limit = true;
9322 +static bool leds_off;
9323 +
9324 +static const unsigned int pcm186x_adc_input_channel_sel_value[] = {
9325 + 0x00, 0x01, 0x02, 0x03, 0x10
9326 +};
9327 +
9328 +static const char * const pcm186x_adcl_input_channel_sel_text[] = {
9329 + "No Select",
9330 + "VINL1[SE]", /* Default for ADCL */
9331 + "VINL2[SE]",
9332 + "VINL2[SE] + VINL1[SE]",
9333 + "{VIN1P, VIN1M}[DIFF]"
9334 +};
9335 +
9336 +static const char * const pcm186x_adcr_input_channel_sel_text[] = {
9337 + "No Select",
9338 + "VINR1[SE]", /* Default for ADCR */
9339 + "VINR2[SE]",
9340 + "VINR2[SE] + VINR1[SE]",
9341 + "{VIN2P, VIN2M}[DIFF]"
9342 +};
9343 +
9344 +static const struct soc_enum pcm186x_adc_input_channel_sel[] = {
9345 + SOC_VALUE_ENUM_SINGLE(PCM186X_ADC1_INPUT_SEL_L, 0,
9346 + PCM186X_ADC_INPUT_SEL_MASK,
9347 + ARRAY_SIZE(pcm186x_adcl_input_channel_sel_text),
9348 + pcm186x_adcl_input_channel_sel_text,
9349 + pcm186x_adc_input_channel_sel_value),
9350 + SOC_VALUE_ENUM_SINGLE(PCM186X_ADC1_INPUT_SEL_R, 0,
9351 + PCM186X_ADC_INPUT_SEL_MASK,
9352 + ARRAY_SIZE(pcm186x_adcr_input_channel_sel_text),
9353 + pcm186x_adcr_input_channel_sel_text,
9354 + pcm186x_adc_input_channel_sel_value),
9355 +};
9356 +
9357 +static const unsigned int pcm186x_mic_bias_sel_value[] = {
9358 + 0x00, 0x01, 0x11
9359 +};
9360 +
9361 +static const char * const pcm186x_mic_bias_sel_text[] = {
9362 + "Mic Bias off",
9363 + "Mic Bias on",
9364 + "Mic Bias with Bypass Resistor"
9365 +};
9366 +
9367 +static const struct soc_enum pcm186x_mic_bias_sel[] = {
9368 + SOC_VALUE_ENUM_SINGLE(PCM186X_MIC_BIAS_CTRL, 0,
9369 + GENMASK(4, 0),
9370 + ARRAY_SIZE(pcm186x_mic_bias_sel_text),
9371 + pcm186x_mic_bias_sel_text,
9372 + pcm186x_mic_bias_sel_value),
9373 +};
9374 +
9375 +static const unsigned int pcm186x_gain_sel_value[] = {
9376 + 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
9377 + 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
9378 + 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
9379 + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
9380 + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
9381 + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
9382 + 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
9383 + 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
9384 + 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
9385 + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
9386 + 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
9387 + 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
9388 + 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
9389 + 0x50
9390 +};
9391 +
9392 +static const char * const pcm186x_gain_sel_text[] = {
9393 + "-12.0dB", "-11.5dB", "-11.0dB", "-10.5dB", "-10.0dB", "-9.5dB",
9394 + "-9.0dB", "-8.5dB", "-8.0dB", "-7.5dB", "-7.0dB", "-6.5dB",
9395 + "-6.0dB", "-5.5dB", "-5.0dB", "-4.5dB", "-4.0dB", "-3.5dB",
9396 + "-3.0dB", "-2.5dB", "-2.0dB", "-1.5dB", "-1.0dB", "-0.5dB",
9397 + "0.0dB", "0.5dB", "1.0dB", "1.5dB", "2.0dB", "2.5dB",
9398 + "3.0dB", "3.5dB", "4.0dB", "4.5dB", "5.0dB", "5.5dB",
9399 + "6.0dB", "6.5dB", "7.0dB", "7.5dB", "8.0dB", "8.5dB",
9400 + "9.0dB", "9.5dB", "10.0dB", "10.5dB", "11.0dB", "11.5dB",
9401 + "12.0dB", "12.5dB", "13.0dB", "13.5dB", "14.0dB", "14.5dB",
9402 + "15.0dB", "15.5dB", "16.0dB", "16.5dB", "17.0dB", "17.5dB",
9403 + "18.0dB", "18.5dB", "19.0dB", "19.5dB", "20.0dB", "20.5dB",
9404 + "21.0dB", "21.5dB", "22.0dB", "22.5dB", "23.0dB", "23.5dB",
9405 + "24.0dB", "24.5dB", "25.0dB", "25.5dB", "26.0dB", "26.5dB",
9406 + "27.0dB", "27.5dB", "28.0dB", "28.5dB", "29.0dB", "29.5dB",
9407 + "30.0dB", "30.5dB", "31.0dB", "31.5dB", "32.0dB", "32.5dB",
9408 + "33.0dB", "33.5dB", "34.0dB", "34.5dB", "35.0dB", "35.5dB",
9409 + "36.0dB", "36.5dB", "37.0dB", "37.5dB", "38.0dB", "38.5dB",
9410 + "39.0dB", "39.5dB", "40.0dB"};
9411 +
9412 +static const struct soc_enum pcm186x_gain_sel[] = {
9413 + SOC_VALUE_ENUM_SINGLE(PCM186X_PGA_VAL_CH1_L, 0,
9414 + 0xff,
9415 + ARRAY_SIZE(pcm186x_gain_sel_text),
9416 + pcm186x_gain_sel_text,
9417 + pcm186x_gain_sel_value),
9418 + SOC_VALUE_ENUM_SINGLE(PCM186X_PGA_VAL_CH1_R, 0,
9419 + 0xff,
9420 + ARRAY_SIZE(pcm186x_gain_sel_text),
9421 + pcm186x_gain_sel_text,
9422 + pcm186x_gain_sel_value),
9423 +};
9424 +
9425 +static const struct snd_kcontrol_new pcm1863_snd_controls_card[] = {
9426 + SOC_ENUM("ADC Left Input", pcm186x_adc_input_channel_sel[0]),
9427 + SOC_ENUM("ADC Right Input", pcm186x_adc_input_channel_sel[1]),
9428 + SOC_ENUM("ADC Mic Bias", pcm186x_mic_bias_sel),
9429 + SOC_ENUM("PGA Gain Left", pcm186x_gain_sel[0]),
9430 + SOC_ENUM("PGA Gain Right", pcm186x_gain_sel[1]),
9431 +};
9432 +
9433 +static int pcm1863_add_controls(struct snd_soc_component *component)
9434 +{
9435 + snd_soc_add_component_controls(component,
9436 + pcm1863_snd_controls_card,
9437 + ARRAY_SIZE(pcm1863_snd_controls_card));
9438 + return 0;
9439 +}
9440 +
9441 +static void snd_rpi_hifiberry_dacplusadcpro_select_clk(
9442 + struct snd_soc_component *component, int clk_id)
9443 +{
9444 + switch (clk_id) {
9445 + case HIFIBERRY_DACPRO_NOCLOCK:
9446 + snd_soc_component_update_bits(component,
9447 + PCM512x_GPIO_CONTROL_1, 0x24, 0x00);
9448 + break;
9449 + case HIFIBERRY_DACPRO_CLK44EN:
9450 + snd_soc_component_update_bits(component,
9451 + PCM512x_GPIO_CONTROL_1, 0x24, 0x20);
9452 + break;
9453 + case HIFIBERRY_DACPRO_CLK48EN:
9454 + snd_soc_component_update_bits(component,
9455 + PCM512x_GPIO_CONTROL_1, 0x24, 0x04);
9456 + break;
9457 + }
9458 + usleep_range(3000, 4000);
9459 +}
9460 +
9461 +static void snd_rpi_hifiberry_dacplusadcpro_clk_gpio(struct snd_soc_component *component)
9462 +{
9463 + snd_soc_component_update_bits(component, PCM512x_GPIO_EN, 0x24, 0x24);
9464 + snd_soc_component_update_bits(component, PCM512x_GPIO_OUTPUT_3, 0x0f, 0x02);
9465 + snd_soc_component_update_bits(component, PCM512x_GPIO_OUTPUT_6, 0x0f, 0x02);
9466 +}
9467 +
9468 +static bool snd_rpi_hifiberry_dacplusadcpro_is_sclk(struct snd_soc_component *component)
9469 +{
9470 + unsigned int sck;
9471 +
9472 + sck = snd_soc_component_read(component, PCM512x_RATE_DET_4);
9473 + return (!(sck & 0x40));
9474 +}
9475 +
9476 +static bool snd_rpi_hifiberry_dacplusadcpro_is_pro_card(struct snd_soc_component *component)
9477 +{
9478 + bool isClk44EN, isClk48En, isNoClk;
9479 +
9480 + snd_rpi_hifiberry_dacplusadcpro_clk_gpio(component);
9481 +
9482 + snd_rpi_hifiberry_dacplusadcpro_select_clk(component, HIFIBERRY_DACPRO_CLK44EN);
9483 + isClk44EN = snd_rpi_hifiberry_dacplusadcpro_is_sclk(component);
9484 +
9485 + snd_rpi_hifiberry_dacplusadcpro_select_clk(component, HIFIBERRY_DACPRO_NOCLOCK);
9486 + isNoClk = snd_rpi_hifiberry_dacplusadcpro_is_sclk(component);
9487 +
9488 + snd_rpi_hifiberry_dacplusadcpro_select_clk(component, HIFIBERRY_DACPRO_CLK48EN);
9489 + isClk48En = snd_rpi_hifiberry_dacplusadcpro_is_sclk(component);
9490 +
9491 + return (isClk44EN && isClk48En && !isNoClk);
9492 +}
9493 +
9494 +static int snd_rpi_hifiberry_dacplusadcpro_clk_for_rate(int sample_rate)
9495 +{
9496 + int type;
9497 +
9498 + switch (sample_rate) {
9499 + case 11025:
9500 + case 22050:
9501 + case 44100:
9502 + case 88200:
9503 + case 176400:
9504 + case 352800:
9505 + type = HIFIBERRY_DACPRO_CLK44EN;
9506 + break;
9507 + default:
9508 + type = HIFIBERRY_DACPRO_CLK48EN;
9509 + break;
9510 + }
9511 + return type;
9512 +}
9513 +
9514 +static void snd_rpi_hifiberry_dacplusadcpro_set_sclk(struct snd_soc_component *component,
9515 + int sample_rate)
9516 +{
9517 + struct pcm512x_priv *pcm512x = snd_soc_component_get_drvdata(component);
9518 +
9519 + if (!IS_ERR(pcm512x->sclk)) {
9520 + int ctype;
9521 +
9522 + ctype = snd_rpi_hifiberry_dacplusadcpro_clk_for_rate(sample_rate);
9523 + clk_set_rate(pcm512x->sclk, (ctype == HIFIBERRY_DACPRO_CLK44EN)
9524 + ? CLK_44EN_RATE : CLK_48EN_RATE);
9525 + snd_rpi_hifiberry_dacplusadcpro_select_clk(component, ctype);
9526 + }
9527 +}
9528 +
9529 +static int snd_rpi_hifiberry_dacplusadcpro_init(struct snd_soc_pcm_runtime *rtd)
9530 +{
9531 + struct snd_soc_component *dac = asoc_rtd_to_codec(rtd, 0)->component;
9532 + struct snd_soc_component *adc = asoc_rtd_to_codec(rtd, 1)->component;
9533 + struct snd_soc_dai_driver *adc_driver = asoc_rtd_to_codec(rtd, 1)->driver;
9534 + struct pcm512x_priv *priv;
9535 + int ret;
9536 +
9537 + if (slave)
9538 + snd_rpi_hifiberry_is_dacpro = false;
9539 + else
9540 + snd_rpi_hifiberry_is_dacpro =
9541 + snd_rpi_hifiberry_dacplusadcpro_is_pro_card(dac);
9542 +
9543 + if (snd_rpi_hifiberry_is_dacpro) {
9544 + struct snd_soc_dai_link *dai = rtd->dai_link;
9545 +
9546 + dai->name = "HiFiBerry DAC+ADC Pro";
9547 + dai->stream_name = "HiFiBerry DAC+ADC Pro HiFi";
9548 + dai->dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
9549 + | SND_SOC_DAIFMT_CBM_CFM;
9550 +
9551 + // set DAC DAI configuration
9552 + ret = snd_soc_dai_set_fmt(asoc_rtd_to_codec(rtd, 0),
9553 + SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
9554 + | SND_SOC_DAIFMT_CBM_CFM);
9555 + if (ret < 0)
9556 + return ret;
9557 +
9558 + // set ADC DAI configuration
9559 + ret = snd_soc_dai_set_fmt(asoc_rtd_to_codec(rtd, 1),
9560 + SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
9561 + | SND_SOC_DAIFMT_CBS_CFS);
9562 + if (ret < 0)
9563 + return ret;
9564 +
9565 + // set CPU DAI configuration
9566 + ret = snd_soc_dai_set_fmt(asoc_rtd_to_cpu(rtd, 0),
9567 + SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
9568 + if (ret < 0)
9569 + return ret;
9570 +
9571 + snd_soc_component_update_bits(dac, PCM512x_BCLK_LRCLK_CFG, 0x31, 0x11);
9572 + snd_soc_component_update_bits(dac, PCM512x_MASTER_MODE, 0x03, 0x03);
9573 + snd_soc_component_update_bits(dac, PCM512x_MASTER_CLKDIV_2, 0x7f, 63);
9574 + } else {
9575 + priv = snd_soc_component_get_drvdata(dac);
9576 + priv->sclk = ERR_PTR(-ENOENT);
9577 + }
9578 +
9579 + /* disable 24bit mode as long as I2S module does not have sign extension fixed */
9580 + adc_driver->capture.formats = SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S16_LE;
9581 +
9582 + snd_soc_component_update_bits(dac, PCM512x_GPIO_EN, 0x08, 0x08);
9583 + snd_soc_component_update_bits(dac, PCM512x_GPIO_OUTPUT_4, 0x0f, 0x02);
9584 + if (leds_off)
9585 + snd_soc_component_update_bits(dac, PCM512x_GPIO_CONTROL_1, 0x08, 0x00);
9586 + else
9587 + snd_soc_component_update_bits(dac, PCM512x_GPIO_CONTROL_1, 0x08, 0x08);
9588 +
9589 + ret = pcm1863_add_controls(adc);
9590 + if (ret < 0)
9591 + dev_warn(rtd->dev, "Failed to add pcm1863 controls: %d\n",
9592 + ret);
9593 +
9594 + /* set GPIO2 to output, GPIO3 input */
9595 + snd_soc_component_write(adc, PCM186X_GPIO3_2_CTRL, 0x00);
9596 + snd_soc_component_write(adc, PCM186X_GPIO3_2_DIR_CTRL, 0x04);
9597 + if (leds_off)
9598 + snd_soc_component_update_bits(adc, PCM186X_GPIO_IN_OUT, 0x40, 0x00);
9599 + else
9600 + snd_soc_component_update_bits(adc, PCM186X_GPIO_IN_OUT, 0x40, 0x40);
9601 +
9602 + if (digital_gain_0db_limit) {
9603 + int ret;
9604 + struct snd_soc_card *card = rtd->card;
9605 +
9606 + ret = snd_soc_limit_volume(card, "Digital Playback Volume", 207);
9607 + if (ret < 0)
9608 + dev_warn(card->dev, "Failed to set volume limit: %d\n", ret);
9609 + }
9610 +
9611 + return 0;
9612 +}
9613 +
9614 +static int snd_rpi_hifiberry_dacplusadcpro_update_rate_den(
9615 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
9616 +{
9617 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
9618 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component; /* only use DAC */
9619 + struct pcm512x_priv *pcm512x = snd_soc_component_get_drvdata(component);
9620 + struct snd_ratnum *rats_no_pll;
9621 + unsigned int num = 0, den = 0;
9622 + int err;
9623 +
9624 + rats_no_pll = devm_kzalloc(rtd->dev, sizeof(*rats_no_pll), GFP_KERNEL);
9625 + if (!rats_no_pll)
9626 + return -ENOMEM;
9627 +
9628 + rats_no_pll->num = clk_get_rate(pcm512x->sclk) / 64;
9629 + rats_no_pll->den_min = 1;
9630 + rats_no_pll->den_max = 128;
9631 + rats_no_pll->den_step = 1;
9632 +
9633 + err = snd_interval_ratnum(hw_param_interval(params,
9634 + SNDRV_PCM_HW_PARAM_RATE), 1, rats_no_pll, &num, &den);
9635 + if (err >= 0 && den) {
9636 + params->rate_num = num;
9637 + params->rate_den = den;
9638 + }
9639 +
9640 + devm_kfree(rtd->dev, rats_no_pll);
9641 + return 0;
9642 +}
9643 +
9644 +static int snd_rpi_hifiberry_dacplusadcpro_hw_params(
9645 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
9646 +{
9647 + int ret = 0;
9648 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
9649 + int channels = params_channels(params);
9650 + int width = 32;
9651 + struct snd_soc_component *dac = asoc_rtd_to_codec(rtd, 0)->component;
9652 + struct snd_soc_dai *dai = asoc_rtd_to_codec(rtd, 0);
9653 + struct snd_soc_dai_driver *drv = dai->driver;
9654 + const struct snd_soc_dai_ops *ops = drv->ops;
9655 +
9656 + if (snd_rpi_hifiberry_is_dacpro) {
9657 + width = snd_pcm_format_physical_width(params_format(params));
9658 +
9659 + snd_rpi_hifiberry_dacplusadcpro_set_sclk(dac,
9660 + params_rate(params));
9661 +
9662 + ret = snd_rpi_hifiberry_dacplusadcpro_update_rate_den(
9663 + substream, params);
9664 + if (ret)
9665 + return ret;
9666 + }
9667 +
9668 + ret = snd_soc_dai_set_bclk_ratio(asoc_rtd_to_cpu(rtd, 0), channels * width);
9669 + if (ret)
9670 + return ret;
9671 + ret = snd_soc_dai_set_bclk_ratio(asoc_rtd_to_codec(rtd, 0), channels * width);
9672 + if (ret)
9673 + return ret;
9674 + if (snd_rpi_hifiberry_is_dacpro && ops->hw_params)
9675 + ret = ops->hw_params(substream, params, dai);
9676 + return ret;
9677 +}
9678 +
9679 +static int snd_rpi_hifiberry_dacplusadcpro_startup(
9680 + struct snd_pcm_substream *substream)
9681 +{
9682 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
9683 + struct snd_soc_component *dac = asoc_rtd_to_codec(rtd, 0)->component;
9684 + struct snd_soc_component *adc = asoc_rtd_to_codec(rtd, 1)->component;
9685 +
9686 + if (leds_off)
9687 + return 0;
9688 + /* switch on respective LED */
9689 + if (!substream->stream)
9690 + snd_soc_component_update_bits(dac, PCM512x_GPIO_CONTROL_1, 0x08, 0x08);
9691 + else
9692 + snd_soc_component_update_bits(adc, PCM186X_GPIO_IN_OUT, 0x40, 0x40);
9693 + return 0;
9694 +}
9695 +
9696 +static void snd_rpi_hifiberry_dacplusadcpro_shutdown(
9697 + struct snd_pcm_substream *substream)
9698 +{
9699 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
9700 + struct snd_soc_component *dac = asoc_rtd_to_codec(rtd, 0)->component;
9701 + struct snd_soc_component *adc = asoc_rtd_to_codec(rtd, 1)->component;
9702 +
9703 + /* switch off respective LED */
9704 + if (!substream->stream)
9705 + snd_soc_component_update_bits(dac, PCM512x_GPIO_CONTROL_1, 0x08, 0x00);
9706 + else
9707 + snd_soc_component_update_bits(adc, PCM186X_GPIO_IN_OUT, 0x40, 0x00);
9708 +}
9709 +
9710 +
9711 +/* machine stream operations */
9712 +static struct snd_soc_ops snd_rpi_hifiberry_dacplusadcpro_ops = {
9713 + .hw_params = snd_rpi_hifiberry_dacplusadcpro_hw_params,
9714 + .startup = snd_rpi_hifiberry_dacplusadcpro_startup,
9715 + .shutdown = snd_rpi_hifiberry_dacplusadcpro_shutdown,
9716 +};
9717 +
9718 +SND_SOC_DAILINK_DEFS(hifi,
9719 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
9720 + DAILINK_COMP_ARRAY(COMP_CODEC("pcm512x.1-004d", "pcm512x-hifi"),
9721 + COMP_CODEC("pcm186x.1-004a", "pcm1863-aif")),
9722 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
9723 +
9724 +static struct snd_soc_dai_link snd_rpi_hifiberry_dacplusadcpro_dai[] = {
9725 +{
9726 + .name = "HiFiBerry DAC+ADC PRO",
9727 + .stream_name = "HiFiBerry DAC+ADC PRO HiFi",
9728 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
9729 + SND_SOC_DAIFMT_CBS_CFS,
9730 + .ops = &snd_rpi_hifiberry_dacplusadcpro_ops,
9731 + .init = snd_rpi_hifiberry_dacplusadcpro_init,
9732 + SND_SOC_DAILINK_REG(hifi),
9733 +},
9734 +};
9735 +
9736 +/* aux device for optional headphone amp */
9737 +static struct snd_soc_aux_dev hifiberry_dacplusadcpro_aux_devs[] = {
9738 + {
9739 + .dlc = {
9740 + .name = "tpa6130a2.1-0060",
9741 + },
9742 + },
9743 +};
9744 +
9745 +/* audio machine driver */
9746 +static struct snd_soc_card snd_rpi_hifiberry_dacplusadcpro = {
9747 + .name = "snd_rpi_hifiberry_dacplusadcpro",
9748 + .driver_name = "HifiberryDacpAdcPro",
9749 + .owner = THIS_MODULE,
9750 + .dai_link = snd_rpi_hifiberry_dacplusadcpro_dai,
9751 + .num_links = ARRAY_SIZE(snd_rpi_hifiberry_dacplusadcpro_dai),
9752 +};
9753 +
9754 +static int hb_hp_detect(void)
9755 +{
9756 + struct i2c_adapter *adap = i2c_get_adapter(1);
9757 + int ret;
9758 + struct i2c_client tpa_i2c_client = {
9759 + .addr = 0x60,
9760 + .adapter = adap,
9761 + };
9762 +
9763 + if (!adap)
9764 + return -EPROBE_DEFER; /* I2C module not yet available */
9765 +
9766 + ret = i2c_smbus_read_byte(&tpa_i2c_client) >= 0;
9767 + i2c_put_adapter(adap);
9768 + return ret;
9769 +};
9770 +
9771 +static struct property tpa_enable_prop = {
9772 + .name = "status",
9773 + .length = 4 + 1, /* length 'okay' + 1 */
9774 + .value = "okay",
9775 + };
9776 +
9777 +static int snd_rpi_hifiberry_dacplusadcpro_probe(struct platform_device *pdev)
9778 +{
9779 + int ret = 0, i = 0;
9780 + struct snd_soc_card *card = &snd_rpi_hifiberry_dacplusadcpro;
9781 + struct device_node *tpa_node;
9782 + struct property *tpa_prop;
9783 + struct of_changeset ocs;
9784 + int len;
9785 +
9786 + /* probe for head phone amp */
9787 + ret = hb_hp_detect();
9788 + if (ret < 0)
9789 + return ret;
9790 + if (ret) {
9791 + card->aux_dev = hifiberry_dacplusadcpro_aux_devs;
9792 + card->num_aux_devs =
9793 + ARRAY_SIZE(hifiberry_dacplusadcpro_aux_devs);
9794 + tpa_node = of_find_compatible_node(NULL, NULL, "ti,tpa6130a2");
9795 + tpa_prop = of_find_property(tpa_node, "status", &len);
9796 +
9797 + if (strcmp((char *)tpa_prop->value, "okay")) {
9798 + /* and activate headphone using change_sets */
9799 + dev_info(&pdev->dev, "activating headphone amplifier");
9800 + of_changeset_init(&ocs);
9801 + ret = of_changeset_update_property(&ocs, tpa_node,
9802 + &tpa_enable_prop);
9803 + if (ret) {
9804 + dev_err(&pdev->dev,
9805 + "cannot activate headphone amplifier\n");
9806 + return -ENODEV;
9807 + }
9808 + ret = of_changeset_apply(&ocs);
9809 + if (ret) {
9810 + dev_err(&pdev->dev,
9811 + "cannot activate headphone amplifier\n");
9812 + return -ENODEV;
9813 + }
9814 + }
9815 + }
9816 +
9817 + snd_rpi_hifiberry_dacplusadcpro.dev = &pdev->dev;
9818 + if (pdev->dev.of_node) {
9819 + struct device_node *i2s_node;
9820 + struct snd_soc_dai_link *dai;
9821 +
9822 + dai = &snd_rpi_hifiberry_dacplusadcpro_dai[0];
9823 + i2s_node = of_parse_phandle(pdev->dev.of_node,
9824 + "i2s-controller", 0);
9825 + if (i2s_node) {
9826 + for (i = 0; i < card->num_links; i++) {
9827 + dai->cpus->dai_name = NULL;
9828 + dai->cpus->of_node = i2s_node;
9829 + dai->platforms->name = NULL;
9830 + dai->platforms->of_node = i2s_node;
9831 + }
9832 + }
9833 + }
9834 + digital_gain_0db_limit = !of_property_read_bool(
9835 + pdev->dev.of_node, "hifiberry-dacplusadcpro,24db_digital_gain");
9836 + slave = of_property_read_bool(pdev->dev.of_node,
9837 + "hifiberry-dacplusadcpro,slave");
9838 + leds_off = of_property_read_bool(pdev->dev.of_node,
9839 + "hifiberry-dacplusadcpro,leds_off");
9840 + ret = snd_soc_register_card(&snd_rpi_hifiberry_dacplusadcpro);
9841 + if (ret && ret != -EPROBE_DEFER)
9842 + dev_err(&pdev->dev,
9843 + "snd_soc_register_card() failed: %d\n", ret);
9844 +
9845 + return ret;
9846 +}
9847 +
9848 +static const struct of_device_id snd_rpi_hifiberry_dacplusadcpro_of_match[] = {
9849 + { .compatible = "hifiberry,hifiberry-dacplusadcpro", },
9850 + {},
9851 +};
9852 +
9853 +MODULE_DEVICE_TABLE(of, snd_rpi_hifiberry_dacplusadcpro_of_match);
9854 +
9855 +static struct platform_driver snd_rpi_hifiberry_dacplusadcpro_driver = {
9856 + .driver = {
9857 + .name = "snd-rpi-hifiberry-dacplusadcpro",
9858 + .owner = THIS_MODULE,
9859 + .of_match_table = snd_rpi_hifiberry_dacplusadcpro_of_match,
9860 + },
9861 + .probe = snd_rpi_hifiberry_dacplusadcpro_probe,
9862 +};
9863 +
9864 +module_platform_driver(snd_rpi_hifiberry_dacplusadcpro_driver);
9865 +
9866 +MODULE_AUTHOR("Joerg Schambacher <joerg@hifiberry.com>");
9867 +MODULE_AUTHOR("Daniel Matuschek <daniel@hifiberry.com>");
9868 +MODULE_DESCRIPTION("ASoC Driver for HiFiBerry DAC+ADC");
9869 +MODULE_LICENSE("GPL v2");
9870 --- /dev/null
9871 +++ b/sound/soc/bcm/hifiberry_dacplusdsp.c
9872 @@ -0,0 +1,90 @@
9873 +// SPDX-License-Identifier: GPL-2.0
9874 +/*
9875 + * ASoC Driver for HiFiBerry DAC + DSP
9876 + *
9877 + * Author: Joerg Schambacher <joscha@schambacher.com>
9878 + * Copyright 2018
9879 + *
9880 + * This program is free software; you can redistribute it and/or
9881 + * modify it under the terms of the GNU General Public License
9882 + * version 2 as published by the Free Software Foundation.
9883 + *
9884 + * This program is distributed in the hope that it will be useful, but
9885 + * WITHOUT ANY WARRANTY; without even the implied warranty of
9886 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9887 + * General Public License for more details.
9888 + */
9889 +
9890 +#include <linux/init.h>
9891 +#include <linux/module.h>
9892 +#include <linux/of.h>
9893 +#include <linux/platform_device.h>
9894 +#include <sound/soc.h>
9895 +
9896 +static struct snd_soc_component_driver dacplusdsp_component_driver;
9897 +
9898 +static struct snd_soc_dai_driver dacplusdsp_dai = {
9899 + .name = "dacplusdsp-hifi",
9900 + .capture = {
9901 + .stream_name = "DAC+DSP Capture",
9902 + .channels_min = 2,
9903 + .channels_max = 2,
9904 + .rates = SNDRV_PCM_RATE_CONTINUOUS,
9905 + .formats = SNDRV_PCM_FMTBIT_S16_LE |
9906 + SNDRV_PCM_FMTBIT_S24_LE |
9907 + SNDRV_PCM_FMTBIT_S32_LE,
9908 + },
9909 + .playback = {
9910 + .stream_name = "DACP+DSP Playback",
9911 + .channels_min = 2,
9912 + .channels_max = 2,
9913 + .rates = SNDRV_PCM_RATE_CONTINUOUS,
9914 + .formats = SNDRV_PCM_FMTBIT_S16_LE |
9915 + SNDRV_PCM_FMTBIT_S24_LE |
9916 + SNDRV_PCM_FMTBIT_S32_LE,
9917 + },
9918 + .symmetric_rate = 1};
9919 +
9920 +#ifdef CONFIG_OF
9921 +static const struct of_device_id dacplusdsp_ids[] = {
9922 + {
9923 + .compatible = "hifiberry,dacplusdsp",
9924 + },
9925 + {} };
9926 +MODULE_DEVICE_TABLE(of, dacplusdsp_ids);
9927 +#endif
9928 +
9929 +static int dacplusdsp_platform_probe(struct platform_device *pdev)
9930 +{
9931 + int ret;
9932 +
9933 + ret = snd_soc_register_component(&pdev->dev,
9934 + &dacplusdsp_component_driver, &dacplusdsp_dai, 1);
9935 + if (ret) {
9936 + pr_alert("snd_soc_register_component failed\n");
9937 + return ret;
9938 + }
9939 +
9940 + return 0;
9941 +}
9942 +
9943 +static int dacplusdsp_platform_remove(struct platform_device *pdev)
9944 +{
9945 + snd_soc_unregister_component(&pdev->dev);
9946 + return 0;
9947 +}
9948 +
9949 +static struct platform_driver dacplusdsp_driver = {
9950 + .driver = {
9951 + .name = "hifiberry-dacplusdsp-codec",
9952 + .of_match_table = of_match_ptr(dacplusdsp_ids),
9953 + },
9954 + .probe = dacplusdsp_platform_probe,
9955 + .remove = dacplusdsp_platform_remove,
9956 +};
9957 +
9958 +module_platform_driver(dacplusdsp_driver);
9959 +
9960 +MODULE_AUTHOR("Joerg Schambacher <joerg@i2audio.com>");
9961 +MODULE_DESCRIPTION("ASoC Driver for HiFiBerry DAC+DSP");
9962 +MODULE_LICENSE("GPL v2");
9963 --- /dev/null
9964 +++ b/sound/soc/bcm/hifiberry_dacplushd.c
9965 @@ -0,0 +1,238 @@
9966 +// SPDX-License-Identifier: GPL-2.0
9967 +/*
9968 + * ASoC Driver for HiFiBerry DAC+ HD
9969 + *
9970 + * Author: Joerg Schambacher, i2Audio GmbH for HiFiBerry
9971 + * Copyright 2020
9972 + *
9973 + * This program is free software; you can redistribute it and/or
9974 + * modify it under the terms of the GNU General Public License
9975 + * version 2 as published by the Free Software Foundation.
9976 + *
9977 + * This program is distributed in the hope that it will be useful, but
9978 + * WITHOUT ANY WARRANTY; without even the implied warranty of
9979 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9980 + * General Public License for more details.
9981 + */
9982 +
9983 +#include <linux/module.h>
9984 +#include <linux/platform_device.h>
9985 +#include <linux/kernel.h>
9986 +#include <linux/delay.h>
9987 +#include <linux/module.h>
9988 +#include <linux/of.h>
9989 +#include <linux/delay.h>
9990 +#include <linux/gpio.h>
9991 +#include <linux/gpio/consumer.h>
9992 +#include <sound/core.h>
9993 +#include <sound/pcm.h>
9994 +#include <sound/pcm_params.h>
9995 +#include <sound/soc.h>
9996 +#include <linux/i2c.h>
9997 +#include <linux/clk.h>
9998 +
9999 +#include "../codecs/pcm179x.h"
10000 +
10001 +#define DEFAULT_RATE 44100
10002 +
10003 +struct brd_drv_data {
10004 + struct regmap *regmap;
10005 + struct clk *sclk;
10006 +};
10007 +
10008 +static struct brd_drv_data drvdata;
10009 +static struct gpio_desc *reset_gpio;
10010 +static const unsigned int hb_dacplushd_rates[] = {
10011 + 192000, 96000, 48000, 176400, 88200, 44100,
10012 +};
10013 +
10014 +static struct snd_pcm_hw_constraint_list hb_dacplushd_constraints = {
10015 + .list = hb_dacplushd_rates,
10016 + .count = ARRAY_SIZE(hb_dacplushd_rates),
10017 +};
10018 +
10019 +static int snd_rpi_hb_dacplushd_startup(struct snd_pcm_substream *substream)
10020 +{
10021 + /* constraints for standard sample rates */
10022 + snd_pcm_hw_constraint_list(substream->runtime, 0,
10023 + SNDRV_PCM_HW_PARAM_RATE,
10024 + &hb_dacplushd_constraints);
10025 + return 0;
10026 +}
10027 +
10028 +static void snd_rpi_hifiberry_dacplushd_set_sclk(
10029 + struct snd_soc_component *component,
10030 + int sample_rate)
10031 +{
10032 + if (!IS_ERR(drvdata.sclk))
10033 + clk_set_rate(drvdata.sclk, sample_rate);
10034 +}
10035 +
10036 +static int snd_rpi_hifiberry_dacplushd_init(struct snd_soc_pcm_runtime *rtd)
10037 +{
10038 + struct snd_soc_dai_link *dai = rtd->dai_link;
10039 + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
10040 +
10041 + dai->name = "HiFiBerry DAC+ HD";
10042 + dai->stream_name = "HiFiBerry DAC+ HD HiFi";
10043 + dai->dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
10044 + | SND_SOC_DAIFMT_CBM_CFM;
10045 +
10046 + /* allow only fixed 32 clock counts per channel */
10047 + snd_soc_dai_set_bclk_ratio(cpu_dai, 32*2);
10048 +
10049 + return 0;
10050 +}
10051 +
10052 +static int snd_rpi_hifiberry_dacplushd_hw_params(
10053 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
10054 +{
10055 + int ret = 0;
10056 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
10057 +
10058 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
10059 +
10060 + snd_rpi_hifiberry_dacplushd_set_sclk(component, params_rate(params));
10061 + return ret;
10062 +}
10063 +
10064 +/* machine stream operations */
10065 +static struct snd_soc_ops snd_rpi_hifiberry_dacplushd_ops = {
10066 + .startup = snd_rpi_hb_dacplushd_startup,
10067 + .hw_params = snd_rpi_hifiberry_dacplushd_hw_params,
10068 +};
10069 +
10070 +SND_SOC_DAILINK_DEFS(hifi,
10071 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
10072 + DAILINK_COMP_ARRAY(COMP_CODEC("pcm179x.1-004c", "pcm179x-hifi")),
10073 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
10074 +
10075 +
10076 +static struct snd_soc_dai_link snd_rpi_hifiberry_dacplushd_dai[] = {
10077 +{
10078 + .name = "HiFiBerry DAC+ HD",
10079 + .stream_name = "HiFiBerry DAC+ HD HiFi",
10080 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
10081 + SND_SOC_DAIFMT_CBS_CFS,
10082 + .ops = &snd_rpi_hifiberry_dacplushd_ops,
10083 + .init = snd_rpi_hifiberry_dacplushd_init,
10084 + SND_SOC_DAILINK_REG(hifi),
10085 +},
10086 +};
10087 +
10088 +/* audio machine driver */
10089 +static struct snd_soc_card snd_rpi_hifiberry_dacplushd = {
10090 + .name = "snd_rpi_hifiberry_dacplushd",
10091 + .driver_name = "HifiberryDacplusHD",
10092 + .owner = THIS_MODULE,
10093 + .dai_link = snd_rpi_hifiberry_dacplushd_dai,
10094 + .num_links = ARRAY_SIZE(snd_rpi_hifiberry_dacplushd_dai),
10095 +};
10096 +
10097 +static int snd_rpi_hifiberry_dacplushd_probe(struct platform_device *pdev)
10098 +{
10099 + int ret = 0;
10100 + static int dac_reset_done;
10101 + struct device *dev = &pdev->dev;
10102 + struct device_node *dev_node = dev->of_node;
10103 +
10104 + snd_rpi_hifiberry_dacplushd.dev = &pdev->dev;
10105 +
10106 + /* get GPIO and release DAC from RESET */
10107 + if (!dac_reset_done) {
10108 + reset_gpio = gpiod_get(&pdev->dev, "reset", GPIOD_OUT_LOW);
10109 + if (IS_ERR(reset_gpio)) {
10110 + dev_err(&pdev->dev, "gpiod_get() failed\n");
10111 + return -EINVAL;
10112 + }
10113 + dac_reset_done = 1;
10114 + }
10115 + if (!IS_ERR(reset_gpio))
10116 + gpiod_set_value(reset_gpio, 0);
10117 + msleep(1);
10118 + if (!IS_ERR(reset_gpio))
10119 + gpiod_set_value(reset_gpio, 1);
10120 + msleep(1);
10121 + if (!IS_ERR(reset_gpio))
10122 + gpiod_set_value(reset_gpio, 0);
10123 +
10124 + if (pdev->dev.of_node) {
10125 + struct device_node *i2s_node;
10126 + struct snd_soc_dai_link *dai;
10127 +
10128 + dai = &snd_rpi_hifiberry_dacplushd_dai[0];
10129 + i2s_node = of_parse_phandle(pdev->dev.of_node,
10130 + "i2s-controller", 0);
10131 +
10132 + if (i2s_node) {
10133 + dai->cpus->of_node = i2s_node;
10134 + dai->platforms->of_node = i2s_node;
10135 + dai->cpus->dai_name = NULL;
10136 + dai->platforms->name = NULL;
10137 + } else {
10138 + return -EPROBE_DEFER;
10139 + }
10140 +
10141 + }
10142 +
10143 + ret = devm_snd_soc_register_card(&pdev->dev,
10144 + &snd_rpi_hifiberry_dacplushd);
10145 + if (ret && ret != -EPROBE_DEFER) {
10146 + dev_err(&pdev->dev,
10147 + "snd_soc_register_card() failed: %d\n", ret);
10148 + return ret;
10149 + }
10150 + if (ret == -EPROBE_DEFER)
10151 + return ret;
10152 +
10153 + dev_set_drvdata(dev, &drvdata);
10154 + if (dev_node == NULL) {
10155 + dev_err(&pdev->dev, "Device tree node not found\n");
10156 + return -ENODEV;
10157 + }
10158 +
10159 + drvdata.sclk = devm_clk_get(dev, NULL);
10160 + if (IS_ERR(drvdata.sclk)) {
10161 + drvdata.sclk = ERR_PTR(-ENOENT);
10162 + return -ENODEV;
10163 + }
10164 +
10165 + clk_set_rate(drvdata.sclk, DEFAULT_RATE);
10166 +
10167 + return ret;
10168 +}
10169 +
10170 +static int snd_rpi_hifiberry_dacplushd_remove(struct platform_device *pdev)
10171 +{
10172 + if (IS_ERR(reset_gpio))
10173 + return -EINVAL;
10174 +
10175 + /* put DAC into RESET and release GPIO */
10176 + gpiod_set_value(reset_gpio, 0);
10177 + gpiod_put(reset_gpio);
10178 +
10179 + return 0;
10180 +}
10181 +
10182 +static const struct of_device_id snd_rpi_hifiberry_dacplushd_of_match[] = {
10183 + { .compatible = "hifiberry,hifiberry-dacplushd", },
10184 + {},
10185 +};
10186 +
10187 +MODULE_DEVICE_TABLE(of, snd_rpi_hifiberry_dacplushd_of_match);
10188 +
10189 +static struct platform_driver snd_rpi_hifiberry_dacplushd_driver = {
10190 + .driver = {
10191 + .name = "snd-rpi-hifiberry-dacplushd",
10192 + .owner = THIS_MODULE,
10193 + .of_match_table = snd_rpi_hifiberry_dacplushd_of_match,
10194 + },
10195 + .probe = snd_rpi_hifiberry_dacplushd_probe,
10196 + .remove = snd_rpi_hifiberry_dacplushd_remove,
10197 +};
10198 +
10199 +module_platform_driver(snd_rpi_hifiberry_dacplushd_driver);
10200 +
10201 +MODULE_AUTHOR("Joerg Schambacher <joerg@i2audio.com>");
10202 +MODULE_DESCRIPTION("ASoC Driver for HiFiBerry DAC+ HD");
10203 +MODULE_LICENSE("GPL v2");
10204 --- /dev/null
10205 +++ b/sound/soc/bcm/i-sabre-q2m.c
10206 @@ -0,0 +1,159 @@
10207 +/*
10208 + * ASoC Driver for I-Sabre Q2M
10209 + *
10210 + * Author: Satoru Kawase
10211 + * Modified by: Xiao Qingyong
10212 + * Update kernel v4.18+ by : Audiophonics
10213 + * Copyright 2018 Audiophonics
10214 + *
10215 + * This program is free software; you can redistribute it and/or
10216 + * modify it under the terms of the GNU General Public License
10217 + * version 2 as published by the Free Software Foundation.
10218 + *
10219 + * This program is distributed in the hope that it will be useful, but
10220 + * WITHOUT ANY WARRANTY; without even the implied warranty of
10221 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10222 + * General Public License for more details.
10223 + */
10224 +
10225 +#include <linux/kernel.h>
10226 +#include <linux/init.h>
10227 +#include <linux/module.h>
10228 +#include <linux/delay.h>
10229 +#include <linux/fs.h>
10230 +#include <asm/uaccess.h>
10231 +#include <sound/core.h>
10232 +#include <sound/soc.h>
10233 +#include <sound/pcm.h>
10234 +#include <sound/pcm_params.h>
10235 +
10236 +#include "../codecs/i-sabre-codec.h"
10237 +
10238 +
10239 +static int snd_rpi_i_sabre_q2m_init(struct snd_soc_pcm_runtime *rtd)
10240 +{
10241 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
10242 + unsigned int value;
10243 +
10244 + /* Device ID */
10245 + value = snd_soc_component_read(component, ISABRECODEC_REG_01);
10246 + dev_info(component->card->dev, "Audiophonics Device ID : %02X\n", value);
10247 +
10248 + /* API revision */
10249 + value = snd_soc_component_read(component, ISABRECODEC_REG_02);
10250 + dev_info(component->card->dev, "Audiophonics API revision : %02X\n", value);
10251 +
10252 + return 0;
10253 +}
10254 +
10255 +static int snd_rpi_i_sabre_q2m_hw_params(
10256 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
10257 +{
10258 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
10259 + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
10260 + int bclk_ratio;
10261 +
10262 + bclk_ratio = snd_pcm_format_physical_width(
10263 + params_format(params)) * params_channels(params);
10264 + return snd_soc_dai_set_bclk_ratio(cpu_dai, bclk_ratio);
10265 +}
10266 +
10267 +/* machine stream operations */
10268 +static struct snd_soc_ops snd_rpi_i_sabre_q2m_ops = {
10269 + .hw_params = snd_rpi_i_sabre_q2m_hw_params,
10270 +};
10271 +
10272 +SND_SOC_DAILINK_DEFS(rpi_i_sabre_q2m,
10273 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
10274 + DAILINK_COMP_ARRAY(COMP_CODEC("i-sabre-codec-i2c.1-0048", "i-sabre-codec-dai")),
10275 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
10276 +
10277 +static struct snd_soc_dai_link snd_rpi_i_sabre_q2m_dai[] = {
10278 + {
10279 + .name = "I-Sabre Q2M",
10280 + .stream_name = "I-Sabre Q2M DAC",
10281 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
10282 + | SND_SOC_DAIFMT_CBS_CFS,
10283 + .init = snd_rpi_i_sabre_q2m_init,
10284 + .ops = &snd_rpi_i_sabre_q2m_ops,
10285 + SND_SOC_DAILINK_REG(rpi_i_sabre_q2m),
10286 + }
10287 +};
10288 +
10289 +/* audio machine driver */
10290 +static struct snd_soc_card snd_rpi_i_sabre_q2m = {
10291 + .name = "I-Sabre Q2M DAC",
10292 + .owner = THIS_MODULE,
10293 + .dai_link = snd_rpi_i_sabre_q2m_dai,
10294 + .num_links = ARRAY_SIZE(snd_rpi_i_sabre_q2m_dai)
10295 +};
10296 +
10297 +
10298 +static int snd_rpi_i_sabre_q2m_probe(struct platform_device *pdev)
10299 +{
10300 + int ret = 0;
10301 +
10302 + snd_rpi_i_sabre_q2m.dev = &pdev->dev;
10303 + if (pdev->dev.of_node) {
10304 + struct device_node *i2s_node;
10305 + struct snd_soc_dai_link *dai;
10306 +
10307 + dai = &snd_rpi_i_sabre_q2m_dai[0];
10308 + i2s_node = of_parse_phandle(pdev->dev.of_node,
10309 + "i2s-controller", 0);
10310 + if (i2s_node) {
10311 + dai->cpus->dai_name = NULL;
10312 + dai->cpus->of_node = i2s_node;
10313 + dai->platforms->name = NULL;
10314 + dai->platforms->of_node = i2s_node;
10315 + } else {
10316 + dev_err(&pdev->dev,
10317 + "Property 'i2s-controller' missing or invalid\n");
10318 + return (-EINVAL);
10319 + }
10320 +
10321 + dai->name = "I-Sabre Q2M";
10322 + dai->stream_name = "I-Sabre Q2M DAC";
10323 + dai->dai_fmt = SND_SOC_DAIFMT_I2S
10324 + | SND_SOC_DAIFMT_NB_NF
10325 + | SND_SOC_DAIFMT_CBS_CFS;
10326 + }
10327 +
10328 + /* Wait for registering codec driver */
10329 + mdelay(50);
10330 +
10331 + ret = snd_soc_register_card(&snd_rpi_i_sabre_q2m);
10332 + if (ret) {
10333 + dev_err(&pdev->dev,
10334 + "snd_soc_register_card() failed: %d\n", ret);
10335 + }
10336 +
10337 + return ret;
10338 +}
10339 +
10340 +static int snd_rpi_i_sabre_q2m_remove(struct platform_device *pdev)
10341 +{
10342 + snd_soc_unregister_card(&snd_rpi_i_sabre_q2m);
10343 + return 0;
10344 +}
10345 +
10346 +static const struct of_device_id snd_rpi_i_sabre_q2m_of_match[] = {
10347 + { .compatible = "audiophonics,i-sabre-q2m", },
10348 + {}
10349 +};
10350 +MODULE_DEVICE_TABLE(of, snd_rpi_i_sabre_q2m_of_match);
10351 +
10352 +static struct platform_driver snd_rpi_i_sabre_q2m_driver = {
10353 + .driver = {
10354 + .name = "snd-rpi-i-sabre-q2m",
10355 + .owner = THIS_MODULE,
10356 + .of_match_table = snd_rpi_i_sabre_q2m_of_match,
10357 + },
10358 + .probe = snd_rpi_i_sabre_q2m_probe,
10359 + .remove = snd_rpi_i_sabre_q2m_remove,
10360 +};
10361 +module_platform_driver(snd_rpi_i_sabre_q2m_driver);
10362 +
10363 +MODULE_DESCRIPTION("ASoC Driver for I-Sabre Q2M");
10364 +MODULE_AUTHOR("Audiophonics <http://www.audiophonics.fr>");
10365 +MODULE_LICENSE("GPL");
10366 --- /dev/null
10367 +++ b/sound/soc/bcm/iqaudio-codec.c
10368 @@ -0,0 +1,275 @@
10369 +/*
10370 + * ASoC Driver for IQaudIO Raspberry Pi Codec board
10371 + *
10372 + * Author: Gordon Garrity <gordon@iqaudio.com>
10373 + * (C) Copyright IQaudio Limited, 2017-2019
10374 + *
10375 + * This program is free software; you can redistribute it and/or
10376 + * modify it under the terms of the GNU General Public License
10377 + * version 2 as published by the Free Software Foundation.
10378 + *
10379 + * This program is distributed in the hope that it will be useful, but
10380 + * WITHOUT ANY WARRANTY; without even the implied warranty of
10381 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10382 + * General Public License for more details.
10383 + */
10384 +
10385 +#include <linux/module.h>
10386 +#include <linux/gpio/consumer.h>
10387 +#include <linux/platform_device.h>
10388 +
10389 +#include <sound/core.h>
10390 +#include <sound/pcm.h>
10391 +#include <sound/pcm_params.h>
10392 +#include <sound/soc.h>
10393 +#include <sound/jack.h>
10394 +
10395 +#include <linux/acpi.h>
10396 +#include <linux/slab.h>
10397 +#include "../codecs/da7213.h"
10398 +
10399 +static int pll_out = DA7213_PLL_FREQ_OUT_90316800;
10400 +
10401 +static int snd_rpi_iqaudio_pll_control(struct snd_soc_dapm_widget *w,
10402 + struct snd_kcontrol *k, int event)
10403 +{
10404 + int ret = 0;
10405 + struct snd_soc_dapm_context *dapm = w->dapm;
10406 + struct snd_soc_card *card = dapm->card;
10407 + struct snd_soc_pcm_runtime *rtd =
10408 + snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
10409 + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
10410 +
10411 + if (SND_SOC_DAPM_EVENT_OFF(event)) {
10412 + ret = snd_soc_dai_set_pll(codec_dai, 0, DA7213_SYSCLK_MCLK, 0,
10413 + 0);
10414 + if (ret)
10415 + dev_err(card->dev, "Failed to bypass PLL: %d\n", ret);
10416 + /* Allow PLL time to bypass */
10417 + msleep(100);
10418 + } else if (SND_SOC_DAPM_EVENT_ON(event)) {
10419 + ret = snd_soc_dai_set_pll(codec_dai, 0, DA7213_SYSCLK_PLL, 0,
10420 + pll_out);
10421 + if (ret)
10422 + dev_err(card->dev, "Failed to enable PLL: %d\n", ret);
10423 + /* Allow PLL time to lock */
10424 + msleep(100);
10425 + }
10426 +
10427 + return ret;
10428 +}
10429 +
10430 +static int snd_rpi_iqaudio_post_dapm_event(struct snd_soc_dapm_widget *w,
10431 + struct snd_kcontrol *kcontrol,
10432 + int event)
10433 +{
10434 + switch (event) {
10435 + case SND_SOC_DAPM_POST_PMU:
10436 + /* Delay for mic bias ramp */
10437 + msleep(1000);
10438 + break;
10439 + default:
10440 + break;
10441 + }
10442 +
10443 + return 0;
10444 +}
10445 +
10446 +static const struct snd_kcontrol_new dapm_controls[] = {
10447 + SOC_DAPM_PIN_SWITCH("HP Jack"),
10448 + SOC_DAPM_PIN_SWITCH("MIC Jack"),
10449 + SOC_DAPM_PIN_SWITCH("Onboard MIC"),
10450 + SOC_DAPM_PIN_SWITCH("AUX Jack"),
10451 +};
10452 +
10453 +static const struct snd_soc_dapm_widget dapm_widgets[] = {
10454 + SND_SOC_DAPM_HP("HP Jack", NULL),
10455 + SND_SOC_DAPM_MIC("MIC Jack", NULL),
10456 + SND_SOC_DAPM_MIC("Onboard MIC", NULL),
10457 + SND_SOC_DAPM_LINE("AUX Jack", NULL),
10458 + SND_SOC_DAPM_SUPPLY("PLL Control", SND_SOC_NOPM, 0, 0,
10459 + snd_rpi_iqaudio_pll_control,
10460 + SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
10461 + SND_SOC_DAPM_POST("Post Power Up Event", snd_rpi_iqaudio_post_dapm_event),
10462 +};
10463 +
10464 +static const struct snd_soc_dapm_route audio_map[] = {
10465 + {"HP Jack", NULL, "HPL"},
10466 + {"HP Jack", NULL, "HPR"},
10467 + {"HP Jack", NULL, "PLL Control"},
10468 +
10469 + {"AUXR", NULL, "AUX Jack"},
10470 + {"AUXL", NULL, "AUX Jack"},
10471 + {"AUX Jack", NULL, "PLL Control"},
10472 +
10473 + /* Assume Mic1 is linked to Headset and Mic2 to on-board mic */
10474 + {"MIC1", NULL, "MIC Jack"},
10475 + {"MIC Jack", NULL, "PLL Control"},
10476 + {"MIC2", NULL, "Onboard MIC"},
10477 + {"Onboard MIC", NULL, "PLL Control"},
10478 +};
10479 +
10480 +/* machine stream operations */
10481 +
10482 +static int snd_rpi_iqaudio_codec_init(struct snd_soc_pcm_runtime *rtd)
10483 +{
10484 + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
10485 + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
10486 + int ret;
10487 +
10488 + /*
10489 + * Disable AUX Jack Pin by default to prevent PLL being enabled at
10490 + * startup. This avoids holding the PLL to a fixed SR config for
10491 + * subsequent streams.
10492 + *
10493 + * This pin can still be enabled later, as required by user-space.
10494 + */
10495 + snd_soc_dapm_disable_pin(&rtd->card->dapm, "AUX Jack");
10496 + snd_soc_dapm_sync(&rtd->card->dapm);
10497 +
10498 + /* Set bclk ratio to align with codec's BCLK rate */
10499 + ret = snd_soc_dai_set_bclk_ratio(cpu_dai, 64);
10500 + if (ret) {
10501 + dev_err(rtd->dev, "Failed to set CPU BLCK ratio\n");
10502 + return ret;
10503 + }
10504 +
10505 + /* Set MCLK frequency to codec, onboard 11.2896MHz clock */
10506 + return snd_soc_dai_set_sysclk(codec_dai, DA7213_CLKSRC_MCLK, 11289600,
10507 + SND_SOC_CLOCK_OUT);
10508 +}
10509 +
10510 +static int snd_rpi_iqaudio_codec_hw_params(struct snd_pcm_substream *substream,
10511 + struct snd_pcm_hw_params *params)
10512 +{
10513 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
10514 + unsigned int samplerate = params_rate(params);
10515 +
10516 + switch (samplerate) {
10517 + case 8000:
10518 + case 16000:
10519 + case 32000:
10520 + case 48000:
10521 + case 96000:
10522 + pll_out = DA7213_PLL_FREQ_OUT_98304000;
10523 + return 0;
10524 + case 44100:
10525 + case 88200:
10526 + pll_out = DA7213_PLL_FREQ_OUT_90316800;
10527 + return 0;
10528 + default:
10529 + dev_err(rtd->dev,"Unsupported samplerate %d\n", samplerate);
10530 + return -EINVAL;
10531 + }
10532 +}
10533 +
10534 +static const struct snd_soc_ops snd_rpi_iqaudio_codec_ops = {
10535 + .hw_params = snd_rpi_iqaudio_codec_hw_params,
10536 +};
10537 +
10538 +SND_SOC_DAILINK_DEFS(rpi_iqaudio,
10539 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
10540 + DAILINK_COMP_ARRAY(COMP_CODEC("da7213.1-001a", "da7213-hifi")),
10541 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2835-i2s.0")));
10542 +
10543 +static struct snd_soc_dai_link snd_rpi_iqaudio_codec_dai[] = {
10544 +{
10545 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
10546 + SND_SOC_DAIFMT_CBM_CFM,
10547 + .init = snd_rpi_iqaudio_codec_init,
10548 + .ops = &snd_rpi_iqaudio_codec_ops,
10549 + .symmetric_rate = 1,
10550 + .symmetric_channels = 1,
10551 + .symmetric_sample_bits = 1,
10552 + SND_SOC_DAILINK_REG(rpi_iqaudio),
10553 +},
10554 +};
10555 +
10556 +/* audio machine driver */
10557 +static struct snd_soc_card snd_rpi_iqaudio_codec = {
10558 + .owner = THIS_MODULE,
10559 + .dai_link = snd_rpi_iqaudio_codec_dai,
10560 + .num_links = ARRAY_SIZE(snd_rpi_iqaudio_codec_dai),
10561 + .controls = dapm_controls,
10562 + .num_controls = ARRAY_SIZE(dapm_controls),
10563 + .dapm_widgets = dapm_widgets,
10564 + .num_dapm_widgets = ARRAY_SIZE(dapm_widgets),
10565 + .dapm_routes = audio_map,
10566 + .num_dapm_routes = ARRAY_SIZE(audio_map),
10567 +};
10568 +
10569 +static int snd_rpi_iqaudio_codec_probe(struct platform_device *pdev)
10570 +{
10571 + int ret = 0;
10572 +
10573 + snd_rpi_iqaudio_codec.dev = &pdev->dev;
10574 +
10575 + if (pdev->dev.of_node) {
10576 + struct device_node *i2s_node;
10577 + struct snd_soc_card *card = &snd_rpi_iqaudio_codec;
10578 + struct snd_soc_dai_link *dai = &snd_rpi_iqaudio_codec_dai[0];
10579 +
10580 + i2s_node = of_parse_phandle(pdev->dev.of_node,
10581 + "i2s-controller", 0);
10582 + if (i2s_node) {
10583 + dai->cpus->dai_name = NULL;
10584 + dai->cpus->of_node = i2s_node;
10585 + dai->platforms->name = NULL;
10586 + dai->platforms->of_node = i2s_node;
10587 + }
10588 +
10589 + if (of_property_read_string(pdev->dev.of_node, "card_name",
10590 + &card->name))
10591 + card->name = "IQaudIOCODEC";
10592 +
10593 + if (of_property_read_string(pdev->dev.of_node, "dai_name",
10594 + &dai->name))
10595 + dai->name = "IQaudIO CODEC";
10596 +
10597 + if (of_property_read_string(pdev->dev.of_node,
10598 + "dai_stream_name", &dai->stream_name))
10599 + dai->stream_name = "IQaudIO CODEC HiFi v1.2";
10600 +
10601 + }
10602 +
10603 + ret = snd_soc_register_card(&snd_rpi_iqaudio_codec);
10604 + if (ret) {
10605 + if (ret != -EPROBE_DEFER)
10606 + dev_err(&pdev->dev,
10607 + "snd_soc_register_card() failed: %d\n", ret);
10608 + return ret;
10609 + }
10610 +
10611 + return 0;
10612 +}
10613 +
10614 +static int snd_rpi_iqaudio_codec_remove(struct platform_device *pdev)
10615 +{
10616 + snd_soc_unregister_card(&snd_rpi_iqaudio_codec);
10617 + return 0;
10618 +}
10619 +
10620 +static const struct of_device_id iqaudio_of_match[] = {
10621 + { .compatible = "iqaudio,iqaudio-codec", },
10622 + {},
10623 +};
10624 +
10625 +MODULE_DEVICE_TABLE(of, iqaudio_of_match);
10626 +
10627 +static struct platform_driver snd_rpi_iqaudio_codec_driver = {
10628 + .driver = {
10629 + .name = "snd-rpi-iqaudio-codec",
10630 + .owner = THIS_MODULE,
10631 + .of_match_table = iqaudio_of_match,
10632 + },
10633 + .probe = snd_rpi_iqaudio_codec_probe,
10634 + .remove = snd_rpi_iqaudio_codec_remove,
10635 +};
10636 +
10637 +
10638 +
10639 +module_platform_driver(snd_rpi_iqaudio_codec_driver);
10640 +
10641 +MODULE_AUTHOR("Gordon Garrity <gordon@iqaudio.com>");
10642 +MODULE_DESCRIPTION("ASoC Driver for IQaudIO CODEC");
10643 +MODULE_LICENSE("GPL v2");
10644 --- /dev/null
10645 +++ b/sound/soc/bcm/iqaudio-dac.c
10646 @@ -0,0 +1,224 @@
10647 +/*
10648 + * ASoC Driver for IQaudIO DAC
10649 + *
10650 + * Author: Florian Meier <florian.meier@koalo.de>
10651 + * Copyright 2013
10652 + *
10653 + * This program is free software; you can redistribute it and/or
10654 + * modify it under the terms of the GNU General Public License
10655 + * version 2 as published by the Free Software Foundation.
10656 + *
10657 + * This program is distributed in the hope that it will be useful, but
10658 + * WITHOUT ANY WARRANTY; without even the implied warranty of
10659 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10660 + * General Public License for more details.
10661 + */
10662 +
10663 +#include <linux/module.h>
10664 +#include <linux/gpio/consumer.h>
10665 +#include <linux/platform_device.h>
10666 +
10667 +#include <sound/core.h>
10668 +#include <sound/pcm.h>
10669 +#include <sound/pcm_params.h>
10670 +#include <sound/soc.h>
10671 +#include <sound/jack.h>
10672 +
10673 +static bool digital_gain_0db_limit = true;
10674 +
10675 +static struct gpio_desc *mute_gpio;
10676 +
10677 +static int snd_rpi_iqaudio_dac_init(struct snd_soc_pcm_runtime *rtd)
10678 +{
10679 + if (digital_gain_0db_limit)
10680 + {
10681 + int ret;
10682 + struct snd_soc_card *card = rtd->card;
10683 +
10684 + ret = snd_soc_limit_volume(card, "Digital Playback Volume", 207);
10685 + if (ret < 0)
10686 + dev_warn(card->dev, "Failed to set volume limit: %d\n", ret);
10687 + }
10688 +
10689 + return 0;
10690 +}
10691 +
10692 +static void snd_rpi_iqaudio_gpio_mute(struct snd_soc_card *card)
10693 +{
10694 + if (mute_gpio) {
10695 + dev_info(card->dev, "%s: muting amp using GPIO22\n",
10696 + __func__);
10697 + gpiod_set_value_cansleep(mute_gpio, 0);
10698 + }
10699 +}
10700 +
10701 +static void snd_rpi_iqaudio_gpio_unmute(struct snd_soc_card *card)
10702 +{
10703 + if (mute_gpio) {
10704 + dev_info(card->dev, "%s: un-muting amp using GPIO22\n",
10705 + __func__);
10706 + gpiod_set_value_cansleep(mute_gpio, 1);
10707 + }
10708 +}
10709 +
10710 +static int snd_rpi_iqaudio_set_bias_level(struct snd_soc_card *card,
10711 + struct snd_soc_dapm_context *dapm, enum snd_soc_bias_level level)
10712 +{
10713 + struct snd_soc_pcm_runtime *rtd;
10714 + struct snd_soc_dai *codec_dai;
10715 +
10716 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
10717 + codec_dai = asoc_rtd_to_codec(rtd, 0);
10718 +
10719 + if (dapm->dev != codec_dai->dev)
10720 + return 0;
10721 +
10722 + switch (level) {
10723 + case SND_SOC_BIAS_PREPARE:
10724 + if (dapm->bias_level != SND_SOC_BIAS_STANDBY)
10725 + break;
10726 +
10727 + /* UNMUTE AMP */
10728 + snd_rpi_iqaudio_gpio_unmute(card);
10729 +
10730 + break;
10731 + case SND_SOC_BIAS_STANDBY:
10732 + if (dapm->bias_level != SND_SOC_BIAS_PREPARE)
10733 + break;
10734 +
10735 + /* MUTE AMP */
10736 + snd_rpi_iqaudio_gpio_mute(card);
10737 +
10738 + break;
10739 + default:
10740 + break;
10741 + }
10742 +
10743 + return 0;
10744 +}
10745 +
10746 +SND_SOC_DAILINK_DEFS(hifi,
10747 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
10748 + DAILINK_COMP_ARRAY(COMP_CODEC("pcm512x.1-004c", "pcm512x-hifi")),
10749 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
10750 +
10751 +static struct snd_soc_dai_link snd_rpi_iqaudio_dac_dai[] = {
10752 +{
10753 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
10754 + SND_SOC_DAIFMT_CBS_CFS,
10755 + .init = snd_rpi_iqaudio_dac_init,
10756 + SND_SOC_DAILINK_REG(hifi),
10757 +},
10758 +};
10759 +
10760 +/* audio machine driver */
10761 +static struct snd_soc_card snd_rpi_iqaudio_dac = {
10762 + .owner = THIS_MODULE,
10763 + .dai_link = snd_rpi_iqaudio_dac_dai,
10764 + .num_links = ARRAY_SIZE(snd_rpi_iqaudio_dac_dai),
10765 +};
10766 +
10767 +static int snd_rpi_iqaudio_dac_probe(struct platform_device *pdev)
10768 +{
10769 + int ret = 0;
10770 + bool gpio_unmute = false;
10771 +
10772 + snd_rpi_iqaudio_dac.dev = &pdev->dev;
10773 +
10774 + if (pdev->dev.of_node) {
10775 + struct device_node *i2s_node;
10776 + struct snd_soc_card *card = &snd_rpi_iqaudio_dac;
10777 + struct snd_soc_dai_link *dai = &snd_rpi_iqaudio_dac_dai[0];
10778 + bool auto_gpio_mute = false;
10779 +
10780 + i2s_node = of_parse_phandle(pdev->dev.of_node,
10781 + "i2s-controller", 0);
10782 + if (i2s_node) {
10783 + dai->cpus->dai_name = NULL;
10784 + dai->cpus->of_node = i2s_node;
10785 + dai->platforms->name = NULL;
10786 + dai->platforms->of_node = i2s_node;
10787 + }
10788 +
10789 + digital_gain_0db_limit = !of_property_read_bool(
10790 + pdev->dev.of_node, "iqaudio,24db_digital_gain");
10791 +
10792 + if (of_property_read_string(pdev->dev.of_node, "card_name",
10793 + &card->name))
10794 + card->name = "IQaudIODAC";
10795 +
10796 + if (of_property_read_string(pdev->dev.of_node, "dai_name",
10797 + &dai->name))
10798 + dai->name = "IQaudIO DAC";
10799 +
10800 + if (of_property_read_string(pdev->dev.of_node,
10801 + "dai_stream_name", &dai->stream_name))
10802 + dai->stream_name = "IQaudIO DAC HiFi";
10803 +
10804 + /* gpio_unmute - one time unmute amp using GPIO */
10805 + gpio_unmute = of_property_read_bool(pdev->dev.of_node,
10806 + "iqaudio-dac,unmute-amp");
10807 +
10808 + /* auto_gpio_mute - mute/unmute amp using GPIO */
10809 + auto_gpio_mute = of_property_read_bool(pdev->dev.of_node,
10810 + "iqaudio-dac,auto-mute-amp");
10811 +
10812 + if (auto_gpio_mute || gpio_unmute) {
10813 + mute_gpio = devm_gpiod_get_optional(&pdev->dev, "mute",
10814 + GPIOD_OUT_LOW);
10815 + if (IS_ERR(mute_gpio)) {
10816 + ret = PTR_ERR(mute_gpio);
10817 + dev_err(&pdev->dev,
10818 + "Failed to get mute gpio: %d\n", ret);
10819 + return ret;
10820 + }
10821 +
10822 + if (auto_gpio_mute && mute_gpio)
10823 + snd_rpi_iqaudio_dac.set_bias_level =
10824 + snd_rpi_iqaudio_set_bias_level;
10825 + }
10826 + }
10827 +
10828 + ret = snd_soc_register_card(&snd_rpi_iqaudio_dac);
10829 + if (ret) {
10830 + if (ret != -EPROBE_DEFER)
10831 + dev_err(&pdev->dev,
10832 + "snd_soc_register_card() failed: %d\n", ret);
10833 + return ret;
10834 + }
10835 +
10836 + if (gpio_unmute && mute_gpio)
10837 + snd_rpi_iqaudio_gpio_unmute(&snd_rpi_iqaudio_dac);
10838 +
10839 + return 0;
10840 +}
10841 +
10842 +static int snd_rpi_iqaudio_dac_remove(struct platform_device *pdev)
10843 +{
10844 + snd_rpi_iqaudio_gpio_mute(&snd_rpi_iqaudio_dac);
10845 +
10846 + snd_soc_unregister_card(&snd_rpi_iqaudio_dac);
10847 + return 0;
10848 +}
10849 +
10850 +static const struct of_device_id iqaudio_of_match[] = {
10851 + { .compatible = "iqaudio,iqaudio-dac", },
10852 + {},
10853 +};
10854 +MODULE_DEVICE_TABLE(of, iqaudio_of_match);
10855 +
10856 +static struct platform_driver snd_rpi_iqaudio_dac_driver = {
10857 + .driver = {
10858 + .name = "snd-rpi-iqaudio-dac",
10859 + .owner = THIS_MODULE,
10860 + .of_match_table = iqaudio_of_match,
10861 + },
10862 + .probe = snd_rpi_iqaudio_dac_probe,
10863 + .remove = snd_rpi_iqaudio_dac_remove,
10864 +};
10865 +
10866 +module_platform_driver(snd_rpi_iqaudio_dac_driver);
10867 +
10868 +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
10869 +MODULE_DESCRIPTION("ASoC Driver for IQAudio DAC");
10870 +MODULE_LICENSE("GPL v2");
10871 --- /dev/null
10872 +++ b/sound/soc/bcm/justboom-both.c
10873 @@ -0,0 +1,267 @@
10874 +// SPDX-License-Identifier: GPL-2.0
10875 +/*
10876 + * rpi--wm8804.c -- ALSA SoC Raspberry Pi soundcard.
10877 + *
10878 + * Authors: Johannes Krude <johannes@krude.de
10879 + *
10880 + * Driver for when connecting simultaneously justboom-digi and justboom-dac
10881 + *
10882 + * Based upon code from:
10883 + * justboom-digi.c
10884 + * by Milan Neskovic <info@justboom.co>
10885 + * justboom-dac.c
10886 + * by Milan Neskovic <info@justboom.co>
10887 + *
10888 + * This program is free software; you can redistribute it and/or
10889 + * modify it under the terms of the GNU General Public License
10890 + * version 2 as published by the Free Software Foundation.
10891 + *
10892 + * This program is distributed in the hope that it will be useful, but
10893 + * WITHOUT ANY WARRANTY; without even the implied warranty of
10894 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10895 + * General Public License for more details.
10896 + */
10897 +
10898 +#include <linux/module.h>
10899 +#include <linux/platform_device.h>
10900 +
10901 +#include <sound/core.h>
10902 +#include <sound/pcm.h>
10903 +#include <sound/pcm_params.h>
10904 +#include <sound/soc.h>
10905 +#include <sound/jack.h>
10906 +
10907 +#include "../codecs/wm8804.h"
10908 +#include "../codecs/pcm512x.h"
10909 +
10910 +
10911 +static bool digital_gain_0db_limit = true;
10912 +
10913 +static int snd_rpi_justboom_both_init(struct snd_soc_pcm_runtime *rtd)
10914 +{
10915 + struct snd_soc_component *digi = asoc_rtd_to_codec(rtd, 0)->component;
10916 + struct snd_soc_component *dac = asoc_rtd_to_codec(rtd, 1)->component;
10917 +
10918 + /* enable TX output */
10919 + snd_soc_component_update_bits(digi, WM8804_PWRDN, 0x4, 0x0);
10920 +
10921 + snd_soc_component_update_bits(dac, PCM512x_GPIO_EN, 0x08, 0x08);
10922 + snd_soc_component_update_bits(dac, PCM512x_GPIO_OUTPUT_4, 0xf, 0x02);
10923 + snd_soc_component_update_bits(dac, PCM512x_GPIO_CONTROL_1, 0x08, 0x08);
10924 +
10925 + if (digital_gain_0db_limit) {
10926 + int ret;
10927 + struct snd_soc_card *card = rtd->card;
10928 +
10929 + ret = snd_soc_limit_volume(card, "Digital Playback Volume",
10930 + 207);
10931 + if (ret < 0)
10932 + dev_warn(card->dev, "Failed to set volume limit: %d\n",
10933 + ret);
10934 + }
10935 +
10936 + return 0;
10937 +}
10938 +
10939 +static int snd_rpi_justboom_both_hw_params(struct snd_pcm_substream *substream,
10940 + struct snd_pcm_hw_params *params)
10941 +{
10942 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
10943 + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
10944 + struct snd_soc_component *digi = asoc_rtd_to_codec(rtd, 0)->component;
10945 + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
10946 +
10947 + int sysclk = 27000000; /* This is fixed on this board */
10948 +
10949 + long mclk_freq = 0;
10950 + int mclk_div = 1;
10951 + int sampling_freq = 1;
10952 +
10953 + int ret;
10954 +
10955 + int samplerate = params_rate(params);
10956 +
10957 + if (samplerate <= 96000) {
10958 + mclk_freq = samplerate*256;
10959 + mclk_div = WM8804_MCLKDIV_256FS;
10960 + } else {
10961 + mclk_freq = samplerate*128;
10962 + mclk_div = WM8804_MCLKDIV_128FS;
10963 + }
10964 +
10965 + switch (samplerate) {
10966 + case 32000:
10967 + sampling_freq = 0x03;
10968 + break;
10969 + case 44100:
10970 + sampling_freq = 0x00;
10971 + break;
10972 + case 48000:
10973 + sampling_freq = 0x02;
10974 + break;
10975 + case 88200:
10976 + sampling_freq = 0x08;
10977 + break;
10978 + case 96000:
10979 + sampling_freq = 0x0a;
10980 + break;
10981 + case 176400:
10982 + sampling_freq = 0x0c;
10983 + break;
10984 + case 192000:
10985 + sampling_freq = 0x0e;
10986 + break;
10987 + default:
10988 + dev_err(rtd->card->dev,
10989 + "Failed to set WM8804 SYSCLK, unsupported samplerate %d\n",
10990 + samplerate);
10991 + }
10992 +
10993 + snd_soc_dai_set_clkdiv(codec_dai, WM8804_MCLK_DIV, mclk_div);
10994 + snd_soc_dai_set_pll(codec_dai, 0, 0, sysclk, mclk_freq);
10995 +
10996 + ret = snd_soc_dai_set_sysclk(codec_dai, WM8804_TX_CLKSRC_PLL,
10997 + sysclk, SND_SOC_CLOCK_OUT);
10998 + if (ret < 0) {
10999 + dev_err(rtd->card->dev,
11000 + "Failed to set WM8804 SYSCLK: %d\n", ret);
11001 + return ret;
11002 + }
11003 +
11004 + /* Enable TX output */
11005 + snd_soc_component_update_bits(digi, WM8804_PWRDN, 0x4, 0x0);
11006 +
11007 + /* Power on */
11008 + snd_soc_component_update_bits(digi, WM8804_PWRDN, 0x9, 0);
11009 +
11010 + /* set sampling frequency status bits */
11011 + snd_soc_component_update_bits(digi, WM8804_SPDTX4, 0x0f, sampling_freq);
11012 +
11013 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 64);
11014 +}
11015 +
11016 +static int snd_rpi_justboom_both_startup(struct snd_pcm_substream *substream)
11017 +{
11018 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
11019 + struct snd_soc_component *digi = asoc_rtd_to_codec(rtd, 0)->component;
11020 + struct snd_soc_component *dac = asoc_rtd_to_codec(rtd, 1)->component;
11021 +
11022 + /* turn on digital output */
11023 + snd_soc_component_update_bits(digi, WM8804_PWRDN, 0x3c, 0x00);
11024 +
11025 + snd_soc_component_update_bits(dac, PCM512x_GPIO_CONTROL_1, 0x08, 0x08);
11026 +
11027 + return 0;
11028 +}
11029 +
11030 +static void snd_rpi_justboom_both_shutdown(struct snd_pcm_substream *substream)
11031 +{
11032 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
11033 + struct snd_soc_component *digi = asoc_rtd_to_codec(rtd, 0)->component;
11034 + struct snd_soc_component *dac = asoc_rtd_to_codec(rtd, 1)->component;
11035 +
11036 + snd_soc_component_update_bits(dac, PCM512x_GPIO_CONTROL_1, 0x08, 0x00);
11037 +
11038 + /* turn off output */
11039 + snd_soc_component_update_bits(digi, WM8804_PWRDN, 0x3c, 0x3c);
11040 +}
11041 +
11042 +/* machine stream operations */
11043 +static struct snd_soc_ops snd_rpi_justboom_both_ops = {
11044 + .hw_params = snd_rpi_justboom_both_hw_params,
11045 + .startup = snd_rpi_justboom_both_startup,
11046 + .shutdown = snd_rpi_justboom_both_shutdown,
11047 +};
11048 +
11049 +SND_SOC_DAILINK_DEFS(rpi_justboom_both,
11050 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
11051 + DAILINK_COMP_ARRAY(COMP_CODEC("pcm512x.1-004d", "pcm512x-hifi"),
11052 + COMP_CODEC("wm8804.1-003b", "wm8804-spdif")),
11053 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
11054 +
11055 +static struct snd_soc_dai_link snd_rpi_justboom_both_dai[] = {
11056 +{
11057 + .name = "JustBoom Digi",
11058 + .stream_name = "JustBoom Digi HiFi",
11059 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
11060 + SND_SOC_DAIFMT_CBM_CFM,
11061 + .ops = &snd_rpi_justboom_both_ops,
11062 + .init = snd_rpi_justboom_both_init,
11063 + SND_SOC_DAILINK_REG(rpi_justboom_both),
11064 +},
11065 +};
11066 +
11067 +/* audio machine driver */
11068 +static struct snd_soc_card snd_rpi_justboom_both = {
11069 + .name = "snd_rpi_justboom_both",
11070 + .driver_name = "JustBoomBoth",
11071 + .owner = THIS_MODULE,
11072 + .dai_link = snd_rpi_justboom_both_dai,
11073 + .num_links = ARRAY_SIZE(snd_rpi_justboom_both_dai),
11074 +};
11075 +
11076 +static int snd_rpi_justboom_both_probe(struct platform_device *pdev)
11077 +{
11078 + int ret = 0;
11079 + struct snd_soc_card *card = &snd_rpi_justboom_both;
11080 +
11081 + snd_rpi_justboom_both.dev = &pdev->dev;
11082 +
11083 + if (pdev->dev.of_node) {
11084 + struct device_node *i2s_node;
11085 + struct snd_soc_dai_link *dai = &snd_rpi_justboom_both_dai[0];
11086 +
11087 + i2s_node = of_parse_phandle(pdev->dev.of_node,
11088 + "i2s-controller", 0);
11089 +
11090 + if (i2s_node) {
11091 + int i;
11092 +
11093 + for (i = 0; i < card->num_links; i++) {
11094 + dai->cpus->dai_name = NULL;
11095 + dai->cpus->of_node = i2s_node;
11096 + dai->platforms->name = NULL;
11097 + dai->platforms->of_node = i2s_node;
11098 + }
11099 + }
11100 +
11101 + digital_gain_0db_limit = !of_property_read_bool(
11102 + pdev->dev.of_node, "justboom,24db_digital_gain");
11103 + }
11104 +
11105 + ret = snd_soc_register_card(card);
11106 + if (ret && ret != -EPROBE_DEFER) {
11107 + dev_err(&pdev->dev,
11108 + "snd_soc_register_card() failed: %d\n", ret);
11109 + }
11110 +
11111 + return ret;
11112 +}
11113 +
11114 +static int snd_rpi_justboom_both_remove(struct platform_device *pdev)
11115 +{
11116 + snd_soc_unregister_card(&snd_rpi_justboom_both);
11117 + return 0;
11118 +}
11119 +
11120 +static const struct of_device_id snd_rpi_justboom_both_of_match[] = {
11121 + { .compatible = "justboom,justboom-both", },
11122 + {},
11123 +};
11124 +MODULE_DEVICE_TABLE(of, snd_rpi_justboom_both_of_match);
11125 +
11126 +static struct platform_driver snd_rpi_justboom_both_driver = {
11127 + .driver = {
11128 + .name = "snd-rpi-justboom-both",
11129 + .owner = THIS_MODULE,
11130 + .of_match_table = snd_rpi_justboom_both_of_match,
11131 + },
11132 + .probe = snd_rpi_justboom_both_probe,
11133 + .remove = snd_rpi_justboom_both_remove,
11134 +};
11135 +
11136 +module_platform_driver(snd_rpi_justboom_both_driver);
11137 +
11138 +MODULE_AUTHOR("Johannes Krude <johannes@krude.de>");
11139 +MODULE_DESCRIPTION("ASoC Driver for simultaneous use of JustBoom PI Digi & DAC HAT Sound Cards");
11140 +MODULE_LICENSE("GPL v2");
11141 --- /dev/null
11142 +++ b/sound/soc/bcm/justboom-dac.c
11143 @@ -0,0 +1,147 @@
11144 +/*
11145 + * ASoC Driver for JustBoom DAC Raspberry Pi HAT Sound Card
11146 + *
11147 + * Author: Milan Neskovic
11148 + * Copyright 2016
11149 + * based on code by Daniel Matuschek <info@crazy-audio.com>
11150 + * based on code by Florian Meier <florian.meier@koalo.de>
11151 + *
11152 + * This program is free software; you can redistribute it and/or
11153 + * modify it under the terms of the GNU General Public License
11154 + * version 2 as published by the Free Software Foundation.
11155 + *
11156 + * This program is distributed in the hope that it will be useful, but
11157 + * WITHOUT ANY WARRANTY; without even the implied warranty of
11158 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11159 + * General Public License for more details.
11160 + */
11161 +
11162 +#include <linux/module.h>
11163 +#include <linux/platform_device.h>
11164 +
11165 +#include <sound/core.h>
11166 +#include <sound/pcm.h>
11167 +#include <sound/pcm_params.h>
11168 +#include <sound/soc.h>
11169 +#include <sound/jack.h>
11170 +
11171 +#include "../codecs/pcm512x.h"
11172 +
11173 +static bool digital_gain_0db_limit = true;
11174 +
11175 +static int snd_rpi_justboom_dac_init(struct snd_soc_pcm_runtime *rtd)
11176 +{
11177 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
11178 + snd_soc_component_update_bits(component, PCM512x_GPIO_EN, 0x08, 0x08);
11179 + snd_soc_component_update_bits(component, PCM512x_GPIO_OUTPUT_4, 0xf, 0x02);
11180 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x08,0x08);
11181 +
11182 + if (digital_gain_0db_limit)
11183 + {
11184 + int ret;
11185 + struct snd_soc_card *card = rtd->card;
11186 +
11187 + ret = snd_soc_limit_volume(card, "Digital Playback Volume", 207);
11188 + if (ret < 0)
11189 + dev_warn(card->dev, "Failed to set volume limit: %d\n", ret);
11190 + }
11191 +
11192 + return 0;
11193 +}
11194 +
11195 +static int snd_rpi_justboom_dac_startup(struct snd_pcm_substream *substream) {
11196 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
11197 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
11198 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x08,0x08);
11199 + return 0;
11200 +}
11201 +
11202 +static void snd_rpi_justboom_dac_shutdown(struct snd_pcm_substream *substream) {
11203 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
11204 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
11205 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x08,0x00);
11206 +}
11207 +
11208 +/* machine stream operations */
11209 +static struct snd_soc_ops snd_rpi_justboom_dac_ops = {
11210 + .startup = snd_rpi_justboom_dac_startup,
11211 + .shutdown = snd_rpi_justboom_dac_shutdown,
11212 +};
11213 +
11214 +SND_SOC_DAILINK_DEFS(hifi,
11215 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
11216 + DAILINK_COMP_ARRAY(COMP_CODEC("pcm512x.1-004d", "pcm512x-hifi")),
11217 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
11218 +
11219 +static struct snd_soc_dai_link snd_rpi_justboom_dac_dai[] = {
11220 +{
11221 + .name = "JustBoom DAC",
11222 + .stream_name = "JustBoom DAC HiFi",
11223 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
11224 + SND_SOC_DAIFMT_CBS_CFS,
11225 + .ops = &snd_rpi_justboom_dac_ops,
11226 + .init = snd_rpi_justboom_dac_init,
11227 + SND_SOC_DAILINK_REG(hifi),
11228 +},
11229 +};
11230 +
11231 +/* audio machine driver */
11232 +static struct snd_soc_card snd_rpi_justboom_dac = {
11233 + .name = "snd_rpi_justboom_dac",
11234 + .driver_name = "JustBoomDac",
11235 + .owner = THIS_MODULE,
11236 + .dai_link = snd_rpi_justboom_dac_dai,
11237 + .num_links = ARRAY_SIZE(snd_rpi_justboom_dac_dai),
11238 +};
11239 +
11240 +static int snd_rpi_justboom_dac_probe(struct platform_device *pdev)
11241 +{
11242 + int ret = 0;
11243 +
11244 + snd_rpi_justboom_dac.dev = &pdev->dev;
11245 +
11246 + if (pdev->dev.of_node) {
11247 + struct device_node *i2s_node;
11248 + struct snd_soc_dai_link *dai = &snd_rpi_justboom_dac_dai[0];
11249 + i2s_node = of_parse_phandle(pdev->dev.of_node,
11250 + "i2s-controller", 0);
11251 +
11252 + if (i2s_node) {
11253 + dai->cpus->dai_name = NULL;
11254 + dai->cpus->of_node = i2s_node;
11255 + dai->platforms->name = NULL;
11256 + dai->platforms->of_node = i2s_node;
11257 + }
11258 +
11259 + digital_gain_0db_limit = !of_property_read_bool(
11260 + pdev->dev.of_node, "justboom,24db_digital_gain");
11261 + }
11262 +
11263 + ret = devm_snd_soc_register_card(&pdev->dev, &snd_rpi_justboom_dac);
11264 + if (ret && ret != -EPROBE_DEFER)
11265 + dev_err(&pdev->dev,
11266 + "snd_soc_register_card() failed: %d\n", ret);
11267 +
11268 + return ret;
11269 +}
11270 +
11271 +static const struct of_device_id snd_rpi_justboom_dac_of_match[] = {
11272 + { .compatible = "justboom,justboom-dac", },
11273 + {},
11274 +};
11275 +MODULE_DEVICE_TABLE(of, snd_rpi_justboom_dac_of_match);
11276 +
11277 +static struct platform_driver snd_rpi_justboom_dac_driver = {
11278 + .driver = {
11279 + .name = "snd-rpi-justboom-dac",
11280 + .owner = THIS_MODULE,
11281 + .of_match_table = snd_rpi_justboom_dac_of_match,
11282 + },
11283 + .probe = snd_rpi_justboom_dac_probe,
11284 +};
11285 +
11286 +module_platform_driver(snd_rpi_justboom_dac_driver);
11287 +
11288 +MODULE_AUTHOR("Milan Neskovic <info@justboom.co>");
11289 +MODULE_DESCRIPTION("ASoC Driver for JustBoom PI DAC HAT Sound Card");
11290 +MODULE_LICENSE("GPL v2");
11291 --- /dev/null
11292 +++ b/sound/soc/bcm/pifi-40.c
11293 @@ -0,0 +1,284 @@
11294 +// SPDX-License-Identifier: GPL-2.0-only
11295 +/*
11296 + * ALSA ASoC Machine Driver for PiFi-40
11297 + *
11298 + * Author: David Knell <david.knell@gmail.com)
11299 + * based on code by Daniel Matuschek <info@crazy-audio.com>
11300 + * based on code by Florian Meier <florian.meier@koalo.de>
11301 + * Copyright (C) 2020
11302 + *
11303 + * This program is free software; you can redistribute it and/or
11304 + * modify it under the terms of the GNU General Public License
11305 + * version 2 as published by the Free Software Foundation.
11306 + *
11307 + * This program is distributed in the hope that it will be useful, but
11308 + * WITHOUT ANY WARRANTY; without even the implied warranty of
11309 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11310 + * General Public License for more details.
11311 + */
11312 +
11313 +#include <linux/module.h>
11314 +#include <linux/platform_device.h>
11315 +#include <linux/gpio/consumer.h>
11316 +#include <sound/core.h>
11317 +#include <sound/pcm.h>
11318 +#include <sound/pcm_params.h>
11319 +#include <sound/soc.h>
11320 +#include <linux/firmware.h>
11321 +#include <linux/delay.h>
11322 +#include <sound/tlv.h>
11323 +
11324 +static struct gpio_desc *pdn_gpio;
11325 +static int vol = 0x30;
11326 +
11327 +// Volume control
11328 +static int pifi_40_vol_get(struct snd_kcontrol *kcontrol,
11329 + struct snd_ctl_elem_value *ucontrol)
11330 +{
11331 + ucontrol->value.integer.value[0] = vol;
11332 + ucontrol->value.integer.value[1] = vol;
11333 + return 0;
11334 +}
11335 +
11336 +static int pifi_40_vol_set(struct snd_kcontrol *kcontrol,
11337 + struct snd_ctl_elem_value *ucontrol)
11338 +{
11339 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
11340 + struct snd_soc_pcm_runtime *rtd;
11341 + unsigned int v = ucontrol->value.integer.value[0];
11342 + struct snd_soc_component *dac[2];
11343 +
11344 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
11345 + dac[0] = asoc_rtd_to_codec(rtd, 0)->component;
11346 + dac[1] = asoc_rtd_to_codec(rtd, 1)->component;
11347 +
11348 + snd_soc_component_write(dac[0], 0x07, 255 - v);
11349 + snd_soc_component_write(dac[1], 0x07, 255 - v);
11350 +
11351 + vol = v;
11352 + return 1;
11353 +}
11354 +
11355 +static const DECLARE_TLV_DB_SCALE(digital_tlv_master, -10350, 50, 1);
11356 +static const struct snd_kcontrol_new pifi_40_controls[] = {
11357 + SOC_DOUBLE_R_EXT_TLV("Master Volume", 0x00, 0x01,
11358 + 0x00, // Min
11359 + 0xff, // Max
11360 + 0x01, // Invert
11361 + pifi_40_vol_get, pifi_40_vol_set,
11362 + digital_tlv_master)
11363 +};
11364 +
11365 +static const char * const codec_ctl_pfx[] = { "Left", "Right" };
11366 +
11367 +static const char * const codec_ctl_name[] = { "Master Volume",
11368 + "Speaker Volume",
11369 + "Speaker Switch" };
11370 +
11371 +static int snd_pifi_40_init(struct snd_soc_pcm_runtime *rtd)
11372 +{
11373 + struct snd_soc_card *card = rtd->card;
11374 + struct snd_soc_component *dac[2];
11375 + struct snd_kcontrol *kctl;
11376 + int i, j;
11377 +
11378 + dac[0] = asoc_rtd_to_codec(rtd, 0)->component;
11379 + dac[1] = asoc_rtd_to_codec(rtd, 1)->component;
11380 +
11381 +
11382 + // Set up cards - pulse power down first
11383 + gpiod_set_value_cansleep(pdn_gpio, 1);
11384 + usleep_range(1000, 10000);
11385 + gpiod_set_value_cansleep(pdn_gpio, 0);
11386 + usleep_range(20000, 30000);
11387 +
11388 + // Oscillator trim
11389 + snd_soc_component_write(dac[0], 0x1b, 0);
11390 + snd_soc_component_write(dac[1], 0x1b, 0);
11391 + usleep_range(60000, 80000);
11392 +
11393 + // Common setup
11394 + for (i = 0; i < 2; i++) {
11395 + // MCLK at 64fs, sample rate 44.1 or 48kHz
11396 + snd_soc_component_write(dac[i], 0x00, 0x60);
11397 +
11398 + // Set up for PBTL
11399 + snd_soc_component_write(dac[i], 0x19, 0x3A);
11400 + snd_soc_component_write(dac[i], 0x25, 0x01103245);
11401 +
11402 + // Master vol to -10db
11403 + snd_soc_component_write(dac[i], 0x07, 0x44);
11404 + }
11405 + // Inputs set to L and R respectively
11406 + snd_soc_component_write(dac[0], 0x20, 0x00017772);
11407 + snd_soc_component_write(dac[1], 0x20, 0x00107772);
11408 +
11409 + // Remove codec controls
11410 + for (i = 0; i < 2; i++) {
11411 + for (j = 0; j < 3; j++) {
11412 + char cname[256];
11413 +
11414 + sprintf(cname, "%s %s", codec_ctl_pfx[i],
11415 + codec_ctl_name[j]);
11416 + kctl = snd_soc_card_get_kcontrol(card, cname);
11417 + if (!kctl) {
11418 + pr_info("Control %s not found\n",
11419 + cname);
11420 + } else {
11421 + kctl->vd[0].access =
11422 + SNDRV_CTL_ELEM_ACCESS_READWRITE;
11423 + snd_ctl_remove(card->snd_card, kctl);
11424 + }
11425 + }
11426 + }
11427 +
11428 + return 0;
11429 +}
11430 +
11431 +static int snd_pifi_40_hw_params(struct snd_pcm_substream *substream,
11432 + struct snd_pcm_hw_params *params)
11433 +{
11434 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
11435 + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
11436 + unsigned int sample_bits;
11437 +
11438 + sample_bits = snd_pcm_format_physical_width(params_format(params));
11439 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 64);
11440 +}
11441 +
11442 +static struct snd_soc_ops snd_pifi_40_ops = { .hw_params =
11443 + snd_pifi_40_hw_params };
11444 +
11445 +static struct snd_soc_dai_link_component pifi_40_codecs[] = {
11446 + {
11447 + .dai_name = "tas571x-hifi",
11448 + },
11449 + {
11450 + .dai_name = "tas571x-hifi",
11451 + },
11452 +};
11453 +
11454 +SND_SOC_DAILINK_DEFS(
11455 + pifi_40_dai, DAILINK_COMP_ARRAY(COMP_EMPTY()),
11456 + DAILINK_COMP_ARRAY(COMP_CODEC("tas571x.1-001a", "tas571x-hifi"),
11457 + COMP_CODEC("tas571x.1-001b", "tas571x-hifi")),
11458 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
11459 +
11460 +static struct snd_soc_dai_link snd_pifi_40_dai[] = {
11461 + {
11462 + .name = "PiFi40",
11463 + .stream_name = "PiFi40",
11464 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
11465 + SND_SOC_DAIFMT_CBS_CFS,
11466 + .ops = &snd_pifi_40_ops,
11467 + .init = snd_pifi_40_init,
11468 + SND_SOC_DAILINK_REG(pifi_40_dai),
11469 + },
11470 +};
11471 +
11472 +// Machine driver
11473 +static struct snd_soc_card snd_pifi_40 = {
11474 + .name = "PiFi40",
11475 + .owner = THIS_MODULE,
11476 + .dai_link = snd_pifi_40_dai,
11477 + .num_links = ARRAY_SIZE(snd_pifi_40_dai),
11478 + .controls = pifi_40_controls,
11479 + .num_controls = ARRAY_SIZE(pifi_40_controls)
11480 +};
11481 +
11482 +static void snd_pifi_40_pdn(struct snd_soc_card *card, int on)
11483 +{
11484 + if (pdn_gpio)
11485 + gpiod_set_value_cansleep(pdn_gpio, on ? 0 : 1);
11486 +}
11487 +
11488 +static int snd_pifi_40_probe(struct platform_device *pdev)
11489 +{
11490 + struct snd_soc_card *card = &snd_pifi_40;
11491 + int ret = 0, i = 0;
11492 +
11493 + card->dev = &pdev->dev;
11494 + platform_set_drvdata(pdev, &snd_pifi_40);
11495 +
11496 + if (pdev->dev.of_node) {
11497 + struct device_node *i2s_node;
11498 + struct snd_soc_dai_link *dai;
11499 +
11500 + dai = &snd_pifi_40_dai[0];
11501 + i2s_node = of_parse_phandle(pdev->dev.of_node, "i2s-controller",
11502 + 0);
11503 + if (i2s_node) {
11504 + for (i = 0; i < card->num_links; i++) {
11505 + dai->cpus->dai_name = NULL;
11506 + dai->cpus->of_node = i2s_node;
11507 + dai->platforms->name = NULL;
11508 + dai->platforms->of_node = i2s_node;
11509 + }
11510 + }
11511 +
11512 + pifi_40_codecs[0].of_node =
11513 + of_parse_phandle(pdev->dev.of_node, "audio-codec", 0);
11514 + pifi_40_codecs[1].of_node =
11515 + of_parse_phandle(pdev->dev.of_node, "audio-codec", 1);
11516 + if (!pifi_40_codecs[0].of_node || !pifi_40_codecs[1].of_node) {
11517 + dev_err(&pdev->dev,
11518 + "Property 'audio-codec' missing or invalid\n");
11519 + return -EINVAL;
11520 + }
11521 +
11522 + pdn_gpio = devm_gpiod_get_optional(&pdev->dev, "pdn",
11523 + GPIOD_OUT_LOW);
11524 + if (IS_ERR(pdn_gpio)) {
11525 + ret = PTR_ERR(pdn_gpio);
11526 + dev_err(&pdev->dev, "failed to get pdn gpio: %d\n",
11527 + ret);
11528 + return ret;
11529 + }
11530 +
11531 + ret = snd_soc_register_card(&snd_pifi_40);
11532 + if (ret < 0) {
11533 + dev_err(&pdev->dev,
11534 + "snd_soc_register_card() failed: %d\n", ret);
11535 + return ret;
11536 + }
11537 +
11538 + return 0;
11539 + }
11540 +
11541 + return -EINVAL;
11542 +}
11543 +
11544 +static int snd_pifi_40_remove(struct platform_device *pdev)
11545 +{
11546 + struct snd_soc_card *card = platform_get_drvdata(pdev);
11547 +
11548 + kfree(&card->drvdata);
11549 + snd_pifi_40_pdn(&snd_pifi_40, 0);
11550 + snd_soc_unregister_card(&snd_pifi_40);
11551 + return 0;
11552 +}
11553 +
11554 +static const struct of_device_id snd_pifi_40_of_match[] = {
11555 + {
11556 + .compatible = "pifi,pifi-40",
11557 + },
11558 + { /* sentinel */ },
11559 +};
11560 +
11561 +MODULE_DEVICE_TABLE(of, snd_pifi_40_of_match);
11562 +
11563 +static struct platform_driver snd_pifi_40_driver = {
11564 + .driver = {
11565 + .name = "snd-pifi-40",
11566 + .owner = THIS_MODULE,
11567 + .of_match_table = snd_pifi_40_of_match,
11568 + },
11569 + .probe = snd_pifi_40_probe,
11570 + .remove = snd_pifi_40_remove,
11571 +};
11572 +
11573 +module_platform_driver(snd_pifi_40_driver);
11574 +
11575 +MODULE_AUTHOR("David Knell <david.knell@gmail.com>");
11576 +MODULE_DESCRIPTION("ALSA ASoC Machine Driver for PiFi-40");
11577 +MODULE_LICENSE("GPL v2");
11578 --- /dev/null
11579 +++ b/sound/soc/bcm/pisound.c
11580 @@ -0,0 +1,1241 @@
11581 +/*
11582 + * Pisound Linux kernel module.
11583 + * Copyright (C) 2016-2020 Vilniaus Blokas UAB, https://blokas.io/pisound
11584 + *
11585 + * This program is free software; you can redistribute it and/or
11586 + * modify it under the terms of the GNU General Public License
11587 + * as published by the Free Software Foundation; version 2 of the
11588 + * License.
11589 + *
11590 + * This program is distributed in the hope that it will be useful,
11591 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11592 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11593 + * GNU General Public License for more details.
11594 + *
11595 + * You should have received a copy of the GNU General Public License
11596 + * along with this program; if not, write to the Free Software
11597 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
11598 + * MA 02110-1301, USA.
11599 + */
11600 +
11601 +#include <linux/init.h>
11602 +#include <linux/module.h>
11603 +#include <linux/platform_device.h>
11604 +#include <linux/gpio.h>
11605 +#include <linux/kobject.h>
11606 +#include <linux/sysfs.h>
11607 +#include <linux/delay.h>
11608 +#include <linux/spi/spi.h>
11609 +#include <linux/interrupt.h>
11610 +#include <linux/kfifo.h>
11611 +#include <linux/jiffies.h>
11612 +
11613 +#include <sound/core.h>
11614 +#include <sound/pcm.h>
11615 +#include <sound/pcm_params.h>
11616 +#include <sound/soc.h>
11617 +#include <sound/jack.h>
11618 +#include <sound/rawmidi.h>
11619 +#include <sound/asequencer.h>
11620 +#include <sound/control.h>
11621 +
11622 +static int pisnd_spi_init(struct device *dev);
11623 +static void pisnd_spi_uninit(void);
11624 +
11625 +static void pisnd_spi_flush(void);
11626 +static void pisnd_spi_start(void);
11627 +static uint8_t pisnd_spi_recv(uint8_t *buffer, uint8_t length);
11628 +
11629 +typedef void (*pisnd_spi_recv_cb)(void *data);
11630 +static void pisnd_spi_set_callback(pisnd_spi_recv_cb cb, void *data);
11631 +
11632 +static const char *pisnd_spi_get_serial(void);
11633 +static const char *pisnd_spi_get_id(void);
11634 +static const char *pisnd_spi_get_fw_version(void);
11635 +static const char *pisnd_spi_get_hw_version(void);
11636 +
11637 +static int pisnd_midi_init(struct snd_card *card);
11638 +static void pisnd_midi_uninit(void);
11639 +
11640 +enum task_e {
11641 + TASK_PROCESS = 0,
11642 +};
11643 +
11644 +static void pisnd_schedule_process(enum task_e task);
11645 +
11646 +#define PISOUND_LOG_PREFIX "pisound: "
11647 +
11648 +#ifdef PISOUND_DEBUG
11649 +# define printd(...) pr_alert(PISOUND_LOG_PREFIX __VA_ARGS__)
11650 +#else
11651 +# define printd(...) do {} while (0)
11652 +#endif
11653 +
11654 +#define printe(...) pr_err(PISOUND_LOG_PREFIX __VA_ARGS__)
11655 +#define printi(...) pr_info(PISOUND_LOG_PREFIX __VA_ARGS__)
11656 +
11657 +static struct snd_rawmidi *g_rmidi;
11658 +static struct snd_rawmidi_substream *g_midi_output_substream;
11659 +
11660 +static int pisnd_output_open(struct snd_rawmidi_substream *substream)
11661 +{
11662 + g_midi_output_substream = substream;
11663 + return 0;
11664 +}
11665 +
11666 +static int pisnd_output_close(struct snd_rawmidi_substream *substream)
11667 +{
11668 + g_midi_output_substream = NULL;
11669 + return 0;
11670 +}
11671 +
11672 +static void pisnd_output_trigger(
11673 + struct snd_rawmidi_substream *substream,
11674 + int up
11675 + )
11676 +{
11677 + if (substream != g_midi_output_substream) {
11678 + printe("MIDI output trigger called for an unexpected stream!");
11679 + return;
11680 + }
11681 +
11682 + if (!up)
11683 + return;
11684 +
11685 + pisnd_spi_start();
11686 +}
11687 +
11688 +static void pisnd_output_drain(struct snd_rawmidi_substream *substream)
11689 +{
11690 + pisnd_spi_flush();
11691 +}
11692 +
11693 +static int pisnd_input_open(struct snd_rawmidi_substream *substream)
11694 +{
11695 + return 0;
11696 +}
11697 +
11698 +static int pisnd_input_close(struct snd_rawmidi_substream *substream)
11699 +{
11700 + return 0;
11701 +}
11702 +
11703 +static void pisnd_midi_recv_callback(void *substream)
11704 +{
11705 + uint8_t data[128];
11706 + uint8_t n = 0;
11707 +
11708 + while ((n = pisnd_spi_recv(data, sizeof(data)))) {
11709 + int res = snd_rawmidi_receive(substream, data, n);
11710 + (void)res;
11711 + printd("midi recv %u bytes, res = %d\n", n, res);
11712 + }
11713 +}
11714 +
11715 +static void pisnd_input_trigger(struct snd_rawmidi_substream *substream, int up)
11716 +{
11717 + if (up) {
11718 + pisnd_spi_set_callback(pisnd_midi_recv_callback, substream);
11719 + pisnd_schedule_process(TASK_PROCESS);
11720 + } else {
11721 + pisnd_spi_set_callback(NULL, NULL);
11722 + }
11723 +}
11724 +
11725 +static struct snd_rawmidi_ops pisnd_output_ops = {
11726 + .open = pisnd_output_open,
11727 + .close = pisnd_output_close,
11728 + .trigger = pisnd_output_trigger,
11729 + .drain = pisnd_output_drain,
11730 +};
11731 +
11732 +static struct snd_rawmidi_ops pisnd_input_ops = {
11733 + .open = pisnd_input_open,
11734 + .close = pisnd_input_close,
11735 + .trigger = pisnd_input_trigger,
11736 +};
11737 +
11738 +static void pisnd_get_port_info(
11739 + struct snd_rawmidi *rmidi,
11740 + int number,
11741 + struct snd_seq_port_info *seq_port_info
11742 + )
11743 +{
11744 + seq_port_info->type =
11745 + SNDRV_SEQ_PORT_TYPE_MIDI_GENERIC |
11746 + SNDRV_SEQ_PORT_TYPE_HARDWARE |
11747 + SNDRV_SEQ_PORT_TYPE_PORT;
11748 + seq_port_info->midi_voices = 0;
11749 +}
11750 +
11751 +static struct snd_rawmidi_global_ops pisnd_global_ops = {
11752 + .get_port_info = pisnd_get_port_info,
11753 +};
11754 +
11755 +static int pisnd_midi_init(struct snd_card *card)
11756 +{
11757 + int err;
11758 +
11759 + g_midi_output_substream = NULL;
11760 +
11761 + err = snd_rawmidi_new(card, "pisound MIDI", 0, 1, 1, &g_rmidi);
11762 +
11763 + if (err < 0) {
11764 + printe("snd_rawmidi_new failed: %d\n", err);
11765 + return err;
11766 + }
11767 +
11768 + strcpy(g_rmidi->name, "pisound MIDI ");
11769 + strcat(g_rmidi->name, pisnd_spi_get_serial());
11770 +
11771 + g_rmidi->info_flags =
11772 + SNDRV_RAWMIDI_INFO_OUTPUT |
11773 + SNDRV_RAWMIDI_INFO_INPUT |
11774 + SNDRV_RAWMIDI_INFO_DUPLEX;
11775 +
11776 + g_rmidi->ops = &pisnd_global_ops;
11777 +
11778 + g_rmidi->private_data = (void *)0;
11779 +
11780 + snd_rawmidi_set_ops(
11781 + g_rmidi,
11782 + SNDRV_RAWMIDI_STREAM_OUTPUT,
11783 + &pisnd_output_ops
11784 + );
11785 +
11786 + snd_rawmidi_set_ops(
11787 + g_rmidi,
11788 + SNDRV_RAWMIDI_STREAM_INPUT,
11789 + &pisnd_input_ops
11790 + );
11791 +
11792 + return 0;
11793 +}
11794 +
11795 +static void pisnd_midi_uninit(void)
11796 +{
11797 +}
11798 +
11799 +static void *g_recvData;
11800 +static pisnd_spi_recv_cb g_recvCallback;
11801 +
11802 +#define FIFO_SIZE 4096
11803 +
11804 +static char g_serial_num[11];
11805 +static char g_id[25];
11806 +enum { MAX_VERSION_STR_LEN = 6 };
11807 +static char g_fw_version[MAX_VERSION_STR_LEN];
11808 +static char g_hw_version[MAX_VERSION_STR_LEN];
11809 +
11810 +static uint8_t g_ledFlashDuration;
11811 +static bool g_ledFlashDurationChanged;
11812 +
11813 +DEFINE_KFIFO(spi_fifo_in, uint8_t, FIFO_SIZE);
11814 +DEFINE_KFIFO(spi_fifo_out, uint8_t, FIFO_SIZE);
11815 +
11816 +static struct gpio_desc *data_available;
11817 +static struct gpio_desc *spi_reset;
11818 +
11819 +static struct spi_device *pisnd_spi_device;
11820 +
11821 +static struct workqueue_struct *pisnd_workqueue;
11822 +static struct work_struct pisnd_work_process;
11823 +
11824 +static void pisnd_work_handler(struct work_struct *work);
11825 +
11826 +static void spi_transfer(const uint8_t *txbuf, uint8_t *rxbuf, int len);
11827 +static uint16_t spi_transfer16(uint16_t val);
11828 +
11829 +static int pisnd_init_workqueues(void)
11830 +{
11831 + pisnd_workqueue = create_singlethread_workqueue("pisnd_workqueue");
11832 + INIT_WORK(&pisnd_work_process, pisnd_work_handler);
11833 +
11834 + return 0;
11835 +}
11836 +
11837 +static void pisnd_uninit_workqueues(void)
11838 +{
11839 + flush_workqueue(pisnd_workqueue);
11840 + destroy_workqueue(pisnd_workqueue);
11841 +
11842 + pisnd_workqueue = NULL;
11843 +}
11844 +
11845 +static bool pisnd_spi_has_more(void)
11846 +{
11847 + return gpiod_get_value(data_available);
11848 +}
11849 +
11850 +static void pisnd_schedule_process(enum task_e task)
11851 +{
11852 + if (pisnd_spi_device != NULL &&
11853 + pisnd_workqueue != NULL &&
11854 + !work_pending(&pisnd_work_process)
11855 + ) {
11856 + printd("schedule: has more = %d\n", pisnd_spi_has_more());
11857 + if (task == TASK_PROCESS)
11858 + queue_work(pisnd_workqueue, &pisnd_work_process);
11859 + }
11860 +}
11861 +
11862 +static irqreturn_t data_available_interrupt_handler(int irq, void *dev_id)
11863 +{
11864 + if (irq == gpiod_to_irq(data_available) && pisnd_spi_has_more()) {
11865 + printd("schedule from irq\n");
11866 + pisnd_schedule_process(TASK_PROCESS);
11867 + }
11868 +
11869 + return IRQ_HANDLED;
11870 +}
11871 +
11872 +static uint16_t spi_transfer16(uint16_t val)
11873 +{
11874 + uint8_t txbuf[2];
11875 + uint8_t rxbuf[2];
11876 +
11877 + if (!pisnd_spi_device) {
11878 + printe("pisnd_spi_device null, returning\n");
11879 + return 0;
11880 + }
11881 +
11882 + txbuf[0] = val >> 8;
11883 + txbuf[1] = val & 0xff;
11884 +
11885 + spi_transfer(txbuf, rxbuf, sizeof(txbuf));
11886 +
11887 + printd("received: %02x%02x\n", rxbuf[0], rxbuf[1]);
11888 +
11889 + return (rxbuf[0] << 8) | rxbuf[1];
11890 +}
11891 +
11892 +static void spi_transfer(const uint8_t *txbuf, uint8_t *rxbuf, int len)
11893 +{
11894 + int err;
11895 + struct spi_transfer transfer;
11896 + struct spi_message msg;
11897 +
11898 + memset(rxbuf, 0, len);
11899 +
11900 + if (!pisnd_spi_device) {
11901 + printe("pisnd_spi_device null, returning\n");
11902 + return;
11903 + }
11904 +
11905 + spi_message_init(&msg);
11906 +
11907 + memset(&transfer, 0, sizeof(transfer));
11908 +
11909 + transfer.tx_buf = txbuf;
11910 + transfer.rx_buf = rxbuf;
11911 + transfer.len = len;
11912 + transfer.speed_hz = 150000;
11913 + transfer.delay.value = 10;
11914 + transfer.delay.unit = SPI_DELAY_UNIT_USECS;
11915 +
11916 + spi_message_add_tail(&transfer, &msg);
11917 +
11918 + err = spi_sync(pisnd_spi_device, &msg);
11919 +
11920 + if (err < 0) {
11921 + printe("spi_sync error %d\n", err);
11922 + return;
11923 + }
11924 +
11925 + printd("hasMore %d\n", pisnd_spi_has_more());
11926 +}
11927 +
11928 +static int spi_read_bytes(char *dst, size_t length, uint8_t *bytesRead)
11929 +{
11930 + uint16_t rx;
11931 + uint8_t size;
11932 + uint8_t i;
11933 +
11934 + memset(dst, 0, length);
11935 + *bytesRead = 0;
11936 +
11937 + rx = spi_transfer16(0);
11938 + if (!(rx >> 8))
11939 + return -EINVAL;
11940 +
11941 + size = rx & 0xff;
11942 +
11943 + if (size > length)
11944 + return -EINVAL;
11945 +
11946 + for (i = 0; i < size; ++i) {
11947 + rx = spi_transfer16(0);
11948 + if (!(rx >> 8))
11949 + return -EINVAL;
11950 +
11951 + dst[i] = rx & 0xff;
11952 + }
11953 +
11954 + *bytesRead = i;
11955 +
11956 + return 0;
11957 +}
11958 +
11959 +static int spi_device_match(struct device *dev, const void *data)
11960 +{
11961 + struct spi_device *spi = container_of(dev, struct spi_device, dev);
11962 +
11963 + printd(" %s %s %dkHz %d bits mode=0x%02X\n",
11964 + spi->modalias, dev_name(dev), spi->max_speed_hz/1000,
11965 + spi->bits_per_word, spi->mode);
11966 +
11967 + if (strcmp("pisound-spi", spi->modalias) == 0) {
11968 + printi("\tFound!\n");
11969 + return 1;
11970 + }
11971 +
11972 + printe("\tNot found!\n");
11973 + return 0;
11974 +}
11975 +
11976 +static struct spi_device *pisnd_spi_find_device(void)
11977 +{
11978 + struct device *dev;
11979 +
11980 + printi("Searching for spi device...\n");
11981 + dev = bus_find_device(&spi_bus_type, NULL, NULL, spi_device_match);
11982 + if (dev != NULL)
11983 + return container_of(dev, struct spi_device, dev);
11984 + else
11985 + return NULL;
11986 +}
11987 +
11988 +static void pisnd_work_handler(struct work_struct *work)
11989 +{
11990 + enum { TRANSFER_SIZE = 4 };
11991 + enum { PISOUND_OUTPUT_BUFFER_SIZE_MILLIBYTES = 127 * 1000 };
11992 + enum { MIDI_MILLIBYTES_PER_JIFFIE = (3125 * 1000) / HZ };
11993 + int out_buffer_used_millibytes = 0;
11994 + unsigned long now;
11995 + uint8_t val;
11996 + uint8_t txbuf[TRANSFER_SIZE];
11997 + uint8_t rxbuf[TRANSFER_SIZE];
11998 + uint8_t midibuf[TRANSFER_SIZE];
11999 + int i, n;
12000 + bool had_data;
12001 +
12002 + unsigned long last_transfer_at = jiffies;
12003 +
12004 + if (work == &pisnd_work_process) {
12005 + if (pisnd_spi_device == NULL)
12006 + return;
12007 +
12008 + do {
12009 + if (g_midi_output_substream &&
12010 + kfifo_avail(&spi_fifo_out) >= sizeof(midibuf)) {
12011 +
12012 + n = snd_rawmidi_transmit_peek(
12013 + g_midi_output_substream,
12014 + midibuf, sizeof(midibuf)
12015 + );
12016 +
12017 + if (n > 0) {
12018 + for (i = 0; i < n; ++i)
12019 + kfifo_put(
12020 + &spi_fifo_out,
12021 + midibuf[i]
12022 + );
12023 + snd_rawmidi_transmit_ack(
12024 + g_midi_output_substream,
12025 + i
12026 + );
12027 + }
12028 + }
12029 +
12030 + had_data = false;
12031 + memset(txbuf, 0, sizeof(txbuf));
12032 + for (i = 0; i < sizeof(txbuf) &&
12033 + ((out_buffer_used_millibytes+1000 <
12034 + PISOUND_OUTPUT_BUFFER_SIZE_MILLIBYTES) ||
12035 + g_ledFlashDurationChanged);
12036 + i += 2) {
12037 +
12038 + val = 0;
12039 +
12040 + if (g_ledFlashDurationChanged) {
12041 + txbuf[i+0] = 0xf0;
12042 + txbuf[i+1] = g_ledFlashDuration;
12043 + g_ledFlashDuration = 0;
12044 + g_ledFlashDurationChanged = false;
12045 + } else if (kfifo_get(&spi_fifo_out, &val)) {
12046 + txbuf[i+0] = 0x0f;
12047 + txbuf[i+1] = val;
12048 + out_buffer_used_millibytes += 1000;
12049 + }
12050 + }
12051 +
12052 + spi_transfer(txbuf, rxbuf, sizeof(txbuf));
12053 + /* Estimate the Pisound's MIDI output buffer usage, so
12054 + * that we don't overflow it. Space in the buffer should
12055 + * be becoming available at the UART MIDI byte transfer
12056 + * rate.
12057 + */
12058 + now = jiffies;
12059 + if (now != last_transfer_at) {
12060 + out_buffer_used_millibytes -=
12061 + (now - last_transfer_at) *
12062 + MIDI_MILLIBYTES_PER_JIFFIE;
12063 + if (out_buffer_used_millibytes < 0)
12064 + out_buffer_used_millibytes = 0;
12065 + last_transfer_at = now;
12066 + }
12067 +
12068 + for (i = 0; i < sizeof(rxbuf); i += 2) {
12069 + if (rxbuf[i]) {
12070 + kfifo_put(&spi_fifo_in, rxbuf[i+1]);
12071 + if (kfifo_len(&spi_fifo_in) > 16 &&
12072 + g_recvCallback)
12073 + g_recvCallback(g_recvData);
12074 + had_data = true;
12075 + }
12076 + }
12077 + } while (had_data
12078 + || !kfifo_is_empty(&spi_fifo_out)
12079 + || pisnd_spi_has_more()
12080 + || g_ledFlashDurationChanged
12081 + || out_buffer_used_millibytes != 0
12082 + );
12083 +
12084 + if (!kfifo_is_empty(&spi_fifo_in) && g_recvCallback)
12085 + g_recvCallback(g_recvData);
12086 + }
12087 +}
12088 +
12089 +static int pisnd_spi_gpio_init(struct device *dev)
12090 +{
12091 + spi_reset = gpiod_get_index(dev, "reset", 1, GPIOD_ASIS);
12092 + data_available = gpiod_get_index(dev, "data_available", 0, GPIOD_ASIS);
12093 +
12094 + gpiod_direction_output(spi_reset, 1);
12095 + gpiod_direction_input(data_available);
12096 +
12097 + /* Reset the slave. */
12098 + gpiod_set_value(spi_reset, false);
12099 + mdelay(1);
12100 + gpiod_set_value(spi_reset, true);
12101 +
12102 + /* Give time for spi slave to start. */
12103 + mdelay(64);
12104 +
12105 + return 0;
12106 +}
12107 +
12108 +static void pisnd_spi_gpio_uninit(void)
12109 +{
12110 + gpiod_set_value(spi_reset, false);
12111 + gpiod_put(spi_reset);
12112 + spi_reset = NULL;
12113 +
12114 + gpiod_put(data_available);
12115 + data_available = NULL;
12116 +}
12117 +
12118 +static int pisnd_spi_gpio_irq_init(struct device *dev)
12119 +{
12120 + return request_threaded_irq(
12121 + gpiod_to_irq(data_available), NULL,
12122 + data_available_interrupt_handler,
12123 + IRQF_TIMER | IRQF_TRIGGER_RISING | IRQF_ONESHOT,
12124 + "data_available_int",
12125 + NULL
12126 + );
12127 +}
12128 +
12129 +static void pisnd_spi_gpio_irq_uninit(void)
12130 +{
12131 + free_irq(gpiod_to_irq(data_available), NULL);
12132 +}
12133 +
12134 +static int spi_read_info(void)
12135 +{
12136 + uint16_t tmp;
12137 + uint8_t count;
12138 + uint8_t n;
12139 + uint8_t i;
12140 + uint8_t j;
12141 + char buffer[257];
12142 + int ret;
12143 + char *p;
12144 +
12145 + memset(g_serial_num, 0, sizeof(g_serial_num));
12146 + memset(g_fw_version, 0, sizeof(g_fw_version));
12147 + strcpy(g_hw_version, "1.0"); // Assume 1.0 hw version.
12148 + memset(g_id, 0, sizeof(g_id));
12149 +
12150 + tmp = spi_transfer16(0);
12151 +
12152 + if (!(tmp >> 8))
12153 + return -EINVAL;
12154 +
12155 + count = tmp & 0xff;
12156 +
12157 + for (i = 0; i < count; ++i) {
12158 + memset(buffer, 0, sizeof(buffer));
12159 + ret = spi_read_bytes(buffer, sizeof(buffer)-1, &n);
12160 +
12161 + if (ret < 0)
12162 + return ret;
12163 +
12164 + switch (i) {
12165 + case 0:
12166 + if (n != 2)
12167 + return -EINVAL;
12168 +
12169 + snprintf(
12170 + g_fw_version,
12171 + MAX_VERSION_STR_LEN,
12172 + "%x.%02x",
12173 + buffer[0],
12174 + buffer[1]
12175 + );
12176 +
12177 + g_fw_version[MAX_VERSION_STR_LEN-1] = '\0';
12178 + break;
12179 + case 3:
12180 + if (n != 2)
12181 + return -EINVAL;
12182 +
12183 + snprintf(
12184 + g_hw_version,
12185 + MAX_VERSION_STR_LEN,
12186 + "%x.%x",
12187 + buffer[0],
12188 + buffer[1]
12189 + );
12190 +
12191 + g_hw_version[MAX_VERSION_STR_LEN-1] = '\0';
12192 + break;
12193 + case 1:
12194 + if (n >= sizeof(g_serial_num))
12195 + return -EINVAL;
12196 +
12197 + memcpy(g_serial_num, buffer, sizeof(g_serial_num));
12198 + break;
12199 + case 2:
12200 + {
12201 + if (n*2 >= sizeof(g_id))
12202 + return -EINVAL;
12203 +
12204 + p = g_id;
12205 + for (j = 0; j < n; ++j)
12206 + p += sprintf(p, "%02x", buffer[j]);
12207 +
12208 + *p = '\0';
12209 + }
12210 + break;
12211 + default:
12212 + break;
12213 + }
12214 + }
12215 +
12216 + return 0;
12217 +}
12218 +
12219 +static int pisnd_spi_init(struct device *dev)
12220 +{
12221 + int ret;
12222 + struct spi_device *spi;
12223 +
12224 + memset(g_serial_num, 0, sizeof(g_serial_num));
12225 + memset(g_id, 0, sizeof(g_id));
12226 + memset(g_fw_version, 0, sizeof(g_fw_version));
12227 + memset(g_hw_version, 0, sizeof(g_hw_version));
12228 +
12229 + spi = pisnd_spi_find_device();
12230 +
12231 + if (spi != NULL) {
12232 + printd("initializing spi!\n");
12233 + pisnd_spi_device = spi;
12234 + ret = spi_setup(pisnd_spi_device);
12235 + } else {
12236 + printe("SPI device not found, deferring!\n");
12237 + return -EPROBE_DEFER;
12238 + }
12239 +
12240 + ret = pisnd_spi_gpio_init(dev);
12241 +
12242 + if (ret < 0) {
12243 + printe("SPI GPIO init failed: %d\n", ret);
12244 + spi_dev_put(pisnd_spi_device);
12245 + pisnd_spi_device = NULL;
12246 + pisnd_spi_gpio_uninit();
12247 + return ret;
12248 + }
12249 +
12250 + ret = spi_read_info();
12251 +
12252 + if (ret < 0) {
12253 + printe("Reading card info failed: %d\n", ret);
12254 + spi_dev_put(pisnd_spi_device);
12255 + pisnd_spi_device = NULL;
12256 + pisnd_spi_gpio_uninit();
12257 + return ret;
12258 + }
12259 +
12260 + /* Flash the LEDs. */
12261 + spi_transfer16(0xf008);
12262 +
12263 + ret = pisnd_spi_gpio_irq_init(dev);
12264 + if (ret < 0) {
12265 + printe("SPI irq request failed: %d\n", ret);
12266 + spi_dev_put(pisnd_spi_device);
12267 + pisnd_spi_device = NULL;
12268 + pisnd_spi_gpio_irq_uninit();
12269 + pisnd_spi_gpio_uninit();
12270 + }
12271 +
12272 + ret = pisnd_init_workqueues();
12273 + if (ret != 0) {
12274 + printe("Workqueue initialization failed: %d\n", ret);
12275 + spi_dev_put(pisnd_spi_device);
12276 + pisnd_spi_device = NULL;
12277 + pisnd_spi_gpio_irq_uninit();
12278 + pisnd_spi_gpio_uninit();
12279 + pisnd_uninit_workqueues();
12280 + return ret;
12281 + }
12282 +
12283 + if (pisnd_spi_has_more()) {
12284 + printd("data is available, scheduling from init\n");
12285 + pisnd_schedule_process(TASK_PROCESS);
12286 + }
12287 +
12288 + return 0;
12289 +}
12290 +
12291 +static void pisnd_spi_uninit(void)
12292 +{
12293 + pisnd_uninit_workqueues();
12294 +
12295 + spi_dev_put(pisnd_spi_device);
12296 + pisnd_spi_device = NULL;
12297 +
12298 + pisnd_spi_gpio_irq_uninit();
12299 + pisnd_spi_gpio_uninit();
12300 +}
12301 +
12302 +static void pisnd_spi_flash_leds(uint8_t duration)
12303 +{
12304 + g_ledFlashDuration = duration;
12305 + g_ledFlashDurationChanged = true;
12306 + printd("schedule from spi_flash_leds\n");
12307 + pisnd_schedule_process(TASK_PROCESS);
12308 +}
12309 +
12310 +static void pisnd_spi_flush(void)
12311 +{
12312 + while (!kfifo_is_empty(&spi_fifo_out)) {
12313 + pisnd_spi_start();
12314 + flush_workqueue(pisnd_workqueue);
12315 + }
12316 +}
12317 +
12318 +static void pisnd_spi_start(void)
12319 +{
12320 + printd("schedule from spi_start\n");
12321 + pisnd_schedule_process(TASK_PROCESS);
12322 +}
12323 +
12324 +static uint8_t pisnd_spi_recv(uint8_t *buffer, uint8_t length)
12325 +{
12326 + return kfifo_out(&spi_fifo_in, buffer, length);
12327 +}
12328 +
12329 +static void pisnd_spi_set_callback(pisnd_spi_recv_cb cb, void *data)
12330 +{
12331 + g_recvData = data;
12332 + g_recvCallback = cb;
12333 +}
12334 +
12335 +static const char *pisnd_spi_get_serial(void)
12336 +{
12337 + return g_serial_num;
12338 +}
12339 +
12340 +static const char *pisnd_spi_get_id(void)
12341 +{
12342 + return g_id;
12343 +}
12344 +
12345 +static const char *pisnd_spi_get_fw_version(void)
12346 +{
12347 + return g_fw_version;
12348 +}
12349 +
12350 +static const char *pisnd_spi_get_hw_version(void)
12351 +{
12352 + return g_hw_version;
12353 +}
12354 +
12355 +static const struct of_device_id pisound_of_match[] = {
12356 + { .compatible = "blokaslabs,pisound", },
12357 + { .compatible = "blokaslabs,pisound-spi", },
12358 + {},
12359 +};
12360 +
12361 +enum {
12362 + SWITCH = 0,
12363 + VOLUME = 1,
12364 +};
12365 +
12366 +static int pisnd_ctl_info(struct snd_kcontrol *kcontrol,
12367 + struct snd_ctl_elem_info *uinfo)
12368 +{
12369 + if (kcontrol->private_value == SWITCH) {
12370 + uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
12371 + uinfo->count = 1;
12372 + uinfo->value.integer.min = 0;
12373 + uinfo->value.integer.max = 1;
12374 + return 0;
12375 + } else if (kcontrol->private_value == VOLUME) {
12376 + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
12377 + uinfo->count = 1;
12378 + uinfo->value.integer.min = 0;
12379 + uinfo->value.integer.max = 100;
12380 + return 0;
12381 + }
12382 + return -EINVAL;
12383 +}
12384 +
12385 +static int pisnd_ctl_get(struct snd_kcontrol *kcontrol,
12386 + struct snd_ctl_elem_value *ucontrol)
12387 +{
12388 + if (kcontrol->private_value == SWITCH) {
12389 + ucontrol->value.integer.value[0] = 1;
12390 + return 0;
12391 + } else if (kcontrol->private_value == VOLUME) {
12392 + ucontrol->value.integer.value[0] = 100;
12393 + return 0;
12394 + }
12395 +
12396 + return -EINVAL;
12397 +}
12398 +
12399 +static struct snd_kcontrol_new pisnd_ctl[] = {
12400 + {
12401 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12402 + .name = "PCM Playback Switch",
12403 + .index = 0,
12404 + .private_value = SWITCH,
12405 + .access = SNDRV_CTL_ELEM_ACCESS_READ,
12406 + .info = pisnd_ctl_info,
12407 + .get = pisnd_ctl_get,
12408 + },
12409 + {
12410 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12411 + .name = "PCM Playback Volume",
12412 + .index = 0,
12413 + .private_value = VOLUME,
12414 + .access = SNDRV_CTL_ELEM_ACCESS_READ,
12415 + .info = pisnd_ctl_info,
12416 + .get = pisnd_ctl_get,
12417 + },
12418 +};
12419 +
12420 +static int pisnd_ctl_init(struct snd_card *card)
12421 +{
12422 + int err, i;
12423 +
12424 + for (i = 0; i < ARRAY_SIZE(pisnd_ctl); ++i) {
12425 + err = snd_ctl_add(card, snd_ctl_new1(&pisnd_ctl[i], NULL));
12426 + if (err < 0)
12427 + return err;
12428 + }
12429 +
12430 + return 0;
12431 +}
12432 +
12433 +static int pisnd_ctl_uninit(void)
12434 +{
12435 + return 0;
12436 +}
12437 +
12438 +static struct gpio_desc *osr0, *osr1, *osr2;
12439 +static struct gpio_desc *reset;
12440 +static struct gpio_desc *button;
12441 +
12442 +static int pisnd_hw_params(
12443 + struct snd_pcm_substream *substream,
12444 + struct snd_pcm_hw_params *params
12445 + )
12446 +{
12447 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
12448 + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
12449 +
12450 + /* Pisound runs on fixed 32 clock counts per channel,
12451 + * as generated by the master ADC.
12452 + */
12453 + snd_soc_dai_set_bclk_ratio(cpu_dai, 32*2);
12454 +
12455 + printd("rate = %d\n", params_rate(params));
12456 + printd("ch = %d\n", params_channels(params));
12457 + printd("bits = %u\n",
12458 + snd_pcm_format_physical_width(params_format(params)));
12459 + printd("format = %d\n", params_format(params));
12460 +
12461 + gpiod_set_value(reset, false);
12462 +
12463 + switch (params_rate(params)) {
12464 + case 48000:
12465 + gpiod_set_value(osr0, true);
12466 + gpiod_set_value(osr1, false);
12467 + gpiod_set_value(osr2, false);
12468 + break;
12469 + case 96000:
12470 + gpiod_set_value(osr0, true);
12471 + gpiod_set_value(osr1, false);
12472 + gpiod_set_value(osr2, true);
12473 + break;
12474 + case 192000:
12475 + gpiod_set_value(osr0, true);
12476 + gpiod_set_value(osr1, true);
12477 + gpiod_set_value(osr2, true);
12478 + break;
12479 + default:
12480 + printe("Unsupported rate %u!\n", params_rate(params));
12481 + return -EINVAL;
12482 + }
12483 +
12484 + gpiod_set_value(reset, true);
12485 +
12486 + return 0;
12487 +}
12488 +
12489 +static unsigned int rates[3] = {
12490 + 48000, 96000, 192000
12491 +};
12492 +
12493 +static struct snd_pcm_hw_constraint_list constraints_rates = {
12494 + .count = ARRAY_SIZE(rates),
12495 + .list = rates,
12496 + .mask = 0,
12497 +};
12498 +
12499 +static int pisnd_startup(struct snd_pcm_substream *substream)
12500 +{
12501 + int err = snd_pcm_hw_constraint_list(
12502 + substream->runtime,
12503 + 0,
12504 + SNDRV_PCM_HW_PARAM_RATE,
12505 + &constraints_rates
12506 + );
12507 +
12508 + if (err < 0)
12509 + return err;
12510 +
12511 + err = snd_pcm_hw_constraint_single(
12512 + substream->runtime,
12513 + SNDRV_PCM_HW_PARAM_CHANNELS,
12514 + 2
12515 + );
12516 +
12517 + if (err < 0)
12518 + return err;
12519 +
12520 + err = snd_pcm_hw_constraint_mask64(
12521 + substream->runtime,
12522 + SNDRV_PCM_HW_PARAM_FORMAT,
12523 + SNDRV_PCM_FMTBIT_S16_LE |
12524 + SNDRV_PCM_FMTBIT_S24_LE |
12525 + SNDRV_PCM_FMTBIT_S32_LE
12526 + );
12527 +
12528 + if (err < 0)
12529 + return err;
12530 +
12531 + return 0;
12532 +}
12533 +
12534 +static struct snd_soc_ops pisnd_ops = {
12535 + .startup = pisnd_startup,
12536 + .hw_params = pisnd_hw_params,
12537 +};
12538 +
12539 +SND_SOC_DAILINK_DEFS(pisnd,
12540 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
12541 + DAILINK_COMP_ARRAY(COMP_DUMMY()),
12542 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
12543 +
12544 +static struct snd_soc_dai_link pisnd_dai[] = {
12545 + {
12546 + .name = "pisound",
12547 + .stream_name = "pisound",
12548 + .dai_fmt =
12549 + SND_SOC_DAIFMT_I2S |
12550 + SND_SOC_DAIFMT_NB_NF |
12551 + SND_SOC_DAIFMT_CBM_CFM,
12552 + .ops = &pisnd_ops,
12553 + SND_SOC_DAILINK_REG(pisnd),
12554 + },
12555 +};
12556 +
12557 +static int pisnd_card_probe(struct snd_soc_card *card)
12558 +{
12559 + int err = pisnd_midi_init(card->snd_card);
12560 +
12561 + if (err < 0) {
12562 + printe("pisnd_midi_init failed: %d\n", err);
12563 + return err;
12564 + }
12565 +
12566 + err = pisnd_ctl_init(card->snd_card);
12567 + if (err < 0) {
12568 + printe("pisnd_ctl_init failed: %d\n", err);
12569 + return err;
12570 + }
12571 +
12572 + return 0;
12573 +}
12574 +
12575 +static int pisnd_card_remove(struct snd_soc_card *card)
12576 +{
12577 + pisnd_ctl_uninit();
12578 + pisnd_midi_uninit();
12579 + return 0;
12580 +}
12581 +
12582 +static struct snd_soc_card pisnd_card = {
12583 + .name = "pisound",
12584 + .owner = THIS_MODULE,
12585 + .dai_link = pisnd_dai,
12586 + .num_links = ARRAY_SIZE(pisnd_dai),
12587 + .probe = pisnd_card_probe,
12588 + .remove = pisnd_card_remove,
12589 +};
12590 +
12591 +static int pisnd_init_gpio(struct device *dev)
12592 +{
12593 + osr0 = gpiod_get_index(dev, "osr", 0, GPIOD_ASIS);
12594 + osr1 = gpiod_get_index(dev, "osr", 1, GPIOD_ASIS);
12595 + osr2 = gpiod_get_index(dev, "osr", 2, GPIOD_ASIS);
12596 +
12597 + reset = gpiod_get_index(dev, "reset", 0, GPIOD_ASIS);
12598 +
12599 + button = gpiod_get_index(dev, "button", 0, GPIOD_ASIS);
12600 +
12601 + gpiod_direction_output(osr0, 1);
12602 + gpiod_direction_output(osr1, 1);
12603 + gpiod_direction_output(osr2, 1);
12604 + gpiod_direction_output(reset, 1);
12605 +
12606 + gpiod_set_value(reset, false);
12607 + gpiod_set_value(osr0, true);
12608 + gpiod_set_value(osr1, false);
12609 + gpiod_set_value(osr2, false);
12610 + gpiod_set_value(reset, true);
12611 +
12612 + gpiod_export(button, false);
12613 +
12614 + return 0;
12615 +}
12616 +
12617 +static int pisnd_uninit_gpio(void)
12618 +{
12619 + int i;
12620 +
12621 + struct gpio_desc **gpios[] = {
12622 + &osr0, &osr1, &osr2, &reset, &button,
12623 + };
12624 +
12625 + gpiod_unexport(button);
12626 +
12627 + for (i = 0; i < ARRAY_SIZE(gpios); ++i) {
12628 + if (*gpios[i] == NULL) {
12629 + printd("weird, GPIO[%d] is NULL already\n", i);
12630 + continue;
12631 + }
12632 +
12633 + gpiod_put(*gpios[i]);
12634 + *gpios[i] = NULL;
12635 + }
12636 +
12637 + return 0;
12638 +}
12639 +
12640 +static struct kobject *pisnd_kobj;
12641 +
12642 +static ssize_t pisnd_serial_show(
12643 + struct kobject *kobj,
12644 + struct kobj_attribute *attr,
12645 + char *buf
12646 + )
12647 +{
12648 + return sprintf(buf, "%s\n", pisnd_spi_get_serial());
12649 +}
12650 +
12651 +static ssize_t pisnd_id_show(
12652 + struct kobject *kobj,
12653 + struct kobj_attribute *attr,
12654 + char *buf
12655 + )
12656 +{
12657 + return sprintf(buf, "%s\n", pisnd_spi_get_id());
12658 +}
12659 +
12660 +static ssize_t pisnd_fw_version_show(
12661 + struct kobject *kobj,
12662 + struct kobj_attribute *attr,
12663 + char *buf
12664 + )
12665 +{
12666 + return sprintf(buf, "%s\n", pisnd_spi_get_fw_version());
12667 +}
12668 +
12669 +static ssize_t pisnd_hw_version_show(
12670 + struct kobject *kobj,
12671 + struct kobj_attribute *attr,
12672 + char *buf
12673 +)
12674 +{
12675 + return sprintf(buf, "%s\n", pisnd_spi_get_hw_version());
12676 +}
12677 +
12678 +static ssize_t pisnd_led_store(
12679 + struct kobject *kobj,
12680 + struct kobj_attribute *attr,
12681 + const char *buf,
12682 + size_t length
12683 + )
12684 +{
12685 + uint32_t timeout;
12686 + int err;
12687 +
12688 + err = kstrtou32(buf, 10, &timeout);
12689 +
12690 + if (err == 0 && timeout <= 255)
12691 + pisnd_spi_flash_leds(timeout);
12692 +
12693 + return length;
12694 +}
12695 +
12696 +static struct kobj_attribute pisnd_serial_attribute =
12697 + __ATTR(serial, 0444, pisnd_serial_show, NULL);
12698 +static struct kobj_attribute pisnd_id_attribute =
12699 + __ATTR(id, 0444, pisnd_id_show, NULL);
12700 +static struct kobj_attribute pisnd_fw_version_attribute =
12701 + __ATTR(version, 0444, pisnd_fw_version_show, NULL);
12702 +static struct kobj_attribute pisnd_hw_version_attribute =
12703 +__ATTR(hw_version, 0444, pisnd_hw_version_show, NULL);
12704 +static struct kobj_attribute pisnd_led_attribute =
12705 + __ATTR(led, 0644, NULL, pisnd_led_store);
12706 +
12707 +static struct attribute *attrs[] = {
12708 + &pisnd_serial_attribute.attr,
12709 + &pisnd_id_attribute.attr,
12710 + &pisnd_fw_version_attribute.attr,
12711 + &pisnd_hw_version_attribute.attr,
12712 + &pisnd_led_attribute.attr,
12713 + NULL
12714 +};
12715 +
12716 +static struct attribute_group attr_group = { .attrs = attrs };
12717 +
12718 +static int pisnd_probe(struct platform_device *pdev)
12719 +{
12720 + int ret = 0;
12721 + int i;
12722 +
12723 + ret = pisnd_spi_init(&pdev->dev);
12724 + if (ret < 0) {
12725 + printe("pisnd_spi_init failed: %d\n", ret);
12726 + return ret;
12727 + }
12728 +
12729 + printi("Detected Pisound card:\n");
12730 + printi("\tSerial: %s\n", pisnd_spi_get_serial());
12731 + printi("\tFirmware Version: %s\n", pisnd_spi_get_fw_version());
12732 + printi("\tHardware Version: %s\n", pisnd_spi_get_hw_version());
12733 + printi("\tId: %s\n", pisnd_spi_get_id());
12734 +
12735 + pisnd_kobj = kobject_create_and_add("pisound", kernel_kobj);
12736 + if (!pisnd_kobj) {
12737 + pisnd_spi_uninit();
12738 + return -ENOMEM;
12739 + }
12740 +
12741 + ret = sysfs_create_group(pisnd_kobj, &attr_group);
12742 + if (ret < 0) {
12743 + pisnd_spi_uninit();
12744 + kobject_put(pisnd_kobj);
12745 + return -ENOMEM;
12746 + }
12747 +
12748 + pisnd_init_gpio(&pdev->dev);
12749 + pisnd_card.dev = &pdev->dev;
12750 +
12751 + if (pdev->dev.of_node) {
12752 + struct device_node *i2s_node;
12753 +
12754 + i2s_node = of_parse_phandle(
12755 + pdev->dev.of_node,
12756 + "i2s-controller",
12757 + 0
12758 + );
12759 +
12760 + for (i = 0; i < pisnd_card.num_links; ++i) {
12761 + struct snd_soc_dai_link *dai = &pisnd_dai[i];
12762 +
12763 + if (i2s_node) {
12764 + dai->cpus->dai_name = NULL;
12765 + dai->cpus->of_node = i2s_node;
12766 + dai->platforms->name = NULL;
12767 + dai->platforms->of_node = i2s_node;
12768 + dai->stream_name = pisnd_spi_get_serial();
12769 + }
12770 + }
12771 + }
12772 +
12773 + ret = snd_soc_register_card(&pisnd_card);
12774 +
12775 + if (ret < 0) {
12776 + if (ret != -EPROBE_DEFER)
12777 + printe("snd_soc_register_card() failed: %d\n", ret);
12778 + pisnd_uninit_gpio();
12779 + kobject_put(pisnd_kobj);
12780 + pisnd_spi_uninit();
12781 + }
12782 +
12783 + return ret;
12784 +}
12785 +
12786 +static int pisnd_remove(struct platform_device *pdev)
12787 +{
12788 + printi("Unloading.\n");
12789 +
12790 + if (pisnd_kobj) {
12791 + kobject_put(pisnd_kobj);
12792 + pisnd_kobj = NULL;
12793 + }
12794 +
12795 + pisnd_spi_uninit();
12796 +
12797 + /* Turn off */
12798 + gpiod_set_value(reset, false);
12799 + pisnd_uninit_gpio();
12800 +
12801 + snd_soc_unregister_card(&pisnd_card);
12802 + return 0;
12803 +}
12804 +
12805 +MODULE_DEVICE_TABLE(of, pisound_of_match);
12806 +
12807 +static struct platform_driver pisnd_driver = {
12808 + .driver = {
12809 + .name = "snd-rpi-pisound",
12810 + .owner = THIS_MODULE,
12811 + .of_match_table = pisound_of_match,
12812 + },
12813 + .probe = pisnd_probe,
12814 + .remove = pisnd_remove,
12815 +};
12816 +
12817 +module_platform_driver(pisnd_driver);
12818 +
12819 +MODULE_AUTHOR("Giedrius Trainavicius <giedrius@blokas.io>");
12820 +MODULE_DESCRIPTION("ASoC Driver for Pisound, https://blokas.io/pisound");
12821 +MODULE_LICENSE("GPL v2");
12822 --- /dev/null
12823 +++ b/sound/soc/bcm/rpi-cirrus.c
12824 @@ -0,0 +1,1025 @@
12825 +/*
12826 + * ASoC machine driver for Cirrus Logic Audio Card
12827 + * (with WM5102 and WM8804 codecs)
12828 + *
12829 + * Copyright 2015-2017 Matthias Reichl <hias@horus.com>
12830 + *
12831 + * Based on rpi-cirrus-sound-pi driver (c) Wolfson / Cirrus Logic Inc.
12832 + *
12833 + * This program is free software; you can redistribute it and/or modify
12834 + * it under the terms of the GNU General Public License version 2 as
12835 + * published by the Free Software Foundation.
12836 + */
12837 +
12838 +#include <linux/module.h>
12839 +#include <linux/mutex.h>
12840 +#include <linux/slab.h>
12841 +#include <linux/list.h>
12842 +#include <linux/delay.h>
12843 +#include <sound/pcm_params.h>
12844 +
12845 +#include <linux/mfd/arizona/registers.h>
12846 +
12847 +#include "../codecs/wm5102.h"
12848 +#include "../codecs/wm8804.h"
12849 +
12850 +#define WM8804_CLKOUT_HZ 12000000
12851 +
12852 +#define RPI_CIRRUS_DEFAULT_RATE 44100
12853 +#define WM5102_MAX_SYSCLK_1 49152000 /* max sysclk for 4K family */
12854 +#define WM5102_MAX_SYSCLK_2 45158400 /* max sysclk for 11.025K family */
12855 +
12856 +static inline unsigned int calc_sysclk(unsigned int rate)
12857 +{
12858 + return (rate % 4000) ? WM5102_MAX_SYSCLK_2 : WM5102_MAX_SYSCLK_1;
12859 +}
12860 +
12861 +enum {
12862 + DAI_WM5102 = 0,
12863 + DAI_WM8804,
12864 +};
12865 +
12866 +struct rpi_cirrus_priv {
12867 + /* mutex for synchronzing FLL1 access with DAPM */
12868 + struct mutex lock;
12869 + unsigned int card_rate;
12870 + int sync_path_enable;
12871 + int fll1_freq; /* negative means RefClock in spdif rx case */
12872 +
12873 + /* track hw params/free for substreams */
12874 + unsigned int params_set;
12875 + unsigned int min_rate_idx, max_rate_idx;
12876 + unsigned char iec958_status[4];
12877 +};
12878 +
12879 +/* helper functions */
12880 +static inline struct snd_soc_pcm_runtime *get_wm5102_runtime(
12881 + struct snd_soc_card *card) {
12882 + return snd_soc_get_pcm_runtime(card, &card->dai_link[DAI_WM5102]);
12883 +}
12884 +
12885 +static inline struct snd_soc_pcm_runtime *get_wm8804_runtime(
12886 + struct snd_soc_card *card) {
12887 + return snd_soc_get_pcm_runtime(card, &card->dai_link[DAI_WM8804]);
12888 +}
12889 +
12890 +
12891 +struct rate_info {
12892 + unsigned int value;
12893 + char *text;
12894 +};
12895 +
12896 +static struct rate_info min_rates[] = {
12897 + { 0, "off"},
12898 + { 32000, "32kHz"},
12899 + { 44100, "44.1kHz"}
12900 +};
12901 +
12902 +#define NUM_MIN_RATES ARRAY_SIZE(min_rates)
12903 +
12904 +static int rpi_cirrus_min_rate_info(struct snd_kcontrol *kcontrol,
12905 + struct snd_ctl_elem_info *uinfo)
12906 +{
12907 + uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
12908 + uinfo->count = 1;
12909 + uinfo->value.enumerated.items = NUM_MIN_RATES;
12910 +
12911 + if (uinfo->value.enumerated.item >= NUM_MIN_RATES)
12912 + uinfo->value.enumerated.item = NUM_MIN_RATES - 1;
12913 + strcpy(uinfo->value.enumerated.name,
12914 + min_rates[uinfo->value.enumerated.item].text);
12915 + return 0;
12916 +}
12917 +
12918 +static int rpi_cirrus_min_rate_get(struct snd_kcontrol *kcontrol,
12919 + struct snd_ctl_elem_value *ucontrol)
12920 +{
12921 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
12922 + struct rpi_cirrus_priv *priv = snd_soc_card_get_drvdata(card);
12923 +
12924 + ucontrol->value.enumerated.item[0] = priv->min_rate_idx;
12925 + return 0;
12926 +}
12927 +
12928 +static int rpi_cirrus_min_rate_put(struct snd_kcontrol *kcontrol,
12929 + struct snd_ctl_elem_value *ucontrol)
12930 +{
12931 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
12932 + struct rpi_cirrus_priv *priv = snd_soc_card_get_drvdata(card);
12933 + int changed = 0;
12934 +
12935 + if (priv->min_rate_idx != ucontrol->value.enumerated.item[0]) {
12936 + changed = 1;
12937 + priv->min_rate_idx = ucontrol->value.enumerated.item[0];
12938 + }
12939 +
12940 + return changed;
12941 +}
12942 +
12943 +static struct rate_info max_rates[] = {
12944 + { 0, "off"},
12945 + { 48000, "48kHz"},
12946 + { 96000, "96kHz"}
12947 +};
12948 +
12949 +#define NUM_MAX_RATES ARRAY_SIZE(max_rates)
12950 +
12951 +static int rpi_cirrus_max_rate_info(struct snd_kcontrol *kcontrol,
12952 + struct snd_ctl_elem_info *uinfo)
12953 +{
12954 + uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
12955 + uinfo->count = 1;
12956 + uinfo->value.enumerated.items = NUM_MAX_RATES;
12957 + if (uinfo->value.enumerated.item >= NUM_MAX_RATES)
12958 + uinfo->value.enumerated.item = NUM_MAX_RATES - 1;
12959 + strcpy(uinfo->value.enumerated.name,
12960 + max_rates[uinfo->value.enumerated.item].text);
12961 + return 0;
12962 +}
12963 +
12964 +static int rpi_cirrus_max_rate_get(struct snd_kcontrol *kcontrol,
12965 + struct snd_ctl_elem_value *ucontrol)
12966 +{
12967 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
12968 + struct rpi_cirrus_priv *priv = snd_soc_card_get_drvdata(card);
12969 +
12970 + ucontrol->value.enumerated.item[0] = priv->max_rate_idx;
12971 + return 0;
12972 +}
12973 +
12974 +static int rpi_cirrus_max_rate_put(struct snd_kcontrol *kcontrol,
12975 + struct snd_ctl_elem_value *ucontrol)
12976 +{
12977 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
12978 + struct rpi_cirrus_priv *priv = snd_soc_card_get_drvdata(card);
12979 + int changed = 0;
12980 +
12981 + if (priv->max_rate_idx != ucontrol->value.enumerated.item[0]) {
12982 + changed = 1;
12983 + priv->max_rate_idx = ucontrol->value.enumerated.item[0];
12984 + }
12985 +
12986 + return changed;
12987 +}
12988 +
12989 +static int rpi_cirrus_spdif_info(struct snd_kcontrol *kcontrol,
12990 + struct snd_ctl_elem_info *uinfo)
12991 +{
12992 + uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
12993 + uinfo->count = 1;
12994 + return 0;
12995 +}
12996 +
12997 +static int rpi_cirrus_spdif_playback_get(struct snd_kcontrol *kcontrol,
12998 + struct snd_ctl_elem_value *ucontrol)
12999 +{
13000 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
13001 + struct rpi_cirrus_priv *priv = snd_soc_card_get_drvdata(card);
13002 + int i;
13003 +
13004 + for (i = 0; i < 4; i++)
13005 + ucontrol->value.iec958.status[i] = priv->iec958_status[i];
13006 +
13007 + return 0;
13008 +}
13009 +
13010 +static int rpi_cirrus_spdif_playback_put(struct snd_kcontrol *kcontrol,
13011 + struct snd_ctl_elem_value *ucontrol)
13012 +{
13013 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
13014 + struct snd_soc_component *wm8804_component =
13015 + asoc_rtd_to_codec(get_wm8804_runtime(card), 0)->component;
13016 + struct rpi_cirrus_priv *priv = snd_soc_card_get_drvdata(card);
13017 + unsigned char *stat = priv->iec958_status;
13018 + unsigned char *ctrl_stat = ucontrol->value.iec958.status;
13019 + unsigned int mask;
13020 + int i, changed = 0;
13021 +
13022 + for (i = 0; i < 4; i++) {
13023 + mask = (i == 3) ? 0x3f : 0xff;
13024 + if ((ctrl_stat[i] & mask) != (stat[i] & mask)) {
13025 + changed = 1;
13026 + stat[i] = ctrl_stat[i] & mask;
13027 + snd_soc_component_update_bits(wm8804_component,
13028 + WM8804_SPDTX1 + i, mask, stat[i]);
13029 + }
13030 + }
13031 +
13032 + return changed;
13033 +}
13034 +
13035 +static int rpi_cirrus_spdif_mask_get(struct snd_kcontrol *kcontrol,
13036 + struct snd_ctl_elem_value *ucontrol)
13037 +{
13038 + ucontrol->value.iec958.status[0] = 0xff;
13039 + ucontrol->value.iec958.status[1] = 0xff;
13040 + ucontrol->value.iec958.status[2] = 0xff;
13041 + ucontrol->value.iec958.status[3] = 0x3f;
13042 +
13043 + return 0;
13044 +}
13045 +
13046 +static int rpi_cirrus_spdif_capture_get(struct snd_kcontrol *kcontrol,
13047 + struct snd_ctl_elem_value *ucontrol)
13048 +{
13049 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
13050 + struct snd_soc_component *wm8804_component =
13051 + asoc_rtd_to_codec(get_wm8804_runtime(card), 0)->component;
13052 + unsigned int val, mask;
13053 + int i;
13054 +
13055 + for (i = 0; i < 4; i++) {
13056 + val = snd_soc_component_read(wm8804_component,
13057 + WM8804_RXCHAN1 + i);
13058 + mask = (i == 3) ? 0x3f : 0xff;
13059 + ucontrol->value.iec958.status[i] = val & mask;
13060 + }
13061 +
13062 + return 0;
13063 +}
13064 +
13065 +#define SPDIF_FLAG_CTRL(desc, reg, bit, invert) \
13066 +{ \
13067 + .access = SNDRV_CTL_ELEM_ACCESS_READ \
13068 + | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
13069 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
13070 + .name = SNDRV_CTL_NAME_IEC958("", CAPTURE, NONE) \
13071 + desc " Flag", \
13072 + .info = snd_ctl_boolean_mono_info, \
13073 + .get = rpi_cirrus_spdif_status_flag_get, \
13074 + .private_value = \
13075 + (bit) | ((reg) << 8) | ((invert) << 16) \
13076 +}
13077 +
13078 +static int rpi_cirrus_spdif_status_flag_get(struct snd_kcontrol *kcontrol,
13079 + struct snd_ctl_elem_value *ucontrol)
13080 +{
13081 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
13082 + struct snd_soc_component *wm8804_component =
13083 + asoc_rtd_to_codec(get_wm8804_runtime(card), 0)->component;
13084 +
13085 + unsigned int bit = kcontrol->private_value & 0xff;
13086 + unsigned int reg = (kcontrol->private_value >> 8) & 0xff;
13087 + unsigned int invert = (kcontrol->private_value >> 16) & 0xff;
13088 + unsigned int val;
13089 + bool flag;
13090 +
13091 + val = snd_soc_component_read(wm8804_component, reg);
13092 +
13093 + flag = val & (1 << bit);
13094 +
13095 + ucontrol->value.integer.value[0] = invert ? !flag : flag;
13096 +
13097 + return 0;
13098 +}
13099 +
13100 +static const char * const recovered_frequency_texts[] = {
13101 + "176.4/192 kHz",
13102 + "88.2/96 kHz",
13103 + "44.1/48 kHz",
13104 + "32 kHz"
13105 +};
13106 +
13107 +#define NUM_RECOVERED_FREQUENCIES \
13108 + ARRAY_SIZE(recovered_frequency_texts)
13109 +
13110 +static int rpi_cirrus_recovered_frequency_info(struct snd_kcontrol *kcontrol,
13111 + struct snd_ctl_elem_info *uinfo)
13112 +{
13113 + uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
13114 + uinfo->count = 1;
13115 + uinfo->value.enumerated.items = NUM_RECOVERED_FREQUENCIES;
13116 + if (uinfo->value.enumerated.item >= NUM_RECOVERED_FREQUENCIES)
13117 + uinfo->value.enumerated.item = NUM_RECOVERED_FREQUENCIES - 1;
13118 + strcpy(uinfo->value.enumerated.name,
13119 + recovered_frequency_texts[uinfo->value.enumerated.item]);
13120 + return 0;
13121 +}
13122 +
13123 +static int rpi_cirrus_recovered_frequency_get(struct snd_kcontrol *kcontrol,
13124 + struct snd_ctl_elem_value *ucontrol)
13125 +{
13126 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
13127 + struct snd_soc_component *wm8804_component =
13128 + asoc_rtd_to_codec(get_wm8804_runtime(card), 0)->component;
13129 + unsigned int val;
13130 +
13131 + val = snd_soc_component_read(wm8804_component, WM8804_SPDSTAT);
13132 +
13133 + ucontrol->value.enumerated.item[0] = (val >> 4) & 0x03;
13134 + return 0;
13135 +}
13136 +
13137 +static const struct snd_kcontrol_new rpi_cirrus_controls[] = {
13138 + {
13139 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13140 + .name = "Min Sample Rate",
13141 + .info = rpi_cirrus_min_rate_info,
13142 + .get = rpi_cirrus_min_rate_get,
13143 + .put = rpi_cirrus_min_rate_put,
13144 + },
13145 + {
13146 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13147 + .name = "Max Sample Rate",
13148 + .info = rpi_cirrus_max_rate_info,
13149 + .get = rpi_cirrus_max_rate_get,
13150 + .put = rpi_cirrus_max_rate_put,
13151 + },
13152 + {
13153 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13154 + .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT),
13155 + .info = rpi_cirrus_spdif_info,
13156 + .get = rpi_cirrus_spdif_playback_get,
13157 + .put = rpi_cirrus_spdif_playback_put,
13158 + },
13159 + {
13160 + .access = SNDRV_CTL_ELEM_ACCESS_READ
13161 + | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
13162 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13163 + .name = SNDRV_CTL_NAME_IEC958("", CAPTURE, DEFAULT),
13164 + .info = rpi_cirrus_spdif_info,
13165 + .get = rpi_cirrus_spdif_capture_get,
13166 + },
13167 + {
13168 + .access = SNDRV_CTL_ELEM_ACCESS_READ,
13169 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13170 + .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, MASK),
13171 + .info = rpi_cirrus_spdif_info,
13172 + .get = rpi_cirrus_spdif_mask_get,
13173 + },
13174 + {
13175 + .access = SNDRV_CTL_ELEM_ACCESS_READ
13176 + | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
13177 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13178 + .name = SNDRV_CTL_NAME_IEC958("", CAPTURE, NONE)
13179 + "Recovered Frequency",
13180 + .info = rpi_cirrus_recovered_frequency_info,
13181 + .get = rpi_cirrus_recovered_frequency_get,
13182 + },
13183 + SPDIF_FLAG_CTRL("Audio", WM8804_SPDSTAT, 0, 1),
13184 + SPDIF_FLAG_CTRL("Non-PCM", WM8804_SPDSTAT, 1, 0),
13185 + SPDIF_FLAG_CTRL("Copyright", WM8804_SPDSTAT, 2, 1),
13186 + SPDIF_FLAG_CTRL("De-Emphasis", WM8804_SPDSTAT, 3, 0),
13187 + SPDIF_FLAG_CTRL("Lock", WM8804_SPDSTAT, 6, 1),
13188 + SPDIF_FLAG_CTRL("Invalid", WM8804_INTSTAT, 1, 0),
13189 + SPDIF_FLAG_CTRL("TransErr", WM8804_INTSTAT, 3, 0),
13190 +};
13191 +
13192 +static const char * const linein_micbias_texts[] = {
13193 + "off", "on",
13194 +};
13195 +
13196 +static SOC_ENUM_SINGLE_VIRT_DECL(linein_micbias_enum,
13197 + linein_micbias_texts);
13198 +
13199 +static const struct snd_kcontrol_new linein_micbias_mux =
13200 + SOC_DAPM_ENUM("Route", linein_micbias_enum);
13201 +
13202 +static int rpi_cirrus_spdif_rx_enable_event(struct snd_soc_dapm_widget *w,
13203 + struct snd_kcontrol *kcontrol, int event);
13204 +
13205 +const struct snd_soc_dapm_widget rpi_cirrus_dapm_widgets[] = {
13206 + SND_SOC_DAPM_MIC("DMIC", NULL),
13207 + SND_SOC_DAPM_MIC("Headset Mic", NULL),
13208 + SND_SOC_DAPM_INPUT("Line Input"),
13209 + SND_SOC_DAPM_MIC("Line Input with Micbias", NULL),
13210 + SND_SOC_DAPM_MUX("Line Input Micbias", SND_SOC_NOPM, 0, 0,
13211 + &linein_micbias_mux),
13212 + SND_SOC_DAPM_INPUT("dummy SPDIF in"),
13213 + SND_SOC_DAPM_PGA_E("dummy SPDIFRX", SND_SOC_NOPM, 0, 0, NULL, 0,
13214 + rpi_cirrus_spdif_rx_enable_event,
13215 + SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
13216 + SND_SOC_DAPM_INPUT("Dummy Input"),
13217 + SND_SOC_DAPM_OUTPUT("Dummy Output"),
13218 +};
13219 +
13220 +const struct snd_soc_dapm_route rpi_cirrus_dapm_routes[] = {
13221 + { "IN1L", NULL, "Headset Mic" },
13222 + { "IN1R", NULL, "Headset Mic" },
13223 + { "Headset Mic", NULL, "MICBIAS1" },
13224 +
13225 + { "IN2L", NULL, "DMIC" },
13226 + { "IN2R", NULL, "DMIC" },
13227 + { "DMIC", NULL, "MICBIAS2" },
13228 +
13229 + { "IN3L", NULL, "Line Input Micbias" },
13230 + { "IN3R", NULL, "Line Input Micbias" },
13231 +
13232 + { "Line Input Micbias", "off", "Line Input" },
13233 + { "Line Input Micbias", "on", "Line Input with Micbias" },
13234 +
13235 + /* Make sure MICVDD is enabled, otherwise we get noise */
13236 + { "Line Input", NULL, "MICVDD" },
13237 + { "Line Input with Micbias", NULL, "MICBIAS3" },
13238 +
13239 + /* Dummy routes to check whether SPDIF RX is enabled or not */
13240 + {"dummy SPDIFRX", NULL, "dummy SPDIF in"},
13241 + {"AIFTX", NULL, "dummy SPDIFRX"},
13242 +
13243 + /*
13244 + * Dummy routes to keep wm5102 from staying off on
13245 + * playback/capture if all mixers are off.
13246 + */
13247 + { "Dummy Output", NULL, "AIF1RX1" },
13248 + { "Dummy Output", NULL, "AIF1RX2" },
13249 + { "AIF1TX1", NULL, "Dummy Input" },
13250 + { "AIF1TX2", NULL, "Dummy Input" },
13251 +};
13252 +
13253 +static int rpi_cirrus_clear_flls(struct snd_soc_card *card,
13254 + struct snd_soc_component *wm5102_component) {
13255 +
13256 + int ret1, ret2;
13257 +
13258 + ret1 = snd_soc_component_set_pll(wm5102_component,
13259 + WM5102_FLL1, ARIZONA_FLL_SRC_NONE, 0, 0);
13260 + ret2 = snd_soc_component_set_pll(wm5102_component,
13261 + WM5102_FLL1_REFCLK, ARIZONA_FLL_SRC_NONE, 0, 0);
13262 +
13263 + if (ret1) {
13264 + dev_warn(card->dev,
13265 + "setting FLL1 to zero failed: %d\n", ret1);
13266 + return ret1;
13267 + }
13268 + if (ret2) {
13269 + dev_warn(card->dev,
13270 + "setting FLL1_REFCLK to zero failed: %d\n", ret2);
13271 + return ret2;
13272 + }
13273 + return 0;
13274 +}
13275 +
13276 +static int rpi_cirrus_set_fll(struct snd_soc_card *card,
13277 + struct snd_soc_component *wm5102_component, unsigned int clk_freq)
13278 +{
13279 + int ret = snd_soc_component_set_pll(wm5102_component,
13280 + WM5102_FLL1,
13281 + ARIZONA_CLK_SRC_MCLK1,
13282 + WM8804_CLKOUT_HZ,
13283 + clk_freq);
13284 + if (ret)
13285 + dev_err(card->dev, "Failed to set FLL1 to %d: %d\n",
13286 + clk_freq, ret);
13287 +
13288 + usleep_range(1000, 2000);
13289 + return ret;
13290 +}
13291 +
13292 +static int rpi_cirrus_set_fll_refclk(struct snd_soc_card *card,
13293 + struct snd_soc_component *wm5102_component,
13294 + unsigned int clk_freq, unsigned int aif2_freq)
13295 +{
13296 + int ret = snd_soc_component_set_pll(wm5102_component,
13297 + WM5102_FLL1_REFCLK,
13298 + ARIZONA_CLK_SRC_MCLK1,
13299 + WM8804_CLKOUT_HZ,
13300 + clk_freq);
13301 + if (ret) {
13302 + dev_err(card->dev,
13303 + "Failed to set FLL1_REFCLK to %d: %d\n",
13304 + clk_freq, ret);
13305 + return ret;
13306 + }
13307 +
13308 + ret = snd_soc_component_set_pll(wm5102_component,
13309 + WM5102_FLL1,
13310 + ARIZONA_CLK_SRC_AIF2BCLK,
13311 + aif2_freq, clk_freq);
13312 + if (ret)
13313 + dev_err(card->dev,
13314 + "Failed to set FLL1 with Sync Clock %d to %d: %d\n",
13315 + aif2_freq, clk_freq, ret);
13316 +
13317 + usleep_range(1000, 2000);
13318 + return ret;
13319 +}
13320 +
13321 +static int rpi_cirrus_spdif_rx_enable_event(struct snd_soc_dapm_widget *w,
13322 + struct snd_kcontrol *kcontrol, int event)
13323 +{
13324 + struct snd_soc_card *card = w->dapm->card;
13325 + struct rpi_cirrus_priv *priv = snd_soc_card_get_drvdata(card);
13326 + struct snd_soc_component *wm5102_component =
13327 + asoc_rtd_to_codec(get_wm5102_runtime(card), 0)->component;
13328 +
13329 + unsigned int clk_freq, aif2_freq;
13330 + int ret = 0;
13331 +
13332 + switch (event) {
13333 + case SND_SOC_DAPM_POST_PMU:
13334 + mutex_lock(&priv->lock);
13335 +
13336 + /* Enable sync path in case of SPDIF capture use case */
13337 +
13338 + clk_freq = calc_sysclk(priv->card_rate);
13339 + aif2_freq = 64 * priv->card_rate;
13340 +
13341 + dev_dbg(card->dev,
13342 + "spdif_rx: changing FLL1 to use Ref Clock clk: %d spdif: %d\n",
13343 + clk_freq, aif2_freq);
13344 +
13345 + ret = rpi_cirrus_clear_flls(card, wm5102_component);
13346 + if (ret) {
13347 + dev_err(card->dev, "spdif_rx: failed to clear FLLs\n");
13348 + goto out;
13349 + }
13350 +
13351 + ret = rpi_cirrus_set_fll_refclk(card, wm5102_component,
13352 + clk_freq, aif2_freq);
13353 +
13354 + if (ret) {
13355 + dev_err(card->dev, "spdif_rx: failed to set FLLs\n");
13356 + goto out;
13357 + }
13358 +
13359 + /* set to negative to indicate we're doing spdif rx */
13360 + priv->fll1_freq = -clk_freq;
13361 + priv->sync_path_enable = 1;
13362 + break;
13363 +
13364 + case SND_SOC_DAPM_POST_PMD:
13365 + mutex_lock(&priv->lock);
13366 + priv->sync_path_enable = 0;
13367 + break;
13368 +
13369 + default:
13370 + return 0;
13371 + }
13372 +
13373 +out:
13374 + mutex_unlock(&priv->lock);
13375 + return ret;
13376 +}
13377 +
13378 +static int rpi_cirrus_set_bias_level(struct snd_soc_card *card,
13379 + struct snd_soc_dapm_context *dapm,
13380 + enum snd_soc_bias_level level)
13381 +{
13382 + struct rpi_cirrus_priv *priv = snd_soc_card_get_drvdata(card);
13383 + struct snd_soc_pcm_runtime *wm5102_runtime = get_wm5102_runtime(card);
13384 + struct snd_soc_component *wm5102_component =
13385 + asoc_rtd_to_codec(wm5102_runtime, 0)->component;
13386 +
13387 + int ret = 0;
13388 + unsigned int clk_freq;
13389 +
13390 + if (dapm->dev != asoc_rtd_to_codec(wm5102_runtime, 0)->dev)
13391 + return 0;
13392 +
13393 + switch (level) {
13394 + case SND_SOC_BIAS_PREPARE:
13395 + if (dapm->bias_level == SND_SOC_BIAS_ON)
13396 + break;
13397 +
13398 + mutex_lock(&priv->lock);
13399 +
13400 + if (!priv->sync_path_enable) {
13401 + clk_freq = calc_sysclk(priv->card_rate);
13402 +
13403 + dev_dbg(card->dev,
13404 + "set_bias: changing FLL1 from %d to %d\n",
13405 + priv->fll1_freq, clk_freq);
13406 +
13407 + ret = rpi_cirrus_set_fll(card,
13408 + wm5102_component, clk_freq);
13409 + if (ret)
13410 + dev_err(card->dev,
13411 + "set_bias: Failed to set FLL1\n");
13412 + else
13413 + priv->fll1_freq = clk_freq;
13414 + }
13415 + mutex_unlock(&priv->lock);
13416 + break;
13417 + default:
13418 + break;
13419 + }
13420 +
13421 + return ret;
13422 +}
13423 +
13424 +static int rpi_cirrus_set_bias_level_post(struct snd_soc_card *card,
13425 + struct snd_soc_dapm_context *dapm,
13426 + enum snd_soc_bias_level level)
13427 +{
13428 + struct rpi_cirrus_priv *priv = snd_soc_card_get_drvdata(card);
13429 + struct snd_soc_pcm_runtime *wm5102_runtime = get_wm5102_runtime(card);
13430 + struct snd_soc_component *wm5102_component =
13431 + asoc_rtd_to_codec(wm5102_runtime, 0)->component;
13432 +
13433 + if (dapm->dev != asoc_rtd_to_codec(wm5102_runtime, 0)->dev)
13434 + return 0;
13435 +
13436 + switch (level) {
13437 + case SND_SOC_BIAS_STANDBY:
13438 + mutex_lock(&priv->lock);
13439 +
13440 + dev_dbg(card->dev,
13441 + "set_bias_post: changing FLL1 from %d to off\n",
13442 + priv->fll1_freq);
13443 +
13444 + if (rpi_cirrus_clear_flls(card, wm5102_component))
13445 + dev_err(card->dev,
13446 + "set_bias_post: failed to clear FLLs\n");
13447 + else
13448 + priv->fll1_freq = 0;
13449 +
13450 + mutex_unlock(&priv->lock);
13451 +
13452 + break;
13453 + default:
13454 + break;
13455 + }
13456 +
13457 + return 0;
13458 +}
13459 +
13460 +static int rpi_cirrus_set_wm8804_pll(struct snd_soc_card *card,
13461 + struct snd_soc_dai *wm8804_dai, unsigned int rate)
13462 +{
13463 + int ret;
13464 +
13465 + /* use 256fs */
13466 + unsigned int clk_freq = rate * 256;
13467 +
13468 + ret = snd_soc_dai_set_pll(wm8804_dai, 0, 0,
13469 + WM8804_CLKOUT_HZ, clk_freq);
13470 + if (ret) {
13471 + dev_err(card->dev,
13472 + "Failed to set WM8804 PLL to %d: %d\n", clk_freq, ret);
13473 + return ret;
13474 + }
13475 +
13476 + /* Set MCLK as PLL Output */
13477 + ret = snd_soc_dai_set_sysclk(wm8804_dai,
13478 + WM8804_TX_CLKSRC_PLL, clk_freq, 0);
13479 + if (ret) {
13480 + dev_err(card->dev,
13481 + "Failed to set MCLK as PLL Output: %d\n", ret);
13482 + return ret;
13483 + }
13484 +
13485 + return ret;
13486 +}
13487 +
13488 +static int rpi_cirrus_startup(struct snd_pcm_substream *substream)
13489 +{
13490 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
13491 + struct snd_soc_card *card = rtd->card;
13492 + struct rpi_cirrus_priv *priv = snd_soc_card_get_drvdata(card);
13493 + unsigned int min_rate = min_rates[priv->min_rate_idx].value;
13494 + unsigned int max_rate = max_rates[priv->max_rate_idx].value;
13495 +
13496 + if (min_rate || max_rate) {
13497 + if (max_rate == 0)
13498 + max_rate = UINT_MAX;
13499 +
13500 + dev_dbg(card->dev,
13501 + "startup: limiting rate to %u-%u\n",
13502 + min_rate, max_rate);
13503 +
13504 + snd_pcm_hw_constraint_minmax(substream->runtime,
13505 + SNDRV_PCM_HW_PARAM_RATE, min_rate, max_rate);
13506 + }
13507 +
13508 + return 0;
13509 +}
13510 +
13511 +static struct snd_soc_pcm_stream rpi_cirrus_dai_link2_params = {
13512 + .formats = SNDRV_PCM_FMTBIT_S24_LE,
13513 + .channels_min = 2,
13514 + .channels_max = 2,
13515 + .rate_min = RPI_CIRRUS_DEFAULT_RATE,
13516 + .rate_max = RPI_CIRRUS_DEFAULT_RATE,
13517 +};
13518 +
13519 +static int rpi_cirrus_hw_params(struct snd_pcm_substream *substream,
13520 + struct snd_pcm_hw_params *params)
13521 +{
13522 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
13523 + struct snd_soc_card *card = rtd->card;
13524 + struct rpi_cirrus_priv *priv = snd_soc_card_get_drvdata(card);
13525 + struct snd_soc_dai *bcm_i2s_dai = asoc_rtd_to_cpu(rtd, 0);
13526 + struct snd_soc_component *wm5102_component = asoc_rtd_to_codec(rtd, 0)->component;
13527 + struct snd_soc_dai *wm8804_dai = asoc_rtd_to_codec(get_wm8804_runtime(card), 0);
13528 +
13529 + int ret;
13530 +
13531 + unsigned int width = snd_pcm_format_physical_width(
13532 + params_format(params));
13533 + unsigned int rate = params_rate(params);
13534 + unsigned int clk_freq = calc_sysclk(rate);
13535 +
13536 + mutex_lock(&priv->lock);
13537 +
13538 + dev_dbg(card->dev, "hw_params: setting rate to %d\n", rate);
13539 +
13540 + ret = snd_soc_dai_set_bclk_ratio(bcm_i2s_dai, 2 * width);
13541 + if (ret) {
13542 + dev_err(card->dev, "set_bclk_ratio failed: %d\n", ret);
13543 + goto out;
13544 + }
13545 +
13546 + ret = snd_soc_dai_set_tdm_slot(asoc_rtd_to_codec(rtd, 0), 0x03, 0x03, 2, width);
13547 + if (ret) {
13548 + dev_err(card->dev, "set_tdm_slot failed: %d\n", ret);
13549 + goto out;
13550 + }
13551 +
13552 + /* WM8804 supports sample rates from 32k only */
13553 + if (rate >= 32000) {
13554 + ret = rpi_cirrus_set_wm8804_pll(card, wm8804_dai, rate);
13555 + if (ret)
13556 + goto out;
13557 + }
13558 +
13559 + ret = snd_soc_component_set_sysclk(wm5102_component,
13560 + ARIZONA_CLK_SYSCLK,
13561 + ARIZONA_CLK_SRC_FLL1,
13562 + clk_freq,
13563 + SND_SOC_CLOCK_IN);
13564 + if (ret) {
13565 + dev_err(card->dev, "Failed to set SYSCLK: %d\n", ret);
13566 + goto out;
13567 + }
13568 +
13569 + if ((priv->fll1_freq > 0) && (priv->fll1_freq != clk_freq)) {
13570 + dev_dbg(card->dev,
13571 + "hw_params: changing FLL1 from %d to %d\n",
13572 + priv->fll1_freq, clk_freq);
13573 +
13574 + if (rpi_cirrus_clear_flls(card, wm5102_component)) {
13575 + dev_err(card->dev, "hw_params: failed to clear FLLs\n");
13576 + goto out;
13577 + }
13578 +
13579 + if (rpi_cirrus_set_fll(card, wm5102_component, clk_freq)) {
13580 + dev_err(card->dev, "hw_params: failed to set FLL\n");
13581 + goto out;
13582 + }
13583 +
13584 + priv->fll1_freq = clk_freq;
13585 + }
13586 +
13587 + priv->card_rate = rate;
13588 + rpi_cirrus_dai_link2_params.rate_min = rate;
13589 + rpi_cirrus_dai_link2_params.rate_max = rate;
13590 +
13591 + priv->params_set |= 1 << substream->stream;
13592 +
13593 +out:
13594 + mutex_unlock(&priv->lock);
13595 +
13596 + return ret;
13597 +}
13598 +
13599 +static int rpi_cirrus_hw_free(struct snd_pcm_substream *substream)
13600 +{
13601 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
13602 + struct snd_soc_card *card = rtd->card;
13603 + struct rpi_cirrus_priv *priv = snd_soc_card_get_drvdata(card);
13604 + struct snd_soc_component *wm5102_component = asoc_rtd_to_codec(rtd, 0)->component;
13605 + int ret;
13606 + unsigned int old_params_set = priv->params_set;
13607 +
13608 + priv->params_set &= ~(1 << substream->stream);
13609 +
13610 + /* disable sysclk if this was the last open stream */
13611 + if (priv->params_set == 0 && old_params_set) {
13612 + dev_dbg(card->dev,
13613 + "hw_free: Setting SYSCLK to Zero\n");
13614 +
13615 + ret = snd_soc_component_set_sysclk(wm5102_component,
13616 + ARIZONA_CLK_SYSCLK,
13617 + ARIZONA_CLK_SRC_FLL1,
13618 + 0,
13619 + SND_SOC_CLOCK_IN);
13620 + if (ret)
13621 + dev_err(card->dev,
13622 + "hw_free: Failed to set SYSCLK to Zero: %d\n",
13623 + ret);
13624 + }
13625 + return 0;
13626 +}
13627 +
13628 +static int rpi_cirrus_init_wm5102(struct snd_soc_pcm_runtime *rtd)
13629 +{
13630 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
13631 + int ret;
13632 +
13633 + /* no 32kHz input, derive it from sysclk if needed */
13634 + snd_soc_component_update_bits(component,
13635 + ARIZONA_CLOCK_32K_1, ARIZONA_CLK_32K_SRC_MASK, 2);
13636 +
13637 + if (rpi_cirrus_clear_flls(rtd->card, component))
13638 + dev_warn(rtd->card->dev,
13639 + "init_wm5102: failed to clear FLLs\n");
13640 +
13641 + ret = snd_soc_component_set_sysclk(component,
13642 + ARIZONA_CLK_SYSCLK, ARIZONA_CLK_SRC_FLL1,
13643 + 0, SND_SOC_CLOCK_IN);
13644 + if (ret) {
13645 + dev_err(rtd->card->dev,
13646 + "Failed to set SYSCLK to Zero: %d\n", ret);
13647 + return ret;
13648 + }
13649 +
13650 + return 0;
13651 +}
13652 +
13653 +static int rpi_cirrus_init_wm8804(struct snd_soc_pcm_runtime *rtd)
13654 +{
13655 + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
13656 + struct snd_soc_component *component = codec_dai->component;
13657 + struct snd_soc_card *card = rtd->card;
13658 + struct rpi_cirrus_priv *priv = snd_soc_card_get_drvdata(card);
13659 + unsigned int val, mask;
13660 + int i, ret;
13661 +
13662 + for (i = 0; i < 4; i++) {
13663 + val = snd_soc_component_read(component,
13664 + WM8804_SPDTX1 + i);
13665 + mask = (i == 3) ? 0x3f : 0xff;
13666 + priv->iec958_status[i] = val & mask;
13667 + }
13668 +
13669 + /* Setup for 256fs */
13670 + ret = snd_soc_dai_set_clkdiv(codec_dai,
13671 + WM8804_MCLK_DIV, WM8804_MCLKDIV_256FS);
13672 + if (ret) {
13673 + dev_err(card->dev,
13674 + "init_wm8804: Failed to set MCLK_DIV to 256fs: %d\n",
13675 + ret);
13676 + return ret;
13677 + }
13678 +
13679 + /* Output OSC on CLKOUT */
13680 + ret = snd_soc_dai_set_sysclk(codec_dai,
13681 + WM8804_CLKOUT_SRC_OSCCLK, WM8804_CLKOUT_HZ, 0);
13682 + if (ret)
13683 + dev_err(card->dev,
13684 + "init_wm8804: Failed to set CLKOUT as OSC Frequency: %d\n",
13685 + ret);
13686 +
13687 + /* Init PLL with default samplerate */
13688 + ret = rpi_cirrus_set_wm8804_pll(card, codec_dai,
13689 + RPI_CIRRUS_DEFAULT_RATE);
13690 + if (ret)
13691 + dev_err(card->dev,
13692 + "init_wm8804: Failed to setup PLL for %dHz: %d\n",
13693 + RPI_CIRRUS_DEFAULT_RATE, ret);
13694 +
13695 + return ret;
13696 +}
13697 +
13698 +static struct snd_soc_ops rpi_cirrus_ops = {
13699 + .startup = rpi_cirrus_startup,
13700 + .hw_params = rpi_cirrus_hw_params,
13701 + .hw_free = rpi_cirrus_hw_free,
13702 +};
13703 +
13704 +SND_SOC_DAILINK_DEFS(wm5102,
13705 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
13706 + DAILINK_COMP_ARRAY(COMP_CODEC("wm5102-codec", "wm5102-aif1")),
13707 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
13708 +
13709 +SND_SOC_DAILINK_DEFS(wm8804,
13710 + DAILINK_COMP_ARRAY(COMP_CPU("wm5102-aif2")),
13711 + DAILINK_COMP_ARRAY(COMP_CODEC("wm8804.1-003b", "wm8804-spdif")));
13712 +
13713 +static struct snd_soc_dai_link rpi_cirrus_dai[] = {
13714 + [DAI_WM5102] = {
13715 + .name = "WM5102",
13716 + .stream_name = "WM5102 AiFi",
13717 + .dai_fmt = SND_SOC_DAIFMT_I2S
13718 + | SND_SOC_DAIFMT_NB_NF
13719 + | SND_SOC_DAIFMT_CBM_CFM,
13720 + .ops = &rpi_cirrus_ops,
13721 + .init = rpi_cirrus_init_wm5102,
13722 + SND_SOC_DAILINK_REG(wm5102),
13723 + },
13724 + [DAI_WM8804] = {
13725 + .name = "WM5102 SPDIF",
13726 + .stream_name = "SPDIF Tx/Rx",
13727 + .dai_fmt = SND_SOC_DAIFMT_I2S
13728 + | SND_SOC_DAIFMT_NB_NF
13729 + | SND_SOC_DAIFMT_CBM_CFM,
13730 + .ignore_suspend = 1,
13731 + .params = &rpi_cirrus_dai_link2_params,
13732 + .init = rpi_cirrus_init_wm8804,
13733 + SND_SOC_DAILINK_REG(wm8804),
13734 + },
13735 +};
13736 +
13737 +
13738 +static int rpi_cirrus_late_probe(struct snd_soc_card *card)
13739 +{
13740 + struct rpi_cirrus_priv *priv = snd_soc_card_get_drvdata(card);
13741 + struct snd_soc_pcm_runtime *wm5102_runtime = get_wm5102_runtime(card);
13742 + struct snd_soc_pcm_runtime *wm8804_runtime = get_wm8804_runtime(card);
13743 + int ret;
13744 +
13745 + dev_dbg(card->dev, "iec958_bits: %02x %02x %02x %02x\n",
13746 + priv->iec958_status[0],
13747 + priv->iec958_status[1],
13748 + priv->iec958_status[2],
13749 + priv->iec958_status[3]);
13750 +
13751 + ret = snd_soc_dai_set_sysclk(
13752 + asoc_rtd_to_codec(wm5102_runtime, 0), ARIZONA_CLK_SYSCLK, 0, 0);
13753 + if (ret) {
13754 + dev_err(card->dev,
13755 + "Failed to set WM5102 codec dai clk domain: %d\n", ret);
13756 + return ret;
13757 + }
13758 +
13759 + ret = snd_soc_dai_set_sysclk(
13760 + asoc_rtd_to_cpu(wm8804_runtime, 0), ARIZONA_CLK_SYSCLK, 0, 0);
13761 + if (ret)
13762 + dev_err(card->dev,
13763 + "Failed to set WM8804 codec dai clk domain: %d\n", ret);
13764 +
13765 + return ret;
13766 +}
13767 +
13768 +/* audio machine driver */
13769 +static struct snd_soc_card rpi_cirrus_card = {
13770 + .name = "RPi-Cirrus",
13771 + .driver_name = "RPiCirrus",
13772 + .owner = THIS_MODULE,
13773 + .dai_link = rpi_cirrus_dai,
13774 + .num_links = ARRAY_SIZE(rpi_cirrus_dai),
13775 + .late_probe = rpi_cirrus_late_probe,
13776 + .controls = rpi_cirrus_controls,
13777 + .num_controls = ARRAY_SIZE(rpi_cirrus_controls),
13778 + .dapm_widgets = rpi_cirrus_dapm_widgets,
13779 + .num_dapm_widgets = ARRAY_SIZE(rpi_cirrus_dapm_widgets),
13780 + .dapm_routes = rpi_cirrus_dapm_routes,
13781 + .num_dapm_routes = ARRAY_SIZE(rpi_cirrus_dapm_routes),
13782 + .set_bias_level = rpi_cirrus_set_bias_level,
13783 + .set_bias_level_post = rpi_cirrus_set_bias_level_post,
13784 +};
13785 +
13786 +static int rpi_cirrus_probe(struct platform_device *pdev)
13787 +{
13788 + int ret = 0;
13789 + struct rpi_cirrus_priv *priv;
13790 + struct device_node *i2s_node;
13791 +
13792 + priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
13793 + if (!priv)
13794 + return -ENOMEM;
13795 +
13796 + priv->min_rate_idx = 1; /* min samplerate 32kHz */
13797 + priv->card_rate = RPI_CIRRUS_DEFAULT_RATE;
13798 +
13799 + mutex_init(&priv->lock);
13800 +
13801 + snd_soc_card_set_drvdata(&rpi_cirrus_card, priv);
13802 +
13803 + if (!pdev->dev.of_node)
13804 + return -ENODEV;
13805 +
13806 + i2s_node = of_parse_phandle(
13807 + pdev->dev.of_node, "i2s-controller", 0);
13808 + if (!i2s_node) {
13809 + dev_err(&pdev->dev, "i2s-controller missing in DT\n");
13810 + return -ENODEV;
13811 + }
13812 +
13813 + rpi_cirrus_dai[DAI_WM5102].cpus->of_node = i2s_node;
13814 + rpi_cirrus_dai[DAI_WM5102].platforms->of_node = i2s_node;
13815 +
13816 + rpi_cirrus_card.dev = &pdev->dev;
13817 +
13818 + ret = devm_snd_soc_register_card(&pdev->dev, &rpi_cirrus_card);
13819 + if (ret) {
13820 + if (ret == -EPROBE_DEFER)
13821 + dev_dbg(&pdev->dev,
13822 + "register card requested probe deferral\n");
13823 + else
13824 + dev_err(&pdev->dev,
13825 + "Failed to register card: %d\n", ret);
13826 + }
13827 +
13828 + return ret;
13829 +}
13830 +
13831 +static const struct of_device_id rpi_cirrus_of_match[] = {
13832 + { .compatible = "wlf,rpi-cirrus", },
13833 + {},
13834 +};
13835 +MODULE_DEVICE_TABLE(of, rpi_cirrus_of_match);
13836 +
13837 +static struct platform_driver rpi_cirrus_driver = {
13838 + .driver = {
13839 + .name = "snd-rpi-cirrus",
13840 + .of_match_table = of_match_ptr(rpi_cirrus_of_match),
13841 + },
13842 + .probe = rpi_cirrus_probe,
13843 +};
13844 +
13845 +module_platform_driver(rpi_cirrus_driver);
13846 +
13847 +MODULE_AUTHOR("Matthias Reichl <hias@horus.com>");
13848 +MODULE_DESCRIPTION("ASoC driver for Cirrus Logic Audio Card");
13849 +MODULE_LICENSE("GPL");
13850 --- /dev/null
13851 +++ b/sound/soc/bcm/rpi-proto.c
13852 @@ -0,0 +1,147 @@
13853 +/*
13854 + * ASoC driver for PROTO AudioCODEC (with a WM8731)
13855 + * connected to a Raspberry Pi
13856 + *
13857 + * Author: Florian Meier, <koalo@koalo.de>
13858 + * Copyright 2013
13859 + *
13860 + * This program is free software; you can redistribute it and/or modify
13861 + * it under the terms of the GNU General Public License version 2 as
13862 + * published by the Free Software Foundation.
13863 + */
13864 +
13865 +#include <linux/module.h>
13866 +#include <linux/platform_device.h>
13867 +
13868 +#include <sound/core.h>
13869 +#include <sound/pcm.h>
13870 +#include <sound/soc.h>
13871 +#include <sound/jack.h>
13872 +
13873 +#include "../codecs/wm8731.h"
13874 +
13875 +static const unsigned int wm8731_rates_12288000[] = {
13876 + 8000, 32000, 48000, 96000,
13877 +};
13878 +
13879 +static struct snd_pcm_hw_constraint_list wm8731_constraints_12288000 = {
13880 + .list = wm8731_rates_12288000,
13881 + .count = ARRAY_SIZE(wm8731_rates_12288000),
13882 +};
13883 +
13884 +static int snd_rpi_proto_startup(struct snd_pcm_substream *substream)
13885 +{
13886 + /* Setup constraints, because there is a 12.288 MHz XTAL on the board */
13887 + snd_pcm_hw_constraint_list(substream->runtime, 0,
13888 + SNDRV_PCM_HW_PARAM_RATE,
13889 + &wm8731_constraints_12288000);
13890 + return 0;
13891 +}
13892 +
13893 +static int snd_rpi_proto_hw_params(struct snd_pcm_substream *substream,
13894 + struct snd_pcm_hw_params *params)
13895 +{
13896 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
13897 + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
13898 + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
13899 + int sysclk = 12288000; /* This is fixed on this board */
13900 +
13901 + /* Set proto bclk */
13902 + int ret = snd_soc_dai_set_bclk_ratio(cpu_dai,32*2);
13903 + if (ret < 0){
13904 + dev_err(rtd->card->dev,
13905 + "Failed to set BCLK ratio %d\n", ret);
13906 + return ret;
13907 + }
13908 +
13909 + /* Set proto sysclk */
13910 + ret = snd_soc_dai_set_sysclk(codec_dai, WM8731_SYSCLK_XTAL,
13911 + sysclk, SND_SOC_CLOCK_IN);
13912 + if (ret < 0) {
13913 + dev_err(rtd->card->dev,
13914 + "Failed to set WM8731 SYSCLK: %d\n", ret);
13915 + return ret;
13916 + }
13917 +
13918 + return 0;
13919 +}
13920 +
13921 +/* machine stream operations */
13922 +static struct snd_soc_ops snd_rpi_proto_ops = {
13923 + .startup = snd_rpi_proto_startup,
13924 + .hw_params = snd_rpi_proto_hw_params,
13925 +};
13926 +
13927 +SND_SOC_DAILINK_DEFS(rpi_proto,
13928 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
13929 + DAILINK_COMP_ARRAY(COMP_CODEC("wm8731.1-001a", "wm8731-hifi")),
13930 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
13931 +
13932 +static struct snd_soc_dai_link snd_rpi_proto_dai[] = {
13933 +{
13934 + .name = "WM8731",
13935 + .stream_name = "WM8731 HiFi",
13936 + .dai_fmt = SND_SOC_DAIFMT_I2S
13937 + | SND_SOC_DAIFMT_NB_NF
13938 + | SND_SOC_DAIFMT_CBM_CFM,
13939 + .ops = &snd_rpi_proto_ops,
13940 + SND_SOC_DAILINK_REG(rpi_proto),
13941 +},
13942 +};
13943 +
13944 +/* audio machine driver */
13945 +static struct snd_soc_card snd_rpi_proto = {
13946 + .name = "snd_rpi_proto",
13947 + .owner = THIS_MODULE,
13948 + .dai_link = snd_rpi_proto_dai,
13949 + .num_links = ARRAY_SIZE(snd_rpi_proto_dai),
13950 +};
13951 +
13952 +static int snd_rpi_proto_probe(struct platform_device *pdev)
13953 +{
13954 + int ret = 0;
13955 +
13956 + snd_rpi_proto.dev = &pdev->dev;
13957 +
13958 + if (pdev->dev.of_node) {
13959 + struct device_node *i2s_node;
13960 + struct snd_soc_dai_link *dai = &snd_rpi_proto_dai[0];
13961 + i2s_node = of_parse_phandle(pdev->dev.of_node,
13962 + "i2s-controller", 0);
13963 +
13964 + if (i2s_node) {
13965 + dai->cpus->dai_name = NULL;
13966 + dai->cpus->of_node = i2s_node;
13967 + dai->platforms->name = NULL;
13968 + dai->platforms->of_node = i2s_node;
13969 + }
13970 + }
13971 +
13972 + ret = devm_snd_soc_register_card(&pdev->dev, &snd_rpi_proto);
13973 + if (ret && ret != -EPROBE_DEFER)
13974 + dev_err(&pdev->dev,
13975 + "snd_soc_register_card() failed: %d\n", ret);
13976 +
13977 + return ret;
13978 +}
13979 +
13980 +static const struct of_device_id snd_rpi_proto_of_match[] = {
13981 + { .compatible = "rpi,rpi-proto", },
13982 + {},
13983 +};
13984 +MODULE_DEVICE_TABLE(of, snd_rpi_proto_of_match);
13985 +
13986 +static struct platform_driver snd_rpi_proto_driver = {
13987 + .driver = {
13988 + .name = "snd-rpi-proto",
13989 + .owner = THIS_MODULE,
13990 + .of_match_table = snd_rpi_proto_of_match,
13991 + },
13992 + .probe = snd_rpi_proto_probe,
13993 +};
13994 +
13995 +module_platform_driver(snd_rpi_proto_driver);
13996 +
13997 +MODULE_AUTHOR("Florian Meier");
13998 +MODULE_DESCRIPTION("ASoC Driver for Raspberry Pi connected to PROTO board (WM8731)");
13999 +MODULE_LICENSE("GPL");
14000 --- /dev/null
14001 +++ b/sound/soc/bcm/rpi-simple-soundcard.c
14002 @@ -0,0 +1,487 @@
14003 +// SPDX-License-Identifier: GPL-2.0
14004 +/*
14005 + * rpi-simple-soundcard.c -- ALSA SoC Raspberry Pi soundcard.
14006 + *
14007 + * Copyright (C) 2018 Raspberry Pi.
14008 + *
14009 + * Authors: Tim Gover <tim.gover@raspberrypi.org>
14010 + *
14011 + * Based on code:
14012 + * hifiberry_amp.c, hifiberry_dac.c, rpi-dac.c
14013 + * by Florian Meier <florian.meier@koalo.de>
14014 + *
14015 + * googlevoicehat-soundcard.c
14016 + * by Peter Malkin <petermalkin@google.com>
14017 + *
14018 + * adau1977-adc.c
14019 + * by Andrey Grodzovsky <andrey2805@gmail.com>
14020 + *
14021 + * merus-amp.c
14022 + * by Ariel Muszkat <ariel.muszkat@gmail.com>
14023 + * Jorgen Kragh Jakobsen <jorgen.kraghjakobsen@infineon.com>
14024 + *
14025 + * This program is free software; you can redistribute it and/or
14026 + * modify it under the terms of the GNU General Public License
14027 + * version 2 as published by the Free Software Foundation.
14028 + *
14029 + * This program is distributed in the hope that it will be useful, but
14030 + * WITHOUT ANY WARRANTY; without even the implied warranty of
14031 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14032 + * General Public License for more details.
14033 + */
14034 +
14035 +#include <linux/module.h>
14036 +#include <linux/platform_device.h>
14037 +#include <linux/gpio/consumer.h>
14038 +
14039 +#include <sound/core.h>
14040 +#include <sound/pcm.h>
14041 +#include <sound/pcm_params.h>
14042 +#include <sound/soc.h>
14043 +
14044 +/* Parameters for generic RPI functions */
14045 +struct snd_rpi_simple_drvdata {
14046 + struct snd_soc_dai_link *dai;
14047 + const char* card_name;
14048 + unsigned int fixed_bclk_ratio;
14049 +};
14050 +
14051 +static struct snd_soc_card snd_rpi_simple = {
14052 + .driver_name = "RPi-simple",
14053 + .owner = THIS_MODULE,
14054 + .dai_link = NULL,
14055 + .num_links = 1, /* Only a single DAI supported at the moment */
14056 +};
14057 +
14058 +static int snd_rpi_simple_init(struct snd_soc_pcm_runtime *rtd)
14059 +{
14060 + struct snd_rpi_simple_drvdata *drvdata =
14061 + snd_soc_card_get_drvdata(rtd->card);
14062 + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
14063 +
14064 + if (drvdata->fixed_bclk_ratio > 0)
14065 + return snd_soc_dai_set_bclk_ratio(cpu_dai,
14066 + drvdata->fixed_bclk_ratio);
14067 +
14068 + return 0;
14069 +}
14070 +
14071 +static int pifi_mini_210_init(struct snd_soc_pcm_runtime *rtd)
14072 +{
14073 + struct snd_soc_component *dac;
14074 + struct gpio_desc *pdn_gpio, *rst_gpio;
14075 + struct snd_soc_dai *codec_dai;
14076 + int ret;
14077 +
14078 + snd_rpi_simple_init(rtd);
14079 + codec_dai = asoc_rtd_to_codec(rtd, 0);
14080 +
14081 + dac = codec_dai[0].component;
14082 +
14083 + pdn_gpio = devm_gpiod_get_optional(snd_rpi_simple.dev, "pdn",
14084 + GPIOD_OUT_LOW);
14085 + if (IS_ERR(pdn_gpio)) {
14086 + ret = PTR_ERR(pdn_gpio);
14087 + dev_err(snd_rpi_simple.dev, "failed to get pdn gpio: %d\n", ret);
14088 + return ret;
14089 + }
14090 +
14091 + rst_gpio = devm_gpiod_get_optional(snd_rpi_simple.dev, "rst",
14092 + GPIOD_OUT_LOW);
14093 + if (IS_ERR(rst_gpio)) {
14094 + ret = PTR_ERR(rst_gpio);
14095 + dev_err(snd_rpi_simple.dev, "failed to get rst gpio: %d\n", ret);
14096 + return ret;
14097 + }
14098 +
14099 + // Set up cards - pulse power down and reset first, then
14100 + // set up according to datasheet
14101 + gpiod_set_value_cansleep(pdn_gpio, 1);
14102 + gpiod_set_value_cansleep(rst_gpio, 1);
14103 + usleep_range(1000, 10000);
14104 + gpiod_set_value_cansleep(pdn_gpio, 0);
14105 + usleep_range(20000, 30000);
14106 + gpiod_set_value_cansleep(rst_gpio, 0);
14107 + usleep_range(20000, 30000);
14108 +
14109 + // Oscillator trim
14110 + snd_soc_component_write(dac, 0x1b, 0);
14111 + usleep_range(60000, 80000);
14112 +
14113 + // MCLK at 64fs, sample rate 44.1 or 48kHz
14114 + snd_soc_component_write(dac, 0x00, 0x60);
14115 +
14116 + // Set up for BTL - AD/BD mode - AD is 0x00107772, BD is 0x00987772
14117 + snd_soc_component_write(dac, 0x20, 0x00107772);
14118 +
14119 + // End mute
14120 + snd_soc_component_write(dac, 0x05, 0x00);
14121 +
14122 + return 0;
14123 +}
14124 +
14125 +static int snd_rpi_simple_hw_params(struct snd_pcm_substream *substream,
14126 + struct snd_pcm_hw_params *params)
14127 +{
14128 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
14129 + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
14130 + struct snd_rpi_simple_drvdata *drvdata;
14131 + unsigned int sample_bits;
14132 +
14133 + drvdata = snd_soc_card_get_drvdata(rtd->card);
14134 +
14135 + if (drvdata->fixed_bclk_ratio > 0)
14136 + return 0; // BCLK is configured in .init
14137 +
14138 + /* The simple drivers just set the bclk_ratio to sample_bits * 2 so
14139 + * hard-code this for now. More complex drivers could just replace
14140 + * the hw_params routine.
14141 + */
14142 + sample_bits = snd_pcm_format_physical_width(params_format(params));
14143 + return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);
14144 +}
14145 +
14146 +static struct snd_soc_ops snd_rpi_simple_ops = {
14147 + .hw_params = snd_rpi_simple_hw_params,
14148 +};
14149 +
14150 +static int snd_merus_amp_hw_params(struct snd_pcm_substream *substream,
14151 + struct snd_pcm_hw_params *params)
14152 +{
14153 + struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
14154 + int rate;
14155 +
14156 + rate = params_rate(params);
14157 + if (rate > 48000) {
14158 + dev_err(rtd->card->dev,
14159 + "Unsupported samplerate %d\n",
14160 + rate);
14161 + return -EINVAL;
14162 + }
14163 + return 0;
14164 +}
14165 +
14166 +static struct snd_soc_ops snd_merus_amp_ops = {
14167 + .hw_params = snd_merus_amp_hw_params,
14168 +};
14169 +
14170 +enum adau1977_clk_id {
14171 + ADAU1977_SYSCLK,
14172 +};
14173 +
14174 +enum adau1977_sysclk_src {
14175 + ADAU1977_SYSCLK_SRC_MCLK,
14176 + ADAU1977_SYSCLK_SRC_LRCLK,
14177 +};
14178 +
14179 +static int adau1977_init(struct snd_soc_pcm_runtime *rtd)
14180 +{
14181 + int ret;
14182 + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
14183 +
14184 + ret = snd_soc_dai_set_tdm_slot(codec_dai, 0, 0, 0, 0);
14185 + if (ret < 0)
14186 + return ret;
14187 +
14188 + return snd_soc_component_set_sysclk(codec_dai->component,
14189 + ADAU1977_SYSCLK, ADAU1977_SYSCLK_SRC_MCLK,
14190 + 11289600, SND_SOC_CLOCK_IN);
14191 +}
14192 +
14193 +SND_SOC_DAILINK_DEFS(adau1977,
14194 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
14195 + DAILINK_COMP_ARRAY(COMP_CODEC("adau1977.1-0011", "adau1977-hifi")),
14196 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
14197 +
14198 +static struct snd_soc_dai_link snd_rpi_adau1977_dai[] = {
14199 + {
14200 + .name = "adau1977",
14201 + .stream_name = "ADAU1977",
14202 + .init = adau1977_init,
14203 + .dai_fmt = SND_SOC_DAIFMT_I2S |
14204 + SND_SOC_DAIFMT_NB_NF |
14205 + SND_SOC_DAIFMT_CBM_CFM,
14206 + SND_SOC_DAILINK_REG(adau1977),
14207 + },
14208 +};
14209 +
14210 +static struct snd_rpi_simple_drvdata drvdata_adau1977 = {
14211 + .card_name = "snd_rpi_adau1977_adc",
14212 + .dai = snd_rpi_adau1977_dai,
14213 +};
14214 +
14215 +SND_SOC_DAILINK_DEFS(gvchat,
14216 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
14217 + DAILINK_COMP_ARRAY(COMP_CODEC("voicehat-codec", "voicehat-hifi")),
14218 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
14219 +
14220 +static struct snd_soc_dai_link snd_googlevoicehat_soundcard_dai[] = {
14221 +{
14222 + .name = "Google voiceHAT SoundCard",
14223 + .stream_name = "Google voiceHAT SoundCard HiFi",
14224 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
14225 + SND_SOC_DAIFMT_CBS_CFS,
14226 + SND_SOC_DAILINK_REG(gvchat),
14227 +},
14228 +};
14229 +
14230 +static struct snd_rpi_simple_drvdata drvdata_googlevoicehat = {
14231 + .card_name = "snd_rpi_googlevoicehat_soundcard",
14232 + .dai = snd_googlevoicehat_soundcard_dai,
14233 +};
14234 +
14235 +SND_SOC_DAILINK_DEFS(hifiberry_dacplusdsp,
14236 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
14237 + DAILINK_COMP_ARRAY(COMP_CODEC("dacplusdsp-codec", "dacplusdsp-hifi")),
14238 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
14239 +
14240 +static struct snd_soc_dai_link snd_hifiberrydacplusdsp_soundcard_dai[] = {
14241 +{
14242 + .name = "Hifiberry DAC+DSP SoundCard",
14243 + .stream_name = "Hifiberry DAC+DSP SoundCard HiFi",
14244 + .dai_fmt = SND_SOC_DAIFMT_I2S |
14245 + SND_SOC_DAIFMT_NB_NF |
14246 + SND_SOC_DAIFMT_CBS_CFS,
14247 + SND_SOC_DAILINK_REG(hifiberry_dacplusdsp),
14248 +},
14249 +};
14250 +
14251 +static struct snd_rpi_simple_drvdata drvdata_hifiberrydacplusdsp = {
14252 + .card_name = "snd_rpi_hifiberrydacplusdsp_soundcard",
14253 + .dai = snd_hifiberrydacplusdsp_soundcard_dai,
14254 +};
14255 +
14256 +SND_SOC_DAILINK_DEFS(hifiberry_amp,
14257 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
14258 + DAILINK_COMP_ARRAY(COMP_CODEC("tas5713.1-001b", "tas5713-hifi")),
14259 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
14260 +
14261 +static struct snd_soc_dai_link snd_hifiberry_amp_dai[] = {
14262 + {
14263 + .name = "HifiBerry AMP",
14264 + .stream_name = "HifiBerry AMP HiFi",
14265 + .dai_fmt = SND_SOC_DAIFMT_I2S |
14266 + SND_SOC_DAIFMT_NB_NF |
14267 + SND_SOC_DAIFMT_CBS_CFS,
14268 + SND_SOC_DAILINK_REG(hifiberry_amp),
14269 + },
14270 +};
14271 +
14272 +static struct snd_rpi_simple_drvdata drvdata_hifiberry_amp = {
14273 + .card_name = "snd_rpi_hifiberry_amp",
14274 + .dai = snd_hifiberry_amp_dai,
14275 + .fixed_bclk_ratio = 64,
14276 +};
14277 +
14278 +SND_SOC_DAILINK_DEFS(hifiberry_amp3,
14279 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
14280 + DAILINK_COMP_ARRAY(COMP_CODEC("ma120x0p.1-0020", "ma120x0p-amp")),
14281 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
14282 +
14283 +static struct snd_soc_dai_link snd_hifiberry_amp3_dai[] = {
14284 + {
14285 + .name = "HifiberryAmp3",
14286 + .stream_name = "Hifiberry Amp3",
14287 + .dai_fmt = SND_SOC_DAIFMT_I2S |
14288 + SND_SOC_DAIFMT_NB_NF |
14289 + SND_SOC_DAIFMT_CBS_CFS,
14290 + SND_SOC_DAILINK_REG(hifiberry_amp3),
14291 + },
14292 +};
14293 +
14294 +static struct snd_rpi_simple_drvdata drvdata_hifiberry_amp3 = {
14295 + .card_name = "snd_rpi_hifiberry_amp3",
14296 + .dai = snd_hifiberry_amp3_dai,
14297 + .fixed_bclk_ratio = 64,
14298 +};
14299 +
14300 +SND_SOC_DAILINK_DEFS(hifiberry_dac,
14301 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
14302 + DAILINK_COMP_ARRAY(COMP_CODEC("pcm5102a-codec", "pcm5102a-hifi")),
14303 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
14304 +
14305 +static struct snd_soc_dai_link snd_hifiberry_dac_dai[] = {
14306 + {
14307 + .name = "HifiBerry DAC",
14308 + .stream_name = "HifiBerry DAC HiFi",
14309 + .dai_fmt = SND_SOC_DAIFMT_I2S |
14310 + SND_SOC_DAIFMT_NB_NF |
14311 + SND_SOC_DAIFMT_CBS_CFS,
14312 + SND_SOC_DAILINK_REG(hifiberry_dac),
14313 + },
14314 +};
14315 +
14316 +static struct snd_rpi_simple_drvdata drvdata_hifiberry_dac = {
14317 + .card_name = "snd_rpi_hifiberry_dac",
14318 + .dai = snd_hifiberry_dac_dai,
14319 +};
14320 +
14321 +SND_SOC_DAILINK_DEFS(dionaudio_kiwi,
14322 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
14323 + DAILINK_COMP_ARRAY(COMP_CODEC("pcm1794a-codec", "pcm1794a-hifi")),
14324 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
14325 +
14326 +static struct snd_soc_dai_link snd_dionaudio_kiwi_dai[] = {
14327 +{
14328 + .name = "DionAudio KIWI",
14329 + .stream_name = "DionAudio KIWI STREAMER",
14330 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
14331 + SND_SOC_DAIFMT_CBS_CFS,
14332 + SND_SOC_DAILINK_REG(dionaudio_kiwi),
14333 +},
14334 +};
14335 +
14336 +static struct snd_rpi_simple_drvdata drvdata_dionaudio_kiwi = {
14337 + .card_name = "snd_rpi_dionaudio_kiwi",
14338 + .dai = snd_dionaudio_kiwi_dai,
14339 + .fixed_bclk_ratio = 64,
14340 +};
14341 +
14342 +SND_SOC_DAILINK_DEFS(rpi_dac,
14343 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
14344 + DAILINK_COMP_ARRAY(COMP_CODEC("pcm1794a-codec", "pcm1794a-hifi")),
14345 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
14346 +
14347 +static struct snd_soc_dai_link snd_rpi_dac_dai[] = {
14348 +{
14349 + .name = "RPi-DAC",
14350 + .stream_name = "RPi-DAC HiFi",
14351 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
14352 + SND_SOC_DAIFMT_CBS_CFS,
14353 + SND_SOC_DAILINK_REG(rpi_dac),
14354 +},
14355 +};
14356 +
14357 +static struct snd_rpi_simple_drvdata drvdata_rpi_dac = {
14358 + .card_name = "snd_rpi_rpi_dac",
14359 + .dai = snd_rpi_dac_dai,
14360 + .fixed_bclk_ratio = 64,
14361 +};
14362 +
14363 +SND_SOC_DAILINK_DEFS(merus_amp,
14364 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
14365 + DAILINK_COMP_ARRAY(COMP_CODEC("ma120x0p.1-0020", "ma120x0p-amp")),
14366 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
14367 +
14368 +static struct snd_soc_dai_link snd_merus_amp_dai[] = {
14369 + {
14370 + .name = "MerusAmp",
14371 + .stream_name = "Merus Audio Amp",
14372 + .ops = &snd_merus_amp_ops,
14373 + .dai_fmt = SND_SOC_DAIFMT_I2S |
14374 + SND_SOC_DAIFMT_NB_NF |
14375 + SND_SOC_DAIFMT_CBS_CFS,
14376 + SND_SOC_DAILINK_REG(merus_amp),
14377 + },
14378 +};
14379 +
14380 +static struct snd_rpi_simple_drvdata drvdata_merus_amp = {
14381 + .card_name = "snd_rpi_merus_amp",
14382 + .dai = snd_merus_amp_dai,
14383 + .fixed_bclk_ratio = 64,
14384 +};
14385 +
14386 +SND_SOC_DAILINK_DEFS(pifi_mini_210,
14387 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
14388 + DAILINK_COMP_ARRAY(COMP_CODEC("tas571x.1-001a", "tas571x-hifi")),
14389 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
14390 +
14391 +static struct snd_soc_dai_link snd_pifi_mini_210_dai[] = {
14392 + {
14393 + .name = "PiFi Mini 210",
14394 + .stream_name = "PiFi Mini 210 HiFi",
14395 + .init = pifi_mini_210_init,
14396 + .dai_fmt = SND_SOC_DAIFMT_I2S |
14397 + SND_SOC_DAIFMT_NB_NF |
14398 + SND_SOC_DAIFMT_CBS_CFS,
14399 + SND_SOC_DAILINK_REG(pifi_mini_210),
14400 + },
14401 +};
14402 +
14403 +static struct snd_rpi_simple_drvdata drvdata_pifi_mini_210 = {
14404 + .card_name = "snd_pifi_mini_210",
14405 + .dai = snd_pifi_mini_210_dai,
14406 + .fixed_bclk_ratio = 64,
14407 +};
14408 +
14409 +static const struct of_device_id snd_rpi_simple_of_match[] = {
14410 + { .compatible = "adi,adau1977-adc",
14411 + .data = (void *) &drvdata_adau1977 },
14412 + { .compatible = "googlevoicehat,googlevoicehat-soundcard",
14413 + .data = (void *) &drvdata_googlevoicehat },
14414 + { .compatible = "hifiberrydacplusdsp,hifiberrydacplusdsp-soundcard",
14415 + .data = (void *) &drvdata_hifiberrydacplusdsp },
14416 + { .compatible = "hifiberry,hifiberry-amp",
14417 + .data = (void *) &drvdata_hifiberry_amp },
14418 + { .compatible = "hifiberry,hifiberry-amp3",
14419 + .data = (void *) &drvdata_hifiberry_amp3 },
14420 + { .compatible = "hifiberry,hifiberry-dac",
14421 + .data = (void *) &drvdata_hifiberry_dac },
14422 + { .compatible = "dionaudio,dionaudio-kiwi",
14423 + .data = (void *) &drvdata_dionaudio_kiwi },
14424 + { .compatible = "rpi,rpi-dac", &drvdata_rpi_dac},
14425 + { .compatible = "merus,merus-amp",
14426 + .data = (void *) &drvdata_merus_amp },
14427 + { .compatible = "pifi,pifi-mini-210",
14428 + .data = (void *) &drvdata_pifi_mini_210 },
14429 + {},
14430 +};
14431 +
14432 +static int snd_rpi_simple_probe(struct platform_device *pdev)
14433 +{
14434 + int ret = 0;
14435 + const struct of_device_id *of_id;
14436 +
14437 + snd_rpi_simple.dev = &pdev->dev;
14438 + of_id = of_match_node(snd_rpi_simple_of_match, pdev->dev.of_node);
14439 +
14440 + if (pdev->dev.of_node && of_id->data) {
14441 + struct device_node *i2s_node;
14442 + struct snd_rpi_simple_drvdata *drvdata =
14443 + (struct snd_rpi_simple_drvdata *) of_id->data;
14444 + struct snd_soc_dai_link *dai = drvdata->dai;
14445 +
14446 + snd_soc_card_set_drvdata(&snd_rpi_simple, drvdata);
14447 +
14448 + /* More complex drivers might override individual functions */
14449 + if (!dai->init)
14450 + dai->init = snd_rpi_simple_init;
14451 + if (!dai->ops)
14452 + dai->ops = &snd_rpi_simple_ops;
14453 +
14454 + snd_rpi_simple.name = drvdata->card_name;
14455 +
14456 + snd_rpi_simple.dai_link = dai;
14457 + i2s_node = of_parse_phandle(pdev->dev.of_node,
14458 + "i2s-controller", 0);
14459 + if (!i2s_node) {
14460 + pr_err("Failed to find i2s-controller DT node\n");
14461 + return -ENODEV;
14462 + }
14463 +
14464 + dai->cpus->of_node = i2s_node;
14465 + dai->platforms->of_node = i2s_node;
14466 + }
14467 +
14468 + ret = devm_snd_soc_register_card(&pdev->dev, &snd_rpi_simple);
14469 + if (ret && ret != -EPROBE_DEFER)
14470 + dev_err(&pdev->dev, "Failed to register card %d\n", ret);
14471 +
14472 + return ret;
14473 +}
14474 +
14475 +static struct platform_driver snd_rpi_simple_driver = {
14476 + .driver = {
14477 + .name = "snd-rpi-simple",
14478 + .owner = THIS_MODULE,
14479 + .of_match_table = snd_rpi_simple_of_match,
14480 + },
14481 + .probe = snd_rpi_simple_probe,
14482 +};
14483 +MODULE_DEVICE_TABLE(of, snd_rpi_simple_of_match);
14484 +
14485 +module_platform_driver(snd_rpi_simple_driver);
14486 +
14487 +MODULE_AUTHOR("Tim Gover <tim.gover@raspberrypi.org>");
14488 +MODULE_DESCRIPTION("ASoC Raspberry Pi simple soundcard driver ");
14489 +MODULE_LICENSE("GPL v2");
14490 --- /dev/null
14491 +++ b/sound/soc/bcm/rpi-wm8804-soundcard.c
14492 @@ -0,0 +1,410 @@
14493 +// SPDX-License-Identifier: GPL-2.0
14494 +/*
14495 + * rpi--wm8804.c -- ALSA SoC Raspberry Pi soundcard.
14496 + *
14497 + * Copyright (C) 2018 Raspberry Pi.
14498 + *
14499 + * Authors: Tim Gover <tim.gover@raspberrypi.org>
14500 + *
14501 + * Generic driver for Pi Hat WM8804 digi sounds cards
14502 + *
14503 + * Based upon code from:
14504 + * justboom-digi.c
14505 + * by Milan Neskovic <info@justboom.co>
14506 + *
14507 + * iqaudio_digi.c
14508 + * by Daniel Matuschek <info@crazy-audio.com>
14509 + *
14510 + * allo-digione.c
14511 + * by Baswaraj <jaikumar@cem-solutions.net>
14512 + *
14513 + * hifiberry-digi.c
14514 + * Daniel Matuschek <info@crazy-audio.com>
14515 + *
14516 + * This program is free software; you can redistribute it and/or
14517 + * modify it under the terms of the GNU General Public License
14518 + * version 2 as published by the Free Software Foundation.
14519 + *
14520 + * This program is distributed in the hope that it will be useful, but
14521 + * WITHOUT ANY WARRANTY; without even the implied warranty of
14522 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14523 + * General Public License for more details.
14524 + */
14525 +
14526 +#include <linux/gpio/consumer.h>
14527 +#include <linux/platform_device.h>
14528 +#include <linux/module.h>
14529 +
14530 +#include <sound/core.h>
14531 +#include <sound/pcm.h>
14532 +#include <sound/pcm_params.h>
14533 +#include <sound/soc.h>
14534 +
14535 +#include "../codecs/wm8804.h"
14536 +
14537 +struct wm8804_clk_cfg {
14538 + unsigned int sysclk_freq;
14539 + unsigned int mclk_freq;
14540 + unsigned int mclk_div;
14541 +};
14542 +
14543 +/* Parameters for generic functions */
14544 +struct snd_rpi_wm8804_drvdata {
14545 + /* Required - pointer to the DAI structure */
14546 + struct snd_soc_dai_link *dai;
14547 + /* Required - snd_soc_card name */
14548 + const char *card_name;
14549 + /* Optional DT node names if card info is defined in DT */
14550 + const char *card_name_dt;
14551 + const char *dai_name_dt;
14552 + const char *dai_stream_name_dt;
14553 + /* Optional probe extension - called prior to register_card */
14554 + int (*probe)(struct platform_device *pdev);
14555 +};
14556 +
14557 +static struct gpio_desc *snd_clk44gpio;
14558 +static struct gpio_desc *snd_clk48gpio;
14559 +static int wm8804_samplerate = 0;
14560 +
14561 +/* Forward declarations */
14562 +static struct snd_soc_dai_link snd_allo_digione_dai[];
14563 +static struct snd_soc_card snd_rpi_wm8804;
14564 +
14565 +
14566 +#define CLK_44EN_RATE 22579200UL
14567 +#define CLK_48EN_RATE 24576000UL
14568 +
14569 +static unsigned int snd_rpi_wm8804_enable_clock(unsigned int samplerate)
14570 +{
14571 + switch (samplerate) {
14572 + case 11025:
14573 + case 22050:
14574 + case 44100:
14575 + case 88200:
14576 + case 176400:
14577 + gpiod_set_value_cansleep(snd_clk44gpio, 1);
14578 + gpiod_set_value_cansleep(snd_clk48gpio, 0);
14579 + return CLK_44EN_RATE;
14580 + default:
14581 + gpiod_set_value_cansleep(snd_clk48gpio, 1);
14582 + gpiod_set_value_cansleep(snd_clk44gpio, 0);
14583 + return CLK_48EN_RATE;
14584 + }
14585 +}
14586 +
14587 +static void snd_rpi_wm8804_clk_cfg(unsigned int samplerate,
14588 + struct wm8804_clk_cfg *clk_cfg)
14589 +{
14590 + clk_cfg->sysclk_freq = 27000000;
14591 +
14592 + if (samplerate <= 96000 ||
14593 + snd_rpi_wm8804.dai_link == snd_allo_digione_dai) {
14594 + clk_cfg->mclk_freq = samplerate * 256;
14595 + clk_cfg->mclk_div = WM8804_MCLKDIV_256FS;
14596 + } else {
14597 + clk_cfg->mclk_freq = samplerate * 128;
14598 + clk_cfg->mclk_div = WM8804_MCLKDIV_128FS;
14599 + }
14600 +
14601 + if (!(IS_ERR(snd_clk44gpio) || IS_ERR(snd_clk48gpio)))
14602 + clk_cfg->sysclk_freq = snd_rpi_wm8804_enable_clock(samplerate);
14603 +}
14604 +
14605 +static int snd_rpi_wm8804_hw_params(struct snd_pcm_substream *substream,
14606 + struct snd_pcm_hw_params *params)
14607 +{
14608 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
14609 + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
14610 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
14611 + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
14612 + int sampling_freq = 1;
14613 + int ret;
14614 + struct wm8804_clk_cfg clk_cfg;
14615 + int samplerate = params_rate(params);
14616 +
14617 + if (samplerate == wm8804_samplerate)
14618 + return 0;
14619 +
14620 + /* clear until all clocks are setup properly */
14621 + wm8804_samplerate = 0;
14622 +
14623 + snd_rpi_wm8804_clk_cfg(samplerate, &clk_cfg);
14624 +
14625 + pr_debug("%s samplerate: %d mclk_freq: %u mclk_div: %u sysclk: %u\n",
14626 + __func__, samplerate, clk_cfg.mclk_freq,
14627 + clk_cfg.mclk_div, clk_cfg.sysclk_freq);
14628 +
14629 + switch (samplerate) {
14630 + case 32000:
14631 + sampling_freq = 0x03;
14632 + break;
14633 + case 44100:
14634 + sampling_freq = 0x00;
14635 + break;
14636 + case 48000:
14637 + sampling_freq = 0x02;
14638 + break;
14639 + case 88200:
14640 + sampling_freq = 0x08;
14641 + break;
14642 + case 96000:
14643 + sampling_freq = 0x0a;
14644 + break;
14645 + case 176400:
14646 + sampling_freq = 0x0c;
14647 + break;
14648 + case 192000:
14649 + sampling_freq = 0x0e;
14650 + break;
14651 + default:
14652 + dev_err(rtd->card->dev,
14653 + "Failed to set WM8804 SYSCLK, unsupported samplerate %d\n",
14654 + samplerate);
14655 + }
14656 +
14657 + snd_soc_dai_set_clkdiv(codec_dai, WM8804_MCLK_DIV, clk_cfg.mclk_div);
14658 + snd_soc_dai_set_pll(codec_dai, 0, 0,
14659 + clk_cfg.sysclk_freq, clk_cfg.mclk_freq);
14660 +
14661 + ret = snd_soc_dai_set_sysclk(codec_dai, WM8804_TX_CLKSRC_PLL,
14662 + clk_cfg.sysclk_freq, SND_SOC_CLOCK_OUT);
14663 + if (ret < 0) {
14664 + dev_err(rtd->card->dev,
14665 + "Failed to set WM8804 SYSCLK: %d\n", ret);
14666 + return ret;
14667 + }
14668 +
14669 + wm8804_samplerate = samplerate;
14670 +
14671 + /* set sampling frequency status bits */
14672 + snd_soc_component_update_bits(component, WM8804_SPDTX4, 0x0f,
14673 + sampling_freq);
14674 +
14675 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 64);
14676 +}
14677 +
14678 +static struct snd_soc_ops snd_rpi_wm8804_ops = {
14679 + .hw_params = snd_rpi_wm8804_hw_params,
14680 +};
14681 +
14682 +SND_SOC_DAILINK_DEFS(justboom_digi,
14683 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
14684 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
14685 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
14686 +
14687 +static struct snd_soc_dai_link snd_justboom_digi_dai[] = {
14688 +{
14689 + .name = "JustBoom Digi",
14690 + .stream_name = "JustBoom Digi HiFi",
14691 + SND_SOC_DAILINK_REG(justboom_digi),
14692 +},
14693 +};
14694 +
14695 +static struct snd_rpi_wm8804_drvdata drvdata_justboom_digi = {
14696 + .card_name = "snd_rpi_justboom_digi",
14697 + .dai = snd_justboom_digi_dai,
14698 +};
14699 +
14700 +SND_SOC_DAILINK_DEFS(iqaudio_digi,
14701 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
14702 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
14703 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
14704 +
14705 +static struct snd_soc_dai_link snd_iqaudio_digi_dai[] = {
14706 +{
14707 + .name = "IQAudIO Digi",
14708 + .stream_name = "IQAudIO Digi HiFi",
14709 + SND_SOC_DAILINK_REG(iqaudio_digi),
14710 +},
14711 +};
14712 +
14713 +static struct snd_rpi_wm8804_drvdata drvdata_iqaudio_digi = {
14714 + .card_name = "IQAudIODigi",
14715 + .dai = snd_iqaudio_digi_dai,
14716 + .card_name_dt = "wm8804-digi,card-name",
14717 + .dai_name_dt = "wm8804-digi,dai-name",
14718 + .dai_stream_name_dt = "wm8804-digi,dai-stream-name",
14719 +};
14720 +
14721 +static int snd_allo_digione_probe(struct platform_device *pdev)
14722 +{
14723 + pr_debug("%s\n", __func__);
14724 +
14725 + if (IS_ERR(snd_clk44gpio) || IS_ERR(snd_clk48gpio)) {
14726 + dev_err(&pdev->dev, "devm_gpiod_get() failed\n");
14727 + return -EINVAL;
14728 + }
14729 + return 0;
14730 +}
14731 +
14732 +SND_SOC_DAILINK_DEFS(allo_digione,
14733 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
14734 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
14735 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
14736 +
14737 +static struct snd_soc_dai_link snd_allo_digione_dai[] = {
14738 +{
14739 + .name = "Allo DigiOne",
14740 + .stream_name = "Allo DigiOne HiFi",
14741 + SND_SOC_DAILINK_REG(allo_digione),
14742 +},
14743 +};
14744 +
14745 +static struct snd_rpi_wm8804_drvdata drvdata_allo_digione = {
14746 + .card_name = "snd_allo_digione",
14747 + .dai = snd_allo_digione_dai,
14748 + .probe = snd_allo_digione_probe,
14749 +};
14750 +
14751 +SND_SOC_DAILINK_DEFS(hifiberry_digi,
14752 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
14753 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
14754 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
14755 +
14756 +static struct snd_soc_dai_link snd_hifiberry_digi_dai[] = {
14757 +{
14758 + .name = "HifiBerry Digi",
14759 + .stream_name = "HifiBerry Digi HiFi",
14760 + SND_SOC_DAILINK_REG(hifiberry_digi),
14761 +},
14762 +};
14763 +
14764 +static int snd_hifiberry_digi_probe(struct platform_device *pdev)
14765 +{
14766 + pr_debug("%s\n", __func__);
14767 +
14768 + if (IS_ERR(snd_clk44gpio) || IS_ERR(snd_clk48gpio))
14769 + return 0;
14770 +
14771 + snd_hifiberry_digi_dai->name = "HiFiBerry Digi+ Pro";
14772 + snd_hifiberry_digi_dai->stream_name = "HiFiBerry Digi+ Pro HiFi";
14773 + return 0;
14774 +}
14775 +
14776 +static struct snd_rpi_wm8804_drvdata drvdata_hifiberry_digi = {
14777 + .card_name = "snd_rpi_hifiberry_digi",
14778 + .dai = snd_hifiberry_digi_dai,
14779 + .probe = snd_hifiberry_digi_probe,
14780 +};
14781 +
14782 +static const struct of_device_id snd_rpi_wm8804_of_match[] = {
14783 + { .compatible = "justboom,justboom-digi",
14784 + .data = (void *) &drvdata_justboom_digi },
14785 + { .compatible = "iqaudio,wm8804-digi",
14786 + .data = (void *) &drvdata_iqaudio_digi },
14787 + { .compatible = "allo,allo-digione",
14788 + .data = (void *) &drvdata_allo_digione },
14789 + { .compatible = "hifiberry,hifiberry-digi",
14790 + .data = (void *) &drvdata_hifiberry_digi },
14791 + {},
14792 +};
14793 +
14794 +static struct snd_soc_card snd_rpi_wm8804 = {
14795 + .driver_name = "RPi-WM8804",
14796 + .owner = THIS_MODULE,
14797 + .dai_link = NULL,
14798 + .num_links = 1,
14799 +};
14800 +
14801 +static int snd_rpi_wm8804_probe(struct platform_device *pdev)
14802 +{
14803 + int ret = 0;
14804 + const struct of_device_id *of_id;
14805 +
14806 + snd_rpi_wm8804.dev = &pdev->dev;
14807 + of_id = of_match_node(snd_rpi_wm8804_of_match, pdev->dev.of_node);
14808 +
14809 + if (pdev->dev.of_node && of_id->data) {
14810 + struct device_node *i2s_node;
14811 + struct snd_rpi_wm8804_drvdata *drvdata =
14812 + (struct snd_rpi_wm8804_drvdata *) of_id->data;
14813 + struct snd_soc_dai_link *dai = drvdata->dai;
14814 +
14815 + snd_soc_card_set_drvdata(&snd_rpi_wm8804, drvdata);
14816 +
14817 + if (!dai->ops)
14818 + dai->ops = &snd_rpi_wm8804_ops;
14819 + if (!dai->codecs->dai_name)
14820 + dai->codecs->dai_name = "wm8804-spdif";
14821 + if (!dai->codecs->name)
14822 + dai->codecs->name = "wm8804.1-003b";
14823 + if (!dai->dai_fmt)
14824 + dai->dai_fmt = SND_SOC_DAIFMT_I2S |
14825 + SND_SOC_DAIFMT_NB_NF |
14826 + SND_SOC_DAIFMT_CBM_CFM;
14827 +
14828 + snd_rpi_wm8804.dai_link = dai;
14829 + i2s_node = of_parse_phandle(pdev->dev.of_node,
14830 + "i2s-controller", 0);
14831 + if (!i2s_node) {
14832 + pr_err("Failed to find i2s-controller DT node\n");
14833 + return -ENODEV;
14834 + }
14835 +
14836 + snd_rpi_wm8804.name = drvdata->card_name;
14837 +
14838 + /* If requested by in drvdata get card & DAI names from DT */
14839 + if (drvdata->card_name_dt)
14840 + of_property_read_string(i2s_node,
14841 + drvdata->card_name_dt,
14842 + &snd_rpi_wm8804.name);
14843 +
14844 + if (drvdata->dai_name_dt)
14845 + of_property_read_string(i2s_node,
14846 + drvdata->dai_name_dt,
14847 + &dai->name);
14848 +
14849 + if (drvdata->dai_stream_name_dt)
14850 + of_property_read_string(i2s_node,
14851 + drvdata->dai_stream_name_dt,
14852 + &dai->stream_name);
14853 +
14854 + dai->cpus->of_node = i2s_node;
14855 + dai->platforms->of_node = i2s_node;
14856 +
14857 + /*
14858 + * clk44gpio and clk48gpio are not required by all cards so
14859 + * don't check the error status.
14860 + */
14861 + snd_clk44gpio =
14862 + devm_gpiod_get(&pdev->dev, "clock44", GPIOD_OUT_LOW);
14863 +
14864 + snd_clk48gpio =
14865 + devm_gpiod_get(&pdev->dev, "clock48", GPIOD_OUT_LOW);
14866 +
14867 + if (drvdata->probe) {
14868 + ret = drvdata->probe(pdev);
14869 + if (ret < 0) {
14870 + dev_err(&pdev->dev, "Custom probe failed %d\n",
14871 + ret);
14872 + return ret;
14873 + }
14874 + }
14875 +
14876 + pr_debug("%s card: %s dai: %s stream: %s\n", __func__,
14877 + snd_rpi_wm8804.name,
14878 + dai->name, dai->stream_name);
14879 + }
14880 +
14881 + ret = devm_snd_soc_register_card(&pdev->dev, &snd_rpi_wm8804);
14882 + if (ret && ret != -EPROBE_DEFER)
14883 + dev_err(&pdev->dev, "Failed to register card %d\n", ret);
14884 +
14885 + return ret;
14886 +}
14887 +
14888 +static struct platform_driver snd_rpi_wm8804_driver = {
14889 + .driver = {
14890 + .name = "snd-rpi-wm8804",
14891 + .owner = THIS_MODULE,
14892 + .of_match_table = snd_rpi_wm8804_of_match,
14893 + },
14894 + .probe = snd_rpi_wm8804_probe,
14895 +};
14896 +MODULE_DEVICE_TABLE(of, snd_rpi_wm8804_of_match);
14897 +
14898 +module_platform_driver(snd_rpi_wm8804_driver);
14899 +
14900 +MODULE_AUTHOR("Tim Gover <tim.gover@raspberrypi.org>");
14901 +MODULE_DESCRIPTION("ASoC Raspberry Pi Hat generic digi driver for WM8804 based cards");
14902 +MODULE_LICENSE("GPL v2");
14903 --- a/sound/soc/codecs/Kconfig
14904 +++ b/sound/soc/codecs/Kconfig
14905 @@ -109,6 +109,7 @@ config SND_SOC_ALL_CODECS
14906 imply SND_SOC_ICS43432
14907 imply SND_SOC_INNO_RK3036
14908 imply SND_SOC_ISABELLE
14909 + imply SND_SOC_I_SABRE_CODEC
14910 imply SND_SOC_JZ4740_CODEC
14911 imply SND_SOC_JZ4725B_CODEC
14912 imply SND_SOC_JZ4760_CODEC
14913 @@ -116,6 +117,7 @@ config SND_SOC_ALL_CODECS
14914 imply SND_SOC_LM4857
14915 imply SND_SOC_LM49453
14916 imply SND_SOC_LOCHNAGAR_SC
14917 + imply SND_SOC_MA120X0P
14918 imply SND_SOC_MAX98088
14919 imply SND_SOC_MAX98090
14920 imply SND_SOC_MAX98095
14921 @@ -156,6 +158,7 @@ config SND_SOC_ALL_CODECS
14922 imply SND_SOC_PCM179X_SPI
14923 imply SND_SOC_PCM186X_I2C
14924 imply SND_SOC_PCM186X_SPI
14925 + imply SND_SOC_PCM1794A
14926 imply SND_SOC_PCM3008
14927 imply SND_SOC_PCM3060_I2C
14928 imply SND_SOC_PCM3060_SPI
14929 @@ -234,6 +237,7 @@ config SND_SOC_ALL_CODECS
14930 imply SND_SOC_TLV320ADCX140
14931 imply SND_SOC_TLV320AIC23_I2C
14932 imply SND_SOC_TLV320AIC23_SPI
14933 + imply SND_SOC_TAS5713
14934 imply SND_SOC_TLV320AIC26
14935 imply SND_SOC_TLV320AIC31XX
14936 imply SND_SOC_TLV320AIC32X4_I2C
14937 @@ -383,12 +387,12 @@ config SND_SOC_AD193X
14938 tristate
14939
14940 config SND_SOC_AD193X_SPI
14941 - tristate
14942 + tristate "Analog Devices AU193X CODEC - SPI"
14943 depends on SPI_MASTER
14944 select SND_SOC_AD193X
14945
14946 config SND_SOC_AD193X_I2C
14947 - tristate
14948 + tristate "Analog Devices AU193X CODEC - I2C"
14949 depends on I2C
14950 select SND_SOC_AD193X
14951
14952 @@ -991,6 +995,13 @@ config SND_SOC_LOCHNAGAR_SC
14953 This driver support the sound card functionality of the Cirrus
14954 Logic Lochnagar audio development board.
14955
14956 +config SND_SOC_MA120X0P
14957 + tristate "Infineon Merus(TM) MA120X0P Multilevel Class-D Audio amplifiers"
14958 + depends on I2C
14959 + help
14960 + Enable support for Infineon MA120X0P Multilevel Class-D audio power
14961 + amplifiers.
14962 +
14963 config SND_SOC_MADERA
14964 tristate
14965 default y if SND_SOC_CS47L15=y
14966 @@ -1333,6 +1344,10 @@ config SND_SOC_RT5616
14967 tristate "Realtek RT5616 CODEC"
14968 depends on I2C
14969
14970 +config SND_SOC_PCM1794A
14971 + tristate
14972 + depends on I2C
14973 +
14974 config SND_SOC_RT5631
14975 tristate "Realtek ALC5631/RT5631 CODEC"
14976 depends on I2C
14977 @@ -1623,6 +1638,9 @@ config SND_SOC_TFA9879
14978 tristate "NXP Semiconductors TFA9879 amplifier"
14979 depends on I2C
14980
14981 +config SND_SOC_TAS5713
14982 + tristate
14983 +
14984 config SND_SOC_TFA989X
14985 tristate "NXP/Goodix TFA989X (TFA1) amplifiers"
14986 depends on I2C
14987 @@ -2169,4 +2187,8 @@ config SND_SOC_LPASS_TX_MACRO
14988 select SND_SOC_LPASS_MACRO_COMMON
14989 tristate "Qualcomm TX Macro in LPASS(Low Power Audio SubSystem)"
14990
14991 +config SND_SOC_I_SABRE_CODEC
14992 + tristate "Audiophonics I-SABRE Codec"
14993 + depends on I2C
14994 +
14995 endmenu
14996 --- a/sound/soc/codecs/Makefile
14997 +++ b/sound/soc/codecs/Makefile
14998 @@ -113,6 +113,7 @@ snd-soc-hda-codec-objs := hda.o hda-dai.
14999 snd-soc-ics43432-objs := ics43432.o
15000 snd-soc-inno-rk3036-objs := inno_rk3036.o
15001 snd-soc-isabelle-objs := isabelle.o
15002 +snd-soc-i-sabre-codec-objs := i-sabre-codec.o
15003 snd-soc-jz4740-codec-objs := jz4740.o
15004 snd-soc-jz4725b-codec-objs := jz4725b.o
15005 snd-soc-jz4760-codec-objs := jz4760.o
15006 @@ -126,6 +127,7 @@ snd-soc-lpass-rx-macro-objs := lpass-rx-
15007 snd-soc-lpass-tx-macro-objs := lpass-tx-macro.o
15008 snd-soc-lpass-wsa-macro-objs := lpass-wsa-macro.o
15009 snd-soc-lpass-va-macro-objs := lpass-va-macro.o
15010 +snd-soc-ma120x0p-objs := ma120x0p.o
15011 snd-soc-madera-objs := madera.o
15012 snd-soc-max9759-objs := max9759.o
15013 snd-soc-max9768-objs := max9768.o
15014 @@ -172,6 +174,7 @@ snd-soc-pcm179x-spi-objs := pcm179x-spi.
15015 snd-soc-pcm186x-objs := pcm186x.o
15016 snd-soc-pcm186x-i2c-objs := pcm186x-i2c.o
15017 snd-soc-pcm186x-spi-objs := pcm186x-spi.o
15018 +snd-soc-pcm1794a-objs := pcm1794a.o
15019 snd-soc-pcm3008-objs := pcm3008.o
15020 snd-soc-pcm3060-objs := pcm3060.o
15021 snd-soc-pcm3060-i2c-objs := pcm3060-i2c.o
15022 @@ -256,6 +259,7 @@ snd-soc-tas6424-objs := tas6424.o
15023 snd-soc-tda7419-objs := tda7419.o
15024 snd-soc-tas2770-objs := tas2770.o
15025 snd-soc-tfa9879-objs := tfa9879.o
15026 +snd-soc-tas5713-objs := tas5713.o
15027 snd-soc-tfa989x-objs := tfa989x.o
15028 snd-soc-tlv320adc3xxx-objs := tlv320adc3xxx.o
15029 snd-soc-tlv320aic23-objs := tlv320aic23.o
15030 @@ -474,6 +478,7 @@ obj-$(CONFIG_SND_SOC_HDA) += snd-soc-hda
15031 obj-$(CONFIG_SND_SOC_ICS43432) += snd-soc-ics43432.o
15032 obj-$(CONFIG_SND_SOC_INNO_RK3036) += snd-soc-inno-rk3036.o
15033 obj-$(CONFIG_SND_SOC_ISABELLE) += snd-soc-isabelle.o
15034 +obj-$(CONFIG_SND_SOC_I_SABRE_CODEC) += snd-soc-i-sabre-codec.o
15035 obj-$(CONFIG_SND_SOC_JZ4740_CODEC) += snd-soc-jz4740-codec.o
15036 obj-$(CONFIG_SND_SOC_JZ4725B_CODEC) += snd-soc-jz4725b-codec.o
15037 obj-$(CONFIG_SND_SOC_JZ4760_CODEC) += snd-soc-jz4760-codec.o
15038 @@ -482,6 +487,7 @@ obj-$(CONFIG_SND_SOC_L3) += snd-soc-l3.o
15039 obj-$(CONFIG_SND_SOC_LM4857) += snd-soc-lm4857.o
15040 obj-$(CONFIG_SND_SOC_LM49453) += snd-soc-lm49453.o
15041 obj-$(CONFIG_SND_SOC_LOCHNAGAR_SC) += snd-soc-lochnagar-sc.o
15042 +obj-$(CONFIG_SND_SOC_MA120X0P) += snd-soc-ma120x0p.o
15043 obj-$(CONFIG_SND_SOC_MADERA) += snd-soc-madera.o
15044 obj-$(CONFIG_SND_SOC_MAX9759) += snd-soc-max9759.o
15045 obj-$(CONFIG_SND_SOC_MAX9768) += snd-soc-max9768.o
15046 @@ -539,6 +545,7 @@ obj-$(CONFIG_SND_SOC_PCM5102A) += snd-so
15047 obj-$(CONFIG_SND_SOC_PCM512x) += snd-soc-pcm512x.o
15048 obj-$(CONFIG_SND_SOC_PCM512x_I2C) += snd-soc-pcm512x-i2c.o
15049 obj-$(CONFIG_SND_SOC_PCM512x_SPI) += snd-soc-pcm512x-spi.o
15050 +obj-$(CONFIG_SND_SOC_PCM1794A) += snd-soc-pcm1794a.o
15051 obj-$(CONFIG_SND_SOC_RK3328) += snd-soc-rk3328.o
15052 obj-$(CONFIG_SND_SOC_RK817) += snd-soc-rk817.o
15053 obj-$(CONFIG_SND_SOC_RL6231) += snd-soc-rl6231.o
15054 @@ -613,6 +620,7 @@ obj-$(CONFIG_SND_SOC_TAS5805M) += snd-so
15055 obj-$(CONFIG_SND_SOC_TAS6424) += snd-soc-tas6424.o
15056 obj-$(CONFIG_SND_SOC_TDA7419) += snd-soc-tda7419.o
15057 obj-$(CONFIG_SND_SOC_TAS2770) += snd-soc-tas2770.o
15058 +obj-$(CONFIG_SND_SOC_TAS5713) += snd-soc-tas5713.o
15059 obj-$(CONFIG_SND_SOC_TFA9879) += snd-soc-tfa9879.o
15060 obj-$(CONFIG_SND_SOC_TFA989X) += snd-soc-tfa989x.o
15061 obj-$(CONFIG_SND_SOC_TLV320ADC3XXX) += snd-soc-tlv320adc3xxx.o
15062 --- a/sound/soc/codecs/cs42xx8-i2c.c
15063 +++ b/sound/soc/codecs/cs42xx8-i2c.c
15064 @@ -42,11 +42,18 @@ static struct i2c_device_id cs42xx8_i2c_
15065 };
15066 MODULE_DEVICE_TABLE(i2c, cs42xx8_i2c_id);
15067
15068 +const struct of_device_id cs42xx8_i2c_of_match[] = {
15069 + { .compatible = "cirrus,cs42448", .data = &cs42448_data, },
15070 + { .compatible = "cirrus,cs42888", .data = &cs42888_data, },
15071 + { /* sentinel */ }
15072 +};
15073 +MODULE_DEVICE_TABLE(of, cs42xx8_i2c_of_match);
15074 +
15075 static struct i2c_driver cs42xx8_i2c_driver = {
15076 .driver = {
15077 .name = "cs42xx8",
15078 .pm = &cs42xx8_pm,
15079 - .of_match_table = cs42xx8_of_match,
15080 + .of_match_table = cs42xx8_i2c_of_match,
15081 },
15082 .probe_new = cs42xx8_i2c_probe,
15083 .remove = cs42xx8_i2c_remove,
15084 --- a/sound/soc/codecs/cs42xx8.c
15085 +++ b/sound/soc/codecs/cs42xx8.c
15086 @@ -516,8 +516,10 @@ const struct of_device_id cs42xx8_of_mat
15087 { .compatible = "cirrus,cs42888", .data = &cs42888_data, },
15088 { /* sentinel */ }
15089 };
15090 +#if !IS_ENABLED(CONFIG_SND_SOC_CS42XX8_I2C)
15091 MODULE_DEVICE_TABLE(of, cs42xx8_of_match);
15092 EXPORT_SYMBOL_GPL(cs42xx8_of_match);
15093 +#endif
15094
15095 int cs42xx8_probe(struct device *dev, struct regmap *regmap)
15096 {
15097 --- /dev/null
15098 +++ b/sound/soc/codecs/i-sabre-codec.c
15099 @@ -0,0 +1,390 @@
15100 +/*
15101 + * Driver for I-Sabre Q2M
15102 + *
15103 + * Author: Satoru Kawase
15104 + * Modified by: Xiao Qingyong
15105 + * Modified by: JC BARBAUD (Mute)
15106 + * Update kernel v4.18+ by : Audiophonics
15107 + * Copyright 2018 Audiophonics
15108 + *
15109 + * This program is free software; you can redistribute it and/or
15110 + * modify it under the terms of the GNU General Public License
15111 + * version 2 as published by the Free Software Foundation.
15112 + *
15113 + * This program is distributed in the hope that it will be useful, but
15114 + * WITHOUT ANY WARRANTY; without even the implied warranty of
15115 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15116 + * General Public License for more details.
15117 + */
15118 +
15119 +
15120 +#include <linux/init.h>
15121 +#include <linux/module.h>
15122 +#include <linux/regmap.h>
15123 +#include <linux/i2c.h>
15124 +#include <sound/soc.h>
15125 +#include <sound/pcm_params.h>
15126 +#include <sound/tlv.h>
15127 +
15128 +#include "i-sabre-codec.h"
15129 +
15130 +
15131 +/* I-Sabre Q2M Codec Private Data */
15132 +struct i_sabre_codec_priv {
15133 + struct regmap *regmap;
15134 + unsigned int fmt;
15135 +};
15136 +
15137 +
15138 +/* I-Sabre Q2M Codec Default Register Value */
15139 +static const struct reg_default i_sabre_codec_reg_defaults[] = {
15140 + { ISABRECODEC_REG_10, 0x00 },
15141 + { ISABRECODEC_REG_20, 0x00 },
15142 + { ISABRECODEC_REG_21, 0x00 },
15143 + { ISABRECODEC_REG_22, 0x00 },
15144 + { ISABRECODEC_REG_24, 0x00 },
15145 +};
15146 +
15147 +
15148 +static bool i_sabre_codec_writeable(struct device *dev, unsigned int reg)
15149 +{
15150 + switch (reg) {
15151 + case ISABRECODEC_REG_10:
15152 + case ISABRECODEC_REG_20:
15153 + case ISABRECODEC_REG_21:
15154 + case ISABRECODEC_REG_22:
15155 + case ISABRECODEC_REG_24:
15156 + return true;
15157 +
15158 + default:
15159 + return false;
15160 + }
15161 +}
15162 +
15163 +static bool i_sabre_codec_readable(struct device *dev, unsigned int reg)
15164 +{
15165 + switch (reg) {
15166 + case ISABRECODEC_REG_01:
15167 + case ISABRECODEC_REG_02:
15168 + case ISABRECODEC_REG_10:
15169 + case ISABRECODEC_REG_20:
15170 + case ISABRECODEC_REG_21:
15171 + case ISABRECODEC_REG_22:
15172 + case ISABRECODEC_REG_24:
15173 + return true;
15174 +
15175 + default:
15176 + return false;
15177 + }
15178 +}
15179 +
15180 +static bool i_sabre_codec_volatile(struct device *dev, unsigned int reg)
15181 +{
15182 + switch (reg) {
15183 + case ISABRECODEC_REG_01:
15184 + case ISABRECODEC_REG_02:
15185 + return true;
15186 +
15187 + default:
15188 + return false;
15189 + }
15190 +}
15191 +
15192 +
15193 +/* Volume Scale */
15194 +static const DECLARE_TLV_DB_SCALE(volume_tlv, -10000, 100, 0);
15195 +
15196 +
15197 +/* Filter Type */
15198 +static const char * const fir_filter_type_texts[] = {
15199 + "brick wall",
15200 + "corrected minimum phase fast",
15201 + "minimum phase slow",
15202 + "minimum phase fast",
15203 + "linear phase slow",
15204 + "linear phase fast",
15205 + "apodizing fast",
15206 +};
15207 +
15208 +static SOC_ENUM_SINGLE_DECL(i_sabre_fir_filter_type_enum,
15209 + ISABRECODEC_REG_22, 0, fir_filter_type_texts);
15210 +
15211 +
15212 +/* I2S / SPDIF Select */
15213 +static const char * const iis_spdif_sel_texts[] = {
15214 + "I2S",
15215 + "SPDIF",
15216 +};
15217 +
15218 +static SOC_ENUM_SINGLE_DECL(i_sabre_iis_spdif_sel_enum,
15219 + ISABRECODEC_REG_24, 0, iis_spdif_sel_texts);
15220 +
15221 +
15222 +/* Control */
15223 +static const struct snd_kcontrol_new i_sabre_codec_controls[] = {
15224 +SOC_SINGLE_RANGE_TLV("Digital Playback Volume", ISABRECODEC_REG_20, 0, 0, 100, 1, volume_tlv),
15225 +SOC_SINGLE("Digital Playback Switch", ISABRECODEC_REG_21, 0, 1, 1),
15226 +SOC_ENUM("FIR Filter Type", i_sabre_fir_filter_type_enum),
15227 +SOC_ENUM("I2S/SPDIF Select", i_sabre_iis_spdif_sel_enum),
15228 +};
15229 +
15230 +
15231 +static const u32 i_sabre_codec_dai_rates_slave[] = {
15232 + 8000, 11025, 16000, 22050, 32000,
15233 + 44100, 48000, 64000, 88200, 96000,
15234 + 176400, 192000, 352800, 384000,
15235 + 705600, 768000, 1411200, 1536000
15236 +};
15237 +
15238 +static const struct snd_pcm_hw_constraint_list constraints_slave = {
15239 + .list = i_sabre_codec_dai_rates_slave,
15240 + .count = ARRAY_SIZE(i_sabre_codec_dai_rates_slave),
15241 +};
15242 +
15243 +static int i_sabre_codec_dai_startup_slave(
15244 + struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
15245 +{
15246 + struct snd_soc_component *component = dai->component;
15247 + int ret;
15248 +
15249 + ret = snd_pcm_hw_constraint_list(substream->runtime,
15250 + 0, SNDRV_PCM_HW_PARAM_RATE, &constraints_slave);
15251 + if (ret != 0) {
15252 + dev_err(component->card->dev, "Failed to setup rates constraints: %d\n", ret);
15253 + }
15254 +
15255 + return ret;
15256 +}
15257 +
15258 +static int i_sabre_codec_dai_startup(
15259 + struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
15260 +{
15261 + struct snd_soc_component *component = dai->component;
15262 + struct i_sabre_codec_priv *i_sabre_codec
15263 + = snd_soc_component_get_drvdata(component);
15264 +
15265 + switch (i_sabre_codec->fmt & SND_SOC_DAIFMT_MASTER_MASK) {
15266 + case SND_SOC_DAIFMT_CBS_CFS:
15267 + return i_sabre_codec_dai_startup_slave(substream, dai);
15268 +
15269 + default:
15270 + return (-EINVAL);
15271 + }
15272 +}
15273 +
15274 +static int i_sabre_codec_hw_params(
15275 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params,
15276 + struct snd_soc_dai *dai)
15277 +{
15278 + struct snd_soc_component *component = dai->component;
15279 + struct i_sabre_codec_priv *i_sabre_codec
15280 + = snd_soc_component_get_drvdata(component);
15281 + unsigned int daifmt;
15282 + int format_width;
15283 +
15284 + dev_dbg(component->card->dev, "hw_params %u Hz, %u channels\n",
15285 + params_rate(params), params_channels(params));
15286 +
15287 + /* Check I2S Format (Bit Size) */
15288 + format_width = snd_pcm_format_width(params_format(params));
15289 + if ((format_width != 32) && (format_width != 16)) {
15290 + dev_err(component->card->dev, "Bad frame size: %d\n",
15291 + snd_pcm_format_width(params_format(params)));
15292 + return (-EINVAL);
15293 + }
15294 +
15295 + /* Check Slave Mode */
15296 + daifmt = i_sabre_codec->fmt & SND_SOC_DAIFMT_MASTER_MASK;
15297 + if (daifmt != SND_SOC_DAIFMT_CBS_CFS) {
15298 + return (-EINVAL);
15299 + }
15300 +
15301 + /* Notify Sampling Frequency */
15302 + switch (params_rate(params))
15303 + {
15304 + case 44100:
15305 + case 48000:
15306 + case 88200:
15307 + case 96000:
15308 + case 176400:
15309 + case 192000:
15310 + snd_soc_component_update_bits(component, ISABRECODEC_REG_10, 0x01, 0x00);
15311 + break;
15312 +
15313 + case 352800:
15314 + case 384000:
15315 + case 705600:
15316 + case 768000:
15317 + case 1411200:
15318 + case 1536000:
15319 + snd_soc_component_update_bits(component, ISABRECODEC_REG_10, 0x01, 0x01);
15320 + break;
15321 + }
15322 +
15323 + return 0;
15324 +}
15325 +
15326 +static int i_sabre_codec_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
15327 +{
15328 + struct snd_soc_component *component = dai->component;
15329 + struct i_sabre_codec_priv *i_sabre_codec
15330 + = snd_soc_component_get_drvdata(component);
15331 +
15332 + /* interface format */
15333 + switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
15334 + case SND_SOC_DAIFMT_I2S:
15335 + break;
15336 +
15337 + case SND_SOC_DAIFMT_RIGHT_J:
15338 + case SND_SOC_DAIFMT_LEFT_J:
15339 + default:
15340 + return (-EINVAL);
15341 + }
15342 +
15343 + /* clock inversion */
15344 + if ((fmt & SND_SOC_DAIFMT_INV_MASK) != SND_SOC_DAIFMT_NB_NF) {
15345 + return (-EINVAL);
15346 + }
15347 +
15348 + /* Set Audio Data Format */
15349 + i_sabre_codec->fmt = fmt;
15350 +
15351 + return 0;
15352 +}
15353 +
15354 +static int i_sabre_codec_dac_mute(struct snd_soc_dai *dai, int mute, int direction)
15355 +{
15356 + struct snd_soc_component *component = dai->component;
15357 +
15358 + if (mute) {
15359 + snd_soc_component_update_bits(component, ISABRECODEC_REG_21, 0x01, 0x01);
15360 + } else {
15361 + snd_soc_component_update_bits(component, ISABRECODEC_REG_21, 0x01, 0x00);
15362 + }
15363 +
15364 + return 0;
15365 +}
15366 +
15367 +
15368 +static const struct snd_soc_dai_ops i_sabre_codec_dai_ops = {
15369 + .startup = i_sabre_codec_dai_startup,
15370 + .hw_params = i_sabre_codec_hw_params,
15371 + .set_fmt = i_sabre_codec_set_fmt,
15372 + .mute_stream = i_sabre_codec_dac_mute,
15373 +};
15374 +
15375 +static struct snd_soc_dai_driver i_sabre_codec_dai = {
15376 + .name = "i-sabre-codec-dai",
15377 + .playback = {
15378 + .stream_name = "Playback",
15379 + .channels_min = 2,
15380 + .channels_max = 2,
15381 + .rates = SNDRV_PCM_RATE_CONTINUOUS,
15382 + .rate_min = 8000,
15383 + .rate_max = 1536000,
15384 + .formats = SNDRV_PCM_FMTBIT_S16_LE
15385 + | SNDRV_PCM_FMTBIT_S32_LE,
15386 + },
15387 + .ops = &i_sabre_codec_dai_ops,
15388 +};
15389 +
15390 +static struct snd_soc_component_driver i_sabre_codec_codec_driver = {
15391 + .controls = i_sabre_codec_controls,
15392 + .num_controls = ARRAY_SIZE(i_sabre_codec_controls),
15393 +};
15394 +
15395 +
15396 +static const struct regmap_config i_sabre_codec_regmap = {
15397 + .reg_bits = 8,
15398 + .val_bits = 8,
15399 + .max_register = ISABRECODEC_MAX_REG,
15400 +
15401 + .reg_defaults = i_sabre_codec_reg_defaults,
15402 + .num_reg_defaults = ARRAY_SIZE(i_sabre_codec_reg_defaults),
15403 +
15404 + .writeable_reg = i_sabre_codec_writeable,
15405 + .readable_reg = i_sabre_codec_readable,
15406 + .volatile_reg = i_sabre_codec_volatile,
15407 +
15408 + .cache_type = REGCACHE_RBTREE,
15409 +};
15410 +
15411 +
15412 +static int i_sabre_codec_probe(struct device *dev, struct regmap *regmap)
15413 +{
15414 + struct i_sabre_codec_priv *i_sabre_codec;
15415 + int ret;
15416 +
15417 + i_sabre_codec = devm_kzalloc(dev, sizeof(*i_sabre_codec), GFP_KERNEL);
15418 + if (!i_sabre_codec) {
15419 + dev_err(dev, "devm_kzalloc");
15420 + return (-ENOMEM);
15421 + }
15422 +
15423 + i_sabre_codec->regmap = regmap;
15424 +
15425 + dev_set_drvdata(dev, i_sabre_codec);
15426 +
15427 + ret = snd_soc_register_component(dev,
15428 + &i_sabre_codec_codec_driver, &i_sabre_codec_dai, 1);
15429 + if (ret != 0) {
15430 + dev_err(dev, "Failed to register CODEC: %d\n", ret);
15431 + return ret;
15432 + }
15433 +
15434 + return 0;
15435 +}
15436 +
15437 +static void i_sabre_codec_remove(struct device *dev)
15438 +{
15439 + snd_soc_unregister_component(dev);
15440 +}
15441 +
15442 +
15443 +static int i_sabre_codec_i2c_probe(
15444 + struct i2c_client *i2c, const struct i2c_device_id *id)
15445 +{
15446 + struct regmap *regmap;
15447 +
15448 + regmap = devm_regmap_init_i2c(i2c, &i_sabre_codec_regmap);
15449 + if (IS_ERR(regmap)) {
15450 + return PTR_ERR(regmap);
15451 + }
15452 +
15453 + return i_sabre_codec_probe(&i2c->dev, regmap);
15454 +}
15455 +
15456 +static void i_sabre_codec_i2c_remove(struct i2c_client *i2c)
15457 +{
15458 + i_sabre_codec_remove(&i2c->dev);
15459 +}
15460 +
15461 +
15462 +static const struct i2c_device_id i_sabre_codec_i2c_id[] = {
15463 + { "i-sabre-codec", },
15464 + { }
15465 +};
15466 +MODULE_DEVICE_TABLE(i2c, i_sabre_codec_i2c_id);
15467 +
15468 +static const struct of_device_id i_sabre_codec_of_match[] = {
15469 + { .compatible = "audiophonics,i-sabre-codec", },
15470 + { }
15471 +};
15472 +MODULE_DEVICE_TABLE(of, i_sabre_codec_of_match);
15473 +
15474 +static struct i2c_driver i_sabre_codec_i2c_driver = {
15475 + .driver = {
15476 + .name = "i-sabre-codec-i2c",
15477 + .owner = THIS_MODULE,
15478 + .of_match_table = of_match_ptr(i_sabre_codec_of_match),
15479 + },
15480 + .probe = i_sabre_codec_i2c_probe,
15481 + .remove = i_sabre_codec_i2c_remove,
15482 + .id_table = i_sabre_codec_i2c_id,
15483 +};
15484 +module_i2c_driver(i_sabre_codec_i2c_driver);
15485 +
15486 +
15487 +MODULE_DESCRIPTION("ASoC I-Sabre Q2M codec driver");
15488 +MODULE_AUTHOR("Audiophonics <http://www.audiophonics.fr>");
15489 +MODULE_LICENSE("GPL");
15490 --- /dev/null
15491 +++ b/sound/soc/codecs/i-sabre-codec.h
15492 @@ -0,0 +1,42 @@
15493 +/*
15494 + * Driver for I-Sabre Q2M
15495 + *
15496 + * Author: Satoru Kawase
15497 + * Modified by: Xiao Qingyong
15498 + * Copyright 2018 Audiophonics
15499 + *
15500 + * This program is free software; you can redistribute it and/or
15501 + * modify it under the terms of the GNU General Public License
15502 + * version 2 as published by the Free Software Foundation.
15503 + *
15504 + * This program is distributed in the hope that it will be useful, but
15505 + * WITHOUT ANY WARRANTY; without even the implied warranty of
15506 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15507 + * General Public License for more details.
15508 + */
15509 +
15510 +#ifndef _SND_SOC_ISABRECODEC
15511 +#define _SND_SOC_ISABRECODEC
15512 +
15513 +
15514 +/* ISABRECODEC Register Address */
15515 +#define ISABRECODEC_REG_01 0x01 /* Virtual Device ID : 0x01 = es9038q2m */
15516 +#define ISABRECODEC_REG_02 0x02 /* API revision : 0x01 = Revision 01 */
15517 +#define ISABRECODEC_REG_10 0x10 /* 0x01 = above 192kHz, 0x00 = otherwise */
15518 +#define ISABRECODEC_REG_20 0x20 /* 0 - 100 (decimal value, 0 = min., 100 = max.) */
15519 +#define ISABRECODEC_REG_21 0x21 /* 0x00 = Mute OFF, 0x01 = Mute ON */
15520 +#define ISABRECODEC_REG_22 0x22
15521 +/*
15522 + 0x00 = brick wall,
15523 + 0x01 = corrected minimum phase fast,
15524 + 0x02 = minimum phase slow,
15525 + 0x03 = minimum phase fast,
15526 + 0x04 = linear phase slow,
15527 + 0x05 = linear phase fast,
15528 + 0x06 = apodizing fast,
15529 +*/
15530 +//#define ISABRECODEC_REG_23 0x23 /* reserved */
15531 +#define ISABRECODEC_REG_24 0x24 /* 0x00 = I2S, 0x01 = SPDIF */
15532 +#define ISABRECODEC_MAX_REG 0x24 /* Maximum Register Number */
15533 +
15534 +#endif /* _SND_SOC_ISABRECODEC */
15535 --- /dev/null
15536 +++ b/sound/soc/codecs/ma120x0p.c
15537 @@ -0,0 +1,1381 @@
15538 +// SPDX-License-Identifier: GPL-2.0-or-later
15539 +/*
15540 + * ASoC Driver for Infineon Merus(TM) ma120x0p multi-level class-D amplifier
15541 + *
15542 + * Authors: Ariel Muszkat <ariel.muszkat@gmail.com>
15543 + * Jorgen Kragh Jakobsen <jorgen.kraghjakobsen@infineon.com>
15544 + *
15545 + * Copyright (C) 2019 Infineon Technologies AG
15546 + *
15547 + */
15548 +#include <linux/module.h>
15549 +#include <linux/moduleparam.h>
15550 +#include <linux/init.h>
15551 +#include <linux/delay.h>
15552 +#include <linux/pm_runtime.h>
15553 +#include <linux/i2c.h>
15554 +#include <linux/of_device.h>
15555 +#include <linux/spi/spi.h>
15556 +#include <linux/regmap.h>
15557 +#include <linux/regulator/consumer.h>
15558 +#include <linux/slab.h>
15559 +#include <linux/gpio/consumer.h>
15560 +#include <linux/gpio.h>
15561 +#include <sound/core.h>
15562 +#include <sound/pcm.h>
15563 +#include <sound/pcm_params.h>
15564 +#include <sound/soc.h>
15565 +#include <sound/soc-dapm.h>
15566 +#include <sound/initval.h>
15567 +#include <sound/tlv.h>
15568 +#include <linux/interrupt.h>
15569 +
15570 +#include <linux/kernel.h>
15571 +#include <linux/string.h>
15572 +#include <linux/fs.h>
15573 +#include <linux/uaccess.h>
15574 +
15575 +#ifndef _MA120X0P_
15576 +#define _MA120X0P_
15577 +//------------------------------------------------------------------manualPM---
15578 +// Select Manual PowerMode control
15579 +#define ma_manualpm__a 0
15580 +#define ma_manualpm__len 1
15581 +#define ma_manualpm__mask 0x40
15582 +#define ma_manualpm__shift 0x06
15583 +#define ma_manualpm__reset 0x00
15584 +//--------------------------------------------------------------------pm_man---
15585 +// manual selected power mode
15586 +#define ma_pm_man__a 0
15587 +#define ma_pm_man__len 2
15588 +#define ma_pm_man__mask 0x30
15589 +#define ma_pm_man__shift 0x04
15590 +#define ma_pm_man__reset 0x03
15591 +//------------------------------------------ ----------------------mthr_1to2---
15592 +// mod. index threshold value for pm1=>pm2 change.
15593 +#define ma_mthr_1to2__a 1
15594 +#define ma_mthr_1to2__len 8
15595 +#define ma_mthr_1to2__mask 0xff
15596 +#define ma_mthr_1to2__shift 0x00
15597 +#define ma_mthr_1to2__reset 0x3c
15598 +//-----------------------------------------------------------------mthr_2to1---
15599 +// mod. index threshold value for pm2=>pm1 change.
15600 +#define ma_mthr_2to1__a 2
15601 +#define ma_mthr_2to1__len 8
15602 +#define ma_mthr_2to1__mask 0xff
15603 +#define ma_mthr_2to1__shift 0x00
15604 +#define ma_mthr_2to1__reset 0x32
15605 +//-----------------------------------------------------------------mthr_2to3---
15606 +// mod. index threshold value for pm2=>pm3 change.
15607 +#define ma_mthr_2to3__a 3
15608 +#define ma_mthr_2to3__len 8
15609 +#define ma_mthr_2to3__mask 0xff
15610 +#define ma_mthr_2to3__shift 0x00
15611 +#define ma_mthr_2to3__reset 0x5a
15612 +//-----------------------------------------------------------------mthr_3to2---
15613 +// mod. index threshold value for pm3=>pm2 change.
15614 +#define ma_mthr_3to2__a 4
15615 +#define ma_mthr_3to2__len 8
15616 +#define ma_mthr_3to2__mask 0xff
15617 +#define ma_mthr_3to2__shift 0x00
15618 +#define ma_mthr_3to2__reset 0x50
15619 +//-------------------------------------------------------------pwmclkdiv_nom---
15620 +// pwm default clock divider value
15621 +#define ma_pwmclkdiv_nom__a 8
15622 +#define ma_pwmclkdiv_nom__len 8
15623 +#define ma_pwmclkdiv_nom__mask 0xff
15624 +#define ma_pwmclkdiv_nom__shift 0x00
15625 +#define ma_pwmclkdiv_nom__reset 0x26
15626 +//--------- ----------------------------------------------------ocp_latch_en---
15627 +// high to use permanently latching level-2 ocp
15628 +#define ma_ocp_latch_en__a 10
15629 +#define ma_ocp_latch_en__len 1
15630 +#define ma_ocp_latch_en__mask 0x02
15631 +#define ma_ocp_latch_en__shift 0x01
15632 +#define ma_ocp_latch_en__reset 0x00
15633 +//---------------------------------------------------------------lf_clamp_en---
15634 +// high (default) to enable lf int2+3 clamping on clip
15635 +#define ma_lf_clamp_en__a 10
15636 +#define ma_lf_clamp_en__len 1
15637 +#define ma_lf_clamp_en__mask 0x80
15638 +#define ma_lf_clamp_en__shift 0x07
15639 +#define ma_lf_clamp_en__reset 0x00
15640 +//-------------------------------------------------------pmcfg_btl_b.modtype---
15641 +//
15642 +#define ma_pmcfg_btl_b__modtype__a 18
15643 +#define ma_pmcfg_btl_b__modtype__len 2
15644 +#define ma_pmcfg_btl_b__modtype__mask 0x18
15645 +#define ma_pmcfg_btl_b__modtype__shift 0x03
15646 +#define ma_pmcfg_btl_b__modtype__reset 0x02
15647 +//-------------------------------------------------------pmcfg_btl_b.freqdiv---
15648 +#define ma_pmcfg_btl_b__freqdiv__a 18
15649 +#define ma_pmcfg_btl_b__freqdiv__len 2
15650 +#define ma_pmcfg_btl_b__freqdiv__mask 0x06
15651 +#define ma_pmcfg_btl_b__freqdiv__shift 0x01
15652 +#define ma_pmcfg_btl_b__freqdiv__reset 0x01
15653 +//----------------------------------------------------pmcfg_btl_b.lf_gain_ol---
15654 +//
15655 +#define ma_pmcfg_btl_b__lf_gain_ol__a 18
15656 +#define ma_pmcfg_btl_b__lf_gain_ol__len 1
15657 +#define ma_pmcfg_btl_b__lf_gain_ol__mask 0x01
15658 +#define ma_pmcfg_btl_b__lf_gain_ol__shift 0x00
15659 +#define ma_pmcfg_btl_b__lf_gain_ol__reset 0x01
15660 +//-------------------------------------------------------pmcfg_btl_c.freqdiv---
15661 +//
15662 +#define ma_pmcfg_btl_c__freqdiv__a 19
15663 +#define ma_pmcfg_btl_c__freqdiv__len 2
15664 +#define ma_pmcfg_btl_c__freqdiv__mask 0x06
15665 +#define ma_pmcfg_btl_c__freqdiv__shift 0x01
15666 +#define ma_pmcfg_btl_c__freqdiv__reset 0x01
15667 +//-------------------------------------------------------pmcfg_btl_c.modtype---
15668 +//
15669 +#define ma_pmcfg_btl_c__modtype__a 19
15670 +#define ma_pmcfg_btl_c__modtype__len 2
15671 +#define ma_pmcfg_btl_c__modtype__mask 0x18
15672 +#define ma_pmcfg_btl_c__modtype__shift 0x03
15673 +#define ma_pmcfg_btl_c__modtype__reset 0x01
15674 +//----------------------------------------------------pmcfg_btl_c.lf_gain_ol---
15675 +//
15676 +#define ma_pmcfg_btl_c__lf_gain_ol__a 19
15677 +#define ma_pmcfg_btl_c__lf_gain_ol__len 1
15678 +#define ma_pmcfg_btl_c__lf_gain_ol__mask 0x01
15679 +#define ma_pmcfg_btl_c__lf_gain_ol__shift 0x00
15680 +#define ma_pmcfg_btl_c__lf_gain_ol__reset 0x00
15681 +//-------------------------------------------------------pmcfg_btl_d.modtype---
15682 +//
15683 +#define ma_pmcfg_btl_d__modtype__a 20
15684 +#define ma_pmcfg_btl_d__modtype__len 2
15685 +#define ma_pmcfg_btl_d__modtype__mask 0x18
15686 +#define ma_pmcfg_btl_d__modtype__shift 0x03
15687 +#define ma_pmcfg_btl_d__modtype__reset 0x02
15688 +//-------------------------------------------------------pmcfg_btl_d.freqdiv---
15689 +//
15690 +#define ma_pmcfg_btl_d__freqdiv__a 20
15691 +#define ma_pmcfg_btl_d__freqdiv__len 2
15692 +#define ma_pmcfg_btl_d__freqdiv__mask 0x06
15693 +#define ma_pmcfg_btl_d__freqdiv__shift 0x01
15694 +#define ma_pmcfg_btl_d__freqdiv__reset 0x02
15695 +//----------------------------------------------------pmcfg_btl_d.lf_gain_ol---
15696 +//
15697 +#define ma_pmcfg_btl_d__lf_gain_ol__a 20
15698 +#define ma_pmcfg_btl_d__lf_gain_ol__len 1
15699 +#define ma_pmcfg_btl_d__lf_gain_ol__mask 0x01
15700 +#define ma_pmcfg_btl_d__lf_gain_ol__shift 0x00
15701 +#define ma_pmcfg_btl_d__lf_gain_ol__reset 0x00
15702 +//------------ -------------------------------------------pmcfg_se_a.modtype---
15703 +//
15704 +#define ma_pmcfg_se_a__modtype__a 21
15705 +#define ma_pmcfg_se_a__modtype__len 2
15706 +#define ma_pmcfg_se_a__modtype__mask 0x18
15707 +#define ma_pmcfg_se_a__modtype__shift 0x03
15708 +#define ma_pmcfg_se_a__modtype__reset 0x01
15709 +//--------------------------------------------------------pmcfg_se_a.freqdiv---
15710 +//
15711 +#define ma_pmcfg_se_a__freqdiv__a 21
15712 +#define ma_pmcfg_se_a__freqdiv__len 2
15713 +#define ma_pmcfg_se_a__freqdiv__mask 0x06
15714 +#define ma_pmcfg_se_a__freqdiv__shift 0x01
15715 +#define ma_pmcfg_se_a__freqdiv__reset 0x00
15716 +//-----------------------------------------------------pmcfg_se_a.lf_gain_ol---
15717 +//
15718 +#define ma_pmcfg_se_a__lf_gain_ol__a 21
15719 +#define ma_pmcfg_se_a__lf_gain_ol__len 1
15720 +#define ma_pmcfg_se_a__lf_gain_ol__mask 0x01
15721 +#define ma_pmcfg_se_a__lf_gain_ol__shift 0x00
15722 +#define ma_pmcfg_se_a__lf_gain_ol__reset 0x01
15723 +//-----------------------------------------------------pmcfg_se_b.lf_gain_ol---
15724 +//
15725 +#define ma_pmcfg_se_b__lf_gain_ol__a 22
15726 +#define ma_pmcfg_se_b__lf_gain_ol__len 1
15727 +#define ma_pmcfg_se_b__lf_gain_ol__mask 0x01
15728 +#define ma_pmcfg_se_b__lf_gain_ol__shift 0x00
15729 +#define ma_pmcfg_se_b__lf_gain_ol__reset 0x00
15730 +//--------------------------------------------------------pmcfg_se_b.freqdiv---
15731 +//
15732 +#define ma_pmcfg_se_b__freqdiv__a 22
15733 +#define ma_pmcfg_se_b__freqdiv__len 2
15734 +#define ma_pmcfg_se_b__freqdiv__mask 0x06
15735 +#define ma_pmcfg_se_b__freqdiv__shift 0x01
15736 +#define ma_pmcfg_se_b__freqdiv__reset 0x01
15737 +//--------------------------------------------------------pmcfg_se_b.modtype---
15738 +//
15739 +#define ma_pmcfg_se_b__modtype__a 22
15740 +#define ma_pmcfg_se_b__modtype__len 2
15741 +#define ma_pmcfg_se_b__modtype__mask 0x18
15742 +#define ma_pmcfg_se_b__modtype__shift 0x03
15743 +#define ma_pmcfg_se_b__modtype__reset 0x01
15744 +//----------------------------------------------------------balwaitcount_pm1---
15745 +// pm1 balancing period.
15746 +#define ma_balwaitcount_pm1__a 23
15747 +#define ma_balwaitcount_pm1__len 8
15748 +#define ma_balwaitcount_pm1__mask 0xff
15749 +#define ma_balwaitcount_pm1__shift 0x00
15750 +#define ma_balwaitcount_pm1__reset 0x14
15751 +//----------------------------------------------------------balwaitcount_pm2---
15752 +// pm2 balancing period.
15753 +#define ma_balwaitcount_pm2__a 24
15754 +#define ma_balwaitcount_pm2__len 8
15755 +#define ma_balwaitcount_pm2__mask 0xff
15756 +#define ma_balwaitcount_pm2__shift 0x00
15757 +#define ma_balwaitcount_pm2__reset 0x14
15758 +//----------------------------------------------------------balwaitcount_pm3---
15759 +// pm3 balancing period.
15760 +#define ma_balwaitcount_pm3__a 25
15761 +#define ma_balwaitcount_pm3__len 8
15762 +#define ma_balwaitcount_pm3__mask 0xff
15763 +#define ma_balwaitcount_pm3__shift 0x00
15764 +#define ma_balwaitcount_pm3__reset 0x1a
15765 +//-------------------------------------------------------------usespread_pm1---
15766 +// pm1 pwm spread-spectrum mode on/off.
15767 +#define ma_usespread_pm1__a 26
15768 +#define ma_usespread_pm1__len 1
15769 +#define ma_usespread_pm1__mask 0x40
15770 +#define ma_usespread_pm1__shift 0x06
15771 +#define ma_usespread_pm1__reset 0x00
15772 +//---------------------------------------------------------------dtsteps_pm1---
15773 +// pm1 dead time setting [10ns steps].
15774 +#define ma_dtsteps_pm1__a 26
15775 +#define ma_dtsteps_pm1__len 3
15776 +#define ma_dtsteps_pm1__mask 0x38
15777 +#define ma_dtsteps_pm1__shift 0x03
15778 +#define ma_dtsteps_pm1__reset 0x04
15779 +//---------------------------------------------------------------baltype_pm1---
15780 +// pm1 balancing sensor scheme.
15781 +#define ma_baltype_pm1__a 26
15782 +#define ma_baltype_pm1__len 3
15783 +#define ma_baltype_pm1__mask 0x07
15784 +#define ma_baltype_pm1__shift 0x00
15785 +#define ma_baltype_pm1__reset 0x00
15786 +//-------------------------------------------------------------usespread_pm2---
15787 +// pm2 pwm spread-spectrum mode on/off.
15788 +#define ma_usespread_pm2__a 27
15789 +#define ma_usespread_pm2__len 1
15790 +#define ma_usespread_pm2__mask 0x40
15791 +#define ma_usespread_pm2__shift 0x06
15792 +#define ma_usespread_pm2__reset 0x00
15793 +//---------------------------------------------------------------dtsteps_pm2---
15794 +// pm2 dead time setting [10ns steps].
15795 +#define ma_dtsteps_pm2__a 27
15796 +#define ma_dtsteps_pm2__len 3
15797 +#define ma_dtsteps_pm2__mask 0x38
15798 +#define ma_dtsteps_pm2__shift 0x03
15799 +#define ma_dtsteps_pm2__reset 0x03
15800 +//---------------------------------------------------------------baltype_pm2---
15801 +// pm2 balancing sensor scheme.
15802 +#define ma_baltype_pm2__a 27
15803 +#define ma_baltype_pm2__len 3
15804 +#define ma_baltype_pm2__mask 0x07
15805 +#define ma_baltype_pm2__shift 0x00
15806 +#define ma_baltype_pm2__reset 0x01
15807 +//-------------------------------------------------------------usespread_pm3---
15808 +// pm3 pwm spread-spectrum mode on/off.
15809 +#define ma_usespread_pm3__a 28
15810 +#define ma_usespread_pm3__len 1
15811 +#define ma_usespread_pm3__mask 0x40
15812 +#define ma_usespread_pm3__shift 0x06
15813 +#define ma_usespread_pm3__reset 0x00
15814 +//---------------------------------------------------------------dtsteps_pm3---
15815 +// pm3 dead time setting [10ns steps].
15816 +#define ma_dtsteps_pm3__a 28
15817 +#define ma_dtsteps_pm3__len 3
15818 +#define ma_dtsteps_pm3__mask 0x38
15819 +#define ma_dtsteps_pm3__shift 0x03
15820 +#define ma_dtsteps_pm3__reset 0x01
15821 +//---------------------------------------------------------------baltype_pm3---
15822 +// pm3 balancing sensor scheme.
15823 +#define ma_baltype_pm3__a 28
15824 +#define ma_baltype_pm3__len 3
15825 +#define ma_baltype_pm3__mask 0x07
15826 +#define ma_baltype_pm3__shift 0x00
15827 +#define ma_baltype_pm3__reset 0x03
15828 +//-----------------------------------------------------------------pmprofile---
15829 +// pm profile select. valid presets: 0-1-2-3-4. 5=> custom profile.
15830 +#define ma_pmprofile__a 29
15831 +#define ma_pmprofile__len 3
15832 +#define ma_pmprofile__mask 0x07
15833 +#define ma_pmprofile__shift 0x00
15834 +#define ma_pmprofile__reset 0x00
15835 +//-------------------------------------------------------------------pm3_man---
15836 +// custom profile pm3 contents. 0=>a, 1=>b, 2=>c, 3=>d
15837 +#define ma_pm3_man__a 30
15838 +#define ma_pm3_man__len 2
15839 +#define ma_pm3_man__mask 0x30
15840 +#define ma_pm3_man__shift 0x04
15841 +#define ma_pm3_man__reset 0x02
15842 +//-------------------------------------------------------------------pm2_man---
15843 +// custom profile pm2 contents. 0=>a, 1=>b, 2=>c, 3=>d
15844 +#define ma_pm2_man__a 30
15845 +#define ma_pm2_man__len 2
15846 +#define ma_pm2_man__mask 0x0c
15847 +#define ma_pm2_man__shift 0x02
15848 +#define ma_pm2_man__reset 0x03
15849 +//-------------------------------------------------------------------pm1_man---
15850 +// custom profile pm1 contents. 0=>a, 1=>b, 2=>c, 3=>d
15851 +#define ma_pm1_man__a 30
15852 +#define ma_pm1_man__len 2
15853 +#define ma_pm1_man__mask 0x03
15854 +#define ma_pm1_man__shift 0x00
15855 +#define ma_pm1_man__reset 0x03
15856 +//-----------------------------------------------------------ocp_latch_clear---
15857 +// low-high clears current ocp latched condition.
15858 +#define ma_ocp_latch_clear__a 32
15859 +#define ma_ocp_latch_clear__len 1
15860 +#define ma_ocp_latch_clear__mask 0x80
15861 +#define ma_ocp_latch_clear__shift 0x07
15862 +#define ma_ocp_latch_clear__reset 0x00
15863 +//-------------------------------------------------------------audio_in_mode---
15864 +// audio input mode; 0-1-2-3-4-5
15865 +#define ma_audio_in_mode__a 37
15866 +#define ma_audio_in_mode__len 3
15867 +#define ma_audio_in_mode__mask 0xe0
15868 +#define ma_audio_in_mode__shift 0x05
15869 +#define ma_audio_in_mode__reset 0x00
15870 +//-----------------------------------------------------------------eh_dcshdn---
15871 +// high to enable dc protection
15872 +#define ma_eh_dcshdn__a 38
15873 +#define ma_eh_dcshdn__len 1
15874 +#define ma_eh_dcshdn__mask 0x04
15875 +#define ma_eh_dcshdn__shift 0x02
15876 +#define ma_eh_dcshdn__reset 0x01
15877 +//---------------------------------------------------------audio_in_mode_ext---
15878 +// if set, audio_in_mode is controlled from audio_in_mode register. if not set
15879 +//audio_in_mode is set from fuse bank setting
15880 +#define ma_audio_in_mode_ext__a 39
15881 +#define ma_audio_in_mode_ext__len 1
15882 +#define ma_audio_in_mode_ext__mask 0x20
15883 +#define ma_audio_in_mode_ext__shift 0x05
15884 +#define ma_audio_in_mode_ext__reset 0x00
15885 +//------------------------------------------------------------------eh_clear---
15886 +// flip to clear error registers
15887 +#define ma_eh_clear__a 45
15888 +#define ma_eh_clear__len 1
15889 +#define ma_eh_clear__mask 0x04
15890 +#define ma_eh_clear__shift 0x02
15891 +#define ma_eh_clear__reset 0x00
15892 +//----------------------------------------------------------thermal_compr_en---
15893 +// enable otw-contr. input compression?
15894 +#define ma_thermal_compr_en__a 45
15895 +#define ma_thermal_compr_en__len 1
15896 +#define ma_thermal_compr_en__mask 0x20
15897 +#define ma_thermal_compr_en__shift 0x05
15898 +#define ma_thermal_compr_en__reset 0x01
15899 +//---------------------------------------------------------------system_mute---
15900 +// 1 = mute system, 0 = normal operation
15901 +#define ma_system_mute__a 45
15902 +#define ma_system_mute__len 1
15903 +#define ma_system_mute__mask 0x40
15904 +#define ma_system_mute__shift 0x06
15905 +#define ma_system_mute__reset 0x00
15906 +//------------------------------------------------------thermal_compr_max_db---
15907 +// audio limiter max thermal reduction
15908 +#define ma_thermal_compr_max_db__a 46
15909 +#define ma_thermal_compr_max_db__len 3
15910 +#define ma_thermal_compr_max_db__mask 0x07
15911 +#define ma_thermal_compr_max_db__shift 0x00
15912 +#define ma_thermal_compr_max_db__reset 0x04
15913 +//---------------------------------------------------------audio_proc_enable---
15914 +// enable audio proc, bypass if not enabled
15915 +#define ma_audio_proc_enable__a 53
15916 +#define ma_audio_proc_enable__len 1
15917 +#define ma_audio_proc_enable__mask 0x08
15918 +#define ma_audio_proc_enable__shift 0x03
15919 +#define ma_audio_proc_enable__reset 0x00
15920 +//--------------------------------------------------------audio_proc_release---
15921 +// 00:slow, 01:normal, 10:fast
15922 +#define ma_audio_proc_release__a 53
15923 +#define ma_audio_proc_release__len 2
15924 +#define ma_audio_proc_release__mask 0x30
15925 +#define ma_audio_proc_release__shift 0x04
15926 +#define ma_audio_proc_release__reset 0x00
15927 +//---------------------------------------------------------audio_proc_attack---
15928 +// 00:slow, 01:normal, 10:fast
15929 +#define ma_audio_proc_attack__a 53
15930 +#define ma_audio_proc_attack__len 2
15931 +#define ma_audio_proc_attack__mask 0xc0
15932 +#define ma_audio_proc_attack__shift 0x06
15933 +#define ma_audio_proc_attack__reset 0x00
15934 +//----------------------------------------------------------------i2s_format---
15935 +// i2s basic data format, 000 = std. i2s, 001 = left justified (default)
15936 +#define ma_i2s_format__a 53
15937 +#define ma_i2s_format__len 3
15938 +#define ma_i2s_format__mask 0x07
15939 +#define ma_i2s_format__shift 0x00
15940 +#define ma_i2s_format__reset 0x01
15941 +//--------------------------------------------------audio_proc_limiterenable---
15942 +// 1: enable limiter, 0: disable limiter
15943 +#define ma_audio_proc_limiterenable__a 54
15944 +#define ma_audio_proc_limiterenable__len 1
15945 +#define ma_audio_proc_limiterenable__mask 0x40
15946 +#define ma_audio_proc_limiterenable__shift 0x06
15947 +#define ma_audio_proc_limiterenable__reset 0x00
15948 +//-----------------------------------------------------------audio_proc_mute---
15949 +// 1: mute, 0: unmute
15950 +#define ma_audio_proc_mute__a 54
15951 +#define ma_audio_proc_mute__len 1
15952 +#define ma_audio_proc_mute__mask 0x80
15953 +#define ma_audio_proc_mute__shift 0x07
15954 +#define ma_audio_proc_mute__reset 0x00
15955 +//---------------------------------------------------------------i2s_sck_pol---
15956 +// i2s sck polarity cfg. 0 = rising edge data change
15957 +#define ma_i2s_sck_pol__a 54
15958 +#define ma_i2s_sck_pol__len 1
15959 +#define ma_i2s_sck_pol__mask 0x01
15960 +#define ma_i2s_sck_pol__shift 0x00
15961 +#define ma_i2s_sck_pol__reset 0x01
15962 +//-------------------------------------------------------------i2s_framesize---
15963 +// i2s word length. 00 = 32bit, 01 = 24bit
15964 +#define ma_i2s_framesize__a 54
15965 +#define ma_i2s_framesize__len 2
15966 +#define ma_i2s_framesize__mask 0x18
15967 +#define ma_i2s_framesize__shift 0x03
15968 +#define ma_i2s_framesize__reset 0x00
15969 +//----------------------------------------------------------------i2s_ws_pol---
15970 +// i2s ws polarity. 0 = low first
15971 +#define ma_i2s_ws_pol__a 54
15972 +#define ma_i2s_ws_pol__len 1
15973 +#define ma_i2s_ws_pol__mask 0x02
15974 +#define ma_i2s_ws_pol__shift 0x01
15975 +#define ma_i2s_ws_pol__reset 0x00
15976 +//-----------------------------------------------------------------i2s_order---
15977 +// i2s word bit order. 0 = msb first
15978 +#define ma_i2s_order__a 54
15979 +#define ma_i2s_order__len 1
15980 +#define ma_i2s_order__mask 0x04
15981 +#define ma_i2s_order__shift 0x02
15982 +#define ma_i2s_order__reset 0x00
15983 +//------------------------------------------------------------i2s_rightfirst---
15984 +// i2s l/r word order; 0 = left first
15985 +#define ma_i2s_rightfirst__a 54
15986 +#define ma_i2s_rightfirst__len 1
15987 +#define ma_i2s_rightfirst__mask 0x20
15988 +#define ma_i2s_rightfirst__shift 0x05
15989 +#define ma_i2s_rightfirst__reset 0x00
15990 +//-------------------------------------------------------------vol_db_master---
15991 +// master volume db
15992 +#define ma_vol_db_master__a 64
15993 +#define ma_vol_db_master__len 8
15994 +#define ma_vol_db_master__mask 0xff
15995 +#define ma_vol_db_master__shift 0x00
15996 +#define ma_vol_db_master__reset 0x18
15997 +//------------------------------------------------------------vol_lsb_master---
15998 +// master volume lsb 1/4 steps
15999 +#define ma_vol_lsb_master__a 65
16000 +#define ma_vol_lsb_master__len 2
16001 +#define ma_vol_lsb_master__mask 0x03
16002 +#define ma_vol_lsb_master__shift 0x00
16003 +#define ma_vol_lsb_master__reset 0x00
16004 +//----------------------------------------------------------------vol_db_ch0---
16005 +// volume channel 0
16006 +#define ma_vol_db_ch0__a 66
16007 +#define ma_vol_db_ch0__len 8
16008 +#define ma_vol_db_ch0__mask 0xff
16009 +#define ma_vol_db_ch0__shift 0x00
16010 +#define ma_vol_db_ch0__reset 0x18
16011 +//----------------------------------------------------------------vol_db_ch1---
16012 +// volume channel 1
16013 +#define ma_vol_db_ch1__a 67
16014 +#define ma_vol_db_ch1__len 8
16015 +#define ma_vol_db_ch1__mask 0xff
16016 +#define ma_vol_db_ch1__shift 0x00
16017 +#define ma_vol_db_ch1__reset 0x18
16018 +//----------------------------------------------------------------vol_db_ch2---
16019 +// volume channel 2
16020 +#define ma_vol_db_ch2__a 68
16021 +#define ma_vol_db_ch2__len 8
16022 +#define ma_vol_db_ch2__mask 0xff
16023 +#define ma_vol_db_ch2__shift 0x00
16024 +#define ma_vol_db_ch2__reset 0x18
16025 +//----------------------------------------------------------------vol_db_ch3---
16026 +// volume channel 3
16027 +#define ma_vol_db_ch3__a 69
16028 +#define ma_vol_db_ch3__len 8
16029 +#define ma_vol_db_ch3__mask 0xff
16030 +#define ma_vol_db_ch3__shift 0x00
16031 +#define ma_vol_db_ch3__reset 0x18
16032 +//---------------------------------------------------------------vol_lsb_ch0---
16033 +// volume channel 1 - 1/4 steps
16034 +#define ma_vol_lsb_ch0__a 70
16035 +#define ma_vol_lsb_ch0__len 2
16036 +#define ma_vol_lsb_ch0__mask 0x03
16037 +#define ma_vol_lsb_ch0__shift 0x00
16038 +#define ma_vol_lsb_ch0__reset 0x00
16039 +//---------------------------------------------------------------vol_lsb_ch1---
16040 +// volume channel 3 - 1/4 steps
16041 +#define ma_vol_lsb_ch1__a 70
16042 +#define ma_vol_lsb_ch1__len 2
16043 +#define ma_vol_lsb_ch1__mask 0x0c
16044 +#define ma_vol_lsb_ch1__shift 0x02
16045 +#define ma_vol_lsb_ch1__reset 0x00
16046 +//---------------------------------------------------------------vol_lsb_ch2---
16047 +// volume channel 2 - 1/4 steps
16048 +#define ma_vol_lsb_ch2__a 70
16049 +#define ma_vol_lsb_ch2__len 2
16050 +#define ma_vol_lsb_ch2__mask 0x30
16051 +#define ma_vol_lsb_ch2__shift 0x04
16052 +#define ma_vol_lsb_ch2__reset 0x00
16053 +//---------------------------------------------------------------vol_lsb_ch3---
16054 +// volume channel 3 - 1/4 steps
16055 +#define ma_vol_lsb_ch3__a 70
16056 +#define ma_vol_lsb_ch3__len 2
16057 +#define ma_vol_lsb_ch3__mask 0xc0
16058 +#define ma_vol_lsb_ch3__shift 0x06
16059 +#define ma_vol_lsb_ch3__reset 0x00
16060 +//----------------------------------------------------------------thr_db_ch0---
16061 +// thr_db channel 0
16062 +#define ma_thr_db_ch0__a 71
16063 +#define ma_thr_db_ch0__len 8
16064 +#define ma_thr_db_ch0__mask 0xff
16065 +#define ma_thr_db_ch0__shift 0x00
16066 +#define ma_thr_db_ch0__reset 0x18
16067 +//----------------------------------------------------------------thr_db_ch1---
16068 +// thr db ch1
16069 +#define ma_thr_db_ch1__a 72
16070 +#define ma_thr_db_ch1__len 8
16071 +#define ma_thr_db_ch1__mask 0xff
16072 +#define ma_thr_db_ch1__shift 0x00
16073 +#define ma_thr_db_ch1__reset 0x18
16074 +//----------------------------------------------------------------thr_db_ch2---
16075 +// thr db ch2
16076 +#define ma_thr_db_ch2__a 73
16077 +#define ma_thr_db_ch2__len 8
16078 +#define ma_thr_db_ch2__mask 0xff
16079 +#define ma_thr_db_ch2__shift 0x00
16080 +#define ma_thr_db_ch2__reset 0x18
16081 +//----------------------------------------------------------------thr_db_ch3---
16082 +// threshold db ch3
16083 +#define ma_thr_db_ch3__a 74
16084 +#define ma_thr_db_ch3__len 8
16085 +#define ma_thr_db_ch3__mask 0xff
16086 +#define ma_thr_db_ch3__shift 0x00
16087 +#define ma_thr_db_ch3__reset 0x18
16088 +//---------------------------------------------------------------thr_lsb_ch0---
16089 +// thr lsb ch0
16090 +#define ma_thr_lsb_ch0__a 75
16091 +#define ma_thr_lsb_ch0__len 2
16092 +#define ma_thr_lsb_ch0__mask 0x03
16093 +#define ma_thr_lsb_ch0__shift 0x00
16094 +#define ma_thr_lsb_ch0__reset 0x00
16095 +//---------------------------------------------------------------thr_lsb_ch1---
16096 +// thr lsb ch1
16097 +#define ma_thr_lsb_ch1__a 75
16098 +#define ma_thr_lsb_ch1__len 2
16099 +#define ma_thr_lsb_ch1__mask 0x0c
16100 +#define ma_thr_lsb_ch1__shift 0x02
16101 +#define ma_thr_lsb_ch1__reset 0x00
16102 +//---------------------------------------------------------------thr_lsb_ch2---
16103 +// thr lsb ch2 1/4 db step
16104 +#define ma_thr_lsb_ch2__a 75
16105 +#define ma_thr_lsb_ch2__len 2
16106 +#define ma_thr_lsb_ch2__mask 0x30
16107 +#define ma_thr_lsb_ch2__shift 0x04
16108 +#define ma_thr_lsb_ch2__reset 0x00
16109 +//---------------------------------------------------------------thr_lsb_ch3---
16110 +// threshold lsb ch3
16111 +#define ma_thr_lsb_ch3__a 75
16112 +#define ma_thr_lsb_ch3__len 2
16113 +#define ma_thr_lsb_ch3__mask 0xc0
16114 +#define ma_thr_lsb_ch3__shift 0x06
16115 +#define ma_thr_lsb_ch3__reset 0x00
16116 +//-----------------------------------------------------------dcu_mon0.pm_mon---
16117 +// power mode monitor channel 0
16118 +#define ma_dcu_mon0__pm_mon__a 96
16119 +#define ma_dcu_mon0__pm_mon__len 2
16120 +#define ma_dcu_mon0__pm_mon__mask 0x03
16121 +#define ma_dcu_mon0__pm_mon__shift 0x00
16122 +#define ma_dcu_mon0__pm_mon__reset 0x00
16123 +//-----------------------------------------------------dcu_mon0.freqmode_mon---
16124 +// frequence mode monitor channel 0
16125 +#define ma_dcu_mon0__freqmode_mon__a 96
16126 +#define ma_dcu_mon0__freqmode_mon__len 3
16127 +#define ma_dcu_mon0__freqmode_mon__mask 0x70
16128 +#define ma_dcu_mon0__freqmode_mon__shift 0x04
16129 +#define ma_dcu_mon0__freqmode_mon__reset 0x00
16130 +//-------------------------------------------------------dcu_mon0.pps_passed---
16131 +// dcu0 pps completion indicator
16132 +#define ma_dcu_mon0__pps_passed__a 96
16133 +#define ma_dcu_mon0__pps_passed__len 1
16134 +#define ma_dcu_mon0__pps_passed__mask 0x80
16135 +#define ma_dcu_mon0__pps_passed__shift 0x07
16136 +#define ma_dcu_mon0__pps_passed__reset 0x00
16137 +//----------------------------------------------------------dcu_mon0.ocp_mon---
16138 +// ocp monitor channel 0
16139 +#define ma_dcu_mon0__ocp_mon__a 97
16140 +#define ma_dcu_mon0__ocp_mon__len 1
16141 +#define ma_dcu_mon0__ocp_mon__mask 0x01
16142 +#define ma_dcu_mon0__ocp_mon__shift 0x00
16143 +#define ma_dcu_mon0__ocp_mon__reset 0x00
16144 +//--------------------------------------------------------dcu_mon0.vcfly1_ok---
16145 +// cfly1 protection monitor channel 0.
16146 +#define ma_dcu_mon0__vcfly1_ok__a 97
16147 +#define ma_dcu_mon0__vcfly1_ok__len 1
16148 +#define ma_dcu_mon0__vcfly1_ok__mask 0x02
16149 +#define ma_dcu_mon0__vcfly1_ok__shift 0x01
16150 +#define ma_dcu_mon0__vcfly1_ok__reset 0x00
16151 +//--------------------------------------------------------dcu_mon0.vcfly2_ok---
16152 +// cfly2 protection monitor channel 0.
16153 +#define ma_dcu_mon0__vcfly2_ok__a 97
16154 +#define ma_dcu_mon0__vcfly2_ok__len 1
16155 +#define ma_dcu_mon0__vcfly2_ok__mask 0x04
16156 +#define ma_dcu_mon0__vcfly2_ok__shift 0x02
16157 +#define ma_dcu_mon0__vcfly2_ok__reset 0x00
16158 +//----------------------------------------------------------dcu_mon0.pvdd_ok---
16159 +// dcu0 pvdd monitor
16160 +#define ma_dcu_mon0__pvdd_ok__a 97
16161 +#define ma_dcu_mon0__pvdd_ok__len 1
16162 +#define ma_dcu_mon0__pvdd_ok__mask 0x08
16163 +#define ma_dcu_mon0__pvdd_ok__shift 0x03
16164 +#define ma_dcu_mon0__pvdd_ok__reset 0x00
16165 +//-----------------------------------------------------------dcu_mon0.vdd_ok---
16166 +// dcu0 vdd monitor
16167 +#define ma_dcu_mon0__vdd_ok__a 97
16168 +#define ma_dcu_mon0__vdd_ok__len 1
16169 +#define ma_dcu_mon0__vdd_ok__mask 0x10
16170 +#define ma_dcu_mon0__vdd_ok__shift 0x04
16171 +#define ma_dcu_mon0__vdd_ok__reset 0x00
16172 +//-------------------------------------------------------------dcu_mon0.mute---
16173 +// dcu0 mute monitor
16174 +#define ma_dcu_mon0__mute__a 97
16175 +#define ma_dcu_mon0__mute__len 1
16176 +#define ma_dcu_mon0__mute__mask 0x20
16177 +#define ma_dcu_mon0__mute__shift 0x05
16178 +#define ma_dcu_mon0__mute__reset 0x00
16179 +//------------------------------------------------------------dcu_mon0.m_mon---
16180 +// m sense monitor channel 0
16181 +#define ma_dcu_mon0__m_mon__a 98
16182 +#define ma_dcu_mon0__m_mon__len 8
16183 +#define ma_dcu_mon0__m_mon__mask 0xff
16184 +#define ma_dcu_mon0__m_mon__shift 0x00
16185 +#define ma_dcu_mon0__m_mon__reset 0x00
16186 +//-----------------------------------------------------------dcu_mon1.pm_mon---
16187 +// power mode monitor channel 1
16188 +#define ma_dcu_mon1__pm_mon__a 100
16189 +#define ma_dcu_mon1__pm_mon__len 2
16190 +#define ma_dcu_mon1__pm_mon__mask 0x03
16191 +#define ma_dcu_mon1__pm_mon__shift 0x00
16192 +#define ma_dcu_mon1__pm_mon__reset 0x00
16193 +//-----------------------------------------------------dcu_mon1.freqmode_mon---
16194 +// frequence mode monitor channel 1
16195 +#define ma_dcu_mon1__freqmode_mon__a 100
16196 +#define ma_dcu_mon1__freqmode_mon__len 3
16197 +#define ma_dcu_mon1__freqmode_mon__mask 0x70
16198 +#define ma_dcu_mon1__freqmode_mon__shift 0x04
16199 +#define ma_dcu_mon1__freqmode_mon__reset 0x00
16200 +//-------------------------------------------------------dcu_mon1.pps_passed---
16201 +// dcu1 pps completion indicator
16202 +#define ma_dcu_mon1__pps_passed__a 100
16203 +#define ma_dcu_mon1__pps_passed__len 1
16204 +#define ma_dcu_mon1__pps_passed__mask 0x80
16205 +#define ma_dcu_mon1__pps_passed__shift 0x07
16206 +#define ma_dcu_mon1__pps_passed__reset 0x00
16207 +//----------------------------------------------------------dcu_mon1.ocp_mon---
16208 +// ocp monitor channel 1
16209 +#define ma_dcu_mon1__ocp_mon__a 101
16210 +#define ma_dcu_mon1__ocp_mon__len 1
16211 +#define ma_dcu_mon1__ocp_mon__mask 0x01
16212 +#define ma_dcu_mon1__ocp_mon__shift 0x00
16213 +#define ma_dcu_mon1__ocp_mon__reset 0x00
16214 +//--------------------------------------------------------dcu_mon1.vcfly1_ok---
16215 +// cfly1 protcetion monitor channel 1
16216 +#define ma_dcu_mon1__vcfly1_ok__a 101
16217 +#define ma_dcu_mon1__vcfly1_ok__len 1
16218 +#define ma_dcu_mon1__vcfly1_ok__mask 0x02
16219 +#define ma_dcu_mon1__vcfly1_ok__shift 0x01
16220 +#define ma_dcu_mon1__vcfly1_ok__reset 0x00
16221 +//--------------------------------------------------------dcu_mon1.vcfly2_ok---
16222 +// cfly2 protection monitor channel 1
16223 +#define ma_dcu_mon1__vcfly2_ok__a 101
16224 +#define ma_dcu_mon1__vcfly2_ok__len 1
16225 +#define ma_dcu_mon1__vcfly2_ok__mask 0x04
16226 +#define ma_dcu_mon1__vcfly2_ok__shift 0x02
16227 +#define ma_dcu_mon1__vcfly2_ok__reset 0x00
16228 +//----------------------------------------------------------dcu_mon1.pvdd_ok---
16229 +// dcu1 pvdd monitor
16230 +#define ma_dcu_mon1__pvdd_ok__a 101
16231 +#define ma_dcu_mon1__pvdd_ok__len 1
16232 +#define ma_dcu_mon1__pvdd_ok__mask 0x08
16233 +#define ma_dcu_mon1__pvdd_ok__shift 0x03
16234 +#define ma_dcu_mon1__pvdd_ok__reset 0x00
16235 +//-----------------------------------------------------------dcu_mon1.vdd_ok---
16236 +// dcu1 vdd monitor
16237 +#define ma_dcu_mon1__vdd_ok__a 101
16238 +#define ma_dcu_mon1__vdd_ok__len 1
16239 +#define ma_dcu_mon1__vdd_ok__mask 0x10
16240 +#define ma_dcu_mon1__vdd_ok__shift 0x04
16241 +#define ma_dcu_mon1__vdd_ok__reset 0x00
16242 +//-------------------------------------------------------------dcu_mon1.mute---
16243 +// dcu1 mute monitor
16244 +#define ma_dcu_mon1__mute__a 101
16245 +#define ma_dcu_mon1__mute__len 1
16246 +#define ma_dcu_mon1__mute__mask 0x20
16247 +#define ma_dcu_mon1__mute__shift 0x05
16248 +#define ma_dcu_mon1__mute__reset 0x00
16249 +//------------------------------------------------------------dcu_mon1.m_mon---
16250 +// m sense monitor channel 1
16251 +#define ma_dcu_mon1__m_mon__a 102
16252 +#define ma_dcu_mon1__m_mon__len 8
16253 +#define ma_dcu_mon1__m_mon__mask 0xff
16254 +#define ma_dcu_mon1__m_mon__shift 0x00
16255 +#define ma_dcu_mon1__m_mon__reset 0x00
16256 +//--------------------------------------------------------dcu_mon0.sw_enable---
16257 +// dcu0 switch enable monitor
16258 +#define ma_dcu_mon0__sw_enable__a 104
16259 +#define ma_dcu_mon0__sw_enable__len 1
16260 +#define ma_dcu_mon0__sw_enable__mask 0x40
16261 +#define ma_dcu_mon0__sw_enable__shift 0x06
16262 +#define ma_dcu_mon0__sw_enable__reset 0x00
16263 +//--------------------------------------------------------dcu_mon1.sw_enable---
16264 +// dcu1 switch enable monitor
16265 +#define ma_dcu_mon1__sw_enable__a 104
16266 +#define ma_dcu_mon1__sw_enable__len 1
16267 +#define ma_dcu_mon1__sw_enable__mask 0x80
16268 +#define ma_dcu_mon1__sw_enable__shift 0x07
16269 +#define ma_dcu_mon1__sw_enable__reset 0x00
16270 +//------------------------------------------------------------hvboot0_ok_mon---
16271 +// hvboot0_ok for test/debug
16272 +#define ma_hvboot0_ok_mon__a 105
16273 +#define ma_hvboot0_ok_mon__len 1
16274 +#define ma_hvboot0_ok_mon__mask 0x40
16275 +#define ma_hvboot0_ok_mon__shift 0x06
16276 +#define ma_hvboot0_ok_mon__reset 0x00
16277 +//------------------------------------------------------------hvboot1_ok_mon---
16278 +// hvboot1_ok for test/debug
16279 +#define ma_hvboot1_ok_mon__a 105
16280 +#define ma_hvboot1_ok_mon__len 1
16281 +#define ma_hvboot1_ok_mon__mask 0x80
16282 +#define ma_hvboot1_ok_mon__shift 0x07
16283 +#define ma_hvboot1_ok_mon__reset 0x00
16284 +//-----------------------------------------------------------------error_acc---
16285 +// accumulated errors, at and after triggering
16286 +#define ma_error_acc__a 109
16287 +#define ma_error_acc__len 8
16288 +#define ma_error_acc__mask 0xff
16289 +#define ma_error_acc__shift 0x00
16290 +#define ma_error_acc__reset 0x00
16291 +//-------------------------------------------------------------i2s_data_rate---
16292 +// detected i2s data rate: 00/01/10 = x1/x2/x4
16293 +#define ma_i2s_data_rate__a 116
16294 +#define ma_i2s_data_rate__len 2
16295 +#define ma_i2s_data_rate__mask 0x03
16296 +#define ma_i2s_data_rate__shift 0x00
16297 +#define ma_i2s_data_rate__reset 0x00
16298 +//---------------------------------------------------------audio_in_mode_mon---
16299 +// audio input mode monitor
16300 +#define ma_audio_in_mode_mon__a 116
16301 +#define ma_audio_in_mode_mon__len 3
16302 +#define ma_audio_in_mode_mon__mask 0x1c
16303 +#define ma_audio_in_mode_mon__shift 0x02
16304 +#define ma_audio_in_mode_mon__reset 0x00
16305 +//------------------------------------------------------------------msel_mon---
16306 +// msel[2:0] monitor register
16307 +#define ma_msel_mon__a 117
16308 +#define ma_msel_mon__len 3
16309 +#define ma_msel_mon__mask 0x07
16310 +#define ma_msel_mon__shift 0x00
16311 +#define ma_msel_mon__reset 0x00
16312 +//---------------------------------------------------------------------error---
16313 +// current error flag monitor reg - for app. ctrl.
16314 +#define ma_error__a 124
16315 +#define ma_error__len 8
16316 +#define ma_error__mask 0xff
16317 +#define ma_error__shift 0x00
16318 +#define ma_error__reset 0x00
16319 +//----------------------------------------------------audio_proc_limiter_mon---
16320 +// b7-b4: channel 3-0 limiter active
16321 +#define ma_audio_proc_limiter_mon__a 126
16322 +#define ma_audio_proc_limiter_mon__len 4
16323 +#define ma_audio_proc_limiter_mon__mask 0xf0
16324 +#define ma_audio_proc_limiter_mon__shift 0x04
16325 +#define ma_audio_proc_limiter_mon__reset 0x00
16326 +//-------------------------------------------------------audio_proc_clip_mon---
16327 +// b3-b0: channel 3-0 clipping monitor
16328 +#define ma_audio_proc_clip_mon__a 126
16329 +#define ma_audio_proc_clip_mon__len 4
16330 +#define ma_audio_proc_clip_mon__mask 0x0f
16331 +#define ma_audio_proc_clip_mon__shift 0x00
16332 +#define ma_audio_proc_clip_mon__reset 0x00
16333 +#endif
16334 +
16335 +#define SOC_ENUM_ERR(xname, xenum)\
16336 +{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
16337 + .access = SNDRV_CTL_ELEM_ACCESS_READ,\
16338 + .info = snd_soc_info_enum_double,\
16339 + .get = snd_soc_get_enum_double, .put = snd_soc_put_enum_double,\
16340 + .private_value = (unsigned long)&(xenum) }
16341 +
16342 +static struct i2c_client *i2c;
16343 +
16344 +struct ma120x0p_priv {
16345 + struct regmap *regmap;
16346 + int mclk_div;
16347 + struct snd_soc_component *component;
16348 + struct gpio_desc *enable_gpio;
16349 + struct gpio_desc *mute_gpio;
16350 + struct gpio_desc *booster_gpio;
16351 + struct gpio_desc *error_gpio;
16352 +};
16353 +
16354 +static struct ma120x0p_priv *priv_data;
16355 +
16356 +//Used to share the IRQ number within this file
16357 +static unsigned int irqNumber;
16358 +
16359 +// Function prototype for the custom IRQ handler function
16360 +static irqreturn_t ma120x0p_irq_handler(int irq, void *data);
16361 +
16362 +//Alsa Controls
16363 +static const char * const limenable_text[] = {"Bypassed", "Enabled"};
16364 +static const char * const limatack_text[] = {"Slow", "Normal", "Fast"};
16365 +static const char * const limrelease_text[] = {"Slow", "Normal", "Fast"};
16366 +
16367 +static const char * const err_flycap_text[] = {"Ok", "Error"};
16368 +static const char * const err_overcurr_text[] = {"Ok", "Error"};
16369 +static const char * const err_pllerr_text[] = {"Ok", "Error"};
16370 +static const char * const err_pvddunder_text[] = {"Ok", "Error"};
16371 +static const char * const err_overtempw_text[] = {"Ok", "Error"};
16372 +static const char * const err_overtempe_text[] = {"Ok", "Error"};
16373 +static const char * const err_pinlowimp_text[] = {"Ok", "Error"};
16374 +static const char * const err_dcprot_text[] = {"Ok", "Error"};
16375 +
16376 +static const char * const pwr_mode_prof_text[] = {"PMF0", "PMF1", "PMF2",
16377 +"PMF3", "PMF4"};
16378 +
16379 +static const struct soc_enum lim_enable_ctrl =
16380 + SOC_ENUM_SINGLE(ma_audio_proc_limiterenable__a,
16381 + ma_audio_proc_limiterenable__shift,
16382 + ma_audio_proc_limiterenable__len + 1,
16383 + limenable_text);
16384 +static const struct soc_enum limatack_ctrl =
16385 + SOC_ENUM_SINGLE(ma_audio_proc_attack__a,
16386 + ma_audio_proc_attack__shift,
16387 + ma_audio_proc_attack__len + 1,
16388 + limatack_text);
16389 +static const struct soc_enum limrelease_ctrl =
16390 + SOC_ENUM_SINGLE(ma_audio_proc_release__a,
16391 + ma_audio_proc_release__shift,
16392 + ma_audio_proc_release__len + 1,
16393 + limrelease_text);
16394 +static const struct soc_enum err_flycap_ctrl =
16395 + SOC_ENUM_SINGLE(ma_error__a, 0, 3, err_flycap_text);
16396 +static const struct soc_enum err_overcurr_ctrl =
16397 + SOC_ENUM_SINGLE(ma_error__a, 1, 3, err_overcurr_text);
16398 +static const struct soc_enum err_pllerr_ctrl =
16399 + SOC_ENUM_SINGLE(ma_error__a, 2, 3, err_pllerr_text);
16400 +static const struct soc_enum err_pvddunder_ctrl =
16401 + SOC_ENUM_SINGLE(ma_error__a, 3, 3, err_pvddunder_text);
16402 +static const struct soc_enum err_overtempw_ctrl =
16403 + SOC_ENUM_SINGLE(ma_error__a, 4, 3, err_overtempw_text);
16404 +static const struct soc_enum err_overtempe_ctrl =
16405 + SOC_ENUM_SINGLE(ma_error__a, 5, 3, err_overtempe_text);
16406 +static const struct soc_enum err_pinlowimp_ctrl =
16407 + SOC_ENUM_SINGLE(ma_error__a, 6, 3, err_pinlowimp_text);
16408 +static const struct soc_enum err_dcprot_ctrl =
16409 + SOC_ENUM_SINGLE(ma_error__a, 7, 3, err_dcprot_text);
16410 +static const struct soc_enum pwr_mode_prof_ctrl =
16411 + SOC_ENUM_SINGLE(ma_pmprofile__a, ma_pmprofile__shift, 5,
16412 + pwr_mode_prof_text);
16413 +
16414 +static const char * const pwr_mode_texts[] = {
16415 + "Dynamic power mode",
16416 + "Power mode 1",
16417 + "Power mode 2",
16418 + "Power mode 3",
16419 + };
16420 +
16421 +static const int pwr_mode_values[] = {
16422 + 0x10,
16423 + 0x50,
16424 + 0x60,
16425 + 0x70,
16426 + };
16427 +
16428 +static SOC_VALUE_ENUM_SINGLE_DECL(pwr_mode_ctrl,
16429 + ma_pm_man__a, 0, 0x70,
16430 + pwr_mode_texts,
16431 + pwr_mode_values);
16432 +
16433 +static const DECLARE_TLV_DB_SCALE(ma120x0p_vol_tlv, -5000, 100, 0);
16434 +static const DECLARE_TLV_DB_SCALE(ma120x0p_lim_tlv, -14400, 100, 0);
16435 +static const DECLARE_TLV_DB_SCALE(ma120x0p_lr_tlv, -5000, 100, 0);
16436 +
16437 +static const struct snd_kcontrol_new ma120x0p_snd_controls[] = {
16438 + //Master Volume
16439 + SOC_SINGLE_RANGE_TLV("A.Mstr Vol Volume",
16440 + ma_vol_db_master__a, 0, 0x18, 0xa8, 1, ma120x0p_vol_tlv),
16441 +
16442 + //L-R Volume ch0
16443 + SOC_SINGLE_RANGE_TLV("B.L Vol Volume",
16444 + ma_vol_db_ch0__a, 0, 0x18, 0x4a, 1, ma120x0p_lr_tlv),
16445 + SOC_SINGLE_RANGE_TLV("C.R Vol Volume",
16446 + ma_vol_db_ch1__a, 0, 0x18, 0x4a, 1, ma120x0p_lr_tlv),
16447 +
16448 + //L-R Limiter Threshold ch0-ch1
16449 + SOC_DOUBLE_R_RANGE_TLV("D.Lim thresh Volume",
16450 + ma_thr_db_ch0__a, ma_thr_db_ch1__a, 0, 0x0e, 0x4a, 1,
16451 + ma120x0p_lim_tlv),
16452 +
16453 + //Enum Switches/Selectors
16454 + //SOC_ENUM("E.AudioProc Mute", audioproc_mute_ctrl),
16455 + SOC_ENUM("F.Limiter Enable", lim_enable_ctrl),
16456 + SOC_ENUM("G.Limiter Attck", limatack_ctrl),
16457 + SOC_ENUM("H.Limiter Rls", limrelease_ctrl),
16458 +
16459 + //Enum Error Monitor (read-only)
16460 + SOC_ENUM_ERR("I.Err flycap", err_flycap_ctrl),
16461 + SOC_ENUM_ERR("J.Err overcurr", err_overcurr_ctrl),
16462 + SOC_ENUM_ERR("K.Err pllerr", err_pllerr_ctrl),
16463 + SOC_ENUM_ERR("L.Err pvddunder", err_pvddunder_ctrl),
16464 + SOC_ENUM_ERR("M.Err overtempw", err_overtempw_ctrl),
16465 + SOC_ENUM_ERR("N.Err overtempe", err_overtempe_ctrl),
16466 + SOC_ENUM_ERR("O.Err pinlowimp", err_pinlowimp_ctrl),
16467 + SOC_ENUM_ERR("P.Err dcprot", err_dcprot_ctrl),
16468 +
16469 + //Power modes profiles
16470 + SOC_ENUM("Q.PM Prof", pwr_mode_prof_ctrl),
16471 +
16472 + // Power mode selection (Dynamic,1,2,3)
16473 + SOC_ENUM("R.Power Mode", pwr_mode_ctrl),
16474 +};
16475 +
16476 +//Machine Driver
16477 +static int ma120x0p_hw_params(struct snd_pcm_substream *substream,
16478 + struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
16479 +{
16480 + u16 blen = 0x00;
16481 +
16482 + struct snd_soc_component *component = dai->component;
16483 +
16484 + priv_data->component = component;
16485 +
16486 + switch (params_format(params)) {
16487 + case SNDRV_PCM_FORMAT_S16_LE:
16488 + blen = 0x10;
16489 + break;
16490 + case SNDRV_PCM_FORMAT_S24_LE:
16491 + blen = 0x00;
16492 + break;
16493 + case SNDRV_PCM_FORMAT_S32_LE:
16494 + blen = 0x00;
16495 + break;
16496 + default:
16497 + dev_err(dai->dev, "Unsupported word length: %u\n",
16498 + params_format(params));
16499 + return -EINVAL;
16500 + }
16501 +
16502 + // set word length
16503 + snd_soc_component_update_bits(component, ma_i2s_framesize__a,
16504 + ma_i2s_framesize__mask, blen);
16505 +
16506 + return 0;
16507 +}
16508 +
16509 +static int ma120x0p_mute_stream(struct snd_soc_dai *dai, int mute, int stream)
16510 +{
16511 + int val = 0;
16512 +
16513 + struct ma120x0p_priv *ma120x0p;
16514 +
16515 + struct snd_soc_component *component = dai->component;
16516 +
16517 + ma120x0p = snd_soc_component_get_drvdata(component);
16518 +
16519 + if (mute)
16520 + val = 0;
16521 + else
16522 + val = 1;
16523 +
16524 + gpiod_set_value_cansleep(priv_data->mute_gpio, val);
16525 +
16526 + return 0;
16527 +}
16528 +
16529 +static const struct snd_soc_dai_ops ma120x0p_dai_ops = {
16530 + .hw_params = ma120x0p_hw_params,
16531 + .mute_stream = ma120x0p_mute_stream,
16532 +};
16533 +
16534 +static struct snd_soc_dai_driver ma120x0p_dai = {
16535 + .name = "ma120x0p-amp",
16536 + .playback = {
16537 + .stream_name = "Playback",
16538 + .channels_min = 2,
16539 + .channels_max = 2,
16540 + .rates = SNDRV_PCM_RATE_CONTINUOUS,
16541 + .rate_min = 44100,
16542 + .rate_max = 192000,
16543 + .formats = SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE
16544 + },
16545 + .ops = &ma120x0p_dai_ops,
16546 +};
16547 +
16548 +//Codec Driver
16549 +static int ma120x0p_clear_err(struct snd_soc_component *component)
16550 +{
16551 + int ret = 0;
16552 +
16553 + struct ma120x0p_priv *ma120x0p;
16554 +
16555 + ma120x0p = snd_soc_component_get_drvdata(component);
16556 +
16557 + ret = snd_soc_component_update_bits(component,
16558 + ma_eh_clear__a, ma_eh_clear__mask, 0x00);
16559 + if (ret < 0)
16560 + return ret;
16561 +
16562 + ret = snd_soc_component_update_bits(component,
16563 + ma_eh_clear__a, ma_eh_clear__mask, 0x04);
16564 + if (ret < 0)
16565 + return ret;
16566 +
16567 + ret = snd_soc_component_update_bits(component,
16568 + ma_eh_clear__a, ma_eh_clear__mask, 0x00);
16569 + if (ret < 0)
16570 + return ret;
16571 +
16572 + return 0;
16573 +}
16574 +
16575 +static void ma120x0p_remove(struct snd_soc_component *component)
16576 +{
16577 + struct ma120x0p_priv *ma120x0p;
16578 +
16579 + ma120x0p = snd_soc_component_get_drvdata(component);
16580 +}
16581 +
16582 +static int ma120x0p_probe(struct snd_soc_component *component)
16583 +{
16584 + struct ma120x0p_priv *ma120x0p;
16585 +
16586 + int ret = 0;
16587 +
16588 + i2c = container_of(component->dev, struct i2c_client, dev);
16589 +
16590 + ma120x0p = snd_soc_component_get_drvdata(component);
16591 +
16592 + //Reset error
16593 + ma120x0p_clear_err(component);
16594 + if (ret < 0)
16595 + return ret;
16596 +
16597 + // set serial audio format I2S and enable audio processor
16598 + ret = snd_soc_component_write(component, ma_i2s_format__a, 0x08);
16599 + if (ret < 0)
16600 + return ret;
16601 +
16602 + // Enable audio limiter
16603 + ret = snd_soc_component_update_bits(component,
16604 + ma_audio_proc_limiterenable__a,
16605 + ma_audio_proc_limiterenable__mask, 0x40);
16606 + if (ret < 0)
16607 + return ret;
16608 +
16609 + // Set lim attack to fast
16610 + ret = snd_soc_component_update_bits(component,
16611 + ma_audio_proc_attack__a, ma_audio_proc_attack__mask, 0x80);
16612 + if (ret < 0)
16613 + return ret;
16614 +
16615 + // Set lim attack to low
16616 + ret = snd_soc_component_update_bits(component,
16617 + ma_audio_proc_release__a, ma_audio_proc_release__mask, 0x00);
16618 + if (ret < 0)
16619 + return ret;
16620 +
16621 + // set volume to 0dB
16622 + ret = snd_soc_component_write(component, ma_vol_db_master__a, 0x18);
16623 + if (ret < 0)
16624 + return ret;
16625 +
16626 + // set ch0 lim thresh to -15dB
16627 + ret = snd_soc_component_write(component, ma_thr_db_ch0__a, 0x27);
16628 + if (ret < 0)
16629 + return ret;
16630 +
16631 + // set ch1 lim thresh to -15dB
16632 + ret = snd_soc_component_write(component, ma_thr_db_ch1__a, 0x27);
16633 + if (ret < 0)
16634 + return ret;
16635 +
16636 + //Check for errors
16637 + ret = snd_soc_component_test_bits(component, ma_error_acc__a, 0x00, 0);
16638 + if (ret < 0)
16639 + return ret;
16640 + ret = snd_soc_component_test_bits(component, ma_error_acc__a, 0x01, 0);
16641 + if (ret < 0)
16642 + return ret;
16643 + ret = snd_soc_component_test_bits(component, ma_error_acc__a, 0x02, 0);
16644 + if (ret < 0)
16645 + return ret;
16646 + ret = snd_soc_component_test_bits(component, ma_error_acc__a, 0x08, 0);
16647 + if (ret < 0)
16648 + return ret;
16649 + ret = snd_soc_component_test_bits(component, ma_error_acc__a, 0x10, 0);
16650 + if (ret < 0)
16651 + return ret;
16652 + ret = snd_soc_component_test_bits(component, ma_error_acc__a, 0x20, 0);
16653 + if (ret < 0)
16654 + return ret;
16655 + ret = snd_soc_component_test_bits(component, ma_error_acc__a, 0x40, 0);
16656 + if (ret < 0)
16657 + return ret;
16658 + ret = snd_soc_component_test_bits(component, ma_error_acc__a, 0x80, 0);
16659 + if (ret < 0)
16660 + return ret;
16661 +
16662 + return 0;
16663 +}
16664 +
16665 +static int ma120x0p_set_bias_level(struct snd_soc_component *component,
16666 + enum snd_soc_bias_level level)
16667 +{
16668 + int ret = 0;
16669 +
16670 + struct ma120x0p_priv *ma120x0p;
16671 +
16672 + ma120x0p = snd_soc_component_get_drvdata(component);
16673 +
16674 + switch (level) {
16675 + case SND_SOC_BIAS_ON:
16676 + break;
16677 +
16678 + case SND_SOC_BIAS_PREPARE:
16679 + break;
16680 +
16681 + case SND_SOC_BIAS_STANDBY:
16682 + ret = gpiod_get_value_cansleep(priv_data->enable_gpio);
16683 + if (ret != 0) {
16684 + dev_err(component->dev, "Device ma120x0p disabled in STANDBY BIAS: %d\n",
16685 + ret);
16686 + return ret;
16687 + }
16688 + break;
16689 +
16690 + case SND_SOC_BIAS_OFF:
16691 + break;
16692 + }
16693 +
16694 + return 0;
16695 +}
16696 +
16697 +static const struct snd_soc_dapm_widget ma120x0p_dapm_widgets[] = {
16698 + SND_SOC_DAPM_OUTPUT("OUT_A"),
16699 + SND_SOC_DAPM_OUTPUT("OUT_B"),
16700 +};
16701 +
16702 +static const struct snd_soc_dapm_route ma120x0p_dapm_routes[] = {
16703 + { "OUT_B", NULL, "Playback" },
16704 + { "OUT_A", NULL, "Playback" },
16705 +};
16706 +
16707 +static const struct snd_soc_component_driver ma120x0p_component_driver = {
16708 + .probe = ma120x0p_probe,
16709 + .remove = ma120x0p_remove,
16710 + .set_bias_level = ma120x0p_set_bias_level,
16711 + .dapm_widgets = ma120x0p_dapm_widgets,
16712 + .num_dapm_widgets = ARRAY_SIZE(ma120x0p_dapm_widgets),
16713 + .dapm_routes = ma120x0p_dapm_routes,
16714 + .num_dapm_routes = ARRAY_SIZE(ma120x0p_dapm_routes),
16715 + .controls = ma120x0p_snd_controls,
16716 + .num_controls = ARRAY_SIZE(ma120x0p_snd_controls),
16717 + .use_pmdown_time = 1,
16718 + .endianness = 1,
16719 +};
16720 +
16721 +//I2C Driver
16722 +static const struct reg_default ma120x0p_reg_defaults[] = {
16723 + { 0x01, 0x3c },
16724 +};
16725 +
16726 +static bool ma120x0p_reg_volatile(struct device *dev, unsigned int reg)
16727 +{
16728 + switch (reg) {
16729 + case ma_error__a:
16730 + return true;
16731 + default:
16732 + return false;
16733 + }
16734 +}
16735 +
16736 +static const struct of_device_id ma120x0p_of_match[] = {
16737 + { .compatible = "ma,ma120x0p", },
16738 + { }
16739 +};
16740 +
16741 +MODULE_DEVICE_TABLE(of, ma120x0p_of_match);
16742 +
16743 +static struct regmap_config ma120x0p_regmap_config = {
16744 + .reg_bits = 8,
16745 + .val_bits = 8,
16746 +
16747 + .max_register = 255,
16748 + .volatile_reg = ma120x0p_reg_volatile,
16749 +
16750 + .cache_type = REGCACHE_RBTREE,
16751 + .reg_defaults = ma120x0p_reg_defaults,
16752 + .num_reg_defaults = ARRAY_SIZE(ma120x0p_reg_defaults),
16753 +};
16754 +
16755 +static int ma120x0p_i2c_probe(struct i2c_client *i2c,
16756 + const struct i2c_device_id *id)
16757 +{
16758 + int ret;
16759 +
16760 + priv_data = devm_kzalloc(&i2c->dev, sizeof(*priv_data), GFP_KERNEL);
16761 + if (!priv_data)
16762 + return -ENOMEM;
16763 + i2c_set_clientdata(i2c, priv_data);
16764 +
16765 + priv_data->regmap = devm_regmap_init_i2c(i2c, &ma120x0p_regmap_config);
16766 + if (IS_ERR(priv_data->regmap)) {
16767 + ret = PTR_ERR(priv_data->regmap);
16768 + return ret;
16769 + }
16770 +
16771 + //Startup sequence
16772 +
16773 + //Make sure the device is muted
16774 + priv_data->mute_gpio = devm_gpiod_get_optional(&i2c->dev, "mute_gp",
16775 + GPIOD_OUT_LOW);
16776 + if (IS_ERR(priv_data->mute_gpio)) {
16777 + ret = PTR_ERR(priv_data->mute_gpio);
16778 + dev_err(&i2c->dev, "Failed to get mute gpio line: %d\n", ret);
16779 + return ret;
16780 + }
16781 + msleep(50);
16782 +
16783 +// MA120xx0P devices are usually powered by an integrated boost converter.
16784 +// An option GPIO control line is provided to enable the booster properly and
16785 +// in sync with the enable and mute GPIO lines.
16786 + priv_data->booster_gpio = devm_gpiod_get_optional(&i2c->dev,
16787 + "booster_gp", GPIOD_OUT_LOW);
16788 + if (IS_ERR(priv_data->booster_gpio)) {
16789 + ret = PTR_ERR(priv_data->booster_gpio);
16790 + dev_err(&i2c->dev,
16791 + "Failed to get booster enable gpio line: %d\n", ret);
16792 + return ret;
16793 + }
16794 + msleep(50);
16795 +
16796 + //Enable booster and wait 200ms until stable PVDD
16797 + gpiod_set_value_cansleep(priv_data->booster_gpio, 1);
16798 + msleep(200);
16799 +
16800 + //Enable ma120x0pp
16801 + priv_data->enable_gpio = devm_gpiod_get_optional(&i2c->dev,
16802 + "enable_gp", GPIOD_OUT_LOW);
16803 + if (IS_ERR(priv_data->enable_gpio)) {
16804 + ret = PTR_ERR(priv_data->enable_gpio);
16805 + dev_err(&i2c->dev,
16806 + "Failed to get ma120x0p enable gpio line: %d\n", ret);
16807 + return ret;
16808 + }
16809 + msleep(50);
16810 +
16811 + //Optional use of ma120x0pp error line as an interrupt trigger to
16812 + //platform GPIO.
16813 + //Get error input gpio ma120x0p
16814 + priv_data->error_gpio = devm_gpiod_get_optional(&i2c->dev,
16815 + "error_gp", GPIOD_IN);
16816 + if (IS_ERR(priv_data->error_gpio)) {
16817 + ret = PTR_ERR(priv_data->error_gpio);
16818 + dev_err(&i2c->dev,
16819 + "Failed to get ma120x0p error gpio line: %d\n", ret);
16820 + return ret;
16821 + }
16822 +
16823 + if (priv_data->error_gpio != NULL) {
16824 + irqNumber = gpiod_to_irq(priv_data->error_gpio);
16825 +
16826 + ret = devm_request_threaded_irq(&i2c->dev,
16827 + irqNumber, ma120x0p_irq_handler,
16828 + NULL, IRQF_TRIGGER_FALLING,
16829 + "ma120x0p", priv_data);
16830 + if (ret != 0)
16831 + dev_warn(&i2c->dev, "Failed to request IRQ: %d\n",
16832 + ret);
16833 + }
16834 +
16835 + ret = devm_snd_soc_register_component(&i2c->dev,
16836 + &ma120x0p_component_driver, &ma120x0p_dai, 1);
16837 +
16838 + return ret;
16839 +}
16840 +
16841 +static irqreturn_t ma120x0p_irq_handler(int irq, void *data)
16842 +{
16843 + gpiod_set_value_cansleep(priv_data->mute_gpio, 0);
16844 + gpiod_set_value_cansleep(priv_data->enable_gpio, 1);
16845 + return IRQ_HANDLED;
16846 +}
16847 +
16848 +static void ma120x0p_i2c_remove(struct i2c_client *i2c)
16849 +{
16850 + snd_soc_unregister_component(&i2c->dev);
16851 + i2c_set_clientdata(i2c, NULL);
16852 +
16853 + gpiod_set_value_cansleep(priv_data->mute_gpio, 0);
16854 + msleep(30);
16855 + gpiod_set_value_cansleep(priv_data->enable_gpio, 1);
16856 + msleep(200);
16857 + gpiod_set_value_cansleep(priv_data->booster_gpio, 0);
16858 + msleep(200);
16859 +
16860 + kfree(priv_data);
16861 +}
16862 +
16863 +static void ma120x0p_i2c_shutdown(struct i2c_client *i2c)
16864 +{
16865 + snd_soc_unregister_component(&i2c->dev);
16866 + i2c_set_clientdata(i2c, NULL);
16867 +
16868 + gpiod_set_value_cansleep(priv_data->mute_gpio, 0);
16869 + msleep(30);
16870 + gpiod_set_value_cansleep(priv_data->enable_gpio, 1);
16871 + msleep(200);
16872 + gpiod_set_value_cansleep(priv_data->booster_gpio, 0);
16873 + msleep(200);
16874 +
16875 + kfree(priv_data);
16876 +}
16877 +
16878 +static const struct i2c_device_id ma120x0p_i2c_id[] = {
16879 + { "ma120x0p", 0 },
16880 + { }
16881 +};
16882 +
16883 +MODULE_DEVICE_TABLE(i2c, ma120x0p_i2c_id);
16884 +
16885 +static struct i2c_driver ma120x0p_i2c_driver = {
16886 + .driver = {
16887 + .name = "ma120x0p",
16888 + .owner = THIS_MODULE,
16889 + .of_match_table = ma120x0p_of_match,
16890 + },
16891 + .probe = ma120x0p_i2c_probe,
16892 + .remove = ma120x0p_i2c_remove,
16893 + .shutdown = ma120x0p_i2c_shutdown,
16894 + .id_table = ma120x0p_i2c_id
16895 +};
16896 +
16897 +static int __init ma120x0p_modinit(void)
16898 +{
16899 + int ret = 0;
16900 +
16901 + ret = i2c_add_driver(&ma120x0p_i2c_driver);
16902 + if (ret != 0) {
16903 + pr_err("Failed to register MA120X0P I2C driver: %d\n", ret);
16904 + return ret;
16905 + }
16906 + return ret;
16907 +}
16908 +module_init(ma120x0p_modinit);
16909 +
16910 +static void __exit ma120x0p_exit(void)
16911 +{
16912 + i2c_del_driver(&ma120x0p_i2c_driver);
16913 +}
16914 +module_exit(ma120x0p_exit);
16915 +
16916 +MODULE_AUTHOR("Ariel Muszkat ariel.muszkat@gmail.com>");
16917 +MODULE_DESCRIPTION("ASoC driver for ma120x0p");
16918 +MODULE_LICENSE("GPL v2");
16919 --- /dev/null
16920 +++ b/sound/soc/codecs/pcm1794a.c
16921 @@ -0,0 +1,69 @@
16922 +/*
16923 + * Driver for the PCM1794A codec
16924 + *
16925 + * Author: Florian Meier <florian.meier@koalo.de>
16926 + * Copyright 2013
16927 + *
16928 + * This program is free software; you can redistribute it and/or
16929 + * modify it under the terms of the GNU General Public License
16930 + * version 2 as published by the Free Software Foundation.
16931 + *
16932 + * This program is distributed in the hope that it will be useful, but
16933 + * WITHOUT ANY WARRANTY; without even the implied warranty of
16934 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16935 + * General Public License for more details.
16936 + */
16937 +
16938 +
16939 +#include <linux/init.h>
16940 +#include <linux/module.h>
16941 +#include <linux/platform_device.h>
16942 +
16943 +#include <sound/soc.h>
16944 +
16945 +static struct snd_soc_dai_driver pcm1794a_dai = {
16946 + .name = "pcm1794a-hifi",
16947 + .playback = {
16948 + .channels_min = 2,
16949 + .channels_max = 2,
16950 + .rates = SNDRV_PCM_RATE_8000_192000,
16951 + .formats = SNDRV_PCM_FMTBIT_S16_LE |
16952 + SNDRV_PCM_FMTBIT_S24_LE
16953 + },
16954 +};
16955 +
16956 +static struct snd_soc_component_driver soc_component_dev_pcm1794a;
16957 +
16958 +static int pcm1794a_probe(struct platform_device *pdev)
16959 +{
16960 + return snd_soc_register_component(&pdev->dev, &soc_component_dev_pcm1794a,
16961 + &pcm1794a_dai, 1);
16962 +}
16963 +
16964 +static int pcm1794a_remove(struct platform_device *pdev)
16965 +{
16966 + snd_soc_unregister_component(&pdev->dev);
16967 + return 0;
16968 +}
16969 +
16970 +static const struct of_device_id pcm1794a_of_match[] = {
16971 + { .compatible = "ti,pcm1794a", },
16972 + { }
16973 +};
16974 +MODULE_DEVICE_TABLE(of, pcm1794a_of_match);
16975 +
16976 +static struct platform_driver pcm1794a_component_driver = {
16977 + .probe = pcm1794a_probe,
16978 + .remove = pcm1794a_remove,
16979 + .driver = {
16980 + .name = "pcm1794a-codec",
16981 + .owner = THIS_MODULE,
16982 + .of_match_table = of_match_ptr(pcm1794a_of_match),
16983 + },
16984 +};
16985 +
16986 +module_platform_driver(pcm1794a_component_driver);
16987 +
16988 +MODULE_DESCRIPTION("ASoC PCM1794A codec driver");
16989 +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
16990 +MODULE_LICENSE("GPL v2");
16991 --- a/sound/soc/codecs/pcm512x.c
16992 +++ b/sound/soc/codecs/pcm512x.c
16993 @@ -536,7 +536,7 @@ static unsigned long pcm512x_ncp_target(
16994
16995 static const u32 pcm512x_dai_rates[] = {
16996 8000, 11025, 16000, 22050, 32000, 44100, 48000, 64000,
16997 - 88200, 96000, 176400, 192000, 384000,
16998 + 88200, 96000, 176400, 192000, 352800, 384000,
16999 };
17000
17001 static const struct snd_pcm_hw_constraint_list constraints_slave = {
17002 --- /dev/null
17003 +++ b/sound/soc/codecs/tas5713.c
17004 @@ -0,0 +1,361 @@
17005 +/*
17006 + * ASoC Driver for TAS5713
17007 + *
17008 + * Author: Sebastian Eickhoff <basti.eickhoff@googlemail.com>
17009 + * Copyright 2014
17010 + *
17011 + * This program is free software; you can redistribute it and/or
17012 + * modify it under the terms of the GNU General Public License
17013 + * version 2 as published by the Free Software Foundation.
17014 + *
17015 + * This program is distributed in the hope that it will be useful, but
17016 + * WITHOUT ANY WARRANTY; without even the implied warranty of
17017 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17018 + * General Public License for more details.
17019 + */
17020 +
17021 +#include <linux/module.h>
17022 +#include <linux/moduleparam.h>
17023 +#include <linux/init.h>
17024 +#include <linux/delay.h>
17025 +#include <linux/pm.h>
17026 +#include <linux/i2c.h>
17027 +#include <linux/of_device.h>
17028 +#include <linux/spi/spi.h>
17029 +#include <linux/regmap.h>
17030 +#include <linux/regulator/consumer.h>
17031 +#include <linux/slab.h>
17032 +#include <sound/core.h>
17033 +#include <sound/pcm.h>
17034 +#include <sound/pcm_params.h>
17035 +#include <sound/soc.h>
17036 +#include <sound/initval.h>
17037 +#include <sound/tlv.h>
17038 +
17039 +#include <linux/kernel.h>
17040 +#include <linux/string.h>
17041 +#include <linux/fs.h>
17042 +#include <asm/uaccess.h>
17043 +
17044 +#include "tas5713.h"
17045 +
17046 +
17047 +static struct i2c_client *i2c;
17048 +
17049 +struct tas5713_priv {
17050 + struct regmap *regmap;
17051 + int mclk_div;
17052 + struct snd_soc_component *component;
17053 +};
17054 +
17055 +static struct tas5713_priv *priv_data;
17056 +
17057 +
17058 +
17059 +
17060 +/*
17061 + * _ _ ___ _ ___ _ _
17062 + * /_\ | | / __| /_\ / __|___ _ _| |_ _ _ ___| |___
17063 + * / _ \| |__\__ \/ _ \ | (__/ _ \ ' \ _| '_/ _ \ (_-<
17064 + * /_/ \_\____|___/_/ \_\ \___\___/_||_\__|_| \___/_/__/
17065 + *
17066 + */
17067 +
17068 +static const DECLARE_TLV_DB_SCALE(tas5713_vol_tlv, -10000, 50, 1);
17069 +
17070 +
17071 +static const struct snd_kcontrol_new tas5713_snd_controls[] = {
17072 + SOC_SINGLE_TLV ("Master" , TAS5713_VOL_MASTER, 0, 248, 1, tas5713_vol_tlv),
17073 + SOC_DOUBLE_R_TLV("Channels" , TAS5713_VOL_CH1, TAS5713_VOL_CH2, 0, 248, 1, tas5713_vol_tlv)
17074 +};
17075 +
17076 +
17077 +
17078 +
17079 +/*
17080 + * __ __ _ _ ___ _
17081 + * | \/ |__ _ __| |_ (_)_ _ ___ | \ _ _(_)_ _____ _ _
17082 + * | |\/| / _` / _| ' \| | ' \/ -_) | |) | '_| \ V / -_) '_|
17083 + * |_| |_\__,_\__|_||_|_|_||_\___| |___/|_| |_|\_/\___|_|
17084 + *
17085 + */
17086 +
17087 +static int tas5713_hw_params(struct snd_pcm_substream *substream,
17088 + struct snd_pcm_hw_params *params,
17089 + struct snd_soc_dai *dai)
17090 +{
17091 + u16 blen = 0x00;
17092 +
17093 + struct snd_soc_component *component = dai->component;
17094 + priv_data->component = component;
17095 +
17096 + switch (params_format(params)) {
17097 + case SNDRV_PCM_FORMAT_S16_LE:
17098 + blen = 0x03;
17099 + break;
17100 + case SNDRV_PCM_FORMAT_S20_3LE:
17101 + blen = 0x1;
17102 + break;
17103 + case SNDRV_PCM_FORMAT_S24_LE:
17104 + blen = 0x04;
17105 + break;
17106 + case SNDRV_PCM_FORMAT_S32_LE:
17107 + blen = 0x05;
17108 + break;
17109 + default:
17110 + dev_err(dai->dev, "Unsupported word length: %u\n",
17111 + params_format(params));
17112 + return -EINVAL;
17113 + }
17114 +
17115 + // set word length
17116 + snd_soc_component_update_bits(component, TAS5713_SERIAL_DATA_INTERFACE, 0x7, blen);
17117 +
17118 + return 0;
17119 +}
17120 +
17121 +
17122 +static int tas5713_mute_stream(struct snd_soc_dai *dai, int mute, int stream)
17123 +{
17124 + unsigned int val = 0;
17125 +
17126 + struct tas5713_priv *tas5713;
17127 + struct snd_soc_component *component = dai->component;
17128 + tas5713 = snd_soc_component_get_drvdata(component);
17129 +
17130 + if (mute) {
17131 + val = TAS5713_SOFT_MUTE_ALL;
17132 + }
17133 +
17134 + return regmap_write(tas5713->regmap, TAS5713_SOFT_MUTE, val);
17135 +}
17136 +
17137 +
17138 +static const struct snd_soc_dai_ops tas5713_dai_ops = {
17139 + .hw_params = tas5713_hw_params,
17140 + .mute_stream = tas5713_mute_stream,
17141 +};
17142 +
17143 +
17144 +static struct snd_soc_dai_driver tas5713_dai = {
17145 + .name = "tas5713-hifi",
17146 + .playback = {
17147 + .stream_name = "Playback",
17148 + .channels_min = 2,
17149 + .channels_max = 2,
17150 + .rates = SNDRV_PCM_RATE_8000_48000,
17151 + .formats = (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE ),
17152 + },
17153 + .ops = &tas5713_dai_ops,
17154 +};
17155 +
17156 +
17157 +
17158 +
17159 +/*
17160 + * ___ _ ___ _
17161 + * / __|___ __| |___ __ | \ _ _(_)_ _____ _ _
17162 + * | (__/ _ \/ _` / -_) _| | |) | '_| \ V / -_) '_|
17163 + * \___\___/\__,_\___\__| |___/|_| |_|\_/\___|_|
17164 + *
17165 + */
17166 +
17167 +static void tas5713_remove(struct snd_soc_component *component)
17168 +{
17169 + struct tas5713_priv *tas5713;
17170 +
17171 + tas5713 = snd_soc_component_get_drvdata(component);
17172 +}
17173 +
17174 +
17175 +static int tas5713_probe(struct snd_soc_component *component)
17176 +{
17177 + struct tas5713_priv *tas5713;
17178 + int i, ret;
17179 +
17180 + i2c = container_of(component->dev, struct i2c_client, dev);
17181 +
17182 + tas5713 = snd_soc_component_get_drvdata(component);
17183 +
17184 + // Reset error
17185 + ret = snd_soc_component_write(component, TAS5713_ERROR_STATUS, 0x00);
17186 + if (ret < 0) return ret;
17187 +
17188 + // Trim oscillator
17189 + ret = snd_soc_component_write(component, TAS5713_OSC_TRIM, 0x00);
17190 + if (ret < 0) return ret;
17191 + msleep(1000);
17192 +
17193 + // Reset error
17194 + ret = snd_soc_component_write(component, TAS5713_ERROR_STATUS, 0x00);
17195 + if (ret < 0) return ret;
17196 +
17197 + // I2S 24bit
17198 + ret = snd_soc_component_write(component, TAS5713_SERIAL_DATA_INTERFACE, 0x05);
17199 + if (ret < 0) return ret;
17200 +
17201 + // Unmute
17202 + ret = snd_soc_component_write(component, TAS5713_SYSTEM_CTRL2, 0x00);
17203 + if (ret < 0) return ret;
17204 + ret = snd_soc_component_write(component, TAS5713_SOFT_MUTE, 0x00);
17205 + if (ret < 0) return ret;
17206 +
17207 + // Set volume to 0db
17208 + ret = snd_soc_component_write(component, TAS5713_VOL_MASTER, 0x00);
17209 + if (ret < 0) return ret;
17210 +
17211 + // Now start programming the default initialization sequence
17212 + for (i = 0; i < ARRAY_SIZE(tas5713_init_sequence); ++i) {
17213 + ret = i2c_master_send(i2c,
17214 + tas5713_init_sequence[i].data,
17215 + tas5713_init_sequence[i].size);
17216 + if (ret < 0) {
17217 + printk(KERN_INFO "TAS5713 CODEC PROBE: InitSeq returns: %d\n", ret);
17218 + }
17219 + }
17220 +
17221 + // Unmute
17222 + ret = snd_soc_component_write(component, TAS5713_SYSTEM_CTRL2, 0x00);
17223 + if (ret < 0) return ret;
17224 +
17225 + return 0;
17226 +}
17227 +
17228 +
17229 +static struct snd_soc_component_driver soc_codec_dev_tas5713 = {
17230 + .probe = tas5713_probe,
17231 + .remove = tas5713_remove,
17232 + .controls = tas5713_snd_controls,
17233 + .num_controls = ARRAY_SIZE(tas5713_snd_controls),
17234 +};
17235 +
17236 +
17237 +
17238 +
17239 +/*
17240 + * ___ ___ ___ ___ _
17241 + * |_ _|_ ) __| | \ _ _(_)_ _____ _ _
17242 + * | | / / (__ | |) | '_| \ V / -_) '_|
17243 + * |___/___\___| |___/|_| |_|\_/\___|_|
17244 + *
17245 + */
17246 +
17247 +static const struct reg_default tas5713_reg_defaults[] = {
17248 + { 0x07 ,0x80 }, // R7 - VOL_MASTER - -40dB
17249 + { 0x08 , 30 }, // R8 - VOL_CH1 - 0dB
17250 + { 0x09 , 30 }, // R9 - VOL_CH2 - 0dB
17251 + { 0x0A ,0x80 }, // R10 - VOL_HEADPHONE - -40dB
17252 +};
17253 +
17254 +
17255 +static bool tas5713_reg_volatile(struct device *dev, unsigned int reg)
17256 +{
17257 + switch (reg) {
17258 + case TAS5713_DEVICE_ID:
17259 + case TAS5713_ERROR_STATUS:
17260 + case TAS5713_CLOCK_CTRL:
17261 + return true;
17262 + default:
17263 + return false;
17264 + }
17265 +}
17266 +
17267 +
17268 +static const struct of_device_id tas5713_of_match[] = {
17269 + { .compatible = "ti,tas5713", },
17270 + { }
17271 +};
17272 +MODULE_DEVICE_TABLE(of, tas5713_of_match);
17273 +
17274 +
17275 +static struct regmap_config tas5713_regmap_config = {
17276 + .reg_bits = 8,
17277 + .val_bits = 8,
17278 +
17279 + .max_register = TAS5713_MAX_REGISTER,
17280 + .volatile_reg = tas5713_reg_volatile,
17281 +
17282 + .cache_type = REGCACHE_RBTREE,
17283 + .reg_defaults = tas5713_reg_defaults,
17284 + .num_reg_defaults = ARRAY_SIZE(tas5713_reg_defaults),
17285 +};
17286 +
17287 +
17288 +static int tas5713_i2c_probe(struct i2c_client *i2c,
17289 + const struct i2c_device_id *id)
17290 +{
17291 + int ret;
17292 +
17293 + priv_data = devm_kzalloc(&i2c->dev, sizeof *priv_data, GFP_KERNEL);
17294 + if (!priv_data)
17295 + return -ENOMEM;
17296 +
17297 + priv_data->regmap = devm_regmap_init_i2c(i2c, &tas5713_regmap_config);
17298 + if (IS_ERR(priv_data->regmap)) {
17299 + ret = PTR_ERR(priv_data->regmap);
17300 + return ret;
17301 + }
17302 +
17303 + i2c_set_clientdata(i2c, priv_data);
17304 +
17305 + ret = snd_soc_register_component(&i2c->dev,
17306 + &soc_codec_dev_tas5713, &tas5713_dai, 1);
17307 +
17308 + return ret;
17309 +}
17310 +
17311 +
17312 +static void tas5713_i2c_remove(struct i2c_client *i2c)
17313 +{
17314 + snd_soc_unregister_component(&i2c->dev);
17315 + i2c_set_clientdata(i2c, NULL);
17316 +
17317 + kfree(priv_data);
17318 +}
17319 +
17320 +
17321 +static const struct i2c_device_id tas5713_i2c_id[] = {
17322 + { "tas5713", 0 },
17323 + { }
17324 +};
17325 +
17326 +MODULE_DEVICE_TABLE(i2c, tas5713_i2c_id);
17327 +
17328 +
17329 +static struct i2c_driver tas5713_i2c_driver = {
17330 + .driver = {
17331 + .name = "tas5713",
17332 + .owner = THIS_MODULE,
17333 + .of_match_table = tas5713_of_match,
17334 + },
17335 + .probe = tas5713_i2c_probe,
17336 + .remove = tas5713_i2c_remove,
17337 + .id_table = tas5713_i2c_id
17338 +};
17339 +
17340 +
17341 +static int __init tas5713_modinit(void)
17342 +{
17343 + int ret = 0;
17344 +
17345 + ret = i2c_add_driver(&tas5713_i2c_driver);
17346 + if (ret) {
17347 + printk(KERN_ERR "Failed to register tas5713 I2C driver: %d\n",
17348 + ret);
17349 + }
17350 +
17351 + return ret;
17352 +}
17353 +module_init(tas5713_modinit);
17354 +
17355 +
17356 +static void __exit tas5713_exit(void)
17357 +{
17358 + i2c_del_driver(&tas5713_i2c_driver);
17359 +}
17360 +module_exit(tas5713_exit);
17361 +
17362 +
17363 +MODULE_AUTHOR("Sebastian Eickhoff <basti.eickhoff@googlemail.com>");
17364 +MODULE_DESCRIPTION("ASoC driver for TAS5713");
17365 +MODULE_LICENSE("GPL v2");
17366 --- /dev/null
17367 +++ b/sound/soc/codecs/tas5713.h
17368 @@ -0,0 +1,210 @@
17369 +/*
17370 + * ASoC Driver for TAS5713
17371 + *
17372 + * Author: Sebastian Eickhoff <basti.eickhoff@googlemail.com>
17373 + * Copyright 2014
17374 + *
17375 + * This program is free software; you can redistribute it and/or
17376 + * modify it under the terms of the GNU General Public License
17377 + * version 2 as published by the Free Software Foundation.
17378 + *
17379 + * This program is distributed in the hope that it will be useful, but
17380 + * WITHOUT ANY WARRANTY; without even the implied warranty of
17381 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17382 + * General Public License for more details.
17383 + */
17384 +
17385 +#ifndef _TAS5713_H
17386 +#define _TAS5713_H
17387 +
17388 +
17389 +// TAS5713 I2C-bus register addresses
17390 +
17391 +#define TAS5713_CLOCK_CTRL 0x00
17392 +#define TAS5713_DEVICE_ID 0x01
17393 +#define TAS5713_ERROR_STATUS 0x02
17394 +#define TAS5713_SYSTEM_CTRL1 0x03
17395 +#define TAS5713_SERIAL_DATA_INTERFACE 0x04
17396 +#define TAS5713_SYSTEM_CTRL2 0x05
17397 +#define TAS5713_SOFT_MUTE 0x06
17398 +#define TAS5713_VOL_MASTER 0x07
17399 +#define TAS5713_VOL_CH1 0x08
17400 +#define TAS5713_VOL_CH2 0x09
17401 +#define TAS5713_VOL_HEADPHONE 0x0A
17402 +#define TAS5713_VOL_CONFIG 0x0E
17403 +#define TAS5713_MODULATION_LIMIT 0x10
17404 +#define TAS5713_IC_DLY_CH1 0x11
17405 +#define TAS5713_IC_DLY_CH2 0x12
17406 +#define TAS5713_IC_DLY_CH3 0x13
17407 +#define TAS5713_IC_DLY_CH4 0x14
17408 +
17409 +#define TAS5713_START_STOP_PERIOD 0x1A
17410 +#define TAS5713_OSC_TRIM 0x1B
17411 +#define TAS5713_BKND_ERR 0x1C
17412 +
17413 +#define TAS5713_INPUT_MUX 0x20
17414 +#define TAS5713_SRC_SELECT_CH4 0x21
17415 +#define TAS5713_PWM_MUX 0x25
17416 +
17417 +#define TAS5713_CH1_BQ0 0x29
17418 +#define TAS5713_CH1_BQ1 0x2A
17419 +#define TAS5713_CH1_BQ2 0x2B
17420 +#define TAS5713_CH1_BQ3 0x2C
17421 +#define TAS5713_CH1_BQ4 0x2D
17422 +#define TAS5713_CH1_BQ5 0x2E
17423 +#define TAS5713_CH1_BQ6 0x2F
17424 +#define TAS5713_CH1_BQ7 0x58
17425 +#define TAS5713_CH1_BQ8 0x59
17426 +
17427 +#define TAS5713_CH2_BQ0 0x30
17428 +#define TAS5713_CH2_BQ1 0x31
17429 +#define TAS5713_CH2_BQ2 0x32
17430 +#define TAS5713_CH2_BQ3 0x33
17431 +#define TAS5713_CH2_BQ4 0x34
17432 +#define TAS5713_CH2_BQ5 0x35
17433 +#define TAS5713_CH2_BQ6 0x36
17434 +#define TAS5713_CH2_BQ7 0x5C
17435 +#define TAS5713_CH2_BQ8 0x5D
17436 +
17437 +#define TAS5713_CH4_BQ0 0x5A
17438 +#define TAS5713_CH4_BQ1 0x5B
17439 +#define TAS5713_CH3_BQ0 0x5E
17440 +#define TAS5713_CH3_BQ1 0x5F
17441 +
17442 +#define TAS5713_DRC1_SOFTENING_FILTER_ALPHA_OMEGA 0x3B
17443 +#define TAS5713_DRC1_ATTACK_RELEASE_RATE 0x3C
17444 +#define TAS5713_DRC2_SOFTENING_FILTER_ALPHA_OMEGA 0x3E
17445 +#define TAS5713_DRC2_ATTACK_RELEASE_RATE 0x3F
17446 +#define TAS5713_DRC1_ATTACK_RELEASE_THRES 0x40
17447 +#define TAS5713_DRC2_ATTACK_RELEASE_THRES 0x43
17448 +#define TAS5713_DRC_CTRL 0x46
17449 +
17450 +#define TAS5713_BANK_SW_CTRL 0x50
17451 +#define TAS5713_CH1_OUTPUT_MIXER 0x51
17452 +#define TAS5713_CH2_OUTPUT_MIXER 0x52
17453 +#define TAS5713_CH1_INPUT_MIXER 0x53
17454 +#define TAS5713_CH2_INPUT_MIXER 0x54
17455 +#define TAS5713_OUTPUT_POST_SCALE 0x56
17456 +#define TAS5713_OUTPUT_PRESCALE 0x57
17457 +
17458 +#define TAS5713_IDF_POST_SCALE 0x62
17459 +
17460 +#define TAS5713_CH1_INLINE_MIXER 0x70
17461 +#define TAS5713_CH1_INLINE_DRC_EN_MIXER 0x71
17462 +#define TAS5713_CH1_R_CHANNEL_MIXER 0x72
17463 +#define TAS5713_CH1_L_CHANNEL_MIXER 0x73
17464 +#define TAS5713_CH2_INLINE_MIXER 0x74
17465 +#define TAS5713_CH2_INLINE_DRC_EN_MIXER 0x75
17466 +#define TAS5713_CH2_L_CHANNEL_MIXER 0x76
17467 +#define TAS5713_CH2_R_CHANNEL_MIXER 0x77
17468 +
17469 +#define TAS5713_UPDATE_DEV_ADDR_KEY 0xF8
17470 +#define TAS5713_UPDATE_DEV_ADDR_REG 0xF9
17471 +
17472 +#define TAS5713_REGISTER_COUNT 0x46
17473 +#define TAS5713_MAX_REGISTER 0xF9
17474 +
17475 +
17476 +// Bitmasks for registers
17477 +#define TAS5713_SOFT_MUTE_ALL 0x07
17478 +
17479 +
17480 +
17481 +struct tas5713_init_command {
17482 + const int size;
17483 + const char *const data;
17484 +};
17485 +
17486 +static const struct tas5713_init_command tas5713_init_sequence[] = {
17487 +
17488 + // Trim oscillator
17489 + { .size = 2, .data = "\x1B\x00" },
17490 + // System control register 1 (0x03): block DC
17491 + { .size = 2, .data = "\x03\x80" },
17492 + // Mute everything
17493 + { .size = 2, .data = "\x05\x40" },
17494 + // Modulation limit register (0x10): 97.7%
17495 + { .size = 2, .data = "\x10\x02" },
17496 + // Interchannel delay registers
17497 + // (0x11, 0x12, 0x13, and 0x14): BD mode
17498 + { .size = 2, .data = "\x11\xB8" },
17499 + { .size = 2, .data = "\x12\x60" },
17500 + { .size = 2, .data = "\x13\xA0" },
17501 + { .size = 2, .data = "\x14\x48" },
17502 + // PWM shutdown group register (0x19): no shutdown
17503 + { .size = 2, .data = "\x19\x00" },
17504 + // Input multiplexer register (0x20): BD mode
17505 + { .size = 2, .data = "\x20\x00\x89\x77\x72" },
17506 + // PWM output mux register (0x25)
17507 + // Channel 1 --> OUTA, channel 1 neg --> OUTB
17508 + // Channel 2 --> OUTC, channel 2 neg --> OUTD
17509 + { .size = 5, .data = "\x25\x01\x02\x13\x45" },
17510 + // DRC control (0x46): DRC off
17511 + { .size = 5, .data = "\x46\x00\x00\x00\x00" },
17512 + // BKND_ERR register (0x1C): 299ms reset period
17513 + { .size = 2, .data = "\x1C\x07" },
17514 + // Mute channel 3
17515 + { .size = 2, .data = "\x0A\xFF" },
17516 + // Volume configuration register (0x0E): volume slew 512 steps
17517 + { .size = 2, .data = "\x0E\x90" },
17518 + // Clock control register (0x00): 44/48kHz, MCLK=64xfs
17519 + { .size = 2, .data = "\x00\x60" },
17520 + // Bank switch and eq control (0x50): no bank switching
17521 + { .size = 5, .data = "\x50\x00\x00\x00\x00" },
17522 + // Volume registers (0x07, 0x08, 0x09, 0x0A)
17523 + { .size = 2, .data = "\x07\x20" },
17524 + { .size = 2, .data = "\x08\x30" },
17525 + { .size = 2, .data = "\x09\x30" },
17526 + { .size = 2, .data = "\x0A\xFF" },
17527 + // 0x72, 0x73, 0x76, 0x77 input mixer:
17528 + // no intermix between channels
17529 + { .size = 5, .data = "\x72\x00\x00\x00\x00" },
17530 + { .size = 5, .data = "\x73\x00\x80\x00\x00" },
17531 + { .size = 5, .data = "\x76\x00\x00\x00\x00" },
17532 + { .size = 5, .data = "\x77\x00\x80\x00\x00" },
17533 + // 0x70, 0x71, 0x74, 0x75 inline DRC mixer:
17534 + // no inline DRC inmix
17535 + { .size = 5, .data = "\x70\x00\x80\x00\x00" },
17536 + { .size = 5, .data = "\x71\x00\x00\x00\x00" },
17537 + { .size = 5, .data = "\x74\x00\x80\x00\x00" },
17538 + { .size = 5, .data = "\x75\x00\x00\x00\x00" },
17539 + // 0x56, 0x57 Output scale
17540 + { .size = 5, .data = "\x56\x00\x80\x00\x00" },
17541 + { .size = 5, .data = "\x57\x00\x02\x00\x00" },
17542 + // 0x3B, 0x3c
17543 + { .size = 9, .data = "\x3B\x00\x08\x00\x00\x00\x78\x00\x00" },
17544 + { .size = 9, .data = "\x3C\x00\x00\x01\x00\xFF\xFF\xFF\x00" },
17545 + { .size = 9, .data = "\x3E\x00\x08\x00\x00\x00\x78\x00\x00" },
17546 + { .size = 9, .data = "\x3F\x00\x00\x01\x00\xFF\xFF\xFF\x00" },
17547 + { .size = 9, .data = "\x40\x00\x00\x01\x00\xFF\xFF\xFF\x00" },
17548 + { .size = 9, .data = "\x43\x00\x00\x01\x00\xFF\xFF\xFF\x00" },
17549 + // 0x51, 0x52: output mixer
17550 + { .size = 9, .data = "\x51\x00\x80\x00\x00\x00\x00\x00\x00" },
17551 + { .size = 9, .data = "\x52\x00\x80\x00\x00\x00\x00\x00\x00" },
17552 + // PEQ defaults
17553 + { .size = 21, .data = "\x29\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
17554 + { .size = 21, .data = "\x2A\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
17555 + { .size = 21, .data = "\x2B\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
17556 + { .size = 21, .data = "\x2C\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
17557 + { .size = 21, .data = "\x2D\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
17558 + { .size = 21, .data = "\x2E\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
17559 + { .size = 21, .data = "\x2F\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
17560 + { .size = 21, .data = "\x30\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
17561 + { .size = 21, .data = "\x31\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
17562 + { .size = 21, .data = "\x32\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
17563 + { .size = 21, .data = "\x33\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
17564 + { .size = 21, .data = "\x34\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
17565 + { .size = 21, .data = "\x35\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
17566 + { .size = 21, .data = "\x36\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
17567 + { .size = 21, .data = "\x58\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
17568 + { .size = 21, .data = "\x59\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
17569 + { .size = 21, .data = "\x5C\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
17570 + { .size = 21, .data = "\x5D\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
17571 + { .size = 21, .data = "\x5E\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
17572 + { .size = 21, .data = "\x5F\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
17573 + { .size = 21, .data = "\x5A\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
17574 + { .size = 21, .data = "\x5B\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
17575 +};
17576 +
17577 +
17578 +#endif /* _TAS5713_H */
17579 --- a/sound/soc/soc-core.c
17580 +++ b/sound/soc/soc-core.c
17581 @@ -1223,7 +1223,15 @@ int snd_soc_runtime_set_dai_fmt(struct s
17582 return 0;
17583
17584 for_each_rtd_codec_dais(rtd, i, codec_dai) {
17585 - ret = snd_soc_dai_set_fmt(codec_dai, dai_fmt);
17586 + unsigned int codec_dai_fmt = dai_fmt;
17587 +
17588 + // there can only be one master when using multiple codecs
17589 + if (i && (codec_dai_fmt & SND_SOC_DAIFMT_MASTER_MASK)) {
17590 + codec_dai_fmt &= ~SND_SOC_DAIFMT_MASTER_MASK;
17591 + codec_dai_fmt |= SND_SOC_DAIFMT_CBS_CFS;
17592 + }
17593 +
17594 + ret = snd_soc_dai_set_fmt(codec_dai, codec_dai_fmt);
17595 if (ret != 0 && ret != -ENOTSUPP)
17596 return ret;
17597 }
17598 --- a/sound/usb/card.c
17599 +++ b/sound/usb/card.c
17600 @@ -856,8 +856,14 @@ static int usb_audio_probe(struct usb_in
17601 if (ignore_ctl_error)
17602 chip->quirk_flags |= QUIRK_FLAG_IGNORE_CTL_ERROR;
17603
17604 - if (chip->quirk_flags & QUIRK_FLAG_DISABLE_AUTOSUSPEND)
17605 + if (chip->quirk_flags & QUIRK_FLAG_DISABLE_AUTOSUSPEND) {
17606 + /*
17607 + * Grab the interface, because on a webcam uvcvideo may race
17608 + * with snd-usb-audio during probe and re-enable autosuspend.
17609 + */
17610 + usb_autopm_get_interface(intf);
17611 usb_disable_autosuspend(interface_to_usbdev(intf));
17612 + }
17613
17614 /*
17615 * For devices with more than one control interface, we assume the
17616 --- a/sound/usb/quirks.c
17617 +++ b/sound/usb/quirks.c
17618 @@ -2087,6 +2087,8 @@ static const struct usb_audio_quirk_flag
17619 QUIRK_FLAG_FIXED_RATE),
17620 DEVICE_FLG(0x0ecb, 0x2069, /* JBL Quantum810 Wireless */
17621 QUIRK_FLAG_FIXED_RATE),
17622 + DEVICE_FLG(0x09da, 0x2695, /* A4Tech FHD 1080p webcam */
17623 + QUIRK_FLAG_DISABLE_AUTOSUSPEND | QUIRK_FLAG_GET_SAMPLE_RATE),
17624 DEVICE_FLG(0x0fd9, 0x0008, /* Hauppauge HVR-950Q */
17625 QUIRK_FLAG_SHARE_MEDIA_DEVICE | QUIRK_FLAG_ALIGN_TRANSFER),
17626 DEVICE_FLG(0x1224, 0x2a25, /* Jieli Technology USB PHY 2.0 */