s3c-fb.c 48 KB

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