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> |
| 24 | #include <sound/soc-dapm.h> |
| 25 | |
| 26 | #include <asm/dma.h> |
David Brownell | 5cf1c00 | 2009-01-05 02:08:30 -0800 | [diff] [blame] | 27 | #include <asm/mach-types.h> |
Hugo Villeneuve | ac37373 | 2009-01-15 15:40:35 -0500 | [diff] [blame^] | 28 | #ifdef CONFIG_SFFSDR_FPGA |
Hugo Villeneuve | 08bd168 | 2008-11-19 01:37:32 -0500 | [diff] [blame] | 29 | #include <asm/plat-sffsdr/sffsdr-fpga.h> |
Hugo Villeneuve | ac37373 | 2009-01-15 15:40:35 -0500 | [diff] [blame^] | 30 | #endif |
Hugo Villeneuve | 08bd168 | 2008-11-19 01:37:32 -0500 | [diff] [blame] | 31 | |
| 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 | |
| 39 | static int sffsdr_hw_params(struct snd_pcm_substream *substream, |
Mark Brown | dee89c4 | 2008-11-18 22:11:38 +0000 | [diff] [blame] | 40 | struct snd_pcm_hw_params *params, |
| 41 | struct snd_soc_dai *dai) |
Hugo Villeneuve | 08bd168 | 2008-11-19 01:37:32 -0500 | [diff] [blame] | 42 | { |
| 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 Villeneuve | ac37373 | 2009-01-15 15:40:35 -0500 | [diff] [blame^] | 48 | /* 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 Villeneuve | 08bd168 | 2008-11-19 01:37:32 -0500 | [diff] [blame] | 59 | /* 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 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", |
| 86 | .cpu_dai = &davinci_i2s_dai, |
| 87 | .codec_dai = &pcm3008_dai, |
| 88 | .ops = &sffsdr_ops, |
| 89 | }; |
| 90 | |
| 91 | /* davinci-sffsdr audio machine driver */ |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 92 | static struct snd_soc_card snd_soc_sffsdr = { |
Hugo Villeneuve | 08bd168 | 2008-11-19 01:37:32 -0500 | [diff] [blame] | 93 | .name = "DaVinci SFFSDR", |
Mark Brown | 87689d5 | 2008-12-02 16:01:14 +0000 | [diff] [blame] | 94 | .platform = &davinci_soc_platform, |
Hugo Villeneuve | 08bd168 | 2008-11-19 01:37:32 -0500 | [diff] [blame] | 95 | .dai_link = &sffsdr_dai, |
| 96 | .num_links = 1, |
| 97 | }; |
| 98 | |
| 99 | /* sffsdr audio private data */ |
| 100 | static 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 */ |
| 108 | static struct snd_soc_device sffsdr_snd_devdata = { |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 109 | .card = &snd_soc_sffsdr, |
Hugo Villeneuve | 08bd168 | 2008-11-19 01:37:32 -0500 | [diff] [blame] | 110 | .codec_dev = &soc_codec_dev_pcm3008, |
| 111 | .codec_data = &sffsdr_pcm3008_setup, |
| 112 | }; |
| 113 | |
| 114 | static 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 | |
| 122 | static 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 | |
| 127 | static struct platform_device *sffsdr_snd_device; |
| 128 | |
| 129 | static int __init sffsdr_init(void) |
| 130 | { |
| 131 | int ret; |
| 132 | |
David Brownell | 5cf1c00 | 2009-01-05 02:08:30 -0800 | [diff] [blame] | 133 | if (!machine_is_sffsdr()) |
| 134 | return -EINVAL; |
| 135 | |
Hugo Villeneuve | 08bd168 | 2008-11-19 01:37:32 -0500 | [diff] [blame] | 136 | 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 | |
| 160 | error: |
| 161 | platform_device_put(sffsdr_snd_device); |
| 162 | return ret; |
| 163 | } |
| 164 | |
| 165 | static void __exit sffsdr_exit(void) |
| 166 | { |
| 167 | platform_device_unregister(sffsdr_snd_device); |
| 168 | } |
| 169 | |
| 170 | module_init(sffsdr_init); |
| 171 | module_exit(sffsdr_exit); |
| 172 | |
| 173 | MODULE_AUTHOR("Hugo Villeneuve"); |
| 174 | MODULE_DESCRIPTION("Lyrtech SFFSDR ASoC driver"); |
| 175 | MODULE_LICENSE("GPL"); |