Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 1 | /* |
| 2 | * ASoC driver for TI DAVINCI EVM platform |
| 3 | * |
Vladimir Barinov | d6b5203 | 2008-09-29 23:14:11 +0400 | [diff] [blame] | 4 | * Author: Vladimir Barinov, <vbarinov@embeddedalley.com> |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 5 | * Copyright: (C) 2007 MontaVista Software, Inc., <source@mvista.com> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License version 2 as |
| 9 | * published by the Free Software Foundation. |
| 10 | */ |
| 11 | |
| 12 | #include <linux/module.h> |
| 13 | #include <linux/moduleparam.h> |
| 14 | #include <linux/timer.h> |
| 15 | #include <linux/interrupt.h> |
| 16 | #include <linux/platform_device.h> |
| 17 | #include <sound/core.h> |
| 18 | #include <sound/pcm.h> |
| 19 | #include <sound/soc.h> |
| 20 | #include <sound/soc-dapm.h> |
| 21 | |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 22 | #include <asm/dma.h> |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 23 | #include <mach/hardware.h> |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 24 | |
| 25 | #include "../codecs/tlv320aic3x.h" |
| 26 | #include "davinci-pcm.h" |
| 27 | #include "davinci-i2s.h" |
| 28 | |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 29 | |
Troy Kisky | d6f8339 | 2008-12-19 13:05:25 -0700 | [diff] [blame] | 30 | #define AUDIO_FORMAT (SND_SOC_DAIFMT_DSP_B | \ |
| 31 | SND_SOC_DAIFMT_CBM_CFM | SND_SOC_DAIFMT_IB_NF) |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 32 | static int evm_hw_params(struct snd_pcm_substream *substream, |
| 33 | struct snd_pcm_hw_params *params) |
| 34 | { |
| 35 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | 9cb132d | 2008-07-07 16:07:42 +0100 | [diff] [blame] | 36 | struct snd_soc_dai *codec_dai = rtd->dai->codec_dai; |
| 37 | struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai; |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 38 | int ret = 0; |
David Brownell | 05d5e99 | 2009-01-04 02:50:10 -0800 | [diff] [blame] | 39 | unsigned sysclk; |
| 40 | |
| 41 | /* ASP1 on DM355 EVM is clocked by an external oscillator */ |
| 42 | if (machine_is_davinci_dm355_evm()) |
| 43 | sysclk = 27000000; |
| 44 | |
| 45 | /* ASP0 in DM6446 EVM is clocked by U55, as configured by |
| 46 | * board-dm644x-evm.c using GPIOs from U18. There are six |
| 47 | * options; here we "know" we use a 48 KHz sample rate. |
| 48 | */ |
| 49 | else if (machine_is_davinci_evm()) |
| 50 | sysclk = 12288000; |
| 51 | |
| 52 | else |
| 53 | return -EINVAL; |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 54 | |
| 55 | /* set codec DAI configuration */ |
Troy Kisky | 9e03162 | 2008-12-19 13:05:23 -0700 | [diff] [blame] | 56 | ret = snd_soc_dai_set_fmt(codec_dai, AUDIO_FORMAT); |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 57 | if (ret < 0) |
| 58 | return ret; |
| 59 | |
| 60 | /* set cpu DAI configuration */ |
Troy Kisky | 9e03162 | 2008-12-19 13:05:23 -0700 | [diff] [blame] | 61 | ret = snd_soc_dai_set_fmt(cpu_dai, AUDIO_FORMAT); |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 62 | if (ret < 0) |
| 63 | return ret; |
| 64 | |
| 65 | /* set the codec system clock */ |
David Brownell | 05d5e99 | 2009-01-04 02:50:10 -0800 | [diff] [blame] | 66 | ret = snd_soc_dai_set_sysclk(codec_dai, 0, sysclk, SND_SOC_CLOCK_OUT); |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 67 | if (ret < 0) |
| 68 | return ret; |
| 69 | |
| 70 | return 0; |
| 71 | } |
| 72 | |
| 73 | static struct snd_soc_ops evm_ops = { |
| 74 | .hw_params = evm_hw_params, |
| 75 | }; |
| 76 | |
| 77 | /* davinci-evm machine dapm widgets */ |
| 78 | static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = { |
| 79 | SND_SOC_DAPM_HP("Headphone Jack", NULL), |
| 80 | SND_SOC_DAPM_LINE("Line Out", NULL), |
| 81 | SND_SOC_DAPM_MIC("Mic Jack", NULL), |
| 82 | SND_SOC_DAPM_LINE("Line In", NULL), |
| 83 | }; |
| 84 | |
| 85 | /* davinci-evm machine audio_mapnections to the codec pins */ |
Mark Brown | acf497f | 2008-05-13 14:58:30 +0200 | [diff] [blame] | 86 | static const struct snd_soc_dapm_route audio_map[] = { |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 87 | /* Headphone connected to HPLOUT, HPROUT */ |
| 88 | {"Headphone Jack", NULL, "HPLOUT"}, |
| 89 | {"Headphone Jack", NULL, "HPROUT"}, |
| 90 | |
| 91 | /* Line Out connected to LLOUT, RLOUT */ |
| 92 | {"Line Out", NULL, "LLOUT"}, |
| 93 | {"Line Out", NULL, "RLOUT"}, |
| 94 | |
| 95 | /* Mic connected to (MIC3L | MIC3R) */ |
| 96 | {"MIC3L", NULL, "Mic Bias 2V"}, |
| 97 | {"MIC3R", NULL, "Mic Bias 2V"}, |
| 98 | {"Mic Bias 2V", NULL, "Mic Jack"}, |
| 99 | |
| 100 | /* Line In connected to (LINE1L | LINE2L), (LINE1R | LINE2R) */ |
| 101 | {"LINE1L", NULL, "Line In"}, |
| 102 | {"LINE2L", NULL, "Line In"}, |
| 103 | {"LINE1R", NULL, "Line In"}, |
| 104 | {"LINE2R", NULL, "Line In"}, |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 105 | }; |
| 106 | |
| 107 | /* Logic for a aic3x as connected on a davinci-evm */ |
| 108 | static int evm_aic3x_init(struct snd_soc_codec *codec) |
| 109 | { |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 110 | /* Add davinci-evm specific widgets */ |
Mark Brown | acf497f | 2008-05-13 14:58:30 +0200 | [diff] [blame] | 111 | snd_soc_dapm_new_controls(codec, aic3x_dapm_widgets, |
| 112 | ARRAY_SIZE(aic3x_dapm_widgets)); |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 113 | |
| 114 | /* Set up davinci-evm specific audio path audio_map */ |
Mark Brown | acf497f | 2008-05-13 14:58:30 +0200 | [diff] [blame] | 115 | snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 116 | |
| 117 | /* not connected */ |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 118 | snd_soc_dapm_disable_pin(codec, "MONO_LOUT"); |
| 119 | snd_soc_dapm_disable_pin(codec, "HPLCOM"); |
| 120 | snd_soc_dapm_disable_pin(codec, "HPRCOM"); |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 121 | |
| 122 | /* always connected */ |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 123 | snd_soc_dapm_enable_pin(codec, "Headphone Jack"); |
| 124 | snd_soc_dapm_enable_pin(codec, "Line Out"); |
| 125 | snd_soc_dapm_enable_pin(codec, "Mic Jack"); |
| 126 | snd_soc_dapm_enable_pin(codec, "Line In"); |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 127 | |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 128 | snd_soc_dapm_sync(codec); |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 129 | |
| 130 | return 0; |
| 131 | } |
| 132 | |
| 133 | /* davinci-evm digital audio interface glue - connects codec <--> CPU */ |
| 134 | static struct snd_soc_dai_link evm_dai = { |
| 135 | .name = "TLV320AIC3X", |
| 136 | .stream_name = "AIC3X", |
| 137 | .cpu_dai = &davinci_i2s_dai, |
| 138 | .codec_dai = &aic3x_dai, |
| 139 | .init = evm_aic3x_init, |
| 140 | .ops = &evm_ops, |
| 141 | }; |
| 142 | |
| 143 | /* davinci-evm audio machine driver */ |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 144 | static struct snd_soc_card snd_soc_card_evm = { |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 145 | .name = "DaVinci EVM", |
Mark Brown | 87689d5 | 2008-12-02 16:01:14 +0000 | [diff] [blame] | 146 | .platform = &davinci_soc_platform, |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 147 | .dai_link = &evm_dai, |
| 148 | .num_links = 1, |
| 149 | }; |
| 150 | |
| 151 | /* evm audio private data */ |
| 152 | static struct aic3x_setup_data evm_aic3x_setup = { |
Jean Delvare | ba8ed12 | 2008-09-22 14:15:53 +0200 | [diff] [blame] | 153 | .i2c_bus = 0, |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 154 | .i2c_address = 0x1b, |
| 155 | }; |
| 156 | |
| 157 | /* evm audio subsystem */ |
| 158 | static struct snd_soc_device evm_snd_devdata = { |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 159 | .card = &snd_soc_card_evm, |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 160 | .codec_dev = &soc_codec_dev_aic3x, |
| 161 | .codec_data = &evm_aic3x_setup, |
| 162 | }; |
| 163 | |
| 164 | static struct resource evm_snd_resources[] = { |
| 165 | { |
| 166 | .start = DAVINCI_MCBSP_BASE, |
| 167 | .end = DAVINCI_MCBSP_BASE + SZ_8K - 1, |
| 168 | .flags = IORESOURCE_MEM, |
| 169 | }, |
| 170 | }; |
| 171 | |
| 172 | static struct evm_snd_platform_data evm_snd_data = { |
| 173 | .tx_dma_ch = DM644X_DMACH_MCBSP_TX, |
| 174 | .rx_dma_ch = DM644X_DMACH_MCBSP_RX, |
| 175 | }; |
| 176 | |
| 177 | static struct platform_device *evm_snd_device; |
| 178 | |
| 179 | static int __init evm_init(void) |
| 180 | { |
| 181 | int ret; |
| 182 | |
| 183 | evm_snd_device = platform_device_alloc("soc-audio", 0); |
| 184 | if (!evm_snd_device) |
| 185 | return -ENOMEM; |
| 186 | |
| 187 | platform_set_drvdata(evm_snd_device, &evm_snd_devdata); |
| 188 | evm_snd_devdata.dev = &evm_snd_device->dev; |
Kevin Hilman | bf3dbe5 | 2009-02-13 11:36:37 -0800 | [diff] [blame] | 189 | platform_device_add_data(evm_snd_device, &evm_snd_data, |
| 190 | sizeof(evm_snd_data)); |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 191 | |
| 192 | ret = platform_device_add_resources(evm_snd_device, evm_snd_resources, |
| 193 | ARRAY_SIZE(evm_snd_resources)); |
| 194 | if (ret) { |
| 195 | platform_device_put(evm_snd_device); |
| 196 | return ret; |
| 197 | } |
| 198 | |
| 199 | ret = platform_device_add(evm_snd_device); |
| 200 | if (ret) |
| 201 | platform_device_put(evm_snd_device); |
| 202 | |
| 203 | return ret; |
| 204 | } |
| 205 | |
| 206 | static void __exit evm_exit(void) |
| 207 | { |
| 208 | platform_device_unregister(evm_snd_device); |
| 209 | } |
| 210 | |
| 211 | module_init(evm_init); |
| 212 | module_exit(evm_exit); |
| 213 | |
| 214 | MODULE_AUTHOR("Vladimir Barinov"); |
| 215 | MODULE_DESCRIPTION("TI DAVINCI EVM ASoC driver"); |
| 216 | MODULE_LICENSE("GPL"); |