xref: /linux/arch/mips/sibyte/swarm/platform.c (revision 8806048878fce541afe1d72cd2320f092519f90a)
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 
12*88060488SRalf Baechle #if defined(CONFIG_SIBYTE_SWARM) || defined(CONFIG_SIBYTE_LITTLESUR)
13*88060488SRalf 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);
84*88060488SRalf Baechle 
85*88060488SRalf Baechle #endif /* defined(CONFIG_SIBYTE_SWARM) || defined(CONFIG_SIBYTE_LITTLESUR) */
86