Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | // SPDX-License-Identifier: GPL-2.0+ /* * Copyright (C) 2024 PHYTEC Messtechnik GmbH * Author: Daniel Schultz <d.schultz@phytec.de> */ #include <asm/arch/hardware.h> #include "am6_som_detection.h" extern struct phytec_eeprom_data eeprom_data; #if IS_ENABLED(CONFIG_PHYTEC_AM62_SOM_DETECTION) || \ IS_ENABLED(CONFIG_PHYTEC_AM62A_SOM_DETECTION) || \ IS_ENABLED(CONFIG_PHYTEC_AM64_SOM_DETECTION) /* Check if the SoM is actually one of the following products: * - phyCORE-AM62x * - phyCORE-AM62Ax * - phyCORE-AM64x * * Returns 0 in case it's a known SoM. Otherwise, returns -1. */ int phytec_am6_detect(struct phytec_eeprom_data *data) { char *opt; u8 som; if (!data) data = &eeprom_data; /* We cannot do the check for early API revisions */ if (!data->valid || data->payload.api_rev < PHYTEC_API_REV2) return -1; som = data->payload.data.data_api2.som_no; debug("%s: som id: %u\n", __func__, som); opt = phytec_get_opt(data); if (!opt) return -1; if (som == PHYTEC_AM62X_SOM && soc_is_am62x()) return 0; if (som == PHYTEC_AM62AX_SOM && soc_is_am62ax()) return 0; if (som == PHYTEC_AM64X_SOM && soc_is_am64x()) return 0; return -1; } static u8 phytec_check_opt(struct phytec_eeprom_data *data, u8 option) { char *opt; if (!data) data = &eeprom_data; if (!data->valid || data->payload.api_rev < PHYTEC_API_REV2) return PHYTEC_EEPROM_INVAL; if (option > 8) return PHYTEC_EEPROM_INVAL; opt = phytec_get_opt(data); if (opt) return PHYTEC_GET_OPTION(opt[option]); return PHYTEC_EEPROM_INVAL; } /* * Reads LPDDR4 ram size from EEPROM. * * returns: * - The size * - PHYTEC_EEPROM_INVAL when the data is invalid. */ u8 __maybe_unused phytec_get_am6_ddr_size(struct phytec_eeprom_data *data) { u8 ddr_id = phytec_check_opt(data, 3); pr_debug("%s: ddr id: %u\n", __func__, ddr_id); return ddr_id; } /* * Reads SPI-NOR flash size and type from EEPROM. * * returns: * - PHYTEC_EEPROM_VALUE_X if no SPI is poulated. * - Otherwise a board depended code for the size. * - PHYTEC_EEPROM_INVAL when the data is invalid. */ u8 __maybe_unused phytec_get_am6_spi(struct phytec_eeprom_data *data) { u8 spi = phytec_check_opt(data, 5); pr_debug("%s: spi: %u\n", __func__, spi); return spi; } /* * Reads Ethernet phy information from EEPROM. * * returns: * - 0x0 no ethernet phy is populated. * - 0x1 if 10/100/1000 MBit Phy is populated. * - PHYTEC_EEPROM_INVAL when the data is invalid. */ u8 __maybe_unused phytec_get_am6_eth(struct phytec_eeprom_data *data) { u8 eth = phytec_check_opt(data, 6); pr_debug("%s: eth: %u\n", __func__, eth); return eth; } /* * Reads RTC information from EEPROM. * * returns: * - 0 if no RTC is poulated. * - 1 if it is populated. * - PHYTEC_EEPROM_INVAL when the data is invalid. */ u8 __maybe_unused phytec_get_am6_rtc(struct phytec_eeprom_data *data) { u8 rtc = phytec_check_opt(data, 7); pr_debug("%s: rtc: %u\n", __func__, rtc); return rtc; } #else inline int __maybe_unused phytec_am6_detect(struct phytec_eeprom_data *data) { return -1; } inline u8 __maybe_unused phytec_get_am6_ddr_size(struct phytec_eeprom_data *data) { return PHYTEC_EEPROM_INVAL; } inline u8 __maybe_unused phytec_get_am6_spi(struct phytec_eeprom_data *data) { return PHYTEC_EEPROM_INVAL; } inline u8 __maybe_unused phytec_get_am6_eth(struct phytec_eeprom_data *data) { return PHYTEC_EEPROM_INVAL; } inline u8 __maybe_unused phytec_get_am6_rtc(struct phytec_eeprom_data *data) { return PHYTEC_EEPROM_INVAL; } #endif |