Merge remote-tracking branch 'xen-tip/linux-next'
[deliverable/linux.git] / drivers / media / platform / exynos4-is / fimc-is-i2c.c
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/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 return ret;
61
62 platform_set_drvdata(pdev, isp_i2c);
63
64 pm_runtime_enable(&pdev->dev);
65 pm_runtime_enable(&i2c_adap->dev);
66
67 return 0;
68 }
69
70 static int fimc_is_i2c_remove(struct platform_device *pdev)
71 {
72 struct fimc_is_i2c *isp_i2c = platform_get_drvdata(pdev);
73
74 pm_runtime_disable(&isp_i2c->adapter.dev);
75 pm_runtime_disable(&pdev->dev);
76 i2c_del_adapter(&isp_i2c->adapter);
77
78 return 0;
79 }
80
81 #ifdef CONFIG_PM
82 static int fimc_is_i2c_runtime_suspend(struct device *dev)
83 {
84 struct fimc_is_i2c *isp_i2c = dev_get_drvdata(dev);
85
86 clk_disable_unprepare(isp_i2c->clock);
87 return 0;
88 }
89
90 static int fimc_is_i2c_runtime_resume(struct device *dev)
91 {
92 struct fimc_is_i2c *isp_i2c = dev_get_drvdata(dev);
93
94 return clk_prepare_enable(isp_i2c->clock);
95 }
96 #endif
97
98 #ifdef CONFIG_PM_SLEEP
99 static int fimc_is_i2c_suspend(struct device *dev)
100 {
101 if (pm_runtime_suspended(dev))
102 return 0;
103
104 return fimc_is_i2c_runtime_suspend(dev);
105 }
106
107 static int fimc_is_i2c_resume(struct device *dev)
108 {
109 if (pm_runtime_suspended(dev))
110 return 0;
111
112 return fimc_is_i2c_runtime_resume(dev);
113 }
114 #endif
115
116 static struct dev_pm_ops fimc_is_i2c_pm_ops = {
117 SET_RUNTIME_PM_OPS(fimc_is_i2c_runtime_suspend,
118 fimc_is_i2c_runtime_resume, NULL)
119 SET_SYSTEM_SLEEP_PM_OPS(fimc_is_i2c_suspend, fimc_is_i2c_resume)
120 };
121
122 static const struct of_device_id fimc_is_i2c_of_match[] = {
123 { .compatible = FIMC_IS_I2C_COMPATIBLE },
124 { },
125 };
126
127 static struct platform_driver fimc_is_i2c_driver = {
128 .probe = fimc_is_i2c_probe,
129 .remove = fimc_is_i2c_remove,
130 .driver = {
131 .of_match_table = fimc_is_i2c_of_match,
132 .name = "fimc-isp-i2c",
133 .pm = &fimc_is_i2c_pm_ops,
134 }
135 };
136
137 int fimc_is_register_i2c_driver(void)
138 {
139 return platform_driver_register(&fimc_is_i2c_driver);
140 }
141
142 void fimc_is_unregister_i2c_driver(void)
143 {
144 platform_driver_unregister(&fimc_is_i2c_driver);
145 }
This page took 0.051079 seconds and 5 git commands to generate.