Christophe Leroy | 42c709d | 2024-04-02 18:55:31 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * TI LM74 temperature sensor driver |
| 4 | * |
| 5 | * Copyright (C) 2024 CS GROUP France |
| 6 | * |
| 7 | */ |
| 8 | |
| 9 | #include <dm.h> |
| 10 | #include <thermal.h> |
| 11 | #include <spi.h> |
| 12 | |
| 13 | static int ti_lm74_get_temp(struct udevice *dev, int *temp) |
| 14 | { |
| 15 | char buf[2]; |
| 16 | s16 raw; |
| 17 | int ret; |
| 18 | |
| 19 | ret = dm_spi_claim_bus(dev); |
| 20 | if (ret) |
| 21 | return ret; |
| 22 | |
| 23 | ret = dm_spi_xfer(dev, 16, NULL, buf, SPI_XFER_BEGIN | SPI_XFER_END); |
| 24 | |
| 25 | dm_spi_release_bus(dev); |
| 26 | if (ret) |
| 27 | return ret; |
| 28 | |
| 29 | raw = ((buf[0] << 8) + buf[1]) >> 3; |
| 30 | |
| 31 | *temp = (((int)raw * 125) + 1000) / 2000; |
| 32 | |
| 33 | return 0; |
| 34 | } |
| 35 | |
| 36 | static struct dm_thermal_ops ti_lm74_ops = { |
| 37 | .get_temp = ti_lm74_get_temp, |
| 38 | }; |
| 39 | |
| 40 | static const struct udevice_id of_ti_lm74_match[] = { |
| 41 | { |
| 42 | .compatible = "ti,lm74", |
| 43 | }, |
| 44 | {}, |
| 45 | }; |
| 46 | |
| 47 | U_BOOT_DRIVER(ti_bandgap_thermal) = { |
| 48 | .name = "ti_lm74_thermal", |
| 49 | .id = UCLASS_THERMAL, |
| 50 | .ops = &ti_lm74_ops, |
| 51 | .of_match = of_ti_lm74_match, |
| 52 | }; |