fsl-diu-fb.c 47 KB

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