blob: 1f8850239437f7f37f0a62b1d64f9441befae496 [file] [log] [blame]
Dzmitry Sankouski4cbc16c2021-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
8#include <init.h>
9#include <env.h>
10#include <common.h>
11#include <asm/system.h>
12#include <asm/gpio.h>
13#include <dm.h>
14
15DECLARE_GLOBAL_DATA_PTR;
16
17int dram_init(void)
18{
19 return fdtdec_setup_mem_size_base();
20}
21
22void reset_cpu(void)
23{
24 psci_system_reset();
25}
26
27__weak int board_init(void)
28{
29 return 0;
30}
31
32/* Check for vol- and power buttons */
33__weak int misc_init_r(void)
34{
35 struct udevice *pon;
36 struct gpio_desc resin;
37 int node, ret;
38
39 ret = uclass_get_device_by_name(UCLASS_GPIO, "pm8998_pon@800", &pon);
40 if (ret < 0) {
41 printf("Failed to find PMIC pon node. Check device tree\n");
42 return 0;
43 }
44
45 node = fdt_subnode_offset(gd->fdt_blob, dev_of_offset(pon),
46 "key_vol_down");
47 if (node < 0) {
48 printf("Failed to find key_vol_down node. Check device tree\n");
49 return 0;
50 }
51 if (gpio_request_by_name_nodev(offset_to_ofnode(node), "gpios", 0,
52 &resin, 0)) {
53 printf("Failed to request key_vol_down button.\n");
54 return 0;
55 }
56 if (dm_gpio_get_value(&resin)) {
57 env_set("key_vol_down", "1");
58 printf("Volume down button pressed\n");
59 } else {
60 env_set("key_vol_down", "0");
61 }
62
63 node = fdt_subnode_offset(gd->fdt_blob, dev_of_offset(pon),
64 "key_power");
65 if (node < 0) {
66 printf("Failed to find key_power node. Check device tree\n");
67 return 0;
68 }
69 if (gpio_request_by_name_nodev(offset_to_ofnode(node), "gpios", 0,
70 &resin, 0)) {
71 printf("Failed to request key_power button.\n");
72 return 0;
73 }
74 if (dm_gpio_get_value(&resin)) {
75 env_set("key_power", "1");
76 printf("Power button pressed\n");
77 } else {
78 env_set("key_power", "0");
79 }
80
Dzmitry Sankouski971ccee2022-12-27 22:47:09 +030081 /*
82 * search for kaslr address, set by primary bootloader by searching first
83 * 0x100 relocated bytes at u-boot's initial load address range
84 */
85 uintptr_t start = gd->ram_base;
86 uintptr_t end = start + 0x800000;
87 u8 *addr = (u8 *)start;
88 phys_addr_t *relocaddr = (phys_addr_t *)gd->relocaddr;
89 u32 block_size = 0x1000;
90
91 while (memcmp(addr, relocaddr, 0x100) && (uintptr_t)addr < end)
92 addr += block_size;
93
94 if ((uintptr_t)addr >= end)
95 printf("KASLR not found in range 0x%lx - 0x%lx", start, end);
96 else
97 env_set_addr("KASLR", addr);
98
Dzmitry Sankouski4cbc16c2021-10-17 13:44:31 +030099 return 0;
100}