fsl-diu-fb.c 51 KB

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