Merge remote-tracking branch 's5p/for-next'
[linux-2.6/next.git] / arch / mips / sibyte / swarm / platform.c
blob097335262fb3f3abad4f5850636ee03d67e2c5a5
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>
8 #include <asm/sibyte/board.h>
9 #include <asm/sibyte/sb1250_genbus.h>
10 #include <asm/sibyte/sb1250_regs.h>
12 #if defined(CONFIG_SIBYTE_SWARM) || defined(CONFIG_SIBYTE_LITTLESUR)
14 #define DRV_NAME "pata-swarm"
16 #define SWARM_IDE_SHIFT 5
17 #define SWARM_IDE_BASE 0x1f0
18 #define SWARM_IDE_CTRL 0x3f6
20 static struct resource swarm_pata_resource[] = {
22 .name = "Swarm GenBus IDE",
23 .flags = IORESOURCE_MEM,
24 }, {
25 .name = "Swarm GenBus IDE",
26 .flags = IORESOURCE_MEM,
27 }, {
28 .name = "Swarm GenBus IDE",
29 .flags = IORESOURCE_IRQ,
30 .start = K_INT_GB_IDE,
31 .end = K_INT_GB_IDE,
35 static struct pata_platform_info pata_platform_data = {
36 .ioport_shift = SWARM_IDE_SHIFT,
39 static struct platform_device swarm_pata_device = {
40 .name = "pata_platform",
41 .id = -1,
42 .resource = swarm_pata_resource,
43 .num_resources = ARRAY_SIZE(swarm_pata_resource),
44 .dev = {
45 .platform_data = &pata_platform_data,
46 .coherent_dma_mask = ~0, /* grumble */
50 static int __init swarm_pata_init(void)
52 u8 __iomem *base;
53 phys_t offset, size;
54 struct resource *r;
56 if (!SIBYTE_HAVE_IDE)
57 return -ENODEV;
59 base = ioremap(A_IO_EXT_BASE, 0x800);
60 offset = __raw_readq(base + R_IO_EXT_REG(R_IO_EXT_START_ADDR, IDE_CS));
61 size = __raw_readq(base + R_IO_EXT_REG(R_IO_EXT_MULT_SIZE, IDE_CS));
62 iounmap(base);
64 offset = G_IO_START_ADDR(offset) << S_IO_ADDRBASE;
65 size = (G_IO_MULT_SIZE(size) + 1) << S_IO_REGSIZE;
66 if (offset < A_PHYS_GENBUS || offset >= A_PHYS_GENBUS_END) {
67 pr_info(DRV_NAME ": PATA interface at GenBus disabled\n");
69 return -EBUSY;
72 pr_info(DRV_NAME ": PATA interface at GenBus slot %i\n", IDE_CS);
74 r = swarm_pata_resource;
75 r[0].start = offset + (SWARM_IDE_BASE << SWARM_IDE_SHIFT);
76 r[0].end = offset + ((SWARM_IDE_BASE + 8) << SWARM_IDE_SHIFT) - 1;
77 r[1].start = offset + (SWARM_IDE_CTRL << SWARM_IDE_SHIFT);
78 r[1].end = offset + ((SWARM_IDE_CTRL + 1) << SWARM_IDE_SHIFT) - 1;
80 return platform_device_register(&swarm_pata_device);
83 device_initcall(swarm_pata_init);
85 #endif /* defined(CONFIG_SIBYTE_SWARM) || defined(CONFIG_SIBYTE_LITTLESUR) */
87 #define sb1250_dev_struct(num) \
88 static struct resource sb1250_res##num = { \
89 .name = "SB1250 MAC " __stringify(num), \
90 .flags = IORESOURCE_MEM, \
91 .start = A_MAC_CHANNEL_BASE(num), \
92 .end = A_MAC_CHANNEL_BASE(num + 1) -1, \
93 };\
94 static struct platform_device sb1250_dev##num = { \
95 .name = "sb1250-mac", \
96 .id = num, \
97 .resource = &sb1250_res##num, \
98 .num_resources = 1, \
101 sb1250_dev_struct(0);
102 sb1250_dev_struct(1);
103 sb1250_dev_struct(2);
104 sb1250_dev_struct(3);
106 static struct platform_device *sb1250_devs[] __initdata = {
107 &sb1250_dev0,
108 &sb1250_dev1,
109 &sb1250_dev2,
110 &sb1250_dev3,
113 static int __init sb1250_device_init(void)
115 int ret;
117 /* Set the number of available units based on the SOC type. */
118 switch (soc_type) {
119 case K_SYS_SOC_TYPE_BCM1250:
120 case K_SYS_SOC_TYPE_BCM1250_ALT:
121 ret = platform_add_devices(sb1250_devs, 3);
122 break;
123 case K_SYS_SOC_TYPE_BCM1120:
124 case K_SYS_SOC_TYPE_BCM1125:
125 case K_SYS_SOC_TYPE_BCM1125H:
126 case K_SYS_SOC_TYPE_BCM1250_ALT2: /* Hybrid */
127 ret = platform_add_devices(sb1250_devs, 2);
128 break;
129 case K_SYS_SOC_TYPE_BCM1x55:
130 case K_SYS_SOC_TYPE_BCM1x80:
131 ret = platform_add_devices(sb1250_devs, 4);
132 break;
133 default:
134 ret = -ENODEV;
135 break;
137 return ret;
139 device_initcall(sb1250_device_init);