blob: 52fee3d2771a7ce7bfdb95592e44b898d9288417 [file] [log] [blame]
Ralf Baechle4237f222005-11-17 16:23:50 +00001/*
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>
Maciej W. Rozycki4d4423c2008-05-14 23:06:14 +02007 * Copyright (c) 2006, 2008 Maciej W. Rozycki
Ralf Baechle4237f222005-11-17 16:23:50 +00008 *
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
55static char swarm_ide_string[] = DRV_NAME;
56
57static struct resource swarm_ide_resource = {
58 .name = "SWARM GenBus IDE",
59 .flags = IORESOURCE_MEM,
60};
61
62static 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 */
68static int __devinit swarm_ide_probe(struct device *dev)
69{
70 ide_hwif_t *hwif;
71 u8 __iomem *base;
72 phys_t offset, size;
Maciej W. Rozycki4d4423c2008-05-14 23:06:14 +020073 hw_regs_t hw;
Ralf Baechle4237f222005-11-17 16:23:50 +000074 int i;
Maciej W. Rozycki4d4423c2008-05-14 23:06:14 +020075 u8 idx[] = { 0xff, 0xff, 0xff, 0xff };
Ralf Baechle4237f222005-11-17 16:23:50 +000076
77 if (!SIBYTE_HAVE_IDE)
78 return -ENODEV;
79
Bartlomiej Zolnierkiewicz7d9f3d52008-04-26 17:36:32 +020080 hwif = ide_find_port();
81 if (hwif == NULL) {
Ralf Baechle4237f222005-11-17 16:23:50 +000082 printk(KERN_ERR DRV_NAME ": no free slot for interface\n");
83 return -ENOMEM;
84 }
85
Ralf Baechle4237f222005-11-17 16:23:50 +000086 base = ioremap(A_IO_EXT_BASE, 0x800);
87 offset = __raw_readq(base + R_IO_EXT_REG(R_IO_EXT_START_ADDR, IDE_CS));
88 size = __raw_readq(base + R_IO_EXT_REG(R_IO_EXT_MULT_SIZE, IDE_CS));
89 iounmap(base);
90
91 offset = G_IO_START_ADDR(offset) << S_IO_ADDRBASE;
92 size = (G_IO_MULT_SIZE(size) + 1) << S_IO_REGSIZE;
93 if (offset < A_PHYS_GENBUS || offset >= A_PHYS_GENBUS_END) {
94 printk(KERN_INFO DRV_NAME
95 ": IDE interface at GenBus disabled\n");
96 return -EBUSY;
97 }
98
99 printk(KERN_INFO DRV_NAME ": IDE interface at GenBus slot %i\n",
100 IDE_CS);
101
102 swarm_ide_resource.start = offset;
103 swarm_ide_resource.end = offset + size - 1;
104 if (request_resource(&iomem_resource, &swarm_ide_resource)) {
105 printk(KERN_ERR DRV_NAME
106 ": can't request I/O memory resource\n");
107 return -EBUSY;
108 }
109
110 base = ioremap(offset, size);
111
112 /* Setup MMIO ops. */
Bartlomiej Zolnierkiewiczc5dd43e2008-04-28 23:44:37 +0200113 hwif->host_flags = IDE_HFLAG_MMIO;
Ralf Baechle4237f222005-11-17 16:23:50 +0000114 default_hwif_mmiops(hwif);
Bartlomiej Zolnierkiewicz3dd89a92008-04-26 22:25:19 +0200115
Bartlomiej Zolnierkiewicz4c3032d2008-04-27 15:38:32 +0200116 for (i = 0; i <= 7; i++)
Maciej W. Rozycki4d4423c2008-05-14 23:06:14 +0200117 hw.io_ports_array[i] =
Ralf Baechle4237f222005-11-17 16:23:50 +0000118 (unsigned long)(base + ((0x1f0 + i) << 5));
Maciej W. Rozycki4d4423c2008-05-14 23:06:14 +0200119 hw.io_ports.ctl_addr =
Ralf Baechle4237f222005-11-17 16:23:50 +0000120 (unsigned long)(base + (0x3f6 << 5));
Maciej W. Rozycki4d4423c2008-05-14 23:06:14 +0200121 hw.irq = K_INT_GB_IDE;
122 hw.chipset = ide_generic;
123
124 ide_init_port_hw(hwif, &hw);
Ralf Baechle4237f222005-11-17 16:23:50 +0000125
Bartlomiej Zolnierkiewicz8447d9d2007-10-20 00:32:31 +0200126 idx[0] = hwif->index;
Bartlomiej Zolnierkiewicz5cbf79c2007-05-10 00:01:11 +0200127
Bartlomiej Zolnierkiewiczc413b9b2008-02-02 19:56:31 +0100128 ide_device_add(idx, NULL);
Bartlomiej Zolnierkiewicz5cbf79c2007-05-10 00:01:11 +0200129
Ralf Baechle4237f222005-11-17 16:23:50 +0000130 dev_set_drvdata(dev, hwif);
131
132 return 0;
133}
134
135static struct device_driver swarm_ide_driver = {
136 .name = swarm_ide_string,
137 .bus = &platform_bus_type,
138 .probe = swarm_ide_probe,
139};
140
141static void swarm_ide_platform_release(struct device *device)
142{
143 struct platform_device *pldev;
144
145 /* free device */
146 pldev = to_platform_device(device);
147 kfree(pldev);
148}
149
150static int __devinit swarm_ide_init_module(void)
151{
152 struct platform_device *pldev;
153 int err;
154
155 printk(KERN_INFO "SWARM IDE driver\n");
156
157 if (driver_register(&swarm_ide_driver)) {
158 printk(KERN_ERR "Driver registration failed\n");
159 err = -ENODEV;
160 goto out;
161 }
162
Yoann Padioleaudd00cc42007-07-19 01:49:03 -0700163 if (!(pldev = kzalloc(sizeof (*pldev), GFP_KERNEL))) {
Ralf Baechle4237f222005-11-17 16:23:50 +0000164 err = -ENOMEM;
165 goto out_unregister_driver;
166 }
167
Ralf Baechle4237f222005-11-17 16:23:50 +0000168 pldev->name = swarm_ide_string;
169 pldev->id = 0;
170 pldev->dev.release = swarm_ide_platform_release;
171
172 if (platform_device_register(pldev)) {
173 err = -ENODEV;
174 goto out_free_pldev;
175 }
176
177 if (!pldev->dev.driver) {
178 /*
179 * The driver was not bound to this device, there was
180 * no hardware at this address. Unregister it, as the
181 * release fuction will take care of freeing the
182 * allocated structure
183 */
184 platform_device_unregister (pldev);
185 }
186
187 swarm_ide_dev = pldev;
188
189 return 0;
190
191out_free_pldev:
192 kfree(pldev);
193
194out_unregister_driver:
195 driver_unregister(&swarm_ide_driver);
196out:
197 return err;
198}
199
200module_init(swarm_ide_init_module);