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 MIT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) // Copyright (c) 2020 BayLibre, SAS.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) // Author: Jerome Brunet <jbrunet@baylibre.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/of_platform.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <sound/soc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <sound/soc-dai.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include "meson-card.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) struct gx_dai_link_i2s_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 	unsigned int mclk_fs;
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  * Base params for the codec to codec links
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  * Those will be over-written by the CPU side of the link
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) static const struct snd_soc_pcm_stream codec_params = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	.formats = SNDRV_PCM_FMTBIT_S24_LE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	.rate_min = 5525,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	.rate_max = 192000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	.channels_min = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	.channels_max = 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) static int gx_card_i2s_be_hw_params(struct snd_pcm_substream *substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 				    struct snd_pcm_hw_params *params)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	struct meson_card *priv = snd_soc_card_get_drvdata(rtd->card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	struct gx_dai_link_i2s_data *be =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 		(struct gx_dai_link_i2s_data *)priv->link_data[rtd->num];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	return meson_card_i2s_set_sysclk(substream, params, be->mclk_fs);
^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) static const struct snd_soc_ops gx_card_i2s_be_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	.hw_params = gx_card_i2s_be_hw_params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) static int gx_card_parse_i2s(struct snd_soc_card *card,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 			     struct device_node *node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 			     int *index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	struct meson_card *priv = snd_soc_card_get_drvdata(card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	struct snd_soc_dai_link *link = &card->dai_link[*index];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	struct gx_dai_link_i2s_data *be;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	/* Allocate i2s link parameters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	be = devm_kzalloc(card->dev, sizeof(*be), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	if (!be)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	priv->link_data[*index] = be;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	/* Setup i2s link */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	link->ops = &gx_card_i2s_be_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	link->dai_fmt = meson_card_parse_daifmt(node, link->cpus->of_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	of_property_read_u32(node, "mclk-fs", &be->mclk_fs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) static int gx_card_cpu_identify(struct snd_soc_dai_link_component *c,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 				char *match)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	if (of_device_is_compatible(c->of_node, DT_PREFIX "aiu")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		if (strstr(c->dai_name, match))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 			return 1;
^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) 	/* dai not matched */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	return 0;
^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) static int gx_card_add_link(struct snd_soc_card *card, struct device_node *np,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 			    int *index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	struct snd_soc_dai_link *dai_link = &card->dai_link[*index];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	struct snd_soc_dai_link_component *cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	cpu = devm_kzalloc(card->dev, sizeof(*cpu), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	if (!cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	dai_link->cpus = cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	dai_link->num_cpus = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	ret = meson_card_parse_dai(card, np, &dai_link->cpus->of_node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 				   &dai_link->cpus->dai_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	if (gx_card_cpu_identify(dai_link->cpus, "FIFO"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		return  meson_card_set_fe_link(card, dai_link, np, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	ret = meson_card_set_be_link(card, dai_link, np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	/* Or apply codec to codec params if necessary */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	if (gx_card_cpu_identify(dai_link->cpus, "CODEC CTRL")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		dai_link->params = &codec_params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		dai_link->no_pcm = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		snd_soc_dai_link_set_capabilities(dai_link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		/* Check if the cpu is the i2s encoder and parse i2s data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		if (gx_card_cpu_identify(dai_link->cpus, "I2S Encoder"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 			ret = gx_card_parse_i2s(card, np, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) static const struct meson_card_match_data gx_card_match_data = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	.add_link = gx_card_add_link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) static const struct of_device_id gx_card_of_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		.compatible = "amlogic,gx-sound-card",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		.data = &gx_card_match_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	}, {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) MODULE_DEVICE_TABLE(of, gx_card_of_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) static struct platform_driver gx_card_pdrv = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	.probe = meson_card_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	.remove = meson_card_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		.name = "gx-sound-card",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		.of_match_table = gx_card_of_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) module_platform_driver(gx_card_pdrv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) MODULE_DESCRIPTION("Amlogic GX ALSA machine driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) MODULE_AUTHOR("Jerome Brunet <jbrunet@baylibre.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) MODULE_LICENSE("GPL v2");