1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /***************************************************************************
3 * Copyright (C) 2010-2012 by Bruno Prémont <bonbons@linux-vserver.org> *
5 * Based on Logitech G13 driver (v0.4) *
6 * Copyright (C) 2009 by Rick L. Vinyard, Jr. <rvinyard@cs.nmsu.edu> *
8 ***************************************************************************/
10 #define PICOLCD_NAME "PicoLCD (graphic)"
13 #define REPORT_ERROR_CODE 0x10 /* LCD: IN[16] */
14 #define ERR_SUCCESS 0x00
15 #define ERR_PARAMETER_MISSING 0x01
16 #define ERR_DATA_MISSING 0x02
17 #define ERR_BLOCK_READ_ONLY 0x03
18 #define ERR_BLOCK_NOT_ERASABLE 0x04
19 #define ERR_BLOCK_TOO_BIG 0x05
20 #define ERR_SECTION_OVERFLOW 0x06
21 #define ERR_INVALID_CMD_LEN 0x07
22 #define ERR_INVALID_DATA_LEN 0x08
23 #define REPORT_KEY_STATE 0x11 /* LCD: IN[2] */
24 #define REPORT_IR_DATA 0x21 /* LCD: IN[63] */
25 #define REPORT_EE_DATA 0x32 /* LCD: IN[63] */
26 #define REPORT_MEMORY 0x41 /* LCD: IN[63] */
27 #define REPORT_LED_STATE 0x81 /* LCD: OUT[1] */
28 #define REPORT_BRIGHTNESS 0x91 /* LCD: OUT[1] */
29 #define REPORT_CONTRAST 0x92 /* LCD: OUT[1] */
30 #define REPORT_RESET 0x93 /* LCD: OUT[2] */
31 #define REPORT_LCD_CMD 0x94 /* LCD: OUT[63] */
32 #define REPORT_LCD_DATA 0x95 /* LCD: OUT[63] */
33 #define REPORT_LCD_CMD_DATA 0x96 /* LCD: OUT[63] */
34 #define REPORT_EE_READ 0xa3 /* LCD: OUT[63] */
35 #define REPORT_EE_WRITE 0xa4 /* LCD: OUT[63] */
36 #define REPORT_ERASE_MEMORY 0xb2 /* LCD: OUT[2] */
37 #define REPORT_READ_MEMORY 0xb3 /* LCD: OUT[3] */
38 #define REPORT_WRITE_MEMORY 0xb4 /* LCD: OUT[63] */
39 #define REPORT_SPLASH_RESTART 0xc1 /* LCD: OUT[1] */
40 #define REPORT_EXIT_KEYBOARD 0xef /* LCD: OUT[2] */
41 #define REPORT_VERSION 0xf1 /* LCD: IN[2],OUT[1] Bootloader: IN[2],OUT[1] */
42 #define REPORT_BL_ERASE_MEMORY 0xf2 /* Bootloader: IN[36],OUT[4] */
43 #define REPORT_BL_READ_MEMORY 0xf3 /* Bootloader: IN[36],OUT[4] */
44 #define REPORT_BL_WRITE_MEMORY 0xf4 /* Bootloader: IN[36],OUT[36] */
45 #define REPORT_DEVID 0xf5 /* LCD: IN[5], OUT[1] Bootloader: IN[5],OUT[1] */
46 #define REPORT_SPLASH_SIZE 0xf6 /* LCD: IN[4], OUT[1] */
47 #define REPORT_HOOK_VERSION 0xf7 /* LCD: IN[2], OUT[1] */
48 #define REPORT_EXIT_FLASHER 0xff /* Bootloader: OUT[2] */
50 /* Description of in-progress IO operation, used for operations
51 * that trigger response from device */
52 struct picolcd_pending {
53 struct hid_report *out_report;
54 struct hid_report *in_report;
55 struct completion ready;
61 #define PICOLCD_KEYS 17
63 /* Per device data structure */
65 struct hid_device *hdev;
66 #ifdef CONFIG_DEBUG_FS
67 struct dentry *debug_reset;
68 struct dentry *debug_eeprom;
69 struct dentry *debug_flash;
70 struct mutex mutex_flash;
74 unsigned short opmode_delay;
77 struct input_dev *input_keys;
78 #ifdef CONFIG_HID_PICOLCD_CIR
79 struct rc_dev *rc_dev;
81 unsigned short keycode[PICOLCD_KEYS];
83 #ifdef CONFIG_HID_PICOLCD_FB
84 /* Framebuffer stuff */
85 struct fb_info *fb_info;
86 #endif /* CONFIG_HID_PICOLCD_FB */
87 #ifdef CONFIG_HID_PICOLCD_LCD
88 struct lcd_device *lcd;
90 #endif /* CONFIG_HID_PICOLCD_LCD */
91 #ifdef CONFIG_HID_PICOLCD_BACKLIGHT
92 struct backlight_device *backlight;
95 #endif /* CONFIG_HID_PICOLCD_BACKLIGHT */
96 #ifdef CONFIG_HID_PICOLCD_LEDS
99 struct led_classdev *led[8];
100 #endif /* CONFIG_HID_PICOLCD_LEDS */
102 /* Housekeeping stuff */
105 struct picolcd_pending *pending;
107 #define PICOLCD_BOOTLOADER 1
108 #define PICOLCD_FAILED 2
109 #define PICOLCD_CIR_SHUN 4
112 #ifdef CONFIG_HID_PICOLCD_FB
113 struct picolcd_fb_data {
114 /* Framebuffer stuff */
116 struct picolcd_data *picolcd;
121 u8 *vbitmap; /* local copy of what was sent to PicoLCD */
122 u8 *bitmap; /* framebuffer */
124 #endif /* CONFIG_HID_PICOLCD_FB */
126 /* Find a given report */
127 #define picolcd_in_report(id, dev) picolcd_report(id, dev, HID_INPUT_REPORT)
128 #define picolcd_out_report(id, dev) picolcd_report(id, dev, HID_OUTPUT_REPORT)
130 struct hid_report *picolcd_report(int id, struct hid_device *hdev, int dir);
132 #ifdef CONFIG_DEBUG_FS
133 void picolcd_debug_out_report(struct picolcd_data *data,
134 struct hid_device *hdev, struct hid_report *report);
135 #define hid_hw_request(a, b, c) \
137 picolcd_debug_out_report(hid_get_drvdata(a), a, b); \
138 hid_hw_request(a, b, c); \
141 void picolcd_debug_raw_event(struct picolcd_data *data,
142 struct hid_device *hdev, struct hid_report *report,
143 u8 *raw_data, int size);
145 void picolcd_init_devfs(struct picolcd_data *data,
146 struct hid_report *eeprom_r, struct hid_report *eeprom_w,
147 struct hid_report *flash_r, struct hid_report *flash_w,
148 struct hid_report *reset);
150 void picolcd_exit_devfs(struct picolcd_data *data);
152 static inline void picolcd_debug_out_report(struct picolcd_data *data,
153 struct hid_device *hdev, struct hid_report *report)
156 static inline void picolcd_debug_raw_event(struct picolcd_data *data,
157 struct hid_device *hdev, struct hid_report *report,
158 u8 *raw_data, int size)
161 static inline void picolcd_init_devfs(struct picolcd_data *data,
162 struct hid_report *eeprom_r, struct hid_report *eeprom_w,
163 struct hid_report *flash_r, struct hid_report *flash_w,
164 struct hid_report *reset)
167 static inline void picolcd_exit_devfs(struct picolcd_data *data)
170 #endif /* CONFIG_DEBUG_FS */
173 #ifdef CONFIG_HID_PICOLCD_FB
174 int picolcd_fb_reset(struct picolcd_data *data, int clear);
176 int picolcd_init_framebuffer(struct picolcd_data *data);
178 void picolcd_exit_framebuffer(struct picolcd_data *data);
180 void picolcd_fb_refresh(struct picolcd_data *data);
181 #define picolcd_fbinfo(d) ((d)->fb_info)
183 static inline int picolcd_fb_reset(struct picolcd_data *data, int clear)
187 static inline int picolcd_init_framebuffer(struct picolcd_data *data)
191 static inline void picolcd_exit_framebuffer(struct picolcd_data *data)
194 static inline void picolcd_fb_refresh(struct picolcd_data *data)
197 #define picolcd_fbinfo(d) NULL
198 #endif /* CONFIG_HID_PICOLCD_FB */
201 #ifdef CONFIG_HID_PICOLCD_BACKLIGHT
202 int picolcd_init_backlight(struct picolcd_data *data,
203 struct hid_report *report);
205 void picolcd_exit_backlight(struct picolcd_data *data);
207 int picolcd_resume_backlight(struct picolcd_data *data);
209 void picolcd_suspend_backlight(struct picolcd_data *data);
211 static inline int picolcd_init_backlight(struct picolcd_data *data,
212 struct hid_report *report)
216 static inline void picolcd_exit_backlight(struct picolcd_data *data)
219 static inline int picolcd_resume_backlight(struct picolcd_data *data)
223 static inline void picolcd_suspend_backlight(struct picolcd_data *data)
227 #endif /* CONFIG_HID_PICOLCD_BACKLIGHT */
230 #ifdef CONFIG_HID_PICOLCD_LCD
231 int picolcd_init_lcd(struct picolcd_data *data,
232 struct hid_report *report);
234 void picolcd_exit_lcd(struct picolcd_data *data);
236 int picolcd_resume_lcd(struct picolcd_data *data);
238 static inline int picolcd_init_lcd(struct picolcd_data *data,
239 struct hid_report *report)
243 static inline void picolcd_exit_lcd(struct picolcd_data *data)
246 static inline int picolcd_resume_lcd(struct picolcd_data *data)
250 #endif /* CONFIG_HID_PICOLCD_LCD */
253 #ifdef CONFIG_HID_PICOLCD_LEDS
254 int picolcd_init_leds(struct picolcd_data *data,
255 struct hid_report *report);
257 void picolcd_exit_leds(struct picolcd_data *data);
259 void picolcd_leds_set(struct picolcd_data *data);
261 static inline int picolcd_init_leds(struct picolcd_data *data,
262 struct hid_report *report)
266 static inline void picolcd_exit_leds(struct picolcd_data *data)
269 static inline void picolcd_leds_set(struct picolcd_data *data)
272 #endif /* CONFIG_HID_PICOLCD_LEDS */
275 #ifdef CONFIG_HID_PICOLCD_CIR
276 int picolcd_raw_cir(struct picolcd_data *data,
277 struct hid_report *report, u8 *raw_data, int size);
279 int picolcd_init_cir(struct picolcd_data *data, struct hid_report *report);
281 void picolcd_exit_cir(struct picolcd_data *data);
283 static inline int picolcd_raw_cir(struct picolcd_data *data,
284 struct hid_report *report, u8 *raw_data, int size)
288 static inline int picolcd_init_cir(struct picolcd_data *data, struct hid_report *report)
292 static inline void picolcd_exit_cir(struct picolcd_data *data)
295 #endif /* CONFIG_HID_PICOLCD_CIR */
297 int picolcd_reset(struct hid_device *hdev);
298 struct picolcd_pending *picolcd_send_and_wait(struct hid_device *hdev,
299 int report_id, const u8 *raw_data, int size);