blob: 4d1dbd696dcf8bea6cd1ba19eefceb02fc273f05 [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>
Simon Glassafb02152019-12-28 10:45:01 -07009#include <cpu_func.h>
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020010#include <dm.h>
Simon Glass5e6201b2019-08-01 09:46:51 -060011#include <env.h>
Simon Glassa7b51302019-11-14 12:57:46 -070012#include <init.h>
Simon Glass274e0b02020-05-10 11:39:56 -060013#include <net.h>
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020014#include <usb.h>
Simon Glass274e0b02020-05-10 11:39:56 -060015#include <asm/cache.h>
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020016#include <asm/gpio.h>
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +010017#include <fdt_support.h>
Ramon Fried806549682018-07-31 12:29:58 +030018#include <asm/arch/dram.h>
Ramon Friede82a31c2018-08-03 16:25:37 +030019#include <asm/arch/misc.h>
Simon Glassdbd79542020-05-10 11:40:11 -060020#include <linux/delay.h>
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020021
22DECLARE_GLOBAL_DATA_PTR;
23
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +010024/* pointer to the device tree ammended by the firmware */
Jorge Ramirez-Ortizf44f3012018-01-10 11:34:38 +010025extern void *fw_dtb;
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +010026
Jorge Ramirez-Ortizf44f3012018-01-10 11:34:38 +010027void *board_fdt_blob_setup(void)
28{
29 if (fdt_magic(fw_dtb) != FDT_MAGIC) {
30 printf("Firmware provided invalid dtb!\n");
31 return NULL;
32 }
33
34 return fw_dtb;
35}
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +010036
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020037int dram_init(void)
38{
39 gd->ram_size = PHYS_SDRAM_1_SIZE;
Jorge Ramirez-Ortizf44f3012018-01-10 11:34:38 +010040
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020041 return 0;
42}
43
Simon Glass2f949c32017-03-31 08:40:32 -060044int dram_init_banksize(void)
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020045{
46 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
47 gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
Simon Glass2f949c32017-03-31 08:40:32 -060048
49 return 0;
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020050}
51
Ramon Friedbc866cc82018-09-21 13:35:43 +030052int board_usb_init(int index, enum usb_init_type init)
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020053{
54 static struct udevice *pmic_gpio;
55 static struct gpio_desc hub_reset, usb_sel;
56 int ret = 0, node;
57
58 if (!pmic_gpio) {
59 ret = uclass_get_device_by_name(UCLASS_GPIO,
60 "pm8916_gpios@c000",
61 &pmic_gpio);
62 if (ret < 0) {
63 printf("Failed to find pm8916_gpios@c000 node.\n");
64 return ret;
65 }
66 }
67
68 /* Try to request gpios needed to start usb host on dragonboard */
69 if (!dm_gpio_is_valid(&hub_reset)) {
Simon Glassdd79d6e2017-01-17 16:52:55 -070070 node = fdt_subnode_offset(gd->fdt_blob,
71 dev_of_offset(pmic_gpio),
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020072 "usb_hub_reset_pm");
73 if (node < 0) {
74 printf("Failed to find usb_hub_reset_pm dt node.\n");
75 return node;
76 }
Simon Glass1d9af1f2017-05-30 21:47:09 -060077 ret = gpio_request_by_name_nodev(offset_to_ofnode(node),
78 "gpios", 0, &hub_reset, 0);
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020079 if (ret < 0) {
80 printf("Failed to request usb_hub_reset_pm gpio.\n");
81 return ret;
82 }
83 }
84
85 if (!dm_gpio_is_valid(&usb_sel)) {
Simon Glassdd79d6e2017-01-17 16:52:55 -070086 node = fdt_subnode_offset(gd->fdt_blob,
87 dev_of_offset(pmic_gpio),
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020088 "usb_sw_sel_pm");
89 if (node < 0) {
90 printf("Failed to find usb_sw_sel_pm dt node.\n");
91 return 0;
92 }
Simon Glass1d9af1f2017-05-30 21:47:09 -060093 ret = gpio_request_by_name_nodev(offset_to_ofnode(node),
94 "gpios", 0, &usb_sel, 0);
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020095 if (ret < 0) {
96 printf("Failed to request usb_sw_sel_pm gpio.\n");
97 return ret;
98 }
99 }
100
Ramon Friedbc866cc82018-09-21 13:35:43 +0300101 if (init == USB_INIT_HOST) {
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +0200102 /* Start USB Hub */
103 dm_gpio_set_dir_flags(&hub_reset,
104 GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE);
105 mdelay(100);
106 /* Switch usb to host connectors */
107 dm_gpio_set_dir_flags(&usb_sel,
108 GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE);
109 mdelay(100);
110 } else { /* Device */
111 /* Disable hub */
112 dm_gpio_set_dir_flags(&hub_reset, GPIOD_IS_OUT);
113 /* Switch back to device connector */
114 dm_gpio_set_dir_flags(&usb_sel, GPIOD_IS_OUT);
115 }
116
117 return 0;
118}
119
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +0200120/* Check for vol- button - if pressed - stop autoboot */
121int misc_init_r(void)
122{
123 struct udevice *pon;
124 struct gpio_desc resin;
125 int node, ret;
126
127 ret = uclass_get_device_by_name(UCLASS_GPIO, "pm8916_pon@800", &pon);
128 if (ret < 0) {
129 printf("Failed to find PMIC pon node. Check device tree\n");
130 return 0;
131 }
132
Simon Glassdd79d6e2017-01-17 16:52:55 -0700133 node = fdt_subnode_offset(gd->fdt_blob, dev_of_offset(pon),
134 "key_vol_down");
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +0200135 if (node < 0) {
136 printf("Failed to find key_vol_down node. Check device tree\n");
137 return 0;
138 }
139
Simon Glass1d9af1f2017-05-30 21:47:09 -0600140 if (gpio_request_by_name_nodev(offset_to_ofnode(node), "gpios", 0,
141 &resin, 0)) {
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +0200142 printf("Failed to request key_vol_down button.\n");
143 return 0;
144 }
145
146 if (dm_gpio_get_value(&resin)) {
Simon Glass6a38e412017-08-03 12:22:09 -0600147 env_set("bootdelay", "-1");
Ramon Frieddbc94102018-09-21 13:35:55 +0300148 env_set("bootcmd", "fastboot 0");
149 printf("key_vol_down pressed - Starting fastboot.\n");
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +0200150 }
151
152 return 0;
153}
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +0100154
155int board_init(void)
156{
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +0100157 return 0;
158}
159
Ramon Fried63596f02018-09-21 13:35:46 +0300160int board_late_init(void)
161{
162 char serial[16];
163
164 memset(serial, 0, 16);
165 snprintf(serial, 13, "%x", msm_board_serial());
166 env_set("serial#", serial);
167 return 0;
168}
169
Ramon Friede82a31c2018-08-03 16:25:37 +0300170/* Fixup of DTB for Linux Kernel
171 * 1. Fixup installed DRAM.
172 * 2. Fixup WLAN/BT Mac address:
173 * First, check if MAC addresses for WLAN/BT exists as environemnt
174 * variables wlanaddr,btaddr. if not, generate a unique address.
175 */
176
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900177int ft_board_setup(void *blob, struct bd_info *bd)
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +0100178{
Ramon Friede82a31c2018-08-03 16:25:37 +0300179 u8 mac[ARP_HLEN];
180
181 msm_fixup_memory(blob);
182
183 if (!eth_env_get_enetaddr("wlanaddr", mac)) {
184 msm_generate_mac_addr(mac);
Jorge Ramirez-Ortizf44f3012018-01-10 11:34:38 +0100185 };
186
Ramon Friede82a31c2018-08-03 16:25:37 +0300187 do_fixup_by_compat(blob, "qcom,wcnss-wlan",
188 "local-mac-address", mac, ARP_HLEN, 1);
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +0100189
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +0100190
Ramon Friede82a31c2018-08-03 16:25:37 +0300191 if (!eth_env_get_enetaddr("btaddr", mac)) {
192 msm_generate_mac_addr(mac);
193
194/* The BD address is same as WLAN MAC address but with
195 * least significant bit flipped.
196 */
197 mac[0] ^= 0x01;
198 };
Ramon Fried806549682018-07-31 12:29:58 +0300199
Ramon Friede82a31c2018-08-03 16:25:37 +0300200 do_fixup_by_compat(blob, "qcom,wcnss-bt",
201 "local-bd-address", mac, ARP_HLEN, 1);
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +0100202 return 0;
203}
Jorge Ramirez-Ortiz4154c9e2018-01-10 11:34:36 +0100204
205void reset_cpu(ulong addr)
206{
207 psci_system_reset();
208}