forked from Minki/linux
91f2a7b24b
Add simple 'functionality' member to dummy Exynos IS i2c adapter to make i2c core happy and get rid of NULL pointer dereference during Exynos4 IS probe since v4.10-rc1: Unable to handle kernel NULL pointer dereference at virtual address 00000000 pgd = c0004000 [00000000] *pgd=00000000 Internal error: Oops: 80000005 [#1] PREEMPT SMP ARM Modules linked in: CPU: 1 PID: 100 Comm: kworker/1:2 Not tainted 4.10.0-rc6-next-20170131-00054-g39e6e4233de6 #1921 Hardware name: SAMSUNG EXYNOS (Flattened Device Tree) Workqueue: events deferred_probe_work_func task: ef2e0000 task.stack: ef2ec000 PC is at 0x0 LR is at i2c_register_adapter+0x98/0x5cc ... [<c05040bc>] (i2c_register_adapter) from [<c05379d4>] (fimc_is_i2c_probe+0x84/0xe4) [<c05379d4>] (fimc_is_i2c_probe) from [<c041b5c8>] (platform_drv_probe+0x50/0xb0) [<c041b5c8>] (platform_drv_probe) from [<c0419f48>] (driver_probe_device+0x234/0x2dc) [<c0419f48>] (driver_probe_device) from [<c04184e0>] (bus_for_each_drv+0x44/0x8c) [<c04184e0>] (bus_for_each_drv) from [<c0419c8c>] (__device_attach+0x9c/0x100) [<c0419c8c>] (__device_attach) from [<c0419374>] (bus_probe_device+0x84/0x8c) [<c0419374>] (bus_probe_device) from [<c04178d4>] (device_add+0x380/0x528) [<c04178d4>] (device_add) from [<c05aceb4>] (of_platform_device_create_pdata+0x70/0xa4) [<c05aceb4>] (of_platform_device_create_pdata) from [<c05acfd4>] (of_platform_bus_create+0xec/0x320) [<c05acfd4>] (of_platform_bus_create) from [<c05ad264>] (of_platform_populate+0x5c/0xac) [<c05ad264>] (of_platform_populate) from [<c0533420>] (fimc_is_probe+0x1c0/0x4cc) [<c0533420>] (fimc_is_probe) from [<c041b5c8>] (platform_drv_probe+0x50/0xb0) [<c041b5c8>] (platform_drv_probe) from [<c0419f48>] (driver_probe_device+0x234/0x2dc) [<c0419f48>] (driver_probe_device) from [<c04184e0>] (bus_for_each_drv+0x44/0x8c) [<c04184e0>] (bus_for_each_drv) from [<c0419c8c>] (__device_attach+0x9c/0x100) [<c0419c8c>] (__device_attach) from [<c0419374>] (bus_probe_device+0x84/0x8c) [<c0419374>] (bus_probe_device) from [<c04197a8>] (deferred_probe_work_func+0x60/0x8c) [<c04197a8>] (deferred_probe_work_func) from [<c01329a4>] (process_one_work+0x120/0x31c) [<c01329a4>] (process_one_work) from [<c0132bc8>] (process_scheduled_works+0x28/0x38) [<c0132bc8>] (process_scheduled_works) from [<c0132ddc>] (worker_thread+0x204/0x4ac) [<c0132ddc>] (worker_thread) from [<c01381b8>] (kthread+0xfc/0x134) [<c01381b8>] (kthread) from [<c01078b8>] (ret_from_fork+0x14/0x3c) Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
163 lines
3.9 KiB
C
163 lines
3.9 KiB
C
/*
|
|
* Samsung EXYNOS4x12 FIMC-IS (Imaging Subsystem) driver
|
|
*
|
|
* Copyright (C) 2013 Samsung Electronics Co., Ltd.
|
|
*
|
|
* Author: Sylwester Nawrocki <s.nawrocki@samsung.com>
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
* published by the Free Software Foundation.
|
|
*/
|
|
|
|
#include <linux/clk.h>
|
|
#include <linux/module.h>
|
|
#include <linux/i2c.h>
|
|
#include <linux/platform_device.h>
|
|
#include <linux/pm_runtime.h>
|
|
#include <linux/slab.h>
|
|
#include "fimc-is-i2c.h"
|
|
|
|
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;
|
|
strlcpy(i2c_adap->name, "exynos4x12-isp-i2c", sizeof(i2c_adap->name));
|
|
i2c_adap->owner = THIS_MODULE;
|
|
i2c_adap->algo = &fimc_is_i2c_algorithm;
|
|
i2c_adap->class = I2C_CLASS_SPD;
|
|
|
|
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 int 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);
|
|
|
|
return 0;
|
|
}
|
|
|
|
#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
|
|
|
|
#ifdef CONFIG_PM_SLEEP
|
|
static int fimc_is_i2c_suspend(struct device *dev)
|
|
{
|
|
if (pm_runtime_suspended(dev))
|
|
return 0;
|
|
|
|
return fimc_is_i2c_runtime_suspend(dev);
|
|
}
|
|
|
|
static int fimc_is_i2c_resume(struct device *dev)
|
|
{
|
|
if (pm_runtime_suspended(dev))
|
|
return 0;
|
|
|
|
return fimc_is_i2c_runtime_resume(dev);
|
|
}
|
|
#endif
|
|
|
|
static struct dev_pm_ops fimc_is_i2c_pm_ops = {
|
|
SET_RUNTIME_PM_OPS(fimc_is_i2c_runtime_suspend,
|
|
fimc_is_i2c_runtime_resume, NULL)
|
|
SET_SYSTEM_SLEEP_PM_OPS(fimc_is_i2c_suspend, fimc_is_i2c_resume)
|
|
};
|
|
|
|
static const struct of_device_id fimc_is_i2c_of_match[] = {
|
|
{ .compatible = FIMC_IS_I2C_COMPATIBLE },
|
|
{ },
|
|
};
|
|
|
|
static struct platform_driver fimc_is_i2c_driver = {
|
|
.probe = fimc_is_i2c_probe,
|
|
.remove = fimc_is_i2c_remove,
|
|
.driver = {
|
|
.of_match_table = fimc_is_i2c_of_match,
|
|
.name = "fimc-isp-i2c",
|
|
.pm = &fimc_is_i2c_pm_ops,
|
|
}
|
|
};
|
|
|
|
int fimc_is_register_i2c_driver(void)
|
|
{
|
|
return platform_driver_register(&fimc_is_i2c_driver);
|
|
}
|
|
|
|
void fimc_is_unregister_i2c_driver(void)
|
|
{
|
|
platform_driver_unregister(&fimc_is_i2c_driver);
|
|
}
|