rfbi.c 24 KB

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