drivers/media/rc/mtk-cir.c
Source file repositories/reference/linux-study-clean/drivers/media/rc/mtk-cir.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/media/rc/mtk-cir.c- Extension
.c- Size
- 11847 bytes
- Lines
- 455
- Domain
- Driver Families
- Bucket
- drivers/media
- 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/clk.hlinux/interrupt.hlinux/module.hlinux/io.hlinux/of.hlinux/platform_device.hlinux/reset.hmedia/rc-core.h
Detected Declarations
struct mtk_field_typestruct mtk_ir_datastruct mtk_irenum mtk_fieldsenum mtk_regsfunction mtk_chkdata_regfunction mtk_chk_periodfunction mtk_w32_maskfunction mtk_w32function mtk_r32function mtk_irq_disablefunction mtk_irq_enablefunction mtk_ir_irqfunction mtk_ir_probefunction mtk_ir_remove
Annotated Snippet
struct mtk_field_type {
u32 reg;
u8 offset;
u32 mask;
};
/*
* struct mtk_ir_data - This is the structure holding all differences among
various hardwares
* @regs: The pointer to the array holding registers offset
* @fields: The pointer to the array holding fields location
* @div: The internal divisor for the based reference clock
* @ok_count: The count indicating the completion of IR data
* receiving when count is reached
* @hw_period: The value indicating the hardware sampling period
*/
struct mtk_ir_data {
const u32 *regs;
const struct mtk_field_type *fields;
u8 div;
u8 ok_count;
u32 hw_period;
};
static const struct mtk_field_type mt7623_fields[] = {
[MTK_CHK_PERIOD] = {0x10, 8, GENMASK(20, 8)},
[MTK_HW_PERIOD] = {0x10, 0, GENMASK(7, 0)},
};
static const struct mtk_field_type mt7622_fields[] = {
[MTK_CHK_PERIOD] = {0x24, 0, GENMASK(24, 0)},
[MTK_HW_PERIOD] = {0x10, 0, GENMASK(24, 0)},
};
/*
* struct mtk_ir - This is the main datasructure for holding the state
* of the driver
* @dev: The device pointer
* @rc: The rc instrance
* @base: The mapped register i/o base
* @irq: The IRQ that we are using
* @clk: The clock that IR internal is using
* @bus: The clock that software decoder is using
* @data: Holding specific data for vaious platform
*/
struct mtk_ir {
struct device *dev;
struct rc_dev *rc;
void __iomem *base;
int irq;
struct clk *clk;
struct clk *bus;
const struct mtk_ir_data *data;
};
static inline u32 mtk_chkdata_reg(struct mtk_ir *ir, u32 i)
{
return ir->data->regs[MTK_CHKDATA_REG] + 4 * i;
}
static inline u32 mtk_chk_period(struct mtk_ir *ir)
{
u32 val;
/*
* Period for software decoder used in the
* unit of raw software sampling
*/
val = DIV_ROUND_CLOSEST(clk_get_rate(ir->bus),
USEC_PER_SEC * ir->data->div / MTK_IR_SAMPLE);
dev_dbg(ir->dev, "@pwm clk = \t%lu\n",
clk_get_rate(ir->bus) / ir->data->div);
dev_dbg(ir->dev, "@chkperiod = %08x\n", val);
return val;
}
static void mtk_w32_mask(struct mtk_ir *ir, u32 val, u32 mask, unsigned int reg)
{
u32 tmp;
tmp = __raw_readl(ir->base + reg);
tmp = (tmp & ~mask) | val;
__raw_writel(tmp, ir->base + reg);
}
static void mtk_w32(struct mtk_ir *ir, u32 val, unsigned int reg)
{
__raw_writel(val, ir->base + reg);
Annotation
- Immediate include surface: `linux/clk.h`, `linux/interrupt.h`, `linux/module.h`, `linux/io.h`, `linux/of.h`, `linux/platform_device.h`, `linux/reset.h`, `media/rc-core.h`.
- Detected declarations: `struct mtk_field_type`, `struct mtk_ir_data`, `struct mtk_ir`, `enum mtk_fields`, `enum mtk_regs`, `function mtk_chkdata_reg`, `function mtk_chk_period`, `function mtk_w32_mask`, `function mtk_w32`, `function mtk_r32`.
- Atlas domain: Driver Families / drivers/media.
- 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.