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)  * Copyright (C) STMicroelectronics SA 2015
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Authors: Arnaud Pouliquen <arnaud.pouliquen@st.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *          for STMicroelectronics.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/pinctrl/consumer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include "uniperif.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  * User frame size shall be 2, 4, 6 or 8 32-bits words length
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  * (i.e. 8, 16, 24 or 32 bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  * This constraint comes from allowed values for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  * UNIPERIF_I2S_FMT_NUM_CH register
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #define UNIPERIF_MAX_FRAME_SZ 0x20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #define UNIPERIF_ALLOWED_FRAME_SZ (0x08 | 0x10 | 0x18 | UNIPERIF_MAX_FRAME_SZ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) struct sti_uniperiph_dev_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	unsigned int id; /* Nb available player instances */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	unsigned int version; /* player IP version */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	unsigned int stream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	const char *dai_names;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	enum uniperif_type type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) static const struct sti_uniperiph_dev_data sti_uniplayer_hdmi = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	.id = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	.version = SND_ST_UNIPERIF_VERSION_UNI_PLR_TOP_1_0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	.stream = SNDRV_PCM_STREAM_PLAYBACK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	.dai_names = "Uni Player #0 (HDMI)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	.type = SND_ST_UNIPERIF_TYPE_HDMI
^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 const struct sti_uniperiph_dev_data sti_uniplayer_pcm_out = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	.id = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	.version = SND_ST_UNIPERIF_VERSION_UNI_PLR_TOP_1_0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	.stream = SNDRV_PCM_STREAM_PLAYBACK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	.dai_names = "Uni Player #1 (PCM OUT)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	.type = SND_ST_UNIPERIF_TYPE_PCM | SND_ST_UNIPERIF_TYPE_TDM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) static const struct sti_uniperiph_dev_data sti_uniplayer_dac = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	.id = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	.version = SND_ST_UNIPERIF_VERSION_UNI_PLR_TOP_1_0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	.stream = SNDRV_PCM_STREAM_PLAYBACK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	.dai_names = "Uni Player #2 (DAC)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	.type = SND_ST_UNIPERIF_TYPE_PCM,
^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 sti_uniperiph_dev_data sti_uniplayer_spdif = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	.id = 3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	.version = SND_ST_UNIPERIF_VERSION_UNI_PLR_TOP_1_0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	.stream = SNDRV_PCM_STREAM_PLAYBACK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	.dai_names = "Uni Player #3 (SPDIF)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	.type = SND_ST_UNIPERIF_TYPE_SPDIF
^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 const struct sti_uniperiph_dev_data sti_unireader_pcm_in = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	.id = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	.version = SND_ST_UNIPERIF_VERSION_UNI_RDR_1_0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	.stream = SNDRV_PCM_STREAM_CAPTURE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	.dai_names = "Uni Reader #0 (PCM IN)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	.type = SND_ST_UNIPERIF_TYPE_PCM | SND_ST_UNIPERIF_TYPE_TDM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) static const struct sti_uniperiph_dev_data sti_unireader_hdmi_in = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	.id = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	.version = SND_ST_UNIPERIF_VERSION_UNI_RDR_1_0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	.stream = SNDRV_PCM_STREAM_CAPTURE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	.dai_names = "Uni Reader #1 (HDMI IN)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	.type = SND_ST_UNIPERIF_TYPE_PCM,
^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 const struct of_device_id snd_soc_sti_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	{ .compatible = "st,stih407-uni-player-hdmi",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	  .data = &sti_uniplayer_hdmi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	{ .compatible = "st,stih407-uni-player-pcm-out",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	  .data = &sti_uniplayer_pcm_out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	{ .compatible = "st,stih407-uni-player-dac",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	  .data = &sti_uniplayer_dac
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	{ .compatible = "st,stih407-uni-player-spdif",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	  .data = &sti_uniplayer_spdif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	{ .compatible = "st,stih407-uni-reader-pcm_in",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	  .data = &sti_unireader_pcm_in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	{ .compatible = "st,stih407-uni-reader-hdmi",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	  .data = &sti_unireader_hdmi_in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	{},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) int  sti_uniperiph_reset(struct uniperif *uni)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	int count = 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	/* Reset uniperipheral uni */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	SET_UNIPERIF_SOFT_RST_SOFT_RST(uni);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	if (uni->ver < SND_ST_UNIPERIF_VERSION_UNI_PLR_TOP_1_0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		while (GET_UNIPERIF_SOFT_RST_SOFT_RST(uni) && count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 			udelay(5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 			count--;
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	if (!count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		dev_err(uni->dev, "Failed to reset uniperif\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	return 0;
^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) int sti_uniperiph_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 			       unsigned int rx_mask, int slots,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 			       int slot_width)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	struct sti_uniperiph_data *priv = snd_soc_dai_get_drvdata(dai);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	struct uniperif *uni = priv->dai_data.uni;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	int i, frame_size, avail_slots;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	if (!UNIPERIF_TYPE_IS_TDM(uni)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		dev_err(uni->dev, "cpu dai not in tdm mode\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	/* store info in unip context */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	uni->tdm_slot.slots = slots;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	uni->tdm_slot.slot_width = slot_width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	/* unip is unidirectionnal */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	uni->tdm_slot.mask = (tx_mask != 0) ? tx_mask : rx_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	/* number of available timeslots */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	for (i = 0, avail_slots = 0; i < uni->tdm_slot.slots; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		if ((uni->tdm_slot.mask >> i) & 0x01)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 			avail_slots++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	uni->tdm_slot.avail_slots = avail_slots;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	/* frame size in bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	frame_size = uni->tdm_slot.avail_slots * uni->tdm_slot.slot_width / 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	/* check frame size is allowed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	if ((frame_size > UNIPERIF_MAX_FRAME_SZ) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	    (frame_size & ~(int)UNIPERIF_ALLOWED_FRAME_SZ)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		dev_err(uni->dev, "frame size not allowed: %d bytes\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 			frame_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		return -EINVAL;
^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) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) int sti_uniperiph_fix_tdm_chan(struct snd_pcm_hw_params *params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 			       struct snd_pcm_hw_rule *rule)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	struct uniperif *uni = rule->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	struct snd_interval t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	t.min = uni->tdm_slot.avail_slots;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	t.max = uni->tdm_slot.avail_slots;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	t.openmin = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	t.openmax = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	t.integer = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	return snd_interval_refine(hw_param_interval(params, rule->var), &t);
^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) int sti_uniperiph_fix_tdm_format(struct snd_pcm_hw_params *params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 				 struct snd_pcm_hw_rule *rule)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	struct uniperif *uni = rule->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	struct snd_mask *maskp = hw_param_mask(params, rule->var);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	u64 format;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	switch (uni->tdm_slot.slot_width) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	case 16:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		format = SNDRV_PCM_FMTBIT_S16_LE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	case 32:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		format = SNDRV_PCM_FMTBIT_S32_LE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		dev_err(uni->dev, "format not supported: %d bits\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 			uni->tdm_slot.slot_width);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	maskp->bits[0] &= (u_int32_t)format;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	maskp->bits[1] &= (u_int32_t)(format >> 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	/* clear remaining indexes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	memset(maskp->bits + 2, 0, (SNDRV_MASK_MAX - 64) / 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	if (!maskp->bits[0] && !maskp->bits[1])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) int sti_uniperiph_get_tdm_word_pos(struct uniperif *uni,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 				   unsigned int *word_pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	int slot_width = uni->tdm_slot.slot_width / 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	int slots_num = uni->tdm_slot.slots;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	unsigned int slots_mask = uni->tdm_slot.mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	int i, j, k;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	unsigned int word16_pos[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	/* word16_pos:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	 * word16_pos[0] = WORDX_LSB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	 * word16_pos[1] = WORDX_MSB,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	 * word16_pos[2] = WORDX+1_LSB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	 * word16_pos[3] = WORDX+1_MSB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	/* set unip word position */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	for (i = 0, j = 0, k = 0; (i < slots_num) && (k < WORD_MAX); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		if ((slots_mask >> i) & 0x01) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 			word16_pos[j] = i * slot_width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 			if (slot_width == 4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 				word16_pos[j + 1] = word16_pos[j] + 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 				j++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 			j++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 			if (j > 3) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 				word_pos[k] = word16_pos[1] |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 					      (word16_pos[0] << 8) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 					      (word16_pos[3] << 16) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 					      (word16_pos[2] << 24);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 				j = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 				k++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)  * sti_uniperiph_dai_create_ctrl
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)  * This function is used to create Ctrl associated to DAI but also pcm device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)  * Request is done by front end to associate ctrl with pcm device id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) static int sti_uniperiph_dai_create_ctrl(struct snd_soc_dai *dai)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	struct sti_uniperiph_data *priv = snd_soc_dai_get_drvdata(dai);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	struct uniperif *uni = priv->dai_data.uni;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	struct snd_kcontrol_new *ctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	if (!uni->num_ctrls)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	for (i = 0; i < uni->num_ctrls; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		 * Several Control can have same name. Controls are indexed on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 		 * Uniperipheral instance ID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 		ctrl = &uni->snd_ctrls[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 		ctrl->index = uni->id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		ctrl->device = uni->id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	return snd_soc_add_dai_controls(dai, uni->snd_ctrls, uni->num_ctrls);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)  * DAI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) int sti_uniperiph_dai_hw_params(struct snd_pcm_substream *substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 				struct snd_pcm_hw_params *params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 				struct snd_soc_dai *dai)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	struct sti_uniperiph_data *priv = snd_soc_dai_get_drvdata(dai);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	struct uniperif *uni = priv->dai_data.uni;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	struct snd_dmaengine_dai_dma_data *dma_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	int transfer_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	if (uni->type == SND_ST_UNIPERIF_TYPE_TDM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 		/* transfer size = user frame size (in 32-bits FIFO cell) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 		transfer_size = snd_soc_params_to_frame_size(params) / 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 		transfer_size = params_channels(params) * UNIPERIF_FIFO_FRAMES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	dma_data = snd_soc_dai_get_dma_data(dai, substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	dma_data->maxburst = transfer_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) int sti_uniperiph_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	struct sti_uniperiph_data *priv = snd_soc_dai_get_drvdata(dai);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	priv->dai_data.uni->daifmt = fmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) static int sti_uniperiph_suspend(struct snd_soc_component *component)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	struct sti_uniperiph_data *priv = snd_soc_component_get_drvdata(component);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	struct uniperif *uni = priv->dai_data.uni;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	/* The uniperipheral should be in stopped state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	if (uni->state != UNIPERIF_STATE_STOPPED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 		dev_err(uni->dev, "%s: invalid uni state( %d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 			__func__, (int)uni->state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 		return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	/* Pinctrl: switch pinstate to sleep */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	ret = pinctrl_pm_select_sleep_state(uni->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 		dev_err(uni->dev, "%s: failed to select pinctrl state\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 			__func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) static int sti_uniperiph_resume(struct snd_soc_component *component)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	struct sti_uniperiph_data *priv = snd_soc_component_get_drvdata(component);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	struct uniperif *uni = priv->dai_data.uni;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	if (priv->dai_data.stream == SNDRV_PCM_STREAM_PLAYBACK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 		ret = uni_player_resume(uni);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	/* pinctrl: switch pinstate to default */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	ret = pinctrl_pm_select_default_state(uni->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 		dev_err(uni->dev, "%s: failed to select pinctrl state\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 			__func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) static int sti_uniperiph_dai_probe(struct snd_soc_dai *dai)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	struct sti_uniperiph_data *priv = snd_soc_dai_get_drvdata(dai);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	struct sti_uniperiph_dai *dai_data = &priv->dai_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	/* DMA settings*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	if (priv->dai_data.stream == SNDRV_PCM_STREAM_PLAYBACK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 		snd_soc_dai_init_dma_data(dai, &dai_data->dma_data, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 		snd_soc_dai_init_dma_data(dai, NULL, &dai_data->dma_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	dai_data->dma_data.addr = dai_data->uni->fifo_phys_address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	dai_data->dma_data.addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	return sti_uniperiph_dai_create_ctrl(dai);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) static const struct snd_soc_dai_driver sti_uniperiph_dai_template = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	.probe = sti_uniperiph_dai_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) static const struct snd_soc_component_driver sti_uniperiph_dai_component = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	.name = "sti_cpu_dai",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	.suspend = sti_uniperiph_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	.resume = sti_uniperiph_resume
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) static int sti_uniperiph_cpu_dai_of(struct device_node *node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 				    struct sti_uniperiph_data *priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	struct device *dev = &priv->pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	struct sti_uniperiph_dai *dai_data = &priv->dai_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	struct snd_soc_dai_driver *dai = priv->dai;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	struct snd_soc_pcm_stream *stream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	struct uniperif *uni;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	const struct of_device_id *of_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	const struct sti_uniperiph_dev_data *dev_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	const char *mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	/* Populate data structure depending on compatibility */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	of_id = of_match_node(snd_soc_sti_match, node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	if (!of_id->data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 		dev_err(dev, "data associated to device is missing\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	dev_data = (struct sti_uniperiph_dev_data *)of_id->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	uni = devm_kzalloc(dev, sizeof(*uni), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	if (!uni)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	uni->id = dev_data->id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	uni->ver = dev_data->version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	*dai = sti_uniperiph_dai_template;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	dai->name = dev_data->dai_names;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	/* Get resources */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	uni->mem_region = platform_get_resource(priv->pdev, IORESOURCE_MEM, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	if (!uni->mem_region) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 		dev_err(dev, "Failed to get memory resource\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	uni->base = devm_ioremap_resource(dev, uni->mem_region);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 	if (IS_ERR(uni->base))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 		return PTR_ERR(uni->base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 	uni->fifo_phys_address = uni->mem_region->start +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 				     UNIPERIF_FIFO_DATA_OFFSET(uni);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	uni->irq = platform_get_irq(priv->pdev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	if (uni->irq < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 		return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 	uni->type = dev_data->type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	/* check if player should be configured for tdm */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	if (dev_data->type & SND_ST_UNIPERIF_TYPE_TDM) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 		if (!of_property_read_string(node, "st,tdm-mode", &mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 			uni->type = SND_ST_UNIPERIF_TYPE_TDM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 			uni->type = SND_ST_UNIPERIF_TYPE_PCM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	dai_data->uni = uni;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	dai_data->stream = dev_data->stream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	if (priv->dai_data.stream == SNDRV_PCM_STREAM_PLAYBACK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 		ret = uni_player_init(priv->pdev, uni);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 		stream = &dai->playback;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 		ret = uni_reader_init(priv->pdev, uni);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 		stream = &dai->capture;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	dai->ops = uni->dai_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	stream->stream_name = dai->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	stream->channels_min = uni->hw->channels_min;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	stream->channels_max = uni->hw->channels_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	stream->rates = uni->hw->rates;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	stream->formats = uni->hw->formats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) static const struct snd_dmaengine_pcm_config dmaengine_pcm_config = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	.prepare_slave_config = snd_dmaengine_pcm_prepare_slave_config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) static int sti_uniperiph_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	struct sti_uniperiph_data *priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 	struct device_node *node = pdev->dev.of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 	/* Allocate the private data and the CPU_DAI array */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 	priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 	if (!priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 	priv->dai = devm_kzalloc(&pdev->dev, sizeof(*priv->dai), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 	if (!priv->dai)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 	priv->pdev = pdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 	ret = sti_uniperiph_cpu_dai_of(node, priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 	dev_set_drvdata(&pdev->dev, priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 	ret = devm_snd_soc_register_component(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 					      &sti_uniperiph_dai_component,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 					      priv->dai, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 	return devm_snd_dmaengine_pcm_register(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 					       &dmaengine_pcm_config, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) static struct platform_driver sti_uniperiph_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 		.name = "sti-uniperiph-dai",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 		.of_match_table = snd_soc_sti_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 	.probe = sti_uniperiph_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) module_platform_driver(sti_uniperiph_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) MODULE_DESCRIPTION("uniperipheral DAI driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) MODULE_AUTHOR("Arnaud Pouliquen <arnaud.pouliquen@st.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) MODULE_LICENSE("GPL v2");