Ryan Mallon | 315f7da | 2010-06-08 22:01:12 +1200 | [diff] [blame^] | 1 | /* |
| 2 | * snappercl15.c -- SoC audio for Bluewater Systems Snapper CL15 module |
| 3 | * |
| 4 | * Copyright (C) 2008 Bluewater Systems Ltd |
| 5 | * Author: Ryan Mallon <ryan@bluewatersys.com> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify it |
| 8 | * under the terms of the GNU General Public License as published by the |
| 9 | * Free Software Foundation; either version 2 of the License, or (at your |
| 10 | * option) any later version. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | #include <linux/platform_device.h> |
| 15 | #include <sound/core.h> |
| 16 | #include <sound/pcm.h> |
| 17 | #include <sound/soc.h> |
| 18 | #include <sound/soc-dapm.h> |
| 19 | |
| 20 | #include <asm/mach-types.h> |
| 21 | #include <mach/hardware.h> |
| 22 | |
| 23 | #include "../codecs/tlv320aic23.h" |
| 24 | #include "ep93xx-pcm.h" |
| 25 | #include "ep93xx-i2s.h" |
| 26 | |
| 27 | #define CODEC_CLOCK 5644800 |
| 28 | |
| 29 | static int snappercl15_hw_params(struct snd_pcm_substream *substream, |
| 30 | struct snd_pcm_hw_params *params) |
| 31 | { |
| 32 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 33 | struct snd_soc_dai *codec_dai = rtd->dai->codec_dai; |
| 34 | struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai; |
| 35 | int err; |
| 36 | |
| 37 | err = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S | |
| 38 | SND_SOC_DAIFMT_NB_IF | |
| 39 | SND_SOC_DAIFMT_CBS_CFS); |
| 40 | |
| 41 | err = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S | |
| 42 | SND_SOC_DAIFMT_NB_IF | |
| 43 | SND_SOC_DAIFMT_CBS_CFS); |
| 44 | if (err) |
| 45 | return err; |
| 46 | |
| 47 | err = snd_soc_dai_set_sysclk(codec_dai, 0, CODEC_CLOCK, |
| 48 | SND_SOC_CLOCK_IN); |
| 49 | if (err) |
| 50 | return err; |
| 51 | |
| 52 | err = snd_soc_dai_set_sysclk(cpu_dai, 0, CODEC_CLOCK, |
| 53 | SND_SOC_CLOCK_OUT); |
| 54 | if (err) |
| 55 | return err; |
| 56 | |
| 57 | return 0; |
| 58 | } |
| 59 | |
| 60 | static struct snd_soc_ops snappercl15_ops = { |
| 61 | .hw_params = snappercl15_hw_params, |
| 62 | }; |
| 63 | |
| 64 | static const struct snd_soc_dapm_widget tlv320aic23_dapm_widgets[] = { |
| 65 | SND_SOC_DAPM_HP("Headphone Jack", NULL), |
| 66 | SND_SOC_DAPM_LINE("Line In", NULL), |
| 67 | SND_SOC_DAPM_MIC("Mic Jack", NULL), |
| 68 | }; |
| 69 | |
| 70 | static const struct snd_soc_dapm_route audio_map[] = { |
| 71 | {"Headphone Jack", NULL, "LHPOUT"}, |
| 72 | {"Headphone Jack", NULL, "RHPOUT"}, |
| 73 | |
| 74 | {"LLINEIN", NULL, "Line In"}, |
| 75 | {"RLINEIN", NULL, "Line In"}, |
| 76 | |
| 77 | {"MICIN", NULL, "Mic Jack"}, |
| 78 | }; |
| 79 | |
| 80 | static int snappercl15_tlv320aic23_init(struct snd_soc_codec *codec) |
| 81 | { |
| 82 | snd_soc_dapm_new_controls(codec, tlv320aic23_dapm_widgets, |
| 83 | ARRAY_SIZE(tlv320aic23_dapm_widgets)); |
| 84 | |
| 85 | snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); |
| 86 | return 0; |
| 87 | } |
| 88 | |
| 89 | static struct snd_soc_dai_link snappercl15_dai = { |
| 90 | .name = "tlv320aic23", |
| 91 | .stream_name = "AIC23", |
| 92 | .cpu_dai = &ep93xx_i2s_dai, |
| 93 | .codec_dai = &tlv320aic23_dai, |
| 94 | .init = snappercl15_tlv320aic23_init, |
| 95 | .ops = &snappercl15_ops, |
| 96 | }; |
| 97 | |
| 98 | static struct snd_soc_card snd_soc_snappercl15 = { |
| 99 | .name = "Snapper CL15", |
| 100 | .platform = &ep93xx_soc_platform, |
| 101 | .dai_link = &snappercl15_dai, |
| 102 | .num_links = 1, |
| 103 | }; |
| 104 | |
| 105 | static struct snd_soc_device snappercl15_snd_devdata = { |
| 106 | .card = &snd_soc_snappercl15, |
| 107 | .codec_dev = &soc_codec_dev_tlv320aic23, |
| 108 | }; |
| 109 | |
| 110 | static struct platform_device *snappercl15_snd_device; |
| 111 | |
| 112 | static int __init snappercl15_init(void) |
| 113 | { |
| 114 | int ret; |
| 115 | |
| 116 | if (!machine_is_snapper_cl15()) |
| 117 | return -ENODEV; |
| 118 | |
| 119 | ret = ep93xx_i2s_acquire(EP93XX_SYSCON_DEVCFG_I2SONAC97, |
| 120 | EP93XX_SYSCON_I2SCLKDIV_ORIDE | |
| 121 | EP93XX_SYSCON_I2SCLKDIV_SPOL); |
| 122 | if (ret) |
| 123 | return ret; |
| 124 | |
| 125 | snappercl15_snd_device = platform_device_alloc("soc-audio", -1); |
| 126 | if (!snappercl15_snd_device) |
| 127 | return -ENOMEM; |
| 128 | |
| 129 | platform_set_drvdata(snappercl15_snd_device, &snappercl15_snd_devdata); |
| 130 | snappercl15_snd_devdata.dev = &snappercl15_snd_device->dev; |
| 131 | ret = platform_device_add(snappercl15_snd_device); |
| 132 | if (ret) |
| 133 | platform_device_put(snappercl15_snd_device); |
| 134 | |
| 135 | return ret; |
| 136 | } |
| 137 | |
| 138 | static void __exit snappercl15_exit(void) |
| 139 | { |
| 140 | platform_device_unregister(snappercl15_snd_device); |
| 141 | ep93xx_i2s_release(); |
| 142 | } |
| 143 | |
| 144 | module_init(snappercl15_init); |
| 145 | module_exit(snappercl15_exit); |
| 146 | |
| 147 | MODULE_AUTHOR("Ryan Mallon <ryan@bluewatersys.com>"); |
| 148 | MODULE_DESCRIPTION("ALSA SoC Snapper CL15"); |
| 149 | MODULE_LICENSE("GPL"); |
| 150 | |