Enric Balletbò i Serra | b2a2236 | 2009-11-18 15:59:24 +0100 | [diff] [blame] | 1 | /* |
| 2 | * igep0020.c -- SoC audio for IGEP v2 |
| 3 | * |
| 4 | * Based on sound/soc/omap/overo.c by Steve Sakoman |
| 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> |
Enric Balletbò i Serra | b2a2236 | 2009-11-18 15:59:24 +0100 | [diff] [blame] | 25 | #include <sound/core.h> |
| 26 | #include <sound/pcm.h> |
| 27 | #include <sound/soc.h> |
Enric Balletbò i Serra | b2a2236 | 2009-11-18 15:59:24 +0100 | [diff] [blame] | 28 | |
| 29 | #include <asm/mach-types.h> |
| 30 | #include <mach/hardware.h> |
| 31 | #include <mach/gpio.h> |
| 32 | #include <plat/mcbsp.h> |
| 33 | |
| 34 | #include "omap-mcbsp.h" |
| 35 | #include "omap-pcm.h" |
Enric Balletbò i Serra | b2a2236 | 2009-11-18 15:59:24 +0100 | [diff] [blame] | 36 | |
| 37 | static int igep2_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; |
Enric Balletbò i Serra | b2a2236 | 2009-11-18 15:59:24 +0100 | [diff] [blame] | 42 | int ret; |
| 43 | |
Enric Balletbò i Serra | b2a2236 | 2009-11-18 15:59:24 +0100 | [diff] [blame] | 44 | /* Set the codec system clock for DAC and ADC */ |
| 45 | ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000, |
| 46 | SND_SOC_CLOCK_IN); |
| 47 | if (ret < 0) { |
| 48 | printk(KERN_ERR "can't set codec system clock\n"); |
| 49 | return ret; |
| 50 | } |
| 51 | |
| 52 | return 0; |
| 53 | } |
| 54 | |
| 55 | static struct snd_soc_ops igep2_ops = { |
| 56 | .hw_params = igep2_hw_params, |
| 57 | }; |
| 58 | |
| 59 | /* Digital audio interface glue - connects codec <--> CPU */ |
| 60 | static struct snd_soc_dai_link igep2_dai = { |
| 61 | .name = "TWL4030", |
| 62 | .stream_name = "TWL4030", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 63 | .cpu_dai_name = "omap-mcbsp-dai.1", |
| 64 | .codec_dai_name = "twl4030-hifi", |
| 65 | .platform_name = "omap-pcm-audio", |
| 66 | .codec_name = "twl4030-codec", |
Jarkko Nikula | cf9feff | 2011-09-30 16:07:45 +0300 | [diff] [blame] | 67 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | |
| 68 | SND_SOC_DAIFMT_CBM_CFM, |
Enric Balletbò i Serra | b2a2236 | 2009-11-18 15:59:24 +0100 | [diff] [blame] | 69 | .ops = &igep2_ops, |
| 70 | }; |
| 71 | |
| 72 | /* Audio machine driver */ |
| 73 | static struct snd_soc_card snd_soc_card_igep2 = { |
| 74 | .name = "igep2", |
Enric Balletbò i Serra | b2a2236 | 2009-11-18 15:59:24 +0100 | [diff] [blame] | 75 | .dai_link = &igep2_dai, |
| 76 | .num_links = 1, |
| 77 | }; |
| 78 | |
Enric Balletbò i Serra | b2a2236 | 2009-11-18 15:59:24 +0100 | [diff] [blame] | 79 | static struct platform_device *igep2_snd_device; |
| 80 | |
| 81 | static int __init igep2_soc_init(void) |
| 82 | { |
| 83 | int ret; |
| 84 | |
Jarkko Nikula | ec588ae | 2010-10-06 16:47:26 +0300 | [diff] [blame] | 85 | if (!machine_is_igep0020()) |
Enric Balletbò i Serra | b2a2236 | 2009-11-18 15:59:24 +0100 | [diff] [blame] | 86 | return -ENODEV; |
Enric Balletbò i Serra | b2a2236 | 2009-11-18 15:59:24 +0100 | [diff] [blame] | 87 | printk(KERN_INFO "IGEP v2 SoC init\n"); |
| 88 | |
| 89 | igep2_snd_device = platform_device_alloc("soc-audio", -1); |
| 90 | if (!igep2_snd_device) { |
| 91 | printk(KERN_ERR "Platform device allocation failed\n"); |
| 92 | return -ENOMEM; |
| 93 | } |
| 94 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 95 | platform_set_drvdata(igep2_snd_device, &snd_soc_card_igep2); |
Enric Balletbò i Serra | b2a2236 | 2009-11-18 15:59:24 +0100 | [diff] [blame] | 96 | |
| 97 | ret = platform_device_add(igep2_snd_device); |
| 98 | if (ret) |
| 99 | goto err1; |
| 100 | |
| 101 | return 0; |
| 102 | |
| 103 | err1: |
| 104 | printk(KERN_ERR "Unable to add platform device\n"); |
| 105 | platform_device_put(igep2_snd_device); |
| 106 | |
| 107 | return ret; |
| 108 | } |
| 109 | module_init(igep2_soc_init); |
| 110 | |
| 111 | static void __exit igep2_soc_exit(void) |
| 112 | { |
| 113 | platform_device_unregister(igep2_snd_device); |
| 114 | } |
| 115 | module_exit(igep2_soc_exit); |
| 116 | |
| 117 | MODULE_AUTHOR("Enric Balletbo i Serra <eballetbo@iseebcn.com>"); |
| 118 | MODULE_DESCRIPTION("ALSA SoC IGEP v2"); |
| 119 | MODULE_LICENSE("GPL"); |