swarm.c 5.3 KB

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