drivers/i2c/busses/i2c-designware-amdisp.c

Source file repositories/reference/linux-study-clean/drivers/i2c/busses/i2c-designware-amdisp.c

File Facts

System
Linux kernel
Corpus path
drivers/i2c/busses/i2c-designware-amdisp.c
Extension
.c
Size
5130 bytes
Lines
196
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.

Dependency Surface

Detected Declarations

Annotated Snippet

// SPDX-License-Identifier: GPL-2.0+
/*
 * Based on Synopsys DesignWare I2C adapter driver.
 *
 * Copyright (C) 2025 Advanced Micro Devices, Inc.
 */

#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/pm_domain.h>
#include <linux/pm_runtime.h>
#include <linux/soc/amd/isp4_misc.h>

#include "i2c-designware-core.h"

#define DRV_NAME		"amd_isp_i2c_designware"
#define AMD_ISP_I2C_INPUT_CLK	100 /* Mhz */

static void amd_isp_dw_i2c_plat_pm_cleanup(struct dw_i2c_dev *i2c_dev)
{
	pm_runtime_disable(i2c_dev->dev);
}

static inline u32 amd_isp_dw_i2c_get_clk_rate(struct dw_i2c_dev *i2c_dev)
{
	return AMD_ISP_I2C_INPUT_CLK * 1000;
}

static int amd_isp_dw_i2c_plat_probe(struct platform_device *pdev)
{
	struct dw_i2c_dev *isp_i2c_dev;
	struct i2c_adapter *adap;
	int ret;

	isp_i2c_dev = devm_kzalloc(&pdev->dev, sizeof(*isp_i2c_dev), GFP_KERNEL);
	if (!isp_i2c_dev)
		return -ENOMEM;
	isp_i2c_dev->dev = &pdev->dev;

	pdev->dev.init_name = DRV_NAME;

	/*
	 * Use the polling mode to send/receive the data, because
	 * no IRQ connection from ISP I2C
	 */
	isp_i2c_dev->flags |= ACCESS_POLLING;
	platform_set_drvdata(pdev, isp_i2c_dev);

	isp_i2c_dev->base = devm_platform_ioremap_resource(pdev, 0);
	if (IS_ERR(isp_i2c_dev->base))
		return dev_err_probe(&pdev->dev, PTR_ERR(isp_i2c_dev->base),
				     "failed to get IOMEM resource\n");

	isp_i2c_dev->get_clk_rate_khz = amd_isp_dw_i2c_get_clk_rate;
	ret = i2c_dw_fw_parse_and_configure(isp_i2c_dev);
	if (ret)
		return dev_err_probe(&pdev->dev, ret,
				     "failed to parse i2c dw fwnode and configure\n");

	i2c_dw_configure(isp_i2c_dev);

	adap = &isp_i2c_dev->adapter;
	adap->owner = THIS_MODULE;
	scnprintf(adap->name, sizeof(adap->name), AMDISP_I2C_ADAP_NAME);
	ACPI_COMPANION_SET(&adap->dev, ACPI_COMPANION(&pdev->dev));
	adap->dev.of_node = pdev->dev.of_node;
	/* use dynamically allocated adapter id */
	adap->nr = -1;

	if (isp_i2c_dev->flags & ACCESS_NO_IRQ_SUSPEND)
		dev_pm_set_driver_flags(&pdev->dev,
					DPM_FLAG_SMART_PREPARE);
	else
		dev_pm_set_driver_flags(&pdev->dev,
					DPM_FLAG_SMART_PREPARE |
					DPM_FLAG_SMART_SUSPEND);

	device_enable_async_suspend(&pdev->dev);

	dev_pm_genpd_resume(&pdev->dev);
	ret = i2c_dw_probe(isp_i2c_dev);
	if (ret) {
		dev_err_probe(&pdev->dev, ret, "i2c_dw_probe failed\n");
		goto error_release_rpm;
	}
	dev_pm_genpd_suspend(&pdev->dev);
	pm_runtime_set_suspended(&pdev->dev);
	pm_runtime_enable(&pdev->dev);

	return 0;

Annotation

Implementation Notes