fsl-diu-fb.c 51 KB

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