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 | 4d4423c | 2008-05-14 23:06:14 +0200 | [diff] [blame] | 7 | * Copyright (c) 2006, 2008 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 | |
Bartlomiej Zolnierkiewicz | e48905e | 2008-07-16 20:33:41 +0200 | [diff] [blame] | 64 | static const struct ide_port_info swarm_port_info = { |
Bartlomiej Zolnierkiewicz | eb3aff5 | 2008-07-16 20:33:42 +0200 | [diff] [blame] | 65 | .name = DRV_NAME, |
Bartlomiej Zolnierkiewicz | e48905e | 2008-07-16 20:33:41 +0200 | [diff] [blame] | 66 | .host_flags = IDE_HFLAG_MMIO | IDE_HFLAG_NO_DMA, |
| 67 | }; |
| 68 | |
Ralf Baechle | 4237f22 | 2005-11-17 16:23:50 +0000 | [diff] [blame] | 69 | /* |
| 70 | * swarm_ide_probe - if the board header indicates the existence of |
| 71 | * Generic Bus IDE, allocate a HWIF for it. |
| 72 | */ |
| 73 | static int __devinit swarm_ide_probe(struct device *dev) |
| 74 | { |
Ralf Baechle | 4237f22 | 2005-11-17 16:23:50 +0000 | [diff] [blame] | 75 | u8 __iomem *base; |
Bartlomiej Zolnierkiewicz | 48c3c10 | 2008-07-23 19:55:57 +0200 | [diff] [blame] | 76 | struct ide_host *host; |
Ralf Baechle | 4237f22 | 2005-11-17 16:23:50 +0000 | [diff] [blame] | 77 | phys_t offset, size; |
Bartlomiej Zolnierkiewicz | 6f904d0 | 2008-07-23 19:55:57 +0200 | [diff] [blame] | 78 | int i, rc; |
Bartlomiej Zolnierkiewicz | c97c6ac | 2008-07-23 19:55:50 +0200 | [diff] [blame] | 79 | hw_regs_t hw, *hws[] = { &hw, NULL, NULL, NULL }; |
Ralf Baechle | 4237f22 | 2005-11-17 16:23:50 +0000 | [diff] [blame] | 80 | |
| 81 | if (!SIBYTE_HAVE_IDE) |
| 82 | return -ENODEV; |
| 83 | |
Ralf Baechle | 4237f22 | 2005-11-17 16:23:50 +0000 | [diff] [blame] | 84 | base = ioremap(A_IO_EXT_BASE, 0x800); |
| 85 | offset = __raw_readq(base + R_IO_EXT_REG(R_IO_EXT_START_ADDR, IDE_CS)); |
| 86 | size = __raw_readq(base + R_IO_EXT_REG(R_IO_EXT_MULT_SIZE, IDE_CS)); |
| 87 | iounmap(base); |
| 88 | |
| 89 | offset = G_IO_START_ADDR(offset) << S_IO_ADDRBASE; |
| 90 | size = (G_IO_MULT_SIZE(size) + 1) << S_IO_REGSIZE; |
| 91 | if (offset < A_PHYS_GENBUS || offset >= A_PHYS_GENBUS_END) { |
| 92 | printk(KERN_INFO DRV_NAME |
| 93 | ": IDE interface at GenBus disabled\n"); |
| 94 | return -EBUSY; |
| 95 | } |
| 96 | |
| 97 | printk(KERN_INFO DRV_NAME ": IDE interface at GenBus slot %i\n", |
| 98 | IDE_CS); |
| 99 | |
| 100 | swarm_ide_resource.start = offset; |
| 101 | swarm_ide_resource.end = offset + size - 1; |
| 102 | if (request_resource(&iomem_resource, &swarm_ide_resource)) { |
| 103 | printk(KERN_ERR DRV_NAME |
| 104 | ": can't request I/O memory resource\n"); |
| 105 | return -EBUSY; |
| 106 | } |
| 107 | |
| 108 | base = ioremap(offset, size); |
| 109 | |
Bartlomiej Zolnierkiewicz | 4c3032d | 2008-04-27 15:38:32 +0200 | [diff] [blame] | 110 | for (i = 0; i <= 7; i++) |
Maciej W. Rozycki | 4d4423c | 2008-05-14 23:06:14 +0200 | [diff] [blame] | 111 | hw.io_ports_array[i] = |
Ralf Baechle | 4237f22 | 2005-11-17 16:23:50 +0000 | [diff] [blame] | 112 | (unsigned long)(base + ((0x1f0 + i) << 5)); |
Maciej W. Rozycki | 4d4423c | 2008-05-14 23:06:14 +0200 | [diff] [blame] | 113 | hw.io_ports.ctl_addr = |
Ralf Baechle | 4237f22 | 2005-11-17 16:23:50 +0000 | [diff] [blame] | 114 | (unsigned long)(base + (0x3f6 << 5)); |
Maciej W. Rozycki | 4d4423c | 2008-05-14 23:06:14 +0200 | [diff] [blame] | 115 | hw.irq = K_INT_GB_IDE; |
| 116 | hw.chipset = ide_generic; |
| 117 | |
Bartlomiej Zolnierkiewicz | 6f904d0 | 2008-07-23 19:55:57 +0200 | [diff] [blame] | 118 | rc = ide_host_add(&swarm_port_info, hws, &host); |
| 119 | if (rc) |
Bartlomiej Zolnierkiewicz | cb8ea09 | 2008-07-16 20:33:44 +0200 | [diff] [blame] | 120 | goto err; |
| 121 | |
Bartlomiej Zolnierkiewicz | 48c3c10 | 2008-07-23 19:55:57 +0200 | [diff] [blame] | 122 | dev_set_drvdata(dev, host); |
Ralf Baechle | 4237f22 | 2005-11-17 16:23:50 +0000 | [diff] [blame] | 123 | |
| 124 | return 0; |
Bartlomiej Zolnierkiewicz | cb8ea09 | 2008-07-16 20:33:44 +0200 | [diff] [blame] | 125 | err: |
| 126 | release_resource(&swarm_ide_resource); |
| 127 | iounmap(base); |
Bartlomiej Zolnierkiewicz | 6f904d0 | 2008-07-23 19:55:57 +0200 | [diff] [blame] | 128 | return rc; |
Ralf Baechle | 4237f22 | 2005-11-17 16:23:50 +0000 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | static struct device_driver swarm_ide_driver = { |
| 132 | .name = swarm_ide_string, |
| 133 | .bus = &platform_bus_type, |
| 134 | .probe = swarm_ide_probe, |
| 135 | }; |
| 136 | |
| 137 | static void swarm_ide_platform_release(struct device *device) |
| 138 | { |
| 139 | struct platform_device *pldev; |
| 140 | |
| 141 | /* free device */ |
| 142 | pldev = to_platform_device(device); |
| 143 | kfree(pldev); |
| 144 | } |
| 145 | |
| 146 | static int __devinit swarm_ide_init_module(void) |
| 147 | { |
| 148 | struct platform_device *pldev; |
| 149 | int err; |
| 150 | |
| 151 | printk(KERN_INFO "SWARM IDE driver\n"); |
| 152 | |
| 153 | if (driver_register(&swarm_ide_driver)) { |
| 154 | printk(KERN_ERR "Driver registration failed\n"); |
| 155 | err = -ENODEV; |
| 156 | goto out; |
| 157 | } |
| 158 | |
Yoann Padioleau | dd00cc4 | 2007-07-19 01:49:03 -0700 | [diff] [blame] | 159 | if (!(pldev = kzalloc(sizeof (*pldev), GFP_KERNEL))) { |
Ralf Baechle | 4237f22 | 2005-11-17 16:23:50 +0000 | [diff] [blame] | 160 | err = -ENOMEM; |
| 161 | goto out_unregister_driver; |
| 162 | } |
| 163 | |
Ralf Baechle | 4237f22 | 2005-11-17 16:23:50 +0000 | [diff] [blame] | 164 | pldev->name = swarm_ide_string; |
| 165 | pldev->id = 0; |
| 166 | pldev->dev.release = swarm_ide_platform_release; |
| 167 | |
| 168 | if (platform_device_register(pldev)) { |
| 169 | err = -ENODEV; |
| 170 | goto out_free_pldev; |
| 171 | } |
| 172 | |
| 173 | if (!pldev->dev.driver) { |
| 174 | /* |
| 175 | * The driver was not bound to this device, there was |
| 176 | * no hardware at this address. Unregister it, as the |
| 177 | * release fuction will take care of freeing the |
| 178 | * allocated structure |
| 179 | */ |
| 180 | platform_device_unregister (pldev); |
| 181 | } |
| 182 | |
| 183 | swarm_ide_dev = pldev; |
| 184 | |
| 185 | return 0; |
| 186 | |
| 187 | out_free_pldev: |
| 188 | kfree(pldev); |
| 189 | |
| 190 | out_unregister_driver: |
| 191 | driver_unregister(&swarm_ide_driver); |
| 192 | out: |
| 193 | return err; |
| 194 | } |
| 195 | |
| 196 | module_init(swarm_ide_init_module); |