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