Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is subject to the terms and conditions of the GNU General Public |
| 3 | * License. See the file "COPYING" in the main directory of this archive |
| 4 | * for more details. |
| 5 | * |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 6 | * Copyright (C) 2003-2006 Silicon Graphics, Inc. All Rights Reserved. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | |
| 10 | /* |
| 11 | * This file contains a module version of the ioc4 serial driver. This |
| 12 | * includes all the support functions needed (support functions, etc.) |
| 13 | * and the serial driver itself. |
| 14 | */ |
| 15 | #include <linux/errno.h> |
| 16 | #include <linux/tty.h> |
| 17 | #include <linux/serial.h> |
| 18 | #include <linux/serialP.h> |
| 19 | #include <linux/circ_buf.h> |
| 20 | #include <linux/serial_reg.h> |
| 21 | #include <linux/module.h> |
| 22 | #include <linux/pci.h> |
Brent Casavant | 22329b5 | 2005-06-21 17:15:59 -0700 | [diff] [blame] | 23 | #include <linux/ioc4.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <linux/serial_core.h> |
| 25 | |
| 26 | /* |
| 27 | * interesting things about the ioc4 |
| 28 | */ |
| 29 | |
| 30 | #define IOC4_NUM_SERIAL_PORTS 4 /* max ports per card */ |
| 31 | #define IOC4_NUM_CARDS 8 /* max cards per partition */ |
| 32 | |
| 33 | #define GET_SIO_IR(_n) (_n == 0) ? (IOC4_SIO_IR_S0) : \ |
| 34 | (_n == 1) ? (IOC4_SIO_IR_S1) : \ |
| 35 | (_n == 2) ? (IOC4_SIO_IR_S2) : \ |
| 36 | (IOC4_SIO_IR_S3) |
| 37 | |
| 38 | #define GET_OTHER_IR(_n) (_n == 0) ? (IOC4_OTHER_IR_S0_MEMERR) : \ |
| 39 | (_n == 1) ? (IOC4_OTHER_IR_S1_MEMERR) : \ |
| 40 | (_n == 2) ? (IOC4_OTHER_IR_S2_MEMERR) : \ |
| 41 | (IOC4_OTHER_IR_S3_MEMERR) |
| 42 | |
| 43 | |
| 44 | /* |
| 45 | * All IOC4 registers are 32 bits wide. |
| 46 | */ |
| 47 | |
| 48 | /* |
| 49 | * PCI Memory Space Map |
| 50 | */ |
| 51 | #define IOC4_PCI_ERR_ADDR_L 0x000 /* Low Error Address */ |
| 52 | #define IOC4_PCI_ERR_ADDR_VLD (0x1 << 0) |
| 53 | #define IOC4_PCI_ERR_ADDR_MST_ID_MSK (0xf << 1) |
| 54 | #define IOC4_PCI_ERR_ADDR_MST_NUM_MSK (0xe << 1) |
| 55 | #define IOC4_PCI_ERR_ADDR_MST_TYP_MSK (0x1 << 1) |
| 56 | #define IOC4_PCI_ERR_ADDR_MUL_ERR (0x1 << 5) |
| 57 | #define IOC4_PCI_ERR_ADDR_ADDR_MSK (0x3ffffff << 6) |
| 58 | |
| 59 | /* Interrupt types */ |
| 60 | #define IOC4_SIO_INTR_TYPE 0 |
| 61 | #define IOC4_OTHER_INTR_TYPE 1 |
| 62 | #define IOC4_NUM_INTR_TYPES 2 |
| 63 | |
| 64 | /* Bitmasks for IOC4_SIO_IR, IOC4_SIO_IEC, and IOC4_SIO_IES */ |
| 65 | #define IOC4_SIO_IR_S0_TX_MT 0x00000001 /* Serial port 0 TX empty */ |
| 66 | #define IOC4_SIO_IR_S0_RX_FULL 0x00000002 /* Port 0 RX buf full */ |
| 67 | #define IOC4_SIO_IR_S0_RX_HIGH 0x00000004 /* Port 0 RX hiwat */ |
| 68 | #define IOC4_SIO_IR_S0_RX_TIMER 0x00000008 /* Port 0 RX timeout */ |
| 69 | #define IOC4_SIO_IR_S0_DELTA_DCD 0x00000010 /* Port 0 delta DCD */ |
| 70 | #define IOC4_SIO_IR_S0_DELTA_CTS 0x00000020 /* Port 0 delta CTS */ |
| 71 | #define IOC4_SIO_IR_S0_INT 0x00000040 /* Port 0 pass-thru intr */ |
| 72 | #define IOC4_SIO_IR_S0_TX_EXPLICIT 0x00000080 /* Port 0 explicit TX thru */ |
| 73 | #define IOC4_SIO_IR_S1_TX_MT 0x00000100 /* Serial port 1 */ |
| 74 | #define IOC4_SIO_IR_S1_RX_FULL 0x00000200 /* */ |
| 75 | #define IOC4_SIO_IR_S1_RX_HIGH 0x00000400 /* */ |
| 76 | #define IOC4_SIO_IR_S1_RX_TIMER 0x00000800 /* */ |
| 77 | #define IOC4_SIO_IR_S1_DELTA_DCD 0x00001000 /* */ |
| 78 | #define IOC4_SIO_IR_S1_DELTA_CTS 0x00002000 /* */ |
| 79 | #define IOC4_SIO_IR_S1_INT 0x00004000 /* */ |
| 80 | #define IOC4_SIO_IR_S1_TX_EXPLICIT 0x00008000 /* */ |
| 81 | #define IOC4_SIO_IR_S2_TX_MT 0x00010000 /* Serial port 2 */ |
| 82 | #define IOC4_SIO_IR_S2_RX_FULL 0x00020000 /* */ |
| 83 | #define IOC4_SIO_IR_S2_RX_HIGH 0x00040000 /* */ |
| 84 | #define IOC4_SIO_IR_S2_RX_TIMER 0x00080000 /* */ |
| 85 | #define IOC4_SIO_IR_S2_DELTA_DCD 0x00100000 /* */ |
| 86 | #define IOC4_SIO_IR_S2_DELTA_CTS 0x00200000 /* */ |
| 87 | #define IOC4_SIO_IR_S2_INT 0x00400000 /* */ |
| 88 | #define IOC4_SIO_IR_S2_TX_EXPLICIT 0x00800000 /* */ |
| 89 | #define IOC4_SIO_IR_S3_TX_MT 0x01000000 /* Serial port 3 */ |
| 90 | #define IOC4_SIO_IR_S3_RX_FULL 0x02000000 /* */ |
| 91 | #define IOC4_SIO_IR_S3_RX_HIGH 0x04000000 /* */ |
| 92 | #define IOC4_SIO_IR_S3_RX_TIMER 0x08000000 /* */ |
| 93 | #define IOC4_SIO_IR_S3_DELTA_DCD 0x10000000 /* */ |
| 94 | #define IOC4_SIO_IR_S3_DELTA_CTS 0x20000000 /* */ |
| 95 | #define IOC4_SIO_IR_S3_INT 0x40000000 /* */ |
| 96 | #define IOC4_SIO_IR_S3_TX_EXPLICIT 0x80000000 /* */ |
| 97 | |
| 98 | /* Per device interrupt masks */ |
| 99 | #define IOC4_SIO_IR_S0 (IOC4_SIO_IR_S0_TX_MT | \ |
| 100 | IOC4_SIO_IR_S0_RX_FULL | \ |
| 101 | IOC4_SIO_IR_S0_RX_HIGH | \ |
| 102 | IOC4_SIO_IR_S0_RX_TIMER | \ |
| 103 | IOC4_SIO_IR_S0_DELTA_DCD | \ |
| 104 | IOC4_SIO_IR_S0_DELTA_CTS | \ |
| 105 | IOC4_SIO_IR_S0_INT | \ |
| 106 | IOC4_SIO_IR_S0_TX_EXPLICIT) |
| 107 | #define IOC4_SIO_IR_S1 (IOC4_SIO_IR_S1_TX_MT | \ |
| 108 | IOC4_SIO_IR_S1_RX_FULL | \ |
| 109 | IOC4_SIO_IR_S1_RX_HIGH | \ |
| 110 | IOC4_SIO_IR_S1_RX_TIMER | \ |
| 111 | IOC4_SIO_IR_S1_DELTA_DCD | \ |
| 112 | IOC4_SIO_IR_S1_DELTA_CTS | \ |
| 113 | IOC4_SIO_IR_S1_INT | \ |
| 114 | IOC4_SIO_IR_S1_TX_EXPLICIT) |
| 115 | #define IOC4_SIO_IR_S2 (IOC4_SIO_IR_S2_TX_MT | \ |
| 116 | IOC4_SIO_IR_S2_RX_FULL | \ |
| 117 | IOC4_SIO_IR_S2_RX_HIGH | \ |
| 118 | IOC4_SIO_IR_S2_RX_TIMER | \ |
| 119 | IOC4_SIO_IR_S2_DELTA_DCD | \ |
| 120 | IOC4_SIO_IR_S2_DELTA_CTS | \ |
| 121 | IOC4_SIO_IR_S2_INT | \ |
| 122 | IOC4_SIO_IR_S2_TX_EXPLICIT) |
| 123 | #define IOC4_SIO_IR_S3 (IOC4_SIO_IR_S3_TX_MT | \ |
| 124 | IOC4_SIO_IR_S3_RX_FULL | \ |
| 125 | IOC4_SIO_IR_S3_RX_HIGH | \ |
| 126 | IOC4_SIO_IR_S3_RX_TIMER | \ |
| 127 | IOC4_SIO_IR_S3_DELTA_DCD | \ |
| 128 | IOC4_SIO_IR_S3_DELTA_CTS | \ |
| 129 | IOC4_SIO_IR_S3_INT | \ |
| 130 | IOC4_SIO_IR_S3_TX_EXPLICIT) |
| 131 | |
| 132 | /* Bitmasks for IOC4_OTHER_IR, IOC4_OTHER_IEC, and IOC4_OTHER_IES */ |
Brent Casavant | 22329b5 | 2005-06-21 17:15:59 -0700 | [diff] [blame] | 133 | #define IOC4_OTHER_IR_ATA_INT 0x00000001 /* ATAPI intr pass-thru */ |
| 134 | #define IOC4_OTHER_IR_ATA_MEMERR 0x00000002 /* ATAPI DMA PCI error */ |
| 135 | #define IOC4_OTHER_IR_S0_MEMERR 0x00000004 /* Port 0 PCI error */ |
| 136 | #define IOC4_OTHER_IR_S1_MEMERR 0x00000008 /* Port 1 PCI error */ |
| 137 | #define IOC4_OTHER_IR_S2_MEMERR 0x00000010 /* Port 2 PCI error */ |
| 138 | #define IOC4_OTHER_IR_S3_MEMERR 0x00000020 /* Port 3 PCI error */ |
| 139 | #define IOC4_OTHER_IR_KBD_INT 0x00000040 /* Keyboard/mouse */ |
| 140 | #define IOC4_OTHER_IR_RESERVED 0x007fff80 /* Reserved */ |
| 141 | #define IOC4_OTHER_IR_RT_INT 0x00800000 /* INT_OUT section output */ |
| 142 | #define IOC4_OTHER_IR_GEN_INT 0xff000000 /* Generic pins */ |
| 143 | |
| 144 | #define IOC4_OTHER_IR_SER_MEMERR (IOC4_OTHER_IR_S0_MEMERR | IOC4_OTHER_IR_S1_MEMERR | \ |
| 145 | IOC4_OTHER_IR_S2_MEMERR | IOC4_OTHER_IR_S3_MEMERR) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | |
| 147 | /* Bitmasks for IOC4_SIO_CR */ |
| 148 | #define IOC4_SIO_CR_CMD_PULSE_SHIFT 0 /* byte bus strobe shift */ |
| 149 | #define IOC4_SIO_CR_ARB_DIAG_TX0 0x00000000 |
| 150 | #define IOC4_SIO_CR_ARB_DIAG_RX0 0x00000010 |
| 151 | #define IOC4_SIO_CR_ARB_DIAG_TX1 0x00000020 |
| 152 | #define IOC4_SIO_CR_ARB_DIAG_RX1 0x00000030 |
| 153 | #define IOC4_SIO_CR_ARB_DIAG_TX2 0x00000040 |
| 154 | #define IOC4_SIO_CR_ARB_DIAG_RX2 0x00000050 |
| 155 | #define IOC4_SIO_CR_ARB_DIAG_TX3 0x00000060 |
| 156 | #define IOC4_SIO_CR_ARB_DIAG_RX3 0x00000070 |
| 157 | #define IOC4_SIO_CR_SIO_DIAG_IDLE 0x00000080 /* 0 -> active request among |
| 158 | serial ports (ro) */ |
| 159 | /* Defs for some of the generic I/O pins */ |
| 160 | #define IOC4_GPCR_UART0_MODESEL 0x10 /* Pin is output to port 0 |
| 161 | mode sel */ |
| 162 | #define IOC4_GPCR_UART1_MODESEL 0x20 /* Pin is output to port 1 |
| 163 | mode sel */ |
| 164 | #define IOC4_GPCR_UART2_MODESEL 0x40 /* Pin is output to port 2 |
| 165 | mode sel */ |
| 166 | #define IOC4_GPCR_UART3_MODESEL 0x80 /* Pin is output to port 3 |
| 167 | mode sel */ |
| 168 | |
| 169 | #define IOC4_GPPR_UART0_MODESEL_PIN 4 /* GIO pin controlling |
| 170 | uart 0 mode select */ |
| 171 | #define IOC4_GPPR_UART1_MODESEL_PIN 5 /* GIO pin controlling |
| 172 | uart 1 mode select */ |
| 173 | #define IOC4_GPPR_UART2_MODESEL_PIN 6 /* GIO pin controlling |
| 174 | uart 2 mode select */ |
| 175 | #define IOC4_GPPR_UART3_MODESEL_PIN 7 /* GIO pin controlling |
| 176 | uart 3 mode select */ |
| 177 | |
| 178 | /* Bitmasks for serial RX status byte */ |
| 179 | #define IOC4_RXSB_OVERRUN 0x01 /* Char(s) lost */ |
| 180 | #define IOC4_RXSB_PAR_ERR 0x02 /* Parity error */ |
| 181 | #define IOC4_RXSB_FRAME_ERR 0x04 /* Framing error */ |
| 182 | #define IOC4_RXSB_BREAK 0x08 /* Break character */ |
| 183 | #define IOC4_RXSB_CTS 0x10 /* State of CTS */ |
| 184 | #define IOC4_RXSB_DCD 0x20 /* State of DCD */ |
| 185 | #define IOC4_RXSB_MODEM_VALID 0x40 /* DCD, CTS, and OVERRUN are valid */ |
| 186 | #define IOC4_RXSB_DATA_VALID 0x80 /* Data byte, FRAME_ERR PAR_ERR |
| 187 | * & BREAK valid */ |
| 188 | |
| 189 | /* Bitmasks for serial TX control byte */ |
| 190 | #define IOC4_TXCB_INT_WHEN_DONE 0x20 /* Interrupt after this byte is sent */ |
| 191 | #define IOC4_TXCB_INVALID 0x00 /* Byte is invalid */ |
| 192 | #define IOC4_TXCB_VALID 0x40 /* Byte is valid */ |
| 193 | #define IOC4_TXCB_MCR 0x80 /* Data<7:0> to modem control reg */ |
| 194 | #define IOC4_TXCB_DELAY 0xc0 /* Delay data<7:0> mSec */ |
| 195 | |
| 196 | /* Bitmasks for IOC4_SBBR_L */ |
| 197 | #define IOC4_SBBR_L_SIZE 0x00000001 /* 0 == 1KB rings, 1 == 4KB rings */ |
| 198 | |
| 199 | /* Bitmasks for IOC4_SSCR_<3:0> */ |
| 200 | #define IOC4_SSCR_RX_THRESHOLD 0x000001ff /* Hiwater mark */ |
| 201 | #define IOC4_SSCR_TX_TIMER_BUSY 0x00010000 /* TX timer in progress */ |
| 202 | #define IOC4_SSCR_HFC_EN 0x00020000 /* Hardware flow control enabled */ |
| 203 | #define IOC4_SSCR_RX_RING_DCD 0x00040000 /* Post RX record on delta-DCD */ |
| 204 | #define IOC4_SSCR_RX_RING_CTS 0x00080000 /* Post RX record on delta-CTS */ |
| 205 | #define IOC4_SSCR_DIAG 0x00200000 /* Bypass clock divider for sim */ |
| 206 | #define IOC4_SSCR_RX_DRAIN 0x08000000 /* Drain RX buffer to memory */ |
| 207 | #define IOC4_SSCR_DMA_EN 0x10000000 /* Enable ring buffer DMA */ |
| 208 | #define IOC4_SSCR_DMA_PAUSE 0x20000000 /* Pause DMA */ |
| 209 | #define IOC4_SSCR_PAUSE_STATE 0x40000000 /* Sets when PAUSE takes effect */ |
| 210 | #define IOC4_SSCR_RESET 0x80000000 /* Reset DMA channels */ |
| 211 | |
| 212 | /* All producer/comsumer pointers are the same bitfield */ |
| 213 | #define IOC4_PROD_CONS_PTR_4K 0x00000ff8 /* For 4K buffers */ |
| 214 | #define IOC4_PROD_CONS_PTR_1K 0x000003f8 /* For 1K buffers */ |
| 215 | #define IOC4_PROD_CONS_PTR_OFF 3 |
| 216 | |
| 217 | /* Bitmasks for IOC4_SRCIR_<3:0> */ |
| 218 | #define IOC4_SRCIR_ARM 0x80000000 /* Arm RX timer */ |
| 219 | |
| 220 | /* Bitmasks for IOC4_SHADOW_<3:0> */ |
| 221 | #define IOC4_SHADOW_DR 0x00000001 /* Data ready */ |
| 222 | #define IOC4_SHADOW_OE 0x00000002 /* Overrun error */ |
| 223 | #define IOC4_SHADOW_PE 0x00000004 /* Parity error */ |
| 224 | #define IOC4_SHADOW_FE 0x00000008 /* Framing error */ |
| 225 | #define IOC4_SHADOW_BI 0x00000010 /* Break interrupt */ |
| 226 | #define IOC4_SHADOW_THRE 0x00000020 /* Xmit holding register empty */ |
| 227 | #define IOC4_SHADOW_TEMT 0x00000040 /* Xmit shift register empty */ |
| 228 | #define IOC4_SHADOW_RFCE 0x00000080 /* Char in RX fifo has an error */ |
| 229 | #define IOC4_SHADOW_DCTS 0x00010000 /* Delta clear to send */ |
| 230 | #define IOC4_SHADOW_DDCD 0x00080000 /* Delta data carrier detect */ |
| 231 | #define IOC4_SHADOW_CTS 0x00100000 /* Clear to send */ |
| 232 | #define IOC4_SHADOW_DCD 0x00800000 /* Data carrier detect */ |
| 233 | #define IOC4_SHADOW_DTR 0x01000000 /* Data terminal ready */ |
| 234 | #define IOC4_SHADOW_RTS 0x02000000 /* Request to send */ |
| 235 | #define IOC4_SHADOW_OUT1 0x04000000 /* 16550 OUT1 bit */ |
| 236 | #define IOC4_SHADOW_OUT2 0x08000000 /* 16550 OUT2 bit */ |
| 237 | #define IOC4_SHADOW_LOOP 0x10000000 /* Loopback enabled */ |
| 238 | |
| 239 | /* Bitmasks for IOC4_SRTR_<3:0> */ |
| 240 | #define IOC4_SRTR_CNT 0x00000fff /* Reload value for RX timer */ |
| 241 | #define IOC4_SRTR_CNT_VAL 0x0fff0000 /* Current value of RX timer */ |
| 242 | #define IOC4_SRTR_CNT_VAL_SHIFT 16 |
| 243 | #define IOC4_SRTR_HZ 16000 /* SRTR clock frequency */ |
| 244 | |
| 245 | /* Serial port register map used for DMA and PIO serial I/O */ |
| 246 | struct ioc4_serialregs { |
| 247 | uint32_t sscr; |
| 248 | uint32_t stpir; |
| 249 | uint32_t stcir; |
| 250 | uint32_t srpir; |
| 251 | uint32_t srcir; |
| 252 | uint32_t srtr; |
| 253 | uint32_t shadow; |
| 254 | }; |
| 255 | |
| 256 | /* IOC4 UART register map */ |
| 257 | struct ioc4_uartregs { |
| 258 | char i4u_lcr; |
| 259 | union { |
| 260 | char iir; /* read only */ |
| 261 | char fcr; /* write only */ |
| 262 | } u3; |
| 263 | union { |
| 264 | char ier; /* DLAB == 0 */ |
| 265 | char dlm; /* DLAB == 1 */ |
| 266 | } u2; |
| 267 | union { |
| 268 | char rbr; /* read only, DLAB == 0 */ |
| 269 | char thr; /* write only, DLAB == 0 */ |
| 270 | char dll; /* DLAB == 1 */ |
| 271 | } u1; |
| 272 | char i4u_scr; |
| 273 | char i4u_msr; |
| 274 | char i4u_lsr; |
| 275 | char i4u_mcr; |
| 276 | }; |
| 277 | |
| 278 | /* short names */ |
| 279 | #define i4u_dll u1.dll |
| 280 | #define i4u_ier u2.ier |
| 281 | #define i4u_dlm u2.dlm |
| 282 | #define i4u_fcr u3.fcr |
| 283 | |
Brent Casavant | 22329b5 | 2005-06-21 17:15:59 -0700 | [diff] [blame] | 284 | /* Serial port registers used for DMA serial I/O */ |
| 285 | struct ioc4_serial { |
| 286 | uint32_t sbbr01_l; |
| 287 | uint32_t sbbr01_h; |
| 288 | uint32_t sbbr23_l; |
| 289 | uint32_t sbbr23_h; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | |
Brent Casavant | 22329b5 | 2005-06-21 17:15:59 -0700 | [diff] [blame] | 291 | struct ioc4_serialregs port_0; |
| 292 | struct ioc4_serialregs port_1; |
| 293 | struct ioc4_serialregs port_2; |
| 294 | struct ioc4_serialregs port_3; |
| 295 | struct ioc4_uartregs uart_0; |
| 296 | struct ioc4_uartregs uart_1; |
| 297 | struct ioc4_uartregs uart_2; |
| 298 | struct ioc4_uartregs uart_3; |
| 299 | } ioc4_serial; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | |
| 301 | /* UART clock speed */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | #define IOC4_SER_XIN_CLK_66 66666667 |
| 303 | #define IOC4_SER_XIN_CLK_33 33333333 |
| 304 | |
| 305 | #define IOC4_W_IES 0 |
| 306 | #define IOC4_W_IEC 1 |
| 307 | |
| 308 | typedef void ioc4_intr_func_f(void *, uint32_t); |
| 309 | typedef ioc4_intr_func_f *ioc4_intr_func_t; |
| 310 | |
Pat Gefre | 396dc44 | 2005-10-30 15:02:49 -0800 | [diff] [blame] | 311 | static unsigned int Num_of_ioc4_cards; |
| 312 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | /* defining this will get you LOTS of great debug info */ |
| 314 | //#define DEBUG_INTERRUPTS |
| 315 | #define DPRINT_CONFIG(_x...) ; |
| 316 | //#define DPRINT_CONFIG(_x...) printk _x |
| 317 | |
| 318 | /* number of characters left in xmit buffer before we ask for more */ |
| 319 | #define WAKEUP_CHARS 256 |
| 320 | |
| 321 | /* number of characters we want to transmit to the lower level at a time */ |
Pat Gefre | 396dc44 | 2005-10-30 15:02:49 -0800 | [diff] [blame] | 322 | #define IOC4_MAX_CHARS 256 |
| 323 | #define IOC4_FIFO_CHARS 255 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | |
| 325 | /* Device name we're using */ |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 326 | #define DEVICE_NAME_RS232 "ttyIOC" |
| 327 | #define DEVICE_NAME_RS422 "ttyAIOC" |
| 328 | #define DEVICE_MAJOR 204 |
| 329 | #define DEVICE_MINOR_RS232 50 |
| 330 | #define DEVICE_MINOR_RS422 84 |
| 331 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | |
| 333 | /* register offsets */ |
| 334 | #define IOC4_SERIAL_OFFSET 0x300 |
| 335 | |
| 336 | /* flags for next_char_state */ |
| 337 | #define NCS_BREAK 0x1 |
| 338 | #define NCS_PARITY 0x2 |
| 339 | #define NCS_FRAMING 0x4 |
| 340 | #define NCS_OVERRUN 0x8 |
| 341 | |
| 342 | /* cause we need SOME parameters ... */ |
| 343 | #define MIN_BAUD_SUPPORTED 1200 |
| 344 | #define MAX_BAUD_SUPPORTED 115200 |
| 345 | |
| 346 | /* protocol types supported */ |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 347 | #define PROTO_RS232 3 |
| 348 | #define PROTO_RS422 7 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | |
| 350 | /* Notification types */ |
| 351 | #define N_DATA_READY 0x01 |
| 352 | #define N_OUTPUT_LOWAT 0x02 |
| 353 | #define N_BREAK 0x04 |
| 354 | #define N_PARITY_ERROR 0x08 |
| 355 | #define N_FRAMING_ERROR 0x10 |
| 356 | #define N_OVERRUN_ERROR 0x20 |
| 357 | #define N_DDCD 0x40 |
| 358 | #define N_DCTS 0x80 |
| 359 | |
| 360 | #define N_ALL_INPUT (N_DATA_READY | N_BREAK | \ |
| 361 | N_PARITY_ERROR | N_FRAMING_ERROR | \ |
| 362 | N_OVERRUN_ERROR | N_DDCD | N_DCTS) |
| 363 | |
| 364 | #define N_ALL_OUTPUT N_OUTPUT_LOWAT |
| 365 | |
| 366 | #define N_ALL_ERRORS (N_PARITY_ERROR | N_FRAMING_ERROR | N_OVERRUN_ERROR) |
| 367 | |
| 368 | #define N_ALL (N_DATA_READY | N_OUTPUT_LOWAT | N_BREAK | \ |
| 369 | N_PARITY_ERROR | N_FRAMING_ERROR | \ |
| 370 | N_OVERRUN_ERROR | N_DDCD | N_DCTS) |
| 371 | |
| 372 | #define SER_DIVISOR(_x, clk) (((clk) + (_x) * 8) / ((_x) * 16)) |
| 373 | #define DIVISOR_TO_BAUD(div, clk) ((clk) / 16 / (div)) |
| 374 | |
| 375 | /* Some masks */ |
| 376 | #define LCR_MASK_BITS_CHAR (UART_LCR_WLEN5 | UART_LCR_WLEN6 \ |
| 377 | | UART_LCR_WLEN7 | UART_LCR_WLEN8) |
| 378 | #define LCR_MASK_STOP_BITS (UART_LCR_STOP) |
| 379 | |
Brent Casavant | 22329b5 | 2005-06-21 17:15:59 -0700 | [diff] [blame] | 380 | #define PENDING(_p) (readl(&(_p)->ip_mem->sio_ir.raw) & _p->ip_ienb) |
| 381 | #define READ_SIO_IR(_p) readl(&(_p)->ip_mem->sio_ir.raw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | |
| 383 | /* Default to 4k buffers */ |
| 384 | #ifdef IOC4_1K_BUFFERS |
| 385 | #define RING_BUF_SIZE 1024 |
| 386 | #define IOC4_BUF_SIZE_BIT 0 |
| 387 | #define PROD_CONS_MASK IOC4_PROD_CONS_PTR_1K |
| 388 | #else |
| 389 | #define RING_BUF_SIZE 4096 |
| 390 | #define IOC4_BUF_SIZE_BIT IOC4_SBBR_L_SIZE |
| 391 | #define PROD_CONS_MASK IOC4_PROD_CONS_PTR_4K |
| 392 | #endif |
| 393 | |
| 394 | #define TOTAL_RING_BUF_SIZE (RING_BUF_SIZE * 4) |
| 395 | |
| 396 | /* |
| 397 | * This is the entry saved by the driver - one per card |
| 398 | */ |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 399 | |
| 400 | #define UART_PORT_MIN 0 |
| 401 | #define UART_PORT_RS232 UART_PORT_MIN |
| 402 | #define UART_PORT_RS422 1 |
| 403 | #define UART_PORT_COUNT 2 /* one for each mode */ |
| 404 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | struct ioc4_control { |
| 406 | int ic_irq; |
| 407 | struct { |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 408 | /* uart ports are allocated here - 1 for rs232, 1 for rs422 */ |
| 409 | struct uart_port icp_uart_port[UART_PORT_COUNT]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | /* Handy reference material */ |
| 411 | struct ioc4_port *icp_port; |
| 412 | } ic_port[IOC4_NUM_SERIAL_PORTS]; |
| 413 | struct ioc4_soft *ic_soft; |
| 414 | }; |
| 415 | |
| 416 | /* |
| 417 | * per-IOC4 data structure |
| 418 | */ |
| 419 | #define MAX_IOC4_INTR_ENTS (8 * sizeof(uint32_t)) |
| 420 | struct ioc4_soft { |
Brent Casavant | 22329b5 | 2005-06-21 17:15:59 -0700 | [diff] [blame] | 421 | struct ioc4_misc_regs __iomem *is_ioc4_misc_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | struct ioc4_serial __iomem *is_ioc4_serial_addr; |
| 423 | |
| 424 | /* Each interrupt type has an entry in the array */ |
| 425 | struct ioc4_intr_type { |
| 426 | |
| 427 | /* |
| 428 | * Each in-use entry in this array contains at least |
| 429 | * one nonzero bit in sd_bits; no two entries in this |
| 430 | * array have overlapping sd_bits values. |
| 431 | */ |
| 432 | struct ioc4_intr_info { |
| 433 | uint32_t sd_bits; |
| 434 | ioc4_intr_func_f *sd_intr; |
| 435 | void *sd_info; |
| 436 | } is_intr_info[MAX_IOC4_INTR_ENTS]; |
| 437 | |
| 438 | /* Number of entries active in the above array */ |
| 439 | atomic_t is_num_intrs; |
| 440 | } is_intr_type[IOC4_NUM_INTR_TYPES]; |
| 441 | |
| 442 | /* is_ir_lock must be held while |
| 443 | * modifying sio_ie values, so |
| 444 | * we can be sure that sio_ie is |
| 445 | * not changing when we read it |
| 446 | * along with sio_ir. |
| 447 | */ |
| 448 | spinlock_t is_ir_lock; /* SIO_IE[SC] mod lock */ |
| 449 | }; |
| 450 | |
| 451 | /* Local port info for each IOC4 serial ports */ |
| 452 | struct ioc4_port { |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 453 | struct uart_port *ip_port; /* current active port ptr */ |
| 454 | /* Ptrs for all ports */ |
| 455 | struct uart_port *ip_all_ports[UART_PORT_COUNT]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | /* Back ptrs for this port */ |
| 457 | struct ioc4_control *ip_control; |
| 458 | struct pci_dev *ip_pdev; |
| 459 | struct ioc4_soft *ip_ioc4_soft; |
| 460 | |
| 461 | /* pci mem addresses */ |
Brent Casavant | 22329b5 | 2005-06-21 17:15:59 -0700 | [diff] [blame] | 462 | struct ioc4_misc_regs __iomem *ip_mem; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | struct ioc4_serial __iomem *ip_serial; |
| 464 | struct ioc4_serialregs __iomem *ip_serial_regs; |
| 465 | struct ioc4_uartregs __iomem *ip_uart_regs; |
| 466 | |
| 467 | /* Ring buffer page for this port */ |
| 468 | dma_addr_t ip_dma_ringbuf; |
| 469 | /* vaddr of ring buffer */ |
| 470 | struct ring_buffer *ip_cpu_ringbuf; |
| 471 | |
| 472 | /* Rings for this port */ |
| 473 | struct ring *ip_inring; |
| 474 | struct ring *ip_outring; |
| 475 | |
| 476 | /* Hook to port specific values */ |
| 477 | struct hooks *ip_hooks; |
| 478 | |
| 479 | spinlock_t ip_lock; |
| 480 | |
| 481 | /* Various rx/tx parameters */ |
| 482 | int ip_baud; |
| 483 | int ip_tx_lowat; |
| 484 | int ip_rx_timeout; |
| 485 | |
| 486 | /* Copy of notification bits */ |
| 487 | int ip_notify; |
| 488 | |
| 489 | /* Shadow copies of various registers so we don't need to PIO |
| 490 | * read them constantly |
| 491 | */ |
| 492 | uint32_t ip_ienb; /* Enabled interrupts */ |
| 493 | uint32_t ip_sscr; |
| 494 | uint32_t ip_tx_prod; |
| 495 | uint32_t ip_rx_cons; |
| 496 | int ip_pci_bus_speed; |
| 497 | unsigned char ip_flags; |
| 498 | }; |
| 499 | |
| 500 | /* tx low water mark. We need to notify the driver whenever tx is getting |
| 501 | * close to empty so it can refill the tx buffer and keep things going. |
| 502 | * Let's assume that if we interrupt 1 ms before the tx goes idle, we'll |
| 503 | * have no trouble getting in more chars in time (I certainly hope so). |
| 504 | */ |
| 505 | #define TX_LOWAT_LATENCY 1000 |
| 506 | #define TX_LOWAT_HZ (1000000 / TX_LOWAT_LATENCY) |
| 507 | #define TX_LOWAT_CHARS(baud) (baud / 10 / TX_LOWAT_HZ) |
| 508 | |
| 509 | /* Flags per port */ |
| 510 | #define INPUT_HIGH 0x01 |
| 511 | #define DCD_ON 0x02 |
| 512 | #define LOWAT_WRITTEN 0x04 |
| 513 | #define READ_ABORTED 0x08 |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 514 | #define PORT_ACTIVE 0x10 |
| 515 | #define PORT_INACTIVE 0 /* This is the value when "off" */ |
| 516 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | |
| 518 | /* Since each port has different register offsets and bitmasks |
| 519 | * for everything, we'll store those that we need in tables so we |
| 520 | * don't have to be constantly checking the port we are dealing with. |
| 521 | */ |
| 522 | struct hooks { |
| 523 | uint32_t intr_delta_dcd; |
| 524 | uint32_t intr_delta_cts; |
| 525 | uint32_t intr_tx_mt; |
| 526 | uint32_t intr_rx_timer; |
| 527 | uint32_t intr_rx_high; |
| 528 | uint32_t intr_tx_explicit; |
| 529 | uint32_t intr_dma_error; |
| 530 | uint32_t intr_clear; |
| 531 | uint32_t intr_all; |
Brent Casavant | 22329b5 | 2005-06-21 17:15:59 -0700 | [diff] [blame] | 532 | int rs422_select_pin; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | }; |
| 534 | |
| 535 | static struct hooks hooks_array[IOC4_NUM_SERIAL_PORTS] = { |
| 536 | /* Values for port 0 */ |
| 537 | { |
| 538 | IOC4_SIO_IR_S0_DELTA_DCD, IOC4_SIO_IR_S0_DELTA_CTS, |
| 539 | IOC4_SIO_IR_S0_TX_MT, IOC4_SIO_IR_S0_RX_TIMER, |
| 540 | IOC4_SIO_IR_S0_RX_HIGH, IOC4_SIO_IR_S0_TX_EXPLICIT, |
| 541 | IOC4_OTHER_IR_S0_MEMERR, |
| 542 | (IOC4_SIO_IR_S0_TX_MT | IOC4_SIO_IR_S0_RX_FULL | |
| 543 | IOC4_SIO_IR_S0_RX_HIGH | IOC4_SIO_IR_S0_RX_TIMER | |
| 544 | IOC4_SIO_IR_S0_DELTA_DCD | IOC4_SIO_IR_S0_DELTA_CTS | |
| 545 | IOC4_SIO_IR_S0_INT | IOC4_SIO_IR_S0_TX_EXPLICIT), |
| 546 | IOC4_SIO_IR_S0, IOC4_GPPR_UART0_MODESEL_PIN, |
| 547 | }, |
| 548 | |
| 549 | /* Values for port 1 */ |
| 550 | { |
| 551 | IOC4_SIO_IR_S1_DELTA_DCD, IOC4_SIO_IR_S1_DELTA_CTS, |
| 552 | IOC4_SIO_IR_S1_TX_MT, IOC4_SIO_IR_S1_RX_TIMER, |
| 553 | IOC4_SIO_IR_S1_RX_HIGH, IOC4_SIO_IR_S1_TX_EXPLICIT, |
| 554 | IOC4_OTHER_IR_S1_MEMERR, |
| 555 | (IOC4_SIO_IR_S1_TX_MT | IOC4_SIO_IR_S1_RX_FULL | |
| 556 | IOC4_SIO_IR_S1_RX_HIGH | IOC4_SIO_IR_S1_RX_TIMER | |
| 557 | IOC4_SIO_IR_S1_DELTA_DCD | IOC4_SIO_IR_S1_DELTA_CTS | |
| 558 | IOC4_SIO_IR_S1_INT | IOC4_SIO_IR_S1_TX_EXPLICIT), |
| 559 | IOC4_SIO_IR_S1, IOC4_GPPR_UART1_MODESEL_PIN, |
| 560 | }, |
| 561 | |
| 562 | /* Values for port 2 */ |
| 563 | { |
| 564 | IOC4_SIO_IR_S2_DELTA_DCD, IOC4_SIO_IR_S2_DELTA_CTS, |
| 565 | IOC4_SIO_IR_S2_TX_MT, IOC4_SIO_IR_S2_RX_TIMER, |
| 566 | IOC4_SIO_IR_S2_RX_HIGH, IOC4_SIO_IR_S2_TX_EXPLICIT, |
| 567 | IOC4_OTHER_IR_S2_MEMERR, |
| 568 | (IOC4_SIO_IR_S2_TX_MT | IOC4_SIO_IR_S2_RX_FULL | |
| 569 | IOC4_SIO_IR_S2_RX_HIGH | IOC4_SIO_IR_S2_RX_TIMER | |
| 570 | IOC4_SIO_IR_S2_DELTA_DCD | IOC4_SIO_IR_S2_DELTA_CTS | |
| 571 | IOC4_SIO_IR_S2_INT | IOC4_SIO_IR_S2_TX_EXPLICIT), |
| 572 | IOC4_SIO_IR_S2, IOC4_GPPR_UART2_MODESEL_PIN, |
| 573 | }, |
| 574 | |
| 575 | /* Values for port 3 */ |
| 576 | { |
| 577 | IOC4_SIO_IR_S3_DELTA_DCD, IOC4_SIO_IR_S3_DELTA_CTS, |
| 578 | IOC4_SIO_IR_S3_TX_MT, IOC4_SIO_IR_S3_RX_TIMER, |
| 579 | IOC4_SIO_IR_S3_RX_HIGH, IOC4_SIO_IR_S3_TX_EXPLICIT, |
| 580 | IOC4_OTHER_IR_S3_MEMERR, |
| 581 | (IOC4_SIO_IR_S3_TX_MT | IOC4_SIO_IR_S3_RX_FULL | |
| 582 | IOC4_SIO_IR_S3_RX_HIGH | IOC4_SIO_IR_S3_RX_TIMER | |
| 583 | IOC4_SIO_IR_S3_DELTA_DCD | IOC4_SIO_IR_S3_DELTA_CTS | |
| 584 | IOC4_SIO_IR_S3_INT | IOC4_SIO_IR_S3_TX_EXPLICIT), |
| 585 | IOC4_SIO_IR_S3, IOC4_GPPR_UART3_MODESEL_PIN, |
| 586 | } |
| 587 | }; |
| 588 | |
| 589 | /* A ring buffer entry */ |
| 590 | struct ring_entry { |
| 591 | union { |
| 592 | struct { |
| 593 | uint32_t alldata; |
| 594 | uint32_t allsc; |
| 595 | } all; |
| 596 | struct { |
| 597 | char data[4]; /* data bytes */ |
| 598 | char sc[4]; /* status/control */ |
| 599 | } s; |
| 600 | } u; |
| 601 | }; |
| 602 | |
| 603 | /* Test the valid bits in any of the 4 sc chars using "allsc" member */ |
| 604 | #define RING_ANY_VALID \ |
| 605 | ((uint32_t)(IOC4_RXSB_MODEM_VALID | IOC4_RXSB_DATA_VALID) * 0x01010101) |
| 606 | |
| 607 | #define ring_sc u.s.sc |
| 608 | #define ring_data u.s.data |
| 609 | #define ring_allsc u.all.allsc |
| 610 | |
| 611 | /* Number of entries per ring buffer. */ |
| 612 | #define ENTRIES_PER_RING (RING_BUF_SIZE / (int) sizeof(struct ring_entry)) |
| 613 | |
| 614 | /* An individual ring */ |
| 615 | struct ring { |
| 616 | struct ring_entry entries[ENTRIES_PER_RING]; |
| 617 | }; |
| 618 | |
| 619 | /* The whole enchilada */ |
| 620 | struct ring_buffer { |
| 621 | struct ring TX_0_OR_2; |
| 622 | struct ring RX_0_OR_2; |
| 623 | struct ring TX_1_OR_3; |
| 624 | struct ring RX_1_OR_3; |
| 625 | }; |
| 626 | |
| 627 | /* Get a ring from a port struct */ |
| 628 | #define RING(_p, _wh) &(((struct ring_buffer *)((_p)->ip_cpu_ringbuf))->_wh) |
| 629 | |
| 630 | /* Infinite loop detection. |
| 631 | */ |
| 632 | #define MAXITER 10000000 |
| 633 | |
| 634 | /* Prototypes */ |
| 635 | static void receive_chars(struct uart_port *); |
| 636 | static void handle_intr(void *arg, uint32_t sio_ir); |
| 637 | |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 638 | /* |
| 639 | * port_is_active - determines if this port is currently active |
| 640 | * @port: ptr to soft struct for this port |
| 641 | * @uart_port: uart port to test for |
| 642 | */ |
| 643 | static inline int port_is_active(struct ioc4_port *port, |
| 644 | struct uart_port *uart_port) |
| 645 | { |
| 646 | if (port) { |
| 647 | if ((port->ip_flags & PORT_ACTIVE) |
| 648 | && (port->ip_port == uart_port)) |
| 649 | return 1; |
| 650 | } |
| 651 | return 0; |
| 652 | } |
| 653 | |
| 654 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | /** |
| 656 | * write_ireg - write the interrupt regs |
| 657 | * @ioc4_soft: ptr to soft struct for this port |
| 658 | * @val: value to write |
| 659 | * @which: which register |
| 660 | * @type: which ireg set |
| 661 | */ |
| 662 | static inline void |
| 663 | write_ireg(struct ioc4_soft *ioc4_soft, uint32_t val, int which, int type) |
| 664 | { |
Brent Casavant | 22329b5 | 2005-06-21 17:15:59 -0700 | [diff] [blame] | 665 | struct ioc4_misc_regs __iomem *mem = ioc4_soft->is_ioc4_misc_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | unsigned long flags; |
| 667 | |
| 668 | spin_lock_irqsave(&ioc4_soft->is_ir_lock, flags); |
| 669 | |
| 670 | switch (type) { |
| 671 | case IOC4_SIO_INTR_TYPE: |
| 672 | switch (which) { |
| 673 | case IOC4_W_IES: |
Brent Casavant | 22329b5 | 2005-06-21 17:15:59 -0700 | [diff] [blame] | 674 | writel(val, &mem->sio_ies.raw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | break; |
| 676 | |
| 677 | case IOC4_W_IEC: |
Brent Casavant | 22329b5 | 2005-06-21 17:15:59 -0700 | [diff] [blame] | 678 | writel(val, &mem->sio_iec.raw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | break; |
| 680 | } |
| 681 | break; |
| 682 | |
| 683 | case IOC4_OTHER_INTR_TYPE: |
| 684 | switch (which) { |
| 685 | case IOC4_W_IES: |
Brent Casavant | 22329b5 | 2005-06-21 17:15:59 -0700 | [diff] [blame] | 686 | writel(val, &mem->other_ies.raw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | break; |
| 688 | |
| 689 | case IOC4_W_IEC: |
Brent Casavant | 22329b5 | 2005-06-21 17:15:59 -0700 | [diff] [blame] | 690 | writel(val, &mem->other_iec.raw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | break; |
| 692 | } |
| 693 | break; |
| 694 | |
| 695 | default: |
| 696 | break; |
| 697 | } |
| 698 | spin_unlock_irqrestore(&ioc4_soft->is_ir_lock, flags); |
| 699 | } |
| 700 | |
| 701 | /** |
| 702 | * set_baud - Baud rate setting code |
| 703 | * @port: port to set |
| 704 | * @baud: baud rate to use |
| 705 | */ |
| 706 | static int set_baud(struct ioc4_port *port, int baud) |
| 707 | { |
| 708 | int actual_baud; |
| 709 | int diff; |
| 710 | int lcr; |
| 711 | unsigned short divisor; |
| 712 | struct ioc4_uartregs __iomem *uart; |
| 713 | |
| 714 | divisor = SER_DIVISOR(baud, port->ip_pci_bus_speed); |
| 715 | if (!divisor) |
| 716 | return 1; |
| 717 | actual_baud = DIVISOR_TO_BAUD(divisor, port->ip_pci_bus_speed); |
| 718 | |
| 719 | diff = actual_baud - baud; |
| 720 | if (diff < 0) |
| 721 | diff = -diff; |
| 722 | |
| 723 | /* If we're within 1%, we've found a match */ |
| 724 | if (diff * 100 > actual_baud) |
| 725 | return 1; |
| 726 | |
| 727 | uart = port->ip_uart_regs; |
| 728 | lcr = readb(&uart->i4u_lcr); |
| 729 | writeb(lcr | UART_LCR_DLAB, &uart->i4u_lcr); |
| 730 | writeb((unsigned char)divisor, &uart->i4u_dll); |
| 731 | writeb((unsigned char)(divisor >> 8), &uart->i4u_dlm); |
| 732 | writeb(lcr, &uart->i4u_lcr); |
| 733 | return 0; |
| 734 | } |
| 735 | |
| 736 | |
| 737 | /** |
| 738 | * get_ioc4_port - given a uart port, return the control structure |
| 739 | * @port: uart port |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 740 | * @set: set this port as current |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 | */ |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 742 | static struct ioc4_port *get_ioc4_port(struct uart_port *the_port, int set) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | { |
Brent Casavant | 22329b5 | 2005-06-21 17:15:59 -0700 | [diff] [blame] | 744 | struct ioc4_driver_data *idd = dev_get_drvdata(the_port->dev); |
| 745 | struct ioc4_control *control = idd->idd_serial_data; |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 746 | struct ioc4_port *port; |
| 747 | int port_num, port_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 | |
| 749 | if (control) { |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 750 | for ( port_num = 0; port_num < IOC4_NUM_SERIAL_PORTS; |
| 751 | port_num++ ) { |
| 752 | port = control->ic_port[port_num].icp_port; |
| 753 | if (!port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | continue; |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 755 | for (port_type = UART_PORT_MIN; |
| 756 | port_type < UART_PORT_COUNT; |
| 757 | port_type++) { |
| 758 | if (the_port == port->ip_all_ports |
| 759 | [port_type]) { |
| 760 | /* set local copy */ |
| 761 | if (set) { |
| 762 | port->ip_port = the_port; |
| 763 | } |
| 764 | return port; |
| 765 | } |
| 766 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | } |
| 768 | } |
| 769 | return NULL; |
| 770 | } |
| 771 | |
| 772 | /* The IOC4 hardware provides no atomic way to determine if interrupts |
| 773 | * are pending since two reads are required to do so. The handler must |
| 774 | * read the SIO_IR and the SIO_IES, and take the logical and of the |
| 775 | * two. When this value is zero, all interrupts have been serviced and |
| 776 | * the handler may return. |
| 777 | * |
| 778 | * This has the unfortunate "hole" that, if some other CPU or |
| 779 | * some other thread or some higher level interrupt manages to |
| 780 | * modify SIO_IE between our reads of SIO_IR and SIO_IE, we may |
| 781 | * think we have observed SIO_IR&SIO_IE==0 when in fact this |
| 782 | * condition never really occurred. |
| 783 | * |
| 784 | * To solve this, we use a simple spinlock that must be held |
| 785 | * whenever modifying SIO_IE; holding this lock while observing |
| 786 | * both SIO_IR and SIO_IE guarantees that we do not falsely |
| 787 | * conclude that no enabled interrupts are pending. |
| 788 | */ |
| 789 | |
| 790 | static inline uint32_t |
| 791 | pending_intrs(struct ioc4_soft *soft, int type) |
| 792 | { |
Brent Casavant | 22329b5 | 2005-06-21 17:15:59 -0700 | [diff] [blame] | 793 | struct ioc4_misc_regs __iomem *mem = soft->is_ioc4_misc_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 794 | unsigned long flag; |
| 795 | uint32_t intrs = 0; |
| 796 | |
| 797 | BUG_ON(!((type == IOC4_SIO_INTR_TYPE) |
| 798 | || (type == IOC4_OTHER_INTR_TYPE))); |
| 799 | |
| 800 | spin_lock_irqsave(&soft->is_ir_lock, flag); |
| 801 | |
| 802 | switch (type) { |
| 803 | case IOC4_SIO_INTR_TYPE: |
Brent Casavant | 22329b5 | 2005-06-21 17:15:59 -0700 | [diff] [blame] | 804 | intrs = readl(&mem->sio_ir.raw) & readl(&mem->sio_ies.raw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 805 | break; |
| 806 | |
| 807 | case IOC4_OTHER_INTR_TYPE: |
Brent Casavant | 22329b5 | 2005-06-21 17:15:59 -0700 | [diff] [blame] | 808 | intrs = readl(&mem->other_ir.raw) & readl(&mem->other_ies.raw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | |
| 810 | /* Don't process any ATA interrupte */ |
| 811 | intrs &= ~(IOC4_OTHER_IR_ATA_INT | IOC4_OTHER_IR_ATA_MEMERR); |
| 812 | break; |
| 813 | |
| 814 | default: |
| 815 | break; |
| 816 | } |
| 817 | spin_unlock_irqrestore(&soft->is_ir_lock, flag); |
| 818 | return intrs; |
| 819 | } |
| 820 | |
| 821 | /** |
| 822 | * port_init - Initialize the sio and ioc4 hardware for a given port |
| 823 | * called per port from attach... |
| 824 | * @port: port to initialize |
| 825 | */ |
| 826 | static int inline port_init(struct ioc4_port *port) |
| 827 | { |
| 828 | uint32_t sio_cr; |
| 829 | struct hooks *hooks = port->ip_hooks; |
| 830 | struct ioc4_uartregs __iomem *uart; |
| 831 | |
| 832 | /* Idle the IOC4 serial interface */ |
| 833 | writel(IOC4_SSCR_RESET, &port->ip_serial_regs->sscr); |
| 834 | |
| 835 | /* Wait until any pending bus activity for this port has ceased */ |
| 836 | do |
Brent Casavant | 22329b5 | 2005-06-21 17:15:59 -0700 | [diff] [blame] | 837 | sio_cr = readl(&port->ip_mem->sio_cr.raw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 838 | while (!(sio_cr & IOC4_SIO_CR_SIO_DIAG_IDLE)); |
| 839 | |
| 840 | /* Finish reset sequence */ |
| 841 | writel(0, &port->ip_serial_regs->sscr); |
| 842 | |
| 843 | /* Once RESET is done, reload cached tx_prod and rx_cons values |
| 844 | * and set rings to empty by making prod == cons |
| 845 | */ |
| 846 | port->ip_tx_prod = readl(&port->ip_serial_regs->stcir) & PROD_CONS_MASK; |
| 847 | writel(port->ip_tx_prod, &port->ip_serial_regs->stpir); |
| 848 | port->ip_rx_cons = readl(&port->ip_serial_regs->srpir) & PROD_CONS_MASK; |
Patrick Gefre | 5b052d8 | 2005-05-01 08:59:22 -0700 | [diff] [blame] | 849 | writel(port->ip_rx_cons | IOC4_SRCIR_ARM, &port->ip_serial_regs->srcir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | |
| 851 | /* Disable interrupts for this 16550 */ |
| 852 | uart = port->ip_uart_regs; |
| 853 | writeb(0, &uart->i4u_lcr); |
| 854 | writeb(0, &uart->i4u_ier); |
| 855 | |
| 856 | /* Set the default baud */ |
| 857 | set_baud(port, port->ip_baud); |
| 858 | |
| 859 | /* Set line control to 8 bits no parity */ |
| 860 | writeb(UART_LCR_WLEN8 | 0, &uart->i4u_lcr); |
| 861 | /* UART_LCR_STOP == 1 stop */ |
| 862 | |
| 863 | /* Enable the FIFOs */ |
| 864 | writeb(UART_FCR_ENABLE_FIFO, &uart->i4u_fcr); |
| 865 | /* then reset 16550 FIFOs */ |
| 866 | writeb(UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT, |
| 867 | &uart->i4u_fcr); |
| 868 | |
| 869 | /* Clear modem control register */ |
| 870 | writeb(0, &uart->i4u_mcr); |
| 871 | |
| 872 | /* Clear deltas in modem status register */ |
| 873 | readb(&uart->i4u_msr); |
| 874 | |
| 875 | /* Only do this once per port pair */ |
| 876 | if (port->ip_hooks == &hooks_array[0] |
| 877 | || port->ip_hooks == &hooks_array[2]) { |
| 878 | unsigned long ring_pci_addr; |
| 879 | uint32_t __iomem *sbbr_l; |
| 880 | uint32_t __iomem *sbbr_h; |
| 881 | |
| 882 | if (port->ip_hooks == &hooks_array[0]) { |
| 883 | sbbr_l = &port->ip_serial->sbbr01_l; |
| 884 | sbbr_h = &port->ip_serial->sbbr01_h; |
| 885 | } else { |
| 886 | sbbr_l = &port->ip_serial->sbbr23_l; |
| 887 | sbbr_h = &port->ip_serial->sbbr23_h; |
| 888 | } |
| 889 | |
| 890 | ring_pci_addr = (unsigned long __iomem)port->ip_dma_ringbuf; |
| 891 | DPRINT_CONFIG(("%s: ring_pci_addr 0x%lx\n", |
| 892 | __FUNCTION__, ring_pci_addr)); |
| 893 | |
| 894 | writel((unsigned int)((uint64_t)ring_pci_addr >> 32), sbbr_h); |
| 895 | writel((unsigned int)ring_pci_addr | IOC4_BUF_SIZE_BIT, sbbr_l); |
| 896 | } |
| 897 | |
| 898 | /* Set the receive timeout value to 10 msec */ |
| 899 | writel(IOC4_SRTR_HZ / 100, &port->ip_serial_regs->srtr); |
| 900 | |
| 901 | /* Set rx threshold, enable DMA */ |
| 902 | /* Set high water mark at 3/4 of full ring */ |
| 903 | port->ip_sscr = (ENTRIES_PER_RING * 3 / 4); |
| 904 | writel(port->ip_sscr, &port->ip_serial_regs->sscr); |
| 905 | |
| 906 | /* Disable and clear all serial related interrupt bits */ |
| 907 | write_ireg(port->ip_ioc4_soft, hooks->intr_clear, |
| 908 | IOC4_W_IEC, IOC4_SIO_INTR_TYPE); |
| 909 | port->ip_ienb &= ~hooks->intr_clear; |
Brent Casavant | 22329b5 | 2005-06-21 17:15:59 -0700 | [diff] [blame] | 910 | writel(hooks->intr_clear, &port->ip_mem->sio_ir.raw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 911 | return 0; |
| 912 | } |
| 913 | |
| 914 | /** |
| 915 | * handle_dma_error_intr - service any pending DMA error interrupts for the |
| 916 | * given port - 2nd level called via sd_intr |
| 917 | * @arg: handler arg |
| 918 | * @other_ir: ioc4regs |
| 919 | */ |
| 920 | static void handle_dma_error_intr(void *arg, uint32_t other_ir) |
| 921 | { |
| 922 | struct ioc4_port *port = (struct ioc4_port *)arg; |
| 923 | struct hooks *hooks = port->ip_hooks; |
Andrew Morton | a5a89ba | 2006-10-29 22:46:33 -0800 | [diff] [blame] | 924 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | |
| 926 | spin_lock_irqsave(&port->ip_lock, flags); |
| 927 | |
| 928 | /* ACK the interrupt */ |
Brent Casavant | 22329b5 | 2005-06-21 17:15:59 -0700 | [diff] [blame] | 929 | writel(hooks->intr_dma_error, &port->ip_mem->other_ir.raw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 930 | |
Brent Casavant | 22329b5 | 2005-06-21 17:15:59 -0700 | [diff] [blame] | 931 | if (readl(&port->ip_mem->pci_err_addr_l.raw) & IOC4_PCI_ERR_ADDR_VLD) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 932 | printk(KERN_ERR |
| 933 | "PCI error address is 0x%lx, " |
| 934 | "master is serial port %c %s\n", |
| 935 | (((uint64_t)readl(&port->ip_mem->pci_err_addr_h) |
| 936 | << 32) |
Brent Casavant | 22329b5 | 2005-06-21 17:15:59 -0700 | [diff] [blame] | 937 | | readl(&port->ip_mem->pci_err_addr_l.raw)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 938 | & IOC4_PCI_ERR_ADDR_ADDR_MSK, '1' + |
Brent Casavant | 22329b5 | 2005-06-21 17:15:59 -0700 | [diff] [blame] | 939 | ((char)(readl(&port->ip_mem->pci_err_addr_l.raw) & |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | IOC4_PCI_ERR_ADDR_MST_NUM_MSK) >> 1), |
Brent Casavant | 22329b5 | 2005-06-21 17:15:59 -0700 | [diff] [blame] | 941 | (readl(&port->ip_mem->pci_err_addr_l.raw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 942 | & IOC4_PCI_ERR_ADDR_MST_TYP_MSK) |
| 943 | ? "RX" : "TX"); |
| 944 | |
Brent Casavant | 22329b5 | 2005-06-21 17:15:59 -0700 | [diff] [blame] | 945 | if (readl(&port->ip_mem->pci_err_addr_l.raw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 946 | & IOC4_PCI_ERR_ADDR_MUL_ERR) { |
| 947 | printk(KERN_ERR |
| 948 | "Multiple errors occurred\n"); |
| 949 | } |
| 950 | } |
| 951 | spin_unlock_irqrestore(&port->ip_lock, flags); |
| 952 | |
| 953 | /* Re-enable DMA error interrupts */ |
| 954 | write_ireg(port->ip_ioc4_soft, hooks->intr_dma_error, IOC4_W_IES, |
| 955 | IOC4_OTHER_INTR_TYPE); |
| 956 | } |
| 957 | |
| 958 | /** |
| 959 | * intr_connect - interrupt connect function |
| 960 | * @soft: soft struct for this card |
| 961 | * @type: interrupt type |
| 962 | * @intrbits: bit pattern to set |
| 963 | * @intr: handler function |
| 964 | * @info: handler arg |
| 965 | */ |
| 966 | static void |
| 967 | intr_connect(struct ioc4_soft *soft, int type, |
| 968 | uint32_t intrbits, ioc4_intr_func_f * intr, void *info) |
| 969 | { |
| 970 | int i; |
| 971 | struct ioc4_intr_info *intr_ptr; |
| 972 | |
| 973 | BUG_ON(!((type == IOC4_SIO_INTR_TYPE) |
| 974 | || (type == IOC4_OTHER_INTR_TYPE))); |
| 975 | |
| 976 | i = atomic_inc(&soft-> is_intr_type[type].is_num_intrs) - 1; |
| 977 | BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0))); |
| 978 | |
| 979 | /* Save off the lower level interrupt handler */ |
| 980 | intr_ptr = &soft->is_intr_type[type].is_intr_info[i]; |
| 981 | intr_ptr->sd_bits = intrbits; |
| 982 | intr_ptr->sd_intr = intr; |
| 983 | intr_ptr->sd_info = info; |
| 984 | } |
| 985 | |
| 986 | /** |
| 987 | * ioc4_intr - Top level IOC4 interrupt handler. |
| 988 | * @irq: irq value |
| 989 | * @arg: handler arg |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 990 | */ |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 991 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 992 | static irqreturn_t ioc4_intr(int irq, void *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 993 | { |
| 994 | struct ioc4_soft *soft; |
| 995 | uint32_t this_ir, this_mir; |
| 996 | int xx, num_intrs = 0; |
| 997 | int intr_type; |
| 998 | int handled = 0; |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 999 | struct ioc4_intr_info *intr_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1000 | |
| 1001 | soft = arg; |
| 1002 | for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) { |
| 1003 | num_intrs = (int)atomic_read( |
| 1004 | &soft->is_intr_type[intr_type].is_num_intrs); |
| 1005 | |
| 1006 | this_mir = this_ir = pending_intrs(soft, intr_type); |
| 1007 | |
| 1008 | /* Farm out the interrupt to the various drivers depending on |
| 1009 | * which interrupt bits are set. |
| 1010 | */ |
| 1011 | for (xx = 0; xx < num_intrs; xx++) { |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 1012 | intr_info = &soft->is_intr_type[intr_type].is_intr_info[xx]; |
| 1013 | if ((this_mir = this_ir & intr_info->sd_bits)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1014 | /* Disable owned interrupts, call handler */ |
| 1015 | handled++; |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 1016 | write_ireg(soft, intr_info->sd_bits, IOC4_W_IEC, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1017 | intr_type); |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 1018 | intr_info->sd_intr(intr_info->sd_info, this_mir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1019 | this_ir &= ~this_mir; |
| 1020 | } |
| 1021 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1022 | } |
| 1023 | #ifdef DEBUG_INTERRUPTS |
| 1024 | { |
Brent Casavant | 22329b5 | 2005-06-21 17:15:59 -0700 | [diff] [blame] | 1025 | struct ioc4_misc_regs __iomem *mem = soft->is_ioc4_misc_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1026 | unsigned long flag; |
| 1027 | |
| 1028 | spin_lock_irqsave(&soft->is_ir_lock, flag); |
Brent Casavant | 22329b5 | 2005-06-21 17:15:59 -0700 | [diff] [blame] | 1029 | printk ("%s : %d : mem 0x%p sio_ir 0x%x sio_ies 0x%x " |
| 1030 | "other_ir 0x%x other_ies 0x%x mask 0x%x\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1031 | __FUNCTION__, __LINE__, |
Brent Casavant | 22329b5 | 2005-06-21 17:15:59 -0700 | [diff] [blame] | 1032 | (void *)mem, readl(&mem->sio_ir.raw), |
| 1033 | readl(&mem->sio_ies.raw), |
| 1034 | readl(&mem->other_ir.raw), |
| 1035 | readl(&mem->other_ies.raw), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1036 | IOC4_OTHER_IR_ATA_INT | IOC4_OTHER_IR_ATA_MEMERR); |
| 1037 | spin_unlock_irqrestore(&soft->is_ir_lock, flag); |
| 1038 | } |
| 1039 | #endif |
| 1040 | return handled ? IRQ_HANDLED : IRQ_NONE; |
| 1041 | } |
| 1042 | |
| 1043 | /** |
| 1044 | * ioc4_attach_local - Device initialization. |
| 1045 | * Called at *_attach() time for each |
| 1046 | * IOC4 with serial ports in the system. |
Brent Casavant | d4c477c | 2005-06-21 17:16:01 -0700 | [diff] [blame] | 1047 | * @idd: Master module data for this IOC4 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1048 | */ |
Brent Casavant | d4c477c | 2005-06-21 17:16:01 -0700 | [diff] [blame] | 1049 | static int inline ioc4_attach_local(struct ioc4_driver_data *idd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1050 | { |
| 1051 | struct ioc4_port *port; |
| 1052 | struct ioc4_port *ports[IOC4_NUM_SERIAL_PORTS]; |
| 1053 | int port_number; |
| 1054 | uint16_t ioc4_revid_min = 62; |
| 1055 | uint16_t ioc4_revid; |
Brent Casavant | d4c477c | 2005-06-21 17:16:01 -0700 | [diff] [blame] | 1056 | struct pci_dev *pdev = idd->idd_pdev; |
| 1057 | struct ioc4_control* control = idd->idd_serial_data; |
| 1058 | struct ioc4_soft *soft = control->ic_soft; |
| 1059 | void __iomem *ioc4_misc = idd->idd_misc_regs; |
| 1060 | void __iomem *ioc4_serial = soft->is_ioc4_serial_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1061 | |
| 1062 | /* IOC4 firmware must be at least rev 62 */ |
| 1063 | pci_read_config_word(pdev, PCI_COMMAND_SPECIAL, &ioc4_revid); |
| 1064 | |
| 1065 | printk(KERN_INFO "IOC4 firmware revision %d\n", ioc4_revid); |
| 1066 | if (ioc4_revid < ioc4_revid_min) { |
| 1067 | printk(KERN_WARNING |
| 1068 | "IOC4 serial not supported on firmware rev %d, " |
| 1069 | "please upgrade to rev %d or higher\n", |
| 1070 | ioc4_revid, ioc4_revid_min); |
| 1071 | return -EPERM; |
| 1072 | } |
Brent Casavant | 22329b5 | 2005-06-21 17:15:59 -0700 | [diff] [blame] | 1073 | BUG_ON(ioc4_misc == NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1074 | BUG_ON(ioc4_serial == NULL); |
| 1075 | |
| 1076 | /* Create port structures for each port */ |
| 1077 | for (port_number = 0; port_number < IOC4_NUM_SERIAL_PORTS; |
| 1078 | port_number++) { |
Burman Yan | 8f31bb3 | 2007-02-14 00:33:07 -0800 | [diff] [blame^] | 1079 | port = kzalloc(sizeof(struct ioc4_port), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1080 | if (!port) { |
| 1081 | printk(KERN_WARNING |
| 1082 | "IOC4 serial memory not available for port\n"); |
| 1083 | return -ENOMEM; |
| 1084 | } |
Pat Gefre | 396dc44 | 2005-10-30 15:02:49 -0800 | [diff] [blame] | 1085 | spin_lock_init(&port->ip_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1086 | |
| 1087 | /* we need to remember the previous ones, to point back to |
| 1088 | * them farther down - setting up the ring buffers. |
| 1089 | */ |
| 1090 | ports[port_number] = port; |
| 1091 | |
| 1092 | /* Allocate buffers and jumpstart the hardware. */ |
| 1093 | control->ic_port[port_number].icp_port = port; |
| 1094 | port->ip_ioc4_soft = soft; |
| 1095 | port->ip_pdev = pdev; |
| 1096 | port->ip_ienb = 0; |
Brent Casavant | d4c477c | 2005-06-21 17:16:01 -0700 | [diff] [blame] | 1097 | /* Use baud rate calculations based on detected PCI |
| 1098 | * bus speed. Simply test whether the PCI clock is |
| 1099 | * running closer to 66MHz or 33MHz. |
| 1100 | */ |
| 1101 | if (idd->count_period/IOC4_EXTINT_COUNT_DIVISOR < 20) { |
| 1102 | port->ip_pci_bus_speed = IOC4_SER_XIN_CLK_66; |
| 1103 | } else { |
| 1104 | port->ip_pci_bus_speed = IOC4_SER_XIN_CLK_33; |
| 1105 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1106 | port->ip_baud = 9600; |
| 1107 | port->ip_control = control; |
Brent Casavant | 22329b5 | 2005-06-21 17:15:59 -0700 | [diff] [blame] | 1108 | port->ip_mem = ioc4_misc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1109 | port->ip_serial = ioc4_serial; |
| 1110 | |
| 1111 | /* point to the right hook */ |
| 1112 | port->ip_hooks = &hooks_array[port_number]; |
| 1113 | |
| 1114 | /* Get direct hooks to the serial regs and uart regs |
| 1115 | * for this port |
| 1116 | */ |
| 1117 | switch (port_number) { |
| 1118 | case 0: |
| 1119 | port->ip_serial_regs = &(port->ip_serial->port_0); |
| 1120 | port->ip_uart_regs = &(port->ip_serial->uart_0); |
| 1121 | break; |
| 1122 | case 1: |
| 1123 | port->ip_serial_regs = &(port->ip_serial->port_1); |
| 1124 | port->ip_uart_regs = &(port->ip_serial->uart_1); |
| 1125 | break; |
| 1126 | case 2: |
| 1127 | port->ip_serial_regs = &(port->ip_serial->port_2); |
| 1128 | port->ip_uart_regs = &(port->ip_serial->uart_2); |
| 1129 | break; |
| 1130 | default: |
| 1131 | case 3: |
| 1132 | port->ip_serial_regs = &(port->ip_serial->port_3); |
| 1133 | port->ip_uart_regs = &(port->ip_serial->uart_3); |
| 1134 | break; |
| 1135 | } |
| 1136 | |
| 1137 | /* ring buffers are 1 to a pair of ports */ |
| 1138 | if (port_number && (port_number & 1)) { |
| 1139 | /* odd use the evens buffer */ |
| 1140 | port->ip_dma_ringbuf = |
| 1141 | ports[port_number - 1]->ip_dma_ringbuf; |
| 1142 | port->ip_cpu_ringbuf = |
| 1143 | ports[port_number - 1]->ip_cpu_ringbuf; |
| 1144 | port->ip_inring = RING(port, RX_1_OR_3); |
| 1145 | port->ip_outring = RING(port, TX_1_OR_3); |
| 1146 | |
| 1147 | } else { |
| 1148 | if (port->ip_dma_ringbuf == 0) { |
| 1149 | port->ip_cpu_ringbuf = pci_alloc_consistent |
| 1150 | (pdev, TOTAL_RING_BUF_SIZE, |
| 1151 | &port->ip_dma_ringbuf); |
| 1152 | |
| 1153 | } |
| 1154 | BUG_ON(!((((int64_t)port->ip_dma_ringbuf) & |
| 1155 | (TOTAL_RING_BUF_SIZE - 1)) == 0)); |
| 1156 | DPRINT_CONFIG(("%s : ip_cpu_ringbuf 0x%p " |
| 1157 | "ip_dma_ringbuf 0x%p\n", |
| 1158 | __FUNCTION__, |
| 1159 | (void *)port->ip_cpu_ringbuf, |
| 1160 | (void *)port->ip_dma_ringbuf)); |
| 1161 | port->ip_inring = RING(port, RX_0_OR_2); |
| 1162 | port->ip_outring = RING(port, TX_0_OR_2); |
| 1163 | } |
| 1164 | DPRINT_CONFIG(("%s : port %d [addr 0x%p] control 0x%p", |
| 1165 | __FUNCTION__, |
| 1166 | port_number, (void *)port, (void *)control)); |
| 1167 | DPRINT_CONFIG((" ip_serial_regs 0x%p ip_uart_regs 0x%p\n", |
| 1168 | (void *)port->ip_serial_regs, |
| 1169 | (void *)port->ip_uart_regs)); |
| 1170 | |
| 1171 | /* Initialize the hardware for IOC4 */ |
| 1172 | port_init(port); |
| 1173 | |
| 1174 | DPRINT_CONFIG(("%s: port_number %d port 0x%p inring 0x%p " |
| 1175 | "outring 0x%p\n", |
| 1176 | __FUNCTION__, |
| 1177 | port_number, (void *)port, |
| 1178 | (void *)port->ip_inring, |
| 1179 | (void *)port->ip_outring)); |
| 1180 | |
| 1181 | /* Attach interrupt handlers */ |
| 1182 | intr_connect(soft, IOC4_SIO_INTR_TYPE, |
| 1183 | GET_SIO_IR(port_number), |
| 1184 | handle_intr, port); |
| 1185 | |
| 1186 | intr_connect(soft, IOC4_OTHER_INTR_TYPE, |
| 1187 | GET_OTHER_IR(port_number), |
| 1188 | handle_dma_error_intr, port); |
| 1189 | } |
| 1190 | return 0; |
| 1191 | } |
| 1192 | |
| 1193 | /** |
| 1194 | * enable_intrs - enable interrupts |
| 1195 | * @port: port to enable |
| 1196 | * @mask: mask to use |
| 1197 | */ |
| 1198 | static void enable_intrs(struct ioc4_port *port, uint32_t mask) |
| 1199 | { |
| 1200 | struct hooks *hooks = port->ip_hooks; |
| 1201 | |
| 1202 | if ((port->ip_ienb & mask) != mask) { |
| 1203 | write_ireg(port->ip_ioc4_soft, mask, IOC4_W_IES, |
| 1204 | IOC4_SIO_INTR_TYPE); |
| 1205 | port->ip_ienb |= mask; |
| 1206 | } |
| 1207 | |
| 1208 | if (port->ip_ienb) |
| 1209 | write_ireg(port->ip_ioc4_soft, hooks->intr_dma_error, |
| 1210 | IOC4_W_IES, IOC4_OTHER_INTR_TYPE); |
| 1211 | } |
| 1212 | |
| 1213 | /** |
| 1214 | * local_open - local open a port |
| 1215 | * @port: port to open |
| 1216 | */ |
| 1217 | static inline int local_open(struct ioc4_port *port) |
| 1218 | { |
| 1219 | int spiniter = 0; |
| 1220 | |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 1221 | port->ip_flags = PORT_ACTIVE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1222 | |
| 1223 | /* Pause the DMA interface if necessary */ |
| 1224 | if (port->ip_sscr & IOC4_SSCR_DMA_EN) { |
| 1225 | writel(port->ip_sscr | IOC4_SSCR_DMA_PAUSE, |
| 1226 | &port->ip_serial_regs->sscr); |
| 1227 | while((readl(&port->ip_serial_regs-> sscr) |
| 1228 | & IOC4_SSCR_PAUSE_STATE) == 0) { |
| 1229 | spiniter++; |
| 1230 | if (spiniter > MAXITER) { |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 1231 | port->ip_flags = PORT_INACTIVE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1232 | return -1; |
| 1233 | } |
| 1234 | } |
| 1235 | } |
| 1236 | |
| 1237 | /* Reset the input fifo. If the uart received chars while the port |
| 1238 | * was closed and DMA is not enabled, the uart may have a bunch of |
| 1239 | * chars hanging around in its rx fifo which will not be discarded |
| 1240 | * by rclr in the upper layer. We must get rid of them here. |
| 1241 | */ |
| 1242 | writeb(UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR, |
| 1243 | &port->ip_uart_regs->i4u_fcr); |
| 1244 | |
| 1245 | writeb(UART_LCR_WLEN8, &port->ip_uart_regs->i4u_lcr); |
| 1246 | /* UART_LCR_STOP == 1 stop */ |
| 1247 | |
| 1248 | /* Re-enable DMA, set default threshold to intr whenever there is |
| 1249 | * data available. |
| 1250 | */ |
| 1251 | port->ip_sscr &= ~IOC4_SSCR_RX_THRESHOLD; |
| 1252 | port->ip_sscr |= 1; /* default threshold */ |
| 1253 | |
| 1254 | /* Plug in the new sscr. This implicitly clears the DMA_PAUSE |
| 1255 | * flag if it was set above |
| 1256 | */ |
| 1257 | writel(port->ip_sscr, &port->ip_serial_regs->sscr); |
| 1258 | port->ip_tx_lowat = 1; |
| 1259 | return 0; |
| 1260 | } |
| 1261 | |
| 1262 | /** |
| 1263 | * set_rx_timeout - Set rx timeout and threshold values. |
| 1264 | * @port: port to use |
| 1265 | * @timeout: timeout value in ticks |
| 1266 | */ |
| 1267 | static inline int set_rx_timeout(struct ioc4_port *port, int timeout) |
| 1268 | { |
| 1269 | int threshold; |
| 1270 | |
| 1271 | port->ip_rx_timeout = timeout; |
| 1272 | |
| 1273 | /* Timeout is in ticks. Let's figure out how many chars we |
| 1274 | * can receive at the current baud rate in that interval |
| 1275 | * and set the rx threshold to that amount. There are 4 chars |
| 1276 | * per ring entry, so we'll divide the number of chars that will |
| 1277 | * arrive in timeout by 4. |
Patrick Gefre | 6cb2875 | 2005-05-01 08:59:21 -0700 | [diff] [blame] | 1278 | * So .... timeout * baud / 10 / HZ / 4, with HZ = 100. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1279 | */ |
Patrick Gefre | 6cb2875 | 2005-05-01 08:59:21 -0700 | [diff] [blame] | 1280 | threshold = timeout * port->ip_baud / 4000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1281 | if (threshold == 0) |
| 1282 | threshold = 1; /* otherwise we'll intr all the time! */ |
| 1283 | |
| 1284 | if ((unsigned)threshold > (unsigned)IOC4_SSCR_RX_THRESHOLD) |
| 1285 | return 1; |
| 1286 | |
| 1287 | port->ip_sscr &= ~IOC4_SSCR_RX_THRESHOLD; |
| 1288 | port->ip_sscr |= threshold; |
| 1289 | |
| 1290 | writel(port->ip_sscr, &port->ip_serial_regs->sscr); |
| 1291 | |
Patrick Gefre | 6cb2875 | 2005-05-01 08:59:21 -0700 | [diff] [blame] | 1292 | /* Now set the rx timeout to the given value |
| 1293 | * again timeout * IOC4_SRTR_HZ / HZ |
| 1294 | */ |
| 1295 | timeout = timeout * IOC4_SRTR_HZ / 100; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1296 | if (timeout > IOC4_SRTR_CNT) |
| 1297 | timeout = IOC4_SRTR_CNT; |
| 1298 | |
| 1299 | writel(timeout, &port->ip_serial_regs->srtr); |
| 1300 | return 0; |
| 1301 | } |
| 1302 | |
| 1303 | /** |
| 1304 | * config_port - config the hardware |
| 1305 | * @port: port to config |
| 1306 | * @baud: baud rate for the port |
| 1307 | * @byte_size: data size |
| 1308 | * @stop_bits: number of stop bits |
| 1309 | * @parenb: parity enable ? |
| 1310 | * @parodd: odd parity ? |
| 1311 | */ |
| 1312 | static inline int |
| 1313 | config_port(struct ioc4_port *port, |
| 1314 | int baud, int byte_size, int stop_bits, int parenb, int parodd) |
| 1315 | { |
| 1316 | char lcr, sizebits; |
| 1317 | int spiniter = 0; |
| 1318 | |
| 1319 | DPRINT_CONFIG(("%s: baud %d byte_size %d stop %d parenb %d parodd %d\n", |
| 1320 | __FUNCTION__, baud, byte_size, stop_bits, parenb, parodd)); |
| 1321 | |
| 1322 | if (set_baud(port, baud)) |
| 1323 | return 1; |
| 1324 | |
| 1325 | switch (byte_size) { |
| 1326 | case 5: |
| 1327 | sizebits = UART_LCR_WLEN5; |
| 1328 | break; |
| 1329 | case 6: |
| 1330 | sizebits = UART_LCR_WLEN6; |
| 1331 | break; |
| 1332 | case 7: |
| 1333 | sizebits = UART_LCR_WLEN7; |
| 1334 | break; |
| 1335 | case 8: |
| 1336 | sizebits = UART_LCR_WLEN8; |
| 1337 | break; |
| 1338 | default: |
| 1339 | return 1; |
| 1340 | } |
| 1341 | |
| 1342 | /* Pause the DMA interface if necessary */ |
| 1343 | if (port->ip_sscr & IOC4_SSCR_DMA_EN) { |
| 1344 | writel(port->ip_sscr | IOC4_SSCR_DMA_PAUSE, |
| 1345 | &port->ip_serial_regs->sscr); |
| 1346 | while((readl(&port->ip_serial_regs->sscr) |
| 1347 | & IOC4_SSCR_PAUSE_STATE) == 0) { |
| 1348 | spiniter++; |
| 1349 | if (spiniter > MAXITER) |
| 1350 | return -1; |
| 1351 | } |
| 1352 | } |
| 1353 | |
| 1354 | /* Clear relevant fields in lcr */ |
| 1355 | lcr = readb(&port->ip_uart_regs->i4u_lcr); |
| 1356 | lcr &= ~(LCR_MASK_BITS_CHAR | UART_LCR_EPAR | |
| 1357 | UART_LCR_PARITY | LCR_MASK_STOP_BITS); |
| 1358 | |
| 1359 | /* Set byte size in lcr */ |
| 1360 | lcr |= sizebits; |
| 1361 | |
| 1362 | /* Set parity */ |
| 1363 | if (parenb) { |
| 1364 | lcr |= UART_LCR_PARITY; |
| 1365 | if (!parodd) |
| 1366 | lcr |= UART_LCR_EPAR; |
| 1367 | } |
| 1368 | |
| 1369 | /* Set stop bits */ |
| 1370 | if (stop_bits) |
| 1371 | lcr |= UART_LCR_STOP /* 2 stop bits */ ; |
| 1372 | |
| 1373 | writeb(lcr, &port->ip_uart_regs->i4u_lcr); |
| 1374 | |
| 1375 | /* Re-enable the DMA interface if necessary */ |
| 1376 | if (port->ip_sscr & IOC4_SSCR_DMA_EN) { |
| 1377 | writel(port->ip_sscr, &port->ip_serial_regs->sscr); |
| 1378 | } |
| 1379 | port->ip_baud = baud; |
| 1380 | |
| 1381 | /* When we get within this number of ring entries of filling the |
| 1382 | * entire ring on tx, place an EXPLICIT intr to generate a lowat |
| 1383 | * notification when output has drained. |
| 1384 | */ |
| 1385 | port->ip_tx_lowat = (TX_LOWAT_CHARS(baud) + 3) / 4; |
| 1386 | if (port->ip_tx_lowat == 0) |
| 1387 | port->ip_tx_lowat = 1; |
| 1388 | |
Patrick Gefre | 6cb2875 | 2005-05-01 08:59:21 -0700 | [diff] [blame] | 1389 | set_rx_timeout(port, 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1390 | |
| 1391 | return 0; |
| 1392 | } |
| 1393 | |
| 1394 | /** |
| 1395 | * do_write - Write bytes to the port. Returns the number of bytes |
| 1396 | * actually written. Called from transmit_chars |
| 1397 | * @port: port to use |
| 1398 | * @buf: the stuff to write |
| 1399 | * @len: how many bytes in 'buf' |
| 1400 | */ |
| 1401 | static inline int do_write(struct ioc4_port *port, char *buf, int len) |
| 1402 | { |
| 1403 | int prod_ptr, cons_ptr, total = 0; |
| 1404 | struct ring *outring; |
| 1405 | struct ring_entry *entry; |
| 1406 | struct hooks *hooks = port->ip_hooks; |
| 1407 | |
| 1408 | BUG_ON(!(len >= 0)); |
| 1409 | |
| 1410 | prod_ptr = port->ip_tx_prod; |
| 1411 | cons_ptr = readl(&port->ip_serial_regs->stcir) & PROD_CONS_MASK; |
| 1412 | outring = port->ip_outring; |
| 1413 | |
| 1414 | /* Maintain a 1-entry red-zone. The ring buffer is full when |
| 1415 | * (cons - prod) % ring_size is 1. Rather than do this subtraction |
| 1416 | * in the body of the loop, I'll do it now. |
| 1417 | */ |
| 1418 | cons_ptr = (cons_ptr - (int)sizeof(struct ring_entry)) & PROD_CONS_MASK; |
| 1419 | |
| 1420 | /* Stuff the bytes into the output */ |
| 1421 | while ((prod_ptr != cons_ptr) && (len > 0)) { |
| 1422 | int xx; |
| 1423 | |
| 1424 | /* Get 4 bytes (one ring entry) at a time */ |
| 1425 | entry = (struct ring_entry *)((caddr_t) outring + prod_ptr); |
| 1426 | |
| 1427 | /* Invalidate all entries */ |
| 1428 | entry->ring_allsc = 0; |
| 1429 | |
| 1430 | /* Copy in some bytes */ |
| 1431 | for (xx = 0; (xx < 4) && (len > 0); xx++) { |
| 1432 | entry->ring_data[xx] = *buf++; |
| 1433 | entry->ring_sc[xx] = IOC4_TXCB_VALID; |
| 1434 | len--; |
| 1435 | total++; |
| 1436 | } |
| 1437 | |
| 1438 | /* If we are within some small threshold of filling up the |
| 1439 | * entire ring buffer, we must place an EXPLICIT intr here |
| 1440 | * to generate a lowat interrupt in case we subsequently |
| 1441 | * really do fill up the ring and the caller goes to sleep. |
| 1442 | * No need to place more than one though. |
| 1443 | */ |
| 1444 | if (!(port->ip_flags & LOWAT_WRITTEN) && |
| 1445 | ((cons_ptr - prod_ptr) & PROD_CONS_MASK) |
| 1446 | <= port->ip_tx_lowat |
| 1447 | * (int)sizeof(struct ring_entry)) { |
| 1448 | port->ip_flags |= LOWAT_WRITTEN; |
| 1449 | entry->ring_sc[0] |= IOC4_TXCB_INT_WHEN_DONE; |
| 1450 | } |
| 1451 | |
| 1452 | /* Go on to next entry */ |
| 1453 | prod_ptr += sizeof(struct ring_entry); |
| 1454 | prod_ptr &= PROD_CONS_MASK; |
| 1455 | } |
| 1456 | |
| 1457 | /* If we sent something, start DMA if necessary */ |
| 1458 | if (total > 0 && !(port->ip_sscr & IOC4_SSCR_DMA_EN)) { |
| 1459 | port->ip_sscr |= IOC4_SSCR_DMA_EN; |
| 1460 | writel(port->ip_sscr, &port->ip_serial_regs->sscr); |
| 1461 | } |
| 1462 | |
| 1463 | /* Store the new producer pointer. If tx is disabled, we stuff the |
| 1464 | * data into the ring buffer, but we don't actually start tx. |
| 1465 | */ |
| 1466 | if (!uart_tx_stopped(port->ip_port)) { |
| 1467 | writel(prod_ptr, &port->ip_serial_regs->stpir); |
| 1468 | |
| 1469 | /* If we are now transmitting, enable tx_mt interrupt so we |
| 1470 | * can disable DMA if necessary when the tx finishes. |
| 1471 | */ |
| 1472 | if (total > 0) |
| 1473 | enable_intrs(port, hooks->intr_tx_mt); |
| 1474 | } |
| 1475 | port->ip_tx_prod = prod_ptr; |
| 1476 | return total; |
| 1477 | } |
| 1478 | |
| 1479 | /** |
| 1480 | * disable_intrs - disable interrupts |
| 1481 | * @port: port to enable |
| 1482 | * @mask: mask to use |
| 1483 | */ |
| 1484 | static void disable_intrs(struct ioc4_port *port, uint32_t mask) |
| 1485 | { |
| 1486 | struct hooks *hooks = port->ip_hooks; |
| 1487 | |
| 1488 | if (port->ip_ienb & mask) { |
| 1489 | write_ireg(port->ip_ioc4_soft, mask, IOC4_W_IEC, |
| 1490 | IOC4_SIO_INTR_TYPE); |
| 1491 | port->ip_ienb &= ~mask; |
| 1492 | } |
| 1493 | |
| 1494 | if (!port->ip_ienb) |
| 1495 | write_ireg(port->ip_ioc4_soft, hooks->intr_dma_error, |
| 1496 | IOC4_W_IEC, IOC4_OTHER_INTR_TYPE); |
| 1497 | } |
| 1498 | |
| 1499 | /** |
| 1500 | * set_notification - Modify event notification |
| 1501 | * @port: port to use |
| 1502 | * @mask: events mask |
| 1503 | * @set_on: set ? |
| 1504 | */ |
| 1505 | static int set_notification(struct ioc4_port *port, int mask, int set_on) |
| 1506 | { |
| 1507 | struct hooks *hooks = port->ip_hooks; |
| 1508 | uint32_t intrbits, sscrbits; |
| 1509 | |
| 1510 | BUG_ON(!mask); |
| 1511 | |
| 1512 | intrbits = sscrbits = 0; |
| 1513 | |
| 1514 | if (mask & N_DATA_READY) |
| 1515 | intrbits |= (hooks->intr_rx_timer | hooks->intr_rx_high); |
| 1516 | if (mask & N_OUTPUT_LOWAT) |
| 1517 | intrbits |= hooks->intr_tx_explicit; |
| 1518 | if (mask & N_DDCD) { |
| 1519 | intrbits |= hooks->intr_delta_dcd; |
| 1520 | sscrbits |= IOC4_SSCR_RX_RING_DCD; |
| 1521 | } |
| 1522 | if (mask & N_DCTS) |
| 1523 | intrbits |= hooks->intr_delta_cts; |
| 1524 | |
| 1525 | if (set_on) { |
| 1526 | enable_intrs(port, intrbits); |
| 1527 | port->ip_notify |= mask; |
| 1528 | port->ip_sscr |= sscrbits; |
| 1529 | } else { |
| 1530 | disable_intrs(port, intrbits); |
| 1531 | port->ip_notify &= ~mask; |
| 1532 | port->ip_sscr &= ~sscrbits; |
| 1533 | } |
| 1534 | |
| 1535 | /* We require DMA if either DATA_READY or DDCD notification is |
| 1536 | * currently requested. If neither of these is requested and |
| 1537 | * there is currently no tx in progress, DMA may be disabled. |
| 1538 | */ |
| 1539 | if (port->ip_notify & (N_DATA_READY | N_DDCD)) |
| 1540 | port->ip_sscr |= IOC4_SSCR_DMA_EN; |
| 1541 | else if (!(port->ip_ienb & hooks->intr_tx_mt)) |
| 1542 | port->ip_sscr &= ~IOC4_SSCR_DMA_EN; |
| 1543 | |
| 1544 | writel(port->ip_sscr, &port->ip_serial_regs->sscr); |
| 1545 | return 0; |
| 1546 | } |
| 1547 | |
| 1548 | /** |
| 1549 | * set_mcr - set the master control reg |
| 1550 | * @the_port: port to use |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1551 | * @mask1: mcr mask |
| 1552 | * @mask2: shadow mask |
| 1553 | */ |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 1554 | static inline int set_mcr(struct uart_port *the_port, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1555 | int mask1, int mask2) |
| 1556 | { |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 1557 | struct ioc4_port *port = get_ioc4_port(the_port, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1558 | uint32_t shadow; |
| 1559 | int spiniter = 0; |
| 1560 | char mcr; |
| 1561 | |
| 1562 | if (!port) |
| 1563 | return -1; |
| 1564 | |
| 1565 | /* Pause the DMA interface if necessary */ |
| 1566 | if (port->ip_sscr & IOC4_SSCR_DMA_EN) { |
| 1567 | writel(port->ip_sscr | IOC4_SSCR_DMA_PAUSE, |
| 1568 | &port->ip_serial_regs->sscr); |
| 1569 | while ((readl(&port->ip_serial_regs->sscr) |
| 1570 | & IOC4_SSCR_PAUSE_STATE) == 0) { |
| 1571 | spiniter++; |
| 1572 | if (spiniter > MAXITER) |
| 1573 | return -1; |
| 1574 | } |
| 1575 | } |
| 1576 | shadow = readl(&port->ip_serial_regs->shadow); |
| 1577 | mcr = (shadow & 0xff000000) >> 24; |
| 1578 | |
| 1579 | /* Set new value */ |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 1580 | mcr |= mask1; |
| 1581 | shadow |= mask2; |
| 1582 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1583 | writeb(mcr, &port->ip_uart_regs->i4u_mcr); |
| 1584 | writel(shadow, &port->ip_serial_regs->shadow); |
| 1585 | |
| 1586 | /* Re-enable the DMA interface if necessary */ |
| 1587 | if (port->ip_sscr & IOC4_SSCR_DMA_EN) { |
| 1588 | writel(port->ip_sscr, &port->ip_serial_regs->sscr); |
| 1589 | } |
| 1590 | return 0; |
| 1591 | } |
| 1592 | |
| 1593 | /** |
| 1594 | * ioc4_set_proto - set the protocol for the port |
| 1595 | * @port: port to use |
| 1596 | * @proto: protocol to use |
| 1597 | */ |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 1598 | static int ioc4_set_proto(struct ioc4_port *port, int proto) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1599 | { |
| 1600 | struct hooks *hooks = port->ip_hooks; |
| 1601 | |
| 1602 | switch (proto) { |
| 1603 | case PROTO_RS232: |
| 1604 | /* Clear the appropriate GIO pin */ |
Brent Casavant | 22329b5 | 2005-06-21 17:15:59 -0700 | [diff] [blame] | 1605 | writel(0, (&port->ip_mem->gppr[hooks->rs422_select_pin].raw)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1606 | break; |
| 1607 | |
| 1608 | case PROTO_RS422: |
| 1609 | /* Set the appropriate GIO pin */ |
Brent Casavant | 22329b5 | 2005-06-21 17:15:59 -0700 | [diff] [blame] | 1610 | writel(1, (&port->ip_mem->gppr[hooks->rs422_select_pin].raw)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1611 | break; |
| 1612 | |
| 1613 | default: |
| 1614 | return 1; |
| 1615 | } |
| 1616 | return 0; |
| 1617 | } |
| 1618 | |
| 1619 | /** |
| 1620 | * transmit_chars - upper level write, called with ip_lock |
| 1621 | * @the_port: port to write |
| 1622 | */ |
| 1623 | static void transmit_chars(struct uart_port *the_port) |
| 1624 | { |
| 1625 | int xmit_count, tail, head; |
| 1626 | int result; |
| 1627 | char *start; |
| 1628 | struct tty_struct *tty; |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 1629 | struct ioc4_port *port = get_ioc4_port(the_port, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1630 | struct uart_info *info; |
| 1631 | |
| 1632 | if (!the_port) |
| 1633 | return; |
| 1634 | if (!port) |
| 1635 | return; |
| 1636 | |
| 1637 | info = the_port->info; |
| 1638 | tty = info->tty; |
| 1639 | |
| 1640 | if (uart_circ_empty(&info->xmit) || uart_tx_stopped(the_port)) { |
| 1641 | /* Nothing to do or hw stopped */ |
| 1642 | set_notification(port, N_ALL_OUTPUT, 0); |
| 1643 | return; |
| 1644 | } |
| 1645 | |
| 1646 | head = info->xmit.head; |
| 1647 | tail = info->xmit.tail; |
| 1648 | start = (char *)&info->xmit.buf[tail]; |
| 1649 | |
| 1650 | /* write out all the data or until the end of the buffer */ |
| 1651 | xmit_count = (head < tail) ? (UART_XMIT_SIZE - tail) : (head - tail); |
| 1652 | if (xmit_count > 0) { |
| 1653 | result = do_write(port, start, xmit_count); |
| 1654 | if (result > 0) { |
| 1655 | /* booking */ |
| 1656 | xmit_count -= result; |
| 1657 | the_port->icount.tx += result; |
| 1658 | /* advance the pointers */ |
| 1659 | tail += result; |
| 1660 | tail &= UART_XMIT_SIZE - 1; |
| 1661 | info->xmit.tail = tail; |
| 1662 | start = (char *)&info->xmit.buf[tail]; |
| 1663 | } |
| 1664 | } |
| 1665 | if (uart_circ_chars_pending(&info->xmit) < WAKEUP_CHARS) |
| 1666 | uart_write_wakeup(the_port); |
| 1667 | |
| 1668 | if (uart_circ_empty(&info->xmit)) { |
| 1669 | set_notification(port, N_OUTPUT_LOWAT, 0); |
| 1670 | } else { |
| 1671 | set_notification(port, N_OUTPUT_LOWAT, 1); |
| 1672 | } |
| 1673 | } |
| 1674 | |
| 1675 | /** |
| 1676 | * ioc4_change_speed - change the speed of the port |
| 1677 | * @the_port: port to change |
| 1678 | * @new_termios: new termios settings |
| 1679 | * @old_termios: old termios settings |
| 1680 | */ |
| 1681 | static void |
| 1682 | ioc4_change_speed(struct uart_port *the_port, |
Alan Cox | 606d099 | 2006-12-08 02:38:45 -0800 | [diff] [blame] | 1683 | struct ktermios *new_termios, struct ktermios *old_termios) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1684 | { |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 1685 | struct ioc4_port *port = get_ioc4_port(the_port, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1686 | int baud, bits; |
Patrick Gefre | 68985e4 | 2005-05-01 08:59:21 -0700 | [diff] [blame] | 1687 | unsigned cflag; |
| 1688 | int new_parity = 0, new_parity_enable = 0, new_stop = 0, new_data = 8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1689 | struct uart_info *info = the_port->info; |
| 1690 | |
| 1691 | cflag = new_termios->c_cflag; |
| 1692 | |
| 1693 | switch (cflag & CSIZE) { |
| 1694 | case CS5: |
| 1695 | new_data = 5; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1696 | bits = 7; |
| 1697 | break; |
| 1698 | case CS6: |
| 1699 | new_data = 6; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1700 | bits = 8; |
| 1701 | break; |
| 1702 | case CS7: |
| 1703 | new_data = 7; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1704 | bits = 9; |
| 1705 | break; |
| 1706 | case CS8: |
| 1707 | new_data = 8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1708 | bits = 10; |
| 1709 | break; |
| 1710 | default: |
| 1711 | /* cuz we always need a default ... */ |
| 1712 | new_data = 5; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1713 | bits = 7; |
| 1714 | break; |
| 1715 | } |
| 1716 | if (cflag & CSTOPB) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1717 | bits++; |
| 1718 | new_stop = 1; |
| 1719 | } |
| 1720 | if (cflag & PARENB) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1721 | bits++; |
| 1722 | new_parity_enable = 1; |
Patrick Gefre | 68985e4 | 2005-05-01 08:59:21 -0700 | [diff] [blame] | 1723 | if (cflag & PARODD) |
| 1724 | new_parity = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1725 | } |
| 1726 | baud = uart_get_baud_rate(the_port, new_termios, old_termios, |
| 1727 | MIN_BAUD_SUPPORTED, MAX_BAUD_SUPPORTED); |
| 1728 | DPRINT_CONFIG(("%s: returned baud %d\n", __FUNCTION__, baud)); |
| 1729 | |
| 1730 | /* default is 9600 */ |
| 1731 | if (!baud) |
| 1732 | baud = 9600; |
| 1733 | |
| 1734 | if (!the_port->fifosize) |
Pat Gefre | 396dc44 | 2005-10-30 15:02:49 -0800 | [diff] [blame] | 1735 | the_port->fifosize = IOC4_FIFO_CHARS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1736 | the_port->timeout = ((the_port->fifosize * HZ * bits) / (baud / 10)); |
| 1737 | the_port->timeout += HZ / 50; /* Add .02 seconds of slop */ |
| 1738 | |
| 1739 | the_port->ignore_status_mask = N_ALL_INPUT; |
| 1740 | |
Pat Gefre | 396dc44 | 2005-10-30 15:02:49 -0800 | [diff] [blame] | 1741 | info->tty->low_latency = 1; |
| 1742 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1743 | if (I_IGNPAR(info->tty)) |
| 1744 | the_port->ignore_status_mask &= ~(N_PARITY_ERROR |
| 1745 | | N_FRAMING_ERROR); |
| 1746 | if (I_IGNBRK(info->tty)) { |
| 1747 | the_port->ignore_status_mask &= ~N_BREAK; |
| 1748 | if (I_IGNPAR(info->tty)) |
| 1749 | the_port->ignore_status_mask &= ~N_OVERRUN_ERROR; |
| 1750 | } |
| 1751 | if (!(cflag & CREAD)) { |
| 1752 | /* ignore everything */ |
| 1753 | the_port->ignore_status_mask &= ~N_DATA_READY; |
| 1754 | } |
| 1755 | |
Patrick Gefre | 149733d | 2005-05-01 08:59:21 -0700 | [diff] [blame] | 1756 | if (cflag & CRTSCTS) { |
Patrick Gefre | 149733d | 2005-05-01 08:59:21 -0700 | [diff] [blame] | 1757 | port->ip_sscr |= IOC4_SSCR_HFC_EN; |
Patrick Gefre | 149733d | 2005-05-01 08:59:21 -0700 | [diff] [blame] | 1758 | } |
Patrick Gefre | 68985e4 | 2005-05-01 08:59:21 -0700 | [diff] [blame] | 1759 | else { |
Patrick Gefre | 68985e4 | 2005-05-01 08:59:21 -0700 | [diff] [blame] | 1760 | port->ip_sscr &= ~IOC4_SSCR_HFC_EN; |
| 1761 | } |
| 1762 | writel(port->ip_sscr, &port->ip_serial_regs->sscr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1763 | |
| 1764 | /* Set the configuration and proper notification call */ |
| 1765 | DPRINT_CONFIG(("%s : port 0x%p cflag 0%o " |
| 1766 | "config_port(baud %d data %d stop %d p enable %d parity %d)," |
| 1767 | " notification 0x%x\n", |
| 1768 | __FUNCTION__, (void *)port, cflag, baud, new_data, new_stop, |
| 1769 | new_parity_enable, new_parity, the_port->ignore_status_mask)); |
| 1770 | |
| 1771 | if ((config_port(port, baud, /* baud */ |
| 1772 | new_data, /* byte size */ |
| 1773 | new_stop, /* stop bits */ |
| 1774 | new_parity_enable, /* set parity */ |
| 1775 | new_parity)) >= 0) { /* parity 1==odd */ |
| 1776 | set_notification(port, the_port->ignore_status_mask, 1); |
| 1777 | } |
| 1778 | } |
| 1779 | |
| 1780 | /** |
| 1781 | * ic4_startup_local - Start up the serial port - returns >= 0 if no errors |
| 1782 | * @the_port: Port to operate on |
| 1783 | */ |
| 1784 | static inline int ic4_startup_local(struct uart_port *the_port) |
| 1785 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1786 | struct ioc4_port *port; |
| 1787 | struct uart_info *info; |
| 1788 | |
| 1789 | if (!the_port) |
| 1790 | return -1; |
| 1791 | |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 1792 | port = get_ioc4_port(the_port, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1793 | if (!port) |
| 1794 | return -1; |
| 1795 | |
| 1796 | info = the_port->info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1797 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1798 | local_open(port); |
| 1799 | |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 1800 | /* set the protocol - mapbase has the port type */ |
| 1801 | ioc4_set_proto(port, the_port->mapbase); |
| 1802 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1803 | /* set the speed of the serial port */ |
Alan Cox | 606d099 | 2006-12-08 02:38:45 -0800 | [diff] [blame] | 1804 | ioc4_change_speed(the_port, info->tty->termios, (struct ktermios *)0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1805 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1806 | return 0; |
| 1807 | } |
| 1808 | |
| 1809 | /* |
| 1810 | * ioc4_cb_output_lowat - called when the output low water mark is hit |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 1811 | * @the_port: port to output |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1812 | */ |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 1813 | static void ioc4_cb_output_lowat(struct uart_port *the_port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1814 | { |
Pat Gefre | 396dc44 | 2005-10-30 15:02:49 -0800 | [diff] [blame] | 1815 | unsigned long pflags; |
| 1816 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1817 | /* ip_lock is set on the call here */ |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 1818 | if (the_port) { |
| 1819 | spin_lock_irqsave(&the_port->lock, pflags); |
| 1820 | transmit_chars(the_port); |
| 1821 | spin_unlock_irqrestore(&the_port->lock, pflags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1822 | } |
| 1823 | } |
| 1824 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1825 | /** |
| 1826 | * handle_intr - service any interrupts for the given port - 2nd level |
| 1827 | * called via sd_intr |
| 1828 | * @arg: handler arg |
| 1829 | * @sio_ir: ioc4regs |
| 1830 | */ |
| 1831 | static void handle_intr(void *arg, uint32_t sio_ir) |
| 1832 | { |
| 1833 | struct ioc4_port *port = (struct ioc4_port *)arg; |
| 1834 | struct hooks *hooks = port->ip_hooks; |
| 1835 | unsigned int rx_high_rd_aborted = 0; |
Andrew Morton | a5a89ba | 2006-10-29 22:46:33 -0800 | [diff] [blame] | 1836 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1837 | struct uart_port *the_port; |
| 1838 | int loop_counter; |
| 1839 | |
| 1840 | /* Possible race condition here: The tx_mt interrupt bit may be |
| 1841 | * cleared without the intervention of the interrupt handler, |
| 1842 | * e.g. by a write. If the top level interrupt handler reads a |
| 1843 | * tx_mt, then some other processor does a write, starting up |
| 1844 | * output, then we come in here, see the tx_mt and stop DMA, the |
| 1845 | * output started by the other processor will hang. Thus we can |
| 1846 | * only rely on tx_mt being legitimate if it is read while the |
| 1847 | * port lock is held. Therefore this bit must be ignored in the |
| 1848 | * passed in interrupt mask which was read by the top level |
| 1849 | * interrupt handler since the port lock was not held at the time |
| 1850 | * it was read. We can only rely on this bit being accurate if it |
| 1851 | * is read while the port lock is held. So we'll clear it for now, |
| 1852 | * and reload it later once we have the port lock. |
| 1853 | */ |
| 1854 | sio_ir &= ~(hooks->intr_tx_mt); |
| 1855 | |
| 1856 | spin_lock_irqsave(&port->ip_lock, flags); |
| 1857 | |
| 1858 | loop_counter = MAXITER; /* to avoid hangs */ |
| 1859 | |
| 1860 | do { |
| 1861 | uint32_t shadow; |
| 1862 | |
| 1863 | if ( loop_counter-- <= 0 ) { |
| 1864 | printk(KERN_WARNING "IOC4 serial: " |
| 1865 | "possible hang condition/" |
| 1866 | "port stuck on interrupt.\n"); |
| 1867 | break; |
| 1868 | } |
| 1869 | |
| 1870 | /* Handle a DCD change */ |
| 1871 | if (sio_ir & hooks->intr_delta_dcd) { |
| 1872 | /* ACK the interrupt */ |
| 1873 | writel(hooks->intr_delta_dcd, |
Brent Casavant | 22329b5 | 2005-06-21 17:15:59 -0700 | [diff] [blame] | 1874 | &port->ip_mem->sio_ir.raw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1875 | |
| 1876 | shadow = readl(&port->ip_serial_regs->shadow); |
| 1877 | |
| 1878 | if ((port->ip_notify & N_DDCD) |
| 1879 | && (shadow & IOC4_SHADOW_DCD) |
| 1880 | && (port->ip_port)) { |
| 1881 | the_port = port->ip_port; |
| 1882 | the_port->icount.dcd = 1; |
| 1883 | wake_up_interruptible |
| 1884 | (&the_port-> info->delta_msr_wait); |
| 1885 | } else if ((port->ip_notify & N_DDCD) |
| 1886 | && !(shadow & IOC4_SHADOW_DCD)) { |
| 1887 | /* Flag delta DCD/no DCD */ |
| 1888 | port->ip_flags |= DCD_ON; |
| 1889 | } |
| 1890 | } |
| 1891 | |
| 1892 | /* Handle a CTS change */ |
| 1893 | if (sio_ir & hooks->intr_delta_cts) { |
| 1894 | /* ACK the interrupt */ |
| 1895 | writel(hooks->intr_delta_cts, |
Brent Casavant | 22329b5 | 2005-06-21 17:15:59 -0700 | [diff] [blame] | 1896 | &port->ip_mem->sio_ir.raw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1897 | |
| 1898 | shadow = readl(&port->ip_serial_regs->shadow); |
| 1899 | |
| 1900 | if ((port->ip_notify & N_DCTS) |
| 1901 | && (port->ip_port)) { |
| 1902 | the_port = port->ip_port; |
| 1903 | the_port->icount.cts = |
| 1904 | (shadow & IOC4_SHADOW_CTS) ? 1 : 0; |
| 1905 | wake_up_interruptible |
| 1906 | (&the_port->info->delta_msr_wait); |
| 1907 | } |
| 1908 | } |
| 1909 | |
| 1910 | /* rx timeout interrupt. Must be some data available. Put this |
| 1911 | * before the check for rx_high since servicing this condition |
| 1912 | * may cause that condition to clear. |
| 1913 | */ |
| 1914 | if (sio_ir & hooks->intr_rx_timer) { |
| 1915 | /* ACK the interrupt */ |
| 1916 | writel(hooks->intr_rx_timer, |
Brent Casavant | 22329b5 | 2005-06-21 17:15:59 -0700 | [diff] [blame] | 1917 | &port->ip_mem->sio_ir.raw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1918 | |
| 1919 | if ((port->ip_notify & N_DATA_READY) |
| 1920 | && (port->ip_port)) { |
| 1921 | /* ip_lock is set on call here */ |
| 1922 | receive_chars(port->ip_port); |
| 1923 | } |
| 1924 | } |
| 1925 | |
| 1926 | /* rx high interrupt. Must be after rx_timer. */ |
| 1927 | else if (sio_ir & hooks->intr_rx_high) { |
| 1928 | /* Data available, notify upper layer */ |
| 1929 | if ((port->ip_notify & N_DATA_READY) |
| 1930 | && port->ip_port) { |
| 1931 | /* ip_lock is set on call here */ |
| 1932 | receive_chars(port->ip_port); |
| 1933 | } |
| 1934 | |
| 1935 | /* We can't ACK this interrupt. If receive_chars didn't |
| 1936 | * cause the condition to clear, we'll have to disable |
| 1937 | * the interrupt until the data is drained. |
| 1938 | * If the read was aborted, don't disable the interrupt |
| 1939 | * as this may cause us to hang indefinitely. An |
| 1940 | * aborted read generally means that this interrupt |
| 1941 | * hasn't been delivered to the cpu yet anyway, even |
| 1942 | * though we see it as asserted when we read the sio_ir. |
| 1943 | */ |
| 1944 | if ((sio_ir = PENDING(port)) & hooks->intr_rx_high) { |
| 1945 | if ((port->ip_flags & READ_ABORTED) == 0) { |
| 1946 | port->ip_ienb &= ~hooks->intr_rx_high; |
| 1947 | port->ip_flags |= INPUT_HIGH; |
| 1948 | } else { |
| 1949 | rx_high_rd_aborted++; |
| 1950 | } |
| 1951 | } |
| 1952 | } |
| 1953 | |
| 1954 | /* We got a low water interrupt: notify upper layer to |
| 1955 | * send more data. Must come before tx_mt since servicing |
| 1956 | * this condition may cause that condition to clear. |
| 1957 | */ |
| 1958 | if (sio_ir & hooks->intr_tx_explicit) { |
| 1959 | port->ip_flags &= ~LOWAT_WRITTEN; |
| 1960 | |
| 1961 | /* ACK the interrupt */ |
| 1962 | writel(hooks->intr_tx_explicit, |
Brent Casavant | 22329b5 | 2005-06-21 17:15:59 -0700 | [diff] [blame] | 1963 | &port->ip_mem->sio_ir.raw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1964 | |
| 1965 | if (port->ip_notify & N_OUTPUT_LOWAT) |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 1966 | ioc4_cb_output_lowat(port->ip_port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1967 | } |
| 1968 | |
| 1969 | /* Handle tx_mt. Must come after tx_explicit. */ |
| 1970 | else if (sio_ir & hooks->intr_tx_mt) { |
| 1971 | /* If we are expecting a lowat notification |
| 1972 | * and we get to this point it probably means that for |
| 1973 | * some reason the tx_explicit didn't work as expected |
| 1974 | * (that can legitimately happen if the output buffer is |
| 1975 | * filled up in just the right way). |
| 1976 | * So send the notification now. |
| 1977 | */ |
| 1978 | if (port->ip_notify & N_OUTPUT_LOWAT) { |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 1979 | ioc4_cb_output_lowat(port->ip_port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1980 | |
| 1981 | /* We need to reload the sio_ir since the lowat |
| 1982 | * call may have caused another write to occur, |
| 1983 | * clearing the tx_mt condition. |
| 1984 | */ |
| 1985 | sio_ir = PENDING(port); |
| 1986 | } |
| 1987 | |
| 1988 | /* If the tx_mt condition still persists even after the |
| 1989 | * lowat call, we've got some work to do. |
| 1990 | */ |
| 1991 | if (sio_ir & hooks->intr_tx_mt) { |
| 1992 | |
| 1993 | /* If we are not currently expecting DMA input, |
| 1994 | * and the transmitter has just gone idle, |
| 1995 | * there is no longer any reason for DMA, so |
| 1996 | * disable it. |
| 1997 | */ |
| 1998 | if (!(port->ip_notify |
| 1999 | & (N_DATA_READY | N_DDCD))) { |
| 2000 | BUG_ON(!(port->ip_sscr |
| 2001 | & IOC4_SSCR_DMA_EN)); |
| 2002 | port->ip_sscr &= ~IOC4_SSCR_DMA_EN; |
| 2003 | writel(port->ip_sscr, |
| 2004 | &port->ip_serial_regs->sscr); |
| 2005 | } |
| 2006 | |
| 2007 | /* Prevent infinite tx_mt interrupt */ |
| 2008 | port->ip_ienb &= ~hooks->intr_tx_mt; |
| 2009 | } |
| 2010 | } |
| 2011 | sio_ir = PENDING(port); |
| 2012 | |
| 2013 | /* if the read was aborted and only hooks->intr_rx_high, |
| 2014 | * clear hooks->intr_rx_high, so we do not loop forever. |
| 2015 | */ |
| 2016 | |
| 2017 | if (rx_high_rd_aborted && (sio_ir == hooks->intr_rx_high)) { |
| 2018 | sio_ir &= ~hooks->intr_rx_high; |
| 2019 | } |
| 2020 | } while (sio_ir & hooks->intr_all); |
| 2021 | |
| 2022 | spin_unlock_irqrestore(&port->ip_lock, flags); |
| 2023 | |
| 2024 | /* Re-enable interrupts before returning from interrupt handler. |
| 2025 | * Getting interrupted here is okay. It'll just v() our semaphore, and |
| 2026 | * we'll come through the loop again. |
| 2027 | */ |
| 2028 | |
| 2029 | write_ireg(port->ip_ioc4_soft, port->ip_ienb, IOC4_W_IES, |
| 2030 | IOC4_SIO_INTR_TYPE); |
| 2031 | } |
| 2032 | |
| 2033 | /* |
| 2034 | * ioc4_cb_post_ncs - called for some basic errors |
| 2035 | * @port: port to use |
| 2036 | * @ncs: event |
| 2037 | */ |
| 2038 | static void ioc4_cb_post_ncs(struct uart_port *the_port, int ncs) |
| 2039 | { |
| 2040 | struct uart_icount *icount; |
| 2041 | |
| 2042 | icount = &the_port->icount; |
| 2043 | |
| 2044 | if (ncs & NCS_BREAK) |
| 2045 | icount->brk++; |
| 2046 | if (ncs & NCS_FRAMING) |
| 2047 | icount->frame++; |
| 2048 | if (ncs & NCS_OVERRUN) |
| 2049 | icount->overrun++; |
| 2050 | if (ncs & NCS_PARITY) |
| 2051 | icount->parity++; |
| 2052 | } |
| 2053 | |
| 2054 | /** |
| 2055 | * do_read - Read in bytes from the port. Return the number of bytes |
| 2056 | * actually read. |
| 2057 | * @the_port: port to use |
| 2058 | * @buf: place to put the stuff we read |
| 2059 | * @len: how big 'buf' is |
| 2060 | */ |
| 2061 | |
| 2062 | static inline int do_read(struct uart_port *the_port, unsigned char *buf, |
| 2063 | int len) |
| 2064 | { |
| 2065 | int prod_ptr, cons_ptr, total; |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 2066 | struct ioc4_port *port = get_ioc4_port(the_port, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2067 | struct ring *inring; |
| 2068 | struct ring_entry *entry; |
| 2069 | struct hooks *hooks = port->ip_hooks; |
| 2070 | int byte_num; |
| 2071 | char *sc; |
| 2072 | int loop_counter; |
| 2073 | |
| 2074 | BUG_ON(!(len >= 0)); |
| 2075 | BUG_ON(!port); |
| 2076 | |
| 2077 | /* There is a nasty timing issue in the IOC4. When the rx_timer |
| 2078 | * expires or the rx_high condition arises, we take an interrupt. |
| 2079 | * At some point while servicing the interrupt, we read bytes from |
| 2080 | * the ring buffer and re-arm the rx_timer. However the rx_timer is |
| 2081 | * not started until the first byte is received *after* it is armed, |
| 2082 | * and any bytes pending in the rx construction buffers are not drained |
| 2083 | * to memory until either there are 4 bytes available or the rx_timer |
| 2084 | * expires. This leads to a potential situation where data is left |
| 2085 | * in the construction buffers forever - 1 to 3 bytes were received |
| 2086 | * after the interrupt was generated but before the rx_timer was |
| 2087 | * re-armed. At that point as long as no subsequent bytes are received |
| 2088 | * the timer will never be started and the bytes will remain in the |
| 2089 | * construction buffer forever. The solution is to execute a DRAIN |
| 2090 | * command after rearming the timer. This way any bytes received before |
| 2091 | * the DRAIN will be drained to memory, and any bytes received after |
| 2092 | * the DRAIN will start the TIMER and be drained when it expires. |
| 2093 | * Luckily, this only needs to be done when the DMA buffer is empty |
| 2094 | * since there is no requirement that this function return all |
| 2095 | * available data as long as it returns some. |
| 2096 | */ |
| 2097 | /* Re-arm the timer */ |
Pat Gefre | 396dc44 | 2005-10-30 15:02:49 -0800 | [diff] [blame] | 2098 | writel(port->ip_rx_cons | IOC4_SRCIR_ARM, &port->ip_serial_regs->srcir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2099 | |
| 2100 | prod_ptr = readl(&port->ip_serial_regs->srpir) & PROD_CONS_MASK; |
| 2101 | cons_ptr = port->ip_rx_cons; |
| 2102 | |
| 2103 | if (prod_ptr == cons_ptr) { |
| 2104 | int reset_dma = 0; |
| 2105 | |
| 2106 | /* Input buffer appears empty, do a flush. */ |
| 2107 | |
| 2108 | /* DMA must be enabled for this to work. */ |
| 2109 | if (!(port->ip_sscr & IOC4_SSCR_DMA_EN)) { |
| 2110 | port->ip_sscr |= IOC4_SSCR_DMA_EN; |
| 2111 | reset_dma = 1; |
| 2112 | } |
| 2113 | |
| 2114 | /* Potential race condition: we must reload the srpir after |
| 2115 | * issuing the drain command, otherwise we could think the rx |
| 2116 | * buffer is empty, then take a very long interrupt, and when |
| 2117 | * we come back it's full and we wait forever for the drain to |
| 2118 | * complete. |
| 2119 | */ |
| 2120 | writel(port->ip_sscr | IOC4_SSCR_RX_DRAIN, |
| 2121 | &port->ip_serial_regs->sscr); |
| 2122 | prod_ptr = readl(&port->ip_serial_regs->srpir) |
| 2123 | & PROD_CONS_MASK; |
| 2124 | |
| 2125 | /* We must not wait for the DRAIN to complete unless there are |
| 2126 | * at least 8 bytes (2 ring entries) available to receive the |
| 2127 | * data otherwise the DRAIN will never complete and we'll |
| 2128 | * deadlock here. |
| 2129 | * In fact, to make things easier, I'll just ignore the flush if |
| 2130 | * there is any data at all now available. |
| 2131 | */ |
| 2132 | if (prod_ptr == cons_ptr) { |
| 2133 | loop_counter = 0; |
| 2134 | while (readl(&port->ip_serial_regs->sscr) & |
| 2135 | IOC4_SSCR_RX_DRAIN) { |
| 2136 | loop_counter++; |
| 2137 | if (loop_counter > MAXITER) |
| 2138 | return -1; |
| 2139 | } |
| 2140 | |
| 2141 | /* SIGH. We have to reload the prod_ptr *again* since |
| 2142 | * the drain may have caused it to change |
| 2143 | */ |
| 2144 | prod_ptr = readl(&port->ip_serial_regs->srpir) |
| 2145 | & PROD_CONS_MASK; |
| 2146 | } |
| 2147 | if (reset_dma) { |
| 2148 | port->ip_sscr &= ~IOC4_SSCR_DMA_EN; |
| 2149 | writel(port->ip_sscr, &port->ip_serial_regs->sscr); |
| 2150 | } |
| 2151 | } |
| 2152 | inring = port->ip_inring; |
| 2153 | port->ip_flags &= ~READ_ABORTED; |
| 2154 | |
| 2155 | total = 0; |
| 2156 | loop_counter = 0xfffff; /* to avoid hangs */ |
| 2157 | |
| 2158 | /* Grab bytes from the hardware */ |
| 2159 | while ((prod_ptr != cons_ptr) && (len > 0)) { |
| 2160 | entry = (struct ring_entry *)((caddr_t)inring + cons_ptr); |
| 2161 | |
| 2162 | if ( loop_counter-- <= 0 ) { |
| 2163 | printk(KERN_WARNING "IOC4 serial: " |
| 2164 | "possible hang condition/" |
| 2165 | "port stuck on read.\n"); |
| 2166 | break; |
| 2167 | } |
| 2168 | |
| 2169 | /* According to the producer pointer, this ring entry |
| 2170 | * must contain some data. But if the PIO happened faster |
| 2171 | * than the DMA, the data may not be available yet, so let's |
| 2172 | * wait until it arrives. |
| 2173 | */ |
| 2174 | if ((entry->ring_allsc & RING_ANY_VALID) == 0) { |
| 2175 | /* Indicate the read is aborted so we don't disable |
| 2176 | * the interrupt thinking that the consumer is |
| 2177 | * congested. |
| 2178 | */ |
| 2179 | port->ip_flags |= READ_ABORTED; |
| 2180 | len = 0; |
| 2181 | break; |
| 2182 | } |
| 2183 | |
| 2184 | /* Load the bytes/status out of the ring entry */ |
| 2185 | for (byte_num = 0; byte_num < 4 && len > 0; byte_num++) { |
| 2186 | sc = &(entry->ring_sc[byte_num]); |
| 2187 | |
| 2188 | /* Check for change in modem state or overrun */ |
| 2189 | if ((*sc & IOC4_RXSB_MODEM_VALID) |
| 2190 | && (port->ip_notify & N_DDCD)) { |
| 2191 | /* Notify upper layer if DCD dropped */ |
| 2192 | |
| 2193 | if ((port->ip_flags & DCD_ON) |
| 2194 | && !(*sc & IOC4_RXSB_DCD)) { |
| 2195 | |
| 2196 | /* If we have already copied some data, |
| 2197 | * return it. We'll pick up the carrier |
| 2198 | * drop on the next pass. That way we |
| 2199 | * don't throw away the data that has |
| 2200 | * already been copied back to |
| 2201 | * the caller's buffer. |
| 2202 | */ |
| 2203 | if (total > 0) { |
| 2204 | len = 0; |
| 2205 | break; |
| 2206 | } |
| 2207 | port->ip_flags &= ~DCD_ON; |
| 2208 | |
| 2209 | /* Turn off this notification so the |
| 2210 | * carrier drop protocol won't see it |
| 2211 | * again when it does a read. |
| 2212 | */ |
| 2213 | *sc &= ~IOC4_RXSB_MODEM_VALID; |
| 2214 | |
| 2215 | /* To keep things consistent, we need |
| 2216 | * to update the consumer pointer so |
| 2217 | * the next reader won't come in and |
| 2218 | * try to read the same ring entries |
| 2219 | * again. This must be done here before |
| 2220 | * the dcd change. |
| 2221 | */ |
| 2222 | |
| 2223 | if ((entry->ring_allsc & RING_ANY_VALID) |
| 2224 | == 0) { |
| 2225 | cons_ptr += (int)sizeof |
| 2226 | (struct ring_entry); |
| 2227 | cons_ptr &= PROD_CONS_MASK; |
| 2228 | } |
| 2229 | writel(cons_ptr, |
| 2230 | &port->ip_serial_regs->srcir); |
| 2231 | port->ip_rx_cons = cons_ptr; |
| 2232 | |
| 2233 | /* Notify upper layer of carrier drop */ |
| 2234 | if ((port->ip_notify & N_DDCD) |
| 2235 | && port->ip_port) { |
| 2236 | the_port->icount.dcd = 0; |
| 2237 | wake_up_interruptible |
| 2238 | (&the_port->info-> |
| 2239 | delta_msr_wait); |
| 2240 | } |
| 2241 | |
| 2242 | /* If we had any data to return, we |
| 2243 | * would have returned it above. |
| 2244 | */ |
| 2245 | return 0; |
| 2246 | } |
| 2247 | } |
| 2248 | if (*sc & IOC4_RXSB_MODEM_VALID) { |
| 2249 | /* Notify that an input overrun occurred */ |
| 2250 | if ((*sc & IOC4_RXSB_OVERRUN) |
| 2251 | && (port->ip_notify & N_OVERRUN_ERROR)) { |
| 2252 | ioc4_cb_post_ncs(the_port, NCS_OVERRUN); |
| 2253 | } |
| 2254 | /* Don't look at this byte again */ |
| 2255 | *sc &= ~IOC4_RXSB_MODEM_VALID; |
| 2256 | } |
| 2257 | |
| 2258 | /* Check for valid data or RX errors */ |
| 2259 | if ((*sc & IOC4_RXSB_DATA_VALID) && |
| 2260 | ((*sc & (IOC4_RXSB_PAR_ERR |
| 2261 | | IOC4_RXSB_FRAME_ERR |
| 2262 | | IOC4_RXSB_BREAK)) |
| 2263 | && (port->ip_notify & (N_PARITY_ERROR |
| 2264 | | N_FRAMING_ERROR |
| 2265 | | N_BREAK)))) { |
| 2266 | /* There is an error condition on the next byte. |
| 2267 | * If we have already transferred some bytes, |
| 2268 | * we'll stop here. Otherwise if this is the |
| 2269 | * first byte to be read, we'll just transfer |
| 2270 | * it alone after notifying the |
| 2271 | * upper layer of its status. |
| 2272 | */ |
| 2273 | if (total > 0) { |
| 2274 | len = 0; |
| 2275 | break; |
| 2276 | } else { |
| 2277 | if ((*sc & IOC4_RXSB_PAR_ERR) && |
| 2278 | (port->ip_notify & N_PARITY_ERROR)) { |
| 2279 | ioc4_cb_post_ncs(the_port, |
| 2280 | NCS_PARITY); |
| 2281 | } |
| 2282 | if ((*sc & IOC4_RXSB_FRAME_ERR) && |
| 2283 | (port->ip_notify & N_FRAMING_ERROR)){ |
| 2284 | ioc4_cb_post_ncs(the_port, |
| 2285 | NCS_FRAMING); |
| 2286 | } |
| 2287 | if ((*sc & IOC4_RXSB_BREAK) |
| 2288 | && (port->ip_notify & N_BREAK)) { |
| 2289 | ioc4_cb_post_ncs |
| 2290 | (the_port, |
| 2291 | NCS_BREAK); |
| 2292 | } |
| 2293 | len = 1; |
| 2294 | } |
| 2295 | } |
| 2296 | if (*sc & IOC4_RXSB_DATA_VALID) { |
| 2297 | *sc &= ~IOC4_RXSB_DATA_VALID; |
| 2298 | *buf = entry->ring_data[byte_num]; |
| 2299 | buf++; |
| 2300 | len--; |
| 2301 | total++; |
| 2302 | } |
| 2303 | } |
| 2304 | |
| 2305 | /* If we used up this entry entirely, go on to the next one, |
| 2306 | * otherwise we must have run out of buffer space, so |
| 2307 | * leave the consumer pointer here for the next read in case |
| 2308 | * there are still unread bytes in this entry. |
| 2309 | */ |
| 2310 | if ((entry->ring_allsc & RING_ANY_VALID) == 0) { |
| 2311 | cons_ptr += (int)sizeof(struct ring_entry); |
| 2312 | cons_ptr &= PROD_CONS_MASK; |
| 2313 | } |
| 2314 | } |
| 2315 | |
| 2316 | /* Update consumer pointer and re-arm rx timer interrupt */ |
| 2317 | writel(cons_ptr, &port->ip_serial_regs->srcir); |
| 2318 | port->ip_rx_cons = cons_ptr; |
| 2319 | |
| 2320 | /* If we have now dipped below the rx high water mark and we have |
| 2321 | * rx_high interrupt turned off, we can now turn it back on again. |
| 2322 | */ |
| 2323 | if ((port->ip_flags & INPUT_HIGH) && (((prod_ptr - cons_ptr) |
| 2324 | & PROD_CONS_MASK) < ((port->ip_sscr & |
| 2325 | IOC4_SSCR_RX_THRESHOLD) |
| 2326 | << IOC4_PROD_CONS_PTR_OFF))) { |
| 2327 | port->ip_flags &= ~INPUT_HIGH; |
| 2328 | enable_intrs(port, hooks->intr_rx_high); |
| 2329 | } |
| 2330 | return total; |
| 2331 | } |
Pat Gefre | 396dc44 | 2005-10-30 15:02:49 -0800 | [diff] [blame] | 2332 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2333 | /** |
| 2334 | * receive_chars - upper level read. Called with ip_lock. |
| 2335 | * @the_port: port to read from |
| 2336 | */ |
| 2337 | static void receive_chars(struct uart_port *the_port) |
| 2338 | { |
| 2339 | struct tty_struct *tty; |
| 2340 | unsigned char ch[IOC4_MAX_CHARS]; |
Pat Gefre | 396dc44 | 2005-10-30 15:02:49 -0800 | [diff] [blame] | 2341 | int read_count, request_count = IOC4_MAX_CHARS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2342 | struct uart_icount *icount; |
| 2343 | struct uart_info *info = the_port->info; |
Pat Gefre | 396dc44 | 2005-10-30 15:02:49 -0800 | [diff] [blame] | 2344 | unsigned long pflags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2345 | |
| 2346 | /* Make sure all the pointers are "good" ones */ |
| 2347 | if (!info) |
| 2348 | return; |
| 2349 | if (!info->tty) |
| 2350 | return; |
| 2351 | |
Pat Gefre | 396dc44 | 2005-10-30 15:02:49 -0800 | [diff] [blame] | 2352 | spin_lock_irqsave(&the_port->lock, pflags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2353 | tty = info->tty; |
| 2354 | |
Pat Gefre | 27d162e | 2006-03-11 03:27:17 -0800 | [diff] [blame] | 2355 | request_count = tty_buffer_request_room(tty, IOC4_MAX_CHARS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2356 | |
| 2357 | if (request_count > 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2358 | icount = &the_port->icount; |
| 2359 | read_count = do_read(the_port, ch, request_count); |
| 2360 | if (read_count > 0) { |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 2361 | tty_insert_flip_string(tty, ch, read_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2362 | icount->rx += read_count; |
| 2363 | } |
| 2364 | } |
Pat Gefre | 396dc44 | 2005-10-30 15:02:49 -0800 | [diff] [blame] | 2365 | |
| 2366 | spin_unlock_irqrestore(&the_port->lock, pflags); |
| 2367 | |
Pat Gefre | 27d162e | 2006-03-11 03:27:17 -0800 | [diff] [blame] | 2368 | tty_flip_buffer_push(tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2369 | } |
| 2370 | |
| 2371 | /** |
| 2372 | * ic4_type - What type of console are we? |
| 2373 | * @port: Port to operate with (we ignore since we only have one port) |
| 2374 | * |
| 2375 | */ |
| 2376 | static const char *ic4_type(struct uart_port *the_port) |
| 2377 | { |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 2378 | if (the_port->mapbase == PROTO_RS232) |
| 2379 | return "SGI IOC4 Serial [rs232]"; |
| 2380 | else |
| 2381 | return "SGI IOC4 Serial [rs422]"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2382 | } |
| 2383 | |
| 2384 | /** |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 2385 | * ic4_tx_empty - Is the transmitter empty? |
| 2386 | * @port: Port to operate on |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2387 | * |
| 2388 | */ |
| 2389 | static unsigned int ic4_tx_empty(struct uart_port *the_port) |
| 2390 | { |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 2391 | struct ioc4_port *port = get_ioc4_port(the_port, 0); |
| 2392 | unsigned int ret = 0; |
| 2393 | |
| 2394 | if (port_is_active(port, the_port)) { |
| 2395 | if (readl(&port->ip_serial_regs->shadow) & IOC4_SHADOW_TEMT) |
| 2396 | ret = TIOCSER_TEMT; |
| 2397 | } |
| 2398 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2399 | } |
| 2400 | |
| 2401 | /** |
| 2402 | * ic4_stop_tx - stop the transmitter |
| 2403 | * @port: Port to operate on |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2404 | * |
| 2405 | */ |
Russell King | b129a8c | 2005-08-31 10:12:14 +0100 | [diff] [blame] | 2406 | static void ic4_stop_tx(struct uart_port *the_port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2407 | { |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 2408 | struct ioc4_port *port = get_ioc4_port(the_port, 0); |
| 2409 | |
| 2410 | if (port_is_active(port, the_port)) |
| 2411 | set_notification(port, N_OUTPUT_LOWAT, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2412 | } |
| 2413 | |
| 2414 | /** |
| 2415 | * null_void_function - |
| 2416 | * @port: Port to operate on |
| 2417 | * |
| 2418 | */ |
| 2419 | static void null_void_function(struct uart_port *the_port) |
| 2420 | { |
| 2421 | } |
| 2422 | |
| 2423 | /** |
| 2424 | * ic4_shutdown - shut down the port - free irq and disable |
| 2425 | * @port: Port to shut down |
| 2426 | * |
| 2427 | */ |
| 2428 | static void ic4_shutdown(struct uart_port *the_port) |
| 2429 | { |
| 2430 | unsigned long port_flags; |
| 2431 | struct ioc4_port *port; |
| 2432 | struct uart_info *info; |
| 2433 | |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 2434 | port = get_ioc4_port(the_port, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2435 | if (!port) |
| 2436 | return; |
| 2437 | |
| 2438 | info = the_port->info; |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 2439 | port->ip_port = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2440 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2441 | wake_up_interruptible(&info->delta_msr_wait); |
| 2442 | |
| 2443 | if (info->tty) |
| 2444 | set_bit(TTY_IO_ERROR, &info->tty->flags); |
| 2445 | |
Pat Gefre | 396dc44 | 2005-10-30 15:02:49 -0800 | [diff] [blame] | 2446 | spin_lock_irqsave(&the_port->lock, port_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2447 | set_notification(port, N_ALL, 0); |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 2448 | port->ip_flags = PORT_INACTIVE; |
Pat Gefre | 396dc44 | 2005-10-30 15:02:49 -0800 | [diff] [blame] | 2449 | spin_unlock_irqrestore(&the_port->lock, port_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2450 | } |
| 2451 | |
| 2452 | /** |
| 2453 | * ic4_set_mctrl - set control lines (dtr, rts, etc) |
| 2454 | * @port: Port to operate on |
| 2455 | * @mctrl: Lines to set/unset |
| 2456 | * |
| 2457 | */ |
| 2458 | static void ic4_set_mctrl(struct uart_port *the_port, unsigned int mctrl) |
| 2459 | { |
| 2460 | unsigned char mcr = 0; |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 2461 | struct ioc4_port *port; |
| 2462 | |
| 2463 | port = get_ioc4_port(the_port, 0); |
| 2464 | if (!port_is_active(port, the_port)) |
| 2465 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2466 | |
| 2467 | if (mctrl & TIOCM_RTS) |
| 2468 | mcr |= UART_MCR_RTS; |
| 2469 | if (mctrl & TIOCM_DTR) |
| 2470 | mcr |= UART_MCR_DTR; |
| 2471 | if (mctrl & TIOCM_OUT1) |
| 2472 | mcr |= UART_MCR_OUT1; |
| 2473 | if (mctrl & TIOCM_OUT2) |
| 2474 | mcr |= UART_MCR_OUT2; |
| 2475 | if (mctrl & TIOCM_LOOP) |
| 2476 | mcr |= UART_MCR_LOOP; |
| 2477 | |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 2478 | set_mcr(the_port, mcr, IOC4_SHADOW_DTR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2479 | } |
| 2480 | |
| 2481 | /** |
| 2482 | * ic4_get_mctrl - get control line info |
| 2483 | * @port: port to operate on |
| 2484 | * |
| 2485 | */ |
| 2486 | static unsigned int ic4_get_mctrl(struct uart_port *the_port) |
| 2487 | { |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 2488 | struct ioc4_port *port = get_ioc4_port(the_port, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2489 | uint32_t shadow; |
| 2490 | unsigned int ret = 0; |
| 2491 | |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 2492 | if (!port_is_active(port, the_port)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2493 | return 0; |
| 2494 | |
| 2495 | shadow = readl(&port->ip_serial_regs->shadow); |
| 2496 | if (shadow & IOC4_SHADOW_DCD) |
| 2497 | ret |= TIOCM_CAR; |
| 2498 | if (shadow & IOC4_SHADOW_DR) |
| 2499 | ret |= TIOCM_DSR; |
| 2500 | if (shadow & IOC4_SHADOW_CTS) |
| 2501 | ret |= TIOCM_CTS; |
| 2502 | return ret; |
| 2503 | } |
| 2504 | |
| 2505 | /** |
| 2506 | * ic4_start_tx - Start transmitter, flush any output |
| 2507 | * @port: Port to operate on |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2508 | * |
| 2509 | */ |
Russell King | b129a8c | 2005-08-31 10:12:14 +0100 | [diff] [blame] | 2510 | static void ic4_start_tx(struct uart_port *the_port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2511 | { |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 2512 | struct ioc4_port *port = get_ioc4_port(the_port, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2513 | |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 2514 | if (port_is_active(port, the_port)) { |
Pat Gefre | 396dc44 | 2005-10-30 15:02:49 -0800 | [diff] [blame] | 2515 | set_notification(port, N_OUTPUT_LOWAT, 1); |
| 2516 | enable_intrs(port, port->ip_hooks->intr_tx_mt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2517 | } |
| 2518 | } |
| 2519 | |
| 2520 | /** |
| 2521 | * ic4_break_ctl - handle breaks |
| 2522 | * @port: Port to operate on |
| 2523 | * @break_state: Break state |
| 2524 | * |
| 2525 | */ |
| 2526 | static void ic4_break_ctl(struct uart_port *the_port, int break_state) |
| 2527 | { |
| 2528 | } |
| 2529 | |
| 2530 | /** |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 2531 | * ic4_startup - Start up the serial port |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2532 | * @port: Port to operate on |
| 2533 | * |
| 2534 | */ |
| 2535 | static int ic4_startup(struct uart_port *the_port) |
| 2536 | { |
| 2537 | int retval; |
| 2538 | struct ioc4_port *port; |
| 2539 | struct ioc4_control *control; |
| 2540 | struct uart_info *info; |
| 2541 | unsigned long port_flags; |
| 2542 | |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 2543 | if (!the_port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2544 | return -ENODEV; |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 2545 | port = get_ioc4_port(the_port, 1); |
| 2546 | if (!port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2547 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2548 | info = the_port->info; |
| 2549 | |
| 2550 | control = port->ip_control; |
| 2551 | if (!control) { |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 2552 | port->ip_port = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2553 | return -ENODEV; |
| 2554 | } |
| 2555 | |
| 2556 | /* Start up the serial port */ |
Pat Gefre | 396dc44 | 2005-10-30 15:02:49 -0800 | [diff] [blame] | 2557 | spin_lock_irqsave(&the_port->lock, port_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2558 | retval = ic4_startup_local(the_port); |
Pat Gefre | 396dc44 | 2005-10-30 15:02:49 -0800 | [diff] [blame] | 2559 | spin_unlock_irqrestore(&the_port->lock, port_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2560 | return retval; |
| 2561 | } |
| 2562 | |
| 2563 | /** |
| 2564 | * ic4_set_termios - set termios stuff |
| 2565 | * @port: port to operate on |
| 2566 | * @termios: New settings |
| 2567 | * @termios: Old |
| 2568 | * |
| 2569 | */ |
| 2570 | static void |
| 2571 | ic4_set_termios(struct uart_port *the_port, |
Alan Cox | 606d099 | 2006-12-08 02:38:45 -0800 | [diff] [blame] | 2572 | struct ktermios *termios, struct ktermios *old_termios) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2573 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2574 | unsigned long port_flags; |
| 2575 | |
Pat Gefre | 396dc44 | 2005-10-30 15:02:49 -0800 | [diff] [blame] | 2576 | spin_lock_irqsave(&the_port->lock, port_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2577 | ioc4_change_speed(the_port, termios, old_termios); |
Pat Gefre | 396dc44 | 2005-10-30 15:02:49 -0800 | [diff] [blame] | 2578 | spin_unlock_irqrestore(&the_port->lock, port_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2579 | } |
| 2580 | |
| 2581 | /** |
| 2582 | * ic4_request_port - allocate resources for port - no op.... |
| 2583 | * @port: port to operate on |
| 2584 | * |
| 2585 | */ |
| 2586 | static int ic4_request_port(struct uart_port *port) |
| 2587 | { |
| 2588 | return 0; |
| 2589 | } |
| 2590 | |
| 2591 | /* Associate the uart functions above - given to serial core */ |
| 2592 | |
| 2593 | static struct uart_ops ioc4_ops = { |
| 2594 | .tx_empty = ic4_tx_empty, |
| 2595 | .set_mctrl = ic4_set_mctrl, |
| 2596 | .get_mctrl = ic4_get_mctrl, |
| 2597 | .stop_tx = ic4_stop_tx, |
| 2598 | .start_tx = ic4_start_tx, |
| 2599 | .stop_rx = null_void_function, |
| 2600 | .enable_ms = null_void_function, |
| 2601 | .break_ctl = ic4_break_ctl, |
| 2602 | .startup = ic4_startup, |
| 2603 | .shutdown = ic4_shutdown, |
| 2604 | .set_termios = ic4_set_termios, |
| 2605 | .type = ic4_type, |
| 2606 | .release_port = null_void_function, |
| 2607 | .request_port = ic4_request_port, |
| 2608 | }; |
| 2609 | |
| 2610 | /* |
| 2611 | * Boot-time initialization code |
| 2612 | */ |
| 2613 | |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 2614 | static struct uart_driver ioc4_uart_rs232 = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2615 | .owner = THIS_MODULE, |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 2616 | .driver_name = "ioc4_serial_rs232", |
| 2617 | .dev_name = DEVICE_NAME_RS232, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2618 | .major = DEVICE_MAJOR, |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 2619 | .minor = DEVICE_MINOR_RS232, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2620 | .nr = IOC4_NUM_CARDS * IOC4_NUM_SERIAL_PORTS, |
| 2621 | }; |
| 2622 | |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 2623 | static struct uart_driver ioc4_uart_rs422 = { |
| 2624 | .owner = THIS_MODULE, |
| 2625 | .driver_name = "ioc4_serial_rs422", |
| 2626 | .dev_name = DEVICE_NAME_RS422, |
| 2627 | .major = DEVICE_MAJOR, |
| 2628 | .minor = DEVICE_MINOR_RS422, |
| 2629 | .nr = IOC4_NUM_CARDS * IOC4_NUM_SERIAL_PORTS, |
| 2630 | }; |
| 2631 | |
| 2632 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2633 | /** |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 2634 | * ioc4_serial_remove_one - detach function |
| 2635 | * |
| 2636 | * @idd: IOC4 master module data for this IOC4 |
| 2637 | */ |
| 2638 | |
| 2639 | static int ioc4_serial_remove_one(struct ioc4_driver_data *idd) |
| 2640 | { |
| 2641 | int port_num, port_type; |
| 2642 | struct ioc4_control *control; |
| 2643 | struct uart_port *the_port; |
| 2644 | struct ioc4_port *port; |
| 2645 | struct ioc4_soft *soft; |
| 2646 | |
Brent Casavant | f5befce | 2006-06-23 02:05:52 -0700 | [diff] [blame] | 2647 | /* If serial driver did not attach, don't try to detach */ |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 2648 | control = idd->idd_serial_data; |
Brent Casavant | f5befce | 2006-06-23 02:05:52 -0700 | [diff] [blame] | 2649 | if (!control) |
| 2650 | return 0; |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 2651 | |
| 2652 | for (port_num = 0; port_num < IOC4_NUM_SERIAL_PORTS; port_num++) { |
| 2653 | for (port_type = UART_PORT_MIN; |
| 2654 | port_type < UART_PORT_COUNT; |
| 2655 | port_type++) { |
| 2656 | the_port = &control->ic_port[port_num].icp_uart_port |
| 2657 | [port_type]; |
| 2658 | if (the_port) { |
| 2659 | switch (port_type) { |
| 2660 | case UART_PORT_RS422: |
| 2661 | uart_remove_one_port(&ioc4_uart_rs422, |
| 2662 | the_port); |
| 2663 | break; |
| 2664 | default: |
| 2665 | case UART_PORT_RS232: |
| 2666 | uart_remove_one_port(&ioc4_uart_rs232, |
| 2667 | the_port); |
| 2668 | break; |
| 2669 | } |
| 2670 | } |
| 2671 | } |
| 2672 | port = control->ic_port[port_num].icp_port; |
| 2673 | /* we allocate in pairs */ |
| 2674 | if (!(port_num & 1) && port) { |
| 2675 | pci_free_consistent(port->ip_pdev, |
| 2676 | TOTAL_RING_BUF_SIZE, |
| 2677 | port->ip_cpu_ringbuf, |
| 2678 | port->ip_dma_ringbuf); |
| 2679 | kfree(port); |
| 2680 | } |
| 2681 | } |
| 2682 | soft = control->ic_soft; |
| 2683 | if (soft) { |
| 2684 | free_irq(control->ic_irq, soft); |
| 2685 | if (soft->is_ioc4_serial_addr) { |
Amol Lad | f466413 | 2006-09-30 23:29:21 -0700 | [diff] [blame] | 2686 | iounmap(soft->is_ioc4_serial_addr); |
Brent Casavant | 52c9ae0 | 2007-02-10 01:44:46 -0800 | [diff] [blame] | 2687 | release_mem_region((unsigned long) |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 2688 | soft->is_ioc4_serial_addr, |
| 2689 | sizeof(struct ioc4_serial)); |
| 2690 | } |
| 2691 | kfree(soft); |
| 2692 | } |
| 2693 | kfree(control); |
| 2694 | idd->idd_serial_data = NULL; |
| 2695 | |
| 2696 | return 0; |
| 2697 | } |
| 2698 | |
| 2699 | |
| 2700 | /** |
| 2701 | * ioc4_serial_core_attach_rs232 - register with serial core |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2702 | * This is done during pci probing |
| 2703 | * @pdev: handle for this card |
| 2704 | */ |
| 2705 | static inline int |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 2706 | ioc4_serial_core_attach(struct pci_dev *pdev, int port_type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2707 | { |
| 2708 | struct ioc4_port *port; |
| 2709 | struct uart_port *the_port; |
Brent Casavant | 22329b5 | 2005-06-21 17:15:59 -0700 | [diff] [blame] | 2710 | struct ioc4_driver_data *idd = pci_get_drvdata(pdev); |
| 2711 | struct ioc4_control *control = idd->idd_serial_data; |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 2712 | int port_num; |
| 2713 | int port_type_idx; |
| 2714 | struct uart_driver *u_driver; |
| 2715 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2716 | |
| 2717 | DPRINT_CONFIG(("%s: attach pdev 0x%p - control 0x%p\n", |
| 2718 | __FUNCTION__, pdev, (void *)control)); |
| 2719 | |
| 2720 | if (!control) |
| 2721 | return -ENODEV; |
| 2722 | |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 2723 | port_type_idx = (port_type == PROTO_RS232) ? UART_PORT_RS232 |
| 2724 | : UART_PORT_RS422; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2725 | |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 2726 | u_driver = (port_type == PROTO_RS232) ? &ioc4_uart_rs232 |
| 2727 | : &ioc4_uart_rs422; |
| 2728 | |
| 2729 | /* once around for each port on this card */ |
| 2730 | for (port_num = 0; port_num < IOC4_NUM_SERIAL_PORTS; port_num++) { |
| 2731 | the_port = &control->ic_port[port_num].icp_uart_port |
| 2732 | [port_type_idx]; |
| 2733 | port = control->ic_port[port_num].icp_port; |
| 2734 | port->ip_all_ports[port_type_idx] = the_port; |
| 2735 | |
| 2736 | DPRINT_CONFIG(("%s: attach the_port 0x%p / port 0x%p : type %s\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2737 | __FUNCTION__, (void *)the_port, |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 2738 | (void *)port, |
| 2739 | port_type == PROTO_RS232 ? "rs232" : "rs422")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2740 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2741 | /* membase, iobase and mapbase just need to be non-0 */ |
| 2742 | the_port->membase = (unsigned char __iomem *)1; |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 2743 | the_port->iobase = (pdev->bus->number << 16) | port_num; |
| 2744 | the_port->line = (Num_of_ioc4_cards << 2) | port_num; |
| 2745 | the_port->mapbase = port_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2746 | the_port->type = PORT_16550A; |
Pat Gefre | 396dc44 | 2005-10-30 15:02:49 -0800 | [diff] [blame] | 2747 | the_port->fifosize = IOC4_FIFO_CHARS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2748 | the_port->ops = &ioc4_ops; |
| 2749 | the_port->irq = control->ic_irq; |
| 2750 | the_port->dev = &pdev->dev; |
Pat Gefre | 396dc44 | 2005-10-30 15:02:49 -0800 | [diff] [blame] | 2751 | spin_lock_init(&the_port->lock); |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 2752 | if (uart_add_one_port(u_driver, the_port) < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2753 | printk(KERN_WARNING |
Pat Gefre | 396dc44 | 2005-10-30 15:02:49 -0800 | [diff] [blame] | 2754 | "%s: unable to add port %d bus %d\n", |
| 2755 | __FUNCTION__, the_port->line, pdev->bus->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2756 | } else { |
| 2757 | DPRINT_CONFIG( |
Pat Gefre | 396dc44 | 2005-10-30 15:02:49 -0800 | [diff] [blame] | 2758 | ("IOC4 serial port %d irq = %d, bus %d\n", |
| 2759 | the_port->line, the_port->irq, pdev->bus->number)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2760 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2761 | } |
| 2762 | return 0; |
| 2763 | } |
| 2764 | |
| 2765 | /** |
| 2766 | * ioc4_serial_attach_one - register attach function |
Brent Casavant | 22329b5 | 2005-06-21 17:15:59 -0700 | [diff] [blame] | 2767 | * called per card found from IOC4 master module. |
| 2768 | * @idd: Master module data for this IOC4 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2769 | */ |
| 2770 | int |
Brent Casavant | 22329b5 | 2005-06-21 17:15:59 -0700 | [diff] [blame] | 2771 | ioc4_serial_attach_one(struct ioc4_driver_data *idd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2772 | { |
Brent Casavant | 22329b5 | 2005-06-21 17:15:59 -0700 | [diff] [blame] | 2773 | unsigned long tmp_addr1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2774 | struct ioc4_serial __iomem *serial; |
| 2775 | struct ioc4_soft *soft; |
| 2776 | struct ioc4_control *control; |
Brent Casavant | 22329b5 | 2005-06-21 17:15:59 -0700 | [diff] [blame] | 2777 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2778 | |
| 2779 | |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 2780 | DPRINT_CONFIG(("%s (0x%p, 0x%p)\n", __FUNCTION__, idd->idd_pdev, |
| 2781 | idd->idd_pci_id)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2782 | |
Brent Casavant | f5befce | 2006-06-23 02:05:52 -0700 | [diff] [blame] | 2783 | /* PCI-RT does not bring out serial connections. |
| 2784 | * Do not attach to this particular IOC4. |
| 2785 | */ |
| 2786 | if (idd->idd_variant == IOC4_VARIANT_PCI_RT) |
| 2787 | return 0; |
| 2788 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2789 | /* request serial registers */ |
Brent Casavant | 22329b5 | 2005-06-21 17:15:59 -0700 | [diff] [blame] | 2790 | tmp_addr1 = idd->idd_bar0 + IOC4_SERIAL_OFFSET; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2791 | |
Brent Casavant | 52c9ae0 | 2007-02-10 01:44:46 -0800 | [diff] [blame] | 2792 | if (!request_mem_region(tmp_addr1, sizeof(struct ioc4_serial), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2793 | "sioc4_uart")) { |
| 2794 | printk(KERN_WARNING |
| 2795 | "ioc4 (%p): unable to get request region for " |
Brent Casavant | 22329b5 | 2005-06-21 17:15:59 -0700 | [diff] [blame] | 2796 | "uart space\n", (void *)idd->idd_pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2797 | ret = -ENODEV; |
| 2798 | goto out1; |
| 2799 | } |
| 2800 | serial = ioremap(tmp_addr1, sizeof(struct ioc4_serial)); |
| 2801 | if (!serial) { |
| 2802 | printk(KERN_WARNING |
| 2803 | "ioc4 (%p) : unable to remap ioc4 serial register\n", |
Brent Casavant | 22329b5 | 2005-06-21 17:15:59 -0700 | [diff] [blame] | 2804 | (void *)idd->idd_pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2805 | ret = -ENODEV; |
| 2806 | goto out2; |
| 2807 | } |
| 2808 | DPRINT_CONFIG(("%s : mem 0x%p, serial 0x%p\n", |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 2809 | __FUNCTION__, (void *)idd->idd_misc_regs, |
| 2810 | (void *)serial)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2811 | |
| 2812 | /* Get memory for the new card */ |
Burman Yan | 8f31bb3 | 2007-02-14 00:33:07 -0800 | [diff] [blame^] | 2813 | control = kzalloc(sizeof(struct ioc4_control), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2814 | |
| 2815 | if (!control) { |
| 2816 | printk(KERN_WARNING "ioc4_attach_one" |
| 2817 | ": unable to get memory for the IOC4\n"); |
| 2818 | ret = -ENOMEM; |
| 2819 | goto out2; |
| 2820 | } |
Brent Casavant | 22329b5 | 2005-06-21 17:15:59 -0700 | [diff] [blame] | 2821 | idd->idd_serial_data = control; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2822 | |
| 2823 | /* Allocate the soft structure */ |
Burman Yan | 8f31bb3 | 2007-02-14 00:33:07 -0800 | [diff] [blame^] | 2824 | soft = kzalloc(sizeof(struct ioc4_soft), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2825 | if (!soft) { |
| 2826 | printk(KERN_WARNING |
| 2827 | "ioc4 (%p): unable to get memory for the soft struct\n", |
Brent Casavant | 22329b5 | 2005-06-21 17:15:59 -0700 | [diff] [blame] | 2828 | (void *)idd->idd_pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2829 | ret = -ENOMEM; |
| 2830 | goto out3; |
| 2831 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2832 | |
| 2833 | spin_lock_init(&soft->is_ir_lock); |
Brent Casavant | 22329b5 | 2005-06-21 17:15:59 -0700 | [diff] [blame] | 2834 | soft->is_ioc4_misc_addr = idd->idd_misc_regs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2835 | soft->is_ioc4_serial_addr = serial; |
| 2836 | |
| 2837 | /* Init the IOC4 */ |
Brent Casavant | 22329b5 | 2005-06-21 17:15:59 -0700 | [diff] [blame] | 2838 | writel(0xf << IOC4_SIO_CR_CMD_PULSE_SHIFT, |
| 2839 | &idd->idd_misc_regs->sio_cr.raw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2840 | |
| 2841 | /* Enable serial port mode select generic PIO pins as outputs */ |
| 2842 | writel(IOC4_GPCR_UART0_MODESEL | IOC4_GPCR_UART1_MODESEL |
| 2843 | | IOC4_GPCR_UART2_MODESEL | IOC4_GPCR_UART3_MODESEL, |
Brent Casavant | 22329b5 | 2005-06-21 17:15:59 -0700 | [diff] [blame] | 2844 | &idd->idd_misc_regs->gpcr_s.raw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2845 | |
Brent Casavant | 22329b5 | 2005-06-21 17:15:59 -0700 | [diff] [blame] | 2846 | /* Clear and disable all serial interrupts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2847 | write_ireg(soft, ~0, IOC4_W_IEC, IOC4_SIO_INTR_TYPE); |
Brent Casavant | 22329b5 | 2005-06-21 17:15:59 -0700 | [diff] [blame] | 2848 | writel(~0, &idd->idd_misc_regs->sio_ir.raw); |
| 2849 | write_ireg(soft, IOC4_OTHER_IR_SER_MEMERR, IOC4_W_IEC, |
| 2850 | IOC4_OTHER_INTR_TYPE); |
| 2851 | writel(IOC4_OTHER_IR_SER_MEMERR, &idd->idd_misc_regs->other_ir.raw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2852 | control->ic_soft = soft; |
Brent Casavant | 22329b5 | 2005-06-21 17:15:59 -0700 | [diff] [blame] | 2853 | |
| 2854 | /* Hook up interrupt handler */ |
Thomas Gleixner | 40663cc | 2006-07-01 19:29:43 -0700 | [diff] [blame] | 2855 | if (!request_irq(idd->idd_pdev->irq, ioc4_intr, IRQF_SHARED, |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 2856 | "sgi-ioc4serial", soft)) { |
Brent Casavant | 22329b5 | 2005-06-21 17:15:59 -0700 | [diff] [blame] | 2857 | control->ic_irq = idd->idd_pdev->irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2858 | } else { |
| 2859 | printk(KERN_WARNING |
| 2860 | "%s : request_irq fails for IRQ 0x%x\n ", |
Brent Casavant | 22329b5 | 2005-06-21 17:15:59 -0700 | [diff] [blame] | 2861 | __FUNCTION__, idd->idd_pdev->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2862 | } |
Brent Casavant | d4c477c | 2005-06-21 17:16:01 -0700 | [diff] [blame] | 2863 | ret = ioc4_attach_local(idd); |
| 2864 | if (ret) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2865 | goto out4; |
| 2866 | |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 2867 | /* register port with the serial core - 1 rs232, 1 rs422 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2868 | |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 2869 | if ((ret = ioc4_serial_core_attach(idd->idd_pdev, PROTO_RS232))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2870 | goto out4; |
| 2871 | |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 2872 | if ((ret = ioc4_serial_core_attach(idd->idd_pdev, PROTO_RS422))) |
| 2873 | goto out5; |
| 2874 | |
Pat Gefre | 396dc44 | 2005-10-30 15:02:49 -0800 | [diff] [blame] | 2875 | Num_of_ioc4_cards++; |
| 2876 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2877 | return ret; |
| 2878 | |
| 2879 | /* error exits that give back resources */ |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 2880 | out5: |
| 2881 | ioc4_serial_remove_one(idd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2882 | out4: |
| 2883 | kfree(soft); |
| 2884 | out3: |
| 2885 | kfree(control); |
| 2886 | out2: |
Amol Lad | f466413 | 2006-09-30 23:29:21 -0700 | [diff] [blame] | 2887 | if (serial) |
| 2888 | iounmap(serial); |
Brent Casavant | 52c9ae0 | 2007-02-10 01:44:46 -0800 | [diff] [blame] | 2889 | release_mem_region(tmp_addr1, sizeof(struct ioc4_serial)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2890 | out1: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2891 | |
| 2892 | return ret; |
| 2893 | } |
| 2894 | |
| 2895 | |
Brent Casavant | 22329b5 | 2005-06-21 17:15:59 -0700 | [diff] [blame] | 2896 | static struct ioc4_submodule ioc4_serial_submodule = { |
| 2897 | .is_name = "IOC4_serial", |
| 2898 | .is_owner = THIS_MODULE, |
| 2899 | .is_probe = ioc4_serial_attach_one, |
| 2900 | .is_remove = ioc4_serial_remove_one, |
| 2901 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2902 | |
| 2903 | /** |
| 2904 | * ioc4_serial_init - module init |
| 2905 | */ |
| 2906 | int ioc4_serial_init(void) |
| 2907 | { |
| 2908 | int ret; |
| 2909 | |
| 2910 | /* register with serial core */ |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 2911 | if ((ret = uart_register_driver(&ioc4_uart_rs232)) < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2912 | printk(KERN_WARNING |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 2913 | "%s: Couldn't register rs232 IOC4 serial driver\n", |
| 2914 | __FUNCTION__); |
| 2915 | return ret; |
| 2916 | } |
| 2917 | if ((ret = uart_register_driver(&ioc4_uart_rs422)) < 0) { |
| 2918 | printk(KERN_WARNING |
| 2919 | "%s: Couldn't register rs422 IOC4 serial driver\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2920 | __FUNCTION__); |
| 2921 | return ret; |
| 2922 | } |
Brent Casavant | 22329b5 | 2005-06-21 17:15:59 -0700 | [diff] [blame] | 2923 | |
| 2924 | /* register with IOC4 main module */ |
| 2925 | return ioc4_register_submodule(&ioc4_serial_submodule); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2926 | } |
| 2927 | |
Brent Casavant | 22329b5 | 2005-06-21 17:15:59 -0700 | [diff] [blame] | 2928 | static void __devexit ioc4_serial_exit(void) |
| 2929 | { |
| 2930 | ioc4_unregister_submodule(&ioc4_serial_submodule); |
Pat Gefre | 64b9137 | 2006-03-25 03:08:07 -0800 | [diff] [blame] | 2931 | uart_unregister_driver(&ioc4_uart_rs232); |
| 2932 | uart_unregister_driver(&ioc4_uart_rs422); |
Brent Casavant | 22329b5 | 2005-06-21 17:15:59 -0700 | [diff] [blame] | 2933 | } |
| 2934 | |
Brent Casavant | 59f1480 | 2006-10-17 00:09:25 -0700 | [diff] [blame] | 2935 | late_initcall(ioc4_serial_init); /* Call only after tty init is done */ |
Brent Casavant | 22329b5 | 2005-06-21 17:15:59 -0700 | [diff] [blame] | 2936 | module_exit(ioc4_serial_exit); |
| 2937 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2938 | MODULE_AUTHOR("Pat Gefre - Silicon Graphics Inc. (SGI) <pfg@sgi.com>"); |
| 2939 | MODULE_DESCRIPTION("Serial PCI driver module for SGI IOC4 Base-IO Card"); |
| 2940 | MODULE_LICENSE("GPL"); |