Commit 87976ce2 authored by Serge Semin's avatar Serge Semin Committed by Guenter Roeck

hwmon: Add Baikal-T1 PVT sensor driver

Baikal-T1 SoC provides an embedded process, voltage and temperature
sensor to monitor an internal SoC environment (chip temperature, supply
voltage and process monitor) and on time detect critical situations,
which may cause the system instability and even damages. The IP-block
is based on the Analog Bits PVT sensor, but is equipped with a
dedicated control wrapper, which provides a MMIO registers-based access
to the sensor core functionality (APB3-bus based) and exposes an
additional functions like thresholds/data ready interrupts, its status
and masks, measurements timeout. All of these is used to create a hwmon
driver being added to the kernel by this commit.

The driver implements support for the hardware monitoring capabilities
of Baikal-T1 process, voltage and temperature sensors. PVT IP-core
consists of one temperature and four voltage sensors, each of which is
implemented as a dedicated hwmon channel config.

The driver can optionally provide the hwmon alarms for each sensor the
PVT controller supports. The alarms functionality is made compile-time
configurable due to the hardware interface implementation peculiarity,
which is connected with an ability to convert data from only one sensor
at a time. Additional limitation is that the controller performs the
thresholds checking synchronously with the data conversion procedure.
Due to these limitations in order to have the hwmon alarms
automatically detected the driver code must switch from one sensor to
another, read converted data and manually check the threshold status
bits. Depending on the measurements timeout settings this design may
cause additional burden on the system performance. By default if the
alarms kernel config is disabled the data conversion is performed by
the driver on demand when read operation is requested via corresponding
_input-file.
Co-developed-by: default avatarMaxim Kaurkin <maxim.kaurkin@baikalelectronics.ru>
Signed-off-by: default avatarMaxim Kaurkin <maxim.kaurkin@baikalelectronics.ru>
Signed-off-by: default avatarSerge Semin <Sergey.Semin@baikalelectronics.ru>
Cc: Alexey Malahov <Alexey.Malahov@baikalelectronics.ru>
Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Rob Herring <robh+dt@kernel.org>
Cc: linux-mips@vger.kernel.org
Cc: devicetree@vger.kernel.org
Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
parent 1597b374
.. SPDX-License-Identifier: GPL-2.0-only
Kernel driver bt1-pvt
=====================
Supported chips:
* Baikal-T1 PVT sensor (in SoC)
Prefix: 'bt1-pvt'
Addresses scanned: -
Datasheet: Provided by BAIKAL ELECTRONICS upon request and under NDA
Authors:
Maxim Kaurkin <maxim.kaurkin@baikalelectronics.ru>
Serge Semin <Sergey.Semin@baikalelectronics.ru>
Description
-----------
This driver implements support for the hardware monitoring capabilities of the
embedded into Baikal-T1 process, voltage and temperature sensors. PVT IP-core
consists of one temperature and four voltage sensors, which can be used to
monitor the chip internal environment like heating, supply voltage and
transistors performance. The driver can optionally provide the hwmon alarms
for each sensor the PVT controller supports. The alarms functionality is made
compile-time configurable due to the hardware interface implementation
peculiarity, which is connected with an ability to convert data from only one
sensor at a time. Additional limitation is that the controller performs the
thresholds checking synchronously with the data conversion procedure. Due to
these in order to have the hwmon alarms automatically detected the driver code
must switch from one sensor to another, read converted data and manually check
the threshold status bits. Depending on the measurements timeout settings
(update_interval sysfs node value) this design may cause additional burden on
the system performance. So in case if alarms are unnecessary in your system
design it's recommended to have them disabled to prevent the PVT IRQs being
periodically raised to get the data cache/alarms status up to date. By default
in alarm-less configuration the data conversion is performed by the driver
on demand when read operation is requested via corresponding _input-file.
Temperature Monitoring
----------------------
Temperature is measured with 10-bit resolution and reported in millidegree
Celsius. The driver performs all the scaling by itself therefore reports true
temperatures that don't need any user-space adjustments. While the data
translation formulae isn't linear, which gives us non-linear discreteness,
it's close to one, but giving a bit better accuracy for higher temperatures.
The temperature input is mapped as follows (the last column indicates the input
ranges)::
temp1: CPU embedded diode -48.38C - +147.438C
In case if the alarms kernel config is enabled in the driver the temperature input
has associated min and max limits which trigger an alarm when crossed.
Voltage Monitoring
------------------
The voltage inputs are also sampled with 10-bit resolution and reported in
millivolts. But in this case the data translation formulae is linear, which
provides a constant measurements discreteness. The data scaling is also
performed by the driver, so returning true millivolts. The voltage inputs are
mapped as follows (the last column indicates the input ranges)::
in0: VDD (processor core) 0.62V - 1.168V
in1: Low-Vt (low voltage threshold) 0.62V - 1.168V
in2: High-Vt (high voltage threshold) 0.62V - 1.168V
in3: Standard-Vt (standard voltage threshold) 0.62V - 1.168V
In case if the alarms config is enabled in the driver the voltage inputs
have associated min and max limits which trigger an alarm when crossed.
Sysfs Attributes
----------------
Following is a list of all sysfs attributes that the driver provides, their
permissions and a short description:
=============================== ======= =======================================
Name Perm Description
=============================== ======= =======================================
update_interval RW Measurements update interval per
sensor.
temp1_type RO Sensor type (always 1 as CPU embedded
diode).
temp1_label RO CPU Core Temperature sensor.
temp1_input RO Measured temperature in millidegree
Celsius.
temp1_min RW Low limit for temp input.
temp1_max RW High limit for temp input.
temp1_min_alarm RO Temperature input alarm. Returns 1 if
temperature input went below min limit,
0 otherwise.
temp1_max_alarm RO Temperature input alarm. Returns 1 if
temperature input went above max limit,
0 otherwise.
temp1_offset RW Temperature offset in millidegree
Celsius which is added to the
temperature reading by the chip. It can
be used to manually adjust the
temperature measurements within 7.130
degrees Celsius.
in[0-3]_label RO CPU Voltage sensor (either core or
low/high/standard thresholds).
in[0-3]_input RO Measured voltage in millivolts.
in[0-3]_min RW Low limit for voltage input.
in[0-3]_max RW High limit for voltage input.
in[0-3]_min_alarm RO Voltage input alarm. Returns 1 if
voltage input went below min limit,
0 otherwise.
in[0-3]_max_alarm RO Voltage input alarm. Returns 1 if
voltage input went above max limit,
0 otherwise.
=============================== ======= =======================================
...@@ -44,6 +44,7 @@ Hardware Monitoring Kernel Drivers ...@@ -44,6 +44,7 @@ Hardware Monitoring Kernel Drivers
asc7621 asc7621
aspeed-pwm-tacho aspeed-pwm-tacho
bel-pfe bel-pfe
bt1-pvt
coretemp coretemp
da9052 da9052
da9055 da9055
......
...@@ -414,6 +414,31 @@ config SENSORS_ATXP1 ...@@ -414,6 +414,31 @@ config SENSORS_ATXP1
This driver can also be built as a module. If so, the module This driver can also be built as a module. If so, the module
will be called atxp1. will be called atxp1.
config SENSORS_BT1_PVT
tristate "Baikal-T1 Process, Voltage, Temperature sensor driver"
depends on MIPS_BAIKAL_T1 || COMPILE_TEST
help
If you say yes here you get support for Baikal-T1 PVT sensor
embedded into the SoC.
This driver can also be built as a module. If so, the module will be
called bt1-pvt.
config SENSORS_BT1_PVT_ALARMS
bool "Enable Baikal-T1 PVT sensor alarms"
depends on SENSORS_BT1_PVT
help
Baikal-T1 PVT IP-block provides threshold registers for each
supported sensor. But the corresponding interrupts might be
generated by the thresholds comparator only in synchronization with
a data conversion. Additionally there is only one sensor data can
be converted at a time. All of these makes the interface impossible
to be used for the hwmon alarms implementation without periodic
switch between the PVT sensors. By default the data conversion is
performed on demand from the user-space. If this config is enabled
the data conversion will be periodically performed and the data will be
saved in the internal driver cache.
config SENSORS_DRIVETEMP config SENSORS_DRIVETEMP
tristate "Hard disk drives with temperature sensors" tristate "Hard disk drives with temperature sensors"
depends on SCSI && ATA depends on SCSI && ATA
......
...@@ -54,6 +54,7 @@ obj-$(CONFIG_SENSORS_ASC7621) += asc7621.o ...@@ -54,6 +54,7 @@ obj-$(CONFIG_SENSORS_ASC7621) += asc7621.o
obj-$(CONFIG_SENSORS_ASPEED) += aspeed-pwm-tacho.o obj-$(CONFIG_SENSORS_ASPEED) += aspeed-pwm-tacho.o
obj-$(CONFIG_SENSORS_ATXP1) += atxp1.o obj-$(CONFIG_SENSORS_ATXP1) += atxp1.o
obj-$(CONFIG_SENSORS_AXI_FAN_CONTROL) += axi-fan-control.o obj-$(CONFIG_SENSORS_AXI_FAN_CONTROL) += axi-fan-control.o
obj-$(CONFIG_SENSORS_BT1_PVT) += bt1-pvt.o
obj-$(CONFIG_SENSORS_CORETEMP) += coretemp.o obj-$(CONFIG_SENSORS_CORETEMP) += coretemp.o
obj-$(CONFIG_SENSORS_DA9052_ADC)+= da9052-hwmon.o obj-$(CONFIG_SENSORS_DA9052_ADC)+= da9052-hwmon.o
obj-$(CONFIG_SENSORS_DA9055)+= da9055-hwmon.o obj-$(CONFIG_SENSORS_DA9055)+= da9055-hwmon.o
......
This diff is collapsed.
/* SPDX-License-Identifier: GPL-2.0-only */
/*
* Copyright (C) 2020 BAIKAL ELECTRONICS, JSC
*
* Baikal-T1 Process, Voltage, Temperature sensor driver
*/
#ifndef __HWMON_BT1_PVT_H__
#define __HWMON_BT1_PVT_H__
#include <linux/completion.h>
#include <linux/hwmon.h>
#include <linux/kernel.h>
#include <linux/mutex.h>
#include <linux/seqlock.h>
/* Baikal-T1 PVT registers and their bitfields */
#define PVT_CTRL 0x00
#define PVT_CTRL_EN BIT(0)
#define PVT_CTRL_MODE_FLD 1
#define PVT_CTRL_MODE_MASK GENMASK(3, PVT_CTRL_MODE_FLD)
#define PVT_CTRL_MODE_TEMP 0x0
#define PVT_CTRL_MODE_VOLT 0x1
#define PVT_CTRL_MODE_LVT 0x2
#define PVT_CTRL_MODE_HVT 0x4
#define PVT_CTRL_MODE_SVT 0x6
#define PVT_CTRL_TRIM_FLD 4
#define PVT_CTRL_TRIM_MASK GENMASK(8, PVT_CTRL_TRIM_FLD)
#define PVT_DATA 0x04
#define PVT_DATA_VALID BIT(10)
#define PVT_DATA_DATA_FLD 0
#define PVT_DATA_DATA_MASK GENMASK(9, PVT_DATA_DATA_FLD)
#define PVT_TTHRES 0x08
#define PVT_VTHRES 0x0C
#define PVT_LTHRES 0x10
#define PVT_HTHRES 0x14
#define PVT_STHRES 0x18
#define PVT_THRES_LO_FLD 0
#define PVT_THRES_LO_MASK GENMASK(9, PVT_THRES_LO_FLD)
#define PVT_THRES_HI_FLD 10
#define PVT_THRES_HI_MASK GENMASK(19, PVT_THRES_HI_FLD)
#define PVT_TTIMEOUT 0x1C
#define PVT_INTR_STAT 0x20
#define PVT_INTR_MASK 0x24
#define PVT_RAW_INTR_STAT 0x28
#define PVT_INTR_DVALID BIT(0)
#define PVT_INTR_TTHRES_LO BIT(1)
#define PVT_INTR_TTHRES_HI BIT(2)
#define PVT_INTR_VTHRES_LO BIT(3)
#define PVT_INTR_VTHRES_HI BIT(4)
#define PVT_INTR_LTHRES_LO BIT(5)
#define PVT_INTR_LTHRES_HI BIT(6)
#define PVT_INTR_HTHRES_LO BIT(7)
#define PVT_INTR_HTHRES_HI BIT(8)
#define PVT_INTR_STHRES_LO BIT(9)
#define PVT_INTR_STHRES_HI BIT(10)
#define PVT_INTR_ALL GENMASK(10, 0)
#define PVT_CLR_INTR 0x2C
/*
* PVT sensors-related limits and default values
* @PVT_TEMP_MIN: Minimal temperature in millidegrees of Celsius.
* @PVT_TEMP_MAX: Maximal temperature in millidegrees of Celsius.
* @PVT_TEMP_CHS: Number of temperature hwmon channels.
* @PVT_VOLT_MIN: Minimal voltage in mV.
* @PVT_VOLT_MAX: Maximal voltage in mV.
* @PVT_VOLT_CHS: Number of voltage hwmon channels.
* @PVT_DATA_MIN: Minimal PVT raw data value.
* @PVT_DATA_MAX: Maximal PVT raw data value.
* @PVT_TRIM_MIN: Minimal temperature sensor trim value.
* @PVT_TRIM_MAX: Maximal temperature sensor trim value.
* @PVT_TRIM_DEF: Default temperature sensor trim value (set a proper value
* when one is determined for Baikal-T1 SoC).
* @PVT_TRIM_TEMP: Maximum temperature encoded by the trim factor.
* @PVT_TRIM_STEP: Temperature stride corresponding to the trim value.
* @PVT_TOUT_MIN: Minimal timeout between samples in nanoseconds.
* @PVT_TOUT_DEF: Default data measurements timeout. In case if alarms are
* activated the PVT IRQ is enabled to be raised after each
* conversion in order to have the thresholds checked and the
* converted value cached. Too frequent conversions may cause
* the system CPU overload. Lets set the 50ms delay between
* them by default to prevent this.
*/
#define PVT_TEMP_MIN -48380L
#define PVT_TEMP_MAX 147438L
#define PVT_TEMP_CHS 1
#define PVT_VOLT_MIN 620L
#define PVT_VOLT_MAX 1168L
#define PVT_VOLT_CHS 4
#define PVT_DATA_MIN 0
#define PVT_DATA_MAX (PVT_DATA_DATA_MASK >> PVT_DATA_DATA_FLD)
#define PVT_TRIM_MIN 0
#define PVT_TRIM_MAX (PVT_CTRL_TRIM_MASK >> PVT_CTRL_TRIM_FLD)
#define PVT_TRIM_TEMP 7130
#define PVT_TRIM_STEP (PVT_TRIM_TEMP / PVT_TRIM_MAX)
#define PVT_TRIM_DEF 0
#define PVT_TOUT_MIN (NSEC_PER_SEC / 3000)
#if defined(CONFIG_SENSORS_BT1_PVT_ALARMS)
# define PVT_TOUT_DEF 60000
#else
# define PVT_TOUT_DEF 0
#endif
/*
* enum pvt_sensor_type - Baikal-T1 PVT sensor types (correspond to each PVT
* sampling mode)
* @PVT_SENSOR*: helpers to traverse the sensors in loops.
* @PVT_TEMP: PVT Temperature sensor.
* @PVT_VOLT: PVT Voltage sensor.
* @PVT_LVT: PVT Low-Voltage threshold sensor.
* @PVT_HVT: PVT High-Voltage threshold sensor.
* @PVT_SVT: PVT Standard-Voltage threshold sensor.
*/
enum pvt_sensor_type {
PVT_SENSOR_FIRST,
PVT_TEMP = PVT_SENSOR_FIRST,
PVT_VOLT,
PVT_LVT,
PVT_HVT,
PVT_SVT,
PVT_SENSOR_LAST = PVT_SVT,
PVT_SENSORS_NUM
};
/*
* enum pvt_clock_type - Baikal-T1 PVT clocks.
* @PVT_CLOCK_APB: APB clock.
* @PVT_CLOCK_REF: PVT reference clock.
*/
enum pvt_clock_type {
PVT_CLOCK_APB,
PVT_CLOCK_REF,
PVT_CLOCK_NUM
};
/*
* struct pvt_sensor_info - Baikal-T1 PVT sensor informational structure
* @channel: Sensor channel ID.
* @label: hwmon sensor label.
* @mode: PVT mode corresponding to the channel.
* @thres_base: upper and lower threshold values of the sensor.
* @thres_sts_lo: low threshold status bitfield.
* @thres_sts_hi: high threshold status bitfield.
* @type: Sensor type.
* @attr_min_alarm: Min alarm attribute ID.
* @attr_min_alarm: Max alarm attribute ID.
*/
struct pvt_sensor_info {
int channel;
const char *label;
u32 mode;
unsigned long thres_base;
u32 thres_sts_lo;
u32 thres_sts_hi;
enum hwmon_sensor_types type;
u32 attr_min_alarm;
u32 attr_max_alarm;
};
#define PVT_SENSOR_INFO(_ch, _label, _type, _mode, _thres) \
{ \
.channel = _ch, \
.label = _label, \
.mode = PVT_CTRL_MODE_ ##_mode, \
.thres_base = PVT_ ##_thres, \
.thres_sts_lo = PVT_INTR_ ##_thres## _LO, \
.thres_sts_hi = PVT_INTR_ ##_thres## _HI, \
.type = _type, \
.attr_min_alarm = _type## _min, \
.attr_max_alarm = _type## _max, \
}
/*
* struct pvt_cache - PVT sensors data cache
* @data: data cache in raw format.
* @thres_sts_lo: low threshold status saved on the previous data conversion.
* @thres_sts_hi: high threshold status saved on the previous data conversion.
* @data_seqlock: cached data seq-lock.
* @conversion: data conversion completion.
*/
struct pvt_cache {
u32 data;
#if defined(CONFIG_SENSORS_BT1_PVT_ALARMS)
seqlock_t data_seqlock;
u32 thres_sts_lo;
u32 thres_sts_hi;
#else
struct completion conversion;
#endif
};
/*
* struct pvt_hwmon - Baikal-T1 PVT private data
* @dev: device structure of the PVT platform device.
* @hwmon: hwmon device structure.
* @regs: pointer to the Baikal-T1 PVT registers region.
* @irq: PVT events IRQ number.
* @clks: Array of the PVT clocks descriptor (APB/ref clocks).
* @ref_clk: Pointer to the reference clocks descriptor.
* @iface_mtx: Generic interface mutex (used to lock the alarm registers
* when the alarms enabled, or the data conversion interface
* if alarms are disabled).
* @sensor: current PVT sensor the data conversion is being performed for.
* @cache: data cache descriptor.
*/
struct pvt_hwmon {
struct device *dev;
struct device *hwmon;
void __iomem *regs;
int irq;
struct clk_bulk_data clks[PVT_CLOCK_NUM];
struct mutex iface_mtx;
enum pvt_sensor_type sensor;
struct pvt_cache cache[PVT_SENSORS_NUM];
};
/*
* struct pvt_poly_term - a term descriptor of the PVT data translation
* polynomial
* @deg: degree of the term.
* @coef: multiplication factor of the term.
* @divider: distributed divider per each degree.
* @divider_leftover: divider leftover, which couldn't be redistributed.
*/
struct pvt_poly_term {
unsigned int deg;
long coef;
long divider;
long divider_leftover;
};
/*
* struct pvt_poly - PVT data translation polynomial descriptor
* @total_divider: total data divider.
* @terms: polynomial terms up to a free one.
*/
struct pvt_poly {
long total_divider;
struct pvt_poly_term terms[];
};
#endif /* __HWMON_BT1_PVT_H__ */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment