blob: 4698b9d5e3e47a9b0389d9f6bafab9dd6db56a41 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +02002/*
3 * Board init file for Dragonboard 410C
4 *
5 * (C) Copyright 2015 Mateusz Kulikowski <mateusz.kulikowski@gmail.com>
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +02006 */
7
Caleb Connolly89a90d02023-12-05 13:46:48 +00008#include <button.h>
Simon Glassafb02152019-12-28 10:45:01 -07009#include <cpu_func.h>
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020010#include <dm.h>
Caleb Connolly154ed1d2024-02-26 17:26:21 +000011#include <dm/pinctrl.h>
Simon Glass5e6201b2019-08-01 09:46:51 -060012#include <env.h>
Simon Glassa7b51302019-11-14 12:57:46 -070013#include <init.h>
Caleb Connolly878ffb62024-02-26 17:26:22 +000014#include <mmc.h>
Simon Glass274e0b02020-05-10 11:39:56 -060015#include <net.h>
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020016#include <usb.h>
Simon Glass274e0b02020-05-10 11:39:56 -060017#include <asm/cache.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060018#include <asm/global_data.h>
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020019#include <asm/gpio.h>
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +010020#include <fdt_support.h>
Simon Glassdbd79542020-05-10 11:40:11 -060021#include <linux/delay.h>
Mateusz Kulikowskiee5e70d2016-03-31 23:12:33 +020022
23DECLARE_GLOBAL_DATA_PTR;
24
Caleb Connolly878ffb62024-02-26 17:26:22 +000025static u32 msm_board_serial(void)
26{
27 struct mmc *mmc_dev;
28
29 mmc_dev = find_mmc_device(0);
30 if (!mmc_dev)
31 return 0;
32
33 if (mmc_init(mmc_dev))
34 return 0;
35
Stephan Gerholda82aab52025-04-07 18:59:25 +020036 /* MMC serial number */
37 return mmc_dev->cid[2] << 16 | mmc_dev->cid[3] >> 16;
Caleb Connolly878ffb62024-02-26 17:26:22 +000038}
39
40static void msm_generate_mac_addr(u8 *mac)
41{
42 /* use locally adminstrated pool */
43 mac[0] = 0x02;
44 mac[1] = 0x00;
45
46 /*
47 * Put the 32-bit serial number in the last 32-bit of the MAC address.
48 * Use big endian order so it is consistent with the serial number
49 * written as a hexadecimal string, e.g. 0x1234abcd -> 02:00:12:34:ab:cd
50 */
51 put_unaligned_be32(msm_board_serial(), &mac[2]);
52}
53
Caleb Connolly31385662024-02-26 17:26:25 +000054int qcom_late_init(void)
Ramon Fried63596f02018-09-21 13:35:46 +030055{
56 char serial[16];
57
58 memset(serial, 0, 16);
59 snprintf(serial, 13, "%x", msm_board_serial());
60 env_set("serial#", serial);
61 return 0;
62}
63
Stephan Gerhold638d3c52025-04-07 18:59:24 +020064/*
65 * Fixup of DTB for Linux Kernel
66 * 1. Fixup WLAN/BT Mac address:
Ramon Friede82a31c2018-08-03 16:25:37 +030067 * First, check if MAC addresses for WLAN/BT exists as environemnt
68 * variables wlanaddr,btaddr. if not, generate a unique address.
69 */
70
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +090071int ft_board_setup(void *blob, struct bd_info *bd)
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +010072{
Ramon Friede82a31c2018-08-03 16:25:37 +030073 u8 mac[ARP_HLEN];
Stephan Gerhold638d3c52025-04-07 18:59:24 +020074 int i;
Ramon Friede82a31c2018-08-03 16:25:37 +030075
Ramon Friede82a31c2018-08-03 16:25:37 +030076 if (!eth_env_get_enetaddr("wlanaddr", mac)) {
77 msm_generate_mac_addr(mac);
Jorge Ramirez-Ortizf44f3012018-01-10 11:34:38 +010078 };
79
Ramon Friede82a31c2018-08-03 16:25:37 +030080 do_fixup_by_compat(blob, "qcom,wcnss-wlan",
81 "local-mac-address", mac, ARP_HLEN, 1);
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +010082
Ramon Friede82a31c2018-08-03 16:25:37 +030083 if (!eth_env_get_enetaddr("btaddr", mac)) {
84 msm_generate_mac_addr(mac);
85
Stephan Gerhold638d3c52025-04-07 18:59:24 +020086 /*
87 * The BD address is same as WLAN MAC address but with
88 * least significant bit flipped.
89 */
90 mac[ARP_HLEN - 1] ^= 0x01;
Ramon Friede82a31c2018-08-03 16:25:37 +030091 };
Ramon Fried806549682018-07-31 12:29:58 +030092
Stephan Gerhold638d3c52025-04-07 18:59:24 +020093 /*
94 * Reverse array since local-bd-address is formatted with least
95 * significant byte first (little endian).
96 */
97 for (i = 0; i < ARP_HLEN / 2; ++i) {
98 u8 tmp = mac[i];
99
100 mac[i] = mac[ARP_HLEN - 1 - i];
101 mac[ARP_HLEN - 1 - i] = tmp;
102 }
103
Ramon Friede82a31c2018-08-03 16:25:37 +0300104 do_fixup_by_compat(blob, "qcom,wcnss-bt",
105 "local-bd-address", mac, ARP_HLEN, 1);
Jorge Ramirez-Ortiz2cd3db92018-01-10 11:34:35 +0100106 return 0;
107}