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