Skip to content

Commit 6ac0aec

Browse files
committed
Input: iforce - allow callers supply data buffer when fetching device IDs
We want to move buffer handling into transport layers as the properties of buffers (DMA-safety, alignment, etc) are different for different transports. To allow this, let's allow caller to specify their own buffers for the results of iforce_get_id_packet() and let transport drivers to figure what buffers they need to use for transfers. Tested-by: Tim Schumacher <timschumi@gmx.de> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
1 parent 633354d commit 6ac0aec

4 files changed

Lines changed: 47 additions & 30 deletions

File tree

‎drivers/input/joystick/iforce/iforce-main.c‎

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,9 @@ int iforce_init_device(struct device *parent, u16 bustype,
225225
{
226226
struct input_dev *input_dev;
227227
struct ff_device *ff;
228-
unsigned char c[] = "CEOV";
228+
u8 c[] = "CEOV";
229+
u8 buf[IFORCE_MAX_LENGTH];
230+
size_t len;
229231
int i, error;
230232
int ff_effects = 0;
231233

@@ -269,7 +271,7 @@ int iforce_init_device(struct device *parent, u16 bustype,
269271
*/
270272

271273
for (i = 0; i < 20; i++)
272-
if (!iforce_get_id_packet(iforce, "O"))
274+
if (!iforce_get_id_packet(iforce, 'O', buf, &len))
273275
break;
274276

275277
if (i == 20) { /* 5 seconds */
@@ -283,23 +285,23 @@ int iforce_init_device(struct device *parent, u16 bustype,
283285
* Get device info.
284286
*/
285287

286-
if (!iforce_get_id_packet(iforce, "M"))
287-
input_dev->id.vendor = (iforce->edata[2] << 8) | iforce->edata[1];
288+
if (!iforce_get_id_packet(iforce, 'M', buf, &len) || len < 3)
289+
input_dev->id.vendor = (buf[2] << 8) | buf[1];
288290
else
289291
dev_warn(&iforce->dev->dev, "Device does not respond to id packet M\n");
290292

291-
if (!iforce_get_id_packet(iforce, "P"))
292-
input_dev->id.product = (iforce->edata[2] << 8) | iforce->edata[1];
293+
if (!iforce_get_id_packet(iforce, 'P', buf, &len) || len < 3)
294+
input_dev->id.product = (buf[2] << 8) | buf[1];
293295
else
294296
dev_warn(&iforce->dev->dev, "Device does not respond to id packet P\n");
295297

296-
if (!iforce_get_id_packet(iforce, "B"))
297-
iforce->device_memory.end = (iforce->edata[2] << 8) | iforce->edata[1];
298+
if (!iforce_get_id_packet(iforce, 'B', buf, &len) || len < 3)
299+
iforce->device_memory.end = (buf[2] << 8) | buf[1];
298300
else
299301
dev_warn(&iforce->dev->dev, "Device does not respond to id packet B\n");
300302

301-
if (!iforce_get_id_packet(iforce, "N"))
302-
ff_effects = iforce->edata[1];
303+
if (!iforce_get_id_packet(iforce, 'N', buf, &len) || len < 2)
304+
ff_effects = buf[1];
303305
else
304306
dev_warn(&iforce->dev->dev, "Device does not respond to id packet N\n");
305307

@@ -315,8 +317,9 @@ int iforce_init_device(struct device *parent, u16 bustype,
315317
*/
316318

317319
for (i = 0; c[i]; i++)
318-
if (!iforce_get_id_packet(iforce, c + i))
319-
iforce_dump_packet(iforce, "info", iforce->ecmd, iforce->edata);
320+
if (!iforce_get_id_packet(iforce, c[i], buf, &len))
321+
iforce_dump_packet(iforce, "info",
322+
(FF_CMD_QUERY & 0xff00) | len, buf);
320323

321324
/*
322325
* Disable spring, enable force feedback.

‎drivers/input/joystick/iforce/iforce-serio.c‎

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ struct iforce_serio {
3131
int idx, pkt, len, id;
3232
u8 csum;
3333
u8 expect_packet;
34+
u8 cmd_response[IFORCE_MAX_LENGTH];
35+
u8 cmd_response_len;
3436
};
3537

3638
static void iforce_serio_xmit(struct iforce *iforce)
@@ -81,24 +83,34 @@ static void iforce_serio_xmit(struct iforce *iforce)
8183
spin_unlock_irqrestore(&iforce->xmit_lock, flags);
8284
}
8385

84-
static int iforce_serio_get_id(struct iforce *iforce, u8 *packet)
86+
static int iforce_serio_get_id(struct iforce *iforce, u8 id,
87+
u8 *response_data, size_t *response_len)
8588
{
8689
struct iforce_serio *iforce_serio = container_of(iforce,
8790
struct iforce_serio,
8891
iforce);
8992

9093
iforce_serio->expect_packet = HI(FF_CMD_QUERY);
91-
iforce_send_packet(iforce, FF_CMD_QUERY, packet);
94+
iforce_serio->cmd_response_len = 0;
95+
96+
iforce_send_packet(iforce, FF_CMD_QUERY, &id);
9297

9398
wait_event_interruptible_timeout(iforce->wait,
9499
!iforce_serio->expect_packet, HZ);
95100

96101
if (iforce_serio->expect_packet) {
97102
iforce_serio->expect_packet = 0;
98-
return -EIO;
103+
return -ETIMEDOUT;
99104
}
100105

101-
return -(iforce->edata[0] != packet[0]);
106+
if (iforce_serio->cmd_response[0] != id)
107+
return -EIO;
108+
109+
memcpy(response_data, iforce_serio->cmd_response,
110+
iforce_serio->cmd_response_len);
111+
*response_len = iforce_serio->cmd_response_len;
112+
113+
return 0;
102114
}
103115

104116
static int iforce_serio_start_io(struct iforce *iforce)
@@ -127,7 +139,7 @@ static void iforce_serio_write_wakeup(struct serio *serio)
127139
}
128140

129141
static irqreturn_t iforce_serio_irq(struct serio *serio,
130-
unsigned char data, unsigned int flags)
142+
unsigned char data, unsigned int flags)
131143
{
132144
struct iforce_serio *iforce_serio = serio_get_drvdata(serio);
133145
struct iforce *iforce = &iforce_serio->iforce;
@@ -166,9 +178,9 @@ static irqreturn_t iforce_serio_irq(struct serio *serio,
166178
/* Handle command completion */
167179
if (iforce_serio->expect_packet == iforce_serio->id) {
168180
iforce_serio->expect_packet = 0;
169-
iforce->ecmd = (iforce_serio->id << 8) |
170-
iforce_serio->idx;
171-
memcpy(iforce->edata, iforce->data, IFORCE_MAX_LENGTH);
181+
memcpy(iforce_serio->cmd_response, iforce->data,
182+
IFORCE_MAX_LENGTH);
183+
iforce_serio->cmd_response_len = iforce_serio->len;
172184

173185
/* Signal that command is done */
174186
wake_up(&iforce->wait);

‎drivers/input/joystick/iforce/iforce-usb.c‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ static void iforce_usb_xmit(struct iforce *iforce)
8787
__iforce_usb_xmit(iforce);
8888
}
8989

90-
static int iforce_usb_get_id(struct iforce *iforce, u8 *packet)
90+
static int iforce_usb_get_id(struct iforce *iforce, u8 id,
91+
u8 *response_data, size_t *response_len)
9192
{
9293
struct iforce_usb *iforce_usb = container_of(iforce, struct iforce_usb,
9394
iforce);
@@ -100,18 +101,18 @@ static int iforce_usb_get_id(struct iforce *iforce, u8 *packet)
100101

101102
status = usb_control_msg(iforce_usb->usbdev,
102103
usb_rcvctrlpipe(iforce_usb->usbdev, 0),
103-
packet[0],
104+
id,
104105
USB_TYPE_VENDOR | USB_DIR_IN |
105106
USB_RECIP_INTERFACE,
106107
0, 0, buf, IFORCE_MAX_LENGTH, HZ);
107108
if (status < 0) {
108109
dev_err(&iforce_usb->intf->dev,
109110
"usb_submit_urb failed: %d\n", status);
110-
} else if (buf[0] != packet[0]) {
111+
} else if (buf[0] != id) {
111112
status = -EIO;
112113
} else {
113-
iforce->ecmd = 0xff00 | status;
114-
memcpy(iforce->edata, buf, status);
114+
memcpy(response_data, buf, status);
115+
*response_len = status;
115116
status = 0;
116117
}
117118

‎drivers/input/joystick/iforce/iforce.h‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ struct iforce;
9595

9696
struct iforce_xport_ops {
9797
void (*xmit)(struct iforce *iforce);
98-
int (*get_id)(struct iforce *iforce, u8* id);
98+
int (*get_id)(struct iforce *iforce, u8 id,
99+
u8 *response_data, size_t *response_len);
99100
int (*start_io)(struct iforce *iforce);
100101
void (*stop_io)(struct iforce *iforce);
101102
};
@@ -107,8 +108,6 @@ struct iforce {
107108
int bus;
108109

109110
unsigned char data[IFORCE_MAX_LENGTH];
110-
unsigned char edata[IFORCE_MAX_LENGTH];
111-
u16 ecmd;
112111

113112
spinlock_t xmit_lock;
114113
/* Buffer used for asynchronous sending of bytes to the device */
@@ -135,9 +134,11 @@ struct iforce {
135134
/* Encode a time value */
136135
#define TIME_SCALE(a) (a)
137136

138-
static inline int iforce_get_id_packet(struct iforce *iforce, u8* id)
137+
static inline int iforce_get_id_packet(struct iforce *iforce, u8 id,
138+
u8 *response_data, size_t *response_len)
139139
{
140-
return iforce->xport_ops->get_id(iforce, id);
140+
return iforce->xport_ops->get_id(iforce, id,
141+
response_data, response_len);
141142
}
142143

143144
/* Public functions */

0 commit comments

Comments
 (0)