diff options
author | Sylwester Nawrocki <s.nawrocki@samsung.com> | 2013-03-11 14:28:18 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2013-04-04 19:04:49 -0400 |
commit | da114376d325298cce4a7271c4de9bd41c712266 (patch) | |
tree | 1cef9405828eadbe7d3d9695a6ad03fd9bba22e8 /drivers/media | |
parent | 9a761e436843f228eaa2decda6d2c6dbd5ef1480 (diff) |
[media] exynos4-is: Add FIMC-IS ISP I2C bus driver
This patch adds the ISP I2C bus controller driver files.
Creating a standard I2C bus adapter, even if the driver doesn't
actually communicate with the hardware and it is instead
controlled by the ISP firmware running on the Cortex-A5, allows
to use standard hardware description in the device tree. As the
sensor would have actually had a standard V4L2 sub-device driver
run on the host CPU.
This approach allows to adapt the driver with a relatively small
effort should the Imaging Subsystem architecture change so that
the I2C bus is handled by the host's CPU OS, rather than the
internal FIMC-IS ARM CPU firmware. The image sensor driver could
be a standard I2C client driver, as in case of most existing
image sensors.
Signed-off-by: Sylwester Nawrocki <s.nawrocki@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media')
-rw-r--r-- | drivers/media/platform/exynos4-is/fimc-is-i2c.c | 129 | ||||
-rw-r--r-- | drivers/media/platform/exynos4-is/fimc-is-i2c.h | 15 |
2 files changed, 144 insertions, 0 deletions
diff --git a/drivers/media/platform/exynos4-is/fimc-is-i2c.c b/drivers/media/platform/exynos4-is/fimc-is-i2c.c new file mode 100644 index 000000000000..1ec6b3c6a62a --- /dev/null +++ b/drivers/media/platform/exynos4-is/fimc-is-i2c.c | |||
@@ -0,0 +1,129 @@ | |||
1 | /* | ||
2 | * Samsung EXYNOS4x12 FIMC-IS (Imaging Subsystem) driver | ||
3 | * | ||
4 | * Copyright (C) 2013 Samsung Electronics Co., Ltd. | ||
5 | * | ||
6 | * Author: Sylwester Nawrocki <s.nawrocki@samsung.com> | ||
7 | * | ||
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. | ||
11 | */ | ||
12 | |||
13 | #include <linux/clk.h> | ||
14 | #include <linux/module.h> | ||
15 | #include <linux/of_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" | ||
20 | |||
21 | struct fimc_is_i2c { | ||
22 | struct i2c_adapter adapter; | ||
23 | struct clk *clock; | ||
24 | }; | ||
25 | |||
26 | /* | ||
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. | ||
30 | */ | ||
31 | static const struct i2c_algorithm fimc_is_i2c_algorithm; | ||
32 | |||
33 | static int fimc_is_i2c_probe(struct platform_device *pdev) | ||
34 | { | ||
35 | struct device_node *node = pdev->dev.of_node; | ||
36 | struct fimc_is_i2c *isp_i2c; | ||
37 | struct i2c_adapter *i2c_adap; | ||
38 | int ret; | ||
39 | |||
40 | isp_i2c = devm_kzalloc(&pdev->dev, sizeof(*isp_i2c), GFP_KERNEL); | ||
41 | if (!isp_i2c) | ||
42 | return -ENOMEM; | ||
43 | |||
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); | ||
48 | } | ||
49 | |||
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; | ||
57 | |||
58 | ret = i2c_add_adapter(i2c_adap); | ||
59 | if (ret < 0) { | ||
60 | dev_err(&pdev->dev, "failed to add I2C bus %s\n", | ||
61 | node->full_name); | ||
62 | return ret; | ||
63 | } | ||
64 | |||
65 | platform_set_drvdata(pdev, isp_i2c); | ||
66 | |||
67 | pm_runtime_enable(&pdev->dev); | ||
68 | pm_runtime_enable(&i2c_adap->dev); | ||
69 | |||
70 | of_i2c_register_devices(i2c_adap); | ||
71 | |||
72 | return 0; | ||
73 | } | ||
74 | |||
75 | static int fimc_is_i2c_remove(struct platform_device *pdev) | ||
76 | { | ||
77 | struct fimc_is_i2c *isp_i2c = platform_get_drvdata(pdev); | ||
78 | |||
79 | pm_runtime_disable(&isp_i2c->adapter.dev); | ||
80 | pm_runtime_disable(&pdev->dev); | ||
81 | i2c_del_adapter(&isp_i2c->adapter); | ||
82 | |||
83 | return 0; | ||
84 | } | ||
85 | |||
86 | static int fimc_is_i2c_suspend(struct device *dev) | ||
87 | { | ||
88 | struct fimc_is_i2c *isp_i2c = dev_get_drvdata(dev); | ||
89 | clk_disable_unprepare(isp_i2c->clock); | ||
90 | return 0; | ||
91 | } | ||
92 | |||
93 | static int fimc_is_i2c_resume(struct device *dev) | ||
94 | { | ||
95 | struct fimc_is_i2c *isp_i2c = dev_get_drvdata(dev); | ||
96 | return clk_prepare_enable(isp_i2c->clock); | ||
97 | } | ||
98 | |||
99 | UNIVERSAL_DEV_PM_OPS(fimc_is_i2c_pm_ops, fimc_is_i2c_suspend, | ||
100 | fimc_is_i2c_resume, NULL); | ||
101 | |||
102 | static const struct of_device_id fimc_is_i2c_of_match[] = { | ||
103 | { .compatible = FIMC_IS_I2C_COMPATIBLE }, | ||
104 | { }, | ||
105 | }; | ||
106 | MODULE_DEVICE_TABLE(of, fimc_is_i2c_of_match); | ||
107 | |||
108 | static struct platform_driver fimc_is_i2c_driver = { | ||
109 | .probe = fimc_is_i2c_probe, | ||
110 | .remove = fimc_is_i2c_remove, | ||
111 | .driver = { | ||
112 | .of_match_table = fimc_is_i2c_of_match, | ||
113 | .name = "fimc-isp-i2c", | ||
114 | .owner = THIS_MODULE, | ||
115 | .pm = &fimc_is_i2c_pm_ops, | ||
116 | } | ||
117 | }; | ||
118 | |||
119 | int fimc_is_register_i2c_driver(void) | ||
120 | { | ||
121 | return platform_driver_register(&fimc_is_i2c_driver); | ||
122 | } | ||
123 | EXPORT_SYMBOL(fimc_is_register_i2c_driver); | ||
124 | |||
125 | void fimc_is_unregister_i2c_driver(void) | ||
126 | { | ||
127 | platform_driver_unregister(&fimc_is_i2c_driver); | ||
128 | } | ||
129 | EXPORT_SYMBOL(fimc_is_unregister_i2c_driver); | ||
diff --git a/drivers/media/platform/exynos4-is/fimc-is-i2c.h b/drivers/media/platform/exynos4-is/fimc-is-i2c.h new file mode 100644 index 000000000000..0d38d6bb963b --- /dev/null +++ b/drivers/media/platform/exynos4-is/fimc-is-i2c.h | |||
@@ -0,0 +1,15 @@ | |||
1 | /* | ||
2 | * Samsung EXYNOS4x12 FIMC-IS (Imaging Subsystem) driver | ||
3 | * | ||
4 | * Copyright (C) 2013 Samsung Electronics Co., Ltd. | ||
5 | * Sylwester Nawrocki <s.nawrocki@samsung.com> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License version 2 as | ||
9 | * published by the Free Software Foundation. | ||
10 | */ | ||
11 | |||
12 | #define FIMC_IS_I2C_COMPATIBLE "samsung,exynos4212-i2c-isp" | ||
13 | |||
14 | int fimc_is_register_i2c_driver(void); | ||
15 | void fimc_is_unregister_i2c_driver(void); | ||