matroxfb_crtc2.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739
  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/uaccess.h>
  18. /* **************************************************** */
  19. static int mem = 8192;
  20. module_param(mem, int, 0);
  21. MODULE_PARM_DESC(mem, "Memory size reserved for dualhead (default=8MB)");
  22. /* **************************************************** */
  23. static int matroxfb_dh_setcolreg(unsigned regno, unsigned red, unsigned green,
  24. unsigned blue, unsigned transp, struct fb_info* info) {
  25. u_int32_t col;
  26. #define m2info (container_of(info, struct matroxfb_dh_fb_info, fbcon))
  27. if (regno >= 16)
  28. return 1;
  29. if (m2info->fbcon.var.grayscale) {
  30. /* gray = 0.30*R + 0.59*G + 0.11*B */
  31. red = green = blue = (red * 77 + green * 151 + blue * 28) >> 8;
  32. }
  33. red = CNVT_TOHW(red, m2info->fbcon.var.red.length);
  34. green = CNVT_TOHW(green, m2info->fbcon.var.green.length);
  35. blue = CNVT_TOHW(blue, m2info->fbcon.var.blue.length);
  36. transp = CNVT_TOHW(transp, m2info->fbcon.var.transp.length);
  37. col = (red << m2info->fbcon.var.red.offset) |
  38. (green << m2info->fbcon.var.green.offset) |
  39. (blue << m2info->fbcon.var.blue.offset) |
  40. (transp << m2info->fbcon.var.transp.offset);
  41. switch (m2info->fbcon.var.bits_per_pixel) {
  42. case 16:
  43. m2info->cmap[regno] = col | (col << 16);
  44. break;
  45. case 32:
  46. m2info->cmap[regno] = col;
  47. break;
  48. }
  49. return 0;
  50. #undef m2info
  51. }
  52. static void matroxfb_dh_restore(struct matroxfb_dh_fb_info* m2info,
  53. struct my_timming* mt,
  54. int mode,
  55. unsigned int pos) {
  56. u_int32_t tmp;
  57. u_int32_t datactl;
  58. struct matrox_fb_info *minfo = m2info->primary_dev;
  59. switch (mode) {
  60. case 15:
  61. tmp = 0x00200000;
  62. break;
  63. case 16:
  64. tmp = 0x00400000;
  65. break;
  66. /* case 32: */
  67. default:
  68. tmp = 0x00800000;
  69. break;
  70. }
  71. tmp |= 0x00000001; /* enable CRTC2 */
  72. datactl = 0;
  73. if (minfo->outputs[1].src == MATROXFB_SRC_CRTC2) {
  74. if (minfo->devflags.g450dac) {
  75. tmp |= 0x00000006; /* source from secondary pixel PLL */
  76. /* no vidrst when in monitor mode */
  77. if (minfo->outputs[1].mode != MATROXFB_OUTPUT_MODE_MONITOR) {
  78. tmp |= 0xC0001000; /* Enable H/V vidrst */
  79. }
  80. } else {
  81. tmp |= 0x00000002; /* source from VDOCLK */
  82. tmp |= 0xC0000000; /* enable vvidrst & hvidrst */
  83. /* MGA TVO is our clock source */
  84. }
  85. } else if (minfo->outputs[0].src == MATROXFB_SRC_CRTC2) {
  86. tmp |= 0x00000004; /* source from pixclock */
  87. /* PIXPLL is our clock source */
  88. }
  89. if (minfo->outputs[0].src == MATROXFB_SRC_CRTC2) {
  90. tmp |= 0x00100000; /* connect CRTC2 to DAC */
  91. }
  92. if (mt->interlaced) {
  93. tmp |= 0x02000000; /* interlaced, second field is bigger, as G450 apparently ignores it */
  94. mt->VDisplay >>= 1;
  95. mt->VSyncStart >>= 1;
  96. mt->VSyncEnd >>= 1;
  97. mt->VTotal >>= 1;
  98. }
  99. if ((mt->HTotal & 7) == 2) {
  100. datactl |= 0x00000010;
  101. mt->HTotal &= ~7;
  102. }
  103. tmp |= 0x10000000; /* 0x10000000 is VIDRST polarity */
  104. mga_outl(0x3C14, ((mt->HDisplay - 8) << 16) | (mt->HTotal - 8));
  105. mga_outl(0x3C18, ((mt->HSyncEnd - 8) << 16) | (mt->HSyncStart - 8));
  106. mga_outl(0x3C1C, ((mt->VDisplay - 1) << 16) | (mt->VTotal - 1));
  107. mga_outl(0x3C20, ((mt->VSyncEnd - 1) << 16) | (mt->VSyncStart - 1));
  108. mga_outl(0x3C24, ((mt->VSyncStart) << 16) | (mt->HSyncStart)); /* preload */
  109. {
  110. u_int32_t linelen = m2info->fbcon.var.xres_virtual * (m2info->fbcon.var.bits_per_pixel >> 3);
  111. if (tmp & 0x02000000) {
  112. /* field #0 is smaller, so... */
  113. mga_outl(0x3C2C, pos); /* field #1 vmemory start */
  114. mga_outl(0x3C28, pos + linelen); /* field #0 vmemory start */
  115. linelen <<= 1;
  116. m2info->interlaced = 1;
  117. } else {
  118. mga_outl(0x3C28, pos); /* vmemory start */
  119. m2info->interlaced = 0;
  120. }
  121. mga_outl(0x3C40, linelen);
  122. }
  123. mga_outl(0x3C4C, datactl); /* data control */
  124. if (tmp & 0x02000000) {
  125. int i;
  126. mga_outl(0x3C10, tmp & ~0x02000000);
  127. for (i = 0; i < 2; i++) {
  128. unsigned int nl;
  129. unsigned int lastl = 0;
  130. while ((nl = mga_inl(0x3C48) & 0xFFF) >= lastl) {
  131. lastl = nl;
  132. }
  133. }
  134. }
  135. mga_outl(0x3C10, tmp);
  136. minfo->hw.crtc2.ctl = tmp;
  137. tmp = mt->VDisplay << 16; /* line compare */
  138. if (mt->sync & FB_SYNC_HOR_HIGH_ACT)
  139. tmp |= 0x00000100;
  140. if (mt->sync & FB_SYNC_VERT_HIGH_ACT)
  141. tmp |= 0x00000200;
  142. mga_outl(0x3C44, tmp);
  143. }
  144. static void matroxfb_dh_disable(struct matroxfb_dh_fb_info* m2info) {
  145. struct matrox_fb_info *minfo = m2info->primary_dev;
  146. mga_outl(0x3C10, 0x00000004); /* disable CRTC2, CRTC1->DAC1, PLL as clock source */
  147. minfo->hw.crtc2.ctl = 0x00000004;
  148. }
  149. static void matroxfb_dh_pan_var(struct matroxfb_dh_fb_info* m2info,
  150. struct fb_var_screeninfo* var) {
  151. unsigned int pos;
  152. unsigned int linelen;
  153. unsigned int pixelsize;
  154. struct matrox_fb_info *minfo = m2info->primary_dev;
  155. m2info->fbcon.var.xoffset = var->xoffset;
  156. m2info->fbcon.var.yoffset = var->yoffset;
  157. pixelsize = m2info->fbcon.var.bits_per_pixel >> 3;
  158. linelen = m2info->fbcon.var.xres_virtual * pixelsize;
  159. pos = m2info->fbcon.var.yoffset * linelen + m2info->fbcon.var.xoffset * pixelsize;
  160. pos += m2info->video.offbase;
  161. if (m2info->interlaced) {
  162. mga_outl(0x3C2C, pos);
  163. mga_outl(0x3C28, pos + linelen);
  164. } else {
  165. mga_outl(0x3C28, pos);
  166. }
  167. }
  168. static int matroxfb_dh_decode_var(struct matroxfb_dh_fb_info* m2info,
  169. struct fb_var_screeninfo* var,
  170. int *visual,
  171. int *video_cmap_len,
  172. int *mode) {
  173. unsigned int mask;
  174. unsigned int memlen;
  175. unsigned int vramlen;
  176. switch (var->bits_per_pixel) {
  177. case 16: mask = 0x1F;
  178. break;
  179. case 32: mask = 0x0F;
  180. break;
  181. default: return -EINVAL;
  182. }
  183. vramlen = m2info->video.len_usable;
  184. if (var->yres_virtual < var->yres)
  185. var->yres_virtual = var->yres;
  186. if (var->xres_virtual < var->xres)
  187. var->xres_virtual = var->xres;
  188. var->xres_virtual = (var->xres_virtual + mask) & ~mask;
  189. if (var->yres_virtual > 32767)
  190. return -EINVAL;
  191. memlen = var->xres_virtual * var->yres_virtual * (var->bits_per_pixel >> 3);
  192. if (memlen > vramlen)
  193. return -EINVAL;
  194. if (var->xoffset + var->xres > var->xres_virtual)
  195. var->xoffset = var->xres_virtual - var->xres;
  196. if (var->yoffset + var->yres > var->yres_virtual)
  197. var->yoffset = var->yres_virtual - var->yres;
  198. var->xres &= ~7;
  199. var->left_margin &= ~7;
  200. var->right_margin &= ~7;
  201. var->hsync_len &= ~7;
  202. *mode = var->bits_per_pixel;
  203. if (var->bits_per_pixel == 16) {
  204. if (var->green.length == 5) {
  205. var->red.offset = 10;
  206. var->red.length = 5;
  207. var->green.offset = 5;
  208. var->green.length = 5;
  209. var->blue.offset = 0;
  210. var->blue.length = 5;
  211. var->transp.offset = 15;
  212. var->transp.length = 1;
  213. *mode = 15;
  214. } else {
  215. var->red.offset = 11;
  216. var->red.length = 5;
  217. var->green.offset = 5;
  218. var->green.length = 6;
  219. var->blue.offset = 0;
  220. var->blue.length = 5;
  221. var->transp.offset = 0;
  222. var->transp.length = 0;
  223. }
  224. } else {
  225. var->red.offset = 16;
  226. var->red.length = 8;
  227. var->green.offset = 8;
  228. var->green.length = 8;
  229. var->blue.offset = 0;
  230. var->blue.length = 8;
  231. var->transp.offset = 24;
  232. var->transp.length = 8;
  233. }
  234. *visual = FB_VISUAL_TRUECOLOR;
  235. *video_cmap_len = 16;
  236. return 0;
  237. }
  238. static int matroxfb_dh_open(struct fb_info* info, int user) {
  239. #define m2info (container_of(info, struct matroxfb_dh_fb_info, fbcon))
  240. struct matrox_fb_info *minfo = m2info->primary_dev;
  241. if (minfo) {
  242. int err;
  243. if (minfo->dead) {
  244. return -ENXIO;
  245. }
  246. err = minfo->fbops.fb_open(&minfo->fbcon, user);
  247. if (err) {
  248. return err;
  249. }
  250. }
  251. return 0;
  252. #undef m2info
  253. }
  254. static int matroxfb_dh_release(struct fb_info* info, int user) {
  255. #define m2info (container_of(info, struct matroxfb_dh_fb_info, fbcon))
  256. int err = 0;
  257. struct matrox_fb_info *minfo = m2info->primary_dev;
  258. if (minfo) {
  259. err = minfo->fbops.fb_release(&minfo->fbcon, user);
  260. }
  261. return err;
  262. #undef m2info
  263. }
  264. /*
  265. * This function is called before the register_framebuffer so
  266. * no locking is needed.
  267. */
  268. static void matroxfb_dh_init_fix(struct matroxfb_dh_fb_info *m2info)
  269. {
  270. struct fb_fix_screeninfo *fix = &m2info->fbcon.fix;
  271. strcpy(fix->id, "MATROX DH");
  272. fix->smem_start = m2info->video.base;
  273. fix->smem_len = m2info->video.len_usable;
  274. fix->ypanstep = 1;
  275. fix->ywrapstep = 0;
  276. fix->xpanstep = 8; /* TBD */
  277. fix->mmio_start = m2info->mmio.base;
  278. fix->mmio_len = m2info->mmio.len;
  279. fix->accel = 0; /* no accel... */
  280. }
  281. static int matroxfb_dh_check_var(struct fb_var_screeninfo* var, struct fb_info* info) {
  282. #define m2info (container_of(info, struct matroxfb_dh_fb_info, fbcon))
  283. int visual;
  284. int cmap_len;
  285. int mode;
  286. return matroxfb_dh_decode_var(m2info, var, &visual, &cmap_len, &mode);
  287. #undef m2info
  288. }
  289. static int matroxfb_dh_set_par(struct fb_info* info) {
  290. #define m2info (container_of(info, struct matroxfb_dh_fb_info, fbcon))
  291. int visual;
  292. int cmap_len;
  293. int mode;
  294. int err;
  295. struct fb_var_screeninfo* var = &info->var;
  296. struct matrox_fb_info *minfo = m2info->primary_dev;
  297. if ((err = matroxfb_dh_decode_var(m2info, var, &visual, &cmap_len, &mode)) != 0)
  298. return err;
  299. /* cmap */
  300. {
  301. m2info->fbcon.screen_base = vaddr_va(m2info->video.vbase);
  302. m2info->fbcon.fix.visual = visual;
  303. m2info->fbcon.fix.type = FB_TYPE_PACKED_PIXELS;
  304. m2info->fbcon.fix.type_aux = 0;
  305. m2info->fbcon.fix.line_length = (var->xres_virtual * var->bits_per_pixel) >> 3;
  306. }
  307. {
  308. struct my_timming mt;
  309. unsigned int pos;
  310. int out;
  311. int cnt;
  312. matroxfb_var2my(&m2info->fbcon.var, &mt);
  313. mt.crtc = MATROXFB_SRC_CRTC2;
  314. /* CRTC2 delay */
  315. mt.delay = 34;
  316. pos = (m2info->fbcon.var.yoffset * m2info->fbcon.var.xres_virtual + m2info->fbcon.var.xoffset) * m2info->fbcon.var.bits_per_pixel >> 3;
  317. pos += m2info->video.offbase;
  318. cnt = 0;
  319. down_read(&minfo->altout.lock);
  320. for (out = 0; out < MATROXFB_MAX_OUTPUTS; out++) {
  321. if (minfo->outputs[out].src == MATROXFB_SRC_CRTC2) {
  322. cnt++;
  323. if (minfo->outputs[out].output->compute) {
  324. minfo->outputs[out].output->compute(minfo->outputs[out].data, &mt);
  325. }
  326. }
  327. }
  328. minfo->crtc2.pixclock = mt.pixclock;
  329. minfo->crtc2.mnp = mt.mnp;
  330. up_read(&minfo->altout.lock);
  331. if (cnt) {
  332. matroxfb_dh_restore(m2info, &mt, mode, pos);
  333. } else {
  334. matroxfb_dh_disable(m2info);
  335. }
  336. DAC1064_global_init(minfo);
  337. DAC1064_global_restore(minfo);
  338. down_read(&minfo->altout.lock);
  339. for (out = 0; out < MATROXFB_MAX_OUTPUTS; out++) {
  340. if (minfo->outputs[out].src == MATROXFB_SRC_CRTC2 &&
  341. minfo->outputs[out].output->program) {
  342. minfo->outputs[out].output->program(minfo->outputs[out].data);
  343. }
  344. }
  345. for (out = 0; out < MATROXFB_MAX_OUTPUTS; out++) {
  346. if (minfo->outputs[out].src == MATROXFB_SRC_CRTC2 &&
  347. minfo->outputs[out].output->start) {
  348. minfo->outputs[out].output->start(minfo->outputs[out].data);
  349. }
  350. }
  351. up_read(&minfo->altout.lock);
  352. }
  353. m2info->initialized = 1;
  354. return 0;
  355. #undef m2info
  356. }
  357. static int matroxfb_dh_pan_display(struct fb_var_screeninfo* var, struct fb_info* info) {
  358. #define m2info (container_of(info, struct matroxfb_dh_fb_info, fbcon))
  359. matroxfb_dh_pan_var(m2info, var);
  360. return 0;
  361. #undef m2info
  362. }
  363. static int matroxfb_dh_get_vblank(const struct matroxfb_dh_fb_info* m2info, struct fb_vblank* vblank) {
  364. struct matrox_fb_info *minfo = m2info->primary_dev;
  365. matroxfb_enable_irq(minfo, 0);
  366. memset(vblank, 0, sizeof(*vblank));
  367. vblank->flags = FB_VBLANK_HAVE_VCOUNT | FB_VBLANK_HAVE_VBLANK;
  368. /* mask out reserved bits + field number (odd/even) */
  369. vblank->vcount = mga_inl(0x3C48) & 0x000007FF;
  370. /* compatibility stuff */
  371. if (vblank->vcount >= m2info->fbcon.var.yres)
  372. vblank->flags |= FB_VBLANK_VBLANKING;
  373. if (test_bit(0, &minfo->irq_flags)) {
  374. vblank->flags |= FB_VBLANK_HAVE_COUNT;
  375. /* Only one writer, aligned int value...
  376. it should work without lock and without atomic_t */
  377. vblank->count = minfo->crtc2.vsync.cnt;
  378. }
  379. return 0;
  380. }
  381. static int matroxfb_dh_ioctl(struct fb_info *info,
  382. unsigned int cmd,
  383. unsigned long arg)
  384. {
  385. #define m2info (container_of(info, struct matroxfb_dh_fb_info, fbcon))
  386. struct matrox_fb_info *minfo = m2info->primary_dev;
  387. DBG(__func__)
  388. switch (cmd) {
  389. case FBIOGET_VBLANK:
  390. {
  391. struct fb_vblank vblank;
  392. int err;
  393. err = matroxfb_dh_get_vblank(m2info, &vblank);
  394. if (err)
  395. return err;
  396. if (copy_to_user((void __user *)arg, &vblank, sizeof(vblank)))
  397. return -EFAULT;
  398. return 0;
  399. }
  400. case FBIO_WAITFORVSYNC:
  401. {
  402. u_int32_t crt;
  403. if (get_user(crt, (u_int32_t __user *)arg))
  404. return -EFAULT;
  405. if (crt != 0)
  406. return -ENODEV;
  407. return matroxfb_wait_for_sync(minfo, 1);
  408. }
  409. case MATROXFB_SET_OUTPUT_MODE:
  410. case MATROXFB_GET_OUTPUT_MODE:
  411. case MATROXFB_GET_ALL_OUTPUTS:
  412. {
  413. return minfo->fbcon.fbops->fb_ioctl(&minfo->fbcon, cmd, arg);
  414. }
  415. case MATROXFB_SET_OUTPUT_CONNECTION:
  416. {
  417. u_int32_t tmp;
  418. int out;
  419. int changes;
  420. if (get_user(tmp, (u_int32_t __user *)arg))
  421. return -EFAULT;
  422. for (out = 0; out < 32; out++) {
  423. if (tmp & (1 << out)) {
  424. if (out >= MATROXFB_MAX_OUTPUTS)
  425. return -ENXIO;
  426. if (!minfo->outputs[out].output)
  427. return -ENXIO;
  428. switch (minfo->outputs[out].src) {
  429. case MATROXFB_SRC_NONE:
  430. case MATROXFB_SRC_CRTC2:
  431. break;
  432. default:
  433. return -EBUSY;
  434. }
  435. }
  436. }
  437. if (minfo->devflags.panellink) {
  438. if (tmp & MATROXFB_OUTPUT_CONN_DFP)
  439. return -EINVAL;
  440. if ((minfo->outputs[2].src == MATROXFB_SRC_CRTC1) && tmp)
  441. return -EBUSY;
  442. }
  443. changes = 0;
  444. for (out = 0; out < MATROXFB_MAX_OUTPUTS; out++) {
  445. if (tmp & (1 << out)) {
  446. if (minfo->outputs[out].src != MATROXFB_SRC_CRTC2) {
  447. changes = 1;
  448. minfo->outputs[out].src = MATROXFB_SRC_CRTC2;
  449. }
  450. } else if (minfo->outputs[out].src == MATROXFB_SRC_CRTC2) {
  451. changes = 1;
  452. minfo->outputs[out].src = MATROXFB_SRC_NONE;
  453. }
  454. }
  455. if (!changes)
  456. return 0;
  457. matroxfb_dh_set_par(info);
  458. return 0;
  459. }
  460. case MATROXFB_GET_OUTPUT_CONNECTION:
  461. {
  462. u_int32_t conn = 0;
  463. int out;
  464. for (out = 0; out < MATROXFB_MAX_OUTPUTS; out++) {
  465. if (minfo->outputs[out].src == MATROXFB_SRC_CRTC2) {
  466. conn |= 1 << out;
  467. }
  468. }
  469. if (put_user(conn, (u_int32_t __user *)arg))
  470. return -EFAULT;
  471. return 0;
  472. }
  473. case MATROXFB_GET_AVAILABLE_OUTPUTS:
  474. {
  475. u_int32_t tmp = 0;
  476. int out;
  477. for (out = 0; out < MATROXFB_MAX_OUTPUTS; out++) {
  478. if (minfo->outputs[out].output) {
  479. switch (minfo->outputs[out].src) {
  480. case MATROXFB_SRC_NONE:
  481. case MATROXFB_SRC_CRTC2:
  482. tmp |= 1 << out;
  483. break;
  484. }
  485. }
  486. }
  487. if (minfo->devflags.panellink) {
  488. tmp &= ~MATROXFB_OUTPUT_CONN_DFP;
  489. if (minfo->outputs[2].src == MATROXFB_SRC_CRTC1) {
  490. tmp = 0;
  491. }
  492. }
  493. if (put_user(tmp, (u_int32_t __user *)arg))
  494. return -EFAULT;
  495. return 0;
  496. }
  497. }
  498. return -ENOTTY;
  499. #undef m2info
  500. }
  501. static int matroxfb_dh_blank(int blank, struct fb_info* info) {
  502. #define m2info (container_of(info, struct matroxfb_dh_fb_info, fbcon))
  503. switch (blank) {
  504. case 1:
  505. case 2:
  506. case 3:
  507. case 4:
  508. default:;
  509. }
  510. /* do something... */
  511. return 0;
  512. #undef m2info
  513. }
  514. static struct fb_ops matroxfb_dh_ops = {
  515. .owner = THIS_MODULE,
  516. .fb_open = matroxfb_dh_open,
  517. .fb_release = matroxfb_dh_release,
  518. .fb_check_var = matroxfb_dh_check_var,
  519. .fb_set_par = matroxfb_dh_set_par,
  520. .fb_setcolreg = matroxfb_dh_setcolreg,
  521. .fb_pan_display =matroxfb_dh_pan_display,
  522. .fb_blank = matroxfb_dh_blank,
  523. .fb_ioctl = matroxfb_dh_ioctl,
  524. .fb_fillrect = cfb_fillrect,
  525. .fb_copyarea = cfb_copyarea,
  526. .fb_imageblit = cfb_imageblit,
  527. };
  528. static struct fb_var_screeninfo matroxfb_dh_defined = {
  529. 640,480,640,480,/* W,H, virtual W,H */
  530. 0,0, /* offset */
  531. 32, /* depth */
  532. 0, /* gray */
  533. {0,0,0}, /* R */
  534. {0,0,0}, /* G */
  535. {0,0,0}, /* B */
  536. {0,0,0}, /* alpha */
  537. 0, /* nonstd */
  538. FB_ACTIVATE_NOW,
  539. -1,-1, /* display size */
  540. 0, /* accel flags */
  541. 39721L,48L,16L,33L,10L,
  542. 96L,2,0, /* no sync info */
  543. FB_VMODE_NONINTERLACED,
  544. 0, {0,0,0,0,0}
  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 */