HID: i2c-hid: override HID descriptors for certain devices
[muen/linux.git] / drivers / hid / i2c-hid / i2c-hid-core.c
1 /*
2  * HID over I2C protocol implementation
3  *
4  * Copyright (c) 2012 Benjamin Tissoires <benjamin.tissoires@gmail.com>
5  * Copyright (c) 2012 Ecole Nationale de l'Aviation Civile, France
6  * Copyright (c) 2012 Red Hat, Inc
7  *
8  * This code is partly based on "USB HID support for Linux":
9  *
10  *  Copyright (c) 1999 Andreas Gal
11  *  Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
12  *  Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
13  *  Copyright (c) 2007-2008 Oliver Neukum
14  *  Copyright (c) 2006-2010 Jiri Kosina
15  *
16  * This file is subject to the terms and conditions of the GNU General Public
17  * License.  See the file COPYING in the main directory of this archive for
18  * more details.
19  */
20
21 #include <linux/module.h>
22 #include <linux/i2c.h>
23 #include <linux/interrupt.h>
24 #include <linux/input.h>
25 #include <linux/irq.h>
26 #include <linux/delay.h>
27 #include <linux/slab.h>
28 #include <linux/pm.h>
29 #include <linux/pm_runtime.h>
30 #include <linux/device.h>
31 #include <linux/wait.h>
32 #include <linux/err.h>
33 #include <linux/string.h>
34 #include <linux/list.h>
35 #include <linux/jiffies.h>
36 #include <linux/kernel.h>
37 #include <linux/hid.h>
38 #include <linux/mutex.h>
39 #include <linux/acpi.h>
40 #include <linux/of.h>
41 #include <linux/regulator/consumer.h>
42
43 #include <linux/platform_data/i2c-hid.h>
44
45 #include "../hid-ids.h"
46 #include "i2c-hid.h"
47
48 /* quirks to control the device */
49 #define I2C_HID_QUIRK_SET_PWR_WAKEUP_DEV        BIT(0)
50 #define I2C_HID_QUIRK_NO_IRQ_AFTER_RESET        BIT(1)
51 #define I2C_HID_QUIRK_RESEND_REPORT_DESCR       BIT(2)
52
53 /* flags */
54 #define I2C_HID_STARTED         0
55 #define I2C_HID_RESET_PENDING   1
56 #define I2C_HID_READ_PENDING    2
57
58 #define I2C_HID_PWR_ON          0x00
59 #define I2C_HID_PWR_SLEEP       0x01
60
61 /* debug option */
62 static bool debug;
63 module_param(debug, bool, 0444);
64 MODULE_PARM_DESC(debug, "print a lot of debug information");
65
66 #define i2c_hid_dbg(ihid, fmt, arg...)                                    \
67 do {                                                                      \
68         if (debug)                                                        \
69                 dev_printk(KERN_DEBUG, &(ihid)->client->dev, fmt, ##arg); \
70 } while (0)
71
72 struct i2c_hid_desc {
73         __le16 wHIDDescLength;
74         __le16 bcdVersion;
75         __le16 wReportDescLength;
76         __le16 wReportDescRegister;
77         __le16 wInputRegister;
78         __le16 wMaxInputLength;
79         __le16 wOutputRegister;
80         __le16 wMaxOutputLength;
81         __le16 wCommandRegister;
82         __le16 wDataRegister;
83         __le16 wVendorID;
84         __le16 wProductID;
85         __le16 wVersionID;
86         __le32 reserved;
87 } __packed;
88
89 struct i2c_hid_cmd {
90         unsigned int registerIndex;
91         __u8 opcode;
92         unsigned int length;
93         bool wait;
94 };
95
96 union command {
97         u8 data[0];
98         struct cmd {
99                 __le16 reg;
100                 __u8 reportTypeID;
101                 __u8 opcode;
102         } __packed c;
103 };
104
105 #define I2C_HID_CMD(opcode_) \
106         .opcode = opcode_, .length = 4, \
107         .registerIndex = offsetof(struct i2c_hid_desc, wCommandRegister)
108
109 /* fetch HID descriptor */
110 static const struct i2c_hid_cmd hid_descr_cmd = { .length = 2 };
111 /* fetch report descriptors */
112 static const struct i2c_hid_cmd hid_report_descr_cmd = {
113                 .registerIndex = offsetof(struct i2c_hid_desc,
114                         wReportDescRegister),
115                 .opcode = 0x00,
116                 .length = 2 };
117 /* commands */
118 static const struct i2c_hid_cmd hid_reset_cmd =         { I2C_HID_CMD(0x01),
119                                                           .wait = true };
120 static const struct i2c_hid_cmd hid_get_report_cmd =    { I2C_HID_CMD(0x02) };
121 static const struct i2c_hid_cmd hid_set_report_cmd =    { I2C_HID_CMD(0x03) };
122 static const struct i2c_hid_cmd hid_set_power_cmd =     { I2C_HID_CMD(0x08) };
123 static const struct i2c_hid_cmd hid_no_cmd =            { .length = 0 };
124
125 /*
126  * These definitions are not used here, but are defined by the spec.
127  * Keeping them here for documentation purposes.
128  *
129  * static const struct i2c_hid_cmd hid_get_idle_cmd = { I2C_HID_CMD(0x04) };
130  * static const struct i2c_hid_cmd hid_set_idle_cmd = { I2C_HID_CMD(0x05) };
131  * static const struct i2c_hid_cmd hid_get_protocol_cmd = { I2C_HID_CMD(0x06) };
132  * static const struct i2c_hid_cmd hid_set_protocol_cmd = { I2C_HID_CMD(0x07) };
133  */
134
135 /* The main device structure */
136 struct i2c_hid {
137         struct i2c_client       *client;        /* i2c client */
138         struct hid_device       *hid;   /* pointer to corresponding HID dev */
139         union {
140                 __u8 hdesc_buffer[sizeof(struct i2c_hid_desc)];
141                 struct i2c_hid_desc hdesc;      /* the HID Descriptor */
142         };
143         __le16                  wHIDDescRegister; /* location of the i2c
144                                                    * register of the HID
145                                                    * descriptor. */
146         unsigned int            bufsize;        /* i2c buffer size */
147         u8                      *inbuf;         /* Input buffer */
148         u8                      *rawbuf;        /* Raw Input buffer */
149         u8                      *cmdbuf;        /* Command buffer */
150         u8                      *argsbuf;       /* Command arguments buffer */
151
152         unsigned long           flags;          /* device flags */
153         unsigned long           quirks;         /* Various quirks */
154
155         wait_queue_head_t       wait;           /* For waiting the interrupt */
156
157         struct i2c_hid_platform_data pdata;
158
159         bool                    irq_wake_enabled;
160         struct mutex            reset_lock;
161 };
162
163 static const struct i2c_hid_quirks {
164         __u16 idVendor;
165         __u16 idProduct;
166         __u32 quirks;
167 } i2c_hid_quirks[] = {
168         { USB_VENDOR_ID_WEIDA, USB_DEVICE_ID_WEIDA_8752,
169                 I2C_HID_QUIRK_SET_PWR_WAKEUP_DEV },
170         { USB_VENDOR_ID_WEIDA, USB_DEVICE_ID_WEIDA_8755,
171                 I2C_HID_QUIRK_SET_PWR_WAKEUP_DEV },
172         { I2C_VENDOR_ID_HANTICK, I2C_PRODUCT_ID_HANTICK_5288,
173                 I2C_HID_QUIRK_NO_IRQ_AFTER_RESET },
174         { USB_VENDOR_ID_SIS_TOUCH, USB_DEVICE_ID_SIS10FB_TOUCH,
175                 I2C_HID_QUIRK_RESEND_REPORT_DESCR },
176         { 0, 0 }
177 };
178
179 /*
180  * i2c_hid_lookup_quirk: return any quirks associated with a I2C HID device
181  * @idVendor: the 16-bit vendor ID
182  * @idProduct: the 16-bit product ID
183  *
184  * Returns: a u32 quirks value.
185  */
186 static u32 i2c_hid_lookup_quirk(const u16 idVendor, const u16 idProduct)
187 {
188         u32 quirks = 0;
189         int n;
190
191         for (n = 0; i2c_hid_quirks[n].idVendor; n++)
192                 if (i2c_hid_quirks[n].idVendor == idVendor &&
193                     (i2c_hid_quirks[n].idProduct == (__u16)HID_ANY_ID ||
194                      i2c_hid_quirks[n].idProduct == idProduct))
195                         quirks = i2c_hid_quirks[n].quirks;
196
197         return quirks;
198 }
199
200 static int __i2c_hid_command(struct i2c_client *client,
201                 const struct i2c_hid_cmd *command, u8 reportID,
202                 u8 reportType, u8 *args, int args_len,
203                 unsigned char *buf_recv, int data_len)
204 {
205         struct i2c_hid *ihid = i2c_get_clientdata(client);
206         union command *cmd = (union command *)ihid->cmdbuf;
207         int ret;
208         struct i2c_msg msg[2];
209         int msg_num = 1;
210
211         int length = command->length;
212         bool wait = command->wait;
213         unsigned int registerIndex = command->registerIndex;
214
215         /* special case for hid_descr_cmd */
216         if (command == &hid_descr_cmd) {
217                 cmd->c.reg = ihid->wHIDDescRegister;
218         } else {
219                 cmd->data[0] = ihid->hdesc_buffer[registerIndex];
220                 cmd->data[1] = ihid->hdesc_buffer[registerIndex + 1];
221         }
222
223         if (length > 2) {
224                 cmd->c.opcode = command->opcode;
225                 cmd->c.reportTypeID = reportID | reportType << 4;
226         }
227
228         memcpy(cmd->data + length, args, args_len);
229         length += args_len;
230
231         i2c_hid_dbg(ihid, "%s: cmd=%*ph\n", __func__, length, cmd->data);
232
233         msg[0].addr = client->addr;
234         msg[0].flags = client->flags & I2C_M_TEN;
235         msg[0].len = length;
236         msg[0].buf = cmd->data;
237         if (data_len > 0) {
238                 msg[1].addr = client->addr;
239                 msg[1].flags = client->flags & I2C_M_TEN;
240                 msg[1].flags |= I2C_M_RD;
241                 msg[1].len = data_len;
242                 msg[1].buf = buf_recv;
243                 msg_num = 2;
244                 set_bit(I2C_HID_READ_PENDING, &ihid->flags);
245         }
246
247         if (wait)
248                 set_bit(I2C_HID_RESET_PENDING, &ihid->flags);
249
250         ret = i2c_transfer(client->adapter, msg, msg_num);
251
252         if (data_len > 0)
253                 clear_bit(I2C_HID_READ_PENDING, &ihid->flags);
254
255         if (ret != msg_num)
256                 return ret < 0 ? ret : -EIO;
257
258         ret = 0;
259
260         if (wait && (ihid->quirks & I2C_HID_QUIRK_NO_IRQ_AFTER_RESET)) {
261                 msleep(100);
262         } else if (wait) {
263                 i2c_hid_dbg(ihid, "%s: waiting...\n", __func__);
264                 if (!wait_event_timeout(ihid->wait,
265                                 !test_bit(I2C_HID_RESET_PENDING, &ihid->flags),
266                                 msecs_to_jiffies(5000)))
267                         ret = -ENODATA;
268                 i2c_hid_dbg(ihid, "%s: finished.\n", __func__);
269         }
270
271         return ret;
272 }
273
274 static int i2c_hid_command(struct i2c_client *client,
275                 const struct i2c_hid_cmd *command,
276                 unsigned char *buf_recv, int data_len)
277 {
278         return __i2c_hid_command(client, command, 0, 0, NULL, 0,
279                                 buf_recv, data_len);
280 }
281
282 static int i2c_hid_get_report(struct i2c_client *client, u8 reportType,
283                 u8 reportID, unsigned char *buf_recv, int data_len)
284 {
285         struct i2c_hid *ihid = i2c_get_clientdata(client);
286         u8 args[3];
287         int ret;
288         int args_len = 0;
289         u16 readRegister = le16_to_cpu(ihid->hdesc.wDataRegister);
290
291         i2c_hid_dbg(ihid, "%s\n", __func__);
292
293         if (reportID >= 0x0F) {
294                 args[args_len++] = reportID;
295                 reportID = 0x0F;
296         }
297
298         args[args_len++] = readRegister & 0xFF;
299         args[args_len++] = readRegister >> 8;
300
301         ret = __i2c_hid_command(client, &hid_get_report_cmd, reportID,
302                 reportType, args, args_len, buf_recv, data_len);
303         if (ret) {
304                 dev_err(&client->dev,
305                         "failed to retrieve report from device.\n");
306                 return ret;
307         }
308
309         return 0;
310 }
311
312 /**
313  * i2c_hid_set_or_send_report: forward an incoming report to the device
314  * @client: the i2c_client of the device
315  * @reportType: 0x03 for HID_FEATURE_REPORT ; 0x02 for HID_OUTPUT_REPORT
316  * @reportID: the report ID
317  * @buf: the actual data to transfer, without the report ID
318  * @len: size of buf
319  * @use_data: true: use SET_REPORT HID command, false: send plain OUTPUT report
320  */
321 static int i2c_hid_set_or_send_report(struct i2c_client *client, u8 reportType,
322                 u8 reportID, unsigned char *buf, size_t data_len, bool use_data)
323 {
324         struct i2c_hid *ihid = i2c_get_clientdata(client);
325         u8 *args = ihid->argsbuf;
326         const struct i2c_hid_cmd *hidcmd;
327         int ret;
328         u16 dataRegister = le16_to_cpu(ihid->hdesc.wDataRegister);
329         u16 outputRegister = le16_to_cpu(ihid->hdesc.wOutputRegister);
330         u16 maxOutputLength = le16_to_cpu(ihid->hdesc.wMaxOutputLength);
331         u16 size;
332         int args_len;
333         int index = 0;
334
335         i2c_hid_dbg(ihid, "%s\n", __func__);
336
337         if (data_len > ihid->bufsize)
338                 return -EINVAL;
339
340         size =          2                       /* size */ +
341                         (reportID ? 1 : 0)      /* reportID */ +
342                         data_len                /* buf */;
343         args_len =      (reportID >= 0x0F ? 1 : 0) /* optional third byte */ +
344                         2                       /* dataRegister */ +
345                         size                    /* args */;
346
347         if (!use_data && maxOutputLength == 0)
348                 return -ENOSYS;
349
350         if (reportID >= 0x0F) {
351                 args[index++] = reportID;
352                 reportID = 0x0F;
353         }
354
355         /*
356          * use the data register for feature reports or if the device does not
357          * support the output register
358          */
359         if (use_data) {
360                 args[index++] = dataRegister & 0xFF;
361                 args[index++] = dataRegister >> 8;
362                 hidcmd = &hid_set_report_cmd;
363         } else {
364                 args[index++] = outputRegister & 0xFF;
365                 args[index++] = outputRegister >> 8;
366                 hidcmd = &hid_no_cmd;
367         }
368
369         args[index++] = size & 0xFF;
370         args[index++] = size >> 8;
371
372         if (reportID)
373                 args[index++] = reportID;
374
375         memcpy(&args[index], buf, data_len);
376
377         ret = __i2c_hid_command(client, hidcmd, reportID,
378                 reportType, args, args_len, NULL, 0);
379         if (ret) {
380                 dev_err(&client->dev, "failed to set a report to device.\n");
381                 return ret;
382         }
383
384         return data_len;
385 }
386
387 static int i2c_hid_set_power(struct i2c_client *client, int power_state)
388 {
389         struct i2c_hid *ihid = i2c_get_clientdata(client);
390         int ret;
391
392         i2c_hid_dbg(ihid, "%s\n", __func__);
393
394         /*
395          * Some devices require to send a command to wakeup before power on.
396          * The call will get a return value (EREMOTEIO) but device will be
397          * triggered and activated. After that, it goes like a normal device.
398          */
399         if (power_state == I2C_HID_PWR_ON &&
400             ihid->quirks & I2C_HID_QUIRK_SET_PWR_WAKEUP_DEV) {
401                 ret = i2c_hid_command(client, &hid_set_power_cmd, NULL, 0);
402
403                 /* Device was already activated */
404                 if (!ret)
405                         goto set_pwr_exit;
406         }
407
408         ret = __i2c_hid_command(client, &hid_set_power_cmd, power_state,
409                 0, NULL, 0, NULL, 0);
410
411         if (ret)
412                 dev_err(&client->dev, "failed to change power setting.\n");
413
414 set_pwr_exit:
415         return ret;
416 }
417
418 static int i2c_hid_hwreset(struct i2c_client *client)
419 {
420         struct i2c_hid *ihid = i2c_get_clientdata(client);
421         int ret;
422
423         i2c_hid_dbg(ihid, "%s\n", __func__);
424
425         /*
426          * This prevents sending feature reports while the device is
427          * being reset. Otherwise we may lose the reset complete
428          * interrupt.
429          */
430         mutex_lock(&ihid->reset_lock);
431
432         ret = i2c_hid_set_power(client, I2C_HID_PWR_ON);
433         if (ret)
434                 goto out_unlock;
435
436         /*
437          * The HID over I2C specification states that if a DEVICE needs time
438          * after the PWR_ON request, it should utilise CLOCK stretching.
439          * However, it has been observered that the Windows driver provides a
440          * 1ms sleep between the PWR_ON and RESET requests and that some devices
441          * rely on this.
442          */
443         usleep_range(1000, 5000);
444
445         i2c_hid_dbg(ihid, "resetting...\n");
446
447         ret = i2c_hid_command(client, &hid_reset_cmd, NULL, 0);
448         if (ret) {
449                 dev_err(&client->dev, "failed to reset device.\n");
450                 i2c_hid_set_power(client, I2C_HID_PWR_SLEEP);
451         }
452
453 out_unlock:
454         mutex_unlock(&ihid->reset_lock);
455         return ret;
456 }
457
458 static void i2c_hid_get_input(struct i2c_hid *ihid)
459 {
460         int ret;
461         u32 ret_size;
462         int size = le16_to_cpu(ihid->hdesc.wMaxInputLength);
463
464         if (size > ihid->bufsize)
465                 size = ihid->bufsize;
466
467         ret = i2c_master_recv(ihid->client, ihid->inbuf, size);
468         if (ret != size) {
469                 if (ret < 0)
470                         return;
471
472                 dev_err(&ihid->client->dev, "%s: got %d data instead of %d\n",
473                         __func__, ret, size);
474                 return;
475         }
476
477         ret_size = ihid->inbuf[0] | ihid->inbuf[1] << 8;
478
479         if (!ret_size) {
480                 /* host or device initiated RESET completed */
481                 if (test_and_clear_bit(I2C_HID_RESET_PENDING, &ihid->flags))
482                         wake_up(&ihid->wait);
483                 return;
484         }
485
486         if ((ret_size > size) || (ret_size < 2)) {
487                 dev_err(&ihid->client->dev, "%s: incomplete report (%d/%d)\n",
488                         __func__, size, ret_size);
489                 return;
490         }
491
492         i2c_hid_dbg(ihid, "input: %*ph\n", ret_size, ihid->inbuf);
493
494         if (test_bit(I2C_HID_STARTED, &ihid->flags))
495                 hid_input_report(ihid->hid, HID_INPUT_REPORT, ihid->inbuf + 2,
496                                 ret_size - 2, 1);
497
498         return;
499 }
500
501 static irqreturn_t i2c_hid_irq(int irq, void *dev_id)
502 {
503         struct i2c_hid *ihid = dev_id;
504
505         if (test_bit(I2C_HID_READ_PENDING, &ihid->flags))
506                 return IRQ_HANDLED;
507
508         i2c_hid_get_input(ihid);
509
510         return IRQ_HANDLED;
511 }
512
513 static int i2c_hid_get_report_length(struct hid_report *report)
514 {
515         return ((report->size - 1) >> 3) + 1 +
516                 report->device->report_enum[report->type].numbered + 2;
517 }
518
519 /*
520  * Traverse the supplied list of reports and find the longest
521  */
522 static void i2c_hid_find_max_report(struct hid_device *hid, unsigned int type,
523                 unsigned int *max)
524 {
525         struct hid_report *report;
526         unsigned int size;
527
528         /* We should not rely on wMaxInputLength, as some devices may set it to
529          * a wrong length. */
530         list_for_each_entry(report, &hid->report_enum[type].report_list, list) {
531                 size = i2c_hid_get_report_length(report);
532                 if (*max < size)
533                         *max = size;
534         }
535 }
536
537 static void i2c_hid_free_buffers(struct i2c_hid *ihid)
538 {
539         kfree(ihid->inbuf);
540         kfree(ihid->rawbuf);
541         kfree(ihid->argsbuf);
542         kfree(ihid->cmdbuf);
543         ihid->inbuf = NULL;
544         ihid->rawbuf = NULL;
545         ihid->cmdbuf = NULL;
546         ihid->argsbuf = NULL;
547         ihid->bufsize = 0;
548 }
549
550 static int i2c_hid_alloc_buffers(struct i2c_hid *ihid, size_t report_size)
551 {
552         /* the worst case is computed from the set_report command with a
553          * reportID > 15 and the maximum report length */
554         int args_len = sizeof(__u8) + /* ReportID */
555                        sizeof(__u8) + /* optional ReportID byte */
556                        sizeof(__u16) + /* data register */
557                        sizeof(__u16) + /* size of the report */
558                        report_size; /* report */
559
560         ihid->inbuf = kzalloc(report_size, GFP_KERNEL);
561         ihid->rawbuf = kzalloc(report_size, GFP_KERNEL);
562         ihid->argsbuf = kzalloc(args_len, GFP_KERNEL);
563         ihid->cmdbuf = kzalloc(sizeof(union command) + args_len, GFP_KERNEL);
564
565         if (!ihid->inbuf || !ihid->rawbuf || !ihid->argsbuf || !ihid->cmdbuf) {
566                 i2c_hid_free_buffers(ihid);
567                 return -ENOMEM;
568         }
569
570         ihid->bufsize = report_size;
571
572         return 0;
573 }
574
575 static int i2c_hid_get_raw_report(struct hid_device *hid,
576                 unsigned char report_number, __u8 *buf, size_t count,
577                 unsigned char report_type)
578 {
579         struct i2c_client *client = hid->driver_data;
580         struct i2c_hid *ihid = i2c_get_clientdata(client);
581         size_t ret_count, ask_count;
582         int ret;
583
584         if (report_type == HID_OUTPUT_REPORT)
585                 return -EINVAL;
586
587         /* +2 bytes to include the size of the reply in the query buffer */
588         ask_count = min(count + 2, (size_t)ihid->bufsize);
589
590         ret = i2c_hid_get_report(client,
591                         report_type == HID_FEATURE_REPORT ? 0x03 : 0x01,
592                         report_number, ihid->rawbuf, ask_count);
593
594         if (ret < 0)
595                 return ret;
596
597         ret_count = ihid->rawbuf[0] | (ihid->rawbuf[1] << 8);
598
599         if (ret_count <= 2)
600                 return 0;
601
602         ret_count = min(ret_count, ask_count);
603
604         /* The query buffer contains the size, dropping it in the reply */
605         count = min(count, ret_count - 2);
606         memcpy(buf, ihid->rawbuf + 2, count);
607
608         return count;
609 }
610
611 static int i2c_hid_output_raw_report(struct hid_device *hid, __u8 *buf,
612                 size_t count, unsigned char report_type, bool use_data)
613 {
614         struct i2c_client *client = hid->driver_data;
615         struct i2c_hid *ihid = i2c_get_clientdata(client);
616         int report_id = buf[0];
617         int ret;
618
619         if (report_type == HID_INPUT_REPORT)
620                 return -EINVAL;
621
622         mutex_lock(&ihid->reset_lock);
623
624         if (report_id) {
625                 buf++;
626                 count--;
627         }
628
629         ret = i2c_hid_set_or_send_report(client,
630                                 report_type == HID_FEATURE_REPORT ? 0x03 : 0x02,
631                                 report_id, buf, count, use_data);
632
633         if (report_id && ret >= 0)
634                 ret++; /* add report_id to the number of transfered bytes */
635
636         mutex_unlock(&ihid->reset_lock);
637
638         return ret;
639 }
640
641 static int i2c_hid_output_report(struct hid_device *hid, __u8 *buf,
642                 size_t count)
643 {
644         return i2c_hid_output_raw_report(hid, buf, count, HID_OUTPUT_REPORT,
645                         false);
646 }
647
648 static int i2c_hid_raw_request(struct hid_device *hid, unsigned char reportnum,
649                                __u8 *buf, size_t len, unsigned char rtype,
650                                int reqtype)
651 {
652         switch (reqtype) {
653         case HID_REQ_GET_REPORT:
654                 return i2c_hid_get_raw_report(hid, reportnum, buf, len, rtype);
655         case HID_REQ_SET_REPORT:
656                 if (buf[0] != reportnum)
657                         return -EINVAL;
658                 return i2c_hid_output_raw_report(hid, buf, len, rtype, true);
659         default:
660                 return -EIO;
661         }
662 }
663
664 static int i2c_hid_parse(struct hid_device *hid)
665 {
666         struct i2c_client *client = hid->driver_data;
667         struct i2c_hid *ihid = i2c_get_clientdata(client);
668         struct i2c_hid_desc *hdesc = &ihid->hdesc;
669         unsigned int rsize;
670         char *rdesc;
671         int ret;
672         int tries = 3;
673         char *use_override;
674
675         i2c_hid_dbg(ihid, "entering %s\n", __func__);
676
677         rsize = le16_to_cpu(hdesc->wReportDescLength);
678         if (!rsize || rsize > HID_MAX_DESCRIPTOR_SIZE) {
679                 dbg_hid("weird size of report descriptor (%u)\n", rsize);
680                 return -EINVAL;
681         }
682
683         do {
684                 ret = i2c_hid_hwreset(client);
685                 if (ret)
686                         msleep(1000);
687         } while (tries-- > 0 && ret);
688
689         if (ret)
690                 return ret;
691
692         use_override = i2c_hid_get_dmi_hid_report_desc_override(client->name,
693                                                                 &rsize);
694
695         if (use_override) {
696                 rdesc = use_override;
697                 i2c_hid_dbg(ihid, "Using a HID report descriptor override\n");
698         } else {
699                 rdesc = kzalloc(rsize, GFP_KERNEL);
700
701                 if (!rdesc) {
702                         dbg_hid("couldn't allocate rdesc memory\n");
703                         return -ENOMEM;
704                 }
705
706                 i2c_hid_dbg(ihid, "asking HID report descriptor\n");
707
708                 ret = i2c_hid_command(client, &hid_report_descr_cmd,
709                                       rdesc, rsize);
710                 if (ret) {
711                         hid_err(hid, "reading report descriptor failed\n");
712                         kfree(rdesc);
713                         return -EIO;
714                 }
715         }
716
717         i2c_hid_dbg(ihid, "Report Descriptor: %*ph\n", rsize, rdesc);
718
719         ret = hid_parse_report(hid, rdesc, rsize);
720         if (!use_override)
721                 kfree(rdesc);
722
723         if (ret) {
724                 dbg_hid("parsing report descriptor failed\n");
725                 return ret;
726         }
727
728         return 0;
729 }
730
731 static int i2c_hid_start(struct hid_device *hid)
732 {
733         struct i2c_client *client = hid->driver_data;
734         struct i2c_hid *ihid = i2c_get_clientdata(client);
735         int ret;
736         unsigned int bufsize = HID_MIN_BUFFER_SIZE;
737
738         i2c_hid_find_max_report(hid, HID_INPUT_REPORT, &bufsize);
739         i2c_hid_find_max_report(hid, HID_OUTPUT_REPORT, &bufsize);
740         i2c_hid_find_max_report(hid, HID_FEATURE_REPORT, &bufsize);
741
742         if (bufsize > ihid->bufsize) {
743                 disable_irq(client->irq);
744                 i2c_hid_free_buffers(ihid);
745
746                 ret = i2c_hid_alloc_buffers(ihid, bufsize);
747                 enable_irq(client->irq);
748
749                 if (ret)
750                         return ret;
751         }
752
753         return 0;
754 }
755
756 static void i2c_hid_stop(struct hid_device *hid)
757 {
758         hid->claimed = 0;
759 }
760
761 static int i2c_hid_open(struct hid_device *hid)
762 {
763         struct i2c_client *client = hid->driver_data;
764         struct i2c_hid *ihid = i2c_get_clientdata(client);
765         int ret = 0;
766
767         ret = pm_runtime_get_sync(&client->dev);
768         if (ret < 0)
769                 return ret;
770
771         set_bit(I2C_HID_STARTED, &ihid->flags);
772         return 0;
773 }
774
775 static void i2c_hid_close(struct hid_device *hid)
776 {
777         struct i2c_client *client = hid->driver_data;
778         struct i2c_hid *ihid = i2c_get_clientdata(client);
779
780         clear_bit(I2C_HID_STARTED, &ihid->flags);
781
782         /* Save some power */
783         pm_runtime_put(&client->dev);
784 }
785
786 static int i2c_hid_power(struct hid_device *hid, int lvl)
787 {
788         struct i2c_client *client = hid->driver_data;
789         struct i2c_hid *ihid = i2c_get_clientdata(client);
790
791         i2c_hid_dbg(ihid, "%s lvl:%d\n", __func__, lvl);
792
793         switch (lvl) {
794         case PM_HINT_FULLON:
795                 pm_runtime_get_sync(&client->dev);
796                 break;
797         case PM_HINT_NORMAL:
798                 pm_runtime_put(&client->dev);
799                 break;
800         }
801         return 0;
802 }
803
804 struct hid_ll_driver i2c_hid_ll_driver = {
805         .parse = i2c_hid_parse,
806         .start = i2c_hid_start,
807         .stop = i2c_hid_stop,
808         .open = i2c_hid_open,
809         .close = i2c_hid_close,
810         .power = i2c_hid_power,
811         .output_report = i2c_hid_output_report,
812         .raw_request = i2c_hid_raw_request,
813 };
814 EXPORT_SYMBOL_GPL(i2c_hid_ll_driver);
815
816 static int i2c_hid_init_irq(struct i2c_client *client)
817 {
818         struct i2c_hid *ihid = i2c_get_clientdata(client);
819         unsigned long irqflags = 0;
820         int ret;
821
822         dev_dbg(&client->dev, "Requesting IRQ: %d\n", client->irq);
823
824         if (!irq_get_trigger_type(client->irq))
825                 irqflags = IRQF_TRIGGER_LOW;
826
827         ret = request_threaded_irq(client->irq, NULL, i2c_hid_irq,
828                                    irqflags | IRQF_ONESHOT, client->name, ihid);
829         if (ret < 0) {
830                 dev_warn(&client->dev,
831                         "Could not register for %s interrupt, irq = %d,"
832                         " ret = %d\n",
833                         client->name, client->irq, ret);
834
835                 return ret;
836         }
837
838         return 0;
839 }
840
841 static int i2c_hid_fetch_hid_descriptor(struct i2c_hid *ihid)
842 {
843         struct i2c_client *client = ihid->client;
844         struct i2c_hid_desc *hdesc = &ihid->hdesc;
845         unsigned int dsize;
846         int ret;
847
848         /* i2c hid fetch using a fixed descriptor size (30 bytes) */
849         if (i2c_hid_get_dmi_i2c_hid_desc_override(client->name)) {
850                 i2c_hid_dbg(ihid, "Using a HID descriptor override\n");
851                 ihid->hdesc =
852                         *i2c_hid_get_dmi_i2c_hid_desc_override(client->name);
853         } else {
854                 i2c_hid_dbg(ihid, "Fetching the HID descriptor\n");
855                 ret = i2c_hid_command(client, &hid_descr_cmd,
856                                       ihid->hdesc_buffer,
857                                       sizeof(struct i2c_hid_desc));
858                 if (ret) {
859                         dev_err(&client->dev, "hid_descr_cmd failed\n");
860                         return -ENODEV;
861                 }
862         }
863
864         /* Validate the length of HID descriptor, the 4 first bytes:
865          * bytes 0-1 -> length
866          * bytes 2-3 -> bcdVersion (has to be 1.00) */
867         /* check bcdVersion == 1.0 */
868         if (le16_to_cpu(hdesc->bcdVersion) != 0x0100) {
869                 dev_err(&client->dev,
870                         "unexpected HID descriptor bcdVersion (0x%04hx)\n",
871                         le16_to_cpu(hdesc->bcdVersion));
872                 return -ENODEV;
873         }
874
875         /* Descriptor length should be 30 bytes as per the specification */
876         dsize = le16_to_cpu(hdesc->wHIDDescLength);
877         if (dsize != sizeof(struct i2c_hid_desc)) {
878                 dev_err(&client->dev, "weird size of HID descriptor (%u)\n",
879                         dsize);
880                 return -ENODEV;
881         }
882         i2c_hid_dbg(ihid, "HID Descriptor: %*ph\n", dsize, ihid->hdesc_buffer);
883         return 0;
884 }
885
886 #ifdef CONFIG_ACPI
887 static const struct acpi_device_id i2c_hid_acpi_blacklist[] = {
888         /*
889          * The CHPN0001 ACPI device, which is used to describe the Chipone
890          * ICN8505 controller, has a _CID of PNP0C50 but is not HID compatible.
891          */
892         {"CHPN0001", 0 },
893         { },
894 };
895
896 static int i2c_hid_acpi_pdata(struct i2c_client *client,
897                 struct i2c_hid_platform_data *pdata)
898 {
899         static guid_t i2c_hid_guid =
900                 GUID_INIT(0x3CDFF6F7, 0x4267, 0x4555,
901                           0xAD, 0x05, 0xB3, 0x0A, 0x3D, 0x89, 0x38, 0xDE);
902         union acpi_object *obj;
903         struct acpi_device *adev;
904         acpi_handle handle;
905
906         handle = ACPI_HANDLE(&client->dev);
907         if (!handle || acpi_bus_get_device(handle, &adev)) {
908                 dev_err(&client->dev, "Error could not get ACPI device\n");
909                 return -ENODEV;
910         }
911
912         if (acpi_match_device_ids(adev, i2c_hid_acpi_blacklist) == 0)
913                 return -ENODEV;
914
915         obj = acpi_evaluate_dsm_typed(handle, &i2c_hid_guid, 1, 1, NULL,
916                                       ACPI_TYPE_INTEGER);
917         if (!obj) {
918                 dev_err(&client->dev, "Error _DSM call to get HID descriptor address failed\n");
919                 return -ENODEV;
920         }
921
922         pdata->hid_descriptor_address = obj->integer.value;
923         ACPI_FREE(obj);
924
925         return 0;
926 }
927
928 static void i2c_hid_acpi_fix_up_power(struct device *dev)
929 {
930         struct acpi_device *adev;
931
932         adev = ACPI_COMPANION(dev);
933         if (adev)
934                 acpi_device_fix_up_power(adev);
935 }
936
937 static const struct acpi_device_id i2c_hid_acpi_match[] = {
938         {"ACPI0C50", 0 },
939         {"PNP0C50", 0 },
940         { },
941 };
942 MODULE_DEVICE_TABLE(acpi, i2c_hid_acpi_match);
943 #else
944 static inline int i2c_hid_acpi_pdata(struct i2c_client *client,
945                 struct i2c_hid_platform_data *pdata)
946 {
947         return -ENODEV;
948 }
949
950 static inline void i2c_hid_acpi_fix_up_power(struct device *dev) {}
951 #endif
952
953 #ifdef CONFIG_OF
954 static int i2c_hid_of_probe(struct i2c_client *client,
955                 struct i2c_hid_platform_data *pdata)
956 {
957         struct device *dev = &client->dev;
958         u32 val;
959         int ret;
960
961         ret = of_property_read_u32(dev->of_node, "hid-descr-addr", &val);
962         if (ret) {
963                 dev_err(&client->dev, "HID register address not provided\n");
964                 return -ENODEV;
965         }
966         if (val >> 16) {
967                 dev_err(&client->dev, "Bad HID register address: 0x%08x\n",
968                         val);
969                 return -EINVAL;
970         }
971         pdata->hid_descriptor_address = val;
972
973         return 0;
974 }
975
976 static const struct of_device_id i2c_hid_of_match[] = {
977         { .compatible = "hid-over-i2c" },
978         {},
979 };
980 MODULE_DEVICE_TABLE(of, i2c_hid_of_match);
981 #else
982 static inline int i2c_hid_of_probe(struct i2c_client *client,
983                 struct i2c_hid_platform_data *pdata)
984 {
985         return -ENODEV;
986 }
987 #endif
988
989 static void i2c_hid_fwnode_probe(struct i2c_client *client,
990                                  struct i2c_hid_platform_data *pdata)
991 {
992         u32 val;
993
994         if (!device_property_read_u32(&client->dev, "post-power-on-delay-ms",
995                                       &val))
996                 pdata->post_power_delay_ms = val;
997 }
998
999 static int i2c_hid_probe(struct i2c_client *client,
1000                          const struct i2c_device_id *dev_id)
1001 {
1002         int ret;
1003         struct i2c_hid *ihid;
1004         struct hid_device *hid;
1005         __u16 hidRegister;
1006         struct i2c_hid_platform_data *platform_data = client->dev.platform_data;
1007
1008         dbg_hid("HID probe called for i2c 0x%02x\n", client->addr);
1009
1010         if (!client->irq) {
1011                 dev_err(&client->dev,
1012                         "HID over i2c has not been provided an Int IRQ\n");
1013                 return -EINVAL;
1014         }
1015
1016         if (client->irq < 0) {
1017                 if (client->irq != -EPROBE_DEFER)
1018                         dev_err(&client->dev,
1019                                 "HID over i2c doesn't have a valid IRQ\n");
1020                 return client->irq;
1021         }
1022
1023         ihid = devm_kzalloc(&client->dev, sizeof(*ihid), GFP_KERNEL);
1024         if (!ihid)
1025                 return -ENOMEM;
1026
1027         if (client->dev.of_node) {
1028                 ret = i2c_hid_of_probe(client, &ihid->pdata);
1029                 if (ret)
1030                         return ret;
1031         } else if (!platform_data) {
1032                 ret = i2c_hid_acpi_pdata(client, &ihid->pdata);
1033                 if (ret)
1034                         return ret;
1035         } else {
1036                 ihid->pdata = *platform_data;
1037         }
1038
1039         /* Parse platform agnostic common properties from ACPI / device tree */
1040         i2c_hid_fwnode_probe(client, &ihid->pdata);
1041
1042         ihid->pdata.supplies[0].supply = "vdd";
1043         ihid->pdata.supplies[1].supply = "vddl";
1044
1045         ret = devm_regulator_bulk_get(&client->dev,
1046                                       ARRAY_SIZE(ihid->pdata.supplies),
1047                                       ihid->pdata.supplies);
1048         if (ret)
1049                 return ret;
1050
1051         ret = regulator_bulk_enable(ARRAY_SIZE(ihid->pdata.supplies),
1052                                     ihid->pdata.supplies);
1053         if (ret < 0)
1054                 return ret;
1055
1056         if (ihid->pdata.post_power_delay_ms)
1057                 msleep(ihid->pdata.post_power_delay_ms);
1058
1059         i2c_set_clientdata(client, ihid);
1060
1061         ihid->client = client;
1062
1063         hidRegister = ihid->pdata.hid_descriptor_address;
1064         ihid->wHIDDescRegister = cpu_to_le16(hidRegister);
1065
1066         init_waitqueue_head(&ihid->wait);
1067         mutex_init(&ihid->reset_lock);
1068
1069         /* we need to allocate the command buffer without knowing the maximum
1070          * size of the reports. Let's use HID_MIN_BUFFER_SIZE, then we do the
1071          * real computation later. */
1072         ret = i2c_hid_alloc_buffers(ihid, HID_MIN_BUFFER_SIZE);
1073         if (ret < 0)
1074                 goto err_regulator;
1075
1076         i2c_hid_acpi_fix_up_power(&client->dev);
1077
1078         pm_runtime_get_noresume(&client->dev);
1079         pm_runtime_set_active(&client->dev);
1080         pm_runtime_enable(&client->dev);
1081         device_enable_async_suspend(&client->dev);
1082
1083         /* Make sure there is something at this address */
1084         ret = i2c_smbus_read_byte(client);
1085         if (ret < 0) {
1086                 dev_dbg(&client->dev, "nothing at this address: %d\n", ret);
1087                 ret = -ENXIO;
1088                 goto err_pm;
1089         }
1090
1091         ret = i2c_hid_fetch_hid_descriptor(ihid);
1092         if (ret < 0)
1093                 goto err_pm;
1094
1095         ret = i2c_hid_init_irq(client);
1096         if (ret < 0)
1097                 goto err_pm;
1098
1099         hid = hid_allocate_device();
1100         if (IS_ERR(hid)) {
1101                 ret = PTR_ERR(hid);
1102                 goto err_irq;
1103         }
1104
1105         ihid->hid = hid;
1106
1107         hid->driver_data = client;
1108         hid->ll_driver = &i2c_hid_ll_driver;
1109         hid->dev.parent = &client->dev;
1110         hid->bus = BUS_I2C;
1111         hid->version = le16_to_cpu(ihid->hdesc.bcdVersion);
1112         hid->vendor = le16_to_cpu(ihid->hdesc.wVendorID);
1113         hid->product = le16_to_cpu(ihid->hdesc.wProductID);
1114
1115         snprintf(hid->name, sizeof(hid->name), "%s %04hX:%04hX",
1116                  client->name, hid->vendor, hid->product);
1117         strlcpy(hid->phys, dev_name(&client->dev), sizeof(hid->phys));
1118
1119         ihid->quirks = i2c_hid_lookup_quirk(hid->vendor, hid->product);
1120
1121         ret = hid_add_device(hid);
1122         if (ret) {
1123                 if (ret != -ENODEV)
1124                         hid_err(client, "can't add hid device: %d\n", ret);
1125                 goto err_mem_free;
1126         }
1127
1128         pm_runtime_put(&client->dev);
1129         return 0;
1130
1131 err_mem_free:
1132         hid_destroy_device(hid);
1133
1134 err_irq:
1135         free_irq(client->irq, ihid);
1136
1137 err_pm:
1138         pm_runtime_put_noidle(&client->dev);
1139         pm_runtime_disable(&client->dev);
1140
1141 err_regulator:
1142         regulator_bulk_disable(ARRAY_SIZE(ihid->pdata.supplies),
1143                                ihid->pdata.supplies);
1144         i2c_hid_free_buffers(ihid);
1145         return ret;
1146 }
1147
1148 static int i2c_hid_remove(struct i2c_client *client)
1149 {
1150         struct i2c_hid *ihid = i2c_get_clientdata(client);
1151         struct hid_device *hid;
1152
1153         pm_runtime_get_sync(&client->dev);
1154         pm_runtime_disable(&client->dev);
1155         pm_runtime_set_suspended(&client->dev);
1156         pm_runtime_put_noidle(&client->dev);
1157
1158         hid = ihid->hid;
1159         hid_destroy_device(hid);
1160
1161         free_irq(client->irq, ihid);
1162
1163         if (ihid->bufsize)
1164                 i2c_hid_free_buffers(ihid);
1165
1166         regulator_bulk_disable(ARRAY_SIZE(ihid->pdata.supplies),
1167                                ihid->pdata.supplies);
1168
1169         return 0;
1170 }
1171
1172 static void i2c_hid_shutdown(struct i2c_client *client)
1173 {
1174         struct i2c_hid *ihid = i2c_get_clientdata(client);
1175
1176         i2c_hid_set_power(client, I2C_HID_PWR_SLEEP);
1177         free_irq(client->irq, ihid);
1178 }
1179
1180 #ifdef CONFIG_PM_SLEEP
1181 static int i2c_hid_suspend(struct device *dev)
1182 {
1183         struct i2c_client *client = to_i2c_client(dev);
1184         struct i2c_hid *ihid = i2c_get_clientdata(client);
1185         struct hid_device *hid = ihid->hid;
1186         int ret;
1187         int wake_status;
1188
1189         if (hid->driver && hid->driver->suspend) {
1190                 /*
1191                  * Wake up the device so that IO issues in
1192                  * HID driver's suspend code can succeed.
1193                  */
1194                 ret = pm_runtime_resume(dev);
1195                 if (ret < 0)
1196                         return ret;
1197
1198                 ret = hid->driver->suspend(hid, PMSG_SUSPEND);
1199                 if (ret < 0)
1200                         return ret;
1201         }
1202
1203         if (!pm_runtime_suspended(dev)) {
1204                 /* Save some power */
1205                 i2c_hid_set_power(client, I2C_HID_PWR_SLEEP);
1206
1207                 disable_irq(client->irq);
1208         }
1209
1210         if (device_may_wakeup(&client->dev)) {
1211                 wake_status = enable_irq_wake(client->irq);
1212                 if (!wake_status)
1213                         ihid->irq_wake_enabled = true;
1214                 else
1215                         hid_warn(hid, "Failed to enable irq wake: %d\n",
1216                                 wake_status);
1217         } else {
1218                 regulator_bulk_disable(ARRAY_SIZE(ihid->pdata.supplies),
1219                                        ihid->pdata.supplies);
1220         }
1221
1222         return 0;
1223 }
1224
1225 static int i2c_hid_resume(struct device *dev)
1226 {
1227         int ret;
1228         struct i2c_client *client = to_i2c_client(dev);
1229         struct i2c_hid *ihid = i2c_get_clientdata(client);
1230         struct hid_device *hid = ihid->hid;
1231         int wake_status;
1232
1233         if (!device_may_wakeup(&client->dev)) {
1234                 ret = regulator_bulk_enable(ARRAY_SIZE(ihid->pdata.supplies),
1235                                             ihid->pdata.supplies);
1236                 if (ret)
1237                         hid_warn(hid, "Failed to enable supplies: %d\n", ret);
1238
1239                 if (ihid->pdata.post_power_delay_ms)
1240                         msleep(ihid->pdata.post_power_delay_ms);
1241         } else if (ihid->irq_wake_enabled) {
1242                 wake_status = disable_irq_wake(client->irq);
1243                 if (!wake_status)
1244                         ihid->irq_wake_enabled = false;
1245                 else
1246                         hid_warn(hid, "Failed to disable irq wake: %d\n",
1247                                 wake_status);
1248         }
1249
1250         /* We'll resume to full power */
1251         pm_runtime_disable(dev);
1252         pm_runtime_set_active(dev);
1253         pm_runtime_enable(dev);
1254
1255         enable_irq(client->irq);
1256
1257         /* Instead of resetting device, simply powers the device on. This
1258          * solves "incomplete reports" on Raydium devices 2386:3118 and
1259          * 2386:4B33
1260          */
1261         ret = i2c_hid_set_power(client, I2C_HID_PWR_ON);
1262         if (ret)
1263                 return ret;
1264
1265         /* Some devices need to re-send report descr cmd
1266          * after resume, after this it will be back normal.
1267          * otherwise it issues too many incomplete reports.
1268          */
1269         if (ihid->quirks & I2C_HID_QUIRK_RESEND_REPORT_DESCR) {
1270                 ret = i2c_hid_command(client, &hid_report_descr_cmd, NULL, 0);
1271                 if (ret)
1272                         return ret;
1273         }
1274
1275         if (hid->driver && hid->driver->reset_resume) {
1276                 ret = hid->driver->reset_resume(hid);
1277                 return ret;
1278         }
1279
1280         return 0;
1281 }
1282 #endif
1283
1284 #ifdef CONFIG_PM
1285 static int i2c_hid_runtime_suspend(struct device *dev)
1286 {
1287         struct i2c_client *client = to_i2c_client(dev);
1288
1289         i2c_hid_set_power(client, I2C_HID_PWR_SLEEP);
1290         disable_irq(client->irq);
1291         return 0;
1292 }
1293
1294 static int i2c_hid_runtime_resume(struct device *dev)
1295 {
1296         struct i2c_client *client = to_i2c_client(dev);
1297
1298         enable_irq(client->irq);
1299         i2c_hid_set_power(client, I2C_HID_PWR_ON);
1300         return 0;
1301 }
1302 #endif
1303
1304 static const struct dev_pm_ops i2c_hid_pm = {
1305         SET_SYSTEM_SLEEP_PM_OPS(i2c_hid_suspend, i2c_hid_resume)
1306         SET_RUNTIME_PM_OPS(i2c_hid_runtime_suspend, i2c_hid_runtime_resume,
1307                            NULL)
1308 };
1309
1310 static const struct i2c_device_id i2c_hid_id_table[] = {
1311         { "hid", 0 },
1312         { "hid-over-i2c", 0 },
1313         { },
1314 };
1315 MODULE_DEVICE_TABLE(i2c, i2c_hid_id_table);
1316
1317
1318 static struct i2c_driver i2c_hid_driver = {
1319         .driver = {
1320                 .name   = "i2c_hid",
1321                 .pm     = &i2c_hid_pm,
1322                 .acpi_match_table = ACPI_PTR(i2c_hid_acpi_match),
1323                 .of_match_table = of_match_ptr(i2c_hid_of_match),
1324         },
1325
1326         .probe          = i2c_hid_probe,
1327         .remove         = i2c_hid_remove,
1328         .shutdown       = i2c_hid_shutdown,
1329         .id_table       = i2c_hid_id_table,
1330 };
1331
1332 module_i2c_driver(i2c_hid_driver);
1333
1334 MODULE_DESCRIPTION("HID over I2C core driver");
1335 MODULE_AUTHOR("Benjamin Tissoires <benjamin.tissoires@gmail.com>");
1336 MODULE_LICENSE("GPL");