1 /***************************************************************************
2 * Copyright (C) 2010-2012 by Bruno Prémont <bonbons@linux-vserver.org> *
4 * Based on Logitech G13 driver (v0.4) *
5 * Copyright (C) 2009 by Rick L. Vinyard, Jr. <rvinyard@cs.nmsu.edu> *
7 * This program is free software: you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation, version 2 of the License. *
11 * This driver is distributed in the hope that it will be useful, but *
12 * WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14 * General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this software. If not see <http://www.gnu.org/licenses/>. *
18 ***************************************************************************/
20 #include <linux/hid.h>
21 #include <linux/hid-debug.h>
24 #include <linux/seq_file.h>
25 #include <linux/debugfs.h>
27 #include <linux/module.h>
28 #include <linux/uaccess.h>
30 #include "hid-picolcd.h"
33 static int picolcd_debug_reset_show(struct seq_file
*f
, void *p
)
35 if (picolcd_fbinfo((struct picolcd_data
*)f
->private))
36 seq_printf(f
, "all fb\n");
38 seq_printf(f
, "all\n");
42 static int picolcd_debug_reset_open(struct inode
*inode
, struct file
*f
)
44 return single_open(f
, picolcd_debug_reset_show
, inode
->i_private
);
47 static ssize_t
picolcd_debug_reset_write(struct file
*f
, const char __user
*user_buf
,
48 size_t count
, loff_t
*ppos
)
50 struct picolcd_data
*data
= ((struct seq_file
*)f
->private_data
)->private;
52 size_t cnt
= min(count
, sizeof(buf
)-1);
53 if (copy_from_user(buf
, user_buf
, cnt
))
56 while (cnt
> 0 && (buf
[cnt
-1] == ' ' || buf
[cnt
-1] == '\n'))
59 if (strcmp(buf
, "all") == 0) {
60 picolcd_reset(data
->hdev
);
61 picolcd_fb_reset(data
, 1);
62 } else if (strcmp(buf
, "fb") == 0) {
63 picolcd_fb_reset(data
, 1);
70 static const struct file_operations picolcd_debug_reset_fops
= {
72 .open
= picolcd_debug_reset_open
,
75 .write
= picolcd_debug_reset_write
,
76 .release
= single_release
,
82 static ssize_t
picolcd_debug_eeprom_read(struct file
*f
, char __user
*u
,
83 size_t s
, loff_t
*off
)
85 struct picolcd_data
*data
= f
->private_data
;
86 struct picolcd_pending
*resp
;
95 /* prepare buffer with info about what we want to read (addr & len) */
96 raw_data
[0] = *off
& 0xff;
97 raw_data
[1] = (*off
>> 8) & 0xff;
98 raw_data
[2] = s
< 20 ? s
: 20;
99 if (*off
+ raw_data
[2] > 0xff)
100 raw_data
[2] = 0x100 - *off
;
101 resp
= picolcd_send_and_wait(data
->hdev
, REPORT_EE_READ
, raw_data
,
106 if (resp
->in_report
&& resp
->in_report
->id
== REPORT_EE_DATA
) {
107 /* successful read :) */
108 ret
= resp
->raw_data
[2];
111 if (copy_to_user(u
, resp
->raw_data
+3, ret
))
115 } /* anything else is some kind of IO error */
121 static ssize_t
picolcd_debug_eeprom_write(struct file
*f
, const char __user
*u
,
122 size_t s
, loff_t
*off
)
124 struct picolcd_data
*data
= f
->private_data
;
125 struct picolcd_pending
*resp
;
134 memset(raw_data
, 0, sizeof(raw_data
));
135 raw_data
[0] = *off
& 0xff;
136 raw_data
[1] = (*off
>> 8) & 0xff;
137 raw_data
[2] = min_t(size_t, 20, s
);
138 if (*off
+ raw_data
[2] > 0xff)
139 raw_data
[2] = 0x100 - *off
;
141 if (copy_from_user(raw_data
+3, u
, min((u8
)20, raw_data
[2])))
143 resp
= picolcd_send_and_wait(data
->hdev
, REPORT_EE_WRITE
, raw_data
,
149 if (resp
->in_report
&& resp
->in_report
->id
== REPORT_EE_DATA
) {
150 /* check if written data matches */
151 if (memcmp(raw_data
, resp
->raw_data
, 3+raw_data
[2]) == 0) {
162 * - read/write happens in chunks of at most 20 bytes, it's up to userspace
163 * to loop in order to get more data.
164 * - on write errors on otherwise correct write request the bytes
165 * that should have been written are in undefined state.
167 static const struct file_operations picolcd_debug_eeprom_fops
= {
168 .owner
= THIS_MODULE
,
170 .read
= picolcd_debug_eeprom_read
,
171 .write
= picolcd_debug_eeprom_write
,
172 .llseek
= generic_file_llseek
,
178 /* record a flash address to buf (bounds check to be done by caller) */
179 static int _picolcd_flash_setaddr(struct picolcd_data
*data
, u8
*buf
, long off
)
182 buf
[1] = (off
>> 8) & 0xff;
183 if (data
->addr_sz
== 3)
184 buf
[2] = (off
>> 16) & 0xff;
185 return data
->addr_sz
== 2 ? 2 : 3;
188 /* read a given size of data (bounds check to be done by caller) */
189 static ssize_t
_picolcd_flash_read(struct picolcd_data
*data
, int report_id
,
190 char __user
*u
, size_t s
, loff_t
*off
)
192 struct picolcd_pending
*resp
;
195 int len_off
, err
= -EIO
;
199 len_off
= _picolcd_flash_setaddr(data
, raw_data
, *off
);
200 raw_data
[len_off
] = s
> 32 ? 32 : s
;
201 resp
= picolcd_send_and_wait(data
->hdev
, report_id
, raw_data
, len_off
+1);
202 if (!resp
|| !resp
->in_report
)
204 if (resp
->in_report
->id
== REPORT_MEMORY
||
205 resp
->in_report
->id
== REPORT_BL_READ_MEMORY
) {
206 if (memcmp(raw_data
, resp
->raw_data
, len_off
+1) != 0)
208 if (copy_to_user(u
+ret
, resp
->raw_data
+len_off
+1, raw_data
[len_off
])) {
212 *off
+= raw_data
[len_off
];
213 s
-= raw_data
[len_off
];
214 ret
+= raw_data
[len_off
];
220 return ret
> 0 ? ret
: err
;
225 static ssize_t
picolcd_debug_flash_read(struct file
*f
, char __user
*u
,
226 size_t s
, loff_t
*off
)
228 struct picolcd_data
*data
= f
->private_data
;
234 if (*off
+ s
> 0x05fff)
237 if (data
->status
& PICOLCD_BOOTLOADER
)
238 return _picolcd_flash_read(data
, REPORT_BL_READ_MEMORY
, u
, s
, off
);
240 return _picolcd_flash_read(data
, REPORT_READ_MEMORY
, u
, s
, off
);
243 /* erase block aligned to 64bytes boundary */
244 static ssize_t
_picolcd_flash_erase64(struct picolcd_data
*data
, int report_id
,
247 struct picolcd_pending
*resp
;
255 len_off
= _picolcd_flash_setaddr(data
, raw_data
, *off
);
256 resp
= picolcd_send_and_wait(data
->hdev
, report_id
, raw_data
, len_off
);
257 if (!resp
|| !resp
->in_report
)
259 if (resp
->in_report
->id
== REPORT_MEMORY
||
260 resp
->in_report
->id
== REPORT_BL_ERASE_MEMORY
) {
261 if (memcmp(raw_data
, resp
->raw_data
, len_off
) != 0)
270 /* write a given size of data (bounds check to be done by caller) */
271 static ssize_t
_picolcd_flash_write(struct picolcd_data
*data
, int report_id
,
272 const char __user
*u
, size_t s
, loff_t
*off
)
274 struct picolcd_pending
*resp
;
277 int len_off
, err
= -EIO
;
281 len_off
= _picolcd_flash_setaddr(data
, raw_data
, *off
);
282 raw_data
[len_off
] = s
> 32 ? 32 : s
;
283 if (copy_from_user(raw_data
+len_off
+1, u
, raw_data
[len_off
])) {
287 resp
= picolcd_send_and_wait(data
->hdev
, report_id
, raw_data
,
288 len_off
+1+raw_data
[len_off
]);
289 if (!resp
|| !resp
->in_report
)
291 if (resp
->in_report
->id
== REPORT_MEMORY
||
292 resp
->in_report
->id
== REPORT_BL_WRITE_MEMORY
) {
293 if (memcmp(raw_data
, resp
->raw_data
, len_off
+1+raw_data
[len_off
]) != 0)
295 *off
+= raw_data
[len_off
];
296 s
-= raw_data
[len_off
];
297 ret
+= raw_data
[len_off
];
305 return ret
> 0 ? ret
: err
;
308 static ssize_t
picolcd_debug_flash_write(struct file
*f
, const char __user
*u
,
309 size_t s
, loff_t
*off
)
311 struct picolcd_data
*data
= f
->private_data
;
312 ssize_t err
, ret
= 0;
313 int report_erase
, report_write
;
324 if (data
->status
& PICOLCD_BOOTLOADER
) {
325 report_erase
= REPORT_BL_ERASE_MEMORY
;
326 report_write
= REPORT_BL_WRITE_MEMORY
;
328 report_erase
= REPORT_ERASE_MEMORY
;
329 report_write
= REPORT_WRITE_MEMORY
;
331 mutex_lock(&data
->mutex_flash
);
333 err
= _picolcd_flash_erase64(data
, report_erase
, off
);
336 err
= _picolcd_flash_write(data
, report_write
, u
, 64, off
);
345 mutex_unlock(&data
->mutex_flash
);
346 return ret
> 0 ? ret
: err
;
351 * - concurrent writing is prevented by mutex and all writes must be
352 * n*64 bytes and 64-byte aligned, each write being preceded by an
353 * ERASE which erases a 64byte block.
354 * If less than requested was written or an error is returned for an
355 * otherwise correct write request the next 64-byte block which should
356 * have been written is in undefined state (mostly: original, erased,
357 * (half-)written with write error)
358 * - reading can happen without special restriction
360 static const struct file_operations picolcd_debug_flash_fops
= {
361 .owner
= THIS_MODULE
,
363 .read
= picolcd_debug_flash_read
,
364 .write
= picolcd_debug_flash_write
,
365 .llseek
= generic_file_llseek
,
370 * Helper code for HID report level dumping/debugging
372 static const char * const error_codes
[] = {
373 "success", "parameter missing", "data_missing", "block readonly",
374 "block not erasable", "block too big", "section overflow",
375 "invalid command length", "invalid data length",
378 static void dump_buff_as_hex(char *dst
, size_t dst_sz
, const u8
*data
,
379 const size_t data_len
)
382 for (i
= j
= 0; i
< data_len
&& j
+ 4 < dst_sz
; i
++) {
383 dst
[j
++] = hex_asc
[(data
[i
] >> 4) & 0x0f];
384 dst
[j
++] = hex_asc
[data
[i
] & 0x0f];
390 if (i
< data_len
&& j
> 2)
391 dst
[j
-2] = dst
[j
-3] = '.';
394 void picolcd_debug_out_report(struct picolcd_data
*data
,
395 struct hid_device
*hdev
, struct hid_report
*report
)
398 int raw_size
= (report
->size
>> 3) + 1;
402 /* Avoid unnecessary overhead if debugfs is disabled */
403 if (list_empty(&hdev
->debug_list
))
406 buff
= kmalloc(BUFF_SZ
, GFP_ATOMIC
);
410 raw_data
= hid_alloc_report_buf(report
, GFP_ATOMIC
);
416 snprintf(buff
, BUFF_SZ
, "\nout report %d (size %d) = ",
417 report
->id
, raw_size
);
418 hid_debug_event(hdev
, buff
);
419 raw_data
[0] = report
->id
;
420 hid_output_report(report
, raw_data
);
421 dump_buff_as_hex(buff
, BUFF_SZ
, raw_data
, raw_size
);
422 hid_debug_event(hdev
, buff
);
424 switch (report
->id
) {
425 case REPORT_LED_STATE
:
426 /* 1 data byte with GPO state */
427 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
428 "REPORT_LED_STATE", report
->id
, raw_size
-1);
429 hid_debug_event(hdev
, buff
);
430 snprintf(buff
, BUFF_SZ
, "\tGPO state: 0x%02x\n", raw_data
[1]);
431 hid_debug_event(hdev
, buff
);
433 case REPORT_BRIGHTNESS
:
434 /* 1 data byte with brightness */
435 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
436 "REPORT_BRIGHTNESS", report
->id
, raw_size
-1);
437 hid_debug_event(hdev
, buff
);
438 snprintf(buff
, BUFF_SZ
, "\tBrightness: 0x%02x\n", raw_data
[1]);
439 hid_debug_event(hdev
, buff
);
441 case REPORT_CONTRAST
:
442 /* 1 data byte with contrast */
443 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
444 "REPORT_CONTRAST", report
->id
, raw_size
-1);
445 hid_debug_event(hdev
, buff
);
446 snprintf(buff
, BUFF_SZ
, "\tContrast: 0x%02x\n", raw_data
[1]);
447 hid_debug_event(hdev
, buff
);
450 /* 2 data bytes with reset duration in ms */
451 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
452 "REPORT_RESET", report
->id
, raw_size
-1);
453 hid_debug_event(hdev
, buff
);
454 snprintf(buff
, BUFF_SZ
, "\tDuration: 0x%02x%02x (%dms)\n",
455 raw_data
[2], raw_data
[1], raw_data
[2] << 8 | raw_data
[1]);
456 hid_debug_event(hdev
, buff
);
459 /* 63 data bytes with LCD commands */
460 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
461 "REPORT_LCD_CMD", report
->id
, raw_size
-1);
462 hid_debug_event(hdev
, buff
);
463 /* TODO: format decoding */
465 case REPORT_LCD_DATA
:
466 /* 63 data bytes with LCD data */
467 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
468 "REPORT_LCD_CMD", report
->id
, raw_size
-1);
469 /* TODO: format decoding */
470 hid_debug_event(hdev
, buff
);
472 case REPORT_LCD_CMD_DATA
:
473 /* 63 data bytes with LCD commands and data */
474 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
475 "REPORT_LCD_CMD", report
->id
, raw_size
-1);
476 /* TODO: format decoding */
477 hid_debug_event(hdev
, buff
);
480 /* 3 data bytes with read area description */
481 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
482 "REPORT_EE_READ", report
->id
, raw_size
-1);
483 hid_debug_event(hdev
, buff
);
484 snprintf(buff
, BUFF_SZ
, "\tData address: 0x%02x%02x\n",
485 raw_data
[2], raw_data
[1]);
486 hid_debug_event(hdev
, buff
);
487 snprintf(buff
, BUFF_SZ
, "\tData length: %d\n", raw_data
[3]);
488 hid_debug_event(hdev
, buff
);
490 case REPORT_EE_WRITE
:
491 /* 3+1..20 data bytes with write area description */
492 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
493 "REPORT_EE_WRITE", report
->id
, raw_size
-1);
494 hid_debug_event(hdev
, buff
);
495 snprintf(buff
, BUFF_SZ
, "\tData address: 0x%02x%02x\n",
496 raw_data
[2], raw_data
[1]);
497 hid_debug_event(hdev
, buff
);
498 snprintf(buff
, BUFF_SZ
, "\tData length: %d\n", raw_data
[3]);
499 hid_debug_event(hdev
, buff
);
500 if (raw_data
[3] == 0) {
501 snprintf(buff
, BUFF_SZ
, "\tNo data\n");
502 } else if (raw_data
[3] + 4 <= raw_size
) {
503 snprintf(buff
, BUFF_SZ
, "\tData: ");
504 hid_debug_event(hdev
, buff
);
505 dump_buff_as_hex(buff
, BUFF_SZ
, raw_data
+4, raw_data
[3]);
507 snprintf(buff
, BUFF_SZ
, "\tData overflowed\n");
509 hid_debug_event(hdev
, buff
);
511 case REPORT_ERASE_MEMORY
:
512 case REPORT_BL_ERASE_MEMORY
:
513 /* 3 data bytes with pointer inside erase block */
514 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
515 "REPORT_ERASE_MEMORY", report
->id
, raw_size
-1);
516 hid_debug_event(hdev
, buff
);
517 switch (data
->addr_sz
) {
519 snprintf(buff
, BUFF_SZ
, "\tAddress inside 64 byte block: 0x%02x%02x\n",
520 raw_data
[2], raw_data
[1]);
523 snprintf(buff
, BUFF_SZ
, "\tAddress inside 64 byte block: 0x%02x%02x%02x\n",
524 raw_data
[3], raw_data
[2], raw_data
[1]);
527 snprintf(buff
, BUFF_SZ
, "\tNot supported\n");
529 hid_debug_event(hdev
, buff
);
531 case REPORT_READ_MEMORY
:
532 case REPORT_BL_READ_MEMORY
:
533 /* 4 data bytes with read area description */
534 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
535 "REPORT_READ_MEMORY", report
->id
, raw_size
-1);
536 hid_debug_event(hdev
, buff
);
537 switch (data
->addr_sz
) {
539 snprintf(buff
, BUFF_SZ
, "\tData address: 0x%02x%02x\n",
540 raw_data
[2], raw_data
[1]);
541 hid_debug_event(hdev
, buff
);
542 snprintf(buff
, BUFF_SZ
, "\tData length: %d\n", raw_data
[3]);
545 snprintf(buff
, BUFF_SZ
, "\tData address: 0x%02x%02x%02x\n",
546 raw_data
[3], raw_data
[2], raw_data
[1]);
547 hid_debug_event(hdev
, buff
);
548 snprintf(buff
, BUFF_SZ
, "\tData length: %d\n", raw_data
[4]);
551 snprintf(buff
, BUFF_SZ
, "\tNot supported\n");
553 hid_debug_event(hdev
, buff
);
555 case REPORT_WRITE_MEMORY
:
556 case REPORT_BL_WRITE_MEMORY
:
557 /* 4+1..32 data bytes with write adrea description */
558 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
559 "REPORT_WRITE_MEMORY", report
->id
, raw_size
-1);
560 hid_debug_event(hdev
, buff
);
561 switch (data
->addr_sz
) {
563 snprintf(buff
, BUFF_SZ
, "\tData address: 0x%02x%02x\n",
564 raw_data
[2], raw_data
[1]);
565 hid_debug_event(hdev
, buff
);
566 snprintf(buff
, BUFF_SZ
, "\tData length: %d\n", raw_data
[3]);
567 hid_debug_event(hdev
, buff
);
568 if (raw_data
[3] == 0) {
569 snprintf(buff
, BUFF_SZ
, "\tNo data\n");
570 } else if (raw_data
[3] + 4 <= raw_size
) {
571 snprintf(buff
, BUFF_SZ
, "\tData: ");
572 hid_debug_event(hdev
, buff
);
573 dump_buff_as_hex(buff
, BUFF_SZ
, raw_data
+4, raw_data
[3]);
575 snprintf(buff
, BUFF_SZ
, "\tData overflowed\n");
579 snprintf(buff
, BUFF_SZ
, "\tData address: 0x%02x%02x%02x\n",
580 raw_data
[3], raw_data
[2], raw_data
[1]);
581 hid_debug_event(hdev
, buff
);
582 snprintf(buff
, BUFF_SZ
, "\tData length: %d\n", raw_data
[4]);
583 hid_debug_event(hdev
, buff
);
584 if (raw_data
[4] == 0) {
585 snprintf(buff
, BUFF_SZ
, "\tNo data\n");
586 } else if (raw_data
[4] + 5 <= raw_size
) {
587 snprintf(buff
, BUFF_SZ
, "\tData: ");
588 hid_debug_event(hdev
, buff
);
589 dump_buff_as_hex(buff
, BUFF_SZ
, raw_data
+5, raw_data
[4]);
591 snprintf(buff
, BUFF_SZ
, "\tData overflowed\n");
595 snprintf(buff
, BUFF_SZ
, "\tNot supported\n");
597 hid_debug_event(hdev
, buff
);
599 case REPORT_SPLASH_RESTART
:
602 case REPORT_EXIT_KEYBOARD
:
603 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
604 "REPORT_EXIT_KEYBOARD", report
->id
, raw_size
-1);
605 hid_debug_event(hdev
, buff
);
606 snprintf(buff
, BUFF_SZ
, "\tRestart delay: %dms (0x%02x%02x)\n",
607 raw_data
[1] | (raw_data
[2] << 8),
608 raw_data
[2], raw_data
[1]);
609 hid_debug_event(hdev
, buff
);
612 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
613 "REPORT_VERSION", report
->id
, raw_size
-1);
614 hid_debug_event(hdev
, buff
);
617 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
618 "REPORT_DEVID", report
->id
, raw_size
-1);
619 hid_debug_event(hdev
, buff
);
621 case REPORT_SPLASH_SIZE
:
622 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
623 "REPORT_SPLASH_SIZE", report
->id
, raw_size
-1);
624 hid_debug_event(hdev
, buff
);
626 case REPORT_HOOK_VERSION
:
627 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
628 "REPORT_HOOK_VERSION", report
->id
, raw_size
-1);
629 hid_debug_event(hdev
, buff
);
631 case REPORT_EXIT_FLASHER
:
632 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
633 "REPORT_VERSION", report
->id
, raw_size
-1);
634 hid_debug_event(hdev
, buff
);
635 snprintf(buff
, BUFF_SZ
, "\tRestart delay: %dms (0x%02x%02x)\n",
636 raw_data
[1] | (raw_data
[2] << 8),
637 raw_data
[2], raw_data
[1]);
638 hid_debug_event(hdev
, buff
);
641 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
642 "<unknown>", report
->id
, raw_size
-1);
643 hid_debug_event(hdev
, buff
);
646 wake_up_interruptible(&hdev
->debug_wait
);
651 void picolcd_debug_raw_event(struct picolcd_data
*data
,
652 struct hid_device
*hdev
, struct hid_report
*report
,
653 u8
*raw_data
, int size
)
658 /* Avoid unnecessary overhead if debugfs is disabled */
659 if (list_empty(&hdev
->debug_list
))
662 buff
= kmalloc(BUFF_SZ
, GFP_ATOMIC
);
666 switch (report
->id
) {
667 case REPORT_ERROR_CODE
:
668 /* 2 data bytes with affected report and error code */
669 snprintf(buff
, BUFF_SZ
, "report %s (%d, size=%d)\n",
670 "REPORT_ERROR_CODE", report
->id
, size
-1);
671 hid_debug_event(hdev
, buff
);
672 if (raw_data
[2] < ARRAY_SIZE(error_codes
))
673 snprintf(buff
, BUFF_SZ
, "\tError code 0x%02x (%s) in reply to report 0x%02x\n",
674 raw_data
[2], error_codes
[raw_data
[2]], raw_data
[1]);
676 snprintf(buff
, BUFF_SZ
, "\tError code 0x%02x in reply to report 0x%02x\n",
677 raw_data
[2], raw_data
[1]);
678 hid_debug_event(hdev
, buff
);
680 case REPORT_KEY_STATE
:
681 /* 2 data bytes with key state */
682 snprintf(buff
, BUFF_SZ
, "report %s (%d, size=%d)\n",
683 "REPORT_KEY_STATE", report
->id
, size
-1);
684 hid_debug_event(hdev
, buff
);
685 if (raw_data
[1] == 0)
686 snprintf(buff
, BUFF_SZ
, "\tNo key pressed\n");
687 else if (raw_data
[2] == 0)
688 snprintf(buff
, BUFF_SZ
, "\tOne key pressed: 0x%02x (%d)\n",
689 raw_data
[1], raw_data
[1]);
691 snprintf(buff
, BUFF_SZ
, "\tTwo keys pressed: 0x%02x (%d), 0x%02x (%d)\n",
692 raw_data
[1], raw_data
[1], raw_data
[2], raw_data
[2]);
693 hid_debug_event(hdev
, buff
);
696 /* Up to 20 byes of IR scancode data */
697 snprintf(buff
, BUFF_SZ
, "report %s (%d, size=%d)\n",
698 "REPORT_IR_DATA", report
->id
, size
-1);
699 hid_debug_event(hdev
, buff
);
700 if (raw_data
[1] == 0) {
701 snprintf(buff
, BUFF_SZ
, "\tUnexpectedly 0 data length\n");
702 hid_debug_event(hdev
, buff
);
703 } else if (raw_data
[1] + 1 <= size
) {
704 snprintf(buff
, BUFF_SZ
, "\tData length: %d\n\tIR Data: ",
706 hid_debug_event(hdev
, buff
);
707 dump_buff_as_hex(buff
, BUFF_SZ
, raw_data
+2, raw_data
[1]);
708 hid_debug_event(hdev
, buff
);
710 snprintf(buff
, BUFF_SZ
, "\tOverflowing data length: %d\n",
712 hid_debug_event(hdev
, buff
);
716 /* Data buffer in response to REPORT_EE_READ or REPORT_EE_WRITE */
717 snprintf(buff
, BUFF_SZ
, "report %s (%d, size=%d)\n",
718 "REPORT_EE_DATA", report
->id
, size
-1);
719 hid_debug_event(hdev
, buff
);
720 snprintf(buff
, BUFF_SZ
, "\tData address: 0x%02x%02x\n",
721 raw_data
[2], raw_data
[1]);
722 hid_debug_event(hdev
, buff
);
723 snprintf(buff
, BUFF_SZ
, "\tData length: %d\n", raw_data
[3]);
724 hid_debug_event(hdev
, buff
);
725 if (raw_data
[3] == 0) {
726 snprintf(buff
, BUFF_SZ
, "\tNo data\n");
727 hid_debug_event(hdev
, buff
);
728 } else if (raw_data
[3] + 4 <= size
) {
729 snprintf(buff
, BUFF_SZ
, "\tData: ");
730 hid_debug_event(hdev
, buff
);
731 dump_buff_as_hex(buff
, BUFF_SZ
, raw_data
+4, raw_data
[3]);
732 hid_debug_event(hdev
, buff
);
734 snprintf(buff
, BUFF_SZ
, "\tData overflowed\n");
735 hid_debug_event(hdev
, buff
);
739 /* Data buffer in response to REPORT_READ_MEMORY or REPORT_WRTIE_MEMORY */
740 snprintf(buff
, BUFF_SZ
, "report %s (%d, size=%d)\n",
741 "REPORT_MEMORY", report
->id
, size
-1);
742 hid_debug_event(hdev
, buff
);
743 switch (data
->addr_sz
) {
745 snprintf(buff
, BUFF_SZ
, "\tData address: 0x%02x%02x\n",
746 raw_data
[2], raw_data
[1]);
747 hid_debug_event(hdev
, buff
);
748 snprintf(buff
, BUFF_SZ
, "\tData length: %d\n", raw_data
[3]);
749 hid_debug_event(hdev
, buff
);
750 if (raw_data
[3] == 0) {
751 snprintf(buff
, BUFF_SZ
, "\tNo data\n");
752 } else if (raw_data
[3] + 4 <= size
) {
753 snprintf(buff
, BUFF_SZ
, "\tData: ");
754 hid_debug_event(hdev
, buff
);
755 dump_buff_as_hex(buff
, BUFF_SZ
, raw_data
+4, raw_data
[3]);
757 snprintf(buff
, BUFF_SZ
, "\tData overflowed\n");
761 snprintf(buff
, BUFF_SZ
, "\tData address: 0x%02x%02x%02x\n",
762 raw_data
[3], raw_data
[2], raw_data
[1]);
763 hid_debug_event(hdev
, buff
);
764 snprintf(buff
, BUFF_SZ
, "\tData length: %d\n", raw_data
[4]);
765 hid_debug_event(hdev
, buff
);
766 if (raw_data
[4] == 0) {
767 snprintf(buff
, BUFF_SZ
, "\tNo data\n");
768 } else if (raw_data
[4] + 5 <= size
) {
769 snprintf(buff
, BUFF_SZ
, "\tData: ");
770 hid_debug_event(hdev
, buff
);
771 dump_buff_as_hex(buff
, BUFF_SZ
, raw_data
+5, raw_data
[4]);
773 snprintf(buff
, BUFF_SZ
, "\tData overflowed\n");
777 snprintf(buff
, BUFF_SZ
, "\tNot supported\n");
779 hid_debug_event(hdev
, buff
);
782 snprintf(buff
, BUFF_SZ
, "report %s (%d, size=%d)\n",
783 "REPORT_VERSION", report
->id
, size
-1);
784 hid_debug_event(hdev
, buff
);
785 snprintf(buff
, BUFF_SZ
, "\tFirmware version: %d.%d\n",
786 raw_data
[2], raw_data
[1]);
787 hid_debug_event(hdev
, buff
);
789 case REPORT_BL_ERASE_MEMORY
:
790 snprintf(buff
, BUFF_SZ
, "report %s (%d, size=%d)\n",
791 "REPORT_BL_ERASE_MEMORY", report
->id
, size
-1);
792 hid_debug_event(hdev
, buff
);
795 case REPORT_BL_READ_MEMORY
:
796 snprintf(buff
, BUFF_SZ
, "report %s (%d, size=%d)\n",
797 "REPORT_BL_READ_MEMORY", report
->id
, size
-1);
798 hid_debug_event(hdev
, buff
);
801 case REPORT_BL_WRITE_MEMORY
:
802 snprintf(buff
, BUFF_SZ
, "report %s (%d, size=%d)\n",
803 "REPORT_BL_WRITE_MEMORY", report
->id
, size
-1);
804 hid_debug_event(hdev
, buff
);
808 snprintf(buff
, BUFF_SZ
, "report %s (%d, size=%d)\n",
809 "REPORT_DEVID", report
->id
, size
-1);
810 hid_debug_event(hdev
, buff
);
811 snprintf(buff
, BUFF_SZ
, "\tSerial: 0x%02x%02x%02x%02x\n",
812 raw_data
[1], raw_data
[2], raw_data
[3], raw_data
[4]);
813 hid_debug_event(hdev
, buff
);
814 snprintf(buff
, BUFF_SZ
, "\tType: 0x%02x\n",
816 hid_debug_event(hdev
, buff
);
818 case REPORT_SPLASH_SIZE
:
819 snprintf(buff
, BUFF_SZ
, "report %s (%d, size=%d)\n",
820 "REPORT_SPLASH_SIZE", report
->id
, size
-1);
821 hid_debug_event(hdev
, buff
);
822 snprintf(buff
, BUFF_SZ
, "\tTotal splash space: %d\n",
823 (raw_data
[2] << 8) | raw_data
[1]);
824 hid_debug_event(hdev
, buff
);
825 snprintf(buff
, BUFF_SZ
, "\tUsed splash space: %d\n",
826 (raw_data
[4] << 8) | raw_data
[3]);
827 hid_debug_event(hdev
, buff
);
829 case REPORT_HOOK_VERSION
:
830 snprintf(buff
, BUFF_SZ
, "report %s (%d, size=%d)\n",
831 "REPORT_HOOK_VERSION", report
->id
, size
-1);
832 hid_debug_event(hdev
, buff
);
833 snprintf(buff
, BUFF_SZ
, "\tFirmware version: %d.%d\n",
834 raw_data
[1], raw_data
[2]);
835 hid_debug_event(hdev
, buff
);
838 snprintf(buff
, BUFF_SZ
, "report %s (%d, size=%d)\n",
839 "<unknown>", report
->id
, size
-1);
840 hid_debug_event(hdev
, buff
);
843 wake_up_interruptible(&hdev
->debug_wait
);
847 void picolcd_init_devfs(struct picolcd_data
*data
,
848 struct hid_report
*eeprom_r
, struct hid_report
*eeprom_w
,
849 struct hid_report
*flash_r
, struct hid_report
*flash_w
,
850 struct hid_report
*reset
)
852 struct hid_device
*hdev
= data
->hdev
;
854 mutex_init(&data
->mutex_flash
);
858 data
->debug_reset
= debugfs_create_file("reset", 0600,
859 hdev
->debug_dir
, data
, &picolcd_debug_reset_fops
);
862 if (eeprom_r
|| eeprom_w
)
863 data
->debug_eeprom
= debugfs_create_file("eeprom",
864 (eeprom_w
? S_IWUSR
: 0) | (eeprom_r
? S_IRUSR
: 0),
865 hdev
->debug_dir
, data
, &picolcd_debug_eeprom_fops
);
868 if (flash_r
&& flash_r
->maxfield
== 1 && flash_r
->field
[0]->report_size
== 8)
869 data
->addr_sz
= flash_r
->field
[0]->report_count
- 1;
872 if (data
->addr_sz
== 2 || data
->addr_sz
== 3) {
873 data
->debug_flash
= debugfs_create_file("flash",
874 (flash_w
? S_IWUSR
: 0) | (flash_r
? S_IRUSR
: 0),
875 hdev
->debug_dir
, data
, &picolcd_debug_flash_fops
);
876 } else if (flash_r
|| flash_w
)
877 hid_warn(hdev
, "Unexpected FLASH access reports, please submit rdesc for review\n");
880 void picolcd_exit_devfs(struct picolcd_data
*data
)
884 dent
= data
->debug_reset
;
885 data
->debug_reset
= NULL
;
886 debugfs_remove(dent
);
887 dent
= data
->debug_eeprom
;
888 data
->debug_eeprom
= NULL
;
889 debugfs_remove(dent
);
890 dent
= data
->debug_flash
;
891 data
->debug_flash
= NULL
;
892 debugfs_remove(dent
);
893 mutex_destroy(&data
->mutex_flash
);