You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
freifunkist-firmware/target/linux/brcm2708/patches-4.14/950-0075-New-AudioInjector....

247 lines
8.8 KiB

brcm2708: add kernel 4.14 support Patch generation process: - rebase rpi/rpi-4.14.y on v4.14.89 from linux-stable - git format-patch v4.14.89 Patches skipped during rebase: - lan78xx: Read MAC address from DT if present - lan78xx: Enable LEDs and auto-negotiation - Revert "softirq: Let ksoftirqd do its job" - sc16is7xx: Fix for multi-channel stall - lan78xx: Ignore DT MAC address if already valid - lan78xx: Simple patch to prevent some crashes - tcp_write_queue_purge clears all the SKBs in the write queue - Revert "lan78xx: Simple patch to prevent some crashes" - lan78xx: Connect phy early - Arm: mm: ftrace: Only set text back to ro after kernel has been marked ro - Revert "Revert "softirq: Let ksoftirqd do its job"" - ASoC: cs4265: SOC_SINGLE register value error fix - Revert "ASoC: cs4265: SOC_SINGLE register value error fix" - Revert "net: pskb_trim_rcsum() and CHECKSUM_COMPLETE are friends" - Revert "Revert "net: pskb_trim_rcsum() and CHECKSUM_COMPLETE are friends"" Patches dropped after rebase: - net: Add non-mainline source for rtl8192cu wlan - net: Fix rtl8192cu build errors on other platforms - brcm: adds support for BCM43341 wifi - brcmfmac: Mute expected startup 'errors' - ARM64: Fix build break for RTL8187/RTL8192CU wifi - ARM64: Enable RTL8187/RTL8192CU wifi in build config - This is the driver for Sony CXD2880 DVB-T2/T tuner + demodulator - brcmfmac: add CLM download support - brcmfmac: request_firmware_direct is quieter - Sets the BCDC priority to constant 0 - brcmfmac: Disable ARP offloading when promiscuous - brcmfmac: Avoid possible out-of-bounds read - brcmfmac: Delete redundant length check - net: rtl8192cu: Normalize indentation - net: rtl8192cu: Fix implicit fallthrough warnings - Revert "Sets the BCDC priority to constant 0" - media: cxd2880: Bump to match 4.18.y version - media: cxd2880-spi: Bump to match 4.18.y version - Revert "mm: alloc_contig: re-allow CMA to compact FS pages" - Revert "Revert "mm: alloc_contig: re-allow CMA to compact FS pages"" - cxd2880: CXD2880_SPI_DRV should select DVB_CXD2880 with MEDIA_SUBDRV_AUTOSELECT - 950-0421-HID-hid-bigbenff-driver-for-BigBen-Interactive-PS3OF.patch - 950-0453-Add-hid-bigbenff-to-list-of-have_special_driver-for-.patch Make I2C built-in instead of modular as in upstream defconfig; also the easiest way to get MFD_ARIZONA enabled, which is required by kmod-sound-soc-rpi-cirrus. Add missing compatible strings from 4.9/960-add-rasbperrypi-compatible.patch, using upstream names for compute modules. Add extra patch to enable the LEDs on lan78xx. Compile-tested: bcm2708, bcm2709, bcm2710 (with CONFIG_ALL_KMODS=y) Runtime-tested: bcm2708, bcm2710 Signed-off-by: Stijn Tintel <stijn@linux-ipv6.be>
6 years ago
From ef421b47c67af36f31730fe5e6088cfb672369ea Mon Sep 17 00:00:00 2001
From: Matt Flax <flatmax@flatmax.org>
Date: Mon, 16 May 2016 21:36:31 +1000
Subject: [PATCH 075/454] New AudioInjector.net Pi soundcard with low jitter
audio in and out.
Contains the sound/soc/bcm ALSA machine driver and necessary alterations to the Kconfig and Makefile.
Adds the dts overlay and updates the Makefile and README.
Updates the relevant defconfig files to enable building for the Raspberry Pi.
Thanks to Phil Elwell (pelwell) for the review, simple-card concepts and discussion. Thanks to Clive Messer for overlay naming suggestions.
Added support for headphones, microphone and bclk_ratio settings.
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.
---
sound/soc/bcm/Kconfig | 7 +
sound/soc/bcm/Makefile | 3 +
sound/soc/bcm/audioinjector-pi-soundcard.c | 193 +++++++++++++++++++++
3 files changed, 203 insertions(+)
create mode 100644 sound/soc/bcm/audioinjector-pi-soundcard.c
--- a/sound/soc/bcm/Kconfig
+++ b/sound/soc/bcm/Kconfig
@@ -95,3 +95,10 @@ config SND_BCM2708_SOC_ADAU1977_ADC
select SND_SOC_ADAU1977_I2C
help
Say Y or M if you want to add support for ADAU1977 ADC.
+
+config SND_AUDIOINJECTOR_PI_SOUNDCARD
+ tristate "Support for audioinjector.net Pi add on soundcard"
+ depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
+ select SND_SOC_WM8731
+ help
+ Say Y or M if you want to add support for audioinjector.net Pi Hat
--- a/sound/soc/bcm/Makefile
+++ b/sound/soc/bcm/Makefile
@@ -20,6 +20,7 @@ snd-soc-rpi-dac-objs := rpi-dac.o
snd-soc-rpi-proto-objs := rpi-proto.o
snd-soc-iqaudio-dac-objs := iqaudio-dac.o
snd-soc-raspidac3-objs := raspidac3.o
+snd-soc-audioinjector-pi-soundcard-objs := audioinjector-pi-soundcard.o
obj-$(CONFIG_SND_BCM2708_SOC_ADAU1977_ADC) += snd-soc-adau1977-adc.o
obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_AMP) += snd-soc-hifiberry-amp.o
@@ -32,3 +33,5 @@ obj-$(CONFIG_SND_BCM2708_SOC_RPI_DAC) +=
obj-$(CONFIG_SND_BCM2708_SOC_RPI_PROTO) += snd-soc-rpi-proto.o
obj-$(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) += snd-soc-iqaudio-dac.o
obj-$(CONFIG_SND_BCM2708_SOC_RASPIDAC3) += snd-soc-raspidac3.o
+obj-$(CONFIG_SND_AUDIOINJECTOR_PI_SOUNDCARD) += snd-soc-audioinjector-pi-soundcard.o
+
--- /dev/null
+++ b/sound/soc/bcm/audioinjector-pi-soundcard.c
@@ -0,0 +1,193 @@
+/*
+ * ASoC Driver for AudioInjector Pi add on soundcard
+ *
+ * Created on: 13-May-2016
+ * Author: flatmax@flatmax.org
+ * based on code by Cliff Cai <Cliff.Cai@analog.com> for the ssm2602 machine blackfin.
+ * with help from Lars-Peter Clausen for simplifying the original code to use the dai_fmt field.
+ * i2s_node code taken from the other sound/soc/bcm machine drivers.
+ *
+ * Copyright (C) 2016 Flatmax Pty. Ltd.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ */
+
+#include <linux/module.h>
+#include <linux/types.h>
+
+#include <sound/core.h>
+#include <sound/soc.h>
+#include <sound/pcm_params.h>
+#include <sound/control.h>
+
+#include "../codecs/wm8731.h"
+
+static const unsigned int bcm2835_rates_12000000[] = {
+ 8000, 16000, 32000, 44100, 48000, 96000, 88200,
+};
+
+static struct snd_pcm_hw_constraint_list bcm2835_constraints_12000000 = {
+ .list = bcm2835_rates_12000000,
+ .count = ARRAY_SIZE(bcm2835_rates_12000000),
+};
+
+static int snd_audioinjector_pi_soundcard_startup(struct snd_pcm_substream *substream)
+{
+ /* Setup constraints, because there is a 12 MHz XTAL on the board */
+ snd_pcm_hw_constraint_list(substream->runtime, 0,
+ SNDRV_PCM_HW_PARAM_RATE,
+ &bcm2835_constraints_12000000);
+ return 0;
+}
+
+static int snd_audioinjector_pi_soundcard_hw_params(struct snd_pcm_substream *substream,
+ struct snd_pcm_hw_params *params)
+{
+ struct snd_soc_pcm_runtime *rtd = substream->private_data;
+ struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
+
+ switch (params_rate(params)){
+ case 8000:
+ return snd_soc_dai_set_bclk_ratio(cpu_dai, 1);
+ case 16000:
+ return snd_soc_dai_set_bclk_ratio(cpu_dai, 750);
+ case 32000:
+ return snd_soc_dai_set_bclk_ratio(cpu_dai, 375);
+ case 44100:
+ return snd_soc_dai_set_bclk_ratio(cpu_dai, 272);
+ case 48000:
+ return snd_soc_dai_set_bclk_ratio(cpu_dai, 250);
+ case 88200:
+ return snd_soc_dai_set_bclk_ratio(cpu_dai, 136);
+ case 96000:
+ return snd_soc_dai_set_bclk_ratio(cpu_dai, 125);
+ default:
+ return snd_soc_dai_set_bclk_ratio(cpu_dai, 125);
+ }
+}
+
+/* machine stream operations */
+static struct snd_soc_ops snd_audioinjector_pi_soundcard_ops = {
+ .startup = snd_audioinjector_pi_soundcard_startup,
+ .hw_params = snd_audioinjector_pi_soundcard_hw_params,
+};
+
+static int audioinjector_pi_soundcard_dai_init(struct snd_soc_pcm_runtime *rtd)
+{
+ return snd_soc_dai_set_sysclk(rtd->codec_dai, WM8731_SYSCLK_XTAL, 12000000, SND_SOC_CLOCK_IN);
+}
+
+static struct snd_soc_dai_link audioinjector_pi_soundcard_dai[] = {
+ {
+ .name = "AudioInjector audio",
+ .stream_name = "AudioInjector audio",
+ .cpu_dai_name = "bcm2708-i2s.0",
+ .codec_dai_name = "wm8731-hifi",
+ .platform_name = "bcm2835-i2s.0",
+ .codec_name = "wm8731.1-001a",
+ .ops = &snd_audioinjector_pi_soundcard_ops,
+ .init = audioinjector_pi_soundcard_dai_init,
+ .dai_fmt = SND_SOC_DAIFMT_CBM_CFM|SND_SOC_DAIFMT_I2S|SND_SOC_DAIFMT_NB_NF,
+ },
+};
+
+static const struct snd_soc_dapm_widget wm8731_dapm_widgets[] = {
+ SND_SOC_DAPM_HP("Headphone Jack", NULL),
+ SND_SOC_DAPM_SPK("Ext Spk", NULL),
+ SND_SOC_DAPM_LINE("Line In Jacks", NULL),
+ SND_SOC_DAPM_MIC("Microphone", NULL),
+};
+
+static const struct snd_soc_dapm_route audioinjector_audio_map[] = {
+ /* headphone connected to LHPOUT, RHPOUT */
+ {"Headphone Jack", NULL, "LHPOUT"},
+ {"Headphone Jack", NULL, "RHPOUT"},
+
+ /* speaker connected to LOUT, ROUT */
+ {"Ext Spk", NULL, "ROUT"},
+ {"Ext Spk", NULL, "LOUT"},
+
+ /* line inputs */
+ {"Line In Jacks", NULL, "Line Input"},
+
+ /* mic is connected to Mic Jack, with WM8731 Mic Bias */
+ {"Microphone", NULL, "Mic Bias"},
+};
+
+static struct snd_soc_card snd_soc_audioinjector = {
+ .name = "audioinjector-pi-soundcard",
+ .dai_link = audioinjector_pi_soundcard_dai,
+ .num_links = ARRAY_SIZE(audioinjector_pi_soundcard_dai),
+
+ .dapm_widgets = wm8731_dapm_widgets,
+ .num_dapm_widgets = ARRAY_SIZE(wm8731_dapm_widgets),
+ .dapm_routes = audioinjector_audio_map,
+ .num_dapm_routes = ARRAY_SIZE(audioinjector_audio_map),
+};
+
+static int audioinjector_pi_soundcard_probe(struct platform_device *pdev)
+{
+ struct snd_soc_card *card = &snd_soc_audioinjector;
+ int ret;
+
+ card->dev = &pdev->dev;
+
+ if (pdev->dev.of_node) {
+ struct snd_soc_dai_link *dai = &audioinjector_pi_soundcard_dai[0];
+ struct device_node *i2s_node = of_parse_phandle(pdev->dev.of_node,
+ "i2s-controller", 0);
+
+ if (i2s_node) {
+ dai->cpu_dai_name = NULL;
+ dai->cpu_of_node = i2s_node;
+ dai->platform_name = NULL;
+ dai->platform_of_node = i2s_node;
+ } else
+ if (!dai->cpu_of_node) {
+ dev_err(&pdev->dev, "Property 'i2s-controller' missing or invalid\n");
+ return -EINVAL;
+ }
+ }
+
+ if ((ret = snd_soc_register_card(card))) {
+ dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret);
+ }
+ return ret;
+}
+
+static int audioinjector_pi_soundcard_remove(struct platform_device *pdev)
+{
+ struct snd_soc_card *card = platform_get_drvdata(pdev);
+ return snd_soc_unregister_card(card);
+
+}
+
+static const struct of_device_id audioinjector_pi_soundcard_of_match[] = {
+ { .compatible = "ai,audioinjector-pi-soundcard", },
+ {},
+};
+MODULE_DEVICE_TABLE(of, audioinjector_pi_soundcard_of_match);
+
+static struct platform_driver audioinjector_pi_soundcard_driver = {
+ .driver = {
+ .name = "audioinjector-stereo",
+ .owner = THIS_MODULE,
+ .of_match_table = audioinjector_pi_soundcard_of_match,
+ },
+ .probe = audioinjector_pi_soundcard_probe,
+ .remove = audioinjector_pi_soundcard_remove,
+};
+
+module_platform_driver(audioinjector_pi_soundcard_driver);
+MODULE_AUTHOR("Matt Flax <flatmax@flatmax.org>");
+MODULE_DESCRIPTION("AudioInjector.net Pi Soundcard");
+MODULE_LICENSE("GPL v2");
+MODULE_ALIAS("platform:audioinjector-pi-soundcard");
+