zram: remove zram_meta structure
[linux/fpc-iii.git] / drivers / acpi / spcr.c
blob3afa8c1fa12702c251d5d3654e2026ba0ebfcd62
1 /*
2 * Copyright (c) 2012, Intel Corporation
3 * Copyright (c) 2015, Red Hat, Inc.
4 * Copyright (c) 2015, 2016 Linaro Ltd.
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.
12 #define pr_fmt(fmt) "ACPI: SPCR: " fmt
14 #include <linux/acpi.h>
15 #include <linux/console.h>
16 #include <linux/kernel.h>
17 #include <linux/serial_core.h>
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.
24 static bool qdf2400_erratum_44_present(struct acpi_table_header *h)
26 if (memcmp(h->oem_id, "QCOM ", ACPI_OEM_ID_SIZE))
27 return false;
29 if (!memcmp(h->oem_table_id, "QDF2432 ", ACPI_OEM_TABLE_ID_SIZE))
30 return true;
32 if (!memcmp(h->oem_table_id, "QDF2400 ", ACPI_OEM_TABLE_ID_SIZE) &&
33 h->oem_revision == 1)
34 return true;
36 return false;
39 /**
40 * parse_spcr() - parse ACPI SPCR table and add preferred console
42 * @earlycon: set up earlycon for the console specified by the table
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.
48 * When CONFIG_ACPI_SPCR_TABLE is defined, this function should be called
49 * from arch initialization code as soon as the DT/ACPI decision is made.
52 int __init parse_spcr(bool earlycon)
54 static char opts[64];
55 struct acpi_table_spcr *table;
56 acpi_status status;
57 char *uart;
58 char *iotype;
59 int baud_rate;
60 int err;
62 if (acpi_disabled)
63 return -ENODEV;
65 status = acpi_get_table(ACPI_SIG_SPCR, 0,
66 (struct acpi_table_header **)&table);
68 if (ACPI_FAILURE(status))
69 return -ENOENT;
71 if (table->header.revision < 2) {
72 err = -ENOENT;
73 pr_err("wrong table version\n");
74 goto done;
77 iotype = table->serial_port.space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY ?
78 "mmio" : "io";
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;
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;
116 if (qdf2400_erratum_44_present(&table->header))
117 uart = "qdf2400_e44";
119 snprintf(opts, sizeof(opts), "%s,%s,0x%llx,%d", uart, iotype,
120 table->serial_port.address, baud_rate);
122 pr_info("console: %s\n", opts);
124 if (earlycon)
125 setup_earlycon(opts);
127 err = add_preferred_console(uart, 0, opts + strlen(uart) + 1);
129 done:
130 acpi_put_table((struct acpi_table_header *)table);
131 return err;