@@ -226,12 +226,42 @@ static struct uart_driver __read_mostly pl011_driver = {
.vuart_info = pl011_vuart,
};
+static int __init pl011_uart_init(int irq, u64 addr, u64 size)
+{
+ struct pl011 *uart;
+
+ uart = &pl011_com;
+ uart->irq = irq;
+ uart->clock_hz = 0x16e3600;
+ uart->baud = BAUD_AUTO;
+ uart->data_bits = 8;
+ uart->parity = PARITY_NONE;
+ uart->stop_bits = 1;
+
+ uart->regs = ioremap_nocache(addr, size);
+ if ( !uart->regs )
+ {
+ printk("pl011: Unable to map the UART memory\n");
+ return -ENOMEM;
+ }
+
+ uart->vuart.base_addr = addr;
+ uart->vuart.size = size;
+ uart->vuart.data_off = DR;
+ uart->vuart.status_off = FR;
+ uart->vuart.status = 0;
+
+ /* Register with generic serial driver. */
+ serial_register_uart(SERHND_DTUART, &pl011_driver, uart);
+
+ return 0;
+}
+
/* TODO: Parse UART config from the command line */
-static int __init pl011_uart_init(struct dt_device_node *dev,
- const void *data)
+static int __init pl011_dt_uart_init(struct dt_device_node *dev,
+ const void *data)
{
const char *config = data;
- struct pl011 *uart;
int res;
u64 addr, size;
@@ -240,14 +270,6 @@ static int __init pl011_uart_init(struct dt_device_node *dev,
printk("WARNING: UART configuration is not supported\n");
}
- uart = &pl011_com;
-
- uart->clock_hz = 0x16e3600;
- uart->baud = BAUD_AUTO;
- uart->data_bits = 8;
- uart->parity = PARITY_NONE;
- uart->stop_bits = 1;
-
res = dt_device_get_address(dev, 0, &addr, &size);
if ( res )
{
@@ -262,24 +284,14 @@ static int __init pl011_uart_init(struct dt_device_node *dev,
printk("pl011: Unable to retrieve the IRQ\n");
return -EINVAL;
}
- uart->irq = res;
- uart->regs = ioremap_nocache(addr, size);
- if ( !uart->regs )
+ res = pl011_uart_init(res, addr, size);
+ if ( res < 0 )
{
- printk("pl011: Unable to map the UART memory\n");
- return -ENOMEM;
+ printk("pl011: Unable to initialize\n");
+ return res;
}
- uart->vuart.base_addr = addr;
- uart->vuart.size = size;
- uart->vuart.data_off = DR;
- uart->vuart.status_off = FR;
- uart->vuart.status = 0;
-
- /* Register with generic serial driver. */
- serial_register_uart(SERHND_DTUART, &pl011_driver, uart);
-
dt_device_set_used_by(dev, DOMID_XEN);
return 0;
@@ -293,7 +305,7 @@ static const struct dt_device_match pl011_dt_match[] __initconst =
DT_DEVICE_START(pl011, "PL011 UART", DEVICE_SERIAL)
.dt_match = pl011_dt_match,
- .init = pl011_uart_init,
+ .init = pl011_dt_uart_init,
DT_DEVICE_END
/*