2005-11-17 11:23:50 -05:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2001, 2002, 2003 Broadcom Corporation
|
|
|
|
* Copyright (C) 2004 MontaVista Software Inc.
|
|
|
|
* Author: Manish Lachwani, mlachwani@mvista.com
|
|
|
|
* Copyright (C) 2004 MIPS Technologies, Inc. All rights reserved.
|
|
|
|
* Author: Maciej W. Rozycki <macro@mips.com>
|
2008-05-14 17:06:14 -04:00
|
|
|
* Copyright (c) 2006, 2008 Maciej W. Rozycki
|
2005-11-17 11:23:50 -05:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Derived loosely from ide-pmac.c, so:
|
|
|
|
* Copyright (C) 1998 Paul Mackerras.
|
|
|
|
* Copyright (C) 1995-1998 Mark Lord
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Boards with SiByte processors so far have supported IDE devices via
|
|
|
|
* the Generic Bus, PCI bus, and built-in PCMCIA interface. In all
|
|
|
|
* cases, byte-swapping must be avoided for these devices (whereas
|
|
|
|
* other PCI devices, for example, will require swapping). Any
|
|
|
|
* SiByte-targetted kernel including IDE support will include this
|
|
|
|
* file. Probing of a Generic Bus for an IDE device is controlled by
|
|
|
|
* the definition of "SIBYTE_HAVE_IDE", which is provided by
|
|
|
|
* <asm/sibyte/board.h> for Broadcom boards.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/ide.h>
|
|
|
|
#include <linux/ioport.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
|
|
|
|
#include <asm/io.h>
|
|
|
|
|
|
|
|
#include <asm/sibyte/board.h>
|
|
|
|
#include <asm/sibyte/sb1250_genbus.h>
|
|
|
|
#include <asm/sibyte/sb1250_regs.h>
|
|
|
|
|
|
|
|
#define DRV_NAME "ide-swarm"
|
|
|
|
|
|
|
|
static char swarm_ide_string[] = DRV_NAME;
|
|
|
|
|
|
|
|
static struct resource swarm_ide_resource = {
|
|
|
|
.name = "SWARM GenBus IDE",
|
|
|
|
.flags = IORESOURCE_MEM,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct platform_device *swarm_ide_dev;
|
|
|
|
|
2008-07-16 14:33:41 -04:00
|
|
|
static const struct ide_port_info swarm_port_info = {
|
2008-07-16 14:33:42 -04:00
|
|
|
.name = DRV_NAME,
|
2008-07-16 14:33:41 -04:00
|
|
|
.host_flags = IDE_HFLAG_MMIO | IDE_HFLAG_NO_DMA,
|
|
|
|
};
|
|
|
|
|
2005-11-17 11:23:50 -05:00
|
|
|
/*
|
|
|
|
* swarm_ide_probe - if the board header indicates the existence of
|
|
|
|
* Generic Bus IDE, allocate a HWIF for it.
|
|
|
|
*/
|
|
|
|
static int __devinit swarm_ide_probe(struct device *dev)
|
|
|
|
{
|
|
|
|
u8 __iomem *base;
|
2008-07-23 13:55:57 -04:00
|
|
|
struct ide_host *host;
|
2005-11-17 11:23:50 -05:00
|
|
|
phys_t offset, size;
|
ide: add ide_host_add() helper
Add ide_host_add() helper which does ide_host_alloc()+ide_host_register(),
then convert ide_setup_pci_device[s](), ide_legacy_device_add() and some
host drivers to use it.
While at it:
* Fix ide_setup_pci_device[s](), ide_arm.c, gayle.c, ide-4drives.c,
macide.c, q40ide.c, cmd640.c and cs5520.c to return correct error value.
* -ENOENT -> -ENOMEM in rapide.c, ide-h8300.c, ide-generic.c, au1xxx-ide.c
and pmac.c
* -ENODEV -> -ENOMEM in palm_bk3710.c, ide_platform.c and delkin_cb.c
* -1 -> -ENOMEM in ide-pnp.c
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
2008-07-23 13:55:57 -04:00
|
|
|
int i, rc;
|
2008-07-23 13:55:50 -04:00
|
|
|
hw_regs_t hw, *hws[] = { &hw, NULL, NULL, NULL };
|
2005-11-17 11:23:50 -05:00
|
|
|
|
|
|
|
if (!SIBYTE_HAVE_IDE)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
base = ioremap(A_IO_EXT_BASE, 0x800);
|
|
|
|
offset = __raw_readq(base + R_IO_EXT_REG(R_IO_EXT_START_ADDR, IDE_CS));
|
|
|
|
size = __raw_readq(base + R_IO_EXT_REG(R_IO_EXT_MULT_SIZE, IDE_CS));
|
|
|
|
iounmap(base);
|
|
|
|
|
|
|
|
offset = G_IO_START_ADDR(offset) << S_IO_ADDRBASE;
|
|
|
|
size = (G_IO_MULT_SIZE(size) + 1) << S_IO_REGSIZE;
|
|
|
|
if (offset < A_PHYS_GENBUS || offset >= A_PHYS_GENBUS_END) {
|
|
|
|
printk(KERN_INFO DRV_NAME
|
|
|
|
": IDE interface at GenBus disabled\n");
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
printk(KERN_INFO DRV_NAME ": IDE interface at GenBus slot %i\n",
|
|
|
|
IDE_CS);
|
|
|
|
|
|
|
|
swarm_ide_resource.start = offset;
|
|
|
|
swarm_ide_resource.end = offset + size - 1;
|
|
|
|
if (request_resource(&iomem_resource, &swarm_ide_resource)) {
|
|
|
|
printk(KERN_ERR DRV_NAME
|
|
|
|
": can't request I/O memory resource\n");
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
base = ioremap(offset, size);
|
|
|
|
|
2008-04-27 09:38:32 -04:00
|
|
|
for (i = 0; i <= 7; i++)
|
2008-05-14 17:06:14 -04:00
|
|
|
hw.io_ports_array[i] =
|
2005-11-17 11:23:50 -05:00
|
|
|
(unsigned long)(base + ((0x1f0 + i) << 5));
|
2008-05-14 17:06:14 -04:00
|
|
|
hw.io_ports.ctl_addr =
|
2005-11-17 11:23:50 -05:00
|
|
|
(unsigned long)(base + (0x3f6 << 5));
|
2008-05-14 17:06:14 -04:00
|
|
|
hw.irq = K_INT_GB_IDE;
|
|
|
|
hw.chipset = ide_generic;
|
|
|
|
|
ide: add ide_host_add() helper
Add ide_host_add() helper which does ide_host_alloc()+ide_host_register(),
then convert ide_setup_pci_device[s](), ide_legacy_device_add() and some
host drivers to use it.
While at it:
* Fix ide_setup_pci_device[s](), ide_arm.c, gayle.c, ide-4drives.c,
macide.c, q40ide.c, cmd640.c and cs5520.c to return correct error value.
* -ENOENT -> -ENOMEM in rapide.c, ide-h8300.c, ide-generic.c, au1xxx-ide.c
and pmac.c
* -ENODEV -> -ENOMEM in palm_bk3710.c, ide_platform.c and delkin_cb.c
* -1 -> -ENOMEM in ide-pnp.c
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
2008-07-23 13:55:57 -04:00
|
|
|
rc = ide_host_add(&swarm_port_info, hws, &host);
|
|
|
|
if (rc)
|
2008-07-16 14:33:44 -04:00
|
|
|
goto err;
|
|
|
|
|
2008-07-23 13:55:57 -04:00
|
|
|
dev_set_drvdata(dev, host);
|
2005-11-17 11:23:50 -05:00
|
|
|
|
|
|
|
return 0;
|
2008-07-16 14:33:44 -04:00
|
|
|
err:
|
|
|
|
release_resource(&swarm_ide_resource);
|
|
|
|
iounmap(base);
|
ide: add ide_host_add() helper
Add ide_host_add() helper which does ide_host_alloc()+ide_host_register(),
then convert ide_setup_pci_device[s](), ide_legacy_device_add() and some
host drivers to use it.
While at it:
* Fix ide_setup_pci_device[s](), ide_arm.c, gayle.c, ide-4drives.c,
macide.c, q40ide.c, cmd640.c and cs5520.c to return correct error value.
* -ENOENT -> -ENOMEM in rapide.c, ide-h8300.c, ide-generic.c, au1xxx-ide.c
and pmac.c
* -ENODEV -> -ENOMEM in palm_bk3710.c, ide_platform.c and delkin_cb.c
* -1 -> -ENOMEM in ide-pnp.c
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
2008-07-23 13:55:57 -04:00
|
|
|
return rc;
|
2005-11-17 11:23:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct device_driver swarm_ide_driver = {
|
|
|
|
.name = swarm_ide_string,
|
|
|
|
.bus = &platform_bus_type,
|
|
|
|
.probe = swarm_ide_probe,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void swarm_ide_platform_release(struct device *device)
|
|
|
|
{
|
|
|
|
struct platform_device *pldev;
|
|
|
|
|
|
|
|
/* free device */
|
|
|
|
pldev = to_platform_device(device);
|
|
|
|
kfree(pldev);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __devinit swarm_ide_init_module(void)
|
|
|
|
{
|
|
|
|
struct platform_device *pldev;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
printk(KERN_INFO "SWARM IDE driver\n");
|
|
|
|
|
|
|
|
if (driver_register(&swarm_ide_driver)) {
|
|
|
|
printk(KERN_ERR "Driver registration failed\n");
|
|
|
|
err = -ENODEV;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
some kmalloc/memset ->kzalloc (tree wide)
Transform some calls to kmalloc/memset to a single kzalloc (or kcalloc).
Here is a short excerpt of the semantic patch performing
this transformation:
@@
type T2;
expression x;
identifier f,fld;
expression E;
expression E1,E2;
expression e1,e2,e3,y;
statement S;
@@
x =
- kmalloc
+ kzalloc
(E1,E2)
... when != \(x->fld=E;\|y=f(...,x,...);\|f(...,x,...);\|x=E;\|while(...) S\|for(e1;e2;e3) S\)
- memset((T2)x,0,E1);
@@
expression E1,E2,E3;
@@
- kzalloc(E1 * E2,E3)
+ kcalloc(E1,E2,E3)
[akpm@linux-foundation.org: get kcalloc args the right way around]
Signed-off-by: Yoann Padioleau <padator@wanadoo.fr>
Cc: Richard Henderson <rth@twiddle.net>
Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
Acked-by: Russell King <rmk@arm.linux.org.uk>
Cc: Bryan Wu <bryan.wu@analog.com>
Acked-by: Jiri Slaby <jirislaby@gmail.com>
Cc: Dave Airlie <airlied@linux.ie>
Acked-by: Roland Dreier <rolandd@cisco.com>
Cc: Jiri Kosina <jkosina@suse.cz>
Acked-by: Dmitry Torokhov <dtor@mail.ru>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Acked-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Acked-by: Pierre Ossman <drzeus-list@drzeus.cx>
Cc: Jeff Garzik <jeff@garzik.org>
Cc: "David S. Miller" <davem@davemloft.net>
Acked-by: Greg KH <greg@kroah.com>
Cc: James Bottomley <James.Bottomley@steeleye.com>
Cc: "Antonino A. Daplas" <adaplas@pol.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-19 04:49:03 -04:00
|
|
|
if (!(pldev = kzalloc(sizeof (*pldev), GFP_KERNEL))) {
|
2005-11-17 11:23:50 -05:00
|
|
|
err = -ENOMEM;
|
|
|
|
goto out_unregister_driver;
|
|
|
|
}
|
|
|
|
|
|
|
|
pldev->name = swarm_ide_string;
|
|
|
|
pldev->id = 0;
|
|
|
|
pldev->dev.release = swarm_ide_platform_release;
|
|
|
|
|
|
|
|
if (platform_device_register(pldev)) {
|
|
|
|
err = -ENODEV;
|
|
|
|
goto out_free_pldev;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!pldev->dev.driver) {
|
|
|
|
/*
|
|
|
|
* The driver was not bound to this device, there was
|
|
|
|
* no hardware at this address. Unregister it, as the
|
|
|
|
* release fuction will take care of freeing the
|
|
|
|
* allocated structure
|
|
|
|
*/
|
|
|
|
platform_device_unregister (pldev);
|
|
|
|
}
|
|
|
|
|
|
|
|
swarm_ide_dev = pldev;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
out_free_pldev:
|
|
|
|
kfree(pldev);
|
|
|
|
|
|
|
|
out_unregister_driver:
|
|
|
|
driver_unregister(&swarm_ide_driver);
|
|
|
|
out:
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(swarm_ide_init_module);
|