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> |
| 27 | #include <sound/soc-dapm.h> |
| 28 | |
| 29 | #include <asm/mach-types.h> |
| 30 | #include <mach/hardware.h> |
| 31 | #include <mach/gpio.h> |
| 32 | #include <mach/mcbsp.h> |
| 33 | |
| 34 | #include "omap-mcbsp.h" |
| 35 | #include "omap-pcm.h" |
| 36 | #include "../codecs/twl4030.h" |
| 37 | |
| 38 | static int omap3beagle_hw_params(struct snd_pcm_substream *substream, |
| 39 | struct snd_pcm_hw_params *params) |
| 40 | { |
| 41 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 42 | struct snd_soc_dai *codec_dai = rtd->dai->codec_dai; |
| 43 | struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai; |
| 44 | int ret; |
| 45 | |
| 46 | /* Set codec DAI configuration */ |
| 47 | ret = snd_soc_dai_set_fmt(codec_dai, |
| 48 | SND_SOC_DAIFMT_I2S | |
| 49 | SND_SOC_DAIFMT_NB_NF | |
| 50 | SND_SOC_DAIFMT_CBM_CFM); |
| 51 | if (ret < 0) { |
| 52 | printk(KERN_ERR "can't set codec DAI configuration\n"); |
| 53 | return ret; |
| 54 | } |
| 55 | |
| 56 | /* Set cpu DAI configuration */ |
| 57 | ret = snd_soc_dai_set_fmt(cpu_dai, |
| 58 | SND_SOC_DAIFMT_I2S | |
| 59 | SND_SOC_DAIFMT_NB_NF | |
| 60 | SND_SOC_DAIFMT_CBM_CFM); |
| 61 | if (ret < 0) { |
| 62 | printk(KERN_ERR "can't set cpu DAI configuration\n"); |
| 63 | return ret; |
| 64 | } |
| 65 | |
| 66 | /* Set the codec system clock for DAC and ADC */ |
| 67 | ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000, |
| 68 | SND_SOC_CLOCK_IN); |
| 69 | if (ret < 0) { |
| 70 | printk(KERN_ERR "can't set codec system clock\n"); |
| 71 | return ret; |
| 72 | } |
| 73 | |
| 74 | return 0; |
| 75 | } |
| 76 | |
| 77 | static struct snd_soc_ops omap3beagle_ops = { |
| 78 | .hw_params = omap3beagle_hw_params, |
| 79 | }; |
| 80 | |
| 81 | /* Digital audio interface glue - connects codec <--> CPU */ |
| 82 | static struct snd_soc_dai_link omap3beagle_dai = { |
| 83 | .name = "TWL4030", |
| 84 | .stream_name = "TWL4030", |
| 85 | .cpu_dai = &omap_mcbsp_dai[0], |
| 86 | .codec_dai = &twl4030_dai, |
| 87 | .ops = &omap3beagle_ops, |
| 88 | }; |
| 89 | |
| 90 | /* Audio machine driver */ |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 91 | static struct snd_soc_card snd_soc_omap3beagle = { |
Steve Sakoman | dc06102 | 2008-10-30 21:55:24 -0700 | [diff] [blame] | 92 | .name = "omap3beagle", |
| 93 | .dai_link = &omap3beagle_dai, |
| 94 | .num_links = 1, |
| 95 | }; |
| 96 | |
| 97 | /* Audio subsystem */ |
| 98 | static struct snd_soc_device omap3beagle_snd_devdata = { |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 99 | .card = &snd_soc_omap3beagle, |
Steve Sakoman | dc06102 | 2008-10-30 21:55:24 -0700 | [diff] [blame] | 100 | .platform = &omap_soc_platform, |
| 101 | .codec_dev = &soc_codec_dev_twl4030, |
| 102 | }; |
| 103 | |
| 104 | static struct platform_device *omap3beagle_snd_device; |
| 105 | |
| 106 | static int __init omap3beagle_soc_init(void) |
| 107 | { |
| 108 | int ret; |
| 109 | |
| 110 | if (!machine_is_omap3_beagle()) { |
| 111 | pr_debug("Not OMAP3 Beagle!\n"); |
| 112 | return -ENODEV; |
| 113 | } |
| 114 | pr_info("OMAP3 Beagle SoC init\n"); |
| 115 | |
| 116 | omap3beagle_snd_device = platform_device_alloc("soc-audio", -1); |
| 117 | if (!omap3beagle_snd_device) { |
| 118 | printk(KERN_ERR "Platform device allocation failed\n"); |
| 119 | return -ENOMEM; |
| 120 | } |
| 121 | |
| 122 | platform_set_drvdata(omap3beagle_snd_device, &omap3beagle_snd_devdata); |
| 123 | omap3beagle_snd_devdata.dev = &omap3beagle_snd_device->dev; |
| 124 | *(unsigned int *)omap3beagle_dai.cpu_dai->private_data = 1; /* McBSP2 */ |
| 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"); |