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