1 /***************************************************************************
2 * Copyright (C) 2010 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>
22 #include <linux/input.h>
24 #include "usbhid/usbhid.h"
25 #include <linux/usb.h>
28 #include <linux/vmalloc.h>
29 #include <linux/backlight.h>
30 #include <linux/lcd.h>
32 #include <linux/leds.h>
34 #include <linux/seq_file.h>
35 #include <linux/debugfs.h>
37 #include <linux/completion.h>
38 #include <linux/uaccess.h>
39 #include <linux/module.h>
41 #define PICOLCD_NAME "PicoLCD (graphic)"
44 #define REPORT_ERROR_CODE 0x10 /* LCD: IN[16] */
45 #define ERR_SUCCESS 0x00
46 #define ERR_PARAMETER_MISSING 0x01
47 #define ERR_DATA_MISSING 0x02
48 #define ERR_BLOCK_READ_ONLY 0x03
49 #define ERR_BLOCK_NOT_ERASABLE 0x04
50 #define ERR_BLOCK_TOO_BIG 0x05
51 #define ERR_SECTION_OVERFLOW 0x06
52 #define ERR_INVALID_CMD_LEN 0x07
53 #define ERR_INVALID_DATA_LEN 0x08
54 #define REPORT_KEY_STATE 0x11 /* LCD: IN[2] */
55 #define REPORT_IR_DATA 0x21 /* LCD: IN[63] */
56 #define REPORT_EE_DATA 0x32 /* LCD: IN[63] */
57 #define REPORT_MEMORY 0x41 /* LCD: IN[63] */
58 #define REPORT_LED_STATE 0x81 /* LCD: OUT[1] */
59 #define REPORT_BRIGHTNESS 0x91 /* LCD: OUT[1] */
60 #define REPORT_CONTRAST 0x92 /* LCD: OUT[1] */
61 #define REPORT_RESET 0x93 /* LCD: OUT[2] */
62 #define REPORT_LCD_CMD 0x94 /* LCD: OUT[63] */
63 #define REPORT_LCD_DATA 0x95 /* LCD: OUT[63] */
64 #define REPORT_LCD_CMD_DATA 0x96 /* LCD: OUT[63] */
65 #define REPORT_EE_READ 0xa3 /* LCD: OUT[63] */
66 #define REPORT_EE_WRITE 0xa4 /* LCD: OUT[63] */
67 #define REPORT_ERASE_MEMORY 0xb2 /* LCD: OUT[2] */
68 #define REPORT_READ_MEMORY 0xb3 /* LCD: OUT[3] */
69 #define REPORT_WRITE_MEMORY 0xb4 /* LCD: OUT[63] */
70 #define REPORT_SPLASH_RESTART 0xc1 /* LCD: OUT[1] */
71 #define REPORT_EXIT_KEYBOARD 0xef /* LCD: OUT[2] */
72 #define REPORT_VERSION 0xf1 /* LCD: IN[2],OUT[1] Bootloader: IN[2],OUT[1] */
73 #define REPORT_BL_ERASE_MEMORY 0xf2 /* Bootloader: IN[36],OUT[4] */
74 #define REPORT_BL_READ_MEMORY 0xf3 /* Bootloader: IN[36],OUT[4] */
75 #define REPORT_BL_WRITE_MEMORY 0xf4 /* Bootloader: IN[36],OUT[36] */
76 #define REPORT_DEVID 0xf5 /* LCD: IN[5], OUT[1] Bootloader: IN[5],OUT[1] */
77 #define REPORT_SPLASH_SIZE 0xf6 /* LCD: IN[4], OUT[1] */
78 #define REPORT_HOOK_VERSION 0xf7 /* LCD: IN[2], OUT[1] */
79 #define REPORT_EXIT_FLASHER 0xff /* Bootloader: OUT[2] */
81 #ifdef CONFIG_HID_PICOLCD_FB
84 * The PicoLCD use a Topway LCD module of 256x64 pixel
85 * This display area is tiled over 4 controllers with 8 tiles
86 * each. Each tile has 8x64 pixel, each data byte representing
87 * a 1-bit wide vertical line of the tile.
89 * The display can be updated at a tile granularity.
91 * Chip 1 Chip 2 Chip 3 Chip 4
92 * +----------------+----------------+----------------+----------------+
93 * | Tile 1 | Tile 1 | Tile 1 | Tile 1 |
94 * +----------------+----------------+----------------+----------------+
95 * | Tile 2 | Tile 2 | Tile 2 | Tile 2 |
96 * +----------------+----------------+----------------+----------------+
98 * +----------------+----------------+----------------+----------------+
99 * | Tile 8 | Tile 8 | Tile 8 | Tile 8 |
100 * +----------------+----------------+----------------+----------------+
102 #define PICOLCDFB_NAME "picolcdfb"
103 #define PICOLCDFB_WIDTH (256)
104 #define PICOLCDFB_HEIGHT (64)
105 #define PICOLCDFB_SIZE (PICOLCDFB_WIDTH * PICOLCDFB_HEIGHT / 8)
107 #define PICOLCDFB_UPDATE_RATE_LIMIT 10
108 #define PICOLCDFB_UPDATE_RATE_DEFAULT 2
110 /* Framebuffer visual structures */
111 static const struct fb_fix_screeninfo picolcdfb_fix
= {
112 .id
= PICOLCDFB_NAME
,
113 .type
= FB_TYPE_PACKED_PIXELS
,
114 .visual
= FB_VISUAL_MONO01
,
118 .line_length
= PICOLCDFB_WIDTH
/ 8,
119 .accel
= FB_ACCEL_NONE
,
122 static const struct fb_var_screeninfo picolcdfb_var
= {
123 .xres
= PICOLCDFB_WIDTH
,
124 .yres
= PICOLCDFB_HEIGHT
,
125 .xres_virtual
= PICOLCDFB_WIDTH
,
126 .yres_virtual
= PICOLCDFB_HEIGHT
,
152 #endif /* CONFIG_HID_PICOLCD_FB */
156 * The PicoLCD has an IR receiver header, a built-in keypad with 5 keys
157 * and header for 4x4 key matrix. The built-in keys are part of the matrix.
159 static const unsigned short def_keymap
[] = {
160 KEY_RESERVED
, /* none */
161 KEY_BACK
, /* col 4 + row 1 */
162 KEY_HOMEPAGE
, /* col 3 + row 1 */
163 KEY_RESERVED
, /* col 2 + row 1 */
164 KEY_RESERVED
, /* col 1 + row 1 */
165 KEY_SCROLLUP
, /* col 4 + row 2 */
166 KEY_OK
, /* col 3 + row 2 */
167 KEY_SCROLLDOWN
, /* col 2 + row 2 */
168 KEY_RESERVED
, /* col 1 + row 2 */
169 KEY_RESERVED
, /* col 4 + row 3 */
170 KEY_RESERVED
, /* col 3 + row 3 */
171 KEY_RESERVED
, /* col 2 + row 3 */
172 KEY_RESERVED
, /* col 1 + row 3 */
173 KEY_RESERVED
, /* col 4 + row 4 */
174 KEY_RESERVED
, /* col 3 + row 4 */
175 KEY_RESERVED
, /* col 2 + row 4 */
176 KEY_RESERVED
, /* col 1 + row 4 */
178 #define PICOLCD_KEYS ARRAY_SIZE(def_keymap)
180 /* Description of in-progress IO operation, used for operations
181 * that trigger response from device */
182 struct picolcd_pending
{
183 struct hid_report
*out_report
;
184 struct hid_report
*in_report
;
185 struct completion ready
;
190 /* Per device data structure */
191 struct picolcd_data
{
192 struct hid_device
*hdev
;
193 #ifdef CONFIG_DEBUG_FS
194 struct dentry
*debug_reset
;
195 struct dentry
*debug_eeprom
;
196 struct dentry
*debug_flash
;
197 struct mutex mutex_flash
;
201 unsigned short opmode_delay
;
204 struct input_dev
*input_keys
;
205 struct input_dev
*input_cir
;
206 unsigned short keycode
[PICOLCD_KEYS
];
208 #ifdef CONFIG_HID_PICOLCD_FB
209 /* Framebuffer stuff */
213 u8
*fb_vbitmap
; /* local copy of what was sent to PicoLCD */
214 u8
*fb_bitmap
; /* framebuffer */
215 struct fb_info
*fb_info
;
216 struct fb_deferred_io fb_defio
;
217 #endif /* CONFIG_HID_PICOLCD_FB */
218 #ifdef CONFIG_HID_PICOLCD_LCD
219 struct lcd_device
*lcd
;
221 #endif /* CONFIG_HID_PICOLCD_LCD */
222 #ifdef CONFIG_HID_PICOLCD_BACKLIGHT
223 struct backlight_device
*backlight
;
226 #endif /* CONFIG_HID_PICOLCD_BACKLIGHT */
227 #ifdef CONFIG_HID_PICOLCD_LEDS
230 struct led_classdev
*led
[8];
231 #endif /* CONFIG_HID_PICOLCD_LEDS */
233 /* Housekeeping stuff */
236 struct picolcd_pending
*pending
;
238 #define PICOLCD_BOOTLOADER 1
239 #define PICOLCD_FAILED 2
240 #define PICOLCD_READY_FB 4
244 /* Find a given report */
245 #define picolcd_in_report(id, dev) picolcd_report(id, dev, HID_INPUT_REPORT)
246 #define picolcd_out_report(id, dev) picolcd_report(id, dev, HID_OUTPUT_REPORT)
248 static struct hid_report
*picolcd_report(int id
, struct hid_device
*hdev
, int dir
)
250 struct list_head
*feature_report_list
= &hdev
->report_enum
[dir
].report_list
;
251 struct hid_report
*report
= NULL
;
253 list_for_each_entry(report
, feature_report_list
, list
) {
254 if (report
->id
== id
)
257 hid_warn(hdev
, "No report with id 0x%x found\n", id
);
261 #ifdef CONFIG_DEBUG_FS
262 static void picolcd_debug_out_report(struct picolcd_data
*data
,
263 struct hid_device
*hdev
, struct hid_report
*report
);
264 #define usbhid_submit_report(a, b, c) \
266 picolcd_debug_out_report(hid_get_drvdata(a), a, b); \
267 usbhid_submit_report(a, b, c); \
271 /* Submit a report and wait for a reply from device - if device fades away
272 * or does not respond in time, return NULL */
273 static struct picolcd_pending
*picolcd_send_and_wait(struct hid_device
*hdev
,
274 int report_id
, const u8
*raw_data
, int size
)
276 struct picolcd_data
*data
= hid_get_drvdata(hdev
);
277 struct picolcd_pending
*work
;
278 struct hid_report
*report
= picolcd_out_report(report_id
, hdev
);
282 if (!report
|| !data
)
284 if (data
->status
& PICOLCD_FAILED
)
286 work
= kzalloc(sizeof(*work
), GFP_KERNEL
);
290 init_completion(&work
->ready
);
291 work
->out_report
= report
;
292 work
->in_report
= NULL
;
295 mutex_lock(&data
->mutex
);
296 spin_lock_irqsave(&data
->lock
, flags
);
297 for (i
= k
= 0; i
< report
->maxfield
; i
++)
298 for (j
= 0; j
< report
->field
[i
]->report_count
; j
++) {
299 hid_set_field(report
->field
[i
], j
, k
< size
? raw_data
[k
] : 0);
302 data
->pending
= work
;
303 usbhid_submit_report(data
->hdev
, report
, USB_DIR_OUT
);
304 spin_unlock_irqrestore(&data
->lock
, flags
);
305 wait_for_completion_interruptible_timeout(&work
->ready
, HZ
*2);
306 spin_lock_irqsave(&data
->lock
, flags
);
307 data
->pending
= NULL
;
308 spin_unlock_irqrestore(&data
->lock
, flags
);
309 mutex_unlock(&data
->mutex
);
313 #ifdef CONFIG_HID_PICOLCD_FB
314 /* Send a given tile to PicoLCD */
315 static int picolcd_fb_send_tile(struct hid_device
*hdev
, int chip
, int tile
)
317 struct picolcd_data
*data
= hid_get_drvdata(hdev
);
318 struct hid_report
*report1
= picolcd_out_report(REPORT_LCD_CMD_DATA
, hdev
);
319 struct hid_report
*report2
= picolcd_out_report(REPORT_LCD_DATA
, hdev
);
324 if (!report1
|| report1
->maxfield
!= 1 || !report2
|| report2
->maxfield
!= 1)
327 spin_lock_irqsave(&data
->lock
, flags
);
328 hid_set_field(report1
->field
[0], 0, chip
<< 2);
329 hid_set_field(report1
->field
[0], 1, 0x02);
330 hid_set_field(report1
->field
[0], 2, 0x00);
331 hid_set_field(report1
->field
[0], 3, 0x00);
332 hid_set_field(report1
->field
[0], 4, 0xb8 | tile
);
333 hid_set_field(report1
->field
[0], 5, 0x00);
334 hid_set_field(report1
->field
[0], 6, 0x00);
335 hid_set_field(report1
->field
[0], 7, 0x40);
336 hid_set_field(report1
->field
[0], 8, 0x00);
337 hid_set_field(report1
->field
[0], 9, 0x00);
338 hid_set_field(report1
->field
[0], 10, 32);
340 hid_set_field(report2
->field
[0], 0, (chip
<< 2) | 0x01);
341 hid_set_field(report2
->field
[0], 1, 0x00);
342 hid_set_field(report2
->field
[0], 2, 0x00);
343 hid_set_field(report2
->field
[0], 3, 32);
345 tdata
= data
->fb_vbitmap
+ (tile
* 4 + chip
) * 64;
346 for (i
= 0; i
< 64; i
++)
348 hid_set_field(report1
->field
[0], 11 + i
, tdata
[i
]);
350 hid_set_field(report2
->field
[0], 4 + i
- 32, tdata
[i
]);
352 usbhid_submit_report(data
->hdev
, report1
, USB_DIR_OUT
);
353 usbhid_submit_report(data
->hdev
, report2
, USB_DIR_OUT
);
354 spin_unlock_irqrestore(&data
->lock
, flags
);
358 /* Translate a single tile*/
359 static int picolcd_fb_update_tile(u8
*vbitmap
, const u8
*bitmap
, int bpp
,
362 int i
, b
, changed
= 0;
364 u8
*vdata
= vbitmap
+ (tile
* 4 + chip
) * 64;
367 for (b
= 7; b
>= 0; b
--) {
368 const u8
*bdata
= bitmap
+ tile
* 256 + chip
* 8 + b
* 32;
369 for (i
= 0; i
< 64; i
++) {
371 tdata
[i
] |= (bdata
[i
/8] >> (i
% 8)) & 0x01;
374 } else if (bpp
== 8) {
375 for (b
= 7; b
>= 0; b
--) {
376 const u8
*bdata
= bitmap
+ (tile
* 256 + chip
* 8 + b
* 32) * 8;
377 for (i
= 0; i
< 64; i
++) {
379 tdata
[i
] |= (bdata
[i
] & 0x80) ? 0x01 : 0x00;
383 /* Oops, we should never get here! */
388 for (i
= 0; i
< 64; i
++)
389 if (tdata
[i
] != vdata
[i
]) {
396 /* Reconfigure LCD display */
397 static int picolcd_fb_reset(struct picolcd_data
*data
, int clear
)
399 struct hid_report
*report
= picolcd_out_report(REPORT_LCD_CMD
, data
->hdev
);
402 static const u8 mapcmd
[8] = { 0x00, 0x02, 0x00, 0x64, 0x3f, 0x00, 0x64, 0xc0 };
404 if (!report
|| report
->maxfield
!= 1)
407 spin_lock_irqsave(&data
->lock
, flags
);
408 for (i
= 0; i
< 4; i
++) {
409 for (j
= 0; j
< report
->field
[0]->maxusage
; j
++)
411 hid_set_field(report
->field
[0], j
, i
<< 2);
412 else if (j
< sizeof(mapcmd
))
413 hid_set_field(report
->field
[0], j
, mapcmd
[j
]);
415 hid_set_field(report
->field
[0], j
, 0);
416 usbhid_submit_report(data
->hdev
, report
, USB_DIR_OUT
);
419 data
->status
|= PICOLCD_READY_FB
;
420 spin_unlock_irqrestore(&data
->lock
, flags
);
422 if (data
->fb_bitmap
) {
424 memset(data
->fb_vbitmap
, 0, PICOLCDFB_SIZE
);
425 memset(data
->fb_bitmap
, 0, PICOLCDFB_SIZE
*data
->fb_bpp
);
430 /* schedule first output of framebuffer */
432 schedule_delayed_work(&data
->fb_info
->deferred_work
, 0);
437 /* Update fb_vbitmap from the screen_base and send changed tiles to device */
438 static void picolcd_fb_update(struct picolcd_data
*data
)
446 spin_lock_irqsave(&data
->lock
, flags
);
447 if (!(data
->status
& PICOLCD_READY_FB
)) {
448 spin_unlock_irqrestore(&data
->lock
, flags
);
449 picolcd_fb_reset(data
, 0);
451 spin_unlock_irqrestore(&data
->lock
, flags
);
455 * Translate the framebuffer into the format needed by the PicoLCD.
456 * See display layout above.
457 * Do this one tile after the other and push those tiles that changed.
459 * Wait for our IO to complete as otherwise we might flood the queue!
462 for (chip
= 0; chip
< 4; chip
++)
463 for (tile
= 0; tile
< 8; tile
++)
464 if (picolcd_fb_update_tile(data
->fb_vbitmap
,
465 data
->fb_bitmap
, data
->fb_bpp
, chip
, tile
) ||
468 if (!data
->fb_info
->par
)
469 return; /* device lost! */
470 if (n
>= HID_OUTPUT_FIFO_SIZE
/ 2) {
471 usbhid_wait_io(data
->hdev
);
474 picolcd_fb_send_tile(data
->hdev
, chip
, tile
);
476 data
->fb_force
= false;
478 usbhid_wait_io(data
->hdev
);
481 /* Stub to call the system default and update the image on the picoLCD */
482 static void picolcd_fb_fillrect(struct fb_info
*info
,
483 const struct fb_fillrect
*rect
)
487 sys_fillrect(info
, rect
);
489 schedule_delayed_work(&info
->deferred_work
, 0);
492 /* Stub to call the system default and update the image on the picoLCD */
493 static void picolcd_fb_copyarea(struct fb_info
*info
,
494 const struct fb_copyarea
*area
)
498 sys_copyarea(info
, area
);
500 schedule_delayed_work(&info
->deferred_work
, 0);
503 /* Stub to call the system default and update the image on the picoLCD */
504 static void picolcd_fb_imageblit(struct fb_info
*info
, const struct fb_image
*image
)
508 sys_imageblit(info
, image
);
510 schedule_delayed_work(&info
->deferred_work
, 0);
514 * this is the slow path from userspace. they can seek and write to
515 * the fb. it's inefficient to do anything less than a full screen draw
517 static ssize_t
picolcd_fb_write(struct fb_info
*info
, const char __user
*buf
,
518 size_t count
, loff_t
*ppos
)
523 ret
= fb_sys_write(info
, buf
, count
, ppos
);
525 schedule_delayed_work(&info
->deferred_work
, 0);
529 static int picolcd_fb_blank(int blank
, struct fb_info
*info
)
533 /* We let fb notification do this for us via lcd/backlight device */
537 static void picolcd_fb_destroy(struct fb_info
*info
)
539 struct picolcd_data
*data
= info
->par
;
540 u32
*ref_cnt
= info
->pseudo_palette
;
545 data
->fb_info
= NULL
;
546 fb_deferred_io_cleanup(info
);
549 mutex_lock(&info
->lock
);
551 may_release
= !*ref_cnt
;
552 mutex_unlock(&info
->lock
);
554 vfree((u8
*)info
->fix
.smem_start
);
555 framebuffer_release(info
);
559 static int picolcd_fb_check_var(struct fb_var_screeninfo
*var
, struct fb_info
*info
)
561 __u32 bpp
= var
->bits_per_pixel
;
562 __u32 activate
= var
->activate
;
564 /* only allow 1/8 bit depth (8-bit is grayscale) */
565 *var
= picolcdfb_var
;
566 var
->activate
= activate
;
568 var
->bits_per_pixel
= 8;
570 var
->green
.length
= 8;
571 var
->blue
.length
= 8;
573 var
->bits_per_pixel
= 1;
575 var
->green
.length
= 1;
576 var
->blue
.length
= 1;
581 static int picolcd_set_par(struct fb_info
*info
)
583 struct picolcd_data
*data
= info
->par
;
587 if (info
->var
.bits_per_pixel
== data
->fb_bpp
)
589 /* switch between 1/8 bit depths */
590 if (info
->var
.bits_per_pixel
!= 1 && info
->var
.bits_per_pixel
!= 8)
593 o_fb
= data
->fb_bitmap
;
594 tmp_fb
= kmalloc(PICOLCDFB_SIZE
*info
->var
.bits_per_pixel
, GFP_KERNEL
);
598 /* translate FB content to new bits-per-pixel */
599 if (info
->var
.bits_per_pixel
== 1) {
601 for (i
= 0; i
< PICOLCDFB_SIZE
; i
++) {
603 for (b
= 0; b
< 8; b
++) {
605 p
|= o_fb
[i
*8+b
] ? 0x01 : 0x00;
609 memcpy(o_fb
, tmp_fb
, PICOLCDFB_SIZE
);
610 info
->fix
.visual
= FB_VISUAL_MONO01
;
611 info
->fix
.line_length
= PICOLCDFB_WIDTH
/ 8;
614 memcpy(tmp_fb
, o_fb
, PICOLCDFB_SIZE
);
615 for (i
= 0; i
< PICOLCDFB_SIZE
* 8; i
++)
616 o_fb
[i
] = tmp_fb
[i
/8] & (0x01 << (7 - i
% 8)) ? 0xff : 0x00;
617 info
->fix
.visual
= FB_VISUAL_DIRECTCOLOR
;
618 info
->fix
.line_length
= PICOLCDFB_WIDTH
;
622 data
->fb_bpp
= info
->var
.bits_per_pixel
;
626 /* Do refcounting on our FB and cleanup per worker if FB is
627 * closed after unplug of our device
628 * (fb_release holds info->lock and still touches info after
629 * we return so we can't release it immediately.
631 struct picolcd_fb_cleanup_item
{
632 struct fb_info
*info
;
633 struct picolcd_fb_cleanup_item
*next
;
635 static struct picolcd_fb_cleanup_item
*fb_pending
;
636 static DEFINE_SPINLOCK(fb_pending_lock
);
638 static void picolcd_fb_do_cleanup(struct work_struct
*data
)
640 struct picolcd_fb_cleanup_item
*item
;
644 spin_lock_irqsave(&fb_pending_lock
, flags
);
646 fb_pending
= item
? item
->next
: NULL
;
647 spin_unlock_irqrestore(&fb_pending_lock
, flags
);
650 u8
*fb
= (u8
*)item
->info
->fix
.smem_start
;
651 /* make sure we do not race against fb core when
653 mutex_lock(&item
->info
->lock
);
654 mutex_unlock(&item
->info
->lock
);
655 framebuffer_release(item
->info
);
661 static DECLARE_WORK(picolcd_fb_cleanup
, picolcd_fb_do_cleanup
);
663 static int picolcd_fb_open(struct fb_info
*info
, int u
)
665 u32
*ref_cnt
= info
->pseudo_palette
;
672 static int picolcd_fb_release(struct fb_info
*info
, int u
)
674 u32
*ref_cnt
= info
->pseudo_palette
;
680 struct picolcd_fb_cleanup_item
*item
= (struct picolcd_fb_cleanup_item
*)ref_cnt
;
682 spin_lock_irqsave(&fb_pending_lock
, flags
);
683 item
->next
= fb_pending
;
685 spin_unlock_irqrestore(&fb_pending_lock
, flags
);
686 schedule_work(&picolcd_fb_cleanup
);
691 /* Note this can't be const because of struct fb_info definition */
692 static struct fb_ops picolcdfb_ops
= {
693 .owner
= THIS_MODULE
,
694 .fb_destroy
= picolcd_fb_destroy
,
695 .fb_open
= picolcd_fb_open
,
696 .fb_release
= picolcd_fb_release
,
697 .fb_read
= fb_sys_read
,
698 .fb_write
= picolcd_fb_write
,
699 .fb_blank
= picolcd_fb_blank
,
700 .fb_fillrect
= picolcd_fb_fillrect
,
701 .fb_copyarea
= picolcd_fb_copyarea
,
702 .fb_imageblit
= picolcd_fb_imageblit
,
703 .fb_check_var
= picolcd_fb_check_var
,
704 .fb_set_par
= picolcd_set_par
,
708 /* Callback from deferred IO workqueue */
709 static void picolcd_fb_deferred_io(struct fb_info
*info
, struct list_head
*pagelist
)
711 picolcd_fb_update(info
->par
);
714 static const struct fb_deferred_io picolcd_fb_defio
= {
715 .delay
= HZ
/ PICOLCDFB_UPDATE_RATE_DEFAULT
,
716 .deferred_io
= picolcd_fb_deferred_io
,
721 * The "fb_update_rate" sysfs attribute
723 static ssize_t
picolcd_fb_update_rate_show(struct device
*dev
,
724 struct device_attribute
*attr
, char *buf
)
726 struct picolcd_data
*data
= dev_get_drvdata(dev
);
727 unsigned i
, fb_update_rate
= data
->fb_update_rate
;
730 for (i
= 1; i
<= PICOLCDFB_UPDATE_RATE_LIMIT
; i
++)
731 if (ret
>= PAGE_SIZE
)
733 else if (i
== fb_update_rate
)
734 ret
+= snprintf(buf
+ret
, PAGE_SIZE
-ret
, "[%u] ", i
);
736 ret
+= snprintf(buf
+ret
, PAGE_SIZE
-ret
, "%u ", i
);
738 buf
[min(ret
, (size_t)PAGE_SIZE
)-1] = '\n';
742 static ssize_t
picolcd_fb_update_rate_store(struct device
*dev
,
743 struct device_attribute
*attr
, const char *buf
, size_t count
)
745 struct picolcd_data
*data
= dev_get_drvdata(dev
);
749 if (count
< 1 || count
> 10)
752 i
= sscanf(buf
, "%u", &u
);
756 if (u
> PICOLCDFB_UPDATE_RATE_LIMIT
)
759 u
= PICOLCDFB_UPDATE_RATE_DEFAULT
;
761 data
->fb_update_rate
= u
;
762 data
->fb_defio
.delay
= HZ
/ data
->fb_update_rate
;
766 static DEVICE_ATTR(fb_update_rate
, 0666, picolcd_fb_update_rate_show
,
767 picolcd_fb_update_rate_store
);
769 /* initialize Framebuffer device */
770 static int picolcd_init_framebuffer(struct picolcd_data
*data
)
772 struct device
*dev
= &data
->hdev
->dev
;
773 struct fb_info
*info
= NULL
;
774 int i
, error
= -ENOMEM
;
775 u8
*fb_vbitmap
= NULL
;
776 u8
*fb_bitmap
= NULL
;
779 fb_bitmap
= vmalloc(PICOLCDFB_SIZE
*8);
780 if (fb_bitmap
== NULL
) {
781 dev_err(dev
, "can't get a free page for framebuffer\n");
785 fb_vbitmap
= kmalloc(PICOLCDFB_SIZE
, GFP_KERNEL
);
786 if (fb_vbitmap
== NULL
) {
787 dev_err(dev
, "can't alloc vbitmap image buffer\n");
791 data
->fb_update_rate
= PICOLCDFB_UPDATE_RATE_DEFAULT
;
792 data
->fb_defio
= picolcd_fb_defio
;
793 /* The extra memory is:
794 * - struct picolcd_fb_cleanup_item
795 * - u32 for ref_count
796 * - 256*u32 for pseudo_palette
798 info
= framebuffer_alloc(257 * sizeof(u32
) + sizeof(struct picolcd_fb_cleanup_item
), dev
);
800 dev_err(dev
, "failed to allocate a framebuffer\n");
804 palette
= info
->par
+ sizeof(struct picolcd_fb_cleanup_item
);
807 for (i
= 0; i
< 256; i
++)
808 palette
[i
] = i
> 0 && i
< 16 ? 0xff : 0;
809 info
->pseudo_palette
= palette
;
810 info
->fbdefio
= &data
->fb_defio
;
811 info
->screen_base
= (char __force __iomem
*)fb_bitmap
;
812 info
->fbops
= &picolcdfb_ops
;
813 info
->var
= picolcdfb_var
;
814 info
->fix
= picolcdfb_fix
;
815 info
->fix
.smem_len
= PICOLCDFB_SIZE
*8;
816 info
->fix
.smem_start
= (unsigned long)fb_bitmap
;
818 info
->flags
= FBINFO_FLAG_DEFAULT
;
820 data
->fb_vbitmap
= fb_vbitmap
;
821 data
->fb_bitmap
= fb_bitmap
;
822 data
->fb_bpp
= picolcdfb_var
.bits_per_pixel
;
823 error
= picolcd_fb_reset(data
, 1);
825 dev_err(dev
, "failed to configure display\n");
828 error
= device_create_file(dev
, &dev_attr_fb_update_rate
);
830 dev_err(dev
, "failed to create sysfs attributes\n");
833 fb_deferred_io_init(info
);
834 data
->fb_info
= info
;
835 error
= register_framebuffer(info
);
837 dev_err(dev
, "failed to register framebuffer\n");
840 /* schedule first output of framebuffer */
842 schedule_delayed_work(&info
->deferred_work
, 0);
846 fb_deferred_io_cleanup(info
);
847 device_remove_file(dev
, &dev_attr_fb_update_rate
);
849 data
->fb_vbitmap
= NULL
;
850 data
->fb_bitmap
= NULL
;
852 data
->fb_info
= NULL
;
855 framebuffer_release(info
);
861 static void picolcd_exit_framebuffer(struct picolcd_data
*data
)
863 struct fb_info
*info
= data
->fb_info
;
864 u8
*fb_vbitmap
= data
->fb_vbitmap
;
870 device_remove_file(&data
->hdev
->dev
, &dev_attr_fb_update_rate
);
871 unregister_framebuffer(info
);
872 data
->fb_vbitmap
= NULL
;
873 data
->fb_bitmap
= NULL
;
875 data
->fb_info
= NULL
;
879 #define picolcd_fbinfo(d) ((d)->fb_info)
881 static inline int picolcd_fb_reset(struct picolcd_data
*data
, int clear
)
885 static inline int picolcd_init_framebuffer(struct picolcd_data
*data
)
889 static inline void picolcd_exit_framebuffer(struct picolcd_data
*data
)
892 #define picolcd_fbinfo(d) NULL
893 #endif /* CONFIG_HID_PICOLCD_FB */
895 #ifdef CONFIG_HID_PICOLCD_BACKLIGHT
897 * backlight class device
899 static int picolcd_get_brightness(struct backlight_device
*bdev
)
901 struct picolcd_data
*data
= bl_get_data(bdev
);
902 return data
->lcd_brightness
;
905 static int picolcd_set_brightness(struct backlight_device
*bdev
)
907 struct picolcd_data
*data
= bl_get_data(bdev
);
908 struct hid_report
*report
= picolcd_out_report(REPORT_BRIGHTNESS
, data
->hdev
);
911 if (!report
|| report
->maxfield
!= 1 || report
->field
[0]->report_count
!= 1)
914 data
->lcd_brightness
= bdev
->props
.brightness
& 0x0ff;
915 data
->lcd_power
= bdev
->props
.power
;
916 spin_lock_irqsave(&data
->lock
, flags
);
917 hid_set_field(report
->field
[0], 0, data
->lcd_power
== FB_BLANK_UNBLANK
? data
->lcd_brightness
: 0);
918 usbhid_submit_report(data
->hdev
, report
, USB_DIR_OUT
);
919 spin_unlock_irqrestore(&data
->lock
, flags
);
923 static int picolcd_check_bl_fb(struct backlight_device
*bdev
, struct fb_info
*fb
)
925 return fb
&& fb
== picolcd_fbinfo((struct picolcd_data
*)bl_get_data(bdev
));
928 static const struct backlight_ops picolcd_blops
= {
929 .update_status
= picolcd_set_brightness
,
930 .get_brightness
= picolcd_get_brightness
,
931 .check_fb
= picolcd_check_bl_fb
,
934 static int picolcd_init_backlight(struct picolcd_data
*data
, struct hid_report
*report
)
936 struct device
*dev
= &data
->hdev
->dev
;
937 struct backlight_device
*bdev
;
938 struct backlight_properties props
;
941 if (report
->maxfield
!= 1 || report
->field
[0]->report_count
!= 1 ||
942 report
->field
[0]->report_size
!= 8) {
943 dev_err(dev
, "unsupported BRIGHTNESS report");
947 memset(&props
, 0, sizeof(props
));
948 props
.type
= BACKLIGHT_RAW
;
949 props
.max_brightness
= 0xff;
950 bdev
= backlight_device_register(dev_name(dev
), dev
, data
,
951 &picolcd_blops
, &props
);
953 dev_err(dev
, "failed to register backlight\n");
954 return PTR_ERR(bdev
);
956 bdev
->props
.brightness
= 0xff;
957 data
->lcd_brightness
= 0xff;
958 data
->backlight
= bdev
;
959 picolcd_set_brightness(bdev
);
963 static void picolcd_exit_backlight(struct picolcd_data
*data
)
965 struct backlight_device
*bdev
= data
->backlight
;
967 data
->backlight
= NULL
;
969 backlight_device_unregister(bdev
);
972 static inline int picolcd_resume_backlight(struct picolcd_data
*data
)
974 if (!data
->backlight
)
976 return picolcd_set_brightness(data
->backlight
);
980 static void picolcd_suspend_backlight(struct picolcd_data
*data
)
982 int bl_power
= data
->lcd_power
;
983 if (!data
->backlight
)
986 data
->backlight
->props
.power
= FB_BLANK_POWERDOWN
;
987 picolcd_set_brightness(data
->backlight
);
988 data
->lcd_power
= data
->backlight
->props
.power
= bl_power
;
990 #endif /* CONFIG_PM */
992 static inline int picolcd_init_backlight(struct picolcd_data
*data
,
993 struct hid_report
*report
)
997 static inline void picolcd_exit_backlight(struct picolcd_data
*data
)
1000 static inline int picolcd_resume_backlight(struct picolcd_data
*data
)
1004 static inline void picolcd_suspend_backlight(struct picolcd_data
*data
)
1007 #endif /* CONFIG_HID_PICOLCD_BACKLIGHT */
1009 #ifdef CONFIG_HID_PICOLCD_LCD
1013 static int picolcd_get_contrast(struct lcd_device
*ldev
)
1015 struct picolcd_data
*data
= lcd_get_data(ldev
);
1016 return data
->lcd_contrast
;
1019 static int picolcd_set_contrast(struct lcd_device
*ldev
, int contrast
)
1021 struct picolcd_data
*data
= lcd_get_data(ldev
);
1022 struct hid_report
*report
= picolcd_out_report(REPORT_CONTRAST
, data
->hdev
);
1023 unsigned long flags
;
1025 if (!report
|| report
->maxfield
!= 1 || report
->field
[0]->report_count
!= 1)
1028 data
->lcd_contrast
= contrast
& 0x0ff;
1029 spin_lock_irqsave(&data
->lock
, flags
);
1030 hid_set_field(report
->field
[0], 0, data
->lcd_contrast
);
1031 usbhid_submit_report(data
->hdev
, report
, USB_DIR_OUT
);
1032 spin_unlock_irqrestore(&data
->lock
, flags
);
1036 static int picolcd_check_lcd_fb(struct lcd_device
*ldev
, struct fb_info
*fb
)
1038 return fb
&& fb
== picolcd_fbinfo((struct picolcd_data
*)lcd_get_data(ldev
));
1041 static struct lcd_ops picolcd_lcdops
= {
1042 .get_contrast
= picolcd_get_contrast
,
1043 .set_contrast
= picolcd_set_contrast
,
1044 .check_fb
= picolcd_check_lcd_fb
,
1047 static int picolcd_init_lcd(struct picolcd_data
*data
, struct hid_report
*report
)
1049 struct device
*dev
= &data
->hdev
->dev
;
1050 struct lcd_device
*ldev
;
1054 if (report
->maxfield
!= 1 || report
->field
[0]->report_count
!= 1 ||
1055 report
->field
[0]->report_size
!= 8) {
1056 dev_err(dev
, "unsupported CONTRAST report");
1060 ldev
= lcd_device_register(dev_name(dev
), dev
, data
, &picolcd_lcdops
);
1062 dev_err(dev
, "failed to register LCD\n");
1063 return PTR_ERR(ldev
);
1065 ldev
->props
.max_contrast
= 0x0ff;
1066 data
->lcd_contrast
= 0xe5;
1068 picolcd_set_contrast(ldev
, 0xe5);
1072 static void picolcd_exit_lcd(struct picolcd_data
*data
)
1074 struct lcd_device
*ldev
= data
->lcd
;
1078 lcd_device_unregister(ldev
);
1081 static inline int picolcd_resume_lcd(struct picolcd_data
*data
)
1085 return picolcd_set_contrast(data
->lcd
, data
->lcd_contrast
);
1088 static inline int picolcd_init_lcd(struct picolcd_data
*data
,
1089 struct hid_report
*report
)
1093 static inline void picolcd_exit_lcd(struct picolcd_data
*data
)
1096 static inline int picolcd_resume_lcd(struct picolcd_data
*data
)
1100 #endif /* CONFIG_HID_PICOLCD_LCD */
1102 #ifdef CONFIG_HID_PICOLCD_LEDS
1106 static void picolcd_leds_set(struct picolcd_data
*data
)
1108 struct hid_report
*report
;
1109 unsigned long flags
;
1113 report
= picolcd_out_report(REPORT_LED_STATE
, data
->hdev
);
1114 if (!report
|| report
->maxfield
!= 1 || report
->field
[0]->report_count
!= 1)
1117 spin_lock_irqsave(&data
->lock
, flags
);
1118 hid_set_field(report
->field
[0], 0, data
->led_state
);
1119 usbhid_submit_report(data
->hdev
, report
, USB_DIR_OUT
);
1120 spin_unlock_irqrestore(&data
->lock
, flags
);
1123 static void picolcd_led_set_brightness(struct led_classdev
*led_cdev
,
1124 enum led_brightness value
)
1127 struct hid_device
*hdev
;
1128 struct picolcd_data
*data
;
1131 dev
= led_cdev
->dev
->parent
;
1132 hdev
= container_of(dev
, struct hid_device
, dev
);
1133 data
= hid_get_drvdata(hdev
);
1134 for (i
= 0; i
< 8; i
++) {
1135 if (led_cdev
!= data
->led
[i
])
1137 state
= (data
->led_state
>> i
) & 1;
1138 if (value
== LED_OFF
&& state
) {
1139 data
->led_state
&= ~(1 << i
);
1140 picolcd_leds_set(data
);
1141 } else if (value
!= LED_OFF
&& !state
) {
1142 data
->led_state
|= 1 << i
;
1143 picolcd_leds_set(data
);
1149 static enum led_brightness
picolcd_led_get_brightness(struct led_classdev
*led_cdev
)
1152 struct hid_device
*hdev
;
1153 struct picolcd_data
*data
;
1156 dev
= led_cdev
->dev
->parent
;
1157 hdev
= container_of(dev
, struct hid_device
, dev
);
1158 data
= hid_get_drvdata(hdev
);
1159 for (i
= 0; i
< 8; i
++)
1160 if (led_cdev
== data
->led
[i
]) {
1161 value
= (data
->led_state
>> i
) & 1;
1164 return value
? LED_FULL
: LED_OFF
;
1167 static int picolcd_init_leds(struct picolcd_data
*data
, struct hid_report
*report
)
1169 struct device
*dev
= &data
->hdev
->dev
;
1170 struct led_classdev
*led
;
1171 size_t name_sz
= strlen(dev_name(dev
)) + 8;
1177 if (report
->maxfield
!= 1 || report
->field
[0]->report_count
!= 1 ||
1178 report
->field
[0]->report_size
!= 8) {
1179 dev_err(dev
, "unsupported LED_STATE report");
1183 for (i
= 0; i
< 8; i
++) {
1184 led
= kzalloc(sizeof(struct led_classdev
)+name_sz
, GFP_KERNEL
);
1186 dev_err(dev
, "can't allocate memory for LED %d\n", i
);
1190 name
= (void *)(&led
[1]);
1191 snprintf(name
, name_sz
, "%s::GPO%d", dev_name(dev
), i
);
1193 led
->brightness
= 0;
1194 led
->max_brightness
= 1;
1195 led
->brightness_get
= picolcd_led_get_brightness
;
1196 led
->brightness_set
= picolcd_led_set_brightness
;
1199 ret
= led_classdev_register(dev
, data
->led
[i
]);
1201 data
->led
[i
] = NULL
;
1203 dev_err(dev
, "can't register LED %d\n", i
);
1209 for (i
= 0; i
< 8; i
++)
1212 data
->led
[i
] = NULL
;
1213 led_classdev_unregister(led
);
1219 static void picolcd_exit_leds(struct picolcd_data
*data
)
1221 struct led_classdev
*led
;
1224 for (i
= 0; i
< 8; i
++) {
1226 data
->led
[i
] = NULL
;
1229 led_classdev_unregister(led
);
1235 static inline int picolcd_init_leds(struct picolcd_data
*data
,
1236 struct hid_report
*report
)
1240 static inline void picolcd_exit_leds(struct picolcd_data
*data
)
1243 static inline int picolcd_leds_set(struct picolcd_data
*data
)
1247 #endif /* CONFIG_HID_PICOLCD_LEDS */
1250 * input class device
1252 static int picolcd_raw_keypad(struct picolcd_data
*data
,
1253 struct hid_report
*report
, u8
*raw_data
, int size
)
1257 * First and second data bytes list currently pressed keys,
1258 * 0x00 means no key and at most 2 keys may be pressed at same time
1262 /* determine newly pressed keys */
1263 for (i
= 0; i
< size
; i
++) {
1264 unsigned int key_code
;
1265 if (raw_data
[i
] == 0)
1267 for (j
= 0; j
< sizeof(data
->pressed_keys
); j
++)
1268 if (data
->pressed_keys
[j
] == raw_data
[i
])
1269 goto key_already_down
;
1270 for (j
= 0; j
< sizeof(data
->pressed_keys
); j
++)
1271 if (data
->pressed_keys
[j
] == 0) {
1272 data
->pressed_keys
[j
] = raw_data
[i
];
1275 input_event(data
->input_keys
, EV_MSC
, MSC_SCAN
, raw_data
[i
]);
1276 if (raw_data
[i
] < PICOLCD_KEYS
)
1277 key_code
= data
->keycode
[raw_data
[i
]];
1279 key_code
= KEY_UNKNOWN
;
1280 if (key_code
!= KEY_UNKNOWN
) {
1281 dbg_hid(PICOLCD_NAME
" got key press for %u:%d",
1282 raw_data
[i
], key_code
);
1283 input_report_key(data
->input_keys
, key_code
, 1);
1285 input_sync(data
->input_keys
);
1290 /* determine newly released keys */
1291 for (j
= 0; j
< sizeof(data
->pressed_keys
); j
++) {
1292 unsigned int key_code
;
1293 if (data
->pressed_keys
[j
] == 0)
1295 for (i
= 0; i
< size
; i
++)
1296 if (data
->pressed_keys
[j
] == raw_data
[i
])
1297 goto key_still_down
;
1298 input_event(data
->input_keys
, EV_MSC
, MSC_SCAN
, data
->pressed_keys
[j
]);
1299 if (data
->pressed_keys
[j
] < PICOLCD_KEYS
)
1300 key_code
= data
->keycode
[data
->pressed_keys
[j
]];
1302 key_code
= KEY_UNKNOWN
;
1303 if (key_code
!= KEY_UNKNOWN
) {
1304 dbg_hid(PICOLCD_NAME
" got key release for %u:%d",
1305 data
->pressed_keys
[j
], key_code
);
1306 input_report_key(data
->input_keys
, key_code
, 0);
1308 input_sync(data
->input_keys
);
1309 data
->pressed_keys
[j
] = 0;
1316 static int picolcd_raw_cir(struct picolcd_data
*data
,
1317 struct hid_report
*report
, u8
*raw_data
, int size
)
1319 /* Need understanding of CIR data format to implement ... */
1323 static int picolcd_check_version(struct hid_device
*hdev
)
1325 struct picolcd_data
*data
= hid_get_drvdata(hdev
);
1326 struct picolcd_pending
*verinfo
;
1332 verinfo
= picolcd_send_and_wait(hdev
, REPORT_VERSION
, NULL
, 0);
1334 hid_err(hdev
, "no version response from PicoLCD\n");
1338 if (verinfo
->raw_size
== 2) {
1339 data
->version
[0] = verinfo
->raw_data
[1];
1340 data
->version
[1] = verinfo
->raw_data
[0];
1341 if (data
->status
& PICOLCD_BOOTLOADER
) {
1342 hid_info(hdev
, "PicoLCD, bootloader version %d.%d\n",
1343 verinfo
->raw_data
[1], verinfo
->raw_data
[0]);
1345 hid_info(hdev
, "PicoLCD, firmware version %d.%d\n",
1346 verinfo
->raw_data
[1], verinfo
->raw_data
[0]);
1349 hid_err(hdev
, "confused, got unexpected version response from PicoLCD\n");
1357 * Reset our device and wait for answer to VERSION request
1359 static int picolcd_reset(struct hid_device
*hdev
)
1361 struct picolcd_data
*data
= hid_get_drvdata(hdev
);
1362 struct hid_report
*report
= picolcd_out_report(REPORT_RESET
, hdev
);
1363 unsigned long flags
;
1366 if (!data
|| !report
|| report
->maxfield
!= 1)
1369 spin_lock_irqsave(&data
->lock
, flags
);
1370 if (hdev
->product
== USB_DEVICE_ID_PICOLCD_BOOTLOADER
)
1371 data
->status
|= PICOLCD_BOOTLOADER
;
1373 /* perform the reset */
1374 hid_set_field(report
->field
[0], 0, 1);
1375 usbhid_submit_report(hdev
, report
, USB_DIR_OUT
);
1376 spin_unlock_irqrestore(&data
->lock
, flags
);
1378 error
= picolcd_check_version(hdev
);
1382 picolcd_resume_lcd(data
);
1383 picolcd_resume_backlight(data
);
1384 #ifdef CONFIG_HID_PICOLCD_FB
1386 schedule_delayed_work(&data
->fb_info
->deferred_work
, 0);
1387 #endif /* CONFIG_HID_PICOLCD_FB */
1389 picolcd_leds_set(data
);
1394 * The "operation_mode" sysfs attribute
1396 static ssize_t
picolcd_operation_mode_show(struct device
*dev
,
1397 struct device_attribute
*attr
, char *buf
)
1399 struct picolcd_data
*data
= dev_get_drvdata(dev
);
1401 if (data
->status
& PICOLCD_BOOTLOADER
)
1402 return snprintf(buf
, PAGE_SIZE
, "[bootloader] lcd\n");
1404 return snprintf(buf
, PAGE_SIZE
, "bootloader [lcd]\n");
1407 static ssize_t
picolcd_operation_mode_store(struct device
*dev
,
1408 struct device_attribute
*attr
, const char *buf
, size_t count
)
1410 struct picolcd_data
*data
= dev_get_drvdata(dev
);
1411 struct hid_report
*report
= NULL
;
1413 int timeout
= data
->opmode_delay
;
1414 unsigned long flags
;
1416 if (cnt
>= 3 && strncmp("lcd", buf
, 3) == 0) {
1417 if (data
->status
& PICOLCD_BOOTLOADER
)
1418 report
= picolcd_out_report(REPORT_EXIT_FLASHER
, data
->hdev
);
1421 } else if (cnt
>= 10 && strncmp("bootloader", buf
, 10) == 0) {
1422 if (!(data
->status
& PICOLCD_BOOTLOADER
))
1423 report
= picolcd_out_report(REPORT_EXIT_KEYBOARD
, data
->hdev
);
1430 while (cnt
> 0 && (buf
[cnt
-1] == '\n' || buf
[cnt
-1] == '\r'))
1435 spin_lock_irqsave(&data
->lock
, flags
);
1436 hid_set_field(report
->field
[0], 0, timeout
& 0xff);
1437 hid_set_field(report
->field
[0], 1, (timeout
>> 8) & 0xff);
1438 usbhid_submit_report(data
->hdev
, report
, USB_DIR_OUT
);
1439 spin_unlock_irqrestore(&data
->lock
, flags
);
1443 static DEVICE_ATTR(operation_mode
, 0644, picolcd_operation_mode_show
,
1444 picolcd_operation_mode_store
);
1447 * The "operation_mode_delay" sysfs attribute
1449 static ssize_t
picolcd_operation_mode_delay_show(struct device
*dev
,
1450 struct device_attribute
*attr
, char *buf
)
1452 struct picolcd_data
*data
= dev_get_drvdata(dev
);
1454 return snprintf(buf
, PAGE_SIZE
, "%hu\n", data
->opmode_delay
);
1457 static ssize_t
picolcd_operation_mode_delay_store(struct device
*dev
,
1458 struct device_attribute
*attr
, const char *buf
, size_t count
)
1460 struct picolcd_data
*data
= dev_get_drvdata(dev
);
1462 if (sscanf(buf
, "%u", &u
) != 1)
1467 data
->opmode_delay
= u
;
1471 static DEVICE_ATTR(operation_mode_delay
, 0644, picolcd_operation_mode_delay_show
,
1472 picolcd_operation_mode_delay_store
);
1475 #ifdef CONFIG_DEBUG_FS
1479 static int picolcd_debug_reset_show(struct seq_file
*f
, void *p
)
1481 if (picolcd_fbinfo((struct picolcd_data
*)f
->private))
1482 seq_printf(f
, "all fb\n");
1484 seq_printf(f
, "all\n");
1488 static int picolcd_debug_reset_open(struct inode
*inode
, struct file
*f
)
1490 return single_open(f
, picolcd_debug_reset_show
, inode
->i_private
);
1493 static ssize_t
picolcd_debug_reset_write(struct file
*f
, const char __user
*user_buf
,
1494 size_t count
, loff_t
*ppos
)
1496 struct picolcd_data
*data
= ((struct seq_file
*)f
->private_data
)->private;
1498 size_t cnt
= min(count
, sizeof(buf
)-1);
1499 if (copy_from_user(buf
, user_buf
, cnt
))
1502 while (cnt
> 0 && (buf
[cnt
-1] == ' ' || buf
[cnt
-1] == '\n'))
1505 if (strcmp(buf
, "all") == 0) {
1506 picolcd_reset(data
->hdev
);
1507 picolcd_fb_reset(data
, 1);
1508 } else if (strcmp(buf
, "fb") == 0) {
1509 picolcd_fb_reset(data
, 1);
1516 static const struct file_operations picolcd_debug_reset_fops
= {
1517 .owner
= THIS_MODULE
,
1518 .open
= picolcd_debug_reset_open
,
1520 .llseek
= seq_lseek
,
1521 .write
= picolcd_debug_reset_write
,
1522 .release
= single_release
,
1528 static int picolcd_debug_eeprom_open(struct inode
*i
, struct file
*f
)
1530 f
->private_data
= i
->i_private
;
1534 static ssize_t
picolcd_debug_eeprom_read(struct file
*f
, char __user
*u
,
1535 size_t s
, loff_t
*off
)
1537 struct picolcd_data
*data
= f
->private_data
;
1538 struct picolcd_pending
*resp
;
1547 /* prepare buffer with info about what we want to read (addr & len) */
1548 raw_data
[0] = *off
& 0xff;
1549 raw_data
[1] = (*off
>> 8) & 0xff;
1550 raw_data
[2] = s
< 20 ? s
: 20;
1551 if (*off
+ raw_data
[2] > 0xff)
1552 raw_data
[2] = 0x100 - *off
;
1553 resp
= picolcd_send_and_wait(data
->hdev
, REPORT_EE_READ
, raw_data
,
1558 if (resp
->in_report
&& resp
->in_report
->id
== REPORT_EE_DATA
) {
1559 /* successful read :) */
1560 ret
= resp
->raw_data
[2];
1563 if (copy_to_user(u
, resp
->raw_data
+3, ret
))
1567 } /* anything else is some kind of IO error */
1573 static ssize_t
picolcd_debug_eeprom_write(struct file
*f
, const char __user
*u
,
1574 size_t s
, loff_t
*off
)
1576 struct picolcd_data
*data
= f
->private_data
;
1577 struct picolcd_pending
*resp
;
1586 memset(raw_data
, 0, sizeof(raw_data
));
1587 raw_data
[0] = *off
& 0xff;
1588 raw_data
[1] = (*off
>> 8) & 0xff;
1589 raw_data
[2] = min((size_t)20, s
);
1590 if (*off
+ raw_data
[2] > 0xff)
1591 raw_data
[2] = 0x100 - *off
;
1593 if (copy_from_user(raw_data
+3, u
, min((u8
)20, raw_data
[2])))
1595 resp
= picolcd_send_and_wait(data
->hdev
, REPORT_EE_WRITE
, raw_data
,
1601 if (resp
->in_report
&& resp
->in_report
->id
== REPORT_EE_DATA
) {
1602 /* check if written data matches */
1603 if (memcmp(raw_data
, resp
->raw_data
, 3+raw_data
[2]) == 0) {
1604 *off
+= raw_data
[2];
1614 * - read/write happens in chunks of at most 20 bytes, it's up to userspace
1615 * to loop in order to get more data.
1616 * - on write errors on otherwise correct write request the bytes
1617 * that should have been written are in undefined state.
1619 static const struct file_operations picolcd_debug_eeprom_fops
= {
1620 .owner
= THIS_MODULE
,
1621 .open
= picolcd_debug_eeprom_open
,
1622 .read
= picolcd_debug_eeprom_read
,
1623 .write
= picolcd_debug_eeprom_write
,
1624 .llseek
= generic_file_llseek
,
1630 static int picolcd_debug_flash_open(struct inode
*i
, struct file
*f
)
1632 f
->private_data
= i
->i_private
;
1636 /* record a flash address to buf (bounds check to be done by caller) */
1637 static int _picolcd_flash_setaddr(struct picolcd_data
*data
, u8
*buf
, long off
)
1639 buf
[0] = off
& 0xff;
1640 buf
[1] = (off
>> 8) & 0xff;
1641 if (data
->addr_sz
== 3)
1642 buf
[2] = (off
>> 16) & 0xff;
1643 return data
->addr_sz
== 2 ? 2 : 3;
1646 /* read a given size of data (bounds check to be done by caller) */
1647 static ssize_t
_picolcd_flash_read(struct picolcd_data
*data
, int report_id
,
1648 char __user
*u
, size_t s
, loff_t
*off
)
1650 struct picolcd_pending
*resp
;
1653 int len_off
, err
= -EIO
;
1657 len_off
= _picolcd_flash_setaddr(data
, raw_data
, *off
);
1658 raw_data
[len_off
] = s
> 32 ? 32 : s
;
1659 resp
= picolcd_send_and_wait(data
->hdev
, report_id
, raw_data
, len_off
+1);
1660 if (!resp
|| !resp
->in_report
)
1662 if (resp
->in_report
->id
== REPORT_MEMORY
||
1663 resp
->in_report
->id
== REPORT_BL_READ_MEMORY
) {
1664 if (memcmp(raw_data
, resp
->raw_data
, len_off
+1) != 0)
1666 if (copy_to_user(u
+ret
, resp
->raw_data
+len_off
+1, raw_data
[len_off
])) {
1670 *off
+= raw_data
[len_off
];
1671 s
-= raw_data
[len_off
];
1672 ret
+= raw_data
[len_off
];
1678 return ret
> 0 ? ret
: err
;
1683 static ssize_t
picolcd_debug_flash_read(struct file
*f
, char __user
*u
,
1684 size_t s
, loff_t
*off
)
1686 struct picolcd_data
*data
= f
->private_data
;
1692 if (*off
+ s
> 0x05fff)
1695 if (data
->status
& PICOLCD_BOOTLOADER
)
1696 return _picolcd_flash_read(data
, REPORT_BL_READ_MEMORY
, u
, s
, off
);
1698 return _picolcd_flash_read(data
, REPORT_READ_MEMORY
, u
, s
, off
);
1701 /* erase block aligned to 64bytes boundary */
1702 static ssize_t
_picolcd_flash_erase64(struct picolcd_data
*data
, int report_id
,
1705 struct picolcd_pending
*resp
;
1713 len_off
= _picolcd_flash_setaddr(data
, raw_data
, *off
);
1714 resp
= picolcd_send_and_wait(data
->hdev
, report_id
, raw_data
, len_off
);
1715 if (!resp
|| !resp
->in_report
)
1717 if (resp
->in_report
->id
== REPORT_MEMORY
||
1718 resp
->in_report
->id
== REPORT_BL_ERASE_MEMORY
) {
1719 if (memcmp(raw_data
, resp
->raw_data
, len_off
) != 0)
1728 /* write a given size of data (bounds check to be done by caller) */
1729 static ssize_t
_picolcd_flash_write(struct picolcd_data
*data
, int report_id
,
1730 const char __user
*u
, size_t s
, loff_t
*off
)
1732 struct picolcd_pending
*resp
;
1735 int len_off
, err
= -EIO
;
1739 len_off
= _picolcd_flash_setaddr(data
, raw_data
, *off
);
1740 raw_data
[len_off
] = s
> 32 ? 32 : s
;
1741 if (copy_from_user(raw_data
+len_off
+1, u
, raw_data
[len_off
])) {
1745 resp
= picolcd_send_and_wait(data
->hdev
, report_id
, raw_data
,
1746 len_off
+1+raw_data
[len_off
]);
1747 if (!resp
|| !resp
->in_report
)
1749 if (resp
->in_report
->id
== REPORT_MEMORY
||
1750 resp
->in_report
->id
== REPORT_BL_WRITE_MEMORY
) {
1751 if (memcmp(raw_data
, resp
->raw_data
, len_off
+1+raw_data
[len_off
]) != 0)
1753 *off
+= raw_data
[len_off
];
1754 s
-= raw_data
[len_off
];
1755 ret
+= raw_data
[len_off
];
1763 return ret
> 0 ? ret
: err
;
1766 static ssize_t
picolcd_debug_flash_write(struct file
*f
, const char __user
*u
,
1767 size_t s
, loff_t
*off
)
1769 struct picolcd_data
*data
= f
->private_data
;
1770 ssize_t err
, ret
= 0;
1771 int report_erase
, report_write
;
1782 if (data
->status
& PICOLCD_BOOTLOADER
) {
1783 report_erase
= REPORT_BL_ERASE_MEMORY
;
1784 report_write
= REPORT_BL_WRITE_MEMORY
;
1786 report_erase
= REPORT_ERASE_MEMORY
;
1787 report_write
= REPORT_WRITE_MEMORY
;
1789 mutex_lock(&data
->mutex_flash
);
1791 err
= _picolcd_flash_erase64(data
, report_erase
, off
);
1794 err
= _picolcd_flash_write(data
, report_write
, u
, 64, off
);
1803 mutex_unlock(&data
->mutex_flash
);
1804 return ret
> 0 ? ret
: err
;
1809 * - concurrent writing is prevented by mutex and all writes must be
1810 * n*64 bytes and 64-byte aligned, each write being preceded by an
1811 * ERASE which erases a 64byte block.
1812 * If less than requested was written or an error is returned for an
1813 * otherwise correct write request the next 64-byte block which should
1814 * have been written is in undefined state (mostly: original, erased,
1815 * (half-)written with write error)
1816 * - reading can happen without special restriction
1818 static const struct file_operations picolcd_debug_flash_fops
= {
1819 .owner
= THIS_MODULE
,
1820 .open
= picolcd_debug_flash_open
,
1821 .read
= picolcd_debug_flash_read
,
1822 .write
= picolcd_debug_flash_write
,
1823 .llseek
= generic_file_llseek
,
1828 * Helper code for HID report level dumping/debugging
1830 static const char *error_codes
[] = {
1831 "success", "parameter missing", "data_missing", "block readonly",
1832 "block not erasable", "block too big", "section overflow",
1833 "invalid command length", "invalid data length",
1836 static void dump_buff_as_hex(char *dst
, size_t dst_sz
, const u8
*data
,
1837 const size_t data_len
)
1840 for (i
= j
= 0; i
< data_len
&& j
+ 3 < dst_sz
; i
++) {
1841 dst
[j
++] = hex_asc
[(data
[i
] >> 4) & 0x0f];
1842 dst
[j
++] = hex_asc
[data
[i
] & 0x0f];
1852 static void picolcd_debug_out_report(struct picolcd_data
*data
,
1853 struct hid_device
*hdev
, struct hid_report
*report
)
1856 int raw_size
= (report
->size
>> 3) + 1;
1860 /* Avoid unnecessary overhead if debugfs is disabled */
1861 if (!hdev
->debug_events
)
1864 buff
= kmalloc(BUFF_SZ
, GFP_ATOMIC
);
1868 snprintf(buff
, BUFF_SZ
, "\nout report %d (size %d) = ",
1869 report
->id
, raw_size
);
1870 hid_debug_event(hdev
, buff
);
1871 if (raw_size
+ 5 > sizeof(raw_data
)) {
1873 hid_debug_event(hdev
, " TOO BIG\n");
1876 raw_data
[0] = report
->id
;
1877 hid_output_report(report
, raw_data
);
1878 dump_buff_as_hex(buff
, BUFF_SZ
, raw_data
, raw_size
);
1879 hid_debug_event(hdev
, buff
);
1882 switch (report
->id
) {
1883 case REPORT_LED_STATE
:
1884 /* 1 data byte with GPO state */
1885 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
1886 "REPORT_LED_STATE", report
->id
, raw_size
-1);
1887 hid_debug_event(hdev
, buff
);
1888 snprintf(buff
, BUFF_SZ
, "\tGPO state: 0x%02x\n", raw_data
[1]);
1889 hid_debug_event(hdev
, buff
);
1891 case REPORT_BRIGHTNESS
:
1892 /* 1 data byte with brightness */
1893 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
1894 "REPORT_BRIGHTNESS", report
->id
, raw_size
-1);
1895 hid_debug_event(hdev
, buff
);
1896 snprintf(buff
, BUFF_SZ
, "\tBrightness: 0x%02x\n", raw_data
[1]);
1897 hid_debug_event(hdev
, buff
);
1899 case REPORT_CONTRAST
:
1900 /* 1 data byte with contrast */
1901 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
1902 "REPORT_CONTRAST", report
->id
, raw_size
-1);
1903 hid_debug_event(hdev
, buff
);
1904 snprintf(buff
, BUFF_SZ
, "\tContrast: 0x%02x\n", raw_data
[1]);
1905 hid_debug_event(hdev
, buff
);
1908 /* 2 data bytes with reset duration in ms */
1909 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
1910 "REPORT_RESET", report
->id
, raw_size
-1);
1911 hid_debug_event(hdev
, buff
);
1912 snprintf(buff
, BUFF_SZ
, "\tDuration: 0x%02x%02x (%dms)\n",
1913 raw_data
[2], raw_data
[1], raw_data
[2] << 8 | raw_data
[1]);
1914 hid_debug_event(hdev
, buff
);
1916 case REPORT_LCD_CMD
:
1917 /* 63 data bytes with LCD commands */
1918 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
1919 "REPORT_LCD_CMD", report
->id
, raw_size
-1);
1920 hid_debug_event(hdev
, buff
);
1921 /* TODO: format decoding */
1923 case REPORT_LCD_DATA
:
1924 /* 63 data bytes with LCD data */
1925 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
1926 "REPORT_LCD_CMD", report
->id
, raw_size
-1);
1927 /* TODO: format decoding */
1928 hid_debug_event(hdev
, buff
);
1930 case REPORT_LCD_CMD_DATA
:
1931 /* 63 data bytes with LCD commands and data */
1932 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
1933 "REPORT_LCD_CMD", report
->id
, raw_size
-1);
1934 /* TODO: format decoding */
1935 hid_debug_event(hdev
, buff
);
1937 case REPORT_EE_READ
:
1938 /* 3 data bytes with read area description */
1939 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
1940 "REPORT_EE_READ", report
->id
, raw_size
-1);
1941 hid_debug_event(hdev
, buff
);
1942 snprintf(buff
, BUFF_SZ
, "\tData address: 0x%02x%02x\n",
1943 raw_data
[2], raw_data
[1]);
1944 hid_debug_event(hdev
, buff
);
1945 snprintf(buff
, BUFF_SZ
, "\tData length: %d\n", raw_data
[3]);
1946 hid_debug_event(hdev
, buff
);
1948 case REPORT_EE_WRITE
:
1949 /* 3+1..20 data bytes with write area description */
1950 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
1951 "REPORT_EE_WRITE", report
->id
, raw_size
-1);
1952 hid_debug_event(hdev
, buff
);
1953 snprintf(buff
, BUFF_SZ
, "\tData address: 0x%02x%02x\n",
1954 raw_data
[2], raw_data
[1]);
1955 hid_debug_event(hdev
, buff
);
1956 snprintf(buff
, BUFF_SZ
, "\tData length: %d\n", raw_data
[3]);
1957 hid_debug_event(hdev
, buff
);
1958 if (raw_data
[3] == 0) {
1959 snprintf(buff
, BUFF_SZ
, "\tNo data\n");
1960 } else if (raw_data
[3] + 4 <= raw_size
) {
1961 snprintf(buff
, BUFF_SZ
, "\tData: ");
1962 hid_debug_event(hdev
, buff
);
1963 dump_buff_as_hex(buff
, BUFF_SZ
, raw_data
+4, raw_data
[3]);
1965 snprintf(buff
, BUFF_SZ
, "\tData overflowed\n");
1967 hid_debug_event(hdev
, buff
);
1969 case REPORT_ERASE_MEMORY
:
1970 case REPORT_BL_ERASE_MEMORY
:
1971 /* 3 data bytes with pointer inside erase block */
1972 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
1973 "REPORT_ERASE_MEMORY", report
->id
, raw_size
-1);
1974 hid_debug_event(hdev
, buff
);
1975 switch (data
->addr_sz
) {
1977 snprintf(buff
, BUFF_SZ
, "\tAddress inside 64 byte block: 0x%02x%02x\n",
1978 raw_data
[2], raw_data
[1]);
1981 snprintf(buff
, BUFF_SZ
, "\tAddress inside 64 byte block: 0x%02x%02x%02x\n",
1982 raw_data
[3], raw_data
[2], raw_data
[1]);
1985 snprintf(buff
, BUFF_SZ
, "\tNot supported\n");
1987 hid_debug_event(hdev
, buff
);
1989 case REPORT_READ_MEMORY
:
1990 case REPORT_BL_READ_MEMORY
:
1991 /* 4 data bytes with read area description */
1992 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
1993 "REPORT_READ_MEMORY", report
->id
, raw_size
-1);
1994 hid_debug_event(hdev
, buff
);
1995 switch (data
->addr_sz
) {
1997 snprintf(buff
, BUFF_SZ
, "\tData address: 0x%02x%02x\n",
1998 raw_data
[2], raw_data
[1]);
1999 hid_debug_event(hdev
, buff
);
2000 snprintf(buff
, BUFF_SZ
, "\tData length: %d\n", raw_data
[3]);
2003 snprintf(buff
, BUFF_SZ
, "\tData address: 0x%02x%02x%02x\n",
2004 raw_data
[3], raw_data
[2], raw_data
[1]);
2005 hid_debug_event(hdev
, buff
);
2006 snprintf(buff
, BUFF_SZ
, "\tData length: %d\n", raw_data
[4]);
2009 snprintf(buff
, BUFF_SZ
, "\tNot supported\n");
2011 hid_debug_event(hdev
, buff
);
2013 case REPORT_WRITE_MEMORY
:
2014 case REPORT_BL_WRITE_MEMORY
:
2015 /* 4+1..32 data bytes with write adrea description */
2016 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
2017 "REPORT_WRITE_MEMORY", report
->id
, raw_size
-1);
2018 hid_debug_event(hdev
, buff
);
2019 switch (data
->addr_sz
) {
2021 snprintf(buff
, BUFF_SZ
, "\tData address: 0x%02x%02x\n",
2022 raw_data
[2], raw_data
[1]);
2023 hid_debug_event(hdev
, buff
);
2024 snprintf(buff
, BUFF_SZ
, "\tData length: %d\n", raw_data
[3]);
2025 hid_debug_event(hdev
, buff
);
2026 if (raw_data
[3] == 0) {
2027 snprintf(buff
, BUFF_SZ
, "\tNo data\n");
2028 } else if (raw_data
[3] + 4 <= raw_size
) {
2029 snprintf(buff
, BUFF_SZ
, "\tData: ");
2030 hid_debug_event(hdev
, buff
);
2031 dump_buff_as_hex(buff
, BUFF_SZ
, raw_data
+4, raw_data
[3]);
2033 snprintf(buff
, BUFF_SZ
, "\tData overflowed\n");
2037 snprintf(buff
, BUFF_SZ
, "\tData address: 0x%02x%02x%02x\n",
2038 raw_data
[3], raw_data
[2], raw_data
[1]);
2039 hid_debug_event(hdev
, buff
);
2040 snprintf(buff
, BUFF_SZ
, "\tData length: %d\n", raw_data
[4]);
2041 hid_debug_event(hdev
, buff
);
2042 if (raw_data
[4] == 0) {
2043 snprintf(buff
, BUFF_SZ
, "\tNo data\n");
2044 } else if (raw_data
[4] + 5 <= raw_size
) {
2045 snprintf(buff
, BUFF_SZ
, "\tData: ");
2046 hid_debug_event(hdev
, buff
);
2047 dump_buff_as_hex(buff
, BUFF_SZ
, raw_data
+5, raw_data
[4]);
2049 snprintf(buff
, BUFF_SZ
, "\tData overflowed\n");
2053 snprintf(buff
, BUFF_SZ
, "\tNot supported\n");
2055 hid_debug_event(hdev
, buff
);
2057 case REPORT_SPLASH_RESTART
:
2060 case REPORT_EXIT_KEYBOARD
:
2061 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
2062 "REPORT_EXIT_KEYBOARD", report
->id
, raw_size
-1);
2063 hid_debug_event(hdev
, buff
);
2064 snprintf(buff
, BUFF_SZ
, "\tRestart delay: %dms (0x%02x%02x)\n",
2065 raw_data
[1] | (raw_data
[2] << 8),
2066 raw_data
[2], raw_data
[1]);
2067 hid_debug_event(hdev
, buff
);
2069 case REPORT_VERSION
:
2070 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
2071 "REPORT_VERSION", report
->id
, raw_size
-1);
2072 hid_debug_event(hdev
, buff
);
2075 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
2076 "REPORT_DEVID", report
->id
, raw_size
-1);
2077 hid_debug_event(hdev
, buff
);
2079 case REPORT_SPLASH_SIZE
:
2080 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
2081 "REPORT_SPLASH_SIZE", report
->id
, raw_size
-1);
2082 hid_debug_event(hdev
, buff
);
2084 case REPORT_HOOK_VERSION
:
2085 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
2086 "REPORT_HOOK_VERSION", report
->id
, raw_size
-1);
2087 hid_debug_event(hdev
, buff
);
2089 case REPORT_EXIT_FLASHER
:
2090 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
2091 "REPORT_VERSION", report
->id
, raw_size
-1);
2092 hid_debug_event(hdev
, buff
);
2093 snprintf(buff
, BUFF_SZ
, "\tRestart delay: %dms (0x%02x%02x)\n",
2094 raw_data
[1] | (raw_data
[2] << 8),
2095 raw_data
[2], raw_data
[1]);
2096 hid_debug_event(hdev
, buff
);
2099 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
2100 "<unknown>", report
->id
, raw_size
-1);
2101 hid_debug_event(hdev
, buff
);
2104 wake_up_interruptible(&hdev
->debug_wait
);
2108 static void picolcd_debug_raw_event(struct picolcd_data
*data
,
2109 struct hid_device
*hdev
, struct hid_report
*report
,
2110 u8
*raw_data
, int size
)
2115 /* Avoid unnecessary overhead if debugfs is disabled */
2116 if (!hdev
->debug_events
)
2119 buff
= kmalloc(BUFF_SZ
, GFP_ATOMIC
);
2123 switch (report
->id
) {
2124 case REPORT_ERROR_CODE
:
2125 /* 2 data bytes with affected report and error code */
2126 snprintf(buff
, BUFF_SZ
, "report %s (%d, size=%d)\n",
2127 "REPORT_ERROR_CODE", report
->id
, size
-1);
2128 hid_debug_event(hdev
, buff
);
2129 if (raw_data
[2] < ARRAY_SIZE(error_codes
))
2130 snprintf(buff
, BUFF_SZ
, "\tError code 0x%02x (%s) in reply to report 0x%02x\n",
2131 raw_data
[2], error_codes
[raw_data
[2]], raw_data
[1]);
2133 snprintf(buff
, BUFF_SZ
, "\tError code 0x%02x in reply to report 0x%02x\n",
2134 raw_data
[2], raw_data
[1]);
2135 hid_debug_event(hdev
, buff
);
2137 case REPORT_KEY_STATE
:
2138 /* 2 data bytes with key state */
2139 snprintf(buff
, BUFF_SZ
, "report %s (%d, size=%d)\n",
2140 "REPORT_KEY_STATE", report
->id
, size
-1);
2141 hid_debug_event(hdev
, buff
);
2142 if (raw_data
[1] == 0)
2143 snprintf(buff
, BUFF_SZ
, "\tNo key pressed\n");
2144 else if (raw_data
[2] == 0)
2145 snprintf(buff
, BUFF_SZ
, "\tOne key pressed: 0x%02x (%d)\n",
2146 raw_data
[1], raw_data
[1]);
2148 snprintf(buff
, BUFF_SZ
, "\tTwo keys pressed: 0x%02x (%d), 0x%02x (%d)\n",
2149 raw_data
[1], raw_data
[1], raw_data
[2], raw_data
[2]);
2150 hid_debug_event(hdev
, buff
);
2152 case REPORT_IR_DATA
:
2153 /* Up to 20 byes of IR scancode data */
2154 snprintf(buff
, BUFF_SZ
, "report %s (%d, size=%d)\n",
2155 "REPORT_IR_DATA", report
->id
, size
-1);
2156 hid_debug_event(hdev
, buff
);
2157 if (raw_data
[1] == 0) {
2158 snprintf(buff
, BUFF_SZ
, "\tUnexpectedly 0 data length\n");
2159 hid_debug_event(hdev
, buff
);
2160 } else if (raw_data
[1] + 1 <= size
) {
2161 snprintf(buff
, BUFF_SZ
, "\tData length: %d\n\tIR Data: ",
2163 hid_debug_event(hdev
, buff
);
2164 dump_buff_as_hex(buff
, BUFF_SZ
, raw_data
+2, raw_data
[1]-1);
2165 hid_debug_event(hdev
, buff
);
2167 snprintf(buff
, BUFF_SZ
, "\tOverflowing data length: %d\n",
2169 hid_debug_event(hdev
, buff
);
2172 case REPORT_EE_DATA
:
2173 /* Data buffer in response to REPORT_EE_READ or REPORT_EE_WRITE */
2174 snprintf(buff
, BUFF_SZ
, "report %s (%d, size=%d)\n",
2175 "REPORT_EE_DATA", report
->id
, size
-1);
2176 hid_debug_event(hdev
, buff
);
2177 snprintf(buff
, BUFF_SZ
, "\tData address: 0x%02x%02x\n",
2178 raw_data
[2], raw_data
[1]);
2179 hid_debug_event(hdev
, buff
);
2180 snprintf(buff
, BUFF_SZ
, "\tData length: %d\n", raw_data
[3]);
2181 hid_debug_event(hdev
, buff
);
2182 if (raw_data
[3] == 0) {
2183 snprintf(buff
, BUFF_SZ
, "\tNo data\n");
2184 hid_debug_event(hdev
, buff
);
2185 } else if (raw_data
[3] + 4 <= size
) {
2186 snprintf(buff
, BUFF_SZ
, "\tData: ");
2187 hid_debug_event(hdev
, buff
);
2188 dump_buff_as_hex(buff
, BUFF_SZ
, raw_data
+4, raw_data
[3]);
2189 hid_debug_event(hdev
, buff
);
2191 snprintf(buff
, BUFF_SZ
, "\tData overflowed\n");
2192 hid_debug_event(hdev
, buff
);
2196 /* Data buffer in response to REPORT_READ_MEMORY or REPORT_WRTIE_MEMORY */
2197 snprintf(buff
, BUFF_SZ
, "report %s (%d, size=%d)\n",
2198 "REPORT_MEMORY", report
->id
, size
-1);
2199 hid_debug_event(hdev
, buff
);
2200 switch (data
->addr_sz
) {
2202 snprintf(buff
, BUFF_SZ
, "\tData address: 0x%02x%02x\n",
2203 raw_data
[2], raw_data
[1]);
2204 hid_debug_event(hdev
, buff
);
2205 snprintf(buff
, BUFF_SZ
, "\tData length: %d\n", raw_data
[3]);
2206 hid_debug_event(hdev
, buff
);
2207 if (raw_data
[3] == 0) {
2208 snprintf(buff
, BUFF_SZ
, "\tNo data\n");
2209 } else if (raw_data
[3] + 4 <= size
) {
2210 snprintf(buff
, BUFF_SZ
, "\tData: ");
2211 hid_debug_event(hdev
, buff
);
2212 dump_buff_as_hex(buff
, BUFF_SZ
, raw_data
+4, raw_data
[3]);
2214 snprintf(buff
, BUFF_SZ
, "\tData overflowed\n");
2218 snprintf(buff
, BUFF_SZ
, "\tData address: 0x%02x%02x%02x\n",
2219 raw_data
[3], raw_data
[2], raw_data
[1]);
2220 hid_debug_event(hdev
, buff
);
2221 snprintf(buff
, BUFF_SZ
, "\tData length: %d\n", raw_data
[4]);
2222 hid_debug_event(hdev
, buff
);
2223 if (raw_data
[4] == 0) {
2224 snprintf(buff
, BUFF_SZ
, "\tNo data\n");
2225 } else if (raw_data
[4] + 5 <= size
) {
2226 snprintf(buff
, BUFF_SZ
, "\tData: ");
2227 hid_debug_event(hdev
, buff
);
2228 dump_buff_as_hex(buff
, BUFF_SZ
, raw_data
+5, raw_data
[4]);
2230 snprintf(buff
, BUFF_SZ
, "\tData overflowed\n");
2234 snprintf(buff
, BUFF_SZ
, "\tNot supported\n");
2236 hid_debug_event(hdev
, buff
);
2238 case REPORT_VERSION
:
2239 snprintf(buff
, BUFF_SZ
, "report %s (%d, size=%d)\n",
2240 "REPORT_VERSION", report
->id
, size
-1);
2241 hid_debug_event(hdev
, buff
);
2242 snprintf(buff
, BUFF_SZ
, "\tFirmware version: %d.%d\n",
2243 raw_data
[2], raw_data
[1]);
2244 hid_debug_event(hdev
, buff
);
2246 case REPORT_BL_ERASE_MEMORY
:
2247 snprintf(buff
, BUFF_SZ
, "report %s (%d, size=%d)\n",
2248 "REPORT_BL_ERASE_MEMORY", report
->id
, size
-1);
2249 hid_debug_event(hdev
, buff
);
2252 case REPORT_BL_READ_MEMORY
:
2253 snprintf(buff
, BUFF_SZ
, "report %s (%d, size=%d)\n",
2254 "REPORT_BL_READ_MEMORY", report
->id
, size
-1);
2255 hid_debug_event(hdev
, buff
);
2258 case REPORT_BL_WRITE_MEMORY
:
2259 snprintf(buff
, BUFF_SZ
, "report %s (%d, size=%d)\n",
2260 "REPORT_BL_WRITE_MEMORY", report
->id
, size
-1);
2261 hid_debug_event(hdev
, buff
);
2265 snprintf(buff
, BUFF_SZ
, "report %s (%d, size=%d)\n",
2266 "REPORT_DEVID", report
->id
, size
-1);
2267 hid_debug_event(hdev
, buff
);
2268 snprintf(buff
, BUFF_SZ
, "\tSerial: 0x%02x%02x%02x%02x\n",
2269 raw_data
[1], raw_data
[2], raw_data
[3], raw_data
[4]);
2270 hid_debug_event(hdev
, buff
);
2271 snprintf(buff
, BUFF_SZ
, "\tType: 0x%02x\n",
2273 hid_debug_event(hdev
, buff
);
2275 case REPORT_SPLASH_SIZE
:
2276 snprintf(buff
, BUFF_SZ
, "report %s (%d, size=%d)\n",
2277 "REPORT_SPLASH_SIZE", report
->id
, size
-1);
2278 hid_debug_event(hdev
, buff
);
2279 snprintf(buff
, BUFF_SZ
, "\tTotal splash space: %d\n",
2280 (raw_data
[2] << 8) | raw_data
[1]);
2281 hid_debug_event(hdev
, buff
);
2282 snprintf(buff
, BUFF_SZ
, "\tUsed splash space: %d\n",
2283 (raw_data
[4] << 8) | raw_data
[3]);
2284 hid_debug_event(hdev
, buff
);
2286 case REPORT_HOOK_VERSION
:
2287 snprintf(buff
, BUFF_SZ
, "report %s (%d, size=%d)\n",
2288 "REPORT_HOOK_VERSION", report
->id
, size
-1);
2289 hid_debug_event(hdev
, buff
);
2290 snprintf(buff
, BUFF_SZ
, "\tFirmware version: %d.%d\n",
2291 raw_data
[1], raw_data
[2]);
2292 hid_debug_event(hdev
, buff
);
2295 snprintf(buff
, BUFF_SZ
, "report %s (%d, size=%d)\n",
2296 "<unknown>", report
->id
, size
-1);
2297 hid_debug_event(hdev
, buff
);
2300 wake_up_interruptible(&hdev
->debug_wait
);
2304 static void picolcd_init_devfs(struct picolcd_data
*data
,
2305 struct hid_report
*eeprom_r
, struct hid_report
*eeprom_w
,
2306 struct hid_report
*flash_r
, struct hid_report
*flash_w
,
2307 struct hid_report
*reset
)
2309 struct hid_device
*hdev
= data
->hdev
;
2311 mutex_init(&data
->mutex_flash
);
2315 data
->debug_reset
= debugfs_create_file("reset", 0600,
2316 hdev
->debug_dir
, data
, &picolcd_debug_reset_fops
);
2319 if (eeprom_r
|| eeprom_w
)
2320 data
->debug_eeprom
= debugfs_create_file("eeprom",
2321 (eeprom_w
? S_IWUSR
: 0) | (eeprom_r
? S_IRUSR
: 0),
2322 hdev
->debug_dir
, data
, &picolcd_debug_eeprom_fops
);
2325 if (flash_r
&& flash_r
->maxfield
== 1 && flash_r
->field
[0]->report_size
== 8)
2326 data
->addr_sz
= flash_r
->field
[0]->report_count
- 1;
2329 if (data
->addr_sz
== 2 || data
->addr_sz
== 3) {
2330 data
->debug_flash
= debugfs_create_file("flash",
2331 (flash_w
? S_IWUSR
: 0) | (flash_r
? S_IRUSR
: 0),
2332 hdev
->debug_dir
, data
, &picolcd_debug_flash_fops
);
2333 } else if (flash_r
|| flash_w
)
2334 hid_warn(hdev
, "Unexpected FLASH access reports, please submit rdesc for review\n");
2337 static void picolcd_exit_devfs(struct picolcd_data
*data
)
2339 struct dentry
*dent
;
2341 dent
= data
->debug_reset
;
2342 data
->debug_reset
= NULL
;
2344 debugfs_remove(dent
);
2345 dent
= data
->debug_eeprom
;
2346 data
->debug_eeprom
= NULL
;
2348 debugfs_remove(dent
);
2349 dent
= data
->debug_flash
;
2350 data
->debug_flash
= NULL
;
2352 debugfs_remove(dent
);
2353 mutex_destroy(&data
->mutex_flash
);
2356 static inline void picolcd_debug_raw_event(struct picolcd_data
*data
,
2357 struct hid_device
*hdev
, struct hid_report
*report
,
2358 u8
*raw_data
, int size
)
2361 static inline void picolcd_init_devfs(struct picolcd_data
*data
,
2362 struct hid_report
*eeprom_r
, struct hid_report
*eeprom_w
,
2363 struct hid_report
*flash_r
, struct hid_report
*flash_w
,
2364 struct hid_report
*reset
)
2367 static inline void picolcd_exit_devfs(struct picolcd_data
*data
)
2370 #endif /* CONFIG_DEBUG_FS */
2373 * Handle raw report as sent by device
2375 static int picolcd_raw_event(struct hid_device
*hdev
,
2376 struct hid_report
*report
, u8
*raw_data
, int size
)
2378 struct picolcd_data
*data
= hid_get_drvdata(hdev
);
2379 unsigned long flags
;
2385 if (report
->id
== REPORT_KEY_STATE
) {
2386 if (data
->input_keys
)
2387 ret
= picolcd_raw_keypad(data
, report
, raw_data
+1, size
-1);
2388 } else if (report
->id
== REPORT_IR_DATA
) {
2389 if (data
->input_cir
)
2390 ret
= picolcd_raw_cir(data
, report
, raw_data
+1, size
-1);
2392 spin_lock_irqsave(&data
->lock
, flags
);
2394 * We let the caller of picolcd_send_and_wait() check if the
2395 * report we got is one of the expected ones or not.
2397 if (data
->pending
) {
2398 memcpy(data
->pending
->raw_data
, raw_data
+1, size
-1);
2399 data
->pending
->raw_size
= size
-1;
2400 data
->pending
->in_report
= report
;
2401 complete(&data
->pending
->ready
);
2403 spin_unlock_irqrestore(&data
->lock
, flags
);
2406 picolcd_debug_raw_event(data
, hdev
, report
, raw_data
, size
);
2411 static int picolcd_suspend(struct hid_device
*hdev
, pm_message_t message
)
2413 if (PMSG_IS_AUTO(message
))
2416 picolcd_suspend_backlight(hid_get_drvdata(hdev
));
2417 dbg_hid(PICOLCD_NAME
" device ready for suspend\n");
2421 static int picolcd_resume(struct hid_device
*hdev
)
2424 ret
= picolcd_resume_backlight(hid_get_drvdata(hdev
));
2426 dbg_hid(PICOLCD_NAME
" restoring backlight failed: %d\n", ret
);
2430 static int picolcd_reset_resume(struct hid_device
*hdev
)
2433 ret
= picolcd_reset(hdev
);
2435 dbg_hid(PICOLCD_NAME
" resetting our device failed: %d\n", ret
);
2436 ret
= picolcd_fb_reset(hid_get_drvdata(hdev
), 0);
2438 dbg_hid(PICOLCD_NAME
" restoring framebuffer content failed: %d\n", ret
);
2439 ret
= picolcd_resume_lcd(hid_get_drvdata(hdev
));
2441 dbg_hid(PICOLCD_NAME
" restoring lcd failed: %d\n", ret
);
2442 ret
= picolcd_resume_backlight(hid_get_drvdata(hdev
));
2444 dbg_hid(PICOLCD_NAME
" restoring backlight failed: %d\n", ret
);
2445 picolcd_leds_set(hid_get_drvdata(hdev
));
2450 /* initialize keypad input device */
2451 static int picolcd_init_keys(struct picolcd_data
*data
,
2452 struct hid_report
*report
)
2454 struct hid_device
*hdev
= data
->hdev
;
2455 struct input_dev
*idev
;
2460 if (report
->maxfield
!= 1 || report
->field
[0]->report_count
!= 2 ||
2461 report
->field
[0]->report_size
!= 8) {
2462 hid_err(hdev
, "unsupported KEY_STATE report\n");
2466 idev
= input_allocate_device();
2468 hid_err(hdev
, "failed to allocate input device\n");
2471 input_set_drvdata(idev
, hdev
);
2472 memcpy(data
->keycode
, def_keymap
, sizeof(def_keymap
));
2473 idev
->name
= hdev
->name
;
2474 idev
->phys
= hdev
->phys
;
2475 idev
->uniq
= hdev
->uniq
;
2476 idev
->id
.bustype
= hdev
->bus
;
2477 idev
->id
.vendor
= hdev
->vendor
;
2478 idev
->id
.product
= hdev
->product
;
2479 idev
->id
.version
= hdev
->version
;
2480 idev
->dev
.parent
= hdev
->dev
.parent
;
2481 idev
->keycode
= &data
->keycode
;
2482 idev
->keycodemax
= PICOLCD_KEYS
;
2483 idev
->keycodesize
= sizeof(data
->keycode
[0]);
2484 input_set_capability(idev
, EV_MSC
, MSC_SCAN
);
2485 set_bit(EV_REP
, idev
->evbit
);
2486 for (i
= 0; i
< PICOLCD_KEYS
; i
++)
2487 input_set_capability(idev
, EV_KEY
, data
->keycode
[i
]);
2488 error
= input_register_device(idev
);
2490 hid_err(hdev
, "error registering the input device\n");
2491 input_free_device(idev
);
2494 data
->input_keys
= idev
;
2498 static void picolcd_exit_keys(struct picolcd_data
*data
)
2500 struct input_dev
*idev
= data
->input_keys
;
2502 data
->input_keys
= NULL
;
2504 input_unregister_device(idev
);
2507 /* initialize CIR input device */
2508 static inline int picolcd_init_cir(struct picolcd_data
*data
, struct hid_report
*report
)
2510 /* support not implemented yet */
2514 static inline void picolcd_exit_cir(struct picolcd_data
*data
)
2518 static int picolcd_probe_lcd(struct hid_device
*hdev
, struct picolcd_data
*data
)
2522 error
= picolcd_check_version(hdev
);
2526 if (data
->version
[0] != 0 && data
->version
[1] != 3)
2527 hid_info(hdev
, "Device with untested firmware revision, please submit /sys/kernel/debug/hid/%s/rdesc for this device.\n",
2528 dev_name(&hdev
->dev
));
2530 /* Setup keypad input device */
2531 error
= picolcd_init_keys(data
, picolcd_in_report(REPORT_KEY_STATE
, hdev
));
2535 /* Setup CIR input device */
2536 error
= picolcd_init_cir(data
, picolcd_in_report(REPORT_IR_DATA
, hdev
));
2540 /* Set up the framebuffer device */
2541 error
= picolcd_init_framebuffer(data
);
2545 /* Setup lcd class device */
2546 error
= picolcd_init_lcd(data
, picolcd_out_report(REPORT_CONTRAST
, hdev
));
2550 /* Setup backlight class device */
2551 error
= picolcd_init_backlight(data
, picolcd_out_report(REPORT_BRIGHTNESS
, hdev
));
2555 /* Setup the LED class devices */
2556 error
= picolcd_init_leds(data
, picolcd_out_report(REPORT_LED_STATE
, hdev
));
2560 picolcd_init_devfs(data
, picolcd_out_report(REPORT_EE_READ
, hdev
),
2561 picolcd_out_report(REPORT_EE_WRITE
, hdev
),
2562 picolcd_out_report(REPORT_READ_MEMORY
, hdev
),
2563 picolcd_out_report(REPORT_WRITE_MEMORY
, hdev
),
2564 picolcd_out_report(REPORT_RESET
, hdev
));
2567 picolcd_exit_leds(data
);
2568 picolcd_exit_backlight(data
);
2569 picolcd_exit_lcd(data
);
2570 picolcd_exit_framebuffer(data
);
2571 picolcd_exit_cir(data
);
2572 picolcd_exit_keys(data
);
2576 static int picolcd_probe_bootloader(struct hid_device
*hdev
, struct picolcd_data
*data
)
2580 error
= picolcd_check_version(hdev
);
2584 if (data
->version
[0] != 1 && data
->version
[1] != 0)
2585 hid_info(hdev
, "Device with untested bootloader revision, please submit /sys/kernel/debug/hid/%s/rdesc for this device.\n",
2586 dev_name(&hdev
->dev
));
2588 picolcd_init_devfs(data
, NULL
, NULL
,
2589 picolcd_out_report(REPORT_BL_READ_MEMORY
, hdev
),
2590 picolcd_out_report(REPORT_BL_WRITE_MEMORY
, hdev
), NULL
);
2594 static int picolcd_probe(struct hid_device
*hdev
,
2595 const struct hid_device_id
*id
)
2597 struct picolcd_data
*data
;
2598 int error
= -ENOMEM
;
2600 dbg_hid(PICOLCD_NAME
" hardware probe...\n");
2603 * Let's allocate the picolcd data structure, set some reasonable
2604 * defaults, and associate it with the device
2606 data
= kzalloc(sizeof(struct picolcd_data
), GFP_KERNEL
);
2608 hid_err(hdev
, "can't allocate space for Minibox PicoLCD device data\n");
2610 goto err_no_cleanup
;
2613 spin_lock_init(&data
->lock
);
2614 mutex_init(&data
->mutex
);
2616 data
->opmode_delay
= 5000;
2617 if (hdev
->product
== USB_DEVICE_ID_PICOLCD_BOOTLOADER
)
2618 data
->status
|= PICOLCD_BOOTLOADER
;
2619 hid_set_drvdata(hdev
, data
);
2621 /* Parse the device reports and start it up */
2622 error
= hid_parse(hdev
);
2624 hid_err(hdev
, "device report parse failed\n");
2625 goto err_cleanup_data
;
2628 /* We don't use hidinput but hid_hw_start() fails if nothing is
2629 * claimed. So spoof claimed input. */
2630 hdev
->claimed
= HID_CLAIMED_INPUT
;
2631 error
= hid_hw_start(hdev
, 0);
2634 hid_err(hdev
, "hardware start failed\n");
2635 goto err_cleanup_data
;
2638 error
= hid_hw_open(hdev
);
2640 hid_err(hdev
, "failed to open input interrupt pipe for key and IR events\n");
2641 goto err_cleanup_hid_hw
;
2644 error
= device_create_file(&hdev
->dev
, &dev_attr_operation_mode_delay
);
2646 hid_err(hdev
, "failed to create sysfs attributes\n");
2647 goto err_cleanup_hid_ll
;
2650 error
= device_create_file(&hdev
->dev
, &dev_attr_operation_mode
);
2652 hid_err(hdev
, "failed to create sysfs attributes\n");
2653 goto err_cleanup_sysfs1
;
2656 if (data
->status
& PICOLCD_BOOTLOADER
)
2657 error
= picolcd_probe_bootloader(hdev
, data
);
2659 error
= picolcd_probe_lcd(hdev
, data
);
2661 goto err_cleanup_sysfs2
;
2663 dbg_hid(PICOLCD_NAME
" activated and initialized\n");
2667 device_remove_file(&hdev
->dev
, &dev_attr_operation_mode
);
2669 device_remove_file(&hdev
->dev
, &dev_attr_operation_mode_delay
);
2677 hid_set_drvdata(hdev
, NULL
);
2682 static void picolcd_remove(struct hid_device
*hdev
)
2684 struct picolcd_data
*data
= hid_get_drvdata(hdev
);
2685 unsigned long flags
;
2687 dbg_hid(PICOLCD_NAME
" hardware remove...\n");
2688 spin_lock_irqsave(&data
->lock
, flags
);
2689 data
->status
|= PICOLCD_FAILED
;
2690 spin_unlock_irqrestore(&data
->lock
, flags
);
2691 #ifdef CONFIG_HID_PICOLCD_FB
2692 /* short-circuit FB as early as possible in order to
2693 * avoid long delays if we host console.
2696 data
->fb_info
->par
= NULL
;
2699 picolcd_exit_devfs(data
);
2700 device_remove_file(&hdev
->dev
, &dev_attr_operation_mode
);
2701 device_remove_file(&hdev
->dev
, &dev_attr_operation_mode_delay
);
2704 hid_set_drvdata(hdev
, NULL
);
2706 /* Shortcut potential pending reply that will never arrive */
2707 spin_lock_irqsave(&data
->lock
, flags
);
2709 complete(&data
->pending
->ready
);
2710 spin_unlock_irqrestore(&data
->lock
, flags
);
2713 picolcd_exit_leds(data
);
2714 /* Clean up the framebuffer */
2715 picolcd_exit_backlight(data
);
2716 picolcd_exit_lcd(data
);
2717 picolcd_exit_framebuffer(data
);
2719 picolcd_exit_cir(data
);
2720 picolcd_exit_keys(data
);
2722 mutex_destroy(&data
->mutex
);
2723 /* Finally, clean up the picolcd data itself */
2727 static const struct hid_device_id picolcd_devices
[] = {
2728 { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP
, USB_DEVICE_ID_PICOLCD
) },
2729 { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP
, USB_DEVICE_ID_PICOLCD_BOOTLOADER
) },
2732 MODULE_DEVICE_TABLE(hid
, picolcd_devices
);
2734 static struct hid_driver picolcd_driver
= {
2735 .name
= "hid-picolcd",
2736 .id_table
= picolcd_devices
,
2737 .probe
= picolcd_probe
,
2738 .remove
= picolcd_remove
,
2739 .raw_event
= picolcd_raw_event
,
2741 .suspend
= picolcd_suspend
,
2742 .resume
= picolcd_resume
,
2743 .reset_resume
= picolcd_reset_resume
,
2747 static int __init
picolcd_init(void)
2749 return hid_register_driver(&picolcd_driver
);
2752 static void __exit
picolcd_exit(void)
2754 hid_unregister_driver(&picolcd_driver
);
2755 #ifdef CONFIG_HID_PICOLCD_FB
2756 flush_work_sync(&picolcd_fb_cleanup
);
2757 WARN_ON(fb_pending
);
2761 module_init(picolcd_init
);
2762 module_exit(picolcd_exit
);
2763 MODULE_DESCRIPTION("Minibox graphics PicoLCD Driver");
2764 MODULE_LICENSE("GPL v2");