acornfb.c 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144
  1. /*
  2. * linux/drivers/video/acornfb.c
  3. *
  4. * Copyright (C) 1998-2001 Russell King
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * Frame buffer code for Acorn platforms
  11. *
  12. * NOTE: Most of the modes with X!=640 will disappear shortly.
  13. * NOTE: Startup setting of HS & VS polarity not supported.
  14. * (do we need to support it if we're coming up in 640x480?)
  15. *
  16. * FIXME: (things broken by the "new improved" FBCON API)
  17. * - Blanking 8bpp displays with VIDC
  18. */
  19. #include <linux/module.h>
  20. #include <linux/kernel.h>
  21. #include <linux/errno.h>
  22. #include <linux/string.h>
  23. #include <linux/ctype.h>
  24. #include <linux/mm.h>
  25. #include <linux/init.h>
  26. #include <linux/fb.h>
  27. #include <linux/platform_device.h>
  28. #include <linux/dma-mapping.h>
  29. #include <linux/io.h>
  30. #include <linux/gfp.h>
  31. #include <mach/hardware.h>
  32. #include <asm/irq.h>
  33. #include <asm/mach-types.h>
  34. #include <asm/pgtable.h>
  35. #include "acornfb.h"
  36. /*
  37. * Default resolution.
  38. * NOTE that it has to be supported in the table towards
  39. * the end of this file.
  40. */
  41. #define DEFAULT_XRES 640
  42. #define DEFAULT_YRES 480
  43. #define DEFAULT_BPP 4
  44. /*
  45. * define this to debug the video mode selection
  46. */
  47. #undef DEBUG_MODE_SELECTION
  48. /*
  49. * Translation from RISC OS monitor types to actual
  50. * HSYNC and VSYNC frequency ranges. These are
  51. * probably not right, but they're the best info I
  52. * have. Allow 1% either way on the nominal for TVs.
  53. */
  54. #define NR_MONTYPES 6
  55. static struct fb_monspecs monspecs[NR_MONTYPES] = {
  56. { /* TV */
  57. .hfmin = 15469,
  58. .hfmax = 15781,
  59. .vfmin = 49,
  60. .vfmax = 51,
  61. }, { /* Multi Freq */
  62. .hfmin = 0,
  63. .hfmax = 99999,
  64. .vfmin = 0,
  65. .vfmax = 199,
  66. }, { /* Hi-res mono */
  67. .hfmin = 58608,
  68. .hfmax = 58608,
  69. .vfmin = 64,
  70. .vfmax = 64,
  71. }, { /* VGA */
  72. .hfmin = 30000,
  73. .hfmax = 70000,
  74. .vfmin = 60,
  75. .vfmax = 60,
  76. }, { /* SVGA */
  77. .hfmin = 30000,
  78. .hfmax = 70000,
  79. .vfmin = 56,
  80. .vfmax = 75,
  81. }, {
  82. .hfmin = 30000,
  83. .hfmax = 70000,
  84. .vfmin = 60,
  85. .vfmax = 60,
  86. }
  87. };
  88. static struct fb_info fb_info;
  89. static struct acornfb_par current_par;
  90. static struct vidc_timing current_vidc;
  91. extern unsigned int vram_size; /* set by setup.c */
  92. #ifdef HAS_VIDC20
  93. #include <mach/acornfb.h>
  94. #define MAX_SIZE 2*1024*1024
  95. /* VIDC20 has a different set of rules from the VIDC:
  96. * hcr : must be multiple of 4
  97. * hswr : must be even
  98. * hdsr : must be even
  99. * hder : must be even
  100. * vcr : >= 2, (interlace, must be odd)
  101. * vswr : >= 1
  102. * vdsr : >= 1
  103. * vder : >= vdsr
  104. */
  105. static void acornfb_set_timing(struct fb_info *info)
  106. {
  107. struct fb_var_screeninfo *var = &info->var;
  108. struct vidc_timing vidc;
  109. u_int vcr, fsize;
  110. u_int ext_ctl, dat_ctl;
  111. u_int words_per_line;
  112. memset(&vidc, 0, sizeof(vidc));
  113. vidc.h_sync_width = var->hsync_len - 8;
  114. vidc.h_border_start = vidc.h_sync_width + var->left_margin + 8 - 12;
  115. vidc.h_display_start = vidc.h_border_start + 12 - 18;
  116. vidc.h_display_end = vidc.h_display_start + var->xres;
  117. vidc.h_border_end = vidc.h_display_end + 18 - 12;
  118. vidc.h_cycle = vidc.h_border_end + var->right_margin + 12 - 8;
  119. vidc.h_interlace = vidc.h_cycle / 2;
  120. vidc.v_sync_width = var->vsync_len - 1;
  121. vidc.v_border_start = vidc.v_sync_width + var->upper_margin;
  122. vidc.v_display_start = vidc.v_border_start;
  123. vidc.v_display_end = vidc.v_display_start + var->yres;
  124. vidc.v_border_end = vidc.v_display_end;
  125. vidc.control = acornfb_default_control();
  126. vcr = var->vsync_len + var->upper_margin + var->yres +
  127. var->lower_margin;
  128. if ((var->vmode & FB_VMODE_MASK) == FB_VMODE_INTERLACED) {
  129. vidc.v_cycle = (vcr - 3) / 2;
  130. vidc.control |= VIDC20_CTRL_INT;
  131. } else
  132. vidc.v_cycle = vcr - 2;
  133. switch (var->bits_per_pixel) {
  134. case 1: vidc.control |= VIDC20_CTRL_1BPP; break;
  135. case 2: vidc.control |= VIDC20_CTRL_2BPP; break;
  136. case 4: vidc.control |= VIDC20_CTRL_4BPP; break;
  137. default:
  138. case 8: vidc.control |= VIDC20_CTRL_8BPP; break;
  139. case 16: vidc.control |= VIDC20_CTRL_16BPP; break;
  140. case 32: vidc.control |= VIDC20_CTRL_32BPP; break;
  141. }
  142. acornfb_vidc20_find_rates(&vidc, var);
  143. fsize = var->vsync_len + var->upper_margin + var->lower_margin - 1;
  144. if (memcmp(&current_vidc, &vidc, sizeof(vidc))) {
  145. current_vidc = vidc;
  146. vidc_writel(VIDC20_CTRL| vidc.control);
  147. vidc_writel(0xd0000000 | vidc.pll_ctl);
  148. vidc_writel(0x80000000 | vidc.h_cycle);
  149. vidc_writel(0x81000000 | vidc.h_sync_width);
  150. vidc_writel(0x82000000 | vidc.h_border_start);
  151. vidc_writel(0x83000000 | vidc.h_display_start);
  152. vidc_writel(0x84000000 | vidc.h_display_end);
  153. vidc_writel(0x85000000 | vidc.h_border_end);
  154. vidc_writel(0x86000000);
  155. vidc_writel(0x87000000 | vidc.h_interlace);
  156. vidc_writel(0x90000000 | vidc.v_cycle);
  157. vidc_writel(0x91000000 | vidc.v_sync_width);
  158. vidc_writel(0x92000000 | vidc.v_border_start);
  159. vidc_writel(0x93000000 | vidc.v_display_start);
  160. vidc_writel(0x94000000 | vidc.v_display_end);
  161. vidc_writel(0x95000000 | vidc.v_border_end);
  162. vidc_writel(0x96000000);
  163. vidc_writel(0x97000000);
  164. }
  165. iomd_writel(fsize, IOMD_FSIZE);
  166. ext_ctl = acornfb_default_econtrol();
  167. if (var->sync & FB_SYNC_COMP_HIGH_ACT) /* should be FB_SYNC_COMP */
  168. ext_ctl |= VIDC20_ECTL_HS_NCSYNC | VIDC20_ECTL_VS_NCSYNC;
  169. else {
  170. if (var->sync & FB_SYNC_HOR_HIGH_ACT)
  171. ext_ctl |= VIDC20_ECTL_HS_HSYNC;
  172. else
  173. ext_ctl |= VIDC20_ECTL_HS_NHSYNC;
  174. if (var->sync & FB_SYNC_VERT_HIGH_ACT)
  175. ext_ctl |= VIDC20_ECTL_VS_VSYNC;
  176. else
  177. ext_ctl |= VIDC20_ECTL_VS_NVSYNC;
  178. }
  179. vidc_writel(VIDC20_ECTL | ext_ctl);
  180. words_per_line = var->xres * var->bits_per_pixel / 32;
  181. if (current_par.using_vram && info->fix.smem_len == 2048*1024)
  182. words_per_line /= 2;
  183. /* RiscPC doesn't use the VIDC's VRAM control. */
  184. dat_ctl = VIDC20_DCTL_VRAM_DIS | VIDC20_DCTL_SNA | words_per_line;
  185. /* The data bus width is dependent on both the type
  186. * and amount of video memory.
  187. * DRAM 32bit low
  188. * 1MB VRAM 32bit
  189. * 2MB VRAM 64bit
  190. */
  191. if (current_par.using_vram && current_par.vram_half_sam == 2048)
  192. dat_ctl |= VIDC20_DCTL_BUS_D63_0;
  193. else
  194. dat_ctl |= VIDC20_DCTL_BUS_D31_0;
  195. vidc_writel(VIDC20_DCTL | dat_ctl);
  196. #ifdef DEBUG_MODE_SELECTION
  197. printk(KERN_DEBUG "VIDC registers for %dx%dx%d:\n", var->xres,
  198. var->yres, var->bits_per_pixel);
  199. printk(KERN_DEBUG " H-cycle : %d\n", vidc.h_cycle);
  200. printk(KERN_DEBUG " H-sync-width : %d\n", vidc.h_sync_width);
  201. printk(KERN_DEBUG " H-border-start : %d\n", vidc.h_border_start);
  202. printk(KERN_DEBUG " H-display-start : %d\n", vidc.h_display_start);
  203. printk(KERN_DEBUG " H-display-end : %d\n", vidc.h_display_end);
  204. printk(KERN_DEBUG " H-border-end : %d\n", vidc.h_border_end);
  205. printk(KERN_DEBUG " H-interlace : %d\n", vidc.h_interlace);
  206. printk(KERN_DEBUG " V-cycle : %d\n", vidc.v_cycle);
  207. printk(KERN_DEBUG " V-sync-width : %d\n", vidc.v_sync_width);
  208. printk(KERN_DEBUG " V-border-start : %d\n", vidc.v_border_start);
  209. printk(KERN_DEBUG " V-display-start : %d\n", vidc.v_display_start);
  210. printk(KERN_DEBUG " V-display-end : %d\n", vidc.v_display_end);
  211. printk(KERN_DEBUG " V-border-end : %d\n", vidc.v_border_end);
  212. printk(KERN_DEBUG " Ext Ctrl (C) : 0x%08X\n", ext_ctl);
  213. printk(KERN_DEBUG " PLL Ctrl (D) : 0x%08X\n", vidc.pll_ctl);
  214. printk(KERN_DEBUG " Ctrl (E) : 0x%08X\n", vidc.control);
  215. printk(KERN_DEBUG " Data Ctrl (F) : 0x%08X\n", dat_ctl);
  216. printk(KERN_DEBUG " Fsize : 0x%08X\n", fsize);
  217. #endif
  218. }
  219. /*
  220. * We have to take note of the VIDC20's 16-bit palette here.
  221. * The VIDC20 looks up a 16 bit pixel as follows:
  222. *
  223. * bits 111111
  224. * 5432109876543210
  225. * red ++++++++ (8 bits, 7 to 0)
  226. * green ++++++++ (8 bits, 11 to 4)
  227. * blue ++++++++ (8 bits, 15 to 8)
  228. *
  229. * We use a pixel which looks like:
  230. *
  231. * bits 111111
  232. * 5432109876543210
  233. * red +++++ (5 bits, 4 to 0)
  234. * green +++++ (5 bits, 9 to 5)
  235. * blue +++++ (5 bits, 14 to 10)
  236. */
  237. static int
  238. acornfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
  239. u_int trans, struct fb_info *info)
  240. {
  241. union palette pal;
  242. if (regno >= current_par.palette_size)
  243. return 1;
  244. if (regno < 16 && info->fix.visual == FB_VISUAL_DIRECTCOLOR) {
  245. u32 pseudo_val;
  246. pseudo_val = regno << info->var.red.offset;
  247. pseudo_val |= regno << info->var.green.offset;
  248. pseudo_val |= regno << info->var.blue.offset;
  249. ((u32 *)info->pseudo_palette)[regno] = pseudo_val;
  250. }
  251. pal.p = 0;
  252. pal.vidc20.red = red >> 8;
  253. pal.vidc20.green = green >> 8;
  254. pal.vidc20.blue = blue >> 8;
  255. current_par.palette[regno] = pal;
  256. if (info->var.bits_per_pixel == 16) {
  257. int i;
  258. pal.p = 0;
  259. vidc_writel(0x10000000);
  260. for (i = 0; i < 256; i += 1) {
  261. pal.vidc20.red = current_par.palette[ i & 31].vidc20.red;
  262. pal.vidc20.green = current_par.palette[(i >> 1) & 31].vidc20.green;
  263. pal.vidc20.blue = current_par.palette[(i >> 2) & 31].vidc20.blue;
  264. vidc_writel(pal.p);
  265. /* Palette register pointer auto-increments */
  266. }
  267. } else {
  268. vidc_writel(0x10000000 | regno);
  269. vidc_writel(pal.p);
  270. }
  271. return 0;
  272. }
  273. #endif
  274. /*
  275. * Before selecting the timing parameters, adjust
  276. * the resolution to fit the rules.
  277. */
  278. static int
  279. acornfb_adjust_timing(struct fb_info *info, struct fb_var_screeninfo *var, u_int fontht)
  280. {
  281. u_int font_line_len, sam_size, min_size, size, nr_y;
  282. /* xres must be even */
  283. var->xres = (var->xres + 1) & ~1;
  284. /*
  285. * We don't allow xres_virtual to differ from xres
  286. */
  287. var->xres_virtual = var->xres;
  288. var->xoffset = 0;
  289. if (current_par.using_vram)
  290. sam_size = current_par.vram_half_sam * 2;
  291. else
  292. sam_size = 16;
  293. /*
  294. * Now, find a value for yres_virtual which allows
  295. * us to do ywrap scrolling. The value of
  296. * yres_virtual must be such that the end of the
  297. * displayable frame buffer must be aligned with
  298. * the start of a font line.
  299. */
  300. font_line_len = var->xres * var->bits_per_pixel * fontht / 8;
  301. min_size = var->xres * var->yres * var->bits_per_pixel / 8;
  302. /*
  303. * If minimum screen size is greater than that we have
  304. * available, reject it.
  305. */
  306. if (min_size > info->fix.smem_len)
  307. return -EINVAL;
  308. /* Find int 'y', such that y * fll == s * sam < maxsize
  309. * y = s * sam / fll; s = maxsize / sam
  310. */
  311. for (size = info->fix.smem_len;
  312. nr_y = size / font_line_len, min_size <= size;
  313. size -= sam_size) {
  314. if (nr_y * font_line_len == size)
  315. break;
  316. }
  317. nr_y *= fontht;
  318. if (var->accel_flags & FB_ACCELF_TEXT) {
  319. if (min_size > size) {
  320. /*
  321. * failed, use ypan
  322. */
  323. size = info->fix.smem_len;
  324. var->yres_virtual = size / (font_line_len / fontht);
  325. } else
  326. var->yres_virtual = nr_y;
  327. } else if (var->yres_virtual > nr_y)
  328. var->yres_virtual = nr_y;
  329. current_par.screen_end = info->fix.smem_start + size;
  330. /*
  331. * Fix yres & yoffset if needed.
  332. */
  333. if (var->yres > var->yres_virtual)
  334. var->yres = var->yres_virtual;
  335. if (var->vmode & FB_VMODE_YWRAP) {
  336. if (var->yoffset > var->yres_virtual)
  337. var->yoffset = var->yres_virtual;
  338. } else {
  339. if (var->yoffset + var->yres > var->yres_virtual)
  340. var->yoffset = var->yres_virtual - var->yres;
  341. }
  342. /* hsync_len must be even */
  343. var->hsync_len = (var->hsync_len + 1) & ~1;
  344. #if defined(HAS_VIDC20)
  345. /* left_margin must be even */
  346. if (var->left_margin & 1) {
  347. var->left_margin += 1;
  348. var->right_margin -= 1;
  349. }
  350. /* right_margin must be even */
  351. if (var->right_margin & 1)
  352. var->right_margin += 1;
  353. #endif
  354. if (var->vsync_len < 1)
  355. var->vsync_len = 1;
  356. return 0;
  357. }
  358. static int
  359. acornfb_validate_timing(struct fb_var_screeninfo *var,
  360. struct fb_monspecs *monspecs)
  361. {
  362. unsigned long hs, vs;
  363. /*
  364. * hs(Hz) = 10^12 / (pixclock * xtotal)
  365. * vs(Hz) = hs(Hz) / ytotal
  366. *
  367. * No need to do long long divisions or anything
  368. * like that if you factor it correctly
  369. */
  370. hs = 1953125000 / var->pixclock;
  371. hs = hs * 512 /
  372. (var->xres + var->left_margin + var->right_margin + var->hsync_len);
  373. vs = hs /
  374. (var->yres + var->upper_margin + var->lower_margin + var->vsync_len);
  375. return (vs >= monspecs->vfmin && vs <= monspecs->vfmax &&
  376. hs >= monspecs->hfmin && hs <= monspecs->hfmax) ? 0 : -EINVAL;
  377. }
  378. static inline void
  379. acornfb_update_dma(struct fb_info *info, struct fb_var_screeninfo *var)
  380. {
  381. u_int off = var->yoffset * info->fix.line_length;
  382. #if defined(HAS_MEMC)
  383. memc_write(VDMA_INIT, off >> 2);
  384. #elif defined(HAS_IOMD)
  385. iomd_writel(info->fix.smem_start + off, IOMD_VIDINIT);
  386. #endif
  387. }
  388. static int
  389. acornfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
  390. {
  391. u_int fontht;
  392. int err;
  393. /*
  394. * FIXME: Find the font height
  395. */
  396. fontht = 8;
  397. var->red.msb_right = 0;
  398. var->green.msb_right = 0;
  399. var->blue.msb_right = 0;
  400. var->transp.msb_right = 0;
  401. switch (var->bits_per_pixel) {
  402. case 1: case 2: case 4: case 8:
  403. var->red.offset = 0;
  404. var->red.length = var->bits_per_pixel;
  405. var->green = var->red;
  406. var->blue = var->red;
  407. var->transp.offset = 0;
  408. var->transp.length = 0;
  409. break;
  410. #ifdef HAS_VIDC20
  411. case 16:
  412. var->red.offset = 0;
  413. var->red.length = 5;
  414. var->green.offset = 5;
  415. var->green.length = 5;
  416. var->blue.offset = 10;
  417. var->blue.length = 5;
  418. var->transp.offset = 15;
  419. var->transp.length = 1;
  420. break;
  421. case 32:
  422. var->red.offset = 0;
  423. var->red.length = 8;
  424. var->green.offset = 8;
  425. var->green.length = 8;
  426. var->blue.offset = 16;
  427. var->blue.length = 8;
  428. var->transp.offset = 24;
  429. var->transp.length = 4;
  430. break;
  431. #endif
  432. default:
  433. return -EINVAL;
  434. }
  435. /*
  436. * Check to see if the pixel rate is valid.
  437. */
  438. if (!acornfb_valid_pixrate(var))
  439. return -EINVAL;
  440. /*
  441. * Validate and adjust the resolution to
  442. * match the video generator hardware.
  443. */
  444. err = acornfb_adjust_timing(info, var, fontht);
  445. if (err)
  446. return err;
  447. /*
  448. * Validate the timing against the
  449. * monitor hardware.
  450. */
  451. return acornfb_validate_timing(var, &info->monspecs);
  452. }
  453. static int acornfb_set_par(struct fb_info *info)
  454. {
  455. switch (info->var.bits_per_pixel) {
  456. case 1:
  457. current_par.palette_size = 2;
  458. info->fix.visual = FB_VISUAL_MONO10;
  459. break;
  460. case 2:
  461. current_par.palette_size = 4;
  462. info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
  463. break;
  464. case 4:
  465. current_par.palette_size = 16;
  466. info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
  467. break;
  468. case 8:
  469. current_par.palette_size = VIDC_PALETTE_SIZE;
  470. info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
  471. break;
  472. #ifdef HAS_VIDC20
  473. case 16:
  474. current_par.palette_size = 32;
  475. info->fix.visual = FB_VISUAL_DIRECTCOLOR;
  476. break;
  477. case 32:
  478. current_par.palette_size = VIDC_PALETTE_SIZE;
  479. info->fix.visual = FB_VISUAL_DIRECTCOLOR;
  480. break;
  481. #endif
  482. default:
  483. BUG();
  484. }
  485. info->fix.line_length = (info->var.xres * info->var.bits_per_pixel) / 8;
  486. #if defined(HAS_MEMC)
  487. {
  488. unsigned long size = info->fix.smem_len - VDMA_XFERSIZE;
  489. memc_write(VDMA_START, 0);
  490. memc_write(VDMA_END, size >> 2);
  491. }
  492. #elif defined(HAS_IOMD)
  493. {
  494. unsigned long start, size;
  495. u_int control;
  496. start = info->fix.smem_start;
  497. size = current_par.screen_end;
  498. if (current_par.using_vram) {
  499. size -= current_par.vram_half_sam;
  500. control = DMA_CR_E | (current_par.vram_half_sam / 256);
  501. } else {
  502. size -= 16;
  503. control = DMA_CR_E | DMA_CR_D | 16;
  504. }
  505. iomd_writel(start, IOMD_VIDSTART);
  506. iomd_writel(size, IOMD_VIDEND);
  507. iomd_writel(control, IOMD_VIDCR);
  508. }
  509. #endif
  510. acornfb_update_dma(info, &info->var);
  511. acornfb_set_timing(info);
  512. return 0;
  513. }
  514. static int
  515. acornfb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
  516. {
  517. u_int y_bottom = var->yoffset;
  518. if (!(var->vmode & FB_VMODE_YWRAP))
  519. y_bottom += info->var.yres;
  520. if (y_bottom > info->var.yres_virtual)
  521. return -EINVAL;
  522. acornfb_update_dma(info, var);
  523. return 0;
  524. }
  525. static struct fb_ops acornfb_ops = {
  526. .owner = THIS_MODULE,
  527. .fb_check_var = acornfb_check_var,
  528. .fb_set_par = acornfb_set_par,
  529. .fb_setcolreg = acornfb_setcolreg,
  530. .fb_pan_display = acornfb_pan_display,
  531. .fb_fillrect = cfb_fillrect,
  532. .fb_copyarea = cfb_copyarea,
  533. .fb_imageblit = cfb_imageblit,
  534. };
  535. /*
  536. * Everything after here is initialisation!!!
  537. */
  538. static struct fb_videomode modedb[] = {
  539. { /* 320x256 @ 50Hz */
  540. NULL, 50, 320, 256, 125000, 92, 62, 35, 19, 38, 2,
  541. FB_SYNC_COMP_HIGH_ACT,
  542. FB_VMODE_NONINTERLACED
  543. }, { /* 640x250 @ 50Hz, 15.6 kHz hsync */
  544. NULL, 50, 640, 250, 62500, 185, 123, 38, 21, 76, 3,
  545. 0,
  546. FB_VMODE_NONINTERLACED
  547. }, { /* 640x256 @ 50Hz, 15.6 kHz hsync */
  548. NULL, 50, 640, 256, 62500, 185, 123, 35, 18, 76, 3,
  549. 0,
  550. FB_VMODE_NONINTERLACED
  551. }, { /* 640x512 @ 50Hz, 26.8 kHz hsync */
  552. NULL, 50, 640, 512, 41667, 113, 87, 18, 1, 56, 3,
  553. 0,
  554. FB_VMODE_NONINTERLACED
  555. }, { /* 640x250 @ 70Hz, 31.5 kHz hsync */
  556. NULL, 70, 640, 250, 39722, 48, 16, 109, 88, 96, 2,
  557. 0,
  558. FB_VMODE_NONINTERLACED
  559. }, { /* 640x256 @ 70Hz, 31.5 kHz hsync */
  560. NULL, 70, 640, 256, 39722, 48, 16, 106, 85, 96, 2,
  561. 0,
  562. FB_VMODE_NONINTERLACED
  563. }, { /* 640x352 @ 70Hz, 31.5 kHz hsync */
  564. NULL, 70, 640, 352, 39722, 48, 16, 58, 37, 96, 2,
  565. 0,
  566. FB_VMODE_NONINTERLACED
  567. }, { /* 640x480 @ 60Hz, 31.5 kHz hsync */
  568. NULL, 60, 640, 480, 39722, 48, 16, 32, 11, 96, 2,
  569. 0,
  570. FB_VMODE_NONINTERLACED
  571. }, { /* 800x600 @ 56Hz, 35.2 kHz hsync */
  572. NULL, 56, 800, 600, 27778, 101, 23, 22, 1, 100, 2,
  573. 0,
  574. FB_VMODE_NONINTERLACED
  575. }, { /* 896x352 @ 60Hz, 21.8 kHz hsync */
  576. NULL, 60, 896, 352, 41667, 59, 27, 9, 0, 118, 3,
  577. 0,
  578. FB_VMODE_NONINTERLACED
  579. }, { /* 1024x 768 @ 60Hz, 48.4 kHz hsync */
  580. NULL, 60, 1024, 768, 15385, 160, 24, 29, 3, 136, 6,
  581. 0,
  582. FB_VMODE_NONINTERLACED
  583. }, { /* 1280x1024 @ 60Hz, 63.8 kHz hsync */
  584. NULL, 60, 1280, 1024, 9090, 186, 96, 38, 1, 160, 3,
  585. 0,
  586. FB_VMODE_NONINTERLACED
  587. }
  588. };
  589. static struct fb_videomode acornfb_default_mode = {
  590. .name = NULL,
  591. .refresh = 60,
  592. .xres = 640,
  593. .yres = 480,
  594. .pixclock = 39722,
  595. .left_margin = 56,
  596. .right_margin = 16,
  597. .upper_margin = 34,
  598. .lower_margin = 9,
  599. .hsync_len = 88,
  600. .vsync_len = 2,
  601. .sync = 0,
  602. .vmode = FB_VMODE_NONINTERLACED
  603. };
  604. static void acornfb_init_fbinfo(void)
  605. {
  606. static int first = 1;
  607. if (!first)
  608. return;
  609. first = 0;
  610. fb_info.fbops = &acornfb_ops;
  611. fb_info.flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
  612. fb_info.pseudo_palette = current_par.pseudo_palette;
  613. strcpy(fb_info.fix.id, "Acorn");
  614. fb_info.fix.type = FB_TYPE_PACKED_PIXELS;
  615. fb_info.fix.type_aux = 0;
  616. fb_info.fix.xpanstep = 0;
  617. fb_info.fix.ypanstep = 1;
  618. fb_info.fix.ywrapstep = 1;
  619. fb_info.fix.line_length = 0;
  620. fb_info.fix.accel = FB_ACCEL_NONE;
  621. /*
  622. * setup initial parameters
  623. */
  624. memset(&fb_info.var, 0, sizeof(fb_info.var));
  625. #if defined(HAS_VIDC20)
  626. fb_info.var.red.length = 8;
  627. fb_info.var.transp.length = 4;
  628. #endif
  629. fb_info.var.green = fb_info.var.red;
  630. fb_info.var.blue = fb_info.var.red;
  631. fb_info.var.nonstd = 0;
  632. fb_info.var.activate = FB_ACTIVATE_NOW;
  633. fb_info.var.height = -1;
  634. fb_info.var.width = -1;
  635. fb_info.var.vmode = FB_VMODE_NONINTERLACED;
  636. fb_info.var.accel_flags = FB_ACCELF_TEXT;
  637. current_par.dram_size = 0;
  638. current_par.montype = -1;
  639. current_par.dpms = 0;
  640. }
  641. /*
  642. * setup acornfb options:
  643. *
  644. * mon:hmin-hmax:vmin-vmax:dpms:width:height
  645. * Set monitor parameters:
  646. * hmin = horizontal minimum frequency (Hz)
  647. * hmax = horizontal maximum frequency (Hz) (optional)
  648. * vmin = vertical minimum frequency (Hz)
  649. * vmax = vertical maximum frequency (Hz) (optional)
  650. * dpms = DPMS supported? (optional)
  651. * width = width of picture in mm. (optional)
  652. * height = height of picture in mm. (optional)
  653. *
  654. * montype:type
  655. * Set RISC-OS style monitor type:
  656. * 0 (or tv) - TV frequency
  657. * 1 (or multi) - Multi frequency
  658. * 2 (or hires) - Hi-res monochrome
  659. * 3 (or vga) - VGA
  660. * 4 (or svga) - SVGA
  661. * auto, or option missing
  662. * - try hardware detect
  663. *
  664. * dram:size
  665. * Set the amount of DRAM to use for the frame buffer
  666. * (even if you have VRAM).
  667. * size can optionally be followed by 'M' or 'K' for
  668. * MB or KB respectively.
  669. */
  670. static void acornfb_parse_mon(char *opt)
  671. {
  672. char *p = opt;
  673. current_par.montype = -2;
  674. fb_info.monspecs.hfmin = simple_strtoul(p, &p, 0);
  675. if (*p == '-')
  676. fb_info.monspecs.hfmax = simple_strtoul(p + 1, &p, 0);
  677. else
  678. fb_info.monspecs.hfmax = fb_info.monspecs.hfmin;
  679. if (*p != ':')
  680. goto bad;
  681. fb_info.monspecs.vfmin = simple_strtoul(p + 1, &p, 0);
  682. if (*p == '-')
  683. fb_info.monspecs.vfmax = simple_strtoul(p + 1, &p, 0);
  684. else
  685. fb_info.monspecs.vfmax = fb_info.monspecs.vfmin;
  686. if (*p != ':')
  687. goto check_values;
  688. fb_info.monspecs.dpms = simple_strtoul(p + 1, &p, 0);
  689. if (*p != ':')
  690. goto check_values;
  691. fb_info.var.width = simple_strtoul(p + 1, &p, 0);
  692. if (*p != ':')
  693. goto check_values;
  694. fb_info.var.height = simple_strtoul(p + 1, NULL, 0);
  695. check_values:
  696. if (fb_info.monspecs.hfmax < fb_info.monspecs.hfmin ||
  697. fb_info.monspecs.vfmax < fb_info.monspecs.vfmin)
  698. goto bad;
  699. return;
  700. bad:
  701. printk(KERN_ERR "Acornfb: bad monitor settings: %s\n", opt);
  702. current_par.montype = -1;
  703. }
  704. static void acornfb_parse_montype(char *opt)
  705. {
  706. current_par.montype = -2;
  707. if (strncmp(opt, "tv", 2) == 0) {
  708. opt += 2;
  709. current_par.montype = 0;
  710. } else if (strncmp(opt, "multi", 5) == 0) {
  711. opt += 5;
  712. current_par.montype = 1;
  713. } else if (strncmp(opt, "hires", 5) == 0) {
  714. opt += 5;
  715. current_par.montype = 2;
  716. } else if (strncmp(opt, "vga", 3) == 0) {
  717. opt += 3;
  718. current_par.montype = 3;
  719. } else if (strncmp(opt, "svga", 4) == 0) {
  720. opt += 4;
  721. current_par.montype = 4;
  722. } else if (strncmp(opt, "auto", 4) == 0) {
  723. opt += 4;
  724. current_par.montype = -1;
  725. } else if (isdigit(*opt))
  726. current_par.montype = simple_strtoul(opt, &opt, 0);
  727. if (current_par.montype == -2 ||
  728. current_par.montype > NR_MONTYPES) {
  729. printk(KERN_ERR "acornfb: unknown monitor type: %s\n",
  730. opt);
  731. current_par.montype = -1;
  732. } else
  733. if (opt && *opt) {
  734. if (strcmp(opt, ",dpms") == 0)
  735. current_par.dpms = 1;
  736. else
  737. printk(KERN_ERR
  738. "acornfb: unknown monitor option: %s\n",
  739. opt);
  740. }
  741. }
  742. static void acornfb_parse_dram(char *opt)
  743. {
  744. unsigned int size;
  745. size = simple_strtoul(opt, &opt, 0);
  746. if (opt) {
  747. switch (*opt) {
  748. case 'M':
  749. case 'm':
  750. size *= 1024;
  751. case 'K':
  752. case 'k':
  753. size *= 1024;
  754. default:
  755. break;
  756. }
  757. }
  758. current_par.dram_size = size;
  759. }
  760. static struct options {
  761. char *name;
  762. void (*parse)(char *opt);
  763. } opt_table[] = {
  764. { "mon", acornfb_parse_mon },
  765. { "montype", acornfb_parse_montype },
  766. { "dram", acornfb_parse_dram },
  767. { NULL, NULL }
  768. };
  769. static int acornfb_setup(char *options)
  770. {
  771. struct options *optp;
  772. char *opt;
  773. if (!options || !*options)
  774. return 0;
  775. acornfb_init_fbinfo();
  776. while ((opt = strsep(&options, ",")) != NULL) {
  777. if (!*opt)
  778. continue;
  779. for (optp = opt_table; optp->name; optp++) {
  780. int optlen;
  781. optlen = strlen(optp->name);
  782. if (strncmp(opt, optp->name, optlen) == 0 &&
  783. opt[optlen] == ':') {
  784. optp->parse(opt + optlen + 1);
  785. break;
  786. }
  787. }
  788. if (!optp->name)
  789. printk(KERN_ERR "acornfb: unknown parameter: %s\n",
  790. opt);
  791. }
  792. return 0;
  793. }
  794. /*
  795. * Detect type of monitor connected
  796. * For now, we just assume SVGA
  797. */
  798. static int acornfb_detect_monitortype(void)
  799. {
  800. return 4;
  801. }
  802. /*
  803. * This enables the unused memory to be freed on older Acorn machines.
  804. * We are freeing memory on behalf of the architecture initialisation
  805. * code here.
  806. */
  807. static inline void
  808. free_unused_pages(unsigned int virtual_start, unsigned int virtual_end)
  809. {
  810. int mb_freed = 0;
  811. /*
  812. * Align addresses
  813. */
  814. virtual_start = PAGE_ALIGN(virtual_start);
  815. virtual_end = PAGE_ALIGN(virtual_end);
  816. while (virtual_start < virtual_end) {
  817. struct page *page;
  818. /*
  819. * Clear page reserved bit,
  820. * set count to 1, and free
  821. * the page.
  822. */
  823. page = virt_to_page(virtual_start);
  824. __free_reserved_page(page);
  825. virtual_start += PAGE_SIZE;
  826. mb_freed += PAGE_SIZE / 1024;
  827. }
  828. printk("acornfb: freed %dK memory\n", mb_freed);
  829. }
  830. static int acornfb_probe(struct platform_device *dev)
  831. {
  832. unsigned long size;
  833. u_int h_sync, v_sync;
  834. int rc, i;
  835. char *option = NULL;
  836. if (fb_get_options("acornfb", &option))
  837. return -ENODEV;
  838. acornfb_setup(option);
  839. acornfb_init_fbinfo();
  840. current_par.dev = &dev->dev;
  841. if (current_par.montype == -1)
  842. current_par.montype = acornfb_detect_monitortype();
  843. if (current_par.montype == -1 || current_par.montype > NR_MONTYPES)
  844. current_par.montype = 4;
  845. if (current_par.montype >= 0) {
  846. fb_info.monspecs = monspecs[current_par.montype];
  847. fb_info.monspecs.dpms = current_par.dpms;
  848. }
  849. /*
  850. * Try to select a suitable default mode
  851. */
  852. for (i = 0; i < ARRAY_SIZE(modedb); i++) {
  853. unsigned long hs;
  854. hs = modedb[i].refresh *
  855. (modedb[i].yres + modedb[i].upper_margin +
  856. modedb[i].lower_margin + modedb[i].vsync_len);
  857. if (modedb[i].xres == DEFAULT_XRES &&
  858. modedb[i].yres == DEFAULT_YRES &&
  859. modedb[i].refresh >= fb_info.monspecs.vfmin &&
  860. modedb[i].refresh <= fb_info.monspecs.vfmax &&
  861. hs >= fb_info.monspecs.hfmin &&
  862. hs <= fb_info.monspecs.hfmax) {
  863. acornfb_default_mode = modedb[i];
  864. break;
  865. }
  866. }
  867. fb_info.screen_base = (char *)SCREEN_BASE;
  868. fb_info.fix.smem_start = SCREEN_START;
  869. current_par.using_vram = 0;
  870. /*
  871. * If vram_size is set, we are using VRAM in
  872. * a Risc PC. However, if the user has specified
  873. * an amount of DRAM then use that instead.
  874. */
  875. if (vram_size && !current_par.dram_size) {
  876. size = vram_size;
  877. current_par.vram_half_sam = vram_size / 1024;
  878. current_par.using_vram = 1;
  879. } else if (current_par.dram_size)
  880. size = current_par.dram_size;
  881. else
  882. size = MAX_SIZE;
  883. /*
  884. * Limit maximum screen size.
  885. */
  886. if (size > MAX_SIZE)
  887. size = MAX_SIZE;
  888. size = PAGE_ALIGN(size);
  889. #if defined(HAS_VIDC20)
  890. if (!current_par.using_vram) {
  891. dma_addr_t handle;
  892. void *base;
  893. /*
  894. * RiscPC needs to allocate the DRAM memory
  895. * for the framebuffer if we are not using
  896. * VRAM.
  897. */
  898. base = dma_alloc_writecombine(current_par.dev, size, &handle,
  899. GFP_KERNEL);
  900. if (base == NULL) {
  901. printk(KERN_ERR "acornfb: unable to allocate screen "
  902. "memory\n");
  903. return -ENOMEM;
  904. }
  905. fb_info.screen_base = base;
  906. fb_info.fix.smem_start = handle;
  907. }
  908. #endif
  909. fb_info.fix.smem_len = size;
  910. current_par.palette_size = VIDC_PALETTE_SIZE;
  911. /*
  912. * Lookup the timing for this resolution. If we can't
  913. * find it, then we can't restore it if we change
  914. * the resolution, so we disable this feature.
  915. */
  916. do {
  917. rc = fb_find_mode(&fb_info.var, &fb_info, NULL, modedb,
  918. ARRAY_SIZE(modedb),
  919. &acornfb_default_mode, DEFAULT_BPP);
  920. /*
  921. * If we found an exact match, all ok.
  922. */
  923. if (rc == 1)
  924. break;
  925. rc = fb_find_mode(&fb_info.var, &fb_info, NULL, NULL, 0,
  926. &acornfb_default_mode, DEFAULT_BPP);
  927. /*
  928. * If we found an exact match, all ok.
  929. */
  930. if (rc == 1)
  931. break;
  932. rc = fb_find_mode(&fb_info.var, &fb_info, NULL, modedb,
  933. ARRAY_SIZE(modedb),
  934. &acornfb_default_mode, DEFAULT_BPP);
  935. if (rc)
  936. break;
  937. rc = fb_find_mode(&fb_info.var, &fb_info, NULL, NULL, 0,
  938. &acornfb_default_mode, DEFAULT_BPP);
  939. } while (0);
  940. /*
  941. * If we didn't find an exact match, try the
  942. * generic database.
  943. */
  944. if (rc == 0) {
  945. printk("Acornfb: no valid mode found\n");
  946. return -EINVAL;
  947. }
  948. h_sync = 1953125000 / fb_info.var.pixclock;
  949. h_sync = h_sync * 512 / (fb_info.var.xres + fb_info.var.left_margin +
  950. fb_info.var.right_margin + fb_info.var.hsync_len);
  951. v_sync = h_sync / (fb_info.var.yres + fb_info.var.upper_margin +
  952. fb_info.var.lower_margin + fb_info.var.vsync_len);
  953. printk(KERN_INFO "Acornfb: %dkB %cRAM, %s, using %dx%d, "
  954. "%d.%03dkHz, %dHz\n",
  955. fb_info.fix.smem_len / 1024,
  956. current_par.using_vram ? 'V' : 'D',
  957. VIDC_NAME, fb_info.var.xres, fb_info.var.yres,
  958. h_sync / 1000, h_sync % 1000, v_sync);
  959. printk(KERN_INFO "Acornfb: Monitor: %d.%03d-%d.%03dkHz, %d-%dHz%s\n",
  960. fb_info.monspecs.hfmin / 1000, fb_info.monspecs.hfmin % 1000,
  961. fb_info.monspecs.hfmax / 1000, fb_info.monspecs.hfmax % 1000,
  962. fb_info.monspecs.vfmin, fb_info.monspecs.vfmax,
  963. fb_info.monspecs.dpms ? ", DPMS" : "");
  964. if (fb_set_var(&fb_info, &fb_info.var))
  965. printk(KERN_ERR "Acornfb: unable to set display parameters\n");
  966. if (register_framebuffer(&fb_info) < 0)
  967. return -EINVAL;
  968. return 0;
  969. }
  970. static struct platform_driver acornfb_driver = {
  971. .probe = acornfb_probe,
  972. .driver = {
  973. .name = "acornfb",
  974. },
  975. };
  976. static int __init acornfb_init(void)
  977. {
  978. return platform_driver_register(&acornfb_driver);
  979. }
  980. module_init(acornfb_init);
  981. MODULE_AUTHOR("Russell King");
  982. MODULE_DESCRIPTION("VIDC 1/1a/20 framebuffer driver");
  983. MODULE_LICENSE("GPL");