drivers/staging/iio/addac/adt7316.c

Source file repositories/reference/linux-study-clean/drivers/staging/iio/addac/adt7316.c

File Facts

System
Linux kernel
Corpus path
drivers/staging/iio/addac/adt7316.c
Extension
.c
Size
58502 bytes
Lines
2198
Domain
Driver Families
Bucket
drivers/staging
Inferred role
Driver Families: exported/initcall integration point
Status
integration 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 adt7316_chip_info {
	struct adt7316_bus	bus;
	struct gpio_desc	*ldac_pin;
	u16			int_mask;	/* 0x2f */
	u8			config1;
	u8			config2;
	u8			config3;
	u8			dac_config;	/* DAC config */
	u8			ldac_config;	/* LDAC config */
	u8			dac_bits;	/* 8, 10, 12 */
	u8			id;		/* chip id */
};

/*
 * Logic interrupt mask for user application to enable
 * interrupts.
 */
#define ADT7316_IN_TEMP_HIGH_INT_MASK	0x1
#define ADT7316_IN_TEMP_LOW_INT_MASK	0x2
#define ADT7316_EX_TEMP_HIGH_INT_MASK	0x4
#define ADT7316_EX_TEMP_LOW_INT_MASK	0x8
#define ADT7316_EX_TEMP_FAULT_INT_MASK	0x10
#define ADT7516_AIN1_INT_MASK		0x4
#define ADT7516_AIN2_INT_MASK		0x20
#define ADT7516_AIN3_INT_MASK		0x40
#define ADT7516_AIN4_INT_MASK		0x80
#define ADT7316_VDD_INT_MASK		0x100
#define ADT7316_TEMP_INT_MASK		0x1F
#define ADT7516_AIN_INT_MASK		0xE0
#define ADT7316_TEMP_AIN_INT_MASK	\
	(ADT7316_TEMP_INT_MASK)

static ssize_t adt7316_show_enabled(struct device *dev,
				    struct device_attribute *attr,
				    char *buf)
{
	struct iio_dev *dev_info = dev_to_iio_dev(dev);
	struct adt7316_chip_info *chip = iio_priv(dev_info);

	return sysfs_emit(buf, "%d\n", !!(chip->config1 & ADT7316_EN));
}

static ssize_t _adt7316_store_enabled(struct adt7316_chip_info *chip,
				      int enable)
{
	u8 config1;
	int ret;

	if (enable)
		config1 = chip->config1 | ADT7316_EN;
	else
		config1 = chip->config1 & ~ADT7316_EN;

	ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG1, config1);
	if (ret)
		return -EIO;

	chip->config1 = config1;

	return ret;
}

static ssize_t adt7316_store_enabled(struct device *dev,
				     struct device_attribute *attr,
				     const char *buf,
				     size_t len)
{
	struct iio_dev *dev_info = dev_to_iio_dev(dev);
	struct adt7316_chip_info *chip = iio_priv(dev_info);
	int enable;

	if (buf[0] == '1')
		enable = 1;
	else
		enable = 0;

	if (_adt7316_store_enabled(chip, enable) < 0)
		return -EIO;

	return len;
}

static IIO_DEVICE_ATTR(enabled, 0644,
		adt7316_show_enabled,
		adt7316_store_enabled,
		0);

static ssize_t adt7316_show_select_ex_temp(struct device *dev,
					   struct device_attribute *attr,
					   char *buf)

Annotation

Implementation Notes