matroxfb_crtc2.c 20 KB

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