virtex.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * The platform specific code for virtex devices since a boot loader is not
  3. * always used.
  4. *
  5. * (C) Copyright 2008 Xilinx, Inc.
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License version 2 as published
  9. * by the Free Software Foundation.
  10. */
  11. #include "ops.h"
  12. #include "io.h"
  13. #include "stdio.h"
  14. #define UART_DLL 0 /* Out: Divisor Latch Low */
  15. #define UART_DLM 1 /* Out: Divisor Latch High */
  16. #define UART_FCR 2 /* Out: FIFO Control Register */
  17. #define UART_FCR_CLEAR_RCVR 0x02 /* Clear the RCVR FIFO */
  18. #define UART_FCR_CLEAR_XMIT 0x04 /* Clear the XMIT FIFO */
  19. #define UART_LCR 3 /* Out: Line Control Register */
  20. #define UART_MCR 4 /* Out: Modem Control Register */
  21. #define UART_MCR_RTS 0x02 /* RTS complement */
  22. #define UART_MCR_DTR 0x01 /* DTR complement */
  23. #define UART_LCR_DLAB 0x80 /* Divisor latch access bit */
  24. #define UART_LCR_WLEN8 0x03 /* Wordlength: 8 bits */
  25. static int virtex_ns16550_console_init(void *devp)
  26. {
  27. unsigned char *reg_base;
  28. u32 reg_shift, reg_offset, clk, spd;
  29. u16 divisor;
  30. int n;
  31. if (dt_get_virtual_reg(devp, (void **)&reg_base, 1) < 1)
  32. return -1;
  33. n = getprop(devp, "reg-offset", &reg_offset, sizeof(reg_offset));
  34. if (n == sizeof(reg_offset))
  35. reg_base += reg_offset;
  36. n = getprop(devp, "reg-shift", &reg_shift, sizeof(reg_shift));
  37. if (n != sizeof(reg_shift))
  38. reg_shift = 0;
  39. n = getprop(devp, "current-speed", (void *)&spd, sizeof(spd));
  40. if (n != sizeof(spd))
  41. spd = 9600;
  42. /* should there be a default clock rate?*/
  43. n = getprop(devp, "clock-frequency", (void *)&clk, sizeof(clk));
  44. if (n != sizeof(clk))
  45. return -1;
  46. divisor = clk / (16 * spd);
  47. /* Access baud rate */
  48. out_8(reg_base + (UART_LCR << reg_shift), UART_LCR_DLAB);
  49. /* Baud rate based on input clock */
  50. out_8(reg_base + (UART_DLL << reg_shift), divisor & 0xFF);
  51. out_8(reg_base + (UART_DLM << reg_shift), divisor >> 8);
  52. /* 8 data, 1 stop, no parity */
  53. out_8(reg_base + (UART_LCR << reg_shift), UART_LCR_WLEN8);
  54. /* RTS/DTR */
  55. out_8(reg_base + (UART_MCR << reg_shift), UART_MCR_RTS | UART_MCR_DTR);
  56. /* Clear transmitter and receiver */
  57. out_8(reg_base + (UART_FCR << reg_shift),
  58. UART_FCR_CLEAR_XMIT | UART_FCR_CLEAR_RCVR);
  59. return 0;
  60. }
  61. /* For virtex, the kernel may be loaded without using a bootloader and if so
  62. some UARTs need more setup than is provided in the normal console init
  63. */
  64. int platform_specific_init(void)
  65. {
  66. void *devp;
  67. char devtype[MAX_PROP_LEN];
  68. char path[MAX_PATH_LEN];
  69. devp = finddevice("/chosen");
  70. if (devp == NULL)
  71. return -1;
  72. if (getprop(devp, "linux,stdout-path", path, MAX_PATH_LEN) > 0) {
  73. devp = finddevice(path);
  74. if (devp == NULL)
  75. return -1;
  76. if ((getprop(devp, "device_type", devtype, sizeof(devtype)) > 0)
  77. && !strcmp(devtype, "serial")
  78. && (dt_is_compatible(devp, "ns16550")))
  79. virtex_ns16550_console_init(devp);
  80. }
  81. return 0;
  82. }