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 hid_warn(hdev
, "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 hid_err(hdev
, "no version response from PicoLCD\n");
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 hid_info(hdev
, "PicoLCD, bootloader version %d.%d\n",
1341 verinfo
->raw_data
[1], verinfo
->raw_data
[0]);
1343 hid_info(hdev
, "PicoLCD, firmware version %d.%d\n",
1344 verinfo
->raw_data
[1], verinfo
->raw_data
[0]);
1347 hid_err(hdev
, "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
)) {
1871 hid_debug_event(hdev
, " TOO BIG\n");
1874 raw_data
[0] = report
->id
;
1875 hid_output_report(report
, raw_data
);
1876 dump_buff_as_hex(buff
, BUFF_SZ
, raw_data
, raw_size
);
1877 hid_debug_event(hdev
, buff
);
1880 switch (report
->id
) {
1881 case REPORT_LED_STATE
:
1882 /* 1 data byte with GPO state */
1883 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
1884 "REPORT_LED_STATE", report
->id
, raw_size
-1);
1885 hid_debug_event(hdev
, buff
);
1886 snprintf(buff
, BUFF_SZ
, "\tGPO state: 0x%02x\n", raw_data
[1]);
1887 hid_debug_event(hdev
, buff
);
1889 case REPORT_BRIGHTNESS
:
1890 /* 1 data byte with brightness */
1891 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
1892 "REPORT_BRIGHTNESS", report
->id
, raw_size
-1);
1893 hid_debug_event(hdev
, buff
);
1894 snprintf(buff
, BUFF_SZ
, "\tBrightness: 0x%02x\n", raw_data
[1]);
1895 hid_debug_event(hdev
, buff
);
1897 case REPORT_CONTRAST
:
1898 /* 1 data byte with contrast */
1899 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
1900 "REPORT_CONTRAST", report
->id
, raw_size
-1);
1901 hid_debug_event(hdev
, buff
);
1902 snprintf(buff
, BUFF_SZ
, "\tContrast: 0x%02x\n", raw_data
[1]);
1903 hid_debug_event(hdev
, buff
);
1906 /* 2 data bytes with reset duration in ms */
1907 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
1908 "REPORT_RESET", report
->id
, raw_size
-1);
1909 hid_debug_event(hdev
, buff
);
1910 snprintf(buff
, BUFF_SZ
, "\tDuration: 0x%02x%02x (%dms)\n",
1911 raw_data
[2], raw_data
[1], raw_data
[2] << 8 | raw_data
[1]);
1912 hid_debug_event(hdev
, buff
);
1914 case REPORT_LCD_CMD
:
1915 /* 63 data bytes with LCD commands */
1916 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
1917 "REPORT_LCD_CMD", report
->id
, raw_size
-1);
1918 hid_debug_event(hdev
, buff
);
1919 /* TODO: format decoding */
1921 case REPORT_LCD_DATA
:
1922 /* 63 data bytes with LCD data */
1923 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
1924 "REPORT_LCD_CMD", report
->id
, raw_size
-1);
1925 /* TODO: format decoding */
1926 hid_debug_event(hdev
, buff
);
1928 case REPORT_LCD_CMD_DATA
:
1929 /* 63 data bytes with LCD commands and data */
1930 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
1931 "REPORT_LCD_CMD", report
->id
, raw_size
-1);
1932 /* TODO: format decoding */
1933 hid_debug_event(hdev
, buff
);
1935 case REPORT_EE_READ
:
1936 /* 3 data bytes with read area description */
1937 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
1938 "REPORT_EE_READ", report
->id
, raw_size
-1);
1939 hid_debug_event(hdev
, buff
);
1940 snprintf(buff
, BUFF_SZ
, "\tData address: 0x%02x%02x\n",
1941 raw_data
[2], raw_data
[1]);
1942 hid_debug_event(hdev
, buff
);
1943 snprintf(buff
, BUFF_SZ
, "\tData length: %d\n", raw_data
[3]);
1944 hid_debug_event(hdev
, buff
);
1946 case REPORT_EE_WRITE
:
1947 /* 3+1..20 data bytes with write area description */
1948 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
1949 "REPORT_EE_WRITE", report
->id
, raw_size
-1);
1950 hid_debug_event(hdev
, buff
);
1951 snprintf(buff
, BUFF_SZ
, "\tData address: 0x%02x%02x\n",
1952 raw_data
[2], raw_data
[1]);
1953 hid_debug_event(hdev
, buff
);
1954 snprintf(buff
, BUFF_SZ
, "\tData length: %d\n", raw_data
[3]);
1955 hid_debug_event(hdev
, buff
);
1956 if (raw_data
[3] == 0) {
1957 snprintf(buff
, BUFF_SZ
, "\tNo data\n");
1958 } else if (raw_data
[3] + 4 <= raw_size
) {
1959 snprintf(buff
, BUFF_SZ
, "\tData: ");
1960 hid_debug_event(hdev
, buff
);
1961 dump_buff_as_hex(buff
, BUFF_SZ
, raw_data
+4, raw_data
[3]);
1963 snprintf(buff
, BUFF_SZ
, "\tData overflowed\n");
1965 hid_debug_event(hdev
, buff
);
1967 case REPORT_ERASE_MEMORY
:
1968 case REPORT_BL_ERASE_MEMORY
:
1969 /* 3 data bytes with pointer inside erase block */
1970 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
1971 "REPORT_ERASE_MEMORY", report
->id
, raw_size
-1);
1972 hid_debug_event(hdev
, buff
);
1973 switch (data
->addr_sz
) {
1975 snprintf(buff
, BUFF_SZ
, "\tAddress inside 64 byte block: 0x%02x%02x\n",
1976 raw_data
[2], raw_data
[1]);
1979 snprintf(buff
, BUFF_SZ
, "\tAddress inside 64 byte block: 0x%02x%02x%02x\n",
1980 raw_data
[3], raw_data
[2], raw_data
[1]);
1983 snprintf(buff
, BUFF_SZ
, "\tNot supported\n");
1985 hid_debug_event(hdev
, buff
);
1987 case REPORT_READ_MEMORY
:
1988 case REPORT_BL_READ_MEMORY
:
1989 /* 4 data bytes with read area description */
1990 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
1991 "REPORT_READ_MEMORY", report
->id
, raw_size
-1);
1992 hid_debug_event(hdev
, buff
);
1993 switch (data
->addr_sz
) {
1995 snprintf(buff
, BUFF_SZ
, "\tData address: 0x%02x%02x\n",
1996 raw_data
[2], raw_data
[1]);
1997 hid_debug_event(hdev
, buff
);
1998 snprintf(buff
, BUFF_SZ
, "\tData length: %d\n", raw_data
[3]);
2001 snprintf(buff
, BUFF_SZ
, "\tData address: 0x%02x%02x%02x\n",
2002 raw_data
[3], raw_data
[2], raw_data
[1]);
2003 hid_debug_event(hdev
, buff
);
2004 snprintf(buff
, BUFF_SZ
, "\tData length: %d\n", raw_data
[4]);
2007 snprintf(buff
, BUFF_SZ
, "\tNot supported\n");
2009 hid_debug_event(hdev
, buff
);
2011 case REPORT_WRITE_MEMORY
:
2012 case REPORT_BL_WRITE_MEMORY
:
2013 /* 4+1..32 data bytes with write adrea description */
2014 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
2015 "REPORT_WRITE_MEMORY", report
->id
, raw_size
-1);
2016 hid_debug_event(hdev
, buff
);
2017 switch (data
->addr_sz
) {
2019 snprintf(buff
, BUFF_SZ
, "\tData address: 0x%02x%02x\n",
2020 raw_data
[2], raw_data
[1]);
2021 hid_debug_event(hdev
, buff
);
2022 snprintf(buff
, BUFF_SZ
, "\tData length: %d\n", raw_data
[3]);
2023 hid_debug_event(hdev
, buff
);
2024 if (raw_data
[3] == 0) {
2025 snprintf(buff
, BUFF_SZ
, "\tNo data\n");
2026 } else if (raw_data
[3] + 4 <= raw_size
) {
2027 snprintf(buff
, BUFF_SZ
, "\tData: ");
2028 hid_debug_event(hdev
, buff
);
2029 dump_buff_as_hex(buff
, BUFF_SZ
, raw_data
+4, raw_data
[3]);
2031 snprintf(buff
, BUFF_SZ
, "\tData overflowed\n");
2035 snprintf(buff
, BUFF_SZ
, "\tData address: 0x%02x%02x%02x\n",
2036 raw_data
[3], raw_data
[2], raw_data
[1]);
2037 hid_debug_event(hdev
, buff
);
2038 snprintf(buff
, BUFF_SZ
, "\tData length: %d\n", raw_data
[4]);
2039 hid_debug_event(hdev
, buff
);
2040 if (raw_data
[4] == 0) {
2041 snprintf(buff
, BUFF_SZ
, "\tNo data\n");
2042 } else if (raw_data
[4] + 5 <= raw_size
) {
2043 snprintf(buff
, BUFF_SZ
, "\tData: ");
2044 hid_debug_event(hdev
, buff
);
2045 dump_buff_as_hex(buff
, BUFF_SZ
, raw_data
+5, raw_data
[4]);
2047 snprintf(buff
, BUFF_SZ
, "\tData overflowed\n");
2051 snprintf(buff
, BUFF_SZ
, "\tNot supported\n");
2053 hid_debug_event(hdev
, buff
);
2055 case REPORT_SPLASH_RESTART
:
2058 case REPORT_EXIT_KEYBOARD
:
2059 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
2060 "REPORT_EXIT_KEYBOARD", report
->id
, raw_size
-1);
2061 hid_debug_event(hdev
, buff
);
2062 snprintf(buff
, BUFF_SZ
, "\tRestart delay: %dms (0x%02x%02x)\n",
2063 raw_data
[1] | (raw_data
[2] << 8),
2064 raw_data
[2], raw_data
[1]);
2065 hid_debug_event(hdev
, buff
);
2067 case REPORT_VERSION
:
2068 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
2069 "REPORT_VERSION", report
->id
, raw_size
-1);
2070 hid_debug_event(hdev
, buff
);
2073 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
2074 "REPORT_DEVID", report
->id
, raw_size
-1);
2075 hid_debug_event(hdev
, buff
);
2077 case REPORT_SPLASH_SIZE
:
2078 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
2079 "REPORT_SPLASH_SIZE", report
->id
, raw_size
-1);
2080 hid_debug_event(hdev
, buff
);
2082 case REPORT_HOOK_VERSION
:
2083 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
2084 "REPORT_HOOK_VERSION", report
->id
, raw_size
-1);
2085 hid_debug_event(hdev
, buff
);
2087 case REPORT_EXIT_FLASHER
:
2088 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
2089 "REPORT_VERSION", report
->id
, raw_size
-1);
2090 hid_debug_event(hdev
, buff
);
2091 snprintf(buff
, BUFF_SZ
, "\tRestart delay: %dms (0x%02x%02x)\n",
2092 raw_data
[1] | (raw_data
[2] << 8),
2093 raw_data
[2], raw_data
[1]);
2094 hid_debug_event(hdev
, buff
);
2097 snprintf(buff
, BUFF_SZ
, "out report %s (%d, size=%d)\n",
2098 "<unknown>", report
->id
, raw_size
-1);
2099 hid_debug_event(hdev
, buff
);
2102 wake_up_interruptible(&hdev
->debug_wait
);
2106 static void picolcd_debug_raw_event(struct picolcd_data
*data
,
2107 struct hid_device
*hdev
, struct hid_report
*report
,
2108 u8
*raw_data
, int size
)
2113 /* Avoid unnecessary overhead if debugfs is disabled */
2114 if (!hdev
->debug_events
)
2117 buff
= kmalloc(BUFF_SZ
, GFP_ATOMIC
);
2121 switch (report
->id
) {
2122 case REPORT_ERROR_CODE
:
2123 /* 2 data bytes with affected report and error code */
2124 snprintf(buff
, BUFF_SZ
, "report %s (%d, size=%d)\n",
2125 "REPORT_ERROR_CODE", report
->id
, size
-1);
2126 hid_debug_event(hdev
, buff
);
2127 if (raw_data
[2] < ARRAY_SIZE(error_codes
))
2128 snprintf(buff
, BUFF_SZ
, "\tError code 0x%02x (%s) in reply to report 0x%02x\n",
2129 raw_data
[2], error_codes
[raw_data
[2]], raw_data
[1]);
2131 snprintf(buff
, BUFF_SZ
, "\tError code 0x%02x in reply to report 0x%02x\n",
2132 raw_data
[2], raw_data
[1]);
2133 hid_debug_event(hdev
, buff
);
2135 case REPORT_KEY_STATE
:
2136 /* 2 data bytes with key state */
2137 snprintf(buff
, BUFF_SZ
, "report %s (%d, size=%d)\n",
2138 "REPORT_KEY_STATE", report
->id
, size
-1);
2139 hid_debug_event(hdev
, buff
);
2140 if (raw_data
[1] == 0)
2141 snprintf(buff
, BUFF_SZ
, "\tNo key pressed\n");
2142 else if (raw_data
[2] == 0)
2143 snprintf(buff
, BUFF_SZ
, "\tOne key pressed: 0x%02x (%d)\n",
2144 raw_data
[1], raw_data
[1]);
2146 snprintf(buff
, BUFF_SZ
, "\tTwo keys pressed: 0x%02x (%d), 0x%02x (%d)\n",
2147 raw_data
[1], raw_data
[1], raw_data
[2], raw_data
[2]);
2148 hid_debug_event(hdev
, buff
);
2150 case REPORT_IR_DATA
:
2151 /* Up to 20 byes of IR scancode data */
2152 snprintf(buff
, BUFF_SZ
, "report %s (%d, size=%d)\n",
2153 "REPORT_IR_DATA", report
->id
, size
-1);
2154 hid_debug_event(hdev
, buff
);
2155 if (raw_data
[1] == 0) {
2156 snprintf(buff
, BUFF_SZ
, "\tUnexpectedly 0 data length\n");
2157 hid_debug_event(hdev
, buff
);
2158 } else if (raw_data
[1] + 1 <= size
) {
2159 snprintf(buff
, BUFF_SZ
, "\tData length: %d\n\tIR Data: ",
2161 hid_debug_event(hdev
, buff
);
2162 dump_buff_as_hex(buff
, BUFF_SZ
, raw_data
+2, raw_data
[1]-1);
2163 hid_debug_event(hdev
, buff
);
2165 snprintf(buff
, BUFF_SZ
, "\tOverflowing data length: %d\n",
2167 hid_debug_event(hdev
, buff
);
2170 case REPORT_EE_DATA
:
2171 /* Data buffer in response to REPORT_EE_READ or REPORT_EE_WRITE */
2172 snprintf(buff
, BUFF_SZ
, "report %s (%d, size=%d)\n",
2173 "REPORT_EE_DATA", report
->id
, size
-1);
2174 hid_debug_event(hdev
, buff
);
2175 snprintf(buff
, BUFF_SZ
, "\tData address: 0x%02x%02x\n",
2176 raw_data
[2], raw_data
[1]);
2177 hid_debug_event(hdev
, buff
);
2178 snprintf(buff
, BUFF_SZ
, "\tData length: %d\n", raw_data
[3]);
2179 hid_debug_event(hdev
, buff
);
2180 if (raw_data
[3] == 0) {
2181 snprintf(buff
, BUFF_SZ
, "\tNo data\n");
2182 hid_debug_event(hdev
, buff
);
2183 } else if (raw_data
[3] + 4 <= size
) {
2184 snprintf(buff
, BUFF_SZ
, "\tData: ");
2185 hid_debug_event(hdev
, buff
);
2186 dump_buff_as_hex(buff
, BUFF_SZ
, raw_data
+4, raw_data
[3]);
2187 hid_debug_event(hdev
, buff
);
2189 snprintf(buff
, BUFF_SZ
, "\tData overflowed\n");
2190 hid_debug_event(hdev
, buff
);
2194 /* Data buffer in response to REPORT_READ_MEMORY or REPORT_WRTIE_MEMORY */
2195 snprintf(buff
, BUFF_SZ
, "report %s (%d, size=%d)\n",
2196 "REPORT_MEMORY", report
->id
, size
-1);
2197 hid_debug_event(hdev
, buff
);
2198 switch (data
->addr_sz
) {
2200 snprintf(buff
, BUFF_SZ
, "\tData address: 0x%02x%02x\n",
2201 raw_data
[2], raw_data
[1]);
2202 hid_debug_event(hdev
, buff
);
2203 snprintf(buff
, BUFF_SZ
, "\tData length: %d\n", raw_data
[3]);
2204 hid_debug_event(hdev
, buff
);
2205 if (raw_data
[3] == 0) {
2206 snprintf(buff
, BUFF_SZ
, "\tNo data\n");
2207 } else if (raw_data
[3] + 4 <= size
) {
2208 snprintf(buff
, BUFF_SZ
, "\tData: ");
2209 hid_debug_event(hdev
, buff
);
2210 dump_buff_as_hex(buff
, BUFF_SZ
, raw_data
+4, raw_data
[3]);
2212 snprintf(buff
, BUFF_SZ
, "\tData overflowed\n");
2216 snprintf(buff
, BUFF_SZ
, "\tData address: 0x%02x%02x%02x\n",
2217 raw_data
[3], raw_data
[2], raw_data
[1]);
2218 hid_debug_event(hdev
, buff
);
2219 snprintf(buff
, BUFF_SZ
, "\tData length: %d\n", raw_data
[4]);
2220 hid_debug_event(hdev
, buff
);
2221 if (raw_data
[4] == 0) {
2222 snprintf(buff
, BUFF_SZ
, "\tNo data\n");
2223 } else if (raw_data
[4] + 5 <= size
) {
2224 snprintf(buff
, BUFF_SZ
, "\tData: ");
2225 hid_debug_event(hdev
, buff
);
2226 dump_buff_as_hex(buff
, BUFF_SZ
, raw_data
+5, raw_data
[4]);
2228 snprintf(buff
, BUFF_SZ
, "\tData overflowed\n");
2232 snprintf(buff
, BUFF_SZ
, "\tNot supported\n");
2234 hid_debug_event(hdev
, buff
);
2236 case REPORT_VERSION
:
2237 snprintf(buff
, BUFF_SZ
, "report %s (%d, size=%d)\n",
2238 "REPORT_VERSION", report
->id
, size
-1);
2239 hid_debug_event(hdev
, buff
);
2240 snprintf(buff
, BUFF_SZ
, "\tFirmware version: %d.%d\n",
2241 raw_data
[2], raw_data
[1]);
2242 hid_debug_event(hdev
, buff
);
2244 case REPORT_BL_ERASE_MEMORY
:
2245 snprintf(buff
, BUFF_SZ
, "report %s (%d, size=%d)\n",
2246 "REPORT_BL_ERASE_MEMORY", report
->id
, size
-1);
2247 hid_debug_event(hdev
, buff
);
2250 case REPORT_BL_READ_MEMORY
:
2251 snprintf(buff
, BUFF_SZ
, "report %s (%d, size=%d)\n",
2252 "REPORT_BL_READ_MEMORY", report
->id
, size
-1);
2253 hid_debug_event(hdev
, buff
);
2256 case REPORT_BL_WRITE_MEMORY
:
2257 snprintf(buff
, BUFF_SZ
, "report %s (%d, size=%d)\n",
2258 "REPORT_BL_WRITE_MEMORY", report
->id
, size
-1);
2259 hid_debug_event(hdev
, buff
);
2263 snprintf(buff
, BUFF_SZ
, "report %s (%d, size=%d)\n",
2264 "REPORT_DEVID", report
->id
, size
-1);
2265 hid_debug_event(hdev
, buff
);
2266 snprintf(buff
, BUFF_SZ
, "\tSerial: 0x%02x%02x%02x%02x\n",
2267 raw_data
[1], raw_data
[2], raw_data
[3], raw_data
[4]);
2268 hid_debug_event(hdev
, buff
);
2269 snprintf(buff
, BUFF_SZ
, "\tType: 0x%02x\n",
2271 hid_debug_event(hdev
, buff
);
2273 case REPORT_SPLASH_SIZE
:
2274 snprintf(buff
, BUFF_SZ
, "report %s (%d, size=%d)\n",
2275 "REPORT_SPLASH_SIZE", report
->id
, size
-1);
2276 hid_debug_event(hdev
, buff
);
2277 snprintf(buff
, BUFF_SZ
, "\tTotal splash space: %d\n",
2278 (raw_data
[2] << 8) | raw_data
[1]);
2279 hid_debug_event(hdev
, buff
);
2280 snprintf(buff
, BUFF_SZ
, "\tUsed splash space: %d\n",
2281 (raw_data
[4] << 8) | raw_data
[3]);
2282 hid_debug_event(hdev
, buff
);
2284 case REPORT_HOOK_VERSION
:
2285 snprintf(buff
, BUFF_SZ
, "report %s (%d, size=%d)\n",
2286 "REPORT_HOOK_VERSION", report
->id
, size
-1);
2287 hid_debug_event(hdev
, buff
);
2288 snprintf(buff
, BUFF_SZ
, "\tFirmware version: %d.%d\n",
2289 raw_data
[1], raw_data
[2]);
2290 hid_debug_event(hdev
, buff
);
2293 snprintf(buff
, BUFF_SZ
, "report %s (%d, size=%d)\n",
2294 "<unknown>", report
->id
, size
-1);
2295 hid_debug_event(hdev
, buff
);
2298 wake_up_interruptible(&hdev
->debug_wait
);
2302 static void picolcd_init_devfs(struct picolcd_data
*data
,
2303 struct hid_report
*eeprom_r
, struct hid_report
*eeprom_w
,
2304 struct hid_report
*flash_r
, struct hid_report
*flash_w
,
2305 struct hid_report
*reset
)
2307 struct hid_device
*hdev
= data
->hdev
;
2309 mutex_init(&data
->mutex_flash
);
2313 data
->debug_reset
= debugfs_create_file("reset", 0600,
2314 hdev
->debug_dir
, data
, &picolcd_debug_reset_fops
);
2317 if (eeprom_r
|| eeprom_w
)
2318 data
->debug_eeprom
= debugfs_create_file("eeprom",
2319 (eeprom_w
? S_IWUSR
: 0) | (eeprom_r
? S_IRUSR
: 0),
2320 hdev
->debug_dir
, data
, &picolcd_debug_eeprom_fops
);
2323 if (flash_r
&& flash_r
->maxfield
== 1 && flash_r
->field
[0]->report_size
== 8)
2324 data
->addr_sz
= flash_r
->field
[0]->report_count
- 1;
2327 if (data
->addr_sz
== 2 || data
->addr_sz
== 3) {
2328 data
->debug_flash
= debugfs_create_file("flash",
2329 (flash_w
? S_IWUSR
: 0) | (flash_r
? S_IRUSR
: 0),
2330 hdev
->debug_dir
, data
, &picolcd_debug_flash_fops
);
2331 } else if (flash_r
|| flash_w
)
2332 hid_warn(hdev
, "Unexpected FLASH access reports, 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 hid_err(hdev
, "unsupported KEY_STATE report\n");
2464 idev
= input_allocate_device();
2466 hid_err(hdev
, "failed to allocate input device\n");
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 hid_err(hdev
, "error registering the input device\n");
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 hid_info(hdev
, "Device with untested firmware revision, please submit /sys/kernel/debug/hid/%s/rdesc for this device.\n",
2526 dev_name(&hdev
->dev
));
2528 /* Setup keypad input device */
2529 error
= picolcd_init_keys(data
, picolcd_in_report(REPORT_KEY_STATE
, hdev
));
2533 /* Setup CIR input device */
2534 error
= picolcd_init_cir(data
, picolcd_in_report(REPORT_IR_DATA
, hdev
));
2538 /* Set up the framebuffer device */
2539 error
= picolcd_init_framebuffer(data
);
2543 /* Setup lcd class device */
2544 error
= picolcd_init_lcd(data
, picolcd_out_report(REPORT_CONTRAST
, hdev
));
2548 /* Setup backlight class device */
2549 error
= picolcd_init_backlight(data
, picolcd_out_report(REPORT_BRIGHTNESS
, hdev
));
2553 /* Setup the LED class devices */
2554 error
= picolcd_init_leds(data
, picolcd_out_report(REPORT_LED_STATE
, hdev
));
2558 picolcd_init_devfs(data
, picolcd_out_report(REPORT_EE_READ
, hdev
),
2559 picolcd_out_report(REPORT_EE_WRITE
, hdev
),
2560 picolcd_out_report(REPORT_READ_MEMORY
, hdev
),
2561 picolcd_out_report(REPORT_WRITE_MEMORY
, hdev
),
2562 picolcd_out_report(REPORT_RESET
, hdev
));
2565 picolcd_exit_leds(data
);
2566 picolcd_exit_backlight(data
);
2567 picolcd_exit_lcd(data
);
2568 picolcd_exit_framebuffer(data
);
2569 picolcd_exit_cir(data
);
2570 picolcd_exit_keys(data
);
2574 static int picolcd_probe_bootloader(struct hid_device
*hdev
, struct picolcd_data
*data
)
2578 error
= picolcd_check_version(hdev
);
2582 if (data
->version
[0] != 1 && data
->version
[1] != 0)
2583 hid_info(hdev
, "Device with untested bootloader revision, please submit /sys/kernel/debug/hid/%s/rdesc for this device.\n",
2584 dev_name(&hdev
->dev
));
2586 picolcd_init_devfs(data
, NULL
, NULL
,
2587 picolcd_out_report(REPORT_BL_READ_MEMORY
, hdev
),
2588 picolcd_out_report(REPORT_BL_WRITE_MEMORY
, hdev
), NULL
);
2592 static int picolcd_probe(struct hid_device
*hdev
,
2593 const struct hid_device_id
*id
)
2595 struct picolcd_data
*data
;
2596 int error
= -ENOMEM
;
2598 dbg_hid(PICOLCD_NAME
" hardware probe...\n");
2601 * Let's allocate the picolcd data structure, set some reasonable
2602 * defaults, and associate it with the device
2604 data
= kzalloc(sizeof(struct picolcd_data
), GFP_KERNEL
);
2606 hid_err(hdev
, "can't allocate space for Minibox PicoLCD device data\n");
2608 goto err_no_cleanup
;
2611 spin_lock_init(&data
->lock
);
2612 mutex_init(&data
->mutex
);
2614 data
->opmode_delay
= 5000;
2615 if (hdev
->product
== USB_DEVICE_ID_PICOLCD_BOOTLOADER
)
2616 data
->status
|= PICOLCD_BOOTLOADER
;
2617 hid_set_drvdata(hdev
, data
);
2619 /* Parse the device reports and start it up */
2620 error
= hid_parse(hdev
);
2622 hid_err(hdev
, "device report parse failed\n");
2623 goto err_cleanup_data
;
2626 /* We don't use hidinput but hid_hw_start() fails if nothing is
2627 * claimed. So spoof claimed input. */
2628 hdev
->claimed
= HID_CLAIMED_INPUT
;
2629 error
= hid_hw_start(hdev
, 0);
2632 hid_err(hdev
, "hardware start failed\n");
2633 goto err_cleanup_data
;
2636 error
= hid_hw_open(hdev
);
2638 hid_err(hdev
, "failed to open input interrupt pipe for key and IR events\n");
2639 goto err_cleanup_hid_hw
;
2642 error
= device_create_file(&hdev
->dev
, &dev_attr_operation_mode_delay
);
2644 hid_err(hdev
, "failed to create sysfs attributes\n");
2645 goto err_cleanup_hid_ll
;
2648 error
= device_create_file(&hdev
->dev
, &dev_attr_operation_mode
);
2650 hid_err(hdev
, "failed to create sysfs attributes\n");
2651 goto err_cleanup_sysfs1
;
2654 if (data
->status
& PICOLCD_BOOTLOADER
)
2655 error
= picolcd_probe_bootloader(hdev
, data
);
2657 error
= picolcd_probe_lcd(hdev
, data
);
2659 goto err_cleanup_sysfs2
;
2661 dbg_hid(PICOLCD_NAME
" activated and initialized\n");
2665 device_remove_file(&hdev
->dev
, &dev_attr_operation_mode
);
2667 device_remove_file(&hdev
->dev
, &dev_attr_operation_mode_delay
);
2675 hid_set_drvdata(hdev
, NULL
);
2680 static void picolcd_remove(struct hid_device
*hdev
)
2682 struct picolcd_data
*data
= hid_get_drvdata(hdev
);
2683 unsigned long flags
;
2685 dbg_hid(PICOLCD_NAME
" hardware remove...\n");
2686 spin_lock_irqsave(&data
->lock
, flags
);
2687 data
->status
|= PICOLCD_FAILED
;
2688 spin_unlock_irqrestore(&data
->lock
, flags
);
2689 #ifdef CONFIG_HID_PICOLCD_FB
2690 /* short-circuit FB as early as possible in order to
2691 * avoid long delays if we host console.
2694 data
->fb_info
->par
= NULL
;
2697 picolcd_exit_devfs(data
);
2698 device_remove_file(&hdev
->dev
, &dev_attr_operation_mode
);
2699 device_remove_file(&hdev
->dev
, &dev_attr_operation_mode_delay
);
2702 hid_set_drvdata(hdev
, NULL
);
2704 /* Shortcut potential pending reply that will never arrive */
2705 spin_lock_irqsave(&data
->lock
, flags
);
2707 complete(&data
->pending
->ready
);
2708 spin_unlock_irqrestore(&data
->lock
, flags
);
2711 picolcd_exit_leds(data
);
2712 /* Clean up the framebuffer */
2713 picolcd_exit_backlight(data
);
2714 picolcd_exit_lcd(data
);
2715 picolcd_exit_framebuffer(data
);
2717 picolcd_exit_cir(data
);
2718 picolcd_exit_keys(data
);
2720 mutex_destroy(&data
->mutex
);
2721 /* Finally, clean up the picolcd data itself */
2725 static const struct hid_device_id picolcd_devices
[] = {
2726 { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP
, USB_DEVICE_ID_PICOLCD
) },
2727 { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP
, USB_DEVICE_ID_PICOLCD_BOOTLOADER
) },
2730 MODULE_DEVICE_TABLE(hid
, picolcd_devices
);
2732 static struct hid_driver picolcd_driver
= {
2733 .name
= "hid-picolcd",
2734 .id_table
= picolcd_devices
,
2735 .probe
= picolcd_probe
,
2736 .remove
= picolcd_remove
,
2737 .raw_event
= picolcd_raw_event
,
2739 .suspend
= picolcd_suspend
,
2740 .resume
= picolcd_resume
,
2741 .reset_resume
= picolcd_reset_resume
,
2745 static int __init
picolcd_init(void)
2747 return hid_register_driver(&picolcd_driver
);
2750 static void __exit
picolcd_exit(void)
2752 hid_unregister_driver(&picolcd_driver
);
2753 #ifdef CONFIG_HID_PICOLCD_FB
2754 flush_work_sync(&picolcd_fb_cleanup
);
2755 WARN_ON(fb_pending
);
2759 module_init(picolcd_init
);
2760 module_exit(picolcd_exit
);
2761 MODULE_DESCRIPTION("Minibox graphics PicoLCD Driver");
2762 MODULE_LICENSE("GPL v2");