Lines Matching +full:v +full:- +full:bit
1 // SPDX-License-Identifier: GPL-2.0-or-later
30 #define SUN4I_SPDIF_CTL_MCLKDIV(v) ((v) << 4) /* v even */ argument
31 #define SUN4I_SPDIF_CTL_MCLKOUTEN BIT(2)
32 #define SUN4I_SPDIF_CTL_GEN BIT(1)
33 #define SUN4I_SPDIF_CTL_RESET BIT(0)
36 #define SUN4I_SPDIF_TXCFG_SINGLEMOD BIT(31)
37 #define SUN4I_SPDIF_TXCFG_ASS BIT(17)
38 #define SUN4I_SPDIF_TXCFG_NONAUDIO BIT(16)
39 #define SUN4I_SPDIF_TXCFG_TXRATIO(v) ((v) << 4) argument
45 #define SUN4I_SPDIF_TXCFG_CHSTMODE BIT(1)
46 #define SUN4I_SPDIF_TXCFG_TXEN BIT(0)
49 #define SUN4I_SPDIF_RXCFG_LOCKFLAG BIT(4)
50 #define SUN4I_SPDIF_RXCFG_CHSTSRC BIT(3)
51 #define SUN4I_SPDIF_RXCFG_CHSTCP BIT(1)
52 #define SUN4I_SPDIF_RXCFG_RXEN BIT(0)
59 #define SUN4I_SPDIF_FCTL_FIFOSRC BIT(31)
60 #define SUN4I_SPDIF_FCTL_FTX BIT(17)
61 #define SUN4I_SPDIF_FCTL_FRX BIT(16)
62 #define SUN4I_SPDIF_FCTL_TXTL(v) ((v) << 8) argument
64 #define SUN4I_SPDIF_FCTL_RXTL(v) ((v) << 3) argument
66 #define SUN4I_SPDIF_FCTL_TXIM BIT(2)
67 #define SUN4I_SPDIF_FCTL_RXOM(v) ((v) << 0) argument
71 #define SUN50I_H6_SPDIF_FCTL_HUB_EN BIT(31)
72 #define SUN50I_H6_SPDIF_FCTL_FTX BIT(30)
73 #define SUN50I_H6_SPDIF_FCTL_FRX BIT(29)
74 #define SUN50I_H6_SPDIF_FCTL_TXTL(v) ((v) << 12) argument
76 #define SUN50I_H6_SPDIF_FCTL_RXTL(v) ((v) << 4) argument
78 #define SUN50I_H6_SPDIF_FCTL_TXIM BIT(2)
79 #define SUN50I_H6_SPDIF_FCTL_RXOM(v) ((v) << 0) argument
83 #define SUN4I_SPDIF_FSTA_TXE BIT(14)
85 #define SUN4I_SPDIF_FSTA_RXA BIT(6)
89 #define SUN4I_SPDIF_INT_RXLOCKEN BIT(18)
90 #define SUN4I_SPDIF_INT_RXUNLOCKEN BIT(17)
91 #define SUN4I_SPDIF_INT_RXPARERREN BIT(16)
92 #define SUN4I_SPDIF_INT_TXDRQEN BIT(7)
93 #define SUN4I_SPDIF_INT_TXUIEN BIT(6)
94 #define SUN4I_SPDIF_INT_TXOIEN BIT(5)
95 #define SUN4I_SPDIF_INT_TXEIEN BIT(4)
96 #define SUN4I_SPDIF_INT_RXDRQEN BIT(2)
97 #define SUN4I_SPDIF_INT_RXOIEN BIT(1)
98 #define SUN4I_SPDIF_INT_RXAIEN BIT(0)
101 #define SUN4I_SPDIF_ISTA_RXLOCKSTA BIT(18)
102 #define SUN4I_SPDIF_ISTA_RXUNLOCKSTA BIT(17)
103 #define SUN4I_SPDIF_ISTA_RXPARERRSTA BIT(16)
104 #define SUN4I_SPDIF_ISTA_TXUSTA BIT(6)
105 #define SUN4I_SPDIF_ISTA_TXOSTA BIT(5)
106 #define SUN4I_SPDIF_ISTA_TXESTA BIT(4)
107 #define SUN4I_SPDIF_ISTA_RXOSTA BIT(1)
108 #define SUN4I_SPDIF_ISTA_RXASTA BIT(0)
117 #define SUN4I_SPDIF_TXCHSTA0_CLK(v) ((v) << 28) argument
118 #define SUN4I_SPDIF_TXCHSTA0_SAMFREQ(v) ((v) << 24) argument
120 #define SUN4I_SPDIF_TXCHSTA0_CHNUM(v) ((v) << 20) argument
122 #define SUN4I_SPDIF_TXCHSTA0_SRCNUM(v) ((v) << 16) argument
123 #define SUN4I_SPDIF_TXCHSTA0_CATACOD(v) ((v) << 8) argument
124 #define SUN4I_SPDIF_TXCHSTA0_MODE(v) ((v) << 6) argument
125 #define SUN4I_SPDIF_TXCHSTA0_EMPHASIS(v) ((v) << 3) argument
126 #define SUN4I_SPDIF_TXCHSTA0_CP BIT(2)
127 #define SUN4I_SPDIF_TXCHSTA0_AUDIO BIT(1)
128 #define SUN4I_SPDIF_TXCHSTA0_PRO BIT(0)
131 #define SUN4I_SPDIF_TXCHSTA1_CGMSA(v) ((v) << 8) argument
132 #define SUN4I_SPDIF_TXCHSTA1_ORISAMFREQ(v) ((v) << 4) argument
134 #define SUN4I_SPDIF_TXCHSTA1_SAMWORDLEN(v) ((v) << 1) argument
135 #define SUN4I_SPDIF_TXCHSTA1_MAXWORDLEN BIT(0)
138 #define SUN4I_SPDIF_RXCHSTA0_CLK(v) ((v) << 28) argument
139 #define SUN4I_SPDIF_RXCHSTA0_SAMFREQ(v) ((v) << 24) argument
140 #define SUN4I_SPDIF_RXCHSTA0_CHNUM(v) ((v) << 20) argument
141 #define SUN4I_SPDIF_RXCHSTA0_SRCNUM(v) ((v) << 16) argument
142 #define SUN4I_SPDIF_RXCHSTA0_CATACOD(v) ((v) << 8) argument
143 #define SUN4I_SPDIF_RXCHSTA0_MODE(v) ((v) << 6) argument
144 #define SUN4I_SPDIF_RXCHSTA0_EMPHASIS(v) ((v) << 3) argument
145 #define SUN4I_SPDIF_RXCHSTA0_CP BIT(2)
146 #define SUN4I_SPDIF_RXCHSTA0_AUDIO BIT(1)
147 #define SUN4I_SPDIF_RXCHSTA0_PRO BIT(0)
150 #define SUN4I_SPDIF_RXCHSTA1_CGMSA(v) ((v) << 8) argument
151 #define SUN4I_SPDIF_RXCHSTA1_ORISAMFREQ(v) ((v) << 4) argument
152 #define SUN4I_SPDIF_RXCHSTA1_SAMWORDLEN(v) ((v) << 1) argument
153 #define SUN4I_SPDIF_RXCHSTA1_MAXWORDLEN BIT(0)
169 * struct sun4i_spdif_quirks - Differences between SoC variants.
196 const struct sun4i_spdif_quirks *quirks = host->quirks; in sun4i_spdif_configure()
199 regmap_write(host->regmap, SUN4I_SPDIF_CTL, SUN4I_SPDIF_CTL_RESET); in sun4i_spdif_configure()
202 regmap_update_bits(host->regmap, SUN4I_SPDIF_FCTL, in sun4i_spdif_configure()
203 quirks->val_fctl_ftx, quirks->val_fctl_ftx); in sun4i_spdif_configure()
206 regmap_update_bits(host->regmap, SUN4I_SPDIF_FCTL, in sun4i_spdif_configure()
210 regmap_write(host->regmap, SUN4I_SPDIF_TXCNT, 0); in sun4i_spdif_configure()
216 if (substream->runtime->channels == 1) in sun4i_snd_txctrl_on()
217 regmap_update_bits(host->regmap, SUN4I_SPDIF_TXCFG, in sun4i_snd_txctrl_on()
222 regmap_update_bits(host->regmap, SUN4I_SPDIF_TXCFG, in sun4i_snd_txctrl_on()
226 regmap_update_bits(host->regmap, SUN4I_SPDIF_INT, in sun4i_snd_txctrl_on()
230 regmap_update_bits(host->regmap, SUN4I_SPDIF_CTL, in sun4i_snd_txctrl_on()
238 regmap_update_bits(host->regmap, SUN4I_SPDIF_TXCFG, in sun4i_snd_txctrl_off()
242 regmap_update_bits(host->regmap, SUN4I_SPDIF_INT, in sun4i_snd_txctrl_off()
246 regmap_update_bits(host->regmap, SUN4I_SPDIF_CTL, in sun4i_snd_txctrl_off()
256 if (substream->stream != SNDRV_PCM_STREAM_PLAYBACK) in sun4i_spdif_startup()
257 return -EINVAL; in sun4i_spdif_startup()
275 struct platform_device *pdev = host->pdev; in sun4i_spdif_hw_params()
287 return -EINVAL; in sun4i_spdif_hw_params()
290 host->dma_params_tx.addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; in sun4i_spdif_hw_params()
294 host->dma_params_tx.addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES; in sun4i_spdif_hw_params()
304 return -EINVAL; in sun4i_spdif_hw_params()
322 return -EINVAL; in sun4i_spdif_hw_params()
324 mclk *= host->quirks->mclk_multiplier; in sun4i_spdif_hw_params()
326 ret = clk_set_rate(host->spdif_clk, mclk); in sun4i_spdif_hw_params()
328 dev_err(&pdev->dev, in sun4i_spdif_hw_params()
354 return -EINVAL; in sun4i_spdif_hw_params()
356 mclk_div *= host->quirks->mclk_multiplier; in sun4i_spdif_hw_params()
360 reg_val |= fmt; /* set non audio and bit depth */ in sun4i_spdif_hw_params()
362 reg_val |= SUN4I_SPDIF_TXCFG_TXRATIO(mclk_div - 1); in sun4i_spdif_hw_params()
363 regmap_write(host->regmap, SUN4I_SPDIF_TXCFG, reg_val); in sun4i_spdif_hw_params()
374 if (substream->stream != SNDRV_PCM_STREAM_PLAYBACK) in sun4i_spdif_trigger()
375 return -EINVAL; in sun4i_spdif_trigger()
391 ret = -EINVAL; in sun4i_spdif_trigger()
400 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; in sun4i_spdif_info()
401 uinfo->count = 1; in sun4i_spdif_info()
409 u8 *status = ucontrol->value.iec958.status; in sun4i_spdif_get_status_mask()
426 u8 *status = ucontrol->value.iec958.status; in sun4i_spdif_get_status()
430 spin_lock_irqsave(&host->lock, flags); in sun4i_spdif_get_status()
432 regmap_read(host->regmap, SUN4I_SPDIF_TXCHSTA0, ®); in sun4i_spdif_get_status()
439 regmap_read(host->regmap, SUN4I_SPDIF_TXCHSTA1, ®); in sun4i_spdif_get_status()
444 spin_unlock_irqrestore(&host->lock, flags); in sun4i_spdif_get_status()
454 u8 *status = ucontrol->value.iec958.status; in sun4i_spdif_set_status()
459 spin_lock_irqsave(&host->lock, flags); in sun4i_spdif_set_status()
466 regmap_update_bits_check(host->regmap, SUN4I_SPDIF_TXCHSTA0, in sun4i_spdif_set_status()
472 regmap_update_bits_check(host->regmap, SUN4I_SPDIF_TXCHSTA1, in sun4i_spdif_set_status()
479 regmap_update_bits(host->regmap, SUN4I_SPDIF_TXCFG, in sun4i_spdif_set_status()
483 spin_unlock_irqrestore(&host->lock, flags); in sun4i_spdif_set_status()
509 snd_soc_dai_init_dma_data(dai, &host->dma_params_tx, NULL); in sun4i_spdif_soc_dai_probe()
577 .compatible = "allwinner,sun4i-a10-spdif",
581 .compatible = "allwinner,sun6i-a31-spdif",
585 .compatible = "allwinner,sun8i-h3-spdif",
589 .compatible = "allwinner,sun50i-h6-spdif",
593 .compatible = "allwinner,sun50i-h616-spdif",
602 .name = "sun4i-spdif",
610 clk_disable_unprepare(host->spdif_clk); in sun4i_spdif_runtime_suspend()
611 clk_disable_unprepare(host->apb_clk); in sun4i_spdif_runtime_suspend()
621 ret = clk_prepare_enable(host->spdif_clk); in sun4i_spdif_runtime_resume()
624 ret = clk_prepare_enable(host->apb_clk); in sun4i_spdif_runtime_resume()
626 clk_disable_unprepare(host->spdif_clk); in sun4i_spdif_runtime_resume()
639 dev_dbg(&pdev->dev, "Entered %s\n", __func__); in sun4i_spdif_probe()
641 host = devm_kzalloc(&pdev->dev, sizeof(*host), GFP_KERNEL); in sun4i_spdif_probe()
643 return -ENOMEM; in sun4i_spdif_probe()
645 host->pdev = pdev; in sun4i_spdif_probe()
646 spin_lock_init(&host->lock); in sun4i_spdif_probe()
649 memcpy(&host->cpu_dai_drv, &sun4i_spdif_dai, sizeof(sun4i_spdif_dai)); in sun4i_spdif_probe()
650 host->cpu_dai_drv.name = dev_name(&pdev->dev); in sun4i_spdif_probe()
657 quirks = of_device_get_match_data(&pdev->dev); in sun4i_spdif_probe()
659 dev_err(&pdev->dev, "Failed to determine the quirks to use\n"); in sun4i_spdif_probe()
660 return -ENODEV; in sun4i_spdif_probe()
662 host->quirks = quirks; in sun4i_spdif_probe()
664 host->regmap = devm_regmap_init_mmio(&pdev->dev, base, in sun4i_spdif_probe()
668 host->apb_clk = devm_clk_get(&pdev->dev, "apb"); in sun4i_spdif_probe()
669 if (IS_ERR(host->apb_clk)) { in sun4i_spdif_probe()
670 dev_err(&pdev->dev, "failed to get a apb clock.\n"); in sun4i_spdif_probe()
671 return PTR_ERR(host->apb_clk); in sun4i_spdif_probe()
674 host->spdif_clk = devm_clk_get(&pdev->dev, "spdif"); in sun4i_spdif_probe()
675 if (IS_ERR(host->spdif_clk)) { in sun4i_spdif_probe()
676 dev_err(&pdev->dev, "failed to get a spdif clock.\n"); in sun4i_spdif_probe()
677 return PTR_ERR(host->spdif_clk); in sun4i_spdif_probe()
680 host->dma_params_tx.addr = res->start + quirks->reg_dac_txdata; in sun4i_spdif_probe()
681 host->dma_params_tx.maxburst = 8; in sun4i_spdif_probe()
682 host->dma_params_tx.addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES; in sun4i_spdif_probe()
686 if (quirks->has_reset) { in sun4i_spdif_probe()
687 host->rst = devm_reset_control_get_optional_exclusive(&pdev->dev, in sun4i_spdif_probe()
689 if (PTR_ERR(host->rst) == -EPROBE_DEFER) { in sun4i_spdif_probe()
690 ret = -EPROBE_DEFER; in sun4i_spdif_probe()
691 dev_err(&pdev->dev, "Failed to get reset: %d\n", ret); in sun4i_spdif_probe()
694 if (!IS_ERR(host->rst)) in sun4i_spdif_probe()
695 reset_control_deassert(host->rst); in sun4i_spdif_probe()
698 ret = devm_snd_soc_register_component(&pdev->dev, in sun4i_spdif_probe()
703 pm_runtime_enable(&pdev->dev); in sun4i_spdif_probe()
704 if (!pm_runtime_enabled(&pdev->dev)) { in sun4i_spdif_probe()
705 ret = sun4i_spdif_runtime_resume(&pdev->dev); in sun4i_spdif_probe()
710 ret = devm_snd_dmaengine_pcm_register(&pdev->dev, NULL, 0); in sun4i_spdif_probe()
715 if (!pm_runtime_status_suspended(&pdev->dev)) in sun4i_spdif_probe()
716 sun4i_spdif_runtime_suspend(&pdev->dev); in sun4i_spdif_probe()
718 pm_runtime_disable(&pdev->dev); in sun4i_spdif_probe()
724 pm_runtime_disable(&pdev->dev); in sun4i_spdif_remove()
725 if (!pm_runtime_status_suspended(&pdev->dev)) in sun4i_spdif_remove()
726 sun4i_spdif_runtime_suspend(&pdev->dev); in sun4i_spdif_remove()
736 .name = "sun4i-spdif",
750 MODULE_ALIAS("platform:sun4i-spdif");