Aleksey Makarov | ad1696f | 2016-09-27 23:54:13 +0300 | [diff] [blame] | 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 | |
Christopher Covington | d8a4995 | 2017-02-15 16:39:43 -0500 | [diff] [blame] | 19 | /* |
Timur Tabi | 37ef38f | 2017-07-27 16:15:52 -0500 | [diff] [blame] | 20 | * 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 |
| 24 | * parse_spcr(). |
| 25 | */ |
| 26 | bool qdf2400_e44_present; |
| 27 | EXPORT_SYMBOL(qdf2400_e44_present); |
| 28 | |
| 29 | /* |
Christopher Covington | d8a4995 | 2017-02-15 16:39:43 -0500 | [diff] [blame] | 30 | * 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 | */ |
| 34 | static 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 Tabi | 542ed78 | 2017-02-28 14:30:33 -0600 | [diff] [blame] | 43 | h->oem_revision == 1) |
Christopher Covington | d8a4995 | 2017-02-15 16:39:43 -0500 | [diff] [blame] | 44 | return true; |
| 45 | |
| 46 | return false; |
| 47 | } |
| 48 | |
Loc Ho | 79a6483 | 2017-07-03 14:33:09 -0700 | [diff] [blame] | 49 | /* |
| 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 | */ |
| 54 | static bool xgene_8250_erratum_present(struct acpi_table_spcr *tb) |
| 55 | { |
Graeme Gregory | dee82bc | 2017-08-04 22:49:43 +0100 | [diff] [blame] | 56 | bool xgene_8250 = false; |
| 57 | |
Loc Ho | 79a6483 | 2017-07-03 14:33:09 -0700 | [diff] [blame] | 58 | if (tb->interface_type != ACPI_DBG2_16550_COMPATIBLE) |
| 59 | return false; |
| 60 | |
Graeme Gregory | dee82bc | 2017-08-04 22:49:43 +0100 | [diff] [blame] | 61 | if (memcmp(tb->header.oem_id, "APMC0D", ACPI_OEM_ID_SIZE) && |
| 62 | memcmp(tb->header.oem_id, "HPE ", ACPI_OEM_ID_SIZE)) |
Loc Ho | 79a6483 | 2017-07-03 14:33:09 -0700 | [diff] [blame] | 63 | return false; |
| 64 | |
| 65 | if (!memcmp(tb->header.oem_table_id, "XGENESPC", |
| 66 | ACPI_OEM_TABLE_ID_SIZE) && tb->header.oem_revision == 0) |
Graeme Gregory | dee82bc | 2017-08-04 22:49:43 +0100 | [diff] [blame] | 67 | xgene_8250 = true; |
Loc Ho | 79a6483 | 2017-07-03 14:33:09 -0700 | [diff] [blame] | 68 | |
Graeme Gregory | dee82bc | 2017-08-04 22:49:43 +0100 | [diff] [blame] | 69 | 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 Ho | 79a6483 | 2017-07-03 14:33:09 -0700 | [diff] [blame] | 74 | } |
| 75 | |
Aleksey Makarov | ad1696f | 2016-09-27 23:54:13 +0300 | [diff] [blame] | 76 | /** |
| 77 | * parse_spcr() - parse ACPI SPCR table and add preferred console |
| 78 | * |
| 79 | * @earlycon: set up earlycon for the console specified by the table |
| 80 | * |
| 81 | * For the architectures with support for ACPI, CONFIG_ACPI_SPCR_TABLE may be |
| 82 | * defined to parse ACPI SPCR table. As a result of the parsing preferred |
| 83 | * console is registered and if @earlycon is true, earlycon is set up. |
| 84 | * |
| 85 | * When CONFIG_ACPI_SPCR_TABLE is defined, this function should be called |
Masahiro Yamada | 183b802 | 2017-02-27 14:29:20 -0800 | [diff] [blame] | 86 | * from arch initialization code as soon as the DT/ACPI decision is made. |
Aleksey Makarov | ad1696f | 2016-09-27 23:54:13 +0300 | [diff] [blame] | 87 | * |
| 88 | */ |
| 89 | int __init parse_spcr(bool earlycon) |
| 90 | { |
| 91 | static char opts[64]; |
| 92 | struct acpi_table_spcr *table; |
Aleksey Makarov | ad1696f | 2016-09-27 23:54:13 +0300 | [diff] [blame] | 93 | acpi_status status; |
| 94 | char *uart; |
| 95 | char *iotype; |
| 96 | int baud_rate; |
| 97 | int err; |
| 98 | |
| 99 | if (acpi_disabled) |
| 100 | return -ENODEV; |
| 101 | |
Lv Zheng | 6b11d1d | 2016-12-14 15:04:39 +0800 | [diff] [blame] | 102 | status = acpi_get_table(ACPI_SIG_SPCR, 0, |
| 103 | (struct acpi_table_header **)&table); |
Aleksey Makarov | ad1696f | 2016-09-27 23:54:13 +0300 | [diff] [blame] | 104 | |
| 105 | if (ACPI_FAILURE(status)) |
| 106 | return -ENOENT; |
| 107 | |
| 108 | if (table->header.revision < 2) { |
| 109 | err = -ENOENT; |
| 110 | pr_err("wrong table version\n"); |
| 111 | goto done; |
| 112 | } |
| 113 | |
Loc Ho | 2bece49 | 2017-07-03 14:33:08 -0700 | [diff] [blame] | 114 | if (table->serial_port.space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) { |
| 115 | switch (table->serial_port.access_width) { |
| 116 | default: |
| 117 | pr_err("Unexpected SPCR Access Width. Defaulting to byte size\n"); |
| 118 | case ACPI_ACCESS_SIZE_BYTE: |
| 119 | iotype = "mmio"; |
| 120 | break; |
| 121 | case ACPI_ACCESS_SIZE_WORD: |
| 122 | iotype = "mmio16"; |
| 123 | break; |
| 124 | case ACPI_ACCESS_SIZE_DWORD: |
| 125 | iotype = "mmio32"; |
| 126 | break; |
| 127 | } |
| 128 | } else |
| 129 | iotype = "io"; |
Aleksey Makarov | ad1696f | 2016-09-27 23:54:13 +0300 | [diff] [blame] | 130 | |
| 131 | switch (table->interface_type) { |
| 132 | case ACPI_DBG2_ARM_SBSA_32BIT: |
| 133 | iotype = "mmio32"; |
| 134 | /* fall through */ |
| 135 | case ACPI_DBG2_ARM_PL011: |
| 136 | case ACPI_DBG2_ARM_SBSA_GENERIC: |
| 137 | case ACPI_DBG2_BCM2835: |
| 138 | uart = "pl011"; |
| 139 | break; |
| 140 | case ACPI_DBG2_16550_COMPATIBLE: |
| 141 | case ACPI_DBG2_16550_SUBSET: |
| 142 | uart = "uart"; |
| 143 | break; |
| 144 | default: |
| 145 | err = -ENOENT; |
| 146 | goto done; |
| 147 | } |
| 148 | |
| 149 | switch (table->baud_rate) { |
| 150 | case 3: |
| 151 | baud_rate = 9600; |
| 152 | break; |
| 153 | case 4: |
| 154 | baud_rate = 19200; |
| 155 | break; |
| 156 | case 6: |
| 157 | baud_rate = 57600; |
| 158 | break; |
| 159 | case 7: |
| 160 | baud_rate = 115200; |
| 161 | break; |
| 162 | default: |
| 163 | err = -ENOENT; |
| 164 | goto done; |
| 165 | } |
| 166 | |
Timur Tabi | 37ef38f | 2017-07-27 16:15:52 -0500 | [diff] [blame] | 167 | /* |
| 168 | * If the E44 erratum is required, then we need to tell the pl011 |
| 169 | * driver to implement the work-around. |
| 170 | * |
| 171 | * The global variable is used by the probe function when it |
| 172 | * creates the UARTs, whether or not they're used as a console. |
| 173 | * |
| 174 | * If the user specifies "traditional" earlycon, the qdf2400_e44 |
| 175 | * console name matches the EARLYCON_DECLARE() statement, and |
| 176 | * SPCR is not used. Parameter "earlycon" is false. |
| 177 | * |
| 178 | * If the user specifies "SPCR" earlycon, then we need to update |
| 179 | * the console name so that it also says "qdf2400_e44". Parameter |
| 180 | * "earlycon" is true. |
| 181 | * |
| 182 | * For consistency, if we change the console name, then we do it |
| 183 | * for everyone, not just earlycon. |
| 184 | */ |
| 185 | if (qdf2400_erratum_44_present(&table->header)) { |
| 186 | qdf2400_e44_present = true; |
| 187 | if (earlycon) |
| 188 | uart = "qdf2400_e44"; |
| 189 | } |
| 190 | |
Graeme Gregory | 03c3876 | 2017-08-04 22:49:44 +0100 | [diff] [blame^] | 191 | if (xgene_8250_erratum_present(table)) { |
Loc Ho | 79a6483 | 2017-07-03 14:33:09 -0700 | [diff] [blame] | 192 | iotype = "mmio32"; |
Christopher Covington | d8a4995 | 2017-02-15 16:39:43 -0500 | [diff] [blame] | 193 | |
Graeme Gregory | 03c3876 | 2017-08-04 22:49:44 +0100 | [diff] [blame^] | 194 | /* for xgene v1 and v2 we don't know the clock rate of the |
| 195 | * UART so don't attempt to change to the baud rate state |
| 196 | * in the table because driver cannot calculate the dividers |
| 197 | */ |
| 198 | snprintf(opts, sizeof(opts), "%s,%s,0x%llx", uart, iotype, |
| 199 | table->serial_port.address); |
| 200 | } else { |
| 201 | snprintf(opts, sizeof(opts), "%s,%s,0x%llx,%d", uart, iotype, |
| 202 | table->serial_port.address, baud_rate); |
| 203 | } |
Aleksey Makarov | ad1696f | 2016-09-27 23:54:13 +0300 | [diff] [blame] | 204 | |
| 205 | pr_info("console: %s\n", opts); |
| 206 | |
| 207 | if (earlycon) |
| 208 | setup_earlycon(opts); |
| 209 | |
| 210 | err = add_preferred_console(uart, 0, opts + strlen(uart) + 1); |
| 211 | |
| 212 | done: |
Lv Zheng | 6b11d1d | 2016-12-14 15:04:39 +0800 | [diff] [blame] | 213 | acpi_put_table((struct acpi_table_header *)table); |
Aleksey Makarov | ad1696f | 2016-09-27 23:54:13 +0300 | [diff] [blame] | 214 | return err; |
| 215 | } |