]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blob - drivers/acpi/spcr.c
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input
[mirror_ubuntu-zesty-kernel.git] / drivers / acpi / spcr.c
1 /*
2 * Copyright (c) 2012, Intel Corporation
3 * Copyright (c) 2015, Red Hat, Inc.
4 * Copyright (c) 2015, 2016 Linaro Ltd.
5 *
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.
9 *
10 */
11
12 #define pr_fmt(fmt) "ACPI: SPCR: " fmt
13
14 #include <linux/acpi.h>
15 #include <linux/console.h>
16 #include <linux/kernel.h>
17 #include <linux/serial_core.h>
18
19 /**
20 * parse_spcr() - parse ACPI SPCR table and add preferred console
21 *
22 * @earlycon: set up earlycon for the console specified by the table
23 *
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.
27 *
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.
30 *
31 */
32 int __init parse_spcr(bool earlycon)
33 {
34 static char opts[64];
35 struct acpi_table_spcr *table;
36 acpi_size table_size;
37 acpi_status status;
38 char *uart;
39 char *iotype;
40 int baud_rate;
41 int err;
42
43 if (acpi_disabled)
44 return -ENODEV;
45
46 status = acpi_get_table_with_size(ACPI_SIG_SPCR, 0,
47 (struct acpi_table_header **)&table,
48 &table_size);
49
50 if (ACPI_FAILURE(status))
51 return -ENOENT;
52
53 if (table->header.revision < 2) {
54 err = -ENOENT;
55 pr_err("wrong table version\n");
56 goto done;
57 }
58
59 iotype = table->serial_port.space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY ?
60 "mmio" : "io";
61
62 switch (table->interface_type) {
63 case ACPI_DBG2_ARM_SBSA_32BIT:
64 iotype = "mmio32";
65 /* fall through */
66 case ACPI_DBG2_ARM_PL011:
67 case ACPI_DBG2_ARM_SBSA_GENERIC:
68 case ACPI_DBG2_BCM2835:
69 uart = "pl011";
70 break;
71 case ACPI_DBG2_16550_COMPATIBLE:
72 case ACPI_DBG2_16550_SUBSET:
73 uart = "uart";
74 break;
75 default:
76 err = -ENOENT;
77 goto done;
78 }
79
80 switch (table->baud_rate) {
81 case 3:
82 baud_rate = 9600;
83 break;
84 case 4:
85 baud_rate = 19200;
86 break;
87 case 6:
88 baud_rate = 57600;
89 break;
90 case 7:
91 baud_rate = 115200;
92 break;
93 default:
94 err = -ENOENT;
95 goto done;
96 }
97
98 snprintf(opts, sizeof(opts), "%s,%s,0x%llx,%d", uart, iotype,
99 table->serial_port.address, baud_rate);
100
101 pr_info("console: %s\n", opts);
102
103 if (earlycon)
104 setup_earlycon(opts);
105
106 err = add_preferred_console(uart, 0, opts + strlen(uart) + 1);
107
108 done:
109 early_acpi_os_unmap_memory((void __iomem *)table, table_size);
110 return err;
111 }