OMAP: DSS2: Use omap_pm_get_dev_context_loss_count to get ctx loss count
[pandora-kernel.git] / arch / arm / mach-omap2 / display.c
1 /*
2  * OMAP2plus display device setup / initialization.
3  *
4  * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
5  *      Senthilvadivu Guruswamy
6  *      Sumit Semwal
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  * This program is distributed "as is" WITHOUT ANY WARRANTY of any
13  * kind, whether express or implied; without even the implied warranty
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  */
17
18 #include <linux/kernel.h>
19 #include <linux/init.h>
20 #include <linux/platform_device.h>
21 #include <linux/io.h>
22 #include <linux/clk.h>
23 #include <linux/err.h>
24
25 #include <video/omapdss.h>
26 #include <plat/omap_hwmod.h>
27 #include <plat/omap_device.h>
28 #include <plat/omap-pm.h>
29
30 static struct platform_device omap_display_device = {
31         .name          = "omapdss",
32         .id            = -1,
33         .dev            = {
34                 .platform_data = NULL,
35         },
36 };
37
38 static struct omap_device_pm_latency omap_dss_latency[] = {
39         [0] = {
40                 .deactivate_func        = omap_device_idle_hwmods,
41                 .activate_func          = omap_device_enable_hwmods,
42                 .flags                  = OMAP_DEVICE_LATENCY_AUTO_ADJUST,
43         },
44 };
45
46 /* oh_core is used for getting opt-clocks */
47 static struct omap_hwmod        *oh_core;
48
49 static bool opt_clock_available(const char *clk_role)
50 {
51         int i;
52
53         for (i = 0; i < oh_core->opt_clks_cnt; i++) {
54                 if (!strcmp(oh_core->opt_clks[i].role, clk_role))
55                         return true;
56         }
57         return false;
58 }
59
60 struct omap_dss_hwmod_data {
61         const char *oh_name;
62         const char *dev_name;
63         const int id;
64 };
65
66 static const struct omap_dss_hwmod_data omap2_dss_hwmod_data[] __initdata = {
67         { "dss_core", "omapdss_dss", -1 },
68         { "dss_dispc", "omapdss_dispc", -1 },
69         { "dss_rfbi", "omapdss_rfbi", -1 },
70         { "dss_venc", "omapdss_venc", -1 },
71 };
72
73 static const struct omap_dss_hwmod_data omap3_dss_hwmod_data[] __initdata = {
74         { "dss_core", "omapdss_dss", -1 },
75         { "dss_dispc", "omapdss_dispc", -1 },
76         { "dss_rfbi", "omapdss_rfbi", -1 },
77         { "dss_venc", "omapdss_venc", -1 },
78         { "dss_dsi1", "omapdss_dsi1", -1 },
79 };
80
81 static const struct omap_dss_hwmod_data omap4_dss_hwmod_data[] __initdata = {
82         { "dss_core", "omapdss_dss", -1 },
83         { "dss_dispc", "omapdss_dispc", -1 },
84         { "dss_rfbi", "omapdss_rfbi", -1 },
85         { "dss_venc", "omapdss_venc", -1 },
86         { "dss_dsi1", "omapdss_dsi1", -1 },
87         { "dss_dsi2", "omapdss_dsi2", -1 },
88         { "dss_hdmi", "omapdss_hdmi", -1 },
89 };
90
91 int __init omap_display_init(struct omap_dss_board_info *board_data)
92 {
93         int r = 0;
94         struct omap_hwmod *oh;
95         struct omap_device *od;
96         int i, oh_count;
97         struct omap_display_platform_data pdata;
98         const struct omap_dss_hwmod_data *curr_dss_hwmod;
99
100         memset(&pdata, 0, sizeof(pdata));
101
102         if (cpu_is_omap24xx()) {
103                 curr_dss_hwmod = omap2_dss_hwmod_data;
104                 oh_count = ARRAY_SIZE(omap2_dss_hwmod_data);
105         } else if (cpu_is_omap34xx()) {
106                 curr_dss_hwmod = omap3_dss_hwmod_data;
107                 oh_count = ARRAY_SIZE(omap3_dss_hwmod_data);
108         } else {
109                 curr_dss_hwmod = omap4_dss_hwmod_data;
110                 oh_count = ARRAY_SIZE(omap4_dss_hwmod_data);
111         }
112
113         /* opt_clks are always associated with dss hwmod */
114         oh_core = omap_hwmod_lookup("dss_core");
115         if (!oh_core) {
116                 pr_err("Could not look up dss_core.\n");
117                 return -ENODEV;
118         }
119
120         pdata.board_data = board_data;
121         pdata.board_data->get_context_loss_count =
122                 omap_pm_get_dev_context_loss_count;
123         pdata.opt_clock_available = opt_clock_available;
124
125         for (i = 0; i < oh_count; i++) {
126                 oh = omap_hwmod_lookup(curr_dss_hwmod[i].oh_name);
127                 if (!oh) {
128                         pr_err("Could not look up %s\n",
129                                 curr_dss_hwmod[i].oh_name);
130                         return -ENODEV;
131                 }
132
133                 od = omap_device_build(curr_dss_hwmod[i].dev_name,
134                                 curr_dss_hwmod[i].id, oh, &pdata,
135                                 sizeof(struct omap_display_platform_data),
136                                 omap_dss_latency,
137                                 ARRAY_SIZE(omap_dss_latency), 0);
138
139                 if (WARN((IS_ERR(od)), "Could not build omap_device for %s\n",
140                                 curr_dss_hwmod[i].oh_name))
141                         return -ENODEV;
142         }
143         omap_display_device.dev.platform_data = board_data;
144
145         r = platform_device_register(&omap_display_device);
146         if (r < 0)
147                 printk(KERN_ERR "Unable to register OMAP-Display device\n");
148
149         return r;
150 }