scx200_32.c 3.3 KB

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