18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * This file is subject to the terms and conditions of the GNU General Public
38c2ecf20Sopenharmony_ci * License.  See the file "COPYING" in the main directory of this archive
48c2ecf20Sopenharmony_ci * for more details.
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
78c2ecf20Sopenharmony_ci */
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#include <linux/init.h>
108c2ecf20Sopenharmony_ci#include <linux/kernel.h>
118c2ecf20Sopenharmony_ci#include <linux/platform_device.h>
128c2ecf20Sopenharmony_ci#include <bcm63xx_cpu.h>
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_cistatic struct resource uart0_resources[] = {
158c2ecf20Sopenharmony_ci	{
168c2ecf20Sopenharmony_ci		/* start & end filled at runtime */
178c2ecf20Sopenharmony_ci		.flags		= IORESOURCE_MEM,
188c2ecf20Sopenharmony_ci	},
198c2ecf20Sopenharmony_ci	{
208c2ecf20Sopenharmony_ci		/* start filled at runtime */
218c2ecf20Sopenharmony_ci		.flags		= IORESOURCE_IRQ,
228c2ecf20Sopenharmony_ci	},
238c2ecf20Sopenharmony_ci};
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_cistatic struct resource uart1_resources[] = {
268c2ecf20Sopenharmony_ci	{
278c2ecf20Sopenharmony_ci		/* start & end filled at runtime */
288c2ecf20Sopenharmony_ci		.flags		= IORESOURCE_MEM,
298c2ecf20Sopenharmony_ci	},
308c2ecf20Sopenharmony_ci	{
318c2ecf20Sopenharmony_ci		/* start filled at runtime */
328c2ecf20Sopenharmony_ci		.flags		= IORESOURCE_IRQ,
338c2ecf20Sopenharmony_ci	},
348c2ecf20Sopenharmony_ci};
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_cistatic struct platform_device bcm63xx_uart_devices[] = {
378c2ecf20Sopenharmony_ci	{
388c2ecf20Sopenharmony_ci		.name		= "bcm63xx_uart",
398c2ecf20Sopenharmony_ci		.id		= 0,
408c2ecf20Sopenharmony_ci		.num_resources	= ARRAY_SIZE(uart0_resources),
418c2ecf20Sopenharmony_ci		.resource	= uart0_resources,
428c2ecf20Sopenharmony_ci	},
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci	{
458c2ecf20Sopenharmony_ci		.name		= "bcm63xx_uart",
468c2ecf20Sopenharmony_ci		.id		= 1,
478c2ecf20Sopenharmony_ci		.num_resources	= ARRAY_SIZE(uart1_resources),
488c2ecf20Sopenharmony_ci		.resource	= uart1_resources,
498c2ecf20Sopenharmony_ci	}
508c2ecf20Sopenharmony_ci};
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ciint __init bcm63xx_uart_register(unsigned int id)
538c2ecf20Sopenharmony_ci{
548c2ecf20Sopenharmony_ci	if (id >= ARRAY_SIZE(bcm63xx_uart_devices))
558c2ecf20Sopenharmony_ci		return -ENODEV;
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci	if (id == 1 && (!BCMCPU_IS_3368() && !BCMCPU_IS_6358() &&
588c2ecf20Sopenharmony_ci		!BCMCPU_IS_6368()))
598c2ecf20Sopenharmony_ci		return -ENODEV;
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ci	if (id == 0) {
628c2ecf20Sopenharmony_ci		uart0_resources[0].start = bcm63xx_regset_address(RSET_UART0);
638c2ecf20Sopenharmony_ci		uart0_resources[0].end = uart0_resources[0].start +
648c2ecf20Sopenharmony_ci			RSET_UART_SIZE - 1;
658c2ecf20Sopenharmony_ci		uart0_resources[1].start = bcm63xx_get_irq_number(IRQ_UART0);
668c2ecf20Sopenharmony_ci	}
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci	if (id == 1) {
698c2ecf20Sopenharmony_ci		uart1_resources[0].start = bcm63xx_regset_address(RSET_UART1);
708c2ecf20Sopenharmony_ci		uart1_resources[0].end = uart1_resources[0].start +
718c2ecf20Sopenharmony_ci			RSET_UART_SIZE - 1;
728c2ecf20Sopenharmony_ci		uart1_resources[1].start = bcm63xx_get_irq_number(IRQ_UART1);
738c2ecf20Sopenharmony_ci	}
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ci	return platform_device_register(&bcm63xx_uart_devices[id]);
768c2ecf20Sopenharmony_ci}
77