init.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. * Joshua Henderson, joshua.henderson@microchip.com
  3. * Copyright (C) 2015 Microchip Technology Inc. All rights reserved.
  4. *
  5. * This program is free software; you can distribute it and/or modify it
  6. * under the terms of the GNU General Public License (Version 2) as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12. * for more details.
  13. */
  14. #include <linux/init.h>
  15. #include <linux/kernel.h>
  16. #include <linux/of_address.h>
  17. #include <linux/of_fdt.h>
  18. #include <linux/of_platform.h>
  19. #include <linux/platform_data/sdhci-pic32.h>
  20. #include <asm/fw/fw.h>
  21. #include <asm/mips-boards/generic.h>
  22. #include <asm/prom.h>
  23. #include "pic32mzda.h"
  24. const char *get_system_type(void)
  25. {
  26. return "PIC32MZDA";
  27. }
  28. static ulong get_fdtaddr(void)
  29. {
  30. ulong ftaddr = 0;
  31. if (fw_passed_dtb && !fw_arg2 && !fw_arg3)
  32. return (ulong)fw_passed_dtb;
  33. if (__dtb_start < __dtb_end)
  34. ftaddr = (ulong)__dtb_start;
  35. return ftaddr;
  36. }
  37. void __init plat_mem_setup(void)
  38. {
  39. void *dtb;
  40. dtb = (void *)get_fdtaddr();
  41. if (!dtb) {
  42. pr_err("pic32: no DTB found.\n");
  43. return;
  44. }
  45. /*
  46. * Load the builtin device tree. This causes the chosen node to be
  47. * parsed resulting in our memory appearing.
  48. */
  49. __dt_setup_arch(dtb);
  50. pr_info("Found following command lines\n");
  51. pr_info(" boot_command_line: %s\n", boot_command_line);
  52. pr_info(" arcs_cmdline : %s\n", arcs_cmdline);
  53. #ifdef CONFIG_CMDLINE_BOOL
  54. pr_info(" builtin_cmdline : %s\n", CONFIG_CMDLINE);
  55. #endif
  56. if (dtb != __dtb_start)
  57. strlcpy(arcs_cmdline, boot_command_line, COMMAND_LINE_SIZE);
  58. #ifdef CONFIG_EARLY_PRINTK
  59. fw_init_early_console(-1);
  60. #endif
  61. pic32_config_init();
  62. }
  63. static __init void pic32_init_cmdline(int argc, char *argv[])
  64. {
  65. unsigned int count = COMMAND_LINE_SIZE - 1;
  66. int i;
  67. char *dst = &(arcs_cmdline[0]);
  68. char *src;
  69. for (i = 1; i < argc && count; ++i) {
  70. src = argv[i];
  71. while (*src && count) {
  72. *dst++ = *src++;
  73. --count;
  74. }
  75. *dst++ = ' ';
  76. }
  77. if (i > 1)
  78. --dst;
  79. *dst = 0;
  80. }
  81. void __init prom_init(void)
  82. {
  83. pic32_init_cmdline((int)fw_arg0, (char **)fw_arg1);
  84. }
  85. void __init prom_free_prom_memory(void)
  86. {
  87. }
  88. void __init device_tree_init(void)
  89. {
  90. if (!initial_boot_params)
  91. return;
  92. unflatten_and_copy_device_tree();
  93. }
  94. static struct pic32_sdhci_platform_data sdhci_data = {
  95. .setup_dma = pic32_set_sdhci_adma_fifo_threshold,
  96. };
  97. static struct of_dev_auxdata pic32_auxdata_lookup[] __initdata = {
  98. OF_DEV_AUXDATA("microchip,pic32mzda-sdhci", 0, "sdhci", &sdhci_data),
  99. { /* sentinel */}
  100. };
  101. static int __init pic32_of_prepare_platform_data(struct of_dev_auxdata *lookup)
  102. {
  103. struct device_node *root, *np;
  104. struct resource res;
  105. root = of_find_node_by_path("/");
  106. for (; lookup->compatible; lookup++) {
  107. np = of_find_compatible_node(NULL, NULL, lookup->compatible);
  108. if (np) {
  109. lookup->name = (char *)np->name;
  110. if (lookup->phys_addr)
  111. continue;
  112. if (!of_address_to_resource(np, 0, &res))
  113. lookup->phys_addr = res.start;
  114. }
  115. }
  116. return 0;
  117. }
  118. static int __init plat_of_setup(void)
  119. {
  120. if (!of_have_populated_dt())
  121. panic("Device tree not present");
  122. pic32_of_prepare_platform_data(pic32_auxdata_lookup);
  123. if (of_platform_default_populate(NULL, pic32_auxdata_lookup, NULL))
  124. panic("Failed to populate DT");
  125. return 0;
  126. }
  127. arch_initcall(plat_of_setup);