.. | .. |
---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0-or-later */ |
---|
1 | 2 | /* |
---|
2 | 3 | * Copyright (c) 2000-2002 Vojtech Pavlik <vojtech@ucw.cz> |
---|
3 | 4 | * Copyright (c) 2001-2002, 2007 Johann Deneux <johann.deneux@gmail.com> |
---|
.. | .. |
---|
5 | 6 | * USB/RS232 I-Force joysticks and wheels. |
---|
6 | 7 | */ |
---|
7 | 8 | |
---|
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 | | - |
---|
24 | 9 | #include <linux/kernel.h> |
---|
25 | 10 | #include <linux/slab.h> |
---|
26 | 11 | #include <linux/input.h> |
---|
27 | 12 | #include <linux/module.h> |
---|
28 | 13 | #include <linux/spinlock.h> |
---|
29 | | -#include <linux/usb.h> |
---|
30 | | -#include <linux/serio.h> |
---|
31 | 14 | #include <linux/circ_buf.h> |
---|
32 | 15 | #include <linux/mutex.h> |
---|
33 | 16 | |
---|
.. | .. |
---|
39 | 22 | |
---|
40 | 23 | |
---|
41 | 24 | #define IFORCE_MAX_LENGTH 16 |
---|
42 | | - |
---|
43 | | -/* iforce::bus */ |
---|
44 | | -#define IFORCE_232 1 |
---|
45 | | -#define IFORCE_USB 2 |
---|
46 | 25 | |
---|
47 | 26 | #define IFORCE_EFFECTS_MAX 32 |
---|
48 | 27 | |
---|
.. | .. |
---|
93 | 72 | signed short *ff; |
---|
94 | 73 | }; |
---|
95 | 74 | |
---|
| 75 | +struct iforce; |
---|
| 76 | + |
---|
| 77 | +struct iforce_xport_ops { |
---|
| 78 | + void (*xmit)(struct iforce *iforce); |
---|
| 79 | + int (*get_id)(struct iforce *iforce, u8 id, |
---|
| 80 | + u8 *response_data, size_t *response_len); |
---|
| 81 | + int (*start_io)(struct iforce *iforce); |
---|
| 82 | + void (*stop_io)(struct iforce *iforce); |
---|
| 83 | +}; |
---|
| 84 | + |
---|
96 | 85 | struct iforce { |
---|
97 | 86 | struct input_dev *dev; /* Input device interface */ |
---|
98 | 87 | struct iforce_device *type; |
---|
99 | | - int bus; |
---|
| 88 | + const struct iforce_xport_ops *xport_ops; |
---|
100 | 89 | |
---|
101 | | - unsigned char data[IFORCE_MAX_LENGTH]; |
---|
102 | | - unsigned char edata[IFORCE_MAX_LENGTH]; |
---|
103 | | - u16 ecmd; |
---|
104 | | - u16 expect_packet; |
---|
105 | | - |
---|
106 | | -#ifdef CONFIG_JOYSTICK_IFORCE_232 |
---|
107 | | - struct serio *serio; /* RS232 transfer */ |
---|
108 | | - int idx, pkt, len, id; |
---|
109 | | - unsigned char csum; |
---|
110 | | -#endif |
---|
111 | | -#ifdef CONFIG_JOYSTICK_IFORCE_USB |
---|
112 | | - struct usb_device *usbdev; /* USB transfer */ |
---|
113 | | - struct usb_interface *intf; |
---|
114 | | - struct urb *irq, *out, *ctrl; |
---|
115 | | - struct usb_ctrlrequest cr; |
---|
116 | | -#endif |
---|
117 | 90 | spinlock_t xmit_lock; |
---|
118 | 91 | /* Buffer used for asynchronous sending of bytes to the device */ |
---|
119 | 92 | struct circ_buf xmit; |
---|
.. | .. |
---|
139 | 112 | /* Encode a time value */ |
---|
140 | 113 | #define TIME_SCALE(a) (a) |
---|
141 | 114 | |
---|
| 115 | +static inline int iforce_get_id_packet(struct iforce *iforce, u8 id, |
---|
| 116 | + u8 *response_data, size_t *response_len) |
---|
| 117 | +{ |
---|
| 118 | + return iforce->xport_ops->get_id(iforce, id, |
---|
| 119 | + response_data, response_len); |
---|
| 120 | +} |
---|
| 121 | + |
---|
| 122 | +static inline void iforce_clear_xmit_and_wake(struct iforce *iforce) |
---|
| 123 | +{ |
---|
| 124 | + clear_bit(IFORCE_XMIT_RUNNING, iforce->xmit_flags); |
---|
| 125 | + wake_up_all(&iforce->wait); |
---|
| 126 | +} |
---|
142 | 127 | |
---|
143 | 128 | /* Public functions */ |
---|
144 | | -/* iforce-serio.c */ |
---|
145 | | -void iforce_serial_xmit(struct iforce *iforce); |
---|
146 | | - |
---|
147 | | -/* iforce-usb.c */ |
---|
148 | | -void iforce_usb_xmit(struct iforce *iforce); |
---|
149 | | - |
---|
150 | 129 | /* iforce-main.c */ |
---|
151 | | -int iforce_init_device(struct iforce *iforce); |
---|
| 130 | +int iforce_init_device(struct device *parent, u16 bustype, |
---|
| 131 | + struct iforce *iforce); |
---|
152 | 132 | |
---|
153 | 133 | /* iforce-packets.c */ |
---|
154 | 134 | int iforce_control_playback(struct iforce*, u16 id, unsigned int); |
---|
155 | | -void iforce_process_packet(struct iforce *iforce, u16 cmd, unsigned char *data); |
---|
| 135 | +void iforce_process_packet(struct iforce *iforce, |
---|
| 136 | + u8 packet_id, u8 *data, size_t len); |
---|
156 | 137 | int iforce_send_packet(struct iforce *iforce, u16 cmd, unsigned char* data); |
---|
157 | 138 | void iforce_dump_packet(struct iforce *iforce, char *msg, u16 cmd, unsigned char *data); |
---|
158 | | -int iforce_get_id_packet(struct iforce *iforce, char *packet); |
---|
159 | 139 | |
---|
160 | 140 | /* iforce-ff.c */ |
---|
161 | 141 | int iforce_upload_periodic(struct iforce *, struct ff_effect *, struct ff_effect *); |
---|