platform.c 3.4 KB

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