drivers/media/platform/samsung/exynos4-is/fimc-is-i2c.c

Source file repositories/reference/linux-study-clean/drivers/media/platform/samsung/exynos4-is/fimc-is-i2c.c

File Facts

System
Linux kernel
Corpus path
drivers/media/platform/samsung/exynos4-is/fimc-is-i2c.c
Extension
.c
Size
3856 bytes
Lines
157
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.

Dependency Surface

Detected Declarations

Annotated Snippet

struct fimc_is_i2c {
	struct i2c_adapter adapter;
	struct clk *clock;
};

/*
 * An empty algorithm is used as the actual I2C bus controller driver
 * is implemented in the FIMC-IS subsystem firmware and the host CPU
 * doesn't access the I2C bus controller.
 */
static u32 is_i2c_func(struct i2c_adapter *adap)
{
	return I2C_FUNC_I2C;
}

static const struct i2c_algorithm fimc_is_i2c_algorithm = {
	.functionality	= is_i2c_func,
};

static int fimc_is_i2c_probe(struct platform_device *pdev)
{
	struct device_node *node = pdev->dev.of_node;
	struct fimc_is_i2c *isp_i2c;
	struct i2c_adapter *i2c_adap;
	int ret;

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

	isp_i2c->clock = devm_clk_get(&pdev->dev, "i2c_isp");
	if (IS_ERR(isp_i2c->clock)) {
		dev_err(&pdev->dev, "failed to get the clock\n");
		return PTR_ERR(isp_i2c->clock);
	}

	i2c_adap = &isp_i2c->adapter;
	i2c_adap->dev.of_node = node;
	i2c_adap->dev.parent = &pdev->dev;
	strscpy(i2c_adap->name, "exynos4x12-isp-i2c", sizeof(i2c_adap->name));
	i2c_adap->owner = THIS_MODULE;
	i2c_adap->algo = &fimc_is_i2c_algorithm;

	platform_set_drvdata(pdev, isp_i2c);
	pm_runtime_enable(&pdev->dev);

	ret = i2c_add_adapter(i2c_adap);
	if (ret < 0)
		goto err_pm_dis;
	/*
	 * Client drivers of this adapter don't do any I2C transfers as that
	 * is handled by the ISP firmware.  But we rely on the runtime PM
	 * state propagation from the clients up to the adapter driver so
	 * clear the ignore_children flags here.  PM rutnime calls are not
	 * used in probe() handler of clients of this adapter so there is
	 * no issues with clearing the flag right after registering the I2C
	 * adapter.
	 */
	pm_suspend_ignore_children(&i2c_adap->dev, false);
	return 0;

err_pm_dis:
	pm_runtime_disable(&pdev->dev);
	return ret;
}

static void fimc_is_i2c_remove(struct platform_device *pdev)
{
	struct fimc_is_i2c *isp_i2c = platform_get_drvdata(pdev);

	pm_runtime_disable(&pdev->dev);
	i2c_del_adapter(&isp_i2c->adapter);
}

#ifdef CONFIG_PM
static int fimc_is_i2c_runtime_suspend(struct device *dev)
{
	struct fimc_is_i2c *isp_i2c = dev_get_drvdata(dev);

	clk_disable_unprepare(isp_i2c->clock);
	return 0;
}

static int fimc_is_i2c_runtime_resume(struct device *dev)
{
	struct fimc_is_i2c *isp_i2c = dev_get_drvdata(dev);

	return clk_prepare_enable(isp_i2c->clock);
}
#endif

Annotation

Implementation Notes