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)  * ASoC driver for PROTO AudioCODEC (with a WM8731)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Author:      Florian Meier, <koalo@koalo.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *	      Copyright 2013
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <sound/core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <sound/pcm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <sound/soc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <sound/jack.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include "../codecs/wm8731.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #define XTAL_RATE 12288000	/* This is fixed on this board */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) static int snd_proto_init(struct snd_soc_pcm_runtime *rtd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	struct snd_soc_card *card = rtd->card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	/* Set proto sysclk */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	int ret = snd_soc_dai_set_sysclk(codec_dai, WM8731_SYSCLK_XTAL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 					 XTAL_RATE, SND_SOC_CLOCK_IN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 		dev_err(card->dev, "Failed to set WM8731 SYSCLK: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 			ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) static const struct snd_soc_dapm_widget snd_proto_widget[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	SND_SOC_DAPM_MIC("Microphone Jack", NULL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	SND_SOC_DAPM_HP("Headphone Jack", NULL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) static const struct snd_soc_dapm_route snd_proto_route[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	/* speaker connected to LHPOUT/RHPOUT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	{"Headphone Jack", NULL, "LHPOUT"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	{"Headphone Jack", NULL, "RHPOUT"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	/* mic is connected to Mic Jack, with WM8731 Mic Bias */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	{"MICIN", NULL, "Mic Bias"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	{"Mic Bias", NULL, "Microphone Jack"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) /* audio machine driver */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) static struct snd_soc_card snd_proto = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	.name		= "snd_mikroe_proto",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	.owner		= THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	.dapm_widgets	= snd_proto_widget,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	.num_dapm_widgets = ARRAY_SIZE(snd_proto_widget),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	.dapm_routes	= snd_proto_route,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	.num_dapm_routes = ARRAY_SIZE(snd_proto_route),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) static int snd_proto_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	struct snd_soc_dai_link *dai;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	struct snd_soc_dai_link_component *comp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	struct device_node *np = pdev->dev.of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	struct device_node *codec_np, *cpu_np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	struct device_node *bitclkmaster = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	struct device_node *framemaster = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	unsigned int dai_fmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	if (!np) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		dev_err(&pdev->dev, "No device node supplied\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	snd_proto.dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	ret = snd_soc_of_parse_card_name(&snd_proto, "model");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	dai = devm_kzalloc(&pdev->dev, sizeof(*dai), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	if (!dai)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	/* for cpus/codecs/platforms */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	comp = devm_kzalloc(&pdev->dev, 3 * sizeof(*comp), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	if (!comp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	snd_proto.dai_link = dai;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	snd_proto.num_links = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	dai->cpus = &comp[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	dai->num_cpus = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	dai->codecs = &comp[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	dai->num_codecs = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	dai->platforms = &comp[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	dai->num_platforms = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	dai->name = "WM8731";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	dai->stream_name = "WM8731 HiFi";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	dai->codecs->dai_name = "wm8731-hifi";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	dai->init = &snd_proto_init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	codec_np = of_parse_phandle(np, "audio-codec", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	if (!codec_np) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		dev_err(&pdev->dev, "audio-codec node missing\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	dai->codecs->of_node = codec_np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	cpu_np = of_parse_phandle(np, "i2s-controller", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	if (!cpu_np) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		dev_err(&pdev->dev, "i2s-controller missing\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	dai->cpus->of_node = cpu_np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	dai->platforms->of_node = cpu_np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	dai_fmt = snd_soc_of_parse_daifmt(np, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 					  &bitclkmaster, &framemaster);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	if (bitclkmaster != framemaster) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		dev_err(&pdev->dev, "Must be the same bitclock and frame master\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	if (bitclkmaster) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		dai_fmt &= ~SND_SOC_DAIFMT_MASTER_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		if (codec_np == bitclkmaster)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 			dai_fmt |= SND_SOC_DAIFMT_CBM_CFM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 			dai_fmt |= SND_SOC_DAIFMT_CBS_CFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	of_node_put(bitclkmaster);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	of_node_put(framemaster);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	dai->dai_fmt = dai_fmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	of_node_put(codec_np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	of_node_put(cpu_np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	ret = snd_soc_register_card(&snd_proto);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	if (ret && ret != -EPROBE_DEFER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		dev_err(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 			"snd_soc_register_card() failed: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^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) static int snd_proto_remove(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	return snd_soc_unregister_card(&snd_proto);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) static const struct of_device_id snd_proto_of_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	{ .compatible = "mikroe,mikroe-proto", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	{},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) MODULE_DEVICE_TABLE(of, snd_proto_of_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) static struct platform_driver snd_proto_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		.name   = "snd-mikroe-proto",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		.of_match_table = snd_proto_of_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	.probe	  = snd_proto_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	.remove	 = snd_proto_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) module_platform_driver(snd_proto_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) MODULE_AUTHOR("Florian Meier");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) MODULE_DESCRIPTION("ASoC Driver for PROTO board (WM8731)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) MODULE_LICENSE("GPL");