platform.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * Copyright 2011, Netlogic Microsystems.
  3. * Copyright 2004, Matt Porter <mporter@kernel.crashing.org>
  4. *
  5. * This file is licensed under the terms of the GNU General Public
  6. * License version 2. This program is licensed "as is" without any
  7. * warranty of any kind, whether express or implied.
  8. */
  9. #include <linux/device.h>
  10. #include <linux/platform_device.h>
  11. #include <linux/kernel.h>
  12. #include <linux/init.h>
  13. #include <linux/resource.h>
  14. #include <linux/serial_8250.h>
  15. #include <linux/serial_reg.h>
  16. #include <asm/netlogic/xlr/iomap.h>
  17. #include <asm/netlogic/xlr/pic.h>
  18. #include <asm/netlogic/xlr/xlr.h>
  19. unsigned int nlm_xlr_uart_in(struct uart_port *p, int offset)
  20. {
  21. nlm_reg_t *mmio;
  22. unsigned int value;
  23. /* XLR uart does not need any mapping of regs */
  24. mmio = (nlm_reg_t *)(p->membase + (offset << p->regshift));
  25. value = netlogic_read_reg(mmio, 0);
  26. /* See XLR/XLS errata */
  27. if (offset == UART_MSR)
  28. value ^= 0xF0;
  29. else if (offset == UART_MCR)
  30. value ^= 0x3;
  31. return value;
  32. }
  33. void nlm_xlr_uart_out(struct uart_port *p, int offset, int value)
  34. {
  35. nlm_reg_t *mmio;
  36. /* XLR uart does not need any mapping of regs */
  37. mmio = (nlm_reg_t *)(p->membase + (offset << p->regshift));
  38. /* See XLR/XLS errata */
  39. if (offset == UART_MSR)
  40. value ^= 0xF0;
  41. else if (offset == UART_MCR)
  42. value ^= 0x3;
  43. netlogic_write_reg(mmio, 0, value);
  44. }
  45. #define PORT(_irq) \
  46. { \
  47. .irq = _irq, \
  48. .regshift = 2, \
  49. .iotype = UPIO_MEM32, \
  50. .flags = (UPF_SKIP_TEST | \
  51. UPF_FIXED_TYPE | UPF_BOOT_AUTOCONF),\
  52. .uartclk = PIC_CLKS_PER_SEC, \
  53. .type = PORT_16550A, \
  54. .serial_in = nlm_xlr_uart_in, \
  55. .serial_out = nlm_xlr_uart_out, \
  56. }
  57. static struct plat_serial8250_port xlr_uart_data[] = {
  58. PORT(PIC_UART_0_IRQ),
  59. PORT(PIC_UART_1_IRQ),
  60. {},
  61. };
  62. static struct platform_device uart_device = {
  63. .name = "serial8250",
  64. .id = PLAT8250_DEV_PLATFORM,
  65. .dev = {
  66. .platform_data = xlr_uart_data,
  67. },
  68. };
  69. static int __init nlm_uart_init(void)
  70. {
  71. nlm_reg_t *mmio;
  72. mmio = netlogic_io_mmio(NETLOGIC_IO_UART_0_OFFSET);
  73. xlr_uart_data[0].membase = (void __iomem *)mmio;
  74. xlr_uart_data[0].mapbase = CPHYSADDR((unsigned long)mmio);
  75. mmio = netlogic_io_mmio(NETLOGIC_IO_UART_1_OFFSET);
  76. xlr_uart_data[1].membase = (void __iomem *)mmio;
  77. xlr_uart_data[1].mapbase = CPHYSADDR((unsigned long)mmio);
  78. return platform_device_register(&uart_device);
  79. }
  80. arch_initcall(nlm_uart_init);