s3c-fb.c 51 KB

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