drivers/hwmon/max1619.c

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

File Facts

System
Linux kernel
Corpus path
drivers/hwmon/max1619.c
Extension
.c
Size
9526 bytes
Lines
400
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

switch (attr) {
		case hwmon_chip_update_interval:
			return 0644;
		case hwmon_chip_alarms:
			return 0444;
		default:
			break;
		}
		break;
	case hwmon_temp:
		switch (attr) {
		case hwmon_temp_input:
			return 0444;
		case hwmon_temp_min:
		case hwmon_temp_max:
		case hwmon_temp_crit:
		case hwmon_temp_crit_hyst:
			return 0644;
		case hwmon_temp_min_alarm:
		case hwmon_temp_max_alarm:
		case hwmon_temp_crit_alarm:
		case hwmon_temp_fault:
			return 0444;
		default:
			break;
		}
		break;
	default:
		break;
	}
	return 0;
}

static const struct hwmon_channel_info * const max1619_info[] = {
	HWMON_CHANNEL_INFO(chip, HWMON_C_ALARMS | HWMON_C_UPDATE_INTERVAL),
	HWMON_CHANNEL_INFO(temp,
			   HWMON_T_INPUT,
			   HWMON_T_INPUT | HWMON_T_MIN | HWMON_T_MAX |
			   HWMON_T_CRIT | HWMON_T_CRIT_HYST |
			   HWMON_T_MIN_ALARM | HWMON_T_MAX_ALARM |
			   HWMON_T_CRIT_ALARM | HWMON_T_FAULT),
	NULL
};

static const struct hwmon_ops max1619_hwmon_ops = {
	.is_visible = max1619_is_visible,
	.read = max1619_read,
	.write = max1619_write,
};

static const struct hwmon_chip_info max1619_chip_info = {
	.ops = &max1619_hwmon_ops,
	.info = max1619_info,
};

/* Return 0 if detection is successful, -ENODEV otherwise */
static int max1619_detect(struct i2c_client *client,
			  struct i2c_board_info *info)
{
	struct i2c_adapter *adapter = client->adapter;
	int regval;

	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
		return -ENODEV;

	regval = i2c_smbus_read_byte_data(client, MAX1619_REG_CONFIG);
	if (regval < 0 || (regval & 0x03))
		return -ENODEV;
	regval = i2c_smbus_read_byte_data(client, MAX1619_REG_CONVRATE);
	if (regval < 0 || regval > 0x07)
		return -ENODEV;
	regval = i2c_smbus_read_byte_data(client, MAX1619_REG_STATUS);
	if (regval < 0 || (regval & 0x61))
		return -ENODEV;

	regval = i2c_smbus_read_byte_data(client, MAX1619_REG_MAN_ID);
	if (regval != 0x4d)
		return -ENODEV;
	regval = i2c_smbus_read_byte_data(client, MAX1619_REG_CHIP_ID);
	if (regval != 0x04)
		return -ENODEV;

	strscpy(info->type, "max1619", I2C_NAME_SIZE);

	return 0;
}

static int max1619_init_chip(struct regmap *regmap)
{
	int ret;

Annotation

Implementation Notes