ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / drivers / parisc / hppb.c
1 /*
2 ** hppb.c:
3 **      HP-PB bus driver for the NOVA and K-Class systems.
4 **
5 **      (c) Copyright 2002 Ryan Bradetich
6 **      (c) Copyright 2002 Hewlett-Packard Company
7 **
8 ** This program is free software; you can redistribute it and/or modify
9 ** it under the terms of the GNU General Public License as published by
10 ** the Free Software Foundation; either version 2 of the License, or
11 ** (at your option) any later version.
12 **
13 ** This Driver currently only supports the console (port 0) on the MUX.
14 ** Additional work will be needed on this driver to enable the full
15 ** functionality of the MUX.
16 **
17 */
18
19 #include <linux/config.h>
20 #include <linux/types.h>
21 #include <linux/init.h>
22 #include <linux/mm.h>
23 #include <linux/slab.h>
24 #include <linux/ioport.h>
25
26 #include <asm/io.h>
27 #include <asm/hardware.h>
28 #include <asm/parisc-device.h>
29
30 #include <linux/pci.h>
31
32 struct hppb_card {
33         unsigned long hpa;
34         struct resource mmio_region;
35         struct hppb_card *next;
36 };
37
38 struct hppb_card hppb_card_head = {
39         .hpa = 0,
40         .next = NULL,
41 };
42
43 #define IO_IO_LOW  offsetof(struct bc_module, io_io_low)
44 #define IO_IO_HIGH offsetof(struct bc_module, io_io_high)
45
46 /**
47  * hppb_probe - Determine if the hppb driver should claim this device.
48  * @dev: The device which has been found
49  *
50  * Determine if hppb driver should claim this chip (return 0) or not 
51  * (return 1). If so, initialize the chip and tell other partners in crime 
52  * they have work to do.
53  */
54 static int hppb_probe(struct parisc_device *dev)
55 {
56         int status;
57         struct hppb_card *card = &hppb_card_head;
58
59         while(card->next) {
60                 card = card->next;
61         }
62
63         if(card->hpa) {
64                 card->next = kmalloc(sizeof(struct hppb_card), GFP_KERNEL);
65                 if(!card->next) {
66                         printk(KERN_ERR "HP-PB: Unable to allocate memory.\n");
67                         return 1;
68                 }
69                 memset(card->next, '\0', sizeof(struct hppb_card));
70                 card = card->next;
71         }
72         printk(KERN_INFO "Found GeckoBoa at 0x%lx\n", dev->hpa);
73
74         card->hpa = dev->hpa;
75         card->mmio_region.name = "HP-PB Bus";
76         card->mmio_region.flags = IORESOURCE_MEM;
77
78         card->mmio_region.start = __raw_readl(dev->hpa + IO_IO_LOW);
79         card->mmio_region.end = __raw_readl(dev->hpa + IO_IO_HIGH) - 1;
80
81         status = ccio_request_resource(dev, &card->mmio_region);
82         if(status < 0) {
83                 printk(KERN_ERR "%s: failed to claim HP-PB bus space (%08lx, %08lx)\n",
84                         __FILE__, card->mmio_region.start, card->mmio_region.end);
85         }
86
87         return 0;
88 }
89
90
91 static struct parisc_device_id hppb_tbl[] = {
92         { HPHW_BCPORT, HVERSION_REV_ANY_ID, 0x500, 0xc }, 
93         { 0, }
94 };
95
96 static struct parisc_driver hppb_driver = {
97         .name =         "Gecko Boa",
98         .id_table =     hppb_tbl,
99         .probe =        hppb_probe,
100 };
101
102 /**
103  * hppb_init - HP-PB bus initalization procedure.
104  *
105  * Register this driver.   
106  */
107 void __init hppb_init(void)
108 {
109         register_parisc_driver(&hppb_driver);
110 }