blob: 62510ec863c6293e7646f3161e928d50ff5206b8 [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
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
Tomi Valkeinena0b38cc2011-05-11 14:05:07 +030025#include <video/omapdss.h>
Senthilvadivu Guruswamycf07f532011-01-24 06:21:56 +000026#include <plat/omap_hwmod.h>
27#include <plat/omap_device.h>
Tomi Valkeinen700dee72011-05-23 15:50:47 +030028#include <plat/omap-pm.h>
Sumit Semwalb7ee79a2011-01-24 06:21:54 +000029
Tomi Valkeinendc358352011-06-15 15:22:47 +030030#include "control.h"
31
Sumit Semwalb7ee79a2011-01-24 06:21:54 +000032static struct platform_device omap_display_device = {
33 .name = "omapdss",
34 .id = -1,
35 .dev = {
36 .platform_data = NULL,
37 },
38};
39
Senthilvadivu Guruswamycf07f532011-01-24 06:21:56 +000040static struct omap_device_pm_latency omap_dss_latency[] = {
41 [0] = {
42 .deactivate_func = omap_device_idle_hwmods,
43 .activate_func = omap_device_enable_hwmods,
44 .flags = OMAP_DEVICE_LATENCY_AUTO_ADJUST,
45 },
46};
47
Archit Taneja179e0452011-04-18 09:32:13 +053048struct omap_dss_hwmod_data {
49 const char *oh_name;
50 const char *dev_name;
51 const int id;
52};
53
54static const struct omap_dss_hwmod_data omap2_dss_hwmod_data[] __initdata = {
55 { "dss_core", "omapdss_dss", -1 },
56 { "dss_dispc", "omapdss_dispc", -1 },
57 { "dss_rfbi", "omapdss_rfbi", -1 },
58 { "dss_venc", "omapdss_venc", -1 },
59};
60
61static const struct omap_dss_hwmod_data omap3_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 },
Tomi Valkeinen7c68dd92011-08-03 14:00:57 +030066 { "dss_dsi1", "omapdss_dsi", 0 },
Archit Taneja179e0452011-04-18 09:32:13 +053067};
68
69static const struct omap_dss_hwmod_data omap4_dss_hwmod_data[] __initdata = {
70 { "dss_core", "omapdss_dss", -1 },
71 { "dss_dispc", "omapdss_dispc", -1 },
72 { "dss_rfbi", "omapdss_rfbi", -1 },
73 { "dss_venc", "omapdss_venc", -1 },
Tomi Valkeinen7c68dd92011-08-03 14:00:57 +030074 { "dss_dsi1", "omapdss_dsi", 0 },
75 { "dss_dsi2", "omapdss_dsi", 1 },
Archit Taneja179e0452011-04-18 09:32:13 +053076 { "dss_hdmi", "omapdss_hdmi", -1 },
77};
78
Tomi Valkeinendc358352011-06-15 15:22:47 +030079static int omap4_dsi_mux_pads(int dsi_id, unsigned lanes)
80{
81 u32 enable_mask, enable_shift;
82 u32 pipd_mask, pipd_shift;
83 u32 reg;
84
85 if (dsi_id == 0) {
86 enable_mask = OMAP4_DSI1_LANEENABLE_MASK;
87 enable_shift = OMAP4_DSI1_LANEENABLE_SHIFT;
88 pipd_mask = OMAP4_DSI1_PIPD_MASK;
89 pipd_shift = OMAP4_DSI1_PIPD_SHIFT;
90 } else if (dsi_id == 1) {
91 enable_mask = OMAP4_DSI2_LANEENABLE_MASK;
92 enable_shift = OMAP4_DSI2_LANEENABLE_SHIFT;
93 pipd_mask = OMAP4_DSI2_PIPD_MASK;
94 pipd_shift = OMAP4_DSI2_PIPD_SHIFT;
95 } else {
96 return -ENODEV;
97 }
98
99 reg = omap4_ctrl_pad_readl(OMAP4_CTRL_MODULE_PAD_CORE_CONTROL_DSIPHY);
100
101 reg &= ~enable_mask;
102 reg &= ~pipd_mask;
103
104 reg |= (lanes << enable_shift) & enable_mask;
105 reg |= (lanes << pipd_shift) & pipd_mask;
106
107 omap4_ctrl_pad_writel(reg, OMAP4_CTRL_MODULE_PAD_CORE_CONTROL_DSIPHY);
108
109 return 0;
110}
111
Tomi Valkeinen5bc416c2011-06-15 15:21:12 +0300112static int omap_dsi_enable_pads(int dsi_id, unsigned lane_mask)
113{
Tomi Valkeinendc358352011-06-15 15:22:47 +0300114 if (cpu_is_omap44xx())
115 return omap4_dsi_mux_pads(dsi_id, lane_mask);
116
Tomi Valkeinen5bc416c2011-06-15 15:21:12 +0300117 return 0;
118}
119
120static void omap_dsi_disable_pads(int dsi_id, unsigned lane_mask)
121{
Tomi Valkeinendc358352011-06-15 15:22:47 +0300122 if (cpu_is_omap44xx())
123 omap4_dsi_mux_pads(dsi_id, 0);
Tomi Valkeinen5bc416c2011-06-15 15:21:12 +0300124}
125
Sumit Semwalb7ee79a2011-01-24 06:21:54 +0000126int __init omap_display_init(struct omap_dss_board_info *board_data)
127{
128 int r = 0;
Senthilvadivu Guruswamycf07f532011-01-24 06:21:56 +0000129 struct omap_hwmod *oh;
130 struct omap_device *od;
Archit Taneja179e0452011-04-18 09:32:13 +0530131 int i, oh_count;
Senthilvadivu Guruswamycf07f532011-01-24 06:21:56 +0000132 struct omap_display_platform_data pdata;
Archit Taneja179e0452011-04-18 09:32:13 +0530133 const struct omap_dss_hwmod_data *curr_dss_hwmod;
Senthilvadivu Guruswamycf07f532011-01-24 06:21:56 +0000134
135 memset(&pdata, 0, sizeof(pdata));
136
Archit Taneja179e0452011-04-18 09:32:13 +0530137 if (cpu_is_omap24xx()) {
138 curr_dss_hwmod = omap2_dss_hwmod_data;
139 oh_count = ARRAY_SIZE(omap2_dss_hwmod_data);
140 } else if (cpu_is_omap34xx()) {
141 curr_dss_hwmod = omap3_dss_hwmod_data;
142 oh_count = ARRAY_SIZE(omap3_dss_hwmod_data);
143 } else {
144 curr_dss_hwmod = omap4_dss_hwmod_data;
145 oh_count = ARRAY_SIZE(omap4_dss_hwmod_data);
146 }
Mayuresh Janorkar545376e2011-01-27 11:17:04 +0000147
Tomi Valkeinen5bc416c2011-06-15 15:21:12 +0300148 if (board_data->dsi_enable_pads == NULL)
149 board_data->dsi_enable_pads = omap_dsi_enable_pads;
150 if (board_data->dsi_disable_pads == NULL)
151 board_data->dsi_disable_pads = omap_dsi_disable_pads;
152
Senthilvadivu Guruswamycf07f532011-01-24 06:21:56 +0000153 pdata.board_data = board_data;
Tomi Valkeinen700dee72011-05-23 15:50:47 +0300154 pdata.board_data->get_context_loss_count =
155 omap_pm_get_dev_context_loss_count;
Senthilvadivu Guruswamycf07f532011-01-24 06:21:56 +0000156
157 for (i = 0; i < oh_count; i++) {
Archit Taneja179e0452011-04-18 09:32:13 +0530158 oh = omap_hwmod_lookup(curr_dss_hwmod[i].oh_name);
Senthilvadivu Guruswamycf07f532011-01-24 06:21:56 +0000159 if (!oh) {
Archit Taneja179e0452011-04-18 09:32:13 +0530160 pr_err("Could not look up %s\n",
161 curr_dss_hwmod[i].oh_name);
Senthilvadivu Guruswamycf07f532011-01-24 06:21:56 +0000162 return -ENODEV;
163 }
Semwal, Sumitfd4b34f2011-03-01 02:42:13 -0600164
Archit Taneja179e0452011-04-18 09:32:13 +0530165 od = omap_device_build(curr_dss_hwmod[i].dev_name,
166 curr_dss_hwmod[i].id, oh, &pdata,
Senthilvadivu Guruswamycf07f532011-01-24 06:21:56 +0000167 sizeof(struct omap_display_platform_data),
168 omap_dss_latency,
169 ARRAY_SIZE(omap_dss_latency), 0);
170
171 if (WARN((IS_ERR(od)), "Could not build omap_device for %s\n",
Archit Taneja179e0452011-04-18 09:32:13 +0530172 curr_dss_hwmod[i].oh_name))
Senthilvadivu Guruswamycf07f532011-01-24 06:21:56 +0000173 return -ENODEV;
174 }
Sumit Semwalb7ee79a2011-01-24 06:21:54 +0000175 omap_display_device.dev.platform_data = board_data;
176
177 r = platform_device_register(&omap_display_device);
178 if (r < 0)
179 printk(KERN_ERR "Unable to register OMAP-Display device\n");
180
181 return r;
182}