1/*
2 *  linux/include/asm-m68k/ide.h
3 *
4 *  Copyright (C) 1994-1996  Linus Torvalds & authors
5 */
6
7/* Copyright(c) 1996 Kars de Jong */
8/* Based on the ide driver from 1.2.13pl8 */
9
10/*
11 * Credits (alphabetical):
12 *
13 *  - Bjoern Brauel
14 *  - Kars de Jong
15 *  - Torsten Ebeling
16 *  - Dwight Engen
17 *  - Thorsten Floeck
18 *  - Roman Hodek
19 *  - Guenther Kelleter
20 *  - Chris Lawrence
21 *  - Michael Rausch
22 *  - Christian Sauer
23 *  - Michael Schmitz
24 *  - Jes Soerensen
25 *  - Michael Thurm
26 *  - Geert Uytterhoeven
27 */
28
29#ifndef _M68K_IDE_H
30#define _M68K_IDE_H
31
32#ifdef __KERNEL__
33
34#include <linux/config.h>
35
36#include <asm/setup.h>
37#include <asm/io.h>
38#include <asm/irq.h>
39
40#ifdef CONFIG_ATARI
41#include <linux/interrupt.h>
42#include <asm/atari_stdma.h>
43#endif
44
45#ifdef CONFIG_MAC
46#include <asm/macints.h>
47#endif
48
49#ifndef MAX_HWIFS
50#define MAX_HWIFS	4	/* same as the other archs */
51#endif
52
53
54static __inline__ int ide_default_irq(ide_ioreg_t base)
55{
56	  return 0;
57}
58
59static __inline__ ide_ioreg_t ide_default_io_base(int index)
60{
61          return 0;
62}
63
64
65/*
66 * Set up a hw structure for a specified data port, control port and IRQ.
67 * This should follow whatever the default interface uses.
68 */
69static __inline__ void ide_init_hwif_ports(hw_regs_t *hw, ide_ioreg_t data_port, ide_ioreg_t ctrl_port, int *irq)
70{
71	if (data_port || ctrl_port)
72		printk("ide_init_hwif_ports: must not be called\n");
73}
74
75/*
76 * This registers the standard ports for this architecture with the IDE
77 * driver.
78 */
79static __inline__ void ide_init_default_hwifs(void)
80{
81}
82
83typedef union {
84	unsigned all			: 8;	/* all of the bits together */
85	struct {
86		unsigned bit7		: 1;	/* always 1 */
87		unsigned lba		: 1;	/* using LBA instead of CHS */
88		unsigned bit5		: 1;	/* always 1 */
89		unsigned unit		: 1;	/* drive select number, 0 or 1 */
90		unsigned head		: 4;	/* always zeros here */
91	} b;
92} select_t;
93
94typedef union {
95	unsigned all			: 8;	/* all of the bits together */
96	struct {
97		unsigned HOB		: 1;	/* 48-bit address ordering */
98		unsigned reserved456	: 3;
99		unsigned bit3		: 1;	/* ATA-2 thingy */
100		unsigned SRST		: 1;	/* host soft reset bit */
101		unsigned nIEN		: 1;	/* device INTRQ to host */
102		unsigned bit0		: 1;
103	} b;
104} control_t;
105
106static __inline__ int ide_request_irq(unsigned int irq, void (*handler)(int, void *, struct pt_regs *),
107			unsigned long flags, const char *device, void *dev_id)
108{
109#ifdef CONFIG_AMIGA
110	if (MACH_IS_AMIGA)
111		return request_irq(irq, handler, 0, device, dev_id);
112#endif /* CONFIG_AMIGA */
113#ifdef CONFIG_Q40
114	if (MACH_IS_Q40)
115	  	return request_irq(irq, handler, 0, device, dev_id);
116#endif /* CONFIG_Q40*/
117#ifdef CONFIG_MAC
118	if (MACH_IS_MAC)
119		return request_irq(irq, handler, 0, device, dev_id);
120#endif /* CONFIG_MAC */
121	return 0;
122}
123
124static __inline__ void ide_free_irq(unsigned int irq, void *dev_id)
125{
126#ifdef CONFIG_AMIGA
127	if (MACH_IS_AMIGA)
128		free_irq(irq, dev_id);
129#endif /* CONFIG_AMIGA */
130#ifdef CONFIG_Q40
131	if (MACH_IS_Q40)
132	  	free_irq(irq, dev_id);
133#endif /* CONFIG_Q40*/
134#ifdef CONFIG_MAC
135	if (MACH_IS_MAC)
136		free_irq(irq, dev_id);
137#endif /* CONFIG_MAC */
138}
139
140/*
141 * We should really implement those some day.
142 */
143static __inline__ int ide_check_region (ide_ioreg_t from, unsigned int extent)
144{
145	return 0;
146}
147
148static __inline__ void ide_request_region (ide_ioreg_t from, unsigned int extent, const char *name)
149{
150#ifdef CONFIG_Q40
151        if (MACH_IS_Q40)
152            request_region((q40ide_ioreg_t)from,extent,name);
153#endif
154}
155
156static __inline__ void ide_release_region (ide_ioreg_t from, unsigned int extent)
157{
158#ifdef CONFIG_Q40
159        if (MACH_IS_Q40)
160            release_region((q40ide_ioreg_t)from,extent);
161#endif
162}
163
164#undef SUPPORT_SLOW_DATA_PORTS
165#define SUPPORT_SLOW_DATA_PORTS 0
166
167#undef SUPPORT_VLB_SYNC
168#define SUPPORT_VLB_SYNC 0
169
170/* this definition is used only on startup .. */
171#undef HD_DATA
172#define HD_DATA NULL
173
174
175/*
176 * get rid of defs from io.h
177 * ide still has some private and conflicting versions
178 */
179#undef insw
180#undef insl
181#undef outsw
182#undef outsl
183
184
185/*
186 * define IO method and translation,
187 * so far only Q40 has ide-if on ISA
188 */
189#ifndef CONFIG_Q40
190
191#define ADDR_TRANS_B(_addr_) (_addr_)
192#define ADDR_TRANS_W(_addr_) (_addr_)
193
194#else
195
196#define ADDR_TRANS_B(_addr_) (MACH_IS_Q40 ? ((unsigned char *)Q40_ISA_IO_B(_addr_)) : (_addr_))
197#define ADDR_TRANS_W(_addr_) (MACH_IS_Q40 ? ((unsigned char *)Q40_ISA_IO_W(_addr_)) : (_addr_))
198#endif
199
200#define HAVE_ARCH_OUT_BYTE
201
202#define OUT_BYTE(v,p)	out_8(ADDR_TRANS_B((p)), (v))
203#define OUT_WORD(v,p)	out_be16(ADDR_TRANS_W((p)), (v))
204
205#define HAVE_ARCH_IN_BYTE
206
207#define IN_BYTE(p)	in_8(ADDR_TRANS_B((p)))
208#define IN_WORD(p)	in_be16(ADDR_TRANS_W((p)))
209
210#define insw(port, buf, nr) raw_insw(ADDR_TRANS_W(port), buf, nr)
211#define outsw(port, buf, nr) raw_outsw(ADDR_TRANS_W(port), buf, nr)
212
213#define insl(data_reg, buffer, wcount) insw(data_reg, buffer, (wcount)<<1)
214#define outsl(data_reg, buffer, wcount) outsw(data_reg, buffer, (wcount)<<1)
215
216
217#if defined(CONFIG_ATARI) || defined(CONFIG_Q40)
218
219#define insl_swapw(data_reg, buffer, wcount) \
220    insw_swapw(data_reg, buffer, (wcount)<<1)
221#define outsl_swapw(data_reg, buffer, wcount) \
222    outsw_swapw(data_reg, buffer, (wcount)<<1)
223
224#define insw_swapw(port, buf, nr) raw_insw_swapw(ADDR_TRANS_W(port), buf, nr)
225#define outsw_swapw(port, buf, nr) raw_outsw_swapw(ADDR_TRANS_W(port),buf,nr)
226
227#endif /* CONFIG_ATARI || CONFIG_Q40 */
228
229
230#define T_CHAR          (0x0000)        /* char:  don't touch  */
231#define T_SHORT         (0x4000)        /* short: 12 -> 21     */
232#define T_INT           (0x8000)        /* int:   1234 -> 4321 */
233#define T_TEXT          (0xc000)        /* text:  12 -> 21     */
234
235#define T_MASK_TYPE     (0xc000)
236#define T_MASK_COUNT    (0x3fff)
237
238#define D_CHAR(cnt)     (T_CHAR  | (cnt))
239#define D_SHORT(cnt)    (T_SHORT | (cnt))
240#define D_INT(cnt)      (T_INT   | (cnt))
241#define D_TEXT(cnt)     (T_TEXT  | (cnt))
242
243/* Q40 and Atari have byteswapped IDE bus and since many interesting
244 * values in the identification string are text, chars and words they
245 * happened to be almost correct without swapping.. However *_capacity
246 * is needed for drives over 8 GB. RZ */
247#if defined(CONFIG_Q40) || defined(CONFIG_ATARI)
248#define M68K_IDE_SWAPW  (MACH_IS_Q40 || MACH_IS_ATARI)
249#endif
250
251#if defined(CONFIG_AMIGA) || defined(CONFIG_MAC) || defined(M68K_IDE_SWAPW)
252static u_short driveid_types[] = {
253	D_SHORT(10),	/* config - vendor2 */
254	D_TEXT(20),	/* serial_no */
255	D_SHORT(3),	/* buf_type, buf_size - ecc_bytes */
256	D_TEXT(48),	/* fw_rev - model */
257	D_CHAR(2),	/* max_multsect - vendor3 */
258	D_SHORT(1),	/* dword_io */
259	D_CHAR(2),	/* vendor4 - capability */
260	D_SHORT(1),	/* reserved50 */
261	D_CHAR(4),	/* vendor5 - tDMA */
262	D_SHORT(4),	/* field_valid - cur_sectors */
263	D_INT(1),	/* cur_capacity */
264	D_CHAR(2),	/* multsect - multsect_valid */
265	D_INT(1),	/* lba_capacity */
266	D_SHORT(194)	/* dma_1word - reserved */
267};
268
269#define num_driveid_types       (sizeof(driveid_types)/sizeof(*driveid_types))
270#endif /* CONFIG_AMIGA */
271
272static __inline__ void ide_fix_driveid(struct hd_driveid *id)
273{
274#if defined(CONFIG_AMIGA) || defined(CONFIG_MAC) || defined(M68K_IDE_SWAPW)
275   u_char *p = (u_char *)id;
276   int i, j, cnt;
277   u_char t;
278
279   if (!MACH_IS_AMIGA && !MACH_IS_MAC && !MACH_IS_Q40 && !MACH_IS_ATARI)
280   	return;
281#ifdef M68K_IDE_SWAPW
282   if (M68K_IDE_SWAPW)    /* fix bus byteorder first */
283      for (i=0; i < 512; i+=2) {
284	 t = p[i]; p[i] = p[i+1]; p[i+1] = t;
285      }
286#endif
287   for (i = 0; i < num_driveid_types; i++) {
288      cnt = driveid_types[i] & T_MASK_COUNT;
289      switch (driveid_types[i] & T_MASK_TYPE) {
290         case T_CHAR:
291            p += cnt;
292            break;
293         case T_SHORT:
294            for (j = 0; j < cnt; j++) {
295	       t = p[0];
296	       p[0] = p[1];
297	       p[1] = t;
298               p += 2;
299            }
300            break;
301         case T_INT:
302            for (j = 0; j < cnt; j++) {
303	       t = p[0];
304	       p[0] = p[3];
305	       p[3] = t;
306	       t = p[1];
307	       p[1] = p[2];
308	       p[2] = t;
309               p += 4;
310            }
311            break;
312         case T_TEXT:
313            for (j = 0; j < cnt; j += 2) {
314	       t = p[0];
315	       p[0] = p[1];
316	       p[1] = t;
317               p += 2;
318            }
319            break;
320      }
321   }
322#endif /* CONFIG_AMIGA */
323}
324
325static __inline__ void ide_release_lock (int *ide_lock)
326{
327#ifdef CONFIG_ATARI
328	if (MACH_IS_ATARI) {
329		if (*ide_lock == 0) {
330			printk("ide_release_lock: bug\n");
331			return;
332		}
333		*ide_lock = 0;
334		stdma_release();
335	}
336#endif /* CONFIG_ATARI */
337}
338
339static __inline__ void ide_get_lock (int *ide_lock, void (*handler)(int, void *, struct pt_regs *), void *data)
340{
341#ifdef CONFIG_ATARI
342	if (MACH_IS_ATARI) {
343		if (*ide_lock == 0) {
344			if (in_interrupt() > 0)
345				panic( "Falcon IDE hasn't ST-DMA lock in interrupt" );
346			stdma_lock(handler, data);
347			*ide_lock = 1;
348		}
349	}
350#endif /* CONFIG_ATARI */
351}
352
353#define ide_ack_intr(hwif)	((hwif)->hw.ack_intr ? (hwif)->hw.ack_intr(hwif) : 1)
354
355/*
356 * On the Atari, we sometimes can't enable interrupts:
357 */
358
359/* MSch: changed sti() to STI() wherever possible in ide.c; moved STI() def.
360 * to asm/ide.h
361 */
362/* The Atari interrupt structure strictly requires that the IPL isn't lowered
363 * uncontrolled in an interrupt handler. In the concrete case, the IDE
364 * interrupt is already a slow int, so the irq is already disabled at the time
365 * the handler is called, and the IPL has been lowered to the minimum value
366 * possible. To avoid going below that, STI() checks for being called inside
367 * an interrupt, and in that case it does nothing. Hope that is reasonable and
368 * works. (Roman)
369 */
370#ifdef MACH_ATARI_ONLY
371#define	ide__sti()					\
372    do {						\
373	if (!in_interrupt()) __sti();			\
374    } while(0)
375#elif defined(CONFIG_ATARI)
376#define	ide__sti()						\
377    do {							\
378	if (!MACH_IS_ATARI || !in_interrupt()) sti();		\
379    } while(0)
380#else /* !defined(CONFIG_ATARI) */
381#define	ide__sti()	__sti()
382#endif
383
384#endif /* __KERNEL__ */
385
386#endif /* _M68K_IDE_H */
387