scx200.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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/module.h>
  5. #include <linux/errno.h>
  6. #include <linux/kernel.h>
  7. #include <linux/init.h>
  8. #include <linux/mutex.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_MUTEX(scx200_gpio_config_lock);
  36. static void __devinit scx200_init_shadow(void)
  37. {
  38. int bank;
  39. /* read the current values driven on the GPIO signals */
  40. for (bank = 0; bank < 2; ++bank)
  41. scx200_gpio_shadow[bank] = inl(scx200_gpio_base + 0x10 * bank);
  42. }
  43. static int __devinit scx200_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  44. {
  45. unsigned base;
  46. if (pdev->device == PCI_DEVICE_ID_NS_SCx200_BRIDGE ||
  47. pdev->device == PCI_DEVICE_ID_NS_SC1100_BRIDGE) {
  48. base = pci_resource_start(pdev, 0);
  49. printk(KERN_INFO NAME ": GPIO base 0x%x\n", base);
  50. if (request_region(base, SCx200_GPIO_SIZE, "NatSemi SCx200 GPIO") == 0) {
  51. printk(KERN_ERR NAME ": can't allocate I/O for GPIOs\n");
  52. return -EBUSY;
  53. }
  54. scx200_gpio_base = base;
  55. scx200_init_shadow();
  56. } else {
  57. /* find the base of the Configuration Block */
  58. if (scx200_cb_probe(SCx200_CB_BASE_FIXED)) {
  59. scx200_cb_base = SCx200_CB_BASE_FIXED;
  60. } else {
  61. pci_read_config_dword(pdev, SCx200_CBA_SCRATCH, &base);
  62. if (scx200_cb_probe(base)) {
  63. scx200_cb_base = base;
  64. } else {
  65. printk(KERN_WARNING NAME ": Configuration Block not found\n");
  66. return -ENODEV;
  67. }
  68. }
  69. printk(KERN_INFO NAME ": Configuration Block base 0x%x\n", scx200_cb_base);
  70. }
  71. return 0;
  72. }
  73. u32 scx200_gpio_configure(unsigned index, u32 mask, u32 bits)
  74. {
  75. u32 config, new_config;
  76. mutex_lock(&scx200_gpio_config_lock);
  77. outl(index, scx200_gpio_base + 0x20);
  78. config = inl(scx200_gpio_base + 0x24);
  79. new_config = (config & mask) | bits;
  80. outl(new_config, scx200_gpio_base + 0x24);
  81. mutex_unlock(&scx200_gpio_config_lock);
  82. return config;
  83. }
  84. static int __init scx200_init(void)
  85. {
  86. printk(KERN_INFO NAME ": NatSemi SCx200 Driver\n");
  87. return pci_register_driver(&scx200_pci_driver);
  88. }
  89. static void __exit scx200_cleanup(void)
  90. {
  91. pci_unregister_driver(&scx200_pci_driver);
  92. release_region(scx200_gpio_base, SCx200_GPIO_SIZE);
  93. }
  94. module_init(scx200_init);
  95. module_exit(scx200_cleanup);
  96. EXPORT_SYMBOL(scx200_gpio_base);
  97. EXPORT_SYMBOL(scx200_gpio_shadow);
  98. EXPORT_SYMBOL(scx200_gpio_configure);
  99. EXPORT_SYMBOL(scx200_cb_base);