From f2428c1dff932a5f15edc2335908113dd9b60599 Mon Sep 17 00:00:00 2001 From: Zheng Yang Date: Tue, 21 Aug 2012 09:50:46 +0800 Subject: [PATCH] rk2928: acodec: move audio codec platform device registration to board file to configure speaker control pin. --- arch/arm/mach-rk2928/board-rk2928-a720.c | 25 ++++++++++++++++++ arch/arm/mach-rk2928/board-rk2928-sdk.c | 25 ++++++++++++++++++ arch/arm/mach-rk2928/devices.c | 20 -------------- sound/soc/codecs/rk2928_codec.c | 33 +++++++++++++++--------- 4 files changed, 71 insertions(+), 32 deletions(-) diff --git a/arch/arm/mach-rk2928/board-rk2928-a720.c b/arch/arm/mach-rk2928/board-rk2928-a720.c index 0bc1895fc61b..9ee25c281577 100755 --- a/arch/arm/mach-rk2928/board-rk2928-a720.c +++ b/arch/arm/mach-rk2928/board-rk2928-a720.c @@ -436,6 +436,28 @@ struct rk29_sdmmc_platform_data default_sdmmc0_data = { }; #endif // CONFIG_SDMMC0_RK29 +#ifdef CONFIG_SND_SOC_RK2928 +static struct resource resources_acodec[] = { + { + .start = RK2928_ACODEC_PHYS, + .end = RK2928_ACODEC_PHYS + RK2928_ACODEC_SIZE - 1, + .flags = IORESOURCE_MEM, + }, + { + .start = RK2928_PIN1_PA0, + .end = RK2928_PIN1_PA0, + .flags = IORESOURCE_IO, + }, +}; + +static struct platform_device device_acodec = { + .name = "rk2928-codec", + .id = -1, + .num_resources = ARRAY_SIZE(resources_acodec), + .resource = resources_acodec, +}; +#endif + static struct platform_device *devices[] __initdata = { #ifdef CONFIG_BACKLIGHT_RK29_BL &rk29_device_backlight, @@ -446,6 +468,9 @@ static struct platform_device *devices[] __initdata = { #ifdef CONFIG_ION &device_ion, #endif +#ifdef CONFIG_SND_SOC_RK2928 + &device_acodec, +#endif }; //i2c #ifdef CONFIG_I2C0_RK30 diff --git a/arch/arm/mach-rk2928/board-rk2928-sdk.c b/arch/arm/mach-rk2928/board-rk2928-sdk.c index 0eb825055991..0e743011f20f 100755 --- a/arch/arm/mach-rk2928/board-rk2928-sdk.c +++ b/arch/arm/mach-rk2928/board-rk2928-sdk.c @@ -636,6 +636,28 @@ static struct platform_device device_rfkill_rk = { }; #endif +#ifdef CONFIG_SND_SOC_RK2928 +static struct resource resources_acodec[] = { + { + .start = RK2928_ACODEC_PHYS, + .end = RK2928_ACODEC_PHYS + RK2928_ACODEC_SIZE - 1, + .flags = IORESOURCE_MEM, + }, + { + .start = RK2928_PIN3_PD4, + .end = RK2928_PIN3_PD4, + .flags = IORESOURCE_IO, + }, +}; + +static struct platform_device device_acodec = { + .name = "rk2928-codec", + .id = -1, + .num_resources = ARRAY_SIZE(resources_acodec), + .resource = resources_acodec, +}; +#endif + static struct platform_device *devices[] __initdata = { #ifdef CONFIG_BACKLIGHT_RK29_BL &rk29_device_backlight, @@ -652,6 +674,9 @@ static struct platform_device *devices[] __initdata = { #ifdef CONFIG_RFKILL_RK &device_rfkill_rk, #endif +#ifdef CONFIG_SND_SOC_RK2928 + &device_acodec, +#endif }; //i2c #ifdef CONFIG_I2C0_RK30 diff --git a/arch/arm/mach-rk2928/devices.c b/arch/arm/mach-rk2928/devices.c index 9be98c671c93..c5eab43b1f3f 100755 --- a/arch/arm/mach-rk2928/devices.c +++ b/arch/arm/mach-rk2928/devices.c @@ -786,23 +786,6 @@ static void __init rk2928_init_sdmmc(void) #endif } -#ifdef CONFIG_SND_SOC_RK2928 -static struct resource resources_acodec[] = { - { - .start = RK2928_ACODEC_PHYS, - .end = RK2928_ACODEC_PHYS + RK2928_ACODEC_SIZE - 1, - .flags = IORESOURCE_MEM, - }, -}; - -static struct platform_device device_acodec = { - .name = "rk2928-codec", - .id = -1, - .num_resources = ARRAY_SIZE(resources_acodec), - .resource = resources_acodec, -}; -#endif - static struct resource resource_arm_pmu = { .start = IRQ_ARM_PMU, .end = IRQ_ARM_PMU, @@ -848,9 +831,6 @@ static int __init rk2928_init_devices(void) rk_serial_debug_init(DEBUG_UART_BASE, IRQ_DEBUG_UART, IRQ_UART_SIGNAL, -1); #endif rk2928_init_i2s(); -#ifdef CONFIG_SND_SOC_RK2928 - platform_device_register(&device_acodec); -#endif #ifdef CONFIG_HDMI_RK2928 platform_device_register(&device_hdmi); #endif diff --git a/sound/soc/codecs/rk2928_codec.c b/sound/soc/codecs/rk2928_codec.c index 54a75a2ec61c..a31276077b7d 100755 --- a/sound/soc/codecs/rk2928_codec.c +++ b/sound/soc/codecs/rk2928_codec.c @@ -41,8 +41,6 @@ #include "rk2928_codec.h" -#define SPK_CTL RK2928_PIN1_PA0 - static struct rk2928_codec_data { struct device *dev; int regbase; @@ -50,6 +48,7 @@ static struct rk2928_codec_data { int regsize_phy; int mute; int hdmi_enable; + int spkctl; } rk2928_data; static const struct snd_soc_dapm_widget rk2928_dapm_widgets[] = { @@ -149,8 +148,8 @@ static int rk2928_audio_trigger(struct snd_pcm_substream *substream, int cmd, if(!rk2928_data.hdmi_enable) rk2928_write(codec, CODEC_REG_DAC_MUTE, v_MUTE_DAC(0)); rk2928_data.mute = 0; - if(SPK_CTL != INVALID_GPIO) { - gpio_direction_output(SPK_CTL, GPIO_HIGH); + if(rk2928_data.spkctl != INVALID_GPIO) { + gpio_direction_output(rk2928_data.spkctl, GPIO_HIGH); } } else { @@ -163,8 +162,8 @@ static int rk2928_audio_trigger(struct snd_pcm_substream *substream, int cmd, case SNDRV_PCM_TRIGGER_SUSPEND: case SNDRV_PCM_TRIGGER_PAUSE_PUSH: if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { - if(SPK_CTL != INVALID_GPIO) { - gpio_direction_output(SPK_CTL, GPIO_LOW); + if(rk2928_data.spkctl != INVALID_GPIO) { + gpio_direction_output(rk2928_data.spkctl, GPIO_LOW); } rk2928_write(codec, CODEC_REG_DAC_MUTE, v_MUTE_DAC(1)); rk2928_data.mute = 1; @@ -246,17 +245,27 @@ static int rk2928_probe(struct snd_soc_codec *codec) ret = -ENXIO; goto err1; } - // Select SDI input from internal audio codec - writel(0x04000400, RK2928_GRF_BASE + GRF_SOC_CON0); - if(SPK_CTL != INVALID_GPIO) { - ret = gpio_request(SPK_CTL, NULL); + res = platform_get_resource(pdev, IORESOURCE_IO, 0); + if(!res) { + rk2928_data.spkctl = INVALID_GPIO; + } + else { + rk2928_data.spkctl = res->start; + } + + if(rk2928_data.spkctl != INVALID_GPIO) { + ret = gpio_request(rk2928_data.spkctl, NULL); if (ret != 0) { - gpio_free(SPK_CTL); + gpio_free(rk2928_data.spkctl); } else - gpio_direction_output(SPK_CTL, GPIO_LOW); + gpio_direction_output(rk2928_data.spkctl, GPIO_LOW); } + + // Select SDI input from internal audio codec + writel(0x04000400, RK2928_GRF_BASE + GRF_SOC_CON0); + // Mute and Power off codec rk2928_write(codec, CODEC_REG_DAC_MUTE, v_MUTE_DAC(1)); rk2928_set_bias_level(codec, SND_SOC_BIAS_OFF); -- 2.34.1