| Ralf Baechle | 4237f22 | 2005-11-17 16:23:50 +0000 | [diff] [blame] | 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> | 
| Maciej W. Rozycki | 45e02b5 | 2006-10-06 00:44:02 -0700 | [diff] [blame] | 7 | * Copyright (c) 2006  Maciej W. Rozycki | 
| Ralf Baechle | 4237f22 | 2005-11-17 16:23:50 +0000 | [diff] [blame] | 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 |  | 
|  | 75 | if (!SIBYTE_HAVE_IDE) | 
|  | 76 | return -ENODEV; | 
|  | 77 |  | 
|  | 78 | /* Find an empty slot.  */ | 
|  | 79 | for (i = 0; i < MAX_HWIFS; i++) | 
|  | 80 | if (!ide_hwifs[i].io_ports[IDE_DATA_OFFSET]) | 
|  | 81 | break; | 
|  | 82 | if (i >= MAX_HWIFS) { | 
|  | 83 | printk(KERN_ERR DRV_NAME ": no free slot for interface\n"); | 
|  | 84 | return -ENOMEM; | 
|  | 85 | } | 
|  | 86 |  | 
|  | 87 | hwif = ide_hwifs + i; | 
|  | 88 |  | 
|  | 89 | base = ioremap(A_IO_EXT_BASE, 0x800); | 
|  | 90 | offset = __raw_readq(base + R_IO_EXT_REG(R_IO_EXT_START_ADDR, IDE_CS)); | 
|  | 91 | size = __raw_readq(base + R_IO_EXT_REG(R_IO_EXT_MULT_SIZE, IDE_CS)); | 
|  | 92 | iounmap(base); | 
|  | 93 |  | 
|  | 94 | offset = G_IO_START_ADDR(offset) << S_IO_ADDRBASE; | 
|  | 95 | size = (G_IO_MULT_SIZE(size) + 1) << S_IO_REGSIZE; | 
|  | 96 | if (offset < A_PHYS_GENBUS || offset >= A_PHYS_GENBUS_END) { | 
|  | 97 | printk(KERN_INFO DRV_NAME | 
|  | 98 | ": IDE interface at GenBus disabled\n"); | 
|  | 99 | return -EBUSY; | 
|  | 100 | } | 
|  | 101 |  | 
|  | 102 | printk(KERN_INFO DRV_NAME ": IDE interface at GenBus slot %i\n", | 
|  | 103 | IDE_CS); | 
|  | 104 |  | 
|  | 105 | swarm_ide_resource.start = offset; | 
|  | 106 | swarm_ide_resource.end = offset + size - 1; | 
|  | 107 | if (request_resource(&iomem_resource, &swarm_ide_resource)) { | 
|  | 108 | printk(KERN_ERR DRV_NAME | 
|  | 109 | ": can't request I/O memory resource\n"); | 
|  | 110 | return -EBUSY; | 
|  | 111 | } | 
|  | 112 |  | 
|  | 113 | base = ioremap(offset, size); | 
|  | 114 |  | 
|  | 115 | /* Setup MMIO ops.  */ | 
|  | 116 | default_hwif_mmiops(hwif); | 
|  | 117 | /* Prevent resource map manipulation.  */ | 
| Bartlomiej Zolnierkiewicz | 2ad1e55 | 2007-02-17 02:40:25 +0100 | [diff] [blame] | 118 | hwif->mmio = 1; | 
| Ralf Baechle | 4237f22 | 2005-11-17 16:23:50 +0000 | [diff] [blame] | 119 | hwif->noprobe = 0; | 
|  | 120 |  | 
|  | 121 | for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++) | 
|  | 122 | hwif->hw.io_ports[i] = | 
|  | 123 | (unsigned long)(base + ((0x1f0 + i) << 5)); | 
|  | 124 | hwif->hw.io_ports[IDE_CONTROL_OFFSET] = | 
|  | 125 | (unsigned long)(base + (0x3f6 << 5)); | 
|  | 126 | hwif->hw.irq = K_INT_GB_IDE; | 
|  | 127 |  | 
|  | 128 | memcpy(hwif->io_ports, hwif->hw.io_ports, sizeof(hwif->io_ports)); | 
|  | 129 | hwif->irq = hwif->hw.irq; | 
|  | 130 |  | 
| Maciej W. Rozycki | 45e02b5 | 2006-10-06 00:44:02 -0700 | [diff] [blame] | 131 | probe_hwif_init(hwif); | 
| Ralf Baechle | 4237f22 | 2005-11-17 16:23:50 +0000 | [diff] [blame] | 132 | dev_set_drvdata(dev, hwif); | 
|  | 133 |  | 
|  | 134 | return 0; | 
|  | 135 | } | 
|  | 136 |  | 
|  | 137 | static struct device_driver swarm_ide_driver = { | 
|  | 138 | .name	= swarm_ide_string, | 
|  | 139 | .bus	= &platform_bus_type, | 
|  | 140 | .probe	= swarm_ide_probe, | 
|  | 141 | }; | 
|  | 142 |  | 
|  | 143 | static void swarm_ide_platform_release(struct device *device) | 
|  | 144 | { | 
|  | 145 | struct platform_device *pldev; | 
|  | 146 |  | 
|  | 147 | /* free device */ | 
|  | 148 | pldev = to_platform_device(device); | 
|  | 149 | kfree(pldev); | 
|  | 150 | } | 
|  | 151 |  | 
|  | 152 | static int __devinit swarm_ide_init_module(void) | 
|  | 153 | { | 
|  | 154 | struct platform_device *pldev; | 
|  | 155 | int err; | 
|  | 156 |  | 
|  | 157 | printk(KERN_INFO "SWARM IDE driver\n"); | 
|  | 158 |  | 
|  | 159 | if (driver_register(&swarm_ide_driver)) { | 
|  | 160 | printk(KERN_ERR "Driver registration failed\n"); | 
|  | 161 | err = -ENODEV; | 
|  | 162 | goto out; | 
|  | 163 | } | 
|  | 164 |  | 
|  | 165 | if (!(pldev = kmalloc(sizeof (*pldev), GFP_KERNEL))) { | 
|  | 166 | err = -ENOMEM; | 
|  | 167 | goto out_unregister_driver; | 
|  | 168 | } | 
|  | 169 |  | 
|  | 170 | memset (pldev, 0, sizeof (*pldev)); | 
|  | 171 | pldev->name		= swarm_ide_string; | 
|  | 172 | pldev->id		= 0; | 
|  | 173 | pldev->dev.release	= swarm_ide_platform_release; | 
|  | 174 |  | 
|  | 175 | if (platform_device_register(pldev)) { | 
|  | 176 | err = -ENODEV; | 
|  | 177 | goto out_free_pldev; | 
|  | 178 | } | 
|  | 179 |  | 
|  | 180 | if (!pldev->dev.driver) { | 
|  | 181 | /* | 
|  | 182 | * The driver was not bound to this device, there was | 
|  | 183 | * no hardware at this address. Unregister it, as the | 
|  | 184 | * release fuction will take care of freeing the | 
|  | 185 | * allocated structure | 
|  | 186 | */ | 
|  | 187 | platform_device_unregister (pldev); | 
|  | 188 | } | 
|  | 189 |  | 
|  | 190 | swarm_ide_dev = pldev; | 
|  | 191 |  | 
|  | 192 | return 0; | 
|  | 193 |  | 
|  | 194 | out_free_pldev: | 
|  | 195 | kfree(pldev); | 
|  | 196 |  | 
|  | 197 | out_unregister_driver: | 
|  | 198 | driver_unregister(&swarm_ide_driver); | 
|  | 199 | out: | 
|  | 200 | return err; | 
|  | 201 | } | 
|  | 202 |  | 
|  | 203 | module_init(swarm_ide_init_module); |