s3c-fb.c 50 KB

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