From 035f9ed3a8ceb0eaf88e09d16f10f9f4accf6c88 Mon Sep 17 00:00:00 2001 From: Pitichai Pitimaneeyakul Date: Mon, 2 Mar 2015 17:06:56 +0700 Subject: [PATCH] This will add durio sound driver to rpi 3.18.y Changes to be committed: new file: arch/arm/boot/dts/duriosound-dac-overlay.dts new file: sound/soc/bcm/duriosound-dac.c Changes not staged for commit: modified: arch/arm/configs/bcm2709_defconfig modified: arch/arm/configs/bcmrpi_defconfig modified: arch/arm/mach-bcm2708/bcm2708.c modified: arch/arm/mach-bcm2709/bcm2709.c modified: sound/soc/bcm/Kconfig modified: sound/soc/bcm/Makefile modified: sound/soc/bcm/duriosound-dac.c --- arch/arm/boot/dts/duriosound-dac-overlay.dts | 34 ++++++ arch/arm/configs/bcm2709_defconfig | 1 + arch/arm/configs/bcmrpi_defconfig | 1 + arch/arm/mach-bcm2708/bcm2708.c | 19 ++++ arch/arm/mach-bcm2709/bcm2709.c | 19 ++++ sound/soc/bcm/Kconfig | 8 ++ sound/soc/bcm/Makefile | 2 + sound/soc/bcm/duriosound-dac.c | 106 +++++++++++++++++++ 8 files changed, 190 insertions(+) create mode 100644 arch/arm/boot/dts/duriosound-dac-overlay.dts create mode 100644 sound/soc/bcm/duriosound-dac.c diff --git a/arch/arm/boot/dts/duriosound-dac-overlay.dts b/arch/arm/boot/dts/duriosound-dac-overlay.dts new file mode 100644 index 00000000000000..577e46f18dbb93 --- /dev/null +++ b/arch/arm/boot/dts/duriosound-dac-overlay.dts @@ -0,0 +1,34 @@ +// Definitions for DURIOSOUND DAC +/dts-v1/; +/plugin/; + +/ { + compatible = "brcm,bcm2708"; + + fragment@0 { + target = <&sound>; + __overlay__ { + compatible = "duriosound,duriosound-dac"; + i2s-controller = <&i2s>; + status = "okay"; + }; + }; + + fragment@1 { + target = <&i2s>; + __overlay__ { + status = "okay"; + }; + }; + + fragment@2 { + target-path = "/"; + __overlay__ { + pcm5102a-codec { + #sound-dai-cells = <0>; + compatible = "ti,pcm5102a"; + status = "okay"; + }; + }; + }; +}; diff --git a/arch/arm/configs/bcm2709_defconfig b/arch/arm/configs/bcm2709_defconfig index 1c88a5ea0b587d..ab994bf9e31b4b 100644 --- a/arch/arm/configs/bcm2709_defconfig +++ b/arch/arm/configs/bcm2709_defconfig @@ -798,6 +798,7 @@ CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI=m CONFIG_SND_BCM2708_SOC_HIFIBERRY_AMP=m CONFIG_SND_BCM2708_SOC_RPI_DAC=m CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC=m +CONFIG_SND_BCM2708_SOC_DURIOSOUND_DAC=m CONFIG_SND_SIMPLE_CARD=m CONFIG_SOUND_PRIME=m CONFIG_HIDRAW=y diff --git a/arch/arm/configs/bcmrpi_defconfig b/arch/arm/configs/bcmrpi_defconfig index b0619928c487b5..d197abf090d645 100644 --- a/arch/arm/configs/bcmrpi_defconfig +++ b/arch/arm/configs/bcmrpi_defconfig @@ -792,6 +792,7 @@ CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI=m CONFIG_SND_BCM2708_SOC_HIFIBERRY_AMP=m CONFIG_SND_BCM2708_SOC_RPI_DAC=m CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC=m +CONFIG_SND_BCM2708_SOC_DURIOSOUND_DAC=m CONFIG_SND_SIMPLE_CARD=m CONFIG_SOUND_PRIME=m CONFIG_HIDRAW=y diff --git a/arch/arm/mach-bcm2708/bcm2708.c b/arch/arm/mach-bcm2708/bcm2708.c index 762e17c175a5ae..1162ff8394a706 100644 --- a/arch/arm/mach-bcm2708/bcm2708.c +++ b/arch/arm/mach-bcm2708/bcm2708.c @@ -733,6 +733,20 @@ static struct i2c_board_info __initdata snd_pcm512x_i2c_devices[] = { }; #endif +#if defined(CONFIG_SND_BCM2708_SOC_DURIOSOUND_DAC) || defined(CONFIG_SND_BCM2708_SOC_DURIOSOUND_DAC_MODULE) +static struct platform_device snd_duriosound_dac_device = { + .name = "snd-hifiberry-dac", + .id = 0, + .num_resources = 0, +}; + +static struct platform_device snd_pcm5102a_durio_codec_device = { + .name = "pcm5102a-codec", + .id = -1, + .num_resources = 0, +}; +#endif + int __init bcm_register_device(struct platform_device *pdev) { int ret; @@ -932,6 +946,11 @@ void __init bcm2708_init(void) i2c_register_board_info_dt(1, snd_pcm512x_i2c_devices, ARRAY_SIZE(snd_pcm512x_i2c_devices)); #endif +#if defined(CONFIG_SND_BCM2708_SOC_DURIOSOUND_DAC) || defined(CONFIG_SND_BCM2708_SOC_DURIOSOUND_DAC_MODULE) + bcm_register_device_dt(&snd_duriosound_dac_device); + bcm_register_device_dt(&snd_pcm5102a_durio_codec_device); +#endif + for (i = 0; i < ARRAY_SIZE(amba_devs); i++) { struct amba_device *d = amba_devs[i]; diff --git a/arch/arm/mach-bcm2709/bcm2709.c b/arch/arm/mach-bcm2709/bcm2709.c index 7e3affdcbcf509..0af4ba67866998 100644 --- a/arch/arm/mach-bcm2709/bcm2709.c +++ b/arch/arm/mach-bcm2709/bcm2709.c @@ -755,6 +755,20 @@ static struct i2c_board_info __initdata snd_pcm512x_i2c_devices[] = { }; #endif +#if defined(CONFIG_SND_BCM2708_SOC_DURIOSOUND_DAC) || defined(CONFIG_SND_BCM2708_SOC_DURIOSOUND_DAC_MODULE) +static struct platform_device snd_duriosound_dac_device = { + .name = "snd-hifiberry-dac", + .id = 0, + .num_resources = 0, +}; + +static struct platform_device snd_pcm5102a_durio_codec_device = { + .name = "pcm5102a-codec", + .id = -1, + .num_resources = 0, +}; +#endif + int __init bcm_register_device(struct platform_device *pdev) { int ret; @@ -954,6 +968,11 @@ void __init bcm2709_init(void) i2c_register_board_info_dt(1, snd_pcm512x_i2c_devices, ARRAY_SIZE(snd_pcm512x_i2c_devices)); #endif +#if defined(CONFIG_SND_BCM2708_SOC_DURIOSOUND_DAC) || defined(CONFIG_SND_BCM2708_SOC_DURIOSOUND_DAC_MODULE) + bcm_register_device_dt(&snd_duriosound_dac_device); + bcm_register_device_dt(&snd_pcm5102a_durio_codec_device); +#endif + for (i = 0; i < ARRAY_SIZE(amba_devs); i++) { struct amba_device *d = amba_devs[i]; diff --git a/sound/soc/bcm/Kconfig b/sound/soc/bcm/Kconfig index 40d27c1dcb4a46..34be93e9d7928d 100644 --- a/sound/soc/bcm/Kconfig +++ b/sound/soc/bcm/Kconfig @@ -60,3 +60,11 @@ config SND_BCM2708_SOC_IQAUDIO_DAC select SND_SOC_PCM512x_I2C help Say Y or M if you want to add support for IQaudIO-DAC. + +config SND_BCM2708_SOC_DURIOSOUND_DAC + tristate "Support for DurioSound DAC" + depends on SND_BCM2708_SOC_I2S + select SND_SOC_PCM5102A + help + Say Y or M if you want to add support for DurioSound DAC. + diff --git a/sound/soc/bcm/Makefile b/sound/soc/bcm/Makefile index 17ea2b02afa3de..41487a6093409d 100644 --- a/sound/soc/bcm/Makefile +++ b/sound/soc/bcm/Makefile @@ -15,6 +15,7 @@ snd-soc-hifiberry-digi-objs := hifiberry_digi.o snd-soc-hifiberry-amp-objs := hifiberry_amp.o snd-soc-rpi-dac-objs := rpi-dac.o snd-soc-iqaudio-dac-objs := iqaudio-dac.o +snd-soc-duriosound-dac-objs := duriosound-dac.o obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) += snd-soc-hifiberry-dac.o obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS) += snd-soc-hifiberry-dacplus.o @@ -22,3 +23,4 @@ obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) += snd-soc-hifiberry-digi.o obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_AMP) += snd-soc-hifiberry-amp.o obj-$(CONFIG_SND_BCM2708_SOC_RPI_DAC) += snd-soc-rpi-dac.o obj-$(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) += snd-soc-iqaudio-dac.o +obj-$(CONFIG_SND_BCM2708_SOC_DURIOSOUND_DAC) += snd-soc-duriosound-dac.o diff --git a/sound/soc/bcm/duriosound-dac.c b/sound/soc/bcm/duriosound-dac.c new file mode 100644 index 00000000000000..5d24de86145340 --- /dev/null +++ b/sound/soc/bcm/duriosound-dac.c @@ -0,0 +1,106 @@ +/* + * ASoC Driver for DurioSound-DAC. + * + * Author : Pitichai Pitimaneeyakul + * Copyright 2014 + * + * based on code by Florian Meier + * + * This Module is rewritten from rpi-dac.c and it is modified to + * use pcm5102a as codec to support DurioSound DAC. + * + * 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 +#include +#include + +#include +#include +#include +#include +#include + +static int snd_rpi_duriosound_dac_init(struct snd_soc_pcm_runtime *rtd) +{ + return 0; +} + +static int snd_rpi_duriosound_dac_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; + + unsigned int sample_bits = + snd_pcm_format_physical_width(params_format(params)); + + return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2); +} + +/* machine stream operations */ +static struct snd_soc_ops snd_rpi_duriosound_dac_ops = { + .hw_params = snd_rpi_duriosound_dac_hw_params, +}; + +static struct snd_soc_dai_link snd_rpi_duriosound_dac_dai[] = { +{ + .name = "DurioSound-DAC", + .stream_name = "DurioSound-DAC HiFi", + .cpu_dai_name = "bcm2708-i2s.0", + .codec_dai_name = "pcm5102a-hifi", + .platform_name = "bcm2708-i2s.0", + .codec_name = "pcm5102a-codec", + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | + SND_SOC_DAIFMT_CBS_CFS, + .ops = &snd_rpi_duriosound_dac_ops, + .init = snd_rpi_duriosound_dac_init, +}, +}; + +/* audio machine driver */ +static struct snd_soc_card snd_rpi_duriosound_dac = { + .name = "snd_rpi_duriosound_dac", + .dai_link = snd_rpi_duriosound_dac_dai, + .num_links = ARRAY_SIZE(snd_rpi_duriosound_dac_dai), +}; + +static int snd_rpi_duriosound_dac_probe(struct platform_device *pdev) +{ + int ret = 0; + + snd_rpi_duriosound_dac.dev = &pdev->dev; + ret = snd_soc_register_card(&snd_rpi_duriosound_dac); + if (ret) + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret); + + return ret; +} + +static int snd_rpi_duriosound_dac_remove(struct platform_device *pdev) +{ + return snd_soc_unregister_card(&snd_rpi_duriosound_dac); +} + +static struct platform_driver snd_rpi_duriosound_dac_driver = { + .driver = { + .name = "snd-duriosound-dac", + .owner = THIS_MODULE, + }, + .probe = snd_rpi_duriosound_dac_probe, + .remove = snd_rpi_duriosound_dac_remove, +}; + +module_platform_driver(snd_rpi_duriosound_dac_driver); + +MODULE_AUTHOR("Pitichai Pitimaneeyakul "); +MODULE_DESCRIPTION("ASoC Driver for DurioSound-DAC"); +MODULE_LICENSE("GPL v2");