1 #include <linux/kernel.h>
2 #include <linux/spinlock.h>
5 #include <linux/signal.h>
6 #include <linux/sched.h>
7 #include <linux/interrupt.h>
11 #include "dvb_demux.h"
12 #include "dvb_frontend.h"
15 #include "mantis_common.h"
16 #include "mantis_reg.h"
17 #include "mantis_uart.h"
19 struct mantis_uart_params {
20 enum mantis_baud baud_rate;
21 enum mantis_parity parity;
24 #define UART_MAX_BUF 16
26 int mantis_uart_read(struct mantis_pci *mantis, u8 *data)
28 struct mantis_hwconfig *config = mantis->hwconfig;
33 for (i = 0; i < (config->bytes + 1); i++) {
35 if (stat & MANTIS_UART_RXFIFO_FULL) {
36 dprintk(MANTIS_ERROR, 1, "RX Fifo FULL");
38 data[i] = mmread(MANTIS_UART_RXD) & 0x3f;
40 stat = mmread(MANTIS_UART_STAT);
42 dprintk(MANTIS_DEBUG, 1, "Reading ... <%02x>", data[i] & 0x3f);
44 if (data[i] & (1 << 7)) {
45 dprintk(MANTIS_ERROR, 1, "UART framing error");
48 if (data[i] & (1 << 6)) {
49 dprintk(MANTIS_ERROR, 1, "UART parity error");
57 static void mantis_uart_work(struct work_struct *work)
59 struct mantis_pci *mantis = container_of(work, struct mantis_pci, uart_work);
60 struct mantis_hwconfig *config = mantis->hwconfig;
64 dprintk(MANTIS_DEBUG, 1, "UART read");
65 mantis_uart_read(mantis, buf);
67 dprintk(MANTIS_DEBUG, 1, "UART: ");
68 for (i = 0; i < (config->bytes + 1); i++)
69 dprintk(MANTIS_DEBUG, 0, "<%02x> ", buf[i]);
71 dprintk(MANTIS_DEBUG, 0, "\n");
74 static int mantis_uart_setup(struct mantis_pci *mantis,
75 struct mantis_uart_params *params)
77 char* rates[] = { "B_9600", "B_19200", "B_38400", "B_57600", "B_115200" };
78 char* parity[] = { "NONE", "ODD", "EVEN" };
82 dprintk(MANTIS_DEBUG, 1, "Set Parity <%s> Baud Rate <%s>",
83 parity[params->parity],
84 rates[params->baud_rate]);
86 mmwrite((mmread(MANTIS_UART_CTL) | (params->parity & 0x3)), MANTIS_UART_CTL);
88 reg = mmread(MANTIS_UART_BAUD);
90 switch (params->baud_rate) {
91 case MANTIS_BAUD_9600:
94 case MANTIS_BAUD_19200:
97 case MANTIS_BAUD_38400:
100 case MANTIS_BAUD_57600:
103 case MANTIS_BAUD_115200:
110 mmwrite(reg, MANTIS_UART_BAUD);
115 int mantis_uart_init(struct mantis_pci *mantis)
117 struct mantis_hwconfig *config = mantis->hwconfig;
118 struct mantis_uart_params params;
120 dprintk(MANTIS_DEBUG, 1, "Initializing UART ..");
121 /* default parity: */
122 params.baud_rate = config->baud_rate;
123 params.parity = config->parity;
125 init_waitqueue_head(&mantis->uart_wq);
126 spin_lock_init(&mantis->uart_lock);
128 INIT_WORK(&mantis->uart_work, mantis_uart_work);
130 /* disable interrupt */
131 mmwrite(mmread(MANTIS_UART_CTL) & 0xffef, MANTIS_UART_CTL);
133 mantis_uart_setup(mantis, ¶ms);
136 mmwrite((mmread(MANTIS_UART_BAUD) | (config->bytes << 8)), MANTIS_UART_BAUD);
139 mmwrite((mmread(MANTIS_UART_CTL) | MANTIS_UART_RXFLUSH), MANTIS_UART_CTL);
141 /* enable interrupt */
142 mmwrite(mmread(MANTIS_INT_MASK) | 0x800, MANTIS_INT_MASK);
143 mmwrite(mmread(MANTIS_UART_CTL) | MANTIS_UART_RXINT, MANTIS_UART_CTL);
145 schedule_work(&mantis->uart_work);
149 EXPORT_SYMBOL_GPL(mantis_uart_init);
151 void mantis_uart_exit(struct mantis_pci *mantis)
153 /* disable interrupt */
154 mmwrite(mmread(MANTIS_UART_CTL) & 0xffef, MANTIS_UART_CTL);
156 EXPORT_SYMBOL_GPL(mantis_uart_exit);