From 4e00e098889e969903d7ae61d4cbd0e4773a52af Mon Sep 17 00:00:00 2001 From: Howard Mitchell Date: Wed, 30 Jul 2014 10:02:00 +0100 Subject: [PATCH 1/6] Revert "fix soc-core's inverse range and let IQaudIO DAC use this fixed SOC_DOUBLE_R_RANGE_TLV support" --- sound/soc/soc-core.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 4d8917b9e11a94..bf39f1666aef98 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -3058,8 +3058,8 @@ int snd_soc_put_volsw_range(struct snd_kcontrol *kcontrol, if (invert) val = ((max - ucontrol->value.integer.value[0] + min) & mask); - else - val = (ucontrol->value.integer.value[0] & mask); + else + val = (ucontrol->value.integer.value[0] & mask); val_mask = mask << shift; val = val << shift; @@ -3070,8 +3070,8 @@ int snd_soc_put_volsw_range(struct snd_kcontrol *kcontrol, if (snd_soc_volsw_is_stereo(mc)) { if (invert) val = ((max - ucontrol->value.integer.value[1] + min) & mask); - else - val = (ucontrol->value.integer.value[1] & mask); + else + val = (ucontrol->value.integer.value[1] & mask); val_mask = mask << shift; val = val << shift; From 6a4491eb889dccce1c0279cbfcb038158b4c3a91 Mon Sep 17 00:00:00 2001 From: Howard Mitchell Date: Wed, 30 Jul 2014 10:08:37 +0100 Subject: [PATCH 2/6] Revert "Fix volsw_range functions so SOC_DOUBLE_R_RANGE_TLV works." --- sound/soc/soc-core.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index bf39f1666aef98..051c006281f5c2 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -3024,8 +3024,8 @@ int snd_soc_info_volsw_range(struct snd_kcontrol *kcontrol, uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; uinfo->count = snd_soc_volsw_is_stereo(mc) ? 2 : 1; - uinfo->value.integer.min = min; - uinfo->value.integer.max = platform_max; + uinfo->value.integer.min = 0; + uinfo->value.integer.max = platform_max - min; return 0; } @@ -3056,10 +3056,9 @@ int snd_soc_put_volsw_range(struct snd_kcontrol *kcontrol, unsigned int val, val_mask; int ret; + val = ((ucontrol->value.integer.value[0] + min) & mask); if (invert) - val = ((max - ucontrol->value.integer.value[0] + min) & mask); - else - val = (ucontrol->value.integer.value[0] & mask); + val = max - val; val_mask = mask << shift; val = val << shift; @@ -3068,10 +3067,9 @@ int snd_soc_put_volsw_range(struct snd_kcontrol *kcontrol, return ret; if (snd_soc_volsw_is_stereo(mc)) { + val = ((ucontrol->value.integer.value[1] + min) & mask); if (invert) - val = ((max - ucontrol->value.integer.value[1] + min) & mask); - else - val = (ucontrol->value.integer.value[1] & mask); + val = max - val; val_mask = mask << shift; val = val << shift; @@ -3109,14 +3107,18 @@ int snd_soc_get_volsw_range(struct snd_kcontrol *kcontrol, (snd_soc_read(codec, reg) >> shift) & mask; if (invert) ucontrol->value.integer.value[0] = - max - ucontrol->value.integer.value[0] + min; + max - ucontrol->value.integer.value[0]; + ucontrol->value.integer.value[0] = + ucontrol->value.integer.value[0] - min; if (snd_soc_volsw_is_stereo(mc)) { ucontrol->value.integer.value[1] = (snd_soc_read(codec, rreg) >> shift) & mask; if (invert) ucontrol->value.integer.value[1] = - max - ucontrol->value.integer.value[1] + min; + max - ucontrol->value.integer.value[1]; + ucontrol->value.integer.value[1] = + ucontrol->value.integer.value[1] - min; } return 0; From 30c03d03f4ecb018b425a1c1969515af60b07dc9 Mon Sep 17 00:00:00 2001 From: Howard Mitchell Date: Wed, 30 Jul 2014 10:20:03 +0100 Subject: [PATCH 3/6] Revert "Add IQaudIO Sound Card support for Raspberry Pi" --- arch/arm/configs/bcmrpi_defconfig | 1 - arch/arm/mach-bcm2708/bcm2708.c | 22 --- sound/soc/bcm/Kconfig | 7 - sound/soc/bcm/Makefile | 2 - sound/soc/bcm/iqaudio-dac.c | 111 -------------- sound/soc/codecs/Kconfig | 4 - sound/soc/codecs/Makefile | 2 - sound/soc/codecs/pcm512x.c | 243 ++++++++++-------------------- sound/soc/codecs/pcm512x.h | 143 +++++++++++------- 9 files changed, 163 insertions(+), 372 deletions(-) delete mode 100644 sound/soc/bcm/iqaudio-dac.c diff --git a/arch/arm/configs/bcmrpi_defconfig b/arch/arm/configs/bcmrpi_defconfig index 29fe486f3c6524..9888fc959c0278 100644 --- a/arch/arm/configs/bcmrpi_defconfig +++ b/arch/arm/configs/bcmrpi_defconfig @@ -751,7 +751,6 @@ CONFIG_SND_BCM2708_SOC_RPI_DAC=m CONFIG_SND_SOC_I2C_AND_SPI=m CONFIG_SND_SOC_PCM5102A=m CONFIG_SND_SOC_PCM1794A=m -CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC=m CONFIG_SOUND_PRIME=m CONFIG_HIDRAW=y CONFIG_HID_A4TECH=m diff --git a/arch/arm/mach-bcm2708/bcm2708.c b/arch/arm/mach-bcm2708/bcm2708.c index f67e5521de566c..da3849226a130f 100644 --- a/arch/arm/mach-bcm2708/bcm2708.c +++ b/arch/arm/mach-bcm2708/bcm2708.c @@ -674,22 +674,6 @@ static struct platform_device snd_pcm1794a_codec_device = { }; #endif - -#if defined(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) || defined(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC_MODULE) -static struct platform_device snd_rpi_iqaudio_dac_device = { - .name = "snd-rpi-iqaudio-dac", - .id = 0, - .num_resources = 0, -}; - -// Use the actual device name rather than generic driver name -static struct i2c_board_info __initdata snd_pcm512x_i2c_devices[] = { - { - I2C_BOARD_INFO("pcm5122", 0x4c) - }, -}; -#endif - int __init bcm_register_device(struct platform_device *pdev) { int ret; @@ -855,12 +839,6 @@ void __init bcm2708_init(void) bcm_register_device(&snd_pcm1794a_codec_device); #endif -#if defined(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) || defined(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC_MODULE) - bcm_register_device(&snd_rpi_iqaudio_dac_device); - i2c_register_board_info(1, snd_pcm512x_i2c_devices, ARRAY_SIZE(snd_pcm512x_i2c_devices)); -#endif - - for (i = 0; i < ARRAY_SIZE(amba_devs); i++) { struct amba_device *d = amba_devs[i]; amba_device_register(d, &iomem_resource); diff --git a/sound/soc/bcm/Kconfig b/sound/soc/bcm/Kconfig index 84e4f27af70423..e563dbcb0513b2 100644 --- a/sound/soc/bcm/Kconfig +++ b/sound/soc/bcm/Kconfig @@ -39,10 +39,3 @@ config SND_BCM2708_SOC_RPI_DAC select SND_SOC_PCM1794A help Say Y or M if you want to add support for RPi-DAC. - -config SND_BCM2708_SOC_IQAUDIO_DAC - tristate "Support for IQaudIO-DAC" - depends on SND_BCM2708_SOC_I2S - select SND_SOC_PCM512x - help - Say Y or M if you want to add support for IQaudIO-DAC. diff --git a/sound/soc/bcm/Makefile b/sound/soc/bcm/Makefile index d597fb09482a1b..826df7d3e85464 100644 --- a/sound/soc/bcm/Makefile +++ b/sound/soc/bcm/Makefile @@ -12,9 +12,7 @@ obj-$(CONFIG_SND_BCM2708_SOC_I2S) += snd-soc-bcm2708-i2s.o snd-soc-hifiberry-dac-objs := hifiberry_dac.o snd-soc-hifiberry-digi-objs := hifiberry_digi.o snd-soc-rpi-dac-objs := rpi-dac.o -snd-soc-iqaudio-dac-objs := iqaudio-dac.o obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) += snd-soc-hifiberry-dac.o obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) += snd-soc-hifiberry-digi.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 diff --git a/sound/soc/bcm/iqaudio-dac.c b/sound/soc/bcm/iqaudio-dac.c deleted file mode 100644 index 515f0448b196eb..00000000000000 --- a/sound/soc/bcm/iqaudio-dac.c +++ /dev/null @@ -1,111 +0,0 @@ -/* - * ASoC Driver for IQaudIO DAC - * - * Author: Florian Meier - * Copyright 2013 - * - * 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 - -static int snd_rpi_iqaudio_dac_init(struct snd_soc_pcm_runtime *rtd) -{ -// NOT USED struct snd_soc_codec *codec = rtd->codec; - - return 0; -} - -static int snd_rpi_iqaudio_dac_hw_params(struct snd_pcm_substream *substream, - struct snd_pcm_hw_params *params) -{ - struct snd_soc_pcm_runtime *rtd = substream->private_data; -// NOT USED struct snd_soc_dai *codec_dai = rtd->codec_dai; -// NOT USED struct snd_soc_codec *codec = rtd->codec; - 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_iqaudio_dac_ops = { - .hw_params = snd_rpi_iqaudio_dac_hw_params, -}; - -static struct snd_soc_dai_link snd_rpi_iqaudio_dac_dai[] = { -{ - .name = "IQaudIO DAC", - .stream_name = "IQaudIO DAC HiFi", - .cpu_dai_name = "bcm2708-i2s.0", - .codec_dai_name = "pcm512x-hifi", - .platform_name = "bcm2708-i2s.0", - .codec_name = "pcm512x.1-004c", - .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | - SND_SOC_DAIFMT_CBS_CFS, - .ops = &snd_rpi_iqaudio_dac_ops, - .init = snd_rpi_iqaudio_dac_init, -}, -}; - -/* audio machine driver */ -static struct snd_soc_card snd_rpi_iqaudio_dac = { - .name = "snd_rpi_iqaudio_dac", - .dai_link = snd_rpi_iqaudio_dac_dai, - .num_links = ARRAY_SIZE(snd_rpi_iqaudio_dac_dai), -}; - -static int snd_rpi_iqaudio_dac_probe(struct platform_device *pdev) -{ - int ret = 0; - - snd_rpi_iqaudio_dac.dev = &pdev->dev; - ret = snd_soc_register_card(&snd_rpi_iqaudio_dac); - if (ret) - dev_err(&pdev->dev, - "snd_soc_register_card() failed: %d\n", ret); - - return ret; -} - -static int snd_rpi_iqaudio_dac_remove(struct platform_device *pdev) -{ - return snd_soc_unregister_card(&snd_rpi_iqaudio_dac); -} - -static const struct of_device_id iqaudio_of_match[] = { - { .compatible = "iqaudio,iqaudio-dac", }, - {}, -}; - -static struct platform_driver snd_rpi_iqaudio_dac_driver = { - .driver = { - .name = "snd-rpi-iqaudio-dac", - .owner = THIS_MODULE, - .of_match_table = iqaudio_of_match, - }, - .probe = snd_rpi_iqaudio_dac_probe, - .remove = snd_rpi_iqaudio_dac_remove, -}; - -module_platform_driver(snd_rpi_iqaudio_dac_driver); - -MODULE_AUTHOR("Florian Meier "); -MODULE_DESCRIPTION("ASoC Driver for IQAudio DAC"); -MODULE_LICENSE("GPL v2"); diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig index b3a048837ef0fc..54dec920683c98 100644 --- a/sound/soc/codecs/Kconfig +++ b/sound/soc/codecs/Kconfig @@ -71,7 +71,6 @@ config SND_SOC_ALL_CODECS select SND_SOC_PCM512x_SPI if SPI_MASTER select SND_SOC_PCM1794A select SND_SOC_PCM5102A - select SND_SOC_PCM512x if SND_SOC_I2C_AND_SPI select SND_SOC_RT5631 if I2C select SND_SOC_RT5640 if I2C select SND_SOC_SGTL5000 if I2C @@ -399,9 +398,6 @@ config SND_SOC_PCM1794A config SND_SOC_PCM5102A tristate -config SND_SOC_PCM512x - tristate - config SND_SOC_RT5631 tristate diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile index 95600ec3d5e484..7f0eefac0b53f2 100644 --- a/sound/soc/codecs/Makefile +++ b/sound/soc/codecs/Makefile @@ -60,7 +60,6 @@ snd-soc-pcm512x-i2c-objs := pcm512x-i2c.o snd-soc-pcm512x-spi-objs := pcm512x-spi.o snd-soc-pcm1794a-objs := pcm1794a.o snd-soc-pcm5102a-objs := pcm5102a.o -snd-soc-pcm512x-objs := pcm512x.o snd-soc-rt5631-objs := rt5631.o snd-soc-rt5640-objs := rt5640.o snd-soc-sgtl5000-objs := sgtl5000.o @@ -214,7 +213,6 @@ obj-$(CONFIG_SND_SOC_PCM512x_I2C) += snd-soc-pcm512x-i2c.o obj-$(CONFIG_SND_SOC_PCM512x_SPI) += snd-soc-pcm512x-spi.o obj-$(CONFIG_SND_SOC_PCM1794A) += snd-soc-pcm1794a.o obj-$(CONFIG_SND_SOC_PCM5102A) += snd-soc-pcm5102a.o -obj-$(CONFIG_SND_SOC_PCM512x) += snd-soc-pcm512x.o obj-$(CONFIG_SND_SOC_RT5631) += snd-soc-rt5631.o obj-$(CONFIG_SND_SOC_RT5640) += snd-soc-rt5640.o obj-$(CONFIG_SND_SOC_SGTL5000) += snd-soc-sgtl5000.o diff --git a/sound/soc/codecs/pcm512x.c b/sound/soc/codecs/pcm512x.c index b669e156b9a43b..4b4c0c7bb918fe 100644 --- a/sound/soc/codecs/pcm512x.c +++ b/sound/soc/codecs/pcm512x.c @@ -18,11 +18,9 @@ #include #include #include -#include #include #include #include -#include #include #include #include @@ -30,7 +28,7 @@ #include "pcm512x.h" #define PCM512x_NUM_SUPPLIES 3 -static const char *pcm512x_supply_names[PCM512x_NUM_SUPPLIES] = { +static const char * const pcm512x_supply_names[PCM512x_NUM_SUPPLIES] = { "AVDD", "DVDD", "CPVDD", @@ -66,22 +64,29 @@ PCM512x_REGULATOR_EVENT(1) PCM512x_REGULATOR_EVENT(2) static const struct reg_default pcm512x_reg_defaults[] = { - { PCM512x_RESET, 0x00 }, - { PCM512x_POWER, 0x00 }, - { PCM512x_MUTE, 0x00 }, - { PCM512x_DSP, 0x00 }, - { PCM512x_PLL_REF, 0x00 }, - { PCM512x_DAC_ROUTING, 0x11 }, - { PCM512x_DSP_PROGRAM, 0x01 }, - { PCM512x_CLKDET, 0x00 }, - { PCM512x_AUTO_MUTE, 0x00 }, - { PCM512x_ERROR_DETECT, 0x00 }, - { PCM512x_DIGITAL_VOLUME_1, 0x00 }, - { PCM512x_DIGITAL_VOLUME_2, 0x30 }, - { PCM512x_DIGITAL_VOLUME_3, 0x30 }, - { PCM512x_DIGITAL_MUTE_1, 0x22 }, - { PCM512x_DIGITAL_MUTE_2, 0x00 }, - { PCM512x_DIGITAL_MUTE_3, 0x07 }, + { PCM512x_RESET, 0x00 }, + { PCM512x_POWER, 0x00 }, + { PCM512x_MUTE, 0x00 }, + { PCM512x_DSP, 0x00 }, + { PCM512x_PLL_REF, 0x00 }, + { PCM512x_DAC_ROUTING, 0x11 }, + { PCM512x_DSP_PROGRAM, 0x01 }, + { PCM512x_CLKDET, 0x00 }, + { PCM512x_AUTO_MUTE, 0x00 }, + { PCM512x_ERROR_DETECT, 0x00 }, + { PCM512x_DIGITAL_VOLUME_1, 0x00 }, + { PCM512x_DIGITAL_VOLUME_2, 0x30 }, + { PCM512x_DIGITAL_VOLUME_3, 0x30 }, + { PCM512x_DIGITAL_MUTE_1, 0x22 }, + { PCM512x_DIGITAL_MUTE_2, 0x00 }, + { PCM512x_DIGITAL_MUTE_3, 0x07 }, + { PCM512x_OUTPUT_AMPLITUDE, 0x00 }, + { PCM512x_ANALOG_GAIN_CTRL, 0x00 }, + { PCM512x_UNDERVOLTAGE_PROT, 0x00 }, + { PCM512x_ANALOG_MUTE_CTRL, 0x00 }, + { PCM512x_ANALOG_GAIN_BOOST, 0x00 }, + { PCM512x_VCOM_CTRL_1, 0x00 }, + { PCM512x_VCOM_CTRL_2, 0x01 }, }; static bool pcm512x_readable(struct device *dev, unsigned int reg) @@ -141,9 +146,18 @@ static bool pcm512x_readable(struct device *dev, unsigned int reg) case PCM512x_ANALOG_MUTE_DET: case PCM512x_GPIN: case PCM512x_DIGITAL_MUTE_DET: + case PCM512x_OUTPUT_AMPLITUDE: + case PCM512x_ANALOG_GAIN_CTRL: + case PCM512x_UNDERVOLTAGE_PROT: + case PCM512x_ANALOG_MUTE_CTRL: + case PCM512x_ANALOG_GAIN_BOOST: + case PCM512x_VCOM_CTRL_1: + case PCM512x_VCOM_CTRL_2: + case PCM512x_CRAM_CTRL: return true; default: - return false; + /* There are 256 raw register addresses */ + return reg < 0xff; } } @@ -159,17 +173,22 @@ static bool pcm512x_volatile(struct device *dev, unsigned int reg) case PCM512x_ANALOG_MUTE_DET: case PCM512x_GPIN: case PCM512x_DIGITAL_MUTE_DET: + case PCM512x_CRAM_CTRL: return true; default: - return false; + /* There are 256 raw register addresses */ + return reg < 0xff; } } static const DECLARE_TLV_DB_SCALE(digital_tlv, -10350, 50, 1); +static const DECLARE_TLV_DB_SCALE(analog_tlv, -600, 600, 0); +static const DECLARE_TLV_DB_SCALE(boost_tlv, 0, 80, 0); -static const char *pcm512x_dsp_program_texts[] = { +static const char * const pcm512x_dsp_program_texts[] = { "FIR interpolation with de-emphasis", "Low latency IIR with de-emphasis", + "Fixed process flow", "High attenuation with de-emphasis", "Ringing-less low latency FIR", }; @@ -182,31 +201,31 @@ static const unsigned int pcm512x_dsp_program_values[] = { 7, }; -static const SOC_VALUE_ENUM_SINGLE_DECL(pcm512x_dsp_program, - PCM512x_DSP_PROGRAM, 0, 0x1f, - pcm512x_dsp_program_texts, - pcm512x_dsp_program_values); +static SOC_VALUE_ENUM_SINGLE_DECL(pcm512x_dsp_program, + PCM512x_DSP_PROGRAM, 0, 0x1f, + pcm512x_dsp_program_texts, + pcm512x_dsp_program_values); -static const char *pcm512x_clk_missing_text[] = { +static const char * const pcm512x_clk_missing_text[] = { "1s", "2s", "3s", "4s", "5s", "6s", "7s", "8s" }; static const struct soc_enum pcm512x_clk_missing = - SOC_ENUM_SINGLE(PCM512x_CLKDET, 0, 7, pcm512x_clk_missing_text); + SOC_ENUM_SINGLE(PCM512x_CLKDET, 0, 8, pcm512x_clk_missing_text); -static const char *pcm512x_autom_text[] = { +static const char * const pcm512x_autom_text[] = { "21ms", "106ms", "213ms", "533ms", "1.07s", "2.13s", "5.33s", "10.66s" }; static const struct soc_enum pcm512x_autom_l = - SOC_ENUM_SINGLE(PCM512x_AUTO_MUTE, PCM512x_ATML_SHIFT, 7, + SOC_ENUM_SINGLE(PCM512x_AUTO_MUTE, PCM512x_ATML_SHIFT, 8, pcm512x_autom_text); static const struct soc_enum pcm512x_autom_r = - SOC_ENUM_SINGLE(PCM512x_AUTO_MUTE, PCM512x_ATMR_SHIFT, 7, + SOC_ENUM_SINGLE(PCM512x_AUTO_MUTE, PCM512x_ATMR_SHIFT, 8, pcm512x_autom_text); -static const char *pcm512x_ramp_rate_text[] = { +static const char * const pcm512x_ramp_rate_text[] = { "1 sample/update", "2 samples/update", "4 samples/update", "Immediate" }; @@ -223,7 +242,7 @@ static const struct soc_enum pcm512x_vedf = SOC_ENUM_SINGLE(PCM512x_DIGITAL_MUTE_2, PCM512x_VEDF_SHIFT, 4, pcm512x_ramp_rate_text); -static const char *pcm512x_ramp_step_text[] = { +static const char * const pcm512x_ramp_step_text[] = { "4dB/step", "2dB/step", "1dB/step", "0.5dB/step" }; @@ -239,10 +258,13 @@ static const struct soc_enum pcm512x_veds = SOC_ENUM_SINGLE(PCM512x_DIGITAL_MUTE_2, PCM512x_VEDS_SHIFT, 4, pcm512x_ramp_step_text); -/* Don't let the DAC go into clipping by limiting the alsa volume control range */ static const struct snd_kcontrol_new pcm512x_controls[] = { -SOC_DOUBLE_R_RANGE_TLV("Playback Digital Volume", PCM512x_DIGITAL_VOLUME_2, - PCM512x_DIGITAL_VOLUME_3, 0, 40, 255, 1, digital_tlv), +SOC_DOUBLE_R_TLV("Playback Digital Volume", PCM512x_DIGITAL_VOLUME_2, + PCM512x_DIGITAL_VOLUME_3, 0, 255, 1, digital_tlv), +SOC_DOUBLE_TLV("Playback Volume", PCM512x_ANALOG_GAIN_CTRL, + PCM512x_LAGN_SHIFT, PCM512x_RAGN_SHIFT, 1, 1, analog_tlv), +SOC_DOUBLE_TLV("Playback Boost Volume", PCM512x_ANALOG_GAIN_BOOST, + PCM512x_AGBL_SHIFT, PCM512x_AGBR_SHIFT, 1, 0, boost_tlv), SOC_DOUBLE("Playback Digital Switch", PCM512x_MUTE, PCM512x_RQML_SHIFT, PCM512x_RQMR_SHIFT, 1, 1), @@ -343,27 +365,32 @@ static struct snd_soc_codec_driver pcm512x_codec_driver = { .num_dapm_routes = ARRAY_SIZE(pcm512x_dapm_routes), }; -static const struct regmap_config pcm512x_regmap = { +static const struct regmap_range_cfg pcm512x_range = { + .name = "Pages", .range_min = PCM512x_VIRT_BASE, + .range_max = PCM512x_MAX_REGISTER, + .selector_reg = PCM512x_PAGE, + .selector_mask = 0xff, + .window_start = 0, .window_len = 0x100, +}; + +const struct regmap_config pcm512x_regmap = { .reg_bits = 8, .val_bits = 8, .readable_reg = pcm512x_readable, .volatile_reg = pcm512x_volatile, + .ranges = &pcm512x_range, + .num_ranges = 1, + .max_register = PCM512x_MAX_REGISTER, .reg_defaults = pcm512x_reg_defaults, .num_reg_defaults = ARRAY_SIZE(pcm512x_reg_defaults), .cache_type = REGCACHE_RBTREE, }; +EXPORT_SYMBOL_GPL(pcm512x_regmap); -static const struct of_device_id pcm512x_of_match[] = { - { .compatible = "ti,pcm5121", }, - { .compatible = "ti,pcm5122", }, - { } -}; -MODULE_DEVICE_TABLE(of, pcm512x_of_match); - -static int pcm512x_probe(struct device *dev, struct regmap *regmap) +int pcm512x_probe(struct device *dev, struct regmap *regmap) { struct pcm512x_priv *pcm512x; int i, ret; @@ -463,8 +490,6 @@ static int pcm512x_probe(struct device *dev, struct regmap *regmap) goto err_pm; } - dev_info(dev, "Completed initialisation - pcm512x_probe"); - return 0; err_pm: @@ -477,8 +502,9 @@ static int pcm512x_probe(struct device *dev, struct regmap *regmap) pcm512x->supplies); return ret; } +EXPORT_SYMBOL_GPL(pcm512x_probe); -static void pcm512x_remove(struct device *dev) +void pcm512x_remove(struct device *dev) { struct pcm512x_priv *pcm512x = dev_get_drvdata(dev); @@ -489,8 +515,8 @@ static void pcm512x_remove(struct device *dev) regulator_bulk_disable(ARRAY_SIZE(pcm512x->supplies), pcm512x->supplies); } +EXPORT_SYMBOL_GPL(pcm512x_remove); -/* TODO static int pcm512x_suspend(struct device *dev) { struct pcm512x_priv *pcm512x = dev_get_drvdata(dev); @@ -553,125 +579,10 @@ static int pcm512x_resume(struct device *dev) return 0; } -// END OF PCM512x_suspend and resume calls TODO -*/ - -static const struct dev_pm_ops pcm512x_pm_ops = { +const struct dev_pm_ops pcm512x_pm_ops = { SET_RUNTIME_PM_OPS(pcm512x_suspend, pcm512x_resume, NULL) }; - -#if IS_ENABLED(CONFIG_I2C) -static int pcm512x_i2c_probe(struct i2c_client *i2c, - const struct i2c_device_id *id) -{ - struct regmap *regmap; - - regmap = devm_regmap_init_i2c(i2c, &pcm512x_regmap); - if (IS_ERR(regmap)) - return PTR_ERR(regmap); - - return pcm512x_probe(&i2c->dev, regmap); -} - -static int pcm512x_i2c_remove(struct i2c_client *i2c) -{ - pcm512x_remove(&i2c->dev); - return 0; -} - -static const struct i2c_device_id pcm512x_i2c_id[] = { - { "pcm5121", }, - { "pcm5122", }, - { } -}; -MODULE_DEVICE_TABLE(i2c, pcm512x_i2c_id); - -static struct i2c_driver pcm512x_i2c_driver = { - .probe = pcm512x_i2c_probe, - .remove = pcm512x_i2c_remove, - .id_table = pcm512x_i2c_id, - .driver = { - .name = "pcm512x", - .owner = THIS_MODULE, - .of_match_table = pcm512x_of_match, - .pm = &pcm512x_pm_ops, - }, -}; -#endif - -#if defined(CONFIG_SPI_MASTER) -static int pcm512x_spi_probe(struct spi_device *spi) -{ - struct regmap *regmap; - int ret; - - regmap = devm_regmap_init_spi(spi, &pcm512x_regmap); - if (IS_ERR(regmap)) { - ret = PTR_ERR(regmap); - return ret; - } - - return pcm512x_probe(&spi->dev, regmap); -} - -static int pcm512x_spi_remove(struct spi_device *spi) -{ - pcm512x_remove(&spi->dev); - return 0; -} - -static const struct spi_device_id pcm512x_spi_id[] = { - { "pcm5121", }, - { "pcm5122", }, - { }, -}; -MODULE_DEVICE_TABLE(spi, pcm512x_spi_id); - -static struct spi_driver pcm512x_spi_driver = { - .probe = pcm512x_spi_probe, - .remove = pcm512x_spi_remove, - .id_table = pcm512x_spi_id, - .driver = { - .name = "pcm512x", - .owner = THIS_MODULE, - .of_match_table = pcm512x_of_match, - .pm = &pcm512x_pm_ops, - }, -}; -#endif - -static int __init pcm512x_modinit(void) -{ - int ret = 0; - -#if IS_ENABLED(CONFIG_I2C) - ret = i2c_add_driver(&pcm512x_i2c_driver); - if (ret) { - printk(KERN_ERR "Failed to register pcm512x I2C driver: %d\n", - ret); - } -#endif -#if defined(CONFIG_SPI_MASTER) - ret = spi_register_driver(&pcm512x_spi_driver); - if (ret != 0) { - printk(KERN_ERR "Failed to register pcm512x SPI driver: %d\n", - ret); - } -#endif - return ret; -} -module_init(pcm512x_modinit); - -static void __exit pcm512x_exit(void) -{ -#if IS_ENABLED(CONFIG_I2C) - i2c_del_driver(&pcm512x_i2c_driver); -#endif -#if defined(CONFIG_SPI_MASTER) - spi_unregister_driver(&pcm512x_spi_driver); -#endif -} -module_exit(pcm512x_exit); +EXPORT_SYMBOL_GPL(pcm512x_pm_ops); MODULE_DESCRIPTION("ASoC PCM512x codec driver"); MODULE_AUTHOR("Mark Brown "); diff --git a/sound/soc/codecs/pcm512x.h b/sound/soc/codecs/pcm512x.h index b2f518ecb35cbe..6ee76aaca09a0a 100644 --- a/sound/soc/codecs/pcm512x.h +++ b/sound/soc/codecs/pcm512x.h @@ -17,66 +17,81 @@ #ifndef _SND_SOC_PCM512X #define _SND_SOC_PCM512X -#define PCM512x_PAGE_0_BASE 0 +#include +#include + +#define PCM512x_VIRT_BASE 0x100 +#define PCM512x_PAGE_LEN 0x100 +#define PCM512x_PAGE_BASE(n) (PCM512x_VIRT_BASE + (PCM512x_PAGE_LEN * n)) #define PCM512x_PAGE 0 -#define PCM512x_RESET (PCM512x_PAGE_0_BASE + 1) -#define PCM512x_POWER (PCM512x_PAGE_0_BASE + 2) -#define PCM512x_MUTE (PCM512x_PAGE_0_BASE + 3) -#define PCM512x_PLL_EN (PCM512x_PAGE_0_BASE + 4) -#define PCM512x_SPI_MISO_FUNCTION (PCM512x_PAGE_0_BASE + 6) -#define PCM512x_DSP (PCM512x_PAGE_0_BASE + 7) -#define PCM512x_GPIO_EN (PCM512x_PAGE_0_BASE + 8) -#define PCM512x_BCLK_LRCLK_CFG (PCM512x_PAGE_0_BASE + 9) -#define PCM512x_DSP_GPIO_INPUT (PCM512x_PAGE_0_BASE + 10) -#define PCM512x_MASTER_MODE (PCM512x_PAGE_0_BASE + 12) -#define PCM512x_PLL_REF (PCM512x_PAGE_0_BASE + 13) -#define PCM512x_PLL_COEFF_0 (PCM512x_PAGE_0_BASE + 20) -#define PCM512x_PLL_COEFF_1 (PCM512x_PAGE_0_BASE + 21) -#define PCM512x_PLL_COEFF_2 (PCM512x_PAGE_0_BASE + 22) -#define PCM512x_PLL_COEFF_3 (PCM512x_PAGE_0_BASE + 23) -#define PCM512x_PLL_COEFF_4 (PCM512x_PAGE_0_BASE + 24) -#define PCM512x_DSP_CLKDIV (PCM512x_PAGE_0_BASE + 27) -#define PCM512x_DAC_CLKDIV (PCM512x_PAGE_0_BASE + 28) -#define PCM512x_NCP_CLKDIV (PCM512x_PAGE_0_BASE + 29) -#define PCM512x_OSR_CLKDIV (PCM512x_PAGE_0_BASE + 30) -#define PCM512x_MASTER_CLKDIV_1 (PCM512x_PAGE_0_BASE + 32) -#define PCM512x_MASTER_CLKDIV_2 (PCM512x_PAGE_0_BASE + 33) -#define PCM512x_FS_SPEED_MODE (PCM512x_PAGE_0_BASE + 34) -#define PCM512x_IDAC_1 (PCM512x_PAGE_0_BASE + 35) -#define PCM512x_IDAC_2 (PCM512x_PAGE_0_BASE + 36) -#define PCM512x_ERROR_DETECT (PCM512x_PAGE_0_BASE + 37) -#define PCM512x_I2S_1 (PCM512x_PAGE_0_BASE + 40) -#define PCM512x_I2S_2 (PCM512x_PAGE_0_BASE + 41) -#define PCM512x_DAC_ROUTING (PCM512x_PAGE_0_BASE + 42) -#define PCM512x_DSP_PROGRAM (PCM512x_PAGE_0_BASE + 43) -#define PCM512x_CLKDET (PCM512x_PAGE_0_BASE + 44) -#define PCM512x_AUTO_MUTE (PCM512x_PAGE_0_BASE + 59) -#define PCM512x_DIGITAL_VOLUME_1 (PCM512x_PAGE_0_BASE + 60) -#define PCM512x_DIGITAL_VOLUME_2 (PCM512x_PAGE_0_BASE + 61) -#define PCM512x_DIGITAL_VOLUME_3 (PCM512x_PAGE_0_BASE + 62) -#define PCM512x_DIGITAL_MUTE_1 (PCM512x_PAGE_0_BASE + 63) -#define PCM512x_DIGITAL_MUTE_2 (PCM512x_PAGE_0_BASE + 64) -#define PCM512x_DIGITAL_MUTE_3 (PCM512x_PAGE_0_BASE + 65) -#define PCM512x_GPIO_OUTPUT_1 (PCM512x_PAGE_0_BASE + 80) -#define PCM512x_GPIO_OUTPUT_2 (PCM512x_PAGE_0_BASE + 81) -#define PCM512x_GPIO_OUTPUT_3 (PCM512x_PAGE_0_BASE + 82) -#define PCM512x_GPIO_OUTPUT_4 (PCM512x_PAGE_0_BASE + 83) -#define PCM512x_GPIO_OUTPUT_5 (PCM512x_PAGE_0_BASE + 84) -#define PCM512x_GPIO_OUTPUT_6 (PCM512x_PAGE_0_BASE + 85) -#define PCM512x_GPIO_CONTROL_1 (PCM512x_PAGE_0_BASE + 86) -#define PCM512x_GPIO_CONTROL_2 (PCM512x_PAGE_0_BASE + 87) -#define PCM512x_OVERFLOW (PCM512x_PAGE_0_BASE + 90) -#define PCM512x_RATE_DET_1 (PCM512x_PAGE_0_BASE + 91) -#define PCM512x_RATE_DET_2 (PCM512x_PAGE_0_BASE + 92) -#define PCM512x_RATE_DET_3 (PCM512x_PAGE_0_BASE + 93) -#define PCM512x_RATE_DET_4 (PCM512x_PAGE_0_BASE + 94) -#define PCM512x_ANALOG_MUTE_DET (PCM512x_PAGE_0_BASE + 108) -#define PCM512x_GPIN (PCM512x_PAGE_0_BASE + 119) -#define PCM512x_DIGITAL_MUTE_DET (PCM512x_PAGE_0_BASE + 120) - -#define PCM512x_MAX_REGISTER (PCM512x_PAGE_0_BASE + 120) +#define PCM512x_RESET (PCM512x_PAGE_BASE(0) + 1) +#define PCM512x_POWER (PCM512x_PAGE_BASE(0) + 2) +#define PCM512x_MUTE (PCM512x_PAGE_BASE(0) + 3) +#define PCM512x_PLL_EN (PCM512x_PAGE_BASE(0) + 4) +#define PCM512x_SPI_MISO_FUNCTION (PCM512x_PAGE_BASE(0) + 6) +#define PCM512x_DSP (PCM512x_PAGE_BASE(0) + 7) +#define PCM512x_GPIO_EN (PCM512x_PAGE_BASE(0) + 8) +#define PCM512x_BCLK_LRCLK_CFG (PCM512x_PAGE_BASE(0) + 9) +#define PCM512x_DSP_GPIO_INPUT (PCM512x_PAGE_BASE(0) + 10) +#define PCM512x_MASTER_MODE (PCM512x_PAGE_BASE(0) + 12) +#define PCM512x_PLL_REF (PCM512x_PAGE_BASE(0) + 13) +#define PCM512x_PLL_COEFF_0 (PCM512x_PAGE_BASE(0) + 20) +#define PCM512x_PLL_COEFF_1 (PCM512x_PAGE_BASE(0) + 21) +#define PCM512x_PLL_COEFF_2 (PCM512x_PAGE_BASE(0) + 22) +#define PCM512x_PLL_COEFF_3 (PCM512x_PAGE_BASE(0) + 23) +#define PCM512x_PLL_COEFF_4 (PCM512x_PAGE_BASE(0) + 24) +#define PCM512x_DSP_CLKDIV (PCM512x_PAGE_BASE(0) + 27) +#define PCM512x_DAC_CLKDIV (PCM512x_PAGE_BASE(0) + 28) +#define PCM512x_NCP_CLKDIV (PCM512x_PAGE_BASE(0) + 29) +#define PCM512x_OSR_CLKDIV (PCM512x_PAGE_BASE(0) + 30) +#define PCM512x_MASTER_CLKDIV_1 (PCM512x_PAGE_BASE(0) + 32) +#define PCM512x_MASTER_CLKDIV_2 (PCM512x_PAGE_BASE(0) + 33) +#define PCM512x_FS_SPEED_MODE (PCM512x_PAGE_BASE(0) + 34) +#define PCM512x_IDAC_1 (PCM512x_PAGE_BASE(0) + 35) +#define PCM512x_IDAC_2 (PCM512x_PAGE_BASE(0) + 36) +#define PCM512x_ERROR_DETECT (PCM512x_PAGE_BASE(0) + 37) +#define PCM512x_I2S_1 (PCM512x_PAGE_BASE(0) + 40) +#define PCM512x_I2S_2 (PCM512x_PAGE_BASE(0) + 41) +#define PCM512x_DAC_ROUTING (PCM512x_PAGE_BASE(0) + 42) +#define PCM512x_DSP_PROGRAM (PCM512x_PAGE_BASE(0) + 43) +#define PCM512x_CLKDET (PCM512x_PAGE_BASE(0) + 44) +#define PCM512x_AUTO_MUTE (PCM512x_PAGE_BASE(0) + 59) +#define PCM512x_DIGITAL_VOLUME_1 (PCM512x_PAGE_BASE(0) + 60) +#define PCM512x_DIGITAL_VOLUME_2 (PCM512x_PAGE_BASE(0) + 61) +#define PCM512x_DIGITAL_VOLUME_3 (PCM512x_PAGE_BASE(0) + 62) +#define PCM512x_DIGITAL_MUTE_1 (PCM512x_PAGE_BASE(0) + 63) +#define PCM512x_DIGITAL_MUTE_2 (PCM512x_PAGE_BASE(0) + 64) +#define PCM512x_DIGITAL_MUTE_3 (PCM512x_PAGE_BASE(0) + 65) +#define PCM512x_GPIO_OUTPUT_1 (PCM512x_PAGE_BASE(0) + 80) +#define PCM512x_GPIO_OUTPUT_2 (PCM512x_PAGE_BASE(0) + 81) +#define PCM512x_GPIO_OUTPUT_3 (PCM512x_PAGE_BASE(0) + 82) +#define PCM512x_GPIO_OUTPUT_4 (PCM512x_PAGE_BASE(0) + 83) +#define PCM512x_GPIO_OUTPUT_5 (PCM512x_PAGE_BASE(0) + 84) +#define PCM512x_GPIO_OUTPUT_6 (PCM512x_PAGE_BASE(0) + 85) +#define PCM512x_GPIO_CONTROL_1 (PCM512x_PAGE_BASE(0) + 86) +#define PCM512x_GPIO_CONTROL_2 (PCM512x_PAGE_BASE(0) + 87) +#define PCM512x_OVERFLOW (PCM512x_PAGE_BASE(0) + 90) +#define PCM512x_RATE_DET_1 (PCM512x_PAGE_BASE(0) + 91) +#define PCM512x_RATE_DET_2 (PCM512x_PAGE_BASE(0) + 92) +#define PCM512x_RATE_DET_3 (PCM512x_PAGE_BASE(0) + 93) +#define PCM512x_RATE_DET_4 (PCM512x_PAGE_BASE(0) + 94) +#define PCM512x_ANALOG_MUTE_DET (PCM512x_PAGE_BASE(0) + 108) +#define PCM512x_GPIN (PCM512x_PAGE_BASE(0) + 119) +#define PCM512x_DIGITAL_MUTE_DET (PCM512x_PAGE_BASE(0) + 120) + +#define PCM512x_OUTPUT_AMPLITUDE (PCM512x_PAGE_BASE(1) + 1) +#define PCM512x_ANALOG_GAIN_CTRL (PCM512x_PAGE_BASE(1) + 2) +#define PCM512x_UNDERVOLTAGE_PROT (PCM512x_PAGE_BASE(1) + 5) +#define PCM512x_ANALOG_MUTE_CTRL (PCM512x_PAGE_BASE(1) + 6) +#define PCM512x_ANALOG_GAIN_BOOST (PCM512x_PAGE_BASE(1) + 7) +#define PCM512x_VCOM_CTRL_1 (PCM512x_PAGE_BASE(1) + 8) +#define PCM512x_VCOM_CTRL_2 (PCM512x_PAGE_BASE(1) + 9) + +#define PCM512x_CRAM_CTRL (PCM512x_PAGE_BASE(44) + 1) + +#define PCM512x_MAX_REGISTER (PCM512x_PAGE_BASE(44) + 1) /* Page 0, Register 1 - reset */ #define PCM512x_RSTR (1 << 0) @@ -139,4 +154,18 @@ #define PCM512x_AMLE_SHIFT 1 #define PCM512x_AMLR_SHIFT 0 +/* Page 1, Register 2 - analog volume control */ +#define PCM512x_RAGN_SHIFT 0 +#define PCM512x_LAGN_SHIFT 4 + +/* Page 1, Register 7 - analog boost control */ +#define PCM512x_AGBR_SHIFT 0 +#define PCM512x_AGBL_SHIFT 4 + +extern const struct dev_pm_ops pcm512x_pm_ops; +extern const struct regmap_config pcm512x_regmap; + +int pcm512x_probe(struct device *dev, struct regmap *regmap); +void pcm512x_remove(struct device *dev); + #endif From 0a5d48a65a72b4eed8da1b3e84a1ba4886d6552b Mon Sep 17 00:00:00 2001 From: Gordon Garrity Date: Sat, 8 Mar 2014 16:56:57 +0000 Subject: [PATCH 4/6] Add IQaudIO Sound Card support for Raspberry Pi --- arch/arm/configs/bcmrpi_defconfig | 1 + arch/arm/mach-bcm2708/bcm2708.c | 22 ++++++ sound/soc/bcm/Kconfig | 7 ++ sound/soc/bcm/Makefile | 2 + sound/soc/bcm/iqaudio-dac.c | 111 ++++++++++++++++++++++++++++++ 5 files changed, 143 insertions(+) create mode 100644 sound/soc/bcm/iqaudio-dac.c diff --git a/arch/arm/configs/bcmrpi_defconfig b/arch/arm/configs/bcmrpi_defconfig index 9888fc959c0278..29fe486f3c6524 100644 --- a/arch/arm/configs/bcmrpi_defconfig +++ b/arch/arm/configs/bcmrpi_defconfig @@ -751,6 +751,7 @@ CONFIG_SND_BCM2708_SOC_RPI_DAC=m CONFIG_SND_SOC_I2C_AND_SPI=m CONFIG_SND_SOC_PCM5102A=m CONFIG_SND_SOC_PCM1794A=m +CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC=m CONFIG_SOUND_PRIME=m CONFIG_HIDRAW=y CONFIG_HID_A4TECH=m diff --git a/arch/arm/mach-bcm2708/bcm2708.c b/arch/arm/mach-bcm2708/bcm2708.c index da3849226a130f..f67e5521de566c 100644 --- a/arch/arm/mach-bcm2708/bcm2708.c +++ b/arch/arm/mach-bcm2708/bcm2708.c @@ -674,6 +674,22 @@ static struct platform_device snd_pcm1794a_codec_device = { }; #endif + +#if defined(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) || defined(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC_MODULE) +static struct platform_device snd_rpi_iqaudio_dac_device = { + .name = "snd-rpi-iqaudio-dac", + .id = 0, + .num_resources = 0, +}; + +// Use the actual device name rather than generic driver name +static struct i2c_board_info __initdata snd_pcm512x_i2c_devices[] = { + { + I2C_BOARD_INFO("pcm5122", 0x4c) + }, +}; +#endif + int __init bcm_register_device(struct platform_device *pdev) { int ret; @@ -839,6 +855,12 @@ void __init bcm2708_init(void) bcm_register_device(&snd_pcm1794a_codec_device); #endif +#if defined(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) || defined(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC_MODULE) + bcm_register_device(&snd_rpi_iqaudio_dac_device); + i2c_register_board_info(1, snd_pcm512x_i2c_devices, ARRAY_SIZE(snd_pcm512x_i2c_devices)); +#endif + + for (i = 0; i < ARRAY_SIZE(amba_devs); i++) { struct amba_device *d = amba_devs[i]; amba_device_register(d, &iomem_resource); diff --git a/sound/soc/bcm/Kconfig b/sound/soc/bcm/Kconfig index e563dbcb0513b2..c621a5e50da7d0 100644 --- a/sound/soc/bcm/Kconfig +++ b/sound/soc/bcm/Kconfig @@ -39,3 +39,10 @@ config SND_BCM2708_SOC_RPI_DAC select SND_SOC_PCM1794A help Say Y or M if you want to add support for RPi-DAC. + +config SND_BCM2708_SOC_IQAUDIO_DAC + tristate "Support for IQaudIO-DAC" + depends on SND_BCM2708_SOC_I2S + select SND_SOC_PCM512x_I2C + help + Say Y or M if you want to add support for IQaudIO-DAC. diff --git a/sound/soc/bcm/Makefile b/sound/soc/bcm/Makefile index 826df7d3e85464..d597fb09482a1b 100644 --- a/sound/soc/bcm/Makefile +++ b/sound/soc/bcm/Makefile @@ -12,7 +12,9 @@ obj-$(CONFIG_SND_BCM2708_SOC_I2S) += snd-soc-bcm2708-i2s.o snd-soc-hifiberry-dac-objs := hifiberry_dac.o snd-soc-hifiberry-digi-objs := hifiberry_digi.o snd-soc-rpi-dac-objs := rpi-dac.o +snd-soc-iqaudio-dac-objs := iqaudio-dac.o obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) += snd-soc-hifiberry-dac.o obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) += snd-soc-hifiberry-digi.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 diff --git a/sound/soc/bcm/iqaudio-dac.c b/sound/soc/bcm/iqaudio-dac.c new file mode 100644 index 00000000000000..8d0e2aebad97f1 --- /dev/null +++ b/sound/soc/bcm/iqaudio-dac.c @@ -0,0 +1,111 @@ +/* + * ASoC Driver for IQaudIO DAC + * + * Author: Florian Meier + * Copyright 2013 + * + * 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 + +static int snd_rpi_iqaudio_dac_init(struct snd_soc_pcm_runtime *rtd) +{ +// NOT USED struct snd_soc_codec *codec = rtd->codec; + + return 0; +} + +static int snd_rpi_iqaudio_dac_hw_params(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *params) +{ + struct snd_soc_pcm_runtime *rtd = substream->private_data; +// NOT USED struct snd_soc_dai *codec_dai = rtd->codec_dai; +// NOT USED struct snd_soc_codec *codec = rtd->codec; + 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_iqaudio_dac_ops = { + .hw_params = snd_rpi_iqaudio_dac_hw_params, +}; + +static struct snd_soc_dai_link snd_rpi_iqaudio_dac_dai[] = { +{ + .name = "IQaudIO DAC", + .stream_name = "IQaudIO DAC HiFi", + .cpu_dai_name = "bcm2708-i2s.0", + .codec_dai_name = "pcm512x-hifi", + .platform_name = "bcm2708-i2s.0", + .codec_name = "pcm512x.1-004c", + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | + SND_SOC_DAIFMT_CBS_CFS, + .ops = &snd_rpi_iqaudio_dac_ops, + .init = snd_rpi_iqaudio_dac_init, +}, +}; + +/* audio machine driver */ +static struct snd_soc_card snd_rpi_iqaudio_dac = { + .name = "IQaudIODAC", + .dai_link = snd_rpi_iqaudio_dac_dai, + .num_links = ARRAY_SIZE(snd_rpi_iqaudio_dac_dai), +}; + +static int snd_rpi_iqaudio_dac_probe(struct platform_device *pdev) +{ + int ret = 0; + + snd_rpi_iqaudio_dac.dev = &pdev->dev; + ret = snd_soc_register_card(&snd_rpi_iqaudio_dac); + if (ret) + dev_err(&pdev->dev, + "snd_soc_register_card() failed: %d\n", ret); + + return ret; +} + +static int snd_rpi_iqaudio_dac_remove(struct platform_device *pdev) +{ + return snd_soc_unregister_card(&snd_rpi_iqaudio_dac); +} + +static const struct of_device_id iqaudio_of_match[] = { + { .compatible = "iqaudio,iqaudio-dac", }, + {}, +}; + +static struct platform_driver snd_rpi_iqaudio_dac_driver = { + .driver = { + .name = "snd-rpi-iqaudio-dac", + .owner = THIS_MODULE, + .of_match_table = iqaudio_of_match, + }, + .probe = snd_rpi_iqaudio_dac_probe, + .remove = snd_rpi_iqaudio_dac_remove, +}; + +module_platform_driver(snd_rpi_iqaudio_dac_driver); + +MODULE_AUTHOR("Florian Meier "); +MODULE_DESCRIPTION("ASoC Driver for IQAudio DAC"); +MODULE_LICENSE("GPL v2"); From 38d43a3c52731319ed078146de6acc000dfa1837 Mon Sep 17 00:00:00 2001 From: Howard Mitchell Date: Wed, 30 Jul 2014 21:43:37 +0100 Subject: [PATCH 5/6] soc-core: Fix volsw_range funcs so SOC_DOUBLE_R_RANGE_TLV works. This is so that the correct range of values as specified with the SOC_DOUBLE_R_RANGE_TLV macro are sent to the hardware for both the normal and invert cases. --- sound/soc/soc-core.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 051c006281f5c2..4d8917b9e11a94 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -3024,8 +3024,8 @@ int snd_soc_info_volsw_range(struct snd_kcontrol *kcontrol, uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; uinfo->count = snd_soc_volsw_is_stereo(mc) ? 2 : 1; - uinfo->value.integer.min = 0; - uinfo->value.integer.max = platform_max - min; + uinfo->value.integer.min = min; + uinfo->value.integer.max = platform_max; return 0; } @@ -3056,9 +3056,10 @@ int snd_soc_put_volsw_range(struct snd_kcontrol *kcontrol, unsigned int val, val_mask; int ret; - val = ((ucontrol->value.integer.value[0] + min) & mask); if (invert) - val = max - val; + val = ((max - ucontrol->value.integer.value[0] + min) & mask); + else + val = (ucontrol->value.integer.value[0] & mask); val_mask = mask << shift; val = val << shift; @@ -3067,9 +3068,10 @@ int snd_soc_put_volsw_range(struct snd_kcontrol *kcontrol, return ret; if (snd_soc_volsw_is_stereo(mc)) { - val = ((ucontrol->value.integer.value[1] + min) & mask); if (invert) - val = max - val; + val = ((max - ucontrol->value.integer.value[1] + min) & mask); + else + val = (ucontrol->value.integer.value[1] & mask); val_mask = mask << shift; val = val << shift; @@ -3107,18 +3109,14 @@ int snd_soc_get_volsw_range(struct snd_kcontrol *kcontrol, (snd_soc_read(codec, reg) >> shift) & mask; if (invert) ucontrol->value.integer.value[0] = - max - ucontrol->value.integer.value[0]; - ucontrol->value.integer.value[0] = - ucontrol->value.integer.value[0] - min; + max - ucontrol->value.integer.value[0] + min; if (snd_soc_volsw_is_stereo(mc)) { ucontrol->value.integer.value[1] = (snd_soc_read(codec, rreg) >> shift) & mask; if (invert) ucontrol->value.integer.value[1] = - max - ucontrol->value.integer.value[1]; - ucontrol->value.integer.value[1] = - ucontrol->value.integer.value[1] - min; + max - ucontrol->value.integer.value[1] + min; } return 0; From 8f39c5cb44f74baabbd511a82c212e675f097ddd Mon Sep 17 00:00:00 2001 From: Howard Mitchell Date: Fri, 28 Mar 2014 16:40:31 +0000 Subject: [PATCH 6/6] pcm512x: Use a range macro for Volume and rename to PCM. This allows limiting the output gain to avoid clipping in the DAC ouput stages. --- sound/soc/codecs/pcm512x.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sound/soc/codecs/pcm512x.c b/sound/soc/codecs/pcm512x.c index 4b4c0c7bb918fe..ec7e034da19738 100644 --- a/sound/soc/codecs/pcm512x.c +++ b/sound/soc/codecs/pcm512x.c @@ -259,8 +259,8 @@ static const struct soc_enum pcm512x_veds = pcm512x_ramp_step_text); static const struct snd_kcontrol_new pcm512x_controls[] = { -SOC_DOUBLE_R_TLV("Playback Digital Volume", PCM512x_DIGITAL_VOLUME_2, - PCM512x_DIGITAL_VOLUME_3, 0, 255, 1, digital_tlv), +SOC_DOUBLE_R_RANGE_TLV("PCM", PCM512x_DIGITAL_VOLUME_2, + PCM512x_DIGITAL_VOLUME_3, 0, 40, 255, 1, digital_tlv), SOC_DOUBLE_TLV("Playback Volume", PCM512x_ANALOG_GAIN_CTRL, PCM512x_LAGN_SHIFT, PCM512x_RAGN_SHIFT, 1, 1, analog_tlv), SOC_DOUBLE_TLV("Playback Boost Volume", PCM512x_ANALOG_GAIN_BOOST,