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