xref: /linux/arch/mips/sibyte/swarm/platform.c (revision 15d45cce3a0e0716fa49c768f887c6406dfb91f7)
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;
53*15d45cceSRalf Baechle 	phys_addr_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) */
868cd9b132SSebastian Andrzej Siewior 
878cd9b132SSebastian Andrzej Siewior #define sb1250_dev_struct(num) \
888cd9b132SSebastian Andrzej Siewior 	static struct resource sb1250_res##num = {		\
898cd9b132SSebastian Andrzej Siewior 		.name = "SB1250 MAC " __stringify(num),		\
908cd9b132SSebastian Andrzej Siewior 		.flags = IORESOURCE_MEM,		\
918cd9b132SSebastian Andrzej Siewior 		.start = A_MAC_CHANNEL_BASE(num),	\
928cd9b132SSebastian Andrzej Siewior 		.end = A_MAC_CHANNEL_BASE(num + 1) -1,	\
938cd9b132SSebastian Andrzej Siewior 	};\
948cd9b132SSebastian Andrzej Siewior 	static struct platform_device sb1250_dev##num = {	\
958cd9b132SSebastian Andrzej Siewior 		.name = "sb1250-mac",			\
968cd9b132SSebastian Andrzej Siewior 	.id = num,					\
978cd9b132SSebastian Andrzej Siewior 	.resource = &sb1250_res##num,			\
988cd9b132SSebastian Andrzej Siewior 	.num_resources = 1,				\
998cd9b132SSebastian Andrzej Siewior 	}
1008cd9b132SSebastian Andrzej Siewior 
1018cd9b132SSebastian Andrzej Siewior sb1250_dev_struct(0);
1028cd9b132SSebastian Andrzej Siewior sb1250_dev_struct(1);
1038cd9b132SSebastian Andrzej Siewior sb1250_dev_struct(2);
1048cd9b132SSebastian Andrzej Siewior sb1250_dev_struct(3);
1058cd9b132SSebastian Andrzej Siewior 
1068cd9b132SSebastian Andrzej Siewior static struct platform_device *sb1250_devs[] __initdata = {
1078cd9b132SSebastian Andrzej Siewior 	&sb1250_dev0,
1088cd9b132SSebastian Andrzej Siewior 	&sb1250_dev1,
1098cd9b132SSebastian Andrzej Siewior 	&sb1250_dev2,
1108cd9b132SSebastian Andrzej Siewior 	&sb1250_dev3,
1118cd9b132SSebastian Andrzej Siewior };
1128cd9b132SSebastian Andrzej Siewior 
1138cd9b132SSebastian Andrzej Siewior static int __init sb1250_device_init(void)
1148cd9b132SSebastian Andrzej Siewior {
1158cd9b132SSebastian Andrzej Siewior 	int ret;
1168cd9b132SSebastian Andrzej Siewior 
1178cd9b132SSebastian Andrzej Siewior 	/* Set the number of available units based on the SOC type.  */
1188cd9b132SSebastian Andrzej Siewior 	switch (soc_type) {
1198cd9b132SSebastian Andrzej Siewior 	case K_SYS_SOC_TYPE_BCM1250:
1208cd9b132SSebastian Andrzej Siewior 	case K_SYS_SOC_TYPE_BCM1250_ALT:
1218cd9b132SSebastian Andrzej Siewior 		ret = platform_add_devices(sb1250_devs, 3);
1228cd9b132SSebastian Andrzej Siewior 		break;
1238cd9b132SSebastian Andrzej Siewior 	case K_SYS_SOC_TYPE_BCM1120:
1248cd9b132SSebastian Andrzej Siewior 	case K_SYS_SOC_TYPE_BCM1125:
1258cd9b132SSebastian Andrzej Siewior 	case K_SYS_SOC_TYPE_BCM1125H:
1268cd9b132SSebastian Andrzej Siewior 	case K_SYS_SOC_TYPE_BCM1250_ALT2:	/* Hybrid */
1278cd9b132SSebastian Andrzej Siewior 		ret = platform_add_devices(sb1250_devs, 2);
1288cd9b132SSebastian Andrzej Siewior 		break;
1298cd9b132SSebastian Andrzej Siewior 	case K_SYS_SOC_TYPE_BCM1x55:
1308cd9b132SSebastian Andrzej Siewior 	case K_SYS_SOC_TYPE_BCM1x80:
1318cd9b132SSebastian Andrzej Siewior 		ret = platform_add_devices(sb1250_devs, 4);
1328cd9b132SSebastian Andrzej Siewior 		break;
1338cd9b132SSebastian Andrzej Siewior 	default:
1348cd9b132SSebastian Andrzej Siewior 		ret = -ENODEV;
1358cd9b132SSebastian Andrzej Siewior 		break;
1368cd9b132SSebastian Andrzej Siewior 	}
1378cd9b132SSebastian Andrzej Siewior 	return ret;
1388cd9b132SSebastian Andrzej Siewior }
1398cd9b132SSebastian Andrzej Siewior device_initcall(sb1250_device_init);
140