ide-h8300.c 5.0 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 9 10
/*
 * H8/300 generic IDE interface
 */

#include <linux/init.h>
#include <linux/ide.h>

#include <asm/io.h>
#include <asm/irq.h>

11 12
#define DRV_NAME "ide-h8300"

L
Linus Torvalds 已提交
13 14 15 16 17 18 19 20 21 22 23 24
#define bswap(d) \
({					\
	u16 r;				\
	__asm__("mov.b %w1,r1h\n\t"	\
		"mov.b %x1,r1l\n\t"	\
		"mov.w r1,%0"		\
		:"=r"(r)		\
		:"r"(d)			\
		:"er1");		\
	(r);				\
})

25
static void h8300_tf_load(ide_drive_t *drive, struct ide_cmd *cmd)
26 27 28
{
	ide_hwif_t *hwif = drive->hwif;
	struct ide_io_ports *io_ports = &hwif->io_ports;
29 30
	struct ide_taskfile *tf = &cmd->tf;
	u8 HIHI = (cmd->tf_flags & IDE_TFLAG_LBA48) ? 0xE0 : 0xEF;
31

32
	if (cmd->ftf_flags & IDE_FTFLAG_FLAGGED)
33 34
		HIHI = 0xFF;

35
	if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_FEATURE)
36
		outb(tf->hob_feature, io_ports->feature_addr);
37
	if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_NSECT)
38
		outb(tf->hob_nsect, io_ports->nsect_addr);
39
	if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_LBAL)
40
		outb(tf->hob_lbal, io_ports->lbal_addr);
41
	if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_LBAM)
42
		outb(tf->hob_lbam, io_ports->lbam_addr);
43
	if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_LBAH)
44 45
		outb(tf->hob_lbah, io_ports->lbah_addr);

46
	if (cmd->tf_flags & IDE_TFLAG_OUT_FEATURE)
47
		outb(tf->feature, io_ports->feature_addr);
48
	if (cmd->tf_flags & IDE_TFLAG_OUT_NSECT)
49
		outb(tf->nsect, io_ports->nsect_addr);
50
	if (cmd->tf_flags & IDE_TFLAG_OUT_LBAL)
51
		outb(tf->lbal, io_ports->lbal_addr);
52
	if (cmd->tf_flags & IDE_TFLAG_OUT_LBAM)
53
		outb(tf->lbam, io_ports->lbam_addr);
54
	if (cmd->tf_flags & IDE_TFLAG_OUT_LBAH)
55 56
		outb(tf->lbah, io_ports->lbah_addr);

57
	if (cmd->tf_flags & IDE_TFLAG_OUT_DEVICE)
58
		outb((tf->device & HIHI) | drive->select,
59 60 61
		     io_ports->device_addr);
}

62
static void h8300_tf_read(ide_drive_t *drive, struct ide_cmd *cmd)
63 64 65
{
	ide_hwif_t *hwif = drive->hwif;
	struct ide_io_ports *io_ports = &hwif->io_ports;
66
	struct ide_taskfile *tf = &cmd->tf;
67 68

	/* be sure we're looking at the low order bits */
S
Sergei Shtylyov 已提交
69
	outb(ATA_DEVCTL_OBS, io_ports->ctl_addr);
70

71 72
	if (cmd->tf_flags & IDE_TFLAG_IN_ERROR)
		tf->error  = inb(io_ports->feature_addr);
73
	if (cmd->tf_flags & IDE_TFLAG_IN_NSECT)
74
		tf->nsect  = inb(io_ports->nsect_addr);
75
	if (cmd->tf_flags & IDE_TFLAG_IN_LBAL)
76
		tf->lbal   = inb(io_ports->lbal_addr);
77
	if (cmd->tf_flags & IDE_TFLAG_IN_LBAM)
78
		tf->lbam   = inb(io_ports->lbam_addr);
79
	if (cmd->tf_flags & IDE_TFLAG_IN_LBAH)
80
		tf->lbah   = inb(io_ports->lbah_addr);
81
	if (cmd->tf_flags & IDE_TFLAG_IN_DEVICE)
82 83
		tf->device = inb(io_ports->device_addr);

84
	if (cmd->tf_flags & IDE_TFLAG_LBA48) {
S
Sergei Shtylyov 已提交
85
		outb(ATA_HOB | ATA_DEVCTL_OBS, io_ports->ctl_addr);
86

87 88
		if (cmd->tf_flags & IDE_TFLAG_IN_HOB_ERROR)
			tf->hob_error = inb(io_ports->feature_addr);
89
		if (cmd->tf_flags & IDE_TFLAG_IN_HOB_NSECT)
90
			tf->hob_nsect = inb(io_ports->nsect_addr);
91
		if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAL)
92
			tf->hob_lbal  = inb(io_ports->lbal_addr);
93
		if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAM)
