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
7 Content-Type: text/plain; charset=UTF-8
8 Content-Transfer-Encoding: 8bit
10 ASoC: Add support for Rpi-DAC
12 ASoC: Add prompt for ICS43432 codec
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
18 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
20 Add IQaudIO Sound Card support for Raspberry Pi
22 Set a limit of 0dB on Digital Volume Control
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.
29 Allow up to 24dB digital gain to be applied when using IQAudIO DAC+
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.
35 Modify IQAudIO DAC+ ASoC driver to set card/dai config from dt
37 Add the ability to set the card name, dai name and dai stream name, from
40 Signed-off-by: DigitalDreamtime <clive.messer@digitaldreamtime.co.uk>
42 IQaudIO: auto-mute for AMP+ and DigiAMP+
44 IQAudIO amplifier mute via GPIO22. Add dt params for "one-shot" unmute
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."
53 Tested on both AMP+ (via DAC+) and DigiAMP+, with both options...
55 dtoverlay=iqaudio-dacplus,unmute_amp
56 "one-shot" unmute when kernel module loads.
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.)
63 Revision 4, using gpiod.
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
69 Revision 6, don't attempt to "one-shot" unmute amp, unless card is
70 successfully registered.
72 Signed-off-by: DigitalDreamtime <clive.messer@digitaldreamtime.co.uk>
74 ASoC: iqaudio-dac: fix S24_LE format
76 Remove set_bclk_ratio call so 24-bit data is transmitted in
79 Signed-off-by: Matthias Reichl <hias@horus.com>
81 ASoC: iqaudio-dac: use modern dai_link style
83 Signed-off-by: Matthias Reichl <hias@horus.com>
85 Added support for HiFiBerry DAC+
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.
90 Add support for the HiFiBerry DAC+ Pro.
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.
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.
96 Limit PCM512x "Digital" gain to 0dB by default with HiFiBerry DAC+
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.
102 Add dt param to force HiFiBerry DAC+ Pro into slave mode
104 "dtoverlay=hifiberry-dacplus,slave"
106 Add 'slave' param to use HiFiBerry DAC+ Pro in slave mode,
107 with Pi as master for bit and frame clock.
109 Signed-off-by: DigitalDreamtime <clive.messer@digitaldreamtime.co.uk>
111 Fixed a bug when using 352.8kHz sample rate
113 Signed-off-by: Daniel Matuschek <daniel@hifiberry.com>
115 ASoC: pcm512x: revert downstream changes
117 This partially reverts commit 185ea05465aac8bf02a0d2b2f4289d42c72870b7
118 which was added by https://github.com/raspberrypi/linux/pull/1152
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.
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
129 Signed-off-by: Matthias Reichl <hias@horus.com>
131 ASoC: hifiberry_dacplus: fix S24_LE format
133 Remove set_bclk_ratio call so 24-bit data is transmitted in
136 Signed-off-by: Matthias Reichl <hias@horus.com>
138 ASoC: hifiberry_dacplus: transmit S24_LE with 64 BCLK cycles
140 Signed-off-by: Matthias Reichl <hias@horus.com>
142 hifiberry_dacplus: switch to snd_soc_dai_set_bclk_ratio
144 Signed-off-by: Matthias Reichl <hias@horus.com>
146 ASoC: hifiberry_dacplus: use modern dai_link style
148 Signed-off-by: Hui Wang <hui.wang@canonical.com>
150 Add driver for rpi-proto
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.
156 URL to the audio chip:
157 http://www.mikroe.com/add-on-boards/audio-voice/audio-codec-proto/
159 Playback tested with devicetree enabled.
161 Signed-off-by: Waldemar Brodkorb <wbrodkorb@conet.de>
163 ASoC: rpi-proto: use modern dai_link style
165 Signed-off-by: Hui Wang <hui.wang@canonical.com>
167 Add Support for JustBoom Audio boards
169 justboom-dac: Adjust for ALSA API change
171 As of 4.4, snd_soc_limit_volume now takes a struct snd_soc_card *
172 rather than a struct snd_soc_codec *.
174 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
176 ASoC: justboom-dac: fix S24_LE format
178 Remove set_bclk_ratio call so 24-bit data is transmitted in
181 Also remove hw_params as it's no longer needed.
183 Signed-off-by: Matthias Reichl <hias@horus.com>
185 ASoC: justboom-dac: use modern dai_link style
187 Signed-off-by: Matthias Reichl <hias@horus.com>
189 New AudioInjector.net Pi soundcard with low jitter audio in and out.
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.
196 Added support for headphones, microphone and bclk_ratio settings.
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.
200 ASoC: audioinjector-pi-soundcard: use modern dai_link style
202 Signed-off-by: Hui Wang <hui.wang@canonical.com>
204 New driver for RRA DigiDAC1 soundcard using WM8741 + WM8804
206 ASoC: digidac1-soundcard: use modern dai_link style
208 Signed-off-by: Hui Wang <hui.wang@canonical.com>
210 Add support for Dion Audio LOCO DAC-AMP HAT
212 Using dedicated machine driver and pcm5102a codec driver.
214 Signed-off-by: DigitalDreamtime <clive.messer@digitaldreamtime.co.uk>
216 ASoC: dionaudio_loco: use modern dai_link style
218 Signed-off-by: Hui Wang <hui.wang@canonical.com>
220 Allo Piano DAC boards: Initial 2 channel (stereo) support (#1645)
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
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
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>
237 ASoC: allo-piano-dac: fix S24_LE format
239 Remove set_bclk_ratio call so 24-bit data is transmitted in
242 Also remove hw_params and ops as they are no longer needed.
244 Signed-off-by: Matthias Reichl <hias@horus.com>
246 ASoC: allo-piano-dac: use modern dai_link style
248 Signed-off-by: Hui Wang <hui.wang@canonical.com>
250 Add support for Allo Piano DAC 2.1 plus add-on board for Raspberry Pi.
252 The Piano DAC 2.1 has support for 4 channels with subwoofer.
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>
258 Add clock changes and mute gpios (#1938)
260 Also improve code style and adhere to ALSA coding conventions.
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>
266 PianoPlus: Dual Mono & Dual Stereo features added (#2069)
268 allo-piano-dac-plus: Master volume added + fixes
270 Master volume added, which controls both DACs volumes.
272 See: https://github.com/raspberrypi/linux/pull/2149
274 Also fix initial max volume, default mode value, and unmute.
276 Signed-off-by: allocom <sparky-dev@allo.com>
278 ASoC: allo-piano-dac-plus: fix S24_LE format
280 Remove set_bclk_ratio call so 24-bit data is transmitted in
283 Signed-off-by: Matthias Reichl <hias@horus.com>
285 sound: bcm: Fix memset dereference warning
287 This warning appears with GCC 6.4.0 from toolchains.bootlin.com:
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));
294 Suggested-by: Phil Elwell <phil@raspberrypi.org>
295 Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
297 ASoC: allo-piano-dac-plus: use modern dai_link style
299 Signed-off-by: Hui Wang <hui.wang@canonical.com>
301 Add support for Allo Boss DAC add-on board for Raspberry Pi. (#1924)
303 Signed-off-by: Baswaraj K <jaikumar@cem-solutions.net>
304 Reviewed-by: Deepak <deepak@zilogic.com>
305 Reviewed-by: BabuSubashChandar <babusubashchandar@zilogic.com>
307 Add support for new clock rate and mute gpios.
309 Signed-off-by: Baswaraj K <jaikumar@cem-solutions.net>
310 Reviewed-by: Deepak <deepak@zilogic.com>
311 Reviewed-by: BabuSubashChandar <babusubashchandar@zilogic.com>
313 ASoC: allo-boss-dac: fix S24_LE format
315 Remove set_bclk_ratio call so 24-bit data is transmitted in
318 Signed-off-by: Matthias Reichl <hias@horus.com>
320 ASoC: allo-boss-dac: transmit S24_LE with 64 BCLK cycles
322 Signed-off-by: Matthias Reichl <hias@horus.com>
324 allo-boss-dac: switch to snd_soc_dai_set_bclk_ratio
326 Signed-off-by: Matthias Reichl <hias@horus.com>
328 ASoC: allo-boss-dac: use modern dai_link style
330 Signed-off-by: Hui Wang <hui.wang@canonical.com>
332 Support for Blokas Labs pisound board
334 Pisound dynamic overlay (#1760)
336 Restructuring pisound-overlay.dts, so it can be loaded and unloaded dynamically using dtoverlay.
338 Print a logline when the kernel module is removed.
340 pisound improvements:
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.
349 Add missing SND_PISOUND selects dependency to SND_RAWMIDI
351 Without it the Pisound module fails to compile.
352 See https://github.com/raspberrypi/linux/issues/2366
354 Updates for Pisound module code:
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
362 Signed-off-by: Giedrius Trainavicius <giedrius@blokas.io>
364 Fixing memset call in pisound.c
366 Signed-off-by: Giedrius Trainavicius <giedrius@blokas.io>
368 Fix for Pisound's MIDI Input getting blocked for a while in rare cases.
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
374 Signed-off-by: Giedrius Trainavicius <giedrius@blokas.io>
376 Fix for Pisound kernel module in Real Time kernel configuration.
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
383 Pisound: Remove spinlock usage around spi_sync
385 ASoC: pisound: use modern dai_link style
387 Signed-off-by: Hui Wang <hui.wang@canonical.com>
389 ASoC: pisound: fix the parameter for spi_device_match
391 Signed-off-by: Hui Wang <hui.wang@canonical.com>
393 ASoC: Add driver for Cirrus Logic Audio Card
395 Note: due to problems with deferred probing of regulators
396 the following softdep should be added to a modprobe.d file
398 softdep arizona-spi pre: arizona-ldo1
400 Signed-off-by: Matthias Reichl <hias@horus.com>
402 ASoC: rpi-cirrus: use modern dai_link style
404 Signed-off-by: Matthias Reichl <hias@horus.com>
406 sound: Support for Dion Audio LOCO-V2 DAC-AMP HAT
408 Signed-off-by: Miquel Blauw <info@dionaudio.nl>
410 ASoC: dionaudio_loco-v2: fix S24_LE format
412 Remove set_bclk_ratio call so 24-bit data is transmitted in
415 Also remove hw_params and ops as they are no longer needed.
417 Signed-off-by: Matthias Reichl <hias@horus.com>
419 ASoC: dionaudio_loco-v2: use modern dai_link style
421 Signed-off-by: Hui Wang <hui.wang@canonical.com>
423 Add support for Fe-Pi audio sound card. (#1867)
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.
429 Signed-off-by: Henry Kupis <fe-pi@cox.net>
431 ASoC: fe-pi-audio: use modern dai_link style
433 Signed-off-by: Hui Wang <hui.wang@canonical.com>
435 Add support for the AudioInjector.net Octo sound card
437 AudioInjector Octo: sample rates, regulators, reset
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
443 Reference the bcm270x DT regulators in the overlay.
445 This patch adds a reset GPIO for the AudioInjector.net octo sound card.
447 Audioinjector octo : Make the playback and capture symmetric
449 This patch ensures that the sample rate and channel count of the audioinjector
450 octo sound card are symmetric.
452 audioinjector-octo: Add continuous clock feature
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
459 See: https://github.com/raspberrypi/linux/issues/2409
461 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
463 sound: Fixes for audioinjector-octo under 4.19
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.
469 2. Fix the diagnostics in an error path of the soundcard driver to
470 correctly identify the reason for the failure to load.
472 3. Move the declaration of the clock node in the overlay outside
473 the I2C node to avoid warnings.
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...)
479 See: https://github.com/Audio-Injector/Octo/issues/14
480 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
482 [1] af503716ac14 ("i2c: core: report OF style module alias for devices registered via OF")
484 ASoC: audioinjector-octo-soundcard: use modern dai_link style
486 Signed-off-by: Hui Wang <hui.wang@canonical.com>
488 Driver support for Google voiceHAT soundcard.
490 ASoC: googlevoicehat-codec: Use correct device when grabbing GPIO
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.
496 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
498 ASoC: googlevoicehat-codec: Reformat for kernel coding standards
500 Fix all whitespace, indentation, and bracing errors.
502 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
504 ASoC: googlevoicehat-codec: Make driver function structure const
506 Make voicehat_component_driver a const structure.
508 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
510 ASoC: googlevoicehat-codec: Only convert from ms to jiffies once
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.
516 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
518 Driver and overlay for Allo Katana DAC
520 Allo Katana DAC: Updated default values
522 Signed-off-by: Jaikumar <jaikumar@cem-solutions.com>
524 Added mute stream func
526 Signed-off-by: Jaikumar <jaikumar@cem-solutions.net>
528 codecs: Correct Katana minimum volume
530 Update Katana minimum volume to get the exact 0.5 dB value in each step.
532 Signed-off-by: Sudeep Kumar <sudeepkumar@cem-solutions.net>
534 ASoC: Add generic RPI driver for simple soundcards.
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.
541 This initial commit adds support for the ADAU1977 ADC, Google VoiceHat,
542 HifiBerry AMP, HifiBerry DAC and RPI DAC.
544 Signed-off-by: Tim Gover <tim.gover@raspberrypi.org>
546 ASoC: Use correct card name in rpi-simple driver
548 Use the specific card name from drvdata instead of the snd_rpi_simple
550 rpi-simple-soundcard: Use nicer driver name "RPi-simple"
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
556 ASoC: rpi-simple-soundcard: use modern dai_link style
558 Signed-off-by: Hui Wang <hui.wang@canonical.com>
560 ASoC: Add Kconfig and Makefile for sound/soc/bcm
562 Signed-off-by: popcornmix <popcornmix@gmail.com>
564 ASoC: Create a generic Pi Hat WM8804 driver
566 Reduce the amount of duplicated code by creating a generic driver for
567 Pi Hat digi cards using the WM8804 codec.
570 Allo DigiOne, Hifiberry Digi/Pro, JustBoom Digi and IQAudIO Digi
571 dedicate soundcard drivers with a generic driver.
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
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
585 ASoC: rpi-wm8804-soundcard: use modern dai_link style
587 Signed-off-by: Matthias Reichl <hias@horus.com>
589 rpi-wm8804-soundcard: drop PWRDN register writes
591 Since kernel 4.0 the PWRDN register bits are under DAPM
592 control from the wm8804 driver.
594 Drop code that modifies that register to avoid interfering
597 Signed-off-by: Matthias Reichl <hias@horus.com>
599 rpi-wm8804-soundcard: configure wm8804 clocks only on rate change
601 This should avoid clicks when stopping and immediately afterwards
602 starting a stream with the same samplerate as before.
604 Signed-off-by: Matthias Reichl <hias@horus.com>
606 rpi-wm8804-soundcard: Fixed MCLKDIV for Allo Digione
608 The Allo Digione board wants a fixed MCLKDIV of 256.
610 See: https://github.com/raspberrypi/linux/issues/3296
612 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
614 ASoC: Add support for AudioSense-Pi add-on soundcard
616 AudioSense-Pi is a RPi HAT based on a TI's TLV320AIC32x4 stereo codec
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.
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
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)
637 Audio output can be routed to the headphones or
638 speakers (with additional hardware)
640 Signed-off-by: b-ak <anur.bhargav@gmail.com>
642 ASoC: audiosense-pi: use modern dai_link style
644 Signed-off-by: Hui Wang <hui.wang@canonical.com>
646 Added driver for the HiFiBerry DAC+ ADC (#2694)
648 Signed-off-by: Daniel Matuschek <daniel@hifiberry.com>
650 hifiberry_dacplusadc: switch to snd_soc_dai_set_bclk_ratio
652 Signed-off-by: Matthias Reichl <hias@horus.com>
654 ASoC: hifiberry_dacplusadc: fix DAI link setup
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.
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).
663 So drop the offending code to prevent issues if a dmic property
664 should be added to the DT overlay.
666 Signed-off-by: Matthias Reichl <hias@horus.com>
668 ASoC: hifiberry_dacplusadc: use modern dai_link style
670 Signed-off-by: Matthias Reichl <hias@horus.com>
672 Audiophonics I-Sabre 9038Q2M DAC driver
674 Signed-off-by: Audiophonics <contact@audiophonics.fr>
676 ASoC: i-sabre-q2m: use modern dai_link style
678 Signed-off-by: Hui Wang <hui.wang@canonical.com>
680 Added IQaudIO Pi-Codec board support (#2969)
682 Add support for the IQaudIO Pi-Codec board.
684 Signed-off-by: Gordon <gordon@iqaudio.com>
686 Fixed 48k timing issue
688 ASoC: iqaudio-codec: use modern dai_link style
690 Signed-off-by: Hui Wang <hui.wang@canonical.com>
692 adds the Hifiberry DAC+ADC PRO version
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
697 Add Hifiberry DAC+DSP soundcard driver (#3224)
699 Adds the driver for the Hifiberry DAC+DSP. It supports capture and
700 playback depending on the DSP firmware.
702 Signed-off-by: Joerg Schambacher <joerg@i2audio.com>
704 Allow simultaneous use of JustBoom DAC and Digi
706 Signed-off-by: Johannes Krude <johannes@krude.de>
708 Pisound: MIDI communication fixes for scaled down CPU.
710 * Increased maximum SPI communication speed to avoid running too slow
711 when the CPU is scaled down and losing MIDI data.
713 * Keep track of buffer usage in millibytes for higher precision.
715 Signed-off-by: Giedrius Trainavičius <giedrius@blokas.io>
717 sound: Add the HiFiBerry DAC+HD version
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.
722 Signed-off-by: Joerg Schambacher <joerg@i2audio.com>
724 Fix master mode settings of HiFiBerry DAC+ADC PRO card (#3424)
726 This patch fixes the board DAI setting when in master-mode.
727 Wrong setting could have caused random pop noise.
729 Signed-off-by: Joerg Schambacher <joerg@i2audio.com>
731 adds LED OFF feature to HiFiBerry DAC+ADC PRO sound card
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.
737 Signed-off-by: Joerg Schambacher <joerg@i2audio.com>
739 adds LED OFF feature to HiFiBerry DAC+ADC sound card
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.
745 Signed-off-by: Joerg Schambacher <joerg@i2audio.com>
747 adds LED OFF feature to HiFiBerry DAC+/DAC+PRO sound cards
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.
753 Signed-off-by: Joerg Schambacher <joerg@i2audio.com>
755 pisound: Added reading Pisound board hardware revision and exposing it (#3425)
757 pisound: Added reading Pisound board hardware revision and exposing it in kernel log and sysfs file:
759 /sys/kernel/pisound/hw_version
761 Signed-off-by: Giedrius <giedrius@blokas.io>
763 Added driver for HiFiBerry Amp amplifier add-on board
765 The driver contains a low-level hardware driver for the TAS5713 and the
766 drivers for the Raspberry Pi I2S subsystem.
768 TAS5713: return error if initialisation fails
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.
775 HiFiBerry Amp: fix device-tree problems
777 Some code to load the driver based on device-tree-overlays was missing. This is added by this patch.
779 According to 5713 pdf doc CLOCK_CTRL is a readonly status register, and it behaves so. Remove useless setting
781 sound: pcm512x-codec: Adding 352.8kHz samplerate support
783 sound/soc: only first codec is master in multicodec setup
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
789 Signed-off-by: Johannes Krude <johannes@krude.de>
791 ASoC: Fix snd_soc_get_pcm_runtime usage
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
797 Signed-off-by: Phil Elwell <phil@raspberrypi.com>
799 [1] 4468189ff307 ("ASoC: soc-core: find rtd via dai_link pointer at snd_soc_get_pcm_runtime()")
801 Add support for the AudioInjector.net Isolated sound card
803 This patch adds support for the Audio Injector Isolated sound card.
805 Signed-off-by: Matt Flax <flatmax@flatmax.org>
807 Add support for merus-amp soundcard and ma120x0p codec
809 Add 96KHz rate support to MA120X0P codec and make enable and mute gpio
812 Signed-off-by: AMuszkat <ariel.muszkat@gmail.com>
814 Fixes a problem with clock settings of HiFiBerry DAC+ADC PRO (#3545)
816 This patch fixes a problem of the re-calculation of
817 i2s-clock and -parameter settings when only the ADC is activated.
819 Signed-off-by: Joerg Schambacher <joerg@i2audio.com>
821 configs: Enable the AD193x codecs
823 See: https://github.com/raspberrypi/linux/issues/2850
825 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
827 Switch to snd_soc_dai_set_bclk_ratio
828 Replaces obsolete function snd_soc_dai_set_tdm_slot
830 Signed-off-by: Joerg Schambacher <joerg@i2audio.com>
832 Enhances the DAC+ driver to control the optional headphone amplifier
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.
838 Signed-off-by: Joerg Schambacher joerg@i2audio.com
840 Update Allo Piano Dac Driver
842 Add unique names to the individual dac coded drivers
843 Remove some of the codec controls that are not used.
845 Signed-off-by: Paul Hermann <paul@picoreplayer.org>
847 Fixes an onboard clock detection problem of the PRO versions
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.
853 Signed-off-by: Joerg Schambacher <joerg@hifiberry.com>
855 ASoC:ma120x0p: Increase maximum sample rate to 192KHz
857 Change the maximum sample rate for the amplifier to
858 192KHz as given in the Infineon specification.
860 Signed-off-by: Joerg Schambacher <joerg@hifiberry.com>
862 ASoC: ma120x0p: Remove unnecessary const specifier
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,
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)
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, \
877 SOC_VALUE_ENUM_DOUBLE_DECL already has a const specifier. Remove the duplicate
878 const to clean up the warning.
880 Fixes: 42444979e710 ("Add support for all the downstream rpi sound card drivers")
881 Signed-off-by: Nathan Chancellor <nathan@kernel.org>
883 ASoC: bcm: allo-piano-dac-plus: Remove unnecessary const specifiers
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,
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)
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, \
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,
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)
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, \
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,
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)
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, \
914 3 warnings generated.
916 SOC_VALUE_ENUM_DOUBLE_DECL already has a const specifier. Remove the duplicate
917 const specifiers to clean up the warnings.
919 Fixes: 42444979e710 ("Add support for all the downstream rpi sound card drivers")
920 Signed-off-by: Nathan Chancellor <nathan@kernel.org>
922 rpi-simple-soundcard: Add Dion Audio KIWI streamer
924 Signed-off-by: Miquel Blauw <miquelblauw@hotmail.com>
926 rpi-simple-soundcard: adds definitions for the HiFiBerry AMP3 card
928 Uses Infineon MA120x0 amplifier and supports full sample rate of 192ksps.
930 Signed-off-by: Joerg Schambacher <joerg@hifiberry.com>
932 sound: soc: bcm: Added Sound card driver for Dacberry400 Audio card for Raspberry Pi 400
934 Added Sound card driver for DACberry400 Audio card.
936 Signed-off-by: Ashish Vara <ashishhvara@gmail.com>
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
1038 +++ b/Documentation/devicetree/bindings/vendor-prefixes.txt
1040 +Device tree binding vendor prefix registry. Keep list in alphabetical order.
1042 +This isn't an exhaustive list, but you should add new prefixes to it before
1043 +using them to avoid name-space collisions.
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
1059 +allwinner Allwinner Technology Co., Ltd.
1060 +alphascale AlphaScale Integrated Circuits Systems, Inc.
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.
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.
1078 +aries Aries Embedded GmbH
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.
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
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
1114 +chipidea Chipidea, Inc
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
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
1155 +eckelmann Eckelmann AG
1156 +edt Emerging Display Technologies
1157 +eeti eGalax_eMPIA Technology Inc
1158 +elan Elan Microelectronic Corp.
1160 +embest Shenzhen Embest Technology Co., 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.
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
1177 +ezchip EZchip Semiconductor
1179 +fairphone Fairphone B.V.
1180 +faraday Faraday Technology Corporation
1182 +fcs Fairchild Semiconductor
1183 +feiyang Shenzhen Fly Young Technology Co.,LTD.
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.
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
1211 +himax Himax Technologies, Inc.
1212 +hisilicon Hisilicon Limited.
1214 +hitex Hitex Development Tools
1215 +holt Holt Integrated Circuits, Inc.
1216 +honeywell Honeywell
1218 +holtek Holtek Semiconductor, Inc.
1219 +hwacom HwaCom Systems Inc.
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.
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
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
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.
1264 +libretech Shenzhen Libre Technology Co., Ltd
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
1279 +meas Measurement Specialties
1280 +mediatek MediaTek Inc.
1281 +megachips MegaChips
1282 +mele Shenzhen MeLE Digital Technology Ltd.
1283 +melexis Melexis N.V.
1285 +mellanox Mellanox Technologies
1287 +merrii Merrii Technology Co., Ltd.
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.
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.
1313 +netlogic Broadcom Corporation (formerly NetLogic Microsystems)
1314 +netron-dy Netron DY
1315 +netxeon Shenzhen Netxeon Technology CO., LTD
1317 +nextthing Next Thing Co.
1318 +newhaven Newhaven Display International
1319 +ni National Instruments
1321 +nlt NLT Technologies, Ltd.
1323 +nordic Nordic Semiconductor
1324 +novtech NovTech, Inc.
1325 +nutsboard NutsBoard
1326 +nuvoton Nuvoton Technology Corporation
1327 +nvd New Vision Display
1329 +nxp NXP Semiconductors
1330 +okaya Okaya Electric America, Inc.
1331 +oki Oki Electric Industry Co., 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
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
1356 +pixcir PIXCIR MICROELECTRONICS Co., Ltd
1357 +plantower Plantower Co., Ltd
1358 +plathome Plat'Home Co., Ltd.
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
1371 +qiaodian QiaoDian XianShi Corporation
1372 +qnap QNAP Systems, Inc.
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
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.
1408 +silabs Silicon Laboratories
1410 +silergy Silergy Corp.
1411 +siliconmitus Silicon Mitus, Inc.
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.
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
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.
1453 +toshiba Toshiba Corporation
1456 +tplink TP-LINK Technologies Co., Ltd.
1459 +tronsmart Tronsmart
1460 +truly Truly Semiconductors Limited
1461 +tsd Theobroma Systems Design und Consulting GmbH
1462 +tyan Tyan Computer Corporation
1464 +ucrobotics uCRobotics
1465 +ubnt Ubiquiti Networks
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
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.
1485 +whwave Shenzhen whwave Electronics, Inc.
1487 +winbond Winbond Electronics corp.
1488 +winstar Winstar Display Corp.
1489 +wlf Wolfson Microelectronics
1490 +wm Wondermedia Technologies, Inc.
1492 +xes Extreme Engineering Solutions (X-ES)
1493 +xillybus Xillybus Ltd.
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
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
1508 description: Bitmain Technologies
1510 + description: Vilniaus Blokas UAB
1512 description: BluTek Power
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
1520 +config COMMON_CLK_HIFIBERRY_DACPLUSHD
1523 +config COMMON_CLK_HIFIBERRY_DACPRO
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
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
1549 +++ b/drivers/clk/clk-allo-dac.c
1552 + * Clock Driver for Allo DAC
1554 + * Author: Baswaraj K <jaikumar@cem-solutions.net>
1556 + * based on code by Stuart MacLean
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.
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.
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>
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
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
1586 +struct clk_allo_hw {
1591 +#define to_allo_clk(_hw) container_of(_hw, struct clk_allo_hw, hw)
1593 +static const struct of_device_id clk_allo_dac_dt_ids[] = {
1594 + { .compatible = "allo,dac-clk",},
1597 +MODULE_DEVICE_TABLE(of, clk_allo_dac_dt_ids);
1599 +static unsigned long clk_allo_dac_recalc_rate(struct clk_hw *hw,
1600 + unsigned long parent_rate)
1602 + return (to_allo_clk(hw)->mode == 0) ? CLK_44EN_RATE :
1606 +static long clk_allo_dac_round_rate(struct clk_hw *hw,
1607 + unsigned long rate, unsigned long *parent_rate)
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;
1616 + long diff44Rate = (long)(rate - CLK_44EN_RATE);
1617 + long diff48Rate = (long)(CLK_48EN_RATE - rate);
1619 + if (diff44Rate < diff48Rate)
1620 + actual_rate = (long)CLK_44EN_RATE;
1622 + actual_rate = (long)CLK_48EN_RATE;
1624 + return actual_rate;
1628 +static int clk_allo_dac_set_rate(struct clk_hw *hw,
1629 + unsigned long rate, unsigned long parent_rate)
1631 + unsigned long actual_rate;
1632 + struct clk_allo_hw *clk = to_allo_clk(hw);
1634 + actual_rate = (unsigned long)clk_allo_dac_round_rate(hw, rate,
1636 + clk->mode = (actual_rate == CLK_44EN_RATE) ? 0 : 1;
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,
1647 +static int clk_allo_dac_probe(struct platform_device *pdev)
1650 + struct clk_allo_hw *proclk;
1652 + struct device *dev;
1653 + struct clk_init_data init;
1657 + proclk = kzalloc(sizeof(struct clk_allo_hw), GFP_KERNEL);
1661 + init.name = "clk-allo-dac";
1662 + init.ops = &clk_allo_dac_rate_ops;
1664 + init.parent_names = NULL;
1665 + init.num_parents = 0;
1668 + proclk->hw.init = &init;
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,
1675 + dev_err(dev, "Fail to register clock driver\n");
1677 + ret = PTR_ERR(clk);
1682 +static int clk_allo_dac_remove(struct platform_device *pdev)
1684 + of_clk_del_provider(pdev->dev.of_node);
1688 +static struct platform_driver clk_allo_dac_driver = {
1689 + .probe = clk_allo_dac_probe,
1690 + .remove = clk_allo_dac_remove,
1692 + .name = "clk-allo-dac",
1693 + .of_match_table = clk_allo_dac_dt_ids,
1697 +static int __init clk_allo_dac_init(void)
1699 + return platform_driver_register(&clk_allo_dac_driver);
1701 +core_initcall(clk_allo_dac_init);
1703 +static void __exit clk_allo_dac_exit(void)
1705 + platform_driver_unregister(&clk_allo_dac_driver);
1707 +module_exit(clk_allo_dac_exit);
1709 +MODULE_DESCRIPTION("Allo DAC clock driver");
1710 +MODULE_LICENSE("GPL v2");
1711 +MODULE_ALIAS("platform:clk-allo-dac");
1713 +++ b/drivers/clk/clk-hifiberry-dachd.c
1715 +// SPDX-License-Identifier: GPL-2.0
1717 + * Clock Driver for HiFiBerry DAC+ HD
1719 + * Author: Joerg Schambacher, i2Audio GmbH for HiFiBerry
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.
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.
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>
1742 +#define NO_PLL_RESET 0
1743 +#define PLL_RESET 1
1744 +#define HIFIBERRY_PLL_MAX_REGISTER 256
1745 +#define DEFAULT_RATE 44100
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},
1760 + {0x1A, 0x3D}, {0x1B, 0x09}, {0x1E, 0xF3}, {0x20, 0x13},
1761 + {0x21, 0x75}, {0x2B, 0x04}, {0x2D, 0x11}, {0x2E, 0xE0},
1763 + {0x35, 0x9D}, {0x36, 0x00}, {0x3C, 0x42},
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;
1782 + * struct clk_hifiberry_drvdata - Common struct to the HiFiBerry DAC HD Clk
1783 + * @hw: clk_hw for the common clk framework
1785 +struct clk_hifiberry_drvdata {
1786 + struct regmap *regmap;
1789 + unsigned long rate;
1792 +#define to_hifiberry_clk(_hw) \
1793 + container_of(_hw, struct clk_hifiberry_drvdata, hw)
1795 +static int clk_hifiberry_dachd_write_pll_regs(struct regmap *regmap,
1796 + struct reg_default *regs,
1797 + int num, int do_pll_reset)
1801 + char pll_soft_reset[] = { 177, 0xAC, };
1803 + for (i = 0; i < num; i++) {
1804 + ret |= regmap_write(regmap, regs[i].reg, regs[i].def);
1808 + if (do_pll_reset) {
1809 + ret |= regmap_write(regmap, pll_soft_reset[0],
1810 + pll_soft_reset[1]);
1816 +static unsigned long clk_hifiberry_dachd_recalc_rate(struct clk_hw *hw,
1817 + unsigned long parent_rate)
1819 + return to_hifiberry_clk(hw)->rate;
1822 +static long clk_hifiberry_dachd_round_rate(struct clk_hw *hw,
1823 + unsigned long rate, unsigned long *parent_rate)
1828 +static int clk_hifiberry_dachd_set_rate(struct clk_hw *hw,
1829 + unsigned long rate, unsigned long parent_rate)
1832 + struct clk_hifiberry_drvdata *drvdata = to_hifiberry_clk(hw);
1836 + ret = clk_hifiberry_dachd_write_pll_regs(drvdata->regmap,
1837 + dedicated_44k1_pll_regs, num_dedicated_44k1_pll_regs,
1841 + ret = clk_hifiberry_dachd_write_pll_regs(drvdata->regmap,
1842 + dedicated_88k2_pll_regs, num_dedicated_88k2_pll_regs,
1846 + ret = clk_hifiberry_dachd_write_pll_regs(drvdata->regmap,
1847 + dedicated_176k4_pll_regs, num_dedicated_176k4_pll_regs,
1851 + ret = clk_hifiberry_dachd_write_pll_regs(drvdata->regmap,
1852 + dedicated_48k_pll_regs, num_dedicated_48k_pll_regs,
1856 + ret = clk_hifiberry_dachd_write_pll_regs(drvdata->regmap,
1857 + dedicated_96k_pll_regs, num_dedicated_96k_pll_regs,
1861 + ret = clk_hifiberry_dachd_write_pll_regs(drvdata->regmap,
1862 + dedicated_192k_pll_regs, num_dedicated_192k_pll_regs,
1869 + to_hifiberry_clk(hw)->rate = rate;
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,
1880 +static int clk_hifiberry_get_prop_values(struct device *dev,
1882 + struct reg_default *regs)
1886 + u8 tmp[2 * HIFIBERRY_PLL_MAX_REGISTER];
1888 + ret = of_property_read_variable_u8_array(dev->of_node, prop_name,
1889 + tmp, 0, 2 * HIFIBERRY_PLL_MAX_REGISTER);
1894 + "%s <%s> -> #%i odd number of bytes for reg/val pairs!",
1901 + for (i = 0; i < ret; i++) {
1902 + regs[i].reg = (u32)tmp[2 * i];
1903 + regs[i].def = (u32)tmp[2 * i + 1];
1909 +static int clk_hifiberry_dachd_dt_parse(struct device *dev)
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);
1929 +static int clk_hifiberry_dachd_remove(struct device *dev)
1931 + of_clk_del_provider(dev->of_node);
1935 +const struct regmap_config hifiberry_pll_regmap = {
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,
1943 +EXPORT_SYMBOL_GPL(hifiberry_pll_regmap);
1946 +static int clk_hifiberry_dachd_i2c_probe(struct i2c_client *i2c,
1947 + const struct i2c_device_id *id)
1949 + struct clk_hifiberry_drvdata *hdclk;
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;
1956 + hdclk = devm_kzalloc(&i2c->dev,
1957 + sizeof(struct clk_hifiberry_drvdata), GFP_KERNEL);
1961 + i2c_set_clientdata(i2c, hdclk);
1963 + hdclk->regmap = devm_regmap_init_i2c(i2c, &config);
1965 + if (IS_ERR(hdclk->regmap))
1966 + return PTR_ERR(hdclk->regmap);
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),
1976 + clk_hifiberry_dachd_dt_parse(dev);
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);
1984 + init.name = "clk-hifiberry-dachd";
1985 + init.ops = &clk_hifiberry_dachd_rate_ops;
1987 + init.parent_names = NULL;
1988 + init.num_parents = 0;
1990 + hdclk->hw.init = &init;
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);
1998 + ret = of_clk_add_provider(dev_node, of_clk_src_simple_get, hdclk->clk);
2000 + dev_err(dev, "Cannot of_clk_add_provider");
2004 + ret = clk_set_rate(hdclk->hw.clk, DEFAULT_RATE);
2006 + dev_err(dev, "Cannot set rate : %d\n", ret);
2013 +static void clk_hifiberry_dachd_i2c_remove(struct i2c_client *i2c)
2015 + clk_hifiberry_dachd_remove(&i2c->dev);
2018 +static const struct i2c_device_id clk_hifiberry_dachd_i2c_id[] = {
2022 +MODULE_DEVICE_TABLE(i2c, clk_hifiberry_dachd_i2c_id);
2024 +static const struct of_device_id clk_hifiberry_dachd_of_match[] = {
2025 + { .compatible = "hifiberry,dachd-clk", },
2028 +MODULE_DEVICE_TABLE(of, clk_hifiberry_dachd_of_match);
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,
2035 + .name = "dachd-clk",
2036 + .of_match_table = of_match_ptr(clk_hifiberry_dachd_of_match),
2040 +module_i2c_driver(clk_hifiberry_dachd_i2c_driver);
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");
2048 +++ b/drivers/clk/clk-hifiberry-dacpro.c
2051 + * Clock Driver for HiFiBerry DAC Pro
2053 + * Author: Stuart MacLean
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.
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.
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>
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
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
2084 +struct clk_hifiberry_hw {
2089 +#define to_hifiberry_clk(_hw) container_of(_hw, struct clk_hifiberry_hw, hw)
2091 +static const struct of_device_id clk_hifiberry_dacpro_dt_ids[] = {
2092 + { .compatible = "hifiberry,dacpro-clk",},
2095 +MODULE_DEVICE_TABLE(of, clk_hifiberry_dacpro_dt_ids);
2097 +static unsigned long clk_hifiberry_dacpro_recalc_rate(struct clk_hw *hw,
2098 + unsigned long parent_rate)
2100 + return (to_hifiberry_clk(hw)->mode == 0) ? CLK_44EN_RATE :
2104 +static long clk_hifiberry_dacpro_round_rate(struct clk_hw *hw,
2105 + unsigned long rate, unsigned long *parent_rate)
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;
2114 + long diff44Rate = (long)(rate - CLK_44EN_RATE);
2115 + long diff48Rate = (long)(CLK_48EN_RATE - rate);
2117 + if (diff44Rate < diff48Rate)
2118 + actual_rate = (long)CLK_44EN_RATE;
2120 + actual_rate = (long)CLK_48EN_RATE;
2122 + return actual_rate;
2126 +static int clk_hifiberry_dacpro_set_rate(struct clk_hw *hw,
2127 + unsigned long rate, unsigned long parent_rate)
2129 + unsigned long actual_rate;
2130 + struct clk_hifiberry_hw *clk = to_hifiberry_clk(hw);
2132 + actual_rate = (unsigned long)clk_hifiberry_dacpro_round_rate(hw, rate,
2134 + clk->mode = (actual_rate == CLK_44EN_RATE) ? 0 : 1;
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,
2145 +static int clk_hifiberry_dacpro_probe(struct platform_device *pdev)
2148 + struct clk_hifiberry_hw *proclk;
2150 + struct device *dev;
2151 + struct clk_init_data init;
2155 + proclk = kzalloc(sizeof(struct clk_hifiberry_hw), GFP_KERNEL);
2159 + init.name = "clk-hifiberry-dacpro";
2160 + init.ops = &clk_hifiberry_dacpro_rate_ops;
2162 + init.parent_names = NULL;
2163 + init.num_parents = 0;
2166 + proclk->hw.init = &init;
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,
2173 + dev_err(dev, "Fail to register clock driver\n");
2175 + ret = PTR_ERR(clk);
2180 +static int clk_hifiberry_dacpro_remove(struct platform_device *pdev)
2182 + of_clk_del_provider(pdev->dev.of_node);
2186 +static struct platform_driver clk_hifiberry_dacpro_driver = {
2187 + .probe = clk_hifiberry_dacpro_probe,
2188 + .remove = clk_hifiberry_dacpro_remove,
2190 + .name = "clk-hifiberry-dacpro",
2191 + .of_match_table = clk_hifiberry_dacpro_dt_ids,
2195 +static int __init clk_hifiberry_dacpro_init(void)
2197 + return platform_driver_register(&clk_hifiberry_dacpro_driver);
2199 +core_initcall(clk_hifiberry_dacpro_init);
2201 +static void __exit clk_hifiberry_dacpro_exit(void)
2203 + platform_driver_unregister(&clk_hifiberry_dacpro_driver);
2205 +module_exit(clk_hifiberry_dacpro_exit);
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)
2215 If you don't know what to do here, say N
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
2221 + Say Y or M if you want to add support for the ChipDip DAC soundcard
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
2229 + Say Y or M if you want to add support for voiceHAT soundcard.
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
2237 + Say Y or M if you want to add support for HifiBerry DAC.
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
2246 + Say Y or M if you want to add support for HifiBerry DAC+.
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
2254 + Say Y or M if you want to add support for HifiBerry DAC+ HD.
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
2263 + Say Y or M if you want to add support for HifiBerry DAC+ADC.
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
2273 + Say Y or M if you want to add support for HifiBerry DAC+ADC PRO.
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
2280 + Say Y or M if you want to add support for HifiBerry DSP-DAC.
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
2287 + Say Y or M if you want to add support for HifiBerry Digi S/PDIF output board.
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
2295 + Say Y or M if you want to add support for the HifiBerry Amp amplifier board.
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
2303 + Say Y or M if you want to add support for the PiFi40 amp board
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
2311 + Say Y or M if you want to add support for the Wolfson and
2312 + Cirrus Logic audio cards.
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
2320 + Say Y or M if you want to add support for RPi-DAC.
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
2327 + Say Y or M if you want to add support for Audio Codec Board PROTO (WM8731).
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
2335 + Say Y or M if you want to add support for simultaneous
2336 + JustBoom Digi and JustBoom DAC.
2338 + This is not the right choice if you only have one but both of
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
2346 + Say Y or M if you want to add support for JustBoom DAC.
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
2354 + Say Y or M if you want to add support for JustBoom Digi.
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
2361 + Say Y or M if you want to add support for IQaudIO-CODEC.
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
2368 + Say Y or M if you want to add support for IQaudIO-DAC.
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
2376 + Say Y or M if you want to add support for IQAudIO Digital IO board.
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
2383 + Say Y or M if you want to add support for Audiophonics I-SABRE Q2M DAC
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
2391 + Say Y or M if you want to add support for ADAU1977 ADC.
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
2398 + Say Y or M if you want to add support for audioinjector.net Pi Hat
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
2405 + Say Y or M if you want to add support for audioinjector.net octo add on
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
2412 + Say Y or M if you want to add support for audioinjector.net isolated soundcard
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
2419 + Say Y or M if you want to add support for tlv320aic32x4 add-on
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
2427 + Say Y or M if you want to add support for Red Rocks Audio DigiDAC1 board.
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
2434 + Say Y or M if you want to add support for Dion Audio LOCO.
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
2441 + Say Y or M if you want to add support for Dion Audio LOCO-V2.
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
2448 + Say Y or M if you want to add support for Allo Piano DAC.
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
2455 + Say Y or M if you want to add support for Allo Piano DAC Plus.
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
2462 + Say Y or M if you want to add support for Allo Boss DAC.
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
2469 + select SND_AUDIO_GRAPH_CARD
2471 + Say Y or M if you want to add support for Allo Boss2 DAC.
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
2479 + Say Y or M if you want to add support for Allo DigiOne.
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
2486 + select SND_AUDIO_GRAPH_CARD
2488 + Say Y or M if you want to add support for Allo Katana DAC.
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
2495 + Say Y or M if you want to add support for Fe-Pi-Audio.
2498 + tristate "Support for Blokas Labs pisound"
2499 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2500 + select SND_RAWMIDI
2502 + Say Y or M if you want to add support for Blokas Labs pisound.
2504 +config SND_RPI_SIMPLE_SOUNDCARD
2505 + tristate "Support for Raspberry Pi simple soundcards"
2507 + Say Y or M if you want to add support Raspbery Pi simple soundcards
2509 +config SND_RPI_WM8804_SOUNDCARD
2510 + tristate "Support for Raspberry Pi generic WM8804 soundcards"
2512 + Say Y or M if you want to add support for the Raspberry Pi
2513 + generic driver for WM8804 based soundcards.
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
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
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
2531 +# Google voiceHAT custom codec support
2532 +snd-soc-googlevoicehat-codec-objs := googlevoicehat-codec.o
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
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
2600 +++ b/sound/soc/bcm/allo-boss-dac.c
2603 + * ALSA ASoC Machine Driver for Allo Boss DAC
2605 + * Author: Baswaraj K <jaikumar@cem-solutions.net>
2607 + * based on code by Daniel Matuschek,
2608 + * Stuart MacLean <stuart@hifiberry.com>
2609 + * based on code by Florian Meier <florian.meier@koalo.de>
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.
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.
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>
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"
2633 +#define ALLO_BOSS_NOCLOCK 0
2634 +#define ALLO_BOSS_CLK44EN 1
2635 +#define ALLO_BOSS_CLK48EN 2
2637 +struct pcm512x_priv {
2638 + struct regmap *regmap;
2642 +static struct gpio_desc *mute_gpio;
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
2650 +static bool snd_soc_allo_boss_master;
2651 +static bool digital_gain_0db_limit = true;
2653 +static void snd_allo_boss_select_clk(struct snd_soc_component *component,
2657 + case ALLO_BOSS_NOCLOCK:
2658 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x24, 0x00);
2660 + case ALLO_BOSS_CLK44EN:
2661 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x24, 0x20);
2663 + case ALLO_BOSS_CLK48EN:
2664 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x24, 0x04);
2669 +static void snd_allo_boss_clk_gpio(struct snd_soc_component *component)
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);
2676 +static bool snd_allo_boss_is_sclk(struct snd_soc_component *component)
2680 + sck = snd_soc_component_read(component, PCM512x_RATE_DET_4);
2681 + return (!(sck & 0x40));
2684 +static bool snd_allo_boss_is_sclk_sleep(
2685 + struct snd_soc_component *component)
2688 + return snd_allo_boss_is_sclk(component);
2691 +static bool snd_allo_boss_is_master_card(struct snd_soc_component *component)
2693 + bool isClk44EN, isClk48En, isNoClk;
2695 + snd_allo_boss_clk_gpio(component);
2697 + snd_allo_boss_select_clk(component, ALLO_BOSS_CLK44EN);
2698 + isClk44EN = snd_allo_boss_is_sclk_sleep(component);
2700 + snd_allo_boss_select_clk(component, ALLO_BOSS_NOCLOCK);
2701 + isNoClk = snd_allo_boss_is_sclk_sleep(component);
2703 + snd_allo_boss_select_clk(component, ALLO_BOSS_CLK48EN);
2704 + isClk48En = snd_allo_boss_is_sclk_sleep(component);
2706 + return (isClk44EN && isClk48En && !isNoClk);
2709 +static int snd_allo_boss_clk_for_rate(int sample_rate)
2713 + switch (sample_rate) {
2720 + type = ALLO_BOSS_CLK44EN;
2723 + type = ALLO_BOSS_CLK48EN;
2729 +static void snd_allo_boss_set_sclk(struct snd_soc_component *component,
2732 + struct pcm512x_priv *pcm512x = snd_soc_component_get_drvdata(component);
2734 + if (!IS_ERR(pcm512x->sclk)) {
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);
2744 +static int snd_allo_boss_init(struct snd_soc_pcm_runtime *rtd)
2746 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
2747 + struct pcm512x_priv *priv = snd_soc_component_get_drvdata(component);
2750 + snd_soc_allo_boss_master = false;
2752 + snd_soc_allo_boss_master =
2753 + snd_allo_boss_is_master_card(component);
2755 + if (snd_soc_allo_boss_master) {
2756 + struct snd_soc_dai_link *dai = rtd->dai_link;
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;
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);
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.
2772 + if (!IS_ERR(priv->sclk))
2773 + clk_set_rate(priv->sclk, CLK_48EN_RATE);
2775 + priv->sclk = ERR_PTR(-ENOENT);
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);
2782 + if (digital_gain_0db_limit) {
2784 + struct snd_soc_card *card = rtd->card;
2786 + ret = snd_soc_limit_volume(card, "Digital Playback Volume",
2789 + dev_warn(card->dev, "Failed to set volume limit: %d\n",
2796 +static int snd_allo_boss_update_rate_den(
2797 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
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;
2806 + rats_no_pll = devm_kzalloc(rtd->dev, sizeof(*rats_no_pll), GFP_KERNEL);
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;
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;
2822 + devm_kfree(rtd->dev, rats_no_pll);
2826 +static void snd_allo_boss_gpio_mute(struct snd_soc_card *card)
2829 + gpiod_set_value_cansleep(mute_gpio, 1);
2832 +static void snd_allo_boss_gpio_unmute(struct snd_soc_card *card)
2835 + gpiod_set_value_cansleep(mute_gpio, 0);
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)
2841 + struct snd_soc_pcm_runtime *rtd;
2842 + struct snd_soc_dai *codec_dai;
2844 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
2845 + codec_dai = asoc_rtd_to_codec(rtd, 0);
2847 + if (dapm->dev != codec_dai->dev)
2851 + case SND_SOC_BIAS_PREPARE:
2852 + if (dapm->bias_level != SND_SOC_BIAS_STANDBY)
2855 + snd_allo_boss_gpio_unmute(card);
2858 + case SND_SOC_BIAS_STANDBY:
2859 + if (dapm->bias_level != SND_SOC_BIAS_PREPARE)
2862 + snd_allo_boss_gpio_mute(card);
2872 +static int snd_allo_boss_hw_params(
2873 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
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));
2880 + if (snd_soc_allo_boss_master) {
2881 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
2883 + snd_allo_boss_set_sclk(component,
2884 + params_rate(params));
2886 + ret = snd_allo_boss_update_rate_den(
2887 + substream, params);
2892 + ret = snd_soc_dai_set_bclk_ratio(asoc_rtd_to_cpu(rtd, 0), channels * width);
2895 + ret = snd_soc_dai_set_bclk_ratio(asoc_rtd_to_codec(rtd, 0), channels * width);
2899 +static int snd_allo_boss_startup(
2900 + struct snd_pcm_substream *substream)
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;
2906 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x08, 0x08);
2907 + snd_allo_boss_gpio_mute(card);
2909 + if (snd_soc_allo_boss_master) {
2910 + struct pcm512x_priv *priv = snd_soc_component_get_drvdata(component);
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.
2917 + if (!IS_ERR(priv->sclk))
2918 + clk_set_rate(priv->sclk, CLK_48EN_RATE);
2924 +static void snd_allo_boss_shutdown(
2925 + struct snd_pcm_substream *substream)
2927 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
2928 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
2930 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x08, 0x00);
2933 +static int snd_allo_boss_prepare(
2934 + struct snd_pcm_substream *substream)
2936 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
2937 + struct snd_soc_card *card = rtd->card;
2939 + snd_allo_boss_gpio_unmute(card);
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,
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")));
2955 +static struct snd_soc_dai_link snd_allo_boss_dai[] = {
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),
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),
2976 +static int snd_allo_boss_probe(struct platform_device *pdev)
2980 + snd_allo_boss.dev = &pdev->dev;
2982 + if (pdev->dev.of_node) {
2983 + struct device_node *i2s_node;
2984 + struct snd_soc_dai_link *dai;
2986 + dai = &snd_allo_boss_dai[0];
2987 + i2s_node = of_parse_phandle(pdev->dev.of_node,
2988 + "i2s-controller", 0);
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;
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,
3002 + mute_gpio = devm_gpiod_get_optional(&pdev->dev, "mute",
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);
3012 + snd_allo_boss.set_bias_level =
3013 + snd_allo_boss_set_bias_level;
3015 + ret = snd_soc_register_card(&snd_allo_boss);
3017 + dev_err(&pdev->dev,
3018 + "snd_soc_register_card() failed: %d\n", ret);
3023 + snd_allo_boss_gpio_mute(&snd_allo_boss);
3031 +static int snd_allo_boss_remove(struct platform_device *pdev)
3033 + snd_allo_boss_gpio_mute(&snd_allo_boss);
3034 + snd_soc_unregister_card(&snd_allo_boss);
3038 +static const struct of_device_id snd_allo_boss_of_match[] = {
3039 + { .compatible = "allo,boss-dac", },
3040 + { /* sentinel */ },
3042 +MODULE_DEVICE_TABLE(of, snd_allo_boss_of_match);
3044 +static struct platform_driver snd_allo_boss_driver = {
3046 + .name = "snd-allo-boss-dac",
3047 + .owner = THIS_MODULE,
3048 + .of_match_table = snd_allo_boss_of_match,
3050 + .probe = snd_allo_boss_probe,
3051 + .remove = snd_allo_boss_remove,
3054 +module_platform_driver(snd_allo_boss_driver);
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");
3060 +++ b/sound/soc/bcm/allo-boss2-dac.c
3063 + * Driver for the ALLO KATANA CODEC
3065 + * Author: Jaikumar <sudeepkumar@cem-solutions.net>
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.
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.
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>
3107 +#include "../codecs/cs43130.h"
3109 +#include <linux/clk.h>
3110 +#include <linux/gcd.h>
3113 +#define CS43130_DSD_EN_MASK 0x10
3114 +#define CS43130_PDN_DONE_INT_MASK 0x00
3116 +static struct gpio_desc *snd_allo_clk44gpio;
3117 +static struct gpio_desc *snd_allo_clk48gpio;
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 */
3126 + /* shared by both DAIs */
3127 + struct mutex clk_mutex;
3130 + struct completion xtal_rdy;
3131 + struct completion pll_rdy;
3132 + unsigned int mclk;
3133 + unsigned int mclk_int;
3136 + /* DAI specific */
3137 + struct cs43130_dai dais[CS43130_DAI_ID_MAX];
3139 + /* HP load specific */
3143 + struct completion hpload_evt;
3144 + unsigned int hpload_stat;
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;
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},
3224 +static bool cs43130_volatile_register(struct device *dev, unsigned int 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:
3236 +static const char * const pcm_spd_texts[] = {
3241 +static SOC_ENUM_SINGLE_DECL(pcm_spd_enum, CS43130_PCM_FILT_OPT, 7,
3244 +static const SNDRV_CTL_TLVD_DECLARE_DB_MINMAX(master_tlv, -12750, 0);
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,
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,
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),
3263 +static bool cs43130_readable_register(struct device *dev, unsigned int 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:
3308 +static bool cs43130_precious_register(struct device *dev, unsigned int reg)
3311 + case CS43130_INT_STATUS_1 ... CS43130_INT_STATUS_5:
3317 +static int cs43130_pcm_pdn(struct snd_soc_component *component)
3319 + struct cs43130_priv *cs43130 =
3320 + snd_soc_component_get_drvdata(component);
3322 + unsigned int reg, pdn_int;
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, ®);
3331 + pdn_int = reg & 0xFE;
3332 + regmap_update_bits(cs43130->regmap, CS43130_PWDN_CTL,
3333 + CS43130_PDN_ASP_MASK, 1 << CS43130_PDN_ASP_SHIFT);
3337 +static int cs43130_pwr_up_asp_dac(struct snd_soc_component *component)
3339 + struct cs43130_priv *cs43130 =
3340 + snd_soc_component_get_drvdata(component);
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);
3355 +static int cs43130_change_clksrc(struct snd_soc_component *component,
3356 + enum cs43130_mclk_src_sel src)
3359 + struct cs43130_priv *cs43130 =
3360 + snd_soc_component_get_drvdata(component);
3361 + int mclk_int_decoded;
3363 + if (src == cs43130->mclk_int_src) {
3364 + /* clk source has not changed */
3367 + switch (cs43130->mclk_int) {
3368 + case CS43130_MCLK_22M:
3369 + mclk_int_decoded = CS43130_MCLK_22P5;
3371 + case CS43130_MCLK_24M:
3372 + mclk_int_decoded = CS43130_MCLK_24P5;
3375 + dev_err(component->dev, "Invalid MCLK INT freq: %u\n",
3376 + cs43130->mclk_int);
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);
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);
3400 + dev_err(component->dev, "Timeout waiting for XTAL_READY interrupt\n");
3401 + return -ETIMEDOUT;
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);
3415 + case CS43130_MCLK_SRC_RCO:
3416 + cs43130->mclk_int_src = CS43130_MCLK_SRC_RCO;
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);
3433 + dev_err(component->dev, "Invalid MCLK source value\n");
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},
3446 +static const struct cs43130_bitwidth_map *cs43130_get_bitwidth_table(
3447 + unsigned int bitwidth)
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];
3458 +static int cs43130_set_bitwidth(int dai_id, unsigned int bitwidth_dai,
3459 + struct regmap *regmap)
3461 + const struct cs43130_bitwidth_map *bw_map;
3463 + bw_map = cs43130_get_bitwidth_table(bitwidth_dai);
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);
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);
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},
3504 +static const struct cs43130_rate_map *cs43130_get_rate_table(int fs)
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];
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)
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];
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)
3544 + const struct cs43130_clk_gen *clk_gen;
3546 + switch (cs43130->dais[dai_id].dai_format) {
3547 + case SND_SOC_DAIFMT_I2S:
3548 + hi_size = bitwidth_sclk;
3552 + case SND_SOC_DAIFMT_LEFT_J:
3553 + hi_size = bitwidth_sclk;
3557 + case SND_SOC_DAIFMT_DSP_A:
3562 + case SND_SOC_DAIFMT_DSP_B:
3570 + switch (cs43130->dais[dai_id].dai_mode) {
3571 + case SND_SOC_DAIFMT_CBS_CFS:
3574 + case SND_SOC_DAIFMT_CBM_CFM:
3581 + frm_size = bitwidth_sclk * params_channels(params);
3585 + loc_ch2 = bitwidth_sclk * (params_channels(params) - 1);
3587 + frm_data = frm_delay & CS43130_SP_FSD_MASK;
3588 + frm_data |= (frm_phase << CS43130_SP_STP_SHIFT) & CS43130_SP_STP_MASK;
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;
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);
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);
3648 + switch (frm_size) {
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));
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));
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));
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));
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);
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);
3714 +static int cs43130_hw_params(struct snd_pcm_substream *substream,
3715 + struct snd_pcm_hw_params *params,
3716 + struct snd_soc_dai *dai)
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;
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);
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);
3747 + if (cs43130->pll_bypass)
3748 + cs43130_change_clksrc(component, CS43130_MCLK_SRC_EXT);
3750 + cs43130_change_clksrc(component, CS43130_MCLK_SRC_PLL);
3753 + cs43130->clk_req++;
3754 + mutex_unlock(&cs43130->clk_mutex);
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);
3764 + switch (params_rate(params)) {
3772 + dev_err(component->dev, "Rate(%u) not supported\n",
3773 + params_rate(params));
3777 + regmap_update_bits(cs43130->regmap, CS43130_DSD_PATH_CTL_2,
3778 + CS43130_DSD_SPEED_MASK,
3779 + dsd_speed << CS43130_DSD_SPEED_SHIFT);
3781 + case CS43130_ASP_PCM_DAI:
3782 + rate_map = cs43130_get_rate_table(params_rate(params));
3786 + regmap_write(cs43130->regmap, CS43130_SP_SRATE, rate_map->val);
3787 + if ((dop_rate == 176400) && (bitwidth_dai == 24)) {
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);
3805 + dev_err(component->dev, "Invalid DAI (%d)\n", dai->id);
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);
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);
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);
3831 + /* at this point, SCLK must be set */
3832 + dev_err(component->dev, "SCLK freq is not set\n");
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");
3842 + dev_dbg(component->dev,
3843 + "sclk = %u, fs = %d, bitwidth_dai = %u\n",
3844 + sclk, params_rate(params), bitwidth_dai);
3846 + dev_dbg(component->dev,
3847 + "bitwidth_sclk = %u, num_ch = %u\n",
3848 + bitwidth_sclk, params_channels(params));
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);
3856 +static int cs43130_hw_free(struct snd_pcm_substream *substream,
3857 + struct snd_soc_dai *dai)
3859 + struct snd_soc_component *component = dai->component;
3860 + struct cs43130_priv *cs43130 =
3861 + snd_soc_component_get_drvdata(component);
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);
3870 + mutex_unlock(&cs43130->clk_mutex);
3875 +static const unsigned int cs43130_asp_src_rates[] = {
3876 + 32000, 44100, 48000, 88200, 96000, 176400, 192000
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,
3884 +static int cs43130_pcm_startup(struct snd_pcm_substream *substream,
3885 + struct snd_soc_dai *dai)
3887 + return snd_pcm_hw_constraint_list(substream->runtime, 0,
3888 + SNDRV_PCM_HW_PARAM_RATE,
3889 + &cs43130_asp_constraints);
3892 +static int cs43130_pcm_set_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
3894 + struct snd_soc_component *component = codec_dai->component;
3895 + struct cs43130_priv *cs43130 =
3896 + snd_soc_component_get_drvdata(component);
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;
3902 + case SND_SOC_DAIFMT_CBM_CFM:
3903 + cs43130->dais[codec_dai->id].dai_mode = SND_SOC_DAIFMT_CBM_CFM;
3906 + dev_err(component->dev, "unsupported mode\n");
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;
3914 + case SND_SOC_DAIFMT_LEFT_J:
3915 + cs43130->dais[codec_dai->id].dai_format = SND_SOC_DAIFMT_LEFT_J;
3918 + dev_err(component->dev,
3919 + "unsupported audio format\n");
3923 + dev_dbg(component->dev, "dai_id = %d, dai_mode = %u, dai_format = %u\n",
3925 + cs43130->dais[codec_dai->id].dai_mode,
3926 + cs43130->dais[codec_dai->id].dai_format);
3931 +static int cs43130_set_sysclk(struct snd_soc_dai *codec_dai,
3932 + int clk_id, unsigned int freq, int dir)
3934 + struct snd_soc_component *component = codec_dai->component;
3935 + struct cs43130_priv *cs43130 =
3936 + snd_soc_component_get_drvdata(component);
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);
3945 +static int cs43130_component_set_sysclk(struct snd_soc_component *component,
3946 + int clk_id, int source,
3947 + unsigned int freq, int dir)
3949 + struct cs43130_priv *cs43130 =
3950 + snd_soc_component_get_drvdata(component);
3952 + dev_dbg(component->dev, "clk_id = %d, source = %d, freq = %d, dir = %d\n",
3953 + clk_id, source, freq, dir);
3956 + case CS43130_MCLK_22M:
3957 + case CS43130_MCLK_24M:
3958 + cs43130->mclk = freq;
3961 + dev_err(component->dev, "Invalid MCLK INT freq: %u\n", freq);
3965 + if (source == CS43130_MCLK_SRC_EXT) {
3966 + cs43130->pll_bypass = true;
3968 + dev_err(component->dev, "Invalid MCLK source\n");
3974 +static u16 const cs43130_ac_freq[CS43130_AC_FREQ] = {
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,
3994 +static struct snd_soc_dai_driver cs43130_codec_dai = {
3995 + .name = "allo-cs43130",
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
4008 + .ops = &cs43130_dai_ops,
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,
4021 +static const struct regmap_config cs43130_regmap = {
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,
4038 +static u16 const cs43130_dc_threshold[CS43130_DC_THRESHOLD] = {
4043 +static int cs43130_handle_device_data(struct i2c_client *i2c_client,
4044 + struct cs43130_priv *cs43130)
4046 + struct device_node *np = i2c_client->dev.of_node;
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;
4058 + cs43130->xtal_ibias = CS43130_XTAL_IBIAS_7_5UA;
4061 + cs43130->xtal_ibias = CS43130_XTAL_IBIAS_12_5UA;
4064 + cs43130->xtal_ibias = CS43130_XTAL_IBIAS_15UA;
4067 + dev_err(&i2c_client->dev,
4068 + "Invalid cirrus,xtal-ibias value: %d\n", val);
4072 + cs43130->dc_meas = of_property_read_bool(np, "cirrus,dc-measure");
4073 + cs43130->ac_meas = of_property_read_bool(np, "cirrus,ac-measure");
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];
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];
4092 +static int allo_cs43130_component_probe(struct i2c_client *i2c,
4093 + const struct i2c_device_id *id)
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;
4103 + regmap = devm_regmap_init_i2c(i2c, &config);
4104 + if (IS_ERR(regmap))
4105 + return PTR_ERR(regmap);
4107 + cs43130 = devm_kzalloc(dev, sizeof(struct cs43130_priv),
4112 + dev_set_drvdata(dev, cs43130);
4113 + cs43130->regmap = regmap;
4115 + if (i2c->dev.of_node) {
4116 + ret = cs43130_handle_device_data(i2c, cs43130);
4120 + usleep_range(2000, 2050);
4122 + ret = regmap_read(cs43130->regmap, CS43130_DEVID_AB, ®);
4123 + devid = (reg & 0xFF) << 12;
4124 + ret = regmap_read(cs43130->regmap, CS43130_DEVID_CD, ®);
4125 + devid |= (reg & 0xFF) << 4;
4126 + ret = regmap_read(cs43130->regmap, CS43130_DEVID_E, ®);
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);
4133 + cs43130->mclk_int_src = CS43130_MCLK_SRC_RCO;
4136 + ret = snd_soc_register_component(dev, &cs43130_component_driver,
4137 + &cs43130_codec_dai, 1);
4139 + dev_err(dev, "failed to register codec: %d\n", ret);
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);
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");
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");
4161 +static void allo_cs43130_component_remove(struct i2c_client *i2c)
4163 + snd_soc_unregister_component(&i2c->dev);
4166 +static const struct i2c_device_id allo_cs43130_component_id[] = {
4167 + { "allo-cs43198", },
4170 +MODULE_DEVICE_TABLE(i2c, allo_cs43130_component_id);
4172 +static const struct of_device_id allo_cs43130_codec_of_match[] = {
4173 + { .compatible = "allo,allo-cs43198", },
4176 +MODULE_DEVICE_TABLE(of, allo_cs43130_codec_of_match);
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,
4183 + .name = "allo-cs43198",
4184 + .of_match_table = allo_cs43130_codec_of_match,
4188 +module_i2c_driver(allo_cs43130_component_driver);
4190 +MODULE_DESCRIPTION("ASoC Allo Boss2 Codec Driver");
4191 +MODULE_AUTHOR("Sudeepkumar <sudeepkumar@cem-solutions.net>");
4192 +MODULE_LICENSE("GPL v2");
4194 +++ b/sound/soc/bcm/allo-katana-codec.c
4197 + * Driver for the ALLO KATANA CODEC
4199 + * Author: Jaikumar <jaikumar@cem-solutions.net>
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.
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.
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>
4227 +#define KATANA_CODEC_CHIP_ID 0x30
4228 +#define KATANA_CODEC_VIRT_BASE 0x100
4229 +#define KATANA_CODEC_PAGE 0
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)
4243 +#define KATANA_CODEC_MAX_REGISTER (KATANA_CODEC_VIRT_BASE + 10)
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
4264 +struct katana_codec_priv {
4265 + struct regmap *regmap;
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 },
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",
4290 +static const unsigned int katana_codec_dsp_program_values[] = {
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);
4305 +static const char * const katana_codec_deemphasis_texts[] = {
4312 +static const unsigned int katana_codec_deemphasis_values[] = {
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);
4324 +static const SNDRV_CTL_TLVD_DECLARE_DB_MINMAX(master_tlv, -12750, 0);
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)
4335 +static bool katana_codec_readable_register(struct device *dev,
4339 + case KATANA_CODEC_CHIP_ID_REG:
4342 + return reg < 0xff;
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)
4350 + struct snd_soc_component *component = dai->component;
4351 + struct katana_codec_priv *katana_codec =
4352 + snd_soc_component_get_drvdata(component);
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));
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;
4366 + fmt = KATANA_CODEC_CHAN_MONO;
4368 + switch (params_width(params)) {
4370 + fmt |= KATANA_CODEC_ALEN_16;
4373 + fmt |= KATANA_CODEC_ALEN_24;
4376 + fmt |= KATANA_CODEC_ALEN_32;
4379 + dev_err(component->card->dev, "Bad frame size: %d\n",
4380 + params_width(params));
4384 + switch (params_rate(params)) {
4386 + fmt |= KATANA_CODEC_RATE_44100;
4389 + fmt |= KATANA_CODEC_RATE_48000;
4392 + fmt |= KATANA_CODEC_RATE_88200;
4395 + fmt |= KATANA_CODEC_RATE_96000;
4398 + fmt |= KATANA_CODEC_RATE_176400;
4401 + fmt |= KATANA_CODEC_RATE_192000;
4404 + fmt |= KATANA_CODEC_RATE_352800;
4407 + fmt |= KATANA_CODEC_RATE_384000;
4410 + dev_err(component->card->dev, "Bad sample rate: %d\n",
4411 + params_rate(params));
4415 + ret = regmap_write(katana_codec->regmap, KATANA_CODEC_FORMAT,
4418 + dev_err(component->card->dev, "Failed to set format: %d\n", ret);
4423 + case SND_SOC_DAIFMT_CBS_CFS:
4433 +static int katana_codec_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
4435 + struct snd_soc_component *component = dai->component;
4436 + struct katana_codec_priv *katana_codec =
4437 + snd_soc_component_get_drvdata(component);
4439 + katana_codec->fmt = fmt;
4444 +int katana_codec_dai_mute_stream(struct snd_soc_dai *dai, int mute,
4447 + struct snd_soc_component *component = dai->component;
4448 + struct katana_codec_priv *katana_codec =
4449 + snd_soc_component_get_drvdata(component);
4452 + ret = regmap_write(katana_codec->regmap, KATANA_CODEC_MUTE_STREAM,
4455 + dev_err(component->card->dev, "Failed to set mute: %d\n", ret);
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,
4467 +static struct snd_soc_dai_driver katana_codec_dai = {
4468 + .name = "allo-katana-codec",
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
4479 + .ops = &katana_codec_dai_ops,
4482 +static struct snd_soc_component_driver katana_codec_component_driver = {
4483 + .idle_bias_on = true,
4485 + .controls = katana_codec_controls,
4486 + .num_controls = ARRAY_SIZE(katana_codec_controls),
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,
4497 +const struct regmap_config katana_codec_regmap = {
4501 + .ranges = &katana_codec_range,
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,
4511 +static int allo_katana_component_probe(struct i2c_client *i2c,
4512 + const struct i2c_device_id *id)
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;
4521 + regmap = devm_regmap_init_i2c(i2c, &config);
4522 + if (IS_ERR(regmap))
4523 + return PTR_ERR(regmap);
4525 + katana_codec = devm_kzalloc(dev, sizeof(struct katana_codec_priv),
4527 + if (!katana_codec)
4530 + dev_set_drvdata(dev, katana_codec);
4531 + katana_codec->regmap = regmap;
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);
4538 + regmap_update_bits(regmap, KATANA_CODEC_RESET, 0x01, 0x01);
4541 + ret = snd_soc_register_component(dev, &katana_codec_component_driver,
4542 + &katana_codec_dai, 1);
4544 + dev_err(dev, "failed to register codec: %d\n", ret);
4551 +static void allo_katana_component_remove(struct i2c_client *i2c)
4553 + snd_soc_unregister_component(&i2c->dev);
4556 +static const struct i2c_device_id allo_katana_component_id[] = {
4557 + { "allo-katana-codec", },
4560 +MODULE_DEVICE_TABLE(i2c, allo_katana_component_id);
4562 +static const struct of_device_id allo_katana_codec_of_match[] = {
4563 + { .compatible = "allo,allo-katana-codec", },
4566 +MODULE_DEVICE_TABLE(of, allo_katana_codec_of_match);
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,
4573 + .name = "allo-katana-codec",
4574 + .of_match_table = allo_katana_codec_of_match,
4578 +module_i2c_driver(allo_katana_component_driver);
4580 +MODULE_DESCRIPTION("ASoC Allo Katana Codec Driver");
4581 +MODULE_AUTHOR("Jaikumar <jaikumar@cem-solutions.net>");
4582 +MODULE_LICENSE("GPL v2");
4584 +++ b/sound/soc/bcm/allo-piano-dac-plus.c
4587 + * ALSA ASoC Machine Driver for Allo Piano DAC Plus Subwoofer
4589 + * Author: Baswaraj K <jaikumar@cem-solutions.net>
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>
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.
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.
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"
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
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;
4639 +static bool digital_gain_0db_limit = true;
4642 +static struct gpio_desc *mute_gpio[2];
4644 +static const char * const allo_piano_mode_texts[] = {
4651 +static SOC_ENUM_SINGLE_DECL(allo_piano_mode_enum,
4652 + 0, 0, allo_piano_mode_texts);
4654 +static const char * const allo_piano_dual_mode_texts[] = {
4660 +static SOC_ENUM_SINGLE_DECL(allo_piano_dual_mode_enum,
4661 + 0, 0, allo_piano_dual_mode_texts);
4663 +static const char * const allo_piano_dsp_low_pass_texts[] = {
4681 +static SOC_ENUM_SINGLE_DECL(allo_piano_enum,
4682 + 0, 0, allo_piano_dsp_low_pass_texts);
4684 +static int __snd_allo_piano_dsp_program(struct snd_soc_pcm_runtime *rtd,
4685 + unsigned int mode, unsigned int rate, unsigned int lowpass)
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;
4693 + if (rate <= 46000)
4695 + else if (rate <= 68000)
4697 + else if (rate <= 92000)
4699 + else if (rate <= 136000)
4701 + else if (rate <= 184000)
4707 + glb_ptr->set_lowpass = lowpass = 0;
4710 + glb_ptr->set_mode = mode = 0;
4713 + glb_ptr->dual_mode = 0;
4715 + /* same configuration loaded */
4716 + if ((rate == glb_ptr->set_rate) && (lowpass == glb_ptr->set_lowpass)
4717 + && (mode == glb_ptr->set_mode))
4721 + case 0: /* None */
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;
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);
4741 + for (dac = 0; dac < rtd->dai_link->num_codecs; dac++) {
4742 + struct dsp_code *dsp_code_read;
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);
4755 + dev_info(rtd->card->dev, "Dsp Firmware File Name: %s\n",
4758 + ret = request_firmware(&fw, firmware_name, rtd->card->dev);
4760 + dev_err(rtd->card->dev,
4761 + "Error: Allo Piano Firmware %s missing. %d\n",
4762 + firmware_name, ret);
4766 + while (i < (fw->size - 1)) {
4767 + dsp_code_read = (struct dsp_code *)&fw->data[i];
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);
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);
4783 + dev_err(rtd->card->dev,
4784 + "Failed to write Register: %d\n", ret);
4785 + release_firmware(fw);
4790 + release_firmware(fw);
4792 + glb_ptr->set_rate = rate;
4793 + glb_ptr->set_mode = mode;
4794 + glb_ptr->set_lowpass = lowpass;
4801 +static int snd_allo_piano_dsp_program(struct snd_soc_pcm_runtime *rtd,
4802 + unsigned int mode, unsigned int rate, unsigned int lowpass)
4804 + struct snd_soc_card *card = rtd->card;
4805 + struct glb_pool *glb_ptr = card->drvdata;
4808 + mutex_lock(&glb_ptr->lock);
4810 + ret = __snd_allo_piano_dsp_program(rtd, mode, rate, lowpass);
4812 + mutex_unlock(&glb_ptr->lock);
4817 +static int snd_allo_piano_dual_mode_get(struct snd_kcontrol *kcontrol,
4818 + struct snd_ctl_elem_value *ucontrol)
4820 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
4821 + struct glb_pool *glb_ptr = card->drvdata;
4823 + ucontrol->value.integer.value[0] = glb_ptr->dual_mode;
4828 +static int snd_allo_piano_dual_mode_put(struct snd_kcontrol *kcontrol,
4829 + struct snd_ctl_elem_value *ucontrol)
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;
4839 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
4841 + if (ucontrol->value.integer.value[0] > 0) {
4842 + glb_ptr->dual_mode = ucontrol->value.integer.value[0];
4843 + glb_ptr->set_mode = 0;
4845 + if (glb_ptr->set_mode <= 0) {
4846 + glb_ptr->dual_mode = 1;
4847 + glb_ptr->set_mode = 0;
4849 + glb_ptr->dual_mode = 0;
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);
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;
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;
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);
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;
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;
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);
4916 +static int snd_allo_piano_mode_get(struct snd_kcontrol *kcontrol,
4917 + struct snd_ctl_elem_value *ucontrol)
4919 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
4920 + struct glb_pool *glb_ptr = card->drvdata;
4922 + ucontrol->value.integer.value[0] = glb_ptr->set_mode;
4926 +static int snd_allo_piano_mode_put(struct snd_kcontrol *kcontrol,
4927 + struct snd_ctl_elem_value *ucontrol)
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;
4937 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
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);
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;
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;
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);
4968 + return(snd_allo_piano_dsp_program(rtd,
4969 + ucontrol->value.integer.value[0],
4970 + glb_ptr->set_rate, glb_ptr->set_lowpass));
4973 +static int snd_allo_piano_lowpass_get(struct snd_kcontrol *kcontrol,
4974 + struct snd_ctl_elem_value *ucontrol)
4976 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
4977 + struct glb_pool *glb_ptr = card->drvdata;
4979 + ucontrol->value.integer.value[0] = glb_ptr->set_lowpass;
4983 +static int snd_allo_piano_lowpass_put(struct snd_kcontrol *kcontrol,
4984 + struct snd_ctl_elem_value *ucontrol)
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;
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]));
4996 +static int pcm512x_get_reg_sub(struct snd_kcontrol *kcontrol,
4997 + struct snd_ctl_elem_value *ucontrol)
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]);
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);
5015 + left_val = right_val;
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;
5026 +static int pcm512x_set_reg_sub(struct snd_kcontrol *kcontrol,
5027 + struct snd_ctl_elem_value *ucontrol)
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);
5038 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
5040 + if (digital_gain_0db_limit) {
5041 + ret = snd_soc_limit_volume(card, "Subwoofer Playback Volume",
5044 + dev_warn(card->dev, "Failed to set volume limit: %d\n",
5048 + // When in Dual Mono, Sub vol control should not set anything.
5049 + if (glb_ptr->dual_mode != 1) { //Not in Dual Mono mode
5051 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component,
5052 + PCM512x_DIGITAL_VOLUME_2, (~left_val));
5056 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component,
5057 + PCM512x_DIGITAL_VOLUME_3, (~right_val));
5066 +static int pcm512x_get_reg_sub_switch(struct snd_kcontrol *kcontrol,
5067 + struct snd_ctl_elem_value *ucontrol)
5069 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
5070 + struct snd_soc_pcm_runtime *rtd;
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);
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;
5084 +static int pcm512x_set_reg_sub_switch(struct snd_kcontrol *kcontrol,
5085 + struct snd_ctl_elem_value *ucontrol)
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]);
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)));
5105 +static int pcm512x_get_reg_master(struct snd_kcontrol *kcontrol,
5106 + struct snd_ctl_elem_value *ucontrol)
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;
5115 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
5117 + left_val = snd_soc_component_read(asoc_rtd_to_codec(rtd, 0)->component,
5118 + PCM512x_DIGITAL_VOLUME_2);
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);
5124 + right_val = snd_soc_component_read(asoc_rtd_to_codec(rtd, 0)->component,
5125 + PCM512x_DIGITAL_VOLUME_3);
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;
5136 +static int pcm512x_set_reg_master(struct snd_kcontrol *kcontrol,
5137 + struct snd_ctl_elem_value *ucontrol)
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);
5148 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
5150 + if (digital_gain_0db_limit) {
5151 + ret = snd_soc_limit_volume(card, "Master Playback Volume",
5154 + dev_warn(card->dev, "Failed to set volume limit: %d\n",
5158 + if (glb_ptr->dual_mode == 1) { //in Dual Mono Mode
5160 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 0)->component,
5161 + PCM512x_DIGITAL_VOLUME_2, (~left_val));
5165 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component,
5166 + PCM512x_DIGITAL_VOLUME_3, (~right_val));
5172 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 0)->component,
5173 + PCM512x_DIGITAL_VOLUME_2, (~left_val));
5177 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 0)->component,
5178 + PCM512x_DIGITAL_VOLUME_3, (~right_val));
5186 +static int pcm512x_get_reg_master_switch(struct snd_kcontrol *kcontrol,
5187 + struct snd_ctl_elem_value *ucontrol)
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;
5194 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
5196 + val = snd_soc_component_read(asoc_rtd_to_codec(rtd, 0)->component, PCM512x_MUTE);
5198 + ucontrol->value.integer.value[0] =
5199 + (val & P_DAC_LEFT_MUTE) ? P_UNMUTE : P_MUTE;
5201 + if (glb_ptr->dual_mode == 1) {
5202 + val = snd_soc_component_read(asoc_rtd_to_codec(rtd, 1)->component, PCM512x_MUTE);
5204 + ucontrol->value.integer.value[1] =
5205 + (val & P_DAC_RIGHT_MUTE) ? P_UNMUTE : P_MUTE;
5210 +static int pcm512x_set_reg_master_switch(struct snd_kcontrol *kcontrol,
5211 + struct snd_ctl_elem_value *ucontrol)
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]);
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));
5226 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component, PCM512x_MUTE,
5227 + ~((right_val & 0x01)));
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)));
5238 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 0)->component, PCM512x_MUTE,
5239 + ~((left_val & 0x01)<<4 | (right_val & 0x01)));
5243 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component, PCM512x_MUTE,
5244 + ~((left_val & 0x01)<<4 | (right_val & 0x01)));
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);
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),
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),
5265 + SOC_ENUM_EXT("Lowpass Route", allo_piano_enum,
5266 + snd_allo_piano_lowpass_get,
5267 + snd_allo_piano_lowpass_put),
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,
5276 + SOC_DOUBLE_EXT("Subwoofer Playback Switch",
5278 + PCM512x_RQML_SHIFT,
5279 + PCM512x_RQMR_SHIFT, 1, 1,
5280 + pcm512x_get_reg_sub_switch,
5281 + pcm512x_set_reg_sub_switch),
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),
5290 + SOC_DOUBLE_EXT("Master Playback Switch",
5292 + PCM512x_RQML_SHIFT,
5293 + PCM512x_RQMR_SHIFT, 1, 1,
5294 + pcm512x_get_reg_master_switch,
5295 + pcm512x_set_reg_master_switch),
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"
5318 +static int snd_allo_piano_dac_init(struct snd_soc_pcm_runtime *rtd)
5320 + struct snd_soc_card *card = rtd->card;
5321 + struct glb_pool *glb_ptr;
5322 + struct snd_kcontrol *kctl;
5325 + glb_ptr = kzalloc(sizeof(struct glb_pool), GFP_KERNEL);
5329 + card->drvdata = glb_ptr;
5330 + glb_ptr->dual_mode = 2;
5331 + glb_ptr->set_mode = 0;
5333 + mutex_init(&glb_ptr->lock);
5335 + if (digital_gain_0db_limit) {
5338 + //Set volume limit on both dacs
5339 + for (i = 0; i < ARRAY_SIZE(codec_ctl_pfx); i++) {
5342 + sprintf(cname, "%s %s", codec_ctl_pfx[i], codec_ctl_name[0]);
5343 + ret = snd_soc_limit_volume(card, cname, 207);
5345 + dev_warn(card->dev, "Failed to set volume limit: %d\n",
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++) {
5355 + sprintf(cname, "%s %s", codec_ctl_pfx[i], codec_ctl_name[j]);
5356 + kctl = snd_soc_card_get_kcontrol(card, cname);
5358 + dev_err(rtd->card->dev, "Control %s not found\n",
5361 + kctl->vd[0].access =
5362 + SNDRV_CTL_ELEM_ACCESS_READWRITE;
5363 + snd_ctl_remove(card->snd_card, kctl);
5371 +static void snd_allo_piano_gpio_mute(struct snd_soc_card *card)
5374 + gpiod_set_value_cansleep(mute_gpio[0], P_MUTE);
5377 + gpiod_set_value_cansleep(mute_gpio[1], P_MUTE);
5380 +static void snd_allo_piano_gpio_unmute(struct snd_soc_card *card)
5383 + gpiod_set_value_cansleep(mute_gpio[0], P_UNMUTE);
5386 + gpiod_set_value_cansleep(mute_gpio[1], P_UNMUTE);
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)
5392 + struct snd_soc_pcm_runtime *rtd;
5393 + struct snd_soc_dai *codec_dai;
5395 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
5396 + codec_dai = asoc_rtd_to_codec(rtd, 0);
5398 + if (dapm->dev != codec_dai->dev)
5402 + case SND_SOC_BIAS_PREPARE:
5403 + if (dapm->bias_level != SND_SOC_BIAS_STANDBY)
5406 + snd_allo_piano_gpio_unmute(card);
5409 + case SND_SOC_BIAS_STANDBY:
5410 + if (dapm->bias_level != SND_SOC_BIAS_PREPARE)
5413 + snd_allo_piano_gpio_mute(card);
5423 +static int snd_allo_piano_dac_startup(
5424 + struct snd_pcm_substream *substream)
5426 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
5427 + struct snd_soc_card *card = rtd->card;
5429 + snd_allo_piano_gpio_mute(card);
5434 +static int snd_allo_piano_dac_hw_params(
5435 + struct snd_pcm_substream *substream,
5436 + struct snd_pcm_hw_params *params)
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;
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);
5450 + snd_soc_component_write(asoc_rtd_to_codec(rtd, dac)->component,
5452 + PCM512x_SREF_BCK);
5454 + dev_info(asoc_rtd_to_codec(rtd, dac)->component->dev,
5455 + "Setting BCLK as input clock & Enable PLL\n");
5457 + snd_soc_component_write(asoc_rtd_to_codec(rtd, dac)->component,
5461 + snd_soc_component_write(asoc_rtd_to_codec(rtd, dac)->component,
5463 + PCM512x_SREF_SCK);
5465 + dev_info(asoc_rtd_to_codec(rtd, dac)->component->dev,
5466 + "Setting SCLK as input clock & disabled PLL\n");
5470 + ret = snd_allo_piano_dsp_program(rtd, glb_ptr->set_mode, rate,
5471 + glb_ptr->set_lowpass);
5478 +static int snd_allo_piano_dac_prepare(
5479 + struct snd_pcm_substream *substream)
5481 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
5482 + struct snd_soc_card *card = rtd->card;
5484 + snd_allo_piano_gpio_unmute(card);
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,
5496 +static struct snd_soc_dai_link_component allo_piano_2_1_codecs[] = {
5498 + .dai_name = "pcm512x-hifi",
5501 + .dai_name = "pcm512x-hifi",
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()));
5511 +static struct snd_soc_dai_link snd_allo_piano_dac_dai[] = {
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),
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),
5534 +static int snd_allo_piano_dac_probe(struct platform_device *pdev)
5536 + struct snd_soc_card *card = &snd_allo_piano_dac;
5537 + int ret = 0, i = 0;
5539 + card->dev = &pdev->dev;
5540 + platform_set_drvdata(pdev, &snd_allo_piano_dac);
5542 + if (pdev->dev.of_node) {
5543 + struct device_node *i2s_node;
5544 + struct snd_soc_dai_link *dai;
5546 + dai = &snd_allo_piano_dac_dai[0];
5547 + i2s_node = of_parse_phandle(pdev->dev.of_node,
5548 + "i2s-controller", 0);
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;
5557 + digital_gain_0db_limit =
5558 + !of_property_read_bool(pdev->dev.of_node,
5559 + "allo,24db_digital_gain");
5561 + glb_mclk = of_property_read_bool(pdev->dev.of_node,
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");
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");
5580 + mute_gpio[0] = devm_gpiod_get_optional(&pdev->dev, "mute1",
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);
5589 + mute_gpio[1] = devm_gpiod_get_optional(&pdev->dev, "mute2",
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);
5598 + if (mute_gpio[0] && mute_gpio[1])
5599 + snd_allo_piano_dac.set_bias_level =
5600 + snd_allo_piano_set_bias_level;
5602 + ret = snd_soc_register_card(&snd_allo_piano_dac);
5604 + dev_err(&pdev->dev,
5605 + "snd_soc_register_card() failed: %d\n", ret);
5609 + if ((mute_gpio[0]) && (mute_gpio[1]))
5610 + snd_allo_piano_gpio_mute(&snd_allo_piano_dac);
5618 +static int snd_allo_piano_dac_remove(struct platform_device *pdev)
5620 + struct snd_soc_card *card = platform_get_drvdata(pdev);
5622 + kfree(&card->drvdata);
5623 + snd_allo_piano_gpio_mute(&snd_allo_piano_dac);
5624 + snd_soc_unregister_card(&snd_allo_piano_dac);
5628 +static const struct of_device_id snd_allo_piano_dac_of_match[] = {
5629 + { .compatible = "allo,piano-dac-plus", },
5630 + { /* sentinel */ },
5633 +MODULE_DEVICE_TABLE(of, snd_allo_piano_dac_of_match);
5635 +static struct platform_driver snd_allo_piano_dac_driver = {
5637 + .name = "snd-allo-piano-dac-plus",
5638 + .owner = THIS_MODULE,
5639 + .of_match_table = snd_allo_piano_dac_of_match,
5641 + .probe = snd_allo_piano_dac_probe,
5642 + .remove = snd_allo_piano_dac_remove,
5645 +module_platform_driver(snd_allo_piano_dac_driver);
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");
5651 +++ b/sound/soc/bcm/allo-piano-dac.c
5654 + * ALSA ASoC Machine Driver for Allo Piano DAC
5656 + * Author: Baswaraj K <jaikumar@cem-solutions.net>
5658 + * based on code by Daniel Matuschek <info@crazy-audio.com>
5659 + * based on code by Florian Meier <florian.meier@koalo.de>
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.
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.
5671 +#include <linux/module.h>
5672 +#include <linux/platform_device.h>
5674 +#include <sound/core.h>
5675 +#include <sound/pcm.h>
5676 +#include <sound/pcm_params.h>
5677 +#include <sound/soc.h>
5679 +static bool digital_gain_0db_limit = true;
5681 +static int snd_allo_piano_dac_init(struct snd_soc_pcm_runtime *rtd)
5683 + if (digital_gain_0db_limit) {
5685 + struct snd_soc_card *card = rtd->card;
5687 + ret = snd_soc_limit_volume(card, "Digital Playback Volume",
5690 + dev_warn(card->dev, "Failed to set volume limit: %d\n",
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")));
5702 +static struct snd_soc_dai_link snd_allo_piano_dac_dai[] = {
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),
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),
5722 +static int snd_allo_piano_dac_probe(struct platform_device *pdev)
5726 + snd_allo_piano_dac.dev = &pdev->dev;
5728 + if (pdev->dev.of_node) {
5729 + struct device_node *i2s_node;
5730 + struct snd_soc_dai_link *dai;
5732 + dai = &snd_allo_piano_dac_dai[0];
5733 + i2s_node = of_parse_phandle(pdev->dev.of_node,
5734 + "i2s-controller", 0);
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;
5743 + digital_gain_0db_limit = !of_property_read_bool(
5744 + pdev->dev.of_node, "allo,24db_digital_gain");
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);
5755 +static const struct of_device_id snd_allo_piano_dac_of_match[] = {
5756 + { .compatible = "allo,piano-dac", },
5757 + { /* sentinel */ },
5759 +MODULE_DEVICE_TABLE(of, snd_allo_piano_dac_of_match);
5761 +static struct platform_driver snd_allo_piano_dac_driver = {
5763 + .name = "snd-allo-piano-dac",
5764 + .owner = THIS_MODULE,
5765 + .of_match_table = snd_allo_piano_dac_of_match,
5767 + .probe = snd_allo_piano_dac_probe,
5770 +module_platform_driver(snd_allo_piano_dac_driver);
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");
5776 +++ b/sound/soc/bcm/audioinjector-isolated-soundcard.c
5779 + * ASoC Driver for AudioInjector.net isolated soundcard
5781 + * Created on: 20-February-2020
5782 + * Author: flatmax@flatmax.org
5783 + * based on audioinjector-octo-soundcard.c
5785 + * Copyright (C) 2020 Flatmax Pty. Ltd.
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.
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.
5797 +#include <linux/module.h>
5798 +#include <linux/types.h>
5799 +#include <linux/gpio/consumer.h>
5801 +#include <sound/core.h>
5802 +#include <sound/soc.h>
5803 +#include <sound/pcm_params.h>
5804 +#include <sound/control.h>
5806 +static struct gpio_desc *mute_gpio;
5808 +static const unsigned int audioinjector_isolated_rates[] = {
5809 + 192000, 96000, 48000, 32000, 24000, 16000, 8000
5812 +static struct snd_pcm_hw_constraint_list audioinjector_isolated_constraints = {
5813 + .list = audioinjector_isolated_rates,
5814 + .count = ARRAY_SIZE(audioinjector_isolated_rates),
5817 +static int audioinjector_isolated_dai_init(struct snd_soc_pcm_runtime *rtd)
5819 + int ret=snd_soc_dai_set_sysclk(asoc_rtd_to_codec(rtd, 0), 0, 24576000, 0);
5823 + return snd_soc_dai_set_bclk_ratio(asoc_rtd_to_cpu(rtd, 0), 64);
5826 +static int audioinjector_isolated_startup(struct snd_pcm_substream *substream)
5828 + snd_pcm_hw_constraint_list(substream->runtime, 0,
5829 + SNDRV_PCM_HW_PARAM_RATE, &audioinjector_isolated_constraints);
5834 +static int audioinjector_isolated_trigger(struct snd_pcm_substream *substream,
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);
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);
5854 +static struct snd_soc_ops audioinjector_isolated_ops = {
5855 + .startup = audioinjector_isolated_startup,
5856 + .trigger = audioinjector_isolated_trigger,
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")));
5864 +static struct snd_soc_dai_link audioinjector_isolated_dai[] = {
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),
5877 +static const struct snd_soc_dapm_widget audioinjector_isolated_widgets[] = {
5878 + SND_SOC_DAPM_OUTPUT("OUTPUTS"),
5879 + SND_SOC_DAPM_INPUT("INPUTS"),
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-"},
5889 + /* Balanced inputs */
5890 + {"AINA", NULL, "INPUTS"},
5891 + {"AINB", NULL, "INPUTS"},
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),
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),
5905 +static int audioinjector_isolated_probe(struct platform_device *pdev)
5907 + struct snd_soc_card *card = &snd_soc_audioinjector_isolated;
5910 + card->dev = &pdev->dev;
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);
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;
5923 + dev_err(&pdev->dev,
5924 + "i2s-controller missing or invalid in DT\n");
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);
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);
5941 +static const struct of_device_id audioinjector_isolated_of_match[] = {
5942 + { .compatible = "ai,audioinjector-isolated-soundcard", },
5945 +MODULE_DEVICE_TABLE(of, audioinjector_isolated_of_match);
5947 +static struct platform_driver audioinjector_isolated_driver = {
5949 + .name = "audioinjector-isolated",
5950 + .owner = THIS_MODULE,
5951 + .of_match_table = audioinjector_isolated_of_match,
5953 + .probe = audioinjector_isolated_probe,
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");
5962 +++ b/sound/soc/bcm/audioinjector-octo-soundcard.c
5965 + * ASoC Driver for AudioInjector Pi octo channel soundcard (hat)
5967 + * Created on: 27-October-2016
5968 + * Author: flatmax@flatmax.org
5969 + * based on audioinjector-pi-soundcard.c
5971 + * Copyright (C) 2016 Flatmax Pty. Ltd.
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.
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.
5983 +#include <linux/module.h>
5984 +#include <linux/types.h>
5985 +#include <linux/gpio/consumer.h>
5987 +#include <sound/core.h>
5988 +#include <sound/soc.h>
5989 +#include <sound/pcm_params.h>
5990 +#include <sound/control.h>
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;
5997 +static const unsigned int audioinjector_octo_rates[] = {
5998 + 96000, 48000, 32000, 24000, 16000, 8000, 88200, 44100, 29400, 22050, 14700,
6001 +static struct snd_pcm_hw_constraint_list audioinjector_octo_constraints = {
6002 + .list = audioinjector_octo_rates,
6003 + .count = ARRAY_SIZE(audioinjector_octo_rates),
6006 +static int audioinjector_octo_dai_init(struct snd_soc_pcm_runtime *rtd)
6008 + return snd_soc_dai_set_bclk_ratio(asoc_rtd_to_cpu(rtd, 0), 64);
6011 +static int audioinjector_octo_startup(struct snd_pcm_substream *substream)
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;
6020 + snd_pcm_hw_constraint_list(substream->runtime, 0,
6021 + SNDRV_PCM_HW_PARAM_RATE,
6022 + &audioinjector_octo_constraints);
6027 +static void audioinjector_octo_shutdown(struct snd_pcm_substream *substream)
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;
6037 +static int audioinjector_octo_hw_params(struct snd_pcm_substream *substream,
6038 + struct snd_pcm_hw_params *params)
6040 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
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);
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);
6056 + audioinjector_octo_rate = params_rate(params);
6058 + // Set the correct sysclock for the codec
6059 + switch (audioinjector_octo_rate) {
6062 + return snd_soc_dai_set_sysclk(asoc_rtd_to_codec(rtd, 0), 0, 49152000,
6066 + return snd_soc_dai_set_sysclk(asoc_rtd_to_codec(rtd, 0), 0, 49152000/2,
6071 + return snd_soc_dai_set_sysclk(asoc_rtd_to_codec(rtd, 0), 0, 49152000/3,
6075 + return snd_soc_dai_set_sysclk(asoc_rtd_to_codec(rtd, 0), 0, 49152000/6,
6080 + return snd_soc_dai_set_sysclk(asoc_rtd_to_codec(rtd, 0), 0, 45185400,
6084 + return snd_soc_dai_set_sysclk(asoc_rtd_to_codec(rtd, 0), 0, 45185400/2,
6089 + return snd_soc_dai_set_sysclk(asoc_rtd_to_codec(rtd, 0), 0, 45185400/3,
6097 +static int audioinjector_octo_trigger(struct snd_pcm_substream *substream,
6099 + DECLARE_BITMAP(mult, 4);
6101 + memset(mult, 0, sizeof(mult));
6104 + case SNDRV_PCM_TRIGGER_STOP:
6105 + case SNDRV_PCM_TRIGGER_SUSPEND:
6106 + case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
6107 + if (!non_stop_clocks)
6110 + case SNDRV_PCM_TRIGGER_START:
6111 + case SNDRV_PCM_TRIGGER_RESUME:
6112 + case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
6113 + switch (audioinjector_octo_rate) {
6115 + __assign_bit(3, mult, 1);
6118 + __assign_bit(1, mult, 1);
6119 + __assign_bit(2, mult, 1);
6122 + __assign_bit(3, mult, 1);
6125 + __assign_bit(2, mult, 1);
6128 + __assign_bit(3, mult, 1);
6131 + __assign_bit(0, mult, 1);
6132 + __assign_bit(1, mult, 1);
6135 + __assign_bit(3, mult, 1);
6138 + __assign_bit(1, mult, 1);
6141 + __assign_bit(3, mult, 1);
6144 + __assign_bit(0, mult, 1);
6147 + __assign_bit(3, mult, 1);
6156 + gpiod_set_array_value_cansleep(mult_gpios->ndescs, mult_gpios->desc,
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,
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()));
6174 +static struct snd_soc_dai_link audioinjector_octo_dai[] = {
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),
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"),
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"},
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"},
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),
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),
6227 +static int audioinjector_octo_probe(struct platform_device *pdev)
6229 + struct snd_soc_card *card = &snd_soc_audioinjector_octo;
6232 + card->dev = &pdev->dev;
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,
6243 + mult_gpios = devm_gpiod_get_array_optional(&pdev->dev, "mult",
6245 + if (IS_ERR(mult_gpios))
6246 + return PTR_ERR(mult_gpios);
6248 + codec_rst_gpio = devm_gpiod_get_optional(&pdev->dev, "reset",
6250 + if (IS_ERR(codec_rst_gpio))
6251 + return PTR_ERR(codec_rst_gpio);
6253 + non_stop_clocks = of_property_read_bool(pdev->dev.of_node, "non-stop-clocks");
6255 + if (codec_rst_gpio)
6256 + gpiod_set_value(codec_rst_gpio, 1);
6258 + if (codec_rst_gpio)
6259 + gpiod_set_value(codec_rst_gpio, 0);
6261 + if (codec_rst_gpio)
6262 + gpiod_set_value(codec_rst_gpio, 1);
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;
6274 + dev_err(&pdev->dev,
6275 + "i2s-controller missing or invalid in DT\n");
6278 + dev_err(&pdev->dev,
6279 + "Property 'codec' missing or invalid\n");
6284 + ret = devm_snd_soc_register_card(&pdev->dev, card);
6286 + dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret);
6290 +static const struct of_device_id audioinjector_octo_of_match[] = {
6291 + { .compatible = "ai,audioinjector-octo-soundcard", },
6294 +MODULE_DEVICE_TABLE(of, audioinjector_octo_of_match);
6296 +static struct platform_driver audioinjector_octo_driver = {
6298 + .name = "audioinjector-octo",
6299 + .owner = THIS_MODULE,
6300 + .of_match_table = audioinjector_octo_of_match,
6302 + .probe = audioinjector_octo_probe,
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");
6311 +++ b/sound/soc/bcm/audioinjector-pi-soundcard.c
6314 + * ASoC Driver for AudioInjector Pi add on soundcard
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.
6322 + * Copyright (C) 2016 Flatmax Pty. Ltd.
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.
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.
6334 +#include <linux/module.h>
6335 +#include <linux/types.h>
6337 +#include <sound/core.h>
6338 +#include <sound/soc.h>
6339 +#include <sound/pcm_params.h>
6340 +#include <sound/control.h>
6342 +#include "../codecs/wm8731.h"
6344 +static const unsigned int bcm2835_rates_12000000[] = {
6345 + 8000, 16000, 32000, 44100, 48000, 96000, 88200,
6348 +static struct snd_pcm_hw_constraint_list bcm2835_constraints_12000000 = {
6349 + .list = bcm2835_rates_12000000,
6350 + .count = ARRAY_SIZE(bcm2835_rates_12000000),
6353 +static int snd_audioinjector_pi_soundcard_startup(struct snd_pcm_substream *substream)
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);
6362 +static int snd_audioinjector_pi_soundcard_hw_params(struct snd_pcm_substream *substream,
6363 + struct snd_pcm_hw_params *params)
6365 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
6366 + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
6368 + switch (params_rate(params)){
6370 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 1);
6372 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 750);
6374 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 375);
6376 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 272);
6378 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 250);
6380 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 136);
6382 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 125);
6384 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 125);
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,
6394 +static int audioinjector_pi_soundcard_dai_init(struct snd_soc_pcm_runtime *rtd)
6396 + return snd_soc_dai_set_sysclk(asoc_rtd_to_codec(rtd, 0), WM8731_SYSCLK_XTAL, 12000000, SND_SOC_CLOCK_IN);
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")));
6404 +static struct snd_soc_dai_link audioinjector_pi_soundcard_dai[] = {
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),
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),
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"},
6427 + /* speaker connected to LOUT, ROUT */
6428 + {"Ext Spk", NULL, "ROUT"},
6429 + {"Ext Spk", NULL, "LOUT"},
6432 + {"Line In Jacks", NULL, "Line Input"},
6434 + /* mic is connected to Mic Jack, with WM8731 Mic Bias */
6435 + {"Microphone", NULL, "Mic Bias"},
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),
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),
6449 +static int audioinjector_pi_soundcard_probe(struct platform_device *pdev)
6451 + struct snd_soc_card *card = &snd_soc_audioinjector;
6454 + card->dev = &pdev->dev;
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);
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;
6467 + if (!dai->cpus->of_node) {
6468 + dev_err(&pdev->dev, "Property 'i2s-controller' missing or invalid\n");
6473 + if ((ret = devm_snd_soc_register_card(&pdev->dev, card)))
6474 + return dev_err_probe(&pdev->dev, ret, "%s\n", __func__);
6476 + dev_info(&pdev->dev, "successfully loaded\n");
6481 +static const struct of_device_id audioinjector_pi_soundcard_of_match[] = {
6482 + { .compatible = "ai,audioinjector-pi-soundcard", },
6485 +MODULE_DEVICE_TABLE(of, audioinjector_pi_soundcard_of_match);
6487 +static struct platform_driver audioinjector_pi_soundcard_driver = {
6489 + .name = "audioinjector-stereo",
6490 + .owner = THIS_MODULE,
6491 + .of_match_table = audioinjector_pi_soundcard_of_match,
6493 + .probe = audioinjector_pi_soundcard_probe,
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");
6503 +++ b/sound/soc/bcm/audiosense-pi.c
6506 + * ASoC Driver for AudioSense add on soundcard
6508 + * Bhargav A K <anur.bhargav@gmail.com>
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.
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.
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>
6532 +#include <sound/tlv320aic32x4.h>
6533 +#include "../codecs/tlv320aic32x4.h"
6535 +#define AIC32X4_SYSCLK_XTAL 0x00
6538 + * Setup Codec Sample Rates and Channels
6539 + * Supported Rates:
6540 + * 8000, 11025, 16000, 22050, 32000, 44100, 48000, 64000, 88200, 96000,
6542 +static const unsigned int audiosense_pi_rate[] = {
6546 +static struct snd_pcm_hw_constraint_list audiosense_constraints_rates = {
6547 + .list = audiosense_pi_rate,
6548 + .count = ARRAY_SIZE(audiosense_pi_rate),
6551 +static const unsigned int audiosense_pi_channels[] = {
6555 +static struct snd_pcm_hw_constraint_list audiosense_constraints_ch = {
6556 + .count = ARRAY_SIZE(audiosense_pi_channels),
6557 + .list = audiosense_pi_channels,
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"),
6570 +static const struct snd_soc_dapm_route audiosense_pi_audio_map[] = {
6571 + /* Line Inputs are connected to
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"},
6583 + /* Mic is connected to IN2_L and IN2_R */
6584 + {"Left ADC", NULL, "Mic Bias"},
6585 + {"Right ADC", NULL, "Mic Bias"},
6587 + /* Headphone connected to HPL, HPR */
6588 + {"Headphone Jack", NULL, "HPL"},
6589 + {"Headphone Jack", NULL, "HPR"},
6591 + /* Speakers connected to LOL and LOR */
6592 + {"Line Out", NULL, "LOL"},
6593 + {"Line Out", NULL, "LOR"},
6596 +static int audiosense_pi_card_init(struct snd_soc_pcm_runtime *rtd)
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;
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);
6612 +static int audiosense_pi_card_hw_params(
6613 + struct snd_pcm_substream *substream,
6614 + struct snd_pcm_hw_params *params)
6617 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
6618 + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
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);
6624 + dev_err(rtd->card->dev,
6625 + "could not set codec driver clock params\n");
6631 +static int audiosense_pi_card_startup(struct snd_pcm_substream *substream)
6633 + struct snd_pcm_runtime *runtime = substream->runtime;
6636 + * Set codec to 48Khz Sampling, Stereo I/O and 16 bit audio
6638 + runtime->hw.channels_max = 2;
6639 + snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
6640 + &audiosense_constraints_ch);
6642 + runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE;
6643 + snd_pcm_hw_constraint_msbits(runtime, 0, 16, 16);
6646 + snd_pcm_hw_constraint_list(substream->runtime, 0,
6647 + SNDRV_PCM_HW_PARAM_RATE,
6648 + &audiosense_constraints_rates);
6652 +static struct snd_soc_ops audiosense_pi_card_ops = {
6653 + .startup = audiosense_pi_card_startup,
6654 + .hw_params = audiosense_pi_card_hw_params,
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")));
6662 +static struct snd_soc_dai_link audiosense_pi_card_dai[] = {
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),
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),
6686 +static int audiosense_pi_card_probe(struct platform_device *pdev)
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;
6693 + card->dev = &pdev->dev;
6696 + dev_err(&pdev->dev, "DAI not found. Missing or Invalid\n");
6700 + i2s_node = of_parse_phandle(pdev->dev.of_node, "i2s-controller", 0);
6702 + dev_err(&pdev->dev,
6703 + "Property 'i2s-controller' missing or invalid\n");
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;
6712 + of_node_put(i2s_node);
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);
6722 +static int audiosense_pi_card_remove(struct platform_device *pdev)
6724 + struct snd_soc_card *card = platform_get_drvdata(pdev);
6726 + snd_soc_unregister_card(card);
6730 +static const struct of_device_id audiosense_pi_card_of_match[] = {
6731 + { .compatible = "as,audiosense-pi", },
6734 +MODULE_DEVICE_TABLE(of, audiosense_pi_card_of_match);
6736 +static struct platform_driver audiosense_pi_card_driver = {
6738 + .name = "audiosense-snd-card",
6739 + .owner = THIS_MODULE,
6740 + .of_match_table = audiosense_pi_card_of_match,
6742 + .probe = audiosense_pi_card_probe,
6743 + .remove = audiosense_pi_card_remove,
6746 +module_platform_driver(audiosense_pi_card_driver);
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");
6754 +++ b/sound/soc/bcm/chipdip-dac.c
6757 + * ASoC Driver for ChipDip DAC
6759 + * Author: Evgenij Sapunov
6761 + * based on code by Milan Neskovic <info@justboom.co>
6762 + * based on code by Jaikumar <jaikumar@cem-solutions.net>
6764 + * Thanks to Phil Elwell (pelwell) for help.
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.
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.
6776 +#include <linux/module.h>
6777 +#include <linux/gpio/consumer.h>
6778 +#include <linux/platform_device.h>
6779 +#include <linux/delay.h>
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>
6787 +#define SR_BIT_0 0 //sample rate bits
6790 +#define BD_BIT_0 3 //bit depth bits
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))
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))
6806 +#define MUTE_ACTIVE 0
6807 +#define MUTE_NOT_ACTIVE 1
6809 +#define HW_PARAMS_GPIO_COUNT 5
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;
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);
6820 +static void snd_rpi_chipdip_dac_gpio_array_set(int value)
6824 + for (i = 0; i < HW_PARAMS_GPIO_COUNT; i++)
6825 + snd_rpi_chipdip_dac_gpio_set(hw_params_gpios[i], ((value >> i) & 1));
6828 +static void snd_rpi_chipdip_dac_gpio_set(struct gpio_desc *gpio_item, int value)
6831 + gpiod_set_value_cansleep(gpio_item, value);
6834 +static int snd_rpi_chipdip_dac_init(struct snd_soc_pcm_runtime *rtd)
6839 +static int snd_rpi_chipdip_dac_hw_params(struct snd_pcm_substream *substream,
6840 + struct snd_pcm_hw_params *params)
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;
6849 + ret = snd_soc_dai_set_bclk_ratio(asoc_rtd_to_cpu(rtd, 0), 2 * 32);
6851 + if (current_width != param_value) {
6852 + current_width = param_value;
6853 + gpio_change_pending = 1;
6855 + switch (param_value) {
6857 + bit_depth_state = BIT_DEPTH_MASK_16;
6860 + bit_depth_state = BIT_DEPTH_MASK_24;
6863 + bit_depth_state = BIT_DEPTH_MASK_32;
6870 + param_value = params_rate(params);
6871 + if (current_rate != param_value) {
6872 + current_rate = param_value;
6873 + gpio_change_pending = 1;
6875 + switch (param_value) {
6877 + sample_rate_state = SAMPLE_RATE_MASK_44_1;
6880 + sample_rate_state = SAMPLE_RATE_MASK_48;
6883 + sample_rate_state = SAMPLE_RATE_MASK_88_2;
6886 + sample_rate_state = SAMPLE_RATE_MASK_96;
6889 + sample_rate_state = SAMPLE_RATE_MASK_176_4;
6892 + sample_rate_state = SAMPLE_RATE_MASK_192;
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);
6903 + snd_rpi_chipdip_dac_gpio_set(mute_gpio, MUTE_NOT_ACTIVE);
6909 +static int snd_rpi_chipdip_dac_startup(struct snd_pcm_substream *substream)
6914 +static void snd_rpi_chipdip_dac_shutdown(struct snd_pcm_substream *substream)
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,
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")));
6931 +static struct snd_soc_dai_link snd_rpi_chipdip_dac_dai[] = {
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),
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),
6952 +static int snd_rpi_chipdip_dac_probe(struct platform_device *pdev)
6957 + snd_rpi_chipdip_dac.dev = &pdev->dev;
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);
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;
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);
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);
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);
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);
7001 + snd_rpi_chipdip_dac_gpio_set(sdwn_gpio, 1);
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);
7011 +static const struct of_device_id snd_rpi_chipdip_dac_of_match[] = {
7012 + { .compatible = "chipdip,chipdip-dac", },
7015 +MODULE_DEVICE_TABLE(of, snd_rpi_chipdip_dac_of_match);
7017 +static struct platform_driver snd_rpi_chipdip_dac_driver = {
7019 + .name = "snd-rpi-chipdip-dac",
7020 + .owner = THIS_MODULE,
7021 + .of_match_table = snd_rpi_chipdip_dac_of_match,
7023 + .probe = snd_rpi_chipdip_dac_probe,
7026 +module_platform_driver(snd_rpi_chipdip_dac_driver);
7028 +MODULE_AUTHOR("Evgenij Sapunov <evgenij.sapunov@chipdip.ru>");
7029 +MODULE_DESCRIPTION("ASoC Driver for ChipDip DAC");
7030 +MODULE_LICENSE("GPL v2");
7032 +++ b/sound/soc/bcm/dacberry400.c
7035 + * ASoC Driver for Dacberry400 soundcard
7037 + * Ashish Vara<ashishhvara@gmail.com>
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.
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.
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"
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"),
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),
7077 +static const struct snd_soc_dapm_route dacberry400_audio_map[] = {
7078 + {"Headphone Jack", NULL, "HPLOUT"},
7079 + {"Headphone Jack", NULL, "HPROUT"},
7081 + {"LINE1L", NULL, "Line In"},
7082 + {"LINE1R", NULL, "Line In"},
7084 + {"Line Out", NULL, "LLOUT"},
7085 + {"Line Out", NULL, "RLOUT"},
7087 + {"MIC3L", NULL, "MIC Jack"},
7088 + {"MIC3R", NULL, "MIC Jack"},
7091 +static int snd_rpi_dacberry400_init(struct snd_soc_pcm_runtime *rtd)
7093 + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
7094 + struct snd_soc_component *component = codec_dai->component;
7097 + ret = snd_soc_dai_set_sysclk(codec_dai, 2, 12000000,
7098 + SND_SOC_CLOCK_OUT);
7100 + if (ret && ret != -ENOTSUPP)
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);
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)
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;
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)
7127 + case SND_SOC_BIAS_PREPARE:
7128 + if (dapm->bias_level != SND_SOC_BIAS_STANDBY)
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__);
7140 + case SND_SOC_BIAS_STANDBY:
7141 + if (dapm->bias_level != SND_SOC_BIAS_PREPARE)
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__);
7160 +static int snd_rpi_dacberry400_hw_params(struct snd_pcm_substream *substream,
7161 + struct snd_pcm_hw_params *params)
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);
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);
7181 + clock = snd_soc_component_read(component, 2);
7183 + ret = snd_soc_dai_set_bclk_ratio(cpu_dai, channels*width);
7188 +static const struct snd_soc_ops snd_rpi_dacberry400_ops = {
7189 + .hw_params = snd_rpi_dacberry400_hw_params,
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")));
7198 +static struct snd_soc_dai_link snd_rpi_dacberry400_dai[] = {
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),
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,
7222 +static int snd_rpi_dacberry400_probe(struct platform_device *pdev)
7226 + snd_rpi_dacberry400.dev = &pdev->dev;
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];
7233 + i2s_node = of_parse_phandle(pdev->dev.of_node,
7234 + "i2s-controller", 0);
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);
7243 + if (of_property_read_string(pdev->dev.of_node, "card_name",
7245 + card->name = "tlvaudioCODEC";
7247 + if (of_property_read_string(pdev->dev.of_node, "dai_name",
7249 + dai->name = "tlvaudio CODEC";
7253 + ret = snd_soc_register_card(&snd_rpi_dacberry400);
7255 + if (ret != -EPROBE_DEFER)
7256 + dev_err(&pdev->dev,
7257 + "snd_soc_register_card() failed: %d\n", ret);
7264 +static int snd_rpi_dacberry400_remove(struct platform_device *pdev)
7266 + snd_soc_unregister_card(&snd_rpi_dacberry400);
7270 +static const struct of_device_id dacberry400_match_id[] = {
7271 + { .compatible = "osaelectronics,dacberry400",},
7274 +MODULE_DEVICE_TABLE(of, dacberry400_match_id);
7276 +static struct platform_driver snd_rpi_dacberry400_driver = {
7278 + .name = "snd-rpi-dacberry400",
7279 + .owner = THIS_MODULE,
7280 + .of_match_table = dacberry400_match_id,
7282 + .probe = snd_rpi_dacberry400_probe,
7283 + .remove = snd_rpi_dacberry400_remove,
7286 +module_platform_driver(snd_rpi_dacberry400_driver);
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");
7294 +++ b/sound/soc/bcm/digidac1-soundcard.c
7297 + * ASoC Driver for RRA DigiDAC1
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.
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.
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>
7324 +#include "../codecs/wm8804.h"
7325 +#include "../codecs/wm8741.h"
7327 +#define WM8741_NUM_SUPPLIES 2
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;
7338 +static int samplerate = 44100;
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 */
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 */
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 */
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]),
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]),
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]),
7400 +static int w8741_add_controls(struct snd_soc_component *component)
7402 + struct wm8741_priv *wm8741 = snd_soc_component_get_drvdata(component);
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));
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));
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));
7428 +static int digidac1_soundcard_init(struct snd_soc_pcm_runtime *rtd)
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;
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");
7443 + wm8741_component = asoc_rtd_to_codec(wm8741_rtd, 0)->component;
7444 + ret = w8741_add_controls(wm8741_component);
7446 + dev_warn(card->dev, "Failed to add new wm8741 controls: %d\n",
7449 + /* enable TX output */
7450 + snd_soc_component_update_bits(component, WM8804_PWRDN, 0x4, 0x0);
7452 + kctl = snd_soc_card_get_kcontrol(card,
7453 + "Playback Volume");
7455 + kctl->vd[0].access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
7456 + snd_ctl_remove(sound_card, kctl);
7458 + kctl = snd_soc_card_get_kcontrol(card,
7459 + "Fine Playback Volume");
7461 + kctl->vd[0].access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
7462 + snd_ctl_remove(sound_card, kctl);
7467 +static int digidac1_soundcard_startup(struct snd_pcm_substream *substream)
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;
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");
7482 + wm8741_component = asoc_rtd_to_codec(wm8741_rtd, 0)->component;
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);
7497 +static void digidac1_soundcard_shutdown(struct snd_pcm_substream *substream)
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;
7503 + snd_soc_component_update_bits(component, WM8804_PWRDN, 0x3c, 0x3c);
7506 +static int digidac1_soundcard_hw_params(struct snd_pcm_substream *substream,
7507 + struct snd_pcm_hw_params *params)
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;
7517 + int sysclk = 27000000;
7518 + long mclk_freq = 0;
7520 + int sampling_freq = 1;
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");
7528 + wm8741_component = asoc_rtd_to_codec(wm8741_rtd, 0)->component;
7529 + samplerate = params_rate(params);
7531 + if (samplerate <= 96000) {
7532 + mclk_freq = samplerate*256;
7533 + mclk_div = WM8804_MCLKDIV_256FS;
7535 + mclk_freq = samplerate*128;
7536 + mclk_div = WM8804_MCLKDIV_128FS;
7539 + switch (samplerate) {
7541 + sampling_freq = 0x03;
7544 + sampling_freq = 0x00;
7547 + sampling_freq = 0x02;
7550 + sampling_freq = 0x08;
7553 + sampling_freq = 0x0a;
7556 + sampling_freq = 0x0c;
7559 + sampling_freq = 0x0e;
7562 + dev_err(card->dev,
7563 + "Failed to set WM8804 SYSCLK, unsupported samplerate %d\n",
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);
7570 + ret = snd_soc_dai_set_sysclk(codec_dai, WM8804_TX_CLKSRC_PLL,
7571 + sysclk, SND_SOC_CLOCK_OUT);
7573 + dev_err(card->dev,
7574 + "Failed to set WM8804 SYSCLK: %d\n", ret);
7577 + /* Enable wm8804 TX output */
7578 + snd_soc_component_update_bits(component, WM8804_PWRDN, 0x4, 0x0);
7580 + /* wm8804 Power on */
7581 + snd_soc_component_update_bits(component, WM8804_PWRDN, 0x9, 0);
7583 + /* wm8804 set sampling frequency status bits */
7584 + snd_soc_component_update_bits(component, WM8804_SPDTX4, 0x0f, sampling_freq);
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);
7594 + snd_soc_component_update_bits(wm8741_component, WM8741_MODE_CONTROL_1,
7595 + WM8741_OSR_MASK, 0x40);
7597 + /* wm8741 bit size */
7598 + switch (params_width(params)) {
7600 + snd_soc_component_update_bits(wm8741_component, WM8741_FORMAT_CONTROL,
7601 + WM8741_IWL_MASK, 0x00);
7604 + snd_soc_component_update_bits(wm8741_component, WM8741_FORMAT_CONTROL,
7605 + WM8741_IWL_MASK, 0x01);
7608 + snd_soc_component_update_bits(wm8741_component, WM8741_FORMAT_CONTROL,
7609 + WM8741_IWL_MASK, 0x02);
7612 + snd_soc_component_update_bits(wm8741_component, WM8741_FORMAT_CONTROL,
7613 + WM8741_IWL_MASK, 0x03);
7616 + dev_dbg(card->dev, "wm8741_hw_params: Unsupported bit size param = %d",
7617 + params_width(params));
7621 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 64);
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,
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")));
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()));
7640 +static struct snd_soc_dai_link digidac1_soundcard_dai[] = {
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),
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),
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),
7668 +static int digidac1_soundcard_probe(struct platform_device *pdev)
7672 + digidac1_soundcard.dev = &pdev->dev;
7674 + if (pdev->dev.of_node) {
7675 + struct device_node *i2s_node;
7676 + struct snd_soc_dai_link *dai = &digidac1_soundcard_dai[0];
7678 + i2s_node = of_parse_phandle(pdev->dev.of_node,
7679 + "i2s-controller", 0);
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;
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",
7697 +static const struct of_device_id digidac1_soundcard_of_match[] = {
7698 + { .compatible = "rra,digidac1-soundcard", },
7701 +MODULE_DEVICE_TABLE(of, digidac1_soundcard_of_match);
7703 +static struct platform_driver digidac1_soundcard_driver = {
7705 + .name = "digidac1-audio",
7706 + .owner = THIS_MODULE,
7707 + .of_match_table = digidac1_soundcard_of_match,
7709 + .probe = digidac1_soundcard_probe,
7712 +module_platform_driver(digidac1_soundcard_driver);
7714 +MODULE_AUTHOR("José M. Tasende <vintage@redrocksaudio.es>");
7715 +MODULE_DESCRIPTION("ASoC Driver for RRA DigiDAC1");
7716 +MODULE_LICENSE("GPL v2");
7718 +++ b/sound/soc/bcm/dionaudio_loco-v2.c
7721 + * ASoC Driver for Dion Audio LOCO-V2 DAC-AMP
7723 + * Author: Miquel Blauw <info@dionaudio.nl>
7726 + * Based on the software of the RPi-DAC writen by Florian Meier
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.
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.
7738 +#include <linux/module.h>
7739 +#include <linux/platform_device.h>
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>
7747 +static bool digital_gain_0db_limit = true;
7749 +static int snd_rpi_dionaudio_loco_v2_init(struct snd_soc_pcm_runtime *rtd)
7751 + if (digital_gain_0db_limit) {
7753 + struct snd_soc_card *card = rtd->card;
7755 + ret = snd_soc_limit_volume(card, "Digital Playback Volume", 207);
7757 + dev_warn(card->dev, "Failed to set volume limit: %d\n", ret);
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")));
7768 +static struct snd_soc_dai_link snd_rpi_dionaudio_loco_v2_dai[] = {
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),
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),
7785 +static int snd_rpi_dionaudio_loco_v2_probe(struct platform_device *pdev)
7789 + snd_rpi_dionaudio_loco_v2.dev = &pdev->dev;
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];
7796 + i2s_node = of_parse_phandle(pdev->dev.of_node,
7797 + "i2s-controller", 0);
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;
7805 + digital_gain_0db_limit = !of_property_read_bool(
7806 + pdev->dev.of_node, "dionaudio,24db_digital_gain");
7809 + ret = devm_snd_soc_register_card(&pdev->dev, &snd_rpi_dionaudio_loco_v2);
7811 + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
7817 +static const struct of_device_id dionaudio_of_match[] = {
7818 + { .compatible = "dionaudio,dionaudio-loco-v2", },
7821 +MODULE_DEVICE_TABLE(of, dionaudio_of_match);
7823 +static struct platform_driver snd_rpi_dionaudio_loco_v2_driver = {
7825 + .name = "snd-rpi-dionaudio-loco-v2",
7826 + .owner = THIS_MODULE,
7827 + .of_match_table = dionaudio_of_match,
7829 + .probe = snd_rpi_dionaudio_loco_v2_probe,
7832 +module_platform_driver(snd_rpi_dionaudio_loco_v2_driver);
7834 +MODULE_AUTHOR("Miquel Blauw <info@dionaudio.nl>");
7835 +MODULE_DESCRIPTION("ASoC Driver for DionAudio LOCO-V2");
7836 +MODULE_LICENSE("GPL v2");
7838 +++ b/sound/soc/bcm/dionaudio_loco.c
7841 + * ASoC Driver for Dion Audio LOCO DAC-AMP
7843 + * Author: Miquel Blauw <info@dionaudio.nl>
7846 + * Based on the software of the RPi-DAC writen by Florian Meier
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.
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.
7858 +#include <linux/module.h>
7859 +#include <linux/platform_device.h>
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>
7867 +static int snd_rpi_dionaudio_loco_hw_params(
7868 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
7870 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
7871 + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
7873 + unsigned int sample_bits =
7874 + snd_pcm_format_physical_width(params_format(params));
7876 + return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);
7879 +/* machine stream operations */
7880 +static struct snd_soc_ops snd_rpi_dionaudio_loco_ops = {
7881 + .hw_params = snd_rpi_dionaudio_loco_hw_params,
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")));
7889 +static struct snd_soc_dai_link snd_rpi_dionaudio_loco_dai[] = {
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),
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),
7908 +static int snd_rpi_dionaudio_loco_probe(struct platform_device *pdev)
7910 + struct device_node *np;
7913 + snd_rpi_dionaudio_loco.dev = &pdev->dev;
7915 + np = pdev->dev.of_node;
7917 + struct snd_soc_dai_link *dai = &snd_rpi_dionaudio_loco_dai[0];
7918 + struct device_node *i2s_np;
7920 + i2s_np = of_parse_phandle(np, "i2s-controller", 0);
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;
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",
7937 +static const struct of_device_id snd_rpi_dionaudio_loco_of_match[] = {
7938 + { .compatible = "dionaudio,loco-pcm5242-tpa3118", },
7939 + { /* sentinel */ },
7941 +MODULE_DEVICE_TABLE(of, snd_rpi_dionaudio_loco_of_match);
7943 +static struct platform_driver snd_rpi_dionaudio_loco_driver = {
7945 + .name = "snd-dionaudio-loco",
7946 + .owner = THIS_MODULE,
7947 + .of_match_table = snd_rpi_dionaudio_loco_of_match,
7949 + .probe = snd_rpi_dionaudio_loco_probe,
7952 +module_platform_driver(snd_rpi_dionaudio_loco_driver);
7954 +MODULE_AUTHOR("Miquel Blauw <info@dionaudio.nl>");
7955 +MODULE_DESCRIPTION("ASoC Driver for DionAudio LOCO");
7956 +MODULE_LICENSE("GPL v2");
7958 +++ b/sound/soc/bcm/fe-pi-audio.c
7961 + * ASoC Driver for Fe-Pi Audio Sound Card
7963 + * Author: Henry Kupis <kuupaz@gmail.com>
7965 + * based on code by Florian Meier <florian.meier@koalo.de>
7966 + * based on code by Shawn Guo <shawn.guo@linaro.org>
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.
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.
7978 +#include <linux/module.h>
7979 +#include <linux/platform_device.h>
7980 +#include <linux/io.h>
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>
7988 +#include "../codecs/sgtl5000.h"
7990 +static int snd_fe_pi_audio_init(struct snd_soc_pcm_runtime *rtd)
7992 + struct snd_soc_card *card = rtd->card;
7993 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
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);
8005 +static int snd_fe_pi_audio_hw_params(struct snd_pcm_substream *substream,
8006 + struct snd_pcm_hw_params *params)
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);
8014 + /* Set SGTL5000's SYSCLK */
8015 + ret = snd_soc_dai_set_sysclk(codec_dai, SGTL5000_SYSCLK, 12288000, SND_SOC_CLOCK_IN);
8017 + dev_err(dev, "could not set codec driver clock params\n");
8025 +static struct snd_soc_ops snd_fe_pi_audio_ops = {
8026 + .hw_params = snd_fe_pi_audio_hw_params,
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")));
8034 +static struct snd_soc_dai_link snd_fe_pi_audio_dai[] = {
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),
8046 +static const struct snd_soc_dapm_route fe_pi_audio_dapm_routes[] = {
8047 + {"ADC", NULL, "Mic Bias"},
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),
8057 + .dapm_routes = fe_pi_audio_dapm_routes,
8058 + .num_dapm_routes = ARRAY_SIZE(fe_pi_audio_dapm_routes),
8061 +static int snd_fe_pi_audio_probe(struct platform_device *pdev)
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];
8069 + fe_pi_audio.dev = &pdev->dev;
8071 + i2s_node = of_parse_phandle(np, "i2s-controller", 0);
8073 + dev_err(&pdev->dev, "i2s_node phandle missing or invalid\n");
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;
8082 + of_node_put(i2s_node);
8084 + card->dev = &pdev->dev;
8085 + platform_set_drvdata(pdev, card);
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);
8094 +static const struct of_device_id snd_fe_pi_audio_of_match[] = {
8095 + { .compatible = "fe-pi,fe-pi-audio", },
8098 +MODULE_DEVICE_TABLE(of, snd_fe_pi_audio_of_match);
8100 +static struct platform_driver snd_fe_pi_audio_driver = {
8102 + .name = "snd-fe-pi-audio",
8103 + .owner = THIS_MODULE,
8104 + .of_match_table = snd_fe_pi_audio_of_match,
8106 + .probe = snd_fe_pi_audio_probe,
8109 +module_platform_driver(snd_fe_pi_audio_driver);
8111 +MODULE_AUTHOR("Henry Kupis <fe-pi@cox.net>");
8112 +MODULE_DESCRIPTION("ASoC Driver for Fe-Pi Audio");
8113 +MODULE_LICENSE("GPL v2");
8115 +++ b/sound/soc/bcm/googlevoicehat-codec.c
8118 + * Driver for the Google voiceHAT audio codec for Raspberry Pi.
8120 + * Author: Peter Malkin <petermalkin@google.com>
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.
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.
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>
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
8154 +struct voicehat_priv {
8155 + struct delayed_work enable_sdmode_work;
8156 + struct gpio_desc *sdmode_gpio;
8157 + unsigned long sdmode_delay_jiffies;
8160 +static void voicehat_enable_sdmode_work(struct work_struct *work)
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);
8168 +static int voicehat_component_probe(struct snd_soc_component *component)
8170 + struct voicehat_priv *voicehat =
8171 + snd_soc_component_get_drvdata(component);
8173 + voicehat->sdmode_gpio = devm_gpiod_get(component->dev, "sdmode",
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);
8180 + INIT_DELAYED_WORK(&voicehat->enable_sdmode_work,
8181 + voicehat_enable_sdmode_work);
8185 +static void voicehat_component_remove(struct snd_soc_component *component)
8187 + struct voicehat_priv *voicehat =
8188 + snd_soc_component_get_drvdata(component);
8190 + cancel_delayed_work_sync(&voicehat->enable_sdmode_work);
8193 +static const struct snd_soc_dapm_widget voicehat_dapm_widgets[] = {
8194 + SND_SOC_DAPM_OUTPUT("Speaker"),
8197 +static const struct snd_soc_dapm_route voicehat_dapm_routes[] = {
8198 + {"Speaker", NULL, "HiFi Playback"},
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),
8210 +static int voicehat_daiops_trigger(struct snd_pcm_substream *substream, int cmd,
8211 + struct snd_soc_dai *dai)
8213 + struct snd_soc_component *component = dai->component;
8214 + struct voicehat_priv *voicehat =
8215 + snd_soc_component_get_drvdata(component);
8217 + if (voicehat->sdmode_delay_jiffies == 0)
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]);
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);
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);
8249 +static const struct snd_soc_dai_ops voicehat_dai_ops = {
8250 + .trigger = voicehat_daiops_trigger,
8253 +static struct snd_soc_dai_driver voicehat_dai = {
8254 + .name = "voicehat-hifi",
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
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
8269 + .ops = &voicehat_dai_ops,
8270 + .symmetric_rate = 1
8274 +static const struct of_device_id voicehat_ids[] = {
8275 + { .compatible = "google,voicehat", }, {}
8277 + MODULE_DEVICE_TABLE(of, voicehat_ids);
8280 +static int voicehat_platform_probe(struct platform_device *pdev)
8282 + struct voicehat_priv *voicehat;
8283 + unsigned int sdmode_delay;
8286 + voicehat = devm_kzalloc(&pdev->dev, sizeof(*voicehat), GFP_KERNEL);
8290 + ret = device_property_read_u32(&pdev->dev, "voicehat_sdmode_delay",
8294 + sdmode_delay = SDMODE_DELAY_MS;
8295 + dev_info(&pdev->dev,
8296 + "property 'voicehat_sdmode_delay' not found default 5 mS");
8298 + dev_info(&pdev->dev, "property 'voicehat_sdmode_delay' found delay= %d mS",
8301 + voicehat->sdmode_delay_jiffies = msecs_to_jiffies(sdmode_delay);
8303 + dev_set_drvdata(&pdev->dev, voicehat);
8305 + return snd_soc_register_component(&pdev->dev,
8306 + &voicehat_component_driver,
8311 +static int voicehat_platform_remove(struct platform_device *pdev)
8313 + snd_soc_unregister_component(&pdev->dev);
8317 +static struct platform_driver voicehat_driver = {
8319 + .name = "voicehat-codec",
8320 + .of_match_table = of_match_ptr(voicehat_ids),
8322 + .probe = voicehat_platform_probe,
8323 + .remove = voicehat_platform_remove,
8326 +module_platform_driver(voicehat_driver);
8328 +MODULE_DESCRIPTION("Google voiceHAT Codec driver");
8329 +MODULE_AUTHOR("Peter Malkin <petermalkin@google.com>");
8330 +MODULE_LICENSE("GPL v2");
8332 +++ b/sound/soc/bcm/hifiberry_dacplus.c
8335 + * ASoC Driver for HiFiBerry DAC+ / DAC Pro / AMP100
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>
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.
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.
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>
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>
8371 +#include "../codecs/pcm512x.h"
8373 +#define HIFIBERRY_DACPRO_NOCLOCK 0
8374 +#define HIFIBERRY_DACPRO_CLK44EN 1
8375 +#define HIFIBERRY_DACPRO_CLK48EN 2
8377 +struct pcm512x_priv {
8378 + struct regmap *regmap;
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
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;
8398 +static int snd_rpi_hifiberry_dacplus_mute_set(int mute)
8400 + gpiod_set_value_cansleep(snd_mute_gpio, mute);
8404 +static int snd_rpi_hifiberry_dacplus_mute_get(struct snd_kcontrol *kcontrol,
8405 + struct snd_ctl_elem_value *ucontrol)
8407 + ucontrol->value.integer.value[0] = mute_ext;
8412 +static int snd_rpi_hifiberry_dacplus_mute_put(struct snd_kcontrol *kcontrol,
8413 + struct snd_ctl_elem_value *ucontrol)
8415 + if (mute_ext == ucontrol->value.integer.value[0])
8418 + mute_ext = ucontrol->value.integer.value[0];
8420 + return snd_rpi_hifiberry_dacplus_mute_set(mute_ext);
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);
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),
8433 +static void snd_rpi_hifiberry_dacplus_select_clk(struct snd_soc_component *component,
8437 + case HIFIBERRY_DACPRO_NOCLOCK:
8438 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x24, 0x00);
8440 + case HIFIBERRY_DACPRO_CLK44EN:
8441 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x24, 0x20);
8443 + case HIFIBERRY_DACPRO_CLK48EN:
8444 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x24, 0x04);
8447 + usleep_range(3000, 4000);
8450 +static void snd_rpi_hifiberry_dacplus_clk_gpio(struct snd_soc_component *component)
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);
8457 +static bool snd_rpi_hifiberry_dacplus_is_sclk(struct snd_soc_component *component)
8461 + sck = snd_soc_component_read(component, PCM512x_RATE_DET_4);
8462 + return (!(sck & 0x40));
8465 +static bool snd_rpi_hifiberry_dacplus_is_pro_card(struct snd_soc_component *component)
8467 + bool isClk44EN, isClk48En, isNoClk;
8469 + snd_rpi_hifiberry_dacplus_clk_gpio(component);
8471 + snd_rpi_hifiberry_dacplus_select_clk(component, HIFIBERRY_DACPRO_CLK44EN);
8472 + isClk44EN = snd_rpi_hifiberry_dacplus_is_sclk(component);
8474 + snd_rpi_hifiberry_dacplus_select_clk(component, HIFIBERRY_DACPRO_NOCLOCK);
8475 + isNoClk = snd_rpi_hifiberry_dacplus_is_sclk(component);
8477 + snd_rpi_hifiberry_dacplus_select_clk(component, HIFIBERRY_DACPRO_CLK48EN);
8478 + isClk48En = snd_rpi_hifiberry_dacplus_is_sclk(component);
8480 + return (isClk44EN && isClk48En && !isNoClk);
8483 +static int snd_rpi_hifiberry_dacplus_clk_for_rate(int sample_rate)
8487 + switch (sample_rate) {
8494 + type = HIFIBERRY_DACPRO_CLK44EN;
8497 + type = HIFIBERRY_DACPRO_CLK48EN;
8503 +static void snd_rpi_hifiberry_dacplus_set_sclk(struct snd_soc_component *component,
8506 + struct pcm512x_priv *pcm512x = snd_soc_component_get_drvdata(component);
8508 + if (!IS_ERR(pcm512x->sclk)) {
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);
8518 +static int snd_rpi_hifiberry_dacplus_init(struct snd_soc_pcm_runtime *rtd)
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;
8525 + snd_rpi_hifiberry_is_dacpro = false;
8527 + snd_rpi_hifiberry_is_dacpro =
8528 + snd_rpi_hifiberry_dacplus_is_pro_card(component);
8530 + if (snd_rpi_hifiberry_is_dacpro) {
8531 + struct snd_soc_dai_link *dai = rtd->dai_link;
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;
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);
8542 + priv = snd_soc_component_get_drvdata(component);
8543 + priv->sclk = ERR_PTR(-ENOENT);
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);
8549 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x08, 0x00);
8551 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x08, 0x08);
8553 + if (digital_gain_0db_limit) {
8555 + struct snd_soc_card *card = rtd->card;
8557 + ret = snd_soc_limit_volume(card, "Digital Playback Volume", 207);
8559 + dev_warn(card->dev, "Failed to set volume limit: %d\n", ret);
8561 + if (snd_reset_gpio) {
8562 + gpiod_set_value_cansleep(snd_reset_gpio, 0);
8564 + gpiod_set_value_cansleep(snd_reset_gpio, 1);
8566 + gpiod_set_value_cansleep(snd_reset_gpio, 0);
8570 + snd_soc_add_card_controls(card, hb_dacplus_opt_mute_controls,
8571 + ARRAY_SIZE(hb_dacplus_opt_mute_controls));
8573 + if (snd_mute_gpio)
8574 + gpiod_set_value_cansleep(snd_mute_gpio, mute_ext);
8579 +static int snd_rpi_hifiberry_dacplus_update_rate_den(
8580 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
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;
8589 + rats_no_pll = devm_kzalloc(rtd->dev, sizeof(*rats_no_pll), GFP_KERNEL);
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;
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;
8605 + devm_kfree(rtd->dev, rats_no_pll);
8609 +static int snd_rpi_hifiberry_dacplus_hw_params(
8610 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
8613 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
8614 + int channels = params_channels(params);
8617 + if (snd_rpi_hifiberry_is_dacpro) {
8618 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
8620 + width = snd_pcm_format_physical_width(params_format(params));
8622 + snd_rpi_hifiberry_dacplus_set_sclk(component,
8623 + params_rate(params));
8625 + ret = snd_rpi_hifiberry_dacplus_update_rate_den(
8626 + substream, params);
8629 + ret = snd_soc_dai_set_bclk_ratio(asoc_rtd_to_cpu(rtd, 0), channels * width);
8632 + ret = snd_soc_dai_set_bclk_ratio(asoc_rtd_to_codec(rtd, 0), channels * width);
8636 +static int snd_rpi_hifiberry_dacplus_startup(
8637 + struct snd_pcm_substream *substream)
8639 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
8640 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
8643 + gpiod_set_value_cansleep(snd_mute_gpio, 0);
8646 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x08, 0x08);
8650 +static void snd_rpi_hifiberry_dacplus_shutdown(
8651 + struct snd_pcm_substream *substream)
8653 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
8654 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
8656 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x08, 0x00);
8658 + gpiod_set_value_cansleep(snd_mute_gpio, 1);
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,
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")));
8673 +static struct snd_soc_dai_link snd_rpi_hifiberry_dacplus_dai[] = {
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),
8685 +/* aux device for optional headphone amp */
8686 +static struct snd_soc_aux_dev hifiberry_dacplus_aux_devs[] = {
8689 + .name = "tpa6130a2.1-0060",
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),
8703 +static int hb_hp_detect(void)
8705 + struct i2c_adapter *adap = i2c_get_adapter(1);
8707 + struct i2c_client tpa_i2c_client = {
8713 + return -EPROBE_DEFER; /* I2C module not yet available */
8715 + ret = i2c_smbus_read_byte(&tpa_i2c_client) >= 0;
8716 + i2c_put_adapter(adap);
8720 +static struct property tpa_enable_prop = {
8722 + .length = 4 + 1, /* length 'okay' + 1 */
8726 +static int snd_rpi_hifiberry_dacplus_probe(struct platform_device *pdev)
8729 + struct snd_soc_card *card = &snd_rpi_hifiberry_dacplus;
8731 + struct device_node *tpa_node;
8732 + struct property *tpa_prop;
8733 + struct of_changeset ocs;
8734 + struct property *pp;
8737 + /* probe for head phone amp */
8738 + ret = hb_hp_detect();
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);
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);
8755 + dev_err(&pdev->dev,
8756 + "cannot activate headphone amplifier\n");
8759 + ret = of_changeset_apply(&ocs);
8761 + dev_err(&pdev->dev,
8762 + "cannot activate headphone amplifier\n");
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;
8773 + dai = &snd_rpi_hifiberry_dacplus_dai[0];
8774 + i2s_node = of_parse_phandle(pdev->dev.of_node,
8775 + "i2s-controller", 0);
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;
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");
8794 + * check for HW MUTE as defined in DT-overlay
8795 + * active high, therefore default to HIGH to MUTE
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);
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);
8808 + if (!of_property_read_u32(pdev->dev.of_node,
8809 + "hifiberry-dacplus,mute_ext_ctl", &mute_ext)) {
8810 + /* ALSA control will be used */
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);
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);
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));
8841 +static const struct of_device_id snd_rpi_hifiberry_dacplus_of_match[] = {
8842 + { .compatible = "hifiberry,hifiberry-dacplus", },
8845 +MODULE_DEVICE_TABLE(of, snd_rpi_hifiberry_dacplus_of_match);
8847 +static struct platform_driver snd_rpi_hifiberry_dacplus_driver = {
8849 + .name = "snd-rpi-hifiberry-dacplus",
8850 + .owner = THIS_MODULE,
8851 + .of_match_table = snd_rpi_hifiberry_dacplus_of_match,
8853 + .probe = snd_rpi_hifiberry_dacplus_probe,
8856 +module_platform_driver(snd_rpi_hifiberry_dacplus_driver);
8858 +MODULE_AUTHOR("Daniel Matuschek <daniel@hifiberry.com>");
8859 +MODULE_DESCRIPTION("ASoC Driver for HiFiBerry DAC+");
8860 +MODULE_LICENSE("GPL v2");
8862 +++ b/sound/soc/bcm/hifiberry_dacplusadc.c
8865 + * ASoC Driver for HiFiBerry DAC+ / DAC Pro with ADC
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>
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.
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.
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>
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>
8899 +#include "../codecs/pcm512x.h"
8901 +#define HIFIBERRY_DACPRO_NOCLOCK 0
8902 +#define HIFIBERRY_DACPRO_CLK44EN 1
8903 +#define HIFIBERRY_DACPRO_CLK48EN 2
8905 +struct platform_device *dmic_codec_dev;
8907 +struct pcm512x_priv {
8908 + struct regmap *regmap;
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
8918 +static bool snd_rpi_hifiberry_is_dacpro;
8919 +static bool digital_gain_0db_limit = true;
8920 +static bool leds_off;
8922 +static void snd_rpi_hifiberry_dacplusadc_select_clk(struct snd_soc_component *component,
8926 + case HIFIBERRY_DACPRO_NOCLOCK:
8927 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x24, 0x00);
8929 + case HIFIBERRY_DACPRO_CLK44EN:
8930 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x24, 0x20);
8932 + case HIFIBERRY_DACPRO_CLK48EN:
8933 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x24, 0x04);
8938 +static void snd_rpi_hifiberry_dacplusadc_clk_gpio(struct snd_soc_component *component)
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);
8945 +static bool snd_rpi_hifiberry_dacplusadc_is_sclk(struct snd_soc_component *component)
8949 + sck = snd_soc_component_read(component, PCM512x_RATE_DET_4);
8950 + return (!(sck & 0x40));
8953 +static bool snd_rpi_hifiberry_dacplusadc_is_sclk_sleep(
8954 + struct snd_soc_component *component)
8957 + return snd_rpi_hifiberry_dacplusadc_is_sclk(component);
8960 +static bool snd_rpi_hifiberry_dacplusadc_is_pro_card(struct snd_soc_component *component)
8962 + bool isClk44EN, isClk48En, isNoClk;
8964 + snd_rpi_hifiberry_dacplusadc_clk_gpio(component);
8966 + snd_rpi_hifiberry_dacplusadc_select_clk(component, HIFIBERRY_DACPRO_CLK44EN);
8967 + isClk44EN = snd_rpi_hifiberry_dacplusadc_is_sclk_sleep(component);
8969 + snd_rpi_hifiberry_dacplusadc_select_clk(component, HIFIBERRY_DACPRO_NOCLOCK);
8970 + isNoClk = snd_rpi_hifiberry_dacplusadc_is_sclk_sleep(component);
8972 + snd_rpi_hifiberry_dacplusadc_select_clk(component, HIFIBERRY_DACPRO_CLK48EN);
8973 + isClk48En = snd_rpi_hifiberry_dacplusadc_is_sclk_sleep(component);
8975 + return (isClk44EN && isClk48En && !isNoClk);
8978 +static int snd_rpi_hifiberry_dacplusadc_clk_for_rate(int sample_rate)
8982 + switch (sample_rate) {
8989 + type = HIFIBERRY_DACPRO_CLK44EN;
8992 + type = HIFIBERRY_DACPRO_CLK48EN;
8998 +static void snd_rpi_hifiberry_dacplusadc_set_sclk(struct snd_soc_component *component,
9001 + struct pcm512x_priv *pcm512x = snd_soc_component_get_drvdata(component);
9003 + if (!IS_ERR(pcm512x->sclk)) {
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);
9013 +static int snd_rpi_hifiberry_dacplusadc_init(struct snd_soc_pcm_runtime *rtd)
9015 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
9016 + struct pcm512x_priv *priv;
9019 + snd_rpi_hifiberry_is_dacpro = false;
9021 + snd_rpi_hifiberry_is_dacpro =
9022 + snd_rpi_hifiberry_dacplusadc_is_pro_card(component);
9024 + if (snd_rpi_hifiberry_is_dacpro) {
9025 + struct snd_soc_dai_link *dai = rtd->dai_link;
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;
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);
9036 + priv = snd_soc_component_get_drvdata(component);
9037 + priv->sclk = ERR_PTR(-ENOENT);
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);
9043 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x08, 0x00);
9045 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x08, 0x08);
9047 + if (digital_gain_0db_limit) {
9049 + struct snd_soc_card *card = rtd->card;
9051 + ret = snd_soc_limit_volume(card, "Digital Playback Volume", 207);
9053 + dev_warn(card->dev, "Failed to set volume limit: %d\n", ret);
9059 +static int snd_rpi_hifiberry_dacplusadc_update_rate_den(
9060 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
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;
9069 + rats_no_pll = devm_kzalloc(rtd->dev, sizeof(*rats_no_pll), GFP_KERNEL);
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;
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;
9085 + devm_kfree(rtd->dev, rats_no_pll);
9089 +static int snd_rpi_hifiberry_dacplusadc_hw_params(
9090 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
9093 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
9094 + int channels = params_channels(params);
9097 + if (snd_rpi_hifiberry_is_dacpro) {
9098 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
9100 + width = snd_pcm_format_physical_width(params_format(params));
9102 + snd_rpi_hifiberry_dacplusadc_set_sclk(component,
9103 + params_rate(params));
9105 + ret = snd_rpi_hifiberry_dacplusadc_update_rate_den(
9106 + substream, params);
9109 + ret = snd_soc_dai_set_bclk_ratio(asoc_rtd_to_cpu(rtd, 0), channels * width);
9112 + ret = snd_soc_dai_set_bclk_ratio(asoc_rtd_to_codec(rtd, 0), channels * width);
9116 +static int hifiberry_dacplusadc_LED_cnt;
9118 +static int snd_rpi_hifiberry_dacplusadc_startup(
9119 + struct snd_pcm_substream *substream)
9121 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
9122 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
9126 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1,
9128 + hifiberry_dacplusadc_LED_cnt++;
9132 +static void snd_rpi_hifiberry_dacplusadc_shutdown(
9133 + struct snd_pcm_substream *substream)
9135 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
9136 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
9138 + hifiberry_dacplusadc_LED_cnt--;
9139 + if (!hifiberry_dacplusadc_LED_cnt)
9140 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1,
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,
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")));
9157 +static struct snd_soc_dai_link snd_rpi_hifiberry_dacplusadc_dai[] = {
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),
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),
9179 +static int snd_rpi_hifiberry_dacplusadc_probe(struct platform_device *pdev)
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;
9188 + dai = &snd_rpi_hifiberry_dacplusadc_dai[0];
9189 + i2s_node = of_parse_phandle(pdev->dev.of_node,
9190 + "i2s-controller", 0);
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;
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");
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);
9214 +static const struct of_device_id snd_rpi_hifiberry_dacplusadc_of_match[] = {
9215 + { .compatible = "hifiberry,hifiberry-dacplusadc", },
9219 +MODULE_DEVICE_TABLE(of, snd_rpi_hifiberry_dacplusadc_of_match);
9221 +static struct platform_driver snd_rpi_hifiberry_dacplusadc_driver = {
9223 + .name = "snd-rpi-hifiberry-dacplusadc",
9224 + .owner = THIS_MODULE,
9225 + .of_match_table = snd_rpi_hifiberry_dacplusadc_of_match,
9227 + .probe = snd_rpi_hifiberry_dacplusadc_probe,
9230 +static int __init hifiberry_dacplusadc_init(void)
9234 + dmic_codec_dev = platform_device_register_simple("dmic-codec", -1, NULL,
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);
9241 + ret = platform_driver_register(&snd_rpi_hifiberry_dacplusadc_driver);
9243 + pr_err("%s: platform driver registration failed\n", __func__);
9244 + platform_device_unregister(dmic_codec_dev);
9249 +module_init(hifiberry_dacplusadc_init);
9251 +static void __exit hifiberry_dacplusadc_exit(void)
9253 + platform_driver_unregister(&snd_rpi_hifiberry_dacplusadc_driver);
9254 + platform_device_unregister(dmic_codec_dev);
9256 +module_exit(hifiberry_dacplusadc_exit);
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");
9263 +++ b/sound/soc/bcm/hifiberry_dacplusadcpro.c
9266 + * ASoC Driver for HiFiBerry DAC+ / DAC Pro with ADC PRO Version (SW control)
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
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.
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.
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>
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>
9302 +#include "../codecs/pcm512x.h"
9303 +#include "../codecs/pcm186x.h"
9305 +#define HIFIBERRY_DACPRO_NOCLOCK 0
9306 +#define HIFIBERRY_DACPRO_CLK44EN 1
9307 +#define HIFIBERRY_DACPRO_CLK48EN 2
9309 +struct pcm512x_priv {
9310 + struct regmap *regmap;
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
9320 +static bool snd_rpi_hifiberry_is_dacpro;
9321 +static bool digital_gain_0db_limit = true;
9322 +static bool leds_off;
9324 +static const unsigned int pcm186x_adc_input_channel_sel_value[] = {
9325 + 0x00, 0x01, 0x02, 0x03, 0x10
9328 +static const char * const pcm186x_adcl_input_channel_sel_text[] = {
9330 + "VINL1[SE]", /* Default for ADCL */
9332 + "VINL2[SE] + VINL1[SE]",
9333 + "{VIN1P, VIN1M}[DIFF]"
9336 +static const char * const pcm186x_adcr_input_channel_sel_text[] = {
9338 + "VINR1[SE]", /* Default for ADCR */
9340 + "VINR2[SE] + VINR1[SE]",
9341 + "{VIN2P, VIN2M}[DIFF]"
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),
9357 +static const unsigned int pcm186x_mic_bias_sel_value[] = {
9361 +static const char * const pcm186x_mic_bias_sel_text[] = {
9364 + "Mic Bias with Bypass Resistor"
9367 +static const struct soc_enum pcm186x_mic_bias_sel[] = {
9368 + SOC_VALUE_ENUM_SINGLE(PCM186X_MIC_BIAS_CTRL, 0,
9370 + ARRAY_SIZE(pcm186x_mic_bias_sel_text),
9371 + pcm186x_mic_bias_sel_text,
9372 + pcm186x_mic_bias_sel_value),
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,
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"};
9412 +static const struct soc_enum pcm186x_gain_sel[] = {
9413 + SOC_VALUE_ENUM_SINGLE(PCM186X_PGA_VAL_CH1_L, 0,
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,
9420 + ARRAY_SIZE(pcm186x_gain_sel_text),
9421 + pcm186x_gain_sel_text,
9422 + pcm186x_gain_sel_value),
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]),
9433 +static int pcm1863_add_controls(struct snd_soc_component *component)
9435 + snd_soc_add_component_controls(component,
9436 + pcm1863_snd_controls_card,
9437 + ARRAY_SIZE(pcm1863_snd_controls_card));
9441 +static void snd_rpi_hifiberry_dacplusadcpro_select_clk(
9442 + struct snd_soc_component *component, int clk_id)
9445 + case HIFIBERRY_DACPRO_NOCLOCK:
9446 + snd_soc_component_update_bits(component,
9447 + PCM512x_GPIO_CONTROL_1, 0x24, 0x00);
9449 + case HIFIBERRY_DACPRO_CLK44EN:
9450 + snd_soc_component_update_bits(component,
9451 + PCM512x_GPIO_CONTROL_1, 0x24, 0x20);
9453 + case HIFIBERRY_DACPRO_CLK48EN:
9454 + snd_soc_component_update_bits(component,
9455 + PCM512x_GPIO_CONTROL_1, 0x24, 0x04);
9458 + usleep_range(3000, 4000);
9461 +static void snd_rpi_hifiberry_dacplusadcpro_clk_gpio(struct snd_soc_component *component)
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);
9468 +static bool snd_rpi_hifiberry_dacplusadcpro_is_sclk(struct snd_soc_component *component)
9472 + sck = snd_soc_component_read(component, PCM512x_RATE_DET_4);
9473 + return (!(sck & 0x40));
9476 +static bool snd_rpi_hifiberry_dacplusadcpro_is_pro_card(struct snd_soc_component *component)
9478 + bool isClk44EN, isClk48En, isNoClk;
9480 + snd_rpi_hifiberry_dacplusadcpro_clk_gpio(component);
9482 + snd_rpi_hifiberry_dacplusadcpro_select_clk(component, HIFIBERRY_DACPRO_CLK44EN);
9483 + isClk44EN = snd_rpi_hifiberry_dacplusadcpro_is_sclk(component);
9485 + snd_rpi_hifiberry_dacplusadcpro_select_clk(component, HIFIBERRY_DACPRO_NOCLOCK);
9486 + isNoClk = snd_rpi_hifiberry_dacplusadcpro_is_sclk(component);
9488 + snd_rpi_hifiberry_dacplusadcpro_select_clk(component, HIFIBERRY_DACPRO_CLK48EN);
9489 + isClk48En = snd_rpi_hifiberry_dacplusadcpro_is_sclk(component);
9491 + return (isClk44EN && isClk48En && !isNoClk);
9494 +static int snd_rpi_hifiberry_dacplusadcpro_clk_for_rate(int sample_rate)
9498 + switch (sample_rate) {
9505 + type = HIFIBERRY_DACPRO_CLK44EN;
9508 + type = HIFIBERRY_DACPRO_CLK48EN;
9514 +static void snd_rpi_hifiberry_dacplusadcpro_set_sclk(struct snd_soc_component *component,
9517 + struct pcm512x_priv *pcm512x = snd_soc_component_get_drvdata(component);
9519 + if (!IS_ERR(pcm512x->sclk)) {
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);
9529 +static int snd_rpi_hifiberry_dacplusadcpro_init(struct snd_soc_pcm_runtime *rtd)
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;
9538 + snd_rpi_hifiberry_is_dacpro = false;
9540 + snd_rpi_hifiberry_is_dacpro =
9541 + snd_rpi_hifiberry_dacplusadcpro_is_pro_card(dac);
9543 + if (snd_rpi_hifiberry_is_dacpro) {
9544 + struct snd_soc_dai_link *dai = rtd->dai_link;
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;
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);
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);
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);
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);
9575 + priv = snd_soc_component_get_drvdata(dac);
9576 + priv->sclk = ERR_PTR(-ENOENT);
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;
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);
9585 + snd_soc_component_update_bits(dac, PCM512x_GPIO_CONTROL_1, 0x08, 0x00);
9587 + snd_soc_component_update_bits(dac, PCM512x_GPIO_CONTROL_1, 0x08, 0x08);
9589 + ret = pcm1863_add_controls(adc);
9591 + dev_warn(rtd->dev, "Failed to add pcm1863 controls: %d\n",
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);
9598 + snd_soc_component_update_bits(adc, PCM186X_GPIO_IN_OUT, 0x40, 0x00);
9600 + snd_soc_component_update_bits(adc, PCM186X_GPIO_IN_OUT, 0x40, 0x40);
9602 + if (digital_gain_0db_limit) {
9604 + struct snd_soc_card *card = rtd->card;
9606 + ret = snd_soc_limit_volume(card, "Digital Playback Volume", 207);
9608 + dev_warn(card->dev, "Failed to set volume limit: %d\n", ret);
9614 +static int snd_rpi_hifiberry_dacplusadcpro_update_rate_den(
9615 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
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;
9624 + rats_no_pll = devm_kzalloc(rtd->dev, sizeof(*rats_no_pll), GFP_KERNEL);
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;
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;
9640 + devm_kfree(rtd->dev, rats_no_pll);
9644 +static int snd_rpi_hifiberry_dacplusadcpro_hw_params(
9645 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
9648 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
9649 + int channels = params_channels(params);
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;
9656 + if (snd_rpi_hifiberry_is_dacpro) {
9657 + width = snd_pcm_format_physical_width(params_format(params));
9659 + snd_rpi_hifiberry_dacplusadcpro_set_sclk(dac,
9660 + params_rate(params));
9662 + ret = snd_rpi_hifiberry_dacplusadcpro_update_rate_den(
9663 + substream, params);
9668 + ret = snd_soc_dai_set_bclk_ratio(asoc_rtd_to_cpu(rtd, 0), channels * width);
9671 + ret = snd_soc_dai_set_bclk_ratio(asoc_rtd_to_codec(rtd, 0), channels * width);
9674 + if (snd_rpi_hifiberry_is_dacpro && ops->hw_params)
9675 + ret = ops->hw_params(substream, params, dai);
9679 +static int snd_rpi_hifiberry_dacplusadcpro_startup(
9680 + struct snd_pcm_substream *substream)
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;
9688 + /* switch on respective LED */
9689 + if (!substream->stream)
9690 + snd_soc_component_update_bits(dac, PCM512x_GPIO_CONTROL_1, 0x08, 0x08);
9692 + snd_soc_component_update_bits(adc, PCM186X_GPIO_IN_OUT, 0x40, 0x40);
9696 +static void snd_rpi_hifiberry_dacplusadcpro_shutdown(
9697 + struct snd_pcm_substream *substream)
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;
9703 + /* switch off respective LED */
9704 + if (!substream->stream)
9705 + snd_soc_component_update_bits(dac, PCM512x_GPIO_CONTROL_1, 0x08, 0x00);
9707 + snd_soc_component_update_bits(adc, PCM186X_GPIO_IN_OUT, 0x40, 0x00);
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,
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")));
9724 +static struct snd_soc_dai_link snd_rpi_hifiberry_dacplusadcpro_dai[] = {
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),
9736 +/* aux device for optional headphone amp */
9737 +static struct snd_soc_aux_dev hifiberry_dacplusadcpro_aux_devs[] = {
9740 + .name = "tpa6130a2.1-0060",
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),
9754 +static int hb_hp_detect(void)
9756 + struct i2c_adapter *adap = i2c_get_adapter(1);
9758 + struct i2c_client tpa_i2c_client = {
9764 + return -EPROBE_DEFER; /* I2C module not yet available */
9766 + ret = i2c_smbus_read_byte(&tpa_i2c_client) >= 0;
9767 + i2c_put_adapter(adap);
9771 +static struct property tpa_enable_prop = {
9773 + .length = 4 + 1, /* length 'okay' + 1 */
9777 +static int snd_rpi_hifiberry_dacplusadcpro_probe(struct platform_device *pdev)
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;
9786 + /* probe for head phone amp */
9787 + ret = hb_hp_detect();
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);
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);
9804 + dev_err(&pdev->dev,
9805 + "cannot activate headphone amplifier\n");
9808 + ret = of_changeset_apply(&ocs);
9810 + dev_err(&pdev->dev,
9811 + "cannot activate headphone amplifier\n");
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;
9822 + dai = &snd_rpi_hifiberry_dacplusadcpro_dai[0];
9823 + i2s_node = of_parse_phandle(pdev->dev.of_node,
9824 + "i2s-controller", 0);
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;
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);
9848 +static const struct of_device_id snd_rpi_hifiberry_dacplusadcpro_of_match[] = {
9849 + { .compatible = "hifiberry,hifiberry-dacplusadcpro", },
9853 +MODULE_DEVICE_TABLE(of, snd_rpi_hifiberry_dacplusadcpro_of_match);
9855 +static struct platform_driver snd_rpi_hifiberry_dacplusadcpro_driver = {
9857 + .name = "snd-rpi-hifiberry-dacplusadcpro",
9858 + .owner = THIS_MODULE,
9859 + .of_match_table = snd_rpi_hifiberry_dacplusadcpro_of_match,
9861 + .probe = snd_rpi_hifiberry_dacplusadcpro_probe,
9864 +module_platform_driver(snd_rpi_hifiberry_dacplusadcpro_driver);
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");
9871 +++ b/sound/soc/bcm/hifiberry_dacplusdsp.c
9873 +// SPDX-License-Identifier: GPL-2.0
9875 + * ASoC Driver for HiFiBerry DAC + DSP
9877 + * Author: Joerg Schambacher <joscha@schambacher.com>
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.
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.
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>
9896 +static struct snd_soc_component_driver dacplusdsp_component_driver;
9898 +static struct snd_soc_dai_driver dacplusdsp_dai = {
9899 + .name = "dacplusdsp-hifi",
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,
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,
9918 + .symmetric_rate = 1};
9921 +static const struct of_device_id dacplusdsp_ids[] = {
9923 + .compatible = "hifiberry,dacplusdsp",
9926 +MODULE_DEVICE_TABLE(of, dacplusdsp_ids);
9929 +static int dacplusdsp_platform_probe(struct platform_device *pdev)
9933 + ret = snd_soc_register_component(&pdev->dev,
9934 + &dacplusdsp_component_driver, &dacplusdsp_dai, 1);
9936 + pr_alert("snd_soc_register_component failed\n");
9943 +static int dacplusdsp_platform_remove(struct platform_device *pdev)
9945 + snd_soc_unregister_component(&pdev->dev);
9949 +static struct platform_driver dacplusdsp_driver = {
9951 + .name = "hifiberry-dacplusdsp-codec",
9952 + .of_match_table = of_match_ptr(dacplusdsp_ids),
9954 + .probe = dacplusdsp_platform_probe,
9955 + .remove = dacplusdsp_platform_remove,
9958 +module_platform_driver(dacplusdsp_driver);
9960 +MODULE_AUTHOR("Joerg Schambacher <joerg@i2audio.com>");
9961 +MODULE_DESCRIPTION("ASoC Driver for HiFiBerry DAC+DSP");
9962 +MODULE_LICENSE("GPL v2");
9964 +++ b/sound/soc/bcm/hifiberry_dacplushd.c
9966 +// SPDX-License-Identifier: GPL-2.0
9968 + * ASoC Driver for HiFiBerry DAC+ HD
9970 + * Author: Joerg Schambacher, i2Audio GmbH for HiFiBerry
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.
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.
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>
9999 +#include "../codecs/pcm179x.h"
10001 +#define DEFAULT_RATE 44100
10003 +struct brd_drv_data {
10004 + struct regmap *regmap;
10005 + struct clk *sclk;
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,
10014 +static struct snd_pcm_hw_constraint_list hb_dacplushd_constraints = {
10015 + .list = hb_dacplushd_rates,
10016 + .count = ARRAY_SIZE(hb_dacplushd_rates),
10019 +static int snd_rpi_hb_dacplushd_startup(struct snd_pcm_substream *substream)
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);
10028 +static void snd_rpi_hifiberry_dacplushd_set_sclk(
10029 + struct snd_soc_component *component,
10032 + if (!IS_ERR(drvdata.sclk))
10033 + clk_set_rate(drvdata.sclk, sample_rate);
10036 +static int snd_rpi_hifiberry_dacplushd_init(struct snd_soc_pcm_runtime *rtd)
10038 + struct snd_soc_dai_link *dai = rtd->dai_link;
10039 + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
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;
10046 + /* allow only fixed 32 clock counts per channel */
10047 + snd_soc_dai_set_bclk_ratio(cpu_dai, 32*2);
10052 +static int snd_rpi_hifiberry_dacplushd_hw_params(
10053 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
10056 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
10058 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
10060 + snd_rpi_hifiberry_dacplushd_set_sclk(component, params_rate(params));
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,
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")));
10076 +static struct snd_soc_dai_link snd_rpi_hifiberry_dacplushd_dai[] = {
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),
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),
10097 +static int snd_rpi_hifiberry_dacplushd_probe(struct platform_device *pdev)
10100 + static int dac_reset_done;
10101 + struct device *dev = &pdev->dev;
10102 + struct device_node *dev_node = dev->of_node;
10104 + snd_rpi_hifiberry_dacplushd.dev = &pdev->dev;
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");
10113 + dac_reset_done = 1;
10115 + if (!IS_ERR(reset_gpio))
10116 + gpiod_set_value(reset_gpio, 0);
10118 + if (!IS_ERR(reset_gpio))
10119 + gpiod_set_value(reset_gpio, 1);
10121 + if (!IS_ERR(reset_gpio))
10122 + gpiod_set_value(reset_gpio, 0);
10124 + if (pdev->dev.of_node) {
10125 + struct device_node *i2s_node;
10126 + struct snd_soc_dai_link *dai;
10128 + dai = &snd_rpi_hifiberry_dacplushd_dai[0];
10129 + i2s_node = of_parse_phandle(pdev->dev.of_node,
10130 + "i2s-controller", 0);
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;
10138 + return -EPROBE_DEFER;
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);
10150 + if (ret == -EPROBE_DEFER)
10153 + dev_set_drvdata(dev, &drvdata);
10154 + if (dev_node == NULL) {
10155 + dev_err(&pdev->dev, "Device tree node not found\n");
10159 + drvdata.sclk = devm_clk_get(dev, NULL);
10160 + if (IS_ERR(drvdata.sclk)) {
10161 + drvdata.sclk = ERR_PTR(-ENOENT);
10165 + clk_set_rate(drvdata.sclk, DEFAULT_RATE);
10170 +static int snd_rpi_hifiberry_dacplushd_remove(struct platform_device *pdev)
10172 + if (IS_ERR(reset_gpio))
10175 + /* put DAC into RESET and release GPIO */
10176 + gpiod_set_value(reset_gpio, 0);
10177 + gpiod_put(reset_gpio);
10182 +static const struct of_device_id snd_rpi_hifiberry_dacplushd_of_match[] = {
10183 + { .compatible = "hifiberry,hifiberry-dacplushd", },
10187 +MODULE_DEVICE_TABLE(of, snd_rpi_hifiberry_dacplushd_of_match);
10189 +static struct platform_driver snd_rpi_hifiberry_dacplushd_driver = {
10191 + .name = "snd-rpi-hifiberry-dacplushd",
10192 + .owner = THIS_MODULE,
10193 + .of_match_table = snd_rpi_hifiberry_dacplushd_of_match,
10195 + .probe = snd_rpi_hifiberry_dacplushd_probe,
10196 + .remove = snd_rpi_hifiberry_dacplushd_remove,
10199 +module_platform_driver(snd_rpi_hifiberry_dacplushd_driver);
10201 +MODULE_AUTHOR("Joerg Schambacher <joerg@i2audio.com>");
10202 +MODULE_DESCRIPTION("ASoC Driver for HiFiBerry DAC+ HD");
10203 +MODULE_LICENSE("GPL v2");
10205 +++ b/sound/soc/bcm/i-sabre-q2m.c
10208 + * ASoC Driver for I-Sabre Q2M
10210 + * Author: Satoru Kawase
10211 + * Modified by: Xiao Qingyong
10212 + * Update kernel v4.18+ by : Audiophonics
10213 + * Copyright 2018 Audiophonics
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.
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.
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>
10236 +#include "../codecs/i-sabre-codec.h"
10239 +static int snd_rpi_i_sabre_q2m_init(struct snd_soc_pcm_runtime *rtd)
10241 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
10242 + unsigned int value;
10245 + value = snd_soc_component_read(component, ISABRECODEC_REG_01);
10246 + dev_info(component->card->dev, "Audiophonics Device ID : %02X\n", value);
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);
10255 +static int snd_rpi_i_sabre_q2m_hw_params(
10256 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
10258 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
10259 + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
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);
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,
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")));
10277 +static struct snd_soc_dai_link snd_rpi_i_sabre_q2m_dai[] = {
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),
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)
10298 +static int snd_rpi_i_sabre_q2m_probe(struct platform_device *pdev)
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;
10307 + dai = &snd_rpi_i_sabre_q2m_dai[0];
10308 + i2s_node = of_parse_phandle(pdev->dev.of_node,
10309 + "i2s-controller", 0);
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;
10316 + dev_err(&pdev->dev,
10317 + "Property 'i2s-controller' missing or invalid\n");
10318 + return (-EINVAL);
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;
10328 + /* Wait for registering codec driver */
10331 + ret = snd_soc_register_card(&snd_rpi_i_sabre_q2m);
10333 + dev_err(&pdev->dev,
10334 + "snd_soc_register_card() failed: %d\n", ret);
10340 +static int snd_rpi_i_sabre_q2m_remove(struct platform_device *pdev)
10342 + snd_soc_unregister_card(&snd_rpi_i_sabre_q2m);
10346 +static const struct of_device_id snd_rpi_i_sabre_q2m_of_match[] = {
10347 + { .compatible = "audiophonics,i-sabre-q2m", },
10350 +MODULE_DEVICE_TABLE(of, snd_rpi_i_sabre_q2m_of_match);
10352 +static struct platform_driver snd_rpi_i_sabre_q2m_driver = {
10354 + .name = "snd-rpi-i-sabre-q2m",
10355 + .owner = THIS_MODULE,
10356 + .of_match_table = snd_rpi_i_sabre_q2m_of_match,
10358 + .probe = snd_rpi_i_sabre_q2m_probe,
10359 + .remove = snd_rpi_i_sabre_q2m_remove,
10361 +module_platform_driver(snd_rpi_i_sabre_q2m_driver);
10363 +MODULE_DESCRIPTION("ASoC Driver for I-Sabre Q2M");
10364 +MODULE_AUTHOR("Audiophonics <http://www.audiophonics.fr>");
10365 +MODULE_LICENSE("GPL");
10367 +++ b/sound/soc/bcm/iqaudio-codec.c
10370 + * ASoC Driver for IQaudIO Raspberry Pi Codec board
10372 + * Author: Gordon Garrity <gordon@iqaudio.com>
10373 + * (C) Copyright IQaudio Limited, 2017-2019
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.
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.
10385 +#include <linux/module.h>
10386 +#include <linux/gpio/consumer.h>
10387 +#include <linux/platform_device.h>
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>
10395 +#include <linux/acpi.h>
10396 +#include <linux/slab.h>
10397 +#include "../codecs/da7213.h"
10399 +static int pll_out = DA7213_PLL_FREQ_OUT_90316800;
10401 +static int snd_rpi_iqaudio_pll_control(struct snd_soc_dapm_widget *w,
10402 + struct snd_kcontrol *k, int event)
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);
10411 + if (SND_SOC_DAPM_EVENT_OFF(event)) {
10412 + ret = snd_soc_dai_set_pll(codec_dai, 0, DA7213_SYSCLK_MCLK, 0,
10415 + dev_err(card->dev, "Failed to bypass PLL: %d\n", ret);
10416 + /* Allow PLL time to bypass */
10418 + } else if (SND_SOC_DAPM_EVENT_ON(event)) {
10419 + ret = snd_soc_dai_set_pll(codec_dai, 0, DA7213_SYSCLK_PLL, 0,
10422 + dev_err(card->dev, "Failed to enable PLL: %d\n", ret);
10423 + /* Allow PLL time to lock */
10430 +static int snd_rpi_iqaudio_post_dapm_event(struct snd_soc_dapm_widget *w,
10431 + struct snd_kcontrol *kcontrol,
10435 + case SND_SOC_DAPM_POST_PMU:
10436 + /* Delay for mic bias ramp */
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"),
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),
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"},
10469 + {"AUXR", NULL, "AUX Jack"},
10470 + {"AUXL", NULL, "AUX Jack"},
10471 + {"AUX Jack", NULL, "PLL Control"},
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"},
10480 +/* machine stream operations */
10482 +static int snd_rpi_iqaudio_codec_init(struct snd_soc_pcm_runtime *rtd)
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);
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.
10493 + * This pin can still be enabled later, as required by user-space.
10495 + snd_soc_dapm_disable_pin(&rtd->card->dapm, "AUX Jack");
10496 + snd_soc_dapm_sync(&rtd->card->dapm);
10498 + /* Set bclk ratio to align with codec's BCLK rate */
10499 + ret = snd_soc_dai_set_bclk_ratio(cpu_dai, 64);
10501 + dev_err(rtd->dev, "Failed to set CPU BLCK ratio\n");
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);
10510 +static int snd_rpi_iqaudio_codec_hw_params(struct snd_pcm_substream *substream,
10511 + struct snd_pcm_hw_params *params)
10513 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
10514 + unsigned int samplerate = params_rate(params);
10516 + switch (samplerate) {
10522 + pll_out = DA7213_PLL_FREQ_OUT_98304000;
10526 + pll_out = DA7213_PLL_FREQ_OUT_90316800;
10529 + dev_err(rtd->dev,"Unsupported samplerate %d\n", samplerate);
10534 +static const struct snd_soc_ops snd_rpi_iqaudio_codec_ops = {
10535 + .hw_params = snd_rpi_iqaudio_codec_hw_params,
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")));
10543 +static struct snd_soc_dai_link snd_rpi_iqaudio_codec_dai[] = {
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),
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),
10569 +static int snd_rpi_iqaudio_codec_probe(struct platform_device *pdev)
10573 + snd_rpi_iqaudio_codec.dev = &pdev->dev;
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];
10580 + i2s_node = of_parse_phandle(pdev->dev.of_node,
10581 + "i2s-controller", 0);
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;
10589 + if (of_property_read_string(pdev->dev.of_node, "card_name",
10591 + card->name = "IQaudIOCODEC";
10593 + if (of_property_read_string(pdev->dev.of_node, "dai_name",
10595 + dai->name = "IQaudIO CODEC";
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";
10603 + ret = snd_soc_register_card(&snd_rpi_iqaudio_codec);
10605 + if (ret != -EPROBE_DEFER)
10606 + dev_err(&pdev->dev,
10607 + "snd_soc_register_card() failed: %d\n", ret);
10614 +static int snd_rpi_iqaudio_codec_remove(struct platform_device *pdev)
10616 + snd_soc_unregister_card(&snd_rpi_iqaudio_codec);
10620 +static const struct of_device_id iqaudio_of_match[] = {
10621 + { .compatible = "iqaudio,iqaudio-codec", },
10625 +MODULE_DEVICE_TABLE(of, iqaudio_of_match);
10627 +static struct platform_driver snd_rpi_iqaudio_codec_driver = {
10629 + .name = "snd-rpi-iqaudio-codec",
10630 + .owner = THIS_MODULE,
10631 + .of_match_table = iqaudio_of_match,
10633 + .probe = snd_rpi_iqaudio_codec_probe,
10634 + .remove = snd_rpi_iqaudio_codec_remove,
10639 +module_platform_driver(snd_rpi_iqaudio_codec_driver);
10641 +MODULE_AUTHOR("Gordon Garrity <gordon@iqaudio.com>");
10642 +MODULE_DESCRIPTION("ASoC Driver for IQaudIO CODEC");
10643 +MODULE_LICENSE("GPL v2");
10645 +++ b/sound/soc/bcm/iqaudio-dac.c
10648 + * ASoC Driver for IQaudIO DAC
10650 + * Author: Florian Meier <florian.meier@koalo.de>
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.
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.
10663 +#include <linux/module.h>
10664 +#include <linux/gpio/consumer.h>
10665 +#include <linux/platform_device.h>
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>
10673 +static bool digital_gain_0db_limit = true;
10675 +static struct gpio_desc *mute_gpio;
10677 +static int snd_rpi_iqaudio_dac_init(struct snd_soc_pcm_runtime *rtd)
10679 + if (digital_gain_0db_limit)
10682 + struct snd_soc_card *card = rtd->card;
10684 + ret = snd_soc_limit_volume(card, "Digital Playback Volume", 207);
10686 + dev_warn(card->dev, "Failed to set volume limit: %d\n", ret);
10692 +static void snd_rpi_iqaudio_gpio_mute(struct snd_soc_card *card)
10695 + dev_info(card->dev, "%s: muting amp using GPIO22\n",
10697 + gpiod_set_value_cansleep(mute_gpio, 0);
10701 +static void snd_rpi_iqaudio_gpio_unmute(struct snd_soc_card *card)
10704 + dev_info(card->dev, "%s: un-muting amp using GPIO22\n",
10706 + gpiod_set_value_cansleep(mute_gpio, 1);
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)
10713 + struct snd_soc_pcm_runtime *rtd;
10714 + struct snd_soc_dai *codec_dai;
10716 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
10717 + codec_dai = asoc_rtd_to_codec(rtd, 0);
10719 + if (dapm->dev != codec_dai->dev)
10723 + case SND_SOC_BIAS_PREPARE:
10724 + if (dapm->bias_level != SND_SOC_BIAS_STANDBY)
10728 + snd_rpi_iqaudio_gpio_unmute(card);
10731 + case SND_SOC_BIAS_STANDBY:
10732 + if (dapm->bias_level != SND_SOC_BIAS_PREPARE)
10736 + snd_rpi_iqaudio_gpio_mute(card);
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")));
10751 +static struct snd_soc_dai_link snd_rpi_iqaudio_dac_dai[] = {
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),
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),
10767 +static int snd_rpi_iqaudio_dac_probe(struct platform_device *pdev)
10770 + bool gpio_unmute = false;
10772 + snd_rpi_iqaudio_dac.dev = &pdev->dev;
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;
10780 + i2s_node = of_parse_phandle(pdev->dev.of_node,
10781 + "i2s-controller", 0);
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;
10789 + digital_gain_0db_limit = !of_property_read_bool(
10790 + pdev->dev.of_node, "iqaudio,24db_digital_gain");
10792 + if (of_property_read_string(pdev->dev.of_node, "card_name",
10794 + card->name = "IQaudIODAC";
10796 + if (of_property_read_string(pdev->dev.of_node, "dai_name",
10798 + dai->name = "IQaudIO DAC";
10800 + if (of_property_read_string(pdev->dev.of_node,
10801 + "dai_stream_name", &dai->stream_name))
10802 + dai->stream_name = "IQaudIO DAC HiFi";
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");
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");
10812 + if (auto_gpio_mute || gpio_unmute) {
10813 + mute_gpio = devm_gpiod_get_optional(&pdev->dev, "mute",
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);
10822 + if (auto_gpio_mute && mute_gpio)
10823 + snd_rpi_iqaudio_dac.set_bias_level =
10824 + snd_rpi_iqaudio_set_bias_level;
10828 + ret = snd_soc_register_card(&snd_rpi_iqaudio_dac);
10830 + if (ret != -EPROBE_DEFER)
10831 + dev_err(&pdev->dev,
10832 + "snd_soc_register_card() failed: %d\n", ret);
10836 + if (gpio_unmute && mute_gpio)
10837 + snd_rpi_iqaudio_gpio_unmute(&snd_rpi_iqaudio_dac);
10842 +static int snd_rpi_iqaudio_dac_remove(struct platform_device *pdev)
10844 + snd_rpi_iqaudio_gpio_mute(&snd_rpi_iqaudio_dac);
10846 + snd_soc_unregister_card(&snd_rpi_iqaudio_dac);
10850 +static const struct of_device_id iqaudio_of_match[] = {
10851 + { .compatible = "iqaudio,iqaudio-dac", },
10854 +MODULE_DEVICE_TABLE(of, iqaudio_of_match);
10856 +static struct platform_driver snd_rpi_iqaudio_dac_driver = {
10858 + .name = "snd-rpi-iqaudio-dac",
10859 + .owner = THIS_MODULE,
10860 + .of_match_table = iqaudio_of_match,
10862 + .probe = snd_rpi_iqaudio_dac_probe,
10863 + .remove = snd_rpi_iqaudio_dac_remove,
10866 +module_platform_driver(snd_rpi_iqaudio_dac_driver);
10868 +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
10869 +MODULE_DESCRIPTION("ASoC Driver for IQAudio DAC");
10870 +MODULE_LICENSE("GPL v2");
10872 +++ b/sound/soc/bcm/justboom-both.c
10874 +// SPDX-License-Identifier: GPL-2.0
10876 + * rpi--wm8804.c -- ALSA SoC Raspberry Pi soundcard.
10878 + * Authors: Johannes Krude <johannes@krude.de
10880 + * Driver for when connecting simultaneously justboom-digi and justboom-dac
10882 + * Based upon code from:
10883 + * justboom-digi.c
10884 + * by Milan Neskovic <info@justboom.co>
10886 + * by Milan Neskovic <info@justboom.co>
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.
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.
10898 +#include <linux/module.h>
10899 +#include <linux/platform_device.h>
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>
10907 +#include "../codecs/wm8804.h"
10908 +#include "../codecs/pcm512x.h"
10911 +static bool digital_gain_0db_limit = true;
10913 +static int snd_rpi_justboom_both_init(struct snd_soc_pcm_runtime *rtd)
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;
10918 + /* enable TX output */
10919 + snd_soc_component_update_bits(digi, WM8804_PWRDN, 0x4, 0x0);
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);
10925 + if (digital_gain_0db_limit) {
10927 + struct snd_soc_card *card = rtd->card;
10929 + ret = snd_soc_limit_volume(card, "Digital Playback Volume",
10932 + dev_warn(card->dev, "Failed to set volume limit: %d\n",
10939 +static int snd_rpi_justboom_both_hw_params(struct snd_pcm_substream *substream,
10940 + struct snd_pcm_hw_params *params)
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);
10947 + int sysclk = 27000000; /* This is fixed on this board */
10949 + long mclk_freq = 0;
10950 + int mclk_div = 1;
10951 + int sampling_freq = 1;
10955 + int samplerate = params_rate(params);
10957 + if (samplerate <= 96000) {
10958 + mclk_freq = samplerate*256;
10959 + mclk_div = WM8804_MCLKDIV_256FS;
10961 + mclk_freq = samplerate*128;
10962 + mclk_div = WM8804_MCLKDIV_128FS;
10965 + switch (samplerate) {
10967 + sampling_freq = 0x03;
10970 + sampling_freq = 0x00;
10973 + sampling_freq = 0x02;
10976 + sampling_freq = 0x08;
10979 + sampling_freq = 0x0a;
10982 + sampling_freq = 0x0c;
10985 + sampling_freq = 0x0e;
10988 + dev_err(rtd->card->dev,
10989 + "Failed to set WM8804 SYSCLK, unsupported samplerate %d\n",
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);
10996 + ret = snd_soc_dai_set_sysclk(codec_dai, WM8804_TX_CLKSRC_PLL,
10997 + sysclk, SND_SOC_CLOCK_OUT);
10999 + dev_err(rtd->card->dev,
11000 + "Failed to set WM8804 SYSCLK: %d\n", ret);
11004 + /* Enable TX output */
11005 + snd_soc_component_update_bits(digi, WM8804_PWRDN, 0x4, 0x0);
11008 + snd_soc_component_update_bits(digi, WM8804_PWRDN, 0x9, 0);
11010 + /* set sampling frequency status bits */
11011 + snd_soc_component_update_bits(digi, WM8804_SPDTX4, 0x0f, sampling_freq);
11013 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 64);
11016 +static int snd_rpi_justboom_both_startup(struct snd_pcm_substream *substream)
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;
11022 + /* turn on digital output */
11023 + snd_soc_component_update_bits(digi, WM8804_PWRDN, 0x3c, 0x00);
11025 + snd_soc_component_update_bits(dac, PCM512x_GPIO_CONTROL_1, 0x08, 0x08);
11030 +static void snd_rpi_justboom_both_shutdown(struct snd_pcm_substream *substream)
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;
11036 + snd_soc_component_update_bits(dac, PCM512x_GPIO_CONTROL_1, 0x08, 0x00);
11038 + /* turn off output */
11039 + snd_soc_component_update_bits(digi, WM8804_PWRDN, 0x3c, 0x3c);
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,
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")));
11055 +static struct snd_soc_dai_link snd_rpi_justboom_both_dai[] = {
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),
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),
11076 +static int snd_rpi_justboom_both_probe(struct platform_device *pdev)
11079 + struct snd_soc_card *card = &snd_rpi_justboom_both;
11081 + snd_rpi_justboom_both.dev = &pdev->dev;
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];
11087 + i2s_node = of_parse_phandle(pdev->dev.of_node,
11088 + "i2s-controller", 0);
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;
11101 + digital_gain_0db_limit = !of_property_read_bool(
11102 + pdev->dev.of_node, "justboom,24db_digital_gain");
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);
11114 +static int snd_rpi_justboom_both_remove(struct platform_device *pdev)
11116 + snd_soc_unregister_card(&snd_rpi_justboom_both);
11120 +static const struct of_device_id snd_rpi_justboom_both_of_match[] = {
11121 + { .compatible = "justboom,justboom-both", },
11124 +MODULE_DEVICE_TABLE(of, snd_rpi_justboom_both_of_match);
11126 +static struct platform_driver snd_rpi_justboom_both_driver = {
11128 + .name = "snd-rpi-justboom-both",
11129 + .owner = THIS_MODULE,
11130 + .of_match_table = snd_rpi_justboom_both_of_match,
11132 + .probe = snd_rpi_justboom_both_probe,
11133 + .remove = snd_rpi_justboom_both_remove,
11136 +module_platform_driver(snd_rpi_justboom_both_driver);
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");
11142 +++ b/sound/soc/bcm/justboom-dac.c
11145 + * ASoC Driver for JustBoom DAC Raspberry Pi HAT Sound Card
11147 + * Author: Milan Neskovic
11149 + * based on code by Daniel Matuschek <info@crazy-audio.com>
11150 + * based on code by Florian Meier <florian.meier@koalo.de>
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.
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.
11162 +#include <linux/module.h>
11163 +#include <linux/platform_device.h>
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>
11171 +#include "../codecs/pcm512x.h"
11173 +static bool digital_gain_0db_limit = true;
11175 +static int snd_rpi_justboom_dac_init(struct snd_soc_pcm_runtime *rtd)
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);
11182 + if (digital_gain_0db_limit)
11185 + struct snd_soc_card *card = rtd->card;
11187 + ret = snd_soc_limit_volume(card, "Digital Playback Volume", 207);
11189 + dev_warn(card->dev, "Failed to set volume limit: %d\n", ret);
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);
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);
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,
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")));
11219 +static struct snd_soc_dai_link snd_rpi_justboom_dac_dai[] = {
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),
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),
11240 +static int snd_rpi_justboom_dac_probe(struct platform_device *pdev)
11244 + snd_rpi_justboom_dac.dev = &pdev->dev;
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);
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;
11259 + digital_gain_0db_limit = !of_property_read_bool(
11260 + pdev->dev.of_node, "justboom,24db_digital_gain");
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);
11271 +static const struct of_device_id snd_rpi_justboom_dac_of_match[] = {
11272 + { .compatible = "justboom,justboom-dac", },
11275 +MODULE_DEVICE_TABLE(of, snd_rpi_justboom_dac_of_match);
11277 +static struct platform_driver snd_rpi_justboom_dac_driver = {
11279 + .name = "snd-rpi-justboom-dac",
11280 + .owner = THIS_MODULE,
11281 + .of_match_table = snd_rpi_justboom_dac_of_match,
11283 + .probe = snd_rpi_justboom_dac_probe,
11286 +module_platform_driver(snd_rpi_justboom_dac_driver);
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");
11292 +++ b/sound/soc/bcm/pifi-40.c
11294 +// SPDX-License-Identifier: GPL-2.0-only
11296 + * ALSA ASoC Machine Driver for PiFi-40
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
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.
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.
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>
11324 +static struct gpio_desc *pdn_gpio;
11325 +static int vol = 0x30;
11328 +static int pifi_40_vol_get(struct snd_kcontrol *kcontrol,
11329 + struct snd_ctl_elem_value *ucontrol)
11331 + ucontrol->value.integer.value[0] = vol;
11332 + ucontrol->value.integer.value[1] = vol;
11336 +static int pifi_40_vol_set(struct snd_kcontrol *kcontrol,
11337 + struct snd_ctl_elem_value *ucontrol)
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];
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;
11348 + snd_soc_component_write(dac[0], 0x07, 255 - v);
11349 + snd_soc_component_write(dac[1], 0x07, 255 - v);
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,
11361 + pifi_40_vol_get, pifi_40_vol_set,
11362 + digital_tlv_master)
11365 +static const char * const codec_ctl_pfx[] = { "Left", "Right" };
11367 +static const char * const codec_ctl_name[] = { "Master Volume",
11368 + "Speaker Volume",
11369 + "Speaker Switch" };
11371 +static int snd_pifi_40_init(struct snd_soc_pcm_runtime *rtd)
11373 + struct snd_soc_card *card = rtd->card;
11374 + struct snd_soc_component *dac[2];
11375 + struct snd_kcontrol *kctl;
11378 + dac[0] = asoc_rtd_to_codec(rtd, 0)->component;
11379 + dac[1] = asoc_rtd_to_codec(rtd, 1)->component;
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);
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);
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);
11398 + // Set up for PBTL
11399 + snd_soc_component_write(dac[i], 0x19, 0x3A);
11400 + snd_soc_component_write(dac[i], 0x25, 0x01103245);
11402 + // Master vol to -10db
11403 + snd_soc_component_write(dac[i], 0x07, 0x44);
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);
11409 + // Remove codec controls
11410 + for (i = 0; i < 2; i++) {
11411 + for (j = 0; j < 3; j++) {
11414 + sprintf(cname, "%s %s", codec_ctl_pfx[i],
11415 + codec_ctl_name[j]);
11416 + kctl = snd_soc_card_get_kcontrol(card, cname);
11418 + pr_info("Control %s not found\n",
11421 + kctl->vd[0].access =
11422 + SNDRV_CTL_ELEM_ACCESS_READWRITE;
11423 + snd_ctl_remove(card->snd_card, kctl);
11431 +static int snd_pifi_40_hw_params(struct snd_pcm_substream *substream,
11432 + struct snd_pcm_hw_params *params)
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;
11438 + sample_bits = snd_pcm_format_physical_width(params_format(params));
11439 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 64);
11442 +static struct snd_soc_ops snd_pifi_40_ops = { .hw_params =
11443 + snd_pifi_40_hw_params };
11445 +static struct snd_soc_dai_link_component pifi_40_codecs[] = {
11447 + .dai_name = "tas571x-hifi",
11450 + .dai_name = "tas571x-hifi",
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()));
11460 +static struct snd_soc_dai_link snd_pifi_40_dai[] = {
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),
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)
11482 +static void snd_pifi_40_pdn(struct snd_soc_card *card, int on)
11485 + gpiod_set_value_cansleep(pdn_gpio, on ? 0 : 1);
11488 +static int snd_pifi_40_probe(struct platform_device *pdev)
11490 + struct snd_soc_card *card = &snd_pifi_40;
11491 + int ret = 0, i = 0;
11493 + card->dev = &pdev->dev;
11494 + platform_set_drvdata(pdev, &snd_pifi_40);
11496 + if (pdev->dev.of_node) {
11497 + struct device_node *i2s_node;
11498 + struct snd_soc_dai_link *dai;
11500 + dai = &snd_pifi_40_dai[0];
11501 + i2s_node = of_parse_phandle(pdev->dev.of_node, "i2s-controller",
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;
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");
11522 + pdn_gpio = devm_gpiod_get_optional(&pdev->dev, "pdn",
11524 + if (IS_ERR(pdn_gpio)) {
11525 + ret = PTR_ERR(pdn_gpio);
11526 + dev_err(&pdev->dev, "failed to get pdn gpio: %d\n",
11531 + ret = snd_soc_register_card(&snd_pifi_40);
11533 + dev_err(&pdev->dev,
11534 + "snd_soc_register_card() failed: %d\n", ret);
11544 +static int snd_pifi_40_remove(struct platform_device *pdev)
11546 + struct snd_soc_card *card = platform_get_drvdata(pdev);
11548 + kfree(&card->drvdata);
11549 + snd_pifi_40_pdn(&snd_pifi_40, 0);
11550 + snd_soc_unregister_card(&snd_pifi_40);
11554 +static const struct of_device_id snd_pifi_40_of_match[] = {
11556 + .compatible = "pifi,pifi-40",
11558 + { /* sentinel */ },
11561 +MODULE_DEVICE_TABLE(of, snd_pifi_40_of_match);
11563 +static struct platform_driver snd_pifi_40_driver = {
11565 + .name = "snd-pifi-40",
11566 + .owner = THIS_MODULE,
11567 + .of_match_table = snd_pifi_40_of_match,
11569 + .probe = snd_pifi_40_probe,
11570 + .remove = snd_pifi_40_remove,
11573 +module_platform_driver(snd_pifi_40_driver);
11575 +MODULE_AUTHOR("David Knell <david.knell@gmail.com>");
11576 +MODULE_DESCRIPTION("ALSA ASoC Machine Driver for PiFi-40");
11577 +MODULE_LICENSE("GPL v2");
11579 +++ b/sound/soc/bcm/pisound.c
11582 + * Pisound Linux kernel module.
11583 + * Copyright (C) 2016-2020 Vilniaus Blokas UAB, https://blokas.io/pisound
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
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.
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.
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>
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>
11622 +static int pisnd_spi_init(struct device *dev);
11623 +static void pisnd_spi_uninit(void);
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);
11629 +typedef void (*pisnd_spi_recv_cb)(void *data);
11630 +static void pisnd_spi_set_callback(pisnd_spi_recv_cb cb, void *data);
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);
11637 +static int pisnd_midi_init(struct snd_card *card);
11638 +static void pisnd_midi_uninit(void);
11641 + TASK_PROCESS = 0,
11644 +static void pisnd_schedule_process(enum task_e task);
11646 +#define PISOUND_LOG_PREFIX "pisound: "
11648 +#ifdef PISOUND_DEBUG
11649 +# define printd(...) pr_alert(PISOUND_LOG_PREFIX __VA_ARGS__)
11651 +# define printd(...) do {} while (0)
11654 +#define printe(...) pr_err(PISOUND_LOG_PREFIX __VA_ARGS__)
11655 +#define printi(...) pr_info(PISOUND_LOG_PREFIX __VA_ARGS__)
11657 +static struct snd_rawmidi *g_rmidi;
11658 +static struct snd_rawmidi_substream *g_midi_output_substream;
11660 +static int pisnd_output_open(struct snd_rawmidi_substream *substream)
11662 + g_midi_output_substream = substream;
11666 +static int pisnd_output_close(struct snd_rawmidi_substream *substream)
11668 + g_midi_output_substream = NULL;
11672 +static void pisnd_output_trigger(
11673 + struct snd_rawmidi_substream *substream,
11677 + if (substream != g_midi_output_substream) {
11678 + printe("MIDI output trigger called for an unexpected stream!");
11685 + pisnd_spi_start();
11688 +static void pisnd_output_drain(struct snd_rawmidi_substream *substream)
11690 + pisnd_spi_flush();
11693 +static int pisnd_input_open(struct snd_rawmidi_substream *substream)
11698 +static int pisnd_input_close(struct snd_rawmidi_substream *substream)
11703 +static void pisnd_midi_recv_callback(void *substream)
11705 + uint8_t data[128];
11708 + while ((n = pisnd_spi_recv(data, sizeof(data)))) {
11709 + int res = snd_rawmidi_receive(substream, data, n);
11711 + printd("midi recv %u bytes, res = %d\n", n, res);
11715 +static void pisnd_input_trigger(struct snd_rawmidi_substream *substream, int up)
11718 + pisnd_spi_set_callback(pisnd_midi_recv_callback, substream);
11719 + pisnd_schedule_process(TASK_PROCESS);
11721 + pisnd_spi_set_callback(NULL, NULL);
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,
11732 +static struct snd_rawmidi_ops pisnd_input_ops = {
11733 + .open = pisnd_input_open,
11734 + .close = pisnd_input_close,
11735 + .trigger = pisnd_input_trigger,
11738 +static void pisnd_get_port_info(
11739 + struct snd_rawmidi *rmidi,
11741 + struct snd_seq_port_info *seq_port_info
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;
11751 +static struct snd_rawmidi_global_ops pisnd_global_ops = {
11752 + .get_port_info = pisnd_get_port_info,
11755 +static int pisnd_midi_init(struct snd_card *card)
11759 + g_midi_output_substream = NULL;
11761 + err = snd_rawmidi_new(card, "pisound MIDI", 0, 1, 1, &g_rmidi);
11764 + printe("snd_rawmidi_new failed: %d\n", err);
11768 + strcpy(g_rmidi->name, "pisound MIDI ");
11769 + strcat(g_rmidi->name, pisnd_spi_get_serial());
11771 + g_rmidi->info_flags =
11772 + SNDRV_RAWMIDI_INFO_OUTPUT |
11773 + SNDRV_RAWMIDI_INFO_INPUT |
11774 + SNDRV_RAWMIDI_INFO_DUPLEX;
11776 + g_rmidi->ops = &pisnd_global_ops;
11778 + g_rmidi->private_data = (void *)0;
11780 + snd_rawmidi_set_ops(
11782 + SNDRV_RAWMIDI_STREAM_OUTPUT,
11783 + &pisnd_output_ops
11786 + snd_rawmidi_set_ops(
11788 + SNDRV_RAWMIDI_STREAM_INPUT,
11795 +static void pisnd_midi_uninit(void)
11799 +static void *g_recvData;
11800 +static pisnd_spi_recv_cb g_recvCallback;
11802 +#define FIFO_SIZE 4096
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];
11810 +static uint8_t g_ledFlashDuration;
11811 +static bool g_ledFlashDurationChanged;
11813 +DEFINE_KFIFO(spi_fifo_in, uint8_t, FIFO_SIZE);
11814 +DEFINE_KFIFO(spi_fifo_out, uint8_t, FIFO_SIZE);
11816 +static struct gpio_desc *data_available;
11817 +static struct gpio_desc *spi_reset;
11819 +static struct spi_device *pisnd_spi_device;
11821 +static struct workqueue_struct *pisnd_workqueue;
11822 +static struct work_struct pisnd_work_process;
11824 +static void pisnd_work_handler(struct work_struct *work);
11826 +static void spi_transfer(const uint8_t *txbuf, uint8_t *rxbuf, int len);
11827 +static uint16_t spi_transfer16(uint16_t val);
11829 +static int pisnd_init_workqueues(void)
11831 + pisnd_workqueue = create_singlethread_workqueue("pisnd_workqueue");
11832 + INIT_WORK(&pisnd_work_process, pisnd_work_handler);
11837 +static void pisnd_uninit_workqueues(void)
11839 + flush_workqueue(pisnd_workqueue);
11840 + destroy_workqueue(pisnd_workqueue);
11842 + pisnd_workqueue = NULL;
11845 +static bool pisnd_spi_has_more(void)
11847 + return gpiod_get_value(data_available);
11850 +static void pisnd_schedule_process(enum task_e task)
11852 + if (pisnd_spi_device != NULL &&
11853 + pisnd_workqueue != NULL &&
11854 + !work_pending(&pisnd_work_process)
11856 + printd("schedule: has more = %d\n", pisnd_spi_has_more());
11857 + if (task == TASK_PROCESS)
11858 + queue_work(pisnd_workqueue, &pisnd_work_process);
11862 +static irqreturn_t data_available_interrupt_handler(int irq, void *dev_id)
11864 + if (irq == gpiod_to_irq(data_available) && pisnd_spi_has_more()) {
11865 + printd("schedule from irq\n");
11866 + pisnd_schedule_process(TASK_PROCESS);
11869 + return IRQ_HANDLED;
11872 +static uint16_t spi_transfer16(uint16_t val)
11874 + uint8_t txbuf[2];
11875 + uint8_t rxbuf[2];
11877 + if (!pisnd_spi_device) {
11878 + printe("pisnd_spi_device null, returning\n");
11882 + txbuf[0] = val >> 8;
11883 + txbuf[1] = val & 0xff;
11885 + spi_transfer(txbuf, rxbuf, sizeof(txbuf));
11887 + printd("received: %02x%02x\n", rxbuf[0], rxbuf[1]);
11889 + return (rxbuf[0] << 8) | rxbuf[1];
11892 +static void spi_transfer(const uint8_t *txbuf, uint8_t *rxbuf, int len)
11895 + struct spi_transfer transfer;
11896 + struct spi_message msg;
11898 + memset(rxbuf, 0, len);
11900 + if (!pisnd_spi_device) {
11901 + printe("pisnd_spi_device null, returning\n");
11905 + spi_message_init(&msg);
11907 + memset(&transfer, 0, sizeof(transfer));
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;
11916 + spi_message_add_tail(&transfer, &msg);
11918 + err = spi_sync(pisnd_spi_device, &msg);
11921 + printe("spi_sync error %d\n", err);
11925 + printd("hasMore %d\n", pisnd_spi_has_more());
11928 +static int spi_read_bytes(char *dst, size_t length, uint8_t *bytesRead)
11934 + memset(dst, 0, length);
11937 + rx = spi_transfer16(0);
11941 + size = rx & 0xff;
11943 + if (size > length)
11946 + for (i = 0; i < size; ++i) {
11947 + rx = spi_transfer16(0);
11951 + dst[i] = rx & 0xff;
11959 +static int spi_device_match(struct device *dev, const void *data)
11961 + struct spi_device *spi = container_of(dev, struct spi_device, dev);
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);
11967 + if (strcmp("pisound-spi", spi->modalias) == 0) {
11968 + printi("\tFound!\n");
11972 + printe("\tNot found!\n");
11976 +static struct spi_device *pisnd_spi_find_device(void)
11978 + struct device *dev;
11980 + printi("Searching for spi device...\n");
11981 + dev = bus_find_device(&spi_bus_type, NULL, NULL, spi_device_match);
11983 + return container_of(dev, struct spi_device, dev);
11988 +static void pisnd_work_handler(struct work_struct *work)
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;
11996 + uint8_t txbuf[TRANSFER_SIZE];
11997 + uint8_t rxbuf[TRANSFER_SIZE];
11998 + uint8_t midibuf[TRANSFER_SIZE];
12002 + unsigned long last_transfer_at = jiffies;
12004 + if (work == &pisnd_work_process) {
12005 + if (pisnd_spi_device == NULL)
12009 + if (g_midi_output_substream &&
12010 + kfifo_avail(&spi_fifo_out) >= sizeof(midibuf)) {
12012 + n = snd_rawmidi_transmit_peek(
12013 + g_midi_output_substream,
12014 + midibuf, sizeof(midibuf)
12018 + for (i = 0; i < n; ++i)
12023 + snd_rawmidi_transmit_ack(
12024 + g_midi_output_substream,
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);
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;
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
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;
12068 + for (i = 0; i < sizeof(rxbuf); i += 2) {
12070 + kfifo_put(&spi_fifo_in, rxbuf[i+1]);
12071 + if (kfifo_len(&spi_fifo_in) > 16 &&
12073 + g_recvCallback(g_recvData);
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
12084 + if (!kfifo_is_empty(&spi_fifo_in) && g_recvCallback)
12085 + g_recvCallback(g_recvData);
12089 +static int pisnd_spi_gpio_init(struct device *dev)
12091 + spi_reset = gpiod_get_index(dev, "reset", 1, GPIOD_ASIS);
12092 + data_available = gpiod_get_index(dev, "data_available", 0, GPIOD_ASIS);
12094 + gpiod_direction_output(spi_reset, 1);
12095 + gpiod_direction_input(data_available);
12097 + /* Reset the slave. */
12098 + gpiod_set_value(spi_reset, false);
12100 + gpiod_set_value(spi_reset, true);
12102 + /* Give time for spi slave to start. */
12108 +static void pisnd_spi_gpio_uninit(void)
12110 + gpiod_set_value(spi_reset, false);
12111 + gpiod_put(spi_reset);
12112 + spi_reset = NULL;
12114 + gpiod_put(data_available);
12115 + data_available = NULL;
12118 +static int pisnd_spi_gpio_irq_init(struct device *dev)
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",
12129 +static void pisnd_spi_gpio_irq_uninit(void)
12131 + free_irq(gpiod_to_irq(data_available), NULL);
12134 +static int spi_read_info(void)
12141 + char buffer[257];
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));
12150 + tmp = spi_transfer16(0);
12155 + count = tmp & 0xff;
12157 + for (i = 0; i < count; ++i) {
12158 + memset(buffer, 0, sizeof(buffer));
12159 + ret = spi_read_bytes(buffer, sizeof(buffer)-1, &n);
12171 + MAX_VERSION_STR_LEN,
12177 + g_fw_version[MAX_VERSION_STR_LEN-1] = '\0';
12185 + MAX_VERSION_STR_LEN,
12191 + g_hw_version[MAX_VERSION_STR_LEN-1] = '\0';
12194 + if (n >= sizeof(g_serial_num))
12197 + memcpy(g_serial_num, buffer, sizeof(g_serial_num));
12201 + if (n*2 >= sizeof(g_id))
12205 + for (j = 0; j < n; ++j)
12206 + p += sprintf(p, "%02x", buffer[j]);
12219 +static int pisnd_spi_init(struct device *dev)
12222 + struct spi_device *spi;
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));
12229 + spi = pisnd_spi_find_device();
12231 + if (spi != NULL) {
12232 + printd("initializing spi!\n");
12233 + pisnd_spi_device = spi;
12234 + ret = spi_setup(pisnd_spi_device);
12236 + printe("SPI device not found, deferring!\n");
12237 + return -EPROBE_DEFER;
12240 + ret = pisnd_spi_gpio_init(dev);
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();
12250 + ret = spi_read_info();
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();
12260 + /* Flash the LEDs. */
12261 + spi_transfer16(0xf008);
12263 + ret = pisnd_spi_gpio_irq_init(dev);
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();
12272 + ret = pisnd_init_workqueues();
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();
12283 + if (pisnd_spi_has_more()) {
12284 + printd("data is available, scheduling from init\n");
12285 + pisnd_schedule_process(TASK_PROCESS);
12291 +static void pisnd_spi_uninit(void)
12293 + pisnd_uninit_workqueues();
12295 + spi_dev_put(pisnd_spi_device);
12296 + pisnd_spi_device = NULL;
12298 + pisnd_spi_gpio_irq_uninit();
12299 + pisnd_spi_gpio_uninit();
12302 +static void pisnd_spi_flash_leds(uint8_t duration)
12304 + g_ledFlashDuration = duration;
12305 + g_ledFlashDurationChanged = true;
12306 + printd("schedule from spi_flash_leds\n");
12307 + pisnd_schedule_process(TASK_PROCESS);
12310 +static void pisnd_spi_flush(void)
12312 + while (!kfifo_is_empty(&spi_fifo_out)) {
12313 + pisnd_spi_start();
12314 + flush_workqueue(pisnd_workqueue);
12318 +static void pisnd_spi_start(void)
12320 + printd("schedule from spi_start\n");
12321 + pisnd_schedule_process(TASK_PROCESS);
12324 +static uint8_t pisnd_spi_recv(uint8_t *buffer, uint8_t length)
12326 + return kfifo_out(&spi_fifo_in, buffer, length);
12329 +static void pisnd_spi_set_callback(pisnd_spi_recv_cb cb, void *data)
12331 + g_recvData = data;
12332 + g_recvCallback = cb;
12335 +static const char *pisnd_spi_get_serial(void)
12337 + return g_serial_num;
12340 +static const char *pisnd_spi_get_id(void)
12345 +static const char *pisnd_spi_get_fw_version(void)
12347 + return g_fw_version;
12350 +static const char *pisnd_spi_get_hw_version(void)
12352 + return g_hw_version;
12355 +static const struct of_device_id pisound_of_match[] = {
12356 + { .compatible = "blokaslabs,pisound", },
12357 + { .compatible = "blokaslabs,pisound-spi", },
12366 +static int pisnd_ctl_info(struct snd_kcontrol *kcontrol,
12367 + struct snd_ctl_elem_info *uinfo)
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;
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;
12385 +static int pisnd_ctl_get(struct snd_kcontrol *kcontrol,
12386 + struct snd_ctl_elem_value *ucontrol)
12388 + if (kcontrol->private_value == SWITCH) {
12389 + ucontrol->value.integer.value[0] = 1;
12391 + } else if (kcontrol->private_value == VOLUME) {
12392 + ucontrol->value.integer.value[0] = 100;
12399 +static struct snd_kcontrol_new pisnd_ctl[] = {
12401 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12402 + .name = "PCM Playback Switch",
12404 + .private_value = SWITCH,
12405 + .access = SNDRV_CTL_ELEM_ACCESS_READ,
12406 + .info = pisnd_ctl_info,
12407 + .get = pisnd_ctl_get,
12410 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12411 + .name = "PCM Playback Volume",
12413 + .private_value = VOLUME,
12414 + .access = SNDRV_CTL_ELEM_ACCESS_READ,
12415 + .info = pisnd_ctl_info,
12416 + .get = pisnd_ctl_get,
12420 +static int pisnd_ctl_init(struct snd_card *card)
12424 + for (i = 0; i < ARRAY_SIZE(pisnd_ctl); ++i) {
12425 + err = snd_ctl_add(card, snd_ctl_new1(&pisnd_ctl[i], NULL));
12433 +static int pisnd_ctl_uninit(void)
12438 +static struct gpio_desc *osr0, *osr1, *osr2;
12439 +static struct gpio_desc *reset;
12440 +static struct gpio_desc *button;
12442 +static int pisnd_hw_params(
12443 + struct snd_pcm_substream *substream,
12444 + struct snd_pcm_hw_params *params
12447 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
12448 + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
12450 + /* Pisound runs on fixed 32 clock counts per channel,
12451 + * as generated by the master ADC.
12453 + snd_soc_dai_set_bclk_ratio(cpu_dai, 32*2);
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));
12461 + gpiod_set_value(reset, false);
12463 + switch (params_rate(params)) {
12465 + gpiod_set_value(osr0, true);
12466 + gpiod_set_value(osr1, false);
12467 + gpiod_set_value(osr2, false);
12470 + gpiod_set_value(osr0, true);
12471 + gpiod_set_value(osr1, false);
12472 + gpiod_set_value(osr2, true);
12475 + gpiod_set_value(osr0, true);
12476 + gpiod_set_value(osr1, true);
12477 + gpiod_set_value(osr2, true);
12480 + printe("Unsupported rate %u!\n", params_rate(params));
12484 + gpiod_set_value(reset, true);
12489 +static unsigned int rates[3] = {
12490 + 48000, 96000, 192000
12493 +static struct snd_pcm_hw_constraint_list constraints_rates = {
12494 + .count = ARRAY_SIZE(rates),
12499 +static int pisnd_startup(struct snd_pcm_substream *substream)
12501 + int err = snd_pcm_hw_constraint_list(
12502 + substream->runtime,
12504 + SNDRV_PCM_HW_PARAM_RATE,
12505 + &constraints_rates
12511 + err = snd_pcm_hw_constraint_single(
12512 + substream->runtime,
12513 + SNDRV_PCM_HW_PARAM_CHANNELS,
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
12534 +static struct snd_soc_ops pisnd_ops = {
12535 + .startup = pisnd_startup,
12536 + .hw_params = pisnd_hw_params,
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")));
12544 +static struct snd_soc_dai_link pisnd_dai[] = {
12546 + .name = "pisound",
12547 + .stream_name = "pisound",
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),
12557 +static int pisnd_card_probe(struct snd_soc_card *card)
12559 + int err = pisnd_midi_init(card->snd_card);
12562 + printe("pisnd_midi_init failed: %d\n", err);
12566 + err = pisnd_ctl_init(card->snd_card);
12568 + printe("pisnd_ctl_init failed: %d\n", err);
12575 +static int pisnd_card_remove(struct snd_soc_card *card)
12577 + pisnd_ctl_uninit();
12578 + pisnd_midi_uninit();
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,
12591 +static int pisnd_init_gpio(struct device *dev)
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);
12597 + reset = gpiod_get_index(dev, "reset", 0, GPIOD_ASIS);
12599 + button = gpiod_get_index(dev, "button", 0, GPIOD_ASIS);
12601 + gpiod_direction_output(osr0, 1);
12602 + gpiod_direction_output(osr1, 1);
12603 + gpiod_direction_output(osr2, 1);
12604 + gpiod_direction_output(reset, 1);
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);
12612 + gpiod_export(button, false);
12617 +static int pisnd_uninit_gpio(void)
12621 + struct gpio_desc **gpios[] = {
12622 + &osr0, &osr1, &osr2, &reset, &button,
12625 + gpiod_unexport(button);
12627 + for (i = 0; i < ARRAY_SIZE(gpios); ++i) {
12628 + if (*gpios[i] == NULL) {
12629 + printd("weird, GPIO[%d] is NULL already\n", i);
12633 + gpiod_put(*gpios[i]);
12634 + *gpios[i] = NULL;
12640 +static struct kobject *pisnd_kobj;
12642 +static ssize_t pisnd_serial_show(
12643 + struct kobject *kobj,
12644 + struct kobj_attribute *attr,
12648 + return sprintf(buf, "%s\n", pisnd_spi_get_serial());
12651 +static ssize_t pisnd_id_show(
12652 + struct kobject *kobj,
12653 + struct kobj_attribute *attr,
12657 + return sprintf(buf, "%s\n", pisnd_spi_get_id());
12660 +static ssize_t pisnd_fw_version_show(
12661 + struct kobject *kobj,
12662 + struct kobj_attribute *attr,
12666 + return sprintf(buf, "%s\n", pisnd_spi_get_fw_version());
12669 +static ssize_t pisnd_hw_version_show(
12670 + struct kobject *kobj,
12671 + struct kobj_attribute *attr,
12675 + return sprintf(buf, "%s\n", pisnd_spi_get_hw_version());
12678 +static ssize_t pisnd_led_store(
12679 + struct kobject *kobj,
12680 + struct kobj_attribute *attr,
12685 + uint32_t timeout;
12688 + err = kstrtou32(buf, 10, &timeout);
12690 + if (err == 0 && timeout <= 255)
12691 + pisnd_spi_flash_leds(timeout);
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);
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,
12716 +static struct attribute_group attr_group = { .attrs = attrs };
12718 +static int pisnd_probe(struct platform_device *pdev)
12723 + ret = pisnd_spi_init(&pdev->dev);
12725 + printe("pisnd_spi_init failed: %d\n", ret);
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());
12735 + pisnd_kobj = kobject_create_and_add("pisound", kernel_kobj);
12736 + if (!pisnd_kobj) {
12737 + pisnd_spi_uninit();
12741 + ret = sysfs_create_group(pisnd_kobj, &attr_group);
12743 + pisnd_spi_uninit();
12744 + kobject_put(pisnd_kobj);
12748 + pisnd_init_gpio(&pdev->dev);
12749 + pisnd_card.dev = &pdev->dev;
12751 + if (pdev->dev.of_node) {
12752 + struct device_node *i2s_node;
12754 + i2s_node = of_parse_phandle(
12755 + pdev->dev.of_node,
12756 + "i2s-controller",
12760 + for (i = 0; i < pisnd_card.num_links; ++i) {
12761 + struct snd_soc_dai_link *dai = &pisnd_dai[i];
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();
12773 + ret = snd_soc_register_card(&pisnd_card);
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();
12786 +static int pisnd_remove(struct platform_device *pdev)
12788 + printi("Unloading.\n");
12790 + if (pisnd_kobj) {
12791 + kobject_put(pisnd_kobj);
12792 + pisnd_kobj = NULL;
12795 + pisnd_spi_uninit();
12798 + gpiod_set_value(reset, false);
12799 + pisnd_uninit_gpio();
12801 + snd_soc_unregister_card(&pisnd_card);
12805 +MODULE_DEVICE_TABLE(of, pisound_of_match);
12807 +static struct platform_driver pisnd_driver = {
12809 + .name = "snd-rpi-pisound",
12810 + .owner = THIS_MODULE,
12811 + .of_match_table = pisound_of_match,
12813 + .probe = pisnd_probe,
12814 + .remove = pisnd_remove,
12817 +module_platform_driver(pisnd_driver);
12819 +MODULE_AUTHOR("Giedrius Trainavicius <giedrius@blokas.io>");
12820 +MODULE_DESCRIPTION("ASoC Driver for Pisound, https://blokas.io/pisound");
12821 +MODULE_LICENSE("GPL v2");
12823 +++ b/sound/soc/bcm/rpi-cirrus.c
12826 + * ASoC machine driver for Cirrus Logic Audio Card
12827 + * (with WM5102 and WM8804 codecs)
12829 + * Copyright 2015-2017 Matthias Reichl <hias@horus.com>
12831 + * Based on rpi-cirrus-sound-pi driver (c) Wolfson / Cirrus Logic Inc.
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.
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>
12845 +#include <linux/mfd/arizona/registers.h>
12847 +#include "../codecs/wm5102.h"
12848 +#include "../codecs/wm8804.h"
12850 +#define WM8804_CLKOUT_HZ 12000000
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 */
12856 +static inline unsigned int calc_sysclk(unsigned int rate)
12858 + return (rate % 4000) ? WM5102_MAX_SYSCLK_2 : WM5102_MAX_SYSCLK_1;
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 */
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];
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]);
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]);
12891 +struct rate_info {
12892 + unsigned int value;
12896 +static struct rate_info min_rates[] = {
12898 + { 32000, "32kHz"},
12899 + { 44100, "44.1kHz"}
12902 +#define NUM_MIN_RATES ARRAY_SIZE(min_rates)
12904 +static int rpi_cirrus_min_rate_info(struct snd_kcontrol *kcontrol,
12905 + struct snd_ctl_elem_info *uinfo)
12907 + uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
12908 + uinfo->count = 1;
12909 + uinfo->value.enumerated.items = NUM_MIN_RATES;
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);
12918 +static int rpi_cirrus_min_rate_get(struct snd_kcontrol *kcontrol,
12919 + struct snd_ctl_elem_value *ucontrol)
12921 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
12922 + struct rpi_cirrus_priv *priv = snd_soc_card_get_drvdata(card);
12924 + ucontrol->value.enumerated.item[0] = priv->min_rate_idx;
12928 +static int rpi_cirrus_min_rate_put(struct snd_kcontrol *kcontrol,
12929 + struct snd_ctl_elem_value *ucontrol)
12931 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
12932 + struct rpi_cirrus_priv *priv = snd_soc_card_get_drvdata(card);
12935 + if (priv->min_rate_idx != ucontrol->value.enumerated.item[0]) {
12937 + priv->min_rate_idx = ucontrol->value.enumerated.item[0];
12943 +static struct rate_info max_rates[] = {
12945 + { 48000, "48kHz"},
12946 + { 96000, "96kHz"}
12949 +#define NUM_MAX_RATES ARRAY_SIZE(max_rates)
12951 +static int rpi_cirrus_max_rate_info(struct snd_kcontrol *kcontrol,
12952 + struct snd_ctl_elem_info *uinfo)
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);
12964 +static int rpi_cirrus_max_rate_get(struct snd_kcontrol *kcontrol,
12965 + struct snd_ctl_elem_value *ucontrol)
12967 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
12968 + struct rpi_cirrus_priv *priv = snd_soc_card_get_drvdata(card);
12970 + ucontrol->value.enumerated.item[0] = priv->max_rate_idx;
12974 +static int rpi_cirrus_max_rate_put(struct snd_kcontrol *kcontrol,
12975 + struct snd_ctl_elem_value *ucontrol)
12977 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
12978 + struct rpi_cirrus_priv *priv = snd_soc_card_get_drvdata(card);
12981 + if (priv->max_rate_idx != ucontrol->value.enumerated.item[0]) {
12983 + priv->max_rate_idx = ucontrol->value.enumerated.item[0];
12989 +static int rpi_cirrus_spdif_info(struct snd_kcontrol *kcontrol,
12990 + struct snd_ctl_elem_info *uinfo)
12992 + uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
12993 + uinfo->count = 1;
12997 +static int rpi_cirrus_spdif_playback_get(struct snd_kcontrol *kcontrol,
12998 + struct snd_ctl_elem_value *ucontrol)
13000 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
13001 + struct rpi_cirrus_priv *priv = snd_soc_card_get_drvdata(card);
13004 + for (i = 0; i < 4; i++)
13005 + ucontrol->value.iec958.status[i] = priv->iec958_status[i];
13010 +static int rpi_cirrus_spdif_playback_put(struct snd_kcontrol *kcontrol,
13011 + struct snd_ctl_elem_value *ucontrol)
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;
13022 + for (i = 0; i < 4; i++) {
13023 + mask = (i == 3) ? 0x3f : 0xff;
13024 + if ((ctrl_stat[i] & mask) != (stat[i] & mask)) {
13026 + stat[i] = ctrl_stat[i] & mask;
13027 + snd_soc_component_update_bits(wm8804_component,
13028 + WM8804_SPDTX1 + i, mask, stat[i]);
13035 +static int rpi_cirrus_spdif_mask_get(struct snd_kcontrol *kcontrol,
13036 + struct snd_ctl_elem_value *ucontrol)
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;
13046 +static int rpi_cirrus_spdif_capture_get(struct snd_kcontrol *kcontrol,
13047 + struct snd_ctl_elem_value *ucontrol)
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;
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;
13065 +#define SPDIF_FLAG_CTRL(desc, reg, bit, invert) \
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) \
13072 + .info = snd_ctl_boolean_mono_info, \
13073 + .get = rpi_cirrus_spdif_status_flag_get, \
13074 + .private_value = \
13075 + (bit) | ((reg) << 8) | ((invert) << 16) \
13078 +static int rpi_cirrus_spdif_status_flag_get(struct snd_kcontrol *kcontrol,
13079 + struct snd_ctl_elem_value *ucontrol)
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;
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;
13091 + val = snd_soc_component_read(wm8804_component, reg);
13093 + flag = val & (1 << bit);
13095 + ucontrol->value.integer.value[0] = invert ? !flag : flag;
13100 +static const char * const recovered_frequency_texts[] = {
13107 +#define NUM_RECOVERED_FREQUENCIES \
13108 + ARRAY_SIZE(recovered_frequency_texts)
13110 +static int rpi_cirrus_recovered_frequency_info(struct snd_kcontrol *kcontrol,
13111 + struct snd_ctl_elem_info *uinfo)
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]);
13123 +static int rpi_cirrus_recovered_frequency_get(struct snd_kcontrol *kcontrol,
13124 + struct snd_ctl_elem_value *ucontrol)
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;
13131 + val = snd_soc_component_read(wm8804_component, WM8804_SPDSTAT);
13133 + ucontrol->value.enumerated.item[0] = (val >> 4) & 0x03;
13137 +static const struct snd_kcontrol_new rpi_cirrus_controls[] = {
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,
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,
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,
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,
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,
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,
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),
13192 +static const char * const linein_micbias_texts[] = {
13196 +static SOC_ENUM_SINGLE_VIRT_DECL(linein_micbias_enum,
13197 + linein_micbias_texts);
13199 +static const struct snd_kcontrol_new linein_micbias_mux =
13200 + SOC_DAPM_ENUM("Route", linein_micbias_enum);
13202 +static int rpi_cirrus_spdif_rx_enable_event(struct snd_soc_dapm_widget *w,
13203 + struct snd_kcontrol *kcontrol, int event);
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"),
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" },
13225 + { "IN2L", NULL, "DMIC" },
13226 + { "IN2R", NULL, "DMIC" },
13227 + { "DMIC", NULL, "MICBIAS2" },
13229 + { "IN3L", NULL, "Line Input Micbias" },
13230 + { "IN3R", NULL, "Line Input Micbias" },
13232 + { "Line Input Micbias", "off", "Line Input" },
13233 + { "Line Input Micbias", "on", "Line Input with Micbias" },
13235 + /* Make sure MICVDD is enabled, otherwise we get noise */
13236 + { "Line Input", NULL, "MICVDD" },
13237 + { "Line Input with Micbias", NULL, "MICBIAS3" },
13239 + /* Dummy routes to check whether SPDIF RX is enabled or not */
13240 + {"dummy SPDIFRX", NULL, "dummy SPDIF in"},
13241 + {"AIFTX", NULL, "dummy SPDIFRX"},
13244 + * Dummy routes to keep wm5102 from staying off on
13245 + * playback/capture if all mixers are off.
13247 + { "Dummy Output", NULL, "AIF1RX1" },
13248 + { "Dummy Output", NULL, "AIF1RX2" },
13249 + { "AIF1TX1", NULL, "Dummy Input" },
13250 + { "AIF1TX2", NULL, "Dummy Input" },
13253 +static int rpi_cirrus_clear_flls(struct snd_soc_card *card,
13254 + struct snd_soc_component *wm5102_component) {
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);
13264 + dev_warn(card->dev,
13265 + "setting FLL1 to zero failed: %d\n", ret1);
13269 + dev_warn(card->dev,
13270 + "setting FLL1_REFCLK to zero failed: %d\n", ret2);
13276 +static int rpi_cirrus_set_fll(struct snd_soc_card *card,
13277 + struct snd_soc_component *wm5102_component, unsigned int clk_freq)
13279 + int ret = snd_soc_component_set_pll(wm5102_component,
13281 + ARIZONA_CLK_SRC_MCLK1,
13282 + WM8804_CLKOUT_HZ,
13285 + dev_err(card->dev, "Failed to set FLL1 to %d: %d\n",
13288 + usleep_range(1000, 2000);
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)
13296 + int ret = snd_soc_component_set_pll(wm5102_component,
13297 + WM5102_FLL1_REFCLK,
13298 + ARIZONA_CLK_SRC_MCLK1,
13299 + WM8804_CLKOUT_HZ,
13302 + dev_err(card->dev,
13303 + "Failed to set FLL1_REFCLK to %d: %d\n",
13308 + ret = snd_soc_component_set_pll(wm5102_component,
13310 + ARIZONA_CLK_SRC_AIF2BCLK,
13311 + aif2_freq, clk_freq);
13313 + dev_err(card->dev,
13314 + "Failed to set FLL1 with Sync Clock %d to %d: %d\n",
13315 + aif2_freq, clk_freq, ret);
13317 + usleep_range(1000, 2000);
13321 +static int rpi_cirrus_spdif_rx_enable_event(struct snd_soc_dapm_widget *w,
13322 + struct snd_kcontrol *kcontrol, int event)
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;
13329 + unsigned int clk_freq, aif2_freq;
13333 + case SND_SOC_DAPM_POST_PMU:
13334 + mutex_lock(&priv->lock);
13336 + /* Enable sync path in case of SPDIF capture use case */
13338 + clk_freq = calc_sysclk(priv->card_rate);
13339 + aif2_freq = 64 * priv->card_rate;
13341 + dev_dbg(card->dev,
13342 + "spdif_rx: changing FLL1 to use Ref Clock clk: %d spdif: %d\n",
13343 + clk_freq, aif2_freq);
13345 + ret = rpi_cirrus_clear_flls(card, wm5102_component);
13347 + dev_err(card->dev, "spdif_rx: failed to clear FLLs\n");
13351 + ret = rpi_cirrus_set_fll_refclk(card, wm5102_component,
13352 + clk_freq, aif2_freq);
13355 + dev_err(card->dev, "spdif_rx: failed to set FLLs\n");
13359 + /* set to negative to indicate we're doing spdif rx */
13360 + priv->fll1_freq = -clk_freq;
13361 + priv->sync_path_enable = 1;
13364 + case SND_SOC_DAPM_POST_PMD:
13365 + mutex_lock(&priv->lock);
13366 + priv->sync_path_enable = 0;
13374 + mutex_unlock(&priv->lock);
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)
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;
13388 + unsigned int clk_freq;
13390 + if (dapm->dev != asoc_rtd_to_codec(wm5102_runtime, 0)->dev)
13394 + case SND_SOC_BIAS_PREPARE:
13395 + if (dapm->bias_level == SND_SOC_BIAS_ON)
13398 + mutex_lock(&priv->lock);
13400 + if (!priv->sync_path_enable) {
13401 + clk_freq = calc_sysclk(priv->card_rate);
13403 + dev_dbg(card->dev,
13404 + "set_bias: changing FLL1 from %d to %d\n",
13405 + priv->fll1_freq, clk_freq);
13407 + ret = rpi_cirrus_set_fll(card,
13408 + wm5102_component, clk_freq);
13410 + dev_err(card->dev,
13411 + "set_bias: Failed to set FLL1\n");
13413 + priv->fll1_freq = clk_freq;
13415 + mutex_unlock(&priv->lock);
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)
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;
13433 + if (dapm->dev != asoc_rtd_to_codec(wm5102_runtime, 0)->dev)
13437 + case SND_SOC_BIAS_STANDBY:
13438 + mutex_lock(&priv->lock);
13440 + dev_dbg(card->dev,
13441 + "set_bias_post: changing FLL1 from %d to off\n",
13442 + priv->fll1_freq);
13444 + if (rpi_cirrus_clear_flls(card, wm5102_component))
13445 + dev_err(card->dev,
13446 + "set_bias_post: failed to clear FLLs\n");
13448 + priv->fll1_freq = 0;
13450 + mutex_unlock(&priv->lock);
13460 +static int rpi_cirrus_set_wm8804_pll(struct snd_soc_card *card,
13461 + struct snd_soc_dai *wm8804_dai, unsigned int rate)
13466 + unsigned int clk_freq = rate * 256;
13468 + ret = snd_soc_dai_set_pll(wm8804_dai, 0, 0,
13469 + WM8804_CLKOUT_HZ, clk_freq);
13471 + dev_err(card->dev,
13472 + "Failed to set WM8804 PLL to %d: %d\n", clk_freq, ret);
13476 + /* Set MCLK as PLL Output */
13477 + ret = snd_soc_dai_set_sysclk(wm8804_dai,
13478 + WM8804_TX_CLKSRC_PLL, clk_freq, 0);
13480 + dev_err(card->dev,
13481 + "Failed to set MCLK as PLL Output: %d\n", ret);
13488 +static int rpi_cirrus_startup(struct snd_pcm_substream *substream)
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;
13496 + if (min_rate || max_rate) {
13497 + if (max_rate == 0)
13498 + max_rate = UINT_MAX;
13500 + dev_dbg(card->dev,
13501 + "startup: limiting rate to %u-%u\n",
13502 + min_rate, max_rate);
13504 + snd_pcm_hw_constraint_minmax(substream->runtime,
13505 + SNDRV_PCM_HW_PARAM_RATE, min_rate, max_rate);
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,
13519 +static int rpi_cirrus_hw_params(struct snd_pcm_substream *substream,
13520 + struct snd_pcm_hw_params *params)
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);
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);
13536 + mutex_lock(&priv->lock);
13538 + dev_dbg(card->dev, "hw_params: setting rate to %d\n", rate);
13540 + ret = snd_soc_dai_set_bclk_ratio(bcm_i2s_dai, 2 * width);
13542 + dev_err(card->dev, "set_bclk_ratio failed: %d\n", ret);
13546 + ret = snd_soc_dai_set_tdm_slot(asoc_rtd_to_codec(rtd, 0), 0x03, 0x03, 2, width);
13548 + dev_err(card->dev, "set_tdm_slot failed: %d\n", ret);
13552 + /* WM8804 supports sample rates from 32k only */
13553 + if (rate >= 32000) {
13554 + ret = rpi_cirrus_set_wm8804_pll(card, wm8804_dai, rate);
13559 + ret = snd_soc_component_set_sysclk(wm5102_component,
13560 + ARIZONA_CLK_SYSCLK,
13561 + ARIZONA_CLK_SRC_FLL1,
13563 + SND_SOC_CLOCK_IN);
13565 + dev_err(card->dev, "Failed to set SYSCLK: %d\n", ret);
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);
13574 + if (rpi_cirrus_clear_flls(card, wm5102_component)) {
13575 + dev_err(card->dev, "hw_params: failed to clear FLLs\n");
13579 + if (rpi_cirrus_set_fll(card, wm5102_component, clk_freq)) {
13580 + dev_err(card->dev, "hw_params: failed to set FLL\n");
13584 + priv->fll1_freq = clk_freq;
13587 + priv->card_rate = rate;
13588 + rpi_cirrus_dai_link2_params.rate_min = rate;
13589 + rpi_cirrus_dai_link2_params.rate_max = rate;
13591 + priv->params_set |= 1 << substream->stream;
13594 + mutex_unlock(&priv->lock);
13599 +static int rpi_cirrus_hw_free(struct snd_pcm_substream *substream)
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;
13606 + unsigned int old_params_set = priv->params_set;
13608 + priv->params_set &= ~(1 << substream->stream);
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");
13615 + ret = snd_soc_component_set_sysclk(wm5102_component,
13616 + ARIZONA_CLK_SYSCLK,
13617 + ARIZONA_CLK_SRC_FLL1,
13619 + SND_SOC_CLOCK_IN);
13621 + dev_err(card->dev,
13622 + "hw_free: Failed to set SYSCLK to Zero: %d\n",
13628 +static int rpi_cirrus_init_wm5102(struct snd_soc_pcm_runtime *rtd)
13630 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
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);
13637 + if (rpi_cirrus_clear_flls(rtd->card, component))
13638 + dev_warn(rtd->card->dev,
13639 + "init_wm5102: failed to clear FLLs\n");
13641 + ret = snd_soc_component_set_sysclk(component,
13642 + ARIZONA_CLK_SYSCLK, ARIZONA_CLK_SRC_FLL1,
13643 + 0, SND_SOC_CLOCK_IN);
13645 + dev_err(rtd->card->dev,
13646 + "Failed to set SYSCLK to Zero: %d\n", ret);
13653 +static int rpi_cirrus_init_wm8804(struct snd_soc_pcm_runtime *rtd)
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;
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;
13669 + /* Setup for 256fs */
13670 + ret = snd_soc_dai_set_clkdiv(codec_dai,
13671 + WM8804_MCLK_DIV, WM8804_MCLKDIV_256FS);
13673 + dev_err(card->dev,
13674 + "init_wm8804: Failed to set MCLK_DIV to 256fs: %d\n",
13679 + /* Output OSC on CLKOUT */
13680 + ret = snd_soc_dai_set_sysclk(codec_dai,
13681 + WM8804_CLKOUT_SRC_OSCCLK, WM8804_CLKOUT_HZ, 0);
13683 + dev_err(card->dev,
13684 + "init_wm8804: Failed to set CLKOUT as OSC Frequency: %d\n",
13687 + /* Init PLL with default samplerate */
13688 + ret = rpi_cirrus_set_wm8804_pll(card, codec_dai,
13689 + RPI_CIRRUS_DEFAULT_RATE);
13691 + dev_err(card->dev,
13692 + "init_wm8804: Failed to setup PLL for %dHz: %d\n",
13693 + RPI_CIRRUS_DEFAULT_RATE, ret);
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,
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()));
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")));
13713 +static struct snd_soc_dai_link rpi_cirrus_dai[] = {
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),
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),
13738 +static int rpi_cirrus_late_probe(struct snd_soc_card *card)
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);
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]);
13751 + ret = snd_soc_dai_set_sysclk(
13752 + asoc_rtd_to_codec(wm5102_runtime, 0), ARIZONA_CLK_SYSCLK, 0, 0);
13754 + dev_err(card->dev,
13755 + "Failed to set WM5102 codec dai clk domain: %d\n", ret);
13759 + ret = snd_soc_dai_set_sysclk(
13760 + asoc_rtd_to_cpu(wm8804_runtime, 0), ARIZONA_CLK_SYSCLK, 0, 0);
13762 + dev_err(card->dev,
13763 + "Failed to set WM8804 codec dai clk domain: %d\n", ret);
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,
13786 +static int rpi_cirrus_probe(struct platform_device *pdev)
13789 + struct rpi_cirrus_priv *priv;
13790 + struct device_node *i2s_node;
13792 + priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
13796 + priv->min_rate_idx = 1; /* min samplerate 32kHz */
13797 + priv->card_rate = RPI_CIRRUS_DEFAULT_RATE;
13799 + mutex_init(&priv->lock);
13801 + snd_soc_card_set_drvdata(&rpi_cirrus_card, priv);
13803 + if (!pdev->dev.of_node)
13806 + i2s_node = of_parse_phandle(
13807 + pdev->dev.of_node, "i2s-controller", 0);
13809 + dev_err(&pdev->dev, "i2s-controller missing in DT\n");
13813 + rpi_cirrus_dai[DAI_WM5102].cpus->of_node = i2s_node;
13814 + rpi_cirrus_dai[DAI_WM5102].platforms->of_node = i2s_node;
13816 + rpi_cirrus_card.dev = &pdev->dev;
13818 + ret = devm_snd_soc_register_card(&pdev->dev, &rpi_cirrus_card);
13820 + if (ret == -EPROBE_DEFER)
13821 + dev_dbg(&pdev->dev,
13822 + "register card requested probe deferral\n");
13824 + dev_err(&pdev->dev,
13825 + "Failed to register card: %d\n", ret);
13831 +static const struct of_device_id rpi_cirrus_of_match[] = {
13832 + { .compatible = "wlf,rpi-cirrus", },
13835 +MODULE_DEVICE_TABLE(of, rpi_cirrus_of_match);
13837 +static struct platform_driver rpi_cirrus_driver = {
13839 + .name = "snd-rpi-cirrus",
13840 + .of_match_table = of_match_ptr(rpi_cirrus_of_match),
13842 + .probe = rpi_cirrus_probe,
13845 +module_platform_driver(rpi_cirrus_driver);
13847 +MODULE_AUTHOR("Matthias Reichl <hias@horus.com>");
13848 +MODULE_DESCRIPTION("ASoC driver for Cirrus Logic Audio Card");
13849 +MODULE_LICENSE("GPL");
13851 +++ b/sound/soc/bcm/rpi-proto.c
13854 + * ASoC driver for PROTO AudioCODEC (with a WM8731)
13855 + * connected to a Raspberry Pi
13857 + * Author: Florian Meier, <koalo@koalo.de>
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.
13865 +#include <linux/module.h>
13866 +#include <linux/platform_device.h>
13868 +#include <sound/core.h>
13869 +#include <sound/pcm.h>
13870 +#include <sound/soc.h>
13871 +#include <sound/jack.h>
13873 +#include "../codecs/wm8731.h"
13875 +static const unsigned int wm8731_rates_12288000[] = {
13876 + 8000, 32000, 48000, 96000,
13879 +static struct snd_pcm_hw_constraint_list wm8731_constraints_12288000 = {
13880 + .list = wm8731_rates_12288000,
13881 + .count = ARRAY_SIZE(wm8731_rates_12288000),
13884 +static int snd_rpi_proto_startup(struct snd_pcm_substream *substream)
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);
13893 +static int snd_rpi_proto_hw_params(struct snd_pcm_substream *substream,
13894 + struct snd_pcm_hw_params *params)
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 */
13901 + /* Set proto bclk */
13902 + int ret = snd_soc_dai_set_bclk_ratio(cpu_dai,32*2);
13904 + dev_err(rtd->card->dev,
13905 + "Failed to set BCLK ratio %d\n", ret);
13909 + /* Set proto sysclk */
13910 + ret = snd_soc_dai_set_sysclk(codec_dai, WM8731_SYSCLK_XTAL,
13911 + sysclk, SND_SOC_CLOCK_IN);
13913 + dev_err(rtd->card->dev,
13914 + "Failed to set WM8731 SYSCLK: %d\n", ret);
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,
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")));
13932 +static struct snd_soc_dai_link snd_rpi_proto_dai[] = {
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),
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),
13952 +static int snd_rpi_proto_probe(struct platform_device *pdev)
13956 + snd_rpi_proto.dev = &pdev->dev;
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);
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;
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);
13980 +static const struct of_device_id snd_rpi_proto_of_match[] = {
13981 + { .compatible = "rpi,rpi-proto", },
13984 +MODULE_DEVICE_TABLE(of, snd_rpi_proto_of_match);
13986 +static struct platform_driver snd_rpi_proto_driver = {
13988 + .name = "snd-rpi-proto",
13989 + .owner = THIS_MODULE,
13990 + .of_match_table = snd_rpi_proto_of_match,
13992 + .probe = snd_rpi_proto_probe,
13995 +module_platform_driver(snd_rpi_proto_driver);
13997 +MODULE_AUTHOR("Florian Meier");
13998 +MODULE_DESCRIPTION("ASoC Driver for Raspberry Pi connected to PROTO board (WM8731)");
13999 +MODULE_LICENSE("GPL");
14001 +++ b/sound/soc/bcm/rpi-simple-soundcard.c
14003 +// SPDX-License-Identifier: GPL-2.0
14005 + * rpi-simple-soundcard.c -- ALSA SoC Raspberry Pi soundcard.
14007 + * Copyright (C) 2018 Raspberry Pi.
14009 + * Authors: Tim Gover <tim.gover@raspberrypi.org>
14012 + * hifiberry_amp.c, hifiberry_dac.c, rpi-dac.c
14013 + * by Florian Meier <florian.meier@koalo.de>
14015 + * googlevoicehat-soundcard.c
14016 + * by Peter Malkin <petermalkin@google.com>
14019 + * by Andrey Grodzovsky <andrey2805@gmail.com>
14022 + * by Ariel Muszkat <ariel.muszkat@gmail.com>
14023 + * Jorgen Kragh Jakobsen <jorgen.kraghjakobsen@infineon.com>
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.
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.
14035 +#include <linux/module.h>
14036 +#include <linux/platform_device.h>
14037 +#include <linux/gpio/consumer.h>
14039 +#include <sound/core.h>
14040 +#include <sound/pcm.h>
14041 +#include <sound/pcm_params.h>
14042 +#include <sound/soc.h>
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;
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 */
14058 +static int snd_rpi_simple_init(struct snd_soc_pcm_runtime *rtd)
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);
14064 + if (drvdata->fixed_bclk_ratio > 0)
14065 + return snd_soc_dai_set_bclk_ratio(cpu_dai,
14066 + drvdata->fixed_bclk_ratio);
14071 +static int pifi_mini_210_init(struct snd_soc_pcm_runtime *rtd)
14073 + struct snd_soc_component *dac;
14074 + struct gpio_desc *pdn_gpio, *rst_gpio;
14075 + struct snd_soc_dai *codec_dai;
14078 + snd_rpi_simple_init(rtd);
14079 + codec_dai = asoc_rtd_to_codec(rtd, 0);
14081 + dac = codec_dai[0].component;
14083 + pdn_gpio = devm_gpiod_get_optional(snd_rpi_simple.dev, "pdn",
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);
14091 + rst_gpio = devm_gpiod_get_optional(snd_rpi_simple.dev, "rst",
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);
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);
14109 + // Oscillator trim
14110 + snd_soc_component_write(dac, 0x1b, 0);
14111 + usleep_range(60000, 80000);
14113 + // MCLK at 64fs, sample rate 44.1 or 48kHz
14114 + snd_soc_component_write(dac, 0x00, 0x60);
14116 + // Set up for BTL - AD/BD mode - AD is 0x00107772, BD is 0x00987772
14117 + snd_soc_component_write(dac, 0x20, 0x00107772);
14120 + snd_soc_component_write(dac, 0x05, 0x00);
14125 +static int snd_rpi_simple_hw_params(struct snd_pcm_substream *substream,
14126 + struct snd_pcm_hw_params *params)
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;
14133 + drvdata = snd_soc_card_get_drvdata(rtd->card);
14135 + if (drvdata->fixed_bclk_ratio > 0)
14136 + return 0; // BCLK is configured in .init
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.
14142 + sample_bits = snd_pcm_format_physical_width(params_format(params));
14143 + return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);
14146 +static struct snd_soc_ops snd_rpi_simple_ops = {
14147 + .hw_params = snd_rpi_simple_hw_params,
14150 +static int snd_merus_amp_hw_params(struct snd_pcm_substream *substream,
14151 + struct snd_pcm_hw_params *params)
14153 + struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
14156 + rate = params_rate(params);
14157 + if (rate > 48000) {
14158 + dev_err(rtd->card->dev,
14159 + "Unsupported samplerate %d\n",
14166 +static struct snd_soc_ops snd_merus_amp_ops = {
14167 + .hw_params = snd_merus_amp_hw_params,
14170 +enum adau1977_clk_id {
14174 +enum adau1977_sysclk_src {
14175 + ADAU1977_SYSCLK_SRC_MCLK,
14176 + ADAU1977_SYSCLK_SRC_LRCLK,
14179 +static int adau1977_init(struct snd_soc_pcm_runtime *rtd)
14182 + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
14184 + ret = snd_soc_dai_set_tdm_slot(codec_dai, 0, 0, 0, 0);
14188 + return snd_soc_component_set_sysclk(codec_dai->component,
14189 + ADAU1977_SYSCLK, ADAU1977_SYSCLK_SRC_MCLK,
14190 + 11289600, SND_SOC_CLOCK_IN);
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()));
14198 +static struct snd_soc_dai_link snd_rpi_adau1977_dai[] = {
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),
14210 +static struct snd_rpi_simple_drvdata drvdata_adau1977 = {
14211 + .card_name = "snd_rpi_adau1977_adc",
14212 + .dai = snd_rpi_adau1977_dai,
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()));
14220 +static struct snd_soc_dai_link snd_googlevoicehat_soundcard_dai[] = {
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),
14230 +static struct snd_rpi_simple_drvdata drvdata_googlevoicehat = {
14231 + .card_name = "snd_rpi_googlevoicehat_soundcard",
14232 + .dai = snd_googlevoicehat_soundcard_dai,
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()));
14240 +static struct snd_soc_dai_link snd_hifiberrydacplusdsp_soundcard_dai[] = {
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),
14251 +static struct snd_rpi_simple_drvdata drvdata_hifiberrydacplusdsp = {
14252 + .card_name = "snd_rpi_hifiberrydacplusdsp_soundcard",
14253 + .dai = snd_hifiberrydacplusdsp_soundcard_dai,
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()));
14261 +static struct snd_soc_dai_link snd_hifiberry_amp_dai[] = {
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),
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,
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()));
14283 +static struct snd_soc_dai_link snd_hifiberry_amp3_dai[] = {
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),
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,
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()));
14305 +static struct snd_soc_dai_link snd_hifiberry_dac_dai[] = {
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),
14316 +static struct snd_rpi_simple_drvdata drvdata_hifiberry_dac = {
14317 + .card_name = "snd_rpi_hifiberry_dac",
14318 + .dai = snd_hifiberry_dac_dai,
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()));
14326 +static struct snd_soc_dai_link snd_dionaudio_kiwi_dai[] = {
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),
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,
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()));
14347 +static struct snd_soc_dai_link snd_rpi_dac_dai[] = {
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),
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,
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()));
14368 +static struct snd_soc_dai_link snd_merus_amp_dai[] = {
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),
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,
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()));
14391 +static struct snd_soc_dai_link snd_pifi_mini_210_dai[] = {
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),
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,
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 },
14432 +static int snd_rpi_simple_probe(struct platform_device *pdev)
14435 + const struct of_device_id *of_id;
14437 + snd_rpi_simple.dev = &pdev->dev;
14438 + of_id = of_match_node(snd_rpi_simple_of_match, pdev->dev.of_node);
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;
14446 + snd_soc_card_set_drvdata(&snd_rpi_simple, drvdata);
14448 + /* More complex drivers might override individual functions */
14450 + dai->init = snd_rpi_simple_init;
14452 + dai->ops = &snd_rpi_simple_ops;
14454 + snd_rpi_simple.name = drvdata->card_name;
14456 + snd_rpi_simple.dai_link = dai;
14457 + i2s_node = of_parse_phandle(pdev->dev.of_node,
14458 + "i2s-controller", 0);
14460 + pr_err("Failed to find i2s-controller DT node\n");
14464 + dai->cpus->of_node = i2s_node;
14465 + dai->platforms->of_node = i2s_node;
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);
14475 +static struct platform_driver snd_rpi_simple_driver = {
14477 + .name = "snd-rpi-simple",
14478 + .owner = THIS_MODULE,
14479 + .of_match_table = snd_rpi_simple_of_match,
14481 + .probe = snd_rpi_simple_probe,
14483 +MODULE_DEVICE_TABLE(of, snd_rpi_simple_of_match);
14485 +module_platform_driver(snd_rpi_simple_driver);
14487 +MODULE_AUTHOR("Tim Gover <tim.gover@raspberrypi.org>");
14488 +MODULE_DESCRIPTION("ASoC Raspberry Pi simple soundcard driver ");
14489 +MODULE_LICENSE("GPL v2");
14491 +++ b/sound/soc/bcm/rpi-wm8804-soundcard.c
14493 +// SPDX-License-Identifier: GPL-2.0
14495 + * rpi--wm8804.c -- ALSA SoC Raspberry Pi soundcard.
14497 + * Copyright (C) 2018 Raspberry Pi.
14499 + * Authors: Tim Gover <tim.gover@raspberrypi.org>
14501 + * Generic driver for Pi Hat WM8804 digi sounds cards
14503 + * Based upon code from:
14504 + * justboom-digi.c
14505 + * by Milan Neskovic <info@justboom.co>
14508 + * by Daniel Matuschek <info@crazy-audio.com>
14511 + * by Baswaraj <jaikumar@cem-solutions.net>
14513 + * hifiberry-digi.c
14514 + * Daniel Matuschek <info@crazy-audio.com>
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.
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.
14526 +#include <linux/gpio/consumer.h>
14527 +#include <linux/platform_device.h>
14528 +#include <linux/module.h>
14530 +#include <sound/core.h>
14531 +#include <sound/pcm.h>
14532 +#include <sound/pcm_params.h>
14533 +#include <sound/soc.h>
14535 +#include "../codecs/wm8804.h"
14537 +struct wm8804_clk_cfg {
14538 + unsigned int sysclk_freq;
14539 + unsigned int mclk_freq;
14540 + unsigned int mclk_div;
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);
14557 +static struct gpio_desc *snd_clk44gpio;
14558 +static struct gpio_desc *snd_clk48gpio;
14559 +static int wm8804_samplerate = 0;
14561 +/* Forward declarations */
14562 +static struct snd_soc_dai_link snd_allo_digione_dai[];
14563 +static struct snd_soc_card snd_rpi_wm8804;
14566 +#define CLK_44EN_RATE 22579200UL
14567 +#define CLK_48EN_RATE 24576000UL
14569 +static unsigned int snd_rpi_wm8804_enable_clock(unsigned int samplerate)
14571 + switch (samplerate) {
14577 + gpiod_set_value_cansleep(snd_clk44gpio, 1);
14578 + gpiod_set_value_cansleep(snd_clk48gpio, 0);
14579 + return CLK_44EN_RATE;
14581 + gpiod_set_value_cansleep(snd_clk48gpio, 1);
14582 + gpiod_set_value_cansleep(snd_clk44gpio, 0);
14583 + return CLK_48EN_RATE;
14587 +static void snd_rpi_wm8804_clk_cfg(unsigned int samplerate,
14588 + struct wm8804_clk_cfg *clk_cfg)
14590 + clk_cfg->sysclk_freq = 27000000;
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;
14597 + clk_cfg->mclk_freq = samplerate * 128;
14598 + clk_cfg->mclk_div = WM8804_MCLKDIV_128FS;
14601 + if (!(IS_ERR(snd_clk44gpio) || IS_ERR(snd_clk48gpio)))
14602 + clk_cfg->sysclk_freq = snd_rpi_wm8804_enable_clock(samplerate);
14605 +static int snd_rpi_wm8804_hw_params(struct snd_pcm_substream *substream,
14606 + struct snd_pcm_hw_params *params)
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;
14614 + struct wm8804_clk_cfg clk_cfg;
14615 + int samplerate = params_rate(params);
14617 + if (samplerate == wm8804_samplerate)
14620 + /* clear until all clocks are setup properly */
14621 + wm8804_samplerate = 0;
14623 + snd_rpi_wm8804_clk_cfg(samplerate, &clk_cfg);
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);
14629 + switch (samplerate) {
14631 + sampling_freq = 0x03;
14634 + sampling_freq = 0x00;
14637 + sampling_freq = 0x02;
14640 + sampling_freq = 0x08;
14643 + sampling_freq = 0x0a;
14646 + sampling_freq = 0x0c;
14649 + sampling_freq = 0x0e;
14652 + dev_err(rtd->card->dev,
14653 + "Failed to set WM8804 SYSCLK, unsupported samplerate %d\n",
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);
14661 + ret = snd_soc_dai_set_sysclk(codec_dai, WM8804_TX_CLKSRC_PLL,
14662 + clk_cfg.sysclk_freq, SND_SOC_CLOCK_OUT);
14664 + dev_err(rtd->card->dev,
14665 + "Failed to set WM8804 SYSCLK: %d\n", ret);
14669 + wm8804_samplerate = samplerate;
14671 + /* set sampling frequency status bits */
14672 + snd_soc_component_update_bits(component, WM8804_SPDTX4, 0x0f,
14675 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 64);
14678 +static struct snd_soc_ops snd_rpi_wm8804_ops = {
14679 + .hw_params = snd_rpi_wm8804_hw_params,
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()));
14687 +static struct snd_soc_dai_link snd_justboom_digi_dai[] = {
14689 + .name = "JustBoom Digi",
14690 + .stream_name = "JustBoom Digi HiFi",
14691 + SND_SOC_DAILINK_REG(justboom_digi),
14695 +static struct snd_rpi_wm8804_drvdata drvdata_justboom_digi = {
14696 + .card_name = "snd_rpi_justboom_digi",
14697 + .dai = snd_justboom_digi_dai,
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()));
14705 +static struct snd_soc_dai_link snd_iqaudio_digi_dai[] = {
14707 + .name = "IQAudIO Digi",
14708 + .stream_name = "IQAudIO Digi HiFi",
14709 + SND_SOC_DAILINK_REG(iqaudio_digi),
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",
14721 +static int snd_allo_digione_probe(struct platform_device *pdev)
14723 + pr_debug("%s\n", __func__);
14725 + if (IS_ERR(snd_clk44gpio) || IS_ERR(snd_clk48gpio)) {
14726 + dev_err(&pdev->dev, "devm_gpiod_get() failed\n");
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()));
14737 +static struct snd_soc_dai_link snd_allo_digione_dai[] = {
14739 + .name = "Allo DigiOne",
14740 + .stream_name = "Allo DigiOne HiFi",
14741 + SND_SOC_DAILINK_REG(allo_digione),
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,
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()));
14756 +static struct snd_soc_dai_link snd_hifiberry_digi_dai[] = {
14758 + .name = "HifiBerry Digi",
14759 + .stream_name = "HifiBerry Digi HiFi",
14760 + SND_SOC_DAILINK_REG(hifiberry_digi),
14764 +static int snd_hifiberry_digi_probe(struct platform_device *pdev)
14766 + pr_debug("%s\n", __func__);
14768 + if (IS_ERR(snd_clk44gpio) || IS_ERR(snd_clk48gpio))
14771 + snd_hifiberry_digi_dai->name = "HiFiBerry Digi+ Pro";
14772 + snd_hifiberry_digi_dai->stream_name = "HiFiBerry Digi+ Pro HiFi";
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,
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 },
14794 +static struct snd_soc_card snd_rpi_wm8804 = {
14795 + .driver_name = "RPi-WM8804",
14796 + .owner = THIS_MODULE,
14797 + .dai_link = NULL,
14801 +static int snd_rpi_wm8804_probe(struct platform_device *pdev)
14804 + const struct of_device_id *of_id;
14806 + snd_rpi_wm8804.dev = &pdev->dev;
14807 + of_id = of_match_node(snd_rpi_wm8804_of_match, pdev->dev.of_node);
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;
14815 + snd_soc_card_set_drvdata(&snd_rpi_wm8804, drvdata);
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;
14828 + snd_rpi_wm8804.dai_link = dai;
14829 + i2s_node = of_parse_phandle(pdev->dev.of_node,
14830 + "i2s-controller", 0);
14832 + pr_err("Failed to find i2s-controller DT node\n");
14836 + snd_rpi_wm8804.name = drvdata->card_name;
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);
14844 + if (drvdata->dai_name_dt)
14845 + of_property_read_string(i2s_node,
14846 + drvdata->dai_name_dt,
14849 + if (drvdata->dai_stream_name_dt)
14850 + of_property_read_string(i2s_node,
14851 + drvdata->dai_stream_name_dt,
14852 + &dai->stream_name);
14854 + dai->cpus->of_node = i2s_node;
14855 + dai->platforms->of_node = i2s_node;
14858 + * clk44gpio and clk48gpio are not required by all cards so
14859 + * don't check the error status.
14862 + devm_gpiod_get(&pdev->dev, "clock44", GPIOD_OUT_LOW);
14865 + devm_gpiod_get(&pdev->dev, "clock48", GPIOD_OUT_LOW);
14867 + if (drvdata->probe) {
14868 + ret = drvdata->probe(pdev);
14870 + dev_err(&pdev->dev, "Custom probe failed %d\n",
14876 + pr_debug("%s card: %s dai: %s stream: %s\n", __func__,
14877 + snd_rpi_wm8804.name,
14878 + dai->name, dai->stream_name);
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);
14888 +static struct platform_driver snd_rpi_wm8804_driver = {
14890 + .name = "snd-rpi-wm8804",
14891 + .owner = THIS_MODULE,
14892 + .of_match_table = snd_rpi_wm8804_of_match,
14894 + .probe = snd_rpi_wm8804_probe,
14896 +MODULE_DEVICE_TABLE(of, snd_rpi_wm8804_of_match);
14898 +module_platform_driver(snd_rpi_wm8804_driver);
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
14940 config SND_SOC_AD193X_SPI
14942 + tristate "Analog Devices AU193X CODEC - SPI"
14943 depends on SPI_MASTER
14944 select SND_SOC_AD193X
14946 config SND_SOC_AD193X_I2C
14948 + tristate "Analog Devices AU193X CODEC - I2C"
14950 select SND_SOC_AD193X
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.
14956 +config SND_SOC_MA120X0P
14957 + tristate "Infineon Merus(TM) MA120X0P Multilevel Class-D Audio amplifiers"
14960 + Enable support for Infineon MA120X0P Multilevel Class-D audio power
14963 config SND_SOC_MADERA
14965 default y if SND_SOC_CS47L15=y
14966 @@ -1333,6 +1344,10 @@ config SND_SOC_RT5616
14967 tristate "Realtek RT5616 CODEC"
14970 +config SND_SOC_PCM1794A
14974 config SND_SOC_RT5631
14975 tristate "Realtek ALC5631/RT5631 CODEC"
14977 @@ -1623,6 +1638,9 @@ config SND_SOC_TFA9879
14978 tristate "NXP Semiconductors TFA9879 amplifier"
14981 +config SND_SOC_TAS5713
14984 config SND_SOC_TFA989X
14985 tristate "NXP/Goodix TFA989X (TFA1) amplifiers"
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)"
14991 +config SND_SOC_I_SABRE_CODEC
14992 + tristate "Audiophonics I-SABRE Codec"
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_
15066 MODULE_DEVICE_TABLE(i2c, cs42xx8_i2c_id);
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 */ }
15073 +MODULE_DEVICE_TABLE(of, cs42xx8_i2c_of_match);
15075 static struct i2c_driver cs42xx8_i2c_driver = {
15079 - .of_match_table = cs42xx8_of_match,
15080 + .of_match_table = cs42xx8_i2c_of_match,
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, },
15090 +#if !IS_ENABLED(CONFIG_SND_SOC_CS42XX8_I2C)
15091 MODULE_DEVICE_TABLE(of, cs42xx8_of_match);
15092 EXPORT_SYMBOL_GPL(cs42xx8_of_match);
15095 int cs42xx8_probe(struct device *dev, struct regmap *regmap)
15098 +++ b/sound/soc/codecs/i-sabre-codec.c
15101 + * Driver for I-Sabre Q2M
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
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.
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.
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>
15128 +#include "i-sabre-codec.h"
15131 +/* I-Sabre Q2M Codec Private Data */
15132 +struct i_sabre_codec_priv {
15133 + struct regmap *regmap;
15134 + unsigned int fmt;
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 },
15148 +static bool i_sabre_codec_writeable(struct device *dev, unsigned int 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:
15163 +static bool i_sabre_codec_readable(struct device *dev, unsigned int 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:
15180 +static bool i_sabre_codec_volatile(struct device *dev, unsigned int reg)
15183 + case ISABRECODEC_REG_01:
15184 + case ISABRECODEC_REG_02:
15193 +/* Volume Scale */
15194 +static const DECLARE_TLV_DB_SCALE(volume_tlv, -10000, 100, 0);
15198 +static const char * const fir_filter_type_texts[] = {
15200 + "corrected minimum phase fast",
15201 + "minimum phase slow",
15202 + "minimum phase fast",
15203 + "linear phase slow",
15204 + "linear phase fast",
15205 + "apodizing fast",
15208 +static SOC_ENUM_SINGLE_DECL(i_sabre_fir_filter_type_enum,
15209 + ISABRECODEC_REG_22, 0, fir_filter_type_texts);
15212 +/* I2S / SPDIF Select */
15213 +static const char * const iis_spdif_sel_texts[] = {
15218 +static SOC_ENUM_SINGLE_DECL(i_sabre_iis_spdif_sel_enum,
15219 + ISABRECODEC_REG_24, 0, iis_spdif_sel_texts);
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),
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
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),
15243 +static int i_sabre_codec_dai_startup_slave(
15244 + struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
15246 + struct snd_soc_component *component = dai->component;
15249 + ret = snd_pcm_hw_constraint_list(substream->runtime,
15250 + 0, SNDRV_PCM_HW_PARAM_RATE, &constraints_slave);
15252 + dev_err(component->card->dev, "Failed to setup rates constraints: %d\n", ret);
15258 +static int i_sabre_codec_dai_startup(
15259 + struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
15261 + struct snd_soc_component *component = dai->component;
15262 + struct i_sabre_codec_priv *i_sabre_codec
15263 + = snd_soc_component_get_drvdata(component);
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);
15270 + return (-EINVAL);
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)
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;
15284 + dev_dbg(component->card->dev, "hw_params %u Hz, %u channels\n",
15285 + params_rate(params), params_channels(params));
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);
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);
15301 + /* Notify Sampling Frequency */
15302 + switch (params_rate(params))
15310 + snd_soc_component_update_bits(component, ISABRECODEC_REG_10, 0x01, 0x00);
15319 + snd_soc_component_update_bits(component, ISABRECODEC_REG_10, 0x01, 0x01);
15326 +static int i_sabre_codec_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
15328 + struct snd_soc_component *component = dai->component;
15329 + struct i_sabre_codec_priv *i_sabre_codec
15330 + = snd_soc_component_get_drvdata(component);
15332 + /* interface format */
15333 + switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
15334 + case SND_SOC_DAIFMT_I2S:
15337 + case SND_SOC_DAIFMT_RIGHT_J:
15338 + case SND_SOC_DAIFMT_LEFT_J:
15340 + return (-EINVAL);
15343 + /* clock inversion */
15344 + if ((fmt & SND_SOC_DAIFMT_INV_MASK) != SND_SOC_DAIFMT_NB_NF) {
15345 + return (-EINVAL);
15348 + /* Set Audio Data Format */
15349 + i_sabre_codec->fmt = fmt;
15354 +static int i_sabre_codec_dac_mute(struct snd_soc_dai *dai, int mute, int direction)
15356 + struct snd_soc_component *component = dai->component;
15359 + snd_soc_component_update_bits(component, ISABRECODEC_REG_21, 0x01, 0x01);
15361 + snd_soc_component_update_bits(component, ISABRECODEC_REG_21, 0x01, 0x00);
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,
15375 +static struct snd_soc_dai_driver i_sabre_codec_dai = {
15376 + .name = "i-sabre-codec-dai",
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,
15387 + .ops = &i_sabre_codec_dai_ops,
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),
15396 +static const struct regmap_config i_sabre_codec_regmap = {
15399 + .max_register = ISABRECODEC_MAX_REG,
15401 + .reg_defaults = i_sabre_codec_reg_defaults,
15402 + .num_reg_defaults = ARRAY_SIZE(i_sabre_codec_reg_defaults),
15404 + .writeable_reg = i_sabre_codec_writeable,
15405 + .readable_reg = i_sabre_codec_readable,
15406 + .volatile_reg = i_sabre_codec_volatile,
15408 + .cache_type = REGCACHE_RBTREE,
15412 +static int i_sabre_codec_probe(struct device *dev, struct regmap *regmap)
15414 + struct i_sabre_codec_priv *i_sabre_codec;
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);
15423 + i_sabre_codec->regmap = regmap;
15425 + dev_set_drvdata(dev, i_sabre_codec);
15427 + ret = snd_soc_register_component(dev,
15428 + &i_sabre_codec_codec_driver, &i_sabre_codec_dai, 1);
15430 + dev_err(dev, "Failed to register CODEC: %d\n", ret);
15437 +static void i_sabre_codec_remove(struct device *dev)
15439 + snd_soc_unregister_component(dev);
15443 +static int i_sabre_codec_i2c_probe(
15444 + struct i2c_client *i2c, const struct i2c_device_id *id)
15446 + struct regmap *regmap;
15448 + regmap = devm_regmap_init_i2c(i2c, &i_sabre_codec_regmap);
15449 + if (IS_ERR(regmap)) {
15450 + return PTR_ERR(regmap);
15453 + return i_sabre_codec_probe(&i2c->dev, regmap);
15456 +static void i_sabre_codec_i2c_remove(struct i2c_client *i2c)
15458 + i_sabre_codec_remove(&i2c->dev);
15462 +static const struct i2c_device_id i_sabre_codec_i2c_id[] = {
15463 + { "i-sabre-codec", },
15466 +MODULE_DEVICE_TABLE(i2c, i_sabre_codec_i2c_id);
15468 +static const struct of_device_id i_sabre_codec_of_match[] = {
15469 + { .compatible = "audiophonics,i-sabre-codec", },
15472 +MODULE_DEVICE_TABLE(of, i_sabre_codec_of_match);
15474 +static struct i2c_driver i_sabre_codec_i2c_driver = {
15476 + .name = "i-sabre-codec-i2c",
15477 + .owner = THIS_MODULE,
15478 + .of_match_table = of_match_ptr(i_sabre_codec_of_match),
15480 + .probe = i_sabre_codec_i2c_probe,
15481 + .remove = i_sabre_codec_i2c_remove,
15482 + .id_table = i_sabre_codec_i2c_id,
15484 +module_i2c_driver(i_sabre_codec_i2c_driver);
15487 +MODULE_DESCRIPTION("ASoC I-Sabre Q2M codec driver");
15488 +MODULE_AUTHOR("Audiophonics <http://www.audiophonics.fr>");
15489 +MODULE_LICENSE("GPL");
15491 +++ b/sound/soc/codecs/i-sabre-codec.h
15494 + * Driver for I-Sabre Q2M
15496 + * Author: Satoru Kawase
15497 + * Modified by: Xiao Qingyong
15498 + * Copyright 2018 Audiophonics
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.
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.
15510 +#ifndef _SND_SOC_ISABRECODEC
15511 +#define _SND_SOC_ISABRECODEC
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
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,
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 */
15534 +#endif /* _SND_SOC_ISABRECODEC */
15536 +++ b/sound/soc/codecs/ma120x0p.c
15538 +// SPDX-License-Identifier: GPL-2.0-or-later
15540 + * ASoC Driver for Infineon Merus(TM) ma120x0p multi-level class-D amplifier
15542 + * Authors: Ariel Muszkat <ariel.muszkat@gmail.com>
15543 + * Jorgen Kragh Jakobsen <jorgen.kraghjakobsen@infineon.com>
15545 + * Copyright (C) 2019 Infineon Technologies AG
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>
15570 +#include <linux/kernel.h>
15571 +#include <linux/string.h>
15572 +#include <linux/fs.h>
15573 +#include <linux/uaccess.h>
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---
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---
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---
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---
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---
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---
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---
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---
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---
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---
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---
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---
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---
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---
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---
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---
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---
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---
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
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) }
16342 +static struct i2c_client *i2c;
16344 +struct ma120x0p_priv {
16345 + struct regmap *regmap;
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;
16354 +static struct ma120x0p_priv *priv_data;
16356 +//Used to share the IRQ number within this file
16357 +static unsigned int irqNumber;
16359 +// Function prototype for the custom IRQ handler function
16360 +static irqreturn_t ma120x0p_irq_handler(int irq, void *data);
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"};
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"};
16376 +static const char * const pwr_mode_prof_text[] = {"PMF0", "PMF1", "PMF2",
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,
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,
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);
16414 +static const char * const pwr_mode_texts[] = {
16415 + "Dynamic power mode",
16421 +static const int pwr_mode_values[] = {
16428 +static SOC_VALUE_ENUM_SINGLE_DECL(pwr_mode_ctrl,
16429 + ma_pm_man__a, 0, 0x70,
16431 + pwr_mode_values);
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);
16437 +static const struct snd_kcontrol_new ma120x0p_snd_controls[] = {
16439 + SOC_SINGLE_RANGE_TLV("A.Mstr Vol Volume",
16440 + ma_vol_db_master__a, 0, 0x18, 0xa8, 1, ma120x0p_vol_tlv),
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),
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),
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),
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),
16469 + //Power modes profiles
16470 + SOC_ENUM("Q.PM Prof", pwr_mode_prof_ctrl),
16472 + // Power mode selection (Dynamic,1,2,3)
16473 + SOC_ENUM("R.Power Mode", pwr_mode_ctrl),
16477 +static int ma120x0p_hw_params(struct snd_pcm_substream *substream,
16478 + struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
16482 + struct snd_soc_component *component = dai->component;
16484 + priv_data->component = component;
16486 + switch (params_format(params)) {
16487 + case SNDRV_PCM_FORMAT_S16_LE:
16490 + case SNDRV_PCM_FORMAT_S24_LE:
16493 + case SNDRV_PCM_FORMAT_S32_LE:
16497 + dev_err(dai->dev, "Unsupported word length: %u\n",
16498 + params_format(params));
16502 + // set word length
16503 + snd_soc_component_update_bits(component, ma_i2s_framesize__a,
16504 + ma_i2s_framesize__mask, blen);
16509 +static int ma120x0p_mute_stream(struct snd_soc_dai *dai, int mute, int stream)
16513 + struct ma120x0p_priv *ma120x0p;
16515 + struct snd_soc_component *component = dai->component;
16517 + ma120x0p = snd_soc_component_get_drvdata(component);
16524 + gpiod_set_value_cansleep(priv_data->mute_gpio, val);
16529 +static const struct snd_soc_dai_ops ma120x0p_dai_ops = {
16530 + .hw_params = ma120x0p_hw_params,
16531 + .mute_stream = ma120x0p_mute_stream,
16534 +static struct snd_soc_dai_driver ma120x0p_dai = {
16535 + .name = "ma120x0p-amp",
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
16545 + .ops = &ma120x0p_dai_ops,
16549 +static int ma120x0p_clear_err(struct snd_soc_component *component)
16553 + struct ma120x0p_priv *ma120x0p;
16555 + ma120x0p = snd_soc_component_get_drvdata(component);
16557 + ret = snd_soc_component_update_bits(component,
16558 + ma_eh_clear__a, ma_eh_clear__mask, 0x00);
16562 + ret = snd_soc_component_update_bits(component,
16563 + ma_eh_clear__a, ma_eh_clear__mask, 0x04);
16567 + ret = snd_soc_component_update_bits(component,
16568 + ma_eh_clear__a, ma_eh_clear__mask, 0x00);
16575 +static void ma120x0p_remove(struct snd_soc_component *component)
16577 + struct ma120x0p_priv *ma120x0p;
16579 + ma120x0p = snd_soc_component_get_drvdata(component);
16582 +static int ma120x0p_probe(struct snd_soc_component *component)
16584 + struct ma120x0p_priv *ma120x0p;
16588 + i2c = container_of(component->dev, struct i2c_client, dev);
16590 + ma120x0p = snd_soc_component_get_drvdata(component);
16593 + ma120x0p_clear_err(component);
16597 + // set serial audio format I2S and enable audio processor
16598 + ret = snd_soc_component_write(component, ma_i2s_format__a, 0x08);
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);
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);
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);
16621 + // set volume to 0dB
16622 + ret = snd_soc_component_write(component, ma_vol_db_master__a, 0x18);
16626 + // set ch0 lim thresh to -15dB
16627 + ret = snd_soc_component_write(component, ma_thr_db_ch0__a, 0x27);
16631 + // set ch1 lim thresh to -15dB
16632 + ret = snd_soc_component_write(component, ma_thr_db_ch1__a, 0x27);
16636 + //Check for errors
16637 + ret = snd_soc_component_test_bits(component, ma_error_acc__a, 0x00, 0);
16640 + ret = snd_soc_component_test_bits(component, ma_error_acc__a, 0x01, 0);
16643 + ret = snd_soc_component_test_bits(component, ma_error_acc__a, 0x02, 0);
16646 + ret = snd_soc_component_test_bits(component, ma_error_acc__a, 0x08, 0);
16649 + ret = snd_soc_component_test_bits(component, ma_error_acc__a, 0x10, 0);
16652 + ret = snd_soc_component_test_bits(component, ma_error_acc__a, 0x20, 0);
16655 + ret = snd_soc_component_test_bits(component, ma_error_acc__a, 0x40, 0);
16658 + ret = snd_soc_component_test_bits(component, ma_error_acc__a, 0x80, 0);
16665 +static int ma120x0p_set_bias_level(struct snd_soc_component *component,
16666 + enum snd_soc_bias_level level)
16670 + struct ma120x0p_priv *ma120x0p;
16672 + ma120x0p = snd_soc_component_get_drvdata(component);
16675 + case SND_SOC_BIAS_ON:
16678 + case SND_SOC_BIAS_PREPARE:
16681 + case SND_SOC_BIAS_STANDBY:
16682 + ret = gpiod_get_value_cansleep(priv_data->enable_gpio);
16684 + dev_err(component->dev, "Device ma120x0p disabled in STANDBY BIAS: %d\n",
16690 + case SND_SOC_BIAS_OFF:
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"),
16702 +static const struct snd_soc_dapm_route ma120x0p_dapm_routes[] = {
16703 + { "OUT_B", NULL, "Playback" },
16704 + { "OUT_A", NULL, "Playback" },
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,
16722 +static const struct reg_default ma120x0p_reg_defaults[] = {
16726 +static bool ma120x0p_reg_volatile(struct device *dev, unsigned int reg)
16729 + case ma_error__a:
16736 +static const struct of_device_id ma120x0p_of_match[] = {
16737 + { .compatible = "ma,ma120x0p", },
16741 +MODULE_DEVICE_TABLE(of, ma120x0p_of_match);
16743 +static struct regmap_config ma120x0p_regmap_config = {
16747 + .max_register = 255,
16748 + .volatile_reg = ma120x0p_reg_volatile,
16750 + .cache_type = REGCACHE_RBTREE,
16751 + .reg_defaults = ma120x0p_reg_defaults,
16752 + .num_reg_defaults = ARRAY_SIZE(ma120x0p_reg_defaults),
16755 +static int ma120x0p_i2c_probe(struct i2c_client *i2c,
16756 + const struct i2c_device_id *id)
16760 + priv_data = devm_kzalloc(&i2c->dev, sizeof(*priv_data), GFP_KERNEL);
16763 + i2c_set_clientdata(i2c, priv_data);
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);
16771 + //Startup sequence
16773 + //Make sure the device is muted
16774 + priv_data->mute_gpio = devm_gpiod_get_optional(&i2c->dev, "mute_gp",
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);
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);
16796 + //Enable booster and wait 200ms until stable PVDD
16797 + gpiod_set_value_cansleep(priv_data->booster_gpio, 1);
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);
16811 + //Optional use of ma120x0pp error line as an interrupt trigger to
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);
16823 + if (priv_data->error_gpio != NULL) {
16824 + irqNumber = gpiod_to_irq(priv_data->error_gpio);
16826 + ret = devm_request_threaded_irq(&i2c->dev,
16827 + irqNumber, ma120x0p_irq_handler,
16828 + NULL, IRQF_TRIGGER_FALLING,
16829 + "ma120x0p", priv_data);
16831 + dev_warn(&i2c->dev, "Failed to request IRQ: %d\n",
16835 + ret = devm_snd_soc_register_component(&i2c->dev,
16836 + &ma120x0p_component_driver, &ma120x0p_dai, 1);
16841 +static irqreturn_t ma120x0p_irq_handler(int irq, void *data)
16843 + gpiod_set_value_cansleep(priv_data->mute_gpio, 0);
16844 + gpiod_set_value_cansleep(priv_data->enable_gpio, 1);
16845 + return IRQ_HANDLED;
16848 +static void ma120x0p_i2c_remove(struct i2c_client *i2c)
16850 + snd_soc_unregister_component(&i2c->dev);
16851 + i2c_set_clientdata(i2c, NULL);
16853 + gpiod_set_value_cansleep(priv_data->mute_gpio, 0);
16855 + gpiod_set_value_cansleep(priv_data->enable_gpio, 1);
16857 + gpiod_set_value_cansleep(priv_data->booster_gpio, 0);
16860 + kfree(priv_data);
16863 +static void ma120x0p_i2c_shutdown(struct i2c_client *i2c)
16865 + snd_soc_unregister_component(&i2c->dev);
16866 + i2c_set_clientdata(i2c, NULL);
16868 + gpiod_set_value_cansleep(priv_data->mute_gpio, 0);
16870 + gpiod_set_value_cansleep(priv_data->enable_gpio, 1);
16872 + gpiod_set_value_cansleep(priv_data->booster_gpio, 0);
16875 + kfree(priv_data);
16878 +static const struct i2c_device_id ma120x0p_i2c_id[] = {
16879 + { "ma120x0p", 0 },
16883 +MODULE_DEVICE_TABLE(i2c, ma120x0p_i2c_id);
16885 +static struct i2c_driver ma120x0p_i2c_driver = {
16887 + .name = "ma120x0p",
16888 + .owner = THIS_MODULE,
16889 + .of_match_table = ma120x0p_of_match,
16891 + .probe = ma120x0p_i2c_probe,
16892 + .remove = ma120x0p_i2c_remove,
16893 + .shutdown = ma120x0p_i2c_shutdown,
16894 + .id_table = ma120x0p_i2c_id
16897 +static int __init ma120x0p_modinit(void)
16901 + ret = i2c_add_driver(&ma120x0p_i2c_driver);
16903 + pr_err("Failed to register MA120X0P I2C driver: %d\n", ret);
16908 +module_init(ma120x0p_modinit);
16910 +static void __exit ma120x0p_exit(void)
16912 + i2c_del_driver(&ma120x0p_i2c_driver);
16914 +module_exit(ma120x0p_exit);
16916 +MODULE_AUTHOR("Ariel Muszkat ariel.muszkat@gmail.com>");
16917 +MODULE_DESCRIPTION("ASoC driver for ma120x0p");
16918 +MODULE_LICENSE("GPL v2");
16920 +++ b/sound/soc/codecs/pcm1794a.c
16923 + * Driver for the PCM1794A codec
16925 + * Author: Florian Meier <florian.meier@koalo.de>
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.
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.
16939 +#include <linux/init.h>
16940 +#include <linux/module.h>
16941 +#include <linux/platform_device.h>
16943 +#include <sound/soc.h>
16945 +static struct snd_soc_dai_driver pcm1794a_dai = {
16946 + .name = "pcm1794a-hifi",
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
16956 +static struct snd_soc_component_driver soc_component_dev_pcm1794a;
16958 +static int pcm1794a_probe(struct platform_device *pdev)
16960 + return snd_soc_register_component(&pdev->dev, &soc_component_dev_pcm1794a,
16961 + &pcm1794a_dai, 1);
16964 +static int pcm1794a_remove(struct platform_device *pdev)
16966 + snd_soc_unregister_component(&pdev->dev);
16970 +static const struct of_device_id pcm1794a_of_match[] = {
16971 + { .compatible = "ti,pcm1794a", },
16974 +MODULE_DEVICE_TABLE(of, pcm1794a_of_match);
16976 +static struct platform_driver pcm1794a_component_driver = {
16977 + .probe = pcm1794a_probe,
16978 + .remove = pcm1794a_remove,
16980 + .name = "pcm1794a-codec",
16981 + .owner = THIS_MODULE,
16982 + .of_match_table = of_match_ptr(pcm1794a_of_match),
16986 +module_platform_driver(pcm1794a_component_driver);
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(
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,
17001 static const struct snd_pcm_hw_constraint_list constraints_slave = {
17003 +++ b/sound/soc/codecs/tas5713.c
17006 + * ASoC Driver for TAS5713
17008 + * Author: Sebastian Eickhoff <basti.eickhoff@googlemail.com>
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.
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.
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>
17039 +#include <linux/kernel.h>
17040 +#include <linux/string.h>
17041 +#include <linux/fs.h>
17042 +#include <asm/uaccess.h>
17044 +#include "tas5713.h"
17047 +static struct i2c_client *i2c;
17049 +struct tas5713_priv {
17050 + struct regmap *regmap;
17052 + struct snd_soc_component *component;
17055 +static struct tas5713_priv *priv_data;
17061 + * _ _ ___ _ ___ _ _
17062 + * /_\ | | / __| /_\ / __|___ _ _| |_ _ _ ___| |___
17063 + * / _ \| |__\__ \/ _ \ | (__/ _ \ ' \ _| '_/ _ \ (_-<
17064 + * /_/ \_\____|___/_/ \_\ \___\___/_||_\__|_| \___/_/__/
17068 +static const DECLARE_TLV_DB_SCALE(tas5713_vol_tlv, -10000, 50, 1);
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)
17080 + * __ __ _ _ ___ _
17081 + * | \/ |__ _ __| |_ (_)_ _ ___ | \ _ _(_)_ _____ _ _
17082 + * | |\/| / _` / _| ' \| | ' \/ -_) | |) | '_| \ V / -_) '_|
17083 + * |_| |_\__,_\__|_||_|_|_||_\___| |___/|_| |_|\_/\___|_|
17087 +static int tas5713_hw_params(struct snd_pcm_substream *substream,
17088 + struct snd_pcm_hw_params *params,
17089 + struct snd_soc_dai *dai)
17093 + struct snd_soc_component *component = dai->component;
17094 + priv_data->component = component;
17096 + switch (params_format(params)) {
17097 + case SNDRV_PCM_FORMAT_S16_LE:
17100 + case SNDRV_PCM_FORMAT_S20_3LE:
17103 + case SNDRV_PCM_FORMAT_S24_LE:
17106 + case SNDRV_PCM_FORMAT_S32_LE:
17110 + dev_err(dai->dev, "Unsupported word length: %u\n",
17111 + params_format(params));
17115 + // set word length
17116 + snd_soc_component_update_bits(component, TAS5713_SERIAL_DATA_INTERFACE, 0x7, blen);
17122 +static int tas5713_mute_stream(struct snd_soc_dai *dai, int mute, int stream)
17124 + unsigned int val = 0;
17126 + struct tas5713_priv *tas5713;
17127 + struct snd_soc_component *component = dai->component;
17128 + tas5713 = snd_soc_component_get_drvdata(component);
17131 + val = TAS5713_SOFT_MUTE_ALL;
17134 + return regmap_write(tas5713->regmap, TAS5713_SOFT_MUTE, val);
17138 +static const struct snd_soc_dai_ops tas5713_dai_ops = {
17139 + .hw_params = tas5713_hw_params,
17140 + .mute_stream = tas5713_mute_stream,
17144 +static struct snd_soc_dai_driver tas5713_dai = {
17145 + .name = "tas5713-hifi",
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 ),
17153 + .ops = &tas5713_dai_ops,
17161 + * / __|___ __| |___ __ | \ _ _(_)_ _____ _ _
17162 + * | (__/ _ \/ _` / -_) _| | |) | '_| \ V / -_) '_|
17163 + * \___\___/\__,_\___\__| |___/|_| |_|\_/\___|_|
17167 +static void tas5713_remove(struct snd_soc_component *component)
17169 + struct tas5713_priv *tas5713;
17171 + tas5713 = snd_soc_component_get_drvdata(component);
17175 +static int tas5713_probe(struct snd_soc_component *component)
17177 + struct tas5713_priv *tas5713;
17180 + i2c = container_of(component->dev, struct i2c_client, dev);
17182 + tas5713 = snd_soc_component_get_drvdata(component);
17185 + ret = snd_soc_component_write(component, TAS5713_ERROR_STATUS, 0x00);
17186 + if (ret < 0) return ret;
17188 + // Trim oscillator
17189 + ret = snd_soc_component_write(component, TAS5713_OSC_TRIM, 0x00);
17190 + if (ret < 0) return ret;
17194 + ret = snd_soc_component_write(component, TAS5713_ERROR_STATUS, 0x00);
17195 + if (ret < 0) return ret;
17198 + ret = snd_soc_component_write(component, TAS5713_SERIAL_DATA_INTERFACE, 0x05);
17199 + if (ret < 0) return ret;
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;
17207 + // Set volume to 0db
17208 + ret = snd_soc_component_write(component, TAS5713_VOL_MASTER, 0x00);
17209 + if (ret < 0) return ret;
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);
17217 + printk(KERN_INFO "TAS5713 CODEC PROBE: InitSeq returns: %d\n", ret);
17222 + ret = snd_soc_component_write(component, TAS5713_SYSTEM_CTRL2, 0x00);
17223 + if (ret < 0) return ret;
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),
17240 + * ___ ___ ___ ___ _
17241 + * |_ _|_ ) __| | \ _ _(_)_ _____ _ _
17242 + * | | / / (__ | |) | '_| \ V / -_) '_|
17243 + * |___/___\___| |___/|_| |_|\_/\___|_|
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
17255 +static bool tas5713_reg_volatile(struct device *dev, unsigned int reg)
17258 + case TAS5713_DEVICE_ID:
17259 + case TAS5713_ERROR_STATUS:
17260 + case TAS5713_CLOCK_CTRL:
17268 +static const struct of_device_id tas5713_of_match[] = {
17269 + { .compatible = "ti,tas5713", },
17272 +MODULE_DEVICE_TABLE(of, tas5713_of_match);
17275 +static struct regmap_config tas5713_regmap_config = {
17279 + .max_register = TAS5713_MAX_REGISTER,
17280 + .volatile_reg = tas5713_reg_volatile,
17282 + .cache_type = REGCACHE_RBTREE,
17283 + .reg_defaults = tas5713_reg_defaults,
17284 + .num_reg_defaults = ARRAY_SIZE(tas5713_reg_defaults),
17288 +static int tas5713_i2c_probe(struct i2c_client *i2c,
17289 + const struct i2c_device_id *id)
17293 + priv_data = devm_kzalloc(&i2c->dev, sizeof *priv_data, GFP_KERNEL);
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);
17303 + i2c_set_clientdata(i2c, priv_data);
17305 + ret = snd_soc_register_component(&i2c->dev,
17306 + &soc_codec_dev_tas5713, &tas5713_dai, 1);
17312 +static void tas5713_i2c_remove(struct i2c_client *i2c)
17314 + snd_soc_unregister_component(&i2c->dev);
17315 + i2c_set_clientdata(i2c, NULL);
17317 + kfree(priv_data);
17321 +static const struct i2c_device_id tas5713_i2c_id[] = {
17322 + { "tas5713", 0 },
17326 +MODULE_DEVICE_TABLE(i2c, tas5713_i2c_id);
17329 +static struct i2c_driver tas5713_i2c_driver = {
17331 + .name = "tas5713",
17332 + .owner = THIS_MODULE,
17333 + .of_match_table = tas5713_of_match,
17335 + .probe = tas5713_i2c_probe,
17336 + .remove = tas5713_i2c_remove,
17337 + .id_table = tas5713_i2c_id
17341 +static int __init tas5713_modinit(void)
17345 + ret = i2c_add_driver(&tas5713_i2c_driver);
17347 + printk(KERN_ERR "Failed to register tas5713 I2C driver: %d\n",
17353 +module_init(tas5713_modinit);
17356 +static void __exit tas5713_exit(void)
17358 + i2c_del_driver(&tas5713_i2c_driver);
17360 +module_exit(tas5713_exit);
17363 +MODULE_AUTHOR("Sebastian Eickhoff <basti.eickhoff@googlemail.com>");
17364 +MODULE_DESCRIPTION("ASoC driver for TAS5713");
17365 +MODULE_LICENSE("GPL v2");
17367 +++ b/sound/soc/codecs/tas5713.h
17370 + * ASoC Driver for TAS5713
17372 + * Author: Sebastian Eickhoff <basti.eickhoff@googlemail.com>
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.
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.
17385 +#ifndef _TAS5713_H
17386 +#define _TAS5713_H
17389 +// TAS5713 I2C-bus register addresses
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
17409 +#define TAS5713_START_STOP_PERIOD 0x1A
17410 +#define TAS5713_OSC_TRIM 0x1B
17411 +#define TAS5713_BKND_ERR 0x1C
17413 +#define TAS5713_INPUT_MUX 0x20
17414 +#define TAS5713_SRC_SELECT_CH4 0x21
17415 +#define TAS5713_PWM_MUX 0x25
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
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
17437 +#define TAS5713_CH4_BQ0 0x5A
17438 +#define TAS5713_CH4_BQ1 0x5B
17439 +#define TAS5713_CH3_BQ0 0x5E
17440 +#define TAS5713_CH3_BQ1 0x5F
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
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
17458 +#define TAS5713_IDF_POST_SCALE 0x62
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
17469 +#define TAS5713_UPDATE_DEV_ADDR_KEY 0xF8
17470 +#define TAS5713_UPDATE_DEV_ADDR_REG 0xF9
17472 +#define TAS5713_REGISTER_COUNT 0x46
17473 +#define TAS5713_MAX_REGISTER 0xF9
17476 +// Bitmasks for registers
17477 +#define TAS5713_SOFT_MUTE_ALL 0x07
17481 +struct tas5713_init_command {
17483 + const char *const data;
17486 +static const struct tas5713_init_command tas5713_init_sequence[] = {
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" },
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" },
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" },
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
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;
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;
17594 + ret = snd_soc_dai_set_fmt(codec_dai, codec_dai_fmt);
17595 if (ret != 0 && ret != -ENOTSUPP)
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;
17604 - if (chip->quirk_flags & QUIRK_FLAG_DISABLE_AUTOSUSPEND)
17605 + if (chip->quirk_flags & QUIRK_FLAG_DISABLE_AUTOSUSPEND) {
17607 + * Grab the interface, because on a webcam uvcvideo may race
17608 + * with snd-usb-audio during probe and re-enable autosuspend.
17610 + usb_autopm_get_interface(intf);
17611 usb_disable_autosuspend(interface_to_usbdev(intf));
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 */