/* * Texas Instruments CPDMA Driver * * Copyright (C) 2010 Texas Instruments * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation version 2. * * This program is distributed "as is" WITHOUT ANY WARRANTY of any * kind, whether express or implied; without even the implied warranty * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */#include<linux/kernel.h>#include<linux/spinlock.h>#include<linux/device.h>#include<linux/module.h>#include<linux/slab.h>#include<linux/err.h>#include<linux/dma-mapping.h>#include<linux/io.h>#include<linux/delay.h>#include<linux/genalloc.h>#include"davinci_cpdma.h"/* DMA Registers */#define CPDMA_TXIDVER 0x00#define CPDMA_TXCONTROL 0x04#define CPDMA_TXTEARDOWN 0x08#define CPDMA_RXIDVER 0x10#define CPDMA_RXCONTROL 0x14#define CPDMA_SOFTRESET 0x1c#define CPDMA_RXTEARDOWN 0x18#define CPDMA_TX_PRI0_RATE 0x30#define CPDMA_TXINTSTATRAW 0x80#define CPDMA_TXINTSTATMASKED 0x84#define CPDMA_TXINTMASKSET 0x88#define CPDMA_TXINTMASKCLEAR 0x8c#define CPDMA_MACINVECTOR 0x90#define CPDMA_MACEOIVECTOR 0x94#define CPDMA_RXINTSTATRAW 0xa0#define CPDMA_RXINTSTATMASKED 0xa4#define CPDMA_RXINTMASKSET 0xa8#define CPDMA_RXINTMASKCLEAR 0xac#define CPDMA_DMAINTSTATRAW 0xb0#define CPDMA_DMAINTSTATMASKED 0xb4#define CPDMA_DMAINTMASKSET 0xb8#define CPDMA_DMAINTMASKCLEAR 0xbc#define CPDMA_DMAINT_HOSTERR BIT(1)/* the following exist only if has_ext_regs is set */#define CPDMA_DMACONTROL 0x20#define CPDMA_DMASTATUS 0x24#define CPDMA_RXBUFFOFS 0x28#define CPDMA_EM_CONTROL 0x2c/* Descriptor mode bits */#define CPDMA_DESC_SOP BIT(31)#define CPDMA_DESC_EOP BIT(30)#define CPDMA_DESC_OWNER BIT(29)#define CPDMA_DESC_EOQ BIT(28)#define CPDMA_DESC_TD_COMPLETE BIT(27)#define CPDMA_DESC_PASS_CRC BIT(26)#define CPDMA_DESC_TO_PORT_EN BIT(20)#define CPDMA_TO_PORT_SHIFT 16#define CPDMA_DESC_PORT_MASK (BIT(18) | BIT(17) | BIT(16))#define CPDMA_DESC_CRC_LEN 4#define CPDMA_TEARDOWN_VALUE 0xfffffffc#define CPDMA_MAX_RLIM_CNT 16384structcpdma_desc{/* hardware fields */u32hw_next;u32hw_buffer;u32hw_len;u32hw_mode;/* software fields */void*sw_token;u32sw_buffer;u32sw_len;};structcpdma_desc_pool{phys_addr_tphys;dma_addr_thw_addr;void__iomem*iomap;/* ioremap map */void*cpumap;/* dma_alloc map */intdesc_size,mem_size;intnum_desc;structdevice*dev;structgen_pool*gen_pool;};enumcpdma_state{CPDMA_STATE_IDLE,CPDMA_STATE_ACTIVE,CPDMA_STATE_TEARDOWN,};structcpdma_ctlr{enumcpdma_statestate;structcpdma_paramsparams;structdevice*dev;structcpdma_desc_pool*pool;spinlock_tlock;structcpdma_chan*channels[2*CPDMA_MAX_CHANNELS];intchan_num;intnum_rx_desc