[SCSI] gvp11: Use shost_priv() and kill ugly HDATA() macro
[GitHub/LineageOS/android_kernel_motorola_exynos9610.git] / drivers / scsi / mvme147.c
CommitLineData
1da177e4
LT
1#include <linux/types.h>
2#include <linux/mm.h>
3#include <linux/blkdev.h>
1da177e4
LT
4#include <linux/interrupt.h>
5
6#include <asm/page.h>
7#include <asm/pgtable.h>
8#include <asm/mvme147hw.h>
9#include <asm/irq.h>
10
11#include "scsi.h"
12#include <scsi/scsi_host.h>
13#include "wd33c93.h"
14#include "mvme147.h"
15
be4540db 16#include <linux/stat.h>
1da177e4 17
be4540db
GU
18
19#define HDATA(ptr) ((struct WD33C93_hostdata *)((ptr)->hostdata))
1da177e4
LT
20
21static struct Scsi_Host *mvme147_host = NULL;
22
be4540db 23static irqreturn_t mvme147_intr(int irq, void *dummy)
1da177e4 24{
be4540db
GU
25 if (irq == MVME147_IRQ_SCSI_PORT)
26 wd33c93_intr(mvme147_host);
27 else
28 m147_pcc->dma_intr = 0x89; /* Ack and enable ints */
29 return IRQ_HANDLED;
1da177e4
LT
30}
31
65396410 32static int dma_setup(struct scsi_cmnd *cmd, int dir_in)
1da177e4 33{
be4540db
GU
34 unsigned char flags = 0x01;
35 unsigned long addr = virt_to_bus(cmd->SCp.ptr);
36
37 /* setup dma direction */
38 if (!dir_in)
39 flags |= 0x04;
40
41 /* remember direction */
42 HDATA(mvme147_host)->dma_dir = dir_in;
43
44 if (dir_in) {
45 /* invalidate any cache */
46 cache_clear(addr, cmd->SCp.this_residual);
47 } else {
48 /* push any dirty cache */
49 cache_push(addr, cmd->SCp.this_residual);
50 }
51
52 /* start DMA */
53 m147_pcc->dma_bcr = cmd->SCp.this_residual | (1 << 24);
54 m147_pcc->dma_dadr = addr;
55 m147_pcc->dma_cntrl = flags;
56
57 /* return success */
58 return 0;
1da177e4
LT
59}
60
65396410 61static void dma_stop(struct Scsi_Host *instance, struct scsi_cmnd *SCpnt,
be4540db 62 int status)
1da177e4 63{
be4540db 64 m147_pcc->dma_cntrl = 0;
1da177e4
LT
65}
66
d0be4a7d 67int mvme147_detect(struct scsi_host_template *tpnt)
1da177e4 68{
be4540db
GU
69 static unsigned char called = 0;
70 wd33c93_regs regs;
71
72 if (!MACH_IS_MVME147 || called)
73 return 0;
74 called++;
75
76 tpnt->proc_name = "MVME147";
77 tpnt->proc_info = &wd33c93_proc_info;
78
79 mvme147_host = scsi_register(tpnt, sizeof(struct WD33C93_hostdata));
80 if (!mvme147_host)
81 goto err_out;
82
83 mvme147_host->base = 0xfffe4000;
84 mvme147_host->irq = MVME147_IRQ_SCSI_PORT;
85 regs.SASR = (volatile unsigned char *)0xfffe4000;
86 regs.SCMD = (volatile unsigned char *)0xfffe4001;
87 HDATA(mvme147_host)->no_sync = 0xff;
88 HDATA(mvme147_host)->fast = 0;
89 HDATA(mvme147_host)->dma_mode = CTRL_DMA;
90 wd33c93_init(mvme147_host, regs, dma_setup, dma_stop, WD33C93_FS_8_10);
91
92 if (request_irq(MVME147_IRQ_SCSI_PORT, mvme147_intr, 0,
93 "MVME147 SCSI PORT", mvme147_intr))
94 goto err_unregister;
95 if (request_irq(MVME147_IRQ_SCSI_DMA, mvme147_intr, 0,
96 "MVME147 SCSI DMA", mvme147_intr))
97 goto err_free_irq;
1da177e4 98#if 0 /* Disabled; causes problems booting */
be4540db
GU
99 m147_pcc->scsi_interrupt = 0x10; /* Assert SCSI bus reset */
100 udelay(100);
101 m147_pcc->scsi_interrupt = 0x00; /* Negate SCSI bus reset */
102 udelay(2000);
103 m147_pcc->scsi_interrupt = 0x40; /* Clear bus reset interrupt */
1da177e4 104#endif
be4540db 105 m147_pcc->scsi_interrupt = 0x09; /* Enable interrupt */
1da177e4 106
be4540db
GU
107 m147_pcc->dma_cntrl = 0x00; /* ensure DMA is stopped */
108 m147_pcc->dma_intr = 0x89; /* Ack and enable ints */
1da177e4 109
be4540db 110 return 1;
1da177e4 111
be4540db
GU
112err_free_irq:
113 free_irq(MVME147_IRQ_SCSI_PORT, mvme147_intr);
114err_unregister:
115 scsi_unregister(mvme147_host);
116err_out:
117 return 0;
1da177e4
LT
118}
119
65396410 120static int mvme147_bus_reset(struct scsi_cmnd *cmd)
1da177e4
LT
121{
122 /* FIXME perform bus-specific reset */
68b3aa7c 123
be4540db 124 /* FIXME 2: kill this function, and let midlayer fallback to
df0ae249
JG
125 the same result, calling wd33c93_host_reset() */
126
68b3aa7c 127 spin_lock_irq(cmd->device->host->host_lock);
1da177e4 128 wd33c93_host_reset(cmd);
68b3aa7c
JG
129 spin_unlock_irq(cmd->device->host->host_lock);
130
1da177e4
LT
131 return SUCCESS;
132}
133
134#define HOSTS_C
135
136#include "mvme147.h"
137
d0be4a7d 138static struct scsi_host_template driver_template = {
1da177e4
LT
139 .proc_name = "MVME147",
140 .name = "MVME147 built-in SCSI",
141 .detect = mvme147_detect,
142 .release = mvme147_release,
143 .queuecommand = wd33c93_queuecommand,
144 .eh_abort_handler = wd33c93_abort,
145 .eh_bus_reset_handler = mvme147_bus_reset,
146 .eh_host_reset_handler = wd33c93_host_reset,
147 .can_queue = CAN_QUEUE,
148 .this_id = 7,
149 .sg_tablesize = SG_ALL,
150 .cmd_per_lun = CMD_PER_LUN,
151 .use_clustering = ENABLE_CLUSTERING
152};
153
154
155#include "scsi_module.c"
156
157int mvme147_release(struct Scsi_Host *instance)
158{
159#ifdef MODULE
be4540db
GU
160 /* XXX Make sure DMA is stopped! */
161 free_irq(MVME147_IRQ_SCSI_PORT, mvme147_intr);
162 free_irq(MVME147_IRQ_SCSI_DMA, mvme147_intr);
1da177e4 163#endif
be4540db 164 return 1;
1da177e4 165}