scx200_32.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. MODULE_AUTHOR("Christer Weinigel <wingel@nano-system.com>");
  17. MODULE_DESCRIPTION("NatSemi SCx200 Driver");
  18. MODULE_LICENSE("GPL");
  19. unsigned scx200_gpio_base = 0;
  20. unsigned long scx200_gpio_shadow[2];
  21. unsigned scx200_cb_base = 0;
  22. static struct pci_device_id scx200_tbl[] = {
  23. { PCI_VDEVICE(NS, PCI_DEVICE_ID_NS_SCx200_BRIDGE) },
  24. { PCI_VDEVICE(NS, PCI_DEVICE_ID_NS_SC1100_BRIDGE) },
  25. { PCI_VDEVICE(NS, PCI_DEVICE_ID_NS_SCx200_XBUS) },
  26. { PCI_VDEVICE(NS, PCI_DEVICE_ID_NS_SC1100_XBUS) },
  27. { },
  28. };
  29. MODULE_DEVICE_TABLE(pci,scx200_tbl);
  30. static int scx200_probe(struct pci_dev *, const struct pci_device_id *);
  31. static struct pci_driver scx200_pci_driver = {
  32. .name = "scx200",
  33. .id_table = scx200_tbl,
  34. .probe = scx200_probe,
  35. };
  36. static DEFINE_MUTEX(scx200_gpio_config_lock);
  37. static void scx200_init_shadow(void)
  38. {
  39. int bank;
  40. /* read the current values driven on the GPIO signals */
  41. for (bank = 0; bank < 2; ++bank)
  42. scx200_gpio_shadow[bank] = inl(scx200_gpio_base + 0x10 * bank);
  43. }
  44. static int scx200_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  45. {
  46. unsigned base;
  47. if (pdev->device == PCI_DEVICE_ID_NS_SCx200_BRIDGE ||
  48. pdev->device == PCI_DEVICE_ID_NS_SC1100_BRIDGE) {
  49. base = pci_resource_start(pdev, 0);
  50. pr_info("GPIO base 0x%x\n", base);
  51. if (!request_region(base, SCx200_GPIO_SIZE,
  52. "NatSemi SCx200 GPIO")) {
  53. pr_err("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. pr_warn("Configuration Block not found\n");
  68. return -ENODEV;
  69. }
  70. }
  71. pr_info("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. pr_info("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);