drivers/i2c/busses/i2c-diolan-u2c.c
Source file repositories/reference/linux-study-clean/drivers/i2c/busses/i2c-diolan-u2c.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/i2c/busses/i2c-diolan-u2c.c- Extension
.c- Size
- 12886 bytes
- Lines
- 513
- Domain
- Driver Families
- Bucket
- drivers/i2c
- 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.
- 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/kernel.hlinux/errno.hlinux/module.hlinux/types.hlinux/slab.hlinux/usb.hlinux/i2c.h
Detected Declarations
struct i2c_diolan_u2cfunction diolan_usb_transferfunction diolan_write_cmdfunction diolan_usb_cmdfunction diolan_usb_cmd_datafunction diolan_usb_cmd_data2function diolan_flush_inputfunction diolan_i2c_startfunction diolan_i2c_repeated_startfunction diolan_i2c_stopfunction diolan_i2c_get_byte_ackfunction diolan_i2c_put_byte_ackfunction diolan_set_speedfunction diolan_set_clock_synchfunction diolan_set_clock_synch_timeoutfunction diolan_fw_versionfunction diolan_get_serialfunction diolan_initfunction diolan_usb_xferfunction diolan_usb_funcfunction diolan_u2c_probefunction diolan_u2c_disconnect
Annotated Snippet
struct i2c_diolan_u2c {
u8 obuffer[DIOLAN_OUTBUF_LEN]; /* output buffer */
u8 ibuffer[DIOLAN_INBUF_LEN]; /* input buffer */
int ep_in, ep_out; /* Endpoints */
struct usb_device *usb_dev; /* the usb device for this device */
struct usb_interface *interface;/* the interface for this device */
struct i2c_adapter adapter; /* i2c related things */
int olen; /* Output buffer length */
int ocount; /* Number of enqueued messages */
};
static uint frequency = I2C_MAX_STANDARD_MODE_FREQ; /* I2C clock frequency in Hz */
module_param(frequency, uint, S_IRUGO | S_IWUSR);
MODULE_PARM_DESC(frequency, "I2C clock frequency in hertz");
/* usb layer */
/* Send command to device, and get response. */
static int diolan_usb_transfer(struct i2c_diolan_u2c *dev)
{
int ret = 0;
int actual;
int i;
if (!dev->olen || !dev->ocount)
return -EINVAL;
ret = usb_bulk_msg(dev->usb_dev,
usb_sndbulkpipe(dev->usb_dev, dev->ep_out),
dev->obuffer, dev->olen, &actual,
DIOLAN_USB_TIMEOUT);
if (!ret) {
for (i = 0; i < dev->ocount; i++) {
int tmpret;
tmpret = usb_bulk_msg(dev->usb_dev,
usb_rcvbulkpipe(dev->usb_dev,
dev->ep_in),
dev->ibuffer,
sizeof(dev->ibuffer), &actual,
DIOLAN_USB_TIMEOUT);
/*
* Stop command processing if a previous command
* returned an error.
* Note that we still need to retrieve all messages.
*/
if (ret < 0)
continue;
ret = tmpret;
if (ret == 0 && actual > 0) {
switch (dev->ibuffer[actual - 1]) {
case RESP_NACK:
/*
* Return ENXIO if NACK was received as
* response to the address phase,
* EIO otherwise
*/
ret = i == 1 ? -ENXIO : -EIO;
break;
case RESP_TIMEOUT:
ret = -ETIMEDOUT;
break;
case RESP_OK:
/* strip off return code */
ret = actual - 1;
break;
default:
ret = -EIO;
break;
}
}
}
}
dev->olen = 0;
dev->ocount = 0;
return ret;
}
static int diolan_write_cmd(struct i2c_diolan_u2c *dev, bool flush)
{
if (flush || dev->olen >= DIOLAN_FLUSH_LEN)
return diolan_usb_transfer(dev);
return 0;
}
/* Send command (no data) */
static int diolan_usb_cmd(struct i2c_diolan_u2c *dev, u8 command, bool flush)
{
dev->obuffer[dev->olen++] = command;
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/errno.h`, `linux/module.h`, `linux/types.h`, `linux/slab.h`, `linux/usb.h`, `linux/i2c.h`.
- Detected declarations: `struct i2c_diolan_u2c`, `function diolan_usb_transfer`, `function diolan_write_cmd`, `function diolan_usb_cmd`, `function diolan_usb_cmd_data`, `function diolan_usb_cmd_data2`, `function diolan_flush_input`, `function diolan_i2c_start`, `function diolan_i2c_repeated_start`, `function diolan_i2c_stop`.
- Atlas domain: Driver Families / drivers/i2c.
- Implementation status: source implementation candidate.
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.