sdi.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. /*
  2. * linux/drivers/video/omap2/dss/sdi.c
  3. *
  4. * Copyright (C) 2009 Nokia Corporation
  5. * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License version 2 as published by
  9. * the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. * more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along with
  17. * this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #define DSS_SUBSYS_NAME "SDI"
  20. #include <linux/kernel.h>
  21. #include <linux/clk.h>
  22. #include <linux/delay.h>
  23. #include <linux/err.h>
  24. #include <plat/display.h>
  25. #include "dss.h"
  26. static struct {
  27. bool skip_init;
  28. bool update_enabled;
  29. } sdi;
  30. static void sdi_basic_init(void)
  31. {
  32. dispc_set_parallel_interface_mode(OMAP_DSS_PARALLELMODE_BYPASS);
  33. dispc_set_lcd_display_type(OMAP_DSS_LCD_DISPLAY_TFT);
  34. dispc_set_tft_data_lines(24);
  35. dispc_lcd_enable_signal_polarity(1);
  36. }
  37. static int sdi_display_enable(struct omap_dss_device *dssdev)
  38. {
  39. struct omap_video_timings *t = &dssdev->panel.timings;
  40. struct dss_clock_info dss_cinfo;
  41. struct dispc_clock_info dispc_cinfo;
  42. u16 lck_div, pck_div;
  43. unsigned long fck;
  44. unsigned long pck;
  45. int r;
  46. r = omap_dss_start_device(dssdev);
  47. if (r) {
  48. DSSERR("failed to start device\n");
  49. goto err0;
  50. }
  51. if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED) {
  52. DSSERR("dssdev already enabled\n");
  53. r = -EINVAL;
  54. goto err1;
  55. }
  56. /* In case of skip_init sdi_init has already enabled the clocks */
  57. if (!sdi.skip_init)
  58. dss_clk_enable(DSS_CLK_ICK | DSS_CLK_FCK1);
  59. sdi_basic_init();
  60. /* 15.5.9.1.2 */
  61. dssdev->panel.config |= OMAP_DSS_LCD_RF | OMAP_DSS_LCD_ONOFF;
  62. dispc_set_pol_freq(dssdev->panel.config, dssdev->panel.acbi,
  63. dssdev->panel.acb);
  64. if (!sdi.skip_init) {
  65. r = dss_calc_clock_div(1, t->pixel_clock * 1000,
  66. &dss_cinfo, &dispc_cinfo);
  67. } else {
  68. r = dss_get_clock_div(&dss_cinfo);
  69. r = dispc_get_clock_div(&dispc_cinfo);
  70. }
  71. if (r)
  72. goto err2;
  73. fck = dss_cinfo.fck;
  74. lck_div = dispc_cinfo.lck_div;
  75. pck_div = dispc_cinfo.pck_div;
  76. pck = fck / lck_div / pck_div / 1000;
  77. if (pck != t->pixel_clock) {
  78. DSSWARN("Could not find exact pixel clock. Requested %d kHz, "
  79. "got %lu kHz\n",
  80. t->pixel_clock, pck);
  81. t->pixel_clock = pck;
  82. }
  83. dispc_set_lcd_timings(t);
  84. r = dss_set_clock_div(&dss_cinfo);
  85. if (r)
  86. goto err2;
  87. r = dispc_set_clock_div(&dispc_cinfo);
  88. if (r)
  89. goto err2;
  90. if (!sdi.skip_init) {
  91. dss_sdi_init(dssdev->phy.sdi.datapairs);
  92. r = dss_sdi_enable();
  93. if (r)
  94. goto err1;
  95. mdelay(2);
  96. }
  97. dispc_enable_lcd_out(1);
  98. if (dssdev->driver->enable) {
  99. r = dssdev->driver->enable(dssdev);
  100. if (r)
  101. goto err3;
  102. }
  103. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  104. sdi.skip_init = 0;
  105. return 0;
  106. err3:
  107. dispc_enable_lcd_out(0);
  108. err2:
  109. dss_clk_disable(DSS_CLK_ICK | DSS_CLK_FCK1);
  110. err1:
  111. omap_dss_stop_device(dssdev);
  112. err0:
  113. return r;
  114. }
  115. static int sdi_display_resume(struct omap_dss_device *dssdev);
  116. static void sdi_display_disable(struct omap_dss_device *dssdev)
  117. {
  118. if (dssdev->state == OMAP_DSS_DISPLAY_DISABLED)
  119. return;
  120. if (dssdev->state == OMAP_DSS_DISPLAY_SUSPENDED)
  121. if (sdi_display_resume(dssdev))
  122. return;
  123. if (dssdev->driver->disable)
  124. dssdev->driver->disable(dssdev);
  125. dispc_enable_lcd_out(0);
  126. dss_sdi_disable();
  127. dss_clk_disable(DSS_CLK_ICK | DSS_CLK_FCK1);
  128. dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
  129. omap_dss_stop_device(dssdev);
  130. }
  131. static int sdi_display_suspend(struct omap_dss_device *dssdev)
  132. {
  133. if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
  134. return -EINVAL;
  135. if (dssdev->driver->suspend)
  136. dssdev->driver->suspend(dssdev);
  137. dispc_enable_lcd_out(0);
  138. dss_sdi_disable();
  139. dss_clk_disable(DSS_CLK_ICK | DSS_CLK_FCK1);
  140. dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED;
  141. return 0;
  142. }
  143. static int sdi_display_resume(struct omap_dss_device *dssdev)
  144. {
  145. int r;
  146. if (dssdev->state != OMAP_DSS_DISPLAY_SUSPENDED)
  147. return -EINVAL;
  148. dss_clk_enable(DSS_CLK_ICK | DSS_CLK_FCK1);
  149. r = dss_sdi_enable();
  150. if (r)
  151. goto err;
  152. mdelay(2);
  153. dispc_enable_lcd_out(1);
  154. if (dssdev->driver->resume)
  155. dssdev->driver->resume(dssdev);
  156. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  157. return 0;
  158. err:
  159. dss_clk_disable(DSS_CLK_ICK | DSS_CLK_FCK1);
  160. return r;
  161. }
  162. static int sdi_display_set_update_mode(struct omap_dss_device *dssdev,
  163. enum omap_dss_update_mode mode)
  164. {
  165. if (mode == OMAP_DSS_UPDATE_MANUAL)
  166. return -EINVAL;
  167. if (mode == OMAP_DSS_UPDATE_DISABLED) {
  168. dispc_enable_lcd_out(0);
  169. sdi.update_enabled = 0;
  170. } else {
  171. dispc_enable_lcd_out(1);
  172. sdi.update_enabled = 1;
  173. }
  174. return 0;
  175. }
  176. static enum omap_dss_update_mode sdi_display_get_update_mode(
  177. struct omap_dss_device *dssdev)
  178. {
  179. return sdi.update_enabled ? OMAP_DSS_UPDATE_AUTO :
  180. OMAP_DSS_UPDATE_DISABLED;
  181. }
  182. static void sdi_get_timings(struct omap_dss_device *dssdev,
  183. struct omap_video_timings *timings)
  184. {
  185. *timings = dssdev->panel.timings;
  186. }
  187. int sdi_init_display(struct omap_dss_device *dssdev)
  188. {
  189. DSSDBG("SDI init\n");
  190. dssdev->enable = sdi_display_enable;
  191. dssdev->disable = sdi_display_disable;
  192. dssdev->suspend = sdi_display_suspend;
  193. dssdev->resume = sdi_display_resume;
  194. dssdev->set_update_mode = sdi_display_set_update_mode;
  195. dssdev->get_update_mode = sdi_display_get_update_mode;
  196. dssdev->get_timings = sdi_get_timings;
  197. return 0;
  198. }
  199. int sdi_init(bool skip_init)
  200. {
  201. /* we store this for first display enable, then clear it */
  202. sdi.skip_init = skip_init;
  203. /*
  204. * Enable clocks already here, otherwise there would be a toggle
  205. * of them until sdi_display_enable is called.
  206. */
  207. if (skip_init)
  208. dss_clk_enable(DSS_CLK_ICK | DSS_CLK_FCK1);
  209. return 0;
  210. }
  211. void sdi_exit(void)
  212. {
  213. }