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