s3c-fb.c 49 KB

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