blob: 6c096b49a1f8286c3635a040211d4d64b3e9acf0 [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>
Jorge Ramirez-Ortiz9f2d1b22018-01-10 11:33:50 +01009#include <asm/arch/sysmap-apq8096.h>
Simon Glass5e6201b2019-08-01 09:46:51 -060010#include <env.h>
Jorge Ramirez-Ortiz9f2d1b22018-01-10 11:33:50 +010011#include <linux/arm-smccc.h>
12#include <linux/psci.h>
13#include <common.h>
14#include <dm.h>
15#include <asm/io.h>
16#include <linux/bitops.h>
17#include <asm/psci.h>
Jorge Ramirez-Ortizc8833d32018-01-10 11:33:52 +010018#include <asm/gpio.h>
Jorge Ramirez-Ortiz9f2d1b22018-01-10 11:33:50 +010019
20DECLARE_GLOBAL_DATA_PTR;
21
22int dram_init(void)
23{
24 gd->ram_size = PHYS_SDRAM_SIZE;
25
26 return 0;
27}
28
29int dram_init_banksize(void)
30{
31 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
32 gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
33
34 gd->bd->bi_dram[1].start = PHYS_SDRAM_2;
35 gd->bd->bi_dram[1].size = PHYS_SDRAM_2_SIZE;
36
37 return 0;
38}
39
40static void sdhci_power_init(void)
41{
42 const u32 TLMM_PULL_MASK = 0x3;
43 const u32 TLMM_HDRV_MASK = 0x7;
44
45 struct tlmm_cfg {
46 u32 bit; /* bit in the register */
47 u8 mask; /* mask clk/dat/cmd control */
48 u8 val;
49 };
50
51 /* bit offsets in the sdc tlmm register */
52 enum { SDC1_DATA_HDRV = 0,
53 SDC1_CMD_HDRV = 3,
54 SDC1_CLK_HDRV = 6,
55 SDC1_DATA_PULL = 9,
56 SDC1_CMD_PULL = 11,
57 SDC1_CLK_PULL = 13,
58 SDC1_RCLK_PULL = 15,
59 };
60
61 enum { TLMM_PULL_DOWN = 0x1,
62 TLMM_PULL_UP = 0x3,
63 TLMM_NO_PULL = 0x0,
64 };
65
66 enum { TLMM_CUR_VAL_10MA = 0x04,
67 TLMM_CUR_VAL_16MA = 0x07,
68 };
69 int i;
70
71 /* drive strength configs for sdhc pins */
72 const struct tlmm_cfg hdrv[] = {
73
74 { SDC1_CLK_HDRV, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK, },
75 { SDC1_CMD_HDRV, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK, },
76 { SDC1_DATA_HDRV, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK, },
77 };
78
79 /* pull configs for sdhc pins */
80 const struct tlmm_cfg pull[] = {
81
82 { SDC1_CLK_PULL, TLMM_NO_PULL, TLMM_PULL_MASK, },
83 { SDC1_CMD_PULL, TLMM_PULL_UP, TLMM_PULL_MASK, },
84 { SDC1_DATA_PULL, TLMM_PULL_UP, TLMM_PULL_MASK, },
85 };
86
87 const struct tlmm_cfg rclk[] = {
88
89 { SDC1_RCLK_PULL, TLMM_PULL_DOWN, TLMM_PULL_MASK,},
90 };
91
92 for (i = 0; i < ARRAY_SIZE(hdrv); i++)
93 clrsetbits_le32(SDC1_HDRV_PULL_CTL_REG,
94 hdrv[i].mask << hdrv[i].bit,
95 hdrv[i].val << hdrv[i].bit);
96
97 for (i = 0; i < ARRAY_SIZE(pull); i++)
98 clrsetbits_le32(SDC1_HDRV_PULL_CTL_REG,
99 pull[i].mask << pull[i].bit,
100 pull[i].val << pull[i].bit);
101
102 for (i = 0; i < ARRAY_SIZE(rclk); i++)
103 clrsetbits_le32(SDC1_HDRV_PULL_CTL_REG,
104 rclk[i].mask << rclk[i].bit,
105 rclk[i].val << rclk[i].bit);
106}
107
108static void show_psci_version(void)
109{
110 struct arm_smccc_res res;
111
112 arm_smccc_smc(ARM_PSCI_0_2_FN_PSCI_VERSION, 0, 0, 0, 0, 0, 0, 0, &res);
113
114 printf("PSCI: v%ld.%ld\n",
115 PSCI_VERSION_MAJOR(res.a0),
116 PSCI_VERSION_MINOR(res.a0));
117}
118
119int board_init(void)
120{
121 sdhci_power_init();
122 show_psci_version();
123
124 return 0;
125}
126
127void reset_cpu(ulong addr)
128{
129 psci_system_reset();
Jorge Ramirez-Ortizc8833d32018-01-10 11:33:52 +0100130}
131
132/* Check for vol- button - if pressed - stop autoboot */
133int misc_init_r(void)
134{
135 struct udevice *pon;
136 struct gpio_desc resin;
137 int node, ret;
138
139 ret = uclass_get_device_by_name(UCLASS_GPIO, "pm8994_pon@800", &pon);
140 if (ret < 0) {
141 printf("Failed to find PMIC pon node. Check device tree\n");
142 return 0;
143 }
144
145 node = fdt_subnode_offset(gd->fdt_blob, dev_of_offset(pon),
146 "key_vol_down");
147 if (node < 0) {
148 printf("Failed to find key_vol_down node. Check device tree\n");
149 return 0;
150 }
151
152 if (gpio_request_by_name_nodev(offset_to_ofnode(node), "gpios", 0,
153 &resin, 0)) {
154 printf("Failed to request key_vol_down button.\n");
155 return 0;
156 }
157
158 if (dm_gpio_get_value(&resin)) {
159 env_set("bootdelay", "-1");
160 printf("Power button pressed - dropping to console.\n");
161 }
162
163 return 0;
164}