Merge branch 'next' of git://github.com/kernelslacker/cpufreq
[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 #include "control.h"
31
32 static struct platform_device omap_display_device = {
33         .name          = "omapdss",
34         .id            = -1,
35         .dev            = {
36                 .platform_data = NULL,
37         },
38 };
39
40 struct omap_dss_hwmod_data {
41         const char *oh_name;
42         const char *dev_name;
43         const int id;
44 };
45
46 static const struct omap_dss_hwmod_data omap2_dss_hwmod_data[] __initdata = {
47         { "dss_core", "omapdss_dss", -1 },
48         { "dss_dispc", "omapdss_dispc", -1 },
49         { "dss_rfbi", "omapdss_rfbi", -1 },
50         { "dss_venc", "omapdss_venc", -1 },
51 };
52
53 static const struct omap_dss_hwmod_data omap3_dss_hwmod_data[] __initdata = {
54         { "dss_core", "omapdss_dss", -1 },
55         { "dss_dispc", "omapdss_dispc", -1 },
56         { "dss_rfbi", "omapdss_rfbi", -1 },
57         { "dss_venc", "omapdss_venc", -1 },
58         { "dss_dsi1", "omapdss_dsi", 0 },
59 };
60
61 static const struct omap_dss_hwmod_data omap4_dss_hwmod_data[] __initdata = {
62         { "dss_core", "omapdss_dss", -1 },
63         { "dss_dispc", "omapdss_dispc", -1 },
64         { "dss_rfbi", "omapdss_rfbi", -1 },
65         { "dss_venc", "omapdss_venc", -1 },
66         { "dss_dsi1", "omapdss_dsi", 0 },
67         { "dss_dsi2", "omapdss_dsi", 1 },
68         { "dss_hdmi", "omapdss_hdmi", -1 },
69 };
70
71 static int omap4_dsi_mux_pads(int dsi_id, unsigned lanes)
72 {
73         u32 enable_mask, enable_shift;
74         u32 pipd_mask, pipd_shift;
75         u32 reg;
76
77         if (dsi_id == 0) {
78                 enable_mask = OMAP4_DSI1_LANEENABLE_MASK;
79                 enable_shift = OMAP4_DSI1_LANEENABLE_SHIFT;
80                 pipd_mask = OMAP4_DSI1_PIPD_MASK;
81                 pipd_shift = OMAP4_DSI1_PIPD_SHIFT;
82         } else if (dsi_id == 1) {
83                 enable_mask = OMAP4_DSI2_LANEENABLE_MASK;
84                 enable_shift = OMAP4_DSI2_LANEENABLE_SHIFT;
85                 pipd_mask = OMAP4_DSI2_PIPD_MASK;
86                 pipd_shift = OMAP4_DSI2_PIPD_SHIFT;
87         } else {
88                 return -ENODEV;
89         }
90
91         reg = omap4_ctrl_pad_readl(OMAP4_CTRL_MODULE_PAD_CORE_CONTROL_DSIPHY);
92
93         reg &= ~enable_mask;
94         reg &= ~pipd_mask;
95
96         reg |= (lanes << enable_shift) & enable_mask;
97         reg |= (lanes << pipd_shift) & pipd_mask;
98
99         omap4_ctrl_pad_writel(reg, OMAP4_CTRL_MODULE_PAD_CORE_CONTROL_DSIPHY);
100
101         return 0;
102 }
103
104 static int omap_dsi_enable_pads(int dsi_id, unsigned lane_mask)
105 {
106         if (cpu_is_omap44xx())
107                 return omap4_dsi_mux_pads(dsi_id, lane_mask);
108
109         return 0;
110 }
111
112 static void omap_dsi_disable_pads(int dsi_id, unsigned lane_mask)
113 {
114         if (cpu_is_omap44xx())
115                 omap4_dsi_mux_pads(dsi_id, 0);
116 }
117
118 int __init omap_display_init(struct omap_dss_board_info *board_data)
119 {
120         int r = 0;
121         struct omap_hwmod *oh;
122         struct platform_device *pdev;
123         int i, oh_count;
124         struct omap_display_platform_data pdata;
125         const struct omap_dss_hwmod_data *curr_dss_hwmod;
126
127         memset(&pdata, 0, sizeof(pdata));
128
129         if (cpu_is_omap24xx()) {
130                 curr_dss_hwmod = omap2_dss_hwmod_data;
131                 oh_count = ARRAY_SIZE(omap2_dss_hwmod_data);
132         } else if (cpu_is_omap34xx()) {
133                 curr_dss_hwmod = omap3_dss_hwmod_data;
134                 oh_count = ARRAY_SIZE(omap3_dss_hwmod_data);
135         } else {
136                 curr_dss_hwmod = omap4_dss_hwmod_data;
137                 oh_count = ARRAY_SIZE(omap4_dss_hwmod_data);
138         }
139
140         if (board_data->dsi_enable_pads == NULL)
141                 board_data->dsi_enable_pads = omap_dsi_enable_pads;
142         if (board_data->dsi_disable_pads == NULL)
143                 board_data->dsi_disable_pads = omap_dsi_disable_pads;
144
145         pdata.board_data = board_data;
146         pdata.board_data->get_context_loss_count =
147                 omap_pm_get_dev_context_loss_count;
148
149         for (i = 0; i < oh_count; i++) {
150                 oh = omap_hwmod_lookup(curr_dss_hwmod[i].oh_name);
151                 if (!oh) {
152                         pr_err("Could not look up %s\n",
153                                 curr_dss_hwmod[i].oh_name);
154                         return -ENODEV;
155                 }
156
157                 pdev = omap_device_build(curr_dss_hwmod[i].dev_name,
158                                 curr_dss_hwmod[i].id, oh, &pdata,
159                                 sizeof(struct omap_display_platform_data),
160                                 NULL, 0, 0);
161
162                 if (WARN((IS_ERR(pdev)), "Could not build omap_device for %s\n",
163                                 curr_dss_hwmod[i].oh_name))
164                         return -ENODEV;
165         }
166         omap_display_device.dev.platform_data = board_data;
167
168         r = platform_device_register(&omap_display_device);
169         if (r < 0)
170                 printk(KERN_ERR "Unable to register OMAP-Display device\n");
171
172         return r;
173 }