fsl-diu-fb.c 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819
  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. pr_debug("check_var xres: %d\n", var->xres);
  525. pr_debug("check_var yres: %d\n", var->yres);
  526. if (var->xres_virtual < var->xres)
  527. var->xres_virtual = var->xres;
  528. if (var->yres_virtual < var->yres)
  529. var->yres_virtual = var->yres;
  530. if (var->xoffset < 0)
  531. var->xoffset = 0;
  532. if (var->yoffset < 0)
  533. var->yoffset = 0;
  534. if (var->xoffset + info->var.xres > info->var.xres_virtual)
  535. var->xoffset = info->var.xres_virtual - info->var.xres;
  536. if (var->yoffset + info->var.yres > info->var.yres_virtual)
  537. var->yoffset = info->var.yres_virtual - info->var.yres;
  538. if ((var->bits_per_pixel != 32) && (var->bits_per_pixel != 24) &&
  539. (var->bits_per_pixel != 16))
  540. var->bits_per_pixel = default_bpp;
  541. switch (var->bits_per_pixel) {
  542. case 16:
  543. var->red.length = 5;
  544. var->red.offset = 11;
  545. var->red.msb_right = 0;
  546. var->green.length = 6;
  547. var->green.offset = 5;
  548. var->green.msb_right = 0;
  549. var->blue.length = 5;
  550. var->blue.offset = 0;
  551. var->blue.msb_right = 0;
  552. var->transp.length = 0;
  553. var->transp.offset = 0;
  554. var->transp.msb_right = 0;
  555. break;
  556. case 24:
  557. var->red.length = 8;
  558. var->red.offset = 0;
  559. var->red.msb_right = 0;
  560. var->green.length = 8;
  561. var->green.offset = 8;
  562. var->green.msb_right = 0;
  563. var->blue.length = 8;
  564. var->blue.offset = 16;
  565. var->blue.msb_right = 0;
  566. var->transp.length = 0;
  567. var->transp.offset = 0;
  568. var->transp.msb_right = 0;
  569. break;
  570. case 32:
  571. var->red.length = 8;
  572. var->red.offset = 16;
  573. var->red.msb_right = 0;
  574. var->green.length = 8;
  575. var->green.offset = 8;
  576. var->green.msb_right = 0;
  577. var->blue.length = 8;
  578. var->blue.offset = 0;
  579. var->blue.msb_right = 0;
  580. var->transp.length = 8;
  581. var->transp.offset = 24;
  582. var->transp.msb_right = 0;
  583. break;
  584. }
  585. var->height = -1;
  586. var->width = -1;
  587. var->grayscale = 0;
  588. /* Copy nonstd field to/from sync for fbset usage */
  589. var->sync |= var->nonstd;
  590. var->nonstd |= var->sync;
  591. adjust_aoi_size_position(var, info);
  592. return 0;
  593. }
  594. static void set_fix(struct fb_info *info)
  595. {
  596. struct fb_fix_screeninfo *fix = &info->fix;
  597. struct fb_var_screeninfo *var = &info->var;
  598. struct mfb_info *mfbi = info->par;
  599. strncpy(fix->id, mfbi->id, strlen(mfbi->id));
  600. fix->line_length = var->xres_virtual * var->bits_per_pixel / 8;
  601. fix->type = FB_TYPE_PACKED_PIXELS;
  602. fix->accel = FB_ACCEL_NONE;
  603. fix->visual = FB_VISUAL_TRUECOLOR;
  604. fix->xpanstep = 1;
  605. fix->ypanstep = 1;
  606. }
  607. static void update_lcdc(struct fb_info *info)
  608. {
  609. struct fb_var_screeninfo *var = &info->var;
  610. struct mfb_info *mfbi = info->par;
  611. struct fsl_diu_data *machine_data = mfbi->parent;
  612. struct diu *hw;
  613. int i, j;
  614. char __iomem *cursor_base, *gamma_table_base;
  615. u32 temp;
  616. hw = dr.diu_reg;
  617. if (mfbi->type == MFB_TYPE_OFF) {
  618. fsl_diu_disable_panel(info);
  619. return;
  620. }
  621. diu_ops.set_monitor_port(machine_data->monitor_port);
  622. gamma_table_base = pool.gamma.vaddr;
  623. cursor_base = pool.cursor.vaddr;
  624. /* Prep for DIU init - gamma table, cursor table */
  625. for (i = 0; i <= 2; i++)
  626. for (j = 0; j <= 255; j++)
  627. *gamma_table_base++ = j;
  628. diu_ops.set_gamma_table(machine_data->monitor_port, pool.gamma.vaddr);
  629. pr_debug("update-lcdc: HW - %p\n Disabling DIU\n", hw);
  630. disable_lcdc(info);
  631. /* Program DIU registers */
  632. out_be32(&hw->gamma, pool.gamma.paddr);
  633. out_be32(&hw->cursor, pool.cursor.paddr);
  634. out_be32(&hw->bgnd, 0x007F7F7F); /* BGND */
  635. out_be32(&hw->bgnd_wb, 0); /* BGND_WB */
  636. out_be32(&hw->disp_size, (var->yres << 16 | var->xres));
  637. /* DISP SIZE */
  638. pr_debug("DIU xres: %d\n", var->xres);
  639. pr_debug("DIU yres: %d\n", var->yres);
  640. out_be32(&hw->wb_size, 0); /* WB SIZE */
  641. out_be32(&hw->wb_mem_addr, 0); /* WB MEM ADDR */
  642. /* Horizontal and vertical configuration register */
  643. temp = var->left_margin << 22 | /* BP_H */
  644. var->hsync_len << 11 | /* PW_H */
  645. var->right_margin; /* FP_H */
  646. out_be32(&hw->hsyn_para, temp);
  647. temp = var->upper_margin << 22 | /* BP_V */
  648. var->vsync_len << 11 | /* PW_V */
  649. var->lower_margin; /* FP_V */
  650. out_be32(&hw->vsyn_para, temp);
  651. pr_debug("DIU right_margin - %d\n", var->right_margin);
  652. pr_debug("DIU left_margin - %d\n", var->left_margin);
  653. pr_debug("DIU hsync_len - %d\n", var->hsync_len);
  654. pr_debug("DIU upper_margin - %d\n", var->upper_margin);
  655. pr_debug("DIU lower_margin - %d\n", var->lower_margin);
  656. pr_debug("DIU vsync_len - %d\n", var->vsync_len);
  657. pr_debug("DIU HSYNC - 0x%08x\n", hw->hsyn_para);
  658. pr_debug("DIU VSYNC - 0x%08x\n", hw->vsyn_para);
  659. diu_ops.set_pixel_clock(var->pixclock);
  660. out_be32(&hw->syn_pol, 0); /* SYNC SIGNALS POLARITY */
  661. out_be32(&hw->thresholds, 0x00037800); /* The Thresholds */
  662. out_be32(&hw->int_status, 0); /* INTERRUPT STATUS */
  663. out_be32(&hw->plut, 0x01F5F666);
  664. /* Enable the DIU */
  665. enable_lcdc(info);
  666. }
  667. static int map_video_memory(struct fb_info *info)
  668. {
  669. phys_addr_t phys;
  670. u32 smem_len = info->fix.line_length * info->var.yres_virtual;
  671. pr_debug("info->var.xres_virtual = %d\n", info->var.xres_virtual);
  672. pr_debug("info->var.yres_virtual = %d\n", info->var.yres_virtual);
  673. pr_debug("info->fix.line_length = %d\n", info->fix.line_length);
  674. pr_debug("MAP_VIDEO_MEMORY: smem_len = %u\n", smem_len);
  675. info->screen_base = fsl_diu_alloc(smem_len, &phys);
  676. if (info->screen_base == NULL) {
  677. printk(KERN_ERR "Unable to allocate fb memory\n");
  678. return -ENOMEM;
  679. }
  680. mutex_lock(&info->mm_lock);
  681. info->fix.smem_start = (unsigned long) phys;
  682. info->fix.smem_len = smem_len;
  683. mutex_unlock(&info->mm_lock);
  684. info->screen_size = info->fix.smem_len;
  685. pr_debug("Allocated fb @ paddr=0x%08lx, size=%d.\n",
  686. info->fix.smem_start, info->fix.smem_len);
  687. pr_debug("screen base %p\n", info->screen_base);
  688. return 0;
  689. }
  690. static void unmap_video_memory(struct fb_info *info)
  691. {
  692. fsl_diu_free(info->screen_base, info->fix.smem_len);
  693. mutex_lock(&info->mm_lock);
  694. info->screen_base = NULL;
  695. info->fix.smem_start = 0;
  696. info->fix.smem_len = 0;
  697. mutex_unlock(&info->mm_lock);
  698. }
  699. /*
  700. * Using the fb_var_screeninfo in fb_info we set the aoi of this
  701. * particular framebuffer. It is a light version of fsl_diu_set_par.
  702. */
  703. static int fsl_diu_set_aoi(struct fb_info *info)
  704. {
  705. struct fb_var_screeninfo *var = &info->var;
  706. struct mfb_info *mfbi = info->par;
  707. struct diu_ad *ad = mfbi->ad;
  708. /* AOI should not be greater than display size */
  709. ad->offset_xyi = cpu_to_le32((var->yoffset << 16) | var->xoffset);
  710. ad->offset_xyd = cpu_to_le32((mfbi->y_aoi_d << 16) | mfbi->x_aoi_d);
  711. return 0;
  712. }
  713. /*
  714. * Using the fb_var_screeninfo in fb_info we set the resolution of this
  715. * particular framebuffer. This function alters the fb_fix_screeninfo stored
  716. * in fb_info. It does not alter var in fb_info since we are using that
  717. * data. This means we depend on the data in var inside fb_info to be
  718. * supported by the hardware. fsl_diu_check_var is always called before
  719. * fsl_diu_set_par to ensure this.
  720. */
  721. static int fsl_diu_set_par(struct fb_info *info)
  722. {
  723. unsigned long len;
  724. struct fb_var_screeninfo *var = &info->var;
  725. struct mfb_info *mfbi = info->par;
  726. struct fsl_diu_data *machine_data = mfbi->parent;
  727. struct diu_ad *ad = mfbi->ad;
  728. struct diu *hw;
  729. hw = dr.diu_reg;
  730. set_fix(info);
  731. mfbi->cursor_reset = 1;
  732. len = info->var.yres_virtual * info->fix.line_length;
  733. /* Alloc & dealloc each time resolution/bpp change */
  734. if (len != info->fix.smem_len) {
  735. if (info->fix.smem_start)
  736. unmap_video_memory(info);
  737. pr_debug("SET PAR: smem_len = %d\n", info->fix.smem_len);
  738. /* Memory allocation for framebuffer */
  739. if (map_video_memory(info)) {
  740. printk(KERN_ERR "Unable to allocate fb memory 1\n");
  741. return -ENOMEM;
  742. }
  743. }
  744. ad->pix_fmt =
  745. diu_ops.get_pixel_format(var->bits_per_pixel,
  746. machine_data->monitor_port);
  747. ad->addr = cpu_to_le32(info->fix.smem_start);
  748. ad->src_size_g_alpha = cpu_to_le32((var->yres_virtual << 12) |
  749. var->xres_virtual) | mfbi->g_alpha;
  750. /* AOI should not be greater than display size */
  751. ad->aoi_size = cpu_to_le32((var->yres << 16) | var->xres);
  752. ad->offset_xyi = cpu_to_le32((var->yoffset << 16) | var->xoffset);
  753. ad->offset_xyd = cpu_to_le32((mfbi->y_aoi_d << 16) | mfbi->x_aoi_d);
  754. /* Disable chroma keying function */
  755. ad->ckmax_r = 0;
  756. ad->ckmax_g = 0;
  757. ad->ckmax_b = 0;
  758. ad->ckmin_r = 255;
  759. ad->ckmin_g = 255;
  760. ad->ckmin_b = 255;
  761. if (mfbi->index == 0)
  762. update_lcdc(info);
  763. return 0;
  764. }
  765. static inline __u32 CNVT_TOHW(__u32 val, __u32 width)
  766. {
  767. return ((val<<width) + 0x7FFF - val)>>16;
  768. }
  769. /*
  770. * Set a single color register. The values supplied have a 16 bit magnitude
  771. * which needs to be scaled in this function for the hardware. Things to take
  772. * into consideration are how many color registers, if any, are supported with
  773. * the current color visual. With truecolor mode no color palettes are
  774. * supported. Here a pseudo palette is created which we store the value in
  775. * pseudo_palette in struct fb_info. For pseudocolor mode we have a limited
  776. * color palette.
  777. */
  778. static int fsl_diu_setcolreg(unsigned regno, unsigned red, unsigned green,
  779. unsigned blue, unsigned transp, struct fb_info *info)
  780. {
  781. int ret = 1;
  782. /*
  783. * If greyscale is true, then we convert the RGB value
  784. * to greyscale no matter what visual we are using.
  785. */
  786. if (info->var.grayscale)
  787. red = green = blue = (19595 * red + 38470 * green +
  788. 7471 * blue) >> 16;
  789. switch (info->fix.visual) {
  790. case FB_VISUAL_TRUECOLOR:
  791. /*
  792. * 16-bit True Colour. We encode the RGB value
  793. * according to the RGB bitfield information.
  794. */
  795. if (regno < 16) {
  796. u32 *pal = info->pseudo_palette;
  797. u32 v;
  798. red = CNVT_TOHW(red, info->var.red.length);
  799. green = CNVT_TOHW(green, info->var.green.length);
  800. blue = CNVT_TOHW(blue, info->var.blue.length);
  801. transp = CNVT_TOHW(transp, info->var.transp.length);
  802. v = (red << info->var.red.offset) |
  803. (green << info->var.green.offset) |
  804. (blue << info->var.blue.offset) |
  805. (transp << info->var.transp.offset);
  806. pal[regno] = v;
  807. ret = 0;
  808. }
  809. break;
  810. case FB_VISUAL_STATIC_PSEUDOCOLOR:
  811. case FB_VISUAL_PSEUDOCOLOR:
  812. break;
  813. }
  814. return ret;
  815. }
  816. /*
  817. * Pan (or wrap, depending on the `vmode' field) the display using the
  818. * 'xoffset' and 'yoffset' fields of the 'var' structure. If the values
  819. * don't fit, return -EINVAL.
  820. */
  821. static int fsl_diu_pan_display(struct fb_var_screeninfo *var,
  822. struct fb_info *info)
  823. {
  824. if ((info->var.xoffset == var->xoffset) &&
  825. (info->var.yoffset == var->yoffset))
  826. return 0; /* No change, do nothing */
  827. if (var->xoffset < 0 || var->yoffset < 0
  828. || var->xoffset + info->var.xres > info->var.xres_virtual
  829. || var->yoffset + info->var.yres > info->var.yres_virtual)
  830. return -EINVAL;
  831. info->var.xoffset = var->xoffset;
  832. info->var.yoffset = var->yoffset;
  833. if (var->vmode & FB_VMODE_YWRAP)
  834. info->var.vmode |= FB_VMODE_YWRAP;
  835. else
  836. info->var.vmode &= ~FB_VMODE_YWRAP;
  837. fsl_diu_set_aoi(info);
  838. return 0;
  839. }
  840. /*
  841. * Blank the screen if blank_mode != 0, else unblank. Return 0 if blanking
  842. * succeeded, != 0 if un-/blanking failed.
  843. * blank_mode == 2: suspend vsync
  844. * blank_mode == 3: suspend hsync
  845. * blank_mode == 4: powerdown
  846. */
  847. static int fsl_diu_blank(int blank_mode, struct fb_info *info)
  848. {
  849. struct mfb_info *mfbi = info->par;
  850. mfbi->blank = blank_mode;
  851. switch (blank_mode) {
  852. case FB_BLANK_VSYNC_SUSPEND:
  853. case FB_BLANK_HSYNC_SUSPEND:
  854. /* FIXME: fixes to enable_panel and enable lcdc needed */
  855. case FB_BLANK_NORMAL:
  856. /* fsl_diu_disable_panel(info);*/
  857. break;
  858. case FB_BLANK_POWERDOWN:
  859. /* disable_lcdc(info); */
  860. break;
  861. case FB_BLANK_UNBLANK:
  862. /* fsl_diu_enable_panel(info);*/
  863. break;
  864. }
  865. return 0;
  866. }
  867. static int fsl_diu_ioctl(struct fb_info *info, unsigned int cmd,
  868. unsigned long arg)
  869. {
  870. struct mfb_info *mfbi = info->par;
  871. struct diu_ad *ad = mfbi->ad;
  872. struct mfb_chroma_key ck;
  873. unsigned char global_alpha;
  874. struct aoi_display_offset aoi_d;
  875. __u32 pix_fmt;
  876. void __user *buf = (void __user *)arg;
  877. if (!arg)
  878. return -EINVAL;
  879. switch (cmd) {
  880. case MFB_SET_PIXFMT:
  881. if (copy_from_user(&pix_fmt, buf, sizeof(pix_fmt)))
  882. return -EFAULT;
  883. ad->pix_fmt = pix_fmt;
  884. pr_debug("Set pixel format to 0x%08x\n", ad->pix_fmt);
  885. break;
  886. case MFB_GET_PIXFMT:
  887. pix_fmt = ad->pix_fmt;
  888. if (copy_to_user(buf, &pix_fmt, sizeof(pix_fmt)))
  889. return -EFAULT;
  890. pr_debug("get pixel format 0x%08x\n", ad->pix_fmt);
  891. break;
  892. case MFB_SET_AOID:
  893. if (copy_from_user(&aoi_d, buf, sizeof(aoi_d)))
  894. return -EFAULT;
  895. mfbi->x_aoi_d = aoi_d.x_aoi_d;
  896. mfbi->y_aoi_d = aoi_d.y_aoi_d;
  897. pr_debug("set AOI display offset of index %d to (%d,%d)\n",
  898. mfbi->index, aoi_d.x_aoi_d, aoi_d.y_aoi_d);
  899. fsl_diu_check_var(&info->var, info);
  900. fsl_diu_set_aoi(info);
  901. break;
  902. case MFB_GET_AOID:
  903. aoi_d.x_aoi_d = mfbi->x_aoi_d;
  904. aoi_d.y_aoi_d = mfbi->y_aoi_d;
  905. if (copy_to_user(buf, &aoi_d, sizeof(aoi_d)))
  906. return -EFAULT;
  907. pr_debug("get AOI display offset of index %d (%d,%d)\n",
  908. mfbi->index, aoi_d.x_aoi_d, aoi_d.y_aoi_d);
  909. break;
  910. case MFB_GET_ALPHA:
  911. global_alpha = mfbi->g_alpha;
  912. if (copy_to_user(buf, &global_alpha, sizeof(global_alpha)))
  913. return -EFAULT;
  914. pr_debug("get global alpha of index %d\n", mfbi->index);
  915. break;
  916. case MFB_SET_ALPHA:
  917. /* set panel information */
  918. if (copy_from_user(&global_alpha, buf, sizeof(global_alpha)))
  919. return -EFAULT;
  920. ad->src_size_g_alpha = (ad->src_size_g_alpha & (~0xff)) |
  921. (global_alpha & 0xff);
  922. mfbi->g_alpha = global_alpha;
  923. pr_debug("set global alpha for index %d\n", mfbi->index);
  924. break;
  925. case MFB_SET_CHROMA_KEY:
  926. /* set panel winformation */
  927. if (copy_from_user(&ck, buf, sizeof(ck)))
  928. return -EFAULT;
  929. if (ck.enable &&
  930. (ck.red_max < ck.red_min ||
  931. ck.green_max < ck.green_min ||
  932. ck.blue_max < ck.blue_min))
  933. return -EINVAL;
  934. if (!ck.enable) {
  935. ad->ckmax_r = 0;
  936. ad->ckmax_g = 0;
  937. ad->ckmax_b = 0;
  938. ad->ckmin_r = 255;
  939. ad->ckmin_g = 255;
  940. ad->ckmin_b = 255;
  941. } else {
  942. ad->ckmax_r = ck.red_max;
  943. ad->ckmax_g = ck.green_max;
  944. ad->ckmax_b = ck.blue_max;
  945. ad->ckmin_r = ck.red_min;
  946. ad->ckmin_g = ck.green_min;
  947. ad->ckmin_b = ck.blue_min;
  948. }
  949. pr_debug("set chroma key\n");
  950. break;
  951. case FBIOGET_GWINFO:
  952. if (mfbi->type == MFB_TYPE_OFF)
  953. return -ENODEV;
  954. /* get graphic window information */
  955. if (copy_to_user(buf, ad, sizeof(*ad)))
  956. return -EFAULT;
  957. break;
  958. case FBIOGET_HWCINFO:
  959. pr_debug("FBIOGET_HWCINFO:0x%08x\n", FBIOGET_HWCINFO);
  960. break;
  961. case FBIOPUT_MODEINFO:
  962. pr_debug("FBIOPUT_MODEINFO:0x%08x\n", FBIOPUT_MODEINFO);
  963. break;
  964. case FBIOGET_DISPINFO:
  965. pr_debug("FBIOGET_DISPINFO:0x%08x\n", FBIOGET_DISPINFO);
  966. break;
  967. default:
  968. printk(KERN_ERR "Unknown ioctl command (0x%08X)\n", cmd);
  969. return -ENOIOCTLCMD;
  970. }
  971. return 0;
  972. }
  973. /* turn on fb if count == 1
  974. */
  975. static int fsl_diu_open(struct fb_info *info, int user)
  976. {
  977. struct mfb_info *mfbi = info->par;
  978. int res = 0;
  979. /* free boot splash memory on first /dev/fb0 open */
  980. if (!mfbi->index && diu_ops.release_bootmem)
  981. diu_ops.release_bootmem();
  982. spin_lock(&diu_lock);
  983. mfbi->count++;
  984. if (mfbi->count == 1) {
  985. pr_debug("open plane index %d\n", mfbi->index);
  986. fsl_diu_check_var(&info->var, info);
  987. res = fsl_diu_set_par(info);
  988. if (res < 0)
  989. mfbi->count--;
  990. else {
  991. res = fsl_diu_enable_panel(info);
  992. if (res < 0)
  993. mfbi->count--;
  994. }
  995. }
  996. spin_unlock(&diu_lock);
  997. return res;
  998. }
  999. /* turn off fb if count == 0
  1000. */
  1001. static int fsl_diu_release(struct fb_info *info, int user)
  1002. {
  1003. struct mfb_info *mfbi = info->par;
  1004. int res = 0;
  1005. spin_lock(&diu_lock);
  1006. mfbi->count--;
  1007. if (mfbi->count == 0) {
  1008. pr_debug("release plane index %d\n", mfbi->index);
  1009. res = fsl_diu_disable_panel(info);
  1010. if (res < 0)
  1011. mfbi->count++;
  1012. }
  1013. spin_unlock(&diu_lock);
  1014. return res;
  1015. }
  1016. static struct fb_ops fsl_diu_ops = {
  1017. .owner = THIS_MODULE,
  1018. .fb_check_var = fsl_diu_check_var,
  1019. .fb_set_par = fsl_diu_set_par,
  1020. .fb_setcolreg = fsl_diu_setcolreg,
  1021. .fb_blank = fsl_diu_blank,
  1022. .fb_pan_display = fsl_diu_pan_display,
  1023. .fb_fillrect = cfb_fillrect,
  1024. .fb_copyarea = cfb_copyarea,
  1025. .fb_imageblit = cfb_imageblit,
  1026. .fb_ioctl = fsl_diu_ioctl,
  1027. .fb_open = fsl_diu_open,
  1028. .fb_release = fsl_diu_release,
  1029. };
  1030. static int init_fbinfo(struct fb_info *info)
  1031. {
  1032. struct mfb_info *mfbi = info->par;
  1033. info->device = NULL;
  1034. info->var.activate = FB_ACTIVATE_NOW;
  1035. info->fbops = &fsl_diu_ops;
  1036. info->flags = FBINFO_FLAG_DEFAULT;
  1037. info->pseudo_palette = &mfbi->pseudo_palette;
  1038. /* Allocate colormap */
  1039. fb_alloc_cmap(&info->cmap, 16, 0);
  1040. return 0;
  1041. }
  1042. static int __devinit install_fb(struct fb_info *info)
  1043. {
  1044. int rc;
  1045. struct mfb_info *mfbi = info->par;
  1046. const char *aoi_mode, *init_aoi_mode = "320x240";
  1047. struct fb_videomode *db = fsl_diu_mode_db;
  1048. unsigned int dbsize = ARRAY_SIZE(fsl_diu_mode_db);
  1049. int has_default_mode = 1;
  1050. if (init_fbinfo(info))
  1051. return -EINVAL;
  1052. if (mfbi->index == 0) { /* plane 0 */
  1053. if (mfbi->edid_data) {
  1054. /* Now build modedb from EDID */
  1055. fb_edid_to_monspecs(mfbi->edid_data, &info->monspecs);
  1056. fb_videomode_to_modelist(info->monspecs.modedb,
  1057. info->monspecs.modedb_len,
  1058. &info->modelist);
  1059. db = info->monspecs.modedb;
  1060. dbsize = info->monspecs.modedb_len;
  1061. }
  1062. aoi_mode = fb_mode;
  1063. } else {
  1064. aoi_mode = init_aoi_mode;
  1065. }
  1066. pr_debug("mode used = %s\n", aoi_mode);
  1067. rc = fb_find_mode(&info->var, info, aoi_mode, db, dbsize,
  1068. &fsl_diu_default_mode, default_bpp);
  1069. switch (rc) {
  1070. case 1:
  1071. pr_debug("using mode specified in @mode\n");
  1072. break;
  1073. case 2:
  1074. pr_debug("using mode specified in @mode "
  1075. "with ignored refresh rate\n");
  1076. break;
  1077. case 3:
  1078. pr_debug("using mode default mode\n");
  1079. break;
  1080. case 4:
  1081. pr_debug("using mode from list\n");
  1082. break;
  1083. default:
  1084. pr_debug("rc = %d\n", rc);
  1085. pr_debug("failed to find mode\n");
  1086. /*
  1087. * For plane 0 we continue and look into
  1088. * driver's internal modedb.
  1089. */
  1090. if (mfbi->index == 0 && mfbi->edid_data)
  1091. has_default_mode = 0;
  1092. else
  1093. return -EINVAL;
  1094. break;
  1095. }
  1096. if (!has_default_mode) {
  1097. rc = fb_find_mode(&info->var, info, aoi_mode, fsl_diu_mode_db,
  1098. ARRAY_SIZE(fsl_diu_mode_db),
  1099. &fsl_diu_default_mode,
  1100. default_bpp);
  1101. if (rc > 0 && rc < 5)
  1102. has_default_mode = 1;
  1103. }
  1104. /* Still not found, use preferred mode from database if any */
  1105. if (!has_default_mode && info->monspecs.modedb) {
  1106. struct fb_monspecs *specs = &info->monspecs;
  1107. struct fb_videomode *modedb = &specs->modedb[0];
  1108. /*
  1109. * Get preferred timing. If not found,
  1110. * first mode in database will be used.
  1111. */
  1112. if (specs->misc & FB_MISC_1ST_DETAIL) {
  1113. int i;
  1114. for (i = 0; i < specs->modedb_len; i++) {
  1115. if (specs->modedb[i].flag & FB_MODE_IS_FIRST) {
  1116. modedb = &specs->modedb[i];
  1117. break;
  1118. }
  1119. }
  1120. }
  1121. info->var.bits_per_pixel = default_bpp;
  1122. fb_videomode_to_var(&info->var, modedb);
  1123. }
  1124. pr_debug("xres_virtual %d\n", info->var.xres_virtual);
  1125. pr_debug("bits_per_pixel %d\n", info->var.bits_per_pixel);
  1126. pr_debug("info->var.yres_virtual = %d\n", info->var.yres_virtual);
  1127. pr_debug("info->fix.line_length = %d\n", info->fix.line_length);
  1128. if (mfbi->type == MFB_TYPE_OFF)
  1129. mfbi->blank = FB_BLANK_NORMAL;
  1130. else
  1131. mfbi->blank = FB_BLANK_UNBLANK;
  1132. if (fsl_diu_check_var(&info->var, info)) {
  1133. printk(KERN_ERR "fb_check_var failed");
  1134. fb_dealloc_cmap(&info->cmap);
  1135. return -EINVAL;
  1136. }
  1137. if (register_framebuffer(info) < 0) {
  1138. printk(KERN_ERR "register_framebuffer failed");
  1139. unmap_video_memory(info);
  1140. fb_dealloc_cmap(&info->cmap);
  1141. return -EINVAL;
  1142. }
  1143. mfbi->registered = 1;
  1144. printk(KERN_INFO "fb%d: %s fb device registered successfully.\n",
  1145. info->node, info->fix.id);
  1146. return 0;
  1147. }
  1148. static void uninstall_fb(struct fb_info *info)
  1149. {
  1150. struct mfb_info *mfbi = info->par;
  1151. if (!mfbi->registered)
  1152. return;
  1153. if (mfbi->index == 0)
  1154. kfree(mfbi->edid_data);
  1155. unregister_framebuffer(info);
  1156. unmap_video_memory(info);
  1157. if (&info->cmap)
  1158. fb_dealloc_cmap(&info->cmap);
  1159. mfbi->registered = 0;
  1160. }
  1161. static irqreturn_t fsl_diu_isr(int irq, void *dev_id)
  1162. {
  1163. struct diu *hw = dr.diu_reg;
  1164. unsigned int status = in_be32(&hw->int_status);
  1165. if (status) {
  1166. /* This is the workaround for underrun */
  1167. if (status & INT_UNDRUN) {
  1168. out_be32(&hw->diu_mode, 0);
  1169. pr_debug("Err: DIU occurs underrun!\n");
  1170. udelay(1);
  1171. out_be32(&hw->diu_mode, 1);
  1172. }
  1173. #if defined(CONFIG_NOT_COHERENT_CACHE)
  1174. else if (status & INT_VSYNC) {
  1175. unsigned int i;
  1176. for (i = 0; i < coherence_data_size;
  1177. i += d_cache_line_size)
  1178. __asm__ __volatile__ (
  1179. "dcbz 0, %[input]"
  1180. ::[input]"r"(&coherence_data[i]));
  1181. }
  1182. #endif
  1183. return IRQ_HANDLED;
  1184. }
  1185. return IRQ_NONE;
  1186. }
  1187. static int request_irq_local(int irq)
  1188. {
  1189. unsigned long status, ints;
  1190. struct diu *hw;
  1191. int ret;
  1192. hw = dr.diu_reg;
  1193. /* Read to clear the status */
  1194. status = in_be32(&hw->int_status);
  1195. ret = request_irq(irq, fsl_diu_isr, 0, "diu", NULL);
  1196. if (ret)
  1197. pr_info("Request diu IRQ failed.\n");
  1198. else {
  1199. ints = INT_PARERR | INT_LS_BF_VS;
  1200. #if !defined(CONFIG_NOT_COHERENT_CACHE)
  1201. ints |= INT_VSYNC;
  1202. #endif
  1203. if (dr.mode == MFB_MODE2 || dr.mode == MFB_MODE3)
  1204. ints |= INT_VSYNC_WB;
  1205. /* Read to clear the status */
  1206. status = in_be32(&hw->int_status);
  1207. out_be32(&hw->int_mask, ints);
  1208. }
  1209. return ret;
  1210. }
  1211. static void free_irq_local(int irq)
  1212. {
  1213. struct diu *hw = dr.diu_reg;
  1214. /* Disable all LCDC interrupt */
  1215. out_be32(&hw->int_mask, 0x1f);
  1216. free_irq(irq, NULL);
  1217. }
  1218. #ifdef CONFIG_PM
  1219. /*
  1220. * Power management hooks. Note that we won't be called from IRQ context,
  1221. * unlike the blank functions above, so we may sleep.
  1222. */
  1223. static int fsl_diu_suspend(struct platform_device *ofdev, pm_message_t state)
  1224. {
  1225. struct fsl_diu_data *machine_data;
  1226. machine_data = dev_get_drvdata(&ofdev->dev);
  1227. disable_lcdc(machine_data->fsl_diu_info[0]);
  1228. return 0;
  1229. }
  1230. static int fsl_diu_resume(struct platform_device *ofdev)
  1231. {
  1232. struct fsl_diu_data *machine_data;
  1233. machine_data = dev_get_drvdata(&ofdev->dev);
  1234. enable_lcdc(machine_data->fsl_diu_info[0]);
  1235. return 0;
  1236. }
  1237. #else
  1238. #define fsl_diu_suspend NULL
  1239. #define fsl_diu_resume NULL
  1240. #endif /* CONFIG_PM */
  1241. /* Align to 64-bit(8-byte), 32-byte, etc. */
  1242. static int allocate_buf(struct device *dev, struct diu_addr *buf, u32 size,
  1243. u32 bytes_align)
  1244. {
  1245. u32 offset, ssize;
  1246. u32 mask;
  1247. dma_addr_t paddr = 0;
  1248. ssize = size + bytes_align;
  1249. buf->vaddr = dma_alloc_coherent(dev, ssize, &paddr, GFP_DMA |
  1250. __GFP_ZERO);
  1251. if (!buf->vaddr)
  1252. return -ENOMEM;
  1253. buf->paddr = (__u32) paddr;
  1254. mask = bytes_align - 1;
  1255. offset = (u32)buf->paddr & mask;
  1256. if (offset) {
  1257. buf->offset = bytes_align - offset;
  1258. buf->paddr = (u32)buf->paddr + offset;
  1259. } else
  1260. buf->offset = 0;
  1261. return 0;
  1262. }
  1263. static void free_buf(struct device *dev, struct diu_addr *buf, u32 size,
  1264. u32 bytes_align)
  1265. {
  1266. dma_free_coherent(dev, size + bytes_align,
  1267. buf->vaddr, (buf->paddr - buf->offset));
  1268. return;
  1269. }
  1270. static ssize_t store_monitor(struct device *device,
  1271. struct device_attribute *attr, const char *buf, size_t count)
  1272. {
  1273. int old_monitor_port;
  1274. unsigned long val;
  1275. struct fsl_diu_data *machine_data =
  1276. container_of(attr, struct fsl_diu_data, dev_attr);
  1277. if (strict_strtoul(buf, 10, &val))
  1278. return 0;
  1279. old_monitor_port = machine_data->monitor_port;
  1280. machine_data->monitor_port = diu_ops.set_sysfs_monitor_port(val);
  1281. if (old_monitor_port != machine_data->monitor_port) {
  1282. /* All AOIs need adjust pixel format
  1283. * fsl_diu_set_par only change the pixsel format here
  1284. * unlikely to fail. */
  1285. fsl_diu_set_par(machine_data->fsl_diu_info[0]);
  1286. fsl_diu_set_par(machine_data->fsl_diu_info[1]);
  1287. fsl_diu_set_par(machine_data->fsl_diu_info[2]);
  1288. fsl_diu_set_par(machine_data->fsl_diu_info[3]);
  1289. fsl_diu_set_par(machine_data->fsl_diu_info[4]);
  1290. }
  1291. return count;
  1292. }
  1293. static ssize_t show_monitor(struct device *device,
  1294. struct device_attribute *attr, char *buf)
  1295. {
  1296. struct fsl_diu_data *machine_data =
  1297. container_of(attr, struct fsl_diu_data, dev_attr);
  1298. return diu_ops.show_monitor_port(machine_data->monitor_port, buf);
  1299. }
  1300. static int __devinit fsl_diu_probe(struct platform_device *ofdev)
  1301. {
  1302. struct device_node *np = ofdev->dev.of_node;
  1303. struct mfb_info *mfbi;
  1304. phys_addr_t dummy_ad_addr;
  1305. int ret, i, error = 0;
  1306. struct resource res;
  1307. struct fsl_diu_data *machine_data;
  1308. int diu_mode;
  1309. machine_data = kzalloc(sizeof(struct fsl_diu_data), GFP_KERNEL);
  1310. if (!machine_data)
  1311. return -ENOMEM;
  1312. for (i = 0; i < ARRAY_SIZE(machine_data->fsl_diu_info); i++) {
  1313. machine_data->fsl_diu_info[i] =
  1314. framebuffer_alloc(sizeof(struct mfb_info), &ofdev->dev);
  1315. if (!machine_data->fsl_diu_info[i]) {
  1316. dev_err(&ofdev->dev, "cannot allocate memory\n");
  1317. ret = -ENOMEM;
  1318. goto error2;
  1319. }
  1320. mfbi = machine_data->fsl_diu_info[i]->par;
  1321. memcpy(mfbi, &mfb_template[i], sizeof(struct mfb_info));
  1322. mfbi->parent = machine_data;
  1323. if (mfbi->index == 0) {
  1324. const u8 *prop;
  1325. int len;
  1326. /* Get EDID */
  1327. prop = of_get_property(np, "edid", &len);
  1328. if (prop && len == EDID_LENGTH)
  1329. mfbi->edid_data = kmemdup(prop, EDID_LENGTH,
  1330. GFP_KERNEL);
  1331. }
  1332. }
  1333. ret = of_address_to_resource(np, 0, &res);
  1334. if (ret) {
  1335. dev_err(&ofdev->dev, "could not obtain DIU address\n");
  1336. goto error;
  1337. }
  1338. if (!res.start) {
  1339. dev_err(&ofdev->dev, "invalid DIU address\n");
  1340. goto error;
  1341. }
  1342. dev_dbg(&ofdev->dev, "%s, res.start: 0x%08x\n", __func__, res.start);
  1343. dr.diu_reg = ioremap(res.start, sizeof(struct diu));
  1344. if (!dr.diu_reg) {
  1345. dev_err(&ofdev->dev, "Err: can't map DIU registers!\n");
  1346. ret = -EFAULT;
  1347. goto error2;
  1348. }
  1349. diu_mode = in_be32(&dr.diu_reg->diu_mode);
  1350. if (diu_mode != MFB_MODE1)
  1351. out_be32(&dr.diu_reg->diu_mode, 0); /* disable DIU */
  1352. /* Get the IRQ of the DIU */
  1353. machine_data->irq = irq_of_parse_and_map(np, 0);
  1354. if (!machine_data->irq) {
  1355. dev_err(&ofdev->dev, "could not get DIU IRQ\n");
  1356. ret = -EINVAL;
  1357. goto error;
  1358. }
  1359. machine_data->monitor_port = monitor_port;
  1360. /* Area descriptor memory pool aligns to 64-bit boundary */
  1361. if (allocate_buf(&ofdev->dev, &pool.ad,
  1362. sizeof(struct diu_ad) * FSL_AOI_NUM, 8))
  1363. return -ENOMEM;
  1364. /* Get memory for Gamma Table - 32-byte aligned memory */
  1365. if (allocate_buf(&ofdev->dev, &pool.gamma, 768, 32)) {
  1366. ret = -ENOMEM;
  1367. goto error;
  1368. }
  1369. /* For performance, cursor bitmap buffer aligns to 32-byte boundary */
  1370. if (allocate_buf(&ofdev->dev, &pool.cursor, MAX_CURS * MAX_CURS * 2,
  1371. 32)) {
  1372. ret = -ENOMEM;
  1373. goto error;
  1374. }
  1375. i = ARRAY_SIZE(machine_data->fsl_diu_info);
  1376. machine_data->dummy_ad = (struct diu_ad *)
  1377. ((u32)pool.ad.vaddr + pool.ad.offset) + i;
  1378. machine_data->dummy_ad->paddr = pool.ad.paddr +
  1379. i * sizeof(struct diu_ad);
  1380. machine_data->dummy_aoi_virt = fsl_diu_alloc(64, &dummy_ad_addr);
  1381. if (!machine_data->dummy_aoi_virt) {
  1382. ret = -ENOMEM;
  1383. goto error;
  1384. }
  1385. machine_data->dummy_ad->addr = cpu_to_le32(dummy_ad_addr);
  1386. machine_data->dummy_ad->pix_fmt = 0x88882317;
  1387. machine_data->dummy_ad->src_size_g_alpha = cpu_to_le32((4 << 12) | 4);
  1388. machine_data->dummy_ad->aoi_size = cpu_to_le32((4 << 16) | 2);
  1389. machine_data->dummy_ad->offset_xyi = 0;
  1390. machine_data->dummy_ad->offset_xyd = 0;
  1391. machine_data->dummy_ad->next_ad = 0;
  1392. /*
  1393. * Let DIU display splash screen if it was pre-initialized
  1394. * by the bootloader, set dummy area descriptor otherwise.
  1395. */
  1396. if (diu_mode != MFB_MODE1)
  1397. out_be32(&dr.diu_reg->desc[0], machine_data->dummy_ad->paddr);
  1398. out_be32(&dr.diu_reg->desc[1], machine_data->dummy_ad->paddr);
  1399. out_be32(&dr.diu_reg->desc[2], machine_data->dummy_ad->paddr);
  1400. for (i = 0; i < ARRAY_SIZE(machine_data->fsl_diu_info); i++) {
  1401. machine_data->fsl_diu_info[i]->fix.smem_start = 0;
  1402. mfbi = machine_data->fsl_diu_info[i]->par;
  1403. mfbi->ad = (struct diu_ad *)((u32)pool.ad.vaddr
  1404. + pool.ad.offset) + i;
  1405. mfbi->ad->paddr = pool.ad.paddr + i * sizeof(struct diu_ad);
  1406. ret = install_fb(machine_data->fsl_diu_info[i]);
  1407. if (ret) {
  1408. dev_err(&ofdev->dev,
  1409. "Failed to register framebuffer %d\n",
  1410. i);
  1411. goto error;
  1412. }
  1413. }
  1414. if (request_irq_local(machine_data->irq)) {
  1415. dev_err(machine_data->fsl_diu_info[0]->dev,
  1416. "could not request irq for diu.");
  1417. goto error;
  1418. }
  1419. sysfs_attr_init(&machine_data->dev_attr.attr);
  1420. machine_data->dev_attr.attr.name = "monitor";
  1421. machine_data->dev_attr.attr.mode = S_IRUGO|S_IWUSR;
  1422. machine_data->dev_attr.show = show_monitor;
  1423. machine_data->dev_attr.store = store_monitor;
  1424. error = device_create_file(machine_data->fsl_diu_info[0]->dev,
  1425. &machine_data->dev_attr);
  1426. if (error) {
  1427. dev_err(machine_data->fsl_diu_info[0]->dev,
  1428. "could not create sysfs %s file\n",
  1429. machine_data->dev_attr.attr.name);
  1430. }
  1431. dev_set_drvdata(&ofdev->dev, machine_data);
  1432. return 0;
  1433. error:
  1434. for (i = ARRAY_SIZE(machine_data->fsl_diu_info);
  1435. i > 0; i--)
  1436. uninstall_fb(machine_data->fsl_diu_info[i - 1]);
  1437. if (pool.ad.vaddr)
  1438. free_buf(&ofdev->dev, &pool.ad,
  1439. sizeof(struct diu_ad) * FSL_AOI_NUM, 8);
  1440. if (pool.gamma.vaddr)
  1441. free_buf(&ofdev->dev, &pool.gamma, 768, 32);
  1442. if (pool.cursor.vaddr)
  1443. free_buf(&ofdev->dev, &pool.cursor, MAX_CURS * MAX_CURS * 2,
  1444. 32);
  1445. if (machine_data->dummy_aoi_virt)
  1446. fsl_diu_free(machine_data->dummy_aoi_virt, 64);
  1447. iounmap(dr.diu_reg);
  1448. error2:
  1449. for (i = 0; i < ARRAY_SIZE(machine_data->fsl_diu_info); i++)
  1450. if (machine_data->fsl_diu_info[i])
  1451. framebuffer_release(machine_data->fsl_diu_info[i]);
  1452. kfree(machine_data);
  1453. return ret;
  1454. }
  1455. static int fsl_diu_remove(struct platform_device *ofdev)
  1456. {
  1457. struct fsl_diu_data *machine_data;
  1458. int i;
  1459. machine_data = dev_get_drvdata(&ofdev->dev);
  1460. disable_lcdc(machine_data->fsl_diu_info[0]);
  1461. free_irq_local(machine_data->irq);
  1462. for (i = ARRAY_SIZE(machine_data->fsl_diu_info); i > 0; i--)
  1463. uninstall_fb(machine_data->fsl_diu_info[i - 1]);
  1464. if (pool.ad.vaddr)
  1465. free_buf(&ofdev->dev, &pool.ad,
  1466. sizeof(struct diu_ad) * FSL_AOI_NUM, 8);
  1467. if (pool.gamma.vaddr)
  1468. free_buf(&ofdev->dev, &pool.gamma, 768, 32);
  1469. if (pool.cursor.vaddr)
  1470. free_buf(&ofdev->dev, &pool.cursor, MAX_CURS * MAX_CURS * 2,
  1471. 32);
  1472. if (machine_data->dummy_aoi_virt)
  1473. fsl_diu_free(machine_data->dummy_aoi_virt, 64);
  1474. iounmap(dr.diu_reg);
  1475. for (i = 0; i < ARRAY_SIZE(machine_data->fsl_diu_info); i++)
  1476. if (machine_data->fsl_diu_info[i])
  1477. framebuffer_release(machine_data->fsl_diu_info[i]);
  1478. kfree(machine_data);
  1479. return 0;
  1480. }
  1481. #ifndef MODULE
  1482. static int __init fsl_diu_setup(char *options)
  1483. {
  1484. char *opt;
  1485. unsigned long val;
  1486. if (!options || !*options)
  1487. return 0;
  1488. while ((opt = strsep(&options, ",")) != NULL) {
  1489. if (!*opt)
  1490. continue;
  1491. if (!strncmp(opt, "monitor=", 8)) {
  1492. if (!strict_strtoul(opt + 8, 10, &val) && (val <= 2))
  1493. monitor_port = val;
  1494. } else if (!strncmp(opt, "bpp=", 4)) {
  1495. if (!strict_strtoul(opt + 4, 10, &val))
  1496. default_bpp = val;
  1497. } else
  1498. fb_mode = opt;
  1499. }
  1500. return 0;
  1501. }
  1502. #endif
  1503. static struct of_device_id fsl_diu_match[] = {
  1504. #ifdef CONFIG_PPC_MPC512x
  1505. {
  1506. .compatible = "fsl,mpc5121-diu",
  1507. },
  1508. #endif
  1509. {
  1510. .compatible = "fsl,diu",
  1511. },
  1512. {}
  1513. };
  1514. MODULE_DEVICE_TABLE(of, fsl_diu_match);
  1515. static struct platform_driver fsl_diu_driver = {
  1516. .driver = {
  1517. .name = "fsl_diu",
  1518. .owner = THIS_MODULE,
  1519. .of_match_table = fsl_diu_match,
  1520. },
  1521. .probe = fsl_diu_probe,
  1522. .remove = fsl_diu_remove,
  1523. .suspend = fsl_diu_suspend,
  1524. .resume = fsl_diu_resume,
  1525. };
  1526. static int __init fsl_diu_init(void)
  1527. {
  1528. #ifdef CONFIG_NOT_COHERENT_CACHE
  1529. struct device_node *np;
  1530. const u32 *prop;
  1531. #endif
  1532. int ret;
  1533. #ifndef MODULE
  1534. char *option;
  1535. /*
  1536. * For kernel boot options (in 'video=xxxfb:<options>' format)
  1537. */
  1538. if (fb_get_options("fslfb", &option))
  1539. return -ENODEV;
  1540. fsl_diu_setup(option);
  1541. #endif
  1542. printk(KERN_INFO "Freescale DIU driver\n");
  1543. #ifdef CONFIG_NOT_COHERENT_CACHE
  1544. np = of_find_node_by_type(NULL, "cpu");
  1545. if (!np) {
  1546. printk(KERN_ERR "Err: can't find device node 'cpu'\n");
  1547. return -ENODEV;
  1548. }
  1549. prop = of_get_property(np, "d-cache-size", NULL);
  1550. if (prop == NULL) {
  1551. of_node_put(np);
  1552. return -ENODEV;
  1553. }
  1554. /* Freescale PLRU requires 13/8 times the cache size to do a proper
  1555. displacement flush
  1556. */
  1557. coherence_data_size = *prop * 13;
  1558. coherence_data_size /= 8;
  1559. prop = of_get_property(np, "d-cache-line-size", NULL);
  1560. if (prop == NULL) {
  1561. of_node_put(np);
  1562. return -ENODEV;
  1563. }
  1564. d_cache_line_size = *prop;
  1565. of_node_put(np);
  1566. coherence_data = vmalloc(coherence_data_size);
  1567. if (!coherence_data)
  1568. return -ENOMEM;
  1569. #endif
  1570. ret = platform_driver_register(&fsl_diu_driver);
  1571. if (ret) {
  1572. printk(KERN_ERR
  1573. "fsl-diu: failed to register platform driver\n");
  1574. #if defined(CONFIG_NOT_COHERENT_CACHE)
  1575. vfree(coherence_data);
  1576. #endif
  1577. iounmap(dr.diu_reg);
  1578. }
  1579. return ret;
  1580. }
  1581. static void __exit fsl_diu_exit(void)
  1582. {
  1583. platform_driver_unregister(&fsl_diu_driver);
  1584. #if defined(CONFIG_NOT_COHERENT_CACHE)
  1585. vfree(coherence_data);
  1586. #endif
  1587. }
  1588. module_init(fsl_diu_init);
  1589. module_exit(fsl_diu_exit);
  1590. MODULE_AUTHOR("York Sun <yorksun@freescale.com>");
  1591. MODULE_DESCRIPTION("Freescale DIU framebuffer driver");
  1592. MODULE_LICENSE("GPL");
  1593. module_param_named(mode, fb_mode, charp, 0);
  1594. MODULE_PARM_DESC(mode,
  1595. "Specify resolution as \"<xres>x<yres>[-<bpp>][@<refresh>]\" ");
  1596. module_param_named(bpp, default_bpp, ulong, 0);
  1597. MODULE_PARM_DESC(bpp, "Specify bit-per-pixel if not specified mode");
  1598. module_param_named(monitor, monitor_port, int, 0);
  1599. MODULE_PARM_DESC(monitor,
  1600. "Specify the monitor port (0, 1 or 2) if supported by the platform");