blob: e6b2b681fda3164b27f0116bfc119ac9d1f3481b [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Linus Torvalds1da177e2005-04-16 15:20:36 -07002#include <linux/types.h>
3#include <linux/mm.h>
4#include <linux/blkdev.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07005#include <linux/interrupt.h>
6
7#include <asm/page.h>
8#include <asm/pgtable.h>
9#include <asm/mvme147hw.h>
10#include <asm/irq.h>
11
12#include "scsi.h"
13#include <scsi/scsi_host.h>
14#include "wd33c93.h"
15#include "mvme147.h"
16
Geert Uytterhoevenbe4540d2010-04-04 11:00:34 +020017#include <linux/stat.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
Geert Uytterhoevenbe4540d2010-04-04 11:00:34 +020019
Geert Uytterhoeven4616ac72009-05-17 13:35:13 +020020static irqreturn_t mvme147_intr(int irq, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -070021{
Geert Uytterhoeven4616ac72009-05-17 13:35:13 +020022 struct Scsi_Host *instance = data;
23
Geert Uytterhoevenbe4540d2010-04-04 11:00:34 +020024 if (irq == MVME147_IRQ_SCSI_PORT)
Geert Uytterhoeven4616ac72009-05-17 13:35:13 +020025 wd33c93_intr(instance);
Geert Uytterhoevenbe4540d2010-04-04 11:00:34 +020026 else
27 m147_pcc->dma_intr = 0x89; /* Ack and enable ints */
28 return IRQ_HANDLED;
Linus Torvalds1da177e2005-04-16 15:20:36 -070029}
30
Henrik Kretzschmar65396412006-09-12 23:49:33 +020031static int dma_setup(struct scsi_cmnd *cmd, int dir_in)
Linus Torvalds1da177e2005-04-16 15:20:36 -070032{
Geert Uytterhoeven4616ac72009-05-17 13:35:13 +020033 struct Scsi_Host *instance = cmd->device->host;
34 struct WD33C93_hostdata *hdata = shost_priv(instance);
Geert Uytterhoevenbe4540d2010-04-04 11:00:34 +020035 unsigned char flags = 0x01;
36 unsigned long addr = virt_to_bus(cmd->SCp.ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Geert Uytterhoevenbe4540d2010-04-04 11:00:34 +020038 /* setup dma direction */
39 if (!dir_in)
40 flags |= 0x04;
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
Geert Uytterhoevenbe4540d2010-04-04 11:00:34 +020042 /* remember direction */
Geert Uytterhoevence195662010-04-04 11:00:38 +020043 hdata->dma_dir = dir_in;
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
Geert Uytterhoevenbe4540d2010-04-04 11:00:34 +020045 if (dir_in) {
46 /* invalidate any cache */
47 cache_clear(addr, cmd->SCp.this_residual);
48 } else {
49 /* push any dirty cache */
50 cache_push(addr, cmd->SCp.this_residual);
51 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
Geert Uytterhoevenbe4540d2010-04-04 11:00:34 +020053 /* start DMA */
54 m147_pcc->dma_bcr = cmd->SCp.this_residual | (1 << 24);
55 m147_pcc->dma_dadr = addr;
56 m147_pcc->dma_cntrl = flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
Geert Uytterhoevenbe4540d2010-04-04 11:00:34 +020058 /* return success */
59 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070060}
61
Henrik Kretzschmar65396412006-09-12 23:49:33 +020062static void dma_stop(struct Scsi_Host *instance, struct scsi_cmnd *SCpnt,
Geert Uytterhoevenbe4540d2010-04-04 11:00:34 +020063 int status)
Linus Torvalds1da177e2005-04-16 15:20:36 -070064{
Geert Uytterhoevenbe4540d2010-04-04 11:00:34 +020065 m147_pcc->dma_cntrl = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070066}
67
Christoph Hellwigd0be4a7d2005-10-31 18:31:40 +010068int mvme147_detect(struct scsi_host_template *tpnt)
Linus Torvalds1da177e2005-04-16 15:20:36 -070069{
Geert Uytterhoevenbe4540d2010-04-04 11:00:34 +020070 static unsigned char called = 0;
Geert Uytterhoeven4616ac72009-05-17 13:35:13 +020071 struct Scsi_Host *instance;
Geert Uytterhoevenbe4540d2010-04-04 11:00:34 +020072 wd33c93_regs regs;
Geert Uytterhoevence195662010-04-04 11:00:38 +020073 struct WD33C93_hostdata *hdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
Geert Uytterhoevenbe4540d2010-04-04 11:00:34 +020075 if (!MACH_IS_MVME147 || called)
76 return 0;
77 called++;
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
Geert Uytterhoevenbe4540d2010-04-04 11:00:34 +020079 tpnt->proc_name = "MVME147";
Al Viro408bb252013-03-31 00:30:35 -040080 tpnt->show_info = wd33c93_show_info,
81 tpnt->write_info = wd33c93_write_info,
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
Geert Uytterhoeven4616ac72009-05-17 13:35:13 +020083 instance = scsi_register(tpnt, sizeof(struct WD33C93_hostdata));
84 if (!instance)
Geert Uytterhoevenbe4540d2010-04-04 11:00:34 +020085 goto err_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
Geert Uytterhoeven4616ac72009-05-17 13:35:13 +020087 instance->base = 0xfffe4000;
88 instance->irq = MVME147_IRQ_SCSI_PORT;
Geert Uytterhoevenbe4540d2010-04-04 11:00:34 +020089 regs.SASR = (volatile unsigned char *)0xfffe4000;
90 regs.SCMD = (volatile unsigned char *)0xfffe4001;
Geert Uytterhoeven4616ac72009-05-17 13:35:13 +020091 hdata = shost_priv(instance);
Geert Uytterhoevence195662010-04-04 11:00:38 +020092 hdata->no_sync = 0xff;
93 hdata->fast = 0;
94 hdata->dma_mode = CTRL_DMA;
Geert Uytterhoeven4616ac72009-05-17 13:35:13 +020095 wd33c93_init(instance, regs, dma_setup, dma_stop, WD33C93_FS_8_10);
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
Geert Uytterhoevenbe4540d2010-04-04 11:00:34 +020097 if (request_irq(MVME147_IRQ_SCSI_PORT, mvme147_intr, 0,
Geert Uytterhoeven4616ac72009-05-17 13:35:13 +020098 "MVME147 SCSI PORT", instance))
Geert Uytterhoevenbe4540d2010-04-04 11:00:34 +020099 goto err_unregister;
100 if (request_irq(MVME147_IRQ_SCSI_DMA, mvme147_intr, 0,
Geert Uytterhoeven4616ac72009-05-17 13:35:13 +0200101 "MVME147 SCSI DMA", instance))
Geert Uytterhoevenbe4540d2010-04-04 11:00:34 +0200102 goto err_free_irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103#if 0 /* Disabled; causes problems booting */
Geert Uytterhoevenbe4540d2010-04-04 11:00:34 +0200104 m147_pcc->scsi_interrupt = 0x10; /* Assert SCSI bus reset */
105 udelay(100);
106 m147_pcc->scsi_interrupt = 0x00; /* Negate SCSI bus reset */
107 udelay(2000);
108 m147_pcc->scsi_interrupt = 0x40; /* Clear bus reset interrupt */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109#endif
Geert Uytterhoevenbe4540d2010-04-04 11:00:34 +0200110 m147_pcc->scsi_interrupt = 0x09; /* Enable interrupt */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111
Geert Uytterhoevenbe4540d2010-04-04 11:00:34 +0200112 m147_pcc->dma_cntrl = 0x00; /* ensure DMA is stopped */
113 m147_pcc->dma_intr = 0x89; /* Ack and enable ints */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
Geert Uytterhoevenbe4540d2010-04-04 11:00:34 +0200115 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
Geert Uytterhoevenbe4540d2010-04-04 11:00:34 +0200117err_free_irq:
118 free_irq(MVME147_IRQ_SCSI_PORT, mvme147_intr);
119err_unregister:
Geert Uytterhoeven4616ac72009-05-17 13:35:13 +0200120 scsi_unregister(instance);
Geert Uytterhoevenbe4540d2010-04-04 11:00:34 +0200121err_out:
122 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123}
124
Christoph Hellwigd0be4a7d2005-10-31 18:31:40 +0100125static struct scsi_host_template driver_template = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 .proc_name = "MVME147",
127 .name = "MVME147 built-in SCSI",
128 .detect = mvme147_detect,
129 .release = mvme147_release,
130 .queuecommand = wd33c93_queuecommand,
131 .eh_abort_handler = wd33c93_abort,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 .eh_host_reset_handler = wd33c93_host_reset,
133 .can_queue = CAN_QUEUE,
134 .this_id = 7,
135 .sg_tablesize = SG_ALL,
136 .cmd_per_lun = CMD_PER_LUN,
137 .use_clustering = ENABLE_CLUSTERING
138};
139
140
141#include "scsi_module.c"
142
143int mvme147_release(struct Scsi_Host *instance)
144{
145#ifdef MODULE
Geert Uytterhoevenbe4540d2010-04-04 11:00:34 +0200146 /* XXX Make sure DMA is stopped! */
147 free_irq(MVME147_IRQ_SCSI_PORT, mvme147_intr);
148 free_irq(MVME147_IRQ_SCSI_DMA, mvme147_intr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149#endif
Geert Uytterhoevenbe4540d2010-04-04 11:00:34 +0200150 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151}