Main Page | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

irda_device.h

Go to the documentation of this file.
00001 /*********************************************************************
00002  *                
00003  * Filename:      irda_device.h
00004  * Version:       0.9
00005  * Description:   Contains various declarations used by the drivers
00006  * Status:        Experimental.
00007  * Author:        Dag Brattli <dagb@cs.uit.no>
00008  * Created at:    Tue Apr 14 12:41:42 1998
00009  * Modified at:   Fri Jan 14 10:46:56 2000
00010  * Modified by:   Dag Brattli <dagb@cs.uit.no>
00011  * 
00012  *     Copyright (c) 1999-2000 Dag Brattli, All Rights Reserved.
00013  *     Copyright (c) 1998 Thomas Davis, <ratbert@radiks.net>,
00014  *
00015  *     This program is free software; you can redistribute it and/or 
00016  *     modify it under the terms of the GNU General Public License as 
00017  *     published by the Free Software Foundation; either version 2 of 
00018  *     the License, or (at your option) any later version.
00019  * 
00020  *     This program is distributed in the hope that it will be useful,
00021  *     but WITHOUT ANY WARRANTY; without even the implied warranty of
00022  *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00023  *     GNU General Public License for more details.
00024  * 
00025  *     You should have received a copy of the GNU General Public License 
00026  *     along with this program; if not, write to the Free Software 
00027  *     Foundation, Inc., 59 Temple Place, Suite 330, Boston, 
00028  *     MA 02111-1307 USA
00029  *     
00030  ********************************************************************/
00031 
00032 #ifndef IRDA_DEVICE_H
00033 #define IRDA_DEVICE_H
00034 
00035 #include <linux/tty.h>
00036 #include <linux/netdevice.h>
00037 #include <asm/spinlock.h>
00038 #include <linux/irda.h>
00039 
00040 #include <net/irda/irda.h>
00041 #include <net/irda/qos.h>
00042 #include <net/irda/irqueue.h>
00043 #include <net/irda/irlap_frame.h>
00044 
00045 /* Some non-standard interface flags (should not conflict with any in if.h) */
00046 #define IFF_SIR         0x0001 /* Supports SIR speeds */
00047 #define IFF_MIR         0x0002 /* Supports MIR speeds */
00048 #define IFF_FIR         0x0004 /* Supports FIR speeds */
00049 #define IFF_VFIR        0x0008 /* Supports VFIR speeds */
00050 #define IFF_PIO         0x0010 /* Supports PIO transfer of data */
00051 #define IFF_DMA         0x0020 /* Supports DMA transfer of data */
00052 #define IFF_SHM         0x0040 /* Supports shared memory data transfers */
00053 #define IFF_DONGLE      0x0080 /* Interface has a dongle attached */
00054 #define IFF_AIR         0x0100 /* Supports Advanced IR (AIR) standards */
00055 
00056 #define IO_XMIT 0x01
00057 #define IO_RECV 0x02
00058 
00059 typedef enum {
00060         IRDA_IRLAP, /* IrDA mode, and deliver to IrLAP */
00061         IRDA_RAW,   /* IrDA mode */
00062         SHARP_ASK,
00063         TV_REMOTE,  /* Also known as Consumer Electronics IR */
00064 } INFRARED_MODE;
00065 
00066 typedef enum {
00067         IRDA_TASK_INIT,        /* All tasks are initialized with this state */
00068         IRDA_TASK_DONE,        /* Signals that the task is finished */
00069         IRDA_TASK_WAIT,
00070         IRDA_TASK_WAIT1,
00071         IRDA_TASK_WAIT2,
00072         IRDA_TASK_WAIT3,
00073         IRDA_TASK_CHILD_INIT,  /* Initializing child task */
00074         IRDA_TASK_CHILD_WAIT,  /* Waiting for child task to finish */
00075         IRDA_TASK_CHILD_DONE   /* Child task is finished */
00076 } TASK_STATE;
00077 
00078 struct irda_task;
00079 typedef int (*TASK_CALLBACK) (struct irda_task *task);
00080 
00081 struct irda_task {
00082         queue_t q;
00083         magic_t magic;
00084 
00085         TASK_STATE state;
00086         TASK_CALLBACK function;
00087         TASK_CALLBACK finished;
00088 
00089         struct irda_task *parent;
00090         struct timer_list timer;
00091 
00092         void *instance; /* Instance being called */
00093         void *param;    /* Parameter to be used by instance */
00094 };
00095 
00096 /* Dongle info */
00097 struct dongle_reg;
00098 typedef struct {
00099         struct dongle_reg *issue;     /* Registration info */
00100         struct device *dev;           /* Device we are attached to */
00101         struct irda_task *speed_task; /* Task handling speed change */
00102         struct irda_task *reset_task; /* Task handling reset */
00103         __u32 speed;                  /* Current speed */
00104 
00105         /* Callbacks to the IrDA device driver */
00106         int (*set_mode)(struct device *, int mode);
00107         int (*read)(struct device *dev, __u8 *buf, int len);
00108         int (*write)(struct device *dev, __u8 *buf, int len);
00109         int (*set_dtr_rts)(struct device *dev, int dtr, int rts);
00110 } dongle_t;
00111 
00112 /* Dongle registration info */
00113 struct dongle_reg {
00114         queue_t q;         /* Must be first */
00115         IRDA_DONGLE type;
00116 
00117         void (*open)(dongle_t *dongle, struct qos_info *qos);
00118         void (*close)(dongle_t *dongle);
00119         int  (*reset)(struct irda_task *task);
00120         int  (*change_speed)(struct irda_task *task);
00121 };
00122 
00123 /* Chip specific info */
00124 typedef struct {
00125         int cfg_base;         /* Config register IO base */
00126         int sir_base;         /* SIR IO base */
00127         int fir_base;         /* FIR IO base */
00128         int mem_base;         /* Shared memory base */
00129         int sir_ext;          /* Length of SIR iobase */
00130         int fir_ext;          /* Length of FIR iobase */
00131         int irq, irq2;        /* Interrupts used */
00132         int dma, dma2;        /* DMA channel(s) used */
00133         int fifo_size;        /* FIFO size */
00134         int irqflags;         /* interrupt flags (ie, SA_SHIRQ|SA_INTERRUPT) */
00135         int direction;        /* Link direction, used by some FIR drivers */
00136         int enabled;          /* Powered on? */
00137         int suspended;        /* Suspended by APM */
00138         __u32 speed;          /* Currently used speed */
00139         __u32 new_speed;      /* Speed we must change to when Tx is finished */
00140         int dongle_id;        /* Dongle or transceiver currently used */
00141 } chipio_t;
00142 
00143 /* IO buffer specific info (inspired by struct sk_buff) */
00144 typedef struct {
00145         int state;            /* Receiving state (transmit state not used) */
00146         int in_frame;         /* True if receiving frame */
00147 
00148         __u8 *head;           /* start of buffer */
00149         __u8 *data;           /* start of data in buffer */
00150         __u8 *tail;           /* end of data in buffer */
00151 
00152         int len;              /* length of data */
00153         int truesize;         /* total size of buffer */
00154         __u16 fcs;
00155 } iobuff_t;
00156 
00157 /* Function prototypes */
00158 int  irda_device_init(void);
00159 void irda_device_cleanup(void);
00160 
00161 /* Interface to be uses by IrLAP */
00162 void irda_device_set_media_busy(struct device *dev, int status);
00163 int  irda_device_is_media_busy(struct device *dev);
00164 int  irda_device_is_receiving(struct device *dev);
00165 
00166 /* Interface for internal use */
00167 int  irda_device_txqueue_empty(struct device *dev);
00168 int  irda_device_set_raw_mode(struct device* self, int status);
00169 int  irda_device_set_dtr_rts(struct device *dev, int dtr, int rts);
00170 int  irda_device_change_speed(struct device *dev, __u32 speed);
00171 int  irda_device_setup(struct device *dev);
00172 
00173 /* Dongle interface */
00174 void irda_device_unregister_dongle(struct dongle_reg *dongle);
00175 int  irda_device_register_dongle(struct dongle_reg *dongle);
00176 dongle_t *irda_device_dongle_init(struct device *dev, int type);
00177 int irda_device_dongle_cleanup(dongle_t *dongle);
00178 
00179 void setup_dma(int channel, char *buffer, int count, int mode);
00180 
00181 void irda_task_delete(struct irda_task *task);
00182 int  irda_task_kick(struct irda_task *task);
00183 struct irda_task *irda_task_execute(void *instance, TASK_CALLBACK function, 
00184                                     TASK_CALLBACK finished, 
00185                                     struct irda_task *parent, void *param);
00186 void irda_task_next_state(struct irda_task *task, TASK_STATE state);
00187 
00188 extern const char *infrared_mode[];
00189 
00190 /*
00191  * Function irda_get_mtt (skb)
00192  *
00193  *    Utility function for getting the minimum turnaround time out of 
00194  *    the skb, where it has been hidden in the cb field.
00195  */
00196 #define irda_get_mtt(skb) (                                                 \
00197         IRDA_MIN(10000,                                                     \
00198                   (((struct irda_skb_cb *) skb->cb)->magic == LAP_MAGIC) ?  \
00199                           ((struct irda_skb_cb *)(skb->cb))->mtt : 10000    \
00200                  )                                                          \
00201 )
00202 
00203 #if 0
00204 extern inline __u16 irda_get_mtt(struct sk_buff *skb)
00205 {
00206         __u16 mtt;
00207 
00208         if (((struct irda_skb_cb *)(skb->cb))->magic != LAP_MAGIC)
00209                 mtt = 10000;
00210         else
00211                 mtt = ((struct irda_skb_cb *)(skb->cb))->mtt;
00212 
00213         ASSERT(mtt <= 10000, return 10000;);
00214         
00215         return mtt;
00216 }
00217 #endif
00218 
00219 /*
00220  * Function irda_get_speed (skb)
00221  *
00222  *    Extact the speed this frame should be sent out with from the skb
00223  *
00224  */
00225 #define irda_get_speed(skb) (                                           \
00226         (((struct irda_skb_cb*) skb->cb)->magic == LAP_MAGIC) ?         \
00227                   ((struct irda_skb_cb *)(skb->cb))->speed : 9600       \
00228 )
00229 
00230 #if 0
00231 extern inline __u32 irda_get_speed(struct sk_buff *skb)
00232 {
00233         __u32 speed;
00234 
00235         if (((struct irda_skb_cb *)(skb->cb))->magic != LAP_MAGIC)
00236                 speed = 9600;
00237         else
00238                 speed = ((struct irda_skb_cb *)(skb->cb))->speed;
00239 
00240         return speed;
00241 }
00242 #endif
00243 
00244 #endif /* IRDA_DEVICE_H */
00245 
00246