rfbi.c 24 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078
  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 <video/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 omap_video_timings timings;
  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.timings.x_res;
  264. u16 height = rfbi.timings.y_res;
  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.timings);
  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.timings.x_res = w;
  643. rfbi.timings.y_res = 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 x_res and y_res fields
  704. * are expected to be already configured by the panel driver via
  705. * omapdss_rfbi_set_size()
  706. */
  707. rfbi.timings.hsw = 1;
  708. rfbi.timings.hfp = 1;
  709. rfbi.timings.hbp = 1;
  710. rfbi.timings.vsw = 1;
  711. rfbi.timings.vfp = 0;
  712. rfbi.timings.vbp = 0;
  713. rfbi.timings.interlace = false;
  714. rfbi.timings.hsync_level = OMAPDSS_SIG_ACTIVE_HIGH;
  715. rfbi.timings.vsync_level = OMAPDSS_SIG_ACTIVE_HIGH;
  716. rfbi.timings.data_pclk_edge = OMAPDSS_DRIVE_SIG_RISING_EDGE;
  717. rfbi.timings.de_level = OMAPDSS_SIG_ACTIVE_HIGH;
  718. rfbi.timings.sync_pclk_edge = OMAPDSS_DRIVE_SIG_FALLING_EDGE;
  719. dss_mgr_set_timings(mgr, &rfbi.timings);
  720. }
  721. static int rfbi_display_enable(struct omap_dss_device *dssdev)
  722. {
  723. struct omap_dss_device *out = &rfbi.output;
  724. int r;
  725. if (!out->dispc_channel_connected) {
  726. DSSERR("failed to enable display: no output/manager\n");
  727. return -ENODEV;
  728. }
  729. r = rfbi_runtime_get();
  730. if (r)
  731. return r;
  732. r = dss_mgr_register_framedone_handler(out->manager,
  733. framedone_callback, NULL);
  734. if (r) {
  735. DSSERR("can't get FRAMEDONE irq\n");
  736. goto err1;
  737. }
  738. rfbi_config_lcd_manager(dssdev);
  739. rfbi_configure_bus(dssdev->phy.rfbi.channel, rfbi.pixel_size,
  740. rfbi.data_lines);
  741. rfbi_set_timings(dssdev->phy.rfbi.channel, &rfbi.intf_timings);
  742. return 0;
  743. err1:
  744. rfbi_runtime_put();
  745. return r;
  746. }
  747. static void rfbi_display_disable(struct omap_dss_device *dssdev)
  748. {
  749. struct omap_dss_device *out = &rfbi.output;
  750. dss_mgr_unregister_framedone_handler(out->manager,
  751. framedone_callback, NULL);
  752. rfbi_runtime_put();
  753. }
  754. static int rfbi_init_display(struct omap_dss_device *dssdev)
  755. {
  756. rfbi.dssdev[dssdev->phy.rfbi.channel] = dssdev;
  757. return 0;
  758. }
  759. static void rfbi_init_output(struct platform_device *pdev)
  760. {
  761. struct omap_dss_device *out = &rfbi.output;
  762. out->dev = &pdev->dev;
  763. out->id = OMAP_DSS_OUTPUT_DBI;
  764. out->output_type = OMAP_DISPLAY_TYPE_DBI;
  765. out->name = "rfbi.0";
  766. out->dispc_channel = OMAP_DSS_CHANNEL_LCD;
  767. out->owner = THIS_MODULE;
  768. omapdss_register_output(out);
  769. }
  770. static void rfbi_uninit_output(struct platform_device *pdev)
  771. {
  772. struct omap_dss_device *out = &rfbi.output;
  773. omapdss_unregister_output(out);
  774. }
  775. /* RFBI HW IP initialisation */
  776. static int rfbi_bind(struct device *dev, struct device *master, void *data)
  777. {
  778. struct platform_device *pdev = to_platform_device(dev);
  779. u32 rev;
  780. struct resource *rfbi_mem;
  781. struct clk *clk;
  782. int r;
  783. rfbi.pdev = pdev;
  784. sema_init(&rfbi.bus_lock, 1);
  785. rfbi_mem = platform_get_resource(rfbi.pdev, IORESOURCE_MEM, 0);
  786. if (!rfbi_mem) {
  787. DSSERR("can't get IORESOURCE_MEM RFBI\n");
  788. return -EINVAL;
  789. }
  790. rfbi.base = devm_ioremap(&pdev->dev, rfbi_mem->start,
  791. resource_size(rfbi_mem));
  792. if (!rfbi.base) {
  793. DSSERR("can't ioremap RFBI\n");
  794. return -ENOMEM;
  795. }
  796. clk = clk_get(&pdev->dev, "ick");
  797. if (IS_ERR(clk)) {
  798. DSSERR("can't get ick\n");
  799. return PTR_ERR(clk);
  800. }
  801. rfbi.l4_khz = clk_get_rate(clk) / 1000;
  802. clk_put(clk);
  803. pm_runtime_enable(&pdev->dev);
  804. r = rfbi_runtime_get();
  805. if (r)
  806. goto err_runtime_get;
  807. msleep(10);
  808. rev = rfbi_read_reg(RFBI_REVISION);
  809. dev_dbg(&pdev->dev, "OMAP RFBI rev %d.%d\n",
  810. FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
  811. rfbi_runtime_put();
  812. dss_debugfs_create_file("rfbi", rfbi_dump_regs);
  813. rfbi_init_output(pdev);
  814. return 0;
  815. err_runtime_get:
  816. pm_runtime_disable(&pdev->dev);
  817. return r;
  818. }
  819. static void rfbi_unbind(struct device *dev, struct device *master, void *data)
  820. {
  821. struct platform_device *pdev = to_platform_device(dev);
  822. rfbi_uninit_output(pdev);
  823. pm_runtime_disable(&pdev->dev);
  824. return 0;
  825. }
  826. static const struct component_ops rfbi_component_ops = {
  827. .bind = rfbi_bind,
  828. .unbind = rfbi_unbind,
  829. };
  830. static int rfbi_probe(struct platform_device *pdev)
  831. {
  832. return component_add(&pdev->dev, &rfbi_component_ops);
  833. }
  834. static int rfbi_remove(struct platform_device *pdev)
  835. {
  836. component_del(&pdev->dev, &rfbi_component_ops);
  837. return 0;
  838. }
  839. static int rfbi_runtime_suspend(struct device *dev)
  840. {
  841. dispc_runtime_put();
  842. return 0;
  843. }
  844. static int rfbi_runtime_resume(struct device *dev)
  845. {
  846. int r;
  847. r = dispc_runtime_get();
  848. if (r < 0)
  849. return r;
  850. return 0;
  851. }
  852. static const struct dev_pm_ops rfbi_pm_ops = {
  853. .runtime_suspend = rfbi_runtime_suspend,
  854. .runtime_resume = rfbi_runtime_resume,
  855. };
  856. static struct platform_driver omap_rfbihw_driver = {
  857. .probe = rfbi_probe,
  858. .remove = rfbi_remove,
  859. .driver = {
  860. .name = "omapdss_rfbi",
  861. .pm = &rfbi_pm_ops,
  862. .suppress_bind_attrs = true,
  863. },
  864. };
  865. int __init rfbi_init_platform_driver(void)
  866. {
  867. return platform_driver_register(&omap_rfbihw_driver);
  868. }
  869. void rfbi_uninit_platform_driver(void)
  870. {
  871. platform_driver_unregister(&omap_rfbihw_driver);
  872. }