Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * Generic driver for the MPSC (UART mode) on Marvell parts (e.g., GT64240, |
| 3 | * GT64260, MV64340, MV64360, GT96100, ... ). |
| 4 | * |
| 5 | * Author: Mark A. Greer <mgreer@mvista.com> |
| 6 | * |
| 7 | * Based on an old MPSC driver that was in the linuxppc tree. It appears to |
| 8 | * have been created by Chris Zankel (formerly of MontaVista) but there |
| 9 | * is no proper Copyright so I'm not sure. Apparently, parts were also |
| 10 | * taken from PPCBoot (now U-Boot). Also based on drivers/serial/8250.c |
| 11 | * by Russell King. |
| 12 | * |
| 13 | * 2004 (c) MontaVista, Software, Inc. This file is licensed under |
| 14 | * the terms of the GNU General Public License version 2. This program |
| 15 | * is licensed "as is" without any warranty of any kind, whether express |
| 16 | * or implied. |
| 17 | */ |
| 18 | /* |
| 19 | * The MPSC interface is much like a typical network controller's interface. |
| 20 | * That is, you set up separate rings of descriptors for transmitting and |
| 21 | * receiving data. There is also a pool of buffers with (one buffer per |
| 22 | * descriptor) that incoming data are dma'd into or outgoing data are dma'd |
| 23 | * out of. |
| 24 | * |
| 25 | * The MPSC requires two other controllers to be able to work. The Baud Rate |
| 26 | * Generator (BRG) provides a clock at programmable frequencies which determines |
| 27 | * the baud rate. The Serial DMA Controller (SDMA) takes incoming data from the |
| 28 | * MPSC and DMA's it into memory or DMA's outgoing data and passes it to the |
| 29 | * MPSC. It is actually the SDMA interrupt that the driver uses to keep the |
| 30 | * transmit and receive "engines" going (i.e., indicate data has been |
| 31 | * transmitted or received). |
| 32 | * |
| 33 | * NOTES: |
| 34 | * |
| 35 | * 1) Some chips have an erratum where several regs cannot be |
| 36 | * read. To work around that, we keep a local copy of those regs in |
| 37 | * 'mpsc_port_info'. |
| 38 | * |
| 39 | * 2) Some chips have an erratum where the ctlr will hang when the SDMA ctlr |
| 40 | * accesses system mem with coherency enabled. For that reason, the driver |
| 41 | * assumes that coherency for that ctlr has been disabled. This means |
| 42 | * that when in a cache coherent system, the driver has to manually manage |
| 43 | * the data cache on the areas that it touches because the dma_* macro are |
| 44 | * basically no-ops. |
| 45 | * |
| 46 | * 3) There is an erratum (on PPC) where you can't use the instruction to do |
| 47 | * a DMA_TO_DEVICE/cache clean so DMA_BIDIRECTIONAL/flushes are used in places |
| 48 | * where a DMA_TO_DEVICE/clean would have [otherwise] sufficed. |
| 49 | * |
| 50 | * 4) AFAICT, hardware flow control isn't supported by the controller --MAG. |
| 51 | */ |
| 52 | |
Mark A. Greer | e4294b3 | 2006-03-25 03:08:28 -0800 | [diff] [blame] | 53 | |
| 54 | #if defined(CONFIG_SERIAL_MPSC_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) |
| 55 | #define SUPPORT_SYSRQ |
| 56 | #endif |
| 57 | |
| 58 | #include <linux/module.h> |
| 59 | #include <linux/moduleparam.h> |
| 60 | #include <linux/tty.h> |
| 61 | #include <linux/tty_flip.h> |
| 62 | #include <linux/ioport.h> |
| 63 | #include <linux/init.h> |
| 64 | #include <linux/console.h> |
| 65 | #include <linux/sysrq.h> |
| 66 | #include <linux/serial.h> |
| 67 | #include <linux/serial_core.h> |
| 68 | #include <linux/delay.h> |
| 69 | #include <linux/device.h> |
| 70 | #include <linux/dma-mapping.h> |
| 71 | #include <linux/mv643xx.h> |
Russell King | d052d1b | 2005-10-29 19:07:23 +0100 | [diff] [blame] | 72 | #include <linux/platform_device.h> |
| 73 | |
Mark A. Greer | e4294b3 | 2006-03-25 03:08:28 -0800 | [diff] [blame] | 74 | #include <asm/io.h> |
| 75 | #include <asm/irq.h> |
| 76 | |
Mark A. Greer | e4294b3 | 2006-03-25 03:08:28 -0800 | [diff] [blame] | 77 | #define MPSC_NUM_CTLRS 2 |
| 78 | |
| 79 | /* |
| 80 | * Descriptors and buffers must be cache line aligned. |
| 81 | * Buffers lengths must be multiple of cache line size. |
| 82 | * Number of Tx & Rx descriptors must be powers of 2. |
| 83 | */ |
| 84 | #define MPSC_RXR_ENTRIES 32 |
| 85 | #define MPSC_RXRE_SIZE dma_get_cache_alignment() |
| 86 | #define MPSC_RXR_SIZE (MPSC_RXR_ENTRIES * MPSC_RXRE_SIZE) |
| 87 | #define MPSC_RXBE_SIZE dma_get_cache_alignment() |
| 88 | #define MPSC_RXB_SIZE (MPSC_RXR_ENTRIES * MPSC_RXBE_SIZE) |
| 89 | |
| 90 | #define MPSC_TXR_ENTRIES 32 |
| 91 | #define MPSC_TXRE_SIZE dma_get_cache_alignment() |
| 92 | #define MPSC_TXR_SIZE (MPSC_TXR_ENTRIES * MPSC_TXRE_SIZE) |
| 93 | #define MPSC_TXBE_SIZE dma_get_cache_alignment() |
| 94 | #define MPSC_TXB_SIZE (MPSC_TXR_ENTRIES * MPSC_TXBE_SIZE) |
| 95 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 96 | #define MPSC_DMA_ALLOC_SIZE (MPSC_RXR_SIZE + MPSC_RXB_SIZE + MPSC_TXR_SIZE \ |
| 97 | + MPSC_TXB_SIZE + dma_get_cache_alignment() /* for alignment */) |
Mark A. Greer | e4294b3 | 2006-03-25 03:08:28 -0800 | [diff] [blame] | 98 | |
| 99 | /* Rx and Tx Ring entry descriptors -- assume entry size is <= cacheline size */ |
| 100 | struct mpsc_rx_desc { |
| 101 | u16 bufsize; |
| 102 | u16 bytecnt; |
| 103 | u32 cmdstat; |
| 104 | u32 link; |
| 105 | u32 buf_ptr; |
| 106 | } __attribute((packed)); |
| 107 | |
| 108 | struct mpsc_tx_desc { |
| 109 | u16 bytecnt; |
| 110 | u16 shadow; |
| 111 | u32 cmdstat; |
| 112 | u32 link; |
| 113 | u32 buf_ptr; |
| 114 | } __attribute((packed)); |
| 115 | |
| 116 | /* |
| 117 | * Some regs that have the erratum that you can't read them are are shared |
| 118 | * between the two MPSC controllers. This struct contains those shared regs. |
| 119 | */ |
| 120 | struct mpsc_shared_regs { |
| 121 | phys_addr_t mpsc_routing_base_p; |
| 122 | phys_addr_t sdma_intr_base_p; |
| 123 | |
| 124 | void __iomem *mpsc_routing_base; |
| 125 | void __iomem *sdma_intr_base; |
| 126 | |
| 127 | u32 MPSC_MRR_m; |
| 128 | u32 MPSC_RCRR_m; |
| 129 | u32 MPSC_TCRR_m; |
| 130 | u32 SDMA_INTR_CAUSE_m; |
| 131 | u32 SDMA_INTR_MASK_m; |
| 132 | }; |
| 133 | |
| 134 | /* The main driver data structure */ |
| 135 | struct mpsc_port_info { |
| 136 | struct uart_port port; /* Overlay uart_port structure */ |
| 137 | |
| 138 | /* Internal driver state for this ctlr */ |
| 139 | u8 ready; |
| 140 | u8 rcv_data; |
| 141 | tcflag_t c_iflag; /* save termios->c_iflag */ |
| 142 | tcflag_t c_cflag; /* save termios->c_cflag */ |
| 143 | |
| 144 | /* Info passed in from platform */ |
| 145 | u8 mirror_regs; /* Need to mirror regs? */ |
| 146 | u8 cache_mgmt; /* Need manual cache mgmt? */ |
| 147 | u8 brg_can_tune; /* BRG has baud tuning? */ |
| 148 | u32 brg_clk_src; |
| 149 | u16 mpsc_max_idle; |
| 150 | int default_baud; |
| 151 | int default_bits; |
| 152 | int default_parity; |
| 153 | int default_flow; |
| 154 | |
| 155 | /* Physical addresses of various blocks of registers (from platform) */ |
| 156 | phys_addr_t mpsc_base_p; |
| 157 | phys_addr_t sdma_base_p; |
| 158 | phys_addr_t brg_base_p; |
| 159 | |
| 160 | /* Virtual addresses of various blocks of registers (from platform) */ |
| 161 | void __iomem *mpsc_base; |
| 162 | void __iomem *sdma_base; |
| 163 | void __iomem *brg_base; |
| 164 | |
| 165 | /* Descriptor ring and buffer allocations */ |
| 166 | void *dma_region; |
| 167 | dma_addr_t dma_region_p; |
| 168 | |
| 169 | dma_addr_t rxr; /* Rx descriptor ring */ |
| 170 | dma_addr_t rxr_p; /* Phys addr of rxr */ |
| 171 | u8 *rxb; /* Rx Ring I/O buf */ |
| 172 | u8 *rxb_p; /* Phys addr of rxb */ |
| 173 | u32 rxr_posn; /* First desc w/ Rx data */ |
| 174 | |
| 175 | dma_addr_t txr; /* Tx descriptor ring */ |
| 176 | dma_addr_t txr_p; /* Phys addr of txr */ |
| 177 | u8 *txb; /* Tx Ring I/O buf */ |
| 178 | u8 *txb_p; /* Phys addr of txb */ |
| 179 | int txr_head; /* Where new data goes */ |
| 180 | int txr_tail; /* Where sent data comes off */ |
Dave Jiang | 1733310 | 2007-05-06 14:48:50 -0700 | [diff] [blame] | 181 | spinlock_t tx_lock; /* transmit lock */ |
Mark A. Greer | e4294b3 | 2006-03-25 03:08:28 -0800 | [diff] [blame] | 182 | |
| 183 | /* Mirrored values of regs we can't read (if 'mirror_regs' set) */ |
| 184 | u32 MPSC_MPCR_m; |
| 185 | u32 MPSC_CHR_1_m; |
| 186 | u32 MPSC_CHR_2_m; |
| 187 | u32 MPSC_CHR_10_m; |
| 188 | u32 BRG_BCR_m; |
| 189 | struct mpsc_shared_regs *shared_regs; |
| 190 | }; |
| 191 | |
| 192 | /* Hooks to platform-specific code */ |
| 193 | int mpsc_platform_register_driver(void); |
| 194 | void mpsc_platform_unregister_driver(void); |
| 195 | |
| 196 | /* Hooks back in to mpsc common to be called by platform-specific code */ |
| 197 | struct mpsc_port_info *mpsc_device_probe(int index); |
| 198 | struct mpsc_port_info *mpsc_device_remove(int index); |
| 199 | |
| 200 | /* Main MPSC Configuration Register Offsets */ |
| 201 | #define MPSC_MMCRL 0x0000 |
| 202 | #define MPSC_MMCRH 0x0004 |
| 203 | #define MPSC_MPCR 0x0008 |
| 204 | #define MPSC_CHR_1 0x000c |
| 205 | #define MPSC_CHR_2 0x0010 |
| 206 | #define MPSC_CHR_3 0x0014 |
| 207 | #define MPSC_CHR_4 0x0018 |
| 208 | #define MPSC_CHR_5 0x001c |
| 209 | #define MPSC_CHR_6 0x0020 |
| 210 | #define MPSC_CHR_7 0x0024 |
| 211 | #define MPSC_CHR_8 0x0028 |
| 212 | #define MPSC_CHR_9 0x002c |
| 213 | #define MPSC_CHR_10 0x0030 |
| 214 | #define MPSC_CHR_11 0x0034 |
| 215 | |
| 216 | #define MPSC_MPCR_FRZ (1 << 9) |
| 217 | #define MPSC_MPCR_CL_5 0 |
| 218 | #define MPSC_MPCR_CL_6 1 |
| 219 | #define MPSC_MPCR_CL_7 2 |
| 220 | #define MPSC_MPCR_CL_8 3 |
| 221 | #define MPSC_MPCR_SBL_1 0 |
| 222 | #define MPSC_MPCR_SBL_2 1 |
| 223 | |
| 224 | #define MPSC_CHR_2_TEV (1<<1) |
| 225 | #define MPSC_CHR_2_TA (1<<7) |
| 226 | #define MPSC_CHR_2_TTCS (1<<9) |
| 227 | #define MPSC_CHR_2_REV (1<<17) |
| 228 | #define MPSC_CHR_2_RA (1<<23) |
| 229 | #define MPSC_CHR_2_CRD (1<<25) |
| 230 | #define MPSC_CHR_2_EH (1<<31) |
| 231 | #define MPSC_CHR_2_PAR_ODD 0 |
| 232 | #define MPSC_CHR_2_PAR_SPACE 1 |
| 233 | #define MPSC_CHR_2_PAR_EVEN 2 |
| 234 | #define MPSC_CHR_2_PAR_MARK 3 |
| 235 | |
| 236 | /* MPSC Signal Routing */ |
| 237 | #define MPSC_MRR 0x0000 |
| 238 | #define MPSC_RCRR 0x0004 |
| 239 | #define MPSC_TCRR 0x0008 |
| 240 | |
| 241 | /* Serial DMA Controller Interface Registers */ |
| 242 | #define SDMA_SDC 0x0000 |
| 243 | #define SDMA_SDCM 0x0008 |
| 244 | #define SDMA_RX_DESC 0x0800 |
| 245 | #define SDMA_RX_BUF_PTR 0x0808 |
| 246 | #define SDMA_SCRDP 0x0810 |
| 247 | #define SDMA_TX_DESC 0x0c00 |
| 248 | #define SDMA_SCTDP 0x0c10 |
| 249 | #define SDMA_SFTDP 0x0c14 |
| 250 | |
| 251 | #define SDMA_DESC_CMDSTAT_PE (1<<0) |
| 252 | #define SDMA_DESC_CMDSTAT_CDL (1<<1) |
| 253 | #define SDMA_DESC_CMDSTAT_FR (1<<3) |
| 254 | #define SDMA_DESC_CMDSTAT_OR (1<<6) |
| 255 | #define SDMA_DESC_CMDSTAT_BR (1<<9) |
| 256 | #define SDMA_DESC_CMDSTAT_MI (1<<10) |
| 257 | #define SDMA_DESC_CMDSTAT_A (1<<11) |
| 258 | #define SDMA_DESC_CMDSTAT_AM (1<<12) |
| 259 | #define SDMA_DESC_CMDSTAT_CT (1<<13) |
| 260 | #define SDMA_DESC_CMDSTAT_C (1<<14) |
| 261 | #define SDMA_DESC_CMDSTAT_ES (1<<15) |
| 262 | #define SDMA_DESC_CMDSTAT_L (1<<16) |
| 263 | #define SDMA_DESC_CMDSTAT_F (1<<17) |
| 264 | #define SDMA_DESC_CMDSTAT_P (1<<18) |
| 265 | #define SDMA_DESC_CMDSTAT_EI (1<<23) |
| 266 | #define SDMA_DESC_CMDSTAT_O (1<<31) |
| 267 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 268 | #define SDMA_DESC_DFLT (SDMA_DESC_CMDSTAT_O \ |
| 269 | | SDMA_DESC_CMDSTAT_EI) |
Mark A. Greer | e4294b3 | 2006-03-25 03:08:28 -0800 | [diff] [blame] | 270 | |
| 271 | #define SDMA_SDC_RFT (1<<0) |
| 272 | #define SDMA_SDC_SFM (1<<1) |
| 273 | #define SDMA_SDC_BLMR (1<<6) |
| 274 | #define SDMA_SDC_BLMT (1<<7) |
| 275 | #define SDMA_SDC_POVR (1<<8) |
| 276 | #define SDMA_SDC_RIFB (1<<9) |
| 277 | |
| 278 | #define SDMA_SDCM_ERD (1<<7) |
| 279 | #define SDMA_SDCM_AR (1<<15) |
| 280 | #define SDMA_SDCM_STD (1<<16) |
| 281 | #define SDMA_SDCM_TXD (1<<23) |
| 282 | #define SDMA_SDCM_AT (1<<31) |
| 283 | |
| 284 | #define SDMA_0_CAUSE_RXBUF (1<<0) |
| 285 | #define SDMA_0_CAUSE_RXERR (1<<1) |
| 286 | #define SDMA_0_CAUSE_TXBUF (1<<2) |
| 287 | #define SDMA_0_CAUSE_TXEND (1<<3) |
| 288 | #define SDMA_1_CAUSE_RXBUF (1<<8) |
| 289 | #define SDMA_1_CAUSE_RXERR (1<<9) |
| 290 | #define SDMA_1_CAUSE_TXBUF (1<<10) |
| 291 | #define SDMA_1_CAUSE_TXEND (1<<11) |
| 292 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 293 | #define SDMA_CAUSE_RX_MASK (SDMA_0_CAUSE_RXBUF | SDMA_0_CAUSE_RXERR \ |
| 294 | | SDMA_1_CAUSE_RXBUF | SDMA_1_CAUSE_RXERR) |
| 295 | #define SDMA_CAUSE_TX_MASK (SDMA_0_CAUSE_TXBUF | SDMA_0_CAUSE_TXEND \ |
| 296 | | SDMA_1_CAUSE_TXBUF | SDMA_1_CAUSE_TXEND) |
Mark A. Greer | e4294b3 | 2006-03-25 03:08:28 -0800 | [diff] [blame] | 297 | |
| 298 | /* SDMA Interrupt registers */ |
| 299 | #define SDMA_INTR_CAUSE 0x0000 |
| 300 | #define SDMA_INTR_MASK 0x0080 |
| 301 | |
| 302 | /* Baud Rate Generator Interface Registers */ |
| 303 | #define BRG_BCR 0x0000 |
| 304 | #define BRG_BTR 0x0004 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | |
| 306 | /* |
| 307 | * Define how this driver is known to the outside (we've been assigned a |
| 308 | * range on the "Low-density serial ports" major). |
| 309 | */ |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 310 | #define MPSC_MAJOR 204 |
| 311 | #define MPSC_MINOR_START 44 |
| 312 | #define MPSC_DRIVER_NAME "MPSC" |
| 313 | #define MPSC_DEV_NAME "ttyMM" |
| 314 | #define MPSC_VERSION "1.00" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | |
| 316 | static struct mpsc_port_info mpsc_ports[MPSC_NUM_CTLRS]; |
| 317 | static struct mpsc_shared_regs mpsc_shared_regs; |
Lee Nicks | 4d0145a | 2005-06-25 14:55:36 -0700 | [diff] [blame] | 318 | static struct uart_driver mpsc_reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | |
Lee Nicks | 4d0145a | 2005-06-25 14:55:36 -0700 | [diff] [blame] | 320 | static void mpsc_start_rx(struct mpsc_port_info *pi); |
| 321 | static void mpsc_free_ring_mem(struct mpsc_port_info *pi); |
| 322 | static void mpsc_release_port(struct uart_port *port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | /* |
| 324 | ****************************************************************************** |
| 325 | * |
| 326 | * Baud Rate Generator Routines (BRG) |
| 327 | * |
| 328 | ****************************************************************************** |
| 329 | */ |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 330 | static void mpsc_brg_init(struct mpsc_port_info *pi, u32 clk_src) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | { |
| 332 | u32 v; |
| 333 | |
| 334 | v = (pi->mirror_regs) ? pi->BRG_BCR_m : readl(pi->brg_base + BRG_BCR); |
| 335 | v = (v & ~(0xf << 18)) | ((clk_src & 0xf) << 18); |
| 336 | |
| 337 | if (pi->brg_can_tune) |
| 338 | v &= ~(1 << 25); |
| 339 | |
| 340 | if (pi->mirror_regs) |
| 341 | pi->BRG_BCR_m = v; |
| 342 | writel(v, pi->brg_base + BRG_BCR); |
| 343 | |
| 344 | writel(readl(pi->brg_base + BRG_BTR) & 0xffff0000, |
| 345 | pi->brg_base + BRG_BTR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | } |
| 347 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 348 | static void mpsc_brg_enable(struct mpsc_port_info *pi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | { |
| 350 | u32 v; |
| 351 | |
| 352 | v = (pi->mirror_regs) ? pi->BRG_BCR_m : readl(pi->brg_base + BRG_BCR); |
| 353 | v |= (1 << 16); |
| 354 | |
| 355 | if (pi->mirror_regs) |
| 356 | pi->BRG_BCR_m = v; |
| 357 | writel(v, pi->brg_base + BRG_BCR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | } |
| 359 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 360 | static void mpsc_brg_disable(struct mpsc_port_info *pi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | { |
| 362 | u32 v; |
| 363 | |
| 364 | v = (pi->mirror_regs) ? pi->BRG_BCR_m : readl(pi->brg_base + BRG_BCR); |
| 365 | v &= ~(1 << 16); |
| 366 | |
| 367 | if (pi->mirror_regs) |
| 368 | pi->BRG_BCR_m = v; |
| 369 | writel(v, pi->brg_base + BRG_BCR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | } |
| 371 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 372 | /* |
| 373 | * To set the baud, we adjust the CDV field in the BRG_BCR reg. |
| 374 | * From manual: Baud = clk / ((CDV+1)*2) ==> CDV = (clk / (baud*2)) - 1. |
| 375 | * However, the input clock is divided by 16 in the MPSC b/c of how |
| 376 | * 'MPSC_MMCRH' was set up so we have to divide the 'clk' used in our |
| 377 | * calculation by 16 to account for that. So the real calculation |
| 378 | * that accounts for the way the mpsc is set up is: |
| 379 | * CDV = (clk / (baud*2*16)) - 1 ==> CDV = (clk / (baud << 5)) - 1. |
| 380 | */ |
| 381 | static void mpsc_set_baudrate(struct mpsc_port_info *pi, u32 baud) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | u32 cdv = (pi->port.uartclk / (baud << 5)) - 1; |
| 384 | u32 v; |
| 385 | |
| 386 | mpsc_brg_disable(pi); |
| 387 | v = (pi->mirror_regs) ? pi->BRG_BCR_m : readl(pi->brg_base + BRG_BCR); |
| 388 | v = (v & 0xffff0000) | (cdv & 0xffff); |
| 389 | |
| 390 | if (pi->mirror_regs) |
| 391 | pi->BRG_BCR_m = v; |
| 392 | writel(v, pi->brg_base + BRG_BCR); |
| 393 | mpsc_brg_enable(pi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | /* |
| 397 | ****************************************************************************** |
| 398 | * |
| 399 | * Serial DMA Routines (SDMA) |
| 400 | * |
| 401 | ****************************************************************************** |
| 402 | */ |
| 403 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 404 | static void mpsc_sdma_burstsize(struct mpsc_port_info *pi, u32 burst_size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | { |
| 406 | u32 v; |
| 407 | |
| 408 | pr_debug("mpsc_sdma_burstsize[%d]: burst_size: %d\n", |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 409 | pi->port.line, burst_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | |
| 411 | burst_size >>= 3; /* Divide by 8 b/c reg values are 8-byte chunks */ |
| 412 | |
| 413 | if (burst_size < 2) |
| 414 | v = 0x0; /* 1 64-bit word */ |
| 415 | else if (burst_size < 4) |
| 416 | v = 0x1; /* 2 64-bit words */ |
| 417 | else if (burst_size < 8) |
| 418 | v = 0x2; /* 4 64-bit words */ |
| 419 | else |
| 420 | v = 0x3; /* 8 64-bit words */ |
| 421 | |
| 422 | writel((readl(pi->sdma_base + SDMA_SDC) & (0x3 << 12)) | (v << 12), |
| 423 | pi->sdma_base + SDMA_SDC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | } |
| 425 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 426 | static void mpsc_sdma_init(struct mpsc_port_info *pi, u32 burst_size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | { |
| 428 | pr_debug("mpsc_sdma_init[%d]: burst_size: %d\n", pi->port.line, |
| 429 | burst_size); |
| 430 | |
| 431 | writel((readl(pi->sdma_base + SDMA_SDC) & 0x3ff) | 0x03f, |
| 432 | pi->sdma_base + SDMA_SDC); |
| 433 | mpsc_sdma_burstsize(pi, burst_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | } |
| 435 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 436 | static u32 mpsc_sdma_intr_mask(struct mpsc_port_info *pi, u32 mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | { |
| 438 | u32 old, v; |
| 439 | |
| 440 | pr_debug("mpsc_sdma_intr_mask[%d]: mask: 0x%x\n", pi->port.line, mask); |
| 441 | |
| 442 | old = v = (pi->mirror_regs) ? pi->shared_regs->SDMA_INTR_MASK_m : |
| 443 | readl(pi->shared_regs->sdma_intr_base + SDMA_INTR_MASK); |
| 444 | |
| 445 | mask &= 0xf; |
| 446 | if (pi->port.line) |
| 447 | mask <<= 8; |
| 448 | v &= ~mask; |
| 449 | |
| 450 | if (pi->mirror_regs) |
| 451 | pi->shared_regs->SDMA_INTR_MASK_m = v; |
| 452 | writel(v, pi->shared_regs->sdma_intr_base + SDMA_INTR_MASK); |
| 453 | |
| 454 | if (pi->port.line) |
| 455 | old >>= 8; |
| 456 | return old & 0xf; |
| 457 | } |
| 458 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 459 | static void mpsc_sdma_intr_unmask(struct mpsc_port_info *pi, u32 mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | { |
| 461 | u32 v; |
| 462 | |
| 463 | pr_debug("mpsc_sdma_intr_unmask[%d]: mask: 0x%x\n", pi->port.line,mask); |
| 464 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 465 | v = (pi->mirror_regs) ? pi->shared_regs->SDMA_INTR_MASK_m |
| 466 | : readl(pi->shared_regs->sdma_intr_base + SDMA_INTR_MASK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | |
| 468 | mask &= 0xf; |
| 469 | if (pi->port.line) |
| 470 | mask <<= 8; |
| 471 | v |= mask; |
| 472 | |
| 473 | if (pi->mirror_regs) |
| 474 | pi->shared_regs->SDMA_INTR_MASK_m = v; |
| 475 | writel(v, pi->shared_regs->sdma_intr_base + SDMA_INTR_MASK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | } |
| 477 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 478 | static void mpsc_sdma_intr_ack(struct mpsc_port_info *pi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | { |
| 480 | pr_debug("mpsc_sdma_intr_ack[%d]: Acknowledging IRQ\n", pi->port.line); |
| 481 | |
| 482 | if (pi->mirror_regs) |
| 483 | pi->shared_regs->SDMA_INTR_CAUSE_m = 0; |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 484 | writeb(0x00, pi->shared_regs->sdma_intr_base + SDMA_INTR_CAUSE |
| 485 | + pi->port.line); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | } |
| 487 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 488 | static void mpsc_sdma_set_rx_ring(struct mpsc_port_info *pi, |
| 489 | struct mpsc_rx_desc *rxre_p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | { |
| 491 | pr_debug("mpsc_sdma_set_rx_ring[%d]: rxre_p: 0x%x\n", |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 492 | pi->port.line, (u32)rxre_p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | |
| 494 | writel((u32)rxre_p, pi->sdma_base + SDMA_SCRDP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | } |
| 496 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 497 | static void mpsc_sdma_set_tx_ring(struct mpsc_port_info *pi, |
| 498 | struct mpsc_tx_desc *txre_p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | { |
| 500 | writel((u32)txre_p, pi->sdma_base + SDMA_SFTDP); |
| 501 | writel((u32)txre_p, pi->sdma_base + SDMA_SCTDP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | } |
| 503 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 504 | static void mpsc_sdma_cmd(struct mpsc_port_info *pi, u32 val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | { |
| 506 | u32 v; |
| 507 | |
| 508 | v = readl(pi->sdma_base + SDMA_SDCM); |
| 509 | if (val) |
| 510 | v |= val; |
| 511 | else |
| 512 | v = 0; |
| 513 | wmb(); |
| 514 | writel(v, pi->sdma_base + SDMA_SDCM); |
| 515 | wmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | } |
| 517 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 518 | static uint mpsc_sdma_tx_active(struct mpsc_port_info *pi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | { |
| 520 | return readl(pi->sdma_base + SDMA_SDCM) & SDMA_SDCM_TXD; |
| 521 | } |
| 522 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 523 | static void mpsc_sdma_start_tx(struct mpsc_port_info *pi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | { |
| 525 | struct mpsc_tx_desc *txre, *txre_p; |
| 526 | |
| 527 | /* If tx isn't running & there's a desc ready to go, start it */ |
| 528 | if (!mpsc_sdma_tx_active(pi)) { |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 529 | txre = (struct mpsc_tx_desc *)(pi->txr |
| 530 | + (pi->txr_tail * MPSC_TXRE_SIZE)); |
| 531 | dma_cache_sync(pi->port.dev, (void *)txre, MPSC_TXRE_SIZE, |
| 532 | DMA_FROM_DEVICE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | #if defined(CONFIG_PPC32) && !defined(CONFIG_NOT_COHERENT_CACHE) |
| 534 | if (pi->cache_mgmt) /* GT642[46]0 Res #COMM-2 */ |
| 535 | invalidate_dcache_range((ulong)txre, |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 536 | (ulong)txre + MPSC_TXRE_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | #endif |
| 538 | |
| 539 | if (be32_to_cpu(txre->cmdstat) & SDMA_DESC_CMDSTAT_O) { |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 540 | txre_p = (struct mpsc_tx_desc *) |
| 541 | (pi->txr_p + (pi->txr_tail * MPSC_TXRE_SIZE)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | |
| 543 | mpsc_sdma_set_tx_ring(pi, txre_p); |
| 544 | mpsc_sdma_cmd(pi, SDMA_SDCM_STD | SDMA_SDCM_TXD); |
| 545 | } |
| 546 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | } |
| 548 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 549 | static void mpsc_sdma_stop(struct mpsc_port_info *pi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | { |
| 551 | pr_debug("mpsc_sdma_stop[%d]: Stopping SDMA\n", pi->port.line); |
| 552 | |
| 553 | /* Abort any SDMA transfers */ |
| 554 | mpsc_sdma_cmd(pi, 0); |
| 555 | mpsc_sdma_cmd(pi, SDMA_SDCM_AR | SDMA_SDCM_AT); |
| 556 | |
| 557 | /* Clear the SDMA current and first TX and RX pointers */ |
Al Viro | 2c6e759 | 2005-04-25 18:32:12 -0700 | [diff] [blame] | 558 | mpsc_sdma_set_tx_ring(pi, NULL); |
| 559 | mpsc_sdma_set_rx_ring(pi, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | |
| 561 | /* Disable interrupts */ |
| 562 | mpsc_sdma_intr_mask(pi, 0xf); |
| 563 | mpsc_sdma_intr_ack(pi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | /* |
| 567 | ****************************************************************************** |
| 568 | * |
| 569 | * Multi-Protocol Serial Controller Routines (MPSC) |
| 570 | * |
| 571 | ****************************************************************************** |
| 572 | */ |
| 573 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 574 | static void mpsc_hw_init(struct mpsc_port_info *pi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | { |
| 576 | u32 v; |
| 577 | |
| 578 | pr_debug("mpsc_hw_init[%d]: Initializing hardware\n", pi->port.line); |
| 579 | |
| 580 | /* Set up clock routing */ |
| 581 | if (pi->mirror_regs) { |
| 582 | v = pi->shared_regs->MPSC_MRR_m; |
| 583 | v &= ~0x1c7; |
| 584 | pi->shared_regs->MPSC_MRR_m = v; |
| 585 | writel(v, pi->shared_regs->mpsc_routing_base + MPSC_MRR); |
| 586 | |
| 587 | v = pi->shared_regs->MPSC_RCRR_m; |
| 588 | v = (v & ~0xf0f) | 0x100; |
| 589 | pi->shared_regs->MPSC_RCRR_m = v; |
| 590 | writel(v, pi->shared_regs->mpsc_routing_base + MPSC_RCRR); |
| 591 | |
| 592 | v = pi->shared_regs->MPSC_TCRR_m; |
| 593 | v = (v & ~0xf0f) | 0x100; |
| 594 | pi->shared_regs->MPSC_TCRR_m = v; |
| 595 | writel(v, pi->shared_regs->mpsc_routing_base + MPSC_TCRR); |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 596 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | v = readl(pi->shared_regs->mpsc_routing_base + MPSC_MRR); |
| 598 | v &= ~0x1c7; |
| 599 | writel(v, pi->shared_regs->mpsc_routing_base + MPSC_MRR); |
| 600 | |
| 601 | v = readl(pi->shared_regs->mpsc_routing_base + MPSC_RCRR); |
| 602 | v = (v & ~0xf0f) | 0x100; |
| 603 | writel(v, pi->shared_regs->mpsc_routing_base + MPSC_RCRR); |
| 604 | |
| 605 | v = readl(pi->shared_regs->mpsc_routing_base + MPSC_TCRR); |
| 606 | v = (v & ~0xf0f) | 0x100; |
| 607 | writel(v, pi->shared_regs->mpsc_routing_base + MPSC_TCRR); |
| 608 | } |
| 609 | |
| 610 | /* Put MPSC in UART mode & enabel Tx/Rx egines */ |
| 611 | writel(0x000004c4, pi->mpsc_base + MPSC_MMCRL); |
| 612 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 613 | /* No preamble, 16x divider, low-latency, */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | writel(0x04400400, pi->mpsc_base + MPSC_MMCRH); |
Mark A. Greer | 7bbdc3d | 2008-02-04 22:27:54 -0800 | [diff] [blame] | 615 | mpsc_set_baudrate(pi, pi->default_baud); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | |
| 617 | if (pi->mirror_regs) { |
| 618 | pi->MPSC_CHR_1_m = 0; |
| 619 | pi->MPSC_CHR_2_m = 0; |
| 620 | } |
| 621 | writel(0, pi->mpsc_base + MPSC_CHR_1); |
| 622 | writel(0, pi->mpsc_base + MPSC_CHR_2); |
| 623 | writel(pi->mpsc_max_idle, pi->mpsc_base + MPSC_CHR_3); |
| 624 | writel(0, pi->mpsc_base + MPSC_CHR_4); |
| 625 | writel(0, pi->mpsc_base + MPSC_CHR_5); |
| 626 | writel(0, pi->mpsc_base + MPSC_CHR_6); |
| 627 | writel(0, pi->mpsc_base + MPSC_CHR_7); |
| 628 | writel(0, pi->mpsc_base + MPSC_CHR_8); |
| 629 | writel(0, pi->mpsc_base + MPSC_CHR_9); |
| 630 | writel(0, pi->mpsc_base + MPSC_CHR_10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | } |
| 632 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 633 | static void mpsc_enter_hunt(struct mpsc_port_info *pi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | { |
| 635 | pr_debug("mpsc_enter_hunt[%d]: Hunting...\n", pi->port.line); |
| 636 | |
| 637 | if (pi->mirror_regs) { |
| 638 | writel(pi->MPSC_CHR_2_m | MPSC_CHR_2_EH, |
| 639 | pi->mpsc_base + MPSC_CHR_2); |
| 640 | /* Erratum prevents reading CHR_2 so just delay for a while */ |
| 641 | udelay(100); |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 642 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | writel(readl(pi->mpsc_base + MPSC_CHR_2) | MPSC_CHR_2_EH, |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 644 | pi->mpsc_base + MPSC_CHR_2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | |
| 646 | while (readl(pi->mpsc_base + MPSC_CHR_2) & MPSC_CHR_2_EH) |
| 647 | udelay(10); |
| 648 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | } |
| 650 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 651 | static void mpsc_freeze(struct mpsc_port_info *pi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | { |
| 653 | u32 v; |
| 654 | |
| 655 | pr_debug("mpsc_freeze[%d]: Freezing\n", pi->port.line); |
| 656 | |
| 657 | v = (pi->mirror_regs) ? pi->MPSC_MPCR_m : |
| 658 | readl(pi->mpsc_base + MPSC_MPCR); |
| 659 | v |= MPSC_MPCR_FRZ; |
| 660 | |
| 661 | if (pi->mirror_regs) |
| 662 | pi->MPSC_MPCR_m = v; |
| 663 | writel(v, pi->mpsc_base + MPSC_MPCR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | } |
| 665 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 666 | static void mpsc_unfreeze(struct mpsc_port_info *pi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | { |
| 668 | u32 v; |
| 669 | |
| 670 | v = (pi->mirror_regs) ? pi->MPSC_MPCR_m : |
| 671 | readl(pi->mpsc_base + MPSC_MPCR); |
| 672 | v &= ~MPSC_MPCR_FRZ; |
| 673 | |
| 674 | if (pi->mirror_regs) |
| 675 | pi->MPSC_MPCR_m = v; |
| 676 | writel(v, pi->mpsc_base + MPSC_MPCR); |
| 677 | |
| 678 | pr_debug("mpsc_unfreeze[%d]: Unfrozen\n", pi->port.line); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | } |
| 680 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 681 | static void mpsc_set_char_length(struct mpsc_port_info *pi, u32 len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | { |
| 683 | u32 v; |
| 684 | |
| 685 | pr_debug("mpsc_set_char_length[%d]: char len: %d\n", pi->port.line,len); |
| 686 | |
| 687 | v = (pi->mirror_regs) ? pi->MPSC_MPCR_m : |
| 688 | readl(pi->mpsc_base + MPSC_MPCR); |
| 689 | v = (v & ~(0x3 << 12)) | ((len & 0x3) << 12); |
| 690 | |
| 691 | if (pi->mirror_regs) |
| 692 | pi->MPSC_MPCR_m = v; |
| 693 | writel(v, pi->mpsc_base + MPSC_MPCR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | } |
| 695 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 696 | static void mpsc_set_stop_bit_length(struct mpsc_port_info *pi, u32 len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | { |
| 698 | u32 v; |
| 699 | |
| 700 | pr_debug("mpsc_set_stop_bit_length[%d]: stop bits: %d\n", |
| 701 | pi->port.line, len); |
| 702 | |
| 703 | v = (pi->mirror_regs) ? pi->MPSC_MPCR_m : |
| 704 | readl(pi->mpsc_base + MPSC_MPCR); |
| 705 | |
| 706 | v = (v & ~(1 << 14)) | ((len & 0x1) << 14); |
| 707 | |
| 708 | if (pi->mirror_regs) |
| 709 | pi->MPSC_MPCR_m = v; |
| 710 | writel(v, pi->mpsc_base + MPSC_MPCR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | } |
| 712 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 713 | static void mpsc_set_parity(struct mpsc_port_info *pi, u32 p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | { |
| 715 | u32 v; |
| 716 | |
| 717 | pr_debug("mpsc_set_parity[%d]: parity bits: 0x%x\n", pi->port.line, p); |
| 718 | |
| 719 | v = (pi->mirror_regs) ? pi->MPSC_CHR_2_m : |
| 720 | readl(pi->mpsc_base + MPSC_CHR_2); |
| 721 | |
| 722 | p &= 0x3; |
| 723 | v = (v & ~0xc000c) | (p << 18) | (p << 2); |
| 724 | |
| 725 | if (pi->mirror_regs) |
| 726 | pi->MPSC_CHR_2_m = v; |
| 727 | writel(v, pi->mpsc_base + MPSC_CHR_2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | } |
| 729 | |
| 730 | /* |
| 731 | ****************************************************************************** |
| 732 | * |
| 733 | * Driver Init Routines |
| 734 | * |
| 735 | ****************************************************************************** |
| 736 | */ |
| 737 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 738 | static void mpsc_init_hw(struct mpsc_port_info *pi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | { |
| 740 | pr_debug("mpsc_init_hw[%d]: Initializing\n", pi->port.line); |
| 741 | |
| 742 | mpsc_brg_init(pi, pi->brg_clk_src); |
| 743 | mpsc_brg_enable(pi); |
| 744 | mpsc_sdma_init(pi, dma_get_cache_alignment()); /* burst a cacheline */ |
| 745 | mpsc_sdma_stop(pi); |
| 746 | mpsc_hw_init(pi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | } |
| 748 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 749 | static int mpsc_alloc_ring_mem(struct mpsc_port_info *pi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 750 | { |
| 751 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | |
| 753 | pr_debug("mpsc_alloc_ring_mem[%d]: Allocating ring mem\n", |
| 754 | pi->port.line); |
| 755 | |
| 756 | if (!pi->dma_region) { |
| 757 | if (!dma_supported(pi->port.dev, 0xffffffff)) { |
| 758 | printk(KERN_ERR "MPSC: Inadequate DMA support\n"); |
| 759 | rc = -ENXIO; |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 760 | } else if ((pi->dma_region = dma_alloc_noncoherent(pi->port.dev, |
| 761 | MPSC_DMA_ALLOC_SIZE, |
| 762 | &pi->dma_region_p, GFP_KERNEL)) |
| 763 | == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | printk(KERN_ERR "MPSC: Can't alloc Desc region\n"); |
| 765 | rc = -ENOMEM; |
| 766 | } |
| 767 | } |
| 768 | |
| 769 | return rc; |
| 770 | } |
| 771 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 772 | static void mpsc_free_ring_mem(struct mpsc_port_info *pi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | { |
| 774 | pr_debug("mpsc_free_ring_mem[%d]: Freeing ring mem\n", pi->port.line); |
| 775 | |
| 776 | if (pi->dma_region) { |
| 777 | dma_free_noncoherent(pi->port.dev, MPSC_DMA_ALLOC_SIZE, |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 778 | pi->dma_region, pi->dma_region_p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | pi->dma_region = NULL; |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 780 | pi->dma_region_p = (dma_addr_t)NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 781 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | } |
| 783 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 784 | static void mpsc_init_rings(struct mpsc_port_info *pi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | { |
| 786 | struct mpsc_rx_desc *rxre; |
| 787 | struct mpsc_tx_desc *txre; |
| 788 | dma_addr_t dp, dp_p; |
| 789 | u8 *bp, *bp_p; |
| 790 | int i; |
| 791 | |
| 792 | pr_debug("mpsc_init_rings[%d]: Initializing rings\n", pi->port.line); |
| 793 | |
| 794 | BUG_ON(pi->dma_region == NULL); |
| 795 | |
| 796 | memset(pi->dma_region, 0, MPSC_DMA_ALLOC_SIZE); |
| 797 | |
| 798 | /* |
| 799 | * Descriptors & buffers are multiples of cacheline size and must be |
| 800 | * cacheline aligned. |
| 801 | */ |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 802 | dp = ALIGN((u32)pi->dma_region, dma_get_cache_alignment()); |
| 803 | dp_p = ALIGN((u32)pi->dma_region_p, dma_get_cache_alignment()); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | |
| 805 | /* |
| 806 | * Partition dma region into rx ring descriptor, rx buffers, |
| 807 | * tx ring descriptors, and tx buffers. |
| 808 | */ |
| 809 | pi->rxr = dp; |
| 810 | pi->rxr_p = dp_p; |
| 811 | dp += MPSC_RXR_SIZE; |
| 812 | dp_p += MPSC_RXR_SIZE; |
| 813 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 814 | pi->rxb = (u8 *)dp; |
| 815 | pi->rxb_p = (u8 *)dp_p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | dp += MPSC_RXB_SIZE; |
| 817 | dp_p += MPSC_RXB_SIZE; |
| 818 | |
| 819 | pi->rxr_posn = 0; |
| 820 | |
| 821 | pi->txr = dp; |
| 822 | pi->txr_p = dp_p; |
| 823 | dp += MPSC_TXR_SIZE; |
| 824 | dp_p += MPSC_TXR_SIZE; |
| 825 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 826 | pi->txb = (u8 *)dp; |
| 827 | pi->txb_p = (u8 *)dp_p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 828 | |
| 829 | pi->txr_head = 0; |
| 830 | pi->txr_tail = 0; |
| 831 | |
| 832 | /* Init rx ring descriptors */ |
| 833 | dp = pi->rxr; |
| 834 | dp_p = pi->rxr_p; |
| 835 | bp = pi->rxb; |
| 836 | bp_p = pi->rxb_p; |
| 837 | |
| 838 | for (i = 0; i < MPSC_RXR_ENTRIES; i++) { |
| 839 | rxre = (struct mpsc_rx_desc *)dp; |
| 840 | |
| 841 | rxre->bufsize = cpu_to_be16(MPSC_RXBE_SIZE); |
| 842 | rxre->bytecnt = cpu_to_be16(0); |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 843 | rxre->cmdstat = cpu_to_be32(SDMA_DESC_CMDSTAT_O |
| 844 | | SDMA_DESC_CMDSTAT_EI | SDMA_DESC_CMDSTAT_F |
| 845 | | SDMA_DESC_CMDSTAT_L); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | rxre->link = cpu_to_be32(dp_p + MPSC_RXRE_SIZE); |
| 847 | rxre->buf_ptr = cpu_to_be32(bp_p); |
| 848 | |
| 849 | dp += MPSC_RXRE_SIZE; |
| 850 | dp_p += MPSC_RXRE_SIZE; |
| 851 | bp += MPSC_RXBE_SIZE; |
| 852 | bp_p += MPSC_RXBE_SIZE; |
| 853 | } |
| 854 | rxre->link = cpu_to_be32(pi->rxr_p); /* Wrap last back to first */ |
| 855 | |
| 856 | /* Init tx ring descriptors */ |
| 857 | dp = pi->txr; |
| 858 | dp_p = pi->txr_p; |
| 859 | bp = pi->txb; |
| 860 | bp_p = pi->txb_p; |
| 861 | |
| 862 | for (i = 0; i < MPSC_TXR_ENTRIES; i++) { |
| 863 | txre = (struct mpsc_tx_desc *)dp; |
| 864 | |
| 865 | txre->link = cpu_to_be32(dp_p + MPSC_TXRE_SIZE); |
| 866 | txre->buf_ptr = cpu_to_be32(bp_p); |
| 867 | |
| 868 | dp += MPSC_TXRE_SIZE; |
| 869 | dp_p += MPSC_TXRE_SIZE; |
| 870 | bp += MPSC_TXBE_SIZE; |
| 871 | bp_p += MPSC_TXBE_SIZE; |
| 872 | } |
| 873 | txre->link = cpu_to_be32(pi->txr_p); /* Wrap last back to first */ |
| 874 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 875 | dma_cache_sync(pi->port.dev, (void *)pi->dma_region, |
| 876 | MPSC_DMA_ALLOC_SIZE, DMA_BIDIRECTIONAL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 877 | #if defined(CONFIG_PPC32) && !defined(CONFIG_NOT_COHERENT_CACHE) |
| 878 | if (pi->cache_mgmt) /* GT642[46]0 Res #COMM-2 */ |
| 879 | flush_dcache_range((ulong)pi->dma_region, |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 880 | (ulong)pi->dma_region |
| 881 | + MPSC_DMA_ALLOC_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 | #endif |
| 883 | |
| 884 | return; |
| 885 | } |
| 886 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 887 | static void mpsc_uninit_rings(struct mpsc_port_info *pi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | { |
| 889 | pr_debug("mpsc_uninit_rings[%d]: Uninitializing rings\n",pi->port.line); |
| 890 | |
| 891 | BUG_ON(pi->dma_region == NULL); |
| 892 | |
| 893 | pi->rxr = 0; |
| 894 | pi->rxr_p = 0; |
| 895 | pi->rxb = NULL; |
| 896 | pi->rxb_p = NULL; |
| 897 | pi->rxr_posn = 0; |
| 898 | |
| 899 | pi->txr = 0; |
| 900 | pi->txr_p = 0; |
| 901 | pi->txb = NULL; |
| 902 | pi->txb_p = NULL; |
| 903 | pi->txr_head = 0; |
| 904 | pi->txr_tail = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 | } |
| 906 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 907 | static int mpsc_make_ready(struct mpsc_port_info *pi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | { |
| 909 | int rc; |
| 910 | |
| 911 | pr_debug("mpsc_make_ready[%d]: Making cltr ready\n", pi->port.line); |
| 912 | |
| 913 | if (!pi->ready) { |
| 914 | mpsc_init_hw(pi); |
| 915 | if ((rc = mpsc_alloc_ring_mem(pi))) |
| 916 | return rc; |
| 917 | mpsc_init_rings(pi); |
| 918 | pi->ready = 1; |
| 919 | } |
| 920 | |
| 921 | return 0; |
| 922 | } |
| 923 | |
| 924 | /* |
| 925 | ****************************************************************************** |
| 926 | * |
| 927 | * Interrupt Handling Routines |
| 928 | * |
| 929 | ****************************************************************************** |
| 930 | */ |
| 931 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 932 | static int mpsc_rx_intr(struct mpsc_port_info *pi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 933 | { |
| 934 | struct mpsc_rx_desc *rxre; |
| 935 | struct tty_struct *tty = pi->port.info->tty; |
| 936 | u32 cmdstat, bytes_in, i; |
| 937 | int rc = 0; |
| 938 | u8 *bp; |
| 939 | char flag = TTY_NORMAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | |
| 941 | pr_debug("mpsc_rx_intr[%d]: Handling Rx intr\n", pi->port.line); |
| 942 | |
| 943 | rxre = (struct mpsc_rx_desc *)(pi->rxr + (pi->rxr_posn*MPSC_RXRE_SIZE)); |
| 944 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 945 | dma_cache_sync(pi->port.dev, (void *)rxre, MPSC_RXRE_SIZE, |
| 946 | DMA_FROM_DEVICE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 947 | #if defined(CONFIG_PPC32) && !defined(CONFIG_NOT_COHERENT_CACHE) |
| 948 | if (pi->cache_mgmt) /* GT642[46]0 Res #COMM-2 */ |
| 949 | invalidate_dcache_range((ulong)rxre, |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 950 | (ulong)rxre + MPSC_RXRE_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 951 | #endif |
| 952 | |
| 953 | /* |
| 954 | * Loop through Rx descriptors handling ones that have been completed. |
| 955 | */ |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 956 | while (!((cmdstat = be32_to_cpu(rxre->cmdstat)) |
| 957 | & SDMA_DESC_CMDSTAT_O)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 958 | bytes_in = be16_to_cpu(rxre->bytecnt); |
| 959 | |
| 960 | /* Following use of tty struct directly is deprecated */ |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 961 | if (unlikely(tty_buffer_request_room(tty, bytes_in) |
| 962 | < bytes_in)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 963 | if (tty->low_latency) |
| 964 | tty_flip_buffer_push(tty); |
| 965 | /* |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 966 | * If this failed then we will throw away the bytes |
| 967 | * but must do so to clear interrupts. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 968 | */ |
| 969 | } |
| 970 | |
| 971 | bp = pi->rxb + (pi->rxr_posn * MPSC_RXBE_SIZE); |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 972 | dma_cache_sync(pi->port.dev, (void *)bp, MPSC_RXBE_SIZE, |
| 973 | DMA_FROM_DEVICE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 974 | #if defined(CONFIG_PPC32) && !defined(CONFIG_NOT_COHERENT_CACHE) |
| 975 | if (pi->cache_mgmt) /* GT642[46]0 Res #COMM-2 */ |
| 976 | invalidate_dcache_range((ulong)bp, |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 977 | (ulong)bp + MPSC_RXBE_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 978 | #endif |
| 979 | |
| 980 | /* |
| 981 | * Other than for parity error, the manual provides little |
| 982 | * info on what data will be in a frame flagged by any of |
| 983 | * these errors. For parity error, it is the last byte in |
| 984 | * the buffer that had the error. As for the rest, I guess |
| 985 | * we'll assume there is no data in the buffer. |
| 986 | * If there is...it gets lost. |
| 987 | */ |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 988 | if (unlikely(cmdstat & (SDMA_DESC_CMDSTAT_BR |
| 989 | | SDMA_DESC_CMDSTAT_FR |
| 990 | | SDMA_DESC_CMDSTAT_OR))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 991 | |
| 992 | pi->port.icount.rx++; |
| 993 | |
| 994 | if (cmdstat & SDMA_DESC_CMDSTAT_BR) { /* Break */ |
| 995 | pi->port.icount.brk++; |
| 996 | |
| 997 | if (uart_handle_break(&pi->port)) |
| 998 | goto next_frame; |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 999 | } else if (cmdstat & SDMA_DESC_CMDSTAT_FR) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1000 | pi->port.icount.frame++; |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1001 | } else if (cmdstat & SDMA_DESC_CMDSTAT_OR) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1002 | pi->port.icount.overrun++; |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1003 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1004 | |
| 1005 | cmdstat &= pi->port.read_status_mask; |
| 1006 | |
| 1007 | if (cmdstat & SDMA_DESC_CMDSTAT_BR) |
| 1008 | flag = TTY_BREAK; |
| 1009 | else if (cmdstat & SDMA_DESC_CMDSTAT_FR) |
| 1010 | flag = TTY_FRAME; |
| 1011 | else if (cmdstat & SDMA_DESC_CMDSTAT_OR) |
| 1012 | flag = TTY_OVERRUN; |
| 1013 | else if (cmdstat & SDMA_DESC_CMDSTAT_PE) |
| 1014 | flag = TTY_PARITY; |
| 1015 | } |
| 1016 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1017 | if (uart_handle_sysrq_char(&pi->port, *bp)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1018 | bp++; |
| 1019 | bytes_in--; |
| 1020 | goto next_frame; |
| 1021 | } |
| 1022 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1023 | if ((unlikely(cmdstat & (SDMA_DESC_CMDSTAT_BR |
| 1024 | | SDMA_DESC_CMDSTAT_FR |
| 1025 | | SDMA_DESC_CMDSTAT_OR))) |
| 1026 | && !(cmdstat & pi->port.ignore_status_mask)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1027 | tty_insert_flip_char(tty, *bp, flag); |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1028 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1029 | for (i=0; i<bytes_in; i++) |
| 1030 | tty_insert_flip_char(tty, *bp++, TTY_NORMAL); |
| 1031 | |
| 1032 | pi->port.icount.rx += bytes_in; |
| 1033 | } |
| 1034 | |
| 1035 | next_frame: |
| 1036 | rxre->bytecnt = cpu_to_be16(0); |
| 1037 | wmb(); |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1038 | rxre->cmdstat = cpu_to_be32(SDMA_DESC_CMDSTAT_O |
| 1039 | | SDMA_DESC_CMDSTAT_EI | SDMA_DESC_CMDSTAT_F |
| 1040 | | SDMA_DESC_CMDSTAT_L); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1041 | wmb(); |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1042 | dma_cache_sync(pi->port.dev, (void *)rxre, MPSC_RXRE_SIZE, |
| 1043 | DMA_BIDIRECTIONAL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1044 | #if defined(CONFIG_PPC32) && !defined(CONFIG_NOT_COHERENT_CACHE) |
| 1045 | if (pi->cache_mgmt) /* GT642[46]0 Res #COMM-2 */ |
| 1046 | flush_dcache_range((ulong)rxre, |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1047 | (ulong)rxre + MPSC_RXRE_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1048 | #endif |
| 1049 | |
| 1050 | /* Advance to next descriptor */ |
| 1051 | pi->rxr_posn = (pi->rxr_posn + 1) & (MPSC_RXR_ENTRIES - 1); |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1052 | rxre = (struct mpsc_rx_desc *) |
| 1053 | (pi->rxr + (pi->rxr_posn * MPSC_RXRE_SIZE)); |
| 1054 | dma_cache_sync(pi->port.dev, (void *)rxre, MPSC_RXRE_SIZE, |
| 1055 | DMA_FROM_DEVICE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1056 | #if defined(CONFIG_PPC32) && !defined(CONFIG_NOT_COHERENT_CACHE) |
| 1057 | if (pi->cache_mgmt) /* GT642[46]0 Res #COMM-2 */ |
| 1058 | invalidate_dcache_range((ulong)rxre, |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1059 | (ulong)rxre + MPSC_RXRE_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1060 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1061 | rc = 1; |
| 1062 | } |
| 1063 | |
| 1064 | /* Restart rx engine, if its stopped */ |
| 1065 | if ((readl(pi->sdma_base + SDMA_SDCM) & SDMA_SDCM_ERD) == 0) |
| 1066 | mpsc_start_rx(pi); |
| 1067 | |
| 1068 | tty_flip_buffer_push(tty); |
| 1069 | return rc; |
| 1070 | } |
| 1071 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1072 | static void mpsc_setup_tx_desc(struct mpsc_port_info *pi, u32 count, u32 intr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1073 | { |
| 1074 | struct mpsc_tx_desc *txre; |
| 1075 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1076 | txre = (struct mpsc_tx_desc *)(pi->txr |
| 1077 | + (pi->txr_head * MPSC_TXRE_SIZE)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1078 | |
| 1079 | txre->bytecnt = cpu_to_be16(count); |
| 1080 | txre->shadow = txre->bytecnt; |
| 1081 | wmb(); /* ensure cmdstat is last field updated */ |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1082 | txre->cmdstat = cpu_to_be32(SDMA_DESC_CMDSTAT_O | SDMA_DESC_CMDSTAT_F |
| 1083 | | SDMA_DESC_CMDSTAT_L |
| 1084 | | ((intr) ? SDMA_DESC_CMDSTAT_EI : 0)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1085 | wmb(); |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1086 | dma_cache_sync(pi->port.dev, (void *)txre, MPSC_TXRE_SIZE, |
| 1087 | DMA_BIDIRECTIONAL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1088 | #if defined(CONFIG_PPC32) && !defined(CONFIG_NOT_COHERENT_CACHE) |
| 1089 | if (pi->cache_mgmt) /* GT642[46]0 Res #COMM-2 */ |
| 1090 | flush_dcache_range((ulong)txre, |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1091 | (ulong)txre + MPSC_TXRE_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1092 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1093 | } |
| 1094 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1095 | static void mpsc_copy_tx_data(struct mpsc_port_info *pi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1096 | { |
| 1097 | struct circ_buf *xmit = &pi->port.info->xmit; |
| 1098 | u8 *bp; |
| 1099 | u32 i; |
| 1100 | |
| 1101 | /* Make sure the desc ring isn't full */ |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1102 | while (CIRC_CNT(pi->txr_head, pi->txr_tail, MPSC_TXR_ENTRIES) |
| 1103 | < (MPSC_TXR_ENTRIES - 1)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1104 | if (pi->port.x_char) { |
| 1105 | /* |
| 1106 | * Ideally, we should use the TCS field in |
| 1107 | * CHR_1 to put the x_char out immediately but |
| 1108 | * errata prevents us from being able to read |
| 1109 | * CHR_2 to know that its safe to write to |
| 1110 | * CHR_1. Instead, just put it in-band with |
| 1111 | * all the other Tx data. |
| 1112 | */ |
| 1113 | bp = pi->txb + (pi->txr_head * MPSC_TXBE_SIZE); |
| 1114 | *bp = pi->port.x_char; |
| 1115 | pi->port.x_char = 0; |
| 1116 | i = 1; |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1117 | } else if (!uart_circ_empty(xmit) |
| 1118 | && !uart_tx_stopped(&pi->port)) { |
| 1119 | i = min((u32)MPSC_TXBE_SIZE, |
| 1120 | (u32)uart_circ_chars_pending(xmit)); |
| 1121 | i = min(i, (u32)CIRC_CNT_TO_END(xmit->head, xmit->tail, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1122 | UART_XMIT_SIZE)); |
| 1123 | bp = pi->txb + (pi->txr_head * MPSC_TXBE_SIZE); |
| 1124 | memcpy(bp, &xmit->buf[xmit->tail], i); |
| 1125 | xmit->tail = (xmit->tail + i) & (UART_XMIT_SIZE - 1); |
| 1126 | |
| 1127 | if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) |
| 1128 | uart_write_wakeup(&pi->port); |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1129 | } else { /* All tx data copied into ring bufs */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1130 | return; |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1131 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1132 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1133 | dma_cache_sync(pi->port.dev, (void *)bp, MPSC_TXBE_SIZE, |
| 1134 | DMA_BIDIRECTIONAL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1135 | #if defined(CONFIG_PPC32) && !defined(CONFIG_NOT_COHERENT_CACHE) |
| 1136 | if (pi->cache_mgmt) /* GT642[46]0 Res #COMM-2 */ |
| 1137 | flush_dcache_range((ulong)bp, |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1138 | (ulong)bp + MPSC_TXBE_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1139 | #endif |
| 1140 | mpsc_setup_tx_desc(pi, i, 1); |
| 1141 | |
| 1142 | /* Advance to next descriptor */ |
| 1143 | pi->txr_head = (pi->txr_head + 1) & (MPSC_TXR_ENTRIES - 1); |
| 1144 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1145 | } |
| 1146 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1147 | static int mpsc_tx_intr(struct mpsc_port_info *pi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1148 | { |
| 1149 | struct mpsc_tx_desc *txre; |
| 1150 | int rc = 0; |
Dave Jiang | 1733310 | 2007-05-06 14:48:50 -0700 | [diff] [blame] | 1151 | unsigned long iflags; |
| 1152 | |
| 1153 | spin_lock_irqsave(&pi->tx_lock, iflags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1154 | |
| 1155 | if (!mpsc_sdma_tx_active(pi)) { |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1156 | txre = (struct mpsc_tx_desc *)(pi->txr |
| 1157 | + (pi->txr_tail * MPSC_TXRE_SIZE)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1158 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1159 | dma_cache_sync(pi->port.dev, (void *)txre, MPSC_TXRE_SIZE, |
| 1160 | DMA_FROM_DEVICE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1161 | #if defined(CONFIG_PPC32) && !defined(CONFIG_NOT_COHERENT_CACHE) |
| 1162 | if (pi->cache_mgmt) /* GT642[46]0 Res #COMM-2 */ |
| 1163 | invalidate_dcache_range((ulong)txre, |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1164 | (ulong)txre + MPSC_TXRE_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1165 | #endif |
| 1166 | |
| 1167 | while (!(be32_to_cpu(txre->cmdstat) & SDMA_DESC_CMDSTAT_O)) { |
| 1168 | rc = 1; |
| 1169 | pi->port.icount.tx += be16_to_cpu(txre->bytecnt); |
| 1170 | pi->txr_tail = (pi->txr_tail+1) & (MPSC_TXR_ENTRIES-1); |
| 1171 | |
| 1172 | /* If no more data to tx, fall out of loop */ |
| 1173 | if (pi->txr_head == pi->txr_tail) |
| 1174 | break; |
| 1175 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1176 | txre = (struct mpsc_tx_desc *)(pi->txr |
| 1177 | + (pi->txr_tail * MPSC_TXRE_SIZE)); |
| 1178 | dma_cache_sync(pi->port.dev, (void *)txre, |
| 1179 | MPSC_TXRE_SIZE, DMA_FROM_DEVICE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1180 | #if defined(CONFIG_PPC32) && !defined(CONFIG_NOT_COHERENT_CACHE) |
| 1181 | if (pi->cache_mgmt) /* GT642[46]0 Res #COMM-2 */ |
| 1182 | invalidate_dcache_range((ulong)txre, |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1183 | (ulong)txre + MPSC_TXRE_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1184 | #endif |
| 1185 | } |
| 1186 | |
| 1187 | mpsc_copy_tx_data(pi); |
| 1188 | mpsc_sdma_start_tx(pi); /* start next desc if ready */ |
| 1189 | } |
| 1190 | |
Dave Jiang | 1733310 | 2007-05-06 14:48:50 -0700 | [diff] [blame] | 1191 | spin_unlock_irqrestore(&pi->tx_lock, iflags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1192 | return rc; |
| 1193 | } |
| 1194 | |
| 1195 | /* |
| 1196 | * This is the driver's interrupt handler. To avoid a race, we first clear |
| 1197 | * the interrupt, then handle any completed Rx/Tx descriptors. When done |
| 1198 | * handling those descriptors, we restart the Rx/Tx engines if they're stopped. |
| 1199 | */ |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1200 | static irqreturn_t mpsc_sdma_intr(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1201 | { |
| 1202 | struct mpsc_port_info *pi = dev_id; |
| 1203 | ulong iflags; |
| 1204 | int rc = IRQ_NONE; |
| 1205 | |
| 1206 | pr_debug("mpsc_sdma_intr[%d]: SDMA Interrupt Received\n",pi->port.line); |
| 1207 | |
| 1208 | spin_lock_irqsave(&pi->port.lock, iflags); |
| 1209 | mpsc_sdma_intr_ack(pi); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1210 | if (mpsc_rx_intr(pi)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1211 | rc = IRQ_HANDLED; |
| 1212 | if (mpsc_tx_intr(pi)) |
| 1213 | rc = IRQ_HANDLED; |
| 1214 | spin_unlock_irqrestore(&pi->port.lock, iflags); |
| 1215 | |
| 1216 | pr_debug("mpsc_sdma_intr[%d]: SDMA Interrupt Handled\n", pi->port.line); |
| 1217 | return rc; |
| 1218 | } |
| 1219 | |
| 1220 | /* |
| 1221 | ****************************************************************************** |
| 1222 | * |
| 1223 | * serial_core.c Interface routines |
| 1224 | * |
| 1225 | ****************************************************************************** |
| 1226 | */ |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1227 | static uint mpsc_tx_empty(struct uart_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1228 | { |
| 1229 | struct mpsc_port_info *pi = (struct mpsc_port_info *)port; |
| 1230 | ulong iflags; |
| 1231 | uint rc; |
| 1232 | |
| 1233 | spin_lock_irqsave(&pi->port.lock, iflags); |
| 1234 | rc = mpsc_sdma_tx_active(pi) ? 0 : TIOCSER_TEMT; |
| 1235 | spin_unlock_irqrestore(&pi->port.lock, iflags); |
| 1236 | |
| 1237 | return rc; |
| 1238 | } |
| 1239 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1240 | static void mpsc_set_mctrl(struct uart_port *port, uint mctrl) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1241 | { |
| 1242 | /* Have no way to set modem control lines AFAICT */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1243 | } |
| 1244 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1245 | static uint mpsc_get_mctrl(struct uart_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1246 | { |
| 1247 | struct mpsc_port_info *pi = (struct mpsc_port_info *)port; |
| 1248 | u32 mflags, status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1249 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1250 | status = (pi->mirror_regs) ? pi->MPSC_CHR_10_m |
| 1251 | : readl(pi->mpsc_base + MPSC_CHR_10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1252 | |
| 1253 | mflags = 0; |
| 1254 | if (status & 0x1) |
| 1255 | mflags |= TIOCM_CTS; |
| 1256 | if (status & 0x2) |
| 1257 | mflags |= TIOCM_CAR; |
| 1258 | |
| 1259 | return mflags | TIOCM_DSR; /* No way to tell if DSR asserted */ |
| 1260 | } |
| 1261 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1262 | static void mpsc_stop_tx(struct uart_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1263 | { |
| 1264 | struct mpsc_port_info *pi = (struct mpsc_port_info *)port; |
| 1265 | |
Russell King | b129a8c | 2005-08-31 10:12:14 +0100 | [diff] [blame] | 1266 | pr_debug("mpsc_stop_tx[%d]\n", port->line); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1267 | |
| 1268 | mpsc_freeze(pi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1269 | } |
| 1270 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1271 | static void mpsc_start_tx(struct uart_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1272 | { |
| 1273 | struct mpsc_port_info *pi = (struct mpsc_port_info *)port; |
Dave Jiang | 1733310 | 2007-05-06 14:48:50 -0700 | [diff] [blame] | 1274 | unsigned long iflags; |
| 1275 | |
| 1276 | spin_lock_irqsave(&pi->tx_lock, iflags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1277 | |
| 1278 | mpsc_unfreeze(pi); |
| 1279 | mpsc_copy_tx_data(pi); |
| 1280 | mpsc_sdma_start_tx(pi); |
| 1281 | |
Dave Jiang | 1733310 | 2007-05-06 14:48:50 -0700 | [diff] [blame] | 1282 | spin_unlock_irqrestore(&pi->tx_lock, iflags); |
| 1283 | |
Russell King | b129a8c | 2005-08-31 10:12:14 +0100 | [diff] [blame] | 1284 | pr_debug("mpsc_start_tx[%d]\n", port->line); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1285 | } |
| 1286 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1287 | static void mpsc_start_rx(struct mpsc_port_info *pi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1288 | { |
| 1289 | pr_debug("mpsc_start_rx[%d]: Starting...\n", pi->port.line); |
| 1290 | |
| 1291 | if (pi->rcv_data) { |
| 1292 | mpsc_enter_hunt(pi); |
| 1293 | mpsc_sdma_cmd(pi, SDMA_SDCM_ERD); |
| 1294 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1295 | } |
| 1296 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1297 | static void mpsc_stop_rx(struct uart_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1298 | { |
| 1299 | struct mpsc_port_info *pi = (struct mpsc_port_info *)port; |
| 1300 | |
| 1301 | pr_debug("mpsc_stop_rx[%d]: Stopping...\n", port->line); |
| 1302 | |
Carlos Sanchez | 6c1ead5 | 2007-07-31 00:38:59 -0700 | [diff] [blame] | 1303 | if (pi->mirror_regs) { |
| 1304 | writel(pi->MPSC_CHR_2_m | MPSC_CHR_2_RA, |
| 1305 | pi->mpsc_base + MPSC_CHR_2); |
| 1306 | /* Erratum prevents reading CHR_2 so just delay for a while */ |
| 1307 | udelay(100); |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1308 | } else { |
Carlos Sanchez | 6c1ead5 | 2007-07-31 00:38:59 -0700 | [diff] [blame] | 1309 | writel(readl(pi->mpsc_base + MPSC_CHR_2) | MPSC_CHR_2_RA, |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1310 | pi->mpsc_base + MPSC_CHR_2); |
Carlos Sanchez | 6c1ead5 | 2007-07-31 00:38:59 -0700 | [diff] [blame] | 1311 | |
| 1312 | while (readl(pi->mpsc_base + MPSC_CHR_2) & MPSC_CHR_2_RA) |
| 1313 | udelay(10); |
| 1314 | } |
| 1315 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1316 | mpsc_sdma_cmd(pi, SDMA_SDCM_AR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1317 | } |
| 1318 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1319 | static void mpsc_enable_ms(struct uart_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1320 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1321 | } |
| 1322 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1323 | static void mpsc_break_ctl(struct uart_port *port, int ctl) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1324 | { |
| 1325 | struct mpsc_port_info *pi = (struct mpsc_port_info *)port; |
| 1326 | ulong flags; |
| 1327 | u32 v; |
| 1328 | |
| 1329 | v = ctl ? 0x00ff0000 : 0; |
| 1330 | |
| 1331 | spin_lock_irqsave(&pi->port.lock, flags); |
| 1332 | if (pi->mirror_regs) |
| 1333 | pi->MPSC_CHR_1_m = v; |
| 1334 | writel(v, pi->mpsc_base + MPSC_CHR_1); |
| 1335 | spin_unlock_irqrestore(&pi->port.lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1336 | } |
| 1337 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1338 | static int mpsc_startup(struct uart_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1339 | { |
| 1340 | struct mpsc_port_info *pi = (struct mpsc_port_info *)port; |
| 1341 | u32 flag = 0; |
| 1342 | int rc; |
| 1343 | |
| 1344 | pr_debug("mpsc_startup[%d]: Starting up MPSC, irq: %d\n", |
| 1345 | port->line, pi->port.irq); |
| 1346 | |
| 1347 | if ((rc = mpsc_make_ready(pi)) == 0) { |
| 1348 | /* Setup IRQ handler */ |
| 1349 | mpsc_sdma_intr_ack(pi); |
| 1350 | |
| 1351 | /* If irq's are shared, need to set flag */ |
| 1352 | if (mpsc_ports[0].port.irq == mpsc_ports[1].port.irq) |
Thomas Gleixner | 40663cc | 2006-07-01 19:29:43 -0700 | [diff] [blame] | 1353 | flag = IRQF_SHARED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1354 | |
| 1355 | if (request_irq(pi->port.irq, mpsc_sdma_intr, flag, |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1356 | "mpsc-sdma", pi)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1357 | printk(KERN_ERR "MPSC: Can't get SDMA IRQ %d\n", |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1358 | pi->port.irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1359 | |
| 1360 | mpsc_sdma_intr_unmask(pi, 0xf); |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1361 | mpsc_sdma_set_rx_ring(pi, (struct mpsc_rx_desc *)(pi->rxr_p |
| 1362 | + (pi->rxr_posn * MPSC_RXRE_SIZE))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1363 | } |
| 1364 | |
| 1365 | return rc; |
| 1366 | } |
| 1367 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1368 | static void mpsc_shutdown(struct uart_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1369 | { |
| 1370 | struct mpsc_port_info *pi = (struct mpsc_port_info *)port; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1371 | |
| 1372 | pr_debug("mpsc_shutdown[%d]: Shutting down MPSC\n", port->line); |
| 1373 | |
| 1374 | mpsc_sdma_stop(pi); |
| 1375 | free_irq(pi->port.irq, pi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1376 | } |
| 1377 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1378 | static void mpsc_set_termios(struct uart_port *port, struct ktermios *termios, |
Alan Cox | 606d099 | 2006-12-08 02:38:45 -0800 | [diff] [blame] | 1379 | struct ktermios *old) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1380 | { |
| 1381 | struct mpsc_port_info *pi = (struct mpsc_port_info *)port; |
| 1382 | u32 baud; |
| 1383 | ulong flags; |
| 1384 | u32 chr_bits, stop_bits, par; |
| 1385 | |
| 1386 | pi->c_iflag = termios->c_iflag; |
| 1387 | pi->c_cflag = termios->c_cflag; |
| 1388 | |
| 1389 | switch (termios->c_cflag & CSIZE) { |
| 1390 | case CS5: |
| 1391 | chr_bits = MPSC_MPCR_CL_5; |
| 1392 | break; |
| 1393 | case CS6: |
| 1394 | chr_bits = MPSC_MPCR_CL_6; |
| 1395 | break; |
| 1396 | case CS7: |
| 1397 | chr_bits = MPSC_MPCR_CL_7; |
| 1398 | break; |
| 1399 | case CS8: |
| 1400 | default: |
| 1401 | chr_bits = MPSC_MPCR_CL_8; |
| 1402 | break; |
| 1403 | } |
| 1404 | |
| 1405 | if (termios->c_cflag & CSTOPB) |
| 1406 | stop_bits = MPSC_MPCR_SBL_2; |
| 1407 | else |
| 1408 | stop_bits = MPSC_MPCR_SBL_1; |
| 1409 | |
| 1410 | par = MPSC_CHR_2_PAR_EVEN; |
| 1411 | if (termios->c_cflag & PARENB) |
| 1412 | if (termios->c_cflag & PARODD) |
| 1413 | par = MPSC_CHR_2_PAR_ODD; |
| 1414 | #ifdef CMSPAR |
| 1415 | if (termios->c_cflag & CMSPAR) { |
| 1416 | if (termios->c_cflag & PARODD) |
| 1417 | par = MPSC_CHR_2_PAR_MARK; |
| 1418 | else |
| 1419 | par = MPSC_CHR_2_PAR_SPACE; |
| 1420 | } |
| 1421 | #endif |
| 1422 | |
| 1423 | baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk); |
| 1424 | |
| 1425 | spin_lock_irqsave(&pi->port.lock, flags); |
| 1426 | |
| 1427 | uart_update_timeout(port, termios->c_cflag, baud); |
| 1428 | |
| 1429 | mpsc_set_char_length(pi, chr_bits); |
| 1430 | mpsc_set_stop_bit_length(pi, stop_bits); |
| 1431 | mpsc_set_parity(pi, par); |
| 1432 | mpsc_set_baudrate(pi, baud); |
| 1433 | |
| 1434 | /* Characters/events to read */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1435 | pi->port.read_status_mask = SDMA_DESC_CMDSTAT_OR; |
| 1436 | |
| 1437 | if (termios->c_iflag & INPCK) |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1438 | pi->port.read_status_mask |= SDMA_DESC_CMDSTAT_PE |
| 1439 | | SDMA_DESC_CMDSTAT_FR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1440 | |
| 1441 | if (termios->c_iflag & (BRKINT | PARMRK)) |
| 1442 | pi->port.read_status_mask |= SDMA_DESC_CMDSTAT_BR; |
| 1443 | |
| 1444 | /* Characters/events to ignore */ |
| 1445 | pi->port.ignore_status_mask = 0; |
| 1446 | |
| 1447 | if (termios->c_iflag & IGNPAR) |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1448 | pi->port.ignore_status_mask |= SDMA_DESC_CMDSTAT_PE |
| 1449 | | SDMA_DESC_CMDSTAT_FR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1450 | |
| 1451 | if (termios->c_iflag & IGNBRK) { |
| 1452 | pi->port.ignore_status_mask |= SDMA_DESC_CMDSTAT_BR; |
| 1453 | |
| 1454 | if (termios->c_iflag & IGNPAR) |
| 1455 | pi->port.ignore_status_mask |= SDMA_DESC_CMDSTAT_OR; |
| 1456 | } |
| 1457 | |
Stephane Chazelas | 5797ae3 | 2007-07-31 00:38:59 -0700 | [diff] [blame] | 1458 | if ((termios->c_cflag & CREAD)) { |
| 1459 | if (!pi->rcv_data) { |
| 1460 | pi->rcv_data = 1; |
| 1461 | mpsc_start_rx(pi); |
| 1462 | } |
| 1463 | } else if (pi->rcv_data) { |
| 1464 | mpsc_stop_rx(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1465 | pi->rcv_data = 0; |
Stephane Chazelas | 5797ae3 | 2007-07-31 00:38:59 -0700 | [diff] [blame] | 1466 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1467 | |
| 1468 | spin_unlock_irqrestore(&pi->port.lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1469 | } |
| 1470 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1471 | static const char *mpsc_type(struct uart_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1472 | { |
| 1473 | pr_debug("mpsc_type[%d]: port type: %s\n", port->line,MPSC_DRIVER_NAME); |
| 1474 | return MPSC_DRIVER_NAME; |
| 1475 | } |
| 1476 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1477 | static int mpsc_request_port(struct uart_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1478 | { |
| 1479 | /* Should make chip/platform specific call */ |
| 1480 | return 0; |
| 1481 | } |
| 1482 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1483 | static void mpsc_release_port(struct uart_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1484 | { |
| 1485 | struct mpsc_port_info *pi = (struct mpsc_port_info *)port; |
| 1486 | |
| 1487 | if (pi->ready) { |
| 1488 | mpsc_uninit_rings(pi); |
| 1489 | mpsc_free_ring_mem(pi); |
| 1490 | pi->ready = 0; |
| 1491 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1492 | } |
| 1493 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1494 | static void mpsc_config_port(struct uart_port *port, int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1495 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1496 | } |
| 1497 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1498 | static int mpsc_verify_port(struct uart_port *port, struct serial_struct *ser) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1499 | { |
| 1500 | struct mpsc_port_info *pi = (struct mpsc_port_info *)port; |
| 1501 | int rc = 0; |
| 1502 | |
| 1503 | pr_debug("mpsc_verify_port[%d]: Verifying port data\n", pi->port.line); |
| 1504 | |
| 1505 | if (ser->type != PORT_UNKNOWN && ser->type != PORT_MPSC) |
| 1506 | rc = -EINVAL; |
| 1507 | else if (pi->port.irq != ser->irq) |
| 1508 | rc = -EINVAL; |
| 1509 | else if (ser->io_type != SERIAL_IO_MEM) |
| 1510 | rc = -EINVAL; |
| 1511 | else if (pi->port.uartclk / 16 != ser->baud_base) /* Not sure */ |
| 1512 | rc = -EINVAL; |
| 1513 | else if ((void *)pi->port.mapbase != ser->iomem_base) |
| 1514 | rc = -EINVAL; |
| 1515 | else if (pi->port.iobase != ser->port) |
| 1516 | rc = -EINVAL; |
| 1517 | else if (ser->hub6 != 0) |
| 1518 | rc = -EINVAL; |
| 1519 | |
| 1520 | return rc; |
| 1521 | } |
| 1522 | |
| 1523 | static struct uart_ops mpsc_pops = { |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1524 | .tx_empty = mpsc_tx_empty, |
| 1525 | .set_mctrl = mpsc_set_mctrl, |
| 1526 | .get_mctrl = mpsc_get_mctrl, |
| 1527 | .stop_tx = mpsc_stop_tx, |
| 1528 | .start_tx = mpsc_start_tx, |
| 1529 | .stop_rx = mpsc_stop_rx, |
| 1530 | .enable_ms = mpsc_enable_ms, |
| 1531 | .break_ctl = mpsc_break_ctl, |
| 1532 | .startup = mpsc_startup, |
| 1533 | .shutdown = mpsc_shutdown, |
| 1534 | .set_termios = mpsc_set_termios, |
| 1535 | .type = mpsc_type, |
| 1536 | .release_port = mpsc_release_port, |
| 1537 | .request_port = mpsc_request_port, |
| 1538 | .config_port = mpsc_config_port, |
| 1539 | .verify_port = mpsc_verify_port, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1540 | }; |
| 1541 | |
| 1542 | /* |
| 1543 | ****************************************************************************** |
| 1544 | * |
| 1545 | * Console Interface Routines |
| 1546 | * |
| 1547 | ****************************************************************************** |
| 1548 | */ |
| 1549 | |
| 1550 | #ifdef CONFIG_SERIAL_MPSC_CONSOLE |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1551 | static void mpsc_console_write(struct console *co, const char *s, uint count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1552 | { |
| 1553 | struct mpsc_port_info *pi = &mpsc_ports[co->index]; |
| 1554 | u8 *bp, *dp, add_cr = 0; |
| 1555 | int i; |
Dave Jiang | 1733310 | 2007-05-06 14:48:50 -0700 | [diff] [blame] | 1556 | unsigned long iflags; |
| 1557 | |
| 1558 | spin_lock_irqsave(&pi->tx_lock, iflags); |
| 1559 | |
| 1560 | while (pi->txr_head != pi->txr_tail) { |
| 1561 | while (mpsc_sdma_tx_active(pi)) |
| 1562 | udelay(100); |
| 1563 | mpsc_sdma_intr_ack(pi); |
| 1564 | mpsc_tx_intr(pi); |
| 1565 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1566 | |
| 1567 | while (mpsc_sdma_tx_active(pi)) |
| 1568 | udelay(100); |
| 1569 | |
| 1570 | while (count > 0) { |
| 1571 | bp = dp = pi->txb + (pi->txr_head * MPSC_TXBE_SIZE); |
| 1572 | |
| 1573 | for (i = 0; i < MPSC_TXBE_SIZE; i++) { |
| 1574 | if (count == 0) |
| 1575 | break; |
| 1576 | |
| 1577 | if (add_cr) { |
| 1578 | *(dp++) = '\r'; |
| 1579 | add_cr = 0; |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1580 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1581 | *(dp++) = *s; |
| 1582 | |
| 1583 | if (*(s++) == '\n') { /* add '\r' after '\n' */ |
| 1584 | add_cr = 1; |
| 1585 | count++; |
| 1586 | } |
| 1587 | } |
| 1588 | |
| 1589 | count--; |
| 1590 | } |
| 1591 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1592 | dma_cache_sync(pi->port.dev, (void *)bp, MPSC_TXBE_SIZE, |
| 1593 | DMA_BIDIRECTIONAL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1594 | #if defined(CONFIG_PPC32) && !defined(CONFIG_NOT_COHERENT_CACHE) |
| 1595 | if (pi->cache_mgmt) /* GT642[46]0 Res #COMM-2 */ |
| 1596 | flush_dcache_range((ulong)bp, |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1597 | (ulong)bp + MPSC_TXBE_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1598 | #endif |
| 1599 | mpsc_setup_tx_desc(pi, i, 0); |
| 1600 | pi->txr_head = (pi->txr_head + 1) & (MPSC_TXR_ENTRIES - 1); |
| 1601 | mpsc_sdma_start_tx(pi); |
| 1602 | |
| 1603 | while (mpsc_sdma_tx_active(pi)) |
| 1604 | udelay(100); |
| 1605 | |
| 1606 | pi->txr_tail = (pi->txr_tail + 1) & (MPSC_TXR_ENTRIES - 1); |
| 1607 | } |
| 1608 | |
Dave Jiang | 1733310 | 2007-05-06 14:48:50 -0700 | [diff] [blame] | 1609 | spin_unlock_irqrestore(&pi->tx_lock, iflags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1610 | } |
| 1611 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1612 | static int __init mpsc_console_setup(struct console *co, char *options) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1613 | { |
| 1614 | struct mpsc_port_info *pi; |
| 1615 | int baud, bits, parity, flow; |
| 1616 | |
| 1617 | pr_debug("mpsc_console_setup[%d]: options: %s\n", co->index, options); |
| 1618 | |
| 1619 | if (co->index >= MPSC_NUM_CTLRS) |
| 1620 | co->index = 0; |
| 1621 | |
| 1622 | pi = &mpsc_ports[co->index]; |
| 1623 | |
| 1624 | baud = pi->default_baud; |
| 1625 | bits = pi->default_bits; |
| 1626 | parity = pi->default_parity; |
| 1627 | flow = pi->default_flow; |
| 1628 | |
| 1629 | if (!pi->port.ops) |
| 1630 | return -ENODEV; |
| 1631 | |
| 1632 | spin_lock_init(&pi->port.lock); /* Temporary fix--copied from 8250.c */ |
| 1633 | |
| 1634 | if (options) |
| 1635 | uart_parse_options(options, &baud, &parity, &bits, &flow); |
| 1636 | |
| 1637 | return uart_set_options(&pi->port, co, baud, parity, bits, flow); |
| 1638 | } |
| 1639 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1640 | static struct console mpsc_console = { |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1641 | .name = MPSC_DEV_NAME, |
| 1642 | .write = mpsc_console_write, |
| 1643 | .device = uart_console_device, |
| 1644 | .setup = mpsc_console_setup, |
| 1645 | .flags = CON_PRINTBUFFER, |
| 1646 | .index = -1, |
| 1647 | .data = &mpsc_reg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1648 | }; |
| 1649 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1650 | static int __init mpsc_late_console_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1651 | { |
| 1652 | pr_debug("mpsc_late_console_init: Enter\n"); |
| 1653 | |
| 1654 | if (!(mpsc_console.flags & CON_ENABLED)) |
| 1655 | register_console(&mpsc_console); |
| 1656 | return 0; |
| 1657 | } |
| 1658 | |
| 1659 | late_initcall(mpsc_late_console_init); |
| 1660 | |
| 1661 | #define MPSC_CONSOLE &mpsc_console |
| 1662 | #else |
| 1663 | #define MPSC_CONSOLE NULL |
| 1664 | #endif |
| 1665 | /* |
| 1666 | ****************************************************************************** |
| 1667 | * |
| 1668 | * Dummy Platform Driver to extract & map shared register regions |
| 1669 | * |
| 1670 | ****************************************************************************** |
| 1671 | */ |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1672 | static void mpsc_resource_err(char *s) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1673 | { |
| 1674 | printk(KERN_WARNING "MPSC: Platform device resource error in %s\n", s); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1675 | } |
| 1676 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1677 | static int mpsc_shared_map_regs(struct platform_device *pd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1678 | { |
| 1679 | struct resource *r; |
| 1680 | |
| 1681 | if ((r = platform_get_resource(pd, IORESOURCE_MEM, |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1682 | MPSC_ROUTING_BASE_ORDER)) |
| 1683 | && request_mem_region(r->start, |
| 1684 | MPSC_ROUTING_REG_BLOCK_SIZE, |
| 1685 | "mpsc_routing_regs")) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1686 | mpsc_shared_regs.mpsc_routing_base = ioremap(r->start, |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1687 | MPSC_ROUTING_REG_BLOCK_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1688 | mpsc_shared_regs.mpsc_routing_base_p = r->start; |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1689 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1690 | mpsc_resource_err("MPSC routing base"); |
| 1691 | return -ENOMEM; |
| 1692 | } |
| 1693 | |
| 1694 | if ((r = platform_get_resource(pd, IORESOURCE_MEM, |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1695 | MPSC_SDMA_INTR_BASE_ORDER)) |
| 1696 | && request_mem_region(r->start, |
| 1697 | MPSC_SDMA_INTR_REG_BLOCK_SIZE, |
| 1698 | "sdma_intr_regs")) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1699 | mpsc_shared_regs.sdma_intr_base = ioremap(r->start, |
| 1700 | MPSC_SDMA_INTR_REG_BLOCK_SIZE); |
| 1701 | mpsc_shared_regs.sdma_intr_base_p = r->start; |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1702 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1703 | iounmap(mpsc_shared_regs.mpsc_routing_base); |
| 1704 | release_mem_region(mpsc_shared_regs.mpsc_routing_base_p, |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1705 | MPSC_ROUTING_REG_BLOCK_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1706 | mpsc_resource_err("SDMA intr base"); |
| 1707 | return -ENOMEM; |
| 1708 | } |
| 1709 | |
| 1710 | return 0; |
| 1711 | } |
| 1712 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1713 | static void mpsc_shared_unmap_regs(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1714 | { |
| 1715 | if (!mpsc_shared_regs.mpsc_routing_base) { |
| 1716 | iounmap(mpsc_shared_regs.mpsc_routing_base); |
| 1717 | release_mem_region(mpsc_shared_regs.mpsc_routing_base_p, |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1718 | MPSC_ROUTING_REG_BLOCK_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1719 | } |
| 1720 | if (!mpsc_shared_regs.sdma_intr_base) { |
| 1721 | iounmap(mpsc_shared_regs.sdma_intr_base); |
| 1722 | release_mem_region(mpsc_shared_regs.sdma_intr_base_p, |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1723 | MPSC_SDMA_INTR_REG_BLOCK_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1724 | } |
| 1725 | |
Al Viro | 2c6e759 | 2005-04-25 18:32:12 -0700 | [diff] [blame] | 1726 | mpsc_shared_regs.mpsc_routing_base = NULL; |
| 1727 | mpsc_shared_regs.sdma_intr_base = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1728 | |
| 1729 | mpsc_shared_regs.mpsc_routing_base_p = 0; |
| 1730 | mpsc_shared_regs.sdma_intr_base_p = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1731 | } |
| 1732 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1733 | static int mpsc_shared_drv_probe(struct platform_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1734 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1735 | struct mpsc_shared_pdata *pdata; |
| 1736 | int rc = -ENODEV; |
| 1737 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1738 | if (dev->id == 0) { |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1739 | if (!(rc = mpsc_shared_map_regs(dev))) { |
| 1740 | pdata = (struct mpsc_shared_pdata *) |
| 1741 | dev->dev.platform_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1742 | |
| 1743 | mpsc_shared_regs.MPSC_MRR_m = pdata->mrr_val; |
| 1744 | mpsc_shared_regs.MPSC_RCRR_m= pdata->rcrr_val; |
| 1745 | mpsc_shared_regs.MPSC_TCRR_m= pdata->tcrr_val; |
| 1746 | mpsc_shared_regs.SDMA_INTR_CAUSE_m = |
| 1747 | pdata->intr_cause_val; |
| 1748 | mpsc_shared_regs.SDMA_INTR_MASK_m = |
| 1749 | pdata->intr_mask_val; |
| 1750 | |
| 1751 | rc = 0; |
| 1752 | } |
| 1753 | } |
| 1754 | |
| 1755 | return rc; |
| 1756 | } |
| 1757 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1758 | static int mpsc_shared_drv_remove(struct platform_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1759 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1760 | int rc = -ENODEV; |
| 1761 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1762 | if (dev->id == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1763 | mpsc_shared_unmap_regs(); |
| 1764 | mpsc_shared_regs.MPSC_MRR_m = 0; |
| 1765 | mpsc_shared_regs.MPSC_RCRR_m = 0; |
| 1766 | mpsc_shared_regs.MPSC_TCRR_m = 0; |
| 1767 | mpsc_shared_regs.SDMA_INTR_CAUSE_m = 0; |
| 1768 | mpsc_shared_regs.SDMA_INTR_MASK_m = 0; |
| 1769 | rc = 0; |
| 1770 | } |
| 1771 | |
| 1772 | return rc; |
| 1773 | } |
| 1774 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1775 | static struct platform_driver mpsc_shared_driver = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1776 | .probe = mpsc_shared_drv_probe, |
| 1777 | .remove = mpsc_shared_drv_remove, |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1778 | .driver = { |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1779 | .name = MPSC_SHARED_NAME, |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1780 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1781 | }; |
| 1782 | |
| 1783 | /* |
| 1784 | ****************************************************************************** |
| 1785 | * |
| 1786 | * Driver Interface Routines |
| 1787 | * |
| 1788 | ****************************************************************************** |
| 1789 | */ |
| 1790 | static struct uart_driver mpsc_reg = { |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1791 | .owner = THIS_MODULE, |
| 1792 | .driver_name = MPSC_DRIVER_NAME, |
| 1793 | .dev_name = MPSC_DEV_NAME, |
| 1794 | .major = MPSC_MAJOR, |
| 1795 | .minor = MPSC_MINOR_START, |
| 1796 | .nr = MPSC_NUM_CTLRS, |
| 1797 | .cons = MPSC_CONSOLE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1798 | }; |
| 1799 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1800 | static int mpsc_drv_map_regs(struct mpsc_port_info *pi, |
| 1801 | struct platform_device *pd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1802 | { |
| 1803 | struct resource *r; |
| 1804 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1805 | if ((r = platform_get_resource(pd, IORESOURCE_MEM, MPSC_BASE_ORDER)) |
| 1806 | && request_mem_region(r->start, MPSC_REG_BLOCK_SIZE, |
| 1807 | "mpsc_regs")) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1808 | pi->mpsc_base = ioremap(r->start, MPSC_REG_BLOCK_SIZE); |
| 1809 | pi->mpsc_base_p = r->start; |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1810 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1811 | mpsc_resource_err("MPSC base"); |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1812 | goto err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1813 | } |
| 1814 | |
| 1815 | if ((r = platform_get_resource(pd, IORESOURCE_MEM, |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1816 | MPSC_SDMA_BASE_ORDER)) |
| 1817 | && request_mem_region(r->start, |
| 1818 | MPSC_SDMA_REG_BLOCK_SIZE, "sdma_regs")) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1819 | pi->sdma_base = ioremap(r->start,MPSC_SDMA_REG_BLOCK_SIZE); |
| 1820 | pi->sdma_base_p = r->start; |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1821 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1822 | mpsc_resource_err("SDMA base"); |
Amol Lad | a141a04 | 2006-09-30 23:29:24 -0700 | [diff] [blame] | 1823 | if (pi->mpsc_base) { |
| 1824 | iounmap(pi->mpsc_base); |
| 1825 | pi->mpsc_base = NULL; |
| 1826 | } |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1827 | goto err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1828 | } |
| 1829 | |
| 1830 | if ((r = platform_get_resource(pd,IORESOURCE_MEM,MPSC_BRG_BASE_ORDER)) |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1831 | && request_mem_region(r->start, |
| 1832 | MPSC_BRG_REG_BLOCK_SIZE, "brg_regs")) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1833 | pi->brg_base = ioremap(r->start, MPSC_BRG_REG_BLOCK_SIZE); |
| 1834 | pi->brg_base_p = r->start; |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1835 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1836 | mpsc_resource_err("BRG base"); |
Amol Lad | a141a04 | 2006-09-30 23:29:24 -0700 | [diff] [blame] | 1837 | if (pi->mpsc_base) { |
| 1838 | iounmap(pi->mpsc_base); |
| 1839 | pi->mpsc_base = NULL; |
| 1840 | } |
| 1841 | if (pi->sdma_base) { |
| 1842 | iounmap(pi->sdma_base); |
| 1843 | pi->sdma_base = NULL; |
| 1844 | } |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1845 | goto err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1846 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1847 | return 0; |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1848 | |
| 1849 | err: |
| 1850 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1851 | } |
| 1852 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1853 | static void mpsc_drv_unmap_regs(struct mpsc_port_info *pi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1854 | { |
| 1855 | if (!pi->mpsc_base) { |
| 1856 | iounmap(pi->mpsc_base); |
| 1857 | release_mem_region(pi->mpsc_base_p, MPSC_REG_BLOCK_SIZE); |
| 1858 | } |
| 1859 | if (!pi->sdma_base) { |
| 1860 | iounmap(pi->sdma_base); |
| 1861 | release_mem_region(pi->sdma_base_p, MPSC_SDMA_REG_BLOCK_SIZE); |
| 1862 | } |
| 1863 | if (!pi->brg_base) { |
| 1864 | iounmap(pi->brg_base); |
| 1865 | release_mem_region(pi->brg_base_p, MPSC_BRG_REG_BLOCK_SIZE); |
| 1866 | } |
| 1867 | |
Al Viro | 2c6e759 | 2005-04-25 18:32:12 -0700 | [diff] [blame] | 1868 | pi->mpsc_base = NULL; |
| 1869 | pi->sdma_base = NULL; |
| 1870 | pi->brg_base = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1871 | |
| 1872 | pi->mpsc_base_p = 0; |
| 1873 | pi->sdma_base_p = 0; |
| 1874 | pi->brg_base_p = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1875 | } |
| 1876 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1877 | static void mpsc_drv_get_platform_data(struct mpsc_port_info *pi, |
| 1878 | struct platform_device *pd, int num) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1879 | { |
| 1880 | struct mpsc_pdata *pdata; |
| 1881 | |
| 1882 | pdata = (struct mpsc_pdata *)pd->dev.platform_data; |
| 1883 | |
| 1884 | pi->port.uartclk = pdata->brg_clk_freq; |
| 1885 | pi->port.iotype = UPIO_MEM; |
| 1886 | pi->port.line = num; |
| 1887 | pi->port.type = PORT_MPSC; |
| 1888 | pi->port.fifosize = MPSC_TXBE_SIZE; |
| 1889 | pi->port.membase = pi->mpsc_base; |
| 1890 | pi->port.mapbase = (ulong)pi->mpsc_base; |
| 1891 | pi->port.ops = &mpsc_pops; |
| 1892 | |
| 1893 | pi->mirror_regs = pdata->mirror_regs; |
| 1894 | pi->cache_mgmt = pdata->cache_mgmt; |
| 1895 | pi->brg_can_tune = pdata->brg_can_tune; |
| 1896 | pi->brg_clk_src = pdata->brg_clk_src; |
| 1897 | pi->mpsc_max_idle = pdata->max_idle; |
| 1898 | pi->default_baud = pdata->default_baud; |
| 1899 | pi->default_bits = pdata->default_bits; |
| 1900 | pi->default_parity = pdata->default_parity; |
| 1901 | pi->default_flow = pdata->default_flow; |
| 1902 | |
| 1903 | /* Initial values of mirrored regs */ |
| 1904 | pi->MPSC_CHR_1_m = pdata->chr_1_val; |
| 1905 | pi->MPSC_CHR_2_m = pdata->chr_2_val; |
| 1906 | pi->MPSC_CHR_10_m = pdata->chr_10_val; |
| 1907 | pi->MPSC_MPCR_m = pdata->mpcr_val; |
| 1908 | pi->BRG_BCR_m = pdata->bcr_val; |
| 1909 | |
| 1910 | pi->shared_regs = &mpsc_shared_regs; |
| 1911 | |
| 1912 | pi->port.irq = platform_get_irq(pd, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1913 | } |
| 1914 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1915 | static int mpsc_drv_probe(struct platform_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1916 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1917 | struct mpsc_port_info *pi; |
| 1918 | int rc = -ENODEV; |
| 1919 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1920 | pr_debug("mpsc_drv_probe: Adding MPSC %d\n", dev->id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1921 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1922 | if (dev->id < MPSC_NUM_CTLRS) { |
| 1923 | pi = &mpsc_ports[dev->id]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1924 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1925 | if (!(rc = mpsc_drv_map_regs(pi, dev))) { |
| 1926 | mpsc_drv_get_platform_data(pi, dev, dev->id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1927 | |
Dave Jiang | 1733310 | 2007-05-06 14:48:50 -0700 | [diff] [blame] | 1928 | if (!(rc = mpsc_make_ready(pi))) { |
| 1929 | spin_lock_init(&pi->tx_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1930 | if (!(rc = uart_add_one_port(&mpsc_reg, |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1931 | &pi->port))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1932 | rc = 0; |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1933 | } else { |
| 1934 | mpsc_release_port((struct uart_port *) |
| 1935 | pi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1936 | mpsc_drv_unmap_regs(pi); |
| 1937 | } |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1938 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1939 | mpsc_drv_unmap_regs(pi); |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1940 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1941 | } |
| 1942 | } |
| 1943 | |
| 1944 | return rc; |
| 1945 | } |
| 1946 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1947 | static int mpsc_drv_remove(struct platform_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1948 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1949 | pr_debug("mpsc_drv_exit: Removing MPSC %d\n", dev->id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1950 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1951 | if (dev->id < MPSC_NUM_CTLRS) { |
| 1952 | uart_remove_one_port(&mpsc_reg, &mpsc_ports[dev->id].port); |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1953 | mpsc_release_port((struct uart_port *) |
| 1954 | &mpsc_ports[dev->id].port); |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1955 | mpsc_drv_unmap_regs(&mpsc_ports[dev->id]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1956 | return 0; |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1957 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1958 | return -ENODEV; |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1959 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1960 | } |
| 1961 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1962 | static struct platform_driver mpsc_driver = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1963 | .probe = mpsc_drv_probe, |
| 1964 | .remove = mpsc_drv_remove, |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1965 | .driver = { |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1966 | .name = MPSC_CTLR_NAME, |
Kay Sievers | e169c13 | 2008-04-15 14:34:35 -0700 | [diff] [blame] | 1967 | .owner = THIS_MODULE, |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1968 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1969 | }; |
| 1970 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1971 | static int __init mpsc_drv_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1972 | { |
| 1973 | int rc; |
| 1974 | |
| 1975 | printk(KERN_INFO "Serial: MPSC driver $Revision: 1.00 $\n"); |
| 1976 | |
| 1977 | memset(mpsc_ports, 0, sizeof(mpsc_ports)); |
| 1978 | memset(&mpsc_shared_regs, 0, sizeof(mpsc_shared_regs)); |
| 1979 | |
| 1980 | if (!(rc = uart_register_driver(&mpsc_reg))) { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1981 | if (!(rc = platform_driver_register(&mpsc_shared_driver))) { |
| 1982 | if ((rc = platform_driver_register(&mpsc_driver))) { |
| 1983 | platform_driver_unregister(&mpsc_shared_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1984 | uart_unregister_driver(&mpsc_reg); |
| 1985 | } |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1986 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1987 | uart_unregister_driver(&mpsc_reg); |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1988 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1989 | } |
| 1990 | |
| 1991 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1992 | } |
| 1993 | |
Mark A. Greer | 2e89db7 | 2007-07-31 00:39:01 -0700 | [diff] [blame] | 1994 | static void __exit mpsc_drv_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1995 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1996 | platform_driver_unregister(&mpsc_driver); |
| 1997 | platform_driver_unregister(&mpsc_shared_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1998 | uart_unregister_driver(&mpsc_reg); |
| 1999 | memset(mpsc_ports, 0, sizeof(mpsc_ports)); |
| 2000 | memset(&mpsc_shared_regs, 0, sizeof(mpsc_shared_regs)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2001 | } |
| 2002 | |
| 2003 | module_init(mpsc_drv_init); |
| 2004 | module_exit(mpsc_drv_exit); |
| 2005 | |
| 2006 | MODULE_AUTHOR("Mark A. Greer <mgreer@mvista.com>"); |
| 2007 | MODULE_DESCRIPTION("Generic Marvell MPSC serial/UART driver $Revision: 1.00 $"); |
| 2008 | MODULE_VERSION(MPSC_VERSION); |
| 2009 | MODULE_LICENSE("GPL"); |
| 2010 | MODULE_ALIAS_CHARDEV_MAJOR(MPSC_MAJOR); |
Kay Sievers | e169c13 | 2008-04-15 14:34:35 -0700 | [diff] [blame] | 2011 | MODULE_ALIAS("platform:" MPSC_CTLR_NAME); |