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>
40 #define PICOLCD_NAME "PicoLCD (graphic)"
43 #define REPORT_ERROR_CODE 0x10 /* LCD: IN[16] */
44 #define ERR_SUCCESS 0x00
45 #define ERR_PARAMETER_MISSING 0x01
46 #define ERR_DATA_MISSING 0x02
47 #define ERR_BLOCK_READ_ONLY 0x03
48 #define ERR_BLOCK_NOT_ERASABLE 0x04
49 #define ERR_BLOCK_TOO_BIG 0x05
50 #define ERR_SECTION_OVERFLOW 0x06
51 #define ERR_INVALID_CMD_LEN 0x07
52 #define ERR_INVALID_DATA_LEN 0x08
53 #define REPORT_KEY_STATE 0x11 /* LCD: IN[2] */
54 #define REPORT_IR_DATA 0x21 /* LCD: IN[63] */
55 #define REPORT_EE_DATA 0x32 /* LCD: IN[63] */
56 #define REPORT_MEMORY 0x41 /* LCD: IN[63] */
57 #define REPORT_LED_STATE 0x81 /* LCD: OUT[1] */
58 #define REPORT_BRIGHTNESS 0x91 /* LCD: OUT[1] */
59 #define REPORT_CONTRAST 0x92 /* LCD: OUT[1] */
60 #define REPORT_RESET 0x93 /* LCD: OUT[2] */
61 #define REPORT_LCD_CMD 0x94 /* LCD: OUT[63] */
62 #define REPORT_LCD_DATA 0x95 /* LCD: OUT[63] */
63 #define REPORT_LCD_CMD_DATA 0x96 /* LCD: OUT[63] */
64 #define REPORT_EE_READ 0xa3 /* LCD: OUT[63] */
65 #define REPORT_EE_WRITE 0xa4 /* LCD: OUT[63] */
66 #define REPORT_ERASE_MEMORY 0xb2 /* LCD: OUT[2] */
67 #define REPORT_READ_MEMORY 0xb3 /* LCD: OUT[3] */
68 #define REPORT_WRITE_MEMORY 0xb4 /* LCD: OUT[63] */
69 #define REPORT_SPLASH_RESTART 0xc1 /* LCD: OUT[1] */
70 #define REPORT_EXIT_KEYBOARD 0xef /* LCD: OUT[2] */
71 #define REPORT_VERSION 0xf1 /* LCD: IN[2],OUT[1] Bootloader: IN[2],OUT[1] */
72 #define REPORT_BL_ERASE_MEMORY 0xf2 /* Bootloader: IN[36],OUT[4] */
73 #define REPORT_BL_READ_MEMORY 0xf3 /* Bootloader: IN[36],OUT[4] */
74 #define REPORT_BL_WRITE_MEMORY 0xf4 /* Bootloader: IN[36],OUT[36] */
75 #define REPORT_DEVID 0xf5 /* LCD: IN[5], OUT[1] Bootloader: IN[5],OUT[1] */
76 #define REPORT_SPLASH_SIZE 0xf6 /* LCD: IN[4], OUT[1] */
77 #define REPORT_HOOK_VERSION 0xf7 /* LCD: IN[2], OUT[1] */
78 #define REPORT_EXIT_FLASHER 0xff /* Bootloader: OUT[2] */
80 #ifdef CONFIG_HID_PICOLCD_FB
83 * The PicoLCD use a Topway LCD module of 256x64 pixel
84 * This display area is tiled over 4 controllers with 8 tiles
85 * each. Each tile has 8x64 pixel, each data byte representing
86 * a 1-bit wide vertical line of the tile.
88 * The display can be updated at a tile granularity.
90 * Chip 1 Chip 2 Chip 3 Chip 4
91 * +----------------+----------------+----------------+----------------+
92 * | Tile 1 | Tile 1 | Tile 1 | Tile 1 |
93 * +----------------+----------------+----------------+----------------+
94 * | Tile 2 | Tile 2 | Tile 2 | Tile 2 |
95 * +----------------+----------------+----------------+----------------+
97 * +----------------+----------------+----------------+----------------+
98 * | Tile 8 | Tile 8 | Tile 8 | Tile 8 |
99 * +----------------+----------------+----------------+----------------+
101 #define PICOLCDFB_NAME "picolcdfb"
102 #define PICOLCDFB_WIDTH (256)
103 #define PICOLCDFB_HEIGHT (64)
104 #define PICOLCDFB_SIZE (PICOLCDFB_WIDTH * PICOLCDFB_HEIGHT / 8)
106 #define PICOLCDFB_UPDATE_RATE_LIMIT 10
107 #define PICOLCDFB_UPDATE_RATE_DEFAULT 2
109 /* Framebuffer visual structures */
110 static const struct fb_fix_screeninfo picolcdfb_fix
= {
111 .id
= PICOLCDFB_NAME
,
112 .type
= FB_TYPE_PACKED_PIXELS
,
113 .visual
= FB_VISUAL_MONO01
,
117 .line_length
= PICOLCDFB_WIDTH
/ 8,
118 .accel
= FB_ACCEL_NONE
,
121 static const struct fb_var_screeninfo picolcdfb_var
= {
122 .xres
= PICOLCDFB_WIDTH
,
123 .yres
= PICOLCDFB_HEIGHT
,
124 .xres_virtual
= PICOLCDFB_WIDTH
,
125 .yres_virtual
= PICOLCDFB_HEIGHT
,
151 #endif /* CONFIG_HID_PICOLCD_FB */
155 * The PicoLCD has an IR receiver header, a built-in keypad with 5 keys
156 * and header for 4x4 key matrix. The built-in keys are part of the matrix.
158 static const unsigned short def_keymap
[] = {
159 KEY_RESERVED
, /* none */
160 KEY_BACK
, /* col 4 + row 1 */
161 KEY_HOMEPAGE
, /* col 3 + row 1 */
162 KEY_RESERVED
, /* col 2 + row 1 */
163 KEY_RESERVED
, /* col 1 + row 1 */
164 KEY_SCROLLUP
, /* col 4 + row 2 */
165 KEY_OK
, /* col 3 + row 2 */
166 KEY_SCROLLDOWN
, /* col 2 + row 2 */
167 KEY_RESERVED
, /* col 1 + row 2 */
168 KEY_RESERVED
, /* col 4 + row 3 */
169 KEY_RESERVED
, /* col 3 + row 3 */
170 KEY_RESERVED
, /* col 2 + row 3 */
171 KEY_RESERVED
, /* col 1 + row 3 */
172 KEY_RESERVED
, /* col 4 + row 4 */
173 KEY_RESERVED
, /* col 3 + row 4 */
174 KEY_RESERVED
, /* col 2 + row 4 */
175 KEY_RESERVED
, /* col 1 + row 4 */
177 #define PICOLCD_KEYS ARRAY_SIZE(def_keymap)
179 /* Description of in-progress IO operation, used for operations
180 * that trigger response from device */
181 struct picolcd_pending
{
182 struct hid_report
*out_report
;
183 struct hid_report
*in_report
;
184 struct completion ready
;
189 /* Per device data structure */
190 struct picolcd_data
{
191 struct hid_device
*hdev
;
192 #ifdef CONFIG_DEBUG_FS
193 struct dentry
*debug_reset
;
194 struct dentry
*debug_eeprom
;
195 struct dentry
*debug_flash
;
196 struct mutex mutex_flash
;
200 unsigned short opmode_delay
;
203 struct input_dev
*input_keys
;
204 struct input_dev
*input_cir
;
205 unsigned short keycode
[PICOLCD_KEYS
];
207 #ifdef CONFIG_HID_PICOLCD_FB
208 /* Framebuffer stuff */
212 u8
*fb_vbitmap
; /* local copy of what was sent to PicoLCD */
213 u8
*fb_bitmap
; /* framebuffer */
214 struct fb_info
*fb_info
;
215 struct fb_deferred_io fb_defio
;
216 #endif /* CONFIG_HID_PICOLCD_FB */
217 #ifdef CONFIG_HID_PICOLCD_LCD
218 struct lcd_device
*lcd
;
220 #endif /* CONFIG_HID_PICOLCD_LCD */
221 #ifdef CONFIG_HID_PICOLCD_BACKLIGHT
222 struct backlight_device
*backlight
;
225 #endif /* CONFIG_HID_PICOLCD_BACKLIGHT */
226 #ifdef CONFIG_HID_PICOLCD_LEDS
229 struct led_classdev
*led
[8];
230 #endif /* CONFIG_HID_PICOLCD_LEDS */
232 /* Housekeeping stuff */
235 struct picolcd_pending
*pending
;
237 #define PICOLCD_BOOTLOADER 1
238 #define PICOLCD_FAILED 2
239 #define PICOLCD_READY_FB 4
243 /* Find a given report */
244 #define picolcd_in_report(id, dev) picolcd_report(id, dev, HID_INPUT_REPORT)
245 #define picolcd_out_report(id, dev) picolcd_report(id, dev, HID_OUTPUT_REPORT)
247 static struct hid_report
*picolcd_report(int id
, struct hid_device
*hdev
, int dir
)
249 struct list_head
*feature_report_list
= &hdev
->report_enum
[dir
].report_list
;
250 struct hid_report
*report
= NULL
;
252 list_for_each_entry(report
, feature_report_list
, list
) {
253 if (report
->id
== id
)
256 dev_warn(&hdev
->dev
, "No report with id 0x%x found\n", id
);
260 #ifdef CONFIG_DEBUG_FS
261 static void picolcd_debug_out_report(struct picolcd_data
*data
,
262 struct hid_device
*hdev
, struct hid_report
*report
);
263 #define usbhid_submit_report(a, b, c) \
265 picolcd_debug_out_report(hid_get_drvdata(a), a, b); \
266 usbhid_submit_report(a, b, c); \
270 /* Submit a report and wait for a reply from device - if device fades away
271 * or does not respond in time, return NULL */
272 static struct picolcd_pending
*picolcd_send_and_wait(struct hid_device
*hdev
,
273 int report_id
, const u8
*raw_data
, int size
)
275 struct picolcd_data
*data
= hid_get_drvdata(hdev
);
276 struct picolcd_pending
*work
;
277 struct hid_report
*report
= picolcd_out_report(report_id
, hdev
);
281 if (!report
|| !data
)
283 if (data
->status
& PICOLCD_FAILED
)
285 work
= kzalloc(sizeof(*work
), GFP_KERNEL
);
289 init_completion(&work
->ready
);
290 work
->out_report
= report
;
291 work
->in_report
= NULL
;
294 mutex_lock(&data
->mutex
);
295 spin_lock_irqsave(&data
->lock
, flags
);
296 for (i
= k
= 0; i
< report
->maxfield
; i
++)
297 for (j
= 0; j
< report
->field
[i
]->report_count
; j
++) {
298 hid_set_field(report
->field
[i
], j
, k
< size
? raw_data
[k
] : 0);
301 data
->pending
= work
;
302 usbhid_submit_report(data
->hdev
, report
, USB_DIR_OUT
);
303 spin_unlock_irqrestore(&data
->lock
, flags
);
304 wait_for_completion_interruptible_timeout(&work
->ready
, HZ
*2);
305 spin_lock_irqsave(&data
->lock
, flags
);
306 data
->pending
= NULL
;
307 spin_unlock_irqrestore(&data
->lock
, flags
);
308 mutex_unlock(&data
->mutex
);
312 #ifdef CONFIG_HID_PICOLCD_FB
313 /* Send a given tile to PicoLCD */
314 static int picolcd_fb_send_tile(struct hid_device
*hdev
, int chip
, int tile
)
316 struct picolcd_data
*data
= hid_get_drvdata(hdev
);
317 struct hid_report
*report1
= picolcd_out_report(REPORT_LCD_CMD_DATA
, hdev
);
318 struct hid_report
*report2
= picolcd_out_report(REPORT_LCD_DATA
, hdev
);
323 if (!report1
|| report1
->maxfield
!= 1 || !report2
|| report2
->maxfield
!= 1)
326 spin_lock_irqsave(&data
->lock
, flags
);
327 hid_set_field(report1
->field
[0], 0, chip
<< 2);
328 hid_set_field(report1
->field
[0], 1, 0x02);
329 hid_set_field(report1
->field
[0], 2, 0x00);
330 hid_set_field(report1
->field
[0], 3, 0x00);
331 hid_set_field(report1
->field
[0], 4, 0xb8 | tile
);
332 hid_set_field(report1
->field
[0], 5, 0x00);
333 hid_set_field(report1
->field
[0], 6, 0x00);
334 hid_set_field(report1
->field
[0], 7, 0x40);
335 hid_set_field(report1
->field
[0], 8, 0x00);
336 hid_set_field(report1
->field
[0], 9, 0x00);
337 hid_set_field(report1
->field
[0], 10, 32);
339 hid_set_field(report2
->field
[0], 0, (chip
<< 2) | 0x01);
340 hid_set_field(report2
->field
[0], 1, 0x00);
341 hid_set_field(report2
->field
[0], 2, 0x00);
342 hid_set_field(report2
->field
[0], 3, 32);
344 tdata
= data
->fb_vbitmap
+ (tile
* 4 + chip
) * 64;
345 for (i
= 0; i
< 64; i
++)
347 hid_set_field(report1
->field
[0], 11 + i
, tdata
[i
]);
349 hid_set_field(report2
->field
[0], 4 + i
- 32, tdata
[i
]);
351 usbhid_submit_report(data
->hdev
, report1
, USB_DIR_OUT
);
352 usbhid_submit_report(data
->hdev
, report2
, USB_DIR_OUT
);
353 spin_unlock_irqrestore(&data
->lock
, flags
);
357 /* Translate a single tile*/
358 static int picolcd_fb_update_tile(u8
*vbitmap
, const u8
*bitmap
, int bpp
,
361 int i
, b
, changed
= 0;
363 u8
*vdata
= vbitmap
+ (tile
* 4 + chip
) * 64;
366 for (b
= 7; b
>= 0; b
--) {
367 const u8
*bdata
= bitmap
+ tile
* 256 + chip
* 8 + b
* 32;
368 for (i
= 0; i
< 64; i
++) {
370 tdata
[i
] |= (bdata
[i
/8] >> (i
% 8)) & 0x01;
373 } else if (bpp
== 8) {
374 for (b
= 7; b
>= 0; b
--) {
375 const u8
*bdata
= bitmap
+ (tile
* 256 + chip
* 8 + b
* 32) * 8;
376 for (i
= 0; i
< 64; i
++) {
378 tdata
[i
] |= (bdata
[i
] & 0x80) ? 0x01 : 0x00;
382 /* Oops, we should never get here! */
387 for (i
= 0; i
< 64; i
++)
388 if (tdata
[i
] != vdata
[i
]) {
395 /* Reconfigure LCD display */
396 static int picolcd_fb_reset(struct picolcd_data
*data
, int clear
)
398 struct hid_report
*report
= picolcd_out_report(REPORT_LCD_CMD
, data
->hdev
);
401 static const u8 mapcmd
[8] = { 0x00, 0x02, 0x00, 0x64, 0x3f, 0x00, 0x64, 0xc0 };
403 if (!report
|| report
->maxfield
!= 1)
406 spin_lock_irqsave(&data
->lock
, flags
);
407 for (i
= 0; i
< 4; i
++) {
408 for (j
= 0; j
< report
->field
[0]->maxusage
; j
++)
410 hid_set_field(report
->field
[0], j
, i
<< 2);
411 else if (j
< sizeof(mapcmd
))
412 hid_set_field(report
->field
[0], j
, mapcmd
[j
]);
414 hid_set_field(report
->field
[0], j
, 0);
415 usbhid_submit_report(data
->hdev
, report
, USB_DIR_OUT
);
418 data
->status
|= PICOLCD_READY_FB
;
419 spin_unlock_irqrestore(&data
->lock
, flags
);
421 if (data
->fb_bitmap
) {
423 memset(data
->fb_vbitmap
, 0, PICOLCDFB_SIZE
);
424 memset(data
->fb_bitmap
, 0, PICOLCDFB_SIZE
*data
->fb_bpp
);
429 /* schedule first output of framebuffer */
431 schedule_delayed_work(&data
->fb_info
->deferred_work
, 0);
436 /* Update fb_vbitmap from the screen_base and send changed tiles to device */
437 static void picolcd_fb_update(struct picolcd_data
*data
)
445 spin_lock_irqsave(&data
->lock
, flags
);
446 if (!(data
->status
& PICOLCD_READY_FB
)) {
447 spin_unlock_irqrestore(&data
->lock
, flags
);
448 picolcd_fb_reset(data
, 0);
450 spin_unlock_irqrestore(&data
->lock
, flags
);
454 * Translate the framebuffer into the format needed by the PicoLCD.
455 * See display layout above.
456 * Do this one tile after the other and push those tiles that changed.
458 * Wait for our IO to complete as otherwise we might flood the queue!
461 for (chip
= 0; chip
< 4; chip
++)
462 for (tile
= 0; tile
< 8; tile
++)
463 if (picolcd_fb_update_tile(data
->fb_vbitmap
,
464 data
->fb_bitmap
, data
->fb_bpp
, chip
, tile
) ||
467 if (!data
->fb_info
->par
)
468 return; /* device lost! */
469 if (n
>= HID_OUTPUT_FIFO_SIZE
/ 2) {
470 usbhid_wait_io(data
->hdev
);
473 picolcd_fb_send_tile(data
->hdev
, chip
, tile
);
475 data
->fb_force
= false;
477 usbhid_wait_io(data
->hdev
);
480 /* Stub to call the system default and update the image on the picoLCD */
481 static void picolcd_fb_fillrect(struct fb_info
*info
,
482 const struct fb_fillrect
*rect
)
486 sys_fillrect(info
, rect
);
488 schedule_delayed_work(&info
->deferred_work
, 0);
491 /* Stub to call the system default and update the image on the picoLCD */
492 static void picolcd_fb_copyarea(struct fb_info
*info
,
493 const struct fb_copyarea
*area
)
497 sys_copyarea(info
, area
);
499 schedule_delayed_work(&info
->deferred_work
, 0);
502 /* Stub to call the system default and update the image on the picoLCD */
503 static void picolcd_fb_imageblit(struct fb_info
*info
, const struct fb_image
*image
)
507 sys_imageblit(info
, image
);
509 schedule_delayed_work(&info
->deferred_work
, 0);
513 * this is the slow path from userspace. they can seek and write to
514 * the fb. it's inefficient to do anything less than a full screen draw
516 static ssize_t
picolcd_fb_write(struct fb_info
*info
, const char __user
*buf
,
517 size_t count
, loff_t
*ppos
)
522 ret
= fb_sys_write(info
, buf
, count
, ppos
);
524 schedule_delayed_work(&info
->deferred_work
, 0);
528 static int picolcd_fb_blank(int blank
, struct fb_info
*info
)
532 /* We let fb notification do this for us via lcd/backlight device */
536 static void picolcd_fb_destroy(struct fb_info
*info
)
538 struct picolcd_data
*data
= info
->par
;
539 u32
*ref_cnt
= info
->pseudo_palette
;
544 data
->fb_info
= NULL
;
545 fb_deferred_io_cleanup(info
);
548 mutex_lock(&info
->lock
);
550 may_release
= !*ref_cnt
;
551 mutex_unlock(&info
->lock
);
553 vfree((u8
*)info
->fix
.smem_start
);
554 framebuffer_release(info
);
558 static int picolcd_fb_check_var(struct fb_var_screeninfo
*var
, struct fb_info
*info
)
560 __u32 bpp
= var
->bits_per_pixel
;
561 __u32 activate
= var
->activate
;
563 /* only allow 1/8 bit depth (8-bit is grayscale) */
564 *var
= picolcdfb_var
;
565 var
->activate
= activate
;
567 var
->bits_per_pixel
= 8;
569 var
->green
.length
= 8;
570 var
->blue
.length
= 8;
572 var
->bits_per_pixel
= 1;
574 var
->green
.length
= 1;
575 var
->blue
.length
= 1;
580 static int picolcd_set_par(struct fb_info
*info
)
582 struct picolcd_data
*data
= info
->par
;
586 if (info
->var
.bits_per_pixel
== data
->fb_bpp
)
588 /* switch between 1/8 bit depths */
589 if (info
->var
.bits_per_pixel
!= 1 && info
->var
.bits_per_pixel
!= 8)
592 o_fb
= data
->fb_bitmap
;
593 tmp_fb
= kmalloc(PICOLCDFB_SIZE
*info
->var
.bits_per_pixel
, GFP_KERNEL
);
597 /* translate FB content to new bits-per-pixel */
598 if (info
->var
.bits_per_pixel
== 1) {
600 for (i
= 0; i
< PICOLCDFB_SIZE
; i
++) {
602 for (b
= 0; b
< 8; b
++) {
604 p
|= o_fb
[i
*8+b
] ? 0x01 : 0x00;
608 memcpy(o_fb
, tmp_fb
, PICOLCDFB_SIZE
);
609 info
->fix
.visual
= FB_VISUAL_MONO01
;
610 info
->fix
.line_length
= PICOLCDFB_WIDTH
/ 8;
613 memcpy(tmp_fb
, o_fb
, PICOLCDFB_SIZE
);
614 for (i
= 0; i
< PICOLCDFB_SIZE
* 8; i
++)
615 o_fb
[i
] = tmp_fb
[i
/8] & (0x01 << (7 - i
% 8)) ? 0xff : 0x00;
616 info
->fix
.visual
= FB_VISUAL_DIRECTCOLOR
;
617 info
->fix
.line_length
= PICOLCDFB_WIDTH
;
621 data
->fb_bpp
= info
->var
.bits_per_pixel
;
625 /* Do refcounting on our FB and cleanup per worker if FB is
626 * closed after unplug of our device
627 * (fb_release holds info->lock and still touches info after
628 * we return so we can't release it immediately.
630 struct picolcd_fb_cleanup_item
{
631 struct fb_info
*info
;
632 struct picolcd_fb_cleanup_item
*next
;
634 static struct picolcd_fb_cleanup_item
*fb_pending
;
635 DEFINE_SPINLOCK(fb_pending_lock
);
637 static void picolcd_fb_do_cleanup(struct work_struct
*data
)
639 struct picolcd_fb_cleanup_item
*item
;
643 spin_lock_irqsave(&fb_pending_lock
, flags
);
645 fb_pending
= item
? item
->next
: NULL
;
646 spin_unlock_irqrestore(&fb_pending_lock
, flags
);
649 u8
*fb
= (u8
*)item
->info
->fix
.smem_start
;
650 /* make sure we do not race against fb core when
652 mutex_lock(&item
->info
->lock
);
653 mutex_unlock(&item
->info
->lock
);
654 framebuffer_release(item
->info
);
660 DECLARE_WORK(picolcd_fb_cleanup
, picolcd_fb_do_cleanup
);
662 static int picolcd_fb_open(struct fb_info
*info
, int u
)
664 u32
*ref_cnt
= info
->pseudo_palette
;
671 static int picolcd_fb_release(struct fb_info
*info
, int u
)
673 u32
*ref_cnt
= info
->pseudo_palette
;
679 struct picolcd_fb_cleanup_item
*item
= (struct picolcd_fb_cleanup_item
*)ref_cnt
;
681 spin_lock_irqsave(&fb_pending_lock
, flags
);
682 item
->next
= fb_pending
;
684 spin_unlock_irqrestore(&fb_pending_lock
, flags
);
685 schedule_work(&picolcd_fb_cleanup
);
690 /* Note this can't be const because of struct fb_info definition */
691 static struct fb_ops picolcdfb_ops
= {
692 .owner
= THIS_MODULE
,
693 .fb_destroy
= picolcd_fb_destroy
,
694 .fb_open
= picolcd_fb_open
,
695 .fb_release
= picolcd_fb_release
,
696 .fb_read
= fb_sys_read
,
697 .fb_write
= picolcd_fb_write
,
698 .fb_blank
= picolcd_fb_blank
,
699 .fb_fillrect
= picolcd_fb_fillrect
,
700 .fb_copyarea
= picolcd_fb_copyarea
,
701 .fb_imageblit
= picolcd_fb_imageblit
,
702 .fb_check_var
= picolcd_fb_check_var
,
703 .fb_set_par
= picolcd_set_par
,
707 /* Callback from deferred IO workqueue */
708 static void picolcd_fb_deferred_io(struct fb_info
*info
, struct list_head
*pagelist
)
710 picolcd_fb_update(info
->par
);
713 static const struct fb_deferred_io picolcd_fb_defio
= {
714 .delay
= HZ
/ PICOLCDFB_UPDATE_RATE_DEFAULT
,
715 .deferred_io
= picolcd_fb_deferred_io
,
720 * The "fb_update_rate" sysfs attribute
722 static ssize_t
picolcd_fb_update_rate_show(struct device
*dev
,
723 struct device_attribute
*attr
, char *buf
)
725 struct picolcd_data
*data
= dev_get_drvdata(dev
);
726 unsigned i
, fb_update_rate
= data
->fb_update_rate
;
729 for (i
= 1; i
<= PICOLCDFB_UPDATE_RATE_LIMIT
; i
++)
730 if (ret
>= PAGE_SIZE
)
732 else if (i
== fb_update_rate
)
733 ret
+= snprintf(buf
+ret
, PAGE_SIZE
-ret
, "[%u] ", i
);
735 ret
+= snprintf(buf
+ret
, PAGE_SIZE
-ret
, "%u ", i
);
737 buf
[min(ret
, (size_t)PAGE_SIZE
)-1] = '\n';
741 static ssize_t
picolcd_fb_update_rate_store(struct device
*dev
,
742 struct device_attribute
*attr
, const char *buf
, size_t count
)
744 struct picolcd_data
*data
= dev_get_drvdata(dev
);
748 if (count
< 1 || count
> 10)
751 i
= sscanf(buf
, "%u", &u
);
755 if (u
> PICOLCDFB_UPDATE_RATE_LIMIT
)
758 u
= PICOLCDFB_UPDATE_RATE_DEFAULT
;
760 data
->fb_update_rate
= u
;
761 data
->fb_defio
.delay
= HZ
/ data
->fb_update_rate
;
765 static DEVICE_ATTR(fb_update_rate
, 0666, picolcd_fb_update_rate_show
,
766 picolcd_fb_update_rate_store
);
768 /* initialize Framebuffer device */
769 static int picolcd_init_framebuffer(struct picolcd_data
*data
)
771 struct device
*dev
= &data
->hdev
->dev
;
772 struct fb_info
*info
= NULL
;
773 int i
, error
= -ENOMEM
;
774 u8
*fb_vbitmap
= NULL
;
775 u8
*fb_bitmap
= NULL
;
778 fb_bitmap
= vmalloc(PICOLCDFB_SIZE
*8);
779 if (fb_bitmap
== NULL
) {
780 dev_err(dev
, "can't get a free page for framebuffer\n");
784 fb_vbitmap
= kmalloc(PICOLCDFB_SIZE
, GFP_KERNEL
);
785 if (fb_vbitmap
== NULL
) {
786 dev_err(dev
, "can't alloc vbitmap image buffer\n");
790 data
->fb_update_rate
= PICOLCDFB_UPDATE_RATE_DEFAULT
;
791 data
->fb_defio
= picolcd_fb_defio
;
792 /* The extra memory is:
793 * - struct picolcd_fb_cleanup_item
794 * - u32 for ref_count
795 * - 256*u32 for pseudo_palette
797 info
= framebuffer_alloc(257 * sizeof(u32
) + sizeof(struct picolcd_fb_cleanup_item
), dev
);
799 dev_err(dev
, "failed to allocate a framebuffer\n");
803 palette
= info
->par
+ sizeof(struct picolcd_fb_cleanup_item
);
806 for (i
= 0; i
< 256; i
++)
807 palette
[i
] = i
> 0 && i
< 16 ? 0xff : 0;
808 info
->pseudo_palette
= palette
;
809 info
->fbdefio
= &data
->fb_defio
;
810 info
->screen_base
= (char __force __iomem
*)fb_bitmap
;
811 info
->fbops
= &picolcdfb_ops
;
812 info
->var
= picolcdfb_var
;
813 info
->fix
= picolcdfb_fix
;
814 info
->fix
.smem_len
= PICOLCDFB_SIZE
*8;
815 info
->fix
.smem_start
= (unsigned long)fb_bitmap
;
817 info
->flags
= FBINFO_FLAG_DEFAULT
;
819 data
->fb_vbitmap
= fb_vbitmap
;
820 data
->fb_bitmap
= fb_bitmap
;
821 data
->fb_bpp
= picolcdfb_var
.bits_per_pixel
;
822 error
= picolcd_fb_reset(data
, 1);
824 dev_err(dev
, "failed to configure display\n");
827 error
= device_create_file(dev
, &dev_attr_fb_update_rate
);
829 dev_err(dev
, "failed to create sysfs attributes\n");
832 fb_deferred_io_init(info
);
833 data
->fb_info
= info
;
834 error
= register_framebuffer(info
);
836 dev_err(dev
, "failed to register framebuffer\n");
839 /* schedule first output of framebuffer */
841 schedule_delayed_work(&info
->deferred_work
, 0);
845 fb_deferred_io_cleanup(info
);
846 device_remove_file(dev
, &dev_attr_fb_update_rate
);
848 data
->fb_vbitmap
= NULL
;
849 data
->fb_bitmap
= NULL
;
851 data
->fb_info
= NULL
;
854 framebuffer_release(info
);
860 static void picolcd_exit_framebuffer(struct picolcd_data
*data
)
862 struct fb_info
*info
= data
->fb_info
;
863 u8
*fb_vbitmap
= data
->fb_vbitmap
;
869 device_remove_file(&data
->hdev
->dev
, &dev_attr_fb_update_rate
);
870 unregister_framebuffer(info
);
871 data
->fb_vbitmap
= NULL
;
872 data
->fb_bitmap
= NULL
;
874 data
->fb_info
= NULL
;
878 #define picolcd_fbinfo(d) ((d)->fb_info)
880 static inline int picolcd_fb_reset(struct picolcd_data
*data
, int clear
)
884 static inline int picolcd_init_framebuffer(struct picolcd_data
*data
)
888 static inline void picolcd_exit_framebuffer(struct picolcd_data
*data
)
891 #define picolcd_fbinfo(d) NULL
892 #endif /* CONFIG_HID_PICOLCD_FB */
894 #ifdef CONFIG_HID_PICOLCD_BACKLIGHT
896 * backlight class device
898 static int picolcd_get_brightness(struct backlight_device
*bdev
)
900 struct picolcd_data
*data
= bl_get_data(bdev
);
901 return data
->lcd_brightness
;
904 static int picolcd_set_brightness(struct backlight_device
*bdev
)
906 struct picolcd_data
*data
= bl_get_data(bdev
);
907 struct hid_report
*report
= picolcd_out_report(REPORT_BRIGHTNESS
, data
->hdev
);
910 if (!report
|| report
->maxfield
!= 1 || report
->field
[0]->report_count
!= 1)
913 data
->lcd_brightness
= bdev
->props
.brightness
& 0x0ff;
914 data
->lcd_power
= bdev
->props
.power
;
915 spin_lock_irqsave(&data
->lock
, flags
);
916 hid_set_field(report
->field
[0], 0, data
->lcd_power
== FB_BLANK_UNBLANK
? data
->lcd_brightness
: 0);
917 usbhid_submit_report(data
->hdev
, report
, USB_DIR_OUT
);
918 spin_unlock_irqrestore(&data
->lock
, flags
);
922 static int picolcd_check_bl_fb(struct backlight_device
*bdev
, struct fb_info
*fb
)
924 return fb
&& fb
== picolcd_fbinfo((struct picolcd_data
*)bl_get_data(bdev
));
927 static const struct backlight_ops picolcd_blops
= {
928 .update_status
= picolcd_set_brightness
,
929 .get_brightness
= picolcd_get_brightness
,
930 .check_fb
= picolcd_check_bl_fb
,
933 static int picolcd_init_backlight(struct picolcd_data
*data
, struct hid_report
*report
)
935 struct device
*dev
= &data
->hdev
->dev
;
936 struct backlight_device
*bdev
;
937 struct backlight_properties props
;
940 if (report
->maxfield
!= 1 || report
->field
[0]->report_count
!= 1 ||
941 report
->field
[0]->report_size
!= 8) {
942 dev_err(dev
, "unsupported BRIGHTNESS report");
946 memset(&props
, 0, sizeof(props
));
947 props
.max_brightness
= 0xff;
948 bdev
= backlight_device_register(dev_name(dev
), dev
, data
,
949 &picolcd_blops
, &props
);
951 dev_err(dev
, "failed to register backlight\n");
952 return PTR_ERR(bdev
);
954 bdev
->props
.brightness
= 0xff;
955 data
->lcd_brightness
= 0xff;
956 data
->backlight
= bdev
;
957 picolcd_set_brightness(bdev
);
961 static void picolcd_exit_backlight(struct picolcd_data
*data
)
963 struct backlight_device
*bdev
= data
->backlight
;
965 data
->backlight
= NULL
;
967 backlight_device_unregister(bdev
);
970 static inline int picolcd_resume_backlight(struct picolcd_data
*data
)
972 if (!data
->backlight
)
974 return picolcd_set_brightness(data
->backlight
);
978 static void picolcd_suspend_backlight(struct picolcd_data
*data
)
980 int bl_power
= data
->lcd_power
;
981 if (!data
->backlight
)
984 data
->backlight
->props
.power
= FB_BLANK_POWERDOWN
;
985 picolcd_set_brightness(data
->backlight
);
986 data
->lcd_power
= data
->backlight
->props
.power
= bl_power
;
988 #endif /* CONFIG_PM */
990 static inline int picolcd_init_backlight(struct picolcd_data
*data
,
991 struct hid_report
*report
)
995 static inline void picolcd_exit_backlight(struct picolcd_data
*data
)
998 static inline int picolcd_resume_backlight(struct picolcd_data
*data
)
1002 static inline void picolcd_suspend_backlight(struct picolcd_data
*data
)
1005 #endif /* CONFIG_HID_PICOLCD_BACKLIGHT */
1007 #ifdef CONFIG_HID_PICOLCD_LCD
1011 static int picolcd_get_contrast(struct lcd_device
*ldev
)
1013 struct picolcd_data
*data
= lcd_get_data(ldev
);
1014 return data
->lcd_contrast
;
1017 static int picolcd_set_contrast(struct lcd_device
*ldev
, int contrast
)
1019 struct picolcd_data
*data
= lcd_get_data(ldev
);
1020 struct hid_report
*report
= picolcd_out_report(REPORT_CONTRAST
, data
->hdev
);
1021 unsigned long flags
;
1023 if (!report
|| report
->maxfield
!= 1 || report
->field
[0]->report_count
!= 1)
1026 data
->lcd_contrast
= contrast
& 0x0ff;
1027 spin_lock_irqsave(&data
->lock
, flags
);
1028 hid_set_field(report
->field
[0], 0, data
->lcd_contrast
);
1029 usbhid_submit_report(data
->hdev
, report
, USB_DIR_OUT
);
1030 spin_unlock_irqrestore(&data
->lock
, flags
);
1034 static int picolcd_check_lcd_fb(struct lcd_device
*ldev
, struct fb_info
*fb
)
1036 return fb
&& fb
== picolcd_fbinfo((struct picolcd_data
*)lcd_get_data(ldev
));
1039 static struct lcd_ops picolcd_lcdops
= {
1040 .get_contrast
= picolcd_get_contrast
,
1041 .set_contrast
= picolcd_set_contrast
,
1042 .check_fb
= picolcd_check_lcd_fb
,
1045 static int picolcd_init_lcd(struct picolcd_data
*data
, struct hid_report
*report
)
1047 struct device
*dev
= &data
->hdev
->dev
;
1048 struct lcd_device
*ldev
;
1052 if (report
->maxfield
!= 1 || report
->field
[0]->report_count
!= 1 ||
1053 report
->field
[0]->report_size
!= 8) {
1054 dev_err(dev
, "unsupported CONTRAST report");
1058 ldev
= lcd_device_register(dev_name(dev
), dev
, data
, &picolcd_lcdops
);
1060 dev_err(dev
, "failed to register LCD\n");
1061 return PTR_ERR(ldev
);
1063 ldev
->props
.max_contrast
= 0x0ff;
1064 data
->lcd_contrast
= 0xe5;
1066 picolcd_set_contrast(ldev
, 0xe5);
1070 static void picolcd_exit_lcd(struct picolcd_data
*data
)
1072 struct lcd_device
*ldev
= data
->lcd
;
1076 lcd_device_unregister(ldev
);
1079 static inline int picolcd_resume_lcd(struct picolcd_data
*data
)
1083 return picolcd_set_contrast(data
->lcd
, data
->lcd_contrast
);
1086 static inline int picolcd_init_lcd(struct picolcd_data
*data
,
1087 struct hid_report
*report
)
1091 static inline void picolcd_exit_lcd(struct picolcd_data
*data
)
1094 static inline int picolcd_resume_lcd(struct picolcd_data
*data
)
1098 #endif /* CONFIG_HID_PICOLCD_LCD */
1100 #ifdef CONFIG_HID_PICOLCD_LEDS
1104 static void picolcd_leds_set(struct picolcd_data
*data
)
1106 struct hid_report
*report
;
1107 unsigned long flags
;
1111 report
= picolcd_out_report(REPORT_LED_STATE
, data
->hdev
);
1112 if (!report
|| report
->maxfield
!= 1 || report
->field
[0]->report_count
!= 1)
1115 spin_lock_irqsave(&data
->lock
, flags
);
1116 hid_set_field(report
->field
[0], 0, data
->led_state
);
1117 usbhid_submit_report(data
->hdev
, report
, USB_DIR_OUT
);
1118 spin_unlock_irqrestore(&data
->lock
, flags
);
1121 static void picolcd_led_set_brightness(struct led_classdev
*led_cdev
,
1122 enum led_brightness value
)
1125 struct hid_device
*hdev
;
1126 struct picolcd_data
*data
;
1129 dev
= led_cdev
->dev
->parent
;
1130 hdev
= container_of(dev
, struct hid_device
, dev
);
1131 data
= hid_get_drvdata(hdev
);
1132 for (i
= 0; i
< 8; i
++) {
1133 if (led_cdev
!= data
->led
[i
])
1135 state
= (data
->led_state
>> i
) & 1;
1136 if (value
== LED_OFF
&& state
) {
1137 data
->led_state
&= ~(1 << i
);
1138 picolcd_leds_set(data
);
1139 } else if (value
!= LED_OFF
&& !state
) {
1140 data
->led_state
|= 1 << i
;
1141 picolcd_leds_set(data
);
1147 static enum led_brightness
picolcd_led_get_brightness(struct led_classdev
*led_cdev
)
1150 struct hid_device
*hdev
;
1151 struct picolcd_data
*data
;
1154 dev
= led_cdev
->dev
->parent
;
1155 hdev
= container_of(dev
, struct hid_device
, dev
);
1156 data
= hid_get_drvdata(hdev
);
1157 for (i
= 0; i
< 8; i
++)
1158 if (led_cdev
== data
->led
[i
]) {
1159 value
= (data
->led_state
>> i
) & 1;
1162 return value
? LED_FULL
: LED_OFF
;
1165 static int picolcd_init_leds(struct picolcd_data
*data
, struct hid_report
*report
)
1167 struct device
*dev
= &data
->hdev
->dev
;
1168 struct led_classdev
*led
;
1169 size_t name_sz
= strlen(dev_name(dev
)) + 8;
1175 if (report
->maxfield
!= 1 || report
->field
[0]->report_count
!= 1 ||
1176 report
->field
[0]->report_size
!= 8) {
1177 dev_err(dev
, "unsupported LED_STATE report");
1181 for (i
= 0; i
< 8; i
++) {
1182 led
= kzalloc(sizeof(struct led_classdev
)+name_sz
, GFP_KERNEL
);
1184 dev_err(dev
, "can't allocate memory for LED %d\n", i
);
1188 name
= (void *)(&led
[1]);
1189 snprintf(name
, name_sz
, "%s::GPO%d", dev_name(dev
), i
);
1191 led
->brightness
= 0;
1192 led
->max_brightness
= 1;
1193 led
->brightness_get
= picolcd_led_get_brightness
;
1194 led
->brightness_set
= picolcd_led_set_brightness
;
1197 ret
= led_classdev_register(dev
, data
->led
[i
]);
1199 data
->led
[i
] = NULL
;
1201 dev_err(dev
, "can't register LED %d\n", i
);
1207 for (i
= 0; i
< 8; i
++)
1210 data
->led
[i
] = NULL
;
1211 led_classdev_unregister(led
);
1217 static void picolcd_exit_leds(struct picolcd_data
*data
)
1219 struct led_classdev
*led
;
1222 for (i
= 0; i
< 8; i
++) {
1224 data
->led
[i
] = NULL
;
1227 led_classdev_unregister(led
);
1233 static inline int picolcd_init_leds(struct picolcd_data
*data
,
1234 struct hid_report
*report
)
1238 static inline void picolcd_exit_leds(struct picolcd_data
*data
)
1241 static inline int picolcd_leds_set(struct picolcd_data
*data
)
1245 #endif /* CONFIG_HID_PICOLCD_LEDS */
1248 * input class device
1250 static int picolcd_raw_keypad(struct picolcd_data
*data
,
1251 struct hid_report
*report
, u8
*raw_data
, int size
)
1255 * First and second data bytes list currently pressed keys,
1256 * 0x00 means no key and at most 2 keys may be pressed at same time
1260 /* determine newly pressed keys */
1261 for (i
= 0; i
< size
; i
++) {
1262 unsigned int key_code
;
1263 if (raw_data
[i
] == 0)
1265 for (j
= 0; j
< sizeof(data
->pressed_keys
); j
++)
1266 if (data
->pressed_keys
[j
] == raw_data
[i
])
1267 goto key_already_down
;
1268 for (j
= 0; j
< sizeof(data
->pressed_keys
); j
++)
1269 if (data
->pressed_keys
[j
] == 0) {
1270 data
->pressed_keys
[j
] = raw_data
[i
];
1273 input_event(data
->input_keys
, EV_MSC
, MSC_SCAN
, raw_data
[i
]);
1274 if (raw_data
[i
] < PICOLCD_KEYS
)
1275 key_code
= data
->keycode
[raw_data
[i
]];
1277 key_code
= KEY_UNKNOWN
;
1278 if (key_code
!= KEY_UNKNOWN
) {
1279 dbg_hid(PICOLCD_NAME
" got key press for %u:%d",
1280 raw_data
[i
], key_code
);
1281 input_report_key(data
->input_keys
, key_code
, 1);
1283 input_sync(data
->input_keys
);
1288 /* determine newly released keys */
1289 for (j
= 0; j
< sizeof(data
->pressed_keys
); j
++) {
1290 unsigned int key_code
;
1291 if (data
->pressed_keys
[j
] == 0)
1293 for (i
= 0; i
< size
; i
++)
1294 if (data
->pressed_keys
[j
] == raw_data
[i
])
1295 goto key_still_down
;
1296 input_event(data
->input_keys
, EV_MSC
, MSC_SCAN
, data
->pressed_keys
[j
]);
1297 if (data
->pressed_keys
[j
] < PICOLCD_KEYS
)
1298 key_code
= data
->keycode
[data
->pressed_keys
[j
]];
1300 key_code
= KEY_UNKNOWN
;
1301 if (key_code
!= KEY_UNKNOWN
) {
1302 dbg_hid(PICOLCD_NAME
" got key release for %u:%d",
1303 data
->pressed_keys
[j
], key_code
);
1304 input_report_key(data
->input_keys
, key_code
, 0);
1306 input_sync(data
->input_keys
);
1307 data
->pressed_keys
[j
] = 0;
1314 static int picolcd_raw_cir(struct picolcd_data
*data
,
1315 struct hid_report
*report
, u8
*raw_data
, int size
)
1317 /* Need understanding of CIR data format to implement ... */
1321 static int picolcd_check_version(struct hid_device
*hdev
)
1323 struct picolcd_data
*data
= hid_get_drvdata(hdev
);
1324 struct picolcd_pending
*verinfo
;
1330 verinfo
= picolcd_send_and_wait(hdev
, REPORT_VERSION
, NULL
, 0);
1332 dev_err(&hdev
->dev
, "no version response from PicoLCD");
1336 if (verinfo
->raw_size
== 2) {
1337 data
->version
[0] = verinfo
->raw_data
[1];
1338 data
->version
[1] = verinfo
->raw_data
[0];
1339 if (data
->status
& PICOLCD_BOOTLOADER
) {
1340 dev_info(&hdev
->dev
, "PicoLCD, bootloader version %d.%d\n",
1341 verinfo
->raw_data
[1], verinfo
->raw_data
[0]);
1343 dev_info(&hdev
->dev
, "PicoLCD, firmware version %d.%d\n",
1344 verinfo
->raw_data
[1], verinfo
->raw_data
[0]);
1347 dev_err(&hdev
->dev
, "confused, got unexpected version response from PicoLCD\n");
1355 * Reset our device and wait for answer to VERSION request
1357 static int picolcd_reset(struct hid_device
*hdev
)
1359 struct picolcd_data
*data
= hid_get_drvdata(hdev
);
1360 struct hid_report
*report
= picolcd_out_report(REPORT_RESET
, hdev
);
1361 unsigned long flags
;
1364 if (!data
|| !report
|| report
->maxfield
!= 1)
1367 spin_lock_irqsave(&data
->lock
, flags
);
1368 if (hdev
->product
== USB_DEVICE_ID_PICOLCD_BOOTLOADER
)
1369 data
->status
|= PICOLCD_BOOTLOADER
;
1371 /* perform the reset */
1372 hid_set_field(report
->field
[0], 0, 1);
1373 usbhid_submit_report(hdev
, report
, USB_DIR_OUT
);
1374 spin_unlock_irqrestore(&data
->lock
, flags
);
1376 error
= picolcd_check_version(hdev
);
1380 picolcd_resume_lcd(data
);
1381 picolcd_resume_backlight(data
);
1382 #ifdef CONFIG_HID_PICOLCD_FB
1384 schedule_delayed_work(&data
->fb_info
->deferred_work
, 0);
1385 #endif /* CONFIG_HID_PICOLCD_FB */
1387 picolcd_leds_set(data
);
1392 * The "operation_mode" sysfs attribute
1394 static ssize_t
picolcd_operation_mode_show(struct device
*dev
,
1395 struct device_attribute
*attr
, char *buf
)
1397 struct picolcd_data
*data
= dev_get_drvdata(dev
);
1399 if (data
->status
& PICOLCD_BOOTLOADER
)
1400 return snprintf(buf
, PAGE_SIZE
, "[bootloader] lcd\n");
1402 return snprintf(buf
, PAGE_SIZE
, "bootloader [lcd]\n");
1405 static ssize_t
picolcd_operation_mode_store(struct device
*dev
,
1406 struct device_attribute
*attr
, const char *buf
, size_t count
)
1408 struct picolcd_data
*data
= dev_get_drvdata(dev
);
1409 struct hid_report
*report
= NULL
;
1411 int timeout
= data
->opmode_delay
;
1412 unsigned long flags
;
1414 if (cnt
>= 3 && strncmp("lcd", buf
, 3) == 0) {
1415 if (data
->status
& PICOLCD_BOOTLOADER
)
1416 report
= picolcd_out_report(REPORT_EXIT_FLASHER
, data
->hdev
);
1419 } else if (cnt
>= 10 && strncmp("bootloader", buf
, 10) == 0) {
1420 if (!(data
->status
& PICOLCD_BOOTLOADER
))
1421 report
= picolcd_out_report(REPORT_EXIT_KEYBOARD
, data
->hdev
);
1428 while (cnt
> 0 && (buf
[cnt
-1] == '\n' || buf
[cnt
-1] == '\r'))
1433 spin_lock_irqsave(&data
->lock
, flags
);
1434 hid_set_field(report
->field
[0], 0, timeout
& 0xff);
1435 hid_set_field(report
->field
[0], 1, (timeout
>> 8) & 0xff);
1436 usbhid_submit_report(data
->hdev
, report
, USB_DIR_OUT
);
1437 spin_unlock_irqrestore(&data
->lock
, flags
);
1441 static DEVICE_ATTR(operation_mode
, 0644, picolcd_operation_mode_show
,
1442 picolcd_operation_mode_store
);
1445 * The "operation_mode_delay" sysfs attribute
1447 static ssize_t
picolcd_operation_mode_delay_show(struct device
*dev
,
1448 struct device_attribute
*attr
, char *buf
)
1450 struct picolcd_data
*data
= dev_get_drvdata(dev
);
1452 return snprintf(buf
, PAGE_SIZE
, "%hu\n", data
->opmode_delay
);
1455 static ssize_t
picolcd_operation_mode_delay_store(struct device
*dev
,
1456 struct device_attribute
*attr
, const char *buf
, size_t count
)
1458 struct picolcd_data
*data
= dev_get_drvdata(dev
);
1460 if (sscanf(buf
, "%u", &u
) != 1)
1465 data
->opmode_delay
= u
;
1469 static DEVICE_ATTR(operation_mode_delay
, 0644, picolcd_operation_mode_delay_show
,
1470 picolcd_operation_mode_delay_store
);
1473 #ifdef CONFIG_DEBUG_FS
1477 static int picolcd_debug_reset_show(struct seq_file
*f
, void *p
)
1479 if (picolcd_fbinfo((struct picolcd_data
*)f
->private))
1480 seq_printf(f
, "all fb\n");
1482 seq_printf(f
, "all\n");
1486 static int picolcd_debug_reset_open(struct inode
*inode
, struct file
*f
)
1488 return single_open(f
, picolcd_debug_reset_show
, inode
->i_private
);
1491 static ssize_t
picolcd_debug_reset_write(struct file
*f
, const char __user
*user_buf
,
1492 size_t count
, loff_t
*ppos
)
1494 struct picolcd_data
*data
= ((struct seq_file
*)f
->private_data
)->private;
1496 size_t cnt
= min(count
, sizeof(buf
)-1);
1497 if (copy_from_user(buf
, user_buf
, cnt
))
1500 while (cnt
> 0 && (buf
[cnt
-1] == ' ' || buf
[cnt
-1] == '\n'))
1503 if (strcmp(buf
, "all") == 0) {
1504 picolcd_reset(data
->hdev
);
1505 picolcd_fb_reset(data
, 1);
1506 } else if (strcmp(buf
, "fb") == 0) {
1507 picolcd_fb_reset(data
, 1);
1514 static const struct file_operations picolcd_debug_reset_fops
= {
1515 .owner
= THIS_MODULE
,
1516 .open
= picolcd_debug_reset_open
,
1518 .llseek
= seq_lseek
,
1519 .write
= picolcd_debug_reset_write
,
1520 .release
= single_release
,
1526 static int picolcd_debug_eeprom_open(struct inode
*i
, struct file
*f
)
1528 f
->private_data
= i
->i_private
;
1532 static ssize_t
picolcd_debug_eeprom_read(struct file
*f
, char __user
*u
,
1533 size_t s
, loff_t
*off
)
1535 struct picolcd_data
*data
= f
->private_data
;
1536 struct picolcd_pending
*resp
;
1545 /* prepare buffer with info about what we want to read (addr & len) */
1546 raw_data
[0] = *off
& 0xff;
1547 raw_data
[1] = (*off
>> 8) && 0xff;
1548 raw_data
[2] = s
< 20 ? s
: 20;
1549 if (*off
+ raw_data
[2] > 0xff)
1550 raw_data
[2] = 0x100 - *off
;
1551 resp
= picolcd_send_and_wait(data
->hdev
, REPORT_EE_READ
, raw_data
,
1556 if (resp
->in_report
&& resp
->in_report
->id
== REPORT_EE_DATA
) {
1557 /* successful read :) */
1558 ret
= resp
->raw_data
[2];
1561 if (copy_to_user(u
, resp
->raw_data
+3, ret
))
1565 } /* anything else is some kind of IO error */
1571 static ssize_t
picolcd_debug_eeprom_write(struct file
*f
, const char __user
*u
,
1572 size_t s
, loff_t
*off
)
1574 struct picolcd_data
*data
= f
->private_data
;
1575 struct picolcd_pending
*resp
;
1584 memset(raw_data
, 0, sizeof(raw_data
));
1585 raw_data
[0] = *off
& 0xff;
1586 raw_data
[1] = (*off
>> 8) && 0xff;
1587 raw_data
[2] = s
< 20 ? s
: 20;
1588 if (*off
+ raw_data
[2] > 0xff)
1589 raw_data
[2] = 0x100 - *off
;
1591 if (copy_from_user(raw_data
+3, u
, raw_data
[2]))
1593 resp
= picolcd_send_and_wait(data
->hdev
, REPORT_EE_WRITE
, raw_data
,
1599 if (resp
->in_report
&& resp
->in_report
->id
== REPORT_EE_DATA
) {
1600 /* check if written data matches */
1601 if (memcmp(raw_data
, resp
->raw_data
, 3+raw_data
[2]) == 0) {
1602 *off
+= raw_data
[2];
1612 * - read/write happens in chunks of at most 20 bytes, it's up to userspace
1613 * to loop in order to get more data.
1614 * - on write errors on otherwise correct write request the bytes
1615 * that should have been written are in undefined state.
1617 static const struct file_operations picolcd_debug_eeprom_fops
= {
1618 .owner
= THIS_MODULE
,
1619 .open
= picolcd_debug_eeprom_open
,
1620 .read
= picolcd_debug_eeprom_read
,
1621 .write
= picolcd_debug_eeprom_write
,
1622 .llseek
= generic_file_llseek
,
1628 static int picolcd_debug_flash_open(struct inode
*i
, struct file
*f
)
1630 f
->private_data
= i
->i_private
;
1634 /* record a flash address to buf (bounds check to be done by caller) */
1635 static int _picolcd_flash_setaddr(struct picolcd_data
*data
, u8
*buf
, long off
)
1637 buf
[0] = off
& 0xff;
1638 buf
[1] = (off
>> 8) & 0xff;
1639 if (data
->addr_sz
== 3)
1640 buf
[2] = (off
>> 16) & 0xff;
1641 return data
->addr_sz
== 2 ? 2 : 3;
1644 /* read a given size of data (bounds check to be done by caller) */
1645 static ssize_t
_picolcd_flash_read(struct picolcd_data
*data
, int report_id
,
1646 char __user
*u
, size_t s
, loff_t
*off
)
1648 struct picolcd_pending
*resp
;
1651 int len_off
, err
= -EIO
;
1655 len_off
= _picolcd_flash_setaddr(data
, raw_data
, *off
);
1656 raw_data
[len_off
] = s
> 32 ? 32 : s
;
1657 resp
= picolcd_send_and_wait(data
->hdev
, report_id
, raw_data
, len_off
+1);
1658 if (!resp
|| !resp
->in_report
)
1660 if (resp
->in_report
->id
== REPORT_MEMORY
||
1661 resp
->in_report
->id
== REPORT_BL_READ_MEMORY
) {
1662 if (memcmp(raw_data
, resp
->raw_data
, len_off
+1) != 0)
1664 if (copy_to_user(u
+ret
, resp
->raw_data
+len_off
+1, raw_data
[len_off
])) {
1668 *off
+= raw_data
[len_off
];
1669 s
-= raw_data
[len_off
];
1670 ret
+= raw_data
[len_off
];
1676 return ret
> 0 ? ret
: err
;
1681 static ssize_t
picolcd_debug_flash_read(struct file
*f
, char __user
*u
,
1682 size_t s
, loff_t
*off
)
1684 struct picolcd_data
*data
= f
->private_data
;
1690 if (*off
+ s
> 0x05fff)
1693 if (data
->status
& PICOLCD_BOOTLOADER
)
1694 return _picolcd_flash_read(data
, REPORT_BL_READ_MEMORY
, u
, s
, off
);
1696 return _picolcd_flash_read(data
, REPORT_READ_MEMORY
, u
, s
, off
);
1699 /* erase block aligned to 64bytes boundary */
1700 static ssize_t
_picolcd_flash_erase64(struct picolcd_data
*data
, int report_id
,
1703 struct picolcd_pending
*resp
;
1711 len_off
= _picolcd_flash_setaddr(data
, raw_data
, *off
);
1712 resp
= picolcd_send_and_wait(data
->hdev
, report_id
, raw_data
, len_off
);
1713 if (!resp
|| !resp
->in_report
)
1715 if (resp
->in_report
->id
== REPORT_MEMORY
||
1716 resp
->in_report
->id
== REPORT_BL_ERASE_MEMORY
) {
1717 if (memcmp(raw_data
, resp
->raw_data
, len_off
) != 0)
1726 /* write a given size of data (bounds check to be done by caller) */
1727 static ssize_t
_picolcd_flash_write(struct picolcd_data
*data
, int report_id
,
1728 const char __user
*u
, size_t s
, loff_t
*off
)
1730 struct picolcd_pending
*resp
;
1733 int len_off
, err
= -EIO
;
1737 len_off
= _picolcd_flash_setaddr(data
, raw_data
, *off
);
1738 raw_data
[len_off
] = s
> 32 ? 32 : s
;
1739 if (copy_from_user(raw_data
+len_off
+1, u
, raw_data
[len_off
])) {
1743 resp
= picolcd_send_and_wait(data
->hdev
, report_id
, raw_data
,
1744 len_off
+1+raw_data
[len_off
]);
1745 if (!resp
|| !resp
->in_report
)
1747 if (resp
->in_report
->id
== REPORT_MEMORY
||
1748 resp
->in_report
->id
== REPORT_BL_WRITE_MEMORY
) {
1749 if (memcmp(raw_data
, resp
->raw_data
, len_off
+1+raw_data
[len_off
]) != 0)
1751 *off
+= raw_data
[len_off
];
1752 s
-= raw_data
[len_off
];
1753 ret
+= raw_data
[len_off
];
1761 return ret
> 0 ? ret
: err
;
1764 static ssize_t
picolcd_debug_flash_write(struct file
*f
, const char __user
*u
,
1765 size_t s
, loff_t
*off
)
1767 struct picolcd_data
*data
= f
->private_data
;
1768 ssize_t err
, ret
= 0;
1769 int report_erase
, report_write
;
1780 if (data
->status
& PICOLCD_BOOTLOADER
) {
1781 report_erase
= REPORT_BL_ERASE_MEMORY
;
1782 report_write
= REPORT_BL_WRITE_MEMORY
;
1784 report_erase
= REPORT_ERASE_MEMORY
;
1785 report_write
= REPORT_WRITE_MEMORY
;
1787 mutex_lock(&data
->mutex_flash
);
1789 err
= _picolcd_flash_erase64(data
, report_erase
, off
);
1792 err
= _picolcd_flash_write(data
, report_write
, u
, 64, off
);
1801 mutex_unlock(&data
->mutex_flash
);
1802 return ret
> 0 ? ret
: err
;
1807 * - concurrent writing is prevented by mutex and all writes must be
1808 * n*64 bytes and 64-byte aligned, each write being preceeded by an
1809 * ERASE which erases a 64byte block.
1810 * If less than requested was written or an error is returned for an
1811 * otherwise correct write request the next 64-byte block which should
1812 * have been written is in undefined state (mostly: original, erased,
1813 * (half-)written with write error)
1814 * - reading can happend without special restriction
1816 static const struct file_operations picolcd_debug_flash_fops
= {
1817 .owner
= THIS_MODULE
,
1818 .open
= picolcd_debug_flash_open
,
1819 .read
= picolcd_debug_flash_read
,
1820 .write
= picolcd_debug_flash_write
,
1821 .llseek
= generic_file_llseek
,
1826 * Helper code for HID report level dumping/debugging
1828 static const char *error_codes
[] = {
1829 "success", "parameter missing", "data_missing", "block readonly",
1830 "block not erasable", "block too big", "section overflow",
1831 "invalid command length", "invalid data length",
1834 static void dump_buff_as_hex(char *dst
, size_t dst_sz
, const u8
*data
,
1835 const size_t data_len
)
1838 for (i
= j
= 0; i
< data_len
&& j
+ 3 < dst_sz
; i
++) {
1839 dst
[j
++] = hex_asc
[(data
[i
] >> 4) & 0x0f];
1840 dst
[j
++] = hex_asc
[data
[i
] & 0x0f];
1850 static void picolcd_debug_out_report(struct picolcd_data
*data
,
1851 struct hid_device
*hdev
, struct hid_report
*report
)
1854 int raw_size
= (report
->size
>> 3) + 1;
1858 /* Avoid unnecessary overhead if debugfs is disabled */
1859 if (!hdev
->debug_events
)
1862 buff
= kmalloc(BUFF_SZ
, GFP_ATOMIC
);
1866 snprintf(buff
, BUFF_SZ
, "\nout report %d (size %d) = ",
1867 report
->id
, raw_size
);
1868 hid_debug_event(hdev
, buff
);
1869 if (raw_size
+ 5 > sizeof(raw_data
)) {
1870 hid_debug_event(hdev
, " TOO BIG\n");
1873 raw_data
[0] = report
->id
;
1874 hid_output_report(report
, raw_data
);
1875 dump_buff_as_hex(buff
, BUFF_SZ
, raw_data
, raw_size
);
1876 hid_debug_event(hdev
, buff
);
1879 switch (report
->id
) {
1880 case REPORT_LED_STATE
:
1881 /* 1 data byte with GPO state */
1882 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
1883 "REPORT_LED_STATE", report
->id
, raw_size
-1);
1884 hid_debug_event(hdev
, buff
);
1885 snprintf(buff
, BUFF_SZ
, "\tGPO state: 0x%02x\n", raw_data
[1]);
1886 hid_debug_event(hdev
, buff
);
1888 case REPORT_BRIGHTNESS
:
1889 /* 1 data byte with brightness */
1890 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
1891 "REPORT_BRIGHTNESS", report
->id
, raw_size
-1);
1892 hid_debug_event(hdev
, buff
);
1893 snprintf(buff
, BUFF_SZ
, "\tBrightness: 0x%02x\n", raw_data
[1]);
1894 hid_debug_event(hdev
, buff
);
1896 case REPORT_CONTRAST
:
1897 /* 1 data byte with contrast */
1898 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
1899 "REPORT_CONTRAST", report
->id
, raw_size
-1);
1900 hid_debug_event(hdev
, buff
);
1901 snprintf(buff
, BUFF_SZ
, "\tContrast: 0x%02x\n", raw_data
[1]);
1902 hid_debug_event(hdev
, buff
);
1905 /* 2 data bytes with reset duration in ms */
1906 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
1907 "REPORT_RESET", report
->id
, raw_size
-1);
1908 hid_debug_event(hdev
, buff
);
1909 snprintf(buff
, BUFF_SZ
, "\tDuration: 0x%02x%02x (%dms)\n",
1910 raw_data
[2], raw_data
[1], raw_data
[2] << 8 | raw_data
[1]);
1911 hid_debug_event(hdev
, buff
);
1913 case REPORT_LCD_CMD
:
1914 /* 63 data bytes with LCD commands */
1915 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
1916 "REPORT_LCD_CMD", report
->id
, raw_size
-1);
1917 hid_debug_event(hdev
, buff
);
1918 /* TODO: format decoding */
1920 case REPORT_LCD_DATA
:
1921 /* 63 data bytes with LCD data */
1922 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
1923 "REPORT_LCD_CMD", report
->id
, raw_size
-1);
1924 /* TODO: format decoding */
1925 hid_debug_event(hdev
, buff
);
1927 case REPORT_LCD_CMD_DATA
:
1928 /* 63 data bytes with LCD commands and data */
1929 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
1930 "REPORT_LCD_CMD", report
->id
, raw_size
-1);
1931 /* TODO: format decoding */
1932 hid_debug_event(hdev
, buff
);
1934 case REPORT_EE_READ
:
1935 /* 3 data bytes with read area description */
1936 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
1937 "REPORT_EE_READ", report
->id
, raw_size
-1);
1938 hid_debug_event(hdev
, buff
);
1939 snprintf(buff
, BUFF_SZ
, "\tData address: 0x%02x%02x\n",
1940 raw_data
[2], raw_data
[1]);
1941 hid_debug_event(hdev
, buff
);
1942 snprintf(buff
, BUFF_SZ
, "\tData length: %d\n", raw_data
[3]);
1943 hid_debug_event(hdev
, buff
);
1945 case REPORT_EE_WRITE
:
1946 /* 3+1..20 data bytes with write area description */
1947 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
1948 "REPORT_EE_WRITE", report
->id
, raw_size
-1);
1949 hid_debug_event(hdev
, buff
);
1950 snprintf(buff
, BUFF_SZ
, "\tData address: 0x%02x%02x\n",
1951 raw_data
[2], raw_data
[1]);
1952 hid_debug_event(hdev
, buff
);
1953 snprintf(buff
, BUFF_SZ
, "\tData length: %d\n", raw_data
[3]);
1954 hid_debug_event(hdev
, buff
);
1955 if (raw_data
[3] == 0) {
1956 snprintf(buff
, BUFF_SZ
, "\tNo data\n");
1957 } else if (raw_data
[3] + 4 <= raw_size
) {
1958 snprintf(buff
, BUFF_SZ
, "\tData: ");
1959 hid_debug_event(hdev
, buff
);
1960 dump_buff_as_hex(buff
, BUFF_SZ
, raw_data
+4, raw_data
[3]);
1962 snprintf(buff
, BUFF_SZ
, "\tData overflowed\n");
1964 hid_debug_event(hdev
, buff
);
1966 case REPORT_ERASE_MEMORY
:
1967 case REPORT_BL_ERASE_MEMORY
:
1968 /* 3 data bytes with pointer inside erase block */
1969 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
1970 "REPORT_ERASE_MEMORY", report
->id
, raw_size
-1);
1971 hid_debug_event(hdev
, buff
);
1972 switch (data
->addr_sz
) {
1974 snprintf(buff
, BUFF_SZ
, "\tAddress inside 64 byte block: 0x%02x%02x\n",
1975 raw_data
[2], raw_data
[1]);
1978 snprintf(buff
, BUFF_SZ
, "\tAddress inside 64 byte block: 0x%02x%02x%02x\n",
1979 raw_data
[3], raw_data
[2], raw_data
[1]);
1982 snprintf(buff
, BUFF_SZ
, "\tNot supported\n");
1984 hid_debug_event(hdev
, buff
);
1986 case REPORT_READ_MEMORY
:
1987 case REPORT_BL_READ_MEMORY
:
1988 /* 4 data bytes with read area description */
1989 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
1990 "REPORT_READ_MEMORY", report
->id
, raw_size
-1);
1991 hid_debug_event(hdev
, buff
);
1992 switch (data
->addr_sz
) {
1994 snprintf(buff
, BUFF_SZ
, "\tData address: 0x%02x%02x\n",
1995 raw_data
[2], raw_data
[1]);
1996 hid_debug_event(hdev
, buff
);
1997 snprintf(buff
, BUFF_SZ
, "\tData length: %d\n", raw_data
[3]);
2000 snprintf(buff
, BUFF_SZ
, "\tData address: 0x%02x%02x%02x\n",
2001 raw_data
[3], raw_data
[2], raw_data
[1]);
2002 hid_debug_event(hdev
, buff
);
2003 snprintf(buff
, BUFF_SZ
, "\tData length: %d\n", raw_data
[4]);
2006 snprintf(buff
, BUFF_SZ
, "\tNot supported\n");
2008 hid_debug_event(hdev
, buff
);
2010 case REPORT_WRITE_MEMORY
:
2011 case REPORT_BL_WRITE_MEMORY
:
2012 /* 4+1..32 data bytes with write adrea description */
2013 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
2014 "REPORT_WRITE_MEMORY", report
->id
, raw_size
-1);
2015 hid_debug_event(hdev
, buff
);
2016 switch (data
->addr_sz
) {
2018 snprintf(buff
, BUFF_SZ
, "\tData address: 0x%02x%02x\n",
2019 raw_data
[2], raw_data
[1]);
2020 hid_debug_event(hdev
, buff
);
2021 snprintf(buff
, BUFF_SZ
, "\tData length: %d\n", raw_data
[3]);
2022 hid_debug_event(hdev
, buff
);
2023 if (raw_data
[3] == 0) {
2024 snprintf(buff
, BUFF_SZ
, "\tNo data\n");
2025 } else if (raw_data
[3] + 4 <= raw_size
) {
2026 snprintf(buff
, BUFF_SZ
, "\tData: ");
2027 hid_debug_event(hdev
, buff
);
2028 dump_buff_as_hex(buff
, BUFF_SZ
, raw_data
+4, raw_data
[3]);
2030 snprintf(buff
, BUFF_SZ
, "\tData overflowed\n");
2034 snprintf(buff
, BUFF_SZ
, "\tData address: 0x%02x%02x%02x\n",
2035 raw_data
[3], raw_data
[2], raw_data
[1]);
2036 hid_debug_event(hdev
, buff
);
2037 snprintf(buff
, BUFF_SZ
, "\tData length: %d\n", raw_data
[4]);
2038 hid_debug_event(hdev
, buff
);
2039 if (raw_data
[4] == 0) {
2040 snprintf(buff
, BUFF_SZ
, "\tNo data\n");
2041 } else if (raw_data
[4] + 5 <= raw_size
) {
2042 snprintf(buff
, BUFF_SZ
, "\tData: ");
2043 hid_debug_event(hdev
, buff
);
2044 dump_buff_as_hex(buff
, BUFF_SZ
, raw_data
+5, raw_data
[4]);
2046 snprintf(buff
, BUFF_SZ
, "\tData overflowed\n");
2050 snprintf(buff
, BUFF_SZ
, "\tNot supported\n");
2052 hid_debug_event(hdev
, buff
);
2054 case REPORT_SPLASH_RESTART
:
2057 case REPORT_EXIT_KEYBOARD
:
2058 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
2059 "REPORT_EXIT_KEYBOARD", report
->id
, raw_size
-1);
2060 hid_debug_event(hdev
, buff
);
2061 snprintf(buff
, BUFF_SZ
, "\tRestart delay: %dms (0x%02x%02x)\n",
2062 raw_data
[1] | (raw_data
[2] << 8),
2063 raw_data
[2], raw_data
[1]);
2064 hid_debug_event(hdev
, buff
);
2066 case REPORT_VERSION
:
2067 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
2068 "REPORT_VERSION", report
->id
, raw_size
-1);
2069 hid_debug_event(hdev
, buff
);
2072 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
2073 "REPORT_DEVID", report
->id
, raw_size
-1);
2074 hid_debug_event(hdev
, buff
);
2076 case REPORT_SPLASH_SIZE
:
2077 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
2078 "REPORT_SPLASH_SIZE", report
->id
, raw_size
-1);
2079 hid_debug_event(hdev
, buff
);
2081 case REPORT_HOOK_VERSION
:
2082 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
2083 "REPORT_HOOK_VERSION", report
->id
, raw_size
-1);
2084 hid_debug_event(hdev
, buff
);
2086 case REPORT_EXIT_FLASHER
:
2087 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
2088 "REPORT_VERSION", report
->id
, raw_size
-1);
2089 hid_debug_event(hdev
, buff
);
2090 snprintf(buff
, BUFF_SZ
, "\tRestart delay: %dms (0x%02x%02x)\n",
2091 raw_data
[1] | (raw_data
[2] << 8),
2092 raw_data
[2], raw_data
[1]);
2093 hid_debug_event(hdev
, buff
);
2096 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
2097 "<unknown>", report
->id
, raw_size
-1);
2098 hid_debug_event(hdev
, buff
);
2101 wake_up_interruptible(&hdev
->debug_wait
);
2105 static void picolcd_debug_raw_event(struct picolcd_data
*data
,
2106 struct hid_device
*hdev
, struct hid_report
*report
,
2107 u8
*raw_data
, int size
)
2112 /* Avoid unnecessary overhead if debugfs is disabled */
2113 if (!hdev
->debug_events
)
2116 buff
= kmalloc(BUFF_SZ
, GFP_ATOMIC
);
2120 switch (report
->id
) {
2121 case REPORT_ERROR_CODE
:
2122 /* 2 data bytes with affected report and error code */
2123 snprintf(buff
, BUFF_SZ
, "report %s (%d, size=%d)\n",
2124 "REPORT_ERROR_CODE", report
->id
, size
-1);
2125 hid_debug_event(hdev
, buff
);
2126 if (raw_data
[2] < ARRAY_SIZE(error_codes
))
2127 snprintf(buff
, BUFF_SZ
, "\tError code 0x%02x (%s) in reply to report 0x%02x\n",
2128 raw_data
[2], error_codes
[raw_data
[2]], raw_data
[1]);
2130 snprintf(buff
, BUFF_SZ
, "\tError code 0x%02x in reply to report 0x%02x\n",
2131 raw_data
[2], raw_data
[1]);
2132 hid_debug_event(hdev
, buff
);
2134 case REPORT_KEY_STATE
:
2135 /* 2 data bytes with key state */
2136 snprintf(buff
, BUFF_SZ
, "report %s (%d, size=%d)\n",
2137 "REPORT_KEY_STATE", report
->id
, size
-1);
2138 hid_debug_event(hdev
, buff
);
2139 if (raw_data
[1] == 0)
2140 snprintf(buff
, BUFF_SZ
, "\tNo key pressed\n");
2141 else if (raw_data
[2] == 0)
2142 snprintf(buff
, BUFF_SZ
, "\tOne key pressed: 0x%02x (%d)\n",
2143 raw_data
[1], raw_data
[1]);
2145 snprintf(buff
, BUFF_SZ
, "\tTwo keys pressed: 0x%02x (%d), 0x%02x (%d)\n",
2146 raw_data
[1], raw_data
[1], raw_data
[2], raw_data
[2]);
2147 hid_debug_event(hdev
, buff
);
2149 case REPORT_IR_DATA
:
2150 /* Up to 20 byes of IR scancode data */
2151 snprintf(buff
, BUFF_SZ
, "report %s (%d, size=%d)\n",
2152 "REPORT_IR_DATA", report
->id
, size
-1);
2153 hid_debug_event(hdev
, buff
);
2154 if (raw_data
[1] == 0) {
2155 snprintf(buff
, BUFF_SZ
, "\tUnexpectedly 0 data length\n");
2156 hid_debug_event(hdev
, buff
);
2157 } else if (raw_data
[1] + 1 <= size
) {
2158 snprintf(buff
, BUFF_SZ
, "\tData length: %d\n\tIR Data: ",
2160 hid_debug_event(hdev
, buff
);
2161 dump_buff_as_hex(buff
, BUFF_SZ
, raw_data
+2, raw_data
[1]-1);
2162 hid_debug_event(hdev
, buff
);
2164 snprintf(buff
, BUFF_SZ
, "\tOverflowing data length: %d\n",
2166 hid_debug_event(hdev
, buff
);
2169 case REPORT_EE_DATA
:
2170 /* Data buffer in response to REPORT_EE_READ or REPORT_EE_WRITE */
2171 snprintf(buff
, BUFF_SZ
, "report %s (%d, size=%d)\n",
2172 "REPORT_EE_DATA", report
->id
, size
-1);
2173 hid_debug_event(hdev
, buff
);
2174 snprintf(buff
, BUFF_SZ
, "\tData address: 0x%02x%02x\n",
2175 raw_data
[2], raw_data
[1]);
2176 hid_debug_event(hdev
, buff
);
2177 snprintf(buff
, BUFF_SZ
, "\tData length: %d\n", raw_data
[3]);
2178 hid_debug_event(hdev
, buff
);
2179 if (raw_data
[3] == 0) {
2180 snprintf(buff
, BUFF_SZ
, "\tNo data\n");
2181 hid_debug_event(hdev
, buff
);
2182 } else if (raw_data
[3] + 4 <= size
) {
2183 snprintf(buff
, BUFF_SZ
, "\tData: ");
2184 hid_debug_event(hdev
, buff
);
2185 dump_buff_as_hex(buff
, BUFF_SZ
, raw_data
+4, raw_data
[3]);
2186 hid_debug_event(hdev
, buff
);
2188 snprintf(buff
, BUFF_SZ
, "\tData overflowed\n");
2189 hid_debug_event(hdev
, buff
);
2193 /* Data buffer in response to REPORT_READ_MEMORY or REPORT_WRTIE_MEMORY */
2194 snprintf(buff
, BUFF_SZ
, "report %s (%d, size=%d)\n",
2195 "REPORT_MEMORY", report
->id
, size
-1);
2196 hid_debug_event(hdev
, buff
);
2197 switch (data
->addr_sz
) {
2199 snprintf(buff
, BUFF_SZ
, "\tData address: 0x%02x%02x\n",
2200 raw_data
[2], raw_data
[1]);
2201 hid_debug_event(hdev
, buff
);
2202 snprintf(buff
, BUFF_SZ
, "\tData length: %d\n", raw_data
[3]);
2203 hid_debug_event(hdev
, buff
);
2204 if (raw_data
[3] == 0) {
2205 snprintf(buff
, BUFF_SZ
, "\tNo data\n");
2206 } else if (raw_data
[3] + 4 <= size
) {
2207 snprintf(buff
, BUFF_SZ
, "\tData: ");
2208 hid_debug_event(hdev
, buff
);
2209 dump_buff_as_hex(buff
, BUFF_SZ
, raw_data
+4, raw_data
[3]);
2211 snprintf(buff
, BUFF_SZ
, "\tData overflowed\n");
2215 snprintf(buff
, BUFF_SZ
, "\tData address: 0x%02x%02x%02x\n",
2216 raw_data
[3], raw_data
[2], raw_data
[1]);
2217 hid_debug_event(hdev
, buff
);
2218 snprintf(buff
, BUFF_SZ
, "\tData length: %d\n", raw_data
[4]);
2219 hid_debug_event(hdev
, buff
);
2220 if (raw_data
[4] == 0) {
2221 snprintf(buff
, BUFF_SZ
, "\tNo data\n");
2222 } else if (raw_data
[4] + 5 <= size
) {
2223 snprintf(buff
, BUFF_SZ
, "\tData: ");
2224 hid_debug_event(hdev
, buff
);
2225 dump_buff_as_hex(buff
, BUFF_SZ
, raw_data
+5, raw_data
[4]);
2227 snprintf(buff
, BUFF_SZ
, "\tData overflowed\n");
2231 snprintf(buff
, BUFF_SZ
, "\tNot supported\n");
2233 hid_debug_event(hdev
, buff
);
2235 case REPORT_VERSION
:
2236 snprintf(buff
, BUFF_SZ
, "report %s (%d, size=%d)\n",
2237 "REPORT_VERSION", report
->id
, size
-1);
2238 hid_debug_event(hdev
, buff
);
2239 snprintf(buff
, BUFF_SZ
, "\tFirmware version: %d.%d\n",
2240 raw_data
[2], raw_data
[1]);
2241 hid_debug_event(hdev
, buff
);
2243 case REPORT_BL_ERASE_MEMORY
:
2244 snprintf(buff
, BUFF_SZ
, "report %s (%d, size=%d)\n",
2245 "REPORT_BL_ERASE_MEMORY", report
->id
, size
-1);
2246 hid_debug_event(hdev
, buff
);
2249 case REPORT_BL_READ_MEMORY
:
2250 snprintf(buff
, BUFF_SZ
, "report %s (%d, size=%d)\n",
2251 "REPORT_BL_READ_MEMORY", report
->id
, size
-1);
2252 hid_debug_event(hdev
, buff
);
2255 case REPORT_BL_WRITE_MEMORY
:
2256 snprintf(buff
, BUFF_SZ
, "report %s (%d, size=%d)\n",
2257 "REPORT_BL_WRITE_MEMORY", report
->id
, size
-1);
2258 hid_debug_event(hdev
, buff
);
2262 snprintf(buff
, BUFF_SZ
, "report %s (%d, size=%d)\n",
2263 "REPORT_DEVID", report
->id
, size
-1);
2264 hid_debug_event(hdev
, buff
);
2265 snprintf(buff
, BUFF_SZ
, "\tSerial: 0x%02x%02x%02x%02x\n",
2266 raw_data
[1], raw_data
[2], raw_data
[3], raw_data
[4]);
2267 hid_debug_event(hdev
, buff
);
2268 snprintf(buff
, BUFF_SZ
, "\tType: 0x%02x\n",
2270 hid_debug_event(hdev
, buff
);
2272 case REPORT_SPLASH_SIZE
:
2273 snprintf(buff
, BUFF_SZ
, "report %s (%d, size=%d)\n",
2274 "REPORT_SPLASH_SIZE", report
->id
, size
-1);
2275 hid_debug_event(hdev
, buff
);
2276 snprintf(buff
, BUFF_SZ
, "\tTotal splash space: %d\n",
2277 (raw_data
[2] << 8) | raw_data
[1]);
2278 hid_debug_event(hdev
, buff
);
2279 snprintf(buff
, BUFF_SZ
, "\tUsed splash space: %d\n",
2280 (raw_data
[4] << 8) | raw_data
[3]);
2281 hid_debug_event(hdev
, buff
);
2283 case REPORT_HOOK_VERSION
:
2284 snprintf(buff
, BUFF_SZ
, "report %s (%d, size=%d)\n",
2285 "REPORT_HOOK_VERSION", report
->id
, size
-1);
2286 hid_debug_event(hdev
, buff
);
2287 snprintf(buff
, BUFF_SZ
, "\tFirmware version: %d.%d\n",
2288 raw_data
[1], raw_data
[2]);
2289 hid_debug_event(hdev
, buff
);
2292 snprintf(buff
, BUFF_SZ
, "report %s (%d, size=%d)\n",
2293 "<unknown>", report
->id
, size
-1);
2294 hid_debug_event(hdev
, buff
);
2297 wake_up_interruptible(&hdev
->debug_wait
);
2301 static void picolcd_init_devfs(struct picolcd_data
*data
,
2302 struct hid_report
*eeprom_r
, struct hid_report
*eeprom_w
,
2303 struct hid_report
*flash_r
, struct hid_report
*flash_w
,
2304 struct hid_report
*reset
)
2306 struct hid_device
*hdev
= data
->hdev
;
2308 mutex_init(&data
->mutex_flash
);
2312 data
->debug_reset
= debugfs_create_file("reset", 0600,
2313 hdev
->debug_dir
, data
, &picolcd_debug_reset_fops
);
2316 if (eeprom_r
|| eeprom_w
)
2317 data
->debug_eeprom
= debugfs_create_file("eeprom",
2318 (eeprom_w
? S_IWUSR
: 0) | (eeprom_r
? S_IRUSR
: 0),
2319 hdev
->debug_dir
, data
, &picolcd_debug_eeprom_fops
);
2322 if (flash_r
&& flash_r
->maxfield
== 1 && flash_r
->field
[0]->report_size
== 8)
2323 data
->addr_sz
= flash_r
->field
[0]->report_count
- 1;
2326 if (data
->addr_sz
== 2 || data
->addr_sz
== 3) {
2327 data
->debug_flash
= debugfs_create_file("flash",
2328 (flash_w
? S_IWUSR
: 0) | (flash_r
? S_IRUSR
: 0),
2329 hdev
->debug_dir
, data
, &picolcd_debug_flash_fops
);
2330 } else if (flash_r
|| flash_w
)
2331 dev_warn(&hdev
->dev
, "Unexpected FLASH access reports, "
2332 "please submit rdesc for review\n");
2335 static void picolcd_exit_devfs(struct picolcd_data
*data
)
2337 struct dentry
*dent
;
2339 dent
= data
->debug_reset
;
2340 data
->debug_reset
= NULL
;
2342 debugfs_remove(dent
);
2343 dent
= data
->debug_eeprom
;
2344 data
->debug_eeprom
= NULL
;
2346 debugfs_remove(dent
);
2347 dent
= data
->debug_flash
;
2348 data
->debug_flash
= NULL
;
2350 debugfs_remove(dent
);
2351 mutex_destroy(&data
->mutex_flash
);
2354 static inline void picolcd_debug_raw_event(struct picolcd_data
*data
,
2355 struct hid_device
*hdev
, struct hid_report
*report
,
2356 u8
*raw_data
, int size
)
2359 static inline void picolcd_init_devfs(struct picolcd_data
*data
,
2360 struct hid_report
*eeprom_r
, struct hid_report
*eeprom_w
,
2361 struct hid_report
*flash_r
, struct hid_report
*flash_w
,
2362 struct hid_report
*reset
)
2365 static inline void picolcd_exit_devfs(struct picolcd_data
*data
)
2368 #endif /* CONFIG_DEBUG_FS */
2371 * Handle raw report as sent by device
2373 static int picolcd_raw_event(struct hid_device
*hdev
,
2374 struct hid_report
*report
, u8
*raw_data
, int size
)
2376 struct picolcd_data
*data
= hid_get_drvdata(hdev
);
2377 unsigned long flags
;
2383 if (report
->id
== REPORT_KEY_STATE
) {
2384 if (data
->input_keys
)
2385 ret
= picolcd_raw_keypad(data
, report
, raw_data
+1, size
-1);
2386 } else if (report
->id
== REPORT_IR_DATA
) {
2387 if (data
->input_cir
)
2388 ret
= picolcd_raw_cir(data
, report
, raw_data
+1, size
-1);
2390 spin_lock_irqsave(&data
->lock
, flags
);
2392 * We let the caller of picolcd_send_and_wait() check if the
2393 * report we got is one of the expected ones or not.
2395 if (data
->pending
) {
2396 memcpy(data
->pending
->raw_data
, raw_data
+1, size
-1);
2397 data
->pending
->raw_size
= size
-1;
2398 data
->pending
->in_report
= report
;
2399 complete(&data
->pending
->ready
);
2401 spin_unlock_irqrestore(&data
->lock
, flags
);
2404 picolcd_debug_raw_event(data
, hdev
, report
, raw_data
, size
);
2409 static int picolcd_suspend(struct hid_device
*hdev
, pm_message_t message
)
2411 if (message
.event
& PM_EVENT_AUTO
)
2414 picolcd_suspend_backlight(hid_get_drvdata(hdev
));
2415 dbg_hid(PICOLCD_NAME
" device ready for suspend\n");
2419 static int picolcd_resume(struct hid_device
*hdev
)
2422 ret
= picolcd_resume_backlight(hid_get_drvdata(hdev
));
2424 dbg_hid(PICOLCD_NAME
" restoring backlight failed: %d\n", ret
);
2428 static int picolcd_reset_resume(struct hid_device
*hdev
)
2431 ret
= picolcd_reset(hdev
);
2433 dbg_hid(PICOLCD_NAME
" resetting our device failed: %d\n", ret
);
2434 ret
= picolcd_fb_reset(hid_get_drvdata(hdev
), 0);
2436 dbg_hid(PICOLCD_NAME
" restoring framebuffer content failed: %d\n", ret
);
2437 ret
= picolcd_resume_lcd(hid_get_drvdata(hdev
));
2439 dbg_hid(PICOLCD_NAME
" restoring lcd failed: %d\n", ret
);
2440 ret
= picolcd_resume_backlight(hid_get_drvdata(hdev
));
2442 dbg_hid(PICOLCD_NAME
" restoring backlight failed: %d\n", ret
);
2443 picolcd_leds_set(hid_get_drvdata(hdev
));
2448 /* initialize keypad input device */
2449 static int picolcd_init_keys(struct picolcd_data
*data
,
2450 struct hid_report
*report
)
2452 struct hid_device
*hdev
= data
->hdev
;
2453 struct input_dev
*idev
;
2458 if (report
->maxfield
!= 1 || report
->field
[0]->report_count
!= 2 ||
2459 report
->field
[0]->report_size
!= 8) {
2460 dev_err(&hdev
->dev
, "unsupported KEY_STATE report");
2464 idev
= input_allocate_device();
2466 dev_err(&hdev
->dev
, "failed to allocate input device");
2469 input_set_drvdata(idev
, hdev
);
2470 memcpy(data
->keycode
, def_keymap
, sizeof(def_keymap
));
2471 idev
->name
= hdev
->name
;
2472 idev
->phys
= hdev
->phys
;
2473 idev
->uniq
= hdev
->uniq
;
2474 idev
->id
.bustype
= hdev
->bus
;
2475 idev
->id
.vendor
= hdev
->vendor
;
2476 idev
->id
.product
= hdev
->product
;
2477 idev
->id
.version
= hdev
->version
;
2478 idev
->dev
.parent
= hdev
->dev
.parent
;
2479 idev
->keycode
= &data
->keycode
;
2480 idev
->keycodemax
= PICOLCD_KEYS
;
2481 idev
->keycodesize
= sizeof(data
->keycode
[0]);
2482 input_set_capability(idev
, EV_MSC
, MSC_SCAN
);
2483 set_bit(EV_REP
, idev
->evbit
);
2484 for (i
= 0; i
< PICOLCD_KEYS
; i
++)
2485 input_set_capability(idev
, EV_KEY
, data
->keycode
[i
]);
2486 error
= input_register_device(idev
);
2488 dev_err(&hdev
->dev
, "error registering the input device");
2489 input_free_device(idev
);
2492 data
->input_keys
= idev
;
2496 static void picolcd_exit_keys(struct picolcd_data
*data
)
2498 struct input_dev
*idev
= data
->input_keys
;
2500 data
->input_keys
= NULL
;
2502 input_unregister_device(idev
);
2505 /* initialize CIR input device */
2506 static inline int picolcd_init_cir(struct picolcd_data
*data
, struct hid_report
*report
)
2508 /* support not implemented yet */
2512 static inline void picolcd_exit_cir(struct picolcd_data
*data
)
2516 static int picolcd_probe_lcd(struct hid_device
*hdev
, struct picolcd_data
*data
)
2520 error
= picolcd_check_version(hdev
);
2524 if (data
->version
[0] != 0 && data
->version
[1] != 3)
2525 dev_info(&hdev
->dev
, "Device with untested firmware revision, "
2526 "please submit /sys/kernel/debug/hid/%s/rdesc for this device.\n",
2527 dev_name(&hdev
->dev
));
2529 /* Setup keypad input device */
2530 error
= picolcd_init_keys(data
, picolcd_in_report(REPORT_KEY_STATE
, hdev
));
2534 /* Setup CIR input device */
2535 error
= picolcd_init_cir(data
, picolcd_in_report(REPORT_IR_DATA
, hdev
));
2539 /* Set up the framebuffer device */
2540 error
= picolcd_init_framebuffer(data
);
2544 /* Setup lcd class device */
2545 error
= picolcd_init_lcd(data
, picolcd_out_report(REPORT_CONTRAST
, hdev
));
2549 /* Setup backlight class device */
2550 error
= picolcd_init_backlight(data
, picolcd_out_report(REPORT_BRIGHTNESS
, hdev
));
2554 /* Setup the LED class devices */
2555 error
= picolcd_init_leds(data
, picolcd_out_report(REPORT_LED_STATE
, hdev
));
2559 picolcd_init_devfs(data
, picolcd_out_report(REPORT_EE_READ
, hdev
),
2560 picolcd_out_report(REPORT_EE_WRITE
, hdev
),
2561 picolcd_out_report(REPORT_READ_MEMORY
, hdev
),
2562 picolcd_out_report(REPORT_WRITE_MEMORY
, hdev
),
2563 picolcd_out_report(REPORT_RESET
, hdev
));
2566 picolcd_exit_leds(data
);
2567 picolcd_exit_backlight(data
);
2568 picolcd_exit_lcd(data
);
2569 picolcd_exit_framebuffer(data
);
2570 picolcd_exit_cir(data
);
2571 picolcd_exit_keys(data
);
2575 static int picolcd_probe_bootloader(struct hid_device
*hdev
, struct picolcd_data
*data
)
2579 error
= picolcd_check_version(hdev
);
2583 if (data
->version
[0] != 1 && data
->version
[1] != 0)
2584 dev_info(&hdev
->dev
, "Device with untested bootloader revision, "
2585 "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 dev_err(&hdev
->dev
, "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 dev_err(&hdev
->dev
, "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 dev_err(&hdev
->dev
, "hardware start failed\n");
2635 goto err_cleanup_data
;
2638 error
= hdev
->ll_driver
->open(hdev
);
2640 dev_err(&hdev
->dev
, "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 dev_err(&hdev
->dev
, "failed to create sysfs attributes\n");
2647 goto err_cleanup_hid_ll
;
2650 error
= device_create_file(&hdev
->dev
, &dev_attr_operation_mode
);
2652 dev_err(&hdev
->dev
, "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
);
2671 hdev
->ll_driver
->close(hdev
);
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
);
2702 hdev
->ll_driver
->close(hdev
);
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_scheduled_work();
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");