rfbi.c 23 KB

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