drivers/char/hw_random/omap-rng.c
Source file repositories/reference/linux-study-clean/drivers/char/hw_random/omap-rng.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/char/hw_random/omap-rng.c- Extension
.c- Size
- 14479 bytes
- Lines
- 569
- Domain
- Driver Families
- Bucket
- drivers/char
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/module.hlinux/init.hlinux/random.hlinux/err.hlinux/platform_device.hlinux/hw_random.hlinux/delay.hlinux/kernel.hlinux/slab.hlinux/pm_runtime.hlinux/of.hlinux/interrupt.hlinux/clk.hlinux/io.h
Detected Declarations
struct omap_rng_devstruct omap_rng_pdatastruct omap_rng_devfunction omap_rng_readfunction omap_rng_writefunction omap_rng_do_readfunction omap_rng_initfunction omap_rng_cleanupfunction omap2_rng_data_presentfunction omap2_rng_initfunction omap2_rng_cleanupfunction omap4_rng_data_presentfunction eip76_rng_initfunction omap4_rng_initfunction omap4_rng_cleanupfunction omap4_rng_irqfunction of_get_omap_rng_device_detailsfunction get_omap_rng_device_detailsfunction omap_rng_probefunction omap_rng_removefunction omap_rng_suspendfunction omap_rng_resume
Annotated Snippet
struct omap_rng_pdata {
u16 *regs;
u32 data_size;
u32 (*data_present)(struct omap_rng_dev *priv);
int (*init)(struct omap_rng_dev *priv);
void (*cleanup)(struct omap_rng_dev *priv);
};
struct omap_rng_dev {
void __iomem *base;
struct device *dev;
const struct omap_rng_pdata *pdata;
struct hwrng rng;
struct clk *clk;
struct clk *clk_reg;
};
static inline u32 omap_rng_read(struct omap_rng_dev *priv, u16 reg)
{
return __raw_readl(priv->base + priv->pdata->regs[reg]);
}
static inline void omap_rng_write(struct omap_rng_dev *priv, u16 reg,
u32 val)
{
__raw_writel(val, priv->base + priv->pdata->regs[reg]);
}
static int omap_rng_do_read(struct hwrng *rng, void *data, size_t max,
bool wait)
{
struct omap_rng_dev *priv;
int i, present;
priv = (struct omap_rng_dev *)rng->priv;
if (max < priv->pdata->data_size)
return 0;
for (i = 0; i < RNG_DATA_FILL_TIMEOUT; i++) {
present = priv->pdata->data_present(priv);
if (present || !wait)
break;
udelay(10);
}
if (!present)
return 0;
memcpy_fromio(data, priv->base + priv->pdata->regs[RNG_OUTPUT_0_REG],
priv->pdata->data_size);
if (priv->pdata->regs[RNG_INTACK_REG])
omap_rng_write(priv, RNG_INTACK_REG, RNG_REG_INTACK_RDY_MASK);
return priv->pdata->data_size;
}
static int omap_rng_init(struct hwrng *rng)
{
struct omap_rng_dev *priv;
priv = (struct omap_rng_dev *)rng->priv;
return priv->pdata->init(priv);
}
static void omap_rng_cleanup(struct hwrng *rng)
{
struct omap_rng_dev *priv;
priv = (struct omap_rng_dev *)rng->priv;
priv->pdata->cleanup(priv);
}
static inline u32 omap2_rng_data_present(struct omap_rng_dev *priv)
{
return omap_rng_read(priv, RNG_STATUS_REG) ? 0 : 1;
}
static int omap2_rng_init(struct omap_rng_dev *priv)
{
omap_rng_write(priv, RNG_SYSCONFIG_REG, 0x1);
return 0;
}
static void omap2_rng_cleanup(struct omap_rng_dev *priv)
{
omap_rng_write(priv, RNG_SYSCONFIG_REG, 0x0);
Annotation
- Immediate include surface: `linux/module.h`, `linux/init.h`, `linux/random.h`, `linux/err.h`, `linux/platform_device.h`, `linux/hw_random.h`, `linux/delay.h`, `linux/kernel.h`.
- Detected declarations: `struct omap_rng_dev`, `struct omap_rng_pdata`, `struct omap_rng_dev`, `function omap_rng_read`, `function omap_rng_write`, `function omap_rng_do_read`, `function omap_rng_init`, `function omap_rng_cleanup`, `function omap2_rng_data_present`, `function omap2_rng_init`.
- Atlas domain: Driver Families / drivers/char.
- Implementation status: source implementation candidate.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.