^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) * tegra_wm8903.c - Tegra machine ASoC driver for boards using WM8903 codec.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Author: Stephen Warren <swarren@nvidia.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) 2010-2012 - NVIDIA, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Based on code copyright/by:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * (c) 2009, 2010 Nvidia Graphics Pvt. Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * Copyright 2007 Wolfson Microelectronics PLC.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * Author: Graeme Gregory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * graeme.gregory@wolfsonmicro.com or linux@wolfsonmicro.com
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/gpio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/of_gpio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <sound/core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <sound/jack.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <sound/pcm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <sound/pcm_params.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <sound/soc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include "../codecs/wm8903.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include "tegra_asoc_utils.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #define DRV_NAME "tegra-snd-wm8903"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) struct tegra_wm8903 {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) int gpio_spkr_en;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) int gpio_hp_det;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) int gpio_hp_mute;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) int gpio_int_mic_en;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) int gpio_ext_mic_en;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) struct tegra_asoc_utils_data util_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) static int tegra_wm8903_hw_params(struct snd_pcm_substream *substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) struct snd_pcm_hw_params *params)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) struct snd_soc_card *card = rtd->card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) struct tegra_wm8903 *machine = snd_soc_card_get_drvdata(card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) int srate, mclk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) srate = params_rate(params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) switch (srate) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) case 64000:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) case 88200:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) case 96000:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) mclk = 128 * srate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) mclk = 256 * srate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) /* FIXME: Codec only requires >= 3MHz if OSR==0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) while (mclk < 6000000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) mclk *= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) err = tegra_asoc_utils_set_rate(&machine->util_data, srate, mclk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) dev_err(card->dev, "Can't configure clocks\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) err = snd_soc_dai_set_sysclk(codec_dai, 0, mclk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) SND_SOC_CLOCK_IN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) dev_err(card->dev, "codec_dai clock not set\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) static const struct snd_soc_ops tegra_wm8903_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) .hw_params = tegra_wm8903_hw_params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) static struct snd_soc_jack tegra_wm8903_hp_jack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) static struct snd_soc_jack_pin tegra_wm8903_hp_jack_pins[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) .pin = "Headphone Jack",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) .mask = SND_JACK_HEADPHONE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) static struct snd_soc_jack_gpio tegra_wm8903_hp_jack_gpio = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) .name = "headphone detect",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) .report = SND_JACK_HEADPHONE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) .debounce_time = 150,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) .invert = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) static struct snd_soc_jack tegra_wm8903_mic_jack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) static struct snd_soc_jack_pin tegra_wm8903_mic_jack_pins[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) .pin = "Mic Jack",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) .mask = SND_JACK_MICROPHONE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) static int tegra_wm8903_event_int_spk(struct snd_soc_dapm_widget *w,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) struct snd_kcontrol *k, int event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) struct snd_soc_dapm_context *dapm = w->dapm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) struct snd_soc_card *card = dapm->card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) struct tegra_wm8903 *machine = snd_soc_card_get_drvdata(card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) if (!gpio_is_valid(machine->gpio_spkr_en))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) gpio_set_value_cansleep(machine->gpio_spkr_en,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) SND_SOC_DAPM_EVENT_ON(event));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) static int tegra_wm8903_event_hp(struct snd_soc_dapm_widget *w,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) struct snd_kcontrol *k, int event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) struct snd_soc_dapm_context *dapm = w->dapm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) struct snd_soc_card *card = dapm->card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) struct tegra_wm8903 *machine = snd_soc_card_get_drvdata(card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) if (!gpio_is_valid(machine->gpio_hp_mute))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) gpio_set_value_cansleep(machine->gpio_hp_mute,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) !SND_SOC_DAPM_EVENT_ON(event));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) static int tegra_wm8903_event_int_mic(struct snd_soc_dapm_widget *w,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) struct snd_kcontrol *k, int event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) struct snd_soc_dapm_context *dapm = w->dapm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) struct snd_soc_card *card = dapm->card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) struct tegra_wm8903 *machine = snd_soc_card_get_drvdata(card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) if (!gpio_is_valid(machine->gpio_int_mic_en))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) gpio_set_value_cansleep(machine->gpio_int_mic_en,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) SND_SOC_DAPM_EVENT_ON(event));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) static const struct snd_soc_dapm_widget tegra_wm8903_dapm_widgets[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) SND_SOC_DAPM_SPK("Int Spk", tegra_wm8903_event_int_spk),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) SND_SOC_DAPM_HP("Headphone Jack", tegra_wm8903_event_hp),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) SND_SOC_DAPM_MIC("Mic Jack", NULL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) SND_SOC_DAPM_MIC("Int Mic", tegra_wm8903_event_int_mic),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) static const struct snd_kcontrol_new tegra_wm8903_controls[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) SOC_DAPM_PIN_SWITCH("Int Spk"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) SOC_DAPM_PIN_SWITCH("Int Mic"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) static int tegra_wm8903_init(struct snd_soc_pcm_runtime *rtd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) struct snd_soc_component *component = codec_dai->component;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) struct snd_soc_card *card = rtd->card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) struct tegra_wm8903 *machine = snd_soc_card_get_drvdata(card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) int shrt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) if (gpio_is_valid(machine->gpio_hp_det)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) tegra_wm8903_hp_jack_gpio.gpio = machine->gpio_hp_det;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) snd_soc_card_jack_new(rtd->card, "Headphone Jack",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) SND_JACK_HEADPHONE, &tegra_wm8903_hp_jack,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) tegra_wm8903_hp_jack_pins,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) ARRAY_SIZE(tegra_wm8903_hp_jack_pins));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) snd_soc_jack_add_gpios(&tegra_wm8903_hp_jack,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) &tegra_wm8903_hp_jack_gpio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) if (of_property_read_bool(card->dev->of_node, "nvidia,headset"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) shrt = SND_JACK_MICROPHONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) snd_soc_card_jack_new(rtd->card, "Mic Jack", SND_JACK_MICROPHONE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) &tegra_wm8903_mic_jack,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) tegra_wm8903_mic_jack_pins,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) ARRAY_SIZE(tegra_wm8903_mic_jack_pins));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) wm8903_mic_detect(component, &tegra_wm8903_mic_jack, SND_JACK_MICROPHONE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) shrt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) snd_soc_dapm_force_enable_pin(&card->dapm, "MICBIAS");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) static int tegra_wm8903_remove(struct snd_soc_card *card)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) struct snd_soc_pcm_runtime *rtd =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) struct snd_soc_component *component = codec_dai->component;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) wm8903_mic_detect(component, NULL, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) SND_SOC_DAILINK_DEFS(hifi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) DAILINK_COMP_ARRAY(COMP_EMPTY()),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "wm8903-hifi")),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) DAILINK_COMP_ARRAY(COMP_EMPTY()));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) static struct snd_soc_dai_link tegra_wm8903_dai = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) .name = "WM8903",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) .stream_name = "WM8903 PCM",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) .init = tegra_wm8903_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) .ops = &tegra_wm8903_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) .dai_fmt = SND_SOC_DAIFMT_I2S |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) SND_SOC_DAIFMT_NB_NF |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) SND_SOC_DAIFMT_CBS_CFS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) SND_SOC_DAILINK_REG(hifi),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) static struct snd_soc_card snd_soc_tegra_wm8903 = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) .name = "tegra-wm8903",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) .driver_name = "tegra",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) .dai_link = &tegra_wm8903_dai,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) .num_links = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) .remove = tegra_wm8903_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) .controls = tegra_wm8903_controls,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) .num_controls = ARRAY_SIZE(tegra_wm8903_controls),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) .dapm_widgets = tegra_wm8903_dapm_widgets,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) .num_dapm_widgets = ARRAY_SIZE(tegra_wm8903_dapm_widgets),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) .fully_routed = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) static int tegra_wm8903_driver_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) struct device_node *np = pdev->dev.of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) struct snd_soc_card *card = &snd_soc_tegra_wm8903;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) struct tegra_wm8903 *machine;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) machine = devm_kzalloc(&pdev->dev, sizeof(struct tegra_wm8903),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) if (!machine)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) card->dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) snd_soc_card_set_drvdata(card, machine);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) machine->gpio_spkr_en = of_get_named_gpio(np, "nvidia,spkr-en-gpios",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) if (machine->gpio_spkr_en == -EPROBE_DEFER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) return -EPROBE_DEFER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) if (gpio_is_valid(machine->gpio_spkr_en)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) ret = devm_gpio_request_one(&pdev->dev, machine->gpio_spkr_en,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) GPIOF_OUT_INIT_LOW, "spkr_en");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) dev_err(card->dev, "cannot get spkr_en gpio\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) machine->gpio_hp_mute = of_get_named_gpio(np, "nvidia,hp-mute-gpios",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) if (machine->gpio_hp_mute == -EPROBE_DEFER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) return -EPROBE_DEFER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) if (gpio_is_valid(machine->gpio_hp_mute)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) ret = devm_gpio_request_one(&pdev->dev, machine->gpio_hp_mute,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) GPIOF_OUT_INIT_HIGH, "hp_mute");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) dev_err(card->dev, "cannot get hp_mute gpio\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) machine->gpio_hp_det = of_get_named_gpio(np, "nvidia,hp-det-gpios", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) if (machine->gpio_hp_det == -EPROBE_DEFER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) return -EPROBE_DEFER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) machine->gpio_int_mic_en = of_get_named_gpio(np,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) "nvidia,int-mic-en-gpios", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) if (machine->gpio_int_mic_en == -EPROBE_DEFER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) return -EPROBE_DEFER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) if (gpio_is_valid(machine->gpio_int_mic_en)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) /* Disable int mic; enable signal is active-high */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) ret = devm_gpio_request_one(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) machine->gpio_int_mic_en,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) GPIOF_OUT_INIT_LOW, "int_mic_en");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) dev_err(card->dev, "cannot get int_mic_en gpio\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) machine->gpio_ext_mic_en = of_get_named_gpio(np,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) "nvidia,ext-mic-en-gpios", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) if (machine->gpio_ext_mic_en == -EPROBE_DEFER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) return -EPROBE_DEFER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) if (gpio_is_valid(machine->gpio_ext_mic_en)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) /* Enable ext mic; enable signal is active-low */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) ret = devm_gpio_request_one(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) machine->gpio_ext_mic_en,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) GPIOF_OUT_INIT_LOW, "ext_mic_en");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) dev_err(card->dev, "cannot get ext_mic_en gpio\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) ret = snd_soc_of_parse_card_name(card, "nvidia,model");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) ret = snd_soc_of_parse_audio_routing(card, "nvidia,audio-routing");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) tegra_wm8903_dai.codecs->of_node = of_parse_phandle(np,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) "nvidia,audio-codec", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) if (!tegra_wm8903_dai.codecs->of_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) dev_err(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) "Property 'nvidia,audio-codec' missing or invalid\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) tegra_wm8903_dai.cpus->of_node = of_parse_phandle(np,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) "nvidia,i2s-controller", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) if (!tegra_wm8903_dai.cpus->of_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) dev_err(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) "Property 'nvidia,i2s-controller' missing or invalid\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) tegra_wm8903_dai.platforms->of_node = tegra_wm8903_dai.cpus->of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) ret = tegra_asoc_utils_init(&machine->util_data, &pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) ret = devm_snd_soc_register_card(&pdev->dev, card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) dev_err(&pdev->dev, "devm_snd_soc_register_card failed (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) static const struct of_device_id tegra_wm8903_of_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) { .compatible = "nvidia,tegra-audio-wm8903", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) static struct platform_driver tegra_wm8903_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) .name = DRV_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) .pm = &snd_soc_pm_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) .of_match_table = tegra_wm8903_of_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) .probe = tegra_wm8903_driver_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) module_platform_driver(tegra_wm8903_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) MODULE_AUTHOR("Stephen Warren <swarren@nvidia.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) MODULE_DESCRIPTION("Tegra+WM8903 machine ASoC driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) MODULE_ALIAS("platform:" DRV_NAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) MODULE_DEVICE_TABLE(of, tegra_wm8903_of_match);