xref: /linux/arch/mips/cobalt/serial.c (revision 58e16d792a6a8c6b750f637a4649967fcac853dc)
1*16216333SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
2fb82a3a7SYoichi Yuasa /*
3fb82a3a7SYoichi Yuasa  *  Registration of Cobalt UART platform device.
4fb82a3a7SYoichi Yuasa  *
5ada8e951SYoichi Yuasa  *  Copyright (C) 2007  Yoichi Yuasa <yuasa@linux-mips.org>
6fb82a3a7SYoichi Yuasa  */
7fb82a3a7SYoichi Yuasa #include <linux/errno.h>
8fb82a3a7SYoichi Yuasa #include <linux/init.h>
9fb82a3a7SYoichi Yuasa #include <linux/ioport.h>
10fb82a3a7SYoichi Yuasa #include <linux/platform_device.h>
11fb82a3a7SYoichi Yuasa #include <linux/serial_8250.h>
12fb82a3a7SYoichi Yuasa 
13fb82a3a7SYoichi Yuasa #include <cobalt.h>
14d5ab1a69SYoichi Yuasa #include <irq.h>
15fb82a3a7SYoichi Yuasa 
16fb82a3a7SYoichi Yuasa static struct resource cobalt_uart_resource[] __initdata = {
17fb82a3a7SYoichi Yuasa 	{
18fb82a3a7SYoichi Yuasa 		.start	= 0x1c800000,
19fb82a3a7SYoichi Yuasa 		.end	= 0x1c800007,
20fb82a3a7SYoichi Yuasa 		.flags	= IORESOURCE_MEM,
21fb82a3a7SYoichi Yuasa 	},
22fb82a3a7SYoichi Yuasa 	{
23d5ab1a69SYoichi Yuasa 		.start	= SERIAL_IRQ,
24d5ab1a69SYoichi Yuasa 		.end	= SERIAL_IRQ,
25fb82a3a7SYoichi Yuasa 		.flags	= IORESOURCE_IRQ,
26fb82a3a7SYoichi Yuasa 	},
27fb82a3a7SYoichi Yuasa };
28fb82a3a7SYoichi Yuasa 
29fb82a3a7SYoichi Yuasa static struct plat_serial8250_port cobalt_serial8250_port[] = {
30fb82a3a7SYoichi Yuasa 	{
31d5ab1a69SYoichi Yuasa 		.irq		= SERIAL_IRQ,
32fb82a3a7SYoichi Yuasa 		.uartclk	= 18432000,
33fb82a3a7SYoichi Yuasa 		.iotype		= UPIO_MEM,
34fb82a3a7SYoichi Yuasa 		.flags		= UPF_IOREMAP | UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,
35fb82a3a7SYoichi Yuasa 		.mapbase	= 0x1c800000,
36fb82a3a7SYoichi Yuasa 	},
37fb82a3a7SYoichi Yuasa 	{},
38fb82a3a7SYoichi Yuasa };
39fb82a3a7SYoichi Yuasa 
cobalt_uart_add(void)40fb82a3a7SYoichi Yuasa static __init int cobalt_uart_add(void)
41fb82a3a7SYoichi Yuasa {
42fb82a3a7SYoichi Yuasa 	struct platform_device *pdev;
43fb82a3a7SYoichi Yuasa 	int retval;
44fb82a3a7SYoichi Yuasa 
45fb82a3a7SYoichi Yuasa 	/*
46ac1a236aSMartin Michlmayr 	 * Cobalt Qube1 has no UART.
47fb82a3a7SYoichi Yuasa 	 */
48ac1a236aSMartin Michlmayr 	if (cobalt_board_id == COBALT_BRD_ID_QUBE1)
49fb82a3a7SYoichi Yuasa 		return 0;
50fb82a3a7SYoichi Yuasa 
51fb82a3a7SYoichi Yuasa 	pdev = platform_device_alloc("serial8250", -1);
52fb82a3a7SYoichi Yuasa 	if (!pdev)
53fb82a3a7SYoichi Yuasa 		return -ENOMEM;
54fb82a3a7SYoichi Yuasa 
55fb82a3a7SYoichi Yuasa 	pdev->id = PLAT8250_DEV_PLATFORM;
56fb82a3a7SYoichi Yuasa 	pdev->dev.platform_data = cobalt_serial8250_port;
57fb82a3a7SYoichi Yuasa 
58fb82a3a7SYoichi Yuasa 	retval = platform_device_add_resources(pdev, cobalt_uart_resource, ARRAY_SIZE(cobalt_uart_resource));
59fb82a3a7SYoichi Yuasa 	if (retval)
60fb82a3a7SYoichi Yuasa 		goto err_free_device;
61fb82a3a7SYoichi Yuasa 
62fb82a3a7SYoichi Yuasa 	retval = platform_device_add(pdev);
63fb82a3a7SYoichi Yuasa 	if (retval)
64fb82a3a7SYoichi Yuasa 		goto err_free_device;
65fb82a3a7SYoichi Yuasa 
66fb82a3a7SYoichi Yuasa 	return 0;
67fb82a3a7SYoichi Yuasa 
68fb82a3a7SYoichi Yuasa err_free_device:
69fb82a3a7SYoichi Yuasa 	platform_device_put(pdev);
70fb82a3a7SYoichi Yuasa 
71fb82a3a7SYoichi Yuasa 	return retval;
72fb82a3a7SYoichi Yuasa }
73fb82a3a7SYoichi Yuasa device_initcall(cobalt_uart_add);
74