hid-picolcd.h 8.9 KB

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