fsl-diu-fb.c 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824
  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 __devinitdata 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. int cursor_reset;
  330. unsigned char g_alpha;
  331. unsigned int count;
  332. int x_aoi_d; /* aoi display x offset to physical screen */
  333. int y_aoi_d; /* aoi display y offset to physical screen */
  334. struct fsl_diu_data *parent;
  335. u8 *edid_data;
  336. };
  337. /**
  338. * struct fsl_diu_data - per-DIU data structure
  339. * @dma_addr: DMA address of this structure
  340. * @fsl_diu_info: fb_info objects, one per AOI
  341. * @dev_attr: sysfs structure
  342. * @irq: IRQ
  343. * @monitor_port: the monitor port this DIU is connected to
  344. * @diu_reg: pointer to the DIU hardware registers
  345. * @reg_lock: spinlock for register access
  346. * @dummy_aoi: video buffer for the 4x4 32-bit dummy AOI
  347. * dummy_ad: DIU Area Descriptor for the dummy AOI
  348. * @ad[]: Area Descriptors for each real AOI
  349. * @gamma: gamma color table
  350. * @cursor: hardware cursor data
  351. *
  352. * This data structure must be allocated with 32-byte alignment, so that the
  353. * internal fields can be aligned properly.
  354. */
  355. struct fsl_diu_data {
  356. dma_addr_t dma_addr;
  357. struct fb_info fsl_diu_info[NUM_AOIS];
  358. struct mfb_info mfb[NUM_AOIS];
  359. struct device_attribute dev_attr;
  360. unsigned int irq;
  361. enum fsl_diu_monitor_port monitor_port;
  362. struct diu __iomem *diu_reg;
  363. spinlock_t reg_lock;
  364. u8 dummy_aoi[4 * 4 * 4];
  365. struct diu_ad dummy_ad __aligned(8);
  366. struct diu_ad ad[NUM_AOIS] __aligned(8);
  367. u8 gamma[256 * 3] __aligned(32);
  368. u8 cursor[MAX_CURS * MAX_CURS * 2] __aligned(32);
  369. } __aligned(32);
  370. /* Determine the DMA address of a member of the fsl_diu_data structure */
  371. #define DMA_ADDR(p, f) ((p)->dma_addr + offsetof(struct fsl_diu_data, f))
  372. static struct mfb_info mfb_template[] = {
  373. {
  374. .index = PLANE0,
  375. .id = "Panel0",
  376. .registered = 0,
  377. .count = 0,
  378. .x_aoi_d = 0,
  379. .y_aoi_d = 0,
  380. },
  381. {
  382. .index = PLANE1_AOI0,
  383. .id = "Panel1 AOI0",
  384. .registered = 0,
  385. .g_alpha = 0xff,
  386. .count = 0,
  387. .x_aoi_d = 0,
  388. .y_aoi_d = 0,
  389. },
  390. {
  391. .index = PLANE1_AOI1,
  392. .id = "Panel1 AOI1",
  393. .registered = 0,
  394. .g_alpha = 0xff,
  395. .count = 0,
  396. .x_aoi_d = 0,
  397. .y_aoi_d = 480,
  398. },
  399. {
  400. .index = PLANE2_AOI0,
  401. .id = "Panel2 AOI0",
  402. .registered = 0,
  403. .g_alpha = 0xff,
  404. .count = 0,
  405. .x_aoi_d = 640,
  406. .y_aoi_d = 0,
  407. },
  408. {
  409. .index = PLANE2_AOI1,
  410. .id = "Panel2 AOI1",
  411. .registered = 0,
  412. .g_alpha = 0xff,
  413. .count = 0,
  414. .x_aoi_d = 640,
  415. .y_aoi_d = 480,
  416. },
  417. };
  418. /**
  419. * fsl_diu_name_to_port - convert a port name to a monitor port enum
  420. *
  421. * Takes the name of a monitor port ("dvi", "lvds", or "dlvds") and returns
  422. * the enum fsl_diu_monitor_port that corresponds to that string.
  423. *
  424. * For compatibility with older versions, a number ("0", "1", or "2") is also
  425. * supported.
  426. *
  427. * If the string is unknown, DVI is assumed.
  428. *
  429. * If the particular port is not supported by the platform, another port
  430. * (platform-specific) is chosen instead.
  431. */
  432. static enum fsl_diu_monitor_port fsl_diu_name_to_port(const char *s)
  433. {
  434. enum fsl_diu_monitor_port port = FSL_DIU_PORT_DVI;
  435. unsigned long val;
  436. if (s) {
  437. if (!strict_strtoul(s, 10, &val) && (val <= 2))
  438. port = (enum fsl_diu_monitor_port) val;
  439. else if (strncmp(s, "lvds", 4) == 0)
  440. port = FSL_DIU_PORT_LVDS;
  441. else if (strncmp(s, "dlvds", 5) == 0)
  442. port = FSL_DIU_PORT_DLVDS;
  443. }
  444. return diu_ops.valid_monitor_port(port);
  445. }
  446. /**
  447. * fsl_diu_alloc - allocate memory for the DIU
  448. * @size: number of bytes to allocate
  449. * @param: returned physical address of memory
  450. *
  451. * This function allocates a physically-contiguous block of memory.
  452. */
  453. static void *fsl_diu_alloc(size_t size, phys_addr_t *phys)
  454. {
  455. void *virt;
  456. virt = alloc_pages_exact(size, GFP_DMA | __GFP_ZERO);
  457. if (virt)
  458. *phys = virt_to_phys(virt);
  459. return virt;
  460. }
  461. /**
  462. * fsl_diu_free - release DIU memory
  463. * @virt: pointer returned by fsl_diu_alloc()
  464. * @size: number of bytes allocated by fsl_diu_alloc()
  465. *
  466. * This function releases memory allocated by fsl_diu_alloc().
  467. */
  468. static void fsl_diu_free(void *virt, size_t size)
  469. {
  470. if (virt && size)
  471. free_pages_exact(virt, size);
  472. }
  473. /*
  474. * Workaround for failed writing desc register of planes.
  475. * Needed with MPC5121 DIU rev 2.0 silicon.
  476. */
  477. void wr_reg_wa(u32 *reg, u32 val)
  478. {
  479. do {
  480. out_be32(reg, val);
  481. } while (in_be32(reg) != val);
  482. }
  483. static void fsl_diu_enable_panel(struct fb_info *info)
  484. {
  485. struct mfb_info *pmfbi, *cmfbi, *mfbi = info->par;
  486. struct diu_ad *ad = mfbi->ad;
  487. struct fsl_diu_data *data = mfbi->parent;
  488. struct diu __iomem *hw = data->diu_reg;
  489. switch (mfbi->index) {
  490. case PLANE0:
  491. if (hw->desc[0] != ad->paddr)
  492. wr_reg_wa(&hw->desc[0], ad->paddr);
  493. break;
  494. case PLANE1_AOI0:
  495. cmfbi = &data->mfb[2];
  496. if (hw->desc[1] != ad->paddr) { /* AOI0 closed */
  497. if (cmfbi->count > 0) /* AOI1 open */
  498. ad->next_ad =
  499. cpu_to_le32(cmfbi->ad->paddr);
  500. else
  501. ad->next_ad = 0;
  502. wr_reg_wa(&hw->desc[1], ad->paddr);
  503. }
  504. break;
  505. case PLANE2_AOI0:
  506. cmfbi = &data->mfb[4];
  507. if (hw->desc[2] != ad->paddr) { /* AOI0 closed */
  508. if (cmfbi->count > 0) /* AOI1 open */
  509. ad->next_ad =
  510. cpu_to_le32(cmfbi->ad->paddr);
  511. else
  512. ad->next_ad = 0;
  513. wr_reg_wa(&hw->desc[2], ad->paddr);
  514. }
  515. break;
  516. case PLANE1_AOI1:
  517. pmfbi = &data->mfb[1];
  518. ad->next_ad = 0;
  519. if (hw->desc[1] == data->dummy_ad.paddr)
  520. wr_reg_wa(&hw->desc[1], ad->paddr);
  521. else /* AOI0 open */
  522. pmfbi->ad->next_ad = cpu_to_le32(ad->paddr);
  523. break;
  524. case PLANE2_AOI1:
  525. pmfbi = &data->mfb[3];
  526. ad->next_ad = 0;
  527. if (hw->desc[2] == data->dummy_ad.paddr)
  528. wr_reg_wa(&hw->desc[2], ad->paddr);
  529. else /* AOI0 was open */
  530. pmfbi->ad->next_ad = cpu_to_le32(ad->paddr);
  531. break;
  532. }
  533. }
  534. static void fsl_diu_disable_panel(struct fb_info *info)
  535. {
  536. struct mfb_info *pmfbi, *cmfbi, *mfbi = info->par;
  537. struct diu_ad *ad = mfbi->ad;
  538. struct fsl_diu_data *data = mfbi->parent;
  539. struct diu __iomem *hw = data->diu_reg;
  540. switch (mfbi->index) {
  541. case PLANE0:
  542. if (hw->desc[0] != data->dummy_ad.paddr)
  543. wr_reg_wa(&hw->desc[0], data->dummy_ad.paddr);
  544. break;
  545. case PLANE1_AOI0:
  546. cmfbi = &data->mfb[2];
  547. if (cmfbi->count > 0) /* AOI1 is open */
  548. wr_reg_wa(&hw->desc[1], cmfbi->ad->paddr);
  549. /* move AOI1 to the first */
  550. else /* AOI1 was closed */
  551. wr_reg_wa(&hw->desc[1], data->dummy_ad.paddr);
  552. /* close AOI 0 */
  553. break;
  554. case PLANE2_AOI0:
  555. cmfbi = &data->mfb[4];
  556. if (cmfbi->count > 0) /* AOI1 is open */
  557. wr_reg_wa(&hw->desc[2], cmfbi->ad->paddr);
  558. /* move AOI1 to the first */
  559. else /* AOI1 was closed */
  560. wr_reg_wa(&hw->desc[2], data->dummy_ad.paddr);
  561. /* close AOI 0 */
  562. break;
  563. case PLANE1_AOI1:
  564. pmfbi = &data->mfb[1];
  565. if (hw->desc[1] != 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[1], data->dummy_ad.paddr);
  572. /* close AOI 1 */
  573. break;
  574. case PLANE2_AOI1:
  575. pmfbi = &data->mfb[3];
  576. if (hw->desc[2] != ad->paddr) {
  577. /* AOI1 is not the first in the chain */
  578. if (pmfbi->count > 0)
  579. /* AOI0 is open, must be the first */
  580. pmfbi->ad->next_ad = 0;
  581. } else /* AOI1 is the first in the chain */
  582. wr_reg_wa(&hw->desc[2], data->dummy_ad.paddr);
  583. /* close AOI 1 */
  584. break;
  585. }
  586. }
  587. static void enable_lcdc(struct fb_info *info)
  588. {
  589. struct mfb_info *mfbi = info->par;
  590. struct fsl_diu_data *data = mfbi->parent;
  591. struct diu __iomem *hw = data->diu_reg;
  592. out_be32(&hw->diu_mode, MFB_MODE1);
  593. }
  594. static void disable_lcdc(struct fb_info *info)
  595. {
  596. struct mfb_info *mfbi = info->par;
  597. struct fsl_diu_data *data = mfbi->parent;
  598. struct diu __iomem *hw = data->diu_reg;
  599. out_be32(&hw->diu_mode, 0);
  600. }
  601. static void adjust_aoi_size_position(struct fb_var_screeninfo *var,
  602. struct fb_info *info)
  603. {
  604. struct mfb_info *lower_aoi_mfbi, *upper_aoi_mfbi, *mfbi = info->par;
  605. struct fsl_diu_data *data = mfbi->parent;
  606. int available_height, upper_aoi_bottom;
  607. enum mfb_index index = mfbi->index;
  608. int lower_aoi_is_open, upper_aoi_is_open;
  609. __u32 base_plane_width, base_plane_height, upper_aoi_height;
  610. base_plane_width = data->fsl_diu_info[0].var.xres;
  611. base_plane_height = data->fsl_diu_info[0].var.yres;
  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. switch (index) {
  617. case PLANE0:
  618. if (mfbi->x_aoi_d != 0)
  619. mfbi->x_aoi_d = 0;
  620. if (mfbi->y_aoi_d != 0)
  621. mfbi->y_aoi_d = 0;
  622. break;
  623. case PLANE1_AOI0:
  624. case PLANE2_AOI0:
  625. lower_aoi_mfbi = data->fsl_diu_info[index+1].par;
  626. lower_aoi_is_open = lower_aoi_mfbi->count > 0 ? 1 : 0;
  627. if (var->xres > base_plane_width)
  628. var->xres = base_plane_width;
  629. if ((mfbi->x_aoi_d + var->xres) > base_plane_width)
  630. mfbi->x_aoi_d = base_plane_width - var->xres;
  631. if (lower_aoi_is_open)
  632. available_height = lower_aoi_mfbi->y_aoi_d;
  633. else
  634. available_height = base_plane_height;
  635. if (var->yres > available_height)
  636. var->yres = available_height;
  637. if ((mfbi->y_aoi_d + var->yres) > available_height)
  638. mfbi->y_aoi_d = available_height - var->yres;
  639. break;
  640. case PLANE1_AOI1:
  641. case PLANE2_AOI1:
  642. upper_aoi_mfbi = data->fsl_diu_info[index-1].par;
  643. upper_aoi_height = data->fsl_diu_info[index-1].var.yres;
  644. upper_aoi_bottom = upper_aoi_mfbi->y_aoi_d + upper_aoi_height;
  645. upper_aoi_is_open = upper_aoi_mfbi->count > 0 ? 1 : 0;
  646. if (var->xres > base_plane_width)
  647. var->xres = base_plane_width;
  648. if ((mfbi->x_aoi_d + var->xres) > base_plane_width)
  649. mfbi->x_aoi_d = base_plane_width - var->xres;
  650. if (mfbi->y_aoi_d < 0)
  651. mfbi->y_aoi_d = 0;
  652. if (upper_aoi_is_open) {
  653. if (mfbi->y_aoi_d < upper_aoi_bottom)
  654. mfbi->y_aoi_d = upper_aoi_bottom;
  655. available_height = base_plane_height
  656. - upper_aoi_bottom;
  657. } else
  658. available_height = base_plane_height;
  659. if (var->yres > available_height)
  660. var->yres = available_height;
  661. if ((mfbi->y_aoi_d + var->yres) > base_plane_height)
  662. mfbi->y_aoi_d = base_plane_height - var->yres;
  663. break;
  664. }
  665. }
  666. /*
  667. * Checks to see if the hardware supports the state requested by var passed
  668. * in. This function does not alter the hardware state! If the var passed in
  669. * is slightly off by what the hardware can support then we alter the var
  670. * PASSED in to what we can do. If the hardware doesn't support mode change
  671. * a -EINVAL will be returned by the upper layers.
  672. */
  673. static int fsl_diu_check_var(struct fb_var_screeninfo *var,
  674. struct fb_info *info)
  675. {
  676. if (var->xres_virtual < var->xres)
  677. var->xres_virtual = var->xres;
  678. if (var->yres_virtual < var->yres)
  679. var->yres_virtual = var->yres;
  680. if (var->xoffset < 0)
  681. var->xoffset = 0;
  682. if (var->yoffset < 0)
  683. var->yoffset = 0;
  684. if (var->xoffset + info->var.xres > info->var.xres_virtual)
  685. var->xoffset = info->var.xres_virtual - info->var.xres;
  686. if (var->yoffset + info->var.yres > info->var.yres_virtual)
  687. var->yoffset = info->var.yres_virtual - info->var.yres;
  688. if ((var->bits_per_pixel != 32) && (var->bits_per_pixel != 24) &&
  689. (var->bits_per_pixel != 16))
  690. var->bits_per_pixel = default_bpp;
  691. switch (var->bits_per_pixel) {
  692. case 16:
  693. var->red.length = 5;
  694. var->red.offset = 11;
  695. var->red.msb_right = 0;
  696. var->green.length = 6;
  697. var->green.offset = 5;
  698. var->green.msb_right = 0;
  699. var->blue.length = 5;
  700. var->blue.offset = 0;
  701. var->blue.msb_right = 0;
  702. var->transp.length = 0;
  703. var->transp.offset = 0;
  704. var->transp.msb_right = 0;
  705. break;
  706. case 24:
  707. var->red.length = 8;
  708. var->red.offset = 0;
  709. var->red.msb_right = 0;
  710. var->green.length = 8;
  711. var->green.offset = 8;
  712. var->green.msb_right = 0;
  713. var->blue.length = 8;
  714. var->blue.offset = 16;
  715. var->blue.msb_right = 0;
  716. var->transp.length = 0;
  717. var->transp.offset = 0;
  718. var->transp.msb_right = 0;
  719. break;
  720. case 32:
  721. var->red.length = 8;
  722. var->red.offset = 16;
  723. var->red.msb_right = 0;
  724. var->green.length = 8;
  725. var->green.offset = 8;
  726. var->green.msb_right = 0;
  727. var->blue.length = 8;
  728. var->blue.offset = 0;
  729. var->blue.msb_right = 0;
  730. var->transp.length = 8;
  731. var->transp.offset = 24;
  732. var->transp.msb_right = 0;
  733. break;
  734. }
  735. var->height = -1;
  736. var->width = -1;
  737. var->grayscale = 0;
  738. /* Copy nonstd field to/from sync for fbset usage */
  739. var->sync |= var->nonstd;
  740. var->nonstd |= var->sync;
  741. adjust_aoi_size_position(var, info);
  742. return 0;
  743. }
  744. static void set_fix(struct fb_info *info)
  745. {
  746. struct fb_fix_screeninfo *fix = &info->fix;
  747. struct fb_var_screeninfo *var = &info->var;
  748. struct mfb_info *mfbi = info->par;
  749. strncpy(fix->id, mfbi->id, sizeof(fix->id));
  750. fix->line_length = var->xres_virtual * var->bits_per_pixel / 8;
  751. fix->type = FB_TYPE_PACKED_PIXELS;
  752. fix->accel = FB_ACCEL_NONE;
  753. fix->visual = FB_VISUAL_TRUECOLOR;
  754. fix->xpanstep = 1;
  755. fix->ypanstep = 1;
  756. }
  757. static void update_lcdc(struct fb_info *info)
  758. {
  759. struct fb_var_screeninfo *var = &info->var;
  760. struct mfb_info *mfbi = info->par;
  761. struct fsl_diu_data *data = mfbi->parent;
  762. struct diu __iomem *hw;
  763. int i, j;
  764. u8 *gamma_table_base;
  765. u32 temp;
  766. hw = data->diu_reg;
  767. diu_ops.set_monitor_port(data->monitor_port);
  768. gamma_table_base = data->gamma;
  769. /* Prep for DIU init - gamma table, cursor table */
  770. for (i = 0; i <= 2; i++)
  771. for (j = 0; j <= 255; j++)
  772. *gamma_table_base++ = j;
  773. if (diu_ops.set_gamma_table)
  774. diu_ops.set_gamma_table(data->monitor_port, data->gamma);
  775. disable_lcdc(info);
  776. /* Program DIU registers */
  777. out_be32(&hw->gamma, DMA_ADDR(data, gamma));
  778. out_be32(&hw->cursor, DMA_ADDR(data, cursor));
  779. out_be32(&hw->bgnd, 0x007F7F7F); /* BGND */
  780. out_be32(&hw->bgnd_wb, 0); /* BGND_WB */
  781. out_be32(&hw->disp_size, (var->yres << 16 | var->xres));
  782. /* DISP SIZE */
  783. out_be32(&hw->wb_size, 0); /* WB SIZE */
  784. out_be32(&hw->wb_mem_addr, 0); /* WB MEM ADDR */
  785. /* Horizontal and vertical configuration register */
  786. temp = var->left_margin << 22 | /* BP_H */
  787. var->hsync_len << 11 | /* PW_H */
  788. var->right_margin; /* FP_H */
  789. out_be32(&hw->hsyn_para, temp);
  790. temp = var->upper_margin << 22 | /* BP_V */
  791. var->vsync_len << 11 | /* PW_V */
  792. var->lower_margin; /* FP_V */
  793. out_be32(&hw->vsyn_para, temp);
  794. diu_ops.set_pixel_clock(var->pixclock);
  795. out_be32(&hw->syn_pol, 0); /* SYNC SIGNALS POLARITY */
  796. out_be32(&hw->thresholds, 0x00037800); /* The Thresholds */
  797. out_be32(&hw->int_status, 0); /* INTERRUPT STATUS */
  798. out_be32(&hw->plut, 0x01F5F666);
  799. /* Enable the DIU */
  800. enable_lcdc(info);
  801. }
  802. static int map_video_memory(struct fb_info *info)
  803. {
  804. phys_addr_t phys;
  805. u32 smem_len = info->fix.line_length * info->var.yres_virtual;
  806. info->screen_base = fsl_diu_alloc(smem_len, &phys);
  807. if (info->screen_base == NULL) {
  808. dev_err(info->dev, "unable to allocate fb memory\n");
  809. return -ENOMEM;
  810. }
  811. mutex_lock(&info->mm_lock);
  812. info->fix.smem_start = (unsigned long) phys;
  813. info->fix.smem_len = smem_len;
  814. mutex_unlock(&info->mm_lock);
  815. info->screen_size = info->fix.smem_len;
  816. return 0;
  817. }
  818. static void unmap_video_memory(struct fb_info *info)
  819. {
  820. fsl_diu_free(info->screen_base, info->fix.smem_len);
  821. mutex_lock(&info->mm_lock);
  822. info->screen_base = NULL;
  823. info->fix.smem_start = 0;
  824. info->fix.smem_len = 0;
  825. mutex_unlock(&info->mm_lock);
  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, blue, green, 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, 0, 1, 3, 8, 8, 8, 8);
  880. case 24:
  881. /* 0x88082219 */
  882. return MAKE_PF(4, 0, 1, 2, 2, 0, 8, 8, 8);
  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. * Using the fb_var_screeninfo in fb_info we set the resolution of this
  893. * particular framebuffer. This function alters the fb_fix_screeninfo stored
  894. * in fb_info. It does not alter var in fb_info since we are using that
  895. * data. This means we depend on the data in var inside fb_info to be
  896. * supported by the hardware. fsl_diu_check_var is always called before
  897. * fsl_diu_set_par to ensure this.
  898. */
  899. static int fsl_diu_set_par(struct fb_info *info)
  900. {
  901. unsigned long len;
  902. struct fb_var_screeninfo *var = &info->var;
  903. struct mfb_info *mfbi = info->par;
  904. struct fsl_diu_data *data = mfbi->parent;
  905. struct diu_ad *ad = mfbi->ad;
  906. struct diu __iomem *hw;
  907. hw = data->diu_reg;
  908. set_fix(info);
  909. mfbi->cursor_reset = 1;
  910. len = info->var.yres_virtual * info->fix.line_length;
  911. /* Alloc & dealloc each time resolution/bpp change */
  912. if (len != info->fix.smem_len) {
  913. if (info->fix.smem_start)
  914. unmap_video_memory(info);
  915. /* Memory allocation for framebuffer */
  916. if (map_video_memory(info)) {
  917. dev_err(info->dev, "unable to allocate fb memory 1\n");
  918. return -ENOMEM;
  919. }
  920. }
  921. if (diu_ops.get_pixel_format)
  922. ad->pix_fmt = diu_ops.get_pixel_format(data->monitor_port,
  923. var->bits_per_pixel);
  924. else
  925. ad->pix_fmt = fsl_diu_get_pixel_format(var->bits_per_pixel);
  926. ad->addr = cpu_to_le32(info->fix.smem_start);
  927. ad->src_size_g_alpha = cpu_to_le32((var->yres_virtual << 12) |
  928. var->xres_virtual) | mfbi->g_alpha;
  929. /* AOI should not be greater than display size */
  930. ad->aoi_size = cpu_to_le32((var->yres << 16) | var->xres);
  931. ad->offset_xyi = cpu_to_le32((var->yoffset << 16) | var->xoffset);
  932. ad->offset_xyd = cpu_to_le32((mfbi->y_aoi_d << 16) | mfbi->x_aoi_d);
  933. /* Disable chroma keying function */
  934. ad->ckmax_r = 0;
  935. ad->ckmax_g = 0;
  936. ad->ckmax_b = 0;
  937. ad->ckmin_r = 255;
  938. ad->ckmin_g = 255;
  939. ad->ckmin_b = 255;
  940. if (mfbi->index == PLANE0)
  941. update_lcdc(info);
  942. return 0;
  943. }
  944. static inline __u32 CNVT_TOHW(__u32 val, __u32 width)
  945. {
  946. return ((val << width) + 0x7FFF - val) >> 16;
  947. }
  948. /*
  949. * Set a single color register. The values supplied have a 16 bit magnitude
  950. * which needs to be scaled in this function for the hardware. Things to take
  951. * into consideration are how many color registers, if any, are supported with
  952. * the current color visual. With truecolor mode no color palettes are
  953. * supported. Here a pseudo palette is created which we store the value in
  954. * pseudo_palette in struct fb_info. For pseudocolor mode we have a limited
  955. * color palette.
  956. */
  957. static int fsl_diu_setcolreg(unsigned int regno, unsigned int red,
  958. unsigned int green, unsigned int blue,
  959. unsigned int transp, struct fb_info *info)
  960. {
  961. int ret = 1;
  962. /*
  963. * If greyscale is true, then we convert the RGB value
  964. * to greyscale no matter what visual we are using.
  965. */
  966. if (info->var.grayscale)
  967. red = green = blue = (19595 * red + 38470 * green +
  968. 7471 * blue) >> 16;
  969. switch (info->fix.visual) {
  970. case FB_VISUAL_TRUECOLOR:
  971. /*
  972. * 16-bit True Colour. We encode the RGB value
  973. * according to the RGB bitfield information.
  974. */
  975. if (regno < 16) {
  976. u32 *pal = info->pseudo_palette;
  977. u32 v;
  978. red = CNVT_TOHW(red, info->var.red.length);
  979. green = CNVT_TOHW(green, info->var.green.length);
  980. blue = CNVT_TOHW(blue, info->var.blue.length);
  981. transp = CNVT_TOHW(transp, info->var.transp.length);
  982. v = (red << info->var.red.offset) |
  983. (green << info->var.green.offset) |
  984. (blue << info->var.blue.offset) |
  985. (transp << info->var.transp.offset);
  986. pal[regno] = v;
  987. ret = 0;
  988. }
  989. break;
  990. }
  991. return ret;
  992. }
  993. /*
  994. * Pan (or wrap, depending on the `vmode' field) the display using the
  995. * 'xoffset' and 'yoffset' fields of the 'var' structure. If the values
  996. * don't fit, return -EINVAL.
  997. */
  998. static int fsl_diu_pan_display(struct fb_var_screeninfo *var,
  999. struct fb_info *info)
  1000. {
  1001. if ((info->var.xoffset == var->xoffset) &&
  1002. (info->var.yoffset == var->yoffset))
  1003. return 0; /* No change, do nothing */
  1004. if (var->xoffset < 0 || var->yoffset < 0
  1005. || var->xoffset + info->var.xres > info->var.xres_virtual
  1006. || var->yoffset + info->var.yres > info->var.yres_virtual)
  1007. return -EINVAL;
  1008. info->var.xoffset = var->xoffset;
  1009. info->var.yoffset = var->yoffset;
  1010. if (var->vmode & FB_VMODE_YWRAP)
  1011. info->var.vmode |= FB_VMODE_YWRAP;
  1012. else
  1013. info->var.vmode &= ~FB_VMODE_YWRAP;
  1014. fsl_diu_set_aoi(info);
  1015. return 0;
  1016. }
  1017. static int fsl_diu_ioctl(struct fb_info *info, unsigned int cmd,
  1018. unsigned long arg)
  1019. {
  1020. struct mfb_info *mfbi = info->par;
  1021. struct diu_ad *ad = mfbi->ad;
  1022. struct mfb_chroma_key ck;
  1023. unsigned char global_alpha;
  1024. struct aoi_display_offset aoi_d;
  1025. __u32 pix_fmt;
  1026. void __user *buf = (void __user *)arg;
  1027. if (!arg)
  1028. return -EINVAL;
  1029. switch (cmd) {
  1030. case MFB_SET_PIXFMT_OLD:
  1031. dev_warn(info->dev,
  1032. "MFB_SET_PIXFMT value of 0x%08x is deprecated.\n",
  1033. MFB_SET_PIXFMT_OLD);
  1034. case MFB_SET_PIXFMT:
  1035. if (copy_from_user(&pix_fmt, buf, sizeof(pix_fmt)))
  1036. return -EFAULT;
  1037. ad->pix_fmt = pix_fmt;
  1038. break;
  1039. case MFB_GET_PIXFMT_OLD:
  1040. dev_warn(info->dev,
  1041. "MFB_GET_PIXFMT value of 0x%08x is deprecated.\n",
  1042. MFB_GET_PIXFMT_OLD);
  1043. case MFB_GET_PIXFMT:
  1044. pix_fmt = ad->pix_fmt;
  1045. if (copy_to_user(buf, &pix_fmt, sizeof(pix_fmt)))
  1046. return -EFAULT;
  1047. break;
  1048. case MFB_SET_AOID:
  1049. if (copy_from_user(&aoi_d, buf, sizeof(aoi_d)))
  1050. return -EFAULT;
  1051. mfbi->x_aoi_d = aoi_d.x_aoi_d;
  1052. mfbi->y_aoi_d = aoi_d.y_aoi_d;
  1053. fsl_diu_check_var(&info->var, info);
  1054. fsl_diu_set_aoi(info);
  1055. break;
  1056. case MFB_GET_AOID:
  1057. aoi_d.x_aoi_d = mfbi->x_aoi_d;
  1058. aoi_d.y_aoi_d = mfbi->y_aoi_d;
  1059. if (copy_to_user(buf, &aoi_d, sizeof(aoi_d)))
  1060. return -EFAULT;
  1061. break;
  1062. case MFB_GET_ALPHA:
  1063. global_alpha = mfbi->g_alpha;
  1064. if (copy_to_user(buf, &global_alpha, sizeof(global_alpha)))
  1065. return -EFAULT;
  1066. break;
  1067. case MFB_SET_ALPHA:
  1068. /* set panel information */
  1069. if (copy_from_user(&global_alpha, buf, sizeof(global_alpha)))
  1070. return -EFAULT;
  1071. ad->src_size_g_alpha = (ad->src_size_g_alpha & (~0xff)) |
  1072. (global_alpha & 0xff);
  1073. mfbi->g_alpha = global_alpha;
  1074. break;
  1075. case MFB_SET_CHROMA_KEY:
  1076. /* set panel winformation */
  1077. if (copy_from_user(&ck, buf, sizeof(ck)))
  1078. return -EFAULT;
  1079. if (ck.enable &&
  1080. (ck.red_max < ck.red_min ||
  1081. ck.green_max < ck.green_min ||
  1082. ck.blue_max < ck.blue_min))
  1083. return -EINVAL;
  1084. if (!ck.enable) {
  1085. ad->ckmax_r = 0;
  1086. ad->ckmax_g = 0;
  1087. ad->ckmax_b = 0;
  1088. ad->ckmin_r = 255;
  1089. ad->ckmin_g = 255;
  1090. ad->ckmin_b = 255;
  1091. } else {
  1092. ad->ckmax_r = ck.red_max;
  1093. ad->ckmax_g = ck.green_max;
  1094. ad->ckmax_b = ck.blue_max;
  1095. ad->ckmin_r = ck.red_min;
  1096. ad->ckmin_g = ck.green_min;
  1097. ad->ckmin_b = ck.blue_min;
  1098. }
  1099. break;
  1100. default:
  1101. dev_err(info->dev, "unknown ioctl command (0x%08X)\n", cmd);
  1102. return -ENOIOCTLCMD;
  1103. }
  1104. return 0;
  1105. }
  1106. /* turn on fb if count == 1
  1107. */
  1108. static int fsl_diu_open(struct fb_info *info, int user)
  1109. {
  1110. struct mfb_info *mfbi = info->par;
  1111. int res = 0;
  1112. /* free boot splash memory on first /dev/fb0 open */
  1113. if ((mfbi->index == PLANE0) && diu_ops.release_bootmem)
  1114. diu_ops.release_bootmem();
  1115. spin_lock(&diu_lock);
  1116. mfbi->count++;
  1117. if (mfbi->count == 1) {
  1118. fsl_diu_check_var(&info->var, info);
  1119. res = fsl_diu_set_par(info);
  1120. if (res < 0)
  1121. mfbi->count--;
  1122. else
  1123. fsl_diu_enable_panel(info);
  1124. }
  1125. spin_unlock(&diu_lock);
  1126. return res;
  1127. }
  1128. /* turn off fb if count == 0
  1129. */
  1130. static int fsl_diu_release(struct fb_info *info, int user)
  1131. {
  1132. struct mfb_info *mfbi = info->par;
  1133. int res = 0;
  1134. spin_lock(&diu_lock);
  1135. mfbi->count--;
  1136. if (mfbi->count == 0)
  1137. fsl_diu_disable_panel(info);
  1138. spin_unlock(&diu_lock);
  1139. return res;
  1140. }
  1141. static struct fb_ops fsl_diu_ops = {
  1142. .owner = THIS_MODULE,
  1143. .fb_check_var = fsl_diu_check_var,
  1144. .fb_set_par = fsl_diu_set_par,
  1145. .fb_setcolreg = fsl_diu_setcolreg,
  1146. .fb_pan_display = fsl_diu_pan_display,
  1147. .fb_fillrect = cfb_fillrect,
  1148. .fb_copyarea = cfb_copyarea,
  1149. .fb_imageblit = cfb_imageblit,
  1150. .fb_ioctl = fsl_diu_ioctl,
  1151. .fb_open = fsl_diu_open,
  1152. .fb_release = fsl_diu_release,
  1153. };
  1154. static int __devinit install_fb(struct fb_info *info)
  1155. {
  1156. int rc;
  1157. struct mfb_info *mfbi = info->par;
  1158. const char *aoi_mode, *init_aoi_mode = "320x240";
  1159. struct fb_videomode *db = fsl_diu_mode_db;
  1160. unsigned int dbsize = ARRAY_SIZE(fsl_diu_mode_db);
  1161. int has_default_mode = 1;
  1162. info->var.activate = FB_ACTIVATE_NOW;
  1163. info->fbops = &fsl_diu_ops;
  1164. info->flags = FBINFO_DEFAULT | FBINFO_VIRTFB | FBINFO_PARTIAL_PAN_OK |
  1165. FBINFO_READS_FAST;
  1166. info->pseudo_palette = mfbi->pseudo_palette;
  1167. rc = fb_alloc_cmap(&info->cmap, 16, 0);
  1168. if (rc)
  1169. return rc;
  1170. if (mfbi->index == PLANE0) {
  1171. if (mfbi->edid_data) {
  1172. /* Now build modedb from EDID */
  1173. fb_edid_to_monspecs(mfbi->edid_data, &info->monspecs);
  1174. fb_videomode_to_modelist(info->monspecs.modedb,
  1175. info->monspecs.modedb_len,
  1176. &info->modelist);
  1177. db = info->monspecs.modedb;
  1178. dbsize = info->monspecs.modedb_len;
  1179. }
  1180. aoi_mode = fb_mode;
  1181. } else {
  1182. aoi_mode = init_aoi_mode;
  1183. }
  1184. rc = fb_find_mode(&info->var, info, aoi_mode, db, dbsize, NULL,
  1185. default_bpp);
  1186. if (!rc) {
  1187. /*
  1188. * For plane 0 we continue and look into
  1189. * driver's internal modedb.
  1190. */
  1191. if ((mfbi->index == PLANE0) && mfbi->edid_data)
  1192. has_default_mode = 0;
  1193. else
  1194. return -EINVAL;
  1195. }
  1196. if (!has_default_mode) {
  1197. rc = fb_find_mode(&info->var, info, aoi_mode, fsl_diu_mode_db,
  1198. ARRAY_SIZE(fsl_diu_mode_db), NULL, default_bpp);
  1199. if (rc)
  1200. has_default_mode = 1;
  1201. }
  1202. /* Still not found, use preferred mode from database if any */
  1203. if (!has_default_mode && info->monspecs.modedb) {
  1204. struct fb_monspecs *specs = &info->monspecs;
  1205. struct fb_videomode *modedb = &specs->modedb[0];
  1206. /*
  1207. * Get preferred timing. If not found,
  1208. * first mode in database will be used.
  1209. */
  1210. if (specs->misc & FB_MISC_1ST_DETAIL) {
  1211. int i;
  1212. for (i = 0; i < specs->modedb_len; i++) {
  1213. if (specs->modedb[i].flag & FB_MODE_IS_FIRST) {
  1214. modedb = &specs->modedb[i];
  1215. break;
  1216. }
  1217. }
  1218. }
  1219. info->var.bits_per_pixel = default_bpp;
  1220. fb_videomode_to_var(&info->var, modedb);
  1221. }
  1222. if (fsl_diu_check_var(&info->var, info)) {
  1223. dev_err(info->dev, "fsl_diu_check_var failed\n");
  1224. unmap_video_memory(info);
  1225. fb_dealloc_cmap(&info->cmap);
  1226. return -EINVAL;
  1227. }
  1228. if (register_framebuffer(info) < 0) {
  1229. dev_err(info->dev, "register_framebuffer failed\n");
  1230. unmap_video_memory(info);
  1231. fb_dealloc_cmap(&info->cmap);
  1232. return -EINVAL;
  1233. }
  1234. mfbi->registered = 1;
  1235. dev_info(info->dev, "%s registered successfully\n", mfbi->id);
  1236. return 0;
  1237. }
  1238. static void uninstall_fb(struct fb_info *info)
  1239. {
  1240. struct mfb_info *mfbi = info->par;
  1241. if (!mfbi->registered)
  1242. return;
  1243. if (mfbi->index == PLANE0)
  1244. kfree(mfbi->edid_data);
  1245. unregister_framebuffer(info);
  1246. unmap_video_memory(info);
  1247. if (&info->cmap)
  1248. fb_dealloc_cmap(&info->cmap);
  1249. mfbi->registered = 0;
  1250. }
  1251. static irqreturn_t fsl_diu_isr(int irq, void *dev_id)
  1252. {
  1253. struct diu __iomem *hw = dev_id;
  1254. unsigned int status = in_be32(&hw->int_status);
  1255. if (status) {
  1256. /* This is the workaround for underrun */
  1257. if (status & INT_UNDRUN) {
  1258. out_be32(&hw->diu_mode, 0);
  1259. udelay(1);
  1260. out_be32(&hw->diu_mode, 1);
  1261. }
  1262. #if defined(CONFIG_NOT_COHERENT_CACHE)
  1263. else if (status & INT_VSYNC) {
  1264. unsigned int i;
  1265. for (i = 0; i < coherence_data_size;
  1266. i += d_cache_line_size)
  1267. __asm__ __volatile__ (
  1268. "dcbz 0, %[input]"
  1269. ::[input]"r"(&coherence_data[i]));
  1270. }
  1271. #endif
  1272. return IRQ_HANDLED;
  1273. }
  1274. return IRQ_NONE;
  1275. }
  1276. static int request_irq_local(struct fsl_diu_data *data)
  1277. {
  1278. struct diu __iomem *hw = data->diu_reg;
  1279. u32 ints;
  1280. int ret;
  1281. /* Read to clear the status */
  1282. in_be32(&hw->int_status);
  1283. ret = request_irq(data->irq, fsl_diu_isr, 0, "fsl-diu-fb", hw);
  1284. if (!ret) {
  1285. ints = INT_PARERR | INT_LS_BF_VS;
  1286. #if !defined(CONFIG_NOT_COHERENT_CACHE)
  1287. ints |= INT_VSYNC;
  1288. #endif
  1289. /* Read to clear the status */
  1290. in_be32(&hw->int_status);
  1291. out_be32(&hw->int_mask, ints);
  1292. }
  1293. return ret;
  1294. }
  1295. static void free_irq_local(struct fsl_diu_data *data)
  1296. {
  1297. struct diu __iomem *hw = data->diu_reg;
  1298. /* Disable all LCDC interrupt */
  1299. out_be32(&hw->int_mask, 0x1f);
  1300. free_irq(data->irq, NULL);
  1301. }
  1302. #ifdef CONFIG_PM
  1303. /*
  1304. * Power management hooks. Note that we won't be called from IRQ context,
  1305. * unlike the blank functions above, so we may sleep.
  1306. */
  1307. static int fsl_diu_suspend(struct platform_device *ofdev, pm_message_t state)
  1308. {
  1309. struct fsl_diu_data *data;
  1310. data = dev_get_drvdata(&ofdev->dev);
  1311. disable_lcdc(data->fsl_diu_info[0]);
  1312. return 0;
  1313. }
  1314. static int fsl_diu_resume(struct platform_device *ofdev)
  1315. {
  1316. struct fsl_diu_data *data;
  1317. data = dev_get_drvdata(&ofdev->dev);
  1318. enable_lcdc(data->fsl_diu_info[0]);
  1319. return 0;
  1320. }
  1321. #else
  1322. #define fsl_diu_suspend NULL
  1323. #define fsl_diu_resume NULL
  1324. #endif /* CONFIG_PM */
  1325. static ssize_t store_monitor(struct device *device,
  1326. struct device_attribute *attr, const char *buf, size_t count)
  1327. {
  1328. enum fsl_diu_monitor_port old_monitor_port;
  1329. struct fsl_diu_data *data =
  1330. container_of(attr, struct fsl_diu_data, dev_attr);
  1331. old_monitor_port = data->monitor_port;
  1332. data->monitor_port = fsl_diu_name_to_port(buf);
  1333. if (old_monitor_port != data->monitor_port) {
  1334. /* All AOIs need adjust pixel format
  1335. * fsl_diu_set_par only change the pixsel format here
  1336. * unlikely to fail. */
  1337. unsigned int i;
  1338. for (i=0; i < NUM_AOIS; i++)
  1339. fsl_diu_set_par(&data->fsl_diu_info[i]);
  1340. }
  1341. return count;
  1342. }
  1343. static ssize_t show_monitor(struct device *device,
  1344. struct device_attribute *attr, char *buf)
  1345. {
  1346. struct fsl_diu_data *data =
  1347. container_of(attr, struct fsl_diu_data, dev_attr);
  1348. switch (data->monitor_port) {
  1349. case FSL_DIU_PORT_DVI:
  1350. return sprintf(buf, "DVI\n");
  1351. case FSL_DIU_PORT_LVDS:
  1352. return sprintf(buf, "Single-link LVDS\n");
  1353. case FSL_DIU_PORT_DLVDS:
  1354. return sprintf(buf, "Dual-link LVDS\n");
  1355. }
  1356. return 0;
  1357. }
  1358. static int __devinit fsl_diu_probe(struct platform_device *pdev)
  1359. {
  1360. struct device_node *np = pdev->dev.of_node;
  1361. struct mfb_info *mfbi;
  1362. struct fsl_diu_data *data;
  1363. int diu_mode;
  1364. dma_addr_t dma_addr; /* DMA addr of fsl_diu_data struct */
  1365. unsigned int i;
  1366. int ret;
  1367. data = dma_alloc_coherent(&pdev->dev, sizeof(struct fsl_diu_data),
  1368. &dma_addr, GFP_DMA | __GFP_ZERO);
  1369. if (!data)
  1370. return -ENOMEM;
  1371. data->dma_addr = dma_addr;
  1372. /*
  1373. * dma_alloc_coherent() uses a page allocator, so the address is
  1374. * always page-aligned. We need the memory to be 32-byte aligned,
  1375. * so that's good. However, if one day the allocator changes, we
  1376. * need to catch that. It's not worth the effort to handle unaligned
  1377. * alloctions now because it's highly unlikely to ever be a problem.
  1378. */
  1379. if ((unsigned long)data & 31) {
  1380. dev_err(&pdev->dev, "misaligned allocation");
  1381. ret = -ENOMEM;
  1382. goto error;
  1383. }
  1384. spin_lock_init(&data->reg_lock);
  1385. for (i = 0; i < NUM_AOIS; i++) {
  1386. struct fb_info *info = &data->fsl_diu_info[i];
  1387. info->device = &pdev->dev;
  1388. info->par = &data->mfb[i];
  1389. /*
  1390. * We store the physical address of the AD in the reserved
  1391. * 'paddr' field of the AD itself.
  1392. */
  1393. data->ad[i].paddr = DMA_ADDR(data, ad[i]);
  1394. info->fix.smem_start = 0;
  1395. /* Initialize the AOI data structure */
  1396. mfbi = info->par;
  1397. memcpy(mfbi, &mfb_template[i], sizeof(struct mfb_info));
  1398. mfbi->parent = data;
  1399. mfbi->ad = &data->ad[i];
  1400. if (mfbi->index == PLANE0) {
  1401. const u8 *prop;
  1402. int len;
  1403. /* Get EDID */
  1404. prop = of_get_property(np, "edid", &len);
  1405. if (prop && len == EDID_LENGTH)
  1406. mfbi->edid_data = kmemdup(prop, EDID_LENGTH,
  1407. GFP_KERNEL);
  1408. }
  1409. }
  1410. data->diu_reg = of_iomap(np, 0);
  1411. if (!data->diu_reg) {
  1412. dev_err(&pdev->dev, "cannot map DIU registers\n");
  1413. ret = -EFAULT;
  1414. goto error;
  1415. }
  1416. diu_mode = in_be32(&data->diu_reg->diu_mode);
  1417. if (diu_mode == MFB_MODE0)
  1418. out_be32(&data->diu_reg->diu_mode, 0); /* disable DIU */
  1419. /* Get the IRQ of the DIU */
  1420. data->irq = irq_of_parse_and_map(np, 0);
  1421. if (!data->irq) {
  1422. dev_err(&pdev->dev, "could not get DIU IRQ\n");
  1423. ret = -EINVAL;
  1424. goto error;
  1425. }
  1426. data->monitor_port = monitor_port;
  1427. /* Initialize the dummy Area Descriptor */
  1428. data->dummy_ad.addr = cpu_to_le32(DMA_ADDR(data, dummy_aoi));
  1429. data->dummy_ad.pix_fmt = 0x88882317;
  1430. data->dummy_ad.src_size_g_alpha = cpu_to_le32((4 << 12) | 4);
  1431. data->dummy_ad.aoi_size = cpu_to_le32((4 << 16) | 2);
  1432. data->dummy_ad.offset_xyi = 0;
  1433. data->dummy_ad.offset_xyd = 0;
  1434. data->dummy_ad.next_ad = 0;
  1435. data->dummy_ad.paddr = DMA_ADDR(data, dummy_ad);
  1436. /*
  1437. * Let DIU display splash screen if it was pre-initialized
  1438. * by the bootloader, set dummy area descriptor otherwise.
  1439. */
  1440. if (diu_mode == MFB_MODE0)
  1441. out_be32(&data->diu_reg->desc[0], data->dummy_ad.paddr);
  1442. out_be32(&data->diu_reg->desc[1], data->dummy_ad.paddr);
  1443. out_be32(&data->diu_reg->desc[2], data->dummy_ad.paddr);
  1444. for (i = 0; i < NUM_AOIS; i++) {
  1445. ret = install_fb(&data->fsl_diu_info[i]);
  1446. if (ret) {
  1447. dev_err(&pdev->dev, "could not register fb %d\n", i);
  1448. goto error;
  1449. }
  1450. }
  1451. if (request_irq_local(data)) {
  1452. dev_err(&pdev->dev, "could not claim irq\n");
  1453. goto error;
  1454. }
  1455. sysfs_attr_init(&data->dev_attr.attr);
  1456. data->dev_attr.attr.name = "monitor";
  1457. data->dev_attr.attr.mode = S_IRUGO|S_IWUSR;
  1458. data->dev_attr.show = show_monitor;
  1459. data->dev_attr.store = store_monitor;
  1460. ret = device_create_file(&pdev->dev, &data->dev_attr);
  1461. if (ret) {
  1462. dev_err(&pdev->dev, "could not create sysfs file %s\n",
  1463. data->dev_attr.attr.name);
  1464. }
  1465. dev_set_drvdata(&pdev->dev, data);
  1466. return 0;
  1467. error:
  1468. for (i = 0; i < NUM_AOIS; i++)
  1469. uninstall_fb(&data->fsl_diu_info[i]);
  1470. iounmap(data->diu_reg);
  1471. dma_free_coherent(&pdev->dev, sizeof(struct fsl_diu_data), data,
  1472. data->dma_addr);
  1473. return ret;
  1474. }
  1475. static int fsl_diu_remove(struct platform_device *pdev)
  1476. {
  1477. struct fsl_diu_data *data;
  1478. int i;
  1479. data = dev_get_drvdata(&pdev->dev);
  1480. disable_lcdc(&data->fsl_diu_info[0]);
  1481. free_irq_local(data);
  1482. for (i = 0; i < NUM_AOIS; i++)
  1483. uninstall_fb(&data->fsl_diu_info[i]);
  1484. iounmap(data->diu_reg);
  1485. dma_free_coherent(&pdev->dev, sizeof(struct fsl_diu_data), data,
  1486. data->dma_addr);
  1487. return 0;
  1488. }
  1489. #ifndef MODULE
  1490. static int __init fsl_diu_setup(char *options)
  1491. {
  1492. char *opt;
  1493. unsigned long val;
  1494. if (!options || !*options)
  1495. return 0;
  1496. while ((opt = strsep(&options, ",")) != NULL) {
  1497. if (!*opt)
  1498. continue;
  1499. if (!strncmp(opt, "monitor=", 8)) {
  1500. monitor_port = fsl_diu_name_to_port(opt + 8);
  1501. } else if (!strncmp(opt, "bpp=", 4)) {
  1502. if (!strict_strtoul(opt + 4, 10, &val))
  1503. default_bpp = val;
  1504. } else
  1505. fb_mode = opt;
  1506. }
  1507. return 0;
  1508. }
  1509. #endif
  1510. static struct of_device_id fsl_diu_match[] = {
  1511. #ifdef CONFIG_PPC_MPC512x
  1512. {
  1513. .compatible = "fsl,mpc5121-diu",
  1514. },
  1515. #endif
  1516. {
  1517. .compatible = "fsl,diu",
  1518. },
  1519. {}
  1520. };
  1521. MODULE_DEVICE_TABLE(of, fsl_diu_match);
  1522. static struct platform_driver fsl_diu_driver = {
  1523. .driver = {
  1524. .name = "fsl-diu-fb",
  1525. .owner = THIS_MODULE,
  1526. .of_match_table = fsl_diu_match,
  1527. },
  1528. .probe = fsl_diu_probe,
  1529. .remove = fsl_diu_remove,
  1530. .suspend = fsl_diu_suspend,
  1531. .resume = fsl_diu_resume,
  1532. };
  1533. static int __init fsl_diu_init(void)
  1534. {
  1535. #ifdef CONFIG_NOT_COHERENT_CACHE
  1536. struct device_node *np;
  1537. const u32 *prop;
  1538. #endif
  1539. int ret;
  1540. #ifndef MODULE
  1541. char *option;
  1542. /*
  1543. * For kernel boot options (in 'video=xxxfb:<options>' format)
  1544. */
  1545. if (fb_get_options("fslfb", &option))
  1546. return -ENODEV;
  1547. fsl_diu_setup(option);
  1548. #else
  1549. monitor_port = fsl_diu_name_to_port(monitor_string);
  1550. #endif
  1551. pr_info("Freescale Display Interface Unit (DIU) framebuffer driver\n");
  1552. #ifdef CONFIG_NOT_COHERENT_CACHE
  1553. np = of_find_node_by_type(NULL, "cpu");
  1554. if (!np) {
  1555. pr_err("fsl-diu-fb: can't find 'cpu' device node\n");
  1556. return -ENODEV;
  1557. }
  1558. prop = of_get_property(np, "d-cache-size", NULL);
  1559. if (prop == NULL) {
  1560. pr_err("fsl-diu-fb: missing 'd-cache-size' property' "
  1561. "in 'cpu' node\n");
  1562. of_node_put(np);
  1563. return -ENODEV;
  1564. }
  1565. /*
  1566. * Freescale PLRU requires 13/8 times the cache size to do a proper
  1567. * displacement flush
  1568. */
  1569. coherence_data_size = be32_to_cpup(prop) * 13;
  1570. coherence_data_size /= 8;
  1571. prop = of_get_property(np, "d-cache-line-size", NULL);
  1572. if (prop == NULL) {
  1573. pr_err("fsl-diu-fb: missing 'd-cache-line-size' property' "
  1574. "in 'cpu' node\n");
  1575. of_node_put(np);
  1576. return -ENODEV;
  1577. }
  1578. d_cache_line_size = be32_to_cpup(prop);
  1579. of_node_put(np);
  1580. coherence_data = vmalloc(coherence_data_size);
  1581. if (!coherence_data)
  1582. return -ENOMEM;
  1583. #endif
  1584. ret = platform_driver_register(&fsl_diu_driver);
  1585. if (ret) {
  1586. pr_err("fsl-diu-fb: failed to register platform driver\n");
  1587. #if defined(CONFIG_NOT_COHERENT_CACHE)
  1588. vfree(coherence_data);
  1589. #endif
  1590. }
  1591. return ret;
  1592. }
  1593. static void __exit fsl_diu_exit(void)
  1594. {
  1595. platform_driver_unregister(&fsl_diu_driver);
  1596. #if defined(CONFIG_NOT_COHERENT_CACHE)
  1597. vfree(coherence_data);
  1598. #endif
  1599. }
  1600. module_init(fsl_diu_init);
  1601. module_exit(fsl_diu_exit);
  1602. MODULE_AUTHOR("York Sun <yorksun@freescale.com>");
  1603. MODULE_DESCRIPTION("Freescale DIU framebuffer driver");
  1604. MODULE_LICENSE("GPL");
  1605. module_param_named(mode, fb_mode, charp, 0);
  1606. MODULE_PARM_DESC(mode,
  1607. "Specify resolution as \"<xres>x<yres>[-<bpp>][@<refresh>]\" ");
  1608. module_param_named(bpp, default_bpp, ulong, 0);
  1609. MODULE_PARM_DESC(bpp, "Specify bit-per-pixel if not specified in 'mode'");
  1610. module_param_named(monitor, monitor_string, charp, 0);
  1611. MODULE_PARM_DESC(monitor, "Specify the monitor port "
  1612. "(\"dvi\", \"lvds\", or \"dlvds\") if supported by the platform");