s3c-fb.c 50 KB

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