blob: a501ab44eab2403327529732c6dcc57b9fdaad2e [file] [log] [blame]
Konstantin Porotchkin031fa072018-02-26 16:08:26 +02001/*
2 * Copyright (C) 2018 Marvell International Ltd.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 * https://spdx.org/licenses
6 */
7
8/* Driver for thermal unit located in Marvell ARMADA 8K and compatible SoCs */
9
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000010#include <common/debug.h>
11#include <drivers/marvell/thermal.h>
Konstantin Porotchkin031fa072018-02-26 16:08:26 +020012
13int marvell_thermal_init(struct tsen_config *tsen_cfg)
14{
15 if (tsen_cfg->tsen_ready == 1) {
16 INFO("thermal sensor is already initialized\n");
17 return 0;
18 }
19
20 if (tsen_cfg->ptr_tsen_probe == NULL) {
21 ERROR("initial thermal sensor configuration is missing\n");
22 return -1;
23 }
24
25 if (tsen_cfg->ptr_tsen_probe(tsen_cfg)) {
26 ERROR("thermal sensor initialization failed\n");
27 return -1;
28 }
29
30 VERBOSE("thermal sensor was initialized\n");
31
32 return 0;
33}
34
35int marvell_thermal_read(struct tsen_config *tsen_cfg, int *temp)
36{
37 if (temp == NULL) {
38 ERROR("NULL pointer for temperature read\n");
39 return -1;
40 }
41
42 if (tsen_cfg->ptr_tsen_read == NULL ||
43 tsen_cfg->tsen_ready == 0) {
44 ERROR("thermal sensor was not initialized\n");
45 return -1;
46 }
47
48 if (tsen_cfg->ptr_tsen_read(tsen_cfg, temp)) {
49 ERROR("temperature read failed\n");
50 return -1;
51 }
52
53 return 0;
54}