fsl-diu-fb.c 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834
  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. {
  1317. struct device_node *np = ofdev->dev.of_node;
  1318. struct mfb_info *mfbi;
  1319. phys_addr_t dummy_ad_addr;
  1320. int ret, i, error = 0;
  1321. struct resource res;
  1322. struct fsl_diu_data *machine_data;
  1323. int diu_mode;
  1324. machine_data = kzalloc(sizeof(struct fsl_diu_data), GFP_KERNEL);
  1325. if (!machine_data)
  1326. return -ENOMEM;
  1327. for (i = 0; i < ARRAY_SIZE(machine_data->fsl_diu_info); i++) {
  1328. machine_data->fsl_diu_info[i] =
  1329. framebuffer_alloc(sizeof(struct mfb_info), &ofdev->dev);
  1330. if (!machine_data->fsl_diu_info[i]) {
  1331. dev_err(&ofdev->dev, "cannot allocate memory\n");
  1332. ret = -ENOMEM;
  1333. goto error2;
  1334. }
  1335. mfbi = machine_data->fsl_diu_info[i]->par;
  1336. memcpy(mfbi, &mfb_template[i], sizeof(struct mfb_info));
  1337. mfbi->parent = machine_data;
  1338. if (mfbi->index == 0) {
  1339. const u8 *prop;
  1340. int len;
  1341. /* Get EDID */
  1342. prop = of_get_property(np, "edid", &len);
  1343. if (prop && len == EDID_LENGTH)
  1344. mfbi->edid_data = kmemdup(prop, EDID_LENGTH,
  1345. GFP_KERNEL);
  1346. }
  1347. }
  1348. ret = of_address_to_resource(np, 0, &res);
  1349. if (ret) {
  1350. dev_err(&ofdev->dev, "could not obtain DIU address\n");
  1351. goto error;
  1352. }
  1353. if (!res.start) {
  1354. dev_err(&ofdev->dev, "invalid DIU address\n");
  1355. goto error;
  1356. }
  1357. dev_dbg(&ofdev->dev, "%s, res.start: 0x%08x\n", __func__, res.start);
  1358. dr.diu_reg = ioremap(res.start, sizeof(struct diu));
  1359. if (!dr.diu_reg) {
  1360. dev_err(&ofdev->dev, "Err: can't map DIU registers!\n");
  1361. ret = -EFAULT;
  1362. goto error2;
  1363. }
  1364. diu_mode = in_be32(&dr.diu_reg->diu_mode);
  1365. if (diu_mode != MFB_MODE1)
  1366. out_be32(&dr.diu_reg->diu_mode, 0); /* disable DIU */
  1367. /* Get the IRQ of the DIU */
  1368. machine_data->irq = irq_of_parse_and_map(np, 0);
  1369. if (!machine_data->irq) {
  1370. dev_err(&ofdev->dev, "could not get DIU IRQ\n");
  1371. ret = -EINVAL;
  1372. goto error;
  1373. }
  1374. machine_data->monitor_port = monitor_port;
  1375. /* Area descriptor memory pool aligns to 64-bit boundary */
  1376. if (allocate_buf(&ofdev->dev, &pool.ad,
  1377. sizeof(struct diu_ad) * FSL_AOI_NUM, 8))
  1378. return -ENOMEM;
  1379. /* Get memory for Gamma Table - 32-byte aligned memory */
  1380. if (allocate_buf(&ofdev->dev, &pool.gamma, 768, 32)) {
  1381. ret = -ENOMEM;
  1382. goto error;
  1383. }
  1384. /* For performance, cursor bitmap buffer aligns to 32-byte boundary */
  1385. if (allocate_buf(&ofdev->dev, &pool.cursor, MAX_CURS * MAX_CURS * 2,
  1386. 32)) {
  1387. ret = -ENOMEM;
  1388. goto error;
  1389. }
  1390. i = ARRAY_SIZE(machine_data->fsl_diu_info);
  1391. machine_data->dummy_ad = (struct diu_ad *)
  1392. ((u32)pool.ad.vaddr + pool.ad.offset) + i;
  1393. machine_data->dummy_ad->paddr = pool.ad.paddr +
  1394. i * sizeof(struct diu_ad);
  1395. machine_data->dummy_aoi_virt = fsl_diu_alloc(64, &dummy_ad_addr);
  1396. if (!machine_data->dummy_aoi_virt) {
  1397. ret = -ENOMEM;
  1398. goto error;
  1399. }
  1400. machine_data->dummy_ad->addr = cpu_to_le32(dummy_ad_addr);
  1401. machine_data->dummy_ad->pix_fmt = 0x88882317;
  1402. machine_data->dummy_ad->src_size_g_alpha = cpu_to_le32((4 << 12) | 4);
  1403. machine_data->dummy_ad->aoi_size = cpu_to_le32((4 << 16) | 2);
  1404. machine_data->dummy_ad->offset_xyi = 0;
  1405. machine_data->dummy_ad->offset_xyd = 0;
  1406. machine_data->dummy_ad->next_ad = 0;
  1407. /*
  1408. * Let DIU display splash screen if it was pre-initialized
  1409. * by the bootloader, set dummy area descriptor otherwise.
  1410. */
  1411. if (diu_mode != MFB_MODE1)
  1412. out_be32(&dr.diu_reg->desc[0], machine_data->dummy_ad->paddr);
  1413. out_be32(&dr.diu_reg->desc[1], machine_data->dummy_ad->paddr);
  1414. out_be32(&dr.diu_reg->desc[2], machine_data->dummy_ad->paddr);
  1415. for (i = 0; i < ARRAY_SIZE(machine_data->fsl_diu_info); i++) {
  1416. machine_data->fsl_diu_info[i]->fix.smem_start = 0;
  1417. mfbi = machine_data->fsl_diu_info[i]->par;
  1418. mfbi->ad = (struct diu_ad *)((u32)pool.ad.vaddr
  1419. + pool.ad.offset) + i;
  1420. mfbi->ad->paddr = pool.ad.paddr + i * sizeof(struct diu_ad);
  1421. ret = install_fb(machine_data->fsl_diu_info[i]);
  1422. if (ret) {
  1423. dev_err(&ofdev->dev,
  1424. "Failed to register framebuffer %d\n",
  1425. i);
  1426. goto error;
  1427. }
  1428. }
  1429. if (request_irq_local(machine_data->irq)) {
  1430. dev_err(machine_data->fsl_diu_info[0]->dev,
  1431. "could not request irq for diu.");
  1432. goto error;
  1433. }
  1434. sysfs_attr_init(&machine_data->dev_attr.attr);
  1435. machine_data->dev_attr.attr.name = "monitor";
  1436. machine_data->dev_attr.attr.mode = S_IRUGO|S_IWUSR;
  1437. machine_data->dev_attr.show = show_monitor;
  1438. machine_data->dev_attr.store = store_monitor;
  1439. error = device_create_file(machine_data->fsl_diu_info[0]->dev,
  1440. &machine_data->dev_attr);
  1441. if (error) {
  1442. dev_err(machine_data->fsl_diu_info[0]->dev,
  1443. "could not create sysfs %s file\n",
  1444. machine_data->dev_attr.attr.name);
  1445. }
  1446. dev_set_drvdata(&ofdev->dev, machine_data);
  1447. return 0;
  1448. error:
  1449. for (i = ARRAY_SIZE(machine_data->fsl_diu_info);
  1450. i > 0; i--)
  1451. uninstall_fb(machine_data->fsl_diu_info[i - 1]);
  1452. if (pool.ad.vaddr)
  1453. free_buf(&ofdev->dev, &pool.ad,
  1454. sizeof(struct diu_ad) * FSL_AOI_NUM, 8);
  1455. if (pool.gamma.vaddr)
  1456. free_buf(&ofdev->dev, &pool.gamma, 768, 32);
  1457. if (pool.cursor.vaddr)
  1458. free_buf(&ofdev->dev, &pool.cursor, MAX_CURS * MAX_CURS * 2,
  1459. 32);
  1460. if (machine_data->dummy_aoi_virt)
  1461. fsl_diu_free(machine_data->dummy_aoi_virt, 64);
  1462. iounmap(dr.diu_reg);
  1463. error2:
  1464. for (i = 0; i < ARRAY_SIZE(machine_data->fsl_diu_info); i++)
  1465. if (machine_data->fsl_diu_info[i])
  1466. framebuffer_release(machine_data->fsl_diu_info[i]);
  1467. kfree(machine_data);
  1468. return ret;
  1469. }
  1470. static int fsl_diu_remove(struct platform_device *ofdev)
  1471. {
  1472. struct fsl_diu_data *machine_data;
  1473. int i;
  1474. machine_data = dev_get_drvdata(&ofdev->dev);
  1475. disable_lcdc(machine_data->fsl_diu_info[0]);
  1476. free_irq_local(machine_data->irq);
  1477. for (i = ARRAY_SIZE(machine_data->fsl_diu_info); i > 0; i--)
  1478. uninstall_fb(machine_data->fsl_diu_info[i - 1]);
  1479. if (pool.ad.vaddr)
  1480. free_buf(&ofdev->dev, &pool.ad,
  1481. sizeof(struct diu_ad) * FSL_AOI_NUM, 8);
  1482. if (pool.gamma.vaddr)
  1483. free_buf(&ofdev->dev, &pool.gamma, 768, 32);
  1484. if (pool.cursor.vaddr)
  1485. free_buf(&ofdev->dev, &pool.cursor, MAX_CURS * MAX_CURS * 2,
  1486. 32);
  1487. if (machine_data->dummy_aoi_virt)
  1488. fsl_diu_free(machine_data->dummy_aoi_virt, 64);
  1489. iounmap(dr.diu_reg);
  1490. for (i = 0; i < ARRAY_SIZE(machine_data->fsl_diu_info); i++)
  1491. if (machine_data->fsl_diu_info[i])
  1492. framebuffer_release(machine_data->fsl_diu_info[i]);
  1493. kfree(machine_data);
  1494. return 0;
  1495. }
  1496. #ifndef MODULE
  1497. static int __init fsl_diu_setup(char *options)
  1498. {
  1499. char *opt;
  1500. unsigned long val;
  1501. if (!options || !*options)
  1502. return 0;
  1503. while ((opt = strsep(&options, ",")) != NULL) {
  1504. if (!*opt)
  1505. continue;
  1506. if (!strncmp(opt, "monitor=", 8)) {
  1507. if (!strict_strtoul(opt + 8, 10, &val) && (val <= 2))
  1508. monitor_port = val;
  1509. } else if (!strncmp(opt, "bpp=", 4)) {
  1510. if (!strict_strtoul(opt + 4, 10, &val))
  1511. default_bpp = val;
  1512. } else
  1513. fb_mode = opt;
  1514. }
  1515. return 0;
  1516. }
  1517. #endif
  1518. static struct of_device_id fsl_diu_match[] = {
  1519. #ifdef CONFIG_PPC_MPC512x
  1520. {
  1521. .compatible = "fsl,mpc5121-diu",
  1522. },
  1523. #endif
  1524. {
  1525. .compatible = "fsl,diu",
  1526. },
  1527. {}
  1528. };
  1529. MODULE_DEVICE_TABLE(of, fsl_diu_match);
  1530. static struct platform_driver fsl_diu_driver = {
  1531. .driver = {
  1532. .name = "fsl_diu",
  1533. .owner = THIS_MODULE,
  1534. .of_match_table = fsl_diu_match,
  1535. },
  1536. .probe = fsl_diu_probe,
  1537. .remove = fsl_diu_remove,
  1538. .suspend = fsl_diu_suspend,
  1539. .resume = fsl_diu_resume,
  1540. };
  1541. static int __init fsl_diu_init(void)
  1542. {
  1543. #ifdef CONFIG_NOT_COHERENT_CACHE
  1544. struct device_node *np;
  1545. const u32 *prop;
  1546. #endif
  1547. int ret;
  1548. #ifndef MODULE
  1549. char *option;
  1550. /*
  1551. * For kernel boot options (in 'video=xxxfb:<options>' format)
  1552. */
  1553. if (fb_get_options("fslfb", &option))
  1554. return -ENODEV;
  1555. fsl_diu_setup(option);
  1556. #endif
  1557. printk(KERN_INFO "Freescale DIU driver\n");
  1558. #ifdef CONFIG_NOT_COHERENT_CACHE
  1559. np = of_find_node_by_type(NULL, "cpu");
  1560. if (!np) {
  1561. printk(KERN_ERR "Err: can't find device node 'cpu'\n");
  1562. return -ENODEV;
  1563. }
  1564. prop = of_get_property(np, "d-cache-size", NULL);
  1565. if (prop == NULL) {
  1566. of_node_put(np);
  1567. return -ENODEV;
  1568. }
  1569. /* Freescale PLRU requires 13/8 times the cache size to do a proper
  1570. displacement flush
  1571. */
  1572. coherence_data_size = *prop * 13;
  1573. coherence_data_size /= 8;
  1574. prop = of_get_property(np, "d-cache-line-size", NULL);
  1575. if (prop == NULL) {
  1576. of_node_put(np);
  1577. return -ENODEV;
  1578. }
  1579. d_cache_line_size = *prop;
  1580. of_node_put(np);
  1581. coherence_data = vmalloc(coherence_data_size);
  1582. if (!coherence_data)
  1583. return -ENOMEM;
  1584. #endif
  1585. ret = platform_driver_register(&fsl_diu_driver);
  1586. if (ret) {
  1587. printk(KERN_ERR
  1588. "fsl-diu: failed to register platform driver\n");
  1589. #if defined(CONFIG_NOT_COHERENT_CACHE)
  1590. vfree(coherence_data);
  1591. #endif
  1592. iounmap(dr.diu_reg);
  1593. }
  1594. return ret;
  1595. }
  1596. static void __exit fsl_diu_exit(void)
  1597. {
  1598. platform_driver_unregister(&fsl_diu_driver);
  1599. #if defined(CONFIG_NOT_COHERENT_CACHE)
  1600. vfree(coherence_data);
  1601. #endif
  1602. }
  1603. module_init(fsl_diu_init);
  1604. module_exit(fsl_diu_exit);
  1605. MODULE_AUTHOR("York Sun <yorksun@freescale.com>");
  1606. MODULE_DESCRIPTION("Freescale DIU framebuffer driver");
  1607. MODULE_LICENSE("GPL");
  1608. module_param_named(mode, fb_mode, charp, 0);
  1609. MODULE_PARM_DESC(mode,
  1610. "Specify resolution as \"<xres>x<yres>[-<bpp>][@<refresh>]\" ");
  1611. module_param_named(bpp, default_bpp, ulong, 0);
  1612. MODULE_PARM_DESC(bpp, "Specify bit-per-pixel if not specified mode");
  1613. module_param_named(monitor, monitor_port, int, 0);
  1614. MODULE_PARM_DESC(monitor,
  1615. "Specify the monitor port (0, 1 or 2) if supported by the platform");