1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21#include <linux/kernel.h>
22#include <linux/spinlock.h>
23#include <asm/io.h>
24
25#include <linux/signal.h>
26#include <linux/sched.h>
27#include <linux/interrupt.h>
28
29#include "dmxdev.h"
30#include "dvbdev.h"
31#include "dvb_demux.h"
32#include "dvb_frontend.h"
33#include "dvb_net.h"
34
35#include "mantis_common.h"
36#include "mantis_reg.h"
37#include "mantis_uart.h"
38
39struct mantis_uart_params {
40 enum mantis_baud baud_rate;
41 enum mantis_parity parity;
42};
43
44static struct {
45 char string[7];
46} rates[5] = {
47 { "9600" },
48 { "19200" },
49 { "38400" },
50 { "57600" },
51 { "115200" }
52};
53
54static struct {
55 char string[5];
56} parity[3] = {
57 { "NONE" },
58 { "ODD" },
59 { "EVEN" }
60};
61
62#define UART_MAX_BUF 16
63
64static int mantis_uart_read(struct mantis_pci *mantis, u8 *data)
65{
66 struct mantis_hwconfig *config = mantis->hwconfig;
67 u32 stat = 0, i;
68
69
70 for (i = 0; i < (config->bytes + 1); i++) {
71
72 stat = mmread(MANTIS_UART_STAT);
73
74 if (stat & MANTIS_UART_RXFIFO_FULL) {
75 dprintk(MANTIS_ERROR, 1, "RX Fifo FULL");
76 }
77 data[i] = mmread(MANTIS_UART_RXD) & 0x3f;
78
79 dprintk(MANTIS_DEBUG, 1, "Reading ... <%02x>", data[i] & 0x3f);
80
81 if (data[i] & (1 << 7)) {
82 dprintk(MANTIS_ERROR, 1, "UART framing error");
83 return -EINVAL;
84 }
85 if (data[i] & (1 << 6)) {
86 dprintk(MANTIS_ERROR, 1, "UART parity error");
87 return -EINVAL;
88 }
89 }
90
91 return 0;
92}
93
94static void mantis_uart_work(struct work_struct *work)
95{
96 struct mantis_pci *mantis = container_of(work, struct mantis_pci, uart_work);
97 struct mantis_hwconfig *config = mantis->hwconfig;
98 u8 buf[16];
99 int i;
100
101 mantis_uart_read(mantis, buf);
102
103 for (i = 0; i < (config->bytes + 1); i++)
104 dprintk(MANTIS_INFO, 1, "UART BUF:%d <%02x> ", i, buf[i]);
105
106 dprintk(MANTIS_DEBUG, 0, "\n");
107}
108
109static int mantis_uart_setup(struct mantis_pci *mantis,
110 struct mantis_uart_params *params)
111{
112 u32 reg;
113
114 mmwrite((mmread(MANTIS_UART_CTL) | (params->parity & 0x3)), MANTIS_UART_CTL);
115
116 reg = mmread(MANTIS_UART_BAUD);
117
118 switch (params->baud_rate) {
119 case MANTIS_BAUD_9600:
120 reg |= 0xd8;
121 break;
122 case MANTIS_BAUD_19200:
123 reg |= 0x6c;
124 break;
125 case MANTIS_BAUD_38400:
126 reg |= 0x36;
127 break;
128 case MANTIS_BAUD_57600:
129 reg |= 0x23;
130 break;
131 case MANTIS_BAUD_115200:
132 reg |= 0x11;
133 break;
134 default:
135 return -EINVAL;
136 }
137
138 mmwrite(reg, MANTIS_UART_BAUD);
139
140 return 0;
141}
142
143int mantis_uart_init(struct mantis_pci *mantis)
144{
145 struct mantis_hwconfig *config = mantis->hwconfig;
146 struct mantis_uart_params params;
147
148
149 params.baud_rate = config->baud_rate;
150 params.parity = config->parity;
151 dprintk(MANTIS_INFO, 1, "Initializing UART @ %sbps parity:%s",
152 rates[params.baud_rate].string,
153 parity[params.parity].string);
154
155 init_waitqueue_head(&mantis->uart_wq);
156 spin_lock_init(&mantis->uart_lock);
157
158 INIT_WORK(&mantis->uart_work, mantis_uart_work);
159
160
161 mmwrite(mmread(MANTIS_UART_CTL) & 0xffef, MANTIS_UART_CTL);
162
163 mantis_uart_setup(mantis, ¶ms);
164
165
166 mmwrite((mmread(MANTIS_UART_BAUD) | (config->bytes << 8)), MANTIS_UART_BAUD);
167
168
169 mmwrite((mmread(MANTIS_UART_CTL) | MANTIS_UART_RXFLUSH), MANTIS_UART_CTL);
170
171
172 mmwrite(mmread(MANTIS_INT_MASK) | 0x800, MANTIS_INT_MASK);
173 mmwrite(mmread(MANTIS_UART_CTL) | MANTIS_UART_RXINT, MANTIS_UART_CTL);
174
175 schedule_work(&mantis->uart_work);
176 dprintk(MANTIS_DEBUG, 1, "UART successfully initialized");
177
178 return 0;
179}
180EXPORT_SYMBOL_GPL(mantis_uart_init);
181
182void mantis_uart_exit(struct mantis_pci *mantis)
183{
184
185 mmwrite(mmread(MANTIS_UART_CTL) & 0xffef, MANTIS_UART_CTL);
186 flush_work(&mantis->uart_work);
187}
188EXPORT_SYMBOL_GPL(mantis_uart_exit);
189