]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - drivers/acpi/spcr.c
tty: pl011: Work around QDF2400 E44 stuck BUSY bit
[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
02f469fe
SH
19/*
20 * Some Qualcomm Datacenter Technologies SoCs have a defective UART BUSY bit.
21 * Detect them by examining the OEM fields in the SPCR header, similiar to PCI
22 * quirk detection in pci_mcfg.c.
23 */
24static bool qdf2400_erratum_44_present(struct acpi_table_header *h)
25{
26 if (memcmp(h->oem_id, "QCOM ", ACPI_OEM_ID_SIZE))
27 return false;
28
29 if (!memcmp(h->oem_table_id, "QDF2432 ", ACPI_OEM_TABLE_ID_SIZE))
30 return true;
31
32 if (!memcmp(h->oem_table_id, "QDF2400 ", ACPI_OEM_TABLE_ID_SIZE) &&
33 h->oem_revision == 0)
34 return true;
35
36 return false;
37}
38
ad1696f6
AM
39/**
40 * parse_spcr() - parse ACPI SPCR table and add preferred console
41 *
42 * @earlycon: set up earlycon for the console specified by the table
43 *
44 * For the architectures with support for ACPI, CONFIG_ACPI_SPCR_TABLE may be
45 * defined to parse ACPI SPCR table. As a result of the parsing preferred
46 * console is registered and if @earlycon is true, earlycon is set up.
47 *
48 * When CONFIG_ACPI_SPCR_TABLE is defined, this function should be called
49 * from arch inintialization code as soon as the DT/ACPI decision is made.
50 *
51 */
52int __init parse_spcr(bool earlycon)
53{
54 static char opts[64];
55 struct acpi_table_spcr *table;
ad1696f6
AM
56 acpi_status status;
57 char *uart;
58 char *iotype;
59 int baud_rate;
60 int err;
61
62 if (acpi_disabled)
63 return -ENODEV;
64
6b11d1d6
LZ
65 status = acpi_get_table(ACPI_SIG_SPCR, 0,
66 (struct acpi_table_header **)&table);
ad1696f6
AM
67
68 if (ACPI_FAILURE(status))
69 return -ENOENT;
70
71 if (table->header.revision < 2) {
72 err = -ENOENT;
73 pr_err("wrong table version\n");
74 goto done;
75 }
76
77 iotype = table->serial_port.space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY ?
78 "mmio" : "io";
79
80 switch (table->interface_type) {
81 case ACPI_DBG2_ARM_SBSA_32BIT:
82 iotype = "mmio32";
83 /* fall through */
84 case ACPI_DBG2_ARM_PL011:
85 case ACPI_DBG2_ARM_SBSA_GENERIC:
86 case ACPI_DBG2_BCM2835:
87 uart = "pl011";
88 break;
89 case ACPI_DBG2_16550_COMPATIBLE:
90 case ACPI_DBG2_16550_SUBSET:
91 uart = "uart";
92 break;
93 default:
94 err = -ENOENT;
95 goto done;
96 }
97
98 switch (table->baud_rate) {
99 case 3:
100 baud_rate = 9600;
101 break;
102 case 4:
103 baud_rate = 19200;
104 break;
105 case 6:
106 baud_rate = 57600;
107 break;
108 case 7:
109 baud_rate = 115200;
110 break;
111 default:
112 err = -ENOENT;
113 goto done;
114 }
115
02f469fe
SH
116 if (qdf2400_erratum_44_present(&table->header))
117 uart = "qdf2400_e44";
118
ad1696f6
AM
119 snprintf(opts, sizeof(opts), "%s,%s,0x%llx,%d", uart, iotype,
120 table->serial_port.address, baud_rate);
121
122 pr_info("console: %s\n", opts);
123
124 if (earlycon)
125 setup_earlycon(opts);
126
127 err = add_preferred_console(uart, 0, opts + strlen(uart) + 1);
128
129done:
6b11d1d6 130 acpi_put_table((struct acpi_table_header *)table);
ad1696f6
AM
131 return err;
132}