Hugo Villeneuve | 08bd168 | 2008-11-19 01:37:32 -0500 | [diff] [blame] | 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> |
Hugo Villeneuve | 08bd168 | 2008-11-19 01:37:32 -0500 | [diff] [blame] | 24 | |
| 25 | #include <asm/dma.h> |
David Brownell | 5cf1c00 | 2009-01-05 02:08:30 -0800 | [diff] [blame] | 26 | #include <asm/mach-types.h> |
Hugo Villeneuve | ac37373 | 2009-01-15 15:40:35 -0500 | [diff] [blame] | 27 | #ifdef CONFIG_SFFSDR_FPGA |
Hugo Villeneuve | 08bd168 | 2008-11-19 01:37:32 -0500 | [diff] [blame] | 28 | #include <asm/plat-sffsdr/sffsdr-fpga.h> |
Hugo Villeneuve | ac37373 | 2009-01-15 15:40:35 -0500 | [diff] [blame] | 29 | #endif |
Hugo Villeneuve | 08bd168 | 2008-11-19 01:37:32 -0500 | [diff] [blame] | 30 | |
Hugo Villeneuve | 08bd168 | 2008-11-19 01:37:32 -0500 | [diff] [blame] | 31 | #include <mach/edma.h> |
| 32 | |
| 33 | #include "../codecs/pcm3008.h" |
| 34 | #include "davinci-pcm.h" |
| 35 | #include "davinci-i2s.h" |
| 36 | |
Hugo Villeneuve | 14cbba8 | 2009-03-09 23:32:07 -0400 | [diff] [blame] | 37 | /* |
| 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 Villeneuve | 08bd168 | 2008-11-19 01:37:32 -0500 | [diff] [blame] | 45 | static int sffsdr_hw_params(struct snd_pcm_substream *substream, |
Hugo Villeneuve | 090cec8 | 2009-03-09 23:32:08 -0400 | [diff] [blame] | 46 | struct snd_pcm_hw_params *params) |
Hugo Villeneuve | 08bd168 | 2008-11-19 01:37:32 -0500 | [diff] [blame] | 47 | { |
| 48 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 49 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Hugo Villeneuve | 08bd168 | 2008-11-19 01:37:32 -0500 | [diff] [blame] | 50 | int fs; |
| 51 | int ret = 0; |
| 52 | |
Hugo Villeneuve | ac37373 | 2009-01-15 15:40:35 -0500 | [diff] [blame] | 53 | /* 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 Villeneuve | 14cbba8 | 2009-03-09 23:32:07 -0400 | [diff] [blame] | 64 | /* set cpu DAI configuration */ |
| 65 | ret = snd_soc_dai_set_fmt(cpu_dai, AUDIO_FORMAT); |
Hugo Villeneuve | 08bd168 | 2008-11-19 01:37:32 -0500 | [diff] [blame] | 66 | if (ret < 0) |
| 67 | return ret; |
| 68 | |
Hugo Villeneuve | 08bd168 | 2008-11-19 01:37:32 -0500 | [diff] [blame] | 69 | pr_debug("sffsdr_hw_params: rate = %d Hz\n", fs); |
| 70 | |
Hugo Villeneuve | ac37373 | 2009-01-15 15:40:35 -0500 | [diff] [blame] | 71 | #ifndef CONFIG_SFFSDR_FPGA |
| 72 | return 0; |
| 73 | #else |
Hugo Villeneuve | 08bd168 | 2008-11-19 01:37:32 -0500 | [diff] [blame] | 74 | return sffsdr_fpga_set_codec_fs(fs); |
Hugo Villeneuve | ac37373 | 2009-01-15 15:40:35 -0500 | [diff] [blame] | 75 | #endif |
Hugo Villeneuve | 08bd168 | 2008-11-19 01:37:32 -0500 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | static struct snd_soc_ops sffsdr_ops = { |
| 79 | .hw_params = sffsdr_hw_params, |
| 80 | }; |
| 81 | |
| 82 | /* davinci-sffsdr digital audio interface glue - connects codec <--> CPU */ |
| 83 | static struct snd_soc_dai_link sffsdr_dai = { |
| 84 | .name = "PCM3008", /* Codec name */ |
| 85 | .stream_name = "PCM3008 HiFi", |
Chris Paulson-Ellis | bedad0c | 2010-11-16 12:27:09 +0000 | [diff] [blame] | 86 | .cpu_dai_name = "davinci-mcbsp", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 87 | .codec_dai_name = "pcm3008-hifi", |
| 88 | .codec_name = "pcm3008-codec", |
| 89 | .platform_name = "davinci-pcm-audio", |
Hugo Villeneuve | 08bd168 | 2008-11-19 01:37:32 -0500 | [diff] [blame] | 90 | .ops = &sffsdr_ops, |
| 91 | }; |
| 92 | |
| 93 | /* davinci-sffsdr audio machine driver */ |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 94 | static struct snd_soc_card snd_soc_sffsdr = { |
Hugo Villeneuve | 08bd168 | 2008-11-19 01:37:32 -0500 | [diff] [blame] | 95 | .name = "DaVinci SFFSDR", |
| 96 | .dai_link = &sffsdr_dai, |
| 97 | .num_links = 1, |
| 98 | }; |
| 99 | |
| 100 | /* sffsdr audio private data */ |
| 101 | static struct pcm3008_setup_data sffsdr_pcm3008_setup = { |
| 102 | .dem0_pin = GPIO(45), |
| 103 | .dem1_pin = GPIO(46), |
| 104 | .pdad_pin = GPIO(47), |
| 105 | .pdda_pin = GPIO(38), |
| 106 | }; |
| 107 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 108 | struct platform_device pcm3008_codec = { |
| 109 | .name = "pcm3008-codec", |
| 110 | .id = 0, |
| 111 | .dev = { |
| 112 | .platform_data = &sffsdr_pcm3008_setup, |
| 113 | }, |
Hugo Villeneuve | 08bd168 | 2008-11-19 01:37:32 -0500 | [diff] [blame] | 114 | }; |
| 115 | |
| 116 | static struct resource sffsdr_snd_resources[] = { |
| 117 | { |
| 118 | .start = DAVINCI_MCBSP_BASE, |
| 119 | .end = DAVINCI_MCBSP_BASE + SZ_8K - 1, |
| 120 | .flags = IORESOURCE_MEM, |
| 121 | }, |
| 122 | }; |
| 123 | |
| 124 | static struct evm_snd_platform_data sffsdr_snd_data = { |
| 125 | .tx_dma_ch = DAVINCI_DMA_MCBSP_TX, |
| 126 | .rx_dma_ch = DAVINCI_DMA_MCBSP_RX, |
| 127 | }; |
| 128 | |
| 129 | static struct platform_device *sffsdr_snd_device; |
| 130 | |
| 131 | static int __init sffsdr_init(void) |
| 132 | { |
| 133 | int ret; |
| 134 | |
David Brownell | 5cf1c00 | 2009-01-05 02:08:30 -0800 | [diff] [blame] | 135 | if (!machine_is_sffsdr()) |
| 136 | return -EINVAL; |
| 137 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 138 | platform_device_register(&pcm3008_codec); |
| 139 | |
Hugo Villeneuve | 08bd168 | 2008-11-19 01:37:32 -0500 | [diff] [blame] | 140 | sffsdr_snd_device = platform_device_alloc("soc-audio", 0); |
| 141 | if (!sffsdr_snd_device) { |
| 142 | printk(KERN_ERR "platform device allocation failed\n"); |
| 143 | return -ENOMEM; |
| 144 | } |
| 145 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 146 | platform_set_drvdata(sffsdr_snd_device, &snd_soc_sffsdr); |
Kevin Hilman | bf3dbe5 | 2009-02-13 11:36:37 -0800 | [diff] [blame] | 147 | platform_device_add_data(sffsdr_snd_device, &sffsdr_snd_data, |
| 148 | sizeof(sffsdr_snd_data)); |
Hugo Villeneuve | 08bd168 | 2008-11-19 01:37:32 -0500 | [diff] [blame] | 149 | |
| 150 | ret = platform_device_add_resources(sffsdr_snd_device, |
| 151 | sffsdr_snd_resources, |
| 152 | ARRAY_SIZE(sffsdr_snd_resources)); |
| 153 | if (ret) { |
Andrea Gelmini | fa2eb00 | 2010-10-16 15:19:20 +0200 | [diff] [blame] | 154 | printk(KERN_ERR "platform device add resources failed\n"); |
Hugo Villeneuve | 08bd168 | 2008-11-19 01:37:32 -0500 | [diff] [blame] | 155 | goto error; |
| 156 | } |
| 157 | |
| 158 | ret = platform_device_add(sffsdr_snd_device); |
| 159 | if (ret) |
| 160 | goto error; |
| 161 | |
| 162 | return ret; |
| 163 | |
| 164 | error: |
| 165 | platform_device_put(sffsdr_snd_device); |
| 166 | return ret; |
| 167 | } |
| 168 | |
| 169 | static void __exit sffsdr_exit(void) |
| 170 | { |
| 171 | platform_device_unregister(sffsdr_snd_device); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 172 | platform_device_unregister(&pcm3008_codec); |
Hugo Villeneuve | 08bd168 | 2008-11-19 01:37:32 -0500 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | module_init(sffsdr_init); |
| 176 | module_exit(sffsdr_exit); |
| 177 | |
| 178 | MODULE_AUTHOR("Hugo Villeneuve"); |
| 179 | MODULE_DESCRIPTION("Lyrtech SFFSDR ASoC driver"); |
| 180 | MODULE_LICENSE("GPL"); |