/* * Simple synchronous serial port driver for ETRAX FS and Artpec-3. * * Copyright (c) 2005 Axis Communications AB * * Author: Mikael Starvik * */#include <linux/module.h>#include <linux/kernel.h>#include <linux/types.h>#include <linux/errno.h>#include <linux/major.h>#include <linux/sched.h>#include <linux/mutex.h>#include <linux/interrupt.h>#include <linux/poll.h>#include <linux/init.h>#include <linux/timer.h>#include <linux/spinlock.h>#include <asm/io.h>#include <dma.h>#include <pinmux.h>#include <hwregs/reg_rdwr.h>#include <hwregs/sser_defs.h>#include <hwregs/dma_defs.h>#include <hwregs/dma.h>#include <hwregs/intr_vect_defs.h>#include <hwregs/intr_vect.h>#include <hwregs/reg_map.h>#include <asm/sync_serial.h>/* The receiver is a bit tricky because of the continuous stream of data.*//* *//* Three DMA descriptors are linked together. Each DMA descriptor is *//* responsible for port->bufchunk of a common buffer. *//* *//* +---------------------------------------------+ *//* | +----------+ +----------+ +----------+ | *//* +-> | Descr[0] |-->| Descr[1] |-->| Descr[2] |-+ *//* +----------+ +----------+ +----------+ *//* | | | *//* v v v *//* +-------------------------------------+ *//* | BUFFER | *//* +-------------------------------------+ *//* |<- data_avail ->| *//* readp writep *//* *//* If the application keeps up the pace readp will be right after writep.*//* If the application can't keep the pace we have to throw away data. *//* The idea is that readp should be ready with the data pointed out by *//* Descr[i] when the DMA has filled in Descr[i+1]. *//* Otherwise we will discard *//* the rest of the data pointed out by Descr1 and set readp to the start *//* of Descr2 */#define SYNC_SERIAL_MAJOR 125/* IN_BUFFER_SIZE should be a multiple of 6 to make sure that 24 bit *//* words can be handled */#define IN_BUFFER_SIZE 12288#define IN_DESCR_SIZE 256#define NBR_IN_DESCR (IN_BUFFER_SIZE/IN_DESCR_SIZE)#define OUT_BUFFER_SIZE 1024*8#define NBR_OUT_DESCR 8#define DEFAULT_FRAME_RATE 0#define DEFAULT_WORD_RATE 7/* NOTE: Enabling some debug will likely cause overrun or underrun, * especially if manual mode is use. */#define DEBUG(x)#define DEBUGREAD(x)#define DEBUGWRITE(x)#define DEBUGPOLL(x)#define DEBUGRXINT(x)#define DEBUGTXINT(x)#define DEBUGTRDMA(x)#define DEBUGOUTBUF(x)typedefstruct sync_port
{
reg_scope_instances regi_sser;
reg_scope_instances regi_dmain;
reg_scope_instances regi_dmaout;char started;/* 1 if port has been started */char port_nbr;/* Port 0 or 1 */char busy;/* 1 if port is busy */char enabled;/* 1 if port is enabled */char use_dma