Dzmitry Sankouski | 4cbc16c | 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 | |
| 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 | |
| 15 | DECLARE_GLOBAL_DATA_PTR; |
| 16 | |
| 17 | int dram_init(void) |
| 18 | { |
| 19 | return fdtdec_setup_mem_size_base(); |
| 20 | } |
| 21 | |
| 22 | void 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 Sankouski | 971ccee | 2022-12-27 22:47:09 +0300 | [diff] [blame] | 81 | /* |
| 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 Sankouski | 4cbc16c | 2021-10-17 13:44:31 +0300 | [diff] [blame] | 99 | return 0; |
| 100 | } |