scx200_32.c 3.1 KB
Newer Older
D
Dave Jones 已提交
1 2 3 4 5
/*
 *  Copyright (c) 2001,2002 Christer Weinigel <wingel@nano-system.com>
 *
 *  National Semiconductor SCx200 support.
 */
L
Linus Torvalds 已提交
6 7 8 9 10

#include <linux/module.h>
#include <linux/errno.h>
#include <linux/kernel.h>
#include <linux/init.h>
11
#include <linux/mutex.h>
L
Linus Torvalds 已提交
12 13 14
#include <linux/pci.h>

#include <linux/scx200.h>
15
#include <linux/scx200_gpio.h>
L
Linus Torvalds 已提交
16 17 18 19 20 21 22 23 24

/* Verify that the configuration block really is there */
#define scx200_cb_probe(base) (inw((base) + SCx200_CBA) == (base))

MODULE_AUTHOR("Christer Weinigel <wingel@nano-system.com>");
MODULE_DESCRIPTION("NatSemi SCx200 Driver");
MODULE_LICENSE("GPL");

unsigned scx200_gpio_base = 0;
25
unsigned long scx200_gpio_shadow[2];
L
Linus Torvalds 已提交
26 27 28 29

unsigned scx200_cb_base = 0;

static struct pci_device_id scx200_tbl[] = {
J
Jim Cromie 已提交
30 31 32 33
	{ PCI_VDEVICE(NS, PCI_DEVICE_ID_NS_SCx200_BRIDGE) },
	{ PCI_VDEVICE(NS, PCI_DEVICE_ID_NS_SC1100_BRIDGE) },
	{ PCI_VDEVICE(NS, PCI_DEVICE_ID_NS_SCx200_XBUS)   },
	{ PCI_VDEVICE(NS, PCI_DEVICE_ID_NS_SC1100_XBUS)   },
L
Linus Torvalds 已提交
34 35 36 37
	{ },
};
MODULE_DEVICE_TABLE(pci,scx200_tbl);

38
static int scx200_probe(struct pci_dev *, const struct pci_device_id *);
L
Linus Torvalds 已提交
39 40 41 42 43 44 45

static struct pci_driver scx200_pci_driver = {
	.name = "scx200",
	.id_table = scx200_tbl,
	.probe = scx200_probe,
};

46
static DEFINE_MUTEX(scx200_gpio_config_lock);
L
Linus Torvalds 已提交
47

48
static void scx200_init_shadow(void)
L
Linus Torvalds 已提交
49 50
{
	int bank;
51 52 53 54 55 56

	/* read the current values driven on the GPIO signals */
	for (bank = 0; bank < 2; ++bank)
		scx200_gpio_shadow[bank] = inl(scx200_gpio_base + 0x10 * bank);
}

57
static int scx200_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
58
{
L
Linus Torvalds 已提交
59 60 61 62 63
	unsigned base;

	if (pdev->device == PCI_DEVICE_ID_NS_SCx200_BRIDGE ||
	    pdev->device == PCI_DEVICE_ID_NS_SC1100_BRIDGE) {
		base = pci_resource_start(pdev, 0);
64
		pr_info("GPIO base 0x%x\n", base);
L
Linus Torvalds 已提交
65

66 67 68
		if (!request_region(base, SCx200_GPIO_SIZE,
				    "NatSemi SCx200 GPIO")) {
			pr_err("can't allocate I/O for GPIOs\n");
L
Linus Torvalds 已提交
69 70 71 72
			return -EBUSY;
		}

		scx200_gpio_base = base;
73
		scx200_init_shadow();
L
Linus Torvalds 已提交
74 75 76 77 78 79 80 81 82 83

	} else {
		/* find the base of the Configuration Block */
		if (scx200_cb_probe(SCx200_CB_BASE_FIXED)) {
			scx200_cb_base = SCx200_CB_BASE_FIXED;
		} else {
			pci_read_config_dword(pdev, SCx200_CBA_SCRATCH, &base);
			if (scx200_cb_probe(base)) {
				scx200_cb_base = base;
			} else {
84
				pr_warn("Configuration Block not found\n");
L
Linus Torvalds 已提交
85 86 87
				return -ENODEV;
			}
		}
88
		pr_info("Configuration Block base 0x%x\n", scx200_cb_base);
L
Linus Torvalds 已提交
89 90 91 92 93
	}

	return 0;
}

94
u32 scx200_gpio_configure(unsigned index, u32 mask, u32 bits)
L
Linus Torvalds 已提交
95 96 97
{
	u32 config, new_config;

98
	mutex_lock(&scx200_gpio_config_lock);
L
Linus Torvalds 已提交
99 100 101 102 103 104 105

	outl(index, scx200_gpio_base + 0x20);
	config = inl(scx200_gpio_base + 0x24);

	new_config = (config & mask) | bits;
	outl(new_config, scx200_gpio_base + 0x24);

106
	mutex_unlock(&scx200_gpio_config_lock);
L
Linus Torvalds 已提交
107 108 109 110 111 112

	return config;
}

static int __init scx200_init(void)
{
113
	pr_info("NatSemi SCx200 Driver\n");
114
	return pci_register_driver(&scx200_pci_driver);
L
Linus Torvalds 已提交
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
}

static void __exit scx200_cleanup(void)
{
	pci_unregister_driver(&scx200_pci_driver);
	release_region(scx200_gpio_base, SCx200_GPIO_SIZE);
}

module_init(scx200_init);
module_exit(scx200_cleanup);

EXPORT_SYMBOL(scx200_gpio_base);
EXPORT_SYMBOL(scx200_gpio_shadow);
EXPORT_SYMBOL(scx200_gpio_configure);
EXPORT_SYMBOL(scx200_cb_base);