drivers/thermal/st/st_thermal_memmap.c
Source file repositories/reference/linux-study-clean/drivers/thermal/st/st_thermal_memmap.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/thermal/st/st_thermal_memmap.c- Extension
.c- Size
- 5273 bytes
- Lines
- 185
- Domain
- Driver Families
- Bucket
- drivers/thermal
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/of.hlinux/module.hst_thermal.h
Detected Declarations
function st_mmap_thermal_trip_handlerfunction st_mmap_power_ctrlfunction st_mmap_alloc_regfieldsfunction st_mmap_enable_irqfunction st_mmap_register_enable_irqfunction st_mmap_regmap_initfunction st_mmap_probefunction st_mmap_remove
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* ST Thermal Sensor Driver for memory mapped sensors.
* Author: Ajit Pal Singh <ajitpal.singh@st.com>
*
* Copyright (C) 2003-2014 STMicroelectronics (R&D) Limited
*/
#include <linux/of.h>
#include <linux/module.h>
#include "st_thermal.h"
#define STIH416_MPE_CONF 0x0
#define STIH416_MPE_STATUS 0x4
#define STIH416_MPE_INT_THRESH 0x8
#define STIH416_MPE_INT_EN 0xC
/* Power control bits for the memory mapped thermal sensor */
#define THERMAL_PDN BIT(4)
#define THERMAL_SRSTN BIT(10)
static const struct reg_field st_mmap_thermal_regfields[MAX_REGFIELDS] = {
/*
* According to the STIH416 MPE temp sensor data sheet -
* the PDN (Power Down Bit) and SRSTN (Soft Reset Bit) need to be
* written simultaneously for powering on and off the temperature
* sensor. regmap_update_bits() will be used to update the register.
*/
[INT_THRESH_HI] = REG_FIELD(STIH416_MPE_INT_THRESH, 0, 7),
[DCORRECT] = REG_FIELD(STIH416_MPE_CONF, 5, 9),
[OVERFLOW] = REG_FIELD(STIH416_MPE_STATUS, 9, 9),
[DATA] = REG_FIELD(STIH416_MPE_STATUS, 11, 18),
[INT_ENABLE] = REG_FIELD(STIH416_MPE_INT_EN, 0, 0),
};
static irqreturn_t st_mmap_thermal_trip_handler(int irq, void *sdata)
{
struct st_thermal_sensor *sensor = sdata;
thermal_zone_device_update(sensor->thermal_dev,
THERMAL_EVENT_UNSPECIFIED);
return IRQ_HANDLED;
}
/* Private ops for the Memory Mapped based thermal sensors */
static int st_mmap_power_ctrl(struct st_thermal_sensor *sensor,
enum st_thermal_power_state power_state)
{
const unsigned int mask = (THERMAL_PDN | THERMAL_SRSTN);
const unsigned int val = power_state ? mask : 0;
return regmap_update_bits(sensor->regmap, STIH416_MPE_CONF, mask, val);
}
static int st_mmap_alloc_regfields(struct st_thermal_sensor *sensor)
{
struct device *dev = sensor->dev;
struct regmap *regmap = sensor->regmap;
const struct reg_field *reg_fields = sensor->cdata->reg_fields;
sensor->int_thresh_hi = devm_regmap_field_alloc(dev, regmap,
reg_fields[INT_THRESH_HI]);
sensor->int_enable = devm_regmap_field_alloc(dev, regmap,
reg_fields[INT_ENABLE]);
if (IS_ERR(sensor->int_thresh_hi) || IS_ERR(sensor->int_enable)) {
dev_err(dev, "failed to alloc mmap regfields\n");
return -EINVAL;
}
return 0;
}
static int st_mmap_enable_irq(struct st_thermal_sensor *sensor)
{
int ret;
/* Set upper critical threshold */
ret = regmap_field_write(sensor->int_thresh_hi,
sensor->cdata->crit_temp -
sensor->cdata->temp_adjust_val);
if (ret)
return ret;
return regmap_field_write(sensor->int_enable, 1);
}
static int st_mmap_register_enable_irq(struct st_thermal_sensor *sensor)
Annotation
- Immediate include surface: `linux/of.h`, `linux/module.h`, `st_thermal.h`.
- Detected declarations: `function st_mmap_thermal_trip_handler`, `function st_mmap_power_ctrl`, `function st_mmap_alloc_regfields`, `function st_mmap_enable_irq`, `function st_mmap_register_enable_irq`, `function st_mmap_regmap_init`, `function st_mmap_probe`, `function st_mmap_remove`.
- Atlas domain: Driver Families / drivers/thermal.
- Implementation status: source implementation candidate.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.