cyber2000fb.c 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977
  1. /*
  2. * linux/drivers/video/cyber2000fb.c
  3. *
  4. * Copyright (C) 1998-2002 Russell King
  5. *
  6. * MIPS and 50xx clock support
  7. * Copyright (C) 2001 Bradley D. LaRonde <brad@ltc.com>
  8. *
  9. * 32 bit support, text color and panning fixes for modes != 8 bit
  10. * Copyright (C) 2002 Denis Oliver Kropp <dok@directfb.org>
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License version 2 as
  14. * published by the Free Software Foundation.
  15. *
  16. * Integraphics CyberPro 2000, 2010 and 5000 frame buffer device
  17. *
  18. * Based on cyberfb.c.
  19. *
  20. * Note that we now use the new fbcon fix, var and cmap scheme. We do
  21. * still have to check which console is the currently displayed one
  22. * however, especially for the colourmap stuff.
  23. *
  24. * We also use the new hotplug PCI subsystem. I'm not sure if there
  25. * are any such cards, but I'm erring on the side of caution. We don't
  26. * want to go pop just because someone does have one.
  27. *
  28. * Note that this doesn't work fully in the case of multiple CyberPro
  29. * cards with grabbers. We currently can only attach to the first
  30. * CyberPro card found.
  31. *
  32. * When we're in truecolour mode, we power down the LUT RAM as a power
  33. * saving feature. Also, when we enter any of the powersaving modes
  34. * (except soft blanking) we power down the RAMDACs. This saves about
  35. * 1W, which is roughly 8% of the power consumption of a NetWinder
  36. * (which, incidentally, is about the same saving as a 2.5in hard disk
  37. * entering standby mode.)
  38. */
  39. #include <linux/module.h>
  40. #include <linux/kernel.h>
  41. #include <linux/errno.h>
  42. #include <linux/string.h>
  43. #include <linux/mm.h>
  44. #include <linux/slab.h>
  45. #include <linux/delay.h>
  46. #include <linux/fb.h>
  47. #include <linux/pci.h>
  48. #include <linux/init.h>
  49. #include <linux/io.h>
  50. #include <linux/i2c.h>
  51. #include <linux/i2c-algo-bit.h>
  52. #include <asm/pgtable.h>
  53. #include <asm/system.h>
  54. #ifdef __arm__
  55. #include <asm/mach-types.h>
  56. #endif
  57. #include "cyber2000fb.h"
  58. struct cfb_info {
  59. struct fb_info fb;
  60. struct display_switch *dispsw;
  61. struct display *display;
  62. unsigned char __iomem *region;
  63. unsigned char __iomem *regs;
  64. u_int id;
  65. u_int irq;
  66. int func_use_count;
  67. u_long ref_ps;
  68. /*
  69. * Clock divisors
  70. */
  71. u_int divisors[4];
  72. struct {
  73. u8 red, green, blue;
  74. } palette[NR_PALETTE];
  75. u_char mem_ctl1;
  76. u_char mem_ctl2;
  77. u_char mclk_mult;
  78. u_char mclk_div;
  79. /*
  80. * RAMDAC control register is both of these or'ed together
  81. */
  82. u_char ramdac_ctrl;
  83. u_char ramdac_powerdown;
  84. u32 pseudo_palette[16];
  85. spinlock_t reg_b0_lock;
  86. #ifdef CONFIG_FB_CYBER2000_DDC
  87. bool ddc_registered;
  88. struct i2c_adapter ddc_adapter;
  89. struct i2c_algo_bit_data ddc_algo;
  90. #endif
  91. #ifdef CONFIG_FB_CYBER2000_I2C
  92. struct i2c_adapter i2c_adapter;
  93. struct i2c_algo_bit_data i2c_algo;
  94. #endif
  95. };
  96. static char *default_font = "Acorn8x8";
  97. module_param(default_font, charp, 0);
  98. MODULE_PARM_DESC(default_font, "Default font name");
  99. /*
  100. * Our access methods.
  101. */
  102. #define cyber2000fb_writel(val, reg, cfb) writel(val, (cfb)->regs + (reg))
  103. #define cyber2000fb_writew(val, reg, cfb) writew(val, (cfb)->regs + (reg))
  104. #define cyber2000fb_writeb(val, reg, cfb) writeb(val, (cfb)->regs + (reg))
  105. #define cyber2000fb_readb(reg, cfb) readb((cfb)->regs + (reg))
  106. static inline void
  107. cyber2000_crtcw(unsigned int reg, unsigned int val, struct cfb_info *cfb)
  108. {
  109. cyber2000fb_writew((reg & 255) | val << 8, 0x3d4, cfb);
  110. }
  111. static inline void
  112. cyber2000_grphw(unsigned int reg, unsigned int val, struct cfb_info *cfb)
  113. {
  114. cyber2000fb_writew((reg & 255) | val << 8, 0x3ce, cfb);
  115. }
  116. static inline unsigned int
  117. cyber2000_grphr(unsigned int reg, struct cfb_info *cfb)
  118. {
  119. cyber2000fb_writeb(reg, 0x3ce, cfb);
  120. return cyber2000fb_readb(0x3cf, cfb);
  121. }
  122. static inline void
  123. cyber2000_attrw(unsigned int reg, unsigned int val, struct cfb_info *cfb)
  124. {
  125. cyber2000fb_readb(0x3da, cfb);
  126. cyber2000fb_writeb(reg, 0x3c0, cfb);
  127. cyber2000fb_readb(0x3c1, cfb);
  128. cyber2000fb_writeb(val, 0x3c0, cfb);
  129. }
  130. static inline void
  131. cyber2000_seqw(unsigned int reg, unsigned int val, struct cfb_info *cfb)
  132. {
  133. cyber2000fb_writew((reg & 255) | val << 8, 0x3c4, cfb);
  134. }
  135. /* -------------------- Hardware specific routines ------------------------- */
  136. /*
  137. * Hardware Cyber2000 Acceleration
  138. */
  139. static void
  140. cyber2000fb_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
  141. {
  142. struct cfb_info *cfb = (struct cfb_info *)info;
  143. unsigned long dst, col;
  144. if (!(cfb->fb.var.accel_flags & FB_ACCELF_TEXT)) {
  145. cfb_fillrect(info, rect);
  146. return;
  147. }
  148. cyber2000fb_writeb(0, CO_REG_CONTROL, cfb);
  149. cyber2000fb_writew(rect->width - 1, CO_REG_PIXWIDTH, cfb);
  150. cyber2000fb_writew(rect->height - 1, CO_REG_PIXHEIGHT, cfb);
  151. col = rect->color;
  152. if (cfb->fb.var.bits_per_pixel > 8)
  153. col = ((u32 *)cfb->fb.pseudo_palette)[col];
  154. cyber2000fb_writel(col, CO_REG_FGCOLOUR, cfb);
  155. dst = rect->dx + rect->dy * cfb->fb.var.xres_virtual;
  156. if (cfb->fb.var.bits_per_pixel == 24) {
  157. cyber2000fb_writeb(dst, CO_REG_X_PHASE, cfb);
  158. dst *= 3;
  159. }
  160. cyber2000fb_writel(dst, CO_REG_DEST_PTR, cfb);
  161. cyber2000fb_writeb(CO_FG_MIX_SRC, CO_REG_FGMIX, cfb);
  162. cyber2000fb_writew(CO_CMD_L_PATTERN_FGCOL, CO_REG_CMD_L, cfb);
  163. cyber2000fb_writew(CO_CMD_H_BLITTER, CO_REG_CMD_H, cfb);
  164. }
  165. static void
  166. cyber2000fb_copyarea(struct fb_info *info, const struct fb_copyarea *region)
  167. {
  168. struct cfb_info *cfb = (struct cfb_info *)info;
  169. unsigned int cmd = CO_CMD_L_PATTERN_FGCOL;
  170. unsigned long src, dst;
  171. if (!(cfb->fb.var.accel_flags & FB_ACCELF_TEXT)) {
  172. cfb_copyarea(info, region);
  173. return;
  174. }
  175. cyber2000fb_writeb(0, CO_REG_CONTROL, cfb);
  176. cyber2000fb_writew(region->width - 1, CO_REG_PIXWIDTH, cfb);
  177. cyber2000fb_writew(region->height - 1, CO_REG_PIXHEIGHT, cfb);
  178. src = region->sx + region->sy * cfb->fb.var.xres_virtual;
  179. dst = region->dx + region->dy * cfb->fb.var.xres_virtual;
  180. if (region->sx < region->dx) {
  181. src += region->width - 1;
  182. dst += region->width - 1;
  183. cmd |= CO_CMD_L_INC_LEFT;
  184. }
  185. if (region->sy < region->dy) {
  186. src += (region->height - 1) * cfb->fb.var.xres_virtual;
  187. dst += (region->height - 1) * cfb->fb.var.xres_virtual;
  188. cmd |= CO_CMD_L_INC_UP;
  189. }
  190. if (cfb->fb.var.bits_per_pixel == 24) {
  191. cyber2000fb_writeb(dst, CO_REG_X_PHASE, cfb);
  192. src *= 3;
  193. dst *= 3;
  194. }
  195. cyber2000fb_writel(src, CO_REG_SRC1_PTR, cfb);
  196. cyber2000fb_writel(dst, CO_REG_DEST_PTR, cfb);
  197. cyber2000fb_writew(CO_FG_MIX_SRC, CO_REG_FGMIX, cfb);
  198. cyber2000fb_writew(cmd, CO_REG_CMD_L, cfb);
  199. cyber2000fb_writew(CO_CMD_H_FGSRCMAP | CO_CMD_H_BLITTER,
  200. CO_REG_CMD_H, cfb);
  201. }
  202. static void
  203. cyber2000fb_imageblit(struct fb_info *info, const struct fb_image *image)
  204. {
  205. cfb_imageblit(info, image);
  206. return;
  207. }
  208. static int cyber2000fb_sync(struct fb_info *info)
  209. {
  210. struct cfb_info *cfb = (struct cfb_info *)info;
  211. int count = 100000;
  212. if (!(cfb->fb.var.accel_flags & FB_ACCELF_TEXT))
  213. return 0;
  214. while (cyber2000fb_readb(CO_REG_CONTROL, cfb) & CO_CTRL_BUSY) {
  215. if (!count--) {
  216. debug_printf("accel_wait timed out\n");
  217. cyber2000fb_writeb(0, CO_REG_CONTROL, cfb);
  218. break;
  219. }
  220. udelay(1);
  221. }
  222. return 0;
  223. }
  224. /*
  225. * ===========================================================================
  226. */
  227. static inline u32 convert_bitfield(u_int val, struct fb_bitfield *bf)
  228. {
  229. u_int mask = (1 << bf->length) - 1;
  230. return (val >> (16 - bf->length) & mask) << bf->offset;
  231. }
  232. /*
  233. * Set a single color register. Return != 0 for invalid regno.
  234. */
  235. static int
  236. cyber2000fb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
  237. u_int transp, struct fb_info *info)
  238. {
  239. struct cfb_info *cfb = (struct cfb_info *)info;
  240. struct fb_var_screeninfo *var = &cfb->fb.var;
  241. u32 pseudo_val;
  242. int ret = 1;
  243. switch (cfb->fb.fix.visual) {
  244. default:
  245. return 1;
  246. /*
  247. * Pseudocolour:
  248. * 8 8
  249. * pixel --/--+--/--> red lut --> red dac
  250. * | 8
  251. * +--/--> green lut --> green dac
  252. * | 8
  253. * +--/--> blue lut --> blue dac
  254. */
  255. case FB_VISUAL_PSEUDOCOLOR:
  256. if (regno >= NR_PALETTE)
  257. return 1;
  258. red >>= 8;
  259. green >>= 8;
  260. blue >>= 8;
  261. cfb->palette[regno].red = red;
  262. cfb->palette[regno].green = green;
  263. cfb->palette[regno].blue = blue;
  264. cyber2000fb_writeb(regno, 0x3c8, cfb);
  265. cyber2000fb_writeb(red, 0x3c9, cfb);
  266. cyber2000fb_writeb(green, 0x3c9, cfb);
  267. cyber2000fb_writeb(blue, 0x3c9, cfb);
  268. return 0;
  269. /*
  270. * Direct colour:
  271. * n rl
  272. * pixel --/--+--/--> red lut --> red dac
  273. * | gl
  274. * +--/--> green lut --> green dac
  275. * | bl
  276. * +--/--> blue lut --> blue dac
  277. * n = bpp, rl = red length, gl = green length, bl = blue length
  278. */
  279. case FB_VISUAL_DIRECTCOLOR:
  280. red >>= 8;
  281. green >>= 8;
  282. blue >>= 8;
  283. if (var->green.length == 6 && regno < 64) {
  284. cfb->palette[regno << 2].green = green;
  285. /*
  286. * The 6 bits of the green component are applied
  287. * to the high 6 bits of the LUT.
  288. */
  289. cyber2000fb_writeb(regno << 2, 0x3c8, cfb);
  290. cyber2000fb_writeb(cfb->palette[regno >> 1].red,
  291. 0x3c9, cfb);
  292. cyber2000fb_writeb(green, 0x3c9, cfb);
  293. cyber2000fb_writeb(cfb->palette[regno >> 1].blue,
  294. 0x3c9, cfb);
  295. green = cfb->palette[regno << 3].green;
  296. ret = 0;
  297. }
  298. if (var->green.length >= 5 && regno < 32) {
  299. cfb->palette[regno << 3].red = red;
  300. cfb->palette[regno << 3].green = green;
  301. cfb->palette[regno << 3].blue = blue;
  302. /*
  303. * The 5 bits of each colour component are
  304. * applied to the high 5 bits of the LUT.
  305. */
  306. cyber2000fb_writeb(regno << 3, 0x3c8, cfb);
  307. cyber2000fb_writeb(red, 0x3c9, cfb);
  308. cyber2000fb_writeb(green, 0x3c9, cfb);
  309. cyber2000fb_writeb(blue, 0x3c9, cfb);
  310. ret = 0;
  311. }
  312. if (var->green.length == 4 && regno < 16) {
  313. cfb->palette[regno << 4].red = red;
  314. cfb->palette[regno << 4].green = green;
  315. cfb->palette[regno << 4].blue = blue;
  316. /*
  317. * The 5 bits of each colour component are
  318. * applied to the high 5 bits of the LUT.
  319. */
  320. cyber2000fb_writeb(regno << 4, 0x3c8, cfb);
  321. cyber2000fb_writeb(red, 0x3c9, cfb);
  322. cyber2000fb_writeb(green, 0x3c9, cfb);
  323. cyber2000fb_writeb(blue, 0x3c9, cfb);
  324. ret = 0;
  325. }
  326. /*
  327. * Since this is only used for the first 16 colours, we
  328. * don't have to care about overflowing for regno >= 32
  329. */
  330. pseudo_val = regno << var->red.offset |
  331. regno << var->green.offset |
  332. regno << var->blue.offset;
  333. break;
  334. /*
  335. * True colour:
  336. * n rl
  337. * pixel --/--+--/--> red dac
  338. * | gl
  339. * +--/--> green dac
  340. * | bl
  341. * +--/--> blue dac
  342. * n = bpp, rl = red length, gl = green length, bl = blue length
  343. */
  344. case FB_VISUAL_TRUECOLOR:
  345. pseudo_val = convert_bitfield(transp ^ 0xffff, &var->transp);
  346. pseudo_val |= convert_bitfield(red, &var->red);
  347. pseudo_val |= convert_bitfield(green, &var->green);
  348. pseudo_val |= convert_bitfield(blue, &var->blue);
  349. ret = 0;
  350. break;
  351. }
  352. /*
  353. * Now set our pseudo palette for the CFB16/24/32 drivers.
  354. */
  355. if (regno < 16)
  356. ((u32 *)cfb->fb.pseudo_palette)[regno] = pseudo_val;
  357. return ret;
  358. }
  359. struct par_info {
  360. /*
  361. * Hardware
  362. */
  363. u_char clock_mult;
  364. u_char clock_div;
  365. u_char extseqmisc;
  366. u_char co_pixfmt;
  367. u_char crtc_ofl;
  368. u_char crtc[19];
  369. u_int width;
  370. u_int pitch;
  371. u_int fetch;
  372. /*
  373. * Other
  374. */
  375. u_char ramdac;
  376. };
  377. static const u_char crtc_idx[] = {
  378. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  379. 0x08, 0x09,
  380. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18
  381. };
  382. static void cyber2000fb_write_ramdac_ctrl(struct cfb_info *cfb)
  383. {
  384. unsigned int i;
  385. unsigned int val = cfb->ramdac_ctrl | cfb->ramdac_powerdown;
  386. cyber2000fb_writeb(0x56, 0x3ce, cfb);
  387. i = cyber2000fb_readb(0x3cf, cfb);
  388. cyber2000fb_writeb(i | 4, 0x3cf, cfb);
  389. cyber2000fb_writeb(val, 0x3c6, cfb);
  390. cyber2000fb_writeb(i, 0x3cf, cfb);
  391. /* prevent card lock-up observed on x86 with CyberPro 2000 */
  392. cyber2000fb_readb(0x3cf, cfb);
  393. }
  394. static void cyber2000fb_set_timing(struct cfb_info *cfb, struct par_info *hw)
  395. {
  396. u_int i;
  397. /*
  398. * Blank palette
  399. */
  400. for (i = 0; i < NR_PALETTE; i++) {
  401. cyber2000fb_writeb(i, 0x3c8, cfb);
  402. cyber2000fb_writeb(0, 0x3c9, cfb);
  403. cyber2000fb_writeb(0, 0x3c9, cfb);
  404. cyber2000fb_writeb(0, 0x3c9, cfb);
  405. }
  406. cyber2000fb_writeb(0xef, 0x3c2, cfb);
  407. cyber2000_crtcw(0x11, 0x0b, cfb);
  408. cyber2000_attrw(0x11, 0x00, cfb);
  409. cyber2000_seqw(0x00, 0x01, cfb);
  410. cyber2000_seqw(0x01, 0x01, cfb);
  411. cyber2000_seqw(0x02, 0x0f, cfb);
  412. cyber2000_seqw(0x03, 0x00, cfb);
  413. cyber2000_seqw(0x04, 0x0e, cfb);
  414. cyber2000_seqw(0x00, 0x03, cfb);
  415. for (i = 0; i < sizeof(crtc_idx); i++)
  416. cyber2000_crtcw(crtc_idx[i], hw->crtc[i], cfb);
  417. for (i = 0x0a; i < 0x10; i++)
  418. cyber2000_crtcw(i, 0, cfb);
  419. cyber2000_grphw(EXT_CRT_VRTOFL, hw->crtc_ofl, cfb);
  420. cyber2000_grphw(0x00, 0x00, cfb);
  421. cyber2000_grphw(0x01, 0x00, cfb);
  422. cyber2000_grphw(0x02, 0x00, cfb);
  423. cyber2000_grphw(0x03, 0x00, cfb);
  424. cyber2000_grphw(0x04, 0x00, cfb);
  425. cyber2000_grphw(0x05, 0x60, cfb);
  426. cyber2000_grphw(0x06, 0x05, cfb);
  427. cyber2000_grphw(0x07, 0x0f, cfb);
  428. cyber2000_grphw(0x08, 0xff, cfb);
  429. /* Attribute controller registers */
  430. for (i = 0; i < 16; i++)
  431. cyber2000_attrw(i, i, cfb);
  432. cyber2000_attrw(0x10, 0x01, cfb);
  433. cyber2000_attrw(0x11, 0x00, cfb);
  434. cyber2000_attrw(0x12, 0x0f, cfb);
  435. cyber2000_attrw(0x13, 0x00, cfb);
  436. cyber2000_attrw(0x14, 0x00, cfb);
  437. /* PLL registers */
  438. spin_lock(&cfb->reg_b0_lock);
  439. cyber2000_grphw(EXT_DCLK_MULT, hw->clock_mult, cfb);
  440. cyber2000_grphw(EXT_DCLK_DIV, hw->clock_div, cfb);
  441. cyber2000_grphw(EXT_MCLK_MULT, cfb->mclk_mult, cfb);
  442. cyber2000_grphw(EXT_MCLK_DIV, cfb->mclk_div, cfb);
  443. cyber2000_grphw(0x90, 0x01, cfb);
  444. cyber2000_grphw(0xb9, 0x80, cfb);
  445. cyber2000_grphw(0xb9, 0x00, cfb);
  446. spin_unlock(&cfb->reg_b0_lock);
  447. cfb->ramdac_ctrl = hw->ramdac;
  448. cyber2000fb_write_ramdac_ctrl(cfb);
  449. cyber2000fb_writeb(0x20, 0x3c0, cfb);
  450. cyber2000fb_writeb(0xff, 0x3c6, cfb);
  451. cyber2000_grphw(0x14, hw->fetch, cfb);
  452. cyber2000_grphw(0x15, ((hw->fetch >> 8) & 0x03) |
  453. ((hw->pitch >> 4) & 0x30), cfb);
  454. cyber2000_grphw(EXT_SEQ_MISC, hw->extseqmisc, cfb);
  455. /*
  456. * Set up accelerator registers
  457. */
  458. cyber2000fb_writew(hw->width, CO_REG_SRC_WIDTH, cfb);
  459. cyber2000fb_writew(hw->width, CO_REG_DEST_WIDTH, cfb);
  460. cyber2000fb_writeb(hw->co_pixfmt, CO_REG_PIXFMT, cfb);
  461. }
  462. static inline int
  463. cyber2000fb_update_start(struct cfb_info *cfb, struct fb_var_screeninfo *var)
  464. {
  465. u_int base = var->yoffset * var->xres_virtual + var->xoffset;
  466. base *= var->bits_per_pixel;
  467. /*
  468. * Convert to bytes and shift two extra bits because DAC
  469. * can only start on 4 byte aligned data.
  470. */
  471. base >>= 5;
  472. if (base >= 1 << 20)
  473. return -EINVAL;
  474. cyber2000_grphw(0x10, base >> 16 | 0x10, cfb);
  475. cyber2000_crtcw(0x0c, base >> 8, cfb);
  476. cyber2000_crtcw(0x0d, base, cfb);
  477. return 0;
  478. }
  479. static int
  480. cyber2000fb_decode_crtc(struct par_info *hw, struct cfb_info *cfb,
  481. struct fb_var_screeninfo *var)
  482. {
  483. u_int Htotal, Hblankend, Hsyncend;
  484. u_int Vtotal, Vdispend, Vblankstart, Vblankend, Vsyncstart, Vsyncend;
  485. #define ENCODE_BIT(v, b1, m, b2) ((((v) >> (b1)) & (m)) << (b2))
  486. hw->crtc[13] = hw->pitch;
  487. hw->crtc[17] = 0xe3;
  488. hw->crtc[14] = 0;
  489. hw->crtc[8] = 0;
  490. Htotal = var->xres + var->right_margin +
  491. var->hsync_len + var->left_margin;
  492. if (Htotal > 2080)
  493. return -EINVAL;
  494. hw->crtc[0] = (Htotal >> 3) - 5;
  495. hw->crtc[1] = (var->xres >> 3) - 1;
  496. hw->crtc[2] = var->xres >> 3;
  497. hw->crtc[4] = (var->xres + var->right_margin) >> 3;
  498. Hblankend = (Htotal - 4 * 8) >> 3;
  499. hw->crtc[3] = ENCODE_BIT(Hblankend, 0, 0x1f, 0) |
  500. ENCODE_BIT(1, 0, 0x01, 7);
  501. Hsyncend = (var->xres + var->right_margin + var->hsync_len) >> 3;
  502. hw->crtc[5] = ENCODE_BIT(Hsyncend, 0, 0x1f, 0) |
  503. ENCODE_BIT(Hblankend, 5, 0x01, 7);
  504. Vdispend = var->yres - 1;
  505. Vsyncstart = var->yres + var->lower_margin;
  506. Vsyncend = var->yres + var->lower_margin + var->vsync_len;
  507. Vtotal = var->yres + var->lower_margin + var->vsync_len +
  508. var->upper_margin - 2;
  509. if (Vtotal > 2047)
  510. return -EINVAL;
  511. Vblankstart = var->yres + 6;
  512. Vblankend = Vtotal - 10;
  513. hw->crtc[6] = Vtotal;
  514. hw->crtc[7] = ENCODE_BIT(Vtotal, 8, 0x01, 0) |
  515. ENCODE_BIT(Vdispend, 8, 0x01, 1) |
  516. ENCODE_BIT(Vsyncstart, 8, 0x01, 2) |
  517. ENCODE_BIT(Vblankstart, 8, 0x01, 3) |
  518. ENCODE_BIT(1, 0, 0x01, 4) |
  519. ENCODE_BIT(Vtotal, 9, 0x01, 5) |
  520. ENCODE_BIT(Vdispend, 9, 0x01, 6) |
  521. ENCODE_BIT(Vsyncstart, 9, 0x01, 7);
  522. hw->crtc[9] = ENCODE_BIT(0, 0, 0x1f, 0) |
  523. ENCODE_BIT(Vblankstart, 9, 0x01, 5) |
  524. ENCODE_BIT(1, 0, 0x01, 6);
  525. hw->crtc[10] = Vsyncstart;
  526. hw->crtc[11] = ENCODE_BIT(Vsyncend, 0, 0x0f, 0) |
  527. ENCODE_BIT(1, 0, 0x01, 7);
  528. hw->crtc[12] = Vdispend;
  529. hw->crtc[15] = Vblankstart;
  530. hw->crtc[16] = Vblankend;
  531. hw->crtc[18] = 0xff;
  532. /*
  533. * overflow - graphics reg 0x11
  534. * 0=VTOTAL:10 1=VDEND:10 2=VRSTART:10 3=VBSTART:10
  535. * 4=LINECOMP:10 5-IVIDEO 6=FIXCNT
  536. */
  537. hw->crtc_ofl =
  538. ENCODE_BIT(Vtotal, 10, 0x01, 0) |
  539. ENCODE_BIT(Vdispend, 10, 0x01, 1) |
  540. ENCODE_BIT(Vsyncstart, 10, 0x01, 2) |
  541. ENCODE_BIT(Vblankstart, 10, 0x01, 3) |
  542. EXT_CRT_VRTOFL_LINECOMP10;
  543. /* woody: set the interlaced bit... */
  544. /* FIXME: what about doublescan? */
  545. if ((var->vmode & FB_VMODE_MASK) == FB_VMODE_INTERLACED)
  546. hw->crtc_ofl |= EXT_CRT_VRTOFL_INTERLACE;
  547. return 0;
  548. }
  549. /*
  550. * The following was discovered by a good monitor, bit twiddling, theorising
  551. * and but mostly luck. Strangely, it looks like everyone elses' PLL!
  552. *
  553. * Clock registers:
  554. * fclock = fpll / div2
  555. * fpll = fref * mult / div1
  556. * where:
  557. * fref = 14.318MHz (69842ps)
  558. * mult = reg0xb0.7:0
  559. * div1 = (reg0xb1.5:0 + 1)
  560. * div2 = 2^(reg0xb1.7:6)
  561. * fpll should be between 115 and 260 MHz
  562. * (8696ps and 3846ps)
  563. */
  564. static int
  565. cyber2000fb_decode_clock(struct par_info *hw, struct cfb_info *cfb,
  566. struct fb_var_screeninfo *var)
  567. {
  568. u_long pll_ps = var->pixclock;
  569. const u_long ref_ps = cfb->ref_ps;
  570. u_int div2, t_div1, best_div1, best_mult;
  571. int best_diff;
  572. int vco;
  573. /*
  574. * Step 1:
  575. * find div2 such that 115MHz < fpll < 260MHz
  576. * and 0 <= div2 < 4
  577. */
  578. for (div2 = 0; div2 < 4; div2++) {
  579. u_long new_pll;
  580. new_pll = pll_ps / cfb->divisors[div2];
  581. if (8696 > new_pll && new_pll > 3846) {
  582. pll_ps = new_pll;
  583. break;
  584. }
  585. }
  586. if (div2 == 4)
  587. return -EINVAL;
  588. /*
  589. * Step 2:
  590. * Given pll_ps and ref_ps, find:
  591. * pll_ps * 0.995 < pll_ps_calc < pll_ps * 1.005
  592. * where { 1 < best_div1 < 32, 1 < best_mult < 256 }
  593. * pll_ps_calc = best_div1 / (ref_ps * best_mult)
  594. */
  595. best_diff = 0x7fffffff;
  596. best_mult = 2;
  597. best_div1 = 32;
  598. for (t_div1 = 2; t_div1 < 32; t_div1 += 1) {
  599. u_int rr, t_mult, t_pll_ps;
  600. int diff;
  601. /*
  602. * Find the multiplier for this divisor
  603. */
  604. rr = ref_ps * t_div1;
  605. t_mult = (rr + pll_ps / 2) / pll_ps;
  606. /*
  607. * Is the multiplier within the correct range?
  608. */
  609. if (t_mult > 256 || t_mult < 2)
  610. continue;
  611. /*
  612. * Calculate the actual clock period from this multiplier
  613. * and divisor, and estimate the error.
  614. */
  615. t_pll_ps = (rr + t_mult / 2) / t_mult;
  616. diff = pll_ps - t_pll_ps;
  617. if (diff < 0)
  618. diff = -diff;
  619. if (diff < best_diff) {
  620. best_diff = diff;
  621. best_mult = t_mult;
  622. best_div1 = t_div1;
  623. }
  624. /*
  625. * If we hit an exact value, there is no point in continuing.
  626. */
  627. if (diff == 0)
  628. break;
  629. }
  630. /*
  631. * Step 3:
  632. * combine values
  633. */
  634. hw->clock_mult = best_mult - 1;
  635. hw->clock_div = div2 << 6 | (best_div1 - 1);
  636. vco = ref_ps * best_div1 / best_mult;
  637. if ((ref_ps == 40690) && (vco < 5556))
  638. /* Set VFSEL when VCO > 180MHz (5.556 ps). */
  639. hw->clock_div |= EXT_DCLK_DIV_VFSEL;
  640. return 0;
  641. }
  642. /*
  643. * Set the User Defined Part of the Display
  644. */
  645. static int
  646. cyber2000fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
  647. {
  648. struct cfb_info *cfb = (struct cfb_info *)info;
  649. struct par_info hw;
  650. unsigned int mem;
  651. int err;
  652. var->transp.msb_right = 0;
  653. var->red.msb_right = 0;
  654. var->green.msb_right = 0;
  655. var->blue.msb_right = 0;
  656. var->transp.offset = 0;
  657. var->transp.length = 0;
  658. switch (var->bits_per_pixel) {
  659. case 8: /* PSEUDOCOLOUR, 256 */
  660. var->red.offset = 0;
  661. var->red.length = 8;
  662. var->green.offset = 0;
  663. var->green.length = 8;
  664. var->blue.offset = 0;
  665. var->blue.length = 8;
  666. break;
  667. case 16:/* DIRECTCOLOUR, 64k or 32k */
  668. switch (var->green.length) {
  669. case 6: /* RGB565, 64k */
  670. var->red.offset = 11;
  671. var->red.length = 5;
  672. var->green.offset = 5;
  673. var->green.length = 6;
  674. var->blue.offset = 0;
  675. var->blue.length = 5;
  676. break;
  677. default:
  678. case 5: /* RGB555, 32k */
  679. var->red.offset = 10;
  680. var->red.length = 5;
  681. var->green.offset = 5;
  682. var->green.length = 5;
  683. var->blue.offset = 0;
  684. var->blue.length = 5;
  685. break;
  686. case 4: /* RGB444, 4k + transparency? */
  687. var->transp.offset = 12;
  688. var->transp.length = 4;
  689. var->red.offset = 8;
  690. var->red.length = 4;
  691. var->green.offset = 4;
  692. var->green.length = 4;
  693. var->blue.offset = 0;
  694. var->blue.length = 4;
  695. break;
  696. }
  697. break;
  698. case 24:/* TRUECOLOUR, 16m */
  699. var->red.offset = 16;
  700. var->red.length = 8;
  701. var->green.offset = 8;
  702. var->green.length = 8;
  703. var->blue.offset = 0;
  704. var->blue.length = 8;
  705. break;
  706. case 32:/* TRUECOLOUR, 16m */
  707. var->transp.offset = 24;
  708. var->transp.length = 8;
  709. var->red.offset = 16;
  710. var->red.length = 8;
  711. var->green.offset = 8;
  712. var->green.length = 8;
  713. var->blue.offset = 0;
  714. var->blue.length = 8;
  715. break;
  716. default:
  717. return -EINVAL;
  718. }
  719. mem = var->xres_virtual * var->yres_virtual * (var->bits_per_pixel / 8);
  720. if (mem > cfb->fb.fix.smem_len)
  721. var->yres_virtual = cfb->fb.fix.smem_len * 8 /
  722. (var->bits_per_pixel * var->xres_virtual);
  723. if (var->yres > var->yres_virtual)
  724. var->yres = var->yres_virtual;
  725. if (var->xres > var->xres_virtual)
  726. var->xres = var->xres_virtual;
  727. err = cyber2000fb_decode_clock(&hw, cfb, var);
  728. if (err)
  729. return err;
  730. err = cyber2000fb_decode_crtc(&hw, cfb, var);
  731. if (err)
  732. return err;
  733. return 0;
  734. }
  735. static int cyber2000fb_set_par(struct fb_info *info)
  736. {
  737. struct cfb_info *cfb = (struct cfb_info *)info;
  738. struct fb_var_screeninfo *var = &cfb->fb.var;
  739. struct par_info hw;
  740. unsigned int mem;
  741. hw.width = var->xres_virtual;
  742. hw.ramdac = RAMDAC_VREFEN | RAMDAC_DAC8BIT;
  743. switch (var->bits_per_pixel) {
  744. case 8:
  745. hw.co_pixfmt = CO_PIXFMT_8BPP;
  746. hw.pitch = hw.width >> 3;
  747. hw.extseqmisc = EXT_SEQ_MISC_8;
  748. break;
  749. case 16:
  750. hw.co_pixfmt = CO_PIXFMT_16BPP;
  751. hw.pitch = hw.width >> 2;
  752. switch (var->green.length) {
  753. case 6: /* RGB565, 64k */
  754. hw.extseqmisc = EXT_SEQ_MISC_16_RGB565;
  755. break;
  756. case 5: /* RGB555, 32k */
  757. hw.extseqmisc = EXT_SEQ_MISC_16_RGB555;
  758. break;
  759. case 4: /* RGB444, 4k + transparency? */
  760. hw.extseqmisc = EXT_SEQ_MISC_16_RGB444;
  761. break;
  762. default:
  763. BUG();
  764. }
  765. break;
  766. case 24:/* TRUECOLOUR, 16m */
  767. hw.co_pixfmt = CO_PIXFMT_24BPP;
  768. hw.width *= 3;
  769. hw.pitch = hw.width >> 3;
  770. hw.ramdac |= (RAMDAC_BYPASS | RAMDAC_RAMPWRDN);
  771. hw.extseqmisc = EXT_SEQ_MISC_24_RGB888;
  772. break;
  773. case 32:/* TRUECOLOUR, 16m */
  774. hw.co_pixfmt = CO_PIXFMT_32BPP;
  775. hw.pitch = hw.width >> 1;
  776. hw.ramdac |= (RAMDAC_BYPASS | RAMDAC_RAMPWRDN);
  777. hw.extseqmisc = EXT_SEQ_MISC_32;
  778. break;
  779. default:
  780. BUG();
  781. }
  782. /*
  783. * Sigh, this is absolutely disgusting, but caused by
  784. * the way the fbcon developers want to separate out
  785. * the "checking" and the "setting" of the video mode.
  786. *
  787. * If the mode is not suitable for the hardware here,
  788. * we can't prevent it being set by returning an error.
  789. *
  790. * In theory, since NetWinders contain just one VGA card,
  791. * we should never end up hitting this problem.
  792. */
  793. BUG_ON(cyber2000fb_decode_clock(&hw, cfb, var) != 0);
  794. BUG_ON(cyber2000fb_decode_crtc(&hw, cfb, var) != 0);
  795. hw.width -= 1;
  796. hw.fetch = hw.pitch;
  797. if (!(cfb->mem_ctl2 & MEM_CTL2_64BIT))
  798. hw.fetch <<= 1;
  799. hw.fetch += 1;
  800. cfb->fb.fix.line_length = var->xres_virtual * var->bits_per_pixel / 8;
  801. /*
  802. * Same here - if the size of the video mode exceeds the
  803. * available RAM, we can't prevent this mode being set.
  804. *
  805. * In theory, since NetWinders contain just one VGA card,
  806. * we should never end up hitting this problem.
  807. */
  808. mem = cfb->fb.fix.line_length * var->yres_virtual;
  809. BUG_ON(mem > cfb->fb.fix.smem_len);
  810. /*
  811. * 8bpp displays are always pseudo colour. 16bpp and above
  812. * are direct colour or true colour, depending on whether
  813. * the RAMDAC palettes are bypassed. (Direct colour has
  814. * palettes, true colour does not.)
  815. */
  816. if (var->bits_per_pixel == 8)
  817. cfb->fb.fix.visual = FB_VISUAL_PSEUDOCOLOR;
  818. else if (hw.ramdac & RAMDAC_BYPASS)
  819. cfb->fb.fix.visual = FB_VISUAL_TRUECOLOR;
  820. else
  821. cfb->fb.fix.visual = FB_VISUAL_DIRECTCOLOR;
  822. cyber2000fb_set_timing(cfb, &hw);
  823. cyber2000fb_update_start(cfb, var);
  824. return 0;
  825. }
  826. /*
  827. * Pan or Wrap the Display
  828. */
  829. static int
  830. cyber2000fb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
  831. {
  832. struct cfb_info *cfb = (struct cfb_info *)info;
  833. if (cyber2000fb_update_start(cfb, var))
  834. return -EINVAL;
  835. cfb->fb.var.xoffset = var->xoffset;
  836. cfb->fb.var.yoffset = var->yoffset;
  837. if (var->vmode & FB_VMODE_YWRAP) {
  838. cfb->fb.var.vmode |= FB_VMODE_YWRAP;
  839. } else {
  840. cfb->fb.var.vmode &= ~FB_VMODE_YWRAP;
  841. }
  842. return 0;
  843. }
  844. /*
  845. * (Un)Blank the display.
  846. *
  847. * Blank the screen if blank_mode != 0, else unblank. If
  848. * blank == NULL then the caller blanks by setting the CLUT
  849. * (Color Look Up Table) to all black. Return 0 if blanking
  850. * succeeded, != 0 if un-/blanking failed due to e.g. a
  851. * video mode which doesn't support it. Implements VESA
  852. * suspend and powerdown modes on hardware that supports
  853. * disabling hsync/vsync:
  854. * blank_mode == 2: suspend vsync
  855. * blank_mode == 3: suspend hsync
  856. * blank_mode == 4: powerdown
  857. *
  858. * wms...Enable VESA DMPS compatible powerdown mode
  859. * run "setterm -powersave powerdown" to take advantage
  860. */
  861. static int cyber2000fb_blank(int blank, struct fb_info *info)
  862. {
  863. struct cfb_info *cfb = (struct cfb_info *)info;
  864. unsigned int sync = 0;
  865. int i;
  866. switch (blank) {
  867. case FB_BLANK_POWERDOWN: /* powerdown - both sync lines down */
  868. sync = EXT_SYNC_CTL_VS_0 | EXT_SYNC_CTL_HS_0;
  869. break;
  870. case FB_BLANK_HSYNC_SUSPEND: /* hsync off */
  871. sync = EXT_SYNC_CTL_VS_NORMAL | EXT_SYNC_CTL_HS_0;
  872. break;
  873. case FB_BLANK_VSYNC_SUSPEND: /* vsync off */
  874. sync = EXT_SYNC_CTL_VS_0 | EXT_SYNC_CTL_HS_NORMAL;
  875. break;
  876. case FB_BLANK_NORMAL: /* soft blank */
  877. default: /* unblank */
  878. break;
  879. }
  880. cyber2000_grphw(EXT_SYNC_CTL, sync, cfb);
  881. if (blank <= 1) {
  882. /* turn on ramdacs */
  883. cfb->ramdac_powerdown &= ~(RAMDAC_DACPWRDN | RAMDAC_BYPASS |
  884. RAMDAC_RAMPWRDN);
  885. cyber2000fb_write_ramdac_ctrl(cfb);
  886. }
  887. /*
  888. * Soft blank/unblank the display.
  889. */
  890. if (blank) { /* soft blank */
  891. for (i = 0; i < NR_PALETTE; i++) {
  892. cyber2000fb_writeb(i, 0x3c8, cfb);
  893. cyber2000fb_writeb(0, 0x3c9, cfb);
  894. cyber2000fb_writeb(0, 0x3c9, cfb);
  895. cyber2000fb_writeb(0, 0x3c9, cfb);
  896. }
  897. } else { /* unblank */
  898. for (i = 0; i < NR_PALETTE; i++) {
  899. cyber2000fb_writeb(i, 0x3c8, cfb);
  900. cyber2000fb_writeb(cfb->palette[i].red, 0x3c9, cfb);
  901. cyber2000fb_writeb(cfb->palette[i].green, 0x3c9, cfb);
  902. cyber2000fb_writeb(cfb->palette[i].blue, 0x3c9, cfb);
  903. }
  904. }
  905. if (blank >= 2) {
  906. /* turn off ramdacs */
  907. cfb->ramdac_powerdown |= RAMDAC_DACPWRDN | RAMDAC_BYPASS |
  908. RAMDAC_RAMPWRDN;
  909. cyber2000fb_write_ramdac_ctrl(cfb);
  910. }
  911. return 0;
  912. }
  913. static struct fb_ops cyber2000fb_ops = {
  914. .owner = THIS_MODULE,
  915. .fb_check_var = cyber2000fb_check_var,
  916. .fb_set_par = cyber2000fb_set_par,
  917. .fb_setcolreg = cyber2000fb_setcolreg,
  918. .fb_blank = cyber2000fb_blank,
  919. .fb_pan_display = cyber2000fb_pan_display,
  920. .fb_fillrect = cyber2000fb_fillrect,
  921. .fb_copyarea = cyber2000fb_copyarea,
  922. .fb_imageblit = cyber2000fb_imageblit,
  923. .fb_sync = cyber2000fb_sync,
  924. };
  925. /*
  926. * This is the only "static" reference to the internal data structures
  927. * of this driver. It is here solely at the moment to support the other
  928. * CyberPro modules external to this driver.
  929. */
  930. static struct cfb_info *int_cfb_info;
  931. /*
  932. * Enable access to the extended registers
  933. */
  934. void cyber2000fb_enable_extregs(struct cfb_info *cfb)
  935. {
  936. cfb->func_use_count += 1;
  937. if (cfb->func_use_count == 1) {
  938. int old;
  939. old = cyber2000_grphr(EXT_FUNC_CTL, cfb);
  940. old |= EXT_FUNC_CTL_EXTREGENBL;
  941. cyber2000_grphw(EXT_FUNC_CTL, old, cfb);
  942. }
  943. }
  944. EXPORT_SYMBOL(cyber2000fb_enable_extregs);
  945. /*
  946. * Disable access to the extended registers
  947. */
  948. void cyber2000fb_disable_extregs(struct cfb_info *cfb)
  949. {
  950. if (cfb->func_use_count == 1) {
  951. int old;
  952. old = cyber2000_grphr(EXT_FUNC_CTL, cfb);
  953. old &= ~EXT_FUNC_CTL_EXTREGENBL;
  954. cyber2000_grphw(EXT_FUNC_CTL, old, cfb);
  955. }
  956. if (cfb->func_use_count == 0)
  957. printk(KERN_ERR "disable_extregs: count = 0\n");
  958. else
  959. cfb->func_use_count -= 1;
  960. }
  961. EXPORT_SYMBOL(cyber2000fb_disable_extregs);
  962. /*
  963. * Attach a capture/tv driver to the core CyberX0X0 driver.
  964. */
  965. int cyber2000fb_attach(struct cyberpro_info *info, int idx)
  966. {
  967. if (int_cfb_info != NULL) {
  968. info->dev = int_cfb_info->fb.device;
  969. #ifdef CONFIG_FB_CYBER2000_I2C
  970. info->i2c = &int_cfb_info->i2c_adapter;
  971. #else
  972. info->i2c = NULL;
  973. #endif
  974. info->regs = int_cfb_info->regs;
  975. info->irq = int_cfb_info->irq;
  976. info->fb = int_cfb_info->fb.screen_base;
  977. info->fb_size = int_cfb_info->fb.fix.smem_len;
  978. info->info = int_cfb_info;
  979. strlcpy(info->dev_name, int_cfb_info->fb.fix.id,
  980. sizeof(info->dev_name));
  981. }
  982. return int_cfb_info != NULL;
  983. }
  984. EXPORT_SYMBOL(cyber2000fb_attach);
  985. /*
  986. * Detach a capture/tv driver from the core CyberX0X0 driver.
  987. */
  988. void cyber2000fb_detach(int idx)
  989. {
  990. }
  991. EXPORT_SYMBOL(cyber2000fb_detach);
  992. #ifdef CONFIG_FB_CYBER2000_DDC
  993. #define DDC_REG 0xb0
  994. #define DDC_SCL_OUT (1 << 0)
  995. #define DDC_SDA_OUT (1 << 4)
  996. #define DDC_SCL_IN (1 << 2)
  997. #define DDC_SDA_IN (1 << 6)
  998. static void cyber2000fb_enable_ddc(struct cfb_info *cfb)
  999. {
  1000. spin_lock(&cfb->reg_b0_lock);
  1001. cyber2000fb_writew(0x1bf, 0x3ce, cfb);
  1002. }
  1003. static void cyber2000fb_disable_ddc(struct cfb_info *cfb)
  1004. {
  1005. cyber2000fb_writew(0x0bf, 0x3ce, cfb);
  1006. spin_unlock(&cfb->reg_b0_lock);
  1007. }
  1008. static void cyber2000fb_ddc_setscl(void *data, int val)
  1009. {
  1010. struct cfb_info *cfb = data;
  1011. unsigned char reg;
  1012. cyber2000fb_enable_ddc(cfb);
  1013. reg = cyber2000_grphr(DDC_REG, cfb);
  1014. if (!val) /* bit is inverted */
  1015. reg |= DDC_SCL_OUT;
  1016. else
  1017. reg &= ~DDC_SCL_OUT;
  1018. cyber2000_grphw(DDC_REG, reg, cfb);
  1019. cyber2000fb_disable_ddc(cfb);
  1020. }
  1021. static void cyber2000fb_ddc_setsda(void *data, int val)
  1022. {
  1023. struct cfb_info *cfb = data;
  1024. unsigned char reg;
  1025. cyber2000fb_enable_ddc(cfb);
  1026. reg = cyber2000_grphr(DDC_REG, cfb);
  1027. if (!val) /* bit is inverted */
  1028. reg |= DDC_SDA_OUT;
  1029. else
  1030. reg &= ~DDC_SDA_OUT;
  1031. cyber2000_grphw(DDC_REG, reg, cfb);
  1032. cyber2000fb_disable_ddc(cfb);
  1033. }
  1034. static int cyber2000fb_ddc_getscl(void *data)
  1035. {
  1036. struct cfb_info *cfb = data;
  1037. int retval;
  1038. cyber2000fb_enable_ddc(cfb);
  1039. retval = !!(cyber2000_grphr(DDC_REG, cfb) & DDC_SCL_IN);
  1040. cyber2000fb_disable_ddc(cfb);
  1041. return retval;
  1042. }
  1043. static int cyber2000fb_ddc_getsda(void *data)
  1044. {
  1045. struct cfb_info *cfb = data;
  1046. int retval;
  1047. cyber2000fb_enable_ddc(cfb);
  1048. retval = !!(cyber2000_grphr(DDC_REG, cfb) & DDC_SDA_IN);
  1049. cyber2000fb_disable_ddc(cfb);
  1050. return retval;
  1051. }
  1052. static int __devinit cyber2000fb_setup_ddc_bus(struct cfb_info *cfb)
  1053. {
  1054. strlcpy(cfb->ddc_adapter.name, cfb->fb.fix.id,
  1055. sizeof(cfb->ddc_adapter.name));
  1056. cfb->ddc_adapter.owner = THIS_MODULE;
  1057. cfb->ddc_adapter.class = I2C_CLASS_DDC;
  1058. cfb->ddc_adapter.algo_data = &cfb->ddc_algo;
  1059. cfb->ddc_adapter.dev.parent = cfb->fb.device;
  1060. cfb->ddc_algo.setsda = cyber2000fb_ddc_setsda;
  1061. cfb->ddc_algo.setscl = cyber2000fb_ddc_setscl;
  1062. cfb->ddc_algo.getsda = cyber2000fb_ddc_getsda;
  1063. cfb->ddc_algo.getscl = cyber2000fb_ddc_getscl;
  1064. cfb->ddc_algo.udelay = 10;
  1065. cfb->ddc_algo.timeout = 20;
  1066. cfb->ddc_algo.data = cfb;
  1067. i2c_set_adapdata(&cfb->ddc_adapter, cfb);
  1068. return i2c_bit_add_bus(&cfb->ddc_adapter);
  1069. }
  1070. #endif /* CONFIG_FB_CYBER2000_DDC */
  1071. #ifdef CONFIG_FB_CYBER2000_I2C
  1072. static void cyber2000fb_i2c_setsda(void *data, int state)
  1073. {
  1074. struct cfb_info *cfb = data;
  1075. unsigned int latch2;
  1076. spin_lock(&cfb->reg_b0_lock);
  1077. latch2 = cyber2000_grphr(EXT_LATCH2, cfb);
  1078. latch2 &= EXT_LATCH2_I2C_CLKEN;
  1079. if (state)
  1080. latch2 |= EXT_LATCH2_I2C_DATEN;
  1081. cyber2000_grphw(EXT_LATCH2, latch2, cfb);
  1082. spin_unlock(&cfb->reg_b0_lock);
  1083. }
  1084. static void cyber2000fb_i2c_setscl(void *data, int state)
  1085. {
  1086. struct cfb_info *cfb = data;
  1087. unsigned int latch2;
  1088. spin_lock(&cfb->reg_b0_lock);
  1089. latch2 = cyber2000_grphr(EXT_LATCH2, cfb);
  1090. latch2 &= EXT_LATCH2_I2C_DATEN;
  1091. if (state)
  1092. latch2 |= EXT_LATCH2_I2C_CLKEN;
  1093. cyber2000_grphw(EXT_LATCH2, latch2, cfb);
  1094. spin_unlock(&cfb->reg_b0_lock);
  1095. }
  1096. static int cyber2000fb_i2c_getsda(void *data)
  1097. {
  1098. struct cfb_info *cfb = data;
  1099. int ret;
  1100. spin_lock(&cfb->reg_b0_lock);
  1101. ret = !!(cyber2000_grphr(EXT_LATCH2, cfb) & EXT_LATCH2_I2C_DAT);
  1102. spin_unlock(&cfb->reg_b0_lock);
  1103. return ret;
  1104. }
  1105. static int cyber2000fb_i2c_getscl(void *data)
  1106. {
  1107. struct cfb_info *cfb = data;
  1108. int ret;
  1109. spin_lock(&cfb->reg_b0_lock);
  1110. ret = !!(cyber2000_grphr(EXT_LATCH2, cfb) & EXT_LATCH2_I2C_CLK);
  1111. spin_unlock(&cfb->reg_b0_lock);
  1112. return ret;
  1113. }
  1114. static int __devinit cyber2000fb_i2c_register(struct cfb_info *cfb)
  1115. {
  1116. strlcpy(cfb->i2c_adapter.name, cfb->fb.fix.id,
  1117. sizeof(cfb->i2c_adapter.name));
  1118. cfb->i2c_adapter.owner = THIS_MODULE;
  1119. cfb->i2c_adapter.algo_data = &cfb->i2c_algo;
  1120. cfb->i2c_adapter.dev.parent = cfb->fb.device;
  1121. cfb->i2c_algo.setsda = cyber2000fb_i2c_setsda;
  1122. cfb->i2c_algo.setscl = cyber2000fb_i2c_setscl;
  1123. cfb->i2c_algo.getsda = cyber2000fb_i2c_getsda;
  1124. cfb->i2c_algo.getscl = cyber2000fb_i2c_getscl;
  1125. cfb->i2c_algo.udelay = 5;
  1126. cfb->i2c_algo.timeout = msecs_to_jiffies(100);
  1127. cfb->i2c_algo.data = cfb;
  1128. return i2c_bit_add_bus(&cfb->i2c_adapter);
  1129. }
  1130. static void cyber2000fb_i2c_unregister(struct cfb_info *cfb)
  1131. {
  1132. i2c_del_adapter(&cfb->i2c_adapter);
  1133. }
  1134. #else
  1135. #define cyber2000fb_i2c_register(cfb) (0)
  1136. #define cyber2000fb_i2c_unregister(cfb) do { } while (0)
  1137. #endif
  1138. /*
  1139. * These parameters give
  1140. * 640x480, hsync 31.5kHz, vsync 60Hz
  1141. */
  1142. static struct fb_videomode __devinitdata cyber2000fb_default_mode = {
  1143. .refresh = 60,
  1144. .xres = 640,
  1145. .yres = 480,
  1146. .pixclock = 39722,
  1147. .left_margin = 56,
  1148. .right_margin = 16,
  1149. .upper_margin = 34,
  1150. .lower_margin = 9,
  1151. .hsync_len = 88,
  1152. .vsync_len = 2,
  1153. .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  1154. .vmode = FB_VMODE_NONINTERLACED
  1155. };
  1156. static char igs_regs[] = {
  1157. EXT_CRT_IRQ, 0,
  1158. EXT_CRT_TEST, 0,
  1159. EXT_SYNC_CTL, 0,
  1160. EXT_SEG_WRITE_PTR, 0,
  1161. EXT_SEG_READ_PTR, 0,
  1162. EXT_BIU_MISC, EXT_BIU_MISC_LIN_ENABLE |
  1163. EXT_BIU_MISC_COP_ENABLE |
  1164. EXT_BIU_MISC_COP_BFC,
  1165. EXT_FUNC_CTL, 0,
  1166. CURS_H_START, 0,
  1167. CURS_H_START + 1, 0,
  1168. CURS_H_PRESET, 0,
  1169. CURS_V_START, 0,
  1170. CURS_V_START + 1, 0,
  1171. CURS_V_PRESET, 0,
  1172. CURS_CTL, 0,
  1173. EXT_ATTRIB_CTL, EXT_ATTRIB_CTL_EXT,
  1174. EXT_OVERSCAN_RED, 0,
  1175. EXT_OVERSCAN_GREEN, 0,
  1176. EXT_OVERSCAN_BLUE, 0,
  1177. /* some of these are questionable when we have a BIOS */
  1178. EXT_MEM_CTL0, EXT_MEM_CTL0_7CLK |
  1179. EXT_MEM_CTL0_RAS_1 |
  1180. EXT_MEM_CTL0_MULTCAS,
  1181. EXT_HIDDEN_CTL1, 0x30,
  1182. EXT_FIFO_CTL, 0x0b,
  1183. EXT_FIFO_CTL + 1, 0x17,
  1184. 0x76, 0x00,
  1185. EXT_HIDDEN_CTL4, 0xc8
  1186. };
  1187. /*
  1188. * Initialise the CyberPro hardware. On the CyberPro5XXXX,
  1189. * ensure that we're using the correct PLL (5XXX's may be
  1190. * programmed to use an additional set of PLLs.)
  1191. */
  1192. static void cyberpro_init_hw(struct cfb_info *cfb)
  1193. {
  1194. int i;
  1195. for (i = 0; i < sizeof(igs_regs); i += 2)
  1196. cyber2000_grphw(igs_regs[i], igs_regs[i + 1], cfb);
  1197. if (cfb->id == ID_CYBERPRO_5000) {
  1198. unsigned char val;
  1199. cyber2000fb_writeb(0xba, 0x3ce, cfb);
  1200. val = cyber2000fb_readb(0x3cf, cfb) & 0x80;
  1201. cyber2000fb_writeb(val, 0x3cf, cfb);
  1202. }
  1203. }
  1204. static struct cfb_info __devinit *cyberpro_alloc_fb_info(unsigned int id,
  1205. char *name)
  1206. {
  1207. struct cfb_info *cfb;
  1208. cfb = kzalloc(sizeof(struct cfb_info), GFP_KERNEL);
  1209. if (!cfb)
  1210. return NULL;
  1211. cfb->id = id;
  1212. if (id == ID_CYBERPRO_5000)
  1213. cfb->ref_ps = 40690; /* 24.576 MHz */
  1214. else
  1215. cfb->ref_ps = 69842; /* 14.31818 MHz (69841?) */
  1216. cfb->divisors[0] = 1;
  1217. cfb->divisors[1] = 2;
  1218. cfb->divisors[2] = 4;
  1219. if (id == ID_CYBERPRO_2000)
  1220. cfb->divisors[3] = 8;
  1221. else
  1222. cfb->divisors[3] = 6;
  1223. strcpy(cfb->fb.fix.id, name);
  1224. cfb->fb.fix.type = FB_TYPE_PACKED_PIXELS;
  1225. cfb->fb.fix.type_aux = 0;
  1226. cfb->fb.fix.xpanstep = 0;
  1227. cfb->fb.fix.ypanstep = 1;
  1228. cfb->fb.fix.ywrapstep = 0;
  1229. switch (id) {
  1230. case ID_IGA_1682:
  1231. cfb->fb.fix.accel = 0;
  1232. break;
  1233. case ID_CYBERPRO_2000:
  1234. cfb->fb.fix.accel = FB_ACCEL_IGS_CYBER2000;
  1235. break;
  1236. case ID_CYBERPRO_2010:
  1237. cfb->fb.fix.accel = FB_ACCEL_IGS_CYBER2010;
  1238. break;
  1239. case ID_CYBERPRO_5000:
  1240. cfb->fb.fix.accel = FB_ACCEL_IGS_CYBER5000;
  1241. break;
  1242. }
  1243. cfb->fb.var.nonstd = 0;
  1244. cfb->fb.var.activate = FB_ACTIVATE_NOW;
  1245. cfb->fb.var.height = -1;
  1246. cfb->fb.var.width = -1;
  1247. cfb->fb.var.accel_flags = FB_ACCELF_TEXT;
  1248. cfb->fb.fbops = &cyber2000fb_ops;
  1249. cfb->fb.flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
  1250. cfb->fb.pseudo_palette = cfb->pseudo_palette;
  1251. spin_lock_init(&cfb->reg_b0_lock);
  1252. fb_alloc_cmap(&cfb->fb.cmap, NR_PALETTE, 0);
  1253. return cfb;
  1254. }
  1255. static void cyberpro_free_fb_info(struct cfb_info *cfb)
  1256. {
  1257. if (cfb) {
  1258. /*
  1259. * Free the colourmap
  1260. */
  1261. fb_alloc_cmap(&cfb->fb.cmap, 0, 0);
  1262. kfree(cfb);
  1263. }
  1264. }
  1265. /*
  1266. * Parse Cyber2000fb options. Usage:
  1267. * video=cyber2000:font:fontname
  1268. */
  1269. #ifndef MODULE
  1270. static int cyber2000fb_setup(char *options)
  1271. {
  1272. char *opt;
  1273. if (!options || !*options)
  1274. return 0;
  1275. while ((opt = strsep(&options, ",")) != NULL) {
  1276. if (!*opt)
  1277. continue;
  1278. if (strncmp(opt, "font:", 5) == 0) {
  1279. static char default_font_storage[40];
  1280. strlcpy(default_font_storage, opt + 5,
  1281. sizeof(default_font_storage));
  1282. default_font = default_font_storage;
  1283. continue;
  1284. }
  1285. printk(KERN_ERR "CyberPro20x0: unknown parameter: %s\n", opt);
  1286. }
  1287. return 0;
  1288. }
  1289. #endif /* MODULE */
  1290. /*
  1291. * The CyberPro chips can be placed on many different bus types.
  1292. * This probe function is common to all bus types. The bus-specific
  1293. * probe function is expected to have:
  1294. * - enabled access to the linear memory region
  1295. * - memory mapped access to the registers
  1296. * - initialised mem_ctl1 and mem_ctl2 appropriately.
  1297. */
  1298. static int __devinit cyberpro_common_probe(struct cfb_info *cfb)
  1299. {
  1300. u_long smem_size;
  1301. u_int h_sync, v_sync;
  1302. int err;
  1303. cyberpro_init_hw(cfb);
  1304. /*
  1305. * Get the video RAM size and width from the VGA register.
  1306. * This should have been already initialised by the BIOS,
  1307. * but if it's garbage, claim default 1MB VRAM (woody)
  1308. */
  1309. cfb->mem_ctl1 = cyber2000_grphr(EXT_MEM_CTL1, cfb);
  1310. cfb->mem_ctl2 = cyber2000_grphr(EXT_MEM_CTL2, cfb);
  1311. /*
  1312. * Determine the size of the memory.
  1313. */
  1314. switch (cfb->mem_ctl2 & MEM_CTL2_SIZE_MASK) {
  1315. case MEM_CTL2_SIZE_4MB:
  1316. smem_size = 0x00400000;
  1317. break;
  1318. case MEM_CTL2_SIZE_2MB:
  1319. smem_size = 0x00200000;
  1320. break;
  1321. case MEM_CTL2_SIZE_1MB:
  1322. smem_size = 0x00100000;
  1323. break;
  1324. default:
  1325. smem_size = 0x00100000;
  1326. break;
  1327. }
  1328. cfb->fb.fix.smem_len = smem_size;
  1329. cfb->fb.fix.mmio_len = MMIO_SIZE;
  1330. cfb->fb.screen_base = cfb->region;
  1331. #ifdef CONFIG_FB_CYBER2000_DDC
  1332. if (cyber2000fb_setup_ddc_bus(cfb) == 0)
  1333. cfb->ddc_registered = true;
  1334. #endif
  1335. err = -EINVAL;
  1336. if (!fb_find_mode(&cfb->fb.var, &cfb->fb, NULL, NULL, 0,
  1337. &cyber2000fb_default_mode, 8)) {
  1338. printk(KERN_ERR "%s: no valid mode found\n", cfb->fb.fix.id);
  1339. goto failed;
  1340. }
  1341. cfb->fb.var.yres_virtual = cfb->fb.fix.smem_len * 8 /
  1342. (cfb->fb.var.bits_per_pixel * cfb->fb.var.xres_virtual);
  1343. if (cfb->fb.var.yres_virtual < cfb->fb.var.yres)
  1344. cfb->fb.var.yres_virtual = cfb->fb.var.yres;
  1345. /* fb_set_var(&cfb->fb.var, -1, &cfb->fb); */
  1346. /*
  1347. * Calculate the hsync and vsync frequencies. Note that
  1348. * we split the 1e12 constant up so that we can preserve
  1349. * the precision and fit the results into 32-bit registers.
  1350. * (1953125000 * 512 = 1e12)
  1351. */
  1352. h_sync = 1953125000 / cfb->fb.var.pixclock;
  1353. h_sync = h_sync * 512 / (cfb->fb.var.xres + cfb->fb.var.left_margin +
  1354. cfb->fb.var.right_margin + cfb->fb.var.hsync_len);
  1355. v_sync = h_sync / (cfb->fb.var.yres + cfb->fb.var.upper_margin +
  1356. cfb->fb.var.lower_margin + cfb->fb.var.vsync_len);
  1357. printk(KERN_INFO "%s: %dKiB VRAM, using %dx%d, %d.%03dkHz, %dHz\n",
  1358. cfb->fb.fix.id, cfb->fb.fix.smem_len >> 10,
  1359. cfb->fb.var.xres, cfb->fb.var.yres,
  1360. h_sync / 1000, h_sync % 1000, v_sync);
  1361. err = cyber2000fb_i2c_register(cfb);
  1362. if (err)
  1363. goto failed;
  1364. err = register_framebuffer(&cfb->fb);
  1365. if (err)
  1366. cyber2000fb_i2c_unregister(cfb);
  1367. failed:
  1368. #ifdef CONFIG_FB_CYBER2000_DDC
  1369. if (err && cfb->ddc_registered)
  1370. i2c_del_adapter(&cfb->ddc_adapter);
  1371. #endif
  1372. return err;
  1373. }
  1374. static void __devexit cyberpro_common_remove(struct cfb_info *cfb)
  1375. {
  1376. unregister_framebuffer(&cfb->fb);
  1377. #ifdef CONFIG_FB_CYBER2000_DDC
  1378. if (cfb->ddc_registered)
  1379. i2c_del_adapter(&cfb->ddc_adapter);
  1380. #endif
  1381. cyber2000fb_i2c_unregister(cfb);
  1382. }
  1383. static void cyberpro_common_resume(struct cfb_info *cfb)
  1384. {
  1385. cyberpro_init_hw(cfb);
  1386. /*
  1387. * Reprogram the MEM_CTL1 and MEM_CTL2 registers
  1388. */
  1389. cyber2000_grphw(EXT_MEM_CTL1, cfb->mem_ctl1, cfb);
  1390. cyber2000_grphw(EXT_MEM_CTL2, cfb->mem_ctl2, cfb);
  1391. /*
  1392. * Restore the old video mode and the palette.
  1393. * We also need to tell fbcon to redraw the console.
  1394. */
  1395. cyber2000fb_set_par(&cfb->fb);
  1396. }
  1397. #ifdef CONFIG_ARCH_SHARK
  1398. #include <mach/framebuffer.h>
  1399. static int __devinit cyberpro_vl_probe(void)
  1400. {
  1401. struct cfb_info *cfb;
  1402. int err = -ENOMEM;
  1403. if (!request_mem_region(FB_START, FB_SIZE, "CyberPro2010"))
  1404. return err;
  1405. cfb = cyberpro_alloc_fb_info(ID_CYBERPRO_2010, "CyberPro2010");
  1406. if (!cfb)
  1407. goto failed_release;
  1408. cfb->irq = -1;
  1409. cfb->region = ioremap(FB_START, FB_SIZE);
  1410. if (!cfb->region)
  1411. goto failed_ioremap;
  1412. cfb->regs = cfb->region + MMIO_OFFSET;
  1413. cfb->fb.device = NULL;
  1414. cfb->fb.fix.mmio_start = FB_START + MMIO_OFFSET;
  1415. cfb->fb.fix.smem_start = FB_START;
  1416. /*
  1417. * Bring up the hardware. This is expected to enable access
  1418. * to the linear memory region, and allow access to the memory
  1419. * mapped registers. Also, mem_ctl1 and mem_ctl2 must be
  1420. * initialised.
  1421. */
  1422. cyber2000fb_writeb(0x18, 0x46e8, cfb);
  1423. cyber2000fb_writeb(0x01, 0x102, cfb);
  1424. cyber2000fb_writeb(0x08, 0x46e8, cfb);
  1425. cyber2000fb_writeb(EXT_BIU_MISC, 0x3ce, cfb);
  1426. cyber2000fb_writeb(EXT_BIU_MISC_LIN_ENABLE, 0x3cf, cfb);
  1427. cfb->mclk_mult = 0xdb;
  1428. cfb->mclk_div = 0x54;
  1429. err = cyberpro_common_probe(cfb);
  1430. if (err)
  1431. goto failed;
  1432. if (int_cfb_info == NULL)
  1433. int_cfb_info = cfb;
  1434. return 0;
  1435. failed:
  1436. iounmap(cfb->region);
  1437. failed_ioremap:
  1438. cyberpro_free_fb_info(cfb);
  1439. failed_release:
  1440. release_mem_region(FB_START, FB_SIZE);
  1441. return err;
  1442. }
  1443. #endif /* CONFIG_ARCH_SHARK */
  1444. /*
  1445. * PCI specific support.
  1446. */
  1447. #ifdef CONFIG_PCI
  1448. /*
  1449. * We need to wake up the CyberPro, and make sure its in linear memory
  1450. * mode. Unfortunately, this is specific to the platform and card that
  1451. * we are running on.
  1452. *
  1453. * On x86 and ARM, should we be initialising the CyberPro first via the
  1454. * IO registers, and then the MMIO registers to catch all cases? Can we
  1455. * end up in the situation where the chip is in MMIO mode, but not awake
  1456. * on an x86 system?
  1457. */
  1458. static int cyberpro_pci_enable_mmio(struct cfb_info *cfb)
  1459. {
  1460. unsigned char val;
  1461. #if defined(__sparc_v9__)
  1462. #error "You lose, consult DaveM."
  1463. #elif defined(__sparc__)
  1464. /*
  1465. * SPARC does not have an "outb" instruction, so we generate
  1466. * I/O cycles storing into a reserved memory space at
  1467. * physical address 0x3000000
  1468. */
  1469. unsigned char __iomem *iop;
  1470. iop = ioremap(0x3000000, 0x5000);
  1471. if (iop == NULL) {
  1472. printk(KERN_ERR "iga5000: cannot map I/O\n");
  1473. return -ENOMEM;
  1474. }
  1475. writeb(0x18, iop + 0x46e8);
  1476. writeb(0x01, iop + 0x102);
  1477. writeb(0x08, iop + 0x46e8);
  1478. writeb(EXT_BIU_MISC, iop + 0x3ce);
  1479. writeb(EXT_BIU_MISC_LIN_ENABLE, iop + 0x3cf);
  1480. iounmap(iop);
  1481. #else
  1482. /*
  1483. * Most other machine types are "normal", so
  1484. * we use the standard IO-based wakeup.
  1485. */
  1486. outb(0x18, 0x46e8);
  1487. outb(0x01, 0x102);
  1488. outb(0x08, 0x46e8);
  1489. outb(EXT_BIU_MISC, 0x3ce);
  1490. outb(EXT_BIU_MISC_LIN_ENABLE, 0x3cf);
  1491. #endif
  1492. /*
  1493. * Allow the CyberPro to accept PCI burst accesses
  1494. */
  1495. if (cfb->id == ID_CYBERPRO_2010) {
  1496. printk(KERN_INFO "%s: NOT enabling PCI bursts\n",
  1497. cfb->fb.fix.id);
  1498. } else {
  1499. val = cyber2000_grphr(EXT_BUS_CTL, cfb);
  1500. if (!(val & EXT_BUS_CTL_PCIBURST_WRITE)) {
  1501. printk(KERN_INFO "%s: enabling PCI bursts\n",
  1502. cfb->fb.fix.id);
  1503. val |= EXT_BUS_CTL_PCIBURST_WRITE;
  1504. if (cfb->id == ID_CYBERPRO_5000)
  1505. val |= EXT_BUS_CTL_PCIBURST_READ;
  1506. cyber2000_grphw(EXT_BUS_CTL, val, cfb);
  1507. }
  1508. }
  1509. return 0;
  1510. }
  1511. static int __devinit
  1512. cyberpro_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
  1513. {
  1514. struct cfb_info *cfb;
  1515. char name[16];
  1516. int err;
  1517. sprintf(name, "CyberPro%4X", id->device);
  1518. err = pci_enable_device(dev);
  1519. if (err)
  1520. return err;
  1521. err = -ENOMEM;
  1522. cfb = cyberpro_alloc_fb_info(id->driver_data, name);
  1523. if (!cfb)
  1524. goto failed_release;
  1525. err = pci_request_regions(dev, cfb->fb.fix.id);
  1526. if (err)
  1527. goto failed_regions;
  1528. cfb->irq = dev->irq;
  1529. cfb->region = pci_ioremap_bar(dev, 0);
  1530. if (!cfb->region)
  1531. goto failed_ioremap;
  1532. cfb->regs = cfb->region + MMIO_OFFSET;
  1533. cfb->fb.device = &dev->dev;
  1534. cfb->fb.fix.mmio_start = pci_resource_start(dev, 0) + MMIO_OFFSET;
  1535. cfb->fb.fix.smem_start = pci_resource_start(dev, 0);
  1536. /*
  1537. * Bring up the hardware. This is expected to enable access
  1538. * to the linear memory region, and allow access to the memory
  1539. * mapped registers. Also, mem_ctl1 and mem_ctl2 must be
  1540. * initialised.
  1541. */
  1542. err = cyberpro_pci_enable_mmio(cfb);
  1543. if (err)
  1544. goto failed;
  1545. /*
  1546. * Use MCLK from BIOS. FIXME: what about hotplug?
  1547. */
  1548. cfb->mclk_mult = cyber2000_grphr(EXT_MCLK_MULT, cfb);
  1549. cfb->mclk_div = cyber2000_grphr(EXT_MCLK_DIV, cfb);
  1550. #ifdef __arm__
  1551. /*
  1552. * MCLK on the NetWinder and the Shark is fixed at 75MHz
  1553. */
  1554. if (machine_is_netwinder()) {
  1555. cfb->mclk_mult = 0xdb;
  1556. cfb->mclk_div = 0x54;
  1557. }
  1558. #endif
  1559. err = cyberpro_common_probe(cfb);
  1560. if (err)
  1561. goto failed;
  1562. /*
  1563. * Our driver data
  1564. */
  1565. pci_set_drvdata(dev, cfb);
  1566. if (int_cfb_info == NULL)
  1567. int_cfb_info = cfb;
  1568. return 0;
  1569. failed:
  1570. iounmap(cfb->region);
  1571. failed_ioremap:
  1572. pci_release_regions(dev);
  1573. failed_regions:
  1574. cyberpro_free_fb_info(cfb);
  1575. failed_release:
  1576. return err;
  1577. }
  1578. static void __devexit cyberpro_pci_remove(struct pci_dev *dev)
  1579. {
  1580. struct cfb_info *cfb = pci_get_drvdata(dev);
  1581. if (cfb) {
  1582. cyberpro_common_remove(cfb);
  1583. iounmap(cfb->region);
  1584. cyberpro_free_fb_info(cfb);
  1585. /*
  1586. * Ensure that the driver data is no longer
  1587. * valid.
  1588. */
  1589. pci_set_drvdata(dev, NULL);
  1590. if (cfb == int_cfb_info)
  1591. int_cfb_info = NULL;
  1592. pci_release_regions(dev);
  1593. }
  1594. }
  1595. static int cyberpro_pci_suspend(struct pci_dev *dev, pm_message_t state)
  1596. {
  1597. return 0;
  1598. }
  1599. /*
  1600. * Re-initialise the CyberPro hardware
  1601. */
  1602. static int cyberpro_pci_resume(struct pci_dev *dev)
  1603. {
  1604. struct cfb_info *cfb = pci_get_drvdata(dev);
  1605. if (cfb) {
  1606. cyberpro_pci_enable_mmio(cfb);
  1607. cyberpro_common_resume(cfb);
  1608. }
  1609. return 0;
  1610. }
  1611. static struct pci_device_id cyberpro_pci_table[] = {
  1612. /* Not yet
  1613. * { PCI_VENDOR_ID_INTERG, PCI_DEVICE_ID_INTERG_1682,
  1614. * PCI_ANY_ID, PCI_ANY_ID, 0, 0, ID_IGA_1682 },
  1615. */
  1616. { PCI_VENDOR_ID_INTERG, PCI_DEVICE_ID_INTERG_2000,
  1617. PCI_ANY_ID, PCI_ANY_ID, 0, 0, ID_CYBERPRO_2000 },
  1618. { PCI_VENDOR_ID_INTERG, PCI_DEVICE_ID_INTERG_2010,
  1619. PCI_ANY_ID, PCI_ANY_ID, 0, 0, ID_CYBERPRO_2010 },
  1620. { PCI_VENDOR_ID_INTERG, PCI_DEVICE_ID_INTERG_5000,
  1621. PCI_ANY_ID, PCI_ANY_ID, 0, 0, ID_CYBERPRO_5000 },
  1622. { 0, }
  1623. };
  1624. MODULE_DEVICE_TABLE(pci, cyberpro_pci_table);
  1625. static struct pci_driver cyberpro_driver = {
  1626. .name = "CyberPro",
  1627. .probe = cyberpro_pci_probe,
  1628. .remove = __devexit_p(cyberpro_pci_remove),
  1629. .suspend = cyberpro_pci_suspend,
  1630. .resume = cyberpro_pci_resume,
  1631. .id_table = cyberpro_pci_table
  1632. };
  1633. #endif
  1634. /*
  1635. * I don't think we can use the "module_init" stuff here because
  1636. * the fbcon stuff may not be initialised yet. Hence the #ifdef
  1637. * around module_init.
  1638. *
  1639. * Tony: "module_init" is now required
  1640. */
  1641. static int __init cyber2000fb_init(void)
  1642. {
  1643. int ret = -1, err;
  1644. #ifndef MODULE
  1645. char *option = NULL;
  1646. if (fb_get_options("cyber2000fb", &option))
  1647. return -ENODEV;
  1648. cyber2000fb_setup(option);
  1649. #endif
  1650. #ifdef CONFIG_ARCH_SHARK
  1651. err = cyberpro_vl_probe();
  1652. if (!err)
  1653. ret = 0;
  1654. #endif
  1655. #ifdef CONFIG_PCI
  1656. err = pci_register_driver(&cyberpro_driver);
  1657. if (!err)
  1658. ret = 0;
  1659. #endif
  1660. return ret ? err : 0;
  1661. }
  1662. module_init(cyber2000fb_init);
  1663. #ifndef CONFIG_ARCH_SHARK
  1664. static void __exit cyberpro_exit(void)
  1665. {
  1666. pci_unregister_driver(&cyberpro_driver);
  1667. }
  1668. module_exit(cyberpro_exit);
  1669. #endif
  1670. MODULE_AUTHOR("Russell King");
  1671. MODULE_DESCRIPTION("CyberPro 2000, 2010 and 5000 framebuffer driver");
  1672. MODULE_LICENSE("GPL");