2019-05-29 23:57:50 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2011-01-08 05:36:16 +00:00
|
|
|
/*
|
2011-04-12 17:40:36 +00:00
|
|
|
* tegra_wm8903.c - Tegra machine ASoC driver for boards using WM8903 codec.
|
2011-01-08 05:36:16 +00:00
|
|
|
*
|
|
|
|
* Author: Stephen Warren <swarren@nvidia.com>
|
2012-03-20 20:55:49 +00:00
|
|
|
* Copyright (C) 2010-2012 - NVIDIA, Inc.
|
2011-01-08 05:36:16 +00:00
|
|
|
*
|
|
|
|
* Based on code copyright/by:
|
|
|
|
*
|
|
|
|
* (c) 2009, 2010 Nvidia Graphics Pvt. Ltd.
|
|
|
|
*
|
|
|
|
* Copyright 2007 Wolfson Microelectronics PLC.
|
|
|
|
* Author: Graeme Gregory
|
|
|
|
* graeme.gregory@wolfsonmicro.com or linux@wolfsonmicro.com
|
|
|
|
*/
|
|
|
|
|
2021-05-29 15:46:47 +00:00
|
|
|
#include <linux/gpio/consumer.h>
|
|
|
|
#include <linux/of.h>
|
2011-01-08 05:36:16 +00:00
|
|
|
#include <linux/module.h>
|
2011-01-28 21:26:36 +00:00
|
|
|
#include <linux/platform_device.h>
|
2011-01-28 21:26:37 +00:00
|
|
|
|
2011-01-08 05:36:16 +00:00
|
|
|
#include <sound/core.h>
|
2011-02-03 20:56:13 +00:00
|
|
|
#include <sound/jack.h>
|
2011-01-08 05:36:16 +00:00
|
|
|
#include <sound/soc.h>
|
|
|
|
|
2011-02-10 22:37:16 +00:00
|
|
|
#include "../codecs/wm8903.h"
|
|
|
|
|
2021-05-29 15:46:47 +00:00
|
|
|
#include "tegra_asoc_machine.h"
|
2011-01-08 05:36:16 +00:00
|
|
|
|
2021-05-29 15:46:47 +00:00
|
|
|
static struct snd_soc_jack_pin tegra_wm8903_mic_jack_pins[] = {
|
|
|
|
{ .pin = "Mic Jack", .mask = SND_JACK_MICROPHONE },
|
2011-01-28 21:26:36 +00:00
|
|
|
};
|
2011-01-08 05:36:16 +00:00
|
|
|
|
2021-05-29 15:46:47 +00:00
|
|
|
static unsigned int tegra_wm8903_mclk_rate(unsigned int srate)
|
2011-01-08 05:36:16 +00:00
|
|
|
{
|
2021-05-29 15:46:47 +00:00
|
|
|
unsigned int mclk;
|
2011-01-08 05:36:16 +00:00
|
|
|
|
|
|
|
switch (srate) {
|
|
|
|
case 64000:
|
|
|
|
case 88200:
|
|
|
|
case 96000:
|
|
|
|
mclk = 128 * srate;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
mclk = 256 * srate;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* FIXME: Codec only requires >= 3MHz if OSR==0 */
|
|
|
|
while (mclk < 6000000)
|
|
|
|
mclk *= 2;
|
|
|
|
|
2021-05-29 15:46:47 +00:00
|
|
|
return mclk;
|
2011-01-08 05:36:16 +00:00
|
|
|
}
|
|
|
|
|
2021-05-29 15:46:47 +00:00
|
|
|
static int tegra_wm8903_init(struct snd_soc_pcm_runtime *rtd)
|
2020-03-20 20:55:04 +00:00
|
|
|
{
|
2021-05-29 15:46:47 +00:00
|
|
|
struct tegra_machine *machine = snd_soc_card_get_drvdata(rtd->card);
|
|
|
|
struct snd_soc_card *card = rtd->card;
|
|
|
|
int err;
|
2020-03-20 20:55:04 +00:00
|
|
|
|
2021-05-29 15:46:47 +00:00
|
|
|
/*
|
|
|
|
* Older version of machine driver was ignoring GPIO polarity,
|
|
|
|
* forcing it to active-low. This means that all older device-trees
|
|
|
|
* which set the polarity to active-high are wrong and we need to fix
|
|
|
|
* them up.
|
|
|
|
*/
|
|
|
|
if (machine->asoc->hp_jack_gpio_active_low) {
|
|
|
|
bool active_low = gpiod_is_active_low(machine->gpiod_hp_det);
|
2020-03-20 20:55:04 +00:00
|
|
|
|
2021-05-29 15:46:47 +00:00
|
|
|
machine->hp_jack_gpio->invert = !active_low;
|
|
|
|
}
|
2020-03-20 20:55:04 +00:00
|
|
|
|
2021-05-29 15:46:47 +00:00
|
|
|
err = tegra_asoc_machine_init(rtd);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2011-01-13 22:22:08 +00:00
|
|
|
|
2021-05-29 15:46:47 +00:00
|
|
|
if (!machine->gpiod_mic_det && machine->asoc->add_mic_jack) {
|
|
|
|
struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
|
|
|
|
struct snd_soc_component *component = codec_dai->component;
|
|
|
|
int shrt = 0;
|
|
|
|
|
|
|
|
err = snd_soc_card_jack_new(rtd->card, "Mic Jack",
|
|
|
|
SND_JACK_MICROPHONE,
|
|
|
|
machine->mic_jack,
|
|
|
|
tegra_wm8903_mic_jack_pins,
|
|
|
|
ARRAY_SIZE(tegra_wm8903_mic_jack_pins));
|
|
|
|
if (err) {
|
|
|
|
dev_err(rtd->dev, "Mic Jack creation failed: %d\n", err);
|
|
|
|
return err;
|
|
|
|
}
|
2011-02-03 20:56:14 +00:00
|
|
|
|
2021-05-29 15:46:47 +00:00
|
|
|
if (of_property_read_bool(card->dev->of_node, "nvidia,headset"))
|
|
|
|
shrt = SND_JACK_MICROPHONE;
|
2011-02-10 22:37:18 +00:00
|
|
|
|
2021-05-29 15:46:47 +00:00
|
|
|
wm8903_mic_detect(component, machine->mic_jack,
|
|
|
|
SND_JACK_MICROPHONE, shrt);
|
2011-04-12 17:40:39 +00:00
|
|
|
}
|
2011-02-03 20:56:13 +00:00
|
|
|
|
2015-04-03 11:04:07 +00:00
|
|
|
snd_soc_dapm_force_enable_pin(&card->dapm, "MICBIAS");
|
2011-02-10 22:37:16 +00:00
|
|
|
|
2011-01-13 22:22:08 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-06-11 17:27:19 +00:00
|
|
|
static int tegra_wm8903_remove(struct snd_soc_card *card)
|
|
|
|
{
|
2021-05-29 15:46:47 +00:00
|
|
|
struct snd_soc_dai_link *link = &card->dai_link[0];
|
|
|
|
struct snd_soc_pcm_runtime *rtd = snd_soc_get_pcm_runtime(card, link);
|
2020-03-23 05:21:07 +00:00
|
|
|
struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
|
2018-01-29 03:05:11 +00:00
|
|
|
struct snd_soc_component *component = codec_dai->component;
|
ASoC: tegra: free jack GPIOs before the sound card is freed
snd_soc_jack_add_gpios() schedules a work queue item to poll the GPIO to
generate an initial jack status report. If sound card initialization
fails, that work item needs to be cancelled, so it doesn't run after the
card has been freed. Specifically, freeing the card calls
snd_jack_dev_free() which calls snd_jack_dev_disconnect() which sets
jack->input_dev = NULL, and input_dev is used by snd_jack_report(), which
is called from the work queue item.
snd_soc_jack_free_gpios() cancels the work item. The Tegra ASoC machine
drivers do call this function in the platform driver remove() callback.
However, this happens after the sound card is freed, at least when the
card is freed due to errors late during snd_soc_instantiate_card(). This
leaves a window where the work item can execute after the card is freed.
In next-20140522, sound card initialization does fail for unrelated
reasons, and hits the problem described above.
To solve this, fix the Tegra ASoC machine drivers to clean up the Jack
GPIOs during the snd_soc_card's .remove() callback, which is executed
before the overall card object is freed. also, gGuard the cleanup call
based on whether we actually setup up the GPIOs in the first place.
Ideally, we'd do the cleanup in a struct snd_soc_dai_link .fini/remove
function to match where the GPIOs get set up. However, there is no such
callback.
This change fixes all Tegra machine drivers. By code inspection, I
believe some non-Tegra machine drivers have the same issue. I'll send a
patch for that separately, once this is reviewed.
Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Mark Brown <broonie@linaro.org>
2014-05-22 22:14:53 +00:00
|
|
|
|
2018-01-29 03:05:11 +00:00
|
|
|
wm8903_mic_detect(component, NULL, 0, 0);
|
2012-06-11 17:27:19 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-06-06 04:19:01 +00:00
|
|
|
SND_SOC_DAILINK_DEFS(hifi,
|
|
|
|
DAILINK_COMP_ARRAY(COMP_EMPTY()),
|
2019-06-28 01:49:06 +00:00
|
|
|
DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "wm8903-hifi")),
|
|
|
|
DAILINK_COMP_ARRAY(COMP_EMPTY()));
|
2019-06-06 04:19:01 +00:00
|
|
|
|
2011-04-12 17:40:36 +00:00
|
|
|
static struct snd_soc_dai_link tegra_wm8903_dai = {
|
2011-01-08 05:36:16 +00:00
|
|
|
.name = "WM8903",
|
|
|
|
.stream_name = "WM8903 PCM",
|
2011-04-12 17:40:36 +00:00
|
|
|
.init = tegra_wm8903_init,
|
2012-06-06 23:15:48 +00:00
|
|
|
.dai_fmt = SND_SOC_DAIFMT_I2S |
|
|
|
|
SND_SOC_DAIFMT_NB_NF |
|
|
|
|
SND_SOC_DAIFMT_CBS_CFS,
|
2019-06-06 04:19:01 +00:00
|
|
|
SND_SOC_DAILINK_REG(hifi),
|
2011-01-08 05:36:16 +00:00
|
|
|
};
|
|
|
|
|
2011-04-12 17:40:36 +00:00
|
|
|
static struct snd_soc_card snd_soc_tegra_wm8903 = {
|
2021-05-29 15:46:48 +00:00
|
|
|
.components = "codec:wm8903",
|
2011-12-22 13:23:01 +00:00
|
|
|
.owner = THIS_MODULE,
|
2011-04-12 17:40:36 +00:00
|
|
|
.dai_link = &tegra_wm8903_dai,
|
2011-01-08 05:36:16 +00:00
|
|
|
.num_links = 1,
|
2012-06-11 17:27:19 +00:00
|
|
|
.remove = tegra_wm8903_remove,
|
2011-11-23 19:42:05 +00:00
|
|
|
.fully_routed = true,
|
2011-01-08 05:36:16 +00:00
|
|
|
};
|
|
|
|
|
2021-05-29 15:46:47 +00:00
|
|
|
/* older device-trees used wrong polarity for the headphones-detection GPIO */
|
|
|
|
static const struct tegra_asoc_data tegra_wm8903_data_legacy = {
|
|
|
|
.mclk_rate = tegra_wm8903_mclk_rate,
|
|
|
|
.card = &snd_soc_tegra_wm8903,
|
|
|
|
.hp_jack_gpio_active_low = true,
|
|
|
|
.add_common_dapm_widgets = true,
|
|
|
|
.add_common_controls = true,
|
|
|
|
.add_common_snd_ops = true,
|
|
|
|
.add_mic_jack = true,
|
|
|
|
.add_hp_jack = true,
|
|
|
|
};
|
2011-01-08 05:36:16 +00:00
|
|
|
|
2021-05-29 15:46:47 +00:00
|
|
|
static const struct tegra_asoc_data tegra_wm8903_data = {
|
|
|
|
.mclk_rate = tegra_wm8903_mclk_rate,
|
|
|
|
.card = &snd_soc_tegra_wm8903,
|
|
|
|
.add_common_dapm_widgets = true,
|
|
|
|
.add_common_controls = true,
|
|
|
|
.add_common_snd_ops = true,
|
|
|
|
.add_mic_jack = true,
|
|
|
|
.add_hp_jack = true,
|
|
|
|
};
|
2011-01-08 05:36:16 +00:00
|
|
|
|
2012-11-19 18:25:33 +00:00
|
|
|
static const struct of_device_id tegra_wm8903_of_match[] = {
|
2021-05-29 15:46:47 +00:00
|
|
|
{ .compatible = "ad,tegra-audio-plutux", .data = &tegra_wm8903_data_legacy },
|
|
|
|
{ .compatible = "ad,tegra-audio-wm8903-medcom-wide", .data = &tegra_wm8903_data_legacy },
|
|
|
|
{ .compatible = "ad,tegra-audio-wm8903-tec", .data = &tegra_wm8903_data_legacy },
|
|
|
|
{ .compatible = "nvidia,tegra-audio-wm8903-cardhu", .data = &tegra_wm8903_data_legacy },
|
|
|
|
{ .compatible = "nvidia,tegra-audio-wm8903-harmony", .data = &tegra_wm8903_data_legacy },
|
|
|
|
{ .compatible = "nvidia,tegra-audio-wm8903-picasso", .data = &tegra_wm8903_data_legacy },
|
|
|
|
{ .compatible = "nvidia,tegra-audio-wm8903-seaboard", .data = &tegra_wm8903_data_legacy },
|
|
|
|
{ .compatible = "nvidia,tegra-audio-wm8903-ventana", .data = &tegra_wm8903_data_legacy },
|
|
|
|
{ .compatible = "nvidia,tegra-audio-wm8903", .data = &tegra_wm8903_data },
|
2011-12-12 22:55:36 +00:00
|
|
|
{},
|
|
|
|
};
|
2021-05-29 15:46:47 +00:00
|
|
|
MODULE_DEVICE_TABLE(of, tegra_wm8903_of_match);
|
2011-12-12 22:55:36 +00:00
|
|
|
|
2011-04-12 17:40:36 +00:00
|
|
|
static struct platform_driver tegra_wm8903_driver = {
|
2011-01-28 21:26:36 +00:00
|
|
|
.driver = {
|
2021-05-29 15:46:47 +00:00
|
|
|
.name = "tegra-wm8903",
|
2011-12-12 22:55:36 +00:00
|
|
|
.of_match_table = tegra_wm8903_of_match,
|
2021-05-29 15:46:47 +00:00
|
|
|
.pm = &snd_soc_pm_ops,
|
2011-01-28 21:26:36 +00:00
|
|
|
},
|
2021-05-29 15:46:47 +00:00
|
|
|
.probe = tegra_asoc_machine_probe,
|
2011-01-28 21:26:36 +00:00
|
|
|
};
|
2011-11-23 01:21:20 +00:00
|
|
|
module_platform_driver(tegra_wm8903_driver);
|
2011-01-08 05:36:16 +00:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Stephen Warren <swarren@nvidia.com>");
|
2011-04-12 17:40:36 +00:00
|
|
|
MODULE_DESCRIPTION("Tegra+WM8903 machine ASoC driver");
|
2011-01-08 05:36:16 +00:00
|
|
|
MODULE_LICENSE("GPL");
|