18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci#include <linux/err.h>
38c2ecf20Sopenharmony_ci#include <linux/kernel.h>
48c2ecf20Sopenharmony_ci#include <linux/init.h>
58c2ecf20Sopenharmony_ci#include <linux/io.h>
68c2ecf20Sopenharmony_ci#include <linux/platform_device.h>
78c2ecf20Sopenharmony_ci#include <linux/ata_platform.h>
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#include <asm/sibyte/board.h>
108c2ecf20Sopenharmony_ci#include <asm/sibyte/sb1250_genbus.h>
118c2ecf20Sopenharmony_ci#include <asm/sibyte/sb1250_regs.h>
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci#if defined(CONFIG_SIBYTE_SWARM) || defined(CONFIG_SIBYTE_LITTLESUR)
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci#define DRV_NAME	"pata-swarm"
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci#define SWARM_IDE_SHIFT 5
188c2ecf20Sopenharmony_ci#define SWARM_IDE_BASE	0x1f0
198c2ecf20Sopenharmony_ci#define SWARM_IDE_CTRL	0x3f6
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_cistatic struct resource swarm_pata_resource[] = {
228c2ecf20Sopenharmony_ci	{
238c2ecf20Sopenharmony_ci		.name	= "Swarm GenBus IDE",
248c2ecf20Sopenharmony_ci		.flags	= IORESOURCE_MEM,
258c2ecf20Sopenharmony_ci	}, {
268c2ecf20Sopenharmony_ci		.name	= "Swarm GenBus IDE",
278c2ecf20Sopenharmony_ci		.flags	= IORESOURCE_MEM,
288c2ecf20Sopenharmony_ci	}, {
298c2ecf20Sopenharmony_ci		.name	= "Swarm GenBus IDE",
308c2ecf20Sopenharmony_ci		.flags	= IORESOURCE_IRQ,
318c2ecf20Sopenharmony_ci		.start	= K_INT_GB_IDE,
328c2ecf20Sopenharmony_ci		.end	= K_INT_GB_IDE,
338c2ecf20Sopenharmony_ci	},
348c2ecf20Sopenharmony_ci};
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_cistatic struct pata_platform_info pata_platform_data = {
378c2ecf20Sopenharmony_ci	.ioport_shift	= SWARM_IDE_SHIFT,
388c2ecf20Sopenharmony_ci};
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_cistatic struct platform_device swarm_pata_device = {
418c2ecf20Sopenharmony_ci	.name		= "pata_platform",
428c2ecf20Sopenharmony_ci	.id		= -1,
438c2ecf20Sopenharmony_ci	.resource	= swarm_pata_resource,
448c2ecf20Sopenharmony_ci	.num_resources	= ARRAY_SIZE(swarm_pata_resource),
458c2ecf20Sopenharmony_ci	.dev  = {
468c2ecf20Sopenharmony_ci		.platform_data		= &pata_platform_data,
478c2ecf20Sopenharmony_ci		.coherent_dma_mask	= ~0,	/* grumble */
488c2ecf20Sopenharmony_ci	},
498c2ecf20Sopenharmony_ci};
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_cistatic int __init swarm_pata_init(void)
528c2ecf20Sopenharmony_ci{
538c2ecf20Sopenharmony_ci	u8 __iomem *base;
548c2ecf20Sopenharmony_ci	phys_addr_t offset, size;
558c2ecf20Sopenharmony_ci	struct resource *r;
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci	if (!SIBYTE_HAVE_IDE)
588c2ecf20Sopenharmony_ci		return -ENODEV;
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci	base = ioremap(A_IO_EXT_BASE, 0x800);
618c2ecf20Sopenharmony_ci	offset = __raw_readq(base + R_IO_EXT_REG(R_IO_EXT_START_ADDR, IDE_CS));
628c2ecf20Sopenharmony_ci	size = __raw_readq(base + R_IO_EXT_REG(R_IO_EXT_MULT_SIZE, IDE_CS));
638c2ecf20Sopenharmony_ci	iounmap(base);
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci	offset = G_IO_START_ADDR(offset) << S_IO_ADDRBASE;
668c2ecf20Sopenharmony_ci	size = (G_IO_MULT_SIZE(size) + 1) << S_IO_REGSIZE;
678c2ecf20Sopenharmony_ci	if (offset < A_PHYS_GENBUS || offset >= A_PHYS_GENBUS_END) {
688c2ecf20Sopenharmony_ci		pr_info(DRV_NAME ": PATA interface at GenBus disabled\n");
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ci		return -EBUSY;
718c2ecf20Sopenharmony_ci	}
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci	pr_info(DRV_NAME ": PATA interface at GenBus slot %i\n", IDE_CS);
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ci	r = swarm_pata_resource;
768c2ecf20Sopenharmony_ci	r[0].start = offset + (SWARM_IDE_BASE << SWARM_IDE_SHIFT);
778c2ecf20Sopenharmony_ci	r[0].end   = offset + ((SWARM_IDE_BASE + 8) << SWARM_IDE_SHIFT) - 1;
788c2ecf20Sopenharmony_ci	r[1].start = offset + (SWARM_IDE_CTRL << SWARM_IDE_SHIFT);
798c2ecf20Sopenharmony_ci	r[1].end   = offset + ((SWARM_IDE_CTRL + 1) << SWARM_IDE_SHIFT) - 1;
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci	return platform_device_register(&swarm_pata_device);
828c2ecf20Sopenharmony_ci}
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_cidevice_initcall(swarm_pata_init);
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci#endif /* defined(CONFIG_SIBYTE_SWARM) || defined(CONFIG_SIBYTE_LITTLESUR) */
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci#define sb1250_dev_struct(num) \
898c2ecf20Sopenharmony_ci	static struct resource sb1250_res##num = {		\
908c2ecf20Sopenharmony_ci		.name = "SB1250 MAC " __stringify(num),		\
918c2ecf20Sopenharmony_ci		.flags = IORESOURCE_MEM,		\
928c2ecf20Sopenharmony_ci		.start = A_MAC_CHANNEL_BASE(num),	\
938c2ecf20Sopenharmony_ci		.end = A_MAC_CHANNEL_BASE(num + 1) -1,	\
948c2ecf20Sopenharmony_ci	};\
958c2ecf20Sopenharmony_ci	static struct platform_device sb1250_dev##num = {	\
968c2ecf20Sopenharmony_ci		.name = "sb1250-mac",			\
978c2ecf20Sopenharmony_ci	.id = num,					\
988c2ecf20Sopenharmony_ci	.resource = &sb1250_res##num,			\
998c2ecf20Sopenharmony_ci	.num_resources = 1,				\
1008c2ecf20Sopenharmony_ci	}
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_cisb1250_dev_struct(0);
1038c2ecf20Sopenharmony_cisb1250_dev_struct(1);
1048c2ecf20Sopenharmony_cisb1250_dev_struct(2);
1058c2ecf20Sopenharmony_cisb1250_dev_struct(3);
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_cistatic struct platform_device *sb1250_devs[] __initdata = {
1088c2ecf20Sopenharmony_ci	&sb1250_dev0,
1098c2ecf20Sopenharmony_ci	&sb1250_dev1,
1108c2ecf20Sopenharmony_ci	&sb1250_dev2,
1118c2ecf20Sopenharmony_ci	&sb1250_dev3,
1128c2ecf20Sopenharmony_ci};
1138c2ecf20Sopenharmony_ci
1148c2ecf20Sopenharmony_cistatic int __init sb1250_device_init(void)
1158c2ecf20Sopenharmony_ci{
1168c2ecf20Sopenharmony_ci	int ret;
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_ci	/* Set the number of available units based on the SOC type.  */
1198c2ecf20Sopenharmony_ci	switch (soc_type) {
1208c2ecf20Sopenharmony_ci	case K_SYS_SOC_TYPE_BCM1250:
1218c2ecf20Sopenharmony_ci	case K_SYS_SOC_TYPE_BCM1250_ALT:
1228c2ecf20Sopenharmony_ci		ret = platform_add_devices(sb1250_devs, 3);
1238c2ecf20Sopenharmony_ci		break;
1248c2ecf20Sopenharmony_ci	case K_SYS_SOC_TYPE_BCM1120:
1258c2ecf20Sopenharmony_ci	case K_SYS_SOC_TYPE_BCM1125:
1268c2ecf20Sopenharmony_ci	case K_SYS_SOC_TYPE_BCM1125H:
1278c2ecf20Sopenharmony_ci	case K_SYS_SOC_TYPE_BCM1250_ALT2:	/* Hybrid */
1288c2ecf20Sopenharmony_ci		ret = platform_add_devices(sb1250_devs, 2);
1298c2ecf20Sopenharmony_ci		break;
1308c2ecf20Sopenharmony_ci	case K_SYS_SOC_TYPE_BCM1x55:
1318c2ecf20Sopenharmony_ci	case K_SYS_SOC_TYPE_BCM1x80:
1328c2ecf20Sopenharmony_ci		ret = platform_add_devices(sb1250_devs, 4);
1338c2ecf20Sopenharmony_ci		break;
1348c2ecf20Sopenharmony_ci	default:
1358c2ecf20Sopenharmony_ci		ret = -ENODEV;
1368c2ecf20Sopenharmony_ci		break;
1378c2ecf20Sopenharmony_ci	}
1388c2ecf20Sopenharmony_ci	return ret;
1398c2ecf20Sopenharmony_ci}
1408c2ecf20Sopenharmony_cidevice_initcall(sb1250_device_init);
141