2 Mantis PCI bridge driver
4 Copyright (C) Manu Abraham (abraham.manu@gmail.com)
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include <linux/kernel.h>
22 #include <linux/spinlock.h>
25 #include <linux/signal.h>
26 #include <linux/sched.h>
27 #include <linux/interrupt.h>
28 #include <linux/pci.h>
30 #include <media/dmxdev.h>
31 #include <media/dvbdev.h>
32 #include <media/dvb_demux.h>
33 #include <media/dvb_frontend.h>
34 #include <media/dvb_net.h>
36 #include "mantis_common.h"
37 #include "mantis_reg.h"
38 #include "mantis_uart.h"
39 #include "mantis_input.h"
41 struct mantis_uart_params
{
42 enum mantis_baud baud_rate
;
43 enum mantis_parity parity
;
64 static void mantis_uart_read(struct mantis_pci
*mantis
)
66 struct mantis_hwconfig
*config
= mantis
->hwconfig
;
67 int i
, scancode
= 0, err
= 0;
70 dprintk(MANTIS_DEBUG
, 1, "UART Reading ...");
71 for (i
= 0; i
< (config
->bytes
+ 1); i
++) {
72 int data
= mmread(MANTIS_UART_RXD
);
74 dprintk(MANTIS_DEBUG
, 0, " <%02x>", data
);
76 scancode
= (scancode
<< 8) | (data
& 0x3f);
80 dprintk(MANTIS_ERROR
, 1, "UART framing error");
83 dprintk(MANTIS_ERROR
, 1, "UART parity error");
85 dprintk(MANTIS_DEBUG
, 0, "\n");
87 if ((err
& 0xC0) == 0)
88 mantis_input_process(mantis
, scancode
);
91 static void mantis_uart_work(struct work_struct
*work
)
93 struct mantis_pci
*mantis
= container_of(work
, struct mantis_pci
, uart_work
);
95 unsigned long timeout
;
97 stat
= mmread(MANTIS_UART_STAT
);
99 if (stat
& MANTIS_UART_RXFIFO_FULL
)
100 dprintk(MANTIS_ERROR
, 1, "RX Fifo FULL");
103 * MANTIS_UART_RXFIFO_DATA is only set if at least
104 * config->bytes + 1 bytes are in the FIFO.
107 /* FIXME: is 10ms good enough ? */
108 timeout
= jiffies
+ msecs_to_jiffies(10);
109 while (stat
& MANTIS_UART_RXFIFO_DATA
) {
110 mantis_uart_read(mantis
);
111 stat
= mmread(MANTIS_UART_STAT
);
113 if (!time_is_after_jiffies(timeout
))
117 /* re-enable UART (RX) interrupt */
118 mantis_unmask_ints(mantis
, MANTIS_INT_IRQ1
);
121 static int mantis_uart_setup(struct mantis_pci
*mantis
,
122 struct mantis_uart_params
*params
)
126 mmwrite((mmread(MANTIS_UART_CTL
) | (params
->parity
& 0x3)), MANTIS_UART_CTL
);
128 reg
= mmread(MANTIS_UART_BAUD
);
130 switch (params
->baud_rate
) {
131 case MANTIS_BAUD_9600
:
134 case MANTIS_BAUD_19200
:
137 case MANTIS_BAUD_38400
:
140 case MANTIS_BAUD_57600
:
143 case MANTIS_BAUD_115200
:
150 mmwrite(reg
, MANTIS_UART_BAUD
);
155 int mantis_uart_init(struct mantis_pci
*mantis
)
157 struct mantis_hwconfig
*config
= mantis
->hwconfig
;
158 struct mantis_uart_params params
;
160 /* default parity: */
161 params
.baud_rate
= config
->baud_rate
;
162 params
.parity
= config
->parity
;
163 dprintk(MANTIS_INFO
, 1, "Initializing UART @ %sbps parity:%s",
164 rates
[params
.baud_rate
].string
,
165 parity
[params
.parity
].string
);
167 INIT_WORK(&mantis
->uart_work
, mantis_uart_work
);
169 /* disable interrupt */
170 mmwrite(mmread(MANTIS_UART_CTL
) & 0xffef, MANTIS_UART_CTL
);
172 mantis_uart_setup(mantis
, ¶ms
);
175 mmwrite((mmread(MANTIS_UART_BAUD
) | (config
->bytes
<< 8)), MANTIS_UART_BAUD
);
178 mmwrite((mmread(MANTIS_UART_CTL
) | MANTIS_UART_RXFLUSH
), MANTIS_UART_CTL
);
180 /* enable interrupt */
181 mmwrite(mmread(MANTIS_UART_CTL
) | MANTIS_UART_RXINT
, MANTIS_UART_CTL
);
182 mantis_unmask_ints(mantis
, MANTIS_INT_IRQ1
);
184 schedule_work(&mantis
->uart_work
);
185 dprintk(MANTIS_DEBUG
, 1, "UART successfully initialized");
189 EXPORT_SYMBOL_GPL(mantis_uart_init
);
191 void mantis_uart_exit(struct mantis_pci
*mantis
)
193 /* disable interrupt */
194 mantis_mask_ints(mantis
, MANTIS_INT_IRQ1
);
195 mmwrite(mmread(MANTIS_UART_CTL
) & 0xffef, MANTIS_UART_CTL
);
196 flush_work(&mantis
->uart_work
);
198 EXPORT_SYMBOL_GPL(mantis_uart_exit
);