mirror of
https://github.com/torvalds/linux.git
synced 2026-09-24 06:24:02 +02:00
Add the core driver and MMIO platform driver for the AMD/Xilinx Versal System Monitor (SysMon) block. The SysMon block resides in the platform management controller (PMC) and provides on-chip voltage and temperature monitoring through a 10-bit, 200 kSPS ADC. It can monitor up to 160 voltage channels and 64 temperature satellites distributed across the SoC, with a consistent sample rate of 8 kSPS per channel regardless of how many channels are enabled. The hardware also provides four aggregate temperature registers that are always present regardless of the device tree configuration: the current max and min across all active satellites, and the peak and trough values recorded since the last hardware reset. The driver is split into two compilation units: - versal-sysmon-core: Channel parsing, IIO registration, read_raw - versal-sysmon: MMIO platform driver with custom regmap accessors Voltage results are stored in a 19-bit modified floating-point format and converted to millivolts. Temperature results are stored in Q8.7 signed fixed-point Celsius format and converted to millicelsius. The MMIO regmap backend uses a custom reg_write accessor that automatically unlocks the NPI (NoC programming interface) lock register before each write, as required by the hardware. The regmap is configured with fast_io since the underlying MMIO accessors are safe to call from atomic context. Co-developed-by: Michal Simek <michal.simek@amd.com> Signed-off-by: Michal Simek <michal.simek@amd.com> Signed-off-by: Salih Erim <salih.erim@amd.com> Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
93 lines
2.2 KiB
C
93 lines
2.2 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/*
|
|
* AMD Versal SysMon MMIO platform driver
|
|
*
|
|
* Copyright (C) 2019 - 2022, Xilinx, Inc.
|
|
* Copyright (C) 2022 - 2026, Advanced Micro Devices, Inc.
|
|
*/
|
|
|
|
#include <linux/err.h>
|
|
#include <linux/io.h>
|
|
#include <linux/mod_devicetable.h>
|
|
#include <linux/module.h>
|
|
#include <linux/platform_device.h>
|
|
#include <linux/regmap.h>
|
|
#include <linux/types.h>
|
|
|
|
#include "versal-sysmon.h"
|
|
|
|
struct sysmon_mmio {
|
|
void __iomem *base;
|
|
};
|
|
|
|
static int sysmon_mmio_reg_read(void *context, unsigned int reg, unsigned int *val)
|
|
{
|
|
struct sysmon_mmio *mmio = context;
|
|
|
|
*val = readl(mmio->base + reg);
|
|
return 0;
|
|
}
|
|
|
|
static int sysmon_mmio_reg_write(void *context, unsigned int reg, unsigned int val)
|
|
{
|
|
struct sysmon_mmio *mmio = context;
|
|
|
|
/* NPI must be unlocked before any register write except to NPI_LOCK */
|
|
if (reg != SYSMON_NPI_LOCK)
|
|
writel(SYSMON_NPI_UNLOCK_CODE, mmio->base + SYSMON_NPI_LOCK);
|
|
writel(val, mmio->base + reg);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static const struct regmap_config sysmon_mmio_regmap_config = {
|
|
.reg_bits = 32,
|
|
.val_bits = 32,
|
|
.reg_stride = SYSMON_REG_STRIDE,
|
|
.max_register = SYSMON_MAX_REG,
|
|
.reg_read = sysmon_mmio_reg_read,
|
|
.reg_write = sysmon_mmio_reg_write,
|
|
.fast_io = true,
|
|
};
|
|
|
|
static int sysmon_platform_probe(struct platform_device *pdev)
|
|
{
|
|
struct device *dev = &pdev->dev;
|
|
struct sysmon_mmio *mmio;
|
|
struct regmap *regmap;
|
|
|
|
mmio = devm_kzalloc(dev, sizeof(*mmio), GFP_KERNEL);
|
|
if (!mmio)
|
|
return -ENOMEM;
|
|
|
|
mmio->base = devm_platform_ioremap_resource(pdev, 0);
|
|
if (IS_ERR(mmio->base))
|
|
return PTR_ERR(mmio->base);
|
|
|
|
regmap = devm_regmap_init(dev, NULL, mmio, &sysmon_mmio_regmap_config);
|
|
if (IS_ERR(regmap))
|
|
return PTR_ERR(regmap);
|
|
|
|
return devm_versal_sysmon_core_probe(dev, regmap);
|
|
}
|
|
|
|
static const struct of_device_id sysmon_of_match_table[] = {
|
|
{ .compatible = "xlnx,versal-sysmon" },
|
|
{ }
|
|
};
|
|
MODULE_DEVICE_TABLE(of, sysmon_of_match_table);
|
|
|
|
static struct platform_driver sysmon_platform_driver = {
|
|
.probe = sysmon_platform_probe,
|
|
.driver = {
|
|
.name = "versal-sysmon",
|
|
.of_match_table = sysmon_of_match_table,
|
|
},
|
|
};
|
|
module_platform_driver(sysmon_platform_driver);
|
|
|
|
MODULE_LICENSE("GPL");
|
|
MODULE_DESCRIPTION("AMD Versal SysMon Platform Driver");
|
|
MODULE_IMPORT_NS("VERSAL_SYSMON");
|
|
MODULE_AUTHOR("Salih Erim <salih.erim@amd.com>");
|