rfbi.c 23 KB

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