/* * Function ircomm_tty_init() * * Init IrCOMM TTY layer/driver * */ static int __init ircomm_tty_init(void) { driver = alloc_tty_driver(IRCOMM_TTY_PORTS); if (!driver) return -ENOMEM; ircomm_tty = hashbin_new(HB_LOCK); if (ircomm_tty == NULL) { IRDA_ERROR("%s(), can't allocate hashbin!\n", __FUNCTION__); put_tty_driver(driver); return -ENOMEM; } driver->owner = THIS_MODULE; driver->driver_name = "ircomm"; driver->name = "ircomm"; driver->major = IRCOMM_TTY_MAJOR; driver->minor_start = IRCOMM_TTY_MINOR; driver->type = TTY_DRIVER_TYPE_SERIAL; driver->subtype = SERIAL_TYPE_NORMAL; driver->init_termios = tty_std_termios; driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL; driver->flags = TTY_DRIVER_REAL_RAW; tty_set_operations(driver, &ops); if (tty_register_driver(driver)) { IRDA_ERROR("%s(): Couldn't register serial driver\n", __FUNCTION__); put_tty_driver(driver); return -1; } return 0; }
int sirdev_schedule_request(struct sir_dev *dev, int initial_state, unsigned param) { struct sir_fsm *fsm = &dev->fsm; IRDA_DEBUG(2, "%s - state=0x%04x / param=%u\n", __func__, initial_state, param); if (down_trylock(&fsm->sem)) { if (in_interrupt() || in_atomic() || irqs_disabled()) { IRDA_DEBUG(1, "%s(), state machine busy!\n", __func__); return -EWOULDBLOCK; } else down(&fsm->sem); } if (fsm->state == SIRDEV_STATE_DEAD) { /* race with sirdev_close should never happen */ IRDA_ERROR("%s(), instance staled!\n", __func__); up(&fsm->sem); return -ESTALE; /* or better EPIPE? */ } netif_stop_queue(dev->netdev); atomic_set(&dev->enable_rx, 0); fsm->state = initial_state; fsm->param = param; fsm->result = 0; INIT_DELAYED_WORK(&fsm->work, sirdev_config_fsm); queue_delayed_work(irda_sir_wq, &fsm->work, 0); return 0; }
static int sirdev_tx_complete_fsm(struct sir_dev *dev) { struct sir_fsm *fsm = &dev->fsm; unsigned next_state, delay; unsigned bytes_left; do { next_state = fsm->substate; /* default: stay in current substate */ delay = 0; switch(fsm->substate) { case SIRDEV_STATE_WAIT_XMIT: if (dev->drv->chars_in_buffer) bytes_left = dev->drv->chars_in_buffer(dev); else bytes_left = 0; if (!bytes_left) { next_state = SIRDEV_STATE_WAIT_UNTIL_SENT; break; } if (dev->speed > 115200) delay = (bytes_left*8*10000) / (dev->speed/100); else if (dev->speed > 0) delay = (bytes_left*10*10000) / (dev->speed/100); else delay = 0; /* expected delay (usec) until remaining bytes are sent */ if (delay < 100) { udelay(delay); delay = 0; break; } /* sleep some longer delay (msec) */ delay = (delay+999) / 1000; break; case SIRDEV_STATE_WAIT_UNTIL_SENT: /* block until underlaying hardware buffer are empty */ if (dev->drv->wait_until_sent) dev->drv->wait_until_sent(dev); next_state = SIRDEV_STATE_TX_DONE; break; case SIRDEV_STATE_TX_DONE: return 0; default: IRDA_ERROR("%s - undefined state\n", __func__); return -EINVAL; } fsm->substate = next_state; } while (delay == 0); return delay; }
/* * Function ircomm_tty_init() * * Init IrCOMM TTY layer/driver * */ static int __init ircomm_tty_init(void) { driver = alloc_tty_driver(IRCOMM_TTY_PORTS); if (!driver) return -ENOMEM; ircomm_tty = hashbin_new(HB_LOCK); if (ircomm_tty == NULL) { IRDA_ERROR("%s(), can't allocate hashbin!\n", __func__); put_tty_driver(driver); return -ENOMEM; } <<<<<<< HEAD
static int girbil_reset(struct sir_dev *dev) { unsigned state = dev->fsm.substate; unsigned delay = 0; u8 control = GIRBIL_TXEN | GIRBIL_RXEN; int ret = 0; IRDA_DEBUG(2, "%s()\n", __func__); switch (state) { case SIRDEV_STATE_DONGLE_RESET: sirdev_set_dtr_rts(dev, TRUE, FALSE); delay = 20; state = GIRBIL_STATE_WAIT1_RESET; break; case GIRBIL_STATE_WAIT1_RESET: sirdev_set_dtr_rts(dev, FALSE, TRUE); delay = 20; state = GIRBIL_STATE_WAIT2_RESET; break; case GIRBIL_STATE_WAIT2_RESET: sirdev_raw_write(dev, &control, 1); delay = 20; state = GIRBIL_STATE_WAIT3_RESET; break; case GIRBIL_STATE_WAIT3_RESET: sirdev_set_dtr_rts(dev, TRUE, TRUE); dev->speed = 9600; break; default: IRDA_ERROR("%s(), undefined state %d\n", __func__, state); ret = -1; break; } dev->fsm.substate = state; return (delay > 0) ? delay : ret; }
static int girbil_reset(struct sir_dev *dev) { unsigned state = dev->fsm.substate; unsigned delay = 0; u8 control = GIRBIL_TXEN | GIRBIL_RXEN; int ret = 0; IRDA_DEBUG(2, "%s()\n", __FUNCTION__); switch (state) { case SIRDEV_STATE_DONGLE_RESET: /* Reset dongle */ sirdev_set_dtr_rts(dev, TRUE, FALSE); /* Sleep at least 5 ms */ delay = 20; state = GIRBIL_STATE_WAIT1_RESET; break; case GIRBIL_STATE_WAIT1_RESET: /* Set DTR and clear RTS to enter command mode */ sirdev_set_dtr_rts(dev, FALSE, TRUE); delay = 20; state = GIRBIL_STATE_WAIT2_RESET; break; case GIRBIL_STATE_WAIT2_RESET: /* Write control byte */ sirdev_raw_write(dev, &control, 1); delay = 20; state = GIRBIL_STATE_WAIT3_RESET; break; case GIRBIL_STATE_WAIT3_RESET: /* Go back to normal mode */ sirdev_set_dtr_rts(dev, TRUE, TRUE); dev->speed = 9600; break; default: IRDA_ERROR("%s(), undefined state %d\n", __FUNCTION__, state); ret = -1; break; } dev->fsm.substate = state; return (delay > 0) ? delay : ret; }
int __init irttp_init(void) { irttp = kzalloc(sizeof(struct irttp_cb), GFP_KERNEL); if (irttp == NULL) return -ENOMEM; irttp->magic = TTP_MAGIC; irttp->tsaps = hashbin_new(HB_LOCK); if (!irttp->tsaps) { IRDA_ERROR("%s: can't allocate IrTTP hashbin!\n", __func__); kfree(irttp); return -ENOMEM; } return 0; }
/* * Function irda_device_is_receiving (dev) * * Check if the device driver is currently receiving data * */ int irda_device_is_receiving(struct net_device *dev) { struct if_irda_req req; int ret; IRDA_DEBUG(2, "%s()\n", __FUNCTION__); if (!dev->do_ioctl) { IRDA_ERROR("%s: do_ioctl not impl. by device driver\n", __FUNCTION__); return -1; } ret = dev->do_ioctl(dev, (struct ifreq *) &req, SIOCGRECEIVING); if (ret < 0) return ret; return req.ifr_receiving; }
static int __init ircomm_init(void) { ircomm = hashbin_new(HB_LOCK); if (ircomm == NULL) { IRDA_ERROR("%s(), can't allocate hashbin!\n", __FUNCTION__); return -ENOMEM; } #ifdef CONFIG_PROC_FS { struct proc_dir_entry *ent; ent = create_proc_entry("ircomm", 0, proc_irda); if (ent) ent->proc_fops = &ircomm_proc_fops; } #endif /* CONFIG_PROC_FS */ IRDA_MESSAGE("IrCOMM protocol (Dag Brattli)\n"); return 0; }
static int mcp2120_reset(struct sir_dev *dev) { unsigned state = dev->fsm.substate; unsigned delay = 0; int ret = 0; IRDA_DEBUG(2, "%s()\n", __func__); switch (state) { case SIRDEV_STATE_DONGLE_RESET: ; /* Reset dongle by setting RTS*/ sirdev_set_dtr_rts(dev, TRUE, TRUE); state = MCP2120_STATE_WAIT1_RESET; delay = 50; break; case MCP2120_STATE_WAIT1_RESET: ; /* clear RTS and wait for at least 30 ms. */ sirdev_set_dtr_rts(dev, FALSE, FALSE); state = MCP2120_STATE_WAIT2_RESET; delay = 50; break; case MCP2120_STATE_WAIT2_RESET: ; /* Go back to normal mode */ sirdev_set_dtr_rts(dev, FALSE, FALSE); break; default: IRDA_ERROR("%s(), undefined state %d\n", __func__, state); ret = -EINVAL; break; } dev->fsm.substate = state; return (delay > 0) ? delay : ret; }
static int __init ircomm_init(void) { ircomm = hashbin_new(HB_LOCK); if (ircomm == NULL) { IRDA_ERROR("%s(), can't allocate hashbin!\n", __func__); return -ENOMEM; } #ifdef CONFIG_PROC_FS { struct proc_dir_entry *ent; ent = proc_create("ircomm", 0, proc_irda, &ircomm_proc_fops); if (!ent) { printk(KERN_ERR "ircomm_init: can't create /proc entry!\n"); return -ENODEV; } } #endif IRDA_MESSAGE("IrCOMM protocol (Dag Brattli)\n"); return 0; }
static int mcp2120_change_speed(struct sir_dev *dev, unsigned speed) { unsigned state = dev->fsm.substate; unsigned delay = 0; u8 control[2]; static int ret = 0; IRDA_DEBUG(2, "%s()\n", __func__); switch (state) { case SIRDEV_STATE_DONGLE_SPEED: /* Set DTR to enter command mode */ sirdev_set_dtr_rts(dev, TRUE, FALSE); udelay(500); ret = 0; switch (speed) { default: speed = 9600; ret = -EINVAL; /* fall through */ case 9600: control[0] = MCP2120_9600; ; break; case 19200: control[0] = MCP2120_19200; ; break; case 34800: control[0] = MCP2120_38400; ; break; case 57600: control[0] = MCP2120_57600; ; break; case 115200: control[0] = MCP2120_115200; ; break; } control[1] = MCP2120_COMMIT; /* Write control bytes */ sirdev_raw_write(dev, control, 2); dev->speed = speed; state = MCP2120_STATE_WAIT_SPEED; delay = 100; ; break; case MCP2120_STATE_WAIT_SPEED: /* Go back to normal mode */ sirdev_set_dtr_rts(dev, FALSE, FALSE); ; break; default: IRDA_ERROR("%s(), undefine state %d\n", __func__, state); ret = -EINVAL; break; } dev->fsm.substate = state; return (delay > 0) ? delay : ret; }
static void sirdev_config_fsm(struct work_struct *work) { struct sir_dev *dev = container_of(work, struct sir_dev, fsm.work.work); struct sir_fsm *fsm = &dev->fsm; int next_state; int ret = -1; unsigned delay; IRDA_DEBUG(2, "%s(), <%ld>\n", __func__, jiffies); do { IRDA_DEBUG(3, "%s - state=0x%04x / substate=0x%04x\n", __func__, fsm->state, fsm->substate); next_state = fsm->state; delay = 0; switch(fsm->state) { case SIRDEV_STATE_DONGLE_OPEN: if (dev->dongle_drv != NULL) { ret = sirdev_put_dongle(dev); if (ret) { fsm->result = -EINVAL; next_state = SIRDEV_STATE_ERROR; break; } } /* Initialize dongle */ ret = sirdev_get_dongle(dev, fsm->param); if (ret) { fsm->result = ret; next_state = SIRDEV_STATE_ERROR; break; } /* Dongles are powered through the modem control lines which * were just set during open. Before resetting, let's wait for * the power to stabilize. This is what some dongle drivers did * in open before, while others didn't - should be safe anyway. */ delay = 50; fsm->substate = SIRDEV_STATE_DONGLE_RESET; next_state = SIRDEV_STATE_DONGLE_RESET; fsm->param = 9600; break; case SIRDEV_STATE_DONGLE_CLOSE: /* shouldn't we just treat this as success=? */ if (dev->dongle_drv == NULL) { fsm->result = -EINVAL; next_state = SIRDEV_STATE_ERROR; break; } ret = sirdev_put_dongle(dev); if (ret) { fsm->result = ret; next_state = SIRDEV_STATE_ERROR; break; } next_state = SIRDEV_STATE_DONE; break; case SIRDEV_STATE_SET_DTR_RTS: ret = sirdev_set_dtr_rts(dev, (fsm->param&0x02) ? TRUE : FALSE, (fsm->param&0x01) ? TRUE : FALSE); next_state = SIRDEV_STATE_DONE; break; case SIRDEV_STATE_SET_SPEED: fsm->substate = SIRDEV_STATE_WAIT_XMIT; next_state = SIRDEV_STATE_DONGLE_CHECK; break; case SIRDEV_STATE_DONGLE_CHECK: ret = sirdev_tx_complete_fsm(dev); if (ret < 0) { fsm->result = ret; next_state = SIRDEV_STATE_ERROR; break; } if ((delay=ret) != 0) break; if (dev->dongle_drv) { fsm->substate = SIRDEV_STATE_DONGLE_RESET; next_state = SIRDEV_STATE_DONGLE_RESET; } else { dev->speed = fsm->param; next_state = SIRDEV_STATE_PORT_SPEED; } break; case SIRDEV_STATE_DONGLE_RESET: if (dev->dongle_drv->reset) { ret = dev->dongle_drv->reset(dev); if (ret < 0) { fsm->result = ret; next_state = SIRDEV_STATE_ERROR; break; } } else ret = 0; if ((delay=ret) == 0) { /* set serial port according to dongle default speed */ if (dev->drv->set_speed) dev->drv->set_speed(dev, dev->speed); fsm->substate = SIRDEV_STATE_DONGLE_SPEED; next_state = SIRDEV_STATE_DONGLE_SPEED; } break; case SIRDEV_STATE_DONGLE_SPEED: if (dev->dongle_drv->set_speed) { ret = dev->dongle_drv->set_speed(dev, fsm->param); if (ret < 0) { fsm->result = ret; next_state = SIRDEV_STATE_ERROR; break; } } else ret = 0; if ((delay=ret) == 0) next_state = SIRDEV_STATE_PORT_SPEED; break; case SIRDEV_STATE_PORT_SPEED: /* Finally we are ready to change the serial port speed */ if (dev->drv->set_speed) dev->drv->set_speed(dev, dev->speed); dev->new_speed = 0; next_state = SIRDEV_STATE_DONE; break; case SIRDEV_STATE_DONE: /* Signal network layer so it can send more frames */ netif_wake_queue(dev->netdev); next_state = SIRDEV_STATE_COMPLETE; break; default: IRDA_ERROR("%s - undefined state\n", __func__); fsm->result = -EINVAL; /* fall thru */ case SIRDEV_STATE_ERROR: IRDA_ERROR("%s - error: %d\n", __func__, fsm->result); #if 0 /* don't enable this before we have netdev->tx_timeout to recover */ netif_stop_queue(dev->netdev); #else netif_wake_queue(dev->netdev); #endif /* fall thru */ case SIRDEV_STATE_COMPLETE: /* config change finished, so we are not busy any longer */ sirdev_enable_rx(dev); up(&fsm->sem); return; } fsm->state = next_state; } while(!delay); queue_delayed_work(irda_sir_wq, &fsm->work, msecs_to_jiffies(delay)); }
/* * Function async_wrap (skb, *tx_buff, buffsize) * * Makes a new buffer with wrapping and stuffing, should check that * we don't get tx buffer overflow. */ int async_wrap_skb(struct sk_buff *skb, __u8 *tx_buff, int buffsize) { struct irda_skb_cb *cb = (struct irda_skb_cb *) skb->cb; int xbofs; int i; int n; union { __u16 value; __u8 bytes[2]; } fcs; /* Initialize variables */ fcs.value = INIT_FCS; n = 0; /* * Send XBOF's for required min. turn time and for the negotiated * additional XBOFS */ if (cb->magic != LAP_MAGIC) { /* * This will happen for all frames sent from user-space. * Nothing to worry about, but we set the default number of * BOF's */ IRDA_DEBUG(1, "%s(), wrong magic in skb!\n", __FUNCTION__); xbofs = 10; } else xbofs = cb->xbofs + cb->xbofs_delay; IRDA_DEBUG(4, "%s(), xbofs=%d\n", __FUNCTION__, xbofs); /* Check that we never use more than 115 + 48 xbofs */ if (xbofs > 163) { IRDA_DEBUG(0, "%s(), too many xbofs (%d)\n", __FUNCTION__, xbofs); xbofs = 163; } memset(tx_buff + n, XBOF, xbofs); n += xbofs; /* Start of packet character BOF */ tx_buff[n++] = BOF; /* Insert frame and calc CRC */ for (i=0; i < skb->len; i++) { /* * Check for the possibility of tx buffer overflow. We use * bufsize-5 since the maximum number of bytes that can be * transmitted after this point is 5. */ if(n >= (buffsize-5)) { IRDA_ERROR("%s(), tx buffer overflow (n=%d)\n", __FUNCTION__, n); return n; } n += stuff_byte(skb->data[i], tx_buff+n); fcs.value = irda_fcs(fcs.value, skb->data[i]); } /* Insert CRC in little endian format (LSB first) */ fcs.value = ~fcs.value; #ifdef __LITTLE_ENDIAN n += stuff_byte(fcs.bytes[0], tx_buff+n); n += stuff_byte(fcs.bytes[1], tx_buff+n); #else /* ifdef __BIG_ENDIAN */ n += stuff_byte(fcs.bytes[1], tx_buff+n); n += stuff_byte(fcs.bytes[0], tx_buff+n); #endif tx_buff[n++] = EOF; return n; }
static struct irport_cb * irport_open(int i, unsigned int iobase, unsigned int irq) { struct net_device *dev; struct irport_cb *self; IRDA_DEBUG(1, "%s()\n", __FUNCTION__); /* Lock the port that we need */ if (!request_region(iobase, IO_EXTENT, driver_name)) { IRDA_DEBUG(0, "%s(), can't get iobase of 0x%03x\n", __FUNCTION__, iobase); goto err_out1; } /* * Allocate new instance of the driver */ dev = alloc_irdadev(sizeof(struct irport_cb)); if (!dev) { IRDA_ERROR("%s(), can't allocate memory for " "irda device!\n", __FUNCTION__); goto err_out2; } self = dev->priv; spin_lock_init(&self->lock); /* Need to store self somewhere */ dev_self[i] = self; self->priv = self; self->index = i; /* Initialize IO */ self->io.sir_base = iobase; self->io.sir_ext = IO_EXTENT; self->io.irq = irq; self->io.fifo_size = 16; /* 16550A and compatible */ /* Initialize QoS for this device */ irda_init_max_qos_capabilies(&self->qos); self->qos.baud_rate.bits = IR_9600|IR_19200|IR_38400|IR_57600| IR_115200; self->qos.min_turn_time.bits = qos_mtt_bits; irda_qos_bits_to_value(&self->qos); /* Bootstrap ZeroCopy Rx */ self->rx_buff.truesize = IRDA_SKB_MAX_MTU; self->rx_buff.skb = __dev_alloc_skb(self->rx_buff.truesize, GFP_KERNEL); if (self->rx_buff.skb == NULL) { IRDA_ERROR("%s(), can't allocate memory for " "receive buffer!\n", __FUNCTION__); goto err_out3; } skb_reserve(self->rx_buff.skb, 1); self->rx_buff.head = self->rx_buff.skb->data; /* No need to memset the buffer, unless you are really pedantic */ /* Finish setup the Rx buffer descriptor */ self->rx_buff.in_frame = FALSE; self->rx_buff.state = OUTSIDE_FRAME; self->rx_buff.data = self->rx_buff.head; /* Specify how much memory we want */ self->tx_buff.truesize = 4000; /* Allocate memory if needed */ if (self->tx_buff.truesize > 0) { self->tx_buff.head = kzalloc(self->tx_buff.truesize, GFP_KERNEL); if (self->tx_buff.head == NULL) { IRDA_ERROR("%s(), can't allocate memory for " "transmit buffer!\n", __FUNCTION__); goto err_out4; } } self->tx_buff.data = self->tx_buff.head; self->netdev = dev; /* Keep track of module usage */ SET_MODULE_OWNER(dev); /* May be overridden by piggyback drivers */ self->interrupt = irport_interrupt; self->change_speed = irport_change_speed; /* Override the network functions we need to use */ dev->hard_start_xmit = irport_hard_xmit; dev->tx_timeout = irport_timeout; dev->watchdog_timeo = HZ; /* Allow time enough for speed change */ dev->open = irport_net_open; dev->stop = irport_net_close; dev->get_stats = irport_net_get_stats; dev->do_ioctl = irport_net_ioctl; /* Make ifconfig display some details */ dev->base_addr = iobase; dev->irq = irq; if (register_netdev(dev)) { IRDA_ERROR("%s(), register_netdev() failed!\n", __FUNCTION__); goto err_out5; } IRDA_MESSAGE("IrDA: Registered device %s (irport io=0x%X irq=%d)\n", dev->name, iobase, irq); return self; err_out5: kfree(self->tx_buff.head); err_out4: kfree_skb(self->rx_buff.skb); err_out3: free_netdev(dev); dev_self[i] = NULL; err_out2: release_region(iobase, IO_EXTENT); err_out1: return NULL; }
static int w83977af_open(int i, unsigned int iobase, unsigned int irq, unsigned int dma) { struct net_device *dev; struct w83977af_ir *self; int err; IRDA_DEBUG(0, "%s()\n", __func__ ); if (!request_region(iobase, CHIP_IO_EXTENT, driver_name)) { IRDA_DEBUG(0, "%s(), can't get iobase of 0x%03x\n", __func__ , iobase); return -ENODEV; } if (w83977af_probe(iobase, irq, dma) == -1) { err = -1; goto err_out; } dev = alloc_irdadev(sizeof(struct w83977af_ir)); if (dev == NULL) { printk( KERN_ERR "IrDA: Can't allocate memory for " "IrDA control block!\n"); err = -ENOMEM; goto err_out; } self = netdev_priv(dev); spin_lock_init(&self->lock); self->io.fir_base = iobase; self->io.irq = irq; self->io.fir_ext = CHIP_IO_EXTENT; self->io.dma = dma; self->io.fifo_size = 32; irda_init_max_qos_capabilies(&self->qos); self->qos.baud_rate.bits = IR_9600|IR_19200|IR_38400|IR_57600| IR_115200|IR_576000|IR_1152000|(IR_4000000 << 8); self->qos.min_turn_time.bits = qos_mtt_bits; irda_qos_bits_to_value(&self->qos); self->rx_buff.truesize = 14384; self->tx_buff.truesize = 4000; self->rx_buff.head = dma_alloc_coherent(NULL, self->rx_buff.truesize, &self->rx_buff_dma, GFP_KERNEL); if (self->rx_buff.head == NULL) { err = -ENOMEM; goto err_out1; } memset(self->rx_buff.head, 0, self->rx_buff.truesize); self->tx_buff.head = dma_alloc_coherent(NULL, self->tx_buff.truesize, &self->tx_buff_dma, GFP_KERNEL); if (self->tx_buff.head == NULL) { err = -ENOMEM; goto err_out2; } memset(self->tx_buff.head, 0, self->tx_buff.truesize); self->rx_buff.in_frame = FALSE; self->rx_buff.state = OUTSIDE_FRAME; self->tx_buff.data = self->tx_buff.head; self->rx_buff.data = self->rx_buff.head; self->netdev = dev; dev->netdev_ops = &w83977_netdev_ops; err = register_netdev(dev); if (err) { IRDA_ERROR("%s(), register_netdevice() failed!\n", __func__); goto err_out3; } IRDA_MESSAGE("IrDA: Registered device %s\n", dev->name); dev_self[i] = self; return 0; err_out3: dma_free_coherent(NULL, self->tx_buff.truesize, self->tx_buff.head, self->tx_buff_dma); err_out2: dma_free_coherent(NULL, self->rx_buff.truesize, self->rx_buff.head, self->rx_buff_dma); err_out1: free_netdev(dev); err_out: release_region(iobase, CHIP_IO_EXTENT); return err; }
static int girbil_change_speed(struct sir_dev *dev, unsigned speed) { unsigned state = dev->fsm.substate; unsigned delay = 0; u8 control[2]; static int ret = 0; IRDA_DEBUG(2, "%s()\n", __func__); switch(state) { case SIRDEV_STATE_DONGLE_SPEED: sirdev_set_dtr_rts(dev, FALSE, TRUE); udelay(25); ret = 0; switch (speed) { default: ret = -EINVAL; case 9600: control[0] = GIRBIL_9600; break; case 19200: control[0] = GIRBIL_19200; break; case 34800: control[0] = GIRBIL_38400; break; case 57600: control[0] = GIRBIL_57600; break; case 115200: control[0] = GIRBIL_115200; break; } control[1] = GIRBIL_LOAD; sirdev_raw_write(dev, control, 2); dev->speed = speed; state = GIRBIL_STATE_WAIT_SPEED; delay = 100; break; case GIRBIL_STATE_WAIT_SPEED: sirdev_set_dtr_rts(dev, TRUE, TRUE); udelay(25); break; default: IRDA_ERROR("%s - undefined state %d\n", __func__, state); ret = -EINVAL; break; } dev->fsm.substate = state; return (delay > 0) ? delay : ret; }
static int __init nsc_ircc_open(chipio_t *info) { struct net_device *dev; struct nsc_ircc_cb *self; void *ret; int err, chip_index; IRDA_DEBUG(2, "%s()\n", __func__); for (chip_index = 0; chip_index < ARRAY_SIZE(dev_self); chip_index++) { if (!dev_self[chip_index]) break; } if (chip_index == ARRAY_SIZE(dev_self)) { IRDA_ERROR("%s(), maximum number of supported chips reached!\n", __func__); return -ENOMEM; } IRDA_MESSAGE("%s, Found chip at base=0x%03x\n", driver_name, info->cfg_base); if ((nsc_ircc_setup(info)) == -1) return -1; IRDA_MESSAGE("%s, driver loaded (Dag Brattli)\n", driver_name); dev = alloc_irdadev(sizeof(struct nsc_ircc_cb)); if (dev == NULL) { IRDA_ERROR("%s(), can't allocate memory for " "control block!\n", __func__); return -ENOMEM; } self = netdev_priv(dev); self->netdev = dev; spin_lock_init(&self->lock); dev_self[chip_index] = self; self->index = chip_index; self->io.cfg_base = info->cfg_base; self->io.fir_base = info->fir_base; self->io.irq = info->irq; self->io.fir_ext = CHIP_IO_EXTENT; self->io.dma = info->dma; self->io.fifo_size = 32; ret = request_region(self->io.fir_base, self->io.fir_ext, driver_name); if (!ret) { IRDA_WARNING("%s(), can't get iobase of 0x%03x\n", __func__, self->io.fir_base); err = -ENODEV; goto out1; } irda_init_max_qos_capabilies(&self->qos); self->qos.baud_rate.bits = IR_9600|IR_19200|IR_38400|IR_57600| IR_115200|IR_576000|IR_1152000 |(IR_4000000 << 8); self->qos.min_turn_time.bits = qos_mtt_bits; irda_qos_bits_to_value(&self->qos); self->rx_buff.truesize = 14384; self->tx_buff.truesize = 14384; self->rx_buff.head = dma_alloc_coherent(NULL, self->rx_buff.truesize, &self->rx_buff_dma, GFP_KERNEL); if (self->rx_buff.head == NULL) { err = -ENOMEM; goto out2; } memset(self->rx_buff.head, 0, self->rx_buff.truesize); self->tx_buff.head = dma_alloc_coherent(NULL, self->tx_buff.truesize, &self->tx_buff_dma, GFP_KERNEL); if (self->tx_buff.head == NULL) { err = -ENOMEM; goto out3; } memset(self->tx_buff.head, 0, self->tx_buff.truesize); self->rx_buff.in_frame = FALSE; self->rx_buff.state = OUTSIDE_FRAME; self->tx_buff.data = self->tx_buff.head; self->rx_buff.data = self->rx_buff.head; self->tx_fifo.len = self->tx_fifo.ptr = self->tx_fifo.free = 0; self->tx_fifo.tail = self->tx_buff.head; dev->netdev_ops = &nsc_ircc_sir_ops; err = register_netdev(dev); if (err) { IRDA_ERROR("%s(), register_netdev() failed!\n", __func__); goto out4; } IRDA_MESSAGE("IrDA: Registered device %s\n", dev->name); if ((dongle_id <= 0) || (dongle_id >= ARRAY_SIZE(dongle_types))) { dongle_id = nsc_ircc_read_dongle_id(self->io.fir_base); IRDA_MESSAGE("%s, Found dongle: %s\n", driver_name, dongle_types[dongle_id]); } else { IRDA_MESSAGE("%s, Using dongle: %s\n", driver_name, dongle_types[dongle_id]); } self->io.dongle_id = dongle_id; nsc_ircc_init_dongle_interface(self->io.fir_base, dongle_id); self->pldev = platform_device_register_simple(NSC_IRCC_DRIVER_NAME, self->index, NULL, 0); if (IS_ERR(self->pldev)) { err = PTR_ERR(self->pldev); goto out5; } platform_set_drvdata(self->pldev, self); return chip_index; out5: unregister_netdev(dev); out4: dma_free_coherent(NULL, self->tx_buff.truesize, self->tx_buff.head, self->tx_buff_dma); out3: dma_free_coherent(NULL, self->rx_buff.truesize, self->rx_buff.head, self->rx_buff_dma); out2: release_region(self->io.fir_base, self->io.fir_ext); out1: free_netdev(dev); dev_self[chip_index] = NULL; return err; }
static int __init nsc_ircc_init(void) { chipio_t info; nsc_chip_t *chip; int ret; int cfg_base; int cfg, id; int reg; int i = 0; ret = platform_driver_register(&nsc_ircc_driver); if (ret) { IRDA_ERROR("%s, Can't register driver!\n", driver_name); return ret; } ret = pnp_register_driver(&nsc_ircc_pnp_driver); if (!ret) pnp_registered = 1; ret = -ENODEV; for (chip = chips; chip->name ; chip++) { IRDA_DEBUG(2, "%s(), Probing for %s ...\n", __func__, chip->name); for (cfg = 0; cfg < ARRAY_SIZE(chip->cfg); cfg++) { cfg_base = chip->cfg[cfg]; if (!cfg_base) continue; reg = inb(cfg_base); if (reg == 0xff) { IRDA_DEBUG(2, "%s() no chip at 0x%03x\n", __func__, cfg_base); continue; } outb(chip->cid_index, cfg_base); id = inb(cfg_base+1); if ((id & chip->cid_mask) == chip->cid_value) { IRDA_DEBUG(2, "%s() Found %s chip, revision=%d\n", __func__, chip->name, id & ~chip->cid_mask); if (pnp_succeeded) { memset(&info, 0, sizeof(chipio_t)); info.cfg_base = cfg_base; info.fir_base = pnp_info.fir_base; info.dma = pnp_info.dma; info.irq = pnp_info.irq; if (info.fir_base < 0x2000) { IRDA_MESSAGE("%s, chip->init\n", driver_name); chip->init(chip, &info); } else chip->probe(chip, &info); if (nsc_ircc_open(&info) >= 0) ret = 0; } if (ret) { IRDA_DEBUG(2, "%s, PnP init failed\n", driver_name); memset(&info, 0, sizeof(chipio_t)); info.cfg_base = cfg_base; info.fir_base = io[i]; info.dma = dma[i]; info.irq = irq[i]; if (io[i] < 0x2000) { chip->init(chip, &info); } else chip->probe(chip, &info); if (nsc_ircc_open(&info) >= 0) ret = 0; } i++; } else { IRDA_DEBUG(2, "%s(), Wrong chip id=0x%02x\n", __func__, id); } } } if (ret) { platform_driver_unregister(&nsc_ircc_driver); pnp_unregister_driver(&nsc_ircc_pnp_driver); pnp_registered = 0; } return ret; }
static int tekram_change_speed(struct sir_dev *dev, unsigned speed) { unsigned state = dev->fsm.substate; unsigned delay = 0; u8 byte; static int ret = 0; IRDA_DEBUG(2, "%s()\n", __func__); switch(state) { case SIRDEV_STATE_DONGLE_SPEED: switch (speed) { default: speed = 9600; ret = -EINVAL; /* fall thru */ case 9600: byte = TEKRAM_PW|TEKRAM_9600; break; case 19200: byte = TEKRAM_PW|TEKRAM_19200; break; case 38400: byte = TEKRAM_PW|TEKRAM_38400; break; case 57600: byte = TEKRAM_PW|TEKRAM_57600; break; case 115200: byte = TEKRAM_115200; break; } /* Set DTR, Clear RTS */ sirdev_set_dtr_rts(dev, TRUE, FALSE); /* Wait at least 7us */ udelay(14); /* Write control byte */ sirdev_raw_write(dev, &byte, 1); dev->speed = speed; state = TEKRAM_STATE_WAIT_SPEED; delay = tekram_delay; break; case TEKRAM_STATE_WAIT_SPEED: /* Set DTR, Set RTS */ sirdev_set_dtr_rts(dev, TRUE, TRUE); udelay(50); break; default: IRDA_ERROR("%s - undefined state %d\n", __func__, state); ret = -EINVAL; break; } dev->fsm.substate = state; return (delay > 0) ? delay : ret; }
void sirdev_write_complete(struct sir_dev *dev) { unsigned long flags; struct sk_buff *skb; int actual = 0; int err; spin_lock_irqsave(&dev->tx_lock, flags); IRDA_DEBUG(3, "%s() - dev->tx_buff.len = %d\n", __func__, dev->tx_buff.len); if (likely(dev->tx_buff.len > 0)) { /* Write data left in transmit buffer */ actual = dev->drv->do_write(dev, dev->tx_buff.data, dev->tx_buff.len); if (likely(actual>0)) { dev->tx_buff.data += actual; dev->tx_buff.len -= actual; } else if (unlikely(actual<0)) { /* could be dropped later when we have tx_timeout to recover */ IRDA_ERROR("%s: drv->do_write failed (%d)\n", __func__, actual); if ((skb=dev->tx_skb) != NULL) { dev->tx_skb = NULL; dev_kfree_skb_any(skb); dev->netdev->stats.tx_errors++; dev->netdev->stats.tx_dropped++; } dev->tx_buff.len = 0; } if (dev->tx_buff.len > 0) goto done; /* more data to send later */ } if (unlikely(dev->raw_tx != 0)) { /* in raw mode we are just done now after the buffer was sent * completely. Since this was requested by some dongle driver * running under the control of the irda-thread we must take * care here not to re-enable the queue. The queue will be * restarted when the irda-thread has completed the request. */ IRDA_DEBUG(3, "%s(), raw-tx done\n", __func__); dev->raw_tx = 0; goto done; /* no post-frame handling in raw mode */ } /* we have finished now sending this skb. * update statistics and free the skb. * finally we check and trigger a pending speed change, if any. * if not we switch to rx mode and wake the queue for further * packets. * note the scheduled speed request blocks until the lower * client driver and the corresponding hardware has really * finished sending all data (xmit fifo drained f.e.) * before the speed change gets finally done and the queue * re-activated. */ IRDA_DEBUG(5, "%s(), finished with frame!\n", __func__); if ((skb=dev->tx_skb) != NULL) { dev->tx_skb = NULL; dev->netdev->stats.tx_packets++; dev->netdev->stats.tx_bytes += skb->len; dev_kfree_skb_any(skb); } if (unlikely(dev->new_speed > 0)) { IRDA_DEBUG(5, "%s(), Changing speed!\n", __func__); err = sirdev_schedule_speed(dev, dev->new_speed); if (unlikely(err)) { /* should never happen * forget the speed change and hope the stack recovers */ IRDA_ERROR("%s - schedule speed change failed: %d\n", __func__, err); netif_wake_queue(dev->netdev); } /* else: success * speed change in progress now * on completion dev->new_speed gets cleared, * rx-reenabled and the queue restarted */ } else { sirdev_enable_rx(dev); netif_wake_queue(dev->netdev); } done: spin_unlock_irqrestore(&dev->tx_lock, flags); }
/* * Function w83977af_open (iobase, irq) * * Open driver instance * */ static int w83977af_open(int i, unsigned int iobase, unsigned int irq, unsigned int dma) { struct net_device *dev; struct w83977af_ir *self; int err; IRDA_DEBUG(0, "%s()\n", __func__ ); /* Lock the port that we need */ if (!request_region(iobase, CHIP_IO_EXTENT, driver_name)) { IRDA_DEBUG(0, "%s(), can't get iobase of 0x%03x\n", __func__ , iobase); return -ENODEV; } if (w83977af_probe(iobase, irq, dma) == -1) { err = -1; goto err_out; } /* * Allocate new instance of the driver */ dev = alloc_irdadev(sizeof(struct w83977af_ir)); if (dev == NULL) { printk( KERN_ERR "IrDA: Can't allocate memory for " "IrDA control block!\n"); err = -ENOMEM; goto err_out; } self = netdev_priv(dev); spin_lock_init(&self->lock); /* Initialize IO */ self->io.fir_base = iobase; self->io.irq = irq; self->io.fir_ext = CHIP_IO_EXTENT; self->io.dma = dma; self->io.fifo_size = 32; /* Initialize QoS for this device */ irda_init_max_qos_capabilies(&self->qos); /* The only value we must override it the baudrate */ /* FIXME: The HP HDLS-1100 does not support 1152000! */ self->qos.baud_rate.bits = IR_9600|IR_19200|IR_38400|IR_57600| IR_115200|IR_576000|IR_1152000|(IR_4000000 << 8); /* The HP HDLS-1100 needs 1 ms according to the specs */ self->qos.min_turn_time.bits = qos_mtt_bits; irda_qos_bits_to_value(&self->qos); /* Max DMA buffer size needed = (data_size + 6) * (window_size) + 6; */ self->rx_buff.truesize = 14384; self->tx_buff.truesize = 4000; /* Allocate memory if needed */ self->rx_buff.head = dma_alloc_coherent(NULL, self->rx_buff.truesize, &self->rx_buff_dma, GFP_KERNEL); if (self->rx_buff.head == NULL) { err = -ENOMEM; goto err_out1; } memset(self->rx_buff.head, 0, self->rx_buff.truesize); self->tx_buff.head = dma_alloc_coherent(NULL, self->tx_buff.truesize, &self->tx_buff_dma, GFP_KERNEL); if (self->tx_buff.head == NULL) { err = -ENOMEM; goto err_out2; } memset(self->tx_buff.head, 0, self->tx_buff.truesize); self->rx_buff.in_frame = FALSE; self->rx_buff.state = OUTSIDE_FRAME; self->tx_buff.data = self->tx_buff.head; self->rx_buff.data = self->rx_buff.head; self->netdev = dev; dev->netdev_ops = &w83977_netdev_ops; err = register_netdev(dev); if (err) { IRDA_ERROR("%s(), register_netdevice() failed!\n", __func__); goto err_out3; } IRDA_MESSAGE("IrDA: Registered device %s\n", dev->name); /* Need to store self somewhere */ dev_self[i] = self; return 0; err_out3: dma_free_coherent(NULL, self->tx_buff.truesize, self->tx_buff.head, self->tx_buff_dma); err_out2: dma_free_coherent(NULL, self->rx_buff.truesize, self->rx_buff.head, self->rx_buff_dma); err_out1: free_netdev(dev); err_out: release_region(iobase, CHIP_IO_EXTENT); return err; }
static int girbil_change_speed(struct sir_dev *dev, unsigned speed) { unsigned state = dev->fsm.substate; unsigned delay = 0; u8 control[2]; static int ret = 0; IRDA_DEBUG(2, "%s()\n", __FUNCTION__); /* dongle alread reset - port and dongle at default speed */ switch(state) { case SIRDEV_STATE_DONGLE_SPEED: /* Set DTR and Clear RTS to enter command mode */ sirdev_set_dtr_rts(dev, FALSE, TRUE); udelay(25); /* better wait a little while */ ret = 0; switch (speed) { default: ret = -EINVAL; /* fall through */ case 9600: control[0] = GIRBIL_9600; break; case 19200: control[0] = GIRBIL_19200; break; case 34800: control[0] = GIRBIL_38400; break; case 57600: control[0] = GIRBIL_57600; break; case 115200: control[0] = GIRBIL_115200; break; } control[1] = GIRBIL_LOAD; /* Write control bytes */ sirdev_raw_write(dev, control, 2); dev->speed = speed; state = GIRBIL_STATE_WAIT_SPEED; delay = 100; break; case GIRBIL_STATE_WAIT_SPEED: /* Go back to normal mode */ sirdev_set_dtr_rts(dev, TRUE, TRUE); udelay(25); /* better wait a little while */ break; default: IRDA_ERROR("%s - undefined state %d\n", __FUNCTION__, state); ret = -EINVAL; break; } dev->fsm.substate = state; return (delay > 0) ? delay : ret; }