swarm.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. * Copyright (c) 2006, 2008 Maciej W. Rozycki
  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. * Derived loosely from ide-pmac.c, so:
  25. * Copyright (C) 1998 Paul Mackerras.
  26. * Copyright (C) 1995-1998 Mark Lord
  27. */
  28. /*
  29. * Boards with SiByte processors so far have supported IDE devices via
  30. * the Generic Bus, PCI bus, and built-in PCMCIA interface. In all
  31. * cases, byte-swapping must be avoided for these devices (whereas
  32. * other PCI devices, for example, will require swapping). Any
  33. * SiByte-targetted kernel including IDE support will include this
  34. * file. Probing of a Generic Bus for an IDE device is controlled by
  35. * the definition of "SIBYTE_HAVE_IDE", which is provided by
  36. * <asm/sibyte/board.h> for Broadcom boards.
  37. */
  38. #include <linux/ide.h>
  39. #include <linux/ioport.h>
  40. #include <linux/kernel.h>
  41. #include <linux/types.h>
  42. #include <linux/platform_device.h>
  43. #include <asm/io.h>
  44. #include <asm/sibyte/board.h>
  45. #include <asm/sibyte/sb1250_genbus.h>
  46. #include <asm/sibyte/sb1250_regs.h>
  47. #define DRV_NAME "ide-swarm"
  48. static char swarm_ide_string[] = DRV_NAME;
  49. static struct resource swarm_ide_resource = {
  50. .name = "SWARM GenBus IDE",
  51. .flags = IORESOURCE_MEM,
  52. };
  53. static struct platform_device *swarm_ide_dev;
  54. static const struct ide_port_info swarm_port_info = {
  55. .name = DRV_NAME,
  56. .host_flags = IDE_HFLAG_MMIO | IDE_HFLAG_NO_DMA,
  57. };
  58. /*
  59. * swarm_ide_probe - if the board header indicates the existence of
  60. * Generic Bus IDE, allocate a HWIF for it.
  61. */
  62. static int __devinit swarm_ide_probe(struct device *dev)
  63. {
  64. ide_hwif_t *hwif;
  65. u8 __iomem *base;
  66. phys_t offset, size;
  67. hw_regs_t hw;
  68. int i;
  69. u8 idx[] = { 0xff, 0xff, 0xff, 0xff };
  70. if (!SIBYTE_HAVE_IDE)
  71. return -ENODEV;
  72. base = ioremap(A_IO_EXT_BASE, 0x800);
  73. offset = __raw_readq(base + R_IO_EXT_REG(R_IO_EXT_START_ADDR, IDE_CS));
  74. size = __raw_readq(base + R_IO_EXT_REG(R_IO_EXT_MULT_SIZE, IDE_CS));
  75. iounmap(base);
  76. offset = G_IO_START_ADDR(offset) << S_IO_ADDRBASE;
  77. size = (G_IO_MULT_SIZE(size) + 1) << S_IO_REGSIZE;
  78. if (offset < A_PHYS_GENBUS || offset >= A_PHYS_GENBUS_END) {
  79. printk(KERN_INFO DRV_NAME
  80. ": IDE interface at GenBus disabled\n");
  81. return -EBUSY;
  82. }
  83. printk(KERN_INFO DRV_NAME ": IDE interface at GenBus slot %i\n",
  84. IDE_CS);
  85. swarm_ide_resource.start = offset;
  86. swarm_ide_resource.end = offset + size - 1;
  87. if (request_resource(&iomem_resource, &swarm_ide_resource)) {
  88. printk(KERN_ERR DRV_NAME
  89. ": can't request I/O memory resource\n");
  90. return -EBUSY;
  91. }
  92. base = ioremap(offset, size);
  93. for (i = 0; i <= 7; i++)
  94. hw.io_ports_array[i] =
  95. (unsigned long)(base + ((0x1f0 + i) << 5));
  96. hw.io_ports.ctl_addr =
  97. (unsigned long)(base + (0x3f6 << 5));
  98. hw.irq = K_INT_GB_IDE;
  99. hw.chipset = ide_generic;
  100. hwif = ide_find_port_slot(&swarm_port_info);
  101. if (hwif == NULL)
  102. goto err;
  103. ide_init_port_hw(hwif, &hw);
  104. /* Setup MMIO ops. */
  105. default_hwif_mmiops(hwif);
  106. idx[0] = hwif->index;
  107. ide_device_add(idx, &swarm_port_info);
  108. dev_set_drvdata(dev, hwif);
  109. return 0;
  110. err:
  111. release_resource(&swarm_ide_resource);
  112. iounmap(base);
  113. return -ENOMEM;
  114. }
  115. static struct device_driver swarm_ide_driver = {
  116. .name = swarm_ide_string,
  117. .bus = &platform_bus_type,
  118. .probe = swarm_ide_probe,
  119. };
  120. static void swarm_ide_platform_release(struct device *device)
  121. {
  122. struct platform_device *pldev;
  123. /* free device */
  124. pldev = to_platform_device(device);
  125. kfree(pldev);
  126. }
  127. static int __devinit swarm_ide_init_module(void)
  128. {
  129. struct platform_device *pldev;
  130. int err;
  131. printk(KERN_INFO "SWARM IDE driver\n");
  132. if (driver_register(&swarm_ide_driver)) {
  133. printk(KERN_ERR "Driver registration failed\n");
  134. err = -ENODEV;
  135. goto out;
  136. }
  137. if (!(pldev = kzalloc(sizeof (*pldev), GFP_KERNEL))) {
  138. err = -ENOMEM;
  139. goto out_unregister_driver;
  140. }
  141. pldev->name = swarm_ide_string;
  142. pldev->id = 0;
  143. pldev->dev.release = swarm_ide_platform_release;
  144. if (platform_device_register(pldev)) {
  145. err = -ENODEV;
  146. goto out_free_pldev;
  147. }
  148. if (!pldev->dev.driver) {
  149. /*
  150. * The driver was not bound to this device, there was
  151. * no hardware at this address. Unregister it, as the
  152. * release fuction will take care of freeing the
  153. * allocated structure
  154. */
  155. platform_device_unregister (pldev);
  156. }
  157. swarm_ide_dev = pldev;
  158. return 0;
  159. out_free_pldev:
  160. kfree(pldev);
  161. out_unregister_driver:
  162. driver_unregister(&swarm_ide_driver);
  163. out:
  164. return err;
  165. }
  166. module_init(swarm_ide_init_module);