首页 > 代码库 > kobox : dma_s3c.ko -v1 操作寄存器方式操作S3C2440的DMA

kobox : dma_s3c.ko -v1 操作寄存器方式操作S3C2440的DMA

平台:TQ2440

linux版本:Linux EmbedSky 3.16.1-svn57 #56 Sat Oct 18 21:46:22 PDT 2014 armv4tl GNU/Linux

kobox : dma_s3c.ko -v1 操作寄存器方式操作S3C2440的DMA

目标:v2中改成s3c2410_dma_xxx方式来操作DMA,看这里的寄存器映射是怎么使用系统接口来操作的!

#include "dma.h"

#define MEM_CPY_NO_DMA  0
#define MEM_CPY_DMA     1

//#define BUF_SIZE  (512*1024)
#define BUF_SIZE  (1024)

#define DMA0_BASE_ADDR  0x4B000000
#define DMA1_BASE_ADDR  0x4B000040
#define DMA2_BASE_ADDR  0x4B000080
#define DMA3_BASE_ADDR  0x4B0000C0

struct s3c_dma_regs {
unsigned long disrc;	 	 //DISRC3  0x4B0000C0 R/W DMA 3 initial source register
unsigned long disrcc;	 	 //DISRCC3 0x4B0000C4 R/W DMA 3 initial source control register
unsigned long didst;	 	 //DIDST3  0x4B0000C8 R/W DMA 3 initial destination register
unsigned long didstc;	 	 //DIDSTC3 0x4B0000CC R/W DMA 3 initial destination control register 
unsigned long dcon;		 //DCON3   0x4B0000D0 R/W DMA 3 control registe
unsigned long dstat;	 	 //DSTAT3  0x4B0000D4 R   DMA 3 count register
unsigned long dcsrc;	 	 //DCSRC3  0x4B0000D8 R   DMA 3 current source register
unsigned long dcdst;	  	//DCDST3   0x4B0000DC R   DMA 3 current destination register
unsigned long dmasktrig; //DMASKTRIG3 0x4B0000E0 R/W DMA 3 mask trigger register
};

static char *srcbuff;
static u32 src_dma_phys;
static phys_addr_t src_buff_phys;

static char *dstbuff;
static u32 dst_dma_phys;
static phys_addr_t dst_buff_phys;


static struct class *cls;

static volatile struct s3c_dma_regs *dma_regs = NULL;
static inline void *dma_alloc_writecombine(struct device *dev, size_t size,
				       dma_addr_t *dma_handle, gfp_t flag);
static inline phys_addr_t virt_to_phys(const volatile void *x);


static DECLARE_WAIT_QUEUE_HEAD(dma_waitq);
/* 中断事件标志, 中断服务程序将它置1,ioctl将它清0 */
static volatile int ev_dma = 0;

static int buff_dump(void)
{
	int i;

	printk( "srcbuff:\n"
			"------------------------------------------------------------\n");
	for(i=0; i<BUF_SIZE;i++)
	{
		printk("%x ", srcbuff[i]);
		if((i+1)%32 == 0)
		{
			printk("\n");
		}
	}
	printk( "\n------------------------------------------------------------\n");

	printk( "dstbuff:\n"
			"------------------------------------------------------------\n");
	for(i=0; i<BUF_SIZE;i++)
	{
		printk("%x ", dstbuff[i]);
		if((i+1)%32 == 0)
		{
			printk("\n");
		}
	}
	printk( "\n------------------------------------------------------------\n");

	
}

//static int s3c_dma_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
static long s3c_dma_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{
	int i;

	memset(srcbuff, 0xAA, BUF_SIZE);
	memset(dstbuff, 0x55, BUF_SIZE);
	switch (cmd)
	{
		//这是非DMA模式
		case MEM_CPY_NO_DMA :
		{
			for (i = 0; i < BUF_SIZE; i++)
			{
				dstbuff[i] = srcbuff[i];  //CPU直接将源拷贝到目的
			}	

			if (memcmp(srcbuff, dstbuff, BUF_SIZE) == 0)//这个函数见注释2
			{
				printk("MEM_CPY_NO_DMA OK\n");
			}
			else
			{
				printk("MEM_CPY_DMA ERROR\n");
			}
			
			break;
		}

		//这是DMA模式
		case MEM_CPY_DMA :
		{
			ev_dma = 0;
			/* 把源,目的,长度告诉DMA */
			/* 关于下面寄存器的具体情况,我们在注释3里面来详细讲一下 */
			dma_regs->disrc      = http://www.mamicode.com/src_dma_phys;        /* 源的物理地址 */>

kobox : dma_s3c.ko -v1 操作寄存器方式操作S3C2440的DMA