more changes on original files
[linux-2.4.git] / include / net / irda / irda_device.h
1 /*********************************************************************
2  *                
3  * Filename:      irda_device.h
4  * Version:       0.9
5  * Description:   Contains various declarations used by the drivers
6  * Status:        Experimental.
7  * Author:        Dag Brattli <dagb@cs.uit.no>
8  * Created at:    Tue Apr 14 12:41:42 1998
9  * Modified at:   Mon Mar 20 09:08:57 2000
10  * Modified by:   Dag Brattli <dagb@cs.uit.no>
11  * 
12  *     Copyright (c) 1999-2000 Dag Brattli, All Rights Reserved.
13  *     Copyright (c) 1998 Thomas Davis, <ratbert@radiks.net>,
14  *
15  *     This program is free software; you can redistribute it and/or 
16  *     modify it under the terms of the GNU General Public License as 
17  *     published by the Free Software Foundation; either version 2 of 
18  *     the License, or (at your option) any later version.
19  * 
20  *     This program is distributed in the hope that it will be useful,
21  *     but WITHOUT ANY WARRANTY; without even the implied warranty of
22  *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23  *     GNU General Public License for more details.
24  * 
25  *     You should have received a copy of the GNU General Public License 
26  *     along with this program; if not, write to the Free Software 
27  *     Foundation, Inc., 59 Temple Place, Suite 330, Boston, 
28  *     MA 02111-1307 USA
29  *     
30  ********************************************************************/
31
32 #ifndef IRDA_DEVICE_H
33 #define IRDA_DEVICE_H
34
35 #include <linux/tty.h>
36 #include <linux/netdevice.h>
37 #include <linux/spinlock.h>
38 #include <linux/irda.h>
39
40 #include <net/irda/irda.h>
41 #include <net/irda/qos.h>
42 #include <net/irda/irqueue.h>
43 #include <net/irda/irlap_frame.h>
44
45 /* Some non-standard interface flags (should not conflict with any in if.h) */
46 #define IFF_SIR         0x0001 /* Supports SIR speeds */
47 #define IFF_MIR         0x0002 /* Supports MIR speeds */
48 #define IFF_FIR         0x0004 /* Supports FIR speeds */
49 #define IFF_VFIR        0x0008 /* Supports VFIR speeds */
50 #define IFF_PIO         0x0010 /* Supports PIO transfer of data */
51 #define IFF_DMA         0x0020 /* Supports DMA transfer of data */
52 #define IFF_SHM         0x0040 /* Supports shared memory data transfers */
53 #define IFF_DONGLE      0x0080 /* Interface has a dongle attached */
54 #define IFF_AIR         0x0100 /* Supports Advanced IR (AIR) standards */
55
56 #define IO_XMIT 0x01
57 #define IO_RECV 0x02
58
59 typedef enum {
60         IRDA_IRLAP, /* IrDA mode, and deliver to IrLAP */
61         IRDA_RAW,   /* IrDA mode */
62         SHARP_ASK,
63         TV_REMOTE,  /* Also known as Consumer Electronics IR */
64 } INFRARED_MODE;
65
66 typedef enum {
67         IRDA_TASK_INIT,        /* All tasks are initialized with this state */
68         IRDA_TASK_DONE,        /* Signals that the task is finished */
69         IRDA_TASK_WAIT,
70         IRDA_TASK_WAIT1,
71         IRDA_TASK_WAIT2,
72         IRDA_TASK_WAIT3,
73         IRDA_TASK_CHILD_INIT,  /* Initializing child task */
74         IRDA_TASK_CHILD_WAIT,  /* Waiting for child task to finish */
75         IRDA_TASK_CHILD_DONE   /* Child task is finished */
76 } IRDA_TASK_STATE;
77
78 struct irda_task;
79 typedef int (*IRDA_TASK_CALLBACK) (struct irda_task *task);
80
81 struct irda_task {
82         irda_queue_t q;
83         magic_t magic;
84
85         IRDA_TASK_STATE state;
86         IRDA_TASK_CALLBACK function;
87         IRDA_TASK_CALLBACK finished;
88
89         struct irda_task *parent;
90         struct timer_list timer;
91
92         void *instance; /* Instance being called */
93         void *param;    /* Parameter to be used by instance */
94 };
95
96 /* Dongle info */
97 struct dongle_reg;
98 typedef struct {
99         struct dongle_reg *issue;     /* Registration info */
100         struct net_device *dev;           /* Device we are attached to */
101         struct irda_task *speed_task; /* Task handling speed change */
102         struct irda_task *reset_task; /* Task handling reset */
103         __u32 speed;                  /* Current speed */
104
105         /* Callbacks to the IrDA device driver */
106         int (*set_mode)(struct net_device *, int mode);
107         int (*read)(struct net_device *dev, __u8 *buf, int len);
108         int (*write)(struct net_device *dev, __u8 *buf, int len);
109         int (*set_dtr_rts)(struct net_device *dev, int dtr, int rts);
110 } dongle_t;
111
112 /* Dongle registration info */
113 struct dongle_reg {
114         irda_queue_t q;         /* Must be first */
115         IRDA_DONGLE type;
116
117         void (*open)(dongle_t *dongle, struct qos_info *qos);
118         void (*close)(dongle_t *dongle);
119         int  (*reset)(struct irda_task *task);
120         int  (*change_speed)(struct irda_task *task);
121 };
122
123 /* Chip specific info */
124 typedef struct {
125         int cfg_base;         /* Config register IO base */
126         int sir_base;         /* SIR IO base */
127         int fir_base;         /* FIR IO base */
128         int mem_base;         /* Shared memory base */
129         int sir_ext;          /* Length of SIR iobase */
130         int fir_ext;          /* Length of FIR iobase */
131         int irq, irq2;        /* Interrupts used */
132         int dma, dma2;        /* DMA channel(s) used */
133         int fifo_size;        /* FIFO size */
134         int irqflags;         /* interrupt flags (ie, SA_SHIRQ|SA_INTERRUPT) */
135         int direction;        /* Link direction, used by some FIR drivers */
136         int enabled;          /* Powered on? */
137         int suspended;        /* Suspended by APM */
138         __u32 speed;          /* Currently used speed */
139         __u32 new_speed;      /* Speed we must change to when Tx is finished */
140         int dongle_id;        /* Dongle or transceiver currently used */
141 } chipio_t;
142
143 /* IO buffer specific info (inspired by struct sk_buff) */
144 typedef struct {
145         int state;            /* Receiving state (transmit state not used) */
146         int in_frame;         /* True if receiving frame */
147
148         __u8 *head;           /* start of buffer */
149         __u8 *data;           /* start of data in buffer */
150         __u8 *tail;           /* end of data in buffer */
151
152         int len;              /* length of data */
153         int truesize;         /* total size of buffer */
154         __u16 fcs;
155 } iobuff_t;
156
157 /* Function prototypes */
158 int  irda_device_init(void);
159 void irda_device_cleanup(void);
160
161 /* Interface to be uses by IrLAP */
162 void irda_device_set_media_busy(struct net_device *dev, int status);
163 int  irda_device_is_media_busy(struct net_device *dev);
164 int  irda_device_is_receiving(struct net_device *dev);
165
166 /* Interface for internal use */
167 int  irda_device_txqueue_empty(struct net_device *dev);
168 int  irda_device_set_raw_mode(struct net_device* self, int status);
169 int  irda_device_set_dtr_rts(struct net_device *dev, int dtr, int rts);
170 int  irda_device_change_speed(struct net_device *dev, __u32 speed);
171 int  irda_device_setup(struct net_device *dev);
172
173 /* Dongle interface */
174 void irda_device_unregister_dongle(struct dongle_reg *dongle);
175 int  irda_device_register_dongle(struct dongle_reg *dongle);
176 dongle_t *irda_device_dongle_init(struct net_device *dev, int type);
177 int irda_device_dongle_cleanup(dongle_t *dongle);
178
179 void setup_dma(int channel, char *buffer, int count, int mode);
180
181 void irda_task_delete(struct irda_task *task);
182 int  irda_task_kick(struct irda_task *task);
183 struct irda_task *irda_task_execute(void *instance, 
184                                     IRDA_TASK_CALLBACK function, 
185                                     IRDA_TASK_CALLBACK finished, 
186                                     struct irda_task *parent, void *param);
187 void irda_task_next_state(struct irda_task *task, IRDA_TASK_STATE state);
188
189 extern const char *infrared_mode[];
190
191 /*
192  * Function irda_get_mtt (skb)
193  *
194  *    Utility function for getting the minimum turnaround time out of 
195  *    the skb, where it has been hidden in the cb field.
196  */
197 #define irda_get_mtt(skb) (                                                 \
198         IRDA_MIN(10000,                                                     \
199                   (((struct irda_skb_cb *) skb->cb)->magic == LAP_MAGIC) ?  \
200                           ((struct irda_skb_cb *)(skb->cb))->mtt : 10000    \
201                  )                                                          \
202 )
203
204 #if 0
205 extern inline __u16 irda_get_mtt(struct sk_buff *skb)
206 {
207         __u16 mtt;
208
209         if (((struct irda_skb_cb *)(skb->cb))->magic != LAP_MAGIC)
210                 mtt = 10000;
211         else
212                 mtt = ((struct irda_skb_cb *)(skb->cb))->mtt;
213
214         ASSERT(mtt <= 10000, return 10000;);
215         
216         return mtt;
217 }
218 #endif
219
220 /*
221  * Function irda_get_next_speed (skb)
222  *
223  *    Extract the speed that should be set *after* this frame from the skb
224  *
225  * Note : return -1 for user space frames
226  */
227 #define irda_get_next_speed(skb) (                                              \
228         (((struct irda_skb_cb*) skb->cb)->magic == LAP_MAGIC) ?         \
229                   ((struct irda_skb_cb *)(skb->cb))->next_speed : -1    \
230 )
231
232 #if 0
233 extern inline __u32 irda_get_next_speed(struct sk_buff *skb)
234 {
235         __u32 speed;
236
237         if (((struct irda_skb_cb *)(skb->cb))->magic != LAP_MAGIC)
238                 speed = -1;
239         else
240                 speed = ((struct irda_skb_cb *)(skb->cb))->next_speed;
241
242         return speed;
243 }
244 #endif
245
246 /*
247  * Function irda_get_next_xbofs (skb)
248  *
249  *    Extract the xbofs that should be set for this frame from the skb
250  *
251  * Note : default to 10 for user space frames
252  */
253 #define irda_get_xbofs(skb) (                                           \
254         (((struct irda_skb_cb*) skb->cb)->magic == LAP_MAGIC) ?         \
255                   ((struct irda_skb_cb *)(skb->cb))->xbofs : 10         \
256 )
257
258 /*
259  * Function irda_get_next_xbofs (skb)
260  *
261  *    Extract the xbofs that should be set *after* this frame from the skb
262  *
263  * Note : return -1 for user space frames
264  */
265 #define irda_get_next_xbofs(skb) (                                              \
266         (((struct irda_skb_cb*) skb->cb)->magic == LAP_MAGIC) ?         \
267                   ((struct irda_skb_cb *)(skb->cb))->next_xbofs : -1    \
268 )
269
270 #endif /* IRDA_DEVICE_H */
271
272