Commit | Line | Data |
---|---|---|
08bd1686 HV |
1 | /* |
2 | * ASoC driver for Lyrtech SFFSDR board. | |
3 | * | |
4 | * Author: Hugo Villeneuve | |
5 | * Copyright (C) 2008 Lyrtech inc | |
6 | * | |
7 | * Based on ASoC driver for TI DAVINCI EVM platform, original copyright follow: | |
8 | * Copyright: (C) 2007 MontaVista Software, Inc., <source@mvista.com> | |
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 version 2 as | |
12 | * published by the Free Software Foundation. | |
13 | */ | |
14 | ||
15 | #include <linux/module.h> | |
16 | #include <linux/moduleparam.h> | |
17 | #include <linux/timer.h> | |
18 | #include <linux/interrupt.h> | |
19 | #include <linux/platform_device.h> | |
20 | #include <linux/gpio.h> | |
21 | #include <sound/core.h> | |
22 | #include <sound/pcm.h> | |
23 | #include <sound/soc.h> | |
24 | #include <sound/soc-dapm.h> | |
25 | ||
26 | #include <asm/dma.h> | |
27 | #include <asm/plat-sffsdr/sffsdr-fpga.h> | |
28 | ||
29 | #include <mach/mcbsp.h> | |
30 | #include <mach/edma.h> | |
31 | ||
32 | #include "../codecs/pcm3008.h" | |
33 | #include "davinci-pcm.h" | |
34 | #include "davinci-i2s.h" | |
35 | ||
36 | static int sffsdr_hw_params(struct snd_pcm_substream *substream, | |
37 | struct snd_pcm_hw_params *params) | |
38 | { | |
39 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | |
40 | struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai; | |
41 | int fs; | |
42 | int ret = 0; | |
43 | ||
44 | /* Set cpu DAI configuration: | |
45 | * CLKX and CLKR are the inputs for the Sample Rate Generator. | |
46 | * FSX and FSR are outputs, driven by the sample Rate Generator. */ | |
47 | ret = snd_soc_dai_set_fmt(cpu_dai, | |
48 | SND_SOC_DAIFMT_RIGHT_J | | |
49 | SND_SOC_DAIFMT_CBM_CFS | | |
50 | SND_SOC_DAIFMT_IB_NF); | |
51 | if (ret < 0) | |
52 | return ret; | |
53 | ||
54 | /* Fsref can be 32000, 44100 or 48000. */ | |
55 | fs = params_rate(params); | |
56 | ||
57 | pr_debug("sffsdr_hw_params: rate = %d Hz\n", fs); | |
58 | ||
59 | return sffsdr_fpga_set_codec_fs(fs); | |
60 | } | |
61 | ||
62 | static struct snd_soc_ops sffsdr_ops = { | |
63 | .hw_params = sffsdr_hw_params, | |
64 | }; | |
65 | ||
66 | /* davinci-sffsdr digital audio interface glue - connects codec <--> CPU */ | |
67 | static struct snd_soc_dai_link sffsdr_dai = { | |
68 | .name = "PCM3008", /* Codec name */ | |
69 | .stream_name = "PCM3008 HiFi", | |
70 | .cpu_dai = &davinci_i2s_dai, | |
71 | .codec_dai = &pcm3008_dai, | |
72 | .ops = &sffsdr_ops, | |
73 | }; | |
74 | ||
75 | /* davinci-sffsdr audio machine driver */ | |
87506549 | 76 | static struct snd_soc_card snd_soc_sffsdr = { |
08bd1686 HV |
77 | .name = "DaVinci SFFSDR", |
78 | .dai_link = &sffsdr_dai, | |
79 | .num_links = 1, | |
80 | }; | |
81 | ||
82 | /* sffsdr audio private data */ | |
83 | static struct pcm3008_setup_data sffsdr_pcm3008_setup = { | |
84 | .dem0_pin = GPIO(45), | |
85 | .dem1_pin = GPIO(46), | |
86 | .pdad_pin = GPIO(47), | |
87 | .pdda_pin = GPIO(38), | |
88 | }; | |
89 | ||
90 | /* sffsdr audio subsystem */ | |
91 | static struct snd_soc_device sffsdr_snd_devdata = { | |
87506549 | 92 | .card = &snd_soc_sffsdr, |
08bd1686 HV |
93 | .platform = &davinci_soc_platform, |
94 | .codec_dev = &soc_codec_dev_pcm3008, | |
95 | .codec_data = &sffsdr_pcm3008_setup, | |
96 | }; | |
97 | ||
98 | static struct resource sffsdr_snd_resources[] = { | |
99 | { | |
100 | .start = DAVINCI_MCBSP_BASE, | |
101 | .end = DAVINCI_MCBSP_BASE + SZ_8K - 1, | |
102 | .flags = IORESOURCE_MEM, | |
103 | }, | |
104 | }; | |
105 | ||
106 | static struct evm_snd_platform_data sffsdr_snd_data = { | |
107 | .tx_dma_ch = DAVINCI_DMA_MCBSP_TX, | |
108 | .rx_dma_ch = DAVINCI_DMA_MCBSP_RX, | |
109 | }; | |
110 | ||
111 | static struct platform_device *sffsdr_snd_device; | |
112 | ||
113 | static int __init sffsdr_init(void) | |
114 | { | |
115 | int ret; | |
116 | ||
117 | sffsdr_snd_device = platform_device_alloc("soc-audio", 0); | |
118 | if (!sffsdr_snd_device) { | |
119 | printk(KERN_ERR "platform device allocation failed\n"); | |
120 | return -ENOMEM; | |
121 | } | |
122 | ||
123 | platform_set_drvdata(sffsdr_snd_device, &sffsdr_snd_devdata); | |
124 | sffsdr_snd_devdata.dev = &sffsdr_snd_device->dev; | |
125 | sffsdr_snd_device->dev.platform_data = &sffsdr_snd_data; | |
126 | ||
127 | ret = platform_device_add_resources(sffsdr_snd_device, | |
128 | sffsdr_snd_resources, | |
129 | ARRAY_SIZE(sffsdr_snd_resources)); | |
130 | if (ret) { | |
131 | printk(KERN_ERR "platform device add ressources failed\n"); | |
132 | goto error; | |
133 | } | |
134 | ||
135 | ret = platform_device_add(sffsdr_snd_device); | |
136 | if (ret) | |
137 | goto error; | |
138 | ||
139 | return ret; | |
140 | ||
141 | error: | |
142 | platform_device_put(sffsdr_snd_device); | |
143 | return ret; | |
144 | } | |
145 | ||
146 | static void __exit sffsdr_exit(void) | |
147 | { | |
148 | platform_device_unregister(sffsdr_snd_device); | |
149 | } | |
150 | ||
151 | module_init(sffsdr_init); | |
152 | module_exit(sffsdr_exit); | |
153 | ||
154 | MODULE_AUTHOR("Hugo Villeneuve"); | |
155 | MODULE_DESCRIPTION("Lyrtech SFFSDR ASoC driver"); | |
156 | MODULE_LICENSE("GPL"); |