94
			tf->hob_lbam  = inb(io_ports->lbam_addr);
95
		if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAH)
96
			tf->hob_lbah  = inb(io_ports->lbah_addr);
97 98 99
	}
}

L
Linus Torvalds 已提交
100 101 102 103 104 105 106 107 108 109 110 111 112 113
static void mm_outsw(unsigned long addr, void *buf, u32 len)
{
	unsigned short *bp = (unsigned short *)buf;
	for (; len > 0; len--, bp++)
		*(volatile u16 *)addr = bswap(*bp);
}

static void mm_insw(unsigned long addr, void *buf, u32 len)
{
	unsigned short *bp = (unsigned short *)buf;
	for (; len > 0; len--, bp++)
		*bp = bswap(*(volatile u16 *)addr);
}

114
static void h8300_input_data(ide_drive_t *drive, struct ide_cmd *cmd,
115 116 117 118 119
			     void *buf, unsigned int len)
{
	mm_insw(drive->hwif->io_ports.data_addr, buf, (len + 1) / 2);
}

120
static void h8300_output_data(ide_drive_t *drive, struct ide_cmd *cmd,
121 122 123 124 125
			      void *buf, unsigned int len)
{
	mm_outsw(drive->hwif->io_ports.data_addr, buf, (len + 1) / 2);
}

126 127 128 129
static const struct ide_tp_ops h8300_tp_ops = {
	.exec_command		= ide_exec_command,
	.read_status		= ide_read_status,
	.read_altstatus		= ide_read_altstatus,
130
	.write_devctl		= ide_write_devctl,
131

132
	.dev_select		= ide_dev_select,
133 134 135 136 137 138 139
	.tf_load		= h8300_tf_load,
	.tf_read		= h8300_tf_read,

	.input_data		= h8300_input_data,
	.output_data		= h8300_output_data,
};

L
Linus Torvalds 已提交
140 141 142 143 144 145 146
#define H8300_IDE_GAP (2)

static inline void hw_setup(hw_regs_t *hw)
{
	int i;

	memset(hw, 0, sizeof(hw_regs_t));
147 148 149
	for (i = 0; i <= 7; i++)
		hw->io_ports_array[i] = CONFIG_H8300_IDE_BASE + H8300_IDE_GAP*i;
	hw->io_ports.ctl_addr = CONFIG_H8300_IDE_ALT;
L
Linus Torvalds 已提交
150 151 152 153
	hw->irq = EXT_IRQ0 + CONFIG_H8300_IDE_IRQ;
	hw->chipset = ide_generic;
}

154
static const struct ide_port_info h8300_port_info = {
155
	.tp_ops			= &h8300_tp_ops,
156 157 158
	.host_flags		= IDE_HFLAG_NO_IO_32BIT | IDE_HFLAG_NO_DMA,
};

159
static int __init h8300_ide_init(void)
L
Linus Torvalds 已提交
160
{
161
	hw_regs_t hw, *hws[] = { &hw, NULL, NULL, NULL };
L
Linus Torvalds 已提交
162

163 164
	printk(KERN_INFO DRV_NAME ": H8/300 generic IDE interface\n");

L
Linus Torvalds 已提交
165 166 167 168 169 170 171 172 173
	if (!request_region(CONFIG_H8300_IDE_BASE, H8300_IDE_GAP*8, "ide-h8300"))
		goto out_busy;
	if (!request_region(CONFIG_H8300_IDE_ALT, H8300_IDE_GAP, "ide-h8300")) {
		release_region(CONFIG_H8300_IDE_BASE, H8300_IDE_GAP*8);
		goto out_busy;
	}

	hw_setup(&hw);

174
	return ide_host_add(&h8300_port_info, hws, NULL);
L
Linus Torvalds 已提交
175 176 177

out_busy:
	printk(KERN_ERR "ide-h8300: IDE I/F resource already used.\n");
178 179

	return -EBUSY;
L
Linus Torvalds 已提交
180
}
181 182

module_init(h8300_ide_init);
183 184

MODULE_LICENSE("GPL");