blob: 350e0e9e20aad4e8098ed609e6da363ddec6e3d6 [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>
Simon Glass5e6201b2019-08-01 09:46:51 -060012#include <env.h>
Simon Glassa7b51302019-11-14 12:57:46 -070013#include <init.h>
Simon Glass274e0b02020-05-10 11:39:56 -060014#include <net.h>
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020015#include <usb.h>
Simon Glass274e0b02020-05-10 11:39:56 -060016#include <asm/cache.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060017#include <asm/global_data.h>
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020018#include <asm/gpio.h>
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +010019#include <fdt_support.h>
Ramon Fried806549682018-07-31 12:29:58 +030020#include <asm/arch/dram.h>
Ramon Friede82a31c2018-08-03 16:25:37 +030021#include <asm/arch/misc.h>
Simon Glassdbd79542020-05-10 11:40:11 -060022#include <linux/delay.h>
Mateusz Kulikowskiee5e70d2016-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-Ortizf44f3012018-01-10 11:34:38 +010029
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020030 return 0;
31}
32
Simon Glass2f949c32017-03-31 08:40:32 -060033int dram_init_banksize(void)
Mateusz Kulikowskiee5e70d2016-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 Glass2f949c32017-03-31 08:40:32 -060037
38 return 0;
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020039}
40
Ramon Friedbc866cc82018-09-21 13:35:43 +030041int board_usb_init(int index, enum usb_init_type init)
Mateusz Kulikowskiee5e70d2016-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 Glassdd79d6e2017-01-17 16:52:55 -070059 node = fdt_subnode_offset(gd->fdt_blob,
60 dev_of_offset(pmic_gpio),
Mateusz Kulikowskiee5e70d2016-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 Glass1d9af1f2017-05-30 21:47:09 -060066 ret = gpio_request_by_name_nodev(offset_to_ofnode(node),
67 "gpios", 0, &hub_reset, 0);
Mateusz Kulikowskiee5e70d2016-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 Glassdd79d6e2017-01-17 16:52:55 -070075 node = fdt_subnode_offset(gd->fdt_blob,
76 dev_of_offset(pmic_gpio),
Mateusz Kulikowskiee5e70d2016-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 Glass1d9af1f2017-05-30 21:47:09 -060082 ret = gpio_request_by_name_nodev(offset_to_ofnode(node),
83 "gpios", 0, &usb_sel, 0);
Mateusz Kulikowskiee5e70d2016-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 Friedbc866cc82018-09-21 13:35:43 +030090 if (init == USB_INIT_HOST) {
Mateusz Kulikowskiee5e70d2016-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 Kulikowskiee5e70d2016-03-31 23:12:33 +0200109/* Check for vol- button - if pressed - stop autoboot */
110int misc_init_r(void)
111{
Caleb Connolly89a90d02023-12-05 13:46:48 +0000112 struct udevice *btn;
113 int ret;
114 enum button_state_t state;
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +0200115
Caleb Connolly89a90d02023-12-05 13:46:48 +0000116 ret = button_get_by_label("vol_down", &btn);
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +0200117 if (ret < 0) {
Caleb Connolly89a90d02023-12-05 13:46:48 +0000118 printf("Couldn't find power button!\n");
119 return ret;
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +0200120 }
121
Caleb Connolly89a90d02023-12-05 13:46:48 +0000122 state = button_get_state(btn);
123 if (state == BUTTON_ON) {
Stephan Gerholda0d3b952021-07-14 10:56:25 +0200124 env_set("preboot", "setenv preboot; fastboot 0");
Caleb Connolly89a90d02023-12-05 13:46:48 +0000125 printf("vol_down pressed - Starting fastboot.\n");
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +0200126 }
127
128 return 0;
129}
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +0100130
131int board_init(void)
132{
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +0100133 return 0;
134}
135
Ramon Fried63596f02018-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 Friede82a31c2018-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 Yamadaf7ed78b2020-06-26 15:13:33 +0900153int ft_board_setup(void *blob, struct bd_info *bd)
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +0100154{
Ramon Friede82a31c2018-08-03 16:25:37 +0300155 u8 mac[ARP_HLEN];
156
157 msm_fixup_memory(blob);
158
159 if (!eth_env_get_enetaddr("wlanaddr", mac)) {
160 msm_generate_mac_addr(mac);
Jorge Ramirez-Ortizf44f3012018-01-10 11:34:38 +0100161 };
162
Ramon Friede82a31c2018-08-03 16:25:37 +0300163 do_fixup_by_compat(blob, "qcom,wcnss-wlan",
164 "local-mac-address", mac, ARP_HLEN, 1);
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +0100165
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +0100166
Ramon Friede82a31c2018-08-03 16:25:37 +0300167 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 };
Ramon Fried806549682018-07-31 12:29:58 +0300175
Ramon Friede82a31c2018-08-03 16:25:37 +0300176 do_fixup_by_compat(blob, "qcom,wcnss-bt",
177 "local-bd-address", mac, ARP_HLEN, 1);
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +0100178 return 0;
179}
Jorge Ramirez-Ortiz4154c9e2018-01-10 11:34:36 +0100180
Harald Seiler6f14d5f2020-12-15 16:47:52 +0100181void reset_cpu(void)
Jorge Ramirez-Ortiz4154c9e2018-01-10 11:34:36 +0100182{
183 psci_system_reset();
184}