scx200.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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/mutex.h>
  10. #include <linux/pci.h>
  11. #include <linux/scx200.h>
  12. #include <linux/scx200_gpio.h>
  13. /* Verify that the configuration block really is there */
  14. #define scx200_cb_probe(base) (inw((base) + SCx200_CBA) == (base))
  15. #define NAME "scx200"
  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. long scx200_gpio_shadow[2];
  21. unsigned scx200_cb_base = 0;
  22. static struct pci_device_id scx200_tbl[] = {
  23. { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_SCx200_BRIDGE) },
  24. { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_SC1100_BRIDGE) },
  25. { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_SCx200_XBUS) },
  26. { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_SC1100_XBUS) },
  27. { },
  28. };
  29. MODULE_DEVICE_TABLE(pci,scx200_tbl);
  30. static int __devinit 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 __devinit 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 __devinit 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. printk(KERN_INFO NAME ": GPIO base 0x%x\n", base);
  51. if (request_region(base, SCx200_GPIO_SIZE, "NatSemi SCx200 GPIO") == 0) {
  52. printk(KERN_ERR NAME ": can't allocate I/O for GPIOs\n");
  53. return -EBUSY;
  54. }
  55. scx200_gpio_base = base;
  56. scx200_init_shadow();
  57. } else {
  58. /* find the base of the Configuration Block */
  59. if (scx200_cb_probe(SCx200_CB_BASE_FIXED)) {
  60. scx200_cb_base = SCx200_CB_BASE_FIXED;
  61. } else {
  62. pci_read_config_dword(pdev, SCx200_CBA_SCRATCH, &base);
  63. if (scx200_cb_probe(base)) {
  64. scx200_cb_base = base;
  65. } else {
  66. printk(KERN_WARNING NAME ": Configuration Block not found\n");
  67. return -ENODEV;
  68. }
  69. }
  70. printk(KERN_INFO NAME ": Configuration Block base 0x%x\n", scx200_cb_base);
  71. }
  72. return 0;
  73. }
  74. u32 scx200_gpio_configure(unsigned index, u32 mask, u32 bits)
  75. {
  76. u32 config, new_config;
  77. mutex_lock(&scx200_gpio_config_lock);
  78. outl(index, scx200_gpio_base + 0x20);
  79. config = inl(scx200_gpio_base + 0x24);
  80. new_config = (config & mask) | bits;
  81. outl(new_config, scx200_gpio_base + 0x24);
  82. mutex_unlock(&scx200_gpio_config_lock);
  83. return config;
  84. }
  85. static int __init scx200_init(void)
  86. {
  87. printk(KERN_INFO NAME ": NatSemi SCx200 Driver\n");
  88. return pci_register_driver(&scx200_pci_driver);
  89. }
  90. static void __exit scx200_cleanup(void)
  91. {
  92. pci_unregister_driver(&scx200_pci_driver);
  93. release_region(scx200_gpio_base, SCx200_GPIO_SIZE);
  94. }
  95. module_init(scx200_init);
  96. module_exit(scx200_cleanup);
  97. EXPORT_SYMBOL(scx200_gpio_base);
  98. EXPORT_SYMBOL(scx200_gpio_shadow);
  99. EXPORT_SYMBOL(scx200_gpio_configure);
  100. EXPORT_SYMBOL(scx200_cb_base);