/*
 * linux/include/asm-arm/arch-psionw/ide.h
 *
 * Copyright (C) 2001 Tony Lindgren <tony@atomide.com>
 *
 * Contains code from the Psion 5 ETNA driver for linux, 
 * Copyright (C) 1999 Werner Almesberger.
 * 
 * Some code based on the code from sa1100 ide.h
 * Copyright (c) 1998 Hugo Fiennes & Nicolas Pitre
 *
 */

#include <linux/config.h>
#include <asm/irq.h>
#include <asm/hardware.h>
#include <asm/mach-types.h>
#include <asm/hardware/psionw.h>

#include <../drivers/pcmcia/psion_etna.h>

#if !defined(CONFIG_PSIONW_REVO) && !defined(CONFIG_PSIONW_REVOPLUS)

//#define DISK_RECOVERY_TIME	500
#define WAIT_DRQ	(50*HZ/100)	/* 50msec - spec allows up to 20ms */
#define WAIT_READY	(5*HZ)		/* 5sec - some laptops are very slow */
#define WAIT_CMD	(10*HZ)	/* 10sec  - maximum wait for an IRQ to happen */
//#define CONFIG_BLK_DEV_IDEDMA	1

/*
 * We need to override the default insw and outsw, as the ETNA
 * chip does automatic word to half-word translation. For some
 * weird reason the translation only seems to happen for IDE cards.
 * See also etna_insw_direct() and etna_outsw_direct().
 */
#define insw(p,d,l)		etna_insw_ide(p,d,l)
#define outsw(p,d,l)		etna_outsw_ide(p,d,l)

static __inline__ void
ide_init_hwif_ports(hw_regs_t * hw, int data_port, int ctrl_port, int *irq)
{
	ide_ioreg_t reg;
	int i;
	int regincr = 1;

	/* 
	 * The CF card is not powered up on 5mx Pro when
	 * booting without Epoc. Optionally this is not
	 * needed for 5mx, as ETNA is already powered.
	 * Also the cold init resets the Epoc CF config.
	 */
	etna_cold_init();

	memset(hw, 0, sizeof (*hw));

	reg = (ide_ioreg_t) data_port;

	for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++) {
		hw->io_ports[i] = reg;
		reg += regincr;
	}

	hw->io_ports[IDE_CONTROL_OFFSET] = (ide_ioreg_t) ctrl_port;
}

static __inline__ void
ide_init_default_hwifs(void)
{
	hw_regs_t hw;

	/* init the interface */
	ide_init_hwif_ports(&hw, 0x1f0, 0x3f6, NULL);
	hw.irq = IRQ_EINT1;
	ide_register_hw(&hw, NULL);
}

#endif				/* End ifndef CONFIG_PSIONW_REVO */
