drivers/w1/masters/ds2482.c

Source file repositories/reference/linux-study-clean/drivers/w1/masters/ds2482.c

File Facts

System
Linux kernel
Corpus path
drivers/w1/masters/ds2482.c
Extension
.c
Size
15253 bytes
Lines
562
Domain
Driver Families
Bucket
drivers/w1
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 ds2482_w1_chan {
	struct ds2482_data	*pdev;
	u8			channel;
	struct w1_bus_master	w1_bm;
};

struct ds2482_data {
	struct i2c_client	*client;
	struct mutex		access_lock;

	/* 1-wire interface(s) */
	int			w1_count;	/* 1 or 8 */
	struct ds2482_w1_chan	w1_ch[8];

	/* per-device values */
	u8			channel;
	u8			read_prt;	/* see DS2482_PTR_CODE_xxx */
	u8			reg_config;
};


/**
 * ds2482_calculate_config - Helper to calculate values for configuration register
 * @conf: the raw config value
 * Return: the value w/ complements that can be written to register
 */
static inline u8 ds2482_calculate_config(u8 conf)
{
	conf |= extra_config;

	if (ds2482_active_pullup)
		conf |= DS2482_REG_CFG_APU;

	return conf | ((~conf & 0x0f) << 4);
}


/**
 * ds2482_select_register - Sets the read pointer.
 * @pdev:		The ds2482 client pointer
 * @read_ptr:	see DS2482_PTR_CODE_xxx above
 * Return: -1 on failure, 0 on success
 */
static inline int ds2482_select_register(struct ds2482_data *pdev, u8 read_ptr)
{
	if (pdev->read_prt != read_ptr) {
		if (i2c_smbus_write_byte_data(pdev->client,
					      DS2482_CMD_SET_READ_PTR,
					      read_ptr) < 0)
			return -1;

		pdev->read_prt = read_ptr;
	}
	return 0;
}

/**
 * ds2482_send_cmd - Sends a command without a parameter
 * @pdev:	The ds2482 client pointer
 * @cmd:	DS2482_CMD_RESET,
 *		DS2482_CMD_1WIRE_RESET,
 *		DS2482_CMD_1WIRE_READ_BYTE
 * Return: -1 on failure, 0 on success
 */
static inline int ds2482_send_cmd(struct ds2482_data *pdev, u8 cmd)
{
	if (i2c_smbus_write_byte(pdev->client, cmd) < 0)
		return -1;

	pdev->read_prt = DS2482_PTR_CODE_STATUS;
	return 0;
}

/**
 * ds2482_send_cmd_data - Sends a command with a parameter
 * @pdev:	The ds2482 client pointer
 * @cmd:	DS2482_CMD_WRITE_CONFIG,
 *		DS2482_CMD_1WIRE_SINGLE_BIT,
 *		DS2482_CMD_1WIRE_WRITE_BYTE,
 *		DS2482_CMD_1WIRE_TRIPLET
 * @byte:	The data to send
 * Return: -1 on failure, 0 on success
 */
static inline int ds2482_send_cmd_data(struct ds2482_data *pdev,
				       u8 cmd, u8 byte)
{
	if (i2c_smbus_write_byte_data(pdev->client, cmd, byte) < 0)
		return -1;

	/* all cmds leave in STATUS, except CONFIG */

Annotation

Implementation Notes