blob: 06d3d7e0f85b23147cab838d6485a8bc3fd4c4c2 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Mateusz Kulikowski626f0482016-03-31 23:12:33 +02002/*
3 * Board init file for Dragonboard 410C
4 *
5 * (C) Copyright 2015 Mateusz Kulikowski <mateusz.kulikowski@gmail.com>
Mateusz Kulikowski626f0482016-03-31 23:12:33 +02006 */
7
8#include <common.h>
9#include <dm.h>
Simon Glass9fb625c2019-08-01 09:46:51 -060010#include <env.h>
Mateusz Kulikowski626f0482016-03-31 23:12:33 +020011#include <usb.h>
12#include <asm/gpio.h>
Jorge Ramirez-Ortize2beb872018-01-10 11:34:35 +010013#include <fdt_support.h>
Ramon Friedff06dc22018-08-03 16:25:37 +030014#include <environment.h>
Ramon Fried9beb4902018-07-31 12:29:58 +030015#include <asm/arch/dram.h>
Ramon Friedff06dc22018-08-03 16:25:37 +030016#include <asm/arch/misc.h>
Mateusz Kulikowski626f0482016-03-31 23:12:33 +020017
18DECLARE_GLOBAL_DATA_PTR;
19
Jorge Ramirez-Ortize2beb872018-01-10 11:34:35 +010020/* pointer to the device tree ammended by the firmware */
Jorge Ramirez-Ortiz9337dfb2018-01-10 11:34:38 +010021extern void *fw_dtb;
Jorge Ramirez-Ortize2beb872018-01-10 11:34:35 +010022
Jorge Ramirez-Ortiz9337dfb2018-01-10 11:34:38 +010023void *board_fdt_blob_setup(void)
24{
25 if (fdt_magic(fw_dtb) != FDT_MAGIC) {
26 printf("Firmware provided invalid dtb!\n");
27 return NULL;
28 }
29
30 return fw_dtb;
31}
Jorge Ramirez-Ortize2beb872018-01-10 11:34:35 +010032
Mateusz Kulikowski626f0482016-03-31 23:12:33 +020033int dram_init(void)
34{
35 gd->ram_size = PHYS_SDRAM_1_SIZE;
Jorge Ramirez-Ortiz9337dfb2018-01-10 11:34:38 +010036
Mateusz Kulikowski626f0482016-03-31 23:12:33 +020037 return 0;
38}
39
Simon Glass76b00ac2017-03-31 08:40:32 -060040int dram_init_banksize(void)
Mateusz Kulikowski626f0482016-03-31 23:12:33 +020041{
42 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
43 gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
Simon Glass76b00ac2017-03-31 08:40:32 -060044
45 return 0;
Mateusz Kulikowski626f0482016-03-31 23:12:33 +020046}
47
Ramon Friedcd8c3ae2018-09-21 13:35:43 +030048int board_usb_init(int index, enum usb_init_type init)
Mateusz Kulikowski626f0482016-03-31 23:12:33 +020049{
50 static struct udevice *pmic_gpio;
51 static struct gpio_desc hub_reset, usb_sel;
52 int ret = 0, node;
53
54 if (!pmic_gpio) {
55 ret = uclass_get_device_by_name(UCLASS_GPIO,
56 "pm8916_gpios@c000",
57 &pmic_gpio);
58 if (ret < 0) {
59 printf("Failed to find pm8916_gpios@c000 node.\n");
60 return ret;
61 }
62 }
63
64 /* Try to request gpios needed to start usb host on dragonboard */
65 if (!dm_gpio_is_valid(&hub_reset)) {
Simon Glasse160f7d2017-01-17 16:52:55 -070066 node = fdt_subnode_offset(gd->fdt_blob,
67 dev_of_offset(pmic_gpio),
Mateusz Kulikowski626f0482016-03-31 23:12:33 +020068 "usb_hub_reset_pm");
69 if (node < 0) {
70 printf("Failed to find usb_hub_reset_pm dt node.\n");
71 return node;
72 }
Simon Glass150c5af2017-05-30 21:47:09 -060073 ret = gpio_request_by_name_nodev(offset_to_ofnode(node),
74 "gpios", 0, &hub_reset, 0);
Mateusz Kulikowski626f0482016-03-31 23:12:33 +020075 if (ret < 0) {
76 printf("Failed to request usb_hub_reset_pm gpio.\n");
77 return ret;
78 }
79 }
80
81 if (!dm_gpio_is_valid(&usb_sel)) {
Simon Glasse160f7d2017-01-17 16:52:55 -070082 node = fdt_subnode_offset(gd->fdt_blob,
83 dev_of_offset(pmic_gpio),
Mateusz Kulikowski626f0482016-03-31 23:12:33 +020084 "usb_sw_sel_pm");
85 if (node < 0) {
86 printf("Failed to find usb_sw_sel_pm dt node.\n");
87 return 0;
88 }
Simon Glass150c5af2017-05-30 21:47:09 -060089 ret = gpio_request_by_name_nodev(offset_to_ofnode(node),
90 "gpios", 0, &usb_sel, 0);
Mateusz Kulikowski626f0482016-03-31 23:12:33 +020091 if (ret < 0) {
92 printf("Failed to request usb_sw_sel_pm gpio.\n");
93 return ret;
94 }
95 }
96
Ramon Friedcd8c3ae2018-09-21 13:35:43 +030097 if (init == USB_INIT_HOST) {
Mateusz Kulikowski626f0482016-03-31 23:12:33 +020098 /* Start USB Hub */
99 dm_gpio_set_dir_flags(&hub_reset,
100 GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE);
101 mdelay(100);
102 /* Switch usb to host connectors */
103 dm_gpio_set_dir_flags(&usb_sel,
104 GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE);
105 mdelay(100);
106 } else { /* Device */
107 /* Disable hub */
108 dm_gpio_set_dir_flags(&hub_reset, GPIOD_IS_OUT);
109 /* Switch back to device connector */
110 dm_gpio_set_dir_flags(&usb_sel, GPIOD_IS_OUT);
111 }
112
113 return 0;
114}
115
Mateusz Kulikowski626f0482016-03-31 23:12:33 +0200116/* Check for vol- button - if pressed - stop autoboot */
117int misc_init_r(void)
118{
119 struct udevice *pon;
120 struct gpio_desc resin;
121 int node, ret;
122
123 ret = uclass_get_device_by_name(UCLASS_GPIO, "pm8916_pon@800", &pon);
124 if (ret < 0) {
125 printf("Failed to find PMIC pon node. Check device tree\n");
126 return 0;
127 }
128
Simon Glasse160f7d2017-01-17 16:52:55 -0700129 node = fdt_subnode_offset(gd->fdt_blob, dev_of_offset(pon),
130 "key_vol_down");
Mateusz Kulikowski626f0482016-03-31 23:12:33 +0200131 if (node < 0) {
132 printf("Failed to find key_vol_down node. Check device tree\n");
133 return 0;
134 }
135
Simon Glass150c5af2017-05-30 21:47:09 -0600136 if (gpio_request_by_name_nodev(offset_to_ofnode(node), "gpios", 0,
137 &resin, 0)) {
Mateusz Kulikowski626f0482016-03-31 23:12:33 +0200138 printf("Failed to request key_vol_down button.\n");
139 return 0;
140 }
141
142 if (dm_gpio_get_value(&resin)) {
Simon Glass382bee52017-08-03 12:22:09 -0600143 env_set("bootdelay", "-1");
Ramon Friedaa043ee2018-09-21 13:35:55 +0300144 env_set("bootcmd", "fastboot 0");
145 printf("key_vol_down pressed - Starting fastboot.\n");
Mateusz Kulikowski626f0482016-03-31 23:12:33 +0200146 }
147
148 return 0;
149}
Jorge Ramirez-Ortize2beb872018-01-10 11:34:35 +0100150
151int board_init(void)
152{
Jorge Ramirez-Ortize2beb872018-01-10 11:34:35 +0100153 return 0;
154}
155
Ramon Fried2df573e2018-09-21 13:35:46 +0300156int board_late_init(void)
157{
158 char serial[16];
159
160 memset(serial, 0, 16);
161 snprintf(serial, 13, "%x", msm_board_serial());
162 env_set("serial#", serial);
163 return 0;
164}
165
Ramon Friedff06dc22018-08-03 16:25:37 +0300166/* Fixup of DTB for Linux Kernel
167 * 1. Fixup installed DRAM.
168 * 2. Fixup WLAN/BT Mac address:
169 * First, check if MAC addresses for WLAN/BT exists as environemnt
170 * variables wlanaddr,btaddr. if not, generate a unique address.
171 */
172
Jorge Ramirez-Ortize2beb872018-01-10 11:34:35 +0100173int ft_board_setup(void *blob, bd_t *bd)
174{
Ramon Friedff06dc22018-08-03 16:25:37 +0300175 u8 mac[ARP_HLEN];
Jorge Ramirez-Ortize2beb872018-01-10 11:34:35 +0100176
Ramon Fried9beb4902018-07-31 12:29:58 +0300177 msm_fixup_memory(blob);
178
Ramon Friedff06dc22018-08-03 16:25:37 +0300179 if (!eth_env_get_enetaddr("wlanaddr", mac)) {
180 msm_generate_mac_addr(mac);
181 };
182
183 do_fixup_by_compat(blob, "qcom,wcnss-wlan",
184 "local-mac-address", mac, ARP_HLEN, 1);
185
186
187 if (!eth_env_get_enetaddr("btaddr", mac)) {
188 msm_generate_mac_addr(mac);
189
190/* The BD address is same as WLAN MAC address but with
191 * least significant bit flipped.
192 */
193 mac[0] ^= 0x01;
194 };
195
196 do_fixup_by_compat(blob, "qcom,wcnss-bt",
197 "local-bd-address", mac, ARP_HLEN, 1);
Jorge Ramirez-Ortize2beb872018-01-10 11:34:35 +0100198 return 0;
199}
Jorge Ramirez-Ortiz0689eb72018-01-10 11:34:36 +0100200
201void reset_cpu(ulong addr)
202{
203 psci_system_reset();
204}