acornfb.c 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452
  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/slab.h>
  25. #include <linux/mm.h>
  26. #include <linux/init.h>
  27. #include <linux/fb.h>
  28. #include <linux/platform_device.h>
  29. #include <linux/dma-mapping.h>
  30. #include <mach/hardware.h>
  31. #include <asm/io.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] __initdata = {
  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 += var->yres;
  737. BUG_ON(y_bottom > var->yres_virtual);
  738. acornfb_update_dma(info, var);
  739. return 0;
  740. }
  741. /*
  742. * Note that we are entered with the kernel locked.
  743. */
  744. static int
  745. acornfb_mmap(struct fb_info *info, struct vm_area_struct *vma)
  746. {
  747. unsigned long off, start;
  748. u32 len;
  749. off = vma->vm_pgoff << PAGE_SHIFT;
  750. start = info->fix.smem_start;
  751. len = PAGE_ALIGN(start & ~PAGE_MASK) + info->fix.smem_len;
  752. start &= PAGE_MASK;
  753. if ((vma->vm_end - vma->vm_start + off) > len)
  754. return -EINVAL;
  755. off += start;
  756. vma->vm_pgoff = off >> PAGE_SHIFT;
  757. /* This is an IO map - tell maydump to skip this VMA */
  758. vma->vm_flags |= VM_IO;
  759. vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);
  760. /*
  761. * Don't alter the page protection flags; we want to keep the area
  762. * cached for better performance. This does mean that we may miss
  763. * some updates to the screen occasionally, but process switches
  764. * should cause the caches and buffers to be flushed often enough.
  765. */
  766. if (io_remap_pfn_range(vma, vma->vm_start, off >> PAGE_SHIFT,
  767. vma->vm_end - vma->vm_start,
  768. vma->vm_page_prot))
  769. return -EAGAIN;
  770. return 0;
  771. }
  772. static struct fb_ops acornfb_ops = {
  773. .owner = THIS_MODULE,
  774. .fb_check_var = acornfb_check_var,
  775. .fb_set_par = acornfb_set_par,
  776. .fb_setcolreg = acornfb_setcolreg,
  777. .fb_pan_display = acornfb_pan_display,
  778. .fb_fillrect = cfb_fillrect,
  779. .fb_copyarea = cfb_copyarea,
  780. .fb_imageblit = cfb_imageblit,
  781. .fb_mmap = acornfb_mmap,
  782. };
  783. /*
  784. * Everything after here is initialisation!!!
  785. */
  786. static struct fb_videomode modedb[] __initdata = {
  787. { /* 320x256 @ 50Hz */
  788. NULL, 50, 320, 256, 125000, 92, 62, 35, 19, 38, 2,
  789. FB_SYNC_COMP_HIGH_ACT,
  790. FB_VMODE_NONINTERLACED
  791. }, { /* 640x250 @ 50Hz, 15.6 kHz hsync */
  792. NULL, 50, 640, 250, 62500, 185, 123, 38, 21, 76, 3,
  793. 0,
  794. FB_VMODE_NONINTERLACED
  795. }, { /* 640x256 @ 50Hz, 15.6 kHz hsync */
  796. NULL, 50, 640, 256, 62500, 185, 123, 35, 18, 76, 3,
  797. 0,
  798. FB_VMODE_NONINTERLACED
  799. }, { /* 640x512 @ 50Hz, 26.8 kHz hsync */
  800. NULL, 50, 640, 512, 41667, 113, 87, 18, 1, 56, 3,
  801. 0,
  802. FB_VMODE_NONINTERLACED
  803. }, { /* 640x250 @ 70Hz, 31.5 kHz hsync */
  804. NULL, 70, 640, 250, 39722, 48, 16, 109, 88, 96, 2,
  805. 0,
  806. FB_VMODE_NONINTERLACED
  807. }, { /* 640x256 @ 70Hz, 31.5 kHz hsync */
  808. NULL, 70, 640, 256, 39722, 48, 16, 106, 85, 96, 2,
  809. 0,
  810. FB_VMODE_NONINTERLACED
  811. }, { /* 640x352 @ 70Hz, 31.5 kHz hsync */
  812. NULL, 70, 640, 352, 39722, 48, 16, 58, 37, 96, 2,
  813. 0,
  814. FB_VMODE_NONINTERLACED
  815. }, { /* 640x480 @ 60Hz, 31.5 kHz hsync */
  816. NULL, 60, 640, 480, 39722, 48, 16, 32, 11, 96, 2,
  817. 0,
  818. FB_VMODE_NONINTERLACED
  819. }, { /* 800x600 @ 56Hz, 35.2 kHz hsync */
  820. NULL, 56, 800, 600, 27778, 101, 23, 22, 1, 100, 2,
  821. 0,
  822. FB_VMODE_NONINTERLACED
  823. }, { /* 896x352 @ 60Hz, 21.8 kHz hsync */
  824. NULL, 60, 896, 352, 41667, 59, 27, 9, 0, 118, 3,
  825. 0,
  826. FB_VMODE_NONINTERLACED
  827. }, { /* 1024x 768 @ 60Hz, 48.4 kHz hsync */
  828. NULL, 60, 1024, 768, 15385, 160, 24, 29, 3, 136, 6,
  829. 0,
  830. FB_VMODE_NONINTERLACED
  831. }, { /* 1280x1024 @ 60Hz, 63.8 kHz hsync */
  832. NULL, 60, 1280, 1024, 9090, 186, 96, 38, 1, 160, 3,
  833. 0,
  834. FB_VMODE_NONINTERLACED
  835. }
  836. };
  837. static struct fb_videomode __initdata
  838. acornfb_default_mode = {
  839. .name = NULL,
  840. .refresh = 60,
  841. .xres = 640,
  842. .yres = 480,
  843. .pixclock = 39722,
  844. .left_margin = 56,
  845. .right_margin = 16,
  846. .upper_margin = 34,
  847. .lower_margin = 9,
  848. .hsync_len = 88,
  849. .vsync_len = 2,
  850. .sync = 0,
  851. .vmode = FB_VMODE_NONINTERLACED
  852. };
  853. static void __init acornfb_init_fbinfo(void)
  854. {
  855. static int first = 1;
  856. if (!first)
  857. return;
  858. first = 0;
  859. fb_info.fbops = &acornfb_ops;
  860. fb_info.flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
  861. fb_info.pseudo_palette = current_par.pseudo_palette;
  862. strcpy(fb_info.fix.id, "Acorn");
  863. fb_info.fix.type = FB_TYPE_PACKED_PIXELS;
  864. fb_info.fix.type_aux = 0;
  865. fb_info.fix.xpanstep = 0;
  866. fb_info.fix.ypanstep = 1;
  867. fb_info.fix.ywrapstep = 1;
  868. fb_info.fix.line_length = 0;
  869. fb_info.fix.accel = FB_ACCEL_NONE;
  870. /*
  871. * setup initial parameters
  872. */
  873. memset(&fb_info.var, 0, sizeof(fb_info.var));
  874. #if defined(HAS_VIDC20)
  875. fb_info.var.red.length = 8;
  876. fb_info.var.transp.length = 4;
  877. #elif defined(HAS_VIDC)
  878. fb_info.var.red.length = 4;
  879. fb_info.var.transp.length = 1;
  880. #endif
  881. fb_info.var.green = fb_info.var.red;
  882. fb_info.var.blue = fb_info.var.red;
  883. fb_info.var.nonstd = 0;
  884. fb_info.var.activate = FB_ACTIVATE_NOW;
  885. fb_info.var.height = -1;
  886. fb_info.var.width = -1;
  887. fb_info.var.vmode = FB_VMODE_NONINTERLACED;
  888. fb_info.var.accel_flags = FB_ACCELF_TEXT;
  889. current_par.dram_size = 0;
  890. current_par.montype = -1;
  891. current_par.dpms = 0;
  892. }
  893. /*
  894. * setup acornfb options:
  895. *
  896. * mon:hmin-hmax:vmin-vmax:dpms:width:height
  897. * Set monitor parameters:
  898. * hmin = horizontal minimum frequency (Hz)
  899. * hmax = horizontal maximum frequency (Hz) (optional)
  900. * vmin = vertical minimum frequency (Hz)
  901. * vmax = vertical maximum frequency (Hz) (optional)
  902. * dpms = DPMS supported? (optional)
  903. * width = width of picture in mm. (optional)
  904. * height = height of picture in mm. (optional)
  905. *
  906. * montype:type
  907. * Set RISC-OS style monitor type:
  908. * 0 (or tv) - TV frequency
  909. * 1 (or multi) - Multi frequency
  910. * 2 (or hires) - Hi-res monochrome
  911. * 3 (or vga) - VGA
  912. * 4 (or svga) - SVGA
  913. * auto, or option missing
  914. * - try hardware detect
  915. *
  916. * dram:size
  917. * Set the amount of DRAM to use for the frame buffer
  918. * (even if you have VRAM).
  919. * size can optionally be followed by 'M' or 'K' for
  920. * MB or KB respectively.
  921. */
  922. static void __init
  923. acornfb_parse_mon(char *opt)
  924. {
  925. char *p = opt;
  926. current_par.montype = -2;
  927. fb_info.monspecs.hfmin = simple_strtoul(p, &p, 0);
  928. if (*p == '-')
  929. fb_info.monspecs.hfmax = simple_strtoul(p + 1, &p, 0);
  930. else
  931. fb_info.monspecs.hfmax = fb_info.monspecs.hfmin;
  932. if (*p != ':')
  933. goto bad;
  934. fb_info.monspecs.vfmin = simple_strtoul(p + 1, &p, 0);
  935. if (*p == '-')
  936. fb_info.monspecs.vfmax = simple_strtoul(p + 1, &p, 0);
  937. else
  938. fb_info.monspecs.vfmax = fb_info.monspecs.vfmin;
  939. if (*p != ':')
  940. goto check_values;
  941. fb_info.monspecs.dpms = simple_strtoul(p + 1, &p, 0);
  942. if (*p != ':')
  943. goto check_values;
  944. fb_info.var.width = simple_strtoul(p + 1, &p, 0);
  945. if (*p != ':')
  946. goto check_values;
  947. fb_info.var.height = simple_strtoul(p + 1, NULL, 0);
  948. check_values:
  949. if (fb_info.monspecs.hfmax < fb_info.monspecs.hfmin ||
  950. fb_info.monspecs.vfmax < fb_info.monspecs.vfmin)
  951. goto bad;
  952. return;
  953. bad:
  954. printk(KERN_ERR "Acornfb: bad monitor settings: %s\n", opt);
  955. current_par.montype = -1;
  956. }
  957. static void __init
  958. acornfb_parse_montype(char *opt)
  959. {
  960. current_par.montype = -2;
  961. if (strncmp(opt, "tv", 2) == 0) {
  962. opt += 2;
  963. current_par.montype = 0;
  964. } else if (strncmp(opt, "multi", 5) == 0) {
  965. opt += 5;
  966. current_par.montype = 1;
  967. } else if (strncmp(opt, "hires", 5) == 0) {
  968. opt += 5;
  969. current_par.montype = 2;
  970. } else if (strncmp(opt, "vga", 3) == 0) {
  971. opt += 3;
  972. current_par.montype = 3;
  973. } else if (strncmp(opt, "svga", 4) == 0) {
  974. opt += 4;
  975. current_par.montype = 4;
  976. } else if (strncmp(opt, "auto", 4) == 0) {
  977. opt += 4;
  978. current_par.montype = -1;
  979. } else if (isdigit(*opt))
  980. current_par.montype = simple_strtoul(opt, &opt, 0);
  981. if (current_par.montype == -2 ||
  982. current_par.montype > NR_MONTYPES) {
  983. printk(KERN_ERR "acornfb: unknown monitor type: %s\n",
  984. opt);
  985. current_par.montype = -1;
  986. } else
  987. if (opt && *opt) {
  988. if (strcmp(opt, ",dpms") == 0)
  989. current_par.dpms = 1;
  990. else
  991. printk(KERN_ERR
  992. "acornfb: unknown monitor option: %s\n",
  993. opt);
  994. }
  995. }
  996. static void __init
  997. acornfb_parse_dram(char *opt)
  998. {
  999. unsigned int size;
  1000. size = simple_strtoul(opt, &opt, 0);
  1001. if (opt) {
  1002. switch (*opt) {
  1003. case 'M':
  1004. case 'm':
  1005. size *= 1024;
  1006. case 'K':
  1007. case 'k':
  1008. size *= 1024;
  1009. default:
  1010. break;
  1011. }
  1012. }
  1013. current_par.dram_size = size;
  1014. }
  1015. static struct options {
  1016. char *name;
  1017. void (*parse)(char *opt);
  1018. } opt_table[] __initdata = {
  1019. { "mon", acornfb_parse_mon },
  1020. { "montype", acornfb_parse_montype },
  1021. { "dram", acornfb_parse_dram },
  1022. { NULL, NULL }
  1023. };
  1024. int __init
  1025. acornfb_setup(char *options)
  1026. {
  1027. struct options *optp;
  1028. char *opt;
  1029. if (!options || !*options)
  1030. return 0;
  1031. acornfb_init_fbinfo();
  1032. while ((opt = strsep(&options, ",")) != NULL) {
  1033. if (!*opt)
  1034. continue;
  1035. for (optp = opt_table; optp->name; optp++) {
  1036. int optlen;
  1037. optlen = strlen(optp->name);
  1038. if (strncmp(opt, optp->name, optlen) == 0 &&
  1039. opt[optlen] == ':') {
  1040. optp->parse(opt + optlen + 1);
  1041. break;
  1042. }
  1043. }
  1044. if (!optp->name)
  1045. printk(KERN_ERR "acornfb: unknown parameter: %s\n",
  1046. opt);
  1047. }
  1048. return 0;
  1049. }
  1050. /*
  1051. * Detect type of monitor connected
  1052. * For now, we just assume SVGA
  1053. */
  1054. static int __init
  1055. acornfb_detect_monitortype(void)
  1056. {
  1057. return 4;
  1058. }
  1059. /*
  1060. * This enables the unused memory to be freed on older Acorn machines.
  1061. * We are freeing memory on behalf of the architecture initialisation
  1062. * code here.
  1063. */
  1064. static inline void
  1065. free_unused_pages(unsigned int virtual_start, unsigned int virtual_end)
  1066. {
  1067. int mb_freed = 0;
  1068. /*
  1069. * Align addresses
  1070. */
  1071. virtual_start = PAGE_ALIGN(virtual_start);
  1072. virtual_end = PAGE_ALIGN(virtual_end);
  1073. while (virtual_start < virtual_end) {
  1074. struct page *page;
  1075. /*
  1076. * Clear page reserved bit,
  1077. * set count to 1, and free
  1078. * the page.
  1079. */
  1080. page = virt_to_page(virtual_start);
  1081. ClearPageReserved(page);
  1082. init_page_count(page);
  1083. free_page(virtual_start);
  1084. virtual_start += PAGE_SIZE;
  1085. mb_freed += PAGE_SIZE / 1024;
  1086. }
  1087. printk("acornfb: freed %dK memory\n", mb_freed);
  1088. }
  1089. static int __init acornfb_probe(struct platform_device *dev)
  1090. {
  1091. unsigned long size;
  1092. u_int h_sync, v_sync;
  1093. int rc, i;
  1094. char *option = NULL;
  1095. if (fb_get_options("acornfb", &option))
  1096. return -ENODEV;
  1097. acornfb_setup(option);
  1098. acornfb_init_fbinfo();
  1099. current_par.dev = &dev->dev;
  1100. if (current_par.montype == -1)
  1101. current_par.montype = acornfb_detect_monitortype();
  1102. if (current_par.montype == -1 || current_par.montype > NR_MONTYPES)
  1103. current_par.montype = 4;
  1104. if (current_par.montype >= 0) {
  1105. fb_info.monspecs = monspecs[current_par.montype];
  1106. fb_info.monspecs.dpms = current_par.dpms;
  1107. }
  1108. /*
  1109. * Try to select a suitable default mode
  1110. */
  1111. for (i = 0; i < ARRAY_SIZE(modedb); i++) {
  1112. unsigned long hs;
  1113. hs = modedb[i].refresh *
  1114. (modedb[i].yres + modedb[i].upper_margin +
  1115. modedb[i].lower_margin + modedb[i].vsync_len);
  1116. if (modedb[i].xres == DEFAULT_XRES &&
  1117. modedb[i].yres == DEFAULT_YRES &&
  1118. modedb[i].refresh >= fb_info.monspecs.vfmin &&
  1119. modedb[i].refresh <= fb_info.monspecs.vfmax &&
  1120. hs >= fb_info.monspecs.hfmin &&
  1121. hs <= fb_info.monspecs.hfmax) {
  1122. acornfb_default_mode = modedb[i];
  1123. break;
  1124. }
  1125. }
  1126. fb_info.screen_base = (char *)SCREEN_BASE;
  1127. fb_info.fix.smem_start = SCREEN_START;
  1128. current_par.using_vram = 0;
  1129. /*
  1130. * If vram_size is set, we are using VRAM in
  1131. * a Risc PC. However, if the user has specified
  1132. * an amount of DRAM then use that instead.
  1133. */
  1134. if (vram_size && !current_par.dram_size) {
  1135. size = vram_size;
  1136. current_par.vram_half_sam = vram_size / 1024;
  1137. current_par.using_vram = 1;
  1138. } else if (current_par.dram_size)
  1139. size = current_par.dram_size;
  1140. else
  1141. size = MAX_SIZE;
  1142. /*
  1143. * Limit maximum screen size.
  1144. */
  1145. if (size > MAX_SIZE)
  1146. size = MAX_SIZE;
  1147. size = PAGE_ALIGN(size);
  1148. #if defined(HAS_VIDC20)
  1149. if (!current_par.using_vram) {
  1150. dma_addr_t handle;
  1151. void *base;
  1152. /*
  1153. * RiscPC needs to allocate the DRAM memory
  1154. * for the framebuffer if we are not using
  1155. * VRAM.
  1156. */
  1157. base = dma_alloc_writecombine(current_par.dev, size, &handle,
  1158. GFP_KERNEL);
  1159. if (base == NULL) {
  1160. printk(KERN_ERR "acornfb: unable to allocate screen "
  1161. "memory\n");
  1162. return -ENOMEM;
  1163. }
  1164. fb_info.screen_base = base;
  1165. fb_info.fix.smem_start = handle;
  1166. }
  1167. #endif
  1168. #if defined(HAS_VIDC)
  1169. /*
  1170. * Archimedes/A5000 machines use a fixed address for their
  1171. * framebuffers. Free unused pages
  1172. */
  1173. free_unused_pages(PAGE_OFFSET + size, PAGE_OFFSET + MAX_SIZE);
  1174. #endif
  1175. fb_info.fix.smem_len = size;
  1176. current_par.palette_size = VIDC_PALETTE_SIZE;
  1177. /*
  1178. * Lookup the timing for this resolution. If we can't
  1179. * find it, then we can't restore it if we change
  1180. * the resolution, so we disable this feature.
  1181. */
  1182. do {
  1183. rc = fb_find_mode(&fb_info.var, &fb_info, NULL, modedb,
  1184. ARRAY_SIZE(modedb),
  1185. &acornfb_default_mode, DEFAULT_BPP);
  1186. /*
  1187. * If we found an exact match, all ok.
  1188. */
  1189. if (rc == 1)
  1190. break;
  1191. rc = fb_find_mode(&fb_info.var, &fb_info, NULL, NULL, 0,
  1192. &acornfb_default_mode, DEFAULT_BPP);
  1193. /*
  1194. * If we found an exact match, all ok.
  1195. */
  1196. if (rc == 1)
  1197. break;
  1198. rc = fb_find_mode(&fb_info.var, &fb_info, NULL, modedb,
  1199. ARRAY_SIZE(modedb),
  1200. &acornfb_default_mode, DEFAULT_BPP);
  1201. if (rc)
  1202. break;
  1203. rc = fb_find_mode(&fb_info.var, &fb_info, NULL, NULL, 0,
  1204. &acornfb_default_mode, DEFAULT_BPP);
  1205. } while (0);
  1206. /*
  1207. * If we didn't find an exact match, try the
  1208. * generic database.
  1209. */
  1210. if (rc == 0) {
  1211. printk("Acornfb: no valid mode found\n");
  1212. return -EINVAL;
  1213. }
  1214. h_sync = 1953125000 / fb_info.var.pixclock;
  1215. h_sync = h_sync * 512 / (fb_info.var.xres + fb_info.var.left_margin +
  1216. fb_info.var.right_margin + fb_info.var.hsync_len);
  1217. v_sync = h_sync / (fb_info.var.yres + fb_info.var.upper_margin +
  1218. fb_info.var.lower_margin + fb_info.var.vsync_len);
  1219. printk(KERN_INFO "Acornfb: %dkB %cRAM, %s, using %dx%d, "
  1220. "%d.%03dkHz, %dHz\n",
  1221. fb_info.fix.smem_len / 1024,
  1222. current_par.using_vram ? 'V' : 'D',
  1223. VIDC_NAME, fb_info.var.xres, fb_info.var.yres,
  1224. h_sync / 1000, h_sync % 1000, v_sync);
  1225. printk(KERN_INFO "Acornfb: Monitor: %d.%03d-%d.%03dkHz, %d-%dHz%s\n",
  1226. fb_info.monspecs.hfmin / 1000, fb_info.monspecs.hfmin % 1000,
  1227. fb_info.monspecs.hfmax / 1000, fb_info.monspecs.hfmax % 1000,
  1228. fb_info.monspecs.vfmin, fb_info.monspecs.vfmax,
  1229. fb_info.monspecs.dpms ? ", DPMS" : "");
  1230. if (fb_set_var(&fb_info, &fb_info.var))
  1231. printk(KERN_ERR "Acornfb: unable to set display parameters\n");
  1232. if (register_framebuffer(&fb_info) < 0)
  1233. return -EINVAL;
  1234. return 0;
  1235. }
  1236. static struct platform_driver acornfb_driver = {
  1237. .probe = acornfb_probe,
  1238. .driver = {
  1239. .name = "acornfb",
  1240. },
  1241. };
  1242. static int __init acornfb_init(void)
  1243. {
  1244. return platform_driver_register(&acornfb_driver);
  1245. }
  1246. module_init(acornfb_init);
  1247. MODULE_AUTHOR("Russell King");
  1248. MODULE_DESCRIPTION("VIDC 1/1a/20 framebuffer driver");
  1249. MODULE_LICENSE("GPL");