RT-AC66 3.0.0.4.374.130 core
[tomato.git] / release / src-rt-6.x / linux / linux-2.6 / sound / soc / bcm947xx / bcm94717ap.c
blob5abe72e4ae437e036667da82225c90abdb097143
1 /*
2 * SoC audio for BCM94717AP Board
4 * Copyright (C) 2009, Broadcom Corporation
5 * All Rights Reserved.
6 *
7 * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
8 * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
9 * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
10 * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
12 * $Id: bcm94717ap.c,v 1.1 2009/10/30 20:40:14 Exp $
16 #include <linux/module.h>
17 #include <linux/moduleparam.h>
18 #include <linux/timer.h>
19 #include <linux/interrupt.h>
20 #include <linux/platform_device.h>
21 #include <sound/driver.h>
22 #include <sound/core.h>
23 #include <sound/pcm.h>
24 #include <sound/soc.h>
25 #include <sound/soc-dapm.h>
26 #include <linux/i2c-gpio.h>
28 #include <typedefs.h>
29 #include <bcmdevs.h>
30 #include <pcicfg.h>
31 #include <hndsoc.h>
32 #include <osl.h>
33 #include <bcmutils.h>
34 #include <siutils.h>
35 #include <sbhnddma.h>
36 #include <hnddma.h>
37 #include <i2s_core.h>
40 #include "../codecs/wm8955.h"
41 #include "bcm947xx-pcm.h"
42 #include "bcm947xx-i2s.h"
44 #define BCM947XX_AP_DEBUG 0
45 #if BCM947XX_AP_DEBUG
46 #define DBG(x...) printk(KERN_ERR x)
47 #else
48 #define DBG(x...)
49 #endif
52 /* MCLK in Hz - to bcm94717ap & Wolfson 8955 */
53 #define BCM94717AP_MCLK_FREQ 20000000 /* 20 MHz */
56 static int bcm94717ap_startup(struct snd_pcm_substream *substream)
58 //struct snd_soc_pcm_runtime *rtd = substream->private_data;
59 //struct snd_soc_codec_dai *codec_dai = rtd->dai->codec_dai;
60 //struct snd_soc_cpu_dai *cpu_dai = rtd->dai->cpu_dai;
61 int ret = 0;
63 DBG("%s:\n", __FUNCTION__);
65 return ret;
68 /* we need to unmute the HP at shutdown as the mute burns power on bcm94717ap */
69 static void bcm94717ap_shutdown(struct snd_pcm_substream *substream)
71 DBG("%s\n", __FUNCTION__);
72 return;
75 static int bcm94717ap_hw_params(struct snd_pcm_substream *substream,
76 struct snd_pcm_hw_params *params)
78 struct snd_soc_pcm_runtime *rtd = substream->private_data;
79 struct snd_soc_codec_dai *codec_dai = rtd->dai->codec_dai;
80 struct snd_soc_cpu_dai *cpu_dai = rtd->dai->cpu_dai;
81 unsigned int fmt;
82 int freq = 12288000;
83 //int freq = 11289600;
84 int ret = 0;
86 fmt = SND_SOC_DAIFMT_I2S | /* I2S mode audio */
87 SND_SOC_DAIFMT_NB_NF | /* BCLK not inverted and normal LRCLK polarity */
88 SND_SOC_DAIFMT_CBM_CFM; /* BCM947xx is I2S Slave */
90 /* set codec DAI configuration */
91 DBG("%s: calling set_fmt with fmt 0x%x\n", __FUNCTION__, fmt);
92 ret = codec_dai->dai_ops.set_fmt(codec_dai, fmt);
93 if (ret < 0)
94 return ret;
96 /* set cpu DAI configuration */
97 ret = cpu_dai->dai_ops.set_fmt(cpu_dai, fmt);
98 if (ret < 0)
99 return ret;
102 /* set up the PLL in codec */
103 ret = codec_dai->dai_ops.set_pll(codec_dai, 0, BCM94717AP_MCLK_FREQ, freq);
104 if (ret < 0) {
105 DBG("%s: Error CODEC DAI set_pll returned %d\n", __FUNCTION__, ret);
106 return ret;
108 /* set the codec system clock for DAC and ADC */
109 ret = codec_dai->dai_ops.set_sysclk(codec_dai, WM8955_SYSCLK, freq,
110 SND_SOC_CLOCK_IN);
111 DBG("%s: codec set_sysclk returned %d\n", __FUNCTION__, ret);
112 if (ret < 0)
113 return ret;
115 /* set the I2S system clock as input (unused) */
116 ret = cpu_dai->dai_ops.set_sysclk(cpu_dai, BCM947XX_I2S_SYSCLK, freq,
117 SND_SOC_CLOCK_IN);
119 DBG("%s: cpu set_sysclk returned %d\n", __FUNCTION__, ret);
120 if (ret < 0)
121 return ret;
123 return 0;
126 static struct snd_soc_ops bcm94717ap_ops = {
127 .startup = bcm94717ap_startup,
128 .hw_params = bcm94717ap_hw_params,
129 .shutdown = bcm94717ap_shutdown,
133 * Logic for a wm8955
135 static int bcm94717ap_wm8955_init(struct snd_soc_codec *codec)
137 DBG("%s\n", __FUNCTION__);
139 snd_soc_dapm_sync_endpoints(codec);
141 return 0;
144 /* bcm94717ap digital audio interface glue - connects codec <--> CPU */
145 static struct snd_soc_dai_link bcm94717ap_dai = {
146 .name = "WM8955",
147 .stream_name = "WM8955",
148 .cpu_dai = &bcm947xx_i2s_dai,
149 .codec_dai = &wm8955_dai,
150 .init = bcm94717ap_wm8955_init,
151 .ops = &bcm94717ap_ops,
154 /* bcm94717ap audio machine driver */
155 static struct snd_soc_machine snd_soc_machine_bcm94717ap = {
156 .name = "Bcm94717ap",
157 .dai_link = &bcm94717ap_dai,
158 .num_links = 1,
161 /* bcm94717ap audio private data */
162 static struct wm8955_setup_data bcm94717ap_wm8955_setup = {
163 .i2c_address = 0x1a, /* 2wire / I2C interface */
166 /* bcm94717ap audio subsystem */
167 static struct snd_soc_device bcm94717ap_snd_devdata = {
168 .machine = &snd_soc_machine_bcm94717ap,
169 .platform = &bcm947xx_soc_platform,
170 .codec_dev = &soc_codec_dev_wm8955,
171 .codec_data = &bcm94717ap_wm8955_setup,
174 static struct platform_device *bcm94717ap_snd_device;
176 static int machine_is_bcm94717ap(void)
178 DBG("%s\n", __FUNCTION__);
179 return 1;
183 static struct i2c_gpio_platform_data i2c_gpio_data = {
184 .sda_pin = 4,
185 .scl_pin = 5,
188 static struct platform_device i2c_gpio_device = {
189 .name = "i2c-gpio",
190 .id = 0,
191 .dev = {
192 .platform_data = &i2c_gpio_data,
197 static int __init bcm94717ap_init(void)
199 int ret;
201 DBG("%s\n", __FUNCTION__);
203 if (!machine_is_bcm94717ap())
204 return -ENODEV;
206 ret = platform_device_register(&i2c_gpio_device);
207 if (ret) {
208 platform_device_put(&i2c_gpio_device);
209 return ret;
212 bcm94717ap_snd_device = platform_device_alloc("soc-audio", -1);
213 if (!bcm94717ap_snd_device)
214 return -ENOMEM;
216 platform_set_drvdata(bcm94717ap_snd_device, &bcm94717ap_snd_devdata);
217 bcm94717ap_snd_devdata.dev = &bcm94717ap_snd_device->dev;
218 ret = platform_device_add(bcm94717ap_snd_device);
220 if (ret) {
221 platform_device_put(bcm94717ap_snd_device);
224 return ret;
227 static void __exit bcm94717ap_exit(void)
229 DBG("%s\n", __FUNCTION__);
230 platform_device_unregister(bcm94717ap_snd_device);
233 module_init(bcm94717ap_init);
234 module_exit(bcm94717ap_exit);
236 /* Module information */
237 MODULE_DESCRIPTION("ALSA SoC BCM94717AP");
238 MODULE_LICENSE("GPL");