Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Mateusz Kulikowski | 626f048 | 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 | 626f048 | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 6 | */ |
| 7 | |
Caleb Connolly | 5df679a | 2023-11-30 16:13:50 +0000 | [diff] [blame] | 8 | #include <button.h> |
Mateusz Kulikowski | 626f048 | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 9 | #include <common.h> |
Simon Glass | 9a3b4ce | 2019-12-28 10:45:01 -0700 | [diff] [blame] | 10 | #include <cpu_func.h> |
Mateusz Kulikowski | 626f048 | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 11 | #include <dm.h> |
Simon Glass | 9fb625c | 2019-08-01 09:46:51 -0600 | [diff] [blame] | 12 | #include <env.h> |
Simon Glass | 5255932 | 2019-11-14 12:57:46 -0700 | [diff] [blame] | 13 | #include <init.h> |
Simon Glass | 90526e9 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 14 | #include <net.h> |
Mateusz Kulikowski | 626f048 | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 15 | #include <usb.h> |
Simon Glass | 90526e9 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 16 | #include <asm/cache.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 17 | #include <asm/global_data.h> |
Mateusz Kulikowski | 626f048 | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 18 | #include <asm/gpio.h> |
Jorge Ramirez-Ortiz | e2beb87 | 2018-01-10 11:34:35 +0100 | [diff] [blame] | 19 | #include <fdt_support.h> |
Simon Glass | c05ed00 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 20 | #include <linux/delay.h> |
Mateusz Kulikowski | 626f048 | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 21 | |
Caleb Connolly | 3de41f9 | 2023-11-07 14:58:23 +0000 | [diff] [blame] | 22 | #include "misc.h" |
| 23 | |
Mateusz Kulikowski | 626f048 | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 24 | DECLARE_GLOBAL_DATA_PTR; |
| 25 | |
Ramon Fried | cd8c3ae | 2018-09-21 13:35:43 +0300 | [diff] [blame] | 26 | int board_usb_init(int index, enum usb_init_type init) |
Mateusz Kulikowski | 626f048 | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 27 | { |
| 28 | static struct udevice *pmic_gpio; |
| 29 | static struct gpio_desc hub_reset, usb_sel; |
| 30 | int ret = 0, node; |
| 31 | |
| 32 | if (!pmic_gpio) { |
| 33 | ret = uclass_get_device_by_name(UCLASS_GPIO, |
Caleb Connolly | 1ccfdb5 | 2023-11-14 19:41:44 +0000 | [diff] [blame] | 34 | "gpio@c000", |
Mateusz Kulikowski | 626f048 | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 35 | &pmic_gpio); |
| 36 | if (ret < 0) { |
Caleb Connolly | 1ccfdb5 | 2023-11-14 19:41:44 +0000 | [diff] [blame] | 37 | printf("Failed to find gpio@c000 node.\n"); |
Mateusz Kulikowski | 626f048 | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 38 | return ret; |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | /* Try to request gpios needed to start usb host on dragonboard */ |
| 43 | if (!dm_gpio_is_valid(&hub_reset)) { |
Simon Glass | e160f7d | 2017-01-17 16:52:55 -0700 | [diff] [blame] | 44 | node = fdt_subnode_offset(gd->fdt_blob, |
| 45 | dev_of_offset(pmic_gpio), |
Mateusz Kulikowski | 626f048 | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 46 | "usb_hub_reset_pm"); |
| 47 | if (node < 0) { |
| 48 | printf("Failed to find usb_hub_reset_pm dt node.\n"); |
| 49 | return node; |
| 50 | } |
Simon Glass | 150c5af | 2017-05-30 21:47:09 -0600 | [diff] [blame] | 51 | ret = gpio_request_by_name_nodev(offset_to_ofnode(node), |
| 52 | "gpios", 0, &hub_reset, 0); |
Mateusz Kulikowski | 626f048 | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 53 | if (ret < 0) { |
| 54 | printf("Failed to request usb_hub_reset_pm gpio.\n"); |
| 55 | return ret; |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | if (!dm_gpio_is_valid(&usb_sel)) { |
Simon Glass | e160f7d | 2017-01-17 16:52:55 -0700 | [diff] [blame] | 60 | node = fdt_subnode_offset(gd->fdt_blob, |
| 61 | dev_of_offset(pmic_gpio), |
Mateusz Kulikowski | 626f048 | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 62 | "usb_sw_sel_pm"); |
| 63 | if (node < 0) { |
| 64 | printf("Failed to find usb_sw_sel_pm dt node.\n"); |
| 65 | return 0; |
| 66 | } |
Simon Glass | 150c5af | 2017-05-30 21:47:09 -0600 | [diff] [blame] | 67 | ret = gpio_request_by_name_nodev(offset_to_ofnode(node), |
| 68 | "gpios", 0, &usb_sel, 0); |
Mateusz Kulikowski | 626f048 | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 69 | if (ret < 0) { |
| 70 | printf("Failed to request usb_sw_sel_pm gpio.\n"); |
| 71 | return ret; |
| 72 | } |
| 73 | } |
| 74 | |
Ramon Fried | cd8c3ae | 2018-09-21 13:35:43 +0300 | [diff] [blame] | 75 | if (init == USB_INIT_HOST) { |
Mateusz Kulikowski | 626f048 | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 76 | /* Start USB Hub */ |
| 77 | dm_gpio_set_dir_flags(&hub_reset, |
| 78 | GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE); |
| 79 | mdelay(100); |
| 80 | /* Switch usb to host connectors */ |
| 81 | dm_gpio_set_dir_flags(&usb_sel, |
| 82 | GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE); |
| 83 | mdelay(100); |
| 84 | } else { /* Device */ |
| 85 | /* Disable hub */ |
| 86 | dm_gpio_set_dir_flags(&hub_reset, GPIOD_IS_OUT); |
| 87 | /* Switch back to device connector */ |
| 88 | dm_gpio_set_dir_flags(&usb_sel, GPIOD_IS_OUT); |
| 89 | } |
| 90 | |
| 91 | return 0; |
| 92 | } |
| 93 | |
Mateusz Kulikowski | 626f048 | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 94 | /* Check for vol- button - if pressed - stop autoboot */ |
| 95 | int misc_init_r(void) |
| 96 | { |
Caleb Connolly | 5df679a | 2023-11-30 16:13:50 +0000 | [diff] [blame] | 97 | struct udevice *btn; |
| 98 | int ret; |
| 99 | enum button_state_t state; |
Mateusz Kulikowski | 626f048 | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 100 | |
Caleb Connolly | 5df679a | 2023-11-30 16:13:50 +0000 | [diff] [blame] | 101 | ret = button_get_by_label("vol_down", &btn); |
Mateusz Kulikowski | 626f048 | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 102 | if (ret < 0) { |
Caleb Connolly | 5df679a | 2023-11-30 16:13:50 +0000 | [diff] [blame] | 103 | printf("Couldn't find power button!\n"); |
| 104 | return ret; |
Mateusz Kulikowski | 626f048 | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 105 | } |
| 106 | |
Caleb Connolly | 5df679a | 2023-11-30 16:13:50 +0000 | [diff] [blame] | 107 | state = button_get_state(btn); |
| 108 | if (state == BUTTON_ON) { |
Stephan Gerhold | ccb8de2 | 2021-07-14 10:56:25 +0200 | [diff] [blame] | 109 | env_set("preboot", "setenv preboot; fastboot 0"); |
Caleb Connolly | 5df679a | 2023-11-30 16:13:50 +0000 | [diff] [blame] | 110 | printf("vol_down pressed - Starting fastboot.\n"); |
Mateusz Kulikowski | 626f048 | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | return 0; |
| 114 | } |
Jorge Ramirez-Ortiz | e2beb87 | 2018-01-10 11:34:35 +0100 | [diff] [blame] | 115 | |
Caleb Connolly | 16da8c7 | 2023-10-03 11:35:40 +0100 | [diff] [blame] | 116 | int qcom_late_init(void) |
Ramon Fried | 2df573e | 2018-09-21 13:35:46 +0300 | [diff] [blame] | 117 | { |
| 118 | char serial[16]; |
| 119 | |
| 120 | memset(serial, 0, 16); |
| 121 | snprintf(serial, 13, "%x", msm_board_serial()); |
| 122 | env_set("serial#", serial); |
| 123 | return 0; |
| 124 | } |
| 125 | |
Ramon Fried | ff06dc2 | 2018-08-03 16:25:37 +0300 | [diff] [blame] | 126 | /* Fixup of DTB for Linux Kernel |
| 127 | * 1. Fixup installed DRAM. |
| 128 | * 2. Fixup WLAN/BT Mac address: |
| 129 | * First, check if MAC addresses for WLAN/BT exists as environemnt |
| 130 | * variables wlanaddr,btaddr. if not, generate a unique address. |
| 131 | */ |
| 132 | |
Masahiro Yamada | b75d8dc | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 133 | int ft_board_setup(void *blob, struct bd_info *bd) |
Jorge Ramirez-Ortiz | e2beb87 | 2018-01-10 11:34:35 +0100 | [diff] [blame] | 134 | { |
Ramon Fried | ff06dc2 | 2018-08-03 16:25:37 +0300 | [diff] [blame] | 135 | u8 mac[ARP_HLEN]; |
Jorge Ramirez-Ortiz | e2beb87 | 2018-01-10 11:34:35 +0100 | [diff] [blame] | 136 | |
Ramon Fried | 9beb490 | 2018-07-31 12:29:58 +0300 | [diff] [blame] | 137 | msm_fixup_memory(blob); |
| 138 | |
Ramon Fried | ff06dc2 | 2018-08-03 16:25:37 +0300 | [diff] [blame] | 139 | if (!eth_env_get_enetaddr("wlanaddr", mac)) { |
| 140 | msm_generate_mac_addr(mac); |
| 141 | }; |
| 142 | |
| 143 | do_fixup_by_compat(blob, "qcom,wcnss-wlan", |
| 144 | "local-mac-address", mac, ARP_HLEN, 1); |
| 145 | |
| 146 | |
| 147 | if (!eth_env_get_enetaddr("btaddr", mac)) { |
| 148 | msm_generate_mac_addr(mac); |
| 149 | |
| 150 | /* The BD address is same as WLAN MAC address but with |
| 151 | * least significant bit flipped. |
| 152 | */ |
| 153 | mac[0] ^= 0x01; |
| 154 | }; |
| 155 | |
| 156 | do_fixup_by_compat(blob, "qcom,wcnss-bt", |
| 157 | "local-bd-address", mac, ARP_HLEN, 1); |
Jorge Ramirez-Ortiz | e2beb87 | 2018-01-10 11:34:35 +0100 | [diff] [blame] | 158 | return 0; |
| 159 | } |