Lines Matching +full:3 +full:- +full:d

1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2010-2012 by Bruno Prémont <bonbons@linux-vserver.org> *
11 #include <linux/hid-debug.h>
20 #include "hid-picolcd.h"
25 if (picolcd_fbinfo((struct picolcd_data *)f->private)) in picolcd_debug_reset_show()
34 return single_open(f, picolcd_debug_reset_show, inode->i_private); in picolcd_debug_reset_open()
40 struct picolcd_data *data = ((struct seq_file *)f->private_data)->private; in picolcd_debug_reset_write()
42 size_t cnt = min(count, sizeof(buf)-1); in picolcd_debug_reset_write()
44 return -EFAULT; in picolcd_debug_reset_write()
46 while (cnt > 0 && (buf[cnt-1] == ' ' || buf[cnt-1] == '\n')) in picolcd_debug_reset_write()
47 cnt--; in picolcd_debug_reset_write()
50 picolcd_reset(data->hdev); in picolcd_debug_reset_write()
55 return -EINVAL; in picolcd_debug_reset_write()
75 struct picolcd_data *data = f->private_data; in picolcd_debug_eeprom_read()
77 u8 raw_data[3]; in picolcd_debug_eeprom_read()
78 ssize_t ret = -EIO; in picolcd_debug_eeprom_read()
81 return -EINVAL; in picolcd_debug_eeprom_read()
90 raw_data[2] = 0x100 - *off; in picolcd_debug_eeprom_read()
91 resp = picolcd_send_and_wait(data->hdev, REPORT_EE_READ, raw_data, in picolcd_debug_eeprom_read()
94 return -EIO; in picolcd_debug_eeprom_read()
96 if (resp->in_report && resp->in_report->id == REPORT_EE_DATA) { in picolcd_debug_eeprom_read()
98 ret = resp->raw_data[2]; in picolcd_debug_eeprom_read()
101 if (copy_to_user(u, resp->raw_data+3, ret)) in picolcd_debug_eeprom_read()
102 ret = -EFAULT; in picolcd_debug_eeprom_read()
114 struct picolcd_data *data = f->private_data; in picolcd_debug_eeprom_write()
116 ssize_t ret = -EIO; in picolcd_debug_eeprom_write()
120 return -EINVAL; in picolcd_debug_eeprom_write()
122 return -ENOSPC; in picolcd_debug_eeprom_write()
129 raw_data[2] = 0x100 - *off; in picolcd_debug_eeprom_write()
131 if (copy_from_user(raw_data+3, u, min((u8)20, raw_data[2]))) in picolcd_debug_eeprom_write()
132 return -EFAULT; in picolcd_debug_eeprom_write()
133 resp = picolcd_send_and_wait(data->hdev, REPORT_EE_WRITE, raw_data, in picolcd_debug_eeprom_write()
137 return -EIO; in picolcd_debug_eeprom_write()
139 if (resp->in_report && resp->in_report->id == REPORT_EE_DATA) { in picolcd_debug_eeprom_write()
141 if (memcmp(raw_data, resp->raw_data, 3+raw_data[2]) == 0) { in picolcd_debug_eeprom_write()
152 * - read/write happens in chunks of at most 20 bytes, it's up to userspace
154 * - on write errors on otherwise correct write request the bytes
173 if (data->addr_sz == 3) in _picolcd_flash_setaddr()
175 return data->addr_sz == 2 ? 2 : 3; in _picolcd_flash_setaddr()
185 int len_off, err = -EIO; in _picolcd_flash_read()
188 err = -EIO; in _picolcd_flash_read()
191 resp = picolcd_send_and_wait(data->hdev, report_id, raw_data, len_off+1); in _picolcd_flash_read()
192 if (!resp || !resp->in_report) in _picolcd_flash_read()
194 if (resp->in_report->id == REPORT_MEMORY || in _picolcd_flash_read()
195 resp->in_report->id == REPORT_BL_READ_MEMORY) { in _picolcd_flash_read()
196 if (memcmp(raw_data, resp->raw_data, len_off+1) != 0) in _picolcd_flash_read()
198 if (copy_to_user(u+ret, resp->raw_data+len_off+1, raw_data[len_off])) { in _picolcd_flash_read()
199 err = -EFAULT; in _picolcd_flash_read()
203 s -= raw_data[len_off]; in _picolcd_flash_read()
218 struct picolcd_data *data = f->private_data; in picolcd_debug_flash_read()
221 return -EINVAL; in picolcd_debug_flash_read()
225 s = 0x06000 - *off; in picolcd_debug_flash_read()
227 if (data->status & PICOLCD_BOOTLOADER) in picolcd_debug_flash_read()
238 u8 raw_data[3]; in _picolcd_flash_erase64()
240 ssize_t ret = -EIO; in _picolcd_flash_erase64()
243 return -EINVAL; in _picolcd_flash_erase64()
246 resp = picolcd_send_and_wait(data->hdev, report_id, raw_data, len_off); in _picolcd_flash_erase64()
247 if (!resp || !resp->in_report) in _picolcd_flash_erase64()
249 if (resp->in_report->id == REPORT_MEMORY || in _picolcd_flash_erase64()
250 resp->in_report->id == REPORT_BL_ERASE_MEMORY) { in _picolcd_flash_erase64()
251 if (memcmp(raw_data, resp->raw_data, len_off) != 0) in _picolcd_flash_erase64()
267 int len_off, err = -EIO; in _picolcd_flash_write()
270 err = -EIO; in _picolcd_flash_write()
274 err = -EFAULT; in _picolcd_flash_write()
277 resp = picolcd_send_and_wait(data->hdev, report_id, raw_data, in _picolcd_flash_write()
279 if (!resp || !resp->in_report) in _picolcd_flash_write()
281 if (resp->in_report->id == REPORT_MEMORY || in _picolcd_flash_write()
282 resp->in_report->id == REPORT_BL_WRITE_MEMORY) { in _picolcd_flash_write()
283 if (memcmp(raw_data, resp->raw_data, len_off+1+raw_data[len_off]) != 0) in _picolcd_flash_write()
286 s -= raw_data[len_off]; in _picolcd_flash_write()
301 struct picolcd_data *data = f->private_data; in picolcd_debug_flash_write()
306 return -EINVAL; in picolcd_debug_flash_write()
308 return -ENOSPC; in picolcd_debug_flash_write()
310 return -EINVAL; in picolcd_debug_flash_write()
312 return -EINVAL; in picolcd_debug_flash_write()
314 if (data->status & PICOLCD_BOOTLOADER) { in picolcd_debug_flash_write()
321 mutex_lock(&data->mutex_flash); in picolcd_debug_flash_write()
331 s -= err; in picolcd_debug_flash_write()
335 mutex_unlock(&data->mutex_flash); in picolcd_debug_flash_write()
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
345 * otherwise correct write request the next 64-byte block which should
347 * (half-)written with write error)
348 * - reading can happen without special restriction
379 dst[j-1] = '\n'; in dump_buff_as_hex()
381 dst[j-2] = dst[j-3] = '.'; in dump_buff_as_hex()
388 int raw_size = (report->size >> 3) + 1; in picolcd_debug_out_report()
393 if (list_empty(&hdev->debug_list)) in picolcd_debug_out_report()
406 snprintf(buff, BUFF_SZ, "\nout report %d (size %d) = ", in picolcd_debug_out_report()
407 report->id, raw_size); in picolcd_debug_out_report()
409 raw_data[0] = report->id; in picolcd_debug_out_report()
414 switch (report->id) { in picolcd_debug_out_report()
417 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n", in picolcd_debug_out_report()
418 "REPORT_LED_STATE", report->id, raw_size-1); in picolcd_debug_out_report()
425 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n", in picolcd_debug_out_report()
426 "REPORT_BRIGHTNESS", report->id, raw_size-1); in picolcd_debug_out_report()
433 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n", in picolcd_debug_out_report()
434 "REPORT_CONTRAST", report->id, raw_size-1); in picolcd_debug_out_report()
441 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n", in picolcd_debug_out_report()
442 "REPORT_RESET", report->id, raw_size-1); in picolcd_debug_out_report()
450 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n", in picolcd_debug_out_report()
451 "REPORT_LCD_CMD", report->id, raw_size-1); in picolcd_debug_out_report()
457 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n", in picolcd_debug_out_report()
458 "REPORT_LCD_CMD", report->id, raw_size-1); in picolcd_debug_out_report()
464 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n", in picolcd_debug_out_report()
465 "REPORT_LCD_CMD", report->id, raw_size-1); in picolcd_debug_out_report()
470 /* 3 data bytes with read area description */ in picolcd_debug_out_report()
471 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n", in picolcd_debug_out_report()
472 "REPORT_EE_READ", report->id, raw_size-1); in picolcd_debug_out_report()
477 snprintf(buff, BUFF_SZ, "\tData length: %d\n", raw_data[3]); in picolcd_debug_out_report()
481 /* 3+1..20 data bytes with write area description */ in picolcd_debug_out_report()
482 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n", in picolcd_debug_out_report()
483 "REPORT_EE_WRITE", report->id, raw_size-1); in picolcd_debug_out_report()
488 snprintf(buff, BUFF_SZ, "\tData length: %d\n", raw_data[3]); in picolcd_debug_out_report()
490 if (raw_data[3] == 0) { in picolcd_debug_out_report()
492 } else if (raw_data[3] + 4 <= raw_size) { in picolcd_debug_out_report()
495 dump_buff_as_hex(buff, BUFF_SZ, raw_data+4, raw_data[3]); in picolcd_debug_out_report()
503 /* 3 data bytes with pointer inside erase block */ in picolcd_debug_out_report()
504 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n", in picolcd_debug_out_report()
505 "REPORT_ERASE_MEMORY", report->id, raw_size-1); in picolcd_debug_out_report()
507 switch (data->addr_sz) { in picolcd_debug_out_report()
512 case 3: in picolcd_debug_out_report()
514 raw_data[3], raw_data[2], raw_data[1]); in picolcd_debug_out_report()
524 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n", in picolcd_debug_out_report()
525 "REPORT_READ_MEMORY", report->id, raw_size-1); in picolcd_debug_out_report()
527 switch (data->addr_sz) { in picolcd_debug_out_report()
532 snprintf(buff, BUFF_SZ, "\tData length: %d\n", raw_data[3]); in picolcd_debug_out_report()
534 case 3: in picolcd_debug_out_report()
536 raw_data[3], raw_data[2], raw_data[1]); in picolcd_debug_out_report()
538 snprintf(buff, BUFF_SZ, "\tData length: %d\n", raw_data[4]); in picolcd_debug_out_report()
548 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n", in picolcd_debug_out_report()
549 "REPORT_WRITE_MEMORY", report->id, raw_size-1); in picolcd_debug_out_report()
551 switch (data->addr_sz) { in picolcd_debug_out_report()
556 snprintf(buff, BUFF_SZ, "\tData length: %d\n", raw_data[3]); in picolcd_debug_out_report()
558 if (raw_data[3] == 0) { in picolcd_debug_out_report()
560 } else if (raw_data[3] + 4 <= raw_size) { in picolcd_debug_out_report()
563 dump_buff_as_hex(buff, BUFF_SZ, raw_data+4, raw_data[3]); in picolcd_debug_out_report()
568 case 3: in picolcd_debug_out_report()
570 raw_data[3], raw_data[2], raw_data[1]); in picolcd_debug_out_report()
572 snprintf(buff, BUFF_SZ, "\tData length: %d\n", raw_data[4]); in picolcd_debug_out_report()
593 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n", in picolcd_debug_out_report()
594 "REPORT_EXIT_KEYBOARD", report->id, raw_size-1); in picolcd_debug_out_report()
602 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n", in picolcd_debug_out_report()
603 "REPORT_VERSION", report->id, raw_size-1); in picolcd_debug_out_report()
607 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n", in picolcd_debug_out_report()
608 "REPORT_DEVID", report->id, raw_size-1); in picolcd_debug_out_report()
612 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n", in picolcd_debug_out_report()
613 "REPORT_SPLASH_SIZE", report->id, raw_size-1); in picolcd_debug_out_report()
617 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n", in picolcd_debug_out_report()
618 "REPORT_HOOK_VERSION", report->id, raw_size-1); in picolcd_debug_out_report()
622 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n", in picolcd_debug_out_report()
623 "REPORT_VERSION", report->id, raw_size-1); in picolcd_debug_out_report()
631 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n", in picolcd_debug_out_report()
632 "<unknown>", report->id, raw_size-1); in picolcd_debug_out_report()
636 wake_up_interruptible(&hdev->debug_wait); in picolcd_debug_out_report()
649 if (list_empty(&hdev->debug_list)) in picolcd_debug_raw_event()
656 switch (report->id) { in picolcd_debug_raw_event()
659 snprintf(buff, BUFF_SZ, "report %s (%d, size=%d)\n", in picolcd_debug_raw_event()
660 "REPORT_ERROR_CODE", report->id, size-1); in picolcd_debug_raw_event()
672 snprintf(buff, BUFF_SZ, "report %s (%d, size=%d)\n", in picolcd_debug_raw_event()
673 "REPORT_KEY_STATE", report->id, size-1); in picolcd_debug_raw_event()
678 snprintf(buff, BUFF_SZ, "\tOne key pressed: 0x%02x (%d)\n", in picolcd_debug_raw_event()
681 snprintf(buff, BUFF_SZ, "\tTwo keys pressed: 0x%02x (%d), 0x%02x (%d)\n", in picolcd_debug_raw_event()
687 snprintf(buff, BUFF_SZ, "report %s (%d, size=%d)\n", in picolcd_debug_raw_event()
688 "REPORT_IR_DATA", report->id, size-1); in picolcd_debug_raw_event()
694 snprintf(buff, BUFF_SZ, "\tData length: %d\n\tIR Data: ", in picolcd_debug_raw_event()
700 snprintf(buff, BUFF_SZ, "\tOverflowing data length: %d\n", in picolcd_debug_raw_event()
701 raw_data[1]-1); in picolcd_debug_raw_event()
707 snprintf(buff, BUFF_SZ, "report %s (%d, size=%d)\n", in picolcd_debug_raw_event()
708 "REPORT_EE_DATA", report->id, size-1); in picolcd_debug_raw_event()
713 snprintf(buff, BUFF_SZ, "\tData length: %d\n", raw_data[3]); in picolcd_debug_raw_event()
715 if (raw_data[3] == 0) { in picolcd_debug_raw_event()
718 } else if (raw_data[3] + 4 <= size) { in picolcd_debug_raw_event()
721 dump_buff_as_hex(buff, BUFF_SZ, raw_data+4, raw_data[3]); in picolcd_debug_raw_event()
730 snprintf(buff, BUFF_SZ, "report %s (%d, size=%d)\n", in picolcd_debug_raw_event()
731 "REPORT_MEMORY", report->id, size-1); in picolcd_debug_raw_event()
733 switch (data->addr_sz) { in picolcd_debug_raw_event()
738 snprintf(buff, BUFF_SZ, "\tData length: %d\n", raw_data[3]); in picolcd_debug_raw_event()
740 if (raw_data[3] == 0) { in picolcd_debug_raw_event()
742 } else if (raw_data[3] + 4 <= size) { in picolcd_debug_raw_event()
745 dump_buff_as_hex(buff, BUFF_SZ, raw_data+4, raw_data[3]); in picolcd_debug_raw_event()
750 case 3: in picolcd_debug_raw_event()
752 raw_data[3], raw_data[2], raw_data[1]); in picolcd_debug_raw_event()
754 snprintf(buff, BUFF_SZ, "\tData length: %d\n", raw_data[4]); in picolcd_debug_raw_event()
772 snprintf(buff, BUFF_SZ, "report %s (%d, size=%d)\n", in picolcd_debug_raw_event()
773 "REPORT_VERSION", report->id, size-1); in picolcd_debug_raw_event()
775 snprintf(buff, BUFF_SZ, "\tFirmware version: %d.%d\n", in picolcd_debug_raw_event()
780 snprintf(buff, BUFF_SZ, "report %s (%d, size=%d)\n", in picolcd_debug_raw_event()
781 "REPORT_BL_ERASE_MEMORY", report->id, size-1); in picolcd_debug_raw_event()
786 snprintf(buff, BUFF_SZ, "report %s (%d, size=%d)\n", in picolcd_debug_raw_event()
787 "REPORT_BL_READ_MEMORY", report->id, size-1); in picolcd_debug_raw_event()
792 snprintf(buff, BUFF_SZ, "report %s (%d, size=%d)\n", in picolcd_debug_raw_event()
793 "REPORT_BL_WRITE_MEMORY", report->id, size-1); in picolcd_debug_raw_event()
798 snprintf(buff, BUFF_SZ, "report %s (%d, size=%d)\n", in picolcd_debug_raw_event()
799 "REPORT_DEVID", report->id, size-1); in picolcd_debug_raw_event()
802 raw_data[1], raw_data[2], raw_data[3], raw_data[4]); in picolcd_debug_raw_event()
809 snprintf(buff, BUFF_SZ, "report %s (%d, size=%d)\n", in picolcd_debug_raw_event()
810 "REPORT_SPLASH_SIZE", report->id, size-1); in picolcd_debug_raw_event()
812 snprintf(buff, BUFF_SZ, "\tTotal splash space: %d\n", in picolcd_debug_raw_event()
815 snprintf(buff, BUFF_SZ, "\tUsed splash space: %d\n", in picolcd_debug_raw_event()
816 (raw_data[4] << 8) | raw_data[3]); in picolcd_debug_raw_event()
820 snprintf(buff, BUFF_SZ, "report %s (%d, size=%d)\n", in picolcd_debug_raw_event()
821 "REPORT_HOOK_VERSION", report->id, size-1); in picolcd_debug_raw_event()
823 snprintf(buff, BUFF_SZ, "\tFirmware version: %d.%d\n", in picolcd_debug_raw_event()
828 snprintf(buff, BUFF_SZ, "report %s (%d, size=%d)\n", in picolcd_debug_raw_event()
829 "<unknown>", report->id, size-1); in picolcd_debug_raw_event()
833 wake_up_interruptible(&hdev->debug_wait); in picolcd_debug_raw_event()
842 struct hid_device *hdev = data->hdev; in picolcd_init_devfs()
844 mutex_init(&data->mutex_flash); in picolcd_init_devfs()
848 data->debug_reset = debugfs_create_file("reset", 0600, in picolcd_init_devfs()
849 hdev->debug_dir, data, &picolcd_debug_reset_fops); in picolcd_init_devfs()
853 data->debug_eeprom = debugfs_create_file("eeprom", in picolcd_init_devfs()
855 hdev->debug_dir, data, &picolcd_debug_eeprom_fops); in picolcd_init_devfs()
858 if (flash_r && flash_r->maxfield == 1 && flash_r->field[0]->report_size == 8) in picolcd_init_devfs()
859 data->addr_sz = flash_r->field[0]->report_count - 1; in picolcd_init_devfs()
861 data->addr_sz = -1; in picolcd_init_devfs()
862 if (data->addr_sz == 2 || data->addr_sz == 3) { in picolcd_init_devfs()
863 data->debug_flash = debugfs_create_file("flash", in picolcd_init_devfs()
865 hdev->debug_dir, data, &picolcd_debug_flash_fops); in picolcd_init_devfs()
874 dent = data->debug_reset; in picolcd_exit_devfs()
875 data->debug_reset = NULL; in picolcd_exit_devfs()
877 dent = data->debug_eeprom; in picolcd_exit_devfs()
878 data->debug_eeprom = NULL; in picolcd_exit_devfs()
880 dent = data->debug_flash; in picolcd_exit_devfs()
881 data->debug_flash = NULL; in picolcd_exit_devfs()
883 mutex_destroy(&data->mutex_flash); in picolcd_exit_devfs()