Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * Joshua Henderson, joshua.henderson@microchip.com
0004  * Copyright (C) 2015 Microchip Technology Inc.  All rights reserved.
0005  */
0006 #include <linux/init.h>
0007 #include <linux/kernel.h>
0008 #include <linux/of_address.h>
0009 #include <linux/of_fdt.h>
0010 #include <linux/of_platform.h>
0011 #include <linux/platform_data/sdhci-pic32.h>
0012 
0013 #include <asm/fw/fw.h>
0014 #include <asm/mips-boards/generic.h>
0015 #include <asm/prom.h>
0016 
0017 #include "pic32mzda.h"
0018 
0019 const char *get_system_type(void)
0020 {
0021     return "PIC32MZDA";
0022 }
0023 
0024 void __init plat_mem_setup(void)
0025 {
0026     void *dtb;
0027 
0028     dtb = get_fdt();
0029     if (!dtb) {
0030         pr_err("pic32: no DTB found.\n");
0031         return;
0032     }
0033 
0034     /*
0035      * Load the builtin device tree. This causes the chosen node to be
0036      * parsed resulting in our memory appearing.
0037      */
0038     __dt_setup_arch(dtb);
0039 
0040     pr_info("Found following command lines\n");
0041     pr_info(" boot_command_line: %s\n", boot_command_line);
0042     pr_info(" arcs_cmdline     : %s\n", arcs_cmdline);
0043 #ifdef CONFIG_CMDLINE_BOOL
0044     pr_info(" builtin_cmdline  : %s\n", CONFIG_CMDLINE);
0045 #endif
0046     if (dtb != __dtb_start)
0047         strlcpy(arcs_cmdline, boot_command_line, COMMAND_LINE_SIZE);
0048 
0049 #ifdef CONFIG_EARLY_PRINTK
0050     fw_init_early_console(-1);
0051 #endif
0052     pic32_config_init();
0053 }
0054 
0055 static __init void pic32_init_cmdline(int argc, char *argv[])
0056 {
0057     unsigned int count = COMMAND_LINE_SIZE - 1;
0058     int i;
0059     char *dst = &(arcs_cmdline[0]);
0060     char *src;
0061 
0062     for (i = 1; i < argc && count; ++i) {
0063         src = argv[i];
0064         while (*src && count) {
0065             *dst++ = *src++;
0066             --count;
0067         }
0068         *dst++ = ' ';
0069     }
0070     if (i > 1)
0071         --dst;
0072 
0073     *dst = 0;
0074 }
0075 
0076 void __init prom_init(void)
0077 {
0078     pic32_init_cmdline((int)fw_arg0, (char **)fw_arg1);
0079 }
0080 
0081 static struct pic32_sdhci_platform_data sdhci_data = {
0082     .setup_dma = pic32_set_sdhci_adma_fifo_threshold,
0083 };
0084 
0085 static struct of_dev_auxdata pic32_auxdata_lookup[] __initdata = {
0086     OF_DEV_AUXDATA("microchip,pic32mzda-sdhci", 0, "sdhci", &sdhci_data),
0087     { /* sentinel */}
0088 };
0089 
0090 static int __init pic32_of_prepare_platform_data(struct of_dev_auxdata *lookup)
0091 {
0092     struct device_node *root, *np;
0093     struct resource res;
0094 
0095     root = of_find_node_by_path("/");
0096 
0097     for (; lookup->compatible; lookup++) {
0098         np = of_find_compatible_node(NULL, NULL, lookup->compatible);
0099         if (np) {
0100             lookup->name = (char *)np->name;
0101             if (lookup->phys_addr) {
0102                 of_node_put(np);
0103                 continue;
0104             }
0105             if (!of_address_to_resource(np, 0, &res))
0106                 lookup->phys_addr = res.start;
0107             of_node_put(np);
0108         }
0109     }
0110 
0111     of_node_put(root);
0112 
0113     return 0;
0114 }
0115 
0116 static int __init plat_of_setup(void)
0117 {
0118     if (!of_have_populated_dt())
0119         panic("Device tree not present");
0120 
0121     pic32_of_prepare_platform_data(pic32_auxdata_lookup);
0122     if (of_platform_default_populate(NULL, pic32_auxdata_lookup, NULL))
0123         panic("Failed to populate DT");
0124 
0125     return 0;
0126 }
0127 arch_initcall(plat_of_setup);