Merge tag 'afs-next-20190628' of git://git.kernel.org/pub/scm/linux/kernel/git/dhowel...
[sfrench/cifs-2.6.git] / drivers / input / joystick / iforce / iforce.h
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  *  Copyright (c) 2000-2002 Vojtech Pavlik <vojtech@ucw.cz>
4  *  Copyright (c) 2001-2002, 2007 Johann Deneux <johann.deneux@gmail.com>
5  *
6  *  USB/RS232 I-Force joysticks and wheels.
7  */
8
9 /*
10  */
11
12 #include <linux/kernel.h>
13 #include <linux/slab.h>
14 #include <linux/input.h>
15 #include <linux/module.h>
16 #include <linux/spinlock.h>
17 #include <linux/usb.h>
18 #include <linux/serio.h>
19 #include <linux/circ_buf.h>
20 #include <linux/mutex.h>
21
22 /* This module provides arbitrary resource management routines.
23  * I use it to manage the device's memory.
24  * Despite the name of this module, I am *not* going to access the ioports.
25  */
26 #include <linux/ioport.h>
27
28
29 #define IFORCE_MAX_LENGTH       16
30
31 /* iforce::bus */
32 #define IFORCE_232      1
33 #define IFORCE_USB      2
34
35 #define IFORCE_EFFECTS_MAX      32
36
37 /* Each force feedback effect is made of one core effect, which can be
38  * associated to at most to effect modifiers
39  */
40 #define FF_MOD1_IS_USED         0
41 #define FF_MOD2_IS_USED         1
42 #define FF_CORE_IS_USED         2
43 #define FF_CORE_IS_PLAYED       3       /* Effect is currently being played */
44 #define FF_CORE_SHOULD_PLAY     4       /* User wants the effect to be played */
45 #define FF_CORE_UPDATE          5       /* Effect is being updated */
46 #define FF_MODCORE_CNT          6
47
48 struct iforce_core_effect {
49         /* Information about where modifiers are stored in the device's memory */
50         struct resource mod1_chunk;
51         struct resource mod2_chunk;
52         unsigned long flags[BITS_TO_LONGS(FF_MODCORE_CNT)];
53 };
54
55 #define FF_CMD_EFFECT           0x010e
56 #define FF_CMD_ENVELOPE         0x0208
57 #define FF_CMD_MAGNITUDE        0x0303
58 #define FF_CMD_PERIOD           0x0407
59 #define FF_CMD_CONDITION        0x050a
60
61 #define FF_CMD_AUTOCENTER       0x4002
62 #define FF_CMD_PLAY             0x4103
63 #define FF_CMD_ENABLE           0x4201
64 #define FF_CMD_GAIN             0x4301
65
66 #define FF_CMD_QUERY            0xff01
67
68 /* Buffer for async write */
69 #define XMIT_SIZE               256
70 #define XMIT_INC(var, n)        (var)+=n; (var)&= XMIT_SIZE -1
71 /* iforce::xmit_flags */
72 #define IFORCE_XMIT_RUNNING     0
73 #define IFORCE_XMIT_AGAIN       1
74
75 struct iforce_device {
76         u16 idvendor;
77         u16 idproduct;
78         char *name;
79         signed short *btn;
80         signed short *abs;
81         signed short *ff;
82 };
83
84 struct iforce {
85         struct input_dev *dev;          /* Input device interface */
86         struct iforce_device *type;
87         int bus;
88
89         unsigned char data[IFORCE_MAX_LENGTH];
90         unsigned char edata[IFORCE_MAX_LENGTH];
91         u16 ecmd;
92         u16 expect_packet;
93
94 #ifdef CONFIG_JOYSTICK_IFORCE_232
95         struct serio *serio;            /* RS232 transfer */
96         int idx, pkt, len, id;
97         unsigned char csum;
98 #endif
99 #ifdef CONFIG_JOYSTICK_IFORCE_USB
100         struct usb_device *usbdev;      /* USB transfer */
101         struct usb_interface *intf;
102         struct urb *irq, *out, *ctrl;
103         struct usb_ctrlrequest cr;
104 #endif
105         spinlock_t xmit_lock;
106         /* Buffer used for asynchronous sending of bytes to the device */
107         struct circ_buf xmit;
108         unsigned char xmit_data[XMIT_SIZE];
109         unsigned long xmit_flags[1];
110
111                                         /* Force Feedback */
112         wait_queue_head_t wait;
113         struct resource device_memory;
114         struct iforce_core_effect core_effects[IFORCE_EFFECTS_MAX];
115         struct mutex mem_mutex;
116 };
117
118 /* Get hi and low bytes of a 16-bits int */
119 #define HI(a)   ((unsigned char)((a) >> 8))
120 #define LO(a)   ((unsigned char)((a) & 0xff))
121
122 /* For many parameters, it seems that 0x80 is a special value that should
123  * be avoided. Instead, we replace this value by 0x7f
124  */
125 #define HIFIX80(a) ((unsigned char)(((a)<0? (a)+255 : (a))>>8))
126
127 /* Encode a time value */
128 #define TIME_SCALE(a)   (a)
129
130
131 /* Public functions */
132 /* iforce-serio.c */
133 void iforce_serial_xmit(struct iforce *iforce);
134
135 /* iforce-usb.c */
136 void iforce_usb_xmit(struct iforce *iforce);
137
138 /* iforce-main.c */
139 int iforce_init_device(struct iforce *iforce);
140
141 /* iforce-packets.c */
142 int iforce_control_playback(struct iforce*, u16 id, unsigned int);
143 void iforce_process_packet(struct iforce *iforce, u16 cmd, unsigned char *data);
144 int iforce_send_packet(struct iforce *iforce, u16 cmd, unsigned char* data);
145 void iforce_dump_packet(struct iforce *iforce, char *msg, u16 cmd, unsigned char *data);
146 int iforce_get_id_packet(struct iforce *iforce, char *packet);
147
148 /* iforce-ff.c */
149 int iforce_upload_periodic(struct iforce *, struct ff_effect *, struct ff_effect *);
150 int iforce_upload_constant(struct iforce *, struct ff_effect *, struct ff_effect *);
151 int iforce_upload_condition(struct iforce *, struct ff_effect *, struct ff_effect *);
152
153 /* Public variables */
154 extern struct serio_driver iforce_serio_drv;
155 extern struct usb_driver iforce_usb_driver;