Steve Sakoman | dc06102 | 2008-10-30 21:55:24 -0700 | [diff] [blame] | 1 | /* |
| 2 | * omap3beagle.c -- SoC audio for OMAP3 Beagle |
| 3 | * |
| 4 | * Author: Steve Sakoman <steve@sakoman.com> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * version 2 as published by the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, but |
| 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA |
| 18 | * 02110-1301 USA |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | #include <linux/clk.h> |
| 23 | #include <linux/platform_device.h> |
Paul Gortmaker | da155d5 | 2011-07-15 12:38:28 -0400 | [diff] [blame] | 24 | #include <linux/module.h> |
Steve Sakoman | dc06102 | 2008-10-30 21:55:24 -0700 | [diff] [blame] | 25 | #include <sound/core.h> |
| 26 | #include <sound/pcm.h> |
| 27 | #include <sound/soc.h> |
Steve Sakoman | dc06102 | 2008-10-30 21:55:24 -0700 | [diff] [blame] | 28 | |
| 29 | #include <asm/mach-types.h> |
| 30 | #include <mach/hardware.h> |
| 31 | #include <mach/gpio.h> |
Tony Lindgren | ce491cf | 2009-10-20 09:40:47 -0700 | [diff] [blame] | 32 | #include <plat/mcbsp.h> |
Steve Sakoman | dc06102 | 2008-10-30 21:55:24 -0700 | [diff] [blame] | 33 | |
| 34 | #include "omap-mcbsp.h" |
| 35 | #include "omap-pcm.h" |
Steve Sakoman | dc06102 | 2008-10-30 21:55:24 -0700 | [diff] [blame] | 36 | |
| 37 | static int omap3beagle_hw_params(struct snd_pcm_substream *substream, |
| 38 | struct snd_pcm_hw_params *params) |
| 39 | { |
| 40 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 41 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 42 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Peter Ujfalusi | a8353a5 | 2009-04-24 11:03:21 +0300 | [diff] [blame] | 43 | unsigned int fmt; |
Steve Sakoman | dc06102 | 2008-10-30 21:55:24 -0700 | [diff] [blame] | 44 | int ret; |
| 45 | |
Peter Ujfalusi | a8353a5 | 2009-04-24 11:03:21 +0300 | [diff] [blame] | 46 | switch (params_channels(params)) { |
| 47 | case 2: /* Stereo I2S mode */ |
| 48 | fmt = SND_SOC_DAIFMT_I2S | |
| 49 | SND_SOC_DAIFMT_NB_NF | |
| 50 | SND_SOC_DAIFMT_CBM_CFM; |
| 51 | break; |
| 52 | case 4: /* Four channel TDM mode */ |
| 53 | fmt = SND_SOC_DAIFMT_DSP_A | |
| 54 | SND_SOC_DAIFMT_IB_NF | |
| 55 | SND_SOC_DAIFMT_CBM_CFM; |
| 56 | break; |
| 57 | default: |
| 58 | return -EINVAL; |
| 59 | } |
| 60 | |
Steve Sakoman | dc06102 | 2008-10-30 21:55:24 -0700 | [diff] [blame] | 61 | /* Set codec DAI configuration */ |
Peter Ujfalusi | a8353a5 | 2009-04-24 11:03:21 +0300 | [diff] [blame] | 62 | ret = snd_soc_dai_set_fmt(codec_dai, fmt); |
Steve Sakoman | dc06102 | 2008-10-30 21:55:24 -0700 | [diff] [blame] | 63 | if (ret < 0) { |
| 64 | printk(KERN_ERR "can't set codec DAI configuration\n"); |
| 65 | return ret; |
| 66 | } |
| 67 | |
| 68 | /* Set cpu DAI configuration */ |
Peter Ujfalusi | a8353a5 | 2009-04-24 11:03:21 +0300 | [diff] [blame] | 69 | ret = snd_soc_dai_set_fmt(cpu_dai, fmt); |
Steve Sakoman | dc06102 | 2008-10-30 21:55:24 -0700 | [diff] [blame] | 70 | if (ret < 0) { |
| 71 | printk(KERN_ERR "can't set cpu DAI configuration\n"); |
| 72 | return ret; |
| 73 | } |
| 74 | |
| 75 | /* Set the codec system clock for DAC and ADC */ |
| 76 | ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000, |
| 77 | SND_SOC_CLOCK_IN); |
| 78 | if (ret < 0) { |
| 79 | printk(KERN_ERR "can't set codec system clock\n"); |
| 80 | return ret; |
| 81 | } |
| 82 | |
| 83 | return 0; |
| 84 | } |
| 85 | |
| 86 | static struct snd_soc_ops omap3beagle_ops = { |
| 87 | .hw_params = omap3beagle_hw_params, |
| 88 | }; |
| 89 | |
| 90 | /* Digital audio interface glue - connects codec <--> CPU */ |
| 91 | static struct snd_soc_dai_link omap3beagle_dai = { |
| 92 | .name = "TWL4030", |
| 93 | .stream_name = "TWL4030", |
Peter Ujfalusi | 45656b4 | 2012-02-14 18:20:58 +0200 | [diff] [blame] | 94 | .cpu_dai_name = "omap-mcbsp.2", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 95 | .platform_name = "omap-pcm-audio", |
| 96 | .codec_dai_name = "twl4030-hifi", |
| 97 | .codec_name = "twl4030-codec", |
Steve Sakoman | dc06102 | 2008-10-30 21:55:24 -0700 | [diff] [blame] | 98 | .ops = &omap3beagle_ops, |
| 99 | }; |
| 100 | |
| 101 | /* Audio machine driver */ |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 102 | static struct snd_soc_card snd_soc_omap3beagle = { |
Steve Sakoman | dc06102 | 2008-10-30 21:55:24 -0700 | [diff] [blame] | 103 | .name = "omap3beagle", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 104 | .owner = THIS_MODULE, |
Steve Sakoman | dc06102 | 2008-10-30 21:55:24 -0700 | [diff] [blame] | 105 | .dai_link = &omap3beagle_dai, |
| 106 | .num_links = 1, |
| 107 | }; |
| 108 | |
Steve Sakoman | dc06102 | 2008-10-30 21:55:24 -0700 | [diff] [blame] | 109 | static struct platform_device *omap3beagle_snd_device; |
| 110 | |
| 111 | static int __init omap3beagle_soc_init(void) |
| 112 | { |
| 113 | int ret; |
| 114 | |
Jarkko Nikula | ec588ae | 2010-10-06 16:47:26 +0300 | [diff] [blame] | 115 | if (!(machine_is_omap3_beagle() || machine_is_devkit8000())) |
Steve Sakoman | dc06102 | 2008-10-30 21:55:24 -0700 | [diff] [blame] | 116 | return -ENODEV; |
Thomas Weber | 867af97 | 2010-02-11 16:13:59 +0100 | [diff] [blame] | 117 | pr_info("OMAP3 Beagle/Devkit8000 SoC init\n"); |
Steve Sakoman | dc06102 | 2008-10-30 21:55:24 -0700 | [diff] [blame] | 118 | |
| 119 | omap3beagle_snd_device = platform_device_alloc("soc-audio", -1); |
| 120 | if (!omap3beagle_snd_device) { |
| 121 | printk(KERN_ERR "Platform device allocation failed\n"); |
| 122 | return -ENOMEM; |
| 123 | } |
| 124 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 125 | platform_set_drvdata(omap3beagle_snd_device, &snd_soc_omap3beagle); |
Steve Sakoman | dc06102 | 2008-10-30 21:55:24 -0700 | [diff] [blame] | 126 | |
| 127 | ret = platform_device_add(omap3beagle_snd_device); |
| 128 | if (ret) |
| 129 | goto err1; |
| 130 | |
| 131 | return 0; |
| 132 | |
| 133 | err1: |
| 134 | printk(KERN_ERR "Unable to add platform device\n"); |
| 135 | platform_device_put(omap3beagle_snd_device); |
| 136 | |
| 137 | return ret; |
| 138 | } |
| 139 | |
| 140 | static void __exit omap3beagle_soc_exit(void) |
| 141 | { |
| 142 | platform_device_unregister(omap3beagle_snd_device); |
| 143 | } |
| 144 | |
| 145 | module_init(omap3beagle_soc_init); |
| 146 | module_exit(omap3beagle_soc_exit); |
| 147 | |
| 148 | MODULE_AUTHOR("Steve Sakoman <steve@sakoman.com>"); |
| 149 | MODULE_DESCRIPTION("ALSA SoC OMAP3 Beagle"); |
| 150 | MODULE_LICENSE("GPL"); |