blob: 3209c5ce5dd5b7312bd0f2d924312eded143c62b [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
Caleb Connolly5df679a2023-11-30 16:13:50 +00008#include <button.h>
Mateusz Kulikowski626f0482016-03-31 23:12:33 +02009#include <common.h>
Simon Glass9a3b4ce2019-12-28 10:45:01 -070010#include <cpu_func.h>
Mateusz Kulikowski626f0482016-03-31 23:12:33 +020011#include <dm.h>
Simon Glass9fb625c2019-08-01 09:46:51 -060012#include <env.h>
Simon Glass52559322019-11-14 12:57:46 -070013#include <init.h>
Simon Glass90526e92020-05-10 11:39:56 -060014#include <net.h>
Mateusz Kulikowski626f0482016-03-31 23:12:33 +020015#include <usb.h>
Simon Glass90526e92020-05-10 11:39:56 -060016#include <asm/cache.h>
Simon Glass401d1c42020-10-30 21:38:53 -060017#include <asm/global_data.h>
Mateusz Kulikowski626f0482016-03-31 23:12:33 +020018#include <asm/gpio.h>
Jorge Ramirez-Ortize2beb872018-01-10 11:34:35 +010019#include <fdt_support.h>
Simon Glassc05ed002020-05-10 11:40:11 -060020#include <linux/delay.h>
Mateusz Kulikowski626f0482016-03-31 23:12:33 +020021
Caleb Connolly3de41f92023-11-07 14:58:23 +000022#include "misc.h"
23
Mateusz Kulikowski626f0482016-03-31 23:12:33 +020024DECLARE_GLOBAL_DATA_PTR;
25
Ramon Friedcd8c3ae2018-09-21 13:35:43 +030026int board_usb_init(int index, enum usb_init_type init)
Mateusz Kulikowski626f0482016-03-31 23:12:33 +020027{
28 static struct udevice *pmic_gpio;
29 static struct gpio_desc hub_reset, usb_sel;
30 int ret = 0, node;
31
32 if (!pmic_gpio) {
33 ret = uclass_get_device_by_name(UCLASS_GPIO,
Caleb Connolly1ccfdb52023-11-14 19:41:44 +000034 "gpio@c000",
Mateusz Kulikowski626f0482016-03-31 23:12:33 +020035 &pmic_gpio);
36 if (ret < 0) {
Caleb Connolly1ccfdb52023-11-14 19:41:44 +000037 printf("Failed to find gpio@c000 node.\n");
Mateusz Kulikowski626f0482016-03-31 23:12:33 +020038 return ret;
39 }
40 }
41
42 /* Try to request gpios needed to start usb host on dragonboard */
43 if (!dm_gpio_is_valid(&hub_reset)) {
Simon Glasse160f7d2017-01-17 16:52:55 -070044 node = fdt_subnode_offset(gd->fdt_blob,
45 dev_of_offset(pmic_gpio),
Mateusz Kulikowski626f0482016-03-31 23:12:33 +020046 "usb_hub_reset_pm");
47 if (node < 0) {
48 printf("Failed to find usb_hub_reset_pm dt node.\n");
49 return node;
50 }
Simon Glass150c5af2017-05-30 21:47:09 -060051 ret = gpio_request_by_name_nodev(offset_to_ofnode(node),
52 "gpios", 0, &hub_reset, 0);
Mateusz Kulikowski626f0482016-03-31 23:12:33 +020053 if (ret < 0) {
54 printf("Failed to request usb_hub_reset_pm gpio.\n");
55 return ret;
56 }
57 }
58
59 if (!dm_gpio_is_valid(&usb_sel)) {
Simon Glasse160f7d2017-01-17 16:52:55 -070060 node = fdt_subnode_offset(gd->fdt_blob,
61 dev_of_offset(pmic_gpio),
Mateusz Kulikowski626f0482016-03-31 23:12:33 +020062 "usb_sw_sel_pm");
63 if (node < 0) {
64 printf("Failed to find usb_sw_sel_pm dt node.\n");
65 return 0;
66 }
Simon Glass150c5af2017-05-30 21:47:09 -060067 ret = gpio_request_by_name_nodev(offset_to_ofnode(node),
68 "gpios", 0, &usb_sel, 0);
Mateusz Kulikowski626f0482016-03-31 23:12:33 +020069 if (ret < 0) {
70 printf("Failed to request usb_sw_sel_pm gpio.\n");
71 return ret;
72 }
73 }
74
Ramon Friedcd8c3ae2018-09-21 13:35:43 +030075 if (init == USB_INIT_HOST) {
Mateusz Kulikowski626f0482016-03-31 23:12:33 +020076 /* Start USB Hub */
77 dm_gpio_set_dir_flags(&hub_reset,
78 GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE);
79 mdelay(100);
80 /* Switch usb to host connectors */
81 dm_gpio_set_dir_flags(&usb_sel,
82 GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE);
83 mdelay(100);
84 } else { /* Device */
85 /* Disable hub */
86 dm_gpio_set_dir_flags(&hub_reset, GPIOD_IS_OUT);
87 /* Switch back to device connector */
88 dm_gpio_set_dir_flags(&usb_sel, GPIOD_IS_OUT);
89 }
90
91 return 0;
92}
93
Mateusz Kulikowski626f0482016-03-31 23:12:33 +020094/* Check for vol- button - if pressed - stop autoboot */
95int misc_init_r(void)
96{
Caleb Connolly5df679a2023-11-30 16:13:50 +000097 struct udevice *btn;
98 int ret;
99 enum button_state_t state;
Mateusz Kulikowski626f0482016-03-31 23:12:33 +0200100
Caleb Connolly5df679a2023-11-30 16:13:50 +0000101 ret = button_get_by_label("vol_down", &btn);
Mateusz Kulikowski626f0482016-03-31 23:12:33 +0200102 if (ret < 0) {
Caleb Connolly5df679a2023-11-30 16:13:50 +0000103 printf("Couldn't find power button!\n");
104 return ret;
Mateusz Kulikowski626f0482016-03-31 23:12:33 +0200105 }
106
Caleb Connolly5df679a2023-11-30 16:13:50 +0000107 state = button_get_state(btn);
108 if (state == BUTTON_ON) {
Stephan Gerholdccb8de22021-07-14 10:56:25 +0200109 env_set("preboot", "setenv preboot; fastboot 0");
Caleb Connolly5df679a2023-11-30 16:13:50 +0000110 printf("vol_down pressed - Starting fastboot.\n");
Mateusz Kulikowski626f0482016-03-31 23:12:33 +0200111 }
112
113 return 0;
114}
Jorge Ramirez-Ortize2beb872018-01-10 11:34:35 +0100115
Caleb Connolly16da8c72023-10-03 11:35:40 +0100116int qcom_late_init(void)
Ramon Fried2df573e2018-09-21 13:35:46 +0300117{
118 char serial[16];
119
120 memset(serial, 0, 16);
121 snprintf(serial, 13, "%x", msm_board_serial());
122 env_set("serial#", serial);
123 return 0;
124}
125
Ramon Friedff06dc22018-08-03 16:25:37 +0300126/* Fixup of DTB for Linux Kernel
127 * 1. Fixup installed DRAM.
128 * 2. Fixup WLAN/BT Mac address:
129 * First, check if MAC addresses for WLAN/BT exists as environemnt
130 * variables wlanaddr,btaddr. if not, generate a unique address.
131 */
132
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +0900133int ft_board_setup(void *blob, struct bd_info *bd)
Jorge Ramirez-Ortize2beb872018-01-10 11:34:35 +0100134{
Ramon Friedff06dc22018-08-03 16:25:37 +0300135 u8 mac[ARP_HLEN];
Jorge Ramirez-Ortize2beb872018-01-10 11:34:35 +0100136
Ramon Fried9beb4902018-07-31 12:29:58 +0300137 msm_fixup_memory(blob);
138
Ramon Friedff06dc22018-08-03 16:25:37 +0300139 if (!eth_env_get_enetaddr("wlanaddr", mac)) {
140 msm_generate_mac_addr(mac);
141 };
142
143 do_fixup_by_compat(blob, "qcom,wcnss-wlan",
144 "local-mac-address", mac, ARP_HLEN, 1);
145
146
147 if (!eth_env_get_enetaddr("btaddr", mac)) {
148 msm_generate_mac_addr(mac);
149
150/* The BD address is same as WLAN MAC address but with
151 * least significant bit flipped.
152 */
153 mac[0] ^= 0x01;
154 };
155
156 do_fixup_by_compat(blob, "qcom,wcnss-bt",
157 "local-bd-address", mac, ARP_HLEN, 1);
Jorge Ramirez-Ortize2beb872018-01-10 11:34:35 +0100158 return 0;
159}