Path: blob/master/arch/blackfin/include/asm/bfin_serial.h
15126 views
/*1* bfin_serial.h - Blackfin UART/Serial definitions2*3* Copyright 2006-2010 Analog Devices Inc.4*5* Licensed under the GPL-2 or later.6*/78#ifndef __BFIN_ASM_SERIAL_H__9#define __BFIN_ASM_SERIAL_H__1011#include <linux/serial_core.h>12#include <linux/spinlock.h>13#include <mach/anomaly.h>14#include <mach/bfin_serial.h>1516#if defined(CONFIG_BFIN_UART0_CTSRTS) || \17defined(CONFIG_BFIN_UART1_CTSRTS) || \18defined(CONFIG_BFIN_UART2_CTSRTS) || \19defined(CONFIG_BFIN_UART3_CTSRTS)20# ifdef BFIN_UART_BF54X_STYLE21# define CONFIG_SERIAL_BFIN_HARD_CTSRTS22# else23# define CONFIG_SERIAL_BFIN_CTSRTS24# endif25#endif2627struct circ_buf;28struct timer_list;29struct work_struct;3031struct bfin_serial_port {32struct uart_port port;33unsigned int old_status;34int status_irq;35#ifndef BFIN_UART_BF54X_STYLE36unsigned int lsr;37#endif38#ifdef CONFIG_SERIAL_BFIN_DMA39int tx_done;40int tx_count;41struct circ_buf rx_dma_buf;42struct timer_list rx_dma_timer;43int rx_dma_nrows;44spinlock_t rx_lock;45unsigned int tx_dma_channel;46unsigned int rx_dma_channel;47struct work_struct tx_dma_workqueue;48#elif ANOMALY_0500036349unsigned int anomaly_threshold;50#endif51#ifdef CONFIG_SERIAL_BFIN_HARD_CTSRTS52int scts;53#endif54#if defined(CONFIG_SERIAL_BFIN_CTSRTS) || \55defined(CONFIG_SERIAL_BFIN_HARD_CTSRTS)56int cts_pin;57int rts_pin;58#endif59};6061/* UART_LCR Masks */62#define WLS(x) (((x)-5) & 0x03) /* Word Length Select */63#define STB 0x04 /* Stop Bits */64#define PEN 0x08 /* Parity Enable */65#define EPS 0x10 /* Even Parity Select */66#define STP 0x20 /* Stick Parity */67#define SB 0x40 /* Set Break */68#define DLAB 0x80 /* Divisor Latch Access */6970/* UART_LSR Masks */71#define DR 0x01 /* Data Ready */72#define OE 0x02 /* Overrun Error */73#define PE 0x04 /* Parity Error */74#define FE 0x08 /* Framing Error */75#define BI 0x10 /* Break Interrupt */76#define THRE 0x20 /* THR Empty */77#define TEMT 0x40 /* TSR and UART_THR Empty */78#define TFI 0x80 /* Transmission Finished Indicator */7980/* UART_IER Masks */81#define ERBFI 0x01 /* Enable Receive Buffer Full Interrupt */82#define ETBEI 0x02 /* Enable Transmit Buffer Empty Interrupt */83#define ELSI 0x04 /* Enable RX Status Interrupt */84#define EDSSI 0x08 /* Enable Modem Status Interrupt */85#define EDTPTI 0x10 /* Enable DMA Transmit PIRQ Interrupt */86#define ETFI 0x20 /* Enable Transmission Finished Interrupt */87#define ERFCI 0x40 /* Enable Receive FIFO Count Interrupt */8889/* UART_MCR Masks */90#define XOFF 0x01 /* Transmitter Off */91#define MRTS 0x02 /* Manual Request To Send */92#define RFIT 0x04 /* Receive FIFO IRQ Threshold */93#define RFRT 0x08 /* Receive FIFO RTS Threshold */94#define LOOP_ENA 0x10 /* Loopback Mode Enable */95#define FCPOL 0x20 /* Flow Control Pin Polarity */96#define ARTS 0x40 /* Automatic Request To Send */97#define ACTS 0x80 /* Automatic Clear To Send */9899/* UART_MSR Masks */100#define SCTS 0x01 /* Sticky CTS */101#define CTS 0x10 /* Clear To Send */102#define RFCS 0x20 /* Receive FIFO Count Status */103104/* UART_GCTL Masks */105#define UCEN 0x01 /* Enable UARTx Clocks */106#define IREN 0x02 /* Enable IrDA Mode */107#define TPOLC 0x04 /* IrDA TX Polarity Change */108#define RPOLC 0x08 /* IrDA RX Polarity Change */109#define FPE 0x10 /* Force Parity Error On Transmit */110#define FFE 0x20 /* Force Framing Error On Transmit */111112#ifdef BFIN_UART_BF54X_STYLE113# define OFFSET_DLL 0x00 /* Divisor Latch (Low-Byte) */114# define OFFSET_DLH 0x04 /* Divisor Latch (High-Byte) */115# define OFFSET_GCTL 0x08 /* Global Control Register */116# define OFFSET_LCR 0x0C /* Line Control Register */117# define OFFSET_MCR 0x10 /* Modem Control Register */118# define OFFSET_LSR 0x14 /* Line Status Register */119# define OFFSET_MSR 0x18 /* Modem Status Register */120# define OFFSET_SCR 0x1C /* SCR Scratch Register */121# define OFFSET_IER_SET 0x20 /* Set Interrupt Enable Register */122# define OFFSET_IER_CLEAR 0x24 /* Clear Interrupt Enable Register */123# define OFFSET_THR 0x28 /* Transmit Holding register */124# define OFFSET_RBR 0x2C /* Receive Buffer register */125#else /* BF533 style */126# define OFFSET_THR 0x00 /* Transmit Holding register */127# define OFFSET_RBR 0x00 /* Receive Buffer register */128# define OFFSET_DLL 0x00 /* Divisor Latch (Low-Byte) */129# define OFFSET_DLH 0x04 /* Divisor Latch (High-Byte) */130# define OFFSET_IER 0x04 /* Interrupt Enable Register */131# define OFFSET_IIR 0x08 /* Interrupt Identification Register */132# define OFFSET_LCR 0x0C /* Line Control Register */133# define OFFSET_MCR 0x10 /* Modem Control Register */134# define OFFSET_LSR 0x14 /* Line Status Register */135# define OFFSET_MSR 0x18 /* Modem Status Register */136# define OFFSET_SCR 0x1C /* SCR Scratch Register */137# define OFFSET_GCTL 0x24 /* Global Control Register */138/* code should not need IIR, so force build error if they use it */139# undef OFFSET_IIR140#endif141142/*143* All Blackfin system MMRs are padded to 32bits even if the register144* itself is only 16bits. So use a helper macro to streamline this.145*/146#define __BFP(m) u16 m; u16 __pad_##m147struct bfin_uart_regs {148#ifdef BFIN_UART_BF54X_STYLE149__BFP(dll);150__BFP(dlh);151__BFP(gctl);152__BFP(lcr);153__BFP(mcr);154__BFP(lsr);155__BFP(msr);156__BFP(scr);157__BFP(ier_set);158__BFP(ier_clear);159__BFP(thr);160__BFP(rbr);161#else162union {163u16 dll;164u16 thr;165const u16 rbr;166};167const u16 __pad0;168union {169u16 dlh;170u16 ier;171};172const u16 __pad1;173const __BFP(iir);174__BFP(lcr);175__BFP(mcr);176__BFP(lsr);177__BFP(msr);178__BFP(scr);179const u32 __pad2;180__BFP(gctl);181#endif182};183#undef __BFP184185#ifndef port_membase186# define port_membase(p) 0187#endif188189#define UART_GET_CHAR(p) bfin_read16(port_membase(p) + OFFSET_RBR)190#define UART_GET_DLL(p) bfin_read16(port_membase(p) + OFFSET_DLL)191#define UART_GET_DLH(p) bfin_read16(port_membase(p) + OFFSET_DLH)192#define UART_GET_GCTL(p) bfin_read16(port_membase(p) + OFFSET_GCTL)193#define UART_GET_LCR(p) bfin_read16(port_membase(p) + OFFSET_LCR)194#define UART_GET_MCR(p) bfin_read16(port_membase(p) + OFFSET_MCR)195#define UART_GET_MSR(p) bfin_read16(port_membase(p) + OFFSET_MSR)196197#define UART_PUT_CHAR(p, v) bfin_write16(port_membase(p) + OFFSET_THR, v)198#define UART_PUT_DLL(p, v) bfin_write16(port_membase(p) + OFFSET_DLL, v)199#define UART_PUT_DLH(p, v) bfin_write16(port_membase(p) + OFFSET_DLH, v)200#define UART_PUT_GCTL(p, v) bfin_write16(port_membase(p) + OFFSET_GCTL, v)201#define UART_PUT_LCR(p, v) bfin_write16(port_membase(p) + OFFSET_LCR, v)202#define UART_PUT_MCR(p, v) bfin_write16(port_membase(p) + OFFSET_MCR, v)203204#ifdef BFIN_UART_BF54X_STYLE205206#define UART_CLEAR_IER(p, v) bfin_write16(port_membase(p) + OFFSET_IER_CLEAR, v)207#define UART_GET_IER(p) bfin_read16(port_membase(p) + OFFSET_IER_SET)208#define UART_SET_IER(p, v) bfin_write16(port_membase(p) + OFFSET_IER_SET, v)209210#define UART_CLEAR_DLAB(p) /* MMRs not muxed on BF54x */211#define UART_SET_DLAB(p) /* MMRs not muxed on BF54x */212213#define UART_CLEAR_LSR(p) bfin_write16(port_membase(p) + OFFSET_LSR, -1)214#define UART_GET_LSR(p) bfin_read16(port_membase(p) + OFFSET_LSR)215#define UART_PUT_LSR(p, v) bfin_write16(port_membase(p) + OFFSET_LSR, v)216217/* This handles hard CTS/RTS */218#define BFIN_UART_CTSRTS_HARD219#define UART_CLEAR_SCTS(p) bfin_write16((port_membase(p) + OFFSET_MSR), SCTS)220#define UART_GET_CTS(x) (UART_GET_MSR(x) & CTS)221#define UART_DISABLE_RTS(x) UART_PUT_MCR(x, UART_GET_MCR(x) & ~(ARTS | MRTS))222#define UART_ENABLE_RTS(x) UART_PUT_MCR(x, UART_GET_MCR(x) | MRTS | ARTS)223#define UART_ENABLE_INTS(x, v) UART_SET_IER(x, v)224#define UART_DISABLE_INTS(x) UART_CLEAR_IER(x, 0xF)225226#else /* BF533 style */227228#define UART_CLEAR_IER(p, v) UART_PUT_IER(p, UART_GET_IER(p) & ~(v))229#define UART_GET_IER(p) bfin_read16(port_membase(p) + OFFSET_IER)230#define UART_PUT_IER(p, v) bfin_write16(port_membase(p) + OFFSET_IER, v)231#define UART_SET_IER(p, v) UART_PUT_IER(p, UART_GET_IER(p) | (v))232233#define UART_CLEAR_DLAB(p) do { UART_PUT_LCR(p, UART_GET_LCR(p) & ~DLAB); SSYNC(); } while (0)234#define UART_SET_DLAB(p) do { UART_PUT_LCR(p, UART_GET_LCR(p) | DLAB); SSYNC(); } while (0)235236#ifndef put_lsr_cache237# define put_lsr_cache(p, v)238#endif239#ifndef get_lsr_cache240# define get_lsr_cache(p) 0241#endif242243/* The hardware clears the LSR bits upon read, so we need to cache244* some of the more fun bits in software so they don't get lost245* when checking the LSR in other code paths (TX).246*/247static inline void UART_CLEAR_LSR(void *p)248{249put_lsr_cache(p, 0);250bfin_write16(port_membase(p) + OFFSET_LSR, -1);251}252static inline unsigned int UART_GET_LSR(void *p)253{254unsigned int lsr = bfin_read16(port_membase(p) + OFFSET_LSR);255put_lsr_cache(p, get_lsr_cache(p) | (lsr & (BI|FE|PE|OE)));256return lsr | get_lsr_cache(p);257}258static inline void UART_PUT_LSR(void *p, uint16_t val)259{260put_lsr_cache(p, get_lsr_cache(p) & ~val);261}262263/* This handles soft CTS/RTS */264#define UART_GET_CTS(x) gpio_get_value((x)->cts_pin)265#define UART_DISABLE_RTS(x) gpio_set_value((x)->rts_pin, 1)266#define UART_ENABLE_RTS(x) gpio_set_value((x)->rts_pin, 0)267#define UART_ENABLE_INTS(x, v) UART_PUT_IER(x, v)268#define UART_DISABLE_INTS(x) UART_PUT_IER(x, 0)269270#endif271272#ifndef BFIN_UART_TX_FIFO_SIZE273# define BFIN_UART_TX_FIFO_SIZE 2274#endif275276#endif /* __BFIN_ASM_SERIAL_H__ */277278279