common: Move reset_cpu() to the CPU header
[oweals/u-boot.git] / board / qualcomm / dragonboard820c / dragonboard820c.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Board init file for Dragonboard 820C
4  *
5  * (C) Copyright 2017 Jorge Ramirez-Ortiz <jorge.ramirez-ortiz@linaro.org>
6  */
7
8 #include <cpu_func.h>
9 #include <asm/arch/sysmap-apq8096.h>
10 #include <env.h>
11 #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>
18 #include <asm/gpio.h>
19
20 DECLARE_GLOBAL_DATA_PTR;
21
22 int dram_init(void)
23 {
24         gd->ram_size = PHYS_SDRAM_SIZE;
25
26         return 0;
27 }
28
29 int 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
40 static 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
108 static 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
119 int board_init(void)
120 {
121         sdhci_power_init();
122         show_psci_version();
123
124         return 0;
125 }
126
127 void reset_cpu(ulong addr)
128 {
129         psci_system_reset();
130 }
131
132 /* Check for vol- button - if pressed - stop autoboot */
133 int 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 }