1a16efc1cSKars de Jong /* 2a16efc1cSKars de Jong * Detection routine for the NCR53c710 based Amiga SCSI Controllers for Linux. 3a16efc1cSKars de Jong * Amiga Technologies A4000T SCSI controller. 4a16efc1cSKars de Jong * 5a16efc1cSKars de Jong * Written 1997 by Alan Hourihane <alanh@fairlite.demon.co.uk> 6a16efc1cSKars de Jong * plus modifications of the 53c7xx.c driver to support the Amiga. 7a16efc1cSKars de Jong * 8a16efc1cSKars de Jong * Rewritten to use 53c700.c by Kars de Jong <jongk@linux-m68k.org> 9a16efc1cSKars de Jong */ 10a16efc1cSKars de Jong 11a16efc1cSKars de Jong #include <linux/module.h> 12a16efc1cSKars de Jong #include <linux/platform_device.h> 13a16efc1cSKars de Jong #include <linux/init.h> 14a16efc1cSKars de Jong #include <linux/interrupt.h> 155a0e3ad6STejun Heo #include <linux/slab.h> 1696249cf9SGeert Uytterhoeven #include <asm/amigahw.h> 17a16efc1cSKars de Jong #include <asm/amigaints.h> 18a16efc1cSKars de Jong #include <scsi/scsi_host.h> 19a16efc1cSKars de Jong #include <scsi/scsi_transport_spi.h> 20a16efc1cSKars de Jong 21a16efc1cSKars de Jong #include "53c700.h" 22a16efc1cSKars de Jong 23a16efc1cSKars de Jong 24a16efc1cSKars de Jong static struct scsi_host_template a4000t_scsi_driver_template = { 25a16efc1cSKars de Jong .name = "A4000T builtin SCSI", 26a16efc1cSKars de Jong .proc_name = "A4000t", 27a16efc1cSKars de Jong .this_id = 7, 28a16efc1cSKars de Jong .module = THIS_MODULE, 29a16efc1cSKars de Jong }; 30a16efc1cSKars de Jong 31a16efc1cSKars de Jong 32*a24a6b22SGeert Uytterhoeven #define A4000T_SCSI_OFFSET 0x40 33a16efc1cSKars de Jong 34*a24a6b22SGeert Uytterhoeven static int __init amiga_a4000t_scsi_probe(struct platform_device *pdev) 35a16efc1cSKars de Jong { 36*a24a6b22SGeert Uytterhoeven struct resource *res; 37*a24a6b22SGeert Uytterhoeven phys_addr_t scsi_addr; 38a16efc1cSKars de Jong struct NCR_700_Host_Parameters *hostdata; 39*a24a6b22SGeert Uytterhoeven struct Scsi_Host *host; 40a16efc1cSKars de Jong 41*a24a6b22SGeert Uytterhoeven res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 42*a24a6b22SGeert Uytterhoeven if (!res) 43*a24a6b22SGeert Uytterhoeven return -ENODEV; 44a16efc1cSKars de Jong 45*a24a6b22SGeert Uytterhoeven if (!request_mem_region(res->start, resource_size(res), 46a16efc1cSKars de Jong "A4000T builtin SCSI")) 47*a24a6b22SGeert Uytterhoeven return -EBUSY; 48a16efc1cSKars de Jong 49*a24a6b22SGeert Uytterhoeven hostdata = kzalloc(sizeof(struct NCR_700_Host_Parameters), 50*a24a6b22SGeert Uytterhoeven GFP_KERNEL); 51bbfbbbc1SMariusz Kozlowski if (!hostdata) { 52*a24a6b22SGeert Uytterhoeven dev_err(&pdev->dev, "Failed to allocate host data\n"); 53a16efc1cSKars de Jong goto out_release; 54a16efc1cSKars de Jong } 55a16efc1cSKars de Jong 56*a24a6b22SGeert Uytterhoeven scsi_addr = res->start + A4000T_SCSI_OFFSET; 57*a24a6b22SGeert Uytterhoeven 58a16efc1cSKars de Jong /* Fill in the required pieces of hostdata */ 59*a24a6b22SGeert Uytterhoeven hostdata->base = (void __iomem *)ZTWO_VADDR(scsi_addr); 60a16efc1cSKars de Jong hostdata->clock = 50; 61a16efc1cSKars de Jong hostdata->chip710 = 1; 62a16efc1cSKars de Jong hostdata->dmode_extra = DMODE_FC2; 63a16efc1cSKars de Jong hostdata->dcntl_extra = EA_710; 64a16efc1cSKars de Jong 65a16efc1cSKars de Jong /* and register the chip */ 66e5779a58SGeert Uytterhoeven host = NCR_700_detect(&a4000t_scsi_driver_template, hostdata, 67*a24a6b22SGeert Uytterhoeven &pdev->dev); 68a16efc1cSKars de Jong if (!host) { 69*a24a6b22SGeert Uytterhoeven dev_err(&pdev->dev, 70*a24a6b22SGeert Uytterhoeven "No host detected; board configuration problem?\n"); 71a16efc1cSKars de Jong goto out_free; 72a16efc1cSKars de Jong } 73a16efc1cSKars de Jong 74a16efc1cSKars de Jong host->this_id = 7; 75*a24a6b22SGeert Uytterhoeven host->base = scsi_addr; 76a16efc1cSKars de Jong host->irq = IRQ_AMIGA_PORTS; 77a16efc1cSKars de Jong 78a16efc1cSKars de Jong if (request_irq(host->irq, NCR_700_intr, IRQF_SHARED, "a4000t-scsi", 79a16efc1cSKars de Jong host)) { 80*a24a6b22SGeert Uytterhoeven dev_err(&pdev->dev, "request_irq failed\n"); 81a16efc1cSKars de Jong goto out_put_host; 82a16efc1cSKars de Jong } 83a16efc1cSKars de Jong 84*a24a6b22SGeert Uytterhoeven platform_set_drvdata(pdev, host); 85a16efc1cSKars de Jong scsi_scan_host(host); 86a16efc1cSKars de Jong return 0; 87a16efc1cSKars de Jong 88a16efc1cSKars de Jong out_put_host: 89a16efc1cSKars de Jong scsi_host_put(host); 90a16efc1cSKars de Jong out_free: 91a16efc1cSKars de Jong kfree(hostdata); 92a16efc1cSKars de Jong out_release: 93*a24a6b22SGeert Uytterhoeven release_mem_region(res->start, resource_size(res)); 94a16efc1cSKars de Jong return -ENODEV; 95a16efc1cSKars de Jong } 96a16efc1cSKars de Jong 97*a24a6b22SGeert Uytterhoeven static int __exit amiga_a4000t_scsi_remove(struct platform_device *pdev) 98a16efc1cSKars de Jong { 99*a24a6b22SGeert Uytterhoeven struct Scsi_Host *host = platform_get_drvdata(pdev); 100a16efc1cSKars de Jong struct NCR_700_Host_Parameters *hostdata = shost_priv(host); 101*a24a6b22SGeert Uytterhoeven struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 102a16efc1cSKars de Jong 103a16efc1cSKars de Jong scsi_remove_host(host); 104a16efc1cSKars de Jong NCR_700_release(host); 105a16efc1cSKars de Jong kfree(hostdata); 106a16efc1cSKars de Jong free_irq(host->irq, host); 107*a24a6b22SGeert Uytterhoeven release_mem_region(res->start, resource_size(res)); 108a16efc1cSKars de Jong return 0; 109a16efc1cSKars de Jong } 110a16efc1cSKars de Jong 111*a24a6b22SGeert Uytterhoeven static struct platform_driver amiga_a4000t_scsi_driver = { 112*a24a6b22SGeert Uytterhoeven .remove = __exit_p(amiga_a4000t_scsi_remove), 1137a192ec3SMing Lei .driver = { 114*a24a6b22SGeert Uytterhoeven .name = "amiga-a4000t-scsi", 1157a192ec3SMing Lei .owner = THIS_MODULE, 1167a192ec3SMing Lei }, 117a16efc1cSKars de Jong }; 118a16efc1cSKars de Jong 119*a24a6b22SGeert Uytterhoeven static int __init amiga_a4000t_scsi_init(void) 120a16efc1cSKars de Jong { 121*a24a6b22SGeert Uytterhoeven return platform_driver_probe(&amiga_a4000t_scsi_driver, 122*a24a6b22SGeert Uytterhoeven amiga_a4000t_scsi_probe); 123a16efc1cSKars de Jong } 124a16efc1cSKars de Jong 125*a24a6b22SGeert Uytterhoeven module_init(amiga_a4000t_scsi_init); 126a16efc1cSKars de Jong 127*a24a6b22SGeert Uytterhoeven static void __exit amiga_a4000t_scsi_exit(void) 128a16efc1cSKars de Jong { 129*a24a6b22SGeert Uytterhoeven platform_driver_unregister(&amiga_a4000t_scsi_driver); 130a16efc1cSKars de Jong } 131a16efc1cSKars de Jong 132*a24a6b22SGeert Uytterhoeven module_exit(amiga_a4000t_scsi_exit); 133*a24a6b22SGeert Uytterhoeven 134*a24a6b22SGeert Uytterhoeven MODULE_AUTHOR("Alan Hourihane <alanh@fairlite.demon.co.uk> / " 135*a24a6b22SGeert Uytterhoeven "Kars de Jong <jongk@linux-m68k.org>"); 136*a24a6b22SGeert Uytterhoeven MODULE_DESCRIPTION("Amiga A4000T NCR53C710 driver"); 137*a24a6b22SGeert Uytterhoeven MODULE_LICENSE("GPL"); 138*a24a6b22SGeert Uytterhoeven MODULE_ALIAS("platform:amiga-a4000t-scsi"); 139