drivers/hwmon/g762.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/g762.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/g762.c- Extension
.c- Size
- 28485 bytes
- Lines
- 1124
- Domain
- Driver Families
- Bucket
- drivers/hwmon
- 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.
- 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/device.hlinux/module.hlinux/init.hlinux/jiffies.hlinux/i2c.hlinux/hwmon.hlinux/hwmon-sysfs.hlinux/err.hlinux/mutex.hlinux/kernel.hlinux/clk.hlinux/of.hlinux/platform_data/g762.h
Detected Declarations
struct g762_dataenum g762_regsfunction parametersfunction registerfunction do_set_clk_freqfunction do_set_pwm_modefunction do_set_fan_divfunction do_set_fan_gear_modefunction do_set_fan_pulsesfunction do_set_pwm_enablefunction do_set_pwm_polarityfunction do_set_pwmfunction do_set_fan_targetfunction do_set_fan_startvfunction disabledfunction g762_of_clock_enablefunction g762_of_prop_import_onefunction g762_of_prop_importfunction g762_of_prop_importfunction g762_of_clock_enablefunction g762_pdata_prop_importfunction fan1_input_showfunction pwm1_mode_showfunction pwm1_mode_storefunction fan1_div_showfunction fan1_div_storefunction fan1_pulses_showfunction fan1_pulses_storefunction pwm1_enable_showfunction pwm1_enable_storefunction pwm1_showfunction pwm1_storefunction rpm_from_cntfunction fan1_target_storefunction fan1_fault_showfunction fan1_alarm_showfunction g762_fan_initfunction g762_probe
Annotated Snippet
struct g762_data {
struct i2c_client *client;
bool internal_clock;
struct clk *clk;
/* update mutex */
struct mutex update_lock;
/* board specific parameters. */
u32 clk_freq;
/* g762 register cache */
bool valid;
unsigned long last_updated; /* in jiffies */
u8 set_cnt; /* controls fan rotation speed in closed-loop mode */
u8 act_cnt; /* provides access to current fan RPM value */
u8 fan_sta; /* bit 0: set when actual fan speed is more than
* 25% outside requested fan speed
* bit 1: set when no transition occurs on fan
* pin for 0.7s
*/
u8 set_out; /* controls fan rotation speed in open-loop mode */
u8 fan_cmd1; /* 0: FG_PLS_ID0 FG pulses count per revolution
* 0: 2 counts per revolution
* 1: 4 counts per revolution
* 1: PWM_POLARITY 1: negative_duty
* 0: positive_duty
* 2,3: [FG_CLOCK_ID0, FG_CLK_ID1]
* 00: Divide fan clock by 1
* 01: Divide fan clock by 2
* 10: Divide fan clock by 4
* 11: Divide fan clock by 8
* 4: FAN_MODE 1:closed-loop, 0:open-loop
* 5: OUT_MODE 1:PWM, 0:DC
* 6: DET_FAN_OOC enable "fan ooc" status
* 7: DET_FAN_FAIL enable "fan fail" status
*/
u8 fan_cmd2; /* 0,1: FAN_STARTV 0,1,2,3 -> 0,32,64,96 dac_code
* 2,3: FG_GEAR_MODE
* 00: multiplier = 1
* 01: multiplier = 2
* 10: multiplier = 4
* 4: Mask ALERT# (g763 only)
*/
};
/*
* Convert count value from fan controller register (FAN_SET_CNT) into fan
* speed RPM value. Note that the datasheet documents a basic formula;
* influence of additional parameters (fan clock divisor, fan gear mode)
* have been infered from examples in the datasheet and tests.
*/
static inline unsigned int rpm_from_cnt(u8 cnt, u32 clk_freq, u16 p,
u8 clk_div, u8 gear_mult)
{
if (cnt == 0xff) /* setting cnt to 255 stops the fan */
return 0;
return (clk_freq * 30 * gear_mult) / ((cnt ? cnt : 1) * p * clk_div);
}
/*
* Convert fan RPM value from sysfs into count value for fan controller
* register (FAN_SET_CNT).
*/
static inline unsigned char cnt_from_rpm(unsigned long rpm, u32 clk_freq, u16 p,
u8 clk_div, u8 gear_mult)
{
unsigned long f1 = clk_freq * 30 * gear_mult;
unsigned long f2 = p * clk_div;
if (!rpm) /* to stop the fan, set cnt to 255 */
return 0xff;
rpm = clamp_val(rpm, f1 / (255 * f2), ULONG_MAX / f2);
return DIV_ROUND_CLOSEST(f1, rpm * f2);
}
/* helper to grab and cache data, at most one time per second */
static struct g762_data *g762_update_client(struct device *dev)
{
struct g762_data *data = dev_get_drvdata(dev);
struct i2c_client *client = data->client;
int ret = 0;
mutex_lock(&data->update_lock);
if (time_before(jiffies, data->last_updated + G762_UPDATE_INTERVAL) &&
likely(data->valid))
goto out;
Annotation
- Immediate include surface: `linux/device.h`, `linux/module.h`, `linux/init.h`, `linux/jiffies.h`, `linux/i2c.h`, `linux/hwmon.h`, `linux/hwmon-sysfs.h`, `linux/err.h`.
- Detected declarations: `struct g762_data`, `enum g762_regs`, `function parameters`, `function register`, `function do_set_clk_freq`, `function do_set_pwm_mode`, `function do_set_fan_div`, `function do_set_fan_gear_mode`, `function do_set_fan_pulses`, `function do_set_pwm_enable`.
- Atlas domain: Driver Families / drivers/hwmon.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.