s3c-fb.c 50 KB

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