s3c-fb.c 50 KB

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