s3c-fb.c 50 KB

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