Lines Matching refs:mcdt
118 static void sprd_mcdt_update(struct sprd_mcdt_dev *mcdt, u32 reg, u32 val, in sprd_mcdt_update() argument
121 u32 orig = readl_relaxed(mcdt->base + reg); in sprd_mcdt_update()
125 writel_relaxed(tmp, mcdt->base + reg); in sprd_mcdt_update()
128 static void sprd_mcdt_dac_set_watermark(struct sprd_mcdt_dev *mcdt, u8 channel, in sprd_mcdt_dac_set_watermark() argument
136 sprd_mcdt_update(mcdt, reg, water_mark, in sprd_mcdt_dac_set_watermark()
140 static void sprd_mcdt_adc_set_watermark(struct sprd_mcdt_dev *mcdt, u8 channel, in sprd_mcdt_adc_set_watermark() argument
148 sprd_mcdt_update(mcdt, reg, water_mark, in sprd_mcdt_adc_set_watermark()
152 static void sprd_mcdt_dac_dma_enable(struct sprd_mcdt_dev *mcdt, u8 channel, in sprd_mcdt_dac_dma_enable() argument
158 sprd_mcdt_update(mcdt, MCDT_DMA_EN, BIT(shift), BIT(shift)); in sprd_mcdt_dac_dma_enable()
160 sprd_mcdt_update(mcdt, MCDT_DMA_EN, 0, BIT(shift)); in sprd_mcdt_dac_dma_enable()
163 static void sprd_mcdt_adc_dma_enable(struct sprd_mcdt_dev *mcdt, u8 channel, in sprd_mcdt_adc_dma_enable() argument
167 sprd_mcdt_update(mcdt, MCDT_DMA_EN, BIT(channel), BIT(channel)); in sprd_mcdt_adc_dma_enable()
169 sprd_mcdt_update(mcdt, MCDT_DMA_EN, 0, BIT(channel)); in sprd_mcdt_adc_dma_enable()
172 static void sprd_mcdt_ap_int_enable(struct sprd_mcdt_dev *mcdt, u8 channel, in sprd_mcdt_ap_int_enable() argument
176 sprd_mcdt_update(mcdt, MCDT_INT_MSK_CFG0, BIT(channel), in sprd_mcdt_ap_int_enable()
179 sprd_mcdt_update(mcdt, MCDT_INT_MSK_CFG0, 0, BIT(channel)); in sprd_mcdt_ap_int_enable()
182 static void sprd_mcdt_dac_write_fifo(struct sprd_mcdt_dev *mcdt, u8 channel, in sprd_mcdt_dac_write_fifo() argument
187 writel_relaxed(val, mcdt->base + reg); in sprd_mcdt_dac_write_fifo()
190 static void sprd_mcdt_adc_read_fifo(struct sprd_mcdt_dev *mcdt, u8 channel, in sprd_mcdt_adc_read_fifo() argument
195 *val = readl_relaxed(mcdt->base + reg); in sprd_mcdt_adc_read_fifo()
198 static void sprd_mcdt_dac_dma_chn_select(struct sprd_mcdt_dev *mcdt, u8 channel, in sprd_mcdt_dac_dma_chn_select() argument
203 sprd_mcdt_update(mcdt, MCDT_DMA_CFG0, in sprd_mcdt_dac_dma_chn_select()
209 sprd_mcdt_update(mcdt, MCDT_DMA_CFG0, in sprd_mcdt_dac_dma_chn_select()
215 sprd_mcdt_update(mcdt, MCDT_DMA_CFG0, in sprd_mcdt_dac_dma_chn_select()
221 sprd_mcdt_update(mcdt, MCDT_DMA_CFG0, in sprd_mcdt_dac_dma_chn_select()
227 sprd_mcdt_update(mcdt, MCDT_DMA_CFG0, in sprd_mcdt_dac_dma_chn_select()
234 static void sprd_mcdt_adc_dma_chn_select(struct sprd_mcdt_dev *mcdt, u8 channel, in sprd_mcdt_adc_dma_chn_select() argument
239 sprd_mcdt_update(mcdt, MCDT_DMA_CFG1, in sprd_mcdt_adc_dma_chn_select()
245 sprd_mcdt_update(mcdt, MCDT_DMA_CFG1, in sprd_mcdt_adc_dma_chn_select()
251 sprd_mcdt_update(mcdt, MCDT_DMA_CFG1, in sprd_mcdt_adc_dma_chn_select()
257 sprd_mcdt_update(mcdt, MCDT_DMA_CFG1, in sprd_mcdt_adc_dma_chn_select()
263 sprd_mcdt_update(mcdt, MCDT_DMA_CFG1, in sprd_mcdt_adc_dma_chn_select()
295 static void sprd_mcdt_dac_dma_ack_select(struct sprd_mcdt_dev *mcdt, u8 channel, in sprd_mcdt_dac_dma_ack_select() argument
313 sprd_mcdt_update(mcdt, reg, ack << shift, in sprd_mcdt_dac_dma_ack_select()
317 static void sprd_mcdt_adc_dma_ack_select(struct sprd_mcdt_dev *mcdt, u8 channel, in sprd_mcdt_adc_dma_ack_select() argument
335 sprd_mcdt_update(mcdt, reg, ack << shift, in sprd_mcdt_adc_dma_ack_select()
339 static bool sprd_mcdt_chan_fifo_sts(struct sprd_mcdt_dev *mcdt, u8 channel, in sprd_mcdt_chan_fifo_sts() argument
385 return !!(readl_relaxed(mcdt->base + reg) & BIT(shift)); in sprd_mcdt_chan_fifo_sts()
388 static void sprd_mcdt_dac_fifo_clear(struct sprd_mcdt_dev *mcdt, u8 channel) in sprd_mcdt_dac_fifo_clear() argument
390 sprd_mcdt_update(mcdt, MCDT_FIFO_CLR, BIT(channel), BIT(channel)); in sprd_mcdt_dac_fifo_clear()
393 static void sprd_mcdt_adc_fifo_clear(struct sprd_mcdt_dev *mcdt, u8 channel) in sprd_mcdt_adc_fifo_clear() argument
397 sprd_mcdt_update(mcdt, MCDT_FIFO_CLR, BIT(shift), BIT(shift)); in sprd_mcdt_adc_fifo_clear()
400 static u32 sprd_mcdt_dac_fifo_avail(struct sprd_mcdt_dev *mcdt, u8 channel) in sprd_mcdt_dac_fifo_avail() argument
403 u32 r_addr = (readl_relaxed(mcdt->base + reg) >> in sprd_mcdt_dac_fifo_avail()
405 u32 w_addr = readl_relaxed(mcdt->base + reg) & MCDT_CH_FIFO_ADDR_MASK; in sprd_mcdt_dac_fifo_avail()
413 static u32 sprd_mcdt_adc_fifo_avail(struct sprd_mcdt_dev *mcdt, u8 channel) in sprd_mcdt_adc_fifo_avail() argument
416 u32 r_addr = (readl_relaxed(mcdt->base + reg) >> in sprd_mcdt_adc_fifo_avail()
418 u32 w_addr = readl_relaxed(mcdt->base + reg) & MCDT_CH_FIFO_ADDR_MASK; in sprd_mcdt_adc_fifo_avail()
453 static void sprd_mcdt_chan_int_en(struct sprd_mcdt_dev *mcdt, u8 channel, in sprd_mcdt_chan_int_en() argument
473 sprd_mcdt_update(mcdt, reg, BIT(shift), BIT(shift)); in sprd_mcdt_chan_int_en()
475 sprd_mcdt_update(mcdt, reg, 0, BIT(shift)); in sprd_mcdt_chan_int_en()
478 static void sprd_mcdt_chan_int_clear(struct sprd_mcdt_dev *mcdt, u8 channel, in sprd_mcdt_chan_int_clear() argument
497 sprd_mcdt_update(mcdt, reg, BIT(shift), BIT(shift)); in sprd_mcdt_chan_int_clear()
500 static bool sprd_mcdt_chan_int_sts(struct sprd_mcdt_dev *mcdt, u8 channel, in sprd_mcdt_chan_int_sts() argument
519 return !!(readl_relaxed(mcdt->base + reg) & BIT(shift)); in sprd_mcdt_chan_int_sts()
524 struct sprd_mcdt_dev *mcdt = (struct sprd_mcdt_dev *)dev_id; in sprd_mcdt_irq_handler() local
527 spin_lock(&mcdt->lock); in sprd_mcdt_irq_handler()
530 if (sprd_mcdt_chan_int_sts(mcdt, i, MCDT_ADC_FIFO_AF_INT)) { in sprd_mcdt_irq_handler()
531 struct sprd_mcdt_chan *chan = &mcdt->chan[i]; in sprd_mcdt_irq_handler()
533 sprd_mcdt_chan_int_clear(mcdt, i, MCDT_ADC_FIFO_AF_INT); in sprd_mcdt_irq_handler()
540 if (sprd_mcdt_chan_int_sts(mcdt, i, MCDT_DAC_FIFO_AE_INT)) { in sprd_mcdt_irq_handler()
542 &mcdt->chan[i + MCDT_ADC_CHANNEL_NUM]; in sprd_mcdt_irq_handler()
544 sprd_mcdt_chan_int_clear(mcdt, i, MCDT_DAC_FIFO_AE_INT); in sprd_mcdt_irq_handler()
550 spin_unlock(&mcdt->lock); in sprd_mcdt_irq_handler()
571 struct sprd_mcdt_dev *mcdt = chan->mcdt; in sprd_mcdt_chan_write() local
576 spin_lock_irqsave(&mcdt->lock, flags); in sprd_mcdt_chan_write()
579 dev_err(mcdt->dev, in sprd_mcdt_chan_write()
581 spin_unlock_irqrestore(&mcdt->lock, flags); in sprd_mcdt_chan_write()
585 if (sprd_mcdt_chan_fifo_sts(mcdt, chan->id, MCDT_DAC_FIFO_REAL_FULL)) { in sprd_mcdt_chan_write()
586 dev_err(mcdt->dev, "Channel fifo is full now\n"); in sprd_mcdt_chan_write()
587 spin_unlock_irqrestore(&mcdt->lock, flags); in sprd_mcdt_chan_write()
591 avail = sprd_mcdt_dac_fifo_avail(mcdt, chan->id); in sprd_mcdt_chan_write()
593 dev_err(mcdt->dev, in sprd_mcdt_chan_write()
595 spin_unlock_irqrestore(&mcdt->lock, flags); in sprd_mcdt_chan_write()
600 sprd_mcdt_dac_write_fifo(mcdt, chan->id, *buf++); in sprd_mcdt_chan_write()
602 spin_unlock_irqrestore(&mcdt->lock, flags); in sprd_mcdt_chan_write()
622 struct sprd_mcdt_dev *mcdt = chan->mcdt; in sprd_mcdt_chan_read() local
627 spin_lock_irqsave(&mcdt->lock, flags); in sprd_mcdt_chan_read()
630 dev_err(mcdt->dev, "Can not read data when DMA mode enabled\n"); in sprd_mcdt_chan_read()
631 spin_unlock_irqrestore(&mcdt->lock, flags); in sprd_mcdt_chan_read()
635 if (sprd_mcdt_chan_fifo_sts(mcdt, chan->id, MCDT_ADC_FIFO_REAL_EMPTY)) { in sprd_mcdt_chan_read()
636 dev_err(mcdt->dev, "Channel fifo is empty\n"); in sprd_mcdt_chan_read()
637 spin_unlock_irqrestore(&mcdt->lock, flags); in sprd_mcdt_chan_read()
641 avail = sprd_mcdt_adc_fifo_avail(mcdt, chan->id); in sprd_mcdt_chan_read()
646 sprd_mcdt_adc_read_fifo(mcdt, chan->id, buf++); in sprd_mcdt_chan_read()
648 spin_unlock_irqrestore(&mcdt->lock, flags); in sprd_mcdt_chan_read()
674 struct sprd_mcdt_dev *mcdt = chan->mcdt; in sprd_mcdt_chan_int_enable() local
678 spin_lock_irqsave(&mcdt->lock, flags); in sprd_mcdt_chan_int_enable()
681 dev_err(mcdt->dev, "Failed to set interrupt mode.\n"); in sprd_mcdt_chan_int_enable()
682 spin_unlock_irqrestore(&mcdt->lock, flags); in sprd_mcdt_chan_int_enable()
688 sprd_mcdt_adc_fifo_clear(mcdt, chan->id); in sprd_mcdt_chan_int_enable()
689 sprd_mcdt_adc_set_watermark(mcdt, chan->id, water_mark, in sprd_mcdt_chan_int_enable()
691 sprd_mcdt_chan_int_en(mcdt, chan->id, in sprd_mcdt_chan_int_enable()
693 sprd_mcdt_ap_int_enable(mcdt, chan->id, true); in sprd_mcdt_chan_int_enable()
697 sprd_mcdt_dac_fifo_clear(mcdt, chan->id); in sprd_mcdt_chan_int_enable()
698 sprd_mcdt_dac_set_watermark(mcdt, chan->id, in sprd_mcdt_chan_int_enable()
700 sprd_mcdt_chan_int_en(mcdt, chan->id, in sprd_mcdt_chan_int_enable()
702 sprd_mcdt_ap_int_enable(mcdt, chan->id, true); in sprd_mcdt_chan_int_enable()
706 dev_err(mcdt->dev, "Unsupported channel type\n"); in sprd_mcdt_chan_int_enable()
715 spin_unlock_irqrestore(&mcdt->lock, flags); in sprd_mcdt_chan_int_enable()
727 struct sprd_mcdt_dev *mcdt = chan->mcdt; in sprd_mcdt_chan_int_disable() local
730 spin_lock_irqsave(&mcdt->lock, flags); in sprd_mcdt_chan_int_disable()
733 spin_unlock_irqrestore(&mcdt->lock, flags); in sprd_mcdt_chan_int_disable()
739 sprd_mcdt_chan_int_en(mcdt, chan->id, in sprd_mcdt_chan_int_disable()
741 sprd_mcdt_chan_int_clear(mcdt, chan->id, MCDT_ADC_FIFO_AF_INT); in sprd_mcdt_chan_int_disable()
742 sprd_mcdt_ap_int_enable(mcdt, chan->id, false); in sprd_mcdt_chan_int_disable()
746 sprd_mcdt_chan_int_en(mcdt, chan->id, in sprd_mcdt_chan_int_disable()
748 sprd_mcdt_chan_int_clear(mcdt, chan->id, MCDT_DAC_FIFO_AE_INT); in sprd_mcdt_chan_int_disable()
749 sprd_mcdt_ap_int_enable(mcdt, chan->id, false); in sprd_mcdt_chan_int_disable()
757 spin_unlock_irqrestore(&mcdt->lock, flags); in sprd_mcdt_chan_int_disable()
777 struct sprd_mcdt_dev *mcdt = chan->mcdt; in sprd_mcdt_chan_dma_enable() local
781 spin_lock_irqsave(&mcdt->lock, flags); in sprd_mcdt_chan_dma_enable()
785 dev_err(mcdt->dev, "Failed to set DMA mode\n"); in sprd_mcdt_chan_dma_enable()
786 spin_unlock_irqrestore(&mcdt->lock, flags); in sprd_mcdt_chan_dma_enable()
792 sprd_mcdt_adc_fifo_clear(mcdt, chan->id); in sprd_mcdt_chan_dma_enable()
793 sprd_mcdt_adc_set_watermark(mcdt, chan->id, in sprd_mcdt_chan_dma_enable()
795 sprd_mcdt_adc_dma_enable(mcdt, chan->id, true); in sprd_mcdt_chan_dma_enable()
796 sprd_mcdt_adc_dma_chn_select(mcdt, chan->id, dma_chan); in sprd_mcdt_chan_dma_enable()
797 sprd_mcdt_adc_dma_ack_select(mcdt, chan->id, dma_chan); in sprd_mcdt_chan_dma_enable()
801 sprd_mcdt_dac_fifo_clear(mcdt, chan->id); in sprd_mcdt_chan_dma_enable()
802 sprd_mcdt_dac_set_watermark(mcdt, chan->id, in sprd_mcdt_chan_dma_enable()
804 sprd_mcdt_dac_dma_enable(mcdt, chan->id, true); in sprd_mcdt_chan_dma_enable()
805 sprd_mcdt_dac_dma_chn_select(mcdt, chan->id, dma_chan); in sprd_mcdt_chan_dma_enable()
806 sprd_mcdt_dac_dma_ack_select(mcdt, chan->id, dma_chan); in sprd_mcdt_chan_dma_enable()
810 dev_err(mcdt->dev, "Unsupported channel type\n"); in sprd_mcdt_chan_dma_enable()
817 spin_unlock_irqrestore(&mcdt->lock, flags); in sprd_mcdt_chan_dma_enable()
829 struct sprd_mcdt_dev *mcdt = chan->mcdt; in sprd_mcdt_chan_dma_disable() local
832 spin_lock_irqsave(&mcdt->lock, flags); in sprd_mcdt_chan_dma_disable()
835 spin_unlock_irqrestore(&mcdt->lock, flags); in sprd_mcdt_chan_dma_disable()
841 sprd_mcdt_adc_dma_enable(mcdt, chan->id, false); in sprd_mcdt_chan_dma_disable()
842 sprd_mcdt_adc_fifo_clear(mcdt, chan->id); in sprd_mcdt_chan_dma_disable()
846 sprd_mcdt_dac_dma_enable(mcdt, chan->id, false); in sprd_mcdt_chan_dma_disable()
847 sprd_mcdt_dac_fifo_clear(mcdt, chan->id); in sprd_mcdt_chan_dma_disable()
855 spin_unlock_irqrestore(&mcdt->lock, flags); in sprd_mcdt_chan_dma_disable()
914 static void sprd_mcdt_init_chans(struct sprd_mcdt_dev *mcdt, in sprd_mcdt_init_chans() argument
920 struct sprd_mcdt_chan *chan = &mcdt->chan[i]; in sprd_mcdt_init_chans()
933 chan->mcdt = mcdt; in sprd_mcdt_init_chans()
944 struct sprd_mcdt_dev *mcdt; in sprd_mcdt_probe() local
948 mcdt = devm_kzalloc(&pdev->dev, sizeof(*mcdt), GFP_KERNEL); in sprd_mcdt_probe()
949 if (!mcdt) in sprd_mcdt_probe()
952 mcdt->base = devm_platform_get_and_ioremap_resource(pdev, 0, &res); in sprd_mcdt_probe()
953 if (IS_ERR(mcdt->base)) in sprd_mcdt_probe()
954 return PTR_ERR(mcdt->base); in sprd_mcdt_probe()
956 mcdt->dev = &pdev->dev; in sprd_mcdt_probe()
957 spin_lock_init(&mcdt->lock); in sprd_mcdt_probe()
958 platform_set_drvdata(pdev, mcdt); in sprd_mcdt_probe()
965 0, "sprd-mcdt", mcdt); in sprd_mcdt_probe()
971 sprd_mcdt_init_chans(mcdt, res); in sprd_mcdt_probe()