Manu Abraham | a149735 | 2009-12-11 20:41:07 -0300 | [diff] [blame] | 1 | /* |
| 2 | Mantis PCI bridge driver |
| 3 | |
| 4 | Copyright (C) Manu Abraham (abraham.manu@gmail.com) |
| 5 | |
| 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. |
| 10 | |
| 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. |
| 15 | |
| 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. |
| 19 | */ |
| 20 | |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 21 | #include <linux/kernel.h> |
Manu Abraham | add2063 | 2009-12-04 05:39:57 -0300 | [diff] [blame] | 22 | #include <linux/spinlock.h> |
Alexey Dobriyan | b7f080c | 2011-06-16 11:01:34 +0000 | [diff] [blame] | 23 | #include <asm/io.h> |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 24 | |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 25 | #include <linux/signal.h> |
| 26 | #include <linux/sched.h> |
| 27 | #include <linux/interrupt.h> |
Jan Klötzke | a96762d | 2015-06-06 16:58:13 -0300 | [diff] [blame^] | 28 | #include <linux/pci.h> |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 29 | |
| 30 | #include "dmxdev.h" |
| 31 | #include "dvbdev.h" |
| 32 | #include "dvb_demux.h" |
| 33 | #include "dvb_frontend.h" |
| 34 | #include "dvb_net.h" |
| 35 | |
Manu Abraham | add2063 | 2009-12-04 05:39:57 -0300 | [diff] [blame] | 36 | #include "mantis_common.h" |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 37 | #include "mantis_reg.h" |
| 38 | #include "mantis_uart.h" |
Jan Klötzke | a96762d | 2015-06-06 16:58:13 -0300 | [diff] [blame^] | 39 | #include "mantis_input.h" |
Manu Abraham | add2063 | 2009-12-04 05:39:57 -0300 | [diff] [blame] | 40 | |
| 41 | struct mantis_uart_params { |
| 42 | enum mantis_baud baud_rate; |
| 43 | enum mantis_parity parity; |
| 44 | }; |
| 45 | |
Manu Abraham | a149735 | 2009-12-11 20:41:07 -0300 | [diff] [blame] | 46 | static struct { |
| 47 | char string[7]; |
| 48 | } rates[5] = { |
| 49 | { "9600" }, |
| 50 | { "19200" }, |
| 51 | { "38400" }, |
| 52 | { "57600" }, |
| 53 | { "115200" } |
| 54 | }; |
| 55 | |
| 56 | static struct { |
| 57 | char string[5]; |
| 58 | } parity[3] = { |
| 59 | { "NONE" }, |
| 60 | { "ODD" }, |
| 61 | { "EVEN" } |
| 62 | }; |
| 63 | |
Jan Klötzke | a96762d | 2015-06-06 16:58:13 -0300 | [diff] [blame^] | 64 | static void mantis_uart_read(struct mantis_pci *mantis) |
Manu Abraham | add2063 | 2009-12-04 05:39:57 -0300 | [diff] [blame] | 65 | { |
| 66 | struct mantis_hwconfig *config = mantis->hwconfig; |
Jan Klötzke | a96762d | 2015-06-06 16:58:13 -0300 | [diff] [blame^] | 67 | int i, scancode = 0, err = 0; |
Manu Abraham | add2063 | 2009-12-04 05:39:57 -0300 | [diff] [blame] | 68 | |
| 69 | /* get data */ |
Jan Klötzke | a96762d | 2015-06-06 16:58:13 -0300 | [diff] [blame^] | 70 | dprintk(MANTIS_DEBUG, 1, "UART Reading ..."); |
Manu Abraham | add2063 | 2009-12-04 05:39:57 -0300 | [diff] [blame] | 71 | for (i = 0; i < (config->bytes + 1); i++) { |
Jan Klötzke | a96762d | 2015-06-06 16:58:13 -0300 | [diff] [blame^] | 72 | int data = mmread(MANTIS_UART_RXD); |
| 73 | dprintk(MANTIS_DEBUG, 0, " <%02x>", data); |
Manu Abraham | add2063 | 2009-12-04 05:39:57 -0300 | [diff] [blame] | 74 | |
Jan Klötzke | a96762d | 2015-06-06 16:58:13 -0300 | [diff] [blame^] | 75 | scancode = (scancode << 8) | (data & 0x3f); |
| 76 | err |= data; |
Manu Abraham | 0bdc799 | 2009-12-15 06:17:54 -0300 | [diff] [blame] | 77 | |
Jan Klötzke | a96762d | 2015-06-06 16:58:13 -0300 | [diff] [blame^] | 78 | if (data & (1 << 7)) |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 79 | dprintk(MANTIS_ERROR, 1, "UART framing error"); |
Manu Abraham | add2063 | 2009-12-04 05:39:57 -0300 | [diff] [blame] | 80 | |
Jan Klötzke | a96762d | 2015-06-06 16:58:13 -0300 | [diff] [blame^] | 81 | if (data & (1 << 6)) |
| 82 | dprintk(MANTIS_ERROR, 1, "UART parity error"); |
| 83 | } |
| 84 | dprintk(MANTIS_DEBUG, 0, "\n"); |
| 85 | |
| 86 | if ((err & 0xC0) == 0) |
| 87 | mantis_input_process(mantis, scancode); |
Manu Abraham | add2063 | 2009-12-04 05:39:57 -0300 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | static void mantis_uart_work(struct work_struct *work) |
| 91 | { |
| 92 | struct mantis_pci *mantis = container_of(work, struct mantis_pci, uart_work); |
Jan Klötzke | a96762d | 2015-06-06 16:58:13 -0300 | [diff] [blame^] | 93 | u32 stat; |
Manu Abraham | add2063 | 2009-12-04 05:39:57 -0300 | [diff] [blame] | 94 | |
Jan Klötzke | a96762d | 2015-06-06 16:58:13 -0300 | [diff] [blame^] | 95 | stat = mmread(MANTIS_UART_STAT); |
Manu Abraham | add2063 | 2009-12-04 05:39:57 -0300 | [diff] [blame] | 96 | |
Jan Klötzke | a96762d | 2015-06-06 16:58:13 -0300 | [diff] [blame^] | 97 | if (stat & MANTIS_UART_RXFIFO_FULL) |
| 98 | dprintk(MANTIS_ERROR, 1, "RX Fifo FULL"); |
Manu Abraham | add2063 | 2009-12-04 05:39:57 -0300 | [diff] [blame] | 99 | |
Jan Klötzke | a96762d | 2015-06-06 16:58:13 -0300 | [diff] [blame^] | 100 | /* |
| 101 | * MANTIS_UART_RXFIFO_DATA is only set if at least config->bytes + 1 bytes |
| 102 | * are in the FIFO. |
| 103 | */ |
| 104 | while (stat & MANTIS_UART_RXFIFO_DATA) { |
| 105 | mantis_uart_read(mantis); |
| 106 | stat = mmread(MANTIS_UART_STAT); |
| 107 | } |
| 108 | |
| 109 | /* re-enable UART (RX) interrupt */ |
| 110 | mantis_unmask_ints(mantis, MANTIS_INT_IRQ1); |
Manu Abraham | add2063 | 2009-12-04 05:39:57 -0300 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | static int mantis_uart_setup(struct mantis_pci *mantis, |
| 114 | struct mantis_uart_params *params) |
| 115 | { |
Manu Abraham | add2063 | 2009-12-04 05:39:57 -0300 | [diff] [blame] | 116 | u32 reg; |
| 117 | |
Manu Abraham | add2063 | 2009-12-04 05:39:57 -0300 | [diff] [blame] | 118 | mmwrite((mmread(MANTIS_UART_CTL) | (params->parity & 0x3)), MANTIS_UART_CTL); |
| 119 | |
| 120 | reg = mmread(MANTIS_UART_BAUD); |
| 121 | |
| 122 | switch (params->baud_rate) { |
| 123 | case MANTIS_BAUD_9600: |
| 124 | reg |= 0xd8; |
| 125 | break; |
| 126 | case MANTIS_BAUD_19200: |
| 127 | reg |= 0x6c; |
| 128 | break; |
| 129 | case MANTIS_BAUD_38400: |
| 130 | reg |= 0x36; |
| 131 | break; |
| 132 | case MANTIS_BAUD_57600: |
| 133 | reg |= 0x23; |
| 134 | break; |
| 135 | case MANTIS_BAUD_115200: |
| 136 | reg |= 0x11; |
| 137 | break; |
| 138 | default: |
| 139 | return -EINVAL; |
| 140 | } |
| 141 | |
| 142 | mmwrite(reg, MANTIS_UART_BAUD); |
| 143 | |
| 144 | return 0; |
| 145 | } |
| 146 | |
| 147 | int mantis_uart_init(struct mantis_pci *mantis) |
| 148 | { |
| 149 | struct mantis_hwconfig *config = mantis->hwconfig; |
| 150 | struct mantis_uart_params params; |
| 151 | |
Manu Abraham | add2063 | 2009-12-04 05:39:57 -0300 | [diff] [blame] | 152 | /* default parity: */ |
| 153 | params.baud_rate = config->baud_rate; |
| 154 | params.parity = config->parity; |
Manu Abraham | a149735 | 2009-12-11 20:41:07 -0300 | [diff] [blame] | 155 | dprintk(MANTIS_INFO, 1, "Initializing UART @ %sbps parity:%s", |
| 156 | rates[params.baud_rate].string, |
| 157 | parity[params.parity].string); |
Manu Abraham | add2063 | 2009-12-04 05:39:57 -0300 | [diff] [blame] | 158 | |
Manu Abraham | add2063 | 2009-12-04 05:39:57 -0300 | [diff] [blame] | 159 | INIT_WORK(&mantis->uart_work, mantis_uart_work); |
| 160 | |
| 161 | /* disable interrupt */ |
| 162 | mmwrite(mmread(MANTIS_UART_CTL) & 0xffef, MANTIS_UART_CTL); |
| 163 | |
| 164 | mantis_uart_setup(mantis, ¶ms); |
| 165 | |
| 166 | /* default 1 byte */ |
| 167 | mmwrite((mmread(MANTIS_UART_BAUD) | (config->bytes << 8)), MANTIS_UART_BAUD); |
| 168 | |
| 169 | /* flush buffer */ |
| 170 | mmwrite((mmread(MANTIS_UART_CTL) | MANTIS_UART_RXFLUSH), MANTIS_UART_CTL); |
| 171 | |
| 172 | /* enable interrupt */ |
Manu Abraham | add2063 | 2009-12-04 05:39:57 -0300 | [diff] [blame] | 173 | mmwrite(mmread(MANTIS_UART_CTL) | MANTIS_UART_RXINT, MANTIS_UART_CTL); |
Jan Klötzke | a96762d | 2015-06-06 16:58:13 -0300 | [diff] [blame^] | 174 | mantis_unmask_ints(mantis, MANTIS_INT_IRQ1); |
Manu Abraham | add2063 | 2009-12-04 05:39:57 -0300 | [diff] [blame] | 175 | |
| 176 | schedule_work(&mantis->uart_work); |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 177 | dprintk(MANTIS_DEBUG, 1, "UART successfully initialized"); |
Manu Abraham | add2063 | 2009-12-04 05:39:57 -0300 | [diff] [blame] | 178 | |
| 179 | return 0; |
| 180 | } |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 181 | EXPORT_SYMBOL_GPL(mantis_uart_init); |
Manu Abraham | add2063 | 2009-12-04 05:39:57 -0300 | [diff] [blame] | 182 | |
| 183 | void mantis_uart_exit(struct mantis_pci *mantis) |
| 184 | { |
| 185 | /* disable interrupt */ |
Jan Klötzke | a96762d | 2015-06-06 16:58:13 -0300 | [diff] [blame^] | 186 | mantis_mask_ints(mantis, MANTIS_INT_IRQ1); |
Manu Abraham | add2063 | 2009-12-04 05:39:57 -0300 | [diff] [blame] | 187 | mmwrite(mmread(MANTIS_UART_CTL) & 0xffef, MANTIS_UART_CTL); |
Tejun Heo | 4382973 | 2012-08-20 14:51:24 -0700 | [diff] [blame] | 188 | flush_work(&mantis->uart_work); |
Manu Abraham | add2063 | 2009-12-04 05:39:57 -0300 | [diff] [blame] | 189 | } |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 190 | EXPORT_SYMBOL_GPL(mantis_uart_exit); |