blob: 5be65aae7e0e538b552f9f4bf2bb99c9ed0ad3f8 [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>
Hugo Villeneuve08bd1682008-11-19 01:37:32 -050024
25#include <asm/dma.h>
David Brownell5cf1c002009-01-05 02:08:30 -080026#include <asm/mach-types.h>
Hugo Villeneuveac373732009-01-15 15:40:35 -050027#ifdef CONFIG_SFFSDR_FPGA
Hugo Villeneuve08bd1682008-11-19 01:37:32 -050028#include <asm/plat-sffsdr/sffsdr-fpga.h>
Hugo Villeneuveac373732009-01-15 15:40:35 -050029#endif
Hugo Villeneuve08bd1682008-11-19 01:37:32 -050030
Hugo Villeneuve08bd1682008-11-19 01:37:32 -050031#include <mach/edma.h>
32
33#include "../codecs/pcm3008.h"
34#include "davinci-pcm.h"
35#include "davinci-i2s.h"
36
Hugo Villeneuve14cbba82009-03-09 23:32:07 -040037/*
38 * CLKX and CLKR are the inputs for the Sample Rate Generator.
39 * FSX and FSR are outputs, driven by the sample Rate Generator.
40 */
41#define AUDIO_FORMAT (SND_SOC_DAIFMT_DSP_B | \
42 SND_SOC_DAIFMT_CBM_CFS | \
43 SND_SOC_DAIFMT_IB_NF)
44
Hugo Villeneuve08bd1682008-11-19 01:37:32 -050045static int sffsdr_hw_params(struct snd_pcm_substream *substream,
Hugo Villeneuve090cec82009-03-09 23:32:08 -040046 struct snd_pcm_hw_params *params)
Hugo Villeneuve08bd1682008-11-19 01:37:32 -050047{
48 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000049 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
Hugo Villeneuve08bd1682008-11-19 01:37:32 -050050 int fs;
51 int ret = 0;
52
Hugo Villeneuveac373732009-01-15 15:40:35 -050053 /* Fsref can be 32000, 44100 or 48000. */
54 fs = params_rate(params);
55
56#ifndef CONFIG_SFFSDR_FPGA
57 /* Without the FPGA module, the Fs is fixed at 44100 Hz */
58 if (fs != 44100) {
59 pr_debug("warning: only 44.1 kHz is supported without SFFSDR FPGA module\n");
60 return -EINVAL;
61 }
62#endif
63
Hugo Villeneuve14cbba82009-03-09 23:32:07 -040064 /* set cpu DAI configuration */
65 ret = snd_soc_dai_set_fmt(cpu_dai, AUDIO_FORMAT);
Hugo Villeneuve08bd1682008-11-19 01:37:32 -050066 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",
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +000086 .cpu_dai_name = "davinci-mcbsp",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000087 .codec_dai_name = "pcm3008-hifi",
88 .codec_name = "pcm3008-codec",
Hebbar, Gururajaf08095a2012-08-27 18:56:39 +053089 .platform_name = "davinci-mcbsp",
Hugo Villeneuve08bd1682008-11-19 01:37:32 -050090 .ops = &sffsdr_ops,
91};
92
93/* davinci-sffsdr audio machine driver */
Mark Brown87506542008-11-18 20:50:34 +000094static struct snd_soc_card snd_soc_sffsdr = {
Hugo Villeneuve08bd1682008-11-19 01:37:32 -050095 .name = "DaVinci SFFSDR",
Axel Lin36a16d12011-12-22 21:19:42 +080096 .owner = THIS_MODULE,
Hugo Villeneuve08bd1682008-11-19 01:37:32 -050097 .dai_link = &sffsdr_dai,
98 .num_links = 1,
99};
100
101/* sffsdr audio private data */
102static struct pcm3008_setup_data sffsdr_pcm3008_setup = {
103 .dem0_pin = GPIO(45),
104 .dem1_pin = GPIO(46),
105 .pdad_pin = GPIO(47),
106 .pdda_pin = GPIO(38),
107};
108
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000109struct platform_device pcm3008_codec = {
110 .name = "pcm3008-codec",
111 .id = 0,
112 .dev = {
113 .platform_data = &sffsdr_pcm3008_setup,
114 },
Hugo Villeneuve08bd1682008-11-19 01:37:32 -0500115};
116
117static struct resource sffsdr_snd_resources[] = {
118 {
119 .start = DAVINCI_MCBSP_BASE,
120 .end = DAVINCI_MCBSP_BASE + SZ_8K - 1,
121 .flags = IORESOURCE_MEM,
122 },
123};
124
125static struct evm_snd_platform_data sffsdr_snd_data = {
126 .tx_dma_ch = DAVINCI_DMA_MCBSP_TX,
127 .rx_dma_ch = DAVINCI_DMA_MCBSP_RX,
128};
129
130static struct platform_device *sffsdr_snd_device;
131
132static int __init sffsdr_init(void)
133{
134 int ret;
135
David Brownell5cf1c002009-01-05 02:08:30 -0800136 if (!machine_is_sffsdr())
137 return -EINVAL;
138
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000139 platform_device_register(&pcm3008_codec);
140
Hugo Villeneuve08bd1682008-11-19 01:37:32 -0500141 sffsdr_snd_device = platform_device_alloc("soc-audio", 0);
142 if (!sffsdr_snd_device) {
143 printk(KERN_ERR "platform device allocation failed\n");
144 return -ENOMEM;
145 }
146
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000147 platform_set_drvdata(sffsdr_snd_device, &snd_soc_sffsdr);
Kevin Hilmanbf3dbe52009-02-13 11:36:37 -0800148 platform_device_add_data(sffsdr_snd_device, &sffsdr_snd_data,
149 sizeof(sffsdr_snd_data));
Hugo Villeneuve08bd1682008-11-19 01:37:32 -0500150
151 ret = platform_device_add_resources(sffsdr_snd_device,
152 sffsdr_snd_resources,
153 ARRAY_SIZE(sffsdr_snd_resources));
154 if (ret) {
Andrea Gelminifa2eb002010-10-16 15:19:20 +0200155 printk(KERN_ERR "platform device add resources failed\n");
Hugo Villeneuve08bd1682008-11-19 01:37:32 -0500156 goto error;
157 }
158
159 ret = platform_device_add(sffsdr_snd_device);
160 if (ret)
161 goto error;
162
163 return ret;
164
165error:
166 platform_device_put(sffsdr_snd_device);
167 return ret;
168}
169
170static void __exit sffsdr_exit(void)
171{
172 platform_device_unregister(sffsdr_snd_device);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000173 platform_device_unregister(&pcm3008_codec);
Hugo Villeneuve08bd1682008-11-19 01:37:32 -0500174}
175
176module_init(sffsdr_init);
177module_exit(sffsdr_exit);
178
179MODULE_AUTHOR("Hugo Villeneuve");
180MODULE_DESCRIPTION("Lyrtech SFFSDR ASoC driver");
181MODULE_LICENSE("GPL");