s3c-fb.c 50 KB

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