⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ppc4xx_dma.c

📁 linux-2.6.15.6
💻 C
📖 第 1 页 / 共 2 页
字号:
				return;		}		if (error)			printk				("Warning: ppc4xx_set_dma_addr2 src 0x%x dst 0x%x bus width %d\n",				 src_dma_addr, dst_dma_addr, p_dma_ch->pwidth);	}#endif	ppc4xx_set_src_addr(dmanr, src_dma_addr);	ppc4xx_set_dst_addr(dmanr, dst_dma_addr);}/* * Enables the channel interrupt. * * If performing a scatter/gatter transfer, this function * MUST be called before calling alloc_dma_handle() and building * the sgl list.  Otherwise, interrupts will not be enabled, if * they were previously disabled. */intppc4xx_enable_dma_interrupt(unsigned int dmanr){	unsigned int control;	ppc_dma_ch_t *p_dma_ch = &dma_channels[dmanr];	if (dmanr >= MAX_PPC4xx_DMA_CHANNELS) {		printk("ppc4xx_enable_dma_interrupt: bad channel: %d\n", dmanr);		return DMA_STATUS_BAD_CHANNEL;	}	p_dma_ch->int_enable = 1;	control = mfdcr(DCRN_DMACR0 + (dmanr * 0x8));	control |= DMA_CIE_ENABLE;	/* Channel Interrupt Enable */	mtdcr(DCRN_DMACR0 + (dmanr * 0x8), control);	return DMA_STATUS_GOOD;}/* * Disables the channel interrupt. * * If performing a scatter/gatter transfer, this function * MUST be called before calling alloc_dma_handle() and building * the sgl list.  Otherwise, interrupts will not be disabled, if * they were previously enabled. */intppc4xx_disable_dma_interrupt(unsigned int dmanr){	unsigned int control;	ppc_dma_ch_t *p_dma_ch = &dma_channels[dmanr];	if (dmanr >= MAX_PPC4xx_DMA_CHANNELS) {		printk("ppc4xx_disable_dma_interrupt: bad channel: %d\n", dmanr);		return DMA_STATUS_BAD_CHANNEL;	}	p_dma_ch->int_enable = 0;	control = mfdcr(DCRN_DMACR0 + (dmanr * 0x8));	control &= ~DMA_CIE_ENABLE;	/* Channel Interrupt Enable */	mtdcr(DCRN_DMACR0 + (dmanr * 0x8), control);	return DMA_STATUS_GOOD;}/* * Configures a DMA channel, including the peripheral bus width, if a * peripheral is attached to the channel, the polarity of the DMAReq and * DMAAck signals, etc.  This information should really be setup by the boot * code, since most likely the configuration won't change dynamically. * If the kernel has to call this function, it's recommended that it's * called from platform specific init code.  The driver should not need to * call this function. */intppc4xx_init_dma_channel(unsigned int dmanr, ppc_dma_ch_t * p_init){	unsigned int polarity;	uint32_t control = 0;	ppc_dma_ch_t *p_dma_ch = &dma_channels[dmanr];	DMA_MODE_READ = (unsigned long) DMA_TD;	/* Peripheral to Memory */	DMA_MODE_WRITE = 0;	/* Memory to Peripheral */	if (!p_init) {		printk("ppc4xx_init_dma_channel: NULL p_init\n");		return DMA_STATUS_NULL_POINTER;	}	if (dmanr >= MAX_PPC4xx_DMA_CHANNELS) {		printk("ppc4xx_init_dma_channel: bad channel %d\n", dmanr);		return DMA_STATUS_BAD_CHANNEL;	}#if DCRN_POL > 0	polarity = mfdcr(DCRN_POL);#else	polarity = 0;#endif	/* Setup the control register based on the values passed to	 * us in p_init.  Then, over-write the control register with this	 * new value.	 */	control |= SET_DMA_CONTROL;	/* clear all polarity signals and then "or" in new signal levels */	polarity &= ~GET_DMA_POLARITY(dmanr);	polarity |= p_init->polarity;#if DCRN_POL > 0	mtdcr(DCRN_POL, polarity);#endif	mtdcr(DCRN_DMACR0 + (dmanr * 0x8), control);	/* save these values in our dma channel structure */	memcpy(p_dma_ch, p_init, sizeof (ppc_dma_ch_t));	/*	 * The peripheral width values written in the control register are:	 *   PW_8                 0	 *   PW_16                1	 *   PW_32                2	 *   PW_64                3	 *	 *   Since the DMA count register takes the number of "transfers",	 *   we need to divide the count sent to us in certain	 *   functions by the appropriate number.  It so happens that our	 *   right shift value is equal to the peripheral width value.	 */	p_dma_ch->shift = p_init->pwidth;	/*	 * Save the control word for easy access.	 */	p_dma_ch->control = control;	mtdcr(DCRN_DMASR, 0xffffffff);	/* clear status register */	return DMA_STATUS_GOOD;}/* * This function returns the channel configuration. */intppc4xx_get_channel_config(unsigned int dmanr, ppc_dma_ch_t * p_dma_ch){	unsigned int polarity;	unsigned int control;	if (dmanr >= MAX_PPC4xx_DMA_CHANNELS) {		printk("ppc4xx_get_channel_config: bad channel %d\n", dmanr);		return DMA_STATUS_BAD_CHANNEL;	}	memcpy(p_dma_ch, &dma_channels[dmanr], sizeof (ppc_dma_ch_t));#if DCRN_POL > 0	polarity = mfdcr(DCRN_POL);#else	polarity = 0;#endif	p_dma_ch->polarity = polarity & GET_DMA_POLARITY(dmanr);	control = mfdcr(DCRN_DMACR0 + (dmanr * 0x8));	p_dma_ch->cp = GET_DMA_PRIORITY(control);	p_dma_ch->pwidth = GET_DMA_PW(control);	p_dma_ch->psc = GET_DMA_PSC(control);	p_dma_ch->pwc = GET_DMA_PWC(control);	p_dma_ch->phc = GET_DMA_PHC(control);	p_dma_ch->ce = GET_DMA_CE_ENABLE(control);	p_dma_ch->int_enable = GET_DMA_CIE_ENABLE(control);	p_dma_ch->shift = GET_DMA_PW(control);#ifdef CONFIG_PPC4xx_EDMA	p_dma_ch->pf = GET_DMA_PREFETCH(control);#else	p_dma_ch->ch_enable = GET_DMA_CH(control);	p_dma_ch->ece_enable = GET_DMA_ECE(control);	p_dma_ch->tcd_disable = GET_DMA_TCD(control);#endif	return DMA_STATUS_GOOD;}/* * Sets the priority for the DMA channel dmanr. * Since this is setup by the hardware init function, this function * can be used to dynamically change the priority of a channel. * * Acceptable priorities: * * PRIORITY_LOW * PRIORITY_MID_LOW * PRIORITY_MID_HIGH * PRIORITY_HIGH * */intppc4xx_set_channel_priority(unsigned int dmanr, unsigned int priority){	unsigned int control;	if (dmanr >= MAX_PPC4xx_DMA_CHANNELS) {		printk("ppc4xx_set_channel_priority: bad channel %d\n", dmanr);		return DMA_STATUS_BAD_CHANNEL;	}	if ((priority != PRIORITY_LOW) &&	    (priority != PRIORITY_MID_LOW) &&	    (priority != PRIORITY_MID_HIGH) && (priority != PRIORITY_HIGH)) {		printk("ppc4xx_set_channel_priority: bad priority: 0x%x\n", priority);	}	control = mfdcr(DCRN_DMACR0 + (dmanr * 0x8));	control |= SET_DMA_PRIORITY(priority);	mtdcr(DCRN_DMACR0 + (dmanr * 0x8), control);	return DMA_STATUS_GOOD;}/* * Returns the width of the peripheral attached to this channel. This assumes * that someone who knows the hardware configuration, boot code or some other * init code, already set the width. * * The return value is one of: *   PW_8 *   PW_16 *   PW_32 *   PW_64 * *   The function returns 0 on error. */unsigned intppc4xx_get_peripheral_width(unsigned int dmanr){	unsigned int control;	if (dmanr >= MAX_PPC4xx_DMA_CHANNELS) {		printk("ppc4xx_get_peripheral_width: bad channel %d\n", dmanr);		return DMA_STATUS_BAD_CHANNEL;	}	control = mfdcr(DCRN_DMACR0 + (dmanr * 0x8));	return (GET_DMA_PW(control));}/* * Clears the channel status bits */intppc4xx_clr_dma_status(unsigned int dmanr){	if (dmanr >= MAX_PPC4xx_DMA_CHANNELS) {		printk(KERN_ERR "ppc4xx_clr_dma_status: bad channel: %d\n", dmanr);		return DMA_STATUS_BAD_CHANNEL;	}	mtdcr(DCRN_DMASR, ((u32)DMA_CH0_ERR | (u32)DMA_CS0 | (u32)DMA_TS0) >> dmanr);	return DMA_STATUS_GOOD;}#ifdef CONFIG_PPC4xx_EDMA/* * Enables the burst on the channel (BTEN bit in the control/count register) * Note: * For scatter/gather dma, this function MUST be called before the * ppc4xx_alloc_dma_handle() func as the chan count register is copied into the * sgl list and used as each sgl element is added. */intppc4xx_enable_burst(unsigned int dmanr){	unsigned int ctc;	if (dmanr >= MAX_PPC4xx_DMA_CHANNELS) {		printk(KERN_ERR "ppc4xx_enable_burst: bad channel: %d\n", dmanr);		return DMA_STATUS_BAD_CHANNEL;	}        ctc = mfdcr(DCRN_DMACT0 + (dmanr * 0x8)) | DMA_CTC_BTEN;	mtdcr(DCRN_DMACT0 + (dmanr * 0x8), ctc);	return DMA_STATUS_GOOD;}/* * Disables the burst on the channel (BTEN bit in the control/count register) * Note: * For scatter/gather dma, this function MUST be called before the * ppc4xx_alloc_dma_handle() func as the chan count register is copied into the * sgl list and used as each sgl element is added. */intppc4xx_disable_burst(unsigned int dmanr){	unsigned int ctc;	if (dmanr >= MAX_PPC4xx_DMA_CHANNELS) {		printk(KERN_ERR "ppc4xx_disable_burst: bad channel: %d\n", dmanr);		return DMA_STATUS_BAD_CHANNEL;	}	ctc = mfdcr(DCRN_DMACT0 + (dmanr * 0x8)) &~ DMA_CTC_BTEN;	mtdcr(DCRN_DMACT0 + (dmanr * 0x8), ctc);	return DMA_STATUS_GOOD;}/* * Sets the burst size (number of peripheral widths) for the channel * (BSIZ bits in the control/count register)) * must be one of: *    DMA_CTC_BSIZ_2 *    DMA_CTC_BSIZ_4 *    DMA_CTC_BSIZ_8 *    DMA_CTC_BSIZ_16 * Note: * For scatter/gather dma, this function MUST be called before the * ppc4xx_alloc_dma_handle() func as the chan count register is copied into the * sgl list and used as each sgl element is added. */intppc4xx_set_burst_size(unsigned int dmanr, unsigned int bsize){	unsigned int ctc;	if (dmanr >= MAX_PPC4xx_DMA_CHANNELS) {		printk(KERN_ERR "ppc4xx_set_burst_size: bad channel: %d\n", dmanr);		return DMA_STATUS_BAD_CHANNEL;	}	ctc = mfdcr(DCRN_DMACT0 + (dmanr * 0x8)) &~ DMA_CTC_BSIZ_MSK;	ctc |= (bsize & DMA_CTC_BSIZ_MSK);	mtdcr(DCRN_DMACT0 + (dmanr * 0x8), ctc);	return DMA_STATUS_GOOD;}EXPORT_SYMBOL(ppc4xx_enable_burst);EXPORT_SYMBOL(ppc4xx_disable_burst);EXPORT_SYMBOL(ppc4xx_set_burst_size);#endif /* CONFIG_PPC4xx_EDMA */EXPORT_SYMBOL(ppc4xx_init_dma_channel);EXPORT_SYMBOL(ppc4xx_get_channel_config);EXPORT_SYMBOL(ppc4xx_set_channel_priority);EXPORT_SYMBOL(ppc4xx_get_peripheral_width);EXPORT_SYMBOL(dma_channels);EXPORT_SYMBOL(ppc4xx_set_src_addr);EXPORT_SYMBOL(ppc4xx_set_dst_addr);EXPORT_SYMBOL(ppc4xx_set_dma_addr);EXPORT_SYMBOL(ppc4xx_set_dma_addr2);EXPORT_SYMBOL(ppc4xx_enable_dma);EXPORT_SYMBOL(ppc4xx_disable_dma);EXPORT_SYMBOL(ppc4xx_set_dma_mode);EXPORT_SYMBOL(ppc4xx_set_dma_count);EXPORT_SYMBOL(ppc4xx_get_dma_residue);EXPORT_SYMBOL(ppc4xx_enable_dma_interrupt);EXPORT_SYMBOL(ppc4xx_disable_dma_interrupt);EXPORT_SYMBOL(ppc4xx_get_dma_status);EXPORT_SYMBOL(ppc4xx_clr_dma_status);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -