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