s3c-fb.c 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358
  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 <mach/map.h>
  24. #include <plat/regs-fb-v4.h>
  25. #include <plat/fb.h>
  26. /* This driver will export a number of framebuffer interfaces depending
  27. * on the configuration passed in via the platform data. Each fb instance
  28. * maps to a hardware window. Currently there is no support for runtime
  29. * setting of the alpha-blending functions that each window has, so only
  30. * window 0 is actually useful.
  31. *
  32. * Window 0 is treated specially, it is used for the basis of the LCD
  33. * output timings and as the control for the output power-down state.
  34. */
  35. /* note, the previous use of <mach/regs-fb.h> to get platform specific data
  36. * has been replaced by using the platform device name to pick the correct
  37. * configuration data for the system.
  38. */
  39. #ifdef CONFIG_FB_S3C_DEBUG_REGWRITE
  40. #undef writel
  41. #define writel(v, r) do { \
  42. printk(KERN_DEBUG "%s: %08x => %p\n", __func__, (unsigned int)v, r); \
  43. __raw_writel(v, r); } while(0)
  44. #endif /* FB_S3C_DEBUG_REGWRITE */
  45. struct s3c_fb;
  46. #define VALID_BPP(x) (1 << ((x) - 1))
  47. #define OSD_BASE(win, variant) ((variant).osd + ((win) * (variant).osd_stride))
  48. #define VIDOSD_A(win, variant) (OSD_BASE(win, variant) + 0x00)
  49. #define VIDOSD_B(win, variant) (OSD_BASE(win, variant) + 0x04)
  50. #define VIDOSD_C(win, variant) (OSD_BASE(win, variant) + 0x08)
  51. #define VIDOSD_D(win, variant) (OSD_BASE(win, variant) + 0x0C)
  52. /**
  53. * struct s3c_fb_variant - fb variant information
  54. * @is_2443: Set if S3C2443/S3C2416 style hardware.
  55. * @nr_windows: The number of windows.
  56. * @vidtcon: The base for the VIDTCONx registers
  57. * @wincon: The base for the WINxCON registers.
  58. * @winmap: The base for the WINxMAP registers.
  59. * @keycon: The abse for the WxKEYCON registers.
  60. * @buf_start: Offset of buffer start registers.
  61. * @buf_size: Offset of buffer size registers.
  62. * @buf_end: Offset of buffer end registers.
  63. * @osd: The base for the OSD registers.
  64. * @palette: Address of palette memory, or 0 if none.
  65. */
  66. struct s3c_fb_variant {
  67. unsigned int is_2443:1;
  68. unsigned short nr_windows;
  69. unsigned short vidtcon;
  70. unsigned short wincon;
  71. unsigned short winmap;
  72. unsigned short keycon;
  73. unsigned short buf_start;
  74. unsigned short buf_end;
  75. unsigned short buf_size;
  76. unsigned short osd;
  77. unsigned short osd_stride;
  78. unsigned short palette[S3C_FB_MAX_WIN];
  79. };
  80. /**
  81. * struct s3c_fb_win_variant
  82. * @has_osd_c: Set if has OSD C register.
  83. * @has_osd_d: Set if has OSD D register.
  84. * @palette_sz: Size of palette in entries.
  85. * @palette_16bpp: Set if palette is 16bits wide.
  86. * @valid_bpp: 1 bit per BPP setting to show valid bits-per-pixel.
  87. *
  88. * valid_bpp bit x is set if (x+1)BPP is supported.
  89. */
  90. struct s3c_fb_win_variant {
  91. unsigned int has_osd_c:1;
  92. unsigned int has_osd_d:1;
  93. unsigned int palette_16bpp:1;
  94. unsigned short palette_sz;
  95. u32 valid_bpp;
  96. };
  97. /**
  98. * struct s3c_fb_driverdata - per-device type driver data for init time.
  99. * @variant: The variant information for this driver.
  100. * @win: The window information for each window.
  101. */
  102. struct s3c_fb_driverdata {
  103. struct s3c_fb_variant variant;
  104. struct s3c_fb_win_variant *win[S3C_FB_MAX_WIN];
  105. };
  106. /**
  107. * struct s3c_fb_palette - palette information
  108. * @r: Red bitfield.
  109. * @g: Green bitfield.
  110. * @b: Blue bitfield.
  111. * @a: Alpha bitfield.
  112. */
  113. struct s3c_fb_palette {
  114. struct fb_bitfield r;
  115. struct fb_bitfield g;
  116. struct fb_bitfield b;
  117. struct fb_bitfield a;
  118. };
  119. /**
  120. * struct s3c_fb_win - per window private data for each framebuffer.
  121. * @windata: The platform data supplied for the window configuration.
  122. * @parent: The hardware that this window is part of.
  123. * @fbinfo: Pointer pack to the framebuffer info for this window.
  124. * @varint: The variant information for this window.
  125. * @palette_buffer: Buffer/cache to hold palette entries.
  126. * @pseudo_palette: For use in TRUECOLOUR modes for entries 0..15/
  127. * @index: The window number of this window.
  128. * @palette: The bitfields for changing r/g/b into a hardware palette entry.
  129. */
  130. struct s3c_fb_win {
  131. struct s3c_fb_pd_win *windata;
  132. struct s3c_fb *parent;
  133. struct fb_info *fbinfo;
  134. struct s3c_fb_palette palette;
  135. struct s3c_fb_win_variant variant;
  136. u32 *palette_buffer;
  137. u32 pseudo_palette[16];
  138. unsigned int index;
  139. };
  140. /**
  141. * struct s3c_fb - overall hardware state of the hardware
  142. * @dev: The device that we bound to, for printing, etc.
  143. * @regs_res: The resource we claimed for the IO registers.
  144. * @bus_clk: The clk (hclk) feeding our interface and possibly pixclk.
  145. * @regs: The mapped hardware registers.
  146. * @variant: Variant information for this hardware.
  147. * @enabled: A bitmask of enabled hardware windows.
  148. * @pdata: The platform configuration data passed with the device.
  149. * @windows: The hardware windows that have been claimed.
  150. */
  151. struct s3c_fb {
  152. struct device *dev;
  153. struct resource *regs_res;
  154. struct clk *bus_clk;
  155. void __iomem *regs;
  156. struct s3c_fb_variant variant;
  157. unsigned char enabled;
  158. struct s3c_fb_platdata *pdata;
  159. struct s3c_fb_win *windows[S3C_FB_MAX_WIN];
  160. };
  161. /**
  162. * s3c_fb_validate_win_bpp - validate the bits-per-pixel for this mode.
  163. * @win: The device window.
  164. * @bpp: The bit depth.
  165. */
  166. static bool s3c_fb_validate_win_bpp(struct s3c_fb_win *win, unsigned int bpp)
  167. {
  168. return win->variant.valid_bpp & VALID_BPP(bpp);
  169. }
  170. /**
  171. * s3c_fb_check_var() - framebuffer layer request to verify a given mode.
  172. * @var: The screen information to verify.
  173. * @info: The framebuffer device.
  174. *
  175. * Framebuffer layer call to verify the given information and allow us to
  176. * update various information depending on the hardware capabilities.
  177. */
  178. static int s3c_fb_check_var(struct fb_var_screeninfo *var,
  179. struct fb_info *info)
  180. {
  181. struct s3c_fb_win *win = info->par;
  182. struct s3c_fb_pd_win *windata = win->windata;
  183. struct s3c_fb *sfb = win->parent;
  184. dev_dbg(sfb->dev, "checking parameters\n");
  185. var->xres_virtual = max((unsigned int)windata->virtual_x, var->xres);
  186. var->yres_virtual = max((unsigned int)windata->virtual_y, var->yres);
  187. if (!s3c_fb_validate_win_bpp(win, var->bits_per_pixel)) {
  188. dev_dbg(sfb->dev, "win %d: unsupported bpp %d\n",
  189. win->index, var->bits_per_pixel);
  190. return -EINVAL;
  191. }
  192. /* always ensure these are zero, for drop through cases below */
  193. var->transp.offset = 0;
  194. var->transp.length = 0;
  195. switch (var->bits_per_pixel) {
  196. case 1:
  197. case 2:
  198. case 4:
  199. case 8:
  200. if (sfb->variant.palette[win->index] != 0) {
  201. /* non palletised, A:1,R:2,G:3,B:2 mode */
  202. var->red.offset = 4;
  203. var->green.offset = 2;
  204. var->blue.offset = 0;
  205. var->red.length = 5;
  206. var->green.length = 3;
  207. var->blue.length = 2;
  208. var->transp.offset = 7;
  209. var->transp.length = 1;
  210. } else {
  211. var->red.offset = 0;
  212. var->red.length = var->bits_per_pixel;
  213. var->green = var->red;
  214. var->blue = var->red;
  215. }
  216. break;
  217. case 19:
  218. /* 666 with one bit alpha/transparency */
  219. var->transp.offset = 18;
  220. var->transp.length = 1;
  221. case 18:
  222. var->bits_per_pixel = 32;
  223. /* 666 format */
  224. var->red.offset = 12;
  225. var->green.offset = 6;
  226. var->blue.offset = 0;
  227. var->red.length = 6;
  228. var->green.length = 6;
  229. var->blue.length = 6;
  230. break;
  231. case 16:
  232. /* 16 bpp, 565 format */
  233. var->red.offset = 11;
  234. var->green.offset = 5;
  235. var->blue.offset = 0;
  236. var->red.length = 5;
  237. var->green.length = 6;
  238. var->blue.length = 5;
  239. break;
  240. case 28:
  241. case 25:
  242. var->transp.length = var->bits_per_pixel - 24;
  243. var->transp.offset = 24;
  244. /* drop through */
  245. case 24:
  246. /* our 24bpp is unpacked, so 32bpp */
  247. var->bits_per_pixel = 32;
  248. case 32:
  249. var->red.offset = 16;
  250. var->red.length = 8;
  251. var->green.offset = 8;
  252. var->green.length = 8;
  253. var->blue.offset = 0;
  254. var->blue.length = 8;
  255. break;
  256. default:
  257. dev_err(sfb->dev, "invalid bpp\n");
  258. }
  259. dev_dbg(sfb->dev, "%s: verified parameters\n", __func__);
  260. return 0;
  261. }
  262. /**
  263. * s3c_fb_calc_pixclk() - calculate the divider to create the pixel clock.
  264. * @sfb: The hardware state.
  265. * @pixclock: The pixel clock wanted, in picoseconds.
  266. *
  267. * Given the specified pixel clock, work out the necessary divider to get
  268. * close to the output frequency.
  269. */
  270. static int s3c_fb_calc_pixclk(struct s3c_fb *sfb, unsigned int pixclk)
  271. {
  272. unsigned long clk = clk_get_rate(sfb->bus_clk);
  273. unsigned long long tmp;
  274. unsigned int result;
  275. tmp = (unsigned long long)clk;
  276. tmp *= pixclk;
  277. do_div(tmp, 1000000000UL);
  278. result = (unsigned int)tmp / 1000;
  279. dev_dbg(sfb->dev, "pixclk=%u, clk=%lu, div=%d (%lu)\n",
  280. pixclk, clk, result, clk / result);
  281. return result;
  282. }
  283. /**
  284. * s3c_fb_align_word() - align pixel count to word boundary
  285. * @bpp: The number of bits per pixel
  286. * @pix: The value to be aligned.
  287. *
  288. * Align the given pixel count so that it will start on an 32bit word
  289. * boundary.
  290. */
  291. static int s3c_fb_align_word(unsigned int bpp, unsigned int pix)
  292. {
  293. int pix_per_word;
  294. if (bpp > 16)
  295. return pix;
  296. pix_per_word = (8 * 32) / bpp;
  297. return ALIGN(pix, pix_per_word);
  298. }
  299. /**
  300. * s3c_fb_set_par() - framebuffer request to set new framebuffer state.
  301. * @info: The framebuffer to change.
  302. *
  303. * Framebuffer layer request to set a new mode for the specified framebuffer
  304. */
  305. static int s3c_fb_set_par(struct fb_info *info)
  306. {
  307. struct fb_var_screeninfo *var = &info->var;
  308. struct s3c_fb_win *win = info->par;
  309. struct s3c_fb *sfb = win->parent;
  310. void __iomem *regs = sfb->regs;
  311. void __iomem *buf = regs;
  312. int win_no = win->index;
  313. u32 osdc_data = 0;
  314. u32 data;
  315. u32 pagewidth;
  316. int clkdiv;
  317. dev_dbg(sfb->dev, "setting framebuffer parameters\n");
  318. switch (var->bits_per_pixel) {
  319. case 32:
  320. case 24:
  321. case 16:
  322. case 12:
  323. info->fix.visual = FB_VISUAL_TRUECOLOR;
  324. break;
  325. case 8:
  326. if (win->variant.palette_sz >= 256)
  327. info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
  328. else
  329. info->fix.visual = FB_VISUAL_TRUECOLOR;
  330. break;
  331. case 1:
  332. info->fix.visual = FB_VISUAL_MONO01;
  333. break;
  334. default:
  335. info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
  336. break;
  337. }
  338. info->fix.line_length = (var->xres_virtual * var->bits_per_pixel) / 8;
  339. /* disable the window whilst we update it */
  340. writel(0, regs + WINCON(win_no));
  341. /* use platform specified window as the basis for the lcd timings */
  342. if (win_no == sfb->pdata->default_win) {
  343. clkdiv = s3c_fb_calc_pixclk(sfb, var->pixclock);
  344. data = sfb->pdata->vidcon0;
  345. data &= ~(VIDCON0_CLKVAL_F_MASK | VIDCON0_CLKDIR);
  346. if (clkdiv > 1)
  347. data |= VIDCON0_CLKVAL_F(clkdiv-1) | VIDCON0_CLKDIR;
  348. else
  349. data &= ~VIDCON0_CLKDIR; /* 1:1 clock */
  350. /* write the timing data to the panel */
  351. if (sfb->variant.is_2443)
  352. data |= (1 << 5);
  353. data |= VIDCON0_ENVID | VIDCON0_ENVID_F;
  354. writel(data, regs + VIDCON0);
  355. data = VIDTCON0_VBPD(var->upper_margin - 1) |
  356. VIDTCON0_VFPD(var->lower_margin - 1) |
  357. VIDTCON0_VSPW(var->vsync_len - 1);
  358. writel(data, regs + sfb->variant.vidtcon);
  359. data = VIDTCON1_HBPD(var->left_margin - 1) |
  360. VIDTCON1_HFPD(var->right_margin - 1) |
  361. VIDTCON1_HSPW(var->hsync_len - 1);
  362. /* VIDTCON1 */
  363. writel(data, regs + sfb->variant.vidtcon + 4);
  364. data = VIDTCON2_LINEVAL(var->yres - 1) |
  365. VIDTCON2_HOZVAL(var->xres - 1);
  366. writel(data, regs +sfb->variant.vidtcon + 8 );
  367. }
  368. /* write the buffer address */
  369. /* start and end registers stride is 8 */
  370. buf = regs + win_no * 8;
  371. writel(info->fix.smem_start, buf + sfb->variant.buf_start);
  372. data = info->fix.smem_start + info->fix.line_length * var->yres;
  373. writel(data, buf + sfb->variant.buf_end);
  374. pagewidth = (var->xres * var->bits_per_pixel) >> 3;
  375. data = VIDW_BUF_SIZE_OFFSET(info->fix.line_length - pagewidth) |
  376. VIDW_BUF_SIZE_PAGEWIDTH(pagewidth);
  377. writel(data, regs + sfb->variant.buf_size + (win_no * 4));
  378. /* write 'OSD' registers to control position of framebuffer */
  379. data = VIDOSDxA_TOPLEFT_X(0) | VIDOSDxA_TOPLEFT_Y(0);
  380. writel(data, regs + VIDOSD_A(win_no, sfb->variant));
  381. data = VIDOSDxB_BOTRIGHT_X(s3c_fb_align_word(var->bits_per_pixel,
  382. var->xres - 1)) |
  383. VIDOSDxB_BOTRIGHT_Y(var->yres - 1);
  384. writel(data, regs + VIDOSD_B(win_no, sfb->variant));
  385. data = var->xres * var->yres;
  386. osdc_data = VIDISD14C_ALPHA1_R(0xf) |
  387. VIDISD14C_ALPHA1_G(0xf) |
  388. VIDISD14C_ALPHA1_B(0xf);
  389. if (win->variant.has_osd_d) {
  390. writel(data, regs + VIDOSD_D(win_no, sfb->variant));
  391. writel(osdc_data, regs + VIDOSD_C(win_no, sfb->variant));
  392. } else
  393. writel(data, regs + VIDOSD_C(win_no, sfb->variant));
  394. data = WINCONx_ENWIN;
  395. /* note, since we have to round up the bits-per-pixel, we end up
  396. * relying on the bitfield information for r/g/b/a to work out
  397. * exactly which mode of operation is intended. */
  398. switch (var->bits_per_pixel) {
  399. case 1:
  400. data |= WINCON0_BPPMODE_1BPP;
  401. data |= WINCONx_BITSWP;
  402. data |= WINCONx_BURSTLEN_4WORD;
  403. break;
  404. case 2:
  405. data |= WINCON0_BPPMODE_2BPP;
  406. data |= WINCONx_BITSWP;
  407. data |= WINCONx_BURSTLEN_8WORD;
  408. break;
  409. case 4:
  410. data |= WINCON0_BPPMODE_4BPP;
  411. data |= WINCONx_BITSWP;
  412. data |= WINCONx_BURSTLEN_8WORD;
  413. break;
  414. case 8:
  415. if (var->transp.length != 0)
  416. data |= WINCON1_BPPMODE_8BPP_1232;
  417. else
  418. data |= WINCON0_BPPMODE_8BPP_PALETTE;
  419. data |= WINCONx_BURSTLEN_8WORD;
  420. data |= WINCONx_BYTSWP;
  421. break;
  422. case 16:
  423. if (var->transp.length != 0)
  424. data |= WINCON1_BPPMODE_16BPP_A1555;
  425. else
  426. data |= WINCON0_BPPMODE_16BPP_565;
  427. data |= WINCONx_HAWSWP;
  428. data |= WINCONx_BURSTLEN_16WORD;
  429. break;
  430. case 24:
  431. case 32:
  432. if (var->red.length == 6) {
  433. if (var->transp.length != 0)
  434. data |= WINCON1_BPPMODE_19BPP_A1666;
  435. else
  436. data |= WINCON1_BPPMODE_18BPP_666;
  437. } else if (var->transp.length == 1)
  438. data |= WINCON1_BPPMODE_25BPP_A1888
  439. | WINCON1_BLD_PIX;
  440. else if (var->transp.length == 4)
  441. data |= WINCON1_BPPMODE_28BPP_A4888
  442. | WINCON1_BLD_PIX | WINCON1_ALPHA_SEL;
  443. else
  444. data |= WINCON0_BPPMODE_24BPP_888;
  445. data |= WINCONx_WSWP;
  446. data |= WINCONx_BURSTLEN_16WORD;
  447. break;
  448. }
  449. /* Enable the colour keying for the window below this one */
  450. if (win_no > 0) {
  451. u32 keycon0_data = 0, keycon1_data = 0;
  452. void __iomem *keycon = regs + sfb->variant.keycon;
  453. keycon0_data = ~(WxKEYCON0_KEYBL_EN |
  454. WxKEYCON0_KEYEN_F |
  455. WxKEYCON0_DIRCON) | WxKEYCON0_COMPKEY(0);
  456. keycon1_data = WxKEYCON1_COLVAL(0xffffff);
  457. keycon += (win_no - 1) * 8;
  458. writel(keycon0_data, keycon + WKEYCON0);
  459. writel(keycon1_data, keycon + WKEYCON1);
  460. }
  461. writel(data, regs + sfb->variant.wincon + (win_no * 4));
  462. writel(0x0, regs + sfb->variant.winmap + (win_no * 4));
  463. return 0;
  464. }
  465. /**
  466. * s3c_fb_update_palette() - set or schedule a palette update.
  467. * @sfb: The hardware information.
  468. * @win: The window being updated.
  469. * @reg: The palette index being changed.
  470. * @value: The computed palette value.
  471. *
  472. * Change the value of a palette register, either by directly writing to
  473. * the palette (this requires the palette RAM to be disconnected from the
  474. * hardware whilst this is in progress) or schedule the update for later.
  475. *
  476. * At the moment, since we have no VSYNC interrupt support, we simply set
  477. * the palette entry directly.
  478. */
  479. static void s3c_fb_update_palette(struct s3c_fb *sfb,
  480. struct s3c_fb_win *win,
  481. unsigned int reg,
  482. u32 value)
  483. {
  484. void __iomem *palreg;
  485. u32 palcon;
  486. palreg = sfb->regs + sfb->variant.palette[win->index];
  487. dev_dbg(sfb->dev, "%s: win %d, reg %d (%p): %08x\n",
  488. __func__, win->index, reg, palreg, value);
  489. win->palette_buffer[reg] = value;
  490. palcon = readl(sfb->regs + WPALCON);
  491. writel(palcon | WPALCON_PAL_UPDATE, sfb->regs + WPALCON);
  492. if (win->variant.palette_16bpp)
  493. writew(value, palreg + (reg * 2));
  494. else
  495. writel(value, palreg + (reg * 4));
  496. writel(palcon, sfb->regs + WPALCON);
  497. }
  498. static inline unsigned int chan_to_field(unsigned int chan,
  499. struct fb_bitfield *bf)
  500. {
  501. chan &= 0xffff;
  502. chan >>= 16 - bf->length;
  503. return chan << bf->offset;
  504. }
  505. /**
  506. * s3c_fb_setcolreg() - framebuffer layer request to change palette.
  507. * @regno: The palette index to change.
  508. * @red: The red field for the palette data.
  509. * @green: The green field for the palette data.
  510. * @blue: The blue field for the palette data.
  511. * @trans: The transparency (alpha) field for the palette data.
  512. * @info: The framebuffer being changed.
  513. */
  514. static int s3c_fb_setcolreg(unsigned regno,
  515. unsigned red, unsigned green, unsigned blue,
  516. unsigned transp, struct fb_info *info)
  517. {
  518. struct s3c_fb_win *win = info->par;
  519. struct s3c_fb *sfb = win->parent;
  520. unsigned int val;
  521. dev_dbg(sfb->dev, "%s: win %d: %d => rgb=%d/%d/%d\n",
  522. __func__, win->index, regno, red, green, blue);
  523. switch (info->fix.visual) {
  524. case FB_VISUAL_TRUECOLOR:
  525. /* true-colour, use pseudo-palette */
  526. if (regno < 16) {
  527. u32 *pal = info->pseudo_palette;
  528. val = chan_to_field(red, &info->var.red);
  529. val |= chan_to_field(green, &info->var.green);
  530. val |= chan_to_field(blue, &info->var.blue);
  531. pal[regno] = val;
  532. }
  533. break;
  534. case FB_VISUAL_PSEUDOCOLOR:
  535. if (regno < win->variant.palette_sz) {
  536. val = chan_to_field(red, &win->palette.r);
  537. val |= chan_to_field(green, &win->palette.g);
  538. val |= chan_to_field(blue, &win->palette.b);
  539. s3c_fb_update_palette(sfb, win, regno, val);
  540. }
  541. break;
  542. default:
  543. return 1; /* unknown type */
  544. }
  545. return 0;
  546. }
  547. /**
  548. * s3c_fb_enable() - Set the state of the main LCD output
  549. * @sfb: The main framebuffer state.
  550. * @enable: The state to set.
  551. */
  552. static void s3c_fb_enable(struct s3c_fb *sfb, int enable)
  553. {
  554. u32 vidcon0 = readl(sfb->regs + VIDCON0);
  555. if (enable)
  556. vidcon0 |= VIDCON0_ENVID | VIDCON0_ENVID_F;
  557. else {
  558. /* see the note in the framebuffer datasheet about
  559. * why you cannot take both of these bits down at the
  560. * same time. */
  561. if (!(vidcon0 & VIDCON0_ENVID))
  562. return;
  563. vidcon0 |= VIDCON0_ENVID;
  564. vidcon0 &= ~VIDCON0_ENVID_F;
  565. }
  566. writel(vidcon0, sfb->regs + VIDCON0);
  567. }
  568. /**
  569. * s3c_fb_blank() - blank or unblank the given window
  570. * @blank_mode: The blank state from FB_BLANK_*
  571. * @info: The framebuffer to blank.
  572. *
  573. * Framebuffer layer request to change the power state.
  574. */
  575. static int s3c_fb_blank(int blank_mode, struct fb_info *info)
  576. {
  577. struct s3c_fb_win *win = info->par;
  578. struct s3c_fb *sfb = win->parent;
  579. unsigned int index = win->index;
  580. u32 wincon;
  581. dev_dbg(sfb->dev, "blank mode %d\n", blank_mode);
  582. wincon = readl(sfb->regs + sfb->variant.wincon + (index * 4));
  583. switch (blank_mode) {
  584. case FB_BLANK_POWERDOWN:
  585. wincon &= ~WINCONx_ENWIN;
  586. sfb->enabled &= ~(1 << index);
  587. /* fall through to FB_BLANK_NORMAL */
  588. case FB_BLANK_NORMAL:
  589. /* disable the DMA and display 0x0 (black) */
  590. writel(WINxMAP_MAP | WINxMAP_MAP_COLOUR(0x0),
  591. sfb->regs + sfb->variant.winmap + (index * 4));
  592. break;
  593. case FB_BLANK_UNBLANK:
  594. writel(0x0, sfb->regs + sfb->variant.winmap + (index * 4));
  595. wincon |= WINCONx_ENWIN;
  596. sfb->enabled |= (1 << index);
  597. break;
  598. case FB_BLANK_VSYNC_SUSPEND:
  599. case FB_BLANK_HSYNC_SUSPEND:
  600. default:
  601. return 1;
  602. }
  603. writel(wincon, sfb->regs + sfb->variant.wincon + (index * 4));
  604. /* Check the enabled state to see if we need to be running the
  605. * main LCD interface, as if there are no active windows then
  606. * it is highly likely that we also do not need to output
  607. * anything.
  608. */
  609. /* We could do something like the following code, but the current
  610. * system of using framebuffer events means that we cannot make
  611. * the distinction between just window 0 being inactive and all
  612. * the windows being down.
  613. *
  614. * s3c_fb_enable(sfb, sfb->enabled ? 1 : 0);
  615. */
  616. /* we're stuck with this until we can do something about overriding
  617. * the power control using the blanking event for a single fb.
  618. */
  619. if (index == sfb->pdata->default_win)
  620. s3c_fb_enable(sfb, blank_mode != FB_BLANK_POWERDOWN ? 1 : 0);
  621. return 0;
  622. }
  623. static struct fb_ops s3c_fb_ops = {
  624. .owner = THIS_MODULE,
  625. .fb_check_var = s3c_fb_check_var,
  626. .fb_set_par = s3c_fb_set_par,
  627. .fb_blank = s3c_fb_blank,
  628. .fb_setcolreg = s3c_fb_setcolreg,
  629. .fb_fillrect = cfb_fillrect,
  630. .fb_copyarea = cfb_copyarea,
  631. .fb_imageblit = cfb_imageblit,
  632. };
  633. /**
  634. * s3c_fb_alloc_memory() - allocate display memory for framebuffer window
  635. * @sfb: The base resources for the hardware.
  636. * @win: The window to initialise memory for.
  637. *
  638. * Allocate memory for the given framebuffer.
  639. */
  640. static int __devinit s3c_fb_alloc_memory(struct s3c_fb *sfb,
  641. struct s3c_fb_win *win)
  642. {
  643. struct s3c_fb_pd_win *windata = win->windata;
  644. unsigned int real_size, virt_size, size;
  645. struct fb_info *fbi = win->fbinfo;
  646. dma_addr_t map_dma;
  647. dev_dbg(sfb->dev, "allocating memory for display\n");
  648. real_size = windata->win_mode.xres * windata->win_mode.yres;
  649. virt_size = windata->virtual_x * windata->virtual_y;
  650. dev_dbg(sfb->dev, "real_size=%u (%u.%u), virt_size=%u (%u.%u)\n",
  651. real_size, windata->win_mode.xres, windata->win_mode.yres,
  652. virt_size, windata->virtual_x, windata->virtual_y);
  653. size = (real_size > virt_size) ? real_size : virt_size;
  654. size *= (windata->max_bpp > 16) ? 32 : windata->max_bpp;
  655. size /= 8;
  656. fbi->fix.smem_len = size;
  657. size = PAGE_ALIGN(size);
  658. dev_dbg(sfb->dev, "want %u bytes for window\n", size);
  659. fbi->screen_base = dma_alloc_writecombine(sfb->dev, size,
  660. &map_dma, GFP_KERNEL);
  661. if (!fbi->screen_base)
  662. return -ENOMEM;
  663. dev_dbg(sfb->dev, "mapped %x to %p\n",
  664. (unsigned int)map_dma, fbi->screen_base);
  665. memset(fbi->screen_base, 0x0, size);
  666. fbi->fix.smem_start = map_dma;
  667. return 0;
  668. }
  669. /**
  670. * s3c_fb_free_memory() - free the display memory for the given window
  671. * @sfb: The base resources for the hardware.
  672. * @win: The window to free the display memory for.
  673. *
  674. * Free the display memory allocated by s3c_fb_alloc_memory().
  675. */
  676. static void s3c_fb_free_memory(struct s3c_fb *sfb, struct s3c_fb_win *win)
  677. {
  678. struct fb_info *fbi = win->fbinfo;
  679. dma_free_writecombine(sfb->dev, PAGE_ALIGN(fbi->fix.smem_len),
  680. fbi->screen_base, fbi->fix.smem_start);
  681. }
  682. /**
  683. * s3c_fb_release_win() - release resources for a framebuffer window.
  684. * @win: The window to cleanup the resources for.
  685. *
  686. * Release the resources that where claimed for the hardware window,
  687. * such as the framebuffer instance and any memory claimed for it.
  688. */
  689. static void s3c_fb_release_win(struct s3c_fb *sfb, struct s3c_fb_win *win)
  690. {
  691. if (win->fbinfo) {
  692. unregister_framebuffer(win->fbinfo);
  693. fb_dealloc_cmap(&win->fbinfo->cmap);
  694. s3c_fb_free_memory(sfb, win);
  695. framebuffer_release(win->fbinfo);
  696. }
  697. }
  698. /**
  699. * s3c_fb_probe_win() - register an hardware window
  700. * @sfb: The base resources for the hardware
  701. * @variant: The variant information for this window.
  702. * @res: Pointer to where to place the resultant window.
  703. *
  704. * Allocate and do the basic initialisation for one of the hardware's graphics
  705. * windows.
  706. */
  707. static int __devinit s3c_fb_probe_win(struct s3c_fb *sfb, unsigned int win_no,
  708. struct s3c_fb_win_variant *variant,
  709. struct s3c_fb_win **res)
  710. {
  711. struct fb_var_screeninfo *var;
  712. struct fb_videomode *initmode;
  713. struct s3c_fb_pd_win *windata;
  714. struct s3c_fb_win *win;
  715. struct fb_info *fbinfo;
  716. int palette_size;
  717. int ret;
  718. dev_dbg(sfb->dev, "probing window %d, variant %p\n", win_no, variant);
  719. palette_size = variant->palette_sz * 4;
  720. fbinfo = framebuffer_alloc(sizeof(struct s3c_fb_win) +
  721. palette_size * sizeof(u32), sfb->dev);
  722. if (!fbinfo) {
  723. dev_err(sfb->dev, "failed to allocate framebuffer\n");
  724. return -ENOENT;
  725. }
  726. windata = sfb->pdata->win[win_no];
  727. initmode = &windata->win_mode;
  728. WARN_ON(windata->max_bpp == 0);
  729. WARN_ON(windata->win_mode.xres == 0);
  730. WARN_ON(windata->win_mode.yres == 0);
  731. win = fbinfo->par;
  732. var = &fbinfo->var;
  733. win->variant = *variant;
  734. win->fbinfo = fbinfo;
  735. win->parent = sfb;
  736. win->windata = windata;
  737. win->index = win_no;
  738. win->palette_buffer = (u32 *)(win + 1);
  739. ret = s3c_fb_alloc_memory(sfb, win);
  740. if (ret) {
  741. dev_err(sfb->dev, "failed to allocate display memory\n");
  742. return ret;
  743. }
  744. /* setup the r/b/g positions for the window's palette */
  745. if (win->variant.palette_16bpp) {
  746. /* Set RGB 5:6:5 as default */
  747. win->palette.r.offset = 11;
  748. win->palette.r.length = 5;
  749. win->palette.g.offset = 5;
  750. win->palette.g.length = 6;
  751. win->palette.b.offset = 0;
  752. win->palette.b.length = 5;
  753. } else {
  754. /* Set 8bpp or 8bpp and 1bit alpha */
  755. win->palette.r.offset = 16;
  756. win->palette.r.length = 8;
  757. win->palette.g.offset = 8;
  758. win->palette.g.length = 8;
  759. win->palette.b.offset = 0;
  760. win->palette.b.length = 8;
  761. }
  762. /* setup the initial video mode from the window */
  763. fb_videomode_to_var(&fbinfo->var, initmode);
  764. fbinfo->fix.type = FB_TYPE_PACKED_PIXELS;
  765. fbinfo->fix.accel = FB_ACCEL_NONE;
  766. fbinfo->var.activate = FB_ACTIVATE_NOW;
  767. fbinfo->var.vmode = FB_VMODE_NONINTERLACED;
  768. fbinfo->var.bits_per_pixel = windata->default_bpp;
  769. fbinfo->fbops = &s3c_fb_ops;
  770. fbinfo->flags = FBINFO_FLAG_DEFAULT;
  771. fbinfo->pseudo_palette = &win->pseudo_palette;
  772. /* prepare to actually start the framebuffer */
  773. ret = s3c_fb_check_var(&fbinfo->var, fbinfo);
  774. if (ret < 0) {
  775. dev_err(sfb->dev, "check_var failed on initial video params\n");
  776. return ret;
  777. }
  778. /* create initial colour map */
  779. ret = fb_alloc_cmap(&fbinfo->cmap, win->variant.palette_sz, 1);
  780. if (ret == 0)
  781. fb_set_cmap(&fbinfo->cmap, fbinfo);
  782. else
  783. dev_err(sfb->dev, "failed to allocate fb cmap\n");
  784. s3c_fb_set_par(fbinfo);
  785. dev_dbg(sfb->dev, "about to register framebuffer\n");
  786. /* run the check_var and set_par on our configuration. */
  787. ret = register_framebuffer(fbinfo);
  788. if (ret < 0) {
  789. dev_err(sfb->dev, "failed to register framebuffer\n");
  790. return ret;
  791. }
  792. *res = win;
  793. dev_info(sfb->dev, "window %d: fb %s\n", win_no, fbinfo->fix.id);
  794. return 0;
  795. }
  796. /**
  797. * s3c_fb_clear_win() - clear hardware window registers.
  798. * @sfb: The base resources for the hardware.
  799. * @win: The window to process.
  800. *
  801. * Reset the specific window registers to a known state.
  802. */
  803. static void s3c_fb_clear_win(struct s3c_fb *sfb, int win)
  804. {
  805. void __iomem *regs = sfb->regs;
  806. writel(0, regs + sfb->variant.wincon + (win * 4));
  807. writel(0, regs + VIDOSD_A(win, sfb->variant));
  808. writel(0, regs + VIDOSD_B(win, sfb->variant));
  809. writel(0, regs + VIDOSD_C(win, sfb->variant));
  810. }
  811. static int __devinit s3c_fb_probe(struct platform_device *pdev)
  812. {
  813. struct s3c_fb_driverdata *fbdrv;
  814. struct device *dev = &pdev->dev;
  815. struct s3c_fb_platdata *pd;
  816. struct s3c_fb *sfb;
  817. struct resource *res;
  818. int win;
  819. int ret = 0;
  820. fbdrv = (struct s3c_fb_driverdata *)platform_get_device_id(pdev)->driver_data;
  821. if (fbdrv->variant.nr_windows > S3C_FB_MAX_WIN) {
  822. dev_err(dev, "too many windows, cannot attach\n");
  823. return -EINVAL;
  824. }
  825. pd = pdev->dev.platform_data;
  826. if (!pd) {
  827. dev_err(dev, "no platform data specified\n");
  828. return -EINVAL;
  829. }
  830. sfb = kzalloc(sizeof(struct s3c_fb), GFP_KERNEL);
  831. if (!sfb) {
  832. dev_err(dev, "no memory for framebuffers\n");
  833. return -ENOMEM;
  834. }
  835. dev_dbg(dev, "allocate new framebuffer %p\n", sfb);
  836. sfb->dev = dev;
  837. sfb->pdata = pd;
  838. sfb->variant = fbdrv->variant;
  839. sfb->bus_clk = clk_get(dev, "lcd");
  840. if (IS_ERR(sfb->bus_clk)) {
  841. dev_err(dev, "failed to get bus clock\n");
  842. goto err_sfb;
  843. }
  844. clk_enable(sfb->bus_clk);
  845. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  846. if (!res) {
  847. dev_err(dev, "failed to find registers\n");
  848. ret = -ENOENT;
  849. goto err_clk;
  850. }
  851. sfb->regs_res = request_mem_region(res->start, resource_size(res),
  852. dev_name(dev));
  853. if (!sfb->regs_res) {
  854. dev_err(dev, "failed to claim register region\n");
  855. ret = -ENOENT;
  856. goto err_clk;
  857. }
  858. sfb->regs = ioremap(res->start, resource_size(res));
  859. if (!sfb->regs) {
  860. dev_err(dev, "failed to map registers\n");
  861. ret = -ENXIO;
  862. goto err_req_region;
  863. }
  864. dev_dbg(dev, "got resources (regs %p), probing windows\n", sfb->regs);
  865. /* setup gpio and output polarity controls */
  866. pd->setup_gpio();
  867. writel(pd->vidcon1, sfb->regs + VIDCON1);
  868. /* zero all windows before we do anything */
  869. for (win = 0; win < fbdrv->variant.nr_windows; win++)
  870. s3c_fb_clear_win(sfb, win);
  871. /* initialise colour key controls */
  872. for (win = 0; win < (fbdrv->variant.nr_windows - 1); win++) {
  873. void __iomem *regs = sfb->regs + sfb->variant.keycon;
  874. regs += (win * 8);
  875. writel(0xffffff, regs + WKEYCON0);
  876. writel(0xffffff, regs + WKEYCON1);
  877. }
  878. /* we have the register setup, start allocating framebuffers */
  879. for (win = 0; win < fbdrv->variant.nr_windows; win++) {
  880. if (!pd->win[win])
  881. continue;
  882. ret = s3c_fb_probe_win(sfb, win, fbdrv->win[win],
  883. &sfb->windows[win]);
  884. if (ret < 0) {
  885. dev_err(dev, "failed to create window %d\n", win);
  886. for (; win >= 0; win--)
  887. s3c_fb_release_win(sfb, sfb->windows[win]);
  888. goto err_ioremap;
  889. }
  890. }
  891. platform_set_drvdata(pdev, sfb);
  892. return 0;
  893. err_ioremap:
  894. iounmap(sfb->regs);
  895. err_req_region:
  896. release_resource(sfb->regs_res);
  897. kfree(sfb->regs_res);
  898. err_clk:
  899. clk_disable(sfb->bus_clk);
  900. clk_put(sfb->bus_clk);
  901. err_sfb:
  902. kfree(sfb);
  903. return ret;
  904. }
  905. /**
  906. * s3c_fb_remove() - Cleanup on module finalisation
  907. * @pdev: The platform device we are bound to.
  908. *
  909. * Shutdown and then release all the resources that the driver allocated
  910. * on initialisation.
  911. */
  912. static int __devexit s3c_fb_remove(struct platform_device *pdev)
  913. {
  914. struct s3c_fb *sfb = platform_get_drvdata(pdev);
  915. int win;
  916. for (win = 0; win < S3C_FB_MAX_WIN; win++)
  917. if (sfb->windows[win])
  918. s3c_fb_release_win(sfb, sfb->windows[win]);
  919. iounmap(sfb->regs);
  920. clk_disable(sfb->bus_clk);
  921. clk_put(sfb->bus_clk);
  922. release_resource(sfb->regs_res);
  923. kfree(sfb->regs_res);
  924. kfree(sfb);
  925. return 0;
  926. }
  927. #ifdef CONFIG_PM
  928. static int s3c_fb_suspend(struct platform_device *pdev, pm_message_t state)
  929. {
  930. struct s3c_fb *sfb = platform_get_drvdata(pdev);
  931. struct s3c_fb_win *win;
  932. int win_no;
  933. for (win_no = S3C_FB_MAX_WIN - 1; win_no >= 0; win_no--) {
  934. win = sfb->windows[win_no];
  935. if (!win)
  936. continue;
  937. /* use the blank function to push into power-down */
  938. s3c_fb_blank(FB_BLANK_POWERDOWN, win->fbinfo);
  939. }
  940. clk_disable(sfb->bus_clk);
  941. return 0;
  942. }
  943. static int s3c_fb_resume(struct platform_device *pdev)
  944. {
  945. struct s3c_fb *sfb = platform_get_drvdata(pdev);
  946. struct s3c_fb_platdata *pd = sfb->pdata;
  947. struct s3c_fb_win *win;
  948. int win_no;
  949. clk_enable(sfb->bus_clk);
  950. /* setup registers */
  951. writel(pd->vidcon1, sfb->regs + VIDCON1);
  952. /* zero all windows before we do anything */
  953. for (win_no = 0; win_no < sfb->variant.nr_windows; win_no++)
  954. s3c_fb_clear_win(sfb, win_no);
  955. for (win_no = 0; win_no < sfb->variant.nr_windows - 1; win_no++) {
  956. void __iomem *regs = sfb->regs + sfb->variant.keycon;
  957. regs += (win_no * 8);
  958. writel(0xffffff, regs + WKEYCON0);
  959. writel(0xffffff, regs + WKEYCON1);
  960. }
  961. /* restore framebuffers */
  962. for (win_no = 0; win_no < S3C_FB_MAX_WIN; win_no++) {
  963. win = sfb->windows[win_no];
  964. if (!win)
  965. continue;
  966. dev_dbg(&pdev->dev, "resuming window %d\n", win_no);
  967. s3c_fb_set_par(win->fbinfo);
  968. }
  969. return 0;
  970. }
  971. #else
  972. #define s3c_fb_suspend NULL
  973. #define s3c_fb_resume NULL
  974. #endif
  975. #define VALID_BPP124 (VALID_BPP(1) | VALID_BPP(2) | VALID_BPP(4))
  976. #define VALID_BPP1248 (VALID_BPP124 | VALID_BPP(8))
  977. static struct s3c_fb_win_variant s3c_fb_data_64xx_wins[] __devinitdata = {
  978. [0] = {
  979. .has_osd_c = 1,
  980. .palette_sz = 256,
  981. .valid_bpp = VALID_BPP1248 | VALID_BPP(16) | VALID_BPP(24),
  982. },
  983. [1] = {
  984. .has_osd_c = 1,
  985. .has_osd_d = 1,
  986. .palette_sz = 256,
  987. .valid_bpp = (VALID_BPP1248 | VALID_BPP(16) |
  988. VALID_BPP(18) | VALID_BPP(19) |
  989. VALID_BPP(24) | VALID_BPP(25)),
  990. },
  991. [2] = {
  992. .has_osd_c = 1,
  993. .has_osd_d = 1,
  994. .palette_sz = 16,
  995. .palette_16bpp = 1,
  996. .valid_bpp = (VALID_BPP1248 | VALID_BPP(16) |
  997. VALID_BPP(18) | VALID_BPP(19) |
  998. VALID_BPP(24) | VALID_BPP(25)),
  999. },
  1000. [3] = {
  1001. .has_osd_c = 1,
  1002. .has_osd_d = 1,
  1003. .palette_sz = 16,
  1004. .palette_16bpp = 1,
  1005. .valid_bpp = (VALID_BPP124 | VALID_BPP(16) |
  1006. VALID_BPP(18) | VALID_BPP(19) |
  1007. VALID_BPP(24) | VALID_BPP(25)),
  1008. },
  1009. [4] = {
  1010. .has_osd_c = 1,
  1011. .palette_sz = 4,
  1012. .palette_16bpp = 1,
  1013. .valid_bpp = (VALID_BPP(1) | VALID_BPP(2) |
  1014. VALID_BPP(16) | VALID_BPP(18) |
  1015. VALID_BPP(24) | VALID_BPP(25)),
  1016. },
  1017. };
  1018. static struct s3c_fb_driverdata s3c_fb_data_64xx __devinitdata = {
  1019. .variant = {
  1020. .nr_windows = 5,
  1021. .vidtcon = VIDTCON0,
  1022. .wincon = WINCON(0),
  1023. .winmap = WINxMAP(0),
  1024. .keycon = WKEYCON,
  1025. .osd = VIDOSD_BASE,
  1026. .osd_stride = 16,
  1027. .buf_start = VIDW_BUF_START(0),
  1028. .buf_size = VIDW_BUF_SIZE(0),
  1029. .buf_end = VIDW_BUF_END(0),
  1030. .palette = {
  1031. [0] = 0x400,
  1032. [1] = 0x800,
  1033. [2] = 0x300,
  1034. [3] = 0x320,
  1035. [4] = 0x340,
  1036. },
  1037. },
  1038. .win[0] = &s3c_fb_data_64xx_wins[0],
  1039. .win[1] = &s3c_fb_data_64xx_wins[1],
  1040. .win[2] = &s3c_fb_data_64xx_wins[2],
  1041. .win[3] = &s3c_fb_data_64xx_wins[3],
  1042. .win[4] = &s3c_fb_data_64xx_wins[4],
  1043. };
  1044. static struct s3c_fb_driverdata s3c_fb_data_s5p __devinitdata = {
  1045. .variant = {
  1046. .nr_windows = 5,
  1047. .vidtcon = VIDTCON0,
  1048. .wincon = WINCON(0),
  1049. .winmap = WINxMAP(0),
  1050. .keycon = WKEYCON,
  1051. .osd = VIDOSD_BASE,
  1052. .osd_stride = 16,
  1053. .buf_start = VIDW_BUF_START(0),
  1054. .buf_size = VIDW_BUF_SIZE(0),
  1055. .buf_end = VIDW_BUF_END(0),
  1056. .palette = {
  1057. [0] = 0x2400,
  1058. [1] = 0x2800,
  1059. [2] = 0x2c00,
  1060. [3] = 0x3000,
  1061. [4] = 0x3400,
  1062. },
  1063. },
  1064. .win[0] = &s3c_fb_data_64xx_wins[0],
  1065. .win[1] = &s3c_fb_data_64xx_wins[1],
  1066. .win[2] = &s3c_fb_data_64xx_wins[2],
  1067. .win[3] = &s3c_fb_data_64xx_wins[3],
  1068. .win[4] = &s3c_fb_data_64xx_wins[4],
  1069. };
  1070. /* S3C2443/S3C2416 style hardware */
  1071. static struct s3c_fb_driverdata s3c_fb_data_s3c2443 __devinitdata = {
  1072. .variant = {
  1073. .nr_windows = 2,
  1074. .is_2443 = 1,
  1075. .vidtcon = 0x08,
  1076. .wincon = 0x14,
  1077. .winmap = 0xd0,
  1078. .keycon = 0xb0,
  1079. .osd = 0x28,
  1080. .osd_stride = 12,
  1081. .buf_start = 0x64,
  1082. .buf_size = 0x94,
  1083. .buf_end = 0x7c,
  1084. .palette = {
  1085. [0] = 0x400,
  1086. [1] = 0x800,
  1087. },
  1088. },
  1089. .win[0] = &(struct s3c_fb_win_variant) {
  1090. .palette_sz = 256,
  1091. .valid_bpp = VALID_BPP1248 | VALID_BPP(16) | VALID_BPP(24),
  1092. },
  1093. .win[1] = &(struct s3c_fb_win_variant) {
  1094. .has_osd_c = 1,
  1095. .palette_sz = 256,
  1096. .valid_bpp = (VALID_BPP1248 | VALID_BPP(16) |
  1097. VALID_BPP(18) | VALID_BPP(19) |
  1098. VALID_BPP(24) | VALID_BPP(25) |
  1099. VALID_BPP(28)),
  1100. },
  1101. };
  1102. static struct platform_device_id s3c_fb_driver_ids[] = {
  1103. {
  1104. .name = "s3c-fb",
  1105. .driver_data = (unsigned long)&s3c_fb_data_64xx,
  1106. }, {
  1107. .name = "s5p-fb",
  1108. .driver_data = (unsigned long)&s3c_fb_data_s5p,
  1109. }, {
  1110. .name = "s3c2443-fb",
  1111. .driver_data = (unsigned long)&s3c_fb_data_s3c2443,
  1112. },
  1113. {},
  1114. };
  1115. MODULE_DEVICE_TABLE(platform, s3c_fb_driver_ids);
  1116. static struct platform_driver s3c_fb_driver = {
  1117. .probe = s3c_fb_probe,
  1118. .remove = __devexit_p(s3c_fb_remove),
  1119. .suspend = s3c_fb_suspend,
  1120. .resume = s3c_fb_resume,
  1121. .id_table = s3c_fb_driver_ids,
  1122. .driver = {
  1123. .name = "s3c-fb",
  1124. .owner = THIS_MODULE,
  1125. },
  1126. };
  1127. static int __init s3c_fb_init(void)
  1128. {
  1129. return platform_driver_register(&s3c_fb_driver);
  1130. }
  1131. static void __exit s3c_fb_cleanup(void)
  1132. {
  1133. platform_driver_unregister(&s3c_fb_driver);
  1134. }
  1135. module_init(s3c_fb_init);
  1136. module_exit(s3c_fb_cleanup);
  1137. MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
  1138. MODULE_DESCRIPTION("Samsung S3C SoC Framebuffer driver");
  1139. MODULE_LICENSE("GPL");
  1140. MODULE_ALIAS("platform:s3c-fb");