1 // SPDX-License-Identifier: GPL-2.0
3 * SGI IOC3 8250 UART driver
5 * Copyright (C) 2019 Thomas Bogendoerfer <tbogendoerfer@suse.de>
7 * based on code Copyright (C) 2005 Stanislaw Skowronek <skylark@unaligned.org>
8 * Copyright (C) 2014 Joshua Kinard <kumba@gentoo.org>
11 #include <linux/module.h>
12 #include <linux/errno.h>
14 #include <linux/platform_device.h>
18 #define IOC3_UARTCLK (22000000 / 3)
20 struct ioc3_8250_data
{
24 static unsigned int ioc3_serial_in(struct uart_port
*p
, int offset
)
26 return readb(p
->membase
+ (offset
^ 3));
29 static void ioc3_serial_out(struct uart_port
*p
, int offset
, int value
)
31 writeb(value
, p
->membase
+ (offset
^ 3));
34 static int serial8250_ioc3_probe(struct platform_device
*pdev
)
36 struct ioc3_8250_data
*data
;
37 struct uart_8250_port up
;
39 void __iomem
*membase
;
42 r
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
46 data
= devm_kzalloc(&pdev
->dev
, sizeof(*data
), GFP_KERNEL
);
50 membase
= devm_ioremap(&pdev
->dev
, r
->start
, resource_size(r
));
54 irq
= platform_get_irq(pdev
, 0);
56 irq
= 0; /* no interrupt -> use polling */
58 /* Register serial ports with 8250.c */
59 memset(&up
, 0, sizeof(struct uart_8250_port
));
60 up
.port
.iotype
= UPIO_MEM
;
61 up
.port
.uartclk
= IOC3_UARTCLK
;
62 up
.port
.type
= PORT_16550A
;
64 up
.port
.flags
= (UPF_BOOT_AUTOCONF
| UPF_SHARE_IRQ
);
65 up
.port
.dev
= &pdev
->dev
;
66 up
.port
.membase
= membase
;
67 up
.port
.mapbase
= r
->start
;
68 up
.port
.serial_in
= ioc3_serial_in
;
69 up
.port
.serial_out
= ioc3_serial_out
;
70 line
= serial8250_register_8250_port(&up
);
74 platform_set_drvdata(pdev
, data
);
78 static int serial8250_ioc3_remove(struct platform_device
*pdev
)
80 struct ioc3_8250_data
*data
= platform_get_drvdata(pdev
);
82 serial8250_unregister_port(data
->line
);
86 static struct platform_driver serial8250_ioc3_driver
= {
87 .probe
= serial8250_ioc3_probe
,
88 .remove
= serial8250_ioc3_remove
,
90 .name
= "ioc3-serial8250",
94 module_platform_driver(serial8250_ioc3_driver
);
96 MODULE_AUTHOR("Thomas Bogendoerfer <tbogendoerfer@suse.de>");
97 MODULE_DESCRIPTION("SGI IOC3 8250 UART driver");
98 MODULE_LICENSE("GPL");