cyber2000fb.c 46 KB

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