12fef357cSRalf Baechle #include <linux/err.h> 22fef357cSRalf Baechle #include <linux/kernel.h> 32fef357cSRalf Baechle #include <linux/init.h> 42fef357cSRalf Baechle #include <linux/io.h> 52fef357cSRalf Baechle #include <linux/platform_device.h> 62fef357cSRalf Baechle #include <linux/ata_platform.h> 72fef357cSRalf Baechle 82fef357cSRalf Baechle #include <asm/sibyte/board.h> 92fef357cSRalf Baechle #include <asm/sibyte/sb1250_genbus.h> 102fef357cSRalf Baechle #include <asm/sibyte/sb1250_regs.h> 112fef357cSRalf Baechle 1288060488SRalf Baechle #if defined(CONFIG_SIBYTE_SWARM) || defined(CONFIG_SIBYTE_LITTLESUR) 1388060488SRalf Baechle 142fef357cSRalf Baechle #define DRV_NAME "pata-swarm" 152fef357cSRalf Baechle 162fef357cSRalf Baechle #define SWARM_IDE_SHIFT 5 172fef357cSRalf Baechle #define SWARM_IDE_BASE 0x1f0 182fef357cSRalf Baechle #define SWARM_IDE_CTRL 0x3f6 192fef357cSRalf Baechle 202fef357cSRalf Baechle static struct resource swarm_pata_resource[] = { 212fef357cSRalf Baechle { 222fef357cSRalf Baechle .name = "Swarm GenBus IDE", 232fef357cSRalf Baechle .flags = IORESOURCE_MEM, 242fef357cSRalf Baechle }, { 252fef357cSRalf Baechle .name = "Swarm GenBus IDE", 262fef357cSRalf Baechle .flags = IORESOURCE_MEM, 272fef357cSRalf Baechle }, { 282fef357cSRalf Baechle .name = "Swarm GenBus IDE", 292fef357cSRalf Baechle .flags = IORESOURCE_IRQ, 302fef357cSRalf Baechle .start = K_INT_GB_IDE, 312fef357cSRalf Baechle .end = K_INT_GB_IDE, 322fef357cSRalf Baechle }, 332fef357cSRalf Baechle }; 342fef357cSRalf Baechle 352fef357cSRalf Baechle static struct pata_platform_info pata_platform_data = { 362fef357cSRalf Baechle .ioport_shift = SWARM_IDE_SHIFT, 372fef357cSRalf Baechle }; 382fef357cSRalf Baechle 392fef357cSRalf Baechle static struct platform_device swarm_pata_device = { 402fef357cSRalf Baechle .name = "pata_platform", 412fef357cSRalf Baechle .id = -1, 422fef357cSRalf Baechle .resource = swarm_pata_resource, 432fef357cSRalf Baechle .num_resources = ARRAY_SIZE(swarm_pata_resource), 442fef357cSRalf Baechle .dev = { 452fef357cSRalf Baechle .platform_data = &pata_platform_data, 462fef357cSRalf Baechle .coherent_dma_mask = ~0, /* grumble */ 472fef357cSRalf Baechle }, 482fef357cSRalf Baechle }; 492fef357cSRalf Baechle 502fef357cSRalf Baechle static int __init swarm_pata_init(void) 512fef357cSRalf Baechle { 522fef357cSRalf Baechle u8 __iomem *base; 532fef357cSRalf Baechle phys_t offset, size; 542fef357cSRalf Baechle struct resource *r; 552fef357cSRalf Baechle 562fef357cSRalf Baechle if (!SIBYTE_HAVE_IDE) 572fef357cSRalf Baechle return -ENODEV; 582fef357cSRalf Baechle 592fef357cSRalf Baechle base = ioremap(A_IO_EXT_BASE, 0x800); 602fef357cSRalf Baechle offset = __raw_readq(base + R_IO_EXT_REG(R_IO_EXT_START_ADDR, IDE_CS)); 612fef357cSRalf Baechle size = __raw_readq(base + R_IO_EXT_REG(R_IO_EXT_MULT_SIZE, IDE_CS)); 622fef357cSRalf Baechle iounmap(base); 632fef357cSRalf Baechle 642fef357cSRalf Baechle offset = G_IO_START_ADDR(offset) << S_IO_ADDRBASE; 652fef357cSRalf Baechle size = (G_IO_MULT_SIZE(size) + 1) << S_IO_REGSIZE; 662fef357cSRalf Baechle if (offset < A_PHYS_GENBUS || offset >= A_PHYS_GENBUS_END) { 672fef357cSRalf Baechle pr_info(DRV_NAME ": PATA interface at GenBus disabled\n"); 682fef357cSRalf Baechle 692fef357cSRalf Baechle return -EBUSY; 702fef357cSRalf Baechle } 712fef357cSRalf Baechle 722fef357cSRalf Baechle pr_info(DRV_NAME ": PATA interface at GenBus slot %i\n", IDE_CS); 732fef357cSRalf Baechle 742fef357cSRalf Baechle r = swarm_pata_resource; 752fef357cSRalf Baechle r[0].start = offset + (SWARM_IDE_BASE << SWARM_IDE_SHIFT); 762fef357cSRalf Baechle r[0].end = offset + ((SWARM_IDE_BASE + 8) << SWARM_IDE_SHIFT) - 1; 772fef357cSRalf Baechle r[1].start = offset + (SWARM_IDE_CTRL << SWARM_IDE_SHIFT); 782fef357cSRalf Baechle r[1].end = offset + ((SWARM_IDE_CTRL + 1) << SWARM_IDE_SHIFT) - 1; 792fef357cSRalf Baechle 802fef357cSRalf Baechle return platform_device_register(&swarm_pata_device); 812fef357cSRalf Baechle } 822fef357cSRalf Baechle 832fef357cSRalf Baechle device_initcall(swarm_pata_init); 8488060488SRalf Baechle 8588060488SRalf Baechle #endif /* defined(CONFIG_SIBYTE_SWARM) || defined(CONFIG_SIBYTE_LITTLESUR) */ 86*8cd9b132SSebastian Andrzej Siewior 87*8cd9b132SSebastian Andrzej Siewior #define sb1250_dev_struct(num) \ 88*8cd9b132SSebastian Andrzej Siewior static struct resource sb1250_res##num = { \ 89*8cd9b132SSebastian Andrzej Siewior .name = "SB1250 MAC " __stringify(num), \ 90*8cd9b132SSebastian Andrzej Siewior .flags = IORESOURCE_MEM, \ 91*8cd9b132SSebastian Andrzej Siewior .start = A_MAC_CHANNEL_BASE(num), \ 92*8cd9b132SSebastian Andrzej Siewior .end = A_MAC_CHANNEL_BASE(num + 1) -1, \ 93*8cd9b132SSebastian Andrzej Siewior };\ 94*8cd9b132SSebastian Andrzej Siewior static struct platform_device sb1250_dev##num = { \ 95*8cd9b132SSebastian Andrzej Siewior .name = "sb1250-mac", \ 96*8cd9b132SSebastian Andrzej Siewior .id = num, \ 97*8cd9b132SSebastian Andrzej Siewior .resource = &sb1250_res##num, \ 98*8cd9b132SSebastian Andrzej Siewior .num_resources = 1, \ 99*8cd9b132SSebastian Andrzej Siewior } 100*8cd9b132SSebastian Andrzej Siewior 101*8cd9b132SSebastian Andrzej Siewior sb1250_dev_struct(0); 102*8cd9b132SSebastian Andrzej Siewior sb1250_dev_struct(1); 103*8cd9b132SSebastian Andrzej Siewior sb1250_dev_struct(2); 104*8cd9b132SSebastian Andrzej Siewior sb1250_dev_struct(3); 105*8cd9b132SSebastian Andrzej Siewior 106*8cd9b132SSebastian Andrzej Siewior static struct platform_device *sb1250_devs[] __initdata = { 107*8cd9b132SSebastian Andrzej Siewior &sb1250_dev0, 108*8cd9b132SSebastian Andrzej Siewior &sb1250_dev1, 109*8cd9b132SSebastian Andrzej Siewior &sb1250_dev2, 110*8cd9b132SSebastian Andrzej Siewior &sb1250_dev3, 111*8cd9b132SSebastian Andrzej Siewior }; 112*8cd9b132SSebastian Andrzej Siewior 113*8cd9b132SSebastian Andrzej Siewior static int __init sb1250_device_init(void) 114*8cd9b132SSebastian Andrzej Siewior { 115*8cd9b132SSebastian Andrzej Siewior int ret; 116*8cd9b132SSebastian Andrzej Siewior 117*8cd9b132SSebastian Andrzej Siewior /* Set the number of available units based on the SOC type. */ 118*8cd9b132SSebastian Andrzej Siewior switch (soc_type) { 119*8cd9b132SSebastian Andrzej Siewior case K_SYS_SOC_TYPE_BCM1250: 120*8cd9b132SSebastian Andrzej Siewior case K_SYS_SOC_TYPE_BCM1250_ALT: 121*8cd9b132SSebastian Andrzej Siewior ret = platform_add_devices(sb1250_devs, 3); 122*8cd9b132SSebastian Andrzej Siewior break; 123*8cd9b132SSebastian Andrzej Siewior case K_SYS_SOC_TYPE_BCM1120: 124*8cd9b132SSebastian Andrzej Siewior case K_SYS_SOC_TYPE_BCM1125: 125*8cd9b132SSebastian Andrzej Siewior case K_SYS_SOC_TYPE_BCM1125H: 126*8cd9b132SSebastian Andrzej Siewior case K_SYS_SOC_TYPE_BCM1250_ALT2: /* Hybrid */ 127*8cd9b132SSebastian Andrzej Siewior ret = platform_add_devices(sb1250_devs, 2); 128*8cd9b132SSebastian Andrzej Siewior break; 129*8cd9b132SSebastian Andrzej Siewior case K_SYS_SOC_TYPE_BCM1x55: 130*8cd9b132SSebastian Andrzej Siewior case K_SYS_SOC_TYPE_BCM1x80: 131*8cd9b132SSebastian Andrzej Siewior ret = platform_add_devices(sb1250_devs, 4); 132*8cd9b132SSebastian Andrzej Siewior break; 133*8cd9b132SSebastian Andrzej Siewior default: 134*8cd9b132SSebastian Andrzej Siewior ret = -ENODEV; 135*8cd9b132SSebastian Andrzej Siewior break; 136*8cd9b132SSebastian Andrzej Siewior } 137*8cd9b132SSebastian Andrzej Siewior return ret; 138*8cd9b132SSebastian Andrzej Siewior } 139*8cd9b132SSebastian Andrzej Siewior device_initcall(sb1250_device_init); 140