1 /* 2 * Arm SCP/MCP Software 3 * Copyright (c) 2018-2021, Arm Limited and Contributors. All rights reserved. 4 * 5 * SPDX-License-Identifier: BSD-3-Clause 6 */ 7 8 #include "low_level_access.h" 9 #include "synquacer_common.h" 10 11 #include <sysdef_option.h> 12 13 #include <internal/thermal_sensor.h> 14 15 #include <mod_synquacer_system.h> 16 17 #include <fwk_log.h> 18 #include <fwk_status.h> 19 20 #include <inttypes.h> 21 #include <stdint.h> 22 23 #define DELAY_COUNTER 10 24 thermal_enable(void)25int thermal_enable(void) 26 { 27 int32_t sensor_num = sysdef_option_get_sensor_num(); 28 int32_t i = 0; 29 30 FWK_LOG_INFO("[THERMAL] Thermal enable start"); 31 writel(THERMAL_BASE_ADDRESS + THERMAL_ALLCONFIG_OFFSET, 0); 32 for (i = 0; i < sensor_num; i++) { 33 uint32_t sensor_offset = THERMAL_SENSOR_BASE(i); 34 35 writel(sensor_offset + THERMAL_TS_EN_OFFSET, THERMAL_ENABLE); 36 if (readl(sensor_offset + THERMAL_TS_EN_OFFSET) == 0) { 37 FWK_LOG_INFO( 38 "[THERMAL] Enable individual sensor #%" PRIx32 " fail", i); 39 return FWK_E_DEVICE; 40 } 41 42 writel(sensor_offset + THERMAL_TS_RESET_OFFSET, THERMAL_ENABLE); 43 if (readl(sensor_offset + THERMAL_TS_RESET_OFFSET) == 0) { 44 FWK_LOG_INFO( 45 "[THERMAL] Reset individual sensor #%" PRIx32 " fail", i); 46 return FWK_E_DEVICE; 47 } 48 } 49 50 for (i = 0; i < sensor_num; i++) { 51 uint32_t sensor_offset = THERMAL_SENSOR_BASE(i); 52 int32_t delay_counter; 53 for (delay_counter = 0; delay_counter < DELAY_COUNTER; 54 delay_counter++) { 55 if (readl(sensor_offset + THERMAL_TSDATA_VALID_X_OFFSET) == 1) 56 break; 57 58 synquacer_system_ctx.timer_api->delay( 59 FWK_ID_ELEMENT(FWK_MODULE_IDX_TIMER, 0), 60 MSEC_TO_USEC(1)); 61 } 62 } 63 64 FWK_LOG_INFO("[THERMAL] Thermal enable end"); 65 return FWK_SUCCESS; 66 } 67