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