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