acornfb.c 37 KB

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