^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * ALSA SoC SPDIF In Audio Layer for spear processors
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (C) 2012 ST Microelectronics
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Vipin Kumar <vipin.kumar@st.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * This file is licensed under the terms of the GNU General Public
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * License version 2. This program is licensed "as is" without any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * warranty of any kind, whether express or implied.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/clk.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/ioport.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <sound/dmaengine_pcm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <sound/pcm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <sound/pcm_params.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <sound/soc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <sound/spear_dma.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <sound/spear_spdif.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include "spdif_in_regs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include "spear_pcm.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) struct spdif_in_params {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) u32 format;
^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) struct spdif_in_dev {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) struct clk *clk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) struct spear_dma_data dma_params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) struct spdif_in_params saved_params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) void *io_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) struct device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) void (*reset_perip)(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) int irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) struct snd_dmaengine_dai_dma_data dma_params_rx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) struct snd_dmaengine_pcm_config config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) static void spdif_in_configure(struct spdif_in_dev *host)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) u32 ctrl = SPDIF_IN_PRTYEN | SPDIF_IN_STATEN | SPDIF_IN_USREN |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) SPDIF_IN_VALEN | SPDIF_IN_BLKEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) ctrl |= SPDIF_MODE_16BIT | SPDIF_FIFO_THRES_16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) writel(ctrl, host->io_base + SPDIF_IN_CTRL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) writel(0xF, host->io_base + SPDIF_IN_IRQ_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) static int spdif_in_dai_probe(struct snd_soc_dai *dai)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) struct spdif_in_dev *host = snd_soc_dai_get_drvdata(dai);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) host->dma_params_rx.filter_data = &host->dma_params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) dai->capture_dma_data = &host->dma_params_rx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) static void spdif_in_shutdown(struct snd_pcm_substream *substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) struct snd_soc_dai *dai)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) struct spdif_in_dev *host = snd_soc_dai_get_drvdata(dai);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) if (substream->stream != SNDRV_PCM_STREAM_CAPTURE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) writel(0x0, host->io_base + SPDIF_IN_IRQ_MASK);
^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) static void spdif_in_format(struct spdif_in_dev *host, u32 format)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) u32 ctrl = readl(host->io_base + SPDIF_IN_CTRL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) switch (format) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) case SNDRV_PCM_FORMAT_S16_LE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) ctrl |= SPDIF_XTRACT_16BIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) case SNDRV_PCM_FORMAT_IEC958_SUBFRAME_LE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) ctrl &= ~SPDIF_XTRACT_16BIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) writel(ctrl, host->io_base + SPDIF_IN_CTRL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) static int spdif_in_hw_params(struct snd_pcm_substream *substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) struct snd_pcm_hw_params *params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) struct snd_soc_dai *dai)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) struct spdif_in_dev *host = snd_soc_dai_get_drvdata(dai);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) u32 format;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) if (substream->stream != SNDRV_PCM_STREAM_CAPTURE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) format = params_format(params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) host->saved_params.format = format;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) static int spdif_in_trigger(struct snd_pcm_substream *substream, int cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) struct snd_soc_dai *dai)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) struct spdif_in_dev *host = snd_soc_dai_get_drvdata(dai);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) u32 ctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) if (substream->stream != SNDRV_PCM_STREAM_CAPTURE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) case SNDRV_PCM_TRIGGER_START:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) case SNDRV_PCM_TRIGGER_RESUME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) clk_enable(host->clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) spdif_in_configure(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) spdif_in_format(host, host->saved_params.format);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) ctrl = readl(host->io_base + SPDIF_IN_CTRL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) ctrl |= SPDIF_IN_SAMPLE | SPDIF_IN_ENB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) writel(ctrl, host->io_base + SPDIF_IN_CTRL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) writel(0xF, host->io_base + SPDIF_IN_IRQ_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) case SNDRV_PCM_TRIGGER_STOP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) case SNDRV_PCM_TRIGGER_SUSPEND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) ctrl = readl(host->io_base + SPDIF_IN_CTRL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) ctrl &= ~(SPDIF_IN_SAMPLE | SPDIF_IN_ENB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) writel(ctrl, host->io_base + SPDIF_IN_CTRL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) writel(0x0, host->io_base + SPDIF_IN_IRQ_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) if (host->reset_perip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) host->reset_perip();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) clk_disable(host->clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) static const struct snd_soc_dai_ops spdif_in_dai_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) .shutdown = spdif_in_shutdown,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) .trigger = spdif_in_trigger,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) .hw_params = spdif_in_hw_params,
^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) static struct snd_soc_dai_driver spdif_in_dai = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) .probe = spdif_in_dai_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) .capture = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) .channels_min = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) .channels_max = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) .rates = (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000 | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) SNDRV_PCM_RATE_192000),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) .formats = SNDRV_PCM_FMTBIT_S16_LE | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) .ops = &spdif_in_dai_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) static const struct snd_soc_component_driver spdif_in_component = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) .name = "spdif-in",
^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) static irqreturn_t spdif_in_irq(int irq, void *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) struct spdif_in_dev *host = (struct spdif_in_dev *)arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) u32 irq_status = readl(host->io_base + SPDIF_IN_IRQ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) if (!irq_status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) return IRQ_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) if (irq_status & SPDIF_IRQ_FIFOWRITE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) dev_err(host->dev, "spdif in: fifo write error");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) if (irq_status & SPDIF_IRQ_EMPTYFIFOREAD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) dev_err(host->dev, "spdif in: empty fifo read error");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) if (irq_status & SPDIF_IRQ_FIFOFULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) dev_err(host->dev, "spdif in: fifo full error");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) if (irq_status & SPDIF_IRQ_OUTOFRANGE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) dev_err(host->dev, "spdif in: out of range error");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) writel(0, host->io_base + SPDIF_IN_IRQ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) static int spdif_in_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) struct spdif_in_dev *host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) struct spear_spdif_platform_data *pdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) struct resource *res_fifo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) void __iomem *io_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) io_base = devm_platform_ioremap_resource(pdev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) if (IS_ERR(io_base))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) return PTR_ERR(io_base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) res_fifo = platform_get_resource(pdev, IORESOURCE_IO, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) if (!res_fifo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) host = devm_kzalloc(&pdev->dev, sizeof(*host), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) if (!host)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) host->io_base = io_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) host->irq = platform_get_irq(pdev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) if (host->irq < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) dev_warn(&pdev->dev, "failed to get IRQ: %d\n", host->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) return host->irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) host->clk = devm_clk_get(&pdev->dev, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) if (IS_ERR(host->clk))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) return PTR_ERR(host->clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) pdata = dev_get_platdata(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) if (!pdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) host->dma_params.data = pdata->dma_params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) host->dma_params.addr = res_fifo->start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) host->dma_params.max_burst = 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) host->dma_params.addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) host->reset_perip = pdata->reset_perip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) host->dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) dev_set_drvdata(&pdev->dev, host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) ret = devm_request_irq(&pdev->dev, host->irq, spdif_in_irq, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) "spdif-in", host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) dev_warn(&pdev->dev, "request_irq failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) ret = devm_snd_soc_register_component(&pdev->dev, &spdif_in_component,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) &spdif_in_dai, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) return devm_spear_pcm_platform_register(&pdev->dev, &host->config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) pdata->filter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) static struct platform_driver spdif_in_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) .probe = spdif_in_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) .name = "spdif-in",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) module_platform_driver(spdif_in_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) MODULE_AUTHOR("Vipin Kumar <vipin.kumar@st.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) MODULE_DESCRIPTION("SPEAr SPDIF IN SoC Interface");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) MODULE_ALIAS("platform:spdif_in");