blob: e7ead57f0dac313caab6ace495cee64be4f379bd [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>
9#include <dm.h>
10#include <usb.h>
11#include <asm/gpio.h>
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +010012#include <fdt_support.h>
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020013
14DECLARE_GLOBAL_DATA_PTR;
15
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +010016/* pointer to the device tree ammended by the firmware */
Jorge Ramirez-Ortizf44f3012018-01-10 11:34:38 +010017extern void *fw_dtb;
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +010018
Jorge Ramirez-Ortizf44f3012018-01-10 11:34:38 +010019void *board_fdt_blob_setup(void)
20{
21 if (fdt_magic(fw_dtb) != FDT_MAGIC) {
22 printf("Firmware provided invalid dtb!\n");
23 return NULL;
24 }
25
26 return fw_dtb;
27}
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +010028
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020029int dram_init(void)
30{
31 gd->ram_size = PHYS_SDRAM_1_SIZE;
Jorge Ramirez-Ortizf44f3012018-01-10 11:34:38 +010032
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020033 return 0;
34}
35
Simon Glass2f949c32017-03-31 08:40:32 -060036int dram_init_banksize(void)
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020037{
38 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
39 gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
Simon Glass2f949c32017-03-31 08:40:32 -060040
41 return 0;
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020042}
43
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020044int board_prepare_usb(enum usb_init_type type)
45{
46 static struct udevice *pmic_gpio;
47 static struct gpio_desc hub_reset, usb_sel;
48 int ret = 0, node;
49
50 if (!pmic_gpio) {
51 ret = uclass_get_device_by_name(UCLASS_GPIO,
52 "pm8916_gpios@c000",
53 &pmic_gpio);
54 if (ret < 0) {
55 printf("Failed to find pm8916_gpios@c000 node.\n");
56 return ret;
57 }
58 }
59
60 /* Try to request gpios needed to start usb host on dragonboard */
61 if (!dm_gpio_is_valid(&hub_reset)) {
Simon Glassdd79d6e2017-01-17 16:52:55 -070062 node = fdt_subnode_offset(gd->fdt_blob,
63 dev_of_offset(pmic_gpio),
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020064 "usb_hub_reset_pm");
65 if (node < 0) {
66 printf("Failed to find usb_hub_reset_pm dt node.\n");
67 return node;
68 }
Simon Glass1d9af1f2017-05-30 21:47:09 -060069 ret = gpio_request_by_name_nodev(offset_to_ofnode(node),
70 "gpios", 0, &hub_reset, 0);
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020071 if (ret < 0) {
72 printf("Failed to request usb_hub_reset_pm gpio.\n");
73 return ret;
74 }
75 }
76
77 if (!dm_gpio_is_valid(&usb_sel)) {
Simon Glassdd79d6e2017-01-17 16:52:55 -070078 node = fdt_subnode_offset(gd->fdt_blob,
79 dev_of_offset(pmic_gpio),
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020080 "usb_sw_sel_pm");
81 if (node < 0) {
82 printf("Failed to find usb_sw_sel_pm dt node.\n");
83 return 0;
84 }
Simon Glass1d9af1f2017-05-30 21:47:09 -060085 ret = gpio_request_by_name_nodev(offset_to_ofnode(node),
86 "gpios", 0, &usb_sel, 0);
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020087 if (ret < 0) {
88 printf("Failed to request usb_sw_sel_pm gpio.\n");
89 return ret;
90 }
91 }
92
93 if (type == USB_INIT_HOST) {
94 /* Start USB Hub */
95 dm_gpio_set_dir_flags(&hub_reset,
96 GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE);
97 mdelay(100);
98 /* Switch usb to host connectors */
99 dm_gpio_set_dir_flags(&usb_sel,
100 GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE);
101 mdelay(100);
102 } else { /* Device */
103 /* Disable hub */
104 dm_gpio_set_dir_flags(&hub_reset, GPIOD_IS_OUT);
105 /* Switch back to device connector */
106 dm_gpio_set_dir_flags(&usb_sel, GPIOD_IS_OUT);
107 }
108
109 return 0;
110}
111
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +0200112/* Check for vol- button - if pressed - stop autoboot */
113int misc_init_r(void)
114{
115 struct udevice *pon;
116 struct gpio_desc resin;
117 int node, ret;
118
119 ret = uclass_get_device_by_name(UCLASS_GPIO, "pm8916_pon@800", &pon);
120 if (ret < 0) {
121 printf("Failed to find PMIC pon node. Check device tree\n");
122 return 0;
123 }
124
Simon Glassdd79d6e2017-01-17 16:52:55 -0700125 node = fdt_subnode_offset(gd->fdt_blob, dev_of_offset(pon),
126 "key_vol_down");
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +0200127 if (node < 0) {
128 printf("Failed to find key_vol_down node. Check device tree\n");
129 return 0;
130 }
131
Simon Glass1d9af1f2017-05-30 21:47:09 -0600132 if (gpio_request_by_name_nodev(offset_to_ofnode(node), "gpios", 0,
133 &resin, 0)) {
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +0200134 printf("Failed to request key_vol_down button.\n");
135 return 0;
136 }
137
138 if (dm_gpio_get_value(&resin)) {
Simon Glass6a38e412017-08-03 12:22:09 -0600139 env_set("bootdelay", "-1");
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +0200140 printf("Power button pressed - dropping to console.\n");
141 }
142
143 return 0;
144}
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +0100145
146int board_init(void)
147{
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +0100148 return 0;
149}
150
151int ft_board_setup(void *blob, bd_t *bd)
152{
Jorge Ramirez-Ortizf44f3012018-01-10 11:34:38 +0100153 int offset, len, i;
154 const char *mac;
155 struct {
156 const char *compatible;
157 const char *property;
158 } fix[] = {
159 [0] = {
160 /* update the kernel's dtb with wlan mac */
161 .compatible = "qcom,wcnss-wlan",
162 .property = "local-mac-address",
163 },
164 [1] = {
165 /* update the kernel's dtb with bt mac */
166 .compatible = "qcom,wcnss-bt",
167 .property = "local-bd-address",
168 },
169 };
170
171 for (i = 0; i < sizeof(fix) / sizeof(fix[0]); i++) {
172 offset = fdt_node_offset_by_compatible(gd->fdt_blob, -1,
173 fix[i].compatible);
174 if (offset < 0)
175 continue;
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +0100176
Jorge Ramirez-Ortizf44f3012018-01-10 11:34:38 +0100177 mac = fdt_getprop(gd->fdt_blob, offset, fix[i].property, &len);
178 if (mac)
179 do_fixup_by_compat(blob, fix[i].compatible,
180 fix[i].property, mac, ARP_HLEN, 1);
181 }
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +0100182
183 return 0;
184}
Jorge Ramirez-Ortiz4154c9e2018-01-10 11:34:36 +0100185
186void reset_cpu(ulong addr)
187{
188 psci_system_reset();
189}