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