auo_k1901fb.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. /*
  2. * auok190xfb.c -- FB driver for AUO-K1901 controllers
  3. *
  4. * Copyright (C) 2011, 2012 Heiko Stuebner <heiko@sntech.de>
  5. *
  6. * based on broadsheetfb.c
  7. *
  8. * Copyright (C) 2008, Jaya Kumar
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. *
  14. * Layout is based on skeletonfb.c by James Simmons and Geert Uytterhoeven.
  15. *
  16. * This driver is written to be used with the AUO-K1901 display controller.
  17. *
  18. * It is intended to be architecture independent. A board specific driver
  19. * must be used to perform all the physical IO interactions.
  20. *
  21. * The controller supports different update modes:
  22. * mode0+1 16 step gray (4bit)
  23. * mode2+3 4 step gray (2bit)
  24. * mode4+5 2 step gray (1bit)
  25. * - mode4 is described as "without LUT"
  26. * mode7 automatic selection of update mode
  27. *
  28. * The most interesting difference to the K1900 is the ability to do screen
  29. * updates in an asynchronous fashion. Where the K1900 needs to wait for the
  30. * current update to complete, the K1901 can process later updates already.
  31. */
  32. #include <linux/module.h>
  33. #include <linux/kernel.h>
  34. #include <linux/errno.h>
  35. #include <linux/string.h>
  36. #include <linux/mm.h>
  37. #include <linux/slab.h>
  38. #include <linux/delay.h>
  39. #include <linux/interrupt.h>
  40. #include <linux/fb.h>
  41. #include <linux/init.h>
  42. #include <linux/platform_device.h>
  43. #include <linux/list.h>
  44. #include <linux/firmware.h>
  45. #include <linux/gpio.h>
  46. #include <linux/pm_runtime.h>
  47. #include <video/auo_k190xfb.h>
  48. #include "auo_k190x.h"
  49. /*
  50. * AUO-K1901 specific commands
  51. */
  52. #define AUOK1901_CMD_LUT_INTERFACE 0x0005
  53. #define AUOK1901_CMD_DMA_START 0x1001
  54. #define AUOK1901_CMD_CURSOR_START 0x1007
  55. #define AUOK1901_CMD_CURSOR_STOP AUOK190X_CMD_DATA_STOP
  56. #define AUOK1901_CMD_DDMA_START 0x1009
  57. #define AUOK1901_INIT_GATE_PULSE_LOW (0 << 14)
  58. #define AUOK1901_INIT_GATE_PULSE_HIGH (1 << 14)
  59. #define AUOK1901_INIT_SINGLE_GATE (0 << 13)
  60. #define AUOK1901_INIT_DOUBLE_GATE (1 << 13)
  61. /* Bits to pixels
  62. * Mode 15-12 11-8 7-4 3-0
  63. * format2 2 T 1 T
  64. * format3 1 T 2 T
  65. * format4 T 2 T 1
  66. * format5 T 1 T 2
  67. *
  68. * halftone modes:
  69. * format6 2 2 1 1
  70. * format7 1 1 2 2
  71. */
  72. #define AUOK1901_INIT_FORMAT2 (1 << 7)
  73. #define AUOK1901_INIT_FORMAT3 ((1 << 7) | (1 << 6))
  74. #define AUOK1901_INIT_FORMAT4 (1 << 8)
  75. #define AUOK1901_INIT_FORMAT5 ((1 << 8) | (1 << 6))
  76. #define AUOK1901_INIT_FORMAT6 ((1 << 8) | (1 << 7))
  77. #define AUOK1901_INIT_FORMAT7 ((1 << 8) | (1 << 7) | (1 << 6))
  78. /* res[4] to bit 10
  79. * res[3-0] to bits 5-2
  80. */
  81. #define AUOK1901_INIT_RESOLUTION(_res) (((_res & (1 << 4)) << 6) \
  82. | ((_res & 0xf) << 2))
  83. /*
  84. * portrait / landscape orientation in AUOK1901_CMD_DMA_START
  85. */
  86. #define AUOK1901_DMA_ROTATE90(_rot) ((_rot & 1) << 13)
  87. /*
  88. * equivalent to 1 << 11, needs the ~ to have same rotation like K1900
  89. */
  90. #define AUOK1901_DDMA_ROTATE180(_rot) ((~_rot & 2) << 10)
  91. static void auok1901_init(struct auok190xfb_par *par)
  92. {
  93. struct device *dev = par->info->device;
  94. struct auok190x_board *board = par->board;
  95. u16 init_param = 0;
  96. pm_runtime_get_sync(dev);
  97. init_param |= AUOK190X_INIT_INVERSE_WHITE;
  98. init_param |= AUOK190X_INIT_FORMAT0;
  99. init_param |= AUOK1901_INIT_RESOLUTION(par->resolution);
  100. init_param |= AUOK190X_INIT_SHIFT_LEFT;
  101. auok190x_send_cmdargs(par, AUOK190X_CMD_INIT, 1, &init_param);
  102. /* let the controller finish */
  103. board->wait_for_rdy(par);
  104. pm_runtime_mark_last_busy(dev);
  105. pm_runtime_put_autosuspend(dev);
  106. }
  107. static void auok1901_update_region(struct auok190xfb_par *par, int mode,
  108. u16 y1, u16 y2)
  109. {
  110. struct device *dev = par->info->device;
  111. unsigned char *buf = (unsigned char *)par->info->screen_base;
  112. int xres = par->info->var.xres;
  113. int line_length = par->info->fix.line_length;
  114. u16 args[5];
  115. pm_runtime_get_sync(dev);
  116. mutex_lock(&(par->io_lock));
  117. /* y1 and y2 must be a multiple of 2 so drop the lowest bit */
  118. y1 &= 0xfffe;
  119. y2 &= 0xfffe;
  120. dev_dbg(dev, "update (x,y,w,h,mode)=(%d,%d,%d,%d,%d)\n",
  121. 1, y1+1, xres, y2-y1, mode);
  122. /* K1901: first transfer the region data */
  123. args[0] = AUOK1901_DMA_ROTATE90(par->rotation) | 1;
  124. args[1] = y1 + 1;
  125. args[2] = xres;
  126. args[3] = y2 - y1;
  127. buf += y1 * line_length;
  128. auok190x_send_cmdargs_pixels_nowait(par, AUOK1901_CMD_DMA_START, 4,
  129. args, ((y2 - y1) * line_length)/2,
  130. (u16 *) buf);
  131. auok190x_send_command_nowait(par, AUOK190X_CMD_DATA_STOP);
  132. /* K1901: second tell the controller to update the region with mode */
  133. args[0] = mode | AUOK1901_DDMA_ROTATE180(par->rotation);
  134. args[1] = 1;
  135. args[2] = y1 + 1;
  136. args[3] = xres;
  137. args[4] = y2 - y1;
  138. auok190x_send_cmdargs_nowait(par, AUOK1901_CMD_DDMA_START, 5, args);
  139. par->update_cnt++;
  140. mutex_unlock(&(par->io_lock));
  141. pm_runtime_mark_last_busy(dev);
  142. pm_runtime_put_autosuspend(dev);
  143. }
  144. static void auok1901fb_dpy_update_pages(struct auok190xfb_par *par,
  145. u16 y1, u16 y2)
  146. {
  147. int mode;
  148. if (par->update_mode < 0) {
  149. mode = AUOK190X_UPDATE_MODE(1);
  150. par->last_mode = -1;
  151. } else {
  152. mode = AUOK190X_UPDATE_MODE(par->update_mode);
  153. par->last_mode = par->update_mode;
  154. }
  155. if (par->flash)
  156. mode |= AUOK190X_UPDATE_NONFLASH;
  157. auok1901_update_region(par, mode, y1, y2);
  158. }
  159. static void auok1901fb_dpy_update(struct auok190xfb_par *par)
  160. {
  161. int mode;
  162. /* When doing full updates, wait for the controller to be ready
  163. * This will hopefully catch some hangs of the K1901
  164. */
  165. par->board->wait_for_rdy(par);
  166. if (par->update_mode < 0) {
  167. mode = AUOK190X_UPDATE_MODE(0);
  168. par->last_mode = -1;
  169. } else {
  170. mode = AUOK190X_UPDATE_MODE(par->update_mode);
  171. par->last_mode = par->update_mode;
  172. }
  173. if (par->flash)
  174. mode |= AUOK190X_UPDATE_NONFLASH;
  175. auok1901_update_region(par, mode, 0, par->info->var.yres);
  176. par->update_cnt = 0;
  177. }
  178. static bool auok1901fb_need_refresh(struct auok190xfb_par *par)
  179. {
  180. return (par->update_cnt > 10);
  181. }
  182. static int auok1901fb_probe(struct platform_device *pdev)
  183. {
  184. struct auok190x_init_data init;
  185. struct auok190x_board *board;
  186. /* pick up board specific routines */
  187. board = pdev->dev.platform_data;
  188. if (!board)
  189. return -EINVAL;
  190. /* fill temporary init struct for common init */
  191. init.id = "auo_k1901fb";
  192. init.board = board;
  193. init.update_partial = auok1901fb_dpy_update_pages;
  194. init.update_all = auok1901fb_dpy_update;
  195. init.need_refresh = auok1901fb_need_refresh;
  196. init.init = auok1901_init;
  197. return auok190x_common_probe(pdev, &init);
  198. }
  199. static int auok1901fb_remove(struct platform_device *pdev)
  200. {
  201. return auok190x_common_remove(pdev);
  202. }
  203. static struct platform_driver auok1901fb_driver = {
  204. .probe = auok1901fb_probe,
  205. .remove = auok1901fb_remove,
  206. .driver = {
  207. .name = "auo_k1901fb",
  208. .pm = &auok190x_pm,
  209. },
  210. };
  211. module_platform_driver(auok1901fb_driver);
  212. MODULE_DESCRIPTION("framebuffer driver for the AUO-K1901 EPD controller");
  213. MODULE_AUTHOR("Heiko Stuebner <heiko@sntech.de>");
  214. MODULE_LICENSE("GPL");