V4L/DVB (13802): [Mantis/Hopper] Fix all build related warnings
[safe/jmp/linux-2.6] / drivers / media / dvb / mantis / mantis_uart.c
1 #include <linux/kernel.h>
2 #include <linux/spinlock.h>
3
4 #include <asm/irq.h>
5 #include <linux/signal.h>
6 #include <linux/sched.h>
7 #include <linux/interrupt.h>
8
9 #include "dmxdev.h"
10 #include "dvbdev.h"
11 #include "dvb_demux.h"
12 #include "dvb_frontend.h"
13 #include "dvb_net.h"
14
15 #include "mantis_common.h"
16 #include "mantis_reg.h"
17 #include "mantis_uart.h"
18
19 struct mantis_uart_params {
20         enum mantis_baud        baud_rate;
21         enum mantis_parity      parity;
22 };
23
24 #define UART_MAX_BUF                    16
25
26 int mantis_uart_read(struct mantis_pci *mantis, u8 *data)
27 {
28         struct mantis_hwconfig *config = mantis->hwconfig;
29         u32 stat = 0, i;
30
31         /* get data */
32         for (i = 0; i < (config->bytes + 1); i++) {
33
34                 stat = mmread(MANTIS_UART_STAT);
35
36                 if (stat & MANTIS_UART_RXFIFO_FULL) {
37                         dprintk(MANTIS_ERROR, 1, "RX Fifo FULL");
38                 }
39                 data[i] = mmread(MANTIS_UART_RXD) & 0x3f;
40
41                 dprintk(MANTIS_DEBUG, 1, "Reading ... <%02x>", data[i] & 0x3f);
42
43                 if (data[i] & (1 << 7)) {
44                         dprintk(MANTIS_ERROR, 1, "UART framing error");
45                         return -EINVAL;
46                 }
47                 if (data[i] & (1 << 6)) {
48                         dprintk(MANTIS_ERROR, 1, "UART parity error");
49                         return -EINVAL;
50                 }
51         }
52
53         return 0;
54 }
55
56 static void mantis_uart_work(struct work_struct *work)
57 {
58         struct mantis_pci *mantis = container_of(work, struct mantis_pci, uart_work);
59         struct mantis_hwconfig *config = mantis->hwconfig;
60         u8 buf[16];
61         int i;
62
63         dprintk(MANTIS_DEBUG, 1, "UART read");
64         mantis_uart_read(mantis, buf);
65
66         dprintk(MANTIS_DEBUG, 1, "UART: ");
67         for (i = 0; i < (config->bytes + 1); i++)
68                 dprintk(MANTIS_DEBUG, 0, "<%02x> ", buf[i]);
69
70         dprintk(MANTIS_DEBUG, 0, "\n");
71 }
72
73 static int mantis_uart_setup(struct mantis_pci *mantis,
74                              struct mantis_uart_params *params)
75 {
76         char* rates[] = { "B_9600", "B_19200", "B_38400", "B_57600", "B_115200" };
77         char* parity[] = { "NONE", "ODD", "EVEN" };
78
79         u32 reg;
80
81         dprintk(MANTIS_DEBUG, 1, "Set Parity <%s> Baud Rate <%s>",
82                 parity[params->parity],
83                 rates[params->baud_rate]);
84
85         mmwrite((mmread(MANTIS_UART_CTL) | (params->parity & 0x3)), MANTIS_UART_CTL);
86
87         reg = mmread(MANTIS_UART_BAUD);
88
89         switch (params->baud_rate) {
90         case MANTIS_BAUD_9600:
91                 reg |= 0xd8;
92                 break;
93         case MANTIS_BAUD_19200:
94                 reg |= 0x6c;
95                 break;
96         case MANTIS_BAUD_38400:
97                 reg |= 0x36;
98                 break;
99         case MANTIS_BAUD_57600:
100                 reg |= 0x23;
101                 break;
102         case MANTIS_BAUD_115200:
103                 reg |= 0x11;
104                 break;
105         default:
106                 return -EINVAL;
107         }
108
109         mmwrite(reg, MANTIS_UART_BAUD);
110
111         return 0;
112 }
113
114 int mantis_uart_init(struct mantis_pci *mantis)
115 {
116         struct mantis_hwconfig *config = mantis->hwconfig;
117         struct mantis_uart_params params;
118
119         dprintk(MANTIS_DEBUG, 1, "Initializing UART ..");
120         /* default parity: */
121         params.baud_rate = config->baud_rate;
122         params.parity = config->parity;
123
124         init_waitqueue_head(&mantis->uart_wq);
125         spin_lock_init(&mantis->uart_lock);
126
127         INIT_WORK(&mantis->uart_work, mantis_uart_work);
128
129         /* disable interrupt */
130         mmwrite(mmread(MANTIS_UART_CTL) & 0xffef, MANTIS_UART_CTL);
131
132         mantis_uart_setup(mantis, &params);
133
134         /* default 1 byte */
135         mmwrite((mmread(MANTIS_UART_BAUD) | (config->bytes << 8)), MANTIS_UART_BAUD);
136
137         /* flush buffer */
138         mmwrite((mmread(MANTIS_UART_CTL) | MANTIS_UART_RXFLUSH), MANTIS_UART_CTL);
139
140         /* enable interrupt */
141         mmwrite(mmread(MANTIS_INT_MASK) | 0x800, MANTIS_INT_MASK);
142         mmwrite(mmread(MANTIS_UART_CTL) | MANTIS_UART_RXINT, MANTIS_UART_CTL);
143
144         schedule_work(&mantis->uart_work);
145
146         return 0;
147 }
148 EXPORT_SYMBOL_GPL(mantis_uart_init);
149
150 void mantis_uart_exit(struct mantis_pci *mantis)
151 {
152         /* disable interrupt */
153         mmwrite(mmread(MANTIS_UART_CTL) & 0xffef, MANTIS_UART_CTL);
154 }
155 EXPORT_SYMBOL_GPL(mantis_uart_exit);