s3c-fb.c 50 KB

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