drivers/sbus/char/bbc_envctrl.c
Source file repositories/reference/linux-study-clean/drivers/sbus/char/bbc_envctrl.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/sbus/char/bbc_envctrl.c- Extension
.c- Size
- 16245 bytes
- Lines
- 602
- Domain
- Driver Families
- Bucket
- drivers/sbus
- 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.
- 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/kthread.hlinux/delay.hlinux/kmod.hlinux/reboot.hlinux/of.hlinux/platform_device.hlinux/slab.hasm/oplib.hbbc_i2c.hmax1617.h
Detected Declarations
struct temp_limitsfunction set_fan_speedsfunction get_current_tempsfunction do_envctrl_shutdownfunction analyze_ambient_tempfunction analyze_cpu_tempfunction analyze_tempsfunction prioritize_fan_actionfunction maybe_new_ambient_fan_speedfunction maybe_new_cpu_fan_speedfunction maybe_new_fan_speedsfunction fans_full_blastfunction kenvctrldfunction list_for_each_entryfunction attach_one_tempfunction attach_one_fanfunction destroy_one_tempfunction destroy_all_tempsfunction list_for_each_entry_safefunction destroy_one_fanfunction destroy_all_fansfunction list_for_each_entry_safefunction bbc_envctrl_initfunction bbc_envctrl_cleanup
Annotated Snippet
struct temp_limits {
s8 high_pwroff, high_shutdown, high_warn;
s8 low_warn, low_shutdown, low_pwroff;
};
static struct temp_limits cpu_temp_limits[2] = {
{ 100, 85, 80, 5, -5, -10 },
{ 100, 85, 80, 5, -5, -10 },
};
static struct temp_limits amb_temp_limits[2] = {
{ 65, 55, 40, 5, -5, -10 },
{ 65, 55, 40, 5, -5, -10 },
};
static LIST_HEAD(all_temps);
static LIST_HEAD(all_fans);
#define CPU_FAN_REG 0xf0
#define SYS_FAN_REG 0xf2
#define PSUPPLY_FAN_REG 0xf4
#define FAN_SPEED_MIN 0x0c
#define FAN_SPEED_MAX 0x3f
#define PSUPPLY_FAN_ON 0x1f
#define PSUPPLY_FAN_OFF 0x00
static void set_fan_speeds(struct bbc_fan_control *fp)
{
/* Put temperatures into range so we don't mis-program
* the hardware.
*/
if (fp->cpu_fan_speed < FAN_SPEED_MIN)
fp->cpu_fan_speed = FAN_SPEED_MIN;
if (fp->cpu_fan_speed > FAN_SPEED_MAX)
fp->cpu_fan_speed = FAN_SPEED_MAX;
if (fp->system_fan_speed < FAN_SPEED_MIN)
fp->system_fan_speed = FAN_SPEED_MIN;
if (fp->system_fan_speed > FAN_SPEED_MAX)
fp->system_fan_speed = FAN_SPEED_MAX;
#ifdef ENVCTRL_TRACE
printk("fan%d: Changed fan speed to cpu(%02x) sys(%02x)\n",
fp->index,
fp->cpu_fan_speed, fp->system_fan_speed);
#endif
bbc_i2c_writeb(fp->client, fp->cpu_fan_speed, CPU_FAN_REG);
bbc_i2c_writeb(fp->client, fp->system_fan_speed, SYS_FAN_REG);
bbc_i2c_writeb(fp->client,
(fp->psupply_fan_on ?
PSUPPLY_FAN_ON : PSUPPLY_FAN_OFF),
PSUPPLY_FAN_REG);
}
static void get_current_temps(struct bbc_cpu_temperature *tp)
{
tp->prev_amb_temp = tp->curr_amb_temp;
bbc_i2c_readb(tp->client,
(unsigned char *) &tp->curr_amb_temp,
MAX1617_AMB_TEMP);
tp->prev_cpu_temp = tp->curr_cpu_temp;
bbc_i2c_readb(tp->client,
(unsigned char *) &tp->curr_cpu_temp,
MAX1617_CPU_TEMP);
#ifdef ENVCTRL_TRACE
printk("temp%d: cpu(%d C) amb(%d C)\n",
tp->index,
(int) tp->curr_cpu_temp, (int) tp->curr_amb_temp);
#endif
}
static void do_envctrl_shutdown(struct bbc_cpu_temperature *tp)
{
static int shutting_down = 0;
char *type = "???";
s8 val = -1;
if (shutting_down != 0)
return;
if (tp->curr_amb_temp >= amb_temp_limits[tp->index].high_shutdown ||
tp->curr_amb_temp < amb_temp_limits[tp->index].low_shutdown) {
type = "ambient";
val = tp->curr_amb_temp;
} else if (tp->curr_cpu_temp >= cpu_temp_limits[tp->index].high_shutdown ||
tp->curr_cpu_temp < cpu_temp_limits[tp->index].low_shutdown) {
type = "CPU";
val = tp->curr_cpu_temp;
Annotation
- Immediate include surface: `linux/kthread.h`, `linux/delay.h`, `linux/kmod.h`, `linux/reboot.h`, `linux/of.h`, `linux/platform_device.h`, `linux/slab.h`, `asm/oplib.h`.
- Detected declarations: `struct temp_limits`, `function set_fan_speeds`, `function get_current_temps`, `function do_envctrl_shutdown`, `function analyze_ambient_temp`, `function analyze_cpu_temp`, `function analyze_temps`, `function prioritize_fan_action`, `function maybe_new_ambient_fan_speed`, `function maybe_new_cpu_fan_speed`.
- Atlas domain: Driver Families / drivers/sbus.
- Implementation status: source implementation candidate.
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.