platform.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * ARC FPGA Platform support code
  3. *
  4. * Copyright (C) 2012 Synopsys, Inc. (www.synopsys.com)
  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. #include <linux/types.h>
  11. #include <linux/init.h>
  12. #include <linux/device.h>
  13. #include <linux/platform_device.h>
  14. #include <linux/console.h>
  15. #include <asm/setup.h>
  16. #include <asm/irq.h>
  17. #include <asm/clk.h>
  18. #include <plat/memmap.h>
  19. /*----------------------- Platform Devices -----------------------------*/
  20. #if defined(CONFIG_SERIAL_ARC) || defined(CONFIG_SERIAL_ARC_MODULE)
  21. static unsigned long arc_uart_info[] = {
  22. CONFIG_ARC_SERIAL_BAUD, /* uart->baud */
  23. -1, /* uart->port.uartclk */
  24. -1, /* uart->is_emulated (runtime @running_on_hw) */
  25. 0
  26. };
  27. #define ARC_UART_DEV(n) \
  28. \
  29. static struct resource arc_uart##n##_res[] = { \
  30. { \
  31. .start = UART##n##_BASE, \
  32. .end = UART##n##_BASE + 0xFF, \
  33. .flags = IORESOURCE_MEM, \
  34. }, \
  35. { \
  36. .start = UART##n##_IRQ, \
  37. .end = UART##n##_IRQ, \
  38. .flags = IORESOURCE_IRQ, \
  39. }, \
  40. }; \
  41. \
  42. static struct platform_device arc_uart##n##_dev = { \
  43. .name = "arc-uart", \
  44. .id = n, \
  45. .num_resources = ARRAY_SIZE(arc_uart##n##_res), \
  46. .resource = arc_uart##n##_res, \
  47. .dev = { \
  48. .platform_data = &arc_uart_info, \
  49. }, \
  50. }
  51. ARC_UART_DEV(0);
  52. #if CONFIG_SERIAL_ARC_NR_PORTS > 1
  53. ARC_UART_DEV(1);
  54. #endif
  55. static struct platform_device *fpga_early_devs[] __initdata = {
  56. #if defined(CONFIG_SERIAL_ARC_CONSOLE)
  57. &arc_uart0_dev,
  58. #endif
  59. };
  60. static void arc_fpga_serial_init(void)
  61. {
  62. arc_uart_info[1] = arc_get_core_freq();
  63. /* To let driver workaround ISS bug: baudh Reg can't be set to 0 */
  64. arc_uart_info[2] = !running_on_hw;
  65. early_platform_add_devices(fpga_early_devs,
  66. ARRAY_SIZE(fpga_early_devs));
  67. /*
  68. * ARC console driver registers itself as an early platform driver
  69. * of class "earlyprintk".
  70. * Install it here, followed by probe of devices.
  71. * The installation here doesn't require earlyprintk in command line
  72. * To do so however, replace the lines below with
  73. * parse_early_param();
  74. * early_platform_driver_probe("earlyprintk", 1, 1);
  75. * ^^
  76. */
  77. early_platform_driver_register_all("earlyprintk");
  78. early_platform_driver_probe("earlyprintk", 1, 0);
  79. /*
  80. * This is to make sure that arc uart would be preferred console
  81. * despite one/more of following:
  82. * -command line lacked "console=ttyARC0" or
  83. * -CONFIG_VT_CONSOLE was enabled (for no reason whatsoever)
  84. * Note that this needs to be done after above early console is reg,
  85. * otherwise the early console never gets a chance to run.
  86. */
  87. add_preferred_console("ttyARC", 0, "115200");
  88. }
  89. #else
  90. static void arc_fpga_serial_init(void)
  91. {
  92. }
  93. #endif /* CONFIG_SERIAL_ARC */
  94. /*
  95. * Early Platform Initialization called from setup_arch()
  96. */
  97. void __init arc_platform_early_init(void)
  98. {
  99. pr_info("[plat-arcfpga]: registering early dev resources\n");
  100. arc_fpga_serial_init();
  101. }
  102. static struct platform_device *fpga_devs[] __initdata = {
  103. #if defined(CONFIG_SERIAL_ARC) || defined(CONFIG_SERIAL_ARC_MODULE)
  104. &arc_uart0_dev,
  105. #if CONFIG_SERIAL_ARC_NR_PORTS > 1
  106. &arc_uart1_dev,
  107. #endif
  108. #endif
  109. };
  110. int __init fpga_plat_init(void)
  111. {
  112. pr_info("[plat-arcfpga]: registering device resources\n");
  113. platform_add_devices(fpga_devs, ARRAY_SIZE(fpga_devs));
  114. return 0;
  115. }
  116. arch_initcall(fpga_plat_init);