1 // SPDX-License-Identifier: GPL-2.0-only
2 /***************************************************************************
3 * Copyright (C) 2010-2012 by Bruno Prémont <bonbons@linux-vserver.org> *
5 * Based on Logitech G13 driver (v0.4) *
6 * Copyright (C) 2009 by Rick L. Vinyard, Jr. <rvinyard@cs.nmsu.edu> *
8 ***************************************************************************/
10 #include <linux/hid.h>
11 #include <linux/hid-debug.h>
14 #include <linux/seq_file.h>
15 #include <linux/debugfs.h>
17 #include <linux/module.h>
18 #include <linux/uaccess.h>
20 #include "hid-picolcd.h"
23 static int picolcd_debug_reset_show(struct seq_file *f, void *p)
25 if (picolcd_fbinfo((struct picolcd_data *)f->private))
26 seq_printf(f, "all fb\n");
28 seq_printf(f, "all\n");
32 static int picolcd_debug_reset_open(struct inode *inode, struct file *f)
34 return single_open(f, picolcd_debug_reset_show, inode->i_private);
37 static ssize_t picolcd_debug_reset_write(struct file *f, const char __user *user_buf,
38 size_t count, loff_t *ppos)
40 struct picolcd_data *data = ((struct seq_file *)f->private_data)->private;
42 size_t cnt = min(count, sizeof(buf)-1);
43 if (copy_from_user(buf, user_buf, cnt))
46 while (cnt > 0 && (buf[cnt-1] == ' ' || buf[cnt-1] == '\n'))
49 if (strcmp(buf, "all") == 0) {
50 picolcd_reset(data->hdev);
51 picolcd_fb_reset(data, 1);
52 } else if (strcmp(buf, "fb") == 0) {
53 picolcd_fb_reset(data, 1);
60 static const struct file_operations picolcd_debug_reset_fops = {
62 .open = picolcd_debug_reset_open,
65 .write = picolcd_debug_reset_write,
66 .release = single_release,
72 static ssize_t picolcd_debug_eeprom_read(struct file *f, char __user *u,
73 size_t s, loff_t *off)
75 struct picolcd_data *data = f->private_data;
76 struct picolcd_pending *resp;
85 /* prepare buffer with info about what we want to read (addr & len) */
86 raw_data[0] = *off & 0xff;
87 raw_data[1] = (*off >> 8) & 0xff;
88 raw_data[2] = s < 20 ? s : 20;
89 if (*off + raw_data[2] > 0xff)
90 raw_data[2] = 0x100 - *off;
91 resp = picolcd_send_and_wait(data->hdev, REPORT_EE_READ, raw_data,
96 if (resp->in_report && resp->in_report->id == REPORT_EE_DATA) {
97 /* successful read :) */
98 ret = resp->raw_data[2];
101 if (copy_to_user(u, resp->raw_data+3, ret))
105 } /* anything else is some kind of IO error */
111 static ssize_t picolcd_debug_eeprom_write(struct file *f, const char __user *u,
112 size_t s, loff_t *off)
114 struct picolcd_data *data = f->private_data;
115 struct picolcd_pending *resp;
124 memset(raw_data, 0, sizeof(raw_data));
125 raw_data[0] = *off & 0xff;
126 raw_data[1] = (*off >> 8) & 0xff;
127 raw_data[2] = min_t(size_t, 20, s);
128 if (*off + raw_data[2] > 0xff)
129 raw_data[2] = 0x100 - *off;
131 if (copy_from_user(raw_data+3, u, min((u8)20, raw_data[2])))
133 resp = picolcd_send_and_wait(data->hdev, REPORT_EE_WRITE, raw_data,
139 if (resp->in_report && resp->in_report->id == REPORT_EE_DATA) {
140 /* check if written data matches */
141 if (memcmp(raw_data, resp->raw_data, 3+raw_data[2]) == 0) {
152 * - read/write happens in chunks of at most 20 bytes, it's up to userspace
153 * to loop in order to get more data.
154 * - on write errors on otherwise correct write request the bytes
155 * that should have been written are in undefined state.
157 static const struct file_operations picolcd_debug_eeprom_fops = {
158 .owner = THIS_MODULE,
160 .read = picolcd_debug_eeprom_read,
161 .write = picolcd_debug_eeprom_write,
162 .llseek = generic_file_llseek,
168 /* record a flash address to buf (bounds check to be done by caller) */
169 static int _picolcd_flash_setaddr(struct picolcd_data *data, u8 *buf, long off)
172 buf[1] = (off >> 8) & 0xff;
173 if (data->addr_sz == 3)
174 buf[2] = (off >> 16) & 0xff;
175 return data->addr_sz == 2 ? 2 : 3;
178 /* read a given size of data (bounds check to be done by caller) */
179 static ssize_t _picolcd_flash_read(struct picolcd_data *data, int report_id,
180 char __user *u, size_t s, loff_t *off)
182 struct picolcd_pending *resp;
185 int len_off, err = -EIO;
189 len_off = _picolcd_flash_setaddr(data, raw_data, *off);
190 raw_data[len_off] = s > 32 ? 32 : s;
191 resp = picolcd_send_and_wait(data->hdev, report_id, raw_data, len_off+1);
192 if (!resp || !resp->in_report)
194 if (resp->in_report->id == REPORT_MEMORY ||
195 resp->in_report->id == REPORT_BL_READ_MEMORY) {
196 if (memcmp(raw_data, resp->raw_data, len_off+1) != 0)
198 if (copy_to_user(u+ret, resp->raw_data+len_off+1, raw_data[len_off])) {
202 *off += raw_data[len_off];
203 s -= raw_data[len_off];
204 ret += raw_data[len_off];
210 return ret > 0 ? ret : err;
215 static ssize_t picolcd_debug_flash_read(struct file *f, char __user *u,
216 size_t s, loff_t *off)
218 struct picolcd_data *data = f->private_data;
224 if (*off + s > 0x05fff)
227 if (data->status & PICOLCD_BOOTLOADER)
228 return _picolcd_flash_read(data, REPORT_BL_READ_MEMORY, u, s, off);
230 return _picolcd_flash_read(data, REPORT_READ_MEMORY, u, s, off);
233 /* erase block aligned to 64bytes boundary */
234 static ssize_t _picolcd_flash_erase64(struct picolcd_data *data, int report_id,
237 struct picolcd_pending *resp;
245 len_off = _picolcd_flash_setaddr(data, raw_data, *off);
246 resp = picolcd_send_and_wait(data->hdev, report_id, raw_data, len_off);
247 if (!resp || !resp->in_report)
249 if (resp->in_report->id == REPORT_MEMORY ||
250 resp->in_report->id == REPORT_BL_ERASE_MEMORY) {
251 if (memcmp(raw_data, resp->raw_data, len_off) != 0)
260 /* write a given size of data (bounds check to be done by caller) */
261 static ssize_t _picolcd_flash_write(struct picolcd_data *data, int report_id,
262 const char __user *u, size_t s, loff_t *off)
264 struct picolcd_pending *resp;
267 int len_off, err = -EIO;
271 len_off = _picolcd_flash_setaddr(data, raw_data, *off);
272 raw_data[len_off] = s > 32 ? 32 : s;
273 if (copy_from_user(raw_data+len_off+1, u, raw_data[len_off])) {
277 resp = picolcd_send_and_wait(data->hdev, report_id, raw_data,
278 len_off+1+raw_data[len_off]);
279 if (!resp || !resp->in_report)
281 if (resp->in_report->id == REPORT_MEMORY ||
282 resp->in_report->id == REPORT_BL_WRITE_MEMORY) {
283 if (memcmp(raw_data, resp->raw_data, len_off+1+raw_data[len_off]) != 0)
285 *off += raw_data[len_off];
286 s -= raw_data[len_off];
287 ret += raw_data[len_off];
295 return ret > 0 ? ret : err;
298 static ssize_t picolcd_debug_flash_write(struct file *f, const char __user *u,
299 size_t s, loff_t *off)
301 struct picolcd_data *data = f->private_data;
302 ssize_t err, ret = 0;
303 int report_erase, report_write;
314 if (data->status & PICOLCD_BOOTLOADER) {
315 report_erase = REPORT_BL_ERASE_MEMORY;
316 report_write = REPORT_BL_WRITE_MEMORY;
318 report_erase = REPORT_ERASE_MEMORY;
319 report_write = REPORT_WRITE_MEMORY;
321 mutex_lock(&data->mutex_flash);
323 err = _picolcd_flash_erase64(data, report_erase, off);
326 err = _picolcd_flash_write(data, report_write, u, 64, off);
335 mutex_unlock(&data->mutex_flash);
336 return ret > 0 ? ret : err;
341 * - concurrent writing is prevented by mutex and all writes must be
342 * n*64 bytes and 64-byte aligned, each write being preceded by an
343 * ERASE which erases a 64byte block.
344 * If less than requested was written or an error is returned for an
345 * otherwise correct write request the next 64-byte block which should
346 * have been written is in undefined state (mostly: original, erased,
347 * (half-)written with write error)
348 * - reading can happen without special restriction
350 static const struct file_operations picolcd_debug_flash_fops = {
351 .owner = THIS_MODULE,
353 .read = picolcd_debug_flash_read,
354 .write = picolcd_debug_flash_write,
355 .llseek = generic_file_llseek,
360 * Helper code for HID report level dumping/debugging
362 static const char * const error_codes[] = {
363 "success", "parameter missing", "data_missing", "block readonly",
364 "block not erasable", "block too big", "section overflow",
365 "invalid command length", "invalid data length",
368 static void dump_buff_as_hex(char *dst, size_t dst_sz, const u8 *data,
369 const size_t data_len)
372 for (i = j = 0; i < data_len && j + 4 < dst_sz; i++) {
373 dst[j++] = hex_asc[(data[i] >> 4) & 0x0f];
374 dst[j++] = hex_asc[data[i] & 0x0f];
380 if (i < data_len && j > 2)
381 dst[j-2] = dst[j-3] = '.';
384 void picolcd_debug_out_report(struct picolcd_data *data,
385 struct hid_device *hdev, struct hid_report *report)
388 int raw_size = (report->size >> 3) + 1;
392 /* Avoid unnecessary overhead if debugfs is disabled */
393 if (list_empty(&hdev->debug_list))
396 buff = kmalloc(BUFF_SZ, GFP_ATOMIC);
400 raw_data = hid_alloc_report_buf(report, GFP_ATOMIC);
406 snprintf(buff, BUFF_SZ, "\nout report %d (size %d) = ",
407 report->id, raw_size);
408 hid_debug_event(hdev, buff);
409 raw_data[0] = report->id;
410 hid_output_report(report, raw_data);
411 dump_buff_as_hex(buff, BUFF_SZ, raw_data, raw_size);
412 hid_debug_event(hdev, buff);
414 switch (report->id) {
415 case REPORT_LED_STATE:
416 /* 1 data byte with GPO state */
417 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n",
418 "REPORT_LED_STATE", report->id, raw_size-1);
419 hid_debug_event(hdev, buff);
420 snprintf(buff, BUFF_SZ, "\tGPO state: 0x%02x\n", raw_data[1]);
421 hid_debug_event(hdev, buff);
423 case REPORT_BRIGHTNESS:
424 /* 1 data byte with brightness */
425 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n",
426 "REPORT_BRIGHTNESS", report->id, raw_size-1);
427 hid_debug_event(hdev, buff);
428 snprintf(buff, BUFF_SZ, "\tBrightness: 0x%02x\n", raw_data[1]);
429 hid_debug_event(hdev, buff);
431 case REPORT_CONTRAST:
432 /* 1 data byte with contrast */
433 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n",
434 "REPORT_CONTRAST", report->id, raw_size-1);
435 hid_debug_event(hdev, buff);
436 snprintf(buff, BUFF_SZ, "\tContrast: 0x%02x\n", raw_data[1]);
437 hid_debug_event(hdev, buff);
440 /* 2 data bytes with reset duration in ms */
441 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n",
442 "REPORT_RESET", report->id, raw_size-1);
443 hid_debug_event(hdev, buff);
444 snprintf(buff, BUFF_SZ, "\tDuration: 0x%02x%02x (%dms)\n",
445 raw_data[2], raw_data[1], raw_data[2] << 8 | raw_data[1]);
446 hid_debug_event(hdev, buff);
449 /* 63 data bytes with LCD commands */
450 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n",
451 "REPORT_LCD_CMD", report->id, raw_size-1);
452 hid_debug_event(hdev, buff);
453 /* TODO: format decoding */
455 case REPORT_LCD_DATA:
456 /* 63 data bytes with LCD data */
457 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n",
458 "REPORT_LCD_CMD", report->id, raw_size-1);
459 /* TODO: format decoding */
460 hid_debug_event(hdev, buff);
462 case REPORT_LCD_CMD_DATA:
463 /* 63 data bytes with LCD commands and data */
464 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n",
465 "REPORT_LCD_CMD", report->id, raw_size-1);
466 /* TODO: format decoding */
467 hid_debug_event(hdev, buff);
470 /* 3 data bytes with read area description */
471 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n",
472 "REPORT_EE_READ", report->id, raw_size-1);
473 hid_debug_event(hdev, buff);
474 snprintf(buff, BUFF_SZ, "\tData address: 0x%02x%02x\n",
475 raw_data[2], raw_data[1]);
476 hid_debug_event(hdev, buff);
477 snprintf(buff, BUFF_SZ, "\tData length: %d\n", raw_data[3]);
478 hid_debug_event(hdev, buff);
480 case REPORT_EE_WRITE:
481 /* 3+1..20 data bytes with write area description */
482 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n",
483 "REPORT_EE_WRITE", report->id, raw_size-1);
484 hid_debug_event(hdev, buff);
485 snprintf(buff, BUFF_SZ, "\tData address: 0x%02x%02x\n",
486 raw_data[2], raw_data[1]);
487 hid_debug_event(hdev, buff);
488 snprintf(buff, BUFF_SZ, "\tData length: %d\n", raw_data[3]);
489 hid_debug_event(hdev, buff);
490 if (raw_data[3] == 0) {
491 snprintf(buff, BUFF_SZ, "\tNo data\n");
492 } else if (raw_data[3] + 4 <= raw_size) {
493 snprintf(buff, BUFF_SZ, "\tData: ");
494 hid_debug_event(hdev, buff);
495 dump_buff_as_hex(buff, BUFF_SZ, raw_data+4, raw_data[3]);
497 snprintf(buff, BUFF_SZ, "\tData overflowed\n");
499 hid_debug_event(hdev, buff);
501 case REPORT_ERASE_MEMORY:
502 case REPORT_BL_ERASE_MEMORY:
503 /* 3 data bytes with pointer inside erase block */
504 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n",
505 "REPORT_ERASE_MEMORY", report->id, raw_size-1);
506 hid_debug_event(hdev, buff);
507 switch (data->addr_sz) {
509 snprintf(buff, BUFF_SZ, "\tAddress inside 64 byte block: 0x%02x%02x\n",
510 raw_data[2], raw_data[1]);
513 snprintf(buff, BUFF_SZ, "\tAddress inside 64 byte block: 0x%02x%02x%02x\n",
514 raw_data[3], raw_data[2], raw_data[1]);
517 snprintf(buff, BUFF_SZ, "\tNot supported\n");
519 hid_debug_event(hdev, buff);
521 case REPORT_READ_MEMORY:
522 case REPORT_BL_READ_MEMORY:
523 /* 4 data bytes with read area description */
524 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n",
525 "REPORT_READ_MEMORY", report->id, raw_size-1);
526 hid_debug_event(hdev, buff);
527 switch (data->addr_sz) {
529 snprintf(buff, BUFF_SZ, "\tData address: 0x%02x%02x\n",
530 raw_data[2], raw_data[1]);
531 hid_debug_event(hdev, buff);
532 snprintf(buff, BUFF_SZ, "\tData length: %d\n", raw_data[3]);
535 snprintf(buff, BUFF_SZ, "\tData address: 0x%02x%02x%02x\n",
536 raw_data[3], raw_data[2], raw_data[1]);
537 hid_debug_event(hdev, buff);
538 snprintf(buff, BUFF_SZ, "\tData length: %d\n", raw_data[4]);
541 snprintf(buff, BUFF_SZ, "\tNot supported\n");
543 hid_debug_event(hdev, buff);
545 case REPORT_WRITE_MEMORY:
546 case REPORT_BL_WRITE_MEMORY:
547 /* 4+1..32 data bytes with write adrea description */
548 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n",
549 "REPORT_WRITE_MEMORY", report->id, raw_size-1);
550 hid_debug_event(hdev, buff);
551 switch (data->addr_sz) {
553 snprintf(buff, BUFF_SZ, "\tData address: 0x%02x%02x\n",
554 raw_data[2], raw_data[1]);
555 hid_debug_event(hdev, buff);
556 snprintf(buff, BUFF_SZ, "\tData length: %d\n", raw_data[3]);
557 hid_debug_event(hdev, buff);
558 if (raw_data[3] == 0) {
559 snprintf(buff, BUFF_SZ, "\tNo data\n");
560 } else if (raw_data[3] + 4 <= raw_size) {
561 snprintf(buff, BUFF_SZ, "\tData: ");
562 hid_debug_event(hdev, buff);
563 dump_buff_as_hex(buff, BUFF_SZ, raw_data+4, raw_data[3]);
565 snprintf(buff, BUFF_SZ, "\tData overflowed\n");
569 snprintf(buff, BUFF_SZ, "\tData address: 0x%02x%02x%02x\n",
570 raw_data[3], raw_data[2], raw_data[1]);
571 hid_debug_event(hdev, buff);
572 snprintf(buff, BUFF_SZ, "\tData length: %d\n", raw_data[4]);
573 hid_debug_event(hdev, buff);
574 if (raw_data[4] == 0) {
575 snprintf(buff, BUFF_SZ, "\tNo data\n");
576 } else if (raw_data[4] + 5 <= raw_size) {
577 snprintf(buff, BUFF_SZ, "\tData: ");
578 hid_debug_event(hdev, buff);
579 dump_buff_as_hex(buff, BUFF_SZ, raw_data+5, raw_data[4]);
581 snprintf(buff, BUFF_SZ, "\tData overflowed\n");
585 snprintf(buff, BUFF_SZ, "\tNot supported\n");
587 hid_debug_event(hdev, buff);
589 case REPORT_SPLASH_RESTART:
592 case REPORT_EXIT_KEYBOARD:
593 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n",
594 "REPORT_EXIT_KEYBOARD", report->id, raw_size-1);
595 hid_debug_event(hdev, buff);
596 snprintf(buff, BUFF_SZ, "\tRestart delay: %dms (0x%02x%02x)\n",
597 raw_data[1] | (raw_data[2] << 8),
598 raw_data[2], raw_data[1]);
599 hid_debug_event(hdev, buff);
602 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n",
603 "REPORT_VERSION", report->id, raw_size-1);
604 hid_debug_event(hdev, buff);
607 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n",
608 "REPORT_DEVID", report->id, raw_size-1);
609 hid_debug_event(hdev, buff);
611 case REPORT_SPLASH_SIZE:
612 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n",
613 "REPORT_SPLASH_SIZE", report->id, raw_size-1);
614 hid_debug_event(hdev, buff);
616 case REPORT_HOOK_VERSION:
617 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n",
618 "REPORT_HOOK_VERSION", report->id, raw_size-1);
619 hid_debug_event(hdev, buff);
621 case REPORT_EXIT_FLASHER:
622 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n",
623 "REPORT_VERSION", report->id, raw_size-1);
624 hid_debug_event(hdev, buff);
625 snprintf(buff, BUFF_SZ, "\tRestart delay: %dms (0x%02x%02x)\n",
626 raw_data[1] | (raw_data[2] << 8),
627 raw_data[2], raw_data[1]);
628 hid_debug_event(hdev, buff);
631 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n",
632 "<unknown>", report->id, raw_size-1);
633 hid_debug_event(hdev, buff);
636 wake_up_interruptible(&hdev->debug_wait);
641 void picolcd_debug_raw_event(struct picolcd_data *data,
642 struct hid_device *hdev, struct hid_report *report,
643 u8 *raw_data, int size)
648 /* Avoid unnecessary overhead if debugfs is disabled */
649 if (list_empty(&hdev->debug_list))
652 buff = kmalloc(BUFF_SZ, GFP_ATOMIC);
656 switch (report->id) {
657 case REPORT_ERROR_CODE:
658 /* 2 data bytes with affected report and error code */
659 snprintf(buff, BUFF_SZ, "report %s (%d, size=%d)\n",
660 "REPORT_ERROR_CODE", report->id, size-1);
661 hid_debug_event(hdev, buff);
662 if (raw_data[2] < ARRAY_SIZE(error_codes))
663 snprintf(buff, BUFF_SZ, "\tError code 0x%02x (%s) in reply to report 0x%02x\n",
664 raw_data[2], error_codes[raw_data[2]], raw_data[1]);
666 snprintf(buff, BUFF_SZ, "\tError code 0x%02x in reply to report 0x%02x\n",
667 raw_data[2], raw_data[1]);
668 hid_debug_event(hdev, buff);
670 case REPORT_KEY_STATE:
671 /* 2 data bytes with key state */
672 snprintf(buff, BUFF_SZ, "report %s (%d, size=%d)\n",
673 "REPORT_KEY_STATE", report->id, size-1);
674 hid_debug_event(hdev, buff);
675 if (raw_data[1] == 0)
676 snprintf(buff, BUFF_SZ, "\tNo key pressed\n");
677 else if (raw_data[2] == 0)
678 snprintf(buff, BUFF_SZ, "\tOne key pressed: 0x%02x (%d)\n",
679 raw_data[1], raw_data[1]);
681 snprintf(buff, BUFF_SZ, "\tTwo keys pressed: 0x%02x (%d), 0x%02x (%d)\n",
682 raw_data[1], raw_data[1], raw_data[2], raw_data[2]);
683 hid_debug_event(hdev, buff);
686 /* Up to 20 byes of IR scancode data */
687 snprintf(buff, BUFF_SZ, "report %s (%d, size=%d)\n",
688 "REPORT_IR_DATA", report->id, size-1);
689 hid_debug_event(hdev, buff);
690 if (raw_data[1] == 0) {
691 snprintf(buff, BUFF_SZ, "\tUnexpectedly 0 data length\n");
692 hid_debug_event(hdev, buff);
693 } else if (raw_data[1] + 1 <= size) {
694 snprintf(buff, BUFF_SZ, "\tData length: %d\n\tIR Data: ",
696 hid_debug_event(hdev, buff);
697 dump_buff_as_hex(buff, BUFF_SZ, raw_data+2, raw_data[1]);
698 hid_debug_event(hdev, buff);
700 snprintf(buff, BUFF_SZ, "\tOverflowing data length: %d\n",
702 hid_debug_event(hdev, buff);
706 /* Data buffer in response to REPORT_EE_READ or REPORT_EE_WRITE */
707 snprintf(buff, BUFF_SZ, "report %s (%d, size=%d)\n",
708 "REPORT_EE_DATA", report->id, size-1);
709 hid_debug_event(hdev, buff);
710 snprintf(buff, BUFF_SZ, "\tData address: 0x%02x%02x\n",
711 raw_data[2], raw_data[1]);
712 hid_debug_event(hdev, buff);
713 snprintf(buff, BUFF_SZ, "\tData length: %d\n", raw_data[3]);
714 hid_debug_event(hdev, buff);
715 if (raw_data[3] == 0) {
716 snprintf(buff, BUFF_SZ, "\tNo data\n");
717 hid_debug_event(hdev, buff);
718 } else if (raw_data[3] + 4 <= size) {
719 snprintf(buff, BUFF_SZ, "\tData: ");
720 hid_debug_event(hdev, buff);
721 dump_buff_as_hex(buff, BUFF_SZ, raw_data+4, raw_data[3]);
722 hid_debug_event(hdev, buff);
724 snprintf(buff, BUFF_SZ, "\tData overflowed\n");
725 hid_debug_event(hdev, buff);
729 /* Data buffer in response to REPORT_READ_MEMORY or REPORT_WRITE_MEMORY */
730 snprintf(buff, BUFF_SZ, "report %s (%d, size=%d)\n",
731 "REPORT_MEMORY", report->id, size-1);
732 hid_debug_event(hdev, buff);
733 switch (data->addr_sz) {
735 snprintf(buff, BUFF_SZ, "\tData address: 0x%02x%02x\n",
736 raw_data[2], raw_data[1]);
737 hid_debug_event(hdev, buff);
738 snprintf(buff, BUFF_SZ, "\tData length: %d\n", raw_data[3]);
739 hid_debug_event(hdev, buff);
740 if (raw_data[3] == 0) {
741 snprintf(buff, BUFF_SZ, "\tNo data\n");
742 } else if (raw_data[3] + 4 <= size) {
743 snprintf(buff, BUFF_SZ, "\tData: ");
744 hid_debug_event(hdev, buff);
745 dump_buff_as_hex(buff, BUFF_SZ, raw_data+4, raw_data[3]);
747 snprintf(buff, BUFF_SZ, "\tData overflowed\n");
751 snprintf(buff, BUFF_SZ, "\tData address: 0x%02x%02x%02x\n",
752 raw_data[3], raw_data[2], raw_data[1]);
753 hid_debug_event(hdev, buff);
754 snprintf(buff, BUFF_SZ, "\tData length: %d\n", raw_data[4]);
755 hid_debug_event(hdev, buff);
756 if (raw_data[4] == 0) {
757 snprintf(buff, BUFF_SZ, "\tNo data\n");
758 } else if (raw_data[4] + 5 <= size) {
759 snprintf(buff, BUFF_SZ, "\tData: ");
760 hid_debug_event(hdev, buff);
761 dump_buff_as_hex(buff, BUFF_SZ, raw_data+5, raw_data[4]);
763 snprintf(buff, BUFF_SZ, "\tData overflowed\n");
767 snprintf(buff, BUFF_SZ, "\tNot supported\n");
769 hid_debug_event(hdev, buff);
772 snprintf(buff, BUFF_SZ, "report %s (%d, size=%d)\n",
773 "REPORT_VERSION", report->id, size-1);
774 hid_debug_event(hdev, buff);
775 snprintf(buff, BUFF_SZ, "\tFirmware version: %d.%d\n",
776 raw_data[2], raw_data[1]);
777 hid_debug_event(hdev, buff);
779 case REPORT_BL_ERASE_MEMORY:
780 snprintf(buff, BUFF_SZ, "report %s (%d, size=%d)\n",
781 "REPORT_BL_ERASE_MEMORY", report->id, size-1);
782 hid_debug_event(hdev, buff);
785 case REPORT_BL_READ_MEMORY:
786 snprintf(buff, BUFF_SZ, "report %s (%d, size=%d)\n",
787 "REPORT_BL_READ_MEMORY", report->id, size-1);
788 hid_debug_event(hdev, buff);
791 case REPORT_BL_WRITE_MEMORY:
792 snprintf(buff, BUFF_SZ, "report %s (%d, size=%d)\n",
793 "REPORT_BL_WRITE_MEMORY", report->id, size-1);
794 hid_debug_event(hdev, buff);
798 snprintf(buff, BUFF_SZ, "report %s (%d, size=%d)\n",
799 "REPORT_DEVID", report->id, size-1);
800 hid_debug_event(hdev, buff);
801 snprintf(buff, BUFF_SZ, "\tSerial: 0x%02x%02x%02x%02x\n",
802 raw_data[1], raw_data[2], raw_data[3], raw_data[4]);
803 hid_debug_event(hdev, buff);
804 snprintf(buff, BUFF_SZ, "\tType: 0x%02x\n",
806 hid_debug_event(hdev, buff);
808 case REPORT_SPLASH_SIZE:
809 snprintf(buff, BUFF_SZ, "report %s (%d, size=%d)\n",
810 "REPORT_SPLASH_SIZE", report->id, size-1);
811 hid_debug_event(hdev, buff);
812 snprintf(buff, BUFF_SZ, "\tTotal splash space: %d\n",
813 (raw_data[2] << 8) | raw_data[1]);
814 hid_debug_event(hdev, buff);
815 snprintf(buff, BUFF_SZ, "\tUsed splash space: %d\n",
816 (raw_data[4] << 8) | raw_data[3]);
817 hid_debug_event(hdev, buff);
819 case REPORT_HOOK_VERSION:
820 snprintf(buff, BUFF_SZ, "report %s (%d, size=%d)\n",
821 "REPORT_HOOK_VERSION", report->id, size-1);
822 hid_debug_event(hdev, buff);
823 snprintf(buff, BUFF_SZ, "\tFirmware version: %d.%d\n",
824 raw_data[1], raw_data[2]);
825 hid_debug_event(hdev, buff);
828 snprintf(buff, BUFF_SZ, "report %s (%d, size=%d)\n",
829 "<unknown>", report->id, size-1);
830 hid_debug_event(hdev, buff);
833 wake_up_interruptible(&hdev->debug_wait);
837 void picolcd_init_devfs(struct picolcd_data *data,
838 struct hid_report *eeprom_r, struct hid_report *eeprom_w,
839 struct hid_report *flash_r, struct hid_report *flash_w,
840 struct hid_report *reset)
842 struct hid_device *hdev = data->hdev;
844 mutex_init(&data->mutex_flash);
848 data->debug_reset = debugfs_create_file("reset", 0600,
849 hdev->debug_dir, data, &picolcd_debug_reset_fops);
852 if (eeprom_r || eeprom_w)
853 data->debug_eeprom = debugfs_create_file("eeprom",
854 (eeprom_w ? S_IWUSR : 0) | (eeprom_r ? S_IRUSR : 0),
855 hdev->debug_dir, data, &picolcd_debug_eeprom_fops);
858 if (flash_r && flash_r->maxfield == 1 && flash_r->field[0]->report_size == 8)
859 data->addr_sz = flash_r->field[0]->report_count - 1;
862 if (data->addr_sz == 2 || data->addr_sz == 3) {
863 data->debug_flash = debugfs_create_file("flash",
864 (flash_w ? S_IWUSR : 0) | (flash_r ? S_IRUSR : 0),
865 hdev->debug_dir, data, &picolcd_debug_flash_fops);
866 } else if (flash_r || flash_w)
867 hid_warn(hdev, "Unexpected FLASH access reports, please submit rdesc for review\n");
870 void picolcd_exit_devfs(struct picolcd_data *data)
874 dent = data->debug_reset;
875 data->debug_reset = NULL;
876 debugfs_remove(dent);
877 dent = data->debug_eeprom;
878 data->debug_eeprom = NULL;
879 debugfs_remove(dent);
880 dent = data->debug_flash;
881 data->debug_flash = NULL;
882 debugfs_remove(dent);
883 mutex_destroy(&data->mutex_flash);