rfbi.c 23 KB

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