drivers/thermal/ti-soc-thermal/ti-bandgap.c
Source file repositories/reference/linux-study-clean/drivers/thermal/ti-soc-thermal/ti-bandgap.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/thermal/ti-soc-thermal/ti-bandgap.c- Extension
.c- Size
- 33826 bytes
- Lines
- 1298
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/clk.hlinux/cpu_pm.hlinux/device.hlinux/err.hlinux/export.hlinux/gpio/consumer.hlinux/init.hlinux/interrupt.hlinux/io.hlinux/iopoll.hlinux/kernel.hlinux/module.hlinux/of.hlinux/of_device.hlinux/of_irq.hlinux/of_platform.hlinux/platform_device.hlinux/pm.hlinux/pm_runtime.hlinux/reboot.hlinux/spinlock.hlinux/sys_soc.hlinux/types.hti-bandgap.h
Detected Declarations
function ti_bandgap_readlfunction ti_bandgap_writelfunction ti_bandgap_powerfunction ti_errata814_bandgap_read_tempfunction ti_bandgap_read_tempfunction ti_bandgap_talert_irq_handlerfunction ti_bandgap_tshut_irq_handlerfunction ti_bandgap_adc_to_mcelsiusfunction ti_bandgap_validatefunction ti_bandgap_read_counterfunction ti_bandgap_read_counter_delayfunction ti_bandgap_read_update_intervalfunction ti_bandgap_write_counter_delayfunction ti_bandgap_write_counterfunction ti_bandgap_write_update_intervalfunction ti_bandgap_read_temperaturefunction ti_bandgap_set_sensor_datafunction ti_bandgap_get_sensor_datafunction ti_bandgap_force_single_readfunction ti_bandgap_set_continuous_modefunction ti_bandgap_get_trendfunction ti_bandgap_tshut_initfunction ti_bandgap_talert_initfunction ti_bandgap_buildfunction ti_bandgap_probefunction ti_bandgap_removefunction ti_bandgap_save_ctxtfunction ti_bandgap_restore_ctxtfunction ti_bandgap_suspendfunction bandgap_omap_cpu_notifierfunction ti_bandgap_resume
Annotated Snippet
if (t_hot) {
ctrl &= ~tsr->mask_hot_mask;
ctrl |= tsr->mask_cold_mask;
} else if (t_cold) {
ctrl &= ~tsr->mask_cold_mask;
ctrl |= tsr->mask_hot_mask;
}
ti_bandgap_writel(bgp, ctrl, tsr->bgap_mask_ctrl);
dev_dbg(bgp->dev,
"%s: IRQ from %s sensor: hotevent %d coldevent %d\n",
__func__, bgp->conf->sensors[i].domain,
t_hot, t_cold);
/* report temperature to whom may concern */
if (bgp->conf->report_temperature)
bgp->conf->report_temperature(bgp, i);
}
spin_unlock(&bgp->lock);
return IRQ_HANDLED;
}
/**
* ti_bandgap_tshut_irq_handler() - handles Temperature shutdown signal
* @irq: IRQ number
* @data: private data (unused)
*
* This is the Tshut handler. Use it only if bandgap device features
* HAS(TSHUT). If any sensor fires the Tshut signal, we simply shutdown
* the system.
*
* Return: IRQ_HANDLED
*/
static irqreturn_t ti_bandgap_tshut_irq_handler(int irq, void *data)
{
pr_emerg("%s: TSHUT temperature reached. Needs shut down...\n",
__func__);
orderly_poweroff(true);
return IRQ_HANDLED;
}
/*** Helper functions which manipulate conversion ADC <-> mi Celsius ***/
/**
* ti_bandgap_adc_to_mcelsius() - converts an ADC value to mCelsius scale
* @bgp: struct ti_bandgap pointer
* @adc_val: value in ADC representation
* @t: address where to write the resulting temperature in mCelsius
*
* Simple conversion from ADC representation to mCelsius. In case the ADC value
* is out of the ADC conv table range, it returns -ERANGE, 0 on success.
* The conversion table is indexed by the ADC values.
*
* Return: 0 if conversion was successful, else -ERANGE in case the @adc_val
* argument is out of the ADC conv table range.
*/
static
int ti_bandgap_adc_to_mcelsius(struct ti_bandgap *bgp, int adc_val, int *t)
{
const struct ti_bandgap_data *conf = bgp->conf;
/* look up for temperature in the table and return the temperature */
if (adc_val < conf->adc_start_val || adc_val > conf->adc_end_val)
return -ERANGE;
*t = bgp->conf->conv_table[adc_val - conf->adc_start_val];
return 0;
}
/**
* ti_bandgap_validate() - helper to check the sanity of a struct ti_bandgap
* @bgp: struct ti_bandgap pointer
* @id: bandgap sensor id
*
* Checks if the bandgap pointer is valid and if the sensor id is also
* applicable.
*
* Return: 0 if no errors, -EINVAL for invalid @bgp pointer or -ERANGE if
* @id cannot index @bgp sensors.
*/
static inline int ti_bandgap_validate(struct ti_bandgap *bgp, int id)
{
if (IS_ERR_OR_NULL(bgp)) {
pr_err("%s: invalid bandgap pointer\n", __func__);
return -EINVAL;
}
Annotation
- Immediate include surface: `linux/clk.h`, `linux/cpu_pm.h`, `linux/device.h`, `linux/err.h`, `linux/export.h`, `linux/gpio/consumer.h`, `linux/init.h`, `linux/interrupt.h`.
- Detected declarations: `function ti_bandgap_readl`, `function ti_bandgap_writel`, `function ti_bandgap_power`, `function ti_errata814_bandgap_read_temp`, `function ti_bandgap_read_temp`, `function ti_bandgap_talert_irq_handler`, `function ti_bandgap_tshut_irq_handler`, `function ti_bandgap_adc_to_mcelsius`, `function ti_bandgap_validate`, `function ti_bandgap_read_counter`.
- Atlas domain: Driver Families / drivers/thermal.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- 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.