drivers/i2c/busses/i2c-nct6694.c
Source file repositories/reference/linux-study-clean/drivers/i2c/busses/i2c-nct6694.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/i2c/busses/i2c-nct6694.c- Extension
.c- Size
- 4858 bytes
- Lines
- 197
- 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/i2c.hlinux/idr.hlinux/kernel.hlinux/mfd/nct6694.hlinux/module.hlinux/platform_device.h
Detected Declarations
struct nct6694_i2c_dataenum nct6694_i2c_baudratefunction nct6694_i2c_xferfunction nct6694_i2c_funcfunction nct6694_i2c_set_baudratefunction nct6694_i2c_ida_freefunction nct6694_i2c_probe
Annotated Snippet
struct nct6694_i2c_data {
struct device *dev;
struct nct6694 *nct6694;
struct i2c_adapter adapter;
struct nct6694_i2c_deliver deliver;
unsigned char port;
unsigned char br;
};
static int nct6694_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
{
struct nct6694_i2c_data *data = adap->algo_data;
struct nct6694_i2c_deliver *deliver = &data->deliver;
static const struct nct6694_cmd_header cmd_hd = {
.mod = NCT6694_I2C_MOD,
.cmd = NCT6694_I2C_DELIVER,
.sel = NCT6694_I2C_DELIVER_SEL,
.len = cpu_to_le16(sizeof(*deliver))
};
int ret, i;
for (i = 0; i < num; i++) {
struct i2c_msg *msg_temp = &msgs[i];
memset(deliver, 0, sizeof(*deliver));
deliver->port = data->port;
deliver->br = data->br;
deliver->addr = i2c_8bit_addr_from_msg(msg_temp);
if (msg_temp->flags & I2C_M_RD) {
deliver->r_cnt = msg_temp->len;
ret = nct6694_write_msg(data->nct6694, &cmd_hd, deliver);
if (ret < 0)
return ret;
memcpy(msg_temp->buf, deliver->read_data, msg_temp->len);
} else {
deliver->w_cnt = msg_temp->len;
memcpy(deliver->write_data, msg_temp->buf, msg_temp->len);
ret = nct6694_write_msg(data->nct6694, &cmd_hd, deliver);
if (ret < 0)
return ret;
}
}
return num;
}
static u32 nct6694_i2c_func(struct i2c_adapter *adapter)
{
return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
}
static const struct i2c_adapter_quirks nct6694_i2c_quirks = {
.max_read_len = NCT6694_I2C_MAX_XFER_SIZE,
.max_write_len = NCT6694_I2C_MAX_XFER_SIZE,
};
static const struct i2c_algorithm nct6694_i2c_algo = {
.xfer = nct6694_i2c_xfer,
.functionality = nct6694_i2c_func,
};
static int nct6694_i2c_set_baudrate(struct nct6694_i2c_data *data)
{
if (data->port >= NCT6694_I2C_MAX_DEVS) {
dev_err(data->dev, "Invalid I2C port index %d\n", data->port);
return -EINVAL;
}
if (br_reg[data->port] > NCT6694_I2C_BR_1M) {
dev_warn(data->dev, "Invalid baudrate %d for I2C%d, using 100K\n",
br_reg[data->port], data->port);
br_reg[data->port] = NCT6694_I2C_BR_100K;
}
data->br = br_reg[data->port];
return 0;
}
static void nct6694_i2c_ida_free(void *d)
{
struct nct6694_i2c_data *data = d;
struct nct6694 *nct6694 = data->nct6694;
ida_free(&nct6694->i2c_ida, data->port);
}
static int nct6694_i2c_probe(struct platform_device *pdev)
Annotation
- Immediate include surface: `linux/i2c.h`, `linux/idr.h`, `linux/kernel.h`, `linux/mfd/nct6694.h`, `linux/module.h`, `linux/platform_device.h`.
- Detected declarations: `struct nct6694_i2c_data`, `enum nct6694_i2c_baudrate`, `function nct6694_i2c_xfer`, `function nct6694_i2c_func`, `function nct6694_i2c_set_baudrate`, `function nct6694_i2c_ida_free`, `function nct6694_i2c_probe`.
- 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.