blob: 5f53c2194715b26e1b9ffec31bc5fa2f61deb61d [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
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
81 return 0;
82}