Ian Molton | 28796ea | 2009-01-17 15:11:06 +0000 | [diff] [blame] | 1 | /* |
| 2 | * e740-wm9705.c -- SoC audio for e740 |
| 3 | * |
| 4 | * Copyright 2007 (c) Ian Molton <spyro@f2s.com> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify it |
| 7 | * under the terms of the GNU General Public License as published by the |
| 8 | * Free Software Foundation; version 2 ONLY. |
| 9 | * |
| 10 | */ |
| 11 | |
| 12 | #include <linux/module.h> |
| 13 | #include <linux/moduleparam.h> |
| 14 | #include <linux/gpio.h> |
| 15 | |
| 16 | #include <sound/core.h> |
| 17 | #include <sound/pcm.h> |
| 18 | #include <sound/soc.h> |
Ian Molton | 28796ea | 2009-01-17 15:11:06 +0000 | [diff] [blame] | 19 | |
Ian Molton | 28796ea | 2009-01-17 15:11:06 +0000 | [diff] [blame] | 20 | #include <mach/audio.h> |
| 21 | #include <mach/eseries-gpio.h> |
| 22 | |
| 23 | #include <asm/mach-types.h> |
| 24 | |
| 25 | #include "../codecs/wm9705.h" |
Ian Molton | 28796ea | 2009-01-17 15:11:06 +0000 | [diff] [blame] | 26 | #include "pxa2xx-ac97.h" |
| 27 | |
| 28 | |
| 29 | #define E740_AUDIO_OUT 1 |
| 30 | #define E740_AUDIO_IN 2 |
| 31 | |
| 32 | static int e740_audio_power; |
| 33 | |
| 34 | static void e740_sync_audio_power(int status) |
| 35 | { |
| 36 | gpio_set_value(GPIO_E740_WM9705_nAVDD2, !status); |
| 37 | gpio_set_value(GPIO_E740_AMP_ON, (status & E740_AUDIO_OUT) ? 1 : 0); |
| 38 | gpio_set_value(GPIO_E740_MIC_ON, (status & E740_AUDIO_IN) ? 1 : 0); |
| 39 | } |
| 40 | |
| 41 | static int e740_mic_amp_event(struct snd_soc_dapm_widget *w, |
| 42 | struct snd_kcontrol *kcontrol, int event) |
| 43 | { |
| 44 | if (event & SND_SOC_DAPM_PRE_PMU) |
| 45 | e740_audio_power |= E740_AUDIO_IN; |
| 46 | else if (event & SND_SOC_DAPM_POST_PMD) |
| 47 | e740_audio_power &= ~E740_AUDIO_IN; |
| 48 | |
| 49 | e740_sync_audio_power(e740_audio_power); |
| 50 | |
| 51 | return 0; |
| 52 | } |
| 53 | |
| 54 | static int e740_output_amp_event(struct snd_soc_dapm_widget *w, |
| 55 | struct snd_kcontrol *kcontrol, int event) |
| 56 | { |
| 57 | if (event & SND_SOC_DAPM_PRE_PMU) |
| 58 | e740_audio_power |= E740_AUDIO_OUT; |
| 59 | else if (event & SND_SOC_DAPM_POST_PMD) |
| 60 | e740_audio_power &= ~E740_AUDIO_OUT; |
| 61 | |
| 62 | e740_sync_audio_power(e740_audio_power); |
| 63 | |
| 64 | return 0; |
| 65 | } |
| 66 | |
| 67 | static const struct snd_soc_dapm_widget e740_dapm_widgets[] = { |
| 68 | SND_SOC_DAPM_HP("Headphone Jack", NULL), |
| 69 | SND_SOC_DAPM_SPK("Speaker", NULL), |
| 70 | SND_SOC_DAPM_MIC("Mic (Internal)", NULL), |
| 71 | SND_SOC_DAPM_PGA_E("Output Amp", SND_SOC_NOPM, 0, 0, NULL, 0, |
| 72 | e740_output_amp_event, SND_SOC_DAPM_PRE_PMU | |
| 73 | SND_SOC_DAPM_POST_PMD), |
| 74 | SND_SOC_DAPM_PGA_E("Mic Amp", SND_SOC_NOPM, 0, 0, NULL, 0, |
| 75 | e740_mic_amp_event, SND_SOC_DAPM_PRE_PMU | |
| 76 | SND_SOC_DAPM_POST_PMD), |
| 77 | }; |
| 78 | |
| 79 | static const struct snd_soc_dapm_route audio_map[] = { |
| 80 | {"Output Amp", NULL, "LOUT"}, |
| 81 | {"Output Amp", NULL, "ROUT"}, |
| 82 | {"Output Amp", NULL, "MONOOUT"}, |
| 83 | |
| 84 | {"Speaker", NULL, "Output Amp"}, |
| 85 | {"Headphone Jack", NULL, "Output Amp"}, |
| 86 | |
| 87 | {"MIC1", NULL, "Mic Amp"}, |
| 88 | {"Mic Amp", NULL, "Mic (Internal)"}, |
| 89 | }; |
| 90 | |
Ian Molton | 28796ea | 2009-01-17 15:11:06 +0000 | [diff] [blame] | 91 | static struct snd_soc_dai_link e740_dai[] = { |
| 92 | { |
| 93 | .name = "AC97", |
| 94 | .stream_name = "AC97 HiFi", |
Dmitry Eremin-Solenikov | 4bfc4e2 | 2011-02-23 02:29:11 +0300 | [diff] [blame] | 95 | .cpu_dai_name = "pxa2xx-ac97", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 96 | .codec_dai_name = "wm9705-hifi", |
| 97 | .platform_name = "pxa-pcm-audio", |
| 98 | .codec_name = "wm9705-codec", |
Ian Molton | 28796ea | 2009-01-17 15:11:06 +0000 | [diff] [blame] | 99 | }, |
| 100 | { |
| 101 | .name = "AC97 Aux", |
| 102 | .stream_name = "AC97 Aux", |
Dmitry Eremin-Solenikov | 4bfc4e2 | 2011-02-23 02:29:11 +0300 | [diff] [blame] | 103 | .cpu_dai_name = "pxa2xx-ac97-aux", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 104 | .codec_dai_name = "wm9705-aux", |
| 105 | .platform_name = "pxa-pcm-audio", |
| 106 | .codec_name = "wm9705-codec", |
Ian Molton | 28796ea | 2009-01-17 15:11:06 +0000 | [diff] [blame] | 107 | }, |
| 108 | }; |
| 109 | |
| 110 | static struct snd_soc_card e740 = { |
| 111 | .name = "Toshiba e740", |
Axel Lin | 561c6a1 | 2011-12-22 09:44:43 +0800 | [diff] [blame] | 112 | .owner = THIS_MODULE, |
Ian Molton | 28796ea | 2009-01-17 15:11:06 +0000 | [diff] [blame] | 113 | .dai_link = e740_dai, |
| 114 | .num_links = ARRAY_SIZE(e740_dai), |
Lars-Peter Clausen | 23d8f22 | 2014-03-01 15:48:14 +0100 | [diff] [blame] | 115 | |
| 116 | .dapm_widgets = e740_dapm_widgets, |
| 117 | .num_dapm_widgets = ARRAY_SIZE(e740_dapm_widgets), |
| 118 | .dapm_routes = audio_map, |
| 119 | .num_dapm_routes = ARRAY_SIZE(audio_map), |
Lars-Peter Clausen | dff6c96 | 2015-01-09 22:03:27 +0100 | [diff] [blame] | 120 | .fully_routed = true, |
Ian Molton | 28796ea | 2009-01-17 15:11:06 +0000 | [diff] [blame] | 121 | }; |
| 122 | |
Axel Lin | 6213382 | 2011-12-15 10:52:42 +0800 | [diff] [blame] | 123 | static struct gpio e740_audio_gpios[] = { |
| 124 | { GPIO_E740_MIC_ON, GPIOF_OUT_INIT_LOW, "Mic amp" }, |
| 125 | { GPIO_E740_AMP_ON, GPIOF_OUT_INIT_LOW, "Output amp" }, |
| 126 | { GPIO_E740_WM9705_nAVDD2, GPIOF_OUT_INIT_HIGH, "Audio power" }, |
| 127 | }; |
Ian Molton | 28796ea | 2009-01-17 15:11:06 +0000 | [diff] [blame] | 128 | |
Bill Pemberton | 570f6fe | 2012-12-07 09:26:17 -0500 | [diff] [blame] | 129 | static int e740_probe(struct platform_device *pdev) |
Ian Molton | 28796ea | 2009-01-17 15:11:06 +0000 | [diff] [blame] | 130 | { |
Axel Lin | 6213382 | 2011-12-15 10:52:42 +0800 | [diff] [blame] | 131 | struct snd_soc_card *card = &e740; |
Ian Molton | 28796ea | 2009-01-17 15:11:06 +0000 | [diff] [blame] | 132 | int ret; |
| 133 | |
Axel Lin | 6213382 | 2011-12-15 10:52:42 +0800 | [diff] [blame] | 134 | ret = gpio_request_array(e740_audio_gpios, |
| 135 | ARRAY_SIZE(e740_audio_gpios)); |
Ian Molton | 28796ea | 2009-01-17 15:11:06 +0000 | [diff] [blame] | 136 | if (ret) |
| 137 | return ret; |
| 138 | |
Axel Lin | 6213382 | 2011-12-15 10:52:42 +0800 | [diff] [blame] | 139 | card->dev = &pdev->dev; |
Ian Molton | 28796ea | 2009-01-17 15:11:06 +0000 | [diff] [blame] | 140 | |
Axel Lin | 2fd7076 | 2015-09-01 10:32:59 +0800 | [diff] [blame] | 141 | ret = devm_snd_soc_register_card(&pdev->dev, card); |
Axel Lin | 6213382 | 2011-12-15 10:52:42 +0800 | [diff] [blame] | 142 | if (ret) { |
| 143 | dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", |
| 144 | ret); |
| 145 | gpio_free_array(e740_audio_gpios, ARRAY_SIZE(e740_audio_gpios)); |
Ian Molton | 28796ea | 2009-01-17 15:11:06 +0000 | [diff] [blame] | 146 | } |
Ian Molton | 28796ea | 2009-01-17 15:11:06 +0000 | [diff] [blame] | 147 | return ret; |
| 148 | } |
| 149 | |
Bill Pemberton | 570f6fe | 2012-12-07 09:26:17 -0500 | [diff] [blame] | 150 | static int e740_remove(struct platform_device *pdev) |
Ian Molton | 28796ea | 2009-01-17 15:11:06 +0000 | [diff] [blame] | 151 | { |
Axel Lin | 6213382 | 2011-12-15 10:52:42 +0800 | [diff] [blame] | 152 | gpio_free_array(e740_audio_gpios, ARRAY_SIZE(e740_audio_gpios)); |
Axel Lin | 6213382 | 2011-12-15 10:52:42 +0800 | [diff] [blame] | 153 | return 0; |
Ian Molton | 28796ea | 2009-01-17 15:11:06 +0000 | [diff] [blame] | 154 | } |
| 155 | |
Axel Lin | 6213382 | 2011-12-15 10:52:42 +0800 | [diff] [blame] | 156 | static struct platform_driver e740_driver = { |
| 157 | .driver = { |
| 158 | .name = "e740-audio", |
Dmitry Eremin-Solenikov | 7db1698 | 2013-10-17 14:01:37 +0400 | [diff] [blame] | 159 | .pm = &snd_soc_pm_ops, |
Axel Lin | 6213382 | 2011-12-15 10:52:42 +0800 | [diff] [blame] | 160 | }, |
| 161 | .probe = e740_probe, |
Bill Pemberton | 570f6fe | 2012-12-07 09:26:17 -0500 | [diff] [blame] | 162 | .remove = e740_remove, |
Axel Lin | 6213382 | 2011-12-15 10:52:42 +0800 | [diff] [blame] | 163 | }; |
| 164 | |
| 165 | module_platform_driver(e740_driver); |
Ian Molton | 28796ea | 2009-01-17 15:11:06 +0000 | [diff] [blame] | 166 | |
| 167 | /* Module information */ |
| 168 | MODULE_AUTHOR("Ian Molton <spyro@f2s.com>"); |
| 169 | MODULE_DESCRIPTION("ALSA SoC driver for e740"); |
| 170 | MODULE_LICENSE("GPL v2"); |
Axel Lin | 6213382 | 2011-12-15 10:52:42 +0800 | [diff] [blame] | 171 | MODULE_ALIAS("platform:e740-audio"); |