sh_eth: fix EESIPR values for SH77{34|63}
[linux/fpc-iii.git] / drivers / acpi / spcr.c
blobb8019c4c1d38908895b21a92a094074ca2bd5bd8
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>
19 /**
20 * parse_spcr() - parse ACPI SPCR table and add preferred console
22 * @earlycon: set up earlycon for the console specified by the table
24 * For the architectures with support for ACPI, CONFIG_ACPI_SPCR_TABLE may be
25 * defined to parse ACPI SPCR table. As a result of the parsing preferred
26 * console is registered and if @earlycon is true, earlycon is set up.
28 * When CONFIG_ACPI_SPCR_TABLE is defined, this function should be called
29 * from arch inintialization code as soon as the DT/ACPI decision is made.
32 int __init parse_spcr(bool earlycon)
34 static char opts[64];
35 struct acpi_table_spcr *table;
36 acpi_status status;
37 char *uart;
38 char *iotype;
39 int baud_rate;
40 int err;
42 if (acpi_disabled)
43 return -ENODEV;
45 status = acpi_get_table(ACPI_SIG_SPCR, 0,
46 (struct acpi_table_header **)&table);
48 if (ACPI_FAILURE(status))
49 return -ENOENT;
51 if (table->header.revision < 2) {
52 err = -ENOENT;
53 pr_err("wrong table version\n");
54 goto done;
57 iotype = table->serial_port.space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY ?
58 "mmio" : "io";
60 switch (table->interface_type) {
61 case ACPI_DBG2_ARM_SBSA_32BIT:
62 iotype = "mmio32";
63 /* fall through */
64 case ACPI_DBG2_ARM_PL011:
65 case ACPI_DBG2_ARM_SBSA_GENERIC:
66 case ACPI_DBG2_BCM2835:
67 uart = "pl011";
68 break;
69 case ACPI_DBG2_16550_COMPATIBLE:
70 case ACPI_DBG2_16550_SUBSET:
71 uart = "uart";
72 break;
73 default:
74 err = -ENOENT;
75 goto done;
78 switch (table->baud_rate) {
79 case 3:
80 baud_rate = 9600;
81 break;
82 case 4:
83 baud_rate = 19200;
84 break;
85 case 6:
86 baud_rate = 57600;
87 break;
88 case 7:
89 baud_rate = 115200;
90 break;
91 default:
92 err = -ENOENT;
93 goto done;
96 snprintf(opts, sizeof(opts), "%s,%s,0x%llx,%d", uart, iotype,
97 table->serial_port.address, baud_rate);
99 pr_info("console: %s\n", opts);
101 if (earlycon)
102 setup_earlycon(opts);
104 err = add_preferred_console(uart, 0, opts + strlen(uart) + 1);
106 done:
107 acpi_put_table((struct acpi_table_header *)table);
108 return err;