1 /*********************************************************************
 
   5  * Description:   Implementation for the Greenwich GIrBIL dongle
 
   6  * Status:        Experimental.
 
   7  * Author:        Dag Brattli <dagb@cs.uit.no>
 
   8  * Created at:    Sat Feb  6 21:02:33 1999
 
   9  * Modified at:   Fri Dec 17 09:13:20 1999
 
  10  * Modified by:   Dag Brattli <dagb@cs.uit.no>
 
  12  *     Copyright (c) 1999 Dag Brattli, All Rights Reserved.
 
  14  *     This program is free software; you can redistribute it and/or 
 
  15  *     modify it under the terms of the GNU General Public License as 
 
  16  *     published by the Free Software Foundation; either version 2 of 
 
  17  *     the License, or (at your option) any later version.
 
  19  *     Neither Dag Brattli nor University of Tromsø admit liability nor
 
  20  *     provide warranty for any of this software. This material is 
 
  21  *     provided "AS-IS" and at no charge.
 
  23  ********************************************************************/
 
  25 #include <linux/module.h>
 
  26 #include <linux/delay.h>
 
  27 #include <linux/tty.h>
 
  28 #include <linux/init.h>
 
  30 #include <net/irda/irda.h>
 
  31 #include <net/irda/irda_device.h>
 
  33 static int  girbil_reset(struct irda_task *task);
 
  34 static void girbil_open(dongle_t *self, struct qos_info *qos);
 
  35 static void girbil_close(dongle_t *self);
 
  36 static int  girbil_change_speed(struct irda_task *task);
 
  38 /* Control register 1 */
 
  39 #define GIRBIL_TXEN    0x01 /* Enable transmitter */
 
  40 #define GIRBIL_RXEN    0x02 /* Enable receiver */
 
  41 #define GIRBIL_ECAN    0x04 /* Cancel self emmited data */
 
  42 #define GIRBIL_ECHO    0x08 /* Echo control characters */
 
  44 /* LED Current Register (0x2) */
 
  45 #define GIRBIL_HIGH    0x20
 
  46 #define GIRBIL_MEDIUM  0x21
 
  47 #define GIRBIL_LOW     0x22
 
  49 /* Baud register (0x3) */
 
  50 #define GIRBIL_2400    0x30
 
  51 #define GIRBIL_4800    0x31     
 
  52 #define GIRBIL_9600    0x32
 
  53 #define GIRBIL_19200   0x33
 
  54 #define GIRBIL_38400   0x34     
 
  55 #define GIRBIL_57600   0x35     
 
  56 #define GIRBIL_115200  0x36
 
  58 /* Mode register (0x4) */
 
  59 #define GIRBIL_IRDA    0x40
 
  60 #define GIRBIL_ASK     0x41
 
  62 /* Control register 2 (0x5) */
 
  63 #define GIRBIL_LOAD    0x51 /* Load the new baud rate value */
 
  65 static struct dongle_reg dongle = {
 
  66         .type = IRDA_GIRBIL_DONGLE,
 
  68         .close = girbil_close,
 
  69         .reset = girbil_reset,
 
  70         .change_speed = girbil_change_speed,
 
  74 static int __init girbil_init(void)
 
  76         return irda_device_register_dongle(&dongle);
 
  79 static void __exit girbil_cleanup(void)
 
  81         irda_device_unregister_dongle(&dongle);
 
  84 static void girbil_open(dongle_t *self, struct qos_info *qos)
 
  86         qos->baud_rate.bits &= IR_9600|IR_19200|IR_38400|IR_57600|IR_115200;
 
  87         qos->min_turn_time.bits = 0x03;
 
  90 static void girbil_close(dongle_t *self)
 
  92         /* Power off dongle */
 
  93         self->set_dtr_rts(self->dev, FALSE, FALSE);
 
  97  * Function girbil_change_speed (dev, speed)
 
  99  *    Set the speed for the Girbil type dongle.
 
 102 static int girbil_change_speed(struct irda_task *task)
 
 104         dongle_t *self = (dongle_t *) task->instance;
 
 105         __u32 speed = (__u32) task->param;
 
 109         self->speed_task = task;
 
 111         switch (task->state) {
 
 113                 /* Need to reset the dongle and go to 9600 bps before
 
 115                 if (irda_task_execute(self, girbil_reset, NULL, task, 
 
 118                         /* Dongle need more time to reset */
 
 119                         irda_task_next_state(task, IRDA_TASK_CHILD_WAIT);
 
 121                         /* Give reset 1 sec to finish */
 
 122                         ret = msecs_to_jiffies(1000);
 
 125         case IRDA_TASK_CHILD_WAIT:
 
 126                 IRDA_WARNING("%s(), resetting dongle timed out!\n",
 
 130         case IRDA_TASK_CHILD_DONE:
 
 131                 /* Set DTR and Clear RTS to enter command mode */
 
 132                 self->set_dtr_rts(self->dev, FALSE, TRUE);
 
 137                         control[0] = GIRBIL_9600;
 
 140                         control[0] = GIRBIL_19200;
 
 143                         control[0] = GIRBIL_38400;
 
 146                         control[0] = GIRBIL_57600;
 
 149                         control[0] = GIRBIL_115200;
 
 152                 control[1] = GIRBIL_LOAD;
 
 154                 /* Write control bytes */
 
 155                 self->write(self->dev, control, 2);
 
 156                 irda_task_next_state(task, IRDA_TASK_WAIT);
 
 157                 ret = msecs_to_jiffies(100);
 
 160                 /* Go back to normal mode */
 
 161                 self->set_dtr_rts(self->dev, TRUE, TRUE);
 
 162                 irda_task_next_state(task, IRDA_TASK_DONE);
 
 163                 self->speed_task = NULL;
 
 166                 IRDA_ERROR("%s(), unknown state %d\n",
 
 167                            __FUNCTION__, task->state);
 
 168                 irda_task_next_state(task, IRDA_TASK_DONE);
 
 169                 self->speed_task = NULL;
 
 177  * Function girbil_reset (driver)
 
 179  *      This function resets the girbil dongle.
 
 182  *        0. set RTS, and wait at least 5 ms 
 
 185 static int girbil_reset(struct irda_task *task)
 
 187         dongle_t *self = (dongle_t *) task->instance;
 
 188         __u8 control = GIRBIL_TXEN | GIRBIL_RXEN;
 
 191         self->reset_task = task;
 
 193         switch (task->state) {
 
 196                 self->set_dtr_rts(self->dev, TRUE, FALSE);
 
 197                 irda_task_next_state(task, IRDA_TASK_WAIT1);
 
 198                 /* Sleep at least 5 ms */
 
 199                 ret = msecs_to_jiffies(20);
 
 201         case IRDA_TASK_WAIT1:
 
 202                 /* Set DTR and clear RTS to enter command mode */
 
 203                 self->set_dtr_rts(self->dev, FALSE, TRUE);
 
 204                 irda_task_next_state(task, IRDA_TASK_WAIT2);
 
 205                 ret = msecs_to_jiffies(20);
 
 207         case IRDA_TASK_WAIT2:
 
 208                 /* Write control byte */
 
 209                 self->write(self->dev, &control, 1);
 
 210                 irda_task_next_state(task, IRDA_TASK_WAIT3);
 
 211                 ret = msecs_to_jiffies(20);
 
 213         case IRDA_TASK_WAIT3:
 
 214                 /* Go back to normal mode */
 
 215                 self->set_dtr_rts(self->dev, TRUE, TRUE);
 
 216                 irda_task_next_state(task, IRDA_TASK_DONE);
 
 217                 self->reset_task = NULL;
 
 220                 IRDA_ERROR("%s(), unknown state %d\n",
 
 221                            __FUNCTION__, task->state);
 
 222                 irda_task_next_state(task, IRDA_TASK_DONE);
 
 223                 self->reset_task = NULL;
 
 230 MODULE_AUTHOR("Dag Brattli <dagb@cs.uit.no>");
 
 231 MODULE_DESCRIPTION("Greenwich GIrBIL dongle driver");
 
 232 MODULE_LICENSE("GPL");
 
 233 MODULE_ALIAS("irda-dongle-4"); /* IRDA_GIRBIL_DONGLE */
 
 236  * Function init_module (void)
 
 238  *    Initialize Girbil module
 
 241 module_init(girbil_init);
 
 244  * Function cleanup_module (void)
 
 246  *    Cleanup Girbil module
 
 249 module_exit(girbil_cleanup);