fea9327837427ac926e1bc0e3d87e80a42e556b0
[platform/kernel/u-boot.git] / board / kontron / sl-mx8mm / sl-mx8mm.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (C) 2019 Kontron Electronics GmbH
4  */
5
6 #include <asm/arch/imx-regs.h>
7 #include <asm/global_data.h>
8 #include <asm/io.h>
9 #include <efi.h>
10 #include <efi_loader.h>
11 #include <fdt_support.h>
12 #include <linux/errno.h>
13 #include <linux/kernel.h>
14 #include <net.h>
15
16 DECLARE_GLOBAL_DATA_PTR;
17
18 #if CONFIG_IS_ENABLED(EFI_HAVE_CAPSULE_SUPPORT)
19 struct efi_fw_image fw_images[] = {
20         {
21                 .image_type_id = KONTRON_SL_MX8MM_FIT_IMAGE_GUID,
22                 .fw_name = u"KONTROL-SL-MX8MM-UBOOT",
23                 .image_index = 1,
24         },
25 };
26
27 struct efi_capsule_update_info update_info = {
28         .dfu_string = "sf 0:0=flash-bin raw 0x400 0x1f0000",
29         .images = fw_images,
30 };
31
32 u8 num_image_type_guids = ARRAY_SIZE(fw_images);
33 #endif /* EFI_HAVE_CAPSULE_SUPPORT */
34
35 int board_phys_sdram_size(phys_size_t *size)
36 {
37         u32 ddr_size = readl(M4_BOOTROM_BASE_ADDR);
38
39         if (ddr_size == 4) {
40                 *size = 0x100000000;
41         } else if (ddr_size == 3) {
42                 *size = 0xc0000000;
43         } else if (ddr_size == 2) {
44                 *size = 0x80000000;
45         } else if (ddr_size == 1) {
46                 *size = 0x40000000;
47         } else {
48                 printf("Unknown DDR type!!!\n");
49                 *size = 0x40000000;
50         }
51
52         return 0;
53 }
54
55 /*
56  * If the SoM is mounted on a baseboard with a USB ethernet controller,
57  * there might be an additional MAC address programmed to the MAC OTP fuses.
58  * Although the i.MX8MM has only one MAC, the MAC0, MAC1 and MAC2 registers
59  * in the OTP fuses can still be used to store two separate addresses.
60  * Try to read the secondary address from MAC1 and MAC2 and adjust the
61  * devicetree so Linux can pick up the MAC address.
62  */
63 int fdt_set_usb_eth_addr(void *blob)
64 {
65         u32 value = readl(OCOTP_BASE_ADDR + 0x660);
66         unsigned char mac[6];
67         int node, ret;
68
69         mac[0] = value >> 24;
70         mac[1] = value >> 16;
71         mac[2] = value >> 8;
72         mac[3] = value;
73
74         value = readl(OCOTP_BASE_ADDR + 0x650);
75         mac[4] = value >> 24;
76         mac[5] = value >> 16;
77
78         node = fdt_path_offset(blob, fdt_get_alias(blob, "ethernet1"));
79         if (node < 0) {
80                 /*
81                  * There is no node for the USB ethernet in the devicetree. Just skip.
82                  */
83                 return 0;
84         }
85
86         if (is_zero_ethaddr(mac)) {
87                 printf("\nNo MAC address for USB ethernet set in OTP fuses!\n");
88                 return 0;
89         }
90
91         if (!is_valid_ethaddr(mac)) {
92                 printf("\nInvalid MAC address for USB ethernet set in OTP fuses!\n");
93                 return -EINVAL;
94         }
95
96         ret = fdt_setprop(blob, node, "local-mac-address", &mac, 6);
97         if (ret)
98                 ret = fdt_setprop(blob, node, "mac-address", &mac, 6);
99
100         if (ret)
101                 printf("\nMissing mac-address or local-mac-address property in dt, skip setting MAC address for USB ethernet\n");
102
103         return 0;
104 }
105
106 int ft_board_setup(void *blob, struct bd_info *bd)
107 {
108         int ret = fdt_set_usb_eth_addr(blob);
109
110         if (ret)
111                 return ret;
112
113         return fdt_fixup_memory(blob, PHYS_SDRAM, gd->ram_size);
114 }
115
116 int board_init(void)
117 {
118         return 0;
119 }