Lines Matching +full:use +full:- +full:internal +full:- +full:divider
1 // SPDX-License-Identifier: GPL-2.0-only
3 * omap-mcbsp.c -- OMAP ALSA SoC DAI driver using McBSP port
24 #include "omap-mcbsp-priv.h"
25 #include "omap-mcbsp.h"
26 #include "sdma-pcm.h"
41 dev_dbg(mcbsp->dev, "**** McBSP%d regs ****\n", mcbsp->id); in omap_mcbsp_dump_reg()
42 dev_dbg(mcbsp->dev, "DRR2: 0x%04x\n", MCBSP_READ(mcbsp, DRR2)); in omap_mcbsp_dump_reg()
43 dev_dbg(mcbsp->dev, "DRR1: 0x%04x\n", MCBSP_READ(mcbsp, DRR1)); in omap_mcbsp_dump_reg()
44 dev_dbg(mcbsp->dev, "DXR2: 0x%04x\n", MCBSP_READ(mcbsp, DXR2)); in omap_mcbsp_dump_reg()
45 dev_dbg(mcbsp->dev, "DXR1: 0x%04x\n", MCBSP_READ(mcbsp, DXR1)); in omap_mcbsp_dump_reg()
46 dev_dbg(mcbsp->dev, "SPCR2: 0x%04x\n", MCBSP_READ(mcbsp, SPCR2)); in omap_mcbsp_dump_reg()
47 dev_dbg(mcbsp->dev, "SPCR1: 0x%04x\n", MCBSP_READ(mcbsp, SPCR1)); in omap_mcbsp_dump_reg()
48 dev_dbg(mcbsp->dev, "RCR2: 0x%04x\n", MCBSP_READ(mcbsp, RCR2)); in omap_mcbsp_dump_reg()
49 dev_dbg(mcbsp->dev, "RCR1: 0x%04x\n", MCBSP_READ(mcbsp, RCR1)); in omap_mcbsp_dump_reg()
50 dev_dbg(mcbsp->dev, "XCR2: 0x%04x\n", MCBSP_READ(mcbsp, XCR2)); in omap_mcbsp_dump_reg()
51 dev_dbg(mcbsp->dev, "XCR1: 0x%04x\n", MCBSP_READ(mcbsp, XCR1)); in omap_mcbsp_dump_reg()
52 dev_dbg(mcbsp->dev, "SRGR2: 0x%04x\n", MCBSP_READ(mcbsp, SRGR2)); in omap_mcbsp_dump_reg()
53 dev_dbg(mcbsp->dev, "SRGR1: 0x%04x\n", MCBSP_READ(mcbsp, SRGR1)); in omap_mcbsp_dump_reg()
54 dev_dbg(mcbsp->dev, "PCR0: 0x%04x\n", MCBSP_READ(mcbsp, PCR0)); in omap_mcbsp_dump_reg()
55 dev_dbg(mcbsp->dev, "***********************\n"); in omap_mcbsp_dump_reg()
69 return -EINVAL; in omap2_mcbsp_set_clks_src()
71 fck_src = clk_get(mcbsp->dev, src); in omap2_mcbsp_set_clks_src()
73 dev_err(mcbsp->dev, "CLKS: could not clk_get() %s\n", src); in omap2_mcbsp_set_clks_src()
74 return -EINVAL; in omap2_mcbsp_set_clks_src()
77 pm_runtime_put_sync(mcbsp->dev); in omap2_mcbsp_set_clks_src()
79 r = clk_set_parent(mcbsp->fclk, fck_src); in omap2_mcbsp_set_clks_src()
81 dev_err(mcbsp->dev, "CLKS: could not clk_set_parent() to %s\n", in omap2_mcbsp_set_clks_src()
84 pm_runtime_get_sync(mcbsp->dev); in omap2_mcbsp_set_clks_src()
97 dev_dbg(mcbsp->dev, "IRQ callback : 0x%x\n", irqst); in omap_mcbsp_irq_handler()
100 dev_err(mcbsp->dev, "RX Frame Sync Error!\n"); in omap_mcbsp_irq_handler()
102 dev_dbg(mcbsp->dev, "RX Frame Sync\n"); in omap_mcbsp_irq_handler()
104 dev_dbg(mcbsp->dev, "RX End Of Frame\n"); in omap_mcbsp_irq_handler()
106 dev_dbg(mcbsp->dev, "RX Buffer Threshold Reached\n"); in omap_mcbsp_irq_handler()
108 dev_err(mcbsp->dev, "RX Buffer Underflow!\n"); in omap_mcbsp_irq_handler()
110 dev_err(mcbsp->dev, "RX Buffer Overflow!\n"); in omap_mcbsp_irq_handler()
113 dev_err(mcbsp->dev, "TX Frame Sync Error!\n"); in omap_mcbsp_irq_handler()
115 dev_dbg(mcbsp->dev, "TX Frame Sync\n"); in omap_mcbsp_irq_handler()
117 dev_dbg(mcbsp->dev, "TX End Of Frame\n"); in omap_mcbsp_irq_handler()
119 dev_dbg(mcbsp->dev, "TX Buffer threshold Reached\n"); in omap_mcbsp_irq_handler()
121 dev_err(mcbsp->dev, "TX Buffer Underflow!\n"); in omap_mcbsp_irq_handler()
123 dev_err(mcbsp->dev, "TX Buffer Overflow!\n"); in omap_mcbsp_irq_handler()
125 dev_dbg(mcbsp->dev, "TX Buffer empty at end of frame\n"); in omap_mcbsp_irq_handler()
138 dev_dbg(mcbsp->dev, "TX IRQ callback : 0x%x\n", irqst_spcr2); in omap_mcbsp_tx_irq_handler()
141 dev_err(mcbsp->dev, "TX Frame Sync Error! : 0x%x\n", in omap_mcbsp_tx_irq_handler()
156 dev_dbg(mcbsp->dev, "RX IRQ callback : 0x%x\n", irqst_spcr1); in omap_mcbsp_rx_irq_handler()
159 dev_err(mcbsp->dev, "RX Frame Sync Error! : 0x%x\n", in omap_mcbsp_rx_irq_handler()
177 dev_dbg(mcbsp->dev, "Configuring McBSP%d phys_base: 0x%08lx\n", in omap_mcbsp_config()
178 mcbsp->id, mcbsp->phys_base); in omap_mcbsp_config()
181 MCBSP_WRITE(mcbsp, SPCR2, config->spcr2); in omap_mcbsp_config()
182 MCBSP_WRITE(mcbsp, SPCR1, config->spcr1); in omap_mcbsp_config()
183 MCBSP_WRITE(mcbsp, RCR2, config->rcr2); in omap_mcbsp_config()
184 MCBSP_WRITE(mcbsp, RCR1, config->rcr1); in omap_mcbsp_config()
185 MCBSP_WRITE(mcbsp, XCR2, config->xcr2); in omap_mcbsp_config()
186 MCBSP_WRITE(mcbsp, XCR1, config->xcr1); in omap_mcbsp_config()
187 MCBSP_WRITE(mcbsp, SRGR2, config->srgr2); in omap_mcbsp_config()
188 MCBSP_WRITE(mcbsp, SRGR1, config->srgr1); in omap_mcbsp_config()
189 MCBSP_WRITE(mcbsp, MCR2, config->mcr2); in omap_mcbsp_config()
190 MCBSP_WRITE(mcbsp, MCR1, config->mcr1); in omap_mcbsp_config()
191 MCBSP_WRITE(mcbsp, PCR0, config->pcr0); in omap_mcbsp_config()
192 if (mcbsp->pdata->has_ccr) { in omap_mcbsp_config()
193 MCBSP_WRITE(mcbsp, XCCR, config->xccr); in omap_mcbsp_config()
194 MCBSP_WRITE(mcbsp, RCCR, config->rccr); in omap_mcbsp_config()
197 if (mcbsp->pdata->has_wakeup) in omap_mcbsp_config()
201 if (mcbsp->irq) in omap_mcbsp_config()
207 * omap_mcbsp_dma_reg_params - returns the address of mcbsp data register
220 if (mcbsp->pdata->reg_size == 2) in omap_mcbsp_dma_reg_params()
225 if (mcbsp->pdata->reg_size == 2) in omap_mcbsp_dma_reg_params()
231 return mcbsp->phys_dma_base + data_reg * mcbsp->pdata->reg_step; in omap_mcbsp_dma_reg_params()
236 * The threshold parameter is 1 based, and it is converted (threshold - 1)
241 if (threshold && threshold <= mcbsp->max_tx_thres) in omap_mcbsp_set_tx_threshold()
242 MCBSP_WRITE(mcbsp, THRSH2, threshold - 1); in omap_mcbsp_set_tx_threshold()
247 * The threshold parameter is 1 based, and it is converted (threshold - 1)
252 if (threshold && threshold <= mcbsp->max_rx_thres) in omap_mcbsp_set_rx_threshold()
253 MCBSP_WRITE(mcbsp, THRSH1, threshold - 1); in omap_mcbsp_set_rx_threshold()
267 return mcbsp->pdata->buffer_size - buffstat; in omap_mcbsp_get_tx_delay()
287 return threshold - buffstat; in omap_mcbsp_get_rx_delay()
295 reg_cache = kzalloc(mcbsp->reg_cache_size, GFP_KERNEL); in omap_mcbsp_request()
297 return -ENOMEM; in omap_mcbsp_request()
299 spin_lock(&mcbsp->lock); in omap_mcbsp_request()
300 if (!mcbsp->free) { in omap_mcbsp_request()
301 dev_err(mcbsp->dev, "McBSP%d is currently in use\n", mcbsp->id); in omap_mcbsp_request()
302 err = -EBUSY; in omap_mcbsp_request()
306 mcbsp->free = false; in omap_mcbsp_request()
307 mcbsp->reg_cache = reg_cache; in omap_mcbsp_request()
308 spin_unlock(&mcbsp->lock); in omap_mcbsp_request()
310 if(mcbsp->pdata->ops && mcbsp->pdata->ops->request) in omap_mcbsp_request()
311 mcbsp->pdata->ops->request(mcbsp->id - 1); in omap_mcbsp_request()
314 * Make sure that transmitter, receiver and sample-rate generator are in omap_mcbsp_request()
320 if (mcbsp->irq) { in omap_mcbsp_request()
321 err = request_irq(mcbsp->irq, omap_mcbsp_irq_handler, 0, in omap_mcbsp_request()
324 dev_err(mcbsp->dev, "Unable to request IRQ\n"); in omap_mcbsp_request()
328 err = request_irq(mcbsp->tx_irq, omap_mcbsp_tx_irq_handler, 0, in omap_mcbsp_request()
331 dev_err(mcbsp->dev, "Unable to request TX IRQ\n"); in omap_mcbsp_request()
335 err = request_irq(mcbsp->rx_irq, omap_mcbsp_rx_irq_handler, 0, in omap_mcbsp_request()
338 dev_err(mcbsp->dev, "Unable to request RX IRQ\n"); in omap_mcbsp_request()
345 free_irq(mcbsp->tx_irq, (void *)mcbsp); in omap_mcbsp_request()
347 if(mcbsp->pdata->ops && mcbsp->pdata->ops->free) in omap_mcbsp_request()
348 mcbsp->pdata->ops->free(mcbsp->id - 1); in omap_mcbsp_request()
351 if (mcbsp->pdata->has_wakeup) in omap_mcbsp_request()
354 spin_lock(&mcbsp->lock); in omap_mcbsp_request()
355 mcbsp->free = true; in omap_mcbsp_request()
356 mcbsp->reg_cache = NULL; in omap_mcbsp_request()
358 spin_unlock(&mcbsp->lock); in omap_mcbsp_request()
368 if(mcbsp->pdata->ops && mcbsp->pdata->ops->free) in omap_mcbsp_free()
369 mcbsp->pdata->ops->free(mcbsp->id - 1); in omap_mcbsp_free()
372 if (mcbsp->pdata->has_wakeup) in omap_mcbsp_free()
376 if (mcbsp->irq) { in omap_mcbsp_free()
379 free_irq(mcbsp->irq, (void *)mcbsp); in omap_mcbsp_free()
381 free_irq(mcbsp->rx_irq, (void *)mcbsp); in omap_mcbsp_free()
382 free_irq(mcbsp->tx_irq, (void *)mcbsp); in omap_mcbsp_free()
385 reg_cache = mcbsp->reg_cache; in omap_mcbsp_free()
388 * Select CLKS source from internal source unconditionally before in omap_mcbsp_free()
392 * back to internal source. in omap_mcbsp_free()
397 spin_lock(&mcbsp->lock); in omap_mcbsp_free()
398 if (mcbsp->free) in omap_mcbsp_free()
399 dev_err(mcbsp->dev, "McBSP%d was not reserved\n", mcbsp->id); in omap_mcbsp_free()
401 mcbsp->free = true; in omap_mcbsp_free()
402 mcbsp->reg_cache = NULL; in omap_mcbsp_free()
403 spin_unlock(&mcbsp->lock); in omap_mcbsp_free()
410 * If no transmitter or receiver is active prior calling, then sample-rate
420 if (mcbsp->st_data) in omap_mcbsp_start()
458 if (mcbsp->pdata->has_ccr) { in omap_mcbsp_start()
481 if (mcbsp->pdata->has_ccr) { in omap_mcbsp_stop()
491 if (mcbsp->pdata->has_ccr) { in omap_mcbsp_stop()
508 if (mcbsp->st_data) in omap_mcbsp_stop()
512 #define max_thres(m) (mcbsp->pdata->buffer_size)
520 return sysfs_emit(buf, "%u\n", mcbsp->prop); \
536 return -EDOM; \
538 mcbsp->prop = val; \
559 dma_op_mode = mcbsp->dma_op_mode; in dma_op_mode_show()
583 spin_lock_irq(&mcbsp->lock); in dma_op_mode_store()
584 if (!mcbsp->free) { in dma_op_mode_store()
585 size = -EBUSY; in dma_op_mode_store()
588 mcbsp->dma_op_mode = i; in dma_op_mode_store()
591 spin_unlock_irq(&mcbsp->lock); in dma_op_mode_store()
619 spin_lock_init(&mcbsp->lock); in omap_mcbsp_init()
620 mcbsp->free = true; in omap_mcbsp_init()
626 mcbsp->io_base = devm_ioremap_resource(&pdev->dev, res); in omap_mcbsp_init()
627 if (IS_ERR(mcbsp->io_base)) in omap_mcbsp_init()
628 return PTR_ERR(mcbsp->io_base); in omap_mcbsp_init()
630 mcbsp->phys_base = res->start; in omap_mcbsp_init()
631 mcbsp->reg_cache_size = resource_size(res); in omap_mcbsp_init()
635 mcbsp->phys_dma_base = mcbsp->phys_base; in omap_mcbsp_init()
637 mcbsp->phys_dma_base = res->start; in omap_mcbsp_init()
643 * Use the combined IRQ if available since it gives better debugging in omap_mcbsp_init()
646 mcbsp->irq = platform_get_irq_byname(pdev, "common"); in omap_mcbsp_init()
647 if (mcbsp->irq == -ENXIO) { in omap_mcbsp_init()
648 mcbsp->tx_irq = platform_get_irq_byname(pdev, "tx"); in omap_mcbsp_init()
650 if (mcbsp->tx_irq == -ENXIO) { in omap_mcbsp_init()
651 mcbsp->irq = platform_get_irq(pdev, 0); in omap_mcbsp_init()
652 mcbsp->tx_irq = 0; in omap_mcbsp_init()
654 mcbsp->rx_irq = platform_get_irq_byname(pdev, "rx"); in omap_mcbsp_init()
655 mcbsp->irq = 0; in omap_mcbsp_init()
659 if (!pdev->dev.of_node) { in omap_mcbsp_init()
662 dev_err(&pdev->dev, "invalid tx DMA channel\n"); in omap_mcbsp_init()
663 return -ENODEV; in omap_mcbsp_init()
665 mcbsp->dma_req[0] = res->start; in omap_mcbsp_init()
666 mcbsp->dma_data[0].filter_data = &mcbsp->dma_req[0]; in omap_mcbsp_init()
670 dev_err(&pdev->dev, "invalid rx DMA channel\n"); in omap_mcbsp_init()
671 return -ENODEV; in omap_mcbsp_init()
673 mcbsp->dma_req[1] = res->start; in omap_mcbsp_init()
674 mcbsp->dma_data[1].filter_data = &mcbsp->dma_req[1]; in omap_mcbsp_init()
676 mcbsp->dma_data[0].filter_data = "tx"; in omap_mcbsp_init()
677 mcbsp->dma_data[1].filter_data = "rx"; in omap_mcbsp_init()
680 mcbsp->dma_data[0].addr = omap_mcbsp_dma_reg_params(mcbsp, in omap_mcbsp_init()
682 mcbsp->dma_data[1].addr = omap_mcbsp_dma_reg_params(mcbsp, in omap_mcbsp_init()
685 mcbsp->fclk = devm_clk_get(&pdev->dev, "fck"); in omap_mcbsp_init()
686 if (IS_ERR(mcbsp->fclk)) { in omap_mcbsp_init()
687 ret = PTR_ERR(mcbsp->fclk); in omap_mcbsp_init()
688 dev_err(mcbsp->dev, "unable to get fck: %d\n", ret); in omap_mcbsp_init()
692 mcbsp->dma_op_mode = MCBSP_DMA_MODE_ELEMENT; in omap_mcbsp_init()
693 if (mcbsp->pdata->buffer_size) { in omap_mcbsp_init()
702 mcbsp->max_tx_thres = max_thres(mcbsp) - 0x10; in omap_mcbsp_init()
703 mcbsp->max_rx_thres = max_thres(mcbsp) - 0x10; in omap_mcbsp_init()
705 ret = devm_device_add_group(mcbsp->dev, &additional_attr_group); in omap_mcbsp_init()
707 dev_err(mcbsp->dev, in omap_mcbsp_init()
729 if (mcbsp->pdata->buffer_size == 0) in omap_mcbsp_set_threshold()
735 * period size in THRESHOLD mode, otherwise use McBSP threshold = 1 in omap_mcbsp_set_threshold()
743 /* Configure McBSP internal buffer usage */ in omap_mcbsp_set_threshold()
744 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) in omap_mcbsp_set_threshold()
757 struct omap_mcbsp *mcbsp = rule->private; in omap_mcbsp_hwrule_min_buffersize()
762 size = mcbsp->pdata->buffer_size; in omap_mcbsp_hwrule_min_buffersize()
764 frames.min = size / channels->min; in omap_mcbsp_hwrule_min_buffersize()
793 if (mcbsp->pdata->buffer_size) { in omap_mcbsp_dai_startup()
799 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) in omap_mcbsp_dai_startup()
800 snd_pcm_hw_rule_add(substream->runtime, 0, in omap_mcbsp_dai_startup()
804 SNDRV_PCM_HW_PARAM_CHANNELS, -1); in omap_mcbsp_dai_startup()
807 snd_pcm_hw_constraint_step(substream->runtime, 0, in omap_mcbsp_dai_startup()
818 int tx = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK); in omap_mcbsp_dai_shutdown()
822 if (mcbsp->latency[stream2]) in omap_mcbsp_dai_shutdown()
823 cpu_latency_qos_update_request(&mcbsp->pm_qos_req, in omap_mcbsp_dai_shutdown()
824 mcbsp->latency[stream2]); in omap_mcbsp_dai_shutdown()
825 else if (mcbsp->latency[stream1]) in omap_mcbsp_dai_shutdown()
826 cpu_latency_qos_remove_request(&mcbsp->pm_qos_req); in omap_mcbsp_dai_shutdown()
828 mcbsp->latency[stream1] = 0; in omap_mcbsp_dai_shutdown()
832 mcbsp->configured = 0; in omap_mcbsp_dai_shutdown()
840 struct pm_qos_request *pm_qos_req = &mcbsp->pm_qos_req; in omap_mcbsp_dai_prepare()
841 int tx = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK); in omap_mcbsp_dai_prepare()
844 int latency = mcbsp->latency[stream2]; in omap_mcbsp_dai_prepare()
847 if (!latency || mcbsp->latency[stream1] < latency) in omap_mcbsp_dai_prepare()
848 latency = mcbsp->latency[stream1]; in omap_mcbsp_dai_prepare()
867 mcbsp->active++; in omap_mcbsp_dai_trigger()
868 omap_mcbsp_start(mcbsp, substream->stream); in omap_mcbsp_dai_trigger()
874 omap_mcbsp_stop(mcbsp, substream->stream); in omap_mcbsp_dai_trigger()
875 mcbsp->active--; in omap_mcbsp_dai_trigger()
878 return -EINVAL; in omap_mcbsp_dai_trigger()
895 if (mcbsp->pdata->buffer_size == 0) in omap_mcbsp_dai_delay()
898 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) in omap_mcbsp_dai_delay()
908 delay = fifo_use / substream->runtime->channels; in omap_mcbsp_dai_delay()
918 struct omap_mcbsp_reg_cfg *regs = &mcbsp->cfg_regs; in omap_mcbsp_dai_hw_params()
923 unsigned int buffer_size = mcbsp->pdata->buffer_size; in omap_mcbsp_dai_hw_params()
936 return -EINVAL; in omap_mcbsp_dai_hw_params()
941 if (mcbsp->dma_op_mode == MCBSP_DMA_MODE_THRESHOLD) { in omap_mcbsp_dai_hw_params()
943 int divider = 0; in omap_mcbsp_dai_hw_params() local
946 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) in omap_mcbsp_dai_hw_params()
947 max_thrsh = mcbsp->max_tx_thres; in omap_mcbsp_dai_hw_params()
949 max_thrsh = mcbsp->max_rx_thres; in omap_mcbsp_dai_hw_params()
951 * Use sDMA packet mode if McBSP is in threshold mode: in omap_mcbsp_dai_hw_params()
957 divider = period_words / max_thrsh; in omap_mcbsp_dai_hw_params()
959 divider++; in omap_mcbsp_dai_hw_params()
960 while (period_words % divider && in omap_mcbsp_dai_hw_params()
961 divider < period_words) in omap_mcbsp_dai_hw_params()
962 divider++; in omap_mcbsp_dai_hw_params()
963 if (divider == period_words) in omap_mcbsp_dai_hw_params()
964 return -EINVAL; in omap_mcbsp_dai_hw_params()
966 pkt_size = period_words / divider; in omap_mcbsp_dai_hw_params()
968 /* Use packet mode for non mono streams */ in omap_mcbsp_dai_hw_params()
972 latency = (buffer_size - pkt_size) / channels; in omap_mcbsp_dai_hw_params()
974 (params->rate_num / params->rate_den); in omap_mcbsp_dai_hw_params()
975 mcbsp->latency[substream->stream] = latency; in omap_mcbsp_dai_hw_params()
980 dma_data->maxburst = pkt_size; in omap_mcbsp_dai_hw_params()
982 if (mcbsp->configured) { in omap_mcbsp_dai_hw_params()
987 regs->rcr2 &= ~(RPHASE | RFRLEN2(0x7f) | RWDLEN2(7)); in omap_mcbsp_dai_hw_params()
988 regs->xcr2 &= ~(RPHASE | XFRLEN2(0x7f) | XWDLEN2(7)); in omap_mcbsp_dai_hw_params()
989 regs->rcr1 &= ~(RFRLEN1(0x7f) | RWDLEN1(7)); in omap_mcbsp_dai_hw_params()
990 regs->xcr1 &= ~(XFRLEN1(0x7f) | XWDLEN1(7)); in omap_mcbsp_dai_hw_params()
991 format = mcbsp->fmt & SND_SOC_DAIFMT_FORMAT_MASK; in omap_mcbsp_dai_hw_params()
995 /* Use dual-phase frames */ in omap_mcbsp_dai_hw_params()
996 regs->rcr2 |= RPHASE; in omap_mcbsp_dai_hw_params()
997 regs->xcr2 |= XPHASE; in omap_mcbsp_dai_hw_params()
999 wpf--; in omap_mcbsp_dai_hw_params()
1000 regs->rcr2 |= RFRLEN2(wpf - 1); in omap_mcbsp_dai_hw_params()
1001 regs->xcr2 |= XFRLEN2(wpf - 1); in omap_mcbsp_dai_hw_params()
1004 regs->rcr1 |= RFRLEN1(wpf - 1); in omap_mcbsp_dai_hw_params()
1005 regs->xcr1 |= XFRLEN1(wpf - 1); in omap_mcbsp_dai_hw_params()
1010 regs->rcr2 |= RWDLEN2(OMAP_MCBSP_WORD_16); in omap_mcbsp_dai_hw_params()
1011 regs->rcr1 |= RWDLEN1(OMAP_MCBSP_WORD_16); in omap_mcbsp_dai_hw_params()
1012 regs->xcr2 |= XWDLEN2(OMAP_MCBSP_WORD_16); in omap_mcbsp_dai_hw_params()
1013 regs->xcr1 |= XWDLEN1(OMAP_MCBSP_WORD_16); in omap_mcbsp_dai_hw_params()
1017 regs->rcr2 |= RWDLEN2(OMAP_MCBSP_WORD_32); in omap_mcbsp_dai_hw_params()
1018 regs->rcr1 |= RWDLEN1(OMAP_MCBSP_WORD_32); in omap_mcbsp_dai_hw_params()
1019 regs->xcr2 |= XWDLEN2(OMAP_MCBSP_WORD_32); in omap_mcbsp_dai_hw_params()
1020 regs->xcr1 |= XWDLEN1(OMAP_MCBSP_WORD_32); in omap_mcbsp_dai_hw_params()
1024 return -EINVAL; in omap_mcbsp_dai_hw_params()
1029 master = mcbsp->fmt & SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK; in omap_mcbsp_dai_hw_params()
1031 div = mcbsp->clk_div ? mcbsp->clk_div : 1; in omap_mcbsp_dai_hw_params()
1032 framesize = (mcbsp->in_freq / div) / params_rate(params); in omap_mcbsp_dai_hw_params()
1037 return -EINVAL; in omap_mcbsp_dai_hw_params()
1043 regs->srgr2 &= ~FPER(0xfff); in omap_mcbsp_dai_hw_params()
1044 regs->srgr1 &= ~FWID(0xff); in omap_mcbsp_dai_hw_params()
1048 regs->srgr2 |= FPER(framesize - 1); in omap_mcbsp_dai_hw_params()
1049 regs->srgr1 |= FWID((framesize >> 1) - 1); in omap_mcbsp_dai_hw_params()
1053 regs->srgr2 |= FPER(framesize - 1); in omap_mcbsp_dai_hw_params()
1054 regs->srgr1 |= FWID(0); in omap_mcbsp_dai_hw_params()
1058 omap_mcbsp_config(mcbsp, &mcbsp->cfg_regs); in omap_mcbsp_dai_hw_params()
1059 mcbsp->wlen = wlen; in omap_mcbsp_dai_hw_params()
1060 mcbsp->configured = 1; in omap_mcbsp_dai_hw_params()
1073 struct omap_mcbsp_reg_cfg *regs = &mcbsp->cfg_regs; in omap_mcbsp_dai_set_dai_fmt()
1076 if (mcbsp->configured) in omap_mcbsp_dai_set_dai_fmt()
1079 mcbsp->fmt = fmt; in omap_mcbsp_dai_set_dai_fmt()
1082 regs->spcr2 |= XINTM(3) | FREE; in omap_mcbsp_dai_set_dai_fmt()
1083 regs->spcr1 |= RINTM(3); in omap_mcbsp_dai_set_dai_fmt()
1085 if (!mcbsp->pdata->has_ccr) { in omap_mcbsp_dai_set_dai_fmt()
1086 regs->rcr2 |= RFIG; in omap_mcbsp_dai_set_dai_fmt()
1087 regs->xcr2 |= XFIG; in omap_mcbsp_dai_set_dai_fmt()
1091 if (mcbsp->pdata->has_ccr) { in omap_mcbsp_dai_set_dai_fmt()
1092 regs->xccr = DXENDLY(1) | XDMAEN | XDISABLE; in omap_mcbsp_dai_set_dai_fmt()
1093 regs->rccr = RFULL_CYCLE | RDMAEN | RDISABLE; in omap_mcbsp_dai_set_dai_fmt()
1098 /* 1-bit data delay */ in omap_mcbsp_dai_set_dai_fmt()
1099 regs->rcr2 |= RDATDLY(1); in omap_mcbsp_dai_set_dai_fmt()
1100 regs->xcr2 |= XDATDLY(1); in omap_mcbsp_dai_set_dai_fmt()
1103 /* 0-bit data delay */ in omap_mcbsp_dai_set_dai_fmt()
1104 regs->rcr2 |= RDATDLY(0); in omap_mcbsp_dai_set_dai_fmt()
1105 regs->xcr2 |= XDATDLY(0); in omap_mcbsp_dai_set_dai_fmt()
1106 regs->spcr1 |= RJUST(2); in omap_mcbsp_dai_set_dai_fmt()
1111 /* 1-bit data delay */ in omap_mcbsp_dai_set_dai_fmt()
1112 regs->rcr2 |= RDATDLY(1); in omap_mcbsp_dai_set_dai_fmt()
1113 regs->xcr2 |= XDATDLY(1); in omap_mcbsp_dai_set_dai_fmt()
1118 /* 0-bit data delay */ in omap_mcbsp_dai_set_dai_fmt()
1119 regs->rcr2 |= RDATDLY(0); in omap_mcbsp_dai_set_dai_fmt()
1120 regs->xcr2 |= XDATDLY(0); in omap_mcbsp_dai_set_dai_fmt()
1126 return -EINVAL; in omap_mcbsp_dai_set_dai_fmt()
1132 regs->pcr0 |= FSXM | FSRM | in omap_mcbsp_dai_set_dai_fmt()
1135 regs->srgr2 |= FSGM; in omap_mcbsp_dai_set_dai_fmt()
1139 regs->srgr2 |= FSGM; in omap_mcbsp_dai_set_dai_fmt()
1140 regs->pcr0 |= FSXM | FSRM; in omap_mcbsp_dai_set_dai_fmt()
1147 return -EINVAL; in omap_mcbsp_dai_set_dai_fmt()
1158 regs->pcr0 |= FSXP | FSRP | in omap_mcbsp_dai_set_dai_fmt()
1162 regs->pcr0 |= CLKXP | CLKRP; in omap_mcbsp_dai_set_dai_fmt()
1165 regs->pcr0 |= FSXP | FSRP; in omap_mcbsp_dai_set_dai_fmt()
1170 return -EINVAL; in omap_mcbsp_dai_set_dai_fmt()
1173 regs->pcr0 ^= FSXP | FSRP; in omap_mcbsp_dai_set_dai_fmt()
1182 struct omap_mcbsp_reg_cfg *regs = &mcbsp->cfg_regs; in omap_mcbsp_dai_set_clkdiv()
1185 return -ENODEV; in omap_mcbsp_dai_set_clkdiv()
1187 mcbsp->clk_div = div; in omap_mcbsp_dai_set_clkdiv()
1188 regs->srgr1 &= ~CLKGDV(0xff); in omap_mcbsp_dai_set_clkdiv()
1189 regs->srgr1 |= CLKGDV(div - 1); in omap_mcbsp_dai_set_clkdiv()
1199 struct omap_mcbsp_reg_cfg *regs = &mcbsp->cfg_regs; in omap_mcbsp_dai_set_dai_sysclk()
1202 if (mcbsp->active) { in omap_mcbsp_dai_set_dai_sysclk()
1203 if (freq == mcbsp->in_freq) in omap_mcbsp_dai_set_dai_sysclk()
1206 return -EBUSY; in omap_mcbsp_dai_set_dai_sysclk()
1209 mcbsp->in_freq = freq; in omap_mcbsp_dai_set_dai_sysclk()
1210 regs->srgr2 &= ~CLKSM; in omap_mcbsp_dai_set_dai_sysclk()
1211 regs->pcr0 &= ~SCLKME; in omap_mcbsp_dai_set_dai_sysclk()
1215 regs->srgr2 |= CLKSM; in omap_mcbsp_dai_set_dai_sysclk()
1219 err = -EINVAL; in omap_mcbsp_dai_set_dai_sysclk()
1235 regs->srgr2 |= CLKSM; in omap_mcbsp_dai_set_dai_sysclk()
1236 regs->pcr0 |= SCLKME; in omap_mcbsp_dai_set_dai_sysclk()
1243 regs->pcr0 &= ~CLKXM; in omap_mcbsp_dai_set_dai_sysclk()
1246 regs->pcr0 |= SCLKME; in omap_mcbsp_dai_set_dai_sysclk()
1248 regs->pcr0 &= ~CLKRM; in omap_mcbsp_dai_set_dai_sysclk()
1251 err = -ENODEV; in omap_mcbsp_dai_set_dai_sysclk()
1273 pm_runtime_enable(mcbsp->dev); in omap_mcbsp_probe()
1276 &mcbsp->dma_data[SNDRV_PCM_STREAM_PLAYBACK], in omap_mcbsp_probe()
1277 &mcbsp->dma_data[SNDRV_PCM_STREAM_CAPTURE]); in omap_mcbsp_probe()
1286 pm_runtime_disable(mcbsp->dev); in omap_mcbsp_remove()
1310 .name = "omap-mcbsp",
1341 .compatible = "ti,omap2420-mcbsp",
1345 .compatible = "ti,omap2430-mcbsp",
1349 .compatible = "ti,omap3-mcbsp",
1353 .compatible = "ti,omap4-mcbsp",
1362 struct omap_mcbsp_platform_data *pdata = dev_get_platdata(&pdev->dev); in asoc_mcbsp_probe()
1367 match = of_match_device(omap_mcbsp_of_match, &pdev->dev); in asoc_mcbsp_probe()
1369 struct device_node *node = pdev->dev.of_node; in asoc_mcbsp_probe()
1373 pdata = devm_kzalloc(&pdev->dev, in asoc_mcbsp_probe()
1377 return -ENOMEM; in asoc_mcbsp_probe()
1379 memcpy(pdata, match->data, sizeof(*pdata)); in asoc_mcbsp_probe()
1380 if (!of_property_read_u32(node, "ti,buffer-size", &buffer_size)) in asoc_mcbsp_probe()
1381 pdata->buffer_size = buffer_size; in asoc_mcbsp_probe()
1383 pdata->force_ick_on = pdata_quirk->force_ick_on; in asoc_mcbsp_probe()
1385 dev_err(&pdev->dev, "missing platform data.\n"); in asoc_mcbsp_probe()
1386 return -EINVAL; in asoc_mcbsp_probe()
1388 mcbsp = devm_kzalloc(&pdev->dev, sizeof(struct omap_mcbsp), GFP_KERNEL); in asoc_mcbsp_probe()
1390 return -ENOMEM; in asoc_mcbsp_probe()
1392 mcbsp->id = pdev->id; in asoc_mcbsp_probe()
1393 mcbsp->pdata = pdata; in asoc_mcbsp_probe()
1394 mcbsp->dev = &pdev->dev; in asoc_mcbsp_probe()
1401 if (mcbsp->pdata->reg_size == 2) { in asoc_mcbsp_probe()
1406 ret = devm_snd_soc_register_component(&pdev->dev, in asoc_mcbsp_probe()
1412 return sdma_pcm_platform_register(&pdev->dev, "tx", "rx"); in asoc_mcbsp_probe()
1419 if (mcbsp->pdata->ops && mcbsp->pdata->ops->free) in asoc_mcbsp_remove()
1420 mcbsp->pdata->ops->free(mcbsp->id); in asoc_mcbsp_remove()
1422 if (cpu_latency_qos_request_active(&mcbsp->pm_qos_req)) in asoc_mcbsp_remove()
1423 cpu_latency_qos_remove_request(&mcbsp->pm_qos_req); in asoc_mcbsp_remove()
1430 .name = "omap-mcbsp",
1443 MODULE_ALIAS("platform:omap-mcbsp");