Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 1 | /* |
| 2 | * ASoC driver for TI DAVINCI EVM platform |
| 3 | * |
| 4 | * Author: Vladimir Barinov, <vbarinov@ru.mvista.com> |
| 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 | |
| 22 | #include <asm/mach-types.h> |
| 23 | #include <asm/dma.h> |
| 24 | #include <asm/arch/hardware.h> |
| 25 | |
| 26 | #include "../codecs/tlv320aic3x.h" |
| 27 | #include "davinci-pcm.h" |
| 28 | #include "davinci-i2s.h" |
| 29 | |
| 30 | #define EVM_CODEC_CLOCK 22579200 |
| 31 | |
| 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; |
| 39 | |
| 40 | /* set codec DAI configuration */ |
Liam Girdwood | 64105cf | 2008-07-08 13:19:18 +0100 | [diff] [blame] | 41 | ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S | |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 42 | SND_SOC_DAIFMT_CBM_CFM); |
| 43 | if (ret < 0) |
| 44 | return ret; |
| 45 | |
| 46 | /* set cpu DAI configuration */ |
Liam Girdwood | 64105cf | 2008-07-08 13:19:18 +0100 | [diff] [blame] | 47 | ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_CBM_CFM | |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 48 | SND_SOC_DAIFMT_IB_NF); |
| 49 | if (ret < 0) |
| 50 | return ret; |
| 51 | |
| 52 | /* set the codec system clock */ |
Liam Girdwood | 64105cf | 2008-07-08 13:19:18 +0100 | [diff] [blame] | 53 | ret = snd_soc_dai_set_sysclk(codec_dai, 0, EVM_CODEC_CLOCK, |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 54 | SND_SOC_CLOCK_OUT); |
| 55 | if (ret < 0) |
| 56 | return ret; |
| 57 | |
| 58 | return 0; |
| 59 | } |
| 60 | |
| 61 | static struct snd_soc_ops evm_ops = { |
| 62 | .hw_params = evm_hw_params, |
| 63 | }; |
| 64 | |
| 65 | /* davinci-evm machine dapm widgets */ |
| 66 | static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = { |
| 67 | SND_SOC_DAPM_HP("Headphone Jack", NULL), |
| 68 | SND_SOC_DAPM_LINE("Line Out", NULL), |
| 69 | SND_SOC_DAPM_MIC("Mic Jack", NULL), |
| 70 | SND_SOC_DAPM_LINE("Line In", NULL), |
| 71 | }; |
| 72 | |
| 73 | /* davinci-evm machine audio_mapnections to the codec pins */ |
Mark Brown | acf497f | 2008-05-13 14:58:30 +0200 | [diff] [blame] | 74 | static const struct snd_soc_dapm_route audio_map[] = { |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 75 | /* Headphone connected to HPLOUT, HPROUT */ |
| 76 | {"Headphone Jack", NULL, "HPLOUT"}, |
| 77 | {"Headphone Jack", NULL, "HPROUT"}, |
| 78 | |
| 79 | /* Line Out connected to LLOUT, RLOUT */ |
| 80 | {"Line Out", NULL, "LLOUT"}, |
| 81 | {"Line Out", NULL, "RLOUT"}, |
| 82 | |
| 83 | /* Mic connected to (MIC3L | MIC3R) */ |
| 84 | {"MIC3L", NULL, "Mic Bias 2V"}, |
| 85 | {"MIC3R", NULL, "Mic Bias 2V"}, |
| 86 | {"Mic Bias 2V", NULL, "Mic Jack"}, |
| 87 | |
| 88 | /* Line In connected to (LINE1L | LINE2L), (LINE1R | LINE2R) */ |
| 89 | {"LINE1L", NULL, "Line In"}, |
| 90 | {"LINE2L", NULL, "Line In"}, |
| 91 | {"LINE1R", NULL, "Line In"}, |
| 92 | {"LINE2R", NULL, "Line In"}, |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 93 | }; |
| 94 | |
| 95 | /* Logic for a aic3x as connected on a davinci-evm */ |
| 96 | static int evm_aic3x_init(struct snd_soc_codec *codec) |
| 97 | { |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 98 | /* Add davinci-evm specific widgets */ |
Mark Brown | acf497f | 2008-05-13 14:58:30 +0200 | [diff] [blame] | 99 | snd_soc_dapm_new_controls(codec, aic3x_dapm_widgets, |
| 100 | ARRAY_SIZE(aic3x_dapm_widgets)); |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 101 | |
| 102 | /* Set up davinci-evm specific audio path audio_map */ |
Mark Brown | acf497f | 2008-05-13 14:58:30 +0200 | [diff] [blame] | 103 | snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 104 | |
| 105 | /* not connected */ |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 106 | snd_soc_dapm_disable_pin(codec, "MONO_LOUT"); |
| 107 | snd_soc_dapm_disable_pin(codec, "HPLCOM"); |
| 108 | snd_soc_dapm_disable_pin(codec, "HPRCOM"); |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 109 | |
| 110 | /* always connected */ |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 111 | snd_soc_dapm_enable_pin(codec, "Headphone Jack"); |
| 112 | snd_soc_dapm_enable_pin(codec, "Line Out"); |
| 113 | snd_soc_dapm_enable_pin(codec, "Mic Jack"); |
| 114 | snd_soc_dapm_enable_pin(codec, "Line In"); |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 115 | |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 116 | snd_soc_dapm_sync(codec); |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 117 | |
| 118 | return 0; |
| 119 | } |
| 120 | |
| 121 | /* davinci-evm digital audio interface glue - connects codec <--> CPU */ |
| 122 | static struct snd_soc_dai_link evm_dai = { |
| 123 | .name = "TLV320AIC3X", |
| 124 | .stream_name = "AIC3X", |
| 125 | .cpu_dai = &davinci_i2s_dai, |
| 126 | .codec_dai = &aic3x_dai, |
| 127 | .init = evm_aic3x_init, |
| 128 | .ops = &evm_ops, |
| 129 | }; |
| 130 | |
| 131 | /* davinci-evm audio machine driver */ |
| 132 | static struct snd_soc_machine snd_soc_machine_evm = { |
| 133 | .name = "DaVinci EVM", |
| 134 | .dai_link = &evm_dai, |
| 135 | .num_links = 1, |
| 136 | }; |
| 137 | |
| 138 | /* evm audio private data */ |
| 139 | static struct aic3x_setup_data evm_aic3x_setup = { |
| 140 | .i2c_address = 0x1b, |
| 141 | }; |
| 142 | |
| 143 | /* evm audio subsystem */ |
| 144 | static struct snd_soc_device evm_snd_devdata = { |
| 145 | .machine = &snd_soc_machine_evm, |
| 146 | .platform = &davinci_soc_platform, |
| 147 | .codec_dev = &soc_codec_dev_aic3x, |
| 148 | .codec_data = &evm_aic3x_setup, |
| 149 | }; |
| 150 | |
| 151 | static struct resource evm_snd_resources[] = { |
| 152 | { |
| 153 | .start = DAVINCI_MCBSP_BASE, |
| 154 | .end = DAVINCI_MCBSP_BASE + SZ_8K - 1, |
| 155 | .flags = IORESOURCE_MEM, |
| 156 | }, |
| 157 | }; |
| 158 | |
| 159 | static struct evm_snd_platform_data evm_snd_data = { |
| 160 | .tx_dma_ch = DM644X_DMACH_MCBSP_TX, |
| 161 | .rx_dma_ch = DM644X_DMACH_MCBSP_RX, |
| 162 | }; |
| 163 | |
| 164 | static struct platform_device *evm_snd_device; |
| 165 | |
| 166 | static int __init evm_init(void) |
| 167 | { |
| 168 | int ret; |
| 169 | |
| 170 | evm_snd_device = platform_device_alloc("soc-audio", 0); |
| 171 | if (!evm_snd_device) |
| 172 | return -ENOMEM; |
| 173 | |
| 174 | platform_set_drvdata(evm_snd_device, &evm_snd_devdata); |
| 175 | evm_snd_devdata.dev = &evm_snd_device->dev; |
| 176 | evm_snd_device->dev.platform_data = &evm_snd_data; |
| 177 | |
| 178 | ret = platform_device_add_resources(evm_snd_device, evm_snd_resources, |
| 179 | ARRAY_SIZE(evm_snd_resources)); |
| 180 | if (ret) { |
| 181 | platform_device_put(evm_snd_device); |
| 182 | return ret; |
| 183 | } |
| 184 | |
| 185 | ret = platform_device_add(evm_snd_device); |
| 186 | if (ret) |
| 187 | platform_device_put(evm_snd_device); |
| 188 | |
| 189 | return ret; |
| 190 | } |
| 191 | |
| 192 | static void __exit evm_exit(void) |
| 193 | { |
| 194 | platform_device_unregister(evm_snd_device); |
| 195 | } |
| 196 | |
| 197 | module_init(evm_init); |
| 198 | module_exit(evm_exit); |
| 199 | |
| 200 | MODULE_AUTHOR("Vladimir Barinov"); |
| 201 | MODULE_DESCRIPTION("TI DAVINCI EVM ASoC driver"); |
| 202 | MODULE_LICENSE("GPL"); |