auo_k1900fb.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /*
  2. * auok190xfb.c -- FB driver for AUO-K1900 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-K1900 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 4 step gray (2bit) - FIXME: add strange refresh
  24. * mode3 2 step gray (1bit) - FIXME: add strange refresh
  25. * mode4 handwriting mode (strange behaviour)
  26. * mode5 automatic selection of update mode
  27. */
  28. #include <linux/module.h>
  29. #include <linux/kernel.h>
  30. #include <linux/errno.h>
  31. #include <linux/string.h>
  32. #include <linux/mm.h>
  33. #include <linux/slab.h>
  34. #include <linux/delay.h>
  35. #include <linux/interrupt.h>
  36. #include <linux/fb.h>
  37. #include <linux/init.h>
  38. #include <linux/platform_device.h>
  39. #include <linux/list.h>
  40. #include <linux/firmware.h>
  41. #include <linux/gpio.h>
  42. #include <linux/pm_runtime.h>
  43. #include <video/auo_k190xfb.h>
  44. #include "auo_k190x.h"
  45. /*
  46. * AUO-K1900 specific commands
  47. */
  48. #define AUOK1900_CMD_PARTIALDISP 0x1001
  49. #define AUOK1900_CMD_ROTATION 0x1006
  50. #define AUOK1900_CMD_LUT_STOP 0x1009
  51. #define AUOK1900_INIT_TEMP_AVERAGE (1 << 13)
  52. #define AUOK1900_INIT_ROTATE(_x) ((_x & 0x3) << 10)
  53. #define AUOK1900_INIT_RESOLUTION(_res) ((_res & 0x7) << 2)
  54. static void auok1900_init(struct auok190xfb_par *par)
  55. {
  56. struct device *dev = par->info->device;
  57. struct auok190x_board *board = par->board;
  58. u16 init_param = 0;
  59. pm_runtime_get_sync(dev);
  60. init_param |= AUOK1900_INIT_TEMP_AVERAGE;
  61. init_param |= AUOK1900_INIT_ROTATE(par->rotation);
  62. init_param |= AUOK190X_INIT_INVERSE_WHITE;
  63. init_param |= AUOK190X_INIT_FORMAT0;
  64. init_param |= AUOK1900_INIT_RESOLUTION(par->resolution);
  65. init_param |= AUOK190X_INIT_SHIFT_RIGHT;
  66. auok190x_send_cmdargs(par, AUOK190X_CMD_INIT, 1, &init_param);
  67. /* let the controller finish */
  68. board->wait_for_rdy(par);
  69. pm_runtime_mark_last_busy(dev);
  70. pm_runtime_put_autosuspend(dev);
  71. }
  72. static void auok1900_update_region(struct auok190xfb_par *par, int mode,
  73. u16 y1, u16 y2)
  74. {
  75. struct device *dev = par->info->device;
  76. unsigned char *buf = (unsigned char *)par->info->screen_base;
  77. int xres = par->info->var.xres;
  78. int line_length = par->info->fix.line_length;
  79. u16 args[4];
  80. pm_runtime_get_sync(dev);
  81. mutex_lock(&(par->io_lock));
  82. /* y1 and y2 must be a multiple of 2 so drop the lowest bit */
  83. y1 &= 0xfffe;
  84. y2 &= 0xfffe;
  85. dev_dbg(dev, "update (x,y,w,h,mode)=(%d,%d,%d,%d,%d)\n",
  86. 1, y1+1, xres, y2-y1, mode);
  87. /* to FIX handle different partial update modes */
  88. args[0] = mode | 1;
  89. args[1] = y1 + 1;
  90. args[2] = xres;
  91. args[3] = y2 - y1;
  92. buf += y1 * line_length;
  93. auok190x_send_cmdargs_pixels(par, AUOK1900_CMD_PARTIALDISP, 4, args,
  94. ((y2 - y1) * line_length)/2, (u16 *) buf);
  95. auok190x_send_command(par, AUOK190X_CMD_DATA_STOP);
  96. par->update_cnt++;
  97. mutex_unlock(&(par->io_lock));
  98. pm_runtime_mark_last_busy(dev);
  99. pm_runtime_put_autosuspend(dev);
  100. }
  101. static void auok1900fb_dpy_update_pages(struct auok190xfb_par *par,
  102. u16 y1, u16 y2)
  103. {
  104. int mode;
  105. if (par->update_mode < 0) {
  106. mode = AUOK190X_UPDATE_MODE(1);
  107. par->last_mode = -1;
  108. } else {
  109. mode = AUOK190X_UPDATE_MODE(par->update_mode);
  110. par->last_mode = par->update_mode;
  111. }
  112. if (par->flash)
  113. mode |= AUOK190X_UPDATE_NONFLASH;
  114. auok1900_update_region(par, mode, y1, y2);
  115. }
  116. static void auok1900fb_dpy_update(struct auok190xfb_par *par)
  117. {
  118. int mode;
  119. if (par->update_mode < 0) {
  120. mode = AUOK190X_UPDATE_MODE(0);
  121. par->last_mode = -1;
  122. } else {
  123. mode = AUOK190X_UPDATE_MODE(par->update_mode);
  124. par->last_mode = par->update_mode;
  125. }
  126. if (par->flash)
  127. mode |= AUOK190X_UPDATE_NONFLASH;
  128. auok1900_update_region(par, mode, 0, par->info->var.yres);
  129. par->update_cnt = 0;
  130. }
  131. static bool auok1900fb_need_refresh(struct auok190xfb_par *par)
  132. {
  133. return (par->update_cnt > 10);
  134. }
  135. static int auok1900fb_probe(struct platform_device *pdev)
  136. {
  137. struct auok190x_init_data init;
  138. struct auok190x_board *board;
  139. /* pick up board specific routines */
  140. board = pdev->dev.platform_data;
  141. if (!board)
  142. return -EINVAL;
  143. /* fill temporary init struct for common init */
  144. init.id = "auo_k1900fb";
  145. init.board = board;
  146. init.update_partial = auok1900fb_dpy_update_pages;
  147. init.update_all = auok1900fb_dpy_update;
  148. init.need_refresh = auok1900fb_need_refresh;
  149. init.init = auok1900_init;
  150. return auok190x_common_probe(pdev, &init);
  151. }
  152. static int auok1900fb_remove(struct platform_device *pdev)
  153. {
  154. return auok190x_common_remove(pdev);
  155. }
  156. static struct platform_driver auok1900fb_driver = {
  157. .probe = auok1900fb_probe,
  158. .remove = auok1900fb_remove,
  159. .driver = {
  160. .name = "auo_k1900fb",
  161. .pm = &auok190x_pm,
  162. },
  163. };
  164. module_platform_driver(auok1900fb_driver);
  165. MODULE_DESCRIPTION("framebuffer driver for the AUO-K1900 EPD controller");
  166. MODULE_AUTHOR("Heiko Stuebner <heiko@sntech.de>");
  167. MODULE_LICENSE("GPL");