blob: 50baef1fe5b4a9ae38e291e8bf4b5cf6b5602760 [file] [log] [blame]
Hugo Villeneuve08bd1682008-11-19 01:37:32 -05001/*
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>
David Brownell5cf1c002009-01-05 02:08:30 -080027#include <asm/mach-types.h>
Hugo Villeneuveac373732009-01-15 15:40:35 -050028#ifdef CONFIG_SFFSDR_FPGA
Hugo Villeneuve08bd1682008-11-19 01:37:32 -050029#include <asm/plat-sffsdr/sffsdr-fpga.h>
Hugo Villeneuveac373732009-01-15 15:40:35 -050030#endif
Hugo Villeneuve08bd1682008-11-19 01:37:32 -050031
32#include <mach/mcbsp.h>
33#include <mach/edma.h>
34
35#include "../codecs/pcm3008.h"
36#include "davinci-pcm.h"
37#include "davinci-i2s.h"
38
39static int sffsdr_hw_params(struct snd_pcm_substream *substream,
Mark Browndee89c42008-11-18 22:11:38 +000040 struct snd_pcm_hw_params *params,
41 struct snd_soc_dai *dai)
Hugo Villeneuve08bd1682008-11-19 01:37:32 -050042{
43 struct snd_soc_pcm_runtime *rtd = substream->private_data;
44 struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
45 int fs;
46 int ret = 0;
47
Hugo Villeneuveac373732009-01-15 15:40:35 -050048 /* Fsref can be 32000, 44100 or 48000. */
49 fs = params_rate(params);
50
51#ifndef CONFIG_SFFSDR_FPGA
52 /* Without the FPGA module, the Fs is fixed at 44100 Hz */
53 if (fs != 44100) {
54 pr_debug("warning: only 44.1 kHz is supported without SFFSDR FPGA module\n");
55 return -EINVAL;
56 }
57#endif
58
Hugo Villeneuve08bd1682008-11-19 01:37:32 -050059 /* Set cpu DAI configuration:
60 * CLKX and CLKR are the inputs for the Sample Rate Generator.
61 * FSX and FSR are outputs, driven by the sample Rate Generator. */
62 ret = snd_soc_dai_set_fmt(cpu_dai,
63 SND_SOC_DAIFMT_RIGHT_J |
64 SND_SOC_DAIFMT_CBM_CFS |
65 SND_SOC_DAIFMT_IB_NF);
66 if (ret < 0)
67 return ret;
68
Hugo Villeneuve08bd1682008-11-19 01:37:32 -050069 pr_debug("sffsdr_hw_params: rate = %d Hz\n", fs);
70
Hugo Villeneuveac373732009-01-15 15:40:35 -050071#ifndef CONFIG_SFFSDR_FPGA
72 return 0;
73#else
Hugo Villeneuve08bd1682008-11-19 01:37:32 -050074 return sffsdr_fpga_set_codec_fs(fs);
Hugo Villeneuveac373732009-01-15 15:40:35 -050075#endif
Hugo Villeneuve08bd1682008-11-19 01:37:32 -050076}
77
78static struct snd_soc_ops sffsdr_ops = {
79 .hw_params = sffsdr_hw_params,
80};
81
82/* davinci-sffsdr digital audio interface glue - connects codec <--> CPU */
83static struct snd_soc_dai_link sffsdr_dai = {
84 .name = "PCM3008", /* Codec name */
85 .stream_name = "PCM3008 HiFi",
86 .cpu_dai = &davinci_i2s_dai,
87 .codec_dai = &pcm3008_dai,
88 .ops = &sffsdr_ops,
89};
90
91/* davinci-sffsdr audio machine driver */
Mark Brown87506542008-11-18 20:50:34 +000092static struct snd_soc_card snd_soc_sffsdr = {
Hugo Villeneuve08bd1682008-11-19 01:37:32 -050093 .name = "DaVinci SFFSDR",
Mark Brown87689d52008-12-02 16:01:14 +000094 .platform = &davinci_soc_platform,
Hugo Villeneuve08bd1682008-11-19 01:37:32 -050095 .dai_link = &sffsdr_dai,
96 .num_links = 1,
97};
98
99/* sffsdr audio private data */
100static struct pcm3008_setup_data sffsdr_pcm3008_setup = {
101 .dem0_pin = GPIO(45),
102 .dem1_pin = GPIO(46),
103 .pdad_pin = GPIO(47),
104 .pdda_pin = GPIO(38),
105};
106
107/* sffsdr audio subsystem */
108static struct snd_soc_device sffsdr_snd_devdata = {
Mark Brown87506542008-11-18 20:50:34 +0000109 .card = &snd_soc_sffsdr,
Hugo Villeneuve08bd1682008-11-19 01:37:32 -0500110 .codec_dev = &soc_codec_dev_pcm3008,
111 .codec_data = &sffsdr_pcm3008_setup,
112};
113
114static struct resource sffsdr_snd_resources[] = {
115 {
116 .start = DAVINCI_MCBSP_BASE,
117 .end = DAVINCI_MCBSP_BASE + SZ_8K - 1,
118 .flags = IORESOURCE_MEM,
119 },
120};
121
122static struct evm_snd_platform_data sffsdr_snd_data = {
123 .tx_dma_ch = DAVINCI_DMA_MCBSP_TX,
124 .rx_dma_ch = DAVINCI_DMA_MCBSP_RX,
125};
126
127static struct platform_device *sffsdr_snd_device;
128
129static int __init sffsdr_init(void)
130{
131 int ret;
132
David Brownell5cf1c002009-01-05 02:08:30 -0800133 if (!machine_is_sffsdr())
134 return -EINVAL;
135
Hugo Villeneuve08bd1682008-11-19 01:37:32 -0500136 sffsdr_snd_device = platform_device_alloc("soc-audio", 0);
137 if (!sffsdr_snd_device) {
138 printk(KERN_ERR "platform device allocation failed\n");
139 return -ENOMEM;
140 }
141
142 platform_set_drvdata(sffsdr_snd_device, &sffsdr_snd_devdata);
143 sffsdr_snd_devdata.dev = &sffsdr_snd_device->dev;
144 sffsdr_snd_device->dev.platform_data = &sffsdr_snd_data;
145
146 ret = platform_device_add_resources(sffsdr_snd_device,
147 sffsdr_snd_resources,
148 ARRAY_SIZE(sffsdr_snd_resources));
149 if (ret) {
150 printk(KERN_ERR "platform device add ressources failed\n");
151 goto error;
152 }
153
154 ret = platform_device_add(sffsdr_snd_device);
155 if (ret)
156 goto error;
157
158 return ret;
159
160error:
161 platform_device_put(sffsdr_snd_device);
162 return ret;
163}
164
165static void __exit sffsdr_exit(void)
166{
167 platform_device_unregister(sffsdr_snd_device);
168}
169
170module_init(sffsdr_init);
171module_exit(sffsdr_exit);
172
173MODULE_AUTHOR("Hugo Villeneuve");
174MODULE_DESCRIPTION("Lyrtech SFFSDR ASoC driver");
175MODULE_LICENSE("GPL");