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> |
Caleb Connolly | 154ed1d | 2024-02-26 17:26:21 +0000 | [diff] [blame^] | 12 | #include <dm/pinctrl.h> |
Simon Glass | 5e6201b | 2019-08-01 09:46:51 -0600 | [diff] [blame] | 13 | #include <env.h> |
Simon Glass | a7b5130 | 2019-11-14 12:57:46 -0700 | [diff] [blame] | 14 | #include <init.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 15 | #include <net.h> |
Mateusz Kulikowski | ee5e70d | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 16 | #include <usb.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 17 | #include <asm/cache.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 18 | #include <asm/global_data.h> |
Mateusz Kulikowski | ee5e70d | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 19 | #include <asm/gpio.h> |
Jorge Ramirez-Ortiz | 2cd3db9 | 2018-01-10 11:34:35 +0100 | [diff] [blame] | 20 | #include <fdt_support.h> |
Ramon Fried | 80654968 | 2018-07-31 12:29:58 +0300 | [diff] [blame] | 21 | #include <asm/arch/dram.h> |
Ramon Fried | e82a31c | 2018-08-03 16:25:37 +0300 | [diff] [blame] | 22 | #include <asm/arch/misc.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 23 | #include <linux/delay.h> |
Mateusz Kulikowski | ee5e70d | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 24 | |
| 25 | DECLARE_GLOBAL_DATA_PTR; |
| 26 | |
Caleb Connolly | 154ed1d | 2024-02-26 17:26:21 +0000 | [diff] [blame^] | 27 | #define USB_HUB_RESET_GPIO 2 |
| 28 | #define USB_SW_SELECT_GPIO 3 |
Mateusz Kulikowski | ee5e70d | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 29 | |
Ramon Fried | bc866cc8 | 2018-09-21 13:35:43 +0300 | [diff] [blame] | 30 | int board_usb_init(int index, enum usb_init_type init) |
Mateusz Kulikowski | ee5e70d | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 31 | { |
Caleb Connolly | 154ed1d | 2024-02-26 17:26:21 +0000 | [diff] [blame^] | 32 | struct udevice *usb; |
| 33 | int ret = 0; |
Mateusz Kulikowski | ee5e70d | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 34 | |
Caleb Connolly | 154ed1d | 2024-02-26 17:26:21 +0000 | [diff] [blame^] | 35 | /* USB device */ |
| 36 | ret = device_find_global_by_ofnode(ofnode_path("/soc/usb"), &usb); |
| 37 | if (ret) { |
| 38 | printf("Cannot find USB device\n"); |
| 39 | return ret; |
Mateusz Kulikowski | ee5e70d | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 40 | } |
| 41 | |
Caleb Connolly | 154ed1d | 2024-02-26 17:26:21 +0000 | [diff] [blame^] | 42 | /* Select "default" or "device" pinctrl */ |
| 43 | switch (init) { |
| 44 | case USB_INIT_HOST: |
| 45 | pinctrl_select_state(usb, "default"); |
| 46 | break; |
| 47 | case USB_INIT_DEVICE: |
| 48 | pinctrl_select_state(usb, "device"); |
| 49 | break; |
| 50 | default: |
| 51 | debug("Unknown usb_init_type %d\n", init); |
| 52 | break; |
Mateusz Kulikowski | ee5e70d | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | return 0; |
| 56 | } |
| 57 | |
Mateusz Kulikowski | ee5e70d | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 58 | /* Check for vol- button - if pressed - stop autoboot */ |
| 59 | int misc_init_r(void) |
| 60 | { |
Caleb Connolly | 89a90d0 | 2023-12-05 13:46:48 +0000 | [diff] [blame] | 61 | struct udevice *btn; |
| 62 | int ret; |
| 63 | enum button_state_t state; |
Mateusz Kulikowski | ee5e70d | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 64 | |
Caleb Connolly | 89a90d0 | 2023-12-05 13:46:48 +0000 | [diff] [blame] | 65 | ret = button_get_by_label("vol_down", &btn); |
Mateusz Kulikowski | ee5e70d | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 66 | if (ret < 0) { |
Caleb Connolly | 89a90d0 | 2023-12-05 13:46:48 +0000 | [diff] [blame] | 67 | printf("Couldn't find power button!\n"); |
| 68 | return ret; |
Mateusz Kulikowski | ee5e70d | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 69 | } |
| 70 | |
Caleb Connolly | 89a90d0 | 2023-12-05 13:46:48 +0000 | [diff] [blame] | 71 | state = button_get_state(btn); |
| 72 | if (state == BUTTON_ON) { |
Stephan Gerhold | a0d3b95 | 2021-07-14 10:56:25 +0200 | [diff] [blame] | 73 | env_set("preboot", "setenv preboot; fastboot 0"); |
Caleb Connolly | 89a90d0 | 2023-12-05 13:46:48 +0000 | [diff] [blame] | 74 | printf("vol_down pressed - Starting fastboot.\n"); |
Mateusz Kulikowski | ee5e70d | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | return 0; |
| 78 | } |
Jorge Ramirez-Ortiz | 2cd3db9 | 2018-01-10 11:34:35 +0100 | [diff] [blame] | 79 | |
| 80 | int board_init(void) |
| 81 | { |
Jorge Ramirez-Ortiz | 2cd3db9 | 2018-01-10 11:34:35 +0100 | [diff] [blame] | 82 | return 0; |
| 83 | } |
| 84 | |
Ramon Fried | 63596f0 | 2018-09-21 13:35:46 +0300 | [diff] [blame] | 85 | int board_late_init(void) |
| 86 | { |
| 87 | char serial[16]; |
| 88 | |
| 89 | memset(serial, 0, 16); |
| 90 | snprintf(serial, 13, "%x", msm_board_serial()); |
| 91 | env_set("serial#", serial); |
| 92 | return 0; |
| 93 | } |
| 94 | |
Ramon Fried | e82a31c | 2018-08-03 16:25:37 +0300 | [diff] [blame] | 95 | /* Fixup of DTB for Linux Kernel |
| 96 | * 1. Fixup installed DRAM. |
| 97 | * 2. Fixup WLAN/BT Mac address: |
| 98 | * First, check if MAC addresses for WLAN/BT exists as environemnt |
| 99 | * variables wlanaddr,btaddr. if not, generate a unique address. |
| 100 | */ |
| 101 | |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 102 | int ft_board_setup(void *blob, struct bd_info *bd) |
Jorge Ramirez-Ortiz | 2cd3db9 | 2018-01-10 11:34:35 +0100 | [diff] [blame] | 103 | { |
Ramon Fried | e82a31c | 2018-08-03 16:25:37 +0300 | [diff] [blame] | 104 | u8 mac[ARP_HLEN]; |
| 105 | |
| 106 | msm_fixup_memory(blob); |
| 107 | |
| 108 | if (!eth_env_get_enetaddr("wlanaddr", mac)) { |
| 109 | msm_generate_mac_addr(mac); |
Jorge Ramirez-Ortiz | f44f301 | 2018-01-10 11:34:38 +0100 | [diff] [blame] | 110 | }; |
| 111 | |
Ramon Fried | e82a31c | 2018-08-03 16:25:37 +0300 | [diff] [blame] | 112 | do_fixup_by_compat(blob, "qcom,wcnss-wlan", |
| 113 | "local-mac-address", mac, ARP_HLEN, 1); |
Jorge Ramirez-Ortiz | 2cd3db9 | 2018-01-10 11:34:35 +0100 | [diff] [blame] | 114 | |
Jorge Ramirez-Ortiz | 2cd3db9 | 2018-01-10 11:34:35 +0100 | [diff] [blame] | 115 | |
Ramon Fried | e82a31c | 2018-08-03 16:25:37 +0300 | [diff] [blame] | 116 | if (!eth_env_get_enetaddr("btaddr", mac)) { |
| 117 | msm_generate_mac_addr(mac); |
| 118 | |
| 119 | /* The BD address is same as WLAN MAC address but with |
| 120 | * least significant bit flipped. |
| 121 | */ |
| 122 | mac[0] ^= 0x01; |
| 123 | }; |
Ramon Fried | 80654968 | 2018-07-31 12:29:58 +0300 | [diff] [blame] | 124 | |
Ramon Fried | e82a31c | 2018-08-03 16:25:37 +0300 | [diff] [blame] | 125 | do_fixup_by_compat(blob, "qcom,wcnss-bt", |
| 126 | "local-bd-address", mac, ARP_HLEN, 1); |
Jorge Ramirez-Ortiz | 2cd3db9 | 2018-01-10 11:34:35 +0100 | [diff] [blame] | 127 | return 0; |
| 128 | } |
Jorge Ramirez-Ortiz | 4154c9e | 2018-01-10 11:34:36 +0100 | [diff] [blame] | 129 | |
Harald Seiler | 6f14d5f | 2020-12-15 16:47:52 +0100 | [diff] [blame] | 130 | void reset_cpu(void) |
Jorge Ramirez-Ortiz | 4154c9e | 2018-01-10 11:34:36 +0100 | [diff] [blame] | 131 | { |
| 132 | psci_system_reset(); |
| 133 | } |