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