blob: dc4c795dea5cb47cfbaa72d504f183c38b6609bc [file] [log] [blame]
Bruno Prémontfabdbf22012-07-30 21:38:28 +02001/***************************************************************************
2 * Copyright (C) 2010-2012 by Bruno Prémont <bonbons@linux-vserver.org> *
3 * *
4 * Based on Logitech G13 driver (v0.4) *
5 * Copyright (C) 2009 by Rick L. Vinyard, Jr. <rvinyard@cs.nmsu.edu> *
6 * *
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. *
10 * *
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. *
15 * *
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 ***************************************************************************/
19
20#define PICOLCD_NAME "PicoLCD (graphic)"
21
22/* Report numbers */
23#define REPORT_ERROR_CODE 0x10 /* LCD: IN[16] */
24#define ERR_SUCCESS 0x00
25#define ERR_PARAMETER_MISSING 0x01
26#define ERR_DATA_MISSING 0x02
27#define ERR_BLOCK_READ_ONLY 0x03
28#define ERR_BLOCK_NOT_ERASABLE 0x04
29#define ERR_BLOCK_TOO_BIG 0x05
30#define ERR_SECTION_OVERFLOW 0x06
31#define ERR_INVALID_CMD_LEN 0x07
32#define ERR_INVALID_DATA_LEN 0x08
33#define REPORT_KEY_STATE 0x11 /* LCD: IN[2] */
34#define REPORT_IR_DATA 0x21 /* LCD: IN[63] */
35#define REPORT_EE_DATA 0x32 /* LCD: IN[63] */
36#define REPORT_MEMORY 0x41 /* LCD: IN[63] */
37#define REPORT_LED_STATE 0x81 /* LCD: OUT[1] */
38#define REPORT_BRIGHTNESS 0x91 /* LCD: OUT[1] */
39#define REPORT_CONTRAST 0x92 /* LCD: OUT[1] */
40#define REPORT_RESET 0x93 /* LCD: OUT[2] */
41#define REPORT_LCD_CMD 0x94 /* LCD: OUT[63] */
42#define REPORT_LCD_DATA 0x95 /* LCD: OUT[63] */
43#define REPORT_LCD_CMD_DATA 0x96 /* LCD: OUT[63] */
44#define REPORT_EE_READ 0xa3 /* LCD: OUT[63] */
45#define REPORT_EE_WRITE 0xa4 /* LCD: OUT[63] */
46#define REPORT_ERASE_MEMORY 0xb2 /* LCD: OUT[2] */
47#define REPORT_READ_MEMORY 0xb3 /* LCD: OUT[3] */
48#define REPORT_WRITE_MEMORY 0xb4 /* LCD: OUT[63] */
49#define REPORT_SPLASH_RESTART 0xc1 /* LCD: OUT[1] */
50#define REPORT_EXIT_KEYBOARD 0xef /* LCD: OUT[2] */
51#define REPORT_VERSION 0xf1 /* LCD: IN[2],OUT[1] Bootloader: IN[2],OUT[1] */
52#define REPORT_BL_ERASE_MEMORY 0xf2 /* Bootloader: IN[36],OUT[4] */
53#define REPORT_BL_READ_MEMORY 0xf3 /* Bootloader: IN[36],OUT[4] */
54#define REPORT_BL_WRITE_MEMORY 0xf4 /* Bootloader: IN[36],OUT[36] */
55#define REPORT_DEVID 0xf5 /* LCD: IN[5], OUT[1] Bootloader: IN[5],OUT[1] */
56#define REPORT_SPLASH_SIZE 0xf6 /* LCD: IN[4], OUT[1] */
57#define REPORT_HOOK_VERSION 0xf7 /* LCD: IN[2], OUT[1] */
58#define REPORT_EXIT_FLASHER 0xff /* Bootloader: OUT[2] */
59
60/* Description of in-progress IO operation, used for operations
61 * that trigger response from device */
62struct picolcd_pending {
63 struct hid_report *out_report;
64 struct hid_report *in_report;
65 struct completion ready;
66 int raw_size;
67 u8 raw_data[64];
68};
69
70
71#define PICOLCD_KEYS 17
72
73/* Per device data structure */
74struct picolcd_data {
75 struct hid_device *hdev;
76#ifdef CONFIG_DEBUG_FS
77 struct dentry *debug_reset;
78 struct dentry *debug_eeprom;
79 struct dentry *debug_flash;
80 struct mutex mutex_flash;
81 int addr_sz;
82#endif
83 u8 version[2];
84 unsigned short opmode_delay;
85 /* input stuff */
86 u8 pressed_keys[2];
87 struct input_dev *input_keys;
88 struct input_dev *input_cir;
89 unsigned short keycode[PICOLCD_KEYS];
90
91#ifdef CONFIG_HID_PICOLCD_FB
92 /* Framebuffer stuff */
Bruno Prémontfabdbf22012-07-30 21:38:28 +020093 struct fb_info *fb_info;
Bruno Prémontfabdbf22012-07-30 21:38:28 +020094#endif /* CONFIG_HID_PICOLCD_FB */
95#ifdef CONFIG_HID_PICOLCD_LCD
96 struct lcd_device *lcd;
97 u8 lcd_contrast;
98#endif /* CONFIG_HID_PICOLCD_LCD */
99#ifdef CONFIG_HID_PICOLCD_BACKLIGHT
100 struct backlight_device *backlight;
101 u8 lcd_brightness;
102 u8 lcd_power;
103#endif /* CONFIG_HID_PICOLCD_BACKLIGHT */
104#ifdef CONFIG_HID_PICOLCD_LEDS
105 /* LED stuff */
106 u8 led_state;
107 struct led_classdev *led[8];
108#endif /* CONFIG_HID_PICOLCD_LEDS */
109
110 /* Housekeeping stuff */
111 spinlock_t lock;
112 struct mutex mutex;
113 struct picolcd_pending *pending;
114 int status;
115#define PICOLCD_BOOTLOADER 1
116#define PICOLCD_FAILED 2
Bruno Prémontfabdbf22012-07-30 21:38:28 +0200117};
118
Bruno Prémont16048702012-08-19 19:32:04 +0200119#ifdef CONFIG_HID_PICOLCD_FB
120struct picolcd_fb_data {
121 /* Framebuffer stuff */
122 spinlock_t lock;
123 struct picolcd_data *picolcd;
124 u8 update_rate;
125 u8 bpp;
126 u8 force;
127 u8 ready;
128 u8 *vbitmap; /* local copy of what was sent to PicoLCD */
129 u8 *bitmap; /* framebuffer */
130};
131#endif /* CONFIG_HID_PICOLCD_FB */
Bruno Prémontfabdbf22012-07-30 21:38:28 +0200132
133/* Find a given report */
134#define picolcd_in_report(id, dev) picolcd_report(id, dev, HID_INPUT_REPORT)
135#define picolcd_out_report(id, dev) picolcd_report(id, dev, HID_OUTPUT_REPORT)
136
137struct hid_report *picolcd_report(int id, struct hid_device *hdev, int dir);
138
139#ifdef CONFIG_DEBUG_FS
140void picolcd_debug_out_report(struct picolcd_data *data,
141 struct hid_device *hdev, struct hid_report *report);
142#define usbhid_submit_report(a, b, c) \
143 do { \
144 picolcd_debug_out_report(hid_get_drvdata(a), a, b); \
145 usbhid_submit_report(a, b, c); \
146 } while (0)
147
148void picolcd_debug_raw_event(struct picolcd_data *data,
149 struct hid_device *hdev, struct hid_report *report,
150 u8 *raw_data, int size);
151
152void picolcd_init_devfs(struct picolcd_data *data,
153 struct hid_report *eeprom_r, struct hid_report *eeprom_w,
154 struct hid_report *flash_r, struct hid_report *flash_w,
155 struct hid_report *reset);
156
157void picolcd_exit_devfs(struct picolcd_data *data);
158#else
159static inline void picolcd_debug_raw_event(struct picolcd_data *data,
160 struct hid_device *hdev, struct hid_report *report,
161 u8 *raw_data, int size)
162{
163}
164static inline void picolcd_init_devfs(struct picolcd_data *data,
165 struct hid_report *eeprom_r, struct hid_report *eeprom_w,
166 struct hid_report *flash_r, struct hid_report *flash_w,
167 struct hid_report *reset)
168{
169}
170static inline void picolcd_exit_devfs(struct picolcd_data *data)
171{
172}
173static inline void picolcd_debug_raw_event(struct picolcd_data *data,
174 struct hid_device *hdev, struct hid_report *report,
175 u8 *raw_data, int size)
176{
177}
178#endif /* CONFIG_DEBUG_FS */
179
180
181#ifdef CONFIG_HID_PICOLCD_FB
182int picolcd_fb_reset(struct picolcd_data *data, int clear);
183
184int picolcd_init_framebuffer(struct picolcd_data *data);
185
186void picolcd_exit_framebuffer(struct picolcd_data *data);
187
Bruno Prémontfabdbf22012-07-30 21:38:28 +0200188void picolcd_fb_refresh(struct picolcd_data *data);
189#define picolcd_fbinfo(d) ((d)->fb_info)
190#else
191static inline int picolcd_fb_reset(struct picolcd_data *data, int clear)
192{
193 return 0;
194}
195static inline int picolcd_init_framebuffer(struct picolcd_data *data)
196{
197 return 0;
198}
199static inline void picolcd_exit_framebuffer(struct picolcd_data *data)
200{
201}
Bruno Prémontfabdbf22012-07-30 21:38:28 +0200202static inline void picolcd_fb_refresh(struct picolcd_data *data)
203{
204}
205#define picolcd_fbinfo(d) NULL
206#endif /* CONFIG_HID_PICOLCD_FB */
207
208
209#ifdef CONFIG_HID_PICOLCD_BACKLIGHT
210int picolcd_init_backlight(struct picolcd_data *data,
211 struct hid_report *report);
212
213void picolcd_exit_backlight(struct picolcd_data *data);
214
215int picolcd_resume_backlight(struct picolcd_data *data);
216
217void picolcd_suspend_backlight(struct picolcd_data *data);
218#else
219static inline int picolcd_init_backlight(struct picolcd_data *data,
220 struct hid_report *report)
221{
222 return 0;
223}
224static inline void picolcd_exit_backlight(struct picolcd_data *data)
225{
226}
227static inline int picolcd_resume_backlight(struct picolcd_data *data)
228{
229 return 0;
230}
231static inline void picolcd_suspend_backlight(struct picolcd_data *data)
232{
233}
234
235#endif /* CONFIG_HID_PICOLCD_BACKLIGHT */
236
237
238#ifdef CONFIG_HID_PICOLCD_LCD
239int picolcd_init_lcd(struct picolcd_data *data,
240 struct hid_report *report);
241
242void picolcd_exit_lcd(struct picolcd_data *data);
243
244int picolcd_resume_lcd(struct picolcd_data *data);
245#else
246static inline int picolcd_init_lcd(struct picolcd_data *data,
247 struct hid_report *report)
248{
249 return 0;
250}
251static inline void picolcd_exit_lcd(struct picolcd_data *data)
252{
253}
254static inline int picolcd_resume_lcd(struct picolcd_data *data)
255{
256 return 0;
257}
258#endif /* CONFIG_HID_PICOLCD_LCD */
259
260
261#ifdef CONFIG_HID_PICOLCD_LEDS
262int picolcd_init_leds(struct picolcd_data *data,
263 struct hid_report *report);
264
265void picolcd_exit_leds(struct picolcd_data *data);
266
267void picolcd_leds_set(struct picolcd_data *data);
268#else
269static inline int picolcd_init_leds(struct picolcd_data *data,
270 struct hid_report *report)
271{
272 return 0;
273}
274static inline void picolcd_exit_leds(struct picolcd_data *data)
275{
276}
277static inline void picolcd_leds_set(struct picolcd_data *data)
278{
279}
280#endif /* CONFIG_HID_PICOLCD_LEDS */
281
282
283#ifdef CONFIG_HID_PICOLCD_CIR
284int picolcd_raw_cir(struct picolcd_data *data,
285 struct hid_report *report, u8 *raw_data, int size);
286
287int picolcd_init_cir(struct picolcd_data *data, struct hid_report *report);
288
289void picolcd_exit_cir(struct picolcd_data *data);
290#else
291static inline int picolcd_raw_cir(struct picolcd_data *data,
292 struct hid_report *report, u8 *raw_data, int size)
293{
294 return 1;
295}
296static inline int picolcd_init_cir(struct picolcd_data *data, struct hid_report *report)
297{
298 return 0;
299}
300static inline void picolcd_exit_cir(struct picolcd_data *data)
301{
302}
303#endif /* CONFIG_HID_PICOLCD_LIRC */
304
305int picolcd_reset(struct hid_device *hdev);
306struct picolcd_pending *picolcd_send_and_wait(struct hid_device *hdev,
307 int report_id, const u8 *raw_data, int size);