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 32a24a6b22SGeert Uytterhoeven #define A4000T_SCSI_OFFSET 0x40 33a16efc1cSKars de Jong 34a24a6b22SGeert Uytterhoeven static int __init amiga_a4000t_scsi_probe(struct platform_device *pdev) 35a16efc1cSKars de Jong { 36a24a6b22SGeert Uytterhoeven struct resource *res; 37a24a6b22SGeert Uytterhoeven phys_addr_t scsi_addr; 38a16efc1cSKars de Jong struct NCR_700_Host_Parameters *hostdata; 39a24a6b22SGeert Uytterhoeven struct Scsi_Host *host; 40a16efc1cSKars de Jong 41a24a6b22SGeert Uytterhoeven res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 42a24a6b22SGeert Uytterhoeven if (!res) 43a24a6b22SGeert Uytterhoeven return -ENODEV; 44a16efc1cSKars de Jong 45a24a6b22SGeert Uytterhoeven if (!request_mem_region(res->start, resource_size(res), 46a16efc1cSKars de Jong "A4000T builtin SCSI")) 47a24a6b22SGeert Uytterhoeven return -EBUSY; 48a16efc1cSKars de Jong 49a24a6b22SGeert Uytterhoeven hostdata = kzalloc(sizeof(struct NCR_700_Host_Parameters), 50a24a6b22SGeert Uytterhoeven GFP_KERNEL); 51bbfbbbc1SMariusz Kozlowski if (!hostdata) { 52a24a6b22SGeert Uytterhoeven dev_err(&pdev->dev, "Failed to allocate host data\n"); 53a16efc1cSKars de Jong goto out_release; 54a16efc1cSKars de Jong } 55a16efc1cSKars de Jong 56a24a6b22SGeert Uytterhoeven scsi_addr = res->start + A4000T_SCSI_OFFSET; 57a24a6b22SGeert Uytterhoeven 58a16efc1cSKars de Jong /* Fill in the required pieces of hostdata */ 59*6112ea08SGeert Uytterhoeven hostdata->base = 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, 67a24a6b22SGeert Uytterhoeven &pdev->dev); 68a16efc1cSKars de Jong if (!host) { 69a24a6b22SGeert Uytterhoeven dev_err(&pdev->dev, 70a24a6b22SGeert 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; 75a24a6b22SGeert 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)) { 80a24a6b22SGeert Uytterhoeven dev_err(&pdev->dev, "request_irq failed\n"); 81a16efc1cSKars de Jong goto out_put_host; 82a16efc1cSKars de Jong } 83a16efc1cSKars de Jong 84a24a6b22SGeert 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: 93a24a6b22SGeert Uytterhoeven release_mem_region(res->start, resource_size(res)); 94a16efc1cSKars de Jong return -ENODEV; 95a16efc1cSKars de Jong } 96a16efc1cSKars de Jong 97a24a6b22SGeert Uytterhoeven static int __exit amiga_a4000t_scsi_remove(struct platform_device *pdev) 98a16efc1cSKars de Jong { 99a24a6b22SGeert Uytterhoeven struct Scsi_Host *host = platform_get_drvdata(pdev); 100a16efc1cSKars de Jong struct NCR_700_Host_Parameters *hostdata = shost_priv(host); 101a24a6b22SGeert 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); 107a24a6b22SGeert Uytterhoeven release_mem_region(res->start, resource_size(res)); 108a16efc1cSKars de Jong return 0; 109a16efc1cSKars de Jong } 110a16efc1cSKars de Jong 111a24a6b22SGeert Uytterhoeven static struct platform_driver amiga_a4000t_scsi_driver = { 112a24a6b22SGeert Uytterhoeven .remove = __exit_p(amiga_a4000t_scsi_remove), 1137a192ec3SMing Lei .driver = { 114a24a6b22SGeert Uytterhoeven .name = "amiga-a4000t-scsi", 1157a192ec3SMing Lei .owner = THIS_MODULE, 1167a192ec3SMing Lei }, 117a16efc1cSKars de Jong }; 118a16efc1cSKars de Jong 11970695baaSJingoo Han module_platform_driver_probe(amiga_a4000t_scsi_driver, amiga_a4000t_scsi_probe); 120a24a6b22SGeert Uytterhoeven 121a24a6b22SGeert Uytterhoeven MODULE_AUTHOR("Alan Hourihane <alanh@fairlite.demon.co.uk> / " 122a24a6b22SGeert Uytterhoeven "Kars de Jong <jongk@linux-m68k.org>"); 123a24a6b22SGeert Uytterhoeven MODULE_DESCRIPTION("Amiga A4000T NCR53C710 driver"); 124a24a6b22SGeert Uytterhoeven MODULE_LICENSE("GPL"); 125a24a6b22SGeert Uytterhoeven MODULE_ALIAS("platform:amiga-a4000t-scsi"); 126