xref: /linux/arch/mips/sibyte/swarm/platform.c (revision cdd5b5a9761fd66d17586e4f4ba6588c70e640ea)
1*b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0
22fef357cSRalf Baechle #include <linux/err.h>
32fef357cSRalf Baechle #include <linux/kernel.h>
42fef357cSRalf Baechle #include <linux/init.h>
52fef357cSRalf Baechle #include <linux/io.h>
62fef357cSRalf Baechle #include <linux/platform_device.h>
72fef357cSRalf Baechle #include <linux/ata_platform.h>
82fef357cSRalf Baechle 
92fef357cSRalf Baechle #include <asm/sibyte/board.h>
102fef357cSRalf Baechle #include <asm/sibyte/sb1250_genbus.h>
112fef357cSRalf Baechle #include <asm/sibyte/sb1250_regs.h>
122fef357cSRalf Baechle 
1388060488SRalf Baechle #if defined(CONFIG_SIBYTE_SWARM) || defined(CONFIG_SIBYTE_LITTLESUR)
1488060488SRalf Baechle 
152fef357cSRalf Baechle #define DRV_NAME	"pata-swarm"
162fef357cSRalf Baechle 
172fef357cSRalf Baechle #define SWARM_IDE_SHIFT 5
182fef357cSRalf Baechle #define SWARM_IDE_BASE	0x1f0
192fef357cSRalf Baechle #define SWARM_IDE_CTRL	0x3f6
202fef357cSRalf Baechle 
212fef357cSRalf Baechle static struct resource swarm_pata_resource[] = {
222fef357cSRalf Baechle 	{
232fef357cSRalf Baechle 		.name	= "Swarm GenBus IDE",
242fef357cSRalf Baechle 		.flags	= IORESOURCE_MEM,
252fef357cSRalf Baechle 	}, {
262fef357cSRalf Baechle 		.name	= "Swarm GenBus IDE",
272fef357cSRalf Baechle 		.flags	= IORESOURCE_MEM,
282fef357cSRalf Baechle 	}, {
292fef357cSRalf Baechle 		.name	= "Swarm GenBus IDE",
302fef357cSRalf Baechle 		.flags	= IORESOURCE_IRQ,
312fef357cSRalf Baechle 		.start	= K_INT_GB_IDE,
322fef357cSRalf Baechle 		.end	= K_INT_GB_IDE,
332fef357cSRalf Baechle 	},
342fef357cSRalf Baechle };
352fef357cSRalf Baechle 
362fef357cSRalf Baechle static struct pata_platform_info pata_platform_data = {
372fef357cSRalf Baechle 	.ioport_shift	= SWARM_IDE_SHIFT,
382fef357cSRalf Baechle };
392fef357cSRalf Baechle 
402fef357cSRalf Baechle static struct platform_device swarm_pata_device = {
412fef357cSRalf Baechle 	.name		= "pata_platform",
422fef357cSRalf Baechle 	.id		= -1,
432fef357cSRalf Baechle 	.resource	= swarm_pata_resource,
442fef357cSRalf Baechle 	.num_resources	= ARRAY_SIZE(swarm_pata_resource),
452fef357cSRalf Baechle 	.dev  = {
462fef357cSRalf Baechle 		.platform_data		= &pata_platform_data,
472fef357cSRalf Baechle 		.coherent_dma_mask	= ~0,	/* grumble */
482fef357cSRalf Baechle 	},
492fef357cSRalf Baechle };
502fef357cSRalf Baechle 
swarm_pata_init(void)512fef357cSRalf Baechle static int __init swarm_pata_init(void)
522fef357cSRalf Baechle {
532fef357cSRalf Baechle 	u8 __iomem *base;
5415d45cceSRalf Baechle 	phys_addr_t offset, size;
552fef357cSRalf Baechle 	struct resource *r;
562fef357cSRalf Baechle 
572fef357cSRalf Baechle 	if (!SIBYTE_HAVE_IDE)
582fef357cSRalf Baechle 		return -ENODEV;
592fef357cSRalf Baechle 
602fef357cSRalf Baechle 	base = ioremap(A_IO_EXT_BASE, 0x800);
612fef357cSRalf Baechle 	offset = __raw_readq(base + R_IO_EXT_REG(R_IO_EXT_START_ADDR, IDE_CS));
622fef357cSRalf Baechle 	size = __raw_readq(base + R_IO_EXT_REG(R_IO_EXT_MULT_SIZE, IDE_CS));
632fef357cSRalf Baechle 	iounmap(base);
642fef357cSRalf Baechle 
652fef357cSRalf Baechle 	offset = G_IO_START_ADDR(offset) << S_IO_ADDRBASE;
662fef357cSRalf Baechle 	size = (G_IO_MULT_SIZE(size) + 1) << S_IO_REGSIZE;
672fef357cSRalf Baechle 	if (offset < A_PHYS_GENBUS || offset >= A_PHYS_GENBUS_END) {
682fef357cSRalf Baechle 		pr_info(DRV_NAME ": PATA interface at GenBus disabled\n");
692fef357cSRalf Baechle 
702fef357cSRalf Baechle 		return -EBUSY;
712fef357cSRalf Baechle 	}
722fef357cSRalf Baechle 
732fef357cSRalf Baechle 	pr_info(DRV_NAME ": PATA interface at GenBus slot %i\n", IDE_CS);
742fef357cSRalf Baechle 
752fef357cSRalf Baechle 	r = swarm_pata_resource;
762fef357cSRalf Baechle 	r[0].start = offset + (SWARM_IDE_BASE << SWARM_IDE_SHIFT);
772fef357cSRalf Baechle 	r[0].end   = offset + ((SWARM_IDE_BASE + 8) << SWARM_IDE_SHIFT) - 1;
782fef357cSRalf Baechle 	r[1].start = offset + (SWARM_IDE_CTRL << SWARM_IDE_SHIFT);
792fef357cSRalf Baechle 	r[1].end   = offset + ((SWARM_IDE_CTRL + 1) << SWARM_IDE_SHIFT) - 1;
802fef357cSRalf Baechle 
812fef357cSRalf Baechle 	return platform_device_register(&swarm_pata_device);
822fef357cSRalf Baechle }
832fef357cSRalf Baechle 
842fef357cSRalf Baechle device_initcall(swarm_pata_init);
8588060488SRalf Baechle 
8688060488SRalf Baechle #endif /* defined(CONFIG_SIBYTE_SWARM) || defined(CONFIG_SIBYTE_LITTLESUR) */
878cd9b132SSebastian Andrzej Siewior 
888cd9b132SSebastian Andrzej Siewior #define sb1250_dev_struct(num) \
898cd9b132SSebastian Andrzej Siewior 	static struct resource sb1250_res##num = {		\
908cd9b132SSebastian Andrzej Siewior 		.name = "SB1250 MAC " __stringify(num),		\
918cd9b132SSebastian Andrzej Siewior 		.flags = IORESOURCE_MEM,			\
928cd9b132SSebastian Andrzej Siewior 		.start = A_MAC_CHANNEL_BASE(num),		\
938cd9b132SSebastian Andrzej Siewior 		.end = A_MAC_CHANNEL_BASE(num + 1) - 1,		\
948cd9b132SSebastian Andrzej Siewior 	};\
958cd9b132SSebastian Andrzej Siewior 	static struct platform_device sb1250_dev##num = {	\
968cd9b132SSebastian Andrzej Siewior 		.name = "sb1250-mac",				\
978cd9b132SSebastian Andrzej Siewior 		.id = num,					\
988cd9b132SSebastian Andrzej Siewior 		.resource = &sb1250_res##num,			\
998cd9b132SSebastian Andrzej Siewior 		.num_resources = 1,				\
1008cd9b132SSebastian Andrzej Siewior 	}
1018cd9b132SSebastian Andrzej Siewior 
1028cd9b132SSebastian Andrzej Siewior sb1250_dev_struct(0);
1038cd9b132SSebastian Andrzej Siewior sb1250_dev_struct(1);
1048cd9b132SSebastian Andrzej Siewior sb1250_dev_struct(2);
1058cd9b132SSebastian Andrzej Siewior sb1250_dev_struct(3);
1068cd9b132SSebastian Andrzej Siewior 
1078cd9b132SSebastian Andrzej Siewior static struct platform_device *sb1250_devs[] __initdata = {
1088cd9b132SSebastian Andrzej Siewior 	&sb1250_dev0,
1098cd9b132SSebastian Andrzej Siewior 	&sb1250_dev1,
1108cd9b132SSebastian Andrzej Siewior 	&sb1250_dev2,
1118cd9b132SSebastian Andrzej Siewior 	&sb1250_dev3,
1128cd9b132SSebastian Andrzej Siewior };
1138cd9b132SSebastian Andrzej Siewior 
sb1250_device_init(void)1148cd9b132SSebastian Andrzej Siewior static int __init sb1250_device_init(void)
1158cd9b132SSebastian Andrzej Siewior {
1168cd9b132SSebastian Andrzej Siewior 	int ret;
1178cd9b132SSebastian Andrzej Siewior 
1188cd9b132SSebastian Andrzej Siewior 	/* Set the number of available units based on the SOC type.  */
1198cd9b132SSebastian Andrzej Siewior 	switch (soc_type) {
1208cd9b132SSebastian Andrzej Siewior 	case K_SYS_SOC_TYPE_BCM1250:
1218cd9b132SSebastian Andrzej Siewior 	case K_SYS_SOC_TYPE_BCM1250_ALT:
1228cd9b132SSebastian Andrzej Siewior 		ret = platform_add_devices(sb1250_devs, 3);
1238cd9b132SSebastian Andrzej Siewior 		break;
1248cd9b132SSebastian Andrzej Siewior 	case K_SYS_SOC_TYPE_BCM1120:
1258cd9b132SSebastian Andrzej Siewior 	case K_SYS_SOC_TYPE_BCM1125:
1268cd9b132SSebastian Andrzej Siewior 	case K_SYS_SOC_TYPE_BCM1125H:
1278cd9b132SSebastian Andrzej Siewior 	case K_SYS_SOC_TYPE_BCM1250_ALT2:	/* Hybrid */
1288cd9b132SSebastian Andrzej Siewior 		ret = platform_add_devices(sb1250_devs, 2);
1298cd9b132SSebastian Andrzej Siewior 		break;
1308cd9b132SSebastian Andrzej Siewior 	case K_SYS_SOC_TYPE_BCM1x55:
1318cd9b132SSebastian Andrzej Siewior 	case K_SYS_SOC_TYPE_BCM1x80:
1328cd9b132SSebastian Andrzej Siewior 		ret = platform_add_devices(sb1250_devs, 4);
1338cd9b132SSebastian Andrzej Siewior 		break;
1348cd9b132SSebastian Andrzej Siewior 	default:
1358cd9b132SSebastian Andrzej Siewior 		ret = -ENODEV;
1368cd9b132SSebastian Andrzej Siewior 		break;
1378cd9b132SSebastian Andrzej Siewior 	}
1388cd9b132SSebastian Andrzej Siewior 	return ret;
1398cd9b132SSebastian Andrzej Siewior }
1408cd9b132SSebastian Andrzej Siewior device_initcall(sb1250_device_init);
141