]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - drivers/acpi/spcr.c
UBUNTU: Ubuntu-4.10.0-37.41
[mirror_ubuntu-zesty-kernel.git] / drivers / acpi / spcr.c
CommitLineData
ad1696f6
AM
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
686378f9
TT
19/*
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 */
26bool qdf2400_e44_present;
27EXPORT_SYMBOL(qdf2400_e44_present);
28
02f469fe
SH
29/*
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 */
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) &&
d0704005 43 h->oem_revision == 1)
02f469fe
SH
44 return true;
45
46 return false;
47}
48
ad1696f6
AM
49/**
50 * parse_spcr() - parse ACPI SPCR table and add preferred console
51 *
52 * @earlycon: set up earlycon for the console specified by the table
53 *
54 * For the architectures with support for ACPI, CONFIG_ACPI_SPCR_TABLE may be
55 * defined to parse ACPI SPCR table. As a result of the parsing preferred
56 * console is registered and if @earlycon is true, earlycon is set up.
57 *
58 * When CONFIG_ACPI_SPCR_TABLE is defined, this function should be called
59 * from arch inintialization code as soon as the DT/ACPI decision is made.
60 *
61 */
62int __init parse_spcr(bool earlycon)
63{
64 static char opts[64];
65 struct acpi_table_spcr *table;
ad1696f6
AM
66 acpi_status status;
67 char *uart;
68 char *iotype;
69 int baud_rate;
70 int err;
71
72 if (acpi_disabled)
73 return -ENODEV;
74
6b11d1d6
LZ
75 status = acpi_get_table(ACPI_SIG_SPCR, 0,
76 (struct acpi_table_header **)&table);
ad1696f6
AM
77
78 if (ACPI_FAILURE(status))
79 return -ENOENT;
80
81 if (table->header.revision < 2) {
82 err = -ENOENT;
83 pr_err("wrong table version\n");
84 goto done;
85 }
86
87 iotype = table->serial_port.space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY ?
88 "mmio" : "io";
89
90 switch (table->interface_type) {
91 case ACPI_DBG2_ARM_SBSA_32BIT:
92 iotype = "mmio32";
93 /* fall through */
94 case ACPI_DBG2_ARM_PL011:
95 case ACPI_DBG2_ARM_SBSA_GENERIC:
96 case ACPI_DBG2_BCM2835:
97 uart = "pl011";
98 break;
99 case ACPI_DBG2_16550_COMPATIBLE:
100 case ACPI_DBG2_16550_SUBSET:
101 uart = "uart";
102 break;
103 default:
104 err = -ENOENT;
105 goto done;
106 }
107
108 switch (table->baud_rate) {
109 case 3:
110 baud_rate = 9600;
111 break;
112 case 4:
113 baud_rate = 19200;
114 break;
115 case 6:
116 baud_rate = 57600;
117 break;
118 case 7:
119 baud_rate = 115200;
120 break;
121 default:
122 err = -ENOENT;
123 goto done;
124 }
125
686378f9
TT
126 /*
127 * If the E44 erratum is required, then we need to tell the pl011
128 * driver to implement the work-around.
129 *
130 * The global variable is used by the probe function when it
131 * creates the UARTs, whether or not they're used as a console.
132 *
133 * If the user specifies "traditional" earlycon, the qdf2400_e44
134 * console name matches the EARLYCON_DECLARE() statement, and
135 * SPCR is not used. Parameter "earlycon" is false.
136 *
137 * If the user specifies "SPCR" earlycon, then we need to update
138 * the console name so that it also says "qdf2400_e44". Parameter
139 * "earlycon" is true.
140 *
141 * For consistency, if we change the console name, then we do it
142 * for everyone, not just earlycon.
143 */
144 if (qdf2400_erratum_44_present(&table->header)) {
145 qdf2400_e44_present = true;
146 if (earlycon)
147 uart = "qdf2400_e44";
148 }
02f469fe 149
ad1696f6
AM
150 snprintf(opts, sizeof(opts), "%s,%s,0x%llx,%d", uart, iotype,
151 table->serial_port.address, baud_rate);
152
153 pr_info("console: %s\n", opts);
154
155 if (earlycon)
156 setup_earlycon(opts);
157
158 err = add_preferred_console(uart, 0, opts + strlen(uart) + 1);
159
160done:
6b11d1d6 161 acpi_put_table((struct acpi_table_header *)table);
ad1696f6
AM
162 return err;
163}