^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Handles the Mitac mioa701 SoC system
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2008 Robert Jarzmik
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * This is a little schema of the sound interconnections :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Sagem X200 Wolfson WM9713
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * +--------+ +-------------------+ Rear Speaker
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * | | | | /-+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * | +--->----->---+MONOIN SPKL+--->----+-+ |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * | GSM | | | | | |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * | +--->----->---+PCBEEP SPKR+--->----+-+ |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * | CHIP | | | \-+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * | +---<-----<---+MONO |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * | | | | Front Speaker
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * +--------+ | | /-+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * | HPL+--->----+-+ |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * | | | | |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * | OUT3+--->----+-+ |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * | | \-+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * | |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * | | Front Micro
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * | | +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * | MIC1+-----<--+o+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * | | +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * +-------------------+ ---
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include <linux/moduleparam.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include <asm/mach-types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include <mach/audio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #include <sound/core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #include <sound/pcm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #include <sound/soc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #include <sound/initval.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #include <sound/ac97_codec.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #include "../codecs/wm9713.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #define AC97_GPIO_PULL 0x58
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) /* Use GPIO8 for rear speaker amplifier */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) static int rear_amp_power(struct snd_soc_component *component, int power)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) unsigned short reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) if (power) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) reg = snd_soc_component_read(component, AC97_GPIO_CFG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) snd_soc_component_write(component, AC97_GPIO_CFG, reg | 0x0100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) reg = snd_soc_component_read(component, AC97_GPIO_PULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) snd_soc_component_write(component, AC97_GPIO_PULL, reg | (1<<15));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) reg = snd_soc_component_read(component, AC97_GPIO_CFG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) snd_soc_component_write(component, AC97_GPIO_CFG, reg & ~0x0100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) reg = snd_soc_component_read(component, AC97_GPIO_PULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) snd_soc_component_write(component, AC97_GPIO_PULL, reg & ~(1<<15));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) static int rear_amp_event(struct snd_soc_dapm_widget *widget,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) struct snd_kcontrol *kctl, int event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) struct snd_soc_card *card = widget->dapm->card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) struct snd_soc_pcm_runtime *rtd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) struct snd_soc_component *component;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) component = asoc_rtd_to_codec(rtd, 0)->component;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) return rear_amp_power(component, SND_SOC_DAPM_EVENT_ON(event));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) /* mioa701 machine dapm widgets */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) static const struct snd_soc_dapm_widget mioa701_dapm_widgets[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) SND_SOC_DAPM_SPK("Front Speaker", NULL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) SND_SOC_DAPM_SPK("Rear Speaker", rear_amp_event),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) SND_SOC_DAPM_MIC("Headset", NULL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) SND_SOC_DAPM_LINE("GSM Line Out", NULL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) SND_SOC_DAPM_LINE("GSM Line In", NULL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) SND_SOC_DAPM_MIC("Headset Mic", NULL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) SND_SOC_DAPM_MIC("Front Mic", NULL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) static const struct snd_soc_dapm_route audio_map[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) /* Call Mic */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) {"Mic Bias", NULL, "Front Mic"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) {"MIC1", NULL, "Mic Bias"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) /* Headset Mic */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) {"LINEL", NULL, "Headset Mic"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) {"LINER", NULL, "Headset Mic"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) /* GSM Module */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) {"MONOIN", NULL, "GSM Line Out"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) {"PCBEEP", NULL, "GSM Line Out"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) {"GSM Line In", NULL, "MONO"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) /* headphone connected to HPL, HPR */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) {"Headset", NULL, "HPL"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) {"Headset", NULL, "HPR"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) /* front speaker connected to HPL, OUT3 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) {"Front Speaker", NULL, "HPL"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) {"Front Speaker", NULL, "OUT3"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) /* rear speaker connected to SPKL, SPKR */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) {"Rear Speaker", NULL, "SPKL"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) {"Rear Speaker", NULL, "SPKR"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) static int mioa701_wm9713_init(struct snd_soc_pcm_runtime *rtd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) /* Prepare GPIO8 for rear speaker amplifier */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) snd_soc_component_update_bits(component, AC97_GPIO_CFG, 0x100, 0x100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) /* Prepare MIC input */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) snd_soc_component_update_bits(component, AC97_3D_CONTROL, 0xc000, 0xc000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) static struct snd_soc_ops mioa701_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) SND_SOC_DAILINK_DEFS(ac97,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) DAILINK_COMP_ARRAY(COMP_CPU("pxa2xx-ac97")),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) DAILINK_COMP_ARRAY(COMP_CODEC("wm9713-codec", "wm9713-hifi")),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) DAILINK_COMP_ARRAY(COMP_PLATFORM("pxa-pcm-audio")));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) SND_SOC_DAILINK_DEFS(ac97_aux,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) DAILINK_COMP_ARRAY(COMP_CPU("pxa2xx-ac97-aux")),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) DAILINK_COMP_ARRAY(COMP_CODEC("wm9713-codec", "wm9713-aux")),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) DAILINK_COMP_ARRAY(COMP_PLATFORM("pxa-pcm-audio")));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) static struct snd_soc_dai_link mioa701_dai[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) .name = "AC97",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) .stream_name = "AC97 HiFi",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) .init = mioa701_wm9713_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) .ops = &mioa701_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) SND_SOC_DAILINK_REG(ac97),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) .name = "AC97 Aux",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) .stream_name = "AC97 Aux",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) .ops = &mioa701_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) SND_SOC_DAILINK_REG(ac97_aux),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) static struct snd_soc_card mioa701 = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) .name = "MioA701",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) .dai_link = mioa701_dai,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) .num_links = ARRAY_SIZE(mioa701_dai),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) .dapm_widgets = mioa701_dapm_widgets,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) .num_dapm_widgets = ARRAY_SIZE(mioa701_dapm_widgets),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) .dapm_routes = audio_map,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) .num_dapm_routes = ARRAY_SIZE(audio_map),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) static int mioa701_wm9713_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) if (!machine_is_mioa701())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) mioa701.dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) rc = devm_snd_soc_register_card(&pdev->dev, &mioa701);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) if (!rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) dev_warn(&pdev->dev, "Be warned that incorrect mixers/muxes setup will "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) "lead to overheating and possible destruction of your device."
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) " Do not use without a good knowledge of mio's board design!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) static struct platform_driver mioa701_wm9713_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) .probe = mioa701_wm9713_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) .name = "mioa701-wm9713",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) .pm = &snd_soc_pm_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) module_platform_driver(mioa701_wm9713_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) /* Module information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) MODULE_AUTHOR("Robert Jarzmik (rjarzmik@free.fr)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) MODULE_DESCRIPTION("ALSA SoC WM9713 MIO A701");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) MODULE_ALIAS("platform:mioa701-wm9713");