blob: 2f0db628368b18d5c2a6f9df3cb765bae926e27d [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
Caleb Connolly89a90d02023-12-05 13:46:48 +00008#include <button.h>
Simon Glassafb02152019-12-28 10:45:01 -07009#include <cpu_func.h>
Simon Glass97589732020-05-10 11:40:02 -060010#include <init.h>
Simon Glass5e6201b2019-08-01 09:46:51 -060011#include <env.h>
Simon Glass274e0b02020-05-10 11:39:56 -060012#include <asm/cache.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060013#include <asm/global_data.h>
Jorge Ramirez-Ortiz9f2d1b22018-01-10 11:33:50 +010014#include <linux/arm-smccc.h>
15#include <linux/psci.h>
16#include <common.h>
17#include <dm.h>
18#include <asm/io.h>
19#include <linux/bitops.h>
20#include <asm/psci.h>
Jorge Ramirez-Ortizc8833d32018-01-10 11:33:52 +010021#include <asm/gpio.h>
Jorge Ramirez-Ortiz9f2d1b22018-01-10 11:33:50 +010022
Caleb Connolly10a0abb2023-11-07 12:41:03 +000023#define TLMM_BASE_ADDR (0x1010000)
24
25/* Strength (sdc1) */
26#define SDC1_HDRV_PULL_CTL_REG (TLMM_BASE_ADDR + 0x0012D000)
27
Jorge Ramirez-Ortiz9f2d1b22018-01-10 11:33:50 +010028DECLARE_GLOBAL_DATA_PTR;
29
30int dram_init(void)
31{
32 gd->ram_size = PHYS_SDRAM_SIZE;
33
34 return 0;
35}
36
37int dram_init_banksize(void)
38{
39 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
40 gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
41
42 gd->bd->bi_dram[1].start = PHYS_SDRAM_2;
43 gd->bd->bi_dram[1].size = PHYS_SDRAM_2_SIZE;
44
45 return 0;
46}
47
48static void sdhci_power_init(void)
49{
50 const u32 TLMM_PULL_MASK = 0x3;
51 const u32 TLMM_HDRV_MASK = 0x7;
52
53 struct tlmm_cfg {
54 u32 bit; /* bit in the register */
55 u8 mask; /* mask clk/dat/cmd control */
56 u8 val;
57 };
58
59 /* bit offsets in the sdc tlmm register */
60 enum { SDC1_DATA_HDRV = 0,
61 SDC1_CMD_HDRV = 3,
62 SDC1_CLK_HDRV = 6,
63 SDC1_DATA_PULL = 9,
64 SDC1_CMD_PULL = 11,
65 SDC1_CLK_PULL = 13,
66 SDC1_RCLK_PULL = 15,
67 };
68
69 enum { TLMM_PULL_DOWN = 0x1,
70 TLMM_PULL_UP = 0x3,
71 TLMM_NO_PULL = 0x0,
72 };
73
74 enum { TLMM_CUR_VAL_10MA = 0x04,
75 TLMM_CUR_VAL_16MA = 0x07,
76 };
77 int i;
78
79 /* drive strength configs for sdhc pins */
80 const struct tlmm_cfg hdrv[] = {
Wolfgang Denk9d328a62021-09-27 17:42:38 +020081
Jorge Ramirez-Ortiz9f2d1b22018-01-10 11:33:50 +010082 { SDC1_CLK_HDRV, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK, },
83 { SDC1_CMD_HDRV, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK, },
84 { SDC1_DATA_HDRV, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK, },
85 };
86
87 /* pull configs for sdhc pins */
88 const struct tlmm_cfg pull[] = {
Wolfgang Denk9d328a62021-09-27 17:42:38 +020089
Jorge Ramirez-Ortiz9f2d1b22018-01-10 11:33:50 +010090 { SDC1_CLK_PULL, TLMM_NO_PULL, TLMM_PULL_MASK, },
91 { SDC1_CMD_PULL, TLMM_PULL_UP, TLMM_PULL_MASK, },
92 { SDC1_DATA_PULL, TLMM_PULL_UP, TLMM_PULL_MASK, },
93 };
94
95 const struct tlmm_cfg rclk[] = {
Wolfgang Denk9d328a62021-09-27 17:42:38 +020096
Jorge Ramirez-Ortiz9f2d1b22018-01-10 11:33:50 +010097 { SDC1_RCLK_PULL, TLMM_PULL_DOWN, TLMM_PULL_MASK,},
98 };
99
100 for (i = 0; i < ARRAY_SIZE(hdrv); i++)
101 clrsetbits_le32(SDC1_HDRV_PULL_CTL_REG,
102 hdrv[i].mask << hdrv[i].bit,
103 hdrv[i].val << hdrv[i].bit);
104
105 for (i = 0; i < ARRAY_SIZE(pull); i++)
106 clrsetbits_le32(SDC1_HDRV_PULL_CTL_REG,
107 pull[i].mask << pull[i].bit,
108 pull[i].val << pull[i].bit);
109
110 for (i = 0; i < ARRAY_SIZE(rclk); i++)
111 clrsetbits_le32(SDC1_HDRV_PULL_CTL_REG,
112 rclk[i].mask << rclk[i].bit,
113 rclk[i].val << rclk[i].bit);
114}
115
116static void show_psci_version(void)
117{
118 struct arm_smccc_res res;
119
120 arm_smccc_smc(ARM_PSCI_0_2_FN_PSCI_VERSION, 0, 0, 0, 0, 0, 0, 0, &res);
121
122 printf("PSCI: v%ld.%ld\n",
123 PSCI_VERSION_MAJOR(res.a0),
124 PSCI_VERSION_MINOR(res.a0));
125}
126
127int board_init(void)
128{
129 sdhci_power_init();
130 show_psci_version();
131
132 return 0;
133}
134
Harald Seiler6f14d5f2020-12-15 16:47:52 +0100135void reset_cpu(void)
Jorge Ramirez-Ortiz9f2d1b22018-01-10 11:33:50 +0100136{
137 psci_system_reset();
Jorge Ramirez-Ortizc8833d32018-01-10 11:33:52 +0100138}
139
140/* Check for vol- button - if pressed - stop autoboot */
141int misc_init_r(void)
142{
Caleb Connolly89a90d02023-12-05 13:46:48 +0000143 struct udevice *btn;
144 int ret;
145 enum button_state_t state;
Jorge Ramirez-Ortizc8833d32018-01-10 11:33:52 +0100146
Caleb Connolly89a90d02023-12-05 13:46:48 +0000147 ret = button_get_by_label("pwrkey", &btn);
Jorge Ramirez-Ortizc8833d32018-01-10 11:33:52 +0100148 if (ret < 0) {
Caleb Connolly89a90d02023-12-05 13:46:48 +0000149 printf("Couldn't find power button!\n");
150 return ret;
Jorge Ramirez-Ortizc8833d32018-01-10 11:33:52 +0100151 }
152
Caleb Connolly89a90d02023-12-05 13:46:48 +0000153 state = button_get_state(btn);
154 if (state == BUTTON_ON) {
Jorge Ramirez-Ortizc8833d32018-01-10 11:33:52 +0100155 env_set("bootdelay", "-1");
156 printf("Power button pressed - dropping to console.\n");
157 }
158
159 return 0;
160}