ce4100.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Intel CE4100 platform specific setup code
  4. *
  5. * (C) Copyright 2010 Intel Corporation
  6. */
  7. #include <linux/init.h>
  8. #include <linux/kernel.h>
  9. #include <linux/irq.h>
  10. #include <linux/reboot.h>
  11. #include <linux/serial_reg.h>
  12. #include <linux/serial_8250.h>
  13. #include <asm/ce4100.h>
  14. #include <asm/prom.h>
  15. #include <asm/setup.h>
  16. #include <asm/i8259.h>
  17. #include <asm/io.h>
  18. #include <asm/io_apic.h>
  19. #include <asm/emergency-restart.h>
  20. /*
  21. * The CE4100 platform has an internal 8051 Microcontroller which is
  22. * responsible for signaling to the external Power Management Unit the
  23. * intention to reset, reboot or power off the system. This 8051 device has
  24. * its command register mapped at I/O port 0xcf9 and the value 0x4 is used
  25. * to power off the system.
  26. */
  27. static void ce4100_power_off(void)
  28. {
  29. outb(0x4, 0xcf9);
  30. }
  31. #ifdef CONFIG_SERIAL_8250
  32. static unsigned int mem_serial_in(struct uart_port *p, int offset)
  33. {
  34. offset = offset << p->regshift;
  35. return readl(p->membase + offset);
  36. }
  37. /*
  38. * The UART Tx interrupts are not set under some conditions and therefore serial
  39. * transmission hangs. This is a silicon issue and has not been root caused. The
  40. * workaround for this silicon issue checks UART_LSR_THRE bit and UART_LSR_TEMT
  41. * bit of LSR register in interrupt handler to see whether at least one of these
  42. * two bits is set, if so then process the transmit request. If this workaround
  43. * is not applied, then the serial transmission may hang. This workaround is for
  44. * errata number 9 in Errata - B step.
  45. */
  46. static unsigned int ce4100_mem_serial_in(struct uart_port *p, int offset)
  47. {
  48. unsigned int ret, ier, lsr;
  49. if (offset == UART_IIR) {
  50. offset = offset << p->regshift;
  51. ret = readl(p->membase + offset);
  52. if (ret & UART_IIR_NO_INT) {
  53. /* see if the TX interrupt should have really set */
  54. ier = mem_serial_in(p, UART_IER);
  55. /* see if the UART's XMIT interrupt is enabled */
  56. if (ier & UART_IER_THRI) {
  57. lsr = mem_serial_in(p, UART_LSR);
  58. /* now check to see if the UART should be
  59. generating an interrupt (but isn't) */
  60. if (lsr & (UART_LSR_THRE | UART_LSR_TEMT))
  61. ret &= ~UART_IIR_NO_INT;
  62. }
  63. }
  64. } else
  65. ret = mem_serial_in(p, offset);
  66. return ret;
  67. }
  68. static void ce4100_mem_serial_out(struct uart_port *p, int offset, int value)
  69. {
  70. offset = offset << p->regshift;
  71. writel(value, p->membase + offset);
  72. }
  73. static void ce4100_serial_fixup(int port, struct uart_port *up,
  74. u32 *capabilities)
  75. {
  76. #ifdef CONFIG_EARLY_PRINTK
  77. /*
  78. * Over ride the legacy port configuration that comes from
  79. * asm/serial.h. Using the ioport driver then switching to the
  80. * PCI memmaped driver hangs the IOAPIC
  81. */
  82. if (up->iotype != UPIO_MEM32) {
  83. up->uartclk = 14745600;
  84. up->mapbase = 0xdffe0200;
  85. set_fixmap_nocache(FIX_EARLYCON_MEM_BASE,
  86. up->mapbase & PAGE_MASK);
  87. up->membase =
  88. (void __iomem *)__fix_to_virt(FIX_EARLYCON_MEM_BASE);
  89. up->membase += up->mapbase & ~PAGE_MASK;
  90. up->mapbase += port * 0x100;
  91. up->membase += port * 0x100;
  92. up->iotype = UPIO_MEM32;
  93. up->regshift = 2;
  94. up->irq = 4;
  95. }
  96. #endif
  97. up->iobase = 0;
  98. up->serial_in = ce4100_mem_serial_in;
  99. up->serial_out = ce4100_mem_serial_out;
  100. *capabilities |= (1 << 12);
  101. }
  102. static __init void sdv_serial_fixup(void)
  103. {
  104. serial8250_set_isa_configurator(ce4100_serial_fixup);
  105. }
  106. #else
  107. static inline void sdv_serial_fixup(void) {};
  108. #endif
  109. static void __init sdv_arch_setup(void)
  110. {
  111. sdv_serial_fixup();
  112. }
  113. static void sdv_pci_init(void)
  114. {
  115. x86_of_pci_init();
  116. }
  117. /*
  118. * CE4100 specific x86_init function overrides and early setup
  119. * calls.
  120. */
  121. void __init x86_ce4100_early_setup(void)
  122. {
  123. x86_init.oem.arch_setup = sdv_arch_setup;
  124. x86_init.resources.probe_roms = x86_init_noop;
  125. x86_init.mpparse.get_smp_config = x86_init_uint_noop;
  126. x86_init.mpparse.find_smp_config = x86_init_noop;
  127. x86_init.mpparse.setup_ioapic_ids = setup_ioapic_ids_from_mpc_nocheck;
  128. x86_init.pci.init = ce4100_pci_init;
  129. x86_init.pci.init_irq = sdv_pci_init;
  130. /*
  131. * By default, the reboot method is ACPI which is supported by the
  132. * CE4100 bootloader CEFDK using FADT.ResetReg Address and ResetValue
  133. * the bootloader will however issue a system power off instead of
  134. * reboot. By using BOOT_KBD we ensure proper system reboot as
  135. * expected.
  136. */
  137. reboot_type = BOOT_KBD;
  138. pm_power_off = ce4100_power_off;
  139. }