electra_ide.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Copyright (C) 2007 PA Semi, Inc
  3. *
  4. * Maintained by: Olof Johansson <olof@lixom.net>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. #include <linux/platform_device.h>
  20. #include <asm/prom.h>
  21. #include <asm/system.h>
  22. /* The electra IDE interface is incredibly simple: Just a device on the localbus
  23. * with interrupts hooked up to one of the GPIOs. The device tree contains the
  24. * address window and interrupt mappings already, and the pata_platform driver handles
  25. * the rest. We just need to hook the two up.
  26. */
  27. #define MAX_IFS 4 /* really, we have only one */
  28. static struct platform_device *pdevs[MAX_IFS];
  29. static int __devinit electra_ide_init(void)
  30. {
  31. struct device_node *np;
  32. struct resource r[3];
  33. int ret = 0;
  34. int i;
  35. np = of_find_compatible_node(NULL, "ide", "electra-ide");
  36. i = 0;
  37. while (np && i < MAX_IFS) {
  38. memset(r, 0, sizeof(r));
  39. /* pata_platform wants two address ranges: one for the base registers,
  40. * another for the control (altstatus). It's located at offset 0x3f6 in
  41. * the window, but the device tree only has one large register window
  42. * that covers both ranges. So we need to split it up by hand here:
  43. */
  44. ret = of_address_to_resource(np, 0, &r[0]);
  45. if (ret)
  46. goto out;
  47. ret = of_address_to_resource(np, 0, &r[1]);
  48. if (ret)
  49. goto out;
  50. r[1].start += 0x3f6;
  51. r[0].end = r[1].start-1;
  52. r[2].start = irq_of_parse_and_map(np, 0);
  53. r[2].end = irq_of_parse_and_map(np, 0);
  54. r[2].flags = IORESOURCE_IRQ;
  55. pr_debug("registering platform device at 0x%lx/0x%lx, irq is %ld\n",
  56. r[0].start, r[1].start, r[2].start);
  57. pdevs[i] = platform_device_register_simple("pata_platform", i, r, 3);
  58. if (IS_ERR(pdevs[i])) {
  59. ret = PTR_ERR(pdevs[i]);
  60. pdevs[i] = NULL;
  61. goto out;
  62. }
  63. np = of_find_compatible_node(np, "ide", "electra-ide");
  64. }
  65. out:
  66. return ret;
  67. }
  68. module_init(electra_ide_init);
  69. static void __devexit electra_ide_exit(void)
  70. {
  71. int i;
  72. for (i = 0; i < MAX_IFS; i++)
  73. if (pdevs[i])
  74. platform_device_unregister(pdevs[i]);
  75. }
  76. module_exit(electra_ide_exit);
  77. MODULE_LICENSE("GPL");
  78. MODULE_AUTHOR ("Olof Johansson <olof@lixom.net>");
  79. MODULE_DESCRIPTION("PA Semi Electra IDE driver");