1/*	$NetBSD: iwmreg.h,v 1.7 2005/12/11 12:18:03 christos Exp $	*/
2
3/*
4 * Copyright (c) 1996-99 Hauke Fath.  All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 *    derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28#ifndef _MAC68K_IWMREG_H
29#define _MAC68K_IWMREG_H
30
31/*
32 * iwmreg.h -- Interface declarations for iwm.
33 */
34
35#ifndef _LOCORE
36
37/*
38 * Configuration
39 */
40
41/* Virtual Drive flags register */
42enum {
43	IWM_DS_DISK	= 0x01,
44	IWM_NO_DISK 	= 0x02,
45	IWM_MOTOR_OFF 	= 0x04,
46	IWM_WRITABLE	= 0x08,
47	IWM_DD_DISK 	= 0x10,
48	IWM_NO_DRIVE 	= 0x80000000
49};
50
51/*
52 * Access
53 */
54enum {
55	noErr = 0,		/* All went well			  */
56	noDriveErr = -64,	/* Drive not installed			  */
57	offLinErr = -65,	/* R/W requested for an offline drive	  */
58	noNybErr = -66,		/* Disk is probably blank		  */
59	noAdrMkErr = -67,	/* Can't find an address mark		  */
60	dataVerErr = -68,	/* Read verify compare failed		  */
61	badCkSmErr = -69,	/* Bad address mark checksum		  */
62	badBtSlpErr = -70,	/* Bad address mark (no lead-out)	  */
63	noDtaMkErr = -71,	/* Could not find a data mark		  */
64	badDCkSum = -72,	/* Bad data mark checksum		  */
65	badDBtSlp = -73,	/* One of the data mark bit slip 	  */
66				/* nibbles was incorrect.		  */
67	wrUnderRun = -74,	/* Could not write fast enough to  	  */
68				/* keep up with the IWM			  */
69	cantStepErr = -75,	/*  Step handshake failed during seek	  */
70	tk0BadErr = -76,	/* Track 00 sensor does not change 	  */
71				/* during head calibration		  */
72	initIWMErr = -77,	/* Unable to initialize IWM		  */
73	twoSideErr = -78,	/* Tried to access a double-sided disk    */
74				/* on a single-sided drive (400K drive)	  */
75	spAdjErr = -79,		/* Can't adjust drive speed (400K drive)  */
76	seekErr = -80,		/* Wrong track number read in a sector's  */
77				/* address field		 	  */
78	sectNFErr = -81,	/* Sector number never found on a track	  */
79	fmt1Err = -82,		/* Can't find sector 0 after track format */
80	fmt2Err = -83,		/* Can't get enough sync		  */
81	verErr = -84		/* Track failed to verify		  */
82};
83
84#define IWM_TAG_SIZE 20		/* That's what "SonyEqu.a" says		 */
85
86
87/* Buffer for sector header data */
88struct sectorHdr {
89	u_int8_t side;
90	u_int8_t track;
91	u_int8_t sector;
92	u_int8_t Tags[IWM_TAG_SIZE];
93};
94typedef struct sectorHdr sectorHdr_t;
95
96/*
97 * Cylinder cache data structure
98 * Cyl buffer is allocated in fdopen() and deallocated in fdclose().
99 *
100 * The "valid" flag is overloaded as "dirty" flag when writing
101 * to disk.
102 */
103struct cylCacheSlot {
104	unsigned char *secbuf;		/* ptr to one sector buffer */
105	int32_t valid;			/* content valid for cur. cylinder? */
106};
107typedef struct cylCacheSlot cylCacheSlot_t;
108
109
110#else /* _LOCORE */
111
112
113/*
114 * Assembler equates for IWM, kept here to ensure consistency.
115 * Modelled after <sys/disklabel.h>
116 */
117
118/*
119 * Offsets into data structures
120 */
121	/* sectorHdr_t */
122	.equ	o_side,		0
123	.equ	o_track,	1
124	.equ	o_sector,	2
125	.equ	o_Tags,		3
126
127	/* cylCacheSlot_t */
128	.equ	o_secbuf,	0
129	.equ	o_valid,	4
130
131/*
132 * Parameter (a6) offsets from <mac68k/obio/iwm_fdvar.h>
133 *
134 * int iwmReadSector(sectorHdr_t *hdr, cylCacheSlot_t *r_slots, void *buf)
135 * int iwmWriteSector(sectorHdr_t *hdr, cylCacheSlot_t *w_slots)
136 */
137	.equ	o_hdr,		 8
138	.equ	o_rslots,	12
139	.equ	o_wslots,	12
140	.equ	o_buf,		16
141
142/*
143 * Offsets from IWM base address
144 * Lines are set by any memory access to corresponding address (IM III-34/-44).
145 * The SWIM has actual registers at these addresses, so writing to them
146 * in IWM mode is a no-no.
147 */
148	.equ	ph0L,		0x0000	/* CA0 off (0) */
149	.equ	ph0H,		0x0200	/* CA0 on  (1) */
150	.equ	ph1L,		0x0400	/* CA1 off (0) */
151	.equ	ph1H,		0x0600	/* CA1 on  (1) */
152	.equ	ph2L,		0x0800	/* CA2 off (0) */
153	.equ	ph2H,		0x0A00	/* CA2 on  (1) */
154	.equ	ph3L,		0x0C00	/* LSTRB off (low) */
155	.equ	ph3H,		0x0E00	/* LSTRB on (high) */
156	.equ	mtrOff,		0x1000	/* disk enable off */
157	.equ	mtrOn,		0x1200	/* disk enable on */
158	.equ	intDrive,	0x1400	/* select internal drive */
159	.equ	extDrive,	0x1600	/* select external drive */
160	.equ	q6L,		0x1800	/* Q6 off */
161	.equ	q6H,		0x1A00	/* Q6 on */
162	.equ	q7L,		0x1C00	/* Q7 off */
163	.equ	q7H,		0x1E00	/* Q7 on */
164
165
166/*
167 * VIA Disk SEL line
168 */
169	.equ	vBufA,		0x1E00	/* Offset from vBase to register A  */
170					/* (IM III-43) */
171	.equ	vHeadSel,	5	/* Multi-purpose line (SEL) */
172	.equ	vHeadSelMask,	0x0020	/* Corresponding bit mask */
173
174
175/*
176 * Disk registers
177 *	bit 0 - CA2, bit 1 - SEL, bit 2 - CA0, bit 3 - CA1	   IM III name
178 */
179
180	/* Status */
181	.equ	stepDirection,	0x0000	/* Direction of next head step       */
182					/* 0 = in, 1 = out           (DIRTN) */
183	.equ	rdDataFrom0,	0x0001	/* Set up drive to read data from    */
184					/* head 0                  (RDDATA0) */
185	.equ	diskInserted,	0x0002	/* Disk inserted                     */
186					/* 0 = yes, 1 = no           (CSTIN) */
187	.equ	rdDataFrom1,	0x0003	/* Set up drive to read data from    */
188					/* head 1                  (RDDATA1) */
189	.equ	stillStepping,	0x0004	/* Drive is still stepping           */
190					/* 0 = yes, 1 = no            (STEP) */
191	.equ	writeProtected,	0x0006	/* Disk is locked                    */
192					/* 0 = yes, 1 = no          (WRTPRT) */
193	.equ	drvMotorState,	0x0008	/* Drive motor is on                 */
194					/* 0 = yes, 1 = no         (MOTORON) */
195	.equ	singleSided,	0x0009	/* Drive is single-sided             */
196					/* 0 = yes, 1 = no           (SIDES) */
197	.equ	atTrack00,	0x000A	/* Head is at track 00               */
198					/* 0 = yes, 1 = no             (TK0) */
199	.equ	headLoaded,	0x000B	/* Head loaded, drive is ready       */
200					/* 0 = yes, 1 = no		 ()  */
201	.equ	drvInstalled,	0x000D	/* Disk drive installed              */
202					/* 0 = yes, 1 = no		 ()  */
203	.equ	tachPulse,	0x000E	/* Tachometer pulse (60 /rev.)       */
204					/* 0 = yes, 1 = no	     (TACH)  */
205	.equ	diskIsHD,	0x000F	/* HD disk detected                  */
206					/* 0 = yes, 1 = no	    (DRVIN)  */
207
208	/* Commands */
209	.equ	stepInCmd,	0x0000	/* Head step direction in    (DIRTN) */
210	.equ	stepOutCmd,	0x0001	/* Head step direction out (DIRTN+1) */
211	.equ	doStepCmd,	0x0004	/* Step head (STEP)                  */
212	.equ	motorOnCmd,	0x0008	/* Switch drive motor on   (MOTORON) */
213	.equ	motorOffCmd,	0x0009	/* Switch drive motor off (MOTOROFF) */
214	.equ	ejectDiskCmd,	0x000D	/* Eject disk from drive     (EJECT) */
215
216
217/*
218 * Low level disk errors
219 * For simplicity, they are given the MacOS names and numbers.
220 */
221	.equ	noErr,		  0	/* All went well */
222	.equ	noDriveErr,	-64	/* Drive not installed */
223	.equ	offLinErr,	-65	/* R/W requested for an offline drive */
224	.equ	noNybErr,	-66	/* Disk is probably blank */
225	.equ	noAdrMkErr,	-67	/* Can't find an address mark */
226	.equ	dataVerErr,	-68	/* Read verify compare failed */
227	.equ	badCkSmErr,	-69	/* Bad address mark checksum */
228	.equ	badBtSlpErr,	-70	/* Bad address mark (no lead-out) */
229	.equ	noDtaMkErr,	-71	/* Could not find a data mark */
230	.equ	badDCkSum,	-72	/* Bad data mark checksum */
231	.equ	badDBtSlp,	-73	/* One of the data mark bit slip */
232					/* nibbles was incorrect. */
233	.equ	wrUnderRun,	-74	/* Could not write fast enough to */
234					/* keep up with the IWM */
235	.equ	cantStepErr,	-75	/* Step handshake failed during seek */
236	.equ	tk0BadErr,	-76	/* Track 00 sensor does not change */
237					/* during head calibration */
238	.equ	initIWMErr,	-77	/* Unable to initialize IWM */
239	.equ	twoSideErr,	-78	/* Tried to access a double-sided disk */
240					/* on a single-sided drive (400K drive) */
241	.equ	spAdjErr,	-79	/* Can't adjust drive speed (400K drive) */
242	.equ	seekErr,	-80	/* Wrong track number read in a  */
243					/* sector's address field */
244	.equ	sectNFErr,	-81	/* Sector number never found on a track */
245	.equ	fmt1Err,	-82	/* Can't find sector 0 after  */
246					/* track format */
247	.equ	fmt2Err,	-83	/* Can't get enough sync */
248	.equ	verErr,		-84	/* Track failed to verify */
249
250/*
251 * Misc constants
252 */
253	.equ	iwmMode,	0x17	/* SWIM switch */
254	.equ	maxGCRSectors,	12	/* Max. sectors per track for GCR */
255
256
257#endif /* _LOCORE */
258
259#endif /* _MAC68K_IWMREG_H */
260