drivers/i2c/busses/i2c-stm32f4.c
Source file repositories/reference/linux-study-clean/drivers/i2c/busses/i2c-stm32f4.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/i2c/busses/i2c-stm32f4.c- Extension
.c- Size
- 24269 bytes
- Lines
- 869
- 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.
- 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/delay.hlinux/err.hlinux/i2c.hlinux/interrupt.hlinux/io.hlinux/iopoll.hlinux/module.hlinux/of_address.hlinux/of_irq.hlinux/of.hlinux/platform_device.hlinux/reset.hi2c-stm32.h
Detected Declarations
struct stm32f4_i2c_msgstruct stm32f4_i2c_devfunction stm32f4_i2c_set_bitsfunction stm32f4_i2c_clr_bitsfunction stm32f4_i2c_disable_irqfunction stm32f4_i2c_set_periph_clk_freqfunction stm32f4_i2c_set_rise_timefunction stm32f4_i2c_set_speed_modefunction stm32f4_i2c_hw_configfunction stm32f4_i2c_wait_free_busfunction stm32f4_i2c_write_bytefunction stm32f4_i2c_write_msgfunction stm32f4_i2c_read_msgfunction stm32f4_i2c_terminate_xferfunction stm32f4_i2c_handle_writefunction stm32f4_i2c_handle_readfunction stm32f4_i2c_handle_rx_donefunction stm32f4_i2c_handle_rx_addrfunction stm32f4_i2c_isr_eventfunction BTFfunction stm32f4_i2c_isr_errorfunction stm32f4_i2c_xfer_msgfunction stm32f4_i2c_xferfunction stm32f4_i2c_funcfunction stm32f4_i2c_probefunction stm32f4_i2c_remove
Annotated Snippet
struct stm32f4_i2c_msg {
u8 addr;
u32 count;
u8 *buf;
int result;
bool stop;
};
/**
* struct stm32f4_i2c_dev - private data of the controller
* @adap: I2C adapter for this controller
* @dev: device for this controller
* @base: virtual memory area
* @complete: completion of I2C message
* @clk: hw i2c clock
* @speed: I2C clock frequency of the controller. Standard or Fast are supported
* @parent_rate: I2C clock parent rate in MHz
* @msg: I2C transfer information
*/
struct stm32f4_i2c_dev {
struct i2c_adapter adap;
struct device *dev;
void __iomem *base;
struct completion complete;
struct clk *clk;
int speed;
int parent_rate;
struct stm32f4_i2c_msg msg;
};
static inline void stm32f4_i2c_set_bits(void __iomem *reg, u32 mask)
{
writel_relaxed(readl_relaxed(reg) | mask, reg);
}
static inline void stm32f4_i2c_clr_bits(void __iomem *reg, u32 mask)
{
writel_relaxed(readl_relaxed(reg) & ~mask, reg);
}
static void stm32f4_i2c_disable_irq(struct stm32f4_i2c_dev *i2c_dev)
{
void __iomem *reg = i2c_dev->base + STM32F4_I2C_CR2;
stm32f4_i2c_clr_bits(reg, STM32F4_I2C_CR2_IRQ_MASK);
}
static int stm32f4_i2c_set_periph_clk_freq(struct stm32f4_i2c_dev *i2c_dev)
{
u32 freq;
u32 cr2 = 0;
i2c_dev->parent_rate = clk_get_rate(i2c_dev->clk);
freq = DIV_ROUND_UP(i2c_dev->parent_rate, HZ_TO_MHZ);
if (i2c_dev->speed == STM32_I2C_SPEED_STANDARD) {
/*
* To reach 100 kHz, the parent clk frequency should be between
* a minimum value of 2 MHz and a maximum value of 46 MHz due
* to hardware limitation
*/
if (freq < STM32F4_I2C_MIN_STANDARD_FREQ ||
freq > STM32F4_I2C_MAX_FREQ)
return dev_err_probe(i2c_dev->dev, -EINVAL,
"bad parent clk freq for standard mode\n");
} else {
/*
* To be as close as possible to 400 kHz, the parent clk
* frequency should be between a minimum value of 6 MHz and a
* maximum value of 46 MHz due to hardware limitation
*/
if (freq < STM32F4_I2C_MIN_FAST_FREQ ||
freq > STM32F4_I2C_MAX_FREQ)
return dev_err_probe(i2c_dev->dev, -EINVAL,
"bad parent clk freq for fast mode\n");
}
cr2 |= STM32F4_I2C_CR2_FREQ(freq);
writel_relaxed(cr2, i2c_dev->base + STM32F4_I2C_CR2);
return 0;
}
static void stm32f4_i2c_set_rise_time(struct stm32f4_i2c_dev *i2c_dev)
{
u32 freq = DIV_ROUND_UP(i2c_dev->parent_rate, HZ_TO_MHZ);
u32 trise;
/*
* These bits must be programmed with the maximum SCL rise time given in
Annotation
- Immediate include surface: `linux/clk.h`, `linux/delay.h`, `linux/err.h`, `linux/i2c.h`, `linux/interrupt.h`, `linux/io.h`, `linux/iopoll.h`, `linux/module.h`.
- Detected declarations: `struct stm32f4_i2c_msg`, `struct stm32f4_i2c_dev`, `function stm32f4_i2c_set_bits`, `function stm32f4_i2c_clr_bits`, `function stm32f4_i2c_disable_irq`, `function stm32f4_i2c_set_periph_clk_freq`, `function stm32f4_i2c_set_rise_time`, `function stm32f4_i2c_set_speed_mode`, `function stm32f4_i2c_hw_config`, `function stm32f4_i2c_wait_free_bus`.
- 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.