s3c-fb.c 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360
  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. if (fbi->screen_base)
  680. dma_free_writecombine(sfb->dev, PAGE_ALIGN(fbi->fix.smem_len),
  681. fbi->screen_base, fbi->fix.smem_start);
  682. }
  683. /**
  684. * s3c_fb_release_win() - release resources for a framebuffer window.
  685. * @win: The window to cleanup the resources for.
  686. *
  687. * Release the resources that where claimed for the hardware window,
  688. * such as the framebuffer instance and any memory claimed for it.
  689. */
  690. static void s3c_fb_release_win(struct s3c_fb *sfb, struct s3c_fb_win *win)
  691. {
  692. if (win->fbinfo) {
  693. unregister_framebuffer(win->fbinfo);
  694. if (win->fbinfo->cmap.len)
  695. fb_dealloc_cmap(&win->fbinfo->cmap);
  696. s3c_fb_free_memory(sfb, win);
  697. framebuffer_release(win->fbinfo);
  698. }
  699. }
  700. /**
  701. * s3c_fb_probe_win() - register an hardware window
  702. * @sfb: The base resources for the hardware
  703. * @variant: The variant information for this window.
  704. * @res: Pointer to where to place the resultant window.
  705. *
  706. * Allocate and do the basic initialisation for one of the hardware's graphics
  707. * windows.
  708. */
  709. static int __devinit s3c_fb_probe_win(struct s3c_fb *sfb, unsigned int win_no,
  710. struct s3c_fb_win_variant *variant,
  711. struct s3c_fb_win **res)
  712. {
  713. struct fb_var_screeninfo *var;
  714. struct fb_videomode *initmode;
  715. struct s3c_fb_pd_win *windata;
  716. struct s3c_fb_win *win;
  717. struct fb_info *fbinfo;
  718. int palette_size;
  719. int ret;
  720. dev_dbg(sfb->dev, "probing window %d, variant %p\n", win_no, variant);
  721. palette_size = variant->palette_sz * 4;
  722. fbinfo = framebuffer_alloc(sizeof(struct s3c_fb_win) +
  723. palette_size * sizeof(u32), sfb->dev);
  724. if (!fbinfo) {
  725. dev_err(sfb->dev, "failed to allocate framebuffer\n");
  726. return -ENOENT;
  727. }
  728. windata = sfb->pdata->win[win_no];
  729. initmode = &windata->win_mode;
  730. WARN_ON(windata->max_bpp == 0);
  731. WARN_ON(windata->win_mode.xres == 0);
  732. WARN_ON(windata->win_mode.yres == 0);
  733. win = fbinfo->par;
  734. *res = win;
  735. var = &fbinfo->var;
  736. win->variant = *variant;
  737. win->fbinfo = fbinfo;
  738. win->parent = sfb;
  739. win->windata = windata;
  740. win->index = win_no;
  741. win->palette_buffer = (u32 *)(win + 1);
  742. ret = s3c_fb_alloc_memory(sfb, win);
  743. if (ret) {
  744. dev_err(sfb->dev, "failed to allocate display memory\n");
  745. return ret;
  746. }
  747. /* setup the r/b/g positions for the window's palette */
  748. if (win->variant.palette_16bpp) {
  749. /* Set RGB 5:6:5 as default */
  750. win->palette.r.offset = 11;
  751. win->palette.r.length = 5;
  752. win->palette.g.offset = 5;
  753. win->palette.g.length = 6;
  754. win->palette.b.offset = 0;
  755. win->palette.b.length = 5;
  756. } else {
  757. /* Set 8bpp or 8bpp and 1bit alpha */
  758. win->palette.r.offset = 16;
  759. win->palette.r.length = 8;
  760. win->palette.g.offset = 8;
  761. win->palette.g.length = 8;
  762. win->palette.b.offset = 0;
  763. win->palette.b.length = 8;
  764. }
  765. /* setup the initial video mode from the window */
  766. fb_videomode_to_var(&fbinfo->var, initmode);
  767. fbinfo->fix.type = FB_TYPE_PACKED_PIXELS;
  768. fbinfo->fix.accel = FB_ACCEL_NONE;
  769. fbinfo->var.activate = FB_ACTIVATE_NOW;
  770. fbinfo->var.vmode = FB_VMODE_NONINTERLACED;
  771. fbinfo->var.bits_per_pixel = windata->default_bpp;
  772. fbinfo->fbops = &s3c_fb_ops;
  773. fbinfo->flags = FBINFO_FLAG_DEFAULT;
  774. fbinfo->pseudo_palette = &win->pseudo_palette;
  775. /* prepare to actually start the framebuffer */
  776. ret = s3c_fb_check_var(&fbinfo->var, fbinfo);
  777. if (ret < 0) {
  778. dev_err(sfb->dev, "check_var failed on initial video params\n");
  779. return ret;
  780. }
  781. /* create initial colour map */
  782. ret = fb_alloc_cmap(&fbinfo->cmap, win->variant.palette_sz, 1);
  783. if (ret == 0)
  784. fb_set_cmap(&fbinfo->cmap, fbinfo);
  785. else
  786. dev_err(sfb->dev, "failed to allocate fb cmap\n");
  787. s3c_fb_set_par(fbinfo);
  788. dev_dbg(sfb->dev, "about to register framebuffer\n");
  789. /* run the check_var and set_par on our configuration. */
  790. ret = register_framebuffer(fbinfo);
  791. if (ret < 0) {
  792. dev_err(sfb->dev, "failed to register framebuffer\n");
  793. return ret;
  794. }
  795. dev_info(sfb->dev, "window %d: fb %s\n", win_no, fbinfo->fix.id);
  796. return 0;
  797. }
  798. /**
  799. * s3c_fb_clear_win() - clear hardware window registers.
  800. * @sfb: The base resources for the hardware.
  801. * @win: The window to process.
  802. *
  803. * Reset the specific window registers to a known state.
  804. */
  805. static void s3c_fb_clear_win(struct s3c_fb *sfb, int win)
  806. {
  807. void __iomem *regs = sfb->regs;
  808. writel(0, regs + sfb->variant.wincon + (win * 4));
  809. writel(0, regs + VIDOSD_A(win, sfb->variant));
  810. writel(0, regs + VIDOSD_B(win, sfb->variant));
  811. writel(0, regs + VIDOSD_C(win, sfb->variant));
  812. }
  813. static int __devinit s3c_fb_probe(struct platform_device *pdev)
  814. {
  815. struct s3c_fb_driverdata *fbdrv;
  816. struct device *dev = &pdev->dev;
  817. struct s3c_fb_platdata *pd;
  818. struct s3c_fb *sfb;
  819. struct resource *res;
  820. int win;
  821. int ret = 0;
  822. fbdrv = (struct s3c_fb_driverdata *)platform_get_device_id(pdev)->driver_data;
  823. if (fbdrv->variant.nr_windows > S3C_FB_MAX_WIN) {
  824. dev_err(dev, "too many windows, cannot attach\n");
  825. return -EINVAL;
  826. }
  827. pd = pdev->dev.platform_data;
  828. if (!pd) {
  829. dev_err(dev, "no platform data specified\n");
  830. return -EINVAL;
  831. }
  832. sfb = kzalloc(sizeof(struct s3c_fb), GFP_KERNEL);
  833. if (!sfb) {
  834. dev_err(dev, "no memory for framebuffers\n");
  835. return -ENOMEM;
  836. }
  837. dev_dbg(dev, "allocate new framebuffer %p\n", sfb);
  838. sfb->dev = dev;
  839. sfb->pdata = pd;
  840. sfb->variant = fbdrv->variant;
  841. sfb->bus_clk = clk_get(dev, "lcd");
  842. if (IS_ERR(sfb->bus_clk)) {
  843. dev_err(dev, "failed to get bus clock\n");
  844. goto err_sfb;
  845. }
  846. clk_enable(sfb->bus_clk);
  847. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  848. if (!res) {
  849. dev_err(dev, "failed to find registers\n");
  850. ret = -ENOENT;
  851. goto err_clk;
  852. }
  853. sfb->regs_res = request_mem_region(res->start, resource_size(res),
  854. dev_name(dev));
  855. if (!sfb->regs_res) {
  856. dev_err(dev, "failed to claim register region\n");
  857. ret = -ENOENT;
  858. goto err_clk;
  859. }
  860. sfb->regs = ioremap(res->start, resource_size(res));
  861. if (!sfb->regs) {
  862. dev_err(dev, "failed to map registers\n");
  863. ret = -ENXIO;
  864. goto err_req_region;
  865. }
  866. dev_dbg(dev, "got resources (regs %p), probing windows\n", sfb->regs);
  867. /* setup gpio and output polarity controls */
  868. pd->setup_gpio();
  869. writel(pd->vidcon1, sfb->regs + VIDCON1);
  870. /* zero all windows before we do anything */
  871. for (win = 0; win < fbdrv->variant.nr_windows; win++)
  872. s3c_fb_clear_win(sfb, win);
  873. /* initialise colour key controls */
  874. for (win = 0; win < (fbdrv->variant.nr_windows - 1); win++) {
  875. void __iomem *regs = sfb->regs + sfb->variant.keycon;
  876. regs += (win * 8);
  877. writel(0xffffff, regs + WKEYCON0);
  878. writel(0xffffff, regs + WKEYCON1);
  879. }
  880. /* we have the register setup, start allocating framebuffers */
  881. for (win = 0; win < fbdrv->variant.nr_windows; win++) {
  882. if (!pd->win[win])
  883. continue;
  884. ret = s3c_fb_probe_win(sfb, win, fbdrv->win[win],
  885. &sfb->windows[win]);
  886. if (ret < 0) {
  887. dev_err(dev, "failed to create window %d\n", win);
  888. for (; win >= 0; win--)
  889. s3c_fb_release_win(sfb, sfb->windows[win]);
  890. goto err_ioremap;
  891. }
  892. }
  893. platform_set_drvdata(pdev, sfb);
  894. return 0;
  895. err_ioremap:
  896. iounmap(sfb->regs);
  897. err_req_region:
  898. release_resource(sfb->regs_res);
  899. kfree(sfb->regs_res);
  900. err_clk:
  901. clk_disable(sfb->bus_clk);
  902. clk_put(sfb->bus_clk);
  903. err_sfb:
  904. kfree(sfb);
  905. return ret;
  906. }
  907. /**
  908. * s3c_fb_remove() - Cleanup on module finalisation
  909. * @pdev: The platform device we are bound to.
  910. *
  911. * Shutdown and then release all the resources that the driver allocated
  912. * on initialisation.
  913. */
  914. static int __devexit s3c_fb_remove(struct platform_device *pdev)
  915. {
  916. struct s3c_fb *sfb = platform_get_drvdata(pdev);
  917. int win;
  918. for (win = 0; win < S3C_FB_MAX_WIN; win++)
  919. if (sfb->windows[win])
  920. s3c_fb_release_win(sfb, sfb->windows[win]);
  921. iounmap(sfb->regs);
  922. clk_disable(sfb->bus_clk);
  923. clk_put(sfb->bus_clk);
  924. release_resource(sfb->regs_res);
  925. kfree(sfb->regs_res);
  926. kfree(sfb);
  927. return 0;
  928. }
  929. #ifdef CONFIG_PM
  930. static int s3c_fb_suspend(struct platform_device *pdev, pm_message_t state)
  931. {
  932. struct s3c_fb *sfb = platform_get_drvdata(pdev);
  933. struct s3c_fb_win *win;
  934. int win_no;
  935. for (win_no = S3C_FB_MAX_WIN - 1; win_no >= 0; win_no--) {
  936. win = sfb->windows[win_no];
  937. if (!win)
  938. continue;
  939. /* use the blank function to push into power-down */
  940. s3c_fb_blank(FB_BLANK_POWERDOWN, win->fbinfo);
  941. }
  942. clk_disable(sfb->bus_clk);
  943. return 0;
  944. }
  945. static int s3c_fb_resume(struct platform_device *pdev)
  946. {
  947. struct s3c_fb *sfb = platform_get_drvdata(pdev);
  948. struct s3c_fb_platdata *pd = sfb->pdata;
  949. struct s3c_fb_win *win;
  950. int win_no;
  951. clk_enable(sfb->bus_clk);
  952. /* setup registers */
  953. writel(pd->vidcon1, sfb->regs + VIDCON1);
  954. /* zero all windows before we do anything */
  955. for (win_no = 0; win_no < sfb->variant.nr_windows; win_no++)
  956. s3c_fb_clear_win(sfb, win_no);
  957. for (win_no = 0; win_no < sfb->variant.nr_windows - 1; win_no++) {
  958. void __iomem *regs = sfb->regs + sfb->variant.keycon;
  959. regs += (win_no * 8);
  960. writel(0xffffff, regs + WKEYCON0);
  961. writel(0xffffff, regs + WKEYCON1);
  962. }
  963. /* restore framebuffers */
  964. for (win_no = 0; win_no < S3C_FB_MAX_WIN; win_no++) {
  965. win = sfb->windows[win_no];
  966. if (!win)
  967. continue;
  968. dev_dbg(&pdev->dev, "resuming window %d\n", win_no);
  969. s3c_fb_set_par(win->fbinfo);
  970. }
  971. return 0;
  972. }
  973. #else
  974. #define s3c_fb_suspend NULL
  975. #define s3c_fb_resume NULL
  976. #endif
  977. #define VALID_BPP124 (VALID_BPP(1) | VALID_BPP(2) | VALID_BPP(4))
  978. #define VALID_BPP1248 (VALID_BPP124 | VALID_BPP(8))
  979. static struct s3c_fb_win_variant s3c_fb_data_64xx_wins[] __devinitdata = {
  980. [0] = {
  981. .has_osd_c = 1,
  982. .palette_sz = 256,
  983. .valid_bpp = VALID_BPP1248 | VALID_BPP(16) | VALID_BPP(24),
  984. },
  985. [1] = {
  986. .has_osd_c = 1,
  987. .has_osd_d = 1,
  988. .palette_sz = 256,
  989. .valid_bpp = (VALID_BPP1248 | VALID_BPP(16) |
  990. VALID_BPP(18) | VALID_BPP(19) |
  991. VALID_BPP(24) | VALID_BPP(25)),
  992. },
  993. [2] = {
  994. .has_osd_c = 1,
  995. .has_osd_d = 1,
  996. .palette_sz = 16,
  997. .palette_16bpp = 1,
  998. .valid_bpp = (VALID_BPP1248 | VALID_BPP(16) |
  999. VALID_BPP(18) | VALID_BPP(19) |
  1000. VALID_BPP(24) | VALID_BPP(25)),
  1001. },
  1002. [3] = {
  1003. .has_osd_c = 1,
  1004. .has_osd_d = 1,
  1005. .palette_sz = 16,
  1006. .palette_16bpp = 1,
  1007. .valid_bpp = (VALID_BPP124 | VALID_BPP(16) |
  1008. VALID_BPP(18) | VALID_BPP(19) |
  1009. VALID_BPP(24) | VALID_BPP(25)),
  1010. },
  1011. [4] = {
  1012. .has_osd_c = 1,
  1013. .palette_sz = 4,
  1014. .palette_16bpp = 1,
  1015. .valid_bpp = (VALID_BPP(1) | VALID_BPP(2) |
  1016. VALID_BPP(16) | VALID_BPP(18) |
  1017. VALID_BPP(24) | VALID_BPP(25)),
  1018. },
  1019. };
  1020. static struct s3c_fb_driverdata s3c_fb_data_64xx __devinitdata = {
  1021. .variant = {
  1022. .nr_windows = 5,
  1023. .vidtcon = VIDTCON0,
  1024. .wincon = WINCON(0),
  1025. .winmap = WINxMAP(0),
  1026. .keycon = WKEYCON,
  1027. .osd = VIDOSD_BASE,
  1028. .osd_stride = 16,
  1029. .buf_start = VIDW_BUF_START(0),
  1030. .buf_size = VIDW_BUF_SIZE(0),
  1031. .buf_end = VIDW_BUF_END(0),
  1032. .palette = {
  1033. [0] = 0x400,
  1034. [1] = 0x800,
  1035. [2] = 0x300,
  1036. [3] = 0x320,
  1037. [4] = 0x340,
  1038. },
  1039. },
  1040. .win[0] = &s3c_fb_data_64xx_wins[0],
  1041. .win[1] = &s3c_fb_data_64xx_wins[1],
  1042. .win[2] = &s3c_fb_data_64xx_wins[2],
  1043. .win[3] = &s3c_fb_data_64xx_wins[3],
  1044. .win[4] = &s3c_fb_data_64xx_wins[4],
  1045. };
  1046. static struct s3c_fb_driverdata s3c_fb_data_s5p __devinitdata = {
  1047. .variant = {
  1048. .nr_windows = 5,
  1049. .vidtcon = VIDTCON0,
  1050. .wincon = WINCON(0),
  1051. .winmap = WINxMAP(0),
  1052. .keycon = WKEYCON,
  1053. .osd = VIDOSD_BASE,
  1054. .osd_stride = 16,
  1055. .buf_start = VIDW_BUF_START(0),
  1056. .buf_size = VIDW_BUF_SIZE(0),
  1057. .buf_end = VIDW_BUF_END(0),
  1058. .palette = {
  1059. [0] = 0x2400,
  1060. [1] = 0x2800,
  1061. [2] = 0x2c00,
  1062. [3] = 0x3000,
  1063. [4] = 0x3400,
  1064. },
  1065. },
  1066. .win[0] = &s3c_fb_data_64xx_wins[0],
  1067. .win[1] = &s3c_fb_data_64xx_wins[1],
  1068. .win[2] = &s3c_fb_data_64xx_wins[2],
  1069. .win[3] = &s3c_fb_data_64xx_wins[3],
  1070. .win[4] = &s3c_fb_data_64xx_wins[4],
  1071. };
  1072. /* S3C2443/S3C2416 style hardware */
  1073. static struct s3c_fb_driverdata s3c_fb_data_s3c2443 __devinitdata = {
  1074. .variant = {
  1075. .nr_windows = 2,
  1076. .is_2443 = 1,
  1077. .vidtcon = 0x08,
  1078. .wincon = 0x14,
  1079. .winmap = 0xd0,
  1080. .keycon = 0xb0,
  1081. .osd = 0x28,
  1082. .osd_stride = 12,
  1083. .buf_start = 0x64,
  1084. .buf_size = 0x94,
  1085. .buf_end = 0x7c,
  1086. .palette = {
  1087. [0] = 0x400,
  1088. [1] = 0x800,
  1089. },
  1090. },
  1091. .win[0] = &(struct s3c_fb_win_variant) {
  1092. .palette_sz = 256,
  1093. .valid_bpp = VALID_BPP1248 | VALID_BPP(16) | VALID_BPP(24),
  1094. },
  1095. .win[1] = &(struct s3c_fb_win_variant) {
  1096. .has_osd_c = 1,
  1097. .palette_sz = 256,
  1098. .valid_bpp = (VALID_BPP1248 | VALID_BPP(16) |
  1099. VALID_BPP(18) | VALID_BPP(19) |
  1100. VALID_BPP(24) | VALID_BPP(25) |
  1101. VALID_BPP(28)),
  1102. },
  1103. };
  1104. static struct platform_device_id s3c_fb_driver_ids[] = {
  1105. {
  1106. .name = "s3c-fb",
  1107. .driver_data = (unsigned long)&s3c_fb_data_64xx,
  1108. }, {
  1109. .name = "s5p-fb",
  1110. .driver_data = (unsigned long)&s3c_fb_data_s5p,
  1111. }, {
  1112. .name = "s3c2443-fb",
  1113. .driver_data = (unsigned long)&s3c_fb_data_s3c2443,
  1114. },
  1115. {},
  1116. };
  1117. MODULE_DEVICE_TABLE(platform, s3c_fb_driver_ids);
  1118. static struct platform_driver s3c_fb_driver = {
  1119. .probe = s3c_fb_probe,
  1120. .remove = __devexit_p(s3c_fb_remove),
  1121. .suspend = s3c_fb_suspend,
  1122. .resume = s3c_fb_resume,
  1123. .id_table = s3c_fb_driver_ids,
  1124. .driver = {
  1125. .name = "s3c-fb",
  1126. .owner = THIS_MODULE,
  1127. },
  1128. };
  1129. static int __init s3c_fb_init(void)
  1130. {
  1131. return platform_driver_register(&s3c_fb_driver);
  1132. }
  1133. static void __exit s3c_fb_cleanup(void)
  1134. {
  1135. platform_driver_unregister(&s3c_fb_driver);
  1136. }
  1137. module_init(s3c_fb_init);
  1138. module_exit(s3c_fb_cleanup);
  1139. MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
  1140. MODULE_DESCRIPTION("Samsung S3C SoC Framebuffer driver");
  1141. MODULE_LICENSE("GPL");
  1142. MODULE_ALIAS("platform:s3c-fb");