scx200.c 4.2 KB

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