blob: 185880de1396edbbb51b2344326556e8059e53e4 [file] [log] [blame]
Vyacheslav Bocharovde19bae2021-09-20 11:40:15 +03001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2021 Vyacheslav Bocharov
4 * Author: Vyacheslav Bocharov <adeep@lexina.in>
5 * Author: Neil Armstrong <narmstrong@baylibre.com>
6 *
7 */
8
9#include <common.h>
10#include <dm.h>
11#include <adc.h>
12#include <env.h>
13#include <init.h>
14#include <net.h>
15#include <asm/io.h>
16#include <asm/arch/gx.h>
17#include <asm/arch/sm.h>
18#include <asm/arch/eth.h>
19#include <asm/arch/mem.h>
20
21#define EFUSE_SN_OFFSET 50
22#define EFUSE_SN_SIZE 32
23#define EFUSE_MAC_OFFSET 0
24#define EFUSE_MAC_SIZE 6
25#define EFUSE_USID_OFFSET 18
26#define EFUSE_USID_SIZE 32
27
28int misc_init_r(void)
29{
30 u8 mac_addr[EFUSE_MAC_SIZE];
31 char serial[EFUSE_SN_SIZE];
32 char usid[EFUSE_USID_SIZE];
33 ssize_t len;
34 unsigned int adcval;
35 int ret;
36
37 if (!eth_env_get_enetaddr("ethaddr", mac_addr)) {
38 len = meson_sm_read_efuse(EFUSE_MAC_OFFSET,
39 mac_addr, EFUSE_MAC_SIZE);
40 if (len == EFUSE_MAC_SIZE && is_valid_ethaddr(mac_addr))
41 eth_env_set_enetaddr("ethaddr", mac_addr);
42 else
43 meson_generate_serial_ethaddr();
44 }
45
46 if (!env_get("serial")) {
47 len = meson_sm_read_efuse(EFUSE_SN_OFFSET, serial,
48 EFUSE_SN_SIZE);
49 if (len == EFUSE_SN_SIZE)
50 env_set("serial", serial);
51 }
52
53 if (!env_get("usid")) {
54 len = meson_sm_read_efuse(EFUSE_USID_OFFSET, usid,
55 EFUSE_USID_SIZE);
56 if (len == EFUSE_USID_SIZE)
57 env_set("usid", usid);
58 }
59
60 ret = adc_channel_single_shot("adc@8680", 0, &adcval);
61 if (adcval < 3000)
62 env_set("userbutton", "true");
63 else
64 env_set("userbutton", "false");
65
66 return 0;
67}