arm: mach-k3: Enable dcache in SPL
[oweals/u-boot.git] / board / qualcomm / dragonboard410c / dragonboard410c.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Board init file for Dragonboard 410C
4  *
5  * (C) Copyright 2015 Mateusz Kulikowski <mateusz.kulikowski@gmail.com>
6  */
7
8 #include <common.h>
9 #include <cpu_func.h>
10 #include <dm.h>
11 #include <env.h>
12 #include <init.h>
13 #include <usb.h>
14 #include <asm/gpio.h>
15 #include <fdt_support.h>
16 #include <asm/arch/dram.h>
17 #include <asm/arch/misc.h>
18
19 DECLARE_GLOBAL_DATA_PTR;
20
21 /* pointer to the device tree ammended by the firmware */
22 extern void *fw_dtb;
23
24 void *board_fdt_blob_setup(void)
25 {
26         if (fdt_magic(fw_dtb) != FDT_MAGIC) {
27                 printf("Firmware provided invalid dtb!\n");
28                 return NULL;
29         }
30
31         return fw_dtb;
32 }
33
34 int dram_init(void)
35 {
36         gd->ram_size = PHYS_SDRAM_1_SIZE;
37
38         return 0;
39 }
40
41 int dram_init_banksize(void)
42 {
43         gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
44         gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
45
46         return 0;
47 }
48
49 int board_usb_init(int index, enum usb_init_type init)
50 {
51         static struct udevice *pmic_gpio;
52         static struct gpio_desc hub_reset, usb_sel;
53         int ret = 0, node;
54
55         if (!pmic_gpio) {
56                 ret = uclass_get_device_by_name(UCLASS_GPIO,
57                                                 "pm8916_gpios@c000",
58                                                 &pmic_gpio);
59                 if (ret < 0) {
60                         printf("Failed to find pm8916_gpios@c000 node.\n");
61                         return ret;
62                 }
63         }
64
65         /* Try to request gpios needed to start usb host on dragonboard */
66         if (!dm_gpio_is_valid(&hub_reset)) {
67                 node = fdt_subnode_offset(gd->fdt_blob,
68                                           dev_of_offset(pmic_gpio),
69                                           "usb_hub_reset_pm");
70                 if (node < 0) {
71                         printf("Failed to find usb_hub_reset_pm dt node.\n");
72                         return node;
73                 }
74                 ret = gpio_request_by_name_nodev(offset_to_ofnode(node),
75                                                  "gpios", 0, &hub_reset, 0);
76                 if (ret < 0) {
77                         printf("Failed to request usb_hub_reset_pm gpio.\n");
78                         return ret;
79                 }
80         }
81
82         if (!dm_gpio_is_valid(&usb_sel)) {
83                 node = fdt_subnode_offset(gd->fdt_blob,
84                                           dev_of_offset(pmic_gpio),
85                                           "usb_sw_sel_pm");
86                 if (node < 0) {
87                         printf("Failed to find usb_sw_sel_pm dt node.\n");
88                         return 0;
89                 }
90                 ret = gpio_request_by_name_nodev(offset_to_ofnode(node),
91                                                  "gpios", 0, &usb_sel, 0);
92                 if (ret < 0) {
93                         printf("Failed to request usb_sw_sel_pm gpio.\n");
94                         return ret;
95                 }
96         }
97
98         if (init == USB_INIT_HOST) {
99                 /* Start USB Hub */
100                 dm_gpio_set_dir_flags(&hub_reset,
101                                       GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE);
102                 mdelay(100);
103                 /* Switch usb to host connectors */
104                 dm_gpio_set_dir_flags(&usb_sel,
105                                       GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE);
106                 mdelay(100);
107         } else { /* Device */
108                 /* Disable hub */
109                 dm_gpio_set_dir_flags(&hub_reset, GPIOD_IS_OUT);
110                 /* Switch back to device connector */
111                 dm_gpio_set_dir_flags(&usb_sel, GPIOD_IS_OUT);
112         }
113
114         return 0;
115 }
116
117 /* Check for vol- button - if pressed - stop autoboot */
118 int misc_init_r(void)
119 {
120         struct udevice *pon;
121         struct gpio_desc resin;
122         int node, ret;
123
124         ret = uclass_get_device_by_name(UCLASS_GPIO, "pm8916_pon@800", &pon);
125         if (ret < 0) {
126                 printf("Failed to find PMIC pon node. Check device tree\n");
127                 return 0;
128         }
129
130         node = fdt_subnode_offset(gd->fdt_blob, dev_of_offset(pon),
131                                   "key_vol_down");
132         if (node < 0) {
133                 printf("Failed to find key_vol_down node. Check device tree\n");
134                 return 0;
135         }
136
137         if (gpio_request_by_name_nodev(offset_to_ofnode(node), "gpios", 0,
138                                        &resin, 0)) {
139                 printf("Failed to request key_vol_down button.\n");
140                 return 0;
141         }
142
143         if (dm_gpio_get_value(&resin)) {
144                 env_set("bootdelay", "-1");
145                 env_set("bootcmd", "fastboot 0");
146                 printf("key_vol_down pressed - Starting fastboot.\n");
147         }
148
149         return 0;
150 }
151
152 int board_init(void)
153 {
154         return 0;
155 }
156
157 int board_late_init(void)
158 {
159         char serial[16];
160
161         memset(serial, 0, 16);
162         snprintf(serial, 13, "%x", msm_board_serial());
163         env_set("serial#", serial);
164         return 0;
165 }
166
167 /* Fixup of DTB for Linux Kernel
168  * 1. Fixup installed DRAM.
169  * 2. Fixup WLAN/BT Mac address:
170  *      First, check if MAC addresses for WLAN/BT exists as environemnt
171  *      variables wlanaddr,btaddr. if not, generate a unique address.
172  */
173
174 int ft_board_setup(void *blob, bd_t *bd)
175 {
176         u8 mac[ARP_HLEN];
177
178         msm_fixup_memory(blob);
179
180         if (!eth_env_get_enetaddr("wlanaddr", mac)) {
181                 msm_generate_mac_addr(mac);
182         };
183
184         do_fixup_by_compat(blob, "qcom,wcnss-wlan",
185                            "local-mac-address", mac, ARP_HLEN, 1);
186
187
188         if (!eth_env_get_enetaddr("btaddr", mac)) {
189                 msm_generate_mac_addr(mac);
190
191 /* The BD address is same as WLAN MAC address but with
192  * least significant bit flipped.
193  */
194                 mac[0] ^= 0x01;
195         };
196
197         do_fixup_by_compat(blob, "qcom,wcnss-bt",
198                            "local-bd-address", mac, ARP_HLEN, 1);
199         return 0;
200 }
201
202 void reset_cpu(ulong addr)
203 {
204         psci_system_reset();
205 }