]>
Commit | Line | Data |
---|---|---|
83d290c5 | 1 | // SPDX-License-Identifier: GPL-2.0+ |
626f048b MK |
2 | /* |
3 | * Board init file for Dragonboard 410C | |
4 | * | |
5 | * (C) Copyright 2015 Mateusz Kulikowski <mateusz.kulikowski@gmail.com> | |
626f048b MK |
6 | */ |
7 | ||
8 | #include <common.h> | |
9a3b4ceb | 9 | #include <cpu_func.h> |
626f048b | 10 | #include <dm.h> |
9fb625ce | 11 | #include <env.h> |
5255932f | 12 | #include <init.h> |
90526e9f | 13 | #include <net.h> |
626f048b | 14 | #include <usb.h> |
90526e9f | 15 | #include <asm/cache.h> |
626f048b | 16 | #include <asm/gpio.h> |
e2beb872 | 17 | #include <fdt_support.h> |
9beb4906 | 18 | #include <asm/arch/dram.h> |
ff06dc24 | 19 | #include <asm/arch/misc.h> |
c05ed00a | 20 | #include <linux/delay.h> |
626f048b MK |
21 | |
22 | DECLARE_GLOBAL_DATA_PTR; | |
23 | ||
e2beb872 | 24 | /* pointer to the device tree ammended by the firmware */ |
9337dfb4 | 25 | extern void *fw_dtb; |
e2beb872 | 26 | |
9337dfb4 JRO |
27 | void *board_fdt_blob_setup(void) |
28 | { | |
29 | if (fdt_magic(fw_dtb) != FDT_MAGIC) { | |
30 | printf("Firmware provided invalid dtb!\n"); | |
31 | return NULL; | |
32 | } | |
33 | ||
34 | return fw_dtb; | |
35 | } | |
e2beb872 | 36 | |
626f048b MK |
37 | int dram_init(void) |
38 | { | |
39 | gd->ram_size = PHYS_SDRAM_1_SIZE; | |
9337dfb4 | 40 | |
626f048b MK |
41 | return 0; |
42 | } | |
43 | ||
76b00aca | 44 | int dram_init_banksize(void) |
626f048b MK |
45 | { |
46 | gd->bd->bi_dram[0].start = PHYS_SDRAM_1; | |
47 | gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE; | |
76b00aca SG |
48 | |
49 | return 0; | |
626f048b MK |
50 | } |
51 | ||
cd8c3aec | 52 | int board_usb_init(int index, enum usb_init_type init) |
626f048b MK |
53 | { |
54 | static struct udevice *pmic_gpio; | |
55 | static struct gpio_desc hub_reset, usb_sel; | |
56 | int ret = 0, node; | |
57 | ||
58 | if (!pmic_gpio) { | |
59 | ret = uclass_get_device_by_name(UCLASS_GPIO, | |
60 | "pm8916_gpios@c000", | |
61 | &pmic_gpio); | |
62 | if (ret < 0) { | |
63 | printf("Failed to find pm8916_gpios@c000 node.\n"); | |
64 | return ret; | |
65 | } | |
66 | } | |
67 | ||
68 | /* Try to request gpios needed to start usb host on dragonboard */ | |
69 | if (!dm_gpio_is_valid(&hub_reset)) { | |
e160f7d4 SG |
70 | node = fdt_subnode_offset(gd->fdt_blob, |
71 | dev_of_offset(pmic_gpio), | |
626f048b MK |
72 | "usb_hub_reset_pm"); |
73 | if (node < 0) { | |
74 | printf("Failed to find usb_hub_reset_pm dt node.\n"); | |
75 | return node; | |
76 | } | |
150c5afe SG |
77 | ret = gpio_request_by_name_nodev(offset_to_ofnode(node), |
78 | "gpios", 0, &hub_reset, 0); | |
626f048b MK |
79 | if (ret < 0) { |
80 | printf("Failed to request usb_hub_reset_pm gpio.\n"); | |
81 | return ret; | |
82 | } | |
83 | } | |
84 | ||
85 | if (!dm_gpio_is_valid(&usb_sel)) { | |
e160f7d4 SG |
86 | node = fdt_subnode_offset(gd->fdt_blob, |
87 | dev_of_offset(pmic_gpio), | |
626f048b MK |
88 | "usb_sw_sel_pm"); |
89 | if (node < 0) { | |
90 | printf("Failed to find usb_sw_sel_pm dt node.\n"); | |
91 | return 0; | |
92 | } | |
150c5afe SG |
93 | ret = gpio_request_by_name_nodev(offset_to_ofnode(node), |
94 | "gpios", 0, &usb_sel, 0); | |
626f048b MK |
95 | if (ret < 0) { |
96 | printf("Failed to request usb_sw_sel_pm gpio.\n"); | |
97 | return ret; | |
98 | } | |
99 | } | |
100 | ||
cd8c3aec | 101 | if (init == USB_INIT_HOST) { |
626f048b MK |
102 | /* Start USB Hub */ |
103 | dm_gpio_set_dir_flags(&hub_reset, | |
104 | GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE); | |
105 | mdelay(100); | |
106 | /* Switch usb to host connectors */ | |
107 | dm_gpio_set_dir_flags(&usb_sel, | |
108 | GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE); | |
109 | mdelay(100); | |
110 | } else { /* Device */ | |
111 | /* Disable hub */ | |
112 | dm_gpio_set_dir_flags(&hub_reset, GPIOD_IS_OUT); | |
113 | /* Switch back to device connector */ | |
114 | dm_gpio_set_dir_flags(&usb_sel, GPIOD_IS_OUT); | |
115 | } | |
116 | ||
117 | return 0; | |
118 | } | |
119 | ||
626f048b MK |
120 | /* Check for vol- button - if pressed - stop autoboot */ |
121 | int misc_init_r(void) | |
122 | { | |
123 | struct udevice *pon; | |
124 | struct gpio_desc resin; | |
125 | int node, ret; | |
126 | ||
127 | ret = uclass_get_device_by_name(UCLASS_GPIO, "pm8916_pon@800", &pon); | |
128 | if (ret < 0) { | |
129 | printf("Failed to find PMIC pon node. Check device tree\n"); | |
130 | return 0; | |
131 | } | |
132 | ||
e160f7d4 SG |
133 | node = fdt_subnode_offset(gd->fdt_blob, dev_of_offset(pon), |
134 | "key_vol_down"); | |
626f048b MK |
135 | if (node < 0) { |
136 | printf("Failed to find key_vol_down node. Check device tree\n"); | |
137 | return 0; | |
138 | } | |
139 | ||
150c5afe SG |
140 | if (gpio_request_by_name_nodev(offset_to_ofnode(node), "gpios", 0, |
141 | &resin, 0)) { | |
626f048b MK |
142 | printf("Failed to request key_vol_down button.\n"); |
143 | return 0; | |
144 | } | |
145 | ||
146 | if (dm_gpio_get_value(&resin)) { | |
382bee57 | 147 | env_set("bootdelay", "-1"); |
aa043ee9 RF |
148 | env_set("bootcmd", "fastboot 0"); |
149 | printf("key_vol_down pressed - Starting fastboot.\n"); | |
626f048b MK |
150 | } |
151 | ||
152 | return 0; | |
153 | } | |
e2beb872 JRO |
154 | |
155 | int board_init(void) | |
156 | { | |
e2beb872 JRO |
157 | return 0; |
158 | } | |
159 | ||
2df573e6 RF |
160 | int board_late_init(void) |
161 | { | |
162 | char serial[16]; | |
163 | ||
164 | memset(serial, 0, 16); | |
165 | snprintf(serial, 13, "%x", msm_board_serial()); | |
166 | env_set("serial#", serial); | |
167 | return 0; | |
168 | } | |
169 | ||
ff06dc24 RF |
170 | /* Fixup of DTB for Linux Kernel |
171 | * 1. Fixup installed DRAM. | |
172 | * 2. Fixup WLAN/BT Mac address: | |
173 | * First, check if MAC addresses for WLAN/BT exists as environemnt | |
174 | * variables wlanaddr,btaddr. if not, generate a unique address. | |
175 | */ | |
176 | ||
e2beb872 JRO |
177 | int ft_board_setup(void *blob, bd_t *bd) |
178 | { | |
ff06dc24 RF |
179 | u8 mac[ARP_HLEN]; |
180 | ||
181 | msm_fixup_memory(blob); | |
182 | ||
183 | if (!eth_env_get_enetaddr("wlanaddr", mac)) { | |
184 | msm_generate_mac_addr(mac); | |
9337dfb4 JRO |
185 | }; |
186 | ||
ff06dc24 RF |
187 | do_fixup_by_compat(blob, "qcom,wcnss-wlan", |
188 | "local-mac-address", mac, ARP_HLEN, 1); | |
9337dfb4 | 189 | |
e2beb872 | 190 | |
ff06dc24 RF |
191 | if (!eth_env_get_enetaddr("btaddr", mac)) { |
192 | msm_generate_mac_addr(mac); | |
193 | ||
194 | /* The BD address is same as WLAN MAC address but with | |
195 | * least significant bit flipped. | |
196 | */ | |
197 | mac[0] ^= 0x01; | |
198 | }; | |
9beb4906 | 199 | |
ff06dc24 RF |
200 | do_fixup_by_compat(blob, "qcom,wcnss-bt", |
201 | "local-bd-address", mac, ARP_HLEN, 1); | |
e2beb872 JRO |
202 | return 0; |
203 | } | |
0689eb74 JRO |
204 | |
205 | void reset_cpu(ulong addr) | |
206 | { | |
207 | psci_system_reset(); | |
208 | } |