spcr.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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_status status;
  34. char *uart;
  35. char *iotype;
  36. int baud_rate;
  37. int err;
  38. if (acpi_disabled)
  39. return -ENODEV;
  40. status = acpi_get_table(ACPI_SIG_SPCR, 0,
  41. (struct acpi_table_header **)&table);
  42. if (ACPI_FAILURE(status))
  43. return -ENOENT;
  44. if (table->header.revision < 2) {
  45. err = -ENOENT;
  46. pr_err("wrong table version\n");
  47. goto done;
  48. }
  49. iotype = table->serial_port.space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY ?
  50. "mmio" : "io";
  51. switch (table->interface_type) {
  52. case ACPI_DBG2_ARM_SBSA_32BIT:
  53. iotype = "mmio32";
  54. /* fall through */
  55. case ACPI_DBG2_ARM_PL011:
  56. case ACPI_DBG2_ARM_SBSA_GENERIC:
  57. case ACPI_DBG2_BCM2835:
  58. uart = "pl011";
  59. break;
  60. case ACPI_DBG2_16550_COMPATIBLE:
  61. case ACPI_DBG2_16550_SUBSET:
  62. uart = "uart";
  63. break;
  64. default:
  65. err = -ENOENT;
  66. goto done;
  67. }
  68. switch (table->baud_rate) {
  69. case 3:
  70. baud_rate = 9600;
  71. break;
  72. case 4:
  73. baud_rate = 19200;
  74. break;
  75. case 6:
  76. baud_rate = 57600;
  77. break;
  78. case 7:
  79. baud_rate = 115200;
  80. break;
  81. default:
  82. err = -ENOENT;
  83. goto done;
  84. }
  85. snprintf(opts, sizeof(opts), "%s,%s,0x%llx,%d", uart, iotype,
  86. table->serial_port.address, baud_rate);
  87. pr_info("console: %s\n", opts);
  88. if (earlycon)
  89. setup_earlycon(opts);
  90. err = add_preferred_console(uart, 0, opts + strlen(uart) + 1);
  91. done:
  92. acpi_put_table((struct acpi_table_header *)table);
  93. return err;
  94. }