auo_k1900fb.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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 auok190x_board *board = par->board;
  57. u16 init_param = 0;
  58. init_param |= AUOK1900_INIT_TEMP_AVERAGE;
  59. init_param |= AUOK1900_INIT_ROTATE(par->rotation);
  60. init_param |= AUOK190X_INIT_INVERSE_WHITE;
  61. init_param |= AUOK190X_INIT_FORMAT0;
  62. init_param |= AUOK1900_INIT_RESOLUTION(par->resolution);
  63. init_param |= AUOK190X_INIT_SHIFT_RIGHT;
  64. auok190x_send_cmdargs(par, AUOK190X_CMD_INIT, 1, &init_param);
  65. /* let the controller finish */
  66. board->wait_for_rdy(par);
  67. }
  68. static void auok1900_update_region(struct auok190xfb_par *par, int mode,
  69. u16 y1, u16 y2)
  70. {
  71. struct device *dev = par->info->device;
  72. unsigned char *buf = (unsigned char *)par->info->screen_base;
  73. int xres = par->info->var.xres;
  74. u16 args[4];
  75. pm_runtime_get_sync(dev);
  76. mutex_lock(&(par->io_lock));
  77. /* y1 and y2 must be a multiple of 2 so drop the lowest bit */
  78. y1 &= 0xfffe;
  79. y2 &= 0xfffe;
  80. dev_dbg(dev, "update (x,y,w,h,mode)=(%d,%d,%d,%d,%d)\n",
  81. 1, y1+1, xres, y2-y1, mode);
  82. /* to FIX handle different partial update modes */
  83. args[0] = mode | 1;
  84. args[1] = y1 + 1;
  85. args[2] = xres;
  86. args[3] = y2 - y1;
  87. buf += y1 * xres;
  88. auok190x_send_cmdargs_pixels(par, AUOK1900_CMD_PARTIALDISP, 4, args,
  89. ((y2 - y1) * xres)/2, (u16 *) buf);
  90. auok190x_send_command(par, AUOK190X_CMD_DATA_STOP);
  91. par->update_cnt++;
  92. mutex_unlock(&(par->io_lock));
  93. pm_runtime_mark_last_busy(dev);
  94. pm_runtime_put_autosuspend(dev);
  95. }
  96. static void auok1900fb_dpy_update_pages(struct auok190xfb_par *par,
  97. u16 y1, u16 y2)
  98. {
  99. int mode;
  100. if (par->update_mode < 0) {
  101. mode = AUOK190X_UPDATE_MODE(1);
  102. par->last_mode = -1;
  103. } else {
  104. mode = AUOK190X_UPDATE_MODE(par->update_mode);
  105. par->last_mode = par->update_mode;
  106. }
  107. if (par->flash)
  108. mode |= AUOK190X_UPDATE_NONFLASH;
  109. auok1900_update_region(par, mode, y1, y2);
  110. }
  111. static void auok1900fb_dpy_update(struct auok190xfb_par *par)
  112. {
  113. int mode;
  114. if (par->update_mode < 0) {
  115. mode = AUOK190X_UPDATE_MODE(0);
  116. par->last_mode = -1;
  117. } else {
  118. mode = AUOK190X_UPDATE_MODE(par->update_mode);
  119. par->last_mode = par->update_mode;
  120. }
  121. if (par->flash)
  122. mode |= AUOK190X_UPDATE_NONFLASH;
  123. auok1900_update_region(par, mode, 0, par->info->var.yres);
  124. par->update_cnt = 0;
  125. }
  126. static bool auok1900fb_need_refresh(struct auok190xfb_par *par)
  127. {
  128. return (par->update_cnt > 10);
  129. }
  130. static int auok1900fb_probe(struct platform_device *pdev)
  131. {
  132. struct auok190x_init_data init;
  133. struct auok190x_board *board;
  134. /* pick up board specific routines */
  135. board = pdev->dev.platform_data;
  136. if (!board)
  137. return -EINVAL;
  138. /* fill temporary init struct for common init */
  139. init.id = "auo_k1900fb";
  140. init.board = board;
  141. init.update_partial = auok1900fb_dpy_update_pages;
  142. init.update_all = auok1900fb_dpy_update;
  143. init.need_refresh = auok1900fb_need_refresh;
  144. init.init = auok1900_init;
  145. return auok190x_common_probe(pdev, &init);
  146. }
  147. static int auok1900fb_remove(struct platform_device *pdev)
  148. {
  149. return auok190x_common_remove(pdev);
  150. }
  151. static struct platform_driver auok1900fb_driver = {
  152. .probe = auok1900fb_probe,
  153. .remove = auok1900fb_remove,
  154. .driver = {
  155. .owner = THIS_MODULE,
  156. .name = "auo_k1900fb",
  157. .pm = &auok190x_pm,
  158. },
  159. };
  160. module_platform_driver(auok1900fb_driver);
  161. MODULE_DESCRIPTION("framebuffer driver for the AUO-K1900 EPD controller");
  162. MODULE_AUTHOR("Heiko Stuebner <heiko@sntech.de>");
  163. MODULE_LICENSE("GPL");