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> |
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> |
Caleb Connolly | 154ed1d | 2024-02-26 17:26:21 +0000 | [diff] [blame] | 11 | #include <dm/pinctrl.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> |
Caleb Connolly | 878ffb6 | 2024-02-26 17:26:22 +0000 | [diff] [blame] | 14 | #include <mmc.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> |
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 | |
Caleb Connolly | 878ffb6 | 2024-02-26 17:26:22 +0000 | [diff] [blame] | 25 | /* UNSTUFF_BITS macro taken from Linux Kernel: drivers/mmc/core/sd.c */ |
| 26 | #define UNSTUFF_BITS(resp, start, size) \ |
| 27 | ({ \ |
| 28 | const int __size = size; \ |
| 29 | const u32 __mask = (__size < 32 ? 1 << __size : 0) - 1; \ |
| 30 | const int __off = 3 - ((start) / 32); \ |
| 31 | const int __shft = (start) & 31; \ |
| 32 | u32 __res; \ |
| 33 | \ |
| 34 | __res = resp[__off] >> __shft; \ |
| 35 | if (__size + __shft > 32) \ |
| 36 | __res |= resp[__off - 1] << ((32 - __shft) % 32); \ |
| 37 | __res & __mask; \ |
| 38 | }) |
| 39 | |
| 40 | static u32 msm_board_serial(void) |
| 41 | { |
| 42 | struct mmc *mmc_dev; |
| 43 | |
| 44 | mmc_dev = find_mmc_device(0); |
| 45 | if (!mmc_dev) |
| 46 | return 0; |
| 47 | |
| 48 | if (mmc_init(mmc_dev)) |
| 49 | return 0; |
| 50 | |
| 51 | return UNSTUFF_BITS(mmc_dev->cid, 16, 32); |
| 52 | } |
| 53 | |
| 54 | static void msm_generate_mac_addr(u8 *mac) |
| 55 | { |
| 56 | /* use locally adminstrated pool */ |
| 57 | mac[0] = 0x02; |
| 58 | mac[1] = 0x00; |
| 59 | |
| 60 | /* |
| 61 | * Put the 32-bit serial number in the last 32-bit of the MAC address. |
| 62 | * Use big endian order so it is consistent with the serial number |
| 63 | * written as a hexadecimal string, e.g. 0x1234abcd -> 02:00:12:34:ab:cd |
| 64 | */ |
| 65 | put_unaligned_be32(msm_board_serial(), &mac[2]); |
| 66 | } |
| 67 | |
Mateusz Kulikowski | ee5e70d | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 68 | /* Check for vol- button - if pressed - stop autoboot */ |
| 69 | int misc_init_r(void) |
| 70 | { |
Caleb Connolly | 89a90d0 | 2023-12-05 13:46:48 +0000 | [diff] [blame] | 71 | struct udevice *btn; |
| 72 | int ret; |
| 73 | enum button_state_t state; |
Mateusz Kulikowski | ee5e70d | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 74 | |
Caleb Connolly | 89a90d0 | 2023-12-05 13:46:48 +0000 | [diff] [blame] | 75 | ret = button_get_by_label("vol_down", &btn); |
Mateusz Kulikowski | ee5e70d | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 76 | if (ret < 0) { |
Caleb Connolly | 89a90d0 | 2023-12-05 13:46:48 +0000 | [diff] [blame] | 77 | printf("Couldn't find power button!\n"); |
| 78 | return ret; |
Mateusz Kulikowski | ee5e70d | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 79 | } |
| 80 | |
Caleb Connolly | 89a90d0 | 2023-12-05 13:46:48 +0000 | [diff] [blame] | 81 | state = button_get_state(btn); |
| 82 | if (state == BUTTON_ON) { |
Stephan Gerhold | a0d3b95 | 2021-07-14 10:56:25 +0200 | [diff] [blame] | 83 | env_set("preboot", "setenv preboot; fastboot 0"); |
Caleb Connolly | 89a90d0 | 2023-12-05 13:46:48 +0000 | [diff] [blame] | 84 | printf("vol_down pressed - Starting fastboot.\n"); |
Mateusz Kulikowski | ee5e70d | 2016-03-31 23:12:33 +0200 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | return 0; |
| 88 | } |
Jorge Ramirez-Ortiz | 2cd3db9 | 2018-01-10 11:34:35 +0100 | [diff] [blame] | 89 | |
Caleb Connolly | 3138566 | 2024-02-26 17:26:25 +0000 | [diff] [blame] | 90 | int qcom_late_init(void) |
Ramon Fried | 63596f0 | 2018-09-21 13:35:46 +0300 | [diff] [blame] | 91 | { |
| 92 | char serial[16]; |
| 93 | |
| 94 | memset(serial, 0, 16); |
| 95 | snprintf(serial, 13, "%x", msm_board_serial()); |
| 96 | env_set("serial#", serial); |
| 97 | return 0; |
| 98 | } |
| 99 | |
Ramon Fried | e82a31c | 2018-08-03 16:25:37 +0300 | [diff] [blame] | 100 | /* Fixup of DTB for Linux Kernel |
| 101 | * 1. Fixup installed DRAM. |
| 102 | * 2. Fixup WLAN/BT Mac address: |
| 103 | * First, check if MAC addresses for WLAN/BT exists as environemnt |
| 104 | * variables wlanaddr,btaddr. if not, generate a unique address. |
| 105 | */ |
| 106 | |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 107 | int ft_board_setup(void *blob, struct bd_info *bd) |
Jorge Ramirez-Ortiz | 2cd3db9 | 2018-01-10 11:34:35 +0100 | [diff] [blame] | 108 | { |
Ramon Fried | e82a31c | 2018-08-03 16:25:37 +0300 | [diff] [blame] | 109 | u8 mac[ARP_HLEN]; |
| 110 | |
Ramon Fried | e82a31c | 2018-08-03 16:25:37 +0300 | [diff] [blame] | 111 | if (!eth_env_get_enetaddr("wlanaddr", mac)) { |
| 112 | msm_generate_mac_addr(mac); |
Jorge Ramirez-Ortiz | f44f301 | 2018-01-10 11:34:38 +0100 | [diff] [blame] | 113 | }; |
| 114 | |
Ramon Fried | e82a31c | 2018-08-03 16:25:37 +0300 | [diff] [blame] | 115 | do_fixup_by_compat(blob, "qcom,wcnss-wlan", |
| 116 | "local-mac-address", mac, ARP_HLEN, 1); |
Jorge Ramirez-Ortiz | 2cd3db9 | 2018-01-10 11:34:35 +0100 | [diff] [blame] | 117 | |
Jorge Ramirez-Ortiz | 2cd3db9 | 2018-01-10 11:34:35 +0100 | [diff] [blame] | 118 | |
Ramon Fried | e82a31c | 2018-08-03 16:25:37 +0300 | [diff] [blame] | 119 | if (!eth_env_get_enetaddr("btaddr", mac)) { |
| 120 | msm_generate_mac_addr(mac); |
| 121 | |
| 122 | /* The BD address is same as WLAN MAC address but with |
| 123 | * least significant bit flipped. |
| 124 | */ |
| 125 | mac[0] ^= 0x01; |
| 126 | }; |
Ramon Fried | 80654968 | 2018-07-31 12:29:58 +0300 | [diff] [blame] | 127 | |
Ramon Fried | e82a31c | 2018-08-03 16:25:37 +0300 | [diff] [blame] | 128 | do_fixup_by_compat(blob, "qcom,wcnss-bt", |
| 129 | "local-bd-address", mac, ARP_HLEN, 1); |
Jorge Ramirez-Ortiz | 2cd3db9 | 2018-01-10 11:34:35 +0100 | [diff] [blame] | 130 | return 0; |
| 131 | } |