blob: 9e2179f6322910cbdcfef732235037ac94a1c7cc [file] [log] [blame]
Sumit Semwalb7ee79a2011-01-24 06:21:54 +00001/*
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
Paul Gortmakerd44b28c2011-07-31 10:52:44 -040018#include <linux/string.h>
Sumit Semwalb7ee79a2011-01-24 06:21:54 +000019#include <linux/kernel.h>
20#include <linux/init.h>
21#include <linux/platform_device.h>
22#include <linux/io.h>
23#include <linux/clk.h>
24#include <linux/err.h>
25
Tomi Valkeinena0b38cc2011-05-11 14:05:07 +030026#include <video/omapdss.h>
Senthilvadivu Guruswamycf07f532011-01-24 06:21:56 +000027#include <plat/omap_hwmod.h>
28#include <plat/omap_device.h>
Tomi Valkeinen700dee72011-05-23 15:50:47 +030029#include <plat/omap-pm.h>
Sumit Semwalb7ee79a2011-01-24 06:21:54 +000030
Tomi Valkeinendc358352011-06-15 15:22:47 +030031#include "control.h"
32
Sumit Semwalb7ee79a2011-01-24 06:21:54 +000033static struct platform_device omap_display_device = {
34 .name = "omapdss",
35 .id = -1,
36 .dev = {
37 .platform_data = NULL,
38 },
39};
40
Senthilvadivu Guruswamycf07f532011-01-24 06:21:56 +000041static struct omap_device_pm_latency omap_dss_latency[] = {
42 [0] = {
43 .deactivate_func = omap_device_idle_hwmods,
44 .activate_func = omap_device_enable_hwmods,
45 .flags = OMAP_DEVICE_LATENCY_AUTO_ADJUST,
46 },
47};
48
Archit Taneja179e0452011-04-18 09:32:13 +053049struct omap_dss_hwmod_data {
50 const char *oh_name;
51 const char *dev_name;
52 const int id;
53};
54
55static const struct omap_dss_hwmod_data omap2_dss_hwmod_data[] __initdata = {
56 { "dss_core", "omapdss_dss", -1 },
57 { "dss_dispc", "omapdss_dispc", -1 },
58 { "dss_rfbi", "omapdss_rfbi", -1 },
59 { "dss_venc", "omapdss_venc", -1 },
60};
61
62static const struct omap_dss_hwmod_data omap3_dss_hwmod_data[] __initdata = {
63 { "dss_core", "omapdss_dss", -1 },
64 { "dss_dispc", "omapdss_dispc", -1 },
65 { "dss_rfbi", "omapdss_rfbi", -1 },
66 { "dss_venc", "omapdss_venc", -1 },
Tomi Valkeinen7c68dd92011-08-03 14:00:57 +030067 { "dss_dsi1", "omapdss_dsi", 0 },
Archit Taneja179e0452011-04-18 09:32:13 +053068};
69
70static const struct omap_dss_hwmod_data omap4_dss_hwmod_data[] __initdata = {
71 { "dss_core", "omapdss_dss", -1 },
72 { "dss_dispc", "omapdss_dispc", -1 },
73 { "dss_rfbi", "omapdss_rfbi", -1 },
74 { "dss_venc", "omapdss_venc", -1 },
Tomi Valkeinen7c68dd92011-08-03 14:00:57 +030075 { "dss_dsi1", "omapdss_dsi", 0 },
76 { "dss_dsi2", "omapdss_dsi", 1 },
Archit Taneja179e0452011-04-18 09:32:13 +053077 { "dss_hdmi", "omapdss_hdmi", -1 },
78};
79
Tomi Valkeinendc358352011-06-15 15:22:47 +030080static int omap4_dsi_mux_pads(int dsi_id, unsigned lanes)
81{
82 u32 enable_mask, enable_shift;
83 u32 pipd_mask, pipd_shift;
84 u32 reg;
85
86 if (dsi_id == 0) {
87 enable_mask = OMAP4_DSI1_LANEENABLE_MASK;
88 enable_shift = OMAP4_DSI1_LANEENABLE_SHIFT;
89 pipd_mask = OMAP4_DSI1_PIPD_MASK;
90 pipd_shift = OMAP4_DSI1_PIPD_SHIFT;
91 } else if (dsi_id == 1) {
92 enable_mask = OMAP4_DSI2_LANEENABLE_MASK;
93 enable_shift = OMAP4_DSI2_LANEENABLE_SHIFT;
94 pipd_mask = OMAP4_DSI2_PIPD_MASK;
95 pipd_shift = OMAP4_DSI2_PIPD_SHIFT;
96 } else {
97 return -ENODEV;
98 }
99
100 reg = omap4_ctrl_pad_readl(OMAP4_CTRL_MODULE_PAD_CORE_CONTROL_DSIPHY);
101
102 reg &= ~enable_mask;
103 reg &= ~pipd_mask;
104
105 reg |= (lanes << enable_shift) & enable_mask;
106 reg |= (lanes << pipd_shift) & pipd_mask;
107
108 omap4_ctrl_pad_writel(reg, OMAP4_CTRL_MODULE_PAD_CORE_CONTROL_DSIPHY);
109
110 return 0;
111}
112
Tomi Valkeinen5bc416c2011-06-15 15:21:12 +0300113static int omap_dsi_enable_pads(int dsi_id, unsigned lane_mask)
114{
Tomi Valkeinendc358352011-06-15 15:22:47 +0300115 if (cpu_is_omap44xx())
116 return omap4_dsi_mux_pads(dsi_id, lane_mask);
117
Tomi Valkeinen5bc416c2011-06-15 15:21:12 +0300118 return 0;
119}
120
121static void omap_dsi_disable_pads(int dsi_id, unsigned lane_mask)
122{
Tomi Valkeinendc358352011-06-15 15:22:47 +0300123 if (cpu_is_omap44xx())
124 omap4_dsi_mux_pads(dsi_id, 0);
Tomi Valkeinen5bc416c2011-06-15 15:21:12 +0300125}
126
Sumit Semwalb7ee79a2011-01-24 06:21:54 +0000127int __init omap_display_init(struct omap_dss_board_info *board_data)
128{
129 int r = 0;
Senthilvadivu Guruswamycf07f532011-01-24 06:21:56 +0000130 struct omap_hwmod *oh;
131 struct omap_device *od;
Archit Taneja179e0452011-04-18 09:32:13 +0530132 int i, oh_count;
Senthilvadivu Guruswamycf07f532011-01-24 06:21:56 +0000133 struct omap_display_platform_data pdata;
Archit Taneja179e0452011-04-18 09:32:13 +0530134 const struct omap_dss_hwmod_data *curr_dss_hwmod;
Senthilvadivu Guruswamycf07f532011-01-24 06:21:56 +0000135
136 memset(&pdata, 0, sizeof(pdata));
137
Archit Taneja179e0452011-04-18 09:32:13 +0530138 if (cpu_is_omap24xx()) {
139 curr_dss_hwmod = omap2_dss_hwmod_data;
140 oh_count = ARRAY_SIZE(omap2_dss_hwmod_data);
141 } else if (cpu_is_omap34xx()) {
142 curr_dss_hwmod = omap3_dss_hwmod_data;
143 oh_count = ARRAY_SIZE(omap3_dss_hwmod_data);
144 } else {
145 curr_dss_hwmod = omap4_dss_hwmod_data;
146 oh_count = ARRAY_SIZE(omap4_dss_hwmod_data);
147 }
Mayuresh Janorkar545376e2011-01-27 11:17:04 +0000148
Tomi Valkeinen5bc416c2011-06-15 15:21:12 +0300149 if (board_data->dsi_enable_pads == NULL)
150 board_data->dsi_enable_pads = omap_dsi_enable_pads;
151 if (board_data->dsi_disable_pads == NULL)
152 board_data->dsi_disable_pads = omap_dsi_disable_pads;
153
Senthilvadivu Guruswamycf07f532011-01-24 06:21:56 +0000154 pdata.board_data = board_data;
Tomi Valkeinen700dee72011-05-23 15:50:47 +0300155 pdata.board_data->get_context_loss_count =
156 omap_pm_get_dev_context_loss_count;
Senthilvadivu Guruswamycf07f532011-01-24 06:21:56 +0000157
158 for (i = 0; i < oh_count; i++) {
Archit Taneja179e0452011-04-18 09:32:13 +0530159 oh = omap_hwmod_lookup(curr_dss_hwmod[i].oh_name);
Senthilvadivu Guruswamycf07f532011-01-24 06:21:56 +0000160 if (!oh) {
Archit Taneja179e0452011-04-18 09:32:13 +0530161 pr_err("Could not look up %s\n",
162 curr_dss_hwmod[i].oh_name);
Senthilvadivu Guruswamycf07f532011-01-24 06:21:56 +0000163 return -ENODEV;
164 }
Semwal, Sumitfd4b34f2011-03-01 02:42:13 -0600165
Archit Taneja179e0452011-04-18 09:32:13 +0530166 od = omap_device_build(curr_dss_hwmod[i].dev_name,
167 curr_dss_hwmod[i].id, oh, &pdata,
Senthilvadivu Guruswamycf07f532011-01-24 06:21:56 +0000168 sizeof(struct omap_display_platform_data),
169 omap_dss_latency,
170 ARRAY_SIZE(omap_dss_latency), 0);
171
172 if (WARN((IS_ERR(od)), "Could not build omap_device for %s\n",
Archit Taneja179e0452011-04-18 09:32:13 +0530173 curr_dss_hwmod[i].oh_name))
Senthilvadivu Guruswamycf07f532011-01-24 06:21:56 +0000174 return -ENODEV;
175 }
Sumit Semwalb7ee79a2011-01-24 06:21:54 +0000176 omap_display_device.dev.platform_data = board_data;
177
178 r = platform_device_register(&omap_display_device);
179 if (r < 0)
180 printk(KERN_ERR "Unable to register OMAP-Display device\n");
181
182 return r;
183}