spcr.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. #define pr_fmt(fmt) "ACPI: SPCR: " fmt
  12. #include <linux/acpi.h>
  13. #include <linux/console.h>
  14. #include <linux/kernel.h>
  15. #include <linux/serial_core.h>
  16. /**
  17. * parse_spcr() - parse ACPI SPCR table and add preferred console
  18. *
  19. * @earlycon: set up earlycon for the console specified by the table
  20. *
  21. * For the architectures with support for ACPI, CONFIG_ACPI_SPCR_TABLE may be
  22. * defined to parse ACPI SPCR table. As a result of the parsing preferred
  23. * console is registered and if @earlycon is true, earlycon is set up.
  24. *
  25. * When CONFIG_ACPI_SPCR_TABLE is defined, this function should be called
  26. * from arch inintialization code as soon as the DT/ACPI decision is made.
  27. *
  28. */
  29. int __init parse_spcr(bool earlycon)
  30. {
  31. static char opts[64];
  32. struct acpi_table_spcr *table;
  33. acpi_size table_size;
  34. acpi_status status;
  35. char *uart;
  36. char *iotype;
  37. int baud_rate;
  38. int err;
  39. if (acpi_disabled)
  40. return -ENODEV;
  41. status = acpi_get_table_with_size(ACPI_SIG_SPCR, 0,
  42. (struct acpi_table_header **)&table,
  43. &table_size);
  44. if (ACPI_FAILURE(status))
  45. return -ENOENT;
  46. if (table->header.revision < 2) {
  47. err = -ENOENT;
  48. pr_err("wrong table version\n");
  49. goto done;
  50. }
  51. iotype = table->serial_port.space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY ?
  52. "mmio" : "io";
  53. switch (table->interface_type) {
  54. case ACPI_DBG2_ARM_SBSA_32BIT:
  55. iotype = "mmio32";
  56. /* fall through */
  57. case ACPI_DBG2_ARM_PL011:
  58. case ACPI_DBG2_ARM_SBSA_GENERIC:
  59. case ACPI_DBG2_BCM2835:
  60. uart = "pl011";
  61. break;
  62. case ACPI_DBG2_16550_COMPATIBLE:
  63. case ACPI_DBG2_16550_SUBSET:
  64. uart = "uart";
  65. break;
  66. default:
  67. err = -ENOENT;
  68. goto done;
  69. }
  70. switch (table->baud_rate) {
  71. case 3:
  72. baud_rate = 9600;
  73. break;
  74. case 4:
  75. baud_rate = 19200;
  76. break;
  77. case 6:
  78. baud_rate = 57600;
  79. break;
  80. case 7:
  81. baud_rate = 115200;
  82. break;
  83. default:
  84. err = -ENOENT;
  85. goto done;
  86. }
  87. snprintf(opts, sizeof(opts), "%s,%s,0x%llx,%d", uart, iotype,
  88. table->serial_port.address, baud_rate);
  89. pr_info("console: %s\n", opts);
  90. if (earlycon)
  91. setup_earlycon(opts);
  92. err = add_preferred_console(uart, 0, opts + strlen(uart) + 1);
  93. done:
  94. early_acpi_os_unmap_memory((void __iomem *)table, table_size);
  95. return err;
  96. }