blob: 1adac07569ae9aa7ee187bfd5fafd1bf367d4546 [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
Caleb Connolly89a90d02023-12-05 13:46:48 +00008#include <button.h>
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +02009#include <common.h>
Simon Glassafb02152019-12-28 10:45:01 -070010#include <cpu_func.h>
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020011#include <dm.h>
Caleb Connolly154ed1d2024-02-26 17:26:21 +000012#include <dm/pinctrl.h>
Simon Glass5e6201b2019-08-01 09:46:51 -060013#include <env.h>
Simon Glassa7b51302019-11-14 12:57:46 -070014#include <init.h>
Simon Glass274e0b02020-05-10 11:39:56 -060015#include <net.h>
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020016#include <usb.h>
Simon Glass274e0b02020-05-10 11:39:56 -060017#include <asm/cache.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060018#include <asm/global_data.h>
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020019#include <asm/gpio.h>
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +010020#include <fdt_support.h>
Ramon Fried806549682018-07-31 12:29:58 +030021#include <asm/arch/dram.h>
Ramon Friede82a31c2018-08-03 16:25:37 +030022#include <asm/arch/misc.h>
Simon Glassdbd79542020-05-10 11:40:11 -060023#include <linux/delay.h>
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020024
25DECLARE_GLOBAL_DATA_PTR;
26
Caleb Connolly154ed1d2024-02-26 17:26:21 +000027#define USB_HUB_RESET_GPIO 2
28#define USB_SW_SELECT_GPIO 3
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020029
Ramon Friedbc866cc82018-09-21 13:35:43 +030030int board_usb_init(int index, enum usb_init_type init)
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020031{
Caleb Connolly154ed1d2024-02-26 17:26:21 +000032 struct udevice *usb;
33 int ret = 0;
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020034
Caleb Connolly154ed1d2024-02-26 17:26:21 +000035 /* USB device */
36 ret = device_find_global_by_ofnode(ofnode_path("/soc/usb"), &usb);
37 if (ret) {
38 printf("Cannot find USB device\n");
39 return ret;
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020040 }
41
Caleb Connolly154ed1d2024-02-26 17:26:21 +000042 /* Select "default" or "device" pinctrl */
43 switch (init) {
44 case USB_INIT_HOST:
45 pinctrl_select_state(usb, "default");
46 break;
47 case USB_INIT_DEVICE:
48 pinctrl_select_state(usb, "device");
49 break;
50 default:
51 debug("Unknown usb_init_type %d\n", init);
52 break;
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020053 }
54
55 return 0;
56}
57
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020058/* Check for vol- button - if pressed - stop autoboot */
59int misc_init_r(void)
60{
Caleb Connolly89a90d02023-12-05 13:46:48 +000061 struct udevice *btn;
62 int ret;
63 enum button_state_t state;
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020064
Caleb Connolly89a90d02023-12-05 13:46:48 +000065 ret = button_get_by_label("vol_down", &btn);
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020066 if (ret < 0) {
Caleb Connolly89a90d02023-12-05 13:46:48 +000067 printf("Couldn't find power button!\n");
68 return ret;
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020069 }
70
Caleb Connolly89a90d02023-12-05 13:46:48 +000071 state = button_get_state(btn);
72 if (state == BUTTON_ON) {
Stephan Gerholda0d3b952021-07-14 10:56:25 +020073 env_set("preboot", "setenv preboot; fastboot 0");
Caleb Connolly89a90d02023-12-05 13:46:48 +000074 printf("vol_down pressed - Starting fastboot.\n");
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020075 }
76
77 return 0;
78}
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +010079
80int board_init(void)
81{
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +010082 return 0;
83}
84
Ramon Fried63596f02018-09-21 13:35:46 +030085int board_late_init(void)
86{
87 char serial[16];
88
89 memset(serial, 0, 16);
90 snprintf(serial, 13, "%x", msm_board_serial());
91 env_set("serial#", serial);
92 return 0;
93}
94
Ramon Friede82a31c2018-08-03 16:25:37 +030095/* Fixup of DTB for Linux Kernel
96 * 1. Fixup installed DRAM.
97 * 2. Fixup WLAN/BT Mac address:
98 * First, check if MAC addresses for WLAN/BT exists as environemnt
99 * variables wlanaddr,btaddr. if not, generate a unique address.
100 */
101
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900102int ft_board_setup(void *blob, struct bd_info *bd)
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +0100103{
Ramon Friede82a31c2018-08-03 16:25:37 +0300104 u8 mac[ARP_HLEN];
105
106 msm_fixup_memory(blob);
107
108 if (!eth_env_get_enetaddr("wlanaddr", mac)) {
109 msm_generate_mac_addr(mac);
Jorge Ramirez-Ortizf44f3012018-01-10 11:34:38 +0100110 };
111
Ramon Friede82a31c2018-08-03 16:25:37 +0300112 do_fixup_by_compat(blob, "qcom,wcnss-wlan",
113 "local-mac-address", mac, ARP_HLEN, 1);
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +0100114
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +0100115
Ramon Friede82a31c2018-08-03 16:25:37 +0300116 if (!eth_env_get_enetaddr("btaddr", mac)) {
117 msm_generate_mac_addr(mac);
118
119/* The BD address is same as WLAN MAC address but with
120 * least significant bit flipped.
121 */
122 mac[0] ^= 0x01;
123 };
Ramon Fried806549682018-07-31 12:29:58 +0300124
Ramon Friede82a31c2018-08-03 16:25:37 +0300125 do_fixup_by_compat(blob, "qcom,wcnss-bt",
126 "local-bd-address", mac, ARP_HLEN, 1);
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +0100127 return 0;
128}
Jorge Ramirez-Ortiz4154c9e2018-01-10 11:34:36 +0100129
Harald Seiler6f14d5f2020-12-15 16:47:52 +0100130void reset_cpu(void)
Jorge Ramirez-Ortiz4154c9e2018-01-10 11:34:36 +0100131{
132 psci_system_reset();
133}