s3c-fb.c 48 KB

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