1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * ESWIN EIC7700 Voltage, Temperature sensor driver 4 * 5 * Copyright 2026, Beijing ESWIN Computing Technology Co., Ltd. 6 */ 7 #ifndef __HWMON_EIC7700_PVT_H__ 8 #define __HWMON_EIC7700_PVT_H__ 9 10 #include <linux/completion.h> 11 #include <linux/hwmon.h> 12 #include <linux/kernel.h> 13 #include <linux/time.h> 14 15 /* ESWIN EIC7700 PVT registers and their bitfields */ 16 #define PVT_TRIM 0x04 17 #define PVT_MODE 0x08 18 #define PVT_MODE_MASK GENMASK(2, 0) 19 #define PVT_CTRL_MODE_TEMP 0x0 20 #define PVT_CTRL_MODE_VOLT 0x4 21 #define PVT_ENA 0x0c 22 #define PVT_ENA_EN BIT(0) 23 #define PVT_INT 0x10 24 #define PVT_INT_STAT BIT(0) 25 #define PVT_INT_CLR BIT(1) 26 #define PVT_DATA 0x14 27 #define PVT_DATA_OUT GENMASK(9, 0) 28 29 /* 30 * PVT sensors-related limits and default values 31 * @PVT_TEMP_CHS: Number of temperature hwmon channels. 32 * @PVT_VOLT_CHS: Number of voltage hwmon channels. 33 * @PVT_TRIM_DEF: Default temperature sensor trim value (set a proper value 34 * when one is determined for ESWIN EIC7700 SoC). 35 * @PVT_TOUT_MIN: Minimal timeout between samples in nanoseconds. 36 */ 37 #define PVT_TEMP_CHS 1 38 #define PVT_VOLT_CHS 1 39 #define PVT_TRIM_DEF 0 40 #define PVT_TOUT_MIN (NSEC_PER_SEC / 3000) 41 42 /* 43 * enum pvt_sensor_type - ESWIN EIC7700 PVT sensor types (correspond to each PVT 44 * sampling mode) 45 * @PVT_TEMP: PVT Temperature sensor. 46 * @PVT_VOLT: PVT Voltage sensor. 47 */ 48 enum pvt_sensor_type { 49 PVT_TEMP = 0, 50 PVT_VOLT 51 }; 52 53 #define PVT_CLK_NUM 2 54 55 /* 56 * struct pvt_sensor_info - ESWIN EIC7700 PVT sensor informational structure 57 * @channel: Sensor channel ID. 58 * @label: hwmon sensor label. 59 * @mode: PVT mode corresponding to the channel. 60 * @type: Sensor type. 61 */ 62 struct pvt_sensor_info { 63 int channel; 64 const char *label; 65 u32 mode; 66 enum hwmon_sensor_types type; 67 }; 68 69 #define PVT_SENSOR_INFO(_ch, _label, _type, _mode) \ 70 { \ 71 .channel = _ch, \ 72 .label = _label, \ 73 .mode = PVT_CTRL_MODE_ ##_mode, \ 74 .type = _type, \ 75 } 76 77 /* 78 * struct pvt_hwmon - Eswin EIC7700 PVT private data 79 * @dev: device structure of the PVT platform device. 80 * @hwmon: hwmon device structure. 81 * @regs: pointer to the Eswin EIC7700 PVT registers region. 82 * @irq: PVT events IRQ number. 83 * @clks: PVT clock descriptors. 84 * @data_cache: data cache in raw format. 85 * @conversion: data conversion completion. 86 * @timeout: conversion timeout. 87 */ 88 struct pvt_hwmon { 89 struct device *dev; 90 struct device *hwmon; 91 void __iomem *regs; 92 int irq; 93 struct clk_bulk_data clks[PVT_CLK_NUM]; 94 u32 data_cache; 95 struct completion conversion; 96 ktime_t timeout; 97 }; 98 99 #endif /* __HWMON_EIC7700_PVT_H__ */ 100