platform.c 3.5 KB

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