auo_k1901fb.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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 auok190x_board *board = par->board;
  94. u16 init_param = 0;
  95. init_param |= AUOK190X_INIT_INVERSE_WHITE;
  96. init_param |= AUOK190X_INIT_FORMAT0;
  97. init_param |= AUOK1901_INIT_RESOLUTION(par->resolution);
  98. init_param |= AUOK190X_INIT_SHIFT_LEFT;
  99. auok190x_send_cmdargs(par, AUOK190X_CMD_INIT, 1, &init_param);
  100. /* let the controller finish */
  101. board->wait_for_rdy(par);
  102. }
  103. static void auok1901_update_region(struct auok190xfb_par *par, int mode,
  104. u16 y1, u16 y2)
  105. {
  106. struct device *dev = par->info->device;
  107. unsigned char *buf = (unsigned char *)par->info->screen_base;
  108. int xres = par->info->var.xres;
  109. u16 args[5];
  110. pm_runtime_get_sync(dev);
  111. mutex_lock(&(par->io_lock));
  112. /* y1 and y2 must be a multiple of 2 so drop the lowest bit */
  113. y1 &= 0xfffe;
  114. y2 &= 0xfffe;
  115. dev_dbg(dev, "update (x,y,w,h,mode)=(%d,%d,%d,%d,%d)\n",
  116. 1, y1+1, xres, y2-y1, mode);
  117. /* K1901: first transfer the region data */
  118. args[0] = AUOK1901_DMA_ROTATE90(par->rotation) | 1;
  119. args[1] = y1 + 1;
  120. args[2] = xres;
  121. args[3] = y2 - y1;
  122. buf += y1 * xres;
  123. auok190x_send_cmdargs_pixels_nowait(par, AUOK1901_CMD_DMA_START, 4,
  124. args, ((y2 - y1) * xres)/2,
  125. (u16 *) buf);
  126. auok190x_send_command_nowait(par, AUOK190X_CMD_DATA_STOP);
  127. /* K1901: second tell the controller to update the region with mode */
  128. args[0] = mode | AUOK1901_DDMA_ROTATE180(par->rotation);
  129. args[1] = 1;
  130. args[2] = y1 + 1;
  131. args[3] = xres;
  132. args[4] = y2 - y1;
  133. auok190x_send_cmdargs_nowait(par, AUOK1901_CMD_DDMA_START, 5, args);
  134. par->update_cnt++;
  135. mutex_unlock(&(par->io_lock));
  136. pm_runtime_mark_last_busy(dev);
  137. pm_runtime_put_autosuspend(dev);
  138. }
  139. static void auok1901fb_dpy_update_pages(struct auok190xfb_par *par,
  140. u16 y1, u16 y2)
  141. {
  142. int mode;
  143. if (par->update_mode < 0) {
  144. mode = AUOK190X_UPDATE_MODE(1);
  145. par->last_mode = -1;
  146. } else {
  147. mode = AUOK190X_UPDATE_MODE(par->update_mode);
  148. par->last_mode = par->update_mode;
  149. }
  150. if (par->flash)
  151. mode |= AUOK190X_UPDATE_NONFLASH;
  152. auok1901_update_region(par, mode, y1, y2);
  153. }
  154. static void auok1901fb_dpy_update(struct auok190xfb_par *par)
  155. {
  156. int mode;
  157. /* When doing full updates, wait for the controller to be ready
  158. * This will hopefully catch some hangs of the K1901
  159. */
  160. par->board->wait_for_rdy(par);
  161. if (par->update_mode < 0) {
  162. mode = AUOK190X_UPDATE_MODE(0);
  163. par->last_mode = -1;
  164. } else {
  165. mode = AUOK190X_UPDATE_MODE(par->update_mode);
  166. par->last_mode = par->update_mode;
  167. }
  168. if (par->flash)
  169. mode |= AUOK190X_UPDATE_NONFLASH;
  170. auok1901_update_region(par, mode, 0, par->info->var.yres);
  171. par->update_cnt = 0;
  172. }
  173. static bool auok1901fb_need_refresh(struct auok190xfb_par *par)
  174. {
  175. return (par->update_cnt > 10);
  176. }
  177. static int auok1901fb_probe(struct platform_device *pdev)
  178. {
  179. struct auok190x_init_data init;
  180. struct auok190x_board *board;
  181. /* pick up board specific routines */
  182. board = pdev->dev.platform_data;
  183. if (!board)
  184. return -EINVAL;
  185. /* fill temporary init struct for common init */
  186. init.id = "auo_k1901fb";
  187. init.board = board;
  188. init.update_partial = auok1901fb_dpy_update_pages;
  189. init.update_all = auok1901fb_dpy_update;
  190. init.need_refresh = auok1901fb_need_refresh;
  191. init.init = auok1901_init;
  192. return auok190x_common_probe(pdev, &init);
  193. }
  194. static int auok1901fb_remove(struct platform_device *pdev)
  195. {
  196. return auok190x_common_remove(pdev);
  197. }
  198. static struct platform_driver auok1901fb_driver = {
  199. .probe = auok1901fb_probe,
  200. .remove = auok1901fb_remove,
  201. .driver = {
  202. .owner = THIS_MODULE,
  203. .name = "auo_k1901fb",
  204. .pm = &auok190x_pm,
  205. },
  206. };
  207. module_platform_driver(auok1901fb_driver);
  208. MODULE_DESCRIPTION("framebuffer driver for the AUO-K1901 EPD controller");
  209. MODULE_AUTHOR("Heiko Stuebner <heiko@sntech.de>");
  210. MODULE_LICENSE("GPL");