drivers/hwmon/tc654.c

Source file repositories/reference/linux-study-clean/drivers/hwmon/tc654.c

File Facts

System
Linux kernel
Corpus path
drivers/hwmon/tc654.c
Extension
.c
Size
14948 bytes
Lines
574
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.

Dependency Surface

Detected Declarations

Annotated Snippet

struct tc654_data {
	struct i2c_client *client;

	/* update mutex */
	struct mutex update_lock;

	/* tc654 register cache */
	bool valid;
	unsigned long last_updated;	/* in jiffies */

	u8 rpm_output[2];	/* The fan RPM data for fans 1 and 2 is then
				 * written to registers RPM1 and RPM2
				 */
	u8 fan_fault[2];	/* The Fan Fault Threshold Registers are used to
				 * set the fan fault threshold levels for fan 1
				 * and fan 2
				 */
	u8 config;	/* The Configuration Register is an 8-bit read/
			 * writable multi-function control register
			 *   7: Fan Fault Clear
			 *      1 = Clear Fan Fault
			 *      0 = Normal Operation (default)
			 *   6: Resolution Selection for RPM Output Registers
			 *      RPM Output Registers (RPM1 and RPM2) will be
			 *      set for
			 *      1 = 25 RPM (9-bit) resolution
			 *      0 = 50 RPM (8-bit) resolution (default)
			 *   5: Duty Cycle Control Method
			 *      The V OUT duty cycle will be controlled via
			 *      1 = the SMBus interface.
			 *      0 = via the V IN analog input pin. (default)
			 * 4,3: Fan 2 Pulses Per Rotation
			 *      00 = 1
			 *      01 = 2 (default)
			 *      10 = 4
			 *      11 = 8
			 * 2,1: Fan 1 Pulses Per Rotation
			 *      00 = 1
			 *      01 = 2 (default)
			 *      10 = 4
			 *      11 = 8
			 *   0: Shutdown Mode
			 *      1 = Shutdown mode.
			 *      0 = Normal operation. (default)
			 */
	u8 status;	/* The Status register provides all the information
			 * about what is going on within the TC654/TC655
			 * devices.
			 * 7,6: Unimplemented, Read as '0'
			 *   5: Over-Temperature Fault Condition
			 *      1 = Over-Temperature condition has occurred
			 *      0 = Normal operation. V IN is less than 2.6V
			 *   4: RPM2 Counter Overflow
			 *      1 = Fault condition
			 *      0 = Normal operation
			 *   3: RPM1 Counter Overflow
			 *      1 = Fault condition
			 *      0 = Normal operation
			 *   2: V IN Input Status
			 *      1 = V IN is open
			 *      0 = Normal operation. voltage present at V IN
			 *   1: Fan 2 Fault
			 *      1 = Fault condition
			 *      0 = Normal operation
			 *   0: Fan 1 Fault
			 *      1 = Fault condition
			 *      0 = Normal operation
			 */
	u8 duty_cycle;	/* The DUTY_CYCLE register is a 4-bit read/
			 * writable register used to control the duty
			 * cycle of the V OUT output.
			 */
};

/* helper to grab and cache data, at most one time per second */
static struct tc654_data *tc654_update_client(struct device *dev)
{
	struct tc654_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 + TC654_UPDATE_INTERVAL) &&
	    likely(data->valid))
		goto out;

	ret = i2c_smbus_read_byte_data(client, TC654_REG_RPM(0));
	if (ret < 0)
		goto out;
	data->rpm_output[0] = ret;

Annotation

Implementation Notes