blob: 9bf590cefc7d4d55d89fde0561ec6a5fb70d5192 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* linux/arch/i386/kernel/scx200.c
2
3 Copyright (c) 2001,2002 Christer Weinigel <wingel@nano-system.com>
4
5 National Semiconductor SCx200 support. */
6
7#include <linux/config.h>
8#include <linux/module.h>
9#include <linux/errno.h>
10#include <linux/kernel.h>
11#include <linux/init.h>
Jim Cromie8bcf6132006-06-27 02:54:25 -070012#include <linux/mutex.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/pci.h>
14
15#include <linux/scx200.h>
Adrian Bunkcc658cf2005-11-07 00:58:37 -080016#include <linux/scx200_gpio.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
18/* Verify that the configuration block really is there */
19#define scx200_cb_probe(base) (inw((base) + SCx200_CBA) == (base))
20
21#define NAME "scx200"
22
23MODULE_AUTHOR("Christer Weinigel <wingel@nano-system.com>");
24MODULE_DESCRIPTION("NatSemi SCx200 Driver");
25MODULE_LICENSE("GPL");
26
27unsigned scx200_gpio_base = 0;
28long scx200_gpio_shadow[2];
29
30unsigned scx200_cb_base = 0;
31
32static struct pci_device_id scx200_tbl[] = {
33 { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_SCx200_BRIDGE) },
34 { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_SC1100_BRIDGE) },
35 { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_SCx200_XBUS) },
36 { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_SC1100_XBUS) },
37 { },
38};
39MODULE_DEVICE_TABLE(pci,scx200_tbl);
40
41static int __devinit scx200_probe(struct pci_dev *, const struct pci_device_id *);
42
43static struct pci_driver scx200_pci_driver = {
44 .name = "scx200",
45 .id_table = scx200_tbl,
46 .probe = scx200_probe,
47};
48
Jim Cromie8bcf6132006-06-27 02:54:25 -070049static DEFINE_MUTEX(scx200_gpio_config_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
Jim Cromie9b170b82006-06-27 02:54:17 -070051static void __devinit scx200_init_shadow(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070052{
53 int bank;
Jim Cromie9b170b82006-06-27 02:54:17 -070054
55 /* read the current values driven on the GPIO signals */
56 for (bank = 0; bank < 2; ++bank)
57 scx200_gpio_shadow[bank] = inl(scx200_gpio_base + 0x10 * bank);
58}
59
60static int __devinit scx200_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
61{
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 unsigned base;
63
64 if (pdev->device == PCI_DEVICE_ID_NS_SCx200_BRIDGE ||
65 pdev->device == PCI_DEVICE_ID_NS_SC1100_BRIDGE) {
66 base = pci_resource_start(pdev, 0);
67 printk(KERN_INFO NAME ": GPIO base 0x%x\n", base);
68
69 if (request_region(base, SCx200_GPIO_SIZE, "NatSemi SCx200 GPIO") == 0) {
70 printk(KERN_ERR NAME ": can't allocate I/O for GPIOs\n");
71 return -EBUSY;
72 }
73
74 scx200_gpio_base = base;
Jim Cromie9b170b82006-06-27 02:54:17 -070075 scx200_init_shadow();
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
77 } else {
78 /* find the base of the Configuration Block */
79 if (scx200_cb_probe(SCx200_CB_BASE_FIXED)) {
80 scx200_cb_base = SCx200_CB_BASE_FIXED;
81 } else {
82 pci_read_config_dword(pdev, SCx200_CBA_SCRATCH, &base);
83 if (scx200_cb_probe(base)) {
84 scx200_cb_base = base;
85 } else {
86 printk(KERN_WARNING NAME ": Configuration Block not found\n");
87 return -ENODEV;
88 }
89 }
90 printk(KERN_INFO NAME ": Configuration Block base 0x%x\n", scx200_cb_base);
91 }
92
93 return 0;
94}
95
Jim Cromie55b8c042006-06-27 02:54:15 -070096u32 scx200_gpio_configure(unsigned index, u32 mask, u32 bits)
Linus Torvalds1da177e2005-04-16 15:20:36 -070097{
98 u32 config, new_config;
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
Jim Cromie8bcf6132006-06-27 02:54:25 -0700100 mutex_lock(&scx200_gpio_config_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
102 outl(index, scx200_gpio_base + 0x20);
103 config = inl(scx200_gpio_base + 0x24);
104
105 new_config = (config & mask) | bits;
106 outl(new_config, scx200_gpio_base + 0x24);
107
Jim Cromie8bcf6132006-06-27 02:54:25 -0700108 mutex_unlock(&scx200_gpio_config_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
110 return config;
111}
112
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113static int __init scx200_init(void)
114{
115 printk(KERN_INFO NAME ": NatSemi SCx200 Driver\n");
116
Richard Knutssond1d6da82005-11-30 00:59:14 +0100117 return pci_register_driver(&scx200_pci_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118}
119
120static void __exit scx200_cleanup(void)
121{
122 pci_unregister_driver(&scx200_pci_driver);
123 release_region(scx200_gpio_base, SCx200_GPIO_SIZE);
124}
125
126module_init(scx200_init);
127module_exit(scx200_cleanup);
128
129EXPORT_SYMBOL(scx200_gpio_base);
130EXPORT_SYMBOL(scx200_gpio_shadow);
131EXPORT_SYMBOL(scx200_gpio_configure);
132EXPORT_SYMBOL(scx200_cb_base);