ide: add IDE_HFLAG_MMIO host flag (take 2)
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / ide / mips / swarm.c
1 /*
2 * Copyright (C) 2001, 2002, 2003 Broadcom Corporation
3 * Copyright (C) 2004 MontaVista Software Inc.
4 * Author: Manish Lachwani, mlachwani@mvista.com
5 * Copyright (C) 2004 MIPS Technologies, Inc. All rights reserved.
6 * Author: Maciej W. Rozycki <macro@mips.com>
7 * Copyright (c) 2006 Maciej W. Rozycki
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 */
23
24 /*
25 * Derived loosely from ide-pmac.c, so:
26 * Copyright (C) 1998 Paul Mackerras.
27 * Copyright (C) 1995-1998 Mark Lord
28 */
29
30 /*
31 * Boards with SiByte processors so far have supported IDE devices via
32 * the Generic Bus, PCI bus, and built-in PCMCIA interface. In all
33 * cases, byte-swapping must be avoided for these devices (whereas
34 * other PCI devices, for example, will require swapping). Any
35 * SiByte-targetted kernel including IDE support will include this
36 * file. Probing of a Generic Bus for an IDE device is controlled by
37 * the definition of "SIBYTE_HAVE_IDE", which is provided by
38 * <asm/sibyte/board.h> for Broadcom boards.
39 */
40
41 #include <linux/ide.h>
42 #include <linux/ioport.h>
43 #include <linux/kernel.h>
44 #include <linux/types.h>
45 #include <linux/platform_device.h>
46
47 #include <asm/io.h>
48
49 #include <asm/sibyte/board.h>
50 #include <asm/sibyte/sb1250_genbus.h>
51 #include <asm/sibyte/sb1250_regs.h>
52
53 #define DRV_NAME "ide-swarm"
54
55 static char swarm_ide_string[] = DRV_NAME;
56
57 static struct resource swarm_ide_resource = {
58 .name = "SWARM GenBus IDE",
59 .flags = IORESOURCE_MEM,
60 };
61
62 static struct platform_device *swarm_ide_dev;
63
64 /*
65 * swarm_ide_probe - if the board header indicates the existence of
66 * Generic Bus IDE, allocate a HWIF for it.
67 */
68 static int __devinit swarm_ide_probe(struct device *dev)
69 {
70 ide_hwif_t *hwif;
71 u8 __iomem *base;
72 phys_t offset, size;
73 int i;
74 u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
75
76 if (!SIBYTE_HAVE_IDE)
77 return -ENODEV;
78
79 hwif = ide_find_port();
80 if (hwif == NULL) {
81 printk(KERN_ERR DRV_NAME ": no free slot for interface\n");
82 return -ENOMEM;
83 }
84
85 base = ioremap(A_IO_EXT_BASE, 0x800);
86 offset = __raw_readq(base + R_IO_EXT_REG(R_IO_EXT_START_ADDR, IDE_CS));
87 size = __raw_readq(base + R_IO_EXT_REG(R_IO_EXT_MULT_SIZE, IDE_CS));
88 iounmap(base);
89
90 offset = G_IO_START_ADDR(offset) << S_IO_ADDRBASE;
91 size = (G_IO_MULT_SIZE(size) + 1) << S_IO_REGSIZE;
92 if (offset < A_PHYS_GENBUS || offset >= A_PHYS_GENBUS_END) {
93 printk(KERN_INFO DRV_NAME
94 ": IDE interface at GenBus disabled\n");
95 return -EBUSY;
96 }
97
98 printk(KERN_INFO DRV_NAME ": IDE interface at GenBus slot %i\n",
99 IDE_CS);
100
101 swarm_ide_resource.start = offset;
102 swarm_ide_resource.end = offset + size - 1;
103 if (request_resource(&iomem_resource, &swarm_ide_resource)) {
104 printk(KERN_ERR DRV_NAME
105 ": can't request I/O memory resource\n");
106 return -EBUSY;
107 }
108
109 base = ioremap(offset, size);
110
111 /* Setup MMIO ops. */
112 hwif->host_flags = IDE_HFLAG_MMIO;
113 default_hwif_mmiops(hwif);
114
115 hwif->chipset = ide_generic;
116
117 for (i = 0; i <= 7; i++)
118 hwif->io_ports_array[i] =
119 (unsigned long)(base + ((0x1f0 + i) << 5));
120 hwif->io_ports.ctl_addr =
121 (unsigned long)(base + (0x3f6 << 5));
122 hwif->irq = K_INT_GB_IDE;
123
124 idx[0] = hwif->index;
125
126 ide_device_add(idx, NULL);
127
128 dev_set_drvdata(dev, hwif);
129
130 return 0;
131 }
132
133 static struct device_driver swarm_ide_driver = {
134 .name = swarm_ide_string,
135 .bus = &platform_bus_type,
136 .probe = swarm_ide_probe,
137 };
138
139 static void swarm_ide_platform_release(struct device *device)
140 {
141 struct platform_device *pldev;
142
143 /* free device */
144 pldev = to_platform_device(device);
145 kfree(pldev);
146 }
147
148 static int __devinit swarm_ide_init_module(void)
149 {
150 struct platform_device *pldev;
151 int err;
152
153 printk(KERN_INFO "SWARM IDE driver\n");
154
155 if (driver_register(&swarm_ide_driver)) {
156 printk(KERN_ERR "Driver registration failed\n");
157 err = -ENODEV;
158 goto out;
159 }
160
161 if (!(pldev = kzalloc(sizeof (*pldev), GFP_KERNEL))) {
162 err = -ENOMEM;
163 goto out_unregister_driver;
164 }
165
166 pldev->name = swarm_ide_string;
167 pldev->id = 0;
168 pldev->dev.release = swarm_ide_platform_release;
169
170 if (platform_device_register(pldev)) {
171 err = -ENODEV;
172 goto out_free_pldev;
173 }
174
175 if (!pldev->dev.driver) {
176 /*
177 * The driver was not bound to this device, there was
178 * no hardware at this address. Unregister it, as the
179 * release fuction will take care of freeing the
180 * allocated structure
181 */
182 platform_device_unregister (pldev);
183 }
184
185 swarm_ide_dev = pldev;
186
187 return 0;
188
189 out_free_pldev:
190 kfree(pldev);
191
192 out_unregister_driver:
193 driver_unregister(&swarm_ide_driver);
194 out:
195 return err;
196 }
197
198 module_init(swarm_ide_init_module);