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