Linux kernel & device driver programming

Cross-Referenced Linux and Device Driver Code

[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ]
Version: [ 2.6.11.8 ] [ 2.6.25 ] [ 2.6.25.8 ] [ 2.6.31.13 ] Architecture: [ i386 ]
  1 /*
  2  * $Id: iforce.h,v 1.13 2002/07/07 10:22:50 jdeneux Exp $
  3  *
  4  *  Copyright (c) 2000-2002 Vojtech Pavlik <vojtech@ucw.cz>
  5  *  Copyright (c) 2001-2002, 2007 Johann Deneux <johann.deneux@gmail.com>
  6  *
  7  *  USB/RS232 I-Force joysticks and wheels.
  8  */
  9 
 10 /*
 11  * This program is free software; you can redistribute it and/or modify
 12  * it under the terms of the GNU General Public License as published by
 13  * the Free Software Foundation; either version 2 of the License, or
 14  * (at your option) any later version.
 15  *
 16  * This program is distributed in the hope that it will be useful,
 17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 19  * GNU General Public License for more details.
 20  *
 21  * You should have received a copy of the GNU General Public License
 22  * along with this program; if not, write to the Free Software
 23  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 24  *
 25  * Should you need to contact me, the author, you can do so either by
 26  * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
 27  * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
 28  */
 29 
 30 #include <linux/kernel.h>
 31 #include <linux/slab.h>
 32 #include <linux/input.h>
 33 #include <linux/module.h>
 34 #include <linux/init.h>
 35 #include <linux/spinlock.h>
 36 #include <linux/usb.h>
 37 #include <linux/serio.h>
 38 #include <linux/circ_buf.h>
 39 #include <linux/mutex.h>
 40 
 41 /* This module provides arbitrary resource management routines.
 42  * I use it to manage the device's memory.
 43  * Despite the name of this module, I am *not* going to access the ioports.
 44  */
 45 #include <linux/ioport.h>
 46 
 47 
 48 #define IFORCE_MAX_LENGTH       16
 49 
 50 /* iforce::bus */
 51 #define IFORCE_232      1
 52 #define IFORCE_USB      2
 53 
 54 #define IFORCE_EFFECTS_MAX      32
 55 
 56 /* Each force feedback effect is made of one core effect, which can be
 57  * associated to at most to effect modifiers
 58  */
 59 #define FF_MOD1_IS_USED         0
 60 #define FF_MOD2_IS_USED         1
 61 #define FF_CORE_IS_USED         2
 62 #define FF_CORE_IS_PLAYED       3       /* Effect is currently being played */
 63 #define FF_CORE_SHOULD_PLAY     4       /* User wants the effect to be played */
 64 #define FF_CORE_UPDATE          5       /* Effect is being updated */
 65 #define FF_MODCORE_CNT          6
 66 
 67 struct iforce_core_effect {
 68         /* Information about where modifiers are stored in the device's memory */
 69         struct resource mod1_chunk;
 70         struct resource mod2_chunk;
 71         unsigned long flags[BITS_TO_LONGS(FF_MODCORE_CNT)];
 72 };
 73 
 74 #define FF_CMD_EFFECT           0x010e
 75 #define FF_CMD_ENVELOPE         0x0208
 76 #define FF_CMD_MAGNITUDE        0x0303
 77 #define FF_CMD_PERIOD           0x0407
 78 #define FF_CMD_CONDITION        0x050a
 79 
 80 #define FF_CMD_AUTOCENTER       0x4002
 81 #define FF_CMD_PLAY             0x4103
 82 #define FF_CMD_ENABLE           0x4201
 83 #define FF_CMD_GAIN             0x4301
 84 
 85 #define FF_CMD_QUERY            0xff01
 86 
 87 /* Buffer for async write */
 88 #define XMIT_SIZE               256
 89 #define XMIT_INC(var, n)        (var)+=n; (var)&= XMIT_SIZE -1
 90 /* iforce::xmit_flags */
 91 #define IFORCE_XMIT_RUNNING     0
 92 #define IFORCE_XMIT_AGAIN       1
 93 
 94 struct iforce_device {
 95         u16 idvendor;
 96         u16 idproduct;
 97         char *name;
 98         signed short *btn;
 99         signed short *abs;
100         signed short *ff;
101 };
102 
103 struct iforce {
104         struct input_dev *dev;          /* Input device interface */
105         struct iforce_device *type;
106         int bus;
107 
108         unsigned char data[IFORCE_MAX_LENGTH];
109         unsigned char edata[IFORCE_MAX_LENGTH];
110         u16 ecmd;
111         u16 expect_packet;
112 
113 #ifdef CONFIG_JOYSTICK_IFORCE_232
114         struct serio *serio;            /* RS232 transfer */
115         int idx, pkt, len, id;
116         unsigned char csum;
117 #endif
118 #ifdef CONFIG_JOYSTICK_IFORCE_USB
119         struct usb_device *usbdev;      /* USB transfer */
120         struct urb *irq, *out, *ctrl;
121         struct usb_ctrlrequest cr;
122 #endif
123         spinlock_t xmit_lock;
124         /* Buffer used for asynchronous sending of bytes to the device */
125         struct circ_buf xmit;
126         unsigned char xmit_data[XMIT_SIZE];
127         unsigned long xmit_flags[1];
128 
129                                         /* Force Feedback */
130         wait_queue_head_t wait;
131         struct resource device_memory;
132         struct iforce_core_effect core_effects[IFORCE_EFFECTS_MAX];
133         struct mutex mem_mutex;
134 };
135 
136 /* Get hi and low bytes of a 16-bits int */
137 #define HI(a)   ((unsigned char)((a) >> 8))
138 #define LO(a)   ((unsigned char)((a) & 0xff))
139 
140 /* For many parameters, it seems that 0x80 is a special value that should
141  * be avoided. Instead, we replace this value by 0x7f
142  */
143 #define HIFIX80(a) ((unsigned char)(((a)<0? (a)+255 : (a))>>8))
144 
145 /* Encode a time value */
146 #define TIME_SCALE(a)   (a)
147 
148 
149 /* Public functions */
150 /* iforce-serio.c */
151 void iforce_serial_xmit(struct iforce *iforce);
152 
153 /* iforce-usb.c */
154 void iforce_usb_xmit(struct iforce *iforce);
155 void iforce_usb_delete(struct iforce *iforce);
156 
157 /* iforce-main.c */
158 int iforce_init_device(struct iforce *iforce);
159 void iforce_delete_device(struct iforce *iforce);
160 
161 /* iforce-packets.c */
162 int iforce_control_playback(struct iforce*, u16 id, unsigned int);
163 void iforce_process_packet(struct iforce *iforce, u16 cmd, unsigned char *data);
164 int iforce_send_packet(struct iforce *iforce, u16 cmd, unsigned char* data);
165 void iforce_dump_packet(char *msg, u16 cmd, unsigned char *data) ;
166 int iforce_get_id_packet(struct iforce *iforce, char *packet);
167 
168 /* iforce-ff.c */
169 int iforce_upload_periodic(struct iforce *, struct ff_effect *, struct ff_effect *);
170 int iforce_upload_constant(struct iforce *, struct ff_effect *, struct ff_effect *);
171 int iforce_upload_condition(struct iforce *, struct ff_effect *, struct ff_effect *);
172 
173 /* Public variables */
174 extern struct serio_driver iforce_serio_drv;
175 extern struct usb_driver iforce_usb_driver;
176 
  This page was automatically generated by the LXR engine.