drivers/thermal/qcom/qcom-spmi-temp-alarm.c

Source file repositories/reference/linux-study-clean/drivers/thermal/qcom/qcom-spmi-temp-alarm.c

File Facts

System
Linux kernel
Corpus path
drivers/thermal/qcom/qcom-spmi-temp-alarm.c
Extension
.c
Size
23371 bytes
Lines
907
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.

Dependency Surface

Detected Declarations

Annotated Snippet

struct spmi_temp_alarm_data {
	const struct thermal_zone_device_ops *ops;
	const long (*temp_map)[THRESH_COUNT][STAGE_COUNT];
	int (*sync_thresholds)(struct qpnp_tm_chip *chip);
	int (*get_temp_stage)(struct qpnp_tm_chip *chip);
	int (*configure_trip_temps)(struct qpnp_tm_chip *chip);
};

struct qpnp_tm_chip {
	struct regmap			*map;
	struct device			*dev;
	struct thermal_zone_device	*tz_dev;
	const struct spmi_temp_alarm_data *data;
	unsigned int			subtype;
	long				temp;
	unsigned int			stage;
	unsigned int			base;
	unsigned int			ntrips;
	/* protects .thresh, .stage and chip registers */
	struct mutex			lock;
	bool				initialized;
	bool				require_stage2_shutdown;
	long				temp_thresh_map[STAGE_COUNT];

	struct iio_channel		*adc;
};

/* This array maps from GEN2 alarm state to GEN1 alarm stage */
static const unsigned int alarm_state_map[8] = {0, 1, 1, 2, 2, 3, 3, 3};

static int qpnp_tm_read(struct qpnp_tm_chip *chip, u16 addr, u8 *data)
{
	unsigned int val;
	int ret;

	ret = regmap_read(chip->map, chip->base + addr, &val);
	if (ret < 0)
		return ret;

	*data = val;
	return 0;
}

static int qpnp_tm_write(struct qpnp_tm_chip *chip, u16 addr, u8 data)
{
	return regmap_write(chip->map, chip->base + addr, data);
}

/**
 * qpnp_tm_decode_temp() - return temperature in mC corresponding to the
 *		specified over-temperature stage
 * @chip:		Pointer to the qpnp_tm chip
 * @stage:		Over-temperature stage
 *
 * Return: temperature in mC
 */
static long qpnp_tm_decode_temp(struct qpnp_tm_chip *chip, unsigned int stage)
{
	if (stage == 0 || stage > STAGE_COUNT)
		return 0;

	return chip->temp_thresh_map[stage - 1];
}

/**
 * qpnp_tm_gen1_get_temp_stage() - return over-temperature stage
 * @chip:		Pointer to the qpnp_tm chip
 *
 * Return: stage on success, or errno on failure.
 */
static int qpnp_tm_gen1_get_temp_stage(struct qpnp_tm_chip *chip)
{
	int ret;
	u8 reg;

	ret = qpnp_tm_read(chip, QPNP_TM_REG_STATUS, &reg);
	if (ret < 0)
		return ret;

	return FIELD_GET(STATUS_GEN1_STAGE_MASK, reg);
}

/**
 * qpnp_tm_gen2_get_temp_stage() - return over-temperature stage
 * @chip:		Pointer to the qpnp_tm chip
 *
 * Return: stage on success, or errno on failure.
 */
static int qpnp_tm_gen2_get_temp_stage(struct qpnp_tm_chip *chip)
{

Annotation

Implementation Notes