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-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * atmel_wm8904 - Atmel ASoC driver for boards with WM8904 codec.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2012 Atmel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Author: Bo Shen <voice.shen@atmel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/clk.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/of_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <sound/soc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include "../codecs/wm8904.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include "atmel_ssc_dai.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) static const struct snd_soc_dapm_widget atmel_asoc_wm8904_dapm_widgets[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	SND_SOC_DAPM_HP("Headphone Jack", NULL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	SND_SOC_DAPM_MIC("Mic", NULL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	SND_SOC_DAPM_LINE("Line In Jack", NULL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) static int atmel_asoc_wm8904_hw_params(struct snd_pcm_substream *substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 		struct snd_pcm_hw_params *params)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	ret = snd_soc_dai_set_pll(codec_dai, WM8904_FLL_MCLK, WM8904_FLL_MCLK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 		32768, params_rate(params) * 256);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 		pr_err("%s - failed to set wm8904 codec PLL.", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	 * As here wm8904 use FLL output as its system clock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	 * so calling set_sysclk won't care freq parameter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	 * then we pass 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	ret = snd_soc_dai_set_sysclk(codec_dai, WM8904_CLK_FLL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 			0, SND_SOC_CLOCK_IN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 		pr_err("%s -failed to set wm8904 SYSCLK\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) static const struct snd_soc_ops atmel_asoc_wm8904_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	.hw_params = atmel_asoc_wm8904_hw_params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) SND_SOC_DAILINK_DEFS(pcm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	DAILINK_COMP_ARRAY(COMP_EMPTY()),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "wm8904-hifi")),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	DAILINK_COMP_ARRAY(COMP_EMPTY()));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) static struct snd_soc_dai_link atmel_asoc_wm8904_dailink = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	.name = "WM8904",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	.stream_name = "WM8904 PCM",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	.dai_fmt = SND_SOC_DAIFMT_I2S
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		| SND_SOC_DAIFMT_NB_NF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		| SND_SOC_DAIFMT_CBM_CFM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	.ops = &atmel_asoc_wm8904_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	SND_SOC_DAILINK_REG(pcm),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) static struct snd_soc_card atmel_asoc_wm8904_card = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	.name = "atmel_asoc_wm8904",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	.owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	.dai_link = &atmel_asoc_wm8904_dailink,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	.num_links = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	.dapm_widgets = atmel_asoc_wm8904_dapm_widgets,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	.num_dapm_widgets = ARRAY_SIZE(atmel_asoc_wm8904_dapm_widgets),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	.fully_routed = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) static int atmel_asoc_wm8904_dt_init(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	struct device_node *np = pdev->dev.of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	struct device_node *codec_np, *cpu_np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	struct snd_soc_card *card = &atmel_asoc_wm8904_card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	struct snd_soc_dai_link *dailink = &atmel_asoc_wm8904_dailink;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	if (!np) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		dev_err(&pdev->dev, "only device tree supported\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		return -EINVAL;
^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) 	ret = snd_soc_of_parse_card_name(card, "atmel,model");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		dev_err(&pdev->dev, "failed to parse card name\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	ret = snd_soc_of_parse_audio_routing(card, "atmel,audio-routing");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		dev_err(&pdev->dev, "failed to parse audio routing\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	cpu_np = of_parse_phandle(np, "atmel,ssc-controller", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	if (!cpu_np) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		dev_err(&pdev->dev, "failed to get dai and pcm info\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	dailink->cpus->of_node = cpu_np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	dailink->platforms->of_node = cpu_np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	of_node_put(cpu_np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	codec_np = of_parse_phandle(np, "atmel,audio-codec", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	if (!codec_np) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		dev_err(&pdev->dev, "failed to get codec info\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	dailink->codecs->of_node = codec_np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	of_node_put(codec_np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) static int atmel_asoc_wm8904_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	struct snd_soc_card *card = &atmel_asoc_wm8904_card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	struct snd_soc_dai_link *dailink = &atmel_asoc_wm8904_dailink;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	int id, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	card->dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	ret = atmel_asoc_wm8904_dt_init(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		dev_err(&pdev->dev, "failed to init dt info\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	id = of_alias_get_id((struct device_node *)dailink->cpus->of_node, "ssc");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	ret = atmel_ssc_set_audio(id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	if (ret != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		dev_err(&pdev->dev, "failed to set SSC %d for audio\n", id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	ret = snd_soc_register_card(card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		dev_err(&pdev->dev, "snd_soc_register_card failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		goto err_set_audio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) err_set_audio:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	atmel_ssc_put_audio(id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) static int atmel_asoc_wm8904_remove(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	struct snd_soc_card *card = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	struct snd_soc_dai_link *dailink = &atmel_asoc_wm8904_dailink;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	int id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	id = of_alias_get_id((struct device_node *)dailink->cpus->of_node, "ssc");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	snd_soc_unregister_card(card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	atmel_ssc_put_audio(id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) #ifdef CONFIG_OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) static const struct of_device_id atmel_asoc_wm8904_dt_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	{ .compatible = "atmel,asoc-wm8904", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	{ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) MODULE_DEVICE_TABLE(of, atmel_asoc_wm8904_dt_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) static struct platform_driver atmel_asoc_wm8904_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		.name = "atmel-wm8904-audio",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		.of_match_table = of_match_ptr(atmel_asoc_wm8904_dt_ids),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		.pm		= &snd_soc_pm_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	.probe = atmel_asoc_wm8904_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	.remove = atmel_asoc_wm8904_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) module_platform_driver(atmel_asoc_wm8904_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) /* Module information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) MODULE_AUTHOR("Bo Shen <voice.shen@atmel.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) MODULE_DESCRIPTION("ALSA SoC machine driver for Atmel EK with WM8904 codec");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) MODULE_LICENSE("GPL");