2 * linux/include/asm-m68k/ide.h
4 * Copyright (C) 1994-1996 Linus Torvalds & authors
7 /* Copyright(c) 1996 Kars de Jong */
8 /* Based on the ide driver from 1.2.13pl8 */
11 * Credits (alphabetical):
26 * - Geert Uytterhoeven
34 #include <linux/config.h>
36 #include <asm/setup.h>
41 #include <linux/interrupt.h>
42 #include <asm/atari_stdma.h>
46 #include <asm/macints.h>
50 #define MAX_HWIFS 4 /* same as the other archs */
53 int q40ide_default_irq(q40ide_ioreg_t
);
55 static __inline__
int ide_default_irq(ide_ioreg_t base
)
58 return q40ide_default_irq((q40ide_ioreg_t
) base
);
62 int q40ide_default_io_base(int);
64 static __inline__ ide_ioreg_t
ide_default_io_base(int index
)
67 return (ide_ioreg_t
)q40ide_default_io_base(index
);
72 * Can we do this in a generic manner??
74 void q40_ide_init_hwif_ports (hw_regs_t
*hw
, q40ide_ioreg_t data_port
, q40ide_ioreg_t ctrl_port
, int *irq
);
77 * Set up a hw structure for a specified data port, control port and IRQ.
78 * This should follow whatever the default interface uses.
80 static __inline__
void ide_init_hwif_ports(hw_regs_t
*hw
, ide_ioreg_t data_port
, ide_ioreg_t ctrl_port
, int *irq
)
84 return q40_ide_init_hwif_ports(hw
, (q40ide_ioreg_t
) data_port
, (q40ide_ioreg_t
) ctrl_port
, irq
);
86 if (data_port
|| ctrl_port
)
87 printk("ide_init_hwif_ports: must not be called\n");
91 * This registers the standard ports for this architecture with the IDE
94 static __inline__
void ide_init_default_hwifs(void)
99 unsigned all
: 8; /* all of the bits together */
101 unsigned bit7
: 1; /* always 1 */
102 unsigned lba
: 1; /* using LBA instead of CHS */
103 unsigned bit5
: 1; /* always 1 */
104 unsigned unit
: 1; /* drive select number, 0 or 1 */
105 unsigned head
: 4; /* always zeros here */
109 static __inline__
int ide_request_irq(unsigned int irq
, void (*handler
)(int, void *, struct pt_regs
*),
110 unsigned long flags
, const char *device
, void *dev_id
)
114 return request_irq(irq
, handler
, 0, device
, dev_id
);
115 #endif /* CONFIG_AMIGA */
118 return request_irq(irq
, handler
, 0, device
, dev_id
);
119 #endif /* CONFIG_Q40*/
122 return request_irq(irq
, handler
, 0, device
, dev_id
);
123 #endif /* CONFIG_MAC */
127 static __inline__
void ide_free_irq(unsigned int irq
, void *dev_id
)
131 free_irq(irq
, dev_id
);
132 #endif /* CONFIG_AMIGA */
135 free_irq(irq
, dev_id
);
136 #endif /* CONFIG_Q40*/
139 free_irq(irq
, dev_id
);
140 #endif /* CONFIG_MAC */
144 * We should really implement those some day.
146 static __inline__
int ide_check_region (ide_ioreg_t from
, unsigned int extent
)
151 static __inline__
void ide_request_region (ide_ioreg_t from
, unsigned int extent
, const char *name
)
155 request_region((q40ide_ioreg_t
)from
,extent
,name
);
159 static __inline__
void ide_release_region (ide_ioreg_t from
, unsigned int extent
)
163 release_region((q40ide_ioreg_t
)from
,extent
);
167 #undef SUPPORT_SLOW_DATA_PORTS
168 #define SUPPORT_SLOW_DATA_PORTS 0
170 #undef SUPPORT_VLB_SYNC
171 #define SUPPORT_VLB_SYNC 0
173 /* this definition is used only on startup .. */
180 #define HD_DATA ((ide_ioreg_t)0x1f0)
183 #define HD_DATA (MACH_IS_Q40 ? (ide_ioreg_t)0x1f0 : 0)
188 #define insl(data_reg, buffer, wcount) insw(data_reg, buffer, (wcount)<<1)
189 #define outsl(data_reg, buffer, wcount) outsw(data_reg, buffer, (wcount)<<1)
193 #define ADDR_TRANS(_addr_) (Q40_ISA_IO_W(_addr_))
195 #define ADDR_TRANS(_addr_) (MACH_IS_Q40 ? ((unsigned char *)Q40_ISA_IO_W(_addr_)) : (_addr_))
198 #define ADDR_TRANS(_addr_) (_addr_)
201 #define insw(port, buf, nr) ({ \
202 unsigned char *_port = (unsigned char *) ADDR_TRANS(port); \
203 unsigned char *_buf = (buf); \
205 unsigned long _tmp; \
208 _tmp = (_nr & 15) - 1; \
210 "1: movew %2@,%0@+; dbra %1,1b" \
211 : "=a" (_buf), "=d" (_tmp) \
212 : "a" (_port), "0" (_buf), \
216 _tmp = (_nr >> 4) - 1; \
236 : "=a" (_buf), "=d" (_tmp) \
237 : "a" (_port), "0" (_buf), \
242 #define outsw(port, buf, nr) ({ \
243 unsigned char *_port = (unsigned char *) ADDR_TRANS(port); \
244 unsigned char *_buf = (buf); \
246 unsigned long _tmp; \
249 _tmp = (_nr & 15) - 1; \
251 "1: movew %0@+,%2@; dbra %1,1b" \
252 : "=a" (_buf), "=d" (_tmp) \
253 : "a" (_port), "0" (_buf), \
257 _tmp = (_nr >> 4) - 1; \
277 : "=a" (_buf), "=d" (_tmp) \
278 : "a" (_port), "0" (_buf), \
283 #if defined(CONFIG_ATARI) || defined(CONFIG_Q40)
284 #define insl_swapw(data_reg, buffer, wcount) \
285 insw_swapw(data_reg, buffer, (wcount)<<1)
286 #define outsl_swapw(data_reg, buffer, wcount) \
287 outsw_swapw(data_reg, buffer, (wcount)<<1)
289 #define insw_swapw(port, buf, nr) \
291 __asm__ __volatile__ \
296 1:movew %/a0@,%/d0; \
300 : "g" (ADDR_TRANS(port)), "g" (buf), "g" (nr) \
301 : "d0", "a0", "a1", "d6"); \
303 __asm__ __volatile__ \
309 1:movew %/a0@,%/d0; \
334 : "g" (ADDR_TRANS(port)), "g" (buf), "g" (nr) \
335 : "d0", "a0", "a1", "d6")
338 #define outsw_swapw(port, buf, nr) \
340 __asm__ __volatile__ \
345 1:movew %/a1@+,%/d0; \
349 : "g" (ADDR_TRANS(port)), "g" (buf), "g" (nr) \
350 : "d0", "a0", "a1", "d6"); \
352 __asm__ __volatile__ \
358 1:movew %/a1@+,%/d0; \
383 : "g" (ADDR_TRANS(port)), "g" (buf), "g" (nr) \
384 : "d0", "a0", "a1", "d6")
386 #endif /* CONFIG_ATARI */
388 #define T_CHAR (0x0000) /* char: don't touch */
389 #define T_SHORT (0x4000) /* short: 12 -> 21 */
390 #define T_INT (0x8000) /* int: 1234 -> 4321 */
391 #define T_TEXT (0xc000) /* text: 12 -> 21 */
393 #define T_MASK_TYPE (0xc000)
394 #define T_MASK_COUNT (0x3fff)
396 #define D_CHAR(cnt) (T_CHAR | (cnt))
397 #define D_SHORT(cnt) (T_SHORT | (cnt))
398 #define D_INT(cnt) (T_INT | (cnt))
399 #define D_TEXT(cnt) (T_TEXT | (cnt))
401 #if defined(CONFIG_AMIGA) || defined (CONFIG_MAC)
402 static u_short driveid_types
[] = {
403 D_SHORT(10), /* config - vendor2 */
404 D_TEXT(20), /* serial_no */
405 D_SHORT(3), /* buf_type, buf_size - ecc_bytes */
406 D_TEXT(48), /* fw_rev - model */
407 D_CHAR(2), /* max_multsect - vendor3 */
408 D_SHORT(1), /* dword_io */
409 D_CHAR(2), /* vendor4 - capability */
410 D_SHORT(1), /* reserved50 */
411 D_CHAR(4), /* vendor5 - tDMA */
412 D_SHORT(4), /* field_valid - cur_sectors */
413 D_INT(1), /* cur_capacity */
414 D_CHAR(2), /* multsect - multsect_valid */
415 D_INT(1), /* lba_capacity */
416 D_SHORT(194) /* dma_1word - reservedyy */
419 #define num_driveid_types (sizeof(driveid_types)/sizeof(*driveid_types))
420 #endif /* CONFIG_AMIGA */
422 static __inline__
void ide_fix_driveid(struct hd_driveid
*id
)
424 #if defined(CONFIG_AMIGA) || defined (CONFIG_MAC)
425 u_char
*p
= (u_char
*)id
;
429 if (!MACH_IS_AMIGA
&& !MACH_IS_MAC
)
431 for (i
= 0; i
< num_driveid_types
; i
++) {
432 cnt
= driveid_types
[i
] & T_MASK_COUNT
;
433 switch (driveid_types
[i
] & T_MASK_TYPE
) {
438 for (j
= 0; j
< cnt
; j
++) {
446 for (j
= 0; j
< cnt
; j
++) {
457 for (j
= 0; j
< cnt
; j
+= 2) {
466 #endif /* CONFIG_AMIGA */
469 static __inline__
void ide_release_lock (int *ide_lock
)
473 if (*ide_lock
== 0) {
474 printk("ide_release_lock: bug\n");
480 #endif /* CONFIG_ATARI */
483 static __inline__
void ide_get_lock (int *ide_lock
, void (*handler
)(int, void *, struct pt_regs
*), void *data
)
487 if (*ide_lock
== 0) {
488 if (in_interrupt() > 0)
489 panic( "Falcon IDE hasn't ST-DMA lock in interrupt" );
490 stdma_lock(handler
, data
);
494 #endif /* CONFIG_ATARI */
497 #define ide_ack_intr(hwif) ((hwif)->hw.ack_intr ? (hwif)->hw.ack_intr(hwif) : 1)
500 * On the Atari, we sometimes can't enable interrupts:
503 /* MSch: changed sti() to STI() wherever possible in ide.c; moved STI() def.
506 /* The Atari interrupt structure strictly requires that the IPL isn't lowered
507 * uncontrolled in an interrupt handler. In the concrete case, the IDE
508 * interrupt is already a slow int, so the irq is already disabled at the time
509 * the handler is called, and the IPL has been lowered to the minimum value
510 * possible. To avoid going below that, STI() checks for being called inside
511 * an interrupt, and in that case it does nothing. Hope that is reasonable and
514 #ifdef MACH_ATARI_ONLY
517 if (!in_interrupt()) __sti(); \
519 #elif defined(CONFIG_ATARI)
522 if (!MACH_IS_ATARI || !in_interrupt()) sti(); \
524 #else /* !defined(CONFIG_ATARI) */
525 #define ide__sti() __sti()
528 #endif /* __KERNEL__ */
530 #endif /* _M68K_IDE_H */