1 /*********************************************************************
 
   5  * Description:   Implementation of the Tekram IrMate IR-210B dongle
 
   6  * Status:        Experimental.
 
   7  * Author:        Dag Brattli <dagb@cs.uit.no>
 
   8  * Created at:    Wed Oct 21 20:02:35 1998
 
   9  * Modified at:   Sun Oct 27 22:02:38 2002
 
  10  * Modified by:   Martin Diehl <mad@mdiehl.de>
 
  12  *     Copyright (c) 1998-1999 Dag Brattli,
 
  13  *     Copyright (c) 2002 Martin Diehl,
 
  14  *     All Rights Reserved.
 
  16  *     This program is free software; you can redistribute it and/or 
 
  17  *     modify it under the terms of the GNU General Public License as 
 
  18  *     published by the Free Software Foundation; either version 2 of 
 
  19  *     the License, or (at your option) any later version.
 
  21  *     Neither Dag Brattli nor University of Tromsø admit liability nor
 
  22  *     provide warranty for any of this software. This material is 
 
  23  *     provided "AS-IS" and at no charge.
 
  25  ********************************************************************/
 
  27 #include <linux/module.h>
 
  28 #include <linux/delay.h>
 
  29 #include <linux/init.h>
 
  31 #include <net/irda/irda.h>
 
  35 static int tekram_delay = 150;          /* default is 150 ms */
 
  36 module_param(tekram_delay, int, 0);
 
  37 MODULE_PARM_DESC(tekram_delay, "tekram dongle write complete delay");
 
  39 static int tekram_open(struct sir_dev *);
 
  40 static int tekram_close(struct sir_dev *);
 
  41 static int tekram_change_speed(struct sir_dev *, unsigned);
 
  42 static int tekram_reset(struct sir_dev *);
 
  44 #define TEKRAM_115200 0x00
 
  45 #define TEKRAM_57600  0x01
 
  46 #define TEKRAM_38400  0x02
 
  47 #define TEKRAM_19200  0x03
 
  48 #define TEKRAM_9600   0x04
 
  50 #define TEKRAM_PW     0x10 /* Pulse select bit */
 
  52 static struct dongle_driver tekram = {
 
  54         .driver_name    = "Tekram IR-210B",
 
  55         .type           = IRDA_TEKRAM_DONGLE,
 
  57         .close          = tekram_close,
 
  58         .reset          = tekram_reset,
 
  59         .set_speed      = tekram_change_speed,
 
  62 static int __init tekram_sir_init(void)
 
  64         if (tekram_delay < 1  ||  tekram_delay > 500)
 
  66         IRDA_DEBUG(1, "%s - using %d ms delay\n",
 
  67                 tekram.driver_name, tekram_delay);
 
  68         return irda_register_dongle(&tekram);
 
  71 static void __exit tekram_sir_cleanup(void)
 
  73         irda_unregister_dongle(&tekram);
 
  76 static int tekram_open(struct sir_dev *dev)
 
  78         struct qos_info *qos = &dev->qos;
 
  80         IRDA_DEBUG(2, "%s()\n", __FUNCTION__);
 
  82         sirdev_set_dtr_rts(dev, TRUE, TRUE);
 
  84         qos->baud_rate.bits &= IR_9600|IR_19200|IR_38400|IR_57600|IR_115200;
 
  85         qos->min_turn_time.bits = 0x01; /* Needs at least 10 ms */      
 
  86         irda_qos_bits_to_value(qos);
 
  88         /* irda thread waits 50 msec for power settling */
 
  93 static int tekram_close(struct sir_dev *dev)
 
  95         IRDA_DEBUG(2, "%s()\n", __FUNCTION__);
 
  97         /* Power off dongle */
 
  98         sirdev_set_dtr_rts(dev, FALSE, FALSE);
 
 104  * Function tekram_change_speed (dev, state, speed)
 
 106  *    Set the speed for the Tekram IRMate 210 type dongle. Warning, this 
 
 107  *    function must be called with a process context!
 
 111  *    2. set RTS, and wait at least 7 us
 
 112  *    3. send Control Byte to the IR-210 through TXD to set new baud rate
 
 113  *       wait until the stop bit of Control Byte is sent (for 9600 baud rate, 
 
 114  *       it takes about 100 msec)
 
 116  *      [oops, why 100 msec? sending 1 byte (10 bits) takes 1.05 msec
 
 117  *       - is this probably to compensate for delays in tty layer?]
 
 119  *    5. clear RTS (return to NORMAL Operation)
 
 120  *    6. wait at least 50 us, new setting (baud rate, etc) takes effect here 
 
 124 #define TEKRAM_STATE_WAIT_SPEED (SIRDEV_STATE_DONGLE_SPEED + 1)
 
 126 static int tekram_change_speed(struct sir_dev *dev, unsigned speed)
 
 128         unsigned state = dev->fsm.substate;
 
 133         IRDA_DEBUG(2, "%s()\n", __FUNCTION__);
 
 136         case SIRDEV_STATE_DONGLE_SPEED:
 
 144                         byte = TEKRAM_PW|TEKRAM_9600;
 
 147                         byte = TEKRAM_PW|TEKRAM_19200;
 
 150                         byte = TEKRAM_PW|TEKRAM_38400;
 
 153                         byte = TEKRAM_PW|TEKRAM_57600;
 
 156                         byte = TEKRAM_115200;
 
 160                 /* Set DTR, Clear RTS */
 
 161                 sirdev_set_dtr_rts(dev, TRUE, FALSE);
 
 163                 /* Wait at least 7us */
 
 166                 /* Write control byte */
 
 167                 sirdev_raw_write(dev, &byte, 1);
 
 171                 state = TEKRAM_STATE_WAIT_SPEED;
 
 172                 delay = tekram_delay;
 
 175         case TEKRAM_STATE_WAIT_SPEED:
 
 176                 /* Set DTR, Set RTS */
 
 177                 sirdev_set_dtr_rts(dev, TRUE, TRUE);
 
 182                 IRDA_ERROR("%s - undefined state %d\n", __FUNCTION__, state);
 
 187         dev->fsm.substate = state;
 
 188         return (delay > 0) ? delay : ret;
 
 192  * Function tekram_reset (driver)
 
 194  *      This function resets the tekram dongle. Warning, this function 
 
 195  *      must be called with a process context!! 
 
 198  *        0. Clear RTS and DTR, and wait 50 ms (power off the IR-210 )
 
 200  *        2. set DTR, and wait at least 1 ms 
 
 201  *        3. clear DTR to SPACE state, wait at least 50 us for further 
 
 205 static int tekram_reset(struct sir_dev *dev)
 
 207         IRDA_DEBUG(2, "%s()\n", __FUNCTION__);
 
 209         /* Clear DTR, Set RTS */
 
 210         sirdev_set_dtr_rts(dev, FALSE, TRUE); 
 
 212         /* Should sleep 1 ms */
 
 215         /* Set DTR, Set RTS */
 
 216         sirdev_set_dtr_rts(dev, TRUE, TRUE);
 
 218         /* Wait at least 50 us */
 
 226 MODULE_AUTHOR("Dag Brattli <dagb@cs.uit.no>");
 
 227 MODULE_DESCRIPTION("Tekram IrMate IR-210B dongle driver");
 
 228 MODULE_LICENSE("GPL");
 
 229 MODULE_ALIAS("irda-dongle-0"); /* IRDA_TEKRAM_DONGLE */
 
 231 module_init(tekram_sir_init);
 
 232 module_exit(tekram_sir_cleanup);