s3c-fb.c 49 KB

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