Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add audioinjector stereo soundcard #4

Open
wants to merge 2 commits into
base: release-4.4-rockpi4
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions arch/arm64/boot/dts/rockchip/overlays-rockpi4/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ dtbo-$(CONFIG_ARCH_ROCKCHIP) += \
spi1-flash.dtbo \
hifiberry-dac.dtbo \
hifiberry-dacplus.dtbo \
audioinjector-wm8731-audio.dtbo \
raspberrypi-7-inch-lcd.dtbo \
gt9xx.dtbo \
cpufreq.dtbo \
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/dts-v1/;
/plugin/;

/ {
compatible = "rockchip,rk3399";

fragment@0 {
target = <&i2c7>;
__overlay__ {
#address-cells = <1>;
#size-cells = <0>;
status = "okay";

wm8731@1a {
#sound-dai-cells = <0>;
compatible = "wlf,wm8731";
reg = <0x1a>;
AVDD-supply = <&vcc3v3_sys>;
HPVDD-supply = <&vcc3v3_sys>;
DCVDD-supply = <&vcc3v3_sys>;
DBVDD-supply = <&vcc3v3_sys>;
status = "okay";
};
};
};

fragment@1 {
target-path = "/sound-ext-card";

__overlay__ {
compatible = "ai,audioinjector-pi-soundcard";
i2s-controller = <&i2s1>;
status = "okay";
};
};

fragment@2 {
target = <&i2s1>;
__overlay__ {
status = "okay";
#sound-dai-cells = <0>;
};
};

};
3 changes: 3 additions & 0 deletions arch/arm64/boot/dts/rockchip/overlays-rockpi4/hw_intfc.conf
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,8 @@ intfc:dtoverlay=console-on-ttyS2
# Add ov5647 camera module support. Need disabled imx219 camera module.
#intfc:dtoverlay=ov5647

#audioinjector-wm8731-audio on I2C7. Need set: intfc:i2c7=on
#intfc:dtoverlay=audioinjector-wm8731-audio

# Add w1 on GPIO4_D6 to support devices such as DS18B20.
#intfc:dtoverlay=w1-gpio4-30
1 change: 1 addition & 0 deletions arch/arm64/configs/rockchip_linux_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,7 @@ CONFIG_SND_SOC_ROCKCHIP_MAX98090=y
CONFIG_SND_SOC_ROCKCHIP_RT5645=y
CONFIG_SND_SOC_HIFIBERRY_DAC=y
CONFIG_SND_SOC_HIFIBERRY_DACPLUS=y
CONFIG_SND_AUDIOINJECTOR_PI_SOUNDCARD=y
CONFIG_SND_SOC_ES8316=y
CONFIG_SND_SOC_RK3308=y
CONFIG_SND_SOC_RK3328=y
Expand Down
6 changes: 6 additions & 0 deletions sound/soc/rockchip/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,9 @@ config SND_SOC_HIFIBERRY_DACPLUS
select SND_SOC_PCM512x_I2C
help
Say Y or M if you want to add support for HifiBerry DAC+.

config SND_AUDIOINJECTOR_PI_SOUNDCARD
tristate "Support for audioinjector.net Pi add on soundcard"
select SND_SOC_WM8731
help
Say Y or M if you want to add support for audioinjector.net Pi Hat
2 changes: 2 additions & 0 deletions sound/soc/rockchip/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ snd-soc-rockchip-rt5651-tc358749x-objs := rockchip_rt5651_tc358749x.o
snd-soc-rockchip-cdndp-objs := rockchip_cdndp.o
snd-soc-hifiberry-dac-objs := hifiberry_dac.o
snd-soc-hifiberry-dacplus-objs := hifiberry_dacplus.o
snd-soc-audioinjector-pi-soundcard-objs := audioinjector-pi-soundcard.o

obj-$(CONFIG_SND_SOC_ROCKCHIP_DA7219) += snd-soc-rockchip-da7219.o
obj-$(CONFIG_SND_SOC_ROCKCHIP_HDMI_ANALOG) += snd-soc-rockchip-hdmi-analog.o
Expand All @@ -44,3 +45,4 @@ obj-$(CONFIG_SND_SOC_ROCKCHIP_RT5651_TC358749) += snd-soc-rockchip-rt5651-tc3587
obj-$(CONFIG_SND_SOC_ROCKCHIP_CDNDP) += snd-soc-rockchip-cdndp.o
obj-$(CONFIG_SND_SOC_HIFIBERRY_DAC) += snd-soc-hifiberry-dac.o
obj-$(CONFIG_SND_SOC_HIFIBERRY_DACPLUS) += snd-soc-hifiberry-dacplus.o
obj-$(CONFIG_SND_AUDIOINJECTOR_PI_SOUNDCARD) += snd-soc-audioinjector-pi-soundcard.o
201 changes: 201 additions & 0 deletions sound/soc/rockchip/audioinjector-pi-soundcard.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
/*
* ASoC Driver for AudioInjector Pi add on soundcard
*
* Created on: 13-May-2016
* Author: [email protected]
* based on code by Cliff Cai <[email protected]> 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/delay.h>
#include <linux/module.h>
#include <linux/types.h>
#include <linux/platform_device.h>

#include <sound/core.h>
#include <sound/soc.h>
#include <sound/pcm.h>
#include <sound/pcm_params.h>
#include <sound/control.h>
#include <sound/jack.h>
#include <linux/gpio/consumer.h>

#include "../codecs/wm8731.h"


#ifdef ROCKCHIP_AUDIO
#define ROCKCHIP_I2S_MCLK 512
#define MCLK 12000000
#endif

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;
#ifdef ROCKCHIP_AUDIO
return 0;
#else
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);
}
#endif
}

/* 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, MCLK, 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.7-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 = devm_snd_soc_register_card(&pdev->dev, card))) {
dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret);
}
return ret;
}

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,
};

module_platform_driver(audioinjector_pi_soundcard_driver);
MODULE_AUTHOR("Matt Flax <[email protected]>");
MODULE_DESCRIPTION("AudioInjector.net Pi Soundcard");
MODULE_LICENSE("GPL v2");
MODULE_ALIAS("platform:audioinjector-pi-soundcard");