drivers/i2c/busses/i2c-pasemi-platform.c
Source file repositories/reference/linux-study-clean/drivers/i2c/busses/i2c-pasemi-platform.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/i2c/busses/i2c-pasemi-platform.c- Extension
.c- Size
- 2876 bytes
- Lines
- 114
- 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/i2c.hlinux/io.hlinux/kernel.hlinux/module.hlinux/platform_device.hlinux/types.hi2c-pasemi-core.h
Detected Declarations
struct pasemi_platform_i2c_datafunction pasemi_platform_i2c_calc_clk_divfunction pasemi_platform_i2c_probefunction pasemi_platform_i2c_remove
Annotated Snippet
struct pasemi_platform_i2c_data {
struct pasemi_smbus smbus;
struct clk *clk_ref;
};
static int
pasemi_platform_i2c_calc_clk_div(struct pasemi_platform_i2c_data *data,
u32 frequency)
{
unsigned long clk_rate = clk_get_rate(data->clk_ref);
if (!clk_rate)
return -EINVAL;
data->smbus.clk_div = DIV_ROUND_UP(clk_rate, 16 * frequency);
if (data->smbus.clk_div < 4)
return dev_err_probe(data->smbus.dev, -EINVAL,
"Bus frequency %d is too fast.\n",
frequency);
if (data->smbus.clk_div > 0xff)
return dev_err_probe(data->smbus.dev, -EINVAL,
"Bus frequency %d is too slow.\n",
frequency);
return 0;
}
static int pasemi_platform_i2c_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct pasemi_platform_i2c_data *data;
struct pasemi_smbus *smbus;
u32 frequency;
int error;
int irq_num;
data = devm_kzalloc(dev, sizeof(struct pasemi_platform_i2c_data),
GFP_KERNEL);
if (!data)
return -ENOMEM;
smbus = &data->smbus;
smbus->dev = dev;
smbus->ioaddr = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(smbus->ioaddr))
return PTR_ERR(smbus->ioaddr);
if (of_property_read_u32(dev->of_node, "clock-frequency", &frequency))
frequency = I2C_MAX_STANDARD_MODE_FREQ;
data->clk_ref = devm_clk_get_enabled(dev, NULL);
if (IS_ERR(data->clk_ref))
return PTR_ERR(data->clk_ref);
error = pasemi_platform_i2c_calc_clk_div(data, frequency);
if (error)
return error;
smbus->adapter.dev.of_node = pdev->dev.of_node;
error = pasemi_i2c_common_probe(smbus);
if (error)
return error;
irq_num = platform_get_irq(pdev, 0);
error = devm_request_irq(smbus->dev, irq_num, pasemi_irq_handler, 0, "pasemi_apple_i2c", (void *)smbus);
if (!error)
smbus->use_irq = 1;
platform_set_drvdata(pdev, data);
return 0;
}
static void pasemi_platform_i2c_remove(struct platform_device *pdev) { }
static const struct of_device_id pasemi_platform_i2c_of_match[] = {
{ .compatible = "apple,t8103-i2c" },
{ .compatible = "apple,i2c" },
{},
};
MODULE_DEVICE_TABLE(of, pasemi_platform_i2c_of_match);
static struct platform_driver pasemi_platform_i2c_driver = {
.driver = {
.name = "i2c-apple",
.of_match_table = pasemi_platform_i2c_of_match,
},
.probe = pasemi_platform_i2c_probe,
.remove = pasemi_platform_i2c_remove,
Annotation
- Immediate include surface: `linux/clk.h`, `linux/i2c.h`, `linux/io.h`, `linux/kernel.h`, `linux/module.h`, `linux/platform_device.h`, `linux/types.h`, `i2c-pasemi-core.h`.
- Detected declarations: `struct pasemi_platform_i2c_data`, `function pasemi_platform_i2c_calc_clk_div`, `function pasemi_platform_i2c_probe`, `function pasemi_platform_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.