Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /* jazz_esp.c: ESP front-end for MIPS JAZZ systems.
0003  *
0004  * Copyright (C) 2007 Thomas Bogendörfer (tsbogend@alpha.frankende)
0005  */
0006 
0007 #include <linux/kernel.h>
0008 #include <linux/gfp.h>
0009 #include <linux/types.h>
0010 #include <linux/module.h>
0011 #include <linux/init.h>
0012 #include <linux/interrupt.h>
0013 #include <linux/platform_device.h>
0014 #include <linux/dma-mapping.h>
0015 
0016 #include <asm/irq.h>
0017 #include <asm/io.h>
0018 #include <asm/dma.h>
0019 
0020 #include <asm/jazz.h>
0021 #include <asm/jazzdma.h>
0022 
0023 #include <scsi/scsi_host.h>
0024 
0025 #include "esp_scsi.h"
0026 
0027 #define DRV_MODULE_NAME     "jazz_esp"
0028 #define PFX DRV_MODULE_NAME ": "
0029 #define DRV_VERSION     "1.000"
0030 #define DRV_MODULE_RELDATE  "May 19, 2007"
0031 
0032 static void jazz_esp_write8(struct esp *esp, u8 val, unsigned long reg)
0033 {
0034     *(volatile u8 *)(esp->regs + reg) = val;
0035 }
0036 
0037 static u8 jazz_esp_read8(struct esp *esp, unsigned long reg)
0038 {
0039     return *(volatile u8 *)(esp->regs + reg);
0040 }
0041 
0042 static int jazz_esp_irq_pending(struct esp *esp)
0043 {
0044     if (jazz_esp_read8(esp, ESP_STATUS) & ESP_STAT_INTR)
0045         return 1;
0046     return 0;
0047 }
0048 
0049 static void jazz_esp_reset_dma(struct esp *esp)
0050 {
0051     vdma_disable ((int)esp->dma_regs);
0052 }
0053 
0054 static void jazz_esp_dma_drain(struct esp *esp)
0055 {
0056     /* nothing to do */
0057 }
0058 
0059 static void jazz_esp_dma_invalidate(struct esp *esp)
0060 {
0061     vdma_disable ((int)esp->dma_regs);
0062 }
0063 
0064 static void jazz_esp_send_dma_cmd(struct esp *esp, u32 addr, u32 esp_count,
0065                   u32 dma_count, int write, u8 cmd)
0066 {
0067     BUG_ON(!(cmd & ESP_CMD_DMA));
0068 
0069     jazz_esp_write8(esp, (esp_count >> 0) & 0xff, ESP_TCLOW);
0070     jazz_esp_write8(esp, (esp_count >> 8) & 0xff, ESP_TCMED);
0071     vdma_disable ((int)esp->dma_regs);
0072     if (write)
0073         vdma_set_mode ((int)esp->dma_regs, DMA_MODE_READ);
0074     else
0075         vdma_set_mode ((int)esp->dma_regs, DMA_MODE_WRITE);
0076 
0077     vdma_set_addr ((int)esp->dma_regs, addr);
0078     vdma_set_count ((int)esp->dma_regs, dma_count);
0079     vdma_enable ((int)esp->dma_regs);
0080 
0081     scsi_esp_cmd(esp, cmd);
0082 }
0083 
0084 static int jazz_esp_dma_error(struct esp *esp)
0085 {
0086     u32 enable = vdma_get_enable((int)esp->dma_regs);
0087 
0088     if (enable & (R4030_MEM_INTR|R4030_ADDR_INTR))
0089         return 1;
0090 
0091     return 0;
0092 }
0093 
0094 static const struct esp_driver_ops jazz_esp_ops = {
0095     .esp_write8 =   jazz_esp_write8,
0096     .esp_read8  =   jazz_esp_read8,
0097     .irq_pending    =   jazz_esp_irq_pending,
0098     .reset_dma  =   jazz_esp_reset_dma,
0099     .dma_drain  =   jazz_esp_dma_drain,
0100     .dma_invalidate =   jazz_esp_dma_invalidate,
0101     .send_dma_cmd   =   jazz_esp_send_dma_cmd,
0102     .dma_error  =   jazz_esp_dma_error,
0103 };
0104 
0105 static int esp_jazz_probe(struct platform_device *dev)
0106 {
0107     struct scsi_host_template *tpnt = &scsi_esp_template;
0108     struct Scsi_Host *host;
0109     struct esp *esp;
0110     struct resource *res;
0111     int err;
0112 
0113     host = scsi_host_alloc(tpnt, sizeof(struct esp));
0114 
0115     err = -ENOMEM;
0116     if (!host)
0117         goto fail;
0118 
0119     host->max_id = 8;
0120     esp = shost_priv(host);
0121 
0122     esp->host = host;
0123     esp->dev = &dev->dev;
0124     esp->ops = &jazz_esp_ops;
0125 
0126     res = platform_get_resource(dev, IORESOURCE_MEM, 0);
0127     if (!res)
0128         goto fail_unlink;
0129 
0130     esp->regs = (void __iomem *)res->start;
0131     if (!esp->regs)
0132         goto fail_unlink;
0133 
0134     res = platform_get_resource(dev, IORESOURCE_MEM, 1);
0135     if (!res)
0136         goto fail_unlink;
0137 
0138     esp->dma_regs = (void __iomem *)res->start;
0139 
0140     esp->command_block = dma_alloc_coherent(esp->dev, 16,
0141                         &esp->command_block_dma,
0142                         GFP_KERNEL);
0143     if (!esp->command_block)
0144         goto fail_unmap_regs;
0145 
0146     host->irq = err = platform_get_irq(dev, 0);
0147     if (err < 0)
0148         goto fail_unmap_command_block;
0149     err = request_irq(host->irq, scsi_esp_intr, IRQF_SHARED, "ESP", esp);
0150     if (err < 0)
0151         goto fail_unmap_command_block;
0152 
0153     esp->scsi_id = 7;
0154     esp->host->this_id = esp->scsi_id;
0155     esp->scsi_id_mask = (1 << esp->scsi_id);
0156     esp->cfreq = 40000000;
0157 
0158     dev_set_drvdata(&dev->dev, esp);
0159 
0160     err = scsi_esp_register(esp);
0161     if (err)
0162         goto fail_free_irq;
0163 
0164     return 0;
0165 
0166 fail_free_irq:
0167     free_irq(host->irq, esp);
0168 fail_unmap_command_block:
0169     dma_free_coherent(esp->dev, 16,
0170               esp->command_block,
0171               esp->command_block_dma);
0172 fail_unmap_regs:
0173 fail_unlink:
0174     scsi_host_put(host);
0175 fail:
0176     return err;
0177 }
0178 
0179 static int esp_jazz_remove(struct platform_device *dev)
0180 {
0181     struct esp *esp = dev_get_drvdata(&dev->dev);
0182     unsigned int irq = esp->host->irq;
0183 
0184     scsi_esp_unregister(esp);
0185 
0186     free_irq(irq, esp);
0187     dma_free_coherent(esp->dev, 16,
0188               esp->command_block,
0189               esp->command_block_dma);
0190 
0191     scsi_host_put(esp->host);
0192 
0193     return 0;
0194 }
0195 
0196 /* work with hotplug and coldplug */
0197 MODULE_ALIAS("platform:jazz_esp");
0198 
0199 static struct platform_driver esp_jazz_driver = {
0200     .probe      = esp_jazz_probe,
0201     .remove     = esp_jazz_remove,
0202     .driver = {
0203         .name   = "jazz_esp",
0204     },
0205 };
0206 module_platform_driver(esp_jazz_driver);
0207 
0208 MODULE_DESCRIPTION("JAZZ ESP SCSI driver");
0209 MODULE_AUTHOR("Thomas Bogendoerfer (tsbogend@alpha.franken.de)");
0210 MODULE_LICENSE("GPL");
0211 MODULE_VERSION(DRV_VERSION);