hid-picolcd.h 9.7 KB

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