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/config.h>
28 #include <linux/kernel.h>
29 #include <linux/errno.h>
30 #include <linux/signal.h>
31 #include <linux/sched.h>
32 #include <linux/timer.h>
33 #include <linux/interrupt.h>
34 #include <linux/tty.h>
35 #include <linux/termios.h>
37 #include <linux/tty_flip.h>
38 #include <linux/serial.h>
39 #include <linux/serial_reg.h>
40 #include <linux/major.h>
41 #include <linux/string.h>
42 #include <linux/fcntl.h>
43 #include <linux/ptrace.h>
44 #include <linux/ioport.h>
46 #include <linux/slab.h>
47 #include <linux/init.h>
48 #include <linux/delay.h>
49 #include <linux/pci.h>
50 #include <linux/vmalloc.h>
51 #include <linux/smp.h>
52 #include <linux/smp_lock.h>
53 #include <linux/spinlock.h>
54 #include <linux/kobject.h>
55 #include <linux/firmware.h>
56 #include <linux/bitops.h>
58 #include <asm/system.h>
59 #include <asm/segment.h>
62 #include <asm/uaccess.h>
66 /*#define ICOM_TRACE enable port trace capabilities */
68 #define ICOM_DRIVER_NAME "icom"
69 #define ICOM_VERSION_STR "1.3.1"
71 #define ICOM_PORT ((struct icom_port *)port)
72 #define to_icom_adapter(d) container_of(d, struct icom_adapter, kobj)
74 static const struct pci_device_id icom_pci_table[] = {
76 .vendor = PCI_VENDOR_ID_IBM,
77 .device = PCI_DEVICE_ID_IBM_ICOM_DEV_ID_1,
78 .subvendor = PCI_ANY_ID,
79 .subdevice = PCI_ANY_ID,
80 .driver_data = ADAPTER_V1,
83 .vendor = PCI_VENDOR_ID_IBM,
84 .device = PCI_DEVICE_ID_IBM_ICOM_DEV_ID_2,
85 .subvendor = PCI_VENDOR_ID_IBM,
86 .subdevice = PCI_DEVICE_ID_IBM_ICOM_V2_TWO_PORTS_RVX,
87 .driver_data = ADAPTER_V2,
90 .vendor = PCI_VENDOR_ID_IBM,
91 .device = PCI_DEVICE_ID_IBM_ICOM_DEV_ID_2,
92 .subvendor = PCI_VENDOR_ID_IBM,
93 .subdevice = PCI_DEVICE_ID_IBM_ICOM_V2_ONE_PORT_RVX_ONE_PORT_MDM,
94 .driver_data = ADAPTER_V2,
97 .vendor = PCI_VENDOR_ID_IBM,
98 .device = PCI_DEVICE_ID_IBM_ICOM_DEV_ID_2,
99 .subvendor = PCI_VENDOR_ID_IBM,
100 .subdevice = PCI_DEVICE_ID_IBM_ICOM_FOUR_PORT_MODEL,
101 .driver_data = ADAPTER_V2,
106 struct lookup_proc_table start_proc[4] = {
107 {NULL, ICOM_CONTROL_START_A},
108 {NULL, ICOM_CONTROL_START_B},
109 {NULL, ICOM_CONTROL_START_C},
110 {NULL, ICOM_CONTROL_START_D}
114 struct lookup_proc_table stop_proc[4] = {
115 {NULL, ICOM_CONTROL_STOP_A},
116 {NULL, ICOM_CONTROL_STOP_B},
117 {NULL, ICOM_CONTROL_STOP_C},
118 {NULL, ICOM_CONTROL_STOP_D}
121 struct lookup_int_table int_mask_tbl[4] = {
122 {NULL, ICOM_INT_MASK_PRC_A},
123 {NULL, ICOM_INT_MASK_PRC_B},
124 {NULL, ICOM_INT_MASK_PRC_C},
125 {NULL, ICOM_INT_MASK_PRC_D},
129 MODULE_DEVICE_TABLE(pci, icom_pci_table);
131 static LIST_HEAD(icom_adapter_head);
133 /* spinlock for adapter initialization and changing adapter operations */
134 static spinlock_t icom_lock;
137 static inline void trace(struct icom_port *, char *, unsigned long) {};
139 static inline void trace(struct icom_port *icom_port, char *trace_pt, unsigned long trace_data) {};
142 static void free_port_memory(struct icom_port *icom_port)
144 struct pci_dev *dev = icom_port->adapter->pci_dev;
146 trace(icom_port, "RET_PORT_MEM", 0);
147 if (icom_port->recv_buf) {
148 pci_free_consistent(dev, 4096, icom_port->recv_buf,
149 icom_port->recv_buf_pci);
150 icom_port->recv_buf = NULL;
152 if (icom_port->xmit_buf) {
153 pci_free_consistent(dev, 4096, icom_port->xmit_buf,
154 icom_port->xmit_buf_pci);
155 icom_port->xmit_buf = NULL;
157 if (icom_port->statStg) {
158 pci_free_consistent(dev, 4096, icom_port->statStg,
159 icom_port->statStg_pci);
160 icom_port->statStg = NULL;
163 if (icom_port->xmitRestart) {
164 pci_free_consistent(dev, 4096, icom_port->xmitRestart,
165 icom_port->xmitRestart_pci);
166 icom_port->xmitRestart = NULL;
170 static int __init get_port_memory(struct icom_port *icom_port)
173 unsigned long stgAddr;
174 unsigned long startStgAddr;
175 unsigned long offset;
176 struct pci_dev *dev = icom_port->adapter->pci_dev;
178 icom_port->xmit_buf =
179 pci_alloc_consistent(dev, 4096, &icom_port->xmit_buf_pci);
180 if (!icom_port->xmit_buf) {
181 dev_err(&dev->dev, "Can not allocate Transmit buffer\n");
185 trace(icom_port, "GET_PORT_MEM",
186 (unsigned long) icom_port->xmit_buf);
188 icom_port->recv_buf =
189 pci_alloc_consistent(dev, 4096, &icom_port->recv_buf_pci);
190 if (!icom_port->recv_buf) {
191 dev_err(&dev->dev, "Can not allocate Receive buffer\n");
192 free_port_memory(icom_port);
195 trace(icom_port, "GET_PORT_MEM",
196 (unsigned long) icom_port->recv_buf);
199 pci_alloc_consistent(dev, 4096, &icom_port->statStg_pci);
200 if (!icom_port->statStg) {
201 dev_err(&dev->dev, "Can not allocate Status buffer\n");
202 free_port_memory(icom_port);
205 trace(icom_port, "GET_PORT_MEM",
206 (unsigned long) icom_port->statStg);
208 icom_port->xmitRestart =
209 pci_alloc_consistent(dev, 4096, &icom_port->xmitRestart_pci);
210 if (!icom_port->xmitRestart) {
212 "Can not allocate xmit Restart buffer\n");
213 free_port_memory(icom_port);
217 memset(icom_port->statStg, 0, 4096);
219 /* FODs: Frame Out Descriptor Queue, this is a FIFO queue that
220 indicates that frames are to be transmitted
223 stgAddr = (unsigned long) icom_port->statStg;
224 for (index = 0; index < NUM_XBUFFS; index++) {
225 trace(icom_port, "FOD_ADDR", stgAddr);
226 stgAddr = stgAddr + sizeof(icom_port->statStg->xmit[0]);
227 if (index < (NUM_XBUFFS - 1)) {
228 memset(&icom_port->statStg->xmit[index], 0, sizeof(struct xmit_status_area));
229 icom_port->statStg->xmit[index].leLengthASD =
230 (unsigned short int) cpu_to_le16(XMIT_BUFF_SZ);
231 trace(icom_port, "FOD_ADDR", stgAddr);
232 trace(icom_port, "FOD_XBUFF",
233 (unsigned long) icom_port->xmit_buf);
234 icom_port->statStg->xmit[index].leBuffer =
235 cpu_to_le32(icom_port->xmit_buf_pci);
236 } else if (index == (NUM_XBUFFS - 1)) {
237 memset(&icom_port->statStg->xmit[index], 0, sizeof(struct xmit_status_area));
238 icom_port->statStg->xmit[index].leLengthASD =
239 (unsigned short int) cpu_to_le16(XMIT_BUFF_SZ);
240 trace(icom_port, "FOD_XBUFF",
241 (unsigned long) icom_port->xmit_buf);
242 icom_port->statStg->xmit[index].leBuffer =
243 cpu_to_le32(icom_port->xmit_buf_pci);
245 memset(&icom_port->statStg->xmit[index], 0, sizeof(struct xmit_status_area));
249 startStgAddr = stgAddr;
251 /* fill in every entry, even if no buffer */
252 for (index = 0; index < NUM_RBUFFS; index++) {
253 trace(icom_port, "FID_ADDR", stgAddr);
254 stgAddr = stgAddr + sizeof(icom_port->statStg->rcv[0]);
255 icom_port->statStg->rcv[index].leLength = 0;
256 icom_port->statStg->rcv[index].WorkingLength =
257 (unsigned short int) cpu_to_le16(RCV_BUFF_SZ);
258 if (index < (NUM_RBUFFS - 1) ) {
259 offset = stgAddr - (unsigned long) icom_port->statStg;
260 icom_port->statStg->rcv[index].leNext =
261 cpu_to_le32(icom_port-> statStg_pci + offset);
262 trace(icom_port, "FID_RBUFF",
263 (unsigned long) icom_port->recv_buf);
264 icom_port->statStg->rcv[index].leBuffer =
265 cpu_to_le32(icom_port->recv_buf_pci);
266 } else if (index == (NUM_RBUFFS -1) ) {
267 offset = startStgAddr - (unsigned long) icom_port->statStg;
268 icom_port->statStg->rcv[index].leNext =
269 cpu_to_le32(icom_port-> statStg_pci + offset);
270 trace(icom_port, "FID_RBUFF",
271 (unsigned long) icom_port->recv_buf + 2048);
272 icom_port->statStg->rcv[index].leBuffer =
273 cpu_to_le32(icom_port->recv_buf_pci + 2048);
275 icom_port->statStg->rcv[index].leNext = 0;
276 icom_port->statStg->rcv[index].leBuffer = 0;
283 static void stop_processor(struct icom_port *icom_port)
289 spin_lock_irqsave(&icom_lock, flags);
291 port = icom_port->port;
292 if (port == 0 || port == 1)
293 stop_proc[port].global_control_reg = &icom_port->global_reg->control;
295 stop_proc[port].global_control_reg = &icom_port->global_reg->control_2;
299 temp = readl(stop_proc[port].global_control_reg);
301 (temp & ~start_proc[port].processor_id) | stop_proc[port].processor_id;
302 writel(temp, stop_proc[port].global_control_reg);
305 readl(stop_proc[port].global_control_reg);
307 dev_err(&icom_port->adapter->pci_dev->dev,
308 "Invalid port assignment\n");
311 spin_unlock_irqrestore(&icom_lock, flags);
314 static void start_processor(struct icom_port *icom_port)
320 spin_lock_irqsave(&icom_lock, flags);
322 port = icom_port->port;
323 if (port == 0 || port == 1)
324 start_proc[port].global_control_reg = &icom_port->global_reg->control;
326 start_proc[port].global_control_reg = &icom_port->global_reg->control_2;
328 temp = readl(start_proc[port].global_control_reg);
330 (temp & ~stop_proc[port].processor_id) | start_proc[port].processor_id;
331 writel(temp, start_proc[port].global_control_reg);
334 readl(start_proc[port].global_control_reg);
336 dev_err(&icom_port->adapter->pci_dev->dev,
337 "Invalid port assignment\n");
340 spin_unlock_irqrestore(&icom_lock, flags);
343 static void load_code(struct icom_port *icom_port)
345 const struct firmware *fw;
346 char __iomem *iram_ptr;
349 void __iomem *dram_ptr = icom_port->dram;
351 unsigned char *new_page = NULL;
352 unsigned char cable_id = NO_CABLE;
353 struct pci_dev *dev = icom_port->adapter->pci_dev;
355 /* Clear out any pending interrupts */
356 writew(0x3FFF, icom_port->int_reg);
358 trace(icom_port, "CLEAR_INTERRUPTS", 0);
361 stop_processor(icom_port);
364 memset_io(dram_ptr, 0, 512);
366 /* Load Call Setup into Adapter */
367 if (request_firmware(&fw, "icom_call_setup.bin", &dev->dev) < 0) {
368 dev_err(&dev->dev,"Unable to load icom_call_setup.bin firmware image\n");
373 if (fw->size > ICOM_DCE_IRAM_OFFSET) {
374 dev_err(&dev->dev, "Invalid firmware image for icom_call_setup.bin found.\n");
375 release_firmware(fw);
380 iram_ptr = (char __iomem *)icom_port->dram + ICOM_IRAM_OFFSET;
381 for (index = 0; index < fw->size; index++)
382 writeb(fw->data[index], &iram_ptr[index]);
384 release_firmware(fw);
386 /* Load Resident DCE portion of Adapter */
387 if (request_firmware(&fw, "icom_res_dce.bin", &dev->dev) < 0) {
388 dev_err(&dev->dev,"Unable to load icom_res_dce.bin firmware image\n");
393 if (fw->size > ICOM_IRAM_SIZE) {
394 dev_err(&dev->dev, "Invalid firmware image for icom_res_dce.bin found.\n");
395 release_firmware(fw);
400 iram_ptr = (char __iomem *) icom_port->dram + ICOM_IRAM_OFFSET;
401 for (index = ICOM_DCE_IRAM_OFFSET; index < fw->size; index++)
402 writeb(fw->data[index], &iram_ptr[index]);
404 release_firmware(fw);
406 /* Set Hardware level */
407 if ((icom_port->adapter->version | ADAPTER_V2) == ADAPTER_V2)
408 writeb(V2_HARDWARE, &(icom_port->dram->misc_flags));
410 /* Start the processor in Adapter */
411 start_processor(icom_port);
413 writeb((HDLC_PPP_PURE_ASYNC | HDLC_FF_FILL),
414 &(icom_port->dram->HDLCConfigReg));
415 writeb(0x04, &(icom_port->dram->FlagFillIdleTimer)); /* 0.5 seconds */
416 writeb(0x00, &(icom_port->dram->CmdReg));
417 writeb(0x10, &(icom_port->dram->async_config3));
418 writeb((ICOM_ACFG_DRIVE1 | ICOM_ACFG_NO_PARITY | ICOM_ACFG_8BPC |
419 ICOM_ACFG_1STOP_BIT), &(icom_port->dram->async_config2));
421 /*Set up data in icom DRAM to indicate where personality
422 *code is located and its length.
424 new_page = pci_alloc_consistent(dev, 4096, &temp_pci);
427 dev_err(&dev->dev, "Can not allocate DMA buffer\n");
432 if (request_firmware(&fw, "icom_asc.bin", &dev->dev) < 0) {
433 dev_err(&dev->dev,"Unable to load icom_asc.bin firmware image\n");
438 if (fw->size > ICOM_DCE_IRAM_OFFSET) {
439 dev_err(&dev->dev, "Invalid firmware image for icom_asc.bin found.\n");
440 release_firmware(fw);
445 for (index = 0; index < fw->size; index++)
446 new_page[index] = fw->data[index];
448 release_firmware(fw);
450 writeb((char) ((fw->size + 16)/16), &icom_port->dram->mac_length);
451 writel(temp_pci, &icom_port->dram->mac_load_addr);
453 /*Setting the syncReg to 0x80 causes adapter to start downloading
454 the personality code into adapter instruction RAM.
455 Once code is loaded, it will begin executing and, based on
456 information provided above, will start DMAing data from
457 shared memory to adapter DRAM.
459 /* the wait loop below verifies this write operation has been done
462 writeb(START_DOWNLOAD, &icom_port->dram->sync);
464 /* Wait max 1 Sec for data download and processor to start */
465 for (index = 0; index < 10; index++) {
467 if (readb(&icom_port->dram->misc_flags) & ICOM_HDW_ACTIVE)
477 cable_id = readb(&icom_port->dram->cable_id);
479 if (cable_id & ICOM_CABLE_ID_VALID) {
480 /* Get cable ID into the lower 4 bits (standard form) */
481 cable_id = (cable_id & ICOM_CABLE_ID_MASK) >> 4;
482 icom_port->cable_id = cable_id;
484 dev_err(&dev->dev,"Invalid or no cable attached\n");
485 icom_port->cable_id = NO_CABLE;
491 /* Clear out any pending interrupts */
492 writew(0x3FFF, icom_port->int_reg);
495 writeb(ICOM_DISABLE, &(icom_port->dram->disable));
498 stop_processor(icom_port);
500 dev_err(&icom_port->adapter->pci_dev->dev,"Port not opertional\n");
503 if (new_page != NULL)
504 pci_free_consistent(dev, 4096, new_page, temp_pci);
507 static int startup(struct icom_port *icom_port)
510 unsigned char cable_id, raw_cable_id;
514 trace(icom_port, "STARTUP", 0);
516 if (!icom_port->dram) {
517 /* should NEVER be NULL */
518 dev_err(&icom_port->adapter->pci_dev->dev,
519 "Unusable Port, port configuration missing\n");
526 raw_cable_id = readb(&icom_port->dram->cable_id);
527 trace(icom_port, "CABLE_ID", raw_cable_id);
529 /* Get cable ID into the lower 4 bits (standard form) */
530 cable_id = (raw_cable_id & ICOM_CABLE_ID_MASK) >> 4;
532 /* Check for valid Cable ID */
533 if (!(raw_cable_id & ICOM_CABLE_ID_VALID) ||
534 (cable_id != icom_port->cable_id)) {
536 /* reload adapter code, pick up any potential changes in cable id */
537 load_code(icom_port);
539 /* still no sign of cable, error out */
540 raw_cable_id = readb(&icom_port->dram->cable_id);
541 cable_id = (raw_cable_id & ICOM_CABLE_ID_MASK) >> 4;
542 if (!(raw_cable_id & ICOM_CABLE_ID_VALID) ||
543 (icom_port->cable_id == NO_CABLE))
548 * Finally, clear and enable interrupts
550 spin_lock_irqsave(&icom_lock, flags);
551 port = icom_port->port;
552 if (port == 0 || port == 1)
553 int_mask_tbl[port].global_int_mask = &icom_port->global_reg->int_mask;
555 int_mask_tbl[port].global_int_mask = &icom_port->global_reg->int_mask_2;
557 if (port == 0 || port == 2)
558 writew(0x00FF, icom_port->int_reg);
560 writew(0x3F00, icom_port->int_reg);
562 temp = readl(int_mask_tbl[port].global_int_mask);
563 writel(temp & ~int_mask_tbl[port].processor_id, int_mask_tbl[port].global_int_mask);
566 readl(int_mask_tbl[port].global_int_mask);
568 dev_err(&icom_port->adapter->pci_dev->dev,
569 "Invalid port assignment\n");
572 spin_unlock_irqrestore(&icom_lock, flags);
576 static void shutdown(struct icom_port *icom_port)
579 unsigned char cmdReg;
583 spin_lock_irqsave(&icom_lock, flags);
584 trace(icom_port, "SHUTDOWN", 0);
587 * disable all interrupts
589 port = icom_port->port;
590 if (port == 0 || port == 1)
591 int_mask_tbl[port].global_int_mask = &icom_port->global_reg->int_mask;
593 int_mask_tbl[port].global_int_mask = &icom_port->global_reg->int_mask_2;
596 temp = readl(int_mask_tbl[port].global_int_mask);
597 writel(temp | int_mask_tbl[port].processor_id, int_mask_tbl[port].global_int_mask);
600 readl(int_mask_tbl[port].global_int_mask);
602 dev_err(&icom_port->adapter->pci_dev->dev,
603 "Invalid port assignment\n");
605 spin_unlock_irqrestore(&icom_lock, flags);
608 * disable break condition
610 cmdReg = readb(&icom_port->dram->CmdReg);
611 if ((cmdReg | CMD_SND_BREAK) == CMD_SND_BREAK) {
612 writeb(cmdReg & ~CMD_SND_BREAK, &icom_port->dram->CmdReg);
616 static int icom_write(struct uart_port *port)
618 unsigned long data_count;
619 unsigned char cmdReg;
620 unsigned long offset;
621 int temp_tail = port->info->xmit.tail;
623 trace(ICOM_PORT, "WRITE", 0);
625 if (cpu_to_le16(ICOM_PORT->statStg->xmit[0].flags) &
626 SA_FLAGS_READY_TO_XMIT) {
627 trace(ICOM_PORT, "WRITE_FULL", 0);
632 while ((port->info->xmit.head != temp_tail) &&
633 (data_count <= XMIT_BUFF_SZ)) {
635 ICOM_PORT->xmit_buf[data_count++] =
636 port->info->xmit.buf[temp_tail];
639 temp_tail &= (UART_XMIT_SIZE - 1);
643 ICOM_PORT->statStg->xmit[0].flags =
644 cpu_to_le16(SA_FLAGS_READY_TO_XMIT);
645 ICOM_PORT->statStg->xmit[0].leLength =
646 cpu_to_le16(data_count);
648 (unsigned long) &ICOM_PORT->statStg->xmit[0] -
649 (unsigned long) ICOM_PORT->statStg;
650 *ICOM_PORT->xmitRestart =
651 cpu_to_le32(ICOM_PORT->statStg_pci + offset);
652 cmdReg = readb(&ICOM_PORT->dram->CmdReg);
653 writeb(cmdReg | CMD_XMIT_RCV_ENABLE,
654 &ICOM_PORT->dram->CmdReg);
655 writeb(START_XMIT, &ICOM_PORT->dram->StartXmitCmd);
656 trace(ICOM_PORT, "WRITE_START", data_count);
658 readb(&ICOM_PORT->dram->StartXmitCmd);
664 static inline void check_modem_status(struct icom_port *icom_port)
666 static char old_status = 0;
668 unsigned char status;
670 spin_lock(&icom_port->uart_port.lock);
672 /*modem input register */
673 status = readb(&icom_port->dram->isr);
674 trace(icom_port, "CHECK_MODEM", status);
675 delta_status = status ^ old_status;
677 if (delta_status & ICOM_RI)
678 icom_port->uart_port.icount.rng++;
679 if (delta_status & ICOM_DSR)
680 icom_port->uart_port.icount.dsr++;
681 if (delta_status & ICOM_DCD)
682 uart_handle_dcd_change(&icom_port->uart_port,
683 delta_status & ICOM_DCD);
684 if (delta_status & ICOM_CTS)
685 uart_handle_cts_change(&icom_port->uart_port,
686 delta_status & ICOM_CTS);
688 wake_up_interruptible(&icom_port->uart_port.info->
692 spin_unlock(&icom_port->uart_port.lock);
695 static void xmit_interrupt(u16 port_int_reg, struct icom_port *icom_port)
697 unsigned short int count;
700 if (port_int_reg & (INT_XMIT_COMPLETED)) {
701 trace(icom_port, "XMIT_COMPLETE", 0);
703 /* clear buffer in use bit */
704 icom_port->statStg->xmit[0].flags &=
705 cpu_to_le16(~SA_FLAGS_READY_TO_XMIT);
707 count = (unsigned short int)
708 cpu_to_le16(icom_port->statStg->xmit[0].leLength);
709 icom_port->uart_port.icount.tx += count;
712 !uart_circ_empty(&icom_port->uart_port.info->xmit); i++) {
714 icom_port->uart_port.info->xmit.tail++;
715 icom_port->uart_port.info->xmit.tail &=
716 (UART_XMIT_SIZE - 1);
719 if (!icom_write(&icom_port->uart_port))
720 /* activate write queue */
721 uart_write_wakeup(&icom_port->uart_port);
723 trace(icom_port, "XMIT_DISABLED", 0);
726 static void recv_interrupt(u16 port_int_reg, struct icom_port *icom_port)
728 short int count, rcv_buff;
729 struct tty_struct *tty = icom_port->uart_port.info->tty;
730 unsigned short int status;
731 struct uart_icount *icount;
732 unsigned long offset;
734 trace(icom_port, "RCV_COMPLETE", 0);
735 rcv_buff = icom_port->next_rcv;
737 status = cpu_to_le16(icom_port->statStg->rcv[rcv_buff].flags);
738 while (status & SA_FL_RCV_DONE) {
740 trace(icom_port, "FID_STATUS", status);
741 count = cpu_to_le16(icom_port->statStg->rcv[rcv_buff].leLength);
743 trace(icom_port, "RCV_COUNT", count);
744 if (count > (TTY_FLIPBUF_SIZE - tty->flip.count))
745 count = TTY_FLIPBUF_SIZE - tty->flip.count;
747 trace(icom_port, "REAL_COUNT", count);
750 cpu_to_le32(icom_port->statStg->rcv[rcv_buff].leBuffer) -
751 icom_port->recv_buf_pci;
753 memcpy(tty->flip.char_buf_ptr,(unsigned char *)
754 ((unsigned long)icom_port->recv_buf + offset), count);
757 tty->flip.count += count - 1;
758 tty->flip.char_buf_ptr += count - 1;
760 memset(tty->flip.flag_buf_ptr, 0, count);
761 tty->flip.flag_buf_ptr += count - 1;
764 icount = &icom_port->uart_port.icount;
767 /* Break detect logic */
768 if ((status & SA_FLAGS_FRAME_ERROR)
769 && (tty->flip.char_buf_ptr[0] == 0x00)) {
770 status &= ~SA_FLAGS_FRAME_ERROR;
771 status |= SA_FLAGS_BREAK_DET;
772 trace(icom_port, "BREAK_DET", 0);
776 (SA_FLAGS_BREAK_DET | SA_FLAGS_PARITY_ERROR |
777 SA_FLAGS_FRAME_ERROR | SA_FLAGS_OVERRUN)) {
779 if (status & SA_FLAGS_BREAK_DET)
781 if (status & SA_FLAGS_PARITY_ERROR)
783 if (status & SA_FLAGS_FRAME_ERROR)
785 if (status & SA_FLAGS_OVERRUN)
789 * Now check to see if character should be
790 * ignored, and mask off conditions which
793 if (status & icom_port->ignore_status_mask) {
794 trace(icom_port, "IGNORE_CHAR", 0);
798 status &= icom_port->read_status_mask;
800 if (status & SA_FLAGS_BREAK_DET) {
801 *tty->flip.flag_buf_ptr = TTY_BREAK;
802 } else if (status & SA_FLAGS_PARITY_ERROR) {
803 trace(icom_port, "PARITY_ERROR", 0);
804 *tty->flip.flag_buf_ptr = TTY_PARITY;
805 } else if (status & SA_FLAGS_FRAME_ERROR)
806 *tty->flip.flag_buf_ptr = TTY_FRAME;
808 if (status & SA_FLAGS_OVERRUN) {
810 * Overrun is special, since it's
811 * reported immediately, and doesn't
812 * affect the current character
814 if (tty->flip.count < TTY_FLIPBUF_SIZE) {
816 tty->flip.flag_buf_ptr++;
817 tty->flip.char_buf_ptr++;
818 *tty->flip.flag_buf_ptr = TTY_OVERRUN;
823 tty->flip.flag_buf_ptr++;
824 tty->flip.char_buf_ptr++;
827 icom_port->statStg->rcv[rcv_buff].flags = 0;
828 icom_port->statStg->rcv[rcv_buff].leLength = 0;
829 icom_port->statStg->rcv[rcv_buff].WorkingLength =
830 (unsigned short int) cpu_to_le16(RCV_BUFF_SZ);
833 if (rcv_buff == NUM_RBUFFS)
836 status = cpu_to_le16(icom_port->statStg->rcv[rcv_buff].flags);
838 icom_port->next_rcv = rcv_buff;
839 tty_flip_buffer_push(tty);
842 static void process_interrupt(u16 port_int_reg,
843 struct icom_port *icom_port)
846 spin_lock(&icom_port->uart_port.lock);
847 trace(icom_port, "INTERRUPT", port_int_reg);
849 if (port_int_reg & (INT_XMIT_COMPLETED | INT_XMIT_DISABLED))
850 xmit_interrupt(port_int_reg, icom_port);
852 if (port_int_reg & INT_RCV_COMPLETED)
853 recv_interrupt(port_int_reg, icom_port);
855 spin_unlock(&icom_port->uart_port.lock);
858 static irqreturn_t icom_interrupt(int irq, void *dev_id,
859 struct pt_regs *regs)
861 void __iomem * int_reg;
862 u32 adapter_interrupts;
864 struct icom_adapter *icom_adapter;
865 struct icom_port *icom_port;
867 /* find icom_port for this interrupt */
868 icom_adapter = (struct icom_adapter *) dev_id;
870 if ((icom_adapter->version | ADAPTER_V2) == ADAPTER_V2) {
871 int_reg = icom_adapter->base_addr + 0x8024;
873 adapter_interrupts = readl(int_reg);
875 if (adapter_interrupts & 0x00003FFF) {
876 /* port 2 interrupt, NOTE: for all ADAPTER_V2, port 2 will be active */
877 icom_port = &icom_adapter->port_info[2];
878 port_int_reg = (u16) adapter_interrupts;
879 process_interrupt(port_int_reg, icom_port);
880 check_modem_status(icom_port);
882 if (adapter_interrupts & 0x3FFF0000) {
883 /* port 3 interrupt */
884 icom_port = &icom_adapter->port_info[3];
885 if (icom_port->status == ICOM_PORT_ACTIVE) {
887 (u16) (adapter_interrupts >> 16);
888 process_interrupt(port_int_reg, icom_port);
889 check_modem_status(icom_port);
893 /* Clear out any pending interrupts */
894 writel(adapter_interrupts, int_reg);
896 int_reg = icom_adapter->base_addr + 0x8004;
898 int_reg = icom_adapter->base_addr + 0x4004;
901 adapter_interrupts = readl(int_reg);
903 if (adapter_interrupts & 0x00003FFF) {
904 /* port 0 interrupt, NOTE: for all adapters, port 0 will be active */
905 icom_port = &icom_adapter->port_info[0];
906 port_int_reg = (u16) adapter_interrupts;
907 process_interrupt(port_int_reg, icom_port);
908 check_modem_status(icom_port);
910 if (adapter_interrupts & 0x3FFF0000) {
911 /* port 1 interrupt */
912 icom_port = &icom_adapter->port_info[1];
913 if (icom_port->status == ICOM_PORT_ACTIVE) {
914 port_int_reg = (u16) (adapter_interrupts >> 16);
915 process_interrupt(port_int_reg, icom_port);
916 check_modem_status(icom_port);
920 /* Clear out any pending interrupts */
921 writel(adapter_interrupts, int_reg);
923 /* flush the write */
924 adapter_interrupts = readl(int_reg);
930 * ------------------------------------------------------------------
931 * Begin serial-core API
932 * ------------------------------------------------------------------
934 static unsigned int icom_tx_empty(struct uart_port *port)
939 spin_lock_irqsave(&port->lock, flags);
940 if (cpu_to_le16(ICOM_PORT->statStg->xmit[0].flags) &
941 SA_FLAGS_READY_TO_XMIT)
946 spin_unlock_irqrestore(&port->lock, flags);
950 static void icom_set_mctrl(struct uart_port *port, unsigned int mctrl)
952 unsigned char local_osr;
954 trace(ICOM_PORT, "SET_MODEM", 0);
955 local_osr = readb(&ICOM_PORT->dram->osr);
957 if (mctrl & TIOCM_RTS) {
958 trace(ICOM_PORT, "RAISE_RTS", 0);
959 local_osr |= ICOM_RTS;
961 trace(ICOM_PORT, "LOWER_RTS", 0);
962 local_osr &= ~ICOM_RTS;
965 if (mctrl & TIOCM_DTR) {
966 trace(ICOM_PORT, "RAISE_DTR", 0);
967 local_osr |= ICOM_DTR;
969 trace(ICOM_PORT, "LOWER_DTR", 0);
970 local_osr &= ~ICOM_DTR;
973 writeb(local_osr, &ICOM_PORT->dram->osr);
976 static unsigned int icom_get_mctrl(struct uart_port *port)
978 unsigned char status;
981 trace(ICOM_PORT, "GET_MODEM", 0);
983 status = readb(&ICOM_PORT->dram->isr);
985 result = ((status & ICOM_DCD) ? TIOCM_CAR : 0)
986 | ((status & ICOM_RI) ? TIOCM_RNG : 0)
987 | ((status & ICOM_DSR) ? TIOCM_DSR : 0)
988 | ((status & ICOM_CTS) ? TIOCM_CTS : 0);
992 static void icom_stop_tx(struct uart_port *port)
994 unsigned char cmdReg;
996 trace(ICOM_PORT, "STOP", 0);
997 cmdReg = readb(&ICOM_PORT->dram->CmdReg);
998 writeb(cmdReg | CMD_HOLD_XMIT, &ICOM_PORT->dram->CmdReg);
1001 static void icom_start_tx(struct uart_port *port)
1003 unsigned char cmdReg;
1005 trace(ICOM_PORT, "START", 0);
1006 cmdReg = readb(&ICOM_PORT->dram->CmdReg);
1007 if ((cmdReg & CMD_HOLD_XMIT) == CMD_HOLD_XMIT)
1008 writeb(cmdReg & ~CMD_HOLD_XMIT,
1009 &ICOM_PORT->dram->CmdReg);
1014 static void icom_send_xchar(struct uart_port *port, char ch)
1016 unsigned char xdata;
1018 unsigned long flags;
1020 trace(ICOM_PORT, "SEND_XCHAR", ch);
1022 /* wait .1 sec to send char */
1023 for (index = 0; index < 10; index++) {
1024 spin_lock_irqsave(&port->lock, flags);
1025 xdata = readb(&ICOM_PORT->dram->xchar);
1026 if (xdata == 0x00) {
1027 trace(ICOM_PORT, "QUICK_WRITE", 0);
1028 writeb(ch, &ICOM_PORT->dram->xchar);
1030 /* flush write operation */
1031 xdata = readb(&ICOM_PORT->dram->xchar);
1032 spin_unlock_irqrestore(&port->lock, flags);
1035 spin_unlock_irqrestore(&port->lock, flags);
1040 static void icom_stop_rx(struct uart_port *port)
1042 unsigned char cmdReg;
1044 cmdReg = readb(&ICOM_PORT->dram->CmdReg);
1045 writeb(cmdReg & ~CMD_RCV_ENABLE, &ICOM_PORT->dram->CmdReg);
1048 static void icom_enable_ms(struct uart_port *port)
1053 static void icom_break(struct uart_port *port, int break_state)
1055 unsigned char cmdReg;
1056 unsigned long flags;
1058 spin_lock_irqsave(&port->lock, flags);
1059 trace(ICOM_PORT, "BREAK", 0);
1060 cmdReg = readb(&ICOM_PORT->dram->CmdReg);
1061 if (break_state == -1) {
1062 writeb(cmdReg | CMD_SND_BREAK, &ICOM_PORT->dram->CmdReg);
1064 writeb(cmdReg & ~CMD_SND_BREAK, &ICOM_PORT->dram->CmdReg);
1066 spin_unlock_irqrestore(&port->lock, flags);
1069 static int icom_open(struct uart_port *port)
1073 kobject_get(&ICOM_PORT->adapter->kobj);
1074 retval = startup(ICOM_PORT);
1077 kobject_put(&ICOM_PORT->adapter->kobj);
1078 trace(ICOM_PORT, "STARTUP_ERROR", 0);
1085 static void icom_close(struct uart_port *port)
1087 unsigned char cmdReg;
1089 trace(ICOM_PORT, "CLOSE", 0);
1092 cmdReg = readb(&ICOM_PORT->dram->CmdReg);
1093 writeb(cmdReg & (unsigned char) ~CMD_RCV_ENABLE,
1094 &ICOM_PORT->dram->CmdReg);
1096 shutdown(ICOM_PORT);
1098 kobject_put(&ICOM_PORT->adapter->kobj);
1101 static void icom_set_termios(struct uart_port *port,
1102 struct termios *termios,
1103 struct termios *old_termios)
1106 unsigned cflag, iflag;
1109 char new_config3 = 0;
1112 int rcv_buff, xmit_buff;
1113 unsigned long offset;
1114 unsigned long flags;
1116 spin_lock_irqsave(&port->lock, flags);
1117 trace(ICOM_PORT, "CHANGE_SPEED", 0);
1119 cflag = termios->c_cflag;
1120 iflag = termios->c_iflag;
1122 new_config2 = ICOM_ACFG_DRIVE1;
1124 /* byte size and parity */
1125 switch (cflag & CSIZE) {
1126 case CS5: /* 5 bits/char */
1127 new_config2 |= ICOM_ACFG_5BPC;
1130 case CS6: /* 6 bits/char */
1131 new_config2 |= ICOM_ACFG_6BPC;
1134 case CS7: /* 7 bits/char */
1135 new_config2 |= ICOM_ACFG_7BPC;
1138 case CS8: /* 8 bits/char */
1139 new_config2 |= ICOM_ACFG_8BPC;
1146 if (cflag & CSTOPB) {
1148 new_config2 |= ICOM_ACFG_2STOP_BIT;
1151 if (cflag & PARENB) {
1152 /* parity bit enabled */
1153 new_config2 |= ICOM_ACFG_PARITY_ENAB;
1154 trace(ICOM_PORT, "PARENB", 0);
1157 if (cflag & PARODD) {
1159 new_config2 |= ICOM_ACFG_PARITY_ODD;
1160 trace(ICOM_PORT, "PARODD", 0);
1163 /* Determine divisor based on baud rate */
1164 baud = uart_get_baud_rate(port, termios, old_termios,
1166 icom_acfg_baud[BAUD_TABLE_LIMIT]);
1168 baud = 9600; /* B0 transition handled in rs_set_termios */
1170 for (index = 0; index < BAUD_TABLE_LIMIT; index++) {
1171 if (icom_acfg_baud[index] == baud) {
1172 new_config3 = index;
1177 uart_update_timeout(port, cflag, baud);
1179 /* CTS flow control flag and modem status interrupts */
1180 tmp_byte = readb(&(ICOM_PORT->dram->HDLCConfigReg));
1181 if (cflag & CRTSCTS)
1182 tmp_byte |= HDLC_HDW_FLOW;
1184 tmp_byte &= ~HDLC_HDW_FLOW;
1185 writeb(tmp_byte, &(ICOM_PORT->dram->HDLCConfigReg));
1188 * Set up parity check flag
1190 ICOM_PORT->read_status_mask = SA_FLAGS_OVERRUN | SA_FL_RCV_DONE;
1192 ICOM_PORT->read_status_mask |=
1193 SA_FLAGS_FRAME_ERROR | SA_FLAGS_PARITY_ERROR;
1195 if ((iflag & BRKINT) || (iflag & PARMRK))
1196 ICOM_PORT->read_status_mask |= SA_FLAGS_BREAK_DET;
1199 * Characters to ignore
1201 ICOM_PORT->ignore_status_mask = 0;
1203 ICOM_PORT->ignore_status_mask |=
1204 SA_FLAGS_PARITY_ERROR | SA_FLAGS_FRAME_ERROR;
1205 if (iflag & IGNBRK) {
1206 ICOM_PORT->ignore_status_mask |= SA_FLAGS_BREAK_DET;
1208 * If we're ignore parity and break indicators, ignore
1209 * overruns too. (For real raw support).
1212 ICOM_PORT->ignore_status_mask |= SA_FLAGS_OVERRUN;
1216 * !!! ignore all characters if CREAD is not set
1218 if ((cflag & CREAD) == 0)
1219 ICOM_PORT->ignore_status_mask |= SA_FL_RCV_DONE;
1221 /* Turn off Receiver to prepare for reset */
1222 writeb(CMD_RCV_DISABLE, &ICOM_PORT->dram->CmdReg);
1224 for (index = 0; index < 10; index++) {
1225 if (readb(&ICOM_PORT->dram->PrevCmdReg) == 0x00) {
1230 /* clear all current buffers of data */
1231 for (rcv_buff = 0; rcv_buff < NUM_RBUFFS; rcv_buff++) {
1232 ICOM_PORT->statStg->rcv[rcv_buff].flags = 0;
1233 ICOM_PORT->statStg->rcv[rcv_buff].leLength = 0;
1234 ICOM_PORT->statStg->rcv[rcv_buff].WorkingLength =
1235 (unsigned short int) cpu_to_le16(RCV_BUFF_SZ);
1238 for (xmit_buff = 0; xmit_buff < NUM_XBUFFS; xmit_buff++) {
1239 ICOM_PORT->statStg->xmit[xmit_buff].flags = 0;
1242 /* activate changes and start xmit and receiver here */
1243 /* Enable the receiver */
1244 writeb(new_config3, &(ICOM_PORT->dram->async_config3));
1245 writeb(new_config2, &(ICOM_PORT->dram->async_config2));
1246 tmp_byte = readb(&(ICOM_PORT->dram->HDLCConfigReg));
1247 tmp_byte |= HDLC_PPP_PURE_ASYNC | HDLC_FF_FILL;
1248 writeb(tmp_byte, &(ICOM_PORT->dram->HDLCConfigReg));
1249 writeb(0x04, &(ICOM_PORT->dram->FlagFillIdleTimer)); /* 0.5 seconds */
1250 writeb(0xFF, &(ICOM_PORT->dram->ier)); /* enable modem signal interrupts */
1252 /* reset processor */
1253 writeb(CMD_RESTART, &ICOM_PORT->dram->CmdReg);
1255 for (index = 0; index < 10; index++) {
1256 if (readb(&ICOM_PORT->dram->CmdReg) == 0x00) {
1261 /* Enable Transmitter and Reciever */
1263 (unsigned long) &ICOM_PORT->statStg->rcv[0] -
1264 (unsigned long) ICOM_PORT->statStg;
1265 writel(ICOM_PORT->statStg_pci + offset,
1266 &ICOM_PORT->dram->RcvStatusAddr);
1267 ICOM_PORT->next_rcv = 0;
1268 ICOM_PORT->put_length = 0;
1269 *ICOM_PORT->xmitRestart = 0;
1270 writel(ICOM_PORT->xmitRestart_pci,
1271 &ICOM_PORT->dram->XmitStatusAddr);
1272 trace(ICOM_PORT, "XR_ENAB", 0);
1273 writeb(CMD_XMIT_RCV_ENABLE, &ICOM_PORT->dram->CmdReg);
1275 spin_unlock_irqrestore(&port->lock, flags);
1278 static const char *icom_type(struct uart_port *port)
1283 static void icom_release_port(struct uart_port *port)
1287 static int icom_request_port(struct uart_port *port)
1292 static void icom_config_port(struct uart_port *port, int flags)
1294 port->type = PORT_ICOM;
1297 static struct uart_ops icom_ops = {
1298 .tx_empty = icom_tx_empty,
1299 .set_mctrl = icom_set_mctrl,
1300 .get_mctrl = icom_get_mctrl,
1301 .stop_tx = icom_stop_tx,
1302 .start_tx = icom_start_tx,
1303 .send_xchar = icom_send_xchar,
1304 .stop_rx = icom_stop_rx,
1305 .enable_ms = icom_enable_ms,
1306 .break_ctl = icom_break,
1307 .startup = icom_open,
1308 .shutdown = icom_close,
1309 .set_termios = icom_set_termios,
1311 .release_port = icom_release_port,
1312 .request_port = icom_request_port,
1313 .config_port = icom_config_port,
1316 #define ICOM_CONSOLE NULL
1318 static struct uart_driver icom_uart_driver = {
1319 .owner = THIS_MODULE,
1320 .driver_name = ICOM_DRIVER_NAME,
1322 .major = ICOM_MAJOR,
1323 .minor = ICOM_MINOR_START,
1325 .cons = ICOM_CONSOLE,
1328 static int __devinit icom_init_ports(struct icom_adapter *icom_adapter)
1330 u32 subsystem_id = icom_adapter->subsystem_id;
1333 struct icom_port *icom_port;
1335 if (icom_adapter->version == ADAPTER_V1) {
1336 icom_adapter->numb_ports = 2;
1338 for (i = 0; i < 2; i++) {
1339 icom_port = &icom_adapter->port_info[i];
1340 icom_port->port = i;
1341 icom_port->status = ICOM_PORT_ACTIVE;
1342 icom_port->imbed_modem = ICOM_UNKNOWN;
1345 if (subsystem_id == PCI_DEVICE_ID_IBM_ICOM_FOUR_PORT_MODEL) {
1346 icom_adapter->numb_ports = 4;
1348 for (i = 0; i < 4; i++) {
1349 icom_port = &icom_adapter->port_info[i];
1351 icom_port->port = i;
1352 icom_port->status = ICOM_PORT_ACTIVE;
1353 icom_port->imbed_modem = ICOM_IMBED_MODEM;
1356 icom_adapter->numb_ports = 4;
1358 icom_adapter->port_info[0].port = 0;
1359 icom_adapter->port_info[0].status = ICOM_PORT_ACTIVE;
1362 PCI_DEVICE_ID_IBM_ICOM_V2_ONE_PORT_RVX_ONE_PORT_MDM) {
1363 icom_adapter->port_info[0].imbed_modem = ICOM_IMBED_MODEM;
1365 icom_adapter->port_info[0].imbed_modem = ICOM_RVX;
1368 icom_adapter->port_info[1].status = ICOM_PORT_OFF;
1370 icom_adapter->port_info[2].port = 2;
1371 icom_adapter->port_info[2].status = ICOM_PORT_ACTIVE;
1372 icom_adapter->port_info[2].imbed_modem = ICOM_RVX;
1373 icom_adapter->port_info[3].status = ICOM_PORT_OFF;
1380 static void icom_port_active(struct icom_port *icom_port, struct icom_adapter *icom_adapter, int port_num)
1382 if (icom_adapter->version == ADAPTER_V1) {
1383 icom_port->global_reg = icom_adapter->base_addr + 0x4000;
1384 icom_port->int_reg = icom_adapter->base_addr +
1385 0x4004 + 2 - 2 * port_num;
1387 icom_port->global_reg = icom_adapter->base_addr + 0x8000;
1388 if (icom_port->port < 2)
1389 icom_port->int_reg = icom_adapter->base_addr +
1390 0x8004 + 2 - 2 * icom_port->port;
1392 icom_port->int_reg = icom_adapter->base_addr +
1393 0x8024 + 2 - 2 * (icom_port->port - 2);
1396 static int __init icom_load_ports(struct icom_adapter *icom_adapter)
1398 struct icom_port *icom_port;
1402 for (port_num = 0; port_num < icom_adapter->numb_ports; port_num++) {
1404 icom_port = &icom_adapter->port_info[port_num];
1406 if (icom_port->status == ICOM_PORT_ACTIVE) {
1407 icom_port_active(icom_port, icom_adapter, port_num);
1408 icom_port->dram = icom_adapter->base_addr +
1409 0x2000 * icom_port->port;
1411 icom_port->adapter = icom_adapter;
1413 /* get port memory */
1414 if ((retval = get_port_memory(icom_port)) != 0) {
1415 dev_err(&icom_port->adapter->pci_dev->dev,
1416 "Memory allocation for port FAILED\n");
1423 static int __devinit icom_alloc_adapter(struct icom_adapter
1426 int adapter_count = 0;
1427 struct icom_adapter *icom_adapter;
1428 struct icom_adapter *cur_adapter_entry;
1429 struct list_head *tmp;
1431 icom_adapter = (struct icom_adapter *)
1432 kmalloc(sizeof(struct icom_adapter), GFP_KERNEL);
1434 if (!icom_adapter) {
1438 memset(icom_adapter, 0, sizeof(struct icom_adapter));
1440 list_for_each(tmp, &icom_adapter_head) {
1442 list_entry(tmp, struct icom_adapter,
1443 icom_adapter_entry);
1444 if (cur_adapter_entry->index != adapter_count) {
1450 icom_adapter->index = adapter_count;
1451 list_add_tail(&icom_adapter->icom_adapter_entry, tmp);
1453 *icom_adapter_ref = icom_adapter;
1457 static void icom_free_adapter(struct icom_adapter *icom_adapter)
1459 list_del(&icom_adapter->icom_adapter_entry);
1460 kfree(icom_adapter);
1463 static void icom_remove_adapter(struct icom_adapter *icom_adapter)
1465 struct icom_port *icom_port;
1468 for (index = 0; index < icom_adapter->numb_ports; index++) {
1469 icom_port = &icom_adapter->port_info[index];
1471 if (icom_port->status == ICOM_PORT_ACTIVE) {
1472 dev_info(&icom_adapter->pci_dev->dev,
1473 "Device removed\n");
1475 uart_remove_one_port(&icom_uart_driver,
1476 &icom_port->uart_port);
1478 /* be sure that DTR and RTS are dropped */
1479 writeb(0x00, &icom_port->dram->osr);
1481 /* Wait 0.1 Sec for simple Init to complete */
1484 /* Stop proccessor */
1485 stop_processor(icom_port);
1487 free_port_memory(icom_port);
1491 free_irq(icom_adapter->irq_number, (void *) icom_adapter);
1492 iounmap(icom_adapter->base_addr);
1493 icom_free_adapter(icom_adapter);
1494 pci_release_regions(icom_adapter->pci_dev);
1497 static void icom_kobj_release(struct kobject *kobj)
1499 struct icom_adapter *icom_adapter;
1501 icom_adapter = to_icom_adapter(kobj);
1502 icom_remove_adapter(icom_adapter);
1505 static struct kobj_type icom_kobj_type = {
1506 .release = icom_kobj_release,
1509 static int __devinit icom_probe(struct pci_dev *dev,
1510 const struct pci_device_id *ent)
1513 unsigned int command_reg;
1515 struct icom_adapter *icom_adapter;
1516 struct icom_port *icom_port;
1518 retval = pci_enable_device(dev);
1520 dev_err(&dev->dev, "Device enable FAILED\n");
1524 if ( (retval = pci_request_regions(dev, "icom"))) {
1525 dev_err(&dev->dev, "pci_request_region FAILED\n");
1526 pci_disable_device(dev);
1530 pci_set_master(dev);
1532 if ( (retval = pci_read_config_dword(dev, PCI_COMMAND, &command_reg))) {
1533 dev_err(&dev->dev, "PCI Config read FAILED\n");
1537 pci_write_config_dword(dev, PCI_COMMAND,
1538 command_reg | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER
1539 | PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
1541 if (ent->driver_data == ADAPTER_V1) {
1542 pci_write_config_dword(dev, 0x44, 0x8300830A);
1544 pci_write_config_dword(dev, 0x44, 0x42004200);
1545 pci_write_config_dword(dev, 0x48, 0x42004200);
1549 retval = icom_alloc_adapter(&icom_adapter);
1551 dev_err(&dev->dev, "icom_alloc_adapter FAILED\n");
1556 icom_adapter->base_addr_pci = pci_resource_start(dev, 0);
1557 icom_adapter->irq_number = dev->irq;
1558 icom_adapter->pci_dev = dev;
1559 icom_adapter->version = ent->driver_data;
1560 icom_adapter->subsystem_id = ent->subdevice;
1563 retval = icom_init_ports(icom_adapter);
1565 dev_err(&dev->dev, "Port configuration failed\n");
1569 icom_adapter->base_addr = ioremap(icom_adapter->base_addr_pci,
1570 pci_resource_len(dev, 0));
1572 if (!icom_adapter->base_addr)
1575 /* save off irq and request irq line */
1576 if ( (retval = request_irq(dev->irq, icom_interrupt,
1577 SA_INTERRUPT | SA_SHIRQ, ICOM_DRIVER_NAME,
1578 (void *) icom_adapter))) {
1582 retval = icom_load_ports(icom_adapter);
1584 for (index = 0; index < icom_adapter->numb_ports; index++) {
1585 icom_port = &icom_adapter->port_info[index];
1587 if (icom_port->status == ICOM_PORT_ACTIVE) {
1588 icom_port->uart_port.irq = icom_port->adapter->irq_number;
1589 icom_port->uart_port.type = PORT_ICOM;
1590 icom_port->uart_port.iotype = UPIO_MEM;
1591 icom_port->uart_port.membase =
1592 (char *) icom_adapter->base_addr_pci;
1593 icom_port->uart_port.fifosize = 16;
1594 icom_port->uart_port.ops = &icom_ops;
1595 icom_port->uart_port.line =
1596 icom_port->port + icom_adapter->index * 4;
1597 if (uart_add_one_port (&icom_uart_driver, &icom_port->uart_port)) {
1598 icom_port->status = ICOM_PORT_OFF;
1599 dev_err(&dev->dev, "Device add failed\n");
1601 dev_info(&dev->dev, "Device added\n");
1605 kobject_init(&icom_adapter->kobj);
1606 icom_adapter->kobj.ktype = &icom_kobj_type;
1610 iounmap(icom_adapter->base_addr);
1612 icom_free_adapter(icom_adapter);
1615 pci_release_regions(dev);
1616 pci_disable_device(dev);
1623 static void __devexit icom_remove(struct pci_dev *dev)
1625 struct icom_adapter *icom_adapter;
1626 struct list_head *tmp;
1628 list_for_each(tmp, &icom_adapter_head) {
1629 icom_adapter = list_entry(tmp, struct icom_adapter,
1630 icom_adapter_entry);
1631 if (icom_adapter->pci_dev == dev) {
1632 kobject_put(&icom_adapter->kobj);
1637 dev_err(&dev->dev, "Unable to find device to remove\n");
1640 static struct pci_driver icom_pci_driver = {
1641 .name = ICOM_DRIVER_NAME,
1642 .id_table = icom_pci_table,
1643 .probe = icom_probe,
1644 .remove = __devexit_p(icom_remove),
1647 static int __init icom_init(void)
1651 spin_lock_init(&icom_lock);
1653 ret = uart_register_driver(&icom_uart_driver);
1657 ret = pci_register_driver(&icom_pci_driver);
1660 uart_unregister_driver(&icom_uart_driver);
1665 static void __exit icom_exit(void)
1667 pci_unregister_driver(&icom_pci_driver);
1668 uart_unregister_driver(&icom_uart_driver);
1671 module_init(icom_init);
1672 module_exit(icom_exit);
1675 static inline void trace(struct icom_port *icom_port, char *trace_pt,
1676 unsigned long trace_data)
1678 dev_info(&icom_port->adapter->pci_dev->dev, ":%d:%s - %lx\n",
1679 icom_port->port, trace_pt, trace_data);
1683 MODULE_AUTHOR("Michael Anderson <mjanders@us.ibm.com>");
1684 MODULE_DESCRIPTION("IBM iSeries Serial IOA driver");
1685 MODULE_SUPPORTED_DEVICE
1686 ("IBM iSeries 2745, 2771, 2772, 2742, 2793 and 2805 Communications adapters");
1687 MODULE_LICENSE("GPL");