Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^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_wm8753.c - Tegra machine ASoC driver for boards using WM8753 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/wm8753.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-wm8753"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) struct tegra_wm8753 {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	struct tegra_asoc_utils_data util_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) static int tegra_wm8753_hw_params(struct snd_pcm_substream *substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 					struct snd_pcm_hw_params *params)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	struct snd_soc_card *card = rtd->card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	struct tegra_wm8753 *machine = snd_soc_card_get_drvdata(card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	int srate, mclk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	srate = params_rate(params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	switch (srate) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	case 11025:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	case 22050:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	case 44100:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	case 88200:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 		mclk = 11289600;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		mclk = 12288000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	err = tegra_asoc_utils_set_rate(&machine->util_data, srate, mclk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 		dev_err(card->dev, "Can't configure clocks\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	err = snd_soc_dai_set_sysclk(codec_dai, WM8753_MCLK, mclk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 					SND_SOC_CLOCK_IN);
^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, "codec_dai clock not set\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) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) static const struct snd_soc_ops tegra_wm8753_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	.hw_params = tegra_wm8753_hw_params,
^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) static const struct snd_soc_dapm_widget tegra_wm8753_dapm_widgets[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	SND_SOC_DAPM_HP("Headphone Jack", NULL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	SND_SOC_DAPM_MIC("Mic Jack", NULL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) SND_SOC_DAILINK_DEFS(pcm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	DAILINK_COMP_ARRAY(COMP_EMPTY()),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "wm8753-hifi")),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	DAILINK_COMP_ARRAY(COMP_EMPTY()));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) static struct snd_soc_dai_link tegra_wm8753_dai = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	.name = "WM8753",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	.stream_name = "WM8753 PCM",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	.ops = &tegra_wm8753_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	.dai_fmt = SND_SOC_DAIFMT_I2S |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 			SND_SOC_DAIFMT_NB_NF |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 			SND_SOC_DAIFMT_CBS_CFS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	SND_SOC_DAILINK_REG(pcm),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) static struct snd_soc_card snd_soc_tegra_wm8753 = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	.name = "tegra-wm8753",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	.driver_name = "tegra",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	.owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	.dai_link = &tegra_wm8753_dai,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	.num_links = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	.dapm_widgets = tegra_wm8753_dapm_widgets,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	.num_dapm_widgets = ARRAY_SIZE(tegra_wm8753_dapm_widgets),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	.fully_routed = true,
^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_wm8753_driver_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	struct device_node *np = pdev->dev.of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	struct snd_soc_card *card = &snd_soc_tegra_wm8753;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	struct tegra_wm8753 *machine;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	machine = devm_kzalloc(&pdev->dev, sizeof(struct tegra_wm8753),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 			       GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	if (!machine)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	card->dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	snd_soc_card_set_drvdata(card, machine);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	ret = snd_soc_of_parse_card_name(card, "nvidia,model");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	ret = snd_soc_of_parse_audio_routing(card, "nvidia,audio-routing");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	tegra_wm8753_dai.codecs->of_node = of_parse_phandle(np,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 			"nvidia,audio-codec", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	if (!tegra_wm8753_dai.codecs->of_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		dev_err(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 			"Property 'nvidia,audio-codec' missing or invalid\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	tegra_wm8753_dai.cpus->of_node = of_parse_phandle(np,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 			"nvidia,i2s-controller", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	if (!tegra_wm8753_dai.cpus->of_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		dev_err(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 			"Property 'nvidia,i2s-controller' missing or invalid\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	tegra_wm8753_dai.platforms->of_node = tegra_wm8753_dai.cpus->of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	ret = tegra_asoc_utils_init(&machine->util_data, &pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	ret = devm_snd_soc_register_card(&pdev->dev, card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 			ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	return 0;
^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 of_device_id tegra_wm8753_of_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	{ .compatible = "nvidia,tegra-audio-wm8753", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	{},
^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 struct platform_driver tegra_wm8753_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		.name = DRV_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		.pm = &snd_soc_pm_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 		.of_match_table = tegra_wm8753_of_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	.probe = tegra_wm8753_driver_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) module_platform_driver(tegra_wm8753_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) MODULE_AUTHOR("Stephen Warren <swarren@nvidia.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) MODULE_DESCRIPTION("Tegra+WM8753 machine ASoC driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) MODULE_ALIAS("platform:" DRV_NAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) MODULE_DEVICE_TABLE(of, tegra_wm8753_of_match);