1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * ALSA SoC Audio Layer - Rockchip SPDIF_RX Controller driver
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * Copyright (C) 2018 Fuzhou Rockchip Electronics Co., Ltd
6*4882a593Smuzhiyun *
7*4882a593Smuzhiyun */
8*4882a593Smuzhiyun
9*4882a593Smuzhiyun #include <linux/module.h>
10*4882a593Smuzhiyun #include <linux/delay.h>
11*4882a593Smuzhiyun #include <linux/of_gpio.h>
12*4882a593Smuzhiyun #include <linux/clk.h>
13*4882a593Smuzhiyun #include <linux/pm_runtime.h>
14*4882a593Smuzhiyun #include <linux/mfd/syscon.h>
15*4882a593Smuzhiyun #include <linux/regmap.h>
16*4882a593Smuzhiyun #include <linux/reset.h>
17*4882a593Smuzhiyun #include <sound/pcm_params.h>
18*4882a593Smuzhiyun #include <sound/dmaengine_pcm.h>
19*4882a593Smuzhiyun
20*4882a593Smuzhiyun #include "rockchip_spdifrx.h"
21*4882a593Smuzhiyun
22*4882a593Smuzhiyun struct rk_spdifrx_dev {
23*4882a593Smuzhiyun struct device *dev;
24*4882a593Smuzhiyun struct clk *mclk;
25*4882a593Smuzhiyun struct clk *hclk;
26*4882a593Smuzhiyun struct snd_dmaengine_dai_dma_data capture_dma_data;
27*4882a593Smuzhiyun struct regmap *regmap;
28*4882a593Smuzhiyun struct reset_control *reset;
29*4882a593Smuzhiyun int irq;
30*4882a593Smuzhiyun };
31*4882a593Smuzhiyun
rk_spdifrx_runtime_suspend(struct device * dev)32*4882a593Smuzhiyun static int rk_spdifrx_runtime_suspend(struct device *dev)
33*4882a593Smuzhiyun {
34*4882a593Smuzhiyun struct rk_spdifrx_dev *spdifrx = dev_get_drvdata(dev);
35*4882a593Smuzhiyun
36*4882a593Smuzhiyun clk_disable_unprepare(spdifrx->mclk);
37*4882a593Smuzhiyun clk_disable_unprepare(spdifrx->hclk);
38*4882a593Smuzhiyun
39*4882a593Smuzhiyun return 0;
40*4882a593Smuzhiyun }
41*4882a593Smuzhiyun
rk_spdifrx_runtime_resume(struct device * dev)42*4882a593Smuzhiyun static int rk_spdifrx_runtime_resume(struct device *dev)
43*4882a593Smuzhiyun {
44*4882a593Smuzhiyun struct rk_spdifrx_dev *spdifrx = dev_get_drvdata(dev);
45*4882a593Smuzhiyun int ret;
46*4882a593Smuzhiyun
47*4882a593Smuzhiyun ret = clk_prepare_enable(spdifrx->mclk);
48*4882a593Smuzhiyun if (ret) {
49*4882a593Smuzhiyun dev_err(spdifrx->dev, "mclk clock enable failed %d\n", ret);
50*4882a593Smuzhiyun return ret;
51*4882a593Smuzhiyun }
52*4882a593Smuzhiyun
53*4882a593Smuzhiyun ret = clk_prepare_enable(spdifrx->hclk);
54*4882a593Smuzhiyun if (ret) {
55*4882a593Smuzhiyun dev_err(spdifrx->dev, "hclk clock enable failed %d\n", ret);
56*4882a593Smuzhiyun return ret;
57*4882a593Smuzhiyun }
58*4882a593Smuzhiyun
59*4882a593Smuzhiyun return 0;
60*4882a593Smuzhiyun }
61*4882a593Smuzhiyun
rk_spdifrx_hw_params(struct snd_pcm_substream * substream,struct snd_pcm_hw_params * params,struct snd_soc_dai * dai)62*4882a593Smuzhiyun static int rk_spdifrx_hw_params(struct snd_pcm_substream *substream,
63*4882a593Smuzhiyun struct snd_pcm_hw_params *params,
64*4882a593Smuzhiyun struct snd_soc_dai *dai)
65*4882a593Smuzhiyun {
66*4882a593Smuzhiyun struct rk_spdifrx_dev *spdifrx = snd_soc_dai_get_drvdata(dai);
67*4882a593Smuzhiyun
68*4882a593Smuzhiyun regmap_update_bits(spdifrx->regmap, SPDIFRX_INTEN,
69*4882a593Smuzhiyun SPDIFRX_INTEN_SYNCIE_MASK |
70*4882a593Smuzhiyun SPDIFRX_INTEN_NSYNCIE_MASK,
71*4882a593Smuzhiyun SPDIFRX_INTEN_SYNCIE_EN |
72*4882a593Smuzhiyun SPDIFRX_INTEN_NSYNCIE_EN);
73*4882a593Smuzhiyun regmap_update_bits(spdifrx->regmap, SPDIFRX_DMACR,
74*4882a593Smuzhiyun SPDIFRX_DMACR_RDL_MASK, SPDIFRX_DMACR_RDL(8));
75*4882a593Smuzhiyun regmap_update_bits(spdifrx->regmap, SPDIFRX_CDR,
76*4882a593Smuzhiyun SPDIFRX_CDR_AVGSEL_MASK | SPDIFRX_CDR_BYPASS_MASK,
77*4882a593Smuzhiyun SPDIFRX_CDR_AVGSEL_MIN | SPDIFRX_CDR_BYPASS_DIS);
78*4882a593Smuzhiyun return 0;
79*4882a593Smuzhiyun }
80*4882a593Smuzhiyun
rk_spdifrx_reset(struct rk_spdifrx_dev * spdifrx)81*4882a593Smuzhiyun static void rk_spdifrx_reset(struct rk_spdifrx_dev *spdifrx)
82*4882a593Smuzhiyun {
83*4882a593Smuzhiyun reset_control_assert(spdifrx->reset);
84*4882a593Smuzhiyun udelay(1);
85*4882a593Smuzhiyun reset_control_deassert(spdifrx->reset);
86*4882a593Smuzhiyun }
87*4882a593Smuzhiyun
rk_spdifrx_trigger(struct snd_pcm_substream * substream,int cmd,struct snd_soc_dai * dai)88*4882a593Smuzhiyun static int rk_spdifrx_trigger(struct snd_pcm_substream *substream,
89*4882a593Smuzhiyun int cmd, struct snd_soc_dai *dai)
90*4882a593Smuzhiyun {
91*4882a593Smuzhiyun struct rk_spdifrx_dev *spdifrx = snd_soc_dai_get_drvdata(dai);
92*4882a593Smuzhiyun int ret;
93*4882a593Smuzhiyun
94*4882a593Smuzhiyun switch (cmd) {
95*4882a593Smuzhiyun case SNDRV_PCM_TRIGGER_START:
96*4882a593Smuzhiyun case SNDRV_PCM_TRIGGER_RESUME:
97*4882a593Smuzhiyun case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
98*4882a593Smuzhiyun rk_spdifrx_reset(spdifrx);
99*4882a593Smuzhiyun ret = regmap_update_bits(spdifrx->regmap, SPDIFRX_DMACR,
100*4882a593Smuzhiyun SPDIFRX_DMACR_RDE_MASK,
101*4882a593Smuzhiyun SPDIFRX_DMACR_RDE_ENABLE);
102*4882a593Smuzhiyun
103*4882a593Smuzhiyun if (ret != 0)
104*4882a593Smuzhiyun return ret;
105*4882a593Smuzhiyun
106*4882a593Smuzhiyun ret = regmap_update_bits(spdifrx->regmap, SPDIFRX_CFGR,
107*4882a593Smuzhiyun SPDIFRX_EN_MASK,
108*4882a593Smuzhiyun SPDIFRX_EN);
109*4882a593Smuzhiyun break;
110*4882a593Smuzhiyun case SNDRV_PCM_TRIGGER_SUSPEND:
111*4882a593Smuzhiyun case SNDRV_PCM_TRIGGER_STOP:
112*4882a593Smuzhiyun case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
113*4882a593Smuzhiyun ret = regmap_update_bits(spdifrx->regmap, SPDIFRX_DMACR,
114*4882a593Smuzhiyun SPDIFRX_DMACR_RDE_MASK,
115*4882a593Smuzhiyun SPDIFRX_DMACR_RDE_DISABLE);
116*4882a593Smuzhiyun
117*4882a593Smuzhiyun if (ret != 0)
118*4882a593Smuzhiyun return ret;
119*4882a593Smuzhiyun
120*4882a593Smuzhiyun ret = regmap_update_bits(spdifrx->regmap, SPDIFRX_CFGR,
121*4882a593Smuzhiyun SPDIFRX_EN_MASK,
122*4882a593Smuzhiyun SPDIFRX_DIS);
123*4882a593Smuzhiyun break;
124*4882a593Smuzhiyun default:
125*4882a593Smuzhiyun ret = -EINVAL;
126*4882a593Smuzhiyun break;
127*4882a593Smuzhiyun }
128*4882a593Smuzhiyun
129*4882a593Smuzhiyun return ret;
130*4882a593Smuzhiyun }
131*4882a593Smuzhiyun
rk_spdifrx_dai_probe(struct snd_soc_dai * dai)132*4882a593Smuzhiyun static int rk_spdifrx_dai_probe(struct snd_soc_dai *dai)
133*4882a593Smuzhiyun {
134*4882a593Smuzhiyun struct rk_spdifrx_dev *spdifrx = snd_soc_dai_get_drvdata(dai);
135*4882a593Smuzhiyun
136*4882a593Smuzhiyun dai->capture_dma_data = &spdifrx->capture_dma_data;
137*4882a593Smuzhiyun
138*4882a593Smuzhiyun return 0;
139*4882a593Smuzhiyun }
140*4882a593Smuzhiyun
141*4882a593Smuzhiyun static const struct snd_soc_dai_ops rk_spdifrx_dai_ops = {
142*4882a593Smuzhiyun .hw_params = rk_spdifrx_hw_params,
143*4882a593Smuzhiyun .trigger = rk_spdifrx_trigger,
144*4882a593Smuzhiyun };
145*4882a593Smuzhiyun
146*4882a593Smuzhiyun static struct snd_soc_dai_driver rk_spdifrx_dai = {
147*4882a593Smuzhiyun .probe = rk_spdifrx_dai_probe,
148*4882a593Smuzhiyun .capture = {
149*4882a593Smuzhiyun .stream_name = "Capture",
150*4882a593Smuzhiyun .channels_min = 2,
151*4882a593Smuzhiyun .channels_max = 2,
152*4882a593Smuzhiyun .rates = (SNDRV_PCM_RATE_32000 |
153*4882a593Smuzhiyun SNDRV_PCM_RATE_44100 |
154*4882a593Smuzhiyun SNDRV_PCM_RATE_48000 |
155*4882a593Smuzhiyun SNDRV_PCM_RATE_96000 |
156*4882a593Smuzhiyun SNDRV_PCM_RATE_192000),
157*4882a593Smuzhiyun .formats = (SNDRV_PCM_FMTBIT_S16_LE |
158*4882a593Smuzhiyun SNDRV_PCM_FMTBIT_S20_3LE |
159*4882a593Smuzhiyun SNDRV_PCM_FMTBIT_S24_LE),
160*4882a593Smuzhiyun },
161*4882a593Smuzhiyun .ops = &rk_spdifrx_dai_ops,
162*4882a593Smuzhiyun };
163*4882a593Smuzhiyun
164*4882a593Smuzhiyun static const struct snd_soc_component_driver rk_spdifrx_component = {
165*4882a593Smuzhiyun .name = "rockchip-spdifrx",
166*4882a593Smuzhiyun };
167*4882a593Smuzhiyun
rk_spdifrx_wr_reg(struct device * dev,unsigned int reg)168*4882a593Smuzhiyun static bool rk_spdifrx_wr_reg(struct device *dev, unsigned int reg)
169*4882a593Smuzhiyun {
170*4882a593Smuzhiyun switch (reg) {
171*4882a593Smuzhiyun case SPDIFRX_CFGR:
172*4882a593Smuzhiyun case SPDIFRX_CLR:
173*4882a593Smuzhiyun case SPDIFRX_CDR:
174*4882a593Smuzhiyun case SPDIFRX_CDRST:
175*4882a593Smuzhiyun case SPDIFRX_DMACR:
176*4882a593Smuzhiyun case SPDIFRX_FIFOCTRL:
177*4882a593Smuzhiyun case SPDIFRX_INTEN:
178*4882a593Smuzhiyun case SPDIFRX_INTMASK:
179*4882a593Smuzhiyun case SPDIFRX_INTSR:
180*4882a593Smuzhiyun case SPDIFRX_INTCLR:
181*4882a593Smuzhiyun case SPDIFRX_SMPDR:
182*4882a593Smuzhiyun case SPDIFRX_BURSTINFO:
183*4882a593Smuzhiyun return true;
184*4882a593Smuzhiyun default:
185*4882a593Smuzhiyun return false;
186*4882a593Smuzhiyun }
187*4882a593Smuzhiyun }
188*4882a593Smuzhiyun
rk_spdifrx_rd_reg(struct device * dev,unsigned int reg)189*4882a593Smuzhiyun static bool rk_spdifrx_rd_reg(struct device *dev, unsigned int reg)
190*4882a593Smuzhiyun {
191*4882a593Smuzhiyun switch (reg) {
192*4882a593Smuzhiyun case SPDIFRX_CFGR:
193*4882a593Smuzhiyun case SPDIFRX_CLR:
194*4882a593Smuzhiyun case SPDIFRX_CDR:
195*4882a593Smuzhiyun case SPDIFRX_CDRST:
196*4882a593Smuzhiyun case SPDIFRX_DMACR:
197*4882a593Smuzhiyun case SPDIFRX_FIFOCTRL:
198*4882a593Smuzhiyun case SPDIFRX_INTEN:
199*4882a593Smuzhiyun case SPDIFRX_INTMASK:
200*4882a593Smuzhiyun case SPDIFRX_INTSR:
201*4882a593Smuzhiyun case SPDIFRX_INTCLR:
202*4882a593Smuzhiyun case SPDIFRX_SMPDR:
203*4882a593Smuzhiyun case SPDIFRX_BURSTINFO:
204*4882a593Smuzhiyun return true;
205*4882a593Smuzhiyun default:
206*4882a593Smuzhiyun return false;
207*4882a593Smuzhiyun }
208*4882a593Smuzhiyun }
209*4882a593Smuzhiyun
rk_spdifrx_volatile_reg(struct device * dev,unsigned int reg)210*4882a593Smuzhiyun static bool rk_spdifrx_volatile_reg(struct device *dev, unsigned int reg)
211*4882a593Smuzhiyun {
212*4882a593Smuzhiyun switch (reg) {
213*4882a593Smuzhiyun case SPDIFRX_CLR:
214*4882a593Smuzhiyun case SPDIFRX_CDR:
215*4882a593Smuzhiyun case SPDIFRX_CDRST:
216*4882a593Smuzhiyun case SPDIFRX_FIFOCTRL:
217*4882a593Smuzhiyun case SPDIFRX_INTSR:
218*4882a593Smuzhiyun case SPDIFRX_INTCLR:
219*4882a593Smuzhiyun case SPDIFRX_SMPDR:
220*4882a593Smuzhiyun case SPDIFRX_BURSTINFO:
221*4882a593Smuzhiyun return true;
222*4882a593Smuzhiyun default:
223*4882a593Smuzhiyun return false;
224*4882a593Smuzhiyun }
225*4882a593Smuzhiyun }
226*4882a593Smuzhiyun
rk_spdifrx_precious_reg(struct device * dev,unsigned int reg)227*4882a593Smuzhiyun static bool rk_spdifrx_precious_reg(struct device *dev, unsigned int reg)
228*4882a593Smuzhiyun {
229*4882a593Smuzhiyun switch (reg) {
230*4882a593Smuzhiyun case SPDIFRX_SMPDR:
231*4882a593Smuzhiyun return true;
232*4882a593Smuzhiyun default:
233*4882a593Smuzhiyun return false;
234*4882a593Smuzhiyun }
235*4882a593Smuzhiyun }
236*4882a593Smuzhiyun
237*4882a593Smuzhiyun static const struct regmap_config rk_spdifrx_regmap_config = {
238*4882a593Smuzhiyun .reg_bits = 32,
239*4882a593Smuzhiyun .reg_stride = 4,
240*4882a593Smuzhiyun .val_bits = 32,
241*4882a593Smuzhiyun .max_register = SPDIFRX_BURSTINFO,
242*4882a593Smuzhiyun .writeable_reg = rk_spdifrx_wr_reg,
243*4882a593Smuzhiyun .readable_reg = rk_spdifrx_rd_reg,
244*4882a593Smuzhiyun .volatile_reg = rk_spdifrx_volatile_reg,
245*4882a593Smuzhiyun .precious_reg = rk_spdifrx_precious_reg,
246*4882a593Smuzhiyun .cache_type = REGCACHE_FLAT,
247*4882a593Smuzhiyun };
248*4882a593Smuzhiyun
rk_spdifrx_isr(int irq,void * dev_id)249*4882a593Smuzhiyun static irqreturn_t rk_spdifrx_isr(int irq, void *dev_id)
250*4882a593Smuzhiyun {
251*4882a593Smuzhiyun struct rk_spdifrx_dev *spdifrx = dev_id;
252*4882a593Smuzhiyun u32 intsr;
253*4882a593Smuzhiyun
254*4882a593Smuzhiyun regmap_read(spdifrx->regmap, SPDIFRX_INTSR, &intsr);
255*4882a593Smuzhiyun
256*4882a593Smuzhiyun if (intsr & BIT(7)) {
257*4882a593Smuzhiyun dev_dbg(spdifrx->dev, "NSYNC\n");
258*4882a593Smuzhiyun regmap_write(spdifrx->regmap, SPDIFRX_INTCLR, BIT(7));
259*4882a593Smuzhiyun }
260*4882a593Smuzhiyun
261*4882a593Smuzhiyun if (intsr & BIT(9)) {
262*4882a593Smuzhiyun dev_dbg(spdifrx->dev, "SYNC\n");
263*4882a593Smuzhiyun regmap_write(spdifrx->regmap, SPDIFRX_INTCLR, BIT(9));
264*4882a593Smuzhiyun }
265*4882a593Smuzhiyun
266*4882a593Smuzhiyun return IRQ_HANDLED;
267*4882a593Smuzhiyun }
268*4882a593Smuzhiyun
rk_spdifrx_probe(struct platform_device * pdev)269*4882a593Smuzhiyun static int rk_spdifrx_probe(struct platform_device *pdev)
270*4882a593Smuzhiyun {
271*4882a593Smuzhiyun struct rk_spdifrx_dev *spdifrx;
272*4882a593Smuzhiyun struct resource *res;
273*4882a593Smuzhiyun void __iomem *regs;
274*4882a593Smuzhiyun int ret;
275*4882a593Smuzhiyun
276*4882a593Smuzhiyun spdifrx = devm_kzalloc(&pdev->dev, sizeof(*spdifrx), GFP_KERNEL);
277*4882a593Smuzhiyun if (!spdifrx)
278*4882a593Smuzhiyun return -ENOMEM;
279*4882a593Smuzhiyun
280*4882a593Smuzhiyun spdifrx->reset = devm_reset_control_get(&pdev->dev, "spdifrx-m");
281*4882a593Smuzhiyun if (IS_ERR(spdifrx->reset)) {
282*4882a593Smuzhiyun ret = PTR_ERR(spdifrx->reset);
283*4882a593Smuzhiyun if (ret != -ENOENT)
284*4882a593Smuzhiyun return ret;
285*4882a593Smuzhiyun }
286*4882a593Smuzhiyun
287*4882a593Smuzhiyun spdifrx->hclk = devm_clk_get(&pdev->dev, "hclk");
288*4882a593Smuzhiyun if (IS_ERR(spdifrx->hclk))
289*4882a593Smuzhiyun return PTR_ERR(spdifrx->hclk);
290*4882a593Smuzhiyun
291*4882a593Smuzhiyun spdifrx->mclk = devm_clk_get(&pdev->dev, "mclk");
292*4882a593Smuzhiyun if (IS_ERR(spdifrx->mclk))
293*4882a593Smuzhiyun return PTR_ERR(spdifrx->mclk);
294*4882a593Smuzhiyun
295*4882a593Smuzhiyun spdifrx->irq = platform_get_irq(pdev, 0);
296*4882a593Smuzhiyun if (spdifrx->irq < 0)
297*4882a593Smuzhiyun return spdifrx->irq;
298*4882a593Smuzhiyun
299*4882a593Smuzhiyun ret = devm_request_threaded_irq(&pdev->dev, spdifrx->irq, NULL,
300*4882a593Smuzhiyun rk_spdifrx_isr,
301*4882a593Smuzhiyun IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
302*4882a593Smuzhiyun dev_name(&pdev->dev), spdifrx);
303*4882a593Smuzhiyun if (ret)
304*4882a593Smuzhiyun return ret;
305*4882a593Smuzhiyun
306*4882a593Smuzhiyun res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
307*4882a593Smuzhiyun regs = devm_ioremap_resource(&pdev->dev, res);
308*4882a593Smuzhiyun if (IS_ERR(regs))
309*4882a593Smuzhiyun return PTR_ERR(regs);
310*4882a593Smuzhiyun
311*4882a593Smuzhiyun spdifrx->regmap = devm_regmap_init_mmio(&pdev->dev, regs,
312*4882a593Smuzhiyun &rk_spdifrx_regmap_config);
313*4882a593Smuzhiyun if (IS_ERR(spdifrx->regmap))
314*4882a593Smuzhiyun return PTR_ERR(spdifrx->regmap);
315*4882a593Smuzhiyun
316*4882a593Smuzhiyun spdifrx->capture_dma_data.addr = res->start + SPDIFRX_SMPDR;
317*4882a593Smuzhiyun spdifrx->capture_dma_data.addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
318*4882a593Smuzhiyun spdifrx->capture_dma_data.maxburst = 4;
319*4882a593Smuzhiyun
320*4882a593Smuzhiyun spdifrx->dev = &pdev->dev;
321*4882a593Smuzhiyun dev_set_drvdata(&pdev->dev, spdifrx);
322*4882a593Smuzhiyun
323*4882a593Smuzhiyun pm_runtime_enable(&pdev->dev);
324*4882a593Smuzhiyun if (!pm_runtime_enabled(&pdev->dev)) {
325*4882a593Smuzhiyun ret = rk_spdifrx_runtime_resume(&pdev->dev);
326*4882a593Smuzhiyun if (ret)
327*4882a593Smuzhiyun goto err_pm_runtime;
328*4882a593Smuzhiyun }
329*4882a593Smuzhiyun
330*4882a593Smuzhiyun ret = devm_snd_soc_register_component(&pdev->dev,
331*4882a593Smuzhiyun &rk_spdifrx_component,
332*4882a593Smuzhiyun &rk_spdifrx_dai, 1);
333*4882a593Smuzhiyun if (ret) {
334*4882a593Smuzhiyun dev_err(&pdev->dev, "Could not register DAI\n");
335*4882a593Smuzhiyun goto err_pm_suspend;
336*4882a593Smuzhiyun }
337*4882a593Smuzhiyun
338*4882a593Smuzhiyun ret = devm_snd_dmaengine_pcm_register(&pdev->dev, NULL, 0);
339*4882a593Smuzhiyun if (ret) {
340*4882a593Smuzhiyun dev_err(&pdev->dev, "Could not register PCM\n");
341*4882a593Smuzhiyun goto err_pm_suspend;
342*4882a593Smuzhiyun }
343*4882a593Smuzhiyun
344*4882a593Smuzhiyun return 0;
345*4882a593Smuzhiyun
346*4882a593Smuzhiyun err_pm_suspend:
347*4882a593Smuzhiyun if (!pm_runtime_status_suspended(&pdev->dev))
348*4882a593Smuzhiyun rk_spdifrx_runtime_suspend(&pdev->dev);
349*4882a593Smuzhiyun err_pm_runtime:
350*4882a593Smuzhiyun pm_runtime_disable(&pdev->dev);
351*4882a593Smuzhiyun
352*4882a593Smuzhiyun return ret;
353*4882a593Smuzhiyun }
354*4882a593Smuzhiyun
rk_spdifrx_remove(struct platform_device * pdev)355*4882a593Smuzhiyun static int rk_spdifrx_remove(struct platform_device *pdev)
356*4882a593Smuzhiyun {
357*4882a593Smuzhiyun pm_runtime_disable(&pdev->dev);
358*4882a593Smuzhiyun if (!pm_runtime_status_suspended(&pdev->dev))
359*4882a593Smuzhiyun rk_spdifrx_runtime_suspend(&pdev->dev);
360*4882a593Smuzhiyun
361*4882a593Smuzhiyun return 0;
362*4882a593Smuzhiyun }
363*4882a593Smuzhiyun
364*4882a593Smuzhiyun #ifdef CONFIG_PM_SLEEP
rockchip_spdifrx_suspend(struct device * dev)365*4882a593Smuzhiyun static int rockchip_spdifrx_suspend(struct device *dev)
366*4882a593Smuzhiyun {
367*4882a593Smuzhiyun struct rk_spdifrx_dev *spdifrx = dev_get_drvdata(dev);
368*4882a593Smuzhiyun
369*4882a593Smuzhiyun regcache_mark_dirty(spdifrx->regmap);
370*4882a593Smuzhiyun
371*4882a593Smuzhiyun return 0;
372*4882a593Smuzhiyun }
373*4882a593Smuzhiyun
rockchip_spdifrx_resume(struct device * dev)374*4882a593Smuzhiyun static int rockchip_spdifrx_resume(struct device *dev)
375*4882a593Smuzhiyun {
376*4882a593Smuzhiyun struct rk_spdifrx_dev *spdifrx = dev_get_drvdata(dev);
377*4882a593Smuzhiyun int ret;
378*4882a593Smuzhiyun
379*4882a593Smuzhiyun ret = pm_runtime_get_sync(dev);
380*4882a593Smuzhiyun if (ret < 0)
381*4882a593Smuzhiyun return ret;
382*4882a593Smuzhiyun ret = regcache_sync(spdifrx->regmap);
383*4882a593Smuzhiyun pm_runtime_put(dev);
384*4882a593Smuzhiyun
385*4882a593Smuzhiyun return ret;
386*4882a593Smuzhiyun }
387*4882a593Smuzhiyun #endif
388*4882a593Smuzhiyun
389*4882a593Smuzhiyun static const struct dev_pm_ops rk_spdifrx_pm_ops = {
390*4882a593Smuzhiyun SET_RUNTIME_PM_OPS(rk_spdifrx_runtime_suspend, rk_spdifrx_runtime_resume,
391*4882a593Smuzhiyun NULL)
392*4882a593Smuzhiyun SET_SYSTEM_SLEEP_PM_OPS(rockchip_spdifrx_suspend, rockchip_spdifrx_resume)
393*4882a593Smuzhiyun };
394*4882a593Smuzhiyun
395*4882a593Smuzhiyun static const struct of_device_id rk_spdifrx_match[] = {
396*4882a593Smuzhiyun { .compatible = "rockchip,rk3308-spdifrx", },
397*4882a593Smuzhiyun {},
398*4882a593Smuzhiyun };
399*4882a593Smuzhiyun MODULE_DEVICE_TABLE(of, rk_spdifrx_match);
400*4882a593Smuzhiyun
401*4882a593Smuzhiyun static struct platform_driver rk_spdifrx_driver = {
402*4882a593Smuzhiyun .probe = rk_spdifrx_probe,
403*4882a593Smuzhiyun .remove = rk_spdifrx_remove,
404*4882a593Smuzhiyun .driver = {
405*4882a593Smuzhiyun .name = "rockchip-spdifrx",
406*4882a593Smuzhiyun .of_match_table = of_match_ptr(rk_spdifrx_match),
407*4882a593Smuzhiyun .pm = &rk_spdifrx_pm_ops,
408*4882a593Smuzhiyun },
409*4882a593Smuzhiyun };
410*4882a593Smuzhiyun module_platform_driver(rk_spdifrx_driver);
411*4882a593Smuzhiyun
412*4882a593Smuzhiyun MODULE_ALIAS("platform:rockchip-spdifrx");
413*4882a593Smuzhiyun MODULE_DESCRIPTION("ROCKCHIP SPDIFRX Controller Interface");
414*4882a593Smuzhiyun MODULE_AUTHOR("Sugar Zhang <sugar.zhang@rock-chips.com>");
415*4882a593Smuzhiyun MODULE_LICENSE("GPL v2");
416