0001
0002 #include <linux/err.h>
0003 #include <linux/kernel.h>
0004 #include <linux/init.h>
0005 #include <linux/io.h>
0006 #include <linux/platform_device.h>
0007 #include <linux/ata_platform.h>
0008
0009 #include <asm/sibyte/board.h>
0010 #include <asm/sibyte/sb1250_genbus.h>
0011 #include <asm/sibyte/sb1250_regs.h>
0012
0013 #if defined(CONFIG_SIBYTE_SWARM) || defined(CONFIG_SIBYTE_LITTLESUR)
0014
0015 #define DRV_NAME "pata-swarm"
0016
0017 #define SWARM_IDE_SHIFT 5
0018 #define SWARM_IDE_BASE 0x1f0
0019 #define SWARM_IDE_CTRL 0x3f6
0020
0021 static struct resource swarm_pata_resource[] = {
0022 {
0023 .name = "Swarm GenBus IDE",
0024 .flags = IORESOURCE_MEM,
0025 }, {
0026 .name = "Swarm GenBus IDE",
0027 .flags = IORESOURCE_MEM,
0028 }, {
0029 .name = "Swarm GenBus IDE",
0030 .flags = IORESOURCE_IRQ,
0031 .start = K_INT_GB_IDE,
0032 .end = K_INT_GB_IDE,
0033 },
0034 };
0035
0036 static struct pata_platform_info pata_platform_data = {
0037 .ioport_shift = SWARM_IDE_SHIFT,
0038 };
0039
0040 static struct platform_device swarm_pata_device = {
0041 .name = "pata_platform",
0042 .id = -1,
0043 .resource = swarm_pata_resource,
0044 .num_resources = ARRAY_SIZE(swarm_pata_resource),
0045 .dev = {
0046 .platform_data = &pata_platform_data,
0047 .coherent_dma_mask = ~0,
0048 },
0049 };
0050
0051 static int __init swarm_pata_init(void)
0052 {
0053 u8 __iomem *base;
0054 phys_addr_t offset, size;
0055 struct resource *r;
0056
0057 if (!SIBYTE_HAVE_IDE)
0058 return -ENODEV;
0059
0060 base = ioremap(A_IO_EXT_BASE, 0x800);
0061 offset = __raw_readq(base + R_IO_EXT_REG(R_IO_EXT_START_ADDR, IDE_CS));
0062 size = __raw_readq(base + R_IO_EXT_REG(R_IO_EXT_MULT_SIZE, IDE_CS));
0063 iounmap(base);
0064
0065 offset = G_IO_START_ADDR(offset) << S_IO_ADDRBASE;
0066 size = (G_IO_MULT_SIZE(size) + 1) << S_IO_REGSIZE;
0067 if (offset < A_PHYS_GENBUS || offset >= A_PHYS_GENBUS_END) {
0068 pr_info(DRV_NAME ": PATA interface at GenBus disabled\n");
0069
0070 return -EBUSY;
0071 }
0072
0073 pr_info(DRV_NAME ": PATA interface at GenBus slot %i\n", IDE_CS);
0074
0075 r = swarm_pata_resource;
0076 r[0].start = offset + (SWARM_IDE_BASE << SWARM_IDE_SHIFT);
0077 r[0].end = offset + ((SWARM_IDE_BASE + 8) << SWARM_IDE_SHIFT) - 1;
0078 r[1].start = offset + (SWARM_IDE_CTRL << SWARM_IDE_SHIFT);
0079 r[1].end = offset + ((SWARM_IDE_CTRL + 1) << SWARM_IDE_SHIFT) - 1;
0080
0081 return platform_device_register(&swarm_pata_device);
0082 }
0083
0084 device_initcall(swarm_pata_init);
0085
0086 #endif
0087
0088 #define sb1250_dev_struct(num) \
0089 static struct resource sb1250_res##num = { \
0090 .name = "SB1250 MAC " __stringify(num), \
0091 .flags = IORESOURCE_MEM, \
0092 .start = A_MAC_CHANNEL_BASE(num), \
0093 .end = A_MAC_CHANNEL_BASE(num + 1) -1, \
0094 };\
0095 static struct platform_device sb1250_dev##num = { \
0096 .name = "sb1250-mac", \
0097 .id = num, \
0098 .resource = &sb1250_res##num, \
0099 .num_resources = 1, \
0100 }
0101
0102 sb1250_dev_struct(0);
0103 sb1250_dev_struct(1);
0104 sb1250_dev_struct(2);
0105 sb1250_dev_struct(3);
0106
0107 static struct platform_device *sb1250_devs[] __initdata = {
0108 &sb1250_dev0,
0109 &sb1250_dev1,
0110 &sb1250_dev2,
0111 &sb1250_dev3,
0112 };
0113
0114 static int __init sb1250_device_init(void)
0115 {
0116 int ret;
0117
0118
0119 switch (soc_type) {
0120 case K_SYS_SOC_TYPE_BCM1250:
0121 case K_SYS_SOC_TYPE_BCM1250_ALT:
0122 ret = platform_add_devices(sb1250_devs, 3);
0123 break;
0124 case K_SYS_SOC_TYPE_BCM1120:
0125 case K_SYS_SOC_TYPE_BCM1125:
0126 case K_SYS_SOC_TYPE_BCM1125H:
0127 case K_SYS_SOC_TYPE_BCM1250_ALT2:
0128 ret = platform_add_devices(sb1250_devs, 2);
0129 break;
0130 case K_SYS_SOC_TYPE_BCM1x55:
0131 case K_SYS_SOC_TYPE_BCM1x80:
0132 ret = platform_add_devices(sb1250_devs, 4);
0133 break;
0134 default:
0135 ret = -ENODEV;
0136 break;
0137 }
0138 return ret;
0139 }
0140 device_initcall(sb1250_device_init);