fsl-diu-fb.c 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011
  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/spinlock.h>
  33. #include <linux/of_address.h>
  34. #include <linux/of_irq.h>
  35. #include <sysdev/fsl_soc.h>
  36. #include <linux/fsl-diu-fb.h>
  37. #include "edid.h"
  38. #define NUM_AOIS 5 /* 1 for plane 0, 2 for planes 1 & 2 each */
  39. /* HW cursor parameters */
  40. #define MAX_CURS 32
  41. /* INT_STATUS/INT_MASK field descriptions */
  42. #define INT_VSYNC 0x01 /* Vsync interrupt */
  43. #define INT_VSYNC_WB 0x02 /* Vsync interrupt for write back operation */
  44. #define INT_UNDRUN 0x04 /* Under run exception interrupt */
  45. #define INT_PARERR 0x08 /* Display parameters error interrupt */
  46. #define INT_LS_BF_VS 0x10 /* Lines before vsync. interrupt */
  47. /*
  48. * List of supported video modes
  49. *
  50. * The first entry is the default video mode. The remain entries are in
  51. * order if increasing resolution and frequency. The 320x240-60 mode is
  52. * the initial AOI for the second and third planes.
  53. */
  54. static struct fb_videomode fsl_diu_mode_db[] = {
  55. {
  56. .refresh = 60,
  57. .xres = 1024,
  58. .yres = 768,
  59. .pixclock = 15385,
  60. .left_margin = 160,
  61. .right_margin = 24,
  62. .upper_margin = 29,
  63. .lower_margin = 3,
  64. .hsync_len = 136,
  65. .vsync_len = 6,
  66. .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  67. .vmode = FB_VMODE_NONINTERLACED
  68. },
  69. {
  70. .refresh = 60,
  71. .xres = 320,
  72. .yres = 240,
  73. .pixclock = 79440,
  74. .left_margin = 16,
  75. .right_margin = 16,
  76. .upper_margin = 16,
  77. .lower_margin = 5,
  78. .hsync_len = 48,
  79. .vsync_len = 1,
  80. .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  81. .vmode = FB_VMODE_NONINTERLACED
  82. },
  83. {
  84. .refresh = 60,
  85. .xres = 640,
  86. .yres = 480,
  87. .pixclock = 39722,
  88. .left_margin = 48,
  89. .right_margin = 16,
  90. .upper_margin = 33,
  91. .lower_margin = 10,
  92. .hsync_len = 96,
  93. .vsync_len = 2,
  94. .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  95. .vmode = FB_VMODE_NONINTERLACED
  96. },
  97. {
  98. .refresh = 72,
  99. .xres = 640,
  100. .yres = 480,
  101. .pixclock = 32052,
  102. .left_margin = 128,
  103. .right_margin = 24,
  104. .upper_margin = 28,
  105. .lower_margin = 9,
  106. .hsync_len = 40,
  107. .vsync_len = 3,
  108. .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  109. .vmode = FB_VMODE_NONINTERLACED
  110. },
  111. {
  112. .refresh = 75,
  113. .xres = 640,
  114. .yres = 480,
  115. .pixclock = 31747,
  116. .left_margin = 120,
  117. .right_margin = 16,
  118. .upper_margin = 16,
  119. .lower_margin = 1,
  120. .hsync_len = 64,
  121. .vsync_len = 3,
  122. .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  123. .vmode = FB_VMODE_NONINTERLACED
  124. },
  125. {
  126. .refresh = 90,
  127. .xres = 640,
  128. .yres = 480,
  129. .pixclock = 25057,
  130. .left_margin = 120,
  131. .right_margin = 32,
  132. .upper_margin = 14,
  133. .lower_margin = 25,
  134. .hsync_len = 40,
  135. .vsync_len = 14,
  136. .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  137. .vmode = FB_VMODE_NONINTERLACED
  138. },
  139. {
  140. .refresh = 100,
  141. .xres = 640,
  142. .yres = 480,
  143. .pixclock = 22272,
  144. .left_margin = 48,
  145. .right_margin = 32,
  146. .upper_margin = 17,
  147. .lower_margin = 22,
  148. .hsync_len = 128,
  149. .vsync_len = 12,
  150. .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  151. .vmode = FB_VMODE_NONINTERLACED
  152. },
  153. {
  154. .refresh = 60,
  155. .xres = 800,
  156. .yres = 480,
  157. .pixclock = 33805,
  158. .left_margin = 96,
  159. .right_margin = 24,
  160. .upper_margin = 10,
  161. .lower_margin = 3,
  162. .hsync_len = 72,
  163. .vsync_len = 7,
  164. .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  165. .vmode = FB_VMODE_NONINTERLACED
  166. },
  167. {
  168. .refresh = 60,
  169. .xres = 800,
  170. .yres = 600,
  171. .pixclock = 25000,
  172. .left_margin = 88,
  173. .right_margin = 40,
  174. .upper_margin = 23,
  175. .lower_margin = 1,
  176. .hsync_len = 128,
  177. .vsync_len = 4,
  178. .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  179. .vmode = FB_VMODE_NONINTERLACED
  180. },
  181. {
  182. .refresh = 60,
  183. .xres = 854,
  184. .yres = 480,
  185. .pixclock = 31518,
  186. .left_margin = 104,
  187. .right_margin = 16,
  188. .upper_margin = 13,
  189. .lower_margin = 1,
  190. .hsync_len = 88,
  191. .vsync_len = 3,
  192. .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  193. .vmode = FB_VMODE_NONINTERLACED
  194. },
  195. {
  196. .refresh = 70,
  197. .xres = 1024,
  198. .yres = 768,
  199. .pixclock = 16886,
  200. .left_margin = 3,
  201. .right_margin = 3,
  202. .upper_margin = 2,
  203. .lower_margin = 2,
  204. .hsync_len = 40,
  205. .vsync_len = 18,
  206. .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  207. .vmode = FB_VMODE_NONINTERLACED
  208. },
  209. {
  210. .refresh = 75,
  211. .xres = 1024,
  212. .yres = 768,
  213. .pixclock = 15009,
  214. .left_margin = 3,
  215. .right_margin = 3,
  216. .upper_margin = 2,
  217. .lower_margin = 2,
  218. .hsync_len = 80,
  219. .vsync_len = 32,
  220. .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  221. .vmode = FB_VMODE_NONINTERLACED
  222. },
  223. {
  224. .refresh = 60,
  225. .xres = 1280,
  226. .yres = 480,
  227. .pixclock = 18939,
  228. .left_margin = 353,
  229. .right_margin = 47,
  230. .upper_margin = 39,
  231. .lower_margin = 4,
  232. .hsync_len = 8,
  233. .vsync_len = 2,
  234. .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  235. .vmode = FB_VMODE_NONINTERLACED
  236. },
  237. {
  238. .refresh = 60,
  239. .xres = 1280,
  240. .yres = 720,
  241. .pixclock = 13426,
  242. .left_margin = 192,
  243. .right_margin = 64,
  244. .upper_margin = 22,
  245. .lower_margin = 1,
  246. .hsync_len = 136,
  247. .vsync_len = 3,
  248. .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  249. .vmode = FB_VMODE_NONINTERLACED
  250. },
  251. {
  252. .refresh = 60,
  253. .xres = 1280,
  254. .yres = 1024,
  255. .pixclock = 9375,
  256. .left_margin = 38,
  257. .right_margin = 128,
  258. .upper_margin = 2,
  259. .lower_margin = 7,
  260. .hsync_len = 216,
  261. .vsync_len = 37,
  262. .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  263. .vmode = FB_VMODE_NONINTERLACED
  264. },
  265. {
  266. .refresh = 70,
  267. .xres = 1280,
  268. .yres = 1024,
  269. .pixclock = 9380,
  270. .left_margin = 6,
  271. .right_margin = 6,
  272. .upper_margin = 4,
  273. .lower_margin = 4,
  274. .hsync_len = 60,
  275. .vsync_len = 94,
  276. .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  277. .vmode = FB_VMODE_NONINTERLACED
  278. },
  279. {
  280. .refresh = 75,
  281. .xres = 1280,
  282. .yres = 1024,
  283. .pixclock = 9380,
  284. .left_margin = 6,
  285. .right_margin = 6,
  286. .upper_margin = 4,
  287. .lower_margin = 4,
  288. .hsync_len = 60,
  289. .vsync_len = 15,
  290. .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  291. .vmode = FB_VMODE_NONINTERLACED
  292. },
  293. {
  294. .refresh = 60,
  295. .xres = 1920,
  296. .yres = 1080,
  297. .pixclock = 5787,
  298. .left_margin = 328,
  299. .right_margin = 120,
  300. .upper_margin = 34,
  301. .lower_margin = 1,
  302. .hsync_len = 208,
  303. .vsync_len = 3,
  304. .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  305. .vmode = FB_VMODE_NONINTERLACED
  306. },
  307. };
  308. static char *fb_mode;
  309. static unsigned long default_bpp = 32;
  310. static enum fsl_diu_monitor_port monitor_port;
  311. static char *monitor_string;
  312. #if defined(CONFIG_NOT_COHERENT_CACHE)
  313. static u8 *coherence_data;
  314. static size_t coherence_data_size;
  315. static unsigned int d_cache_line_size;
  316. #endif
  317. static DEFINE_SPINLOCK(diu_lock);
  318. enum mfb_index {
  319. PLANE0 = 0, /* Plane 0, only one AOI that fills the screen */
  320. PLANE1_AOI0, /* Plane 1, first AOI */
  321. PLANE1_AOI1, /* Plane 1, second AOI */
  322. PLANE2_AOI0, /* Plane 2, first AOI */
  323. PLANE2_AOI1, /* Plane 2, second AOI */
  324. };
  325. struct mfb_info {
  326. enum mfb_index index;
  327. char *id;
  328. int registered;
  329. unsigned long pseudo_palette[16];
  330. struct diu_ad *ad;
  331. unsigned char g_alpha;
  332. unsigned int count;
  333. int x_aoi_d; /* aoi display x offset to physical screen */
  334. int y_aoi_d; /* aoi display y offset to physical screen */
  335. struct fsl_diu_data *parent;
  336. };
  337. /**
  338. * struct fsl_diu_data - per-DIU data structure
  339. * @dma_addr: DMA address of this structure
  340. * @fsl_diu_info: fb_info objects, one per AOI
  341. * @dev_attr: sysfs structure
  342. * @irq: IRQ
  343. * @monitor_port: the monitor port this DIU is connected to
  344. * @diu_reg: pointer to the DIU hardware registers
  345. * @reg_lock: spinlock for register access
  346. * @dummy_aoi: video buffer for the 4x4 32-bit dummy AOI
  347. * dummy_ad: DIU Area Descriptor for the dummy AOI
  348. * @ad[]: Area Descriptors for each real AOI
  349. * @gamma: gamma color table
  350. * @cursor: hardware cursor data
  351. *
  352. * This data structure must be allocated with 32-byte alignment, so that the
  353. * internal fields can be aligned properly.
  354. */
  355. struct fsl_diu_data {
  356. dma_addr_t dma_addr;
  357. struct fb_info fsl_diu_info[NUM_AOIS];
  358. struct mfb_info mfb[NUM_AOIS];
  359. struct device_attribute dev_attr;
  360. unsigned int irq;
  361. enum fsl_diu_monitor_port monitor_port;
  362. struct diu __iomem *diu_reg;
  363. spinlock_t reg_lock;
  364. u8 dummy_aoi[4 * 4 * 4];
  365. struct diu_ad dummy_ad __aligned(8);
  366. struct diu_ad ad[NUM_AOIS] __aligned(8);
  367. u8 gamma[256 * 3] __aligned(32);
  368. /* It's easier to parse the cursor data as little-endian */
  369. __le16 cursor[MAX_CURS * MAX_CURS] __aligned(32);
  370. /* Blank cursor data -- used to hide the cursor */
  371. __le16 blank_cursor[MAX_CURS * MAX_CURS] __aligned(32);
  372. uint8_t edid_data[EDID_LENGTH];
  373. bool has_edid;
  374. } __aligned(32);
  375. /* Determine the DMA address of a member of the fsl_diu_data structure */
  376. #define DMA_ADDR(p, f) ((p)->dma_addr + offsetof(struct fsl_diu_data, f))
  377. static struct mfb_info mfb_template[] = {
  378. {
  379. .index = PLANE0,
  380. .id = "Panel0",
  381. .registered = 0,
  382. .count = 0,
  383. .x_aoi_d = 0,
  384. .y_aoi_d = 0,
  385. },
  386. {
  387. .index = PLANE1_AOI0,
  388. .id = "Panel1 AOI0",
  389. .registered = 0,
  390. .g_alpha = 0xff,
  391. .count = 0,
  392. .x_aoi_d = 0,
  393. .y_aoi_d = 0,
  394. },
  395. {
  396. .index = PLANE1_AOI1,
  397. .id = "Panel1 AOI1",
  398. .registered = 0,
  399. .g_alpha = 0xff,
  400. .count = 0,
  401. .x_aoi_d = 0,
  402. .y_aoi_d = 480,
  403. },
  404. {
  405. .index = PLANE2_AOI0,
  406. .id = "Panel2 AOI0",
  407. .registered = 0,
  408. .g_alpha = 0xff,
  409. .count = 0,
  410. .x_aoi_d = 640,
  411. .y_aoi_d = 0,
  412. },
  413. {
  414. .index = PLANE2_AOI1,
  415. .id = "Panel2 AOI1",
  416. .registered = 0,
  417. .g_alpha = 0xff,
  418. .count = 0,
  419. .x_aoi_d = 640,
  420. .y_aoi_d = 480,
  421. },
  422. };
  423. #ifdef DEBUG
  424. static void __attribute__ ((unused)) fsl_diu_dump(struct diu __iomem *hw)
  425. {
  426. mb();
  427. pr_debug("DIU: desc=%08x,%08x,%08x, gamma=%08x pallete=%08x "
  428. "cursor=%08x curs_pos=%08x diu_mode=%08x bgnd=%08x "
  429. "disp_size=%08x hsyn_para=%08x vsyn_para=%08x syn_pol=%08x "
  430. "thresholds=%08x int_mask=%08x plut=%08x\n",
  431. hw->desc[0], hw->desc[1], hw->desc[2], hw->gamma,
  432. hw->pallete, hw->cursor, hw->curs_pos, hw->diu_mode,
  433. hw->bgnd, hw->disp_size, hw->hsyn_para, hw->vsyn_para,
  434. hw->syn_pol, hw->thresholds, hw->int_mask, hw->plut);
  435. rmb();
  436. }
  437. #endif
  438. /**
  439. * fsl_diu_name_to_port - convert a port name to a monitor port enum
  440. *
  441. * Takes the name of a monitor port ("dvi", "lvds", or "dlvds") and returns
  442. * the enum fsl_diu_monitor_port that corresponds to that string.
  443. *
  444. * For compatibility with older versions, a number ("0", "1", or "2") is also
  445. * supported.
  446. *
  447. * If the string is unknown, DVI is assumed.
  448. *
  449. * If the particular port is not supported by the platform, another port
  450. * (platform-specific) is chosen instead.
  451. */
  452. static enum fsl_diu_monitor_port fsl_diu_name_to_port(const char *s)
  453. {
  454. enum fsl_diu_monitor_port port = FSL_DIU_PORT_DVI;
  455. unsigned long val;
  456. if (s) {
  457. if (!kstrtoul(s, 10, &val) && (val <= 2))
  458. port = (enum fsl_diu_monitor_port) val;
  459. else if (strncmp(s, "lvds", 4) == 0)
  460. port = FSL_DIU_PORT_LVDS;
  461. else if (strncmp(s, "dlvds", 5) == 0)
  462. port = FSL_DIU_PORT_DLVDS;
  463. }
  464. if (diu_ops.valid_monitor_port)
  465. port = diu_ops.valid_monitor_port(port);
  466. return port;
  467. }
  468. /*
  469. * Workaround for failed writing desc register of planes.
  470. * Needed with MPC5121 DIU rev 2.0 silicon.
  471. */
  472. void wr_reg_wa(u32 *reg, u32 val)
  473. {
  474. do {
  475. out_be32(reg, val);
  476. } while (in_be32(reg) != val);
  477. }
  478. static void fsl_diu_enable_panel(struct fb_info *info)
  479. {
  480. struct mfb_info *pmfbi, *cmfbi, *mfbi = info->par;
  481. struct diu_ad *ad = mfbi->ad;
  482. struct fsl_diu_data *data = mfbi->parent;
  483. struct diu __iomem *hw = data->diu_reg;
  484. switch (mfbi->index) {
  485. case PLANE0:
  486. wr_reg_wa(&hw->desc[0], ad->paddr);
  487. break;
  488. case PLANE1_AOI0:
  489. cmfbi = &data->mfb[2];
  490. if (hw->desc[1] != ad->paddr) { /* AOI0 closed */
  491. if (cmfbi->count > 0) /* AOI1 open */
  492. ad->next_ad =
  493. cpu_to_le32(cmfbi->ad->paddr);
  494. else
  495. ad->next_ad = 0;
  496. wr_reg_wa(&hw->desc[1], ad->paddr);
  497. }
  498. break;
  499. case PLANE2_AOI0:
  500. cmfbi = &data->mfb[4];
  501. if (hw->desc[2] != ad->paddr) { /* AOI0 closed */
  502. if (cmfbi->count > 0) /* AOI1 open */
  503. ad->next_ad =
  504. cpu_to_le32(cmfbi->ad->paddr);
  505. else
  506. ad->next_ad = 0;
  507. wr_reg_wa(&hw->desc[2], ad->paddr);
  508. }
  509. break;
  510. case PLANE1_AOI1:
  511. pmfbi = &data->mfb[1];
  512. ad->next_ad = 0;
  513. if (hw->desc[1] == data->dummy_ad.paddr)
  514. wr_reg_wa(&hw->desc[1], ad->paddr);
  515. else /* AOI0 open */
  516. pmfbi->ad->next_ad = cpu_to_le32(ad->paddr);
  517. break;
  518. case PLANE2_AOI1:
  519. pmfbi = &data->mfb[3];
  520. ad->next_ad = 0;
  521. if (hw->desc[2] == data->dummy_ad.paddr)
  522. wr_reg_wa(&hw->desc[2], ad->paddr);
  523. else /* AOI0 was open */
  524. pmfbi->ad->next_ad = cpu_to_le32(ad->paddr);
  525. break;
  526. }
  527. }
  528. static void fsl_diu_disable_panel(struct fb_info *info)
  529. {
  530. struct mfb_info *pmfbi, *cmfbi, *mfbi = info->par;
  531. struct diu_ad *ad = mfbi->ad;
  532. struct fsl_diu_data *data = mfbi->parent;
  533. struct diu __iomem *hw = data->diu_reg;
  534. switch (mfbi->index) {
  535. case PLANE0:
  536. wr_reg_wa(&hw->desc[0], 0);
  537. break;
  538. case PLANE1_AOI0:
  539. cmfbi = &data->mfb[2];
  540. if (cmfbi->count > 0) /* AOI1 is open */
  541. wr_reg_wa(&hw->desc[1], cmfbi->ad->paddr);
  542. /* move AOI1 to the first */
  543. else /* AOI1 was closed */
  544. wr_reg_wa(&hw->desc[1], data->dummy_ad.paddr);
  545. /* close AOI 0 */
  546. break;
  547. case PLANE2_AOI0:
  548. cmfbi = &data->mfb[4];
  549. if (cmfbi->count > 0) /* AOI1 is open */
  550. wr_reg_wa(&hw->desc[2], cmfbi->ad->paddr);
  551. /* move AOI1 to the first */
  552. else /* AOI1 was closed */
  553. wr_reg_wa(&hw->desc[2], data->dummy_ad.paddr);
  554. /* close AOI 0 */
  555. break;
  556. case PLANE1_AOI1:
  557. pmfbi = &data->mfb[1];
  558. if (hw->desc[1] != ad->paddr) {
  559. /* AOI1 is not the first in the chain */
  560. if (pmfbi->count > 0)
  561. /* AOI0 is open, must be the first */
  562. pmfbi->ad->next_ad = 0;
  563. } else /* AOI1 is the first in the chain */
  564. wr_reg_wa(&hw->desc[1], data->dummy_ad.paddr);
  565. /* close AOI 1 */
  566. break;
  567. case PLANE2_AOI1:
  568. pmfbi = &data->mfb[3];
  569. if (hw->desc[2] != ad->paddr) {
  570. /* AOI1 is not the first in the chain */
  571. if (pmfbi->count > 0)
  572. /* AOI0 is open, must be the first */
  573. pmfbi->ad->next_ad = 0;
  574. } else /* AOI1 is the first in the chain */
  575. wr_reg_wa(&hw->desc[2], data->dummy_ad.paddr);
  576. /* close AOI 1 */
  577. break;
  578. }
  579. }
  580. static void enable_lcdc(struct fb_info *info)
  581. {
  582. struct mfb_info *mfbi = info->par;
  583. struct fsl_diu_data *data = mfbi->parent;
  584. struct diu __iomem *hw = data->diu_reg;
  585. out_be32(&hw->diu_mode, MFB_MODE1);
  586. }
  587. static void disable_lcdc(struct fb_info *info)
  588. {
  589. struct mfb_info *mfbi = info->par;
  590. struct fsl_diu_data *data = mfbi->parent;
  591. struct diu __iomem *hw = data->diu_reg;
  592. out_be32(&hw->diu_mode, 0);
  593. }
  594. static void adjust_aoi_size_position(struct fb_var_screeninfo *var,
  595. struct fb_info *info)
  596. {
  597. struct mfb_info *lower_aoi_mfbi, *upper_aoi_mfbi, *mfbi = info->par;
  598. struct fsl_diu_data *data = mfbi->parent;
  599. int available_height, upper_aoi_bottom;
  600. enum mfb_index index = mfbi->index;
  601. int lower_aoi_is_open, upper_aoi_is_open;
  602. __u32 base_plane_width, base_plane_height, upper_aoi_height;
  603. base_plane_width = data->fsl_diu_info[0].var.xres;
  604. base_plane_height = data->fsl_diu_info[0].var.yres;
  605. if (mfbi->x_aoi_d < 0)
  606. mfbi->x_aoi_d = 0;
  607. if (mfbi->y_aoi_d < 0)
  608. mfbi->y_aoi_d = 0;
  609. switch (index) {
  610. case PLANE0:
  611. if (mfbi->x_aoi_d != 0)
  612. mfbi->x_aoi_d = 0;
  613. if (mfbi->y_aoi_d != 0)
  614. mfbi->y_aoi_d = 0;
  615. break;
  616. case PLANE1_AOI0:
  617. case PLANE2_AOI0:
  618. lower_aoi_mfbi = data->fsl_diu_info[index+1].par;
  619. lower_aoi_is_open = lower_aoi_mfbi->count > 0 ? 1 : 0;
  620. if (var->xres > base_plane_width)
  621. var->xres = base_plane_width;
  622. if ((mfbi->x_aoi_d + var->xres) > base_plane_width)
  623. mfbi->x_aoi_d = base_plane_width - var->xres;
  624. if (lower_aoi_is_open)
  625. available_height = lower_aoi_mfbi->y_aoi_d;
  626. else
  627. available_height = base_plane_height;
  628. if (var->yres > available_height)
  629. var->yres = available_height;
  630. if ((mfbi->y_aoi_d + var->yres) > available_height)
  631. mfbi->y_aoi_d = available_height - var->yres;
  632. break;
  633. case PLANE1_AOI1:
  634. case PLANE2_AOI1:
  635. upper_aoi_mfbi = data->fsl_diu_info[index-1].par;
  636. upper_aoi_height = data->fsl_diu_info[index-1].var.yres;
  637. upper_aoi_bottom = upper_aoi_mfbi->y_aoi_d + upper_aoi_height;
  638. upper_aoi_is_open = upper_aoi_mfbi->count > 0 ? 1 : 0;
  639. if (var->xres > base_plane_width)
  640. var->xres = base_plane_width;
  641. if ((mfbi->x_aoi_d + var->xres) > base_plane_width)
  642. mfbi->x_aoi_d = base_plane_width - var->xres;
  643. if (mfbi->y_aoi_d < 0)
  644. mfbi->y_aoi_d = 0;
  645. if (upper_aoi_is_open) {
  646. if (mfbi->y_aoi_d < upper_aoi_bottom)
  647. mfbi->y_aoi_d = upper_aoi_bottom;
  648. available_height = base_plane_height
  649. - upper_aoi_bottom;
  650. } else
  651. available_height = base_plane_height;
  652. if (var->yres > available_height)
  653. var->yres = available_height;
  654. if ((mfbi->y_aoi_d + var->yres) > base_plane_height)
  655. mfbi->y_aoi_d = base_plane_height - var->yres;
  656. break;
  657. }
  658. }
  659. /*
  660. * Checks to see if the hardware supports the state requested by var passed
  661. * in. This function does not alter the hardware state! If the var passed in
  662. * is slightly off by what the hardware can support then we alter the var
  663. * PASSED in to what we can do. If the hardware doesn't support mode change
  664. * a -EINVAL will be returned by the upper layers.
  665. */
  666. static int fsl_diu_check_var(struct fb_var_screeninfo *var,
  667. struct fb_info *info)
  668. {
  669. if (var->xres_virtual < var->xres)
  670. var->xres_virtual = var->xres;
  671. if (var->yres_virtual < var->yres)
  672. var->yres_virtual = var->yres;
  673. if (var->xoffset < 0)
  674. var->xoffset = 0;
  675. if (var->yoffset < 0)
  676. var->yoffset = 0;
  677. if (var->xoffset + info->var.xres > info->var.xres_virtual)
  678. var->xoffset = info->var.xres_virtual - info->var.xres;
  679. if (var->yoffset + info->var.yres > info->var.yres_virtual)
  680. var->yoffset = info->var.yres_virtual - info->var.yres;
  681. if ((var->bits_per_pixel != 32) && (var->bits_per_pixel != 24) &&
  682. (var->bits_per_pixel != 16))
  683. var->bits_per_pixel = default_bpp;
  684. switch (var->bits_per_pixel) {
  685. case 16:
  686. var->red.length = 5;
  687. var->red.offset = 11;
  688. var->red.msb_right = 0;
  689. var->green.length = 6;
  690. var->green.offset = 5;
  691. var->green.msb_right = 0;
  692. var->blue.length = 5;
  693. var->blue.offset = 0;
  694. var->blue.msb_right = 0;
  695. var->transp.length = 0;
  696. var->transp.offset = 0;
  697. var->transp.msb_right = 0;
  698. break;
  699. case 24:
  700. var->red.length = 8;
  701. var->red.offset = 0;
  702. var->red.msb_right = 0;
  703. var->green.length = 8;
  704. var->green.offset = 8;
  705. var->green.msb_right = 0;
  706. var->blue.length = 8;
  707. var->blue.offset = 16;
  708. var->blue.msb_right = 0;
  709. var->transp.length = 0;
  710. var->transp.offset = 0;
  711. var->transp.msb_right = 0;
  712. break;
  713. case 32:
  714. var->red.length = 8;
  715. var->red.offset = 16;
  716. var->red.msb_right = 0;
  717. var->green.length = 8;
  718. var->green.offset = 8;
  719. var->green.msb_right = 0;
  720. var->blue.length = 8;
  721. var->blue.offset = 0;
  722. var->blue.msb_right = 0;
  723. var->transp.length = 8;
  724. var->transp.offset = 24;
  725. var->transp.msb_right = 0;
  726. break;
  727. }
  728. var->height = -1;
  729. var->width = -1;
  730. var->grayscale = 0;
  731. /* Copy nonstd field to/from sync for fbset usage */
  732. var->sync |= var->nonstd;
  733. var->nonstd |= var->sync;
  734. adjust_aoi_size_position(var, info);
  735. return 0;
  736. }
  737. static void set_fix(struct fb_info *info)
  738. {
  739. struct fb_fix_screeninfo *fix = &info->fix;
  740. struct fb_var_screeninfo *var = &info->var;
  741. struct mfb_info *mfbi = info->par;
  742. strncpy(fix->id, mfbi->id, sizeof(fix->id));
  743. fix->line_length = var->xres_virtual * var->bits_per_pixel / 8;
  744. fix->type = FB_TYPE_PACKED_PIXELS;
  745. fix->accel = FB_ACCEL_NONE;
  746. fix->visual = FB_VISUAL_TRUECOLOR;
  747. fix->xpanstep = 1;
  748. fix->ypanstep = 1;
  749. }
  750. static void update_lcdc(struct fb_info *info)
  751. {
  752. struct fb_var_screeninfo *var = &info->var;
  753. struct mfb_info *mfbi = info->par;
  754. struct fsl_diu_data *data = mfbi->parent;
  755. struct diu __iomem *hw;
  756. int i, j;
  757. u8 *gamma_table_base;
  758. u32 temp;
  759. hw = data->diu_reg;
  760. if (diu_ops.set_monitor_port)
  761. diu_ops.set_monitor_port(data->monitor_port);
  762. gamma_table_base = data->gamma;
  763. /* Prep for DIU init - gamma table, cursor table */
  764. for (i = 0; i <= 2; i++)
  765. for (j = 0; j <= 255; j++)
  766. *gamma_table_base++ = j;
  767. if (diu_ops.set_gamma_table)
  768. diu_ops.set_gamma_table(data->monitor_port, data->gamma);
  769. disable_lcdc(info);
  770. /* Program DIU registers */
  771. out_be32(&hw->gamma, DMA_ADDR(data, gamma));
  772. out_be32(&hw->bgnd, 0x007F7F7F); /* Set background to grey */
  773. out_be32(&hw->disp_size, (var->yres << 16) | var->xres);
  774. /* Horizontal and vertical configuration register */
  775. temp = var->left_margin << 22 | /* BP_H */
  776. var->hsync_len << 11 | /* PW_H */
  777. var->right_margin; /* FP_H */
  778. out_be32(&hw->hsyn_para, temp);
  779. temp = var->upper_margin << 22 | /* BP_V */
  780. var->vsync_len << 11 | /* PW_V */
  781. var->lower_margin; /* FP_V */
  782. out_be32(&hw->vsyn_para, temp);
  783. diu_ops.set_pixel_clock(var->pixclock);
  784. #ifndef CONFIG_PPC_MPC512x
  785. /*
  786. * The PLUT register is defined differently on the MPC5121 than it
  787. * is on other SOCs. Unfortunately, there's no documentation that
  788. * explains how it's supposed to be programmed, so for now, we leave
  789. * it at the default value on the MPC5121.
  790. *
  791. * For other SOCs, program it for the highest priority, which will
  792. * reduce the chance of underrun. Technically, we should scale the
  793. * priority to match the screen resolution, but doing that properly
  794. * requires delicate fine-tuning for each use-case.
  795. */
  796. out_be32(&hw->plut, 0x01F5F666);
  797. #endif
  798. /* Enable the DIU */
  799. enable_lcdc(info);
  800. }
  801. static int map_video_memory(struct fb_info *info)
  802. {
  803. u32 smem_len = info->fix.line_length * info->var.yres_virtual;
  804. void *p;
  805. p = alloc_pages_exact(smem_len, GFP_DMA | __GFP_ZERO);
  806. if (!p) {
  807. dev_err(info->dev, "unable to allocate fb memory\n");
  808. return -ENOMEM;
  809. }
  810. mutex_lock(&info->mm_lock);
  811. info->screen_base = p;
  812. info->fix.smem_start = virt_to_phys(info->screen_base);
  813. info->fix.smem_len = smem_len;
  814. mutex_unlock(&info->mm_lock);
  815. info->screen_size = info->fix.smem_len;
  816. return 0;
  817. }
  818. static void unmap_video_memory(struct fb_info *info)
  819. {
  820. void *p = info->screen_base;
  821. size_t l = info->fix.smem_len;
  822. mutex_lock(&info->mm_lock);
  823. info->screen_base = NULL;
  824. info->fix.smem_start = 0;
  825. info->fix.smem_len = 0;
  826. mutex_unlock(&info->mm_lock);
  827. if (p)
  828. free_pages_exact(p, l);
  829. }
  830. /*
  831. * Using the fb_var_screeninfo in fb_info we set the aoi of this
  832. * particular framebuffer. It is a light version of fsl_diu_set_par.
  833. */
  834. static int fsl_diu_set_aoi(struct fb_info *info)
  835. {
  836. struct fb_var_screeninfo *var = &info->var;
  837. struct mfb_info *mfbi = info->par;
  838. struct diu_ad *ad = mfbi->ad;
  839. /* AOI should not be greater than display size */
  840. ad->offset_xyi = cpu_to_le32((var->yoffset << 16) | var->xoffset);
  841. ad->offset_xyd = cpu_to_le32((mfbi->y_aoi_d << 16) | mfbi->x_aoi_d);
  842. return 0;
  843. }
  844. /**
  845. * fsl_diu_get_pixel_format: return the pixel format for a given color depth
  846. *
  847. * The pixel format is a 32-bit value that determine which bits in each
  848. * pixel are to be used for each color. This is the default function used
  849. * if the platform does not define its own version.
  850. */
  851. static u32 fsl_diu_get_pixel_format(unsigned int bits_per_pixel)
  852. {
  853. #define PF_BYTE_F 0x10000000
  854. #define PF_ALPHA_C_MASK 0x0E000000
  855. #define PF_ALPHA_C_SHIFT 25
  856. #define PF_BLUE_C_MASK 0x01800000
  857. #define PF_BLUE_C_SHIFT 23
  858. #define PF_GREEN_C_MASK 0x00600000
  859. #define PF_GREEN_C_SHIFT 21
  860. #define PF_RED_C_MASK 0x00180000
  861. #define PF_RED_C_SHIFT 19
  862. #define PF_PALETTE 0x00040000
  863. #define PF_PIXEL_S_MASK 0x00030000
  864. #define PF_PIXEL_S_SHIFT 16
  865. #define PF_COMP_3_MASK 0x0000F000
  866. #define PF_COMP_3_SHIFT 12
  867. #define PF_COMP_2_MASK 0x00000F00
  868. #define PF_COMP_2_SHIFT 8
  869. #define PF_COMP_1_MASK 0x000000F0
  870. #define PF_COMP_1_SHIFT 4
  871. #define PF_COMP_0_MASK 0x0000000F
  872. #define PF_COMP_0_SHIFT 0
  873. #define MAKE_PF(alpha, red, green, blue, size, c0, c1, c2, c3) \
  874. cpu_to_le32(PF_BYTE_F | (alpha << PF_ALPHA_C_SHIFT) | \
  875. (blue << PF_BLUE_C_SHIFT) | (green << PF_GREEN_C_SHIFT) | \
  876. (red << PF_RED_C_SHIFT) | (c3 << PF_COMP_3_SHIFT) | \
  877. (c2 << PF_COMP_2_SHIFT) | (c1 << PF_COMP_1_SHIFT) | \
  878. (c0 << PF_COMP_0_SHIFT) | (size << PF_PIXEL_S_SHIFT))
  879. switch (bits_per_pixel) {
  880. case 32:
  881. /* 0x88883316 */
  882. return MAKE_PF(3, 2, 1, 0, 3, 8, 8, 8, 8);
  883. case 24:
  884. /* 0x88082219 */
  885. return MAKE_PF(4, 0, 1, 2, 2, 8, 8, 8, 0);
  886. case 16:
  887. /* 0x65053118 */
  888. return MAKE_PF(4, 2, 1, 0, 1, 5, 6, 5, 0);
  889. default:
  890. pr_err("fsl-diu: unsupported color depth %u\n", bits_per_pixel);
  891. return 0;
  892. }
  893. }
  894. /*
  895. * Copies a cursor image from user space to the proper place in driver
  896. * memory so that the hardware can display the cursor image.
  897. *
  898. * Cursor data is represented as a sequence of 'width' bits packed into bytes.
  899. * That is, the first 8 bits are in the first byte, the second 8 bits in the
  900. * second byte, and so on. Therefore, the each row of the cursor is (width +
  901. * 7) / 8 bytes of 'data'
  902. *
  903. * The DIU only supports cursors up to 32x32 (MAX_CURS). We reject cursors
  904. * larger than this, so we already know that 'width' <= 32. Therefore, we can
  905. * simplify our code by using a 32-bit big-endian integer ("line") to read in
  906. * a single line of pixels, and only look at the top 'width' bits of that
  907. * integer.
  908. *
  909. * This could result in an unaligned 32-bit read. For example, if the cursor
  910. * is 24x24, then the first three bytes of 'image' contain the pixel data for
  911. * the top line of the cursor. We do a 32-bit read of 'image', but we look
  912. * only at the top 24 bits. Then we increment 'image' by 3 bytes. The next
  913. * read is unaligned. The only problem is that we might read past the end of
  914. * 'image' by 1-3 bytes, but that should not cause any problems.
  915. */
  916. static void fsl_diu_load_cursor_image(struct fb_info *info,
  917. const void *image, uint16_t bg, uint16_t fg,
  918. unsigned int width, unsigned int height)
  919. {
  920. struct mfb_info *mfbi = info->par;
  921. struct fsl_diu_data *data = mfbi->parent;
  922. __le16 *cursor = data->cursor;
  923. __le16 _fg = cpu_to_le16(fg);
  924. __le16 _bg = cpu_to_le16(bg);
  925. unsigned int h, w;
  926. for (h = 0; h < height; h++) {
  927. uint32_t mask = 1 << 31;
  928. uint32_t line = be32_to_cpup(image);
  929. for (w = 0; w < width; w++) {
  930. cursor[w] = (line & mask) ? _fg : _bg;
  931. mask >>= 1;
  932. }
  933. cursor += MAX_CURS;
  934. image += DIV_ROUND_UP(width, 8);
  935. }
  936. }
  937. /*
  938. * Set a hardware cursor. The image data for the cursor is passed via the
  939. * fb_cursor object.
  940. */
  941. static int fsl_diu_cursor(struct fb_info *info, struct fb_cursor *cursor)
  942. {
  943. struct mfb_info *mfbi = info->par;
  944. struct fsl_diu_data *data = mfbi->parent;
  945. struct diu __iomem *hw = data->diu_reg;
  946. if (cursor->image.width > MAX_CURS || cursor->image.height > MAX_CURS)
  947. return -EINVAL;
  948. /* The cursor size has changed */
  949. if (cursor->set & FB_CUR_SETSIZE) {
  950. /*
  951. * The DIU cursor is a fixed size, so when we get this
  952. * message, instead of resizing the cursor, we just clear
  953. * all the image data, in expectation of new data. However,
  954. * in tests this control does not appear to be normally
  955. * called.
  956. */
  957. memset(data->cursor, 0, sizeof(data->cursor));
  958. }
  959. /* The cursor position has changed (cursor->image.dx|dy) */
  960. if (cursor->set & FB_CUR_SETPOS) {
  961. uint32_t xx, yy;
  962. yy = (cursor->image.dy - info->var.yoffset) & 0x7ff;
  963. xx = (cursor->image.dx - info->var.xoffset) & 0x7ff;
  964. out_be32(&hw->curs_pos, yy << 16 | xx);
  965. }
  966. /*
  967. * FB_CUR_SETIMAGE - the cursor image has changed
  968. * FB_CUR_SETCMAP - the cursor colors has changed
  969. * FB_CUR_SETSHAPE - the cursor bitmask has changed
  970. */
  971. if (cursor->set & (FB_CUR_SETSHAPE | FB_CUR_SETCMAP | FB_CUR_SETIMAGE)) {
  972. unsigned int image_size =
  973. DIV_ROUND_UP(cursor->image.width, 8) * cursor->image.height;
  974. unsigned int image_words =
  975. DIV_ROUND_UP(image_size, sizeof(uint32_t));
  976. unsigned int bg_idx = cursor->image.bg_color;
  977. unsigned int fg_idx = cursor->image.fg_color;
  978. uint8_t buffer[image_size];
  979. uint32_t *image, *source, *mask;
  980. uint16_t fg, bg;
  981. unsigned int i;
  982. if (info->state != FBINFO_STATE_RUNNING)
  983. return 0;
  984. /*
  985. * Determine the size of the cursor image data. Normally,
  986. * it's 8x16.
  987. */
  988. image_size = DIV_ROUND_UP(cursor->image.width, 8) *
  989. cursor->image.height;
  990. bg = ((info->cmap.red[bg_idx] & 0xf8) << 7) |
  991. ((info->cmap.green[bg_idx] & 0xf8) << 2) |
  992. ((info->cmap.blue[bg_idx] & 0xf8) >> 3) |
  993. 1 << 15;
  994. fg = ((info->cmap.red[fg_idx] & 0xf8) << 7) |
  995. ((info->cmap.green[fg_idx] & 0xf8) << 2) |
  996. ((info->cmap.blue[fg_idx] & 0xf8) >> 3) |
  997. 1 << 15;
  998. /* Use 32-bit operations on the data to improve performance */
  999. image = (uint32_t *)buffer;
  1000. source = (uint32_t *)cursor->image.data;
  1001. mask = (uint32_t *)cursor->mask;
  1002. if (cursor->rop == ROP_XOR)
  1003. for (i = 0; i < image_words; i++)
  1004. image[i] = source[i] ^ mask[i];
  1005. else
  1006. for (i = 0; i < image_words; i++)
  1007. image[i] = source[i] & mask[i];
  1008. fsl_diu_load_cursor_image(info, image, bg, fg,
  1009. cursor->image.width, cursor->image.height);
  1010. }
  1011. /*
  1012. * Show or hide the cursor. The cursor data is always stored in the
  1013. * 'cursor' memory block, and the actual cursor position is always in
  1014. * the DIU's CURS_POS register. To hide the cursor, we redirect the
  1015. * CURSOR register to a blank cursor. The show the cursor, we
  1016. * redirect the CURSOR register to the real cursor data.
  1017. */
  1018. if (cursor->enable)
  1019. out_be32(&hw->cursor, DMA_ADDR(data, cursor));
  1020. else
  1021. out_be32(&hw->cursor, DMA_ADDR(data, blank_cursor));
  1022. return 0;
  1023. }
  1024. /*
  1025. * Using the fb_var_screeninfo in fb_info we set the resolution of this
  1026. * particular framebuffer. This function alters the fb_fix_screeninfo stored
  1027. * in fb_info. It does not alter var in fb_info since we are using that
  1028. * data. This means we depend on the data in var inside fb_info to be
  1029. * supported by the hardware. fsl_diu_check_var is always called before
  1030. * fsl_diu_set_par to ensure this.
  1031. */
  1032. static int fsl_diu_set_par(struct fb_info *info)
  1033. {
  1034. unsigned long len;
  1035. struct fb_var_screeninfo *var = &info->var;
  1036. struct mfb_info *mfbi = info->par;
  1037. struct fsl_diu_data *data = mfbi->parent;
  1038. struct diu_ad *ad = mfbi->ad;
  1039. struct diu __iomem *hw;
  1040. hw = data->diu_reg;
  1041. set_fix(info);
  1042. len = info->var.yres_virtual * info->fix.line_length;
  1043. /* Alloc & dealloc each time resolution/bpp change */
  1044. if (len != info->fix.smem_len) {
  1045. if (info->fix.smem_start)
  1046. unmap_video_memory(info);
  1047. /* Memory allocation for framebuffer */
  1048. if (map_video_memory(info)) {
  1049. dev_err(info->dev, "unable to allocate fb memory 1\n");
  1050. return -ENOMEM;
  1051. }
  1052. }
  1053. if (diu_ops.get_pixel_format)
  1054. ad->pix_fmt = diu_ops.get_pixel_format(data->monitor_port,
  1055. var->bits_per_pixel);
  1056. else
  1057. ad->pix_fmt = fsl_diu_get_pixel_format(var->bits_per_pixel);
  1058. ad->addr = cpu_to_le32(info->fix.smem_start);
  1059. ad->src_size_g_alpha = cpu_to_le32((var->yres_virtual << 12) |
  1060. var->xres_virtual) | mfbi->g_alpha;
  1061. /* AOI should not be greater than display size */
  1062. ad->aoi_size = cpu_to_le32((var->yres << 16) | var->xres);
  1063. ad->offset_xyi = cpu_to_le32((var->yoffset << 16) | var->xoffset);
  1064. ad->offset_xyd = cpu_to_le32((mfbi->y_aoi_d << 16) | mfbi->x_aoi_d);
  1065. /* Disable chroma keying function */
  1066. ad->ckmax_r = 0;
  1067. ad->ckmax_g = 0;
  1068. ad->ckmax_b = 0;
  1069. ad->ckmin_r = 255;
  1070. ad->ckmin_g = 255;
  1071. ad->ckmin_b = 255;
  1072. if (mfbi->index == PLANE0)
  1073. update_lcdc(info);
  1074. return 0;
  1075. }
  1076. static inline __u32 CNVT_TOHW(__u32 val, __u32 width)
  1077. {
  1078. return ((val << width) + 0x7FFF - val) >> 16;
  1079. }
  1080. /*
  1081. * Set a single color register. The values supplied have a 16 bit magnitude
  1082. * which needs to be scaled in this function for the hardware. Things to take
  1083. * into consideration are how many color registers, if any, are supported with
  1084. * the current color visual. With truecolor mode no color palettes are
  1085. * supported. Here a pseudo palette is created which we store the value in
  1086. * pseudo_palette in struct fb_info. For pseudocolor mode we have a limited
  1087. * color palette.
  1088. */
  1089. static int fsl_diu_setcolreg(unsigned int regno, unsigned int red,
  1090. unsigned int green, unsigned int blue,
  1091. unsigned int transp, struct fb_info *info)
  1092. {
  1093. int ret = 1;
  1094. /*
  1095. * If greyscale is true, then we convert the RGB value
  1096. * to greyscale no matter what visual we are using.
  1097. */
  1098. if (info->var.grayscale)
  1099. red = green = blue = (19595 * red + 38470 * green +
  1100. 7471 * blue) >> 16;
  1101. switch (info->fix.visual) {
  1102. case FB_VISUAL_TRUECOLOR:
  1103. /*
  1104. * 16-bit True Colour. We encode the RGB value
  1105. * according to the RGB bitfield information.
  1106. */
  1107. if (regno < 16) {
  1108. u32 *pal = info->pseudo_palette;
  1109. u32 v;
  1110. red = CNVT_TOHW(red, info->var.red.length);
  1111. green = CNVT_TOHW(green, info->var.green.length);
  1112. blue = CNVT_TOHW(blue, info->var.blue.length);
  1113. transp = CNVT_TOHW(transp, info->var.transp.length);
  1114. v = (red << info->var.red.offset) |
  1115. (green << info->var.green.offset) |
  1116. (blue << info->var.blue.offset) |
  1117. (transp << info->var.transp.offset);
  1118. pal[regno] = v;
  1119. ret = 0;
  1120. }
  1121. break;
  1122. }
  1123. return ret;
  1124. }
  1125. /*
  1126. * Pan (or wrap, depending on the `vmode' field) the display using the
  1127. * 'xoffset' and 'yoffset' fields of the 'var' structure. If the values
  1128. * don't fit, return -EINVAL.
  1129. */
  1130. static int fsl_diu_pan_display(struct fb_var_screeninfo *var,
  1131. struct fb_info *info)
  1132. {
  1133. if ((info->var.xoffset == var->xoffset) &&
  1134. (info->var.yoffset == var->yoffset))
  1135. return 0; /* No change, do nothing */
  1136. if (var->xoffset < 0 || var->yoffset < 0
  1137. || var->xoffset + info->var.xres > info->var.xres_virtual
  1138. || var->yoffset + info->var.yres > info->var.yres_virtual)
  1139. return -EINVAL;
  1140. info->var.xoffset = var->xoffset;
  1141. info->var.yoffset = var->yoffset;
  1142. if (var->vmode & FB_VMODE_YWRAP)
  1143. info->var.vmode |= FB_VMODE_YWRAP;
  1144. else
  1145. info->var.vmode &= ~FB_VMODE_YWRAP;
  1146. fsl_diu_set_aoi(info);
  1147. return 0;
  1148. }
  1149. static int fsl_diu_ioctl(struct fb_info *info, unsigned int cmd,
  1150. unsigned long arg)
  1151. {
  1152. struct mfb_info *mfbi = info->par;
  1153. struct diu_ad *ad = mfbi->ad;
  1154. struct mfb_chroma_key ck;
  1155. unsigned char global_alpha;
  1156. struct aoi_display_offset aoi_d;
  1157. __u32 pix_fmt;
  1158. void __user *buf = (void __user *)arg;
  1159. if (!arg)
  1160. return -EINVAL;
  1161. dev_dbg(info->dev, "ioctl %08x (dir=%s%s type=%u nr=%u size=%u)\n", cmd,
  1162. _IOC_DIR(cmd) & _IOC_READ ? "R" : "",
  1163. _IOC_DIR(cmd) & _IOC_WRITE ? "W" : "",
  1164. _IOC_TYPE(cmd), _IOC_NR(cmd), _IOC_SIZE(cmd));
  1165. switch (cmd) {
  1166. case MFB_SET_PIXFMT_OLD:
  1167. dev_warn(info->dev,
  1168. "MFB_SET_PIXFMT value of 0x%08x is deprecated.\n",
  1169. MFB_SET_PIXFMT_OLD);
  1170. case MFB_SET_PIXFMT:
  1171. if (copy_from_user(&pix_fmt, buf, sizeof(pix_fmt)))
  1172. return -EFAULT;
  1173. ad->pix_fmt = pix_fmt;
  1174. break;
  1175. case MFB_GET_PIXFMT_OLD:
  1176. dev_warn(info->dev,
  1177. "MFB_GET_PIXFMT value of 0x%08x is deprecated.\n",
  1178. MFB_GET_PIXFMT_OLD);
  1179. case MFB_GET_PIXFMT:
  1180. pix_fmt = ad->pix_fmt;
  1181. if (copy_to_user(buf, &pix_fmt, sizeof(pix_fmt)))
  1182. return -EFAULT;
  1183. break;
  1184. case MFB_SET_AOID:
  1185. if (copy_from_user(&aoi_d, buf, sizeof(aoi_d)))
  1186. return -EFAULT;
  1187. mfbi->x_aoi_d = aoi_d.x_aoi_d;
  1188. mfbi->y_aoi_d = aoi_d.y_aoi_d;
  1189. fsl_diu_check_var(&info->var, info);
  1190. fsl_diu_set_aoi(info);
  1191. break;
  1192. case MFB_GET_AOID:
  1193. aoi_d.x_aoi_d = mfbi->x_aoi_d;
  1194. aoi_d.y_aoi_d = mfbi->y_aoi_d;
  1195. if (copy_to_user(buf, &aoi_d, sizeof(aoi_d)))
  1196. return -EFAULT;
  1197. break;
  1198. case MFB_GET_ALPHA:
  1199. global_alpha = mfbi->g_alpha;
  1200. if (copy_to_user(buf, &global_alpha, sizeof(global_alpha)))
  1201. return -EFAULT;
  1202. break;
  1203. case MFB_SET_ALPHA:
  1204. /* set panel information */
  1205. if (copy_from_user(&global_alpha, buf, sizeof(global_alpha)))
  1206. return -EFAULT;
  1207. ad->src_size_g_alpha = (ad->src_size_g_alpha & (~0xff)) |
  1208. (global_alpha & 0xff);
  1209. mfbi->g_alpha = global_alpha;
  1210. break;
  1211. case MFB_SET_CHROMA_KEY:
  1212. /* set panel winformation */
  1213. if (copy_from_user(&ck, buf, sizeof(ck)))
  1214. return -EFAULT;
  1215. if (ck.enable &&
  1216. (ck.red_max < ck.red_min ||
  1217. ck.green_max < ck.green_min ||
  1218. ck.blue_max < ck.blue_min))
  1219. return -EINVAL;
  1220. if (!ck.enable) {
  1221. ad->ckmax_r = 0;
  1222. ad->ckmax_g = 0;
  1223. ad->ckmax_b = 0;
  1224. ad->ckmin_r = 255;
  1225. ad->ckmin_g = 255;
  1226. ad->ckmin_b = 255;
  1227. } else {
  1228. ad->ckmax_r = ck.red_max;
  1229. ad->ckmax_g = ck.green_max;
  1230. ad->ckmax_b = ck.blue_max;
  1231. ad->ckmin_r = ck.red_min;
  1232. ad->ckmin_g = ck.green_min;
  1233. ad->ckmin_b = ck.blue_min;
  1234. }
  1235. break;
  1236. #ifdef CONFIG_PPC_MPC512x
  1237. case MFB_SET_GAMMA: {
  1238. struct fsl_diu_data *data = mfbi->parent;
  1239. if (copy_from_user(data->gamma, buf, sizeof(data->gamma)))
  1240. return -EFAULT;
  1241. setbits32(&data->diu_reg->gamma, 0); /* Force table reload */
  1242. break;
  1243. }
  1244. case MFB_GET_GAMMA: {
  1245. struct fsl_diu_data *data = mfbi->parent;
  1246. if (copy_to_user(buf, data->gamma, sizeof(data->gamma)))
  1247. return -EFAULT;
  1248. break;
  1249. }
  1250. #endif
  1251. default:
  1252. dev_err(info->dev, "unknown ioctl command (0x%08X)\n", cmd);
  1253. return -ENOIOCTLCMD;
  1254. }
  1255. return 0;
  1256. }
  1257. static inline void fsl_diu_enable_interrupts(struct fsl_diu_data *data)
  1258. {
  1259. u32 int_mask = INT_UNDRUN; /* enable underrun detection */
  1260. if (IS_ENABLED(CONFIG_NOT_COHERENT_CACHE))
  1261. int_mask |= INT_VSYNC; /* enable vertical sync */
  1262. clrbits32(&data->diu_reg->int_mask, int_mask);
  1263. }
  1264. /* turn on fb if count == 1
  1265. */
  1266. static int fsl_diu_open(struct fb_info *info, int user)
  1267. {
  1268. struct mfb_info *mfbi = info->par;
  1269. int res = 0;
  1270. /* free boot splash memory on first /dev/fb0 open */
  1271. if ((mfbi->index == PLANE0) && diu_ops.release_bootmem)
  1272. diu_ops.release_bootmem();
  1273. spin_lock(&diu_lock);
  1274. mfbi->count++;
  1275. if (mfbi->count == 1) {
  1276. fsl_diu_check_var(&info->var, info);
  1277. res = fsl_diu_set_par(info);
  1278. if (res < 0)
  1279. mfbi->count--;
  1280. else {
  1281. fsl_diu_enable_interrupts(mfbi->parent);
  1282. fsl_diu_enable_panel(info);
  1283. }
  1284. }
  1285. spin_unlock(&diu_lock);
  1286. return res;
  1287. }
  1288. /* turn off fb if count == 0
  1289. */
  1290. static int fsl_diu_release(struct fb_info *info, int user)
  1291. {
  1292. struct mfb_info *mfbi = info->par;
  1293. int res = 0;
  1294. spin_lock(&diu_lock);
  1295. mfbi->count--;
  1296. if (mfbi->count == 0) {
  1297. struct fsl_diu_data *data = mfbi->parent;
  1298. bool disable = true;
  1299. int i;
  1300. /* Disable interrupts only if all AOIs are closed */
  1301. for (i = 0; i < NUM_AOIS; i++) {
  1302. struct mfb_info *mi = data->fsl_diu_info[i].par;
  1303. if (mi->count)
  1304. disable = false;
  1305. }
  1306. if (disable)
  1307. out_be32(&data->diu_reg->int_mask, 0xffffffff);
  1308. fsl_diu_disable_panel(info);
  1309. }
  1310. spin_unlock(&diu_lock);
  1311. return res;
  1312. }
  1313. static struct fb_ops fsl_diu_ops = {
  1314. .owner = THIS_MODULE,
  1315. .fb_check_var = fsl_diu_check_var,
  1316. .fb_set_par = fsl_diu_set_par,
  1317. .fb_setcolreg = fsl_diu_setcolreg,
  1318. .fb_pan_display = fsl_diu_pan_display,
  1319. .fb_fillrect = cfb_fillrect,
  1320. .fb_copyarea = cfb_copyarea,
  1321. .fb_imageblit = cfb_imageblit,
  1322. .fb_ioctl = fsl_diu_ioctl,
  1323. .fb_open = fsl_diu_open,
  1324. .fb_release = fsl_diu_release,
  1325. .fb_cursor = fsl_diu_cursor,
  1326. };
  1327. static int install_fb(struct fb_info *info)
  1328. {
  1329. int rc;
  1330. struct mfb_info *mfbi = info->par;
  1331. struct fsl_diu_data *data = mfbi->parent;
  1332. const char *aoi_mode, *init_aoi_mode = "320x240";
  1333. struct fb_videomode *db = fsl_diu_mode_db;
  1334. unsigned int dbsize = ARRAY_SIZE(fsl_diu_mode_db);
  1335. int has_default_mode = 1;
  1336. info->var.activate = FB_ACTIVATE_NOW;
  1337. info->fbops = &fsl_diu_ops;
  1338. info->flags = FBINFO_DEFAULT | FBINFO_VIRTFB | FBINFO_PARTIAL_PAN_OK |
  1339. FBINFO_READS_FAST;
  1340. info->pseudo_palette = mfbi->pseudo_palette;
  1341. rc = fb_alloc_cmap(&info->cmap, 16, 0);
  1342. if (rc)
  1343. return rc;
  1344. if (mfbi->index == PLANE0) {
  1345. if (data->has_edid) {
  1346. /* Now build modedb from EDID */
  1347. fb_edid_to_monspecs(data->edid_data, &info->monspecs);
  1348. fb_videomode_to_modelist(info->monspecs.modedb,
  1349. info->monspecs.modedb_len,
  1350. &info->modelist);
  1351. db = info->monspecs.modedb;
  1352. dbsize = info->monspecs.modedb_len;
  1353. }
  1354. aoi_mode = fb_mode;
  1355. } else {
  1356. aoi_mode = init_aoi_mode;
  1357. }
  1358. rc = fb_find_mode(&info->var, info, aoi_mode, db, dbsize, NULL,
  1359. default_bpp);
  1360. if (!rc) {
  1361. /*
  1362. * For plane 0 we continue and look into
  1363. * driver's internal modedb.
  1364. */
  1365. if ((mfbi->index == PLANE0) && data->has_edid)
  1366. has_default_mode = 0;
  1367. else
  1368. return -EINVAL;
  1369. }
  1370. if (!has_default_mode) {
  1371. rc = fb_find_mode(&info->var, info, aoi_mode, fsl_diu_mode_db,
  1372. ARRAY_SIZE(fsl_diu_mode_db), NULL, default_bpp);
  1373. if (rc)
  1374. has_default_mode = 1;
  1375. }
  1376. /* Still not found, use preferred mode from database if any */
  1377. if (!has_default_mode && info->monspecs.modedb) {
  1378. struct fb_monspecs *specs = &info->monspecs;
  1379. struct fb_videomode *modedb = &specs->modedb[0];
  1380. /*
  1381. * Get preferred timing. If not found,
  1382. * first mode in database will be used.
  1383. */
  1384. if (specs->misc & FB_MISC_1ST_DETAIL) {
  1385. int i;
  1386. for (i = 0; i < specs->modedb_len; i++) {
  1387. if (specs->modedb[i].flag & FB_MODE_IS_FIRST) {
  1388. modedb = &specs->modedb[i];
  1389. break;
  1390. }
  1391. }
  1392. }
  1393. info->var.bits_per_pixel = default_bpp;
  1394. fb_videomode_to_var(&info->var, modedb);
  1395. }
  1396. if (fsl_diu_check_var(&info->var, info)) {
  1397. dev_err(info->dev, "fsl_diu_check_var failed\n");
  1398. unmap_video_memory(info);
  1399. fb_dealloc_cmap(&info->cmap);
  1400. return -EINVAL;
  1401. }
  1402. if (register_framebuffer(info) < 0) {
  1403. dev_err(info->dev, "register_framebuffer failed\n");
  1404. unmap_video_memory(info);
  1405. fb_dealloc_cmap(&info->cmap);
  1406. return -EINVAL;
  1407. }
  1408. mfbi->registered = 1;
  1409. dev_info(info->dev, "%s registered successfully\n", mfbi->id);
  1410. return 0;
  1411. }
  1412. static void uninstall_fb(struct fb_info *info)
  1413. {
  1414. struct mfb_info *mfbi = info->par;
  1415. if (!mfbi->registered)
  1416. return;
  1417. unregister_framebuffer(info);
  1418. unmap_video_memory(info);
  1419. if (&info->cmap)
  1420. fb_dealloc_cmap(&info->cmap);
  1421. mfbi->registered = 0;
  1422. }
  1423. static irqreturn_t fsl_diu_isr(int irq, void *dev_id)
  1424. {
  1425. struct diu __iomem *hw = dev_id;
  1426. uint32_t status = in_be32(&hw->int_status);
  1427. if (status) {
  1428. /* This is the workaround for underrun */
  1429. if (status & INT_UNDRUN) {
  1430. out_be32(&hw->diu_mode, 0);
  1431. udelay(1);
  1432. out_be32(&hw->diu_mode, 1);
  1433. }
  1434. #if defined(CONFIG_NOT_COHERENT_CACHE)
  1435. else if (status & INT_VSYNC) {
  1436. unsigned int i;
  1437. for (i = 0; i < coherence_data_size;
  1438. i += d_cache_line_size)
  1439. __asm__ __volatile__ (
  1440. "dcbz 0, %[input]"
  1441. ::[input]"r"(&coherence_data[i]));
  1442. }
  1443. #endif
  1444. return IRQ_HANDLED;
  1445. }
  1446. return IRQ_NONE;
  1447. }
  1448. #ifdef CONFIG_PM
  1449. /*
  1450. * Power management hooks. Note that we won't be called from IRQ context,
  1451. * unlike the blank functions above, so we may sleep.
  1452. */
  1453. static int fsl_diu_suspend(struct platform_device *ofdev, pm_message_t state)
  1454. {
  1455. struct fsl_diu_data *data;
  1456. data = dev_get_drvdata(&ofdev->dev);
  1457. disable_lcdc(data->fsl_diu_info);
  1458. return 0;
  1459. }
  1460. static int fsl_diu_resume(struct platform_device *ofdev)
  1461. {
  1462. struct fsl_diu_data *data;
  1463. unsigned int i;
  1464. data = dev_get_drvdata(&ofdev->dev);
  1465. fsl_diu_enable_interrupts(data);
  1466. update_lcdc(data->fsl_diu_info);
  1467. for (i = 0; i < NUM_AOIS; i++) {
  1468. if (data->mfb[i].count)
  1469. fsl_diu_enable_panel(&data->fsl_diu_info[i]);
  1470. }
  1471. return 0;
  1472. }
  1473. #else
  1474. #define fsl_diu_suspend NULL
  1475. #define fsl_diu_resume NULL
  1476. #endif /* CONFIG_PM */
  1477. static ssize_t store_monitor(struct device *device,
  1478. struct device_attribute *attr, const char *buf, size_t count)
  1479. {
  1480. enum fsl_diu_monitor_port old_monitor_port;
  1481. struct fsl_diu_data *data =
  1482. container_of(attr, struct fsl_diu_data, dev_attr);
  1483. old_monitor_port = data->monitor_port;
  1484. data->monitor_port = fsl_diu_name_to_port(buf);
  1485. if (old_monitor_port != data->monitor_port) {
  1486. /* All AOIs need adjust pixel format
  1487. * fsl_diu_set_par only change the pixsel format here
  1488. * unlikely to fail. */
  1489. unsigned int i;
  1490. for (i=0; i < NUM_AOIS; i++)
  1491. fsl_diu_set_par(&data->fsl_diu_info[i]);
  1492. }
  1493. return count;
  1494. }
  1495. static ssize_t show_monitor(struct device *device,
  1496. struct device_attribute *attr, char *buf)
  1497. {
  1498. struct fsl_diu_data *data =
  1499. container_of(attr, struct fsl_diu_data, dev_attr);
  1500. switch (data->monitor_port) {
  1501. case FSL_DIU_PORT_DVI:
  1502. return sprintf(buf, "DVI\n");
  1503. case FSL_DIU_PORT_LVDS:
  1504. return sprintf(buf, "Single-link LVDS\n");
  1505. case FSL_DIU_PORT_DLVDS:
  1506. return sprintf(buf, "Dual-link LVDS\n");
  1507. }
  1508. return 0;
  1509. }
  1510. static int fsl_diu_probe(struct platform_device *pdev)
  1511. {
  1512. struct device_node *np = pdev->dev.of_node;
  1513. struct mfb_info *mfbi;
  1514. struct fsl_diu_data *data;
  1515. dma_addr_t dma_addr; /* DMA addr of fsl_diu_data struct */
  1516. const void *prop;
  1517. unsigned int i;
  1518. int ret;
  1519. data = dmam_alloc_coherent(&pdev->dev, sizeof(struct fsl_diu_data),
  1520. &dma_addr, GFP_DMA | __GFP_ZERO);
  1521. if (!data)
  1522. return -ENOMEM;
  1523. data->dma_addr = dma_addr;
  1524. /*
  1525. * dma_alloc_coherent() uses a page allocator, so the address is
  1526. * always page-aligned. We need the memory to be 32-byte aligned,
  1527. * so that's good. However, if one day the allocator changes, we
  1528. * need to catch that. It's not worth the effort to handle unaligned
  1529. * alloctions now because it's highly unlikely to ever be a problem.
  1530. */
  1531. if ((unsigned long)data & 31) {
  1532. dev_err(&pdev->dev, "misaligned allocation");
  1533. ret = -ENOMEM;
  1534. goto error;
  1535. }
  1536. spin_lock_init(&data->reg_lock);
  1537. for (i = 0; i < NUM_AOIS; i++) {
  1538. struct fb_info *info = &data->fsl_diu_info[i];
  1539. info->device = &pdev->dev;
  1540. info->par = &data->mfb[i];
  1541. /*
  1542. * We store the physical address of the AD in the reserved
  1543. * 'paddr' field of the AD itself.
  1544. */
  1545. data->ad[i].paddr = DMA_ADDR(data, ad[i]);
  1546. info->fix.smem_start = 0;
  1547. /* Initialize the AOI data structure */
  1548. mfbi = info->par;
  1549. memcpy(mfbi, &mfb_template[i], sizeof(struct mfb_info));
  1550. mfbi->parent = data;
  1551. mfbi->ad = &data->ad[i];
  1552. }
  1553. /* Get the EDID data from the device tree, if present */
  1554. prop = of_get_property(np, "edid", &ret);
  1555. if (prop && ret == EDID_LENGTH) {
  1556. memcpy(data->edid_data, prop, EDID_LENGTH);
  1557. data->has_edid = true;
  1558. }
  1559. data->diu_reg = of_iomap(np, 0);
  1560. if (!data->diu_reg) {
  1561. dev_err(&pdev->dev, "cannot map DIU registers\n");
  1562. ret = -EFAULT;
  1563. goto error;
  1564. }
  1565. /* Get the IRQ of the DIU */
  1566. data->irq = irq_of_parse_and_map(np, 0);
  1567. if (!data->irq) {
  1568. dev_err(&pdev->dev, "could not get DIU IRQ\n");
  1569. ret = -EINVAL;
  1570. goto error;
  1571. }
  1572. data->monitor_port = monitor_port;
  1573. /* Initialize the dummy Area Descriptor */
  1574. data->dummy_ad.addr = cpu_to_le32(DMA_ADDR(data, dummy_aoi));
  1575. data->dummy_ad.pix_fmt = 0x88882317;
  1576. data->dummy_ad.src_size_g_alpha = cpu_to_le32((4 << 12) | 4);
  1577. data->dummy_ad.aoi_size = cpu_to_le32((4 << 16) | 2);
  1578. data->dummy_ad.offset_xyi = 0;
  1579. data->dummy_ad.offset_xyd = 0;
  1580. data->dummy_ad.next_ad = 0;
  1581. data->dummy_ad.paddr = DMA_ADDR(data, dummy_ad);
  1582. /*
  1583. * Let DIU continue to display splash screen if it was pre-initialized
  1584. * by the bootloader; otherwise, clear the display.
  1585. */
  1586. if (in_be32(&data->diu_reg->diu_mode) == MFB_MODE0)
  1587. out_be32(&data->diu_reg->desc[0], 0);
  1588. out_be32(&data->diu_reg->desc[1], data->dummy_ad.paddr);
  1589. out_be32(&data->diu_reg->desc[2], data->dummy_ad.paddr);
  1590. /*
  1591. * Older versions of U-Boot leave interrupts enabled, so disable
  1592. * all of them and clear the status register.
  1593. */
  1594. out_be32(&data->diu_reg->int_mask, 0xffffffff);
  1595. in_be32(&data->diu_reg->int_status);
  1596. ret = request_irq(data->irq, fsl_diu_isr, 0, "fsl-diu-fb",
  1597. data->diu_reg);
  1598. if (ret) {
  1599. dev_err(&pdev->dev, "could not claim irq\n");
  1600. goto error;
  1601. }
  1602. for (i = 0; i < NUM_AOIS; i++) {
  1603. ret = install_fb(&data->fsl_diu_info[i]);
  1604. if (ret) {
  1605. dev_err(&pdev->dev, "could not register fb %d\n", i);
  1606. free_irq(data->irq, data->diu_reg);
  1607. goto error;
  1608. }
  1609. }
  1610. sysfs_attr_init(&data->dev_attr.attr);
  1611. data->dev_attr.attr.name = "monitor";
  1612. data->dev_attr.attr.mode = S_IRUGO|S_IWUSR;
  1613. data->dev_attr.show = show_monitor;
  1614. data->dev_attr.store = store_monitor;
  1615. ret = device_create_file(&pdev->dev, &data->dev_attr);
  1616. if (ret) {
  1617. dev_err(&pdev->dev, "could not create sysfs file %s\n",
  1618. data->dev_attr.attr.name);
  1619. }
  1620. dev_set_drvdata(&pdev->dev, data);
  1621. return 0;
  1622. error:
  1623. for (i = 0; i < NUM_AOIS; i++)
  1624. uninstall_fb(&data->fsl_diu_info[i]);
  1625. iounmap(data->diu_reg);
  1626. return ret;
  1627. }
  1628. static int fsl_diu_remove(struct platform_device *pdev)
  1629. {
  1630. struct fsl_diu_data *data;
  1631. int i;
  1632. data = dev_get_drvdata(&pdev->dev);
  1633. disable_lcdc(&data->fsl_diu_info[0]);
  1634. free_irq(data->irq, data->diu_reg);
  1635. for (i = 0; i < NUM_AOIS; i++)
  1636. uninstall_fb(&data->fsl_diu_info[i]);
  1637. iounmap(data->diu_reg);
  1638. return 0;
  1639. }
  1640. #ifndef MODULE
  1641. static int __init fsl_diu_setup(char *options)
  1642. {
  1643. char *opt;
  1644. unsigned long val;
  1645. if (!options || !*options)
  1646. return 0;
  1647. while ((opt = strsep(&options, ",")) != NULL) {
  1648. if (!*opt)
  1649. continue;
  1650. if (!strncmp(opt, "monitor=", 8)) {
  1651. monitor_port = fsl_diu_name_to_port(opt + 8);
  1652. } else if (!strncmp(opt, "bpp=", 4)) {
  1653. if (!kstrtoul(opt + 4, 10, &val))
  1654. default_bpp = val;
  1655. } else
  1656. fb_mode = opt;
  1657. }
  1658. return 0;
  1659. }
  1660. #endif
  1661. static struct of_device_id fsl_diu_match[] = {
  1662. #ifdef CONFIG_PPC_MPC512x
  1663. {
  1664. .compatible = "fsl,mpc5121-diu",
  1665. },
  1666. #endif
  1667. {
  1668. .compatible = "fsl,diu",
  1669. },
  1670. {}
  1671. };
  1672. MODULE_DEVICE_TABLE(of, fsl_diu_match);
  1673. static struct platform_driver fsl_diu_driver = {
  1674. .driver = {
  1675. .name = "fsl-diu-fb",
  1676. .of_match_table = fsl_diu_match,
  1677. },
  1678. .probe = fsl_diu_probe,
  1679. .remove = fsl_diu_remove,
  1680. .suspend = fsl_diu_suspend,
  1681. .resume = fsl_diu_resume,
  1682. };
  1683. static int __init fsl_diu_init(void)
  1684. {
  1685. #ifdef CONFIG_NOT_COHERENT_CACHE
  1686. struct device_node *np;
  1687. const u32 *prop;
  1688. #endif
  1689. int ret;
  1690. #ifndef MODULE
  1691. char *option;
  1692. /*
  1693. * For kernel boot options (in 'video=xxxfb:<options>' format)
  1694. */
  1695. if (fb_get_options("fslfb", &option))
  1696. return -ENODEV;
  1697. fsl_diu_setup(option);
  1698. #else
  1699. monitor_port = fsl_diu_name_to_port(monitor_string);
  1700. #endif
  1701. /*
  1702. * Must to verify set_pixel_clock. If not implement on platform,
  1703. * then that means that there is no platform support for the DIU.
  1704. */
  1705. if (!diu_ops.set_pixel_clock)
  1706. return -ENODEV;
  1707. pr_info("Freescale Display Interface Unit (DIU) framebuffer driver\n");
  1708. #ifdef CONFIG_NOT_COHERENT_CACHE
  1709. np = of_find_node_by_type(NULL, "cpu");
  1710. if (!np) {
  1711. pr_err("fsl-diu-fb: can't find 'cpu' device node\n");
  1712. return -ENODEV;
  1713. }
  1714. prop = of_get_property(np, "d-cache-size", NULL);
  1715. if (prop == NULL) {
  1716. pr_err("fsl-diu-fb: missing 'd-cache-size' property' "
  1717. "in 'cpu' node\n");
  1718. of_node_put(np);
  1719. return -ENODEV;
  1720. }
  1721. /*
  1722. * Freescale PLRU requires 13/8 times the cache size to do a proper
  1723. * displacement flush
  1724. */
  1725. coherence_data_size = be32_to_cpup(prop) * 13;
  1726. coherence_data_size /= 8;
  1727. pr_debug("fsl-diu-fb: coherence data size is %zu bytes\n",
  1728. coherence_data_size);
  1729. prop = of_get_property(np, "d-cache-line-size", NULL);
  1730. if (prop == NULL) {
  1731. pr_err("fsl-diu-fb: missing 'd-cache-line-size' property' "
  1732. "in 'cpu' node\n");
  1733. of_node_put(np);
  1734. return -ENODEV;
  1735. }
  1736. d_cache_line_size = be32_to_cpup(prop);
  1737. pr_debug("fsl-diu-fb: cache lines size is %u bytes\n",
  1738. d_cache_line_size);
  1739. of_node_put(np);
  1740. coherence_data = vmalloc(coherence_data_size);
  1741. if (!coherence_data) {
  1742. pr_err("fsl-diu-fb: could not allocate coherence data "
  1743. "(size=%zu)\n", coherence_data_size);
  1744. return -ENOMEM;
  1745. }
  1746. #endif
  1747. ret = platform_driver_register(&fsl_diu_driver);
  1748. if (ret) {
  1749. pr_err("fsl-diu-fb: failed to register platform driver\n");
  1750. #if defined(CONFIG_NOT_COHERENT_CACHE)
  1751. vfree(coherence_data);
  1752. #endif
  1753. }
  1754. return ret;
  1755. }
  1756. static void __exit fsl_diu_exit(void)
  1757. {
  1758. platform_driver_unregister(&fsl_diu_driver);
  1759. #if defined(CONFIG_NOT_COHERENT_CACHE)
  1760. vfree(coherence_data);
  1761. #endif
  1762. }
  1763. module_init(fsl_diu_init);
  1764. module_exit(fsl_diu_exit);
  1765. MODULE_AUTHOR("York Sun <yorksun@freescale.com>");
  1766. MODULE_DESCRIPTION("Freescale DIU framebuffer driver");
  1767. MODULE_LICENSE("GPL");
  1768. module_param_named(mode, fb_mode, charp, 0);
  1769. MODULE_PARM_DESC(mode,
  1770. "Specify resolution as \"<xres>x<yres>[-<bpp>][@<refresh>]\" ");
  1771. module_param_named(bpp, default_bpp, ulong, 0);
  1772. MODULE_PARM_DESC(bpp, "Specify bit-per-pixel if not specified in 'mode'");
  1773. module_param_named(monitor, monitor_string, charp, 0);
  1774. MODULE_PARM_DESC(monitor, "Specify the monitor port "
  1775. "(\"dvi\", \"lvds\", or \"dlvds\") if supported by the platform");