s3c-fb.c 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062
  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. pr_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. dev_dbg(sfb->dev, "setting framebuffer parameters\n");
  441. pm_runtime_get_sync(sfb->dev);
  442. shadow_protect_win(win, 1);
  443. switch (var->bits_per_pixel) {
  444. case 32:
  445. case 24:
  446. case 16:
  447. case 12:
  448. info->fix.visual = FB_VISUAL_TRUECOLOR;
  449. break;
  450. case 8:
  451. if (win->variant.palette_sz >= 256)
  452. info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
  453. else
  454. info->fix.visual = FB_VISUAL_TRUECOLOR;
  455. break;
  456. case 1:
  457. info->fix.visual = FB_VISUAL_MONO01;
  458. break;
  459. default:
  460. info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
  461. break;
  462. }
  463. info->fix.line_length = (var->xres_virtual * var->bits_per_pixel) / 8;
  464. info->fix.xpanstep = info->var.xres_virtual > info->var.xres ? 1 : 0;
  465. info->fix.ypanstep = info->var.yres_virtual > info->var.yres ? 1 : 0;
  466. /* disable the window whilst we update it */
  467. writel(0, regs + WINCON(win_no));
  468. if (!sfb->output_on)
  469. s3c_fb_enable(sfb, 1);
  470. /* write the buffer address */
  471. /* start and end registers stride is 8 */
  472. buf = regs + win_no * 8;
  473. writel(info->fix.smem_start, buf + sfb->variant.buf_start);
  474. data = info->fix.smem_start + info->fix.line_length * var->yres;
  475. writel(data, buf + sfb->variant.buf_end);
  476. pagewidth = (var->xres * var->bits_per_pixel) >> 3;
  477. data = VIDW_BUF_SIZE_OFFSET(info->fix.line_length - pagewidth) |
  478. VIDW_BUF_SIZE_PAGEWIDTH(pagewidth) |
  479. VIDW_BUF_SIZE_OFFSET_E(info->fix.line_length - pagewidth) |
  480. VIDW_BUF_SIZE_PAGEWIDTH_E(pagewidth);
  481. writel(data, regs + sfb->variant.buf_size + (win_no * 4));
  482. /* write 'OSD' registers to control position of framebuffer */
  483. data = VIDOSDxA_TOPLEFT_X(0) | VIDOSDxA_TOPLEFT_Y(0) |
  484. VIDOSDxA_TOPLEFT_X_E(0) | VIDOSDxA_TOPLEFT_Y_E(0);
  485. writel(data, regs + VIDOSD_A(win_no, sfb->variant));
  486. data = VIDOSDxB_BOTRIGHT_X(s3c_fb_align_word(var->bits_per_pixel,
  487. var->xres - 1)) |
  488. VIDOSDxB_BOTRIGHT_Y(var->yres - 1) |
  489. VIDOSDxB_BOTRIGHT_X_E(s3c_fb_align_word(var->bits_per_pixel,
  490. var->xres - 1)) |
  491. VIDOSDxB_BOTRIGHT_Y_E(var->yres - 1);
  492. writel(data, regs + VIDOSD_B(win_no, sfb->variant));
  493. data = var->xres * var->yres;
  494. alpha = VIDISD14C_ALPHA1_R(0xf) |
  495. VIDISD14C_ALPHA1_G(0xf) |
  496. VIDISD14C_ALPHA1_B(0xf);
  497. vidosd_set_alpha(win, alpha);
  498. vidosd_set_size(win, data);
  499. /* Enable DMA channel for this window */
  500. if (sfb->variant.has_shadowcon) {
  501. data = readl(sfb->regs + SHADOWCON);
  502. data |= SHADOWCON_CHx_ENABLE(win_no);
  503. writel(data, sfb->regs + SHADOWCON);
  504. }
  505. data = WINCONx_ENWIN;
  506. sfb->enabled |= (1 << win->index);
  507. /* note, since we have to round up the bits-per-pixel, we end up
  508. * relying on the bitfield information for r/g/b/a to work out
  509. * exactly which mode of operation is intended. */
  510. switch (var->bits_per_pixel) {
  511. case 1:
  512. data |= WINCON0_BPPMODE_1BPP;
  513. data |= WINCONx_BITSWP;
  514. data |= WINCONx_BURSTLEN_4WORD;
  515. break;
  516. case 2:
  517. data |= WINCON0_BPPMODE_2BPP;
  518. data |= WINCONx_BITSWP;
  519. data |= WINCONx_BURSTLEN_8WORD;
  520. break;
  521. case 4:
  522. data |= WINCON0_BPPMODE_4BPP;
  523. data |= WINCONx_BITSWP;
  524. data |= WINCONx_BURSTLEN_8WORD;
  525. break;
  526. case 8:
  527. if (var->transp.length != 0)
  528. data |= WINCON1_BPPMODE_8BPP_1232;
  529. else
  530. data |= WINCON0_BPPMODE_8BPP_PALETTE;
  531. data |= WINCONx_BURSTLEN_8WORD;
  532. data |= WINCONx_BYTSWP;
  533. break;
  534. case 16:
  535. if (var->transp.length != 0)
  536. data |= WINCON1_BPPMODE_16BPP_A1555;
  537. else
  538. data |= WINCON0_BPPMODE_16BPP_565;
  539. data |= WINCONx_HAWSWP;
  540. data |= WINCONx_BURSTLEN_16WORD;
  541. break;
  542. case 24:
  543. case 32:
  544. if (var->red.length == 6) {
  545. if (var->transp.length != 0)
  546. data |= WINCON1_BPPMODE_19BPP_A1666;
  547. else
  548. data |= WINCON1_BPPMODE_18BPP_666;
  549. } else if (var->transp.length == 1)
  550. data |= WINCON1_BPPMODE_25BPP_A1888
  551. | WINCON1_BLD_PIX;
  552. else if ((var->transp.length == 4) ||
  553. (var->transp.length == 8))
  554. data |= WINCON1_BPPMODE_28BPP_A4888
  555. | WINCON1_BLD_PIX | WINCON1_ALPHA_SEL;
  556. else
  557. data |= WINCON0_BPPMODE_24BPP_888;
  558. data |= WINCONx_WSWP;
  559. data |= WINCONx_BURSTLEN_16WORD;
  560. break;
  561. }
  562. /* Enable the colour keying for the window below this one */
  563. if (win_no > 0) {
  564. u32 keycon0_data = 0, keycon1_data = 0;
  565. void __iomem *keycon = regs + sfb->variant.keycon;
  566. keycon0_data = ~(WxKEYCON0_KEYBL_EN |
  567. WxKEYCON0_KEYEN_F |
  568. WxKEYCON0_DIRCON) | WxKEYCON0_COMPKEY(0);
  569. keycon1_data = WxKEYCON1_COLVAL(0xffffff);
  570. keycon += (win_no - 1) * 8;
  571. writel(keycon0_data, keycon + WKEYCON0);
  572. writel(keycon1_data, keycon + WKEYCON1);
  573. }
  574. writel(data, regs + sfb->variant.wincon + (win_no * 4));
  575. writel(0x0, regs + sfb->variant.winmap + (win_no * 4));
  576. /* Set alpha value width */
  577. if (sfb->variant.has_blendcon) {
  578. data = readl(sfb->regs + BLENDCON);
  579. data &= ~BLENDCON_NEW_MASK;
  580. if (var->transp.length > 4)
  581. data |= BLENDCON_NEW_8BIT_ALPHA_VALUE;
  582. else
  583. data |= BLENDCON_NEW_4BIT_ALPHA_VALUE;
  584. writel(data, sfb->regs + BLENDCON);
  585. }
  586. shadow_protect_win(win, 0);
  587. pm_runtime_put_sync(sfb->dev);
  588. return 0;
  589. }
  590. /**
  591. * s3c_fb_update_palette() - set or schedule a palette update.
  592. * @sfb: The hardware information.
  593. * @win: The window being updated.
  594. * @reg: The palette index being changed.
  595. * @value: The computed palette value.
  596. *
  597. * Change the value of a palette register, either by directly writing to
  598. * the palette (this requires the palette RAM to be disconnected from the
  599. * hardware whilst this is in progress) or schedule the update for later.
  600. *
  601. * At the moment, since we have no VSYNC interrupt support, we simply set
  602. * the palette entry directly.
  603. */
  604. static void s3c_fb_update_palette(struct s3c_fb *sfb,
  605. struct s3c_fb_win *win,
  606. unsigned int reg,
  607. u32 value)
  608. {
  609. void __iomem *palreg;
  610. u32 palcon;
  611. palreg = sfb->regs + sfb->variant.palette[win->index];
  612. dev_dbg(sfb->dev, "%s: win %d, reg %d (%p): %08x\n",
  613. __func__, win->index, reg, palreg, value);
  614. win->palette_buffer[reg] = value;
  615. palcon = readl(sfb->regs + WPALCON);
  616. writel(palcon | WPALCON_PAL_UPDATE, sfb->regs + WPALCON);
  617. if (win->variant.palette_16bpp)
  618. writew(value, palreg + (reg * 2));
  619. else
  620. writel(value, palreg + (reg * 4));
  621. writel(palcon, sfb->regs + WPALCON);
  622. }
  623. static inline unsigned int chan_to_field(unsigned int chan,
  624. struct fb_bitfield *bf)
  625. {
  626. chan &= 0xffff;
  627. chan >>= 16 - bf->length;
  628. return chan << bf->offset;
  629. }
  630. /**
  631. * s3c_fb_setcolreg() - framebuffer layer request to change palette.
  632. * @regno: The palette index to change.
  633. * @red: The red field for the palette data.
  634. * @green: The green field for the palette data.
  635. * @blue: The blue field for the palette data.
  636. * @trans: The transparency (alpha) field for the palette data.
  637. * @info: The framebuffer being changed.
  638. */
  639. static int s3c_fb_setcolreg(unsigned regno,
  640. unsigned red, unsigned green, unsigned blue,
  641. unsigned transp, struct fb_info *info)
  642. {
  643. struct s3c_fb_win *win = info->par;
  644. struct s3c_fb *sfb = win->parent;
  645. unsigned int val;
  646. dev_dbg(sfb->dev, "%s: win %d: %d => rgb=%d/%d/%d\n",
  647. __func__, win->index, regno, red, green, blue);
  648. pm_runtime_get_sync(sfb->dev);
  649. switch (info->fix.visual) {
  650. case FB_VISUAL_TRUECOLOR:
  651. /* true-colour, use pseudo-palette */
  652. if (regno < 16) {
  653. u32 *pal = info->pseudo_palette;
  654. val = chan_to_field(red, &info->var.red);
  655. val |= chan_to_field(green, &info->var.green);
  656. val |= chan_to_field(blue, &info->var.blue);
  657. pal[regno] = val;
  658. }
  659. break;
  660. case FB_VISUAL_PSEUDOCOLOR:
  661. if (regno < win->variant.palette_sz) {
  662. val = chan_to_field(red, &win->palette.r);
  663. val |= chan_to_field(green, &win->palette.g);
  664. val |= chan_to_field(blue, &win->palette.b);
  665. s3c_fb_update_palette(sfb, win, regno, val);
  666. }
  667. break;
  668. default:
  669. pm_runtime_put_sync(sfb->dev);
  670. return 1; /* unknown type */
  671. }
  672. pm_runtime_put_sync(sfb->dev);
  673. return 0;
  674. }
  675. /**
  676. * s3c_fb_blank() - blank or unblank the given window
  677. * @blank_mode: The blank state from FB_BLANK_*
  678. * @info: The framebuffer to blank.
  679. *
  680. * Framebuffer layer request to change the power state.
  681. */
  682. static int s3c_fb_blank(int blank_mode, struct fb_info *info)
  683. {
  684. struct s3c_fb_win *win = info->par;
  685. struct s3c_fb *sfb = win->parent;
  686. unsigned int index = win->index;
  687. u32 wincon;
  688. u32 output_on = sfb->output_on;
  689. dev_dbg(sfb->dev, "blank mode %d\n", blank_mode);
  690. pm_runtime_get_sync(sfb->dev);
  691. wincon = readl(sfb->regs + sfb->variant.wincon + (index * 4));
  692. switch (blank_mode) {
  693. case FB_BLANK_POWERDOWN:
  694. wincon &= ~WINCONx_ENWIN;
  695. sfb->enabled &= ~(1 << index);
  696. /* fall through to FB_BLANK_NORMAL */
  697. case FB_BLANK_NORMAL:
  698. /* disable the DMA and display 0x0 (black) */
  699. shadow_protect_win(win, 1);
  700. writel(WINxMAP_MAP | WINxMAP_MAP_COLOUR(0x0),
  701. sfb->regs + sfb->variant.winmap + (index * 4));
  702. shadow_protect_win(win, 0);
  703. break;
  704. case FB_BLANK_UNBLANK:
  705. shadow_protect_win(win, 1);
  706. writel(0x0, sfb->regs + sfb->variant.winmap + (index * 4));
  707. shadow_protect_win(win, 0);
  708. wincon |= WINCONx_ENWIN;
  709. sfb->enabled |= (1 << index);
  710. break;
  711. case FB_BLANK_VSYNC_SUSPEND:
  712. case FB_BLANK_HSYNC_SUSPEND:
  713. default:
  714. pm_runtime_put_sync(sfb->dev);
  715. return 1;
  716. }
  717. shadow_protect_win(win, 1);
  718. writel(wincon, sfb->regs + sfb->variant.wincon + (index * 4));
  719. /* Check the enabled state to see if we need to be running the
  720. * main LCD interface, as if there are no active windows then
  721. * it is highly likely that we also do not need to output
  722. * anything.
  723. */
  724. s3c_fb_enable(sfb, sfb->enabled ? 1 : 0);
  725. shadow_protect_win(win, 0);
  726. pm_runtime_put_sync(sfb->dev);
  727. return output_on == sfb->output_on;
  728. }
  729. /**
  730. * s3c_fb_pan_display() - Pan the display.
  731. *
  732. * Note that the offsets can be written to the device at any time, as their
  733. * values are latched at each vsync automatically. This also means that only
  734. * the last call to this function will have any effect on next vsync, but
  735. * there is no need to sleep waiting for it to prevent tearing.
  736. *
  737. * @var: The screen information to verify.
  738. * @info: The framebuffer device.
  739. */
  740. static int s3c_fb_pan_display(struct fb_var_screeninfo *var,
  741. struct fb_info *info)
  742. {
  743. struct s3c_fb_win *win = info->par;
  744. struct s3c_fb *sfb = win->parent;
  745. void __iomem *buf = sfb->regs + win->index * 8;
  746. unsigned int start_boff, end_boff;
  747. pm_runtime_get_sync(sfb->dev);
  748. /* Offset in bytes to the start of the displayed area */
  749. start_boff = var->yoffset * info->fix.line_length;
  750. /* X offset depends on the current bpp */
  751. if (info->var.bits_per_pixel >= 8) {
  752. start_boff += var->xoffset * (info->var.bits_per_pixel >> 3);
  753. } else {
  754. switch (info->var.bits_per_pixel) {
  755. case 4:
  756. start_boff += var->xoffset >> 1;
  757. break;
  758. case 2:
  759. start_boff += var->xoffset >> 2;
  760. break;
  761. case 1:
  762. start_boff += var->xoffset >> 3;
  763. break;
  764. default:
  765. dev_err(sfb->dev, "invalid bpp\n");
  766. pm_runtime_put_sync(sfb->dev);
  767. return -EINVAL;
  768. }
  769. }
  770. /* Offset in bytes to the end of the displayed area */
  771. end_boff = start_boff + info->var.yres * info->fix.line_length;
  772. /* Temporarily turn off per-vsync update from shadow registers until
  773. * both start and end addresses are updated to prevent corruption */
  774. shadow_protect_win(win, 1);
  775. writel(info->fix.smem_start + start_boff, buf + sfb->variant.buf_start);
  776. writel(info->fix.smem_start + end_boff, buf + sfb->variant.buf_end);
  777. shadow_protect_win(win, 0);
  778. pm_runtime_put_sync(sfb->dev);
  779. return 0;
  780. }
  781. /**
  782. * s3c_fb_enable_irq() - enable framebuffer interrupts
  783. * @sfb: main hardware state
  784. */
  785. static void s3c_fb_enable_irq(struct s3c_fb *sfb)
  786. {
  787. void __iomem *regs = sfb->regs;
  788. u32 irq_ctrl_reg;
  789. if (!test_and_set_bit(S3C_FB_VSYNC_IRQ_EN, &sfb->irq_flags)) {
  790. /* IRQ disabled, enable it */
  791. irq_ctrl_reg = readl(regs + VIDINTCON0);
  792. irq_ctrl_reg |= VIDINTCON0_INT_ENABLE;
  793. irq_ctrl_reg |= VIDINTCON0_INT_FRAME;
  794. irq_ctrl_reg &= ~VIDINTCON0_FRAMESEL0_MASK;
  795. irq_ctrl_reg |= VIDINTCON0_FRAMESEL0_VSYNC;
  796. irq_ctrl_reg &= ~VIDINTCON0_FRAMESEL1_MASK;
  797. irq_ctrl_reg |= VIDINTCON0_FRAMESEL1_NONE;
  798. writel(irq_ctrl_reg, regs + VIDINTCON0);
  799. }
  800. }
  801. /**
  802. * s3c_fb_disable_irq() - disable framebuffer interrupts
  803. * @sfb: main hardware state
  804. */
  805. static void s3c_fb_disable_irq(struct s3c_fb *sfb)
  806. {
  807. void __iomem *regs = sfb->regs;
  808. u32 irq_ctrl_reg;
  809. if (test_and_clear_bit(S3C_FB_VSYNC_IRQ_EN, &sfb->irq_flags)) {
  810. /* IRQ enabled, disable it */
  811. irq_ctrl_reg = readl(regs + VIDINTCON0);
  812. irq_ctrl_reg &= ~VIDINTCON0_INT_FRAME;
  813. irq_ctrl_reg &= ~VIDINTCON0_INT_ENABLE;
  814. writel(irq_ctrl_reg, regs + VIDINTCON0);
  815. }
  816. }
  817. static irqreturn_t s3c_fb_irq(int irq, void *dev_id)
  818. {
  819. struct s3c_fb *sfb = dev_id;
  820. void __iomem *regs = sfb->regs;
  821. u32 irq_sts_reg;
  822. spin_lock(&sfb->slock);
  823. irq_sts_reg = readl(regs + VIDINTCON1);
  824. if (irq_sts_reg & VIDINTCON1_INT_FRAME) {
  825. /* VSYNC interrupt, accept it */
  826. writel(VIDINTCON1_INT_FRAME, regs + VIDINTCON1);
  827. sfb->vsync_info.count++;
  828. wake_up_interruptible(&sfb->vsync_info.wait);
  829. }
  830. /* We only support waiting for VSYNC for now, so it's safe
  831. * to always disable irqs here.
  832. */
  833. s3c_fb_disable_irq(sfb);
  834. spin_unlock(&sfb->slock);
  835. return IRQ_HANDLED;
  836. }
  837. /**
  838. * s3c_fb_wait_for_vsync() - sleep until next VSYNC interrupt or timeout
  839. * @sfb: main hardware state
  840. * @crtc: head index.
  841. */
  842. static int s3c_fb_wait_for_vsync(struct s3c_fb *sfb, u32 crtc)
  843. {
  844. unsigned long count;
  845. int ret;
  846. if (crtc != 0)
  847. return -ENODEV;
  848. pm_runtime_get_sync(sfb->dev);
  849. count = sfb->vsync_info.count;
  850. s3c_fb_enable_irq(sfb);
  851. ret = wait_event_interruptible_timeout(sfb->vsync_info.wait,
  852. count != sfb->vsync_info.count,
  853. msecs_to_jiffies(VSYNC_TIMEOUT_MSEC));
  854. pm_runtime_put_sync(sfb->dev);
  855. if (ret == 0)
  856. return -ETIMEDOUT;
  857. return 0;
  858. }
  859. static int s3c_fb_ioctl(struct fb_info *info, unsigned int cmd,
  860. unsigned long arg)
  861. {
  862. struct s3c_fb_win *win = info->par;
  863. struct s3c_fb *sfb = win->parent;
  864. int ret;
  865. u32 crtc;
  866. switch (cmd) {
  867. case FBIO_WAITFORVSYNC:
  868. if (get_user(crtc, (u32 __user *)arg)) {
  869. ret = -EFAULT;
  870. break;
  871. }
  872. ret = s3c_fb_wait_for_vsync(sfb, crtc);
  873. break;
  874. default:
  875. ret = -ENOTTY;
  876. }
  877. return ret;
  878. }
  879. static struct fb_ops s3c_fb_ops = {
  880. .owner = THIS_MODULE,
  881. .fb_check_var = s3c_fb_check_var,
  882. .fb_set_par = s3c_fb_set_par,
  883. .fb_blank = s3c_fb_blank,
  884. .fb_setcolreg = s3c_fb_setcolreg,
  885. .fb_fillrect = cfb_fillrect,
  886. .fb_copyarea = cfb_copyarea,
  887. .fb_imageblit = cfb_imageblit,
  888. .fb_pan_display = s3c_fb_pan_display,
  889. .fb_ioctl = s3c_fb_ioctl,
  890. };
  891. /**
  892. * s3c_fb_missing_pixclock() - calculates pixel clock
  893. * @mode: The video mode to change.
  894. *
  895. * Calculate the pixel clock when none has been given through platform data.
  896. */
  897. static void s3c_fb_missing_pixclock(struct fb_videomode *mode)
  898. {
  899. u64 pixclk = 1000000000000ULL;
  900. u32 div;
  901. div = mode->left_margin + mode->hsync_len + mode->right_margin +
  902. mode->xres;
  903. div *= mode->upper_margin + mode->vsync_len + mode->lower_margin +
  904. mode->yres;
  905. div *= mode->refresh ? : 60;
  906. do_div(pixclk, div);
  907. mode->pixclock = pixclk;
  908. }
  909. /**
  910. * s3c_fb_alloc_memory() - allocate display memory for framebuffer window
  911. * @sfb: The base resources for the hardware.
  912. * @win: The window to initialise memory for.
  913. *
  914. * Allocate memory for the given framebuffer.
  915. */
  916. static int __devinit s3c_fb_alloc_memory(struct s3c_fb *sfb,
  917. struct s3c_fb_win *win)
  918. {
  919. struct s3c_fb_pd_win *windata = win->windata;
  920. unsigned int real_size, virt_size, size;
  921. struct fb_info *fbi = win->fbinfo;
  922. dma_addr_t map_dma;
  923. dev_dbg(sfb->dev, "allocating memory for display\n");
  924. real_size = windata->xres * windata->yres;
  925. virt_size = windata->virtual_x * windata->virtual_y;
  926. dev_dbg(sfb->dev, "real_size=%u (%u.%u), virt_size=%u (%u.%u)\n",
  927. real_size, windata->xres, windata->yres,
  928. virt_size, windata->virtual_x, windata->virtual_y);
  929. size = (real_size > virt_size) ? real_size : virt_size;
  930. size *= (windata->max_bpp > 16) ? 32 : windata->max_bpp;
  931. size /= 8;
  932. fbi->fix.smem_len = size;
  933. size = PAGE_ALIGN(size);
  934. dev_dbg(sfb->dev, "want %u bytes for window\n", size);
  935. fbi->screen_base = dma_alloc_writecombine(sfb->dev, size,
  936. &map_dma, GFP_KERNEL);
  937. if (!fbi->screen_base)
  938. return -ENOMEM;
  939. dev_dbg(sfb->dev, "mapped %x to %p\n",
  940. (unsigned int)map_dma, fbi->screen_base);
  941. memset(fbi->screen_base, 0x0, size);
  942. fbi->fix.smem_start = map_dma;
  943. return 0;
  944. }
  945. /**
  946. * s3c_fb_free_memory() - free the display memory for the given window
  947. * @sfb: The base resources for the hardware.
  948. * @win: The window to free the display memory for.
  949. *
  950. * Free the display memory allocated by s3c_fb_alloc_memory().
  951. */
  952. static void s3c_fb_free_memory(struct s3c_fb *sfb, struct s3c_fb_win *win)
  953. {
  954. struct fb_info *fbi = win->fbinfo;
  955. if (fbi->screen_base)
  956. dma_free_writecombine(sfb->dev, PAGE_ALIGN(fbi->fix.smem_len),
  957. fbi->screen_base, fbi->fix.smem_start);
  958. }
  959. /**
  960. * s3c_fb_release_win() - release resources for a framebuffer window.
  961. * @win: The window to cleanup the resources for.
  962. *
  963. * Release the resources that where claimed for the hardware window,
  964. * such as the framebuffer instance and any memory claimed for it.
  965. */
  966. static void s3c_fb_release_win(struct s3c_fb *sfb, struct s3c_fb_win *win)
  967. {
  968. u32 data;
  969. if (win->fbinfo) {
  970. if (sfb->variant.has_shadowcon) {
  971. data = readl(sfb->regs + SHADOWCON);
  972. data &= ~SHADOWCON_CHx_ENABLE(win->index);
  973. data &= ~SHADOWCON_CHx_LOCAL_ENABLE(win->index);
  974. writel(data, sfb->regs + SHADOWCON);
  975. }
  976. unregister_framebuffer(win->fbinfo);
  977. if (win->fbinfo->cmap.len)
  978. fb_dealloc_cmap(&win->fbinfo->cmap);
  979. s3c_fb_free_memory(sfb, win);
  980. framebuffer_release(win->fbinfo);
  981. }
  982. }
  983. /**
  984. * s3c_fb_probe_win() - register an hardware window
  985. * @sfb: The base resources for the hardware
  986. * @variant: The variant information for this window.
  987. * @res: Pointer to where to place the resultant window.
  988. *
  989. * Allocate and do the basic initialisation for one of the hardware's graphics
  990. * windows.
  991. */
  992. static int __devinit s3c_fb_probe_win(struct s3c_fb *sfb, unsigned int win_no,
  993. struct s3c_fb_win_variant *variant,
  994. struct s3c_fb_win **res)
  995. {
  996. struct fb_var_screeninfo *var;
  997. struct fb_videomode initmode;
  998. struct s3c_fb_pd_win *windata;
  999. struct s3c_fb_win *win;
  1000. struct fb_info *fbinfo;
  1001. int palette_size;
  1002. int ret;
  1003. dev_dbg(sfb->dev, "probing window %d, variant %p\n", win_no, variant);
  1004. init_waitqueue_head(&sfb->vsync_info.wait);
  1005. palette_size = variant->palette_sz * 4;
  1006. fbinfo = framebuffer_alloc(sizeof(struct s3c_fb_win) +
  1007. palette_size * sizeof(u32), sfb->dev);
  1008. if (!fbinfo) {
  1009. dev_err(sfb->dev, "failed to allocate framebuffer\n");
  1010. return -ENOENT;
  1011. }
  1012. windata = sfb->pdata->win[win_no];
  1013. initmode = *sfb->pdata->vtiming;
  1014. WARN_ON(windata->max_bpp == 0);
  1015. WARN_ON(windata->xres == 0);
  1016. WARN_ON(windata->yres == 0);
  1017. win = fbinfo->par;
  1018. *res = win;
  1019. var = &fbinfo->var;
  1020. win->variant = *variant;
  1021. win->fbinfo = fbinfo;
  1022. win->parent = sfb;
  1023. win->windata = windata;
  1024. win->index = win_no;
  1025. win->palette_buffer = (u32 *)(win + 1);
  1026. ret = s3c_fb_alloc_memory(sfb, win);
  1027. if (ret) {
  1028. dev_err(sfb->dev, "failed to allocate display memory\n");
  1029. return ret;
  1030. }
  1031. /* setup the r/b/g positions for the window's palette */
  1032. if (win->variant.palette_16bpp) {
  1033. /* Set RGB 5:6:5 as default */
  1034. win->palette.r.offset = 11;
  1035. win->palette.r.length = 5;
  1036. win->palette.g.offset = 5;
  1037. win->palette.g.length = 6;
  1038. win->palette.b.offset = 0;
  1039. win->palette.b.length = 5;
  1040. } else {
  1041. /* Set 8bpp or 8bpp and 1bit alpha */
  1042. win->palette.r.offset = 16;
  1043. win->palette.r.length = 8;
  1044. win->palette.g.offset = 8;
  1045. win->palette.g.length = 8;
  1046. win->palette.b.offset = 0;
  1047. win->palette.b.length = 8;
  1048. }
  1049. /* setup the initial video mode from the window */
  1050. initmode.xres = windata->xres;
  1051. initmode.yres = windata->yres;
  1052. fb_videomode_to_var(&fbinfo->var, &initmode);
  1053. fbinfo->fix.type = FB_TYPE_PACKED_PIXELS;
  1054. fbinfo->fix.accel = FB_ACCEL_NONE;
  1055. fbinfo->var.activate = FB_ACTIVATE_NOW;
  1056. fbinfo->var.vmode = FB_VMODE_NONINTERLACED;
  1057. fbinfo->var.bits_per_pixel = windata->default_bpp;
  1058. fbinfo->fbops = &s3c_fb_ops;
  1059. fbinfo->flags = FBINFO_FLAG_DEFAULT;
  1060. fbinfo->pseudo_palette = &win->pseudo_palette;
  1061. /* prepare to actually start the framebuffer */
  1062. ret = s3c_fb_check_var(&fbinfo->var, fbinfo);
  1063. if (ret < 0) {
  1064. dev_err(sfb->dev, "check_var failed on initial video params\n");
  1065. return ret;
  1066. }
  1067. /* create initial colour map */
  1068. ret = fb_alloc_cmap(&fbinfo->cmap, win->variant.palette_sz, 1);
  1069. if (ret == 0)
  1070. fb_set_cmap(&fbinfo->cmap, fbinfo);
  1071. else
  1072. dev_err(sfb->dev, "failed to allocate fb cmap\n");
  1073. s3c_fb_set_par(fbinfo);
  1074. dev_dbg(sfb->dev, "about to register framebuffer\n");
  1075. /* run the check_var and set_par on our configuration. */
  1076. ret = register_framebuffer(fbinfo);
  1077. if (ret < 0) {
  1078. dev_err(sfb->dev, "failed to register framebuffer\n");
  1079. return ret;
  1080. }
  1081. dev_info(sfb->dev, "window %d: fb %s\n", win_no, fbinfo->fix.id);
  1082. return 0;
  1083. }
  1084. /**
  1085. * s3c_fb_set_rgb_timing() - set video timing for rgb interface.
  1086. * @sfb: The base resources for the hardware.
  1087. *
  1088. * Set horizontal and vertical lcd rgb interface timing.
  1089. */
  1090. static void s3c_fb_set_rgb_timing(struct s3c_fb *sfb)
  1091. {
  1092. struct fb_videomode *vmode = sfb->pdata->vtiming;
  1093. void __iomem *regs = sfb->regs;
  1094. int clkdiv;
  1095. u32 data;
  1096. if (!vmode->pixclock)
  1097. s3c_fb_missing_pixclock(vmode);
  1098. clkdiv = s3c_fb_calc_pixclk(sfb, vmode->pixclock);
  1099. data = sfb->pdata->vidcon0;
  1100. data &= ~(VIDCON0_CLKVAL_F_MASK | VIDCON0_CLKDIR);
  1101. if (clkdiv > 1)
  1102. data |= VIDCON0_CLKVAL_F(clkdiv-1) | VIDCON0_CLKDIR;
  1103. else
  1104. data &= ~VIDCON0_CLKDIR; /* 1:1 clock */
  1105. if (sfb->variant.is_2443)
  1106. data |= (1 << 5);
  1107. writel(data, regs + VIDCON0);
  1108. data = VIDTCON0_VBPD(vmode->upper_margin - 1) |
  1109. VIDTCON0_VFPD(vmode->lower_margin - 1) |
  1110. VIDTCON0_VSPW(vmode->vsync_len - 1);
  1111. writel(data, regs + sfb->variant.vidtcon);
  1112. data = VIDTCON1_HBPD(vmode->left_margin - 1) |
  1113. VIDTCON1_HFPD(vmode->right_margin - 1) |
  1114. VIDTCON1_HSPW(vmode->hsync_len - 1);
  1115. writel(data, regs + sfb->variant.vidtcon + 4);
  1116. data = VIDTCON2_LINEVAL(vmode->yres - 1) |
  1117. VIDTCON2_HOZVAL(vmode->xres - 1) |
  1118. VIDTCON2_LINEVAL_E(vmode->yres - 1) |
  1119. VIDTCON2_HOZVAL_E(vmode->xres - 1);
  1120. writel(data, regs + sfb->variant.vidtcon + 8);
  1121. }
  1122. /**
  1123. * s3c_fb_clear_win() - clear hardware window registers.
  1124. * @sfb: The base resources for the hardware.
  1125. * @win: The window to process.
  1126. *
  1127. * Reset the specific window registers to a known state.
  1128. */
  1129. static void s3c_fb_clear_win(struct s3c_fb *sfb, int win)
  1130. {
  1131. void __iomem *regs = sfb->regs;
  1132. u32 reg;
  1133. writel(0, regs + sfb->variant.wincon + (win * 4));
  1134. writel(0, regs + VIDOSD_A(win, sfb->variant));
  1135. writel(0, regs + VIDOSD_B(win, sfb->variant));
  1136. writel(0, regs + VIDOSD_C(win, sfb->variant));
  1137. reg = readl(regs + SHADOWCON);
  1138. writel(reg & ~SHADOWCON_WINx_PROTECT(win), regs + SHADOWCON);
  1139. }
  1140. static int __devinit s3c_fb_probe(struct platform_device *pdev)
  1141. {
  1142. const struct platform_device_id *platid;
  1143. struct s3c_fb_driverdata *fbdrv;
  1144. struct device *dev = &pdev->dev;
  1145. struct s3c_fb_platdata *pd;
  1146. struct s3c_fb *sfb;
  1147. struct resource *res;
  1148. int win;
  1149. int ret = 0;
  1150. u32 reg;
  1151. platid = platform_get_device_id(pdev);
  1152. fbdrv = (struct s3c_fb_driverdata *)platid->driver_data;
  1153. if (fbdrv->variant.nr_windows > S3C_FB_MAX_WIN) {
  1154. dev_err(dev, "too many windows, cannot attach\n");
  1155. return -EINVAL;
  1156. }
  1157. pd = pdev->dev.platform_data;
  1158. if (!pd) {
  1159. dev_err(dev, "no platform data specified\n");
  1160. return -EINVAL;
  1161. }
  1162. sfb = devm_kzalloc(dev, sizeof(struct s3c_fb), GFP_KERNEL);
  1163. if (!sfb) {
  1164. dev_err(dev, "no memory for framebuffers\n");
  1165. return -ENOMEM;
  1166. }
  1167. dev_dbg(dev, "allocate new framebuffer %p\n", sfb);
  1168. sfb->dev = dev;
  1169. sfb->pdata = pd;
  1170. sfb->variant = fbdrv->variant;
  1171. spin_lock_init(&sfb->slock);
  1172. sfb->bus_clk = clk_get(dev, "lcd");
  1173. if (IS_ERR(sfb->bus_clk)) {
  1174. dev_err(dev, "failed to get bus clock\n");
  1175. ret = PTR_ERR(sfb->bus_clk);
  1176. goto err_sfb;
  1177. }
  1178. clk_enable(sfb->bus_clk);
  1179. if (!sfb->variant.has_clksel) {
  1180. sfb->lcd_clk = clk_get(dev, "sclk_fimd");
  1181. if (IS_ERR(sfb->lcd_clk)) {
  1182. dev_err(dev, "failed to get lcd clock\n");
  1183. ret = PTR_ERR(sfb->lcd_clk);
  1184. goto err_bus_clk;
  1185. }
  1186. clk_enable(sfb->lcd_clk);
  1187. }
  1188. pm_runtime_enable(sfb->dev);
  1189. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1190. if (!res) {
  1191. dev_err(dev, "failed to find registers\n");
  1192. ret = -ENOENT;
  1193. goto err_lcd_clk;
  1194. }
  1195. sfb->regs = devm_request_and_ioremap(dev, res);
  1196. if (!sfb->regs) {
  1197. dev_err(dev, "failed to map registers\n");
  1198. ret = -ENXIO;
  1199. goto err_lcd_clk;
  1200. }
  1201. res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  1202. if (!res) {
  1203. dev_err(dev, "failed to acquire irq resource\n");
  1204. ret = -ENOENT;
  1205. goto err_lcd_clk;
  1206. }
  1207. sfb->irq_no = res->start;
  1208. ret = devm_request_irq(dev, sfb->irq_no, s3c_fb_irq,
  1209. 0, "s3c_fb", sfb);
  1210. if (ret) {
  1211. dev_err(dev, "irq request failed\n");
  1212. goto err_lcd_clk;
  1213. }
  1214. dev_dbg(dev, "got resources (regs %p), probing windows\n", sfb->regs);
  1215. platform_set_drvdata(pdev, sfb);
  1216. pm_runtime_get_sync(sfb->dev);
  1217. /* setup gpio and output polarity controls */
  1218. pd->setup_gpio();
  1219. writel(pd->vidcon1, sfb->regs + VIDCON1);
  1220. /* set video clock running at under-run */
  1221. if (sfb->variant.has_fixvclk) {
  1222. reg = readl(sfb->regs + VIDCON1);
  1223. reg &= ~VIDCON1_VCLK_MASK;
  1224. reg |= VIDCON1_VCLK_RUN;
  1225. writel(reg, sfb->regs + VIDCON1);
  1226. }
  1227. /* zero all windows before we do anything */
  1228. for (win = 0; win < fbdrv->variant.nr_windows; win++)
  1229. s3c_fb_clear_win(sfb, win);
  1230. /* initialise colour key controls */
  1231. for (win = 0; win < (fbdrv->variant.nr_windows - 1); win++) {
  1232. void __iomem *regs = sfb->regs + sfb->variant.keycon;
  1233. regs += (win * 8);
  1234. writel(0xffffff, regs + WKEYCON0);
  1235. writel(0xffffff, regs + WKEYCON1);
  1236. }
  1237. s3c_fb_set_rgb_timing(sfb);
  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. ret = s3c_fb_probe_win(sfb, win, fbdrv->win[win],
  1243. &sfb->windows[win]);
  1244. if (ret < 0) {
  1245. dev_err(dev, "failed to create window %d\n", win);
  1246. for (; win >= 0; win--)
  1247. s3c_fb_release_win(sfb, sfb->windows[win]);
  1248. goto err_pm_runtime;
  1249. }
  1250. }
  1251. platform_set_drvdata(pdev, sfb);
  1252. pm_runtime_put_sync(sfb->dev);
  1253. return 0;
  1254. err_pm_runtime:
  1255. pm_runtime_put_sync(sfb->dev);
  1256. err_lcd_clk:
  1257. pm_runtime_disable(sfb->dev);
  1258. if (!sfb->variant.has_clksel) {
  1259. clk_disable(sfb->lcd_clk);
  1260. clk_put(sfb->lcd_clk);
  1261. }
  1262. err_bus_clk:
  1263. clk_disable(sfb->bus_clk);
  1264. clk_put(sfb->bus_clk);
  1265. err_sfb:
  1266. return ret;
  1267. }
  1268. /**
  1269. * s3c_fb_remove() - Cleanup on module finalisation
  1270. * @pdev: The platform device we are bound to.
  1271. *
  1272. * Shutdown and then release all the resources that the driver allocated
  1273. * on initialisation.
  1274. */
  1275. static int __devexit s3c_fb_remove(struct platform_device *pdev)
  1276. {
  1277. struct s3c_fb *sfb = platform_get_drvdata(pdev);
  1278. int win;
  1279. pm_runtime_get_sync(sfb->dev);
  1280. for (win = 0; win < S3C_FB_MAX_WIN; win++)
  1281. if (sfb->windows[win])
  1282. s3c_fb_release_win(sfb, sfb->windows[win]);
  1283. if (!sfb->variant.has_clksel) {
  1284. clk_disable(sfb->lcd_clk);
  1285. clk_put(sfb->lcd_clk);
  1286. }
  1287. clk_disable(sfb->bus_clk);
  1288. clk_put(sfb->bus_clk);
  1289. pm_runtime_put_sync(sfb->dev);
  1290. pm_runtime_disable(sfb->dev);
  1291. return 0;
  1292. }
  1293. #ifdef CONFIG_PM_SLEEP
  1294. static int s3c_fb_suspend(struct device *dev)
  1295. {
  1296. struct platform_device *pdev = to_platform_device(dev);
  1297. struct s3c_fb *sfb = platform_get_drvdata(pdev);
  1298. struct s3c_fb_win *win;
  1299. int win_no;
  1300. pm_runtime_get_sync(sfb->dev);
  1301. for (win_no = S3C_FB_MAX_WIN - 1; win_no >= 0; win_no--) {
  1302. win = sfb->windows[win_no];
  1303. if (!win)
  1304. continue;
  1305. /* use the blank function to push into power-down */
  1306. s3c_fb_blank(FB_BLANK_POWERDOWN, win->fbinfo);
  1307. }
  1308. if (!sfb->variant.has_clksel)
  1309. clk_disable(sfb->lcd_clk);
  1310. clk_disable(sfb->bus_clk);
  1311. pm_runtime_put_sync(sfb->dev);
  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. pm_runtime_get_sync(sfb->dev);
  1323. clk_enable(sfb->bus_clk);
  1324. if (!sfb->variant.has_clksel)
  1325. clk_enable(sfb->lcd_clk);
  1326. /* setup gpio and output polarity controls */
  1327. pd->setup_gpio();
  1328. writel(pd->vidcon1, sfb->regs + VIDCON1);
  1329. /* set video clock running at under-run */
  1330. if (sfb->variant.has_fixvclk) {
  1331. reg = readl(sfb->regs + VIDCON1);
  1332. reg &= ~VIDCON1_VCLK_MASK;
  1333. reg |= VIDCON1_VCLK_RUN;
  1334. writel(reg, sfb->regs + VIDCON1);
  1335. }
  1336. /* zero all windows before we do anything */
  1337. for (win_no = 0; win_no < sfb->variant.nr_windows; win_no++)
  1338. s3c_fb_clear_win(sfb, win_no);
  1339. for (win_no = 0; win_no < sfb->variant.nr_windows - 1; win_no++) {
  1340. void __iomem *regs = sfb->regs + sfb->variant.keycon;
  1341. win = sfb->windows[win_no];
  1342. if (!win)
  1343. continue;
  1344. shadow_protect_win(win, 1);
  1345. regs += (win_no * 8);
  1346. writel(0xffffff, regs + WKEYCON0);
  1347. writel(0xffffff, regs + WKEYCON1);
  1348. shadow_protect_win(win, 0);
  1349. }
  1350. s3c_fb_set_rgb_timing(sfb);
  1351. /* restore framebuffers */
  1352. for (win_no = 0; win_no < S3C_FB_MAX_WIN; win_no++) {
  1353. win = sfb->windows[win_no];
  1354. if (!win)
  1355. continue;
  1356. dev_dbg(&pdev->dev, "resuming window %d\n", win_no);
  1357. s3c_fb_set_par(win->fbinfo);
  1358. }
  1359. pm_runtime_put_sync(sfb->dev);
  1360. return 0;
  1361. }
  1362. #endif
  1363. #ifdef CONFIG_PM_RUNTIME
  1364. static int s3c_fb_runtime_suspend(struct device *dev)
  1365. {
  1366. struct platform_device *pdev = to_platform_device(dev);
  1367. struct s3c_fb *sfb = platform_get_drvdata(pdev);
  1368. if (!sfb->variant.has_clksel)
  1369. clk_disable(sfb->lcd_clk);
  1370. clk_disable(sfb->bus_clk);
  1371. return 0;
  1372. }
  1373. static int s3c_fb_runtime_resume(struct device *dev)
  1374. {
  1375. struct platform_device *pdev = to_platform_device(dev);
  1376. struct s3c_fb *sfb = platform_get_drvdata(pdev);
  1377. struct s3c_fb_platdata *pd = sfb->pdata;
  1378. clk_enable(sfb->bus_clk);
  1379. if (!sfb->variant.has_clksel)
  1380. clk_enable(sfb->lcd_clk);
  1381. /* setup gpio and output polarity controls */
  1382. pd->setup_gpio();
  1383. writel(pd->vidcon1, sfb->regs + VIDCON1);
  1384. return 0;
  1385. }
  1386. #endif
  1387. #define VALID_BPP124 (VALID_BPP(1) | VALID_BPP(2) | VALID_BPP(4))
  1388. #define VALID_BPP1248 (VALID_BPP124 | VALID_BPP(8))
  1389. static struct s3c_fb_win_variant s3c_fb_data_64xx_wins[] = {
  1390. [0] = {
  1391. .has_osd_c = 1,
  1392. .osd_size_off = 0x8,
  1393. .palette_sz = 256,
  1394. .valid_bpp = (VALID_BPP1248 | VALID_BPP(16) |
  1395. VALID_BPP(18) | VALID_BPP(24)),
  1396. },
  1397. [1] = {
  1398. .has_osd_c = 1,
  1399. .has_osd_d = 1,
  1400. .osd_size_off = 0xc,
  1401. .has_osd_alpha = 1,
  1402. .palette_sz = 256,
  1403. .valid_bpp = (VALID_BPP1248 | VALID_BPP(16) |
  1404. VALID_BPP(18) | VALID_BPP(19) |
  1405. VALID_BPP(24) | VALID_BPP(25) |
  1406. VALID_BPP(28)),
  1407. },
  1408. [2] = {
  1409. .has_osd_c = 1,
  1410. .has_osd_d = 1,
  1411. .osd_size_off = 0xc,
  1412. .has_osd_alpha = 1,
  1413. .palette_sz = 16,
  1414. .palette_16bpp = 1,
  1415. .valid_bpp = (VALID_BPP1248 | VALID_BPP(16) |
  1416. VALID_BPP(18) | VALID_BPP(19) |
  1417. VALID_BPP(24) | VALID_BPP(25) |
  1418. VALID_BPP(28)),
  1419. },
  1420. [3] = {
  1421. .has_osd_c = 1,
  1422. .has_osd_alpha = 1,
  1423. .palette_sz = 16,
  1424. .palette_16bpp = 1,
  1425. .valid_bpp = (VALID_BPP124 | VALID_BPP(16) |
  1426. VALID_BPP(18) | VALID_BPP(19) |
  1427. VALID_BPP(24) | VALID_BPP(25) |
  1428. VALID_BPP(28)),
  1429. },
  1430. [4] = {
  1431. .has_osd_c = 1,
  1432. .has_osd_alpha = 1,
  1433. .palette_sz = 4,
  1434. .palette_16bpp = 1,
  1435. .valid_bpp = (VALID_BPP(1) | VALID_BPP(2) |
  1436. VALID_BPP(16) | VALID_BPP(18) |
  1437. VALID_BPP(19) | VALID_BPP(24) |
  1438. VALID_BPP(25) | VALID_BPP(28)),
  1439. },
  1440. };
  1441. static struct s3c_fb_win_variant s3c_fb_data_s5p_wins[] = {
  1442. [0] = {
  1443. .has_osd_c = 1,
  1444. .osd_size_off = 0x8,
  1445. .palette_sz = 256,
  1446. .valid_bpp = (VALID_BPP1248 | VALID_BPP(13) |
  1447. VALID_BPP(15) | VALID_BPP(16) |
  1448. VALID_BPP(18) | VALID_BPP(19) |
  1449. VALID_BPP(24) | VALID_BPP(25) |
  1450. VALID_BPP(32)),
  1451. },
  1452. [1] = {
  1453. .has_osd_c = 1,
  1454. .has_osd_d = 1,
  1455. .osd_size_off = 0xc,
  1456. .has_osd_alpha = 1,
  1457. .palette_sz = 256,
  1458. .valid_bpp = (VALID_BPP1248 | VALID_BPP(13) |
  1459. VALID_BPP(15) | VALID_BPP(16) |
  1460. VALID_BPP(18) | VALID_BPP(19) |
  1461. VALID_BPP(24) | VALID_BPP(25) |
  1462. VALID_BPP(32)),
  1463. },
  1464. [2] = {
  1465. .has_osd_c = 1,
  1466. .has_osd_d = 1,
  1467. .osd_size_off = 0xc,
  1468. .has_osd_alpha = 1,
  1469. .palette_sz = 256,
  1470. .valid_bpp = (VALID_BPP1248 | VALID_BPP(13) |
  1471. VALID_BPP(15) | VALID_BPP(16) |
  1472. VALID_BPP(18) | VALID_BPP(19) |
  1473. VALID_BPP(24) | VALID_BPP(25) |
  1474. VALID_BPP(32)),
  1475. },
  1476. [3] = {
  1477. .has_osd_c = 1,
  1478. .has_osd_alpha = 1,
  1479. .palette_sz = 256,
  1480. .valid_bpp = (VALID_BPP1248 | VALID_BPP(13) |
  1481. VALID_BPP(15) | VALID_BPP(16) |
  1482. VALID_BPP(18) | VALID_BPP(19) |
  1483. VALID_BPP(24) | VALID_BPP(25) |
  1484. VALID_BPP(32)),
  1485. },
  1486. [4] = {
  1487. .has_osd_c = 1,
  1488. .has_osd_alpha = 1,
  1489. .palette_sz = 256,
  1490. .valid_bpp = (VALID_BPP1248 | VALID_BPP(13) |
  1491. VALID_BPP(15) | VALID_BPP(16) |
  1492. VALID_BPP(18) | VALID_BPP(19) |
  1493. VALID_BPP(24) | VALID_BPP(25) |
  1494. VALID_BPP(32)),
  1495. },
  1496. };
  1497. static struct s3c_fb_driverdata s3c_fb_data_64xx = {
  1498. .variant = {
  1499. .nr_windows = 5,
  1500. .vidtcon = VIDTCON0,
  1501. .wincon = WINCON(0),
  1502. .winmap = WINxMAP(0),
  1503. .keycon = WKEYCON,
  1504. .osd = VIDOSD_BASE,
  1505. .osd_stride = 16,
  1506. .buf_start = VIDW_BUF_START(0),
  1507. .buf_size = VIDW_BUF_SIZE(0),
  1508. .buf_end = VIDW_BUF_END(0),
  1509. .palette = {
  1510. [0] = 0x400,
  1511. [1] = 0x800,
  1512. [2] = 0x300,
  1513. [3] = 0x320,
  1514. [4] = 0x340,
  1515. },
  1516. .has_prtcon = 1,
  1517. .has_clksel = 1,
  1518. },
  1519. .win[0] = &s3c_fb_data_64xx_wins[0],
  1520. .win[1] = &s3c_fb_data_64xx_wins[1],
  1521. .win[2] = &s3c_fb_data_64xx_wins[2],
  1522. .win[3] = &s3c_fb_data_64xx_wins[3],
  1523. .win[4] = &s3c_fb_data_64xx_wins[4],
  1524. };
  1525. static struct s3c_fb_driverdata s3c_fb_data_s5pc100 = {
  1526. .variant = {
  1527. .nr_windows = 5,
  1528. .vidtcon = VIDTCON0,
  1529. .wincon = WINCON(0),
  1530. .winmap = WINxMAP(0),
  1531. .keycon = WKEYCON,
  1532. .osd = VIDOSD_BASE,
  1533. .osd_stride = 16,
  1534. .buf_start = VIDW_BUF_START(0),
  1535. .buf_size = VIDW_BUF_SIZE(0),
  1536. .buf_end = VIDW_BUF_END(0),
  1537. .palette = {
  1538. [0] = 0x2400,
  1539. [1] = 0x2800,
  1540. [2] = 0x2c00,
  1541. [3] = 0x3000,
  1542. [4] = 0x3400,
  1543. },
  1544. .has_prtcon = 1,
  1545. .has_blendcon = 1,
  1546. .has_clksel = 1,
  1547. },
  1548. .win[0] = &s3c_fb_data_s5p_wins[0],
  1549. .win[1] = &s3c_fb_data_s5p_wins[1],
  1550. .win[2] = &s3c_fb_data_s5p_wins[2],
  1551. .win[3] = &s3c_fb_data_s5p_wins[3],
  1552. .win[4] = &s3c_fb_data_s5p_wins[4],
  1553. };
  1554. static struct s3c_fb_driverdata s3c_fb_data_s5pv210 = {
  1555. .variant = {
  1556. .nr_windows = 5,
  1557. .vidtcon = VIDTCON0,
  1558. .wincon = WINCON(0),
  1559. .winmap = WINxMAP(0),
  1560. .keycon = WKEYCON,
  1561. .osd = VIDOSD_BASE,
  1562. .osd_stride = 16,
  1563. .buf_start = VIDW_BUF_START(0),
  1564. .buf_size = VIDW_BUF_SIZE(0),
  1565. .buf_end = VIDW_BUF_END(0),
  1566. .palette = {
  1567. [0] = 0x2400,
  1568. [1] = 0x2800,
  1569. [2] = 0x2c00,
  1570. [3] = 0x3000,
  1571. [4] = 0x3400,
  1572. },
  1573. .has_shadowcon = 1,
  1574. .has_blendcon = 1,
  1575. .has_clksel = 1,
  1576. .has_fixvclk = 1,
  1577. },
  1578. .win[0] = &s3c_fb_data_s5p_wins[0],
  1579. .win[1] = &s3c_fb_data_s5p_wins[1],
  1580. .win[2] = &s3c_fb_data_s5p_wins[2],
  1581. .win[3] = &s3c_fb_data_s5p_wins[3],
  1582. .win[4] = &s3c_fb_data_s5p_wins[4],
  1583. };
  1584. static struct s3c_fb_driverdata s3c_fb_data_exynos4 = {
  1585. .variant = {
  1586. .nr_windows = 5,
  1587. .vidtcon = VIDTCON0,
  1588. .wincon = WINCON(0),
  1589. .winmap = WINxMAP(0),
  1590. .keycon = WKEYCON,
  1591. .osd = VIDOSD_BASE,
  1592. .osd_stride = 16,
  1593. .buf_start = VIDW_BUF_START(0),
  1594. .buf_size = VIDW_BUF_SIZE(0),
  1595. .buf_end = VIDW_BUF_END(0),
  1596. .palette = {
  1597. [0] = 0x2400,
  1598. [1] = 0x2800,
  1599. [2] = 0x2c00,
  1600. [3] = 0x3000,
  1601. [4] = 0x3400,
  1602. },
  1603. .has_shadowcon = 1,
  1604. .has_blendcon = 1,
  1605. .has_fixvclk = 1,
  1606. },
  1607. .win[0] = &s3c_fb_data_s5p_wins[0],
  1608. .win[1] = &s3c_fb_data_s5p_wins[1],
  1609. .win[2] = &s3c_fb_data_s5p_wins[2],
  1610. .win[3] = &s3c_fb_data_s5p_wins[3],
  1611. .win[4] = &s3c_fb_data_s5p_wins[4],
  1612. };
  1613. static struct s3c_fb_driverdata s3c_fb_data_exynos5 = {
  1614. .variant = {
  1615. .nr_windows = 5,
  1616. .vidtcon = VIDTCON0,
  1617. .wincon = WINCON(0),
  1618. .winmap = WINxMAP(0),
  1619. .keycon = WKEYCON,
  1620. .osd = VIDOSD_BASE,
  1621. .osd_stride = 16,
  1622. .buf_start = VIDW_BUF_START(0),
  1623. .buf_size = VIDW_BUF_SIZE(0),
  1624. .buf_end = VIDW_BUF_END(0),
  1625. .palette = {
  1626. [0] = 0x2400,
  1627. [1] = 0x2800,
  1628. [2] = 0x2c00,
  1629. [3] = 0x3000,
  1630. [4] = 0x3400,
  1631. },
  1632. .has_shadowcon = 1,
  1633. .has_blendcon = 1,
  1634. .has_fixvclk = 1,
  1635. },
  1636. .win[0] = &s3c_fb_data_s5p_wins[0],
  1637. .win[1] = &s3c_fb_data_s5p_wins[1],
  1638. .win[2] = &s3c_fb_data_s5p_wins[2],
  1639. .win[3] = &s3c_fb_data_s5p_wins[3],
  1640. .win[4] = &s3c_fb_data_s5p_wins[4],
  1641. };
  1642. /* S3C2443/S3C2416 style hardware */
  1643. static struct s3c_fb_driverdata s3c_fb_data_s3c2443 = {
  1644. .variant = {
  1645. .nr_windows = 2,
  1646. .is_2443 = 1,
  1647. .vidtcon = 0x08,
  1648. .wincon = 0x14,
  1649. .winmap = 0xd0,
  1650. .keycon = 0xb0,
  1651. .osd = 0x28,
  1652. .osd_stride = 12,
  1653. .buf_start = 0x64,
  1654. .buf_size = 0x94,
  1655. .buf_end = 0x7c,
  1656. .palette = {
  1657. [0] = 0x400,
  1658. [1] = 0x800,
  1659. },
  1660. .has_clksel = 1,
  1661. },
  1662. .win[0] = &(struct s3c_fb_win_variant) {
  1663. .palette_sz = 256,
  1664. .valid_bpp = VALID_BPP1248 | VALID_BPP(16) | VALID_BPP(24),
  1665. },
  1666. .win[1] = &(struct s3c_fb_win_variant) {
  1667. .has_osd_c = 1,
  1668. .has_osd_alpha = 1,
  1669. .palette_sz = 256,
  1670. .valid_bpp = (VALID_BPP1248 | VALID_BPP(16) |
  1671. VALID_BPP(18) | VALID_BPP(19) |
  1672. VALID_BPP(24) | VALID_BPP(25) |
  1673. VALID_BPP(28)),
  1674. },
  1675. };
  1676. static struct s3c_fb_driverdata s3c_fb_data_s5p64x0 = {
  1677. .variant = {
  1678. .nr_windows = 3,
  1679. .vidtcon = VIDTCON0,
  1680. .wincon = WINCON(0),
  1681. .winmap = WINxMAP(0),
  1682. .keycon = WKEYCON,
  1683. .osd = VIDOSD_BASE,
  1684. .osd_stride = 16,
  1685. .buf_start = VIDW_BUF_START(0),
  1686. .buf_size = VIDW_BUF_SIZE(0),
  1687. .buf_end = VIDW_BUF_END(0),
  1688. .palette = {
  1689. [0] = 0x2400,
  1690. [1] = 0x2800,
  1691. [2] = 0x2c00,
  1692. },
  1693. .has_blendcon = 1,
  1694. .has_fixvclk = 1,
  1695. },
  1696. .win[0] = &s3c_fb_data_s5p_wins[0],
  1697. .win[1] = &s3c_fb_data_s5p_wins[1],
  1698. .win[2] = &s3c_fb_data_s5p_wins[2],
  1699. };
  1700. static struct platform_device_id s3c_fb_driver_ids[] = {
  1701. {
  1702. .name = "s3c-fb",
  1703. .driver_data = (unsigned long)&s3c_fb_data_64xx,
  1704. }, {
  1705. .name = "s5pc100-fb",
  1706. .driver_data = (unsigned long)&s3c_fb_data_s5pc100,
  1707. }, {
  1708. .name = "s5pv210-fb",
  1709. .driver_data = (unsigned long)&s3c_fb_data_s5pv210,
  1710. }, {
  1711. .name = "exynos4-fb",
  1712. .driver_data = (unsigned long)&s3c_fb_data_exynos4,
  1713. }, {
  1714. .name = "exynos5-fb",
  1715. .driver_data = (unsigned long)&s3c_fb_data_exynos5,
  1716. }, {
  1717. .name = "s3c2443-fb",
  1718. .driver_data = (unsigned long)&s3c_fb_data_s3c2443,
  1719. }, {
  1720. .name = "s5p64x0-fb",
  1721. .driver_data = (unsigned long)&s3c_fb_data_s5p64x0,
  1722. },
  1723. {},
  1724. };
  1725. MODULE_DEVICE_TABLE(platform, s3c_fb_driver_ids);
  1726. static const struct dev_pm_ops s3cfb_pm_ops = {
  1727. SET_SYSTEM_SLEEP_PM_OPS(s3c_fb_suspend, s3c_fb_resume)
  1728. SET_RUNTIME_PM_OPS(s3c_fb_runtime_suspend, s3c_fb_runtime_resume,
  1729. NULL)
  1730. };
  1731. static struct platform_driver s3c_fb_driver = {
  1732. .probe = s3c_fb_probe,
  1733. .remove = __devexit_p(s3c_fb_remove),
  1734. .id_table = s3c_fb_driver_ids,
  1735. .driver = {
  1736. .name = "s3c-fb",
  1737. .owner = THIS_MODULE,
  1738. .pm = &s3cfb_pm_ops,
  1739. },
  1740. };
  1741. module_platform_driver(s3c_fb_driver);
  1742. MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
  1743. MODULE_DESCRIPTION("Samsung S3C SoC Framebuffer driver");
  1744. MODULE_LICENSE("GPL");
  1745. MODULE_ALIAS("platform:s3c-fb");