Dave Jones | 835c34a | 2007-10-12 21:10:53 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2001,2002 Christer Weinigel <wingel@nano-system.com> |
| 3 | * |
| 4 | * National Semiconductor SCx200 support. |
| 5 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | #include <linux/module.h> |
| 8 | #include <linux/errno.h> |
| 9 | #include <linux/kernel.h> |
| 10 | #include <linux/init.h> |
Jim Cromie | 8bcf613 | 2006-06-27 02:54:25 -0700 | [diff] [blame] | 11 | #include <linux/mutex.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <linux/pci.h> |
| 13 | |
| 14 | #include <linux/scx200.h> |
Adrian Bunk | cc658cf | 2005-11-07 00:58:37 -0800 | [diff] [blame] | 15 | #include <linux/scx200_gpio.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | |
| 17 | /* Verify that the configuration block really is there */ |
| 18 | #define scx200_cb_probe(base) (inw((base) + SCx200_CBA) == (base)) |
| 19 | |
| 20 | #define NAME "scx200" |
| 21 | |
| 22 | MODULE_AUTHOR("Christer Weinigel <wingel@nano-system.com>"); |
| 23 | MODULE_DESCRIPTION("NatSemi SCx200 Driver"); |
| 24 | MODULE_LICENSE("GPL"); |
| 25 | |
| 26 | unsigned scx200_gpio_base = 0; |
Al Viro | 64b3361 | 2007-10-14 19:35:20 +0100 | [diff] [blame] | 27 | unsigned long scx200_gpio_shadow[2]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | |
| 29 | unsigned scx200_cb_base = 0; |
| 30 | |
| 31 | static struct pci_device_id scx200_tbl[] = { |
| 32 | { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_SCx200_BRIDGE) }, |
| 33 | { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_SC1100_BRIDGE) }, |
| 34 | { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_SCx200_XBUS) }, |
| 35 | { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_SC1100_XBUS) }, |
| 36 | { }, |
| 37 | }; |
| 38 | MODULE_DEVICE_TABLE(pci,scx200_tbl); |
| 39 | |
| 40 | static int __devinit scx200_probe(struct pci_dev *, const struct pci_device_id *); |
| 41 | |
| 42 | static struct pci_driver scx200_pci_driver = { |
| 43 | .name = "scx200", |
| 44 | .id_table = scx200_tbl, |
| 45 | .probe = scx200_probe, |
| 46 | }; |
| 47 | |
Jim Cromie | 8bcf613 | 2006-06-27 02:54:25 -0700 | [diff] [blame] | 48 | static DEFINE_MUTEX(scx200_gpio_config_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
Jim Cromie | 9b170b8 | 2006-06-27 02:54:17 -0700 | [diff] [blame] | 50 | static void __devinit scx200_init_shadow(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | { |
| 52 | int bank; |
Jim Cromie | 9b170b8 | 2006-06-27 02:54:17 -0700 | [diff] [blame] | 53 | |
| 54 | /* read the current values driven on the GPIO signals */ |
| 55 | for (bank = 0; bank < 2; ++bank) |
| 56 | scx200_gpio_shadow[bank] = inl(scx200_gpio_base + 0x10 * bank); |
| 57 | } |
| 58 | |
| 59 | static int __devinit scx200_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 60 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | unsigned base; |
| 62 | |
| 63 | if (pdev->device == PCI_DEVICE_ID_NS_SCx200_BRIDGE || |
| 64 | pdev->device == PCI_DEVICE_ID_NS_SC1100_BRIDGE) { |
| 65 | base = pci_resource_start(pdev, 0); |
| 66 | printk(KERN_INFO NAME ": GPIO base 0x%x\n", base); |
| 67 | |
Harvey Harrison | 706b7e1 | 2008-01-31 22:05:45 +0100 | [diff] [blame] | 68 | if (!request_region(base, SCx200_GPIO_SIZE, "NatSemi SCx200 GPIO")) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | printk(KERN_ERR NAME ": can't allocate I/O for GPIOs\n"); |
| 70 | return -EBUSY; |
| 71 | } |
| 72 | |
| 73 | scx200_gpio_base = base; |
Jim Cromie | 9b170b8 | 2006-06-27 02:54:17 -0700 | [diff] [blame] | 74 | scx200_init_shadow(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | |
| 76 | } else { |
| 77 | /* find the base of the Configuration Block */ |
| 78 | if (scx200_cb_probe(SCx200_CB_BASE_FIXED)) { |
| 79 | scx200_cb_base = SCx200_CB_BASE_FIXED; |
| 80 | } else { |
| 81 | pci_read_config_dword(pdev, SCx200_CBA_SCRATCH, &base); |
| 82 | if (scx200_cb_probe(base)) { |
| 83 | scx200_cb_base = base; |
| 84 | } else { |
| 85 | printk(KERN_WARNING NAME ": Configuration Block not found\n"); |
| 86 | return -ENODEV; |
| 87 | } |
| 88 | } |
| 89 | printk(KERN_INFO NAME ": Configuration Block base 0x%x\n", scx200_cb_base); |
| 90 | } |
| 91 | |
| 92 | return 0; |
| 93 | } |
| 94 | |
Jim Cromie | 55b8c04 | 2006-06-27 02:54:15 -0700 | [diff] [blame] | 95 | u32 scx200_gpio_configure(unsigned index, u32 mask, u32 bits) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | { |
| 97 | u32 config, new_config; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | |
Jim Cromie | 8bcf613 | 2006-06-27 02:54:25 -0700 | [diff] [blame] | 99 | mutex_lock(&scx200_gpio_config_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | |
| 101 | outl(index, scx200_gpio_base + 0x20); |
| 102 | config = inl(scx200_gpio_base + 0x24); |
| 103 | |
| 104 | new_config = (config & mask) | bits; |
| 105 | outl(new_config, scx200_gpio_base + 0x24); |
| 106 | |
Jim Cromie | 8bcf613 | 2006-06-27 02:54:25 -0700 | [diff] [blame] | 107 | mutex_unlock(&scx200_gpio_config_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | |
| 109 | return config; |
| 110 | } |
| 111 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | static int __init scx200_init(void) |
| 113 | { |
| 114 | printk(KERN_INFO NAME ": NatSemi SCx200 Driver\n"); |
| 115 | |
Richard Knutsson | d1d6da8 | 2005-11-30 00:59:14 +0100 | [diff] [blame] | 116 | return pci_register_driver(&scx200_pci_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | static void __exit scx200_cleanup(void) |
| 120 | { |
| 121 | pci_unregister_driver(&scx200_pci_driver); |
| 122 | release_region(scx200_gpio_base, SCx200_GPIO_SIZE); |
| 123 | } |
| 124 | |
| 125 | module_init(scx200_init); |
| 126 | module_exit(scx200_cleanup); |
| 127 | |
| 128 | EXPORT_SYMBOL(scx200_gpio_base); |
| 129 | EXPORT_SYMBOL(scx200_gpio_shadow); |
| 130 | EXPORT_SYMBOL(scx200_gpio_configure); |
| 131 | EXPORT_SYMBOL(scx200_cb_base); |