1 From 74bd4038e58c360675a25d766634b424239c4b98 Mon Sep 17 00:00:00 2001
2 From: Florian Meier <florian.meier@koalo.de>
3 Date: Mon, 25 Jan 2016 15:48:59 +0000
4 Subject: [PATCH 0106/1085] Add support for all the downstream rpi sound card
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 ASoC:ma120x0p: Corrects the volume level display
940 Fixes the wrongly changed 'limiter volume' display back to -50dB minimum
941 and sets the correct minimum volume level to -144dB to be aligned with
942 the controls and display in alsamixer etc.
944 Signed-off-by: Joerg Schambacher <joerg@hifiberry.com>
946 ASoC: bcm: Fix Rpi-PROTO and audioinjector.net Pi
948 As of kernel 5.19 the WM8731 driver has separate I2C and SPI support
949 modules. Change the Kconfig definitions for the audioinjector.net Pi
950 and Rpi-PROTO soundcards to select SND_SOC_WM8731_I2C.
952 See: https://github.com/raspberrypi/linux/issues/5364
954 Signed-off-by: Phil Elwell <phil@raspberrypi.com>
956 ASoC: adau1977: Add correct compatible strings
958 Signed-off-by: Phil Elwell <phil@raspberrypi.com>
960 ASoC: bcm2835-i2s: Use phys addresses for DAI DMA
962 Contrary to what struct snd_dmaengine_dai_dma_data suggests, the
963 configuration of addresses of DMA slave interfaces should be done in
964 CPU physical addresses.
966 Signed-off-by: Phil Elwell <phil@raspberrypi.com>
968 rpi sound cards: Fix Codec Zero rate switching
970 The Raspberry Pi Codec Zero (and IQaudIO Codec) don't notify the DA7213
971 codec when it needs to change PLL frequencies. As a result, audio can
972 be played at the wrong rate - play a 48kHz sound immediately after a
973 44.1kHz sound to see the effect, but in some configurations the codec
974 can lock into the wrong state and always get some rates wrong.
976 Add the necessary notification to fix the issue.
978 Signed-off-by: Phil Elwell <phil@raspberrypi.com>
980 .../devicetree/bindings/vendor-prefixes.txt | 463 ++++++
981 .../devicetree/bindings/vendor-prefixes.yaml | 2 +
982 drivers/clk/Kconfig | 6 +
983 drivers/clk/Makefile | 2 +
984 drivers/clk/clk-hifiberry-dachd.c | 331 ++++
985 drivers/clk/clk-hifiberry-dacpro.c | 181 +++
986 sound/soc/bcm/Kconfig | 306 ++++
987 sound/soc/bcm/Makefile | 71 +-
988 sound/soc/bcm/allo-boss-dac.c | 457 ++++++
989 sound/soc/bcm/allo-boss2-dac.c | 1130 ++++++++++++++
990 sound/soc/bcm/allo-katana-codec.c | 386 +++++
991 sound/soc/bcm/allo-piano-dac-plus.c | 1064 +++++++++++++
992 sound/soc/bcm/allo-piano-dac.c | 122 ++
993 .../bcm/audioinjector-isolated-soundcard.c | 183 +++
994 sound/soc/bcm/audioinjector-octo-soundcard.c | 346 +++++
995 sound/soc/bcm/audioinjector-pi-soundcard.c | 189 +++
996 sound/soc/bcm/audiosense-pi.c | 248 +++
997 sound/soc/bcm/bcm2835-i2s.c | 18 +-
998 sound/soc/bcm/chipdip-dac.c | 275 ++++
999 sound/soc/bcm/dacberry400.c | 259 ++++
1000 sound/soc/bcm/digidac1-soundcard.c | 421 +++++
1001 sound/soc/bcm/dionaudio_loco-v2.c | 117 ++
1002 sound/soc/bcm/dionaudio_loco.c | 117 ++
1003 sound/soc/bcm/fe-pi-audio.c | 154 ++
1004 sound/soc/bcm/googlevoicehat-codec.c | 214 +++
1005 sound/soc/bcm/hifiberry_dacplus.c | 527 +++++++
1006 sound/soc/bcm/hifiberry_dacplusadc.c | 398 +++++
1007 sound/soc/bcm/hifiberry_dacplusadcpro.c | 605 ++++++++
1008 sound/soc/bcm/hifiberry_dacplusdsp.c | 90 ++
1009 sound/soc/bcm/hifiberry_dacplushd.c | 238 +++
1010 sound/soc/bcm/i-sabre-q2m.c | 159 ++
1011 sound/soc/bcm/iqaudio-codec.c | 278 ++++
1012 sound/soc/bcm/iqaudio-dac.c | 224 +++
1013 sound/soc/bcm/justboom-both.c | 267 ++++
1014 sound/soc/bcm/justboom-dac.c | 147 ++
1015 sound/soc/bcm/pifi-40.c | 284 ++++
1016 sound/soc/bcm/pisound.c | 1241 +++++++++++++++
1017 sound/soc/bcm/rpi-cirrus.c | 1025 ++++++++++++
1018 sound/soc/bcm/rpi-proto.c | 147 ++
1019 sound/soc/bcm/rpi-simple-soundcard.c | 487 ++++++
1020 sound/soc/bcm/rpi-wm8804-soundcard.c | 410 +++++
1021 sound/soc/codecs/Kconfig | 26 +-
1022 sound/soc/codecs/Makefile | 8 +
1023 sound/soc/codecs/adau1977-i2c.c | 10 +
1024 sound/soc/codecs/cs42xx8-i2c.c | 9 +-
1025 sound/soc/codecs/cs42xx8.c | 10 +
1026 sound/soc/codecs/i-sabre-codec.c | 389 +++++
1027 sound/soc/codecs/i-sabre-codec.h | 42 +
1028 sound/soc/codecs/ma120x0p.c | 1380 +++++++++++++++++
1029 sound/soc/codecs/pcm1794a.c | 69 +
1030 sound/soc/codecs/pcm512x.c | 2 +-
1031 sound/soc/codecs/tas5713.c | 360 +++++
1032 sound/soc/codecs/tas5713.h | 210 +++
1033 sound/soc/soc-core.c | 10 +-
1034 sound/usb/card.c | 8 +-
1035 sound/usb/quirks.c | 2 +
1036 56 files changed, 16103 insertions(+), 21 deletions(-)
1037 create mode 100644 Documentation/devicetree/bindings/vendor-prefixes.txt
1038 create mode 100644 drivers/clk/clk-hifiberry-dachd.c
1039 create mode 100644 drivers/clk/clk-hifiberry-dacpro.c
1040 create mode 100644 sound/soc/bcm/allo-boss-dac.c
1041 create mode 100644 sound/soc/bcm/allo-boss2-dac.c
1042 create mode 100644 sound/soc/bcm/allo-katana-codec.c
1043 create mode 100644 sound/soc/bcm/allo-piano-dac-plus.c
1044 create mode 100644 sound/soc/bcm/allo-piano-dac.c
1045 create mode 100644 sound/soc/bcm/audioinjector-isolated-soundcard.c
1046 create mode 100644 sound/soc/bcm/audioinjector-octo-soundcard.c
1047 create mode 100644 sound/soc/bcm/audioinjector-pi-soundcard.c
1048 create mode 100644 sound/soc/bcm/audiosense-pi.c
1049 create mode 100644 sound/soc/bcm/chipdip-dac.c
1050 create mode 100644 sound/soc/bcm/dacberry400.c
1051 create mode 100644 sound/soc/bcm/digidac1-soundcard.c
1052 create mode 100644 sound/soc/bcm/dionaudio_loco-v2.c
1053 create mode 100644 sound/soc/bcm/dionaudio_loco.c
1054 create mode 100644 sound/soc/bcm/fe-pi-audio.c
1055 create mode 100644 sound/soc/bcm/googlevoicehat-codec.c
1056 create mode 100644 sound/soc/bcm/hifiberry_dacplus.c
1057 create mode 100644 sound/soc/bcm/hifiberry_dacplusadc.c
1058 create mode 100644 sound/soc/bcm/hifiberry_dacplusadcpro.c
1059 create mode 100644 sound/soc/bcm/hifiberry_dacplusdsp.c
1060 create mode 100644 sound/soc/bcm/hifiberry_dacplushd.c
1061 create mode 100644 sound/soc/bcm/i-sabre-q2m.c
1062 create mode 100644 sound/soc/bcm/iqaudio-codec.c
1063 create mode 100644 sound/soc/bcm/iqaudio-dac.c
1064 create mode 100644 sound/soc/bcm/justboom-both.c
1065 create mode 100644 sound/soc/bcm/justboom-dac.c
1066 create mode 100644 sound/soc/bcm/pifi-40.c
1067 create mode 100644 sound/soc/bcm/pisound.c
1068 create mode 100644 sound/soc/bcm/rpi-cirrus.c
1069 create mode 100644 sound/soc/bcm/rpi-proto.c
1070 create mode 100644 sound/soc/bcm/rpi-simple-soundcard.c
1071 create mode 100644 sound/soc/bcm/rpi-wm8804-soundcard.c
1072 create mode 100644 sound/soc/codecs/i-sabre-codec.c
1073 create mode 100644 sound/soc/codecs/i-sabre-codec.h
1074 create mode 100644 sound/soc/codecs/ma120x0p.c
1075 create mode 100644 sound/soc/codecs/pcm1794a.c
1076 create mode 100644 sound/soc/codecs/tas5713.c
1077 create mode 100644 sound/soc/codecs/tas5713.h
1080 +++ b/Documentation/devicetree/bindings/vendor-prefixes.txt
1082 +Device tree binding vendor prefix registry. Keep list in alphabetical order.
1084 +This isn't an exhaustive list, but you should add new prefixes to it before
1085 +using them to avoid name-space collisions.
1087 +abilis Abilis Systems
1088 +abracon Abracon Corporation
1089 +actions Actions Semiconductor Co., Ltd.
1090 +active-semi Active-Semi International Inc
1091 +ad Avionic Design GmbH
1092 +adafruit Adafruit Industries, LLC
1093 +adapteva Adapteva, Inc.
1094 +adaptrum Adaptrum, Inc.
1095 +adh AD Holdings Plc.
1096 +adi Analog Devices, Inc.
1097 +advantech Advantech Corporation
1098 +aeroflexgaisler Aeroflex Gaisler AB
1101 +allwinner Allwinner Technology Co., Ltd.
1102 +alphascale AlphaScale Integrated Circuits Systems, Inc.
1104 +amarula Amarula Solutions
1105 +amazon Amazon.com, Inc.
1106 +amcc Applied Micro Circuits Corporation (APM, formally AMCC)
1107 +amd Advanced Micro Devices (AMD), Inc.
1108 +amediatech Shenzhen Amediatech Technology Co., Ltd
1109 +amlogic Amlogic, Inc.
1110 +ampire Ampire Co., Ltd.
1112 +amstaos AMS-Taos Inc.
1113 +analogix Analogix Semiconductor, Inc.
1114 +andestech Andes Technology Corporation
1115 +apm Applied Micro Circuits Corporation (APM)
1116 +aptina Aptina Imaging
1117 +arasan Arasan Chip Systems
1118 +archermind ArcherMind Technology (Nanjing) Co., Ltd.
1120 +aries Aries Embedded GmbH
1122 +armadeus ARMadeus Systems SARL
1123 +arrow Arrow Electronics
1124 +artesyn Artesyn Embedded Technologies Inc.
1125 +asahi-kasei Asahi Kasei Corp.
1126 +aspeed ASPEED Technology Inc.
1127 +asus AsusTek Computer Inc.
1128 +atlas Atlas Scientific LLC
1129 +atmel Atmel Corporation
1130 +auo AU Optronics Corporation
1131 +auvidea Auvidea GmbH
1132 +avago Avago Technologies
1133 +avia avia semiconductor
1134 +avic Shanghai AVIC Optoelectronics Co., Ltd.
1136 +axentia Axentia Technologies AB
1137 +axis Axis Communications AB
1138 +bananapi BIPAI KEJI LIMITED
1139 +bhf Beckhoff Automation GmbH & Co. KG
1140 +bitmain Bitmain Technologies
1141 +blokaslabs Vilniaus Blokas UAB
1142 +boe BOE Technology Group Co., Ltd.
1143 +bosch Bosch Sensortec GmbH
1144 +boundary Boundary Devices Inc.
1145 +brcm Broadcom Corporation
1146 +buffalo Buffalo, Inc.
1147 +bticino Bticino International
1149 +capella Capella Microsystems, Inc
1150 +cascoda Cascoda, Ltd.
1151 +catalyst Catalyst Semiconductor, Inc.
1152 +cavium Cavium, Inc.
1153 +cdns Cadence Design Systems Inc.
1154 +cdtech CDTech(H.K.) Electronics Limited
1156 +chipidea Chipidea, Inc
1158 +chipspark ChipSPARK
1159 +chrp Common Hardware Reference Platform
1160 +chunghwa Chunghwa Picture Tubes Ltd.
1161 +ciaa Computadora Industrial Abierta Argentina
1162 +cirrus Cirrus Logic, Inc.
1163 +cloudengines Cloud Engines, Inc.
1164 +cnm Chips&Media, Inc.
1165 +cnxt Conexant Systems, Inc.
1166 +compulab CompuLab Ltd.
1167 +cortina Cortina Systems, Inc.
1168 +cosmic Cosmic Circuits
1169 +crane Crane Connectivity Solutions
1170 +creative Creative Technology Ltd
1171 +crystalfontz Crystalfontz America, Inc.
1172 +csky Hangzhou C-SKY Microsystems Co., Ltd
1173 +cubietech Cubietech, Ltd.
1174 +cypress Cypress Semiconductor Corporation
1175 +cznic CZ.NIC, z.s.p.o.
1176 +dallas Maxim Integrated Products (formerly Dallas Semiconductor)
1177 +dataimage DataImage, Inc.
1178 +davicom DAVICOM Semiconductor, Inc.
1179 +delta Delta Electronics, Inc.
1180 +denx Denx Software Engineering
1181 +devantech Devantech, Ltd.
1182 +dh DH electronics GmbH
1183 +digi Digi International Inc.
1184 +digilent Diglent, Inc.
1185 +dioo Dioo Microcircuit Co., Ltd
1186 +dlc DLC Display Co., Ltd.
1187 +dlg Dialog Semiconductor
1188 +dlink D-Link Corporation
1190 +domintech Domintech Co., Ltd.
1191 +dongwoon Dongwoon Anatech
1192 +dptechnics DPTechnics
1193 +dragino Dragino Technology Co., Limited
1194 +ea Embedded Artists AB
1195 +ebs-systart EBS-SYSTART GmbH
1197 +eckelmann Eckelmann AG
1198 +edt Emerging Display Technologies
1199 +eeti eGalax_eMPIA Technology Inc
1200 +elan Elan Microelectronic Corp.
1202 +embest Shenzhen Embest Technology Co., Ltd.
1204 +emmicro EM Microelectronic
1205 +emtrion emtrion GmbH
1206 +endless Endless Mobile, Inc.
1207 +energymicro Silicon Laboratories (formerly Energy Micro AS)
1208 +engicam Engicam S.r.l.
1210 +epfl Ecole Polytechnique Fédérale de Lausanne
1211 +epson Seiko Epson Corp.
1212 +est ESTeem Wireless Modems
1213 +ettus NI Ettus Research
1214 +eukrea Eukréa Electromatique
1215 +everest Everest Semiconductor Co. Ltd.
1216 +everspin Everspin Technologies, Inc.
1217 +exar Exar Corporation
1219 +ezchip EZchip Semiconductor
1221 +fairphone Fairphone B.V.
1222 +faraday Faraday Technology Corporation
1224 +fcs Fairchild Semiconductor
1225 +feiyang Shenzhen Fly Young Technology Co.,LTD.
1227 +focaltech FocalTech Systems Co.,Ltd
1228 +friendlyarm Guangzhou FriendlyARM Computer Tech Co., Ltd
1229 +fsl Freescale Semiconductor
1230 +fujitsu Fujitsu Ltd.
1231 +gateworks Gateworks Corporation
1232 +gcw Game Consoles Worldwide
1233 +ge General Electric Company
1234 +geekbuying GeekBuying
1235 +gef GE Fanuc Intelligent Platforms Embedded Systems, Inc.
1236 +GEFanuc GE Fanuc Intelligent Platforms Embedded Systems, Inc.
1237 +geniatech Geniatech, Inc.
1238 +giantec Giantec Semiconductor, Inc.
1239 +giantplus Giantplus Technology Co., Ltd.
1240 +globalscale Globalscale Technologies, Inc.
1241 +globaltop GlobalTop Technology, Inc.
1242 +gmt Global Mixed-mode Technology, Inc.
1243 +goodix Shenzhen Huiding Technology Co., Ltd.
1244 +google Google, Inc.
1246 +grmn Garmin Limited
1247 +gumstix Gumstix, Inc.
1248 +gw Gateworks Corporation
1249 +hannstar HannStar Display Corporation
1250 +haoyu Haoyu Microelectronic Co. Ltd.
1251 +hardkernel Hardkernel Co., Ltd
1253 +himax Himax Technologies, Inc.
1254 +hisilicon Hisilicon Limited.
1256 +hitex Hitex Development Tools
1257 +holt Holt Integrated Circuits, Inc.
1258 +honeywell Honeywell
1260 +holtek Holtek Semiconductor, Inc.
1261 +hwacom HwaCom Systems Inc.
1263 +ibm International Business Machines (IBM)
1264 +icplus IC Plus Corp.
1265 +idt Integrated Device Technologies, Inc.
1266 +ifi Ingenieurburo Fur Ic-Technologie (I/F/I)
1267 +ilitek ILI Technology Corporation (ILITEK)
1268 +img Imagination Technologies Ltd.
1269 +infineon Infineon Technologies
1270 +inforce Inforce Computing
1271 +ingenic Ingenic Semiconductor
1272 +innolux Innolux Corporation
1273 +inside-secure INSIDE Secure
1274 +intel Intel Corporation
1275 +intercontrol Inter Control Group
1276 +invensense InvenSense Inc.
1277 +inversepath Inverse Path
1278 +iom Iomega Corporation
1279 +isee ISEE 2007 S.L.
1281 +issi Integrated Silicon Solutions Inc.
1282 +itead ITEAD Intelligent Systems Co.Ltd
1283 +iwave iWave Systems Technologies Pvt. Ltd.
1284 +jdi Japan Display Inc.
1285 +jedec JEDEC Solid State Technology Association
1286 +jianda Jiandangjing Technology Co., Ltd.
1287 +karo Ka-Ro electronics GmbH
1288 +keithkoep Keith & Koep GmbH
1289 +keymile Keymile GmbH
1291 +kiebackpeter Kieback & Peter GmbH
1292 +kinetic Kinetic Technologies
1293 +kingdisplay King & Display Technology Co., Ltd.
1294 +kingnovel Kingnovel Technology Co., Ltd.
1295 +koe Kaohsiung Opto-Electronics Inc.
1296 +kosagi Sutajio Ko-Usagi PTE Ltd.
1297 +kyo Kyocera Corporation
1300 +lantiq Lantiq Semiconductor
1301 +lattice Lattice Semiconductor
1302 +lego LEGO Systems A/S
1303 +lemaker Shenzhen LeMaker Technology Co., Ltd.
1304 +lenovo Lenovo Group Ltd.
1306 +libretech Shenzhen Libre Technology Co., Ltd
1308 +linaro Linaro Limited
1309 +linksys Belkin International, Inc. (Linksys)
1310 +linux Linux-specific binding
1311 +linx Linx Technologies
1312 +lltc Linear Technology Corporation
1313 +logicpd Logic PD, Inc.
1314 +lsi LSI Corp. (LSI Logic)
1315 +lwn Liebherr-Werk Nenzing GmbH
1316 +macnica Macnica Americas
1317 +marvell Marvell Technology Group Ltd.
1318 +maxim Maxim Integrated Products
1321 +meas Measurement Specialties
1322 +mediatek MediaTek Inc.
1323 +megachips MegaChips
1324 +mele Shenzhen MeLE Digital Technology Ltd.
1325 +melexis Melexis N.V.
1327 +mellanox Mellanox Technologies
1329 +merrii Merrii Technology Co., Ltd.
1331 +microchip Microchip Technology Inc.
1332 +microcrystal Micro Crystal AG
1333 +micron Micron Technology Inc.
1334 +mikroe MikroElektronika d.o.o.
1335 +minix MINIX Technology Ltd.
1336 +miramems MiraMEMS Sensing Technology Co., Ltd.
1337 +mitsubishi Mitsubishi Electric Corporation
1338 +mosaixtech Mosaix Technologies, Inc.
1339 +motorola Motorola, Inc.
1342 +mqmaker mqmaker Inc.
1343 +mscc Microsemi Corporation
1344 +msi Micro-Star International Co. Ltd.
1345 +mti Imagination Technologies Ltd. (formerly MIPS Technologies Inc.)
1346 +multi-inno Multi-Inno Technology Co.,Ltd
1347 +mundoreader Mundo Reader S.L.
1348 +murata Murata Manufacturing Co., Ltd.
1349 +mxicy Macronix International Co., Ltd.
1350 +myir MYIR Tech Limited
1351 +national National Semiconductor
1352 +nec NEC LCD Technologies, Ltd.
1353 +neonode Neonode Inc.
1355 +netlogic Broadcom Corporation (formerly NetLogic Microsystems)
1356 +netron-dy Netron DY
1357 +netxeon Shenzhen Netxeon Technology CO., LTD
1359 +nextthing Next Thing Co.
1360 +newhaven Newhaven Display International
1361 +ni National Instruments
1363 +nlt NLT Technologies, Ltd.
1365 +nordic Nordic Semiconductor
1366 +novtech NovTech, Inc.
1367 +nutsboard NutsBoard
1368 +nuvoton Nuvoton Technology Corporation
1369 +nvd New Vision Display
1371 +nxp NXP Semiconductors
1372 +okaya Okaya Electric America, Inc.
1373 +oki Oki Electric Industry Co., Ltd.
1375 +olpc One Laptop Per Child
1376 +onion Onion Corporation
1377 +onnn ON Semiconductor Corp.
1378 +ontat On Tat Industrial Company
1379 +opalkelly Opal Kelly Incorporated
1380 +opencores OpenCores.org
1381 +openrisc OpenRISC.io
1383 +oranth Shenzhen Oranth Technology Co., Ltd.
1384 +ORCL Oracle Corporation
1385 +orisetech Orise Technology
1386 +ortustech Ortus Technology Co., Ltd.
1387 +ovti OmniVision Technologies
1388 +oxsemi Oxford Semiconductor, Ltd.
1389 +panasonic Panasonic Corporation
1390 +parade Parade Technologies Inc.
1391 +pda Precision Design Associates, Inc.
1392 +pericom Pericom Technology Inc.
1393 +pervasive Pervasive Displays, Inc.
1394 +phicomm PHICOMM Co., Ltd.
1395 +phytec PHYTEC Messtechnik GmbH
1396 +picochip Picochip Ltd
1398 +pixcir PIXCIR MICROELECTRONICS Co., Ltd
1399 +plantower Plantower Co., Ltd
1400 +plathome Plat'Home Co., Ltd.
1402 +plx Broadcom Corporation (formerly PLX Technology)
1403 +pni PNI Sensor Corporation
1404 +portwell Portwell Inc.
1405 +poslab Poslab Technology Co., Ltd.
1406 +powervr PowerVR (deprecated, use img)
1407 +probox2 PROBOX2 (by W2COMP Co., Ltd.)
1408 +pulsedlight PulsedLight, Inc
1409 +qca Qualcomm Atheros, Inc.
1410 +qcom Qualcomm Technologies, Inc
1411 +qemu QEMU, a generic and open source machine emulator and virtualizer
1413 +qiaodian QiaoDian XianShi Corporation
1414 +qnap QNAP Systems, Inc.
1416 +raidsonic RaidSonic Technology GmbH
1417 +ralink Mediatek/Ralink Technology Corp.
1418 +ramtron Ramtron International
1419 +raspberrypi Raspberry Pi Foundation
1420 +raydium Raydium Semiconductor Corp.
1421 +rda Unisoc Communications, Inc.
1422 +realtek Realtek Semiconductor Corp.
1423 +renesas Renesas Electronics Corporation
1424 +richtek Richtek Technology Corporation
1425 +ricoh Ricoh Co. Ltd.
1426 +rikomagic Rikomagic Tech Corp. Ltd
1427 +riscv RISC-V Foundation
1428 +rockchip Fuzhou Rockchip Electronics Co., Ltd
1429 +rohm ROHM Semiconductor Co., Ltd
1430 +roofull Shenzhen Roofull Technology Co, Ltd
1431 +samsung Samsung Semiconductor
1432 +samtec Samtec/Softing company
1433 +sancloud Sancloud Ltd
1434 +sandisk Sandisk Corporation
1435 +sbs Smart Battery System
1436 +schindler Schindler
1437 +seagate Seagate Technology PLC
1438 +semtech Semtech Corporation
1439 +sensirion Sensirion AG
1440 +sff Small Form Factor Committee
1441 +sgd Solomon Goldentek Display Corporation
1443 +sharp Sharp Corporation
1444 +shimafuji Shimafuji Electric, Inc.
1445 +si-en Si-En Technology Ltd.
1446 +sifive SiFive, Inc.
1447 +sigma Sigma Designs, Inc.
1448 +sii Seiko Instruments, Inc.
1450 +silabs Silicon Laboratories
1452 +silergy Silergy Corp.
1453 +siliconmitus Silicon Mitus, Inc.
1455 +sirf SiRF Technology, Inc.
1456 +sis Silicon Integrated Systems Corp.
1457 +sitronix Sitronix Technology Corporation
1458 +skyworks Skyworks Solutions, Inc.
1459 +smsc Standard Microsystems Corporation
1460 +snps Synopsys, Inc.
1461 +socionext Socionext Inc.
1463 +solomon Solomon Systech Limited
1464 +sony Sony Corporation
1465 +spansion Spansion Inc.
1466 +sprd Spreadtrum Communications Inc.
1467 +sst Silicon Storage Technology, Inc.
1468 +st STMicroelectronics
1469 +starry Starry Electronic Technology (ShenZhen) Co., LTD
1472 +stericsson ST-Ericsson
1473 +summit Summit microelectronics
1474 +sunchip Shenzhen Sunchip Technology Co., Ltd
1475 +SUNW Sun Microsystems, Inc
1476 +swir Sierra Wireless
1477 +syna Synaptics Inc.
1478 +synology Synology, Inc.
1479 +tbs TBS Technologies
1480 +tbs-biometrics Touchless Biometric Systems AG
1481 +tcg Trusted Computing Group
1482 +tcl Toby Churchill Ltd.
1483 +technexion TechNexion
1484 +technologic Technologic Systems
1485 +tempo Tempo Semiconductor
1486 +techstar Shenzhen Techstar Electronics Co., Ltd.
1487 +terasic Terasic Inc.
1488 +thine THine Electronics, Inc.
1489 +ti Texas Instruments
1490 +tianma Tianma Micro-electronics Co., Ltd.
1491 +tlm Trusted Logic Mobility
1492 +tmt Tecon Microprocessor Technologies, LLC.
1495 +toshiba Toshiba Corporation
1498 +tplink TP-LINK Technologies Co., Ltd.
1501 +tronsmart Tronsmart
1502 +truly Truly Semiconductors Limited
1503 +tsd Theobroma Systems Design und Consulting GmbH
1504 +tyan Tyan Computer Corporation
1506 +ucrobotics uCRobotics
1507 +ubnt Ubiquiti Networks
1509 +uniwest United Western Technologies Corp (UniWest)
1510 +upisemi uPI Semiconductor Corp.
1511 +urt United Radiant Technology Corporation
1512 +usi Universal Scientific Industrial Co., Ltd.
1513 +v3 V3 Semiconductor
1515 +variscite Variscite Ltd.
1516 +via VIA Technologies, Inc.
1517 +virtio Virtual I/O Device Specification, developed by the OASIS consortium
1518 +vishay Vishay Intertechnology, Inc
1519 +vitesse Vitesse Semiconductor Corporation
1520 +vivante Vivante Corporation
1521 +vocore VoCore Studio
1522 +voipac Voipac Technologies s.r.o.
1523 +vot Vision Optical Technology Co., Ltd.
1524 +wd Western Digital Corp.
1525 +wetek WeTek Electronics, limited.
1527 +whwave Shenzhen whwave Electronics, Inc.
1529 +winbond Winbond Electronics corp.
1530 +winstar Winstar Display Corp.
1531 +wlf Wolfson Microelectronics
1532 +wm Wondermedia Technologies, Inc.
1534 +xes Extreme Engineering Solutions (X-ES)
1535 +xillybus Xillybus Ltd.
1537 +xunlong Shenzhen Xunlong Software CO.,Limited
1538 +ysoft Y Soft Corporation a.s.
1539 +zarlink Zarlink Semiconductor
1540 +zeitec ZEITEC Semiconductor Co., LTD.
1541 +zidoo Shenzhen Zidoo Technology Co., Ltd.
1542 +zii Zodiac Inflight Innovations
1544 +zyxel Zyxel Communications Corp.
1545 --- a/Documentation/devicetree/bindings/vendor-prefixes.yaml
1546 +++ b/Documentation/devicetree/bindings/vendor-prefixes.yaml
1547 @@ -196,6 +196,8 @@ patternProperties:
1548 description: Beckhoff Automation GmbH & Co. KG
1550 description: Bitmain Technologies
1552 + description: Vilniaus Blokas UAB
1554 description: BluTek Power
1556 --- a/drivers/clk/Kconfig
1557 +++ b/drivers/clk/Kconfig
1558 @@ -98,6 +98,12 @@ config COMMON_CLK_HI655X
1559 multi-function device has one fixed-rate oscillator, clocked
1562 +config COMMON_CLK_HIFIBERRY_DACPLUSHD
1565 +config COMMON_CLK_HIFIBERRY_DACPRO
1568 config COMMON_CLK_SCMI
1569 tristate "Clock driver controlled via SCMI interface"
1570 depends on ARM_SCMI_PROTOCOL || COMPILE_TEST
1571 --- a/drivers/clk/Makefile
1572 +++ b/drivers/clk/Makefile
1573 @@ -45,6 +45,8 @@ obj-$(CONFIG_COMMON_CLK_LAN966X) += clk-
1574 obj-$(CONFIG_COMMON_CLK_LOCHNAGAR) += clk-lochnagar.o
1575 obj-$(CONFIG_MACH_LOONGSON32) += clk-loongson1.o
1576 obj-$(CONFIG_COMMON_CLK_LOONGSON2) += clk-loongson2.o
1577 +obj-$(CONFIG_COMMON_CLK_HIFIBERRY_DACPRO) += clk-hifiberry-dacpro.o
1578 +obj-$(CONFIG_COMMON_CLK_HIFIBERRY_DACPLUSHD) += clk-hifiberry-dachd.o
1579 obj-$(CONFIG_COMMON_CLK_MAX77686) += clk-max77686.o
1580 obj-$(CONFIG_COMMON_CLK_MAX9485) += clk-max9485.o
1581 obj-$(CONFIG_ARCH_MILBEAUT_M10V) += clk-milbeaut.o
1583 +++ b/drivers/clk/clk-hifiberry-dachd.c
1585 +// SPDX-License-Identifier: GPL-2.0
1587 + * Clock Driver for HiFiBerry DAC+ HD
1589 + * Author: Joerg Schambacher, i2Audio GmbH for HiFiBerry
1592 + * This program is free software; you can redistribute it and/or
1593 + * modify it under the terms of the GNU General Public License
1594 + * version 2 as published by the Free Software Foundation.
1596 + * This program is distributed in the hope that it will be useful, but
1597 + * WITHOUT ANY WARRANTY; without even the implied warranty of
1598 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1599 + * General Public License for more details.
1602 +#include <linux/clk-provider.h>
1603 +#include <linux/clk.h>
1604 +#include <linux/kernel.h>
1605 +#include <linux/module.h>
1606 +#include <linux/of.h>
1607 +#include <linux/slab.h>
1608 +#include <linux/platform_device.h>
1609 +#include <linux/i2c.h>
1610 +#include <linux/regmap.h>
1612 +#define NO_PLL_RESET 0
1613 +#define PLL_RESET 1
1614 +#define HIFIBERRY_PLL_MAX_REGISTER 256
1615 +#define DEFAULT_RATE 44100
1617 +static struct reg_default hifiberry_pll_reg_defaults[] = {
1618 + {0x02, 0x53}, {0x03, 0x00}, {0x07, 0x20}, {0x0F, 0x00},
1619 + {0x10, 0x0D}, {0x11, 0x1D}, {0x12, 0x0D}, {0x13, 0x8C},
1620 + {0x14, 0x8C}, {0x15, 0x8C}, {0x16, 0x8C}, {0x17, 0x8C},
1621 + {0x18, 0x2A}, {0x1C, 0x00}, {0x1D, 0x0F}, {0x1F, 0x00},
1622 + {0x2A, 0x00}, {0x2C, 0x00}, {0x2F, 0x00}, {0x30, 0x00},
1623 + {0x31, 0x00}, {0x32, 0x00}, {0x34, 0x00}, {0x37, 0x00},
1624 + {0x38, 0x00}, {0x39, 0x00}, {0x3A, 0x00}, {0x3B, 0x01},
1625 + {0x3E, 0x00}, {0x3F, 0x00}, {0x40, 0x00}, {0x41, 0x00},
1626 + {0x5A, 0x00}, {0x5B, 0x00}, {0x95, 0x00}, {0x96, 0x00},
1627 + {0x97, 0x00}, {0x98, 0x00}, {0x99, 0x00}, {0x9A, 0x00},
1628 + {0x9B, 0x00}, {0xA2, 0x00}, {0xA3, 0x00}, {0xA4, 0x00},
1630 + {0x1A, 0x3D}, {0x1B, 0x09}, {0x1E, 0xF3}, {0x20, 0x13},
1631 + {0x21, 0x75}, {0x2B, 0x04}, {0x2D, 0x11}, {0x2E, 0xE0},
1633 + {0x35, 0x9D}, {0x36, 0x00}, {0x3C, 0x42},
1636 +static struct reg_default common_pll_regs[HIFIBERRY_PLL_MAX_REGISTER];
1637 +static int num_common_pll_regs;
1638 +static struct reg_default dedicated_192k_pll_regs[HIFIBERRY_PLL_MAX_REGISTER];
1639 +static int num_dedicated_192k_pll_regs;
1640 +static struct reg_default dedicated_96k_pll_regs[HIFIBERRY_PLL_MAX_REGISTER];
1641 +static int num_dedicated_96k_pll_regs;
1642 +static struct reg_default dedicated_48k_pll_regs[HIFIBERRY_PLL_MAX_REGISTER];
1643 +static int num_dedicated_48k_pll_regs;
1644 +static struct reg_default dedicated_176k4_pll_regs[HIFIBERRY_PLL_MAX_REGISTER];
1645 +static int num_dedicated_176k4_pll_regs;
1646 +static struct reg_default dedicated_88k2_pll_regs[HIFIBERRY_PLL_MAX_REGISTER];
1647 +static int num_dedicated_88k2_pll_regs;
1648 +static struct reg_default dedicated_44k1_pll_regs[HIFIBERRY_PLL_MAX_REGISTER];
1649 +static int num_dedicated_44k1_pll_regs;
1652 + * struct clk_hifiberry_drvdata - Common struct to the HiFiBerry DAC HD Clk
1653 + * @hw: clk_hw for the common clk framework
1655 +struct clk_hifiberry_drvdata {
1656 + struct regmap *regmap;
1659 + unsigned long rate;
1662 +#define to_hifiberry_clk(_hw) \
1663 + container_of(_hw, struct clk_hifiberry_drvdata, hw)
1665 +static int clk_hifiberry_dachd_write_pll_regs(struct regmap *regmap,
1666 + struct reg_default *regs,
1667 + int num, int do_pll_reset)
1671 + char pll_soft_reset[] = { 177, 0xAC, };
1673 + for (i = 0; i < num; i++) {
1674 + ret |= regmap_write(regmap, regs[i].reg, regs[i].def);
1678 + if (do_pll_reset) {
1679 + ret |= regmap_write(regmap, pll_soft_reset[0],
1680 + pll_soft_reset[1]);
1686 +static unsigned long clk_hifiberry_dachd_recalc_rate(struct clk_hw *hw,
1687 + unsigned long parent_rate)
1689 + return to_hifiberry_clk(hw)->rate;
1692 +static long clk_hifiberry_dachd_round_rate(struct clk_hw *hw,
1693 + unsigned long rate, unsigned long *parent_rate)
1698 +static int clk_hifiberry_dachd_set_rate(struct clk_hw *hw,
1699 + unsigned long rate, unsigned long parent_rate)
1702 + struct clk_hifiberry_drvdata *drvdata = to_hifiberry_clk(hw);
1706 + ret = clk_hifiberry_dachd_write_pll_regs(drvdata->regmap,
1707 + dedicated_44k1_pll_regs, num_dedicated_44k1_pll_regs,
1711 + ret = clk_hifiberry_dachd_write_pll_regs(drvdata->regmap,
1712 + dedicated_88k2_pll_regs, num_dedicated_88k2_pll_regs,
1716 + ret = clk_hifiberry_dachd_write_pll_regs(drvdata->regmap,
1717 + dedicated_176k4_pll_regs, num_dedicated_176k4_pll_regs,
1721 + ret = clk_hifiberry_dachd_write_pll_regs(drvdata->regmap,
1722 + dedicated_48k_pll_regs, num_dedicated_48k_pll_regs,
1726 + ret = clk_hifiberry_dachd_write_pll_regs(drvdata->regmap,
1727 + dedicated_96k_pll_regs, num_dedicated_96k_pll_regs,
1731 + ret = clk_hifiberry_dachd_write_pll_regs(drvdata->regmap,
1732 + dedicated_192k_pll_regs, num_dedicated_192k_pll_regs,
1739 + to_hifiberry_clk(hw)->rate = rate;
1744 +const struct clk_ops clk_hifiberry_dachd_rate_ops = {
1745 + .recalc_rate = clk_hifiberry_dachd_recalc_rate,
1746 + .round_rate = clk_hifiberry_dachd_round_rate,
1747 + .set_rate = clk_hifiberry_dachd_set_rate,
1750 +static int clk_hifiberry_get_prop_values(struct device *dev,
1752 + struct reg_default *regs)
1756 + u8 tmp[2 * HIFIBERRY_PLL_MAX_REGISTER];
1758 + ret = of_property_read_variable_u8_array(dev->of_node, prop_name,
1759 + tmp, 0, 2 * HIFIBERRY_PLL_MAX_REGISTER);
1764 + "%s <%s> -> #%i odd number of bytes for reg/val pairs!",
1771 + for (i = 0; i < ret; i++) {
1772 + regs[i].reg = (u32)tmp[2 * i];
1773 + regs[i].def = (u32)tmp[2 * i + 1];
1779 +static int clk_hifiberry_dachd_dt_parse(struct device *dev)
1781 + num_common_pll_regs = clk_hifiberry_get_prop_values(dev,
1782 + "common_pll_regs", common_pll_regs);
1783 + num_dedicated_44k1_pll_regs = clk_hifiberry_get_prop_values(dev,
1784 + "44k1_pll_regs", dedicated_44k1_pll_regs);
1785 + num_dedicated_88k2_pll_regs = clk_hifiberry_get_prop_values(dev,
1786 + "88k2_pll_regs", dedicated_88k2_pll_regs);
1787 + num_dedicated_176k4_pll_regs = clk_hifiberry_get_prop_values(dev,
1788 + "176k4_pll_regs", dedicated_176k4_pll_regs);
1789 + num_dedicated_48k_pll_regs = clk_hifiberry_get_prop_values(dev,
1790 + "48k_pll_regs", dedicated_48k_pll_regs);
1791 + num_dedicated_96k_pll_regs = clk_hifiberry_get_prop_values(dev,
1792 + "96k_pll_regs", dedicated_96k_pll_regs);
1793 + num_dedicated_192k_pll_regs = clk_hifiberry_get_prop_values(dev,
1794 + "192k_pll_regs", dedicated_192k_pll_regs);
1799 +static int clk_hifiberry_dachd_remove(struct device *dev)
1801 + of_clk_del_provider(dev->of_node);
1805 +const struct regmap_config hifiberry_pll_regmap = {
1808 + .max_register = HIFIBERRY_PLL_MAX_REGISTER,
1809 + .reg_defaults = hifiberry_pll_reg_defaults,
1810 + .num_reg_defaults = ARRAY_SIZE(hifiberry_pll_reg_defaults),
1811 + .cache_type = REGCACHE_RBTREE,
1813 +EXPORT_SYMBOL_GPL(hifiberry_pll_regmap);
1816 +static int clk_hifiberry_dachd_i2c_probe(struct i2c_client *i2c)
1818 + struct clk_hifiberry_drvdata *hdclk;
1820 + struct clk_init_data init;
1821 + struct device *dev = &i2c->dev;
1822 + struct device_node *dev_node = dev->of_node;
1823 + struct regmap_config config = hifiberry_pll_regmap;
1825 + hdclk = devm_kzalloc(&i2c->dev,
1826 + sizeof(struct clk_hifiberry_drvdata), GFP_KERNEL);
1830 + i2c_set_clientdata(i2c, hdclk);
1832 + hdclk->regmap = devm_regmap_init_i2c(i2c, &config);
1834 + if (IS_ERR(hdclk->regmap))
1835 + return PTR_ERR(hdclk->regmap);
1837 + /* start PLL to allow detection of DAC */
1838 + ret = clk_hifiberry_dachd_write_pll_regs(hdclk->regmap,
1839 + hifiberry_pll_reg_defaults,
1840 + ARRAY_SIZE(hifiberry_pll_reg_defaults),
1845 + clk_hifiberry_dachd_dt_parse(dev);
1847 + /* restart PLL with configs from DTB */
1848 + ret = clk_hifiberry_dachd_write_pll_regs(hdclk->regmap, common_pll_regs,
1849 + num_common_pll_regs, PLL_RESET);
1853 + init.name = "clk-hifiberry-dachd";
1854 + init.ops = &clk_hifiberry_dachd_rate_ops;
1856 + init.parent_names = NULL;
1857 + init.num_parents = 0;
1859 + hdclk->hw.init = &init;
1861 + hdclk->clk = devm_clk_register(dev, &hdclk->hw);
1862 + if (IS_ERR(hdclk->clk)) {
1863 + dev_err(dev, "unable to register %s\n", init.name);
1864 + return PTR_ERR(hdclk->clk);
1867 + ret = of_clk_add_provider(dev_node, of_clk_src_simple_get, hdclk->clk);
1869 + dev_err(dev, "Cannot of_clk_add_provider");
1873 + ret = clk_set_rate(hdclk->hw.clk, DEFAULT_RATE);
1875 + dev_err(dev, "Cannot set rate : %d\n", ret);
1882 +static void clk_hifiberry_dachd_i2c_remove(struct i2c_client *i2c)
1884 + clk_hifiberry_dachd_remove(&i2c->dev);
1887 +static const struct i2c_device_id clk_hifiberry_dachd_i2c_id[] = {
1891 +MODULE_DEVICE_TABLE(i2c, clk_hifiberry_dachd_i2c_id);
1893 +static const struct of_device_id clk_hifiberry_dachd_of_match[] = {
1894 + { .compatible = "hifiberry,dachd-clk", },
1897 +MODULE_DEVICE_TABLE(of, clk_hifiberry_dachd_of_match);
1899 +static struct i2c_driver clk_hifiberry_dachd_i2c_driver = {
1900 + .probe = clk_hifiberry_dachd_i2c_probe,
1901 + .remove = clk_hifiberry_dachd_i2c_remove,
1902 + .id_table = clk_hifiberry_dachd_i2c_id,
1904 + .name = "dachd-clk",
1905 + .of_match_table = of_match_ptr(clk_hifiberry_dachd_of_match),
1909 +module_i2c_driver(clk_hifiberry_dachd_i2c_driver);
1912 +MODULE_DESCRIPTION("HiFiBerry DAC+ HD clock driver");
1913 +MODULE_AUTHOR("Joerg Schambacher <joerg@i2audio.com>");
1914 +MODULE_LICENSE("GPL v2");
1915 +MODULE_ALIAS("platform:clk-hifiberry-dachd");
1917 +++ b/drivers/clk/clk-hifiberry-dacpro.c
1920 + * Clock Driver for HiFiBerry DAC Pro
1922 + * Author: Stuart MacLean
1925 + * This program is free software; you can redistribute it and/or
1926 + * modify it under the terms of the GNU General Public License
1927 + * version 2 as published by the Free Software Foundation.
1929 + * This program is distributed in the hope that it will be useful, but
1930 + * WITHOUT ANY WARRANTY; without even the implied warranty of
1931 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1932 + * General Public License for more details.
1935 +#include <linux/clk-provider.h>
1936 +#include <linux/clkdev.h>
1937 +#include <linux/kernel.h>
1938 +#include <linux/module.h>
1939 +#include <linux/of.h>
1940 +#include <linux/slab.h>
1941 +#include <linux/platform_device.h>
1943 +struct ext_clk_rates {
1944 + /* Clock rate of CLK44EN attached to GPIO6 pin */
1945 + unsigned long clk_44en;
1946 + /* Clock rate of CLK48EN attached to GPIO3 pin */
1947 + unsigned long clk_48en;
1951 + * struct hifiberry_dacpro_clk - Common struct to the HiFiBerry DAC Pro
1952 + * @hw: clk_hw for the common clk framework
1953 + * @mode: 0 => CLK44EN, 1 => CLK48EN
1955 +struct clk_hifiberry_hw {
1958 + struct ext_clk_rates clk_rates;
1961 +#define to_hifiberry_clk(_hw) container_of(_hw, struct clk_hifiberry_hw, hw)
1963 +static const struct ext_clk_rates hifiberry_dacpro_clks = {
1964 + .clk_44en = 22579200UL,
1965 + .clk_48en = 24576000UL,
1968 +static const struct ext_clk_rates allo_dac_clks = {
1969 + .clk_44en = 45158400UL,
1970 + .clk_48en = 49152000UL,
1973 +static const struct of_device_id clk_hifiberry_dacpro_dt_ids[] = {
1974 + { .compatible = "hifiberry,dacpro-clk", &hifiberry_dacpro_clks },
1975 + { .compatible = "allo,dac-clk", &allo_dac_clks },
1978 +MODULE_DEVICE_TABLE(of, clk_hifiberry_dacpro_dt_ids);
1980 +static unsigned long clk_hifiberry_dacpro_recalc_rate(struct clk_hw *hw,
1981 + unsigned long parent_rate)
1983 + struct clk_hifiberry_hw *clk = to_hifiberry_clk(hw);
1984 + return (clk->mode == 0) ? clk->clk_rates.clk_44en :
1985 + clk->clk_rates.clk_48en;
1988 +static long clk_hifiberry_dacpro_round_rate(struct clk_hw *hw,
1989 + unsigned long rate, unsigned long *parent_rate)
1991 + struct clk_hifiberry_hw *clk = to_hifiberry_clk(hw);
1994 + if (rate <= clk->clk_rates.clk_44en) {
1995 + actual_rate = (long)clk->clk_rates.clk_44en;
1996 + } else if (rate >= clk->clk_rates.clk_48en) {
1997 + actual_rate = (long)clk->clk_rates.clk_48en;
1999 + long diff44Rate = (long)(rate - clk->clk_rates.clk_44en);
2000 + long diff48Rate = (long)(clk->clk_rates.clk_48en - rate);
2002 + if (diff44Rate < diff48Rate)
2003 + actual_rate = (long)clk->clk_rates.clk_44en;
2005 + actual_rate = (long)clk->clk_rates.clk_48en;
2007 + return actual_rate;
2011 +static int clk_hifiberry_dacpro_set_rate(struct clk_hw *hw,
2012 + unsigned long rate, unsigned long parent_rate)
2014 + struct clk_hifiberry_hw *clk = to_hifiberry_clk(hw);
2015 + unsigned long actual_rate;
2017 + actual_rate = (unsigned long)clk_hifiberry_dacpro_round_rate(hw, rate,
2019 + clk->mode = (actual_rate == clk->clk_rates.clk_44en) ? 0 : 1;
2024 +const struct clk_ops clk_hifiberry_dacpro_rate_ops = {
2025 + .recalc_rate = clk_hifiberry_dacpro_recalc_rate,
2026 + .round_rate = clk_hifiberry_dacpro_round_rate,
2027 + .set_rate = clk_hifiberry_dacpro_set_rate,
2030 +static int clk_hifiberry_dacpro_probe(struct platform_device *pdev)
2032 + const struct of_device_id *of_id;
2033 + struct clk_hifiberry_hw *proclk;
2035 + struct device *dev;
2036 + struct clk_init_data init;
2040 + of_id = of_match_node(clk_hifiberry_dacpro_dt_ids, dev->of_node);
2044 + proclk = kzalloc(sizeof(struct clk_hifiberry_hw), GFP_KERNEL);
2048 + init.name = "clk-hifiberry-dacpro";
2049 + init.ops = &clk_hifiberry_dacpro_rate_ops;
2051 + init.parent_names = NULL;
2052 + init.num_parents = 0;
2055 + proclk->hw.init = &init;
2056 + memcpy(&proclk->clk_rates, of_id->data, sizeof(proclk->clk_rates));
2058 + clk = devm_clk_register(dev, &proclk->hw);
2059 + if (!IS_ERR(clk)) {
2060 + ret = of_clk_add_provider(dev->of_node, of_clk_src_simple_get,
2063 + dev_err(dev, "Fail to register clock driver\n");
2065 + ret = PTR_ERR(clk);
2070 +static int clk_hifiberry_dacpro_remove(struct platform_device *pdev)
2072 + of_clk_del_provider(pdev->dev.of_node);
2076 +static struct platform_driver clk_hifiberry_dacpro_driver = {
2077 + .probe = clk_hifiberry_dacpro_probe,
2078 + .remove = clk_hifiberry_dacpro_remove,
2080 + .name = "clk-hifiberry-dacpro",
2081 + .of_match_table = clk_hifiberry_dacpro_dt_ids,
2085 +static int __init clk_hifiberry_dacpro_init(void)
2087 + return platform_driver_register(&clk_hifiberry_dacpro_driver);
2089 +core_initcall(clk_hifiberry_dacpro_init);
2091 +static void __exit clk_hifiberry_dacpro_exit(void)
2093 + platform_driver_unregister(&clk_hifiberry_dacpro_driver);
2095 +module_exit(clk_hifiberry_dacpro_exit);
2097 +MODULE_DESCRIPTION("HiFiBerry DAC Pro clock driver");
2098 +MODULE_LICENSE("GPL v2");
2099 +MODULE_ALIAS("platform:clk-hifiberry-dacpro");
2100 --- a/sound/soc/bcm/Kconfig
2101 +++ b/sound/soc/bcm/Kconfig
2102 @@ -26,3 +26,309 @@ config SND_BCM63XX_I2S_WHISTLER
2103 DSL/PON chips (bcm63158, bcm63178)
2105 If you don't know what to do here, say N
2107 +config SND_BCM2708_SOC_CHIPDIP_DAC
2108 + tristate "Support for the ChipDip DAC"
2109 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2111 + Say Y or M if you want to add support for the ChipDip DAC soundcard
2113 +config SND_BCM2708_SOC_GOOGLEVOICEHAT_SOUNDCARD
2114 + tristate "Support for Google voiceHAT soundcard"
2115 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2116 + select SND_SOC_VOICEHAT
2117 + select SND_RPI_SIMPLE_SOUNDCARD
2119 + Say Y or M if you want to add support for voiceHAT soundcard.
2121 +config SND_BCM2708_SOC_HIFIBERRY_DAC
2122 + tristate "Support for HifiBerry DAC"
2123 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2124 + select SND_SOC_PCM5102A
2125 + select SND_RPI_SIMPLE_SOUNDCARD
2127 + Say Y or M if you want to add support for HifiBerry DAC.
2129 +config SND_BCM2708_SOC_HIFIBERRY_DACPLUS
2130 + tristate "Support for HifiBerry DAC+"
2131 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2132 + select SND_SOC_PCM512x
2133 + select SND_SOC_TPA6130A2
2134 + select COMMON_CLK_HIFIBERRY_DACPRO
2136 + Say Y or M if you want to add support for HifiBerry DAC+.
2138 +config SND_BCM2708_SOC_HIFIBERRY_DACPLUSHD
2139 + tristate "Support for HifiBerry DAC+ HD"
2140 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2141 + select SND_SOC_PCM179X_I2C
2142 + select COMMON_CLK_HIFIBERRY_DACPLUSHD
2144 + Say Y or M if you want to add support for HifiBerry DAC+ HD.
2146 +config SND_BCM2708_SOC_HIFIBERRY_DACPLUSADC
2147 + tristate "Support for HifiBerry DAC+ADC"
2148 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2149 + select SND_SOC_PCM512x_I2C
2150 + select SND_SOC_DMIC
2151 + select COMMON_CLK_HIFIBERRY_DACPRO
2153 + Say Y or M if you want to add support for HifiBerry DAC+ADC.
2155 +config SND_BCM2708_SOC_HIFIBERRY_DACPLUSADCPRO
2156 + tristate "Support for HifiBerry DAC+ADC PRO"
2157 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2158 + select SND_SOC_PCM512x_I2C
2159 + select SND_SOC_PCM186X_I2C
2160 + select SND_SOC_TPA6130A2
2161 + select COMMON_CLK_HIFIBERRY_DACPRO
2163 + Say Y or M if you want to add support for HifiBerry DAC+ADC PRO.
2165 +config SND_BCM2708_SOC_HIFIBERRY_DACPLUSDSP
2166 + tristate "Support for HifiBerry DAC+DSP"
2167 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2168 + select SND_RPI_SIMPLE_SOUNDCARD
2170 + Say Y or M if you want to add support for HifiBerry DSP-DAC.
2172 +config SND_BCM2708_SOC_HIFIBERRY_DIGI
2173 + tristate "Support for HifiBerry Digi"
2174 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2175 + select SND_SOC_WM8804
2177 + Say Y or M if you want to add support for HifiBerry Digi S/PDIF output board.
2179 +config SND_BCM2708_SOC_HIFIBERRY_AMP
2180 + tristate "Support for the HifiBerry Amp"
2181 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2182 + select SND_SOC_TAS5713
2183 + select SND_RPI_SIMPLE_SOUNDCARD
2185 + Say Y or M if you want to add support for the HifiBerry Amp amplifier board.
2187 + config SND_BCM2708_SOC_PIFI_40
2188 + tristate "Support for the PiFi-40 amp"
2189 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2190 + select SND_SOC_TAS571X
2191 + select SND_PIFI_40
2193 + Say Y or M if you want to add support for the PiFi40 amp board
2195 +config SND_BCM2708_SOC_RPI_CIRRUS
2196 + tristate "Support for Cirrus Logic Audio Card"
2197 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2198 + select SND_SOC_WM5102
2199 + select SND_SOC_WM8804
2201 + Say Y or M if you want to add support for the Wolfson and
2202 + Cirrus Logic audio cards.
2204 +config SND_BCM2708_SOC_RPI_DAC
2205 + tristate "Support for RPi-DAC"
2206 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2207 + select SND_SOC_PCM1794A
2208 + select SND_RPI_SIMPLE_SOUNDCARD
2210 + Say Y or M if you want to add support for RPi-DAC.
2212 +config SND_BCM2708_SOC_RPI_PROTO
2213 + tristate "Support for Rpi-PROTO"
2214 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2215 + select SND_SOC_WM8731_I2C
2217 + Say Y or M if you want to add support for Audio Codec Board PROTO (WM8731).
2219 +config SND_BCM2708_SOC_JUSTBOOM_BOTH
2220 + tristate "Support for simultaneous JustBoom Digi and JustBoom DAC"
2221 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2222 + select SND_SOC_WM8804
2223 + select SND_SOC_PCM512x
2225 + Say Y or M if you want to add support for simultaneous
2226 + JustBoom Digi and JustBoom DAC.
2228 + This is not the right choice if you only have one but both of
2231 +config SND_BCM2708_SOC_JUSTBOOM_DAC
2232 + tristate "Support for JustBoom DAC"
2233 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2234 + select SND_SOC_PCM512x
2236 + Say Y or M if you want to add support for JustBoom DAC.
2238 +config SND_BCM2708_SOC_JUSTBOOM_DIGI
2239 + tristate "Support for JustBoom Digi"
2240 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2241 + select SND_SOC_WM8804
2242 + select SND_RPI_WM8804_SOUNDCARD
2244 + Say Y or M if you want to add support for JustBoom Digi.
2246 +config SND_BCM2708_SOC_IQAUDIO_CODEC
2247 + tristate "Support for IQaudIO-CODEC"
2248 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2249 + select SND_SOC_DA7213
2251 + Say Y or M if you want to add support for IQaudIO-CODEC.
2253 +config SND_BCM2708_SOC_IQAUDIO_DAC
2254 + tristate "Support for IQaudIO-DAC"
2255 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2256 + select SND_SOC_PCM512x_I2C
2258 + Say Y or M if you want to add support for IQaudIO-DAC.
2260 +config SND_BCM2708_SOC_IQAUDIO_DIGI
2261 + tristate "Support for IQAudIO Digi"
2262 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2263 + select SND_SOC_WM8804
2264 + select SND_RPI_WM8804_SOUNDCARD
2266 + Say Y or M if you want to add support for IQAudIO Digital IO board.
2268 +config SND_BCM2708_SOC_I_SABRE_Q2M
2269 + tristate "Support for Audiophonics I-Sabre Q2M DAC"
2270 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2271 + select SND_SOC_I_SABRE_CODEC
2273 + Say Y or M if you want to add support for Audiophonics I-SABRE Q2M DAC
2275 +config SND_BCM2708_SOC_ADAU1977_ADC
2276 + tristate "Support for ADAU1977 ADC"
2277 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2278 + select SND_SOC_ADAU1977_I2C
2279 + select SND_RPI_SIMPLE_SOUNDCARD
2281 + Say Y or M if you want to add support for ADAU1977 ADC.
2283 +config SND_AUDIOINJECTOR_PI_SOUNDCARD
2284 + tristate "Support for audioinjector.net Pi add on soundcard"
2285 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2286 + select SND_SOC_WM8731_I2C
2288 + Say Y or M if you want to add support for audioinjector.net Pi Hat
2290 +config SND_AUDIOINJECTOR_OCTO_SOUNDCARD
2291 + tristate "Support for audioinjector.net Octo channel (Hat) soundcard"
2292 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2293 + select SND_SOC_CS42XX8_I2C
2295 + Say Y or M if you want to add support for audioinjector.net octo add on
2297 +config SND_AUDIOINJECTOR_ISOLATED_SOUNDCARD
2298 + tristate "Support for audioinjector.net isolated DAC and ADC soundcard"
2299 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2300 + select SND_SOC_CS4271_I2C
2302 + Say Y or M if you want to add support for audioinjector.net isolated soundcard
2304 +config SND_AUDIOSENSE_PI
2305 + tristate "Support for AudioSense Add-On Soundcard"
2306 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2307 + select SND_SOC_TLV320AIC32X4_I2C
2309 + Say Y or M if you want to add support for tlv320aic32x4 add-on
2311 +config SND_DIGIDAC1_SOUNDCARD
2312 + tristate "Support for Red Rocks Audio DigiDAC1"
2313 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2314 + select SND_SOC_WM8804
2315 + select SND_SOC_WM8741
2317 + Say Y or M if you want to add support for Red Rocks Audio DigiDAC1 board.
2319 +config SND_BCM2708_SOC_DIONAUDIO_LOCO
2320 + tristate "Support for Dion Audio LOCO DAC-AMP"
2321 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2322 + select SND_SOC_PCM5102a
2324 + Say Y or M if you want to add support for Dion Audio LOCO.
2326 +config SND_BCM2708_SOC_DIONAUDIO_LOCO_V2
2327 + tristate "Support for Dion Audio LOCO-V2 DAC-AMP"
2328 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2329 + select SND_SOC_PCM5122
2331 + Say Y or M if you want to add support for Dion Audio LOCO-V2.
2333 +config SND_BCM2708_SOC_ALLO_PIANO_DAC
2334 + tristate "Support for Allo Piano DAC"
2335 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2336 + select SND_SOC_PCM512x_I2C
2338 + Say Y or M if you want to add support for Allo Piano DAC.
2340 +config SND_BCM2708_SOC_ALLO_PIANO_DAC_PLUS
2341 + tristate "Support for Allo Piano DAC Plus"
2342 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2343 + select SND_SOC_PCM512x_I2C
2345 + Say Y or M if you want to add support for Allo Piano DAC Plus.
2347 +config SND_BCM2708_SOC_ALLO_BOSS_DAC
2348 + tristate "Support for Allo Boss DAC"
2349 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2350 + select SND_SOC_PCM512x_I2C
2351 + select COMMON_CLK_HIFIBERRY_DACPRO
2353 + Say Y or M if you want to add support for Allo Boss DAC.
2355 +config SND_BCM2708_SOC_ALLO_BOSS2_DAC
2356 + tristate "Support for Allo Boss2 DAC"
2357 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2360 + select SND_AUDIO_GRAPH_CARD
2362 + Say Y or M if you want to add support for Allo Boss2 DAC.
2364 +config SND_BCM2708_SOC_ALLO_DIGIONE
2365 + tristate "Support for Allo DigiOne"
2366 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2367 + select SND_SOC_WM8804
2368 + select SND_RPI_WM8804_SOUNDCARD
2370 + Say Y or M if you want to add support for Allo DigiOne.
2372 +config SND_BCM2708_SOC_ALLO_KATANA_DAC
2373 + tristate "Support for Allo Katana DAC"
2374 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2377 + select SND_AUDIO_GRAPH_CARD
2379 + Say Y or M if you want to add support for Allo Katana DAC.
2381 +config SND_BCM2708_SOC_FE_PI_AUDIO
2382 + tristate "Support for Fe-Pi-Audio"
2383 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2384 + select SND_SOC_SGTL5000
2386 + Say Y or M if you want to add support for Fe-Pi-Audio.
2389 + tristate "Support for Blokas Labs pisound"
2390 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2391 + select SND_RAWMIDI
2393 + Say Y or M if you want to add support for Blokas Labs pisound.
2395 +config SND_RPI_SIMPLE_SOUNDCARD
2396 + tristate "Support for Raspberry Pi simple soundcards"
2398 + Say Y or M if you want to add support Raspbery Pi simple soundcards
2400 +config SND_RPI_WM8804_SOUNDCARD
2401 + tristate "Support for Raspberry Pi generic WM8804 soundcards"
2403 + Say Y or M if you want to add support for the Raspberry Pi
2404 + generic driver for WM8804 based soundcards.
2406 +config SND_DACBERRY400
2407 + tristate "Support for DACBERRY400 Soundcard"
2408 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
2409 + select SND_SOC_TLV320AIC3X_I2C
2411 + Say Y or M if you want to add support for tlv320aic3x add-on
2412 --- a/sound/soc/bcm/Makefile
2413 +++ b/sound/soc/bcm/Makefile
2414 @@ -12,4 +12,73 @@ obj-$(CONFIG_SND_SOC_CYGNUS) += snd-soc-
2415 # BCM63XX Platform Support
2416 snd-soc-63xx-objs := bcm63xx-i2s-whistler.o bcm63xx-pcm-whistler.o
2418 -obj-$(CONFIG_SND_BCM63XX_I2S_WHISTLER) += snd-soc-63xx.o
2419 \ No newline at end of file
2420 +obj-$(CONFIG_SND_BCM63XX_I2S_WHISTLER) += snd-soc-63xx.o
2422 +# Google voiceHAT custom codec support
2423 +snd-soc-googlevoicehat-codec-objs := googlevoicehat-codec.o
2425 +# BCM2708 Machine Support
2426 +snd-soc-hifiberry-dacplus-objs := hifiberry_dacplus.o
2427 +snd-soc-hifiberry-dacplushd-objs := hifiberry_dacplushd.o
2428 +snd-soc-hifiberry-dacplusadc-objs := hifiberry_dacplusadc.o
2429 +snd-soc-hifiberry-dacplusadcpro-objs := hifiberry_dacplusadcpro.o
2430 +snd-soc-hifiberry-dacplusdsp-objs := hifiberry_dacplusdsp.o
2431 +snd-soc-justboom-both-objs := justboom-both.o
2432 +snd-soc-justboom-dac-objs := justboom-dac.o
2433 +snd-soc-rpi-cirrus-objs := rpi-cirrus.o
2434 +snd-soc-rpi-proto-objs := rpi-proto.o
2435 +snd-soc-iqaudio-codec-objs := iqaudio-codec.o
2436 +snd-soc-iqaudio-dac-objs := iqaudio-dac.o
2437 + snd-soc-i-sabre-q2m-objs := i-sabre-q2m.o
2438 +snd-soc-audioinjector-pi-soundcard-objs := audioinjector-pi-soundcard.o
2439 +snd-soc-audioinjector-octo-soundcard-objs := audioinjector-octo-soundcard.o
2440 +snd-soc-audioinjector-isolated-soundcard-objs := audioinjector-isolated-soundcard.o
2441 +snd-soc-audiosense-pi-objs := audiosense-pi.o
2442 +snd-soc-digidac1-soundcard-objs := digidac1-soundcard.o
2443 +snd-soc-dionaudio-loco-objs := dionaudio_loco.o
2444 +snd-soc-dionaudio-loco-v2-objs := dionaudio_loco-v2.o
2445 +snd-soc-allo-boss-dac-objs := allo-boss-dac.o
2446 +snd-soc-allo-boss2-dac-objs := allo-boss2-dac.o
2447 +snd-soc-allo-piano-dac-objs := allo-piano-dac.o
2448 +snd-soc-allo-piano-dac-plus-objs := allo-piano-dac-plus.o
2449 +snd-soc-allo-katana-codec-objs := allo-katana-codec.o
2450 +snd-soc-pisound-objs := pisound.o
2451 +snd-soc-fe-pi-audio-objs := fe-pi-audio.o
2452 +snd-soc-rpi-simple-soundcard-objs := rpi-simple-soundcard.o
2453 +snd-soc-rpi-wm8804-soundcard-objs := rpi-wm8804-soundcard.o
2454 +snd-soc-pifi-40-objs := pifi-40.o
2455 +snd-soc-chipdip-dac-objs := chipdip-dac.o
2456 +snd-soc-dacberry400-objs := dacberry400.o
2458 +obj-$(CONFIG_SND_BCM2708_SOC_GOOGLEVOICEHAT_SOUNDCARD) += snd-soc-googlevoicehat-codec.o
2459 +obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS) += snd-soc-hifiberry-dacplus.o
2460 +obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUSHD) += snd-soc-hifiberry-dacplushd.o
2461 +obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUSADC) += snd-soc-hifiberry-dacplusadc.o
2462 +obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUSADCPRO) += snd-soc-hifiberry-dacplusadcpro.o
2463 +obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUSDSP) += snd-soc-hifiberry-dacplusdsp.o
2464 +obj-$(CONFIG_SND_BCM2708_SOC_JUSTBOOM_BOTH) += snd-soc-justboom-both.o
2465 +obj-$(CONFIG_SND_BCM2708_SOC_JUSTBOOM_DAC) += snd-soc-justboom-dac.o
2466 +obj-$(CONFIG_SND_BCM2708_SOC_RPI_CIRRUS) += snd-soc-rpi-cirrus.o
2467 +obj-$(CONFIG_SND_BCM2708_SOC_RPI_PROTO) += snd-soc-rpi-proto.o
2468 +obj-$(CONFIG_SND_BCM2708_SOC_IQAUDIO_CODEC) += snd-soc-iqaudio-codec.o
2469 +obj-$(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) += snd-soc-iqaudio-dac.o
2470 +obj-$(CONFIG_SND_BCM2708_SOC_I_SABRE_Q2M) += snd-soc-i-sabre-q2m.o
2471 +obj-$(CONFIG_SND_AUDIOINJECTOR_PI_SOUNDCARD) += snd-soc-audioinjector-pi-soundcard.o
2472 +obj-$(CONFIG_SND_AUDIOINJECTOR_OCTO_SOUNDCARD) += snd-soc-audioinjector-octo-soundcard.o
2473 +obj-$(CONFIG_SND_AUDIOINJECTOR_ISOLATED_SOUNDCARD) += snd-soc-audioinjector-isolated-soundcard.o
2474 +obj-$(CONFIG_SND_AUDIOSENSE_PI) += snd-soc-audiosense-pi.o
2475 +obj-$(CONFIG_SND_DIGIDAC1_SOUNDCARD) += snd-soc-digidac1-soundcard.o
2476 +obj-$(CONFIG_SND_BCM2708_SOC_DIONAUDIO_LOCO) += snd-soc-dionaudio-loco.o
2477 +obj-$(CONFIG_SND_BCM2708_SOC_DIONAUDIO_LOCO_V2) += snd-soc-dionaudio-loco-v2.o
2478 +obj-$(CONFIG_SND_BCM2708_SOC_ALLO_BOSS_DAC) += snd-soc-allo-boss-dac.o
2479 +obj-$(CONFIG_SND_BCM2708_SOC_ALLO_BOSS2_DAC) += snd-soc-allo-boss2-dac.o
2480 +obj-$(CONFIG_SND_BCM2708_SOC_ALLO_PIANO_DAC) += snd-soc-allo-piano-dac.o
2481 +obj-$(CONFIG_SND_BCM2708_SOC_ALLO_PIANO_DAC_PLUS) += snd-soc-allo-piano-dac-plus.o
2482 +obj-$(CONFIG_SND_BCM2708_SOC_ALLO_KATANA_DAC) += snd-soc-allo-katana-codec.o
2483 +obj-$(CONFIG_SND_PISOUND) += snd-soc-pisound.o
2484 +obj-$(CONFIG_SND_BCM2708_SOC_FE_PI_AUDIO) += snd-soc-fe-pi-audio.o
2485 +obj-$(CONFIG_SND_RPI_SIMPLE_SOUNDCARD) += snd-soc-rpi-simple-soundcard.o
2486 +obj-$(CONFIG_SND_RPI_WM8804_SOUNDCARD) += snd-soc-rpi-wm8804-soundcard.o
2487 +obj-$(CONFIG_SND_BCM2708_SOC_PIFI_40) += snd-soc-pifi-40.o
2488 +obj-$(CONFIG_SND_BCM2708_SOC_CHIPDIP_DAC) += snd-soc-chipdip-dac.o
2489 +obj-$(CONFIG_SND_DACBERRY400) += snd-soc-dacberry400.o
2491 +++ b/sound/soc/bcm/allo-boss-dac.c
2494 + * ALSA ASoC Machine Driver for Allo Boss DAC
2496 + * Author: Baswaraj K <jaikumar@cem-solutions.net>
2498 + * based on code by Daniel Matuschek,
2499 + * Stuart MacLean <stuart@hifiberry.com>
2500 + * based on code by Florian Meier <florian.meier@koalo.de>
2502 + * This program is free software; you can redistribute it and/or
2503 + * modify it under the terms of the GNU General Public License
2504 + * version 2 as published by the Free Software Foundation.
2506 + * This program is distributed in the hope that it will be useful, but
2507 + * WITHOUT ANY WARRANTY; without even the implied warranty of
2508 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2509 + * General Public License for more details.
2512 +#include <linux/module.h>
2513 +#include <linux/gpio/consumer.h>
2514 +#include <linux/platform_device.h>
2515 +#include <linux/clk.h>
2516 +#include <linux/delay.h>
2518 +#include <sound/core.h>
2519 +#include <sound/pcm.h>
2520 +#include <sound/pcm_params.h>
2521 +#include <sound/soc.h>
2522 +#include "../codecs/pcm512x.h"
2524 +#define ALLO_BOSS_NOCLOCK 0
2525 +#define ALLO_BOSS_CLK44EN 1
2526 +#define ALLO_BOSS_CLK48EN 2
2528 +struct pcm512x_priv {
2529 + struct regmap *regmap;
2533 +static struct gpio_desc *mute_gpio;
2535 +/* Clock rate of CLK44EN attached to GPIO6 pin */
2536 +#define CLK_44EN_RATE 45158400UL
2537 +/* Clock rate of CLK48EN attached to GPIO3 pin */
2538 +#define CLK_48EN_RATE 49152000UL
2541 +static bool snd_soc_allo_boss_master;
2542 +static bool digital_gain_0db_limit = true;
2544 +static void snd_allo_boss_select_clk(struct snd_soc_component *component,
2548 + case ALLO_BOSS_NOCLOCK:
2549 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x24, 0x00);
2551 + case ALLO_BOSS_CLK44EN:
2552 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x24, 0x20);
2554 + case ALLO_BOSS_CLK48EN:
2555 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x24, 0x04);
2560 +static void snd_allo_boss_clk_gpio(struct snd_soc_component *component)
2562 + snd_soc_component_update_bits(component, PCM512x_GPIO_EN, 0x24, 0x24);
2563 + snd_soc_component_update_bits(component, PCM512x_GPIO_OUTPUT_3, 0x0f, 0x02);
2564 + snd_soc_component_update_bits(component, PCM512x_GPIO_OUTPUT_6, 0x0f, 0x02);
2567 +static bool snd_allo_boss_is_sclk(struct snd_soc_component *component)
2571 + sck = snd_soc_component_read(component, PCM512x_RATE_DET_4);
2572 + return (!(sck & 0x40));
2575 +static bool snd_allo_boss_is_sclk_sleep(
2576 + struct snd_soc_component *component)
2579 + return snd_allo_boss_is_sclk(component);
2582 +static bool snd_allo_boss_is_master_card(struct snd_soc_component *component)
2584 + bool isClk44EN, isClk48En, isNoClk;
2586 + snd_allo_boss_clk_gpio(component);
2588 + snd_allo_boss_select_clk(component, ALLO_BOSS_CLK44EN);
2589 + isClk44EN = snd_allo_boss_is_sclk_sleep(component);
2591 + snd_allo_boss_select_clk(component, ALLO_BOSS_NOCLOCK);
2592 + isNoClk = snd_allo_boss_is_sclk_sleep(component);
2594 + snd_allo_boss_select_clk(component, ALLO_BOSS_CLK48EN);
2595 + isClk48En = snd_allo_boss_is_sclk_sleep(component);
2597 + return (isClk44EN && isClk48En && !isNoClk);
2600 +static int snd_allo_boss_clk_for_rate(int sample_rate)
2604 + switch (sample_rate) {
2611 + type = ALLO_BOSS_CLK44EN;
2614 + type = ALLO_BOSS_CLK48EN;
2620 +static void snd_allo_boss_set_sclk(struct snd_soc_component *component,
2623 + struct pcm512x_priv *pcm512x = snd_soc_component_get_drvdata(component);
2625 + if (!IS_ERR(pcm512x->sclk)) {
2628 + ctype = snd_allo_boss_clk_for_rate(sample_rate);
2629 + clk_set_rate(pcm512x->sclk, (ctype == ALLO_BOSS_CLK44EN)
2630 + ? CLK_44EN_RATE : CLK_48EN_RATE);
2631 + snd_allo_boss_select_clk(component, ctype);
2635 +static int snd_allo_boss_init(struct snd_soc_pcm_runtime *rtd)
2637 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
2638 + struct pcm512x_priv *priv = snd_soc_component_get_drvdata(component);
2641 + snd_soc_allo_boss_master = false;
2643 + snd_soc_allo_boss_master =
2644 + snd_allo_boss_is_master_card(component);
2646 + if (snd_soc_allo_boss_master) {
2647 + struct snd_soc_dai_link *dai = rtd->dai_link;
2649 + dai->name = "BossDAC";
2650 + dai->stream_name = "Boss DAC HiFi [Master]";
2651 + dai->dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
2652 + | SND_SOC_DAIFMT_CBM_CFM;
2654 + snd_soc_component_update_bits(component, PCM512x_BCLK_LRCLK_CFG, 0x31, 0x11);
2655 + snd_soc_component_update_bits(component, PCM512x_MASTER_MODE, 0x03, 0x03);
2656 + snd_soc_component_update_bits(component, PCM512x_MASTER_CLKDIV_2, 0x7f, 63);
2658 + * Default sclk to CLK_48EN_RATE, otherwise codec
2659 + * pcm512x_dai_startup_master method could call
2660 + * snd_pcm_hw_constraint_ratnums using CLK_44EN/64
2661 + * which will mask 384k sample rate.
2663 + if (!IS_ERR(priv->sclk))
2664 + clk_set_rate(priv->sclk, CLK_48EN_RATE);
2666 + priv->sclk = ERR_PTR(-ENOENT);
2669 + snd_soc_component_update_bits(component, PCM512x_GPIO_EN, 0x08, 0x08);
2670 + snd_soc_component_update_bits(component, PCM512x_GPIO_OUTPUT_4, 0x0f, 0x02);
2671 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x08, 0x08);
2673 + if (digital_gain_0db_limit) {
2675 + struct snd_soc_card *card = rtd->card;
2677 + ret = snd_soc_limit_volume(card, "Digital Playback Volume",
2680 + dev_warn(card->dev, "Failed to set volume limit: %d\n",
2687 +static int snd_allo_boss_update_rate_den(
2688 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
2690 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
2691 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
2692 + struct pcm512x_priv *pcm512x = snd_soc_component_get_drvdata(component);
2693 + struct snd_ratnum *rats_no_pll;
2694 + unsigned int num = 0, den = 0;
2697 + rats_no_pll = devm_kzalloc(rtd->dev, sizeof(*rats_no_pll), GFP_KERNEL);
2701 + rats_no_pll->num = clk_get_rate(pcm512x->sclk) / 64;
2702 + rats_no_pll->den_min = 1;
2703 + rats_no_pll->den_max = 128;
2704 + rats_no_pll->den_step = 1;
2706 + err = snd_interval_ratnum(hw_param_interval(params,
2707 + SNDRV_PCM_HW_PARAM_RATE), 1, rats_no_pll, &num, &den);
2708 + if (err >= 0 && den) {
2709 + params->rate_num = num;
2710 + params->rate_den = den;
2713 + devm_kfree(rtd->dev, rats_no_pll);
2717 +static void snd_allo_boss_gpio_mute(struct snd_soc_card *card)
2720 + gpiod_set_value_cansleep(mute_gpio, 1);
2723 +static void snd_allo_boss_gpio_unmute(struct snd_soc_card *card)
2726 + gpiod_set_value_cansleep(mute_gpio, 0);
2729 +static int snd_allo_boss_set_bias_level(struct snd_soc_card *card,
2730 + struct snd_soc_dapm_context *dapm, enum snd_soc_bias_level level)
2732 + struct snd_soc_pcm_runtime *rtd;
2733 + struct snd_soc_dai *codec_dai;
2735 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
2736 + codec_dai = asoc_rtd_to_codec(rtd, 0);
2738 + if (dapm->dev != codec_dai->dev)
2742 + case SND_SOC_BIAS_PREPARE:
2743 + if (dapm->bias_level != SND_SOC_BIAS_STANDBY)
2746 + snd_allo_boss_gpio_unmute(card);
2749 + case SND_SOC_BIAS_STANDBY:
2750 + if (dapm->bias_level != SND_SOC_BIAS_PREPARE)
2753 + snd_allo_boss_gpio_mute(card);
2763 +static int snd_allo_boss_hw_params(
2764 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
2767 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
2768 + int channels = params_channels(params);
2769 + int width = snd_pcm_format_physical_width(params_format(params));
2771 + if (snd_soc_allo_boss_master) {
2772 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
2774 + snd_allo_boss_set_sclk(component,
2775 + params_rate(params));
2777 + ret = snd_allo_boss_update_rate_den(
2778 + substream, params);
2783 + ret = snd_soc_dai_set_bclk_ratio(asoc_rtd_to_cpu(rtd, 0), channels * width);
2786 + ret = snd_soc_dai_set_bclk_ratio(asoc_rtd_to_codec(rtd, 0), channels * width);
2790 +static int snd_allo_boss_startup(
2791 + struct snd_pcm_substream *substream)
2793 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
2794 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
2795 + struct snd_soc_card *card = rtd->card;
2797 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x08, 0x08);
2798 + snd_allo_boss_gpio_mute(card);
2800 + if (snd_soc_allo_boss_master) {
2801 + struct pcm512x_priv *priv = snd_soc_component_get_drvdata(component);
2803 + * Default sclk to CLK_48EN_RATE, otherwise codec
2804 + * pcm512x_dai_startup_master method could call
2805 + * snd_pcm_hw_constraint_ratnums using CLK_44EN/64
2806 + * which will mask 384k sample rate.
2808 + if (!IS_ERR(priv->sclk))
2809 + clk_set_rate(priv->sclk, CLK_48EN_RATE);
2815 +static void snd_allo_boss_shutdown(
2816 + struct snd_pcm_substream *substream)
2818 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
2819 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
2821 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x08, 0x00);
2824 +static int snd_allo_boss_prepare(
2825 + struct snd_pcm_substream *substream)
2827 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
2828 + struct snd_soc_card *card = rtd->card;
2830 + snd_allo_boss_gpio_unmute(card);
2833 +/* machine stream operations */
2834 +static struct snd_soc_ops snd_allo_boss_ops = {
2835 + .hw_params = snd_allo_boss_hw_params,
2836 + .startup = snd_allo_boss_startup,
2837 + .shutdown = snd_allo_boss_shutdown,
2838 + .prepare = snd_allo_boss_prepare,
2841 +SND_SOC_DAILINK_DEFS(allo_boss,
2842 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
2843 + DAILINK_COMP_ARRAY(COMP_CODEC("pcm512x.1-004d", "pcm512x-hifi")),
2844 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
2846 +static struct snd_soc_dai_link snd_allo_boss_dai[] = {
2848 + .name = "Boss DAC",
2849 + .stream_name = "Boss DAC HiFi",
2850 + .dai_fmt = SND_SOC_DAIFMT_I2S |
2851 + SND_SOC_DAIFMT_NB_NF |
2852 + SND_SOC_DAIFMT_CBS_CFS,
2853 + .ops = &snd_allo_boss_ops,
2854 + .init = snd_allo_boss_init,
2855 + SND_SOC_DAILINK_REG(allo_boss),
2859 +/* audio machine driver */
2860 +static struct snd_soc_card snd_allo_boss = {
2861 + .name = "BossDAC",
2862 + .owner = THIS_MODULE,
2863 + .dai_link = snd_allo_boss_dai,
2864 + .num_links = ARRAY_SIZE(snd_allo_boss_dai),
2867 +static int snd_allo_boss_probe(struct platform_device *pdev)
2871 + snd_allo_boss.dev = &pdev->dev;
2873 + if (pdev->dev.of_node) {
2874 + struct device_node *i2s_node;
2875 + struct snd_soc_dai_link *dai;
2877 + dai = &snd_allo_boss_dai[0];
2878 + i2s_node = of_parse_phandle(pdev->dev.of_node,
2879 + "i2s-controller", 0);
2882 + dai->cpus->dai_name = NULL;
2883 + dai->cpus->of_node = i2s_node;
2884 + dai->platforms->name = NULL;
2885 + dai->platforms->of_node = i2s_node;
2888 + digital_gain_0db_limit = !of_property_read_bool(
2889 + pdev->dev.of_node, "allo,24db_digital_gain");
2890 + slave = of_property_read_bool(pdev->dev.of_node,
2893 + mute_gpio = devm_gpiod_get_optional(&pdev->dev, "mute",
2895 + if (IS_ERR(mute_gpio)) {
2896 + ret = PTR_ERR(mute_gpio);
2897 + dev_err(&pdev->dev,
2898 + "failed to get mute gpio: %d\n", ret);
2903 + snd_allo_boss.set_bias_level =
2904 + snd_allo_boss_set_bias_level;
2906 + ret = snd_soc_register_card(&snd_allo_boss);
2908 + dev_err(&pdev->dev,
2909 + "snd_soc_register_card() failed: %d\n", ret);
2914 + snd_allo_boss_gpio_mute(&snd_allo_boss);
2922 +static int snd_allo_boss_remove(struct platform_device *pdev)
2924 + snd_allo_boss_gpio_mute(&snd_allo_boss);
2925 + snd_soc_unregister_card(&snd_allo_boss);
2929 +static const struct of_device_id snd_allo_boss_of_match[] = {
2930 + { .compatible = "allo,boss-dac", },
2931 + { /* sentinel */ },
2933 +MODULE_DEVICE_TABLE(of, snd_allo_boss_of_match);
2935 +static struct platform_driver snd_allo_boss_driver = {
2937 + .name = "snd-allo-boss-dac",
2938 + .owner = THIS_MODULE,
2939 + .of_match_table = snd_allo_boss_of_match,
2941 + .probe = snd_allo_boss_probe,
2942 + .remove = snd_allo_boss_remove,
2945 +module_platform_driver(snd_allo_boss_driver);
2947 +MODULE_AUTHOR("Baswaraj K <jaikumar@cem-solutions.net>");
2948 +MODULE_DESCRIPTION("ALSA ASoC Machine Driver for Allo Boss DAC");
2949 +MODULE_LICENSE("GPL v2");
2951 +++ b/sound/soc/bcm/allo-boss2-dac.c
2954 + * Driver for the ALLO KATANA CODEC
2956 + * Author: Jaikumar <sudeepkumar@cem-solutions.net>
2959 + * This program is free software; you can redistribute it and/or
2960 + * modify it under the terms of the GNU General Public License
2961 + * version 2 as published by the Free Software Foundation.
2963 + * This program is distributed in the hope that it will be useful, but
2964 + * WITHOUT ANY WARRANTY; without even the implied warranty of
2965 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2966 + * General Public License for more details.
2969 +#include <linux/module.h>
2970 +#include <linux/moduleparam.h>
2971 +#include <linux/kernel.h>
2972 +#include <linux/init.h>
2973 +#include <linux/delay.h>
2974 +#include <linux/gpio.h>
2975 +#include <linux/gpio/consumer.h>
2976 +#include <linux/platform_device.h>
2977 +#include <linux/pm.h>
2978 +#include <linux/i2c.h>
2979 +#include <linux/of_device.h>
2980 +#include <linux/regmap.h>
2981 +#include <linux/slab.h>
2982 +#include <sound/core.h>
2983 +#include <sound/pcm.h>
2984 +#include <sound/pcm_params.h>
2985 +#include <sound/soc.h>
2986 +#include <sound/soc-dapm.h>
2987 +#include <sound/initval.h>
2988 +#include <sound/tlv.h>
2989 +#include <linux/of_gpio.h>
2990 +#include <linux/regulator/consumer.h>
2991 +#include <linux/pm_runtime.h>
2992 +#include <linux/of_irq.h>
2993 +#include <linux/completion.h>
2994 +#include <linux/mutex.h>
2995 +#include <linux/workqueue.h>
2996 +#include <sound/jack.h>
2998 +#include "../codecs/cs43130.h"
3000 +#include <linux/clk.h>
3001 +#include <linux/gcd.h>
3004 +#define CS43130_DSD_EN_MASK 0x10
3005 +#define CS43130_PDN_DONE_INT_MASK 0x00
3007 +static struct gpio_desc *snd_allo_clk44gpio;
3008 +static struct gpio_desc *snd_allo_clk48gpio;
3010 +struct cs43130_priv {
3011 + struct snd_soc_component *component;
3012 + struct regmap *regmap;
3013 + struct regulator_bulk_data supplies[CS43130_NUM_SUPPLIES];
3014 + struct gpio_desc *reset_gpio;
3015 + unsigned int dev_id; /* codec device ID */
3017 + /* shared by both DAIs */
3018 + struct mutex clk_mutex;
3021 + struct completion xtal_rdy;
3022 + struct completion pll_rdy;
3023 + unsigned int mclk;
3024 + unsigned int mclk_int;
3027 + /* DAI specific */
3028 + struct cs43130_dai dais[CS43130_DAI_ID_MAX];
3030 + /* HP load specific */
3034 + struct completion hpload_evt;
3035 + unsigned int hpload_stat;
3037 + u16 dc_threshold[CS43130_DC_THRESHOLD];
3038 + u16 ac_freq[CS43130_AC_FREQ];
3039 + u16 hpload_ac[CS43130_AC_FREQ][2];
3040 + struct workqueue_struct *wq;
3041 + struct work_struct work;
3042 + struct snd_soc_jack jack;
3045 +static const struct reg_default cs43130_reg_defaults[] = {
3046 + {CS43130_SYS_CLK_CTL_1, 0x06},
3047 + {CS43130_SP_SRATE, 0x01},
3048 + {CS43130_SP_BITSIZE, 0x05},
3049 + {CS43130_PAD_INT_CFG, 0x03},
3050 + {CS43130_PWDN_CTL, 0xFE},
3051 + {CS43130_CRYSTAL_SET, 0x04},
3052 + {CS43130_PLL_SET_1, 0x00},
3053 + {CS43130_PLL_SET_2, 0x00},
3054 + {CS43130_PLL_SET_3, 0x00},
3055 + {CS43130_PLL_SET_4, 0x00},
3056 + {CS43130_PLL_SET_5, 0x40},
3057 + {CS43130_PLL_SET_6, 0x10},
3058 + {CS43130_PLL_SET_7, 0x80},
3059 + {CS43130_PLL_SET_8, 0x03},
3060 + {CS43130_PLL_SET_9, 0x02},
3061 + {CS43130_PLL_SET_10, 0x02},
3062 + {CS43130_CLKOUT_CTL, 0x00},
3063 + {CS43130_ASP_NUM_1, 0x01},
3064 + {CS43130_ASP_NUM_2, 0x00},
3065 + {CS43130_ASP_DEN_1, 0x08},
3066 + {CS43130_ASP_DEN_2, 0x00},
3067 + {CS43130_ASP_LRCK_HI_TIME_1, 0x1F},
3068 + {CS43130_ASP_LRCK_HI_TIME_2, 0x00},
3069 + {CS43130_ASP_LRCK_PERIOD_1, 0x3F},
3070 + {CS43130_ASP_LRCK_PERIOD_2, 0x00},
3071 + {CS43130_ASP_CLOCK_CONF, 0x0C},
3072 + {CS43130_ASP_FRAME_CONF, 0x0A},
3073 + {CS43130_XSP_NUM_1, 0x01},
3074 + {CS43130_XSP_NUM_2, 0x00},
3075 + {CS43130_XSP_DEN_1, 0x02},
3076 + {CS43130_XSP_DEN_2, 0x00},
3077 + {CS43130_XSP_LRCK_HI_TIME_1, 0x1F},
3078 + {CS43130_XSP_LRCK_HI_TIME_2, 0x00},
3079 + {CS43130_XSP_LRCK_PERIOD_1, 0x3F},
3080 + {CS43130_XSP_LRCK_PERIOD_2, 0x00},
3081 + {CS43130_XSP_CLOCK_CONF, 0x0C},
3082 + {CS43130_XSP_FRAME_CONF, 0x0A},
3083 + {CS43130_ASP_CH_1_LOC, 0x00},
3084 + {CS43130_ASP_CH_2_LOC, 0x00},
3085 + {CS43130_ASP_CH_1_SZ_EN, 0x06},
3086 + {CS43130_ASP_CH_2_SZ_EN, 0x0E},
3087 + {CS43130_XSP_CH_1_LOC, 0x00},
3088 + {CS43130_XSP_CH_2_LOC, 0x00},
3089 + {CS43130_XSP_CH_1_SZ_EN, 0x06},
3090 + {CS43130_XSP_CH_2_SZ_EN, 0x0E},
3091 + {CS43130_DSD_VOL_B, 0x78},
3092 + {CS43130_DSD_VOL_A, 0x78},
3093 + {CS43130_DSD_PATH_CTL_1, 0xA8},
3094 + {CS43130_DSD_INT_CFG, 0x00},
3095 + {CS43130_DSD_PATH_CTL_2, 0x02},
3096 + {CS43130_DSD_PCM_MIX_CTL, 0x00},
3097 + {CS43130_DSD_PATH_CTL_3, 0x40},
3098 + {CS43130_HP_OUT_CTL_1, 0x30},
3099 + {CS43130_PCM_FILT_OPT, 0x02},
3100 + {CS43130_PCM_VOL_B, 0x78},
3101 + {CS43130_PCM_VOL_A, 0x78},
3102 + {CS43130_PCM_PATH_CTL_1, 0xA8},
3103 + {CS43130_PCM_PATH_CTL_2, 0x00},
3104 + {CS43130_CLASS_H_CTL, 0x1E},
3105 + {CS43130_HP_DETECT, 0x04},
3106 + {CS43130_HP_LOAD_1, 0x00},
3107 + {CS43130_HP_MEAS_LOAD_1, 0x00},
3108 + {CS43130_HP_MEAS_LOAD_2, 0x00},
3109 + {CS43130_INT_MASK_1, 0xFF},
3110 + {CS43130_INT_MASK_2, 0xFF},
3111 + {CS43130_INT_MASK_3, 0xFF},
3112 + {CS43130_INT_MASK_4, 0xFF},
3113 + {CS43130_INT_MASK_5, 0xFF},
3115 +static bool cs43130_volatile_register(struct device *dev, unsigned int reg)
3118 + case CS43130_INT_STATUS_1 ... CS43130_INT_STATUS_5:
3119 + case CS43130_HP_DC_STAT_1 ... CS43130_HP_DC_STAT_2:
3120 + case CS43130_HP_AC_STAT_1 ... CS43130_HP_AC_STAT_2:
3127 +static const char * const pcm_spd_texts[] = {
3132 +static SOC_ENUM_SINGLE_DECL(pcm_spd_enum, CS43130_PCM_FILT_OPT, 7,
3135 +static const SNDRV_CTL_TLVD_DECLARE_DB_MINMAX(master_tlv, -12750, 0);
3137 +static const struct snd_kcontrol_new cs43130_controls[] = {
3138 + SOC_DOUBLE_R_TLV("Master Playback Volume", CS43130_PCM_VOL_B,
3139 + CS43130_PCM_VOL_A, 0, 255, 1, master_tlv),
3140 + SOC_DOUBLE("Master Playback Switch", CS43130_PCM_PATH_CTL_1,
3142 + SOC_DOUBLE_R_TLV("Digital Playback Volume", CS43130_DSD_VOL_B,
3143 + CS43130_DSD_VOL_A, 0, 255, 1, master_tlv),
3144 + SOC_DOUBLE("Digital Playback Switch", CS43130_DSD_PATH_CTL_1,
3146 + SOC_SINGLE("HV_Enable", CS43130_HP_OUT_CTL_1, 0, 1, 0),
3147 + SOC_ENUM("PCM Filter Speed", pcm_spd_enum),
3148 + SOC_SINGLE("PCM Phase Compensation", CS43130_PCM_FILT_OPT, 6, 1, 0),
3149 + SOC_SINGLE("PCM Nonoversample Emulate", CS43130_PCM_FILT_OPT, 5, 1, 0),
3150 + SOC_SINGLE("PCM High-pass Filter", CS43130_PCM_FILT_OPT, 1, 1, 0),
3151 + SOC_SINGLE("PCM De-emphasis Filter", CS43130_PCM_FILT_OPT, 0, 1, 0),
3154 +static bool cs43130_readable_register(struct device *dev, unsigned int reg)
3157 + case CS43130_DEVID_AB ... CS43130_SYS_CLK_CTL_1:
3158 + case CS43130_SP_SRATE ... CS43130_PAD_INT_CFG:
3159 + case CS43130_PWDN_CTL:
3160 + case CS43130_CRYSTAL_SET:
3161 + case CS43130_PLL_SET_1 ... CS43130_PLL_SET_5:
3162 + case CS43130_PLL_SET_6:
3163 + case CS43130_PLL_SET_7:
3164 + case CS43130_PLL_SET_8:
3165 + case CS43130_PLL_SET_9:
3166 + case CS43130_PLL_SET_10:
3167 + case CS43130_CLKOUT_CTL:
3168 + case CS43130_ASP_NUM_1 ... CS43130_ASP_FRAME_CONF:
3169 + case CS43130_XSP_NUM_1 ... CS43130_XSP_FRAME_CONF:
3170 + case CS43130_ASP_CH_1_LOC:
3171 + case CS43130_ASP_CH_2_LOC:
3172 + case CS43130_ASP_CH_1_SZ_EN:
3173 + case CS43130_ASP_CH_2_SZ_EN:
3174 + case CS43130_XSP_CH_1_LOC:
3175 + case CS43130_XSP_CH_2_LOC:
3176 + case CS43130_XSP_CH_1_SZ_EN:
3177 + case CS43130_XSP_CH_2_SZ_EN:
3178 + case CS43130_DSD_VOL_B ... CS43130_DSD_PATH_CTL_3:
3179 + case CS43130_HP_OUT_CTL_1:
3180 + case CS43130_PCM_FILT_OPT ... CS43130_PCM_PATH_CTL_2:
3181 + case CS43130_CLASS_H_CTL:
3182 + case CS43130_HP_DETECT:
3183 + case CS43130_HP_STATUS:
3184 + case CS43130_HP_LOAD_1:
3185 + case CS43130_HP_MEAS_LOAD_1:
3186 + case CS43130_HP_MEAS_LOAD_2:
3187 + case CS43130_HP_DC_STAT_1:
3188 + case CS43130_HP_DC_STAT_2:
3189 + case CS43130_HP_AC_STAT_1:
3190 + case CS43130_HP_AC_STAT_2:
3191 + case CS43130_HP_LOAD_STAT:
3192 + case CS43130_INT_STATUS_1 ... CS43130_INT_STATUS_5:
3193 + case CS43130_INT_MASK_1 ... CS43130_INT_MASK_5:
3199 +static bool cs43130_precious_register(struct device *dev, unsigned int reg)
3202 + case CS43130_INT_STATUS_1 ... CS43130_INT_STATUS_5:
3208 +static int cs43130_pcm_pdn(struct snd_soc_component *component)
3210 + struct cs43130_priv *cs43130 =
3211 + snd_soc_component_get_drvdata(component);
3213 + unsigned int reg, pdn_int;
3215 + regmap_write(cs43130->regmap, CS43130_DSD_PATH_CTL_2, 0x02);
3216 + regmap_update_bits(cs43130->regmap, CS43130_INT_MASK_1,
3217 + CS43130_PDN_DONE_INT_MASK, 0);
3218 + regmap_update_bits(cs43130->regmap, CS43130_PWDN_CTL,
3219 + CS43130_PDN_HP_MASK, 1 << CS43130_PDN_HP_SHIFT);
3220 + usleep_range(10, 50);
3221 + ret = regmap_read(cs43130->regmap, CS43130_INT_STATUS_1, ®);
3222 + pdn_int = reg & 0xFE;
3223 + regmap_update_bits(cs43130->regmap, CS43130_PWDN_CTL,
3224 + CS43130_PDN_ASP_MASK, 1 << CS43130_PDN_ASP_SHIFT);
3228 +static int cs43130_pwr_up_asp_dac(struct snd_soc_component *component)
3230 + struct cs43130_priv *cs43130 =
3231 + snd_soc_component_get_drvdata(component);
3233 + regmap_update_bits(cs43130->regmap, CS43130_PAD_INT_CFG,
3234 + CS43130_ASP_3ST_MASK, 0);
3235 + regmap_write(cs43130->regmap, CS43130_DXD1, 0x99);
3236 + regmap_write(cs43130->regmap, CS43130_DXD13, 0x20);
3237 + regmap_update_bits(cs43130->regmap, CS43130_PWDN_CTL,
3238 + CS43130_PDN_ASP_MASK, 0);
3239 + regmap_update_bits(cs43130->regmap, CS43130_PWDN_CTL,
3240 + CS43130_PDN_HP_MASK, 0);
3241 + usleep_range(10000, 12000);
3242 + regmap_write(cs43130->regmap, CS43130_DXD1, 0x00);
3243 + regmap_write(cs43130->regmap, CS43130_DXD13, 0x00);
3246 +static int cs43130_change_clksrc(struct snd_soc_component *component,
3247 + enum cs43130_mclk_src_sel src)
3250 + struct cs43130_priv *cs43130 =
3251 + snd_soc_component_get_drvdata(component);
3252 + int mclk_int_decoded;
3254 + if (src == cs43130->mclk_int_src) {
3255 + /* clk source has not changed */
3258 + switch (cs43130->mclk_int) {
3259 + case CS43130_MCLK_22M:
3260 + mclk_int_decoded = CS43130_MCLK_22P5;
3262 + case CS43130_MCLK_24M:
3263 + mclk_int_decoded = CS43130_MCLK_24P5;
3266 + dev_err(component->dev, "Invalid MCLK INT freq: %u\n",
3267 + cs43130->mclk_int);
3272 + case CS43130_MCLK_SRC_EXT:
3273 + cs43130->pll_bypass = true;
3274 + cs43130->mclk_int_src = CS43130_MCLK_SRC_EXT;
3275 + if (cs43130->xtal_ibias == CS43130_XTAL_UNUSED) {
3276 + regmap_update_bits(cs43130->regmap, CS43130_PWDN_CTL,
3277 + CS43130_PDN_XTAL_MASK,
3278 + 1 << CS43130_PDN_XTAL_SHIFT);
3280 + reinit_completion(&cs43130->xtal_rdy);
3281 + regmap_update_bits(cs43130->regmap, CS43130_INT_MASK_1,
3282 + CS43130_XTAL_RDY_INT_MASK, 0);
3283 + regmap_update_bits(cs43130->regmap, CS43130_PWDN_CTL,
3284 + CS43130_PDN_XTAL_MASK, 0);
3285 + ret = wait_for_completion_timeout(&cs43130->xtal_rdy,
3286 + msecs_to_jiffies(100));
3287 + regmap_update_bits(cs43130->regmap, CS43130_INT_MASK_1,
3288 + CS43130_XTAL_RDY_INT_MASK,
3289 + 1 << CS43130_XTAL_RDY_INT_SHIFT);
3291 + dev_err(component->dev, "Timeout waiting for XTAL_READY interrupt\n");
3292 + return -ETIMEDOUT;
3295 + regmap_update_bits(cs43130->regmap, CS43130_SYS_CLK_CTL_1,
3296 + CS43130_MCLK_SRC_SEL_MASK,
3297 + src << CS43130_MCLK_SRC_SEL_SHIFT);
3298 + regmap_update_bits(cs43130->regmap, CS43130_SYS_CLK_CTL_1,
3299 + CS43130_MCLK_INT_MASK,
3300 + mclk_int_decoded << CS43130_MCLK_INT_SHIFT);
3301 + usleep_range(150, 200);
3302 + regmap_update_bits(cs43130->regmap, CS43130_PWDN_CTL,
3303 + CS43130_PDN_PLL_MASK,
3304 + 1 << CS43130_PDN_PLL_SHIFT);
3306 + case CS43130_MCLK_SRC_RCO:
3307 + cs43130->mclk_int_src = CS43130_MCLK_SRC_RCO;
3309 + regmap_update_bits(cs43130->regmap, CS43130_SYS_CLK_CTL_1,
3310 + CS43130_MCLK_SRC_SEL_MASK,
3311 + src << CS43130_MCLK_SRC_SEL_SHIFT);
3312 + regmap_update_bits(cs43130->regmap, CS43130_SYS_CLK_CTL_1,
3313 + CS43130_MCLK_INT_MASK,
3314 + CS43130_MCLK_22P5 << CS43130_MCLK_INT_SHIFT);
3315 + usleep_range(150, 200);
3316 + regmap_update_bits(cs43130->regmap, CS43130_PWDN_CTL,
3317 + CS43130_PDN_XTAL_MASK,
3318 + 1 << CS43130_PDN_XTAL_SHIFT);
3319 + regmap_update_bits(cs43130->regmap, CS43130_PWDN_CTL,
3320 + CS43130_PDN_PLL_MASK,
3321 + 1 << CS43130_PDN_PLL_SHIFT);
3324 + dev_err(component->dev, "Invalid MCLK source value\n");
3330 +static const struct cs43130_bitwidth_map cs43130_bitwidth_table[] = {
3331 + {8, CS43130_SP_BIT_SIZE_8, CS43130_CH_BIT_SIZE_8},
3332 + {16, CS43130_SP_BIT_SIZE_16, CS43130_CH_BIT_SIZE_16},
3333 + {24, CS43130_SP_BIT_SIZE_24, CS43130_CH_BIT_SIZE_24},
3334 + {32, CS43130_SP_BIT_SIZE_32, CS43130_CH_BIT_SIZE_32},
3337 +static const struct cs43130_bitwidth_map *cs43130_get_bitwidth_table(
3338 + unsigned int bitwidth)
3342 + for (i = 0; i < ARRAY_SIZE(cs43130_bitwidth_table); i++) {
3343 + if (cs43130_bitwidth_table[i].bitwidth == bitwidth)
3344 + return &cs43130_bitwidth_table[i];
3349 +static int cs43130_set_bitwidth(int dai_id, unsigned int bitwidth_dai,
3350 + struct regmap *regmap)
3352 + const struct cs43130_bitwidth_map *bw_map;
3354 + bw_map = cs43130_get_bitwidth_table(bitwidth_dai);
3359 + case CS43130_ASP_PCM_DAI:
3360 + case CS43130_ASP_DOP_DAI:
3361 + regmap_update_bits(regmap, CS43130_ASP_CH_1_SZ_EN,
3362 + CS43130_CH_BITSIZE_MASK, bw_map->ch_bit);
3363 + regmap_update_bits(regmap, CS43130_ASP_CH_2_SZ_EN,
3364 + CS43130_CH_BITSIZE_MASK, bw_map->ch_bit);
3365 + regmap_update_bits(regmap, CS43130_SP_BITSIZE,
3366 + CS43130_ASP_BITSIZE_MASK, bw_map->sp_bit);
3368 + case CS43130_XSP_DOP_DAI:
3369 + regmap_update_bits(regmap, CS43130_XSP_CH_1_SZ_EN,
3370 + CS43130_CH_BITSIZE_MASK, bw_map->ch_bit);
3371 + regmap_update_bits(regmap, CS43130_XSP_CH_2_SZ_EN,
3372 + CS43130_CH_BITSIZE_MASK, bw_map->ch_bit);
3373 + regmap_update_bits(regmap, CS43130_SP_BITSIZE,
3374 + CS43130_XSP_BITSIZE_MASK, bw_map->sp_bit <<
3375 + CS43130_XSP_BITSIZE_SHIFT);
3383 +static const struct cs43130_rate_map cs43130_rate_table[] = {
3384 + {32000, CS43130_ASP_SPRATE_32K},
3385 + {44100, CS43130_ASP_SPRATE_44_1K},
3386 + {48000, CS43130_ASP_SPRATE_48K},
3387 + {88200, CS43130_ASP_SPRATE_88_2K},
3388 + {96000, CS43130_ASP_SPRATE_96K},
3389 + {176400, CS43130_ASP_SPRATE_176_4K},
3390 + {192000, CS43130_ASP_SPRATE_192K},
3391 + {352800, CS43130_ASP_SPRATE_352_8K},
3392 + {384000, CS43130_ASP_SPRATE_384K},
3395 +static const struct cs43130_rate_map *cs43130_get_rate_table(int fs)
3399 + for (i = 0; i < ARRAY_SIZE(cs43130_rate_table); i++) {
3400 + if (cs43130_rate_table[i].fs == fs)
3401 + return &cs43130_rate_table[i];
3407 +static const struct cs43130_clk_gen *cs43130_get_clk_gen(int mclk_int, int fs,
3408 + const struct cs43130_clk_gen *clk_gen_table, int len_clk_gen_table)
3412 + for (i = 0; i < len_clk_gen_table; i++) {
3413 + if (clk_gen_table[i].mclk_int == mclk_int &&
3414 + clk_gen_table[i].fs == fs)
3415 + return &clk_gen_table[i];
3420 +static int cs43130_set_sp_fmt(int dai_id, unsigned int bitwidth_sclk,
3421 + struct snd_pcm_hw_params *params,
3422 + struct cs43130_priv *cs43130)
3435 + const struct cs43130_clk_gen *clk_gen;
3437 + switch (cs43130->dais[dai_id].dai_format) {
3438 + case SND_SOC_DAIFMT_I2S:
3439 + hi_size = bitwidth_sclk;
3443 + case SND_SOC_DAIFMT_LEFT_J:
3444 + hi_size = bitwidth_sclk;
3448 + case SND_SOC_DAIFMT_DSP_A:
3453 + case SND_SOC_DAIFMT_DSP_B:
3461 + switch (cs43130->dais[dai_id].dai_mode) {
3462 + case SND_SOC_DAIFMT_CBS_CFS:
3465 + case SND_SOC_DAIFMT_CBM_CFM:
3472 + frm_size = bitwidth_sclk * params_channels(params);
3476 + loc_ch2 = bitwidth_sclk * (params_channels(params) - 1);
3478 + frm_data = frm_delay & CS43130_SP_FSD_MASK;
3479 + frm_data |= (frm_phase << CS43130_SP_STP_SHIFT) & CS43130_SP_STP_MASK;
3481 + clk_data = lrck_edge & CS43130_SP_LCPOL_IN_MASK;
3482 + clk_data |= (lrck_edge << CS43130_SP_LCPOL_OUT_SHIFT) &
3483 + CS43130_SP_LCPOL_OUT_MASK;
3484 + clk_data |= (sclk_edge << CS43130_SP_SCPOL_IN_SHIFT) &
3485 + CS43130_SP_SCPOL_IN_MASK;
3486 + clk_data |= (sclk_edge << CS43130_SP_SCPOL_OUT_SHIFT) &
3487 + CS43130_SP_SCPOL_OUT_MASK;
3488 + clk_data |= (dai_mode_val << CS43130_SP_MODE_SHIFT) &
3489 + CS43130_SP_MODE_MASK;
3491 + case CS43130_ASP_PCM_DAI:
3492 + case CS43130_ASP_DOP_DAI:
3493 + regmap_update_bits(cs43130->regmap, CS43130_ASP_LRCK_PERIOD_1,
3494 + CS43130_SP_LCPR_DATA_MASK, (frm_size - 1) >>
3495 + CS43130_SP_LCPR_LSB_DATA_SHIFT);
3496 + regmap_update_bits(cs43130->regmap, CS43130_ASP_LRCK_PERIOD_2,
3497 + CS43130_SP_LCPR_DATA_MASK, (frm_size - 1) >>
3498 + CS43130_SP_LCPR_MSB_DATA_SHIFT);
3499 + regmap_update_bits(cs43130->regmap, CS43130_ASP_LRCK_HI_TIME_1,
3500 + CS43130_SP_LCHI_DATA_MASK, (hi_size - 1) >>
3501 + CS43130_SP_LCHI_LSB_DATA_SHIFT);
3502 + regmap_update_bits(cs43130->regmap, CS43130_ASP_LRCK_HI_TIME_2,
3503 + CS43130_SP_LCHI_DATA_MASK, (hi_size - 1) >>
3504 + CS43130_SP_LCHI_MSB_DATA_SHIFT);
3505 + regmap_write(cs43130->regmap, CS43130_ASP_FRAME_CONF, frm_data);
3506 + regmap_write(cs43130->regmap, CS43130_ASP_CH_1_LOC, loc_ch1);
3507 + regmap_write(cs43130->regmap, CS43130_ASP_CH_2_LOC, loc_ch2);
3508 + regmap_update_bits(cs43130->regmap, CS43130_ASP_CH_1_SZ_EN,
3509 + CS43130_CH_EN_MASK, 1 << CS43130_CH_EN_SHIFT);
3510 + regmap_update_bits(cs43130->regmap, CS43130_ASP_CH_2_SZ_EN,
3511 + CS43130_CH_EN_MASK, 1 << CS43130_CH_EN_SHIFT);
3512 + regmap_write(cs43130->regmap, CS43130_ASP_CLOCK_CONF, clk_data);
3514 + case CS43130_XSP_DOP_DAI:
3515 + regmap_update_bits(cs43130->regmap, CS43130_XSP_LRCK_PERIOD_1,
3516 + CS43130_SP_LCPR_DATA_MASK, (frm_size - 1) >>
3517 + CS43130_SP_LCPR_LSB_DATA_SHIFT);
3518 + regmap_update_bits(cs43130->regmap, CS43130_XSP_LRCK_PERIOD_2,
3519 + CS43130_SP_LCPR_DATA_MASK, (frm_size - 1) >>
3520 + CS43130_SP_LCPR_MSB_DATA_SHIFT);
3521 + regmap_update_bits(cs43130->regmap, CS43130_XSP_LRCK_HI_TIME_1,
3522 + CS43130_SP_LCHI_DATA_MASK, (hi_size - 1) >>
3523 + CS43130_SP_LCHI_LSB_DATA_SHIFT);
3524 + regmap_update_bits(cs43130->regmap, CS43130_XSP_LRCK_HI_TIME_2,
3525 + CS43130_SP_LCHI_DATA_MASK, (hi_size - 1) >>
3526 + CS43130_SP_LCHI_MSB_DATA_SHIFT);
3527 + regmap_write(cs43130->regmap, CS43130_XSP_FRAME_CONF, frm_data);
3528 + regmap_write(cs43130->regmap, CS43130_XSP_CH_1_LOC, loc_ch1);
3529 + regmap_write(cs43130->regmap, CS43130_XSP_CH_2_LOC, loc_ch2);
3530 + regmap_update_bits(cs43130->regmap, CS43130_XSP_CH_1_SZ_EN,
3531 + CS43130_CH_EN_MASK, 1 << CS43130_CH_EN_SHIFT);
3532 + regmap_update_bits(cs43130->regmap, CS43130_XSP_CH_2_SZ_EN,
3533 + CS43130_CH_EN_MASK, 1 << CS43130_CH_EN_SHIFT);
3534 + regmap_write(cs43130->regmap, CS43130_XSP_CLOCK_CONF, clk_data);
3539 + switch (frm_size) {
3541 + clk_gen = cs43130_get_clk_gen(cs43130->mclk_int,
3542 + params_rate(params),
3543 + cs43130_16_clk_gen,
3544 + ARRAY_SIZE(cs43130_16_clk_gen));
3547 + clk_gen = cs43130_get_clk_gen(cs43130->mclk_int,
3548 + params_rate(params),
3549 + cs43130_32_clk_gen,
3550 + ARRAY_SIZE(cs43130_32_clk_gen));
3553 + clk_gen = cs43130_get_clk_gen(cs43130->mclk_int,
3554 + params_rate(params),
3555 + cs43130_48_clk_gen,
3556 + ARRAY_SIZE(cs43130_48_clk_gen));
3559 + clk_gen = cs43130_get_clk_gen(cs43130->mclk_int,
3560 + params_rate(params),
3561 + cs43130_64_clk_gen,
3562 + ARRAY_SIZE(cs43130_64_clk_gen));
3570 + case CS43130_ASP_PCM_DAI:
3571 + case CS43130_ASP_DOP_DAI:
3572 + regmap_write(cs43130->regmap, CS43130_ASP_DEN_1,
3573 + (clk_gen->v.denominator & CS43130_SP_M_LSB_DATA_MASK) >>
3574 + CS43130_SP_M_LSB_DATA_SHIFT);
3575 + regmap_write(cs43130->regmap, CS43130_ASP_DEN_2,
3576 + (clk_gen->v.denominator & CS43130_SP_M_MSB_DATA_MASK) >>
3577 + CS43130_SP_M_MSB_DATA_SHIFT);
3578 + regmap_write(cs43130->regmap, CS43130_ASP_NUM_1,
3579 + (clk_gen->v.numerator & CS43130_SP_N_LSB_DATA_MASK) >>
3580 + CS43130_SP_N_LSB_DATA_SHIFT);
3581 + regmap_write(cs43130->regmap, CS43130_ASP_NUM_2,
3582 + (clk_gen->v.numerator & CS43130_SP_N_MSB_DATA_MASK) >>
3583 + CS43130_SP_N_MSB_DATA_SHIFT);
3585 + case CS43130_XSP_DOP_DAI:
3586 + regmap_write(cs43130->regmap, CS43130_XSP_DEN_1,
3587 + (clk_gen->v.denominator & CS43130_SP_M_LSB_DATA_MASK) >>
3588 + CS43130_SP_M_LSB_DATA_SHIFT);
3589 + regmap_write(cs43130->regmap, CS43130_XSP_DEN_2,
3590 + (clk_gen->v.denominator & CS43130_SP_M_MSB_DATA_MASK) >>
3591 + CS43130_SP_M_MSB_DATA_SHIFT);
3592 + regmap_write(cs43130->regmap, CS43130_XSP_NUM_1,
3593 + (clk_gen->v.numerator & CS43130_SP_N_LSB_DATA_MASK) >>
3594 + CS43130_SP_N_LSB_DATA_SHIFT);
3595 + regmap_write(cs43130->regmap, CS43130_XSP_NUM_2,
3596 + (clk_gen->v.numerator & CS43130_SP_N_MSB_DATA_MASK) >>
3597 + CS43130_SP_N_MSB_DATA_SHIFT);
3605 +static int cs43130_hw_params(struct snd_pcm_substream *substream,
3606 + struct snd_pcm_hw_params *params,
3607 + struct snd_soc_dai *dai)
3609 + struct snd_soc_component *component = dai->component;
3610 + struct cs43130_priv *cs43130 =
3611 + snd_soc_component_get_drvdata(component);
3612 + const struct cs43130_rate_map *rate_map;
3613 + unsigned int sclk = cs43130->dais[dai->id].sclk;
3614 + unsigned int bitwidth_sclk;
3615 + unsigned int bitwidth_dai = (unsigned int)(params_width(params));
3616 + unsigned int dop_rate = (unsigned int)(params_rate(params));
3617 + unsigned int required_clk, ret;
3620 + cs43130->pll_bypass = true;
3621 + cs43130_pcm_pdn(component);
3622 + mutex_lock(&cs43130->clk_mutex);
3623 + if (!cs43130->clk_req) {
3624 + /* no DAI is currently using clk */
3625 + if (!(CS43130_MCLK_22M % params_rate(params))) {
3626 + required_clk = CS43130_MCLK_22M;
3627 + cs43130->mclk_int = CS43130_MCLK_22M;
3628 + gpiod_set_value_cansleep(snd_allo_clk44gpio, 1);
3629 + gpiod_set_value_cansleep(snd_allo_clk48gpio, 0);
3630 + usleep_range(13500, 14000);
3632 + required_clk = CS43130_MCLK_24M;
3633 + cs43130->mclk_int = CS43130_MCLK_24M;
3634 + gpiod_set_value_cansleep(snd_allo_clk48gpio, 1);
3635 + gpiod_set_value_cansleep(snd_allo_clk44gpio, 0);
3636 + usleep_range(13500, 14000);
3638 + if (cs43130->pll_bypass)
3639 + cs43130_change_clksrc(component, CS43130_MCLK_SRC_EXT);
3641 + cs43130_change_clksrc(component, CS43130_MCLK_SRC_PLL);
3644 + cs43130->clk_req++;
3645 + mutex_unlock(&cs43130->clk_mutex);
3647 + switch (dai->id) {
3648 + case CS43130_ASP_DOP_DAI:
3649 + case CS43130_XSP_DOP_DAI:
3650 + /* DoP bitwidth is always 24-bit */
3651 + bitwidth_dai = 24;
3652 + sclk = params_rate(params) * bitwidth_dai *
3653 + params_channels(params);
3655 + switch (params_rate(params)) {
3663 + dev_err(component->dev, "Rate(%u) not supported\n",
3664 + params_rate(params));
3668 + regmap_update_bits(cs43130->regmap, CS43130_DSD_PATH_CTL_2,
3669 + CS43130_DSD_SPEED_MASK,
3670 + dsd_speed << CS43130_DSD_SPEED_SHIFT);
3672 + case CS43130_ASP_PCM_DAI:
3673 + rate_map = cs43130_get_rate_table(params_rate(params));
3677 + regmap_write(cs43130->regmap, CS43130_SP_SRATE, rate_map->val);
3678 + if ((dop_rate == 176400) && (bitwidth_dai == 24)) {
3680 + regmap_update_bits(cs43130->regmap,
3681 + CS43130_DSD_PATH_CTL_2,
3682 + CS43130_DSD_SPEED_MASK,
3683 + dsd_speed << CS43130_DSD_SPEED_SHIFT);
3684 + regmap_update_bits(cs43130->regmap,
3685 + CS43130_DSD_PATH_CTL_2,
3686 + CS43130_DSD_SRC_MASK,
3687 + CS43130_DSD_SRC_ASP <<
3688 + CS43130_DSD_SRC_SHIFT);
3689 + regmap_update_bits(cs43130->regmap,
3690 + CS43130_DSD_PATH_CTL_2,
3691 + CS43130_DSD_EN_MASK, 0x01 <<
3692 + CS43130_DSD_EN_SHIFT);
3696 + dev_err(component->dev, "Invalid DAI (%d)\n", dai->id);
3700 + switch (dai->id) {
3701 + case CS43130_ASP_DOP_DAI:
3702 + regmap_update_bits(cs43130->regmap, CS43130_DSD_PATH_CTL_2,
3703 + CS43130_DSD_SRC_MASK, CS43130_DSD_SRC_ASP <<
3704 + CS43130_DSD_SRC_SHIFT);
3705 + regmap_update_bits(cs43130->regmap, CS43130_DSD_PATH_CTL_2,
3706 + CS43130_DSD_EN_MASK, 0x01 <<
3707 + CS43130_DSD_EN_SHIFT);
3709 + case CS43130_XSP_DOP_DAI:
3710 + regmap_update_bits(cs43130->regmap, CS43130_DSD_PATH_CTL_2,
3711 + CS43130_DSD_SRC_MASK, CS43130_DSD_SRC_XSP <<
3712 + CS43130_DSD_SRC_SHIFT);
3715 + if (!sclk && cs43130->dais[dai->id].dai_mode ==
3716 + SND_SOC_DAIFMT_CBM_CFM) {
3717 + /* Calculate SCLK in master mode if unassigned */
3718 + sclk = params_rate(params) * bitwidth_dai *
3719 + params_channels(params);
3722 + /* at this point, SCLK must be set */
3723 + dev_err(component->dev, "SCLK freq is not set\n");
3727 + bitwidth_sclk = (sclk / params_rate(params)) / params_channels(params);
3728 + if (bitwidth_sclk < bitwidth_dai) {
3729 + dev_err(component->dev, "Format not supported: SCLK freq is too low\n");
3733 + dev_dbg(component->dev,
3734 + "sclk = %u, fs = %d, bitwidth_dai = %u\n",
3735 + sclk, params_rate(params), bitwidth_dai);
3737 + dev_dbg(component->dev,
3738 + "bitwidth_sclk = %u, num_ch = %u\n",
3739 + bitwidth_sclk, params_channels(params));
3741 + cs43130_set_bitwidth(dai->id, bitwidth_dai, cs43130->regmap);
3742 + cs43130_set_sp_fmt(dai->id, bitwidth_sclk, params, cs43130);
3743 + ret = cs43130_pwr_up_asp_dac(component);
3747 +static int cs43130_hw_free(struct snd_pcm_substream *substream,
3748 + struct snd_soc_dai *dai)
3750 + struct snd_soc_component *component = dai->component;
3751 + struct cs43130_priv *cs43130 =
3752 + snd_soc_component_get_drvdata(component);
3754 + mutex_lock(&cs43130->clk_mutex);
3755 + cs43130->clk_req--;
3756 + if (!cs43130->clk_req) {
3757 + /* no DAI is currently using clk */
3758 + cs43130_change_clksrc(component, CS43130_MCLK_SRC_RCO);
3759 + cs43130_pcm_pdn(component);
3761 + mutex_unlock(&cs43130->clk_mutex);
3766 +static const unsigned int cs43130_asp_src_rates[] = {
3767 + 32000, 44100, 48000, 88200, 96000, 176400, 192000
3770 +static const struct snd_pcm_hw_constraint_list cs43130_asp_constraints = {
3771 + .count = ARRAY_SIZE(cs43130_asp_src_rates),
3772 + .list = cs43130_asp_src_rates,
3775 +static int cs43130_pcm_startup(struct snd_pcm_substream *substream,
3776 + struct snd_soc_dai *dai)
3778 + return snd_pcm_hw_constraint_list(substream->runtime, 0,
3779 + SNDRV_PCM_HW_PARAM_RATE,
3780 + &cs43130_asp_constraints);
3783 +static int cs43130_pcm_set_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
3785 + struct snd_soc_component *component = codec_dai->component;
3786 + struct cs43130_priv *cs43130 =
3787 + snd_soc_component_get_drvdata(component);
3789 + switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
3790 + case SND_SOC_DAIFMT_CBS_CFS:
3791 + cs43130->dais[codec_dai->id].dai_mode = SND_SOC_DAIFMT_CBS_CFS;
3793 + case SND_SOC_DAIFMT_CBM_CFM:
3794 + cs43130->dais[codec_dai->id].dai_mode = SND_SOC_DAIFMT_CBM_CFM;
3797 + dev_err(component->dev, "unsupported mode\n");
3801 + switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
3802 + case SND_SOC_DAIFMT_I2S:
3803 + cs43130->dais[codec_dai->id].dai_format = SND_SOC_DAIFMT_I2S;
3805 + case SND_SOC_DAIFMT_LEFT_J:
3806 + cs43130->dais[codec_dai->id].dai_format = SND_SOC_DAIFMT_LEFT_J;
3809 + dev_err(component->dev,
3810 + "unsupported audio format\n");
3814 + dev_dbg(component->dev, "dai_id = %d, dai_mode = %u, dai_format = %u\n",
3816 + cs43130->dais[codec_dai->id].dai_mode,
3817 + cs43130->dais[codec_dai->id].dai_format);
3822 +static int cs43130_set_sysclk(struct snd_soc_dai *codec_dai,
3823 + int clk_id, unsigned int freq, int dir)
3825 + struct snd_soc_component *component = codec_dai->component;
3826 + struct cs43130_priv *cs43130 =
3827 + snd_soc_component_get_drvdata(component);
3829 + cs43130->dais[codec_dai->id].sclk = freq;
3830 + dev_dbg(component->dev, "dai_id = %d, sclk = %u\n", codec_dai->id,
3831 + cs43130->dais[codec_dai->id].sclk);
3836 +static int cs43130_component_set_sysclk(struct snd_soc_component *component,
3837 + int clk_id, int source,
3838 + unsigned int freq, int dir)
3840 + struct cs43130_priv *cs43130 =
3841 + snd_soc_component_get_drvdata(component);
3843 + dev_dbg(component->dev, "clk_id = %d, source = %d, freq = %d, dir = %d\n",
3844 + clk_id, source, freq, dir);
3847 + case CS43130_MCLK_22M:
3848 + case CS43130_MCLK_24M:
3849 + cs43130->mclk = freq;
3852 + dev_err(component->dev, "Invalid MCLK INT freq: %u\n", freq);
3856 + if (source == CS43130_MCLK_SRC_EXT) {
3857 + cs43130->pll_bypass = true;
3859 + dev_err(component->dev, "Invalid MCLK source\n");
3865 +static u16 const cs43130_ac_freq[CS43130_AC_FREQ] = {
3877 +static const struct snd_soc_dai_ops cs43130_dai_ops = {
3878 + .startup = cs43130_pcm_startup,
3879 + .hw_params = cs43130_hw_params,
3880 + .hw_free = cs43130_hw_free,
3881 + .set_sysclk = cs43130_set_sysclk,
3882 + .set_fmt = cs43130_pcm_set_fmt,
3885 +static struct snd_soc_dai_driver cs43130_codec_dai = {
3886 + .name = "allo-cs43130",
3888 + .stream_name = "Playback",
3889 + .channels_min = 2,
3890 + .channels_max = 2,
3891 + .rates = SNDRV_PCM_RATE_CONTINUOUS,
3892 + .rate_min = 44100,
3893 + .rate_max = 192000,
3894 + .formats = SNDRV_PCM_FMTBIT_S16_LE |
3895 + SNDRV_PCM_FMTBIT_S24_LE |
3896 + SNDRV_PCM_FMTBIT_S32_LE
3899 + .ops = &cs43130_dai_ops,
3902 +static struct snd_soc_component_driver cs43130_component_driver = {
3903 + .idle_bias_on = true,
3904 + .controls = cs43130_controls,
3905 + .num_controls = ARRAY_SIZE(cs43130_controls),
3906 + .set_sysclk = cs43130_component_set_sysclk,
3907 + .idle_bias_on = 1,
3908 + .use_pmdown_time = 1,
3912 +static const struct regmap_config cs43130_regmap = {
3917 + .max_register = CS43130_LASTREG,
3918 + .reg_defaults = cs43130_reg_defaults,
3919 + .num_reg_defaults = ARRAY_SIZE(cs43130_reg_defaults),
3920 + .readable_reg = cs43130_readable_register,
3921 + .precious_reg = cs43130_precious_register,
3922 + .volatile_reg = cs43130_volatile_register,
3923 + .cache_type = REGCACHE_RBTREE,
3924 + /* needed for regcache_sync */
3925 + .use_single_read = true,
3926 + .use_single_write = true,
3929 +static u16 const cs43130_dc_threshold[CS43130_DC_THRESHOLD] = {
3934 +static int cs43130_handle_device_data(struct i2c_client *i2c_client,
3935 + struct cs43130_priv *cs43130)
3937 + struct device_node *np = i2c_client->dev.of_node;
3941 + if (of_property_read_u32(np, "cirrus,xtal-ibias", &val) < 0) {
3942 + /* Crystal is unused. System clock is used for external MCLK */
3943 + cs43130->xtal_ibias = CS43130_XTAL_UNUSED;
3949 + cs43130->xtal_ibias = CS43130_XTAL_IBIAS_7_5UA;
3952 + cs43130->xtal_ibias = CS43130_XTAL_IBIAS_12_5UA;
3955 + cs43130->xtal_ibias = CS43130_XTAL_IBIAS_15UA;
3958 + dev_err(&i2c_client->dev,
3959 + "Invalid cirrus,xtal-ibias value: %d\n", val);
3963 + cs43130->dc_meas = of_property_read_bool(np, "cirrus,dc-measure");
3964 + cs43130->ac_meas = of_property_read_bool(np, "cirrus,ac-measure");
3966 + if (of_property_read_u16_array(np, "cirrus,ac-freq", cs43130->ac_freq,
3967 + CS43130_AC_FREQ) < 0) {
3968 + for (i = 0; i < CS43130_AC_FREQ; i++)
3969 + cs43130->ac_freq[i] = cs43130_ac_freq[i];
3972 + if (of_property_read_u16_array(np, "cirrus,dc-threshold",
3973 + cs43130->dc_threshold,
3974 + CS43130_DC_THRESHOLD) < 0) {
3975 + for (i = 0; i < CS43130_DC_THRESHOLD; i++)
3976 + cs43130->dc_threshold[i] = cs43130_dc_threshold[i];
3983 +static int allo_cs43130_component_probe(struct i2c_client *i2c)
3985 + struct regmap *regmap;
3986 + struct regmap_config config = cs43130_regmap;
3987 + struct device *dev = &i2c->dev;
3988 + struct cs43130_priv *cs43130;
3989 + unsigned int devid = 0;
3993 + regmap = devm_regmap_init_i2c(i2c, &config);
3994 + if (IS_ERR(regmap))
3995 + return PTR_ERR(regmap);
3997 + cs43130 = devm_kzalloc(dev, sizeof(struct cs43130_priv),
4002 + dev_set_drvdata(dev, cs43130);
4003 + cs43130->regmap = regmap;
4005 + if (i2c->dev.of_node) {
4006 + ret = cs43130_handle_device_data(i2c, cs43130);
4010 + usleep_range(2000, 2050);
4012 + ret = regmap_read(cs43130->regmap, CS43130_DEVID_AB, ®);
4013 + devid = (reg & 0xFF) << 12;
4014 + ret = regmap_read(cs43130->regmap, CS43130_DEVID_CD, ®);
4015 + devid |= (reg & 0xFF) << 4;
4016 + ret = regmap_read(cs43130->regmap, CS43130_DEVID_E, ®);
4017 + devid |= (reg & 0xF0) >> 4;
4018 + if (devid != CS43198_CHIP_ID) {
4019 + dev_err(dev, "Failed to read Chip or wrong Chip id: %d\n", ret);
4023 + cs43130->mclk_int_src = CS43130_MCLK_SRC_RCO;
4026 + ret = snd_soc_register_component(dev, &cs43130_component_driver,
4027 + &cs43130_codec_dai, 1);
4029 + dev_err(dev, "failed to register codec: %d\n", ret);
4032 + regmap_update_bits(cs43130->regmap, CS43130_PAD_INT_CFG,
4033 + CS43130_ASP_3ST_MASK, 0);
4034 + regmap_update_bits(cs43130->regmap, CS43130_PAD_INT_CFG,
4035 + CS43130_XSP_3ST_MASK, 1);
4036 + regmap_update_bits(cs43130->regmap, CS43130_PWDN_CTL,
4037 + CS43130_PDN_HP_MASK, 1 << CS43130_PDN_HP_SHIFT);
4039 + regmap_write(cs43130->regmap, CS43130_CLASS_H_CTL, 0x06);
4040 + snd_allo_clk44gpio = devm_gpiod_get(dev, "clock44", GPIOD_OUT_HIGH);
4041 + if (IS_ERR(snd_allo_clk44gpio))
4042 + dev_err(dev, "devm_gpiod_get() failed\n");
4044 + snd_allo_clk48gpio = devm_gpiod_get(dev, "clock48", GPIOD_OUT_LOW);
4045 + if (IS_ERR(snd_allo_clk48gpio))
4046 + dev_err(dev, "devm_gpiod_get() failed\n");
4051 +static void allo_cs43130_component_remove(struct i2c_client *i2c)
4053 + snd_soc_unregister_component(&i2c->dev);
4056 +static const struct i2c_device_id allo_cs43130_component_id[] = {
4057 + { "allo-cs43198", },
4060 +MODULE_DEVICE_TABLE(i2c, allo_cs43130_component_id);
4062 +static const struct of_device_id allo_cs43130_codec_of_match[] = {
4063 + { .compatible = "allo,allo-cs43198", },
4066 +MODULE_DEVICE_TABLE(of, allo_cs43130_codec_of_match);
4068 +static struct i2c_driver allo_cs43130_component_driver = {
4069 + .probe = allo_cs43130_component_probe,
4070 + .remove = allo_cs43130_component_remove,
4071 + .id_table = allo_cs43130_component_id,
4073 + .name = "allo-cs43198",
4074 + .of_match_table = allo_cs43130_codec_of_match,
4078 +module_i2c_driver(allo_cs43130_component_driver);
4080 +MODULE_DESCRIPTION("ASoC Allo Boss2 Codec Driver");
4081 +MODULE_AUTHOR("Sudeepkumar <sudeepkumar@cem-solutions.net>");
4082 +MODULE_LICENSE("GPL v2");
4084 +++ b/sound/soc/bcm/allo-katana-codec.c
4087 + * Driver for the ALLO KATANA CODEC
4089 + * Author: Jaikumar <jaikumar@cem-solutions.net>
4092 + * This program is free software; you can redistribute it and/or
4093 + * modify it under the terms of the GNU General Public License
4094 + * version 2 as published by the Free Software Foundation.
4096 + * This program is distributed in the hope that it will be useful, but
4097 + * WITHOUT ANY WARRANTY; without even the implied warranty of
4098 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4099 + * General Public License for more details.
4103 +#include <linux/init.h>
4104 +#include <linux/module.h>
4105 +#include <linux/clk.h>
4106 +#include <linux/kernel.h>
4107 +#include <linux/regmap.h>
4108 +#include <linux/regulator/consumer.h>
4109 +#include <linux/gcd.h>
4110 +#include <sound/soc.h>
4111 +#include <sound/soc-dapm.h>
4112 +#include <sound/pcm_params.h>
4113 +#include <sound/tlv.h>
4114 +#include <linux/i2c.h>
4117 +#define KATANA_CODEC_CHIP_ID 0x30
4118 +#define KATANA_CODEC_VIRT_BASE 0x100
4119 +#define KATANA_CODEC_PAGE 0
4121 +#define KATANA_CODEC_CHIP_ID_REG (KATANA_CODEC_VIRT_BASE + 0)
4122 +#define KATANA_CODEC_RESET (KATANA_CODEC_VIRT_BASE + 1)
4123 +#define KATANA_CODEC_VOLUME_1 (KATANA_CODEC_VIRT_BASE + 2)
4124 +#define KATANA_CODEC_VOLUME_2 (KATANA_CODEC_VIRT_BASE + 3)
4125 +#define KATANA_CODEC_MUTE (KATANA_CODEC_VIRT_BASE + 4)
4126 +#define KATANA_CODEC_DSP_PROGRAM (KATANA_CODEC_VIRT_BASE + 5)
4127 +#define KATANA_CODEC_DEEMPHASIS (KATANA_CODEC_VIRT_BASE + 6)
4128 +#define KATANA_CODEC_DOP (KATANA_CODEC_VIRT_BASE + 7)
4129 +#define KATANA_CODEC_FORMAT (KATANA_CODEC_VIRT_BASE + 8)
4130 +#define KATANA_CODEC_COMMAND (KATANA_CODEC_VIRT_BASE + 9)
4131 +#define KATANA_CODEC_MUTE_STREAM (KATANA_CODEC_VIRT_BASE + 10)
4133 +#define KATANA_CODEC_MAX_REGISTER (KATANA_CODEC_VIRT_BASE + 10)
4135 +#define KATANA_CODEC_FMT 0xff
4136 +#define KATANA_CODEC_CHAN_MONO 0x00
4137 +#define KATANA_CODEC_CHAN_STEREO 0x80
4138 +#define KATANA_CODEC_ALEN_16 0x10
4139 +#define KATANA_CODEC_ALEN_24 0x20
4140 +#define KATANA_CODEC_ALEN_32 0x30
4141 +#define KATANA_CODEC_RATE_11025 0x01
4142 +#define KATANA_CODEC_RATE_22050 0x02
4143 +#define KATANA_CODEC_RATE_32000 0x03
4144 +#define KATANA_CODEC_RATE_44100 0x04
4145 +#define KATANA_CODEC_RATE_48000 0x05
4146 +#define KATANA_CODEC_RATE_88200 0x06
4147 +#define KATANA_CODEC_RATE_96000 0x07
4148 +#define KATANA_CODEC_RATE_176400 0x08
4149 +#define KATANA_CODEC_RATE_192000 0x09
4150 +#define KATANA_CODEC_RATE_352800 0x0a
4151 +#define KATANA_CODEC_RATE_384000 0x0b
4154 +struct katana_codec_priv {
4155 + struct regmap *regmap;
4159 +static const struct reg_default katana_codec_reg_defaults[] = {
4160 + { KATANA_CODEC_RESET, 0x00 },
4161 + { KATANA_CODEC_VOLUME_1, 0xF0 },
4162 + { KATANA_CODEC_VOLUME_2, 0xF0 },
4163 + { KATANA_CODEC_MUTE, 0x00 },
4164 + { KATANA_CODEC_DSP_PROGRAM, 0x04 },
4165 + { KATANA_CODEC_DEEMPHASIS, 0x00 },
4166 + { KATANA_CODEC_DOP, 0x00 },
4167 + { KATANA_CODEC_FORMAT, 0xb4 },
4170 +static const char * const katana_codec_dsp_program_texts[] = {
4171 + "Linear Phase Fast Roll-off Filter",
4172 + "Linear Phase Slow Roll-off Filter",
4173 + "Minimum Phase Fast Roll-off Filter",
4174 + "Minimum Phase Slow Roll-off Filter",
4175 + "Apodizing Fast Roll-off Filter",
4176 + "Corrected Minimum Phase Fast Roll-off Filter",
4177 + "Brick Wall Filter",
4180 +static const unsigned int katana_codec_dsp_program_values[] = {
4190 +static SOC_VALUE_ENUM_SINGLE_DECL(katana_codec_dsp_program,
4191 + KATANA_CODEC_DSP_PROGRAM, 0, 0x07,
4192 + katana_codec_dsp_program_texts,
4193 + katana_codec_dsp_program_values);
4195 +static const char * const katana_codec_deemphasis_texts[] = {
4202 +static const unsigned int katana_codec_deemphasis_values[] = {
4209 +static SOC_VALUE_ENUM_SINGLE_DECL(katana_codec_deemphasis,
4210 + KATANA_CODEC_DEEMPHASIS, 0, 0x03,
4211 + katana_codec_deemphasis_texts,
4212 + katana_codec_deemphasis_values);
4214 +static const SNDRV_CTL_TLVD_DECLARE_DB_MINMAX(master_tlv, -12750, 0);
4216 +static const struct snd_kcontrol_new katana_codec_controls[] = {
4217 + SOC_DOUBLE_R_TLV("Master Playback Volume", KATANA_CODEC_VOLUME_1,
4218 + KATANA_CODEC_VOLUME_2, 0, 255, 1, master_tlv),
4219 + SOC_DOUBLE("Master Playback Switch", KATANA_CODEC_MUTE, 0, 0, 1, 1),
4220 + SOC_ENUM("DSP Program Route", katana_codec_dsp_program),
4221 + SOC_ENUM("Deemphasis Route", katana_codec_deemphasis),
4222 + SOC_SINGLE("DoP Playback Switch", KATANA_CODEC_DOP, 0, 1, 1)
4225 +static bool katana_codec_readable_register(struct device *dev,
4229 + case KATANA_CODEC_CHIP_ID_REG:
4232 + return reg < 0xff;
4236 +static int katana_codec_hw_params(struct snd_pcm_substream *substream,
4237 + struct snd_pcm_hw_params *params,
4238 + struct snd_soc_dai *dai)
4240 + struct snd_soc_component *component = dai->component;
4241 + struct katana_codec_priv *katana_codec =
4242 + snd_soc_component_get_drvdata(component);
4246 + dev_dbg(component->card->dev, "hw_params %u Hz, %u channels, %u bits\n",
4247 + params_rate(params),
4248 + params_channels(params),
4249 + params_width(params));
4251 + switch (katana_codec->fmt & SND_SOC_DAIFMT_MASTER_MASK) {
4252 + case SND_SOC_DAIFMT_CBM_CFM: // master
4253 + if (params_channels(params) == 2)
4254 + fmt = KATANA_CODEC_CHAN_STEREO;
4256 + fmt = KATANA_CODEC_CHAN_MONO;
4258 + switch (params_width(params)) {
4260 + fmt |= KATANA_CODEC_ALEN_16;
4263 + fmt |= KATANA_CODEC_ALEN_24;
4266 + fmt |= KATANA_CODEC_ALEN_32;
4269 + dev_err(component->card->dev, "Bad frame size: %d\n",
4270 + params_width(params));
4274 + switch (params_rate(params)) {
4276 + fmt |= KATANA_CODEC_RATE_44100;
4279 + fmt |= KATANA_CODEC_RATE_48000;
4282 + fmt |= KATANA_CODEC_RATE_88200;
4285 + fmt |= KATANA_CODEC_RATE_96000;
4288 + fmt |= KATANA_CODEC_RATE_176400;
4291 + fmt |= KATANA_CODEC_RATE_192000;
4294 + fmt |= KATANA_CODEC_RATE_352800;
4297 + fmt |= KATANA_CODEC_RATE_384000;
4300 + dev_err(component->card->dev, "Bad sample rate: %d\n",
4301 + params_rate(params));
4305 + ret = regmap_write(katana_codec->regmap, KATANA_CODEC_FORMAT,
4308 + dev_err(component->card->dev, "Failed to set format: %d\n", ret);
4313 + case SND_SOC_DAIFMT_CBS_CFS:
4323 +static int katana_codec_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
4325 + struct snd_soc_component *component = dai->component;
4326 + struct katana_codec_priv *katana_codec =
4327 + snd_soc_component_get_drvdata(component);
4329 + katana_codec->fmt = fmt;
4334 +int katana_codec_dai_mute_stream(struct snd_soc_dai *dai, int mute,
4337 + struct snd_soc_component *component = dai->component;
4338 + struct katana_codec_priv *katana_codec =
4339 + snd_soc_component_get_drvdata(component);
4342 + ret = regmap_write(katana_codec->regmap, KATANA_CODEC_MUTE_STREAM,
4345 + dev_err(component->card->dev, "Failed to set mute: %d\n", ret);
4351 +static const struct snd_soc_dai_ops katana_codec_dai_ops = {
4352 + .mute_stream = katana_codec_dai_mute_stream,
4353 + .hw_params = katana_codec_hw_params,
4354 + .set_fmt = katana_codec_set_fmt,
4357 +static struct snd_soc_dai_driver katana_codec_dai = {
4358 + .name = "allo-katana-codec",
4360 + .stream_name = "Playback",
4361 + .channels_min = 2,
4362 + .channels_max = 2,
4363 + .rates = SNDRV_PCM_RATE_CONTINUOUS,
4364 + .rate_min = 44100,
4365 + .rate_max = 384000,
4366 + .formats = SNDRV_PCM_FMTBIT_S16_LE |
4367 + SNDRV_PCM_FMTBIT_S32_LE
4369 + .ops = &katana_codec_dai_ops,
4372 +static struct snd_soc_component_driver katana_codec_component_driver = {
4373 + .idle_bias_on = true,
4375 + .controls = katana_codec_controls,
4376 + .num_controls = ARRAY_SIZE(katana_codec_controls),
4379 +static const struct regmap_range_cfg katana_codec_range = {
4380 + .name = "Pages", .range_min = KATANA_CODEC_VIRT_BASE,
4381 + .range_max = KATANA_CODEC_MAX_REGISTER,
4382 + .selector_reg = KATANA_CODEC_PAGE,
4383 + .selector_mask = 0xff,
4384 + .window_start = 0, .window_len = 0x100,
4387 +const struct regmap_config katana_codec_regmap = {
4391 + .ranges = &katana_codec_range,
4394 + .max_register = KATANA_CODEC_MAX_REGISTER,
4395 + .readable_reg = katana_codec_readable_register,
4396 + .reg_defaults = katana_codec_reg_defaults,
4397 + .num_reg_defaults = ARRAY_SIZE(katana_codec_reg_defaults),
4398 + .cache_type = REGCACHE_RBTREE,
4401 +static int allo_katana_component_probe(struct i2c_client *i2c)
4403 + struct regmap *regmap;
4404 + struct regmap_config config = katana_codec_regmap;
4405 + struct device *dev = &i2c->dev;
4406 + struct katana_codec_priv *katana_codec;
4407 + unsigned int chip_id = 0;
4410 + regmap = devm_regmap_init_i2c(i2c, &config);
4411 + if (IS_ERR(regmap))
4412 + return PTR_ERR(regmap);
4414 + katana_codec = devm_kzalloc(dev, sizeof(struct katana_codec_priv),
4416 + if (!katana_codec)
4419 + dev_set_drvdata(dev, katana_codec);
4420 + katana_codec->regmap = regmap;
4422 + ret = regmap_read(regmap, KATANA_CODEC_CHIP_ID_REG, &chip_id);
4423 + if ((ret != 0) || (chip_id != KATANA_CODEC_CHIP_ID)) {
4424 + dev_err(dev, "Failed to read Chip or wrong Chip id: %d\n", ret);
4427 + regmap_update_bits(regmap, KATANA_CODEC_RESET, 0x01, 0x01);
4430 + ret = snd_soc_register_component(dev, &katana_codec_component_driver,
4431 + &katana_codec_dai, 1);
4433 + dev_err(dev, "failed to register codec: %d\n", ret);
4440 +static void allo_katana_component_remove(struct i2c_client *i2c)
4442 + snd_soc_unregister_component(&i2c->dev);
4445 +static const struct i2c_device_id allo_katana_component_id[] = {
4446 + { "allo-katana-codec", },
4449 +MODULE_DEVICE_TABLE(i2c, allo_katana_component_id);
4451 +static const struct of_device_id allo_katana_codec_of_match[] = {
4452 + { .compatible = "allo,allo-katana-codec", },
4455 +MODULE_DEVICE_TABLE(of, allo_katana_codec_of_match);
4457 +static struct i2c_driver allo_katana_component_driver = {
4458 + .probe = allo_katana_component_probe,
4459 + .remove = allo_katana_component_remove,
4460 + .id_table = allo_katana_component_id,
4462 + .name = "allo-katana-codec",
4463 + .of_match_table = allo_katana_codec_of_match,
4467 +module_i2c_driver(allo_katana_component_driver);
4469 +MODULE_DESCRIPTION("ASoC Allo Katana Codec Driver");
4470 +MODULE_AUTHOR("Jaikumar <jaikumar@cem-solutions.net>");
4471 +MODULE_LICENSE("GPL v2");
4473 +++ b/sound/soc/bcm/allo-piano-dac-plus.c
4476 + * ALSA ASoC Machine Driver for Allo Piano DAC Plus Subwoofer
4478 + * Author: Baswaraj K <jaikumar@cem-solutions.net>
4480 + * based on code by David Knell <david.knell@gmail.com)
4481 + * based on code by Daniel Matuschek <info@crazy-audio.com>
4482 + * based on code by Florian Meier <florian.meier@koalo.de>
4484 + * This program is free software; you can redistribute it and/or
4485 + * modify it under the terms of the GNU General Public License
4486 + * version 2 as published by the Free Software Foundation.
4488 + * This program is distributed in the hope that it will be useful, but
4489 + * WITHOUT ANY WARRANTY; without even the implied warranty of
4490 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4491 + * General Public License for more details.
4494 +#include <linux/module.h>
4495 +#include <linux/platform_device.h>
4496 +#include <linux/gpio/consumer.h>
4497 +#include <sound/core.h>
4498 +#include <sound/pcm.h>
4499 +#include <sound/pcm_params.h>
4500 +#include <sound/soc.h>
4501 +#include <linux/firmware.h>
4502 +#include <linux/delay.h>
4503 +#include <sound/tlv.h>
4504 +#include "../codecs/pcm512x.h"
4506 +#define P_DAC_LEFT_MUTE 0x10
4507 +#define P_DAC_RIGHT_MUTE 0x01
4508 +#define P_DAC_MUTE 0x11
4509 +#define P_DAC_UNMUTE 0x00
4520 + struct mutex lock;
4521 + unsigned int dual_mode;
4522 + unsigned int set_lowpass;
4523 + unsigned int set_mode;
4524 + unsigned int set_rate;
4525 + unsigned int dsp_page_number;
4528 +static bool digital_gain_0db_limit = true;
4531 +static struct gpio_desc *mute_gpio[2];
4533 +static const char * const allo_piano_mode_texts[] = {
4540 +static SOC_ENUM_SINGLE_DECL(allo_piano_mode_enum,
4541 + 0, 0, allo_piano_mode_texts);
4543 +static const char * const allo_piano_dual_mode_texts[] = {
4549 +static SOC_ENUM_SINGLE_DECL(allo_piano_dual_mode_enum,
4550 + 0, 0, allo_piano_dual_mode_texts);
4552 +static const char * const allo_piano_dsp_low_pass_texts[] = {
4570 +static SOC_ENUM_SINGLE_DECL(allo_piano_enum,
4571 + 0, 0, allo_piano_dsp_low_pass_texts);
4573 +static int __snd_allo_piano_dsp_program(struct snd_soc_pcm_runtime *rtd,
4574 + unsigned int mode, unsigned int rate, unsigned int lowpass)
4576 + const struct firmware *fw;
4577 + struct snd_soc_card *card = rtd->card;
4578 + struct glb_pool *glb_ptr = card->drvdata;
4579 + char firmware_name[60];
4580 + int ret = 0, dac = 0;
4582 + if (rate <= 46000)
4584 + else if (rate <= 68000)
4586 + else if (rate <= 92000)
4588 + else if (rate <= 136000)
4590 + else if (rate <= 184000)
4596 + glb_ptr->set_lowpass = lowpass = 0;
4599 + glb_ptr->set_mode = mode = 0;
4602 + glb_ptr->dual_mode = 0;
4604 + /* same configuration loaded */
4605 + if ((rate == glb_ptr->set_rate) && (lowpass == glb_ptr->set_lowpass)
4606 + && (mode == glb_ptr->set_mode))
4610 + case 0: /* None */
4614 + snd_soc_component_write(asoc_rtd_to_codec(rtd, 0)->component,
4615 + PCM512x_MUTE, P_DAC_UNMUTE);
4616 + snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component,
4617 + PCM512x_MUTE, P_DAC_MUTE);
4618 + glb_ptr->set_rate = rate;
4619 + glb_ptr->set_mode = mode;
4620 + glb_ptr->set_lowpass = lowpass;
4624 + snd_soc_component_write(asoc_rtd_to_codec(rtd, 0)->component,
4625 + PCM512x_MUTE, P_DAC_UNMUTE);
4626 + snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component,
4627 + PCM512x_MUTE, P_DAC_UNMUTE);
4630 + for (dac = 0; dac < rtd->dai_link->num_codecs; dac++) {
4631 + struct dsp_code *dsp_code_read;
4634 + if (dac == 0) { /* high */
4635 + snprintf(firmware_name, sizeof(firmware_name),
4636 + "allo/piano/2.2/allo-piano-dsp-%d-%d-%d.bin",
4637 + rate, ((lowpass * 10) + 60), dac);
4638 + } else { /* low */
4639 + snprintf(firmware_name, sizeof(firmware_name),
4640 + "allo/piano/2.%d/allo-piano-dsp-%d-%d-%d.bin",
4641 + (mode - 1), rate, ((lowpass * 10) + 60), dac);
4644 + dev_info(rtd->card->dev, "Dsp Firmware File Name: %s\n",
4647 + ret = request_firmware(&fw, firmware_name, rtd->card->dev);
4649 + dev_err(rtd->card->dev,
4650 + "Error: Allo Piano Firmware %s missing. %d\n",
4651 + firmware_name, ret);
4655 + while (i < (fw->size - 1)) {
4656 + dsp_code_read = (struct dsp_code *)&fw->data[i];
4658 + if (dsp_code_read->offset == 0) {
4659 + glb_ptr->dsp_page_number = dsp_code_read->val;
4660 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, dac)->component,
4661 + PCM512x_PAGE_BASE(0),
4662 + dsp_code_read->val);
4664 + } else if (dsp_code_read->offset != 0) {
4665 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, dac)->component,
4666 + (PCM512x_PAGE_BASE(
4667 + glb_ptr->dsp_page_number) +
4668 + dsp_code_read->offset),
4669 + dsp_code_read->val);
4672 + dev_err(rtd->card->dev,
4673 + "Failed to write Register: %d\n", ret);
4674 + release_firmware(fw);
4679 + release_firmware(fw);
4681 + glb_ptr->set_rate = rate;
4682 + glb_ptr->set_mode = mode;
4683 + glb_ptr->set_lowpass = lowpass;
4690 +static int snd_allo_piano_dsp_program(struct snd_soc_pcm_runtime *rtd,
4691 + unsigned int mode, unsigned int rate, unsigned int lowpass)
4693 + struct snd_soc_card *card = rtd->card;
4694 + struct glb_pool *glb_ptr = card->drvdata;
4697 + mutex_lock(&glb_ptr->lock);
4699 + ret = __snd_allo_piano_dsp_program(rtd, mode, rate, lowpass);
4701 + mutex_unlock(&glb_ptr->lock);
4706 +static int snd_allo_piano_dual_mode_get(struct snd_kcontrol *kcontrol,
4707 + struct snd_ctl_elem_value *ucontrol)
4709 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
4710 + struct glb_pool *glb_ptr = card->drvdata;
4712 + ucontrol->value.integer.value[0] = glb_ptr->dual_mode;
4717 +static int snd_allo_piano_dual_mode_put(struct snd_kcontrol *kcontrol,
4718 + struct snd_ctl_elem_value *ucontrol)
4720 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
4721 + struct glb_pool *glb_ptr = card->drvdata;
4722 + struct snd_soc_pcm_runtime *rtd;
4723 + struct snd_card *snd_card_ptr = card->snd_card;
4724 + struct snd_kcontrol *kctl;
4725 + struct soc_mixer_control *mc;
4726 + unsigned int left_val = 0, right_val = 0;
4728 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
4730 + if (ucontrol->value.integer.value[0] > 0) {
4731 + glb_ptr->dual_mode = ucontrol->value.integer.value[0];
4732 + glb_ptr->set_mode = 0;
4734 + if (glb_ptr->set_mode <= 0) {
4735 + glb_ptr->dual_mode = 1;
4736 + glb_ptr->set_mode = 0;
4738 + glb_ptr->dual_mode = 0;
4743 + if (glb_ptr->dual_mode == 1) { // Dual Mono
4744 + snd_soc_component_write(asoc_rtd_to_codec(rtd, 0)->component,
4745 + PCM512x_MUTE, P_DAC_RIGHT_MUTE);
4746 + snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component,
4747 + PCM512x_MUTE, P_DAC_LEFT_MUTE);
4748 + snd_soc_component_write(asoc_rtd_to_codec(rtd, 0)->component,
4749 + PCM512x_DIGITAL_VOLUME_3, 0xff);
4750 + snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component,
4751 + PCM512x_DIGITAL_VOLUME_2, 0xff);
4753 + list_for_each_entry(kctl, &snd_card_ptr->controls, list) {
4754 + if (!strncmp(kctl->id.name, "Main Digital Playback Volume",
4755 + sizeof(kctl->id.name))) {
4756 + mc = (struct soc_mixer_control *)
4757 + kctl->private_value;
4758 + mc->rreg = mc->reg;
4761 + if (!strncmp(kctl->id.name, "Sub Digital Playback Volume",
4762 + sizeof(kctl->id.name))) {
4763 + mc = (struct soc_mixer_control *)
4764 + kctl->private_value;
4765 + mc->rreg = mc->reg;
4770 + left_val = snd_soc_component_read(asoc_rtd_to_codec(rtd, 0)->component,
4771 + PCM512x_DIGITAL_VOLUME_2);
4772 + right_val = snd_soc_component_read(asoc_rtd_to_codec(rtd, 1)->component,
4773 + PCM512x_DIGITAL_VOLUME_3);
4775 + list_for_each_entry(kctl, &snd_card_ptr->controls, list) {
4776 + if (!strncmp(kctl->id.name, "Main Digital Playback Volume",
4777 + sizeof(kctl->id.name))) {
4778 + mc = (struct soc_mixer_control *)
4779 + kctl->private_value;
4780 + mc->rreg = PCM512x_DIGITAL_VOLUME_3;
4783 + if (!strncmp(kctl->id.name, "Sub Digital Playback Volume",
4784 + sizeof(kctl->id.name))) {
4785 + mc = (struct soc_mixer_control *)
4786 + kctl->private_value;
4787 + mc->rreg = PCM512x_DIGITAL_VOLUME_2;
4792 + snd_soc_component_write(asoc_rtd_to_codec(rtd, 0)->component,
4793 + PCM512x_DIGITAL_VOLUME_3, left_val);
4794 + snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component,
4795 + PCM512x_DIGITAL_VOLUME_2, right_val);
4796 + snd_soc_component_write(asoc_rtd_to_codec(rtd, 0)->component,
4797 + PCM512x_MUTE, P_DAC_UNMUTE);
4798 + snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component,
4799 + PCM512x_MUTE, P_DAC_UNMUTE);
4805 +static int snd_allo_piano_mode_get(struct snd_kcontrol *kcontrol,
4806 + struct snd_ctl_elem_value *ucontrol)
4808 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
4809 + struct glb_pool *glb_ptr = card->drvdata;
4811 + ucontrol->value.integer.value[0] = glb_ptr->set_mode;
4815 +static int snd_allo_piano_mode_put(struct snd_kcontrol *kcontrol,
4816 + struct snd_ctl_elem_value *ucontrol)
4818 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
4819 + struct snd_soc_pcm_runtime *rtd;
4820 + struct glb_pool *glb_ptr = card->drvdata;
4821 + struct snd_card *snd_card_ptr = card->snd_card;
4822 + struct snd_kcontrol *kctl;
4823 + struct soc_mixer_control *mc;
4824 + unsigned int left_val = 0, right_val = 0;
4826 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
4828 + if ((glb_ptr->dual_mode == 1) &&
4829 + (ucontrol->value.integer.value[0] > 0)) {
4830 + left_val = snd_soc_component_read(asoc_rtd_to_codec(rtd, 0)->component,
4831 + PCM512x_DIGITAL_VOLUME_2);
4832 + right_val = snd_soc_component_read(asoc_rtd_to_codec(rtd, 1)->component,
4833 + PCM512x_DIGITAL_VOLUME_2);
4835 + list_for_each_entry(kctl, &snd_card_ptr->controls, list) {
4836 + if (!strncmp(kctl->id.name, "Main Digital Playback Volume",
4837 + sizeof(kctl->id.name))) {
4838 + mc = (struct soc_mixer_control *)
4839 + kctl->private_value;
4840 + mc->rreg = PCM512x_DIGITAL_VOLUME_3;
4843 + if (!strncmp(kctl->id.name, "Sub Digital Playback Volume",
4844 + sizeof(kctl->id.name))) {
4845 + mc = (struct soc_mixer_control *)
4846 + kctl->private_value;
4847 + mc->rreg = PCM512x_DIGITAL_VOLUME_2;
4851 + snd_soc_component_write(asoc_rtd_to_codec(rtd, 0)->component,
4852 + PCM512x_DIGITAL_VOLUME_3, left_val);
4853 + snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component,
4854 + PCM512x_DIGITAL_VOLUME_3, right_val);
4857 + return(snd_allo_piano_dsp_program(rtd,
4858 + ucontrol->value.integer.value[0],
4859 + glb_ptr->set_rate, glb_ptr->set_lowpass));
4862 +static int snd_allo_piano_lowpass_get(struct snd_kcontrol *kcontrol,
4863 + struct snd_ctl_elem_value *ucontrol)
4865 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
4866 + struct glb_pool *glb_ptr = card->drvdata;
4868 + ucontrol->value.integer.value[0] = glb_ptr->set_lowpass;
4872 +static int snd_allo_piano_lowpass_put(struct snd_kcontrol *kcontrol,
4873 + struct snd_ctl_elem_value *ucontrol)
4875 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
4876 + struct snd_soc_pcm_runtime *rtd;
4877 + struct glb_pool *glb_ptr = card->drvdata;
4879 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
4880 + return(snd_allo_piano_dsp_program(rtd,
4881 + glb_ptr->set_mode, glb_ptr->set_rate,
4882 + ucontrol->value.integer.value[0]));
4885 +static int pcm512x_get_reg_sub(struct snd_kcontrol *kcontrol,
4886 + struct snd_ctl_elem_value *ucontrol)
4888 + struct soc_mixer_control *mc =
4889 + (struct soc_mixer_control *)kcontrol->private_value;
4890 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
4891 + struct glb_pool *glb_ptr = card->drvdata;
4892 + struct snd_soc_pcm_runtime *rtd;
4893 + unsigned int left_val = 0;
4894 + unsigned int right_val = 0;
4895 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
4897 + right_val = snd_soc_component_read(asoc_rtd_to_codec(rtd, 1)->component,
4898 + PCM512x_DIGITAL_VOLUME_3);
4899 + if (glb_ptr->dual_mode != 1) {
4900 + left_val = snd_soc_component_read(asoc_rtd_to_codec(rtd, 1)->component,
4901 + PCM512x_DIGITAL_VOLUME_2);
4904 + left_val = right_val;
4907 + ucontrol->value.integer.value[0] =
4908 + (~(left_val >> mc->shift)) & mc->max;
4909 + ucontrol->value.integer.value[1] =
4910 + (~(right_val >> mc->shift)) & mc->max;
4915 +static int pcm512x_set_reg_sub(struct snd_kcontrol *kcontrol,
4916 + struct snd_ctl_elem_value *ucontrol)
4918 + struct soc_mixer_control *mc =
4919 + (struct soc_mixer_control *)kcontrol->private_value;
4920 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
4921 + struct glb_pool *glb_ptr = card->drvdata;
4922 + struct snd_soc_pcm_runtime *rtd;
4923 + unsigned int left_val = (ucontrol->value.integer.value[0] & mc->max);
4924 + unsigned int right_val = (ucontrol->value.integer.value[1] & mc->max);
4927 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
4929 + if (digital_gain_0db_limit) {
4930 + ret = snd_soc_limit_volume(card, "Subwoofer Playback Volume",
4933 + dev_warn(card->dev, "Failed to set volume limit: %d\n",
4937 + // When in Dual Mono, Sub vol control should not set anything.
4938 + if (glb_ptr->dual_mode != 1) { //Not in Dual Mono mode
4940 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component,
4941 + PCM512x_DIGITAL_VOLUME_2, (~left_val));
4945 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component,
4946 + PCM512x_DIGITAL_VOLUME_3, (~right_val));
4955 +static int pcm512x_get_reg_sub_switch(struct snd_kcontrol *kcontrol,
4956 + struct snd_ctl_elem_value *ucontrol)
4958 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
4959 + struct snd_soc_pcm_runtime *rtd;
4962 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
4963 + val = snd_soc_component_read(asoc_rtd_to_codec(rtd, 1)->component, PCM512x_MUTE);
4965 + ucontrol->value.integer.value[0] =
4966 + (val & P_DAC_LEFT_MUTE) ? P_UNMUTE : P_MUTE;
4967 + ucontrol->value.integer.value[1] =
4968 + (val & P_DAC_RIGHT_MUTE) ? P_UNMUTE : P_MUTE;
4973 +static int pcm512x_set_reg_sub_switch(struct snd_kcontrol *kcontrol,
4974 + struct snd_ctl_elem_value *ucontrol)
4976 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
4977 + struct snd_soc_pcm_runtime *rtd;
4978 + struct glb_pool *glb_ptr = card->drvdata;
4979 + unsigned int left_val = (ucontrol->value.integer.value[0]);
4980 + unsigned int right_val = (ucontrol->value.integer.value[1]);
4983 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
4984 + if (glb_ptr->set_mode != 1) {
4985 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component, PCM512x_MUTE,
4986 + ~((left_val & 0x01)<<4 | (right_val & 0x01)));
4994 +static int pcm512x_get_reg_master(struct snd_kcontrol *kcontrol,
4995 + struct snd_ctl_elem_value *ucontrol)
4997 + struct soc_mixer_control *mc =
4998 + (struct soc_mixer_control *)kcontrol->private_value;
4999 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
5000 + struct glb_pool *glb_ptr = card->drvdata;
5001 + struct snd_soc_pcm_runtime *rtd;
5002 + unsigned int left_val = 0, right_val = 0;
5004 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
5006 + left_val = snd_soc_component_read(asoc_rtd_to_codec(rtd, 0)->component,
5007 + PCM512x_DIGITAL_VOLUME_2);
5009 + if (glb_ptr->dual_mode == 1) { // in Dual Mono mode
5010 + right_val = snd_soc_component_read(asoc_rtd_to_codec(rtd, 1)->component,
5011 + PCM512x_DIGITAL_VOLUME_3);
5013 + right_val = snd_soc_component_read(asoc_rtd_to_codec(rtd, 0)->component,
5014 + PCM512x_DIGITAL_VOLUME_3);
5017 + ucontrol->value.integer.value[0] =
5018 + (~(left_val >> mc->shift)) & mc->max;
5019 + ucontrol->value.integer.value[1] =
5020 + (~(right_val >> mc->shift)) & mc->max;
5025 +static int pcm512x_set_reg_master(struct snd_kcontrol *kcontrol,
5026 + struct snd_ctl_elem_value *ucontrol)
5028 + struct soc_mixer_control *mc =
5029 + (struct soc_mixer_control *)kcontrol->private_value;
5030 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
5031 + struct glb_pool *glb_ptr = card->drvdata;
5032 + struct snd_soc_pcm_runtime *rtd;
5033 + unsigned int left_val = (ucontrol->value.integer.value[0] & mc->max);
5034 + unsigned int right_val = (ucontrol->value.integer.value[1] & mc->max);
5037 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
5039 + if (digital_gain_0db_limit) {
5040 + ret = snd_soc_limit_volume(card, "Master Playback Volume",
5043 + dev_warn(card->dev, "Failed to set volume limit: %d\n",
5047 + if (glb_ptr->dual_mode == 1) { //in Dual Mono Mode
5049 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 0)->component,
5050 + PCM512x_DIGITAL_VOLUME_2, (~left_val));
5054 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component,
5055 + PCM512x_DIGITAL_VOLUME_3, (~right_val));
5061 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 0)->component,
5062 + PCM512x_DIGITAL_VOLUME_2, (~left_val));
5066 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 0)->component,
5067 + PCM512x_DIGITAL_VOLUME_3, (~right_val));
5075 +static int pcm512x_get_reg_master_switch(struct snd_kcontrol *kcontrol,
5076 + struct snd_ctl_elem_value *ucontrol)
5078 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
5079 + struct glb_pool *glb_ptr = card->drvdata;
5080 + struct snd_soc_pcm_runtime *rtd;
5083 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
5085 + val = snd_soc_component_read(asoc_rtd_to_codec(rtd, 0)->component, PCM512x_MUTE);
5087 + ucontrol->value.integer.value[0] =
5088 + (val & P_DAC_LEFT_MUTE) ? P_UNMUTE : P_MUTE;
5090 + if (glb_ptr->dual_mode == 1) {
5091 + val = snd_soc_component_read(asoc_rtd_to_codec(rtd, 1)->component, PCM512x_MUTE);
5093 + ucontrol->value.integer.value[1] =
5094 + (val & P_DAC_RIGHT_MUTE) ? P_UNMUTE : P_MUTE;
5099 +static int pcm512x_set_reg_master_switch(struct snd_kcontrol *kcontrol,
5100 + struct snd_ctl_elem_value *ucontrol)
5102 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
5103 + struct snd_soc_pcm_runtime *rtd;
5104 + struct glb_pool *glb_ptr = card->drvdata;
5105 + unsigned int left_val = (ucontrol->value.integer.value[0]);
5106 + unsigned int right_val = (ucontrol->value.integer.value[1]);
5109 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
5110 + if (glb_ptr->dual_mode == 1) {
5111 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 0)->component, PCM512x_MUTE,
5112 + ~((left_val & 0x01)<<4));
5115 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component, PCM512x_MUTE,
5116 + ~((right_val & 0x01)));
5120 + } else if (glb_ptr->set_mode == 1) {
5121 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 0)->component, PCM512x_MUTE,
5122 + ~((left_val & 0x01)<<4 | (right_val & 0x01)));
5127 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 0)->component, PCM512x_MUTE,
5128 + ~((left_val & 0x01)<<4 | (right_val & 0x01)));
5132 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component, PCM512x_MUTE,
5133 + ~((left_val & 0x01)<<4 | (right_val & 0x01)));
5140 +static const DECLARE_TLV_DB_SCALE(digital_tlv_sub, -10350, 50, 1);
5141 +static const DECLARE_TLV_DB_SCALE(digital_tlv_master, -10350, 50, 1);
5143 +static const struct snd_kcontrol_new allo_piano_controls[] = {
5144 + SOC_ENUM_EXT("Subwoofer mode Route",
5145 + allo_piano_mode_enum,
5146 + snd_allo_piano_mode_get,
5147 + snd_allo_piano_mode_put),
5149 + SOC_ENUM_EXT("Dual Mode Route",
5150 + allo_piano_dual_mode_enum,
5151 + snd_allo_piano_dual_mode_get,
5152 + snd_allo_piano_dual_mode_put),
5154 + SOC_ENUM_EXT("Lowpass Route", allo_piano_enum,
5155 + snd_allo_piano_lowpass_get,
5156 + snd_allo_piano_lowpass_put),
5158 + SOC_DOUBLE_R_EXT_TLV("Subwoofer Playback Volume",
5159 + PCM512x_DIGITAL_VOLUME_2,
5160 + PCM512x_DIGITAL_VOLUME_3, 0, 255, 1,
5161 + pcm512x_get_reg_sub,
5162 + pcm512x_set_reg_sub,
5165 + SOC_DOUBLE_EXT("Subwoofer Playback Switch",
5167 + PCM512x_RQML_SHIFT,
5168 + PCM512x_RQMR_SHIFT, 1, 1,
5169 + pcm512x_get_reg_sub_switch,
5170 + pcm512x_set_reg_sub_switch),
5172 + SOC_DOUBLE_R_EXT_TLV("Master Playback Volume",
5173 + PCM512x_DIGITAL_VOLUME_2,
5174 + PCM512x_DIGITAL_VOLUME_3, 0, 255, 1,
5175 + pcm512x_get_reg_master,
5176 + pcm512x_set_reg_master,
5177 + digital_tlv_master),
5179 + SOC_DOUBLE_EXT("Master Playback Switch",
5181 + PCM512x_RQML_SHIFT,
5182 + PCM512x_RQMR_SHIFT, 1, 1,
5183 + pcm512x_get_reg_master_switch,
5184 + pcm512x_set_reg_master_switch),
5187 +static const char * const codec_ctl_pfx[] = { "Main", "Sub" };
5188 +static const char * const codec_ctl_name[] = {
5189 + "Digital Playback Volume",
5190 + "Digital Playback Switch",
5191 + "Auto Mute Mono Switch",
5192 + "Auto Mute Switch",
5193 + "Auto Mute Time Left",
5194 + "Auto Mute Time Right",
5195 + "Clock Missing Period",
5196 + "Max Overclock DAC",
5197 + "Max Overclock DSP",
5198 + "Max Overclock PLL",
5199 + "Volume Ramp Down Emergency Rate",
5200 + "Volume Ramp Down Emergency Step",
5201 + "Volume Ramp Up Rate",
5202 + "Volume Ramp Down Rate",
5203 + "Volume Ramp Up Step",
5204 + "Volume Ramp Down Step"
5207 +static int snd_allo_piano_dac_init(struct snd_soc_pcm_runtime *rtd)
5209 + struct snd_soc_card *card = rtd->card;
5210 + struct glb_pool *glb_ptr;
5211 + struct snd_kcontrol *kctl;
5214 + glb_ptr = kzalloc(sizeof(struct glb_pool), GFP_KERNEL);
5218 + card->drvdata = glb_ptr;
5219 + glb_ptr->dual_mode = 2;
5220 + glb_ptr->set_mode = 0;
5222 + mutex_init(&glb_ptr->lock);
5224 + if (digital_gain_0db_limit) {
5227 + //Set volume limit on both dacs
5228 + for (i = 0; i < ARRAY_SIZE(codec_ctl_pfx); i++) {
5231 + sprintf(cname, "%s %s", codec_ctl_pfx[i], codec_ctl_name[0]);
5232 + ret = snd_soc_limit_volume(card, cname, 207);
5234 + dev_warn(card->dev, "Failed to set volume limit: %d\n",
5239 + // Remove codec controls
5240 + for (i = 0; i < ARRAY_SIZE(codec_ctl_pfx); i++) {
5241 + for (j = 0; j < ARRAY_SIZE(codec_ctl_name); j++) {
5244 + sprintf(cname, "%s %s", codec_ctl_pfx[i], codec_ctl_name[j]);
5245 + kctl = snd_soc_card_get_kcontrol(card, cname);
5247 + dev_err(rtd->card->dev, "Control %s not found\n",
5250 + kctl->vd[0].access =
5251 + SNDRV_CTL_ELEM_ACCESS_READWRITE;
5252 + snd_ctl_remove(card->snd_card, kctl);
5260 +static void snd_allo_piano_gpio_mute(struct snd_soc_card *card)
5263 + gpiod_set_value_cansleep(mute_gpio[0], P_MUTE);
5266 + gpiod_set_value_cansleep(mute_gpio[1], P_MUTE);
5269 +static void snd_allo_piano_gpio_unmute(struct snd_soc_card *card)
5272 + gpiod_set_value_cansleep(mute_gpio[0], P_UNMUTE);
5275 + gpiod_set_value_cansleep(mute_gpio[1], P_UNMUTE);
5278 +static int snd_allo_piano_set_bias_level(struct snd_soc_card *card,
5279 + struct snd_soc_dapm_context *dapm, enum snd_soc_bias_level level)
5281 + struct snd_soc_pcm_runtime *rtd;
5282 + struct snd_soc_dai *codec_dai;
5284 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
5285 + codec_dai = asoc_rtd_to_codec(rtd, 0);
5287 + if (dapm->dev != codec_dai->dev)
5291 + case SND_SOC_BIAS_PREPARE:
5292 + if (dapm->bias_level != SND_SOC_BIAS_STANDBY)
5295 + snd_allo_piano_gpio_unmute(card);
5298 + case SND_SOC_BIAS_STANDBY:
5299 + if (dapm->bias_level != SND_SOC_BIAS_PREPARE)
5302 + snd_allo_piano_gpio_mute(card);
5312 +static int snd_allo_piano_dac_startup(
5313 + struct snd_pcm_substream *substream)
5315 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
5316 + struct snd_soc_card *card = rtd->card;
5318 + snd_allo_piano_gpio_mute(card);
5323 +static int snd_allo_piano_dac_hw_params(
5324 + struct snd_pcm_substream *substream,
5325 + struct snd_pcm_hw_params *params)
5327 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
5328 + unsigned int rate = params_rate(params);
5329 + struct snd_soc_card *card = rtd->card;
5330 + struct glb_pool *glb_ptr = card->drvdata;
5331 + int ret = 0, val = 0, dac;
5333 + for (dac = 0; (glb_mclk && dac < 2); dac++) {
5334 + /* Configure the PLL clock reference for both the Codecs */
5335 + val = snd_soc_component_read(asoc_rtd_to_codec(rtd, dac)->component,
5336 + PCM512x_RATE_DET_4);
5339 + snd_soc_component_write(asoc_rtd_to_codec(rtd, dac)->component,
5341 + PCM512x_SREF_BCK);
5343 + dev_info(asoc_rtd_to_codec(rtd, dac)->component->dev,
5344 + "Setting BCLK as input clock & Enable PLL\n");
5346 + snd_soc_component_write(asoc_rtd_to_codec(rtd, dac)->component,
5350 + snd_soc_component_write(asoc_rtd_to_codec(rtd, dac)->component,
5352 + PCM512x_SREF_SCK);
5354 + dev_info(asoc_rtd_to_codec(rtd, dac)->component->dev,
5355 + "Setting SCLK as input clock & disabled PLL\n");
5359 + ret = snd_allo_piano_dsp_program(rtd, glb_ptr->set_mode, rate,
5360 + glb_ptr->set_lowpass);
5367 +static int snd_allo_piano_dac_prepare(
5368 + struct snd_pcm_substream *substream)
5370 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
5371 + struct snd_soc_card *card = rtd->card;
5373 + snd_allo_piano_gpio_unmute(card);
5378 +/* machine stream operations */
5379 +static struct snd_soc_ops snd_allo_piano_dac_ops = {
5380 + .startup = snd_allo_piano_dac_startup,
5381 + .hw_params = snd_allo_piano_dac_hw_params,
5382 + .prepare = snd_allo_piano_dac_prepare,
5385 +static struct snd_soc_dai_link_component allo_piano_2_1_codecs[] = {
5387 + .dai_name = "pcm512x-hifi",
5390 + .dai_name = "pcm512x-hifi",
5394 +SND_SOC_DAILINK_DEFS(allo_piano_dai_plus,
5395 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
5396 + DAILINK_COMP_ARRAY(COMP_CODEC("pcm512x.1-004c", "pcm512x-hifi"),
5397 + COMP_CODEC("pcm512x.1-004d", "pcm512x-hifi")),
5398 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
5400 +static struct snd_soc_dai_link snd_allo_piano_dac_dai[] = {
5402 + .name = "PianoDACPlus",
5403 + .stream_name = "PianoDACPlus",
5404 + .dai_fmt = SND_SOC_DAIFMT_I2S |
5405 + SND_SOC_DAIFMT_NB_NF |
5406 + SND_SOC_DAIFMT_CBS_CFS,
5407 + .ops = &snd_allo_piano_dac_ops,
5408 + .init = snd_allo_piano_dac_init,
5409 + SND_SOC_DAILINK_REG(allo_piano_dai_plus),
5413 +/* audio machine driver */
5414 +static struct snd_soc_card snd_allo_piano_dac = {
5415 + .name = "PianoDACPlus",
5416 + .owner = THIS_MODULE,
5417 + .dai_link = snd_allo_piano_dac_dai,
5418 + .num_links = ARRAY_SIZE(snd_allo_piano_dac_dai),
5419 + .controls = allo_piano_controls,
5420 + .num_controls = ARRAY_SIZE(allo_piano_controls),
5423 +static int snd_allo_piano_dac_probe(struct platform_device *pdev)
5425 + struct snd_soc_card *card = &snd_allo_piano_dac;
5426 + int ret = 0, i = 0;
5428 + card->dev = &pdev->dev;
5429 + platform_set_drvdata(pdev, &snd_allo_piano_dac);
5431 + if (pdev->dev.of_node) {
5432 + struct device_node *i2s_node;
5433 + struct snd_soc_dai_link *dai;
5435 + dai = &snd_allo_piano_dac_dai[0];
5436 + i2s_node = of_parse_phandle(pdev->dev.of_node,
5437 + "i2s-controller", 0);
5439 + for (i = 0; i < card->num_links; i++) {
5440 + dai->cpus->dai_name = NULL;
5441 + dai->cpus->of_node = i2s_node;
5442 + dai->platforms->name = NULL;
5443 + dai->platforms->of_node = i2s_node;
5446 + digital_gain_0db_limit =
5447 + !of_property_read_bool(pdev->dev.of_node,
5448 + "allo,24db_digital_gain");
5450 + glb_mclk = of_property_read_bool(pdev->dev.of_node,
5453 + allo_piano_2_1_codecs[0].of_node =
5454 + of_parse_phandle(pdev->dev.of_node, "audio-codec", 0);
5455 + if (!allo_piano_2_1_codecs[0].of_node) {
5456 + dev_err(&pdev->dev,
5457 + "Property 'audio-codec' missing or invalid\n");
5461 + allo_piano_2_1_codecs[1].of_node =
5462 + of_parse_phandle(pdev->dev.of_node, "audio-codec", 1);
5463 + if (!allo_piano_2_1_codecs[1].of_node) {
5464 + dev_err(&pdev->dev,
5465 + "Property 'audio-codec' missing or invalid\n");
5469 + mute_gpio[0] = devm_gpiod_get_optional(&pdev->dev, "mute1",
5471 + if (IS_ERR(mute_gpio[0])) {
5472 + ret = PTR_ERR(mute_gpio[0]);
5473 + dev_err(&pdev->dev,
5474 + "failed to get mute1 gpio6: %d\n", ret);
5478 + mute_gpio[1] = devm_gpiod_get_optional(&pdev->dev, "mute2",
5480 + if (IS_ERR(mute_gpio[1])) {
5481 + ret = PTR_ERR(mute_gpio[1]);
5482 + dev_err(&pdev->dev,
5483 + "failed to get mute2 gpio25: %d\n", ret);
5487 + if (mute_gpio[0] && mute_gpio[1])
5488 + snd_allo_piano_dac.set_bias_level =
5489 + snd_allo_piano_set_bias_level;
5491 + ret = snd_soc_register_card(&snd_allo_piano_dac);
5493 + dev_err(&pdev->dev,
5494 + "snd_soc_register_card() failed: %d\n", ret);
5498 + if ((mute_gpio[0]) && (mute_gpio[1]))
5499 + snd_allo_piano_gpio_mute(&snd_allo_piano_dac);
5507 +static int snd_allo_piano_dac_remove(struct platform_device *pdev)
5509 + struct snd_soc_card *card = platform_get_drvdata(pdev);
5511 + kfree(&card->drvdata);
5512 + snd_allo_piano_gpio_mute(&snd_allo_piano_dac);
5513 + snd_soc_unregister_card(&snd_allo_piano_dac);
5517 +static const struct of_device_id snd_allo_piano_dac_of_match[] = {
5518 + { .compatible = "allo,piano-dac-plus", },
5519 + { /* sentinel */ },
5522 +MODULE_DEVICE_TABLE(of, snd_allo_piano_dac_of_match);
5524 +static struct platform_driver snd_allo_piano_dac_driver = {
5526 + .name = "snd-allo-piano-dac-plus",
5527 + .owner = THIS_MODULE,
5528 + .of_match_table = snd_allo_piano_dac_of_match,
5530 + .probe = snd_allo_piano_dac_probe,
5531 + .remove = snd_allo_piano_dac_remove,
5534 +module_platform_driver(snd_allo_piano_dac_driver);
5536 +MODULE_AUTHOR("Baswaraj K <jaikumar@cem-solutions.net>");
5537 +MODULE_DESCRIPTION("ALSA ASoC Machine Driver for Allo Piano DAC Plus");
5538 +MODULE_LICENSE("GPL v2");
5540 +++ b/sound/soc/bcm/allo-piano-dac.c
5543 + * ALSA ASoC Machine Driver for Allo Piano DAC
5545 + * Author: Baswaraj K <jaikumar@cem-solutions.net>
5547 + * based on code by Daniel Matuschek <info@crazy-audio.com>
5548 + * based on code by Florian Meier <florian.meier@koalo.de>
5550 + * This program is free software; you can redistribute it and/or
5551 + * modify it under the terms of the GNU General Public License
5552 + * version 2 as published by the Free Software Foundation.
5554 + * This program is distributed in the hope that it will be useful, but
5555 + * WITHOUT ANY WARRANTY; without even the implied warranty of
5556 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5557 + * General Public License for more details.
5560 +#include <linux/module.h>
5561 +#include <linux/platform_device.h>
5563 +#include <sound/core.h>
5564 +#include <sound/pcm.h>
5565 +#include <sound/pcm_params.h>
5566 +#include <sound/soc.h>
5568 +static bool digital_gain_0db_limit = true;
5570 +static int snd_allo_piano_dac_init(struct snd_soc_pcm_runtime *rtd)
5572 + if (digital_gain_0db_limit) {
5574 + struct snd_soc_card *card = rtd->card;
5576 + ret = snd_soc_limit_volume(card, "Digital Playback Volume",
5579 + dev_warn(card->dev, "Failed to set volume limit: %d\n",
5586 +SND_SOC_DAILINK_DEFS(allo_piano_dai,
5587 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
5588 + DAILINK_COMP_ARRAY(COMP_CODEC("pcm512x.1-004c", "pcm512x-hifi")),
5589 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
5591 +static struct snd_soc_dai_link snd_allo_piano_dac_dai[] = {
5593 + .name = "Piano DAC",
5594 + .stream_name = "Piano DAC HiFi",
5595 + .dai_fmt = SND_SOC_DAIFMT_I2S |
5596 + SND_SOC_DAIFMT_NB_NF |
5597 + SND_SOC_DAIFMT_CBS_CFS,
5598 + .init = snd_allo_piano_dac_init,
5599 + SND_SOC_DAILINK_REG(allo_piano_dai),
5603 +/* audio machine driver */
5604 +static struct snd_soc_card snd_allo_piano_dac = {
5605 + .name = "PianoDAC",
5606 + .owner = THIS_MODULE,
5607 + .dai_link = snd_allo_piano_dac_dai,
5608 + .num_links = ARRAY_SIZE(snd_allo_piano_dac_dai),
5611 +static int snd_allo_piano_dac_probe(struct platform_device *pdev)
5615 + snd_allo_piano_dac.dev = &pdev->dev;
5617 + if (pdev->dev.of_node) {
5618 + struct device_node *i2s_node;
5619 + struct snd_soc_dai_link *dai;
5621 + dai = &snd_allo_piano_dac_dai[0];
5622 + i2s_node = of_parse_phandle(pdev->dev.of_node,
5623 + "i2s-controller", 0);
5626 + dai->cpus->dai_name = NULL;
5627 + dai->cpus->of_node = i2s_node;
5628 + dai->platforms->name = NULL;
5629 + dai->platforms->of_node = i2s_node;
5632 + digital_gain_0db_limit = !of_property_read_bool(
5633 + pdev->dev.of_node, "allo,24db_digital_gain");
5636 + ret = devm_snd_soc_register_card(&pdev->dev, &snd_allo_piano_dac);
5637 + if (ret && ret != -EPROBE_DEFER)
5638 + dev_err(&pdev->dev,
5639 + "snd_soc_register_card() failed: %d\n", ret);
5644 +static const struct of_device_id snd_allo_piano_dac_of_match[] = {
5645 + { .compatible = "allo,piano-dac", },
5646 + { /* sentinel */ },
5648 +MODULE_DEVICE_TABLE(of, snd_allo_piano_dac_of_match);
5650 +static struct platform_driver snd_allo_piano_dac_driver = {
5652 + .name = "snd-allo-piano-dac",
5653 + .owner = THIS_MODULE,
5654 + .of_match_table = snd_allo_piano_dac_of_match,
5656 + .probe = snd_allo_piano_dac_probe,
5659 +module_platform_driver(snd_allo_piano_dac_driver);
5661 +MODULE_AUTHOR("Baswaraj K <jaikumar@cem-solutions.net>");
5662 +MODULE_DESCRIPTION("ALSA ASoC Machine Driver for Allo Piano DAC");
5663 +MODULE_LICENSE("GPL v2");
5665 +++ b/sound/soc/bcm/audioinjector-isolated-soundcard.c
5668 + * ASoC Driver for AudioInjector.net isolated soundcard
5670 + * Created on: 20-February-2020
5671 + * Author: flatmax@flatmax.org
5672 + * based on audioinjector-octo-soundcard.c
5674 + * Copyright (C) 2020 Flatmax Pty. Ltd.
5676 + * This program is free software; you can redistribute it and/or
5677 + * modify it under the terms of the GNU General Public License
5678 + * version 2 as published by the Free Software Foundation.
5680 + * This program is distributed in the hope that it will be useful, but
5681 + * WITHOUT ANY WARRANTY; without even the implied warranty of
5682 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5683 + * General Public License for more details.
5686 +#include <linux/module.h>
5687 +#include <linux/types.h>
5688 +#include <linux/gpio/consumer.h>
5690 +#include <sound/core.h>
5691 +#include <sound/soc.h>
5692 +#include <sound/pcm_params.h>
5693 +#include <sound/control.h>
5695 +static struct gpio_desc *mute_gpio;
5697 +static const unsigned int audioinjector_isolated_rates[] = {
5698 + 192000, 96000, 48000, 32000, 24000, 16000, 8000
5701 +static struct snd_pcm_hw_constraint_list audioinjector_isolated_constraints = {
5702 + .list = audioinjector_isolated_rates,
5703 + .count = ARRAY_SIZE(audioinjector_isolated_rates),
5706 +static int audioinjector_isolated_dai_init(struct snd_soc_pcm_runtime *rtd)
5708 + int ret=snd_soc_dai_set_sysclk(asoc_rtd_to_codec(rtd, 0), 0, 24576000, 0);
5712 + return snd_soc_dai_set_bclk_ratio(asoc_rtd_to_cpu(rtd, 0), 64);
5715 +static int audioinjector_isolated_startup(struct snd_pcm_substream *substream)
5717 + snd_pcm_hw_constraint_list(substream->runtime, 0,
5718 + SNDRV_PCM_HW_PARAM_RATE, &audioinjector_isolated_constraints);
5723 +static int audioinjector_isolated_trigger(struct snd_pcm_substream *substream,
5727 + case SNDRV_PCM_TRIGGER_STOP:
5728 + case SNDRV_PCM_TRIGGER_SUSPEND:
5729 + case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
5730 + gpiod_set_value(mute_gpio, 0);
5732 + case SNDRV_PCM_TRIGGER_START:
5733 + case SNDRV_PCM_TRIGGER_RESUME:
5734 + case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
5735 + gpiod_set_value(mute_gpio, 1);
5743 +static struct snd_soc_ops audioinjector_isolated_ops = {
5744 + .startup = audioinjector_isolated_startup,
5745 + .trigger = audioinjector_isolated_trigger,
5748 +SND_SOC_DAILINK_DEFS(audioinjector_isolated,
5749 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
5750 + DAILINK_COMP_ARRAY(COMP_CODEC("cs4271.1-0010", "cs4271-hifi")),
5751 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
5753 +static struct snd_soc_dai_link audioinjector_isolated_dai[] = {
5755 + .name = "AudioInjector ISO",
5756 + .stream_name = "AI-HIFI",
5757 + .ops = &audioinjector_isolated_ops,
5758 + .init = audioinjector_isolated_dai_init,
5759 + .symmetric_rate = 1,
5760 + .symmetric_channels = 1,
5761 + .dai_fmt = SND_SOC_DAIFMT_CBM_CFM|SND_SOC_DAIFMT_I2S|SND_SOC_DAIFMT_NB_NF,
5762 + SND_SOC_DAILINK_REG(audioinjector_isolated),
5766 +static const struct snd_soc_dapm_widget audioinjector_isolated_widgets[] = {
5767 + SND_SOC_DAPM_OUTPUT("OUTPUTS"),
5768 + SND_SOC_DAPM_INPUT("INPUTS"),
5771 +static const struct snd_soc_dapm_route audioinjector_isolated_route[] = {
5772 + /* Balanced outputs */
5773 + {"OUTPUTS", NULL, "AOUTA+"},
5774 + {"OUTPUTS", NULL, "AOUTA-"},
5775 + {"OUTPUTS", NULL, "AOUTB+"},
5776 + {"OUTPUTS", NULL, "AOUTB-"},
5778 + /* Balanced inputs */
5779 + {"AINA", NULL, "INPUTS"},
5780 + {"AINB", NULL, "INPUTS"},
5783 +static struct snd_soc_card snd_soc_audioinjector_isolated = {
5784 + .name = "audioinjector-isolated-soundcard",
5785 + .dai_link = audioinjector_isolated_dai,
5786 + .num_links = ARRAY_SIZE(audioinjector_isolated_dai),
5788 + .dapm_widgets = audioinjector_isolated_widgets,
5789 + .num_dapm_widgets = ARRAY_SIZE(audioinjector_isolated_widgets),
5790 + .dapm_routes = audioinjector_isolated_route,
5791 + .num_dapm_routes = ARRAY_SIZE(audioinjector_isolated_route),
5794 +static int audioinjector_isolated_probe(struct platform_device *pdev)
5796 + struct snd_soc_card *card = &snd_soc_audioinjector_isolated;
5799 + card->dev = &pdev->dev;
5801 + if (pdev->dev.of_node) {
5802 + struct snd_soc_dai_link *dai = &audioinjector_isolated_dai[0];
5803 + struct device_node *i2s_node =
5804 + of_parse_phandle(pdev->dev.of_node, "i2s-controller", 0);
5807 + dai->cpus->dai_name = NULL;
5808 + dai->cpus->of_node = i2s_node;
5809 + dai->platforms->name = NULL;
5810 + dai->platforms->of_node = i2s_node;
5812 + dev_err(&pdev->dev,
5813 + "i2s-controller missing or invalid in DT\n");
5817 + mute_gpio = devm_gpiod_get_optional(&pdev->dev, "mute", GPIOD_OUT_LOW);
5818 + if (IS_ERR(mute_gpio)){
5819 + dev_err(&pdev->dev, "mute gpio not found in dt overlay\n");
5820 + return PTR_ERR(mute_gpio);
5824 + ret = devm_snd_soc_register_card(&pdev->dev, card);
5825 + if (ret && ret != -EPROBE_DEFER)
5826 + dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret);
5830 +static const struct of_device_id audioinjector_isolated_of_match[] = {
5831 + { .compatible = "ai,audioinjector-isolated-soundcard", },
5834 +MODULE_DEVICE_TABLE(of, audioinjector_isolated_of_match);
5836 +static struct platform_driver audioinjector_isolated_driver = {
5838 + .name = "audioinjector-isolated",
5839 + .owner = THIS_MODULE,
5840 + .of_match_table = audioinjector_isolated_of_match,
5842 + .probe = audioinjector_isolated_probe,
5845 +module_platform_driver(audioinjector_isolated_driver);
5846 +MODULE_AUTHOR("Matt Flax <flatmax@flatmax.org>");
5847 +MODULE_DESCRIPTION("AudioInjector.net isolated Soundcard");
5848 +MODULE_LICENSE("GPL v2");
5849 +MODULE_ALIAS("platform:audioinjector-isolated-soundcard");
5851 +++ b/sound/soc/bcm/audioinjector-octo-soundcard.c
5854 + * ASoC Driver for AudioInjector Pi octo channel soundcard (hat)
5856 + * Created on: 27-October-2016
5857 + * Author: flatmax@flatmax.org
5858 + * based on audioinjector-pi-soundcard.c
5860 + * Copyright (C) 2016 Flatmax Pty. Ltd.
5862 + * This program is free software; you can redistribute it and/or
5863 + * modify it under the terms of the GNU General Public License
5864 + * version 2 as published by the Free Software Foundation.
5866 + * This program is distributed in the hope that it will be useful, but
5867 + * WITHOUT ANY WARRANTY; without even the implied warranty of
5868 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5869 + * General Public License for more details.
5872 +#include <linux/module.h>
5873 +#include <linux/types.h>
5874 +#include <linux/gpio/consumer.h>
5876 +#include <sound/core.h>
5877 +#include <sound/soc.h>
5878 +#include <sound/pcm_params.h>
5879 +#include <sound/control.h>
5881 +static struct gpio_descs *mult_gpios;
5882 +static struct gpio_desc *codec_rst_gpio;
5883 +static unsigned int audioinjector_octo_rate;
5884 +static bool non_stop_clocks;
5886 +static const unsigned int audioinjector_octo_rates[] = {
5887 + 96000, 48000, 32000, 24000, 16000, 8000, 88200, 44100, 29400, 22050, 14700,
5890 +static struct snd_pcm_hw_constraint_list audioinjector_octo_constraints = {
5891 + .list = audioinjector_octo_rates,
5892 + .count = ARRAY_SIZE(audioinjector_octo_rates),
5895 +static int audioinjector_octo_dai_init(struct snd_soc_pcm_runtime *rtd)
5897 + return snd_soc_dai_set_bclk_ratio(asoc_rtd_to_cpu(rtd, 0), 64);
5900 +static int audioinjector_octo_startup(struct snd_pcm_substream *substream)
5902 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
5903 + asoc_rtd_to_cpu(rtd, 0)->driver->playback.channels_min = 8;
5904 + asoc_rtd_to_cpu(rtd, 0)->driver->playback.channels_max = 8;
5905 + asoc_rtd_to_cpu(rtd, 0)->driver->capture.channels_min = 8;
5906 + asoc_rtd_to_cpu(rtd, 0)->driver->capture.channels_max = 8;
5907 + asoc_rtd_to_codec(rtd, 0)->driver->capture.channels_max = 8;
5909 + snd_pcm_hw_constraint_list(substream->runtime, 0,
5910 + SNDRV_PCM_HW_PARAM_RATE,
5911 + &audioinjector_octo_constraints);
5916 +static void audioinjector_octo_shutdown(struct snd_pcm_substream *substream)
5918 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
5919 + asoc_rtd_to_cpu(rtd, 0)->driver->playback.channels_min = 2;
5920 + asoc_rtd_to_cpu(rtd, 0)->driver->playback.channels_max = 2;
5921 + asoc_rtd_to_cpu(rtd, 0)->driver->capture.channels_min = 2;
5922 + asoc_rtd_to_cpu(rtd, 0)->driver->capture.channels_max = 2;
5923 + asoc_rtd_to_codec(rtd, 0)->driver->capture.channels_max = 6;
5926 +static int audioinjector_octo_hw_params(struct snd_pcm_substream *substream,
5927 + struct snd_pcm_hw_params *params)
5929 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
5931 + // set codec DAI configuration
5932 + int ret = snd_soc_dai_set_fmt(asoc_rtd_to_codec(rtd, 0),
5933 + SND_SOC_DAIFMT_CBS_CFS|SND_SOC_DAIFMT_DSP_A|
5934 + SND_SOC_DAIFMT_NB_NF);
5938 + // set cpu DAI configuration
5939 + ret = snd_soc_dai_set_fmt(asoc_rtd_to_cpu(rtd, 0),
5940 + SND_SOC_DAIFMT_CBM_CFM|SND_SOC_DAIFMT_I2S|
5941 + SND_SOC_DAIFMT_NB_NF);
5945 + audioinjector_octo_rate = params_rate(params);
5947 + // Set the correct sysclock for the codec
5948 + switch (audioinjector_octo_rate) {
5951 + return snd_soc_dai_set_sysclk(asoc_rtd_to_codec(rtd, 0), 0, 49152000,
5955 + return snd_soc_dai_set_sysclk(asoc_rtd_to_codec(rtd, 0), 0, 49152000/2,
5960 + return snd_soc_dai_set_sysclk(asoc_rtd_to_codec(rtd, 0), 0, 49152000/3,
5964 + return snd_soc_dai_set_sysclk(asoc_rtd_to_codec(rtd, 0), 0, 49152000/6,
5969 + return snd_soc_dai_set_sysclk(asoc_rtd_to_codec(rtd, 0), 0, 45185400,
5973 + return snd_soc_dai_set_sysclk(asoc_rtd_to_codec(rtd, 0), 0, 45185400/2,
5978 + return snd_soc_dai_set_sysclk(asoc_rtd_to_codec(rtd, 0), 0, 45185400/3,
5986 +static int audioinjector_octo_trigger(struct snd_pcm_substream *substream,
5988 + DECLARE_BITMAP(mult, 4);
5990 + memset(mult, 0, sizeof(mult));
5993 + case SNDRV_PCM_TRIGGER_STOP:
5994 + case SNDRV_PCM_TRIGGER_SUSPEND:
5995 + case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
5996 + if (!non_stop_clocks)
5999 + case SNDRV_PCM_TRIGGER_START:
6000 + case SNDRV_PCM_TRIGGER_RESUME:
6001 + case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
6002 + switch (audioinjector_octo_rate) {
6004 + __assign_bit(3, mult, 1);
6007 + __assign_bit(1, mult, 1);
6008 + __assign_bit(2, mult, 1);
6011 + __assign_bit(3, mult, 1);
6014 + __assign_bit(2, mult, 1);
6017 + __assign_bit(3, mult, 1);
6020 + __assign_bit(0, mult, 1);
6021 + __assign_bit(1, mult, 1);
6024 + __assign_bit(3, mult, 1);
6027 + __assign_bit(1, mult, 1);
6030 + __assign_bit(3, mult, 1);
6033 + __assign_bit(0, mult, 1);
6036 + __assign_bit(3, mult, 1);
6045 + gpiod_set_array_value_cansleep(mult_gpios->ndescs, mult_gpios->desc,
6051 +static struct snd_soc_ops audioinjector_octo_ops = {
6052 + .startup = audioinjector_octo_startup,
6053 + .shutdown = audioinjector_octo_shutdown,
6054 + .hw_params = audioinjector_octo_hw_params,
6055 + .trigger = audioinjector_octo_trigger,
6058 +SND_SOC_DAILINK_DEFS(audioinjector_octo,
6059 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
6060 + DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "cs42448")),
6061 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
6063 +static struct snd_soc_dai_link audioinjector_octo_dai[] = {
6065 + .name = "AudioInjector Octo",
6066 + .stream_name = "AudioInject-HIFI",
6067 + .ops = &audioinjector_octo_ops,
6068 + .init = audioinjector_octo_dai_init,
6069 + .symmetric_rate = 1,
6070 + .symmetric_channels = 1,
6071 + SND_SOC_DAILINK_REG(audioinjector_octo),
6075 +static const struct snd_soc_dapm_widget audioinjector_octo_widgets[] = {
6076 + SND_SOC_DAPM_OUTPUT("OUTPUTS0"),
6077 + SND_SOC_DAPM_OUTPUT("OUTPUTS1"),
6078 + SND_SOC_DAPM_OUTPUT("OUTPUTS2"),
6079 + SND_SOC_DAPM_OUTPUT("OUTPUTS3"),
6080 + SND_SOC_DAPM_INPUT("INPUTS0"),
6081 + SND_SOC_DAPM_INPUT("INPUTS1"),
6082 + SND_SOC_DAPM_INPUT("INPUTS2"),
6085 +static const struct snd_soc_dapm_route audioinjector_octo_route[] = {
6086 + /* Balanced outputs */
6087 + {"OUTPUTS0", NULL, "AOUT1L"},
6088 + {"OUTPUTS0", NULL, "AOUT1R"},
6089 + {"OUTPUTS1", NULL, "AOUT2L"},
6090 + {"OUTPUTS1", NULL, "AOUT2R"},
6091 + {"OUTPUTS2", NULL, "AOUT3L"},
6092 + {"OUTPUTS2", NULL, "AOUT3R"},
6093 + {"OUTPUTS3", NULL, "AOUT4L"},
6094 + {"OUTPUTS3", NULL, "AOUT4R"},
6096 + /* Balanced inputs */
6097 + {"AIN1L", NULL, "INPUTS0"},
6098 + {"AIN1R", NULL, "INPUTS0"},
6099 + {"AIN2L", NULL, "INPUTS1"},
6100 + {"AIN2R", NULL, "INPUTS1"},
6101 + {"AIN3L", NULL, "INPUTS2"},
6102 + {"AIN3R", NULL, "INPUTS2"},
6105 +static struct snd_soc_card snd_soc_audioinjector_octo = {
6106 + .name = "audioinjector-octo-soundcard",
6107 + .dai_link = audioinjector_octo_dai,
6108 + .num_links = ARRAY_SIZE(audioinjector_octo_dai),
6110 + .dapm_widgets = audioinjector_octo_widgets,
6111 + .num_dapm_widgets = ARRAY_SIZE(audioinjector_octo_widgets),
6112 + .dapm_routes = audioinjector_octo_route,
6113 + .num_dapm_routes = ARRAY_SIZE(audioinjector_octo_route),
6116 +static int audioinjector_octo_probe(struct platform_device *pdev)
6118 + struct snd_soc_card *card = &snd_soc_audioinjector_octo;
6121 + card->dev = &pdev->dev;
6123 + if (pdev->dev.of_node) {
6124 + struct snd_soc_dai_link *dai = &audioinjector_octo_dai[0];
6125 + struct device_node *i2s_node =
6126 + of_parse_phandle(pdev->dev.of_node,
6127 + "i2s-controller", 0);
6128 + struct device_node *codec_node =
6129 + of_parse_phandle(pdev->dev.of_node,
6132 + mult_gpios = devm_gpiod_get_array_optional(&pdev->dev, "mult",
6134 + if (IS_ERR(mult_gpios))
6135 + return PTR_ERR(mult_gpios);
6137 + codec_rst_gpio = devm_gpiod_get_optional(&pdev->dev, "reset",
6139 + if (IS_ERR(codec_rst_gpio))
6140 + return PTR_ERR(codec_rst_gpio);
6142 + non_stop_clocks = of_property_read_bool(pdev->dev.of_node, "non-stop-clocks");
6144 + if (codec_rst_gpio)
6145 + gpiod_set_value(codec_rst_gpio, 1);
6147 + if (codec_rst_gpio)
6148 + gpiod_set_value(codec_rst_gpio, 0);
6150 + if (codec_rst_gpio)
6151 + gpiod_set_value(codec_rst_gpio, 1);
6154 + if (i2s_node && codec_node) {
6155 + dai->cpus->dai_name = NULL;
6156 + dai->cpus->of_node = i2s_node;
6157 + dai->platforms->name = NULL;
6158 + dai->platforms->of_node = i2s_node;
6159 + dai->codecs->name = NULL;
6160 + dai->codecs->of_node = codec_node;
6163 + dev_err(&pdev->dev,
6164 + "i2s-controller missing or invalid in DT\n");
6167 + dev_err(&pdev->dev,
6168 + "Property 'codec' missing or invalid\n");
6173 + ret = devm_snd_soc_register_card(&pdev->dev, card);
6175 + dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret);
6179 +static const struct of_device_id audioinjector_octo_of_match[] = {
6180 + { .compatible = "ai,audioinjector-octo-soundcard", },
6183 +MODULE_DEVICE_TABLE(of, audioinjector_octo_of_match);
6185 +static struct platform_driver audioinjector_octo_driver = {
6187 + .name = "audioinjector-octo",
6188 + .owner = THIS_MODULE,
6189 + .of_match_table = audioinjector_octo_of_match,
6191 + .probe = audioinjector_octo_probe,
6194 +module_platform_driver(audioinjector_octo_driver);
6195 +MODULE_AUTHOR("Matt Flax <flatmax@flatmax.org>");
6196 +MODULE_DESCRIPTION("AudioInjector.net octo Soundcard");
6197 +MODULE_LICENSE("GPL v2");
6198 +MODULE_ALIAS("platform:audioinjector-octo-soundcard");
6200 +++ b/sound/soc/bcm/audioinjector-pi-soundcard.c
6203 + * ASoC Driver for AudioInjector Pi add on soundcard
6205 + * Created on: 13-May-2016
6206 + * Author: flatmax@flatmax.org
6207 + * based on code by Cliff Cai <Cliff.Cai@analog.com> for the ssm2602 machine blackfin.
6208 + * with help from Lars-Peter Clausen for simplifying the original code to use the dai_fmt field.
6209 + * i2s_node code taken from the other sound/soc/bcm machine drivers.
6211 + * Copyright (C) 2016 Flatmax Pty. Ltd.
6213 + * This program is free software; you can redistribute it and/or
6214 + * modify it under the terms of the GNU General Public License
6215 + * version 2 as published by the Free Software Foundation.
6217 + * This program is distributed in the hope that it will be useful, but
6218 + * WITHOUT ANY WARRANTY; without even the implied warranty of
6219 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6220 + * General Public License for more details.
6223 +#include <linux/module.h>
6224 +#include <linux/types.h>
6226 +#include <sound/core.h>
6227 +#include <sound/soc.h>
6228 +#include <sound/pcm_params.h>
6229 +#include <sound/control.h>
6231 +#include "../codecs/wm8731.h"
6233 +static const unsigned int bcm2835_rates_12000000[] = {
6234 + 8000, 16000, 32000, 44100, 48000, 96000, 88200,
6237 +static struct snd_pcm_hw_constraint_list bcm2835_constraints_12000000 = {
6238 + .list = bcm2835_rates_12000000,
6239 + .count = ARRAY_SIZE(bcm2835_rates_12000000),
6242 +static int snd_audioinjector_pi_soundcard_startup(struct snd_pcm_substream *substream)
6244 + /* Setup constraints, because there is a 12 MHz XTAL on the board */
6245 + snd_pcm_hw_constraint_list(substream->runtime, 0,
6246 + SNDRV_PCM_HW_PARAM_RATE,
6247 + &bcm2835_constraints_12000000);
6251 +static int snd_audioinjector_pi_soundcard_hw_params(struct snd_pcm_substream *substream,
6252 + struct snd_pcm_hw_params *params)
6254 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
6255 + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
6257 + switch (params_rate(params)){
6259 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 1);
6261 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 750);
6263 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 375);
6265 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 272);
6267 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 250);
6269 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 136);
6271 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 125);
6273 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 125);
6277 +/* machine stream operations */
6278 +static struct snd_soc_ops snd_audioinjector_pi_soundcard_ops = {
6279 + .startup = snd_audioinjector_pi_soundcard_startup,
6280 + .hw_params = snd_audioinjector_pi_soundcard_hw_params,
6283 +static int audioinjector_pi_soundcard_dai_init(struct snd_soc_pcm_runtime *rtd)
6285 + return snd_soc_dai_set_sysclk(asoc_rtd_to_codec(rtd, 0), WM8731_SYSCLK_XTAL, 12000000, SND_SOC_CLOCK_IN);
6288 +SND_SOC_DAILINK_DEFS(audioinjector_pi,
6289 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
6290 + DAILINK_COMP_ARRAY(COMP_CODEC("wm8731.1-001a", "wm8731-hifi")),
6291 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2835-i2s.0")));
6293 +static struct snd_soc_dai_link audioinjector_pi_soundcard_dai[] = {
6295 + .name = "AudioInjector audio",
6296 + .stream_name = "AudioInjector audio",
6297 + .ops = &snd_audioinjector_pi_soundcard_ops,
6298 + .init = audioinjector_pi_soundcard_dai_init,
6299 + .dai_fmt = SND_SOC_DAIFMT_CBM_CFM|SND_SOC_DAIFMT_I2S|SND_SOC_DAIFMT_NB_NF,
6300 + SND_SOC_DAILINK_REG(audioinjector_pi),
6304 +static const struct snd_soc_dapm_widget wm8731_dapm_widgets[] = {
6305 + SND_SOC_DAPM_HP("Headphone Jack", NULL),
6306 + SND_SOC_DAPM_SPK("Ext Spk", NULL),
6307 + SND_SOC_DAPM_LINE("Line In Jacks", NULL),
6308 + SND_SOC_DAPM_MIC("Microphone", NULL),
6311 +static const struct snd_soc_dapm_route audioinjector_audio_map[] = {
6312 + /* headphone connected to LHPOUT, RHPOUT */
6313 + {"Headphone Jack", NULL, "LHPOUT"},
6314 + {"Headphone Jack", NULL, "RHPOUT"},
6316 + /* speaker connected to LOUT, ROUT */
6317 + {"Ext Spk", NULL, "ROUT"},
6318 + {"Ext Spk", NULL, "LOUT"},
6321 + {"Line In Jacks", NULL, "Line Input"},
6323 + /* mic is connected to Mic Jack, with WM8731 Mic Bias */
6324 + {"Microphone", NULL, "Mic Bias"},
6327 +static struct snd_soc_card snd_soc_audioinjector = {
6328 + .name = "audioinjector-pi-soundcard",
6329 + .dai_link = audioinjector_pi_soundcard_dai,
6330 + .num_links = ARRAY_SIZE(audioinjector_pi_soundcard_dai),
6332 + .dapm_widgets = wm8731_dapm_widgets,
6333 + .num_dapm_widgets = ARRAY_SIZE(wm8731_dapm_widgets),
6334 + .dapm_routes = audioinjector_audio_map,
6335 + .num_dapm_routes = ARRAY_SIZE(audioinjector_audio_map),
6338 +static int audioinjector_pi_soundcard_probe(struct platform_device *pdev)
6340 + struct snd_soc_card *card = &snd_soc_audioinjector;
6343 + card->dev = &pdev->dev;
6345 + if (pdev->dev.of_node) {
6346 + struct snd_soc_dai_link *dai = &audioinjector_pi_soundcard_dai[0];
6347 + struct device_node *i2s_node = of_parse_phandle(pdev->dev.of_node,
6348 + "i2s-controller", 0);
6351 + dai->cpus->dai_name = NULL;
6352 + dai->cpus->of_node = i2s_node;
6353 + dai->platforms->name = NULL;
6354 + dai->platforms->of_node = i2s_node;
6356 + if (!dai->cpus->of_node) {
6357 + dev_err(&pdev->dev, "Property 'i2s-controller' missing or invalid\n");
6362 + if ((ret = devm_snd_soc_register_card(&pdev->dev, card)))
6363 + return dev_err_probe(&pdev->dev, ret, "%s\n", __func__);
6365 + dev_info(&pdev->dev, "successfully loaded\n");
6370 +static const struct of_device_id audioinjector_pi_soundcard_of_match[] = {
6371 + { .compatible = "ai,audioinjector-pi-soundcard", },
6374 +MODULE_DEVICE_TABLE(of, audioinjector_pi_soundcard_of_match);
6376 +static struct platform_driver audioinjector_pi_soundcard_driver = {
6378 + .name = "audioinjector-stereo",
6379 + .owner = THIS_MODULE,
6380 + .of_match_table = audioinjector_pi_soundcard_of_match,
6382 + .probe = audioinjector_pi_soundcard_probe,
6385 +module_platform_driver(audioinjector_pi_soundcard_driver);
6386 +MODULE_AUTHOR("Matt Flax <flatmax@flatmax.org>");
6387 +MODULE_DESCRIPTION("AudioInjector.net Pi Soundcard");
6388 +MODULE_LICENSE("GPL v2");
6389 +MODULE_ALIAS("platform:audioinjector-pi-soundcard");
6392 +++ b/sound/soc/bcm/audiosense-pi.c
6395 + * ASoC Driver for AudioSense add on soundcard
6397 + * Bhargav A K <anur.bhargav@gmail.com>
6400 + * This program is free software; you can redistribute it and/or
6401 + * modify it under the terms of the GNU General Public License
6402 + * version 2 as published by the Free Software Foundation.
6404 + * This program is distributed in the hope that it will be useful, but
6405 + * WITHOUT ANY WARRANTY; without even the implied warranty of
6406 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6407 + * General Public License for more details.
6410 +#include <linux/module.h>
6411 +#include <linux/platform_device.h>
6412 +#include <linux/clk.h>
6413 +#include <linux/i2c.h>
6414 +#include <sound/core.h>
6415 +#include <sound/pcm.h>
6416 +#include <sound/pcm_params.h>
6417 +#include <sound/soc.h>
6418 +#include <sound/jack.h>
6419 +#include <sound/control.h>
6421 +#include <sound/tlv320aic32x4.h>
6422 +#include "../codecs/tlv320aic32x4.h"
6424 +#define AIC32X4_SYSCLK_XTAL 0x00
6427 + * Setup Codec Sample Rates and Channels
6428 + * Supported Rates:
6429 + * 8000, 11025, 16000, 22050, 32000, 44100, 48000, 64000, 88200, 96000,
6431 +static const unsigned int audiosense_pi_rate[] = {
6435 +static struct snd_pcm_hw_constraint_list audiosense_constraints_rates = {
6436 + .list = audiosense_pi_rate,
6437 + .count = ARRAY_SIZE(audiosense_pi_rate),
6440 +static const unsigned int audiosense_pi_channels[] = {
6444 +static struct snd_pcm_hw_constraint_list audiosense_constraints_ch = {
6445 + .count = ARRAY_SIZE(audiosense_pi_channels),
6446 + .list = audiosense_pi_channels,
6450 +/* Setup DAPM widgets and paths */
6451 +static const struct snd_soc_dapm_widget audiosense_pi_dapm_widgets[] = {
6452 + SND_SOC_DAPM_HP("Headphone Jack", NULL),
6453 + SND_SOC_DAPM_LINE("Line Out", NULL),
6454 + SND_SOC_DAPM_LINE("Line In", NULL),
6455 + SND_SOC_DAPM_INPUT("CM_L"),
6456 + SND_SOC_DAPM_INPUT("CM_R"),
6459 +static const struct snd_soc_dapm_route audiosense_pi_audio_map[] = {
6460 + /* Line Inputs are connected to
6465 + {"IN1_L", NULL, "Line In"},
6466 + {"IN1_R", NULL, "Line In"},
6467 + {"IN2_L", NULL, "Line In"},
6468 + {"IN2_R", NULL, "Line In"},
6469 + {"IN3_L", NULL, "Line In"},
6470 + {"IN3_R", NULL, "Line In"},
6472 + /* Mic is connected to IN2_L and IN2_R */
6473 + {"Left ADC", NULL, "Mic Bias"},
6474 + {"Right ADC", NULL, "Mic Bias"},
6476 + /* Headphone connected to HPL, HPR */
6477 + {"Headphone Jack", NULL, "HPL"},
6478 + {"Headphone Jack", NULL, "HPR"},
6480 + /* Speakers connected to LOL and LOR */
6481 + {"Line Out", NULL, "LOL"},
6482 + {"Line Out", NULL, "LOR"},
6485 +static int audiosense_pi_card_init(struct snd_soc_pcm_runtime *rtd)
6487 + /* TODO: init of the codec specific dapm data, ignore suspend/resume */
6488 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
6490 + snd_soc_component_update_bits(component, AIC32X4_MICBIAS, 0x78,
6491 + AIC32X4_MICBIAS_LDOIN |
6492 + AIC32X4_MICBIAS_2075V);
6493 + snd_soc_component_update_bits(component, AIC32X4_PWRCFG, 0x08,
6494 + AIC32X4_AVDDWEAKDISABLE);
6495 + snd_soc_component_update_bits(component, AIC32X4_LDOCTL, 0x01,
6496 + AIC32X4_LDOCTLEN);
6501 +static int audiosense_pi_card_hw_params(
6502 + struct snd_pcm_substream *substream,
6503 + struct snd_pcm_hw_params *params)
6506 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
6507 + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
6509 + /* Set the codec system clock, there is a 12 MHz XTAL on the board */
6510 + ret = snd_soc_dai_set_sysclk(codec_dai, AIC32X4_SYSCLK_XTAL,
6511 + 12000000, SND_SOC_CLOCK_IN);
6513 + dev_err(rtd->card->dev,
6514 + "could not set codec driver clock params\n");
6520 +static int audiosense_pi_card_startup(struct snd_pcm_substream *substream)
6522 + struct snd_pcm_runtime *runtime = substream->runtime;
6525 + * Set codec to 48Khz Sampling, Stereo I/O and 16 bit audio
6527 + runtime->hw.channels_max = 2;
6528 + snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
6529 + &audiosense_constraints_ch);
6531 + runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE;
6532 + snd_pcm_hw_constraint_msbits(runtime, 0, 16, 16);
6535 + snd_pcm_hw_constraint_list(substream->runtime, 0,
6536 + SNDRV_PCM_HW_PARAM_RATE,
6537 + &audiosense_constraints_rates);
6541 +static struct snd_soc_ops audiosense_pi_card_ops = {
6542 + .startup = audiosense_pi_card_startup,
6543 + .hw_params = audiosense_pi_card_hw_params,
6546 +SND_SOC_DAILINK_DEFS(audiosense_pi,
6547 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
6548 + DAILINK_COMP_ARRAY(COMP_CODEC("tlv320aic32x4.1-0018", "tlv320aic32x4-hifi")),
6549 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
6551 +static struct snd_soc_dai_link audiosense_pi_card_dai[] = {
6553 + .name = "TLV320AIC3204 Audio",
6554 + .stream_name = "TLV320AIC3204 Hifi Audio",
6555 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
6556 + SND_SOC_DAIFMT_CBM_CFM,
6557 + .ops = &audiosense_pi_card_ops,
6558 + .init = audiosense_pi_card_init,
6559 + SND_SOC_DAILINK_REG(audiosense_pi),
6563 +static struct snd_soc_card audiosense_pi_card = {
6564 + .name = "audiosense-pi",
6565 + .driver_name = "audiosense-pi",
6566 + .dai_link = audiosense_pi_card_dai,
6567 + .owner = THIS_MODULE,
6568 + .num_links = ARRAY_SIZE(audiosense_pi_card_dai),
6569 + .dapm_widgets = audiosense_pi_dapm_widgets,
6570 + .num_dapm_widgets = ARRAY_SIZE(audiosense_pi_dapm_widgets),
6571 + .dapm_routes = audiosense_pi_audio_map,
6572 + .num_dapm_routes = ARRAY_SIZE(audiosense_pi_audio_map),
6575 +static int audiosense_pi_card_probe(struct platform_device *pdev)
6578 + struct snd_soc_card *card = &audiosense_pi_card;
6579 + struct snd_soc_dai_link *dai = &audiosense_pi_card_dai[0];
6580 + struct device_node *i2s_node = pdev->dev.of_node;
6582 + card->dev = &pdev->dev;
6585 + dev_err(&pdev->dev, "DAI not found. Missing or Invalid\n");
6589 + i2s_node = of_parse_phandle(pdev->dev.of_node, "i2s-controller", 0);
6591 + dev_err(&pdev->dev,
6592 + "Property 'i2s-controller' missing or invalid\n");
6596 + dai->cpus->dai_name = NULL;
6597 + dai->cpus->of_node = i2s_node;
6598 + dai->platforms->name = NULL;
6599 + dai->platforms->of_node = i2s_node;
6601 + of_node_put(i2s_node);
6603 + ret = snd_soc_register_card(card);
6604 + if (ret && ret != -EPROBE_DEFER)
6605 + dev_err(&pdev->dev,
6606 + "snd_soc_register_card() failed: %d\n", ret);
6611 +static int audiosense_pi_card_remove(struct platform_device *pdev)
6613 + struct snd_soc_card *card = platform_get_drvdata(pdev);
6615 + snd_soc_unregister_card(card);
6619 +static const struct of_device_id audiosense_pi_card_of_match[] = {
6620 + { .compatible = "as,audiosense-pi", },
6623 +MODULE_DEVICE_TABLE(of, audiosense_pi_card_of_match);
6625 +static struct platform_driver audiosense_pi_card_driver = {
6627 + .name = "audiosense-snd-card",
6628 + .owner = THIS_MODULE,
6629 + .of_match_table = audiosense_pi_card_of_match,
6631 + .probe = audiosense_pi_card_probe,
6632 + .remove = audiosense_pi_card_remove,
6635 +module_platform_driver(audiosense_pi_card_driver);
6637 +MODULE_AUTHOR("Bhargav AK <anur.bhargav@gmail.com>");
6638 +MODULE_DESCRIPTION("ASoC Driver for TLV320AIC3204 Audio");
6639 +MODULE_LICENSE("GPL v2");
6640 +MODULE_ALIAS("platform:audiosense-pi");
6642 --- a/sound/soc/bcm/bcm2835-i2s.c
6643 +++ b/sound/soc/bcm/bcm2835-i2s.c
6645 #include <linux/init.h>
6646 #include <linux/io.h>
6647 #include <linux/module.h>
6648 -#include <linux/of_address.h>
6649 #include <linux/slab.h>
6651 #include <sound/core.h>
6652 @@ -830,8 +829,7 @@ static int bcm2835_i2s_probe(struct plat
6653 struct bcm2835_i2s_dev *dev;
6656 - const __be32 *addr;
6657 - dma_addr_t dma_base;
6658 + struct resource *res;
6660 dev = devm_kzalloc(&pdev->dev, sizeof(*dev),
6662 @@ -846,7 +844,7 @@ static int bcm2835_i2s_probe(struct plat
6663 "could not get clk\n");
6665 /* Request ioarea */
6666 - base = devm_platform_ioremap_resource(pdev, 0);
6667 + base = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
6669 return PTR_ERR(base);
6671 @@ -855,19 +853,11 @@ static int bcm2835_i2s_probe(struct plat
6672 if (IS_ERR(dev->i2s_regmap))
6673 return PTR_ERR(dev->i2s_regmap);
6675 - /* Set the DMA address - we have to parse DT ourselves */
6676 - addr = of_get_address(pdev->dev.of_node, 0, NULL, NULL);
6678 - dev_err(&pdev->dev, "could not get DMA-register address\n");
6681 - dma_base = be32_to_cpup(addr);
6683 dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK].addr =
6684 - dma_base + BCM2835_I2S_FIFO_A_REG;
6685 + res->start + BCM2835_I2S_FIFO_A_REG;
6687 dev->dma_data[SNDRV_PCM_STREAM_CAPTURE].addr =
6688 - dma_base + BCM2835_I2S_FIFO_A_REG;
6689 + res->start + BCM2835_I2S_FIFO_A_REG;
6691 /* Set the bus width */
6692 dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK].addr_width =
6694 +++ b/sound/soc/bcm/chipdip-dac.c
6697 + * ASoC Driver for ChipDip DAC
6699 + * Author: Evgenij Sapunov
6701 + * based on code by Milan Neskovic <info@justboom.co>
6702 + * based on code by Jaikumar <jaikumar@cem-solutions.net>
6704 + * Thanks to Phil Elwell (pelwell) for help.
6706 + * This program is free software; you can redistribute it and/or
6707 + * modify it under the terms of the GNU General Public License
6708 + * version 2 as published by the Free Software Foundation.
6710 + * This program is distributed in the hope that it will be useful, but
6711 + * WITHOUT ANY WARRANTY; without even the implied warranty of
6712 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6713 + * General Public License for more details.
6716 +#include <linux/module.h>
6717 +#include <linux/gpio/consumer.h>
6718 +#include <linux/platform_device.h>
6719 +#include <linux/delay.h>
6721 +#include <sound/core.h>
6722 +#include <sound/pcm.h>
6723 +#include <sound/pcm_params.h>
6724 +#include <sound/soc.h>
6725 +#include <sound/jack.h>
6727 +#define SR_BIT_0 0 //sample rate bits
6730 +#define BD_BIT_0 3 //bit depth bits
6733 +#define SAMPLE_RATE_MASK_44_1 0
6734 +#define SAMPLE_RATE_MASK_48 (1 << SR_BIT_0)
6735 +#define SAMPLE_RATE_MASK_88_2 ((1 << SR_BIT_2) | (1 << SR_BIT_1))
6736 +#define SAMPLE_RATE_MASK_96 (1 << SR_BIT_1)
6737 +#define SAMPLE_RATE_MASK_176_4 ((1 << SR_BIT_2) | (1 << SR_BIT_1) | (1 << SR_BIT_0))
6738 +#define SAMPLE_RATE_MASK_192 ((1 << SR_BIT_1) | (1 << SR_BIT_0))
6739 +#define SAMPLE_RATE_MASK ((1 << SR_BIT_2) | (1 << SR_BIT_1) | (1 << SR_BIT_0))
6741 +#define BIT_DEPTH_MASK_16 0
6742 +#define BIT_DEPTH_MASK_24 (1 << BD_BIT_0)
6743 +#define BIT_DEPTH_MASK_32 (1 << BD_BIT_1)
6744 +#define BIT_DEPTH_MASK ((1 << BD_BIT_1) | (1 << BD_BIT_0))
6746 +#define MUTE_ACTIVE 0
6747 +#define MUTE_NOT_ACTIVE 1
6749 +#define HW_PARAMS_GPIO_COUNT 5
6751 +static struct gpio_desc *mute_gpio;
6752 +static struct gpio_desc *sdwn_gpio;
6753 +static struct gpio_desc *hw_params_gpios[HW_PARAMS_GPIO_COUNT];
6754 +static int current_width;
6755 +static int current_rate;
6757 +static void snd_rpi_chipdip_dac_gpio_array_set(int value);
6758 +static void snd_rpi_chipdip_dac_gpio_set(struct gpio_desc *gpio_item, int value);
6760 +static void snd_rpi_chipdip_dac_gpio_array_set(int value)
6764 + for (i = 0; i < HW_PARAMS_GPIO_COUNT; i++)
6765 + snd_rpi_chipdip_dac_gpio_set(hw_params_gpios[i], ((value >> i) & 1));
6768 +static void snd_rpi_chipdip_dac_gpio_set(struct gpio_desc *gpio_item, int value)
6771 + gpiod_set_value_cansleep(gpio_item, value);
6774 +static int snd_rpi_chipdip_dac_init(struct snd_soc_pcm_runtime *rtd)
6779 +static int snd_rpi_chipdip_dac_hw_params(struct snd_pcm_substream *substream,
6780 + struct snd_pcm_hw_params *params)
6783 + int gpio_change_pending = 0;
6784 + int sample_rate_state = 0;
6785 + int bit_depth_state = 0;
6786 + int param_value = params_width(params);
6787 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
6789 + ret = snd_soc_dai_set_bclk_ratio(asoc_rtd_to_cpu(rtd, 0), 2 * 32);
6791 + if (current_width != param_value) {
6792 + current_width = param_value;
6793 + gpio_change_pending = 1;
6795 + switch (param_value) {
6797 + bit_depth_state = BIT_DEPTH_MASK_16;
6800 + bit_depth_state = BIT_DEPTH_MASK_24;
6803 + bit_depth_state = BIT_DEPTH_MASK_32;
6810 + param_value = params_rate(params);
6811 + if (current_rate != param_value) {
6812 + current_rate = param_value;
6813 + gpio_change_pending = 1;
6815 + switch (param_value) {
6817 + sample_rate_state = SAMPLE_RATE_MASK_44_1;
6820 + sample_rate_state = SAMPLE_RATE_MASK_48;
6823 + sample_rate_state = SAMPLE_RATE_MASK_88_2;
6826 + sample_rate_state = SAMPLE_RATE_MASK_96;
6829 + sample_rate_state = SAMPLE_RATE_MASK_176_4;
6832 + sample_rate_state = SAMPLE_RATE_MASK_192;
6839 + if (gpio_change_pending) {
6840 + snd_rpi_chipdip_dac_gpio_set(mute_gpio, MUTE_ACTIVE);
6841 + snd_rpi_chipdip_dac_gpio_array_set(bit_depth_state | sample_rate_state);
6843 + snd_rpi_chipdip_dac_gpio_set(mute_gpio, MUTE_NOT_ACTIVE);
6849 +static int snd_rpi_chipdip_dac_startup(struct snd_pcm_substream *substream)
6854 +static void snd_rpi_chipdip_dac_shutdown(struct snd_pcm_substream *substream)
6859 +/* machine stream operations */
6860 +static struct snd_soc_ops snd_rpi_chipdip_dac_ops = {
6861 + .hw_params = snd_rpi_chipdip_dac_hw_params,
6862 + .startup = snd_rpi_chipdip_dac_startup,
6863 + .shutdown = snd_rpi_chipdip_dac_shutdown,
6866 +SND_SOC_DAILINK_DEFS(hifi,
6867 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
6868 + DAILINK_COMP_ARRAY(COMP_CODEC("spdif-transmitter", "dit-hifi")),
6869 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
6871 +static struct snd_soc_dai_link snd_rpi_chipdip_dac_dai[] = {
6873 + .name = "ChipDip DAC",
6874 + .stream_name = "ChipDip DAC HiFi",
6875 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
6876 + SND_SOC_DAIFMT_CBM_CFM,
6877 + .ops = &snd_rpi_chipdip_dac_ops,
6878 + .init = snd_rpi_chipdip_dac_init,
6879 + SND_SOC_DAILINK_REG(hifi),
6883 +/* audio machine driver */
6884 +static struct snd_soc_card snd_rpi_chipdip_dac = {
6885 + .name = "ChipDipDAC",
6886 + .driver_name = "ChipdipDac",
6887 + .owner = THIS_MODULE,
6888 + .dai_link = snd_rpi_chipdip_dac_dai,
6889 + .num_links = ARRAY_SIZE(snd_rpi_chipdip_dac_dai),
6892 +static int snd_rpi_chipdip_dac_probe(struct platform_device *pdev)
6897 + snd_rpi_chipdip_dac.dev = &pdev->dev;
6899 + if (pdev->dev.of_node) {
6900 + struct device_node *i2s_node;
6901 + struct snd_soc_dai_link *dai = &snd_rpi_chipdip_dac_dai[0];
6902 + i2s_node = of_parse_phandle(pdev->dev.of_node,
6903 + "i2s-controller", 0);
6906 + dai->cpus->dai_name = NULL;
6907 + dai->cpus->of_node = i2s_node;
6908 + dai->platforms->name = NULL;
6909 + dai->platforms->of_node = i2s_node;
6913 + hw_params_gpios[SR_BIT_0] = devm_gpiod_get_optional(&pdev->dev, "sr0", GPIOD_OUT_LOW);
6914 + hw_params_gpios[SR_BIT_1] = devm_gpiod_get_optional(&pdev->dev, "sr1", GPIOD_OUT_LOW);
6915 + hw_params_gpios[SR_BIT_2] = devm_gpiod_get_optional(&pdev->dev, "sr2", GPIOD_OUT_LOW);
6916 + hw_params_gpios[BD_BIT_0] = devm_gpiod_get_optional(&pdev->dev, "res0", GPIOD_OUT_LOW);
6917 + hw_params_gpios[BD_BIT_1] = devm_gpiod_get_optional(&pdev->dev, "res1", GPIOD_OUT_LOW);
6918 + mute_gpio = devm_gpiod_get_optional(&pdev->dev, "mute", GPIOD_OUT_LOW);
6919 + sdwn_gpio = devm_gpiod_get_optional(&pdev->dev, "sdwn", GPIOD_OUT_HIGH);
6921 + for (i = 0; i < HW_PARAMS_GPIO_COUNT; i++) {
6922 + if (IS_ERR(hw_params_gpios[i])) {
6923 + ret = PTR_ERR(hw_params_gpios[i]);
6924 + dev_err(&pdev->dev, "failed to get hw_params gpio: %d\n", ret);
6929 + if (IS_ERR(mute_gpio)) {
6930 + ret = PTR_ERR(mute_gpio);
6931 + dev_err(&pdev->dev, "failed to get mute gpio: %d\n", ret);
6935 + if (IS_ERR(sdwn_gpio)) {
6936 + ret = PTR_ERR(sdwn_gpio);
6937 + dev_err(&pdev->dev, "failed to get sdwn gpio: %d\n", ret);
6941 + snd_rpi_chipdip_dac_gpio_set(sdwn_gpio, 1);
6943 + ret = devm_snd_soc_register_card(&pdev->dev, &snd_rpi_chipdip_dac);
6944 + if (ret && ret != -EPROBE_DEFER)
6945 + dev_err(&pdev->dev,
6946 + "snd_soc_register_card() failed: %d\n", ret);
6951 +static const struct of_device_id snd_rpi_chipdip_dac_of_match[] = {
6952 + { .compatible = "chipdip,chipdip-dac", },
6955 +MODULE_DEVICE_TABLE(of, snd_rpi_chipdip_dac_of_match);
6957 +static struct platform_driver snd_rpi_chipdip_dac_driver = {
6959 + .name = "snd-rpi-chipdip-dac",
6960 + .owner = THIS_MODULE,
6961 + .of_match_table = snd_rpi_chipdip_dac_of_match,
6963 + .probe = snd_rpi_chipdip_dac_probe,
6966 +module_platform_driver(snd_rpi_chipdip_dac_driver);
6968 +MODULE_AUTHOR("Evgenij Sapunov <evgenij.sapunov@chipdip.ru>");
6969 +MODULE_DESCRIPTION("ASoC Driver for ChipDip DAC");
6970 +MODULE_LICENSE("GPL v2");
6972 +++ b/sound/soc/bcm/dacberry400.c
6975 + * ASoC Driver for Dacberry400 soundcard
6977 + * Ashish Vara<ashishhvara@gmail.com>
6980 + * This program is free software; you can redistribute it and/or
6981 + * modify it under the terms of the GNU General Public License
6982 + * version 2 as published by the Free Software Foundation.
6984 + * This program is distributed in the hope that it will be useful, but
6985 + * WITHOUT ANY WARRANTY; without even the implied warranty of
6986 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6987 + * General Public License for more details.
6990 +#include <linux/module.h>
6991 +#include <linux/gpio/consumer.h>
6992 +#include <linux/platform_device.h>
6993 +#include <sound/core.h>
6994 +#include <sound/pcm.h>
6995 +#include <sound/pcm_params.h>
6996 +#include <sound/soc.h>
6997 +#include <sound/jack.h>
6998 +#include <linux/i2c.h>
6999 +#include <linux/acpi.h>
7000 +#include <linux/slab.h>
7001 +#include "../sound/soc/codecs/tlv320aic3x.h"
7003 +static const struct snd_kcontrol_new dacberry400_controls[] = {
7004 + SOC_DAPM_PIN_SWITCH("MIC Jack"),
7005 + SOC_DAPM_PIN_SWITCH("Line In"),
7006 + SOC_DAPM_PIN_SWITCH("Line Out"),
7007 + SOC_DAPM_PIN_SWITCH("Headphone Jack"),
7010 +static const struct snd_soc_dapm_widget dacberry400_widgets[] = {
7011 + SND_SOC_DAPM_HP("Headphone Jack", NULL),
7012 + SND_SOC_DAPM_MIC("MIC Jack", NULL),
7013 + SND_SOC_DAPM_LINE("Line In", NULL),
7014 + SND_SOC_DAPM_LINE("Line Out", NULL),
7017 +static const struct snd_soc_dapm_route dacberry400_audio_map[] = {
7018 + {"Headphone Jack", NULL, "HPLOUT"},
7019 + {"Headphone Jack", NULL, "HPROUT"},
7021 + {"LINE1L", NULL, "Line In"},
7022 + {"LINE1R", NULL, "Line In"},
7024 + {"Line Out", NULL, "LLOUT"},
7025 + {"Line Out", NULL, "RLOUT"},
7027 + {"MIC3L", NULL, "MIC Jack"},
7028 + {"MIC3R", NULL, "MIC Jack"},
7031 +static int snd_rpi_dacberry400_init(struct snd_soc_pcm_runtime *rtd)
7033 + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
7034 + struct snd_soc_component *component = codec_dai->component;
7037 + ret = snd_soc_dai_set_sysclk(codec_dai, 2, 12000000,
7038 + SND_SOC_CLOCK_OUT);
7040 + if (ret && ret != -ENOTSUPP)
7043 + snd_soc_component_write(component, HPRCOM_CFG, 0x20);
7044 + snd_soc_component_write(component, DACL1_2_HPLOUT_VOL, 0x80);
7045 + snd_soc_component_write(component, DACR1_2_HPROUT_VOL, 0x80);
7050 +static int snd_rpi_dacberry400_set_bias_level(struct snd_soc_card *card,
7051 + struct snd_soc_dapm_context *dapm, enum snd_soc_bias_level level)
7053 + struct snd_soc_pcm_runtime *rtd;
7054 + struct snd_soc_dai *codec_dai;
7055 + struct snd_soc_component *component;
7056 + struct dacberry_priv *aic3x;
7059 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
7060 + codec_dai = asoc_rtd_to_codec(rtd, 0);
7061 + component = codec_dai->component;
7062 + aic3x = snd_soc_component_get_drvdata(component);
7063 + if (dapm->dev != codec_dai->dev)
7067 + case SND_SOC_BIAS_PREPARE:
7068 + if (dapm->bias_level != SND_SOC_BIAS_STANDBY)
7070 + /* UNMUTE ADC/DAC */
7071 + hpcom_reg = snd_soc_component_read(component, HPLCOM_CFG);
7072 + snd_soc_component_write(component, HPLCOM_CFG, hpcom_reg | 0x20);
7073 + snd_soc_component_write(component, LINE1R_2_RADC_CTRL, 0x04);
7074 + snd_soc_component_write(component, LINE1L_2_LADC_CTRL, 0x04);
7075 + snd_soc_component_write(component, LADC_VOL, 0x00);
7076 + snd_soc_component_write(component, RADC_VOL, 0x00);
7077 + pr_info("%s: unmute ADC/DAC\n", __func__);
7080 + case SND_SOC_BIAS_STANDBY:
7081 + if (dapm->bias_level != SND_SOC_BIAS_PREPARE)
7083 + /* MUTE ADC/DAC */
7084 + snd_soc_component_write(component, LDAC_VOL, 0x80);
7085 + snd_soc_component_write(component, RDAC_VOL, 0x80);
7086 + snd_soc_component_write(component, LADC_VOL, 0x80);
7087 + snd_soc_component_write(component, RADC_VOL, 0x80);
7088 + snd_soc_component_write(component, LINE1R_2_RADC_CTRL, 0x00);
7089 + snd_soc_component_write(component, LINE1L_2_LADC_CTRL, 0x00);
7090 + snd_soc_component_write(component, HPLCOM_CFG, 0x00);
7091 + pr_info("%s: mute ADC/DAC\n", __func__);
7100 +static int snd_rpi_dacberry400_hw_params(struct snd_pcm_substream *substream,
7101 + struct snd_pcm_hw_params *params)
7105 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
7106 + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
7107 + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
7108 + struct snd_soc_component *component = codec_dai->component;
7109 + int fsref = (params_rate(params) % 11025 == 0) ? 44100 : 48000;
7110 + int channels = params_channels(params);
7114 + data = (LDAC2LCH | RDAC2RCH);
7115 + data |= (fsref == 44100) ? FSREF_44100 : FSREF_48000;
7116 + if (params_rate(params) >= 64000)
7117 + data |= DUAL_RATE_MODE;
7118 + ret = snd_soc_component_write(component, 0x7, data);
7119 + width = params_width(params);
7121 + clock = snd_soc_component_read(component, 2);
7123 + ret = snd_soc_dai_set_bclk_ratio(cpu_dai, channels*width);
7128 +static const struct snd_soc_ops snd_rpi_dacberry400_ops = {
7129 + .hw_params = snd_rpi_dacberry400_hw_params,
7133 +SND_SOC_DAILINK_DEFS(rpi_dacberry400,
7134 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2835-i2s.0")),
7135 + DAILINK_COMP_ARRAY(COMP_CODEC("tlv320aic3x.1-0018", "tlv320aic3x-hifi")),
7136 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2835-i2s.0")));
7138 +static struct snd_soc_dai_link snd_rpi_dacberry400_dai[] = {
7140 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
7141 + SND_SOC_DAIFMT_CBS_CFS,
7142 + .init = snd_rpi_dacberry400_init,
7143 + .ops = &snd_rpi_dacberry400_ops,
7144 + .symmetric_rate = 1,
7145 + SND_SOC_DAILINK_REG(rpi_dacberry400),
7149 +static struct snd_soc_card snd_rpi_dacberry400 = {
7150 + .owner = THIS_MODULE,
7151 + .dai_link = snd_rpi_dacberry400_dai,
7152 + .num_links = ARRAY_SIZE(snd_rpi_dacberry400_dai),
7153 + .controls = dacberry400_controls,
7154 + .num_controls = ARRAY_SIZE(dacberry400_controls),
7155 + .dapm_widgets = dacberry400_widgets,
7156 + .num_dapm_widgets = ARRAY_SIZE(dacberry400_widgets),
7157 + .dapm_routes = dacberry400_audio_map,
7158 + .num_dapm_routes = ARRAY_SIZE(dacberry400_audio_map),
7159 + .set_bias_level = snd_rpi_dacberry400_set_bias_level,
7162 +static int snd_rpi_dacberry400_probe(struct platform_device *pdev)
7166 + snd_rpi_dacberry400.dev = &pdev->dev;
7168 + if (pdev->dev.of_node) {
7169 + struct device_node *i2s_node;
7170 + struct snd_soc_card *card = &snd_rpi_dacberry400;
7171 + struct snd_soc_dai_link *dai = &snd_rpi_dacberry400_dai[0];
7173 + i2s_node = of_parse_phandle(pdev->dev.of_node,
7174 + "i2s-controller", 0);
7176 + dai->cpus->dai_name = NULL;
7177 + dai->cpus->of_node = i2s_node;
7178 + dai->platforms->name = NULL;
7179 + dai->platforms->of_node = i2s_node;
7180 + of_node_put(i2s_node);
7183 + if (of_property_read_string(pdev->dev.of_node, "card_name",
7185 + card->name = "tlvaudioCODEC";
7187 + if (of_property_read_string(pdev->dev.of_node, "dai_name",
7189 + dai->name = "tlvaudio CODEC";
7193 + ret = snd_soc_register_card(&snd_rpi_dacberry400);
7195 + if (ret != -EPROBE_DEFER)
7196 + dev_err(&pdev->dev,
7197 + "snd_soc_register_card() failed: %d\n", ret);
7204 +static int snd_rpi_dacberry400_remove(struct platform_device *pdev)
7206 + snd_soc_unregister_card(&snd_rpi_dacberry400);
7210 +static const struct of_device_id dacberry400_match_id[] = {
7211 + { .compatible = "osaelectronics,dacberry400",},
7214 +MODULE_DEVICE_TABLE(of, dacberry400_match_id);
7216 +static struct platform_driver snd_rpi_dacberry400_driver = {
7218 + .name = "snd-rpi-dacberry400",
7219 + .owner = THIS_MODULE,
7220 + .of_match_table = dacberry400_match_id,
7222 + .probe = snd_rpi_dacberry400_probe,
7223 + .remove = snd_rpi_dacberry400_remove,
7226 +module_platform_driver(snd_rpi_dacberry400_driver);
7228 +MODULE_AUTHOR("Ashish Vara");
7229 +MODULE_DESCRIPTION("Dacberry400 sound card driver");
7230 +MODULE_LICENSE("GPL");
7231 +MODULE_ALIAS("platform:dacberry400");
7232 +MODULE_SOFTDEP("pre: snd-soc-tlv320aic3x");
7234 +++ b/sound/soc/bcm/digidac1-soundcard.c
7237 + * ASoC Driver for RRA DigiDAC1
7239 + * Author: José M. Tasende <vintage@redrocksaudio.es>
7240 + * based on the HifiBerry DAC driver by Florian Meier <florian.meier@koalo.de>
7241 + * and the Wolfson card driver by Nikesh Oswal, <Nikesh.Oswal@wolfsonmicro.com>
7242 + * This program is free software; you can redistribute it and/or
7243 + * modify it under the terms of the GNU General Public License
7244 + * version 2 as published by the Free Software Foundation.
7246 + * This program is distributed in the hope that it will be useful, but
7247 + * WITHOUT ANY WARRANTY; without even the implied warranty of
7248 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7249 + * General Public License for more details.
7252 +#include <linux/module.h>
7253 +#include <linux/platform_device.h>
7254 +#include <linux/i2c.h>
7255 +#include <sound/core.h>
7256 +#include <sound/pcm.h>
7257 +#include <sound/pcm_params.h>
7258 +#include <sound/soc.h>
7259 +#include <sound/jack.h>
7260 +#include <sound/soc-dapm.h>
7261 +#include <sound/tlv.h>
7262 +#include <linux/regulator/consumer.h>
7264 +#include "../codecs/wm8804.h"
7265 +#include "../codecs/wm8741.h"
7267 +#define WM8741_NUM_SUPPLIES 2
7269 +/* codec private data */
7270 +struct wm8741_priv {
7271 + struct wm8741_platform_data pdata;
7272 + struct regmap *regmap;
7273 + struct regulator_bulk_data supplies[WM8741_NUM_SUPPLIES];
7274 + unsigned int sysclk;
7275 + const struct snd_pcm_hw_constraint_list *sysclk_constraints;
7278 +static int samplerate = 44100;
7280 +/* New Alsa Controls not exposed by original wm8741 codec driver */
7281 +/* in actual driver the att. adjustment is wrong because */
7282 +/* this DAC has a coarse attenuation register with 4dB steps */
7283 +/* and a fine level register with 0.125dB steps */
7284 +/* each register has 32 steps so combining both we have 1024 steps */
7286 +/* The original level controls from driver are removed at startup */
7287 +/* and replaced by the corrected ones. */
7288 +/* The same wm8741 driver can be used for wm8741 and wm8742 devices */
7290 +static const DECLARE_TLV_DB_SCALE(dac_tlv_fine, 0, 13, 0);
7291 +static const DECLARE_TLV_DB_SCALE(dac_tlv_coarse, -12700, 400, 1);
7292 +static const char *w8741_dither[4] = {"Off", "RPDF", "TPDF", "HPDF"};
7293 +static const char *w8741_filter[5] = {
7294 + "Type 1", "Type 2", "Type 3", "Type 4", "Type 5"};
7295 +static const char *w8741_switch[2] = {"Off", "On"};
7296 +static const struct soc_enum w8741_enum[] = {
7297 +SOC_ENUM_SINGLE(WM8741_MODE_CONTROL_2, 0, 4, w8741_dither),/* dithering type */
7298 +SOC_ENUM_SINGLE(WM8741_FILTER_CONTROL, 0, 5, w8741_filter),/* filter type */
7299 +SOC_ENUM_SINGLE(WM8741_FORMAT_CONTROL, 6, 2, w8741_switch),/* phase invert */
7300 +SOC_ENUM_SINGLE(WM8741_VOLUME_CONTROL, 0, 2, w8741_switch),/* volume ramp */
7301 +SOC_ENUM_SINGLE(WM8741_VOLUME_CONTROL, 3, 2, w8741_switch),/* soft mute */
7304 +static const struct snd_kcontrol_new w8741_snd_controls_stereo[] = {
7305 +SOC_DOUBLE_R_TLV("DAC Fine Playback Volume", WM8741_DACLLSB_ATTENUATION,
7306 + WM8741_DACRLSB_ATTENUATION, 0, 31, 1, dac_tlv_fine),
7307 +SOC_DOUBLE_R_TLV("Digital Playback Volume", WM8741_DACLMSB_ATTENUATION,
7308 + WM8741_DACRMSB_ATTENUATION, 0, 31, 1, dac_tlv_coarse),
7309 +SOC_ENUM("DAC Dither", w8741_enum[0]),
7310 +SOC_ENUM("DAC Digital Filter", w8741_enum[1]),
7311 +SOC_ENUM("DAC Phase Invert", w8741_enum[2]),
7312 +SOC_ENUM("DAC Volume Ramp", w8741_enum[3]),
7313 +SOC_ENUM("DAC Soft Mute", w8741_enum[4]),
7316 +static const struct snd_kcontrol_new w8741_snd_controls_mono_left[] = {
7317 +SOC_SINGLE_TLV("DAC Fine Playback Volume", WM8741_DACLLSB_ATTENUATION,
7318 + 0, 31, 0, dac_tlv_fine),
7319 +SOC_SINGLE_TLV("Digital Playback Volume", WM8741_DACLMSB_ATTENUATION,
7320 + 0, 31, 1, dac_tlv_coarse),
7321 +SOC_ENUM("DAC Dither", w8741_enum[0]),
7322 +SOC_ENUM("DAC Digital Filter", w8741_enum[1]),
7323 +SOC_ENUM("DAC Phase Invert", w8741_enum[2]),
7324 +SOC_ENUM("DAC Volume Ramp", w8741_enum[3]),
7325 +SOC_ENUM("DAC Soft Mute", w8741_enum[4]),
7328 +static const struct snd_kcontrol_new w8741_snd_controls_mono_right[] = {
7329 +SOC_SINGLE_TLV("DAC Fine Playback Volume", WM8741_DACRLSB_ATTENUATION,
7330 + 0, 31, 0, dac_tlv_fine),
7331 +SOC_SINGLE_TLV("Digital Playback Volume", WM8741_DACRMSB_ATTENUATION,
7332 + 0, 31, 1, dac_tlv_coarse),
7333 +SOC_ENUM("DAC Dither", w8741_enum[0]),
7334 +SOC_ENUM("DAC Digital Filter", w8741_enum[1]),
7335 +SOC_ENUM("DAC Phase Invert", w8741_enum[2]),
7336 +SOC_ENUM("DAC Volume Ramp", w8741_enum[3]),
7337 +SOC_ENUM("DAC Soft Mute", w8741_enum[4]),
7340 +static int w8741_add_controls(struct snd_soc_component *component)
7342 + struct wm8741_priv *wm8741 = snd_soc_component_get_drvdata(component);
7344 + switch (wm8741->pdata.diff_mode) {
7345 + case WM8741_DIFF_MODE_STEREO:
7346 + case WM8741_DIFF_MODE_STEREO_REVERSED:
7347 + snd_soc_add_component_controls(component,
7348 + w8741_snd_controls_stereo,
7349 + ARRAY_SIZE(w8741_snd_controls_stereo));
7351 + case WM8741_DIFF_MODE_MONO_LEFT:
7352 + snd_soc_add_component_controls(component,
7353 + w8741_snd_controls_mono_left,
7354 + ARRAY_SIZE(w8741_snd_controls_mono_left));
7356 + case WM8741_DIFF_MODE_MONO_RIGHT:
7357 + snd_soc_add_component_controls(component,
7358 + w8741_snd_controls_mono_right,
7359 + ARRAY_SIZE(w8741_snd_controls_mono_right));
7368 +static int digidac1_soundcard_init(struct snd_soc_pcm_runtime *rtd)
7370 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
7371 + struct snd_soc_card *card = rtd->card;
7372 + struct snd_soc_pcm_runtime *wm8741_rtd;
7373 + struct snd_soc_component *wm8741_component;
7374 + struct snd_card *sound_card = card->snd_card;
7375 + struct snd_kcontrol *kctl;
7378 + wm8741_rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[1]);
7379 + if (!wm8741_rtd) {
7380 + dev_warn(card->dev, "digidac1_soundcard_init: couldn't get wm8741 rtd\n");
7383 + wm8741_component = asoc_rtd_to_codec(wm8741_rtd, 0)->component;
7384 + ret = w8741_add_controls(wm8741_component);
7386 + dev_warn(card->dev, "Failed to add new wm8741 controls: %d\n",
7389 + /* enable TX output */
7390 + snd_soc_component_update_bits(component, WM8804_PWRDN, 0x4, 0x0);
7392 + kctl = snd_soc_card_get_kcontrol(card,
7393 + "Playback Volume");
7395 + kctl->vd[0].access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
7396 + snd_ctl_remove(sound_card, kctl);
7398 + kctl = snd_soc_card_get_kcontrol(card,
7399 + "Fine Playback Volume");
7401 + kctl->vd[0].access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
7402 + snd_ctl_remove(sound_card, kctl);
7407 +static int digidac1_soundcard_startup(struct snd_pcm_substream *substream)
7409 + /* turn on wm8804 digital output */
7410 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
7411 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
7412 + struct snd_soc_card *card = rtd->card;
7413 + struct snd_soc_pcm_runtime *wm8741_rtd;
7414 + struct snd_soc_component *wm8741_component;
7416 + snd_soc_component_update_bits(component, WM8804_PWRDN, 0x3c, 0x00);
7417 + wm8741_rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[1]);
7418 + if (!wm8741_rtd) {
7419 + dev_warn(card->dev, "digidac1_soundcard_startup: couldn't get WM8741 rtd\n");
7422 + wm8741_component = asoc_rtd_to_codec(wm8741_rtd, 0)->component;
7424 + /* latch wm8741 level */
7425 + snd_soc_component_update_bits(wm8741_component, WM8741_DACLLSB_ATTENUATION,
7426 + WM8741_UPDATELL, WM8741_UPDATELL);
7427 + snd_soc_component_update_bits(wm8741_component, WM8741_DACLMSB_ATTENUATION,
7428 + WM8741_UPDATELM, WM8741_UPDATELM);
7429 + snd_soc_component_update_bits(wm8741_component, WM8741_DACRLSB_ATTENUATION,
7430 + WM8741_UPDATERL, WM8741_UPDATERL);
7431 + snd_soc_component_update_bits(wm8741_component, WM8741_DACRMSB_ATTENUATION,
7432 + WM8741_UPDATERM, WM8741_UPDATERM);
7437 +static void digidac1_soundcard_shutdown(struct snd_pcm_substream *substream)
7439 + /* turn off wm8804 digital output */
7440 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
7441 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
7443 + snd_soc_component_update_bits(component, WM8804_PWRDN, 0x3c, 0x3c);
7446 +static int digidac1_soundcard_hw_params(struct snd_pcm_substream *substream,
7447 + struct snd_pcm_hw_params *params)
7449 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
7450 + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
7451 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
7452 + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
7453 + struct snd_soc_card *card = rtd->card;
7454 + struct snd_soc_pcm_runtime *wm8741_rtd;
7455 + struct snd_soc_component *wm8741_component;
7457 + int sysclk = 27000000;
7458 + long mclk_freq = 0;
7460 + int sampling_freq = 1;
7463 + wm8741_rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[1]);
7464 + if (!wm8741_rtd) {
7465 + dev_warn(card->dev, "digidac1_soundcard_hw_params: couldn't get WM8741 rtd\n");
7468 + wm8741_component = asoc_rtd_to_codec(wm8741_rtd, 0)->component;
7469 + samplerate = params_rate(params);
7471 + if (samplerate <= 96000) {
7472 + mclk_freq = samplerate*256;
7473 + mclk_div = WM8804_MCLKDIV_256FS;
7475 + mclk_freq = samplerate*128;
7476 + mclk_div = WM8804_MCLKDIV_128FS;
7479 + switch (samplerate) {
7481 + sampling_freq = 0x03;
7484 + sampling_freq = 0x00;
7487 + sampling_freq = 0x02;
7490 + sampling_freq = 0x08;
7493 + sampling_freq = 0x0a;
7496 + sampling_freq = 0x0c;
7499 + sampling_freq = 0x0e;
7502 + dev_err(card->dev,
7503 + "Failed to set WM8804 SYSCLK, unsupported samplerate %d\n",
7507 + snd_soc_dai_set_clkdiv(codec_dai, WM8804_MCLK_DIV, mclk_div);
7508 + snd_soc_dai_set_pll(codec_dai, 0, 0, sysclk, mclk_freq);
7510 + ret = snd_soc_dai_set_sysclk(codec_dai, WM8804_TX_CLKSRC_PLL,
7511 + sysclk, SND_SOC_CLOCK_OUT);
7513 + dev_err(card->dev,
7514 + "Failed to set WM8804 SYSCLK: %d\n", ret);
7517 + /* Enable wm8804 TX output */
7518 + snd_soc_component_update_bits(component, WM8804_PWRDN, 0x4, 0x0);
7520 + /* wm8804 Power on */
7521 + snd_soc_component_update_bits(component, WM8804_PWRDN, 0x9, 0);
7523 + /* wm8804 set sampling frequency status bits */
7524 + snd_soc_component_update_bits(component, WM8804_SPDTX4, 0x0f, sampling_freq);
7526 + /* Now update wm8741 registers for the correct oversampling */
7527 + if (samplerate <= 48000)
7528 + snd_soc_component_update_bits(wm8741_component, WM8741_MODE_CONTROL_1,
7529 + WM8741_OSR_MASK, 0x00);
7530 + else if (samplerate <= 96000)
7531 + snd_soc_component_update_bits(wm8741_component, WM8741_MODE_CONTROL_1,
7532 + WM8741_OSR_MASK, 0x20);
7534 + snd_soc_component_update_bits(wm8741_component, WM8741_MODE_CONTROL_1,
7535 + WM8741_OSR_MASK, 0x40);
7537 + /* wm8741 bit size */
7538 + switch (params_width(params)) {
7540 + snd_soc_component_update_bits(wm8741_component, WM8741_FORMAT_CONTROL,
7541 + WM8741_IWL_MASK, 0x00);
7544 + snd_soc_component_update_bits(wm8741_component, WM8741_FORMAT_CONTROL,
7545 + WM8741_IWL_MASK, 0x01);
7548 + snd_soc_component_update_bits(wm8741_component, WM8741_FORMAT_CONTROL,
7549 + WM8741_IWL_MASK, 0x02);
7552 + snd_soc_component_update_bits(wm8741_component, WM8741_FORMAT_CONTROL,
7553 + WM8741_IWL_MASK, 0x03);
7556 + dev_dbg(card->dev, "wm8741_hw_params: Unsupported bit size param = %d",
7557 + params_width(params));
7561 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 64);
7563 +/* machine stream operations */
7564 +static struct snd_soc_ops digidac1_soundcard_ops = {
7565 + .hw_params = digidac1_soundcard_hw_params,
7566 + .startup = digidac1_soundcard_startup,
7567 + .shutdown = digidac1_soundcard_shutdown,
7570 +SND_SOC_DAILINK_DEFS(digidac1,
7571 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
7572 + DAILINK_COMP_ARRAY(COMP_CODEC("wm8804.1-003b", "wm8804-spdif")),
7573 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2835-i2s.0")));
7575 +SND_SOC_DAILINK_DEFS(digidac11,
7576 + DAILINK_COMP_ARRAY(COMP_CPU("wm8804-spdif")),
7577 + DAILINK_COMP_ARRAY(COMP_CODEC("wm8741.1-001a", "wm8741")),
7578 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
7580 +static struct snd_soc_dai_link digidac1_soundcard_dai[] = {
7582 + .name = "RRA DigiDAC1",
7583 + .stream_name = "RRA DigiDAC1 HiFi",
7584 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
7585 + SND_SOC_DAIFMT_CBM_CFM,
7586 + .ops = &digidac1_soundcard_ops,
7587 + .init = digidac1_soundcard_init,
7588 + SND_SOC_DAILINK_REG(digidac1),
7591 + .name = "RRA DigiDAC11",
7592 + .stream_name = "RRA DigiDAC11 HiFi",
7593 + .dai_fmt = SND_SOC_DAIFMT_I2S
7594 + | SND_SOC_DAIFMT_NB_NF
7595 + | SND_SOC_DAIFMT_CBS_CFS,
7596 + SND_SOC_DAILINK_REG(digidac11),
7600 +/* audio machine driver */
7601 +static struct snd_soc_card digidac1_soundcard = {
7602 + .name = "digidac1-soundcard",
7603 + .owner = THIS_MODULE,
7604 + .dai_link = digidac1_soundcard_dai,
7605 + .num_links = ARRAY_SIZE(digidac1_soundcard_dai),
7608 +static int digidac1_soundcard_probe(struct platform_device *pdev)
7612 + digidac1_soundcard.dev = &pdev->dev;
7614 + if (pdev->dev.of_node) {
7615 + struct device_node *i2s_node;
7616 + struct snd_soc_dai_link *dai = &digidac1_soundcard_dai[0];
7618 + i2s_node = of_parse_phandle(pdev->dev.of_node,
7619 + "i2s-controller", 0);
7622 + dai->cpus->dai_name = NULL;
7623 + dai->cpus->of_node = i2s_node;
7624 + dai->platforms->name = NULL;
7625 + dai->platforms->of_node = i2s_node;
7629 + ret = devm_snd_soc_register_card(&pdev->dev, &digidac1_soundcard);
7630 + if (ret && ret != -EPROBE_DEFER)
7631 + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
7637 +static const struct of_device_id digidac1_soundcard_of_match[] = {
7638 + { .compatible = "rra,digidac1-soundcard", },
7641 +MODULE_DEVICE_TABLE(of, digidac1_soundcard_of_match);
7643 +static struct platform_driver digidac1_soundcard_driver = {
7645 + .name = "digidac1-audio",
7646 + .owner = THIS_MODULE,
7647 + .of_match_table = digidac1_soundcard_of_match,
7649 + .probe = digidac1_soundcard_probe,
7652 +module_platform_driver(digidac1_soundcard_driver);
7654 +MODULE_AUTHOR("José M. Tasende <vintage@redrocksaudio.es>");
7655 +MODULE_DESCRIPTION("ASoC Driver for RRA DigiDAC1");
7656 +MODULE_LICENSE("GPL v2");
7658 +++ b/sound/soc/bcm/dionaudio_loco-v2.c
7661 + * ASoC Driver for Dion Audio LOCO-V2 DAC-AMP
7663 + * Author: Miquel Blauw <info@dionaudio.nl>
7666 + * Based on the software of the RPi-DAC writen by Florian Meier
7668 + * This program is free software; you can redistribute it and/or
7669 + * modify it under the terms of the GNU General Public License
7670 + * version 2 as published by the Free Software Foundation.
7672 + * This program is distributed in the hope that it will be useful, but
7673 + * WITHOUT ANY WARRANTY; without even the implied warranty of
7674 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7675 + * General Public License for more details.
7678 +#include <linux/module.h>
7679 +#include <linux/platform_device.h>
7681 +#include <sound/core.h>
7682 +#include <sound/pcm.h>
7683 +#include <sound/pcm_params.h>
7684 +#include <sound/soc.h>
7685 +#include <sound/jack.h>
7687 +static bool digital_gain_0db_limit = true;
7689 +static int snd_rpi_dionaudio_loco_v2_init(struct snd_soc_pcm_runtime *rtd)
7691 + if (digital_gain_0db_limit) {
7693 + struct snd_soc_card *card = rtd->card;
7695 + ret = snd_soc_limit_volume(card, "Digital Playback Volume", 207);
7697 + dev_warn(card->dev, "Failed to set volume limit: %d\n", ret);
7703 +SND_SOC_DAILINK_DEFS(dionaudio_loco_v2,
7704 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
7705 + DAILINK_COMP_ARRAY(COMP_CODEC("pcm512x.1-004d", "pcm512x-hifi")),
7706 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
7708 +static struct snd_soc_dai_link snd_rpi_dionaudio_loco_v2_dai[] = {
7710 + .name = "DionAudio LOCO-V2",
7711 + .stream_name = "DionAudio LOCO-V2 DAC-AMP",
7712 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
7713 + SND_SOC_DAIFMT_CBS_CFS,
7714 + .init = snd_rpi_dionaudio_loco_v2_init,
7715 + SND_SOC_DAILINK_REG(dionaudio_loco_v2),
7718 +/* audio machine driver */
7719 +static struct snd_soc_card snd_rpi_dionaudio_loco_v2 = {
7720 + .name = "Dion Audio LOCO-V2",
7721 + .dai_link = snd_rpi_dionaudio_loco_v2_dai,
7722 + .num_links = ARRAY_SIZE(snd_rpi_dionaudio_loco_v2_dai),
7725 +static int snd_rpi_dionaudio_loco_v2_probe(struct platform_device *pdev)
7729 + snd_rpi_dionaudio_loco_v2.dev = &pdev->dev;
7731 + if (pdev->dev.of_node) {
7732 + struct device_node *i2s_node;
7733 + struct snd_soc_dai_link *dai =
7734 + &snd_rpi_dionaudio_loco_v2_dai[0];
7736 + i2s_node = of_parse_phandle(pdev->dev.of_node,
7737 + "i2s-controller", 0);
7739 + dai->cpus->dai_name = NULL;
7740 + dai->cpus->of_node = i2s_node;
7741 + dai->platforms->name = NULL;
7742 + dai->platforms->of_node = i2s_node;
7745 + digital_gain_0db_limit = !of_property_read_bool(
7746 + pdev->dev.of_node, "dionaudio,24db_digital_gain");
7749 + ret = devm_snd_soc_register_card(&pdev->dev, &snd_rpi_dionaudio_loco_v2);
7751 + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
7757 +static const struct of_device_id dionaudio_of_match[] = {
7758 + { .compatible = "dionaudio,dionaudio-loco-v2", },
7761 +MODULE_DEVICE_TABLE(of, dionaudio_of_match);
7763 +static struct platform_driver snd_rpi_dionaudio_loco_v2_driver = {
7765 + .name = "snd-rpi-dionaudio-loco-v2",
7766 + .owner = THIS_MODULE,
7767 + .of_match_table = dionaudio_of_match,
7769 + .probe = snd_rpi_dionaudio_loco_v2_probe,
7772 +module_platform_driver(snd_rpi_dionaudio_loco_v2_driver);
7774 +MODULE_AUTHOR("Miquel Blauw <info@dionaudio.nl>");
7775 +MODULE_DESCRIPTION("ASoC Driver for DionAudio LOCO-V2");
7776 +MODULE_LICENSE("GPL v2");
7778 +++ b/sound/soc/bcm/dionaudio_loco.c
7781 + * ASoC Driver for Dion Audio LOCO DAC-AMP
7783 + * Author: Miquel Blauw <info@dionaudio.nl>
7786 + * Based on the software of the RPi-DAC writen by Florian Meier
7788 + * This program is free software; you can redistribute it and/or
7789 + * modify it under the terms of the GNU General Public License
7790 + * version 2 as published by the Free Software Foundation.
7792 + * This program is distributed in the hope that it will be useful, but
7793 + * WITHOUT ANY WARRANTY; without even the implied warranty of
7794 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7795 + * General Public License for more details.
7798 +#include <linux/module.h>
7799 +#include <linux/platform_device.h>
7801 +#include <sound/core.h>
7802 +#include <sound/pcm.h>
7803 +#include <sound/pcm_params.h>
7804 +#include <sound/soc.h>
7805 +#include <sound/jack.h>
7807 +static int snd_rpi_dionaudio_loco_hw_params(
7808 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
7810 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
7811 + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
7813 + unsigned int sample_bits =
7814 + snd_pcm_format_physical_width(params_format(params));
7816 + return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);
7819 +/* machine stream operations */
7820 +static struct snd_soc_ops snd_rpi_dionaudio_loco_ops = {
7821 + .hw_params = snd_rpi_dionaudio_loco_hw_params,
7824 +SND_SOC_DAILINK_DEFS(dionaudio_loco,
7825 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
7826 + DAILINK_COMP_ARRAY(COMP_CODEC("pcm5102a-codec", "pcm5102a-hifi")),
7827 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
7829 +static struct snd_soc_dai_link snd_rpi_dionaudio_loco_dai[] = {
7831 + .name = "DionAudio LOCO",
7832 + .stream_name = "DionAudio LOCO DAC-AMP",
7833 + .dai_fmt = SND_SOC_DAIFMT_I2S |
7834 + SND_SOC_DAIFMT_NB_NF |
7835 + SND_SOC_DAIFMT_CBS_CFS,
7836 + .ops = &snd_rpi_dionaudio_loco_ops,
7837 + SND_SOC_DAILINK_REG(dionaudio_loco),
7841 +/* audio machine driver */
7842 +static struct snd_soc_card snd_rpi_dionaudio_loco = {
7843 + .name = "snd_rpi_dionaudio_loco",
7844 + .dai_link = snd_rpi_dionaudio_loco_dai,
7845 + .num_links = ARRAY_SIZE(snd_rpi_dionaudio_loco_dai),
7848 +static int snd_rpi_dionaudio_loco_probe(struct platform_device *pdev)
7850 + struct device_node *np;
7853 + snd_rpi_dionaudio_loco.dev = &pdev->dev;
7855 + np = pdev->dev.of_node;
7857 + struct snd_soc_dai_link *dai = &snd_rpi_dionaudio_loco_dai[0];
7858 + struct device_node *i2s_np;
7860 + i2s_np = of_parse_phandle(np, "i2s-controller", 0);
7862 + dai->cpus->dai_name = NULL;
7863 + dai->cpus->of_node = i2s_np;
7864 + dai->platforms->name = NULL;
7865 + dai->platforms->of_node = i2s_np;
7869 + ret = devm_snd_soc_register_card(&pdev->dev, &snd_rpi_dionaudio_loco);
7870 + if (ret && ret != -EPROBE_DEFER)
7871 + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
7877 +static const struct of_device_id snd_rpi_dionaudio_loco_of_match[] = {
7878 + { .compatible = "dionaudio,loco-pcm5242-tpa3118", },
7879 + { /* sentinel */ },
7881 +MODULE_DEVICE_TABLE(of, snd_rpi_dionaudio_loco_of_match);
7883 +static struct platform_driver snd_rpi_dionaudio_loco_driver = {
7885 + .name = "snd-dionaudio-loco",
7886 + .owner = THIS_MODULE,
7887 + .of_match_table = snd_rpi_dionaudio_loco_of_match,
7889 + .probe = snd_rpi_dionaudio_loco_probe,
7892 +module_platform_driver(snd_rpi_dionaudio_loco_driver);
7894 +MODULE_AUTHOR("Miquel Blauw <info@dionaudio.nl>");
7895 +MODULE_DESCRIPTION("ASoC Driver for DionAudio LOCO");
7896 +MODULE_LICENSE("GPL v2");
7898 +++ b/sound/soc/bcm/fe-pi-audio.c
7901 + * ASoC Driver for Fe-Pi Audio Sound Card
7903 + * Author: Henry Kupis <kuupaz@gmail.com>
7905 + * based on code by Florian Meier <florian.meier@koalo.de>
7906 + * based on code by Shawn Guo <shawn.guo@linaro.org>
7908 + * This program is free software; you can redistribute it and/or
7909 + * modify it under the terms of the GNU General Public License
7910 + * version 2 as published by the Free Software Foundation.
7912 + * This program is distributed in the hope that it will be useful, but
7913 + * WITHOUT ANY WARRANTY; without even the implied warranty of
7914 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7915 + * General Public License for more details.
7918 +#include <linux/module.h>
7919 +#include <linux/platform_device.h>
7920 +#include <linux/io.h>
7922 +#include <sound/core.h>
7923 +#include <sound/pcm.h>
7924 +#include <sound/pcm_params.h>
7925 +#include <sound/soc.h>
7926 +#include <sound/jack.h>
7928 +#include "../codecs/sgtl5000.h"
7930 +static int snd_fe_pi_audio_init(struct snd_soc_pcm_runtime *rtd)
7932 + struct snd_soc_card *card = rtd->card;
7933 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
7935 + snd_soc_dapm_force_enable_pin(&card->dapm, "LO");
7936 + snd_soc_dapm_force_enable_pin(&card->dapm, "ADC");
7937 + snd_soc_dapm_force_enable_pin(&card->dapm, "DAC");
7938 + snd_soc_dapm_force_enable_pin(&card->dapm, "HP");
7939 + snd_soc_component_update_bits(component, SGTL5000_CHIP_ANA_POWER,
7940 + SGTL5000_VAG_POWERUP, SGTL5000_VAG_POWERUP);
7945 +static int snd_fe_pi_audio_hw_params(struct snd_pcm_substream *substream,
7946 + struct snd_pcm_hw_params *params)
7948 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
7949 + struct device *dev = rtd->card->dev;
7950 + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
7954 + /* Set SGTL5000's SYSCLK */
7955 + ret = snd_soc_dai_set_sysclk(codec_dai, SGTL5000_SYSCLK, 12288000, SND_SOC_CLOCK_IN);
7957 + dev_err(dev, "could not set codec driver clock params\n");
7965 +static struct snd_soc_ops snd_fe_pi_audio_ops = {
7966 + .hw_params = snd_fe_pi_audio_hw_params,
7969 +SND_SOC_DAILINK_DEFS(fe_pi,
7970 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
7971 + DAILINK_COMP_ARRAY(COMP_CODEC("sgtl5000.1-000a", "sgtl5000")),
7972 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
7974 +static struct snd_soc_dai_link snd_fe_pi_audio_dai[] = {
7977 + .stream_name = "Fe-Pi HiFi",
7978 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
7979 + SND_SOC_DAIFMT_CBM_CFM,
7980 + .ops = &snd_fe_pi_audio_ops,
7981 + .init = snd_fe_pi_audio_init,
7982 + SND_SOC_DAILINK_REG(fe_pi),
7986 +static const struct snd_soc_dapm_route fe_pi_audio_dapm_routes[] = {
7987 + {"ADC", NULL, "Mic Bias"},
7991 +static struct snd_soc_card fe_pi_audio = {
7992 + .name = "Fe-Pi Audio",
7993 + .owner = THIS_MODULE,
7994 + .dai_link = snd_fe_pi_audio_dai,
7995 + .num_links = ARRAY_SIZE(snd_fe_pi_audio_dai),
7997 + .dapm_routes = fe_pi_audio_dapm_routes,
7998 + .num_dapm_routes = ARRAY_SIZE(fe_pi_audio_dapm_routes),
8001 +static int snd_fe_pi_audio_probe(struct platform_device *pdev)
8004 + struct snd_soc_card *card = &fe_pi_audio;
8005 + struct device_node *np = pdev->dev.of_node;
8006 + struct device_node *i2s_node;
8007 + struct snd_soc_dai_link *dai = &snd_fe_pi_audio_dai[0];
8009 + fe_pi_audio.dev = &pdev->dev;
8011 + i2s_node = of_parse_phandle(np, "i2s-controller", 0);
8013 + dev_err(&pdev->dev, "i2s_node phandle missing or invalid\n");
8017 + dai->cpus->dai_name = NULL;
8018 + dai->cpus->of_node = i2s_node;
8019 + dai->platforms->name = NULL;
8020 + dai->platforms->of_node = i2s_node;
8022 + of_node_put(i2s_node);
8024 + card->dev = &pdev->dev;
8025 + platform_set_drvdata(pdev, card);
8027 + ret = devm_snd_soc_register_card(&pdev->dev, card);
8028 + if (ret && ret != -EPROBE_DEFER)
8029 + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
8034 +static const struct of_device_id snd_fe_pi_audio_of_match[] = {
8035 + { .compatible = "fe-pi,fe-pi-audio", },
8038 +MODULE_DEVICE_TABLE(of, snd_fe_pi_audio_of_match);
8040 +static struct platform_driver snd_fe_pi_audio_driver = {
8042 + .name = "snd-fe-pi-audio",
8043 + .owner = THIS_MODULE,
8044 + .of_match_table = snd_fe_pi_audio_of_match,
8046 + .probe = snd_fe_pi_audio_probe,
8049 +module_platform_driver(snd_fe_pi_audio_driver);
8051 +MODULE_AUTHOR("Henry Kupis <fe-pi@cox.net>");
8052 +MODULE_DESCRIPTION("ASoC Driver for Fe-Pi Audio");
8053 +MODULE_LICENSE("GPL v2");
8055 +++ b/sound/soc/bcm/googlevoicehat-codec.c
8058 + * Driver for the Google voiceHAT audio codec for Raspberry Pi.
8060 + * Author: Peter Malkin <petermalkin@google.com>
8063 + * This program is free software; you can redistribute it and/or
8064 + * modify it under the terms of the GNU General Public License
8065 + * version 2 as published by the Free Software Foundation.
8067 + * This program is distributed in the hope that it will be useful, but
8068 + * WITHOUT ANY WARRANTY; without even the implied warranty of
8069 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
8070 + * General Public License for more details.
8073 +#include <linux/device.h>
8074 +#include <linux/err.h>
8075 +#include <linux/gpio.h>
8076 +#include <linux/gpio/consumer.h>
8077 +#include <linux/init.h>
8078 +#include <linux/kernel.h>
8079 +#include <linux/mod_devicetable.h>
8080 +#include <linux/module.h>
8081 +#include <linux/of.h>
8082 +#include <linux/platform_device.h>
8083 +#include <linux/version.h>
8084 +#include <sound/pcm.h>
8085 +#include <sound/soc.h>
8086 +#include <sound/soc-dai.h>
8087 +#include <sound/soc-dapm.h>
8089 +#define ICS43432_RATE_MIN_HZ 7190 /* from data sheet */
8090 +#define ICS43432_RATE_MAX_HZ 52800 /* from data sheet */
8091 +/* Delay in enabling SDMODE after clock settles to remove pop */
8092 +#define SDMODE_DELAY_MS 5
8094 +struct voicehat_priv {
8095 + struct delayed_work enable_sdmode_work;
8096 + struct gpio_desc *sdmode_gpio;
8097 + unsigned long sdmode_delay_jiffies;
8100 +static void voicehat_enable_sdmode_work(struct work_struct *work)
8102 + struct voicehat_priv *voicehat = container_of(work,
8103 + struct voicehat_priv,
8104 + enable_sdmode_work.work);
8105 + gpiod_set_value(voicehat->sdmode_gpio, 1);
8108 +static int voicehat_component_probe(struct snd_soc_component *component)
8110 + struct voicehat_priv *voicehat =
8111 + snd_soc_component_get_drvdata(component);
8113 + voicehat->sdmode_gpio = devm_gpiod_get(component->dev, "sdmode",
8115 + if (IS_ERR(voicehat->sdmode_gpio)) {
8116 + dev_err(component->dev, "Unable to allocate GPIO pin\n");
8117 + return PTR_ERR(voicehat->sdmode_gpio);
8120 + INIT_DELAYED_WORK(&voicehat->enable_sdmode_work,
8121 + voicehat_enable_sdmode_work);
8125 +static void voicehat_component_remove(struct snd_soc_component *component)
8127 + struct voicehat_priv *voicehat =
8128 + snd_soc_component_get_drvdata(component);
8130 + cancel_delayed_work_sync(&voicehat->enable_sdmode_work);
8133 +static const struct snd_soc_dapm_widget voicehat_dapm_widgets[] = {
8134 + SND_SOC_DAPM_OUTPUT("Speaker"),
8137 +static const struct snd_soc_dapm_route voicehat_dapm_routes[] = {
8138 + {"Speaker", NULL, "HiFi Playback"},
8141 +static const struct snd_soc_component_driver voicehat_component_driver = {
8142 + .probe = voicehat_component_probe,
8143 + .remove = voicehat_component_remove,
8144 + .dapm_widgets = voicehat_dapm_widgets,
8145 + .num_dapm_widgets = ARRAY_SIZE(voicehat_dapm_widgets),
8146 + .dapm_routes = voicehat_dapm_routes,
8147 + .num_dapm_routes = ARRAY_SIZE(voicehat_dapm_routes),
8150 +static int voicehat_daiops_trigger(struct snd_pcm_substream *substream, int cmd,
8151 + struct snd_soc_dai *dai)
8153 + struct snd_soc_component *component = dai->component;
8154 + struct voicehat_priv *voicehat =
8155 + snd_soc_component_get_drvdata(component);
8157 + if (voicehat->sdmode_delay_jiffies == 0)
8160 + dev_dbg(dai->dev, "CMD %d", cmd);
8161 + dev_dbg(dai->dev, "Playback Active %d", dai->stream[SNDRV_PCM_STREAM_PLAYBACK].active);
8162 + dev_dbg(dai->dev, "Capture Active %d", dai->stream[SNDRV_PCM_STREAM_CAPTURE].active);
8165 + case SNDRV_PCM_TRIGGER_START:
8166 + case SNDRV_PCM_TRIGGER_RESUME:
8167 + case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
8168 + if (dai->stream[SNDRV_PCM_STREAM_PLAYBACK].active) {
8169 + dev_info(dai->dev, "Enabling audio amp...\n");
8170 + queue_delayed_work(
8171 + system_power_efficient_wq,
8172 + &voicehat->enable_sdmode_work,
8173 + voicehat->sdmode_delay_jiffies);
8176 + case SNDRV_PCM_TRIGGER_STOP:
8177 + case SNDRV_PCM_TRIGGER_SUSPEND:
8178 + case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
8179 + if (dai->stream[SNDRV_PCM_STREAM_PLAYBACK].active) {
8180 + cancel_delayed_work(&voicehat->enable_sdmode_work);
8181 + dev_info(dai->dev, "Disabling audio amp...\n");
8182 + gpiod_set_value(voicehat->sdmode_gpio, 0);
8189 +static const struct snd_soc_dai_ops voicehat_dai_ops = {
8190 + .trigger = voicehat_daiops_trigger,
8193 +static struct snd_soc_dai_driver voicehat_dai = {
8194 + .name = "voicehat-hifi",
8196 + .stream_name = "HiFi Capture",
8197 + .channels_min = 2,
8198 + .channels_max = 2,
8199 + .rates = SNDRV_PCM_RATE_48000,
8200 + .formats = SNDRV_PCM_FMTBIT_S32_LE
8203 + .stream_name = "HiFi Playback",
8204 + .channels_min = 2,
8205 + .channels_max = 2,
8206 + .rates = SNDRV_PCM_RATE_48000,
8207 + .formats = SNDRV_PCM_FMTBIT_S32_LE
8209 + .ops = &voicehat_dai_ops,
8210 + .symmetric_rate = 1
8214 +static const struct of_device_id voicehat_ids[] = {
8215 + { .compatible = "google,voicehat", }, {}
8217 + MODULE_DEVICE_TABLE(of, voicehat_ids);
8220 +static int voicehat_platform_probe(struct platform_device *pdev)
8222 + struct voicehat_priv *voicehat;
8223 + unsigned int sdmode_delay;
8226 + voicehat = devm_kzalloc(&pdev->dev, sizeof(*voicehat), GFP_KERNEL);
8230 + ret = device_property_read_u32(&pdev->dev, "voicehat_sdmode_delay",
8234 + sdmode_delay = SDMODE_DELAY_MS;
8235 + dev_info(&pdev->dev,
8236 + "property 'voicehat_sdmode_delay' not found default 5 mS");
8238 + dev_info(&pdev->dev, "property 'voicehat_sdmode_delay' found delay= %d mS",
8241 + voicehat->sdmode_delay_jiffies = msecs_to_jiffies(sdmode_delay);
8243 + dev_set_drvdata(&pdev->dev, voicehat);
8245 + return snd_soc_register_component(&pdev->dev,
8246 + &voicehat_component_driver,
8251 +static int voicehat_platform_remove(struct platform_device *pdev)
8253 + snd_soc_unregister_component(&pdev->dev);
8257 +static struct platform_driver voicehat_driver = {
8259 + .name = "voicehat-codec",
8260 + .of_match_table = of_match_ptr(voicehat_ids),
8262 + .probe = voicehat_platform_probe,
8263 + .remove = voicehat_platform_remove,
8266 +module_platform_driver(voicehat_driver);
8268 +MODULE_DESCRIPTION("Google voiceHAT Codec driver");
8269 +MODULE_AUTHOR("Peter Malkin <petermalkin@google.com>");
8270 +MODULE_LICENSE("GPL v2");
8272 +++ b/sound/soc/bcm/hifiberry_dacplus.c
8275 + * ASoC Driver for HiFiBerry DAC+ / DAC Pro / AMP100
8277 + * Author: Daniel Matuschek, Stuart MacLean <stuart@hifiberry.com>
8278 + * Copyright 2014-2015
8279 + * based on code by Florian Meier <florian.meier@koalo.de>
8280 + * Headphone/AMP100 Joerg Schambacher <joerg@hifiberry.com>
8282 + * This program is free software; you can redistribute it and/or
8283 + * modify it under the terms of the GNU General Public License
8284 + * version 2 as published by the Free Software Foundation.
8286 + * This program is distributed in the hope that it will be useful, but
8287 + * WITHOUT ANY WARRANTY; without even the implied warranty of
8288 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
8289 + * General Public License for more details.
8292 +#include <linux/module.h>
8293 +#include <linux/gpio/consumer.h>
8294 +#include <../drivers/gpio/gpiolib.h>
8295 +#include <linux/platform_device.h>
8296 +#include <linux/kernel.h>
8297 +#include <linux/clk.h>
8298 +#include <linux/kernel.h>
8299 +#include <linux/module.h>
8300 +#include <linux/of.h>
8301 +#include <linux/slab.h>
8302 +#include <linux/delay.h>
8303 +#include <linux/i2c.h>
8305 +#include <sound/core.h>
8306 +#include <sound/pcm.h>
8307 +#include <sound/pcm_params.h>
8308 +#include <sound/soc.h>
8309 +#include <sound/jack.h>
8311 +#include "../codecs/pcm512x.h"
8313 +#define HIFIBERRY_DACPRO_NOCLOCK 0
8314 +#define HIFIBERRY_DACPRO_CLK44EN 1
8315 +#define HIFIBERRY_DACPRO_CLK48EN 2
8317 +struct pcm512x_priv {
8318 + struct regmap *regmap;
8322 +/* Clock rate of CLK44EN attached to GPIO6 pin */
8323 +#define CLK_44EN_RATE 22579200UL
8324 +/* Clock rate of CLK48EN attached to GPIO3 pin */
8325 +#define CLK_48EN_RATE 24576000UL
8328 +static bool snd_rpi_hifiberry_is_dacpro;
8329 +static bool digital_gain_0db_limit = true;
8330 +static bool leds_off;
8331 +static bool auto_mute;
8332 +static int mute_ext_ctl;
8333 +static int mute_ext;
8334 +static struct gpio_desc *snd_mute_gpio;
8335 +static struct gpio_desc *snd_reset_gpio;
8336 +static struct snd_soc_card snd_rpi_hifiberry_dacplus;
8338 +static int snd_rpi_hifiberry_dacplus_mute_set(int mute)
8340 + gpiod_set_value_cansleep(snd_mute_gpio, mute);
8344 +static int snd_rpi_hifiberry_dacplus_mute_get(struct snd_kcontrol *kcontrol,
8345 + struct snd_ctl_elem_value *ucontrol)
8347 + ucontrol->value.integer.value[0] = mute_ext;
8352 +static int snd_rpi_hifiberry_dacplus_mute_put(struct snd_kcontrol *kcontrol,
8353 + struct snd_ctl_elem_value *ucontrol)
8355 + if (mute_ext == ucontrol->value.integer.value[0])
8358 + mute_ext = ucontrol->value.integer.value[0];
8360 + return snd_rpi_hifiberry_dacplus_mute_set(mute_ext);
8363 +static const char * const mute_text[] = {"Play", "Mute"};
8364 +static const struct soc_enum hb_dacplus_opt_mute_enum =
8365 + SOC_ENUM_SINGLE_EXT(2, mute_text);
8367 +static const struct snd_kcontrol_new hb_dacplus_opt_mute_controls[] = {
8368 + SOC_ENUM_EXT("Mute(ext)", hb_dacplus_opt_mute_enum,
8369 + snd_rpi_hifiberry_dacplus_mute_get,
8370 + snd_rpi_hifiberry_dacplus_mute_put),
8373 +static void snd_rpi_hifiberry_dacplus_select_clk(struct snd_soc_component *component,
8377 + case HIFIBERRY_DACPRO_NOCLOCK:
8378 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x24, 0x00);
8380 + case HIFIBERRY_DACPRO_CLK44EN:
8381 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x24, 0x20);
8383 + case HIFIBERRY_DACPRO_CLK48EN:
8384 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x24, 0x04);
8387 + usleep_range(3000, 4000);
8390 +static void snd_rpi_hifiberry_dacplus_clk_gpio(struct snd_soc_component *component)
8392 + snd_soc_component_update_bits(component, PCM512x_GPIO_EN, 0x24, 0x24);
8393 + snd_soc_component_update_bits(component, PCM512x_GPIO_OUTPUT_3, 0x0f, 0x02);
8394 + snd_soc_component_update_bits(component, PCM512x_GPIO_OUTPUT_6, 0x0f, 0x02);
8397 +static bool snd_rpi_hifiberry_dacplus_is_sclk(struct snd_soc_component *component)
8401 + sck = snd_soc_component_read(component, PCM512x_RATE_DET_4);
8402 + return (!(sck & 0x40));
8405 +static bool snd_rpi_hifiberry_dacplus_is_pro_card(struct snd_soc_component *component)
8407 + bool isClk44EN, isClk48En, isNoClk;
8409 + snd_rpi_hifiberry_dacplus_clk_gpio(component);
8411 + snd_rpi_hifiberry_dacplus_select_clk(component, HIFIBERRY_DACPRO_CLK44EN);
8412 + isClk44EN = snd_rpi_hifiberry_dacplus_is_sclk(component);
8414 + snd_rpi_hifiberry_dacplus_select_clk(component, HIFIBERRY_DACPRO_NOCLOCK);
8415 + isNoClk = snd_rpi_hifiberry_dacplus_is_sclk(component);
8417 + snd_rpi_hifiberry_dacplus_select_clk(component, HIFIBERRY_DACPRO_CLK48EN);
8418 + isClk48En = snd_rpi_hifiberry_dacplus_is_sclk(component);
8420 + return (isClk44EN && isClk48En && !isNoClk);
8423 +static int snd_rpi_hifiberry_dacplus_clk_for_rate(int sample_rate)
8427 + switch (sample_rate) {
8434 + type = HIFIBERRY_DACPRO_CLK44EN;
8437 + type = HIFIBERRY_DACPRO_CLK48EN;
8443 +static void snd_rpi_hifiberry_dacplus_set_sclk(struct snd_soc_component *component,
8446 + struct pcm512x_priv *pcm512x = snd_soc_component_get_drvdata(component);
8448 + if (!IS_ERR(pcm512x->sclk)) {
8451 + ctype = snd_rpi_hifiberry_dacplus_clk_for_rate(sample_rate);
8452 + clk_set_rate(pcm512x->sclk, (ctype == HIFIBERRY_DACPRO_CLK44EN)
8453 + ? CLK_44EN_RATE : CLK_48EN_RATE);
8454 + snd_rpi_hifiberry_dacplus_select_clk(component, ctype);
8458 +static int snd_rpi_hifiberry_dacplus_init(struct snd_soc_pcm_runtime *rtd)
8460 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
8461 + struct pcm512x_priv *priv;
8462 + struct snd_soc_card *card = &snd_rpi_hifiberry_dacplus;
8465 + snd_rpi_hifiberry_is_dacpro = false;
8467 + snd_rpi_hifiberry_is_dacpro =
8468 + snd_rpi_hifiberry_dacplus_is_pro_card(component);
8470 + if (snd_rpi_hifiberry_is_dacpro) {
8471 + struct snd_soc_dai_link *dai = rtd->dai_link;
8473 + dai->name = "HiFiBerry DAC+ Pro";
8474 + dai->stream_name = "HiFiBerry DAC+ Pro HiFi";
8475 + dai->dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
8476 + | SND_SOC_DAIFMT_CBM_CFM;
8478 + snd_soc_component_update_bits(component, PCM512x_BCLK_LRCLK_CFG, 0x31, 0x11);
8479 + snd_soc_component_update_bits(component, PCM512x_MASTER_MODE, 0x03, 0x03);
8480 + snd_soc_component_update_bits(component, PCM512x_MASTER_CLKDIV_2, 0x7f, 63);
8482 + priv = snd_soc_component_get_drvdata(component);
8483 + priv->sclk = ERR_PTR(-ENOENT);
8486 + snd_soc_component_update_bits(component, PCM512x_GPIO_EN, 0x08, 0x08);
8487 + snd_soc_component_update_bits(component, PCM512x_GPIO_OUTPUT_4, 0x0f, 0x02);
8489 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x08, 0x00);
8491 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x08, 0x08);
8493 + if (digital_gain_0db_limit) {
8495 + struct snd_soc_card *card = rtd->card;
8497 + ret = snd_soc_limit_volume(card, "Digital Playback Volume", 207);
8499 + dev_warn(card->dev, "Failed to set volume limit: %d\n", ret);
8501 + if (snd_reset_gpio) {
8502 + gpiod_set_value_cansleep(snd_reset_gpio, 0);
8504 + gpiod_set_value_cansleep(snd_reset_gpio, 1);
8506 + gpiod_set_value_cansleep(snd_reset_gpio, 0);
8510 + snd_soc_add_card_controls(card, hb_dacplus_opt_mute_controls,
8511 + ARRAY_SIZE(hb_dacplus_opt_mute_controls));
8513 + if (snd_mute_gpio)
8514 + gpiod_set_value_cansleep(snd_mute_gpio, mute_ext);
8519 +static int snd_rpi_hifiberry_dacplus_update_rate_den(
8520 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
8522 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
8523 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
8524 + struct pcm512x_priv *pcm512x = snd_soc_component_get_drvdata(component);
8525 + struct snd_ratnum *rats_no_pll;
8526 + unsigned int num = 0, den = 0;
8529 + rats_no_pll = devm_kzalloc(rtd->dev, sizeof(*rats_no_pll), GFP_KERNEL);
8533 + rats_no_pll->num = clk_get_rate(pcm512x->sclk) / 64;
8534 + rats_no_pll->den_min = 1;
8535 + rats_no_pll->den_max = 128;
8536 + rats_no_pll->den_step = 1;
8538 + err = snd_interval_ratnum(hw_param_interval(params,
8539 + SNDRV_PCM_HW_PARAM_RATE), 1, rats_no_pll, &num, &den);
8540 + if (err >= 0 && den) {
8541 + params->rate_num = num;
8542 + params->rate_den = den;
8545 + devm_kfree(rtd->dev, rats_no_pll);
8549 +static int snd_rpi_hifiberry_dacplus_hw_params(
8550 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
8553 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
8554 + int channels = params_channels(params);
8557 + if (snd_rpi_hifiberry_is_dacpro) {
8558 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
8560 + width = snd_pcm_format_physical_width(params_format(params));
8562 + snd_rpi_hifiberry_dacplus_set_sclk(component,
8563 + params_rate(params));
8565 + ret = snd_rpi_hifiberry_dacplus_update_rate_den(
8566 + substream, params);
8569 + ret = snd_soc_dai_set_bclk_ratio(asoc_rtd_to_cpu(rtd, 0), channels * width);
8572 + ret = snd_soc_dai_set_bclk_ratio(asoc_rtd_to_codec(rtd, 0), channels * width);
8576 +static int snd_rpi_hifiberry_dacplus_startup(
8577 + struct snd_pcm_substream *substream)
8579 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
8580 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
8583 + gpiod_set_value_cansleep(snd_mute_gpio, 0);
8586 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x08, 0x08);
8590 +static void snd_rpi_hifiberry_dacplus_shutdown(
8591 + struct snd_pcm_substream *substream)
8593 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
8594 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
8596 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x08, 0x00);
8598 + gpiod_set_value_cansleep(snd_mute_gpio, 1);
8601 +/* machine stream operations */
8602 +static struct snd_soc_ops snd_rpi_hifiberry_dacplus_ops = {
8603 + .hw_params = snd_rpi_hifiberry_dacplus_hw_params,
8604 + .startup = snd_rpi_hifiberry_dacplus_startup,
8605 + .shutdown = snd_rpi_hifiberry_dacplus_shutdown,
8608 +SND_SOC_DAILINK_DEFS(rpi_hifiberry_dacplus,
8609 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
8610 + DAILINK_COMP_ARRAY(COMP_CODEC("pcm512x.1-004d", "pcm512x-hifi")),
8611 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
8613 +static struct snd_soc_dai_link snd_rpi_hifiberry_dacplus_dai[] = {
8615 + .name = "HiFiBerry DAC+",
8616 + .stream_name = "HiFiBerry DAC+ HiFi",
8617 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
8618 + SND_SOC_DAIFMT_CBS_CFS,
8619 + .ops = &snd_rpi_hifiberry_dacplus_ops,
8620 + .init = snd_rpi_hifiberry_dacplus_init,
8621 + SND_SOC_DAILINK_REG(rpi_hifiberry_dacplus),
8625 +/* aux device for optional headphone amp */
8626 +static struct snd_soc_aux_dev hifiberry_dacplus_aux_devs[] = {
8629 + .name = "tpa6130a2.1-0060",
8634 +/* audio machine driver */
8635 +static struct snd_soc_card snd_rpi_hifiberry_dacplus = {
8636 + .name = "snd_rpi_hifiberry_dacplus",
8637 + .driver_name = "HifiberryDacp",
8638 + .owner = THIS_MODULE,
8639 + .dai_link = snd_rpi_hifiberry_dacplus_dai,
8640 + .num_links = ARRAY_SIZE(snd_rpi_hifiberry_dacplus_dai),
8643 +static int hb_hp_detect(void)
8645 + struct i2c_adapter *adap = i2c_get_adapter(1);
8647 + struct i2c_client tpa_i2c_client = {
8653 + return -EPROBE_DEFER; /* I2C module not yet available */
8655 + ret = i2c_smbus_read_byte(&tpa_i2c_client) >= 0;
8656 + i2c_put_adapter(adap);
8660 +static struct property tpa_enable_prop = {
8662 + .length = 4 + 1, /* length 'okay' + 1 */
8666 +static int snd_rpi_hifiberry_dacplus_probe(struct platform_device *pdev)
8669 + struct snd_soc_card *card = &snd_rpi_hifiberry_dacplus;
8671 + struct device_node *tpa_node;
8672 + struct property *tpa_prop;
8673 + struct of_changeset ocs;
8674 + struct property *pp;
8677 + /* probe for head phone amp */
8678 + ret = hb_hp_detect();
8682 + card->aux_dev = hifiberry_dacplus_aux_devs;
8683 + card->num_aux_devs =
8684 + ARRAY_SIZE(hifiberry_dacplus_aux_devs);
8685 + tpa_node = of_find_compatible_node(NULL, NULL, "ti,tpa6130a2");
8686 + tpa_prop = of_find_property(tpa_node, "status", &len);
8688 + if (strcmp((char *)tpa_prop->value, "okay")) {
8689 + /* and activate headphone using change_sets */
8690 + dev_info(&pdev->dev, "activating headphone amplifier");
8691 + of_changeset_init(&ocs);
8692 + ret = of_changeset_update_property(&ocs, tpa_node,
8693 + &tpa_enable_prop);
8695 + dev_err(&pdev->dev,
8696 + "cannot activate headphone amplifier\n");
8699 + ret = of_changeset_apply(&ocs);
8701 + dev_err(&pdev->dev,
8702 + "cannot activate headphone amplifier\n");
8708 + snd_rpi_hifiberry_dacplus.dev = &pdev->dev;
8709 + if (pdev->dev.of_node) {
8710 + struct device_node *i2s_node;
8711 + struct snd_soc_dai_link *dai;
8713 + dai = &snd_rpi_hifiberry_dacplus_dai[0];
8714 + i2s_node = of_parse_phandle(pdev->dev.of_node,
8715 + "i2s-controller", 0);
8718 + dai->cpus->dai_name = NULL;
8719 + dai->cpus->of_node = i2s_node;
8720 + dai->platforms->name = NULL;
8721 + dai->platforms->of_node = i2s_node;
8724 + digital_gain_0db_limit = !of_property_read_bool(
8725 + pdev->dev.of_node, "hifiberry,24db_digital_gain");
8726 + slave = of_property_read_bool(pdev->dev.of_node,
8727 + "hifiberry-dacplus,slave");
8728 + leds_off = of_property_read_bool(pdev->dev.of_node,
8729 + "hifiberry-dacplus,leds_off");
8730 + auto_mute = of_property_read_bool(pdev->dev.of_node,
8731 + "hifiberry-dacplus,auto_mute");
8734 + * check for HW MUTE as defined in DT-overlay
8735 + * active high, therefore default to HIGH to MUTE
8737 + snd_mute_gpio = devm_gpiod_get_optional(&pdev->dev,
8738 + "mute", GPIOD_OUT_HIGH);
8739 + if (IS_ERR(snd_mute_gpio)) {
8740 + dev_err(&pdev->dev, "Can't allocate GPIO (HW-MUTE)");
8741 + return PTR_ERR(snd_mute_gpio);
8744 + /* add ALSA control if requested in DT-overlay (AMP100) */
8745 + pp = of_find_property(pdev->dev.of_node,
8746 + "hifiberry-dacplus,mute_ext_ctl", &tmp);
8748 + if (!of_property_read_u32(pdev->dev.of_node,
8749 + "hifiberry-dacplus,mute_ext_ctl", &mute_ext)) {
8750 + /* ALSA control will be used */
8755 + /* check for HW RESET (AMP100) */
8756 + snd_reset_gpio = devm_gpiod_get_optional(&pdev->dev,
8757 + "reset", GPIOD_OUT_HIGH);
8758 + if (IS_ERR(snd_reset_gpio)) {
8759 + dev_err(&pdev->dev, "Can't allocate GPIO (HW-RESET)");
8760 + return PTR_ERR(snd_reset_gpio);
8765 + ret = devm_snd_soc_register_card(&pdev->dev,
8766 + &snd_rpi_hifiberry_dacplus);
8767 + if (ret && ret != -EPROBE_DEFER)
8768 + dev_err(&pdev->dev,
8769 + "snd_soc_register_card() failed: %d\n", ret);
8771 + if (snd_mute_gpio)
8772 + dev_info(&pdev->dev, "GPIO%i for HW-MUTE selected",
8773 + gpio_chip_hwgpio(snd_mute_gpio));
8774 + if (snd_reset_gpio)
8775 + dev_info(&pdev->dev, "GPIO%i for HW-RESET selected",
8776 + gpio_chip_hwgpio(snd_reset_gpio));
8781 +static const struct of_device_id snd_rpi_hifiberry_dacplus_of_match[] = {
8782 + { .compatible = "hifiberry,hifiberry-dacplus", },
8785 +MODULE_DEVICE_TABLE(of, snd_rpi_hifiberry_dacplus_of_match);
8787 +static struct platform_driver snd_rpi_hifiberry_dacplus_driver = {
8789 + .name = "snd-rpi-hifiberry-dacplus",
8790 + .owner = THIS_MODULE,
8791 + .of_match_table = snd_rpi_hifiberry_dacplus_of_match,
8793 + .probe = snd_rpi_hifiberry_dacplus_probe,
8796 +module_platform_driver(snd_rpi_hifiberry_dacplus_driver);
8798 +MODULE_AUTHOR("Daniel Matuschek <daniel@hifiberry.com>");
8799 +MODULE_DESCRIPTION("ASoC Driver for HiFiBerry DAC+");
8800 +MODULE_LICENSE("GPL v2");
8802 +++ b/sound/soc/bcm/hifiberry_dacplusadc.c
8805 + * ASoC Driver for HiFiBerry DAC+ / DAC Pro with ADC
8807 + * Author: Daniel Matuschek, Stuart MacLean <stuart@hifiberry.com>
8808 + * Copyright 2014-2015
8809 + * based on code by Florian Meier <florian.meier@koalo.de>
8810 + * ADC added by Joerg Schambacher <joscha@schambacher.com>
8813 + * This program is free software; you can redistribute it and/or
8814 + * modify it under the terms of the GNU General Public License
8815 + * version 2 as published by the Free Software Foundation.
8817 + * This program is distributed in the hope that it will be useful, but
8818 + * WITHOUT ANY WARRANTY; without even the implied warranty of
8819 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
8820 + * General Public License for more details.
8823 +#include <linux/module.h>
8824 +#include <linux/platform_device.h>
8825 +#include <linux/kernel.h>
8826 +#include <linux/clk.h>
8827 +#include <linux/kernel.h>
8828 +#include <linux/module.h>
8829 +#include <linux/of.h>
8830 +#include <linux/slab.h>
8831 +#include <linux/delay.h>
8833 +#include <sound/core.h>
8834 +#include <sound/pcm.h>
8835 +#include <sound/pcm_params.h>
8836 +#include <sound/soc.h>
8837 +#include <sound/jack.h>
8839 +#include "../codecs/pcm512x.h"
8841 +#define HIFIBERRY_DACPRO_NOCLOCK 0
8842 +#define HIFIBERRY_DACPRO_CLK44EN 1
8843 +#define HIFIBERRY_DACPRO_CLK48EN 2
8845 +struct platform_device *dmic_codec_dev;
8847 +struct pcm512x_priv {
8848 + struct regmap *regmap;
8852 +/* Clock rate of CLK44EN attached to GPIO6 pin */
8853 +#define CLK_44EN_RATE 22579200UL
8854 +/* Clock rate of CLK48EN attached to GPIO3 pin */
8855 +#define CLK_48EN_RATE 24576000UL
8858 +static bool snd_rpi_hifiberry_is_dacpro;
8859 +static bool digital_gain_0db_limit = true;
8860 +static bool leds_off;
8862 +static void snd_rpi_hifiberry_dacplusadc_select_clk(struct snd_soc_component *component,
8866 + case HIFIBERRY_DACPRO_NOCLOCK:
8867 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x24, 0x00);
8869 + case HIFIBERRY_DACPRO_CLK44EN:
8870 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x24, 0x20);
8872 + case HIFIBERRY_DACPRO_CLK48EN:
8873 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x24, 0x04);
8878 +static void snd_rpi_hifiberry_dacplusadc_clk_gpio(struct snd_soc_component *component)
8880 + snd_soc_component_update_bits(component, PCM512x_GPIO_EN, 0x24, 0x24);
8881 + snd_soc_component_update_bits(component, PCM512x_GPIO_OUTPUT_3, 0x0f, 0x02);
8882 + snd_soc_component_update_bits(component, PCM512x_GPIO_OUTPUT_6, 0x0f, 0x02);
8885 +static bool snd_rpi_hifiberry_dacplusadc_is_sclk(struct snd_soc_component *component)
8889 + sck = snd_soc_component_read(component, PCM512x_RATE_DET_4);
8890 + return (!(sck & 0x40));
8893 +static bool snd_rpi_hifiberry_dacplusadc_is_sclk_sleep(
8894 + struct snd_soc_component *component)
8897 + return snd_rpi_hifiberry_dacplusadc_is_sclk(component);
8900 +static bool snd_rpi_hifiberry_dacplusadc_is_pro_card(struct snd_soc_component *component)
8902 + bool isClk44EN, isClk48En, isNoClk;
8904 + snd_rpi_hifiberry_dacplusadc_clk_gpio(component);
8906 + snd_rpi_hifiberry_dacplusadc_select_clk(component, HIFIBERRY_DACPRO_CLK44EN);
8907 + isClk44EN = snd_rpi_hifiberry_dacplusadc_is_sclk_sleep(component);
8909 + snd_rpi_hifiberry_dacplusadc_select_clk(component, HIFIBERRY_DACPRO_NOCLOCK);
8910 + isNoClk = snd_rpi_hifiberry_dacplusadc_is_sclk_sleep(component);
8912 + snd_rpi_hifiberry_dacplusadc_select_clk(component, HIFIBERRY_DACPRO_CLK48EN);
8913 + isClk48En = snd_rpi_hifiberry_dacplusadc_is_sclk_sleep(component);
8915 + return (isClk44EN && isClk48En && !isNoClk);
8918 +static int snd_rpi_hifiberry_dacplusadc_clk_for_rate(int sample_rate)
8922 + switch (sample_rate) {
8929 + type = HIFIBERRY_DACPRO_CLK44EN;
8932 + type = HIFIBERRY_DACPRO_CLK48EN;
8938 +static void snd_rpi_hifiberry_dacplusadc_set_sclk(struct snd_soc_component *component,
8941 + struct pcm512x_priv *pcm512x = snd_soc_component_get_drvdata(component);
8943 + if (!IS_ERR(pcm512x->sclk)) {
8946 + ctype = snd_rpi_hifiberry_dacplusadc_clk_for_rate(sample_rate);
8947 + clk_set_rate(pcm512x->sclk, (ctype == HIFIBERRY_DACPRO_CLK44EN)
8948 + ? CLK_44EN_RATE : CLK_48EN_RATE);
8949 + snd_rpi_hifiberry_dacplusadc_select_clk(component, ctype);
8953 +static int snd_rpi_hifiberry_dacplusadc_init(struct snd_soc_pcm_runtime *rtd)
8955 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
8956 + struct pcm512x_priv *priv;
8959 + snd_rpi_hifiberry_is_dacpro = false;
8961 + snd_rpi_hifiberry_is_dacpro =
8962 + snd_rpi_hifiberry_dacplusadc_is_pro_card(component);
8964 + if (snd_rpi_hifiberry_is_dacpro) {
8965 + struct snd_soc_dai_link *dai = rtd->dai_link;
8967 + dai->name = "HiFiBerry ADCDAC+ Pro";
8968 + dai->stream_name = "HiFiBerry ADCDAC+ Pro HiFi";
8969 + dai->dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
8970 + | SND_SOC_DAIFMT_CBM_CFM;
8972 + snd_soc_component_update_bits(component, PCM512x_BCLK_LRCLK_CFG, 0x31, 0x11);
8973 + snd_soc_component_update_bits(component, PCM512x_MASTER_MODE, 0x03, 0x03);
8974 + snd_soc_component_update_bits(component, PCM512x_MASTER_CLKDIV_2, 0x7f, 63);
8976 + priv = snd_soc_component_get_drvdata(component);
8977 + priv->sclk = ERR_PTR(-ENOENT);
8980 + snd_soc_component_update_bits(component, PCM512x_GPIO_EN, 0x08, 0x08);
8981 + snd_soc_component_update_bits(component, PCM512x_GPIO_OUTPUT_4, 0x0f, 0x02);
8983 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x08, 0x00);
8985 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x08, 0x08);
8987 + if (digital_gain_0db_limit) {
8989 + struct snd_soc_card *card = rtd->card;
8991 + ret = snd_soc_limit_volume(card, "Digital Playback Volume", 207);
8993 + dev_warn(card->dev, "Failed to set volume limit: %d\n", ret);
8999 +static int snd_rpi_hifiberry_dacplusadc_update_rate_den(
9000 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
9002 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
9003 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
9004 + struct pcm512x_priv *pcm512x = snd_soc_component_get_drvdata(component);
9005 + struct snd_ratnum *rats_no_pll;
9006 + unsigned int num = 0, den = 0;
9009 + rats_no_pll = devm_kzalloc(rtd->dev, sizeof(*rats_no_pll), GFP_KERNEL);
9013 + rats_no_pll->num = clk_get_rate(pcm512x->sclk) / 64;
9014 + rats_no_pll->den_min = 1;
9015 + rats_no_pll->den_max = 128;
9016 + rats_no_pll->den_step = 1;
9018 + err = snd_interval_ratnum(hw_param_interval(params,
9019 + SNDRV_PCM_HW_PARAM_RATE), 1, rats_no_pll, &num, &den);
9020 + if (err >= 0 && den) {
9021 + params->rate_num = num;
9022 + params->rate_den = den;
9025 + devm_kfree(rtd->dev, rats_no_pll);
9029 +static int snd_rpi_hifiberry_dacplusadc_hw_params(
9030 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
9033 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
9034 + int channels = params_channels(params);
9037 + if (snd_rpi_hifiberry_is_dacpro) {
9038 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
9040 + width = snd_pcm_format_physical_width(params_format(params));
9042 + snd_rpi_hifiberry_dacplusadc_set_sclk(component,
9043 + params_rate(params));
9045 + ret = snd_rpi_hifiberry_dacplusadc_update_rate_den(
9046 + substream, params);
9049 + ret = snd_soc_dai_set_bclk_ratio(asoc_rtd_to_cpu(rtd, 0), channels * width);
9052 + ret = snd_soc_dai_set_bclk_ratio(asoc_rtd_to_codec(rtd, 0), channels * width);
9056 +static int hifiberry_dacplusadc_LED_cnt;
9058 +static int snd_rpi_hifiberry_dacplusadc_startup(
9059 + struct snd_pcm_substream *substream)
9061 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
9062 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
9066 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1,
9068 + hifiberry_dacplusadc_LED_cnt++;
9072 +static void snd_rpi_hifiberry_dacplusadc_shutdown(
9073 + struct snd_pcm_substream *substream)
9075 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
9076 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
9078 + hifiberry_dacplusadc_LED_cnt--;
9079 + if (!hifiberry_dacplusadc_LED_cnt)
9080 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1,
9084 +/* machine stream operations */
9085 +static struct snd_soc_ops snd_rpi_hifiberry_dacplusadc_ops = {
9086 + .hw_params = snd_rpi_hifiberry_dacplusadc_hw_params,
9087 + .startup = snd_rpi_hifiberry_dacplusadc_startup,
9088 + .shutdown = snd_rpi_hifiberry_dacplusadc_shutdown,
9091 +SND_SOC_DAILINK_DEFS(hifi,
9092 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
9093 + DAILINK_COMP_ARRAY(COMP_CODEC("pcm512x.1-004d", "pcm512x-hifi"),
9094 + COMP_CODEC("dmic-codec", "dmic-hifi")),
9095 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
9097 +static struct snd_soc_dai_link snd_rpi_hifiberry_dacplusadc_dai[] = {
9099 + .name = "HiFiBerry DAC+ADC",
9100 + .stream_name = "HiFiBerry DAC+ADC HiFi",
9101 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
9102 + SND_SOC_DAIFMT_CBS_CFS,
9103 + .ops = &snd_rpi_hifiberry_dacplusadc_ops,
9104 + .init = snd_rpi_hifiberry_dacplusadc_init,
9105 + SND_SOC_DAILINK_REG(hifi),
9109 +/* audio machine driver */
9110 +static struct snd_soc_card snd_rpi_hifiberry_dacplusadc = {
9111 + .name = "snd_rpi_hifiberry_dacplusadc",
9112 + .driver_name = "HifiberryDacpAdc",
9113 + .owner = THIS_MODULE,
9114 + .dai_link = snd_rpi_hifiberry_dacplusadc_dai,
9115 + .num_links = ARRAY_SIZE(snd_rpi_hifiberry_dacplusadc_dai),
9119 +static int snd_rpi_hifiberry_dacplusadc_probe(struct platform_device *pdev)
9123 + snd_rpi_hifiberry_dacplusadc.dev = &pdev->dev;
9124 + if (pdev->dev.of_node) {
9125 + struct device_node *i2s_node;
9126 + struct snd_soc_dai_link *dai;
9128 + dai = &snd_rpi_hifiberry_dacplusadc_dai[0];
9129 + i2s_node = of_parse_phandle(pdev->dev.of_node,
9130 + "i2s-controller", 0);
9132 + dai->cpus->of_node = i2s_node;
9133 + dai->platforms->of_node = i2s_node;
9134 + dai->cpus->dai_name = NULL;
9135 + dai->platforms->name = NULL;
9138 + digital_gain_0db_limit = !of_property_read_bool(
9139 + pdev->dev.of_node, "hifiberry,24db_digital_gain");
9140 + slave = of_property_read_bool(pdev->dev.of_node,
9141 + "hifiberry-dacplusadc,slave");
9142 + leds_off = of_property_read_bool(pdev->dev.of_node,
9143 + "hifiberry-dacplusadc,leds_off");
9145 + ret = devm_snd_soc_register_card(&pdev->dev,
9146 + &snd_rpi_hifiberry_dacplusadc);
9147 + if (ret && ret != -EPROBE_DEFER)
9148 + dev_err(&pdev->dev,
9149 + "snd_soc_register_card() failed: %d\n", ret);
9154 +static const struct of_device_id snd_rpi_hifiberry_dacplusadc_of_match[] = {
9155 + { .compatible = "hifiberry,hifiberry-dacplusadc", },
9159 +MODULE_DEVICE_TABLE(of, snd_rpi_hifiberry_dacplusadc_of_match);
9161 +static struct platform_driver snd_rpi_hifiberry_dacplusadc_driver = {
9163 + .name = "snd-rpi-hifiberry-dacplusadc",
9164 + .owner = THIS_MODULE,
9165 + .of_match_table = snd_rpi_hifiberry_dacplusadc_of_match,
9167 + .probe = snd_rpi_hifiberry_dacplusadc_probe,
9170 +static int __init hifiberry_dacplusadc_init(void)
9174 + dmic_codec_dev = platform_device_register_simple("dmic-codec", -1, NULL,
9176 + if (IS_ERR(dmic_codec_dev)) {
9177 + pr_err("%s: dmic-codec device registration failed\n", __func__);
9178 + return PTR_ERR(dmic_codec_dev);
9181 + ret = platform_driver_register(&snd_rpi_hifiberry_dacplusadc_driver);
9183 + pr_err("%s: platform driver registration failed\n", __func__);
9184 + platform_device_unregister(dmic_codec_dev);
9189 +module_init(hifiberry_dacplusadc_init);
9191 +static void __exit hifiberry_dacplusadc_exit(void)
9193 + platform_driver_unregister(&snd_rpi_hifiberry_dacplusadc_driver);
9194 + platform_device_unregister(dmic_codec_dev);
9196 +module_exit(hifiberry_dacplusadc_exit);
9198 +MODULE_AUTHOR("Joerg Schambacher <joscha@schambacher.com>");
9199 +MODULE_AUTHOR("Daniel Matuschek <daniel@hifiberry.com>");
9200 +MODULE_DESCRIPTION("ASoC Driver for HiFiBerry DAC+ADC");
9201 +MODULE_LICENSE("GPL v2");
9203 +++ b/sound/soc/bcm/hifiberry_dacplusadcpro.c
9206 + * ASoC Driver for HiFiBerry DAC+ / DAC Pro with ADC PRO Version (SW control)
9208 + * Author: Daniel Matuschek, Stuart MacLean <stuart@hifiberry.com>
9209 + * Copyright 2014-2015
9210 + * based on code by Florian Meier <florian.meier@koalo.de>
9211 + * ADC, HP added by Joerg Schambacher <joerg@hifiberry.com>
9212 + * Copyright 2018-21
9214 + * This program is free software; you can redistribute it and/or
9215 + * modify it under the terms of the GNU General Public License
9216 + * version 2 as published by the Free Software Foundation.
9218 + * This program is distributed in the hope that it will be useful, but
9219 + * WITHOUT ANY WARRANTY; without even the implied warranty of
9220 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9221 + * General Public License for more details.
9224 +#include <linux/module.h>
9225 +#include <linux/platform_device.h>
9226 +#include <linux/kernel.h>
9227 +#include <linux/clk.h>
9228 +#include <linux/kernel.h>
9229 +#include <linux/module.h>
9230 +#include <linux/of.h>
9231 +#include <linux/slab.h>
9232 +#include <linux/delay.h>
9233 +#include <linux/i2c.h>
9235 +#include <sound/core.h>
9236 +#include <sound/pcm.h>
9237 +#include <sound/pcm_params.h>
9238 +#include <sound/soc.h>
9239 +#include <sound/jack.h>
9240 +#include <sound/tlv.h>
9242 +#include "../codecs/pcm512x.h"
9243 +#include "../codecs/pcm186x.h"
9245 +#define HIFIBERRY_DACPRO_NOCLOCK 0
9246 +#define HIFIBERRY_DACPRO_CLK44EN 1
9247 +#define HIFIBERRY_DACPRO_CLK48EN 2
9249 +struct pcm512x_priv {
9250 + struct regmap *regmap;
9254 +/* Clock rate of CLK44EN attached to GPIO6 pin */
9255 +#define CLK_44EN_RATE 22579200UL
9256 +/* Clock rate of CLK48EN attached to GPIO3 pin */
9257 +#define CLK_48EN_RATE 24576000UL
9260 +static bool snd_rpi_hifiberry_is_dacpro;
9261 +static bool digital_gain_0db_limit = true;
9262 +static bool leds_off;
9264 +static const unsigned int pcm186x_adc_input_channel_sel_value[] = {
9265 + 0x00, 0x01, 0x02, 0x03, 0x10
9268 +static const char * const pcm186x_adcl_input_channel_sel_text[] = {
9270 + "VINL1[SE]", /* Default for ADCL */
9272 + "VINL2[SE] + VINL1[SE]",
9273 + "{VIN1P, VIN1M}[DIFF]"
9276 +static const char * const pcm186x_adcr_input_channel_sel_text[] = {
9278 + "VINR1[SE]", /* Default for ADCR */
9280 + "VINR2[SE] + VINR1[SE]",
9281 + "{VIN2P, VIN2M}[DIFF]"
9284 +static const struct soc_enum pcm186x_adc_input_channel_sel[] = {
9285 + SOC_VALUE_ENUM_SINGLE(PCM186X_ADC1_INPUT_SEL_L, 0,
9286 + PCM186X_ADC_INPUT_SEL_MASK,
9287 + ARRAY_SIZE(pcm186x_adcl_input_channel_sel_text),
9288 + pcm186x_adcl_input_channel_sel_text,
9289 + pcm186x_adc_input_channel_sel_value),
9290 + SOC_VALUE_ENUM_SINGLE(PCM186X_ADC1_INPUT_SEL_R, 0,
9291 + PCM186X_ADC_INPUT_SEL_MASK,
9292 + ARRAY_SIZE(pcm186x_adcr_input_channel_sel_text),
9293 + pcm186x_adcr_input_channel_sel_text,
9294 + pcm186x_adc_input_channel_sel_value),
9297 +static const unsigned int pcm186x_mic_bias_sel_value[] = {
9301 +static const char * const pcm186x_mic_bias_sel_text[] = {
9304 + "Mic Bias with Bypass Resistor"
9307 +static const struct soc_enum pcm186x_mic_bias_sel[] = {
9308 + SOC_VALUE_ENUM_SINGLE(PCM186X_MIC_BIAS_CTRL, 0,
9310 + ARRAY_SIZE(pcm186x_mic_bias_sel_text),
9311 + pcm186x_mic_bias_sel_text,
9312 + pcm186x_mic_bias_sel_value),
9315 +static const unsigned int pcm186x_gain_sel_value[] = {
9316 + 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
9317 + 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
9318 + 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
9319 + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
9320 + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
9321 + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
9322 + 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
9323 + 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
9324 + 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
9325 + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
9326 + 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
9327 + 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
9328 + 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
9332 +static const char * const pcm186x_gain_sel_text[] = {
9333 + "-12.0dB", "-11.5dB", "-11.0dB", "-10.5dB", "-10.0dB", "-9.5dB",
9334 + "-9.0dB", "-8.5dB", "-8.0dB", "-7.5dB", "-7.0dB", "-6.5dB",
9335 + "-6.0dB", "-5.5dB", "-5.0dB", "-4.5dB", "-4.0dB", "-3.5dB",
9336 + "-3.0dB", "-2.5dB", "-2.0dB", "-1.5dB", "-1.0dB", "-0.5dB",
9337 + "0.0dB", "0.5dB", "1.0dB", "1.5dB", "2.0dB", "2.5dB",
9338 + "3.0dB", "3.5dB", "4.0dB", "4.5dB", "5.0dB", "5.5dB",
9339 + "6.0dB", "6.5dB", "7.0dB", "7.5dB", "8.0dB", "8.5dB",
9340 + "9.0dB", "9.5dB", "10.0dB", "10.5dB", "11.0dB", "11.5dB",
9341 + "12.0dB", "12.5dB", "13.0dB", "13.5dB", "14.0dB", "14.5dB",
9342 + "15.0dB", "15.5dB", "16.0dB", "16.5dB", "17.0dB", "17.5dB",
9343 + "18.0dB", "18.5dB", "19.0dB", "19.5dB", "20.0dB", "20.5dB",
9344 + "21.0dB", "21.5dB", "22.0dB", "22.5dB", "23.0dB", "23.5dB",
9345 + "24.0dB", "24.5dB", "25.0dB", "25.5dB", "26.0dB", "26.5dB",
9346 + "27.0dB", "27.5dB", "28.0dB", "28.5dB", "29.0dB", "29.5dB",
9347 + "30.0dB", "30.5dB", "31.0dB", "31.5dB", "32.0dB", "32.5dB",
9348 + "33.0dB", "33.5dB", "34.0dB", "34.5dB", "35.0dB", "35.5dB",
9349 + "36.0dB", "36.5dB", "37.0dB", "37.5dB", "38.0dB", "38.5dB",
9350 + "39.0dB", "39.5dB", "40.0dB"};
9352 +static const struct soc_enum pcm186x_gain_sel[] = {
9353 + SOC_VALUE_ENUM_SINGLE(PCM186X_PGA_VAL_CH1_L, 0,
9355 + ARRAY_SIZE(pcm186x_gain_sel_text),
9356 + pcm186x_gain_sel_text,
9357 + pcm186x_gain_sel_value),
9358 + SOC_VALUE_ENUM_SINGLE(PCM186X_PGA_VAL_CH1_R, 0,
9360 + ARRAY_SIZE(pcm186x_gain_sel_text),
9361 + pcm186x_gain_sel_text,
9362 + pcm186x_gain_sel_value),
9365 +static const struct snd_kcontrol_new pcm1863_snd_controls_card[] = {
9366 + SOC_ENUM("ADC Left Input", pcm186x_adc_input_channel_sel[0]),
9367 + SOC_ENUM("ADC Right Input", pcm186x_adc_input_channel_sel[1]),
9368 + SOC_ENUM("ADC Mic Bias", pcm186x_mic_bias_sel),
9369 + SOC_ENUM("PGA Gain Left", pcm186x_gain_sel[0]),
9370 + SOC_ENUM("PGA Gain Right", pcm186x_gain_sel[1]),
9373 +static int pcm1863_add_controls(struct snd_soc_component *component)
9375 + snd_soc_add_component_controls(component,
9376 + pcm1863_snd_controls_card,
9377 + ARRAY_SIZE(pcm1863_snd_controls_card));
9381 +static void snd_rpi_hifiberry_dacplusadcpro_select_clk(
9382 + struct snd_soc_component *component, int clk_id)
9385 + case HIFIBERRY_DACPRO_NOCLOCK:
9386 + snd_soc_component_update_bits(component,
9387 + PCM512x_GPIO_CONTROL_1, 0x24, 0x00);
9389 + case HIFIBERRY_DACPRO_CLK44EN:
9390 + snd_soc_component_update_bits(component,
9391 + PCM512x_GPIO_CONTROL_1, 0x24, 0x20);
9393 + case HIFIBERRY_DACPRO_CLK48EN:
9394 + snd_soc_component_update_bits(component,
9395 + PCM512x_GPIO_CONTROL_1, 0x24, 0x04);
9398 + usleep_range(3000, 4000);
9401 +static void snd_rpi_hifiberry_dacplusadcpro_clk_gpio(struct snd_soc_component *component)
9403 + snd_soc_component_update_bits(component, PCM512x_GPIO_EN, 0x24, 0x24);
9404 + snd_soc_component_update_bits(component, PCM512x_GPIO_OUTPUT_3, 0x0f, 0x02);
9405 + snd_soc_component_update_bits(component, PCM512x_GPIO_OUTPUT_6, 0x0f, 0x02);
9408 +static bool snd_rpi_hifiberry_dacplusadcpro_is_sclk(struct snd_soc_component *component)
9412 + sck = snd_soc_component_read(component, PCM512x_RATE_DET_4);
9413 + return (!(sck & 0x40));
9416 +static bool snd_rpi_hifiberry_dacplusadcpro_is_pro_card(struct snd_soc_component *component)
9418 + bool isClk44EN, isClk48En, isNoClk;
9420 + snd_rpi_hifiberry_dacplusadcpro_clk_gpio(component);
9422 + snd_rpi_hifiberry_dacplusadcpro_select_clk(component, HIFIBERRY_DACPRO_CLK44EN);
9423 + isClk44EN = snd_rpi_hifiberry_dacplusadcpro_is_sclk(component);
9425 + snd_rpi_hifiberry_dacplusadcpro_select_clk(component, HIFIBERRY_DACPRO_NOCLOCK);
9426 + isNoClk = snd_rpi_hifiberry_dacplusadcpro_is_sclk(component);
9428 + snd_rpi_hifiberry_dacplusadcpro_select_clk(component, HIFIBERRY_DACPRO_CLK48EN);
9429 + isClk48En = snd_rpi_hifiberry_dacplusadcpro_is_sclk(component);
9431 + return (isClk44EN && isClk48En && !isNoClk);
9434 +static int snd_rpi_hifiberry_dacplusadcpro_clk_for_rate(int sample_rate)
9438 + switch (sample_rate) {
9445 + type = HIFIBERRY_DACPRO_CLK44EN;
9448 + type = HIFIBERRY_DACPRO_CLK48EN;
9454 +static void snd_rpi_hifiberry_dacplusadcpro_set_sclk(struct snd_soc_component *component,
9457 + struct pcm512x_priv *pcm512x = snd_soc_component_get_drvdata(component);
9459 + if (!IS_ERR(pcm512x->sclk)) {
9462 + ctype = snd_rpi_hifiberry_dacplusadcpro_clk_for_rate(sample_rate);
9463 + clk_set_rate(pcm512x->sclk, (ctype == HIFIBERRY_DACPRO_CLK44EN)
9464 + ? CLK_44EN_RATE : CLK_48EN_RATE);
9465 + snd_rpi_hifiberry_dacplusadcpro_select_clk(component, ctype);
9469 +static int snd_rpi_hifiberry_dacplusadcpro_init(struct snd_soc_pcm_runtime *rtd)
9471 + struct snd_soc_component *dac = asoc_rtd_to_codec(rtd, 0)->component;
9472 + struct snd_soc_component *adc = asoc_rtd_to_codec(rtd, 1)->component;
9473 + struct snd_soc_dai_driver *adc_driver = asoc_rtd_to_codec(rtd, 1)->driver;
9474 + struct pcm512x_priv *priv;
9478 + snd_rpi_hifiberry_is_dacpro = false;
9480 + snd_rpi_hifiberry_is_dacpro =
9481 + snd_rpi_hifiberry_dacplusadcpro_is_pro_card(dac);
9483 + if (snd_rpi_hifiberry_is_dacpro) {
9484 + struct snd_soc_dai_link *dai = rtd->dai_link;
9486 + dai->name = "HiFiBerry DAC+ADC Pro";
9487 + dai->stream_name = "HiFiBerry DAC+ADC Pro HiFi";
9488 + dai->dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
9489 + | SND_SOC_DAIFMT_CBM_CFM;
9491 + // set DAC DAI configuration
9492 + ret = snd_soc_dai_set_fmt(asoc_rtd_to_codec(rtd, 0),
9493 + SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
9494 + | SND_SOC_DAIFMT_CBM_CFM);
9498 + // set ADC DAI configuration
9499 + ret = snd_soc_dai_set_fmt(asoc_rtd_to_codec(rtd, 1),
9500 + SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
9501 + | SND_SOC_DAIFMT_CBS_CFS);
9505 + // set CPU DAI configuration
9506 + ret = snd_soc_dai_set_fmt(asoc_rtd_to_cpu(rtd, 0),
9507 + SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
9511 + snd_soc_component_update_bits(dac, PCM512x_BCLK_LRCLK_CFG, 0x31, 0x11);
9512 + snd_soc_component_update_bits(dac, PCM512x_MASTER_MODE, 0x03, 0x03);
9513 + snd_soc_component_update_bits(dac, PCM512x_MASTER_CLKDIV_2, 0x7f, 63);
9515 + priv = snd_soc_component_get_drvdata(dac);
9516 + priv->sclk = ERR_PTR(-ENOENT);
9519 + /* disable 24bit mode as long as I2S module does not have sign extension fixed */
9520 + adc_driver->capture.formats = SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S16_LE;
9522 + snd_soc_component_update_bits(dac, PCM512x_GPIO_EN, 0x08, 0x08);
9523 + snd_soc_component_update_bits(dac, PCM512x_GPIO_OUTPUT_4, 0x0f, 0x02);
9525 + snd_soc_component_update_bits(dac, PCM512x_GPIO_CONTROL_1, 0x08, 0x00);
9527 + snd_soc_component_update_bits(dac, PCM512x_GPIO_CONTROL_1, 0x08, 0x08);
9529 + ret = pcm1863_add_controls(adc);
9531 + dev_warn(rtd->dev, "Failed to add pcm1863 controls: %d\n",
9534 + /* set GPIO2 to output, GPIO3 input */
9535 + snd_soc_component_write(adc, PCM186X_GPIO3_2_CTRL, 0x00);
9536 + snd_soc_component_write(adc, PCM186X_GPIO3_2_DIR_CTRL, 0x04);
9538 + snd_soc_component_update_bits(adc, PCM186X_GPIO_IN_OUT, 0x40, 0x00);
9540 + snd_soc_component_update_bits(adc, PCM186X_GPIO_IN_OUT, 0x40, 0x40);
9542 + if (digital_gain_0db_limit) {
9544 + struct snd_soc_card *card = rtd->card;
9546 + ret = snd_soc_limit_volume(card, "Digital Playback Volume", 207);
9548 + dev_warn(card->dev, "Failed to set volume limit: %d\n", ret);
9554 +static int snd_rpi_hifiberry_dacplusadcpro_update_rate_den(
9555 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
9557 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
9558 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component; /* only use DAC */
9559 + struct pcm512x_priv *pcm512x = snd_soc_component_get_drvdata(component);
9560 + struct snd_ratnum *rats_no_pll;
9561 + unsigned int num = 0, den = 0;
9564 + rats_no_pll = devm_kzalloc(rtd->dev, sizeof(*rats_no_pll), GFP_KERNEL);
9568 + rats_no_pll->num = clk_get_rate(pcm512x->sclk) / 64;
9569 + rats_no_pll->den_min = 1;
9570 + rats_no_pll->den_max = 128;
9571 + rats_no_pll->den_step = 1;
9573 + err = snd_interval_ratnum(hw_param_interval(params,
9574 + SNDRV_PCM_HW_PARAM_RATE), 1, rats_no_pll, &num, &den);
9575 + if (err >= 0 && den) {
9576 + params->rate_num = num;
9577 + params->rate_den = den;
9580 + devm_kfree(rtd->dev, rats_no_pll);
9584 +static int snd_rpi_hifiberry_dacplusadcpro_hw_params(
9585 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
9588 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
9589 + int channels = params_channels(params);
9591 + struct snd_soc_component *dac = asoc_rtd_to_codec(rtd, 0)->component;
9592 + struct snd_soc_dai *dai = asoc_rtd_to_codec(rtd, 0);
9593 + struct snd_soc_dai_driver *drv = dai->driver;
9594 + const struct snd_soc_dai_ops *ops = drv->ops;
9596 + if (snd_rpi_hifiberry_is_dacpro) {
9597 + width = snd_pcm_format_physical_width(params_format(params));
9599 + snd_rpi_hifiberry_dacplusadcpro_set_sclk(dac,
9600 + params_rate(params));
9602 + ret = snd_rpi_hifiberry_dacplusadcpro_update_rate_den(
9603 + substream, params);
9608 + ret = snd_soc_dai_set_bclk_ratio(asoc_rtd_to_cpu(rtd, 0), channels * width);
9611 + ret = snd_soc_dai_set_bclk_ratio(asoc_rtd_to_codec(rtd, 0), channels * width);
9614 + if (snd_rpi_hifiberry_is_dacpro && ops->hw_params)
9615 + ret = ops->hw_params(substream, params, dai);
9619 +static int snd_rpi_hifiberry_dacplusadcpro_startup(
9620 + struct snd_pcm_substream *substream)
9622 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
9623 + struct snd_soc_component *dac = asoc_rtd_to_codec(rtd, 0)->component;
9624 + struct snd_soc_component *adc = asoc_rtd_to_codec(rtd, 1)->component;
9628 + /* switch on respective LED */
9629 + if (!substream->stream)
9630 + snd_soc_component_update_bits(dac, PCM512x_GPIO_CONTROL_1, 0x08, 0x08);
9632 + snd_soc_component_update_bits(adc, PCM186X_GPIO_IN_OUT, 0x40, 0x40);
9636 +static void snd_rpi_hifiberry_dacplusadcpro_shutdown(
9637 + struct snd_pcm_substream *substream)
9639 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
9640 + struct snd_soc_component *dac = asoc_rtd_to_codec(rtd, 0)->component;
9641 + struct snd_soc_component *adc = asoc_rtd_to_codec(rtd, 1)->component;
9643 + /* switch off respective LED */
9644 + if (!substream->stream)
9645 + snd_soc_component_update_bits(dac, PCM512x_GPIO_CONTROL_1, 0x08, 0x00);
9647 + snd_soc_component_update_bits(adc, PCM186X_GPIO_IN_OUT, 0x40, 0x00);
9651 +/* machine stream operations */
9652 +static struct snd_soc_ops snd_rpi_hifiberry_dacplusadcpro_ops = {
9653 + .hw_params = snd_rpi_hifiberry_dacplusadcpro_hw_params,
9654 + .startup = snd_rpi_hifiberry_dacplusadcpro_startup,
9655 + .shutdown = snd_rpi_hifiberry_dacplusadcpro_shutdown,
9658 +SND_SOC_DAILINK_DEFS(hifi,
9659 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
9660 + DAILINK_COMP_ARRAY(COMP_CODEC("pcm512x.1-004d", "pcm512x-hifi"),
9661 + COMP_CODEC("pcm186x.1-004a", "pcm1863-aif")),
9662 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
9664 +static struct snd_soc_dai_link snd_rpi_hifiberry_dacplusadcpro_dai[] = {
9666 + .name = "HiFiBerry DAC+ADC PRO",
9667 + .stream_name = "HiFiBerry DAC+ADC PRO HiFi",
9668 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
9669 + SND_SOC_DAIFMT_CBS_CFS,
9670 + .ops = &snd_rpi_hifiberry_dacplusadcpro_ops,
9671 + .init = snd_rpi_hifiberry_dacplusadcpro_init,
9672 + SND_SOC_DAILINK_REG(hifi),
9676 +/* aux device for optional headphone amp */
9677 +static struct snd_soc_aux_dev hifiberry_dacplusadcpro_aux_devs[] = {
9680 + .name = "tpa6130a2.1-0060",
9685 +/* audio machine driver */
9686 +static struct snd_soc_card snd_rpi_hifiberry_dacplusadcpro = {
9687 + .name = "snd_rpi_hifiberry_dacplusadcpro",
9688 + .driver_name = "HifiberryDacpAdcPro",
9689 + .owner = THIS_MODULE,
9690 + .dai_link = snd_rpi_hifiberry_dacplusadcpro_dai,
9691 + .num_links = ARRAY_SIZE(snd_rpi_hifiberry_dacplusadcpro_dai),
9694 +static int hb_hp_detect(void)
9696 + struct i2c_adapter *adap = i2c_get_adapter(1);
9698 + struct i2c_client tpa_i2c_client = {
9704 + return -EPROBE_DEFER; /* I2C module not yet available */
9706 + ret = i2c_smbus_read_byte(&tpa_i2c_client) >= 0;
9707 + i2c_put_adapter(adap);
9711 +static struct property tpa_enable_prop = {
9713 + .length = 4 + 1, /* length 'okay' + 1 */
9717 +static int snd_rpi_hifiberry_dacplusadcpro_probe(struct platform_device *pdev)
9719 + int ret = 0, i = 0;
9720 + struct snd_soc_card *card = &snd_rpi_hifiberry_dacplusadcpro;
9721 + struct device_node *tpa_node;
9722 + struct property *tpa_prop;
9723 + struct of_changeset ocs;
9726 + /* probe for head phone amp */
9727 + ret = hb_hp_detect();
9731 + card->aux_dev = hifiberry_dacplusadcpro_aux_devs;
9732 + card->num_aux_devs =
9733 + ARRAY_SIZE(hifiberry_dacplusadcpro_aux_devs);
9734 + tpa_node = of_find_compatible_node(NULL, NULL, "ti,tpa6130a2");
9735 + tpa_prop = of_find_property(tpa_node, "status", &len);
9737 + if (strcmp((char *)tpa_prop->value, "okay")) {
9738 + /* and activate headphone using change_sets */
9739 + dev_info(&pdev->dev, "activating headphone amplifier");
9740 + of_changeset_init(&ocs);
9741 + ret = of_changeset_update_property(&ocs, tpa_node,
9742 + &tpa_enable_prop);
9744 + dev_err(&pdev->dev,
9745 + "cannot activate headphone amplifier\n");
9748 + ret = of_changeset_apply(&ocs);
9750 + dev_err(&pdev->dev,
9751 + "cannot activate headphone amplifier\n");
9757 + snd_rpi_hifiberry_dacplusadcpro.dev = &pdev->dev;
9758 + if (pdev->dev.of_node) {
9759 + struct device_node *i2s_node;
9760 + struct snd_soc_dai_link *dai;
9762 + dai = &snd_rpi_hifiberry_dacplusadcpro_dai[0];
9763 + i2s_node = of_parse_phandle(pdev->dev.of_node,
9764 + "i2s-controller", 0);
9766 + for (i = 0; i < card->num_links; i++) {
9767 + dai->cpus->dai_name = NULL;
9768 + dai->cpus->of_node = i2s_node;
9769 + dai->platforms->name = NULL;
9770 + dai->platforms->of_node = i2s_node;
9774 + digital_gain_0db_limit = !of_property_read_bool(
9775 + pdev->dev.of_node, "hifiberry-dacplusadcpro,24db_digital_gain");
9776 + slave = of_property_read_bool(pdev->dev.of_node,
9777 + "hifiberry-dacplusadcpro,slave");
9778 + leds_off = of_property_read_bool(pdev->dev.of_node,
9779 + "hifiberry-dacplusadcpro,leds_off");
9780 + ret = snd_soc_register_card(&snd_rpi_hifiberry_dacplusadcpro);
9781 + if (ret && ret != -EPROBE_DEFER)
9782 + dev_err(&pdev->dev,
9783 + "snd_soc_register_card() failed: %d\n", ret);
9788 +static const struct of_device_id snd_rpi_hifiberry_dacplusadcpro_of_match[] = {
9789 + { .compatible = "hifiberry,hifiberry-dacplusadcpro", },
9793 +MODULE_DEVICE_TABLE(of, snd_rpi_hifiberry_dacplusadcpro_of_match);
9795 +static struct platform_driver snd_rpi_hifiberry_dacplusadcpro_driver = {
9797 + .name = "snd-rpi-hifiberry-dacplusadcpro",
9798 + .owner = THIS_MODULE,
9799 + .of_match_table = snd_rpi_hifiberry_dacplusadcpro_of_match,
9801 + .probe = snd_rpi_hifiberry_dacplusadcpro_probe,
9804 +module_platform_driver(snd_rpi_hifiberry_dacplusadcpro_driver);
9806 +MODULE_AUTHOR("Joerg Schambacher <joerg@hifiberry.com>");
9807 +MODULE_AUTHOR("Daniel Matuschek <daniel@hifiberry.com>");
9808 +MODULE_DESCRIPTION("ASoC Driver for HiFiBerry DAC+ADC");
9809 +MODULE_LICENSE("GPL v2");
9811 +++ b/sound/soc/bcm/hifiberry_dacplusdsp.c
9813 +// SPDX-License-Identifier: GPL-2.0
9815 + * ASoC Driver for HiFiBerry DAC + DSP
9817 + * Author: Joerg Schambacher <joscha@schambacher.com>
9820 + * This program is free software; you can redistribute it and/or
9821 + * modify it under the terms of the GNU General Public License
9822 + * version 2 as published by the Free Software Foundation.
9824 + * This program is distributed in the hope that it will be useful, but
9825 + * WITHOUT ANY WARRANTY; without even the implied warranty of
9826 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9827 + * General Public License for more details.
9830 +#include <linux/init.h>
9831 +#include <linux/module.h>
9832 +#include <linux/of.h>
9833 +#include <linux/platform_device.h>
9834 +#include <sound/soc.h>
9836 +static struct snd_soc_component_driver dacplusdsp_component_driver;
9838 +static struct snd_soc_dai_driver dacplusdsp_dai = {
9839 + .name = "dacplusdsp-hifi",
9841 + .stream_name = "DAC+DSP Capture",
9842 + .channels_min = 2,
9843 + .channels_max = 2,
9844 + .rates = SNDRV_PCM_RATE_CONTINUOUS,
9845 + .formats = SNDRV_PCM_FMTBIT_S16_LE |
9846 + SNDRV_PCM_FMTBIT_S24_LE |
9847 + SNDRV_PCM_FMTBIT_S32_LE,
9850 + .stream_name = "DACP+DSP Playback",
9851 + .channels_min = 2,
9852 + .channels_max = 2,
9853 + .rates = SNDRV_PCM_RATE_CONTINUOUS,
9854 + .formats = SNDRV_PCM_FMTBIT_S16_LE |
9855 + SNDRV_PCM_FMTBIT_S24_LE |
9856 + SNDRV_PCM_FMTBIT_S32_LE,
9858 + .symmetric_rate = 1};
9861 +static const struct of_device_id dacplusdsp_ids[] = {
9863 + .compatible = "hifiberry,dacplusdsp",
9866 +MODULE_DEVICE_TABLE(of, dacplusdsp_ids);
9869 +static int dacplusdsp_platform_probe(struct platform_device *pdev)
9873 + ret = snd_soc_register_component(&pdev->dev,
9874 + &dacplusdsp_component_driver, &dacplusdsp_dai, 1);
9876 + pr_alert("snd_soc_register_component failed\n");
9883 +static int dacplusdsp_platform_remove(struct platform_device *pdev)
9885 + snd_soc_unregister_component(&pdev->dev);
9889 +static struct platform_driver dacplusdsp_driver = {
9891 + .name = "hifiberry-dacplusdsp-codec",
9892 + .of_match_table = of_match_ptr(dacplusdsp_ids),
9894 + .probe = dacplusdsp_platform_probe,
9895 + .remove = dacplusdsp_platform_remove,
9898 +module_platform_driver(dacplusdsp_driver);
9900 +MODULE_AUTHOR("Joerg Schambacher <joerg@i2audio.com>");
9901 +MODULE_DESCRIPTION("ASoC Driver for HiFiBerry DAC+DSP");
9902 +MODULE_LICENSE("GPL v2");
9904 +++ b/sound/soc/bcm/hifiberry_dacplushd.c
9906 +// SPDX-License-Identifier: GPL-2.0
9908 + * ASoC Driver for HiFiBerry DAC+ HD
9910 + * Author: Joerg Schambacher, i2Audio GmbH for HiFiBerry
9913 + * This program is free software; you can redistribute it and/or
9914 + * modify it under the terms of the GNU General Public License
9915 + * version 2 as published by the Free Software Foundation.
9917 + * This program is distributed in the hope that it will be useful, but
9918 + * WITHOUT ANY WARRANTY; without even the implied warranty of
9919 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9920 + * General Public License for more details.
9923 +#include <linux/module.h>
9924 +#include <linux/platform_device.h>
9925 +#include <linux/kernel.h>
9926 +#include <linux/delay.h>
9927 +#include <linux/module.h>
9928 +#include <linux/of.h>
9929 +#include <linux/delay.h>
9930 +#include <linux/gpio.h>
9931 +#include <linux/gpio/consumer.h>
9932 +#include <sound/core.h>
9933 +#include <sound/pcm.h>
9934 +#include <sound/pcm_params.h>
9935 +#include <sound/soc.h>
9936 +#include <linux/i2c.h>
9937 +#include <linux/clk.h>
9939 +#include "../codecs/pcm179x.h"
9941 +#define DEFAULT_RATE 44100
9943 +struct brd_drv_data {
9944 + struct regmap *regmap;
9948 +static struct brd_drv_data drvdata;
9949 +static struct gpio_desc *reset_gpio;
9950 +static const unsigned int hb_dacplushd_rates[] = {
9951 + 192000, 96000, 48000, 176400, 88200, 44100,
9954 +static struct snd_pcm_hw_constraint_list hb_dacplushd_constraints = {
9955 + .list = hb_dacplushd_rates,
9956 + .count = ARRAY_SIZE(hb_dacplushd_rates),
9959 +static int snd_rpi_hb_dacplushd_startup(struct snd_pcm_substream *substream)
9961 + /* constraints for standard sample rates */
9962 + snd_pcm_hw_constraint_list(substream->runtime, 0,
9963 + SNDRV_PCM_HW_PARAM_RATE,
9964 + &hb_dacplushd_constraints);
9968 +static void snd_rpi_hifiberry_dacplushd_set_sclk(
9969 + struct snd_soc_component *component,
9972 + if (!IS_ERR(drvdata.sclk))
9973 + clk_set_rate(drvdata.sclk, sample_rate);
9976 +static int snd_rpi_hifiberry_dacplushd_init(struct snd_soc_pcm_runtime *rtd)
9978 + struct snd_soc_dai_link *dai = rtd->dai_link;
9979 + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
9981 + dai->name = "HiFiBerry DAC+ HD";
9982 + dai->stream_name = "HiFiBerry DAC+ HD HiFi";
9983 + dai->dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
9984 + | SND_SOC_DAIFMT_CBM_CFM;
9986 + /* allow only fixed 32 clock counts per channel */
9987 + snd_soc_dai_set_bclk_ratio(cpu_dai, 32*2);
9992 +static int snd_rpi_hifiberry_dacplushd_hw_params(
9993 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
9996 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
9998 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
10000 + snd_rpi_hifiberry_dacplushd_set_sclk(component, params_rate(params));
10004 +/* machine stream operations */
10005 +static struct snd_soc_ops snd_rpi_hifiberry_dacplushd_ops = {
10006 + .startup = snd_rpi_hb_dacplushd_startup,
10007 + .hw_params = snd_rpi_hifiberry_dacplushd_hw_params,
10010 +SND_SOC_DAILINK_DEFS(hifi,
10011 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
10012 + DAILINK_COMP_ARRAY(COMP_CODEC("pcm179x.1-004c", "pcm179x-hifi")),
10013 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
10016 +static struct snd_soc_dai_link snd_rpi_hifiberry_dacplushd_dai[] = {
10018 + .name = "HiFiBerry DAC+ HD",
10019 + .stream_name = "HiFiBerry DAC+ HD HiFi",
10020 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
10021 + SND_SOC_DAIFMT_CBS_CFS,
10022 + .ops = &snd_rpi_hifiberry_dacplushd_ops,
10023 + .init = snd_rpi_hifiberry_dacplushd_init,
10024 + SND_SOC_DAILINK_REG(hifi),
10028 +/* audio machine driver */
10029 +static struct snd_soc_card snd_rpi_hifiberry_dacplushd = {
10030 + .name = "snd_rpi_hifiberry_dacplushd",
10031 + .driver_name = "HifiberryDacplusHD",
10032 + .owner = THIS_MODULE,
10033 + .dai_link = snd_rpi_hifiberry_dacplushd_dai,
10034 + .num_links = ARRAY_SIZE(snd_rpi_hifiberry_dacplushd_dai),
10037 +static int snd_rpi_hifiberry_dacplushd_probe(struct platform_device *pdev)
10040 + static int dac_reset_done;
10041 + struct device *dev = &pdev->dev;
10042 + struct device_node *dev_node = dev->of_node;
10044 + snd_rpi_hifiberry_dacplushd.dev = &pdev->dev;
10046 + /* get GPIO and release DAC from RESET */
10047 + if (!dac_reset_done) {
10048 + reset_gpio = gpiod_get(&pdev->dev, "reset", GPIOD_OUT_LOW);
10049 + if (IS_ERR(reset_gpio)) {
10050 + dev_err(&pdev->dev, "gpiod_get() failed\n");
10053 + dac_reset_done = 1;
10055 + if (!IS_ERR(reset_gpio))
10056 + gpiod_set_value(reset_gpio, 0);
10058 + if (!IS_ERR(reset_gpio))
10059 + gpiod_set_value(reset_gpio, 1);
10061 + if (!IS_ERR(reset_gpio))
10062 + gpiod_set_value(reset_gpio, 0);
10064 + if (pdev->dev.of_node) {
10065 + struct device_node *i2s_node;
10066 + struct snd_soc_dai_link *dai;
10068 + dai = &snd_rpi_hifiberry_dacplushd_dai[0];
10069 + i2s_node = of_parse_phandle(pdev->dev.of_node,
10070 + "i2s-controller", 0);
10073 + dai->cpus->of_node = i2s_node;
10074 + dai->platforms->of_node = i2s_node;
10075 + dai->cpus->dai_name = NULL;
10076 + dai->platforms->name = NULL;
10078 + return -EPROBE_DEFER;
10083 + ret = devm_snd_soc_register_card(&pdev->dev,
10084 + &snd_rpi_hifiberry_dacplushd);
10085 + if (ret && ret != -EPROBE_DEFER) {
10086 + dev_err(&pdev->dev,
10087 + "snd_soc_register_card() failed: %d\n", ret);
10090 + if (ret == -EPROBE_DEFER)
10093 + dev_set_drvdata(dev, &drvdata);
10094 + if (dev_node == NULL) {
10095 + dev_err(&pdev->dev, "Device tree node not found\n");
10099 + drvdata.sclk = devm_clk_get(dev, NULL);
10100 + if (IS_ERR(drvdata.sclk)) {
10101 + drvdata.sclk = ERR_PTR(-ENOENT);
10105 + clk_set_rate(drvdata.sclk, DEFAULT_RATE);
10110 +static int snd_rpi_hifiberry_dacplushd_remove(struct platform_device *pdev)
10112 + if (IS_ERR(reset_gpio))
10115 + /* put DAC into RESET and release GPIO */
10116 + gpiod_set_value(reset_gpio, 0);
10117 + gpiod_put(reset_gpio);
10122 +static const struct of_device_id snd_rpi_hifiberry_dacplushd_of_match[] = {
10123 + { .compatible = "hifiberry,hifiberry-dacplushd", },
10127 +MODULE_DEVICE_TABLE(of, snd_rpi_hifiberry_dacplushd_of_match);
10129 +static struct platform_driver snd_rpi_hifiberry_dacplushd_driver = {
10131 + .name = "snd-rpi-hifiberry-dacplushd",
10132 + .owner = THIS_MODULE,
10133 + .of_match_table = snd_rpi_hifiberry_dacplushd_of_match,
10135 + .probe = snd_rpi_hifiberry_dacplushd_probe,
10136 + .remove = snd_rpi_hifiberry_dacplushd_remove,
10139 +module_platform_driver(snd_rpi_hifiberry_dacplushd_driver);
10141 +MODULE_AUTHOR("Joerg Schambacher <joerg@i2audio.com>");
10142 +MODULE_DESCRIPTION("ASoC Driver for HiFiBerry DAC+ HD");
10143 +MODULE_LICENSE("GPL v2");
10145 +++ b/sound/soc/bcm/i-sabre-q2m.c
10148 + * ASoC Driver for I-Sabre Q2M
10150 + * Author: Satoru Kawase
10151 + * Modified by: Xiao Qingyong
10152 + * Update kernel v4.18+ by : Audiophonics
10153 + * Copyright 2018 Audiophonics
10155 + * This program is free software; you can redistribute it and/or
10156 + * modify it under the terms of the GNU General Public License
10157 + * version 2 as published by the Free Software Foundation.
10159 + * This program is distributed in the hope that it will be useful, but
10160 + * WITHOUT ANY WARRANTY; without even the implied warranty of
10161 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10162 + * General Public License for more details.
10165 +#include <linux/kernel.h>
10166 +#include <linux/init.h>
10167 +#include <linux/module.h>
10168 +#include <linux/delay.h>
10169 +#include <linux/fs.h>
10170 +#include <asm/uaccess.h>
10171 +#include <sound/core.h>
10172 +#include <sound/soc.h>
10173 +#include <sound/pcm.h>
10174 +#include <sound/pcm_params.h>
10176 +#include "../codecs/i-sabre-codec.h"
10179 +static int snd_rpi_i_sabre_q2m_init(struct snd_soc_pcm_runtime *rtd)
10181 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
10182 + unsigned int value;
10185 + value = snd_soc_component_read(component, ISABRECODEC_REG_01);
10186 + dev_info(component->card->dev, "Audiophonics Device ID : %02X\n", value);
10188 + /* API revision */
10189 + value = snd_soc_component_read(component, ISABRECODEC_REG_02);
10190 + dev_info(component->card->dev, "Audiophonics API revision : %02X\n", value);
10195 +static int snd_rpi_i_sabre_q2m_hw_params(
10196 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
10198 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
10199 + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
10202 + bclk_ratio = snd_pcm_format_physical_width(
10203 + params_format(params)) * params_channels(params);
10204 + return snd_soc_dai_set_bclk_ratio(cpu_dai, bclk_ratio);
10207 +/* machine stream operations */
10208 +static struct snd_soc_ops snd_rpi_i_sabre_q2m_ops = {
10209 + .hw_params = snd_rpi_i_sabre_q2m_hw_params,
10212 +SND_SOC_DAILINK_DEFS(rpi_i_sabre_q2m,
10213 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
10214 + DAILINK_COMP_ARRAY(COMP_CODEC("i-sabre-codec-i2c.1-0048", "i-sabre-codec-dai")),
10215 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
10217 +static struct snd_soc_dai_link snd_rpi_i_sabre_q2m_dai[] = {
10219 + .name = "I-Sabre Q2M",
10220 + .stream_name = "I-Sabre Q2M DAC",
10221 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
10222 + | SND_SOC_DAIFMT_CBS_CFS,
10223 + .init = snd_rpi_i_sabre_q2m_init,
10224 + .ops = &snd_rpi_i_sabre_q2m_ops,
10225 + SND_SOC_DAILINK_REG(rpi_i_sabre_q2m),
10229 +/* audio machine driver */
10230 +static struct snd_soc_card snd_rpi_i_sabre_q2m = {
10231 + .name = "I-Sabre Q2M DAC",
10232 + .owner = THIS_MODULE,
10233 + .dai_link = snd_rpi_i_sabre_q2m_dai,
10234 + .num_links = ARRAY_SIZE(snd_rpi_i_sabre_q2m_dai)
10238 +static int snd_rpi_i_sabre_q2m_probe(struct platform_device *pdev)
10242 + snd_rpi_i_sabre_q2m.dev = &pdev->dev;
10243 + if (pdev->dev.of_node) {
10244 + struct device_node *i2s_node;
10245 + struct snd_soc_dai_link *dai;
10247 + dai = &snd_rpi_i_sabre_q2m_dai[0];
10248 + i2s_node = of_parse_phandle(pdev->dev.of_node,
10249 + "i2s-controller", 0);
10251 + dai->cpus->dai_name = NULL;
10252 + dai->cpus->of_node = i2s_node;
10253 + dai->platforms->name = NULL;
10254 + dai->platforms->of_node = i2s_node;
10256 + dev_err(&pdev->dev,
10257 + "Property 'i2s-controller' missing or invalid\n");
10258 + return (-EINVAL);
10261 + dai->name = "I-Sabre Q2M";
10262 + dai->stream_name = "I-Sabre Q2M DAC";
10263 + dai->dai_fmt = SND_SOC_DAIFMT_I2S
10264 + | SND_SOC_DAIFMT_NB_NF
10265 + | SND_SOC_DAIFMT_CBS_CFS;
10268 + /* Wait for registering codec driver */
10271 + ret = snd_soc_register_card(&snd_rpi_i_sabre_q2m);
10273 + dev_err(&pdev->dev,
10274 + "snd_soc_register_card() failed: %d\n", ret);
10280 +static int snd_rpi_i_sabre_q2m_remove(struct platform_device *pdev)
10282 + snd_soc_unregister_card(&snd_rpi_i_sabre_q2m);
10286 +static const struct of_device_id snd_rpi_i_sabre_q2m_of_match[] = {
10287 + { .compatible = "audiophonics,i-sabre-q2m", },
10290 +MODULE_DEVICE_TABLE(of, snd_rpi_i_sabre_q2m_of_match);
10292 +static struct platform_driver snd_rpi_i_sabre_q2m_driver = {
10294 + .name = "snd-rpi-i-sabre-q2m",
10295 + .owner = THIS_MODULE,
10296 + .of_match_table = snd_rpi_i_sabre_q2m_of_match,
10298 + .probe = snd_rpi_i_sabre_q2m_probe,
10299 + .remove = snd_rpi_i_sabre_q2m_remove,
10301 +module_platform_driver(snd_rpi_i_sabre_q2m_driver);
10303 +MODULE_DESCRIPTION("ASoC Driver for I-Sabre Q2M");
10304 +MODULE_AUTHOR("Audiophonics <http://www.audiophonics.fr>");
10305 +MODULE_LICENSE("GPL");
10307 +++ b/sound/soc/bcm/iqaudio-codec.c
10310 + * ASoC Driver for IQaudIO Raspberry Pi Codec board
10312 + * Author: Gordon Garrity <gordon@iqaudio.com>
10313 + * (C) Copyright IQaudio Limited, 2017-2019
10315 + * This program is free software; you can redistribute it and/or
10316 + * modify it under the terms of the GNU General Public License
10317 + * version 2 as published by the Free Software Foundation.
10319 + * This program is distributed in the hope that it will be useful, but
10320 + * WITHOUT ANY WARRANTY; without even the implied warranty of
10321 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10322 + * General Public License for more details.
10325 +#include <linux/module.h>
10326 +#include <linux/gpio/consumer.h>
10327 +#include <linux/platform_device.h>
10329 +#include <sound/core.h>
10330 +#include <sound/pcm.h>
10331 +#include <sound/pcm_params.h>
10332 +#include <sound/soc.h>
10333 +#include <sound/jack.h>
10335 +#include <linux/acpi.h>
10336 +#include <linux/slab.h>
10337 +#include "../codecs/da7213.h"
10339 +static int pll_out = DA7213_PLL_FREQ_OUT_90316800;
10341 +static int snd_rpi_iqaudio_pll_control(struct snd_soc_dapm_widget *w,
10342 + struct snd_kcontrol *k, int event)
10345 + struct snd_soc_dapm_context *dapm = w->dapm;
10346 + struct snd_soc_card *card = dapm->card;
10347 + struct snd_soc_pcm_runtime *rtd =
10348 + snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
10349 + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
10351 + if (SND_SOC_DAPM_EVENT_OFF(event)) {
10352 + ret = snd_soc_dai_set_pll(codec_dai, 0, DA7213_SYSCLK_MCLK, 0,
10355 + dev_err(card->dev, "Failed to bypass PLL: %d\n", ret);
10356 + /* Allow PLL time to bypass */
10358 + } else if (SND_SOC_DAPM_EVENT_ON(event)) {
10359 + ret = snd_soc_dai_set_pll(codec_dai, 0, DA7213_SYSCLK_PLL, 0,
10362 + dev_err(card->dev, "Failed to enable PLL: %d\n", ret);
10363 + /* Allow PLL time to lock */
10370 +static int snd_rpi_iqaudio_post_dapm_event(struct snd_soc_dapm_widget *w,
10371 + struct snd_kcontrol *kcontrol,
10375 + case SND_SOC_DAPM_POST_PMU:
10376 + /* Delay for mic bias ramp */
10386 +static const struct snd_kcontrol_new dapm_controls[] = {
10387 + SOC_DAPM_PIN_SWITCH("HP Jack"),
10388 + SOC_DAPM_PIN_SWITCH("MIC Jack"),
10389 + SOC_DAPM_PIN_SWITCH("Onboard MIC"),
10390 + SOC_DAPM_PIN_SWITCH("AUX Jack"),
10393 +static const struct snd_soc_dapm_widget dapm_widgets[] = {
10394 + SND_SOC_DAPM_HP("HP Jack", NULL),
10395 + SND_SOC_DAPM_MIC("MIC Jack", NULL),
10396 + SND_SOC_DAPM_MIC("Onboard MIC", NULL),
10397 + SND_SOC_DAPM_LINE("AUX Jack", NULL),
10398 + SND_SOC_DAPM_SUPPLY("PLL Control", SND_SOC_NOPM, 0, 0,
10399 + snd_rpi_iqaudio_pll_control,
10400 + SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
10401 + SND_SOC_DAPM_POST("Post Power Up Event", snd_rpi_iqaudio_post_dapm_event),
10404 +static const struct snd_soc_dapm_route audio_map[] = {
10405 + {"HP Jack", NULL, "HPL"},
10406 + {"HP Jack", NULL, "HPR"},
10407 + {"HP Jack", NULL, "PLL Control"},
10409 + {"AUXR", NULL, "AUX Jack"},
10410 + {"AUXL", NULL, "AUX Jack"},
10411 + {"AUX Jack", NULL, "PLL Control"},
10413 + /* Assume Mic1 is linked to Headset and Mic2 to on-board mic */
10414 + {"MIC1", NULL, "MIC Jack"},
10415 + {"MIC Jack", NULL, "PLL Control"},
10416 + {"MIC2", NULL, "Onboard MIC"},
10417 + {"Onboard MIC", NULL, "PLL Control"},
10420 +/* machine stream operations */
10422 +static int snd_rpi_iqaudio_codec_init(struct snd_soc_pcm_runtime *rtd)
10424 + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
10425 + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
10429 + * Disable AUX Jack Pin by default to prevent PLL being enabled at
10430 + * startup. This avoids holding the PLL to a fixed SR config for
10431 + * subsequent streams.
10433 + * This pin can still be enabled later, as required by user-space.
10435 + snd_soc_dapm_disable_pin(&rtd->card->dapm, "AUX Jack");
10436 + snd_soc_dapm_sync(&rtd->card->dapm);
10438 + /* Set bclk ratio to align with codec's BCLK rate */
10439 + ret = snd_soc_dai_set_bclk_ratio(cpu_dai, 64);
10441 + dev_err(rtd->dev, "Failed to set CPU BLCK ratio\n");
10445 + /* Set MCLK frequency to codec, onboard 11.2896MHz clock */
10446 + return snd_soc_dai_set_sysclk(codec_dai, DA7213_CLKSRC_MCLK, 11289600,
10447 + SND_SOC_CLOCK_OUT);
10450 +static int snd_rpi_iqaudio_codec_hw_params(struct snd_pcm_substream *substream,
10451 + struct snd_pcm_hw_params *params)
10453 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
10454 + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
10455 + unsigned int samplerate = params_rate(params);
10457 + switch (samplerate) {
10463 + pll_out = DA7213_PLL_FREQ_OUT_98304000;
10467 + pll_out = DA7213_PLL_FREQ_OUT_90316800;
10470 + dev_err(rtd->dev,"Unsupported samplerate %d\n", samplerate);
10474 + return snd_soc_dai_set_pll(codec_dai, 0, DA7213_SYSCLK_PLL, 0, pll_out);
10477 +static const struct snd_soc_ops snd_rpi_iqaudio_codec_ops = {
10478 + .hw_params = snd_rpi_iqaudio_codec_hw_params,
10481 +SND_SOC_DAILINK_DEFS(rpi_iqaudio,
10482 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
10483 + DAILINK_COMP_ARRAY(COMP_CODEC("da7213.1-001a", "da7213-hifi")),
10484 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2835-i2s.0")));
10486 +static struct snd_soc_dai_link snd_rpi_iqaudio_codec_dai[] = {
10488 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
10489 + SND_SOC_DAIFMT_CBM_CFM,
10490 + .init = snd_rpi_iqaudio_codec_init,
10491 + .ops = &snd_rpi_iqaudio_codec_ops,
10492 + .symmetric_rate = 1,
10493 + .symmetric_channels = 1,
10494 + .symmetric_sample_bits = 1,
10495 + SND_SOC_DAILINK_REG(rpi_iqaudio),
10499 +/* audio machine driver */
10500 +static struct snd_soc_card snd_rpi_iqaudio_codec = {
10501 + .owner = THIS_MODULE,
10502 + .dai_link = snd_rpi_iqaudio_codec_dai,
10503 + .num_links = ARRAY_SIZE(snd_rpi_iqaudio_codec_dai),
10504 + .controls = dapm_controls,
10505 + .num_controls = ARRAY_SIZE(dapm_controls),
10506 + .dapm_widgets = dapm_widgets,
10507 + .num_dapm_widgets = ARRAY_SIZE(dapm_widgets),
10508 + .dapm_routes = audio_map,
10509 + .num_dapm_routes = ARRAY_SIZE(audio_map),
10512 +static int snd_rpi_iqaudio_codec_probe(struct platform_device *pdev)
10516 + snd_rpi_iqaudio_codec.dev = &pdev->dev;
10518 + if (pdev->dev.of_node) {
10519 + struct device_node *i2s_node;
10520 + struct snd_soc_card *card = &snd_rpi_iqaudio_codec;
10521 + struct snd_soc_dai_link *dai = &snd_rpi_iqaudio_codec_dai[0];
10523 + i2s_node = of_parse_phandle(pdev->dev.of_node,
10524 + "i2s-controller", 0);
10526 + dai->cpus->dai_name = NULL;
10527 + dai->cpus->of_node = i2s_node;
10528 + dai->platforms->name = NULL;
10529 + dai->platforms->of_node = i2s_node;
10532 + if (of_property_read_string(pdev->dev.of_node, "card_name",
10534 + card->name = "IQaudIOCODEC";
10536 + if (of_property_read_string(pdev->dev.of_node, "dai_name",
10538 + dai->name = "IQaudIO CODEC";
10540 + if (of_property_read_string(pdev->dev.of_node,
10541 + "dai_stream_name", &dai->stream_name))
10542 + dai->stream_name = "IQaudIO CODEC HiFi v1.2";
10546 + ret = snd_soc_register_card(&snd_rpi_iqaudio_codec);
10548 + if (ret != -EPROBE_DEFER)
10549 + dev_err(&pdev->dev,
10550 + "snd_soc_register_card() failed: %d\n", ret);
10557 +static int snd_rpi_iqaudio_codec_remove(struct platform_device *pdev)
10559 + snd_soc_unregister_card(&snd_rpi_iqaudio_codec);
10563 +static const struct of_device_id iqaudio_of_match[] = {
10564 + { .compatible = "iqaudio,iqaudio-codec", },
10568 +MODULE_DEVICE_TABLE(of, iqaudio_of_match);
10570 +static struct platform_driver snd_rpi_iqaudio_codec_driver = {
10572 + .name = "snd-rpi-iqaudio-codec",
10573 + .owner = THIS_MODULE,
10574 + .of_match_table = iqaudio_of_match,
10576 + .probe = snd_rpi_iqaudio_codec_probe,
10577 + .remove = snd_rpi_iqaudio_codec_remove,
10582 +module_platform_driver(snd_rpi_iqaudio_codec_driver);
10584 +MODULE_AUTHOR("Gordon Garrity <gordon@iqaudio.com>");
10585 +MODULE_DESCRIPTION("ASoC Driver for IQaudIO CODEC");
10586 +MODULE_LICENSE("GPL v2");
10588 +++ b/sound/soc/bcm/iqaudio-dac.c
10591 + * ASoC Driver for IQaudIO DAC
10593 + * Author: Florian Meier <florian.meier@koalo.de>
10596 + * This program is free software; you can redistribute it and/or
10597 + * modify it under the terms of the GNU General Public License
10598 + * version 2 as published by the Free Software Foundation.
10600 + * This program is distributed in the hope that it will be useful, but
10601 + * WITHOUT ANY WARRANTY; without even the implied warranty of
10602 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10603 + * General Public License for more details.
10606 +#include <linux/module.h>
10607 +#include <linux/gpio/consumer.h>
10608 +#include <linux/platform_device.h>
10610 +#include <sound/core.h>
10611 +#include <sound/pcm.h>
10612 +#include <sound/pcm_params.h>
10613 +#include <sound/soc.h>
10614 +#include <sound/jack.h>
10616 +static bool digital_gain_0db_limit = true;
10618 +static struct gpio_desc *mute_gpio;
10620 +static int snd_rpi_iqaudio_dac_init(struct snd_soc_pcm_runtime *rtd)
10622 + if (digital_gain_0db_limit)
10625 + struct snd_soc_card *card = rtd->card;
10627 + ret = snd_soc_limit_volume(card, "Digital Playback Volume", 207);
10629 + dev_warn(card->dev, "Failed to set volume limit: %d\n", ret);
10635 +static void snd_rpi_iqaudio_gpio_mute(struct snd_soc_card *card)
10638 + dev_info(card->dev, "%s: muting amp using GPIO22\n",
10640 + gpiod_set_value_cansleep(mute_gpio, 0);
10644 +static void snd_rpi_iqaudio_gpio_unmute(struct snd_soc_card *card)
10647 + dev_info(card->dev, "%s: un-muting amp using GPIO22\n",
10649 + gpiod_set_value_cansleep(mute_gpio, 1);
10653 +static int snd_rpi_iqaudio_set_bias_level(struct snd_soc_card *card,
10654 + struct snd_soc_dapm_context *dapm, enum snd_soc_bias_level level)
10656 + struct snd_soc_pcm_runtime *rtd;
10657 + struct snd_soc_dai *codec_dai;
10659 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
10660 + codec_dai = asoc_rtd_to_codec(rtd, 0);
10662 + if (dapm->dev != codec_dai->dev)
10666 + case SND_SOC_BIAS_PREPARE:
10667 + if (dapm->bias_level != SND_SOC_BIAS_STANDBY)
10671 + snd_rpi_iqaudio_gpio_unmute(card);
10674 + case SND_SOC_BIAS_STANDBY:
10675 + if (dapm->bias_level != SND_SOC_BIAS_PREPARE)
10679 + snd_rpi_iqaudio_gpio_mute(card);
10689 +SND_SOC_DAILINK_DEFS(hifi,
10690 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
10691 + DAILINK_COMP_ARRAY(COMP_CODEC("pcm512x.1-004c", "pcm512x-hifi")),
10692 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
10694 +static struct snd_soc_dai_link snd_rpi_iqaudio_dac_dai[] = {
10696 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
10697 + SND_SOC_DAIFMT_CBS_CFS,
10698 + .init = snd_rpi_iqaudio_dac_init,
10699 + SND_SOC_DAILINK_REG(hifi),
10703 +/* audio machine driver */
10704 +static struct snd_soc_card snd_rpi_iqaudio_dac = {
10705 + .owner = THIS_MODULE,
10706 + .dai_link = snd_rpi_iqaudio_dac_dai,
10707 + .num_links = ARRAY_SIZE(snd_rpi_iqaudio_dac_dai),
10710 +static int snd_rpi_iqaudio_dac_probe(struct platform_device *pdev)
10713 + bool gpio_unmute = false;
10715 + snd_rpi_iqaudio_dac.dev = &pdev->dev;
10717 + if (pdev->dev.of_node) {
10718 + struct device_node *i2s_node;
10719 + struct snd_soc_card *card = &snd_rpi_iqaudio_dac;
10720 + struct snd_soc_dai_link *dai = &snd_rpi_iqaudio_dac_dai[0];
10721 + bool auto_gpio_mute = false;
10723 + i2s_node = of_parse_phandle(pdev->dev.of_node,
10724 + "i2s-controller", 0);
10726 + dai->cpus->dai_name = NULL;
10727 + dai->cpus->of_node = i2s_node;
10728 + dai->platforms->name = NULL;
10729 + dai->platforms->of_node = i2s_node;
10732 + digital_gain_0db_limit = !of_property_read_bool(
10733 + pdev->dev.of_node, "iqaudio,24db_digital_gain");
10735 + if (of_property_read_string(pdev->dev.of_node, "card_name",
10737 + card->name = "IQaudIODAC";
10739 + if (of_property_read_string(pdev->dev.of_node, "dai_name",
10741 + dai->name = "IQaudIO DAC";
10743 + if (of_property_read_string(pdev->dev.of_node,
10744 + "dai_stream_name", &dai->stream_name))
10745 + dai->stream_name = "IQaudIO DAC HiFi";
10747 + /* gpio_unmute - one time unmute amp using GPIO */
10748 + gpio_unmute = of_property_read_bool(pdev->dev.of_node,
10749 + "iqaudio-dac,unmute-amp");
10751 + /* auto_gpio_mute - mute/unmute amp using GPIO */
10752 + auto_gpio_mute = of_property_read_bool(pdev->dev.of_node,
10753 + "iqaudio-dac,auto-mute-amp");
10755 + if (auto_gpio_mute || gpio_unmute) {
10756 + mute_gpio = devm_gpiod_get_optional(&pdev->dev, "mute",
10758 + if (IS_ERR(mute_gpio)) {
10759 + ret = PTR_ERR(mute_gpio);
10760 + dev_err(&pdev->dev,
10761 + "Failed to get mute gpio: %d\n", ret);
10765 + if (auto_gpio_mute && mute_gpio)
10766 + snd_rpi_iqaudio_dac.set_bias_level =
10767 + snd_rpi_iqaudio_set_bias_level;
10771 + ret = snd_soc_register_card(&snd_rpi_iqaudio_dac);
10773 + if (ret != -EPROBE_DEFER)
10774 + dev_err(&pdev->dev,
10775 + "snd_soc_register_card() failed: %d\n", ret);
10779 + if (gpio_unmute && mute_gpio)
10780 + snd_rpi_iqaudio_gpio_unmute(&snd_rpi_iqaudio_dac);
10785 +static int snd_rpi_iqaudio_dac_remove(struct platform_device *pdev)
10787 + snd_rpi_iqaudio_gpio_mute(&snd_rpi_iqaudio_dac);
10789 + snd_soc_unregister_card(&snd_rpi_iqaudio_dac);
10793 +static const struct of_device_id iqaudio_of_match[] = {
10794 + { .compatible = "iqaudio,iqaudio-dac", },
10797 +MODULE_DEVICE_TABLE(of, iqaudio_of_match);
10799 +static struct platform_driver snd_rpi_iqaudio_dac_driver = {
10801 + .name = "snd-rpi-iqaudio-dac",
10802 + .owner = THIS_MODULE,
10803 + .of_match_table = iqaudio_of_match,
10805 + .probe = snd_rpi_iqaudio_dac_probe,
10806 + .remove = snd_rpi_iqaudio_dac_remove,
10809 +module_platform_driver(snd_rpi_iqaudio_dac_driver);
10811 +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
10812 +MODULE_DESCRIPTION("ASoC Driver for IQAudio DAC");
10813 +MODULE_LICENSE("GPL v2");
10815 +++ b/sound/soc/bcm/justboom-both.c
10817 +// SPDX-License-Identifier: GPL-2.0
10819 + * rpi--wm8804.c -- ALSA SoC Raspberry Pi soundcard.
10821 + * Authors: Johannes Krude <johannes@krude.de
10823 + * Driver for when connecting simultaneously justboom-digi and justboom-dac
10825 + * Based upon code from:
10826 + * justboom-digi.c
10827 + * by Milan Neskovic <info@justboom.co>
10829 + * by Milan Neskovic <info@justboom.co>
10831 + * This program is free software; you can redistribute it and/or
10832 + * modify it under the terms of the GNU General Public License
10833 + * version 2 as published by the Free Software Foundation.
10835 + * This program is distributed in the hope that it will be useful, but
10836 + * WITHOUT ANY WARRANTY; without even the implied warranty of
10837 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10838 + * General Public License for more details.
10841 +#include <linux/module.h>
10842 +#include <linux/platform_device.h>
10844 +#include <sound/core.h>
10845 +#include <sound/pcm.h>
10846 +#include <sound/pcm_params.h>
10847 +#include <sound/soc.h>
10848 +#include <sound/jack.h>
10850 +#include "../codecs/wm8804.h"
10851 +#include "../codecs/pcm512x.h"
10854 +static bool digital_gain_0db_limit = true;
10856 +static int snd_rpi_justboom_both_init(struct snd_soc_pcm_runtime *rtd)
10858 + struct snd_soc_component *digi = asoc_rtd_to_codec(rtd, 0)->component;
10859 + struct snd_soc_component *dac = asoc_rtd_to_codec(rtd, 1)->component;
10861 + /* enable TX output */
10862 + snd_soc_component_update_bits(digi, WM8804_PWRDN, 0x4, 0x0);
10864 + snd_soc_component_update_bits(dac, PCM512x_GPIO_EN, 0x08, 0x08);
10865 + snd_soc_component_update_bits(dac, PCM512x_GPIO_OUTPUT_4, 0xf, 0x02);
10866 + snd_soc_component_update_bits(dac, PCM512x_GPIO_CONTROL_1, 0x08, 0x08);
10868 + if (digital_gain_0db_limit) {
10870 + struct snd_soc_card *card = rtd->card;
10872 + ret = snd_soc_limit_volume(card, "Digital Playback Volume",
10875 + dev_warn(card->dev, "Failed to set volume limit: %d\n",
10882 +static int snd_rpi_justboom_both_hw_params(struct snd_pcm_substream *substream,
10883 + struct snd_pcm_hw_params *params)
10885 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
10886 + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
10887 + struct snd_soc_component *digi = asoc_rtd_to_codec(rtd, 0)->component;
10888 + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
10890 + int sysclk = 27000000; /* This is fixed on this board */
10892 + long mclk_freq = 0;
10893 + int mclk_div = 1;
10894 + int sampling_freq = 1;
10898 + int samplerate = params_rate(params);
10900 + if (samplerate <= 96000) {
10901 + mclk_freq = samplerate*256;
10902 + mclk_div = WM8804_MCLKDIV_256FS;
10904 + mclk_freq = samplerate*128;
10905 + mclk_div = WM8804_MCLKDIV_128FS;
10908 + switch (samplerate) {
10910 + sampling_freq = 0x03;
10913 + sampling_freq = 0x00;
10916 + sampling_freq = 0x02;
10919 + sampling_freq = 0x08;
10922 + sampling_freq = 0x0a;
10925 + sampling_freq = 0x0c;
10928 + sampling_freq = 0x0e;
10931 + dev_err(rtd->card->dev,
10932 + "Failed to set WM8804 SYSCLK, unsupported samplerate %d\n",
10936 + snd_soc_dai_set_clkdiv(codec_dai, WM8804_MCLK_DIV, mclk_div);
10937 + snd_soc_dai_set_pll(codec_dai, 0, 0, sysclk, mclk_freq);
10939 + ret = snd_soc_dai_set_sysclk(codec_dai, WM8804_TX_CLKSRC_PLL,
10940 + sysclk, SND_SOC_CLOCK_OUT);
10942 + dev_err(rtd->card->dev,
10943 + "Failed to set WM8804 SYSCLK: %d\n", ret);
10947 + /* Enable TX output */
10948 + snd_soc_component_update_bits(digi, WM8804_PWRDN, 0x4, 0x0);
10951 + snd_soc_component_update_bits(digi, WM8804_PWRDN, 0x9, 0);
10953 + /* set sampling frequency status bits */
10954 + snd_soc_component_update_bits(digi, WM8804_SPDTX4, 0x0f, sampling_freq);
10956 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 64);
10959 +static int snd_rpi_justboom_both_startup(struct snd_pcm_substream *substream)
10961 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
10962 + struct snd_soc_component *digi = asoc_rtd_to_codec(rtd, 0)->component;
10963 + struct snd_soc_component *dac = asoc_rtd_to_codec(rtd, 1)->component;
10965 + /* turn on digital output */
10966 + snd_soc_component_update_bits(digi, WM8804_PWRDN, 0x3c, 0x00);
10968 + snd_soc_component_update_bits(dac, PCM512x_GPIO_CONTROL_1, 0x08, 0x08);
10973 +static void snd_rpi_justboom_both_shutdown(struct snd_pcm_substream *substream)
10975 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
10976 + struct snd_soc_component *digi = asoc_rtd_to_codec(rtd, 0)->component;
10977 + struct snd_soc_component *dac = asoc_rtd_to_codec(rtd, 1)->component;
10979 + snd_soc_component_update_bits(dac, PCM512x_GPIO_CONTROL_1, 0x08, 0x00);
10981 + /* turn off output */
10982 + snd_soc_component_update_bits(digi, WM8804_PWRDN, 0x3c, 0x3c);
10985 +/* machine stream operations */
10986 +static struct snd_soc_ops snd_rpi_justboom_both_ops = {
10987 + .hw_params = snd_rpi_justboom_both_hw_params,
10988 + .startup = snd_rpi_justboom_both_startup,
10989 + .shutdown = snd_rpi_justboom_both_shutdown,
10992 +SND_SOC_DAILINK_DEFS(rpi_justboom_both,
10993 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
10994 + DAILINK_COMP_ARRAY(COMP_CODEC("pcm512x.1-004d", "pcm512x-hifi"),
10995 + COMP_CODEC("wm8804.1-003b", "wm8804-spdif")),
10996 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
10998 +static struct snd_soc_dai_link snd_rpi_justboom_both_dai[] = {
11000 + .name = "JustBoom Digi",
11001 + .stream_name = "JustBoom Digi HiFi",
11002 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
11003 + SND_SOC_DAIFMT_CBM_CFM,
11004 + .ops = &snd_rpi_justboom_both_ops,
11005 + .init = snd_rpi_justboom_both_init,
11006 + SND_SOC_DAILINK_REG(rpi_justboom_both),
11010 +/* audio machine driver */
11011 +static struct snd_soc_card snd_rpi_justboom_both = {
11012 + .name = "snd_rpi_justboom_both",
11013 + .driver_name = "JustBoomBoth",
11014 + .owner = THIS_MODULE,
11015 + .dai_link = snd_rpi_justboom_both_dai,
11016 + .num_links = ARRAY_SIZE(snd_rpi_justboom_both_dai),
11019 +static int snd_rpi_justboom_both_probe(struct platform_device *pdev)
11022 + struct snd_soc_card *card = &snd_rpi_justboom_both;
11024 + snd_rpi_justboom_both.dev = &pdev->dev;
11026 + if (pdev->dev.of_node) {
11027 + struct device_node *i2s_node;
11028 + struct snd_soc_dai_link *dai = &snd_rpi_justboom_both_dai[0];
11030 + i2s_node = of_parse_phandle(pdev->dev.of_node,
11031 + "i2s-controller", 0);
11036 + for (i = 0; i < card->num_links; i++) {
11037 + dai->cpus->dai_name = NULL;
11038 + dai->cpus->of_node = i2s_node;
11039 + dai->platforms->name = NULL;
11040 + dai->platforms->of_node = i2s_node;
11044 + digital_gain_0db_limit = !of_property_read_bool(
11045 + pdev->dev.of_node, "justboom,24db_digital_gain");
11048 + ret = snd_soc_register_card(card);
11049 + if (ret && ret != -EPROBE_DEFER) {
11050 + dev_err(&pdev->dev,
11051 + "snd_soc_register_card() failed: %d\n", ret);
11057 +static int snd_rpi_justboom_both_remove(struct platform_device *pdev)
11059 + snd_soc_unregister_card(&snd_rpi_justboom_both);
11063 +static const struct of_device_id snd_rpi_justboom_both_of_match[] = {
11064 + { .compatible = "justboom,justboom-both", },
11067 +MODULE_DEVICE_TABLE(of, snd_rpi_justboom_both_of_match);
11069 +static struct platform_driver snd_rpi_justboom_both_driver = {
11071 + .name = "snd-rpi-justboom-both",
11072 + .owner = THIS_MODULE,
11073 + .of_match_table = snd_rpi_justboom_both_of_match,
11075 + .probe = snd_rpi_justboom_both_probe,
11076 + .remove = snd_rpi_justboom_both_remove,
11079 +module_platform_driver(snd_rpi_justboom_both_driver);
11081 +MODULE_AUTHOR("Johannes Krude <johannes@krude.de>");
11082 +MODULE_DESCRIPTION("ASoC Driver for simultaneous use of JustBoom PI Digi & DAC HAT Sound Cards");
11083 +MODULE_LICENSE("GPL v2");
11085 +++ b/sound/soc/bcm/justboom-dac.c
11088 + * ASoC Driver for JustBoom DAC Raspberry Pi HAT Sound Card
11090 + * Author: Milan Neskovic
11092 + * based on code by Daniel Matuschek <info@crazy-audio.com>
11093 + * based on code by Florian Meier <florian.meier@koalo.de>
11095 + * This program is free software; you can redistribute it and/or
11096 + * modify it under the terms of the GNU General Public License
11097 + * version 2 as published by the Free Software Foundation.
11099 + * This program is distributed in the hope that it will be useful, but
11100 + * WITHOUT ANY WARRANTY; without even the implied warranty of
11101 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11102 + * General Public License for more details.
11105 +#include <linux/module.h>
11106 +#include <linux/platform_device.h>
11108 +#include <sound/core.h>
11109 +#include <sound/pcm.h>
11110 +#include <sound/pcm_params.h>
11111 +#include <sound/soc.h>
11112 +#include <sound/jack.h>
11114 +#include "../codecs/pcm512x.h"
11116 +static bool digital_gain_0db_limit = true;
11118 +static int snd_rpi_justboom_dac_init(struct snd_soc_pcm_runtime *rtd)
11120 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
11121 + snd_soc_component_update_bits(component, PCM512x_GPIO_EN, 0x08, 0x08);
11122 + snd_soc_component_update_bits(component, PCM512x_GPIO_OUTPUT_4, 0xf, 0x02);
11123 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x08,0x08);
11125 + if (digital_gain_0db_limit)
11128 + struct snd_soc_card *card = rtd->card;
11130 + ret = snd_soc_limit_volume(card, "Digital Playback Volume", 207);
11132 + dev_warn(card->dev, "Failed to set volume limit: %d\n", ret);
11138 +static int snd_rpi_justboom_dac_startup(struct snd_pcm_substream *substream) {
11139 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
11140 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
11141 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x08,0x08);
11145 +static void snd_rpi_justboom_dac_shutdown(struct snd_pcm_substream *substream) {
11146 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
11147 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
11148 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x08,0x00);
11151 +/* machine stream operations */
11152 +static struct snd_soc_ops snd_rpi_justboom_dac_ops = {
11153 + .startup = snd_rpi_justboom_dac_startup,
11154 + .shutdown = snd_rpi_justboom_dac_shutdown,
11157 +SND_SOC_DAILINK_DEFS(hifi,
11158 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
11159 + DAILINK_COMP_ARRAY(COMP_CODEC("pcm512x.1-004d", "pcm512x-hifi")),
11160 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
11162 +static struct snd_soc_dai_link snd_rpi_justboom_dac_dai[] = {
11164 + .name = "JustBoom DAC",
11165 + .stream_name = "JustBoom DAC HiFi",
11166 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
11167 + SND_SOC_DAIFMT_CBS_CFS,
11168 + .ops = &snd_rpi_justboom_dac_ops,
11169 + .init = snd_rpi_justboom_dac_init,
11170 + SND_SOC_DAILINK_REG(hifi),
11174 +/* audio machine driver */
11175 +static struct snd_soc_card snd_rpi_justboom_dac = {
11176 + .name = "snd_rpi_justboom_dac",
11177 + .driver_name = "JustBoomDac",
11178 + .owner = THIS_MODULE,
11179 + .dai_link = snd_rpi_justboom_dac_dai,
11180 + .num_links = ARRAY_SIZE(snd_rpi_justboom_dac_dai),
11183 +static int snd_rpi_justboom_dac_probe(struct platform_device *pdev)
11187 + snd_rpi_justboom_dac.dev = &pdev->dev;
11189 + if (pdev->dev.of_node) {
11190 + struct device_node *i2s_node;
11191 + struct snd_soc_dai_link *dai = &snd_rpi_justboom_dac_dai[0];
11192 + i2s_node = of_parse_phandle(pdev->dev.of_node,
11193 + "i2s-controller", 0);
11196 + dai->cpus->dai_name = NULL;
11197 + dai->cpus->of_node = i2s_node;
11198 + dai->platforms->name = NULL;
11199 + dai->platforms->of_node = i2s_node;
11202 + digital_gain_0db_limit = !of_property_read_bool(
11203 + pdev->dev.of_node, "justboom,24db_digital_gain");
11206 + ret = devm_snd_soc_register_card(&pdev->dev, &snd_rpi_justboom_dac);
11207 + if (ret && ret != -EPROBE_DEFER)
11208 + dev_err(&pdev->dev,
11209 + "snd_soc_register_card() failed: %d\n", ret);
11214 +static const struct of_device_id snd_rpi_justboom_dac_of_match[] = {
11215 + { .compatible = "justboom,justboom-dac", },
11218 +MODULE_DEVICE_TABLE(of, snd_rpi_justboom_dac_of_match);
11220 +static struct platform_driver snd_rpi_justboom_dac_driver = {
11222 + .name = "snd-rpi-justboom-dac",
11223 + .owner = THIS_MODULE,
11224 + .of_match_table = snd_rpi_justboom_dac_of_match,
11226 + .probe = snd_rpi_justboom_dac_probe,
11229 +module_platform_driver(snd_rpi_justboom_dac_driver);
11231 +MODULE_AUTHOR("Milan Neskovic <info@justboom.co>");
11232 +MODULE_DESCRIPTION("ASoC Driver for JustBoom PI DAC HAT Sound Card");
11233 +MODULE_LICENSE("GPL v2");
11235 +++ b/sound/soc/bcm/pifi-40.c
11237 +// SPDX-License-Identifier: GPL-2.0-only
11239 + * ALSA ASoC Machine Driver for PiFi-40
11241 + * Author: David Knell <david.knell@gmail.com)
11242 + * based on code by Daniel Matuschek <info@crazy-audio.com>
11243 + * based on code by Florian Meier <florian.meier@koalo.de>
11244 + * Copyright (C) 2020
11246 + * This program is free software; you can redistribute it and/or
11247 + * modify it under the terms of the GNU General Public License
11248 + * version 2 as published by the Free Software Foundation.
11250 + * This program is distributed in the hope that it will be useful, but
11251 + * WITHOUT ANY WARRANTY; without even the implied warranty of
11252 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11253 + * General Public License for more details.
11256 +#include <linux/module.h>
11257 +#include <linux/platform_device.h>
11258 +#include <linux/gpio/consumer.h>
11259 +#include <sound/core.h>
11260 +#include <sound/pcm.h>
11261 +#include <sound/pcm_params.h>
11262 +#include <sound/soc.h>
11263 +#include <linux/firmware.h>
11264 +#include <linux/delay.h>
11265 +#include <sound/tlv.h>
11267 +static struct gpio_desc *pdn_gpio;
11268 +static int vol = 0x30;
11271 +static int pifi_40_vol_get(struct snd_kcontrol *kcontrol,
11272 + struct snd_ctl_elem_value *ucontrol)
11274 + ucontrol->value.integer.value[0] = vol;
11275 + ucontrol->value.integer.value[1] = vol;
11279 +static int pifi_40_vol_set(struct snd_kcontrol *kcontrol,
11280 + struct snd_ctl_elem_value *ucontrol)
11282 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
11283 + struct snd_soc_pcm_runtime *rtd;
11284 + unsigned int v = ucontrol->value.integer.value[0];
11285 + struct snd_soc_component *dac[2];
11287 + rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
11288 + dac[0] = asoc_rtd_to_codec(rtd, 0)->component;
11289 + dac[1] = asoc_rtd_to_codec(rtd, 1)->component;
11291 + snd_soc_component_write(dac[0], 0x07, 255 - v);
11292 + snd_soc_component_write(dac[1], 0x07, 255 - v);
11298 +static const DECLARE_TLV_DB_SCALE(digital_tlv_master, -10350, 50, 1);
11299 +static const struct snd_kcontrol_new pifi_40_controls[] = {
11300 + SOC_DOUBLE_R_EXT_TLV("Master Volume", 0x00, 0x01,
11304 + pifi_40_vol_get, pifi_40_vol_set,
11305 + digital_tlv_master)
11308 +static const char * const codec_ctl_pfx[] = { "Left", "Right" };
11310 +static const char * const codec_ctl_name[] = { "Master Volume",
11311 + "Speaker Volume",
11312 + "Speaker Switch" };
11314 +static int snd_pifi_40_init(struct snd_soc_pcm_runtime *rtd)
11316 + struct snd_soc_card *card = rtd->card;
11317 + struct snd_soc_component *dac[2];
11318 + struct snd_kcontrol *kctl;
11321 + dac[0] = asoc_rtd_to_codec(rtd, 0)->component;
11322 + dac[1] = asoc_rtd_to_codec(rtd, 1)->component;
11325 + // Set up cards - pulse power down first
11326 + gpiod_set_value_cansleep(pdn_gpio, 1);
11327 + usleep_range(1000, 10000);
11328 + gpiod_set_value_cansleep(pdn_gpio, 0);
11329 + usleep_range(20000, 30000);
11331 + // Oscillator trim
11332 + snd_soc_component_write(dac[0], 0x1b, 0);
11333 + snd_soc_component_write(dac[1], 0x1b, 0);
11334 + usleep_range(60000, 80000);
11337 + for (i = 0; i < 2; i++) {
11338 + // MCLK at 64fs, sample rate 44.1 or 48kHz
11339 + snd_soc_component_write(dac[i], 0x00, 0x60);
11341 + // Set up for PBTL
11342 + snd_soc_component_write(dac[i], 0x19, 0x3A);
11343 + snd_soc_component_write(dac[i], 0x25, 0x01103245);
11345 + // Master vol to -10db
11346 + snd_soc_component_write(dac[i], 0x07, 0x44);
11348 + // Inputs set to L and R respectively
11349 + snd_soc_component_write(dac[0], 0x20, 0x00017772);
11350 + snd_soc_component_write(dac[1], 0x20, 0x00107772);
11352 + // Remove codec controls
11353 + for (i = 0; i < 2; i++) {
11354 + for (j = 0; j < 3; j++) {
11357 + sprintf(cname, "%s %s", codec_ctl_pfx[i],
11358 + codec_ctl_name[j]);
11359 + kctl = snd_soc_card_get_kcontrol(card, cname);
11361 + pr_info("Control %s not found\n",
11364 + kctl->vd[0].access =
11365 + SNDRV_CTL_ELEM_ACCESS_READWRITE;
11366 + snd_ctl_remove(card->snd_card, kctl);
11374 +static int snd_pifi_40_hw_params(struct snd_pcm_substream *substream,
11375 + struct snd_pcm_hw_params *params)
11377 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
11378 + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
11379 + unsigned int sample_bits;
11381 + sample_bits = snd_pcm_format_physical_width(params_format(params));
11382 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 64);
11385 +static struct snd_soc_ops snd_pifi_40_ops = { .hw_params =
11386 + snd_pifi_40_hw_params };
11388 +static struct snd_soc_dai_link_component pifi_40_codecs[] = {
11390 + .dai_name = "tas571x-hifi",
11393 + .dai_name = "tas571x-hifi",
11397 +SND_SOC_DAILINK_DEFS(
11398 + pifi_40_dai, DAILINK_COMP_ARRAY(COMP_EMPTY()),
11399 + DAILINK_COMP_ARRAY(COMP_CODEC("tas571x.1-001a", "tas571x-hifi"),
11400 + COMP_CODEC("tas571x.1-001b", "tas571x-hifi")),
11401 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
11403 +static struct snd_soc_dai_link snd_pifi_40_dai[] = {
11405 + .name = "PiFi40",
11406 + .stream_name = "PiFi40",
11407 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
11408 + SND_SOC_DAIFMT_CBS_CFS,
11409 + .ops = &snd_pifi_40_ops,
11410 + .init = snd_pifi_40_init,
11411 + SND_SOC_DAILINK_REG(pifi_40_dai),
11416 +static struct snd_soc_card snd_pifi_40 = {
11417 + .name = "PiFi40",
11418 + .owner = THIS_MODULE,
11419 + .dai_link = snd_pifi_40_dai,
11420 + .num_links = ARRAY_SIZE(snd_pifi_40_dai),
11421 + .controls = pifi_40_controls,
11422 + .num_controls = ARRAY_SIZE(pifi_40_controls)
11425 +static void snd_pifi_40_pdn(struct snd_soc_card *card, int on)
11428 + gpiod_set_value_cansleep(pdn_gpio, on ? 0 : 1);
11431 +static int snd_pifi_40_probe(struct platform_device *pdev)
11433 + struct snd_soc_card *card = &snd_pifi_40;
11434 + int ret = 0, i = 0;
11436 + card->dev = &pdev->dev;
11437 + platform_set_drvdata(pdev, &snd_pifi_40);
11439 + if (pdev->dev.of_node) {
11440 + struct device_node *i2s_node;
11441 + struct snd_soc_dai_link *dai;
11443 + dai = &snd_pifi_40_dai[0];
11444 + i2s_node = of_parse_phandle(pdev->dev.of_node, "i2s-controller",
11447 + for (i = 0; i < card->num_links; i++) {
11448 + dai->cpus->dai_name = NULL;
11449 + dai->cpus->of_node = i2s_node;
11450 + dai->platforms->name = NULL;
11451 + dai->platforms->of_node = i2s_node;
11455 + pifi_40_codecs[0].of_node =
11456 + of_parse_phandle(pdev->dev.of_node, "audio-codec", 0);
11457 + pifi_40_codecs[1].of_node =
11458 + of_parse_phandle(pdev->dev.of_node, "audio-codec", 1);
11459 + if (!pifi_40_codecs[0].of_node || !pifi_40_codecs[1].of_node) {
11460 + dev_err(&pdev->dev,
11461 + "Property 'audio-codec' missing or invalid\n");
11465 + pdn_gpio = devm_gpiod_get_optional(&pdev->dev, "pdn",
11467 + if (IS_ERR(pdn_gpio)) {
11468 + ret = PTR_ERR(pdn_gpio);
11469 + dev_err(&pdev->dev, "failed to get pdn gpio: %d\n",
11474 + ret = snd_soc_register_card(&snd_pifi_40);
11476 + dev_err(&pdev->dev,
11477 + "snd_soc_register_card() failed: %d\n", ret);
11487 +static int snd_pifi_40_remove(struct platform_device *pdev)
11489 + struct snd_soc_card *card = platform_get_drvdata(pdev);
11491 + kfree(&card->drvdata);
11492 + snd_pifi_40_pdn(&snd_pifi_40, 0);
11493 + snd_soc_unregister_card(&snd_pifi_40);
11497 +static const struct of_device_id snd_pifi_40_of_match[] = {
11499 + .compatible = "pifi,pifi-40",
11501 + { /* sentinel */ },
11504 +MODULE_DEVICE_TABLE(of, snd_pifi_40_of_match);
11506 +static struct platform_driver snd_pifi_40_driver = {
11508 + .name = "snd-pifi-40",
11509 + .owner = THIS_MODULE,
11510 + .of_match_table = snd_pifi_40_of_match,
11512 + .probe = snd_pifi_40_probe,
11513 + .remove = snd_pifi_40_remove,
11516 +module_platform_driver(snd_pifi_40_driver);
11518 +MODULE_AUTHOR("David Knell <david.knell@gmail.com>");
11519 +MODULE_DESCRIPTION("ALSA ASoC Machine Driver for PiFi-40");
11520 +MODULE_LICENSE("GPL v2");
11522 +++ b/sound/soc/bcm/pisound.c
11525 + * Pisound Linux kernel module.
11526 + * Copyright (C) 2016-2020 Vilniaus Blokas UAB, https://blokas.io/pisound
11528 + * This program is free software; you can redistribute it and/or
11529 + * modify it under the terms of the GNU General Public License
11530 + * as published by the Free Software Foundation; version 2 of the
11533 + * This program is distributed in the hope that it will be useful,
11534 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11535 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11536 + * GNU General Public License for more details.
11538 + * You should have received a copy of the GNU General Public License
11539 + * along with this program; if not, write to the Free Software
11540 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
11541 + * MA 02110-1301, USA.
11544 +#include <linux/init.h>
11545 +#include <linux/module.h>
11546 +#include <linux/platform_device.h>
11547 +#include <linux/gpio.h>
11548 +#include <linux/kobject.h>
11549 +#include <linux/sysfs.h>
11550 +#include <linux/delay.h>
11551 +#include <linux/spi/spi.h>
11552 +#include <linux/interrupt.h>
11553 +#include <linux/kfifo.h>
11554 +#include <linux/jiffies.h>
11556 +#include <sound/core.h>
11557 +#include <sound/pcm.h>
11558 +#include <sound/pcm_params.h>
11559 +#include <sound/soc.h>
11560 +#include <sound/jack.h>
11561 +#include <sound/rawmidi.h>
11562 +#include <sound/asequencer.h>
11563 +#include <sound/control.h>
11565 +static int pisnd_spi_init(struct device *dev);
11566 +static void pisnd_spi_uninit(void);
11568 +static void pisnd_spi_flush(void);
11569 +static void pisnd_spi_start(void);
11570 +static uint8_t pisnd_spi_recv(uint8_t *buffer, uint8_t length);
11572 +typedef void (*pisnd_spi_recv_cb)(void *data);
11573 +static void pisnd_spi_set_callback(pisnd_spi_recv_cb cb, void *data);
11575 +static const char *pisnd_spi_get_serial(void);
11576 +static const char *pisnd_spi_get_id(void);
11577 +static const char *pisnd_spi_get_fw_version(void);
11578 +static const char *pisnd_spi_get_hw_version(void);
11580 +static int pisnd_midi_init(struct snd_card *card);
11581 +static void pisnd_midi_uninit(void);
11584 + TASK_PROCESS = 0,
11587 +static void pisnd_schedule_process(enum task_e task);
11589 +#define PISOUND_LOG_PREFIX "pisound: "
11591 +#ifdef PISOUND_DEBUG
11592 +# define printd(...) pr_alert(PISOUND_LOG_PREFIX __VA_ARGS__)
11594 +# define printd(...) do {} while (0)
11597 +#define printe(...) pr_err(PISOUND_LOG_PREFIX __VA_ARGS__)
11598 +#define printi(...) pr_info(PISOUND_LOG_PREFIX __VA_ARGS__)
11600 +static struct snd_rawmidi *g_rmidi;
11601 +static struct snd_rawmidi_substream *g_midi_output_substream;
11603 +static int pisnd_output_open(struct snd_rawmidi_substream *substream)
11605 + g_midi_output_substream = substream;
11609 +static int pisnd_output_close(struct snd_rawmidi_substream *substream)
11611 + g_midi_output_substream = NULL;
11615 +static void pisnd_output_trigger(
11616 + struct snd_rawmidi_substream *substream,
11620 + if (substream != g_midi_output_substream) {
11621 + printe("MIDI output trigger called for an unexpected stream!");
11628 + pisnd_spi_start();
11631 +static void pisnd_output_drain(struct snd_rawmidi_substream *substream)
11633 + pisnd_spi_flush();
11636 +static int pisnd_input_open(struct snd_rawmidi_substream *substream)
11641 +static int pisnd_input_close(struct snd_rawmidi_substream *substream)
11646 +static void pisnd_midi_recv_callback(void *substream)
11648 + uint8_t data[128];
11651 + while ((n = pisnd_spi_recv(data, sizeof(data)))) {
11652 + int res = snd_rawmidi_receive(substream, data, n);
11654 + printd("midi recv %u bytes, res = %d\n", n, res);
11658 +static void pisnd_input_trigger(struct snd_rawmidi_substream *substream, int up)
11661 + pisnd_spi_set_callback(pisnd_midi_recv_callback, substream);
11662 + pisnd_schedule_process(TASK_PROCESS);
11664 + pisnd_spi_set_callback(NULL, NULL);
11668 +static struct snd_rawmidi_ops pisnd_output_ops = {
11669 + .open = pisnd_output_open,
11670 + .close = pisnd_output_close,
11671 + .trigger = pisnd_output_trigger,
11672 + .drain = pisnd_output_drain,
11675 +static struct snd_rawmidi_ops pisnd_input_ops = {
11676 + .open = pisnd_input_open,
11677 + .close = pisnd_input_close,
11678 + .trigger = pisnd_input_trigger,
11681 +static void pisnd_get_port_info(
11682 + struct snd_rawmidi *rmidi,
11684 + struct snd_seq_port_info *seq_port_info
11687 + seq_port_info->type =
11688 + SNDRV_SEQ_PORT_TYPE_MIDI_GENERIC |
11689 + SNDRV_SEQ_PORT_TYPE_HARDWARE |
11690 + SNDRV_SEQ_PORT_TYPE_PORT;
11691 + seq_port_info->midi_voices = 0;
11694 +static struct snd_rawmidi_global_ops pisnd_global_ops = {
11695 + .get_port_info = pisnd_get_port_info,
11698 +static int pisnd_midi_init(struct snd_card *card)
11702 + g_midi_output_substream = NULL;
11704 + err = snd_rawmidi_new(card, "pisound MIDI", 0, 1, 1, &g_rmidi);
11707 + printe("snd_rawmidi_new failed: %d\n", err);
11711 + strcpy(g_rmidi->name, "pisound MIDI ");
11712 + strcat(g_rmidi->name, pisnd_spi_get_serial());
11714 + g_rmidi->info_flags =
11715 + SNDRV_RAWMIDI_INFO_OUTPUT |
11716 + SNDRV_RAWMIDI_INFO_INPUT |
11717 + SNDRV_RAWMIDI_INFO_DUPLEX;
11719 + g_rmidi->ops = &pisnd_global_ops;
11721 + g_rmidi->private_data = (void *)0;
11723 + snd_rawmidi_set_ops(
11725 + SNDRV_RAWMIDI_STREAM_OUTPUT,
11726 + &pisnd_output_ops
11729 + snd_rawmidi_set_ops(
11731 + SNDRV_RAWMIDI_STREAM_INPUT,
11738 +static void pisnd_midi_uninit(void)
11742 +static void *g_recvData;
11743 +static pisnd_spi_recv_cb g_recvCallback;
11745 +#define FIFO_SIZE 4096
11747 +static char g_serial_num[11];
11748 +static char g_id[25];
11749 +enum { MAX_VERSION_STR_LEN = 6 };
11750 +static char g_fw_version[MAX_VERSION_STR_LEN];
11751 +static char g_hw_version[MAX_VERSION_STR_LEN];
11753 +static uint8_t g_ledFlashDuration;
11754 +static bool g_ledFlashDurationChanged;
11756 +DEFINE_KFIFO(spi_fifo_in, uint8_t, FIFO_SIZE);
11757 +DEFINE_KFIFO(spi_fifo_out, uint8_t, FIFO_SIZE);
11759 +static struct gpio_desc *data_available;
11760 +static struct gpio_desc *spi_reset;
11762 +static struct spi_device *pisnd_spi_device;
11764 +static struct workqueue_struct *pisnd_workqueue;
11765 +static struct work_struct pisnd_work_process;
11767 +static void pisnd_work_handler(struct work_struct *work);
11769 +static void spi_transfer(const uint8_t *txbuf, uint8_t *rxbuf, int len);
11770 +static uint16_t spi_transfer16(uint16_t val);
11772 +static int pisnd_init_workqueues(void)
11774 + pisnd_workqueue = create_singlethread_workqueue("pisnd_workqueue");
11775 + INIT_WORK(&pisnd_work_process, pisnd_work_handler);
11780 +static void pisnd_uninit_workqueues(void)
11782 + flush_workqueue(pisnd_workqueue);
11783 + destroy_workqueue(pisnd_workqueue);
11785 + pisnd_workqueue = NULL;
11788 +static bool pisnd_spi_has_more(void)
11790 + return gpiod_get_value(data_available);
11793 +static void pisnd_schedule_process(enum task_e task)
11795 + if (pisnd_spi_device != NULL &&
11796 + pisnd_workqueue != NULL &&
11797 + !work_pending(&pisnd_work_process)
11799 + printd("schedule: has more = %d\n", pisnd_spi_has_more());
11800 + if (task == TASK_PROCESS)
11801 + queue_work(pisnd_workqueue, &pisnd_work_process);
11805 +static irqreturn_t data_available_interrupt_handler(int irq, void *dev_id)
11807 + if (irq == gpiod_to_irq(data_available) && pisnd_spi_has_more()) {
11808 + printd("schedule from irq\n");
11809 + pisnd_schedule_process(TASK_PROCESS);
11812 + return IRQ_HANDLED;
11815 +static uint16_t spi_transfer16(uint16_t val)
11817 + uint8_t txbuf[2];
11818 + uint8_t rxbuf[2];
11820 + if (!pisnd_spi_device) {
11821 + printe("pisnd_spi_device null, returning\n");
11825 + txbuf[0] = val >> 8;
11826 + txbuf[1] = val & 0xff;
11828 + spi_transfer(txbuf, rxbuf, sizeof(txbuf));
11830 + printd("received: %02x%02x\n", rxbuf[0], rxbuf[1]);
11832 + return (rxbuf[0] << 8) | rxbuf[1];
11835 +static void spi_transfer(const uint8_t *txbuf, uint8_t *rxbuf, int len)
11838 + struct spi_transfer transfer;
11839 + struct spi_message msg;
11841 + memset(rxbuf, 0, len);
11843 + if (!pisnd_spi_device) {
11844 + printe("pisnd_spi_device null, returning\n");
11848 + spi_message_init(&msg);
11850 + memset(&transfer, 0, sizeof(transfer));
11852 + transfer.tx_buf = txbuf;
11853 + transfer.rx_buf = rxbuf;
11854 + transfer.len = len;
11855 + transfer.speed_hz = 150000;
11856 + transfer.delay.value = 10;
11857 + transfer.delay.unit = SPI_DELAY_UNIT_USECS;
11859 + spi_message_add_tail(&transfer, &msg);
11861 + err = spi_sync(pisnd_spi_device, &msg);
11864 + printe("spi_sync error %d\n", err);
11868 + printd("hasMore %d\n", pisnd_spi_has_more());
11871 +static int spi_read_bytes(char *dst, size_t length, uint8_t *bytesRead)
11877 + memset(dst, 0, length);
11880 + rx = spi_transfer16(0);
11884 + size = rx & 0xff;
11886 + if (size > length)
11889 + for (i = 0; i < size; ++i) {
11890 + rx = spi_transfer16(0);
11894 + dst[i] = rx & 0xff;
11902 +static int spi_device_match(struct device *dev, const void *data)
11904 + struct spi_device *spi = container_of(dev, struct spi_device, dev);
11906 + printd(" %s %s %dkHz %d bits mode=0x%02X\n",
11907 + spi->modalias, dev_name(dev), spi->max_speed_hz/1000,
11908 + spi->bits_per_word, spi->mode);
11910 + if (strcmp("pisound-spi", spi->modalias) == 0) {
11911 + printi("\tFound!\n");
11915 + printe("\tNot found!\n");
11919 +static struct spi_device *pisnd_spi_find_device(void)
11921 + struct device *dev;
11923 + printi("Searching for spi device...\n");
11924 + dev = bus_find_device(&spi_bus_type, NULL, NULL, spi_device_match);
11926 + return container_of(dev, struct spi_device, dev);
11931 +static void pisnd_work_handler(struct work_struct *work)
11933 + enum { TRANSFER_SIZE = 4 };
11934 + enum { PISOUND_OUTPUT_BUFFER_SIZE_MILLIBYTES = 127 * 1000 };
11935 + enum { MIDI_MILLIBYTES_PER_JIFFIE = (3125 * 1000) / HZ };
11936 + int out_buffer_used_millibytes = 0;
11937 + unsigned long now;
11939 + uint8_t txbuf[TRANSFER_SIZE];
11940 + uint8_t rxbuf[TRANSFER_SIZE];
11941 + uint8_t midibuf[TRANSFER_SIZE];
11945 + unsigned long last_transfer_at = jiffies;
11947 + if (work == &pisnd_work_process) {
11948 + if (pisnd_spi_device == NULL)
11952 + if (g_midi_output_substream &&
11953 + kfifo_avail(&spi_fifo_out) >= sizeof(midibuf)) {
11955 + n = snd_rawmidi_transmit_peek(
11956 + g_midi_output_substream,
11957 + midibuf, sizeof(midibuf)
11961 + for (i = 0; i < n; ++i)
11966 + snd_rawmidi_transmit_ack(
11967 + g_midi_output_substream,
11973 + had_data = false;
11974 + memset(txbuf, 0, sizeof(txbuf));
11975 + for (i = 0; i < sizeof(txbuf) &&
11976 + ((out_buffer_used_millibytes+1000 <
11977 + PISOUND_OUTPUT_BUFFER_SIZE_MILLIBYTES) ||
11978 + g_ledFlashDurationChanged);
11983 + if (g_ledFlashDurationChanged) {
11984 + txbuf[i+0] = 0xf0;
11985 + txbuf[i+1] = g_ledFlashDuration;
11986 + g_ledFlashDuration = 0;
11987 + g_ledFlashDurationChanged = false;
11988 + } else if (kfifo_get(&spi_fifo_out, &val)) {
11989 + txbuf[i+0] = 0x0f;
11990 + txbuf[i+1] = val;
11991 + out_buffer_used_millibytes += 1000;
11995 + spi_transfer(txbuf, rxbuf, sizeof(txbuf));
11996 + /* Estimate the Pisound's MIDI output buffer usage, so
11997 + * that we don't overflow it. Space in the buffer should
11998 + * be becoming available at the UART MIDI byte transfer
12002 + if (now != last_transfer_at) {
12003 + out_buffer_used_millibytes -=
12004 + (now - last_transfer_at) *
12005 + MIDI_MILLIBYTES_PER_JIFFIE;
12006 + if (out_buffer_used_millibytes < 0)
12007 + out_buffer_used_millibytes = 0;
12008 + last_transfer_at = now;
12011 + for (i = 0; i < sizeof(rxbuf); i += 2) {
12013 + kfifo_put(&spi_fifo_in, rxbuf[i+1]);
12014 + if (kfifo_len(&spi_fifo_in) > 16 &&
12016 + g_recvCallback(g_recvData);
12020 + } while (had_data
12021 + || !kfifo_is_empty(&spi_fifo_out)
12022 + || pisnd_spi_has_more()
12023 + || g_ledFlashDurationChanged
12024 + || out_buffer_used_millibytes != 0
12027 + if (!kfifo_is_empty(&spi_fifo_in) && g_recvCallback)
12028 + g_recvCallback(g_recvData);
12032 +static int pisnd_spi_gpio_init(struct device *dev)
12034 + spi_reset = gpiod_get_index(dev, "reset", 1, GPIOD_ASIS);
12035 + data_available = gpiod_get_index(dev, "data_available", 0, GPIOD_ASIS);
12037 + gpiod_direction_output(spi_reset, 1);
12038 + gpiod_direction_input(data_available);
12040 + /* Reset the slave. */
12041 + gpiod_set_value(spi_reset, false);
12043 + gpiod_set_value(spi_reset, true);
12045 + /* Give time for spi slave to start. */
12051 +static void pisnd_spi_gpio_uninit(void)
12053 + gpiod_set_value(spi_reset, false);
12054 + gpiod_put(spi_reset);
12055 + spi_reset = NULL;
12057 + gpiod_put(data_available);
12058 + data_available = NULL;
12061 +static int pisnd_spi_gpio_irq_init(struct device *dev)
12063 + return request_threaded_irq(
12064 + gpiod_to_irq(data_available), NULL,
12065 + data_available_interrupt_handler,
12066 + IRQF_TIMER | IRQF_TRIGGER_RISING | IRQF_ONESHOT,
12067 + "data_available_int",
12072 +static void pisnd_spi_gpio_irq_uninit(void)
12074 + free_irq(gpiod_to_irq(data_available), NULL);
12077 +static int spi_read_info(void)
12084 + char buffer[257];
12088 + memset(g_serial_num, 0, sizeof(g_serial_num));
12089 + memset(g_fw_version, 0, sizeof(g_fw_version));
12090 + strcpy(g_hw_version, "1.0"); // Assume 1.0 hw version.
12091 + memset(g_id, 0, sizeof(g_id));
12093 + tmp = spi_transfer16(0);
12098 + count = tmp & 0xff;
12100 + for (i = 0; i < count; ++i) {
12101 + memset(buffer, 0, sizeof(buffer));
12102 + ret = spi_read_bytes(buffer, sizeof(buffer)-1, &n);
12114 + MAX_VERSION_STR_LEN,
12120 + g_fw_version[MAX_VERSION_STR_LEN-1] = '\0';
12128 + MAX_VERSION_STR_LEN,
12134 + g_hw_version[MAX_VERSION_STR_LEN-1] = '\0';
12137 + if (n >= sizeof(g_serial_num))
12140 + memcpy(g_serial_num, buffer, sizeof(g_serial_num));
12144 + if (n*2 >= sizeof(g_id))
12148 + for (j = 0; j < n; ++j)
12149 + p += sprintf(p, "%02x", buffer[j]);
12162 +static int pisnd_spi_init(struct device *dev)
12165 + struct spi_device *spi;
12167 + memset(g_serial_num, 0, sizeof(g_serial_num));
12168 + memset(g_id, 0, sizeof(g_id));
12169 + memset(g_fw_version, 0, sizeof(g_fw_version));
12170 + memset(g_hw_version, 0, sizeof(g_hw_version));
12172 + spi = pisnd_spi_find_device();
12174 + if (spi != NULL) {
12175 + printd("initializing spi!\n");
12176 + pisnd_spi_device = spi;
12177 + ret = spi_setup(pisnd_spi_device);
12179 + printe("SPI device not found, deferring!\n");
12180 + return -EPROBE_DEFER;
12183 + ret = pisnd_spi_gpio_init(dev);
12186 + printe("SPI GPIO init failed: %d\n", ret);
12187 + spi_dev_put(pisnd_spi_device);
12188 + pisnd_spi_device = NULL;
12189 + pisnd_spi_gpio_uninit();
12193 + ret = spi_read_info();
12196 + printe("Reading card info failed: %d\n", ret);
12197 + spi_dev_put(pisnd_spi_device);
12198 + pisnd_spi_device = NULL;
12199 + pisnd_spi_gpio_uninit();
12203 + /* Flash the LEDs. */
12204 + spi_transfer16(0xf008);
12206 + ret = pisnd_spi_gpio_irq_init(dev);
12208 + printe("SPI irq request failed: %d\n", ret);
12209 + spi_dev_put(pisnd_spi_device);
12210 + pisnd_spi_device = NULL;
12211 + pisnd_spi_gpio_irq_uninit();
12212 + pisnd_spi_gpio_uninit();
12215 + ret = pisnd_init_workqueues();
12217 + printe("Workqueue initialization failed: %d\n", ret);
12218 + spi_dev_put(pisnd_spi_device);
12219 + pisnd_spi_device = NULL;
12220 + pisnd_spi_gpio_irq_uninit();
12221 + pisnd_spi_gpio_uninit();
12222 + pisnd_uninit_workqueues();
12226 + if (pisnd_spi_has_more()) {
12227 + printd("data is available, scheduling from init\n");
12228 + pisnd_schedule_process(TASK_PROCESS);
12234 +static void pisnd_spi_uninit(void)
12236 + pisnd_uninit_workqueues();
12238 + spi_dev_put(pisnd_spi_device);
12239 + pisnd_spi_device = NULL;
12241 + pisnd_spi_gpio_irq_uninit();
12242 + pisnd_spi_gpio_uninit();
12245 +static void pisnd_spi_flash_leds(uint8_t duration)
12247 + g_ledFlashDuration = duration;
12248 + g_ledFlashDurationChanged = true;
12249 + printd("schedule from spi_flash_leds\n");
12250 + pisnd_schedule_process(TASK_PROCESS);
12253 +static void pisnd_spi_flush(void)
12255 + while (!kfifo_is_empty(&spi_fifo_out)) {
12256 + pisnd_spi_start();
12257 + flush_workqueue(pisnd_workqueue);
12261 +static void pisnd_spi_start(void)
12263 + printd("schedule from spi_start\n");
12264 + pisnd_schedule_process(TASK_PROCESS);
12267 +static uint8_t pisnd_spi_recv(uint8_t *buffer, uint8_t length)
12269 + return kfifo_out(&spi_fifo_in, buffer, length);
12272 +static void pisnd_spi_set_callback(pisnd_spi_recv_cb cb, void *data)
12274 + g_recvData = data;
12275 + g_recvCallback = cb;
12278 +static const char *pisnd_spi_get_serial(void)
12280 + return g_serial_num;
12283 +static const char *pisnd_spi_get_id(void)
12288 +static const char *pisnd_spi_get_fw_version(void)
12290 + return g_fw_version;
12293 +static const char *pisnd_spi_get_hw_version(void)
12295 + return g_hw_version;
12298 +static const struct of_device_id pisound_of_match[] = {
12299 + { .compatible = "blokaslabs,pisound", },
12300 + { .compatible = "blokaslabs,pisound-spi", },
12309 +static int pisnd_ctl_info(struct snd_kcontrol *kcontrol,
12310 + struct snd_ctl_elem_info *uinfo)
12312 + if (kcontrol->private_value == SWITCH) {
12313 + uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
12314 + uinfo->count = 1;
12315 + uinfo->value.integer.min = 0;
12316 + uinfo->value.integer.max = 1;
12318 + } else if (kcontrol->private_value == VOLUME) {
12319 + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
12320 + uinfo->count = 1;
12321 + uinfo->value.integer.min = 0;
12322 + uinfo->value.integer.max = 100;
12328 +static int pisnd_ctl_get(struct snd_kcontrol *kcontrol,
12329 + struct snd_ctl_elem_value *ucontrol)
12331 + if (kcontrol->private_value == SWITCH) {
12332 + ucontrol->value.integer.value[0] = 1;
12334 + } else if (kcontrol->private_value == VOLUME) {
12335 + ucontrol->value.integer.value[0] = 100;
12342 +static struct snd_kcontrol_new pisnd_ctl[] = {
12344 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12345 + .name = "PCM Playback Switch",
12347 + .private_value = SWITCH,
12348 + .access = SNDRV_CTL_ELEM_ACCESS_READ,
12349 + .info = pisnd_ctl_info,
12350 + .get = pisnd_ctl_get,
12353 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12354 + .name = "PCM Playback Volume",
12356 + .private_value = VOLUME,
12357 + .access = SNDRV_CTL_ELEM_ACCESS_READ,
12358 + .info = pisnd_ctl_info,
12359 + .get = pisnd_ctl_get,
12363 +static int pisnd_ctl_init(struct snd_card *card)
12367 + for (i = 0; i < ARRAY_SIZE(pisnd_ctl); ++i) {
12368 + err = snd_ctl_add(card, snd_ctl_new1(&pisnd_ctl[i], NULL));
12376 +static int pisnd_ctl_uninit(void)
12381 +static struct gpio_desc *osr0, *osr1, *osr2;
12382 +static struct gpio_desc *reset;
12383 +static struct gpio_desc *button;
12385 +static int pisnd_hw_params(
12386 + struct snd_pcm_substream *substream,
12387 + struct snd_pcm_hw_params *params
12390 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
12391 + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
12393 + /* Pisound runs on fixed 32 clock counts per channel,
12394 + * as generated by the master ADC.
12396 + snd_soc_dai_set_bclk_ratio(cpu_dai, 32*2);
12398 + printd("rate = %d\n", params_rate(params));
12399 + printd("ch = %d\n", params_channels(params));
12400 + printd("bits = %u\n",
12401 + snd_pcm_format_physical_width(params_format(params)));
12402 + printd("format = %d\n", params_format(params));
12404 + gpiod_set_value(reset, false);
12406 + switch (params_rate(params)) {
12408 + gpiod_set_value(osr0, true);
12409 + gpiod_set_value(osr1, false);
12410 + gpiod_set_value(osr2, false);
12413 + gpiod_set_value(osr0, true);
12414 + gpiod_set_value(osr1, false);
12415 + gpiod_set_value(osr2, true);
12418 + gpiod_set_value(osr0, true);
12419 + gpiod_set_value(osr1, true);
12420 + gpiod_set_value(osr2, true);
12423 + printe("Unsupported rate %u!\n", params_rate(params));
12427 + gpiod_set_value(reset, true);
12432 +static unsigned int rates[3] = {
12433 + 48000, 96000, 192000
12436 +static struct snd_pcm_hw_constraint_list constraints_rates = {
12437 + .count = ARRAY_SIZE(rates),
12442 +static int pisnd_startup(struct snd_pcm_substream *substream)
12444 + int err = snd_pcm_hw_constraint_list(
12445 + substream->runtime,
12447 + SNDRV_PCM_HW_PARAM_RATE,
12448 + &constraints_rates
12454 + err = snd_pcm_hw_constraint_single(
12455 + substream->runtime,
12456 + SNDRV_PCM_HW_PARAM_CHANNELS,
12463 + err = snd_pcm_hw_constraint_mask64(
12464 + substream->runtime,
12465 + SNDRV_PCM_HW_PARAM_FORMAT,
12466 + SNDRV_PCM_FMTBIT_S16_LE |
12467 + SNDRV_PCM_FMTBIT_S24_LE |
12468 + SNDRV_PCM_FMTBIT_S32_LE
12477 +static struct snd_soc_ops pisnd_ops = {
12478 + .startup = pisnd_startup,
12479 + .hw_params = pisnd_hw_params,
12482 +SND_SOC_DAILINK_DEFS(pisnd,
12483 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
12484 + DAILINK_COMP_ARRAY(COMP_DUMMY()),
12485 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
12487 +static struct snd_soc_dai_link pisnd_dai[] = {
12489 + .name = "pisound",
12490 + .stream_name = "pisound",
12492 + SND_SOC_DAIFMT_I2S |
12493 + SND_SOC_DAIFMT_NB_NF |
12494 + SND_SOC_DAIFMT_CBM_CFM,
12495 + .ops = &pisnd_ops,
12496 + SND_SOC_DAILINK_REG(pisnd),
12500 +static int pisnd_card_probe(struct snd_soc_card *card)
12502 + int err = pisnd_midi_init(card->snd_card);
12505 + printe("pisnd_midi_init failed: %d\n", err);
12509 + err = pisnd_ctl_init(card->snd_card);
12511 + printe("pisnd_ctl_init failed: %d\n", err);
12518 +static int pisnd_card_remove(struct snd_soc_card *card)
12520 + pisnd_ctl_uninit();
12521 + pisnd_midi_uninit();
12525 +static struct snd_soc_card pisnd_card = {
12526 + .name = "pisound",
12527 + .owner = THIS_MODULE,
12528 + .dai_link = pisnd_dai,
12529 + .num_links = ARRAY_SIZE(pisnd_dai),
12530 + .probe = pisnd_card_probe,
12531 + .remove = pisnd_card_remove,
12534 +static int pisnd_init_gpio(struct device *dev)
12536 + osr0 = gpiod_get_index(dev, "osr", 0, GPIOD_ASIS);
12537 + osr1 = gpiod_get_index(dev, "osr", 1, GPIOD_ASIS);
12538 + osr2 = gpiod_get_index(dev, "osr", 2, GPIOD_ASIS);
12540 + reset = gpiod_get_index(dev, "reset", 0, GPIOD_ASIS);
12542 + button = gpiod_get_index(dev, "button", 0, GPIOD_ASIS);
12544 + gpiod_direction_output(osr0, 1);
12545 + gpiod_direction_output(osr1, 1);
12546 + gpiod_direction_output(osr2, 1);
12547 + gpiod_direction_output(reset, 1);
12549 + gpiod_set_value(reset, false);
12550 + gpiod_set_value(osr0, true);
12551 + gpiod_set_value(osr1, false);
12552 + gpiod_set_value(osr2, false);
12553 + gpiod_set_value(reset, true);
12555 + gpiod_export(button, false);
12560 +static int pisnd_uninit_gpio(void)
12564 + struct gpio_desc **gpios[] = {
12565 + &osr0, &osr1, &osr2, &reset, &button,
12568 + gpiod_unexport(button);
12570 + for (i = 0; i < ARRAY_SIZE(gpios); ++i) {
12571 + if (*gpios[i] == NULL) {
12572 + printd("weird, GPIO[%d] is NULL already\n", i);
12576 + gpiod_put(*gpios[i]);
12577 + *gpios[i] = NULL;
12583 +static struct kobject *pisnd_kobj;
12585 +static ssize_t pisnd_serial_show(
12586 + struct kobject *kobj,
12587 + struct kobj_attribute *attr,
12591 + return sprintf(buf, "%s\n", pisnd_spi_get_serial());
12594 +static ssize_t pisnd_id_show(
12595 + struct kobject *kobj,
12596 + struct kobj_attribute *attr,
12600 + return sprintf(buf, "%s\n", pisnd_spi_get_id());
12603 +static ssize_t pisnd_fw_version_show(
12604 + struct kobject *kobj,
12605 + struct kobj_attribute *attr,
12609 + return sprintf(buf, "%s\n", pisnd_spi_get_fw_version());
12612 +static ssize_t pisnd_hw_version_show(
12613 + struct kobject *kobj,
12614 + struct kobj_attribute *attr,
12618 + return sprintf(buf, "%s\n", pisnd_spi_get_hw_version());
12621 +static ssize_t pisnd_led_store(
12622 + struct kobject *kobj,
12623 + struct kobj_attribute *attr,
12628 + uint32_t timeout;
12631 + err = kstrtou32(buf, 10, &timeout);
12633 + if (err == 0 && timeout <= 255)
12634 + pisnd_spi_flash_leds(timeout);
12639 +static struct kobj_attribute pisnd_serial_attribute =
12640 + __ATTR(serial, 0444, pisnd_serial_show, NULL);
12641 +static struct kobj_attribute pisnd_id_attribute =
12642 + __ATTR(id, 0444, pisnd_id_show, NULL);
12643 +static struct kobj_attribute pisnd_fw_version_attribute =
12644 + __ATTR(version, 0444, pisnd_fw_version_show, NULL);
12645 +static struct kobj_attribute pisnd_hw_version_attribute =
12646 +__ATTR(hw_version, 0444, pisnd_hw_version_show, NULL);
12647 +static struct kobj_attribute pisnd_led_attribute =
12648 + __ATTR(led, 0644, NULL, pisnd_led_store);
12650 +static struct attribute *attrs[] = {
12651 + &pisnd_serial_attribute.attr,
12652 + &pisnd_id_attribute.attr,
12653 + &pisnd_fw_version_attribute.attr,
12654 + &pisnd_hw_version_attribute.attr,
12655 + &pisnd_led_attribute.attr,
12659 +static struct attribute_group attr_group = { .attrs = attrs };
12661 +static int pisnd_probe(struct platform_device *pdev)
12666 + ret = pisnd_spi_init(&pdev->dev);
12668 + printe("pisnd_spi_init failed: %d\n", ret);
12672 + printi("Detected Pisound card:\n");
12673 + printi("\tSerial: %s\n", pisnd_spi_get_serial());
12674 + printi("\tFirmware Version: %s\n", pisnd_spi_get_fw_version());
12675 + printi("\tHardware Version: %s\n", pisnd_spi_get_hw_version());
12676 + printi("\tId: %s\n", pisnd_spi_get_id());
12678 + pisnd_kobj = kobject_create_and_add("pisound", kernel_kobj);
12679 + if (!pisnd_kobj) {
12680 + pisnd_spi_uninit();
12684 + ret = sysfs_create_group(pisnd_kobj, &attr_group);
12686 + pisnd_spi_uninit();
12687 + kobject_put(pisnd_kobj);
12691 + pisnd_init_gpio(&pdev->dev);
12692 + pisnd_card.dev = &pdev->dev;
12694 + if (pdev->dev.of_node) {
12695 + struct device_node *i2s_node;
12697 + i2s_node = of_parse_phandle(
12698 + pdev->dev.of_node,
12699 + "i2s-controller",
12703 + for (i = 0; i < pisnd_card.num_links; ++i) {
12704 + struct snd_soc_dai_link *dai = &pisnd_dai[i];
12707 + dai->cpus->dai_name = NULL;
12708 + dai->cpus->of_node = i2s_node;
12709 + dai->platforms->name = NULL;
12710 + dai->platforms->of_node = i2s_node;
12711 + dai->stream_name = pisnd_spi_get_serial();
12716 + ret = snd_soc_register_card(&pisnd_card);
12719 + if (ret != -EPROBE_DEFER)
12720 + printe("snd_soc_register_card() failed: %d\n", ret);
12721 + pisnd_uninit_gpio();
12722 + kobject_put(pisnd_kobj);
12723 + pisnd_spi_uninit();
12729 +static int pisnd_remove(struct platform_device *pdev)
12731 + printi("Unloading.\n");
12733 + if (pisnd_kobj) {
12734 + kobject_put(pisnd_kobj);
12735 + pisnd_kobj = NULL;
12738 + pisnd_spi_uninit();
12741 + gpiod_set_value(reset, false);
12742 + pisnd_uninit_gpio();
12744 + snd_soc_unregister_card(&pisnd_card);
12748 +MODULE_DEVICE_TABLE(of, pisound_of_match);
12750 +static struct platform_driver pisnd_driver = {
12752 + .name = "snd-rpi-pisound",
12753 + .owner = THIS_MODULE,
12754 + .of_match_table = pisound_of_match,
12756 + .probe = pisnd_probe,
12757 + .remove = pisnd_remove,
12760 +module_platform_driver(pisnd_driver);
12762 +MODULE_AUTHOR("Giedrius Trainavicius <giedrius@blokas.io>");
12763 +MODULE_DESCRIPTION("ASoC Driver for Pisound, https://blokas.io/pisound");
12764 +MODULE_LICENSE("GPL v2");
12766 +++ b/sound/soc/bcm/rpi-cirrus.c
12769 + * ASoC machine driver for Cirrus Logic Audio Card
12770 + * (with WM5102 and WM8804 codecs)
12772 + * Copyright 2015-2017 Matthias Reichl <hias@horus.com>
12774 + * Based on rpi-cirrus-sound-pi driver (c) Wolfson / Cirrus Logic Inc.
12776 + * This program is free software; you can redistribute it and/or modify
12777 + * it under the terms of the GNU General Public License version 2 as
12778 + * published by the Free Software Foundation.
12781 +#include <linux/module.h>
12782 +#include <linux/mutex.h>
12783 +#include <linux/slab.h>
12784 +#include <linux/list.h>
12785 +#include <linux/delay.h>
12786 +#include <sound/pcm_params.h>
12788 +#include <linux/mfd/arizona/registers.h>
12790 +#include "../codecs/wm5102.h"
12791 +#include "../codecs/wm8804.h"
12793 +#define WM8804_CLKOUT_HZ 12000000
12795 +#define RPI_CIRRUS_DEFAULT_RATE 44100
12796 +#define WM5102_MAX_SYSCLK_1 49152000 /* max sysclk for 4K family */
12797 +#define WM5102_MAX_SYSCLK_2 45158400 /* max sysclk for 11.025K family */
12799 +static inline unsigned int calc_sysclk(unsigned int rate)
12801 + return (rate % 4000) ? WM5102_MAX_SYSCLK_2 : WM5102_MAX_SYSCLK_1;
12809 +struct rpi_cirrus_priv {
12810 + /* mutex for synchronzing FLL1 access with DAPM */
12811 + struct mutex lock;
12812 + unsigned int card_rate;
12813 + int sync_path_enable;
12814 + int fll1_freq; /* negative means RefClock in spdif rx case */
12816 + /* track hw params/free for substreams */
12817 + unsigned int params_set;
12818 + unsigned int min_rate_idx, max_rate_idx;
12819 + unsigned char iec958_status[4];
12822 +/* helper functions */
12823 +static inline struct snd_soc_pcm_runtime *get_wm5102_runtime(
12824 + struct snd_soc_card *card) {
12825 + return snd_soc_get_pcm_runtime(card, &card->dai_link[DAI_WM5102]);
12828 +static inline struct snd_soc_pcm_runtime *get_wm8804_runtime(
12829 + struct snd_soc_card *card) {
12830 + return snd_soc_get_pcm_runtime(card, &card->dai_link[DAI_WM8804]);
12834 +struct rate_info {
12835 + unsigned int value;
12839 +static struct rate_info min_rates[] = {
12841 + { 32000, "32kHz"},
12842 + { 44100, "44.1kHz"}
12845 +#define NUM_MIN_RATES ARRAY_SIZE(min_rates)
12847 +static int rpi_cirrus_min_rate_info(struct snd_kcontrol *kcontrol,
12848 + struct snd_ctl_elem_info *uinfo)
12850 + uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
12851 + uinfo->count = 1;
12852 + uinfo->value.enumerated.items = NUM_MIN_RATES;
12854 + if (uinfo->value.enumerated.item >= NUM_MIN_RATES)
12855 + uinfo->value.enumerated.item = NUM_MIN_RATES - 1;
12856 + strcpy(uinfo->value.enumerated.name,
12857 + min_rates[uinfo->value.enumerated.item].text);
12861 +static int rpi_cirrus_min_rate_get(struct snd_kcontrol *kcontrol,
12862 + struct snd_ctl_elem_value *ucontrol)
12864 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
12865 + struct rpi_cirrus_priv *priv = snd_soc_card_get_drvdata(card);
12867 + ucontrol->value.enumerated.item[0] = priv->min_rate_idx;
12871 +static int rpi_cirrus_min_rate_put(struct snd_kcontrol *kcontrol,
12872 + struct snd_ctl_elem_value *ucontrol)
12874 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
12875 + struct rpi_cirrus_priv *priv = snd_soc_card_get_drvdata(card);
12878 + if (priv->min_rate_idx != ucontrol->value.enumerated.item[0]) {
12880 + priv->min_rate_idx = ucontrol->value.enumerated.item[0];
12886 +static struct rate_info max_rates[] = {
12888 + { 48000, "48kHz"},
12889 + { 96000, "96kHz"}
12892 +#define NUM_MAX_RATES ARRAY_SIZE(max_rates)
12894 +static int rpi_cirrus_max_rate_info(struct snd_kcontrol *kcontrol,
12895 + struct snd_ctl_elem_info *uinfo)
12897 + uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
12898 + uinfo->count = 1;
12899 + uinfo->value.enumerated.items = NUM_MAX_RATES;
12900 + if (uinfo->value.enumerated.item >= NUM_MAX_RATES)
12901 + uinfo->value.enumerated.item = NUM_MAX_RATES - 1;
12902 + strcpy(uinfo->value.enumerated.name,
12903 + max_rates[uinfo->value.enumerated.item].text);
12907 +static int rpi_cirrus_max_rate_get(struct snd_kcontrol *kcontrol,
12908 + struct snd_ctl_elem_value *ucontrol)
12910 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
12911 + struct rpi_cirrus_priv *priv = snd_soc_card_get_drvdata(card);
12913 + ucontrol->value.enumerated.item[0] = priv->max_rate_idx;
12917 +static int rpi_cirrus_max_rate_put(struct snd_kcontrol *kcontrol,
12918 + struct snd_ctl_elem_value *ucontrol)
12920 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
12921 + struct rpi_cirrus_priv *priv = snd_soc_card_get_drvdata(card);
12924 + if (priv->max_rate_idx != ucontrol->value.enumerated.item[0]) {
12926 + priv->max_rate_idx = ucontrol->value.enumerated.item[0];
12932 +static int rpi_cirrus_spdif_info(struct snd_kcontrol *kcontrol,
12933 + struct snd_ctl_elem_info *uinfo)
12935 + uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
12936 + uinfo->count = 1;
12940 +static int rpi_cirrus_spdif_playback_get(struct snd_kcontrol *kcontrol,
12941 + struct snd_ctl_elem_value *ucontrol)
12943 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
12944 + struct rpi_cirrus_priv *priv = snd_soc_card_get_drvdata(card);
12947 + for (i = 0; i < 4; i++)
12948 + ucontrol->value.iec958.status[i] = priv->iec958_status[i];
12953 +static int rpi_cirrus_spdif_playback_put(struct snd_kcontrol *kcontrol,
12954 + struct snd_ctl_elem_value *ucontrol)
12956 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
12957 + struct snd_soc_component *wm8804_component =
12958 + asoc_rtd_to_codec(get_wm8804_runtime(card), 0)->component;
12959 + struct rpi_cirrus_priv *priv = snd_soc_card_get_drvdata(card);
12960 + unsigned char *stat = priv->iec958_status;
12961 + unsigned char *ctrl_stat = ucontrol->value.iec958.status;
12962 + unsigned int mask;
12963 + int i, changed = 0;
12965 + for (i = 0; i < 4; i++) {
12966 + mask = (i == 3) ? 0x3f : 0xff;
12967 + if ((ctrl_stat[i] & mask) != (stat[i] & mask)) {
12969 + stat[i] = ctrl_stat[i] & mask;
12970 + snd_soc_component_update_bits(wm8804_component,
12971 + WM8804_SPDTX1 + i, mask, stat[i]);
12978 +static int rpi_cirrus_spdif_mask_get(struct snd_kcontrol *kcontrol,
12979 + struct snd_ctl_elem_value *ucontrol)
12981 + ucontrol->value.iec958.status[0] = 0xff;
12982 + ucontrol->value.iec958.status[1] = 0xff;
12983 + ucontrol->value.iec958.status[2] = 0xff;
12984 + ucontrol->value.iec958.status[3] = 0x3f;
12989 +static int rpi_cirrus_spdif_capture_get(struct snd_kcontrol *kcontrol,
12990 + struct snd_ctl_elem_value *ucontrol)
12992 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
12993 + struct snd_soc_component *wm8804_component =
12994 + asoc_rtd_to_codec(get_wm8804_runtime(card), 0)->component;
12995 + unsigned int val, mask;
12998 + for (i = 0; i < 4; i++) {
12999 + val = snd_soc_component_read(wm8804_component,
13000 + WM8804_RXCHAN1 + i);
13001 + mask = (i == 3) ? 0x3f : 0xff;
13002 + ucontrol->value.iec958.status[i] = val & mask;
13008 +#define SPDIF_FLAG_CTRL(desc, reg, bit, invert) \
13010 + .access = SNDRV_CTL_ELEM_ACCESS_READ \
13011 + | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
13012 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
13013 + .name = SNDRV_CTL_NAME_IEC958("", CAPTURE, NONE) \
13015 + .info = snd_ctl_boolean_mono_info, \
13016 + .get = rpi_cirrus_spdif_status_flag_get, \
13017 + .private_value = \
13018 + (bit) | ((reg) << 8) | ((invert) << 16) \
13021 +static int rpi_cirrus_spdif_status_flag_get(struct snd_kcontrol *kcontrol,
13022 + struct snd_ctl_elem_value *ucontrol)
13024 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
13025 + struct snd_soc_component *wm8804_component =
13026 + asoc_rtd_to_codec(get_wm8804_runtime(card), 0)->component;
13028 + unsigned int bit = kcontrol->private_value & 0xff;
13029 + unsigned int reg = (kcontrol->private_value >> 8) & 0xff;
13030 + unsigned int invert = (kcontrol->private_value >> 16) & 0xff;
13031 + unsigned int val;
13034 + val = snd_soc_component_read(wm8804_component, reg);
13036 + flag = val & (1 << bit);
13038 + ucontrol->value.integer.value[0] = invert ? !flag : flag;
13043 +static const char * const recovered_frequency_texts[] = {
13050 +#define NUM_RECOVERED_FREQUENCIES \
13051 + ARRAY_SIZE(recovered_frequency_texts)
13053 +static int rpi_cirrus_recovered_frequency_info(struct snd_kcontrol *kcontrol,
13054 + struct snd_ctl_elem_info *uinfo)
13056 + uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
13057 + uinfo->count = 1;
13058 + uinfo->value.enumerated.items = NUM_RECOVERED_FREQUENCIES;
13059 + if (uinfo->value.enumerated.item >= NUM_RECOVERED_FREQUENCIES)
13060 + uinfo->value.enumerated.item = NUM_RECOVERED_FREQUENCIES - 1;
13061 + strcpy(uinfo->value.enumerated.name,
13062 + recovered_frequency_texts[uinfo->value.enumerated.item]);
13066 +static int rpi_cirrus_recovered_frequency_get(struct snd_kcontrol *kcontrol,
13067 + struct snd_ctl_elem_value *ucontrol)
13069 + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
13070 + struct snd_soc_component *wm8804_component =
13071 + asoc_rtd_to_codec(get_wm8804_runtime(card), 0)->component;
13072 + unsigned int val;
13074 + val = snd_soc_component_read(wm8804_component, WM8804_SPDSTAT);
13076 + ucontrol->value.enumerated.item[0] = (val >> 4) & 0x03;
13080 +static const struct snd_kcontrol_new rpi_cirrus_controls[] = {
13082 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13083 + .name = "Min Sample Rate",
13084 + .info = rpi_cirrus_min_rate_info,
13085 + .get = rpi_cirrus_min_rate_get,
13086 + .put = rpi_cirrus_min_rate_put,
13089 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13090 + .name = "Max Sample Rate",
13091 + .info = rpi_cirrus_max_rate_info,
13092 + .get = rpi_cirrus_max_rate_get,
13093 + .put = rpi_cirrus_max_rate_put,
13096 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13097 + .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT),
13098 + .info = rpi_cirrus_spdif_info,
13099 + .get = rpi_cirrus_spdif_playback_get,
13100 + .put = rpi_cirrus_spdif_playback_put,
13103 + .access = SNDRV_CTL_ELEM_ACCESS_READ
13104 + | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
13105 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13106 + .name = SNDRV_CTL_NAME_IEC958("", CAPTURE, DEFAULT),
13107 + .info = rpi_cirrus_spdif_info,
13108 + .get = rpi_cirrus_spdif_capture_get,
13111 + .access = SNDRV_CTL_ELEM_ACCESS_READ,
13112 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13113 + .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, MASK),
13114 + .info = rpi_cirrus_spdif_info,
13115 + .get = rpi_cirrus_spdif_mask_get,
13118 + .access = SNDRV_CTL_ELEM_ACCESS_READ
13119 + | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
13120 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13121 + .name = SNDRV_CTL_NAME_IEC958("", CAPTURE, NONE)
13122 + "Recovered Frequency",
13123 + .info = rpi_cirrus_recovered_frequency_info,
13124 + .get = rpi_cirrus_recovered_frequency_get,
13126 + SPDIF_FLAG_CTRL("Audio", WM8804_SPDSTAT, 0, 1),
13127 + SPDIF_FLAG_CTRL("Non-PCM", WM8804_SPDSTAT, 1, 0),
13128 + SPDIF_FLAG_CTRL("Copyright", WM8804_SPDSTAT, 2, 1),
13129 + SPDIF_FLAG_CTRL("De-Emphasis", WM8804_SPDSTAT, 3, 0),
13130 + SPDIF_FLAG_CTRL("Lock", WM8804_SPDSTAT, 6, 1),
13131 + SPDIF_FLAG_CTRL("Invalid", WM8804_INTSTAT, 1, 0),
13132 + SPDIF_FLAG_CTRL("TransErr", WM8804_INTSTAT, 3, 0),
13135 +static const char * const linein_micbias_texts[] = {
13139 +static SOC_ENUM_SINGLE_VIRT_DECL(linein_micbias_enum,
13140 + linein_micbias_texts);
13142 +static const struct snd_kcontrol_new linein_micbias_mux =
13143 + SOC_DAPM_ENUM("Route", linein_micbias_enum);
13145 +static int rpi_cirrus_spdif_rx_enable_event(struct snd_soc_dapm_widget *w,
13146 + struct snd_kcontrol *kcontrol, int event);
13148 +const struct snd_soc_dapm_widget rpi_cirrus_dapm_widgets[] = {
13149 + SND_SOC_DAPM_MIC("DMIC", NULL),
13150 + SND_SOC_DAPM_MIC("Headset Mic", NULL),
13151 + SND_SOC_DAPM_INPUT("Line Input"),
13152 + SND_SOC_DAPM_MIC("Line Input with Micbias", NULL),
13153 + SND_SOC_DAPM_MUX("Line Input Micbias", SND_SOC_NOPM, 0, 0,
13154 + &linein_micbias_mux),
13155 + SND_SOC_DAPM_INPUT("dummy SPDIF in"),
13156 + SND_SOC_DAPM_PGA_E("dummy SPDIFRX", SND_SOC_NOPM, 0, 0, NULL, 0,
13157 + rpi_cirrus_spdif_rx_enable_event,
13158 + SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
13159 + SND_SOC_DAPM_INPUT("Dummy Input"),
13160 + SND_SOC_DAPM_OUTPUT("Dummy Output"),
13163 +const struct snd_soc_dapm_route rpi_cirrus_dapm_routes[] = {
13164 + { "IN1L", NULL, "Headset Mic" },
13165 + { "IN1R", NULL, "Headset Mic" },
13166 + { "Headset Mic", NULL, "MICBIAS1" },
13168 + { "IN2L", NULL, "DMIC" },
13169 + { "IN2R", NULL, "DMIC" },
13170 + { "DMIC", NULL, "MICBIAS2" },
13172 + { "IN3L", NULL, "Line Input Micbias" },
13173 + { "IN3R", NULL, "Line Input Micbias" },
13175 + { "Line Input Micbias", "off", "Line Input" },
13176 + { "Line Input Micbias", "on", "Line Input with Micbias" },
13178 + /* Make sure MICVDD is enabled, otherwise we get noise */
13179 + { "Line Input", NULL, "MICVDD" },
13180 + { "Line Input with Micbias", NULL, "MICBIAS3" },
13182 + /* Dummy routes to check whether SPDIF RX is enabled or not */
13183 + {"dummy SPDIFRX", NULL, "dummy SPDIF in"},
13184 + {"AIFTX", NULL, "dummy SPDIFRX"},
13187 + * Dummy routes to keep wm5102 from staying off on
13188 + * playback/capture if all mixers are off.
13190 + { "Dummy Output", NULL, "AIF1RX1" },
13191 + { "Dummy Output", NULL, "AIF1RX2" },
13192 + { "AIF1TX1", NULL, "Dummy Input" },
13193 + { "AIF1TX2", NULL, "Dummy Input" },
13196 +static int rpi_cirrus_clear_flls(struct snd_soc_card *card,
13197 + struct snd_soc_component *wm5102_component) {
13201 + ret1 = snd_soc_component_set_pll(wm5102_component,
13202 + WM5102_FLL1, ARIZONA_FLL_SRC_NONE, 0, 0);
13203 + ret2 = snd_soc_component_set_pll(wm5102_component,
13204 + WM5102_FLL1_REFCLK, ARIZONA_FLL_SRC_NONE, 0, 0);
13207 + dev_warn(card->dev,
13208 + "setting FLL1 to zero failed: %d\n", ret1);
13212 + dev_warn(card->dev,
13213 + "setting FLL1_REFCLK to zero failed: %d\n", ret2);
13219 +static int rpi_cirrus_set_fll(struct snd_soc_card *card,
13220 + struct snd_soc_component *wm5102_component, unsigned int clk_freq)
13222 + int ret = snd_soc_component_set_pll(wm5102_component,
13224 + ARIZONA_CLK_SRC_MCLK1,
13225 + WM8804_CLKOUT_HZ,
13228 + dev_err(card->dev, "Failed to set FLL1 to %d: %d\n",
13231 + usleep_range(1000, 2000);
13235 +static int rpi_cirrus_set_fll_refclk(struct snd_soc_card *card,
13236 + struct snd_soc_component *wm5102_component,
13237 + unsigned int clk_freq, unsigned int aif2_freq)
13239 + int ret = snd_soc_component_set_pll(wm5102_component,
13240 + WM5102_FLL1_REFCLK,
13241 + ARIZONA_CLK_SRC_MCLK1,
13242 + WM8804_CLKOUT_HZ,
13245 + dev_err(card->dev,
13246 + "Failed to set FLL1_REFCLK to %d: %d\n",
13251 + ret = snd_soc_component_set_pll(wm5102_component,
13253 + ARIZONA_CLK_SRC_AIF2BCLK,
13254 + aif2_freq, clk_freq);
13256 + dev_err(card->dev,
13257 + "Failed to set FLL1 with Sync Clock %d to %d: %d\n",
13258 + aif2_freq, clk_freq, ret);
13260 + usleep_range(1000, 2000);
13264 +static int rpi_cirrus_spdif_rx_enable_event(struct snd_soc_dapm_widget *w,
13265 + struct snd_kcontrol *kcontrol, int event)
13267 + struct snd_soc_card *card = w->dapm->card;
13268 + struct rpi_cirrus_priv *priv = snd_soc_card_get_drvdata(card);
13269 + struct snd_soc_component *wm5102_component =
13270 + asoc_rtd_to_codec(get_wm5102_runtime(card), 0)->component;
13272 + unsigned int clk_freq, aif2_freq;
13276 + case SND_SOC_DAPM_POST_PMU:
13277 + mutex_lock(&priv->lock);
13279 + /* Enable sync path in case of SPDIF capture use case */
13281 + clk_freq = calc_sysclk(priv->card_rate);
13282 + aif2_freq = 64 * priv->card_rate;
13284 + dev_dbg(card->dev,
13285 + "spdif_rx: changing FLL1 to use Ref Clock clk: %d spdif: %d\n",
13286 + clk_freq, aif2_freq);
13288 + ret = rpi_cirrus_clear_flls(card, wm5102_component);
13290 + dev_err(card->dev, "spdif_rx: failed to clear FLLs\n");
13294 + ret = rpi_cirrus_set_fll_refclk(card, wm5102_component,
13295 + clk_freq, aif2_freq);
13298 + dev_err(card->dev, "spdif_rx: failed to set FLLs\n");
13302 + /* set to negative to indicate we're doing spdif rx */
13303 + priv->fll1_freq = -clk_freq;
13304 + priv->sync_path_enable = 1;
13307 + case SND_SOC_DAPM_POST_PMD:
13308 + mutex_lock(&priv->lock);
13309 + priv->sync_path_enable = 0;
13317 + mutex_unlock(&priv->lock);
13321 +static int rpi_cirrus_set_bias_level(struct snd_soc_card *card,
13322 + struct snd_soc_dapm_context *dapm,
13323 + enum snd_soc_bias_level level)
13325 + struct rpi_cirrus_priv *priv = snd_soc_card_get_drvdata(card);
13326 + struct snd_soc_pcm_runtime *wm5102_runtime = get_wm5102_runtime(card);
13327 + struct snd_soc_component *wm5102_component =
13328 + asoc_rtd_to_codec(wm5102_runtime, 0)->component;
13331 + unsigned int clk_freq;
13333 + if (dapm->dev != asoc_rtd_to_codec(wm5102_runtime, 0)->dev)
13337 + case SND_SOC_BIAS_PREPARE:
13338 + if (dapm->bias_level == SND_SOC_BIAS_ON)
13341 + mutex_lock(&priv->lock);
13343 + if (!priv->sync_path_enable) {
13344 + clk_freq = calc_sysclk(priv->card_rate);
13346 + dev_dbg(card->dev,
13347 + "set_bias: changing FLL1 from %d to %d\n",
13348 + priv->fll1_freq, clk_freq);
13350 + ret = rpi_cirrus_set_fll(card,
13351 + wm5102_component, clk_freq);
13353 + dev_err(card->dev,
13354 + "set_bias: Failed to set FLL1\n");
13356 + priv->fll1_freq = clk_freq;
13358 + mutex_unlock(&priv->lock);
13367 +static int rpi_cirrus_set_bias_level_post(struct snd_soc_card *card,
13368 + struct snd_soc_dapm_context *dapm,
13369 + enum snd_soc_bias_level level)
13371 + struct rpi_cirrus_priv *priv = snd_soc_card_get_drvdata(card);
13372 + struct snd_soc_pcm_runtime *wm5102_runtime = get_wm5102_runtime(card);
13373 + struct snd_soc_component *wm5102_component =
13374 + asoc_rtd_to_codec(wm5102_runtime, 0)->component;
13376 + if (dapm->dev != asoc_rtd_to_codec(wm5102_runtime, 0)->dev)
13380 + case SND_SOC_BIAS_STANDBY:
13381 + mutex_lock(&priv->lock);
13383 + dev_dbg(card->dev,
13384 + "set_bias_post: changing FLL1 from %d to off\n",
13385 + priv->fll1_freq);
13387 + if (rpi_cirrus_clear_flls(card, wm5102_component))
13388 + dev_err(card->dev,
13389 + "set_bias_post: failed to clear FLLs\n");
13391 + priv->fll1_freq = 0;
13393 + mutex_unlock(&priv->lock);
13403 +static int rpi_cirrus_set_wm8804_pll(struct snd_soc_card *card,
13404 + struct snd_soc_dai *wm8804_dai, unsigned int rate)
13409 + unsigned int clk_freq = rate * 256;
13411 + ret = snd_soc_dai_set_pll(wm8804_dai, 0, 0,
13412 + WM8804_CLKOUT_HZ, clk_freq);
13414 + dev_err(card->dev,
13415 + "Failed to set WM8804 PLL to %d: %d\n", clk_freq, ret);
13419 + /* Set MCLK as PLL Output */
13420 + ret = snd_soc_dai_set_sysclk(wm8804_dai,
13421 + WM8804_TX_CLKSRC_PLL, clk_freq, 0);
13423 + dev_err(card->dev,
13424 + "Failed to set MCLK as PLL Output: %d\n", ret);
13431 +static int rpi_cirrus_startup(struct snd_pcm_substream *substream)
13433 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
13434 + struct snd_soc_card *card = rtd->card;
13435 + struct rpi_cirrus_priv *priv = snd_soc_card_get_drvdata(card);
13436 + unsigned int min_rate = min_rates[priv->min_rate_idx].value;
13437 + unsigned int max_rate = max_rates[priv->max_rate_idx].value;
13439 + if (min_rate || max_rate) {
13440 + if (max_rate == 0)
13441 + max_rate = UINT_MAX;
13443 + dev_dbg(card->dev,
13444 + "startup: limiting rate to %u-%u\n",
13445 + min_rate, max_rate);
13447 + snd_pcm_hw_constraint_minmax(substream->runtime,
13448 + SNDRV_PCM_HW_PARAM_RATE, min_rate, max_rate);
13454 +static struct snd_soc_pcm_stream rpi_cirrus_dai_link2_params = {
13455 + .formats = SNDRV_PCM_FMTBIT_S24_LE,
13456 + .channels_min = 2,
13457 + .channels_max = 2,
13458 + .rate_min = RPI_CIRRUS_DEFAULT_RATE,
13459 + .rate_max = RPI_CIRRUS_DEFAULT_RATE,
13462 +static int rpi_cirrus_hw_params(struct snd_pcm_substream *substream,
13463 + struct snd_pcm_hw_params *params)
13465 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
13466 + struct snd_soc_card *card = rtd->card;
13467 + struct rpi_cirrus_priv *priv = snd_soc_card_get_drvdata(card);
13468 + struct snd_soc_dai *bcm_i2s_dai = asoc_rtd_to_cpu(rtd, 0);
13469 + struct snd_soc_component *wm5102_component = asoc_rtd_to_codec(rtd, 0)->component;
13470 + struct snd_soc_dai *wm8804_dai = asoc_rtd_to_codec(get_wm8804_runtime(card), 0);
13474 + unsigned int width = snd_pcm_format_physical_width(
13475 + params_format(params));
13476 + unsigned int rate = params_rate(params);
13477 + unsigned int clk_freq = calc_sysclk(rate);
13479 + mutex_lock(&priv->lock);
13481 + dev_dbg(card->dev, "hw_params: setting rate to %d\n", rate);
13483 + ret = snd_soc_dai_set_bclk_ratio(bcm_i2s_dai, 2 * width);
13485 + dev_err(card->dev, "set_bclk_ratio failed: %d\n", ret);
13489 + ret = snd_soc_dai_set_tdm_slot(asoc_rtd_to_codec(rtd, 0), 0x03, 0x03, 2, width);
13491 + dev_err(card->dev, "set_tdm_slot failed: %d\n", ret);
13495 + /* WM8804 supports sample rates from 32k only */
13496 + if (rate >= 32000) {
13497 + ret = rpi_cirrus_set_wm8804_pll(card, wm8804_dai, rate);
13502 + ret = snd_soc_component_set_sysclk(wm5102_component,
13503 + ARIZONA_CLK_SYSCLK,
13504 + ARIZONA_CLK_SRC_FLL1,
13506 + SND_SOC_CLOCK_IN);
13508 + dev_err(card->dev, "Failed to set SYSCLK: %d\n", ret);
13512 + if ((priv->fll1_freq > 0) && (priv->fll1_freq != clk_freq)) {
13513 + dev_dbg(card->dev,
13514 + "hw_params: changing FLL1 from %d to %d\n",
13515 + priv->fll1_freq, clk_freq);
13517 + if (rpi_cirrus_clear_flls(card, wm5102_component)) {
13518 + dev_err(card->dev, "hw_params: failed to clear FLLs\n");
13522 + if (rpi_cirrus_set_fll(card, wm5102_component, clk_freq)) {
13523 + dev_err(card->dev, "hw_params: failed to set FLL\n");
13527 + priv->fll1_freq = clk_freq;
13530 + priv->card_rate = rate;
13531 + rpi_cirrus_dai_link2_params.rate_min = rate;
13532 + rpi_cirrus_dai_link2_params.rate_max = rate;
13534 + priv->params_set |= 1 << substream->stream;
13537 + mutex_unlock(&priv->lock);
13542 +static int rpi_cirrus_hw_free(struct snd_pcm_substream *substream)
13544 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
13545 + struct snd_soc_card *card = rtd->card;
13546 + struct rpi_cirrus_priv *priv = snd_soc_card_get_drvdata(card);
13547 + struct snd_soc_component *wm5102_component = asoc_rtd_to_codec(rtd, 0)->component;
13549 + unsigned int old_params_set = priv->params_set;
13551 + priv->params_set &= ~(1 << substream->stream);
13553 + /* disable sysclk if this was the last open stream */
13554 + if (priv->params_set == 0 && old_params_set) {
13555 + dev_dbg(card->dev,
13556 + "hw_free: Setting SYSCLK to Zero\n");
13558 + ret = snd_soc_component_set_sysclk(wm5102_component,
13559 + ARIZONA_CLK_SYSCLK,
13560 + ARIZONA_CLK_SRC_FLL1,
13562 + SND_SOC_CLOCK_IN);
13564 + dev_err(card->dev,
13565 + "hw_free: Failed to set SYSCLK to Zero: %d\n",
13571 +static int rpi_cirrus_init_wm5102(struct snd_soc_pcm_runtime *rtd)
13573 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
13576 + /* no 32kHz input, derive it from sysclk if needed */
13577 + snd_soc_component_update_bits(component,
13578 + ARIZONA_CLOCK_32K_1, ARIZONA_CLK_32K_SRC_MASK, 2);
13580 + if (rpi_cirrus_clear_flls(rtd->card, component))
13581 + dev_warn(rtd->card->dev,
13582 + "init_wm5102: failed to clear FLLs\n");
13584 + ret = snd_soc_component_set_sysclk(component,
13585 + ARIZONA_CLK_SYSCLK, ARIZONA_CLK_SRC_FLL1,
13586 + 0, SND_SOC_CLOCK_IN);
13588 + dev_err(rtd->card->dev,
13589 + "Failed to set SYSCLK to Zero: %d\n", ret);
13596 +static int rpi_cirrus_init_wm8804(struct snd_soc_pcm_runtime *rtd)
13598 + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
13599 + struct snd_soc_component *component = codec_dai->component;
13600 + struct snd_soc_card *card = rtd->card;
13601 + struct rpi_cirrus_priv *priv = snd_soc_card_get_drvdata(card);
13602 + unsigned int val, mask;
13605 + for (i = 0; i < 4; i++) {
13606 + val = snd_soc_component_read(component,
13607 + WM8804_SPDTX1 + i);
13608 + mask = (i == 3) ? 0x3f : 0xff;
13609 + priv->iec958_status[i] = val & mask;
13612 + /* Setup for 256fs */
13613 + ret = snd_soc_dai_set_clkdiv(codec_dai,
13614 + WM8804_MCLK_DIV, WM8804_MCLKDIV_256FS);
13616 + dev_err(card->dev,
13617 + "init_wm8804: Failed to set MCLK_DIV to 256fs: %d\n",
13622 + /* Output OSC on CLKOUT */
13623 + ret = snd_soc_dai_set_sysclk(codec_dai,
13624 + WM8804_CLKOUT_SRC_OSCCLK, WM8804_CLKOUT_HZ, 0);
13626 + dev_err(card->dev,
13627 + "init_wm8804: Failed to set CLKOUT as OSC Frequency: %d\n",
13630 + /* Init PLL with default samplerate */
13631 + ret = rpi_cirrus_set_wm8804_pll(card, codec_dai,
13632 + RPI_CIRRUS_DEFAULT_RATE);
13634 + dev_err(card->dev,
13635 + "init_wm8804: Failed to setup PLL for %dHz: %d\n",
13636 + RPI_CIRRUS_DEFAULT_RATE, ret);
13641 +static struct snd_soc_ops rpi_cirrus_ops = {
13642 + .startup = rpi_cirrus_startup,
13643 + .hw_params = rpi_cirrus_hw_params,
13644 + .hw_free = rpi_cirrus_hw_free,
13647 +SND_SOC_DAILINK_DEFS(wm5102,
13648 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
13649 + DAILINK_COMP_ARRAY(COMP_CODEC("wm5102-codec", "wm5102-aif1")),
13650 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
13652 +SND_SOC_DAILINK_DEFS(wm8804,
13653 + DAILINK_COMP_ARRAY(COMP_CPU("wm5102-aif2")),
13654 + DAILINK_COMP_ARRAY(COMP_CODEC("wm8804.1-003b", "wm8804-spdif")));
13656 +static struct snd_soc_dai_link rpi_cirrus_dai[] = {
13658 + .name = "WM5102",
13659 + .stream_name = "WM5102 AiFi",
13660 + .dai_fmt = SND_SOC_DAIFMT_I2S
13661 + | SND_SOC_DAIFMT_NB_NF
13662 + | SND_SOC_DAIFMT_CBM_CFM,
13663 + .ops = &rpi_cirrus_ops,
13664 + .init = rpi_cirrus_init_wm5102,
13665 + SND_SOC_DAILINK_REG(wm5102),
13668 + .name = "WM5102 SPDIF",
13669 + .stream_name = "SPDIF Tx/Rx",
13670 + .dai_fmt = SND_SOC_DAIFMT_I2S
13671 + | SND_SOC_DAIFMT_NB_NF
13672 + | SND_SOC_DAIFMT_CBM_CFM,
13673 + .ignore_suspend = 1,
13674 + .c2c_params = &rpi_cirrus_dai_link2_params,
13675 + .init = rpi_cirrus_init_wm8804,
13676 + SND_SOC_DAILINK_REG(wm8804),
13681 +static int rpi_cirrus_late_probe(struct snd_soc_card *card)
13683 + struct rpi_cirrus_priv *priv = snd_soc_card_get_drvdata(card);
13684 + struct snd_soc_pcm_runtime *wm5102_runtime = get_wm5102_runtime(card);
13685 + struct snd_soc_pcm_runtime *wm8804_runtime = get_wm8804_runtime(card);
13688 + dev_dbg(card->dev, "iec958_bits: %02x %02x %02x %02x\n",
13689 + priv->iec958_status[0],
13690 + priv->iec958_status[1],
13691 + priv->iec958_status[2],
13692 + priv->iec958_status[3]);
13694 + ret = snd_soc_dai_set_sysclk(
13695 + asoc_rtd_to_codec(wm5102_runtime, 0), ARIZONA_CLK_SYSCLK, 0, 0);
13697 + dev_err(card->dev,
13698 + "Failed to set WM5102 codec dai clk domain: %d\n", ret);
13702 + ret = snd_soc_dai_set_sysclk(
13703 + asoc_rtd_to_cpu(wm8804_runtime, 0), ARIZONA_CLK_SYSCLK, 0, 0);
13705 + dev_err(card->dev,
13706 + "Failed to set WM8804 codec dai clk domain: %d\n", ret);
13711 +/* audio machine driver */
13712 +static struct snd_soc_card rpi_cirrus_card = {
13713 + .name = "RPi-Cirrus",
13714 + .driver_name = "RPiCirrus",
13715 + .owner = THIS_MODULE,
13716 + .dai_link = rpi_cirrus_dai,
13717 + .num_links = ARRAY_SIZE(rpi_cirrus_dai),
13718 + .late_probe = rpi_cirrus_late_probe,
13719 + .controls = rpi_cirrus_controls,
13720 + .num_controls = ARRAY_SIZE(rpi_cirrus_controls),
13721 + .dapm_widgets = rpi_cirrus_dapm_widgets,
13722 + .num_dapm_widgets = ARRAY_SIZE(rpi_cirrus_dapm_widgets),
13723 + .dapm_routes = rpi_cirrus_dapm_routes,
13724 + .num_dapm_routes = ARRAY_SIZE(rpi_cirrus_dapm_routes),
13725 + .set_bias_level = rpi_cirrus_set_bias_level,
13726 + .set_bias_level_post = rpi_cirrus_set_bias_level_post,
13729 +static int rpi_cirrus_probe(struct platform_device *pdev)
13732 + struct rpi_cirrus_priv *priv;
13733 + struct device_node *i2s_node;
13735 + priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
13739 + priv->min_rate_idx = 1; /* min samplerate 32kHz */
13740 + priv->card_rate = RPI_CIRRUS_DEFAULT_RATE;
13742 + mutex_init(&priv->lock);
13744 + snd_soc_card_set_drvdata(&rpi_cirrus_card, priv);
13746 + if (!pdev->dev.of_node)
13749 + i2s_node = of_parse_phandle(
13750 + pdev->dev.of_node, "i2s-controller", 0);
13752 + dev_err(&pdev->dev, "i2s-controller missing in DT\n");
13756 + rpi_cirrus_dai[DAI_WM5102].cpus->of_node = i2s_node;
13757 + rpi_cirrus_dai[DAI_WM5102].platforms->of_node = i2s_node;
13759 + rpi_cirrus_card.dev = &pdev->dev;
13761 + ret = devm_snd_soc_register_card(&pdev->dev, &rpi_cirrus_card);
13763 + if (ret == -EPROBE_DEFER)
13764 + dev_dbg(&pdev->dev,
13765 + "register card requested probe deferral\n");
13767 + dev_err(&pdev->dev,
13768 + "Failed to register card: %d\n", ret);
13774 +static const struct of_device_id rpi_cirrus_of_match[] = {
13775 + { .compatible = "wlf,rpi-cirrus", },
13778 +MODULE_DEVICE_TABLE(of, rpi_cirrus_of_match);
13780 +static struct platform_driver rpi_cirrus_driver = {
13782 + .name = "snd-rpi-cirrus",
13783 + .of_match_table = of_match_ptr(rpi_cirrus_of_match),
13785 + .probe = rpi_cirrus_probe,
13788 +module_platform_driver(rpi_cirrus_driver);
13790 +MODULE_AUTHOR("Matthias Reichl <hias@horus.com>");
13791 +MODULE_DESCRIPTION("ASoC driver for Cirrus Logic Audio Card");
13792 +MODULE_LICENSE("GPL");
13794 +++ b/sound/soc/bcm/rpi-proto.c
13797 + * ASoC driver for PROTO AudioCODEC (with a WM8731)
13798 + * connected to a Raspberry Pi
13800 + * Author: Florian Meier, <koalo@koalo.de>
13803 + * This program is free software; you can redistribute it and/or modify
13804 + * it under the terms of the GNU General Public License version 2 as
13805 + * published by the Free Software Foundation.
13808 +#include <linux/module.h>
13809 +#include <linux/platform_device.h>
13811 +#include <sound/core.h>
13812 +#include <sound/pcm.h>
13813 +#include <sound/soc.h>
13814 +#include <sound/jack.h>
13816 +#include "../codecs/wm8731.h"
13818 +static const unsigned int wm8731_rates_12288000[] = {
13819 + 8000, 32000, 48000, 96000,
13822 +static struct snd_pcm_hw_constraint_list wm8731_constraints_12288000 = {
13823 + .list = wm8731_rates_12288000,
13824 + .count = ARRAY_SIZE(wm8731_rates_12288000),
13827 +static int snd_rpi_proto_startup(struct snd_pcm_substream *substream)
13829 + /* Setup constraints, because there is a 12.288 MHz XTAL on the board */
13830 + snd_pcm_hw_constraint_list(substream->runtime, 0,
13831 + SNDRV_PCM_HW_PARAM_RATE,
13832 + &wm8731_constraints_12288000);
13836 +static int snd_rpi_proto_hw_params(struct snd_pcm_substream *substream,
13837 + struct snd_pcm_hw_params *params)
13839 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
13840 + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
13841 + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
13842 + int sysclk = 12288000; /* This is fixed on this board */
13844 + /* Set proto bclk */
13845 + int ret = snd_soc_dai_set_bclk_ratio(cpu_dai,32*2);
13847 + dev_err(rtd->card->dev,
13848 + "Failed to set BCLK ratio %d\n", ret);
13852 + /* Set proto sysclk */
13853 + ret = snd_soc_dai_set_sysclk(codec_dai, WM8731_SYSCLK_XTAL,
13854 + sysclk, SND_SOC_CLOCK_IN);
13856 + dev_err(rtd->card->dev,
13857 + "Failed to set WM8731 SYSCLK: %d\n", ret);
13864 +/* machine stream operations */
13865 +static struct snd_soc_ops snd_rpi_proto_ops = {
13866 + .startup = snd_rpi_proto_startup,
13867 + .hw_params = snd_rpi_proto_hw_params,
13870 +SND_SOC_DAILINK_DEFS(rpi_proto,
13871 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
13872 + DAILINK_COMP_ARRAY(COMP_CODEC("wm8731.1-001a", "wm8731-hifi")),
13873 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
13875 +static struct snd_soc_dai_link snd_rpi_proto_dai[] = {
13877 + .name = "WM8731",
13878 + .stream_name = "WM8731 HiFi",
13879 + .dai_fmt = SND_SOC_DAIFMT_I2S
13880 + | SND_SOC_DAIFMT_NB_NF
13881 + | SND_SOC_DAIFMT_CBM_CFM,
13882 + .ops = &snd_rpi_proto_ops,
13883 + SND_SOC_DAILINK_REG(rpi_proto),
13887 +/* audio machine driver */
13888 +static struct snd_soc_card snd_rpi_proto = {
13889 + .name = "snd_rpi_proto",
13890 + .owner = THIS_MODULE,
13891 + .dai_link = snd_rpi_proto_dai,
13892 + .num_links = ARRAY_SIZE(snd_rpi_proto_dai),
13895 +static int snd_rpi_proto_probe(struct platform_device *pdev)
13899 + snd_rpi_proto.dev = &pdev->dev;
13901 + if (pdev->dev.of_node) {
13902 + struct device_node *i2s_node;
13903 + struct snd_soc_dai_link *dai = &snd_rpi_proto_dai[0];
13904 + i2s_node = of_parse_phandle(pdev->dev.of_node,
13905 + "i2s-controller", 0);
13908 + dai->cpus->dai_name = NULL;
13909 + dai->cpus->of_node = i2s_node;
13910 + dai->platforms->name = NULL;
13911 + dai->platforms->of_node = i2s_node;
13915 + ret = devm_snd_soc_register_card(&pdev->dev, &snd_rpi_proto);
13916 + if (ret && ret != -EPROBE_DEFER)
13917 + dev_err(&pdev->dev,
13918 + "snd_soc_register_card() failed: %d\n", ret);
13923 +static const struct of_device_id snd_rpi_proto_of_match[] = {
13924 + { .compatible = "rpi,rpi-proto", },
13927 +MODULE_DEVICE_TABLE(of, snd_rpi_proto_of_match);
13929 +static struct platform_driver snd_rpi_proto_driver = {
13931 + .name = "snd-rpi-proto",
13932 + .owner = THIS_MODULE,
13933 + .of_match_table = snd_rpi_proto_of_match,
13935 + .probe = snd_rpi_proto_probe,
13938 +module_platform_driver(snd_rpi_proto_driver);
13940 +MODULE_AUTHOR("Florian Meier");
13941 +MODULE_DESCRIPTION("ASoC Driver for Raspberry Pi connected to PROTO board (WM8731)");
13942 +MODULE_LICENSE("GPL");
13944 +++ b/sound/soc/bcm/rpi-simple-soundcard.c
13946 +// SPDX-License-Identifier: GPL-2.0
13948 + * rpi-simple-soundcard.c -- ALSA SoC Raspberry Pi soundcard.
13950 + * Copyright (C) 2018 Raspberry Pi.
13952 + * Authors: Tim Gover <tim.gover@raspberrypi.org>
13955 + * hifiberry_amp.c, hifiberry_dac.c, rpi-dac.c
13956 + * by Florian Meier <florian.meier@koalo.de>
13958 + * googlevoicehat-soundcard.c
13959 + * by Peter Malkin <petermalkin@google.com>
13962 + * by Andrey Grodzovsky <andrey2805@gmail.com>
13965 + * by Ariel Muszkat <ariel.muszkat@gmail.com>
13966 + * Jorgen Kragh Jakobsen <jorgen.kraghjakobsen@infineon.com>
13968 + * This program is free software; you can redistribute it and/or
13969 + * modify it under the terms of the GNU General Public License
13970 + * version 2 as published by the Free Software Foundation.
13972 + * This program is distributed in the hope that it will be useful, but
13973 + * WITHOUT ANY WARRANTY; without even the implied warranty of
13974 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13975 + * General Public License for more details.
13978 +#include <linux/module.h>
13979 +#include <linux/platform_device.h>
13980 +#include <linux/gpio/consumer.h>
13982 +#include <sound/core.h>
13983 +#include <sound/pcm.h>
13984 +#include <sound/pcm_params.h>
13985 +#include <sound/soc.h>
13987 +/* Parameters for generic RPI functions */
13988 +struct snd_rpi_simple_drvdata {
13989 + struct snd_soc_dai_link *dai;
13990 + const char* card_name;
13991 + unsigned int fixed_bclk_ratio;
13994 +static struct snd_soc_card snd_rpi_simple = {
13995 + .driver_name = "RPi-simple",
13996 + .owner = THIS_MODULE,
13997 + .dai_link = NULL,
13998 + .num_links = 1, /* Only a single DAI supported at the moment */
14001 +static int snd_rpi_simple_init(struct snd_soc_pcm_runtime *rtd)
14003 + struct snd_rpi_simple_drvdata *drvdata =
14004 + snd_soc_card_get_drvdata(rtd->card);
14005 + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
14007 + if (drvdata->fixed_bclk_ratio > 0)
14008 + return snd_soc_dai_set_bclk_ratio(cpu_dai,
14009 + drvdata->fixed_bclk_ratio);
14014 +static int pifi_mini_210_init(struct snd_soc_pcm_runtime *rtd)
14016 + struct snd_soc_component *dac;
14017 + struct gpio_desc *pdn_gpio, *rst_gpio;
14018 + struct snd_soc_dai *codec_dai;
14021 + snd_rpi_simple_init(rtd);
14022 + codec_dai = asoc_rtd_to_codec(rtd, 0);
14024 + dac = codec_dai[0].component;
14026 + pdn_gpio = devm_gpiod_get_optional(snd_rpi_simple.dev, "pdn",
14028 + if (IS_ERR(pdn_gpio)) {
14029 + ret = PTR_ERR(pdn_gpio);
14030 + dev_err(snd_rpi_simple.dev, "failed to get pdn gpio: %d\n", ret);
14034 + rst_gpio = devm_gpiod_get_optional(snd_rpi_simple.dev, "rst",
14036 + if (IS_ERR(rst_gpio)) {
14037 + ret = PTR_ERR(rst_gpio);
14038 + dev_err(snd_rpi_simple.dev, "failed to get rst gpio: %d\n", ret);
14042 + // Set up cards - pulse power down and reset first, then
14043 + // set up according to datasheet
14044 + gpiod_set_value_cansleep(pdn_gpio, 1);
14045 + gpiod_set_value_cansleep(rst_gpio, 1);
14046 + usleep_range(1000, 10000);
14047 + gpiod_set_value_cansleep(pdn_gpio, 0);
14048 + usleep_range(20000, 30000);
14049 + gpiod_set_value_cansleep(rst_gpio, 0);
14050 + usleep_range(20000, 30000);
14052 + // Oscillator trim
14053 + snd_soc_component_write(dac, 0x1b, 0);
14054 + usleep_range(60000, 80000);
14056 + // MCLK at 64fs, sample rate 44.1 or 48kHz
14057 + snd_soc_component_write(dac, 0x00, 0x60);
14059 + // Set up for BTL - AD/BD mode - AD is 0x00107772, BD is 0x00987772
14060 + snd_soc_component_write(dac, 0x20, 0x00107772);
14063 + snd_soc_component_write(dac, 0x05, 0x00);
14068 +static int snd_rpi_simple_hw_params(struct snd_pcm_substream *substream,
14069 + struct snd_pcm_hw_params *params)
14071 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
14072 + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
14073 + struct snd_rpi_simple_drvdata *drvdata;
14074 + unsigned int sample_bits;
14076 + drvdata = snd_soc_card_get_drvdata(rtd->card);
14078 + if (drvdata->fixed_bclk_ratio > 0)
14079 + return 0; // BCLK is configured in .init
14081 + /* The simple drivers just set the bclk_ratio to sample_bits * 2 so
14082 + * hard-code this for now. More complex drivers could just replace
14083 + * the hw_params routine.
14085 + sample_bits = snd_pcm_format_physical_width(params_format(params));
14086 + return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);
14089 +static struct snd_soc_ops snd_rpi_simple_ops = {
14090 + .hw_params = snd_rpi_simple_hw_params,
14093 +static int snd_merus_amp_hw_params(struct snd_pcm_substream *substream,
14094 + struct snd_pcm_hw_params *params)
14096 + struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
14099 + rate = params_rate(params);
14100 + if (rate > 48000) {
14101 + dev_err(rtd->card->dev,
14102 + "Unsupported samplerate %d\n",
14109 +static struct snd_soc_ops snd_merus_amp_ops = {
14110 + .hw_params = snd_merus_amp_hw_params,
14113 +enum adau1977_clk_id {
14117 +enum adau1977_sysclk_src {
14118 + ADAU1977_SYSCLK_SRC_MCLK,
14119 + ADAU1977_SYSCLK_SRC_LRCLK,
14122 +static int adau1977_init(struct snd_soc_pcm_runtime *rtd)
14125 + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
14127 + ret = snd_soc_dai_set_tdm_slot(codec_dai, 0, 0, 0, 0);
14131 + return snd_soc_component_set_sysclk(codec_dai->component,
14132 + ADAU1977_SYSCLK, ADAU1977_SYSCLK_SRC_MCLK,
14133 + 11289600, SND_SOC_CLOCK_IN);
14136 +SND_SOC_DAILINK_DEFS(adau1977,
14137 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
14138 + DAILINK_COMP_ARRAY(COMP_CODEC("adau1977.1-0011", "adau1977-hifi")),
14139 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
14141 +static struct snd_soc_dai_link snd_rpi_adau1977_dai[] = {
14143 + .name = "adau1977",
14144 + .stream_name = "ADAU1977",
14145 + .init = adau1977_init,
14146 + .dai_fmt = SND_SOC_DAIFMT_I2S |
14147 + SND_SOC_DAIFMT_NB_NF |
14148 + SND_SOC_DAIFMT_CBM_CFM,
14149 + SND_SOC_DAILINK_REG(adau1977),
14153 +static struct snd_rpi_simple_drvdata drvdata_adau1977 = {
14154 + .card_name = "snd_rpi_adau1977_adc",
14155 + .dai = snd_rpi_adau1977_dai,
14158 +SND_SOC_DAILINK_DEFS(gvchat,
14159 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
14160 + DAILINK_COMP_ARRAY(COMP_CODEC("voicehat-codec", "voicehat-hifi")),
14161 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
14163 +static struct snd_soc_dai_link snd_googlevoicehat_soundcard_dai[] = {
14165 + .name = "Google voiceHAT SoundCard",
14166 + .stream_name = "Google voiceHAT SoundCard HiFi",
14167 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
14168 + SND_SOC_DAIFMT_CBS_CFS,
14169 + SND_SOC_DAILINK_REG(gvchat),
14173 +static struct snd_rpi_simple_drvdata drvdata_googlevoicehat = {
14174 + .card_name = "snd_rpi_googlevoicehat_soundcard",
14175 + .dai = snd_googlevoicehat_soundcard_dai,
14178 +SND_SOC_DAILINK_DEFS(hifiberry_dacplusdsp,
14179 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
14180 + DAILINK_COMP_ARRAY(COMP_CODEC("dacplusdsp-codec", "dacplusdsp-hifi")),
14181 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
14183 +static struct snd_soc_dai_link snd_hifiberrydacplusdsp_soundcard_dai[] = {
14185 + .name = "Hifiberry DAC+DSP SoundCard",
14186 + .stream_name = "Hifiberry DAC+DSP SoundCard HiFi",
14187 + .dai_fmt = SND_SOC_DAIFMT_I2S |
14188 + SND_SOC_DAIFMT_NB_NF |
14189 + SND_SOC_DAIFMT_CBS_CFS,
14190 + SND_SOC_DAILINK_REG(hifiberry_dacplusdsp),
14194 +static struct snd_rpi_simple_drvdata drvdata_hifiberrydacplusdsp = {
14195 + .card_name = "snd_rpi_hifiberrydacplusdsp_soundcard",
14196 + .dai = snd_hifiberrydacplusdsp_soundcard_dai,
14199 +SND_SOC_DAILINK_DEFS(hifiberry_amp,
14200 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
14201 + DAILINK_COMP_ARRAY(COMP_CODEC("tas5713.1-001b", "tas5713-hifi")),
14202 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
14204 +static struct snd_soc_dai_link snd_hifiberry_amp_dai[] = {
14206 + .name = "HifiBerry AMP",
14207 + .stream_name = "HifiBerry AMP HiFi",
14208 + .dai_fmt = SND_SOC_DAIFMT_I2S |
14209 + SND_SOC_DAIFMT_NB_NF |
14210 + SND_SOC_DAIFMT_CBS_CFS,
14211 + SND_SOC_DAILINK_REG(hifiberry_amp),
14215 +static struct snd_rpi_simple_drvdata drvdata_hifiberry_amp = {
14216 + .card_name = "snd_rpi_hifiberry_amp",
14217 + .dai = snd_hifiberry_amp_dai,
14218 + .fixed_bclk_ratio = 64,
14221 +SND_SOC_DAILINK_DEFS(hifiberry_amp3,
14222 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
14223 + DAILINK_COMP_ARRAY(COMP_CODEC("ma120x0p.1-0020", "ma120x0p-amp")),
14224 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
14226 +static struct snd_soc_dai_link snd_hifiberry_amp3_dai[] = {
14228 + .name = "HifiberryAmp3",
14229 + .stream_name = "Hifiberry Amp3",
14230 + .dai_fmt = SND_SOC_DAIFMT_I2S |
14231 + SND_SOC_DAIFMT_NB_NF |
14232 + SND_SOC_DAIFMT_CBS_CFS,
14233 + SND_SOC_DAILINK_REG(hifiberry_amp3),
14237 +static struct snd_rpi_simple_drvdata drvdata_hifiberry_amp3 = {
14238 + .card_name = "snd_rpi_hifiberry_amp3",
14239 + .dai = snd_hifiberry_amp3_dai,
14240 + .fixed_bclk_ratio = 64,
14243 +SND_SOC_DAILINK_DEFS(hifiberry_dac,
14244 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
14245 + DAILINK_COMP_ARRAY(COMP_CODEC("pcm5102a-codec", "pcm5102a-hifi")),
14246 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
14248 +static struct snd_soc_dai_link snd_hifiberry_dac_dai[] = {
14250 + .name = "HifiBerry DAC",
14251 + .stream_name = "HifiBerry DAC HiFi",
14252 + .dai_fmt = SND_SOC_DAIFMT_I2S |
14253 + SND_SOC_DAIFMT_NB_NF |
14254 + SND_SOC_DAIFMT_CBS_CFS,
14255 + SND_SOC_DAILINK_REG(hifiberry_dac),
14259 +static struct snd_rpi_simple_drvdata drvdata_hifiberry_dac = {
14260 + .card_name = "snd_rpi_hifiberry_dac",
14261 + .dai = snd_hifiberry_dac_dai,
14264 +SND_SOC_DAILINK_DEFS(dionaudio_kiwi,
14265 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
14266 + DAILINK_COMP_ARRAY(COMP_CODEC("pcm1794a-codec", "pcm1794a-hifi")),
14267 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
14269 +static struct snd_soc_dai_link snd_dionaudio_kiwi_dai[] = {
14271 + .name = "DionAudio KIWI",
14272 + .stream_name = "DionAudio KIWI STREAMER",
14273 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
14274 + SND_SOC_DAIFMT_CBS_CFS,
14275 + SND_SOC_DAILINK_REG(dionaudio_kiwi),
14279 +static struct snd_rpi_simple_drvdata drvdata_dionaudio_kiwi = {
14280 + .card_name = "snd_rpi_dionaudio_kiwi",
14281 + .dai = snd_dionaudio_kiwi_dai,
14282 + .fixed_bclk_ratio = 64,
14285 +SND_SOC_DAILINK_DEFS(rpi_dac,
14286 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
14287 + DAILINK_COMP_ARRAY(COMP_CODEC("pcm1794a-codec", "pcm1794a-hifi")),
14288 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
14290 +static struct snd_soc_dai_link snd_rpi_dac_dai[] = {
14292 + .name = "RPi-DAC",
14293 + .stream_name = "RPi-DAC HiFi",
14294 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
14295 + SND_SOC_DAIFMT_CBS_CFS,
14296 + SND_SOC_DAILINK_REG(rpi_dac),
14300 +static struct snd_rpi_simple_drvdata drvdata_rpi_dac = {
14301 + .card_name = "snd_rpi_rpi_dac",
14302 + .dai = snd_rpi_dac_dai,
14303 + .fixed_bclk_ratio = 64,
14306 +SND_SOC_DAILINK_DEFS(merus_amp,
14307 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
14308 + DAILINK_COMP_ARRAY(COMP_CODEC("ma120x0p.1-0020", "ma120x0p-amp")),
14309 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
14311 +static struct snd_soc_dai_link snd_merus_amp_dai[] = {
14313 + .name = "MerusAmp",
14314 + .stream_name = "Merus Audio Amp",
14315 + .ops = &snd_merus_amp_ops,
14316 + .dai_fmt = SND_SOC_DAIFMT_I2S |
14317 + SND_SOC_DAIFMT_NB_NF |
14318 + SND_SOC_DAIFMT_CBS_CFS,
14319 + SND_SOC_DAILINK_REG(merus_amp),
14323 +static struct snd_rpi_simple_drvdata drvdata_merus_amp = {
14324 + .card_name = "snd_rpi_merus_amp",
14325 + .dai = snd_merus_amp_dai,
14326 + .fixed_bclk_ratio = 64,
14329 +SND_SOC_DAILINK_DEFS(pifi_mini_210,
14330 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
14331 + DAILINK_COMP_ARRAY(COMP_CODEC("tas571x.1-001a", "tas571x-hifi")),
14332 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
14334 +static struct snd_soc_dai_link snd_pifi_mini_210_dai[] = {
14336 + .name = "PiFi Mini 210",
14337 + .stream_name = "PiFi Mini 210 HiFi",
14338 + .init = pifi_mini_210_init,
14339 + .dai_fmt = SND_SOC_DAIFMT_I2S |
14340 + SND_SOC_DAIFMT_NB_NF |
14341 + SND_SOC_DAIFMT_CBS_CFS,
14342 + SND_SOC_DAILINK_REG(pifi_mini_210),
14346 +static struct snd_rpi_simple_drvdata drvdata_pifi_mini_210 = {
14347 + .card_name = "snd_pifi_mini_210",
14348 + .dai = snd_pifi_mini_210_dai,
14349 + .fixed_bclk_ratio = 64,
14352 +static const struct of_device_id snd_rpi_simple_of_match[] = {
14353 + { .compatible = "adi,adau1977-adc",
14354 + .data = (void *) &drvdata_adau1977 },
14355 + { .compatible = "googlevoicehat,googlevoicehat-soundcard",
14356 + .data = (void *) &drvdata_googlevoicehat },
14357 + { .compatible = "hifiberrydacplusdsp,hifiberrydacplusdsp-soundcard",
14358 + .data = (void *) &drvdata_hifiberrydacplusdsp },
14359 + { .compatible = "hifiberry,hifiberry-amp",
14360 + .data = (void *) &drvdata_hifiberry_amp },
14361 + { .compatible = "hifiberry,hifiberry-amp3",
14362 + .data = (void *) &drvdata_hifiberry_amp3 },
14363 + { .compatible = "hifiberry,hifiberry-dac",
14364 + .data = (void *) &drvdata_hifiberry_dac },
14365 + { .compatible = "dionaudio,dionaudio-kiwi",
14366 + .data = (void *) &drvdata_dionaudio_kiwi },
14367 + { .compatible = "rpi,rpi-dac", &drvdata_rpi_dac},
14368 + { .compatible = "merus,merus-amp",
14369 + .data = (void *) &drvdata_merus_amp },
14370 + { .compatible = "pifi,pifi-mini-210",
14371 + .data = (void *) &drvdata_pifi_mini_210 },
14375 +static int snd_rpi_simple_probe(struct platform_device *pdev)
14378 + const struct of_device_id *of_id;
14380 + snd_rpi_simple.dev = &pdev->dev;
14381 + of_id = of_match_node(snd_rpi_simple_of_match, pdev->dev.of_node);
14383 + if (pdev->dev.of_node && of_id->data) {
14384 + struct device_node *i2s_node;
14385 + struct snd_rpi_simple_drvdata *drvdata =
14386 + (struct snd_rpi_simple_drvdata *) of_id->data;
14387 + struct snd_soc_dai_link *dai = drvdata->dai;
14389 + snd_soc_card_set_drvdata(&snd_rpi_simple, drvdata);
14391 + /* More complex drivers might override individual functions */
14393 + dai->init = snd_rpi_simple_init;
14395 + dai->ops = &snd_rpi_simple_ops;
14397 + snd_rpi_simple.name = drvdata->card_name;
14399 + snd_rpi_simple.dai_link = dai;
14400 + i2s_node = of_parse_phandle(pdev->dev.of_node,
14401 + "i2s-controller", 0);
14403 + pr_err("Failed to find i2s-controller DT node\n");
14407 + dai->cpus->of_node = i2s_node;
14408 + dai->platforms->of_node = i2s_node;
14411 + ret = devm_snd_soc_register_card(&pdev->dev, &snd_rpi_simple);
14412 + if (ret && ret != -EPROBE_DEFER)
14413 + dev_err(&pdev->dev, "Failed to register card %d\n", ret);
14418 +static struct platform_driver snd_rpi_simple_driver = {
14420 + .name = "snd-rpi-simple",
14421 + .owner = THIS_MODULE,
14422 + .of_match_table = snd_rpi_simple_of_match,
14424 + .probe = snd_rpi_simple_probe,
14426 +MODULE_DEVICE_TABLE(of, snd_rpi_simple_of_match);
14428 +module_platform_driver(snd_rpi_simple_driver);
14430 +MODULE_AUTHOR("Tim Gover <tim.gover@raspberrypi.org>");
14431 +MODULE_DESCRIPTION("ASoC Raspberry Pi simple soundcard driver ");
14432 +MODULE_LICENSE("GPL v2");
14434 +++ b/sound/soc/bcm/rpi-wm8804-soundcard.c
14436 +// SPDX-License-Identifier: GPL-2.0
14438 + * rpi--wm8804.c -- ALSA SoC Raspberry Pi soundcard.
14440 + * Copyright (C) 2018 Raspberry Pi.
14442 + * Authors: Tim Gover <tim.gover@raspberrypi.org>
14444 + * Generic driver for Pi Hat WM8804 digi sounds cards
14446 + * Based upon code from:
14447 + * justboom-digi.c
14448 + * by Milan Neskovic <info@justboom.co>
14451 + * by Daniel Matuschek <info@crazy-audio.com>
14454 + * by Baswaraj <jaikumar@cem-solutions.net>
14456 + * hifiberry-digi.c
14457 + * Daniel Matuschek <info@crazy-audio.com>
14459 + * This program is free software; you can redistribute it and/or
14460 + * modify it under the terms of the GNU General Public License
14461 + * version 2 as published by the Free Software Foundation.
14463 + * This program is distributed in the hope that it will be useful, but
14464 + * WITHOUT ANY WARRANTY; without even the implied warranty of
14465 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14466 + * General Public License for more details.
14469 +#include <linux/gpio/consumer.h>
14470 +#include <linux/platform_device.h>
14471 +#include <linux/module.h>
14473 +#include <sound/core.h>
14474 +#include <sound/pcm.h>
14475 +#include <sound/pcm_params.h>
14476 +#include <sound/soc.h>
14478 +#include "../codecs/wm8804.h"
14480 +struct wm8804_clk_cfg {
14481 + unsigned int sysclk_freq;
14482 + unsigned int mclk_freq;
14483 + unsigned int mclk_div;
14486 +/* Parameters for generic functions */
14487 +struct snd_rpi_wm8804_drvdata {
14488 + /* Required - pointer to the DAI structure */
14489 + struct snd_soc_dai_link *dai;
14490 + /* Required - snd_soc_card name */
14491 + const char *card_name;
14492 + /* Optional DT node names if card info is defined in DT */
14493 + const char *card_name_dt;
14494 + const char *dai_name_dt;
14495 + const char *dai_stream_name_dt;
14496 + /* Optional probe extension - called prior to register_card */
14497 + int (*probe)(struct platform_device *pdev);
14500 +static struct gpio_desc *snd_clk44gpio;
14501 +static struct gpio_desc *snd_clk48gpio;
14502 +static int wm8804_samplerate = 0;
14504 +/* Forward declarations */
14505 +static struct snd_soc_dai_link snd_allo_digione_dai[];
14506 +static struct snd_soc_card snd_rpi_wm8804;
14509 +#define CLK_44EN_RATE 22579200UL
14510 +#define CLK_48EN_RATE 24576000UL
14512 +static unsigned int snd_rpi_wm8804_enable_clock(unsigned int samplerate)
14514 + switch (samplerate) {
14520 + gpiod_set_value_cansleep(snd_clk44gpio, 1);
14521 + gpiod_set_value_cansleep(snd_clk48gpio, 0);
14522 + return CLK_44EN_RATE;
14524 + gpiod_set_value_cansleep(snd_clk48gpio, 1);
14525 + gpiod_set_value_cansleep(snd_clk44gpio, 0);
14526 + return CLK_48EN_RATE;
14530 +static void snd_rpi_wm8804_clk_cfg(unsigned int samplerate,
14531 + struct wm8804_clk_cfg *clk_cfg)
14533 + clk_cfg->sysclk_freq = 27000000;
14535 + if (samplerate <= 96000 ||
14536 + snd_rpi_wm8804.dai_link == snd_allo_digione_dai) {
14537 + clk_cfg->mclk_freq = samplerate * 256;
14538 + clk_cfg->mclk_div = WM8804_MCLKDIV_256FS;
14540 + clk_cfg->mclk_freq = samplerate * 128;
14541 + clk_cfg->mclk_div = WM8804_MCLKDIV_128FS;
14544 + if (!(IS_ERR(snd_clk44gpio) || IS_ERR(snd_clk48gpio)))
14545 + clk_cfg->sysclk_freq = snd_rpi_wm8804_enable_clock(samplerate);
14548 +static int snd_rpi_wm8804_hw_params(struct snd_pcm_substream *substream,
14549 + struct snd_pcm_hw_params *params)
14551 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
14552 + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
14553 + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
14554 + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
14555 + int sampling_freq = 1;
14557 + struct wm8804_clk_cfg clk_cfg;
14558 + int samplerate = params_rate(params);
14560 + if (samplerate == wm8804_samplerate)
14563 + /* clear until all clocks are setup properly */
14564 + wm8804_samplerate = 0;
14566 + snd_rpi_wm8804_clk_cfg(samplerate, &clk_cfg);
14568 + pr_debug("%s samplerate: %d mclk_freq: %u mclk_div: %u sysclk: %u\n",
14569 + __func__, samplerate, clk_cfg.mclk_freq,
14570 + clk_cfg.mclk_div, clk_cfg.sysclk_freq);
14572 + switch (samplerate) {
14574 + sampling_freq = 0x03;
14577 + sampling_freq = 0x00;
14580 + sampling_freq = 0x02;
14583 + sampling_freq = 0x08;
14586 + sampling_freq = 0x0a;
14589 + sampling_freq = 0x0c;
14592 + sampling_freq = 0x0e;
14595 + dev_err(rtd->card->dev,
14596 + "Failed to set WM8804 SYSCLK, unsupported samplerate %d\n",
14600 + snd_soc_dai_set_clkdiv(codec_dai, WM8804_MCLK_DIV, clk_cfg.mclk_div);
14601 + snd_soc_dai_set_pll(codec_dai, 0, 0,
14602 + clk_cfg.sysclk_freq, clk_cfg.mclk_freq);
14604 + ret = snd_soc_dai_set_sysclk(codec_dai, WM8804_TX_CLKSRC_PLL,
14605 + clk_cfg.sysclk_freq, SND_SOC_CLOCK_OUT);
14607 + dev_err(rtd->card->dev,
14608 + "Failed to set WM8804 SYSCLK: %d\n", ret);
14612 + wm8804_samplerate = samplerate;
14614 + /* set sampling frequency status bits */
14615 + snd_soc_component_update_bits(component, WM8804_SPDTX4, 0x0f,
14618 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 64);
14621 +static struct snd_soc_ops snd_rpi_wm8804_ops = {
14622 + .hw_params = snd_rpi_wm8804_hw_params,
14625 +SND_SOC_DAILINK_DEFS(justboom_digi,
14626 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
14627 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
14628 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
14630 +static struct snd_soc_dai_link snd_justboom_digi_dai[] = {
14632 + .name = "JustBoom Digi",
14633 + .stream_name = "JustBoom Digi HiFi",
14634 + SND_SOC_DAILINK_REG(justboom_digi),
14638 +static struct snd_rpi_wm8804_drvdata drvdata_justboom_digi = {
14639 + .card_name = "snd_rpi_justboom_digi",
14640 + .dai = snd_justboom_digi_dai,
14643 +SND_SOC_DAILINK_DEFS(iqaudio_digi,
14644 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
14645 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
14646 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
14648 +static struct snd_soc_dai_link snd_iqaudio_digi_dai[] = {
14650 + .name = "IQAudIO Digi",
14651 + .stream_name = "IQAudIO Digi HiFi",
14652 + SND_SOC_DAILINK_REG(iqaudio_digi),
14656 +static struct snd_rpi_wm8804_drvdata drvdata_iqaudio_digi = {
14657 + .card_name = "IQAudIODigi",
14658 + .dai = snd_iqaudio_digi_dai,
14659 + .card_name_dt = "wm8804-digi,card-name",
14660 + .dai_name_dt = "wm8804-digi,dai-name",
14661 + .dai_stream_name_dt = "wm8804-digi,dai-stream-name",
14664 +static int snd_allo_digione_probe(struct platform_device *pdev)
14666 + pr_debug("%s\n", __func__);
14668 + if (IS_ERR(snd_clk44gpio) || IS_ERR(snd_clk48gpio)) {
14669 + dev_err(&pdev->dev, "devm_gpiod_get() failed\n");
14675 +SND_SOC_DAILINK_DEFS(allo_digione,
14676 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
14677 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
14678 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
14680 +static struct snd_soc_dai_link snd_allo_digione_dai[] = {
14682 + .name = "Allo DigiOne",
14683 + .stream_name = "Allo DigiOne HiFi",
14684 + SND_SOC_DAILINK_REG(allo_digione),
14688 +static struct snd_rpi_wm8804_drvdata drvdata_allo_digione = {
14689 + .card_name = "snd_allo_digione",
14690 + .dai = snd_allo_digione_dai,
14691 + .probe = snd_allo_digione_probe,
14694 +SND_SOC_DAILINK_DEFS(hifiberry_digi,
14695 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
14696 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
14697 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
14699 +static struct snd_soc_dai_link snd_hifiberry_digi_dai[] = {
14701 + .name = "HifiBerry Digi",
14702 + .stream_name = "HifiBerry Digi HiFi",
14703 + SND_SOC_DAILINK_REG(hifiberry_digi),
14707 +static int snd_hifiberry_digi_probe(struct platform_device *pdev)
14709 + pr_debug("%s\n", __func__);
14711 + if (IS_ERR(snd_clk44gpio) || IS_ERR(snd_clk48gpio))
14714 + snd_hifiberry_digi_dai->name = "HiFiBerry Digi+ Pro";
14715 + snd_hifiberry_digi_dai->stream_name = "HiFiBerry Digi+ Pro HiFi";
14719 +static struct snd_rpi_wm8804_drvdata drvdata_hifiberry_digi = {
14720 + .card_name = "snd_rpi_hifiberry_digi",
14721 + .dai = snd_hifiberry_digi_dai,
14722 + .probe = snd_hifiberry_digi_probe,
14725 +static const struct of_device_id snd_rpi_wm8804_of_match[] = {
14726 + { .compatible = "justboom,justboom-digi",
14727 + .data = (void *) &drvdata_justboom_digi },
14728 + { .compatible = "iqaudio,wm8804-digi",
14729 + .data = (void *) &drvdata_iqaudio_digi },
14730 + { .compatible = "allo,allo-digione",
14731 + .data = (void *) &drvdata_allo_digione },
14732 + { .compatible = "hifiberry,hifiberry-digi",
14733 + .data = (void *) &drvdata_hifiberry_digi },
14737 +static struct snd_soc_card snd_rpi_wm8804 = {
14738 + .driver_name = "RPi-WM8804",
14739 + .owner = THIS_MODULE,
14740 + .dai_link = NULL,
14744 +static int snd_rpi_wm8804_probe(struct platform_device *pdev)
14747 + const struct of_device_id *of_id;
14749 + snd_rpi_wm8804.dev = &pdev->dev;
14750 + of_id = of_match_node(snd_rpi_wm8804_of_match, pdev->dev.of_node);
14752 + if (pdev->dev.of_node && of_id->data) {
14753 + struct device_node *i2s_node;
14754 + struct snd_rpi_wm8804_drvdata *drvdata =
14755 + (struct snd_rpi_wm8804_drvdata *) of_id->data;
14756 + struct snd_soc_dai_link *dai = drvdata->dai;
14758 + snd_soc_card_set_drvdata(&snd_rpi_wm8804, drvdata);
14761 + dai->ops = &snd_rpi_wm8804_ops;
14762 + if (!dai->codecs->dai_name)
14763 + dai->codecs->dai_name = "wm8804-spdif";
14764 + if (!dai->codecs->name)
14765 + dai->codecs->name = "wm8804.1-003b";
14766 + if (!dai->dai_fmt)
14767 + dai->dai_fmt = SND_SOC_DAIFMT_I2S |
14768 + SND_SOC_DAIFMT_NB_NF |
14769 + SND_SOC_DAIFMT_CBM_CFM;
14771 + snd_rpi_wm8804.dai_link = dai;
14772 + i2s_node = of_parse_phandle(pdev->dev.of_node,
14773 + "i2s-controller", 0);
14775 + pr_err("Failed to find i2s-controller DT node\n");
14779 + snd_rpi_wm8804.name = drvdata->card_name;
14781 + /* If requested by in drvdata get card & DAI names from DT */
14782 + if (drvdata->card_name_dt)
14783 + of_property_read_string(i2s_node,
14784 + drvdata->card_name_dt,
14785 + &snd_rpi_wm8804.name);
14787 + if (drvdata->dai_name_dt)
14788 + of_property_read_string(i2s_node,
14789 + drvdata->dai_name_dt,
14792 + if (drvdata->dai_stream_name_dt)
14793 + of_property_read_string(i2s_node,
14794 + drvdata->dai_stream_name_dt,
14795 + &dai->stream_name);
14797 + dai->cpus->of_node = i2s_node;
14798 + dai->platforms->of_node = i2s_node;
14801 + * clk44gpio and clk48gpio are not required by all cards so
14802 + * don't check the error status.
14805 + devm_gpiod_get(&pdev->dev, "clock44", GPIOD_OUT_LOW);
14808 + devm_gpiod_get(&pdev->dev, "clock48", GPIOD_OUT_LOW);
14810 + if (drvdata->probe) {
14811 + ret = drvdata->probe(pdev);
14813 + dev_err(&pdev->dev, "Custom probe failed %d\n",
14819 + pr_debug("%s card: %s dai: %s stream: %s\n", __func__,
14820 + snd_rpi_wm8804.name,
14821 + dai->name, dai->stream_name);
14824 + ret = devm_snd_soc_register_card(&pdev->dev, &snd_rpi_wm8804);
14825 + if (ret && ret != -EPROBE_DEFER)
14826 + dev_err(&pdev->dev, "Failed to register card %d\n", ret);
14831 +static struct platform_driver snd_rpi_wm8804_driver = {
14833 + .name = "snd-rpi-wm8804",
14834 + .owner = THIS_MODULE,
14835 + .of_match_table = snd_rpi_wm8804_of_match,
14837 + .probe = snd_rpi_wm8804_probe,
14839 +MODULE_DEVICE_TABLE(of, snd_rpi_wm8804_of_match);
14841 +module_platform_driver(snd_rpi_wm8804_driver);
14843 +MODULE_AUTHOR("Tim Gover <tim.gover@raspberrypi.org>");
14844 +MODULE_DESCRIPTION("ASoC Raspberry Pi Hat generic digi driver for WM8804 based cards");
14845 +MODULE_LICENSE("GPL v2");
14846 --- a/sound/soc/codecs/Kconfig
14847 +++ b/sound/soc/codecs/Kconfig
14848 @@ -119,6 +119,7 @@ config SND_SOC_ALL_CODECS
14849 imply SND_SOC_IDT821034
14850 imply SND_SOC_INNO_RK3036
14851 imply SND_SOC_ISABELLE
14852 + imply SND_SOC_I_SABRE_CODEC
14853 imply SND_SOC_JZ4740_CODEC
14854 imply SND_SOC_JZ4725B_CODEC
14855 imply SND_SOC_JZ4760_CODEC
14856 @@ -126,6 +127,7 @@ config SND_SOC_ALL_CODECS
14857 imply SND_SOC_LM4857
14858 imply SND_SOC_LM49453
14859 imply SND_SOC_LOCHNAGAR_SC
14860 + imply SND_SOC_MA120X0P
14861 imply SND_SOC_MAX98088
14862 imply SND_SOC_MAX98090
14863 imply SND_SOC_MAX98095
14864 @@ -168,6 +170,7 @@ config SND_SOC_ALL_CODECS
14865 imply SND_SOC_PCM179X_SPI
14866 imply SND_SOC_PCM186X_I2C
14867 imply SND_SOC_PCM186X_SPI
14868 + imply SND_SOC_PCM1794A
14869 imply SND_SOC_PCM3008
14870 imply SND_SOC_PCM3060_I2C
14871 imply SND_SOC_PCM3060_SPI
14872 @@ -255,6 +258,7 @@ config SND_SOC_ALL_CODECS
14873 imply SND_SOC_TLV320ADCX140
14874 imply SND_SOC_TLV320AIC23_I2C
14875 imply SND_SOC_TLV320AIC23_SPI
14876 + imply SND_SOC_TAS5713
14877 imply SND_SOC_TLV320AIC26
14878 imply SND_SOC_TLV320AIC31XX
14879 imply SND_SOC_TLV320AIC32X4_I2C
14880 @@ -410,12 +414,12 @@ config SND_SOC_AD193X
14883 config SND_SOC_AD193X_SPI
14885 + tristate "Analog Devices AU193X CODEC - SPI"
14886 depends on SPI_MASTER
14887 select SND_SOC_AD193X
14889 config SND_SOC_AD193X_I2C
14891 + tristate "Analog Devices AU193X CODEC - I2C"
14893 select SND_SOC_AD193X
14895 @@ -1126,6 +1130,13 @@ config SND_SOC_LOCHNAGAR_SC
14896 This driver support the sound card functionality of the Cirrus
14897 Logic Lochnagar audio development board.
14899 +config SND_SOC_MA120X0P
14900 + tristate "Infineon Merus(TM) MA120X0P Multilevel Class-D Audio amplifiers"
14903 + Enable support for Infineon MA120X0P Multilevel Class-D audio power
14906 config SND_SOC_MADERA
14908 default y if SND_SOC_CS47L15=y
14909 @@ -1503,6 +1514,10 @@ config SND_SOC_RT5616
14910 tristate "Realtek RT5616 CODEC"
14913 +config SND_SOC_PCM1794A
14917 config SND_SOC_RT5631
14918 tristate "Realtek ALC5631/RT5631 CODEC"
14920 @@ -1846,6 +1861,9 @@ config SND_SOC_TFA9879
14921 tristate "NXP Semiconductors TFA9879 amplifier"
14924 +config SND_SOC_TAS5713
14927 config SND_SOC_TFA989X
14928 tristate "NXP/Goodix TFA989X (TFA1) amplifiers"
14930 @@ -2404,4 +2422,8 @@ config SND_SOC_LPASS_TX_MACRO
14931 select SND_SOC_LPASS_MACRO_COMMON
14932 tristate "Qualcomm TX Macro in LPASS(Low Power Audio SubSystem)"
14934 +config SND_SOC_I_SABRE_CODEC
14935 + tristate "Audiophonics I-SABRE Codec"
14939 --- a/sound/soc/codecs/Makefile
14940 +++ b/sound/soc/codecs/Makefile
14941 @@ -127,6 +127,7 @@ snd-soc-ics43432-objs := ics43432.o
14942 snd-soc-idt821034-objs := idt821034.o
14943 snd-soc-inno-rk3036-objs := inno_rk3036.o
14944 snd-soc-isabelle-objs := isabelle.o
14945 +snd-soc-i-sabre-codec-objs := i-sabre-codec.o
14946 snd-soc-jz4740-codec-objs := jz4740.o
14947 snd-soc-jz4725b-codec-objs := jz4725b.o
14948 snd-soc-jz4760-codec-objs := jz4760.o
14949 @@ -139,6 +140,7 @@ snd-soc-lpass-rx-macro-objs := lpass-rx-
14950 snd-soc-lpass-tx-macro-objs := lpass-tx-macro.o
14951 snd-soc-lpass-wsa-macro-objs := lpass-wsa-macro.o
14952 snd-soc-lpass-va-macro-objs := lpass-va-macro.o
14953 +snd-soc-ma120x0p-objs := ma120x0p.o
14954 snd-soc-madera-objs := madera.o
14955 snd-soc-max9759-objs := max9759.o
14956 snd-soc-max9768-objs := max9768.o
14957 @@ -187,6 +189,7 @@ snd-soc-pcm179x-spi-objs := pcm179x-spi.
14958 snd-soc-pcm186x-objs := pcm186x.o
14959 snd-soc-pcm186x-i2c-objs := pcm186x-i2c.o
14960 snd-soc-pcm186x-spi-objs := pcm186x-spi.o
14961 +snd-soc-pcm1794a-objs := pcm1794a.o
14962 snd-soc-pcm3008-objs := pcm3008.o
14963 snd-soc-pcm3060-objs := pcm3060.o
14964 snd-soc-pcm3060-i2c-objs := pcm3060-i2c.o
14965 @@ -271,6 +274,7 @@ snd-soc-sta529-objs := sta529.o
14966 snd-soc-stac9766-objs := stac9766.o
14967 snd-soc-sti-sas-objs := sti-sas.o
14968 snd-soc-tas5086-objs := tas5086.o
14969 +snd-soc-tas5713-objs := tas5713.o
14970 snd-soc-tas571x-objs := tas571x.o
14971 snd-soc-tas5720-objs := tas5720.o
14972 snd-soc-tas5805m-objs := tas5805m.o
14973 @@ -513,6 +517,7 @@ obj-$(CONFIG_SND_SOC_ICS43432) += snd-so
14974 obj-$(CONFIG_SND_SOC_IDT821034) += snd-soc-idt821034.o
14975 obj-$(CONFIG_SND_SOC_INNO_RK3036) += snd-soc-inno-rk3036.o
14976 obj-$(CONFIG_SND_SOC_ISABELLE) += snd-soc-isabelle.o
14977 +obj-$(CONFIG_SND_SOC_I_SABRE_CODEC) += snd-soc-i-sabre-codec.o
14978 obj-$(CONFIG_SND_SOC_JZ4740_CODEC) += snd-soc-jz4740-codec.o
14979 obj-$(CONFIG_SND_SOC_JZ4725B_CODEC) += snd-soc-jz4725b-codec.o
14980 obj-$(CONFIG_SND_SOC_JZ4760_CODEC) += snd-soc-jz4760-codec.o
14981 @@ -520,6 +525,7 @@ obj-$(CONFIG_SND_SOC_JZ4770_CODEC) += sn
14982 obj-$(CONFIG_SND_SOC_LM4857) += snd-soc-lm4857.o
14983 obj-$(CONFIG_SND_SOC_LM49453) += snd-soc-lm49453.o
14984 obj-$(CONFIG_SND_SOC_LOCHNAGAR_SC) += snd-soc-lochnagar-sc.o
14985 +obj-$(CONFIG_SND_SOC_MA120X0P) += snd-soc-ma120x0p.o
14986 obj-$(CONFIG_SND_SOC_MADERA) += snd-soc-madera.o
14987 obj-$(CONFIG_SND_SOC_MAX9759) += snd-soc-max9759.o
14988 obj-$(CONFIG_SND_SOC_MAX9768) += snd-soc-max9768.o
14989 @@ -563,6 +569,7 @@ obj-$(CONFIG_SND_SOC_PCM1681) += snd-soc
14990 obj-$(CONFIG_SND_SOC_PCM179X) += snd-soc-pcm179x-codec.o
14991 obj-$(CONFIG_SND_SOC_PCM1789_I2C) += snd-soc-pcm1789-i2c.o
14992 obj-$(CONFIG_SND_SOC_PCM1789) += snd-soc-pcm1789-codec.o
14993 +obj-$(CONFIG_SND_SOC_PCM1794A) += snd-soc-pcm1794a.o
14994 obj-$(CONFIG_SND_SOC_PCM179X_I2C) += snd-soc-pcm179x-i2c.o
14995 obj-$(CONFIG_SND_SOC_PCM179X_SPI) += snd-soc-pcm179x-spi.o
14996 obj-$(CONFIG_SND_SOC_PCM186X) += snd-soc-pcm186x.o
14997 @@ -663,6 +670,7 @@ obj-$(CONFIG_SND_SOC_TAS5805M) += snd-so
14998 obj-$(CONFIG_SND_SOC_TAS6424) += snd-soc-tas6424.o
14999 obj-$(CONFIG_SND_SOC_TDA7419) += snd-soc-tda7419.o
15000 obj-$(CONFIG_SND_SOC_TAS2770) += snd-soc-tas2770.o
15001 +obj-$(CONFIG_SND_SOC_TAS5713) += snd-soc-tas5713.o
15002 obj-$(CONFIG_SND_SOC_TFA9879) += snd-soc-tfa9879.o
15003 obj-$(CONFIG_SND_SOC_TFA989X) += snd-soc-tfa989x.o
15004 obj-$(CONFIG_SND_SOC_TLV320ADC3XXX) += snd-soc-tlv320adc3xxx.o
15005 --- a/sound/soc/codecs/adau1977-i2c.c
15006 +++ b/sound/soc/codecs/adau1977-i2c.c
15007 @@ -38,9 +38,19 @@ static const struct i2c_device_id adau19
15009 MODULE_DEVICE_TABLE(i2c, adau1977_i2c_ids);
15011 +static const struct of_device_id adau1977_of_ids[] = {
15012 + { .compatible = "adi,adau1977", },
15013 + { .compatible = "adi,adau1978", },
15014 + { .compatible = "adi,adau1979", },
15017 +MODULE_DEVICE_TABLE(of, adau1977_of_ids);
15020 static struct i2c_driver adau1977_i2c_driver = {
15022 .name = "adau1977",
15023 + .of_match_table = adau1977_of_ids,
15025 .probe = adau1977_i2c_probe,
15026 .id_table = adau1977_i2c_ids,
15027 --- a/sound/soc/codecs/cs42xx8-i2c.c
15028 +++ b/sound/soc/codecs/cs42xx8-i2c.c
15029 @@ -64,11 +64,18 @@ static const struct i2c_device_id cs42xx
15031 MODULE_DEVICE_TABLE(i2c, cs42xx8_i2c_id);
15033 +const struct of_device_id cs42xx8_i2c_of_match[] = {
15034 + { .compatible = "cirrus,cs42448", .data = &cs42448_data, },
15035 + { .compatible = "cirrus,cs42888", .data = &cs42888_data, },
15036 + { /* sentinel */ }
15038 +MODULE_DEVICE_TABLE(of, cs42xx8_i2c_of_match);
15040 static struct i2c_driver cs42xx8_i2c_driver = {
15044 - .of_match_table = cs42xx8_of_match,
15045 + .of_match_table = cs42xx8_i2c_of_match,
15047 .probe = cs42xx8_i2c_probe,
15048 .remove = cs42xx8_i2c_remove,
15049 --- a/sound/soc/codecs/cs42xx8.c
15050 +++ b/sound/soc/codecs/cs42xx8.c
15051 @@ -510,6 +510,16 @@ const struct cs42xx8_driver_data cs42888
15053 EXPORT_SYMBOL_GPL(cs42888_data);
15055 +const struct of_device_id cs42xx8_of_match[] = {
15056 + { .compatible = "cirrus,cs42448", .data = &cs42448_data, },
15057 + { .compatible = "cirrus,cs42888", .data = &cs42888_data, },
15058 + { /* sentinel */ }
15060 +#if !IS_ENABLED(CONFIG_SND_SOC_CS42XX8_I2C)
15061 +MODULE_DEVICE_TABLE(of, cs42xx8_of_match);
15062 +EXPORT_SYMBOL_GPL(cs42xx8_of_match);
15065 int cs42xx8_probe(struct device *dev, struct regmap *regmap, struct cs42xx8_driver_data *drvdata)
15067 struct cs42xx8_priv *cs42xx8;
15069 +++ b/sound/soc/codecs/i-sabre-codec.c
15072 + * Driver for I-Sabre Q2M
15074 + * Author: Satoru Kawase
15075 + * Modified by: Xiao Qingyong
15076 + * Modified by: JC BARBAUD (Mute)
15077 + * Update kernel v4.18+ by : Audiophonics
15078 + * Copyright 2018 Audiophonics
15080 + * This program is free software; you can redistribute it and/or
15081 + * modify it under the terms of the GNU General Public License
15082 + * version 2 as published by the Free Software Foundation.
15084 + * This program is distributed in the hope that it will be useful, but
15085 + * WITHOUT ANY WARRANTY; without even the implied warranty of
15086 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15087 + * General Public License for more details.
15091 +#include <linux/init.h>
15092 +#include <linux/module.h>
15093 +#include <linux/regmap.h>
15094 +#include <linux/i2c.h>
15095 +#include <sound/soc.h>
15096 +#include <sound/pcm_params.h>
15097 +#include <sound/tlv.h>
15099 +#include "i-sabre-codec.h"
15102 +/* I-Sabre Q2M Codec Private Data */
15103 +struct i_sabre_codec_priv {
15104 + struct regmap *regmap;
15105 + unsigned int fmt;
15109 +/* I-Sabre Q2M Codec Default Register Value */
15110 +static const struct reg_default i_sabre_codec_reg_defaults[] = {
15111 + { ISABRECODEC_REG_10, 0x00 },
15112 + { ISABRECODEC_REG_20, 0x00 },
15113 + { ISABRECODEC_REG_21, 0x00 },
15114 + { ISABRECODEC_REG_22, 0x00 },
15115 + { ISABRECODEC_REG_24, 0x00 },
15119 +static bool i_sabre_codec_writeable(struct device *dev, unsigned int reg)
15122 + case ISABRECODEC_REG_10:
15123 + case ISABRECODEC_REG_20:
15124 + case ISABRECODEC_REG_21:
15125 + case ISABRECODEC_REG_22:
15126 + case ISABRECODEC_REG_24:
15134 +static bool i_sabre_codec_readable(struct device *dev, unsigned int reg)
15137 + case ISABRECODEC_REG_01:
15138 + case ISABRECODEC_REG_02:
15139 + case ISABRECODEC_REG_10:
15140 + case ISABRECODEC_REG_20:
15141 + case ISABRECODEC_REG_21:
15142 + case ISABRECODEC_REG_22:
15143 + case ISABRECODEC_REG_24:
15151 +static bool i_sabre_codec_volatile(struct device *dev, unsigned int reg)
15154 + case ISABRECODEC_REG_01:
15155 + case ISABRECODEC_REG_02:
15164 +/* Volume Scale */
15165 +static const DECLARE_TLV_DB_SCALE(volume_tlv, -10000, 100, 0);
15169 +static const char * const fir_filter_type_texts[] = {
15171 + "corrected minimum phase fast",
15172 + "minimum phase slow",
15173 + "minimum phase fast",
15174 + "linear phase slow",
15175 + "linear phase fast",
15176 + "apodizing fast",
15179 +static SOC_ENUM_SINGLE_DECL(i_sabre_fir_filter_type_enum,
15180 + ISABRECODEC_REG_22, 0, fir_filter_type_texts);
15183 +/* I2S / SPDIF Select */
15184 +static const char * const iis_spdif_sel_texts[] = {
15189 +static SOC_ENUM_SINGLE_DECL(i_sabre_iis_spdif_sel_enum,
15190 + ISABRECODEC_REG_24, 0, iis_spdif_sel_texts);
15194 +static const struct snd_kcontrol_new i_sabre_codec_controls[] = {
15195 +SOC_SINGLE_RANGE_TLV("Digital Playback Volume", ISABRECODEC_REG_20, 0, 0, 100, 1, volume_tlv),
15196 +SOC_SINGLE("Digital Playback Switch", ISABRECODEC_REG_21, 0, 1, 1),
15197 +SOC_ENUM("FIR Filter Type", i_sabre_fir_filter_type_enum),
15198 +SOC_ENUM("I2S/SPDIF Select", i_sabre_iis_spdif_sel_enum),
15202 +static const u32 i_sabre_codec_dai_rates_slave[] = {
15203 + 8000, 11025, 16000, 22050, 32000,
15204 + 44100, 48000, 64000, 88200, 96000,
15205 + 176400, 192000, 352800, 384000,
15206 + 705600, 768000, 1411200, 1536000
15209 +static const struct snd_pcm_hw_constraint_list constraints_slave = {
15210 + .list = i_sabre_codec_dai_rates_slave,
15211 + .count = ARRAY_SIZE(i_sabre_codec_dai_rates_slave),
15214 +static int i_sabre_codec_dai_startup_slave(
15215 + struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
15217 + struct snd_soc_component *component = dai->component;
15220 + ret = snd_pcm_hw_constraint_list(substream->runtime,
15221 + 0, SNDRV_PCM_HW_PARAM_RATE, &constraints_slave);
15223 + dev_err(component->card->dev, "Failed to setup rates constraints: %d\n", ret);
15229 +static int i_sabre_codec_dai_startup(
15230 + struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
15232 + struct snd_soc_component *component = dai->component;
15233 + struct i_sabre_codec_priv *i_sabre_codec
15234 + = snd_soc_component_get_drvdata(component);
15236 + switch (i_sabre_codec->fmt & SND_SOC_DAIFMT_MASTER_MASK) {
15237 + case SND_SOC_DAIFMT_CBS_CFS:
15238 + return i_sabre_codec_dai_startup_slave(substream, dai);
15241 + return (-EINVAL);
15245 +static int i_sabre_codec_hw_params(
15246 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params,
15247 + struct snd_soc_dai *dai)
15249 + struct snd_soc_component *component = dai->component;
15250 + struct i_sabre_codec_priv *i_sabre_codec
15251 + = snd_soc_component_get_drvdata(component);
15252 + unsigned int daifmt;
15253 + int format_width;
15255 + dev_dbg(component->card->dev, "hw_params %u Hz, %u channels\n",
15256 + params_rate(params), params_channels(params));
15258 + /* Check I2S Format (Bit Size) */
15259 + format_width = snd_pcm_format_width(params_format(params));
15260 + if ((format_width != 32) && (format_width != 16)) {
15261 + dev_err(component->card->dev, "Bad frame size: %d\n",
15262 + snd_pcm_format_width(params_format(params)));
15263 + return (-EINVAL);
15266 + /* Check Slave Mode */
15267 + daifmt = i_sabre_codec->fmt & SND_SOC_DAIFMT_MASTER_MASK;
15268 + if (daifmt != SND_SOC_DAIFMT_CBS_CFS) {
15269 + return (-EINVAL);
15272 + /* Notify Sampling Frequency */
15273 + switch (params_rate(params))
15281 + snd_soc_component_update_bits(component, ISABRECODEC_REG_10, 0x01, 0x00);
15290 + snd_soc_component_update_bits(component, ISABRECODEC_REG_10, 0x01, 0x01);
15297 +static int i_sabre_codec_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
15299 + struct snd_soc_component *component = dai->component;
15300 + struct i_sabre_codec_priv *i_sabre_codec
15301 + = snd_soc_component_get_drvdata(component);
15303 + /* interface format */
15304 + switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
15305 + case SND_SOC_DAIFMT_I2S:
15308 + case SND_SOC_DAIFMT_RIGHT_J:
15309 + case SND_SOC_DAIFMT_LEFT_J:
15311 + return (-EINVAL);
15314 + /* clock inversion */
15315 + if ((fmt & SND_SOC_DAIFMT_INV_MASK) != SND_SOC_DAIFMT_NB_NF) {
15316 + return (-EINVAL);
15319 + /* Set Audio Data Format */
15320 + i_sabre_codec->fmt = fmt;
15325 +static int i_sabre_codec_dac_mute(struct snd_soc_dai *dai, int mute, int direction)
15327 + struct snd_soc_component *component = dai->component;
15330 + snd_soc_component_update_bits(component, ISABRECODEC_REG_21, 0x01, 0x01);
15332 + snd_soc_component_update_bits(component, ISABRECODEC_REG_21, 0x01, 0x00);
15339 +static const struct snd_soc_dai_ops i_sabre_codec_dai_ops = {
15340 + .startup = i_sabre_codec_dai_startup,
15341 + .hw_params = i_sabre_codec_hw_params,
15342 + .set_fmt = i_sabre_codec_set_fmt,
15343 + .mute_stream = i_sabre_codec_dac_mute,
15346 +static struct snd_soc_dai_driver i_sabre_codec_dai = {
15347 + .name = "i-sabre-codec-dai",
15349 + .stream_name = "Playback",
15350 + .channels_min = 2,
15351 + .channels_max = 2,
15352 + .rates = SNDRV_PCM_RATE_CONTINUOUS,
15353 + .rate_min = 8000,
15354 + .rate_max = 1536000,
15355 + .formats = SNDRV_PCM_FMTBIT_S16_LE
15356 + | SNDRV_PCM_FMTBIT_S32_LE,
15358 + .ops = &i_sabre_codec_dai_ops,
15361 +static struct snd_soc_component_driver i_sabre_codec_codec_driver = {
15362 + .controls = i_sabre_codec_controls,
15363 + .num_controls = ARRAY_SIZE(i_sabre_codec_controls),
15367 +static const struct regmap_config i_sabre_codec_regmap = {
15370 + .max_register = ISABRECODEC_MAX_REG,
15372 + .reg_defaults = i_sabre_codec_reg_defaults,
15373 + .num_reg_defaults = ARRAY_SIZE(i_sabre_codec_reg_defaults),
15375 + .writeable_reg = i_sabre_codec_writeable,
15376 + .readable_reg = i_sabre_codec_readable,
15377 + .volatile_reg = i_sabre_codec_volatile,
15379 + .cache_type = REGCACHE_RBTREE,
15383 +static int i_sabre_codec_probe(struct device *dev, struct regmap *regmap)
15385 + struct i_sabre_codec_priv *i_sabre_codec;
15388 + i_sabre_codec = devm_kzalloc(dev, sizeof(*i_sabre_codec), GFP_KERNEL);
15389 + if (!i_sabre_codec) {
15390 + dev_err(dev, "devm_kzalloc");
15391 + return (-ENOMEM);
15394 + i_sabre_codec->regmap = regmap;
15396 + dev_set_drvdata(dev, i_sabre_codec);
15398 + ret = snd_soc_register_component(dev,
15399 + &i_sabre_codec_codec_driver, &i_sabre_codec_dai, 1);
15401 + dev_err(dev, "Failed to register CODEC: %d\n", ret);
15408 +static void i_sabre_codec_remove(struct device *dev)
15410 + snd_soc_unregister_component(dev);
15414 +static int i_sabre_codec_i2c_probe(struct i2c_client *i2c)
15416 + struct regmap *regmap;
15418 + regmap = devm_regmap_init_i2c(i2c, &i_sabre_codec_regmap);
15419 + if (IS_ERR(regmap)) {
15420 + return PTR_ERR(regmap);
15423 + return i_sabre_codec_probe(&i2c->dev, regmap);
15426 +static void i_sabre_codec_i2c_remove(struct i2c_client *i2c)
15428 + i_sabre_codec_remove(&i2c->dev);
15432 +static const struct i2c_device_id i_sabre_codec_i2c_id[] = {
15433 + { "i-sabre-codec", },
15436 +MODULE_DEVICE_TABLE(i2c, i_sabre_codec_i2c_id);
15438 +static const struct of_device_id i_sabre_codec_of_match[] = {
15439 + { .compatible = "audiophonics,i-sabre-codec", },
15442 +MODULE_DEVICE_TABLE(of, i_sabre_codec_of_match);
15444 +static struct i2c_driver i_sabre_codec_i2c_driver = {
15446 + .name = "i-sabre-codec-i2c",
15447 + .owner = THIS_MODULE,
15448 + .of_match_table = of_match_ptr(i_sabre_codec_of_match),
15450 + .probe = i_sabre_codec_i2c_probe,
15451 + .remove = i_sabre_codec_i2c_remove,
15452 + .id_table = i_sabre_codec_i2c_id,
15454 +module_i2c_driver(i_sabre_codec_i2c_driver);
15457 +MODULE_DESCRIPTION("ASoC I-Sabre Q2M codec driver");
15458 +MODULE_AUTHOR("Audiophonics <http://www.audiophonics.fr>");
15459 +MODULE_LICENSE("GPL");
15461 +++ b/sound/soc/codecs/i-sabre-codec.h
15464 + * Driver for I-Sabre Q2M
15466 + * Author: Satoru Kawase
15467 + * Modified by: Xiao Qingyong
15468 + * Copyright 2018 Audiophonics
15470 + * This program is free software; you can redistribute it and/or
15471 + * modify it under the terms of the GNU General Public License
15472 + * version 2 as published by the Free Software Foundation.
15474 + * This program is distributed in the hope that it will be useful, but
15475 + * WITHOUT ANY WARRANTY; without even the implied warranty of
15476 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15477 + * General Public License for more details.
15480 +#ifndef _SND_SOC_ISABRECODEC
15481 +#define _SND_SOC_ISABRECODEC
15484 +/* ISABRECODEC Register Address */
15485 +#define ISABRECODEC_REG_01 0x01 /* Virtual Device ID : 0x01 = es9038q2m */
15486 +#define ISABRECODEC_REG_02 0x02 /* API revision : 0x01 = Revision 01 */
15487 +#define ISABRECODEC_REG_10 0x10 /* 0x01 = above 192kHz, 0x00 = otherwise */
15488 +#define ISABRECODEC_REG_20 0x20 /* 0 - 100 (decimal value, 0 = min., 100 = max.) */
15489 +#define ISABRECODEC_REG_21 0x21 /* 0x00 = Mute OFF, 0x01 = Mute ON */
15490 +#define ISABRECODEC_REG_22 0x22
15492 + 0x00 = brick wall,
15493 + 0x01 = corrected minimum phase fast,
15494 + 0x02 = minimum phase slow,
15495 + 0x03 = minimum phase fast,
15496 + 0x04 = linear phase slow,
15497 + 0x05 = linear phase fast,
15498 + 0x06 = apodizing fast,
15500 +//#define ISABRECODEC_REG_23 0x23 /* reserved */
15501 +#define ISABRECODEC_REG_24 0x24 /* 0x00 = I2S, 0x01 = SPDIF */
15502 +#define ISABRECODEC_MAX_REG 0x24 /* Maximum Register Number */
15504 +#endif /* _SND_SOC_ISABRECODEC */
15506 +++ b/sound/soc/codecs/ma120x0p.c
15508 +// SPDX-License-Identifier: GPL-2.0-or-later
15510 + * ASoC Driver for Infineon Merus(TM) ma120x0p multi-level class-D amplifier
15512 + * Authors: Ariel Muszkat <ariel.muszkat@gmail.com>
15513 + * Jorgen Kragh Jakobsen <jorgen.kraghjakobsen@infineon.com>
15515 + * Copyright (C) 2019 Infineon Technologies AG
15518 +#include <linux/module.h>
15519 +#include <linux/moduleparam.h>
15520 +#include <linux/init.h>
15521 +#include <linux/delay.h>
15522 +#include <linux/pm_runtime.h>
15523 +#include <linux/i2c.h>
15524 +#include <linux/of_device.h>
15525 +#include <linux/spi/spi.h>
15526 +#include <linux/regmap.h>
15527 +#include <linux/regulator/consumer.h>
15528 +#include <linux/slab.h>
15529 +#include <linux/gpio/consumer.h>
15530 +#include <linux/gpio.h>
15531 +#include <sound/core.h>
15532 +#include <sound/pcm.h>
15533 +#include <sound/pcm_params.h>
15534 +#include <sound/soc.h>
15535 +#include <sound/soc-dapm.h>
15536 +#include <sound/initval.h>
15537 +#include <sound/tlv.h>
15538 +#include <linux/interrupt.h>
15540 +#include <linux/kernel.h>
15541 +#include <linux/string.h>
15542 +#include <linux/fs.h>
15543 +#include <linux/uaccess.h>
15545 +#ifndef _MA120X0P_
15546 +#define _MA120X0P_
15547 +//------------------------------------------------------------------manualPM---
15548 +// Select Manual PowerMode control
15549 +#define ma_manualpm__a 0
15550 +#define ma_manualpm__len 1
15551 +#define ma_manualpm__mask 0x40
15552 +#define ma_manualpm__shift 0x06
15553 +#define ma_manualpm__reset 0x00
15554 +//--------------------------------------------------------------------pm_man---
15555 +// manual selected power mode
15556 +#define ma_pm_man__a 0
15557 +#define ma_pm_man__len 2
15558 +#define ma_pm_man__mask 0x30
15559 +#define ma_pm_man__shift 0x04
15560 +#define ma_pm_man__reset 0x03
15561 +//------------------------------------------ ----------------------mthr_1to2---
15562 +// mod. index threshold value for pm1=>pm2 change.
15563 +#define ma_mthr_1to2__a 1
15564 +#define ma_mthr_1to2__len 8
15565 +#define ma_mthr_1to2__mask 0xff
15566 +#define ma_mthr_1to2__shift 0x00
15567 +#define ma_mthr_1to2__reset 0x3c
15568 +//-----------------------------------------------------------------mthr_2to1---
15569 +// mod. index threshold value for pm2=>pm1 change.
15570 +#define ma_mthr_2to1__a 2
15571 +#define ma_mthr_2to1__len 8
15572 +#define ma_mthr_2to1__mask 0xff
15573 +#define ma_mthr_2to1__shift 0x00
15574 +#define ma_mthr_2to1__reset 0x32
15575 +//-----------------------------------------------------------------mthr_2to3---
15576 +// mod. index threshold value for pm2=>pm3 change.
15577 +#define ma_mthr_2to3__a 3
15578 +#define ma_mthr_2to3__len 8
15579 +#define ma_mthr_2to3__mask 0xff
15580 +#define ma_mthr_2to3__shift 0x00
15581 +#define ma_mthr_2to3__reset 0x5a
15582 +//-----------------------------------------------------------------mthr_3to2---
15583 +// mod. index threshold value for pm3=>pm2 change.
15584 +#define ma_mthr_3to2__a 4
15585 +#define ma_mthr_3to2__len 8
15586 +#define ma_mthr_3to2__mask 0xff
15587 +#define ma_mthr_3to2__shift 0x00
15588 +#define ma_mthr_3to2__reset 0x50
15589 +//-------------------------------------------------------------pwmclkdiv_nom---
15590 +// pwm default clock divider value
15591 +#define ma_pwmclkdiv_nom__a 8
15592 +#define ma_pwmclkdiv_nom__len 8
15593 +#define ma_pwmclkdiv_nom__mask 0xff
15594 +#define ma_pwmclkdiv_nom__shift 0x00
15595 +#define ma_pwmclkdiv_nom__reset 0x26
15596 +//--------- ----------------------------------------------------ocp_latch_en---
15597 +// high to use permanently latching level-2 ocp
15598 +#define ma_ocp_latch_en__a 10
15599 +#define ma_ocp_latch_en__len 1
15600 +#define ma_ocp_latch_en__mask 0x02
15601 +#define ma_ocp_latch_en__shift 0x01
15602 +#define ma_ocp_latch_en__reset 0x00
15603 +//---------------------------------------------------------------lf_clamp_en---
15604 +// high (default) to enable lf int2+3 clamping on clip
15605 +#define ma_lf_clamp_en__a 10
15606 +#define ma_lf_clamp_en__len 1
15607 +#define ma_lf_clamp_en__mask 0x80
15608 +#define ma_lf_clamp_en__shift 0x07
15609 +#define ma_lf_clamp_en__reset 0x00
15610 +//-------------------------------------------------------pmcfg_btl_b.modtype---
15612 +#define ma_pmcfg_btl_b__modtype__a 18
15613 +#define ma_pmcfg_btl_b__modtype__len 2
15614 +#define ma_pmcfg_btl_b__modtype__mask 0x18
15615 +#define ma_pmcfg_btl_b__modtype__shift 0x03
15616 +#define ma_pmcfg_btl_b__modtype__reset 0x02
15617 +//-------------------------------------------------------pmcfg_btl_b.freqdiv---
15618 +#define ma_pmcfg_btl_b__freqdiv__a 18
15619 +#define ma_pmcfg_btl_b__freqdiv__len 2
15620 +#define ma_pmcfg_btl_b__freqdiv__mask 0x06
15621 +#define ma_pmcfg_btl_b__freqdiv__shift 0x01
15622 +#define ma_pmcfg_btl_b__freqdiv__reset 0x01
15623 +//----------------------------------------------------pmcfg_btl_b.lf_gain_ol---
15625 +#define ma_pmcfg_btl_b__lf_gain_ol__a 18
15626 +#define ma_pmcfg_btl_b__lf_gain_ol__len 1
15627 +#define ma_pmcfg_btl_b__lf_gain_ol__mask 0x01
15628 +#define ma_pmcfg_btl_b__lf_gain_ol__shift 0x00
15629 +#define ma_pmcfg_btl_b__lf_gain_ol__reset 0x01
15630 +//-------------------------------------------------------pmcfg_btl_c.freqdiv---
15632 +#define ma_pmcfg_btl_c__freqdiv__a 19
15633 +#define ma_pmcfg_btl_c__freqdiv__len 2
15634 +#define ma_pmcfg_btl_c__freqdiv__mask 0x06
15635 +#define ma_pmcfg_btl_c__freqdiv__shift 0x01
15636 +#define ma_pmcfg_btl_c__freqdiv__reset 0x01
15637 +//-------------------------------------------------------pmcfg_btl_c.modtype---
15639 +#define ma_pmcfg_btl_c__modtype__a 19
15640 +#define ma_pmcfg_btl_c__modtype__len 2
15641 +#define ma_pmcfg_btl_c__modtype__mask 0x18
15642 +#define ma_pmcfg_btl_c__modtype__shift 0x03
15643 +#define ma_pmcfg_btl_c__modtype__reset 0x01
15644 +//----------------------------------------------------pmcfg_btl_c.lf_gain_ol---
15646 +#define ma_pmcfg_btl_c__lf_gain_ol__a 19
15647 +#define ma_pmcfg_btl_c__lf_gain_ol__len 1
15648 +#define ma_pmcfg_btl_c__lf_gain_ol__mask 0x01
15649 +#define ma_pmcfg_btl_c__lf_gain_ol__shift 0x00
15650 +#define ma_pmcfg_btl_c__lf_gain_ol__reset 0x00
15651 +//-------------------------------------------------------pmcfg_btl_d.modtype---
15653 +#define ma_pmcfg_btl_d__modtype__a 20
15654 +#define ma_pmcfg_btl_d__modtype__len 2
15655 +#define ma_pmcfg_btl_d__modtype__mask 0x18
15656 +#define ma_pmcfg_btl_d__modtype__shift 0x03
15657 +#define ma_pmcfg_btl_d__modtype__reset 0x02
15658 +//-------------------------------------------------------pmcfg_btl_d.freqdiv---
15660 +#define ma_pmcfg_btl_d__freqdiv__a 20
15661 +#define ma_pmcfg_btl_d__freqdiv__len 2
15662 +#define ma_pmcfg_btl_d__freqdiv__mask 0x06
15663 +#define ma_pmcfg_btl_d__freqdiv__shift 0x01
15664 +#define ma_pmcfg_btl_d__freqdiv__reset 0x02
15665 +//----------------------------------------------------pmcfg_btl_d.lf_gain_ol---
15667 +#define ma_pmcfg_btl_d__lf_gain_ol__a 20
15668 +#define ma_pmcfg_btl_d__lf_gain_ol__len 1
15669 +#define ma_pmcfg_btl_d__lf_gain_ol__mask 0x01
15670 +#define ma_pmcfg_btl_d__lf_gain_ol__shift 0x00
15671 +#define ma_pmcfg_btl_d__lf_gain_ol__reset 0x00
15672 +//------------ -------------------------------------------pmcfg_se_a.modtype---
15674 +#define ma_pmcfg_se_a__modtype__a 21
15675 +#define ma_pmcfg_se_a__modtype__len 2
15676 +#define ma_pmcfg_se_a__modtype__mask 0x18
15677 +#define ma_pmcfg_se_a__modtype__shift 0x03
15678 +#define ma_pmcfg_se_a__modtype__reset 0x01
15679 +//--------------------------------------------------------pmcfg_se_a.freqdiv---
15681 +#define ma_pmcfg_se_a__freqdiv__a 21
15682 +#define ma_pmcfg_se_a__freqdiv__len 2
15683 +#define ma_pmcfg_se_a__freqdiv__mask 0x06
15684 +#define ma_pmcfg_se_a__freqdiv__shift 0x01
15685 +#define ma_pmcfg_se_a__freqdiv__reset 0x00
15686 +//-----------------------------------------------------pmcfg_se_a.lf_gain_ol---
15688 +#define ma_pmcfg_se_a__lf_gain_ol__a 21
15689 +#define ma_pmcfg_se_a__lf_gain_ol__len 1
15690 +#define ma_pmcfg_se_a__lf_gain_ol__mask 0x01
15691 +#define ma_pmcfg_se_a__lf_gain_ol__shift 0x00
15692 +#define ma_pmcfg_se_a__lf_gain_ol__reset 0x01
15693 +//-----------------------------------------------------pmcfg_se_b.lf_gain_ol---
15695 +#define ma_pmcfg_se_b__lf_gain_ol__a 22
15696 +#define ma_pmcfg_se_b__lf_gain_ol__len 1
15697 +#define ma_pmcfg_se_b__lf_gain_ol__mask 0x01
15698 +#define ma_pmcfg_se_b__lf_gain_ol__shift 0x00
15699 +#define ma_pmcfg_se_b__lf_gain_ol__reset 0x00
15700 +//--------------------------------------------------------pmcfg_se_b.freqdiv---
15702 +#define ma_pmcfg_se_b__freqdiv__a 22
15703 +#define ma_pmcfg_se_b__freqdiv__len 2
15704 +#define ma_pmcfg_se_b__freqdiv__mask 0x06
15705 +#define ma_pmcfg_se_b__freqdiv__shift 0x01
15706 +#define ma_pmcfg_se_b__freqdiv__reset 0x01
15707 +//--------------------------------------------------------pmcfg_se_b.modtype---
15709 +#define ma_pmcfg_se_b__modtype__a 22
15710 +#define ma_pmcfg_se_b__modtype__len 2
15711 +#define ma_pmcfg_se_b__modtype__mask 0x18
15712 +#define ma_pmcfg_se_b__modtype__shift 0x03
15713 +#define ma_pmcfg_se_b__modtype__reset 0x01
15714 +//----------------------------------------------------------balwaitcount_pm1---
15715 +// pm1 balancing period.
15716 +#define ma_balwaitcount_pm1__a 23
15717 +#define ma_balwaitcount_pm1__len 8
15718 +#define ma_balwaitcount_pm1__mask 0xff
15719 +#define ma_balwaitcount_pm1__shift 0x00
15720 +#define ma_balwaitcount_pm1__reset 0x14
15721 +//----------------------------------------------------------balwaitcount_pm2---
15722 +// pm2 balancing period.
15723 +#define ma_balwaitcount_pm2__a 24
15724 +#define ma_balwaitcount_pm2__len 8
15725 +#define ma_balwaitcount_pm2__mask 0xff
15726 +#define ma_balwaitcount_pm2__shift 0x00
15727 +#define ma_balwaitcount_pm2__reset 0x14
15728 +//----------------------------------------------------------balwaitcount_pm3---
15729 +// pm3 balancing period.
15730 +#define ma_balwaitcount_pm3__a 25
15731 +#define ma_balwaitcount_pm3__len 8
15732 +#define ma_balwaitcount_pm3__mask 0xff
15733 +#define ma_balwaitcount_pm3__shift 0x00
15734 +#define ma_balwaitcount_pm3__reset 0x1a
15735 +//-------------------------------------------------------------usespread_pm1---
15736 +// pm1 pwm spread-spectrum mode on/off.
15737 +#define ma_usespread_pm1__a 26
15738 +#define ma_usespread_pm1__len 1
15739 +#define ma_usespread_pm1__mask 0x40
15740 +#define ma_usespread_pm1__shift 0x06
15741 +#define ma_usespread_pm1__reset 0x00
15742 +//---------------------------------------------------------------dtsteps_pm1---
15743 +// pm1 dead time setting [10ns steps].
15744 +#define ma_dtsteps_pm1__a 26
15745 +#define ma_dtsteps_pm1__len 3
15746 +#define ma_dtsteps_pm1__mask 0x38
15747 +#define ma_dtsteps_pm1__shift 0x03
15748 +#define ma_dtsteps_pm1__reset 0x04
15749 +//---------------------------------------------------------------baltype_pm1---
15750 +// pm1 balancing sensor scheme.
15751 +#define ma_baltype_pm1__a 26
15752 +#define ma_baltype_pm1__len 3
15753 +#define ma_baltype_pm1__mask 0x07
15754 +#define ma_baltype_pm1__shift 0x00
15755 +#define ma_baltype_pm1__reset 0x00
15756 +//-------------------------------------------------------------usespread_pm2---
15757 +// pm2 pwm spread-spectrum mode on/off.
15758 +#define ma_usespread_pm2__a 27
15759 +#define ma_usespread_pm2__len 1
15760 +#define ma_usespread_pm2__mask 0x40
15761 +#define ma_usespread_pm2__shift 0x06
15762 +#define ma_usespread_pm2__reset 0x00
15763 +//---------------------------------------------------------------dtsteps_pm2---
15764 +// pm2 dead time setting [10ns steps].
15765 +#define ma_dtsteps_pm2__a 27
15766 +#define ma_dtsteps_pm2__len 3
15767 +#define ma_dtsteps_pm2__mask 0x38
15768 +#define ma_dtsteps_pm2__shift 0x03
15769 +#define ma_dtsteps_pm2__reset 0x03
15770 +//---------------------------------------------------------------baltype_pm2---
15771 +// pm2 balancing sensor scheme.
15772 +#define ma_baltype_pm2__a 27
15773 +#define ma_baltype_pm2__len 3
15774 +#define ma_baltype_pm2__mask 0x07
15775 +#define ma_baltype_pm2__shift 0x00
15776 +#define ma_baltype_pm2__reset 0x01
15777 +//-------------------------------------------------------------usespread_pm3---
15778 +// pm3 pwm spread-spectrum mode on/off.
15779 +#define ma_usespread_pm3__a 28
15780 +#define ma_usespread_pm3__len 1
15781 +#define ma_usespread_pm3__mask 0x40
15782 +#define ma_usespread_pm3__shift 0x06
15783 +#define ma_usespread_pm3__reset 0x00
15784 +//---------------------------------------------------------------dtsteps_pm3---
15785 +// pm3 dead time setting [10ns steps].
15786 +#define ma_dtsteps_pm3__a 28
15787 +#define ma_dtsteps_pm3__len 3
15788 +#define ma_dtsteps_pm3__mask 0x38
15789 +#define ma_dtsteps_pm3__shift 0x03
15790 +#define ma_dtsteps_pm3__reset 0x01
15791 +//---------------------------------------------------------------baltype_pm3---
15792 +// pm3 balancing sensor scheme.
15793 +#define ma_baltype_pm3__a 28
15794 +#define ma_baltype_pm3__len 3
15795 +#define ma_baltype_pm3__mask 0x07
15796 +#define ma_baltype_pm3__shift 0x00
15797 +#define ma_baltype_pm3__reset 0x03
15798 +//-----------------------------------------------------------------pmprofile---
15799 +// pm profile select. valid presets: 0-1-2-3-4. 5=> custom profile.
15800 +#define ma_pmprofile__a 29
15801 +#define ma_pmprofile__len 3
15802 +#define ma_pmprofile__mask 0x07
15803 +#define ma_pmprofile__shift 0x00
15804 +#define ma_pmprofile__reset 0x00
15805 +//-------------------------------------------------------------------pm3_man---
15806 +// custom profile pm3 contents. 0=>a, 1=>b, 2=>c, 3=>d
15807 +#define ma_pm3_man__a 30
15808 +#define ma_pm3_man__len 2
15809 +#define ma_pm3_man__mask 0x30
15810 +#define ma_pm3_man__shift 0x04
15811 +#define ma_pm3_man__reset 0x02
15812 +//-------------------------------------------------------------------pm2_man---
15813 +// custom profile pm2 contents. 0=>a, 1=>b, 2=>c, 3=>d
15814 +#define ma_pm2_man__a 30
15815 +#define ma_pm2_man__len 2
15816 +#define ma_pm2_man__mask 0x0c
15817 +#define ma_pm2_man__shift 0x02
15818 +#define ma_pm2_man__reset 0x03
15819 +//-------------------------------------------------------------------pm1_man---
15820 +// custom profile pm1 contents. 0=>a, 1=>b, 2=>c, 3=>d
15821 +#define ma_pm1_man__a 30
15822 +#define ma_pm1_man__len 2
15823 +#define ma_pm1_man__mask 0x03
15824 +#define ma_pm1_man__shift 0x00
15825 +#define ma_pm1_man__reset 0x03
15826 +//-----------------------------------------------------------ocp_latch_clear---
15827 +// low-high clears current ocp latched condition.
15828 +#define ma_ocp_latch_clear__a 32
15829 +#define ma_ocp_latch_clear__len 1
15830 +#define ma_ocp_latch_clear__mask 0x80
15831 +#define ma_ocp_latch_clear__shift 0x07
15832 +#define ma_ocp_latch_clear__reset 0x00
15833 +//-------------------------------------------------------------audio_in_mode---
15834 +// audio input mode; 0-1-2-3-4-5
15835 +#define ma_audio_in_mode__a 37
15836 +#define ma_audio_in_mode__len 3
15837 +#define ma_audio_in_mode__mask 0xe0
15838 +#define ma_audio_in_mode__shift 0x05
15839 +#define ma_audio_in_mode__reset 0x00
15840 +//-----------------------------------------------------------------eh_dcshdn---
15841 +// high to enable dc protection
15842 +#define ma_eh_dcshdn__a 38
15843 +#define ma_eh_dcshdn__len 1
15844 +#define ma_eh_dcshdn__mask 0x04
15845 +#define ma_eh_dcshdn__shift 0x02
15846 +#define ma_eh_dcshdn__reset 0x01
15847 +//---------------------------------------------------------audio_in_mode_ext---
15848 +// if set, audio_in_mode is controlled from audio_in_mode register. if not set
15849 +//audio_in_mode is set from fuse bank setting
15850 +#define ma_audio_in_mode_ext__a 39
15851 +#define ma_audio_in_mode_ext__len 1
15852 +#define ma_audio_in_mode_ext__mask 0x20
15853 +#define ma_audio_in_mode_ext__shift 0x05
15854 +#define ma_audio_in_mode_ext__reset 0x00
15855 +//------------------------------------------------------------------eh_clear---
15856 +// flip to clear error registers
15857 +#define ma_eh_clear__a 45
15858 +#define ma_eh_clear__len 1
15859 +#define ma_eh_clear__mask 0x04
15860 +#define ma_eh_clear__shift 0x02
15861 +#define ma_eh_clear__reset 0x00
15862 +//----------------------------------------------------------thermal_compr_en---
15863 +// enable otw-contr. input compression?
15864 +#define ma_thermal_compr_en__a 45
15865 +#define ma_thermal_compr_en__len 1
15866 +#define ma_thermal_compr_en__mask 0x20
15867 +#define ma_thermal_compr_en__shift 0x05
15868 +#define ma_thermal_compr_en__reset 0x01
15869 +//---------------------------------------------------------------system_mute---
15870 +// 1 = mute system, 0 = normal operation
15871 +#define ma_system_mute__a 45
15872 +#define ma_system_mute__len 1
15873 +#define ma_system_mute__mask 0x40
15874 +#define ma_system_mute__shift 0x06
15875 +#define ma_system_mute__reset 0x00
15876 +//------------------------------------------------------thermal_compr_max_db---
15877 +// audio limiter max thermal reduction
15878 +#define ma_thermal_compr_max_db__a 46
15879 +#define ma_thermal_compr_max_db__len 3
15880 +#define ma_thermal_compr_max_db__mask 0x07
15881 +#define ma_thermal_compr_max_db__shift 0x00
15882 +#define ma_thermal_compr_max_db__reset 0x04
15883 +//---------------------------------------------------------audio_proc_enable---
15884 +// enable audio proc, bypass if not enabled
15885 +#define ma_audio_proc_enable__a 53
15886 +#define ma_audio_proc_enable__len 1
15887 +#define ma_audio_proc_enable__mask 0x08
15888 +#define ma_audio_proc_enable__shift 0x03
15889 +#define ma_audio_proc_enable__reset 0x00
15890 +//--------------------------------------------------------audio_proc_release---
15891 +// 00:slow, 01:normal, 10:fast
15892 +#define ma_audio_proc_release__a 53
15893 +#define ma_audio_proc_release__len 2
15894 +#define ma_audio_proc_release__mask 0x30
15895 +#define ma_audio_proc_release__shift 0x04
15896 +#define ma_audio_proc_release__reset 0x00
15897 +//---------------------------------------------------------audio_proc_attack---
15898 +// 00:slow, 01:normal, 10:fast
15899 +#define ma_audio_proc_attack__a 53
15900 +#define ma_audio_proc_attack__len 2
15901 +#define ma_audio_proc_attack__mask 0xc0
15902 +#define ma_audio_proc_attack__shift 0x06
15903 +#define ma_audio_proc_attack__reset 0x00
15904 +//----------------------------------------------------------------i2s_format---
15905 +// i2s basic data format, 000 = std. i2s, 001 = left justified (default)
15906 +#define ma_i2s_format__a 53
15907 +#define ma_i2s_format__len 3
15908 +#define ma_i2s_format__mask 0x07
15909 +#define ma_i2s_format__shift 0x00
15910 +#define ma_i2s_format__reset 0x01
15911 +//--------------------------------------------------audio_proc_limiterenable---
15912 +// 1: enable limiter, 0: disable limiter
15913 +#define ma_audio_proc_limiterenable__a 54
15914 +#define ma_audio_proc_limiterenable__len 1
15915 +#define ma_audio_proc_limiterenable__mask 0x40
15916 +#define ma_audio_proc_limiterenable__shift 0x06
15917 +#define ma_audio_proc_limiterenable__reset 0x00
15918 +//-----------------------------------------------------------audio_proc_mute---
15919 +// 1: mute, 0: unmute
15920 +#define ma_audio_proc_mute__a 54
15921 +#define ma_audio_proc_mute__len 1
15922 +#define ma_audio_proc_mute__mask 0x80
15923 +#define ma_audio_proc_mute__shift 0x07
15924 +#define ma_audio_proc_mute__reset 0x00
15925 +//---------------------------------------------------------------i2s_sck_pol---
15926 +// i2s sck polarity cfg. 0 = rising edge data change
15927 +#define ma_i2s_sck_pol__a 54
15928 +#define ma_i2s_sck_pol__len 1
15929 +#define ma_i2s_sck_pol__mask 0x01
15930 +#define ma_i2s_sck_pol__shift 0x00
15931 +#define ma_i2s_sck_pol__reset 0x01
15932 +//-------------------------------------------------------------i2s_framesize---
15933 +// i2s word length. 00 = 32bit, 01 = 24bit
15934 +#define ma_i2s_framesize__a 54
15935 +#define ma_i2s_framesize__len 2
15936 +#define ma_i2s_framesize__mask 0x18
15937 +#define ma_i2s_framesize__shift 0x03
15938 +#define ma_i2s_framesize__reset 0x00
15939 +//----------------------------------------------------------------i2s_ws_pol---
15940 +// i2s ws polarity. 0 = low first
15941 +#define ma_i2s_ws_pol__a 54
15942 +#define ma_i2s_ws_pol__len 1
15943 +#define ma_i2s_ws_pol__mask 0x02
15944 +#define ma_i2s_ws_pol__shift 0x01
15945 +#define ma_i2s_ws_pol__reset 0x00
15946 +//-----------------------------------------------------------------i2s_order---
15947 +// i2s word bit order. 0 = msb first
15948 +#define ma_i2s_order__a 54
15949 +#define ma_i2s_order__len 1
15950 +#define ma_i2s_order__mask 0x04
15951 +#define ma_i2s_order__shift 0x02
15952 +#define ma_i2s_order__reset 0x00
15953 +//------------------------------------------------------------i2s_rightfirst---
15954 +// i2s l/r word order; 0 = left first
15955 +#define ma_i2s_rightfirst__a 54
15956 +#define ma_i2s_rightfirst__len 1
15957 +#define ma_i2s_rightfirst__mask 0x20
15958 +#define ma_i2s_rightfirst__shift 0x05
15959 +#define ma_i2s_rightfirst__reset 0x00
15960 +//-------------------------------------------------------------vol_db_master---
15961 +// master volume db
15962 +#define ma_vol_db_master__a 64
15963 +#define ma_vol_db_master__len 8
15964 +#define ma_vol_db_master__mask 0xff
15965 +#define ma_vol_db_master__shift 0x00
15966 +#define ma_vol_db_master__reset 0x18
15967 +//------------------------------------------------------------vol_lsb_master---
15968 +// master volume lsb 1/4 steps
15969 +#define ma_vol_lsb_master__a 65
15970 +#define ma_vol_lsb_master__len 2
15971 +#define ma_vol_lsb_master__mask 0x03
15972 +#define ma_vol_lsb_master__shift 0x00
15973 +#define ma_vol_lsb_master__reset 0x00
15974 +//----------------------------------------------------------------vol_db_ch0---
15975 +// volume channel 0
15976 +#define ma_vol_db_ch0__a 66
15977 +#define ma_vol_db_ch0__len 8
15978 +#define ma_vol_db_ch0__mask 0xff
15979 +#define ma_vol_db_ch0__shift 0x00
15980 +#define ma_vol_db_ch0__reset 0x18
15981 +//----------------------------------------------------------------vol_db_ch1---
15982 +// volume channel 1
15983 +#define ma_vol_db_ch1__a 67
15984 +#define ma_vol_db_ch1__len 8
15985 +#define ma_vol_db_ch1__mask 0xff
15986 +#define ma_vol_db_ch1__shift 0x00
15987 +#define ma_vol_db_ch1__reset 0x18
15988 +//----------------------------------------------------------------vol_db_ch2---
15989 +// volume channel 2
15990 +#define ma_vol_db_ch2__a 68
15991 +#define ma_vol_db_ch2__len 8
15992 +#define ma_vol_db_ch2__mask 0xff
15993 +#define ma_vol_db_ch2__shift 0x00
15994 +#define ma_vol_db_ch2__reset 0x18
15995 +//----------------------------------------------------------------vol_db_ch3---
15996 +// volume channel 3
15997 +#define ma_vol_db_ch3__a 69
15998 +#define ma_vol_db_ch3__len 8
15999 +#define ma_vol_db_ch3__mask 0xff
16000 +#define ma_vol_db_ch3__shift 0x00
16001 +#define ma_vol_db_ch3__reset 0x18
16002 +//---------------------------------------------------------------vol_lsb_ch0---
16003 +// volume channel 1 - 1/4 steps
16004 +#define ma_vol_lsb_ch0__a 70
16005 +#define ma_vol_lsb_ch0__len 2
16006 +#define ma_vol_lsb_ch0__mask 0x03
16007 +#define ma_vol_lsb_ch0__shift 0x00
16008 +#define ma_vol_lsb_ch0__reset 0x00
16009 +//---------------------------------------------------------------vol_lsb_ch1---
16010 +// volume channel 3 - 1/4 steps
16011 +#define ma_vol_lsb_ch1__a 70
16012 +#define ma_vol_lsb_ch1__len 2
16013 +#define ma_vol_lsb_ch1__mask 0x0c
16014 +#define ma_vol_lsb_ch1__shift 0x02
16015 +#define ma_vol_lsb_ch1__reset 0x00
16016 +//---------------------------------------------------------------vol_lsb_ch2---
16017 +// volume channel 2 - 1/4 steps
16018 +#define ma_vol_lsb_ch2__a 70
16019 +#define ma_vol_lsb_ch2__len 2
16020 +#define ma_vol_lsb_ch2__mask 0x30
16021 +#define ma_vol_lsb_ch2__shift 0x04
16022 +#define ma_vol_lsb_ch2__reset 0x00
16023 +//---------------------------------------------------------------vol_lsb_ch3---
16024 +// volume channel 3 - 1/4 steps
16025 +#define ma_vol_lsb_ch3__a 70
16026 +#define ma_vol_lsb_ch3__len 2
16027 +#define ma_vol_lsb_ch3__mask 0xc0
16028 +#define ma_vol_lsb_ch3__shift 0x06
16029 +#define ma_vol_lsb_ch3__reset 0x00
16030 +//----------------------------------------------------------------thr_db_ch0---
16031 +// thr_db channel 0
16032 +#define ma_thr_db_ch0__a 71
16033 +#define ma_thr_db_ch0__len 8
16034 +#define ma_thr_db_ch0__mask 0xff
16035 +#define ma_thr_db_ch0__shift 0x00
16036 +#define ma_thr_db_ch0__reset 0x18
16037 +//----------------------------------------------------------------thr_db_ch1---
16039 +#define ma_thr_db_ch1__a 72
16040 +#define ma_thr_db_ch1__len 8
16041 +#define ma_thr_db_ch1__mask 0xff
16042 +#define ma_thr_db_ch1__shift 0x00
16043 +#define ma_thr_db_ch1__reset 0x18
16044 +//----------------------------------------------------------------thr_db_ch2---
16046 +#define ma_thr_db_ch2__a 73
16047 +#define ma_thr_db_ch2__len 8
16048 +#define ma_thr_db_ch2__mask 0xff
16049 +#define ma_thr_db_ch2__shift 0x00
16050 +#define ma_thr_db_ch2__reset 0x18
16051 +//----------------------------------------------------------------thr_db_ch3---
16052 +// threshold db ch3
16053 +#define ma_thr_db_ch3__a 74
16054 +#define ma_thr_db_ch3__len 8
16055 +#define ma_thr_db_ch3__mask 0xff
16056 +#define ma_thr_db_ch3__shift 0x00
16057 +#define ma_thr_db_ch3__reset 0x18
16058 +//---------------------------------------------------------------thr_lsb_ch0---
16060 +#define ma_thr_lsb_ch0__a 75
16061 +#define ma_thr_lsb_ch0__len 2
16062 +#define ma_thr_lsb_ch0__mask 0x03
16063 +#define ma_thr_lsb_ch0__shift 0x00
16064 +#define ma_thr_lsb_ch0__reset 0x00
16065 +//---------------------------------------------------------------thr_lsb_ch1---
16067 +#define ma_thr_lsb_ch1__a 75
16068 +#define ma_thr_lsb_ch1__len 2
16069 +#define ma_thr_lsb_ch1__mask 0x0c
16070 +#define ma_thr_lsb_ch1__shift 0x02
16071 +#define ma_thr_lsb_ch1__reset 0x00
16072 +//---------------------------------------------------------------thr_lsb_ch2---
16073 +// thr lsb ch2 1/4 db step
16074 +#define ma_thr_lsb_ch2__a 75
16075 +#define ma_thr_lsb_ch2__len 2
16076 +#define ma_thr_lsb_ch2__mask 0x30
16077 +#define ma_thr_lsb_ch2__shift 0x04
16078 +#define ma_thr_lsb_ch2__reset 0x00
16079 +//---------------------------------------------------------------thr_lsb_ch3---
16080 +// threshold lsb ch3
16081 +#define ma_thr_lsb_ch3__a 75
16082 +#define ma_thr_lsb_ch3__len 2
16083 +#define ma_thr_lsb_ch3__mask 0xc0
16084 +#define ma_thr_lsb_ch3__shift 0x06
16085 +#define ma_thr_lsb_ch3__reset 0x00
16086 +//-----------------------------------------------------------dcu_mon0.pm_mon---
16087 +// power mode monitor channel 0
16088 +#define ma_dcu_mon0__pm_mon__a 96
16089 +#define ma_dcu_mon0__pm_mon__len 2
16090 +#define ma_dcu_mon0__pm_mon__mask 0x03
16091 +#define ma_dcu_mon0__pm_mon__shift 0x00
16092 +#define ma_dcu_mon0__pm_mon__reset 0x00
16093 +//-----------------------------------------------------dcu_mon0.freqmode_mon---
16094 +// frequence mode monitor channel 0
16095 +#define ma_dcu_mon0__freqmode_mon__a 96
16096 +#define ma_dcu_mon0__freqmode_mon__len 3
16097 +#define ma_dcu_mon0__freqmode_mon__mask 0x70
16098 +#define ma_dcu_mon0__freqmode_mon__shift 0x04
16099 +#define ma_dcu_mon0__freqmode_mon__reset 0x00
16100 +//-------------------------------------------------------dcu_mon0.pps_passed---
16101 +// dcu0 pps completion indicator
16102 +#define ma_dcu_mon0__pps_passed__a 96
16103 +#define ma_dcu_mon0__pps_passed__len 1
16104 +#define ma_dcu_mon0__pps_passed__mask 0x80
16105 +#define ma_dcu_mon0__pps_passed__shift 0x07
16106 +#define ma_dcu_mon0__pps_passed__reset 0x00
16107 +//----------------------------------------------------------dcu_mon0.ocp_mon---
16108 +// ocp monitor channel 0
16109 +#define ma_dcu_mon0__ocp_mon__a 97
16110 +#define ma_dcu_mon0__ocp_mon__len 1
16111 +#define ma_dcu_mon0__ocp_mon__mask 0x01
16112 +#define ma_dcu_mon0__ocp_mon__shift 0x00
16113 +#define ma_dcu_mon0__ocp_mon__reset 0x00
16114 +//--------------------------------------------------------dcu_mon0.vcfly1_ok---
16115 +// cfly1 protection monitor channel 0.
16116 +#define ma_dcu_mon0__vcfly1_ok__a 97
16117 +#define ma_dcu_mon0__vcfly1_ok__len 1
16118 +#define ma_dcu_mon0__vcfly1_ok__mask 0x02
16119 +#define ma_dcu_mon0__vcfly1_ok__shift 0x01
16120 +#define ma_dcu_mon0__vcfly1_ok__reset 0x00
16121 +//--------------------------------------------------------dcu_mon0.vcfly2_ok---
16122 +// cfly2 protection monitor channel 0.
16123 +#define ma_dcu_mon0__vcfly2_ok__a 97
16124 +#define ma_dcu_mon0__vcfly2_ok__len 1
16125 +#define ma_dcu_mon0__vcfly2_ok__mask 0x04
16126 +#define ma_dcu_mon0__vcfly2_ok__shift 0x02
16127 +#define ma_dcu_mon0__vcfly2_ok__reset 0x00
16128 +//----------------------------------------------------------dcu_mon0.pvdd_ok---
16129 +// dcu0 pvdd monitor
16130 +#define ma_dcu_mon0__pvdd_ok__a 97
16131 +#define ma_dcu_mon0__pvdd_ok__len 1
16132 +#define ma_dcu_mon0__pvdd_ok__mask 0x08
16133 +#define ma_dcu_mon0__pvdd_ok__shift 0x03
16134 +#define ma_dcu_mon0__pvdd_ok__reset 0x00
16135 +//-----------------------------------------------------------dcu_mon0.vdd_ok---
16136 +// dcu0 vdd monitor
16137 +#define ma_dcu_mon0__vdd_ok__a 97
16138 +#define ma_dcu_mon0__vdd_ok__len 1
16139 +#define ma_dcu_mon0__vdd_ok__mask 0x10
16140 +#define ma_dcu_mon0__vdd_ok__shift 0x04
16141 +#define ma_dcu_mon0__vdd_ok__reset 0x00
16142 +//-------------------------------------------------------------dcu_mon0.mute---
16143 +// dcu0 mute monitor
16144 +#define ma_dcu_mon0__mute__a 97
16145 +#define ma_dcu_mon0__mute__len 1
16146 +#define ma_dcu_mon0__mute__mask 0x20
16147 +#define ma_dcu_mon0__mute__shift 0x05
16148 +#define ma_dcu_mon0__mute__reset 0x00
16149 +//------------------------------------------------------------dcu_mon0.m_mon---
16150 +// m sense monitor channel 0
16151 +#define ma_dcu_mon0__m_mon__a 98
16152 +#define ma_dcu_mon0__m_mon__len 8
16153 +#define ma_dcu_mon0__m_mon__mask 0xff
16154 +#define ma_dcu_mon0__m_mon__shift 0x00
16155 +#define ma_dcu_mon0__m_mon__reset 0x00
16156 +//-----------------------------------------------------------dcu_mon1.pm_mon---
16157 +// power mode monitor channel 1
16158 +#define ma_dcu_mon1__pm_mon__a 100
16159 +#define ma_dcu_mon1__pm_mon__len 2
16160 +#define ma_dcu_mon1__pm_mon__mask 0x03
16161 +#define ma_dcu_mon1__pm_mon__shift 0x00
16162 +#define ma_dcu_mon1__pm_mon__reset 0x00
16163 +//-----------------------------------------------------dcu_mon1.freqmode_mon---
16164 +// frequence mode monitor channel 1
16165 +#define ma_dcu_mon1__freqmode_mon__a 100
16166 +#define ma_dcu_mon1__freqmode_mon__len 3
16167 +#define ma_dcu_mon1__freqmode_mon__mask 0x70
16168 +#define ma_dcu_mon1__freqmode_mon__shift 0x04
16169 +#define ma_dcu_mon1__freqmode_mon__reset 0x00
16170 +//-------------------------------------------------------dcu_mon1.pps_passed---
16171 +// dcu1 pps completion indicator
16172 +#define ma_dcu_mon1__pps_passed__a 100
16173 +#define ma_dcu_mon1__pps_passed__len 1
16174 +#define ma_dcu_mon1__pps_passed__mask 0x80
16175 +#define ma_dcu_mon1__pps_passed__shift 0x07
16176 +#define ma_dcu_mon1__pps_passed__reset 0x00
16177 +//----------------------------------------------------------dcu_mon1.ocp_mon---
16178 +// ocp monitor channel 1
16179 +#define ma_dcu_mon1__ocp_mon__a 101
16180 +#define ma_dcu_mon1__ocp_mon__len 1
16181 +#define ma_dcu_mon1__ocp_mon__mask 0x01
16182 +#define ma_dcu_mon1__ocp_mon__shift 0x00
16183 +#define ma_dcu_mon1__ocp_mon__reset 0x00
16184 +//--------------------------------------------------------dcu_mon1.vcfly1_ok---
16185 +// cfly1 protcetion monitor channel 1
16186 +#define ma_dcu_mon1__vcfly1_ok__a 101
16187 +#define ma_dcu_mon1__vcfly1_ok__len 1
16188 +#define ma_dcu_mon1__vcfly1_ok__mask 0x02
16189 +#define ma_dcu_mon1__vcfly1_ok__shift 0x01
16190 +#define ma_dcu_mon1__vcfly1_ok__reset 0x00
16191 +//--------------------------------------------------------dcu_mon1.vcfly2_ok---
16192 +// cfly2 protection monitor channel 1
16193 +#define ma_dcu_mon1__vcfly2_ok__a 101
16194 +#define ma_dcu_mon1__vcfly2_ok__len 1
16195 +#define ma_dcu_mon1__vcfly2_ok__mask 0x04
16196 +#define ma_dcu_mon1__vcfly2_ok__shift 0x02
16197 +#define ma_dcu_mon1__vcfly2_ok__reset 0x00
16198 +//----------------------------------------------------------dcu_mon1.pvdd_ok---
16199 +// dcu1 pvdd monitor
16200 +#define ma_dcu_mon1__pvdd_ok__a 101
16201 +#define ma_dcu_mon1__pvdd_ok__len 1
16202 +#define ma_dcu_mon1__pvdd_ok__mask 0x08
16203 +#define ma_dcu_mon1__pvdd_ok__shift 0x03
16204 +#define ma_dcu_mon1__pvdd_ok__reset 0x00
16205 +//-----------------------------------------------------------dcu_mon1.vdd_ok---
16206 +// dcu1 vdd monitor
16207 +#define ma_dcu_mon1__vdd_ok__a 101
16208 +#define ma_dcu_mon1__vdd_ok__len 1
16209 +#define ma_dcu_mon1__vdd_ok__mask 0x10
16210 +#define ma_dcu_mon1__vdd_ok__shift 0x04
16211 +#define ma_dcu_mon1__vdd_ok__reset 0x00
16212 +//-------------------------------------------------------------dcu_mon1.mute---
16213 +// dcu1 mute monitor
16214 +#define ma_dcu_mon1__mute__a 101
16215 +#define ma_dcu_mon1__mute__len 1
16216 +#define ma_dcu_mon1__mute__mask 0x20
16217 +#define ma_dcu_mon1__mute__shift 0x05
16218 +#define ma_dcu_mon1__mute__reset 0x00
16219 +//------------------------------------------------------------dcu_mon1.m_mon---
16220 +// m sense monitor channel 1
16221 +#define ma_dcu_mon1__m_mon__a 102
16222 +#define ma_dcu_mon1__m_mon__len 8
16223 +#define ma_dcu_mon1__m_mon__mask 0xff
16224 +#define ma_dcu_mon1__m_mon__shift 0x00
16225 +#define ma_dcu_mon1__m_mon__reset 0x00
16226 +//--------------------------------------------------------dcu_mon0.sw_enable---
16227 +// dcu0 switch enable monitor
16228 +#define ma_dcu_mon0__sw_enable__a 104
16229 +#define ma_dcu_mon0__sw_enable__len 1
16230 +#define ma_dcu_mon0__sw_enable__mask 0x40
16231 +#define ma_dcu_mon0__sw_enable__shift 0x06
16232 +#define ma_dcu_mon0__sw_enable__reset 0x00
16233 +//--------------------------------------------------------dcu_mon1.sw_enable---
16234 +// dcu1 switch enable monitor
16235 +#define ma_dcu_mon1__sw_enable__a 104
16236 +#define ma_dcu_mon1__sw_enable__len 1
16237 +#define ma_dcu_mon1__sw_enable__mask 0x80
16238 +#define ma_dcu_mon1__sw_enable__shift 0x07
16239 +#define ma_dcu_mon1__sw_enable__reset 0x00
16240 +//------------------------------------------------------------hvboot0_ok_mon---
16241 +// hvboot0_ok for test/debug
16242 +#define ma_hvboot0_ok_mon__a 105
16243 +#define ma_hvboot0_ok_mon__len 1
16244 +#define ma_hvboot0_ok_mon__mask 0x40
16245 +#define ma_hvboot0_ok_mon__shift 0x06
16246 +#define ma_hvboot0_ok_mon__reset 0x00
16247 +//------------------------------------------------------------hvboot1_ok_mon---
16248 +// hvboot1_ok for test/debug
16249 +#define ma_hvboot1_ok_mon__a 105
16250 +#define ma_hvboot1_ok_mon__len 1
16251 +#define ma_hvboot1_ok_mon__mask 0x80
16252 +#define ma_hvboot1_ok_mon__shift 0x07
16253 +#define ma_hvboot1_ok_mon__reset 0x00
16254 +//-----------------------------------------------------------------error_acc---
16255 +// accumulated errors, at and after triggering
16256 +#define ma_error_acc__a 109
16257 +#define ma_error_acc__len 8
16258 +#define ma_error_acc__mask 0xff
16259 +#define ma_error_acc__shift 0x00
16260 +#define ma_error_acc__reset 0x00
16261 +//-------------------------------------------------------------i2s_data_rate---
16262 +// detected i2s data rate: 00/01/10 = x1/x2/x4
16263 +#define ma_i2s_data_rate__a 116
16264 +#define ma_i2s_data_rate__len 2
16265 +#define ma_i2s_data_rate__mask 0x03
16266 +#define ma_i2s_data_rate__shift 0x00
16267 +#define ma_i2s_data_rate__reset 0x00
16268 +//---------------------------------------------------------audio_in_mode_mon---
16269 +// audio input mode monitor
16270 +#define ma_audio_in_mode_mon__a 116
16271 +#define ma_audio_in_mode_mon__len 3
16272 +#define ma_audio_in_mode_mon__mask 0x1c
16273 +#define ma_audio_in_mode_mon__shift 0x02
16274 +#define ma_audio_in_mode_mon__reset 0x00
16275 +//------------------------------------------------------------------msel_mon---
16276 +// msel[2:0] monitor register
16277 +#define ma_msel_mon__a 117
16278 +#define ma_msel_mon__len 3
16279 +#define ma_msel_mon__mask 0x07
16280 +#define ma_msel_mon__shift 0x00
16281 +#define ma_msel_mon__reset 0x00
16282 +//---------------------------------------------------------------------error---
16283 +// current error flag monitor reg - for app. ctrl.
16284 +#define ma_error__a 124
16285 +#define ma_error__len 8
16286 +#define ma_error__mask 0xff
16287 +#define ma_error__shift 0x00
16288 +#define ma_error__reset 0x00
16289 +//----------------------------------------------------audio_proc_limiter_mon---
16290 +// b7-b4: channel 3-0 limiter active
16291 +#define ma_audio_proc_limiter_mon__a 126
16292 +#define ma_audio_proc_limiter_mon__len 4
16293 +#define ma_audio_proc_limiter_mon__mask 0xf0
16294 +#define ma_audio_proc_limiter_mon__shift 0x04
16295 +#define ma_audio_proc_limiter_mon__reset 0x00
16296 +//-------------------------------------------------------audio_proc_clip_mon---
16297 +// b3-b0: channel 3-0 clipping monitor
16298 +#define ma_audio_proc_clip_mon__a 126
16299 +#define ma_audio_proc_clip_mon__len 4
16300 +#define ma_audio_proc_clip_mon__mask 0x0f
16301 +#define ma_audio_proc_clip_mon__shift 0x00
16302 +#define ma_audio_proc_clip_mon__reset 0x00
16305 +#define SOC_ENUM_ERR(xname, xenum)\
16306 +{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
16307 + .access = SNDRV_CTL_ELEM_ACCESS_READ,\
16308 + .info = snd_soc_info_enum_double,\
16309 + .get = snd_soc_get_enum_double, .put = snd_soc_put_enum_double,\
16310 + .private_value = (unsigned long)&(xenum) }
16312 +static struct i2c_client *i2c;
16314 +struct ma120x0p_priv {
16315 + struct regmap *regmap;
16317 + struct snd_soc_component *component;
16318 + struct gpio_desc *enable_gpio;
16319 + struct gpio_desc *mute_gpio;
16320 + struct gpio_desc *booster_gpio;
16321 + struct gpio_desc *error_gpio;
16324 +static struct ma120x0p_priv *priv_data;
16326 +//Used to share the IRQ number within this file
16327 +static unsigned int irqNumber;
16329 +// Function prototype for the custom IRQ handler function
16330 +static irqreturn_t ma120x0p_irq_handler(int irq, void *data);
16333 +static const char * const limenable_text[] = {"Bypassed", "Enabled"};
16334 +static const char * const limatack_text[] = {"Slow", "Normal", "Fast"};
16335 +static const char * const limrelease_text[] = {"Slow", "Normal", "Fast"};
16337 +static const char * const err_flycap_text[] = {"Ok", "Error"};
16338 +static const char * const err_overcurr_text[] = {"Ok", "Error"};
16339 +static const char * const err_pllerr_text[] = {"Ok", "Error"};
16340 +static const char * const err_pvddunder_text[] = {"Ok", "Error"};
16341 +static const char * const err_overtempw_text[] = {"Ok", "Error"};
16342 +static const char * const err_overtempe_text[] = {"Ok", "Error"};
16343 +static const char * const err_pinlowimp_text[] = {"Ok", "Error"};
16344 +static const char * const err_dcprot_text[] = {"Ok", "Error"};
16346 +static const char * const pwr_mode_prof_text[] = {"PMF0", "PMF1", "PMF2",
16349 +static const struct soc_enum lim_enable_ctrl =
16350 + SOC_ENUM_SINGLE(ma_audio_proc_limiterenable__a,
16351 + ma_audio_proc_limiterenable__shift,
16352 + ma_audio_proc_limiterenable__len + 1,
16354 +static const struct soc_enum limatack_ctrl =
16355 + SOC_ENUM_SINGLE(ma_audio_proc_attack__a,
16356 + ma_audio_proc_attack__shift,
16357 + ma_audio_proc_attack__len + 1,
16359 +static const struct soc_enum limrelease_ctrl =
16360 + SOC_ENUM_SINGLE(ma_audio_proc_release__a,
16361 + ma_audio_proc_release__shift,
16362 + ma_audio_proc_release__len + 1,
16363 + limrelease_text);
16364 +static const struct soc_enum err_flycap_ctrl =
16365 + SOC_ENUM_SINGLE(ma_error__a, 0, 3, err_flycap_text);
16366 +static const struct soc_enum err_overcurr_ctrl =
16367 + SOC_ENUM_SINGLE(ma_error__a, 1, 3, err_overcurr_text);
16368 +static const struct soc_enum err_pllerr_ctrl =
16369 + SOC_ENUM_SINGLE(ma_error__a, 2, 3, err_pllerr_text);
16370 +static const struct soc_enum err_pvddunder_ctrl =
16371 + SOC_ENUM_SINGLE(ma_error__a, 3, 3, err_pvddunder_text);
16372 +static const struct soc_enum err_overtempw_ctrl =
16373 + SOC_ENUM_SINGLE(ma_error__a, 4, 3, err_overtempw_text);
16374 +static const struct soc_enum err_overtempe_ctrl =
16375 + SOC_ENUM_SINGLE(ma_error__a, 5, 3, err_overtempe_text);
16376 +static const struct soc_enum err_pinlowimp_ctrl =
16377 + SOC_ENUM_SINGLE(ma_error__a, 6, 3, err_pinlowimp_text);
16378 +static const struct soc_enum err_dcprot_ctrl =
16379 + SOC_ENUM_SINGLE(ma_error__a, 7, 3, err_dcprot_text);
16380 +static const struct soc_enum pwr_mode_prof_ctrl =
16381 + SOC_ENUM_SINGLE(ma_pmprofile__a, ma_pmprofile__shift, 5,
16382 + pwr_mode_prof_text);
16384 +static const char * const pwr_mode_texts[] = {
16385 + "Dynamic power mode",
16391 +static const int pwr_mode_values[] = {
16398 +static SOC_VALUE_ENUM_SINGLE_DECL(pwr_mode_ctrl,
16399 + ma_pm_man__a, 0, 0x70,
16401 + pwr_mode_values);
16403 +static const DECLARE_TLV_DB_SCALE(ma120x0p_vol_tlv, -14400, 100, 0);
16404 +static const DECLARE_TLV_DB_SCALE(ma120x0p_lim_tlv, -5000, 100, 0);
16405 +static const DECLARE_TLV_DB_SCALE(ma120x0p_lr_tlv, -5000, 100, 0);
16407 +static const struct snd_kcontrol_new ma120x0p_snd_controls[] = {
16409 + SOC_SINGLE_RANGE_TLV("A.Mstr Vol Volume",
16410 + ma_vol_db_master__a, 0, 0x18, 0xa8, 1, ma120x0p_vol_tlv),
16413 + SOC_SINGLE_RANGE_TLV("B.L Vol Volume",
16414 + ma_vol_db_ch0__a, 0, 0x18, 0x4a, 1, ma120x0p_lr_tlv),
16415 + SOC_SINGLE_RANGE_TLV("C.R Vol Volume",
16416 + ma_vol_db_ch1__a, 0, 0x18, 0x4a, 1, ma120x0p_lr_tlv),
16418 + //L-R Limiter Threshold ch0-ch1
16419 + SOC_DOUBLE_R_RANGE_TLV("D.Lim thresh Volume",
16420 + ma_thr_db_ch0__a, ma_thr_db_ch1__a, 0, 0x0e, 0x4a, 1,
16421 + ma120x0p_lim_tlv),
16423 + //Enum Switches/Selectors
16424 + //SOC_ENUM("E.AudioProc Mute", audioproc_mute_ctrl),
16425 + SOC_ENUM("F.Limiter Enable", lim_enable_ctrl),
16426 + SOC_ENUM("G.Limiter Attck", limatack_ctrl),
16427 + SOC_ENUM("H.Limiter Rls", limrelease_ctrl),
16429 + //Enum Error Monitor (read-only)
16430 + SOC_ENUM_ERR("I.Err flycap", err_flycap_ctrl),
16431 + SOC_ENUM_ERR("J.Err overcurr", err_overcurr_ctrl),
16432 + SOC_ENUM_ERR("K.Err pllerr", err_pllerr_ctrl),
16433 + SOC_ENUM_ERR("L.Err pvddunder", err_pvddunder_ctrl),
16434 + SOC_ENUM_ERR("M.Err overtempw", err_overtempw_ctrl),
16435 + SOC_ENUM_ERR("N.Err overtempe", err_overtempe_ctrl),
16436 + SOC_ENUM_ERR("O.Err pinlowimp", err_pinlowimp_ctrl),
16437 + SOC_ENUM_ERR("P.Err dcprot", err_dcprot_ctrl),
16439 + //Power modes profiles
16440 + SOC_ENUM("Q.PM Prof", pwr_mode_prof_ctrl),
16442 + // Power mode selection (Dynamic,1,2,3)
16443 + SOC_ENUM("R.Power Mode", pwr_mode_ctrl),
16447 +static int ma120x0p_hw_params(struct snd_pcm_substream *substream,
16448 + struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
16452 + struct snd_soc_component *component = dai->component;
16454 + priv_data->component = component;
16456 + switch (params_format(params)) {
16457 + case SNDRV_PCM_FORMAT_S16_LE:
16460 + case SNDRV_PCM_FORMAT_S24_LE:
16463 + case SNDRV_PCM_FORMAT_S32_LE:
16467 + dev_err(dai->dev, "Unsupported word length: %u\n",
16468 + params_format(params));
16472 + // set word length
16473 + snd_soc_component_update_bits(component, ma_i2s_framesize__a,
16474 + ma_i2s_framesize__mask, blen);
16479 +static int ma120x0p_mute_stream(struct snd_soc_dai *dai, int mute, int stream)
16483 + struct ma120x0p_priv *ma120x0p;
16485 + struct snd_soc_component *component = dai->component;
16487 + ma120x0p = snd_soc_component_get_drvdata(component);
16494 + gpiod_set_value_cansleep(priv_data->mute_gpio, val);
16499 +static const struct snd_soc_dai_ops ma120x0p_dai_ops = {
16500 + .hw_params = ma120x0p_hw_params,
16501 + .mute_stream = ma120x0p_mute_stream,
16504 +static struct snd_soc_dai_driver ma120x0p_dai = {
16505 + .name = "ma120x0p-amp",
16507 + .stream_name = "Playback",
16508 + .channels_min = 2,
16509 + .channels_max = 2,
16510 + .rates = SNDRV_PCM_RATE_CONTINUOUS,
16511 + .rate_min = 44100,
16512 + .rate_max = 192000,
16513 + .formats = SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE
16515 + .ops = &ma120x0p_dai_ops,
16519 +static int ma120x0p_clear_err(struct snd_soc_component *component)
16523 + struct ma120x0p_priv *ma120x0p;
16525 + ma120x0p = snd_soc_component_get_drvdata(component);
16527 + ret = snd_soc_component_update_bits(component,
16528 + ma_eh_clear__a, ma_eh_clear__mask, 0x00);
16532 + ret = snd_soc_component_update_bits(component,
16533 + ma_eh_clear__a, ma_eh_clear__mask, 0x04);
16537 + ret = snd_soc_component_update_bits(component,
16538 + ma_eh_clear__a, ma_eh_clear__mask, 0x00);
16545 +static void ma120x0p_remove(struct snd_soc_component *component)
16547 + struct ma120x0p_priv *ma120x0p;
16549 + ma120x0p = snd_soc_component_get_drvdata(component);
16552 +static int ma120x0p_probe(struct snd_soc_component *component)
16554 + struct ma120x0p_priv *ma120x0p;
16558 + i2c = container_of(component->dev, struct i2c_client, dev);
16560 + ma120x0p = snd_soc_component_get_drvdata(component);
16563 + ma120x0p_clear_err(component);
16567 + // set serial audio format I2S and enable audio processor
16568 + ret = snd_soc_component_write(component, ma_i2s_format__a, 0x08);
16572 + // Enable audio limiter
16573 + ret = snd_soc_component_update_bits(component,
16574 + ma_audio_proc_limiterenable__a,
16575 + ma_audio_proc_limiterenable__mask, 0x40);
16579 + // Set lim attack to fast
16580 + ret = snd_soc_component_update_bits(component,
16581 + ma_audio_proc_attack__a, ma_audio_proc_attack__mask, 0x80);
16585 + // Set lim attack to low
16586 + ret = snd_soc_component_update_bits(component,
16587 + ma_audio_proc_release__a, ma_audio_proc_release__mask, 0x00);
16591 + // set volume to 0dB
16592 + ret = snd_soc_component_write(component, ma_vol_db_master__a, 0x18);
16596 + // set ch0 lim thresh to -15dB
16597 + ret = snd_soc_component_write(component, ma_thr_db_ch0__a, 0x27);
16601 + // set ch1 lim thresh to -15dB
16602 + ret = snd_soc_component_write(component, ma_thr_db_ch1__a, 0x27);
16606 + //Check for errors
16607 + ret = snd_soc_component_test_bits(component, ma_error_acc__a, 0x00, 0);
16610 + ret = snd_soc_component_test_bits(component, ma_error_acc__a, 0x01, 0);
16613 + ret = snd_soc_component_test_bits(component, ma_error_acc__a, 0x02, 0);
16616 + ret = snd_soc_component_test_bits(component, ma_error_acc__a, 0x08, 0);
16619 + ret = snd_soc_component_test_bits(component, ma_error_acc__a, 0x10, 0);
16622 + ret = snd_soc_component_test_bits(component, ma_error_acc__a, 0x20, 0);
16625 + ret = snd_soc_component_test_bits(component, ma_error_acc__a, 0x40, 0);
16628 + ret = snd_soc_component_test_bits(component, ma_error_acc__a, 0x80, 0);
16635 +static int ma120x0p_set_bias_level(struct snd_soc_component *component,
16636 + enum snd_soc_bias_level level)
16640 + struct ma120x0p_priv *ma120x0p;
16642 + ma120x0p = snd_soc_component_get_drvdata(component);
16645 + case SND_SOC_BIAS_ON:
16648 + case SND_SOC_BIAS_PREPARE:
16651 + case SND_SOC_BIAS_STANDBY:
16652 + ret = gpiod_get_value_cansleep(priv_data->enable_gpio);
16654 + dev_err(component->dev, "Device ma120x0p disabled in STANDBY BIAS: %d\n",
16660 + case SND_SOC_BIAS_OFF:
16667 +static const struct snd_soc_dapm_widget ma120x0p_dapm_widgets[] = {
16668 + SND_SOC_DAPM_OUTPUT("OUT_A"),
16669 + SND_SOC_DAPM_OUTPUT("OUT_B"),
16672 +static const struct snd_soc_dapm_route ma120x0p_dapm_routes[] = {
16673 + { "OUT_B", NULL, "Playback" },
16674 + { "OUT_A", NULL, "Playback" },
16677 +static const struct snd_soc_component_driver ma120x0p_component_driver = {
16678 + .probe = ma120x0p_probe,
16679 + .remove = ma120x0p_remove,
16680 + .set_bias_level = ma120x0p_set_bias_level,
16681 + .dapm_widgets = ma120x0p_dapm_widgets,
16682 + .num_dapm_widgets = ARRAY_SIZE(ma120x0p_dapm_widgets),
16683 + .dapm_routes = ma120x0p_dapm_routes,
16684 + .num_dapm_routes = ARRAY_SIZE(ma120x0p_dapm_routes),
16685 + .controls = ma120x0p_snd_controls,
16686 + .num_controls = ARRAY_SIZE(ma120x0p_snd_controls),
16687 + .use_pmdown_time = 1,
16692 +static const struct reg_default ma120x0p_reg_defaults[] = {
16696 +static bool ma120x0p_reg_volatile(struct device *dev, unsigned int reg)
16699 + case ma_error__a:
16706 +static const struct of_device_id ma120x0p_of_match[] = {
16707 + { .compatible = "ma,ma120x0p", },
16711 +MODULE_DEVICE_TABLE(of, ma120x0p_of_match);
16713 +static struct regmap_config ma120x0p_regmap_config = {
16717 + .max_register = 255,
16718 + .volatile_reg = ma120x0p_reg_volatile,
16720 + .cache_type = REGCACHE_RBTREE,
16721 + .reg_defaults = ma120x0p_reg_defaults,
16722 + .num_reg_defaults = ARRAY_SIZE(ma120x0p_reg_defaults),
16725 +static int ma120x0p_i2c_probe(struct i2c_client *i2c)
16729 + priv_data = devm_kzalloc(&i2c->dev, sizeof(*priv_data), GFP_KERNEL);
16732 + i2c_set_clientdata(i2c, priv_data);
16734 + priv_data->regmap = devm_regmap_init_i2c(i2c, &ma120x0p_regmap_config);
16735 + if (IS_ERR(priv_data->regmap)) {
16736 + ret = PTR_ERR(priv_data->regmap);
16740 + //Startup sequence
16742 + //Make sure the device is muted
16743 + priv_data->mute_gpio = devm_gpiod_get_optional(&i2c->dev, "mute_gp",
16745 + if (IS_ERR(priv_data->mute_gpio)) {
16746 + ret = PTR_ERR(priv_data->mute_gpio);
16747 + dev_err(&i2c->dev, "Failed to get mute gpio line: %d\n", ret);
16752 +// MA120xx0P devices are usually powered by an integrated boost converter.
16753 +// An option GPIO control line is provided to enable the booster properly and
16754 +// in sync with the enable and mute GPIO lines.
16755 + priv_data->booster_gpio = devm_gpiod_get_optional(&i2c->dev,
16756 + "booster_gp", GPIOD_OUT_LOW);
16757 + if (IS_ERR(priv_data->booster_gpio)) {
16758 + ret = PTR_ERR(priv_data->booster_gpio);
16759 + dev_err(&i2c->dev,
16760 + "Failed to get booster enable gpio line: %d\n", ret);
16765 + //Enable booster and wait 200ms until stable PVDD
16766 + gpiod_set_value_cansleep(priv_data->booster_gpio, 1);
16769 + //Enable ma120x0pp
16770 + priv_data->enable_gpio = devm_gpiod_get_optional(&i2c->dev,
16771 + "enable_gp", GPIOD_OUT_LOW);
16772 + if (IS_ERR(priv_data->enable_gpio)) {
16773 + ret = PTR_ERR(priv_data->enable_gpio);
16774 + dev_err(&i2c->dev,
16775 + "Failed to get ma120x0p enable gpio line: %d\n", ret);
16780 + //Optional use of ma120x0pp error line as an interrupt trigger to
16782 + //Get error input gpio ma120x0p
16783 + priv_data->error_gpio = devm_gpiod_get_optional(&i2c->dev,
16784 + "error_gp", GPIOD_IN);
16785 + if (IS_ERR(priv_data->error_gpio)) {
16786 + ret = PTR_ERR(priv_data->error_gpio);
16787 + dev_err(&i2c->dev,
16788 + "Failed to get ma120x0p error gpio line: %d\n", ret);
16792 + if (priv_data->error_gpio != NULL) {
16793 + irqNumber = gpiod_to_irq(priv_data->error_gpio);
16795 + ret = devm_request_threaded_irq(&i2c->dev,
16796 + irqNumber, ma120x0p_irq_handler,
16797 + NULL, IRQF_TRIGGER_FALLING,
16798 + "ma120x0p", priv_data);
16800 + dev_warn(&i2c->dev, "Failed to request IRQ: %d\n",
16804 + ret = devm_snd_soc_register_component(&i2c->dev,
16805 + &ma120x0p_component_driver, &ma120x0p_dai, 1);
16810 +static irqreturn_t ma120x0p_irq_handler(int irq, void *data)
16812 + gpiod_set_value_cansleep(priv_data->mute_gpio, 0);
16813 + gpiod_set_value_cansleep(priv_data->enable_gpio, 1);
16814 + return IRQ_HANDLED;
16817 +static void ma120x0p_i2c_remove(struct i2c_client *i2c)
16819 + snd_soc_unregister_component(&i2c->dev);
16820 + i2c_set_clientdata(i2c, NULL);
16822 + gpiod_set_value_cansleep(priv_data->mute_gpio, 0);
16824 + gpiod_set_value_cansleep(priv_data->enable_gpio, 1);
16826 + gpiod_set_value_cansleep(priv_data->booster_gpio, 0);
16829 + kfree(priv_data);
16832 +static void ma120x0p_i2c_shutdown(struct i2c_client *i2c)
16834 + snd_soc_unregister_component(&i2c->dev);
16835 + i2c_set_clientdata(i2c, NULL);
16837 + gpiod_set_value_cansleep(priv_data->mute_gpio, 0);
16839 + gpiod_set_value_cansleep(priv_data->enable_gpio, 1);
16841 + gpiod_set_value_cansleep(priv_data->booster_gpio, 0);
16844 + kfree(priv_data);
16847 +static const struct i2c_device_id ma120x0p_i2c_id[] = {
16848 + { "ma120x0p", 0 },
16852 +MODULE_DEVICE_TABLE(i2c, ma120x0p_i2c_id);
16854 +static struct i2c_driver ma120x0p_i2c_driver = {
16856 + .name = "ma120x0p",
16857 + .owner = THIS_MODULE,
16858 + .of_match_table = ma120x0p_of_match,
16860 + .probe = ma120x0p_i2c_probe,
16861 + .remove = ma120x0p_i2c_remove,
16862 + .shutdown = ma120x0p_i2c_shutdown,
16863 + .id_table = ma120x0p_i2c_id
16866 +static int __init ma120x0p_modinit(void)
16870 + ret = i2c_add_driver(&ma120x0p_i2c_driver);
16872 + pr_err("Failed to register MA120X0P I2C driver: %d\n", ret);
16877 +module_init(ma120x0p_modinit);
16879 +static void __exit ma120x0p_exit(void)
16881 + i2c_del_driver(&ma120x0p_i2c_driver);
16883 +module_exit(ma120x0p_exit);
16885 +MODULE_AUTHOR("Ariel Muszkat ariel.muszkat@gmail.com>");
16886 +MODULE_DESCRIPTION("ASoC driver for ma120x0p");
16887 +MODULE_LICENSE("GPL v2");
16889 +++ b/sound/soc/codecs/pcm1794a.c
16892 + * Driver for the PCM1794A codec
16894 + * Author: Florian Meier <florian.meier@koalo.de>
16897 + * This program is free software; you can redistribute it and/or
16898 + * modify it under the terms of the GNU General Public License
16899 + * version 2 as published by the Free Software Foundation.
16901 + * This program is distributed in the hope that it will be useful, but
16902 + * WITHOUT ANY WARRANTY; without even the implied warranty of
16903 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16904 + * General Public License for more details.
16908 +#include <linux/init.h>
16909 +#include <linux/module.h>
16910 +#include <linux/platform_device.h>
16912 +#include <sound/soc.h>
16914 +static struct snd_soc_dai_driver pcm1794a_dai = {
16915 + .name = "pcm1794a-hifi",
16917 + .channels_min = 2,
16918 + .channels_max = 2,
16919 + .rates = SNDRV_PCM_RATE_8000_192000,
16920 + .formats = SNDRV_PCM_FMTBIT_S16_LE |
16921 + SNDRV_PCM_FMTBIT_S24_LE
16925 +static struct snd_soc_component_driver soc_component_dev_pcm1794a;
16927 +static int pcm1794a_probe(struct platform_device *pdev)
16929 + return snd_soc_register_component(&pdev->dev, &soc_component_dev_pcm1794a,
16930 + &pcm1794a_dai, 1);
16933 +static int pcm1794a_remove(struct platform_device *pdev)
16935 + snd_soc_unregister_component(&pdev->dev);
16939 +static const struct of_device_id pcm1794a_of_match[] = {
16940 + { .compatible = "ti,pcm1794a", },
16943 +MODULE_DEVICE_TABLE(of, pcm1794a_of_match);
16945 +static struct platform_driver pcm1794a_component_driver = {
16946 + .probe = pcm1794a_probe,
16947 + .remove = pcm1794a_remove,
16949 + .name = "pcm1794a-codec",
16950 + .owner = THIS_MODULE,
16951 + .of_match_table = of_match_ptr(pcm1794a_of_match),
16955 +module_platform_driver(pcm1794a_component_driver);
16957 +MODULE_DESCRIPTION("ASoC PCM1794A codec driver");
16958 +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
16959 +MODULE_LICENSE("GPL v2");
16960 --- a/sound/soc/codecs/pcm512x.c
16961 +++ b/sound/soc/codecs/pcm512x.c
16962 @@ -536,7 +536,7 @@ static unsigned long pcm512x_ncp_target(
16964 static const u32 pcm512x_dai_rates[] = {
16965 8000, 11025, 16000, 22050, 32000, 44100, 48000, 64000,
16966 - 88200, 96000, 176400, 192000, 384000,
16967 + 88200, 96000, 176400, 192000, 352800, 384000,
16970 static const struct snd_pcm_hw_constraint_list constraints_slave = {
16972 +++ b/sound/soc/codecs/tas5713.c
16975 + * ASoC Driver for TAS5713
16977 + * Author: Sebastian Eickhoff <basti.eickhoff@googlemail.com>
16980 + * This program is free software; you can redistribute it and/or
16981 + * modify it under the terms of the GNU General Public License
16982 + * version 2 as published by the Free Software Foundation.
16984 + * This program is distributed in the hope that it will be useful, but
16985 + * WITHOUT ANY WARRANTY; without even the implied warranty of
16986 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16987 + * General Public License for more details.
16990 +#include <linux/module.h>
16991 +#include <linux/moduleparam.h>
16992 +#include <linux/init.h>
16993 +#include <linux/delay.h>
16994 +#include <linux/pm.h>
16995 +#include <linux/i2c.h>
16996 +#include <linux/of_device.h>
16997 +#include <linux/spi/spi.h>
16998 +#include <linux/regmap.h>
16999 +#include <linux/regulator/consumer.h>
17000 +#include <linux/slab.h>
17001 +#include <sound/core.h>
17002 +#include <sound/pcm.h>
17003 +#include <sound/pcm_params.h>
17004 +#include <sound/soc.h>
17005 +#include <sound/initval.h>
17006 +#include <sound/tlv.h>
17008 +#include <linux/kernel.h>
17009 +#include <linux/string.h>
17010 +#include <linux/fs.h>
17011 +#include <asm/uaccess.h>
17013 +#include "tas5713.h"
17016 +static struct i2c_client *i2c;
17018 +struct tas5713_priv {
17019 + struct regmap *regmap;
17021 + struct snd_soc_component *component;
17024 +static struct tas5713_priv *priv_data;
17030 + * _ _ ___ _ ___ _ _
17031 + * /_\ | | / __| /_\ / __|___ _ _| |_ _ _ ___| |___
17032 + * / _ \| |__\__ \/ _ \ | (__/ _ \ ' \ _| '_/ _ \ (_-<
17033 + * /_/ \_\____|___/_/ \_\ \___\___/_||_\__|_| \___/_/__/
17037 +static const DECLARE_TLV_DB_SCALE(tas5713_vol_tlv, -10000, 50, 1);
17040 +static const struct snd_kcontrol_new tas5713_snd_controls[] = {
17041 + SOC_SINGLE_TLV ("Master" , TAS5713_VOL_MASTER, 0, 248, 1, tas5713_vol_tlv),
17042 + SOC_DOUBLE_R_TLV("Channels" , TAS5713_VOL_CH1, TAS5713_VOL_CH2, 0, 248, 1, tas5713_vol_tlv)
17049 + * __ __ _ _ ___ _
17050 + * | \/ |__ _ __| |_ (_)_ _ ___ | \ _ _(_)_ _____ _ _
17051 + * | |\/| / _` / _| ' \| | ' \/ -_) | |) | '_| \ V / -_) '_|
17052 + * |_| |_\__,_\__|_||_|_|_||_\___| |___/|_| |_|\_/\___|_|
17056 +static int tas5713_hw_params(struct snd_pcm_substream *substream,
17057 + struct snd_pcm_hw_params *params,
17058 + struct snd_soc_dai *dai)
17062 + struct snd_soc_component *component = dai->component;
17063 + priv_data->component = component;
17065 + switch (params_format(params)) {
17066 + case SNDRV_PCM_FORMAT_S16_LE:
17069 + case SNDRV_PCM_FORMAT_S20_3LE:
17072 + case SNDRV_PCM_FORMAT_S24_LE:
17075 + case SNDRV_PCM_FORMAT_S32_LE:
17079 + dev_err(dai->dev, "Unsupported word length: %u\n",
17080 + params_format(params));
17084 + // set word length
17085 + snd_soc_component_update_bits(component, TAS5713_SERIAL_DATA_INTERFACE, 0x7, blen);
17091 +static int tas5713_mute_stream(struct snd_soc_dai *dai, int mute, int stream)
17093 + unsigned int val = 0;
17095 + struct tas5713_priv *tas5713;
17096 + struct snd_soc_component *component = dai->component;
17097 + tas5713 = snd_soc_component_get_drvdata(component);
17100 + val = TAS5713_SOFT_MUTE_ALL;
17103 + return regmap_write(tas5713->regmap, TAS5713_SOFT_MUTE, val);
17107 +static const struct snd_soc_dai_ops tas5713_dai_ops = {
17108 + .hw_params = tas5713_hw_params,
17109 + .mute_stream = tas5713_mute_stream,
17113 +static struct snd_soc_dai_driver tas5713_dai = {
17114 + .name = "tas5713-hifi",
17116 + .stream_name = "Playback",
17117 + .channels_min = 2,
17118 + .channels_max = 2,
17119 + .rates = SNDRV_PCM_RATE_8000_48000,
17120 + .formats = (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE ),
17122 + .ops = &tas5713_dai_ops,
17130 + * / __|___ __| |___ __ | \ _ _(_)_ _____ _ _
17131 + * | (__/ _ \/ _` / -_) _| | |) | '_| \ V / -_) '_|
17132 + * \___\___/\__,_\___\__| |___/|_| |_|\_/\___|_|
17136 +static void tas5713_remove(struct snd_soc_component *component)
17138 + struct tas5713_priv *tas5713;
17140 + tas5713 = snd_soc_component_get_drvdata(component);
17144 +static int tas5713_probe(struct snd_soc_component *component)
17146 + struct tas5713_priv *tas5713;
17149 + i2c = container_of(component->dev, struct i2c_client, dev);
17151 + tas5713 = snd_soc_component_get_drvdata(component);
17154 + ret = snd_soc_component_write(component, TAS5713_ERROR_STATUS, 0x00);
17155 + if (ret < 0) return ret;
17157 + // Trim oscillator
17158 + ret = snd_soc_component_write(component, TAS5713_OSC_TRIM, 0x00);
17159 + if (ret < 0) return ret;
17163 + ret = snd_soc_component_write(component, TAS5713_ERROR_STATUS, 0x00);
17164 + if (ret < 0) return ret;
17167 + ret = snd_soc_component_write(component, TAS5713_SERIAL_DATA_INTERFACE, 0x05);
17168 + if (ret < 0) return ret;
17171 + ret = snd_soc_component_write(component, TAS5713_SYSTEM_CTRL2, 0x00);
17172 + if (ret < 0) return ret;
17173 + ret = snd_soc_component_write(component, TAS5713_SOFT_MUTE, 0x00);
17174 + if (ret < 0) return ret;
17176 + // Set volume to 0db
17177 + ret = snd_soc_component_write(component, TAS5713_VOL_MASTER, 0x00);
17178 + if (ret < 0) return ret;
17180 + // Now start programming the default initialization sequence
17181 + for (i = 0; i < ARRAY_SIZE(tas5713_init_sequence); ++i) {
17182 + ret = i2c_master_send(i2c,
17183 + tas5713_init_sequence[i].data,
17184 + tas5713_init_sequence[i].size);
17186 + printk(KERN_INFO "TAS5713 CODEC PROBE: InitSeq returns: %d\n", ret);
17191 + ret = snd_soc_component_write(component, TAS5713_SYSTEM_CTRL2, 0x00);
17192 + if (ret < 0) return ret;
17198 +static struct snd_soc_component_driver soc_codec_dev_tas5713 = {
17199 + .probe = tas5713_probe,
17200 + .remove = tas5713_remove,
17201 + .controls = tas5713_snd_controls,
17202 + .num_controls = ARRAY_SIZE(tas5713_snd_controls),
17209 + * ___ ___ ___ ___ _
17210 + * |_ _|_ ) __| | \ _ _(_)_ _____ _ _
17211 + * | | / / (__ | |) | '_| \ V / -_) '_|
17212 + * |___/___\___| |___/|_| |_|\_/\___|_|
17216 +static const struct reg_default tas5713_reg_defaults[] = {
17217 + { 0x07 ,0x80 }, // R7 - VOL_MASTER - -40dB
17218 + { 0x08 , 30 }, // R8 - VOL_CH1 - 0dB
17219 + { 0x09 , 30 }, // R9 - VOL_CH2 - 0dB
17220 + { 0x0A ,0x80 }, // R10 - VOL_HEADPHONE - -40dB
17224 +static bool tas5713_reg_volatile(struct device *dev, unsigned int reg)
17227 + case TAS5713_DEVICE_ID:
17228 + case TAS5713_ERROR_STATUS:
17229 + case TAS5713_CLOCK_CTRL:
17237 +static const struct of_device_id tas5713_of_match[] = {
17238 + { .compatible = "ti,tas5713", },
17241 +MODULE_DEVICE_TABLE(of, tas5713_of_match);
17244 +static struct regmap_config tas5713_regmap_config = {
17248 + .max_register = TAS5713_MAX_REGISTER,
17249 + .volatile_reg = tas5713_reg_volatile,
17251 + .cache_type = REGCACHE_RBTREE,
17252 + .reg_defaults = tas5713_reg_defaults,
17253 + .num_reg_defaults = ARRAY_SIZE(tas5713_reg_defaults),
17257 +static int tas5713_i2c_probe(struct i2c_client *i2c)
17261 + priv_data = devm_kzalloc(&i2c->dev, sizeof *priv_data, GFP_KERNEL);
17265 + priv_data->regmap = devm_regmap_init_i2c(i2c, &tas5713_regmap_config);
17266 + if (IS_ERR(priv_data->regmap)) {
17267 + ret = PTR_ERR(priv_data->regmap);
17271 + i2c_set_clientdata(i2c, priv_data);
17273 + ret = snd_soc_register_component(&i2c->dev,
17274 + &soc_codec_dev_tas5713, &tas5713_dai, 1);
17280 +static void tas5713_i2c_remove(struct i2c_client *i2c)
17282 + snd_soc_unregister_component(&i2c->dev);
17283 + i2c_set_clientdata(i2c, NULL);
17285 + kfree(priv_data);
17289 +static const struct i2c_device_id tas5713_i2c_id[] = {
17290 + { "tas5713", 0 },
17294 +MODULE_DEVICE_TABLE(i2c, tas5713_i2c_id);
17297 +static struct i2c_driver tas5713_i2c_driver = {
17299 + .name = "tas5713",
17300 + .owner = THIS_MODULE,
17301 + .of_match_table = tas5713_of_match,
17303 + .probe = tas5713_i2c_probe,
17304 + .remove = tas5713_i2c_remove,
17305 + .id_table = tas5713_i2c_id
17309 +static int __init tas5713_modinit(void)
17313 + ret = i2c_add_driver(&tas5713_i2c_driver);
17315 + printk(KERN_ERR "Failed to register tas5713 I2C driver: %d\n",
17321 +module_init(tas5713_modinit);
17324 +static void __exit tas5713_exit(void)
17326 + i2c_del_driver(&tas5713_i2c_driver);
17328 +module_exit(tas5713_exit);
17331 +MODULE_AUTHOR("Sebastian Eickhoff <basti.eickhoff@googlemail.com>");
17332 +MODULE_DESCRIPTION("ASoC driver for TAS5713");
17333 +MODULE_LICENSE("GPL v2");
17335 +++ b/sound/soc/codecs/tas5713.h
17338 + * ASoC Driver for TAS5713
17340 + * Author: Sebastian Eickhoff <basti.eickhoff@googlemail.com>
17343 + * This program is free software; you can redistribute it and/or
17344 + * modify it under the terms of the GNU General Public License
17345 + * version 2 as published by the Free Software Foundation.
17347 + * This program is distributed in the hope that it will be useful, but
17348 + * WITHOUT ANY WARRANTY; without even the implied warranty of
17349 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17350 + * General Public License for more details.
17353 +#ifndef _TAS5713_H
17354 +#define _TAS5713_H
17357 +// TAS5713 I2C-bus register addresses
17359 +#define TAS5713_CLOCK_CTRL 0x00
17360 +#define TAS5713_DEVICE_ID 0x01
17361 +#define TAS5713_ERROR_STATUS 0x02
17362 +#define TAS5713_SYSTEM_CTRL1 0x03
17363 +#define TAS5713_SERIAL_DATA_INTERFACE 0x04
17364 +#define TAS5713_SYSTEM_CTRL2 0x05
17365 +#define TAS5713_SOFT_MUTE 0x06
17366 +#define TAS5713_VOL_MASTER 0x07
17367 +#define TAS5713_VOL_CH1 0x08
17368 +#define TAS5713_VOL_CH2 0x09
17369 +#define TAS5713_VOL_HEADPHONE 0x0A
17370 +#define TAS5713_VOL_CONFIG 0x0E
17371 +#define TAS5713_MODULATION_LIMIT 0x10
17372 +#define TAS5713_IC_DLY_CH1 0x11
17373 +#define TAS5713_IC_DLY_CH2 0x12
17374 +#define TAS5713_IC_DLY_CH3 0x13
17375 +#define TAS5713_IC_DLY_CH4 0x14
17377 +#define TAS5713_START_STOP_PERIOD 0x1A
17378 +#define TAS5713_OSC_TRIM 0x1B
17379 +#define TAS5713_BKND_ERR 0x1C
17381 +#define TAS5713_INPUT_MUX 0x20
17382 +#define TAS5713_SRC_SELECT_CH4 0x21
17383 +#define TAS5713_PWM_MUX 0x25
17385 +#define TAS5713_CH1_BQ0 0x29
17386 +#define TAS5713_CH1_BQ1 0x2A
17387 +#define TAS5713_CH1_BQ2 0x2B
17388 +#define TAS5713_CH1_BQ3 0x2C
17389 +#define TAS5713_CH1_BQ4 0x2D
17390 +#define TAS5713_CH1_BQ5 0x2E
17391 +#define TAS5713_CH1_BQ6 0x2F
17392 +#define TAS5713_CH1_BQ7 0x58
17393 +#define TAS5713_CH1_BQ8 0x59
17395 +#define TAS5713_CH2_BQ0 0x30
17396 +#define TAS5713_CH2_BQ1 0x31
17397 +#define TAS5713_CH2_BQ2 0x32
17398 +#define TAS5713_CH2_BQ3 0x33
17399 +#define TAS5713_CH2_BQ4 0x34
17400 +#define TAS5713_CH2_BQ5 0x35
17401 +#define TAS5713_CH2_BQ6 0x36
17402 +#define TAS5713_CH2_BQ7 0x5C
17403 +#define TAS5713_CH2_BQ8 0x5D
17405 +#define TAS5713_CH4_BQ0 0x5A
17406 +#define TAS5713_CH4_BQ1 0x5B
17407 +#define TAS5713_CH3_BQ0 0x5E
17408 +#define TAS5713_CH3_BQ1 0x5F
17410 +#define TAS5713_DRC1_SOFTENING_FILTER_ALPHA_OMEGA 0x3B
17411 +#define TAS5713_DRC1_ATTACK_RELEASE_RATE 0x3C
17412 +#define TAS5713_DRC2_SOFTENING_FILTER_ALPHA_OMEGA 0x3E
17413 +#define TAS5713_DRC2_ATTACK_RELEASE_RATE 0x3F
17414 +#define TAS5713_DRC1_ATTACK_RELEASE_THRES 0x40
17415 +#define TAS5713_DRC2_ATTACK_RELEASE_THRES 0x43
17416 +#define TAS5713_DRC_CTRL 0x46
17418 +#define TAS5713_BANK_SW_CTRL 0x50
17419 +#define TAS5713_CH1_OUTPUT_MIXER 0x51
17420 +#define TAS5713_CH2_OUTPUT_MIXER 0x52
17421 +#define TAS5713_CH1_INPUT_MIXER 0x53
17422 +#define TAS5713_CH2_INPUT_MIXER 0x54
17423 +#define TAS5713_OUTPUT_POST_SCALE 0x56
17424 +#define TAS5713_OUTPUT_PRESCALE 0x57
17426 +#define TAS5713_IDF_POST_SCALE 0x62
17428 +#define TAS5713_CH1_INLINE_MIXER 0x70
17429 +#define TAS5713_CH1_INLINE_DRC_EN_MIXER 0x71
17430 +#define TAS5713_CH1_R_CHANNEL_MIXER 0x72
17431 +#define TAS5713_CH1_L_CHANNEL_MIXER 0x73
17432 +#define TAS5713_CH2_INLINE_MIXER 0x74
17433 +#define TAS5713_CH2_INLINE_DRC_EN_MIXER 0x75
17434 +#define TAS5713_CH2_L_CHANNEL_MIXER 0x76
17435 +#define TAS5713_CH2_R_CHANNEL_MIXER 0x77
17437 +#define TAS5713_UPDATE_DEV_ADDR_KEY 0xF8
17438 +#define TAS5713_UPDATE_DEV_ADDR_REG 0xF9
17440 +#define TAS5713_REGISTER_COUNT 0x46
17441 +#define TAS5713_MAX_REGISTER 0xF9
17444 +// Bitmasks for registers
17445 +#define TAS5713_SOFT_MUTE_ALL 0x07
17449 +struct tas5713_init_command {
17451 + const char *const data;
17454 +static const struct tas5713_init_command tas5713_init_sequence[] = {
17456 + // Trim oscillator
17457 + { .size = 2, .data = "\x1B\x00" },
17458 + // System control register 1 (0x03): block DC
17459 + { .size = 2, .data = "\x03\x80" },
17460 + // Mute everything
17461 + { .size = 2, .data = "\x05\x40" },
17462 + // Modulation limit register (0x10): 97.7%
17463 + { .size = 2, .data = "\x10\x02" },
17464 + // Interchannel delay registers
17465 + // (0x11, 0x12, 0x13, and 0x14): BD mode
17466 + { .size = 2, .data = "\x11\xB8" },
17467 + { .size = 2, .data = "\x12\x60" },
17468 + { .size = 2, .data = "\x13\xA0" },
17469 + { .size = 2, .data = "\x14\x48" },
17470 + // PWM shutdown group register (0x19): no shutdown
17471 + { .size = 2, .data = "\x19\x00" },
17472 + // Input multiplexer register (0x20): BD mode
17473 + { .size = 2, .data = "\x20\x00\x89\x77\x72" },
17474 + // PWM output mux register (0x25)
17475 + // Channel 1 --> OUTA, channel 1 neg --> OUTB
17476 + // Channel 2 --> OUTC, channel 2 neg --> OUTD
17477 + { .size = 5, .data = "\x25\x01\x02\x13\x45" },
17478 + // DRC control (0x46): DRC off
17479 + { .size = 5, .data = "\x46\x00\x00\x00\x00" },
17480 + // BKND_ERR register (0x1C): 299ms reset period
17481 + { .size = 2, .data = "\x1C\x07" },
17482 + // Mute channel 3
17483 + { .size = 2, .data = "\x0A\xFF" },
17484 + // Volume configuration register (0x0E): volume slew 512 steps
17485 + { .size = 2, .data = "\x0E\x90" },
17486 + // Clock control register (0x00): 44/48kHz, MCLK=64xfs
17487 + { .size = 2, .data = "\x00\x60" },
17488 + // Bank switch and eq control (0x50): no bank switching
17489 + { .size = 5, .data = "\x50\x00\x00\x00\x00" },
17490 + // Volume registers (0x07, 0x08, 0x09, 0x0A)
17491 + { .size = 2, .data = "\x07\x20" },
17492 + { .size = 2, .data = "\x08\x30" },
17493 + { .size = 2, .data = "\x09\x30" },
17494 + { .size = 2, .data = "\x0A\xFF" },
17495 + // 0x72, 0x73, 0x76, 0x77 input mixer:
17496 + // no intermix between channels
17497 + { .size = 5, .data = "\x72\x00\x00\x00\x00" },
17498 + { .size = 5, .data = "\x73\x00\x80\x00\x00" },
17499 + { .size = 5, .data = "\x76\x00\x00\x00\x00" },
17500 + { .size = 5, .data = "\x77\x00\x80\x00\x00" },
17501 + // 0x70, 0x71, 0x74, 0x75 inline DRC mixer:
17502 + // no inline DRC inmix
17503 + { .size = 5, .data = "\x70\x00\x80\x00\x00" },
17504 + { .size = 5, .data = "\x71\x00\x00\x00\x00" },
17505 + { .size = 5, .data = "\x74\x00\x80\x00\x00" },
17506 + { .size = 5, .data = "\x75\x00\x00\x00\x00" },
17507 + // 0x56, 0x57 Output scale
17508 + { .size = 5, .data = "\x56\x00\x80\x00\x00" },
17509 + { .size = 5, .data = "\x57\x00\x02\x00\x00" },
17511 + { .size = 9, .data = "\x3B\x00\x08\x00\x00\x00\x78\x00\x00" },
17512 + { .size = 9, .data = "\x3C\x00\x00\x01\x00\xFF\xFF\xFF\x00" },
17513 + { .size = 9, .data = "\x3E\x00\x08\x00\x00\x00\x78\x00\x00" },
17514 + { .size = 9, .data = "\x3F\x00\x00\x01\x00\xFF\xFF\xFF\x00" },
17515 + { .size = 9, .data = "\x40\x00\x00\x01\x00\xFF\xFF\xFF\x00" },
17516 + { .size = 9, .data = "\x43\x00\x00\x01\x00\xFF\xFF\xFF\x00" },
17517 + // 0x51, 0x52: output mixer
17518 + { .size = 9, .data = "\x51\x00\x80\x00\x00\x00\x00\x00\x00" },
17519 + { .size = 9, .data = "\x52\x00\x80\x00\x00\x00\x00\x00\x00" },
17521 + { .size = 21, .data = "\x29\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
17522 + { .size = 21, .data = "\x2A\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
17523 + { .size = 21, .data = "\x2B\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
17524 + { .size = 21, .data = "\x2C\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
17525 + { .size = 21, .data = "\x2D\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
17526 + { .size = 21, .data = "\x2E\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
17527 + { .size = 21, .data = "\x2F\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
17528 + { .size = 21, .data = "\x30\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
17529 + { .size = 21, .data = "\x31\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
17530 + { .size = 21, .data = "\x32\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
17531 + { .size = 21, .data = "\x33\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
17532 + { .size = 21, .data = "\x34\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
17533 + { .size = 21, .data = "\x35\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
17534 + { .size = 21, .data = "\x36\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
17535 + { .size = 21, .data = "\x58\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
17536 + { .size = 21, .data = "\x59\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
17537 + { .size = 21, .data = "\x5C\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
17538 + { .size = 21, .data = "\x5D\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
17539 + { .size = 21, .data = "\x5E\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
17540 + { .size = 21, .data = "\x5F\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
17541 + { .size = 21, .data = "\x5A\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
17542 + { .size = 21, .data = "\x5B\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
17546 +#endif /* _TAS5713_H */
17547 --- a/sound/soc/soc-core.c
17548 +++ b/sound/soc/soc-core.c
17549 @@ -1316,7 +1316,15 @@ int snd_soc_runtime_set_dai_fmt(struct s
17552 for_each_rtd_codec_dais(rtd, i, codec_dai) {
17553 - ret = snd_soc_dai_set_fmt(codec_dai, dai_fmt);
17554 + unsigned int codec_dai_fmt = dai_fmt;
17556 + // there can only be one master when using multiple codecs
17557 + if (i && (codec_dai_fmt & SND_SOC_DAIFMT_MASTER_MASK)) {
17558 + codec_dai_fmt &= ~SND_SOC_DAIFMT_MASTER_MASK;
17559 + codec_dai_fmt |= SND_SOC_DAIFMT_CBS_CFS;
17562 + ret = snd_soc_dai_set_fmt(codec_dai, codec_dai_fmt);
17563 if (ret != 0 && ret != -ENOTSUPP)
17566 --- a/sound/usb/card.c
17567 +++ b/sound/usb/card.c
17568 @@ -863,8 +863,14 @@ static int usb_audio_probe(struct usb_in
17569 if (ignore_ctl_error)
17570 chip->quirk_flags |= QUIRK_FLAG_IGNORE_CTL_ERROR;
17572 - if (chip->quirk_flags & QUIRK_FLAG_DISABLE_AUTOSUSPEND)
17573 + if (chip->quirk_flags & QUIRK_FLAG_DISABLE_AUTOSUSPEND) {
17575 + * Grab the interface, because on a webcam uvcvideo may race
17576 + * with snd-usb-audio during probe and re-enable autosuspend.
17578 + usb_autopm_get_interface(intf);
17579 usb_disable_autosuspend(interface_to_usbdev(intf));
17583 * For devices with more than one control interface, we assume the
17584 --- a/sound/usb/quirks.c
17585 +++ b/sound/usb/quirks.c
17586 @@ -2212,6 +2212,8 @@ static const struct usb_audio_quirk_flag
17587 QUIRK_FLAG_ALIGN_TRANSFER),
17588 DEVICE_FLG(0x534d, 0x2109, /* MacroSilicon MS2109 */
17589 QUIRK_FLAG_ALIGN_TRANSFER),
17590 + DEVICE_FLG(0x09da, 0x2695, /* A4Tech FHD 1080p webcam */
17591 + QUIRK_FLAG_DISABLE_AUTOSUSPEND | QUIRK_FLAG_GET_SAMPLE_RATE),
17593 /* Vendor matches */
17594 VENDOR_FLG(0x045e, /* MS Lifecam */