upload tizen1.0 source
[kernel/linux-2.6.36.git] / sound / soc / blackfin / bf5xx-ad1836.c
1 /*
2  * File:         sound/soc/blackfin/bf5xx-ad1836.c
3  * Author:       Barry Song <Barry.Song@analog.com>
4  *
5  * Created:      Aug 4 2009
6  * Description:  Board driver for ad1836 sound chip
7  *
8  * Bugs:         Enter bugs at http://blackfin.uclinux.org/
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  */
16
17 #include <linux/module.h>
18 #include <linux/moduleparam.h>
19 #include <linux/device.h>
20 #include <sound/core.h>
21 #include <sound/pcm.h>
22 #include <sound/soc.h>
23 #include <sound/soc-dapm.h>
24 #include <sound/pcm_params.h>
25
26 #include <asm/blackfin.h>
27 #include <asm/cacheflush.h>
28 #include <asm/irq.h>
29 #include <asm/dma.h>
30 #include <asm/portmux.h>
31
32 #include "../codecs/ad1836.h"
33 #include "bf5xx-sport.h"
34
35 #include "bf5xx-tdm-pcm.h"
36 #include "bf5xx-tdm.h"
37
38 static struct snd_soc_card bf5xx_ad1836;
39
40 static int bf5xx_ad1836_startup(struct snd_pcm_substream *substream)
41 {
42         struct snd_soc_pcm_runtime *rtd = substream->private_data;
43         struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
44
45         cpu_dai->private_data = sport_handle;
46         return 0;
47 }
48
49 static int bf5xx_ad1836_hw_params(struct snd_pcm_substream *substream,
50         struct snd_pcm_hw_params *params)
51 {
52         struct snd_soc_pcm_runtime *rtd = substream->private_data;
53         struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
54         struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
55         unsigned int channel_map[] = {0, 4, 1, 5, 2, 6, 3, 7};
56         int ret = 0;
57         /* set cpu DAI configuration */
58         ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_DSP_A |
59                 SND_SOC_DAIFMT_IB_IF | SND_SOC_DAIFMT_CBM_CFM);
60         if (ret < 0)
61                 return ret;
62
63         /* set codec DAI configuration */
64         ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_DSP_A |
65                 SND_SOC_DAIFMT_IB_IF | SND_SOC_DAIFMT_CBM_CFM);
66         if (ret < 0)
67                 return ret;
68
69         /* set cpu DAI channel mapping */
70         ret = snd_soc_dai_set_channel_map(cpu_dai, ARRAY_SIZE(channel_map),
71                 channel_map, ARRAY_SIZE(channel_map), channel_map);
72         if (ret < 0)
73                 return ret;
74
75         return 0;
76 }
77
78 static struct snd_soc_ops bf5xx_ad1836_ops = {
79         .startup = bf5xx_ad1836_startup,
80         .hw_params = bf5xx_ad1836_hw_params,
81 };
82
83 static struct snd_soc_dai_link bf5xx_ad1836_dai = {
84         .name = "ad1836",
85         .stream_name = "AD1836",
86         .cpu_dai = &bf5xx_tdm_dai,
87         .codec_dai = &ad1836_dai,
88         .ops = &bf5xx_ad1836_ops,
89 };
90
91 static struct snd_soc_card bf5xx_ad1836 = {
92         .name = "bf5xx_ad1836",
93         .platform = &bf5xx_tdm_soc_platform,
94         .dai_link = &bf5xx_ad1836_dai,
95         .num_links = 1,
96 };
97
98 static struct snd_soc_device bf5xx_ad1836_snd_devdata = {
99         .card = &bf5xx_ad1836,
100         .codec_dev = &soc_codec_dev_ad1836,
101 };
102
103 static struct platform_device *bfxx_ad1836_snd_device;
104
105 static int __init bf5xx_ad1836_init(void)
106 {
107         int ret;
108
109         bfxx_ad1836_snd_device = platform_device_alloc("soc-audio", -1);
110         if (!bfxx_ad1836_snd_device)
111                 return -ENOMEM;
112
113         platform_set_drvdata(bfxx_ad1836_snd_device, &bf5xx_ad1836_snd_devdata);
114         bf5xx_ad1836_snd_devdata.dev = &bfxx_ad1836_snd_device->dev;
115         ret = platform_device_add(bfxx_ad1836_snd_device);
116
117         if (ret)
118                 platform_device_put(bfxx_ad1836_snd_device);
119
120         return ret;
121 }
122
123 static void __exit bf5xx_ad1836_exit(void)
124 {
125         platform_device_unregister(bfxx_ad1836_snd_device);
126 }
127
128 module_init(bf5xx_ad1836_init);
129 module_exit(bf5xx_ad1836_exit);
130
131 /* Module information */
132 MODULE_AUTHOR("Barry Song");
133 MODULE_DESCRIPTION("ALSA SoC AD1836 board driver");
134 MODULE_LICENSE("GPL");
135