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