blob: 254af7907ad3ba4e4ad11c388ea354054abdd2a6 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Mateusz Kulikowskiee5e70d2016-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 Kulikowskiee5e70d2016-03-31 23:12:33 +02006 */
7
8#include <common.h>
9#include <dm.h>
Simon Glass5e6201b2019-08-01 09:46:51 -060010#include <env.h>
Simon Glassa7b51302019-11-14 12:57:46 -070011#include <init.h>
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020012#include <usb.h>
13#include <asm/gpio.h>
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +010014#include <fdt_support.h>
Ramon Fried806549682018-07-31 12:29:58 +030015#include <asm/arch/dram.h>
Ramon Friede82a31c2018-08-03 16:25:37 +030016#include <asm/arch/misc.h>
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020017
18DECLARE_GLOBAL_DATA_PTR;
19
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +010020/* pointer to the device tree ammended by the firmware */
Jorge Ramirez-Ortizf44f3012018-01-10 11:34:38 +010021extern void *fw_dtb;
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +010022
Jorge Ramirez-Ortizf44f3012018-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-Ortiz2cd3db92018-01-10 11:34:35 +010032
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020033int dram_init(void)
34{
35 gd->ram_size = PHYS_SDRAM_1_SIZE;
Jorge Ramirez-Ortizf44f3012018-01-10 11:34:38 +010036
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020037 return 0;
38}
39
Simon Glass2f949c32017-03-31 08:40:32 -060040int dram_init_banksize(void)
Mateusz Kulikowskiee5e70d2016-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 Glass2f949c32017-03-31 08:40:32 -060044
45 return 0;
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020046}
47
Ramon Friedbc866cc82018-09-21 13:35:43 +030048int board_usb_init(int index, enum usb_init_type init)
Mateusz Kulikowskiee5e70d2016-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 Glassdd79d6e2017-01-17 16:52:55 -070066 node = fdt_subnode_offset(gd->fdt_blob,
67 dev_of_offset(pmic_gpio),
Mateusz Kulikowskiee5e70d2016-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 Glass1d9af1f2017-05-30 21:47:09 -060073 ret = gpio_request_by_name_nodev(offset_to_ofnode(node),
74 "gpios", 0, &hub_reset, 0);
Mateusz Kulikowskiee5e70d2016-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 Glassdd79d6e2017-01-17 16:52:55 -070082 node = fdt_subnode_offset(gd->fdt_blob,
83 dev_of_offset(pmic_gpio),
Mateusz Kulikowskiee5e70d2016-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 Glass1d9af1f2017-05-30 21:47:09 -060089 ret = gpio_request_by_name_nodev(offset_to_ofnode(node),
90 "gpios", 0, &usb_sel, 0);
Mateusz Kulikowskiee5e70d2016-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 Friedbc866cc82018-09-21 13:35:43 +030097 if (init == USB_INIT_HOST) {
Mateusz Kulikowskiee5e70d2016-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 Kulikowskiee5e70d2016-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 Glassdd79d6e2017-01-17 16:52:55 -0700129 node = fdt_subnode_offset(gd->fdt_blob, dev_of_offset(pon),
130 "key_vol_down");
Mateusz Kulikowskiee5e70d2016-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 Glass1d9af1f2017-05-30 21:47:09 -0600136 if (gpio_request_by_name_nodev(offset_to_ofnode(node), "gpios", 0,
137 &resin, 0)) {
Mateusz Kulikowskiee5e70d2016-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 Glass6a38e412017-08-03 12:22:09 -0600143 env_set("bootdelay", "-1");
Ramon Frieddbc94102018-09-21 13:35:55 +0300144 env_set("bootcmd", "fastboot 0");
145 printf("key_vol_down pressed - Starting fastboot.\n");
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +0200146 }
147
148 return 0;
149}
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +0100150
151int board_init(void)
152{
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +0100153 return 0;
154}
155
Ramon Fried63596f02018-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 Friede82a31c2018-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-Ortiz2cd3db92018-01-10 11:34:35 +0100173int ft_board_setup(void *blob, bd_t *bd)
174{
Ramon Friede82a31c2018-08-03 16:25:37 +0300175 u8 mac[ARP_HLEN];
176
177 msm_fixup_memory(blob);
178
179 if (!eth_env_get_enetaddr("wlanaddr", mac)) {
180 msm_generate_mac_addr(mac);
Jorge Ramirez-Ortizf44f3012018-01-10 11:34:38 +0100181 };
182
Ramon Friede82a31c2018-08-03 16:25:37 +0300183 do_fixup_by_compat(blob, "qcom,wcnss-wlan",
184 "local-mac-address", mac, ARP_HLEN, 1);
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +0100185
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +0100186
Ramon Friede82a31c2018-08-03 16:25:37 +0300187 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 };
Ramon Fried806549682018-07-31 12:29:58 +0300195
Ramon Friede82a31c2018-08-03 16:25:37 +0300196 do_fixup_by_compat(blob, "qcom,wcnss-bt",
197 "local-bd-address", mac, ARP_HLEN, 1);
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +0100198 return 0;
199}
Jorge Ramirez-Ortiz4154c9e2018-01-10 11:34:36 +0100200
201void reset_cpu(ulong addr)
202{
203 psci_system_reset();
204}