blob: f9cc762a25cd5ba7a90e18e201710d65efb23941 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Jorge Ramirez-Ortiz4b684a62018-01-10 11:33:50 +01002/*
3 * Board init file for Dragonboard 820C
4 *
Jorge Ramirez-Ortiz100fb0b2018-01-10 11:33:52 +01005 * (C) Copyright 2017 Jorge Ramirez-Ortiz <jorge.ramirez-ortiz@linaro.org>
Jorge Ramirez-Ortiz4b684a62018-01-10 11:33:50 +01006 */
7
Simon Glass9a3b4ce2019-12-28 10:45:01 -07008#include <cpu_func.h>
Simon Glass691d7192020-05-10 11:40:02 -06009#include <init.h>
Jorge Ramirez-Ortiz4b684a62018-01-10 11:33:50 +010010#include <asm/arch/sysmap-apq8096.h>
Simon Glass9fb625c2019-08-01 09:46:51 -060011#include <env.h>
Simon Glass90526e92020-05-10 11:39:56 -060012#include <asm/cache.h>
Simon Glass401d1c42020-10-30 21:38:53 -060013#include <asm/global_data.h>
Jorge Ramirez-Ortiz4b684a62018-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-Ortiz100fb0b2018-01-10 11:33:52 +010021#include <asm/gpio.h>
Jorge Ramirez-Ortiz4b684a62018-01-10 11:33:50 +010022
23DECLARE_GLOBAL_DATA_PTR;
24
25int dram_init(void)
26{
27 gd->ram_size = PHYS_SDRAM_SIZE;
28
29 return 0;
30}
31
32int dram_init_banksize(void)
33{
34 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
35 gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
36
37 gd->bd->bi_dram[1].start = PHYS_SDRAM_2;
38 gd->bd->bi_dram[1].size = PHYS_SDRAM_2_SIZE;
39
40 return 0;
41}
42
43static void sdhci_power_init(void)
44{
45 const u32 TLMM_PULL_MASK = 0x3;
46 const u32 TLMM_HDRV_MASK = 0x7;
47
48 struct tlmm_cfg {
49 u32 bit; /* bit in the register */
50 u8 mask; /* mask clk/dat/cmd control */
51 u8 val;
52 };
53
54 /* bit offsets in the sdc tlmm register */
55 enum { SDC1_DATA_HDRV = 0,
56 SDC1_CMD_HDRV = 3,
57 SDC1_CLK_HDRV = 6,
58 SDC1_DATA_PULL = 9,
59 SDC1_CMD_PULL = 11,
60 SDC1_CLK_PULL = 13,
61 SDC1_RCLK_PULL = 15,
62 };
63
64 enum { TLMM_PULL_DOWN = 0x1,
65 TLMM_PULL_UP = 0x3,
66 TLMM_NO_PULL = 0x0,
67 };
68
69 enum { TLMM_CUR_VAL_10MA = 0x04,
70 TLMM_CUR_VAL_16MA = 0x07,
71 };
72 int i;
73
74 /* drive strength configs for sdhc pins */
75 const struct tlmm_cfg hdrv[] = {
Wolfgang Denk0a50b3c2021-09-27 17:42:38 +020076
Jorge Ramirez-Ortiz4b684a62018-01-10 11:33:50 +010077 { SDC1_CLK_HDRV, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK, },
78 { SDC1_CMD_HDRV, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK, },
79 { SDC1_DATA_HDRV, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK, },
80 };
81
82 /* pull configs for sdhc pins */
83 const struct tlmm_cfg pull[] = {
Wolfgang Denk0a50b3c2021-09-27 17:42:38 +020084
Jorge Ramirez-Ortiz4b684a62018-01-10 11:33:50 +010085 { SDC1_CLK_PULL, TLMM_NO_PULL, TLMM_PULL_MASK, },
86 { SDC1_CMD_PULL, TLMM_PULL_UP, TLMM_PULL_MASK, },
87 { SDC1_DATA_PULL, TLMM_PULL_UP, TLMM_PULL_MASK, },
88 };
89
90 const struct tlmm_cfg rclk[] = {
Wolfgang Denk0a50b3c2021-09-27 17:42:38 +020091
Jorge Ramirez-Ortiz4b684a62018-01-10 11:33:50 +010092 { SDC1_RCLK_PULL, TLMM_PULL_DOWN, TLMM_PULL_MASK,},
93 };
94
95 for (i = 0; i < ARRAY_SIZE(hdrv); i++)
96 clrsetbits_le32(SDC1_HDRV_PULL_CTL_REG,
97 hdrv[i].mask << hdrv[i].bit,
98 hdrv[i].val << hdrv[i].bit);
99
100 for (i = 0; i < ARRAY_SIZE(pull); i++)
101 clrsetbits_le32(SDC1_HDRV_PULL_CTL_REG,
102 pull[i].mask << pull[i].bit,
103 pull[i].val << pull[i].bit);
104
105 for (i = 0; i < ARRAY_SIZE(rclk); i++)
106 clrsetbits_le32(SDC1_HDRV_PULL_CTL_REG,
107 rclk[i].mask << rclk[i].bit,
108 rclk[i].val << rclk[i].bit);
109}
110
111static void show_psci_version(void)
112{
113 struct arm_smccc_res res;
114
115 arm_smccc_smc(ARM_PSCI_0_2_FN_PSCI_VERSION, 0, 0, 0, 0, 0, 0, 0, &res);
116
117 printf("PSCI: v%ld.%ld\n",
118 PSCI_VERSION_MAJOR(res.a0),
119 PSCI_VERSION_MINOR(res.a0));
120}
121
122int board_init(void)
123{
124 sdhci_power_init();
125 show_psci_version();
126
127 return 0;
128}
129
Harald Seiler35b65dd2020-12-15 16:47:52 +0100130void reset_cpu(void)
Jorge Ramirez-Ortiz4b684a62018-01-10 11:33:50 +0100131{
132 psci_system_reset();
Jorge Ramirez-Ortiz100fb0b2018-01-10 11:33:52 +0100133}
134
135/* Check for vol- button - if pressed - stop autoboot */
136int misc_init_r(void)
137{
138 struct udevice *pon;
139 struct gpio_desc resin;
140 int node, ret;
141
142 ret = uclass_get_device_by_name(UCLASS_GPIO, "pm8994_pon@800", &pon);
143 if (ret < 0) {
144 printf("Failed to find PMIC pon node. Check device tree\n");
145 return 0;
146 }
147
148 node = fdt_subnode_offset(gd->fdt_blob, dev_of_offset(pon),
149 "key_vol_down");
150 if (node < 0) {
151 printf("Failed to find key_vol_down node. Check device tree\n");
152 return 0;
153 }
154
155 if (gpio_request_by_name_nodev(offset_to_ofnode(node), "gpios", 0,
156 &resin, 0)) {
157 printf("Failed to request key_vol_down button.\n");
158 return 0;
159 }
160
161 if (dm_gpio_get_value(&resin)) {
162 env_set("bootdelay", "-1");
163 printf("Power button pressed - dropping to console.\n");
164 }
165
166 return 0;
167}