2 * Copyright (c) 2012, Intel Corporation
3 * Copyright (c) 2015, Red Hat, Inc.
4 * Copyright (c) 2015, 2016 Linaro Ltd.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
12 #define pr_fmt(fmt) "ACPI: SPCR: " fmt
14 #include <linux/acpi.h>
15 #include <linux/console.h>
16 #include <linux/kernel.h>
17 #include <linux/serial_core.h>
20 * parse_spcr() - parse ACPI SPCR table and add preferred console
22 * @earlycon: set up earlycon for the console specified by the table
24 * For the architectures with support for ACPI, CONFIG_ACPI_SPCR_TABLE may be
25 * defined to parse ACPI SPCR table. As a result of the parsing preferred
26 * console is registered and if @earlycon is true, earlycon is set up.
28 * When CONFIG_ACPI_SPCR_TABLE is defined, this function should be called
29 * from arch inintialization code as soon as the DT/ACPI decision is made.
32 int __init
parse_spcr(bool earlycon
)
35 struct acpi_table_spcr
*table
;
45 status
= acpi_get_table(ACPI_SIG_SPCR
, 0,
46 (struct acpi_table_header
**)&table
);
48 if (ACPI_FAILURE(status
))
51 if (table
->header
.revision
< 2) {
53 pr_err("wrong table version\n");
57 iotype
= table
->serial_port
.space_id
== ACPI_ADR_SPACE_SYSTEM_MEMORY
?
60 switch (table
->interface_type
) {
61 case ACPI_DBG2_ARM_SBSA_32BIT
:
64 case ACPI_DBG2_ARM_PL011
:
65 case ACPI_DBG2_ARM_SBSA_GENERIC
:
66 case ACPI_DBG2_BCM2835
:
69 case ACPI_DBG2_16550_COMPATIBLE
:
70 case ACPI_DBG2_16550_SUBSET
:
78 switch (table
->baud_rate
) {
96 snprintf(opts
, sizeof(opts
), "%s,%s,0x%llx,%d", uart
, iotype
,
97 table
->serial_port
.address
, baud_rate
);
99 pr_info("console: %s\n", opts
);
102 setup_earlycon(opts
);
104 err
= add_preferred_console(uart
, 0, opts
+ strlen(uart
) + 1);
107 acpi_put_table((struct acpi_table_header
*)table
);