acornfb.c 35 KB

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