rfbi.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083
  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/export.h>
  26. #include <linux/vmalloc.h>
  27. #include <linux/clk.h>
  28. #include <linux/io.h>
  29. #include <linux/delay.h>
  30. #include <linux/kfifo.h>
  31. #include <linux/ktime.h>
  32. #include <linux/hrtimer.h>
  33. #include <linux/seq_file.h>
  34. #include <linux/semaphore.h>
  35. #include <linux/platform_device.h>
  36. #include <linux/pm_runtime.h>
  37. #include <linux/component.h>
  38. #include "omapdss.h"
  39. #include "dss.h"
  40. struct rfbi_reg { u16 idx; };
  41. #define RFBI_REG(idx) ((const struct rfbi_reg) { idx })
  42. #define RFBI_REVISION RFBI_REG(0x0000)
  43. #define RFBI_SYSCONFIG RFBI_REG(0x0010)
  44. #define RFBI_SYSSTATUS RFBI_REG(0x0014)
  45. #define RFBI_CONTROL RFBI_REG(0x0040)
  46. #define RFBI_PIXEL_CNT RFBI_REG(0x0044)
  47. #define RFBI_LINE_NUMBER RFBI_REG(0x0048)
  48. #define RFBI_CMD RFBI_REG(0x004c)
  49. #define RFBI_PARAM RFBI_REG(0x0050)
  50. #define RFBI_DATA RFBI_REG(0x0054)
  51. #define RFBI_READ RFBI_REG(0x0058)
  52. #define RFBI_STATUS RFBI_REG(0x005c)
  53. #define RFBI_CONFIG(n) RFBI_REG(0x0060 + (n)*0x18)
  54. #define RFBI_ONOFF_TIME(n) RFBI_REG(0x0064 + (n)*0x18)
  55. #define RFBI_CYCLE_TIME(n) RFBI_REG(0x0068 + (n)*0x18)
  56. #define RFBI_DATA_CYCLE1(n) RFBI_REG(0x006c + (n)*0x18)
  57. #define RFBI_DATA_CYCLE2(n) RFBI_REG(0x0070 + (n)*0x18)
  58. #define RFBI_DATA_CYCLE3(n) RFBI_REG(0x0074 + (n)*0x18)
  59. #define RFBI_VSYNC_WIDTH RFBI_REG(0x0090)
  60. #define RFBI_HSYNC_WIDTH RFBI_REG(0x0094)
  61. #define REG_FLD_MOD(idx, val, start, end) \
  62. rfbi_write_reg(idx, FLD_MOD(rfbi_read_reg(idx), val, start, end))
  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. static int rfbi_convert_timings(struct rfbi_timings *t);
  82. static void rfbi_get_clk_info(u32 *clk_period, u32 *max_clk_div);
  83. static struct {
  84. struct platform_device *pdev;
  85. void __iomem *base;
  86. unsigned long l4_khz;
  87. enum omap_rfbi_datatype datatype;
  88. enum omap_rfbi_parallelmode parallelmode;
  89. enum omap_rfbi_te_mode te_mode;
  90. int te_enabled;
  91. void (*framedone_callback)(void *data);
  92. void *framedone_callback_data;
  93. struct omap_dss_device *dssdev[2];
  94. struct semaphore bus_lock;
  95. struct videomode vm;
  96. int pixel_size;
  97. int data_lines;
  98. struct rfbi_timings intf_timings;
  99. struct omap_dss_device output;
  100. } rfbi;
  101. static inline void rfbi_write_reg(const struct rfbi_reg idx, u32 val)
  102. {
  103. __raw_writel(val, rfbi.base + idx.idx);
  104. }
  105. static inline u32 rfbi_read_reg(const struct rfbi_reg idx)
  106. {
  107. return __raw_readl(rfbi.base + idx.idx);
  108. }
  109. static int rfbi_runtime_get(void)
  110. {
  111. int r;
  112. DSSDBG("rfbi_runtime_get\n");
  113. r = pm_runtime_get_sync(&rfbi.pdev->dev);
  114. WARN_ON(r < 0);
  115. return r < 0 ? r : 0;
  116. }
  117. static void rfbi_runtime_put(void)
  118. {
  119. int r;
  120. DSSDBG("rfbi_runtime_put\n");
  121. r = pm_runtime_put_sync(&rfbi.pdev->dev);
  122. WARN_ON(r < 0 && r != -ENOSYS);
  123. }
  124. static void rfbi_bus_lock(void)
  125. {
  126. down(&rfbi.bus_lock);
  127. }
  128. static void rfbi_bus_unlock(void)
  129. {
  130. up(&rfbi.bus_lock);
  131. }
  132. static void rfbi_write_command(const void *buf, u32 len)
  133. {
  134. switch (rfbi.parallelmode) {
  135. case OMAP_DSS_RFBI_PARALLELMODE_8:
  136. {
  137. const u8 *b = buf;
  138. for (; len; len--)
  139. rfbi_write_reg(RFBI_CMD, *b++);
  140. break;
  141. }
  142. case OMAP_DSS_RFBI_PARALLELMODE_16:
  143. {
  144. const u16 *w = buf;
  145. BUG_ON(len & 1);
  146. for (; len; len -= 2)
  147. rfbi_write_reg(RFBI_CMD, *w++);
  148. break;
  149. }
  150. case OMAP_DSS_RFBI_PARALLELMODE_9:
  151. case OMAP_DSS_RFBI_PARALLELMODE_12:
  152. default:
  153. BUG();
  154. }
  155. }
  156. static void rfbi_read_data(void *buf, u32 len)
  157. {
  158. switch (rfbi.parallelmode) {
  159. case OMAP_DSS_RFBI_PARALLELMODE_8:
  160. {
  161. u8 *b = buf;
  162. for (; len; len--) {
  163. rfbi_write_reg(RFBI_READ, 0);
  164. *b++ = rfbi_read_reg(RFBI_READ);
  165. }
  166. break;
  167. }
  168. case OMAP_DSS_RFBI_PARALLELMODE_16:
  169. {
  170. u16 *w = buf;
  171. BUG_ON(len & ~1);
  172. for (; len; len -= 2) {
  173. rfbi_write_reg(RFBI_READ, 0);
  174. *w++ = rfbi_read_reg(RFBI_READ);
  175. }
  176. break;
  177. }
  178. case OMAP_DSS_RFBI_PARALLELMODE_9:
  179. case OMAP_DSS_RFBI_PARALLELMODE_12:
  180. default:
  181. BUG();
  182. }
  183. }
  184. static void rfbi_write_data(const void *buf, u32 len)
  185. {
  186. switch (rfbi.parallelmode) {
  187. case OMAP_DSS_RFBI_PARALLELMODE_8:
  188. {
  189. const u8 *b = buf;
  190. for (; len; len--)
  191. rfbi_write_reg(RFBI_PARAM, *b++);
  192. break;
  193. }
  194. case OMAP_DSS_RFBI_PARALLELMODE_16:
  195. {
  196. const u16 *w = buf;
  197. BUG_ON(len & 1);
  198. for (; len; len -= 2)
  199. rfbi_write_reg(RFBI_PARAM, *w++);
  200. break;
  201. }
  202. case OMAP_DSS_RFBI_PARALLELMODE_9:
  203. case OMAP_DSS_RFBI_PARALLELMODE_12:
  204. default:
  205. BUG();
  206. }
  207. }
  208. static void 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. 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. }
  257. static int rfbi_transfer_area(struct omap_dss_device *dssdev,
  258. void (*callback)(void *data), void *data)
  259. {
  260. u32 l;
  261. int r;
  262. struct omap_overlay_manager *mgr = rfbi.output.manager;
  263. u16 width = rfbi.vm.hactive;
  264. u16 height = rfbi.vm.vactive;
  265. /*BUG_ON(callback == 0);*/
  266. BUG_ON(rfbi.framedone_callback != NULL);
  267. DSSDBG("rfbi_transfer_area %dx%d\n", width, height);
  268. dss_mgr_set_timings(mgr, &rfbi.vm);
  269. r = dss_mgr_enable(mgr);
  270. if (r)
  271. return r;
  272. rfbi.framedone_callback = callback;
  273. rfbi.framedone_callback_data = data;
  274. rfbi_write_reg(RFBI_PIXEL_CNT, width * height);
  275. l = rfbi_read_reg(RFBI_CONTROL);
  276. l = FLD_MOD(l, 1, 0, 0); /* enable */
  277. if (!rfbi.te_enabled)
  278. l = FLD_MOD(l, 1, 4, 4); /* ITE */
  279. rfbi_write_reg(RFBI_CONTROL, l);
  280. return 0;
  281. }
  282. static void framedone_callback(void *data)
  283. {
  284. void (*callback)(void *data);
  285. DSSDBG("FRAMEDONE\n");
  286. REG_FLD_MOD(RFBI_CONTROL, 0, 0, 0);
  287. callback = rfbi.framedone_callback;
  288. rfbi.framedone_callback = NULL;
  289. if (callback != NULL)
  290. callback(rfbi.framedone_callback_data);
  291. }
  292. #if 1 /* VERBOSE */
  293. static void rfbi_print_timings(void)
  294. {
  295. u32 l;
  296. u32 time;
  297. l = rfbi_read_reg(RFBI_CONFIG(0));
  298. time = 1000000000 / rfbi.l4_khz;
  299. if (l & (1 << 4))
  300. time *= 2;
  301. DSSDBG("Tick time %u ps\n", time);
  302. l = rfbi_read_reg(RFBI_ONOFF_TIME(0));
  303. DSSDBG("CSONTIME %d, CSOFFTIME %d, WEONTIME %d, WEOFFTIME %d, "
  304. "REONTIME %d, REOFFTIME %d\n",
  305. l & 0x0f, (l >> 4) & 0x3f, (l >> 10) & 0x0f, (l >> 14) & 0x3f,
  306. (l >> 20) & 0x0f, (l >> 24) & 0x3f);
  307. l = rfbi_read_reg(RFBI_CYCLE_TIME(0));
  308. DSSDBG("WECYCLETIME %d, RECYCLETIME %d, CSPULSEWIDTH %d, "
  309. "ACCESSTIME %d\n",
  310. (l & 0x3f), (l >> 6) & 0x3f, (l >> 12) & 0x3f,
  311. (l >> 22) & 0x3f);
  312. }
  313. #else
  314. static void rfbi_print_timings(void) {}
  315. #endif
  316. static u32 extif_clk_period;
  317. static inline unsigned long round_to_extif_ticks(unsigned long ps, int div)
  318. {
  319. int bus_tick = extif_clk_period * div;
  320. return (ps + bus_tick - 1) / bus_tick * bus_tick;
  321. }
  322. static int calc_reg_timing(struct rfbi_timings *t, int div)
  323. {
  324. t->clk_div = div;
  325. t->cs_on_time = round_to_extif_ticks(t->cs_on_time, div);
  326. t->we_on_time = round_to_extif_ticks(t->we_on_time, div);
  327. t->we_off_time = round_to_extif_ticks(t->we_off_time, div);
  328. t->we_cycle_time = round_to_extif_ticks(t->we_cycle_time, div);
  329. t->re_on_time = round_to_extif_ticks(t->re_on_time, div);
  330. t->re_off_time = round_to_extif_ticks(t->re_off_time, div);
  331. t->re_cycle_time = round_to_extif_ticks(t->re_cycle_time, div);
  332. t->access_time = round_to_extif_ticks(t->access_time, div);
  333. t->cs_off_time = round_to_extif_ticks(t->cs_off_time, div);
  334. t->cs_pulse_width = round_to_extif_ticks(t->cs_pulse_width, div);
  335. DSSDBG("[reg]cson %d csoff %d reon %d reoff %d\n",
  336. t->cs_on_time, t->cs_off_time, t->re_on_time, t->re_off_time);
  337. DSSDBG("[reg]weon %d weoff %d recyc %d wecyc %d\n",
  338. t->we_on_time, t->we_off_time, t->re_cycle_time,
  339. t->we_cycle_time);
  340. DSSDBG("[reg]rdaccess %d cspulse %d\n",
  341. t->access_time, t->cs_pulse_width);
  342. return rfbi_convert_timings(t);
  343. }
  344. static int calc_extif_timings(struct rfbi_timings *t)
  345. {
  346. u32 max_clk_div;
  347. int div;
  348. rfbi_get_clk_info(&extif_clk_period, &max_clk_div);
  349. for (div = 1; div <= max_clk_div; div++) {
  350. if (calc_reg_timing(t, div) == 0)
  351. break;
  352. }
  353. if (div <= max_clk_div)
  354. return 0;
  355. DSSERR("can't setup timings\n");
  356. return -1;
  357. }
  358. static void rfbi_set_timings(int rfbi_module, struct rfbi_timings *t)
  359. {
  360. int r;
  361. if (!t->converted) {
  362. r = calc_extif_timings(t);
  363. if (r < 0)
  364. DSSERR("Failed to calc timings\n");
  365. }
  366. BUG_ON(!t->converted);
  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. }
  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. static void rfbi_get_clk_info(u32 *clk_period, u32 *max_clk_div)
  384. {
  385. *clk_period = 1000000000 / rfbi.l4_khz;
  386. *max_clk_div = 2;
  387. }
  388. static int rfbi_convert_timings(struct rfbi_timings *t)
  389. {
  390. u32 l;
  391. int reon, reoff, weon, weoff, cson, csoff, cs_pulse;
  392. int actim, recyc, wecyc;
  393. int div = t->clk_div;
  394. if (div <= 0 || div > 2)
  395. return -1;
  396. /* Make sure that after conversion it still holds that:
  397. * weoff > weon, reoff > reon, recyc >= reoff, wecyc >= weoff,
  398. * csoff > cson, csoff >= max(weoff, reoff), actim > reon
  399. */
  400. weon = ps_to_rfbi_ticks(t->we_on_time, div);
  401. weoff = ps_to_rfbi_ticks(t->we_off_time, div);
  402. if (weoff <= weon)
  403. weoff = weon + 1;
  404. if (weon > 0x0f)
  405. return -1;
  406. if (weoff > 0x3f)
  407. return -1;
  408. reon = ps_to_rfbi_ticks(t->re_on_time, div);
  409. reoff = ps_to_rfbi_ticks(t->re_off_time, div);
  410. if (reoff <= reon)
  411. reoff = reon + 1;
  412. if (reon > 0x0f)
  413. return -1;
  414. if (reoff > 0x3f)
  415. return -1;
  416. cson = ps_to_rfbi_ticks(t->cs_on_time, div);
  417. csoff = ps_to_rfbi_ticks(t->cs_off_time, div);
  418. if (csoff <= cson)
  419. csoff = cson + 1;
  420. if (csoff < max(weoff, reoff))
  421. csoff = max(weoff, reoff);
  422. if (cson > 0x0f)
  423. return -1;
  424. if (csoff > 0x3f)
  425. return -1;
  426. l = cson;
  427. l |= csoff << 4;
  428. l |= weon << 10;
  429. l |= weoff << 14;
  430. l |= reon << 20;
  431. l |= reoff << 24;
  432. t->tim[0] = l;
  433. actim = ps_to_rfbi_ticks(t->access_time, div);
  434. if (actim <= reon)
  435. actim = reon + 1;
  436. if (actim > 0x3f)
  437. return -1;
  438. wecyc = ps_to_rfbi_ticks(t->we_cycle_time, div);
  439. if (wecyc < weoff)
  440. wecyc = weoff;
  441. if (wecyc > 0x3f)
  442. return -1;
  443. recyc = ps_to_rfbi_ticks(t->re_cycle_time, div);
  444. if (recyc < reoff)
  445. recyc = reoff;
  446. if (recyc > 0x3f)
  447. return -1;
  448. cs_pulse = ps_to_rfbi_ticks(t->cs_pulse_width, div);
  449. if (cs_pulse > 0x3f)
  450. return -1;
  451. l = wecyc;
  452. l |= recyc << 6;
  453. l |= cs_pulse << 12;
  454. l |= actim << 22;
  455. t->tim[1] = l;
  456. t->tim[2] = div - 1;
  457. t->converted = 1;
  458. return 0;
  459. }
  460. /* xxx FIX module selection missing */
  461. static int rfbi_setup_te(enum omap_rfbi_te_mode mode,
  462. unsigned hs_pulse_time, unsigned vs_pulse_time,
  463. int hs_pol_inv, int vs_pol_inv, int extif_div)
  464. {
  465. int hs, vs;
  466. int min;
  467. u32 l;
  468. hs = ps_to_rfbi_ticks(hs_pulse_time, 1);
  469. vs = ps_to_rfbi_ticks(vs_pulse_time, 1);
  470. if (hs < 2)
  471. return -EDOM;
  472. if (mode == OMAP_DSS_RFBI_TE_MODE_2)
  473. min = 2;
  474. else /* OMAP_DSS_RFBI_TE_MODE_1 */
  475. min = 4;
  476. if (vs < min)
  477. return -EDOM;
  478. if (vs == hs)
  479. return -EINVAL;
  480. rfbi.te_mode = mode;
  481. DSSDBG("setup_te: mode %d hs %d vs %d hs_inv %d vs_inv %d\n",
  482. mode, hs, vs, hs_pol_inv, vs_pol_inv);
  483. rfbi_write_reg(RFBI_HSYNC_WIDTH, hs);
  484. rfbi_write_reg(RFBI_VSYNC_WIDTH, vs);
  485. l = rfbi_read_reg(RFBI_CONFIG(0));
  486. if (hs_pol_inv)
  487. l &= ~(1 << 21);
  488. else
  489. l |= 1 << 21;
  490. if (vs_pol_inv)
  491. l &= ~(1 << 20);
  492. else
  493. l |= 1 << 20;
  494. return 0;
  495. }
  496. /* xxx FIX module selection missing */
  497. static int rfbi_enable_te(bool enable, unsigned line)
  498. {
  499. u32 l;
  500. DSSDBG("te %d line %d mode %d\n", enable, line, rfbi.te_mode);
  501. if (line > (1 << 11) - 1)
  502. return -EINVAL;
  503. l = rfbi_read_reg(RFBI_CONFIG(0));
  504. l &= ~(0x3 << 2);
  505. if (enable) {
  506. rfbi.te_enabled = 1;
  507. l |= rfbi.te_mode << 2;
  508. } else
  509. rfbi.te_enabled = 0;
  510. rfbi_write_reg(RFBI_CONFIG(0), l);
  511. rfbi_write_reg(RFBI_LINE_NUMBER, line);
  512. return 0;
  513. }
  514. static int rfbi_configure_bus(int rfbi_module, int bpp, int lines)
  515. {
  516. u32 l;
  517. int cycle1 = 0, cycle2 = 0, cycle3 = 0;
  518. enum omap_rfbi_cycleformat cycleformat;
  519. enum omap_rfbi_datatype datatype;
  520. enum omap_rfbi_parallelmode parallelmode;
  521. switch (bpp) {
  522. case 12:
  523. datatype = OMAP_DSS_RFBI_DATATYPE_12;
  524. break;
  525. case 16:
  526. datatype = OMAP_DSS_RFBI_DATATYPE_16;
  527. break;
  528. case 18:
  529. datatype = OMAP_DSS_RFBI_DATATYPE_18;
  530. break;
  531. case 24:
  532. datatype = OMAP_DSS_RFBI_DATATYPE_24;
  533. break;
  534. default:
  535. BUG();
  536. return 1;
  537. }
  538. rfbi.datatype = datatype;
  539. switch (lines) {
  540. case 8:
  541. parallelmode = OMAP_DSS_RFBI_PARALLELMODE_8;
  542. break;
  543. case 9:
  544. parallelmode = OMAP_DSS_RFBI_PARALLELMODE_9;
  545. break;
  546. case 12:
  547. parallelmode = OMAP_DSS_RFBI_PARALLELMODE_12;
  548. break;
  549. case 16:
  550. parallelmode = OMAP_DSS_RFBI_PARALLELMODE_16;
  551. break;
  552. default:
  553. BUG();
  554. return 1;
  555. }
  556. rfbi.parallelmode = parallelmode;
  557. if ((bpp % lines) == 0) {
  558. switch (bpp / lines) {
  559. case 1:
  560. cycleformat = OMAP_DSS_RFBI_CYCLEFORMAT_1_1;
  561. break;
  562. case 2:
  563. cycleformat = OMAP_DSS_RFBI_CYCLEFORMAT_2_1;
  564. break;
  565. case 3:
  566. cycleformat = OMAP_DSS_RFBI_CYCLEFORMAT_3_1;
  567. break;
  568. default:
  569. BUG();
  570. return 1;
  571. }
  572. } else if ((2 * bpp % lines) == 0) {
  573. if ((2 * bpp / lines) == 3)
  574. cycleformat = OMAP_DSS_RFBI_CYCLEFORMAT_3_2;
  575. else {
  576. BUG();
  577. return 1;
  578. }
  579. } else {
  580. BUG();
  581. return 1;
  582. }
  583. switch (cycleformat) {
  584. case OMAP_DSS_RFBI_CYCLEFORMAT_1_1:
  585. cycle1 = lines;
  586. break;
  587. case OMAP_DSS_RFBI_CYCLEFORMAT_2_1:
  588. cycle1 = lines;
  589. cycle2 = lines;
  590. break;
  591. case OMAP_DSS_RFBI_CYCLEFORMAT_3_1:
  592. cycle1 = lines;
  593. cycle2 = lines;
  594. cycle3 = lines;
  595. break;
  596. case OMAP_DSS_RFBI_CYCLEFORMAT_3_2:
  597. cycle1 = lines;
  598. cycle2 = (lines / 2) | ((lines / 2) << 16);
  599. cycle3 = (lines << 16);
  600. break;
  601. }
  602. REG_FLD_MOD(RFBI_CONTROL, 0, 3, 2); /* clear CS */
  603. l = 0;
  604. l |= FLD_VAL(parallelmode, 1, 0);
  605. l |= FLD_VAL(0, 3, 2); /* TRIGGERMODE: ITE */
  606. l |= FLD_VAL(0, 4, 4); /* TIMEGRANULARITY */
  607. l |= FLD_VAL(datatype, 6, 5);
  608. /* l |= FLD_VAL(2, 8, 7); */ /* L4FORMAT, 2pix/L4 */
  609. l |= FLD_VAL(0, 8, 7); /* L4FORMAT, 1pix/L4 */
  610. l |= FLD_VAL(cycleformat, 10, 9);
  611. l |= FLD_VAL(0, 12, 11); /* UNUSEDBITS */
  612. l |= FLD_VAL(0, 16, 16); /* A0POLARITY */
  613. l |= FLD_VAL(0, 17, 17); /* REPOLARITY */
  614. l |= FLD_VAL(0, 18, 18); /* WEPOLARITY */
  615. l |= FLD_VAL(0, 19, 19); /* CSPOLARITY */
  616. l |= FLD_VAL(1, 20, 20); /* TE_VSYNC_POLARITY */
  617. l |= FLD_VAL(1, 21, 21); /* HSYNCPOLARITY */
  618. rfbi_write_reg(RFBI_CONFIG(rfbi_module), l);
  619. rfbi_write_reg(RFBI_DATA_CYCLE1(rfbi_module), cycle1);
  620. rfbi_write_reg(RFBI_DATA_CYCLE2(rfbi_module), cycle2);
  621. rfbi_write_reg(RFBI_DATA_CYCLE3(rfbi_module), cycle3);
  622. l = rfbi_read_reg(RFBI_CONTROL);
  623. l = FLD_MOD(l, rfbi_module+1, 3, 2); /* Select CSx */
  624. l = FLD_MOD(l, 0, 1, 1); /* clear bypass */
  625. rfbi_write_reg(RFBI_CONTROL, l);
  626. DSSDBG("RFBI config: bpp %d, lines %d, cycles: 0x%x 0x%x 0x%x\n",
  627. bpp, lines, cycle1, cycle2, cycle3);
  628. return 0;
  629. }
  630. static int rfbi_configure(struct omap_dss_device *dssdev)
  631. {
  632. return rfbi_configure_bus(dssdev->phy.rfbi.channel, rfbi.pixel_size,
  633. rfbi.data_lines);
  634. }
  635. static int rfbi_update(struct omap_dss_device *dssdev, void (*callback)(void *),
  636. void *data)
  637. {
  638. return rfbi_transfer_area(dssdev, callback, data);
  639. }
  640. static void rfbi_set_size(struct omap_dss_device *dssdev, u16 w, u16 h)
  641. {
  642. rfbi.vm.hactive = w;
  643. rfbi.vm.vactive = h;
  644. }
  645. static void rfbi_set_pixel_size(struct omap_dss_device *dssdev, int pixel_size)
  646. {
  647. rfbi.pixel_size = pixel_size;
  648. }
  649. static void rfbi_set_data_lines(struct omap_dss_device *dssdev, int data_lines)
  650. {
  651. rfbi.data_lines = data_lines;
  652. }
  653. static void rfbi_set_interface_timings(struct omap_dss_device *dssdev,
  654. struct rfbi_timings *timings)
  655. {
  656. rfbi.intf_timings = *timings;
  657. }
  658. static void rfbi_dump_regs(struct seq_file *s)
  659. {
  660. #define DUMPREG(r) seq_printf(s, "%-35s %08x\n", #r, rfbi_read_reg(r))
  661. if (rfbi_runtime_get())
  662. return;
  663. DUMPREG(RFBI_REVISION);
  664. DUMPREG(RFBI_SYSCONFIG);
  665. DUMPREG(RFBI_SYSSTATUS);
  666. DUMPREG(RFBI_CONTROL);
  667. DUMPREG(RFBI_PIXEL_CNT);
  668. DUMPREG(RFBI_LINE_NUMBER);
  669. DUMPREG(RFBI_CMD);
  670. DUMPREG(RFBI_PARAM);
  671. DUMPREG(RFBI_DATA);
  672. DUMPREG(RFBI_READ);
  673. DUMPREG(RFBI_STATUS);
  674. DUMPREG(RFBI_CONFIG(0));
  675. DUMPREG(RFBI_ONOFF_TIME(0));
  676. DUMPREG(RFBI_CYCLE_TIME(0));
  677. DUMPREG(RFBI_DATA_CYCLE1(0));
  678. DUMPREG(RFBI_DATA_CYCLE2(0));
  679. DUMPREG(RFBI_DATA_CYCLE3(0));
  680. DUMPREG(RFBI_CONFIG(1));
  681. DUMPREG(RFBI_ONOFF_TIME(1));
  682. DUMPREG(RFBI_CYCLE_TIME(1));
  683. DUMPREG(RFBI_DATA_CYCLE1(1));
  684. DUMPREG(RFBI_DATA_CYCLE2(1));
  685. DUMPREG(RFBI_DATA_CYCLE3(1));
  686. DUMPREG(RFBI_VSYNC_WIDTH);
  687. DUMPREG(RFBI_HSYNC_WIDTH);
  688. rfbi_runtime_put();
  689. #undef DUMPREG
  690. }
  691. static void rfbi_config_lcd_manager(struct omap_dss_device *dssdev)
  692. {
  693. struct omap_overlay_manager *mgr = rfbi.output.manager;
  694. struct dss_lcd_mgr_config mgr_config;
  695. mgr_config.io_pad_mode = DSS_IO_PAD_MODE_RFBI;
  696. mgr_config.stallmode = true;
  697. /* Do we need fifohandcheck for RFBI? */
  698. mgr_config.fifohandcheck = false;
  699. mgr_config.video_port_width = rfbi.pixel_size;
  700. mgr_config.lcden_sig_polarity = 0;
  701. dss_mgr_set_lcd_config(mgr, &mgr_config);
  702. /*
  703. * Set rfbi.timings with default values, the hactive and vactive fields
  704. * are expected to be already configured by the panel driver via
  705. * omapdss_rfbi_set_size()
  706. */
  707. rfbi.vm.hsync_len = 1;
  708. rfbi.vm.hfront_porch = 1;
  709. rfbi.vm.hback_porch = 1;
  710. rfbi.vm.vsync_len = 1;
  711. rfbi.vm.vfront_porch = 0;
  712. rfbi.vm.vback_porch = 0;
  713. rfbi.vm.flags &= ~DISPLAY_FLAGS_INTERLACED;
  714. rfbi.vm.flags &= ~DISPLAY_FLAGS_HSYNC_LOW;
  715. rfbi.vm.flags |= DISPLAY_FLAGS_HSYNC_HIGH;
  716. rfbi.vm.flags &= ~DISPLAY_FLAGS_VSYNC_LOW;
  717. rfbi.vm.flags |= DISPLAY_FLAGS_VSYNC_HIGH;
  718. rfbi.vm.flags &= ~DISPLAY_FLAGS_PIXDATA_NEGEDGE;
  719. rfbi.vm.flags |= DISPLAY_FLAGS_PIXDATA_POSEDGE;
  720. rfbi.vm.flags &= ~DISPLAY_FLAGS_DE_LOW;
  721. rfbi.vm.flags |= DISPLAY_FLAGS_DE_HIGH;
  722. rfbi.vm.flags &= ~DISPLAY_FLAGS_SYNC_POSEDGE;
  723. rfbi.vm.flags |= DISPLAY_FLAGS_SYNC_NEGEDGE;
  724. dss_mgr_set_timings(mgr, &rfbi.vm);
  725. }
  726. static int rfbi_display_enable(struct omap_dss_device *dssdev)
  727. {
  728. struct omap_dss_device *out = &rfbi.output;
  729. int r;
  730. if (!out->dispc_channel_connected) {
  731. DSSERR("failed to enable display: no output/manager\n");
  732. return -ENODEV;
  733. }
  734. r = rfbi_runtime_get();
  735. if (r)
  736. return r;
  737. r = dss_mgr_register_framedone_handler(out->manager,
  738. framedone_callback, NULL);
  739. if (r) {
  740. DSSERR("can't get FRAMEDONE irq\n");
  741. goto err1;
  742. }
  743. rfbi_config_lcd_manager(dssdev);
  744. rfbi_configure_bus(dssdev->phy.rfbi.channel, rfbi.pixel_size,
  745. rfbi.data_lines);
  746. rfbi_set_timings(dssdev->phy.rfbi.channel, &rfbi.intf_timings);
  747. return 0;
  748. err1:
  749. rfbi_runtime_put();
  750. return r;
  751. }
  752. static void rfbi_display_disable(struct omap_dss_device *dssdev)
  753. {
  754. struct omap_dss_device *out = &rfbi.output;
  755. dss_mgr_unregister_framedone_handler(out->manager,
  756. framedone_callback, NULL);
  757. rfbi_runtime_put();
  758. }
  759. static int rfbi_init_display(struct omap_dss_device *dssdev)
  760. {
  761. rfbi.dssdev[dssdev->phy.rfbi.channel] = dssdev;
  762. return 0;
  763. }
  764. static void rfbi_init_output(struct platform_device *pdev)
  765. {
  766. struct omap_dss_device *out = &rfbi.output;
  767. out->dev = &pdev->dev;
  768. out->id = OMAP_DSS_OUTPUT_DBI;
  769. out->output_type = OMAP_DISPLAY_TYPE_DBI;
  770. out->name = "rfbi.0";
  771. out->dispc_channel = OMAP_DSS_CHANNEL_LCD;
  772. out->owner = THIS_MODULE;
  773. omapdss_register_output(out);
  774. }
  775. static void rfbi_uninit_output(struct platform_device *pdev)
  776. {
  777. struct omap_dss_device *out = &rfbi.output;
  778. omapdss_unregister_output(out);
  779. }
  780. /* RFBI HW IP initialisation */
  781. static int rfbi_bind(struct device *dev, struct device *master, void *data)
  782. {
  783. struct platform_device *pdev = to_platform_device(dev);
  784. u32 rev;
  785. struct resource *rfbi_mem;
  786. struct clk *clk;
  787. int r;
  788. rfbi.pdev = pdev;
  789. sema_init(&rfbi.bus_lock, 1);
  790. rfbi_mem = platform_get_resource(rfbi.pdev, IORESOURCE_MEM, 0);
  791. if (!rfbi_mem) {
  792. DSSERR("can't get IORESOURCE_MEM RFBI\n");
  793. return -EINVAL;
  794. }
  795. rfbi.base = devm_ioremap(&pdev->dev, rfbi_mem->start,
  796. resource_size(rfbi_mem));
  797. if (!rfbi.base) {
  798. DSSERR("can't ioremap RFBI\n");
  799. return -ENOMEM;
  800. }
  801. clk = clk_get(&pdev->dev, "ick");
  802. if (IS_ERR(clk)) {
  803. DSSERR("can't get ick\n");
  804. return PTR_ERR(clk);
  805. }
  806. rfbi.l4_khz = clk_get_rate(clk) / 1000;
  807. clk_put(clk);
  808. pm_runtime_enable(&pdev->dev);
  809. r = rfbi_runtime_get();
  810. if (r)
  811. goto err_runtime_get;
  812. msleep(10);
  813. rev = rfbi_read_reg(RFBI_REVISION);
  814. dev_dbg(&pdev->dev, "OMAP RFBI rev %d.%d\n",
  815. FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
  816. rfbi_runtime_put();
  817. dss_debugfs_create_file("rfbi", rfbi_dump_regs);
  818. rfbi_init_output(pdev);
  819. return 0;
  820. err_runtime_get:
  821. pm_runtime_disable(&pdev->dev);
  822. return r;
  823. }
  824. static void rfbi_unbind(struct device *dev, struct device *master, void *data)
  825. {
  826. struct platform_device *pdev = to_platform_device(dev);
  827. rfbi_uninit_output(pdev);
  828. pm_runtime_disable(&pdev->dev);
  829. return 0;
  830. }
  831. static const struct component_ops rfbi_component_ops = {
  832. .bind = rfbi_bind,
  833. .unbind = rfbi_unbind,
  834. };
  835. static int rfbi_probe(struct platform_device *pdev)
  836. {
  837. return component_add(&pdev->dev, &rfbi_component_ops);
  838. }
  839. static int rfbi_remove(struct platform_device *pdev)
  840. {
  841. component_del(&pdev->dev, &rfbi_component_ops);
  842. return 0;
  843. }
  844. static int rfbi_runtime_suspend(struct device *dev)
  845. {
  846. dispc_runtime_put();
  847. return 0;
  848. }
  849. static int rfbi_runtime_resume(struct device *dev)
  850. {
  851. int r;
  852. r = dispc_runtime_get();
  853. if (r < 0)
  854. return r;
  855. return 0;
  856. }
  857. static const struct dev_pm_ops rfbi_pm_ops = {
  858. .runtime_suspend = rfbi_runtime_suspend,
  859. .runtime_resume = rfbi_runtime_resume,
  860. };
  861. static struct platform_driver omap_rfbihw_driver = {
  862. .probe = rfbi_probe,
  863. .remove = rfbi_remove,
  864. .driver = {
  865. .name = "omapdss_rfbi",
  866. .pm = &rfbi_pm_ops,
  867. .suppress_bind_attrs = true,
  868. },
  869. };
  870. int __init rfbi_init_platform_driver(void)
  871. {
  872. return platform_driver_register(&omap_rfbihw_driver);
  873. }
  874. void rfbi_uninit_platform_driver(void)
  875. {
  876. platform_driver_unregister(&omap_rfbihw_driver);
  877. }