s3c-fb.c 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915
  1. /* linux/drivers/video/s3c-fb.c
  2. *
  3. * Copyright 2008 Openmoko Inc.
  4. * Copyright 2008-2010 Simtec Electronics
  5. * Ben Dooks <ben@simtec.co.uk>
  6. * http://armlinux.simtec.co.uk/
  7. *
  8. * Samsung SoC Framebuffer driver
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software FoundatIon.
  13. */
  14. #include <linux/kernel.h>
  15. #include <linux/module.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/dma-mapping.h>
  18. #include <linux/slab.h>
  19. #include <linux/init.h>
  20. #include <linux/clk.h>
  21. #include <linux/fb.h>
  22. #include <linux/io.h>
  23. #include <linux/uaccess.h>
  24. #include <linux/interrupt.h>
  25. #include <linux/pm_runtime.h>
  26. #include <mach/map.h>
  27. #include <plat/regs-fb-v4.h>
  28. #include <plat/fb.h>
  29. /* This driver will export a number of framebuffer interfaces depending
  30. * on the configuration passed in via the platform data. Each fb instance
  31. * maps to a hardware window. Currently there is no support for runtime
  32. * setting of the alpha-blending functions that each window has, so only
  33. * window 0 is actually useful.
  34. *
  35. * Window 0 is treated specially, it is used for the basis of the LCD
  36. * output timings and as the control for the output power-down state.
  37. */
  38. /* note, the previous use of <mach/regs-fb.h> to get platform specific data
  39. * has been replaced by using the platform device name to pick the correct
  40. * configuration data for the system.
  41. */
  42. #ifdef CONFIG_FB_S3C_DEBUG_REGWRITE
  43. #undef writel
  44. #define writel(v, r) do { \
  45. printk(KERN_DEBUG "%s: %08x => %p\n", __func__, (unsigned int)v, r); \
  46. __raw_writel(v, r); } while (0)
  47. #endif /* FB_S3C_DEBUG_REGWRITE */
  48. /* irq_flags bits */
  49. #define S3C_FB_VSYNC_IRQ_EN 0
  50. #define VSYNC_TIMEOUT_MSEC 50
  51. struct s3c_fb;
  52. #define VALID_BPP(x) (1 << ((x) - 1))
  53. #define OSD_BASE(win, variant) ((variant).osd + ((win) * (variant).osd_stride))
  54. #define VIDOSD_A(win, variant) (OSD_BASE(win, variant) + 0x00)
  55. #define VIDOSD_B(win, variant) (OSD_BASE(win, variant) + 0x04)
  56. #define VIDOSD_C(win, variant) (OSD_BASE(win, variant) + 0x08)
  57. #define VIDOSD_D(win, variant) (OSD_BASE(win, variant) + 0x0C)
  58. /**
  59. * struct s3c_fb_variant - fb variant information
  60. * @is_2443: Set if S3C2443/S3C2416 style hardware.
  61. * @nr_windows: The number of windows.
  62. * @vidtcon: The base for the VIDTCONx registers
  63. * @wincon: The base for the WINxCON registers.
  64. * @winmap: The base for the WINxMAP registers.
  65. * @keycon: The abse for the WxKEYCON registers.
  66. * @buf_start: Offset of buffer start registers.
  67. * @buf_size: Offset of buffer size registers.
  68. * @buf_end: Offset of buffer end registers.
  69. * @osd: The base for the OSD registers.
  70. * @palette: Address of palette memory, or 0 if none.
  71. * @has_prtcon: Set if has PRTCON register.
  72. * @has_shadowcon: Set if has SHADOWCON register.
  73. */
  74. struct s3c_fb_variant {
  75. unsigned int is_2443:1;
  76. unsigned short nr_windows;
  77. unsigned short vidtcon;
  78. unsigned short wincon;
  79. unsigned short winmap;
  80. unsigned short keycon;
  81. unsigned short buf_start;
  82. unsigned short buf_end;
  83. unsigned short buf_size;
  84. unsigned short osd;
  85. unsigned short osd_stride;
  86. unsigned short palette[S3C_FB_MAX_WIN];
  87. unsigned int has_prtcon:1;
  88. unsigned int has_shadowcon:1;
  89. };
  90. /**
  91. * struct s3c_fb_win_variant
  92. * @has_osd_c: Set if has OSD C register.
  93. * @has_osd_d: Set if has OSD D register.
  94. * @has_osd_alpha: Set if can change alpha transparency for a window.
  95. * @palette_sz: Size of palette in entries.
  96. * @palette_16bpp: Set if palette is 16bits wide.
  97. * @osd_size_off: If != 0, supports setting up OSD for a window; the appropriate
  98. * register is located at the given offset from OSD_BASE.
  99. * @valid_bpp: 1 bit per BPP setting to show valid bits-per-pixel.
  100. *
  101. * valid_bpp bit x is set if (x+1)BPP is supported.
  102. */
  103. struct s3c_fb_win_variant {
  104. unsigned int has_osd_c:1;
  105. unsigned int has_osd_d:1;
  106. unsigned int has_osd_alpha:1;
  107. unsigned int palette_16bpp:1;
  108. unsigned short osd_size_off;
  109. unsigned short palette_sz;
  110. u32 valid_bpp;
  111. };
  112. /**
  113. * struct s3c_fb_driverdata - per-device type driver data for init time.
  114. * @variant: The variant information for this driver.
  115. * @win: The window information for each window.
  116. */
  117. struct s3c_fb_driverdata {
  118. struct s3c_fb_variant variant;
  119. struct s3c_fb_win_variant *win[S3C_FB_MAX_WIN];
  120. };
  121. /**
  122. * struct s3c_fb_palette - palette information
  123. * @r: Red bitfield.
  124. * @g: Green bitfield.
  125. * @b: Blue bitfield.
  126. * @a: Alpha bitfield.
  127. */
  128. struct s3c_fb_palette {
  129. struct fb_bitfield r;
  130. struct fb_bitfield g;
  131. struct fb_bitfield b;
  132. struct fb_bitfield a;
  133. };
  134. /**
  135. * struct s3c_fb_win - per window private data for each framebuffer.
  136. * @windata: The platform data supplied for the window configuration.
  137. * @parent: The hardware that this window is part of.
  138. * @fbinfo: Pointer pack to the framebuffer info for this window.
  139. * @varint: The variant information for this window.
  140. * @palette_buffer: Buffer/cache to hold palette entries.
  141. * @pseudo_palette: For use in TRUECOLOUR modes for entries 0..15/
  142. * @index: The window number of this window.
  143. * @palette: The bitfields for changing r/g/b into a hardware palette entry.
  144. */
  145. struct s3c_fb_win {
  146. struct s3c_fb_pd_win *windata;
  147. struct s3c_fb *parent;
  148. struct fb_info *fbinfo;
  149. struct s3c_fb_palette palette;
  150. struct s3c_fb_win_variant variant;
  151. u32 *palette_buffer;
  152. u32 pseudo_palette[16];
  153. unsigned int index;
  154. };
  155. /**
  156. * struct s3c_fb_vsync - vsync information
  157. * @wait: a queue for processes waiting for vsync
  158. * @count: vsync interrupt count
  159. */
  160. struct s3c_fb_vsync {
  161. wait_queue_head_t wait;
  162. unsigned int count;
  163. };
  164. /**
  165. * struct s3c_fb - overall hardware state of the hardware
  166. * @slock: The spinlock protection for this data sturcture.
  167. * @dev: The device that we bound to, for printing, etc.
  168. * @regs_res: The resource we claimed for the IO registers.
  169. * @bus_clk: The clk (hclk) feeding our interface and possibly pixclk.
  170. * @regs: The mapped hardware registers.
  171. * @variant: Variant information for this hardware.
  172. * @enabled: A bitmask of enabled hardware windows.
  173. * @pdata: The platform configuration data passed with the device.
  174. * @windows: The hardware windows that have been claimed.
  175. * @irq_no: IRQ line number
  176. * @irq_flags: irq flags
  177. * @vsync_info: VSYNC-related information (count, queues...)
  178. */
  179. struct s3c_fb {
  180. spinlock_t slock;
  181. struct device *dev;
  182. struct resource *regs_res;
  183. struct clk *bus_clk;
  184. void __iomem *regs;
  185. struct s3c_fb_variant variant;
  186. unsigned char enabled;
  187. struct s3c_fb_platdata *pdata;
  188. struct s3c_fb_win *windows[S3C_FB_MAX_WIN];
  189. int irq_no;
  190. unsigned long irq_flags;
  191. struct s3c_fb_vsync vsync_info;
  192. };
  193. /**
  194. * s3c_fb_validate_win_bpp - validate the bits-per-pixel for this mode.
  195. * @win: The device window.
  196. * @bpp: The bit depth.
  197. */
  198. static bool s3c_fb_validate_win_bpp(struct s3c_fb_win *win, unsigned int bpp)
  199. {
  200. return win->variant.valid_bpp & VALID_BPP(bpp);
  201. }
  202. /**
  203. * s3c_fb_check_var() - framebuffer layer request to verify a given mode.
  204. * @var: The screen information to verify.
  205. * @info: The framebuffer device.
  206. *
  207. * Framebuffer layer call to verify the given information and allow us to
  208. * update various information depending on the hardware capabilities.
  209. */
  210. static int s3c_fb_check_var(struct fb_var_screeninfo *var,
  211. struct fb_info *info)
  212. {
  213. struct s3c_fb_win *win = info->par;
  214. struct s3c_fb *sfb = win->parent;
  215. dev_dbg(sfb->dev, "checking parameters\n");
  216. var->xres_virtual = max(var->xres_virtual, var->xres);
  217. var->yres_virtual = max(var->yres_virtual, var->yres);
  218. if (!s3c_fb_validate_win_bpp(win, var->bits_per_pixel)) {
  219. dev_dbg(sfb->dev, "win %d: unsupported bpp %d\n",
  220. win->index, var->bits_per_pixel);
  221. return -EINVAL;
  222. }
  223. /* always ensure these are zero, for drop through cases below */
  224. var->transp.offset = 0;
  225. var->transp.length = 0;
  226. switch (var->bits_per_pixel) {
  227. case 1:
  228. case 2:
  229. case 4:
  230. case 8:
  231. if (sfb->variant.palette[win->index] != 0) {
  232. /* non palletised, A:1,R:2,G:3,B:2 mode */
  233. var->red.offset = 4;
  234. var->green.offset = 2;
  235. var->blue.offset = 0;
  236. var->red.length = 5;
  237. var->green.length = 3;
  238. var->blue.length = 2;
  239. var->transp.offset = 7;
  240. var->transp.length = 1;
  241. } else {
  242. var->red.offset = 0;
  243. var->red.length = var->bits_per_pixel;
  244. var->green = var->red;
  245. var->blue = var->red;
  246. }
  247. break;
  248. case 19:
  249. /* 666 with one bit alpha/transparency */
  250. var->transp.offset = 18;
  251. var->transp.length = 1;
  252. case 18:
  253. var->bits_per_pixel = 32;
  254. /* 666 format */
  255. var->red.offset = 12;
  256. var->green.offset = 6;
  257. var->blue.offset = 0;
  258. var->red.length = 6;
  259. var->green.length = 6;
  260. var->blue.length = 6;
  261. break;
  262. case 16:
  263. /* 16 bpp, 565 format */
  264. var->red.offset = 11;
  265. var->green.offset = 5;
  266. var->blue.offset = 0;
  267. var->red.length = 5;
  268. var->green.length = 6;
  269. var->blue.length = 5;
  270. break;
  271. case 32:
  272. case 28:
  273. case 25:
  274. var->transp.length = var->bits_per_pixel - 24;
  275. var->transp.offset = 24;
  276. /* drop through */
  277. case 24:
  278. /* our 24bpp is unpacked, so 32bpp */
  279. var->bits_per_pixel = 32;
  280. var->red.offset = 16;
  281. var->red.length = 8;
  282. var->green.offset = 8;
  283. var->green.length = 8;
  284. var->blue.offset = 0;
  285. var->blue.length = 8;
  286. break;
  287. default:
  288. dev_err(sfb->dev, "invalid bpp\n");
  289. }
  290. dev_dbg(sfb->dev, "%s: verified parameters\n", __func__);
  291. return 0;
  292. }
  293. /**
  294. * s3c_fb_calc_pixclk() - calculate the divider to create the pixel clock.
  295. * @sfb: The hardware state.
  296. * @pixclock: The pixel clock wanted, in picoseconds.
  297. *
  298. * Given the specified pixel clock, work out the necessary divider to get
  299. * close to the output frequency.
  300. */
  301. static int s3c_fb_calc_pixclk(struct s3c_fb *sfb, unsigned int pixclk)
  302. {
  303. unsigned long clk = clk_get_rate(sfb->bus_clk);
  304. unsigned long long tmp;
  305. unsigned int result;
  306. tmp = (unsigned long long)clk;
  307. tmp *= pixclk;
  308. do_div(tmp, 1000000000UL);
  309. result = (unsigned int)tmp / 1000;
  310. dev_dbg(sfb->dev, "pixclk=%u, clk=%lu, div=%d (%lu)\n",
  311. pixclk, clk, result, clk / result);
  312. return result;
  313. }
  314. /**
  315. * s3c_fb_align_word() - align pixel count to word boundary
  316. * @bpp: The number of bits per pixel
  317. * @pix: The value to be aligned.
  318. *
  319. * Align the given pixel count so that it will start on an 32bit word
  320. * boundary.
  321. */
  322. static int s3c_fb_align_word(unsigned int bpp, unsigned int pix)
  323. {
  324. int pix_per_word;
  325. if (bpp > 16)
  326. return pix;
  327. pix_per_word = (8 * 32) / bpp;
  328. return ALIGN(pix, pix_per_word);
  329. }
  330. /**
  331. * vidosd_set_size() - set OSD size for a window
  332. *
  333. * @win: the window to set OSD size for
  334. * @size: OSD size register value
  335. */
  336. static void vidosd_set_size(struct s3c_fb_win *win, u32 size)
  337. {
  338. struct s3c_fb *sfb = win->parent;
  339. /* OSD can be set up if osd_size_off != 0 for this window */
  340. if (win->variant.osd_size_off)
  341. writel(size, sfb->regs + OSD_BASE(win->index, sfb->variant)
  342. + win->variant.osd_size_off);
  343. }
  344. /**
  345. * vidosd_set_alpha() - set alpha transparency for a window
  346. *
  347. * @win: the window to set OSD size for
  348. * @alpha: alpha register value
  349. */
  350. static void vidosd_set_alpha(struct s3c_fb_win *win, u32 alpha)
  351. {
  352. struct s3c_fb *sfb = win->parent;
  353. if (win->variant.has_osd_alpha)
  354. writel(alpha, sfb->regs + VIDOSD_C(win->index, sfb->variant));
  355. }
  356. /**
  357. * shadow_protect_win() - disable updating values from shadow registers at vsync
  358. *
  359. * @win: window to protect registers for
  360. * @protect: 1 to protect (disable updates)
  361. */
  362. static void shadow_protect_win(struct s3c_fb_win *win, bool protect)
  363. {
  364. struct s3c_fb *sfb = win->parent;
  365. u32 reg;
  366. if (protect) {
  367. if (sfb->variant.has_prtcon) {
  368. writel(PRTCON_PROTECT, sfb->regs + PRTCON);
  369. } else if (sfb->variant.has_shadowcon) {
  370. reg = readl(sfb->regs + SHADOWCON);
  371. writel(reg | SHADOWCON_WINx_PROTECT(win->index),
  372. sfb->regs + SHADOWCON);
  373. }
  374. } else {
  375. if (sfb->variant.has_prtcon) {
  376. writel(0, sfb->regs + PRTCON);
  377. } else if (sfb->variant.has_shadowcon) {
  378. reg = readl(sfb->regs + SHADOWCON);
  379. writel(reg & ~SHADOWCON_WINx_PROTECT(win->index),
  380. sfb->regs + SHADOWCON);
  381. }
  382. }
  383. }
  384. /**
  385. * s3c_fb_set_par() - framebuffer request to set new framebuffer state.
  386. * @info: The framebuffer to change.
  387. *
  388. * Framebuffer layer request to set a new mode for the specified framebuffer
  389. */
  390. static int s3c_fb_set_par(struct fb_info *info)
  391. {
  392. struct fb_var_screeninfo *var = &info->var;
  393. struct s3c_fb_win *win = info->par;
  394. struct s3c_fb *sfb = win->parent;
  395. void __iomem *regs = sfb->regs;
  396. void __iomem *buf = regs;
  397. int win_no = win->index;
  398. u32 alpha = 0;
  399. u32 data;
  400. u32 pagewidth;
  401. int clkdiv;
  402. dev_dbg(sfb->dev, "setting framebuffer parameters\n");
  403. shadow_protect_win(win, 1);
  404. switch (var->bits_per_pixel) {
  405. case 32:
  406. case 24:
  407. case 16:
  408. case 12:
  409. info->fix.visual = FB_VISUAL_TRUECOLOR;
  410. break;
  411. case 8:
  412. if (win->variant.palette_sz >= 256)
  413. info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
  414. else
  415. info->fix.visual = FB_VISUAL_TRUECOLOR;
  416. break;
  417. case 1:
  418. info->fix.visual = FB_VISUAL_MONO01;
  419. break;
  420. default:
  421. info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
  422. break;
  423. }
  424. info->fix.line_length = (var->xres_virtual * var->bits_per_pixel) / 8;
  425. info->fix.xpanstep = info->var.xres_virtual > info->var.xres ? 1 : 0;
  426. info->fix.ypanstep = info->var.yres_virtual > info->var.yres ? 1 : 0;
  427. /* disable the window whilst we update it */
  428. writel(0, regs + WINCON(win_no));
  429. /* use platform specified window as the basis for the lcd timings */
  430. if (win_no == sfb->pdata->default_win) {
  431. clkdiv = s3c_fb_calc_pixclk(sfb, var->pixclock);
  432. data = sfb->pdata->vidcon0;
  433. data &= ~(VIDCON0_CLKVAL_F_MASK | VIDCON0_CLKDIR);
  434. if (clkdiv > 1)
  435. data |= VIDCON0_CLKVAL_F(clkdiv-1) | VIDCON0_CLKDIR;
  436. else
  437. data &= ~VIDCON0_CLKDIR; /* 1:1 clock */
  438. /* write the timing data to the panel */
  439. if (sfb->variant.is_2443)
  440. data |= (1 << 5);
  441. data |= VIDCON0_ENVID | VIDCON0_ENVID_F;
  442. writel(data, regs + VIDCON0);
  443. data = VIDTCON0_VBPD(var->upper_margin - 1) |
  444. VIDTCON0_VFPD(var->lower_margin - 1) |
  445. VIDTCON0_VSPW(var->vsync_len - 1);
  446. writel(data, regs + sfb->variant.vidtcon);
  447. data = VIDTCON1_HBPD(var->left_margin - 1) |
  448. VIDTCON1_HFPD(var->right_margin - 1) |
  449. VIDTCON1_HSPW(var->hsync_len - 1);
  450. /* VIDTCON1 */
  451. writel(data, regs + sfb->variant.vidtcon + 4);
  452. data = VIDTCON2_LINEVAL(var->yres - 1) |
  453. VIDTCON2_HOZVAL(var->xres - 1);
  454. writel(data, regs + sfb->variant.vidtcon + 8);
  455. }
  456. /* write the buffer address */
  457. /* start and end registers stride is 8 */
  458. buf = regs + win_no * 8;
  459. writel(info->fix.smem_start, buf + sfb->variant.buf_start);
  460. data = info->fix.smem_start + info->fix.line_length * var->yres;
  461. writel(data, buf + sfb->variant.buf_end);
  462. pagewidth = (var->xres * var->bits_per_pixel) >> 3;
  463. data = VIDW_BUF_SIZE_OFFSET(info->fix.line_length - pagewidth) |
  464. VIDW_BUF_SIZE_PAGEWIDTH(pagewidth);
  465. writel(data, regs + sfb->variant.buf_size + (win_no * 4));
  466. /* write 'OSD' registers to control position of framebuffer */
  467. data = VIDOSDxA_TOPLEFT_X(0) | VIDOSDxA_TOPLEFT_Y(0);
  468. writel(data, regs + VIDOSD_A(win_no, sfb->variant));
  469. data = VIDOSDxB_BOTRIGHT_X(s3c_fb_align_word(var->bits_per_pixel,
  470. var->xres - 1)) |
  471. VIDOSDxB_BOTRIGHT_Y(var->yres - 1);
  472. writel(data, regs + VIDOSD_B(win_no, sfb->variant));
  473. data = var->xres * var->yres;
  474. alpha = VIDISD14C_ALPHA1_R(0xf) |
  475. VIDISD14C_ALPHA1_G(0xf) |
  476. VIDISD14C_ALPHA1_B(0xf);
  477. vidosd_set_alpha(win, alpha);
  478. vidosd_set_size(win, data);
  479. /* Enable DMA channel for this window */
  480. if (sfb->variant.has_shadowcon) {
  481. data = readl(sfb->regs + SHADOWCON);
  482. data |= SHADOWCON_CHx_ENABLE(win_no);
  483. writel(data, sfb->regs + SHADOWCON);
  484. }
  485. data = WINCONx_ENWIN;
  486. /* note, since we have to round up the bits-per-pixel, we end up
  487. * relying on the bitfield information for r/g/b/a to work out
  488. * exactly which mode of operation is intended. */
  489. switch (var->bits_per_pixel) {
  490. case 1:
  491. data |= WINCON0_BPPMODE_1BPP;
  492. data |= WINCONx_BITSWP;
  493. data |= WINCONx_BURSTLEN_4WORD;
  494. break;
  495. case 2:
  496. data |= WINCON0_BPPMODE_2BPP;
  497. data |= WINCONx_BITSWP;
  498. data |= WINCONx_BURSTLEN_8WORD;
  499. break;
  500. case 4:
  501. data |= WINCON0_BPPMODE_4BPP;
  502. data |= WINCONx_BITSWP;
  503. data |= WINCONx_BURSTLEN_8WORD;
  504. break;
  505. case 8:
  506. if (var->transp.length != 0)
  507. data |= WINCON1_BPPMODE_8BPP_1232;
  508. else
  509. data |= WINCON0_BPPMODE_8BPP_PALETTE;
  510. data |= WINCONx_BURSTLEN_8WORD;
  511. data |= WINCONx_BYTSWP;
  512. break;
  513. case 16:
  514. if (var->transp.length != 0)
  515. data |= WINCON1_BPPMODE_16BPP_A1555;
  516. else
  517. data |= WINCON0_BPPMODE_16BPP_565;
  518. data |= WINCONx_HAWSWP;
  519. data |= WINCONx_BURSTLEN_16WORD;
  520. break;
  521. case 24:
  522. case 32:
  523. if (var->red.length == 6) {
  524. if (var->transp.length != 0)
  525. data |= WINCON1_BPPMODE_19BPP_A1666;
  526. else
  527. data |= WINCON1_BPPMODE_18BPP_666;
  528. } else if (var->transp.length == 1)
  529. data |= WINCON1_BPPMODE_25BPP_A1888
  530. | WINCON1_BLD_PIX;
  531. else if (var->transp.length == 4)
  532. data |= WINCON1_BPPMODE_28BPP_A4888
  533. | WINCON1_BLD_PIX | WINCON1_ALPHA_SEL;
  534. else
  535. data |= WINCON0_BPPMODE_24BPP_888;
  536. data |= WINCONx_WSWP;
  537. data |= WINCONx_BURSTLEN_16WORD;
  538. break;
  539. }
  540. /* Enable the colour keying for the window below this one */
  541. if (win_no > 0) {
  542. u32 keycon0_data = 0, keycon1_data = 0;
  543. void __iomem *keycon = regs + sfb->variant.keycon;
  544. keycon0_data = ~(WxKEYCON0_KEYBL_EN |
  545. WxKEYCON0_KEYEN_F |
  546. WxKEYCON0_DIRCON) | WxKEYCON0_COMPKEY(0);
  547. keycon1_data = WxKEYCON1_COLVAL(0xffffff);
  548. keycon += (win_no - 1) * 8;
  549. writel(keycon0_data, keycon + WKEYCON0);
  550. writel(keycon1_data, keycon + WKEYCON1);
  551. }
  552. writel(data, regs + sfb->variant.wincon + (win_no * 4));
  553. writel(0x0, regs + sfb->variant.winmap + (win_no * 4));
  554. shadow_protect_win(win, 0);
  555. return 0;
  556. }
  557. /**
  558. * s3c_fb_update_palette() - set or schedule a palette update.
  559. * @sfb: The hardware information.
  560. * @win: The window being updated.
  561. * @reg: The palette index being changed.
  562. * @value: The computed palette value.
  563. *
  564. * Change the value of a palette register, either by directly writing to
  565. * the palette (this requires the palette RAM to be disconnected from the
  566. * hardware whilst this is in progress) or schedule the update for later.
  567. *
  568. * At the moment, since we have no VSYNC interrupt support, we simply set
  569. * the palette entry directly.
  570. */
  571. static void s3c_fb_update_palette(struct s3c_fb *sfb,
  572. struct s3c_fb_win *win,
  573. unsigned int reg,
  574. u32 value)
  575. {
  576. void __iomem *palreg;
  577. u32 palcon;
  578. palreg = sfb->regs + sfb->variant.palette[win->index];
  579. dev_dbg(sfb->dev, "%s: win %d, reg %d (%p): %08x\n",
  580. __func__, win->index, reg, palreg, value);
  581. win->palette_buffer[reg] = value;
  582. palcon = readl(sfb->regs + WPALCON);
  583. writel(palcon | WPALCON_PAL_UPDATE, sfb->regs + WPALCON);
  584. if (win->variant.palette_16bpp)
  585. writew(value, palreg + (reg * 2));
  586. else
  587. writel(value, palreg + (reg * 4));
  588. writel(palcon, sfb->regs + WPALCON);
  589. }
  590. static inline unsigned int chan_to_field(unsigned int chan,
  591. struct fb_bitfield *bf)
  592. {
  593. chan &= 0xffff;
  594. chan >>= 16 - bf->length;
  595. return chan << bf->offset;
  596. }
  597. /**
  598. * s3c_fb_setcolreg() - framebuffer layer request to change palette.
  599. * @regno: The palette index to change.
  600. * @red: The red field for the palette data.
  601. * @green: The green field for the palette data.
  602. * @blue: The blue field for the palette data.
  603. * @trans: The transparency (alpha) field for the palette data.
  604. * @info: The framebuffer being changed.
  605. */
  606. static int s3c_fb_setcolreg(unsigned regno,
  607. unsigned red, unsigned green, unsigned blue,
  608. unsigned transp, struct fb_info *info)
  609. {
  610. struct s3c_fb_win *win = info->par;
  611. struct s3c_fb *sfb = win->parent;
  612. unsigned int val;
  613. dev_dbg(sfb->dev, "%s: win %d: %d => rgb=%d/%d/%d\n",
  614. __func__, win->index, regno, red, green, blue);
  615. switch (info->fix.visual) {
  616. case FB_VISUAL_TRUECOLOR:
  617. /* true-colour, use pseudo-palette */
  618. if (regno < 16) {
  619. u32 *pal = info->pseudo_palette;
  620. val = chan_to_field(red, &info->var.red);
  621. val |= chan_to_field(green, &info->var.green);
  622. val |= chan_to_field(blue, &info->var.blue);
  623. pal[regno] = val;
  624. }
  625. break;
  626. case FB_VISUAL_PSEUDOCOLOR:
  627. if (regno < win->variant.palette_sz) {
  628. val = chan_to_field(red, &win->palette.r);
  629. val |= chan_to_field(green, &win->palette.g);
  630. val |= chan_to_field(blue, &win->palette.b);
  631. s3c_fb_update_palette(sfb, win, regno, val);
  632. }
  633. break;
  634. default:
  635. return 1; /* unknown type */
  636. }
  637. return 0;
  638. }
  639. /**
  640. * s3c_fb_enable() - Set the state of the main LCD output
  641. * @sfb: The main framebuffer state.
  642. * @enable: The state to set.
  643. */
  644. static void s3c_fb_enable(struct s3c_fb *sfb, int enable)
  645. {
  646. u32 vidcon0 = readl(sfb->regs + VIDCON0);
  647. if (enable)
  648. vidcon0 |= VIDCON0_ENVID | VIDCON0_ENVID_F;
  649. else {
  650. /* see the note in the framebuffer datasheet about
  651. * why you cannot take both of these bits down at the
  652. * same time. */
  653. if (!(vidcon0 & VIDCON0_ENVID))
  654. return;
  655. vidcon0 |= VIDCON0_ENVID;
  656. vidcon0 &= ~VIDCON0_ENVID_F;
  657. }
  658. writel(vidcon0, sfb->regs + VIDCON0);
  659. }
  660. /**
  661. * s3c_fb_blank() - blank or unblank the given window
  662. * @blank_mode: The blank state from FB_BLANK_*
  663. * @info: The framebuffer to blank.
  664. *
  665. * Framebuffer layer request to change the power state.
  666. */
  667. static int s3c_fb_blank(int blank_mode, struct fb_info *info)
  668. {
  669. struct s3c_fb_win *win = info->par;
  670. struct s3c_fb *sfb = win->parent;
  671. unsigned int index = win->index;
  672. u32 wincon;
  673. dev_dbg(sfb->dev, "blank mode %d\n", blank_mode);
  674. wincon = readl(sfb->regs + sfb->variant.wincon + (index * 4));
  675. switch (blank_mode) {
  676. case FB_BLANK_POWERDOWN:
  677. wincon &= ~WINCONx_ENWIN;
  678. sfb->enabled &= ~(1 << index);
  679. /* fall through to FB_BLANK_NORMAL */
  680. case FB_BLANK_NORMAL:
  681. /* disable the DMA and display 0x0 (black) */
  682. writel(WINxMAP_MAP | WINxMAP_MAP_COLOUR(0x0),
  683. sfb->regs + sfb->variant.winmap + (index * 4));
  684. break;
  685. case FB_BLANK_UNBLANK:
  686. writel(0x0, sfb->regs + sfb->variant.winmap + (index * 4));
  687. wincon |= WINCONx_ENWIN;
  688. sfb->enabled |= (1 << index);
  689. break;
  690. case FB_BLANK_VSYNC_SUSPEND:
  691. case FB_BLANK_HSYNC_SUSPEND:
  692. default:
  693. return 1;
  694. }
  695. writel(wincon, sfb->regs + sfb->variant.wincon + (index * 4));
  696. /* Check the enabled state to see if we need to be running the
  697. * main LCD interface, as if there are no active windows then
  698. * it is highly likely that we also do not need to output
  699. * anything.
  700. */
  701. /* We could do something like the following code, but the current
  702. * system of using framebuffer events means that we cannot make
  703. * the distinction between just window 0 being inactive and all
  704. * the windows being down.
  705. *
  706. * s3c_fb_enable(sfb, sfb->enabled ? 1 : 0);
  707. */
  708. /* we're stuck with this until we can do something about overriding
  709. * the power control using the blanking event for a single fb.
  710. */
  711. if (index == sfb->pdata->default_win)
  712. s3c_fb_enable(sfb, blank_mode != FB_BLANK_POWERDOWN ? 1 : 0);
  713. return 0;
  714. }
  715. /**
  716. * s3c_fb_pan_display() - Pan the display.
  717. *
  718. * Note that the offsets can be written to the device at any time, as their
  719. * values are latched at each vsync automatically. This also means that only
  720. * the last call to this function will have any effect on next vsync, but
  721. * there is no need to sleep waiting for it to prevent tearing.
  722. *
  723. * @var: The screen information to verify.
  724. * @info: The framebuffer device.
  725. */
  726. static int s3c_fb_pan_display(struct fb_var_screeninfo *var,
  727. struct fb_info *info)
  728. {
  729. struct s3c_fb_win *win = info->par;
  730. struct s3c_fb *sfb = win->parent;
  731. void __iomem *buf = sfb->regs + win->index * 8;
  732. unsigned int start_boff, end_boff;
  733. /* Offset in bytes to the start of the displayed area */
  734. start_boff = var->yoffset * info->fix.line_length;
  735. /* X offset depends on the current bpp */
  736. if (info->var.bits_per_pixel >= 8) {
  737. start_boff += var->xoffset * (info->var.bits_per_pixel >> 3);
  738. } else {
  739. switch (info->var.bits_per_pixel) {
  740. case 4:
  741. start_boff += var->xoffset >> 1;
  742. break;
  743. case 2:
  744. start_boff += var->xoffset >> 2;
  745. break;
  746. case 1:
  747. start_boff += var->xoffset >> 3;
  748. break;
  749. default:
  750. dev_err(sfb->dev, "invalid bpp\n");
  751. return -EINVAL;
  752. }
  753. }
  754. /* Offset in bytes to the end of the displayed area */
  755. end_boff = start_boff + var->yres * info->fix.line_length;
  756. /* Temporarily turn off per-vsync update from shadow registers until
  757. * both start and end addresses are updated to prevent corruption */
  758. shadow_protect_win(win, 1);
  759. writel(info->fix.smem_start + start_boff, buf + sfb->variant.buf_start);
  760. writel(info->fix.smem_start + end_boff, buf + sfb->variant.buf_end);
  761. shadow_protect_win(win, 0);
  762. return 0;
  763. }
  764. /**
  765. * s3c_fb_enable_irq() - enable framebuffer interrupts
  766. * @sfb: main hardware state
  767. */
  768. static void s3c_fb_enable_irq(struct s3c_fb *sfb)
  769. {
  770. void __iomem *regs = sfb->regs;
  771. u32 irq_ctrl_reg;
  772. if (!test_and_set_bit(S3C_FB_VSYNC_IRQ_EN, &sfb->irq_flags)) {
  773. /* IRQ disabled, enable it */
  774. irq_ctrl_reg = readl(regs + VIDINTCON0);
  775. irq_ctrl_reg |= VIDINTCON0_INT_ENABLE;
  776. irq_ctrl_reg |= VIDINTCON0_INT_FRAME;
  777. irq_ctrl_reg &= ~VIDINTCON0_FRAMESEL0_MASK;
  778. irq_ctrl_reg |= VIDINTCON0_FRAMESEL0_VSYNC;
  779. irq_ctrl_reg &= ~VIDINTCON0_FRAMESEL1_MASK;
  780. irq_ctrl_reg |= VIDINTCON0_FRAMESEL1_NONE;
  781. writel(irq_ctrl_reg, regs + VIDINTCON0);
  782. }
  783. }
  784. /**
  785. * s3c_fb_disable_irq() - disable framebuffer interrupts
  786. * @sfb: main hardware state
  787. */
  788. static void s3c_fb_disable_irq(struct s3c_fb *sfb)
  789. {
  790. void __iomem *regs = sfb->regs;
  791. u32 irq_ctrl_reg;
  792. if (test_and_clear_bit(S3C_FB_VSYNC_IRQ_EN, &sfb->irq_flags)) {
  793. /* IRQ enabled, disable it */
  794. irq_ctrl_reg = readl(regs + VIDINTCON0);
  795. irq_ctrl_reg &= ~VIDINTCON0_INT_FRAME;
  796. irq_ctrl_reg &= ~VIDINTCON0_INT_ENABLE;
  797. writel(irq_ctrl_reg, regs + VIDINTCON0);
  798. }
  799. }
  800. static irqreturn_t s3c_fb_irq(int irq, void *dev_id)
  801. {
  802. struct s3c_fb *sfb = dev_id;
  803. void __iomem *regs = sfb->regs;
  804. u32 irq_sts_reg;
  805. spin_lock(&sfb->slock);
  806. irq_sts_reg = readl(regs + VIDINTCON1);
  807. if (irq_sts_reg & VIDINTCON1_INT_FRAME) {
  808. /* VSYNC interrupt, accept it */
  809. writel(VIDINTCON1_INT_FRAME, regs + VIDINTCON1);
  810. sfb->vsync_info.count++;
  811. wake_up_interruptible(&sfb->vsync_info.wait);
  812. }
  813. /* We only support waiting for VSYNC for now, so it's safe
  814. * to always disable irqs here.
  815. */
  816. s3c_fb_disable_irq(sfb);
  817. spin_unlock(&sfb->slock);
  818. return IRQ_HANDLED;
  819. }
  820. /**
  821. * s3c_fb_wait_for_vsync() - sleep until next VSYNC interrupt or timeout
  822. * @sfb: main hardware state
  823. * @crtc: head index.
  824. */
  825. static int s3c_fb_wait_for_vsync(struct s3c_fb *sfb, u32 crtc)
  826. {
  827. unsigned long count;
  828. int ret;
  829. if (crtc != 0)
  830. return -ENODEV;
  831. count = sfb->vsync_info.count;
  832. s3c_fb_enable_irq(sfb);
  833. ret = wait_event_interruptible_timeout(sfb->vsync_info.wait,
  834. count != sfb->vsync_info.count,
  835. msecs_to_jiffies(VSYNC_TIMEOUT_MSEC));
  836. if (ret == 0)
  837. return -ETIMEDOUT;
  838. return 0;
  839. }
  840. static int s3c_fb_ioctl(struct fb_info *info, unsigned int cmd,
  841. unsigned long arg)
  842. {
  843. struct s3c_fb_win *win = info->par;
  844. struct s3c_fb *sfb = win->parent;
  845. int ret;
  846. u32 crtc;
  847. switch (cmd) {
  848. case FBIO_WAITFORVSYNC:
  849. if (get_user(crtc, (u32 __user *)arg)) {
  850. ret = -EFAULT;
  851. break;
  852. }
  853. ret = s3c_fb_wait_for_vsync(sfb, crtc);
  854. break;
  855. default:
  856. ret = -ENOTTY;
  857. }
  858. return ret;
  859. }
  860. static int s3c_fb_open(struct fb_info *info, int user)
  861. {
  862. struct s3c_fb_win *win = info->par;
  863. struct s3c_fb *sfb = win->parent;
  864. pm_runtime_get_sync(sfb->dev);
  865. return 0;
  866. }
  867. static int s3c_fb_release(struct fb_info *info, int user)
  868. {
  869. struct s3c_fb_win *win = info->par;
  870. struct s3c_fb *sfb = win->parent;
  871. pm_runtime_put_sync(sfb->dev);
  872. return 0;
  873. }
  874. static struct fb_ops s3c_fb_ops = {
  875. .owner = THIS_MODULE,
  876. .fb_open = s3c_fb_open,
  877. .fb_release = s3c_fb_release,
  878. .fb_check_var = s3c_fb_check_var,
  879. .fb_set_par = s3c_fb_set_par,
  880. .fb_blank = s3c_fb_blank,
  881. .fb_setcolreg = s3c_fb_setcolreg,
  882. .fb_fillrect = cfb_fillrect,
  883. .fb_copyarea = cfb_copyarea,
  884. .fb_imageblit = cfb_imageblit,
  885. .fb_pan_display = s3c_fb_pan_display,
  886. .fb_ioctl = s3c_fb_ioctl,
  887. };
  888. /**
  889. * s3c_fb_missing_pixclock() - calculates pixel clock
  890. * @mode: The video mode to change.
  891. *
  892. * Calculate the pixel clock when none has been given through platform data.
  893. */
  894. static void __devinit s3c_fb_missing_pixclock(struct fb_videomode *mode)
  895. {
  896. u64 pixclk = 1000000000000ULL;
  897. u32 div;
  898. div = mode->left_margin + mode->hsync_len + mode->right_margin +
  899. mode->xres;
  900. div *= mode->upper_margin + mode->vsync_len + mode->lower_margin +
  901. mode->yres;
  902. div *= mode->refresh ? : 60;
  903. do_div(pixclk, div);
  904. mode->pixclock = pixclk;
  905. }
  906. /**
  907. * s3c_fb_alloc_memory() - allocate display memory for framebuffer window
  908. * @sfb: The base resources for the hardware.
  909. * @win: The window to initialise memory for.
  910. *
  911. * Allocate memory for the given framebuffer.
  912. */
  913. static int __devinit s3c_fb_alloc_memory(struct s3c_fb *sfb,
  914. struct s3c_fb_win *win)
  915. {
  916. struct s3c_fb_pd_win *windata = win->windata;
  917. unsigned int real_size, virt_size, size;
  918. struct fb_info *fbi = win->fbinfo;
  919. dma_addr_t map_dma;
  920. dev_dbg(sfb->dev, "allocating memory for display\n");
  921. real_size = windata->win_mode.xres * windata->win_mode.yres;
  922. virt_size = windata->virtual_x * windata->virtual_y;
  923. dev_dbg(sfb->dev, "real_size=%u (%u.%u), virt_size=%u (%u.%u)\n",
  924. real_size, windata->win_mode.xres, windata->win_mode.yres,
  925. virt_size, windata->virtual_x, windata->virtual_y);
  926. size = (real_size > virt_size) ? real_size : virt_size;
  927. size *= (windata->max_bpp > 16) ? 32 : windata->max_bpp;
  928. size /= 8;
  929. fbi->fix.smem_len = size;
  930. size = PAGE_ALIGN(size);
  931. dev_dbg(sfb->dev, "want %u bytes for window\n", size);
  932. fbi->screen_base = dma_alloc_writecombine(sfb->dev, size,
  933. &map_dma, GFP_KERNEL);
  934. if (!fbi->screen_base)
  935. return -ENOMEM;
  936. dev_dbg(sfb->dev, "mapped %x to %p\n",
  937. (unsigned int)map_dma, fbi->screen_base);
  938. memset(fbi->screen_base, 0x0, size);
  939. fbi->fix.smem_start = map_dma;
  940. return 0;
  941. }
  942. /**
  943. * s3c_fb_free_memory() - free the display memory for the given window
  944. * @sfb: The base resources for the hardware.
  945. * @win: The window to free the display memory for.
  946. *
  947. * Free the display memory allocated by s3c_fb_alloc_memory().
  948. */
  949. static void s3c_fb_free_memory(struct s3c_fb *sfb, struct s3c_fb_win *win)
  950. {
  951. struct fb_info *fbi = win->fbinfo;
  952. if (fbi->screen_base)
  953. dma_free_writecombine(sfb->dev, PAGE_ALIGN(fbi->fix.smem_len),
  954. fbi->screen_base, fbi->fix.smem_start);
  955. }
  956. /**
  957. * s3c_fb_release_win() - release resources for a framebuffer window.
  958. * @win: The window to cleanup the resources for.
  959. *
  960. * Release the resources that where claimed for the hardware window,
  961. * such as the framebuffer instance and any memory claimed for it.
  962. */
  963. static void s3c_fb_release_win(struct s3c_fb *sfb, struct s3c_fb_win *win)
  964. {
  965. u32 data;
  966. if (win->fbinfo) {
  967. if (sfb->variant.has_shadowcon) {
  968. data = readl(sfb->regs + SHADOWCON);
  969. data &= ~SHADOWCON_CHx_ENABLE(win->index);
  970. data &= ~SHADOWCON_CHx_LOCAL_ENABLE(win->index);
  971. writel(data, sfb->regs + SHADOWCON);
  972. }
  973. unregister_framebuffer(win->fbinfo);
  974. if (win->fbinfo->cmap.len)
  975. fb_dealloc_cmap(&win->fbinfo->cmap);
  976. s3c_fb_free_memory(sfb, win);
  977. framebuffer_release(win->fbinfo);
  978. }
  979. }
  980. /**
  981. * s3c_fb_probe_win() - register an hardware window
  982. * @sfb: The base resources for the hardware
  983. * @variant: The variant information for this window.
  984. * @res: Pointer to where to place the resultant window.
  985. *
  986. * Allocate and do the basic initialisation for one of the hardware's graphics
  987. * windows.
  988. */
  989. static int __devinit s3c_fb_probe_win(struct s3c_fb *sfb, unsigned int win_no,
  990. struct s3c_fb_win_variant *variant,
  991. struct s3c_fb_win **res)
  992. {
  993. struct fb_var_screeninfo *var;
  994. struct fb_videomode *initmode;
  995. struct s3c_fb_pd_win *windata;
  996. struct s3c_fb_win *win;
  997. struct fb_info *fbinfo;
  998. int palette_size;
  999. int ret;
  1000. dev_dbg(sfb->dev, "probing window %d, variant %p\n", win_no, variant);
  1001. init_waitqueue_head(&sfb->vsync_info.wait);
  1002. palette_size = variant->palette_sz * 4;
  1003. fbinfo = framebuffer_alloc(sizeof(struct s3c_fb_win) +
  1004. palette_size * sizeof(u32), sfb->dev);
  1005. if (!fbinfo) {
  1006. dev_err(sfb->dev, "failed to allocate framebuffer\n");
  1007. return -ENOENT;
  1008. }
  1009. windata = sfb->pdata->win[win_no];
  1010. initmode = &windata->win_mode;
  1011. WARN_ON(windata->max_bpp == 0);
  1012. WARN_ON(windata->win_mode.xres == 0);
  1013. WARN_ON(windata->win_mode.yres == 0);
  1014. win = fbinfo->par;
  1015. *res = win;
  1016. var = &fbinfo->var;
  1017. win->variant = *variant;
  1018. win->fbinfo = fbinfo;
  1019. win->parent = sfb;
  1020. win->windata = windata;
  1021. win->index = win_no;
  1022. win->palette_buffer = (u32 *)(win + 1);
  1023. ret = s3c_fb_alloc_memory(sfb, win);
  1024. if (ret) {
  1025. dev_err(sfb->dev, "failed to allocate display memory\n");
  1026. return ret;
  1027. }
  1028. /* setup the r/b/g positions for the window's palette */
  1029. if (win->variant.palette_16bpp) {
  1030. /* Set RGB 5:6:5 as default */
  1031. win->palette.r.offset = 11;
  1032. win->palette.r.length = 5;
  1033. win->palette.g.offset = 5;
  1034. win->palette.g.length = 6;
  1035. win->palette.b.offset = 0;
  1036. win->palette.b.length = 5;
  1037. } else {
  1038. /* Set 8bpp or 8bpp and 1bit alpha */
  1039. win->palette.r.offset = 16;
  1040. win->palette.r.length = 8;
  1041. win->palette.g.offset = 8;
  1042. win->palette.g.length = 8;
  1043. win->palette.b.offset = 0;
  1044. win->palette.b.length = 8;
  1045. }
  1046. /* setup the initial video mode from the window */
  1047. fb_videomode_to_var(&fbinfo->var, initmode);
  1048. fbinfo->fix.type = FB_TYPE_PACKED_PIXELS;
  1049. fbinfo->fix.accel = FB_ACCEL_NONE;
  1050. fbinfo->var.activate = FB_ACTIVATE_NOW;
  1051. fbinfo->var.vmode = FB_VMODE_NONINTERLACED;
  1052. fbinfo->var.bits_per_pixel = windata->default_bpp;
  1053. fbinfo->fbops = &s3c_fb_ops;
  1054. fbinfo->flags = FBINFO_FLAG_DEFAULT;
  1055. fbinfo->pseudo_palette = &win->pseudo_palette;
  1056. /* prepare to actually start the framebuffer */
  1057. ret = s3c_fb_check_var(&fbinfo->var, fbinfo);
  1058. if (ret < 0) {
  1059. dev_err(sfb->dev, "check_var failed on initial video params\n");
  1060. return ret;
  1061. }
  1062. /* create initial colour map */
  1063. ret = fb_alloc_cmap(&fbinfo->cmap, win->variant.palette_sz, 1);
  1064. if (ret == 0)
  1065. fb_set_cmap(&fbinfo->cmap, fbinfo);
  1066. else
  1067. dev_err(sfb->dev, "failed to allocate fb cmap\n");
  1068. s3c_fb_set_par(fbinfo);
  1069. dev_dbg(sfb->dev, "about to register framebuffer\n");
  1070. /* run the check_var and set_par on our configuration. */
  1071. ret = register_framebuffer(fbinfo);
  1072. if (ret < 0) {
  1073. dev_err(sfb->dev, "failed to register framebuffer\n");
  1074. return ret;
  1075. }
  1076. dev_info(sfb->dev, "window %d: fb %s\n", win_no, fbinfo->fix.id);
  1077. return 0;
  1078. }
  1079. /**
  1080. * s3c_fb_clear_win() - clear hardware window registers.
  1081. * @sfb: The base resources for the hardware.
  1082. * @win: The window to process.
  1083. *
  1084. * Reset the specific window registers to a known state.
  1085. */
  1086. static void s3c_fb_clear_win(struct s3c_fb *sfb, int win)
  1087. {
  1088. void __iomem *regs = sfb->regs;
  1089. u32 reg;
  1090. writel(0, regs + sfb->variant.wincon + (win * 4));
  1091. writel(0, regs + VIDOSD_A(win, sfb->variant));
  1092. writel(0, regs + VIDOSD_B(win, sfb->variant));
  1093. writel(0, regs + VIDOSD_C(win, sfb->variant));
  1094. reg = readl(regs + SHADOWCON);
  1095. writel(reg & ~SHADOWCON_WINx_PROTECT(win), regs + SHADOWCON);
  1096. }
  1097. static int __devinit s3c_fb_probe(struct platform_device *pdev)
  1098. {
  1099. const struct platform_device_id *platid;
  1100. struct s3c_fb_driverdata *fbdrv;
  1101. struct device *dev = &pdev->dev;
  1102. struct s3c_fb_platdata *pd;
  1103. struct s3c_fb *sfb;
  1104. struct resource *res;
  1105. int win;
  1106. int ret = 0;
  1107. platid = platform_get_device_id(pdev);
  1108. fbdrv = (struct s3c_fb_driverdata *)platid->driver_data;
  1109. if (fbdrv->variant.nr_windows > S3C_FB_MAX_WIN) {
  1110. dev_err(dev, "too many windows, cannot attach\n");
  1111. return -EINVAL;
  1112. }
  1113. pd = pdev->dev.platform_data;
  1114. if (!pd) {
  1115. dev_err(dev, "no platform data specified\n");
  1116. return -EINVAL;
  1117. }
  1118. sfb = kzalloc(sizeof(struct s3c_fb), GFP_KERNEL);
  1119. if (!sfb) {
  1120. dev_err(dev, "no memory for framebuffers\n");
  1121. return -ENOMEM;
  1122. }
  1123. dev_dbg(dev, "allocate new framebuffer %p\n", sfb);
  1124. sfb->dev = dev;
  1125. sfb->pdata = pd;
  1126. sfb->variant = fbdrv->variant;
  1127. spin_lock_init(&sfb->slock);
  1128. sfb->bus_clk = clk_get(dev, "lcd");
  1129. if (IS_ERR(sfb->bus_clk)) {
  1130. dev_err(dev, "failed to get bus clock\n");
  1131. ret = PTR_ERR(sfb->bus_clk);
  1132. goto err_sfb;
  1133. }
  1134. clk_enable(sfb->bus_clk);
  1135. pm_runtime_enable(sfb->dev);
  1136. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1137. if (!res) {
  1138. dev_err(dev, "failed to find registers\n");
  1139. ret = -ENOENT;
  1140. goto err_clk;
  1141. }
  1142. sfb->regs_res = request_mem_region(res->start, resource_size(res),
  1143. dev_name(dev));
  1144. if (!sfb->regs_res) {
  1145. dev_err(dev, "failed to claim register region\n");
  1146. ret = -ENOENT;
  1147. goto err_clk;
  1148. }
  1149. sfb->regs = ioremap(res->start, resource_size(res));
  1150. if (!sfb->regs) {
  1151. dev_err(dev, "failed to map registers\n");
  1152. ret = -ENXIO;
  1153. goto err_req_region;
  1154. }
  1155. res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  1156. if (!res) {
  1157. dev_err(dev, "failed to acquire irq resource\n");
  1158. ret = -ENOENT;
  1159. goto err_ioremap;
  1160. }
  1161. sfb->irq_no = res->start;
  1162. ret = request_irq(sfb->irq_no, s3c_fb_irq,
  1163. 0, "s3c_fb", sfb);
  1164. if (ret) {
  1165. dev_err(dev, "irq request failed\n");
  1166. goto err_ioremap;
  1167. }
  1168. dev_dbg(dev, "got resources (regs %p), probing windows\n", sfb->regs);
  1169. platform_set_drvdata(pdev, sfb);
  1170. pm_runtime_get_sync(sfb->dev);
  1171. /* setup gpio and output polarity controls */
  1172. pd->setup_gpio();
  1173. writel(pd->vidcon1, sfb->regs + VIDCON1);
  1174. /* zero all windows before we do anything */
  1175. for (win = 0; win < fbdrv->variant.nr_windows; win++)
  1176. s3c_fb_clear_win(sfb, win);
  1177. /* initialise colour key controls */
  1178. for (win = 0; win < (fbdrv->variant.nr_windows - 1); win++) {
  1179. void __iomem *regs = sfb->regs + sfb->variant.keycon;
  1180. regs += (win * 8);
  1181. writel(0xffffff, regs + WKEYCON0);
  1182. writel(0xffffff, regs + WKEYCON1);
  1183. }
  1184. /* we have the register setup, start allocating framebuffers */
  1185. for (win = 0; win < fbdrv->variant.nr_windows; win++) {
  1186. if (!pd->win[win])
  1187. continue;
  1188. if (!pd->win[win]->win_mode.pixclock)
  1189. s3c_fb_missing_pixclock(&pd->win[win]->win_mode);
  1190. ret = s3c_fb_probe_win(sfb, win, fbdrv->win[win],
  1191. &sfb->windows[win]);
  1192. if (ret < 0) {
  1193. dev_err(dev, "failed to create window %d\n", win);
  1194. for (; win >= 0; win--)
  1195. s3c_fb_release_win(sfb, sfb->windows[win]);
  1196. goto err_irq;
  1197. }
  1198. }
  1199. platform_set_drvdata(pdev, sfb);
  1200. pm_runtime_put_sync(sfb->dev);
  1201. return 0;
  1202. err_irq:
  1203. free_irq(sfb->irq_no, sfb);
  1204. err_ioremap:
  1205. iounmap(sfb->regs);
  1206. err_req_region:
  1207. release_mem_region(sfb->regs_res->start, resource_size(sfb->regs_res));
  1208. err_clk:
  1209. clk_disable(sfb->bus_clk);
  1210. clk_put(sfb->bus_clk);
  1211. err_sfb:
  1212. kfree(sfb);
  1213. return ret;
  1214. }
  1215. /**
  1216. * s3c_fb_remove() - Cleanup on module finalisation
  1217. * @pdev: The platform device we are bound to.
  1218. *
  1219. * Shutdown and then release all the resources that the driver allocated
  1220. * on initialisation.
  1221. */
  1222. static int __devexit s3c_fb_remove(struct platform_device *pdev)
  1223. {
  1224. struct s3c_fb *sfb = platform_get_drvdata(pdev);
  1225. int win;
  1226. pm_runtime_get_sync(sfb->dev);
  1227. for (win = 0; win < S3C_FB_MAX_WIN; win++)
  1228. if (sfb->windows[win])
  1229. s3c_fb_release_win(sfb, sfb->windows[win]);
  1230. free_irq(sfb->irq_no, sfb);
  1231. iounmap(sfb->regs);
  1232. clk_disable(sfb->bus_clk);
  1233. clk_put(sfb->bus_clk);
  1234. release_mem_region(sfb->regs_res->start, resource_size(sfb->regs_res));
  1235. pm_runtime_put_sync(sfb->dev);
  1236. pm_runtime_disable(sfb->dev);
  1237. kfree(sfb);
  1238. return 0;
  1239. }
  1240. #ifdef CONFIG_PM
  1241. static int s3c_fb_suspend(struct device *dev)
  1242. {
  1243. struct platform_device *pdev = to_platform_device(dev);
  1244. struct s3c_fb *sfb = platform_get_drvdata(pdev);
  1245. struct s3c_fb_win *win;
  1246. int win_no;
  1247. for (win_no = S3C_FB_MAX_WIN - 1; win_no >= 0; win_no--) {
  1248. win = sfb->windows[win_no];
  1249. if (!win)
  1250. continue;
  1251. /* use the blank function to push into power-down */
  1252. s3c_fb_blank(FB_BLANK_POWERDOWN, win->fbinfo);
  1253. }
  1254. clk_disable(sfb->bus_clk);
  1255. return 0;
  1256. }
  1257. static int s3c_fb_resume(struct device *dev)
  1258. {
  1259. struct platform_device *pdev = to_platform_device(dev);
  1260. struct s3c_fb *sfb = platform_get_drvdata(pdev);
  1261. struct s3c_fb_platdata *pd = sfb->pdata;
  1262. struct s3c_fb_win *win;
  1263. int win_no;
  1264. clk_enable(sfb->bus_clk);
  1265. /* setup gpio and output polarity controls */
  1266. pd->setup_gpio();
  1267. writel(pd->vidcon1, sfb->regs + VIDCON1);
  1268. /* zero all windows before we do anything */
  1269. for (win_no = 0; win_no < sfb->variant.nr_windows; win_no++)
  1270. s3c_fb_clear_win(sfb, win_no);
  1271. for (win_no = 0; win_no < sfb->variant.nr_windows - 1; win_no++) {
  1272. void __iomem *regs = sfb->regs + sfb->variant.keycon;
  1273. regs += (win_no * 8);
  1274. writel(0xffffff, regs + WKEYCON0);
  1275. writel(0xffffff, regs + WKEYCON1);
  1276. }
  1277. /* restore framebuffers */
  1278. for (win_no = 0; win_no < S3C_FB_MAX_WIN; win_no++) {
  1279. win = sfb->windows[win_no];
  1280. if (!win)
  1281. continue;
  1282. dev_dbg(&pdev->dev, "resuming window %d\n", win_no);
  1283. s3c_fb_set_par(win->fbinfo);
  1284. }
  1285. return 0;
  1286. }
  1287. static int s3c_fb_runtime_suspend(struct device *dev)
  1288. {
  1289. struct platform_device *pdev = to_platform_device(dev);
  1290. struct s3c_fb *sfb = platform_get_drvdata(pdev);
  1291. struct s3c_fb_win *win;
  1292. int win_no;
  1293. for (win_no = S3C_FB_MAX_WIN - 1; win_no >= 0; win_no--) {
  1294. win = sfb->windows[win_no];
  1295. if (!win)
  1296. continue;
  1297. /* use the blank function to push into power-down */
  1298. s3c_fb_blank(FB_BLANK_POWERDOWN, win->fbinfo);
  1299. }
  1300. clk_disable(sfb->bus_clk);
  1301. return 0;
  1302. }
  1303. static int s3c_fb_runtime_resume(struct device *dev)
  1304. {
  1305. struct platform_device *pdev = to_platform_device(dev);
  1306. struct s3c_fb *sfb = platform_get_drvdata(pdev);
  1307. struct s3c_fb_platdata *pd = sfb->pdata;
  1308. struct s3c_fb_win *win;
  1309. int win_no;
  1310. clk_enable(sfb->bus_clk);
  1311. /* setup gpio and output polarity controls */
  1312. pd->setup_gpio();
  1313. writel(pd->vidcon1, sfb->regs + VIDCON1);
  1314. /* zero all windows before we do anything */
  1315. for (win_no = 0; win_no < sfb->variant.nr_windows; win_no++)
  1316. s3c_fb_clear_win(sfb, win_no);
  1317. for (win_no = 0; win_no < sfb->variant.nr_windows - 1; win_no++) {
  1318. void __iomem *regs = sfb->regs + sfb->variant.keycon;
  1319. regs += (win_no * 8);
  1320. writel(0xffffff, regs + WKEYCON0);
  1321. writel(0xffffff, regs + WKEYCON1);
  1322. }
  1323. /* restore framebuffers */
  1324. for (win_no = 0; win_no < S3C_FB_MAX_WIN; win_no++) {
  1325. win = sfb->windows[win_no];
  1326. if (!win)
  1327. continue;
  1328. dev_dbg(&pdev->dev, "resuming window %d\n", win_no);
  1329. s3c_fb_set_par(win->fbinfo);
  1330. }
  1331. return 0;
  1332. }
  1333. #else
  1334. #define s3c_fb_suspend NULL
  1335. #define s3c_fb_resume NULL
  1336. #define s3c_fb_runtime_suspend NULL
  1337. #define s3c_fb_runtime_resume NULL
  1338. #endif
  1339. #define VALID_BPP124 (VALID_BPP(1) | VALID_BPP(2) | VALID_BPP(4))
  1340. #define VALID_BPP1248 (VALID_BPP124 | VALID_BPP(8))
  1341. static struct s3c_fb_win_variant s3c_fb_data_64xx_wins[] = {
  1342. [0] = {
  1343. .has_osd_c = 1,
  1344. .osd_size_off = 0x8,
  1345. .palette_sz = 256,
  1346. .valid_bpp = (VALID_BPP1248 | VALID_BPP(16) |
  1347. VALID_BPP(18) | VALID_BPP(24)),
  1348. },
  1349. [1] = {
  1350. .has_osd_c = 1,
  1351. .has_osd_d = 1,
  1352. .osd_size_off = 0xc,
  1353. .has_osd_alpha = 1,
  1354. .palette_sz = 256,
  1355. .valid_bpp = (VALID_BPP1248 | VALID_BPP(16) |
  1356. VALID_BPP(18) | VALID_BPP(19) |
  1357. VALID_BPP(24) | VALID_BPP(25) |
  1358. VALID_BPP(28)),
  1359. },
  1360. [2] = {
  1361. .has_osd_c = 1,
  1362. .has_osd_d = 1,
  1363. .osd_size_off = 0xc,
  1364. .has_osd_alpha = 1,
  1365. .palette_sz = 16,
  1366. .palette_16bpp = 1,
  1367. .valid_bpp = (VALID_BPP1248 | VALID_BPP(16) |
  1368. VALID_BPP(18) | VALID_BPP(19) |
  1369. VALID_BPP(24) | VALID_BPP(25) |
  1370. VALID_BPP(28)),
  1371. },
  1372. [3] = {
  1373. .has_osd_c = 1,
  1374. .has_osd_alpha = 1,
  1375. .palette_sz = 16,
  1376. .palette_16bpp = 1,
  1377. .valid_bpp = (VALID_BPP124 | VALID_BPP(16) |
  1378. VALID_BPP(18) | VALID_BPP(19) |
  1379. VALID_BPP(24) | VALID_BPP(25) |
  1380. VALID_BPP(28)),
  1381. },
  1382. [4] = {
  1383. .has_osd_c = 1,
  1384. .has_osd_alpha = 1,
  1385. .palette_sz = 4,
  1386. .palette_16bpp = 1,
  1387. .valid_bpp = (VALID_BPP(1) | VALID_BPP(2) |
  1388. VALID_BPP(16) | VALID_BPP(18) |
  1389. VALID_BPP(19) | VALID_BPP(24) |
  1390. VALID_BPP(25) | VALID_BPP(28)),
  1391. },
  1392. };
  1393. static struct s3c_fb_win_variant s3c_fb_data_s5p_wins[] = {
  1394. [0] = {
  1395. .has_osd_c = 1,
  1396. .osd_size_off = 0x8,
  1397. .palette_sz = 256,
  1398. .valid_bpp = (VALID_BPP1248 | VALID_BPP(13) |
  1399. VALID_BPP(15) | VALID_BPP(16) |
  1400. VALID_BPP(18) | VALID_BPP(19) |
  1401. VALID_BPP(24) | VALID_BPP(25) |
  1402. VALID_BPP(32)),
  1403. },
  1404. [1] = {
  1405. .has_osd_c = 1,
  1406. .has_osd_d = 1,
  1407. .osd_size_off = 0xc,
  1408. .has_osd_alpha = 1,
  1409. .palette_sz = 256,
  1410. .valid_bpp = (VALID_BPP1248 | VALID_BPP(13) |
  1411. VALID_BPP(15) | VALID_BPP(16) |
  1412. VALID_BPP(18) | VALID_BPP(19) |
  1413. VALID_BPP(24) | VALID_BPP(25) |
  1414. VALID_BPP(32)),
  1415. },
  1416. [2] = {
  1417. .has_osd_c = 1,
  1418. .has_osd_d = 1,
  1419. .osd_size_off = 0xc,
  1420. .has_osd_alpha = 1,
  1421. .palette_sz = 256,
  1422. .valid_bpp = (VALID_BPP1248 | VALID_BPP(13) |
  1423. VALID_BPP(15) | VALID_BPP(16) |
  1424. VALID_BPP(18) | VALID_BPP(19) |
  1425. VALID_BPP(24) | VALID_BPP(25) |
  1426. VALID_BPP(32)),
  1427. },
  1428. [3] = {
  1429. .has_osd_c = 1,
  1430. .has_osd_alpha = 1,
  1431. .palette_sz = 256,
  1432. .valid_bpp = (VALID_BPP1248 | VALID_BPP(13) |
  1433. VALID_BPP(15) | VALID_BPP(16) |
  1434. VALID_BPP(18) | VALID_BPP(19) |
  1435. VALID_BPP(24) | VALID_BPP(25) |
  1436. VALID_BPP(32)),
  1437. },
  1438. [4] = {
  1439. .has_osd_c = 1,
  1440. .has_osd_alpha = 1,
  1441. .palette_sz = 256,
  1442. .valid_bpp = (VALID_BPP1248 | VALID_BPP(13) |
  1443. VALID_BPP(15) | VALID_BPP(16) |
  1444. VALID_BPP(18) | VALID_BPP(19) |
  1445. VALID_BPP(24) | VALID_BPP(25) |
  1446. VALID_BPP(32)),
  1447. },
  1448. };
  1449. static struct s3c_fb_driverdata s3c_fb_data_64xx = {
  1450. .variant = {
  1451. .nr_windows = 5,
  1452. .vidtcon = VIDTCON0,
  1453. .wincon = WINCON(0),
  1454. .winmap = WINxMAP(0),
  1455. .keycon = WKEYCON,
  1456. .osd = VIDOSD_BASE,
  1457. .osd_stride = 16,
  1458. .buf_start = VIDW_BUF_START(0),
  1459. .buf_size = VIDW_BUF_SIZE(0),
  1460. .buf_end = VIDW_BUF_END(0),
  1461. .palette = {
  1462. [0] = 0x400,
  1463. [1] = 0x800,
  1464. [2] = 0x300,
  1465. [3] = 0x320,
  1466. [4] = 0x340,
  1467. },
  1468. .has_prtcon = 1,
  1469. },
  1470. .win[0] = &s3c_fb_data_64xx_wins[0],
  1471. .win[1] = &s3c_fb_data_64xx_wins[1],
  1472. .win[2] = &s3c_fb_data_64xx_wins[2],
  1473. .win[3] = &s3c_fb_data_64xx_wins[3],
  1474. .win[4] = &s3c_fb_data_64xx_wins[4],
  1475. };
  1476. static struct s3c_fb_driverdata s3c_fb_data_s5pc100 = {
  1477. .variant = {
  1478. .nr_windows = 5,
  1479. .vidtcon = VIDTCON0,
  1480. .wincon = WINCON(0),
  1481. .winmap = WINxMAP(0),
  1482. .keycon = WKEYCON,
  1483. .osd = VIDOSD_BASE,
  1484. .osd_stride = 16,
  1485. .buf_start = VIDW_BUF_START(0),
  1486. .buf_size = VIDW_BUF_SIZE(0),
  1487. .buf_end = VIDW_BUF_END(0),
  1488. .palette = {
  1489. [0] = 0x2400,
  1490. [1] = 0x2800,
  1491. [2] = 0x2c00,
  1492. [3] = 0x3000,
  1493. [4] = 0x3400,
  1494. },
  1495. .has_prtcon = 1,
  1496. },
  1497. .win[0] = &s3c_fb_data_s5p_wins[0],
  1498. .win[1] = &s3c_fb_data_s5p_wins[1],
  1499. .win[2] = &s3c_fb_data_s5p_wins[2],
  1500. .win[3] = &s3c_fb_data_s5p_wins[3],
  1501. .win[4] = &s3c_fb_data_s5p_wins[4],
  1502. };
  1503. static struct s3c_fb_driverdata s3c_fb_data_s5pv210 = {
  1504. .variant = {
  1505. .nr_windows = 5,
  1506. .vidtcon = VIDTCON0,
  1507. .wincon = WINCON(0),
  1508. .winmap = WINxMAP(0),
  1509. .keycon = WKEYCON,
  1510. .osd = VIDOSD_BASE,
  1511. .osd_stride = 16,
  1512. .buf_start = VIDW_BUF_START(0),
  1513. .buf_size = VIDW_BUF_SIZE(0),
  1514. .buf_end = VIDW_BUF_END(0),
  1515. .palette = {
  1516. [0] = 0x2400,
  1517. [1] = 0x2800,
  1518. [2] = 0x2c00,
  1519. [3] = 0x3000,
  1520. [4] = 0x3400,
  1521. },
  1522. .has_shadowcon = 1,
  1523. },
  1524. .win[0] = &s3c_fb_data_s5p_wins[0],
  1525. .win[1] = &s3c_fb_data_s5p_wins[1],
  1526. .win[2] = &s3c_fb_data_s5p_wins[2],
  1527. .win[3] = &s3c_fb_data_s5p_wins[3],
  1528. .win[4] = &s3c_fb_data_s5p_wins[4],
  1529. };
  1530. /* S3C2443/S3C2416 style hardware */
  1531. static struct s3c_fb_driverdata s3c_fb_data_s3c2443 = {
  1532. .variant = {
  1533. .nr_windows = 2,
  1534. .is_2443 = 1,
  1535. .vidtcon = 0x08,
  1536. .wincon = 0x14,
  1537. .winmap = 0xd0,
  1538. .keycon = 0xb0,
  1539. .osd = 0x28,
  1540. .osd_stride = 12,
  1541. .buf_start = 0x64,
  1542. .buf_size = 0x94,
  1543. .buf_end = 0x7c,
  1544. .palette = {
  1545. [0] = 0x400,
  1546. [1] = 0x800,
  1547. },
  1548. },
  1549. .win[0] = &(struct s3c_fb_win_variant) {
  1550. .palette_sz = 256,
  1551. .valid_bpp = VALID_BPP1248 | VALID_BPP(16) | VALID_BPP(24),
  1552. },
  1553. .win[1] = &(struct s3c_fb_win_variant) {
  1554. .has_osd_c = 1,
  1555. .has_osd_alpha = 1,
  1556. .palette_sz = 256,
  1557. .valid_bpp = (VALID_BPP1248 | VALID_BPP(16) |
  1558. VALID_BPP(18) | VALID_BPP(19) |
  1559. VALID_BPP(24) | VALID_BPP(25) |
  1560. VALID_BPP(28)),
  1561. },
  1562. };
  1563. static struct platform_device_id s3c_fb_driver_ids[] = {
  1564. {
  1565. .name = "s3c-fb",
  1566. .driver_data = (unsigned long)&s3c_fb_data_64xx,
  1567. }, {
  1568. .name = "s5pc100-fb",
  1569. .driver_data = (unsigned long)&s3c_fb_data_s5pc100,
  1570. }, {
  1571. .name = "s5pv210-fb",
  1572. .driver_data = (unsigned long)&s3c_fb_data_s5pv210,
  1573. }, {
  1574. .name = "s3c2443-fb",
  1575. .driver_data = (unsigned long)&s3c_fb_data_s3c2443,
  1576. },
  1577. {},
  1578. };
  1579. MODULE_DEVICE_TABLE(platform, s3c_fb_driver_ids);
  1580. static const struct dev_pm_ops s3cfb_pm_ops = {
  1581. .suspend = s3c_fb_suspend,
  1582. .resume = s3c_fb_resume,
  1583. .runtime_suspend = s3c_fb_runtime_suspend,
  1584. .runtime_resume = s3c_fb_runtime_resume,
  1585. };
  1586. static struct platform_driver s3c_fb_driver = {
  1587. .probe = s3c_fb_probe,
  1588. .remove = __devexit_p(s3c_fb_remove),
  1589. .id_table = s3c_fb_driver_ids,
  1590. .driver = {
  1591. .name = "s3c-fb",
  1592. .owner = THIS_MODULE,
  1593. .pm = &s3cfb_pm_ops,
  1594. },
  1595. };
  1596. static int __init s3c_fb_init(void)
  1597. {
  1598. return platform_driver_register(&s3c_fb_driver);
  1599. }
  1600. static void __exit s3c_fb_cleanup(void)
  1601. {
  1602. platform_driver_unregister(&s3c_fb_driver);
  1603. }
  1604. module_init(s3c_fb_init);
  1605. module_exit(s3c_fb_cleanup);
  1606. MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
  1607. MODULE_DESCRIPTION("Samsung S3C SoC Framebuffer driver");
  1608. MODULE_LICENSE("GPL");
  1609. MODULE_ALIAS("platform:s3c-fb");