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