blob: 1d33564029a4bbe5357ed5009638348343391ded [file] [log] [blame]
Graff Yangd510fe72009-05-12 13:47:54 -07001/*
2 * Blackfin Infra-red Driver
3 *
4 * Copyright 2006-2009 Analog Devices Inc.
5 *
6 * Enter bugs at http://blackfin.uclinux.org/
7 *
8 * Licensed under the GPL-2 or later.
9 *
10 */
11
12#include <linux/serial.h>
13#include <linux/module.h>
14#include <linux/netdevice.h>
15#include <linux/interrupt.h>
16#include <linux/delay.h>
17#include <linux/platform_device.h>
18#include <linux/dma-mapping.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090019#include <linux/slab.h>
Graff Yangd510fe72009-05-12 13:47:54 -070020
21#include <net/irda/irda.h>
22#include <net/irda/wrapper.h>
23#include <net/irda/irda_device.h>
24
25#include <asm/irq.h>
26#include <asm/cacheflush.h>
27#include <asm/dma.h>
28#include <asm/portmux.h>
Mike Frysinger709465d2010-10-28 15:43:50 -040029/* Some transitional glue */
30#include <linux/serial_core.h>
31#include <linux/circ_buf.h>
32#include <mach/bfin_serial_5xx.h>
33#undef DRIVER_NAME
Graff Yangd510fe72009-05-12 13:47:54 -070034
35#ifdef CONFIG_SIR_BFIN_DMA
36struct dma_rx_buf {
37 char *buf;
38 int head;
39 int tail;
40};
41#endif
42
43struct bfin_sir_port {
44 unsigned char __iomem *membase;
45 unsigned int irq;
46 unsigned int lsr;
47 unsigned long clk;
48 struct net_device *dev;
49#ifdef CONFIG_SIR_BFIN_DMA
50 int tx_done;
51 struct dma_rx_buf rx_dma_buf;
52 struct timer_list rx_dma_timer;
53 int rx_dma_nrows;
54#endif
55 unsigned int tx_dma_channel;
56 unsigned int rx_dma_channel;
57};
58
59struct bfin_sir_port_res {
60 unsigned long base_addr;
61 int irq;
62 unsigned int rx_dma_channel;
63 unsigned int tx_dma_channel;
64};
65
66struct bfin_sir_self {
67 struct bfin_sir_port *sir_port;
68 spinlock_t lock;
69 unsigned int open;
70 int speed;
71 int newspeed;
72
73 struct sk_buff *txskb;
74 struct sk_buff *rxskb;
75 struct net_device_stats stats;
76 struct device *dev;
77 struct irlap_cb *irlap;
78 struct qos_info qos;
79
80 iobuff_t tx_buff;
81 iobuff_t rx_buff;
82
83 struct work_struct work;
84 int mtt;
85};
86
87#define DRIVER_NAME "bfin_sir"
88
89#define SIR_UART_GET_CHAR(port) bfin_read16((port)->membase + OFFSET_RBR)
90#define SIR_UART_GET_DLL(port) bfin_read16((port)->membase + OFFSET_DLL)
91#define SIR_UART_GET_DLH(port) bfin_read16((port)->membase + OFFSET_DLH)
92#define SIR_UART_GET_LCR(port) bfin_read16((port)->membase + OFFSET_LCR)
93#define SIR_UART_GET_GCTL(port) bfin_read16((port)->membase + OFFSET_GCTL)
94
95#define SIR_UART_PUT_CHAR(port, v) bfin_write16(((port)->membase + OFFSET_THR), v)
96#define SIR_UART_PUT_DLL(port, v) bfin_write16(((port)->membase + OFFSET_DLL), v)
97#define SIR_UART_PUT_DLH(port, v) bfin_write16(((port)->membase + OFFSET_DLH), v)
98#define SIR_UART_PUT_LCR(port, v) bfin_write16(((port)->membase + OFFSET_LCR), v)
99#define SIR_UART_PUT_GCTL(port, v) bfin_write16(((port)->membase + OFFSET_GCTL), v)
100
101#ifdef CONFIG_BF54x
102#define SIR_UART_GET_LSR(port) bfin_read16((port)->membase + OFFSET_LSR)
103#define SIR_UART_GET_IER(port) bfin_read16((port)->membase + OFFSET_IER_SET)
104#define SIR_UART_SET_IER(port, v) bfin_write16(((port)->membase + OFFSET_IER_SET), v)
105#define SIR_UART_CLEAR_IER(port, v) bfin_write16(((port)->membase + OFFSET_IER_CLEAR), v)
106#define SIR_UART_PUT_LSR(port, v) bfin_write16(((port)->membase + OFFSET_LSR), v)
107#define SIR_UART_CLEAR_LSR(port) bfin_write16(((port)->membase + OFFSET_LSR), -1)
108
109#define SIR_UART_SET_DLAB(port)
110#define SIR_UART_CLEAR_DLAB(port)
111
112#define SIR_UART_ENABLE_INTS(port, v) SIR_UART_SET_IER(port, v)
113#define SIR_UART_DISABLE_INTS(port) SIR_UART_CLEAR_IER(port, 0xF)
114#define SIR_UART_STOP_TX(port) do { SIR_UART_PUT_LSR(port, TFI); SIR_UART_CLEAR_IER(port, ETBEI); } while (0)
115#define SIR_UART_ENABLE_TX(port) do { SIR_UART_SET_IER(port, ETBEI); } while (0)
116#define SIR_UART_STOP_RX(port) do { SIR_UART_CLEAR_IER(port, ERBFI); } while (0)
117#define SIR_UART_ENABLE_RX(port) do { SIR_UART_SET_IER(port, ERBFI); } while (0)
118#else
119
120#define SIR_UART_GET_IIR(port) bfin_read16((port)->membase + OFFSET_IIR)
121#define SIR_UART_GET_IER(port) bfin_read16((port)->membase + OFFSET_IER)
122#define SIR_UART_PUT_IER(port, v) bfin_write16(((port)->membase + OFFSET_IER), v)
123
124#define SIR_UART_SET_DLAB(port) do { SIR_UART_PUT_LCR(port, SIR_UART_GET_LCR(port) | DLAB); } while (0)
125#define SIR_UART_CLEAR_DLAB(port) do { SIR_UART_PUT_LCR(port, SIR_UART_GET_LCR(port) & ~DLAB); } while (0)
126
127#define SIR_UART_ENABLE_INTS(port, v) SIR_UART_PUT_IER(port, v)
128#define SIR_UART_DISABLE_INTS(port) SIR_UART_PUT_IER(port, 0)
129#define SIR_UART_STOP_TX(port) do { SIR_UART_PUT_IER(port, SIR_UART_GET_IER(port) & ~ETBEI); } while (0)
130#define SIR_UART_ENABLE_TX(port) do { SIR_UART_PUT_IER(port, SIR_UART_GET_IER(port) | ETBEI); } while (0)
131#define SIR_UART_STOP_RX(port) do { SIR_UART_PUT_IER(port, SIR_UART_GET_IER(port) & ~ERBFI); } while (0)
132#define SIR_UART_ENABLE_RX(port) do { SIR_UART_PUT_IER(port, SIR_UART_GET_IER(port) | ERBFI); } while (0)
133
134static inline unsigned int SIR_UART_GET_LSR(struct bfin_sir_port *port)
135{
136 unsigned int lsr = bfin_read16(port->membase + OFFSET_LSR);
137 port->lsr |= (lsr & (BI|FE|PE|OE));
138 return lsr | port->lsr;
139}
140
141static inline void SIR_UART_CLEAR_LSR(struct bfin_sir_port *port)
142{
143 port->lsr = 0;
144 bfin_read16(port->membase + OFFSET_LSR);
145}
146#endif
147
148static const unsigned short per[][4] = {
149 /* rx pin tx pin NULL uart_number */
150 {P_UART0_RX, P_UART0_TX, 0, 0},
151 {P_UART1_RX, P_UART1_TX, 0, 1},
152 {P_UART2_RX, P_UART2_TX, 0, 2},
153 {P_UART3_RX, P_UART3_TX, 0, 3},
154};