Arun KS | 17f9ecf | 2008-10-02 15:02:45 +0530 | [diff] [blame] | 1 | /* |
| 2 | * osk5912.c -- SoC audio for OSK 5912 |
| 3 | * |
| 4 | * Copyright (C) 2008 Mistral Solutions |
| 5 | * |
| 6 | * Contact: Arun KS <arunks@mistralsolutions.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License |
| 10 | * version 2 as published by the Free Software Foundation. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, but |
| 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA |
| 20 | * 02110-1301 USA |
| 21 | * |
| 22 | */ |
| 23 | |
| 24 | #include <linux/clk.h> |
| 25 | #include <linux/platform_device.h> |
| 26 | #include <sound/core.h> |
| 27 | #include <sound/pcm.h> |
| 28 | #include <sound/soc.h> |
Arun KS | 17f9ecf | 2008-10-02 15:02:45 +0530 | [diff] [blame] | 29 | |
| 30 | #include <asm/mach-types.h> |
| 31 | #include <mach/hardware.h> |
| 32 | #include <linux/gpio.h> |
Paul Gortmaker | da155d5 | 2011-07-15 12:38:28 -0400 | [diff] [blame] | 33 | #include <linux/module.h> |
Tony Lindgren | ce491cf | 2009-10-20 09:40:47 -0700 | [diff] [blame] | 34 | #include <plat/mcbsp.h> |
Arun KS | 17f9ecf | 2008-10-02 15:02:45 +0530 | [diff] [blame] | 35 | |
| 36 | #include "omap-mcbsp.h" |
| 37 | #include "omap-pcm.h" |
| 38 | #include "../codecs/tlv320aic23.h" |
| 39 | |
| 40 | #define CODEC_CLOCK 12000000 |
| 41 | |
| 42 | static struct clk *tlv320aic23_mclk; |
| 43 | |
| 44 | static int osk_startup(struct snd_pcm_substream *substream) |
| 45 | { |
| 46 | return clk_enable(tlv320aic23_mclk); |
| 47 | } |
| 48 | |
| 49 | static void osk_shutdown(struct snd_pcm_substream *substream) |
| 50 | { |
| 51 | clk_disable(tlv320aic23_mclk); |
| 52 | } |
| 53 | |
| 54 | static int osk_hw_params(struct snd_pcm_substream *substream, |
| 55 | struct snd_pcm_hw_params *params) |
| 56 | { |
| 57 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 58 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
Arun KS | 17f9ecf | 2008-10-02 15:02:45 +0530 | [diff] [blame] | 59 | int err; |
| 60 | |
Arun KS | 17f9ecf | 2008-10-02 15:02:45 +0530 | [diff] [blame] | 61 | /* Set the codec system clock for DAC and ADC */ |
| 62 | err = |
| 63 | snd_soc_dai_set_sysclk(codec_dai, 0, CODEC_CLOCK, SND_SOC_CLOCK_IN); |
| 64 | |
| 65 | if (err < 0) { |
| 66 | printk(KERN_ERR "can't set codec system clock\n"); |
| 67 | return err; |
| 68 | } |
| 69 | |
| 70 | return err; |
| 71 | } |
| 72 | |
| 73 | static struct snd_soc_ops osk_ops = { |
| 74 | .startup = osk_startup, |
| 75 | .hw_params = osk_hw_params, |
| 76 | .shutdown = osk_shutdown, |
| 77 | }; |
| 78 | |
| 79 | static const struct snd_soc_dapm_widget tlv320aic23_dapm_widgets[] = { |
| 80 | SND_SOC_DAPM_HP("Headphone Jack", NULL), |
| 81 | SND_SOC_DAPM_LINE("Line In", NULL), |
| 82 | SND_SOC_DAPM_MIC("Mic Jack", NULL), |
| 83 | }; |
| 84 | |
| 85 | static const struct snd_soc_dapm_route audio_map[] = { |
| 86 | {"Headphone Jack", NULL, "LHPOUT"}, |
| 87 | {"Headphone Jack", NULL, "RHPOUT"}, |
| 88 | |
| 89 | {"LLINEIN", NULL, "Line In"}, |
| 90 | {"RLINEIN", NULL, "Line In"}, |
| 91 | |
| 92 | {"MICIN", NULL, "Mic Jack"}, |
| 93 | }; |
| 94 | |
Arun KS | 17f9ecf | 2008-10-02 15:02:45 +0530 | [diff] [blame] | 95 | /* Digital audio interface glue - connects codec <--> CPU */ |
| 96 | static struct snd_soc_dai_link osk_dai = { |
| 97 | .name = "TLV320AIC23", |
| 98 | .stream_name = "AIC23", |
Peter Ujfalusi | 45656b4 | 2012-02-14 18:20:58 +0200 | [diff] [blame] | 99 | .cpu_dai_name = "omap-mcbsp.1", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 100 | .codec_dai_name = "tlv320aic23-hifi", |
| 101 | .platform_name = "omap-pcm-audio", |
| 102 | .codec_name = "tlv320aic23-codec", |
Jarkko Nikula | cf9feff | 2011-09-30 16:07:45 +0300 | [diff] [blame] | 103 | .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_NB_NF | |
| 104 | SND_SOC_DAIFMT_CBM_CFM, |
Arun KS | 17f9ecf | 2008-10-02 15:02:45 +0530 | [diff] [blame] | 105 | .ops = &osk_ops, |
| 106 | }; |
| 107 | |
| 108 | /* Audio machine driver */ |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 109 | static struct snd_soc_card snd_soc_card_osk = { |
Arun KS | 17f9ecf | 2008-10-02 15:02:45 +0530 | [diff] [blame] | 110 | .name = "OSK5912", |
Axel Lin | b425b88 | 2011-12-22 11:08:59 +0800 | [diff] [blame] | 111 | .owner = THIS_MODULE, |
Arun KS | 17f9ecf | 2008-10-02 15:02:45 +0530 | [diff] [blame] | 112 | .dai_link = &osk_dai, |
| 113 | .num_links = 1, |
Peter Ujfalusi | 93b4d79 | 2011-10-10 15:34:11 +0300 | [diff] [blame] | 114 | |
| 115 | .dapm_widgets = tlv320aic23_dapm_widgets, |
| 116 | .num_dapm_widgets = ARRAY_SIZE(tlv320aic23_dapm_widgets), |
| 117 | .dapm_routes = audio_map, |
| 118 | .num_dapm_routes = ARRAY_SIZE(audio_map), |
Arun KS | 17f9ecf | 2008-10-02 15:02:45 +0530 | [diff] [blame] | 119 | }; |
| 120 | |
Arun KS | 17f9ecf | 2008-10-02 15:02:45 +0530 | [diff] [blame] | 121 | static struct platform_device *osk_snd_device; |
| 122 | |
| 123 | static int __init osk_soc_init(void) |
| 124 | { |
| 125 | int err; |
| 126 | u32 curRate; |
| 127 | struct device *dev; |
| 128 | |
| 129 | if (!(machine_is_omap_osk())) |
| 130 | return -ENODEV; |
| 131 | |
| 132 | osk_snd_device = platform_device_alloc("soc-audio", -1); |
| 133 | if (!osk_snd_device) |
| 134 | return -ENOMEM; |
| 135 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 136 | platform_set_drvdata(osk_snd_device, &snd_soc_card_osk); |
Arun KS | 17f9ecf | 2008-10-02 15:02:45 +0530 | [diff] [blame] | 137 | err = platform_device_add(osk_snd_device); |
| 138 | if (err) |
| 139 | goto err1; |
| 140 | |
| 141 | dev = &osk_snd_device->dev; |
| 142 | |
| 143 | tlv320aic23_mclk = clk_get(dev, "mclk"); |
| 144 | if (IS_ERR(tlv320aic23_mclk)) { |
| 145 | printk(KERN_ERR "Could not get mclk clock\n"); |
Axel Lin | 2543618 | 2010-11-24 22:24:01 +0800 | [diff] [blame] | 146 | err = PTR_ERR(tlv320aic23_mclk); |
| 147 | goto err2; |
Arun KS | 17f9ecf | 2008-10-02 15:02:45 +0530 | [diff] [blame] | 148 | } |
| 149 | |
Arun KS | 17f9ecf | 2008-10-02 15:02:45 +0530 | [diff] [blame] | 150 | /* |
| 151 | * Configure 12 MHz output on MCLK. |
| 152 | */ |
| 153 | curRate = (uint) clk_get_rate(tlv320aic23_mclk); |
| 154 | if (curRate != CODEC_CLOCK) { |
| 155 | if (clk_set_rate(tlv320aic23_mclk, CODEC_CLOCK)) { |
| 156 | printk(KERN_ERR "Cannot set MCLK for AIC23 CODEC\n"); |
| 157 | err = -ECANCELED; |
Axel Lin | 2543618 | 2010-11-24 22:24:01 +0800 | [diff] [blame] | 158 | goto err3; |
Arun KS | 17f9ecf | 2008-10-02 15:02:45 +0530 | [diff] [blame] | 159 | } |
| 160 | } |
| 161 | |
David Brownell | 5706d50 | 2009-03-11 02:37:25 -0800 | [diff] [blame] | 162 | printk(KERN_INFO "MCLK = %d [%d]\n", |
| 163 | (uint) clk_get_rate(tlv320aic23_mclk), CODEC_CLOCK); |
Arun KS | 17f9ecf | 2008-10-02 15:02:45 +0530 | [diff] [blame] | 164 | |
| 165 | return 0; |
Axel Lin | 2543618 | 2010-11-24 22:24:01 +0800 | [diff] [blame] | 166 | |
| 167 | err3: |
Arun KS | 17f9ecf | 2008-10-02 15:02:45 +0530 | [diff] [blame] | 168 | clk_put(tlv320aic23_mclk); |
Axel Lin | 2543618 | 2010-11-24 22:24:01 +0800 | [diff] [blame] | 169 | err2: |
Arun KS | 17f9ecf | 2008-10-02 15:02:45 +0530 | [diff] [blame] | 170 | platform_device_del(osk_snd_device); |
Axel Lin | 2543618 | 2010-11-24 22:24:01 +0800 | [diff] [blame] | 171 | err1: |
Arun KS | 17f9ecf | 2008-10-02 15:02:45 +0530 | [diff] [blame] | 172 | platform_device_put(osk_snd_device); |
| 173 | |
| 174 | return err; |
| 175 | |
| 176 | } |
| 177 | |
| 178 | static void __exit osk_soc_exit(void) |
| 179 | { |
Axel Lin | 2543618 | 2010-11-24 22:24:01 +0800 | [diff] [blame] | 180 | clk_put(tlv320aic23_mclk); |
Arun KS | 17f9ecf | 2008-10-02 15:02:45 +0530 | [diff] [blame] | 181 | platform_device_unregister(osk_snd_device); |
| 182 | } |
| 183 | |
| 184 | module_init(osk_soc_init); |
| 185 | module_exit(osk_soc_exit); |
| 186 | |
| 187 | MODULE_AUTHOR("Arun KS <arunks@mistralsolutions.com>"); |
| 188 | MODULE_DESCRIPTION("ALSA SoC OSK 5912"); |
| 189 | MODULE_LICENSE("GPL"); |