移植內核的聲卡驅動。原因沒有聲卡驅動,WM9713聲卡驅動移植(原來的內核有UDA1341聲卡驅動,我們再次基礎上直接修改)
1、直接復制內核得到三個文件:s3c2416_wm9713.c , wm9713.c , s3c2416_ac97.c. linux-3.1\sound\soc\codecs\Wm9713.c---->wm9713.c; linux-3.1\sound\soc\samsung\Smdk_wm9713.c---->s3c2416_wm9713.c; linux-3.1\sound\soc\samsung\Ac97.c------------>s3c2416_ac97.c. 2、使得內核支持那三個文件: 在linux-3.1\sound\soc\samsung\Makefile添加: snd-soc-s3c2416-wm9713-objs := s3c2416_wm9713.o
在linux-3.1/sound/soc/samsung/kconfig 配上WM9713
config SND_SOC_SAMSUNG_SMDK_WM9713
tristate "SoC AC97 Audio support for s3c2416 with WM9713"
## depends on SND_SOC_SAMSUNG && (MACH_SMDK6410 || MACH_SMDKC100 || MACH_SMDKV210 || ##MACH_SMDKC110 || MACH_SMDKV310 || MACH_SMDKC210) #屏蔽掉
depends on SND_SOC_SAMSUNG && ARCH_S3C24XX ##add by ljf
select SND_SOC_WM9713
select SND_SAMSUNG_AC97
help
Sat Y if you want to add support for SoC audio on the SMDK.
這樣在內核中“make menuconfig”裡面就可以看到"SoC AC97 Audio support for s3c2416 with WM9713",並選中他。
接下來我們要在內核中加入這個平台驅動設備:
在“arch/arm/mach-s3c2416/”的mach-tq2416.c中添加:
添加頭文件
#include <mach/dma.h>//add by ljf
#include <linux/dma-mapping.h>//add by ljf
#include <plat/audio.h>//add by ljf
//add by ljf
/*
* AC97
*/
//at plat-s3c24xx/devs.c
static int s3c2416_ac97_cfg_gpio(struct platform_device *pdev)
{
return s3c_gpio_cfgpin_range(S3C2410_GPE(0), 5, S3C_GPIO_SFN(3));//硬件是使用GPE0~4,S3C_GPIO_SFN(3)表示使用第三功能為AC接口
static struct resource s3c_ac97_resource[] = {
[0] = {
.start = S3C2440_PA_AC97,
.end = S3C2440_PA_AC97 + S3C2440_SZ_AC97 -1,
.flags = IORESOURCE_MEM,
},
[1] = {
.start = IRQ_S3C244x_AC97,
.end = IRQ_S3C244x_AC97,
.flags = IORESOURCE_IRQ,
},
[2] = {
.name = "PCM out",
.start = DMACH_PCM_OUT,
.end = DMACH_PCM_OUT,
.flags = IORESOURCE_DMA,
},
[3] = {
.name = "PCM in",
.start = DMACH_PCM_IN,
.end = DMACH_PCM_IN,
.flags = IORESOURCE_DMA,
},
[4] = {
.name = "Mic in",
.start = DMACH_MIC_IN,
.end = DMACH_MIC_IN,
.flags = IORESOURCE_DMA,
},
};
static struct s3c_audio_pdata s3c_ac97_pdata = {
.cfg_gpio = s3c2416_ac97_cfg_gpio,
};
static u64 s3c_device_audio_dmamask = DMA_BIT_MASK(32);//0xffffffffUL;//will change
struct platform_device s3c_device_ac97 = {
.name = "samsung-ac97",//
.id = -1,
.num_resources = ARRAY_SIZE(s3c_ac97_resource),
.resource = s3c_ac97_resource,
.dev = {
.platform_data = &s3c_ac97_pdata,
.dma_mask = &s3c_device_audio_dmamask,
.coherent_dma_mask = DMA_BIT_MASK(32)//;0xffffffffUL//will change
}
};
//add by ljf
然後在“struct platform_device *tq2416_devices[] __initdata”中加入
//add by ljf
#ifdef CONFIG_SND_SOC_SAMSUNG_SMDK_WM9713
&s3c_device_ac97,
&samsung_asoc_dma,
#endif
//add by ljf
然後編譯、燒寫。內核打印信息有
asoc: wm9713-hifi <-> samsung-ac97 mapping ok
ALSA device list:
#0: SMDK WM9713
其實到這邊,你去播放音樂時還是沒聲音。
原因:
由於在ac97初始化的時候,沒有設置wm9713相關為喇叭輸出功能。
解決:
在\sound\soc\samsung\s3c2416_ac97.c
static struct snd_soc_dai_ops s3c_ac97_dai_ops結構體添加:
.prepare = earphone_out,(初始化函數)
實現該函數(寫在s3c_ac97_dai_ops結構體上面就行了):
int earphone_out(struct snd_pcm_substream *substream,struct snd_soc_dai *dai)
{
struct snd_ac97 *ac97;
ac97 = 0;
s3c_ac97_write(ac97,0x26,0x0);
s3c_ac97_write(ac97, 0x0c, 0x0808);
s3c_ac97_write(ac97,0x3c, 0xf803);
s3c_ac97_write(ac97,0x3e,0xb990);
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
//s3c6400_ac97_write(0,0x02, 0x8080);
s3c_ac97_write(ac97,0x02, 0x0404);
s3c_ac97_write(ac97, 0x04, 0x0606);
//s3c6400_ac97_write(0,0x1c, 0x00aa);
s3c_ac97_write(ac97,0x1c, 0x12aa);
}
else
{
s3c_ac97_write(ac97, 0x12, 0x0f0f);
#ifdef CONFIG_SOUND_WM9713_INPUT_STREAM_MIC
s3c_ac97_write(ac97,0x5c,0x2);
s3c_ac97_write(ac97,0x10,0x68);
s3c_ac97_write(ac97,0x14,0xfe00);
#else /* Input Stream is LINE-IN */
s3c_ac97_write(ac97, 0x14, 0xd612);
#endif
}
return 0;
}
到這邊聲卡就移植結束了。
再次編譯,燒寫。
再次測試一下: cat /dev/urandom > /dev/dsp 可以聽到“莎莎”的聲音,說明移植成功。 參考文檔鏈接:感謝這些朋友。http://www.linuxidc.com/Linux/2014-02/96930.htm