2 * Samsung EXYNOS4x12 FIMC-IS (Imaging Subsystem) driver
4 * Copyright (C) 2013 Samsung Electronics Co., Ltd.
6 * Author: Sylwester Nawrocki <s.nawrocki@samsung.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
13 #include <linux/clk.h>
14 #include <linux/module.h>
15 #include <linux/i2c.h>
16 #include <linux/platform_device.h>
17 #include <linux/pm_runtime.h>
18 #include <linux/slab.h>
19 #include "fimc-is-i2c.h"
22 struct i2c_adapter adapter
;
27 * An empty algorithm is used as the actual I2C bus controller driver
28 * is implemented in the FIMC-IS subsystem firmware and the host CPU
29 * doesn't access the I2C bus controller.
31 static const struct i2c_algorithm fimc_is_i2c_algorithm
;
33 static int fimc_is_i2c_probe(struct platform_device
*pdev
)
35 struct device_node
*node
= pdev
->dev
.of_node
;
36 struct fimc_is_i2c
*isp_i2c
;
37 struct i2c_adapter
*i2c_adap
;
40 isp_i2c
= devm_kzalloc(&pdev
->dev
, sizeof(*isp_i2c
), GFP_KERNEL
);
44 isp_i2c
->clock
= devm_clk_get(&pdev
->dev
, "i2c_isp");
45 if (IS_ERR(isp_i2c
->clock
)) {
46 dev_err(&pdev
->dev
, "failed to get the clock\n");
47 return PTR_ERR(isp_i2c
->clock
);
50 i2c_adap
= &isp_i2c
->adapter
;
51 i2c_adap
->dev
.of_node
= node
;
52 i2c_adap
->dev
.parent
= &pdev
->dev
;
53 strlcpy(i2c_adap
->name
, "exynos4x12-isp-i2c", sizeof(i2c_adap
->name
));
54 i2c_adap
->owner
= THIS_MODULE
;
55 i2c_adap
->algo
= &fimc_is_i2c_algorithm
;
56 i2c_adap
->class = I2C_CLASS_SPD
;
58 platform_set_drvdata(pdev
, isp_i2c
);
59 pm_runtime_enable(&pdev
->dev
);
61 ret
= i2c_add_adapter(i2c_adap
);
65 * Client drivers of this adapter don't do any I2C transfers as that
66 * is handled by the ISP firmware. But we rely on the runtime PM
67 * state propagation from the clients up to the adapter driver so
68 * clear the ignore_children flags here. PM rutnime calls are not
69 * used in probe() handler of clients of this adapter so there is
70 * no issues with clearing the flag right after registering the I2C
73 pm_suspend_ignore_children(&i2c_adap
->dev
, false);
77 pm_runtime_disable(&pdev
->dev
);
81 static int fimc_is_i2c_remove(struct platform_device
*pdev
)
83 struct fimc_is_i2c
*isp_i2c
= platform_get_drvdata(pdev
);
85 pm_runtime_disable(&pdev
->dev
);
86 i2c_del_adapter(&isp_i2c
->adapter
);
92 static int fimc_is_i2c_runtime_suspend(struct device
*dev
)
94 struct fimc_is_i2c
*isp_i2c
= dev_get_drvdata(dev
);
96 clk_disable_unprepare(isp_i2c
->clock
);
100 static int fimc_is_i2c_runtime_resume(struct device
*dev
)
102 struct fimc_is_i2c
*isp_i2c
= dev_get_drvdata(dev
);
104 return clk_prepare_enable(isp_i2c
->clock
);
108 #ifdef CONFIG_PM_SLEEP
109 static int fimc_is_i2c_suspend(struct device
*dev
)
111 if (pm_runtime_suspended(dev
))
114 return fimc_is_i2c_runtime_suspend(dev
);
117 static int fimc_is_i2c_resume(struct device
*dev
)
119 if (pm_runtime_suspended(dev
))
122 return fimc_is_i2c_runtime_resume(dev
);
126 static struct dev_pm_ops fimc_is_i2c_pm_ops
= {
127 SET_RUNTIME_PM_OPS(fimc_is_i2c_runtime_suspend
,
128 fimc_is_i2c_runtime_resume
, NULL
)
129 SET_SYSTEM_SLEEP_PM_OPS(fimc_is_i2c_suspend
, fimc_is_i2c_resume
)
132 static const struct of_device_id fimc_is_i2c_of_match
[] = {
133 { .compatible
= FIMC_IS_I2C_COMPATIBLE
},
137 static struct platform_driver fimc_is_i2c_driver
= {
138 .probe
= fimc_is_i2c_probe
,
139 .remove
= fimc_is_i2c_remove
,
141 .of_match_table
= fimc_is_i2c_of_match
,
142 .name
= "fimc-isp-i2c",
143 .pm
= &fimc_is_i2c_pm_ops
,
147 int fimc_is_register_i2c_driver(void)
149 return platform_driver_register(&fimc_is_i2c_driver
);
152 void fimc_is_unregister_i2c_driver(void)
154 platform_driver_unregister(&fimc_is_i2c_driver
);