s3c-fb.c 51 KB

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