Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | ** hppb.c: |
| 4 | ** HP-PB bus driver for the NOVA and K-Class systems. |
| 5 | ** |
| 6 | ** (c) Copyright 2002 Ryan Bradetich |
| 7 | ** (c) Copyright 2002 Hewlett-Packard Company |
| 8 | ** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | ** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | #include <linux/types.h> |
| 13 | #include <linux/init.h> |
| 14 | #include <linux/mm.h> |
| 15 | #include <linux/slab.h> |
Frank Lichtenheld | bec85e8 | 2007-07-17 19:30:38 +0200 | [diff] [blame] | 16 | #include <linux/dma-mapping.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <linux/ioport.h> |
| 18 | |
| 19 | #include <asm/io.h> |
| 20 | #include <asm/hardware.h> |
| 21 | #include <asm/parisc-device.h> |
| 22 | |
Christoph Hellwig | 9b8eeab | 2019-01-29 19:13:04 +0100 | [diff] [blame] | 23 | #include "iommu.h" |
| 24 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | struct hppb_card { |
| 26 | unsigned long hpa; |
| 27 | struct resource mmio_region; |
| 28 | struct hppb_card *next; |
| 29 | }; |
| 30 | |
Adrian Bunk | df8e5bc | 2008-12-02 03:28:16 +0000 | [diff] [blame] | 31 | static struct hppb_card hppb_card_head = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | .hpa = 0, |
| 33 | .next = NULL, |
| 34 | }; |
| 35 | |
| 36 | #define IO_IO_LOW offsetof(struct bc_module, io_io_low) |
| 37 | #define IO_IO_HIGH offsetof(struct bc_module, io_io_high) |
| 38 | |
| 39 | /** |
| 40 | * hppb_probe - Determine if the hppb driver should claim this device. |
| 41 | * @dev: The device which has been found |
| 42 | * |
| 43 | * Determine if hppb driver should claim this chip (return 0) or not |
| 44 | * (return 1). If so, initialize the chip and tell other partners in crime |
| 45 | * they have work to do. |
| 46 | */ |
Helge Deller | cfe4fbf | 2017-08-21 22:02:19 +0200 | [diff] [blame] | 47 | static int __init hppb_probe(struct parisc_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | { |
| 49 | int status; |
| 50 | struct hppb_card *card = &hppb_card_head; |
| 51 | |
| 52 | while(card->next) { |
| 53 | card = card->next; |
| 54 | } |
| 55 | |
| 56 | if(card->hpa) { |
Helge Deller | cb6fc18 | 2006-01-17 12:40:40 -0700 | [diff] [blame] | 57 | card->next = kzalloc(sizeof(struct hppb_card), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | if(!card->next) { |
| 59 | printk(KERN_ERR "HP-PB: Unable to allocate memory.\n"); |
| 60 | return 1; |
| 61 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | card = card->next; |
| 63 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | |
Matthew Wilcox | 53f01bb | 2005-10-21 22:36:40 -0400 | [diff] [blame] | 65 | card->hpa = dev->hpa.start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | card->mmio_region.name = "HP-PB Bus"; |
| 67 | card->mmio_region.flags = IORESOURCE_MEM; |
| 68 | |
Matthew Wilcox | 53f01bb | 2005-10-21 22:36:40 -0400 | [diff] [blame] | 69 | card->mmio_region.start = gsc_readl(dev->hpa.start + IO_IO_LOW); |
| 70 | card->mmio_region.end = gsc_readl(dev->hpa.start + IO_IO_HIGH) - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | |
| 72 | status = ccio_request_resource(dev, &card->mmio_region); |
Helge Deller | 4ccac58 | 2019-09-05 16:35:12 +0200 | [diff] [blame] | 73 | |
| 74 | pr_info("Found GeckoBoa at %pap, bus space %pR,%s claimed.\n", |
| 75 | &dev->hpa.start, |
| 76 | &card->mmio_region, |
| 77 | (status < 0) ? " not":"" ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | |
| 79 | return 0; |
| 80 | } |
| 81 | |
Helge Deller | cfe4fbf | 2017-08-21 22:02:19 +0200 | [diff] [blame] | 82 | static const struct parisc_device_id hppb_tbl[] __initconst = { |
Ryan Bradetich | 075b878 | 2006-11-03 05:05:01 +0000 | [diff] [blame] | 83 | { HPHW_BCPORT, HVERSION_REV_ANY_ID, 0x500, 0xc }, /* E25 and K */ |
| 84 | { HPHW_BCPORT, 0x0, 0x501, 0xc }, /* E35 */ |
| 85 | { HPHW_BCPORT, 0x0, 0x502, 0xc }, /* E45 */ |
| 86 | { HPHW_BCPORT, 0x0, 0x503, 0xc }, /* E55 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | { 0, } |
| 88 | }; |
| 89 | |
Helge Deller | cfe4fbf | 2017-08-21 22:02:19 +0200 | [diff] [blame] | 90 | static struct parisc_driver hppb_driver __refdata = { |
Matthew Wilcox | bdad1f8 | 2005-10-21 22:36:23 -0400 | [diff] [blame] | 91 | .name = "gecko_boa", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | .id_table = hppb_tbl, |
| 93 | .probe = hppb_probe, |
| 94 | }; |
| 95 | |
| 96 | /** |
Joe Perches | 4f63ba1 | 2008-02-03 17:24:37 +0200 | [diff] [blame] | 97 | * hppb_init - HP-PB bus initialization procedure. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | * |
| 99 | * Register this driver. |
| 100 | */ |
| 101 | void __init hppb_init(void) |
| 102 | { |
| 103 | register_parisc_driver(&hppb_driver); |
| 104 | } |