fsl-diu-fb.c 51 KB

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