Dzmitry Sankouski | 2826cbd | 2021-10-17 13:44:31 +0300 | [diff] [blame] | 1 | // 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 Connolly | 89a90d0 | 2023-12-05 13:46:48 +0000 | [diff] [blame] | 8 | #include <button.h> |
Dzmitry Sankouski | 2826cbd | 2021-10-17 13:44:31 +0300 | [diff] [blame] | 9 | #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 | |
| 16 | DECLARE_GLOBAL_DATA_PTR; |
| 17 | |
| 18 | int dram_init(void) |
| 19 | { |
| 20 | return fdtdec_setup_mem_size_base(); |
| 21 | } |
| 22 | |
| 23 | void 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 Connolly | 89a90d0 | 2023-12-05 13:46:48 +0000 | [diff] [blame] | 36 | struct udevice *btn; |
| 37 | int ret; |
| 38 | enum button_state_t state; |
Dzmitry Sankouski | 2826cbd | 2021-10-17 13:44:31 +0300 | [diff] [blame] | 39 | |
Caleb Connolly | 89a90d0 | 2023-12-05 13:46:48 +0000 | [diff] [blame] | 40 | ret = button_get_by_label("pwrkey", &btn); |
Dzmitry Sankouski | 2826cbd | 2021-10-17 13:44:31 +0300 | [diff] [blame] | 41 | if (ret < 0) { |
Caleb Connolly | 89a90d0 | 2023-12-05 13:46:48 +0000 | [diff] [blame] | 42 | printf("Couldn't find power button!\n"); |
| 43 | return ret; |
Dzmitry Sankouski | 2826cbd | 2021-10-17 13:44:31 +0300 | [diff] [blame] | 44 | } |
| 45 | |
Caleb Connolly | 89a90d0 | 2023-12-05 13:46:48 +0000 | [diff] [blame] | 46 | state = button_get_state(btn); |
| 47 | if (state == BUTTON_ON) { |
Dzmitry Sankouski | 2826cbd | 2021-10-17 13:44:31 +0300 | [diff] [blame] | 48 | env_set("key_power", "1"); |
| 49 | printf("Power button pressed\n"); |
| 50 | } else { |
| 51 | env_set("key_power", "0"); |
| 52 | } |
| 53 | |
Dzmitry Sankouski | 80d0ce7 | 2022-12-27 22:47:09 +0300 | [diff] [blame] | 54 | /* |
| 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 Sankouski | 2826cbd | 2021-10-17 13:44:31 +0300 | [diff] [blame] | 72 | return 0; |
| 73 | } |