drivers/hwmon/g760a.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/g760a.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/g760a.c- Extension
.c- Size
- 5408 bytes
- Lines
- 218
- 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/module.hlinux/init.hlinux/slab.hlinux/jiffies.hlinux/i2c.hlinux/hwmon.hlinux/hwmon-sysfs.hlinux/err.hlinux/mutex.hlinux/sysfs.h
Detected Declarations
struct g760a_dataenum g760a_regsfunction rpm_from_cntfunction g760a_read_valuefunction g760a_write_valuefunction fan1_input_showfunction fan1_alarm_showfunction pwm1_showfunction pwm1_storefunction g760a_probe
Annotated Snippet
struct g760a_data {
struct i2c_client *client;
struct mutex update_lock;
/* board specific parameters */
u32 clk; /* default 32kHz */
u16 fan_div; /* default P=2 */
/* g760a register cache */
unsigned int valid:1;
unsigned long last_updated; /* In jiffies */
u8 set_cnt; /* PWM (period) count number; 0xff stops fan */
u8 act_cnt; /* formula: cnt = (CLK * 30)/(rpm * P) */
u8 fan_sta; /* bit 0: set when actual fan speed more than 20%
* outside requested fan speed
* bit 1: set when fan speed below 1920 rpm
*/
};
#define G760A_DEFAULT_CLK 32768
#define G760A_DEFAULT_FAN_DIV 2
#define PWM_FROM_CNT(cnt) (0xff-(cnt))
#define PWM_TO_CNT(pwm) (0xff-(pwm))
static inline unsigned int rpm_from_cnt(u8 val, u32 clk, u16 div)
{
return ((val == 0x00) ? 0 : ((clk*30)/(val*div)));
}
/* read/write wrappers */
static int g760a_read_value(struct i2c_client *client, enum g760a_regs reg)
{
return i2c_smbus_read_byte_data(client, reg);
}
static int g760a_write_value(struct i2c_client *client, enum g760a_regs reg,
u16 value)
{
return i2c_smbus_write_byte_data(client, reg, value);
}
/*
* sysfs attributes
*/
static struct g760a_data *g760a_update_client(struct device *dev)
{
struct g760a_data *data = dev_get_drvdata(dev);
struct i2c_client *client = data->client;
mutex_lock(&data->update_lock);
if (time_after(jiffies, data->last_updated + G760A_UPDATE_INTERVAL)
|| !data->valid) {
dev_dbg(&client->dev, "Starting g760a update\n");
data->set_cnt = g760a_read_value(client, G760A_REG_SET_CNT);
data->act_cnt = g760a_read_value(client, G760A_REG_ACT_CNT);
data->fan_sta = g760a_read_value(client, G760A_REG_FAN_STA);
data->last_updated = jiffies;
data->valid = true;
}
mutex_unlock(&data->update_lock);
return data;
}
static ssize_t fan1_input_show(struct device *dev,
struct device_attribute *da, char *buf)
{
struct g760a_data *data = g760a_update_client(dev);
unsigned int rpm = 0;
mutex_lock(&data->update_lock);
if (!(data->fan_sta & G760A_REG_FAN_STA_RPM_LOW))
rpm = rpm_from_cnt(data->act_cnt, data->clk, data->fan_div);
mutex_unlock(&data->update_lock);
return sprintf(buf, "%d\n", rpm);
}
static ssize_t fan1_alarm_show(struct device *dev,
struct device_attribute *da, char *buf)
{
struct g760a_data *data = g760a_update_client(dev);
Annotation
- Immediate include surface: `linux/module.h`, `linux/init.h`, `linux/slab.h`, `linux/jiffies.h`, `linux/i2c.h`, `linux/hwmon.h`, `linux/hwmon-sysfs.h`, `linux/err.h`.
- Detected declarations: `struct g760a_data`, `enum g760a_regs`, `function rpm_from_cnt`, `function g760a_read_value`, `function g760a_write_value`, `function fan1_input_show`, `function fan1_alarm_show`, `function pwm1_show`, `function pwm1_store`, `function g760a_probe`.
- 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.