2 * H8/300 generic IDE interface
5 #include <linux/init.h>
11 #define DRV_NAME "ide-h8300"
16 __asm__("mov.b %w1,r1h\n\t" \
25 static void mm_outw(u16 d
, unsigned long a
)
27 __asm__("mov.b %w0,r2h\n\t"
35 static u16
mm_inw(unsigned long a
)
37 register u16 r
__asm__("er0");
38 __asm__("mov.w @%1,r2\n\t"
47 static void h8300_tf_load(ide_drive_t
*drive
, struct ide_cmd
*cmd
)
49 ide_hwif_t
*hwif
= drive
->hwif
;
50 struct ide_io_ports
*io_ports
= &hwif
->io_ports
;
51 struct ide_taskfile
*tf
= &cmd
->tf
;
52 u8 HIHI
= (cmd
->tf_flags
& IDE_TFLAG_LBA48
) ? 0xE0 : 0xEF;
54 if (cmd
->ftf_flags
& IDE_FTFLAG_FLAGGED
)
57 if (cmd
->tf_flags
& IDE_TFLAG_OUT_HOB_FEATURE
)
58 outb(tf
->hob_feature
, io_ports
->feature_addr
);
59 if (cmd
->tf_flags
& IDE_TFLAG_OUT_HOB_NSECT
)
60 outb(tf
->hob_nsect
, io_ports
->nsect_addr
);
61 if (cmd
->tf_flags
& IDE_TFLAG_OUT_HOB_LBAL
)
62 outb(tf
->hob_lbal
, io_ports
->lbal_addr
);
63 if (cmd
->tf_flags
& IDE_TFLAG_OUT_HOB_LBAM
)
64 outb(tf
->hob_lbam
, io_ports
->lbam_addr
);
65 if (cmd
->tf_flags
& IDE_TFLAG_OUT_HOB_LBAH
)
66 outb(tf
->hob_lbah
, io_ports
->lbah_addr
);
68 if (cmd
->tf_flags
& IDE_TFLAG_OUT_FEATURE
)
69 outb(tf
->feature
, io_ports
->feature_addr
);
70 if (cmd
->tf_flags
& IDE_TFLAG_OUT_NSECT
)
71 outb(tf
->nsect
, io_ports
->nsect_addr
);
72 if (cmd
->tf_flags
& IDE_TFLAG_OUT_LBAL
)
73 outb(tf
->lbal
, io_ports
->lbal_addr
);
74 if (cmd
->tf_flags
& IDE_TFLAG_OUT_LBAM
)
75 outb(tf
->lbam
, io_ports
->lbam_addr
);
76 if (cmd
->tf_flags
& IDE_TFLAG_OUT_LBAH
)
77 outb(tf
->lbah
, io_ports
->lbah_addr
);
79 if (cmd
->tf_flags
& IDE_TFLAG_OUT_DEVICE
)
80 outb((tf
->device
& HIHI
) | drive
->select
,
81 io_ports
->device_addr
);
84 static void h8300_tf_read(ide_drive_t
*drive
, struct ide_cmd
*cmd
)
86 ide_hwif_t
*hwif
= drive
->hwif
;
87 struct ide_io_ports
*io_ports
= &hwif
->io_ports
;
88 struct ide_taskfile
*tf
= &cmd
->tf
;
90 /* be sure we're looking at the low order bits */
91 outb(ATA_DEVCTL_OBS
, io_ports
->ctl_addr
);
93 if (cmd
->tf_flags
& IDE_TFLAG_IN_ERROR
)
94 tf
->error
= inb(io_ports
->feature_addr
);
95 if (cmd
->tf_flags
& IDE_TFLAG_IN_NSECT
)
96 tf
->nsect
= inb(io_ports
->nsect_addr
);
97 if (cmd
->tf_flags
& IDE_TFLAG_IN_LBAL
)
98 tf
->lbal
= inb(io_ports
->lbal_addr
);
99 if (cmd
->tf_flags
& IDE_TFLAG_IN_LBAM
)
100 tf
->lbam
= inb(io_ports
->lbam_addr
);
101 if (cmd
->tf_flags
& IDE_TFLAG_IN_LBAH
)
102 tf
->lbah
= inb(io_ports
->lbah_addr
);
103 if (cmd
->tf_flags
& IDE_TFLAG_IN_DEVICE
)
104 tf
->device
= inb(io_ports
->device_addr
);
106 if (cmd
->tf_flags
& IDE_TFLAG_LBA48
) {
107 outb(ATA_HOB
| ATA_DEVCTL_OBS
, io_ports
->ctl_addr
);
109 if (cmd
->tf_flags
& IDE_TFLAG_IN_HOB_ERROR
)
110 tf
->hob_error
= inb(io_ports
->feature_addr
);
111 if (cmd
->tf_flags
& IDE_TFLAG_IN_HOB_NSECT
)
112 tf
->hob_nsect
= inb(io_ports
->nsect_addr
);
113 if (cmd
->tf_flags
& IDE_TFLAG_IN_HOB_LBAL
)
114 tf
->hob_lbal
= inb(io_ports
->lbal_addr
);
115 if (cmd
->tf_flags
& IDE_TFLAG_IN_HOB_LBAM
)
116 tf
->hob_lbam
= inb(io_ports
->lbam_addr
);
117 if (cmd
->tf_flags
& IDE_TFLAG_IN_HOB_LBAH
)
118 tf
->hob_lbah
= inb(io_ports
->lbah_addr
);
122 static void mm_outsw(unsigned long addr
, void *buf
, u32 len
)
124 unsigned short *bp
= (unsigned short *)buf
;
125 for (; len
> 0; len
--, bp
++)
126 *(volatile u16
*)addr
= bswap(*bp
);
129 static void mm_insw(unsigned long addr
, void *buf
, u32 len
)
131 unsigned short *bp
= (unsigned short *)buf
;
132 for (; len
> 0; len
--, bp
++)
133 *bp
= bswap(*(volatile u16
*)addr
);
136 static void h8300_input_data(ide_drive_t
*drive
, struct ide_cmd
*cmd
,
137 void *buf
, unsigned int len
)
139 mm_insw(drive
->hwif
->io_ports
.data_addr
, buf
, (len
+ 1) / 2);
142 static void h8300_output_data(ide_drive_t
*drive
, struct ide_cmd
*cmd
,
143 void *buf
, unsigned int len
)
145 mm_outsw(drive
->hwif
->io_ports
.data_addr
, buf
, (len
+ 1) / 2);
148 static const struct ide_tp_ops h8300_tp_ops
= {
149 .exec_command
= ide_exec_command
,
150 .read_status
= ide_read_status
,
151 .read_altstatus
= ide_read_altstatus
,
152 .write_devctl
= ide_write_devctl
,
154 .dev_select
= ide_dev_select
,
155 .tf_load
= h8300_tf_load
,
156 .tf_read
= h8300_tf_read
,
158 .input_data
= h8300_input_data
,
159 .output_data
= h8300_output_data
,
162 #define H8300_IDE_GAP (2)
164 static inline void hw_setup(hw_regs_t
*hw
)
168 memset(hw
, 0, sizeof(hw_regs_t
));
169 for (i
= 0; i
<= 7; i
++)
170 hw
->io_ports_array
[i
] = CONFIG_H8300_IDE_BASE
+ H8300_IDE_GAP
*i
;
171 hw
->io_ports
.ctl_addr
= CONFIG_H8300_IDE_ALT
;
172 hw
->irq
= EXT_IRQ0
+ CONFIG_H8300_IDE_IRQ
;
173 hw
->chipset
= ide_generic
;
176 static const struct ide_port_info h8300_port_info
= {
177 .tp_ops
= &h8300_tp_ops
,
178 .host_flags
= IDE_HFLAG_NO_IO_32BIT
| IDE_HFLAG_NO_DMA
,
181 static int __init
h8300_ide_init(void)
183 hw_regs_t hw
, *hws
[] = { &hw
, NULL
, NULL
, NULL
};
185 printk(KERN_INFO DRV_NAME
": H8/300 generic IDE interface\n");
187 if (!request_region(CONFIG_H8300_IDE_BASE
, H8300_IDE_GAP
*8, "ide-h8300"))
189 if (!request_region(CONFIG_H8300_IDE_ALT
, H8300_IDE_GAP
, "ide-h8300")) {
190 release_region(CONFIG_H8300_IDE_BASE
, H8300_IDE_GAP
*8);
196 return ide_host_add(&h8300_port_info
, hws
, NULL
);
199 printk(KERN_ERR
"ide-h8300: IDE I/F resource already used.\n");
204 module_init(h8300_ide_init
);
206 MODULE_LICENSE("GPL");