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
59typedef 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
66typedef 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
78struct irda_task;
79typedef int (*IRDA_TASK_CALLBACK) (struct irda_task *task);
80
81struct 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 */
97struct dongle_reg;
98typedef 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 */
113struct 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 */
124typedef 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) */
144typedef 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 */
158int  irda_device_init(void);
159void irda_device_cleanup(void);
160
161/* Interface to be uses by IrLAP */
162void irda_device_set_media_busy(struct net_device *dev, int status);
163int  irda_device_is_media_busy(struct net_device *dev);
164int  irda_device_is_receiving(struct net_device *dev);
165
166/* Interface for internal use */
167int  irda_device_txqueue_empty(struct net_device *dev);
168int  irda_device_set_raw_mode(struct net_device* self, int status);
169int  irda_device_set_dtr_rts(struct net_device *dev, int dtr, int rts);
170int  irda_device_change_speed(struct net_device *dev, __u32 speed);
171int  irda_device_setup(struct net_device *dev);
172
173/* Dongle interface */
174void irda_device_unregister_dongle(struct dongle_reg *dongle);
175int  irda_device_register_dongle(struct dongle_reg *dongle);
176dongle_t *irda_device_dongle_init(struct net_device *dev, int type);
177int irda_device_dongle_cleanup(dongle_t *dongle);
178
179void setup_dma(int channel, char *buffer, int count, int mode);
180
181void irda_task_delete(struct irda_task *task);
182int  irda_task_kick(struct irda_task *task);
183struct irda_task *irda_task_execute(void *instance,
184				    IRDA_TASK_CALLBACK function,
185				    IRDA_TASK_CALLBACK finished,
186				    struct irda_task *parent, void *param);
187void irda_task_next_state(struct irda_task *task, IRDA_TASK_STATE state);
188
189extern 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
205/*
206 * Function irda_get_next_speed (skb)
207 *
208 *    Extract the speed that should be set *after* this frame from the skb
209 *
210 * Note : return -1 for user space frames
211 */
212#define irda_get_next_speed(skb) (	                                        \
213	(((struct irda_skb_cb*) skb->cb)->magic == LAP_MAGIC) ? 	\
214                  ((struct irda_skb_cb *)(skb->cb))->next_speed : -1 	\
215)
216
217
218/*
219 * Function irda_get_next_xbofs (skb)
220 *
221 *    Extract the xbofs that should be set for this frame from the skb
222 *
223 * Note : default to 10 for user space frames
224 */
225#define irda_get_xbofs(skb) (	                                        \
226	(((struct irda_skb_cb*) skb->cb)->magic == LAP_MAGIC) ? 	\
227                  ((struct irda_skb_cb *)(skb->cb))->xbofs : 10 	\
228)
229
230/*
231 * Function irda_get_next_xbofs (skb)
232 *
233 *    Extract the xbofs that should be set *after* this frame from the skb
234 *
235 * Note : return -1 for user space frames
236 */
237#define irda_get_next_xbofs(skb) (	                                        \
238	(((struct irda_skb_cb*) skb->cb)->magic == LAP_MAGIC) ? 	\
239                  ((struct irda_skb_cb *)(skb->cb))->next_xbofs : -1 	\
240)
241
242#endif /* IRDA_DEVICE_H */
243
244
245