/* * Function irda_usb_find_class_desc(dev, ifnum) * * Returns instance of IrDA class descriptor, or NULL if not found * * The class descriptor is some extra info that IrDA USB devices will * offer to us, describing their IrDA characteristics. We will use that in * irda_usb_init_qos() * * Based on the same function in drivers/net/irda/irda-usb.c */ static struct irda_class_desc *irda_usb_find_class_desc(struct usb_device *dev, unsigned int ifnum) { struct irda_class_desc *desc; int ret; desc = kmalloc(sizeof (struct irda_class_desc), GFP_KERNEL); if (desc == NULL) return NULL; memset(desc, 0, sizeof(struct irda_class_desc)); ret = usb_control_msg(dev, usb_rcvctrlpipe(dev,0), IU_REQ_GET_CLASS_DESC, USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE, 0, ifnum, desc, sizeof(*desc), MSECS_TO_JIFFIES(500)); dbg("%s - ret=%d", __FUNCTION__, ret); if (ret < sizeof(*desc)) { dbg("%s - class descriptor read %s (%d)", __FUNCTION__, (ret<0) ? "failed" : "too short", ret); goto error; } if (desc->bDescriptorType != USB_DT_IRDA) { dbg("%s - bad class descriptor type", __FUNCTION__); goto error; } irda_usb_dump_class_desc(desc); return desc; error: kfree(desc); return NULL; }
static int wait_for_a_slot(struct slot_args *slargs, int *buffer_index) { int ret = -1, i = 0; DECLARE_WAITQUEUE(my_wait, current); add_wait_queue_exclusive(slargs->slot_wq, &my_wait); while(1) { set_current_state(TASK_INTERRUPTIBLE); /* check for available desc */ spin_lock(slargs->slot_lock); for(i = 0; i < slargs->slot_count; i++) { if (slargs->slot_array[i] == 0) { slargs->slot_array[i] = 1; *buffer_index = i; ret = 0; break; } } spin_unlock(slargs->slot_lock); /* if we acquired a buffer, then break out of while */ if (ret == 0) { break; } if (!signal_pending(current)) { int timeout = MSECS_TO_JIFFIES(1000 * slot_timeout_secs); gossip_debug(GOSSIP_BUFMAP_DEBUG, "[BUFMAP]: waiting %d seconds for a slot\n", slot_timeout_secs); if (!schedule_timeout(timeout)) { gossip_debug(GOSSIP_BUFMAP_DEBUG, "*** wait_for_a_slot timed out\n"); ret = -ETIMEDOUT; break; } gossip_debug(GOSSIP_BUFMAP_DEBUG, "[BUFMAP]: acquired slot\n"); continue; } gossip_debug(GOSSIP_BUFMAP_DEBUG, "pvfs2: wait_for_a_slot() interrupted.\n"); ret = -EINTR; break; } set_current_state(TASK_RUNNING); remove_wait_queue(slargs->slot_wq, &my_wait); return ret; }
/* * Function girbil_reset (driver) * * This function resets the girbil dongle. * * Algorithm: * 0. set RTS, and wait at least 5 ms * 1. clear RTS */ static int girbil_reset(struct irda_task *task) { dongle_t *self = (dongle_t *) task->instance; __u8 control = GIRBIL_TXEN | GIRBIL_RXEN; int ret = 0; self->reset_task = task; switch (task->state) { case IRDA_TASK_INIT: /* Reset dongle */ self->set_dtr_rts(self->dev, TRUE, FALSE); irda_task_next_state(task, IRDA_TASK_WAIT1); /* Sleep at least 5 ms */ ret = MSECS_TO_JIFFIES(20); break; case IRDA_TASK_WAIT1: /* Set DTR and clear RTS to enter command mode */ self->set_dtr_rts(self->dev, FALSE, TRUE); irda_task_next_state(task, IRDA_TASK_WAIT2); ret = MSECS_TO_JIFFIES(20); break; case IRDA_TASK_WAIT2: /* Write control byte */ self->write(self->dev, &control, 1); irda_task_next_state(task, IRDA_TASK_WAIT3); ret = MSECS_TO_JIFFIES(20); break; case IRDA_TASK_WAIT3: /* Go back to normal mode */ self->set_dtr_rts(self->dev, TRUE, TRUE); irda_task_next_state(task, IRDA_TASK_DONE); self->reset_task = NULL; break; default: ERROR(__FUNCTION__ "(), unknown state %d\n", task->state); irda_task_next_state(task, IRDA_TASK_DONE); self->reset_task = NULL; ret = -1; break; } return ret; }
static int mcp2120_reset(struct irda_task *task) { dongle_t *self = (dongle_t *) task->instance; int ret = 0; self->reset_task = task; switch (task->state) { case IRDA_TASK_INIT: //printk("mcp2120_reset irda_task_init\n"); /* Reset dongle by setting RTS*/ self->set_dtr_rts(self->dev, TRUE, TRUE); irda_task_next_state(task, IRDA_TASK_WAIT1); ret = MSECS_TO_JIFFIES(50); break; case IRDA_TASK_WAIT1: //printk("mcp2120_reset irda_task_wait1\n"); /* clear RTS and wait for at least 30 ms. */ self->set_dtr_rts(self->dev, FALSE, FALSE); irda_task_next_state(task, IRDA_TASK_WAIT2); ret = MSECS_TO_JIFFIES(50); break; case IRDA_TASK_WAIT2: //printk("mcp2120_reset irda_task_wait2\n"); /* Go back to normal mode */ self->set_dtr_rts(self->dev, FALSE, FALSE); irda_task_next_state(task, IRDA_TASK_DONE); self->reset_task = NULL; break; default: ERROR("%s(), unknown state %d\n", __FUNCTION__, task->state); irda_task_next_state(task, IRDA_TASK_DONE); self->reset_task = NULL; ret = -1; break; } return ret; }
static int tekram_reset(struct sir_dev *dev) { IRDA_DEBUG(2, "%s()\n", __FUNCTION__); /* Clear DTR, Set RTS */ sirdev_set_dtr_rts(dev, FALSE, TRUE); /* Should sleep 1 ms */ set_current_state(TASK_UNINTERRUPTIBLE); schedule_timeout(MSECS_TO_JIFFIES(1)); /* Set DTR, Set RTS */ sirdev_set_dtr_rts(dev, TRUE, TRUE); /* Wait at least 50 us */ udelay(75); dev->speed = 9600; return 0; }
/* * Function mcp2120_change_speed (dev, speed) * * Set the speed for the MCP2120. * */ static int mcp2120_change_speed(struct irda_task *task) { dongle_t *self = (dongle_t *) task->instance; __u32 speed = (__u32) task->param; __u8 control[2]; int ret = 0; self->speed_task = task; switch (task->state) { case IRDA_TASK_INIT: /* Need to reset the dongle and go to 9600 bps before programming */ //printk("Dmcp2120_change_speed irda_task_init\n"); if (irda_task_execute(self, mcp2120_reset, NULL, task, (void *) speed)) { /* Dongle need more time to reset */ irda_task_next_state(task, IRDA_TASK_CHILD_WAIT); /* Give reset 1 sec to finish */ ret = MSECS_TO_JIFFIES(1000); } break; case IRDA_TASK_CHILD_WAIT: WARNING("%s(), resetting dongle timed out!\n", __FUNCTION__); ret = -1; break; case IRDA_TASK_CHILD_DONE: /* Set DTR to enter command mode */ self->set_dtr_rts(self->dev, TRUE, FALSE); udelay(500); switch (speed) { case 9600: default: control[0] = MCP2120_9600; //printk("mcp2120 9600\n"); break; case 19200: control[0] = MCP2120_19200; //printk("mcp2120 19200\n"); break; case 34800: control[0] = MCP2120_38400; //printk("mcp2120 38400\n"); break; case 57600: control[0] = MCP2120_57600; //printk("mcp2120 57600\n"); break; case 115200: control[0] = MCP2120_115200; //printk("mcp2120 115200\n"); break; } control[1] = MCP2120_COMMIT; /* Write control bytes */ self->write(self->dev, control, 2); irda_task_next_state(task, IRDA_TASK_WAIT); ret = MSECS_TO_JIFFIES(100); //printk("mcp2120_change_speed irda_child_done\n"); break; case IRDA_TASK_WAIT: /* Go back to normal mode */ self->set_dtr_rts(self->dev, FALSE, FALSE); irda_task_next_state(task, IRDA_TASK_DONE); self->speed_task = NULL; //printk("mcp2120_change_speed irda_task_wait\n"); break; default: ERROR("%s(), unknown state %d\n", __FUNCTION__, task->state); irda_task_next_state(task, IRDA_TASK_DONE); self->speed_task = NULL; ret = -1; break; } return ret; }
/* * Function girbil_change_speed (dev, speed) * * Set the speed for the Girbil type dongle. * */ static int girbil_change_speed(struct irda_task *task) { dongle_t *self = (dongle_t *) task->instance; __u32 speed = (__u32) task->param; __u8 control[2]; int ret = 0; self->speed_task = task; switch (task->state) { case IRDA_TASK_INIT: /* Need to reset the dongle and go to 9600 bps before programming */ if (irda_task_execute(self, girbil_reset, NULL, task, (void *) speed)) { /* Dongle need more time to reset */ irda_task_next_state(task, IRDA_TASK_CHILD_WAIT); /* Give reset 1 sec to finish */ ret = MSECS_TO_JIFFIES(1000); } break; case IRDA_TASK_CHILD_WAIT: WARNING(__FUNCTION__ "(), resetting dongle timed out!\n"); ret = -1; break; case IRDA_TASK_CHILD_DONE: /* Set DTR and Clear RTS to enter command mode */ self->set_dtr_rts(self->dev, FALSE, TRUE); switch (speed) { case 9600: default: 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 */ self->write(self->dev, control, 2); irda_task_next_state(task, IRDA_TASK_WAIT); ret = MSECS_TO_JIFFIES(100); break; case IRDA_TASK_WAIT: /* Go back to normal mode */ self->set_dtr_rts(self->dev, TRUE, TRUE); irda_task_next_state(task, IRDA_TASK_DONE); self->speed_task = NULL; break; default: ERROR(__FUNCTION__ "(), unknown state %d\n", task->state); irda_task_next_state(task, IRDA_TASK_DONE); self->speed_task = NULL; ret = -1; break; } return ret; }