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 snprintf(buff, BUFF_SZ, "\nout report %d (size %d) = ",
411 report->id, raw_size);
412 hid_debug_event(hdev, buff);
413 if (raw_size + 5 > sizeof(raw_data)) {
415 hid_debug_event(hdev, " TOO BIG\n");
418 raw_data[0] = report->id;
419 hid_output_report(report, raw_data);
420 dump_buff_as_hex(buff, BUFF_SZ, raw_data, raw_size);
421 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);
650 void picolcd_debug_raw_event(struct picolcd_data *data,
651 struct hid_device *hdev, struct hid_report *report,
652 u8 *raw_data, int size)
657 /* Avoid unnecessary overhead if debugfs is disabled */
658 if (list_empty(&hdev->debug_list))
661 buff = kmalloc(BUFF_SZ, GFP_ATOMIC);
665 switch (report->id) {
666 case REPORT_ERROR_CODE:
667 /* 2 data bytes with affected report and error code */
668 snprintf(buff, BUFF_SZ, "report %s (%d, size=%d)\n",
669 "REPORT_ERROR_CODE", report->id, size-1);
670 hid_debug_event(hdev, buff);
671 if (raw_data[2] < ARRAY_SIZE(error_codes))
672 snprintf(buff, BUFF_SZ, "\tError code 0x%02x (%s) in reply to report 0x%02x\n",
673 raw_data[2], error_codes[raw_data[2]], raw_data[1]);
675 snprintf(buff, BUFF_SZ, "\tError code 0x%02x in reply to report 0x%02x\n",
676 raw_data[2], raw_data[1]);
677 hid_debug_event(hdev, buff);
679 case REPORT_KEY_STATE:
680 /* 2 data bytes with key state */
681 snprintf(buff, BUFF_SZ, "report %s (%d, size=%d)\n",
682 "REPORT_KEY_STATE", report->id, size-1);
683 hid_debug_event(hdev, buff);
684 if (raw_data[1] == 0)
685 snprintf(buff, BUFF_SZ, "\tNo key pressed\n");
686 else if (raw_data[2] == 0)
687 snprintf(buff, BUFF_SZ, "\tOne key pressed: 0x%02x (%d)\n",
688 raw_data[1], raw_data[1]);
690 snprintf(buff, BUFF_SZ, "\tTwo keys pressed: 0x%02x (%d), 0x%02x (%d)\n",
691 raw_data[1], raw_data[1], raw_data[2], raw_data[2]);
692 hid_debug_event(hdev, buff);
695 /* Up to 20 byes of IR scancode data */
696 snprintf(buff, BUFF_SZ, "report %s (%d, size=%d)\n",
697 "REPORT_IR_DATA", report->id, size-1);
698 hid_debug_event(hdev, buff);
699 if (raw_data[1] == 0) {
700 snprintf(buff, BUFF_SZ, "\tUnexpectedly 0 data length\n");
701 hid_debug_event(hdev, buff);
702 } else if (raw_data[1] + 1 <= size) {
703 snprintf(buff, BUFF_SZ, "\tData length: %d\n\tIR Data: ",
705 hid_debug_event(hdev, buff);
706 dump_buff_as_hex(buff, BUFF_SZ, raw_data+2, raw_data[1]);
707 hid_debug_event(hdev, buff);
709 snprintf(buff, BUFF_SZ, "\tOverflowing data length: %d\n",
711 hid_debug_event(hdev, buff);
715 /* Data buffer in response to REPORT_EE_READ or REPORT_EE_WRITE */
716 snprintf(buff, BUFF_SZ, "report %s (%d, size=%d)\n",
717 "REPORT_EE_DATA", report->id, size-1);
718 hid_debug_event(hdev, buff);
719 snprintf(buff, BUFF_SZ, "\tData address: 0x%02x%02x\n",
720 raw_data[2], raw_data[1]);
721 hid_debug_event(hdev, buff);
722 snprintf(buff, BUFF_SZ, "\tData length: %d\n", raw_data[3]);
723 hid_debug_event(hdev, buff);
724 if (raw_data[3] == 0) {
725 snprintf(buff, BUFF_SZ, "\tNo data\n");
726 hid_debug_event(hdev, buff);
727 } else if (raw_data[3] + 4 <= size) {
728 snprintf(buff, BUFF_SZ, "\tData: ");
729 hid_debug_event(hdev, buff);
730 dump_buff_as_hex(buff, BUFF_SZ, raw_data+4, raw_data[3]);
731 hid_debug_event(hdev, buff);
733 snprintf(buff, BUFF_SZ, "\tData overflowed\n");
734 hid_debug_event(hdev, buff);
738 /* Data buffer in response to REPORT_READ_MEMORY or REPORT_WRTIE_MEMORY */
739 snprintf(buff, BUFF_SZ, "report %s (%d, size=%d)\n",
740 "REPORT_MEMORY", report->id, size-1);
741 hid_debug_event(hdev, buff);
742 switch (data->addr_sz) {
744 snprintf(buff, BUFF_SZ, "\tData address: 0x%02x%02x\n",
745 raw_data[2], raw_data[1]);
746 hid_debug_event(hdev, buff);
747 snprintf(buff, BUFF_SZ, "\tData length: %d\n", raw_data[3]);
748 hid_debug_event(hdev, buff);
749 if (raw_data[3] == 0) {
750 snprintf(buff, BUFF_SZ, "\tNo data\n");
751 } else if (raw_data[3] + 4 <= size) {
752 snprintf(buff, BUFF_SZ, "\tData: ");
753 hid_debug_event(hdev, buff);
754 dump_buff_as_hex(buff, BUFF_SZ, raw_data+4, raw_data[3]);
756 snprintf(buff, BUFF_SZ, "\tData overflowed\n");
760 snprintf(buff, BUFF_SZ, "\tData address: 0x%02x%02x%02x\n",
761 raw_data[3], raw_data[2], raw_data[1]);
762 hid_debug_event(hdev, buff);
763 snprintf(buff, BUFF_SZ, "\tData length: %d\n", raw_data[4]);
764 hid_debug_event(hdev, buff);
765 if (raw_data[4] == 0) {
766 snprintf(buff, BUFF_SZ, "\tNo data\n");
767 } else if (raw_data[4] + 5 <= size) {
768 snprintf(buff, BUFF_SZ, "\tData: ");
769 hid_debug_event(hdev, buff);
770 dump_buff_as_hex(buff, BUFF_SZ, raw_data+5, raw_data[4]);
772 snprintf(buff, BUFF_SZ, "\tData overflowed\n");
776 snprintf(buff, BUFF_SZ, "\tNot supported\n");
778 hid_debug_event(hdev, buff);
781 snprintf(buff, BUFF_SZ, "report %s (%d, size=%d)\n",
782 "REPORT_VERSION", report->id, size-1);
783 hid_debug_event(hdev, buff);
784 snprintf(buff, BUFF_SZ, "\tFirmware version: %d.%d\n",
785 raw_data[2], raw_data[1]);
786 hid_debug_event(hdev, buff);
788 case REPORT_BL_ERASE_MEMORY:
789 snprintf(buff, BUFF_SZ, "report %s (%d, size=%d)\n",
790 "REPORT_BL_ERASE_MEMORY", report->id, size-1);
791 hid_debug_event(hdev, buff);
794 case REPORT_BL_READ_MEMORY:
795 snprintf(buff, BUFF_SZ, "report %s (%d, size=%d)\n",
796 "REPORT_BL_READ_MEMORY", report->id, size-1);
797 hid_debug_event(hdev, buff);
800 case REPORT_BL_WRITE_MEMORY:
801 snprintf(buff, BUFF_SZ, "report %s (%d, size=%d)\n",
802 "REPORT_BL_WRITE_MEMORY", report->id, size-1);
803 hid_debug_event(hdev, buff);
807 snprintf(buff, BUFF_SZ, "report %s (%d, size=%d)\n",
808 "REPORT_DEVID", report->id, size-1);
809 hid_debug_event(hdev, buff);
810 snprintf(buff, BUFF_SZ, "\tSerial: 0x%02x%02x%02x%02x\n",
811 raw_data[1], raw_data[2], raw_data[3], raw_data[4]);
812 hid_debug_event(hdev, buff);
813 snprintf(buff, BUFF_SZ, "\tType: 0x%02x\n",
815 hid_debug_event(hdev, buff);
817 case REPORT_SPLASH_SIZE:
818 snprintf(buff, BUFF_SZ, "report %s (%d, size=%d)\n",
819 "REPORT_SPLASH_SIZE", report->id, size-1);
820 hid_debug_event(hdev, buff);
821 snprintf(buff, BUFF_SZ, "\tTotal splash space: %d\n",
822 (raw_data[2] << 8) | raw_data[1]);
823 hid_debug_event(hdev, buff);
824 snprintf(buff, BUFF_SZ, "\tUsed splash space: %d\n",
825 (raw_data[4] << 8) | raw_data[3]);
826 hid_debug_event(hdev, buff);
828 case REPORT_HOOK_VERSION:
829 snprintf(buff, BUFF_SZ, "report %s (%d, size=%d)\n",
830 "REPORT_HOOK_VERSION", report->id, size-1);
831 hid_debug_event(hdev, buff);
832 snprintf(buff, BUFF_SZ, "\tFirmware version: %d.%d\n",
833 raw_data[1], raw_data[2]);
834 hid_debug_event(hdev, buff);
837 snprintf(buff, BUFF_SZ, "report %s (%d, size=%d)\n",
838 "<unknown>", report->id, size-1);
839 hid_debug_event(hdev, buff);
842 wake_up_interruptible(&hdev->debug_wait);
846 void picolcd_init_devfs(struct picolcd_data *data,
847 struct hid_report *eeprom_r, struct hid_report *eeprom_w,
848 struct hid_report *flash_r, struct hid_report *flash_w,
849 struct hid_report *reset)
851 struct hid_device *hdev = data->hdev;
853 mutex_init(&data->mutex_flash);
857 data->debug_reset = debugfs_create_file("reset", 0600,
858 hdev->debug_dir, data, &picolcd_debug_reset_fops);
861 if (eeprom_r || eeprom_w)
862 data->debug_eeprom = debugfs_create_file("eeprom",
863 (eeprom_w ? S_IWUSR : 0) | (eeprom_r ? S_IRUSR : 0),
864 hdev->debug_dir, data, &picolcd_debug_eeprom_fops);
867 if (flash_r && flash_r->maxfield == 1 && flash_r->field[0]->report_size == 8)
868 data->addr_sz = flash_r->field[0]->report_count - 1;
871 if (data->addr_sz == 2 || data->addr_sz == 3) {
872 data->debug_flash = debugfs_create_file("flash",
873 (flash_w ? S_IWUSR : 0) | (flash_r ? S_IRUSR : 0),
874 hdev->debug_dir, data, &picolcd_debug_flash_fops);
875 } else if (flash_r || flash_w)
876 hid_warn(hdev, "Unexpected FLASH access reports, please submit rdesc for review\n");
879 void picolcd_exit_devfs(struct picolcd_data *data)
883 dent = data->debug_reset;
884 data->debug_reset = NULL;
886 debugfs_remove(dent);
887 dent = data->debug_eeprom;
888 data->debug_eeprom = NULL;
890 debugfs_remove(dent);
891 dent = data->debug_flash;
892 data->debug_flash = NULL;
894 debugfs_remove(dent);
895 mutex_destroy(&data->mutex_flash);