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