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> |
| 24 | #include <sound/core.h> |
| 25 | #include <sound/pcm.h> |
| 26 | #include <sound/soc.h> |
Steve Sakoman | dc06102 | 2008-10-30 21:55:24 -0700 | [diff] [blame] | 27 | |
| 28 | #include <asm/mach-types.h> |
| 29 | #include <mach/hardware.h> |
| 30 | #include <mach/gpio.h> |
Tony Lindgren | ce491cf | 2009-10-20 09:40:47 -0700 | [diff] [blame] | 31 | #include <plat/mcbsp.h> |
Steve Sakoman | dc06102 | 2008-10-30 21:55:24 -0700 | [diff] [blame] | 32 | |
| 33 | #include "omap-mcbsp.h" |
| 34 | #include "omap-pcm.h" |
Steve Sakoman | dc06102 | 2008-10-30 21:55:24 -0700 | [diff] [blame] | 35 | |
| 36 | static int omap3beagle_hw_params(struct snd_pcm_substream *substream, |
| 37 | struct snd_pcm_hw_params *params) |
| 38 | { |
| 39 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 40 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 41 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Peter Ujfalusi | a8353a5 | 2009-04-24 11:03:21 +0300 | [diff] [blame] | 42 | unsigned int fmt; |
Steve Sakoman | dc06102 | 2008-10-30 21:55:24 -0700 | [diff] [blame] | 43 | int ret; |
| 44 | |
Peter Ujfalusi | a8353a5 | 2009-04-24 11:03:21 +0300 | [diff] [blame] | 45 | switch (params_channels(params)) { |
| 46 | case 2: /* Stereo I2S mode */ |
| 47 | fmt = SND_SOC_DAIFMT_I2S | |
| 48 | SND_SOC_DAIFMT_NB_NF | |
| 49 | SND_SOC_DAIFMT_CBM_CFM; |
| 50 | break; |
| 51 | case 4: /* Four channel TDM mode */ |
| 52 | fmt = SND_SOC_DAIFMT_DSP_A | |
| 53 | SND_SOC_DAIFMT_IB_NF | |
| 54 | SND_SOC_DAIFMT_CBM_CFM; |
| 55 | break; |
| 56 | default: |
| 57 | return -EINVAL; |
| 58 | } |
| 59 | |
Steve Sakoman | dc06102 | 2008-10-30 21:55:24 -0700 | [diff] [blame] | 60 | /* Set codec DAI configuration */ |
Peter Ujfalusi | a8353a5 | 2009-04-24 11:03:21 +0300 | [diff] [blame] | 61 | ret = snd_soc_dai_set_fmt(codec_dai, fmt); |
Steve Sakoman | dc06102 | 2008-10-30 21:55:24 -0700 | [diff] [blame] | 62 | if (ret < 0) { |
| 63 | printk(KERN_ERR "can't set codec DAI configuration\n"); |
| 64 | return ret; |
| 65 | } |
| 66 | |
| 67 | /* Set cpu DAI configuration */ |
Peter Ujfalusi | a8353a5 | 2009-04-24 11:03:21 +0300 | [diff] [blame] | 68 | ret = snd_soc_dai_set_fmt(cpu_dai, fmt); |
Steve Sakoman | dc06102 | 2008-10-30 21:55:24 -0700 | [diff] [blame] | 69 | if (ret < 0) { |
| 70 | printk(KERN_ERR "can't set cpu DAI configuration\n"); |
| 71 | return ret; |
| 72 | } |
| 73 | |
| 74 | /* Set the codec system clock for DAC and ADC */ |
| 75 | ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000, |
| 76 | SND_SOC_CLOCK_IN); |
| 77 | if (ret < 0) { |
| 78 | printk(KERN_ERR "can't set codec system clock\n"); |
| 79 | return ret; |
| 80 | } |
| 81 | |
| 82 | return 0; |
| 83 | } |
| 84 | |
| 85 | static struct snd_soc_ops omap3beagle_ops = { |
| 86 | .hw_params = omap3beagle_hw_params, |
| 87 | }; |
| 88 | |
| 89 | /* Digital audio interface glue - connects codec <--> CPU */ |
| 90 | static struct snd_soc_dai_link omap3beagle_dai = { |
| 91 | .name = "TWL4030", |
| 92 | .stream_name = "TWL4030", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 93 | .cpu_dai_name = "omap-mcbsp-dai.1", |
| 94 | .platform_name = "omap-pcm-audio", |
| 95 | .codec_dai_name = "twl4030-hifi", |
| 96 | .codec_name = "twl4030-codec", |
Steve Sakoman | dc06102 | 2008-10-30 21:55:24 -0700 | [diff] [blame] | 97 | .ops = &omap3beagle_ops, |
| 98 | }; |
| 99 | |
| 100 | /* Audio machine driver */ |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 101 | static struct snd_soc_card snd_soc_omap3beagle = { |
Steve Sakoman | dc06102 | 2008-10-30 21:55:24 -0700 | [diff] [blame] | 102 | .name = "omap3beagle", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 103 | .owner = THIS_MODULE, |
Steve Sakoman | dc06102 | 2008-10-30 21:55:24 -0700 | [diff] [blame] | 104 | .dai_link = &omap3beagle_dai, |
| 105 | .num_links = 1, |
| 106 | }; |
| 107 | |
Steve Sakoman | dc06102 | 2008-10-30 21:55:24 -0700 | [diff] [blame] | 108 | static struct platform_device *omap3beagle_snd_device; |
| 109 | |
| 110 | static int __init omap3beagle_soc_init(void) |
| 111 | { |
| 112 | int ret; |
| 113 | |
Jarkko Nikula | ec588ae | 2010-10-06 16:47:26 +0300 | [diff] [blame] | 114 | if (!(machine_is_omap3_beagle() || machine_is_devkit8000())) |
Steve Sakoman | dc06102 | 2008-10-30 21:55:24 -0700 | [diff] [blame] | 115 | return -ENODEV; |
Thomas Weber | 867af97 | 2010-02-11 16:13:59 +0100 | [diff] [blame] | 116 | pr_info("OMAP3 Beagle/Devkit8000 SoC init\n"); |
Steve Sakoman | dc06102 | 2008-10-30 21:55:24 -0700 | [diff] [blame] | 117 | |
| 118 | omap3beagle_snd_device = platform_device_alloc("soc-audio", -1); |
| 119 | if (!omap3beagle_snd_device) { |
| 120 | printk(KERN_ERR "Platform device allocation failed\n"); |
| 121 | return -ENOMEM; |
| 122 | } |
| 123 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 124 | platform_set_drvdata(omap3beagle_snd_device, &snd_soc_omap3beagle); |
Steve Sakoman | dc06102 | 2008-10-30 21:55:24 -0700 | [diff] [blame] | 125 | |
| 126 | ret = platform_device_add(omap3beagle_snd_device); |
| 127 | if (ret) |
| 128 | goto err1; |
| 129 | |
| 130 | return 0; |
| 131 | |
| 132 | err1: |
| 133 | printk(KERN_ERR "Unable to add platform device\n"); |
| 134 | platform_device_put(omap3beagle_snd_device); |
| 135 | |
| 136 | return ret; |
| 137 | } |
| 138 | |
| 139 | static void __exit omap3beagle_soc_exit(void) |
| 140 | { |
| 141 | platform_device_unregister(omap3beagle_snd_device); |
| 142 | } |
| 143 | |
| 144 | module_init(omap3beagle_soc_init); |
| 145 | module_exit(omap3beagle_soc_exit); |
| 146 | |
| 147 | MODULE_AUTHOR("Steve Sakoman <steve@sakoman.com>"); |
| 148 | MODULE_DESCRIPTION("ALSA SoC OMAP3 Beagle"); |
| 149 | MODULE_LICENSE("GPL"); |