patch-2.2.15 linux/drivers/net/irda/tekram.c
Next file: linux/drivers/net/irda/toshoboe.c
Previous file: linux/drivers/net/irda/smc-ircc.c
Back to the patch index
Back to the overall index
- Lines: 306
- Date:
Fri Apr 21 12:46:17 2000
- Orig file:
v2.2.14/drivers/net/irda/tekram.c
- Orig date:
Sat Aug 14 02:26:48 1999
diff -u --new-file --recursive --exclude-from ../../exclude v2.2.14/drivers/net/irda/tekram.c linux/drivers/net/irda/tekram.c
@@ -6,7 +6,7 @@
* Status: Experimental.
* Author: Dag Brattli <dagb@cs.uit.no>
* Created at: Wed Oct 21 20:02:35 1998
- * Modified at: Sun May 16 14:33:42 1999
+ * Modified at: Fri Dec 17 09:13:09 1999
* Modified by: Dag Brattli <dagb@cs.uit.no>
*
* Copyright (c) 1998-1999 Dag Brattli, All Rights Reserved.
@@ -29,15 +29,14 @@
#include <linux/init.h>
#include <net/irda/irda.h>
+#include <net/irda/irmod.h>
#include <net/irda/irda_device.h>
#include <net/irda/irtty.h>
-#include <net/irda/dongle.h>
-static void tekram_reset(struct irda_device *dev);
-static void tekram_open(struct irda_device *dev, int type);
-static void tekram_close(struct irda_device *dev);
-static void tekram_change_speed(struct irda_device *dev, int baud);
-static void tekram_init_qos(struct irda_device *idev, struct qos_info *qos);
+static void tekram_open(dongle_t *self, struct qos_info *qos);
+static void tekram_close(dongle_t *self);
+static int tekram_change_speed(struct irda_task *task);
+static int tekram_reset(struct irda_task *task);
#define TEKRAM_115200 0x00
#define TEKRAM_57600 0x01
@@ -47,16 +46,16 @@
#define TEKRAM_PW 0x10 /* Pulse select bit */
-static struct dongle dongle = {
- TEKRAM_DONGLE,
+static struct dongle_reg dongle = {
+ Q_NULL,
+ IRDA_TEKRAM_DONGLE,
tekram_open,
tekram_close,
tekram_reset,
tekram_change_speed,
- tekram_init_qos,
};
-__initfunc(int tekram_init(void))
+int __init tekram_init(void)
{
return irda_device_register_dongle(&dongle);
}
@@ -66,26 +65,34 @@
irda_device_unregister_dongle(&dongle);
}
-static void tekram_open(struct irda_device *idev, int type)
+static void tekram_open(dongle_t *self, struct qos_info *qos)
{
- strcat(idev->description, " <-> tekram");
+ IRDA_DEBUG(2, __FUNCTION__ "()\n");
+
+ qos->baud_rate.bits &= IR_9600|IR_19200|IR_38400|IR_57600|IR_115200;
+ qos->min_turn_time.bits = 0x01; /* Needs at least 10 ms */
+ irda_qos_bits_to_value(qos);
- idev->io.dongle_id = type;
- idev->flags |= IFF_DONGLE;
-
MOD_INC_USE_COUNT;
}
-static void tekram_close(struct irda_device *idev)
-{
+static void tekram_close(dongle_t *self)
+{
+ IRDA_DEBUG(2, __FUNCTION__ "()\n");
+
/* Power off dongle */
- irda_device_set_dtr_rts(idev, FALSE, FALSE);
+ self->set_dtr_rts(self->dev, FALSE, FALSE);
+
+ if (self->reset_task)
+ irda_task_delete(self->reset_task);
+ if (self->speed_task)
+ irda_task_delete(self->speed_task);
MOD_DEC_USE_COUNT;
}
/*
- * Function tekram_change_speed (tty, baud)
+ * Function tekram_change_speed (dev, state, speed)
*
* Set the speed for the Tekram IRMate 210 type dongle. Warning, this
* function must be called with a process context!
@@ -100,16 +107,24 @@
* 6. wait at least 50 us, new setting (baud rate, etc) takes effect here
* after
*/
-static void tekram_change_speed(struct irda_device *idev, int baud)
+static int tekram_change_speed(struct irda_task *task)
{
+ dongle_t *self = (dongle_t *) task->instance;
+ __u32 speed = (__u32) task->param;
__u8 byte;
+ int ret = 0;
- DEBUG(4, __FUNCTION__ "()\n");
+ IRDA_DEBUG(2, __FUNCTION__ "()\n");
+
+ ASSERT(task != NULL, return -1;);
- ASSERT(idev != NULL, return;);
- ASSERT(idev->magic == IRDA_DEVICE_MAGIC, return;);
+ if (self->speed_task && self->speed_task != task) {
+ IRDA_DEBUG(0, __FUNCTION__ "(), busy!\n");
+ return MSECS_TO_JIFFIES(10);
+ } else
+ self->speed_task = task;
- switch (baud) {
+ switch (speed) {
default:
case 9600:
byte = TEKRAM_PW|TEKRAM_9600;
@@ -124,28 +139,62 @@
byte = TEKRAM_PW|TEKRAM_57600;
break;
case 115200:
- byte = TEKRAM_PW|TEKRAM_115200;
+ byte = TEKRAM_115200;
break;
}
- /* Need to reset the dongle and go to 9600 bps before programming */
- tekram_reset(idev);
-
- /* Set DTR, Clear RTS */
- irda_device_set_dtr_rts(idev, TRUE, FALSE);
+ switch (task->state) {
+ case IRDA_TASK_INIT:
+ case IRDA_TASK_CHILD_INIT:
+ /*
+ * Need to reset the dongle and go to 9600 bps before
+ * programming
+ */
+ if (irda_task_execute(self, tekram_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);
+ } else
+ irda_task_next_state(task, IRDA_TASK_CHILD_DONE);
+ break;
+ case IRDA_TASK_CHILD_WAIT:
+ WARNING(__FUNCTION__ "(), resetting dongle timed out!\n");
+ ret = -1;
+ break;
+ case IRDA_TASK_CHILD_DONE:
+ /* Set DTR, Clear RTS */
+ self->set_dtr_rts(self->dev, TRUE, FALSE);
- /* Wait at least 7us */
- udelay(7);
+ /* Wait at least 7us */
+ udelay(14);
- /* Write control byte */
- irda_device_raw_write(idev, &byte, 1);
-
- /* Wait at least 100 ms */
- current->state = TASK_INTERRUPTIBLE;
- schedule_timeout(MSECS_TO_JIFFIES(100));
-
- /* Set DTR, Set RTS */
- irda_device_set_dtr_rts(idev, TRUE, TRUE);
+ /* Write control byte */
+ self->write(self->dev, &byte, 1);
+
+ irda_task_next_state(task, IRDA_TASK_WAIT);
+
+ /* Wait at least 100 ms */
+ ret = MSECS_TO_JIFFIES(150);
+ break;
+ case IRDA_TASK_WAIT:
+ /* Set DTR, Set RTS */
+ 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;
}
/*
@@ -161,50 +210,61 @@
* 3. clear DTR to SPACE state, wait at least 50 us for further
* operation
*/
-void tekram_reset(struct irda_device *idev)
+int tekram_reset(struct irda_task *task)
{
- ASSERT(idev != NULL, return;);
- ASSERT(idev->magic == IRDA_DEVICE_MAGIC, return;);
+ dongle_t *self = (dongle_t *) task->instance;
+ int ret = 0;
+
+ IRDA_DEBUG(2, __FUNCTION__ "()\n");
+
+ ASSERT(task != NULL, return -1;);
+
+ if (self->reset_task && self->reset_task != task) {
+ IRDA_DEBUG(0, __FUNCTION__ "(), busy!\n");
+ return MSECS_TO_JIFFIES(10);
+ } else
+ self->reset_task = task;
/* Power off dongle */
- irda_device_set_dtr_rts(idev, FALSE, FALSE);
-
- /* Sleep 50 ms */
- current->state = TASK_INTERRUPTIBLE;
- schedule_timeout(MSECS_TO_JIFFIES(50));
+ //self->set_dtr_rts(self->dev, FALSE, FALSE);
+ self->set_dtr_rts(self->dev, TRUE, TRUE);
- /* Clear DTR, Set RTS */
- irda_device_set_dtr_rts(idev, FALSE, TRUE);
+ switch (task->state) {
+ case IRDA_TASK_INIT:
+ irda_task_next_state(task, IRDA_TASK_WAIT1);
- /* Should sleep 1 ms, but 10-20 should not do any harm */
- current->state = TASK_INTERRUPTIBLE;
- schedule_timeout(MSECS_TO_JIFFIES(20));
+ /* Sleep 50 ms */
+ ret = MSECS_TO_JIFFIES(50);
+ break;
+ case IRDA_TASK_WAIT1:
+ /* Clear DTR, Set RTS */
+ self->set_dtr_rts(self->dev, FALSE, TRUE);
- /* Set DTR, Set RTS */
- irda_device_set_dtr_rts(idev, TRUE, TRUE);
-
- udelay(50);
+ irda_task_next_state(task, IRDA_TASK_WAIT2);
+
+ /* Should sleep 1 ms */
+ ret = MSECS_TO_JIFFIES(1);
+ break;
+ case IRDA_TASK_WAIT2:
+ /* Set DTR, Set RTS */
+ self->set_dtr_rts(self->dev, TRUE, TRUE);
- /* Make sure the IrDA chip also goes to defalt speed */
- if (idev->change_speed)
- idev->change_speed(idev, 9600);
-}
+ /* Wait at least 50 us */
+ udelay(75);
-/*
- * Function tekram_init_qos (qos)
- *
- * Initialize QoS capabilities
- *
- */
-static void tekram_init_qos(struct irda_device *idev, struct qos_info *qos)
-{
- qos->baud_rate.bits &= IR_9600|IR_19200|IR_38400|IR_57600|IR_115200;
- qos->min_turn_time.bits &= 0x01; /* Needs at least 10 ms */
- irda_qos_bits_to_value(qos);
+ 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;
+ }
+ return ret;
}
#ifdef MODULE
-
MODULE_AUTHOR("Dag Brattli <dagb@cs.uit.no>");
MODULE_DESCRIPTION("Tekram IrMate IR-210B dongle driver");
@@ -229,5 +289,4 @@
{
tekram_cleanup();
}
-
#endif /* MODULE */
FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)