scx200.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /* linux/arch/i386/kernel/scx200.c
  2. Copyright (c) 2001,2002 Christer Weinigel <wingel@nano-system.com>
  3. National Semiconductor SCx200 support. */
  4. #include <linux/config.h>
  5. #include <linux/module.h>
  6. #include <linux/errno.h>
  7. #include <linux/kernel.h>
  8. #include <linux/init.h>
  9. #include <linux/pci.h>
  10. #include <linux/scx200.h>
  11. #include <linux/scx200_gpio.h>
  12. /* Verify that the configuration block really is there */
  13. #define scx200_cb_probe(base) (inw((base) + SCx200_CBA) == (base))
  14. #define NAME "scx200"
  15. MODULE_AUTHOR("Christer Weinigel <wingel@nano-system.com>");
  16. MODULE_DESCRIPTION("NatSemi SCx200 Driver");
  17. MODULE_LICENSE("GPL");
  18. unsigned scx200_gpio_base = 0;
  19. long scx200_gpio_shadow[2];
  20. unsigned scx200_cb_base = 0;
  21. static struct pci_device_id scx200_tbl[] = {
  22. { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_SCx200_BRIDGE) },
  23. { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_SC1100_BRIDGE) },
  24. { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_SCx200_XBUS) },
  25. { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_SC1100_XBUS) },
  26. { },
  27. };
  28. MODULE_DEVICE_TABLE(pci,scx200_tbl);
  29. static int __devinit scx200_probe(struct pci_dev *, const struct pci_device_id *);
  30. static struct pci_driver scx200_pci_driver = {
  31. .name = "scx200",
  32. .id_table = scx200_tbl,
  33. .probe = scx200_probe,
  34. };
  35. static DEFINE_SPINLOCK(scx200_gpio_config_lock);
  36. static int __devinit scx200_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  37. {
  38. int bank;
  39. unsigned base;
  40. if (pdev->device == PCI_DEVICE_ID_NS_SCx200_BRIDGE ||
  41. pdev->device == PCI_DEVICE_ID_NS_SC1100_BRIDGE) {
  42. base = pci_resource_start(pdev, 0);
  43. printk(KERN_INFO NAME ": GPIO base 0x%x\n", base);
  44. if (request_region(base, SCx200_GPIO_SIZE, "NatSemi SCx200 GPIO") == 0) {
  45. printk(KERN_ERR NAME ": can't allocate I/O for GPIOs\n");
  46. return -EBUSY;
  47. }
  48. scx200_gpio_base = base;
  49. /* read the current values driven on the GPIO signals */
  50. for (bank = 0; bank < 2; ++bank)
  51. scx200_gpio_shadow[bank] = inl(scx200_gpio_base + 0x10 * bank);
  52. } else {
  53. /* find the base of the Configuration Block */
  54. if (scx200_cb_probe(SCx200_CB_BASE_FIXED)) {
  55. scx200_cb_base = SCx200_CB_BASE_FIXED;
  56. } else {
  57. pci_read_config_dword(pdev, SCx200_CBA_SCRATCH, &base);
  58. if (scx200_cb_probe(base)) {
  59. scx200_cb_base = base;
  60. } else {
  61. printk(KERN_WARNING NAME ": Configuration Block not found\n");
  62. return -ENODEV;
  63. }
  64. }
  65. printk(KERN_INFO NAME ": Configuration Block base 0x%x\n", scx200_cb_base);
  66. }
  67. return 0;
  68. }
  69. u32 scx200_gpio_configure(unsigned index, u32 mask, u32 bits)
  70. {
  71. u32 config, new_config;
  72. unsigned long flags;
  73. spin_lock_irqsave(&scx200_gpio_config_lock, flags);
  74. outl(index, scx200_gpio_base + 0x20);
  75. config = inl(scx200_gpio_base + 0x24);
  76. new_config = (config & mask) | bits;
  77. outl(new_config, scx200_gpio_base + 0x24);
  78. spin_unlock_irqrestore(&scx200_gpio_config_lock, flags);
  79. return config;
  80. }
  81. void scx200_gpio_dump(unsigned index)
  82. {
  83. u32 config = scx200_gpio_configure(index, ~0, 0);
  84. printk(KERN_INFO NAME ": GPIO-%02u: 0x%08lx %s %s %s %s %s %s %s\n",
  85. index, (unsigned long) config,
  86. (config & 1) ? "OE" : "TS", /* output enabled / tristate */
  87. (config & 2) ? "PP" : "OD", /* push pull / open drain */
  88. (config & 4) ? "PUE" : "PUD", /* pull up enabled/disabled */
  89. (config & 8) ? "LOCKED" : "", /* locked / unlocked */
  90. (config & 16) ? "LEVEL" : "EDGE", /* level/edge input */
  91. (config & 32) ? "HI" : "LO", /* trigger on rising/falling edge */
  92. (config & 64) ? "DEBOUNCE" : ""); /* debounce */
  93. }
  94. static int __init scx200_init(void)
  95. {
  96. printk(KERN_INFO NAME ": NatSemi SCx200 Driver\n");
  97. return pci_register_driver(&scx200_pci_driver);
  98. }
  99. static void __exit scx200_cleanup(void)
  100. {
  101. pci_unregister_driver(&scx200_pci_driver);
  102. release_region(scx200_gpio_base, SCx200_GPIO_SIZE);
  103. }
  104. module_init(scx200_init);
  105. module_exit(scx200_cleanup);
  106. EXPORT_SYMBOL(scx200_gpio_base);
  107. EXPORT_SYMBOL(scx200_gpio_shadow);
  108. EXPORT_SYMBOL(scx200_gpio_configure);
  109. EXPORT_SYMBOL(scx200_gpio_dump);
  110. EXPORT_SYMBOL(scx200_cb_base);