18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * e750-wm9705.c  --  SoC audio for e750
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright 2007 (c) Ian Molton <spyro@f2s.com>
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#include <linux/module.h>
98c2ecf20Sopenharmony_ci#include <linux/moduleparam.h>
108c2ecf20Sopenharmony_ci#include <linux/gpio.h>
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#include <sound/core.h>
138c2ecf20Sopenharmony_ci#include <sound/pcm.h>
148c2ecf20Sopenharmony_ci#include <sound/soc.h>
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci#include <mach/audio.h>
178c2ecf20Sopenharmony_ci#include <mach/eseries-gpio.h>
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci#include <asm/mach-types.h>
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_cistatic int e750_spk_amp_event(struct snd_soc_dapm_widget *w,
228c2ecf20Sopenharmony_ci				struct snd_kcontrol *kcontrol, int event)
238c2ecf20Sopenharmony_ci{
248c2ecf20Sopenharmony_ci	if (event & SND_SOC_DAPM_PRE_PMU)
258c2ecf20Sopenharmony_ci		gpio_set_value(GPIO_E750_SPK_AMP_OFF, 0);
268c2ecf20Sopenharmony_ci	else if (event & SND_SOC_DAPM_POST_PMD)
278c2ecf20Sopenharmony_ci		gpio_set_value(GPIO_E750_SPK_AMP_OFF, 1);
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci	return 0;
308c2ecf20Sopenharmony_ci}
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_cistatic int e750_hp_amp_event(struct snd_soc_dapm_widget *w,
338c2ecf20Sopenharmony_ci				struct snd_kcontrol *kcontrol, int event)
348c2ecf20Sopenharmony_ci{
358c2ecf20Sopenharmony_ci	if (event & SND_SOC_DAPM_PRE_PMU)
368c2ecf20Sopenharmony_ci		gpio_set_value(GPIO_E750_HP_AMP_OFF, 0);
378c2ecf20Sopenharmony_ci	else if (event & SND_SOC_DAPM_POST_PMD)
388c2ecf20Sopenharmony_ci		gpio_set_value(GPIO_E750_HP_AMP_OFF, 1);
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci	return 0;
418c2ecf20Sopenharmony_ci}
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_cistatic const struct snd_soc_dapm_widget e750_dapm_widgets[] = {
448c2ecf20Sopenharmony_ci	SND_SOC_DAPM_HP("Headphone Jack", NULL),
458c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SPK("Speaker", NULL),
468c2ecf20Sopenharmony_ci	SND_SOC_DAPM_MIC("Mic (Internal)", NULL),
478c2ecf20Sopenharmony_ci	SND_SOC_DAPM_PGA_E("Headphone Amp", SND_SOC_NOPM, 0, 0, NULL, 0,
488c2ecf20Sopenharmony_ci			e750_hp_amp_event, SND_SOC_DAPM_PRE_PMU |
498c2ecf20Sopenharmony_ci			SND_SOC_DAPM_POST_PMD),
508c2ecf20Sopenharmony_ci	SND_SOC_DAPM_PGA_E("Speaker Amp", SND_SOC_NOPM, 0, 0, NULL, 0,
518c2ecf20Sopenharmony_ci			e750_spk_amp_event, SND_SOC_DAPM_PRE_PMU |
528c2ecf20Sopenharmony_ci			SND_SOC_DAPM_POST_PMD),
538c2ecf20Sopenharmony_ci};
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_cistatic const struct snd_soc_dapm_route audio_map[] = {
568c2ecf20Sopenharmony_ci	{"Headphone Amp", NULL, "HPOUTL"},
578c2ecf20Sopenharmony_ci	{"Headphone Amp", NULL, "HPOUTR"},
588c2ecf20Sopenharmony_ci	{"Headphone Jack", NULL, "Headphone Amp"},
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci	{"Speaker Amp", NULL, "MONOOUT"},
618c2ecf20Sopenharmony_ci	{"Speaker", NULL, "Speaker Amp"},
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci	{"MIC1", NULL, "Mic (Internal)"},
648c2ecf20Sopenharmony_ci};
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ciSND_SOC_DAILINK_DEFS(ac97,
678c2ecf20Sopenharmony_ci	DAILINK_COMP_ARRAY(COMP_CPU("pxa2xx-ac97")),
688c2ecf20Sopenharmony_ci	DAILINK_COMP_ARRAY(COMP_CODEC("wm9705-codec", "wm9705-hifi")),
698c2ecf20Sopenharmony_ci	DAILINK_COMP_ARRAY(COMP_PLATFORM("pxa-pcm-audio")));
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ciSND_SOC_DAILINK_DEFS(ac97_aux,
728c2ecf20Sopenharmony_ci	DAILINK_COMP_ARRAY(COMP_CPU("pxa2xx-ac97-aux")),
738c2ecf20Sopenharmony_ci	DAILINK_COMP_ARRAY(COMP_CODEC("wm9705-codec", "wm9705-aux")),
748c2ecf20Sopenharmony_ci	DAILINK_COMP_ARRAY(COMP_PLATFORM("pxa-pcm-audio")));
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_cistatic struct snd_soc_dai_link e750_dai[] = {
778c2ecf20Sopenharmony_ci	{
788c2ecf20Sopenharmony_ci		.name = "AC97",
798c2ecf20Sopenharmony_ci		.stream_name = "AC97 HiFi",
808c2ecf20Sopenharmony_ci		SND_SOC_DAILINK_REG(ac97),
818c2ecf20Sopenharmony_ci		/* use ops to check startup state */
828c2ecf20Sopenharmony_ci	},
838c2ecf20Sopenharmony_ci	{
848c2ecf20Sopenharmony_ci		.name = "AC97 Aux",
858c2ecf20Sopenharmony_ci		.stream_name = "AC97 Aux",
868c2ecf20Sopenharmony_ci		SND_SOC_DAILINK_REG(ac97_aux),
878c2ecf20Sopenharmony_ci	},
888c2ecf20Sopenharmony_ci};
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_cistatic struct snd_soc_card e750 = {
918c2ecf20Sopenharmony_ci	.name = "Toshiba e750",
928c2ecf20Sopenharmony_ci	.owner = THIS_MODULE,
938c2ecf20Sopenharmony_ci	.dai_link = e750_dai,
948c2ecf20Sopenharmony_ci	.num_links = ARRAY_SIZE(e750_dai),
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_ci	.dapm_widgets = e750_dapm_widgets,
978c2ecf20Sopenharmony_ci	.num_dapm_widgets = ARRAY_SIZE(e750_dapm_widgets),
988c2ecf20Sopenharmony_ci	.dapm_routes = audio_map,
998c2ecf20Sopenharmony_ci	.num_dapm_routes = ARRAY_SIZE(audio_map),
1008c2ecf20Sopenharmony_ci	.fully_routed = true,
1018c2ecf20Sopenharmony_ci};
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_cistatic struct gpio e750_audio_gpios[] = {
1048c2ecf20Sopenharmony_ci	{ GPIO_E750_HP_AMP_OFF, GPIOF_OUT_INIT_HIGH, "Headphone amp" },
1058c2ecf20Sopenharmony_ci	{ GPIO_E750_SPK_AMP_OFF, GPIOF_OUT_INIT_HIGH, "Speaker amp" },
1068c2ecf20Sopenharmony_ci};
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_cistatic int e750_probe(struct platform_device *pdev)
1098c2ecf20Sopenharmony_ci{
1108c2ecf20Sopenharmony_ci	struct snd_soc_card *card = &e750;
1118c2ecf20Sopenharmony_ci	int ret;
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_ci	ret = gpio_request_array(e750_audio_gpios,
1148c2ecf20Sopenharmony_ci				 ARRAY_SIZE(e750_audio_gpios));
1158c2ecf20Sopenharmony_ci	if (ret)
1168c2ecf20Sopenharmony_ci		return ret;
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_ci	card->dev = &pdev->dev;
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_ci	ret = devm_snd_soc_register_card(&pdev->dev, card);
1218c2ecf20Sopenharmony_ci	if (ret) {
1228c2ecf20Sopenharmony_ci		dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
1238c2ecf20Sopenharmony_ci			ret);
1248c2ecf20Sopenharmony_ci		gpio_free_array(e750_audio_gpios, ARRAY_SIZE(e750_audio_gpios));
1258c2ecf20Sopenharmony_ci	}
1268c2ecf20Sopenharmony_ci	return ret;
1278c2ecf20Sopenharmony_ci}
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_cistatic int e750_remove(struct platform_device *pdev)
1308c2ecf20Sopenharmony_ci{
1318c2ecf20Sopenharmony_ci	gpio_free_array(e750_audio_gpios, ARRAY_SIZE(e750_audio_gpios));
1328c2ecf20Sopenharmony_ci	return 0;
1338c2ecf20Sopenharmony_ci}
1348c2ecf20Sopenharmony_ci
1358c2ecf20Sopenharmony_cistatic struct platform_driver e750_driver = {
1368c2ecf20Sopenharmony_ci	.driver		= {
1378c2ecf20Sopenharmony_ci		.name	= "e750-audio",
1388c2ecf20Sopenharmony_ci		.pm     = &snd_soc_pm_ops,
1398c2ecf20Sopenharmony_ci	},
1408c2ecf20Sopenharmony_ci	.probe		= e750_probe,
1418c2ecf20Sopenharmony_ci	.remove		= e750_remove,
1428c2ecf20Sopenharmony_ci};
1438c2ecf20Sopenharmony_ci
1448c2ecf20Sopenharmony_cimodule_platform_driver(e750_driver);
1458c2ecf20Sopenharmony_ci
1468c2ecf20Sopenharmony_ci/* Module information */
1478c2ecf20Sopenharmony_ciMODULE_AUTHOR("Ian Molton <spyro@f2s.com>");
1488c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("ALSA SoC driver for e750");
1498c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL v2");
1508c2ecf20Sopenharmony_ciMODULE_ALIAS("platform:e750-audio");
151