matroxfb_crtc2.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740
  1. /*
  2. *
  3. * Hardware accelerated Matrox Millennium I, II, Mystique, G100, G200, G400 and G450.
  4. *
  5. * (c) 1998-2002 Petr Vandrovec <vandrove@vc.cvut.cz>
  6. *
  7. * Portions Copyright (c) 2001 Matrox Graphics Inc.
  8. *
  9. * Version: 1.65 2002/08/14
  10. *
  11. */
  12. #include "matroxfb_maven.h"
  13. #include "matroxfb_crtc2.h"
  14. #include "matroxfb_misc.h"
  15. #include "matroxfb_DAC1064.h"
  16. #include <linux/matroxfb.h>
  17. #include <linux/slab.h>
  18. #include <linux/uaccess.h>
  19. /* **************************************************** */
  20. static int mem = 8192;
  21. module_param(mem, int, 0);
  22. MODULE_PARM_DESC(mem, "Memory size reserved for dualhead (default=8MB)");
  23. /* **************************************************** */
  24. static int matroxfb_dh_setcolreg(unsigned regno, unsigned red, unsigned green,
  25. unsigned blue, unsigned transp, struct fb_info* info) {
  26. u_int32_t col;
  27. #define m2info (container_of(info, struct matroxfb_dh_fb_info, fbcon))
  28. if (regno >= 16)
  29. return 1;
  30. if (m2info->fbcon.var.grayscale) {
  31. /* gray = 0.30*R + 0.59*G + 0.11*B */
  32. red = green = blue = (red * 77 + green * 151 + blue * 28) >> 8;
  33. }
  34. red = CNVT_TOHW(red, m2info->fbcon.var.red.length);
  35. green = CNVT_TOHW(green, m2info->fbcon.var.green.length);
  36. blue = CNVT_TOHW(blue, m2info->fbcon.var.blue.length);
  37. transp = CNVT_TOHW(transp, m2info->fbcon.var.transp.length);
  38. col = (red << m2info->fbcon.var.red.offset) |
  39. (green << m2info->fbcon.var.green.offset) |
  40. (blue << m2info->fbcon.var.blue.offset) |
  41. (transp << m2info->fbcon.var.transp.offset);
  42. switch (m2info->fbcon.var.bits_per_pixel) {
  43. case 16:
  44. m2info->cmap[regno] = col | (col << 16);
  45. break;
  46. case 32:
  47. m2info->cmap[regno] = col;
  48. break;
  49. }
  50. return 0;
  51. #undef m2info
  52. }
  53. static void matroxfb_dh_restore(struct matroxfb_dh_fb_info* m2info,
  54. struct my_timming* mt,
  55. int mode,
  56. unsigned int pos) {
  57. u_int32_t tmp;
  58. u_int32_t datactl;
  59. struct matrox_fb_info *minfo = m2info->primary_dev;
  60. switch (mode) {
  61. case 15:
  62. tmp = 0x00200000;
  63. break;
  64. case 16:
  65. tmp = 0x00400000;
  66. break;
  67. /* case 32: */
  68. default:
  69. tmp = 0x00800000;
  70. break;
  71. }
  72. tmp |= 0x00000001; /* enable CRTC2 */
  73. datactl = 0;
  74. if (minfo->outputs[1].src == MATROXFB_SRC_CRTC2) {
  75. if (minfo->devflags.g450dac) {
  76. tmp |= 0x00000006; /* source from secondary pixel PLL */
  77. /* no vidrst when in monitor mode */
  78. if (minfo->outputs[1].mode != MATROXFB_OUTPUT_MODE_MONITOR) {
  79. tmp |= 0xC0001000; /* Enable H/V vidrst */
  80. }
  81. } else {
  82. tmp |= 0x00000002; /* source from VDOCLK */
  83. tmp |= 0xC0000000; /* enable vvidrst & hvidrst */
  84. /* MGA TVO is our clock source */
  85. }
  86. } else if (minfo->outputs[0].src == MATROXFB_SRC_CRTC2) {
  87. tmp |= 0x00000004; /* source from pixclock */
  88. /* PIXPLL is our clock source */
  89. }
  90. if (minfo->outputs[0].src == MATROXFB_SRC_CRTC2) {
  91. tmp |= 0x00100000; /* connect CRTC2 to DAC */
  92. }
  93. if (mt->interlaced) {
  94. tmp |= 0x02000000; /* interlaced, second field is bigger, as G450 apparently ignores it */
  95. mt->VDisplay >>= 1;
  96. mt->VSyncStart >>= 1;
  97. mt->VSyncEnd >>= 1;
  98. mt->VTotal >>= 1;
  99. }
  100. if ((mt->HTotal & 7) == 2) {
  101. datactl |= 0x00000010;
  102. mt->HTotal &= ~7;
  103. }
  104. tmp |= 0x10000000; /* 0x10000000 is VIDRST polarity */
  105. mga_outl(0x3C14, ((mt->HDisplay - 8) << 16) | (mt->HTotal - 8));
  106. mga_outl(0x3C18, ((mt->HSyncEnd - 8) << 16) | (mt->HSyncStart - 8));
  107. mga_outl(0x3C1C, ((mt->VDisplay - 1) << 16) | (mt->VTotal - 1));
  108. mga_outl(0x3C20, ((mt->VSyncEnd - 1) << 16) | (mt->VSyncStart - 1));
  109. mga_outl(0x3C24, ((mt->VSyncStart) << 16) | (mt->HSyncStart)); /* preload */
  110. {
  111. u_int32_t linelen = m2info->fbcon.var.xres_virtual * (m2info->fbcon.var.bits_per_pixel >> 3);
  112. if (tmp & 0x02000000) {
  113. /* field #0 is smaller, so... */
  114. mga_outl(0x3C2C, pos); /* field #1 vmemory start */
  115. mga_outl(0x3C28, pos + linelen); /* field #0 vmemory start */
  116. linelen <<= 1;
  117. m2info->interlaced = 1;
  118. } else {
  119. mga_outl(0x3C28, pos); /* vmemory start */
  120. m2info->interlaced = 0;
  121. }
  122. mga_outl(0x3C40, linelen);
  123. }
  124. mga_outl(0x3C4C, datactl); /* data control */
  125. if (tmp & 0x02000000) {
  126. int i;
  127. mga_outl(0x3C10, tmp & ~0x02000000);
  128. for (i = 0; i < 2; i++) {
  129. unsigned int nl;
  130. unsigned int lastl = 0;
  131. while ((nl = mga_inl(0x3C48) & 0xFFF) >= lastl) {
  132. lastl = nl;
  133. }
  134. }
  135. }
  136. mga_outl(0x3C10, tmp);
  137. minfo->hw.crtc2.ctl = tmp;
  138. tmp = mt->VDisplay << 16; /* line compare */
  139. if (mt->sync & FB_SYNC_HOR_HIGH_ACT)
  140. tmp |= 0x00000100;
  141. if (mt->sync & FB_SYNC_VERT_HIGH_ACT)
  142. tmp |= 0x00000200;
  143. mga_outl(0x3C44, tmp);
  144. }
  145. static void matroxfb_dh_disable(struct matroxfb_dh_fb_info* m2info) {
  146. struct matrox_fb_info *minfo = m2info->primary_dev;
  147. mga_outl(0x3C10, 0x00000004); /* disable CRTC2, CRTC1->DAC1, PLL as clock source */
  148. minfo->hw.crtc2.ctl = 0x00000004;
  149. }
  150. static void matroxfb_dh_pan_var(struct matroxfb_dh_fb_info* m2info,
  151. struct fb_var_screeninfo* var) {
  152. unsigned int pos;
  153. unsigned int linelen;
  154. unsigned int pixelsize;
  155. struct matrox_fb_info *minfo = m2info->primary_dev;
  156. m2info->fbcon.var.xoffset = var->xoffset;
  157. m2info->fbcon.var.yoffset = var->yoffset;
  158. pixelsize = m2info->fbcon.var.bits_per_pixel >> 3;
  159. linelen = m2info->fbcon.var.xres_virtual * pixelsize;
  160. pos = m2info->fbcon.var.yoffset * linelen + m2info->fbcon.var.xoffset * pixelsize;
  161. pos += m2info->video.offbase;
  162. if (m2info->interlaced) {
  163. mga_outl(0x3C2C, pos);
  164. mga_outl(0x3C28, pos + linelen);
  165. } else {
  166. mga_outl(0x3C28, pos);
  167. }
  168. }
  169. static int matroxfb_dh_decode_var(struct matroxfb_dh_fb_info* m2info,
  170. struct fb_var_screeninfo* var,
  171. int *visual,
  172. int *video_cmap_len,
  173. int *mode) {
  174. unsigned int mask;
  175. unsigned int memlen;
  176. unsigned int vramlen;
  177. switch (var->bits_per_pixel) {
  178. case 16: mask = 0x1F;
  179. break;
  180. case 32: mask = 0x0F;
  181. break;
  182. default: return -EINVAL;
  183. }
  184. vramlen = m2info->video.len_usable;
  185. if (var->yres_virtual < var->yres)
  186. var->yres_virtual = var->yres;
  187. if (var->xres_virtual < var->xres)
  188. var->xres_virtual = var->xres;
  189. var->xres_virtual = (var->xres_virtual + mask) & ~mask;
  190. if (var->yres_virtual > 32767)
  191. return -EINVAL;
  192. memlen = var->xres_virtual * var->yres_virtual * (var->bits_per_pixel >> 3);
  193. if (memlen > vramlen)
  194. return -EINVAL;
  195. if (var->xoffset + var->xres > var->xres_virtual)
  196. var->xoffset = var->xres_virtual - var->xres;
  197. if (var->yoffset + var->yres > var->yres_virtual)
  198. var->yoffset = var->yres_virtual - var->yres;
  199. var->xres &= ~7;
  200. var->left_margin &= ~7;
  201. var->right_margin &= ~7;
  202. var->hsync_len &= ~7;
  203. *mode = var->bits_per_pixel;
  204. if (var->bits_per_pixel == 16) {
  205. if (var->green.length == 5) {
  206. var->red.offset = 10;
  207. var->red.length = 5;
  208. var->green.offset = 5;
  209. var->green.length = 5;
  210. var->blue.offset = 0;
  211. var->blue.length = 5;
  212. var->transp.offset = 15;
  213. var->transp.length = 1;
  214. *mode = 15;
  215. } else {
  216. var->red.offset = 11;
  217. var->red.length = 5;
  218. var->green.offset = 5;
  219. var->green.length = 6;
  220. var->blue.offset = 0;
  221. var->blue.length = 5;
  222. var->transp.offset = 0;
  223. var->transp.length = 0;
  224. }
  225. } else {
  226. var->red.offset = 16;
  227. var->red.length = 8;
  228. var->green.offset = 8;
  229. var->green.length = 8;
  230. var->blue.offset = 0;
  231. var->blue.length = 8;
  232. var->transp.offset = 24;
  233. var->transp.length = 8;
  234. }
  235. *visual = FB_VISUAL_TRUECOLOR;
  236. *video_cmap_len = 16;
  237. return 0;
  238. }
  239. static int matroxfb_dh_open(struct fb_info* info, int user) {
  240. #define m2info (container_of(info, struct matroxfb_dh_fb_info, fbcon))
  241. struct matrox_fb_info *minfo = m2info->primary_dev;
  242. if (minfo) {
  243. int err;
  244. if (minfo->dead) {
  245. return -ENXIO;
  246. }
  247. err = minfo->fbops.fb_open(&minfo->fbcon, user);
  248. if (err) {
  249. return err;
  250. }
  251. }
  252. return 0;
  253. #undef m2info
  254. }
  255. static int matroxfb_dh_release(struct fb_info* info, int user) {
  256. #define m2info (container_of(info, struct matroxfb_dh_fb_info, fbcon))
  257. int err = 0;
  258. struct matrox_fb_info *minfo = m2info->primary_dev;
  259. if (minfo) {
  260. err = minfo->fbops.fb_release(&minfo->fbcon, user);
  261. }
  262. return err;
  263. #undef m2info
  264. }
  265. /*
  266. * This function is called before the register_framebuffer so
  267. * no locking is needed.
  268. */
  269. static void matroxfb_dh_init_fix(struct matroxfb_dh_fb_info *m2info)
  270. {
  271. struct fb_fix_screeninfo *fix = &m2info->fbcon.fix;
  272. strcpy(fix->id, "MATROX DH");
  273. fix->smem_start = m2info->video.base;
  274. fix->smem_len = m2info->video.len_usable;
  275. fix->ypanstep = 1;
  276. fix->ywrapstep = 0;
  277. fix->xpanstep = 8; /* TBD */
  278. fix->mmio_start = m2info->mmio.base;
  279. fix->mmio_len = m2info->mmio.len;
  280. fix->accel = 0; /* no accel... */
  281. }
  282. static int matroxfb_dh_check_var(struct fb_var_screeninfo* var, struct fb_info* info) {
  283. #define m2info (container_of(info, struct matroxfb_dh_fb_info, fbcon))
  284. int visual;
  285. int cmap_len;
  286. int mode;
  287. return matroxfb_dh_decode_var(m2info, var, &visual, &cmap_len, &mode);
  288. #undef m2info
  289. }
  290. static int matroxfb_dh_set_par(struct fb_info* info) {
  291. #define m2info (container_of(info, struct matroxfb_dh_fb_info, fbcon))
  292. int visual;
  293. int cmap_len;
  294. int mode;
  295. int err;
  296. struct fb_var_screeninfo* var = &info->var;
  297. struct matrox_fb_info *minfo = m2info->primary_dev;
  298. if ((err = matroxfb_dh_decode_var(m2info, var, &visual, &cmap_len, &mode)) != 0)
  299. return err;
  300. /* cmap */
  301. {
  302. m2info->fbcon.screen_base = vaddr_va(m2info->video.vbase);
  303. m2info->fbcon.fix.visual = visual;
  304. m2info->fbcon.fix.type = FB_TYPE_PACKED_PIXELS;
  305. m2info->fbcon.fix.type_aux = 0;
  306. m2info->fbcon.fix.line_length = (var->xres_virtual * var->bits_per_pixel) >> 3;
  307. }
  308. {
  309. struct my_timming mt;
  310. unsigned int pos;
  311. int out;
  312. int cnt;
  313. matroxfb_var2my(&m2info->fbcon.var, &mt);
  314. mt.crtc = MATROXFB_SRC_CRTC2;
  315. /* CRTC2 delay */
  316. mt.delay = 34;
  317. pos = (m2info->fbcon.var.yoffset * m2info->fbcon.var.xres_virtual + m2info->fbcon.var.xoffset) * m2info->fbcon.var.bits_per_pixel >> 3;
  318. pos += m2info->video.offbase;
  319. cnt = 0;
  320. down_read(&minfo->altout.lock);
  321. for (out = 0; out < MATROXFB_MAX_OUTPUTS; out++) {
  322. if (minfo->outputs[out].src == MATROXFB_SRC_CRTC2) {
  323. cnt++;
  324. if (minfo->outputs[out].output->compute) {
  325. minfo->outputs[out].output->compute(minfo->outputs[out].data, &mt);
  326. }
  327. }
  328. }
  329. minfo->crtc2.pixclock = mt.pixclock;
  330. minfo->crtc2.mnp = mt.mnp;
  331. up_read(&minfo->altout.lock);
  332. if (cnt) {
  333. matroxfb_dh_restore(m2info, &mt, mode, pos);
  334. } else {
  335. matroxfb_dh_disable(m2info);
  336. }
  337. DAC1064_global_init(minfo);
  338. DAC1064_global_restore(minfo);
  339. down_read(&minfo->altout.lock);
  340. for (out = 0; out < MATROXFB_MAX_OUTPUTS; out++) {
  341. if (minfo->outputs[out].src == MATROXFB_SRC_CRTC2 &&
  342. minfo->outputs[out].output->program) {
  343. minfo->outputs[out].output->program(minfo->outputs[out].data);
  344. }
  345. }
  346. for (out = 0; out < MATROXFB_MAX_OUTPUTS; out++) {
  347. if (minfo->outputs[out].src == MATROXFB_SRC_CRTC2 &&
  348. minfo->outputs[out].output->start) {
  349. minfo->outputs[out].output->start(minfo->outputs[out].data);
  350. }
  351. }
  352. up_read(&minfo->altout.lock);
  353. }
  354. m2info->initialized = 1;
  355. return 0;
  356. #undef m2info
  357. }
  358. static int matroxfb_dh_pan_display(struct fb_var_screeninfo* var, struct fb_info* info) {
  359. #define m2info (container_of(info, struct matroxfb_dh_fb_info, fbcon))
  360. matroxfb_dh_pan_var(m2info, var);
  361. return 0;
  362. #undef m2info
  363. }
  364. static int matroxfb_dh_get_vblank(const struct matroxfb_dh_fb_info* m2info, struct fb_vblank* vblank) {
  365. struct matrox_fb_info *minfo = m2info->primary_dev;
  366. matroxfb_enable_irq(minfo, 0);
  367. memset(vblank, 0, sizeof(*vblank));
  368. vblank->flags = FB_VBLANK_HAVE_VCOUNT | FB_VBLANK_HAVE_VBLANK;
  369. /* mask out reserved bits + field number (odd/even) */
  370. vblank->vcount = mga_inl(0x3C48) & 0x000007FF;
  371. /* compatibility stuff */
  372. if (vblank->vcount >= m2info->fbcon.var.yres)
  373. vblank->flags |= FB_VBLANK_VBLANKING;
  374. if (test_bit(0, &minfo->irq_flags)) {
  375. vblank->flags |= FB_VBLANK_HAVE_COUNT;
  376. /* Only one writer, aligned int value...
  377. it should work without lock and without atomic_t */
  378. vblank->count = minfo->crtc2.vsync.cnt;
  379. }
  380. return 0;
  381. }
  382. static int matroxfb_dh_ioctl(struct fb_info *info,
  383. unsigned int cmd,
  384. unsigned long arg)
  385. {
  386. #define m2info (container_of(info, struct matroxfb_dh_fb_info, fbcon))
  387. struct matrox_fb_info *minfo = m2info->primary_dev;
  388. DBG(__func__)
  389. switch (cmd) {
  390. case FBIOGET_VBLANK:
  391. {
  392. struct fb_vblank vblank;
  393. int err;
  394. err = matroxfb_dh_get_vblank(m2info, &vblank);
  395. if (err)
  396. return err;
  397. if (copy_to_user((void __user *)arg, &vblank, sizeof(vblank)))
  398. return -EFAULT;
  399. return 0;
  400. }
  401. case FBIO_WAITFORVSYNC:
  402. {
  403. u_int32_t crt;
  404. if (get_user(crt, (u_int32_t __user *)arg))
  405. return -EFAULT;
  406. if (crt != 0)
  407. return -ENODEV;
  408. return matroxfb_wait_for_sync(minfo, 1);
  409. }
  410. case MATROXFB_SET_OUTPUT_MODE:
  411. case MATROXFB_GET_OUTPUT_MODE:
  412. case MATROXFB_GET_ALL_OUTPUTS:
  413. {
  414. return minfo->fbcon.fbops->fb_ioctl(&minfo->fbcon, cmd, arg);
  415. }
  416. case MATROXFB_SET_OUTPUT_CONNECTION:
  417. {
  418. u_int32_t tmp;
  419. int out;
  420. int changes;
  421. if (get_user(tmp, (u_int32_t __user *)arg))
  422. return -EFAULT;
  423. for (out = 0; out < 32; out++) {
  424. if (tmp & (1 << out)) {
  425. if (out >= MATROXFB_MAX_OUTPUTS)
  426. return -ENXIO;
  427. if (!minfo->outputs[out].output)
  428. return -ENXIO;
  429. switch (minfo->outputs[out].src) {
  430. case MATROXFB_SRC_NONE:
  431. case MATROXFB_SRC_CRTC2:
  432. break;
  433. default:
  434. return -EBUSY;
  435. }
  436. }
  437. }
  438. if (minfo->devflags.panellink) {
  439. if (tmp & MATROXFB_OUTPUT_CONN_DFP)
  440. return -EINVAL;
  441. if ((minfo->outputs[2].src == MATROXFB_SRC_CRTC1) && tmp)
  442. return -EBUSY;
  443. }
  444. changes = 0;
  445. for (out = 0; out < MATROXFB_MAX_OUTPUTS; out++) {
  446. if (tmp & (1 << out)) {
  447. if (minfo->outputs[out].src != MATROXFB_SRC_CRTC2) {
  448. changes = 1;
  449. minfo->outputs[out].src = MATROXFB_SRC_CRTC2;
  450. }
  451. } else if (minfo->outputs[out].src == MATROXFB_SRC_CRTC2) {
  452. changes = 1;
  453. minfo->outputs[out].src = MATROXFB_SRC_NONE;
  454. }
  455. }
  456. if (!changes)
  457. return 0;
  458. matroxfb_dh_set_par(info);
  459. return 0;
  460. }
  461. case MATROXFB_GET_OUTPUT_CONNECTION:
  462. {
  463. u_int32_t conn = 0;
  464. int out;
  465. for (out = 0; out < MATROXFB_MAX_OUTPUTS; out++) {
  466. if (minfo->outputs[out].src == MATROXFB_SRC_CRTC2) {
  467. conn |= 1 << out;
  468. }
  469. }
  470. if (put_user(conn, (u_int32_t __user *)arg))
  471. return -EFAULT;
  472. return 0;
  473. }
  474. case MATROXFB_GET_AVAILABLE_OUTPUTS:
  475. {
  476. u_int32_t tmp = 0;
  477. int out;
  478. for (out = 0; out < MATROXFB_MAX_OUTPUTS; out++) {
  479. if (minfo->outputs[out].output) {
  480. switch (minfo->outputs[out].src) {
  481. case MATROXFB_SRC_NONE:
  482. case MATROXFB_SRC_CRTC2:
  483. tmp |= 1 << out;
  484. break;
  485. }
  486. }
  487. }
  488. if (minfo->devflags.panellink) {
  489. tmp &= ~MATROXFB_OUTPUT_CONN_DFP;
  490. if (minfo->outputs[2].src == MATROXFB_SRC_CRTC1) {
  491. tmp = 0;
  492. }
  493. }
  494. if (put_user(tmp, (u_int32_t __user *)arg))
  495. return -EFAULT;
  496. return 0;
  497. }
  498. }
  499. return -ENOTTY;
  500. #undef m2info
  501. }
  502. static int matroxfb_dh_blank(int blank, struct fb_info* info) {
  503. #define m2info (container_of(info, struct matroxfb_dh_fb_info, fbcon))
  504. switch (blank) {
  505. case 1:
  506. case 2:
  507. case 3:
  508. case 4:
  509. default:;
  510. }
  511. /* do something... */
  512. return 0;
  513. #undef m2info
  514. }
  515. static struct fb_ops matroxfb_dh_ops = {
  516. .owner = THIS_MODULE,
  517. .fb_open = matroxfb_dh_open,
  518. .fb_release = matroxfb_dh_release,
  519. .fb_check_var = matroxfb_dh_check_var,
  520. .fb_set_par = matroxfb_dh_set_par,
  521. .fb_setcolreg = matroxfb_dh_setcolreg,
  522. .fb_pan_display =matroxfb_dh_pan_display,
  523. .fb_blank = matroxfb_dh_blank,
  524. .fb_ioctl = matroxfb_dh_ioctl,
  525. .fb_fillrect = cfb_fillrect,
  526. .fb_copyarea = cfb_copyarea,
  527. .fb_imageblit = cfb_imageblit,
  528. };
  529. static struct fb_var_screeninfo matroxfb_dh_defined = {
  530. 640,480,640,480,/* W,H, virtual W,H */
  531. 0,0, /* offset */
  532. 32, /* depth */
  533. 0, /* gray */
  534. {0,0,0}, /* R */
  535. {0,0,0}, /* G */
  536. {0,0,0}, /* B */
  537. {0,0,0}, /* alpha */
  538. 0, /* nonstd */
  539. FB_ACTIVATE_NOW,
  540. -1,-1, /* display size */
  541. 0, /* accel flags */
  542. 39721L,48L,16L,33L,10L,
  543. 96L,2,0, /* no sync info */
  544. FB_VMODE_NONINTERLACED,
  545. };
  546. static int matroxfb_dh_regit(const struct matrox_fb_info *minfo,
  547. struct matroxfb_dh_fb_info *m2info)
  548. {
  549. #define minfo (m2info->primary_dev)
  550. void* oldcrtc2;
  551. m2info->fbcon.fbops = &matroxfb_dh_ops;
  552. m2info->fbcon.flags = FBINFO_FLAG_DEFAULT;
  553. m2info->fbcon.flags |= FBINFO_HWACCEL_XPAN |
  554. FBINFO_HWACCEL_YPAN;
  555. m2info->fbcon.pseudo_palette = m2info->cmap;
  556. fb_alloc_cmap(&m2info->fbcon.cmap, 256, 1);
  557. if (mem < 64)
  558. mem *= 1024;
  559. if (mem < 64*1024)
  560. mem *= 1024;
  561. mem &= ~0x00000FFF; /* PAGE_MASK? */
  562. if (minfo->video.len_usable + mem <= minfo->video.len)
  563. m2info->video.offbase = minfo->video.len - mem;
  564. else if (minfo->video.len < mem) {
  565. return -ENOMEM;
  566. } else { /* check yres on first head... */
  567. m2info->video.borrowed = mem;
  568. minfo->video.len_usable -= mem;
  569. m2info->video.offbase = minfo->video.len_usable;
  570. }
  571. m2info->video.base = minfo->video.base + m2info->video.offbase;
  572. m2info->video.len = m2info->video.len_usable = m2info->video.len_maximum = mem;
  573. m2info->video.vbase.vaddr = vaddr_va(minfo->video.vbase) + m2info->video.offbase;
  574. m2info->mmio.base = minfo->mmio.base;
  575. m2info->mmio.vbase = minfo->mmio.vbase;
  576. m2info->mmio.len = minfo->mmio.len;
  577. matroxfb_dh_init_fix(m2info);
  578. if (register_framebuffer(&m2info->fbcon)) {
  579. return -ENXIO;
  580. }
  581. if (!m2info->initialized)
  582. fb_set_var(&m2info->fbcon, &matroxfb_dh_defined);
  583. down_write(&minfo->crtc2.lock);
  584. oldcrtc2 = minfo->crtc2.info;
  585. minfo->crtc2.info = m2info;
  586. up_write(&minfo->crtc2.lock);
  587. if (oldcrtc2) {
  588. printk(KERN_ERR "matroxfb_crtc2: Internal consistency check failed: crtc2 already present: %p\n",
  589. oldcrtc2);
  590. }
  591. return 0;
  592. #undef minfo
  593. }
  594. /* ************************** */
  595. static int matroxfb_dh_registerfb(struct matroxfb_dh_fb_info* m2info) {
  596. #define minfo (m2info->primary_dev)
  597. if (matroxfb_dh_regit(minfo, m2info)) {
  598. printk(KERN_ERR "matroxfb_crtc2: secondary head failed to register\n");
  599. return -1;
  600. }
  601. printk(KERN_INFO "matroxfb_crtc2: secondary head of fb%u was registered as fb%u\n",
  602. minfo->fbcon.node, m2info->fbcon.node);
  603. m2info->fbcon_registered = 1;
  604. return 0;
  605. #undef minfo
  606. }
  607. static void matroxfb_dh_deregisterfb(struct matroxfb_dh_fb_info* m2info) {
  608. #define minfo (m2info->primary_dev)
  609. if (m2info->fbcon_registered) {
  610. int id;
  611. struct matroxfb_dh_fb_info* crtc2;
  612. down_write(&minfo->crtc2.lock);
  613. crtc2 = minfo->crtc2.info;
  614. if (crtc2 == m2info)
  615. minfo->crtc2.info = NULL;
  616. up_write(&minfo->crtc2.lock);
  617. if (crtc2 != m2info) {
  618. printk(KERN_ERR "matroxfb_crtc2: Internal consistency check failed: crtc2 mismatch at unload: %p != %p\n",
  619. crtc2, m2info);
  620. printk(KERN_ERR "matroxfb_crtc2: Expect kernel crash after module unload.\n");
  621. return;
  622. }
  623. id = m2info->fbcon.node;
  624. unregister_framebuffer(&m2info->fbcon);
  625. /* return memory back to primary head */
  626. minfo->video.len_usable += m2info->video.borrowed;
  627. printk(KERN_INFO "matroxfb_crtc2: fb%u unregistered\n", id);
  628. m2info->fbcon_registered = 0;
  629. }
  630. #undef minfo
  631. }
  632. static void* matroxfb_crtc2_probe(struct matrox_fb_info* minfo) {
  633. struct matroxfb_dh_fb_info* m2info;
  634. /* hardware is CRTC2 incapable... */
  635. if (!minfo->devflags.crtc2)
  636. return NULL;
  637. m2info = kzalloc(sizeof(*m2info), GFP_KERNEL);
  638. if (!m2info) {
  639. printk(KERN_ERR "matroxfb_crtc2: Not enough memory for CRTC2 control structs\n");
  640. return NULL;
  641. }
  642. m2info->primary_dev = minfo;
  643. if (matroxfb_dh_registerfb(m2info)) {
  644. kfree(m2info);
  645. printk(KERN_ERR "matroxfb_crtc2: CRTC2 framebuffer failed to register\n");
  646. return NULL;
  647. }
  648. return m2info;
  649. }
  650. static void matroxfb_crtc2_remove(struct matrox_fb_info* minfo, void* crtc2) {
  651. matroxfb_dh_deregisterfb(crtc2);
  652. kfree(crtc2);
  653. }
  654. static struct matroxfb_driver crtc2 = {
  655. .name = "Matrox G400 CRTC2",
  656. .probe = matroxfb_crtc2_probe,
  657. .remove = matroxfb_crtc2_remove };
  658. static int matroxfb_crtc2_init(void) {
  659. if (fb_get_options("matrox_crtc2fb", NULL))
  660. return -ENODEV;
  661. matroxfb_register_driver(&crtc2);
  662. return 0;
  663. }
  664. static void matroxfb_crtc2_exit(void) {
  665. matroxfb_unregister_driver(&crtc2);
  666. }
  667. MODULE_AUTHOR("(c) 1999-2002 Petr Vandrovec <vandrove@vc.cvut.cz>");
  668. MODULE_DESCRIPTION("Matrox G400 CRTC2 driver");
  669. MODULE_LICENSE("GPL");
  670. module_init(matroxfb_crtc2_init);
  671. module_exit(matroxfb_crtc2_exit);
  672. /* we do not have __setup() yet */