1 /*
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 
10 #include <common/debug.h>
11 #include <drivers/marvell/thermal.h>
12 
marvell_thermal_init(struct tsen_config * tsen_cfg)13 int 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 
marvell_thermal_read(struct tsen_config * tsen_cfg,int * temp)35 int 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 }
55