On Tue, May 18, 2021 at 03:13:56AM +0300, Dmitry Osipenko wrote: > Squash all machine drivers into a single-universal one. This reduces > code duplication, eases addition of a new drivers and upgrades older > code to a modern Linux kernel APIs. Nice, I never understood why each codec needed it's own machine driver (and typically in turn compatible string). > > Suggested-by: Jonathan Hunter <jonathanh@xxxxxxxxxx> > Co-developed-by: Ion Agorria <ion@xxxxxxxxxxx> > Signed-off-by: Ion Agorria <ion@xxxxxxxxxxx> > Co-developed-by: Svyatoslav Ryhel <clamor95@xxxxxxxxx> > Signed-off-by: Svyatoslav Ryhel <clamor95@xxxxxxxxx> > Signed-off-by: Dmitry Osipenko <digetx@xxxxxxxxx> > --- [...] > diff --git a/sound/soc/tegra/tegra_wm8903.c b/sound/soc/tegra/tegra_wm8903.c > index e4863fa37b0c..fdf74bfd728e 100644 > --- a/sound/soc/tegra/tegra_wm8903.c > +++ b/sound/soc/tegra/tegra_wm8903.c > @@ -14,192 +14,80 @@ > * graeme.gregory@xxxxxxxxxxxxxxxx or linux@xxxxxxxxxxxxxxxx > */ > > +#include <linux/gpio/consumer.h> > +#include <linux/of.h> > #include <linux/module.h> > #include <linux/platform_device.h> > -#include <linux/slab.h> > -#include <linux/gpio.h> > -#include <linux/of_gpio.h> > > #include <sound/core.h> > #include <sound/jack.h> > -#include <sound/pcm.h> > -#include <sound/pcm_params.h> > #include <sound/soc.h> > > #include "../codecs/wm8903.h" > > -#include "tegra_asoc_utils.h" > +#include "tegra_asoc_machine.h" > > -#define DRV_NAME "tegra-snd-wm8903" > +static struct snd_soc_jack_pin tegra_wm8903_mic_jack_pins[] = { > + { .pin = "Mic Jack", .mask = SND_JACK_MICROPHONE }, > +}; > > -struct tegra_wm8903 { > - int gpio_spkr_en; > - int gpio_hp_det; > - int gpio_hp_mute; > - int gpio_int_mic_en; > - int gpio_ext_mic_en; > - struct tegra_asoc_utils_data util_data; > +static const char * const tegra_active_low_hp_compats[] = { > + "ad,tegra-audio-plutux", > + "ad,tegra-audio-wm8903-medcom-wide", > + "ad,tegra-audio-wm8903-tec", > + "nvidia,tegra-audio-wm8903-cardhu", > + "nvidia,tegra-audio-wm8903-harmony", > + "nvidia,tegra-audio-wm8903-picasso", > + "nvidia,tegra-audio-wm8903-seaboard", > + "nvidia,tegra-audio-wm8903-ventana", > + NULL, I think this list should be added to the main match table below with data having a flag for active low HP. Then you only match once, don't need the exported function and the next difference is much easier to add. > }; > > -static int tegra_wm8903_hw_params(struct snd_pcm_substream *substream, > - struct snd_pcm_hw_params *params) > +static int tegra_wm8903_init(struct snd_soc_pcm_runtime *rtd) > { > - struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); > - struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0); > + struct tegra_machine *machine = snd_soc_card_get_drvdata(rtd->card); > + struct device_node *np = rtd->card->dev->of_node; > struct snd_soc_card *card = rtd->card; > - struct tegra_wm8903 *machine = snd_soc_card_get_drvdata(card); > - int srate, mclk; > int err; > > - srate = params_rate(params); > - 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; > + /* > + * 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 > + * up them. > + */ > + if (of_device_compatible_match(np, tegra_active_low_hp_compats)) { > + bool active_low = gpiod_is_active_low(machine->gpiod_hp_det); [...] > +static const struct tegra_asoc_data tegra_wm8903_data = { > + .mclk_rate = tegra_asoc_machine_mclk_rate, > + .card = &snd_soc_tegra_wm8903, > + .add_common_dapm_widgets = true, > + .add_common_controls = true, > + .add_common_soc_ops = true, > + .add_mic_jack = true, > + .add_hp_jack = true, > +}; > > static const struct of_device_id tegra_wm8903_of_match[] = { > - { .compatible = "nvidia,tegra-audio-wm8903", }, > + { .compatible = "nvidia,tegra-audio-wm8903", .data = &tegra_wm8903_data }, > {}, > }; > +MODULE_DEVICE_TABLE(of, tegra_wm8903_of_match); > > static struct platform_driver tegra_wm8903_driver = { > .driver = { > - .name = DRV_NAME, > - .pm = &snd_soc_pm_ops, > + .name = "tegra-wm8903", > .of_match_table = tegra_wm8903_of_match, > + .pm = &snd_soc_pm_ops, > }, > - .probe = tegra_wm8903_driver_probe, > + .probe = tegra_asoc_machine_probe, > }; > module_platform_driver(tegra_wm8903_driver); > > MODULE_AUTHOR("Stephen Warren <swarren@xxxxxxxxxx>"); > MODULE_DESCRIPTION("Tegra+WM8903 machine ASoC driver"); > MODULE_LICENSE("GPL"); > -MODULE_ALIAS("platform:" DRV_NAME); > -MODULE_DEVICE_TABLE(of, tegra_wm8903_of_match);