|
Lines 4-9
Link Here
|
| 4 |
// double buffering added by A'rpi/ESP-team |
4 |
// double buffering added by A'rpi/ESP-team |
| 5 |
// brightness/contrast introduced by eyck |
5 |
// brightness/contrast introduced by eyck |
| 6 |
// multiple card support by Attila Kinali <attila@kinali.ch> |
6 |
// multiple card support by Attila Kinali <attila@kinali.ch> |
|
|
7 |
// ported to the 2.6 series kernels by F.O. Tempel |
| 8 |
// thankfully using the ground work done by Ed Sweetman (for the devfs work) |
| 9 |
// and Gergely Nagy for pushing into the right direction with his patch for 2.6.0-test1 |
| 7 |
|
10 |
|
| 8 |
// Set this value, if autodetection fails! (video ram size in megabytes) |
11 |
// Set this value, if autodetection fails! (video ram size in megabytes) |
| 9 |
// #define MGA_MEMORY_SIZE 16 |
12 |
// #define MGA_MEMORY_SIZE 16 |
|
Lines 36-41
Link Here
|
| 36 |
#include <linux/config.h> |
39 |
#include <linux/config.h> |
| 37 |
#include <linux/version.h> |
40 |
#include <linux/version.h> |
| 38 |
#include <linux/module.h> |
41 |
#include <linux/module.h> |
|
|
42 |
#if CONFIG_DEVFS_FS && LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) |
| 43 |
#include <linux/moduleparam.h> |
| 44 |
#endif |
| 39 |
#include <linux/types.h> |
45 |
#include <linux/types.h> |
| 40 |
#include <linux/kernel.h> |
46 |
#include <linux/kernel.h> |
| 41 |
#include <linux/sched.h> |
47 |
#include <linux/sched.h> |
|
Lines 117-123
Link Here
|
| 117 |
#ifndef min |
123 |
#ifndef min |
| 118 |
#define min(x,y) (((x)<(y))?(x):(y)) |
124 |
#define min(x,y) (((x)<(y))?(x):(y)) |
| 119 |
#endif |
125 |
#endif |
| 120 |
|
126 |
// These functions are provided by the 2.6.0 kernel these days. |
|
|
127 |
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) |
| 121 |
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0) |
128 |
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0) |
| 122 |
#include <linux/ctype.h> |
129 |
#include <linux/ctype.h> |
| 123 |
|
130 |
|
|
Lines 155-161
Link Here
|
| 155 |
return simple_strtoul(cp,endp,base); |
162 |
return simple_strtoul(cp,endp,base); |
| 156 |
} |
163 |
} |
| 157 |
#endif |
164 |
#endif |
| 158 |
|
165 |
#endif // 2.6.0 |
| 159 |
|
166 |
|
| 160 |
typedef struct bes_registers_s |
167 |
typedef struct bes_registers_s |
| 161 |
{ |
168 |
{ |
|
Lines 350-364
Link Here
|
| 350 |
|
357 |
|
| 351 |
|
358 |
|
| 352 |
// global devfs handle for /dev/mga_vid |
359 |
// global devfs handle for /dev/mga_vid |
| 353 |
#ifdef CONFIG_DEVFS_FS |
360 |
#if CONFIG_DEVFS_FS && LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) |
| 354 |
static devfs_handle_t dev_handle = NULL; |
361 |
typedef struct devfs_entry *devfs_handle_t; |
|
|
362 |
devfs_handle_t dev_handle = NULL; |
| 363 |
#endif |
| 364 |
#if CONFIG_DEVFS_FS && LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) |
| 365 |
devfs_handle_t dev_handle = NULL; |
| 355 |
#endif |
366 |
#endif |
| 356 |
|
367 |
|
| 357 |
// card local config |
368 |
// card local config |
| 358 |
typedef struct mga_card_s { |
369 |
typedef struct mga_card_s { |
| 359 |
|
370 |
|
| 360 |
// local devfs handle for /dev/mga_vidX |
371 |
// local devfs handle for /dev/mga_vidX |
| 361 |
#ifdef CONFIG_DEVFS_FS |
372 |
#if CONFIG_DEVFS_FS && LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) |
|
|
373 |
struct devfs_entry *devfs_handle_t; |
| 374 |
devfs_handle_t dev_handle; |
| 375 |
#endif |
| 376 |
#if CONFIG_DEVFS_FS && LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) |
| 362 |
devfs_handle_t dev_handle; |
377 |
devfs_handle_t dev_handle; |
| 363 |
#endif |
378 |
#endif |
| 364 |
|
379 |
|
|
Lines 411-421
Link Here
|
| 411 |
static int mga_contrast[MGA_MAX_CARDS] = MGA_MAX_CARDS_INIT_ARRAY; |
426 |
static int mga_contrast[MGA_MAX_CARDS] = MGA_MAX_CARDS_INIT_ARRAY; |
| 412 |
static int mga_top_reserved[MGA_MAX_CARDS] = MGA_MAX_CARDS_INIT_ARRAY; |
427 |
static int mga_top_reserved[MGA_MAX_CARDS] = MGA_MAX_CARDS_INIT_ARRAY; |
| 413 |
|
428 |
|
|
|
429 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) |
| 430 |
module_param(mga_ram_size, int, 0); |
| 431 |
module_param(mga_top_reserved, int, 0); |
| 432 |
module_param(mga_brightness, int, 0); |
| 433 |
module_param(mga_contrast, int, 0); |
| 434 |
module_param(major, int, 0); |
| 435 |
#else |
| 414 |
MODULE_PARM(mga_ram_size, "1-" __MODULE_STRING(MGA_MAX_CARDS) "i"); |
436 |
MODULE_PARM(mga_ram_size, "1-" __MODULE_STRING(MGA_MAX_CARDS) "i"); |
| 415 |
MODULE_PARM(mga_top_reserved, "1-" __MODULE_STRING(MGA_MAX_CARDS) "i"); |
437 |
MODULE_PARM(mga_top_reserved, "1-" __MODULE_STRING(MGA_MAX_CARDS) "i"); |
| 416 |
MODULE_PARM(mga_brightness, "1-" __MODULE_STRING(MGA_MAX_CARDS) "i"); |
438 |
MODULE_PARM(mga_brightness, "1-" __MODULE_STRING(MGA_MAX_CARDS) "i"); |
| 417 |
MODULE_PARM(mga_contrast, "1-" __MODULE_STRING(MGA_MAX_CARDS) "i"); |
439 |
MODULE_PARM(mga_contrast, "1-" __MODULE_STRING(MGA_MAX_CARDS) "i"); |
| 418 |
MODULE_PARM(major, "i"); |
440 |
MODULE_PARM(major, "i"); |
|
|
441 |
#endif |
| 419 |
|
442 |
|
| 420 |
#ifdef CRTC2 |
443 |
#ifdef CRTC2 |
| 421 |
static void crtc2_frame_sel(mga_card_t * card, int frame) |
444 |
static void crtc2_frame_sel(mga_card_t * card, int frame) |
|
Lines 1317-1322
Link Here
|
| 1317 |
static void cards_init(mga_card_t * card, struct pci_dev * dev, int card_number, int is_g400); |
1340 |
static void cards_init(mga_card_t * card, struct pci_dev * dev, int card_number, int is_g400); |
| 1318 |
|
1341 |
|
| 1319 |
// returns the number of found cards |
1342 |
// returns the number of found cards |
|
|
1343 |
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) |
| 1344 |
#define PCI_DEV_NAME(d) (d)->name |
| 1345 |
#else |
| 1346 |
#define PCI_DEV_NAME(d) pci_name((d)) |
| 1347 |
#endif |
| 1320 |
static int mga_vid_find_card(void) |
1348 |
static int mga_vid_find_card(void) |
| 1321 |
{ |
1349 |
{ |
| 1322 |
struct pci_dev *dev = NULL; |
1350 |
struct pci_dev *dev = NULL; |
|
Lines 1347-1373
Link Here
|
| 1347 |
switch(dev->device) { |
1375 |
switch(dev->device) { |
| 1348 |
case PCI_DEVICE_ID_MATROX_G550: |
1376 |
case PCI_DEVICE_ID_MATROX_G550: |
| 1349 |
mga_dev_name = "MGA G550"; |
1377 |
mga_dev_name = "MGA G550"; |
| 1350 |
printk(KERN_INFO "mga_vid: Found %s at %s [%s]\n", mga_dev_name, dev->slot_name, dev->name); |
1378 |
printk(KERN_INFO "mga_vid: Found %s at %s [%s]\n", mga_dev_name, dev->slot_name, PCI_DEV_NAME(dev)); |
| 1351 |
cards_init(card, dev, mga_cards_num - 1, 1); |
1379 |
cards_init(card, dev, mga_cards_num - 1, 1); |
| 1352 |
break; |
1380 |
break; |
| 1353 |
case PCI_DEVICE_ID_MATROX_G400: |
1381 |
case PCI_DEVICE_ID_MATROX_G400: |
| 1354 |
mga_dev_name = "MGA G400/G450"; |
1382 |
mga_dev_name = "MGA G400/G450"; |
| 1355 |
printk(KERN_INFO "mga_vid: Found %s at %s [%s]\n", mga_dev_name, dev->slot_name, dev->name); |
1383 |
printk(KERN_INFO "mga_vid: Found %s at %s [%s]\n", mga_dev_name, dev->slot_name, PCI_DEV_NAME(dev)); |
| 1356 |
cards_init(card, dev, mga_cards_num - 1, 1); |
1384 |
cards_init(card, dev, mga_cards_num - 1, 1); |
| 1357 |
break; |
1385 |
break; |
| 1358 |
case PCI_DEVICE_ID_MATROX_G200_AGP: |
1386 |
case PCI_DEVICE_ID_MATROX_G200_AGP: |
| 1359 |
mga_dev_name = "MGA G200 AGP"; |
1387 |
mga_dev_name = "MGA G200 AGP"; |
| 1360 |
printk(KERN_INFO "mga_vid: Found %s at %s [%s]\n", mga_dev_name, dev->slot_name, dev->name); |
1388 |
printk(KERN_INFO "mga_vid: Found %s at %s [%s]\n", mga_dev_name, dev->slot_name, PCI_DEV_NAME(dev)); |
| 1361 |
cards_init(card, dev, mga_cards_num - 1, 0); |
1389 |
cards_init(card, dev, mga_cards_num - 1, 0); |
| 1362 |
break; |
1390 |
break; |
| 1363 |
case PCI_DEVICE_ID_MATROX_G200_PCI: |
1391 |
case PCI_DEVICE_ID_MATROX_G200_PCI: |
| 1364 |
mga_dev_name = "MGA G200"; |
1392 |
mga_dev_name = "MGA G200"; |
| 1365 |
printk(KERN_INFO "mga_vid: Found %s at %s [%s]\n", mga_dev_name, dev->slot_name, dev->name); |
1393 |
printk(KERN_INFO "mga_vid: Found %s at %s [%s]\n", mga_dev_name, dev->slot_name, PCI_DEV_NAME(dev)); |
| 1366 |
cards_init(card, dev, mga_cards_num - 1, 0); |
1394 |
cards_init(card, dev, mga_cards_num - 1, 0); |
| 1367 |
break; |
1395 |
break; |
| 1368 |
default: |
1396 |
default: |
| 1369 |
mga_cards_num--; |
1397 |
mga_cards_num--; |
| 1370 |
printk(KERN_INFO "mga_vid: ignoring matrox device (%d) at %s [%s]\n", dev->device, dev->slot_name, dev->name); |
1398 |
printk(KERN_INFO "mga_vid: ignoring matrox device (%d) at %s [%s]\n", dev->device, dev->slot_name, PCI_DEV_NAME(dev)); |
| 1371 |
break; |
1399 |
break; |
| 1372 |
} |
1400 |
} |
| 1373 |
} |
1401 |
} |
|
Lines 1493-1500
Link Here
|
| 1493 |
// card->config.colkey_on=0; //!!! |
1521 |
// card->config.colkey_on=0; //!!! |
| 1494 |
mga_vid_write_regs(card, 1); |
1522 |
mga_vid_write_regs(card, 1); |
| 1495 |
card->vid_in_use = 0; |
1523 |
card->vid_in_use = 0; |
| 1496 |
|
1524 |
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) |
| 1497 |
MOD_DEC_USE_COUNT; |
1525 |
MOD_DEC_USE_COUNT; |
|
|
1526 |
#else |
| 1527 |
try_module_get(THIS_MODULE); |
| 1528 |
#endif |
| 1498 |
return 0; |
1529 |
return 0; |
| 1499 |
} |
1530 |
} |
| 1500 |
|
1531 |
|
|
Lines 1507-1513
Link Here
|
| 1507 |
{ |
1538 |
{ |
| 1508 |
mga_card_t * card; |
1539 |
mga_card_t * card; |
| 1509 |
|
1540 |
|
| 1510 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,2) |
1541 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,2) && LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) |
| 1511 |
int minor = MINOR(inode->i_rdev.value); |
1542 |
int minor = MINOR(inode->i_rdev.value); |
| 1512 |
#else |
1543 |
#else |
| 1513 |
int minor = MINOR(inode->i_rdev); |
1544 |
int minor = MINOR(inode->i_rdev); |
|
Lines 1539-1545
Link Here
|
| 1539 |
return(-EBUSY); |
1570 |
return(-EBUSY); |
| 1540 |
|
1571 |
|
| 1541 |
card->vid_in_use = 1; |
1572 |
card->vid_in_use = 1; |
|
|
1573 |
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) |
| 1542 |
MOD_INC_USE_COUNT; |
1574 |
MOD_INC_USE_COUNT; |
|
|
1575 |
#else |
| 1576 |
module_put(THIS_MODULE); |
| 1577 |
#endif |
| 1543 |
return(0); |
1578 |
return(0); |
| 1544 |
} |
1579 |
} |
| 1545 |
|
1580 |
|
|
Lines 1574-1580
Link Here
|
| 1574 |
{ |
1609 |
{ |
| 1575 |
unsigned int card_option; |
1610 |
unsigned int card_option; |
| 1576 |
// temp buffer for device filename creation used only by devfs |
1611 |
// temp buffer for device filename creation used only by devfs |
| 1577 |
#ifdef CONFIG_DEVFS_FS |
1612 |
#if CONFIG_DEVFS_FS && LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) |
| 1578 |
char buffer[16]; |
1613 |
char buffer[16]; |
| 1579 |
#endif |
1614 |
#endif |
| 1580 |
|
1615 |
|
|
Lines 1685-1691
Link Here
|
| 1685 |
#endif |
1720 |
#endif |
| 1686 |
|
1721 |
|
| 1687 |
// register devfs, let the kernel give us major and minor numbers |
1722 |
// register devfs, let the kernel give us major and minor numbers |
| 1688 |
#ifdef CONFIG_DEVFS_FS |
1723 |
#if CONFIG_DEVFS_FS && LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) |
|
|
1724 |
dev_t dev_handle = MKDEV(major,card_number); |
| 1725 |
devfs_mk_cdev(dev_handle, S_IFCHR | S_IRUSR | S_IRGRP | S_IWUSR, "video/mga_vid%d",card_number); |
| 1726 |
/* Register a symlink for the first card found. Lets not break default behaviour, eh? */ |
| 1727 |
if( card_number == 0 ) { |
| 1728 |
devfs_mk_symlink("mga_vid","video/mga_vid0"); |
| 1729 |
} |
| 1730 |
#endif |
| 1731 |
#if CONFIG_DEVFS_FS && LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) |
| 1689 |
snprintf(buffer, 16, "mga_vid%d", card_number); |
1732 |
snprintf(buffer, 16, "mga_vid%d", card_number); |
| 1690 |
card->dev_handle = devfs_register(NULL, buffer, DEVFS_FL_AUTO_DEVNUM, |
1733 |
card->dev_handle = devfs_register(NULL, buffer, DEVFS_FL_AUTO_DEVNUM, |
| 1691 |
0, 0, |
1734 |
0, 0, |
|
Lines 1728-1752
Link Here
|
| 1728 |
unregister_chrdev(major, "mga_vid"); |
1771 |
unregister_chrdev(major, "mga_vid"); |
| 1729 |
return -EINVAL; |
1772 |
return -EINVAL; |
| 1730 |
} |
1773 |
} |
| 1731 |
#ifdef CONFIG_DEVFS_FS |
1774 |
/* |
| 1732 |
else { |
1775 |
// we assume that this always succeedes |
| 1733 |
// we assume that this always succeedes |
1776 |
#if CONFIG_DEVFS_FS && LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) |
|
|
1777 |
else { |
| 1778 |
dev_t dev_handle = MKDEV(major,0); |
| 1779 |
devfs_mk_cdev(dev_handle, S_IFCHR | S_IRUSR | S_IRGRP | S_IWUSR,"%s","mga_vid"); |
| 1780 |
} |
| 1781 |
#endif |
| 1782 |
#if CONFIG_DEVFS_FS && LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) |
| 1783 |
else { |
| 1734 |
dev_handle = devfs_register(NULL, "mga_vid", DEVFS_FL_AUTO_DEVNUM, |
1784 |
dev_handle = devfs_register(NULL, "mga_vid", DEVFS_FL_AUTO_DEVNUM, |
| 1735 |
0,0, |
1785 |
0,0, |
| 1736 |
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IFCHR, |
1786 |
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IFCHR, |
| 1737 |
&mga_vid_fops, mga_cards[0]); |
1787 |
&mga_vid_fops, mga_cards[0]); |
| 1738 |
} |
1788 |
} |
| 1739 |
#endif |
1789 |
#endif |
| 1740 |
|
1790 |
*/ |
| 1741 |
return(0); |
1791 |
return(0); |
| 1742 |
} |
1792 |
} |
| 1743 |
|
1793 |
|
|
|
1794 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) |
| 1795 |
module_init(mga_vid_initialize); |
| 1796 |
#else |
| 1744 |
int init_module(void) |
1797 |
int init_module(void) |
| 1745 |
{ |
1798 |
{ |
| 1746 |
return mga_vid_initialize(); |
1799 |
return mga_vid_initialize(); |
| 1747 |
} |
1800 |
} |
|
|
1801 |
#endif |
| 1748 |
|
1802 |
|
|
|
1803 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) |
| 1804 |
static void mga_cleanup_module(void) |
| 1805 |
#else |
| 1749 |
void cleanup_module(void) |
1806 |
void cleanup_module(void) |
|
|
1807 |
#endif |
| 1750 |
{ |
1808 |
{ |
| 1751 |
int i; |
1809 |
int i; |
| 1752 |
mga_card_t * card; |
1810 |
mga_card_t * card; |
|
Lines 1765-1771
Link Here
|
| 1765 |
iounmap(card->mmio_base); |
1823 |
iounmap(card->mmio_base); |
| 1766 |
if(card->param_buff) |
1824 |
if(card->param_buff) |
| 1767 |
kfree(card->param_buff); |
1825 |
kfree(card->param_buff); |
| 1768 |
#ifdef CONFIG_DEVFS_FS |
1826 |
#if CONFIG_DEVFS_FS && LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) |
|
|
1827 |
devfs_remove("video/mga_vid%d",i); |
| 1828 |
#endif |
| 1829 |
#if CONFIG_DEVFS_FS && LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) |
| 1769 |
if(card->dev_handle) devfs_unregister(card->dev_handle); |
1830 |
if(card->dev_handle) devfs_unregister(card->dev_handle); |
| 1770 |
#endif |
1831 |
#endif |
| 1771 |
|
1832 |
|
|
Lines 1776-1783
Link Here
|
| 1776 |
|
1837 |
|
| 1777 |
//FIXME turn off BES |
1838 |
//FIXME turn off BES |
| 1778 |
printk(KERN_INFO "mga_vid: Cleaning up module\n"); |
1839 |
printk(KERN_INFO "mga_vid: Cleaning up module\n"); |
| 1779 |
#ifdef CONFIG_DEVFS_FS |
1840 |
#if CONFIG_DEVFS_FS && LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) |
| 1780 |
if(dev_handle) devfs_unregister(dev_handle); |
1841 |
devfs_remove("%s","mga_vid"); |
|
|
1842 |
#endif |
| 1843 |
#if CONFIG_DEVFS_FS && LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) |
| 1844 |
devfs_unregister(dev_handle); |
| 1781 |
#endif |
1845 |
#endif |
| 1782 |
unregister_chrdev(major, "mga_vid"); |
1846 |
unregister_chrdev(major, "mga_vid"); |
| 1783 |
} |
1847 |
} |
|
|
1848 |
|
| 1849 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) |
| 1850 |
module_exit(mga_cleanup_module); |
| 1851 |
#endif |