| Anuj Aggarwal | 14610ce | 2009-05-14 13:59:19 +0530 | [diff] [blame] | 1 | /* | 
|  | 2 | * omap3evm.c  -- ALSA SoC support for OMAP3 EVM | 
|  | 3 | * | 
|  | 4 | * Author: Anuj Aggarwal <anuj.aggarwal@ti.com> | 
|  | 5 | * | 
|  | 6 | * Based on sound/soc/omap/beagle.c by Steve Sakoman | 
|  | 7 | * | 
|  | 8 | * Copyright (C) 2008 Texas Instruments, Incorporated | 
|  | 9 | * | 
|  | 10 | * This program is free software; you can redistribute it and/or modify it | 
|  | 11 | * under the terms of the GNU General Public License as published by the | 
|  | 12 | * Free Software Foundation version 2. | 
|  | 13 | * | 
|  | 14 | * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind, | 
|  | 15 | * whether express or implied; without even the implied warranty of | 
|  | 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 
|  | 17 | * General Public License for more details. | 
|  | 18 | */ | 
|  | 19 |  | 
|  | 20 | #include <linux/clk.h> | 
|  | 21 | #include <linux/platform_device.h> | 
|  | 22 | #include <sound/core.h> | 
|  | 23 | #include <sound/pcm.h> | 
|  | 24 | #include <sound/soc.h> | 
| Anuj Aggarwal | 14610ce | 2009-05-14 13:59:19 +0530 | [diff] [blame] | 25 |  | 
|  | 26 | #include <asm/mach-types.h> | 
|  | 27 | #include <mach/hardware.h> | 
|  | 28 | #include <mach/gpio.h> | 
| Tony Lindgren | ce491cf | 2009-10-20 09:40:47 -0700 | [diff] [blame] | 29 | #include <plat/mcbsp.h> | 
| Anuj Aggarwal | 14610ce | 2009-05-14 13:59:19 +0530 | [diff] [blame] | 30 |  | 
|  | 31 | #include "omap-mcbsp.h" | 
|  | 32 | #include "omap-pcm.h" | 
| Anuj Aggarwal | 14610ce | 2009-05-14 13:59:19 +0530 | [diff] [blame] | 33 |  | 
|  | 34 | static int omap3evm_hw_params(struct snd_pcm_substream *substream, | 
|  | 35 | struct snd_pcm_hw_params *params) | 
|  | 36 | { | 
|  | 37 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 
| Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 38 | struct snd_soc_dai *codec_dai = rtd->codec_dai; | 
|  | 39 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; | 
| Anuj Aggarwal | 14610ce | 2009-05-14 13:59:19 +0530 | [diff] [blame] | 40 | int ret; | 
|  | 41 |  | 
|  | 42 | /* Set codec DAI configuration */ | 
|  | 43 | ret = snd_soc_dai_set_fmt(codec_dai, | 
|  | 44 | SND_SOC_DAIFMT_I2S | | 
|  | 45 | SND_SOC_DAIFMT_NB_NF | | 
|  | 46 | SND_SOC_DAIFMT_CBM_CFM); | 
|  | 47 | if (ret < 0) { | 
|  | 48 | printk(KERN_ERR "Can't set codec DAI configuration\n"); | 
|  | 49 | return ret; | 
|  | 50 | } | 
|  | 51 |  | 
|  | 52 | /* Set cpu DAI configuration */ | 
|  | 53 | ret = snd_soc_dai_set_fmt(cpu_dai, | 
|  | 54 | SND_SOC_DAIFMT_I2S | | 
|  | 55 | SND_SOC_DAIFMT_NB_NF | | 
|  | 56 | SND_SOC_DAIFMT_CBM_CFM); | 
|  | 57 | if (ret < 0) { | 
|  | 58 | printk(KERN_ERR "Can't set cpu DAI configuration\n"); | 
|  | 59 | return ret; | 
|  | 60 | } | 
|  | 61 |  | 
|  | 62 | /* Set the codec system clock for DAC and ADC */ | 
|  | 63 | ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000, | 
|  | 64 | SND_SOC_CLOCK_IN); | 
|  | 65 | if (ret < 0) { | 
|  | 66 | printk(KERN_ERR "Can't set codec system clock\n"); | 
|  | 67 | return ret; | 
|  | 68 | } | 
|  | 69 |  | 
|  | 70 | return 0; | 
|  | 71 | } | 
|  | 72 |  | 
|  | 73 | static struct snd_soc_ops omap3evm_ops = { | 
|  | 74 | .hw_params = omap3evm_hw_params, | 
|  | 75 | }; | 
|  | 76 |  | 
|  | 77 | /* Digital audio interface glue - connects codec <--> CPU */ | 
|  | 78 | static struct snd_soc_dai_link omap3evm_dai = { | 
|  | 79 | .name 		= "TWL4030", | 
|  | 80 | .stream_name 	= "TWL4030", | 
| Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 81 | .cpu_dai_name = "omap-mcbsp-dai.1", | 
|  | 82 | .codec_dai_name = "twl4030-hifi", | 
|  | 83 | .platform_name = "omap-pcm-audio", | 
|  | 84 | .codec_name = "twl4030-codec", | 
| Anuj Aggarwal | 14610ce | 2009-05-14 13:59:19 +0530 | [diff] [blame] | 85 | .ops 		= &omap3evm_ops, | 
|  | 86 | }; | 
|  | 87 |  | 
|  | 88 | /* Audio machine driver */ | 
|  | 89 | static struct snd_soc_card snd_soc_omap3evm = { | 
|  | 90 | .name = "omap3evm", | 
| Anuj Aggarwal | 14610ce | 2009-05-14 13:59:19 +0530 | [diff] [blame] | 91 | .dai_link = &omap3evm_dai, | 
|  | 92 | .num_links = 1, | 
|  | 93 | }; | 
|  | 94 |  | 
| Anuj Aggarwal | 14610ce | 2009-05-14 13:59:19 +0530 | [diff] [blame] | 95 | static struct platform_device *omap3evm_snd_device; | 
|  | 96 |  | 
|  | 97 | static int __init omap3evm_soc_init(void) | 
|  | 98 | { | 
|  | 99 | int ret; | 
|  | 100 |  | 
| Jarkko Nikula | ec588ae | 2010-10-06 16:47:26 +0300 | [diff] [blame] | 101 | if (!machine_is_omap3evm()) | 
| Anuj Aggarwal | 14610ce | 2009-05-14 13:59:19 +0530 | [diff] [blame] | 102 | return -ENODEV; | 
| Anuj Aggarwal | 14610ce | 2009-05-14 13:59:19 +0530 | [diff] [blame] | 103 | pr_info("OMAP3 EVM SoC init\n"); | 
|  | 104 |  | 
|  | 105 | omap3evm_snd_device = platform_device_alloc("soc-audio", -1); | 
|  | 106 | if (!omap3evm_snd_device) { | 
|  | 107 | printk(KERN_ERR "Platform device allocation failed\n"); | 
|  | 108 | return -ENOMEM; | 
|  | 109 | } | 
|  | 110 |  | 
| Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 111 | platform_set_drvdata(omap3evm_snd_device, &snd_soc_omap3evm); | 
| Anuj Aggarwal | 14610ce | 2009-05-14 13:59:19 +0530 | [diff] [blame] | 112 | ret = platform_device_add(omap3evm_snd_device); | 
|  | 113 | if (ret) | 
|  | 114 | goto err1; | 
|  | 115 |  | 
|  | 116 | return 0; | 
|  | 117 |  | 
|  | 118 | err1: | 
|  | 119 | printk(KERN_ERR "Unable to add platform device\n"); | 
|  | 120 | platform_device_put(omap3evm_snd_device); | 
|  | 121 |  | 
|  | 122 | return ret; | 
|  | 123 | } | 
|  | 124 |  | 
|  | 125 | static void __exit omap3evm_soc_exit(void) | 
|  | 126 | { | 
|  | 127 | platform_device_unregister(omap3evm_snd_device); | 
|  | 128 | } | 
|  | 129 |  | 
|  | 130 | module_init(omap3evm_soc_init); | 
|  | 131 | module_exit(omap3evm_soc_exit); | 
|  | 132 |  | 
|  | 133 | MODULE_AUTHOR("Anuj Aggarwal <anuj.aggarwal@ti.com>"); | 
|  | 134 | MODULE_DESCRIPTION("ALSA SoC OMAP3 EVM"); | 
| Anuj Aggarwal | bd6ddcb | 2009-11-17 21:43:42 +0530 | [diff] [blame] | 135 | MODULE_LICENSE("GPL v2"); |