blob: 60962ce6cd4d06c96536ca9ee124a8ac66e10467 [file] [log] [blame]
Barry Songdce944d2009-09-01 12:45:14 +08001/*
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>
Barry Songdce944d2009-09-01 12:45:14 +080023#include <sound/pcm_params.h>
24
25#include <asm/blackfin.h>
26#include <asm/cacheflush.h>
27#include <asm/irq.h>
28#include <asm/dma.h>
29#include <asm/portmux.h>
30
31#include "../codecs/ad1836.h"
Barry Songdce944d2009-09-01 12:45:14 +080032
33#include "bf5xx-tdm-pcm.h"
34#include "bf5xx-tdm.h"
35
36static struct snd_soc_card bf5xx_ad1836;
37
Barry Songdce944d2009-09-01 12:45:14 +080038static int bf5xx_ad1836_hw_params(struct snd_pcm_substream *substream,
39 struct snd_pcm_hw_params *params)
40{
41 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000042 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
43 struct snd_soc_dai *codec_dai = rtd->codec_dai;
Barry Song08db48f2009-09-15 11:24:52 +080044 unsigned int channel_map[] = {0, 4, 1, 5, 2, 6, 3, 7};
Barry Songdce944d2009-09-01 12:45:14 +080045 int ret = 0;
46 /* set cpu DAI configuration */
47 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_DSP_A |
48 SND_SOC_DAIFMT_IB_IF | SND_SOC_DAIFMT_CBM_CFM);
49 if (ret < 0)
50 return ret;
51
52 /* set codec DAI configuration */
53 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_DSP_A |
54 SND_SOC_DAIFMT_IB_IF | SND_SOC_DAIFMT_CBM_CFM);
55 if (ret < 0)
56 return ret;
57
Barry Song08db48f2009-09-15 11:24:52 +080058 /* set cpu DAI channel mapping */
59 ret = snd_soc_dai_set_channel_map(cpu_dai, ARRAY_SIZE(channel_map),
60 channel_map, ARRAY_SIZE(channel_map), channel_map);
61 if (ret < 0)
62 return ret;
63
Barry Songdce944d2009-09-01 12:45:14 +080064 return 0;
65}
66
67static struct snd_soc_ops bf5xx_ad1836_ops = {
Barry Songdce944d2009-09-01 12:45:14 +080068 .hw_params = bf5xx_ad1836_hw_params,
69};
70
Barry Song2c66cb92011-03-28 01:45:10 -040071static struct snd_soc_dai_link bf5xx_ad1836_dai[] = {
72 {
73 .name = "ad1836",
74 .stream_name = "AD1836",
75 .cpu_dai_name = "bfin-tdm.0",
76 .codec_dai_name = "ad1836-hifi",
77 .platform_name = "bfin-tdm-pcm-audio",
Lars-Peter Clausen064d58e2011-06-07 10:24:46 +020078 .codec_name = "spi0.4",
Barry Song2c66cb92011-03-28 01:45:10 -040079 .ops = &bf5xx_ad1836_ops,
80 },
81 {
82 .name = "ad1836",
83 .stream_name = "AD1836",
84 .cpu_dai_name = "bfin-tdm.1",
85 .codec_dai_name = "ad1836-hifi",
86 .platform_name = "bfin-tdm-pcm-audio",
Lars-Peter Clausen064d58e2011-06-07 10:24:46 +020087 .codec_name = "spi0.4",
Barry Song2c66cb92011-03-28 01:45:10 -040088 .ops = &bf5xx_ad1836_ops,
89 },
Barry Songdce944d2009-09-01 12:45:14 +080090};
91
92static struct snd_soc_card bf5xx_ad1836 = {
Mike Frysingerbfe4ee02011-03-28 01:45:09 -040093 .name = "bfin-ad1836",
Axel Lin30e49532011-12-22 21:17:22 +080094 .owner = THIS_MODULE,
Barry Song2c66cb92011-03-28 01:45:10 -040095 .dai_link = &bf5xx_ad1836_dai[CONFIG_SND_BF5XX_SPORT_NUM],
Barry Songdce944d2009-09-01 12:45:14 +080096 .num_links = 1,
97};
98
Barry Songdce944d2009-09-01 12:45:14 +080099static struct platform_device *bfxx_ad1836_snd_device;
100
101static int __init bf5xx_ad1836_init(void)
102{
103 int ret;
104
105 bfxx_ad1836_snd_device = platform_device_alloc("soc-audio", -1);
106 if (!bfxx_ad1836_snd_device)
107 return -ENOMEM;
108
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000109 platform_set_drvdata(bfxx_ad1836_snd_device, &bf5xx_ad1836);
Barry Songdce944d2009-09-01 12:45:14 +0800110 ret = platform_device_add(bfxx_ad1836_snd_device);
111
112 if (ret)
113 platform_device_put(bfxx_ad1836_snd_device);
114
115 return ret;
116}
117
118static void __exit bf5xx_ad1836_exit(void)
119{
120 platform_device_unregister(bfxx_ad1836_snd_device);
121}
122
123module_init(bf5xx_ad1836_init);
124module_exit(bf5xx_ad1836_exit);
125
126/* Module information */
127MODULE_AUTHOR("Barry Song");
128MODULE_DESCRIPTION("ALSA SoC AD1836 board driver");
129MODULE_LICENSE("GPL");
130