rfbi.c 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309
  1. /*
  2. * linux/drivers/video/omap2/dss/rfbi.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 "RFBI"
  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/delay.h>
  29. #include <linux/kfifo.h>
  30. #include <linux/ktime.h>
  31. #include <linux/hrtimer.h>
  32. #include <linux/seq_file.h>
  33. #include <plat/display.h>
  34. #include "dss.h"
  35. /*#define MEASURE_PERF*/
  36. #define RFBI_BASE 0x48050800
  37. struct rfbi_reg { u16 idx; };
  38. #define RFBI_REG(idx) ((const struct rfbi_reg) { idx })
  39. #define RFBI_REVISION RFBI_REG(0x0000)
  40. #define RFBI_SYSCONFIG RFBI_REG(0x0010)
  41. #define RFBI_SYSSTATUS RFBI_REG(0x0014)
  42. #define RFBI_CONTROL RFBI_REG(0x0040)
  43. #define RFBI_PIXEL_CNT RFBI_REG(0x0044)
  44. #define RFBI_LINE_NUMBER RFBI_REG(0x0048)
  45. #define RFBI_CMD RFBI_REG(0x004c)
  46. #define RFBI_PARAM RFBI_REG(0x0050)
  47. #define RFBI_DATA RFBI_REG(0x0054)
  48. #define RFBI_READ RFBI_REG(0x0058)
  49. #define RFBI_STATUS RFBI_REG(0x005c)
  50. #define RFBI_CONFIG(n) RFBI_REG(0x0060 + (n)*0x18)
  51. #define RFBI_ONOFF_TIME(n) RFBI_REG(0x0064 + (n)*0x18)
  52. #define RFBI_CYCLE_TIME(n) RFBI_REG(0x0068 + (n)*0x18)
  53. #define RFBI_DATA_CYCLE1(n) RFBI_REG(0x006c + (n)*0x18)
  54. #define RFBI_DATA_CYCLE2(n) RFBI_REG(0x0070 + (n)*0x18)
  55. #define RFBI_DATA_CYCLE3(n) RFBI_REG(0x0074 + (n)*0x18)
  56. #define RFBI_VSYNC_WIDTH RFBI_REG(0x0090)
  57. #define RFBI_HSYNC_WIDTH RFBI_REG(0x0094)
  58. #define RFBI_CMD_FIFO_LEN_BYTES (16 * sizeof(struct update_param))
  59. #define REG_FLD_MOD(idx, val, start, end) \
  60. rfbi_write_reg(idx, FLD_MOD(rfbi_read_reg(idx), val, start, end))
  61. /* To work around an RFBI transfer rate limitation */
  62. #define OMAP_RFBI_RATE_LIMIT 1
  63. enum omap_rfbi_cycleformat {
  64. OMAP_DSS_RFBI_CYCLEFORMAT_1_1 = 0,
  65. OMAP_DSS_RFBI_CYCLEFORMAT_2_1 = 1,
  66. OMAP_DSS_RFBI_CYCLEFORMAT_3_1 = 2,
  67. OMAP_DSS_RFBI_CYCLEFORMAT_3_2 = 3,
  68. };
  69. enum omap_rfbi_datatype {
  70. OMAP_DSS_RFBI_DATATYPE_12 = 0,
  71. OMAP_DSS_RFBI_DATATYPE_16 = 1,
  72. OMAP_DSS_RFBI_DATATYPE_18 = 2,
  73. OMAP_DSS_RFBI_DATATYPE_24 = 3,
  74. };
  75. enum omap_rfbi_parallelmode {
  76. OMAP_DSS_RFBI_PARALLELMODE_8 = 0,
  77. OMAP_DSS_RFBI_PARALLELMODE_9 = 1,
  78. OMAP_DSS_RFBI_PARALLELMODE_12 = 2,
  79. OMAP_DSS_RFBI_PARALLELMODE_16 = 3,
  80. };
  81. enum update_cmd {
  82. RFBI_CMD_UPDATE = 0,
  83. RFBI_CMD_SYNC = 1,
  84. };
  85. static int rfbi_convert_timings(struct rfbi_timings *t);
  86. static void rfbi_get_clk_info(u32 *clk_period, u32 *max_clk_div);
  87. static void process_cmd_fifo(void);
  88. static struct {
  89. void __iomem *base;
  90. unsigned long l4_khz;
  91. enum omap_rfbi_datatype datatype;
  92. enum omap_rfbi_parallelmode parallelmode;
  93. enum omap_rfbi_te_mode te_mode;
  94. int te_enabled;
  95. void (*framedone_callback)(void *data);
  96. void *framedone_callback_data;
  97. struct omap_dss_device *dssdev[2];
  98. struct kfifo *cmd_fifo;
  99. spinlock_t cmd_lock;
  100. struct completion cmd_done;
  101. atomic_t cmd_fifo_full;
  102. atomic_t cmd_pending;
  103. #ifdef MEASURE_PERF
  104. unsigned perf_bytes;
  105. ktime_t perf_setup_time;
  106. ktime_t perf_start_time;
  107. #endif
  108. } rfbi;
  109. struct update_region {
  110. u16 x;
  111. u16 y;
  112. u16 w;
  113. u16 h;
  114. };
  115. struct update_param {
  116. u8 rfbi_module;
  117. u8 cmd;
  118. union {
  119. struct update_region r;
  120. struct completion *sync;
  121. } par;
  122. };
  123. static inline void rfbi_write_reg(const struct rfbi_reg idx, u32 val)
  124. {
  125. __raw_writel(val, rfbi.base + idx.idx);
  126. }
  127. static inline u32 rfbi_read_reg(const struct rfbi_reg idx)
  128. {
  129. return __raw_readl(rfbi.base + idx.idx);
  130. }
  131. static void rfbi_enable_clocks(bool enable)
  132. {
  133. if (enable)
  134. dss_clk_enable(DSS_CLK_ICK | DSS_CLK_FCK1);
  135. else
  136. dss_clk_disable(DSS_CLK_ICK | DSS_CLK_FCK1);
  137. }
  138. void omap_rfbi_write_command(const void *buf, u32 len)
  139. {
  140. rfbi_enable_clocks(1);
  141. switch (rfbi.parallelmode) {
  142. case OMAP_DSS_RFBI_PARALLELMODE_8:
  143. {
  144. const u8 *b = buf;
  145. for (; len; len--)
  146. rfbi_write_reg(RFBI_CMD, *b++);
  147. break;
  148. }
  149. case OMAP_DSS_RFBI_PARALLELMODE_16:
  150. {
  151. const u16 *w = buf;
  152. BUG_ON(len & 1);
  153. for (; len; len -= 2)
  154. rfbi_write_reg(RFBI_CMD, *w++);
  155. break;
  156. }
  157. case OMAP_DSS_RFBI_PARALLELMODE_9:
  158. case OMAP_DSS_RFBI_PARALLELMODE_12:
  159. default:
  160. BUG();
  161. }
  162. rfbi_enable_clocks(0);
  163. }
  164. EXPORT_SYMBOL(omap_rfbi_write_command);
  165. void omap_rfbi_read_data(void *buf, u32 len)
  166. {
  167. rfbi_enable_clocks(1);
  168. switch (rfbi.parallelmode) {
  169. case OMAP_DSS_RFBI_PARALLELMODE_8:
  170. {
  171. u8 *b = buf;
  172. for (; len; len--) {
  173. rfbi_write_reg(RFBI_READ, 0);
  174. *b++ = rfbi_read_reg(RFBI_READ);
  175. }
  176. break;
  177. }
  178. case OMAP_DSS_RFBI_PARALLELMODE_16:
  179. {
  180. u16 *w = buf;
  181. BUG_ON(len & ~1);
  182. for (; len; len -= 2) {
  183. rfbi_write_reg(RFBI_READ, 0);
  184. *w++ = rfbi_read_reg(RFBI_READ);
  185. }
  186. break;
  187. }
  188. case OMAP_DSS_RFBI_PARALLELMODE_9:
  189. case OMAP_DSS_RFBI_PARALLELMODE_12:
  190. default:
  191. BUG();
  192. }
  193. rfbi_enable_clocks(0);
  194. }
  195. EXPORT_SYMBOL(omap_rfbi_read_data);
  196. void omap_rfbi_write_data(const void *buf, u32 len)
  197. {
  198. rfbi_enable_clocks(1);
  199. switch (rfbi.parallelmode) {
  200. case OMAP_DSS_RFBI_PARALLELMODE_8:
  201. {
  202. const u8 *b = buf;
  203. for (; len; len--)
  204. rfbi_write_reg(RFBI_PARAM, *b++);
  205. break;
  206. }
  207. case OMAP_DSS_RFBI_PARALLELMODE_16:
  208. {
  209. const u16 *w = buf;
  210. BUG_ON(len & 1);
  211. for (; len; len -= 2)
  212. rfbi_write_reg(RFBI_PARAM, *w++);
  213. break;
  214. }
  215. case OMAP_DSS_RFBI_PARALLELMODE_9:
  216. case OMAP_DSS_RFBI_PARALLELMODE_12:
  217. default:
  218. BUG();
  219. }
  220. rfbi_enable_clocks(0);
  221. }
  222. EXPORT_SYMBOL(omap_rfbi_write_data);
  223. void omap_rfbi_write_pixels(const void __iomem *buf, int scr_width,
  224. u16 x, u16 y,
  225. u16 w, u16 h)
  226. {
  227. int start_offset = scr_width * y + x;
  228. int horiz_offset = scr_width - w;
  229. int i;
  230. rfbi_enable_clocks(1);
  231. if (rfbi.datatype == OMAP_DSS_RFBI_DATATYPE_16 &&
  232. rfbi.parallelmode == OMAP_DSS_RFBI_PARALLELMODE_8) {
  233. const u16 __iomem *pd = buf;
  234. pd += start_offset;
  235. for (; h; --h) {
  236. for (i = 0; i < w; ++i) {
  237. const u8 __iomem *b = (const u8 __iomem *)pd;
  238. rfbi_write_reg(RFBI_PARAM, __raw_readb(b+1));
  239. rfbi_write_reg(RFBI_PARAM, __raw_readb(b+0));
  240. ++pd;
  241. }
  242. pd += horiz_offset;
  243. }
  244. } else if (rfbi.datatype == OMAP_DSS_RFBI_DATATYPE_24 &&
  245. rfbi.parallelmode == OMAP_DSS_RFBI_PARALLELMODE_8) {
  246. const u32 __iomem *pd = buf;
  247. pd += start_offset;
  248. for (; h; --h) {
  249. for (i = 0; i < w; ++i) {
  250. const u8 __iomem *b = (const u8 __iomem *)pd;
  251. rfbi_write_reg(RFBI_PARAM, __raw_readb(b+2));
  252. rfbi_write_reg(RFBI_PARAM, __raw_readb(b+1));
  253. rfbi_write_reg(RFBI_PARAM, __raw_readb(b+0));
  254. ++pd;
  255. }
  256. pd += horiz_offset;
  257. }
  258. } else if (rfbi.datatype == OMAP_DSS_RFBI_DATATYPE_16 &&
  259. rfbi.parallelmode == OMAP_DSS_RFBI_PARALLELMODE_16) {
  260. const u16 __iomem *pd = buf;
  261. pd += start_offset;
  262. for (; h; --h) {
  263. for (i = 0; i < w; ++i) {
  264. rfbi_write_reg(RFBI_PARAM, __raw_readw(pd));
  265. ++pd;
  266. }
  267. pd += horiz_offset;
  268. }
  269. } else {
  270. BUG();
  271. }
  272. rfbi_enable_clocks(0);
  273. }
  274. EXPORT_SYMBOL(omap_rfbi_write_pixels);
  275. #ifdef MEASURE_PERF
  276. static void perf_mark_setup(void)
  277. {
  278. rfbi.perf_setup_time = ktime_get();
  279. }
  280. static void perf_mark_start(void)
  281. {
  282. rfbi.perf_start_time = ktime_get();
  283. }
  284. static void perf_show(const char *name)
  285. {
  286. ktime_t t, setup_time, trans_time;
  287. u32 total_bytes;
  288. u32 setup_us, trans_us, total_us;
  289. t = ktime_get();
  290. setup_time = ktime_sub(rfbi.perf_start_time, rfbi.perf_setup_time);
  291. setup_us = (u32)ktime_to_us(setup_time);
  292. if (setup_us == 0)
  293. setup_us = 1;
  294. trans_time = ktime_sub(t, rfbi.perf_start_time);
  295. trans_us = (u32)ktime_to_us(trans_time);
  296. if (trans_us == 0)
  297. trans_us = 1;
  298. total_us = setup_us + trans_us;
  299. total_bytes = rfbi.perf_bytes;
  300. DSSINFO("%s update %u us + %u us = %u us (%uHz), %u bytes, "
  301. "%u kbytes/sec\n",
  302. name,
  303. setup_us,
  304. trans_us,
  305. total_us,
  306. 1000*1000 / total_us,
  307. total_bytes,
  308. total_bytes * 1000 / total_us);
  309. }
  310. #else
  311. #define perf_mark_setup()
  312. #define perf_mark_start()
  313. #define perf_show(x)
  314. #endif
  315. void rfbi_transfer_area(u16 width, u16 height,
  316. void (callback)(void *data), void *data)
  317. {
  318. u32 l;
  319. /*BUG_ON(callback == 0);*/
  320. BUG_ON(rfbi.framedone_callback != NULL);
  321. DSSDBG("rfbi_transfer_area %dx%d\n", width, height);
  322. dispc_set_lcd_size(width, height);
  323. dispc_enable_lcd_out(1);
  324. rfbi.framedone_callback = callback;
  325. rfbi.framedone_callback_data = data;
  326. rfbi_enable_clocks(1);
  327. rfbi_write_reg(RFBI_PIXEL_CNT, width * height);
  328. l = rfbi_read_reg(RFBI_CONTROL);
  329. l = FLD_MOD(l, 1, 0, 0); /* enable */
  330. if (!rfbi.te_enabled)
  331. l = FLD_MOD(l, 1, 4, 4); /* ITE */
  332. perf_mark_start();
  333. rfbi_write_reg(RFBI_CONTROL, l);
  334. }
  335. static void framedone_callback(void *data, u32 mask)
  336. {
  337. void (*callback)(void *data);
  338. DSSDBG("FRAMEDONE\n");
  339. perf_show("DISPC");
  340. REG_FLD_MOD(RFBI_CONTROL, 0, 0, 0);
  341. rfbi_enable_clocks(0);
  342. callback = rfbi.framedone_callback;
  343. rfbi.framedone_callback = NULL;
  344. /*callback(rfbi.framedone_callback_data);*/
  345. atomic_set(&rfbi.cmd_pending, 0);
  346. process_cmd_fifo();
  347. }
  348. #if 1 /* VERBOSE */
  349. static void rfbi_print_timings(void)
  350. {
  351. u32 l;
  352. u32 time;
  353. l = rfbi_read_reg(RFBI_CONFIG(0));
  354. time = 1000000000 / rfbi.l4_khz;
  355. if (l & (1 << 4))
  356. time *= 2;
  357. DSSDBG("Tick time %u ps\n", time);
  358. l = rfbi_read_reg(RFBI_ONOFF_TIME(0));
  359. DSSDBG("CSONTIME %d, CSOFFTIME %d, WEONTIME %d, WEOFFTIME %d, "
  360. "REONTIME %d, REOFFTIME %d\n",
  361. l & 0x0f, (l >> 4) & 0x3f, (l >> 10) & 0x0f, (l >> 14) & 0x3f,
  362. (l >> 20) & 0x0f, (l >> 24) & 0x3f);
  363. l = rfbi_read_reg(RFBI_CYCLE_TIME(0));
  364. DSSDBG("WECYCLETIME %d, RECYCLETIME %d, CSPULSEWIDTH %d, "
  365. "ACCESSTIME %d\n",
  366. (l & 0x3f), (l >> 6) & 0x3f, (l >> 12) & 0x3f,
  367. (l >> 22) & 0x3f);
  368. }
  369. #else
  370. static void rfbi_print_timings(void) {}
  371. #endif
  372. static u32 extif_clk_period;
  373. static inline unsigned long round_to_extif_ticks(unsigned long ps, int div)
  374. {
  375. int bus_tick = extif_clk_period * div;
  376. return (ps + bus_tick - 1) / bus_tick * bus_tick;
  377. }
  378. static int calc_reg_timing(struct rfbi_timings *t, int div)
  379. {
  380. t->clk_div = div;
  381. t->cs_on_time = round_to_extif_ticks(t->cs_on_time, div);
  382. t->we_on_time = round_to_extif_ticks(t->we_on_time, div);
  383. t->we_off_time = round_to_extif_ticks(t->we_off_time, div);
  384. t->we_cycle_time = round_to_extif_ticks(t->we_cycle_time, div);
  385. t->re_on_time = round_to_extif_ticks(t->re_on_time, div);
  386. t->re_off_time = round_to_extif_ticks(t->re_off_time, div);
  387. t->re_cycle_time = round_to_extif_ticks(t->re_cycle_time, div);
  388. t->access_time = round_to_extif_ticks(t->access_time, div);
  389. t->cs_off_time = round_to_extif_ticks(t->cs_off_time, div);
  390. t->cs_pulse_width = round_to_extif_ticks(t->cs_pulse_width, div);
  391. DSSDBG("[reg]cson %d csoff %d reon %d reoff %d\n",
  392. t->cs_on_time, t->cs_off_time, t->re_on_time, t->re_off_time);
  393. DSSDBG("[reg]weon %d weoff %d recyc %d wecyc %d\n",
  394. t->we_on_time, t->we_off_time, t->re_cycle_time,
  395. t->we_cycle_time);
  396. DSSDBG("[reg]rdaccess %d cspulse %d\n",
  397. t->access_time, t->cs_pulse_width);
  398. return rfbi_convert_timings(t);
  399. }
  400. static int calc_extif_timings(struct rfbi_timings *t)
  401. {
  402. u32 max_clk_div;
  403. int div;
  404. rfbi_get_clk_info(&extif_clk_period, &max_clk_div);
  405. for (div = 1; div <= max_clk_div; div++) {
  406. if (calc_reg_timing(t, div) == 0)
  407. break;
  408. }
  409. if (div <= max_clk_div)
  410. return 0;
  411. DSSERR("can't setup timings\n");
  412. return -1;
  413. }
  414. void rfbi_set_timings(int rfbi_module, struct rfbi_timings *t)
  415. {
  416. int r;
  417. if (!t->converted) {
  418. r = calc_extif_timings(t);
  419. if (r < 0)
  420. DSSERR("Failed to calc timings\n");
  421. }
  422. BUG_ON(!t->converted);
  423. rfbi_enable_clocks(1);
  424. rfbi_write_reg(RFBI_ONOFF_TIME(rfbi_module), t->tim[0]);
  425. rfbi_write_reg(RFBI_CYCLE_TIME(rfbi_module), t->tim[1]);
  426. /* TIMEGRANULARITY */
  427. REG_FLD_MOD(RFBI_CONFIG(rfbi_module),
  428. (t->tim[2] ? 1 : 0), 4, 4);
  429. rfbi_print_timings();
  430. rfbi_enable_clocks(0);
  431. }
  432. static int ps_to_rfbi_ticks(int time, int div)
  433. {
  434. unsigned long tick_ps;
  435. int ret;
  436. /* Calculate in picosecs to yield more exact results */
  437. tick_ps = 1000000000 / (rfbi.l4_khz) * div;
  438. ret = (time + tick_ps - 1) / tick_ps;
  439. return ret;
  440. }
  441. #ifdef OMAP_RFBI_RATE_LIMIT
  442. unsigned long rfbi_get_max_tx_rate(void)
  443. {
  444. unsigned long l4_rate, dss1_rate;
  445. int min_l4_ticks = 0;
  446. int i;
  447. /* According to TI this can't be calculated so make the
  448. * adjustments for a couple of known frequencies and warn for
  449. * others.
  450. */
  451. static const struct {
  452. unsigned long l4_clk; /* HZ */
  453. unsigned long dss1_clk; /* HZ */
  454. unsigned long min_l4_ticks;
  455. } ftab[] = {
  456. { 55, 132, 7, }, /* 7.86 MPix/s */
  457. { 110, 110, 12, }, /* 9.16 MPix/s */
  458. { 110, 132, 10, }, /* 11 Mpix/s */
  459. { 120, 120, 10, }, /* 12 Mpix/s */
  460. { 133, 133, 10, }, /* 13.3 Mpix/s */
  461. };
  462. l4_rate = rfbi.l4_khz / 1000;
  463. dss1_rate = dss_clk_get_rate(DSS_CLK_FCK1) / 1000000;
  464. for (i = 0; i < ARRAY_SIZE(ftab); i++) {
  465. /* Use a window instead of an exact match, to account
  466. * for different DPLL multiplier / divider pairs.
  467. */
  468. if (abs(ftab[i].l4_clk - l4_rate) < 3 &&
  469. abs(ftab[i].dss1_clk - dss1_rate) < 3) {
  470. min_l4_ticks = ftab[i].min_l4_ticks;
  471. break;
  472. }
  473. }
  474. if (i == ARRAY_SIZE(ftab)) {
  475. /* Can't be sure, return anyway the maximum not
  476. * rate-limited. This might cause a problem only for the
  477. * tearing synchronisation.
  478. */
  479. DSSERR("can't determine maximum RFBI transfer rate\n");
  480. return rfbi.l4_khz * 1000;
  481. }
  482. return rfbi.l4_khz * 1000 / min_l4_ticks;
  483. }
  484. #else
  485. int rfbi_get_max_tx_rate(void)
  486. {
  487. return rfbi.l4_khz * 1000;
  488. }
  489. #endif
  490. static void rfbi_get_clk_info(u32 *clk_period, u32 *max_clk_div)
  491. {
  492. *clk_period = 1000000000 / rfbi.l4_khz;
  493. *max_clk_div = 2;
  494. }
  495. static int rfbi_convert_timings(struct rfbi_timings *t)
  496. {
  497. u32 l;
  498. int reon, reoff, weon, weoff, cson, csoff, cs_pulse;
  499. int actim, recyc, wecyc;
  500. int div = t->clk_div;
  501. if (div <= 0 || div > 2)
  502. return -1;
  503. /* Make sure that after conversion it still holds that:
  504. * weoff > weon, reoff > reon, recyc >= reoff, wecyc >= weoff,
  505. * csoff > cson, csoff >= max(weoff, reoff), actim > reon
  506. */
  507. weon = ps_to_rfbi_ticks(t->we_on_time, div);
  508. weoff = ps_to_rfbi_ticks(t->we_off_time, div);
  509. if (weoff <= weon)
  510. weoff = weon + 1;
  511. if (weon > 0x0f)
  512. return -1;
  513. if (weoff > 0x3f)
  514. return -1;
  515. reon = ps_to_rfbi_ticks(t->re_on_time, div);
  516. reoff = ps_to_rfbi_ticks(t->re_off_time, div);
  517. if (reoff <= reon)
  518. reoff = reon + 1;
  519. if (reon > 0x0f)
  520. return -1;
  521. if (reoff > 0x3f)
  522. return -1;
  523. cson = ps_to_rfbi_ticks(t->cs_on_time, div);
  524. csoff = ps_to_rfbi_ticks(t->cs_off_time, div);
  525. if (csoff <= cson)
  526. csoff = cson + 1;
  527. if (csoff < max(weoff, reoff))
  528. csoff = max(weoff, reoff);
  529. if (cson > 0x0f)
  530. return -1;
  531. if (csoff > 0x3f)
  532. return -1;
  533. l = cson;
  534. l |= csoff << 4;
  535. l |= weon << 10;
  536. l |= weoff << 14;
  537. l |= reon << 20;
  538. l |= reoff << 24;
  539. t->tim[0] = l;
  540. actim = ps_to_rfbi_ticks(t->access_time, div);
  541. if (actim <= reon)
  542. actim = reon + 1;
  543. if (actim > 0x3f)
  544. return -1;
  545. wecyc = ps_to_rfbi_ticks(t->we_cycle_time, div);
  546. if (wecyc < weoff)
  547. wecyc = weoff;
  548. if (wecyc > 0x3f)
  549. return -1;
  550. recyc = ps_to_rfbi_ticks(t->re_cycle_time, div);
  551. if (recyc < reoff)
  552. recyc = reoff;
  553. if (recyc > 0x3f)
  554. return -1;
  555. cs_pulse = ps_to_rfbi_ticks(t->cs_pulse_width, div);
  556. if (cs_pulse > 0x3f)
  557. return -1;
  558. l = wecyc;
  559. l |= recyc << 6;
  560. l |= cs_pulse << 12;
  561. l |= actim << 22;
  562. t->tim[1] = l;
  563. t->tim[2] = div - 1;
  564. t->converted = 1;
  565. return 0;
  566. }
  567. /* xxx FIX module selection missing */
  568. int omap_rfbi_setup_te(enum omap_rfbi_te_mode mode,
  569. unsigned hs_pulse_time, unsigned vs_pulse_time,
  570. int hs_pol_inv, int vs_pol_inv, int extif_div)
  571. {
  572. int hs, vs;
  573. int min;
  574. u32 l;
  575. hs = ps_to_rfbi_ticks(hs_pulse_time, 1);
  576. vs = ps_to_rfbi_ticks(vs_pulse_time, 1);
  577. if (hs < 2)
  578. return -EDOM;
  579. if (mode == OMAP_DSS_RFBI_TE_MODE_2)
  580. min = 2;
  581. else /* OMAP_DSS_RFBI_TE_MODE_1 */
  582. min = 4;
  583. if (vs < min)
  584. return -EDOM;
  585. if (vs == hs)
  586. return -EINVAL;
  587. rfbi.te_mode = mode;
  588. DSSDBG("setup_te: mode %d hs %d vs %d hs_inv %d vs_inv %d\n",
  589. mode, hs, vs, hs_pol_inv, vs_pol_inv);
  590. rfbi_enable_clocks(1);
  591. rfbi_write_reg(RFBI_HSYNC_WIDTH, hs);
  592. rfbi_write_reg(RFBI_VSYNC_WIDTH, vs);
  593. l = rfbi_read_reg(RFBI_CONFIG(0));
  594. if (hs_pol_inv)
  595. l &= ~(1 << 21);
  596. else
  597. l |= 1 << 21;
  598. if (vs_pol_inv)
  599. l &= ~(1 << 20);
  600. else
  601. l |= 1 << 20;
  602. rfbi_enable_clocks(0);
  603. return 0;
  604. }
  605. EXPORT_SYMBOL(omap_rfbi_setup_te);
  606. /* xxx FIX module selection missing */
  607. int omap_rfbi_enable_te(bool enable, unsigned line)
  608. {
  609. u32 l;
  610. DSSDBG("te %d line %d mode %d\n", enable, line, rfbi.te_mode);
  611. if (line > (1 << 11) - 1)
  612. return -EINVAL;
  613. rfbi_enable_clocks(1);
  614. l = rfbi_read_reg(RFBI_CONFIG(0));
  615. l &= ~(0x3 << 2);
  616. if (enable) {
  617. rfbi.te_enabled = 1;
  618. l |= rfbi.te_mode << 2;
  619. } else
  620. rfbi.te_enabled = 0;
  621. rfbi_write_reg(RFBI_CONFIG(0), l);
  622. rfbi_write_reg(RFBI_LINE_NUMBER, line);
  623. rfbi_enable_clocks(0);
  624. return 0;
  625. }
  626. EXPORT_SYMBOL(omap_rfbi_enable_te);
  627. #if 0
  628. static void rfbi_enable_config(int enable1, int enable2)
  629. {
  630. u32 l;
  631. int cs = 0;
  632. if (enable1)
  633. cs |= 1<<0;
  634. if (enable2)
  635. cs |= 1<<1;
  636. rfbi_enable_clocks(1);
  637. l = rfbi_read_reg(RFBI_CONTROL);
  638. l = FLD_MOD(l, cs, 3, 2);
  639. l = FLD_MOD(l, 0, 1, 1);
  640. rfbi_write_reg(RFBI_CONTROL, l);
  641. l = rfbi_read_reg(RFBI_CONFIG(0));
  642. l = FLD_MOD(l, 0, 3, 2); /* TRIGGERMODE: ITE */
  643. /*l |= FLD_VAL(2, 8, 7); */ /* L4FORMAT, 2pix/L4 */
  644. /*l |= FLD_VAL(0, 8, 7); */ /* L4FORMAT, 1pix/L4 */
  645. l = FLD_MOD(l, 0, 16, 16); /* A0POLARITY */
  646. l = FLD_MOD(l, 1, 20, 20); /* TE_VSYNC_POLARITY */
  647. l = FLD_MOD(l, 1, 21, 21); /* HSYNCPOLARITY */
  648. l = FLD_MOD(l, OMAP_DSS_RFBI_PARALLELMODE_8, 1, 0);
  649. rfbi_write_reg(RFBI_CONFIG(0), l);
  650. rfbi_enable_clocks(0);
  651. }
  652. #endif
  653. int rfbi_configure(int rfbi_module, int bpp, int lines)
  654. {
  655. u32 l;
  656. int cycle1 = 0, cycle2 = 0, cycle3 = 0;
  657. enum omap_rfbi_cycleformat cycleformat;
  658. enum omap_rfbi_datatype datatype;
  659. enum omap_rfbi_parallelmode parallelmode;
  660. switch (bpp) {
  661. case 12:
  662. datatype = OMAP_DSS_RFBI_DATATYPE_12;
  663. break;
  664. case 16:
  665. datatype = OMAP_DSS_RFBI_DATATYPE_16;
  666. break;
  667. case 18:
  668. datatype = OMAP_DSS_RFBI_DATATYPE_18;
  669. break;
  670. case 24:
  671. datatype = OMAP_DSS_RFBI_DATATYPE_24;
  672. break;
  673. default:
  674. BUG();
  675. return 1;
  676. }
  677. rfbi.datatype = datatype;
  678. switch (lines) {
  679. case 8:
  680. parallelmode = OMAP_DSS_RFBI_PARALLELMODE_8;
  681. break;
  682. case 9:
  683. parallelmode = OMAP_DSS_RFBI_PARALLELMODE_9;
  684. break;
  685. case 12:
  686. parallelmode = OMAP_DSS_RFBI_PARALLELMODE_12;
  687. break;
  688. case 16:
  689. parallelmode = OMAP_DSS_RFBI_PARALLELMODE_16;
  690. break;
  691. default:
  692. BUG();
  693. return 1;
  694. }
  695. rfbi.parallelmode = parallelmode;
  696. if ((bpp % lines) == 0) {
  697. switch (bpp / lines) {
  698. case 1:
  699. cycleformat = OMAP_DSS_RFBI_CYCLEFORMAT_1_1;
  700. break;
  701. case 2:
  702. cycleformat = OMAP_DSS_RFBI_CYCLEFORMAT_2_1;
  703. break;
  704. case 3:
  705. cycleformat = OMAP_DSS_RFBI_CYCLEFORMAT_3_1;
  706. break;
  707. default:
  708. BUG();
  709. return 1;
  710. }
  711. } else if ((2 * bpp % lines) == 0) {
  712. if ((2 * bpp / lines) == 3)
  713. cycleformat = OMAP_DSS_RFBI_CYCLEFORMAT_3_2;
  714. else {
  715. BUG();
  716. return 1;
  717. }
  718. } else {
  719. BUG();
  720. return 1;
  721. }
  722. switch (cycleformat) {
  723. case OMAP_DSS_RFBI_CYCLEFORMAT_1_1:
  724. cycle1 = lines;
  725. break;
  726. case OMAP_DSS_RFBI_CYCLEFORMAT_2_1:
  727. cycle1 = lines;
  728. cycle2 = lines;
  729. break;
  730. case OMAP_DSS_RFBI_CYCLEFORMAT_3_1:
  731. cycle1 = lines;
  732. cycle2 = lines;
  733. cycle3 = lines;
  734. break;
  735. case OMAP_DSS_RFBI_CYCLEFORMAT_3_2:
  736. cycle1 = lines;
  737. cycle2 = (lines / 2) | ((lines / 2) << 16);
  738. cycle3 = (lines << 16);
  739. break;
  740. }
  741. rfbi_enable_clocks(1);
  742. REG_FLD_MOD(RFBI_CONTROL, 0, 3, 2); /* clear CS */
  743. l = 0;
  744. l |= FLD_VAL(parallelmode, 1, 0);
  745. l |= FLD_VAL(0, 3, 2); /* TRIGGERMODE: ITE */
  746. l |= FLD_VAL(0, 4, 4); /* TIMEGRANULARITY */
  747. l |= FLD_VAL(datatype, 6, 5);
  748. /* l |= FLD_VAL(2, 8, 7); */ /* L4FORMAT, 2pix/L4 */
  749. l |= FLD_VAL(0, 8, 7); /* L4FORMAT, 1pix/L4 */
  750. l |= FLD_VAL(cycleformat, 10, 9);
  751. l |= FLD_VAL(0, 12, 11); /* UNUSEDBITS */
  752. l |= FLD_VAL(0, 16, 16); /* A0POLARITY */
  753. l |= FLD_VAL(0, 17, 17); /* REPOLARITY */
  754. l |= FLD_VAL(0, 18, 18); /* WEPOLARITY */
  755. l |= FLD_VAL(0, 19, 19); /* CSPOLARITY */
  756. l |= FLD_VAL(1, 20, 20); /* TE_VSYNC_POLARITY */
  757. l |= FLD_VAL(1, 21, 21); /* HSYNCPOLARITY */
  758. rfbi_write_reg(RFBI_CONFIG(rfbi_module), l);
  759. rfbi_write_reg(RFBI_DATA_CYCLE1(rfbi_module), cycle1);
  760. rfbi_write_reg(RFBI_DATA_CYCLE2(rfbi_module), cycle2);
  761. rfbi_write_reg(RFBI_DATA_CYCLE3(rfbi_module), cycle3);
  762. l = rfbi_read_reg(RFBI_CONTROL);
  763. l = FLD_MOD(l, rfbi_module+1, 3, 2); /* Select CSx */
  764. l = FLD_MOD(l, 0, 1, 1); /* clear bypass */
  765. rfbi_write_reg(RFBI_CONTROL, l);
  766. DSSDBG("RFBI config: bpp %d, lines %d, cycles: 0x%x 0x%x 0x%x\n",
  767. bpp, lines, cycle1, cycle2, cycle3);
  768. rfbi_enable_clocks(0);
  769. return 0;
  770. }
  771. EXPORT_SYMBOL(rfbi_configure);
  772. static int rfbi_find_display(struct omap_dss_device *dssdev)
  773. {
  774. if (dssdev == rfbi.dssdev[0])
  775. return 0;
  776. if (dssdev == rfbi.dssdev[1])
  777. return 1;
  778. BUG();
  779. return -1;
  780. }
  781. static void signal_fifo_waiters(void)
  782. {
  783. if (atomic_read(&rfbi.cmd_fifo_full) > 0) {
  784. /* DSSDBG("SIGNALING: Fifo not full for waiter!\n"); */
  785. complete(&rfbi.cmd_done);
  786. atomic_dec(&rfbi.cmd_fifo_full);
  787. }
  788. }
  789. /* returns 1 for async op, and 0 for sync op */
  790. static int do_update(struct omap_dss_device *dssdev, struct update_region *upd)
  791. {
  792. u16 x = upd->x;
  793. u16 y = upd->y;
  794. u16 w = upd->w;
  795. u16 h = upd->h;
  796. perf_mark_setup();
  797. if (dssdev->manager->caps & OMAP_DSS_OVL_MGR_CAP_DISPC) {
  798. /*dssdev->driver->enable_te(dssdev, 1); */
  799. dss_setup_partial_planes(dssdev, &x, &y, &w, &h);
  800. }
  801. #ifdef MEASURE_PERF
  802. rfbi.perf_bytes = w * h * 2; /* XXX always 16bit */
  803. #endif
  804. dssdev->driver->setup_update(dssdev, x, y, w, h);
  805. if (dssdev->manager->caps & OMAP_DSS_OVL_MGR_CAP_DISPC) {
  806. rfbi_transfer_area(w, h, NULL, NULL);
  807. return 1;
  808. } else {
  809. struct omap_overlay *ovl;
  810. void __iomem *addr;
  811. int scr_width;
  812. ovl = dssdev->manager->overlays[0];
  813. scr_width = ovl->info.screen_width;
  814. addr = ovl->info.vaddr;
  815. omap_rfbi_write_pixels(addr, scr_width, x, y, w, h);
  816. perf_show("L4");
  817. return 0;
  818. }
  819. }
  820. static void process_cmd_fifo(void)
  821. {
  822. int len;
  823. struct update_param p;
  824. struct omap_dss_device *dssdev;
  825. unsigned long flags;
  826. if (atomic_inc_return(&rfbi.cmd_pending) != 1)
  827. return;
  828. while (true) {
  829. spin_lock_irqsave(rfbi.cmd_fifo->lock, flags);
  830. len = __kfifo_get(rfbi.cmd_fifo, (unsigned char *)&p,
  831. sizeof(struct update_param));
  832. if (len == 0) {
  833. DSSDBG("nothing more in fifo\n");
  834. atomic_set(&rfbi.cmd_pending, 0);
  835. spin_unlock_irqrestore(rfbi.cmd_fifo->lock, flags);
  836. break;
  837. }
  838. /* DSSDBG("fifo full %d\n", rfbi.cmd_fifo_full.counter);*/
  839. spin_unlock_irqrestore(rfbi.cmd_fifo->lock, flags);
  840. BUG_ON(len != sizeof(struct update_param));
  841. BUG_ON(p.rfbi_module > 1);
  842. dssdev = rfbi.dssdev[p.rfbi_module];
  843. if (p.cmd == RFBI_CMD_UPDATE) {
  844. if (do_update(dssdev, &p.par.r))
  845. break; /* async op */
  846. } else if (p.cmd == RFBI_CMD_SYNC) {
  847. DSSDBG("Signaling SYNC done!\n");
  848. complete(p.par.sync);
  849. } else
  850. BUG();
  851. }
  852. signal_fifo_waiters();
  853. }
  854. static void rfbi_push_cmd(struct update_param *p)
  855. {
  856. int ret;
  857. while (1) {
  858. unsigned long flags;
  859. int available;
  860. spin_lock_irqsave(rfbi.cmd_fifo->lock, flags);
  861. available = RFBI_CMD_FIFO_LEN_BYTES -
  862. __kfifo_len(rfbi.cmd_fifo);
  863. /* DSSDBG("%d bytes left in fifo\n", available); */
  864. if (available < sizeof(struct update_param)) {
  865. DSSDBG("Going to wait because FIFO FULL..\n");
  866. spin_unlock_irqrestore(rfbi.cmd_fifo->lock, flags);
  867. atomic_inc(&rfbi.cmd_fifo_full);
  868. wait_for_completion(&rfbi.cmd_done);
  869. /*DSSDBG("Woke up because fifo not full anymore\n");*/
  870. continue;
  871. }
  872. ret = __kfifo_put(rfbi.cmd_fifo, (unsigned char *)p,
  873. sizeof(struct update_param));
  874. /* DSSDBG("pushed %d bytes\n", ret);*/
  875. spin_unlock_irqrestore(rfbi.cmd_fifo->lock, flags);
  876. BUG_ON(ret != sizeof(struct update_param));
  877. break;
  878. }
  879. }
  880. static void rfbi_push_update(int rfbi_module, int x, int y, int w, int h)
  881. {
  882. struct update_param p;
  883. p.rfbi_module = rfbi_module;
  884. p.cmd = RFBI_CMD_UPDATE;
  885. p.par.r.x = x;
  886. p.par.r.y = y;
  887. p.par.r.w = w;
  888. p.par.r.h = h;
  889. DSSDBG("RFBI pushed %d,%d %dx%d\n", x, y, w, h);
  890. rfbi_push_cmd(&p);
  891. process_cmd_fifo();
  892. }
  893. static void rfbi_push_sync(int rfbi_module, struct completion *sync_comp)
  894. {
  895. struct update_param p;
  896. p.rfbi_module = rfbi_module;
  897. p.cmd = RFBI_CMD_SYNC;
  898. p.par.sync = sync_comp;
  899. rfbi_push_cmd(&p);
  900. DSSDBG("RFBI sync pushed to cmd fifo\n");
  901. process_cmd_fifo();
  902. }
  903. void rfbi_dump_regs(struct seq_file *s)
  904. {
  905. #define DUMPREG(r) seq_printf(s, "%-35s %08x\n", #r, rfbi_read_reg(r))
  906. dss_clk_enable(DSS_CLK_ICK | DSS_CLK_FCK1);
  907. DUMPREG(RFBI_REVISION);
  908. DUMPREG(RFBI_SYSCONFIG);
  909. DUMPREG(RFBI_SYSSTATUS);
  910. DUMPREG(RFBI_CONTROL);
  911. DUMPREG(RFBI_PIXEL_CNT);
  912. DUMPREG(RFBI_LINE_NUMBER);
  913. DUMPREG(RFBI_CMD);
  914. DUMPREG(RFBI_PARAM);
  915. DUMPREG(RFBI_DATA);
  916. DUMPREG(RFBI_READ);
  917. DUMPREG(RFBI_STATUS);
  918. DUMPREG(RFBI_CONFIG(0));
  919. DUMPREG(RFBI_ONOFF_TIME(0));
  920. DUMPREG(RFBI_CYCLE_TIME(0));
  921. DUMPREG(RFBI_DATA_CYCLE1(0));
  922. DUMPREG(RFBI_DATA_CYCLE2(0));
  923. DUMPREG(RFBI_DATA_CYCLE3(0));
  924. DUMPREG(RFBI_CONFIG(1));
  925. DUMPREG(RFBI_ONOFF_TIME(1));
  926. DUMPREG(RFBI_CYCLE_TIME(1));
  927. DUMPREG(RFBI_DATA_CYCLE1(1));
  928. DUMPREG(RFBI_DATA_CYCLE2(1));
  929. DUMPREG(RFBI_DATA_CYCLE3(1));
  930. DUMPREG(RFBI_VSYNC_WIDTH);
  931. DUMPREG(RFBI_HSYNC_WIDTH);
  932. dss_clk_disable(DSS_CLK_ICK | DSS_CLK_FCK1);
  933. #undef DUMPREG
  934. }
  935. int rfbi_init(void)
  936. {
  937. u32 rev;
  938. u32 l;
  939. spin_lock_init(&rfbi.cmd_lock);
  940. rfbi.cmd_fifo = kfifo_alloc(RFBI_CMD_FIFO_LEN_BYTES, GFP_KERNEL,
  941. &rfbi.cmd_lock);
  942. if (IS_ERR(rfbi.cmd_fifo))
  943. return -ENOMEM;
  944. init_completion(&rfbi.cmd_done);
  945. atomic_set(&rfbi.cmd_fifo_full, 0);
  946. atomic_set(&rfbi.cmd_pending, 0);
  947. rfbi.base = ioremap(RFBI_BASE, SZ_256);
  948. if (!rfbi.base) {
  949. DSSERR("can't ioremap RFBI\n");
  950. return -ENOMEM;
  951. }
  952. rfbi_enable_clocks(1);
  953. msleep(10);
  954. rfbi.l4_khz = dss_clk_get_rate(DSS_CLK_ICK) / 1000;
  955. /* Enable autoidle and smart-idle */
  956. l = rfbi_read_reg(RFBI_SYSCONFIG);
  957. l |= (1 << 0) | (2 << 3);
  958. rfbi_write_reg(RFBI_SYSCONFIG, l);
  959. rev = rfbi_read_reg(RFBI_REVISION);
  960. printk(KERN_INFO "OMAP RFBI rev %d.%d\n",
  961. FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
  962. rfbi_enable_clocks(0);
  963. return 0;
  964. }
  965. void rfbi_exit(void)
  966. {
  967. DSSDBG("rfbi_exit\n");
  968. kfifo_free(rfbi.cmd_fifo);
  969. iounmap(rfbi.base);
  970. }
  971. /* struct omap_display support */
  972. static int rfbi_display_update(struct omap_dss_device *dssdev,
  973. u16 x, u16 y, u16 w, u16 h)
  974. {
  975. int rfbi_module;
  976. if (w == 0 || h == 0)
  977. return 0;
  978. rfbi_module = rfbi_find_display(dssdev);
  979. rfbi_push_update(rfbi_module, x, y, w, h);
  980. return 0;
  981. }
  982. static int rfbi_display_sync(struct omap_dss_device *dssdev)
  983. {
  984. struct completion sync_comp;
  985. int rfbi_module;
  986. rfbi_module = rfbi_find_display(dssdev);
  987. init_completion(&sync_comp);
  988. rfbi_push_sync(rfbi_module, &sync_comp);
  989. DSSDBG("Waiting for SYNC to happen...\n");
  990. wait_for_completion(&sync_comp);
  991. DSSDBG("Released from SYNC\n");
  992. return 0;
  993. }
  994. static int rfbi_display_enable_te(struct omap_dss_device *dssdev, bool enable)
  995. {
  996. dssdev->driver->enable_te(dssdev, enable);
  997. return 0;
  998. }
  999. static int rfbi_display_enable(struct omap_dss_device *dssdev)
  1000. {
  1001. int r;
  1002. r = omap_dss_start_device(dssdev);
  1003. if (r) {
  1004. DSSERR("failed to start device\n");
  1005. goto err0;
  1006. }
  1007. r = omap_dispc_register_isr(framedone_callback, NULL,
  1008. DISPC_IRQ_FRAMEDONE);
  1009. if (r) {
  1010. DSSERR("can't get FRAMEDONE irq\n");
  1011. goto err1;
  1012. }
  1013. dispc_set_lcd_display_type(OMAP_DSS_LCD_DISPLAY_TFT);
  1014. dispc_set_parallel_interface_mode(OMAP_DSS_PARALLELMODE_RFBI);
  1015. dispc_set_tft_data_lines(dssdev->ctrl.pixel_size);
  1016. rfbi_configure(dssdev->phy.rfbi.channel,
  1017. dssdev->ctrl.pixel_size,
  1018. dssdev->phy.rfbi.data_lines);
  1019. rfbi_set_timings(dssdev->phy.rfbi.channel,
  1020. &dssdev->ctrl.rfbi_timings);
  1021. if (dssdev->driver->enable) {
  1022. r = dssdev->driver->enable(dssdev);
  1023. if (r)
  1024. goto err2;
  1025. }
  1026. return 0;
  1027. err2:
  1028. omap_dispc_unregister_isr(framedone_callback, NULL,
  1029. DISPC_IRQ_FRAMEDONE);
  1030. err1:
  1031. omap_dss_stop_device(dssdev);
  1032. err0:
  1033. return r;
  1034. }
  1035. static void rfbi_display_disable(struct omap_dss_device *dssdev)
  1036. {
  1037. dssdev->driver->disable(dssdev);
  1038. omap_dispc_unregister_isr(framedone_callback, NULL,
  1039. DISPC_IRQ_FRAMEDONE);
  1040. omap_dss_stop_device(dssdev);
  1041. }
  1042. int rfbi_init_display(struct omap_dss_device *dssdev)
  1043. {
  1044. dssdev->enable = rfbi_display_enable;
  1045. dssdev->disable = rfbi_display_disable;
  1046. dssdev->update = rfbi_display_update;
  1047. dssdev->sync = rfbi_display_sync;
  1048. dssdev->enable_te = rfbi_display_enable_te;
  1049. rfbi.dssdev[dssdev->phy.rfbi.channel] = dssdev;
  1050. dssdev->caps = OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE;
  1051. return 0;
  1052. }