drivers/i2c/busses/i2c-viai2c-wmt.c
Source file repositories/reference/linux-study-clean/drivers/i2c/busses/i2c-viai2c-wmt.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/i2c/busses/i2c-viai2c-wmt.c- Extension
.c- Size
- 4411 bytes
- Lines
- 179
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/clk.hlinux/of.hlinux/of_address.hi2c-viai2c-common.h
Detected Declarations
function Copyrightfunction wmt_i2c_reset_hardwarefunction wmt_i2c_isrfunction wmt_i2c_probefunction wmt_i2c_remove
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Wondermedia I2C Controller Driver
*
* Copyright (C) 2012 Tony Prisk <linux@prisktech.co.nz>
*
* Derived from GPLv2+ licensed source:
* - Copyright (C) 2008 WonderMedia Technologies, Inc.
*/
#include <linux/clk.h>
#include <linux/of.h>
#include <linux/of_address.h>
#include "i2c-viai2c-common.h"
#define REG_SLAVE_CR 0x10
#define REG_SLAVE_SR 0x12
#define REG_SLAVE_ISR 0x14
#define REG_SLAVE_IMR 0x16
#define REG_SLAVE_DR 0x18
#define REG_SLAVE_TR 0x1A
/* REG_TR */
#define SCL_TIMEOUT(x) (((x) & 0xFF) << 8)
#define TR_STD 0x0064
#define TR_HS 0x0019
/* REG_MCR */
#define MCR_APB_96M 7
#define MCR_APB_166M 12
static u32 wmt_i2c_func(struct i2c_adapter *adap)
{
return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | I2C_FUNC_NOSTART;
}
static const struct i2c_algorithm wmt_i2c_algo = {
.xfer = viai2c_xfer,
.functionality = wmt_i2c_func,
};
static int wmt_i2c_reset_hardware(struct viai2c *i2c)
{
int err;
err = clk_prepare_enable(i2c->clk);
if (err)
return dev_err_probe(i2c->dev, err, "failed to enable clock\n");
err = clk_set_rate(i2c->clk, 20000000);
if (err) {
clk_disable_unprepare(i2c->clk);
return dev_err_probe(i2c->dev, err, "failed to set clock = 20Mhz\n");
}
writew(0, i2c->base + VIAI2C_REG_CR);
writew(MCR_APB_166M, i2c->base + VIAI2C_REG_MCR);
writew(VIAI2C_ISR_MASK_ALL, i2c->base + VIAI2C_REG_ISR);
writew(VIAI2C_IMR_ENABLE_ALL, i2c->base + VIAI2C_REG_IMR);
writew(VIAI2C_CR_ENABLE, i2c->base + VIAI2C_REG_CR);
readw(i2c->base + VIAI2C_REG_CSR); /* read clear */
writew(VIAI2C_ISR_MASK_ALL, i2c->base + VIAI2C_REG_ISR);
if (i2c->tcr == VIAI2C_TCR_FAST)
writew(SCL_TIMEOUT(128) | TR_HS, i2c->base + VIAI2C_REG_TR);
else
writew(SCL_TIMEOUT(128) | TR_STD, i2c->base + VIAI2C_REG_TR);
return 0;
}
static irqreturn_t wmt_i2c_isr(int irq, void *data)
{
struct viai2c *i2c = data;
u8 status;
/* save the status and write-clear it */
status = readw(i2c->base + VIAI2C_REG_ISR);
writew(status, i2c->base + VIAI2C_REG_ISR);
i2c->ret = 0;
if (status & VIAI2C_ISR_NACK_ADDR)
i2c->ret = -EIO;
if (status & VIAI2C_ISR_SCL_TIMEOUT)
i2c->ret = -ETIMEDOUT;
if (!i2c->ret)
i2c->ret = viai2c_irq_xfer(i2c);
Annotation
- Immediate include surface: `linux/clk.h`, `linux/of.h`, `linux/of_address.h`, `i2c-viai2c-common.h`.
- Detected declarations: `function Copyright`, `function wmt_i2c_reset_hardware`, `function wmt_i2c_isr`, `function wmt_i2c_probe`, `function wmt_i2c_remove`.
- Atlas domain: Driver Families / drivers/i2c.
- 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.