drivers/net/dsa/xrs700x/xrs700x_i2c.c
Source file repositories/reference/linux-study-clean/drivers/net/dsa/xrs700x/xrs700x_i2c.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/dsa/xrs700x/xrs700x_i2c.c- Extension
.c- Size
- 3628 bytes
- Lines
- 161
- Domain
- Driver Families
- Bucket
- drivers/net
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/bits.hlinux/i2c.hlinux/module.hxrs700x.hxrs700x_reg.h
Detected Declarations
struct xrs700x_i2c_cmdfunction xrs700x_i2c_reg_readfunction xrs700x_i2c_reg_writefunction xrs700x_i2c_probefunction xrs700x_i2c_removefunction xrs700x_i2c_shutdown
Annotated Snippet
struct xrs700x_i2c_cmd {
__be32 reg;
__be16 val;
} __packed;
static int xrs700x_i2c_reg_read(void *context, unsigned int reg,
unsigned int *val)
{
struct device *dev = context;
struct i2c_client *i2c = to_i2c_client(dev);
struct xrs700x_i2c_cmd cmd;
int ret;
cmd.reg = cpu_to_be32(reg | 1);
ret = i2c_master_send(i2c, (char *)&cmd.reg, sizeof(cmd.reg));
if (ret < 0) {
dev_err(dev, "xrs i2c_master_send returned %d\n", ret);
return ret;
}
ret = i2c_master_recv(i2c, (char *)&cmd.val, sizeof(cmd.val));
if (ret < 0) {
dev_err(dev, "xrs i2c_master_recv returned %d\n", ret);
return ret;
}
*val = be16_to_cpu(cmd.val);
return 0;
}
static int xrs700x_i2c_reg_write(void *context, unsigned int reg,
unsigned int val)
{
struct device *dev = context;
struct i2c_client *i2c = to_i2c_client(dev);
struct xrs700x_i2c_cmd cmd;
int ret;
cmd.reg = cpu_to_be32(reg);
cmd.val = cpu_to_be16(val);
ret = i2c_master_send(i2c, (char *)&cmd, sizeof(cmd));
if (ret < 0) {
dev_err(dev, "xrs i2c_master_send returned %d\n", ret);
return ret;
}
return 0;
}
static const struct regmap_config xrs700x_i2c_regmap_config = {
.val_bits = 16,
.reg_stride = 2,
.reg_bits = 32,
.pad_bits = 0,
.write_flag_mask = 0,
.read_flag_mask = 0,
.reg_read = xrs700x_i2c_reg_read,
.reg_write = xrs700x_i2c_reg_write,
.max_register = 0,
.cache_type = REGCACHE_NONE,
.reg_format_endian = REGMAP_ENDIAN_BIG,
.val_format_endian = REGMAP_ENDIAN_BIG
};
static int xrs700x_i2c_probe(struct i2c_client *i2c)
{
struct xrs700x *priv;
int ret;
priv = xrs700x_switch_alloc(&i2c->dev, i2c);
if (!priv)
return -ENOMEM;
priv->regmap = devm_regmap_init(&i2c->dev, NULL, &i2c->dev,
&xrs700x_i2c_regmap_config);
if (IS_ERR(priv->regmap)) {
ret = PTR_ERR(priv->regmap);
dev_err(&i2c->dev, "Failed to initialize regmap: %d\n", ret);
return ret;
}
i2c_set_clientdata(i2c, priv);
ret = xrs700x_switch_register(priv);
/* Main DSA driver may not be started yet. */
if (ret)
return ret;
Annotation
- Immediate include surface: `linux/bits.h`, `linux/i2c.h`, `linux/module.h`, `xrs700x.h`, `xrs700x_reg.h`.
- Detected declarations: `struct xrs700x_i2c_cmd`, `function xrs700x_i2c_reg_read`, `function xrs700x_i2c_reg_write`, `function xrs700x_i2c_probe`, `function xrs700x_i2c_remove`, `function xrs700x_i2c_shutdown`.
- Atlas domain: Driver Families / drivers/net.
- 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.