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/kobject.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, kobj)
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,
102 struct lookup_proc_table start_proc[4] = {
103 {NULL, ICOM_CONTROL_START_A},
104 {NULL, ICOM_CONTROL_START_B},
105 {NULL, ICOM_CONTROL_START_C},
106 {NULL, ICOM_CONTROL_START_D}
110 struct lookup_proc_table stop_proc[4] = {
111 {NULL, ICOM_CONTROL_STOP_A},
112 {NULL, ICOM_CONTROL_STOP_B},
113 {NULL, ICOM_CONTROL_STOP_C},
114 {NULL, ICOM_CONTROL_STOP_D}
117 struct lookup_int_table int_mask_tbl[4] = {
118 {NULL, ICOM_INT_MASK_PRC_A},
119 {NULL, ICOM_INT_MASK_PRC_B},
120 {NULL, ICOM_INT_MASK_PRC_C},
121 {NULL, ICOM_INT_MASK_PRC_D},
125 MODULE_DEVICE_TABLE(pci, icom_pci_table);
127 static LIST_HEAD(icom_adapter_head);
129 /* spinlock for adapter initialization and changing adapter operations */
130 static spinlock_t icom_lock;
133 static inline void trace(struct icom_port *, char *, unsigned long) {};
135 static inline void trace(struct icom_port *icom_port, char *trace_pt, unsigned long trace_data) {};
138 static void free_port_memory(struct icom_port *icom_port)
140 struct pci_dev *dev = icom_port->adapter->pci_dev;
142 trace(icom_port, "RET_PORT_MEM", 0);
143 if (icom_port->recv_buf) {
144 pci_free_consistent(dev, 4096, icom_port->recv_buf,
145 icom_port->recv_buf_pci);
146 icom_port->recv_buf = NULL;
148 if (icom_port->xmit_buf) {
149 pci_free_consistent(dev, 4096, icom_port->xmit_buf,
150 icom_port->xmit_buf_pci);
151 icom_port->xmit_buf = NULL;
153 if (icom_port->statStg) {
154 pci_free_consistent(dev, 4096, icom_port->statStg,
155 icom_port->statStg_pci);
156 icom_port->statStg = NULL;
159 if (icom_port->xmitRestart) {
160 pci_free_consistent(dev, 4096, icom_port->xmitRestart,
161 icom_port->xmitRestart_pci);
162 icom_port->xmitRestart = NULL;
166 static int __devinit get_port_memory(struct icom_port *icom_port)
169 unsigned long stgAddr;
170 unsigned long startStgAddr;
171 unsigned long offset;
172 struct pci_dev *dev = icom_port->adapter->pci_dev;
174 icom_port->xmit_buf =
175 pci_alloc_consistent(dev, 4096, &icom_port->xmit_buf_pci);
176 if (!icom_port->xmit_buf) {
177 dev_err(&dev->dev, "Can not allocate Transmit buffer\n");
181 trace(icom_port, "GET_PORT_MEM",
182 (unsigned long) icom_port->xmit_buf);
184 icom_port->recv_buf =
185 pci_alloc_consistent(dev, 4096, &icom_port->recv_buf_pci);
186 if (!icom_port->recv_buf) {
187 dev_err(&dev->dev, "Can not allocate Receive buffer\n");
188 free_port_memory(icom_port);
191 trace(icom_port, "GET_PORT_MEM",
192 (unsigned long) icom_port->recv_buf);
195 pci_alloc_consistent(dev, 4096, &icom_port->statStg_pci);
196 if (!icom_port->statStg) {
197 dev_err(&dev->dev, "Can not allocate Status buffer\n");
198 free_port_memory(icom_port);
201 trace(icom_port, "GET_PORT_MEM",
202 (unsigned long) icom_port->statStg);
204 icom_port->xmitRestart =
205 pci_alloc_consistent(dev, 4096, &icom_port->xmitRestart_pci);
206 if (!icom_port->xmitRestart) {
208 "Can not allocate xmit Restart buffer\n");
209 free_port_memory(icom_port);
213 memset(icom_port->statStg, 0, 4096);
215 /* FODs: Frame Out Descriptor Queue, this is a FIFO queue that
216 indicates that frames are to be transmitted
219 stgAddr = (unsigned long) icom_port->statStg;
220 for (index = 0; index < NUM_XBUFFS; index++) {
221 trace(icom_port, "FOD_ADDR", stgAddr);
222 stgAddr = stgAddr + sizeof(icom_port->statStg->xmit[0]);
223 if (index < (NUM_XBUFFS - 1)) {
224 memset(&icom_port->statStg->xmit[index], 0, sizeof(struct xmit_status_area));
225 icom_port->statStg->xmit[index].leLengthASD =
226 (unsigned short int) cpu_to_le16(XMIT_BUFF_SZ);
227 trace(icom_port, "FOD_ADDR", stgAddr);
228 trace(icom_port, "FOD_XBUFF",
229 (unsigned long) icom_port->xmit_buf);
230 icom_port->statStg->xmit[index].leBuffer =
231 cpu_to_le32(icom_port->xmit_buf_pci);
232 } else if (index == (NUM_XBUFFS - 1)) {
233 memset(&icom_port->statStg->xmit[index], 0, sizeof(struct xmit_status_area));
234 icom_port->statStg->xmit[index].leLengthASD =
235 (unsigned short int) cpu_to_le16(XMIT_BUFF_SZ);
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);
241 memset(&icom_port->statStg->xmit[index], 0, sizeof(struct xmit_status_area));
245 startStgAddr = stgAddr;
247 /* fill in every entry, even if no buffer */
248 for (index = 0; index < NUM_RBUFFS; index++) {
249 trace(icom_port, "FID_ADDR", stgAddr);
250 stgAddr = stgAddr + sizeof(icom_port->statStg->rcv[0]);
251 icom_port->statStg->rcv[index].leLength = 0;
252 icom_port->statStg->rcv[index].WorkingLength =
253 (unsigned short int) cpu_to_le16(RCV_BUFF_SZ);
254 if (index < (NUM_RBUFFS - 1) ) {
255 offset = stgAddr - (unsigned long) icom_port->statStg;
256 icom_port->statStg->rcv[index].leNext =
257 cpu_to_le32(icom_port-> statStg_pci + offset);
258 trace(icom_port, "FID_RBUFF",
259 (unsigned long) icom_port->recv_buf);
260 icom_port->statStg->rcv[index].leBuffer =
261 cpu_to_le32(icom_port->recv_buf_pci);
262 } else if (index == (NUM_RBUFFS -1) ) {
263 offset = startStgAddr - (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 + 2048);
268 icom_port->statStg->rcv[index].leBuffer =
269 cpu_to_le32(icom_port->recv_buf_pci + 2048);
271 icom_port->statStg->rcv[index].leNext = 0;
272 icom_port->statStg->rcv[index].leBuffer = 0;
279 static void stop_processor(struct icom_port *icom_port)
285 spin_lock_irqsave(&icom_lock, flags);
287 port = icom_port->port;
288 if (port == 0 || port == 1)
289 stop_proc[port].global_control_reg = &icom_port->global_reg->control;
291 stop_proc[port].global_control_reg = &icom_port->global_reg->control_2;
295 temp = readl(stop_proc[port].global_control_reg);
297 (temp & ~start_proc[port].processor_id) | stop_proc[port].processor_id;
298 writel(temp, stop_proc[port].global_control_reg);
301 readl(stop_proc[port].global_control_reg);
303 dev_err(&icom_port->adapter->pci_dev->dev,
304 "Invalid port assignment\n");
307 spin_unlock_irqrestore(&icom_lock, flags);
310 static void start_processor(struct icom_port *icom_port)
316 spin_lock_irqsave(&icom_lock, flags);
318 port = icom_port->port;
319 if (port == 0 || port == 1)
320 start_proc[port].global_control_reg = &icom_port->global_reg->control;
322 start_proc[port].global_control_reg = &icom_port->global_reg->control_2;
324 temp = readl(start_proc[port].global_control_reg);
326 (temp & ~stop_proc[port].processor_id) | start_proc[port].processor_id;
327 writel(temp, start_proc[port].global_control_reg);
330 readl(start_proc[port].global_control_reg);
332 dev_err(&icom_port->adapter->pci_dev->dev,
333 "Invalid port assignment\n");
336 spin_unlock_irqrestore(&icom_lock, flags);
339 static void load_code(struct icom_port *icom_port)
341 const struct firmware *fw;
342 char __iomem *iram_ptr;
345 void __iomem *dram_ptr = icom_port->dram;
347 unsigned char *new_page = NULL;
348 unsigned char cable_id = NO_CABLE;
349 struct pci_dev *dev = icom_port->adapter->pci_dev;
351 /* Clear out any pending interrupts */
352 writew(0x3FFF, icom_port->int_reg);
354 trace(icom_port, "CLEAR_INTERRUPTS", 0);
357 stop_processor(icom_port);
360 memset_io(dram_ptr, 0, 512);
362 /* Load Call Setup into Adapter */
363 if (request_firmware(&fw, "icom_call_setup.bin", &dev->dev) < 0) {
364 dev_err(&dev->dev,"Unable to load icom_call_setup.bin firmware image\n");
369 if (fw->size > ICOM_DCE_IRAM_OFFSET) {
370 dev_err(&dev->dev, "Invalid firmware image for icom_call_setup.bin found.\n");
371 release_firmware(fw);
376 iram_ptr = (char __iomem *)icom_port->dram + ICOM_IRAM_OFFSET;
377 for (index = 0; index < fw->size; index++)
378 writeb(fw->data[index], &iram_ptr[index]);
380 release_firmware(fw);
382 /* Load Resident DCE portion of Adapter */
383 if (request_firmware(&fw, "icom_res_dce.bin", &dev->dev) < 0) {
384 dev_err(&dev->dev,"Unable to load icom_res_dce.bin firmware image\n");
389 if (fw->size > ICOM_IRAM_SIZE) {
390 dev_err(&dev->dev, "Invalid firmware image for icom_res_dce.bin found.\n");
391 release_firmware(fw);
396 iram_ptr = (char __iomem *) icom_port->dram + ICOM_IRAM_OFFSET;
397 for (index = ICOM_DCE_IRAM_OFFSET; index < fw->size; index++)
398 writeb(fw->data[index], &iram_ptr[index]);
400 release_firmware(fw);
402 /* Set Hardware level */
403 if ((icom_port->adapter->version | ADAPTER_V2) == ADAPTER_V2)
404 writeb(V2_HARDWARE, &(icom_port->dram->misc_flags));
406 /* Start the processor in Adapter */
407 start_processor(icom_port);
409 writeb((HDLC_PPP_PURE_ASYNC | HDLC_FF_FILL),
410 &(icom_port->dram->HDLCConfigReg));
411 writeb(0x04, &(icom_port->dram->FlagFillIdleTimer)); /* 0.5 seconds */
412 writeb(0x00, &(icom_port->dram->CmdReg));
413 writeb(0x10, &(icom_port->dram->async_config3));
414 writeb((ICOM_ACFG_DRIVE1 | ICOM_ACFG_NO_PARITY | ICOM_ACFG_8BPC |
415 ICOM_ACFG_1STOP_BIT), &(icom_port->dram->async_config2));
417 /*Set up data in icom DRAM to indicate where personality
418 *code is located and its length.
420 new_page = pci_alloc_consistent(dev, 4096, &temp_pci);
423 dev_err(&dev->dev, "Can not allocate DMA buffer\n");
428 if (request_firmware(&fw, "icom_asc.bin", &dev->dev) < 0) {
429 dev_err(&dev->dev,"Unable to load icom_asc.bin firmware image\n");
434 if (fw->size > ICOM_DCE_IRAM_OFFSET) {
435 dev_err(&dev->dev, "Invalid firmware image for icom_asc.bin found.\n");
436 release_firmware(fw);
441 for (index = 0; index < fw->size; index++)
442 new_page[index] = fw->data[index];
444 release_firmware(fw);
446 writeb((char) ((fw->size + 16)/16), &icom_port->dram->mac_length);
447 writel(temp_pci, &icom_port->dram->mac_load_addr);
449 /*Setting the syncReg to 0x80 causes adapter to start downloading
450 the personality code into adapter instruction RAM.
451 Once code is loaded, it will begin executing and, based on
452 information provided above, will start DMAing data from
453 shared memory to adapter DRAM.
455 /* the wait loop below verifies this write operation has been done
458 writeb(START_DOWNLOAD, &icom_port->dram->sync);
460 /* Wait max 1 Sec for data download and processor to start */
461 for (index = 0; index < 10; index++) {
463 if (readb(&icom_port->dram->misc_flags) & ICOM_HDW_ACTIVE)
473 cable_id = readb(&icom_port->dram->cable_id);
475 if (cable_id & ICOM_CABLE_ID_VALID) {
476 /* Get cable ID into the lower 4 bits (standard form) */
477 cable_id = (cable_id & ICOM_CABLE_ID_MASK) >> 4;
478 icom_port->cable_id = cable_id;
480 dev_err(&dev->dev,"Invalid or no cable attached\n");
481 icom_port->cable_id = NO_CABLE;
487 /* Clear out any pending interrupts */
488 writew(0x3FFF, icom_port->int_reg);
491 writeb(ICOM_DISABLE, &(icom_port->dram->disable));
494 stop_processor(icom_port);
496 dev_err(&icom_port->adapter->pci_dev->dev,"Port not opertional\n");
499 if (new_page != NULL)
500 pci_free_consistent(dev, 4096, new_page, temp_pci);
503 static int startup(struct icom_port *icom_port)
506 unsigned char cable_id, raw_cable_id;
510 trace(icom_port, "STARTUP", 0);
512 if (!icom_port->dram) {
513 /* should NEVER be NULL */
514 dev_err(&icom_port->adapter->pci_dev->dev,
515 "Unusable Port, port configuration missing\n");
522 raw_cable_id = readb(&icom_port->dram->cable_id);
523 trace(icom_port, "CABLE_ID", raw_cable_id);
525 /* Get cable ID into the lower 4 bits (standard form) */
526 cable_id = (raw_cable_id & ICOM_CABLE_ID_MASK) >> 4;
528 /* Check for valid Cable ID */
529 if (!(raw_cable_id & ICOM_CABLE_ID_VALID) ||
530 (cable_id != icom_port->cable_id)) {
532 /* reload adapter code, pick up any potential changes in cable id */
533 load_code(icom_port);
535 /* still no sign of cable, error out */
536 raw_cable_id = readb(&icom_port->dram->cable_id);
537 cable_id = (raw_cable_id & ICOM_CABLE_ID_MASK) >> 4;
538 if (!(raw_cable_id & ICOM_CABLE_ID_VALID) ||
539 (icom_port->cable_id == NO_CABLE))
544 * Finally, clear and enable interrupts
546 spin_lock_irqsave(&icom_lock, flags);
547 port = icom_port->port;
548 if (port == 0 || port == 1)
549 int_mask_tbl[port].global_int_mask = &icom_port->global_reg->int_mask;
551 int_mask_tbl[port].global_int_mask = &icom_port->global_reg->int_mask_2;
553 if (port == 0 || port == 2)
554 writew(0x00FF, icom_port->int_reg);
556 writew(0x3F00, icom_port->int_reg);
558 temp = readl(int_mask_tbl[port].global_int_mask);
559 writel(temp & ~int_mask_tbl[port].processor_id, int_mask_tbl[port].global_int_mask);
562 readl(int_mask_tbl[port].global_int_mask);
564 dev_err(&icom_port->adapter->pci_dev->dev,
565 "Invalid port assignment\n");
568 spin_unlock_irqrestore(&icom_lock, flags);
572 static void shutdown(struct icom_port *icom_port)
575 unsigned char cmdReg;
579 spin_lock_irqsave(&icom_lock, flags);
580 trace(icom_port, "SHUTDOWN", 0);
583 * disable all interrupts
585 port = icom_port->port;
586 if (port == 0 || port == 1)
587 int_mask_tbl[port].global_int_mask = &icom_port->global_reg->int_mask;
589 int_mask_tbl[port].global_int_mask = &icom_port->global_reg->int_mask_2;
592 temp = readl(int_mask_tbl[port].global_int_mask);
593 writel(temp | int_mask_tbl[port].processor_id, int_mask_tbl[port].global_int_mask);
596 readl(int_mask_tbl[port].global_int_mask);
598 dev_err(&icom_port->adapter->pci_dev->dev,
599 "Invalid port assignment\n");
601 spin_unlock_irqrestore(&icom_lock, flags);
604 * disable break condition
606 cmdReg = readb(&icom_port->dram->CmdReg);
607 if ((cmdReg | CMD_SND_BREAK) == CMD_SND_BREAK) {
608 writeb(cmdReg & ~CMD_SND_BREAK, &icom_port->dram->CmdReg);
612 static int icom_write(struct uart_port *port)
614 unsigned long data_count;
615 unsigned char cmdReg;
616 unsigned long offset;
617 int temp_tail = port->info->xmit.tail;
619 trace(ICOM_PORT, "WRITE", 0);
621 if (cpu_to_le16(ICOM_PORT->statStg->xmit[0].flags) &
622 SA_FLAGS_READY_TO_XMIT) {
623 trace(ICOM_PORT, "WRITE_FULL", 0);
628 while ((port->info->xmit.head != temp_tail) &&
629 (data_count <= XMIT_BUFF_SZ)) {
631 ICOM_PORT->xmit_buf[data_count++] =
632 port->info->xmit.buf[temp_tail];
635 temp_tail &= (UART_XMIT_SIZE - 1);
639 ICOM_PORT->statStg->xmit[0].flags =
640 cpu_to_le16(SA_FLAGS_READY_TO_XMIT);
641 ICOM_PORT->statStg->xmit[0].leLength =
642 cpu_to_le16(data_count);
644 (unsigned long) &ICOM_PORT->statStg->xmit[0] -
645 (unsigned long) ICOM_PORT->statStg;
646 *ICOM_PORT->xmitRestart =
647 cpu_to_le32(ICOM_PORT->statStg_pci + offset);
648 cmdReg = readb(&ICOM_PORT->dram->CmdReg);
649 writeb(cmdReg | CMD_XMIT_RCV_ENABLE,
650 &ICOM_PORT->dram->CmdReg);
651 writeb(START_XMIT, &ICOM_PORT->dram->StartXmitCmd);
652 trace(ICOM_PORT, "WRITE_START", data_count);
654 readb(&ICOM_PORT->dram->StartXmitCmd);
660 static inline void check_modem_status(struct icom_port *icom_port)
662 static char old_status = 0;
664 unsigned char status;
666 spin_lock(&icom_port->uart_port.lock);
668 /*modem input register */
669 status = readb(&icom_port->dram->isr);
670 trace(icom_port, "CHECK_MODEM", status);
671 delta_status = status ^ old_status;
673 if (delta_status & ICOM_RI)
674 icom_port->uart_port.icount.rng++;
675 if (delta_status & ICOM_DSR)
676 icom_port->uart_port.icount.dsr++;
677 if (delta_status & ICOM_DCD)
678 uart_handle_dcd_change(&icom_port->uart_port,
679 delta_status & ICOM_DCD);
680 if (delta_status & ICOM_CTS)
681 uart_handle_cts_change(&icom_port->uart_port,
682 delta_status & ICOM_CTS);
684 wake_up_interruptible(&icom_port->uart_port.info->
688 spin_unlock(&icom_port->uart_port.lock);
691 static void xmit_interrupt(u16 port_int_reg, struct icom_port *icom_port)
693 unsigned short int count;
696 if (port_int_reg & (INT_XMIT_COMPLETED)) {
697 trace(icom_port, "XMIT_COMPLETE", 0);
699 /* clear buffer in use bit */
700 icom_port->statStg->xmit[0].flags &=
701 cpu_to_le16(~SA_FLAGS_READY_TO_XMIT);
703 count = (unsigned short int)
704 cpu_to_le16(icom_port->statStg->xmit[0].leLength);
705 icom_port->uart_port.icount.tx += count;
708 !uart_circ_empty(&icom_port->uart_port.info->xmit); i++) {
710 icom_port->uart_port.info->xmit.tail++;
711 icom_port->uart_port.info->xmit.tail &=
712 (UART_XMIT_SIZE - 1);
715 if (!icom_write(&icom_port->uart_port))
716 /* activate write queue */
717 uart_write_wakeup(&icom_port->uart_port);
719 trace(icom_port, "XMIT_DISABLED", 0);
722 static void recv_interrupt(u16 port_int_reg, struct icom_port *icom_port)
724 short int count, rcv_buff;
725 struct tty_struct *tty = icom_port->uart_port.info->tty;
726 unsigned short int status;
727 struct uart_icount *icount;
728 unsigned long offset;
731 trace(icom_port, "RCV_COMPLETE", 0);
732 rcv_buff = icom_port->next_rcv;
734 status = cpu_to_le16(icom_port->statStg->rcv[rcv_buff].flags);
735 while (status & SA_FL_RCV_DONE) {
738 trace(icom_port, "FID_STATUS", status);
739 count = cpu_to_le16(icom_port->statStg->rcv[rcv_buff].leLength);
741 count = tty_buffer_request_room(tty, count);
742 trace(icom_port, "RCV_COUNT", count);
744 trace(icom_port, "REAL_COUNT", count);
747 cpu_to_le32(icom_port->statStg->rcv[rcv_buff].leBuffer) -
748 icom_port->recv_buf_pci;
750 /* Block copy all but the last byte as this may have status */
752 first = icom_port->recv_buf[offset];
753 tty_insert_flip_string(tty, icom_port->recv_buf + offset, count - 1);
756 icount = &icom_port->uart_port.icount;
759 /* Break detect logic */
760 if ((status & SA_FLAGS_FRAME_ERROR)
762 status &= ~SA_FLAGS_FRAME_ERROR;
763 status |= SA_FLAGS_BREAK_DET;
764 trace(icom_port, "BREAK_DET", 0);
770 (SA_FLAGS_BREAK_DET | SA_FLAGS_PARITY_ERROR |
771 SA_FLAGS_FRAME_ERROR | SA_FLAGS_OVERRUN)) {
773 if (status & SA_FLAGS_BREAK_DET)
775 if (status & SA_FLAGS_PARITY_ERROR)
777 if (status & SA_FLAGS_FRAME_ERROR)
779 if (status & SA_FLAGS_OVERRUN)
783 * Now check to see if character should be
784 * ignored, and mask off conditions which
787 if (status & icom_port->ignore_status_mask) {
788 trace(icom_port, "IGNORE_CHAR", 0);
792 status &= icom_port->read_status_mask;
794 if (status & SA_FLAGS_BREAK_DET) {
796 } else if (status & SA_FLAGS_PARITY_ERROR) {
797 trace(icom_port, "PARITY_ERROR", 0);
799 } else if (status & SA_FLAGS_FRAME_ERROR)
804 tty_insert_flip_char(tty, *(icom_port->recv_buf + offset + count - 1), flag);
806 if (status & SA_FLAGS_OVERRUN)
808 * Overrun is special, since it's
809 * reported immediately, and doesn't
810 * affect the current character
812 tty_insert_flip_char(tty, 0, TTY_OVERRUN);
814 icom_port->statStg->rcv[rcv_buff].flags = 0;
815 icom_port->statStg->rcv[rcv_buff].leLength = 0;
816 icom_port->statStg->rcv[rcv_buff].WorkingLength =
817 (unsigned short int) cpu_to_le16(RCV_BUFF_SZ);
820 if (rcv_buff == NUM_RBUFFS)
823 status = cpu_to_le16(icom_port->statStg->rcv[rcv_buff].flags);
825 icom_port->next_rcv = rcv_buff;
826 tty_flip_buffer_push(tty);
829 static void process_interrupt(u16 port_int_reg,
830 struct icom_port *icom_port)
833 spin_lock(&icom_port->uart_port.lock);
834 trace(icom_port, "INTERRUPT", port_int_reg);
836 if (port_int_reg & (INT_XMIT_COMPLETED | INT_XMIT_DISABLED))
837 xmit_interrupt(port_int_reg, icom_port);
839 if (port_int_reg & INT_RCV_COMPLETED)
840 recv_interrupt(port_int_reg, icom_port);
842 spin_unlock(&icom_port->uart_port.lock);
845 static irqreturn_t icom_interrupt(int irq, void *dev_id)
847 void __iomem * int_reg;
848 u32 adapter_interrupts;
850 struct icom_adapter *icom_adapter;
851 struct icom_port *icom_port;
853 /* find icom_port for this interrupt */
854 icom_adapter = (struct icom_adapter *) dev_id;
856 if ((icom_adapter->version | ADAPTER_V2) == ADAPTER_V2) {
857 int_reg = icom_adapter->base_addr + 0x8024;
859 adapter_interrupts = readl(int_reg);
861 if (adapter_interrupts & 0x00003FFF) {
862 /* port 2 interrupt, NOTE: for all ADAPTER_V2, port 2 will be active */
863 icom_port = &icom_adapter->port_info[2];
864 port_int_reg = (u16) adapter_interrupts;
865 process_interrupt(port_int_reg, icom_port);
866 check_modem_status(icom_port);
868 if (adapter_interrupts & 0x3FFF0000) {
869 /* port 3 interrupt */
870 icom_port = &icom_adapter->port_info[3];
871 if (icom_port->status == ICOM_PORT_ACTIVE) {
873 (u16) (adapter_interrupts >> 16);
874 process_interrupt(port_int_reg, icom_port);
875 check_modem_status(icom_port);
879 /* Clear out any pending interrupts */
880 writel(adapter_interrupts, int_reg);
882 int_reg = icom_adapter->base_addr + 0x8004;
884 int_reg = icom_adapter->base_addr + 0x4004;
887 adapter_interrupts = readl(int_reg);
889 if (adapter_interrupts & 0x00003FFF) {
890 /* port 0 interrupt, NOTE: for all adapters, port 0 will be active */
891 icom_port = &icom_adapter->port_info[0];
892 port_int_reg = (u16) adapter_interrupts;
893 process_interrupt(port_int_reg, icom_port);
894 check_modem_status(icom_port);
896 if (adapter_interrupts & 0x3FFF0000) {
897 /* port 1 interrupt */
898 icom_port = &icom_adapter->port_info[1];
899 if (icom_port->status == ICOM_PORT_ACTIVE) {
900 port_int_reg = (u16) (adapter_interrupts >> 16);
901 process_interrupt(port_int_reg, icom_port);
902 check_modem_status(icom_port);
906 /* Clear out any pending interrupts */
907 writel(adapter_interrupts, int_reg);
909 /* flush the write */
910 adapter_interrupts = readl(int_reg);
916 * ------------------------------------------------------------------
917 * Begin serial-core API
918 * ------------------------------------------------------------------
920 static unsigned int icom_tx_empty(struct uart_port *port)
925 spin_lock_irqsave(&port->lock, flags);
926 if (cpu_to_le16(ICOM_PORT->statStg->xmit[0].flags) &
927 SA_FLAGS_READY_TO_XMIT)
932 spin_unlock_irqrestore(&port->lock, flags);
936 static void icom_set_mctrl(struct uart_port *port, unsigned int mctrl)
938 unsigned char local_osr;
940 trace(ICOM_PORT, "SET_MODEM", 0);
941 local_osr = readb(&ICOM_PORT->dram->osr);
943 if (mctrl & TIOCM_RTS) {
944 trace(ICOM_PORT, "RAISE_RTS", 0);
945 local_osr |= ICOM_RTS;
947 trace(ICOM_PORT, "LOWER_RTS", 0);
948 local_osr &= ~ICOM_RTS;
951 if (mctrl & TIOCM_DTR) {
952 trace(ICOM_PORT, "RAISE_DTR", 0);
953 local_osr |= ICOM_DTR;
955 trace(ICOM_PORT, "LOWER_DTR", 0);
956 local_osr &= ~ICOM_DTR;
959 writeb(local_osr, &ICOM_PORT->dram->osr);
962 static unsigned int icom_get_mctrl(struct uart_port *port)
964 unsigned char status;
967 trace(ICOM_PORT, "GET_MODEM", 0);
969 status = readb(&ICOM_PORT->dram->isr);
971 result = ((status & ICOM_DCD) ? TIOCM_CAR : 0)
972 | ((status & ICOM_RI) ? TIOCM_RNG : 0)
973 | ((status & ICOM_DSR) ? TIOCM_DSR : 0)
974 | ((status & ICOM_CTS) ? TIOCM_CTS : 0);
978 static void icom_stop_tx(struct uart_port *port)
980 unsigned char cmdReg;
982 trace(ICOM_PORT, "STOP", 0);
983 cmdReg = readb(&ICOM_PORT->dram->CmdReg);
984 writeb(cmdReg | CMD_HOLD_XMIT, &ICOM_PORT->dram->CmdReg);
987 static void icom_start_tx(struct uart_port *port)
989 unsigned char cmdReg;
991 trace(ICOM_PORT, "START", 0);
992 cmdReg = readb(&ICOM_PORT->dram->CmdReg);
993 if ((cmdReg & CMD_HOLD_XMIT) == CMD_HOLD_XMIT)
994 writeb(cmdReg & ~CMD_HOLD_XMIT,
995 &ICOM_PORT->dram->CmdReg);
1000 static void icom_send_xchar(struct uart_port *port, char ch)
1002 unsigned char xdata;
1004 unsigned long flags;
1006 trace(ICOM_PORT, "SEND_XCHAR", ch);
1008 /* wait .1 sec to send char */
1009 for (index = 0; index < 10; index++) {
1010 spin_lock_irqsave(&port->lock, flags);
1011 xdata = readb(&ICOM_PORT->dram->xchar);
1012 if (xdata == 0x00) {
1013 trace(ICOM_PORT, "QUICK_WRITE", 0);
1014 writeb(ch, &ICOM_PORT->dram->xchar);
1016 /* flush write operation */
1017 xdata = readb(&ICOM_PORT->dram->xchar);
1018 spin_unlock_irqrestore(&port->lock, flags);
1021 spin_unlock_irqrestore(&port->lock, flags);
1026 static void icom_stop_rx(struct uart_port *port)
1028 unsigned char cmdReg;
1030 cmdReg = readb(&ICOM_PORT->dram->CmdReg);
1031 writeb(cmdReg & ~CMD_RCV_ENABLE, &ICOM_PORT->dram->CmdReg);
1034 static void icom_enable_ms(struct uart_port *port)
1039 static void icom_break(struct uart_port *port, int break_state)
1041 unsigned char cmdReg;
1042 unsigned long flags;
1044 spin_lock_irqsave(&port->lock, flags);
1045 trace(ICOM_PORT, "BREAK", 0);
1046 cmdReg = readb(&ICOM_PORT->dram->CmdReg);
1047 if (break_state == -1) {
1048 writeb(cmdReg | CMD_SND_BREAK, &ICOM_PORT->dram->CmdReg);
1050 writeb(cmdReg & ~CMD_SND_BREAK, &ICOM_PORT->dram->CmdReg);
1052 spin_unlock_irqrestore(&port->lock, flags);
1055 static int icom_open(struct uart_port *port)
1059 kobject_get(&ICOM_PORT->adapter->kobj);
1060 retval = startup(ICOM_PORT);
1063 kobject_put(&ICOM_PORT->adapter->kobj);
1064 trace(ICOM_PORT, "STARTUP_ERROR", 0);
1071 static void icom_close(struct uart_port *port)
1073 unsigned char cmdReg;
1075 trace(ICOM_PORT, "CLOSE", 0);
1078 cmdReg = readb(&ICOM_PORT->dram->CmdReg);
1079 writeb(cmdReg & (unsigned char) ~CMD_RCV_ENABLE,
1080 &ICOM_PORT->dram->CmdReg);
1082 shutdown(ICOM_PORT);
1084 kobject_put(&ICOM_PORT->adapter->kobj);
1087 static void icom_set_termios(struct uart_port *port,
1088 struct ktermios *termios,
1089 struct ktermios *old_termios)
1092 unsigned cflag, iflag;
1095 char new_config3 = 0;
1098 int rcv_buff, xmit_buff;
1099 unsigned long offset;
1100 unsigned long flags;
1102 spin_lock_irqsave(&port->lock, flags);
1103 trace(ICOM_PORT, "CHANGE_SPEED", 0);
1105 cflag = termios->c_cflag;
1106 iflag = termios->c_iflag;
1108 new_config2 = ICOM_ACFG_DRIVE1;
1110 /* byte size and parity */
1111 switch (cflag & CSIZE) {
1112 case CS5: /* 5 bits/char */
1113 new_config2 |= ICOM_ACFG_5BPC;
1116 case CS6: /* 6 bits/char */
1117 new_config2 |= ICOM_ACFG_6BPC;
1120 case CS7: /* 7 bits/char */
1121 new_config2 |= ICOM_ACFG_7BPC;
1124 case CS8: /* 8 bits/char */
1125 new_config2 |= ICOM_ACFG_8BPC;
1132 if (cflag & CSTOPB) {
1134 new_config2 |= ICOM_ACFG_2STOP_BIT;
1137 if (cflag & PARENB) {
1138 /* parity bit enabled */
1139 new_config2 |= ICOM_ACFG_PARITY_ENAB;
1140 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;
1319 struct icom_port *icom_port;
1321 if (icom_adapter->version == ADAPTER_V1) {
1322 icom_adapter->numb_ports = 2;
1324 for (i = 0; i < 2; i++) {
1325 icom_port = &icom_adapter->port_info[i];
1326 icom_port->port = i;
1327 icom_port->status = ICOM_PORT_ACTIVE;
1328 icom_port->imbed_modem = ICOM_UNKNOWN;
1331 if (subsystem_id == PCI_DEVICE_ID_IBM_ICOM_FOUR_PORT_MODEL) {
1332 icom_adapter->numb_ports = 4;
1334 for (i = 0; i < 4; i++) {
1335 icom_port = &icom_adapter->port_info[i];
1337 icom_port->port = i;
1338 icom_port->status = ICOM_PORT_ACTIVE;
1339 icom_port->imbed_modem = ICOM_IMBED_MODEM;
1342 icom_adapter->numb_ports = 4;
1344 icom_adapter->port_info[0].port = 0;
1345 icom_adapter->port_info[0].status = ICOM_PORT_ACTIVE;
1348 PCI_DEVICE_ID_IBM_ICOM_V2_ONE_PORT_RVX_ONE_PORT_MDM) {
1349 icom_adapter->port_info[0].imbed_modem = ICOM_IMBED_MODEM;
1351 icom_adapter->port_info[0].imbed_modem = ICOM_RVX;
1354 icom_adapter->port_info[1].status = ICOM_PORT_OFF;
1356 icom_adapter->port_info[2].port = 2;
1357 icom_adapter->port_info[2].status = ICOM_PORT_ACTIVE;
1358 icom_adapter->port_info[2].imbed_modem = ICOM_RVX;
1359 icom_adapter->port_info[3].status = ICOM_PORT_OFF;
1366 static void icom_port_active(struct icom_port *icom_port, struct icom_adapter *icom_adapter, int port_num)
1368 if (icom_adapter->version == ADAPTER_V1) {
1369 icom_port->global_reg = icom_adapter->base_addr + 0x4000;
1370 icom_port->int_reg = icom_adapter->base_addr +
1371 0x4004 + 2 - 2 * port_num;
1373 icom_port->global_reg = icom_adapter->base_addr + 0x8000;
1374 if (icom_port->port < 2)
1375 icom_port->int_reg = icom_adapter->base_addr +
1376 0x8004 + 2 - 2 * icom_port->port;
1378 icom_port->int_reg = icom_adapter->base_addr +
1379 0x8024 + 2 - 2 * (icom_port->port - 2);
1382 static int __devinit icom_load_ports(struct icom_adapter *icom_adapter)
1384 struct icom_port *icom_port;
1388 for (port_num = 0; port_num < icom_adapter->numb_ports; port_num++) {
1390 icom_port = &icom_adapter->port_info[port_num];
1392 if (icom_port->status == ICOM_PORT_ACTIVE) {
1393 icom_port_active(icom_port, icom_adapter, port_num);
1394 icom_port->dram = icom_adapter->base_addr +
1395 0x2000 * icom_port->port;
1397 icom_port->adapter = icom_adapter;
1399 /* get port memory */
1400 if ((retval = get_port_memory(icom_port)) != 0) {
1401 dev_err(&icom_port->adapter->pci_dev->dev,
1402 "Memory allocation for port FAILED\n");
1409 static int __devinit icom_alloc_adapter(struct icom_adapter
1412 int adapter_count = 0;
1413 struct icom_adapter *icom_adapter;
1414 struct icom_adapter *cur_adapter_entry;
1415 struct list_head *tmp;
1417 icom_adapter = (struct icom_adapter *)
1418 kzalloc(sizeof(struct icom_adapter), GFP_KERNEL);
1420 if (!icom_adapter) {
1424 list_for_each(tmp, &icom_adapter_head) {
1426 list_entry(tmp, struct icom_adapter,
1427 icom_adapter_entry);
1428 if (cur_adapter_entry->index != adapter_count) {
1434 icom_adapter->index = adapter_count;
1435 list_add_tail(&icom_adapter->icom_adapter_entry, tmp);
1437 *icom_adapter_ref = icom_adapter;
1441 static void icom_free_adapter(struct icom_adapter *icom_adapter)
1443 list_del(&icom_adapter->icom_adapter_entry);
1444 kfree(icom_adapter);
1447 static void icom_remove_adapter(struct icom_adapter *icom_adapter)
1449 struct icom_port *icom_port;
1452 for (index = 0; index < icom_adapter->numb_ports; index++) {
1453 icom_port = &icom_adapter->port_info[index];
1455 if (icom_port->status == ICOM_PORT_ACTIVE) {
1456 dev_info(&icom_adapter->pci_dev->dev,
1457 "Device removed\n");
1459 uart_remove_one_port(&icom_uart_driver,
1460 &icom_port->uart_port);
1462 /* be sure that DTR and RTS are dropped */
1463 writeb(0x00, &icom_port->dram->osr);
1465 /* Wait 0.1 Sec for simple Init to complete */
1468 /* Stop proccessor */
1469 stop_processor(icom_port);
1471 free_port_memory(icom_port);
1475 free_irq(icom_adapter->pci_dev->irq, (void *) icom_adapter);
1476 iounmap(icom_adapter->base_addr);
1477 icom_free_adapter(icom_adapter);
1478 pci_release_regions(icom_adapter->pci_dev);
1481 static void icom_kobj_release(struct kobject *kobj)
1483 struct icom_adapter *icom_adapter;
1485 icom_adapter = to_icom_adapter(kobj);
1486 icom_remove_adapter(icom_adapter);
1489 static struct kobj_type icom_kobj_type = {
1490 .release = icom_kobj_release,
1493 static int __devinit icom_probe(struct pci_dev *dev,
1494 const struct pci_device_id *ent)
1497 unsigned int command_reg;
1499 struct icom_adapter *icom_adapter;
1500 struct icom_port *icom_port;
1502 retval = pci_enable_device(dev);
1504 dev_err(&dev->dev, "Device enable FAILED\n");
1508 if ( (retval = pci_request_regions(dev, "icom"))) {
1509 dev_err(&dev->dev, "pci_request_regions FAILED\n");
1510 pci_disable_device(dev);
1514 pci_set_master(dev);
1516 if ( (retval = pci_read_config_dword(dev, PCI_COMMAND, &command_reg))) {
1517 dev_err(&dev->dev, "PCI Config read FAILED\n");
1521 pci_write_config_dword(dev, PCI_COMMAND,
1522 command_reg | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER
1523 | PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
1525 if (ent->driver_data == ADAPTER_V1) {
1526 pci_write_config_dword(dev, 0x44, 0x8300830A);
1528 pci_write_config_dword(dev, 0x44, 0x42004200);
1529 pci_write_config_dword(dev, 0x48, 0x42004200);
1533 retval = icom_alloc_adapter(&icom_adapter);
1535 dev_err(&dev->dev, "icom_alloc_adapter FAILED\n");
1540 icom_adapter->base_addr_pci = pci_resource_start(dev, 0);
1541 icom_adapter->pci_dev = dev;
1542 icom_adapter->version = ent->driver_data;
1543 icom_adapter->subsystem_id = ent->subdevice;
1546 retval = icom_init_ports(icom_adapter);
1548 dev_err(&dev->dev, "Port configuration failed\n");
1552 icom_adapter->base_addr = ioremap(icom_adapter->base_addr_pci,
1553 pci_resource_len(dev, 0));
1555 if (!icom_adapter->base_addr)
1558 /* save off irq and request irq line */
1559 if ( (retval = request_irq(dev->irq, icom_interrupt,
1560 IRQF_DISABLED | IRQF_SHARED, ICOM_DRIVER_NAME,
1561 (void *) icom_adapter))) {
1565 retval = icom_load_ports(icom_adapter);
1567 for (index = 0; index < icom_adapter->numb_ports; index++) {
1568 icom_port = &icom_adapter->port_info[index];
1570 if (icom_port->status == ICOM_PORT_ACTIVE) {
1571 icom_port->uart_port.irq = icom_port->adapter->pci_dev->irq;
1572 icom_port->uart_port.type = PORT_ICOM;
1573 icom_port->uart_port.iotype = UPIO_MEM;
1574 icom_port->uart_port.membase =
1575 (char *) icom_adapter->base_addr_pci;
1576 icom_port->uart_port.fifosize = 16;
1577 icom_port->uart_port.ops = &icom_ops;
1578 icom_port->uart_port.line =
1579 icom_port->port + icom_adapter->index * 4;
1580 if (uart_add_one_port (&icom_uart_driver, &icom_port->uart_port)) {
1581 icom_port->status = ICOM_PORT_OFF;
1582 dev_err(&dev->dev, "Device add failed\n");
1584 dev_info(&dev->dev, "Device added\n");
1588 kobject_init(&icom_adapter->kobj);
1589 icom_adapter->kobj.ktype = &icom_kobj_type;
1593 iounmap(icom_adapter->base_addr);
1595 icom_free_adapter(icom_adapter);
1598 pci_release_regions(dev);
1599 pci_disable_device(dev);
1606 static void __devexit icom_remove(struct pci_dev *dev)
1608 struct icom_adapter *icom_adapter;
1609 struct list_head *tmp;
1611 list_for_each(tmp, &icom_adapter_head) {
1612 icom_adapter = list_entry(tmp, struct icom_adapter,
1613 icom_adapter_entry);
1614 if (icom_adapter->pci_dev == dev) {
1615 kobject_put(&icom_adapter->kobj);
1620 dev_err(&dev->dev, "Unable to find device to remove\n");
1623 static struct pci_driver icom_pci_driver = {
1624 .name = ICOM_DRIVER_NAME,
1625 .id_table = icom_pci_table,
1626 .probe = icom_probe,
1627 .remove = __devexit_p(icom_remove),
1630 static int __init icom_init(void)
1634 spin_lock_init(&icom_lock);
1636 ret = uart_register_driver(&icom_uart_driver);
1640 ret = pci_register_driver(&icom_pci_driver);
1643 uart_unregister_driver(&icom_uart_driver);
1648 static void __exit icom_exit(void)
1650 pci_unregister_driver(&icom_pci_driver);
1651 uart_unregister_driver(&icom_uart_driver);
1654 module_init(icom_init);
1655 module_exit(icom_exit);
1658 static inline void trace(struct icom_port *icom_port, char *trace_pt,
1659 unsigned long trace_data)
1661 dev_info(&icom_port->adapter->pci_dev->dev, ":%d:%s - %lx\n",
1662 icom_port->port, trace_pt, trace_data);
1666 MODULE_AUTHOR("Michael Anderson <mjanders@us.ibm.com>");
1667 MODULE_DESCRIPTION("IBM iSeries Serial IOA driver");
1668 MODULE_SUPPORTED_DEVICE
1669 ("IBM iSeries 2745, 2771, 2772, 2742, 2793 and 2805 Communications adapters");
1670 MODULE_LICENSE("GPL");