blob: 9d52743080a4f65200ea6e33f0d0d2fefdb881ea [file] [log] [blame]
Aleksey Makarovad1696f2016-09-27 23:54:13 +03001/*
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
Christopher Covingtond8a49952017-02-15 16:39:43 -050019/*
Timur Tabi37ef38f2017-07-27 16:15:52 -050020 * Erratum 44 for QDF2432v1 and QDF2400v1 SoCs describes the BUSY bit as
21 * occasionally getting stuck as 1. To avoid the potential for a hang, check
22 * TXFE == 0 instead of BUSY == 1. This may not be suitable for all UART
23 * implementations, so only do so if an affected platform is detected in
Prarit Bhargava0231d002018-01-18 10:09:51 -050024 * acpi_parse_spcr().
Timur Tabi37ef38f2017-07-27 16:15:52 -050025 */
26bool qdf2400_e44_present;
27EXPORT_SYMBOL(qdf2400_e44_present);
28
29/*
Christopher Covingtond8a49952017-02-15 16:39:43 -050030 * Some Qualcomm Datacenter Technologies SoCs have a defective UART BUSY bit.
31 * Detect them by examining the OEM fields in the SPCR header, similiar to PCI
32 * quirk detection in pci_mcfg.c.
33 */
34static bool qdf2400_erratum_44_present(struct acpi_table_header *h)
35{
36 if (memcmp(h->oem_id, "QCOM ", ACPI_OEM_ID_SIZE))
37 return false;
38
39 if (!memcmp(h->oem_table_id, "QDF2432 ", ACPI_OEM_TABLE_ID_SIZE))
40 return true;
41
42 if (!memcmp(h->oem_table_id, "QDF2400 ", ACPI_OEM_TABLE_ID_SIZE) &&
Timur Tabi542ed782017-02-28 14:30:33 -060043 h->oem_revision == 1)
Christopher Covingtond8a49952017-02-15 16:39:43 -050044 return true;
45
46 return false;
47}
48
Loc Ho79a64832017-07-03 14:33:09 -070049/*
50 * APM X-Gene v1 and v2 UART hardware is an 16550 like device but has its
51 * register aligned to 32-bit. In addition, the BIOS also encoded the
52 * access width to be 8 bits. This function detects this errata condition.
53 */
54static bool xgene_8250_erratum_present(struct acpi_table_spcr *tb)
55{
Graeme Gregorydee82bc2017-08-04 22:49:43 +010056 bool xgene_8250 = false;
57
Loc Ho79a64832017-07-03 14:33:09 -070058 if (tb->interface_type != ACPI_DBG2_16550_COMPATIBLE)
59 return false;
60
Graeme Gregorydee82bc2017-08-04 22:49:43 +010061 if (memcmp(tb->header.oem_id, "APMC0D", ACPI_OEM_ID_SIZE) &&
62 memcmp(tb->header.oem_id, "HPE ", ACPI_OEM_ID_SIZE))
Loc Ho79a64832017-07-03 14:33:09 -070063 return false;
64
65 if (!memcmp(tb->header.oem_table_id, "XGENESPC",
66 ACPI_OEM_TABLE_ID_SIZE) && tb->header.oem_revision == 0)
Graeme Gregorydee82bc2017-08-04 22:49:43 +010067 xgene_8250 = true;
Loc Ho79a64832017-07-03 14:33:09 -070068
Graeme Gregorydee82bc2017-08-04 22:49:43 +010069 if (!memcmp(tb->header.oem_table_id, "ProLiant",
70 ACPI_OEM_TABLE_ID_SIZE) && tb->header.oem_revision == 1)
71 xgene_8250 = true;
72
73 return xgene_8250;
Loc Ho79a64832017-07-03 14:33:09 -070074}
75
Aleksey Makarovad1696f2016-09-27 23:54:13 +030076/**
Prarit Bhargava0231d002018-01-18 10:09:51 -050077 * acpi_parse_spcr() - parse ACPI SPCR table and add preferred console
Aleksey Makarovad1696f2016-09-27 23:54:13 +030078 *
Prarit Bhargava0231d002018-01-18 10:09:51 -050079 * @enable_earlycon: set up earlycon for the console specified by the table
80 * @enable_console: setup the console specified by the table.
Aleksey Makarovad1696f2016-09-27 23:54:13 +030081 *
82 * For the architectures with support for ACPI, CONFIG_ACPI_SPCR_TABLE may be
83 * defined to parse ACPI SPCR table. As a result of the parsing preferred
Prarit Bhargava0231d002018-01-18 10:09:51 -050084 * console is registered and if @enable_earlycon is true, earlycon is set up.
85 * If @enable_console is true the system console is also configured.
Aleksey Makarovad1696f2016-09-27 23:54:13 +030086 *
87 * When CONFIG_ACPI_SPCR_TABLE is defined, this function should be called
Masahiro Yamada183b8022017-02-27 14:29:20 -080088 * from arch initialization code as soon as the DT/ACPI decision is made.
Aleksey Makarovad1696f2016-09-27 23:54:13 +030089 *
90 */
Prarit Bhargava0231d002018-01-18 10:09:51 -050091int __init acpi_parse_spcr(bool enable_earlycon, bool enable_console)
Aleksey Makarovad1696f2016-09-27 23:54:13 +030092{
93 static char opts[64];
94 struct acpi_table_spcr *table;
Aleksey Makarovad1696f2016-09-27 23:54:13 +030095 acpi_status status;
96 char *uart;
97 char *iotype;
98 int baud_rate;
99 int err;
100
101 if (acpi_disabled)
102 return -ENODEV;
103
Lv Zheng6b11d1d2016-12-14 15:04:39 +0800104 status = acpi_get_table(ACPI_SIG_SPCR, 0,
105 (struct acpi_table_header **)&table);
Aleksey Makarovad1696f2016-09-27 23:54:13 +0300106
107 if (ACPI_FAILURE(status))
108 return -ENOENT;
109
Prarit Bhargava0231d002018-01-18 10:09:51 -0500110 if (table->header.revision < 2)
111 pr_info("SPCR table version %d\n", table->header.revision);
Aleksey Makarovad1696f2016-09-27 23:54:13 +0300112
Loc Ho2bece492017-07-03 14:33:08 -0700113 if (table->serial_port.space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) {
Lv Zheng4eebedd2017-08-03 14:26:19 +0800114 switch (ACPI_ACCESS_BIT_WIDTH((
115 table->serial_port.access_width))) {
Loc Ho2bece492017-07-03 14:33:08 -0700116 default:
117 pr_err("Unexpected SPCR Access Width. Defaulting to byte size\n");
Gustavo A. R. Silva5a9e59e2018-02-09 12:08:21 -0600118 /* fall through */
Lv Zheng4eebedd2017-08-03 14:26:19 +0800119 case 8:
Loc Ho2bece492017-07-03 14:33:08 -0700120 iotype = "mmio";
121 break;
Lv Zheng4eebedd2017-08-03 14:26:19 +0800122 case 16:
Loc Ho2bece492017-07-03 14:33:08 -0700123 iotype = "mmio16";
124 break;
Lv Zheng4eebedd2017-08-03 14:26:19 +0800125 case 32:
Loc Ho2bece492017-07-03 14:33:08 -0700126 iotype = "mmio32";
127 break;
128 }
129 } else
130 iotype = "io";
Aleksey Makarovad1696f2016-09-27 23:54:13 +0300131
132 switch (table->interface_type) {
133 case ACPI_DBG2_ARM_SBSA_32BIT:
134 iotype = "mmio32";
135 /* fall through */
136 case ACPI_DBG2_ARM_PL011:
137 case ACPI_DBG2_ARM_SBSA_GENERIC:
138 case ACPI_DBG2_BCM2835:
139 uart = "pl011";
140 break;
141 case ACPI_DBG2_16550_COMPATIBLE:
142 case ACPI_DBG2_16550_SUBSET:
143 uart = "uart";
144 break;
145 default:
146 err = -ENOENT;
147 goto done;
148 }
149
150 switch (table->baud_rate) {
151 case 3:
152 baud_rate = 9600;
153 break;
154 case 4:
155 baud_rate = 19200;
156 break;
157 case 6:
158 baud_rate = 57600;
159 break;
160 case 7:
161 baud_rate = 115200;
162 break;
163 default:
164 err = -ENOENT;
165 goto done;
166 }
167
Timur Tabi37ef38f2017-07-27 16:15:52 -0500168 /*
169 * If the E44 erratum is required, then we need to tell the pl011
170 * driver to implement the work-around.
171 *
172 * The global variable is used by the probe function when it
173 * creates the UARTs, whether or not they're used as a console.
174 *
175 * If the user specifies "traditional" earlycon, the qdf2400_e44
176 * console name matches the EARLYCON_DECLARE() statement, and
177 * SPCR is not used. Parameter "earlycon" is false.
178 *
179 * If the user specifies "SPCR" earlycon, then we need to update
180 * the console name so that it also says "qdf2400_e44". Parameter
181 * "earlycon" is true.
182 *
183 * For consistency, if we change the console name, then we do it
184 * for everyone, not just earlycon.
185 */
186 if (qdf2400_erratum_44_present(&table->header)) {
187 qdf2400_e44_present = true;
Prarit Bhargava0231d002018-01-18 10:09:51 -0500188 if (enable_earlycon)
Timur Tabi37ef38f2017-07-27 16:15:52 -0500189 uart = "qdf2400_e44";
190 }
191
Graeme Gregory03c38762017-08-04 22:49:44 +0100192 if (xgene_8250_erratum_present(table)) {
Loc Ho79a64832017-07-03 14:33:09 -0700193 iotype = "mmio32";
Christopher Covingtond8a49952017-02-15 16:39:43 -0500194
Graeme Gregory03c38762017-08-04 22:49:44 +0100195 /* for xgene v1 and v2 we don't know the clock rate of the
196 * UART so don't attempt to change to the baud rate state
197 * in the table because driver cannot calculate the dividers
198 */
199 snprintf(opts, sizeof(opts), "%s,%s,0x%llx", uart, iotype,
200 table->serial_port.address);
201 } else {
202 snprintf(opts, sizeof(opts), "%s,%s,0x%llx,%d", uart, iotype,
203 table->serial_port.address, baud_rate);
204 }
Aleksey Makarovad1696f2016-09-27 23:54:13 +0300205
206 pr_info("console: %s\n", opts);
207
Prarit Bhargava0231d002018-01-18 10:09:51 -0500208 if (enable_earlycon)
Aleksey Makarovad1696f2016-09-27 23:54:13 +0300209 setup_earlycon(opts);
210
Prarit Bhargava0231d002018-01-18 10:09:51 -0500211 if (enable_console)
212 err = add_preferred_console(uart, 0, opts + strlen(uart) + 1);
213 else
214 err = 0;
Aleksey Makarovad1696f2016-09-27 23:54:13 +0300215done:
Lv Zheng6b11d1d2016-12-14 15:04:39 +0800216 acpi_put_table((struct acpi_table_header *)table);
Aleksey Makarovad1696f2016-09-27 23:54:13 +0300217 return err;
218}