blob: 067acc9a6f440d0193b2e1605b3d60ecfccdf9a4 [file] [log] [blame]
Dzmitry Sankouski2826cbd2021-10-17 13:44:31 +03001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Common init part for boards based on SDM845
4 *
5 * (C) Copyright 2021 Dzmitry Sankouski <dsankouski@gmail.com>
6 */
7
Caleb Connolly89a90d02023-12-05 13:46:48 +00008#include <button.h>
Dzmitry Sankouski2826cbd2021-10-17 13:44:31 +03009#include <init.h>
10#include <env.h>
11#include <common.h>
12#include <asm/system.h>
13#include <asm/gpio.h>
14#include <dm.h>
15
16DECLARE_GLOBAL_DATA_PTR;
17
18int dram_init(void)
19{
20 return fdtdec_setup_mem_size_base();
21}
22
23void reset_cpu(void)
24{
25 psci_system_reset();
26}
27
28__weak int board_init(void)
29{
30 return 0;
31}
32
33/* Check for vol- and power buttons */
34__weak int misc_init_r(void)
35{
Caleb Connolly89a90d02023-12-05 13:46:48 +000036 struct udevice *btn;
37 int ret;
38 enum button_state_t state;
Dzmitry Sankouski2826cbd2021-10-17 13:44:31 +030039
Caleb Connolly89a90d02023-12-05 13:46:48 +000040 ret = button_get_by_label("pwrkey", &btn);
Dzmitry Sankouski2826cbd2021-10-17 13:44:31 +030041 if (ret < 0) {
Caleb Connolly89a90d02023-12-05 13:46:48 +000042 printf("Couldn't find power button!\n");
43 return ret;
Dzmitry Sankouski2826cbd2021-10-17 13:44:31 +030044 }
45
Caleb Connolly89a90d02023-12-05 13:46:48 +000046 state = button_get_state(btn);
47 if (state == BUTTON_ON) {
Dzmitry Sankouski2826cbd2021-10-17 13:44:31 +030048 env_set("key_power", "1");
49 printf("Power button pressed\n");
50 } else {
51 env_set("key_power", "0");
52 }
53
Dzmitry Sankouski80d0ce72022-12-27 22:47:09 +030054 /*
55 * search for kaslr address, set by primary bootloader by searching first
56 * 0x100 relocated bytes at u-boot's initial load address range
57 */
58 uintptr_t start = gd->ram_base;
59 uintptr_t end = start + 0x800000;
60 u8 *addr = (u8 *)start;
61 phys_addr_t *relocaddr = (phys_addr_t *)gd->relocaddr;
62 u32 block_size = 0x1000;
63
64 while (memcmp(addr, relocaddr, 0x100) && (uintptr_t)addr < end)
65 addr += block_size;
66
67 if ((uintptr_t)addr >= end)
68 printf("KASLR not found in range 0x%lx - 0x%lx", start, end);
69 else
70 env_set_addr("KASLR", addr);
71
Dzmitry Sankouski2826cbd2021-10-17 13:44:31 +030072 return 0;
73}