/drivers/video/omap2/dss/dispc.c

https://bitbucket.org/cyanogenmod/android_kernel_asus_tf300t · C · 3780 lines · 2977 code · 660 blank · 143 comment · 543 complexity · 903a9a937cfbcc11572746619aab0c7d MD5 · raw file

Large files are truncated click here to view the full file

  1. /*
  2. * linux/drivers/video/omap2/dss/dispc.c
  3. *
  4. * Copyright (C) 2009 Nokia Corporation
  5. * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
  6. *
  7. * Some code and ideas taken from drivers/video/omap/ driver
  8. * by Imre Deak.
  9. *
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of the GNU General Public License version 2 as published by
  12. * the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful, but WITHOUT
  15. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  16. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  17. * more details.
  18. *
  19. * You should have received a copy of the GNU General Public License along with
  20. * this program. If not, see <http://www.gnu.org/licenses/>.
  21. */
  22. #define DSS_SUBSYS_NAME "DISPC"
  23. #include <linux/kernel.h>
  24. #include <linux/dma-mapping.h>
  25. #include <linux/vmalloc.h>
  26. #include <linux/clk.h>
  27. #include <linux/io.h>
  28. #include <linux/jiffies.h>
  29. #include <linux/seq_file.h>
  30. #include <linux/delay.h>
  31. #include <linux/workqueue.h>
  32. #include <linux/hardirq.h>
  33. #include <linux/interrupt.h>
  34. #include <linux/platform_device.h>
  35. #include <linux/pm_runtime.h>
  36. #include <plat/sram.h>
  37. #include <plat/clock.h>
  38. #include <video/omapdss.h>
  39. #include "dss.h"
  40. #include "dss_features.h"
  41. #include "dispc.h"
  42. /* DISPC */
  43. #define DISPC_SZ_REGS SZ_4K
  44. #define DISPC_IRQ_MASK_ERROR (DISPC_IRQ_GFX_FIFO_UNDERFLOW | \
  45. DISPC_IRQ_OCP_ERR | \
  46. DISPC_IRQ_VID1_FIFO_UNDERFLOW | \
  47. DISPC_IRQ_VID2_FIFO_UNDERFLOW | \
  48. DISPC_IRQ_SYNC_LOST | \
  49. DISPC_IRQ_SYNC_LOST_DIGIT)
  50. #define DISPC_MAX_NR_ISRS 8
  51. struct omap_dispc_isr_data {
  52. omap_dispc_isr_t isr;
  53. void *arg;
  54. u32 mask;
  55. };
  56. struct dispc_h_coef {
  57. s8 hc4;
  58. s8 hc3;
  59. u8 hc2;
  60. s8 hc1;
  61. s8 hc0;
  62. };
  63. struct dispc_v_coef {
  64. s8 vc22;
  65. s8 vc2;
  66. u8 vc1;
  67. s8 vc0;
  68. s8 vc00;
  69. };
  70. enum omap_burst_size {
  71. BURST_SIZE_X2 = 0,
  72. BURST_SIZE_X4 = 1,
  73. BURST_SIZE_X8 = 2,
  74. };
  75. #define REG_GET(idx, start, end) \
  76. FLD_GET(dispc_read_reg(idx), start, end)
  77. #define REG_FLD_MOD(idx, val, start, end) \
  78. dispc_write_reg(idx, FLD_MOD(dispc_read_reg(idx), val, start, end))
  79. struct dispc_irq_stats {
  80. unsigned long last_reset;
  81. unsigned irq_count;
  82. unsigned irqs[32];
  83. };
  84. static struct {
  85. struct platform_device *pdev;
  86. void __iomem *base;
  87. int ctx_loss_cnt;
  88. int irq;
  89. struct clk *dss_clk;
  90. u32 fifo_size[3];
  91. spinlock_t irq_lock;
  92. u32 irq_error_mask;
  93. struct omap_dispc_isr_data registered_isr[DISPC_MAX_NR_ISRS];
  94. u32 error_irqs;
  95. struct work_struct error_work;
  96. bool ctx_valid;
  97. u32 ctx[DISPC_SZ_REGS / sizeof(u32)];
  98. #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
  99. spinlock_t irq_stats_lock;
  100. struct dispc_irq_stats irq_stats;
  101. #endif
  102. } dispc;
  103. enum omap_color_component {
  104. /* used for all color formats for OMAP3 and earlier
  105. * and for RGB and Y color component on OMAP4
  106. */
  107. DISPC_COLOR_COMPONENT_RGB_Y = 1 << 0,
  108. /* used for UV component for
  109. * OMAP_DSS_COLOR_YUV2, OMAP_DSS_COLOR_UYVY, OMAP_DSS_COLOR_NV12
  110. * color formats on OMAP4
  111. */
  112. DISPC_COLOR_COMPONENT_UV = 1 << 1,
  113. };
  114. static void _omap_dispc_set_irqs(void);
  115. static inline void dispc_write_reg(const u16 idx, u32 val)
  116. {
  117. __raw_writel(val, dispc.base + idx);
  118. }
  119. static inline u32 dispc_read_reg(const u16 idx)
  120. {
  121. return __raw_readl(dispc.base + idx);
  122. }
  123. static int dispc_get_ctx_loss_count(void)
  124. {
  125. struct device *dev = &dispc.pdev->dev;
  126. struct omap_display_platform_data *pdata = dev->platform_data;
  127. struct omap_dss_board_info *board_data = pdata->board_data;
  128. int cnt;
  129. if (!board_data->get_context_loss_count)
  130. return -ENOENT;
  131. cnt = board_data->get_context_loss_count(dev);
  132. WARN_ONCE(cnt < 0, "get_context_loss_count failed: %d\n", cnt);
  133. return cnt;
  134. }
  135. #define SR(reg) \
  136. dispc.ctx[DISPC_##reg / sizeof(u32)] = dispc_read_reg(DISPC_##reg)
  137. #define RR(reg) \
  138. dispc_write_reg(DISPC_##reg, dispc.ctx[DISPC_##reg / sizeof(u32)])
  139. static void dispc_save_context(void)
  140. {
  141. int i;
  142. DSSDBG("dispc_save_context\n");
  143. SR(IRQENABLE);
  144. SR(CONTROL);
  145. SR(CONFIG);
  146. SR(DEFAULT_COLOR(OMAP_DSS_CHANNEL_LCD));
  147. SR(DEFAULT_COLOR(OMAP_DSS_CHANNEL_DIGIT));
  148. SR(TRANS_COLOR(OMAP_DSS_CHANNEL_LCD));
  149. SR(TRANS_COLOR(OMAP_DSS_CHANNEL_DIGIT));
  150. SR(LINE_NUMBER);
  151. SR(TIMING_H(OMAP_DSS_CHANNEL_LCD));
  152. SR(TIMING_V(OMAP_DSS_CHANNEL_LCD));
  153. SR(POL_FREQ(OMAP_DSS_CHANNEL_LCD));
  154. SR(DIVISORo(OMAP_DSS_CHANNEL_LCD));
  155. if (dss_has_feature(FEAT_GLOBAL_ALPHA))
  156. SR(GLOBAL_ALPHA);
  157. SR(SIZE_MGR(OMAP_DSS_CHANNEL_DIGIT));
  158. SR(SIZE_MGR(OMAP_DSS_CHANNEL_LCD));
  159. if (dss_has_feature(FEAT_MGR_LCD2)) {
  160. SR(CONTROL2);
  161. SR(DEFAULT_COLOR(OMAP_DSS_CHANNEL_LCD2));
  162. SR(TRANS_COLOR(OMAP_DSS_CHANNEL_LCD2));
  163. SR(SIZE_MGR(OMAP_DSS_CHANNEL_LCD2));
  164. SR(TIMING_H(OMAP_DSS_CHANNEL_LCD2));
  165. SR(TIMING_V(OMAP_DSS_CHANNEL_LCD2));
  166. SR(POL_FREQ(OMAP_DSS_CHANNEL_LCD2));
  167. SR(DIVISORo(OMAP_DSS_CHANNEL_LCD2));
  168. SR(CONFIG2);
  169. }
  170. SR(OVL_BA0(OMAP_DSS_GFX));
  171. SR(OVL_BA1(OMAP_DSS_GFX));
  172. SR(OVL_POSITION(OMAP_DSS_GFX));
  173. SR(OVL_SIZE(OMAP_DSS_GFX));
  174. SR(OVL_ATTRIBUTES(OMAP_DSS_GFX));
  175. SR(OVL_FIFO_THRESHOLD(OMAP_DSS_GFX));
  176. SR(OVL_ROW_INC(OMAP_DSS_GFX));
  177. SR(OVL_PIXEL_INC(OMAP_DSS_GFX));
  178. SR(OVL_WINDOW_SKIP(OMAP_DSS_GFX));
  179. SR(OVL_TABLE_BA(OMAP_DSS_GFX));
  180. SR(DATA_CYCLE1(OMAP_DSS_CHANNEL_LCD));
  181. SR(DATA_CYCLE2(OMAP_DSS_CHANNEL_LCD));
  182. SR(DATA_CYCLE3(OMAP_DSS_CHANNEL_LCD));
  183. if (dss_has_feature(FEAT_CPR)) {
  184. SR(CPR_COEF_R(OMAP_DSS_CHANNEL_LCD));
  185. SR(CPR_COEF_G(OMAP_DSS_CHANNEL_LCD));
  186. SR(CPR_COEF_B(OMAP_DSS_CHANNEL_LCD));
  187. }
  188. if (dss_has_feature(FEAT_MGR_LCD2)) {
  189. if (dss_has_feature(FEAT_CPR)) {
  190. SR(CPR_COEF_B(OMAP_DSS_CHANNEL_LCD2));
  191. SR(CPR_COEF_G(OMAP_DSS_CHANNEL_LCD2));
  192. SR(CPR_COEF_R(OMAP_DSS_CHANNEL_LCD2));
  193. }
  194. SR(DATA_CYCLE1(OMAP_DSS_CHANNEL_LCD2));
  195. SR(DATA_CYCLE2(OMAP_DSS_CHANNEL_LCD2));
  196. SR(DATA_CYCLE3(OMAP_DSS_CHANNEL_LCD2));
  197. }
  198. if (dss_has_feature(FEAT_PRELOAD))
  199. SR(OVL_PRELOAD(OMAP_DSS_GFX));
  200. /* VID1 */
  201. SR(OVL_BA0(OMAP_DSS_VIDEO1));
  202. SR(OVL_BA1(OMAP_DSS_VIDEO1));
  203. SR(OVL_POSITION(OMAP_DSS_VIDEO1));
  204. SR(OVL_SIZE(OMAP_DSS_VIDEO1));
  205. SR(OVL_ATTRIBUTES(OMAP_DSS_VIDEO1));
  206. SR(OVL_FIFO_THRESHOLD(OMAP_DSS_VIDEO1));
  207. SR(OVL_ROW_INC(OMAP_DSS_VIDEO1));
  208. SR(OVL_PIXEL_INC(OMAP_DSS_VIDEO1));
  209. SR(OVL_FIR(OMAP_DSS_VIDEO1));
  210. SR(OVL_PICTURE_SIZE(OMAP_DSS_VIDEO1));
  211. SR(OVL_ACCU0(OMAP_DSS_VIDEO1));
  212. SR(OVL_ACCU1(OMAP_DSS_VIDEO1));
  213. for (i = 0; i < 8; i++)
  214. SR(OVL_FIR_COEF_H(OMAP_DSS_VIDEO1, i));
  215. for (i = 0; i < 8; i++)
  216. SR(OVL_FIR_COEF_HV(OMAP_DSS_VIDEO1, i));
  217. for (i = 0; i < 5; i++)
  218. SR(OVL_CONV_COEF(OMAP_DSS_VIDEO1, i));
  219. if (dss_has_feature(FEAT_FIR_COEF_V)) {
  220. for (i = 0; i < 8; i++)
  221. SR(OVL_FIR_COEF_V(OMAP_DSS_VIDEO1, i));
  222. }
  223. if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
  224. SR(OVL_BA0_UV(OMAP_DSS_VIDEO1));
  225. SR(OVL_BA1_UV(OMAP_DSS_VIDEO1));
  226. SR(OVL_FIR2(OMAP_DSS_VIDEO1));
  227. SR(OVL_ACCU2_0(OMAP_DSS_VIDEO1));
  228. SR(OVL_ACCU2_1(OMAP_DSS_VIDEO1));
  229. for (i = 0; i < 8; i++)
  230. SR(OVL_FIR_COEF_H2(OMAP_DSS_VIDEO1, i));
  231. for (i = 0; i < 8; i++)
  232. SR(OVL_FIR_COEF_HV2(OMAP_DSS_VIDEO1, i));
  233. for (i = 0; i < 8; i++)
  234. SR(OVL_FIR_COEF_V2(OMAP_DSS_VIDEO1, i));
  235. }
  236. if (dss_has_feature(FEAT_ATTR2))
  237. SR(OVL_ATTRIBUTES2(OMAP_DSS_VIDEO1));
  238. if (dss_has_feature(FEAT_PRELOAD))
  239. SR(OVL_PRELOAD(OMAP_DSS_VIDEO1));
  240. /* VID2 */
  241. SR(OVL_BA0(OMAP_DSS_VIDEO2));
  242. SR(OVL_BA1(OMAP_DSS_VIDEO2));
  243. SR(OVL_POSITION(OMAP_DSS_VIDEO2));
  244. SR(OVL_SIZE(OMAP_DSS_VIDEO2));
  245. SR(OVL_ATTRIBUTES(OMAP_DSS_VIDEO2));
  246. SR(OVL_FIFO_THRESHOLD(OMAP_DSS_VIDEO2));
  247. SR(OVL_ROW_INC(OMAP_DSS_VIDEO2));
  248. SR(OVL_PIXEL_INC(OMAP_DSS_VIDEO2));
  249. SR(OVL_FIR(OMAP_DSS_VIDEO2));
  250. SR(OVL_PICTURE_SIZE(OMAP_DSS_VIDEO2));
  251. SR(OVL_ACCU0(OMAP_DSS_VIDEO2));
  252. SR(OVL_ACCU1(OMAP_DSS_VIDEO2));
  253. for (i = 0; i < 8; i++)
  254. SR(OVL_FIR_COEF_H(OMAP_DSS_VIDEO2, i));
  255. for (i = 0; i < 8; i++)
  256. SR(OVL_FIR_COEF_HV(OMAP_DSS_VIDEO2, i));
  257. for (i = 0; i < 5; i++)
  258. SR(OVL_CONV_COEF(OMAP_DSS_VIDEO2, i));
  259. if (dss_has_feature(FEAT_FIR_COEF_V)) {
  260. for (i = 0; i < 8; i++)
  261. SR(OVL_FIR_COEF_V(OMAP_DSS_VIDEO2, i));
  262. }
  263. if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
  264. SR(OVL_BA0_UV(OMAP_DSS_VIDEO2));
  265. SR(OVL_BA1_UV(OMAP_DSS_VIDEO2));
  266. SR(OVL_FIR2(OMAP_DSS_VIDEO2));
  267. SR(OVL_ACCU2_0(OMAP_DSS_VIDEO2));
  268. SR(OVL_ACCU2_1(OMAP_DSS_VIDEO2));
  269. for (i = 0; i < 8; i++)
  270. SR(OVL_FIR_COEF_H2(OMAP_DSS_VIDEO2, i));
  271. for (i = 0; i < 8; i++)
  272. SR(OVL_FIR_COEF_HV2(OMAP_DSS_VIDEO2, i));
  273. for (i = 0; i < 8; i++)
  274. SR(OVL_FIR_COEF_V2(OMAP_DSS_VIDEO2, i));
  275. }
  276. if (dss_has_feature(FEAT_ATTR2))
  277. SR(OVL_ATTRIBUTES2(OMAP_DSS_VIDEO2));
  278. if (dss_has_feature(FEAT_PRELOAD))
  279. SR(OVL_PRELOAD(OMAP_DSS_VIDEO2));
  280. if (dss_has_feature(FEAT_CORE_CLK_DIV))
  281. SR(DIVISOR);
  282. dispc.ctx_loss_cnt = dispc_get_ctx_loss_count();
  283. dispc.ctx_valid = true;
  284. DSSDBG("context saved, ctx_loss_count %d\n", dispc.ctx_loss_cnt);
  285. }
  286. static void dispc_restore_context(void)
  287. {
  288. int i, ctx;
  289. DSSDBG("dispc_restore_context\n");
  290. if (!dispc.ctx_valid)
  291. return;
  292. ctx = dispc_get_ctx_loss_count();
  293. if (ctx >= 0 && ctx == dispc.ctx_loss_cnt)
  294. return;
  295. DSSDBG("ctx_loss_count: saved %d, current %d\n",
  296. dispc.ctx_loss_cnt, ctx);
  297. /*RR(IRQENABLE);*/
  298. /*RR(CONTROL);*/
  299. RR(CONFIG);
  300. RR(DEFAULT_COLOR(OMAP_DSS_CHANNEL_LCD));
  301. RR(DEFAULT_COLOR(OMAP_DSS_CHANNEL_DIGIT));
  302. RR(TRANS_COLOR(OMAP_DSS_CHANNEL_LCD));
  303. RR(TRANS_COLOR(OMAP_DSS_CHANNEL_DIGIT));
  304. RR(LINE_NUMBER);
  305. RR(TIMING_H(OMAP_DSS_CHANNEL_LCD));
  306. RR(TIMING_V(OMAP_DSS_CHANNEL_LCD));
  307. RR(POL_FREQ(OMAP_DSS_CHANNEL_LCD));
  308. RR(DIVISORo(OMAP_DSS_CHANNEL_LCD));
  309. if (dss_has_feature(FEAT_GLOBAL_ALPHA))
  310. RR(GLOBAL_ALPHA);
  311. RR(SIZE_MGR(OMAP_DSS_CHANNEL_DIGIT));
  312. RR(SIZE_MGR(OMAP_DSS_CHANNEL_LCD));
  313. if (dss_has_feature(FEAT_MGR_LCD2)) {
  314. RR(DEFAULT_COLOR(OMAP_DSS_CHANNEL_LCD2));
  315. RR(TRANS_COLOR(OMAP_DSS_CHANNEL_LCD2));
  316. RR(SIZE_MGR(OMAP_DSS_CHANNEL_LCD2));
  317. RR(TIMING_H(OMAP_DSS_CHANNEL_LCD2));
  318. RR(TIMING_V(OMAP_DSS_CHANNEL_LCD2));
  319. RR(POL_FREQ(OMAP_DSS_CHANNEL_LCD2));
  320. RR(DIVISORo(OMAP_DSS_CHANNEL_LCD2));
  321. RR(CONFIG2);
  322. }
  323. RR(OVL_BA0(OMAP_DSS_GFX));
  324. RR(OVL_BA1(OMAP_DSS_GFX));
  325. RR(OVL_POSITION(OMAP_DSS_GFX));
  326. RR(OVL_SIZE(OMAP_DSS_GFX));
  327. RR(OVL_ATTRIBUTES(OMAP_DSS_GFX));
  328. RR(OVL_FIFO_THRESHOLD(OMAP_DSS_GFX));
  329. RR(OVL_ROW_INC(OMAP_DSS_GFX));
  330. RR(OVL_PIXEL_INC(OMAP_DSS_GFX));
  331. RR(OVL_WINDOW_SKIP(OMAP_DSS_GFX));
  332. RR(OVL_TABLE_BA(OMAP_DSS_GFX));
  333. RR(DATA_CYCLE1(OMAP_DSS_CHANNEL_LCD));
  334. RR(DATA_CYCLE2(OMAP_DSS_CHANNEL_LCD));
  335. RR(DATA_CYCLE3(OMAP_DSS_CHANNEL_LCD));
  336. if (dss_has_feature(FEAT_CPR)) {
  337. RR(CPR_COEF_R(OMAP_DSS_CHANNEL_LCD));
  338. RR(CPR_COEF_G(OMAP_DSS_CHANNEL_LCD));
  339. RR(CPR_COEF_B(OMAP_DSS_CHANNEL_LCD));
  340. }
  341. if (dss_has_feature(FEAT_MGR_LCD2)) {
  342. RR(DATA_CYCLE1(OMAP_DSS_CHANNEL_LCD2));
  343. RR(DATA_CYCLE2(OMAP_DSS_CHANNEL_LCD2));
  344. RR(DATA_CYCLE3(OMAP_DSS_CHANNEL_LCD2));
  345. if (dss_has_feature(FEAT_CPR)) {
  346. RR(CPR_COEF_B(OMAP_DSS_CHANNEL_LCD2));
  347. RR(CPR_COEF_G(OMAP_DSS_CHANNEL_LCD2));
  348. RR(CPR_COEF_R(OMAP_DSS_CHANNEL_LCD2));
  349. }
  350. }
  351. if (dss_has_feature(FEAT_PRELOAD))
  352. RR(OVL_PRELOAD(OMAP_DSS_GFX));
  353. /* VID1 */
  354. RR(OVL_BA0(OMAP_DSS_VIDEO1));
  355. RR(OVL_BA1(OMAP_DSS_VIDEO1));
  356. RR(OVL_POSITION(OMAP_DSS_VIDEO1));
  357. RR(OVL_SIZE(OMAP_DSS_VIDEO1));
  358. RR(OVL_ATTRIBUTES(OMAP_DSS_VIDEO1));
  359. RR(OVL_FIFO_THRESHOLD(OMAP_DSS_VIDEO1));
  360. RR(OVL_ROW_INC(OMAP_DSS_VIDEO1));
  361. RR(OVL_PIXEL_INC(OMAP_DSS_VIDEO1));
  362. RR(OVL_FIR(OMAP_DSS_VIDEO1));
  363. RR(OVL_PICTURE_SIZE(OMAP_DSS_VIDEO1));
  364. RR(OVL_ACCU0(OMAP_DSS_VIDEO1));
  365. RR(OVL_ACCU1(OMAP_DSS_VIDEO1));
  366. for (i = 0; i < 8; i++)
  367. RR(OVL_FIR_COEF_H(OMAP_DSS_VIDEO1, i));
  368. for (i = 0; i < 8; i++)
  369. RR(OVL_FIR_COEF_HV(OMAP_DSS_VIDEO1, i));
  370. for (i = 0; i < 5; i++)
  371. RR(OVL_CONV_COEF(OMAP_DSS_VIDEO1, i));
  372. if (dss_has_feature(FEAT_FIR_COEF_V)) {
  373. for (i = 0; i < 8; i++)
  374. RR(OVL_FIR_COEF_V(OMAP_DSS_VIDEO1, i));
  375. }
  376. if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
  377. RR(OVL_BA0_UV(OMAP_DSS_VIDEO1));
  378. RR(OVL_BA1_UV(OMAP_DSS_VIDEO1));
  379. RR(OVL_FIR2(OMAP_DSS_VIDEO1));
  380. RR(OVL_ACCU2_0(OMAP_DSS_VIDEO1));
  381. RR(OVL_ACCU2_1(OMAP_DSS_VIDEO1));
  382. for (i = 0; i < 8; i++)
  383. RR(OVL_FIR_COEF_H2(OMAP_DSS_VIDEO1, i));
  384. for (i = 0; i < 8; i++)
  385. RR(OVL_FIR_COEF_HV2(OMAP_DSS_VIDEO1, i));
  386. for (i = 0; i < 8; i++)
  387. RR(OVL_FIR_COEF_V2(OMAP_DSS_VIDEO1, i));
  388. }
  389. if (dss_has_feature(FEAT_ATTR2))
  390. RR(OVL_ATTRIBUTES2(OMAP_DSS_VIDEO1));
  391. if (dss_has_feature(FEAT_PRELOAD))
  392. RR(OVL_PRELOAD(OMAP_DSS_VIDEO1));
  393. /* VID2 */
  394. RR(OVL_BA0(OMAP_DSS_VIDEO2));
  395. RR(OVL_BA1(OMAP_DSS_VIDEO2));
  396. RR(OVL_POSITION(OMAP_DSS_VIDEO2));
  397. RR(OVL_SIZE(OMAP_DSS_VIDEO2));
  398. RR(OVL_ATTRIBUTES(OMAP_DSS_VIDEO2));
  399. RR(OVL_FIFO_THRESHOLD(OMAP_DSS_VIDEO2));
  400. RR(OVL_ROW_INC(OMAP_DSS_VIDEO2));
  401. RR(OVL_PIXEL_INC(OMAP_DSS_VIDEO2));
  402. RR(OVL_FIR(OMAP_DSS_VIDEO2));
  403. RR(OVL_PICTURE_SIZE(OMAP_DSS_VIDEO2));
  404. RR(OVL_ACCU0(OMAP_DSS_VIDEO2));
  405. RR(OVL_ACCU1(OMAP_DSS_VIDEO2));
  406. for (i = 0; i < 8; i++)
  407. RR(OVL_FIR_COEF_H(OMAP_DSS_VIDEO2, i));
  408. for (i = 0; i < 8; i++)
  409. RR(OVL_FIR_COEF_HV(OMAP_DSS_VIDEO2, i));
  410. for (i = 0; i < 5; i++)
  411. RR(OVL_CONV_COEF(OMAP_DSS_VIDEO2, i));
  412. if (dss_has_feature(FEAT_FIR_COEF_V)) {
  413. for (i = 0; i < 8; i++)
  414. RR(OVL_FIR_COEF_V(OMAP_DSS_VIDEO2, i));
  415. }
  416. if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
  417. RR(OVL_BA0_UV(OMAP_DSS_VIDEO2));
  418. RR(OVL_BA1_UV(OMAP_DSS_VIDEO2));
  419. RR(OVL_FIR2(OMAP_DSS_VIDEO2));
  420. RR(OVL_ACCU2_0(OMAP_DSS_VIDEO2));
  421. RR(OVL_ACCU2_1(OMAP_DSS_VIDEO2));
  422. for (i = 0; i < 8; i++)
  423. RR(OVL_FIR_COEF_H2(OMAP_DSS_VIDEO2, i));
  424. for (i = 0; i < 8; i++)
  425. RR(OVL_FIR_COEF_HV2(OMAP_DSS_VIDEO2, i));
  426. for (i = 0; i < 8; i++)
  427. RR(OVL_FIR_COEF_V2(OMAP_DSS_VIDEO2, i));
  428. }
  429. if (dss_has_feature(FEAT_ATTR2))
  430. RR(OVL_ATTRIBUTES2(OMAP_DSS_VIDEO2));
  431. if (dss_has_feature(FEAT_PRELOAD))
  432. RR(OVL_PRELOAD(OMAP_DSS_VIDEO2));
  433. if (dss_has_feature(FEAT_CORE_CLK_DIV))
  434. RR(DIVISOR);
  435. /* enable last, because LCD & DIGIT enable are here */
  436. RR(CONTROL);
  437. if (dss_has_feature(FEAT_MGR_LCD2))
  438. RR(CONTROL2);
  439. /* clear spurious SYNC_LOST_DIGIT interrupts */
  440. dispc_write_reg(DISPC_IRQSTATUS, DISPC_IRQ_SYNC_LOST_DIGIT);
  441. /*
  442. * enable last so IRQs won't trigger before
  443. * the context is fully restored
  444. */
  445. RR(IRQENABLE);
  446. DSSDBG("context restored\n");
  447. }
  448. #undef SR
  449. #undef RR
  450. int dispc_runtime_get(void)
  451. {
  452. int r;
  453. DSSDBG("dispc_runtime_get\n");
  454. r = pm_runtime_get_sync(&dispc.pdev->dev);
  455. WARN_ON(r < 0);
  456. return r < 0 ? r : 0;
  457. }
  458. void dispc_runtime_put(void)
  459. {
  460. int r;
  461. DSSDBG("dispc_runtime_put\n");
  462. r = pm_runtime_put(&dispc.pdev->dev);
  463. WARN_ON(r < 0);
  464. }
  465. bool dispc_go_busy(enum omap_channel channel)
  466. {
  467. int bit;
  468. if (channel == OMAP_DSS_CHANNEL_LCD ||
  469. channel == OMAP_DSS_CHANNEL_LCD2)
  470. bit = 5; /* GOLCD */
  471. else
  472. bit = 6; /* GODIGIT */
  473. if (channel == OMAP_DSS_CHANNEL_LCD2)
  474. return REG_GET(DISPC_CONTROL2, bit, bit) == 1;
  475. else
  476. return REG_GET(DISPC_CONTROL, bit, bit) == 1;
  477. }
  478. void dispc_go(enum omap_channel channel)
  479. {
  480. int bit;
  481. bool enable_bit, go_bit;
  482. if (channel == OMAP_DSS_CHANNEL_LCD ||
  483. channel == OMAP_DSS_CHANNEL_LCD2)
  484. bit = 0; /* LCDENABLE */
  485. else
  486. bit = 1; /* DIGITALENABLE */
  487. /* if the channel is not enabled, we don't need GO */
  488. if (channel == OMAP_DSS_CHANNEL_LCD2)
  489. enable_bit = REG_GET(DISPC_CONTROL2, bit, bit) == 1;
  490. else
  491. enable_bit = REG_GET(DISPC_CONTROL, bit, bit) == 1;
  492. if (!enable_bit)
  493. return;
  494. if (channel == OMAP_DSS_CHANNEL_LCD ||
  495. channel == OMAP_DSS_CHANNEL_LCD2)
  496. bit = 5; /* GOLCD */
  497. else
  498. bit = 6; /* GODIGIT */
  499. if (channel == OMAP_DSS_CHANNEL_LCD2)
  500. go_bit = REG_GET(DISPC_CONTROL2, bit, bit) == 1;
  501. else
  502. go_bit = REG_GET(DISPC_CONTROL, bit, bit) == 1;
  503. if (go_bit) {
  504. DSSERR("GO bit not down for channel %d\n", channel);
  505. return;
  506. }
  507. DSSDBG("GO %s\n", channel == OMAP_DSS_CHANNEL_LCD ? "LCD" :
  508. (channel == OMAP_DSS_CHANNEL_LCD2 ? "LCD2" : "DIGIT"));
  509. if (channel == OMAP_DSS_CHANNEL_LCD2)
  510. REG_FLD_MOD(DISPC_CONTROL2, 1, bit, bit);
  511. else
  512. REG_FLD_MOD(DISPC_CONTROL, 1, bit, bit);
  513. }
  514. static void _dispc_write_firh_reg(enum omap_plane plane, int reg, u32 value)
  515. {
  516. dispc_write_reg(DISPC_OVL_FIR_COEF_H(plane, reg), value);
  517. }
  518. static void _dispc_write_firhv_reg(enum omap_plane plane, int reg, u32 value)
  519. {
  520. dispc_write_reg(DISPC_OVL_FIR_COEF_HV(plane, reg), value);
  521. }
  522. static void _dispc_write_firv_reg(enum omap_plane plane, int reg, u32 value)
  523. {
  524. dispc_write_reg(DISPC_OVL_FIR_COEF_V(plane, reg), value);
  525. }
  526. static void _dispc_write_firh2_reg(enum omap_plane plane, int reg, u32 value)
  527. {
  528. BUG_ON(plane == OMAP_DSS_GFX);
  529. dispc_write_reg(DISPC_OVL_FIR_COEF_H2(plane, reg), value);
  530. }
  531. static void _dispc_write_firhv2_reg(enum omap_plane plane, int reg, u32 value)
  532. {
  533. BUG_ON(plane == OMAP_DSS_GFX);
  534. dispc_write_reg(DISPC_OVL_FIR_COEF_HV2(plane, reg), value);
  535. }
  536. static void _dispc_write_firv2_reg(enum omap_plane plane, int reg, u32 value)
  537. {
  538. BUG_ON(plane == OMAP_DSS_GFX);
  539. dispc_write_reg(DISPC_OVL_FIR_COEF_V2(plane, reg), value);
  540. }
  541. static void _dispc_set_scale_coef(enum omap_plane plane, int hscaleup,
  542. int vscaleup, int five_taps,
  543. enum omap_color_component color_comp)
  544. {
  545. /* Coefficients for horizontal up-sampling */
  546. static const struct dispc_h_coef coef_hup[8] = {
  547. { 0, 0, 128, 0, 0 },
  548. { -1, 13, 124, -8, 0 },
  549. { -2, 30, 112, -11, -1 },
  550. { -5, 51, 95, -11, -2 },
  551. { 0, -9, 73, 73, -9 },
  552. { -2, -11, 95, 51, -5 },
  553. { -1, -11, 112, 30, -2 },
  554. { 0, -8, 124, 13, -1 },
  555. };
  556. /* Coefficients for vertical up-sampling */
  557. static const struct dispc_v_coef coef_vup_3tap[8] = {
  558. { 0, 0, 128, 0, 0 },
  559. { 0, 3, 123, 2, 0 },
  560. { 0, 12, 111, 5, 0 },
  561. { 0, 32, 89, 7, 0 },
  562. { 0, 0, 64, 64, 0 },
  563. { 0, 7, 89, 32, 0 },
  564. { 0, 5, 111, 12, 0 },
  565. { 0, 2, 123, 3, 0 },
  566. };
  567. static const struct dispc_v_coef coef_vup_5tap[8] = {
  568. { 0, 0, 128, 0, 0 },
  569. { -1, 13, 124, -8, 0 },
  570. { -2, 30, 112, -11, -1 },
  571. { -5, 51, 95, -11, -2 },
  572. { 0, -9, 73, 73, -9 },
  573. { -2, -11, 95, 51, -5 },
  574. { -1, -11, 112, 30, -2 },
  575. { 0, -8, 124, 13, -1 },
  576. };
  577. /* Coefficients for horizontal down-sampling */
  578. static const struct dispc_h_coef coef_hdown[8] = {
  579. { 0, 36, 56, 36, 0 },
  580. { 4, 40, 55, 31, -2 },
  581. { 8, 44, 54, 27, -5 },
  582. { 12, 48, 53, 22, -7 },
  583. { -9, 17, 52, 51, 17 },
  584. { -7, 22, 53, 48, 12 },
  585. { -5, 27, 54, 44, 8 },
  586. { -2, 31, 55, 40, 4 },
  587. };
  588. /* Coefficients for vertical down-sampling */
  589. static const struct dispc_v_coef coef_vdown_3tap[8] = {
  590. { 0, 36, 56, 36, 0 },
  591. { 0, 40, 57, 31, 0 },
  592. { 0, 45, 56, 27, 0 },
  593. { 0, 50, 55, 23, 0 },
  594. { 0, 18, 55, 55, 0 },
  595. { 0, 23, 55, 50, 0 },
  596. { 0, 27, 56, 45, 0 },
  597. { 0, 31, 57, 40, 0 },
  598. };
  599. static const struct dispc_v_coef coef_vdown_5tap[8] = {
  600. { 0, 36, 56, 36, 0 },
  601. { 4, 40, 55, 31, -2 },
  602. { 8, 44, 54, 27, -5 },
  603. { 12, 48, 53, 22, -7 },
  604. { -9, 17, 52, 51, 17 },
  605. { -7, 22, 53, 48, 12 },
  606. { -5, 27, 54, 44, 8 },
  607. { -2, 31, 55, 40, 4 },
  608. };
  609. const struct dispc_h_coef *h_coef;
  610. const struct dispc_v_coef *v_coef;
  611. int i;
  612. if (hscaleup)
  613. h_coef = coef_hup;
  614. else
  615. h_coef = coef_hdown;
  616. if (vscaleup)
  617. v_coef = five_taps ? coef_vup_5tap : coef_vup_3tap;
  618. else
  619. v_coef = five_taps ? coef_vdown_5tap : coef_vdown_3tap;
  620. for (i = 0; i < 8; i++) {
  621. u32 h, hv;
  622. h = FLD_VAL(h_coef[i].hc0, 7, 0)
  623. | FLD_VAL(h_coef[i].hc1, 15, 8)
  624. | FLD_VAL(h_coef[i].hc2, 23, 16)
  625. | FLD_VAL(h_coef[i].hc3, 31, 24);
  626. hv = FLD_VAL(h_coef[i].hc4, 7, 0)
  627. | FLD_VAL(v_coef[i].vc0, 15, 8)
  628. | FLD_VAL(v_coef[i].vc1, 23, 16)
  629. | FLD_VAL(v_coef[i].vc2, 31, 24);
  630. if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y) {
  631. _dispc_write_firh_reg(plane, i, h);
  632. _dispc_write_firhv_reg(plane, i, hv);
  633. } else {
  634. _dispc_write_firh2_reg(plane, i, h);
  635. _dispc_write_firhv2_reg(plane, i, hv);
  636. }
  637. }
  638. if (five_taps) {
  639. for (i = 0; i < 8; i++) {
  640. u32 v;
  641. v = FLD_VAL(v_coef[i].vc00, 7, 0)
  642. | FLD_VAL(v_coef[i].vc22, 15, 8);
  643. if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y)
  644. _dispc_write_firv_reg(plane, i, v);
  645. else
  646. _dispc_write_firv2_reg(plane, i, v);
  647. }
  648. }
  649. }
  650. static void _dispc_setup_color_conv_coef(void)
  651. {
  652. const struct color_conv_coef {
  653. int ry, rcr, rcb, gy, gcr, gcb, by, bcr, bcb;
  654. int full_range;
  655. } ctbl_bt601_5 = {
  656. 298, 409, 0, 298, -208, -100, 298, 0, 517, 0,
  657. };
  658. const struct color_conv_coef *ct;
  659. #define CVAL(x, y) (FLD_VAL(x, 26, 16) | FLD_VAL(y, 10, 0))
  660. ct = &ctbl_bt601_5;
  661. dispc_write_reg(DISPC_OVL_CONV_COEF(OMAP_DSS_VIDEO1, 0),
  662. CVAL(ct->rcr, ct->ry));
  663. dispc_write_reg(DISPC_OVL_CONV_COEF(OMAP_DSS_VIDEO1, 1),
  664. CVAL(ct->gy, ct->rcb));
  665. dispc_write_reg(DISPC_OVL_CONV_COEF(OMAP_DSS_VIDEO1, 2),
  666. CVAL(ct->gcb, ct->gcr));
  667. dispc_write_reg(DISPC_OVL_CONV_COEF(OMAP_DSS_VIDEO1, 3),
  668. CVAL(ct->bcr, ct->by));
  669. dispc_write_reg(DISPC_OVL_CONV_COEF(OMAP_DSS_VIDEO1, 4),
  670. CVAL(0, ct->bcb));
  671. dispc_write_reg(DISPC_OVL_CONV_COEF(OMAP_DSS_VIDEO2, 0),
  672. CVAL(ct->rcr, ct->ry));
  673. dispc_write_reg(DISPC_OVL_CONV_COEF(OMAP_DSS_VIDEO2, 1),
  674. CVAL(ct->gy, ct->rcb));
  675. dispc_write_reg(DISPC_OVL_CONV_COEF(OMAP_DSS_VIDEO2, 2),
  676. CVAL(ct->gcb, ct->gcr));
  677. dispc_write_reg(DISPC_OVL_CONV_COEF(OMAP_DSS_VIDEO2, 3),
  678. CVAL(ct->bcr, ct->by));
  679. dispc_write_reg(DISPC_OVL_CONV_COEF(OMAP_DSS_VIDEO2, 4),
  680. CVAL(0, ct->bcb));
  681. #undef CVAL
  682. REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(OMAP_DSS_VIDEO1),
  683. ct->full_range, 11, 11);
  684. REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(OMAP_DSS_VIDEO2),
  685. ct->full_range, 11, 11);
  686. }
  687. static void _dispc_set_plane_ba0(enum omap_plane plane, u32 paddr)
  688. {
  689. dispc_write_reg(DISPC_OVL_BA0(plane), paddr);
  690. }
  691. static void _dispc_set_plane_ba1(enum omap_plane plane, u32 paddr)
  692. {
  693. dispc_write_reg(DISPC_OVL_BA1(plane), paddr);
  694. }
  695. static void _dispc_set_plane_ba0_uv(enum omap_plane plane, u32 paddr)
  696. {
  697. dispc_write_reg(DISPC_OVL_BA0_UV(plane), paddr);
  698. }
  699. static void _dispc_set_plane_ba1_uv(enum omap_plane plane, u32 paddr)
  700. {
  701. dispc_write_reg(DISPC_OVL_BA1_UV(plane), paddr);
  702. }
  703. static void _dispc_set_plane_pos(enum omap_plane plane, int x, int y)
  704. {
  705. u32 val = FLD_VAL(y, 26, 16) | FLD_VAL(x, 10, 0);
  706. dispc_write_reg(DISPC_OVL_POSITION(plane), val);
  707. }
  708. static void _dispc_set_pic_size(enum omap_plane plane, int width, int height)
  709. {
  710. u32 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
  711. if (plane == OMAP_DSS_GFX)
  712. dispc_write_reg(DISPC_OVL_SIZE(plane), val);
  713. else
  714. dispc_write_reg(DISPC_OVL_PICTURE_SIZE(plane), val);
  715. }
  716. static void _dispc_set_vid_size(enum omap_plane plane, int width, int height)
  717. {
  718. u32 val;
  719. BUG_ON(plane == OMAP_DSS_GFX);
  720. val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
  721. dispc_write_reg(DISPC_OVL_SIZE(plane), val);
  722. }
  723. static void _dispc_set_pre_mult_alpha(enum omap_plane plane, bool enable)
  724. {
  725. if (!dss_has_feature(FEAT_PRE_MULT_ALPHA))
  726. return;
  727. if (!dss_has_feature(FEAT_GLOBAL_ALPHA_VID1) &&
  728. plane == OMAP_DSS_VIDEO1)
  729. return;
  730. REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable ? 1 : 0, 28, 28);
  731. }
  732. static void _dispc_setup_global_alpha(enum omap_plane plane, u8 global_alpha)
  733. {
  734. if (!dss_has_feature(FEAT_GLOBAL_ALPHA))
  735. return;
  736. if (!dss_has_feature(FEAT_GLOBAL_ALPHA_VID1) &&
  737. plane == OMAP_DSS_VIDEO1)
  738. return;
  739. if (plane == OMAP_DSS_GFX)
  740. REG_FLD_MOD(DISPC_GLOBAL_ALPHA, global_alpha, 7, 0);
  741. else if (plane == OMAP_DSS_VIDEO2)
  742. REG_FLD_MOD(DISPC_GLOBAL_ALPHA, global_alpha, 23, 16);
  743. }
  744. static void _dispc_set_pix_inc(enum omap_plane plane, s32 inc)
  745. {
  746. dispc_write_reg(DISPC_OVL_PIXEL_INC(plane), inc);
  747. }
  748. static void _dispc_set_row_inc(enum omap_plane plane, s32 inc)
  749. {
  750. dispc_write_reg(DISPC_OVL_ROW_INC(plane), inc);
  751. }
  752. static void _dispc_set_color_mode(enum omap_plane plane,
  753. enum omap_color_mode color_mode)
  754. {
  755. u32 m = 0;
  756. if (plane != OMAP_DSS_GFX) {
  757. switch (color_mode) {
  758. case OMAP_DSS_COLOR_NV12:
  759. m = 0x0; break;
  760. case OMAP_DSS_COLOR_RGB12U:
  761. m = 0x1; break;
  762. case OMAP_DSS_COLOR_RGBA16:
  763. m = 0x2; break;
  764. case OMAP_DSS_COLOR_RGBX16:
  765. m = 0x4; break;
  766. case OMAP_DSS_COLOR_ARGB16:
  767. m = 0x5; break;
  768. case OMAP_DSS_COLOR_RGB16:
  769. m = 0x6; break;
  770. case OMAP_DSS_COLOR_ARGB16_1555:
  771. m = 0x7; break;
  772. case OMAP_DSS_COLOR_RGB24U:
  773. m = 0x8; break;
  774. case OMAP_DSS_COLOR_RGB24P:
  775. m = 0x9; break;
  776. case OMAP_DSS_COLOR_YUV2:
  777. m = 0xa; break;
  778. case OMAP_DSS_COLOR_UYVY:
  779. m = 0xb; break;
  780. case OMAP_DSS_COLOR_ARGB32:
  781. m = 0xc; break;
  782. case OMAP_DSS_COLOR_RGBA32:
  783. m = 0xd; break;
  784. case OMAP_DSS_COLOR_RGBX32:
  785. m = 0xe; break;
  786. case OMAP_DSS_COLOR_XRGB16_1555:
  787. m = 0xf; break;
  788. default:
  789. BUG(); break;
  790. }
  791. } else {
  792. switch (color_mode) {
  793. case OMAP_DSS_COLOR_CLUT1:
  794. m = 0x0; break;
  795. case OMAP_DSS_COLOR_CLUT2:
  796. m = 0x1; break;
  797. case OMAP_DSS_COLOR_CLUT4:
  798. m = 0x2; break;
  799. case OMAP_DSS_COLOR_CLUT8:
  800. m = 0x3; break;
  801. case OMAP_DSS_COLOR_RGB12U:
  802. m = 0x4; break;
  803. case OMAP_DSS_COLOR_ARGB16:
  804. m = 0x5; break;
  805. case OMAP_DSS_COLOR_RGB16:
  806. m = 0x6; break;
  807. case OMAP_DSS_COLOR_ARGB16_1555:
  808. m = 0x7; break;
  809. case OMAP_DSS_COLOR_RGB24U:
  810. m = 0x8; break;
  811. case OMAP_DSS_COLOR_RGB24P:
  812. m = 0x9; break;
  813. case OMAP_DSS_COLOR_YUV2:
  814. m = 0xa; break;
  815. case OMAP_DSS_COLOR_UYVY:
  816. m = 0xb; break;
  817. case OMAP_DSS_COLOR_ARGB32:
  818. m = 0xc; break;
  819. case OMAP_DSS_COLOR_RGBA32:
  820. m = 0xd; break;
  821. case OMAP_DSS_COLOR_RGBX32:
  822. m = 0xe; break;
  823. case OMAP_DSS_COLOR_XRGB16_1555:
  824. m = 0xf; break;
  825. default:
  826. BUG(); break;
  827. }
  828. }
  829. REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), m, 4, 1);
  830. }
  831. void dispc_set_channel_out(enum omap_plane plane,
  832. enum omap_channel channel)
  833. {
  834. int shift;
  835. u32 val;
  836. int chan = 0, chan2 = 0;
  837. switch (plane) {
  838. case OMAP_DSS_GFX:
  839. shift = 8;
  840. break;
  841. case OMAP_DSS_VIDEO1:
  842. case OMAP_DSS_VIDEO2:
  843. shift = 16;
  844. break;
  845. default:
  846. BUG();
  847. return;
  848. }
  849. val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
  850. if (dss_has_feature(FEAT_MGR_LCD2)) {
  851. switch (channel) {
  852. case OMAP_DSS_CHANNEL_LCD:
  853. chan = 0;
  854. chan2 = 0;
  855. break;
  856. case OMAP_DSS_CHANNEL_DIGIT:
  857. chan = 1;
  858. chan2 = 0;
  859. break;
  860. case OMAP_DSS_CHANNEL_LCD2:
  861. chan = 0;
  862. chan2 = 1;
  863. break;
  864. default:
  865. BUG();
  866. }
  867. val = FLD_MOD(val, chan, shift, shift);
  868. val = FLD_MOD(val, chan2, 31, 30);
  869. } else {
  870. val = FLD_MOD(val, channel, shift, shift);
  871. }
  872. dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), val);
  873. }
  874. static void dispc_set_burst_size(enum omap_plane plane,
  875. enum omap_burst_size burst_size)
  876. {
  877. int shift;
  878. switch (plane) {
  879. case OMAP_DSS_GFX:
  880. shift = 6;
  881. break;
  882. case OMAP_DSS_VIDEO1:
  883. case OMAP_DSS_VIDEO2:
  884. shift = 14;
  885. break;
  886. default:
  887. BUG();
  888. return;
  889. }
  890. REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), burst_size, shift + 1, shift);
  891. }
  892. static void dispc_configure_burst_sizes(void)
  893. {
  894. int i;
  895. const int burst_size = BURST_SIZE_X8;
  896. /* Configure burst size always to maximum size */
  897. for (i = 0; i < omap_dss_get_num_overlays(); ++i)
  898. dispc_set_burst_size(i, burst_size);
  899. }
  900. u32 dispc_get_burst_size(enum omap_plane plane)
  901. {
  902. unsigned unit = dss_feat_get_burst_size_unit();
  903. /* burst multiplier is always x8 (see dispc_configure_burst_sizes()) */
  904. return unit * 8;
  905. }
  906. void dispc_enable_gamma_table(bool enable)
  907. {
  908. /*
  909. * This is partially implemented to support only disabling of
  910. * the gamma table.
  911. */
  912. if (enable) {
  913. DSSWARN("Gamma table enabling for TV not yet supported");
  914. return;
  915. }
  916. REG_FLD_MOD(DISPC_CONFIG, enable, 9, 9);
  917. }
  918. void dispc_enable_cpr(enum omap_channel channel, bool enable)
  919. {
  920. u16 reg;
  921. if (channel == OMAP_DSS_CHANNEL_LCD)
  922. reg = DISPC_CONFIG;
  923. else if (channel == OMAP_DSS_CHANNEL_LCD2)
  924. reg = DISPC_CONFIG2;
  925. else
  926. return;
  927. REG_FLD_MOD(reg, enable, 15, 15);
  928. }
  929. void dispc_set_cpr_coef(enum omap_channel channel,
  930. struct omap_dss_cpr_coefs *coefs)
  931. {
  932. u32 coef_r, coef_g, coef_b;
  933. if (channel != OMAP_DSS_CHANNEL_LCD && channel != OMAP_DSS_CHANNEL_LCD2)
  934. return;
  935. coef_r = FLD_VAL(coefs->rr, 31, 22) | FLD_VAL(coefs->rg, 20, 11) |
  936. FLD_VAL(coefs->rb, 9, 0);
  937. coef_g = FLD_VAL(coefs->gr, 31, 22) | FLD_VAL(coefs->gg, 20, 11) |
  938. FLD_VAL(coefs->gb, 9, 0);
  939. coef_b = FLD_VAL(coefs->br, 31, 22) | FLD_VAL(coefs->bg, 20, 11) |
  940. FLD_VAL(coefs->bb, 9, 0);
  941. dispc_write_reg(DISPC_CPR_COEF_R(channel), coef_r);
  942. dispc_write_reg(DISPC_CPR_COEF_G(channel), coef_g);
  943. dispc_write_reg(DISPC_CPR_COEF_B(channel), coef_b);
  944. }
  945. static void _dispc_set_vid_color_conv(enum omap_plane plane, bool enable)
  946. {
  947. u32 val;
  948. BUG_ON(plane == OMAP_DSS_GFX);
  949. val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
  950. val = FLD_MOD(val, enable, 9, 9);
  951. dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), val);
  952. }
  953. void dispc_enable_replication(enum omap_plane plane, bool enable)
  954. {
  955. int bit;
  956. if (plane == OMAP_DSS_GFX)
  957. bit = 5;
  958. else
  959. bit = 10;
  960. REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable, bit, bit);
  961. }
  962. void dispc_set_lcd_size(enum omap_channel channel, u16 width, u16 height)
  963. {
  964. u32 val;
  965. BUG_ON((width > (1 << 11)) || (height > (1 << 11)));
  966. val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
  967. dispc_write_reg(DISPC_SIZE_MGR(channel), val);
  968. }
  969. void dispc_set_digit_size(u16 width, u16 height)
  970. {
  971. u32 val;
  972. BUG_ON((width > (1 << 11)) || (height > (1 << 11)));
  973. val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
  974. dispc_write_reg(DISPC_SIZE_MGR(OMAP_DSS_CHANNEL_DIGIT), val);
  975. }
  976. static void dispc_read_plane_fifo_sizes(void)
  977. {
  978. u32 size;
  979. int plane;
  980. u8 start, end;
  981. u32 unit;
  982. unit = dss_feat_get_buffer_size_unit();
  983. dss_feat_get_reg_field(FEAT_REG_FIFOSIZE, &start, &end);
  984. for (plane = 0; plane < ARRAY_SIZE(dispc.fifo_size); ++plane) {
  985. size = REG_GET(DISPC_OVL_FIFO_SIZE_STATUS(plane), start, end);
  986. size *= unit;
  987. dispc.fifo_size[plane] = size;
  988. }
  989. }
  990. u32 dispc_get_plane_fifo_size(enum omap_plane plane)
  991. {
  992. return dispc.fifo_size[plane];
  993. }
  994. void dispc_set_fifo_threshold(enum omap_plane plane, u32 low, u32 high)
  995. {
  996. u8 hi_start, hi_end, lo_start, lo_end;
  997. u32 unit;
  998. unit = dss_feat_get_buffer_size_unit();
  999. WARN_ON(low % unit != 0);
  1000. WARN_ON(high % unit != 0);
  1001. low /= unit;
  1002. high /= unit;
  1003. dss_feat_get_reg_field(FEAT_REG_FIFOHIGHTHRESHOLD, &hi_start, &hi_end);
  1004. dss_feat_get_reg_field(FEAT_REG_FIFOLOWTHRESHOLD, &lo_start, &lo_end);
  1005. DSSDBG("fifo(%d) low/high old %u/%u, new %u/%u\n",
  1006. plane,
  1007. REG_GET(DISPC_OVL_FIFO_THRESHOLD(plane),
  1008. lo_start, lo_end),
  1009. REG_GET(DISPC_OVL_FIFO_THRESHOLD(plane),
  1010. hi_start, hi_end),
  1011. low, high);
  1012. dispc_write_reg(DISPC_OVL_FIFO_THRESHOLD(plane),
  1013. FLD_VAL(high, hi_start, hi_end) |
  1014. FLD_VAL(low, lo_start, lo_end));
  1015. }
  1016. void dispc_enable_fifomerge(bool enable)
  1017. {
  1018. DSSDBG("FIFO merge %s\n", enable ? "enabled" : "disabled");
  1019. REG_FLD_MOD(DISPC_CONFIG, enable ? 1 : 0, 14, 14);
  1020. }
  1021. static void _dispc_set_fir(enum omap_plane plane,
  1022. int hinc, int vinc,
  1023. enum omap_color_component color_comp)
  1024. {
  1025. u32 val;
  1026. if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y) {
  1027. u8 hinc_start, hinc_end, vinc_start, vinc_end;
  1028. dss_feat_get_reg_field(FEAT_REG_FIRHINC,
  1029. &hinc_start, &hinc_end);
  1030. dss_feat_get_reg_field(FEAT_REG_FIRVINC,
  1031. &vinc_start, &vinc_end);
  1032. val = FLD_VAL(vinc, vinc_start, vinc_end) |
  1033. FLD_VAL(hinc, hinc_start, hinc_end);
  1034. dispc_write_reg(DISPC_OVL_FIR(plane), val);
  1035. } else {
  1036. val = FLD_VAL(vinc, 28, 16) | FLD_VAL(hinc, 12, 0);
  1037. dispc_write_reg(DISPC_OVL_FIR2(plane), val);
  1038. }
  1039. }
  1040. static void _dispc_set_vid_accu0(enum omap_plane plane, int haccu, int vaccu)
  1041. {
  1042. u32 val;
  1043. u8 hor_start, hor_end, vert_start, vert_end;
  1044. dss_feat_get_reg_field(FEAT_REG_HORIZONTALACCU, &hor_start, &hor_end);
  1045. dss_feat_get_reg_field(FEAT_REG_VERTICALACCU, &vert_start, &vert_end);
  1046. val = FLD_VAL(vaccu, vert_start, vert_end) |
  1047. FLD_VAL(haccu, hor_start, hor_end);
  1048. dispc_write_reg(DISPC_OVL_ACCU0(plane), val);
  1049. }
  1050. static void _dispc_set_vid_accu1(enum omap_plane plane, int haccu, int vaccu)
  1051. {
  1052. u32 val;
  1053. u8 hor_start, hor_end, vert_start, vert_end;
  1054. dss_feat_get_reg_field(FEAT_REG_HORIZONTALACCU, &hor_start, &hor_end);
  1055. dss_feat_get_reg_field(FEAT_REG_VERTICALACCU, &vert_start, &vert_end);
  1056. val = FLD_VAL(vaccu, vert_start, vert_end) |
  1057. FLD_VAL(haccu, hor_start, hor_end);
  1058. dispc_write_reg(DISPC_OVL_ACCU1(plane), val);
  1059. }
  1060. static void _dispc_set_vid_accu2_0(enum omap_plane plane, int haccu, int vaccu)
  1061. {
  1062. u32 val;
  1063. val = FLD_VAL(vaccu, 26, 16) | FLD_VAL(haccu, 10, 0);
  1064. dispc_write_reg(DISPC_OVL_ACCU2_0(plane), val);
  1065. }
  1066. static void _dispc_set_vid_accu2_1(enum omap_plane plane, int haccu, int vaccu)
  1067. {
  1068. u32 val;
  1069. val = FLD_VAL(vaccu, 26, 16) | FLD_VAL(haccu, 10, 0);
  1070. dispc_write_reg(DISPC_OVL_ACCU2_1(plane), val);
  1071. }
  1072. static void _dispc_set_scale_param(enum omap_plane plane,
  1073. u16 orig_width, u16 orig_height,
  1074. u16 out_width, u16 out_height,
  1075. bool five_taps, u8 rotation,
  1076. enum omap_color_component color_comp)
  1077. {
  1078. int fir_hinc, fir_vinc;
  1079. int hscaleup, vscaleup;
  1080. hscaleup = orig_width <= out_width;
  1081. vscaleup = orig_height <= out_height;
  1082. _dispc_set_scale_coef(plane, hscaleup, vscaleup, five_taps, color_comp);
  1083. fir_hinc = 1024 * orig_width / out_width;
  1084. fir_vinc = 1024 * orig_height / out_height;
  1085. _dispc_set_fir(plane, fir_hinc, fir_vinc, color_comp);
  1086. }
  1087. static void _dispc_set_scaling_common(enum omap_plane plane,
  1088. u16 orig_width, u16 orig_height,
  1089. u16 out_width, u16 out_height,
  1090. bool ilace, bool five_taps,
  1091. bool fieldmode, enum omap_color_mode color_mode,
  1092. u8 rotation)
  1093. {
  1094. int accu0 = 0;
  1095. int accu1 = 0;
  1096. u32 l;
  1097. _dispc_set_scale_param(plane, orig_width, orig_height,
  1098. out_width, out_height, five_taps,
  1099. rotation, DISPC_COLOR_COMPONENT_RGB_Y);
  1100. l = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
  1101. /* RESIZEENABLE and VERTICALTAPS */
  1102. l &= ~((0x3 << 5) | (0x1 << 21));
  1103. l |= (orig_width != out_width) ? (1 << 5) : 0;
  1104. l |= (orig_height != out_height) ? (1 << 6) : 0;
  1105. l |= five_taps ? (1 << 21) : 0;
  1106. /* VRESIZECONF and HRESIZECONF */
  1107. if (dss_has_feature(FEAT_RESIZECONF)) {
  1108. l &= ~(0x3 << 7);
  1109. l |= (orig_width <= out_width) ? 0 : (1 << 7);
  1110. l |= (orig_height <= out_height) ? 0 : (1 << 8);
  1111. }
  1112. /* LINEBUFFERSPLIT */
  1113. if (dss_has_feature(FEAT_LINEBUFFERSPLIT)) {
  1114. l &= ~(0x1 << 22);
  1115. l |= five_taps ? (1 << 22) : 0;
  1116. }
  1117. dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), l);
  1118. /*
  1119. * field 0 = even field = bottom field
  1120. * field 1 = odd field = top field
  1121. */
  1122. if (ilace && !fieldmode) {
  1123. accu1 = 0;
  1124. accu0 = ((1024 * orig_height / out_height) / 2) & 0x3ff;
  1125. if (accu0 >= 1024/2) {
  1126. accu1 = 1024/2;
  1127. accu0 -= accu1;
  1128. }
  1129. }
  1130. _dispc_set_vid_accu0(plane, 0, accu0);
  1131. _dispc_set_vid_accu1(plane, 0, accu1);
  1132. }
  1133. static void _dispc_set_scaling_uv(enum omap_plane plane,
  1134. u16 orig_width, u16 orig_height,
  1135. u16 out_width, u16 out_height,
  1136. bool ilace, bool five_taps,
  1137. bool fieldmode, enum omap_color_mode color_mode,
  1138. u8 rotation)
  1139. {
  1140. int scale_x = out_width != orig_width;
  1141. int scale_y = out_height != orig_height;
  1142. if (!dss_has_feature(FEAT_HANDLE_UV_SEPARATE))
  1143. return;
  1144. if ((color_mode != OMAP_DSS_COLOR_YUV2 &&
  1145. color_mode != OMAP_DSS_COLOR_UYVY &&
  1146. color_mode != OMAP_DSS_COLOR_NV12)) {
  1147. /* reset chroma resampling for RGB formats */
  1148. REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane), 0, 8, 8);
  1149. return;
  1150. }
  1151. switch (color_mode) {
  1152. case OMAP_DSS_COLOR_NV12:
  1153. /* UV is subsampled by 2 vertically*/
  1154. orig_height >>= 1;
  1155. /* UV is subsampled by 2 horz.*/
  1156. orig_width >>= 1;
  1157. break;
  1158. case OMAP_DSS_COLOR_YUV2:
  1159. case OMAP_DSS_COLOR_UYVY:
  1160. /*For YUV422 with 90/270 rotation,
  1161. *we don't upsample chroma
  1162. */
  1163. if (rotation == OMAP_DSS_ROT_0 ||
  1164. rotation == OMAP_DSS_ROT_180)
  1165. /* UV is subsampled by 2 hrz*/
  1166. orig_width >>= 1;
  1167. /* must use FIR for YUV422 if rotated */
  1168. if (rotation != OMAP_DSS_ROT_0)
  1169. scale_x = scale_y = true;
  1170. break;
  1171. default:
  1172. BUG();
  1173. }
  1174. if (out_width != orig_width)
  1175. scale_x = true;
  1176. if (out_height != orig_height)
  1177. scale_y = true;
  1178. _dispc_set_scale_param(plane, orig_width, orig_height,
  1179. out_width, out_height, five_taps,
  1180. rotation, DISPC_COLOR_COMPONENT_UV);
  1181. REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane),
  1182. (scale_x || scale_y) ? 1 : 0, 8, 8);
  1183. /* set H scaling */
  1184. REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), scale_x ? 1 : 0, 5, 5);
  1185. /* set V scaling */
  1186. REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), scale_y ? 1 : 0, 6, 6);
  1187. _dispc_set_vid_accu2_0(plane, 0x80, 0);
  1188. _dispc_set_vid_accu2_1(plane, 0x80, 0);
  1189. }
  1190. static void _dispc_set_scaling(enum omap_plane plane,
  1191. u16 orig_width, u16 orig_height,
  1192. u16 out_width, u16 out_height,
  1193. bool ilace, bool five_taps,
  1194. bool fieldmode, enum omap_color_mode color_mode,
  1195. u8 rotation)
  1196. {
  1197. BUG_ON(plane == OMAP_DSS_GFX);
  1198. _dispc_set_scaling_common(plane,
  1199. orig_width, orig_height,
  1200. out_width, out_height,
  1201. ilace, five_taps,
  1202. fieldmode, color_mode,
  1203. rotation);
  1204. _dispc_set_scaling_uv(plane,
  1205. orig_width, orig_height,
  1206. out_width, out_height,
  1207. ilace, five_taps,
  1208. fieldmode, color_mode,
  1209. rotation);
  1210. }
  1211. static void _dispc_set_rotation_attrs(enum omap_plane plane, u8 rotation,
  1212. bool mirroring, enum omap_color_mode color_mode)
  1213. {
  1214. bool row_repeat = false;
  1215. int vidrot = 0;
  1216. if (color_mode == OMAP_DSS_COLOR_YUV2 ||
  1217. color_mode == OMAP_DSS_COLOR_UYVY) {
  1218. if (mirroring) {
  1219. switch (rotation) {
  1220. case OMAP_DSS_ROT_0:
  1221. vidrot = 2;
  1222. break;
  1223. case OMAP_DSS_ROT_90:
  1224. vidrot = 1;
  1225. break;
  1226. case OMAP_DSS_ROT_180:
  1227. vidrot = 0;
  1228. break;
  1229. case OMAP_DSS_ROT_270:
  1230. vidrot = 3;
  1231. break;
  1232. }
  1233. } else {
  1234. switch (rotation) {
  1235. case OMAP_DSS_ROT_0:
  1236. vidrot = 0;
  1237. break;
  1238. case OMAP_DSS_ROT_90:
  1239. vidrot = 1;
  1240. break;
  1241. case OMAP_DSS_ROT_180:
  1242. vidrot = 2;
  1243. break;
  1244. case OMAP_DSS_ROT_270:
  1245. vidrot = 3;
  1246. break;
  1247. }
  1248. }
  1249. if (rotation == OMAP_DSS_ROT_90 || rotation == OMAP_DSS_ROT_270)
  1250. row_repeat = true;
  1251. else
  1252. row_repeat = false;
  1253. }
  1254. REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), vidrot, 13, 12);
  1255. if (dss_has_feature(FEAT_ROWREPEATENABLE))
  1256. REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane),
  1257. row_repeat ? 1 : 0, 18, 18);
  1258. }
  1259. static int color_mode_to_bpp(enum omap_color_mode color_mode)
  1260. {
  1261. switch (color_mode) {
  1262. case OMAP_DSS_COLOR_CLUT1:
  1263. return 1;
  1264. case OMAP_DSS_COLOR_CLUT2:
  1265. return 2;
  1266. case OMAP_DSS_COLOR_CLUT4:
  1267. return 4;
  1268. case OMAP_DSS_COLOR_CLUT8:
  1269. case OMAP_DSS_COLOR_NV12:
  1270. return 8;
  1271. case OMAP_DSS_COLOR_RGB12U:
  1272. case OMAP_DSS_COLOR_RGB16:
  1273. case OMAP_DSS_COLOR_ARGB16:
  1274. case OMAP_DSS_COLOR_YUV2:
  1275. case OMAP_DSS_COLOR_UYVY:
  1276. case OMAP_DSS_COLOR_RGBA16:
  1277. case OMAP_DSS_COLOR_RGBX16:
  1278. case OMAP_DSS_COLOR_ARGB16_1555:
  1279. case OMAP_DSS_COLOR_XRGB16_1555:
  1280. return 16;
  1281. case OMAP_DSS_COLOR_RGB24P:
  1282. return 24;
  1283. case OMAP_DSS_COLOR_RGB24U:
  1284. case OMAP_DSS_COLOR_ARGB32:
  1285. case OMAP_DSS_COLOR_RGBA32:
  1286. case OMAP_DSS_COLOR_RGBX32:
  1287. return 32;
  1288. default:
  1289. BUG();
  1290. }
  1291. }
  1292. static s32 pixinc(int pixels, u8 ps)
  1293. {
  1294. if (pixels == 1)
  1295. return 1;
  1296. else if (pixels > 1)
  1297. return 1 + (pixels - 1) * ps;
  1298. else if (pixels < 0)
  1299. return 1 - (-pixels + 1) * ps;
  1300. else
  1301. BUG();
  1302. }
  1303. static void calc_vrfb_rotation_offset(u8 rotation, bool mirror,
  1304. u16 screen_width,
  1305. u16 width, u16 height,
  1306. enum omap_color_mode color_mode, bool fieldmode,
  1307. unsigned int field_offset,
  1308. unsigned *offset0, unsigned *offset1,
  1309. s32 *row_inc, s32 *pix_inc)
  1310. {
  1311. u8 ps;
  1312. /* FIXME CLUT formats */
  1313. switch (color_mode) {
  1314. case OMAP_DSS_COLOR_CLUT1:
  1315. case OMAP_DSS_COLOR_CLUT2:
  1316. case OMAP_DSS_COLOR_CLUT4:
  1317. case OMAP_DSS_COLOR_CLUT8:
  1318. BUG();
  1319. return;
  1320. case OMAP_DSS_COLOR_YUV2:
  1321. case OMAP_DSS_COLOR_UYVY:
  1322. ps = 4;
  1323. break;
  1324. default:
  1325. ps = color_mode_to_bpp(color_mode) / 8;
  1326. break;
  1327. }
  1328. DSSDBG("calc_rot(%d): scrw %d, %dx%d\n", rotation, screen_width,
  1329. width, height);
  1330. /*
  1331. * field 0 = even field = bottom field
  1332. * field 1 = odd field = top field
  1333. */
  1334. switch (rotation + mirror * 4) {
  1335. case OMAP_DSS_ROT_0:
  1336. case OMAP_DSS_ROT_180:
  1337. /*
  1338. * If the pixel format is YUV or UYVY divide the width
  1339. * of the image by 2 for 0 and 180 degree rotation.
  1340. */
  1341. if (color_mode == OMAP_DSS_COLOR_YUV2 ||
  1342. color_mode == OMAP_DSS_COLOR_UYVY)
  1343. width = width >> 1;
  1344. case OMAP_DSS_ROT_90:
  1345. case OMAP_DSS_ROT_270:
  1346. *offset1 = 0;
  1347. if (field_offset)
  1348. *offset0 = field_offset * screen_width * ps;
  1349. else
  1350. *offset0 = 0;
  1351. *row_inc = pixinc(1 + (screen_width - width) +
  1352. (fieldmode ? screen_width : 0),
  1353. ps);
  1354. *pix_inc = pixinc(1, ps);
  1355. break;
  1356. case OMAP_DSS_ROT_0 + 4:
  1357. case OMAP_DSS_ROT_180 + 4:
  1358. /* If the pixel format is YUV or UYVY divide the width
  1359. * of the image by 2 for 0 degree and 180 degree
  1360. */
  1361. if (color_mode == OMAP_DSS_COLOR_YUV2 ||
  1362. color_mode == OMAP_DSS_COLOR_UYVY)
  1363. width = width >> 1;
  1364. case OMAP_DSS_ROT_90 + 4:
  1365. case OMAP_DSS_ROT_270 + 4:
  1366. *offset1 = 0;
  1367. if (field_offset)
  1368. *offset0 = field_offset * screen_width * ps;
  1369. else
  1370. *offset0 = 0;
  1371. *row_inc = pixinc(1 - (screen_width + width) -
  1372. (fieldmode ? screen_width : 0),
  1373. ps);
  1374. *pix_inc = pixinc(1, ps);
  1375. break;
  1376. default:
  1377. BUG();
  1378. }
  1379. }
  1380. static void calc_dma_rotation_offset(u8 rotation, bool mirror,
  1381. u16 screen_width,
  1382. u16 width, u16 height,
  1383. enum omap_color_mode color_mode, bool fieldmode,
  1384. unsigned int field_offset,
  1385. unsigned *offset0, unsigned *offset1,
  1386. s32 *row_inc, s32 *pix_inc)
  1387. {
  1388. u8 ps;
  1389. u16 fbw, fbh;
  1390. /* FIXME CLUT formats */
  1391. switch (color_mode) {
  1392. case OMAP_DSS_COLOR_CLUT1:
  1393. case OMAP_DSS_COLOR_CLUT2:
  1394. case OMAP_DSS_COLOR_CLUT4:
  1395. case OMAP_DSS_COLOR_CLUT8:
  1396. BUG();
  1397. return;
  1398. default:
  1399. ps = color_mode_to_bpp(color_mode) / 8;
  1400. break;
  1401. }
  1402. DSSDBG("calc_rot(%d): scrw %d, %dx%d\n", rotation, screen_width,
  1403. width, height);
  1404. /* width & height are overlay sizes, convert to fb sizes */
  1405. if (rotation == OMAP_DSS_ROT_0 || rotation == OMAP_DSS_ROT_180) {
  1406. fbw = width;
  1407. fbh = height;
  1408. } else {
  1409. fbw = height;
  1410. fbh = width;
  1411. }
  1412. /*
  1413. * field 0 = even field = bottom field
  1414. * field 1 = odd field = top field
  1415. */
  1416. switch (rotation + mirror * 4) {
  1417. case OMAP_DSS_ROT_0:
  1418. *offset1 = 0;
  1419. if (field_offset)
  1420. *offset0 = *offset1 + field_offset * screen_width * ps;
  1421. else
  1422. *offset0 = *offset1;
  1423. *row_inc = pixinc(1 + (screen_width - fbw) +
  1424. (fieldmode ? screen_width : 0),
  1425. ps);
  1426. *pix_inc = pixinc(1, ps);
  1427. break;
  1428. case OMAP_DSS_ROT_90:
  1429. *offset1 = screen_width * (fbh - 1) * ps;
  1430. if (field_offset)
  1431. *offset0 = *offset1 + field_offset * ps;
  1432. else
  1433. *offset0 = *offset1;
  1434. *row_inc = pixinc(screen_width * (fbh - 1) + 1 +
  1435. (fieldmode ? 1 : 0), ps);
  1436. *pix_inc = pixinc(-screen_width, ps);
  1437. break;
  1438. case OMAP_DSS_ROT_180:
  1439. *offset1 = (screen_width * (fbh - 1) + fbw - 1) * ps;
  1440. if (field_offset)
  1441. *offset0 = *offset1 - field_offset * screen_width * ps;
  1442. else
  1443. *offset0 = *offset1;
  1444. *row_inc = pixinc(-1 -
  1445. (screen_width - fbw) -
  1446. (fieldmode ? screen_width : 0),
  1447. ps);
  1448. *pix_inc = pixinc(-1, ps);
  1449. break;
  1450. case OMAP_DSS_ROT_270:
  1451. *offset1 = (fbw - 1) * ps;
  1452. if (field_offset)
  1453. *offset0 = *offset1 - field_offset * ps;
  1454. else
  1455. *offset0 = *offset1;
  1456. *row_inc = pixinc(-screen_width * (fbh - 1) - 1 -
  1457. (fieldmode ? 1 : 0), ps);
  1458. *pix_inc = pixinc(screen_width, ps);
  1459. break;
  1460. /* mirroring */
  1461. case OMAP_DSS_ROT_0 + 4:
  1462. *offset1 = (fbw - 1) * ps;
  1463. if (field_offset)
  1464. *offset0 = *offset1 + field_offset * screen_width * ps;
  1465. else
  1466. *offset0 = *offset1;
  1467. *row_inc = pixinc(screen_width * 2 - 1 +
  1468. (fieldmode ? screen_width : 0),
  1469. ps);
  1470. *pix_inc = pixinc(-1, ps);
  1471. break;
  1472. case OMAP_DSS_ROT_90 + 4:
  1473. *offset1 = 0;
  1474. if (field_offset)
  1475. *offset0 = *offset1 + field_offset * ps;
  1476. else
  1477. *offset0 = *offset1;
  1478. *row_inc = pixinc(-screen_width * (fbh - 1) + 1 +
  1479. (fieldmode ? 1 : 0),
  1480. ps);
  1481. *pix_inc = pixinc(screen_width, ps);
  1482. break;
  1483. case OMAP_DSS_ROT_180 + 4:
  1484. *offset1 = screen_width * (fbh - 1) * ps;
  1485. if (field_offset)
  1486. *offset0 = *offset1 - field_offset * screen_width * ps;
  1487. else
  1488. *offset0 = *offset1;
  1489. *row_inc = pixinc(1 - screen_width * 2 -
  1490. (fieldmode ? screen_width : 0),
  1491. ps);
  1492. *pix_inc = pixinc(1, ps);
  1493. break;
  1494. case OMAP_DSS_ROT_270 + 4:
  1495. *offset1 = (screen_width * (fbh - 1) + fbw - 1) * ps;
  1496. if (field_offset)
  1497. *offset0 = *offset1 - field_offset * ps;
  1498. else
  1499. *offset0 = *offset1;
  1500. *row_inc = pixinc(screen_width * (fbh - 1) - 1 -
  1501. (fieldmode ? 1 : 0),
  1502. ps);
  1503. *pix_inc = pixinc(-screen_width, ps);
  1504. break;
  1505. default:
  1506. BUG();
  1507. }
  1508. }
  1509. static unsigned long calc_fclk_five_taps(enum omap_channel channel, u16 width,
  1510. u16 height, u16 out_width, u16 out_height,
  1511. enum omap_color_mode color_mode)
  1512. {
  1513. u32 fclk = 0;
  1514. /* FIXME venc pclk? */
  1515. u64 tmp, pclk = dispc_pclk_rate(channel);
  1516. if (height > out_height) {
  1517. /* FIXME get real display PPL */
  1518. unsigned int ppl = 800;
  1519. tmp = pclk * height * out_width;
  1520. do_div(tmp, 2 * out_height * ppl);
  1521. fclk = tmp;
  1522. if (height > 2 * out_height) {
  1523. if (ppl == out_width)
  1524. return 0;
  1525. tmp = pclk * (height - 2 * out_height) * out_width;
  1526. do_div(tmp, 2 * out_height * (ppl - out_width));
  1527. fclk = max(fclk, (u32) tmp);
  1528. }
  1529. }
  1530. if (width > out_width) {
  1531. tmp = pclk * width;
  1532. do_div(tmp, out_width);
  1533. fclk = max(fclk, (u32) tmp);
  1534. if (color_mode == OMAP_DSS_COLOR_RGB24U)
  1535. fclk <<= 1;
  1536. }
  1537. return fclk;
  1538. }
  1539. static unsigned long calc_fclk(enum omap_channel channel, u16 width,
  1540. u16 height, u16 out_width, u16 out_height)
  1541. {
  1542. unsigned int hf, vf;
  1543. /*
  1544. * FIXME how to determine the 'A' factor
  1545. * for the no downscaling case ?
  1546. */
  1547. if (width > 3 * out_width)
  1548. hf = 4;
  1549. else if (width > 2 * out_width)
  1550. hf = 3;
  1551. else if (width > out_width)
  1552. hf = 2;
  1553. else
  1554. hf = 1;
  1555. if (height > out_height)
  1556. vf = 2;
  1557. else
  1558. vf = 1;
  1559. /* FIXME venc pclk? */
  1560. return dispc_pclk_rate(channel) * vf * hf;
  1561. }
  1562. int dispc_setup_plane(enum omap_plane plane,
  1563. u32 paddr, u16 screen_width,
  1564. u16 pos_x, u16 pos_y,
  1565. u16 width, u16 height,
  1566. u16 out_width, u16 out_height,
  1567. enum omap_color_mode color_mode,
  1568. bool ilace,
  1569. enum omap_dss_rotation_type rotation_type,
  1570. u8 rotation, bool mirror,
  1571. u8 global_alpha, u8 pre_mult_alpha,
  1572. enum omap_channel channel, u32 puv_addr)
  1573. {
  1574. const int maxdownscale = cpu_is_omap34xx() ? 4 : 2;
  1575. bool five_taps = 0;
  1576. bool fieldmode = 0;
  1577. int cconv = 0;
  1578. unsigned offset0, offset1;
  1579. s32 row_inc;
  1580. s32 pix_inc;
  1581. u16 frame_height = height;
  1582. unsigned int field_offset = 0;
  1583. DSSDBG("dispc_setup_plane %d, pa %x, sw %d, %d,%d, %dx%d -> "
  1584. "%dx%d, ilace %d, cmode %x, rot %d, mir %d chan %d\n",
  1585. plane, paddr, screen_width, pos_x, pos_y,
  1586. width, height,
  1587. out_width, out_height,
  1588. ilace, color_mode,
  1589. rotation, mirror, channel);
  1590. if (paddr == 0)
  1591. return -EINVAL;
  1592. if (ilace && height == out_height)
  1593. fieldmode = 1;
  1594. if (ilace) {
  1595. if (fieldmode)
  1596. height /= 2;
  1597. pos_y /= 2;
  1598. out_height /= 2;
  1599. DSSDBG("adjusting for ilace: height %d, pos_y %d, "
  1600. "out_height %d\n",
  1601. height, pos_y, out_height);
  1602. }
  1603. if (!dss_feat_color_mode_supported(plane, color_mode))
  1604. return -EINVAL;
  1605. if (plane == OMAP_DSS_GFX) {
  1606. if (width != out_width || height != out_height)
  1607. return -EINVAL;
  1608. } else {
  1609. /* video plane */
  1610. unsigned long fclk = 0;
  1611. if (out_width < width / maxdownscale ||
  1612. out_width > width * 8)
  1613. return -EINVAL;
  1614. if (out_height < height / maxdownscale ||
  1615. out_height > height * 8)
  1616. return -EINVAL;
  1617. if (color_mode == OMAP_DSS_COLOR_YUV2 ||
  1618. color_mode == OMAP_DSS_COLOR_UYVY ||
  1619. color_mode == OMAP_DSS_COLOR_NV12)
  1620. cconv = 1;
  1621. /* Must use 5-tap filter? */
  1622. five_taps = height > out_height * 2;
  1623. if (!five_taps) {
  1624. fclk = calc_fclk(channel, width, height, out_width,
  1625. out_height);
  1626. /* Try 5-tap filter if 3-tap fclk is too high */
  1627. if (cpu_is_omap34xx() && height > out_height &&
  1628. fclk > dispc_fclk_rate())
  1629. five_taps = true;
  1630. }
  1631. if (width > (2048 >> five_taps)) {
  1632. DSSERR("failed to set up scaling, fclk too low\n");
  1633. return -EINVAL;
  1634. }
  1635. if (five_taps)
  1636. fclk = calc_fclk_five_taps(channel, width, height,
  1637. out_width, out_height, color_mode);
  1638. DSSDBG("required fclk rate = %lu Hz\n", fclk);
  1639. DSSDBG("current fclk rate = %lu Hz\n", dispc_fclk_rate());
  1640. if (!fclk || fclk > dispc_fclk_rate()) {
  1641. DSSERR("failed to set up scaling, "
  1642. "required fclk rate = %lu Hz, "
  1643. "current fclk rate = %lu Hz\n",
  1644. fclk, dispc_fclk_rate());
  1645. return -EINVAL;
  1646. }
  1647. }
  1648. if (ilace && !fieldmode) {
  1649. /*
  1650. * when downscaling the bottom field may have to start several
  1651. * source lines below the top field. Unfortunately ACCUI
  1652. * registers will only hold the fractional part of the offset
  1653. * so the integer part must be added to the base address of the
  1654. * bottom field.
  1655. */
  1656. if (!height || height == out_height)
  1657. field_offset = 0;
  1658. else
  1659. field_offset = height / out_height / 2;
  1660. }
  1661. /* Fields are independent but interleaved in memory. */
  1662. if (fieldmode)
  1663. field_offset = 1;
  1664. if (rotation_type == OMAP_DSS_ROT_DMA)
  1665. calc_dma_rotation_offset(rotation, mirror,
  1666. screen_width, width, frame_height, color_mode,
  1667. fieldmode, field_offset,
  1668. &offset0, &offset1, &row_inc, &pix_inc);
  1669. else
  1670. calc_vrfb_rotation_offset(rotation, mirror,
  1671. screen_width, width, frame_height, color_mode,
  1672. fieldmode, field_offset,
  1673. &offset0, &offset1, &row_inc, &pix_inc);
  1674. DSSDBG("offset0 %u, offset1 %u, row_inc %d, pix_inc %d\n",
  1675. offset0, offset1, row_inc, pix_inc);
  1676. _dispc_set_color_mode(plane, color_mode);
  1677. _dispc_set_plane_ba0(plane, paddr + offset0);
  1678. _dispc_set_plane_ba1(plane, paddr + offset1);
  1679. if (OMAP_DSS_COLOR_NV12 == color_mode) {
  1680. _dispc_set_plane_ba0_uv(plane, puv_addr + offset0);
  1681. _dispc_set_plane_ba1_uv(plane, puv_addr + offset1);
  1682. }
  1683. _dispc_set_row_inc(plane, row_inc);
  1684. _dispc_set_pix_inc(plane, pix_inc);
  1685. DSSDBG("%d,%d %dx%d -> %dx%d\n", pos_x, pos_y, width, height,
  1686. out_width, out_height);
  1687. _dispc_set_plane_pos(plane, pos_x, pos_y);
  1688. _dispc_set_pic_size(plane, width, height);
  1689. if (plane != OMAP_DSS_GFX) {
  1690. _dispc_set_scaling(plane, width, height,
  1691. out_width, out_height,
  1692. ilace, five_taps, fieldmode,
  1693. color_mode, rotation);
  1694. _dispc_set_vid_size(plane, out_width, out_height);
  1695. _dispc_set_vid_color_conv(plane, cconv);
  1696. }
  1697. _dispc_set_rotation_attrs(plane, rotation, mirror, color_mode);
  1698. _dispc_set_pre_mult_alpha(plane, pre_mult_alpha);
  1699. _dispc_setup_global_alpha(plane, global_alpha);
  1700. return 0;
  1701. }
  1702. int dispc_enable_plane(enum omap_plane plane, bool enable)
  1703. {
  1704. DSSDBG("dispc_enable_plane %d, %d\n", plane, enable);
  1705. REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable ? 1 : 0, 0, 0);
  1706. return 0;
  1707. }
  1708. static void dispc_disable_isr(void *data, u32 mask)
  1709. {
  1710. struct completion *compl = data;
  1711. complete(compl);
  1712. }
  1713. static void _enable_lcd_out(enum omap_channel channel, bool enable)
  1714. {
  1715. if (channel == OMAP_DSS_CHANNEL_LCD2)
  1716. REG_FLD_MO