platform.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. #include <linux/err.h>
  2. #include <linux/kernel.h>
  3. #include <linux/init.h>
  4. #include <linux/io.h>
  5. #include <linux/platform_device.h>
  6. #include <linux/ata_platform.h>
  7. #include <asm/sibyte/board.h>
  8. #include <asm/sibyte/sb1250_genbus.h>
  9. #include <asm/sibyte/sb1250_regs.h>
  10. #if defined(CONFIG_SIBYTE_SWARM) || defined(CONFIG_SIBYTE_LITTLESUR)
  11. #define DRV_NAME "pata-swarm"
  12. #define SWARM_IDE_SHIFT 5
  13. #define SWARM_IDE_BASE 0x1f0
  14. #define SWARM_IDE_CTRL 0x3f6
  15. static struct resource swarm_pata_resource[] = {
  16. {
  17. .name = "Swarm GenBus IDE",
  18. .flags = IORESOURCE_MEM,
  19. }, {
  20. .name = "Swarm GenBus IDE",
  21. .flags = IORESOURCE_MEM,
  22. }, {
  23. .name = "Swarm GenBus IDE",
  24. .flags = IORESOURCE_IRQ,
  25. .start = K_INT_GB_IDE,
  26. .end = K_INT_GB_IDE,
  27. },
  28. };
  29. static struct pata_platform_info pata_platform_data = {
  30. .ioport_shift = SWARM_IDE_SHIFT,
  31. };
  32. static struct platform_device swarm_pata_device = {
  33. .name = "pata_platform",
  34. .id = -1,
  35. .resource = swarm_pata_resource,
  36. .num_resources = ARRAY_SIZE(swarm_pata_resource),
  37. .dev = {
  38. .platform_data = &pata_platform_data,
  39. .coherent_dma_mask = ~0, /* grumble */
  40. },
  41. };
  42. static int __init swarm_pata_init(void)
  43. {
  44. u8 __iomem *base;
  45. phys_addr_t offset, size;
  46. struct resource *r;
  47. if (!SIBYTE_HAVE_IDE)
  48. return -ENODEV;
  49. base = ioremap(A_IO_EXT_BASE, 0x800);
  50. offset = __raw_readq(base + R_IO_EXT_REG(R_IO_EXT_START_ADDR, IDE_CS));
  51. size = __raw_readq(base + R_IO_EXT_REG(R_IO_EXT_MULT_SIZE, IDE_CS));
  52. iounmap(base);
  53. offset = G_IO_START_ADDR(offset) << S_IO_ADDRBASE;
  54. size = (G_IO_MULT_SIZE(size) + 1) << S_IO_REGSIZE;
  55. if (offset < A_PHYS_GENBUS || offset >= A_PHYS_GENBUS_END) {
  56. pr_info(DRV_NAME ": PATA interface at GenBus disabled\n");
  57. return -EBUSY;
  58. }
  59. pr_info(DRV_NAME ": PATA interface at GenBus slot %i\n", IDE_CS);
  60. r = swarm_pata_resource;
  61. r[0].start = offset + (SWARM_IDE_BASE << SWARM_IDE_SHIFT);
  62. r[0].end = offset + ((SWARM_IDE_BASE + 8) << SWARM_IDE_SHIFT) - 1;
  63. r[1].start = offset + (SWARM_IDE_CTRL << SWARM_IDE_SHIFT);
  64. r[1].end = offset + ((SWARM_IDE_CTRL + 1) << SWARM_IDE_SHIFT) - 1;
  65. return platform_device_register(&swarm_pata_device);
  66. }
  67. device_initcall(swarm_pata_init);
  68. #endif /* defined(CONFIG_SIBYTE_SWARM) || defined(CONFIG_SIBYTE_LITTLESUR) */
  69. #define sb1250_dev_struct(num) \
  70. static struct resource sb1250_res##num = { \
  71. .name = "SB1250 MAC " __stringify(num), \
  72. .flags = IORESOURCE_MEM, \
  73. .start = A_MAC_CHANNEL_BASE(num), \
  74. .end = A_MAC_CHANNEL_BASE(num + 1) -1, \
  75. };\
  76. static struct platform_device sb1250_dev##num = { \
  77. .name = "sb1250-mac", \
  78. .id = num, \
  79. .resource = &sb1250_res##num, \
  80. .num_resources = 1, \
  81. }
  82. sb1250_dev_struct(0);
  83. sb1250_dev_struct(1);
  84. sb1250_dev_struct(2);
  85. sb1250_dev_struct(3);
  86. static struct platform_device *sb1250_devs[] __initdata = {
  87. &sb1250_dev0,
  88. &sb1250_dev1,
  89. &sb1250_dev2,
  90. &sb1250_dev3,
  91. };
  92. static int __init sb1250_device_init(void)
  93. {
  94. int ret;
  95. /* Set the number of available units based on the SOC type. */
  96. switch (soc_type) {
  97. case K_SYS_SOC_TYPE_BCM1250:
  98. case K_SYS_SOC_TYPE_BCM1250_ALT:
  99. ret = platform_add_devices(sb1250_devs, 3);
  100. break;
  101. case K_SYS_SOC_TYPE_BCM1120:
  102. case K_SYS_SOC_TYPE_BCM1125:
  103. case K_SYS_SOC_TYPE_BCM1125H:
  104. case K_SYS_SOC_TYPE_BCM1250_ALT2: /* Hybrid */
  105. ret = platform_add_devices(sb1250_devs, 2);
  106. break;
  107. case K_SYS_SOC_TYPE_BCM1x55:
  108. case K_SYS_SOC_TYPE_BCM1x80:
  109. ret = platform_add_devices(sb1250_devs, 4);
  110. break;
  111. default:
  112. ret = -ENODEV;
  113. break;
  114. }
  115. return ret;
  116. }
  117. device_initcall(sb1250_device_init);