blob: 75505d0c189746e309e2d073008189426fc3ce99 [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>
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020016#include <asm/gpio.h>
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +010017#include <fdt_support.h>
Ramon Fried806549682018-07-31 12:29:58 +030018#include <asm/arch/dram.h>
Ramon Friede82a31c2018-08-03 16:25:37 +030019#include <asm/arch/misc.h>
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020020
21DECLARE_GLOBAL_DATA_PTR;
22
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +010023/* pointer to the device tree ammended by the firmware */
Jorge Ramirez-Ortizf44f3012018-01-10 11:34:38 +010024extern void *fw_dtb;
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +010025
Jorge Ramirez-Ortizf44f3012018-01-10 11:34:38 +010026void *board_fdt_blob_setup(void)
27{
28 if (fdt_magic(fw_dtb) != FDT_MAGIC) {
29 printf("Firmware provided invalid dtb!\n");
30 return NULL;
31 }
32
33 return fw_dtb;
34}
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +010035
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020036int dram_init(void)
37{
38 gd->ram_size = PHYS_SDRAM_1_SIZE;
Jorge Ramirez-Ortizf44f3012018-01-10 11:34:38 +010039
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020040 return 0;
41}
42
Simon Glass2f949c32017-03-31 08:40:32 -060043int dram_init_banksize(void)
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020044{
45 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
46 gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
Simon Glass2f949c32017-03-31 08:40:32 -060047
48 return 0;
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020049}
50
Ramon Friedbc866cc82018-09-21 13:35:43 +030051int board_usb_init(int index, enum usb_init_type init)
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020052{
53 static struct udevice *pmic_gpio;
54 static struct gpio_desc hub_reset, usb_sel;
55 int ret = 0, node;
56
57 if (!pmic_gpio) {
58 ret = uclass_get_device_by_name(UCLASS_GPIO,
59 "pm8916_gpios@c000",
60 &pmic_gpio);
61 if (ret < 0) {
62 printf("Failed to find pm8916_gpios@c000 node.\n");
63 return ret;
64 }
65 }
66
67 /* Try to request gpios needed to start usb host on dragonboard */
68 if (!dm_gpio_is_valid(&hub_reset)) {
Simon Glassdd79d6e2017-01-17 16:52:55 -070069 node = fdt_subnode_offset(gd->fdt_blob,
70 dev_of_offset(pmic_gpio),
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020071 "usb_hub_reset_pm");
72 if (node < 0) {
73 printf("Failed to find usb_hub_reset_pm dt node.\n");
74 return node;
75 }
Simon Glass1d9af1f2017-05-30 21:47:09 -060076 ret = gpio_request_by_name_nodev(offset_to_ofnode(node),
77 "gpios", 0, &hub_reset, 0);
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020078 if (ret < 0) {
79 printf("Failed to request usb_hub_reset_pm gpio.\n");
80 return ret;
81 }
82 }
83
84 if (!dm_gpio_is_valid(&usb_sel)) {
Simon Glassdd79d6e2017-01-17 16:52:55 -070085 node = fdt_subnode_offset(gd->fdt_blob,
86 dev_of_offset(pmic_gpio),
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020087 "usb_sw_sel_pm");
88 if (node < 0) {
89 printf("Failed to find usb_sw_sel_pm dt node.\n");
90 return 0;
91 }
Simon Glass1d9af1f2017-05-30 21:47:09 -060092 ret = gpio_request_by_name_nodev(offset_to_ofnode(node),
93 "gpios", 0, &usb_sel, 0);
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020094 if (ret < 0) {
95 printf("Failed to request usb_sw_sel_pm gpio.\n");
96 return ret;
97 }
98 }
99
Ramon Friedbc866cc82018-09-21 13:35:43 +0300100 if (init == USB_INIT_HOST) {
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +0200101 /* Start USB Hub */
102 dm_gpio_set_dir_flags(&hub_reset,
103 GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE);
104 mdelay(100);
105 /* Switch usb to host connectors */
106 dm_gpio_set_dir_flags(&usb_sel,
107 GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE);
108 mdelay(100);
109 } else { /* Device */
110 /* Disable hub */
111 dm_gpio_set_dir_flags(&hub_reset, GPIOD_IS_OUT);
112 /* Switch back to device connector */
113 dm_gpio_set_dir_flags(&usb_sel, GPIOD_IS_OUT);
114 }
115
116 return 0;
117}
118
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +0200119/* Check for vol- button - if pressed - stop autoboot */
120int misc_init_r(void)
121{
122 struct udevice *pon;
123 struct gpio_desc resin;
124 int node, ret;
125
126 ret = uclass_get_device_by_name(UCLASS_GPIO, "pm8916_pon@800", &pon);
127 if (ret < 0) {
128 printf("Failed to find PMIC pon node. Check device tree\n");
129 return 0;
130 }
131
Simon Glassdd79d6e2017-01-17 16:52:55 -0700132 node = fdt_subnode_offset(gd->fdt_blob, dev_of_offset(pon),
133 "key_vol_down");
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +0200134 if (node < 0) {
135 printf("Failed to find key_vol_down node. Check device tree\n");
136 return 0;
137 }
138
Simon Glass1d9af1f2017-05-30 21:47:09 -0600139 if (gpio_request_by_name_nodev(offset_to_ofnode(node), "gpios", 0,
140 &resin, 0)) {
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +0200141 printf("Failed to request key_vol_down button.\n");
142 return 0;
143 }
144
145 if (dm_gpio_get_value(&resin)) {
Simon Glass6a38e412017-08-03 12:22:09 -0600146 env_set("bootdelay", "-1");
Ramon Frieddbc94102018-09-21 13:35:55 +0300147 env_set("bootcmd", "fastboot 0");
148 printf("key_vol_down pressed - Starting fastboot.\n");
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +0200149 }
150
151 return 0;
152}
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +0100153
154int board_init(void)
155{
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +0100156 return 0;
157}
158
Ramon Fried63596f02018-09-21 13:35:46 +0300159int board_late_init(void)
160{
161 char serial[16];
162
163 memset(serial, 0, 16);
164 snprintf(serial, 13, "%x", msm_board_serial());
165 env_set("serial#", serial);
166 return 0;
167}
168
Ramon Friede82a31c2018-08-03 16:25:37 +0300169/* Fixup of DTB for Linux Kernel
170 * 1. Fixup installed DRAM.
171 * 2. Fixup WLAN/BT Mac address:
172 * First, check if MAC addresses for WLAN/BT exists as environemnt
173 * variables wlanaddr,btaddr. if not, generate a unique address.
174 */
175
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +0100176int ft_board_setup(void *blob, bd_t *bd)
177{
Ramon Friede82a31c2018-08-03 16:25:37 +0300178 u8 mac[ARP_HLEN];
179
180 msm_fixup_memory(blob);
181
182 if (!eth_env_get_enetaddr("wlanaddr", mac)) {
183 msm_generate_mac_addr(mac);
Jorge Ramirez-Ortizf44f3012018-01-10 11:34:38 +0100184 };
185
Ramon Friede82a31c2018-08-03 16:25:37 +0300186 do_fixup_by_compat(blob, "qcom,wcnss-wlan",
187 "local-mac-address", mac, ARP_HLEN, 1);
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +0100188
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +0100189
Ramon Friede82a31c2018-08-03 16:25:37 +0300190 if (!eth_env_get_enetaddr("btaddr", mac)) {
191 msm_generate_mac_addr(mac);
192
193/* The BD address is same as WLAN MAC address but with
194 * least significant bit flipped.
195 */
196 mac[0] ^= 0x01;
197 };
Ramon Fried806549682018-07-31 12:29:58 +0300198
Ramon Friede82a31c2018-08-03 16:25:37 +0300199 do_fixup_by_compat(blob, "qcom,wcnss-bt",
200 "local-bd-address", mac, ARP_HLEN, 1);
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +0100201 return 0;
202}
Jorge Ramirez-Ortiz4154c9e2018-01-10 11:34:36 +0100203
204void reset_cpu(ulong addr)
205{
206 psci_system_reset();
207}