Konstantin Porotchkin | 031fa07 | 2018-02-26 16:08:26 +0200 | [diff] [blame] | 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 | |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 10 | #include <common/debug.h> |
| 11 | #include <drivers/marvell/thermal.h> |
Konstantin Porotchkin | 031fa07 | 2018-02-26 16:08:26 +0200 | [diff] [blame] | 12 | |
| 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 | |
| 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 | } |