blob: 350e0e9e20aad4e8098ed609e6da363ddec6e3d6 [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>
Ramon Fried9beb4902018-07-31 12:29:58 +030020#include <asm/arch/dram.h>
Ramon Friedff06dc22018-08-03 16:25:37 +030021#include <asm/arch/misc.h>
Simon Glassc05ed002020-05-10 11:40:11 -060022#include <linux/delay.h>
Mateusz Kulikowski626f0482016-03-31 23:12:33 +020023
24DECLARE_GLOBAL_DATA_PTR;
25
26int dram_init(void)
27{
28 gd->ram_size = PHYS_SDRAM_1_SIZE;
Jorge Ramirez-Ortiz9337dfb2018-01-10 11:34:38 +010029
Mateusz Kulikowski626f0482016-03-31 23:12:33 +020030 return 0;
31}
32
Simon Glass76b00ac2017-03-31 08:40:32 -060033int dram_init_banksize(void)
Mateusz Kulikowski626f0482016-03-31 23:12:33 +020034{
35 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
36 gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
Simon Glass76b00ac2017-03-31 08:40:32 -060037
38 return 0;
Mateusz Kulikowski626f0482016-03-31 23:12:33 +020039}
40
Ramon Friedcd8c3ae2018-09-21 13:35:43 +030041int board_usb_init(int index, enum usb_init_type init)
Mateusz Kulikowski626f0482016-03-31 23:12:33 +020042{
43 static struct udevice *pmic_gpio;
44 static struct gpio_desc hub_reset, usb_sel;
45 int ret = 0, node;
46
47 if (!pmic_gpio) {
48 ret = uclass_get_device_by_name(UCLASS_GPIO,
49 "pm8916_gpios@c000",
50 &pmic_gpio);
51 if (ret < 0) {
52 printf("Failed to find pm8916_gpios@c000 node.\n");
53 return ret;
54 }
55 }
56
57 /* Try to request gpios needed to start usb host on dragonboard */
58 if (!dm_gpio_is_valid(&hub_reset)) {
Simon Glasse160f7d2017-01-17 16:52:55 -070059 node = fdt_subnode_offset(gd->fdt_blob,
60 dev_of_offset(pmic_gpio),
Mateusz Kulikowski626f0482016-03-31 23:12:33 +020061 "usb_hub_reset_pm");
62 if (node < 0) {
63 printf("Failed to find usb_hub_reset_pm dt node.\n");
64 return node;
65 }
Simon Glass150c5af2017-05-30 21:47:09 -060066 ret = gpio_request_by_name_nodev(offset_to_ofnode(node),
67 "gpios", 0, &hub_reset, 0);
Mateusz Kulikowski626f0482016-03-31 23:12:33 +020068 if (ret < 0) {
69 printf("Failed to request usb_hub_reset_pm gpio.\n");
70 return ret;
71 }
72 }
73
74 if (!dm_gpio_is_valid(&usb_sel)) {
Simon Glasse160f7d2017-01-17 16:52:55 -070075 node = fdt_subnode_offset(gd->fdt_blob,
76 dev_of_offset(pmic_gpio),
Mateusz Kulikowski626f0482016-03-31 23:12:33 +020077 "usb_sw_sel_pm");
78 if (node < 0) {
79 printf("Failed to find usb_sw_sel_pm dt node.\n");
80 return 0;
81 }
Simon Glass150c5af2017-05-30 21:47:09 -060082 ret = gpio_request_by_name_nodev(offset_to_ofnode(node),
83 "gpios", 0, &usb_sel, 0);
Mateusz Kulikowski626f0482016-03-31 23:12:33 +020084 if (ret < 0) {
85 printf("Failed to request usb_sw_sel_pm gpio.\n");
86 return ret;
87 }
88 }
89
Ramon Friedcd8c3ae2018-09-21 13:35:43 +030090 if (init == USB_INIT_HOST) {
Mateusz Kulikowski626f0482016-03-31 23:12:33 +020091 /* Start USB Hub */
92 dm_gpio_set_dir_flags(&hub_reset,
93 GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE);
94 mdelay(100);
95 /* Switch usb to host connectors */
96 dm_gpio_set_dir_flags(&usb_sel,
97 GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE);
98 mdelay(100);
99 } else { /* Device */
100 /* Disable hub */
101 dm_gpio_set_dir_flags(&hub_reset, GPIOD_IS_OUT);
102 /* Switch back to device connector */
103 dm_gpio_set_dir_flags(&usb_sel, GPIOD_IS_OUT);
104 }
105
106 return 0;
107}
108
Mateusz Kulikowski626f0482016-03-31 23:12:33 +0200109/* Check for vol- button - if pressed - stop autoboot */
110int misc_init_r(void)
111{
Caleb Connolly5df679a2023-11-30 16:13:50 +0000112 struct udevice *btn;
113 int ret;
114 enum button_state_t state;
Mateusz Kulikowski626f0482016-03-31 23:12:33 +0200115
Caleb Connolly5df679a2023-11-30 16:13:50 +0000116 ret = button_get_by_label("vol_down", &btn);
Mateusz Kulikowski626f0482016-03-31 23:12:33 +0200117 if (ret < 0) {
Caleb Connolly5df679a2023-11-30 16:13:50 +0000118 printf("Couldn't find power button!\n");
119 return ret;
Mateusz Kulikowski626f0482016-03-31 23:12:33 +0200120 }
121
Caleb Connolly5df679a2023-11-30 16:13:50 +0000122 state = button_get_state(btn);
123 if (state == BUTTON_ON) {
Stephan Gerholdccb8de22021-07-14 10:56:25 +0200124 env_set("preboot", "setenv preboot; fastboot 0");
Caleb Connolly5df679a2023-11-30 16:13:50 +0000125 printf("vol_down pressed - Starting fastboot.\n");
Mateusz Kulikowski626f0482016-03-31 23:12:33 +0200126 }
127
128 return 0;
129}
Jorge Ramirez-Ortize2beb872018-01-10 11:34:35 +0100130
131int board_init(void)
132{
Jorge Ramirez-Ortize2beb872018-01-10 11:34:35 +0100133 return 0;
134}
135
Ramon Fried2df573e2018-09-21 13:35:46 +0300136int board_late_init(void)
137{
138 char serial[16];
139
140 memset(serial, 0, 16);
141 snprintf(serial, 13, "%x", msm_board_serial());
142 env_set("serial#", serial);
143 return 0;
144}
145
Ramon Friedff06dc22018-08-03 16:25:37 +0300146/* Fixup of DTB for Linux Kernel
147 * 1. Fixup installed DRAM.
148 * 2. Fixup WLAN/BT Mac address:
149 * First, check if MAC addresses for WLAN/BT exists as environemnt
150 * variables wlanaddr,btaddr. if not, generate a unique address.
151 */
152
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +0900153int ft_board_setup(void *blob, struct bd_info *bd)
Jorge Ramirez-Ortize2beb872018-01-10 11:34:35 +0100154{
Ramon Friedff06dc22018-08-03 16:25:37 +0300155 u8 mac[ARP_HLEN];
Jorge Ramirez-Ortize2beb872018-01-10 11:34:35 +0100156
Ramon Fried9beb4902018-07-31 12:29:58 +0300157 msm_fixup_memory(blob);
158
Ramon Friedff06dc22018-08-03 16:25:37 +0300159 if (!eth_env_get_enetaddr("wlanaddr", mac)) {
160 msm_generate_mac_addr(mac);
161 };
162
163 do_fixup_by_compat(blob, "qcom,wcnss-wlan",
164 "local-mac-address", mac, ARP_HLEN, 1);
165
166
167 if (!eth_env_get_enetaddr("btaddr", mac)) {
168 msm_generate_mac_addr(mac);
169
170/* The BD address is same as WLAN MAC address but with
171 * least significant bit flipped.
172 */
173 mac[0] ^= 0x01;
174 };
175
176 do_fixup_by_compat(blob, "qcom,wcnss-bt",
177 "local-bd-address", mac, ARP_HLEN, 1);
Jorge Ramirez-Ortize2beb872018-01-10 11:34:35 +0100178 return 0;
179}
Jorge Ramirez-Ortiz0689eb72018-01-10 11:34:36 +0100180
Harald Seiler35b65dd2020-12-15 16:47:52 +0100181void reset_cpu(void)
Jorge Ramirez-Ortiz0689eb72018-01-10 11:34:36 +0100182{
183 psci_system_reset();
184}