18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * e740-wm9705.c -- SoC audio for e740 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_ci#define E740_AUDIO_OUT 1 228c2ecf20Sopenharmony_ci#define E740_AUDIO_IN 2 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_cistatic int e740_audio_power; 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_cistatic void e740_sync_audio_power(int status) 278c2ecf20Sopenharmony_ci{ 288c2ecf20Sopenharmony_ci gpio_set_value(GPIO_E740_WM9705_nAVDD2, !status); 298c2ecf20Sopenharmony_ci gpio_set_value(GPIO_E740_AMP_ON, (status & E740_AUDIO_OUT) ? 1 : 0); 308c2ecf20Sopenharmony_ci gpio_set_value(GPIO_E740_MIC_ON, (status & E740_AUDIO_IN) ? 1 : 0); 318c2ecf20Sopenharmony_ci} 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_cistatic int e740_mic_amp_event(struct snd_soc_dapm_widget *w, 348c2ecf20Sopenharmony_ci struct snd_kcontrol *kcontrol, int event) 358c2ecf20Sopenharmony_ci{ 368c2ecf20Sopenharmony_ci if (event & SND_SOC_DAPM_PRE_PMU) 378c2ecf20Sopenharmony_ci e740_audio_power |= E740_AUDIO_IN; 388c2ecf20Sopenharmony_ci else if (event & SND_SOC_DAPM_POST_PMD) 398c2ecf20Sopenharmony_ci e740_audio_power &= ~E740_AUDIO_IN; 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci e740_sync_audio_power(e740_audio_power); 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci return 0; 448c2ecf20Sopenharmony_ci} 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_cistatic int e740_output_amp_event(struct snd_soc_dapm_widget *w, 478c2ecf20Sopenharmony_ci struct snd_kcontrol *kcontrol, int event) 488c2ecf20Sopenharmony_ci{ 498c2ecf20Sopenharmony_ci if (event & SND_SOC_DAPM_PRE_PMU) 508c2ecf20Sopenharmony_ci e740_audio_power |= E740_AUDIO_OUT; 518c2ecf20Sopenharmony_ci else if (event & SND_SOC_DAPM_POST_PMD) 528c2ecf20Sopenharmony_ci e740_audio_power &= ~E740_AUDIO_OUT; 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_ci e740_sync_audio_power(e740_audio_power); 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci return 0; 578c2ecf20Sopenharmony_ci} 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_cistatic const struct snd_soc_dapm_widget e740_dapm_widgets[] = { 608c2ecf20Sopenharmony_ci SND_SOC_DAPM_HP("Headphone Jack", NULL), 618c2ecf20Sopenharmony_ci SND_SOC_DAPM_SPK("Speaker", NULL), 628c2ecf20Sopenharmony_ci SND_SOC_DAPM_MIC("Mic (Internal)", NULL), 638c2ecf20Sopenharmony_ci SND_SOC_DAPM_PGA_E("Output Amp", SND_SOC_NOPM, 0, 0, NULL, 0, 648c2ecf20Sopenharmony_ci e740_output_amp_event, SND_SOC_DAPM_PRE_PMU | 658c2ecf20Sopenharmony_ci SND_SOC_DAPM_POST_PMD), 668c2ecf20Sopenharmony_ci SND_SOC_DAPM_PGA_E("Mic Amp", SND_SOC_NOPM, 0, 0, NULL, 0, 678c2ecf20Sopenharmony_ci e740_mic_amp_event, SND_SOC_DAPM_PRE_PMU | 688c2ecf20Sopenharmony_ci SND_SOC_DAPM_POST_PMD), 698c2ecf20Sopenharmony_ci}; 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_cistatic const struct snd_soc_dapm_route audio_map[] = { 728c2ecf20Sopenharmony_ci {"Output Amp", NULL, "LOUT"}, 738c2ecf20Sopenharmony_ci {"Output Amp", NULL, "ROUT"}, 748c2ecf20Sopenharmony_ci {"Output Amp", NULL, "MONOOUT"}, 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci {"Speaker", NULL, "Output Amp"}, 778c2ecf20Sopenharmony_ci {"Headphone Jack", NULL, "Output Amp"}, 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_ci {"MIC1", NULL, "Mic Amp"}, 808c2ecf20Sopenharmony_ci {"Mic Amp", NULL, "Mic (Internal)"}, 818c2ecf20Sopenharmony_ci}; 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ciSND_SOC_DAILINK_DEFS(ac97, 848c2ecf20Sopenharmony_ci DAILINK_COMP_ARRAY(COMP_CPU("pxa2xx-ac97")), 858c2ecf20Sopenharmony_ci DAILINK_COMP_ARRAY(COMP_CODEC("wm9705-codec", "wm9705-hifi")), 868c2ecf20Sopenharmony_ci DAILINK_COMP_ARRAY(COMP_PLATFORM("pxa-pcm-audio"))); 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_ciSND_SOC_DAILINK_DEFS(ac97_aux, 898c2ecf20Sopenharmony_ci DAILINK_COMP_ARRAY(COMP_CPU("pxa2xx-ac97-aux")), 908c2ecf20Sopenharmony_ci DAILINK_COMP_ARRAY(COMP_CODEC("wm9705-codec", "wm9705-aux")), 918c2ecf20Sopenharmony_ci DAILINK_COMP_ARRAY(COMP_PLATFORM("pxa-pcm-audio"))); 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_cistatic struct snd_soc_dai_link e740_dai[] = { 948c2ecf20Sopenharmony_ci { 958c2ecf20Sopenharmony_ci .name = "AC97", 968c2ecf20Sopenharmony_ci .stream_name = "AC97 HiFi", 978c2ecf20Sopenharmony_ci SND_SOC_DAILINK_REG(ac97), 988c2ecf20Sopenharmony_ci }, 998c2ecf20Sopenharmony_ci { 1008c2ecf20Sopenharmony_ci .name = "AC97 Aux", 1018c2ecf20Sopenharmony_ci .stream_name = "AC97 Aux", 1028c2ecf20Sopenharmony_ci SND_SOC_DAILINK_REG(ac97_aux), 1038c2ecf20Sopenharmony_ci }, 1048c2ecf20Sopenharmony_ci}; 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_cistatic struct snd_soc_card e740 = { 1078c2ecf20Sopenharmony_ci .name = "Toshiba e740", 1088c2ecf20Sopenharmony_ci .owner = THIS_MODULE, 1098c2ecf20Sopenharmony_ci .dai_link = e740_dai, 1108c2ecf20Sopenharmony_ci .num_links = ARRAY_SIZE(e740_dai), 1118c2ecf20Sopenharmony_ci 1128c2ecf20Sopenharmony_ci .dapm_widgets = e740_dapm_widgets, 1138c2ecf20Sopenharmony_ci .num_dapm_widgets = ARRAY_SIZE(e740_dapm_widgets), 1148c2ecf20Sopenharmony_ci .dapm_routes = audio_map, 1158c2ecf20Sopenharmony_ci .num_dapm_routes = ARRAY_SIZE(audio_map), 1168c2ecf20Sopenharmony_ci .fully_routed = true, 1178c2ecf20Sopenharmony_ci}; 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_cistatic struct gpio e740_audio_gpios[] = { 1208c2ecf20Sopenharmony_ci { GPIO_E740_MIC_ON, GPIOF_OUT_INIT_LOW, "Mic amp" }, 1218c2ecf20Sopenharmony_ci { GPIO_E740_AMP_ON, GPIOF_OUT_INIT_LOW, "Output amp" }, 1228c2ecf20Sopenharmony_ci { GPIO_E740_WM9705_nAVDD2, GPIOF_OUT_INIT_HIGH, "Audio power" }, 1238c2ecf20Sopenharmony_ci}; 1248c2ecf20Sopenharmony_ci 1258c2ecf20Sopenharmony_cistatic int e740_probe(struct platform_device *pdev) 1268c2ecf20Sopenharmony_ci{ 1278c2ecf20Sopenharmony_ci struct snd_soc_card *card = &e740; 1288c2ecf20Sopenharmony_ci int ret; 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_ci ret = gpio_request_array(e740_audio_gpios, 1318c2ecf20Sopenharmony_ci ARRAY_SIZE(e740_audio_gpios)); 1328c2ecf20Sopenharmony_ci if (ret) 1338c2ecf20Sopenharmony_ci return ret; 1348c2ecf20Sopenharmony_ci 1358c2ecf20Sopenharmony_ci card->dev = &pdev->dev; 1368c2ecf20Sopenharmony_ci 1378c2ecf20Sopenharmony_ci ret = devm_snd_soc_register_card(&pdev->dev, card); 1388c2ecf20Sopenharmony_ci if (ret) { 1398c2ecf20Sopenharmony_ci dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", 1408c2ecf20Sopenharmony_ci ret); 1418c2ecf20Sopenharmony_ci gpio_free_array(e740_audio_gpios, ARRAY_SIZE(e740_audio_gpios)); 1428c2ecf20Sopenharmony_ci } 1438c2ecf20Sopenharmony_ci return ret; 1448c2ecf20Sopenharmony_ci} 1458c2ecf20Sopenharmony_ci 1468c2ecf20Sopenharmony_cistatic int e740_remove(struct platform_device *pdev) 1478c2ecf20Sopenharmony_ci{ 1488c2ecf20Sopenharmony_ci gpio_free_array(e740_audio_gpios, ARRAY_SIZE(e740_audio_gpios)); 1498c2ecf20Sopenharmony_ci return 0; 1508c2ecf20Sopenharmony_ci} 1518c2ecf20Sopenharmony_ci 1528c2ecf20Sopenharmony_cistatic struct platform_driver e740_driver = { 1538c2ecf20Sopenharmony_ci .driver = { 1548c2ecf20Sopenharmony_ci .name = "e740-audio", 1558c2ecf20Sopenharmony_ci .pm = &snd_soc_pm_ops, 1568c2ecf20Sopenharmony_ci }, 1578c2ecf20Sopenharmony_ci .probe = e740_probe, 1588c2ecf20Sopenharmony_ci .remove = e740_remove, 1598c2ecf20Sopenharmony_ci}; 1608c2ecf20Sopenharmony_ci 1618c2ecf20Sopenharmony_cimodule_platform_driver(e740_driver); 1628c2ecf20Sopenharmony_ci 1638c2ecf20Sopenharmony_ci/* Module information */ 1648c2ecf20Sopenharmony_ciMODULE_AUTHOR("Ian Molton <spyro@f2s.com>"); 1658c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("ALSA SoC driver for e740"); 1668c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL v2"); 1678c2ecf20Sopenharmony_ciMODULE_ALIAS("platform:e740-audio"); 168