fsl-diu-fb.c 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754
  1. /*
  2. * Copyright 2008 Freescale Semiconductor, Inc. All Rights Reserved.
  3. *
  4. * Freescale DIU Frame Buffer device driver
  5. *
  6. * Authors: Hongjun Chen <hong-jun.chen@freescale.com>
  7. * Paul Widmer <paul.widmer@freescale.com>
  8. * Srikanth Srinivasan <srikanth.srinivasan@freescale.com>
  9. * York Sun <yorksun@freescale.com>
  10. *
  11. * Based on imxfb.c Copyright (C) 2004 S.Hauer, Pengutronix
  12. *
  13. * This program is free software; you can redistribute it and/or modify it
  14. * under the terms of the GNU General Public License as published by the
  15. * Free Software Foundation; either version 2 of the License, or (at your
  16. * option) any later version.
  17. *
  18. */
  19. #include <linux/module.h>
  20. #include <linux/kernel.h>
  21. #include <linux/errno.h>
  22. #include <linux/string.h>
  23. #include <linux/slab.h>
  24. #include <linux/fb.h>
  25. #include <linux/init.h>
  26. #include <linux/dma-mapping.h>
  27. #include <linux/platform_device.h>
  28. #include <linux/interrupt.h>
  29. #include <linux/clk.h>
  30. #include <linux/uaccess.h>
  31. #include <linux/vmalloc.h>
  32. #include <linux/of_platform.h>
  33. #include <sysdev/fsl_soc.h>
  34. #include <linux/fsl-diu-fb.h>
  35. /*
  36. * These parameters give default parameters
  37. * for video output 1024x768,
  38. * FIXME - change timing to proper amounts
  39. * hsync 31.5kHz, vsync 60Hz
  40. */
  41. static struct fb_videomode __devinitdata fsl_diu_default_mode = {
  42. .refresh = 60,
  43. .xres = 1024,
  44. .yres = 768,
  45. .pixclock = 15385,
  46. .left_margin = 160,
  47. .right_margin = 24,
  48. .upper_margin = 29,
  49. .lower_margin = 3,
  50. .hsync_len = 136,
  51. .vsync_len = 6,
  52. .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  53. .vmode = FB_VMODE_NONINTERLACED
  54. };
  55. static struct fb_videomode __devinitdata fsl_diu_mode_db[] = {
  56. {
  57. .name = "1024x768-60",
  58. .refresh = 60,
  59. .xres = 1024,
  60. .yres = 768,
  61. .pixclock = 15385,
  62. .left_margin = 160,
  63. .right_margin = 24,
  64. .upper_margin = 29,
  65. .lower_margin = 3,
  66. .hsync_len = 136,
  67. .vsync_len = 6,
  68. .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  69. .vmode = FB_VMODE_NONINTERLACED
  70. },
  71. {
  72. .name = "1024x768-70",
  73. .refresh = 70,
  74. .xres = 1024,
  75. .yres = 768,
  76. .pixclock = 16886,
  77. .left_margin = 3,
  78. .right_margin = 3,
  79. .upper_margin = 2,
  80. .lower_margin = 2,
  81. .hsync_len = 40,
  82. .vsync_len = 18,
  83. .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  84. .vmode = FB_VMODE_NONINTERLACED
  85. },
  86. {
  87. .name = "1024x768-75",
  88. .refresh = 75,
  89. .xres = 1024,
  90. .yres = 768,
  91. .pixclock = 15009,
  92. .left_margin = 3,
  93. .right_margin = 3,
  94. .upper_margin = 2,
  95. .lower_margin = 2,
  96. .hsync_len = 80,
  97. .vsync_len = 32,
  98. .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  99. .vmode = FB_VMODE_NONINTERLACED
  100. },
  101. {
  102. .name = "1280x1024-60",
  103. .refresh = 60,
  104. .xres = 1280,
  105. .yres = 1024,
  106. .pixclock = 9375,
  107. .left_margin = 38,
  108. .right_margin = 128,
  109. .upper_margin = 2,
  110. .lower_margin = 7,
  111. .hsync_len = 216,
  112. .vsync_len = 37,
  113. .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  114. .vmode = FB_VMODE_NONINTERLACED
  115. },
  116. {
  117. .name = "1280x1024-70",
  118. .refresh = 70,
  119. .xres = 1280,
  120. .yres = 1024,
  121. .pixclock = 9380,
  122. .left_margin = 6,
  123. .right_margin = 6,
  124. .upper_margin = 4,
  125. .lower_margin = 4,
  126. .hsync_len = 60,
  127. .vsync_len = 94,
  128. .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  129. .vmode = FB_VMODE_NONINTERLACED
  130. },
  131. {
  132. .name = "1280x1024-75",
  133. .refresh = 75,
  134. .xres = 1280,
  135. .yres = 1024,
  136. .pixclock = 9380,
  137. .left_margin = 6,
  138. .right_margin = 6,
  139. .upper_margin = 4,
  140. .lower_margin = 4,
  141. .hsync_len = 60,
  142. .vsync_len = 15,
  143. .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  144. .vmode = FB_VMODE_NONINTERLACED
  145. },
  146. {
  147. .name = "320x240", /* for AOI only */
  148. .refresh = 60,
  149. .xres = 320,
  150. .yres = 240,
  151. .pixclock = 15385,
  152. .left_margin = 0,
  153. .right_margin = 0,
  154. .upper_margin = 0,
  155. .lower_margin = 0,
  156. .hsync_len = 0,
  157. .vsync_len = 0,
  158. .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  159. .vmode = FB_VMODE_NONINTERLACED
  160. },
  161. {
  162. .name = "1280x480-60",
  163. .refresh = 60,
  164. .xres = 1280,
  165. .yres = 480,
  166. .pixclock = 18939,
  167. .left_margin = 353,
  168. .right_margin = 47,
  169. .upper_margin = 39,
  170. .lower_margin = 4,
  171. .hsync_len = 8,
  172. .vsync_len = 2,
  173. .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  174. .vmode = FB_VMODE_NONINTERLACED
  175. },
  176. };
  177. static char *fb_mode = "1024x768-32@60";
  178. static unsigned long default_bpp = 32;
  179. static int monitor_port;
  180. #if defined(CONFIG_NOT_COHERENT_CACHE)
  181. static u8 *coherence_data;
  182. static size_t coherence_data_size;
  183. static unsigned int d_cache_line_size;
  184. #endif
  185. static DEFINE_SPINLOCK(diu_lock);
  186. struct fsl_diu_data {
  187. struct fb_info *fsl_diu_info[FSL_AOI_NUM - 1];
  188. /*FSL_AOI_NUM has one dummy AOI */
  189. struct device_attribute dev_attr;
  190. struct diu_ad *dummy_ad;
  191. void *dummy_aoi_virt;
  192. unsigned int irq;
  193. int fb_enabled;
  194. int monitor_port;
  195. };
  196. struct mfb_info {
  197. int index;
  198. int type;
  199. char *id;
  200. int registered;
  201. int blank;
  202. unsigned long pseudo_palette[16];
  203. struct diu_ad *ad;
  204. int cursor_reset;
  205. unsigned char g_alpha;
  206. unsigned int count;
  207. int x_aoi_d; /* aoi display x offset to physical screen */
  208. int y_aoi_d; /* aoi display y offset to physical screen */
  209. struct fsl_diu_data *parent;
  210. };
  211. static struct mfb_info mfb_template[] = {
  212. { /* AOI 0 for plane 0 */
  213. .index = 0,
  214. .type = MFB_TYPE_OUTPUT,
  215. .id = "Panel0",
  216. .registered = 0,
  217. .count = 0,
  218. .x_aoi_d = 0,
  219. .y_aoi_d = 0,
  220. },
  221. { /* AOI 0 for plane 1 */
  222. .index = 1,
  223. .type = MFB_TYPE_OUTPUT,
  224. .id = "Panel1 AOI0",
  225. .registered = 0,
  226. .g_alpha = 0xff,
  227. .count = 0,
  228. .x_aoi_d = 0,
  229. .y_aoi_d = 0,
  230. },
  231. { /* AOI 1 for plane 1 */
  232. .index = 2,
  233. .type = MFB_TYPE_OUTPUT,
  234. .id = "Panel1 AOI1",
  235. .registered = 0,
  236. .g_alpha = 0xff,
  237. .count = 0,
  238. .x_aoi_d = 0,
  239. .y_aoi_d = 480,
  240. },
  241. { /* AOI 0 for plane 2 */
  242. .index = 3,
  243. .type = MFB_TYPE_OUTPUT,
  244. .id = "Panel2 AOI0",
  245. .registered = 0,
  246. .g_alpha = 0xff,
  247. .count = 0,
  248. .x_aoi_d = 640,
  249. .y_aoi_d = 0,
  250. },
  251. { /* AOI 1 for plane 2 */
  252. .index = 4,
  253. .type = MFB_TYPE_OUTPUT,
  254. .id = "Panel2 AOI1",
  255. .registered = 0,
  256. .g_alpha = 0xff,
  257. .count = 0,
  258. .x_aoi_d = 640,
  259. .y_aoi_d = 480,
  260. },
  261. };
  262. static struct diu_hw dr = {
  263. .mode = MFB_MODE1,
  264. .reg_lock = __SPIN_LOCK_UNLOCKED(diu_hw.reg_lock),
  265. };
  266. static struct diu_pool pool;
  267. /**
  268. * fsl_diu_alloc - allocate memory for the DIU
  269. * @size: number of bytes to allocate
  270. * @param: returned physical address of memory
  271. *
  272. * This function allocates a physically-contiguous block of memory.
  273. */
  274. static void *fsl_diu_alloc(size_t size, phys_addr_t *phys)
  275. {
  276. void *virt;
  277. pr_debug("size=%zu\n", size);
  278. virt = alloc_pages_exact(size, GFP_DMA | __GFP_ZERO);
  279. if (virt) {
  280. *phys = virt_to_phys(virt);
  281. pr_debug("virt=%p phys=%llx\n", virt,
  282. (unsigned long long)*phys);
  283. }
  284. return virt;
  285. }
  286. /**
  287. * fsl_diu_free - release DIU memory
  288. * @virt: pointer returned by fsl_diu_alloc()
  289. * @size: number of bytes allocated by fsl_diu_alloc()
  290. *
  291. * This function releases memory allocated by fsl_diu_alloc().
  292. */
  293. static void fsl_diu_free(void *virt, size_t size)
  294. {
  295. pr_debug("virt=%p size=%zu\n", virt, size);
  296. if (virt && size)
  297. free_pages_exact(virt, size);
  298. }
  299. /*
  300. * Workaround for failed writing desc register of planes.
  301. * Needed with MPC5121 DIU rev 2.0 silicon.
  302. */
  303. void wr_reg_wa(u32 *reg, u32 val)
  304. {
  305. do {
  306. out_be32(reg, val);
  307. } while (in_be32(reg) != val);
  308. }
  309. static int fsl_diu_enable_panel(struct fb_info *info)
  310. {
  311. struct mfb_info *pmfbi, *cmfbi, *mfbi = info->par;
  312. struct diu *hw = dr.diu_reg;
  313. struct diu_ad *ad = mfbi->ad;
  314. struct fsl_diu_data *machine_data = mfbi->parent;
  315. int res = 0;
  316. pr_debug("enable_panel index %d\n", mfbi->index);
  317. if (mfbi->type != MFB_TYPE_OFF) {
  318. switch (mfbi->index) {
  319. case 0: /* plane 0 */
  320. if (hw->desc[0] != ad->paddr)
  321. wr_reg_wa(&hw->desc[0], ad->paddr);
  322. break;
  323. case 1: /* plane 1 AOI 0 */
  324. cmfbi = machine_data->fsl_diu_info[2]->par;
  325. if (hw->desc[1] != ad->paddr) { /* AOI0 closed */
  326. if (cmfbi->count > 0) /* AOI1 open */
  327. ad->next_ad =
  328. cpu_to_le32(cmfbi->ad->paddr);
  329. else
  330. ad->next_ad = 0;
  331. wr_reg_wa(&hw->desc[1], ad->paddr);
  332. }
  333. break;
  334. case 3: /* plane 2 AOI 0 */
  335. cmfbi = machine_data->fsl_diu_info[4]->par;
  336. if (hw->desc[2] != ad->paddr) { /* AOI0 closed */
  337. if (cmfbi->count > 0) /* AOI1 open */
  338. ad->next_ad =
  339. cpu_to_le32(cmfbi->ad->paddr);
  340. else
  341. ad->next_ad = 0;
  342. wr_reg_wa(&hw->desc[2], ad->paddr);
  343. }
  344. break;
  345. case 2: /* plane 1 AOI 1 */
  346. pmfbi = machine_data->fsl_diu_info[1]->par;
  347. ad->next_ad = 0;
  348. if (hw->desc[1] == machine_data->dummy_ad->paddr)
  349. wr_reg_wa(&hw->desc[1], ad->paddr);
  350. else /* AOI0 open */
  351. pmfbi->ad->next_ad = cpu_to_le32(ad->paddr);
  352. break;
  353. case 4: /* plane 2 AOI 1 */
  354. pmfbi = machine_data->fsl_diu_info[3]->par;
  355. ad->next_ad = 0;
  356. if (hw->desc[2] == machine_data->dummy_ad->paddr)
  357. wr_reg_wa(&hw->desc[2], ad->paddr);
  358. else /* AOI0 was open */
  359. pmfbi->ad->next_ad = cpu_to_le32(ad->paddr);
  360. break;
  361. default:
  362. res = -EINVAL;
  363. break;
  364. }
  365. } else
  366. res = -EINVAL;
  367. return res;
  368. }
  369. static int fsl_diu_disable_panel(struct fb_info *info)
  370. {
  371. struct mfb_info *pmfbi, *cmfbi, *mfbi = info->par;
  372. struct diu *hw = dr.diu_reg;
  373. struct diu_ad *ad = mfbi->ad;
  374. struct fsl_diu_data *machine_data = mfbi->parent;
  375. int res = 0;
  376. switch (mfbi->index) {
  377. case 0: /* plane 0 */
  378. if (hw->desc[0] != machine_data->dummy_ad->paddr)
  379. wr_reg_wa(&hw->desc[0], machine_data->dummy_ad->paddr);
  380. break;
  381. case 1: /* plane 1 AOI 0 */
  382. cmfbi = machine_data->fsl_diu_info[2]->par;
  383. if (cmfbi->count > 0) /* AOI1 is open */
  384. wr_reg_wa(&hw->desc[1], cmfbi->ad->paddr);
  385. /* move AOI1 to the first */
  386. else /* AOI1 was closed */
  387. wr_reg_wa(&hw->desc[1], machine_data->dummy_ad->paddr);
  388. /* close AOI 0 */
  389. break;
  390. case 3: /* plane 2 AOI 0 */
  391. cmfbi = machine_data->fsl_diu_info[4]->par;
  392. if (cmfbi->count > 0) /* AOI1 is open */
  393. wr_reg_wa(&hw->desc[2], cmfbi->ad->paddr);
  394. /* move AOI1 to the first */
  395. else /* AOI1 was closed */
  396. wr_reg_wa(&hw->desc[2], machine_data->dummy_ad->paddr);
  397. /* close AOI 0 */
  398. break;
  399. case 2: /* plane 1 AOI 1 */
  400. pmfbi = machine_data->fsl_diu_info[1]->par;
  401. if (hw->desc[1] != ad->paddr) {
  402. /* AOI1 is not the first in the chain */
  403. if (pmfbi->count > 0)
  404. /* AOI0 is open, must be the first */
  405. pmfbi->ad->next_ad = 0;
  406. } else /* AOI1 is the first in the chain */
  407. wr_reg_wa(&hw->desc[1], machine_data->dummy_ad->paddr);
  408. /* close AOI 1 */
  409. break;
  410. case 4: /* plane 2 AOI 1 */
  411. pmfbi = machine_data->fsl_diu_info[3]->par;
  412. if (hw->desc[2] != ad->paddr) {
  413. /* AOI1 is not the first in the chain */
  414. if (pmfbi->count > 0)
  415. /* AOI0 is open, must be the first */
  416. pmfbi->ad->next_ad = 0;
  417. } else /* AOI1 is the first in the chain */
  418. wr_reg_wa(&hw->desc[2], machine_data->dummy_ad->paddr);
  419. /* close AOI 1 */
  420. break;
  421. default:
  422. res = -EINVAL;
  423. break;
  424. }
  425. return res;
  426. }
  427. static void enable_lcdc(struct fb_info *info)
  428. {
  429. struct diu *hw = dr.diu_reg;
  430. struct mfb_info *mfbi = info->par;
  431. struct fsl_diu_data *machine_data = mfbi->parent;
  432. if (!machine_data->fb_enabled) {
  433. out_be32(&hw->diu_mode, dr.mode);
  434. machine_data->fb_enabled++;
  435. }
  436. }
  437. static void disable_lcdc(struct fb_info *info)
  438. {
  439. struct diu *hw = dr.diu_reg;
  440. struct mfb_info *mfbi = info->par;
  441. struct fsl_diu_data *machine_data = mfbi->parent;
  442. if (machine_data->fb_enabled) {
  443. out_be32(&hw->diu_mode, 0);
  444. machine_data->fb_enabled = 0;
  445. }
  446. }
  447. static void adjust_aoi_size_position(struct fb_var_screeninfo *var,
  448. struct fb_info *info)
  449. {
  450. struct mfb_info *lower_aoi_mfbi, *upper_aoi_mfbi, *mfbi = info->par;
  451. struct fsl_diu_data *machine_data = mfbi->parent;
  452. int available_height, upper_aoi_bottom, index = mfbi->index;
  453. int lower_aoi_is_open, upper_aoi_is_open;
  454. __u32 base_plane_width, base_plane_height, upper_aoi_height;
  455. base_plane_width = machine_data->fsl_diu_info[0]->var.xres;
  456. base_plane_height = machine_data->fsl_diu_info[0]->var.yres;
  457. if (mfbi->x_aoi_d < 0)
  458. mfbi->x_aoi_d = 0;
  459. if (mfbi->y_aoi_d < 0)
  460. mfbi->y_aoi_d = 0;
  461. switch (index) {
  462. case 0:
  463. if (mfbi->x_aoi_d != 0)
  464. mfbi->x_aoi_d = 0;
  465. if (mfbi->y_aoi_d != 0)
  466. mfbi->y_aoi_d = 0;
  467. break;
  468. case 1: /* AOI 0 */
  469. case 3:
  470. lower_aoi_mfbi = machine_data->fsl_diu_info[index+1]->par;
  471. lower_aoi_is_open = lower_aoi_mfbi->count > 0 ? 1 : 0;
  472. if (var->xres > base_plane_width)
  473. var->xres = base_plane_width;
  474. if ((mfbi->x_aoi_d + var->xres) > base_plane_width)
  475. mfbi->x_aoi_d = base_plane_width - var->xres;
  476. if (lower_aoi_is_open)
  477. available_height = lower_aoi_mfbi->y_aoi_d;
  478. else
  479. available_height = base_plane_height;
  480. if (var->yres > available_height)
  481. var->yres = available_height;
  482. if ((mfbi->y_aoi_d + var->yres) > available_height)
  483. mfbi->y_aoi_d = available_height - var->yres;
  484. break;
  485. case 2: /* AOI 1 */
  486. case 4:
  487. upper_aoi_mfbi = machine_data->fsl_diu_info[index-1]->par;
  488. upper_aoi_height =
  489. machine_data->fsl_diu_info[index-1]->var.yres;
  490. upper_aoi_bottom = upper_aoi_mfbi->y_aoi_d + upper_aoi_height;
  491. upper_aoi_is_open = upper_aoi_mfbi->count > 0 ? 1 : 0;
  492. if (var->xres > base_plane_width)
  493. var->xres = base_plane_width;
  494. if ((mfbi->x_aoi_d + var->xres) > base_plane_width)
  495. mfbi->x_aoi_d = base_plane_width - var->xres;
  496. if (mfbi->y_aoi_d < 0)
  497. mfbi->y_aoi_d = 0;
  498. if (upper_aoi_is_open) {
  499. if (mfbi->y_aoi_d < upper_aoi_bottom)
  500. mfbi->y_aoi_d = upper_aoi_bottom;
  501. available_height = base_plane_height
  502. - upper_aoi_bottom;
  503. } else
  504. available_height = base_plane_height;
  505. if (var->yres > available_height)
  506. var->yres = available_height;
  507. if ((mfbi->y_aoi_d + var->yres) > base_plane_height)
  508. mfbi->y_aoi_d = base_plane_height - var->yres;
  509. break;
  510. }
  511. }
  512. /*
  513. * Checks to see if the hardware supports the state requested by var passed
  514. * in. This function does not alter the hardware state! If the var passed in
  515. * is slightly off by what the hardware can support then we alter the var
  516. * PASSED in to what we can do. If the hardware doesn't support mode change
  517. * a -EINVAL will be returned by the upper layers.
  518. */
  519. static int fsl_diu_check_var(struct fb_var_screeninfo *var,
  520. struct fb_info *info)
  521. {
  522. unsigned long htotal, vtotal;
  523. pr_debug("check_var xres: %d\n", var->xres);
  524. pr_debug("check_var yres: %d\n", var->yres);
  525. if (var->xres_virtual < var->xres)
  526. var->xres_virtual = var->xres;
  527. if (var->yres_virtual < var->yres)
  528. var->yres_virtual = var->yres;
  529. if (var->xoffset < 0)
  530. var->xoffset = 0;
  531. if (var->yoffset < 0)
  532. var->yoffset = 0;
  533. if (var->xoffset + info->var.xres > info->var.xres_virtual)
  534. var->xoffset = info->var.xres_virtual - info->var.xres;
  535. if (var->yoffset + info->var.yres > info->var.yres_virtual)
  536. var->yoffset = info->var.yres_virtual - info->var.yres;
  537. if ((var->bits_per_pixel != 32) && (var->bits_per_pixel != 24) &&
  538. (var->bits_per_pixel != 16))
  539. var->bits_per_pixel = default_bpp;
  540. switch (var->bits_per_pixel) {
  541. case 16:
  542. var->red.length = 5;
  543. var->red.offset = 11;
  544. var->red.msb_right = 0;
  545. var->green.length = 6;
  546. var->green.offset = 5;
  547. var->green.msb_right = 0;
  548. var->blue.length = 5;
  549. var->blue.offset = 0;
  550. var->blue.msb_right = 0;
  551. var->transp.length = 0;
  552. var->transp.offset = 0;
  553. var->transp.msb_right = 0;
  554. break;
  555. case 24:
  556. var->red.length = 8;
  557. var->red.offset = 0;
  558. var->red.msb_right = 0;
  559. var->green.length = 8;
  560. var->green.offset = 8;
  561. var->green.msb_right = 0;
  562. var->blue.length = 8;
  563. var->blue.offset = 16;
  564. var->blue.msb_right = 0;
  565. var->transp.length = 0;
  566. var->transp.offset = 0;
  567. var->transp.msb_right = 0;
  568. break;
  569. case 32:
  570. var->red.length = 8;
  571. var->red.offset = 16;
  572. var->red.msb_right = 0;
  573. var->green.length = 8;
  574. var->green.offset = 8;
  575. var->green.msb_right = 0;
  576. var->blue.length = 8;
  577. var->blue.offset = 0;
  578. var->blue.msb_right = 0;
  579. var->transp.length = 8;
  580. var->transp.offset = 24;
  581. var->transp.msb_right = 0;
  582. break;
  583. }
  584. /* If the pixclock is below the minimum spec'd value then set to
  585. * refresh rate for 60Hz since this is supported by most monitors.
  586. * Refer to Documentation/fb/ for calculations.
  587. */
  588. if ((var->pixclock < MIN_PIX_CLK) || (var->pixclock > MAX_PIX_CLK)) {
  589. htotal = var->xres + var->right_margin + var->hsync_len +
  590. var->left_margin;
  591. vtotal = var->yres + var->lower_margin + var->vsync_len +
  592. var->upper_margin;
  593. var->pixclock = (vtotal * htotal * 6UL) / 100UL;
  594. var->pixclock = KHZ2PICOS(var->pixclock);
  595. pr_debug("pixclock set for 60Hz refresh = %u ps\n",
  596. var->pixclock);
  597. }
  598. var->height = -1;
  599. var->width = -1;
  600. var->grayscale = 0;
  601. /* Copy nonstd field to/from sync for fbset usage */
  602. var->sync |= var->nonstd;
  603. var->nonstd |= var->sync;
  604. adjust_aoi_size_position(var, info);
  605. return 0;
  606. }
  607. static void set_fix(struct fb_info *info)
  608. {
  609. struct fb_fix_screeninfo *fix = &info->fix;
  610. struct fb_var_screeninfo *var = &info->var;
  611. struct mfb_info *mfbi = info->par;
  612. strncpy(fix->id, mfbi->id, strlen(mfbi->id));
  613. fix->line_length = var->xres_virtual * var->bits_per_pixel / 8;
  614. fix->type = FB_TYPE_PACKED_PIXELS;
  615. fix->accel = FB_ACCEL_NONE;
  616. fix->visual = FB_VISUAL_TRUECOLOR;
  617. fix->xpanstep = 1;
  618. fix->ypanstep = 1;
  619. }
  620. static void update_lcdc(struct fb_info *info)
  621. {
  622. struct fb_var_screeninfo *var = &info->var;
  623. struct mfb_info *mfbi = info->par;
  624. struct fsl_diu_data *machine_data = mfbi->parent;
  625. struct diu *hw;
  626. int i, j;
  627. char __iomem *cursor_base, *gamma_table_base;
  628. u32 temp;
  629. hw = dr.diu_reg;
  630. if (mfbi->type == MFB_TYPE_OFF) {
  631. fsl_diu_disable_panel(info);
  632. return;
  633. }
  634. diu_ops.set_monitor_port(machine_data->monitor_port);
  635. gamma_table_base = pool.gamma.vaddr;
  636. cursor_base = pool.cursor.vaddr;
  637. /* Prep for DIU init - gamma table, cursor table */
  638. for (i = 0; i <= 2; i++)
  639. for (j = 0; j <= 255; j++)
  640. *gamma_table_base++ = j;
  641. diu_ops.set_gamma_table(machine_data->monitor_port, pool.gamma.vaddr);
  642. pr_debug("update-lcdc: HW - %p\n Disabling DIU\n", hw);
  643. disable_lcdc(info);
  644. /* Program DIU registers */
  645. out_be32(&hw->gamma, pool.gamma.paddr);
  646. out_be32(&hw->cursor, pool.cursor.paddr);
  647. out_be32(&hw->bgnd, 0x007F7F7F); /* BGND */
  648. out_be32(&hw->bgnd_wb, 0); /* BGND_WB */
  649. out_be32(&hw->disp_size, (var->yres << 16 | var->xres));
  650. /* DISP SIZE */
  651. pr_debug("DIU xres: %d\n", var->xres);
  652. pr_debug("DIU yres: %d\n", var->yres);
  653. out_be32(&hw->wb_size, 0); /* WB SIZE */
  654. out_be32(&hw->wb_mem_addr, 0); /* WB MEM ADDR */
  655. /* Horizontal and vertical configuration register */
  656. temp = var->left_margin << 22 | /* BP_H */
  657. var->hsync_len << 11 | /* PW_H */
  658. var->right_margin; /* FP_H */
  659. out_be32(&hw->hsyn_para, temp);
  660. temp = var->upper_margin << 22 | /* BP_V */
  661. var->vsync_len << 11 | /* PW_V */
  662. var->lower_margin; /* FP_V */
  663. out_be32(&hw->vsyn_para, temp);
  664. pr_debug("DIU right_margin - %d\n", var->right_margin);
  665. pr_debug("DIU left_margin - %d\n", var->left_margin);
  666. pr_debug("DIU hsync_len - %d\n", var->hsync_len);
  667. pr_debug("DIU upper_margin - %d\n", var->upper_margin);
  668. pr_debug("DIU lower_margin - %d\n", var->lower_margin);
  669. pr_debug("DIU vsync_len - %d\n", var->vsync_len);
  670. pr_debug("DIU HSYNC - 0x%08x\n", hw->hsyn_para);
  671. pr_debug("DIU VSYNC - 0x%08x\n", hw->vsyn_para);
  672. diu_ops.set_pixel_clock(var->pixclock);
  673. out_be32(&hw->syn_pol, 0); /* SYNC SIGNALS POLARITY */
  674. out_be32(&hw->thresholds, 0x00037800); /* The Thresholds */
  675. out_be32(&hw->int_status, 0); /* INTERRUPT STATUS */
  676. out_be32(&hw->plut, 0x01F5F666);
  677. /* Enable the DIU */
  678. enable_lcdc(info);
  679. }
  680. static int map_video_memory(struct fb_info *info)
  681. {
  682. phys_addr_t phys;
  683. u32 smem_len = info->fix.line_length * info->var.yres_virtual;
  684. pr_debug("info->var.xres_virtual = %d\n", info->var.xres_virtual);
  685. pr_debug("info->var.yres_virtual = %d\n", info->var.yres_virtual);
  686. pr_debug("info->fix.line_length = %d\n", info->fix.line_length);
  687. pr_debug("MAP_VIDEO_MEMORY: smem_len = %u\n", smem_len);
  688. info->screen_base = fsl_diu_alloc(smem_len, &phys);
  689. if (info->screen_base == NULL) {
  690. printk(KERN_ERR "Unable to allocate fb memory\n");
  691. return -ENOMEM;
  692. }
  693. mutex_lock(&info->mm_lock);
  694. info->fix.smem_start = (unsigned long) phys;
  695. info->fix.smem_len = smem_len;
  696. mutex_unlock(&info->mm_lock);
  697. info->screen_size = info->fix.smem_len;
  698. pr_debug("Allocated fb @ paddr=0x%08lx, size=%d.\n",
  699. info->fix.smem_start, info->fix.smem_len);
  700. pr_debug("screen base %p\n", info->screen_base);
  701. return 0;
  702. }
  703. static void unmap_video_memory(struct fb_info *info)
  704. {
  705. fsl_diu_free(info->screen_base, info->fix.smem_len);
  706. mutex_lock(&info->mm_lock);
  707. info->screen_base = NULL;
  708. info->fix.smem_start = 0;
  709. info->fix.smem_len = 0;
  710. mutex_unlock(&info->mm_lock);
  711. }
  712. /*
  713. * Using the fb_var_screeninfo in fb_info we set the aoi of this
  714. * particular framebuffer. It is a light version of fsl_diu_set_par.
  715. */
  716. static int fsl_diu_set_aoi(struct fb_info *info)
  717. {
  718. struct fb_var_screeninfo *var = &info->var;
  719. struct mfb_info *mfbi = info->par;
  720. struct diu_ad *ad = mfbi->ad;
  721. /* AOI should not be greater than display size */
  722. ad->offset_xyi = cpu_to_le32((var->yoffset << 16) | var->xoffset);
  723. ad->offset_xyd = cpu_to_le32((mfbi->y_aoi_d << 16) | mfbi->x_aoi_d);
  724. return 0;
  725. }
  726. /*
  727. * Using the fb_var_screeninfo in fb_info we set the resolution of this
  728. * particular framebuffer. This function alters the fb_fix_screeninfo stored
  729. * in fb_info. It does not alter var in fb_info since we are using that
  730. * data. This means we depend on the data in var inside fb_info to be
  731. * supported by the hardware. fsl_diu_check_var is always called before
  732. * fsl_diu_set_par to ensure this.
  733. */
  734. static int fsl_diu_set_par(struct fb_info *info)
  735. {
  736. unsigned long len;
  737. struct fb_var_screeninfo *var = &info->var;
  738. struct mfb_info *mfbi = info->par;
  739. struct fsl_diu_data *machine_data = mfbi->parent;
  740. struct diu_ad *ad = mfbi->ad;
  741. struct diu *hw;
  742. hw = dr.diu_reg;
  743. set_fix(info);
  744. mfbi->cursor_reset = 1;
  745. len = info->var.yres_virtual * info->fix.line_length;
  746. /* Alloc & dealloc each time resolution/bpp change */
  747. if (len != info->fix.smem_len) {
  748. if (info->fix.smem_start)
  749. unmap_video_memory(info);
  750. pr_debug("SET PAR: smem_len = %d\n", info->fix.smem_len);
  751. /* Memory allocation for framebuffer */
  752. if (map_video_memory(info)) {
  753. printk(KERN_ERR "Unable to allocate fb memory 1\n");
  754. return -ENOMEM;
  755. }
  756. }
  757. ad->pix_fmt =
  758. diu_ops.get_pixel_format(var->bits_per_pixel,
  759. machine_data->monitor_port);
  760. ad->addr = cpu_to_le32(info->fix.smem_start);
  761. ad->src_size_g_alpha = cpu_to_le32((var->yres_virtual << 12) |
  762. var->xres_virtual) | mfbi->g_alpha;
  763. /* AOI should not be greater than display size */
  764. ad->aoi_size = cpu_to_le32((var->yres << 16) | var->xres);
  765. ad->offset_xyi = cpu_to_le32((var->yoffset << 16) | var->xoffset);
  766. ad->offset_xyd = cpu_to_le32((mfbi->y_aoi_d << 16) | mfbi->x_aoi_d);
  767. /* Disable chroma keying function */
  768. ad->ckmax_r = 0;
  769. ad->ckmax_g = 0;
  770. ad->ckmax_b = 0;
  771. ad->ckmin_r = 255;
  772. ad->ckmin_g = 255;
  773. ad->ckmin_b = 255;
  774. if (mfbi->index == 0)
  775. update_lcdc(info);
  776. return 0;
  777. }
  778. static inline __u32 CNVT_TOHW(__u32 val, __u32 width)
  779. {
  780. return ((val<<width) + 0x7FFF - val)>>16;
  781. }
  782. /*
  783. * Set a single color register. The values supplied have a 16 bit magnitude
  784. * which needs to be scaled in this function for the hardware. Things to take
  785. * into consideration are how many color registers, if any, are supported with
  786. * the current color visual. With truecolor mode no color palettes are
  787. * supported. Here a psuedo palette is created which we store the value in
  788. * pseudo_palette in struct fb_info. For pseudocolor mode we have a limited
  789. * color palette.
  790. */
  791. static int fsl_diu_setcolreg(unsigned regno, unsigned red, unsigned green,
  792. unsigned blue, unsigned transp, struct fb_info *info)
  793. {
  794. int ret = 1;
  795. /*
  796. * If greyscale is true, then we convert the RGB value
  797. * to greyscale no matter what visual we are using.
  798. */
  799. if (info->var.grayscale)
  800. red = green = blue = (19595 * red + 38470 * green +
  801. 7471 * blue) >> 16;
  802. switch (info->fix.visual) {
  803. case FB_VISUAL_TRUECOLOR:
  804. /*
  805. * 16-bit True Colour. We encode the RGB value
  806. * according to the RGB bitfield information.
  807. */
  808. if (regno < 16) {
  809. u32 *pal = info->pseudo_palette;
  810. u32 v;
  811. red = CNVT_TOHW(red, info->var.red.length);
  812. green = CNVT_TOHW(green, info->var.green.length);
  813. blue = CNVT_TOHW(blue, info->var.blue.length);
  814. transp = CNVT_TOHW(transp, info->var.transp.length);
  815. v = (red << info->var.red.offset) |
  816. (green << info->var.green.offset) |
  817. (blue << info->var.blue.offset) |
  818. (transp << info->var.transp.offset);
  819. pal[regno] = v;
  820. ret = 0;
  821. }
  822. break;
  823. case FB_VISUAL_STATIC_PSEUDOCOLOR:
  824. case FB_VISUAL_PSEUDOCOLOR:
  825. break;
  826. }
  827. return ret;
  828. }
  829. /*
  830. * Pan (or wrap, depending on the `vmode' field) the display using the
  831. * 'xoffset' and 'yoffset' fields of the 'var' structure. If the values
  832. * don't fit, return -EINVAL.
  833. */
  834. static int fsl_diu_pan_display(struct fb_var_screeninfo *var,
  835. struct fb_info *info)
  836. {
  837. if ((info->var.xoffset == var->xoffset) &&
  838. (info->var.yoffset == var->yoffset))
  839. return 0; /* No change, do nothing */
  840. if (var->xoffset < 0 || var->yoffset < 0
  841. || var->xoffset + info->var.xres > info->var.xres_virtual
  842. || var->yoffset + info->var.yres > info->var.yres_virtual)
  843. return -EINVAL;
  844. info->var.xoffset = var->xoffset;
  845. info->var.yoffset = var->yoffset;
  846. if (var->vmode & FB_VMODE_YWRAP)
  847. info->var.vmode |= FB_VMODE_YWRAP;
  848. else
  849. info->var.vmode &= ~FB_VMODE_YWRAP;
  850. fsl_diu_set_aoi(info);
  851. return 0;
  852. }
  853. /*
  854. * Blank the screen if blank_mode != 0, else unblank. Return 0 if blanking
  855. * succeeded, != 0 if un-/blanking failed.
  856. * blank_mode == 2: suspend vsync
  857. * blank_mode == 3: suspend hsync
  858. * blank_mode == 4: powerdown
  859. */
  860. static int fsl_diu_blank(int blank_mode, struct fb_info *info)
  861. {
  862. struct mfb_info *mfbi = info->par;
  863. mfbi->blank = blank_mode;
  864. switch (blank_mode) {
  865. case FB_BLANK_VSYNC_SUSPEND:
  866. case FB_BLANK_HSYNC_SUSPEND:
  867. /* FIXME: fixes to enable_panel and enable lcdc needed */
  868. case FB_BLANK_NORMAL:
  869. /* fsl_diu_disable_panel(info);*/
  870. break;
  871. case FB_BLANK_POWERDOWN:
  872. /* disable_lcdc(info); */
  873. break;
  874. case FB_BLANK_UNBLANK:
  875. /* fsl_diu_enable_panel(info);*/
  876. break;
  877. }
  878. return 0;
  879. }
  880. static int fsl_diu_ioctl(struct fb_info *info, unsigned int cmd,
  881. unsigned long arg)
  882. {
  883. struct mfb_info *mfbi = info->par;
  884. struct diu_ad *ad = mfbi->ad;
  885. struct mfb_chroma_key ck;
  886. unsigned char global_alpha;
  887. struct aoi_display_offset aoi_d;
  888. __u32 pix_fmt;
  889. void __user *buf = (void __user *)arg;
  890. if (!arg)
  891. return -EINVAL;
  892. switch (cmd) {
  893. case MFB_SET_PIXFMT:
  894. if (copy_from_user(&pix_fmt, buf, sizeof(pix_fmt)))
  895. return -EFAULT;
  896. ad->pix_fmt = pix_fmt;
  897. pr_debug("Set pixel format to 0x%08x\n", ad->pix_fmt);
  898. break;
  899. case MFB_GET_PIXFMT:
  900. pix_fmt = ad->pix_fmt;
  901. if (copy_to_user(buf, &pix_fmt, sizeof(pix_fmt)))
  902. return -EFAULT;
  903. pr_debug("get pixel format 0x%08x\n", ad->pix_fmt);
  904. break;
  905. case MFB_SET_AOID:
  906. if (copy_from_user(&aoi_d, buf, sizeof(aoi_d)))
  907. return -EFAULT;
  908. mfbi->x_aoi_d = aoi_d.x_aoi_d;
  909. mfbi->y_aoi_d = aoi_d.y_aoi_d;
  910. pr_debug("set AOI display offset of index %d to (%d,%d)\n",
  911. mfbi->index, aoi_d.x_aoi_d, aoi_d.y_aoi_d);
  912. fsl_diu_check_var(&info->var, info);
  913. fsl_diu_set_aoi(info);
  914. break;
  915. case MFB_GET_AOID:
  916. aoi_d.x_aoi_d = mfbi->x_aoi_d;
  917. aoi_d.y_aoi_d = mfbi->y_aoi_d;
  918. if (copy_to_user(buf, &aoi_d, sizeof(aoi_d)))
  919. return -EFAULT;
  920. pr_debug("get AOI display offset of index %d (%d,%d)\n",
  921. mfbi->index, aoi_d.x_aoi_d, aoi_d.y_aoi_d);
  922. break;
  923. case MFB_GET_ALPHA:
  924. global_alpha = mfbi->g_alpha;
  925. if (copy_to_user(buf, &global_alpha, sizeof(global_alpha)))
  926. return -EFAULT;
  927. pr_debug("get global alpha of index %d\n", mfbi->index);
  928. break;
  929. case MFB_SET_ALPHA:
  930. /* set panel information */
  931. if (copy_from_user(&global_alpha, buf, sizeof(global_alpha)))
  932. return -EFAULT;
  933. ad->src_size_g_alpha = (ad->src_size_g_alpha & (~0xff)) |
  934. (global_alpha & 0xff);
  935. mfbi->g_alpha = global_alpha;
  936. pr_debug("set global alpha for index %d\n", mfbi->index);
  937. break;
  938. case MFB_SET_CHROMA_KEY:
  939. /* set panel winformation */
  940. if (copy_from_user(&ck, buf, sizeof(ck)))
  941. return -EFAULT;
  942. if (ck.enable &&
  943. (ck.red_max < ck.red_min ||
  944. ck.green_max < ck.green_min ||
  945. ck.blue_max < ck.blue_min))
  946. return -EINVAL;
  947. if (!ck.enable) {
  948. ad->ckmax_r = 0;
  949. ad->ckmax_g = 0;
  950. ad->ckmax_b = 0;
  951. ad->ckmin_r = 255;
  952. ad->ckmin_g = 255;
  953. ad->ckmin_b = 255;
  954. } else {
  955. ad->ckmax_r = ck.red_max;
  956. ad->ckmax_g = ck.green_max;
  957. ad->ckmax_b = ck.blue_max;
  958. ad->ckmin_r = ck.red_min;
  959. ad->ckmin_g = ck.green_min;
  960. ad->ckmin_b = ck.blue_min;
  961. }
  962. pr_debug("set chroma key\n");
  963. break;
  964. case FBIOGET_GWINFO:
  965. if (mfbi->type == MFB_TYPE_OFF)
  966. return -ENODEV;
  967. /* get graphic window information */
  968. if (copy_to_user(buf, ad, sizeof(*ad)))
  969. return -EFAULT;
  970. break;
  971. case FBIOGET_HWCINFO:
  972. pr_debug("FBIOGET_HWCINFO:0x%08x\n", FBIOGET_HWCINFO);
  973. break;
  974. case FBIOPUT_MODEINFO:
  975. pr_debug("FBIOPUT_MODEINFO:0x%08x\n", FBIOPUT_MODEINFO);
  976. break;
  977. case FBIOGET_DISPINFO:
  978. pr_debug("FBIOGET_DISPINFO:0x%08x\n", FBIOGET_DISPINFO);
  979. break;
  980. default:
  981. printk(KERN_ERR "Unknown ioctl command (0x%08X)\n", cmd);
  982. return -ENOIOCTLCMD;
  983. }
  984. return 0;
  985. }
  986. /* turn on fb if count == 1
  987. */
  988. static int fsl_diu_open(struct fb_info *info, int user)
  989. {
  990. struct mfb_info *mfbi = info->par;
  991. int res = 0;
  992. spin_lock(&diu_lock);
  993. mfbi->count++;
  994. if (mfbi->count == 1) {
  995. pr_debug("open plane index %d\n", mfbi->index);
  996. fsl_diu_check_var(&info->var, info);
  997. res = fsl_diu_set_par(info);
  998. if (res < 0)
  999. mfbi->count--;
  1000. else {
  1001. res = fsl_diu_enable_panel(info);
  1002. if (res < 0)
  1003. mfbi->count--;
  1004. }
  1005. }
  1006. spin_unlock(&diu_lock);
  1007. return res;
  1008. }
  1009. /* turn off fb if count == 0
  1010. */
  1011. static int fsl_diu_release(struct fb_info *info, int user)
  1012. {
  1013. struct mfb_info *mfbi = info->par;
  1014. int res = 0;
  1015. spin_lock(&diu_lock);
  1016. mfbi->count--;
  1017. if (mfbi->count == 0) {
  1018. pr_debug("release plane index %d\n", mfbi->index);
  1019. res = fsl_diu_disable_panel(info);
  1020. if (res < 0)
  1021. mfbi->count++;
  1022. }
  1023. spin_unlock(&diu_lock);
  1024. return res;
  1025. }
  1026. static struct fb_ops fsl_diu_ops = {
  1027. .owner = THIS_MODULE,
  1028. .fb_check_var = fsl_diu_check_var,
  1029. .fb_set_par = fsl_diu_set_par,
  1030. .fb_setcolreg = fsl_diu_setcolreg,
  1031. .fb_blank = fsl_diu_blank,
  1032. .fb_pan_display = fsl_diu_pan_display,
  1033. .fb_fillrect = cfb_fillrect,
  1034. .fb_copyarea = cfb_copyarea,
  1035. .fb_imageblit = cfb_imageblit,
  1036. .fb_ioctl = fsl_diu_ioctl,
  1037. .fb_open = fsl_diu_open,
  1038. .fb_release = fsl_diu_release,
  1039. };
  1040. static int init_fbinfo(struct fb_info *info)
  1041. {
  1042. struct mfb_info *mfbi = info->par;
  1043. info->device = NULL;
  1044. info->var.activate = FB_ACTIVATE_NOW;
  1045. info->fbops = &fsl_diu_ops;
  1046. info->flags = FBINFO_FLAG_DEFAULT;
  1047. info->pseudo_palette = &mfbi->pseudo_palette;
  1048. /* Allocate colormap */
  1049. fb_alloc_cmap(&info->cmap, 16, 0);
  1050. return 0;
  1051. }
  1052. static int __devinit install_fb(struct fb_info *info)
  1053. {
  1054. int rc;
  1055. struct mfb_info *mfbi = info->par;
  1056. const char *aoi_mode, *init_aoi_mode = "320x240";
  1057. if (init_fbinfo(info))
  1058. return -EINVAL;
  1059. if (mfbi->index == 0) /* plane 0 */
  1060. aoi_mode = fb_mode;
  1061. else
  1062. aoi_mode = init_aoi_mode;
  1063. pr_debug("mode used = %s\n", aoi_mode);
  1064. rc = fb_find_mode(&info->var, info, aoi_mode, fsl_diu_mode_db,
  1065. ARRAY_SIZE(fsl_diu_mode_db), &fsl_diu_default_mode, default_bpp);
  1066. switch (rc) {
  1067. case 1:
  1068. pr_debug("using mode specified in @mode\n");
  1069. break;
  1070. case 2:
  1071. pr_debug("using mode specified in @mode "
  1072. "with ignored refresh rate\n");
  1073. break;
  1074. case 3:
  1075. pr_debug("using mode default mode\n");
  1076. break;
  1077. case 4:
  1078. pr_debug("using mode from list\n");
  1079. break;
  1080. default:
  1081. pr_debug("rc = %d\n", rc);
  1082. pr_debug("failed to find mode\n");
  1083. return -EINVAL;
  1084. break;
  1085. }
  1086. pr_debug("xres_virtual %d\n", info->var.xres_virtual);
  1087. pr_debug("bits_per_pixel %d\n", info->var.bits_per_pixel);
  1088. pr_debug("info->var.yres_virtual = %d\n", info->var.yres_virtual);
  1089. pr_debug("info->fix.line_length = %d\n", info->fix.line_length);
  1090. if (mfbi->type == MFB_TYPE_OFF)
  1091. mfbi->blank = FB_BLANK_NORMAL;
  1092. else
  1093. mfbi->blank = FB_BLANK_UNBLANK;
  1094. if (fsl_diu_check_var(&info->var, info)) {
  1095. printk(KERN_ERR "fb_check_var failed");
  1096. fb_dealloc_cmap(&info->cmap);
  1097. return -EINVAL;
  1098. }
  1099. if (register_framebuffer(info) < 0) {
  1100. printk(KERN_ERR "register_framebuffer failed");
  1101. unmap_video_memory(info);
  1102. fb_dealloc_cmap(&info->cmap);
  1103. return -EINVAL;
  1104. }
  1105. mfbi->registered = 1;
  1106. printk(KERN_INFO "fb%d: %s fb device registered successfully.\n",
  1107. info->node, info->fix.id);
  1108. return 0;
  1109. }
  1110. static void uninstall_fb(struct fb_info *info)
  1111. {
  1112. struct mfb_info *mfbi = info->par;
  1113. if (!mfbi->registered)
  1114. return;
  1115. unregister_framebuffer(info);
  1116. unmap_video_memory(info);
  1117. if (&info->cmap)
  1118. fb_dealloc_cmap(&info->cmap);
  1119. mfbi->registered = 0;
  1120. }
  1121. static irqreturn_t fsl_diu_isr(int irq, void *dev_id)
  1122. {
  1123. struct diu *hw = dr.diu_reg;
  1124. unsigned int status = in_be32(&hw->int_status);
  1125. if (status) {
  1126. /* This is the workaround for underrun */
  1127. if (status & INT_UNDRUN) {
  1128. out_be32(&hw->diu_mode, 0);
  1129. pr_debug("Err: DIU occurs underrun!\n");
  1130. udelay(1);
  1131. out_be32(&hw->diu_mode, 1);
  1132. }
  1133. #if defined(CONFIG_NOT_COHERENT_CACHE)
  1134. else if (status & INT_VSYNC) {
  1135. unsigned int i;
  1136. for (i = 0; i < coherence_data_size;
  1137. i += d_cache_line_size)
  1138. __asm__ __volatile__ (
  1139. "dcbz 0, %[input]"
  1140. ::[input]"r"(&coherence_data[i]));
  1141. }
  1142. #endif
  1143. return IRQ_HANDLED;
  1144. }
  1145. return IRQ_NONE;
  1146. }
  1147. static int request_irq_local(int irq)
  1148. {
  1149. unsigned long status, ints;
  1150. struct diu *hw;
  1151. int ret;
  1152. hw = dr.diu_reg;
  1153. /* Read to clear the status */
  1154. status = in_be32(&hw->int_status);
  1155. ret = request_irq(irq, fsl_diu_isr, 0, "diu", NULL);
  1156. if (ret)
  1157. pr_info("Request diu IRQ failed.\n");
  1158. else {
  1159. ints = INT_PARERR | INT_LS_BF_VS;
  1160. #if !defined(CONFIG_NOT_COHERENT_CACHE)
  1161. ints |= INT_VSYNC;
  1162. #endif
  1163. if (dr.mode == MFB_MODE2 || dr.mode == MFB_MODE3)
  1164. ints |= INT_VSYNC_WB;
  1165. /* Read to clear the status */
  1166. status = in_be32(&hw->int_status);
  1167. out_be32(&hw->int_mask, ints);
  1168. }
  1169. return ret;
  1170. }
  1171. static void free_irq_local(int irq)
  1172. {
  1173. struct diu *hw = dr.diu_reg;
  1174. /* Disable all LCDC interrupt */
  1175. out_be32(&hw->int_mask, 0x1f);
  1176. free_irq(irq, NULL);
  1177. }
  1178. #ifdef CONFIG_PM
  1179. /*
  1180. * Power management hooks. Note that we won't be called from IRQ context,
  1181. * unlike the blank functions above, so we may sleep.
  1182. */
  1183. static int fsl_diu_suspend(struct of_device *ofdev, pm_message_t state)
  1184. {
  1185. struct fsl_diu_data *machine_data;
  1186. machine_data = dev_get_drvdata(&ofdev->dev);
  1187. disable_lcdc(machine_data->fsl_diu_info[0]);
  1188. return 0;
  1189. }
  1190. static int fsl_diu_resume(struct of_device *ofdev)
  1191. {
  1192. struct fsl_diu_data *machine_data;
  1193. machine_data = dev_get_drvdata(&ofdev->dev);
  1194. enable_lcdc(machine_data->fsl_diu_info[0]);
  1195. return 0;
  1196. }
  1197. #else
  1198. #define fsl_diu_suspend NULL
  1199. #define fsl_diu_resume NULL
  1200. #endif /* CONFIG_PM */
  1201. /* Align to 64-bit(8-byte), 32-byte, etc. */
  1202. static int allocate_buf(struct device *dev, struct diu_addr *buf, u32 size,
  1203. u32 bytes_align)
  1204. {
  1205. u32 offset, ssize;
  1206. u32 mask;
  1207. dma_addr_t paddr = 0;
  1208. ssize = size + bytes_align;
  1209. buf->vaddr = dma_alloc_coherent(dev, ssize, &paddr, GFP_DMA |
  1210. __GFP_ZERO);
  1211. if (!buf->vaddr)
  1212. return -ENOMEM;
  1213. buf->paddr = (__u32) paddr;
  1214. mask = bytes_align - 1;
  1215. offset = (u32)buf->paddr & mask;
  1216. if (offset) {
  1217. buf->offset = bytes_align - offset;
  1218. buf->paddr = (u32)buf->paddr + offset;
  1219. } else
  1220. buf->offset = 0;
  1221. return 0;
  1222. }
  1223. static void free_buf(struct device *dev, struct diu_addr *buf, u32 size,
  1224. u32 bytes_align)
  1225. {
  1226. dma_free_coherent(dev, size + bytes_align,
  1227. buf->vaddr, (buf->paddr - buf->offset));
  1228. return;
  1229. }
  1230. static ssize_t store_monitor(struct device *device,
  1231. struct device_attribute *attr, const char *buf, size_t count)
  1232. {
  1233. int old_monitor_port;
  1234. unsigned long val;
  1235. struct fsl_diu_data *machine_data =
  1236. container_of(attr, struct fsl_diu_data, dev_attr);
  1237. if (strict_strtoul(buf, 10, &val))
  1238. return 0;
  1239. old_monitor_port = machine_data->monitor_port;
  1240. machine_data->monitor_port = diu_ops.set_sysfs_monitor_port(val);
  1241. if (old_monitor_port != machine_data->monitor_port) {
  1242. /* All AOIs need adjust pixel format
  1243. * fsl_diu_set_par only change the pixsel format here
  1244. * unlikely to fail. */
  1245. fsl_diu_set_par(machine_data->fsl_diu_info[0]);
  1246. fsl_diu_set_par(machine_data->fsl_diu_info[1]);
  1247. fsl_diu_set_par(machine_data->fsl_diu_info[2]);
  1248. fsl_diu_set_par(machine_data->fsl_diu_info[3]);
  1249. fsl_diu_set_par(machine_data->fsl_diu_info[4]);
  1250. }
  1251. return count;
  1252. }
  1253. static ssize_t show_monitor(struct device *device,
  1254. struct device_attribute *attr, char *buf)
  1255. {
  1256. struct fsl_diu_data *machine_data =
  1257. container_of(attr, struct fsl_diu_data, dev_attr);
  1258. return diu_ops.show_monitor_port(machine_data->monitor_port, buf);
  1259. }
  1260. static int __devinit fsl_diu_probe(struct of_device *ofdev,
  1261. const struct of_device_id *match)
  1262. {
  1263. struct device_node *np = ofdev->dev.of_node;
  1264. struct mfb_info *mfbi;
  1265. phys_addr_t dummy_ad_addr;
  1266. int ret, i, error = 0;
  1267. struct resource res;
  1268. struct fsl_diu_data *machine_data;
  1269. machine_data = kzalloc(sizeof(struct fsl_diu_data), GFP_KERNEL);
  1270. if (!machine_data)
  1271. return -ENOMEM;
  1272. for (i = 0; i < ARRAY_SIZE(machine_data->fsl_diu_info); i++) {
  1273. machine_data->fsl_diu_info[i] =
  1274. framebuffer_alloc(sizeof(struct mfb_info), &ofdev->dev);
  1275. if (!machine_data->fsl_diu_info[i]) {
  1276. dev_err(&ofdev->dev, "cannot allocate memory\n");
  1277. ret = -ENOMEM;
  1278. goto error2;
  1279. }
  1280. mfbi = machine_data->fsl_diu_info[i]->par;
  1281. memcpy(mfbi, &mfb_template[i], sizeof(struct mfb_info));
  1282. mfbi->parent = machine_data;
  1283. }
  1284. ret = of_address_to_resource(np, 0, &res);
  1285. if (ret) {
  1286. dev_err(&ofdev->dev, "could not obtain DIU address\n");
  1287. goto error;
  1288. }
  1289. if (!res.start) {
  1290. dev_err(&ofdev->dev, "invalid DIU address\n");
  1291. goto error;
  1292. }
  1293. dev_dbg(&ofdev->dev, "%s, res.start: 0x%08x\n", __func__, res.start);
  1294. dr.diu_reg = ioremap(res.start, sizeof(struct diu));
  1295. if (!dr.diu_reg) {
  1296. dev_err(&ofdev->dev, "Err: can't map DIU registers!\n");
  1297. ret = -EFAULT;
  1298. goto error2;
  1299. }
  1300. out_be32(&dr.diu_reg->diu_mode, 0); /* disable DIU anyway*/
  1301. /* Get the IRQ of the DIU */
  1302. machine_data->irq = irq_of_parse_and_map(np, 0);
  1303. if (!machine_data->irq) {
  1304. dev_err(&ofdev->dev, "could not get DIU IRQ\n");
  1305. ret = -EINVAL;
  1306. goto error;
  1307. }
  1308. machine_data->monitor_port = monitor_port;
  1309. /* Area descriptor memory pool aligns to 64-bit boundary */
  1310. if (allocate_buf(&ofdev->dev, &pool.ad,
  1311. sizeof(struct diu_ad) * FSL_AOI_NUM, 8))
  1312. return -ENOMEM;
  1313. /* Get memory for Gamma Table - 32-byte aligned memory */
  1314. if (allocate_buf(&ofdev->dev, &pool.gamma, 768, 32)) {
  1315. ret = -ENOMEM;
  1316. goto error;
  1317. }
  1318. /* For performance, cursor bitmap buffer aligns to 32-byte boundary */
  1319. if (allocate_buf(&ofdev->dev, &pool.cursor, MAX_CURS * MAX_CURS * 2,
  1320. 32)) {
  1321. ret = -ENOMEM;
  1322. goto error;
  1323. }
  1324. i = ARRAY_SIZE(machine_data->fsl_diu_info);
  1325. machine_data->dummy_ad = (struct diu_ad *)
  1326. ((u32)pool.ad.vaddr + pool.ad.offset) + i;
  1327. machine_data->dummy_ad->paddr = pool.ad.paddr +
  1328. i * sizeof(struct diu_ad);
  1329. machine_data->dummy_aoi_virt = fsl_diu_alloc(64, &dummy_ad_addr);
  1330. if (!machine_data->dummy_aoi_virt) {
  1331. ret = -ENOMEM;
  1332. goto error;
  1333. }
  1334. machine_data->dummy_ad->addr = cpu_to_le32(dummy_ad_addr);
  1335. machine_data->dummy_ad->pix_fmt = 0x88882317;
  1336. machine_data->dummy_ad->src_size_g_alpha = cpu_to_le32((4 << 12) | 4);
  1337. machine_data->dummy_ad->aoi_size = cpu_to_le32((4 << 16) | 2);
  1338. machine_data->dummy_ad->offset_xyi = 0;
  1339. machine_data->dummy_ad->offset_xyd = 0;
  1340. machine_data->dummy_ad->next_ad = 0;
  1341. out_be32(&dr.diu_reg->desc[0], machine_data->dummy_ad->paddr);
  1342. out_be32(&dr.diu_reg->desc[1], machine_data->dummy_ad->paddr);
  1343. out_be32(&dr.diu_reg->desc[2], machine_data->dummy_ad->paddr);
  1344. for (i = 0; i < ARRAY_SIZE(machine_data->fsl_diu_info); i++) {
  1345. machine_data->fsl_diu_info[i]->fix.smem_start = 0;
  1346. mfbi = machine_data->fsl_diu_info[i]->par;
  1347. mfbi->ad = (struct diu_ad *)((u32)pool.ad.vaddr
  1348. + pool.ad.offset) + i;
  1349. mfbi->ad->paddr = pool.ad.paddr + i * sizeof(struct diu_ad);
  1350. ret = install_fb(machine_data->fsl_diu_info[i]);
  1351. if (ret) {
  1352. dev_err(&ofdev->dev,
  1353. "Failed to register framebuffer %d\n",
  1354. i);
  1355. goto error;
  1356. }
  1357. }
  1358. if (request_irq_local(machine_data->irq)) {
  1359. dev_err(machine_data->fsl_diu_info[0]->dev,
  1360. "could not request irq for diu.");
  1361. goto error;
  1362. }
  1363. sysfs_attr_init(&machine_data->dev_attr.attr);
  1364. machine_data->dev_attr.attr.name = "monitor";
  1365. machine_data->dev_attr.attr.mode = S_IRUGO|S_IWUSR;
  1366. machine_data->dev_attr.show = show_monitor;
  1367. machine_data->dev_attr.store = store_monitor;
  1368. error = device_create_file(machine_data->fsl_diu_info[0]->dev,
  1369. &machine_data->dev_attr);
  1370. if (error) {
  1371. dev_err(machine_data->fsl_diu_info[0]->dev,
  1372. "could not create sysfs %s file\n",
  1373. machine_data->dev_attr.attr.name);
  1374. }
  1375. dev_set_drvdata(&ofdev->dev, machine_data);
  1376. return 0;
  1377. error:
  1378. for (i = ARRAY_SIZE(machine_data->fsl_diu_info);
  1379. i > 0; i--)
  1380. uninstall_fb(machine_data->fsl_diu_info[i - 1]);
  1381. if (pool.ad.vaddr)
  1382. free_buf(&ofdev->dev, &pool.ad,
  1383. sizeof(struct diu_ad) * FSL_AOI_NUM, 8);
  1384. if (pool.gamma.vaddr)
  1385. free_buf(&ofdev->dev, &pool.gamma, 768, 32);
  1386. if (pool.cursor.vaddr)
  1387. free_buf(&ofdev->dev, &pool.cursor, MAX_CURS * MAX_CURS * 2,
  1388. 32);
  1389. if (machine_data->dummy_aoi_virt)
  1390. fsl_diu_free(machine_data->dummy_aoi_virt, 64);
  1391. iounmap(dr.diu_reg);
  1392. error2:
  1393. for (i = 0; i < ARRAY_SIZE(machine_data->fsl_diu_info); i++)
  1394. if (machine_data->fsl_diu_info[i])
  1395. framebuffer_release(machine_data->fsl_diu_info[i]);
  1396. kfree(machine_data);
  1397. return ret;
  1398. }
  1399. static int fsl_diu_remove(struct of_device *ofdev)
  1400. {
  1401. struct fsl_diu_data *machine_data;
  1402. int i;
  1403. machine_data = dev_get_drvdata(&ofdev->dev);
  1404. disable_lcdc(machine_data->fsl_diu_info[0]);
  1405. free_irq_local(machine_data->irq);
  1406. for (i = ARRAY_SIZE(machine_data->fsl_diu_info); i > 0; i--)
  1407. uninstall_fb(machine_data->fsl_diu_info[i - 1]);
  1408. if (pool.ad.vaddr)
  1409. free_buf(&ofdev->dev, &pool.ad,
  1410. sizeof(struct diu_ad) * FSL_AOI_NUM, 8);
  1411. if (pool.gamma.vaddr)
  1412. free_buf(&ofdev->dev, &pool.gamma, 768, 32);
  1413. if (pool.cursor.vaddr)
  1414. free_buf(&ofdev->dev, &pool.cursor, MAX_CURS * MAX_CURS * 2,
  1415. 32);
  1416. if (machine_data->dummy_aoi_virt)
  1417. fsl_diu_free(machine_data->dummy_aoi_virt, 64);
  1418. iounmap(dr.diu_reg);
  1419. for (i = 0; i < ARRAY_SIZE(machine_data->fsl_diu_info); i++)
  1420. if (machine_data->fsl_diu_info[i])
  1421. framebuffer_release(machine_data->fsl_diu_info[i]);
  1422. kfree(machine_data);
  1423. return 0;
  1424. }
  1425. #ifndef MODULE
  1426. static int __init fsl_diu_setup(char *options)
  1427. {
  1428. char *opt;
  1429. unsigned long val;
  1430. if (!options || !*options)
  1431. return 0;
  1432. while ((opt = strsep(&options, ",")) != NULL) {
  1433. if (!*opt)
  1434. continue;
  1435. if (!strncmp(opt, "monitor=", 8)) {
  1436. if (!strict_strtoul(opt + 8, 10, &val) && (val <= 2))
  1437. monitor_port = val;
  1438. } else if (!strncmp(opt, "bpp=", 4)) {
  1439. if (!strict_strtoul(opt + 4, 10, &val))
  1440. default_bpp = val;
  1441. } else
  1442. fb_mode = opt;
  1443. }
  1444. return 0;
  1445. }
  1446. #endif
  1447. static struct of_device_id fsl_diu_match[] = {
  1448. #ifdef CONFIG_PPC_MPC512x
  1449. {
  1450. .compatible = "fsl,mpc5121-diu",
  1451. },
  1452. #endif
  1453. {
  1454. .compatible = "fsl,diu",
  1455. },
  1456. {}
  1457. };
  1458. MODULE_DEVICE_TABLE(of, fsl_diu_match);
  1459. static struct of_platform_driver fsl_diu_driver = {
  1460. .driver = {
  1461. .name = "fsl_diu",
  1462. .owner = THIS_MODULE,
  1463. .of_match_table = fsl_diu_match,
  1464. },
  1465. .probe = fsl_diu_probe,
  1466. .remove = fsl_diu_remove,
  1467. .suspend = fsl_diu_suspend,
  1468. .resume = fsl_diu_resume,
  1469. };
  1470. static int __init fsl_diu_init(void)
  1471. {
  1472. #ifdef CONFIG_NOT_COHERENT_CACHE
  1473. struct device_node *np;
  1474. const u32 *prop;
  1475. #endif
  1476. int ret;
  1477. #ifndef MODULE
  1478. char *option;
  1479. /*
  1480. * For kernel boot options (in 'video=xxxfb:<options>' format)
  1481. */
  1482. if (fb_get_options("fslfb", &option))
  1483. return -ENODEV;
  1484. fsl_diu_setup(option);
  1485. #endif
  1486. printk(KERN_INFO "Freescale DIU driver\n");
  1487. #ifdef CONFIG_NOT_COHERENT_CACHE
  1488. np = of_find_node_by_type(NULL, "cpu");
  1489. if (!np) {
  1490. printk(KERN_ERR "Err: can't find device node 'cpu'\n");
  1491. return -ENODEV;
  1492. }
  1493. prop = of_get_property(np, "d-cache-size", NULL);
  1494. if (prop == NULL) {
  1495. of_node_put(np);
  1496. return -ENODEV;
  1497. }
  1498. /* Freescale PLRU requires 13/8 times the cache size to do a proper
  1499. displacement flush
  1500. */
  1501. coherence_data_size = *prop * 13;
  1502. coherence_data_size /= 8;
  1503. prop = of_get_property(np, "d-cache-line-size", NULL);
  1504. if (prop == NULL) {
  1505. of_node_put(np);
  1506. return -ENODEV;
  1507. }
  1508. d_cache_line_size = *prop;
  1509. of_node_put(np);
  1510. coherence_data = vmalloc(coherence_data_size);
  1511. if (!coherence_data)
  1512. return -ENOMEM;
  1513. #endif
  1514. ret = of_register_platform_driver(&fsl_diu_driver);
  1515. if (ret) {
  1516. printk(KERN_ERR
  1517. "fsl-diu: failed to register platform driver\n");
  1518. #if defined(CONFIG_NOT_COHERENT_CACHE)
  1519. vfree(coherence_data);
  1520. #endif
  1521. iounmap(dr.diu_reg);
  1522. }
  1523. return ret;
  1524. }
  1525. static void __exit fsl_diu_exit(void)
  1526. {
  1527. of_unregister_platform_driver(&fsl_diu_driver);
  1528. #if defined(CONFIG_NOT_COHERENT_CACHE)
  1529. vfree(coherence_data);
  1530. #endif
  1531. }
  1532. module_init(fsl_diu_init);
  1533. module_exit(fsl_diu_exit);
  1534. MODULE_AUTHOR("York Sun <yorksun@freescale.com>");
  1535. MODULE_DESCRIPTION("Freescale DIU framebuffer driver");
  1536. MODULE_LICENSE("GPL");
  1537. module_param_named(mode, fb_mode, charp, 0);
  1538. MODULE_PARM_DESC(mode,
  1539. "Specify resolution as \"<xres>x<yres>[-<bpp>][@<refresh>]\" ");
  1540. module_param_named(bpp, default_bpp, ulong, 0);
  1541. MODULE_PARM_DESC(bpp, "Specify bit-per-pixel if not specified mode");
  1542. module_param_named(monitor, monitor_port, int, 0);
  1543. MODULE_PARM_DESC(monitor,
  1544. "Specify the monitor port (0, 1 or 2) if supported by the platform");