blob: 0b5fabe2806d12f9b5b6017ff45f8331244c0a74 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * H8/300 generic IDE interface
3 */
4
5#include <linux/init.h>
6#include <linux/ide.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07007
8#include <asm/io.h>
9#include <asm/irq.h>
10
Bartlomiej Zolnierkiewiczeb3aff52008-07-16 20:33:42 +020011#define DRV_NAME "ide-h8300"
12
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#define bswap(d) \
14({ \
15 u16 r; \
16 __asm__("mov.b %w1,r1h\n\t" \
17 "mov.b %x1,r1l\n\t" \
18 "mov.w r1,%0" \
19 :"=r"(r) \
20 :"r"(d) \
21 :"er1"); \
22 (r); \
23})
24
Linus Torvalds1da177e2005-04-16 15:20:36 -070025static void mm_outsw(unsigned long addr, void *buf, u32 len)
26{
27 unsigned short *bp = (unsigned short *)buf;
28 for (; len > 0; len--, bp++)
29 *(volatile u16 *)addr = bswap(*bp);
30}
31
32static void mm_insw(unsigned long addr, void *buf, u32 len)
33{
34 unsigned short *bp = (unsigned short *)buf;
35 for (; len > 0; len--, bp++)
36 *bp = bswap(*(volatile u16 *)addr);
37}
38
Bartlomiej Zolnierkiewiczadb1af92009-03-27 12:46:38 +010039static void h8300_input_data(ide_drive_t *drive, struct ide_cmd *cmd,
Bartlomiej Zolnierkiewiczf04ff9c2008-04-28 23:44:37 +020040 void *buf, unsigned int len)
41{
42 mm_insw(drive->hwif->io_ports.data_addr, buf, (len + 1) / 2);
43}
44
Bartlomiej Zolnierkiewiczadb1af92009-03-27 12:46:38 +010045static void h8300_output_data(ide_drive_t *drive, struct ide_cmd *cmd,
Bartlomiej Zolnierkiewiczf04ff9c2008-04-28 23:44:37 +020046 void *buf, unsigned int len)
47{
48 mm_outsw(drive->hwif->io_ports.data_addr, buf, (len + 1) / 2);
49}
50
Bartlomiej Zolnierkiewicz374e0422008-07-23 19:55:56 +020051static const struct ide_tp_ops h8300_tp_ops = {
52 .exec_command = ide_exec_command,
53 .read_status = ide_read_status,
54 .read_altstatus = ide_read_altstatus,
Sergei Shtylyovecf3a312009-03-31 20:15:30 +020055 .write_devctl = ide_write_devctl,
Bartlomiej Zolnierkiewicz374e0422008-07-23 19:55:56 +020056
Sergei Shtylyovabb596b2009-03-31 20:15:32 +020057 .dev_select = ide_dev_select,
Sergei Shtylyovcfd30da2009-04-08 14:12:51 +020058 .tf_load = ide_tf_load,
59 .tf_read = ide_tf_read,
Bartlomiej Zolnierkiewicz374e0422008-07-23 19:55:56 +020060
61 .input_data = h8300_input_data,
62 .output_data = h8300_output_data,
63};
64
Linus Torvalds1da177e2005-04-16 15:20:36 -070065#define H8300_IDE_GAP (2)
66
67static inline void hw_setup(hw_regs_t *hw)
68{
69 int i;
70
71 memset(hw, 0, sizeof(hw_regs_t));
Bartlomiej Zolnierkiewicz4c3032d2008-04-27 15:38:32 +020072 for (i = 0; i <= 7; i++)
73 hw->io_ports_array[i] = CONFIG_H8300_IDE_BASE + H8300_IDE_GAP*i;
74 hw->io_ports.ctl_addr = CONFIG_H8300_IDE_ALT;
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 hw->irq = EXT_IRQ0 + CONFIG_H8300_IDE_IRQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076}
77
Bartlomiej Zolnierkiewiczf81eb802008-07-16 20:33:42 +020078static const struct ide_port_info h8300_port_info = {
Bartlomiej Zolnierkiewicz374e0422008-07-23 19:55:56 +020079 .tp_ops = &h8300_tp_ops,
Bartlomiej Zolnierkiewiczf81eb802008-07-16 20:33:42 +020080 .host_flags = IDE_HFLAG_NO_IO_32BIT | IDE_HFLAG_NO_DMA,
Bartlomiej Zolnierkiewicz29e52cf2009-05-17 19:12:22 +020081 .chipset = ide_generic,
Bartlomiej Zolnierkiewiczf81eb802008-07-16 20:33:42 +020082};
83
Bartlomiej Zolnierkiewiczade2daf2008-01-26 20:13:07 +010084static int __init h8300_ide_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070085{
Bartlomiej Zolnierkiewiczdca39832009-05-17 19:12:24 +020086 hw_regs_t hw, *hws[] = { &hw };
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
Bartlomiej Zolnierkiewicz740c3972008-07-16 20:33:43 +020088 printk(KERN_INFO DRV_NAME ": H8/300 generic IDE interface\n");
89
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 if (!request_region(CONFIG_H8300_IDE_BASE, H8300_IDE_GAP*8, "ide-h8300"))
91 goto out_busy;
92 if (!request_region(CONFIG_H8300_IDE_ALT, H8300_IDE_GAP, "ide-h8300")) {
93 release_region(CONFIG_H8300_IDE_BASE, H8300_IDE_GAP*8);
94 goto out_busy;
95 }
96
97 hw_setup(&hw);
98
Bartlomiej Zolnierkiewiczdca39832009-05-17 19:12:24 +020099 return ide_host_add(&h8300_port_info, hws, 1, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100
101out_busy:
102 printk(KERN_ERR "ide-h8300: IDE I/F resource already used.\n");
Bartlomiej Zolnierkiewiczade2daf2008-01-26 20:13:07 +0100103
104 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105}
Bartlomiej Zolnierkiewiczade2daf2008-01-26 20:13:07 +0100106
107module_init(h8300_ide_init);
Adrian Bunkf95dc322008-04-02 21:22:03 +0200108
109MODULE_LICENSE("GPL");