blob: 81bd8bd95b13a87722e74ce367b7f70318830c58 [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>
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020013#include <usb.h>
14#include <asm/gpio.h>
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +010015#include <fdt_support.h>
Ramon Fried806549682018-07-31 12:29:58 +030016#include <asm/arch/dram.h>
Ramon Friede82a31c2018-08-03 16:25:37 +030017#include <asm/arch/misc.h>
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020018
19DECLARE_GLOBAL_DATA_PTR;
20
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +010021/* pointer to the device tree ammended by the firmware */
Jorge Ramirez-Ortizf44f3012018-01-10 11:34:38 +010022extern void *fw_dtb;
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +010023
Jorge Ramirez-Ortizf44f3012018-01-10 11:34:38 +010024void *board_fdt_blob_setup(void)
25{
26 if (fdt_magic(fw_dtb) != FDT_MAGIC) {
27 printf("Firmware provided invalid dtb!\n");
28 return NULL;
29 }
30
31 return fw_dtb;
32}
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +010033
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020034int dram_init(void)
35{
36 gd->ram_size = PHYS_SDRAM_1_SIZE;
Jorge Ramirez-Ortizf44f3012018-01-10 11:34:38 +010037
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020038 return 0;
39}
40
Simon Glass2f949c32017-03-31 08:40:32 -060041int dram_init_banksize(void)
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020042{
43 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
44 gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
Simon Glass2f949c32017-03-31 08:40:32 -060045
46 return 0;
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020047}
48
Ramon Friedbc866cc82018-09-21 13:35:43 +030049int board_usb_init(int index, enum usb_init_type init)
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020050{
51 static struct udevice *pmic_gpio;
52 static struct gpio_desc hub_reset, usb_sel;
53 int ret = 0, node;
54
55 if (!pmic_gpio) {
56 ret = uclass_get_device_by_name(UCLASS_GPIO,
57 "pm8916_gpios@c000",
58 &pmic_gpio);
59 if (ret < 0) {
60 printf("Failed to find pm8916_gpios@c000 node.\n");
61 return ret;
62 }
63 }
64
65 /* Try to request gpios needed to start usb host on dragonboard */
66 if (!dm_gpio_is_valid(&hub_reset)) {
Simon Glassdd79d6e2017-01-17 16:52:55 -070067 node = fdt_subnode_offset(gd->fdt_blob,
68 dev_of_offset(pmic_gpio),
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020069 "usb_hub_reset_pm");
70 if (node < 0) {
71 printf("Failed to find usb_hub_reset_pm dt node.\n");
72 return node;
73 }
Simon Glass1d9af1f2017-05-30 21:47:09 -060074 ret = gpio_request_by_name_nodev(offset_to_ofnode(node),
75 "gpios", 0, &hub_reset, 0);
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020076 if (ret < 0) {
77 printf("Failed to request usb_hub_reset_pm gpio.\n");
78 return ret;
79 }
80 }
81
82 if (!dm_gpio_is_valid(&usb_sel)) {
Simon Glassdd79d6e2017-01-17 16:52:55 -070083 node = fdt_subnode_offset(gd->fdt_blob,
84 dev_of_offset(pmic_gpio),
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020085 "usb_sw_sel_pm");
86 if (node < 0) {
87 printf("Failed to find usb_sw_sel_pm dt node.\n");
88 return 0;
89 }
Simon Glass1d9af1f2017-05-30 21:47:09 -060090 ret = gpio_request_by_name_nodev(offset_to_ofnode(node),
91 "gpios", 0, &usb_sel, 0);
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020092 if (ret < 0) {
93 printf("Failed to request usb_sw_sel_pm gpio.\n");
94 return ret;
95 }
96 }
97
Ramon Friedbc866cc82018-09-21 13:35:43 +030098 if (init == USB_INIT_HOST) {
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020099 /* Start USB Hub */
100 dm_gpio_set_dir_flags(&hub_reset,
101 GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE);
102 mdelay(100);
103 /* Switch usb to host connectors */
104 dm_gpio_set_dir_flags(&usb_sel,
105 GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE);
106 mdelay(100);
107 } else { /* Device */
108 /* Disable hub */
109 dm_gpio_set_dir_flags(&hub_reset, GPIOD_IS_OUT);
110 /* Switch back to device connector */
111 dm_gpio_set_dir_flags(&usb_sel, GPIOD_IS_OUT);
112 }
113
114 return 0;
115}
116
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +0200117/* Check for vol- button - if pressed - stop autoboot */
118int misc_init_r(void)
119{
120 struct udevice *pon;
121 struct gpio_desc resin;
122 int node, ret;
123
124 ret = uclass_get_device_by_name(UCLASS_GPIO, "pm8916_pon@800", &pon);
125 if (ret < 0) {
126 printf("Failed to find PMIC pon node. Check device tree\n");
127 return 0;
128 }
129
Simon Glassdd79d6e2017-01-17 16:52:55 -0700130 node = fdt_subnode_offset(gd->fdt_blob, dev_of_offset(pon),
131 "key_vol_down");
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +0200132 if (node < 0) {
133 printf("Failed to find key_vol_down node. Check device tree\n");
134 return 0;
135 }
136
Simon Glass1d9af1f2017-05-30 21:47:09 -0600137 if (gpio_request_by_name_nodev(offset_to_ofnode(node), "gpios", 0,
138 &resin, 0)) {
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +0200139 printf("Failed to request key_vol_down button.\n");
140 return 0;
141 }
142
143 if (dm_gpio_get_value(&resin)) {
Simon Glass6a38e412017-08-03 12:22:09 -0600144 env_set("bootdelay", "-1");
Ramon Frieddbc94102018-09-21 13:35:55 +0300145 env_set("bootcmd", "fastboot 0");
146 printf("key_vol_down pressed - Starting fastboot.\n");
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +0200147 }
148
149 return 0;
150}
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +0100151
152int board_init(void)
153{
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +0100154 return 0;
155}
156
Ramon Fried63596f02018-09-21 13:35:46 +0300157int board_late_init(void)
158{
159 char serial[16];
160
161 memset(serial, 0, 16);
162 snprintf(serial, 13, "%x", msm_board_serial());
163 env_set("serial#", serial);
164 return 0;
165}
166
Ramon Friede82a31c2018-08-03 16:25:37 +0300167/* Fixup of DTB for Linux Kernel
168 * 1. Fixup installed DRAM.
169 * 2. Fixup WLAN/BT Mac address:
170 * First, check if MAC addresses for WLAN/BT exists as environemnt
171 * variables wlanaddr,btaddr. if not, generate a unique address.
172 */
173
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +0100174int ft_board_setup(void *blob, bd_t *bd)
175{
Ramon Friede82a31c2018-08-03 16:25:37 +0300176 u8 mac[ARP_HLEN];
177
178 msm_fixup_memory(blob);
179
180 if (!eth_env_get_enetaddr("wlanaddr", mac)) {
181 msm_generate_mac_addr(mac);
Jorge Ramirez-Ortizf44f3012018-01-10 11:34:38 +0100182 };
183
Ramon Friede82a31c2018-08-03 16:25:37 +0300184 do_fixup_by_compat(blob, "qcom,wcnss-wlan",
185 "local-mac-address", mac, ARP_HLEN, 1);
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +0100186
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +0100187
Ramon Friede82a31c2018-08-03 16:25:37 +0300188 if (!eth_env_get_enetaddr("btaddr", mac)) {
189 msm_generate_mac_addr(mac);
190
191/* The BD address is same as WLAN MAC address but with
192 * least significant bit flipped.
193 */
194 mac[0] ^= 0x01;
195 };
Ramon Fried806549682018-07-31 12:29:58 +0300196
Ramon Friede82a31c2018-08-03 16:25:37 +0300197 do_fixup_by_compat(blob, "qcom,wcnss-bt",
198 "local-bd-address", mac, ARP_HLEN, 1);
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +0100199 return 0;
200}
Jorge Ramirez-Ortiz4154c9e2018-01-10 11:34:36 +0100201
202void reset_cpu(ulong addr)
203{
204 psci_system_reset();
205}