uboot/board/kontron/sl-mx8mm/sl-mx8mm.c
<<
>>
Prefs
   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 <fdt_support.h>
  10#include <linux/errno.h>
  11#include <net.h>
  12
  13DECLARE_GLOBAL_DATA_PTR;
  14
  15int board_phys_sdram_size(phys_size_t *size)
  16{
  17        u32 ddr_size = readl(M4_BOOTROM_BASE_ADDR);
  18
  19        if (ddr_size == 4) {
  20                *size = 0x100000000;
  21        } else if (ddr_size == 3) {
  22                *size = 0xc0000000;
  23        } else if (ddr_size == 2) {
  24                *size = 0x80000000;
  25        } else if (ddr_size == 1) {
  26                *size = 0x40000000;
  27        } else {
  28                printf("Unknown DDR type!!!\n");
  29                *size = 0x40000000;
  30        }
  31
  32        return 0;
  33}
  34
  35/*
  36 * If the SoM is mounted on a baseboard with a USB ethernet controller,
  37 * there might be an additional MAC address programmed to the MAC OTP fuses.
  38 * Although the i.MX8MM has only one MAC, the MAC0, MAC1 and MAC2 registers
  39 * in the OTP fuses can still be used to store two separate addresses.
  40 * Try to read the secondary address from MAC1 and MAC2 and adjust the
  41 * devicetree so Linux can pick up the MAC address.
  42 */
  43int fdt_set_usb_eth_addr(void *blob)
  44{
  45        u32 value = readl(OCOTP_BASE_ADDR + 0x660);
  46        unsigned char mac[6];
  47        int node, ret;
  48
  49        mac[0] = value >> 24;
  50        mac[1] = value >> 16;
  51        mac[2] = value >> 8;
  52        mac[3] = value;
  53
  54        value = readl(OCOTP_BASE_ADDR + 0x650);
  55        mac[4] = value >> 24;
  56        mac[5] = value >> 16;
  57
  58        node = fdt_path_offset(blob, fdt_get_alias(blob, "ethernet1"));
  59        if (node < 0) {
  60                /*
  61                 * There is no node for the USB ethernet in the devicetree. Just skip.
  62                 */
  63                return 0;
  64        }
  65
  66        if (is_zero_ethaddr(mac)) {
  67                printf("\nNo MAC address for USB ethernet set in OTP fuses!\n");
  68                return 0;
  69        }
  70
  71        if (!is_valid_ethaddr(mac)) {
  72                printf("\nInvalid MAC address for USB ethernet set in OTP fuses!\n");
  73                return -EINVAL;
  74        }
  75
  76        ret = fdt_setprop(blob, node, "local-mac-address", &mac, 6);
  77        if (ret)
  78                ret = fdt_setprop(blob, node, "mac-address", &mac, 6);
  79
  80        if (ret)
  81                printf("\nMissing mac-address or local-mac-address property in dt, skip setting MAC address for USB ethernet\n");
  82
  83        return 0;
  84}
  85
  86int ft_board_setup(void *blob, struct bd_info *bd)
  87{
  88        int ret = fdt_set_usb_eth_addr(blob);
  89
  90        if (ret)
  91                return ret;
  92
  93        return fdt_fixup_memory(blob, PHYS_SDRAM, gd->ram_size);
  94}
  95
  96int board_init(void)
  97{
  98        return 0;
  99}
 100