blob: 371b3262f8c591f7732d61510838a17a2c1c2132 [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>
Simon Glass3ba929a2020-10-30 21:38:53 -060016#include <asm/global_data.h>
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020017#include <asm/gpio.h>
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +010018#include <fdt_support.h>
Ramon Fried806549682018-07-31 12:29:58 +030019#include <asm/arch/dram.h>
Ramon Friede82a31c2018-08-03 16:25:37 +030020#include <asm/arch/misc.h>
Simon Glassdbd79542020-05-10 11:40:11 -060021#include <linux/delay.h>
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020022
23DECLARE_GLOBAL_DATA_PTR;
24
25int dram_init(void)
26{
27 gd->ram_size = PHYS_SDRAM_1_SIZE;
Jorge Ramirez-Ortizf44f3012018-01-10 11:34:38 +010028
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020029 return 0;
30}
31
Simon Glass2f949c32017-03-31 08:40:32 -060032int dram_init_banksize(void)
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020033{
34 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
35 gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
Simon Glass2f949c32017-03-31 08:40:32 -060036
37 return 0;
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020038}
39
Ramon Friedbc866cc82018-09-21 13:35:43 +030040int board_usb_init(int index, enum usb_init_type init)
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020041{
42 static struct udevice *pmic_gpio;
43 static struct gpio_desc hub_reset, usb_sel;
44 int ret = 0, node;
45
46 if (!pmic_gpio) {
47 ret = uclass_get_device_by_name(UCLASS_GPIO,
48 "pm8916_gpios@c000",
49 &pmic_gpio);
50 if (ret < 0) {
51 printf("Failed to find pm8916_gpios@c000 node.\n");
52 return ret;
53 }
54 }
55
56 /* Try to request gpios needed to start usb host on dragonboard */
57 if (!dm_gpio_is_valid(&hub_reset)) {
Simon Glassdd79d6e2017-01-17 16:52:55 -070058 node = fdt_subnode_offset(gd->fdt_blob,
59 dev_of_offset(pmic_gpio),
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020060 "usb_hub_reset_pm");
61 if (node < 0) {
62 printf("Failed to find usb_hub_reset_pm dt node.\n");
63 return node;
64 }
Simon Glass1d9af1f2017-05-30 21:47:09 -060065 ret = gpio_request_by_name_nodev(offset_to_ofnode(node),
66 "gpios", 0, &hub_reset, 0);
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020067 if (ret < 0) {
68 printf("Failed to request usb_hub_reset_pm gpio.\n");
69 return ret;
70 }
71 }
72
73 if (!dm_gpio_is_valid(&usb_sel)) {
Simon Glassdd79d6e2017-01-17 16:52:55 -070074 node = fdt_subnode_offset(gd->fdt_blob,
75 dev_of_offset(pmic_gpio),
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020076 "usb_sw_sel_pm");
77 if (node < 0) {
78 printf("Failed to find usb_sw_sel_pm dt node.\n");
79 return 0;
80 }
Simon Glass1d9af1f2017-05-30 21:47:09 -060081 ret = gpio_request_by_name_nodev(offset_to_ofnode(node),
82 "gpios", 0, &usb_sel, 0);
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020083 if (ret < 0) {
84 printf("Failed to request usb_sw_sel_pm gpio.\n");
85 return ret;
86 }
87 }
88
Ramon Friedbc866cc82018-09-21 13:35:43 +030089 if (init == USB_INIT_HOST) {
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020090 /* Start USB Hub */
91 dm_gpio_set_dir_flags(&hub_reset,
92 GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE);
93 mdelay(100);
94 /* Switch usb to host connectors */
95 dm_gpio_set_dir_flags(&usb_sel,
96 GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE);
97 mdelay(100);
98 } else { /* Device */
99 /* Disable hub */
100 dm_gpio_set_dir_flags(&hub_reset, GPIOD_IS_OUT);
101 /* Switch back to device connector */
102 dm_gpio_set_dir_flags(&usb_sel, GPIOD_IS_OUT);
103 }
104
105 return 0;
106}
107
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +0200108/* Check for vol- button - if pressed - stop autoboot */
109int misc_init_r(void)
110{
111 struct udevice *pon;
112 struct gpio_desc resin;
113 int node, ret;
114
115 ret = uclass_get_device_by_name(UCLASS_GPIO, "pm8916_pon@800", &pon);
116 if (ret < 0) {
117 printf("Failed to find PMIC pon node. Check device tree\n");
118 return 0;
119 }
120
Simon Glassdd79d6e2017-01-17 16:52:55 -0700121 node = fdt_subnode_offset(gd->fdt_blob, dev_of_offset(pon),
122 "key_vol_down");
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +0200123 if (node < 0) {
124 printf("Failed to find key_vol_down node. Check device tree\n");
125 return 0;
126 }
127
Simon Glass1d9af1f2017-05-30 21:47:09 -0600128 if (gpio_request_by_name_nodev(offset_to_ofnode(node), "gpios", 0,
129 &resin, 0)) {
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +0200130 printf("Failed to request key_vol_down button.\n");
131 return 0;
132 }
133
134 if (dm_gpio_get_value(&resin)) {
Stephan Gerholda0d3b952021-07-14 10:56:25 +0200135 env_set("preboot", "setenv preboot; fastboot 0");
Ramon Frieddbc94102018-09-21 13:35:55 +0300136 printf("key_vol_down pressed - Starting fastboot.\n");
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +0200137 }
138
139 return 0;
140}
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +0100141
142int board_init(void)
143{
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +0100144 return 0;
145}
146
Ramon Fried63596f02018-09-21 13:35:46 +0300147int board_late_init(void)
148{
149 char serial[16];
150
151 memset(serial, 0, 16);
152 snprintf(serial, 13, "%x", msm_board_serial());
153 env_set("serial#", serial);
154 return 0;
155}
156
Ramon Friede82a31c2018-08-03 16:25:37 +0300157/* Fixup of DTB for Linux Kernel
158 * 1. Fixup installed DRAM.
159 * 2. Fixup WLAN/BT Mac address:
160 * First, check if MAC addresses for WLAN/BT exists as environemnt
161 * variables wlanaddr,btaddr. if not, generate a unique address.
162 */
163
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900164int ft_board_setup(void *blob, struct bd_info *bd)
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +0100165{
Ramon Friede82a31c2018-08-03 16:25:37 +0300166 u8 mac[ARP_HLEN];
167
168 msm_fixup_memory(blob);
169
170 if (!eth_env_get_enetaddr("wlanaddr", mac)) {
171 msm_generate_mac_addr(mac);
Jorge Ramirez-Ortizf44f3012018-01-10 11:34:38 +0100172 };
173
Ramon Friede82a31c2018-08-03 16:25:37 +0300174 do_fixup_by_compat(blob, "qcom,wcnss-wlan",
175 "local-mac-address", mac, ARP_HLEN, 1);
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +0100176
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +0100177
Ramon Friede82a31c2018-08-03 16:25:37 +0300178 if (!eth_env_get_enetaddr("btaddr", mac)) {
179 msm_generate_mac_addr(mac);
180
181/* The BD address is same as WLAN MAC address but with
182 * least significant bit flipped.
183 */
184 mac[0] ^= 0x01;
185 };
Ramon Fried806549682018-07-31 12:29:58 +0300186
Ramon Friede82a31c2018-08-03 16:25:37 +0300187 do_fixup_by_compat(blob, "qcom,wcnss-bt",
188 "local-bd-address", mac, ARP_HLEN, 1);
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +0100189 return 0;
190}
Jorge Ramirez-Ortiz4154c9e2018-01-10 11:34:36 +0100191
Harald Seiler6f14d5f2020-12-15 16:47:52 +0100192void reset_cpu(void)
Jorge Ramirez-Ortiz4154c9e2018-01-10 11:34:36 +0100193{
194 psci_system_reset();
195}