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
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) // Freescale P1022DS ALSA SoC Machine driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) // Author: Timur Tabi <timur@freescale.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) // Copyright 2010 Freescale Semiconductor, Inc.
^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/fsl/guts.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/of_address.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) #include <linux/slab.h>
^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 "fsl_dma.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include "fsl_ssi.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include "fsl_utils.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) /* P1022-specific PMUXCR and DMUXCR bit definitions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #define CCSR_GUTS_PMUXCR_UART0_I2C1_MASK	0x0001c000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #define CCSR_GUTS_PMUXCR_UART0_I2C1_UART0_SSI	0x00010000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #define CCSR_GUTS_PMUXCR_UART0_I2C1_SSI		0x00018000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #define CCSR_GUTS_PMUXCR_SSI_DMA_TDM_MASK	0x00000c00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #define CCSR_GUTS_PMUXCR_SSI_DMA_TDM_SSI	0x00000000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #define CCSR_GUTS_DMUXCR_PAD	1	/* DMA controller/channel set to pad */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #define CCSR_GUTS_DMUXCR_SSI	2	/* DMA controller/channel set to SSI */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  * Set the DMACR register in the GUTS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36)  * The DMACR register determines the source of initiated transfers for each
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37)  * channel on each DMA controller.  Rather than have a bunch of repetitive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)  * macros for the bit patterns, we just have a function that calculates
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39)  * them.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41)  * guts: Pointer to GUTS structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42)  * co: The DMA controller (0 or 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43)  * ch: The channel on the DMA controller (0, 1, 2, or 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44)  * device: The device to set as the target (CCSR_GUTS_DMUXCR_xxx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) static inline void guts_set_dmuxcr(struct ccsr_guts __iomem *guts,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	unsigned int co, unsigned int ch, unsigned int device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	unsigned int shift = 16 + (8 * (1 - co) + 2 * (3 - ch));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	clrsetbits_be32(&guts->dmuxcr, 3 << shift, device << shift);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) /* There's only one global utilities register */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) static phys_addr_t guts_phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58)  * machine_data: machine-specific ASoC device data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60)  * This structure contains data for a single sound platform device on an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61)  * P1022 DS.  Some of the data is taken from the device tree.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) struct machine_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	struct snd_soc_dai_link dai[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	struct snd_soc_card card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	unsigned int dai_format;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	unsigned int codec_clk_direction;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	unsigned int cpu_clk_direction;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	unsigned int clk_frequency;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	unsigned int ssi_id;		/* 0 = SSI1, 1 = SSI2, etc */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	unsigned int dma_id[2];		/* 0 = DMA1, 1 = DMA2, etc */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	unsigned int dma_channel_id[2]; /* 0 = ch 0, 1 = ch 1, etc*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	char platform_name[2][DAI_NAME_SIZE]; /* One for each DMA channel */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77)  * p1022_ds_machine_probe: initialize the board
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79)  * This function is used to initialize the board-specific hardware.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81)  * Here we program the DMACR and PMUXCR registers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) static int p1022_ds_machine_probe(struct snd_soc_card *card)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	struct machine_data *mdata =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		container_of(card, struct machine_data, card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	struct ccsr_guts __iomem *guts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	guts = ioremap(guts_phys, sizeof(struct ccsr_guts));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	if (!guts) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		dev_err(card->dev, "could not map global utilities\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	/* Enable SSI Tx signal */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	clrsetbits_be32(&guts->pmuxcr, CCSR_GUTS_PMUXCR_UART0_I2C1_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 			CCSR_GUTS_PMUXCR_UART0_I2C1_UART0_SSI);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	/* Enable SSI Rx signal */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	clrsetbits_be32(&guts->pmuxcr, CCSR_GUTS_PMUXCR_SSI_DMA_TDM_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 			CCSR_GUTS_PMUXCR_SSI_DMA_TDM_SSI);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	/* Enable DMA Channel for SSI */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	guts_set_dmuxcr(guts, mdata->dma_id[0], mdata->dma_channel_id[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 			CCSR_GUTS_DMUXCR_SSI);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	guts_set_dmuxcr(guts, mdata->dma_id[1], mdata->dma_channel_id[1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 			CCSR_GUTS_DMUXCR_SSI);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	iounmap(guts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	return 0;
^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) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)  * p1022_ds_startup: program the board with various hardware parameters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)  * This function takes board-specific information, like clock frequencies
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)  * and serial data formats, and passes that information to the codec and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)  * transport drivers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) static int p1022_ds_startup(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	struct machine_data *mdata =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		container_of(rtd->card, struct machine_data, card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	struct device *dev = rtd->card->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	/* Tell the codec driver what the serial protocol is. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	ret = snd_soc_dai_set_fmt(asoc_rtd_to_codec(rtd, 0), mdata->dai_format);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		dev_err(dev, "could not set codec driver audio format\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	 * Tell the codec driver what the MCLK frequency is, and whether it's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	 * a slave or master.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	ret = snd_soc_dai_set_sysclk(asoc_rtd_to_codec(rtd, 0), 0, mdata->clk_frequency,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 				     mdata->codec_clk_direction);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		dev_err(dev, "could not set codec driver clock params\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	return 0;
^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) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)  * p1022_ds_machine_remove: Remove the sound device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)  * This function is called to remove the sound device for one SSI.  We
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)  * de-program the DMACR and PMUXCR register.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) static int p1022_ds_machine_remove(struct snd_soc_card *card)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	struct machine_data *mdata =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		container_of(card, struct machine_data, card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	struct ccsr_guts __iomem *guts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	guts = ioremap(guts_phys, sizeof(struct ccsr_guts));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	if (!guts) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		dev_err(card->dev, "could not map global utilities\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		return -ENOMEM;
^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) 	/* Restore the signal routing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	clrbits32(&guts->pmuxcr, CCSR_GUTS_PMUXCR_UART0_I2C1_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	clrbits32(&guts->pmuxcr, CCSR_GUTS_PMUXCR_SSI_DMA_TDM_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	guts_set_dmuxcr(guts, mdata->dma_id[0], mdata->dma_channel_id[0], 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	guts_set_dmuxcr(guts, mdata->dma_id[1], mdata->dma_channel_id[1], 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	iounmap(guts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)  * p1022_ds_ops: ASoC machine driver operations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) static const struct snd_soc_ops p1022_ds_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	.startup = p1022_ds_startup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)  * p1022_ds_probe: platform probe function for the machine driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)  * Although this is a machine driver, the SSI node is the "master" node with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)  * respect to audio hardware connections.  Therefore, we create a new ASoC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)  * device for each new SSI node that has a codec attached.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) static int p1022_ds_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	struct device *dev = pdev->dev.parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	/* ssi_pdev is the platform device for the SSI node that probed us */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	struct platform_device *ssi_pdev = to_platform_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	struct device_node *np = ssi_pdev->dev.of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	struct device_node *codec_np = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	struct machine_data *mdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	struct snd_soc_dai_link_component *comp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	int ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	const char *sprop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	const u32 *iprop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	/* Find the codec node for this SSI. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	codec_np = of_parse_phandle(np, "codec-handle", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	if (!codec_np) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		dev_err(dev, "could not find codec node\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	mdata = kzalloc(sizeof(struct machine_data), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	if (!mdata) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		goto error_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	comp = devm_kzalloc(&pdev->dev, 6 * sizeof(*comp), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	if (!comp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		goto error_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	mdata->dai[0].cpus	= &comp[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	mdata->dai[0].codecs	= &comp[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	mdata->dai[0].platforms	= &comp[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	mdata->dai[0].num_cpus		= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	mdata->dai[0].num_codecs	= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	mdata->dai[0].num_platforms	= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	mdata->dai[1].cpus	= &comp[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	mdata->dai[1].codecs	= &comp[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	mdata->dai[1].platforms	= &comp[5];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	mdata->dai[1].num_cpus		= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	mdata->dai[1].num_codecs	= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	mdata->dai[1].num_platforms	= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	mdata->dai[0].cpus->dai_name = dev_name(&ssi_pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	mdata->dai[0].ops = &p1022_ds_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	/* ASoC core can match codec with device node */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	mdata->dai[0].codecs->of_node = codec_np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	/* We register two DAIs per SSI, one for playback and the other for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	 * capture.  We support codecs that have separate DAIs for both playback
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	 * and capture.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	memcpy(&mdata->dai[1], &mdata->dai[0], sizeof(struct snd_soc_dai_link));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	/* The DAI names from the codec (snd_soc_dai_driver.name) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	mdata->dai[0].codecs->dai_name = "wm8776-hifi-playback";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	mdata->dai[1].codecs->dai_name = "wm8776-hifi-capture";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	/* Get the device ID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	iprop = of_get_property(np, "cell-index", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	if (!iprop) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 		dev_err(&pdev->dev, "cell-index property not found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 		goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	mdata->ssi_id = be32_to_cpup(iprop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	/* Get the serial format and clock direction. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	sprop = of_get_property(np, "fsl,mode", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	if (!sprop) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 		dev_err(&pdev->dev, "fsl,mode property not found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 		goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	if (strcasecmp(sprop, "i2s-slave") == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 		mdata->dai_format = SND_SOC_DAIFMT_NB_NF |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 			SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBM_CFM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 		mdata->codec_clk_direction = SND_SOC_CLOCK_OUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 		mdata->cpu_clk_direction = SND_SOC_CLOCK_IN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 		/* In i2s-slave mode, the codec has its own clock source, so we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 		 * need to get the frequency from the device tree and pass it to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 		 * the codec driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 		iprop = of_get_property(codec_np, "clock-frequency", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 		if (!iprop || !*iprop) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 			dev_err(&pdev->dev, "codec bus-frequency "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 				"property is missing or invalid\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 			ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 			goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 		mdata->clk_frequency = be32_to_cpup(iprop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	} else if (strcasecmp(sprop, "i2s-master") == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 		mdata->dai_format = SND_SOC_DAIFMT_NB_NF |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 			SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBS_CFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 		mdata->codec_clk_direction = SND_SOC_CLOCK_IN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 		mdata->cpu_clk_direction = SND_SOC_CLOCK_OUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	} else if (strcasecmp(sprop, "lj-slave") == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 		mdata->dai_format = SND_SOC_DAIFMT_NB_NF |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 			SND_SOC_DAIFMT_LEFT_J | SND_SOC_DAIFMT_CBM_CFM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 		mdata->codec_clk_direction = SND_SOC_CLOCK_OUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 		mdata->cpu_clk_direction = SND_SOC_CLOCK_IN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	} else if (strcasecmp(sprop, "lj-master") == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		mdata->dai_format = SND_SOC_DAIFMT_NB_NF |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 			SND_SOC_DAIFMT_LEFT_J | SND_SOC_DAIFMT_CBS_CFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 		mdata->codec_clk_direction = SND_SOC_CLOCK_IN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 		mdata->cpu_clk_direction = SND_SOC_CLOCK_OUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	} else if (strcasecmp(sprop, "rj-slave") == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 		mdata->dai_format = SND_SOC_DAIFMT_NB_NF |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 			SND_SOC_DAIFMT_RIGHT_J | SND_SOC_DAIFMT_CBM_CFM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 		mdata->codec_clk_direction = SND_SOC_CLOCK_OUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 		mdata->cpu_clk_direction = SND_SOC_CLOCK_IN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	} else if (strcasecmp(sprop, "rj-master") == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 		mdata->dai_format = SND_SOC_DAIFMT_NB_NF |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 			SND_SOC_DAIFMT_RIGHT_J | SND_SOC_DAIFMT_CBS_CFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 		mdata->codec_clk_direction = SND_SOC_CLOCK_IN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 		mdata->cpu_clk_direction = SND_SOC_CLOCK_OUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	} else if (strcasecmp(sprop, "ac97-slave") == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 		mdata->dai_format = SND_SOC_DAIFMT_NB_NF |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 			SND_SOC_DAIFMT_AC97 | SND_SOC_DAIFMT_CBM_CFM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 		mdata->codec_clk_direction = SND_SOC_CLOCK_OUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 		mdata->cpu_clk_direction = SND_SOC_CLOCK_IN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	} else if (strcasecmp(sprop, "ac97-master") == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 		mdata->dai_format = SND_SOC_DAIFMT_NB_NF |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 			SND_SOC_DAIFMT_AC97 | SND_SOC_DAIFMT_CBS_CFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 		mdata->codec_clk_direction = SND_SOC_CLOCK_IN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 		mdata->cpu_clk_direction = SND_SOC_CLOCK_OUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 		dev_err(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 			"unrecognized fsl,mode property '%s'\n", sprop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 		ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 		goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	if (!mdata->clk_frequency) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 		dev_err(&pdev->dev, "unknown clock frequency\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 		ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 		goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	/* Find the playback DMA channel to use. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	mdata->dai[0].platforms->name = mdata->platform_name[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	ret = fsl_asoc_get_dma_channel(np, "fsl,playback-dma", &mdata->dai[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 				       &mdata->dma_channel_id[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 				       &mdata->dma_id[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 		dev_err(&pdev->dev, "missing/invalid playback DMA phandle\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 		goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	/* Find the capture DMA channel to use. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	mdata->dai[1].platforms->name = mdata->platform_name[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	ret = fsl_asoc_get_dma_channel(np, "fsl,capture-dma", &mdata->dai[1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 				       &mdata->dma_channel_id[1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 				       &mdata->dma_id[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 		dev_err(&pdev->dev, "missing/invalid capture DMA phandle\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 		goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	/* Initialize our DAI data structure.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	mdata->dai[0].stream_name = "playback";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	mdata->dai[1].stream_name = "capture";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	mdata->dai[0].name = mdata->dai[0].stream_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	mdata->dai[1].name = mdata->dai[1].stream_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	mdata->card.probe = p1022_ds_machine_probe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	mdata->card.remove = p1022_ds_machine_remove;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	mdata->card.name = pdev->name; /* The platform driver name */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	mdata->card.owner = THIS_MODULE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	mdata->card.dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	mdata->card.num_links = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	mdata->card.dai_link = mdata->dai;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	/* Register with ASoC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	ret = snd_soc_register_card(&mdata->card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 		dev_err(&pdev->dev, "could not register card\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 		goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	of_node_put(codec_np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	kfree(mdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) error_put:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	of_node_put(codec_np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395)  * p1022_ds_remove: remove the platform device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397)  * This function is called when the platform device is removed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) static int p1022_ds_remove(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	struct snd_soc_card *card = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	struct machine_data *mdata =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 		container_of(card, struct machine_data, card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	snd_soc_unregister_card(card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	kfree(mdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) static struct platform_driver p1022_ds_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	.probe = p1022_ds_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	.remove = p1022_ds_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 		 * The name must match 'compatible' property in the device tree,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 		 * in lowercase letters.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 		.name = "snd-soc-p1022ds",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424)  * p1022_ds_init: machine driver initialization.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426)  * This function is called when this module is loaded.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) static int __init p1022_ds_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	struct device_node *guts_np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 	struct resource res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	/* Get the physical address of the global utilities registers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	guts_np = of_find_compatible_node(NULL, NULL, "fsl,p1022-guts");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	if (of_address_to_resource(guts_np, 0, &res)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 		pr_err("snd-soc-p1022ds: missing/invalid global utils node\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 		of_node_put(guts_np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	guts_phys = res.start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	of_node_put(guts_np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	return platform_driver_register(&p1022_ds_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447)  * p1022_ds_exit: machine driver exit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449)  * This function is called when this driver is unloaded.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) static void __exit p1022_ds_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	platform_driver_unregister(&p1022_ds_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) module_init(p1022_ds_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) module_exit(p1022_ds_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) MODULE_AUTHOR("Timur Tabi <timur@freescale.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) MODULE_DESCRIPTION("Freescale P1022 DS ALSA SoC machine driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) MODULE_LICENSE("GPL v2");