video: tegra: host: add DT support
[linux-2.6.git] / drivers / video / tegra / host / gr2d / gr2d.c
1 /*
2  * drivers/video/tegra/host/gr2d/gr2d.c
3  *
4  * Tegra Graphics 2D
5  *
6  * Copyright (c) 2012-2013, NVIDIA Corporation. All rights reserved.
7  *
8  * This program is free software; you can redistribute it and/or modify it
9  * under the terms and conditions of the GNU General Public License,
10  * version 2, as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
15  * more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19  */
20
21 #include <linux/export.h>
22 #include <linux/module.h>
23 #include <linux/pm_runtime.h>
24 #include <linux/of.h>
25 #include <linux/of_device.h>
26 #include <linux/of_platform.h>
27
28 #include "dev.h"
29 #include "bus_client.h"
30 #include "gr2d_t30.h"
31 #include "gr2d_t114.h"
32 #include "t20/t20.h"
33 #include "t30/t30.h"
34 #include "t114/t114.h"
35
36 static struct of_device_id tegra_gr2d_of_match[] __devinitdata = {
37         { .compatible = "nvidia,tegra20-gr2d",
38                 .data = (struct nvhost_device_data *)&t20_gr2d_info },
39         { .compatible = "nvidia,tegra30-gr2d",
40                 .data = (struct nvhost_device_data *)&t30_gr2d_info },
41         { .compatible = "nvidia,tegra114-gr2d",
42                 .data = (struct nvhost_device_data *)&t11_gr2d_info },
43         { },
44 };
45 static int __devinit gr2d_probe(struct platform_device *dev)
46 {
47         int err = 0;
48         struct nvhost_device_data *pdata = NULL;
49
50         if (dev->dev.of_node) {
51                 const struct of_device_id *match;
52
53                 match = of_match_device(tegra_gr2d_of_match, &dev->dev);
54                 if (match)
55                         pdata = (struct nvhost_device_data *)match->data;
56         } else
57                 pdata = (struct nvhost_device_data *)dev->dev.platform_data;
58
59         WARN_ON(!pdata);
60         if (!pdata) {
61                 dev_info(&dev->dev, "no platform data\n");
62                 return -ENODATA;
63         }
64         pdata->pdev = dev;
65         platform_set_drvdata(dev, pdata);
66
67         err = nvhost_client_device_init(dev);
68         if (err)
69                 return err;
70
71         pm_runtime_use_autosuspend(&dev->dev);
72         pm_runtime_set_autosuspend_delay(&dev->dev, 100);
73         pm_runtime_enable(&dev->dev);
74
75         return 0;
76 }
77
78 static int __exit gr2d_remove(struct platform_device *dev)
79 {
80         /* Add clean-up */
81         return 0;
82 }
83
84 #ifdef CONFIG_PM
85 static int gr2d_suspend(struct platform_device *dev, pm_message_t state)
86 {
87         return nvhost_client_device_suspend(dev);
88 }
89
90 static int gr2d_resume(struct platform_device *dev)
91 {
92         dev_info(&dev->dev, "resuming\n");
93         return 0;
94 }
95 #endif
96
97 static struct platform_driver gr2d_driver = {
98         .probe = gr2d_probe,
99         .remove = __exit_p(gr2d_remove),
100 #ifdef CONFIG_PM
101         .suspend = gr2d_suspend,
102         .resume = gr2d_resume,
103 #endif
104         .driver = {
105                 .owner = THIS_MODULE,
106                 .name = "gr2d",
107 #ifdef CONFIG_OF
108                 .of_match_table = tegra_gr2d_of_match,
109 #endif
110         },
111 };
112
113 static int __init gr2d_init(void)
114 {
115         return platform_driver_register(&gr2d_driver);
116 }
117
118 static void __exit gr2d_exit(void)
119 {
120         platform_driver_unregister(&gr2d_driver);
121 }
122
123 module_init(gr2d_init);
124 module_exit(gr2d_exit);