init.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Joshua Henderson, [email protected]
  4. * Copyright (C) 2015 Microchip Technology Inc. All rights reserved.
  5. */
  6. #include <linux/init.h>
  7. #include <linux/kernel.h>
  8. #include <linux/of_address.h>
  9. #include <linux/of_fdt.h>
  10. #include <linux/of_platform.h>
  11. #include <linux/platform_data/sdhci-pic32.h>
  12. #include <asm/fw/fw.h>
  13. #include <asm/mips-boards/generic.h>
  14. #include <asm/prom.h>
  15. #include "pic32mzda.h"
  16. const char *get_system_type(void)
  17. {
  18. return "PIC32MZDA";
  19. }
  20. void __init plat_mem_setup(void)
  21. {
  22. void *dtb;
  23. dtb = get_fdt();
  24. if (!dtb) {
  25. pr_err("pic32: no DTB found.\n");
  26. return;
  27. }
  28. /*
  29. * Load the builtin device tree. This causes the chosen node to be
  30. * parsed resulting in our memory appearing.
  31. */
  32. __dt_setup_arch(dtb);
  33. pr_info("Found following command lines\n");
  34. pr_info(" boot_command_line: %s\n", boot_command_line);
  35. pr_info(" arcs_cmdline : %s\n", arcs_cmdline);
  36. #ifdef CONFIG_CMDLINE_BOOL
  37. pr_info(" builtin_cmdline : %s\n", CONFIG_CMDLINE);
  38. #endif
  39. if (dtb != __dtb_start)
  40. strscpy(arcs_cmdline, boot_command_line, COMMAND_LINE_SIZE);
  41. #ifdef CONFIG_EARLY_PRINTK
  42. fw_init_early_console();
  43. #endif
  44. pic32_config_init();
  45. }
  46. static __init void pic32_init_cmdline(int argc, char *argv[])
  47. {
  48. unsigned int count = COMMAND_LINE_SIZE - 1;
  49. int i;
  50. char *dst = &(arcs_cmdline[0]);
  51. char *src;
  52. for (i = 1; i < argc && count; ++i) {
  53. src = argv[i];
  54. while (*src && count) {
  55. *dst++ = *src++;
  56. --count;
  57. }
  58. *dst++ = ' ';
  59. }
  60. if (i > 1)
  61. --dst;
  62. *dst = 0;
  63. }
  64. void __init prom_init(void)
  65. {
  66. pic32_init_cmdline((int)fw_arg0, (char **)fw_arg1);
  67. }
  68. static struct pic32_sdhci_platform_data sdhci_data = {
  69. .setup_dma = pic32_set_sdhci_adma_fifo_threshold,
  70. };
  71. static struct of_dev_auxdata pic32_auxdata_lookup[] __initdata = {
  72. OF_DEV_AUXDATA("microchip,pic32mzda-sdhci", 0, "sdhci", &sdhci_data),
  73. { /* sentinel */}
  74. };
  75. static int __init pic32_of_prepare_platform_data(struct of_dev_auxdata *lookup)
  76. {
  77. struct device_node *root, *np;
  78. struct resource res;
  79. root = of_find_node_by_path("/");
  80. for (; lookup->compatible; lookup++) {
  81. np = of_find_compatible_node(NULL, NULL, lookup->compatible);
  82. if (np) {
  83. lookup->name = (char *)np->name;
  84. if (lookup->phys_addr) {
  85. of_node_put(np);
  86. continue;
  87. }
  88. if (!of_address_to_resource(np, 0, &res))
  89. lookup->phys_addr = res.start;
  90. of_node_put(np);
  91. }
  92. }
  93. of_node_put(root);
  94. return 0;
  95. }
  96. static int __init plat_of_setup(void)
  97. {
  98. if (!of_have_populated_dt())
  99. panic("Device tree not present");
  100. pic32_of_prepare_platform_data(pic32_auxdata_lookup);
  101. if (of_platform_default_populate(NULL, pic32_auxdata_lookup, NULL))
  102. panic("Failed to populate DT");
  103. return 0;
  104. }
  105. arch_initcall(plat_of_setup);