blob: 6785bf58e9496c98e179d9cb95423472d44f6257 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Jorge Ramirez-Ortiz9f2d1b22018-01-10 11:33:50 +01002/*
3 * Board init file for Dragonboard 820C
4 *
Jorge Ramirez-Ortizc8833d32018-01-10 11:33:52 +01005 * (C) Copyright 2017 Jorge Ramirez-Ortiz <jorge.ramirez-ortiz@linaro.org>
Jorge Ramirez-Ortiz9f2d1b22018-01-10 11:33:50 +01006 */
7
Simon Glassafb02152019-12-28 10:45:01 -07008#include <cpu_func.h>
Simon Glass97589732020-05-10 11:40:02 -06009#include <init.h>
Simon Glass5e6201b2019-08-01 09:46:51 -060010#include <env.h>
Simon Glass274e0b02020-05-10 11:39:56 -060011#include <asm/cache.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060012#include <asm/global_data.h>
Jorge Ramirez-Ortiz9f2d1b22018-01-10 11:33:50 +010013#include <linux/arm-smccc.h>
14#include <linux/psci.h>
15#include <common.h>
16#include <dm.h>
17#include <asm/io.h>
18#include <linux/bitops.h>
19#include <asm/psci.h>
Jorge Ramirez-Ortizc8833d32018-01-10 11:33:52 +010020#include <asm/gpio.h>
Jorge Ramirez-Ortiz9f2d1b22018-01-10 11:33:50 +010021
Caleb Connolly10a0abb2023-11-07 12:41:03 +000022#define TLMM_BASE_ADDR (0x1010000)
23
24/* Strength (sdc1) */
25#define SDC1_HDRV_PULL_CTL_REG (TLMM_BASE_ADDR + 0x0012D000)
26
Jorge Ramirez-Ortiz9f2d1b22018-01-10 11:33:50 +010027DECLARE_GLOBAL_DATA_PTR;
28
29int dram_init(void)
30{
31 gd->ram_size = PHYS_SDRAM_SIZE;
32
33 return 0;
34}
35
36int dram_init_banksize(void)
37{
38 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
39 gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
40
41 gd->bd->bi_dram[1].start = PHYS_SDRAM_2;
42 gd->bd->bi_dram[1].size = PHYS_SDRAM_2_SIZE;
43
44 return 0;
45}
46
47static void sdhci_power_init(void)
48{
49 const u32 TLMM_PULL_MASK = 0x3;
50 const u32 TLMM_HDRV_MASK = 0x7;
51
52 struct tlmm_cfg {
53 u32 bit; /* bit in the register */
54 u8 mask; /* mask clk/dat/cmd control */
55 u8 val;
56 };
57
58 /* bit offsets in the sdc tlmm register */
59 enum { SDC1_DATA_HDRV = 0,
60 SDC1_CMD_HDRV = 3,
61 SDC1_CLK_HDRV = 6,
62 SDC1_DATA_PULL = 9,
63 SDC1_CMD_PULL = 11,
64 SDC1_CLK_PULL = 13,
65 SDC1_RCLK_PULL = 15,
66 };
67
68 enum { TLMM_PULL_DOWN = 0x1,
69 TLMM_PULL_UP = 0x3,
70 TLMM_NO_PULL = 0x0,
71 };
72
73 enum { TLMM_CUR_VAL_10MA = 0x04,
74 TLMM_CUR_VAL_16MA = 0x07,
75 };
76 int i;
77
78 /* drive strength configs for sdhc pins */
79 const struct tlmm_cfg hdrv[] = {
Wolfgang Denk9d328a62021-09-27 17:42:38 +020080
Jorge Ramirez-Ortiz9f2d1b22018-01-10 11:33:50 +010081 { SDC1_CLK_HDRV, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK, },
82 { SDC1_CMD_HDRV, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK, },
83 { SDC1_DATA_HDRV, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK, },
84 };
85
86 /* pull configs for sdhc pins */
87 const struct tlmm_cfg pull[] = {
Wolfgang Denk9d328a62021-09-27 17:42:38 +020088
Jorge Ramirez-Ortiz9f2d1b22018-01-10 11:33:50 +010089 { SDC1_CLK_PULL, TLMM_NO_PULL, TLMM_PULL_MASK, },
90 { SDC1_CMD_PULL, TLMM_PULL_UP, TLMM_PULL_MASK, },
91 { SDC1_DATA_PULL, TLMM_PULL_UP, TLMM_PULL_MASK, },
92 };
93
94 const struct tlmm_cfg rclk[] = {
Wolfgang Denk9d328a62021-09-27 17:42:38 +020095
Jorge Ramirez-Ortiz9f2d1b22018-01-10 11:33:50 +010096 { SDC1_RCLK_PULL, TLMM_PULL_DOWN, TLMM_PULL_MASK,},
97 };
98
99 for (i = 0; i < ARRAY_SIZE(hdrv); i++)
100 clrsetbits_le32(SDC1_HDRV_PULL_CTL_REG,
101 hdrv[i].mask << hdrv[i].bit,
102 hdrv[i].val << hdrv[i].bit);
103
104 for (i = 0; i < ARRAY_SIZE(pull); i++)
105 clrsetbits_le32(SDC1_HDRV_PULL_CTL_REG,
106 pull[i].mask << pull[i].bit,
107 pull[i].val << pull[i].bit);
108
109 for (i = 0; i < ARRAY_SIZE(rclk); i++)
110 clrsetbits_le32(SDC1_HDRV_PULL_CTL_REG,
111 rclk[i].mask << rclk[i].bit,
112 rclk[i].val << rclk[i].bit);
113}
114
115static void show_psci_version(void)
116{
117 struct arm_smccc_res res;
118
119 arm_smccc_smc(ARM_PSCI_0_2_FN_PSCI_VERSION, 0, 0, 0, 0, 0, 0, 0, &res);
120
121 printf("PSCI: v%ld.%ld\n",
122 PSCI_VERSION_MAJOR(res.a0),
123 PSCI_VERSION_MINOR(res.a0));
124}
125
126int board_init(void)
127{
128 sdhci_power_init();
129 show_psci_version();
130
131 return 0;
132}
133
Harald Seiler6f14d5f2020-12-15 16:47:52 +0100134void reset_cpu(void)
Jorge Ramirez-Ortiz9f2d1b22018-01-10 11:33:50 +0100135{
136 psci_system_reset();
Jorge Ramirez-Ortizc8833d32018-01-10 11:33:52 +0100137}
138
139/* Check for vol- button - if pressed - stop autoboot */
140int misc_init_r(void)
141{
142 struct udevice *pon;
143 struct gpio_desc resin;
144 int node, ret;
145
146 ret = uclass_get_device_by_name(UCLASS_GPIO, "pm8994_pon@800", &pon);
147 if (ret < 0) {
148 printf("Failed to find PMIC pon node. Check device tree\n");
149 return 0;
150 }
151
152 node = fdt_subnode_offset(gd->fdt_blob, dev_of_offset(pon),
153 "key_vol_down");
154 if (node < 0) {
155 printf("Failed to find key_vol_down node. Check device tree\n");
156 return 0;
157 }
158
159 if (gpio_request_by_name_nodev(offset_to_ofnode(node), "gpios", 0,
160 &resin, 0)) {
161 printf("Failed to request key_vol_down button.\n");
162 return 0;
163 }
164
165 if (dm_gpio_get_value(&resin)) {
166 env_set("bootdelay", "-1");
167 printf("Power button pressed - dropping to console.\n");
168 }
169
170 return 0;
171}