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 |
Ryan Mallon | 1c5454e | 2011-06-15 14:45:36 +1000 | [diff] [blame] | 5 | * Author: Ryan Mallon |
Ryan Mallon | 315f7da | 2010-06-08 22:01:12 +1200 | [diff] [blame] | 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> |
Paul Gortmaker | da155d5 | 2011-07-15 12:38:28 -0400 | [diff] [blame^] | 15 | #include <linux/module.h> |
Ryan Mallon | 315f7da | 2010-06-08 22:01:12 +1200 | [diff] [blame] | 16 | #include <sound/core.h> |
| 17 | #include <sound/pcm.h> |
| 18 | #include <sound/soc.h> |
Ryan Mallon | 315f7da | 2010-06-08 22:01:12 +1200 | [diff] [blame] | 19 | |
| 20 | #include <asm/mach-types.h> |
| 21 | #include <mach/hardware.h> |
| 22 | |
| 23 | #include "../codecs/tlv320aic23.h" |
| 24 | #include "ep93xx-pcm.h" |
Ryan Mallon | 315f7da | 2010-06-08 22:01:12 +1200 | [diff] [blame] | 25 | |
| 26 | #define CODEC_CLOCK 5644800 |
| 27 | |
| 28 | static int snappercl15_hw_params(struct snd_pcm_substream *substream, |
| 29 | struct snd_pcm_hw_params *params) |
| 30 | { |
| 31 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 32 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 33 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Ryan Mallon | 315f7da | 2010-06-08 22:01:12 +1200 | [diff] [blame] | 34 | int err; |
| 35 | |
| 36 | err = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S | |
| 37 | SND_SOC_DAIFMT_NB_IF | |
| 38 | SND_SOC_DAIFMT_CBS_CFS); |
| 39 | |
| 40 | err = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S | |
| 41 | SND_SOC_DAIFMT_NB_IF | |
| 42 | SND_SOC_DAIFMT_CBS_CFS); |
| 43 | if (err) |
| 44 | return err; |
| 45 | |
| 46 | err = snd_soc_dai_set_sysclk(codec_dai, 0, CODEC_CLOCK, |
| 47 | SND_SOC_CLOCK_IN); |
| 48 | if (err) |
| 49 | return err; |
| 50 | |
| 51 | err = snd_soc_dai_set_sysclk(cpu_dai, 0, CODEC_CLOCK, |
| 52 | SND_SOC_CLOCK_OUT); |
| 53 | if (err) |
| 54 | return err; |
| 55 | |
| 56 | return 0; |
| 57 | } |
| 58 | |
| 59 | static struct snd_soc_ops snappercl15_ops = { |
| 60 | .hw_params = snappercl15_hw_params, |
| 61 | }; |
| 62 | |
| 63 | static const struct snd_soc_dapm_widget tlv320aic23_dapm_widgets[] = { |
| 64 | SND_SOC_DAPM_HP("Headphone Jack", NULL), |
| 65 | SND_SOC_DAPM_LINE("Line In", NULL), |
| 66 | SND_SOC_DAPM_MIC("Mic Jack", NULL), |
| 67 | }; |
| 68 | |
| 69 | static const struct snd_soc_dapm_route audio_map[] = { |
| 70 | {"Headphone Jack", NULL, "LHPOUT"}, |
| 71 | {"Headphone Jack", NULL, "RHPOUT"}, |
| 72 | |
| 73 | {"LLINEIN", NULL, "Line In"}, |
| 74 | {"RLINEIN", NULL, "Line In"}, |
| 75 | |
| 76 | {"MICIN", NULL, "Mic Jack"}, |
| 77 | }; |
| 78 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 79 | static int snappercl15_tlv320aic23_init(struct snd_soc_pcm_runtime *rtd) |
Ryan Mallon | 315f7da | 2010-06-08 22:01:12 +1200 | [diff] [blame] | 80 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 81 | struct snd_soc_codec *codec = rtd->codec; |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 82 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 83 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 84 | snd_soc_dapm_new_controls(dapm, tlv320aic23_dapm_widgets, |
Ryan Mallon | 315f7da | 2010-06-08 22:01:12 +1200 | [diff] [blame] | 85 | ARRAY_SIZE(tlv320aic23_dapm_widgets)); |
| 86 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 87 | snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map)); |
Ryan Mallon | 315f7da | 2010-06-08 22:01:12 +1200 | [diff] [blame] | 88 | return 0; |
| 89 | } |
| 90 | |
| 91 | static struct snd_soc_dai_link snappercl15_dai = { |
| 92 | .name = "tlv320aic23", |
| 93 | .stream_name = "AIC23", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 94 | .cpu_dai_name = "ep93xx-i2s", |
| 95 | .codec_dai_name = "tlv320aic23-hifi", |
| 96 | .codec_name = "tlv320aic23-codec.0-001a", |
| 97 | .platform_name = "ep93xx-pcm-audio", |
Ryan Mallon | 315f7da | 2010-06-08 22:01:12 +1200 | [diff] [blame] | 98 | .init = snappercl15_tlv320aic23_init, |
| 99 | .ops = &snappercl15_ops, |
| 100 | }; |
| 101 | |
| 102 | static struct snd_soc_card snd_soc_snappercl15 = { |
| 103 | .name = "Snapper CL15", |
Ryan Mallon | 315f7da | 2010-06-08 22:01:12 +1200 | [diff] [blame] | 104 | .dai_link = &snappercl15_dai, |
| 105 | .num_links = 1, |
| 106 | }; |
| 107 | |
Mika Westerberg | 62e4f7d | 2011-09-11 12:28:52 +0300 | [diff] [blame] | 108 | static int __devinit snappercl15_probe(struct platform_device *pdev) |
Ryan Mallon | 315f7da | 2010-06-08 22:01:12 +1200 | [diff] [blame] | 109 | { |
Mika Westerberg | 62e4f7d | 2011-09-11 12:28:52 +0300 | [diff] [blame] | 110 | struct snd_soc_card *card = &snd_soc_snappercl15; |
Ryan Mallon | 315f7da | 2010-06-08 22:01:12 +1200 | [diff] [blame] | 111 | int ret; |
| 112 | |
Ryan Mallon | 315f7da | 2010-06-08 22:01:12 +1200 | [diff] [blame] | 113 | ret = ep93xx_i2s_acquire(EP93XX_SYSCON_DEVCFG_I2SONAC97, |
| 114 | EP93XX_SYSCON_I2SCLKDIV_ORIDE | |
| 115 | EP93XX_SYSCON_I2SCLKDIV_SPOL); |
| 116 | if (ret) |
| 117 | return ret; |
| 118 | |
Mika Westerberg | 62e4f7d | 2011-09-11 12:28:52 +0300 | [diff] [blame] | 119 | card->dev = &pdev->dev; |
| 120 | |
| 121 | ret = snd_soc_register_card(card); |
| 122 | if (ret) { |
| 123 | dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", |
| 124 | ret); |
| 125 | ep93xx_i2s_release(); |
| 126 | } |
Ryan Mallon | 315f7da | 2010-06-08 22:01:12 +1200 | [diff] [blame] | 127 | |
| 128 | return ret; |
| 129 | } |
| 130 | |
Mika Westerberg | 62e4f7d | 2011-09-11 12:28:52 +0300 | [diff] [blame] | 131 | static int __devexit snappercl15_remove(struct platform_device *pdev) |
| 132 | { |
| 133 | struct snd_soc_card *card = platform_get_drvdata(pdev); |
| 134 | |
| 135 | snd_soc_unregister_card(card); |
| 136 | ep93xx_i2s_release(); |
| 137 | |
| 138 | return 0; |
| 139 | } |
| 140 | |
| 141 | static struct platform_driver snappercl15_driver = { |
| 142 | .driver = { |
| 143 | .name = "snappercl15-audio", |
| 144 | .owner = THIS_MODULE, |
| 145 | }, |
| 146 | .probe = snappercl15_probe, |
| 147 | .remove = __devexit_p(snappercl15_remove), |
| 148 | }; |
| 149 | |
| 150 | static int __init snappercl15_init(void) |
| 151 | { |
| 152 | return platform_driver_register(&snappercl15_driver); |
| 153 | } |
| 154 | |
Ryan Mallon | 315f7da | 2010-06-08 22:01:12 +1200 | [diff] [blame] | 155 | static void __exit snappercl15_exit(void) |
| 156 | { |
Mika Westerberg | 62e4f7d | 2011-09-11 12:28:52 +0300 | [diff] [blame] | 157 | platform_driver_unregister(&snappercl15_driver); |
Ryan Mallon | 315f7da | 2010-06-08 22:01:12 +1200 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | module_init(snappercl15_init); |
| 161 | module_exit(snappercl15_exit); |
| 162 | |
Ryan Mallon | 1c5454e | 2011-06-15 14:45:36 +1000 | [diff] [blame] | 163 | MODULE_AUTHOR("Ryan Mallon"); |
Ryan Mallon | 315f7da | 2010-06-08 22:01:12 +1200 | [diff] [blame] | 164 | MODULE_DESCRIPTION("ALSA SoC Snapper CL15"); |
| 165 | MODULE_LICENSE("GPL"); |
Mika Westerberg | 62e4f7d | 2011-09-11 12:28:52 +0300 | [diff] [blame] | 166 | MODULE_ALIAS("platform:snappercl15-audio"); |