Steve Sakoman | 4e20787 | 2008-10-30 21:50:13 -0700 | [diff] [blame] | 1 | /* |
| 2 | * overo.c -- SoC audio for Gumstix Overo |
| 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> |
Tony Lindgren | ce491cf | 2009-10-20 09:40:47 -0700 | [diff] [blame] | 32 | #include <plat/mcbsp.h> |
Steve Sakoman | 4e20787 | 2008-10-30 21:50:13 -0700 | [diff] [blame] | 33 | |
| 34 | #include "omap-mcbsp.h" |
| 35 | #include "omap-pcm.h" |
Steve Sakoman | 4e20787 | 2008-10-30 21:50:13 -0700 | [diff] [blame] | 36 | |
| 37 | static int overo_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; |
Steve Sakoman | 4e20787 | 2008-10-30 21:50:13 -0700 | [diff] [blame] | 43 | int ret; |
| 44 | |
| 45 | /* Set codec DAI configuration */ |
| 46 | ret = snd_soc_dai_set_fmt(codec_dai, |
| 47 | SND_SOC_DAIFMT_I2S | |
| 48 | SND_SOC_DAIFMT_NB_NF | |
| 49 | SND_SOC_DAIFMT_CBM_CFM); |
| 50 | if (ret < 0) { |
| 51 | printk(KERN_ERR "can't set codec DAI configuration\n"); |
| 52 | return ret; |
| 53 | } |
| 54 | |
| 55 | /* Set cpu DAI configuration */ |
| 56 | ret = snd_soc_dai_set_fmt(cpu_dai, |
| 57 | SND_SOC_DAIFMT_I2S | |
| 58 | SND_SOC_DAIFMT_NB_NF | |
| 59 | SND_SOC_DAIFMT_CBM_CFM); |
| 60 | if (ret < 0) { |
| 61 | printk(KERN_ERR "can't set cpu DAI configuration\n"); |
| 62 | return ret; |
| 63 | } |
| 64 | |
| 65 | /* Set the codec system clock for DAC and ADC */ |
| 66 | ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000, |
| 67 | SND_SOC_CLOCK_IN); |
| 68 | if (ret < 0) { |
| 69 | printk(KERN_ERR "can't set codec system clock\n"); |
| 70 | return ret; |
| 71 | } |
| 72 | |
| 73 | return 0; |
| 74 | } |
| 75 | |
| 76 | static struct snd_soc_ops overo_ops = { |
| 77 | .hw_params = overo_hw_params, |
| 78 | }; |
| 79 | |
| 80 | /* Digital audio interface glue - connects codec <--> CPU */ |
| 81 | static struct snd_soc_dai_link overo_dai = { |
| 82 | .name = "TWL4030", |
| 83 | .stream_name = "TWL4030", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 84 | .cpu_dai_name = "omap-mcbsp-dai.1", |
| 85 | .codec_dai_name = "twl4030-hifi", |
| 86 | .platform_name = "omap-pcm-audio", |
| 87 | .codec_name = "twl4030-codec", |
Steve Sakoman | 4e20787 | 2008-10-30 21:50:13 -0700 | [diff] [blame] | 88 | .ops = &overo_ops, |
| 89 | }; |
| 90 | |
| 91 | /* Audio machine driver */ |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 92 | static struct snd_soc_card snd_soc_card_overo = { |
Steve Sakoman | 4e20787 | 2008-10-30 21:50:13 -0700 | [diff] [blame] | 93 | .name = "overo", |
| 94 | .dai_link = &overo_dai, |
| 95 | .num_links = 1, |
| 96 | }; |
| 97 | |
Steve Sakoman | 4e20787 | 2008-10-30 21:50:13 -0700 | [diff] [blame] | 98 | static struct platform_device *overo_snd_device; |
| 99 | |
| 100 | static int __init overo_soc_init(void) |
| 101 | { |
| 102 | int ret; |
| 103 | |
Mike Rapoport | 8df89bc | 2009-11-16 16:19:25 +0200 | [diff] [blame] | 104 | if (!(machine_is_overo() || machine_is_cm_t35())) { |
| 105 | pr_debug("Incomatible machine!\n"); |
Steve Sakoman | 4e20787 | 2008-10-30 21:50:13 -0700 | [diff] [blame] | 106 | return -ENODEV; |
| 107 | } |
| 108 | printk(KERN_INFO "overo SoC init\n"); |
| 109 | |
| 110 | overo_snd_device = platform_device_alloc("soc-audio", -1); |
| 111 | if (!overo_snd_device) { |
| 112 | printk(KERN_ERR "Platform device allocation failed\n"); |
| 113 | return -ENOMEM; |
| 114 | } |
| 115 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 116 | platform_set_drvdata(overo_snd_device, &snd_soc_card_overo); |
Steve Sakoman | 4e20787 | 2008-10-30 21:50:13 -0700 | [diff] [blame] | 117 | |
| 118 | ret = platform_device_add(overo_snd_device); |
| 119 | if (ret) |
| 120 | goto err1; |
| 121 | |
| 122 | return 0; |
| 123 | |
| 124 | err1: |
| 125 | printk(KERN_ERR "Unable to add platform device\n"); |
| 126 | platform_device_put(overo_snd_device); |
| 127 | |
| 128 | return ret; |
| 129 | } |
| 130 | module_init(overo_soc_init); |
| 131 | |
| 132 | static void __exit overo_soc_exit(void) |
| 133 | { |
| 134 | platform_device_unregister(overo_snd_device); |
| 135 | } |
| 136 | module_exit(overo_soc_exit); |
| 137 | |
| 138 | MODULE_AUTHOR("Steve Sakoman <steve@sakoman.com>"); |
| 139 | MODULE_DESCRIPTION("ALSA SoC overo"); |
| 140 | MODULE_LICENSE("GPL"); |