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>
24 #include <linux/signal.h>
25 #include <linux/sched.h>
26 #include <linux/interrupt.h>
30 #include "dvb_demux.h"
31 #include "dvb_frontend.h"
34 #include "mantis_common.h"
35 #include "mantis_reg.h"
36 #include "mantis_uart.h"
38 struct mantis_uart_params
{
39 enum mantis_baud baud_rate
;
40 enum mantis_parity parity
;
61 #define UART_MAX_BUF 16
63 int mantis_uart_read(struct mantis_pci
*mantis
, u8
*data
)
65 struct mantis_hwconfig
*config
= mantis
->hwconfig
;
69 for (i
= 0; i
< (config
->bytes
+ 1); i
++) {
71 stat
= mmread(MANTIS_UART_STAT
);
73 if (stat
& MANTIS_UART_RXFIFO_FULL
) {
74 dprintk(MANTIS_ERROR
, 1, "RX Fifo FULL");
76 data
[i
] = mmread(MANTIS_UART_RXD
) & 0x3f;
78 dprintk(MANTIS_DEBUG
, 1, "Reading ... <%02x>", data
[i
] & 0x3f);
80 if (data
[i
] & (1 << 7)) {
81 dprintk(MANTIS_ERROR
, 1, "UART framing error");
84 if (data
[i
] & (1 << 6)) {
85 dprintk(MANTIS_ERROR
, 1, "UART parity error");
93 static void mantis_uart_work(struct work_struct
*work
)
95 struct mantis_pci
*mantis
= container_of(work
, struct mantis_pci
, uart_work
);
96 struct mantis_hwconfig
*config
= mantis
->hwconfig
;
100 mantis_uart_read(mantis
, buf
);
102 for (i
= 0; i
< (config
->bytes
+ 1); i
++)
103 dprintk(MANTIS_INFO
, 1, "UART BUF:%d <%02x> ", i
, buf
[i
]);
105 dprintk(MANTIS_DEBUG
, 0, "\n");
108 static int mantis_uart_setup(struct mantis_pci
*mantis
,
109 struct mantis_uart_params
*params
)
113 mmwrite((mmread(MANTIS_UART_CTL
) | (params
->parity
& 0x3)), MANTIS_UART_CTL
);
115 reg
= mmread(MANTIS_UART_BAUD
);
117 switch (params
->baud_rate
) {
118 case MANTIS_BAUD_9600
:
121 case MANTIS_BAUD_19200
:
124 case MANTIS_BAUD_38400
:
127 case MANTIS_BAUD_57600
:
130 case MANTIS_BAUD_115200
:
137 mmwrite(reg
, MANTIS_UART_BAUD
);
142 int mantis_uart_init(struct mantis_pci
*mantis
)
144 struct mantis_hwconfig
*config
= mantis
->hwconfig
;
145 struct mantis_uart_params params
;
147 /* default parity: */
148 params
.baud_rate
= config
->baud_rate
;
149 params
.parity
= config
->parity
;
150 dprintk(MANTIS_INFO
, 1, "Initializing UART @ %sbps parity:%s",
151 rates
[params
.baud_rate
].string
,
152 parity
[params
.parity
].string
);
154 init_waitqueue_head(&mantis
->uart_wq
);
155 spin_lock_init(&mantis
->uart_lock
);
157 INIT_WORK(&mantis
->uart_work
, mantis_uart_work
);
159 /* disable interrupt */
160 mmwrite(mmread(MANTIS_UART_CTL
) & 0xffef, MANTIS_UART_CTL
);
162 mantis_uart_setup(mantis
, ¶ms
);
165 mmwrite((mmread(MANTIS_UART_BAUD
) | (config
->bytes
<< 8)), MANTIS_UART_BAUD
);
168 mmwrite((mmread(MANTIS_UART_CTL
) | MANTIS_UART_RXFLUSH
), MANTIS_UART_CTL
);
170 /* enable interrupt */
171 mmwrite(mmread(MANTIS_INT_MASK
) | 0x800, MANTIS_INT_MASK
);
172 mmwrite(mmread(MANTIS_UART_CTL
) | MANTIS_UART_RXINT
, MANTIS_UART_CTL
);
174 schedule_work(&mantis
->uart_work
);
175 dprintk(MANTIS_DEBUG
, 1, "UART succesfully initialized");
179 EXPORT_SYMBOL_GPL(mantis_uart_init
);
181 void mantis_uart_exit(struct mantis_pci
*mantis
)
183 /* disable interrupt */
184 mmwrite(mmread(MANTIS_UART_CTL
) & 0xffef, MANTIS_UART_CTL
);
186 EXPORT_SYMBOL_GPL(mantis_uart_exit
);