Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Mateusz Kulikowski | 626f048 | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Board init file for Dragonboard 410C |
| 4 | * |
| 5 | * (C) Copyright 2015 Mateusz Kulikowski <mateusz.kulikowski@gmail.com> |
Mateusz Kulikowski | 626f048 | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
Simon Glass | 9a3b4ce | 2019-12-28 10:45:01 -0700 | [diff] [blame] | 9 | #include <cpu_func.h> |
Mateusz Kulikowski | 626f048 | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 10 | #include <dm.h> |
Simon Glass | 9fb625c | 2019-08-01 09:46:51 -0600 | [diff] [blame] | 11 | #include <env.h> |
Simon Glass | 5255932 | 2019-11-14 12:57:46 -0700 | [diff] [blame] | 12 | #include <init.h> |
Simon Glass | 90526e9 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 13 | #include <net.h> |
Mateusz Kulikowski | 626f048 | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 14 | #include <usb.h> |
Simon Glass | 90526e9 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 15 | #include <asm/cache.h> |
Mateusz Kulikowski | 626f048 | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 16 | #include <asm/gpio.h> |
Jorge Ramirez-Ortiz | e2beb87 | 2018-01-10 11:34:35 +0100 | [diff] [blame] | 17 | #include <fdt_support.h> |
Ramon Fried | 9beb490 | 2018-07-31 12:29:58 +0300 | [diff] [blame] | 18 | #include <asm/arch/dram.h> |
Ramon Fried | ff06dc2 | 2018-08-03 16:25:37 +0300 | [diff] [blame] | 19 | #include <asm/arch/misc.h> |
Simon Glass | c05ed00 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 20 | #include <linux/delay.h> |
Mateusz Kulikowski | 626f048 | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 21 | |
| 22 | DECLARE_GLOBAL_DATA_PTR; |
| 23 | |
Jorge Ramirez-Ortiz | e2beb87 | 2018-01-10 11:34:35 +0100 | [diff] [blame] | 24 | /* pointer to the device tree ammended by the firmware */ |
Jorge Ramirez-Ortiz | 9337dfb | 2018-01-10 11:34:38 +0100 | [diff] [blame] | 25 | extern void *fw_dtb; |
Jorge Ramirez-Ortiz | e2beb87 | 2018-01-10 11:34:35 +0100 | [diff] [blame] | 26 | |
Jorge Ramirez-Ortiz | 9337dfb | 2018-01-10 11:34:38 +0100 | [diff] [blame] | 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 | } |
Jorge Ramirez-Ortiz | e2beb87 | 2018-01-10 11:34:35 +0100 | [diff] [blame] | 36 | |
Mateusz Kulikowski | 626f048 | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 37 | int dram_init(void) |
| 38 | { |
| 39 | gd->ram_size = PHYS_SDRAM_1_SIZE; |
Jorge Ramirez-Ortiz | 9337dfb | 2018-01-10 11:34:38 +0100 | [diff] [blame] | 40 | |
Mateusz Kulikowski | 626f048 | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 41 | return 0; |
| 42 | } |
| 43 | |
Simon Glass | 76b00ac | 2017-03-31 08:40:32 -0600 | [diff] [blame] | 44 | int dram_init_banksize(void) |
Mateusz Kulikowski | 626f048 | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 45 | { |
| 46 | gd->bd->bi_dram[0].start = PHYS_SDRAM_1; |
| 47 | gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE; |
Simon Glass | 76b00ac | 2017-03-31 08:40:32 -0600 | [diff] [blame] | 48 | |
| 49 | return 0; |
Mateusz Kulikowski | 626f048 | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 50 | } |
| 51 | |
Ramon Fried | cd8c3ae | 2018-09-21 13:35:43 +0300 | [diff] [blame] | 52 | int board_usb_init(int index, enum usb_init_type init) |
Mateusz Kulikowski | 626f048 | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 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)) { |
Simon Glass | e160f7d | 2017-01-17 16:52:55 -0700 | [diff] [blame] | 70 | node = fdt_subnode_offset(gd->fdt_blob, |
| 71 | dev_of_offset(pmic_gpio), |
Mateusz Kulikowski | 626f048 | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 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 | } |
Simon Glass | 150c5af | 2017-05-30 21:47:09 -0600 | [diff] [blame] | 77 | ret = gpio_request_by_name_nodev(offset_to_ofnode(node), |
| 78 | "gpios", 0, &hub_reset, 0); |
Mateusz Kulikowski | 626f048 | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 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)) { |
Simon Glass | e160f7d | 2017-01-17 16:52:55 -0700 | [diff] [blame] | 86 | node = fdt_subnode_offset(gd->fdt_blob, |
| 87 | dev_of_offset(pmic_gpio), |
Mateusz Kulikowski | 626f048 | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 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 | } |
Simon Glass | 150c5af | 2017-05-30 21:47:09 -0600 | [diff] [blame] | 93 | ret = gpio_request_by_name_nodev(offset_to_ofnode(node), |
| 94 | "gpios", 0, &usb_sel, 0); |
Mateusz Kulikowski | 626f048 | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 95 | if (ret < 0) { |
| 96 | printf("Failed to request usb_sw_sel_pm gpio.\n"); |
| 97 | return ret; |
| 98 | } |
| 99 | } |
| 100 | |
Ramon Fried | cd8c3ae | 2018-09-21 13:35:43 +0300 | [diff] [blame] | 101 | if (init == USB_INIT_HOST) { |
Mateusz Kulikowski | 626f048 | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 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 | |
Mateusz Kulikowski | 626f048 | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 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 | |
Simon Glass | e160f7d | 2017-01-17 16:52:55 -0700 | [diff] [blame] | 133 | node = fdt_subnode_offset(gd->fdt_blob, dev_of_offset(pon), |
| 134 | "key_vol_down"); |
Mateusz Kulikowski | 626f048 | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 135 | if (node < 0) { |
| 136 | printf("Failed to find key_vol_down node. Check device tree\n"); |
| 137 | return 0; |
| 138 | } |
| 139 | |
Simon Glass | 150c5af | 2017-05-30 21:47:09 -0600 | [diff] [blame] | 140 | if (gpio_request_by_name_nodev(offset_to_ofnode(node), "gpios", 0, |
| 141 | &resin, 0)) { |
Mateusz Kulikowski | 626f048 | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 142 | printf("Failed to request key_vol_down button.\n"); |
| 143 | return 0; |
| 144 | } |
| 145 | |
| 146 | if (dm_gpio_get_value(&resin)) { |
Simon Glass | 382bee5 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 147 | env_set("bootdelay", "-1"); |
Ramon Fried | aa043ee | 2018-09-21 13:35:55 +0300 | [diff] [blame] | 148 | env_set("bootcmd", "fastboot 0"); |
| 149 | printf("key_vol_down pressed - Starting fastboot.\n"); |
Mateusz Kulikowski | 626f048 | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | return 0; |
| 153 | } |
Jorge Ramirez-Ortiz | e2beb87 | 2018-01-10 11:34:35 +0100 | [diff] [blame] | 154 | |
| 155 | int board_init(void) |
| 156 | { |
Jorge Ramirez-Ortiz | e2beb87 | 2018-01-10 11:34:35 +0100 | [diff] [blame] | 157 | return 0; |
| 158 | } |
| 159 | |
Ramon Fried | 2df573e | 2018-09-21 13:35:46 +0300 | [diff] [blame] | 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 | |
Ramon Fried | ff06dc2 | 2018-08-03 16:25:37 +0300 | [diff] [blame] | 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 | |
Masahiro Yamada | b75d8dc | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 177 | int ft_board_setup(void *blob, struct bd_info *bd) |
Jorge Ramirez-Ortiz | e2beb87 | 2018-01-10 11:34:35 +0100 | [diff] [blame] | 178 | { |
Ramon Fried | ff06dc2 | 2018-08-03 16:25:37 +0300 | [diff] [blame] | 179 | u8 mac[ARP_HLEN]; |
Jorge Ramirez-Ortiz | e2beb87 | 2018-01-10 11:34:35 +0100 | [diff] [blame] | 180 | |
Ramon Fried | 9beb490 | 2018-07-31 12:29:58 +0300 | [diff] [blame] | 181 | msm_fixup_memory(blob); |
| 182 | |
Ramon Fried | ff06dc2 | 2018-08-03 16:25:37 +0300 | [diff] [blame] | 183 | if (!eth_env_get_enetaddr("wlanaddr", mac)) { |
| 184 | msm_generate_mac_addr(mac); |
| 185 | }; |
| 186 | |
| 187 | do_fixup_by_compat(blob, "qcom,wcnss-wlan", |
| 188 | "local-mac-address", mac, ARP_HLEN, 1); |
| 189 | |
| 190 | |
| 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 | }; |
| 199 | |
| 200 | do_fixup_by_compat(blob, "qcom,wcnss-bt", |
| 201 | "local-bd-address", mac, ARP_HLEN, 1); |
Jorge Ramirez-Ortiz | e2beb87 | 2018-01-10 11:34:35 +0100 | [diff] [blame] | 202 | return 0; |
| 203 | } |
Jorge Ramirez-Ortiz | 0689eb7 | 2018-01-10 11:34:36 +0100 | [diff] [blame] | 204 | |
| 205 | void reset_cpu(ulong addr) |
| 206 | { |
| 207 | psci_system_reset(); |
| 208 | } |