4 * Copyright (C) 2001 IBM Corporation. All rights reserved.
6 * Serial device driver.
8 * Based on code from serial.c
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #define SERIAL_DO_RESTART
26 #include <linux/module.h>
27 #include <linux/kernel.h>
28 #include <linux/errno.h>
29 #include <linux/signal.h>
30 #include <linux/timer.h>
31 #include <linux/interrupt.h>
32 #include <linux/tty.h>
33 #include <linux/termios.h>
35 #include <linux/tty_flip.h>
36 #include <linux/serial.h>
37 #include <linux/serial_reg.h>
38 #include <linux/major.h>
39 #include <linux/string.h>
40 #include <linux/fcntl.h>
41 #include <linux/ptrace.h>
42 #include <linux/ioport.h>
44 #include <linux/slab.h>
45 #include <linux/init.h>
46 #include <linux/delay.h>
47 #include <linux/pci.h>
48 #include <linux/vmalloc.h>
49 #include <linux/smp.h>
50 #include <linux/spinlock.h>
51 #include <linux/kref.h>
52 #include <linux/firmware.h>
53 #include <linux/bitops.h>
55 #include <asm/system.h>
58 #include <asm/uaccess.h>
62 /*#define ICOM_TRACE enable port trace capabilities */
64 #define ICOM_DRIVER_NAME "icom"
65 #define ICOM_VERSION_STR "1.3.1"
67 #define ICOM_PORT ((struct icom_port *)port)
68 #define to_icom_adapter(d) container_of(d, struct icom_adapter, kref)
70 static const struct pci_device_id icom_pci_table[] = {
72 .vendor = PCI_VENDOR_ID_IBM,
73 .device = PCI_DEVICE_ID_IBM_ICOM_DEV_ID_1,
74 .subvendor = PCI_ANY_ID,
75 .subdevice = PCI_ANY_ID,
76 .driver_data = ADAPTER_V1,
79 .vendor = PCI_VENDOR_ID_IBM,
80 .device = PCI_DEVICE_ID_IBM_ICOM_DEV_ID_2,
81 .subvendor = PCI_VENDOR_ID_IBM,
82 .subdevice = PCI_DEVICE_ID_IBM_ICOM_V2_TWO_PORTS_RVX,
83 .driver_data = ADAPTER_V2,
86 .vendor = PCI_VENDOR_ID_IBM,
87 .device = PCI_DEVICE_ID_IBM_ICOM_DEV_ID_2,
88 .subvendor = PCI_VENDOR_ID_IBM,
89 .subdevice = PCI_DEVICE_ID_IBM_ICOM_V2_ONE_PORT_RVX_ONE_PORT_MDM,
90 .driver_data = ADAPTER_V2,
93 .vendor = PCI_VENDOR_ID_IBM,
94 .device = PCI_DEVICE_ID_IBM_ICOM_DEV_ID_2,
95 .subvendor = PCI_VENDOR_ID_IBM,
96 .subdevice = PCI_DEVICE_ID_IBM_ICOM_FOUR_PORT_MODEL,
97 .driver_data = ADAPTER_V2,
100 .vendor = PCI_VENDOR_ID_IBM,
101 .device = PCI_DEVICE_ID_IBM_ICOM_DEV_ID_2,
102 .subvendor = PCI_VENDOR_ID_IBM,
103 .subdevice = PCI_DEVICE_ID_IBM_ICOM_V2_ONE_PORT_RVX_ONE_PORT_MDM_PCIE,
104 .driver_data = ADAPTER_V2,
109 struct lookup_proc_table start_proc[4] = {
110 {NULL, ICOM_CONTROL_START_A},
111 {NULL, ICOM_CONTROL_START_B},
112 {NULL, ICOM_CONTROL_START_C},
113 {NULL, ICOM_CONTROL_START_D}
117 struct lookup_proc_table stop_proc[4] = {
118 {NULL, ICOM_CONTROL_STOP_A},
119 {NULL, ICOM_CONTROL_STOP_B},
120 {NULL, ICOM_CONTROL_STOP_C},
121 {NULL, ICOM_CONTROL_STOP_D}
124 struct lookup_int_table int_mask_tbl[4] = {
125 {NULL, ICOM_INT_MASK_PRC_A},
126 {NULL, ICOM_INT_MASK_PRC_B},
127 {NULL, ICOM_INT_MASK_PRC_C},
128 {NULL, ICOM_INT_MASK_PRC_D},
132 MODULE_DEVICE_TABLE(pci, icom_pci_table);
134 static LIST_HEAD(icom_adapter_head);
136 /* spinlock for adapter initialization and changing adapter operations */
137 static spinlock_t icom_lock;
140 static inline void trace(struct icom_port *, char *, unsigned long) {};
142 static inline void trace(struct icom_port *icom_port, char *trace_pt, unsigned long trace_data) {};
144 static void icom_kref_release(struct kref *kref);
146 static void free_port_memory(struct icom_port *icom_port)
148 struct pci_dev *dev = icom_port->adapter->pci_dev;
150 trace(icom_port, "RET_PORT_MEM", 0);
151 if (icom_port->recv_buf) {
152 pci_free_consistent(dev, 4096, icom_port->recv_buf,
153 icom_port->recv_buf_pci);
154 icom_port->recv_buf = NULL;
156 if (icom_port->xmit_buf) {
157 pci_free_consistent(dev, 4096, icom_port->xmit_buf,
158 icom_port->xmit_buf_pci);
159 icom_port->xmit_buf = NULL;
161 if (icom_port->statStg) {
162 pci_free_consistent(dev, 4096, icom_port->statStg,
163 icom_port->statStg_pci);
164 icom_port->statStg = NULL;
167 if (icom_port->xmitRestart) {
168 pci_free_consistent(dev, 4096, icom_port->xmitRestart,
169 icom_port->xmitRestart_pci);
170 icom_port->xmitRestart = NULL;
174 static int __devinit get_port_memory(struct icom_port *icom_port)
177 unsigned long stgAddr;
178 unsigned long startStgAddr;
179 unsigned long offset;
180 struct pci_dev *dev = icom_port->adapter->pci_dev;
182 icom_port->xmit_buf =
183 pci_alloc_consistent(dev, 4096, &icom_port->xmit_buf_pci);
184 if (!icom_port->xmit_buf) {
185 dev_err(&dev->dev, "Can not allocate Transmit buffer\n");
189 trace(icom_port, "GET_PORT_MEM",
190 (unsigned long) icom_port->xmit_buf);
192 icom_port->recv_buf =
193 pci_alloc_consistent(dev, 4096, &icom_port->recv_buf_pci);
194 if (!icom_port->recv_buf) {
195 dev_err(&dev->dev, "Can not allocate Receive buffer\n");
196 free_port_memory(icom_port);
199 trace(icom_port, "GET_PORT_MEM",
200 (unsigned long) icom_port->recv_buf);
203 pci_alloc_consistent(dev, 4096, &icom_port->statStg_pci);
204 if (!icom_port->statStg) {
205 dev_err(&dev->dev, "Can not allocate Status buffer\n");
206 free_port_memory(icom_port);
209 trace(icom_port, "GET_PORT_MEM",
210 (unsigned long) icom_port->statStg);
212 icom_port->xmitRestart =
213 pci_alloc_consistent(dev, 4096, &icom_port->xmitRestart_pci);
214 if (!icom_port->xmitRestart) {
216 "Can not allocate xmit Restart buffer\n");
217 free_port_memory(icom_port);
221 memset(icom_port->statStg, 0, 4096);
223 /* FODs: Frame Out Descriptor Queue, this is a FIFO queue that
224 indicates that frames are to be transmitted
227 stgAddr = (unsigned long) icom_port->statStg;
228 for (index = 0; index < NUM_XBUFFS; index++) {
229 trace(icom_port, "FOD_ADDR", stgAddr);
230 stgAddr = stgAddr + sizeof(icom_port->statStg->xmit[0]);
231 if (index < (NUM_XBUFFS - 1)) {
232 memset(&icom_port->statStg->xmit[index], 0, sizeof(struct xmit_status_area));
233 icom_port->statStg->xmit[index].leLengthASD =
234 (unsigned short int) cpu_to_le16(XMIT_BUFF_SZ);
235 trace(icom_port, "FOD_ADDR", stgAddr);
236 trace(icom_port, "FOD_XBUFF",
237 (unsigned long) icom_port->xmit_buf);
238 icom_port->statStg->xmit[index].leBuffer =
239 cpu_to_le32(icom_port->xmit_buf_pci);
240 } else if (index == (NUM_XBUFFS - 1)) {
241 memset(&icom_port->statStg->xmit[index], 0, sizeof(struct xmit_status_area));
242 icom_port->statStg->xmit[index].leLengthASD =
243 (unsigned short int) cpu_to_le16(XMIT_BUFF_SZ);
244 trace(icom_port, "FOD_XBUFF",
245 (unsigned long) icom_port->xmit_buf);
246 icom_port->statStg->xmit[index].leBuffer =
247 cpu_to_le32(icom_port->xmit_buf_pci);
249 memset(&icom_port->statStg->xmit[index], 0, sizeof(struct xmit_status_area));
253 startStgAddr = stgAddr;
255 /* fill in every entry, even if no buffer */
256 for (index = 0; index < NUM_RBUFFS; index++) {
257 trace(icom_port, "FID_ADDR", stgAddr);
258 stgAddr = stgAddr + sizeof(icom_port->statStg->rcv[0]);
259 icom_port->statStg->rcv[index].leLength = 0;
260 icom_port->statStg->rcv[index].WorkingLength =
261 (unsigned short int) cpu_to_le16(RCV_BUFF_SZ);
262 if (index < (NUM_RBUFFS - 1) ) {
263 offset = stgAddr - (unsigned long) icom_port->statStg;
264 icom_port->statStg->rcv[index].leNext =
265 cpu_to_le32(icom_port-> statStg_pci + offset);
266 trace(icom_port, "FID_RBUFF",
267 (unsigned long) icom_port->recv_buf);
268 icom_port->statStg->rcv[index].leBuffer =
269 cpu_to_le32(icom_port->recv_buf_pci);
270 } else if (index == (NUM_RBUFFS -1) ) {
271 offset = startStgAddr - (unsigned long) icom_port->statStg;
272 icom_port->statStg->rcv[index].leNext =
273 cpu_to_le32(icom_port-> statStg_pci + offset);
274 trace(icom_port, "FID_RBUFF",
275 (unsigned long) icom_port->recv_buf + 2048);
276 icom_port->statStg->rcv[index].leBuffer =
277 cpu_to_le32(icom_port->recv_buf_pci + 2048);
279 icom_port->statStg->rcv[index].leNext = 0;
280 icom_port->statStg->rcv[index].leBuffer = 0;
287 static void stop_processor(struct icom_port *icom_port)
293 spin_lock_irqsave(&icom_lock, flags);
295 port = icom_port->port;
296 if (port == 0 || port == 1)
297 stop_proc[port].global_control_reg = &icom_port->global_reg->control;
299 stop_proc[port].global_control_reg = &icom_port->global_reg->control_2;
303 temp = readl(stop_proc[port].global_control_reg);
305 (temp & ~start_proc[port].processor_id) | stop_proc[port].processor_id;
306 writel(temp, stop_proc[port].global_control_reg);
309 readl(stop_proc[port].global_control_reg);
311 dev_err(&icom_port->adapter->pci_dev->dev,
312 "Invalid port assignment\n");
315 spin_unlock_irqrestore(&icom_lock, flags);
318 static void start_processor(struct icom_port *icom_port)
324 spin_lock_irqsave(&icom_lock, flags);
326 port = icom_port->port;
327 if (port == 0 || port == 1)
328 start_proc[port].global_control_reg = &icom_port->global_reg->control;
330 start_proc[port].global_control_reg = &icom_port->global_reg->control_2;
332 temp = readl(start_proc[port].global_control_reg);
334 (temp & ~stop_proc[port].processor_id) | start_proc[port].processor_id;
335 writel(temp, start_proc[port].global_control_reg);
338 readl(start_proc[port].global_control_reg);
340 dev_err(&icom_port->adapter->pci_dev->dev,
341 "Invalid port assignment\n");
344 spin_unlock_irqrestore(&icom_lock, flags);
347 static void load_code(struct icom_port *icom_port)
349 const struct firmware *fw;
350 char __iomem *iram_ptr;
353 void __iomem *dram_ptr = icom_port->dram;
355 unsigned char *new_page = NULL;
356 unsigned char cable_id = NO_CABLE;
357 struct pci_dev *dev = icom_port->adapter->pci_dev;
359 /* Clear out any pending interrupts */
360 writew(0x3FFF, icom_port->int_reg);
362 trace(icom_port, "CLEAR_INTERRUPTS", 0);
365 stop_processor(icom_port);
368 memset_io(dram_ptr, 0, 512);
370 /* Load Call Setup into Adapter */
371 if (request_firmware(&fw, "icom_call_setup.bin", &dev->dev) < 0) {
372 dev_err(&dev->dev,"Unable to load icom_call_setup.bin firmware image\n");
377 if (fw->size > ICOM_DCE_IRAM_OFFSET) {
378 dev_err(&dev->dev, "Invalid firmware image for icom_call_setup.bin found.\n");
379 release_firmware(fw);
384 iram_ptr = (char __iomem *)icom_port->dram + ICOM_IRAM_OFFSET;
385 for (index = 0; index < fw->size; index++)
386 writeb(fw->data[index], &iram_ptr[index]);
388 release_firmware(fw);
390 /* Load Resident DCE portion of Adapter */
391 if (request_firmware(&fw, "icom_res_dce.bin", &dev->dev) < 0) {
392 dev_err(&dev->dev,"Unable to load icom_res_dce.bin firmware image\n");
397 if (fw->size > ICOM_IRAM_SIZE) {
398 dev_err(&dev->dev, "Invalid firmware image for icom_res_dce.bin found.\n");
399 release_firmware(fw);
404 iram_ptr = (char __iomem *) icom_port->dram + ICOM_IRAM_OFFSET;
405 for (index = ICOM_DCE_IRAM_OFFSET; index < fw->size; index++)
406 writeb(fw->data[index], &iram_ptr[index]);
408 release_firmware(fw);
410 /* Set Hardware level */
411 if ((icom_port->adapter->version | ADAPTER_V2) == ADAPTER_V2)
412 writeb(V2_HARDWARE, &(icom_port->dram->misc_flags));
414 /* Start the processor in Adapter */
415 start_processor(icom_port);
417 writeb((HDLC_PPP_PURE_ASYNC | HDLC_FF_FILL),
418 &(icom_port->dram->HDLCConfigReg));
419 writeb(0x04, &(icom_port->dram->FlagFillIdleTimer)); /* 0.5 seconds */
420 writeb(0x00, &(icom_port->dram->CmdReg));
421 writeb(0x10, &(icom_port->dram->async_config3));
422 writeb((ICOM_ACFG_DRIVE1 | ICOM_ACFG_NO_PARITY | ICOM_ACFG_8BPC |
423 ICOM_ACFG_1STOP_BIT), &(icom_port->dram->async_config2));
425 /*Set up data in icom DRAM to indicate where personality
426 *code is located and its length.
428 new_page = pci_alloc_consistent(dev, 4096, &temp_pci);
431 dev_err(&dev->dev, "Can not allocate DMA buffer\n");
436 if (request_firmware(&fw, "icom_asc.bin", &dev->dev) < 0) {
437 dev_err(&dev->dev,"Unable to load icom_asc.bin firmware image\n");
442 if (fw->size > ICOM_DCE_IRAM_OFFSET) {
443 dev_err(&dev->dev, "Invalid firmware image for icom_asc.bin found.\n");
444 release_firmware(fw);
449 for (index = 0; index < fw->size; index++)
450 new_page[index] = fw->data[index];
452 release_firmware(fw);
454 writeb((char) ((fw->size + 16)/16), &icom_port->dram->mac_length);
455 writel(temp_pci, &icom_port->dram->mac_load_addr);
457 /*Setting the syncReg to 0x80 causes adapter to start downloading
458 the personality code into adapter instruction RAM.
459 Once code is loaded, it will begin executing and, based on
460 information provided above, will start DMAing data from
461 shared memory to adapter DRAM.
463 /* the wait loop below verifies this write operation has been done
466 writeb(START_DOWNLOAD, &icom_port->dram->sync);
468 /* Wait max 1 Sec for data download and processor to start */
469 for (index = 0; index < 10; index++) {
471 if (readb(&icom_port->dram->misc_flags) & ICOM_HDW_ACTIVE)
481 cable_id = readb(&icom_port->dram->cable_id);
483 if (cable_id & ICOM_CABLE_ID_VALID) {
484 /* Get cable ID into the lower 4 bits (standard form) */
485 cable_id = (cable_id & ICOM_CABLE_ID_MASK) >> 4;
486 icom_port->cable_id = cable_id;
488 dev_err(&dev->dev,"Invalid or no cable attached\n");
489 icom_port->cable_id = NO_CABLE;
495 /* Clear out any pending interrupts */
496 writew(0x3FFF, icom_port->int_reg);
499 writeb(ICOM_DISABLE, &(icom_port->dram->disable));
502 stop_processor(icom_port);
504 dev_err(&icom_port->adapter->pci_dev->dev,"Port not opertional\n");
507 if (new_page != NULL)
508 pci_free_consistent(dev, 4096, new_page, temp_pci);
511 static int startup(struct icom_port *icom_port)
514 unsigned char cable_id, raw_cable_id;
518 trace(icom_port, "STARTUP", 0);
520 if (!icom_port->dram) {
521 /* should NEVER be NULL */
522 dev_err(&icom_port->adapter->pci_dev->dev,
523 "Unusable Port, port configuration missing\n");
530 raw_cable_id = readb(&icom_port->dram->cable_id);
531 trace(icom_port, "CABLE_ID", raw_cable_id);
533 /* Get cable ID into the lower 4 bits (standard form) */
534 cable_id = (raw_cable_id & ICOM_CABLE_ID_MASK) >> 4;
536 /* Check for valid Cable ID */
537 if (!(raw_cable_id & ICOM_CABLE_ID_VALID) ||
538 (cable_id != icom_port->cable_id)) {
540 /* reload adapter code, pick up any potential changes in cable id */
541 load_code(icom_port);
543 /* still no sign of cable, error out */
544 raw_cable_id = readb(&icom_port->dram->cable_id);
545 cable_id = (raw_cable_id & ICOM_CABLE_ID_MASK) >> 4;
546 if (!(raw_cable_id & ICOM_CABLE_ID_VALID) ||
547 (icom_port->cable_id == NO_CABLE))
552 * Finally, clear and enable interrupts
554 spin_lock_irqsave(&icom_lock, flags);
555 port = icom_port->port;
556 if (port == 0 || port == 1)
557 int_mask_tbl[port].global_int_mask = &icom_port->global_reg->int_mask;
559 int_mask_tbl[port].global_int_mask = &icom_port->global_reg->int_mask_2;
561 if (port == 0 || port == 2)
562 writew(0x00FF, icom_port->int_reg);
564 writew(0x3F00, icom_port->int_reg);
566 temp = readl(int_mask_tbl[port].global_int_mask);
567 writel(temp & ~int_mask_tbl[port].processor_id, int_mask_tbl[port].global_int_mask);
570 readl(int_mask_tbl[port].global_int_mask);
572 dev_err(&icom_port->adapter->pci_dev->dev,
573 "Invalid port assignment\n");
576 spin_unlock_irqrestore(&icom_lock, flags);
580 static void shutdown(struct icom_port *icom_port)
583 unsigned char cmdReg;
587 spin_lock_irqsave(&icom_lock, flags);
588 trace(icom_port, "SHUTDOWN", 0);
591 * disable all interrupts
593 port = icom_port->port;
594 if (port == 0 || port == 1)
595 int_mask_tbl[port].global_int_mask = &icom_port->global_reg->int_mask;
597 int_mask_tbl[port].global_int_mask = &icom_port->global_reg->int_mask_2;
600 temp = readl(int_mask_tbl[port].global_int_mask);
601 writel(temp | int_mask_tbl[port].processor_id, int_mask_tbl[port].global_int_mask);
604 readl(int_mask_tbl[port].global_int_mask);
606 dev_err(&icom_port->adapter->pci_dev->dev,
607 "Invalid port assignment\n");
609 spin_unlock_irqrestore(&icom_lock, flags);
612 * disable break condition
614 cmdReg = readb(&icom_port->dram->CmdReg);
615 if ((cmdReg | CMD_SND_BREAK) == CMD_SND_BREAK) {
616 writeb(cmdReg & ~CMD_SND_BREAK, &icom_port->dram->CmdReg);
620 static int icom_write(struct uart_port *port)
622 unsigned long data_count;
623 unsigned char cmdReg;
624 unsigned long offset;
625 int temp_tail = port->info->xmit.tail;
627 trace(ICOM_PORT, "WRITE", 0);
629 if (cpu_to_le16(ICOM_PORT->statStg->xmit[0].flags) &
630 SA_FLAGS_READY_TO_XMIT) {
631 trace(ICOM_PORT, "WRITE_FULL", 0);
636 while ((port->info->xmit.head != temp_tail) &&
637 (data_count <= XMIT_BUFF_SZ)) {
639 ICOM_PORT->xmit_buf[data_count++] =
640 port->info->xmit.buf[temp_tail];
643 temp_tail &= (UART_XMIT_SIZE - 1);
647 ICOM_PORT->statStg->xmit[0].flags =
648 cpu_to_le16(SA_FLAGS_READY_TO_XMIT);
649 ICOM_PORT->statStg->xmit[0].leLength =
650 cpu_to_le16(data_count);
652 (unsigned long) &ICOM_PORT->statStg->xmit[0] -
653 (unsigned long) ICOM_PORT->statStg;
654 *ICOM_PORT->xmitRestart =
655 cpu_to_le32(ICOM_PORT->statStg_pci + offset);
656 cmdReg = readb(&ICOM_PORT->dram->CmdReg);
657 writeb(cmdReg | CMD_XMIT_RCV_ENABLE,
658 &ICOM_PORT->dram->CmdReg);
659 writeb(START_XMIT, &ICOM_PORT->dram->StartXmitCmd);
660 trace(ICOM_PORT, "WRITE_START", data_count);
662 readb(&ICOM_PORT->dram->StartXmitCmd);
668 static inline void check_modem_status(struct icom_port *icom_port)
670 static char old_status = 0;
672 unsigned char status;
674 spin_lock(&icom_port->uart_port.lock);
676 /*modem input register */
677 status = readb(&icom_port->dram->isr);
678 trace(icom_port, "CHECK_MODEM", status);
679 delta_status = status ^ old_status;
681 if (delta_status & ICOM_RI)
682 icom_port->uart_port.icount.rng++;
683 if (delta_status & ICOM_DSR)
684 icom_port->uart_port.icount.dsr++;
685 if (delta_status & ICOM_DCD)
686 uart_handle_dcd_change(&icom_port->uart_port,
687 delta_status & ICOM_DCD);
688 if (delta_status & ICOM_CTS)
689 uart_handle_cts_change(&icom_port->uart_port,
690 delta_status & ICOM_CTS);
692 wake_up_interruptible(&icom_port->uart_port.info->
696 spin_unlock(&icom_port->uart_port.lock);
699 static void xmit_interrupt(u16 port_int_reg, struct icom_port *icom_port)
701 unsigned short int count;
704 if (port_int_reg & (INT_XMIT_COMPLETED)) {
705 trace(icom_port, "XMIT_COMPLETE", 0);
707 /* clear buffer in use bit */
708 icom_port->statStg->xmit[0].flags &=
709 cpu_to_le16(~SA_FLAGS_READY_TO_XMIT);
711 count = (unsigned short int)
712 cpu_to_le16(icom_port->statStg->xmit[0].leLength);
713 icom_port->uart_port.icount.tx += count;
716 !uart_circ_empty(&icom_port->uart_port.info->xmit); i++) {
718 icom_port->uart_port.info->xmit.tail++;
719 icom_port->uart_port.info->xmit.tail &=
720 (UART_XMIT_SIZE - 1);
723 if (!icom_write(&icom_port->uart_port))
724 /* activate write queue */
725 uart_write_wakeup(&icom_port->uart_port);
727 trace(icom_port, "XMIT_DISABLED", 0);
730 static void recv_interrupt(u16 port_int_reg, struct icom_port *icom_port)
732 short int count, rcv_buff;
733 struct tty_struct *tty = icom_port->uart_port.info->port.tty;
734 unsigned short int status;
735 struct uart_icount *icount;
736 unsigned long offset;
739 trace(icom_port, "RCV_COMPLETE", 0);
740 rcv_buff = icom_port->next_rcv;
742 status = cpu_to_le16(icom_port->statStg->rcv[rcv_buff].flags);
743 while (status & SA_FL_RCV_DONE) {
746 trace(icom_port, "FID_STATUS", status);
747 count = cpu_to_le16(icom_port->statStg->rcv[rcv_buff].leLength);
749 count = tty_buffer_request_room(tty, count);
750 trace(icom_port, "RCV_COUNT", count);
752 trace(icom_port, "REAL_COUNT", count);
755 cpu_to_le32(icom_port->statStg->rcv[rcv_buff].leBuffer) -
756 icom_port->recv_buf_pci;
758 /* Block copy all but the last byte as this may have status */
760 first = icom_port->recv_buf[offset];
761 tty_insert_flip_string(tty, icom_port->recv_buf + offset, count - 1);
764 icount = &icom_port->uart_port.icount;
767 /* Break detect logic */
768 if ((status & SA_FLAGS_FRAME_ERROR)
770 status &= ~SA_FLAGS_FRAME_ERROR;
771 status |= SA_FLAGS_BREAK_DET;
772 trace(icom_port, "BREAK_DET", 0);
778 (SA_FLAGS_BREAK_DET | SA_FLAGS_PARITY_ERROR |
779 SA_FLAGS_FRAME_ERROR | SA_FLAGS_OVERRUN)) {
781 if (status & SA_FLAGS_BREAK_DET)
783 if (status & SA_FLAGS_PARITY_ERROR)
785 if (status & SA_FLAGS_FRAME_ERROR)
787 if (status & SA_FLAGS_OVERRUN)
791 * Now check to see if character should be
792 * ignored, and mask off conditions which
795 if (status & icom_port->ignore_status_mask) {
796 trace(icom_port, "IGNORE_CHAR", 0);
800 status &= icom_port->read_status_mask;
802 if (status & SA_FLAGS_BREAK_DET) {
804 } else if (status & SA_FLAGS_PARITY_ERROR) {
805 trace(icom_port, "PARITY_ERROR", 0);
807 } else if (status & SA_FLAGS_FRAME_ERROR)
812 tty_insert_flip_char(tty, *(icom_port->recv_buf + offset + count - 1), flag);
814 if (status & SA_FLAGS_OVERRUN)
816 * Overrun is special, since it's
817 * reported immediately, and doesn't
818 * affect the current character
820 tty_insert_flip_char(tty, 0, TTY_OVERRUN);
822 icom_port->statStg->rcv[rcv_buff].flags = 0;
823 icom_port->statStg->rcv[rcv_buff].leLength = 0;
824 icom_port->statStg->rcv[rcv_buff].WorkingLength =
825 (unsigned short int) cpu_to_le16(RCV_BUFF_SZ);
828 if (rcv_buff == NUM_RBUFFS)
831 status = cpu_to_le16(icom_port->statStg->rcv[rcv_buff].flags);
833 icom_port->next_rcv = rcv_buff;
834 tty_flip_buffer_push(tty);
837 static void process_interrupt(u16 port_int_reg,
838 struct icom_port *icom_port)
841 spin_lock(&icom_port->uart_port.lock);
842 trace(icom_port, "INTERRUPT", port_int_reg);
844 if (port_int_reg & (INT_XMIT_COMPLETED | INT_XMIT_DISABLED))
845 xmit_interrupt(port_int_reg, icom_port);
847 if (port_int_reg & INT_RCV_COMPLETED)
848 recv_interrupt(port_int_reg, icom_port);
850 spin_unlock(&icom_port->uart_port.lock);
853 static irqreturn_t icom_interrupt(int irq, void *dev_id)
855 void __iomem * int_reg;
856 u32 adapter_interrupts;
858 struct icom_adapter *icom_adapter;
859 struct icom_port *icom_port;
861 /* find icom_port for this interrupt */
862 icom_adapter = (struct icom_adapter *) dev_id;
864 if ((icom_adapter->version | ADAPTER_V2) == ADAPTER_V2) {
865 int_reg = icom_adapter->base_addr + 0x8024;
867 adapter_interrupts = readl(int_reg);
869 if (adapter_interrupts & 0x00003FFF) {
870 /* port 2 interrupt, NOTE: for all ADAPTER_V2, port 2 will be active */
871 icom_port = &icom_adapter->port_info[2];
872 port_int_reg = (u16) adapter_interrupts;
873 process_interrupt(port_int_reg, icom_port);
874 check_modem_status(icom_port);
876 if (adapter_interrupts & 0x3FFF0000) {
877 /* port 3 interrupt */
878 icom_port = &icom_adapter->port_info[3];
879 if (icom_port->status == ICOM_PORT_ACTIVE) {
881 (u16) (adapter_interrupts >> 16);
882 process_interrupt(port_int_reg, icom_port);
883 check_modem_status(icom_port);
887 /* Clear out any pending interrupts */
888 writel(adapter_interrupts, int_reg);
890 int_reg = icom_adapter->base_addr + 0x8004;
892 int_reg = icom_adapter->base_addr + 0x4004;
895 adapter_interrupts = readl(int_reg);
897 if (adapter_interrupts & 0x00003FFF) {
898 /* port 0 interrupt, NOTE: for all adapters, port 0 will be active */
899 icom_port = &icom_adapter->port_info[0];
900 port_int_reg = (u16) adapter_interrupts;
901 process_interrupt(port_int_reg, icom_port);
902 check_modem_status(icom_port);
904 if (adapter_interrupts & 0x3FFF0000) {
905 /* port 1 interrupt */
906 icom_port = &icom_adapter->port_info[1];
907 if (icom_port->status == ICOM_PORT_ACTIVE) {
908 port_int_reg = (u16) (adapter_interrupts >> 16);
909 process_interrupt(port_int_reg, icom_port);
910 check_modem_status(icom_port);
914 /* Clear out any pending interrupts */
915 writel(adapter_interrupts, int_reg);
917 /* flush the write */
918 adapter_interrupts = readl(int_reg);
924 * ------------------------------------------------------------------
925 * Begin serial-core API
926 * ------------------------------------------------------------------
928 static unsigned int icom_tx_empty(struct uart_port *port)
933 spin_lock_irqsave(&port->lock, flags);
934 if (cpu_to_le16(ICOM_PORT->statStg->xmit[0].flags) &
935 SA_FLAGS_READY_TO_XMIT)
940 spin_unlock_irqrestore(&port->lock, flags);
944 static void icom_set_mctrl(struct uart_port *port, unsigned int mctrl)
946 unsigned char local_osr;
948 trace(ICOM_PORT, "SET_MODEM", 0);
949 local_osr = readb(&ICOM_PORT->dram->osr);
951 if (mctrl & TIOCM_RTS) {
952 trace(ICOM_PORT, "RAISE_RTS", 0);
953 local_osr |= ICOM_RTS;
955 trace(ICOM_PORT, "LOWER_RTS", 0);
956 local_osr &= ~ICOM_RTS;
959 if (mctrl & TIOCM_DTR) {
960 trace(ICOM_PORT, "RAISE_DTR", 0);
961 local_osr |= ICOM_DTR;
963 trace(ICOM_PORT, "LOWER_DTR", 0);
964 local_osr &= ~ICOM_DTR;
967 writeb(local_osr, &ICOM_PORT->dram->osr);
970 static unsigned int icom_get_mctrl(struct uart_port *port)
972 unsigned char status;
975 trace(ICOM_PORT, "GET_MODEM", 0);
977 status = readb(&ICOM_PORT->dram->isr);
979 result = ((status & ICOM_DCD) ? TIOCM_CAR : 0)
980 | ((status & ICOM_RI) ? TIOCM_RNG : 0)
981 | ((status & ICOM_DSR) ? TIOCM_DSR : 0)
982 | ((status & ICOM_CTS) ? TIOCM_CTS : 0);
986 static void icom_stop_tx(struct uart_port *port)
988 unsigned char cmdReg;
990 trace(ICOM_PORT, "STOP", 0);
991 cmdReg = readb(&ICOM_PORT->dram->CmdReg);
992 writeb(cmdReg | CMD_HOLD_XMIT, &ICOM_PORT->dram->CmdReg);
995 static void icom_start_tx(struct uart_port *port)
997 unsigned char cmdReg;
999 trace(ICOM_PORT, "START", 0);
1000 cmdReg = readb(&ICOM_PORT->dram->CmdReg);
1001 if ((cmdReg & CMD_HOLD_XMIT) == CMD_HOLD_XMIT)
1002 writeb(cmdReg & ~CMD_HOLD_XMIT,
1003 &ICOM_PORT->dram->CmdReg);
1008 static void icom_send_xchar(struct uart_port *port, char ch)
1010 unsigned char xdata;
1012 unsigned long flags;
1014 trace(ICOM_PORT, "SEND_XCHAR", ch);
1016 /* wait .1 sec to send char */
1017 for (index = 0; index < 10; index++) {
1018 spin_lock_irqsave(&port->lock, flags);
1019 xdata = readb(&ICOM_PORT->dram->xchar);
1020 if (xdata == 0x00) {
1021 trace(ICOM_PORT, "QUICK_WRITE", 0);
1022 writeb(ch, &ICOM_PORT->dram->xchar);
1024 /* flush write operation */
1025 xdata = readb(&ICOM_PORT->dram->xchar);
1026 spin_unlock_irqrestore(&port->lock, flags);
1029 spin_unlock_irqrestore(&port->lock, flags);
1034 static void icom_stop_rx(struct uart_port *port)
1036 unsigned char cmdReg;
1038 cmdReg = readb(&ICOM_PORT->dram->CmdReg);
1039 writeb(cmdReg & ~CMD_RCV_ENABLE, &ICOM_PORT->dram->CmdReg);
1042 static void icom_enable_ms(struct uart_port *port)
1047 static void icom_break(struct uart_port *port, int break_state)
1049 unsigned char cmdReg;
1050 unsigned long flags;
1052 spin_lock_irqsave(&port->lock, flags);
1053 trace(ICOM_PORT, "BREAK", 0);
1054 cmdReg = readb(&ICOM_PORT->dram->CmdReg);
1055 if (break_state == -1) {
1056 writeb(cmdReg | CMD_SND_BREAK, &ICOM_PORT->dram->CmdReg);
1058 writeb(cmdReg & ~CMD_SND_BREAK, &ICOM_PORT->dram->CmdReg);
1060 spin_unlock_irqrestore(&port->lock, flags);
1063 static int icom_open(struct uart_port *port)
1067 kref_get(&ICOM_PORT->adapter->kref);
1068 retval = startup(ICOM_PORT);
1071 kref_put(&ICOM_PORT->adapter->kref, icom_kref_release);
1072 trace(ICOM_PORT, "STARTUP_ERROR", 0);
1079 static void icom_close(struct uart_port *port)
1081 unsigned char cmdReg;
1083 trace(ICOM_PORT, "CLOSE", 0);
1086 cmdReg = readb(&ICOM_PORT->dram->CmdReg);
1087 writeb(cmdReg & (unsigned char) ~CMD_RCV_ENABLE,
1088 &ICOM_PORT->dram->CmdReg);
1090 shutdown(ICOM_PORT);
1092 kref_put(&ICOM_PORT->adapter->kref, icom_kref_release);
1095 static void icom_set_termios(struct uart_port *port,
1096 struct ktermios *termios,
1097 struct ktermios *old_termios)
1100 unsigned cflag, iflag;
1102 char new_config3 = 0;
1105 int rcv_buff, xmit_buff;
1106 unsigned long offset;
1107 unsigned long flags;
1109 spin_lock_irqsave(&port->lock, flags);
1110 trace(ICOM_PORT, "CHANGE_SPEED", 0);
1112 cflag = termios->c_cflag;
1113 iflag = termios->c_iflag;
1115 new_config2 = ICOM_ACFG_DRIVE1;
1117 /* byte size and parity */
1118 switch (cflag & CSIZE) {
1119 case CS5: /* 5 bits/char */
1120 new_config2 |= ICOM_ACFG_5BPC;
1122 case CS6: /* 6 bits/char */
1123 new_config2 |= ICOM_ACFG_6BPC;
1125 case CS7: /* 7 bits/char */
1126 new_config2 |= ICOM_ACFG_7BPC;
1128 case CS8: /* 8 bits/char */
1129 new_config2 |= ICOM_ACFG_8BPC;
1134 if (cflag & CSTOPB) {
1136 new_config2 |= ICOM_ACFG_2STOP_BIT;
1138 if (cflag & PARENB) {
1139 /* parity bit enabled */
1140 new_config2 |= ICOM_ACFG_PARITY_ENAB;
1141 trace(ICOM_PORT, "PARENB", 0);
1143 if (cflag & PARODD) {
1145 new_config2 |= ICOM_ACFG_PARITY_ODD;
1146 trace(ICOM_PORT, "PARODD", 0);
1149 /* Determine divisor based on baud rate */
1150 baud = uart_get_baud_rate(port, termios, old_termios,
1152 icom_acfg_baud[BAUD_TABLE_LIMIT]);
1154 baud = 9600; /* B0 transition handled in rs_set_termios */
1156 for (index = 0; index < BAUD_TABLE_LIMIT; index++) {
1157 if (icom_acfg_baud[index] == baud) {
1158 new_config3 = index;
1163 uart_update_timeout(port, cflag, baud);
1165 /* CTS flow control flag and modem status interrupts */
1166 tmp_byte = readb(&(ICOM_PORT->dram->HDLCConfigReg));
1167 if (cflag & CRTSCTS)
1168 tmp_byte |= HDLC_HDW_FLOW;
1170 tmp_byte &= ~HDLC_HDW_FLOW;
1171 writeb(tmp_byte, &(ICOM_PORT->dram->HDLCConfigReg));
1174 * Set up parity check flag
1176 ICOM_PORT->read_status_mask = SA_FLAGS_OVERRUN | SA_FL_RCV_DONE;
1178 ICOM_PORT->read_status_mask |=
1179 SA_FLAGS_FRAME_ERROR | SA_FLAGS_PARITY_ERROR;
1181 if ((iflag & BRKINT) || (iflag & PARMRK))
1182 ICOM_PORT->read_status_mask |= SA_FLAGS_BREAK_DET;
1185 * Characters to ignore
1187 ICOM_PORT->ignore_status_mask = 0;
1189 ICOM_PORT->ignore_status_mask |=
1190 SA_FLAGS_PARITY_ERROR | SA_FLAGS_FRAME_ERROR;
1191 if (iflag & IGNBRK) {
1192 ICOM_PORT->ignore_status_mask |= SA_FLAGS_BREAK_DET;
1194 * If we're ignore parity and break indicators, ignore
1195 * overruns too. (For real raw support).
1198 ICOM_PORT->ignore_status_mask |= SA_FLAGS_OVERRUN;
1202 * !!! ignore all characters if CREAD is not set
1204 if ((cflag & CREAD) == 0)
1205 ICOM_PORT->ignore_status_mask |= SA_FL_RCV_DONE;
1207 /* Turn off Receiver to prepare for reset */
1208 writeb(CMD_RCV_DISABLE, &ICOM_PORT->dram->CmdReg);
1210 for (index = 0; index < 10; index++) {
1211 if (readb(&ICOM_PORT->dram->PrevCmdReg) == 0x00) {
1216 /* clear all current buffers of data */
1217 for (rcv_buff = 0; rcv_buff < NUM_RBUFFS; rcv_buff++) {
1218 ICOM_PORT->statStg->rcv[rcv_buff].flags = 0;
1219 ICOM_PORT->statStg->rcv[rcv_buff].leLength = 0;
1220 ICOM_PORT->statStg->rcv[rcv_buff].WorkingLength =
1221 (unsigned short int) cpu_to_le16(RCV_BUFF_SZ);
1224 for (xmit_buff = 0; xmit_buff < NUM_XBUFFS; xmit_buff++) {
1225 ICOM_PORT->statStg->xmit[xmit_buff].flags = 0;
1228 /* activate changes and start xmit and receiver here */
1229 /* Enable the receiver */
1230 writeb(new_config3, &(ICOM_PORT->dram->async_config3));
1231 writeb(new_config2, &(ICOM_PORT->dram->async_config2));
1232 tmp_byte = readb(&(ICOM_PORT->dram->HDLCConfigReg));
1233 tmp_byte |= HDLC_PPP_PURE_ASYNC | HDLC_FF_FILL;
1234 writeb(tmp_byte, &(ICOM_PORT->dram->HDLCConfigReg));
1235 writeb(0x04, &(ICOM_PORT->dram->FlagFillIdleTimer)); /* 0.5 seconds */
1236 writeb(0xFF, &(ICOM_PORT->dram->ier)); /* enable modem signal interrupts */
1238 /* reset processor */
1239 writeb(CMD_RESTART, &ICOM_PORT->dram->CmdReg);
1241 for (index = 0; index < 10; index++) {
1242 if (readb(&ICOM_PORT->dram->CmdReg) == 0x00) {
1247 /* Enable Transmitter and Reciever */
1249 (unsigned long) &ICOM_PORT->statStg->rcv[0] -
1250 (unsigned long) ICOM_PORT->statStg;
1251 writel(ICOM_PORT->statStg_pci + offset,
1252 &ICOM_PORT->dram->RcvStatusAddr);
1253 ICOM_PORT->next_rcv = 0;
1254 ICOM_PORT->put_length = 0;
1255 *ICOM_PORT->xmitRestart = 0;
1256 writel(ICOM_PORT->xmitRestart_pci,
1257 &ICOM_PORT->dram->XmitStatusAddr);
1258 trace(ICOM_PORT, "XR_ENAB", 0);
1259 writeb(CMD_XMIT_RCV_ENABLE, &ICOM_PORT->dram->CmdReg);
1261 spin_unlock_irqrestore(&port->lock, flags);
1264 static const char *icom_type(struct uart_port *port)
1269 static void icom_release_port(struct uart_port *port)
1273 static int icom_request_port(struct uart_port *port)
1278 static void icom_config_port(struct uart_port *port, int flags)
1280 port->type = PORT_ICOM;
1283 static struct uart_ops icom_ops = {
1284 .tx_empty = icom_tx_empty,
1285 .set_mctrl = icom_set_mctrl,
1286 .get_mctrl = icom_get_mctrl,
1287 .stop_tx = icom_stop_tx,
1288 .start_tx = icom_start_tx,
1289 .send_xchar = icom_send_xchar,
1290 .stop_rx = icom_stop_rx,
1291 .enable_ms = icom_enable_ms,
1292 .break_ctl = icom_break,
1293 .startup = icom_open,
1294 .shutdown = icom_close,
1295 .set_termios = icom_set_termios,
1297 .release_port = icom_release_port,
1298 .request_port = icom_request_port,
1299 .config_port = icom_config_port,
1302 #define ICOM_CONSOLE NULL
1304 static struct uart_driver icom_uart_driver = {
1305 .owner = THIS_MODULE,
1306 .driver_name = ICOM_DRIVER_NAME,
1308 .major = ICOM_MAJOR,
1309 .minor = ICOM_MINOR_START,
1311 .cons = ICOM_CONSOLE,
1314 static int __devinit icom_init_ports(struct icom_adapter *icom_adapter)
1316 u32 subsystem_id = icom_adapter->subsystem_id;
1318 struct icom_port *icom_port;
1320 if (icom_adapter->version == ADAPTER_V1) {
1321 icom_adapter->numb_ports = 2;
1323 for (i = 0; i < 2; i++) {
1324 icom_port = &icom_adapter->port_info[i];
1325 icom_port->port = i;
1326 icom_port->status = ICOM_PORT_ACTIVE;
1327 icom_port->imbed_modem = ICOM_UNKNOWN;
1330 if (subsystem_id == PCI_DEVICE_ID_IBM_ICOM_FOUR_PORT_MODEL) {
1331 icom_adapter->numb_ports = 4;
1333 for (i = 0; i < 4; i++) {
1334 icom_port = &icom_adapter->port_info[i];
1336 icom_port->port = i;
1337 icom_port->status = ICOM_PORT_ACTIVE;
1338 icom_port->imbed_modem = ICOM_IMBED_MODEM;
1341 icom_adapter->numb_ports = 4;
1343 icom_adapter->port_info[0].port = 0;
1344 icom_adapter->port_info[0].status = ICOM_PORT_ACTIVE;
1347 PCI_DEVICE_ID_IBM_ICOM_V2_ONE_PORT_RVX_ONE_PORT_MDM) {
1348 icom_adapter->port_info[0].imbed_modem = ICOM_IMBED_MODEM;
1350 icom_adapter->port_info[0].imbed_modem = ICOM_RVX;
1353 icom_adapter->port_info[1].status = ICOM_PORT_OFF;
1355 icom_adapter->port_info[2].port = 2;
1356 icom_adapter->port_info[2].status = ICOM_PORT_ACTIVE;
1357 icom_adapter->port_info[2].imbed_modem = ICOM_RVX;
1358 icom_adapter->port_info[3].status = ICOM_PORT_OFF;
1365 static void icom_port_active(struct icom_port *icom_port, struct icom_adapter *icom_adapter, int port_num)
1367 if (icom_adapter->version == ADAPTER_V1) {
1368 icom_port->global_reg = icom_adapter->base_addr + 0x4000;
1369 icom_port->int_reg = icom_adapter->base_addr +
1370 0x4004 + 2 - 2 * port_num;
1372 icom_port->global_reg = icom_adapter->base_addr + 0x8000;
1373 if (icom_port->port < 2)
1374 icom_port->int_reg = icom_adapter->base_addr +
1375 0x8004 + 2 - 2 * icom_port->port;
1377 icom_port->int_reg = icom_adapter->base_addr +
1378 0x8024 + 2 - 2 * (icom_port->port - 2);
1381 static int __devinit icom_load_ports(struct icom_adapter *icom_adapter)
1383 struct icom_port *icom_port;
1386 for (port_num = 0; port_num < icom_adapter->numb_ports; port_num++) {
1388 icom_port = &icom_adapter->port_info[port_num];
1390 if (icom_port->status == ICOM_PORT_ACTIVE) {
1391 icom_port_active(icom_port, icom_adapter, port_num);
1392 icom_port->dram = icom_adapter->base_addr +
1393 0x2000 * icom_port->port;
1395 icom_port->adapter = icom_adapter;
1397 /* get port memory */
1398 if (get_port_memory(icom_port) != 0) {
1399 dev_err(&icom_port->adapter->pci_dev->dev,
1400 "Memory allocation for port FAILED\n");
1407 static int __devinit icom_alloc_adapter(struct icom_adapter
1410 int adapter_count = 0;
1411 struct icom_adapter *icom_adapter;
1412 struct icom_adapter *cur_adapter_entry;
1413 struct list_head *tmp;
1415 icom_adapter = (struct icom_adapter *)
1416 kzalloc(sizeof(struct icom_adapter), GFP_KERNEL);
1418 if (!icom_adapter) {
1422 list_for_each(tmp, &icom_adapter_head) {
1424 list_entry(tmp, struct icom_adapter,
1425 icom_adapter_entry);
1426 if (cur_adapter_entry->index != adapter_count) {
1432 icom_adapter->index = adapter_count;
1433 list_add_tail(&icom_adapter->icom_adapter_entry, tmp);
1435 *icom_adapter_ref = icom_adapter;
1439 static void icom_free_adapter(struct icom_adapter *icom_adapter)
1441 list_del(&icom_adapter->icom_adapter_entry);
1442 kfree(icom_adapter);
1445 static void icom_remove_adapter(struct icom_adapter *icom_adapter)
1447 struct icom_port *icom_port;
1450 for (index = 0; index < icom_adapter->numb_ports; index++) {
1451 icom_port = &icom_adapter->port_info[index];
1453 if (icom_port->status == ICOM_PORT_ACTIVE) {
1454 dev_info(&icom_adapter->pci_dev->dev,
1455 "Device removed\n");
1457 uart_remove_one_port(&icom_uart_driver,
1458 &icom_port->uart_port);
1460 /* be sure that DTR and RTS are dropped */
1461 writeb(0x00, &icom_port->dram->osr);
1463 /* Wait 0.1 Sec for simple Init to complete */
1466 /* Stop proccessor */
1467 stop_processor(icom_port);
1469 free_port_memory(icom_port);
1473 free_irq(icom_adapter->pci_dev->irq, (void *) icom_adapter);
1474 iounmap(icom_adapter->base_addr);
1475 icom_free_adapter(icom_adapter);
1476 pci_release_regions(icom_adapter->pci_dev);
1479 static void icom_kref_release(struct kref *kref)
1481 struct icom_adapter *icom_adapter;
1483 icom_adapter = to_icom_adapter(kref);
1484 icom_remove_adapter(icom_adapter);
1487 static int __devinit icom_probe(struct pci_dev *dev,
1488 const struct pci_device_id *ent)
1491 unsigned int command_reg;
1493 struct icom_adapter *icom_adapter;
1494 struct icom_port *icom_port;
1496 retval = pci_enable_device(dev);
1498 dev_err(&dev->dev, "Device enable FAILED\n");
1502 if ( (retval = pci_request_regions(dev, "icom"))) {
1503 dev_err(&dev->dev, "pci_request_regions FAILED\n");
1504 pci_disable_device(dev);
1508 pci_set_master(dev);
1510 if ( (retval = pci_read_config_dword(dev, PCI_COMMAND, &command_reg))) {
1511 dev_err(&dev->dev, "PCI Config read FAILED\n");
1515 pci_write_config_dword(dev, PCI_COMMAND,
1516 command_reg | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER
1517 | PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
1519 if (ent->driver_data == ADAPTER_V1) {
1520 pci_write_config_dword(dev, 0x44, 0x8300830A);
1522 pci_write_config_dword(dev, 0x44, 0x42004200);
1523 pci_write_config_dword(dev, 0x48, 0x42004200);
1527 retval = icom_alloc_adapter(&icom_adapter);
1529 dev_err(&dev->dev, "icom_alloc_adapter FAILED\n");
1534 icom_adapter->base_addr_pci = pci_resource_start(dev, 0);
1535 icom_adapter->pci_dev = dev;
1536 icom_adapter->version = ent->driver_data;
1537 icom_adapter->subsystem_id = ent->subdevice;
1540 retval = icom_init_ports(icom_adapter);
1542 dev_err(&dev->dev, "Port configuration failed\n");
1546 icom_adapter->base_addr = ioremap(icom_adapter->base_addr_pci,
1547 pci_resource_len(dev, 0));
1549 if (!icom_adapter->base_addr)
1552 /* save off irq and request irq line */
1553 if ( (retval = request_irq(dev->irq, icom_interrupt,
1554 IRQF_DISABLED | IRQF_SHARED, ICOM_DRIVER_NAME,
1555 (void *) icom_adapter))) {
1559 retval = icom_load_ports(icom_adapter);
1561 for (index = 0; index < icom_adapter->numb_ports; index++) {
1562 icom_port = &icom_adapter->port_info[index];
1564 if (icom_port->status == ICOM_PORT_ACTIVE) {
1565 icom_port->uart_port.irq = icom_port->adapter->pci_dev->irq;
1566 icom_port->uart_port.type = PORT_ICOM;
1567 icom_port->uart_port.iotype = UPIO_MEM;
1568 icom_port->uart_port.membase =
1569 (char *) icom_adapter->base_addr_pci;
1570 icom_port->uart_port.fifosize = 16;
1571 icom_port->uart_port.ops = &icom_ops;
1572 icom_port->uart_port.line =
1573 icom_port->port + icom_adapter->index * 4;
1574 if (uart_add_one_port (&icom_uart_driver, &icom_port->uart_port)) {
1575 icom_port->status = ICOM_PORT_OFF;
1576 dev_err(&dev->dev, "Device add failed\n");
1578 dev_info(&dev->dev, "Device added\n");
1582 kref_init(&icom_adapter->kref);
1586 iounmap(icom_adapter->base_addr);
1588 icom_free_adapter(icom_adapter);
1591 pci_release_regions(dev);
1592 pci_disable_device(dev);
1599 static void __devexit icom_remove(struct pci_dev *dev)
1601 struct icom_adapter *icom_adapter;
1602 struct list_head *tmp;
1604 list_for_each(tmp, &icom_adapter_head) {
1605 icom_adapter = list_entry(tmp, struct icom_adapter,
1606 icom_adapter_entry);
1607 if (icom_adapter->pci_dev == dev) {
1608 kref_put(&icom_adapter->kref, icom_kref_release);
1613 dev_err(&dev->dev, "Unable to find device to remove\n");
1616 static struct pci_driver icom_pci_driver = {
1617 .name = ICOM_DRIVER_NAME,
1618 .id_table = icom_pci_table,
1619 .probe = icom_probe,
1620 .remove = __devexit_p(icom_remove),
1623 static int __init icom_init(void)
1627 spin_lock_init(&icom_lock);
1629 ret = uart_register_driver(&icom_uart_driver);
1633 ret = pci_register_driver(&icom_pci_driver);
1636 uart_unregister_driver(&icom_uart_driver);
1641 static void __exit icom_exit(void)
1643 pci_unregister_driver(&icom_pci_driver);
1644 uart_unregister_driver(&icom_uart_driver);
1647 module_init(icom_init);
1648 module_exit(icom_exit);
1651 static inline void trace(struct icom_port *icom_port, char *trace_pt,
1652 unsigned long trace_data)
1654 dev_info(&icom_port->adapter->pci_dev->dev, ":%d:%s - %lx\n",
1655 icom_port->port, trace_pt, trace_data);
1659 MODULE_AUTHOR("Michael Anderson <mjanders@us.ibm.com>");
1660 MODULE_DESCRIPTION("IBM iSeries Serial IOA driver");
1661 MODULE_SUPPORTED_DEVICE
1662 ("IBM iSeries 2745, 2771, 2772, 2742, 2793 and 2805 Communications adapters");
1663 MODULE_LICENSE("GPL");