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