Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * Detection routine for the NCR53c710 based Amiga SCSI Controllers for Linux.
0004  *      Amiga MacroSystemUS WarpEngine SCSI controller.
0005  *      Amiga Technologies/DKB A4091 SCSI controller.
0006  *
0007  * Written 1997 by Alan Hourihane <alanh@fairlite.demon.co.uk>
0008  * plus modifications of the 53c7xx.c driver to support the Amiga.
0009  *
0010  * Rewritten to use 53c700.c by Kars de Jong <jongk@linux-m68k.org>
0011  */
0012 
0013 #include <linux/module.h>
0014 #include <linux/init.h>
0015 #include <linux/interrupt.h>
0016 #include <linux/zorro.h>
0017 #include <linux/slab.h>
0018 
0019 #include <asm/amigahw.h>
0020 #include <asm/amigaints.h>
0021 
0022 #include <scsi/scsi_host.h>
0023 #include <scsi/scsi_transport_spi.h>
0024 
0025 #include "53c700.h"
0026 
0027 MODULE_AUTHOR("Alan Hourihane <alanh@fairlite.demon.co.uk> / Kars de Jong <jongk@linux-m68k.org>");
0028 MODULE_DESCRIPTION("Amiga Zorro NCR53C710 driver");
0029 MODULE_LICENSE("GPL");
0030 
0031 
0032 static struct scsi_host_template zorro7xx_scsi_driver_template = {
0033     .proc_name  = "zorro7xx",
0034     .this_id    = 7,
0035     .module     = THIS_MODULE,
0036 };
0037 
0038 static struct zorro_driver_data {
0039     const char *name;
0040     unsigned long offset;
0041     int absolute;   /* offset is absolute address */
0042 } zorro7xx_driver_data[] = {
0043     { .name = "PowerUP 603e+", .offset = 0xf40000, .absolute = 1 },
0044     { .name = "WarpEngine 40xx", .offset = 0x40000 },
0045     { .name = "A4091", .offset = 0x800000 },
0046     { .name = "GForce 040/060", .offset = 0x40000 },
0047     { 0 }
0048 };
0049 
0050 static struct zorro_device_id zorro7xx_zorro_tbl[] = {
0051     {
0052         .id = ZORRO_PROD_PHASE5_BLIZZARD_603E_PLUS,
0053         .driver_data = (unsigned long)&zorro7xx_driver_data[0],
0054     },
0055     {
0056         .id = ZORRO_PROD_MACROSYSTEMS_WARP_ENGINE_40xx,
0057         .driver_data = (unsigned long)&zorro7xx_driver_data[1],
0058     },
0059     {
0060         .id = ZORRO_PROD_CBM_A4091_1,
0061         .driver_data = (unsigned long)&zorro7xx_driver_data[2],
0062     },
0063     {
0064         .id = ZORRO_PROD_CBM_A4091_2,
0065         .driver_data = (unsigned long)&zorro7xx_driver_data[2],
0066     },
0067     {
0068         .id = ZORRO_PROD_GVP_GFORCE_040_060,
0069         .driver_data = (unsigned long)&zorro7xx_driver_data[3],
0070     },
0071     { 0 }
0072 };
0073 MODULE_DEVICE_TABLE(zorro, zorro7xx_zorro_tbl);
0074 
0075 static int zorro7xx_init_one(struct zorro_dev *z,
0076                  const struct zorro_device_id *ent)
0077 {
0078     struct Scsi_Host *host;
0079     struct NCR_700_Host_Parameters *hostdata;
0080     struct zorro_driver_data *zdd;
0081     unsigned long board, ioaddr;
0082 
0083     board = zorro_resource_start(z);
0084     zdd = (struct zorro_driver_data *)ent->driver_data;
0085 
0086     if (zdd->absolute) {
0087         ioaddr = zdd->offset;
0088     } else {
0089         ioaddr = board + zdd->offset;
0090     }
0091 
0092     if (!zorro_request_device(z, zdd->name)) {
0093         printk(KERN_ERR "zorro7xx: cannot reserve region 0x%lx, abort\n",
0094                board);
0095         return -EBUSY;
0096     }
0097 
0098     hostdata = kzalloc(sizeof(struct NCR_700_Host_Parameters), GFP_KERNEL);
0099     if (!hostdata) {
0100         printk(KERN_ERR "zorro7xx: Failed to allocate host data\n");
0101         goto out_release;
0102     }
0103 
0104     /* Fill in the required pieces of hostdata */
0105     if (ioaddr > 0x01000000)
0106         hostdata->base = ioremap(ioaddr, zorro_resource_len(z));
0107     else
0108         hostdata->base = ZTWO_VADDR(ioaddr);
0109 
0110     hostdata->clock = 50;
0111     hostdata->chip710 = 1;
0112 
0113     /* Settings for at least WarpEngine 40xx */
0114     hostdata->ctest7_extra = CTEST7_TT1;
0115 
0116     zorro7xx_scsi_driver_template.name = zdd->name;
0117 
0118     /* and register the chip */
0119     host = NCR_700_detect(&zorro7xx_scsi_driver_template, hostdata,
0120                   &z->dev);
0121     if (!host) {
0122         printk(KERN_ERR "zorro7xx: No host detected; "
0123                 "board configuration problem?\n");
0124         goto out_free;
0125     }
0126 
0127     host->this_id = 7;
0128     host->base = ioaddr;
0129     host->irq = IRQ_AMIGA_PORTS;
0130 
0131     if (request_irq(host->irq, NCR_700_intr, IRQF_SHARED, "zorro7xx-scsi",
0132             host)) {
0133         printk(KERN_ERR "zorro7xx: request_irq failed\n");
0134         goto out_put_host;
0135     }
0136 
0137     zorro_set_drvdata(z, host);
0138     scsi_scan_host(host);
0139 
0140     return 0;
0141 
0142  out_put_host:
0143     scsi_host_put(host);
0144  out_free:
0145     if (ioaddr > 0x01000000)
0146         iounmap(hostdata->base);
0147     kfree(hostdata);
0148  out_release:
0149     zorro_release_device(z);
0150 
0151     return -ENODEV;
0152 }
0153 
0154 static void zorro7xx_remove_one(struct zorro_dev *z)
0155 {
0156     struct Scsi_Host *host = zorro_get_drvdata(z);
0157     struct NCR_700_Host_Parameters *hostdata = shost_priv(host);
0158 
0159     scsi_remove_host(host);
0160 
0161     NCR_700_release(host);
0162     if (host->base > 0x01000000)
0163         iounmap(hostdata->base);
0164     kfree(hostdata);
0165     free_irq(host->irq, host);
0166     zorro_release_device(z);
0167 }
0168 
0169 static struct zorro_driver zorro7xx_driver = {
0170     .name     = "zorro7xx-scsi",
0171     .id_table = zorro7xx_zorro_tbl,
0172     .probe    = zorro7xx_init_one,
0173     .remove   = zorro7xx_remove_one,
0174 };
0175 
0176 static int __init zorro7xx_scsi_init(void)
0177 {
0178     return zorro_register_driver(&zorro7xx_driver);
0179 }
0180 
0181 static void __exit zorro7xx_scsi_exit(void)
0182 {
0183     zorro_unregister_driver(&zorro7xx_driver);
0184 }
0185 
0186 module_init(zorro7xx_scsi_init);
0187 module_exit(zorro7xx_scsi_exit);