Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * Zalon 53c7xx device driver.
0004  * By Richard Hirst (rhirst@linuxcare.com)
0005  */
0006 
0007 #include <linux/init.h>
0008 #include <linux/interrupt.h>
0009 #include <linux/module.h>
0010 #include <linux/types.h>
0011 #include <asm/hardware.h>
0012 #include <asm/io.h>
0013 
0014 #include "../parisc/gsc.h"
0015 
0016 #include "ncr53c8xx.h"
0017 
0018 MODULE_AUTHOR("Richard Hirst");
0019 MODULE_DESCRIPTION("Bluefish/Zalon 720 SCSI Driver");
0020 MODULE_LICENSE("GPL");
0021 
0022 #define GSC_SCSI_ZALON_OFFSET 0x800
0023 
0024 #define IO_MODULE_EIM       (1*4)
0025 #define IO_MODULE_DC_ADATA  (2*4)
0026 #define IO_MODULE_II_CDATA  (3*4)
0027 #define IO_MODULE_IO_COMMAND    (12*4)
0028 #define IO_MODULE_IO_STATUS (13*4)
0029 
0030 #define IOSTATUS_RY     0x40
0031 #define IOSTATUS_FE     0x80
0032 #define IOIIDATA_SMINT5L    0x40000000
0033 #define IOIIDATA_MINT5EN    0x20000000
0034 #define IOIIDATA_PACKEN     0x10000000
0035 #define IOIIDATA_PREFETCHEN 0x08000000
0036 #define IOIIDATA_IOII       0x00000020
0037 
0038 #define CMD_RESET       5
0039 
0040 static struct ncr_chip zalon720_chip __initdata = {
0041     .revision_id =  0x0f,
0042     .burst_max =    3,
0043     .offset_max =   8,
0044     .nr_divisor =   4,
0045     .features = FE_WIDE | FE_DIFF | FE_EHP| FE_MUX | FE_EA,
0046 };
0047 
0048 
0049 
0050 #if 0
0051 /* FIXME:
0052  * Is this function dead code? or is someone planning on using it in the
0053  * future.  The clock = (int) pdc_result[16] does not look correct to
0054  * me ... I think it should be iodc_data[16].  Since this cause a compile
0055  * error with the new encapsulated PDC, I'm not compiling in this function.
0056  * - RB
0057  */
0058 /* poke SCSI clock out of iodc data */
0059 
0060 static u8 iodc_data[32] __attribute__ ((aligned (64)));
0061 static unsigned long pdc_result[32] __attribute__ ((aligned (16))) ={0,0,0,0};
0062 
0063 static int 
0064 lasi_scsi_clock(void * hpa, int defaultclock)
0065 {
0066     int clock, status;
0067 
0068     status = pdc_iodc_read(&pdc_result, hpa, 0, &iodc_data, 32 );
0069     if (status == PDC_RET_OK) {
0070         clock = (int) pdc_result[16];
0071     } else {
0072         printk(KERN_WARNING "%s: pdc_iodc_read returned %d\n", __func__, status);
0073         clock = defaultclock; 
0074     }
0075 
0076     printk(KERN_DEBUG "%s: SCSI clock %d\n", __func__, clock);
0077     return clock;
0078 }
0079 #endif
0080 
0081 static struct scsi_host_template zalon7xx_template = {
0082     .module     = THIS_MODULE,
0083     .proc_name  = "zalon7xx",
0084     .cmd_size   = sizeof(struct ncr_cmd_priv),
0085 };
0086 
0087 static int __init
0088 zalon_probe(struct parisc_device *dev)
0089 {
0090     struct gsc_irq gsc_irq;
0091     u32 zalon_vers;
0092     int error = -ENODEV;
0093     void __iomem *zalon = ioremap(dev->hpa.start, 4096);
0094     void __iomem *io_port = zalon + GSC_SCSI_ZALON_OFFSET;
0095     static int unit = 0;
0096     struct Scsi_Host *host;
0097     struct ncr_device device;
0098 
0099     __raw_writel(CMD_RESET, zalon + IO_MODULE_IO_COMMAND);
0100     while (!(__raw_readl(zalon + IO_MODULE_IO_STATUS) & IOSTATUS_RY))
0101         cpu_relax();
0102     __raw_writel(IOIIDATA_MINT5EN | IOIIDATA_PACKEN | IOIIDATA_PREFETCHEN,
0103         zalon + IO_MODULE_II_CDATA);
0104 
0105     /* XXX: Save the Zalon version for bug workarounds? */
0106     zalon_vers = (__raw_readl(zalon + IO_MODULE_II_CDATA) >> 24) & 0x07;
0107 
0108     /* Setup the interrupts first.
0109     ** Later on request_irq() will register the handler.
0110     */
0111     dev->irq = gsc_alloc_irq(&gsc_irq);
0112 
0113     printk(KERN_INFO "%s: Zalon version %d, IRQ %d\n", __func__,
0114         zalon_vers, dev->irq);
0115 
0116     __raw_writel(gsc_irq.txn_addr | gsc_irq.txn_data, zalon + IO_MODULE_EIM);
0117 
0118     if (zalon_vers == 0)
0119         printk(KERN_WARNING "%s: Zalon 1.1 or earlier\n", __func__);
0120 
0121     memset(&device, 0, sizeof(struct ncr_device));
0122 
0123     /* The following three are needed before any other access. */
0124     __raw_writeb(0x20, io_port + 0x38); /* DCNTL_REG,  EA  */
0125     __raw_writeb(0x04, io_port + 0x1b); /* CTEST0_REG, EHP */
0126     __raw_writeb(0x80, io_port + 0x22); /* CTEST4_REG, MUX */
0127 
0128     /* Initialise ncr_device structure with items required by ncr_attach. */
0129     device.chip     = zalon720_chip;
0130     device.host_id      = 7;
0131     device.dev      = &dev->dev;
0132     device.slot.base    = dev->hpa.start + GSC_SCSI_ZALON_OFFSET;
0133     device.slot.base_v  = io_port;
0134     device.slot.irq     = dev->irq;
0135     device.differential = 2;
0136 
0137     host = ncr_attach(&zalon7xx_template, unit, &device);
0138     if (!host)
0139         return -ENODEV;
0140 
0141     if (request_irq(dev->irq, ncr53c8xx_intr, IRQF_SHARED, "zalon", host)) {
0142       dev_printk(KERN_ERR, &dev->dev, "irq problem with %d, detaching\n ",
0143              dev->irq);
0144         goto fail;
0145     }
0146 
0147     unit++;
0148 
0149     dev_set_drvdata(&dev->dev, host);
0150 
0151     error = scsi_add_host(host, &dev->dev);
0152     if (error)
0153         goto fail_free_irq;
0154 
0155     scsi_scan_host(host);
0156     return 0;
0157 
0158  fail_free_irq:
0159     free_irq(dev->irq, host);
0160  fail:
0161     ncr53c8xx_release(host);
0162     return error;
0163 }
0164 
0165 static const struct parisc_device_id zalon_tbl[] __initconst = {
0166     { HPHW_A_DMA, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x00089 }, 
0167     { 0, }
0168 };
0169 
0170 MODULE_DEVICE_TABLE(parisc, zalon_tbl);
0171 
0172 static void __exit zalon_remove(struct parisc_device *dev)
0173 {
0174     struct Scsi_Host *host = dev_get_drvdata(&dev->dev);
0175 
0176     scsi_remove_host(host);
0177     ncr53c8xx_release(host);
0178     free_irq(dev->irq, host);
0179 }
0180 
0181 static struct parisc_driver zalon_driver __refdata = {
0182     .name =     "zalon",
0183     .id_table = zalon_tbl,
0184     .probe =    zalon_probe,
0185     .remove =   __exit_p(zalon_remove),
0186 };
0187 
0188 static int __init zalon7xx_init(void)
0189 {
0190     int ret = ncr53c8xx_init();
0191     if (!ret)
0192         ret = register_parisc_driver(&zalon_driver);
0193     if (ret)
0194         ncr53c8xx_exit();
0195     return ret;
0196 }
0197 
0198 static void __exit zalon7xx_exit(void)
0199 {
0200     unregister_parisc_driver(&zalon_driver);
0201     ncr53c8xx_exit();
0202 }
0203 
0204 module_init(zalon7xx_init);
0205 module_exit(zalon7xx_exit);