drivers/base/regmap/regmap-mdio.c
Source file repositories/reference/linux-study-clean/drivers/base/regmap/regmap-mdio.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/base/regmap/regmap-mdio.c- Extension
.c- Size
- 3111 bytes
- Lines
- 122
- Domain
- Driver Families
- Bucket
- drivers/base
- 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.
- 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/errno.hlinux/mdio.hlinux/module.hlinux/regmap.h
Detected Declarations
function regmap_mdio_c22_readfunction regmap_mdio_c22_writefunction regmap_mdio_c45_readfunction regmap_mdio_c45_writeexport __regmap_init_mdioexport __devm_regmap_init_mdio
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
#include <linux/errno.h>
#include <linux/mdio.h>
#include <linux/module.h>
#include <linux/regmap.h>
#define REGVAL_MASK GENMASK(15, 0)
#define REGNUM_C22_MASK GENMASK(4, 0)
/* Clause-45 mask includes the device type (5 bit) and actual register number (16 bit) */
#define REGNUM_C45_MASK GENMASK(20, 0)
static int regmap_mdio_c22_read(void *context, unsigned int reg, unsigned int *val)
{
struct mdio_device *mdio_dev = context;
int ret;
if (unlikely(reg & ~REGNUM_C22_MASK))
return -ENXIO;
ret = mdiodev_read(mdio_dev, reg);
if (ret < 0)
return ret;
*val = ret & REGVAL_MASK;
return 0;
}
static int regmap_mdio_c22_write(void *context, unsigned int reg, unsigned int val)
{
struct mdio_device *mdio_dev = context;
if (unlikely(reg & ~REGNUM_C22_MASK))
return -ENXIO;
return mdiodev_write(mdio_dev, reg, val);
}
static const struct regmap_bus regmap_mdio_c22_bus = {
.reg_write = regmap_mdio_c22_write,
.reg_read = regmap_mdio_c22_read,
};
static int regmap_mdio_c45_read(void *context, unsigned int reg, unsigned int *val)
{
struct mdio_device *mdio_dev = context;
unsigned int devad;
int ret;
if (unlikely(reg & ~REGNUM_C45_MASK))
return -ENXIO;
devad = reg >> REGMAP_MDIO_C45_DEVAD_SHIFT;
reg = reg & REGMAP_MDIO_C45_REGNUM_MASK;
ret = mdiodev_c45_read(mdio_dev, devad, reg);
if (ret < 0)
return ret;
*val = ret & REGVAL_MASK;
return 0;
}
static int regmap_mdio_c45_write(void *context, unsigned int reg, unsigned int val)
{
struct mdio_device *mdio_dev = context;
unsigned int devad;
if (unlikely(reg & ~REGNUM_C45_MASK))
return -ENXIO;
devad = reg >> REGMAP_MDIO_C45_DEVAD_SHIFT;
reg = reg & REGMAP_MDIO_C45_REGNUM_MASK;
return mdiodev_c45_write(mdio_dev, devad, reg, val);
}
static const struct regmap_bus regmap_mdio_c45_bus = {
.reg_write = regmap_mdio_c45_write,
.reg_read = regmap_mdio_c45_read,
};
struct regmap *__regmap_init_mdio(struct mdio_device *mdio_dev,
const struct regmap_config *config, struct lock_class_key *lock_key,
const char *lock_name)
{
const struct regmap_bus *bus;
Annotation
- Immediate include surface: `linux/errno.h`, `linux/mdio.h`, `linux/module.h`, `linux/regmap.h`.
- Detected declarations: `function regmap_mdio_c22_read`, `function regmap_mdio_c22_write`, `function regmap_mdio_c45_read`, `function regmap_mdio_c45_write`, `export __regmap_init_mdio`, `export __devm_regmap_init_mdio`.
- Atlas domain: Driver Families / drivers/base.
- Implementation status: integration 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.