asiliantfb.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626
  1. /*
  2. * drivers/video/asiliantfb.c
  3. * frame buffer driver for Asiliant 69000 chip
  4. * Copyright (C) 2001-2003 Saito.K & Jeanne
  5. *
  6. * from driver/video/chipsfb.c and,
  7. *
  8. * drivers/video/asiliantfb.c -- frame buffer device for
  9. * Asiliant 69030 chip (formerly Intel, formerly Chips & Technologies)
  10. * Author: apc@agelectronics.co.uk
  11. * Copyright (C) 2000 AG Electronics
  12. * Note: the data sheets don't seem to be available from Asiliant.
  13. * They are available by searching developer.intel.com, but are not otherwise
  14. * linked to.
  15. *
  16. * This driver should be portable with minimal effort to the 69000 display
  17. * chip, and to the twin-display mode of the 69030.
  18. * Contains code from Thomas Hhenleitner <th@visuelle-maschinen.de> (thanks)
  19. *
  20. * Derived from the CT65550 driver chipsfb.c:
  21. * Copyright (C) 1998 Paul Mackerras
  22. * ...which was derived from the Powermac "chips" driver:
  23. * Copyright (C) 1997 Fabio Riccardi.
  24. * And from the frame buffer device for Open Firmware-initialized devices:
  25. * Copyright (C) 1997 Geert Uytterhoeven.
  26. *
  27. * This file is subject to the terms and conditions of the GNU General Public
  28. * License. See the file COPYING in the main directory of this archive for
  29. * more details.
  30. */
  31. #include <linux/module.h>
  32. #include <linux/kernel.h>
  33. #include <linux/errno.h>
  34. #include <linux/string.h>
  35. #include <linux/mm.h>
  36. #include <linux/vmalloc.h>
  37. #include <linux/delay.h>
  38. #include <linux/interrupt.h>
  39. #include <linux/fb.h>
  40. #include <linux/init.h>
  41. #include <linux/pci.h>
  42. #include <asm/io.h>
  43. /* Built in clock of the 69030 */
  44. static const unsigned Fref = 14318180;
  45. #define mmio_base (p->screen_base + 0x400000)
  46. #define mm_write_ind(num, val, ap, dp) do { \
  47. writeb((num), mmio_base + (ap)); writeb((val), mmio_base + (dp)); \
  48. } while (0)
  49. static void mm_write_xr(struct fb_info *p, u8 reg, u8 data)
  50. {
  51. mm_write_ind(reg, data, 0x7ac, 0x7ad);
  52. }
  53. #define write_xr(num, val) mm_write_xr(p, num, val)
  54. static void mm_write_fr(struct fb_info *p, u8 reg, u8 data)
  55. {
  56. mm_write_ind(reg, data, 0x7a0, 0x7a1);
  57. }
  58. #define write_fr(num, val) mm_write_fr(p, num, val)
  59. static void mm_write_cr(struct fb_info *p, u8 reg, u8 data)
  60. {
  61. mm_write_ind(reg, data, 0x7a8, 0x7a9);
  62. }
  63. #define write_cr(num, val) mm_write_cr(p, num, val)
  64. static void mm_write_gr(struct fb_info *p, u8 reg, u8 data)
  65. {
  66. mm_write_ind(reg, data, 0x79c, 0x79d);
  67. }
  68. #define write_gr(num, val) mm_write_gr(p, num, val)
  69. static void mm_write_sr(struct fb_info *p, u8 reg, u8 data)
  70. {
  71. mm_write_ind(reg, data, 0x788, 0x789);
  72. }
  73. #define write_sr(num, val) mm_write_sr(p, num, val)
  74. static void mm_write_ar(struct fb_info *p, u8 reg, u8 data)
  75. {
  76. readb(mmio_base + 0x7b4);
  77. mm_write_ind(reg, data, 0x780, 0x780);
  78. }
  79. #define write_ar(num, val) mm_write_ar(p, num, val)
  80. static int asiliantfb_pci_init(struct pci_dev *dp, const struct pci_device_id *);
  81. static int asiliantfb_check_var(struct fb_var_screeninfo *var,
  82. struct fb_info *info);
  83. static int asiliantfb_set_par(struct fb_info *info);
  84. static int asiliantfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
  85. u_int transp, struct fb_info *info);
  86. static struct fb_ops asiliantfb_ops = {
  87. .owner = THIS_MODULE,
  88. .fb_check_var = asiliantfb_check_var,
  89. .fb_set_par = asiliantfb_set_par,
  90. .fb_setcolreg = asiliantfb_setcolreg,
  91. .fb_fillrect = cfb_fillrect,
  92. .fb_copyarea = cfb_copyarea,
  93. .fb_imageblit = cfb_imageblit,
  94. };
  95. /* Calculate the ratios for the dot clocks without using a single long long
  96. * value */
  97. static void asiliant_calc_dclk2(u32 *ppixclock, u8 *dclk2_m, u8 *dclk2_n, u8 *dclk2_div)
  98. {
  99. unsigned pixclock = *ppixclock;
  100. unsigned Ftarget = 1000000 * (1000000 / pixclock);
  101. unsigned n;
  102. unsigned best_error = 0xffffffff;
  103. unsigned best_m = 0xffffffff,
  104. best_n = 0xffffffff;
  105. unsigned ratio;
  106. unsigned remainder;
  107. unsigned char divisor = 0;
  108. /* Calculate the frequency required. This is hard enough. */
  109. ratio = 1000000 / pixclock;
  110. remainder = 1000000 % pixclock;
  111. Ftarget = 1000000 * ratio + (1000000 * remainder) / pixclock;
  112. while (Ftarget < 100000000) {
  113. divisor += 0x10;
  114. Ftarget <<= 1;
  115. }
  116. ratio = Ftarget / Fref;
  117. remainder = Ftarget % Fref;
  118. /* This expresses the constraint that 150kHz <= Fref/n <= 5Mhz,
  119. * together with 3 <= n <= 257. */
  120. for (n = 3; n <= 257; n++) {
  121. unsigned m = n * ratio + (n * remainder) / Fref;
  122. /* 3 <= m <= 257 */
  123. if (m >= 3 && m <= 257) {
  124. unsigned new_error = Ftarget * n >= Fref * m ?
  125. ((Ftarget * n) - (Fref * m)) : ((Fref * m) - (Ftarget * n));
  126. if (new_error < best_error) {
  127. best_n = n;
  128. best_m = m;
  129. best_error = new_error;
  130. }
  131. }
  132. /* But if VLD = 4, then 4m <= 1028 */
  133. else if (m <= 1028) {
  134. /* remember there are still only 8-bits of precision in m, so
  135. * avoid over-optimistic error calculations */
  136. unsigned new_error = Ftarget * n >= Fref * (m & ~3) ?
  137. ((Ftarget * n) - (Fref * (m & ~3))) : ((Fref * (m & ~3)) - (Ftarget * n));
  138. if (new_error < best_error) {
  139. best_n = n;
  140. best_m = m;
  141. best_error = new_error;
  142. }
  143. }
  144. }
  145. if (best_m > 257)
  146. best_m >>= 2; /* divide m by 4, and leave VCO loop divide at 4 */
  147. else
  148. divisor |= 4; /* or set VCO loop divide to 1 */
  149. *dclk2_m = best_m - 2;
  150. *dclk2_n = best_n - 2;
  151. *dclk2_div = divisor;
  152. *ppixclock = pixclock;
  153. return;
  154. }
  155. static void asiliant_set_timing(struct fb_info *p)
  156. {
  157. unsigned hd = p->var.xres / 8;
  158. unsigned hs = (p->var.xres + p->var.right_margin) / 8;
  159. unsigned he = (p->var.xres + p->var.right_margin + p->var.hsync_len) / 8;
  160. unsigned ht = (p->var.left_margin + p->var.xres + p->var.right_margin + p->var.hsync_len) / 8;
  161. unsigned vd = p->var.yres;
  162. unsigned vs = p->var.yres + p->var.lower_margin;
  163. unsigned ve = p->var.yres + p->var.lower_margin + p->var.vsync_len;
  164. unsigned vt = p->var.upper_margin + p->var.yres + p->var.lower_margin + p->var.vsync_len;
  165. unsigned wd = (p->var.xres_virtual * ((p->var.bits_per_pixel+7)/8)) / 8;
  166. if ((p->var.xres == 640) && (p->var.yres == 480) && (p->var.pixclock == 39722)) {
  167. write_fr(0x01, 0x02); /* LCD */
  168. } else {
  169. write_fr(0x01, 0x01); /* CRT */
  170. }
  171. write_cr(0x11, (ve - 1) & 0x0f);
  172. write_cr(0x00, (ht - 5) & 0xff);
  173. write_cr(0x01, hd - 1);
  174. write_cr(0x02, hd);
  175. write_cr(0x03, ((ht - 1) & 0x1f) | 0x80);
  176. write_cr(0x04, hs);
  177. write_cr(0x05, (((ht - 1) & 0x20) <<2) | (he & 0x1f));
  178. write_cr(0x3c, (ht - 1) & 0xc0);
  179. write_cr(0x06, (vt - 2) & 0xff);
  180. write_cr(0x30, (vt - 2) >> 8);
  181. write_cr(0x07, 0x00);
  182. write_cr(0x08, 0x00);
  183. write_cr(0x09, 0x00);
  184. write_cr(0x10, (vs - 1) & 0xff);
  185. write_cr(0x32, ((vs - 1) >> 8) & 0xf);
  186. write_cr(0x11, ((ve - 1) & 0x0f) | 0x80);
  187. write_cr(0x12, (vd - 1) & 0xff);
  188. write_cr(0x31, ((vd - 1) & 0xf00) >> 8);
  189. write_cr(0x13, wd & 0xff);
  190. write_cr(0x41, (wd & 0xf00) >> 8);
  191. write_cr(0x15, (vs - 1) & 0xff);
  192. write_cr(0x33, ((vs - 1) >> 8) & 0xf);
  193. write_cr(0x38, ((ht - 5) & 0x100) >> 8);
  194. write_cr(0x16, (vt - 1) & 0xff);
  195. write_cr(0x18, 0x00);
  196. if (p->var.xres == 640) {
  197. writeb(0xc7, mmio_base + 0x784); /* set misc output reg */
  198. } else {
  199. writeb(0x07, mmio_base + 0x784); /* set misc output reg */
  200. }
  201. }
  202. static int asiliantfb_check_var(struct fb_var_screeninfo *var,
  203. struct fb_info *p)
  204. {
  205. unsigned long Ftarget, ratio, remainder;
  206. ratio = 1000000 / var->pixclock;
  207. remainder = 1000000 % var->pixclock;
  208. Ftarget = 1000000 * ratio + (1000000 * remainder) / var->pixclock;
  209. /* First check the constraint that the maximum post-VCO divisor is 32,
  210. * and the maximum Fvco is 220MHz */
  211. if (Ftarget > 220000000 || Ftarget < 3125000) {
  212. printk(KERN_ERR "asiliantfb dotclock must be between 3.125 and 220MHz\n");
  213. return -ENXIO;
  214. }
  215. var->xres_virtual = var->xres;
  216. var->yres_virtual = var->yres;
  217. if (var->bits_per_pixel == 24) {
  218. var->red.offset = 16;
  219. var->green.offset = 8;
  220. var->blue.offset = 0;
  221. var->red.length = var->blue.length = var->green.length = 8;
  222. } else if (var->bits_per_pixel == 16) {
  223. switch (var->red.offset) {
  224. case 11:
  225. var->green.length = 6;
  226. break;
  227. case 10:
  228. var->green.length = 5;
  229. break;
  230. default:
  231. return -EINVAL;
  232. }
  233. var->green.offset = 5;
  234. var->blue.offset = 0;
  235. var->red.length = var->blue.length = 5;
  236. } else if (var->bits_per_pixel == 8) {
  237. var->red.offset = var->green.offset = var->blue.offset = 0;
  238. var->red.length = var->green.length = var->blue.length = 8;
  239. }
  240. return 0;
  241. }
  242. static int asiliantfb_set_par(struct fb_info *p)
  243. {
  244. u8 dclk2_m; /* Holds m-2 value for register */
  245. u8 dclk2_n; /* Holds n-2 value for register */
  246. u8 dclk2_div; /* Holds divisor bitmask */
  247. /* Set pixclock */
  248. asiliant_calc_dclk2(&p->var.pixclock, &dclk2_m, &dclk2_n, &dclk2_div);
  249. /* Set color depth */
  250. if (p->var.bits_per_pixel == 24) {
  251. write_xr(0x81, 0x16); /* 24 bit packed color mode */
  252. write_xr(0x82, 0x00); /* Disable palettes */
  253. write_xr(0x20, 0x20); /* 24 bit blitter mode */
  254. } else if (p->var.bits_per_pixel == 16) {
  255. if (p->var.red.offset == 11)
  256. write_xr(0x81, 0x15); /* 16 bit color mode */
  257. else
  258. write_xr(0x81, 0x14); /* 15 bit color mode */
  259. write_xr(0x82, 0x00); /* Disable palettes */
  260. write_xr(0x20, 0x10); /* 16 bit blitter mode */
  261. } else if (p->var.bits_per_pixel == 8) {
  262. write_xr(0x0a, 0x02); /* Linear */
  263. write_xr(0x81, 0x12); /* 8 bit color mode */
  264. write_xr(0x82, 0x00); /* Graphics gamma enable */
  265. write_xr(0x20, 0x00); /* 8 bit blitter mode */
  266. }
  267. p->fix.line_length = p->var.xres * (p->var.bits_per_pixel >> 3);
  268. p->fix.visual = (p->var.bits_per_pixel == 8) ? FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR;
  269. write_xr(0xc4, dclk2_m);
  270. write_xr(0xc5, dclk2_n);
  271. write_xr(0xc7, dclk2_div);
  272. /* Set up the CR registers */
  273. asiliant_set_timing(p);
  274. return 0;
  275. }
  276. static int asiliantfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
  277. u_int transp, struct fb_info *p)
  278. {
  279. if (regno > 255)
  280. return 1;
  281. red >>= 8;
  282. green >>= 8;
  283. blue >>= 8;
  284. /* Set hardware palete */
  285. writeb(regno, mmio_base + 0x790);
  286. udelay(1);
  287. writeb(red, mmio_base + 0x791);
  288. writeb(green, mmio_base + 0x791);
  289. writeb(blue, mmio_base + 0x791);
  290. if (regno < 16) {
  291. switch(p->var.red.offset) {
  292. case 10: /* RGB 555 */
  293. ((u32 *)(p->pseudo_palette))[regno] =
  294. ((red & 0xf8) << 7) |
  295. ((green & 0xf8) << 2) |
  296. ((blue & 0xf8) >> 3);
  297. break;
  298. case 11: /* RGB 565 */
  299. ((u32 *)(p->pseudo_palette))[regno] =
  300. ((red & 0xf8) << 8) |
  301. ((green & 0xfc) << 3) |
  302. ((blue & 0xf8) >> 3);
  303. break;
  304. case 16: /* RGB 888 */
  305. ((u32 *)(p->pseudo_palette))[regno] =
  306. (red << 16) |
  307. (green << 8) |
  308. (blue);
  309. break;
  310. }
  311. }
  312. return 0;
  313. }
  314. struct chips_init_reg {
  315. unsigned char addr;
  316. unsigned char data;
  317. };
  318. static struct chips_init_reg chips_init_sr[] =
  319. {
  320. {0x00, 0x03}, /* Reset register */
  321. {0x01, 0x01}, /* Clocking mode */
  322. {0x02, 0x0f}, /* Plane mask */
  323. {0x04, 0x0e} /* Memory mode */
  324. };
  325. static struct chips_init_reg chips_init_gr[] =
  326. {
  327. {0x03, 0x00}, /* Data rotate */
  328. {0x05, 0x00}, /* Graphics mode */
  329. {0x06, 0x01}, /* Miscellaneous */
  330. {0x08, 0x00} /* Bit mask */
  331. };
  332. static struct chips_init_reg chips_init_ar[] =
  333. {
  334. {0x10, 0x01}, /* Mode control */
  335. {0x11, 0x00}, /* Overscan */
  336. {0x12, 0x0f}, /* Memory plane enable */
  337. {0x13, 0x00} /* Horizontal pixel panning */
  338. };
  339. static struct chips_init_reg chips_init_cr[] =
  340. {
  341. {0x0c, 0x00}, /* Start address high */
  342. {0x0d, 0x00}, /* Start address low */
  343. {0x40, 0x00}, /* Extended Start Address */
  344. {0x41, 0x00}, /* Extended Start Address */
  345. {0x14, 0x00}, /* Underline location */
  346. {0x17, 0xe3}, /* CRT mode control */
  347. {0x70, 0x00} /* Interlace control */
  348. };
  349. static struct chips_init_reg chips_init_fr[] =
  350. {
  351. {0x01, 0x02},
  352. {0x03, 0x08},
  353. {0x08, 0xcc},
  354. {0x0a, 0x08},
  355. {0x18, 0x00},
  356. {0x1e, 0x80},
  357. {0x40, 0x83},
  358. {0x41, 0x00},
  359. {0x48, 0x13},
  360. {0x4d, 0x60},
  361. {0x4e, 0x0f},
  362. {0x0b, 0x01},
  363. {0x21, 0x51},
  364. {0x22, 0x1d},
  365. {0x23, 0x5f},
  366. {0x20, 0x4f},
  367. {0x34, 0x00},
  368. {0x24, 0x51},
  369. {0x25, 0x00},
  370. {0x27, 0x0b},
  371. {0x26, 0x00},
  372. {0x37, 0x80},
  373. {0x33, 0x0b},
  374. {0x35, 0x11},
  375. {0x36, 0x02},
  376. {0x31, 0xea},
  377. {0x32, 0x0c},
  378. {0x30, 0xdf},
  379. {0x10, 0x0c},
  380. {0x11, 0xe0},
  381. {0x12, 0x50},
  382. {0x13, 0x00},
  383. {0x16, 0x03},
  384. {0x17, 0xbd},
  385. {0x1a, 0x00},
  386. };
  387. static struct chips_init_reg chips_init_xr[] =
  388. {
  389. {0xce, 0x00}, /* set default memory clock */
  390. {0xcc, 200 }, /* MCLK ratio M */
  391. {0xcd, 18 }, /* MCLK ratio N */
  392. {0xce, 0x90}, /* MCLK divisor = 2 */
  393. {0xc4, 209 },
  394. {0xc5, 118 },
  395. {0xc7, 32 },
  396. {0xcf, 0x06},
  397. {0x09, 0x01}, /* IO Control - CRT controller extensions */
  398. {0x0a, 0x02}, /* Frame buffer mapping */
  399. {0x0b, 0x01}, /* PCI burst write */
  400. {0x40, 0x03}, /* Memory access control */
  401. {0x80, 0x82}, /* Pixel pipeline configuration 0 */
  402. {0x81, 0x12}, /* Pixel pipeline configuration 1 */
  403. {0x82, 0x08}, /* Pixel pipeline configuration 2 */
  404. {0xd0, 0x0f},
  405. {0xd1, 0x01},
  406. };
  407. static void __devinit chips_hw_init(struct fb_info *p)
  408. {
  409. int i;
  410. for (i = 0; i < ARRAY_SIZE(chips_init_xr); ++i)
  411. write_xr(chips_init_xr[i].addr, chips_init_xr[i].data);
  412. write_xr(0x81, 0x12);
  413. write_xr(0x82, 0x08);
  414. write_xr(0x20, 0x00);
  415. for (i = 0; i < ARRAY_SIZE(chips_init_sr); ++i)
  416. write_sr(chips_init_sr[i].addr, chips_init_sr[i].data);
  417. for (i = 0; i < ARRAY_SIZE(chips_init_gr); ++i)
  418. write_gr(chips_init_gr[i].addr, chips_init_gr[i].data);
  419. for (i = 0; i < ARRAY_SIZE(chips_init_ar); ++i)
  420. write_ar(chips_init_ar[i].addr, chips_init_ar[i].data);
  421. /* Enable video output in attribute index register */
  422. writeb(0x20, mmio_base + 0x780);
  423. for (i = 0; i < ARRAY_SIZE(chips_init_cr); ++i)
  424. write_cr(chips_init_cr[i].addr, chips_init_cr[i].data);
  425. for (i = 0; i < ARRAY_SIZE(chips_init_fr); ++i)
  426. write_fr(chips_init_fr[i].addr, chips_init_fr[i].data);
  427. }
  428. static struct fb_fix_screeninfo asiliantfb_fix __devinitdata = {
  429. .id = "Asiliant 69000",
  430. .type = FB_TYPE_PACKED_PIXELS,
  431. .visual = FB_VISUAL_PSEUDOCOLOR,
  432. .accel = FB_ACCEL_NONE,
  433. .line_length = 640,
  434. .smem_len = 0x200000, /* 2MB */
  435. };
  436. static struct fb_var_screeninfo asiliantfb_var __devinitdata = {
  437. .xres = 640,
  438. .yres = 480,
  439. .xres_virtual = 640,
  440. .yres_virtual = 480,
  441. .bits_per_pixel = 8,
  442. .red = { .length = 8 },
  443. .green = { .length = 8 },
  444. .blue = { .length = 8 },
  445. .height = -1,
  446. .width = -1,
  447. .vmode = FB_VMODE_NONINTERLACED,
  448. .pixclock = 39722,
  449. .left_margin = 48,
  450. .right_margin = 16,
  451. .upper_margin = 33,
  452. .lower_margin = 10,
  453. .hsync_len = 96,
  454. .vsync_len = 2,
  455. };
  456. static int __devinit init_asiliant(struct fb_info *p, unsigned long addr)
  457. {
  458. int err;
  459. p->fix = asiliantfb_fix;
  460. p->fix.smem_start = addr;
  461. p->var = asiliantfb_var;
  462. p->fbops = &asiliantfb_ops;
  463. p->flags = FBINFO_DEFAULT;
  464. err = fb_alloc_cmap(&p->cmap, 256, 0);
  465. if (err) {
  466. printk(KERN_ERR "C&T 69000 fb failed to alloc cmap memory\n");
  467. return err;
  468. }
  469. err = register_framebuffer(p);
  470. if (err < 0) {
  471. printk(KERN_ERR "C&T 69000 framebuffer failed to register\n");
  472. fb_dealloc_cmap(&p->cmap);
  473. return err;
  474. }
  475. printk(KERN_INFO "fb%d: Asiliant 69000 frame buffer (%dK RAM detected)\n",
  476. p->node, p->fix.smem_len / 1024);
  477. writeb(0xff, mmio_base + 0x78c);
  478. chips_hw_init(p);
  479. return 0;
  480. }
  481. static int __devinit
  482. asiliantfb_pci_init(struct pci_dev *dp, const struct pci_device_id *ent)
  483. {
  484. unsigned long addr, size;
  485. struct fb_info *p;
  486. int err;
  487. if ((dp->resource[0].flags & IORESOURCE_MEM) == 0)
  488. return -ENODEV;
  489. addr = pci_resource_start(dp, 0);
  490. size = pci_resource_len(dp, 0);
  491. if (addr == 0)
  492. return -ENODEV;
  493. if (!request_mem_region(addr, size, "asiliantfb"))
  494. return -EBUSY;
  495. p = framebuffer_alloc(sizeof(u32) * 16, &dp->dev);
  496. if (!p) {
  497. release_mem_region(addr, size);
  498. return -ENOMEM;
  499. }
  500. p->pseudo_palette = p->par;
  501. p->par = NULL;
  502. p->screen_base = ioremap(addr, 0x800000);
  503. if (p->screen_base == NULL) {
  504. release_mem_region(addr, size);
  505. framebuffer_release(p);
  506. return -ENOMEM;
  507. }
  508. pci_write_config_dword(dp, 4, 0x02800083);
  509. writeb(3, p->screen_base + 0x400784);
  510. err = init_asiliant(p, addr);
  511. if (err) {
  512. iounmap(p->screen_base);
  513. release_mem_region(addr, size);
  514. framebuffer_release(p);
  515. return err;
  516. }
  517. pci_set_drvdata(dp, p);
  518. return 0;
  519. }
  520. static void __devexit asiliantfb_remove(struct pci_dev *dp)
  521. {
  522. struct fb_info *p = pci_get_drvdata(dp);
  523. unregister_framebuffer(p);
  524. fb_dealloc_cmap(&p->cmap);
  525. iounmap(p->screen_base);
  526. release_mem_region(pci_resource_start(dp, 0), pci_resource_len(dp, 0));
  527. pci_set_drvdata(dp, NULL);
  528. framebuffer_release(p);
  529. }
  530. static struct pci_device_id asiliantfb_pci_tbl[] __devinitdata = {
  531. { PCI_VENDOR_ID_CT, PCI_DEVICE_ID_CT_69000, PCI_ANY_ID, PCI_ANY_ID },
  532. { 0 }
  533. };
  534. MODULE_DEVICE_TABLE(pci, asiliantfb_pci_tbl);
  535. static struct pci_driver asiliantfb_driver = {
  536. .name = "asiliantfb",
  537. .id_table = asiliantfb_pci_tbl,
  538. .probe = asiliantfb_pci_init,
  539. .remove = __devexit_p(asiliantfb_remove),
  540. };
  541. static int __init asiliantfb_init(void)
  542. {
  543. if (fb_get_options("asiliantfb", NULL))
  544. return -ENODEV;
  545. return pci_register_driver(&asiliantfb_driver);
  546. }
  547. module_init(asiliantfb_init);
  548. static void __exit asiliantfb_exit(void)
  549. {
  550. pci_unregister_driver(&asiliantfb_driver);
  551. }
  552. MODULE_LICENSE("GPL");