Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Mateusz Kulikowski | ee5e70d | 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 | ee5e70d | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <dm.h> |
| 10 | #include <usb.h> |
| 11 | #include <asm/gpio.h> |
Jorge Ramirez-Ortiz | 2cd3db9 | 2018-01-10 11:34:35 +0100 | [diff] [blame] | 12 | #include <fdt_support.h> |
Ramon Fried | e82a31c | 2018-08-03 16:25:37 +0300 | [diff] [blame] | 13 | #include <environment.h> |
Ramon Fried | 80654968 | 2018-07-31 12:29:58 +0300 | [diff] [blame] | 14 | #include <asm/arch/dram.h> |
Ramon Fried | e82a31c | 2018-08-03 16:25:37 +0300 | [diff] [blame] | 15 | #include <asm/arch/misc.h> |
Mateusz Kulikowski | ee5e70d | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 16 | |
| 17 | DECLARE_GLOBAL_DATA_PTR; |
| 18 | |
Jorge Ramirez-Ortiz | 2cd3db9 | 2018-01-10 11:34:35 +0100 | [diff] [blame] | 19 | /* pointer to the device tree ammended by the firmware */ |
Jorge Ramirez-Ortiz | f44f301 | 2018-01-10 11:34:38 +0100 | [diff] [blame] | 20 | extern void *fw_dtb; |
Jorge Ramirez-Ortiz | 2cd3db9 | 2018-01-10 11:34:35 +0100 | [diff] [blame] | 21 | |
Jorge Ramirez-Ortiz | f44f301 | 2018-01-10 11:34:38 +0100 | [diff] [blame] | 22 | void *board_fdt_blob_setup(void) |
| 23 | { |
| 24 | if (fdt_magic(fw_dtb) != FDT_MAGIC) { |
| 25 | printf("Firmware provided invalid dtb!\n"); |
| 26 | return NULL; |
| 27 | } |
| 28 | |
| 29 | return fw_dtb; |
| 30 | } |
Jorge Ramirez-Ortiz | 2cd3db9 | 2018-01-10 11:34:35 +0100 | [diff] [blame] | 31 | |
Mateusz Kulikowski | ee5e70d | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 32 | int dram_init(void) |
| 33 | { |
| 34 | gd->ram_size = PHYS_SDRAM_1_SIZE; |
Jorge Ramirez-Ortiz | f44f301 | 2018-01-10 11:34:38 +0100 | [diff] [blame] | 35 | |
Mateusz Kulikowski | ee5e70d | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 36 | return 0; |
| 37 | } |
| 38 | |
Simon Glass | 2f949c3 | 2017-03-31 08:40:32 -0600 | [diff] [blame] | 39 | int dram_init_banksize(void) |
Mateusz Kulikowski | ee5e70d | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 40 | { |
| 41 | gd->bd->bi_dram[0].start = PHYS_SDRAM_1; |
| 42 | gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE; |
Simon Glass | 2f949c3 | 2017-03-31 08:40:32 -0600 | [diff] [blame] | 43 | |
| 44 | return 0; |
Mateusz Kulikowski | ee5e70d | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 45 | } |
| 46 | |
Ramon Fried | bc866cc8 | 2018-09-21 13:35:43 +0300 | [diff] [blame] | 47 | int board_usb_init(int index, enum usb_init_type init) |
Mateusz Kulikowski | ee5e70d | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 48 | { |
| 49 | static struct udevice *pmic_gpio; |
| 50 | static struct gpio_desc hub_reset, usb_sel; |
| 51 | int ret = 0, node; |
| 52 | |
| 53 | if (!pmic_gpio) { |
| 54 | ret = uclass_get_device_by_name(UCLASS_GPIO, |
| 55 | "pm8916_gpios@c000", |
| 56 | &pmic_gpio); |
| 57 | if (ret < 0) { |
| 58 | printf("Failed to find pm8916_gpios@c000 node.\n"); |
| 59 | return ret; |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | /* Try to request gpios needed to start usb host on dragonboard */ |
| 64 | if (!dm_gpio_is_valid(&hub_reset)) { |
Simon Glass | dd79d6e | 2017-01-17 16:52:55 -0700 | [diff] [blame] | 65 | node = fdt_subnode_offset(gd->fdt_blob, |
| 66 | dev_of_offset(pmic_gpio), |
Mateusz Kulikowski | ee5e70d | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 67 | "usb_hub_reset_pm"); |
| 68 | if (node < 0) { |
| 69 | printf("Failed to find usb_hub_reset_pm dt node.\n"); |
| 70 | return node; |
| 71 | } |
Simon Glass | 1d9af1f | 2017-05-30 21:47:09 -0600 | [diff] [blame] | 72 | ret = gpio_request_by_name_nodev(offset_to_ofnode(node), |
| 73 | "gpios", 0, &hub_reset, 0); |
Mateusz Kulikowski | ee5e70d | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 74 | if (ret < 0) { |
| 75 | printf("Failed to request usb_hub_reset_pm gpio.\n"); |
| 76 | return ret; |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | if (!dm_gpio_is_valid(&usb_sel)) { |
Simon Glass | dd79d6e | 2017-01-17 16:52:55 -0700 | [diff] [blame] | 81 | node = fdt_subnode_offset(gd->fdt_blob, |
| 82 | dev_of_offset(pmic_gpio), |
Mateusz Kulikowski | ee5e70d | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 83 | "usb_sw_sel_pm"); |
| 84 | if (node < 0) { |
| 85 | printf("Failed to find usb_sw_sel_pm dt node.\n"); |
| 86 | return 0; |
| 87 | } |
Simon Glass | 1d9af1f | 2017-05-30 21:47:09 -0600 | [diff] [blame] | 88 | ret = gpio_request_by_name_nodev(offset_to_ofnode(node), |
| 89 | "gpios", 0, &usb_sel, 0); |
Mateusz Kulikowski | ee5e70d | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 90 | if (ret < 0) { |
| 91 | printf("Failed to request usb_sw_sel_pm gpio.\n"); |
| 92 | return ret; |
| 93 | } |
| 94 | } |
| 95 | |
Ramon Fried | bc866cc8 | 2018-09-21 13:35:43 +0300 | [diff] [blame] | 96 | if (init == USB_INIT_HOST) { |
Mateusz Kulikowski | ee5e70d | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 97 | /* Start USB Hub */ |
| 98 | dm_gpio_set_dir_flags(&hub_reset, |
| 99 | GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE); |
| 100 | mdelay(100); |
| 101 | /* Switch usb to host connectors */ |
| 102 | dm_gpio_set_dir_flags(&usb_sel, |
| 103 | GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE); |
| 104 | mdelay(100); |
| 105 | } else { /* Device */ |
| 106 | /* Disable hub */ |
| 107 | dm_gpio_set_dir_flags(&hub_reset, GPIOD_IS_OUT); |
| 108 | /* Switch back to device connector */ |
| 109 | dm_gpio_set_dir_flags(&usb_sel, GPIOD_IS_OUT); |
| 110 | } |
| 111 | |
| 112 | return 0; |
| 113 | } |
| 114 | |
Mateusz Kulikowski | ee5e70d | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 115 | /* Check for vol- button - if pressed - stop autoboot */ |
| 116 | int misc_init_r(void) |
| 117 | { |
| 118 | struct udevice *pon; |
| 119 | struct gpio_desc resin; |
| 120 | int node, ret; |
| 121 | |
| 122 | ret = uclass_get_device_by_name(UCLASS_GPIO, "pm8916_pon@800", &pon); |
| 123 | if (ret < 0) { |
| 124 | printf("Failed to find PMIC pon node. Check device tree\n"); |
| 125 | return 0; |
| 126 | } |
| 127 | |
Simon Glass | dd79d6e | 2017-01-17 16:52:55 -0700 | [diff] [blame] | 128 | node = fdt_subnode_offset(gd->fdt_blob, dev_of_offset(pon), |
| 129 | "key_vol_down"); |
Mateusz Kulikowski | ee5e70d | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 130 | if (node < 0) { |
| 131 | printf("Failed to find key_vol_down node. Check device tree\n"); |
| 132 | return 0; |
| 133 | } |
| 134 | |
Simon Glass | 1d9af1f | 2017-05-30 21:47:09 -0600 | [diff] [blame] | 135 | if (gpio_request_by_name_nodev(offset_to_ofnode(node), "gpios", 0, |
| 136 | &resin, 0)) { |
Mateusz Kulikowski | ee5e70d | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 137 | printf("Failed to request key_vol_down button.\n"); |
| 138 | return 0; |
| 139 | } |
| 140 | |
| 141 | if (dm_gpio_get_value(&resin)) { |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 142 | env_set("bootdelay", "-1"); |
Ramon Fried | dbc9410 | 2018-09-21 13:35:55 +0300 | [diff] [blame^] | 143 | env_set("bootcmd", "fastboot 0"); |
| 144 | printf("key_vol_down pressed - Starting fastboot.\n"); |
Mateusz Kulikowski | ee5e70d | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | return 0; |
| 148 | } |
Jorge Ramirez-Ortiz | 2cd3db9 | 2018-01-10 11:34:35 +0100 | [diff] [blame] | 149 | |
| 150 | int board_init(void) |
| 151 | { |
Jorge Ramirez-Ortiz | 2cd3db9 | 2018-01-10 11:34:35 +0100 | [diff] [blame] | 152 | return 0; |
| 153 | } |
| 154 | |
Ramon Fried | 63596f0 | 2018-09-21 13:35:46 +0300 | [diff] [blame] | 155 | int board_late_init(void) |
| 156 | { |
| 157 | char serial[16]; |
| 158 | |
| 159 | memset(serial, 0, 16); |
| 160 | snprintf(serial, 13, "%x", msm_board_serial()); |
| 161 | env_set("serial#", serial); |
| 162 | return 0; |
| 163 | } |
| 164 | |
Ramon Fried | e82a31c | 2018-08-03 16:25:37 +0300 | [diff] [blame] | 165 | /* Fixup of DTB for Linux Kernel |
| 166 | * 1. Fixup installed DRAM. |
| 167 | * 2. Fixup WLAN/BT Mac address: |
| 168 | * First, check if MAC addresses for WLAN/BT exists as environemnt |
| 169 | * variables wlanaddr,btaddr. if not, generate a unique address. |
| 170 | */ |
| 171 | |
Jorge Ramirez-Ortiz | 2cd3db9 | 2018-01-10 11:34:35 +0100 | [diff] [blame] | 172 | int ft_board_setup(void *blob, bd_t *bd) |
| 173 | { |
Ramon Fried | e82a31c | 2018-08-03 16:25:37 +0300 | [diff] [blame] | 174 | u8 mac[ARP_HLEN]; |
| 175 | |
| 176 | msm_fixup_memory(blob); |
| 177 | |
| 178 | if (!eth_env_get_enetaddr("wlanaddr", mac)) { |
| 179 | msm_generate_mac_addr(mac); |
Jorge Ramirez-Ortiz | f44f301 | 2018-01-10 11:34:38 +0100 | [diff] [blame] | 180 | }; |
| 181 | |
Ramon Fried | e82a31c | 2018-08-03 16:25:37 +0300 | [diff] [blame] | 182 | do_fixup_by_compat(blob, "qcom,wcnss-wlan", |
| 183 | "local-mac-address", mac, ARP_HLEN, 1); |
Jorge Ramirez-Ortiz | 2cd3db9 | 2018-01-10 11:34:35 +0100 | [diff] [blame] | 184 | |
Jorge Ramirez-Ortiz | 2cd3db9 | 2018-01-10 11:34:35 +0100 | [diff] [blame] | 185 | |
Ramon Fried | e82a31c | 2018-08-03 16:25:37 +0300 | [diff] [blame] | 186 | if (!eth_env_get_enetaddr("btaddr", mac)) { |
| 187 | msm_generate_mac_addr(mac); |
| 188 | |
| 189 | /* The BD address is same as WLAN MAC address but with |
| 190 | * least significant bit flipped. |
| 191 | */ |
| 192 | mac[0] ^= 0x01; |
| 193 | }; |
Ramon Fried | 80654968 | 2018-07-31 12:29:58 +0300 | [diff] [blame] | 194 | |
Ramon Fried | e82a31c | 2018-08-03 16:25:37 +0300 | [diff] [blame] | 195 | do_fixup_by_compat(blob, "qcom,wcnss-bt", |
| 196 | "local-bd-address", mac, ARP_HLEN, 1); |
Jorge Ramirez-Ortiz | 2cd3db9 | 2018-01-10 11:34:35 +0100 | [diff] [blame] | 197 | return 0; |
| 198 | } |
Jorge Ramirez-Ortiz | 4154c9e | 2018-01-10 11:34:36 +0100 | [diff] [blame] | 199 | |
| 200 | void reset_cpu(ulong addr) |
| 201 | { |
| 202 | psci_system_reset(); |
| 203 | } |