gma500: resync with Medfield progress
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / staging / gma500 / mdfld_tmd_vid.c
blobaffdc09c67694cecd895cda8c27cdc70f248f1c5
1 /*
2 * Copyright © 2010 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
23 * Authors:
24 * Jim Liu <jim.liu@intel.com>
25 * Jackie Li<yaodong.li@intel.com>
26 * Gideon Eaton <eaton.
27 * Scott Rowe <scott.m.rowe@intel.com>
30 #include "mdfld_dsi_dbi.h"
31 #include "mdfld_dsi_dpi.h"
32 #include "mdfld_dsi_output.h"
33 #include "mdfld_output.h"
35 #include "mdfld_dsi_pkg_sender.h"
37 #include "displays/tmd_vid.h"
39 /* FIXME: static ? */
40 struct drm_display_mode *tmd_vid_get_config_mode(struct drm_device *dev)
42 struct drm_display_mode *mode;
43 struct drm_psb_private *dev_priv = dev->dev_private;
44 struct mrst_timing_info *ti = &dev_priv->gct_data.DTD;
45 bool use_gct = false; /*Disable GCT for now*/
47 mode = kzalloc(sizeof(*mode), GFP_KERNEL);
48 if (!mode) {
49 dev_err(dev->dev, "Out of memory\n");
50 return NULL;
53 if (use_gct) {
54 dev_dbg(dev->dev, "gct find MIPI panel.\n");
56 mode->hdisplay = (ti->hactive_hi << 8) | ti->hactive_lo;
57 mode->vdisplay = (ti->vactive_hi << 8) | ti->vactive_lo;
58 mode->hsync_start = mode->hdisplay +
59 ((ti->hsync_offset_hi << 8) |
60 ti->hsync_offset_lo);
61 mode->hsync_end = mode->hsync_start +
62 ((ti->hsync_pulse_width_hi << 8) |
63 ti->hsync_pulse_width_lo);
64 mode->htotal = mode->hdisplay + ((ti->hblank_hi << 8) |
65 ti->hblank_lo);
66 mode->vsync_start = \
67 mode->vdisplay + ((ti->vsync_offset_hi << 8) |
68 ti->vsync_offset_lo);
69 mode->vsync_end = \
70 mode->vsync_start + ((ti->vsync_pulse_width_hi << 8) | \
71 ti->vsync_pulse_width_lo);
72 mode->vtotal = mode->vdisplay +
73 ((ti->vblank_hi << 8) | ti->vblank_lo);
74 mode->clock = ti->pixel_clock * 10;
76 dev_dbg(dev->dev, "hdisplay is %d\n", mode->hdisplay);
77 dev_dbg(dev->dev, "vdisplay is %d\n", mode->vdisplay);
78 dev_dbg(dev->dev, "HSS is %d\n", mode->hsync_start);
79 dev_dbg(dev->dev, "HSE is %d\n", mode->hsync_end);
80 dev_dbg(dev->dev, "htotal is %d\n", mode->htotal);
81 dev_dbg(dev->dev, "VSS is %d\n", mode->vsync_start);
82 dev_dbg(dev->dev, "VSE is %d\n", mode->vsync_end);
83 dev_dbg(dev->dev, "vtotal is %d\n", mode->vtotal);
84 dev_dbg(dev->dev, "clock is %d\n", mode->clock);
85 } else {
86 mode->hdisplay = 480;
87 mode->vdisplay = 854;
88 mode->hsync_start = 487;
89 mode->hsync_end = 490;
90 mode->htotal = 499;
91 mode->vsync_start = 861;
92 mode->vsync_end = 865;
93 mode->vtotal = 873;
94 mode->clock = 33264;
96 drm_mode_set_name(mode);
97 drm_mode_set_crtcinfo(mode, 0);
99 mode->type |= DRM_MODE_TYPE_PREFERRED;
101 return mode;
104 static int tmd_vid_get_panel_info(struct drm_device *dev,
105 int pipe,
106 struct panel_info *pi)
108 if (!dev || !pi)
109 return -EINVAL;
111 pi->width_mm = TMD_PANEL_WIDTH;
112 pi->height_mm = TMD_PANEL_HEIGHT;
114 return 0;
118 * mdfld_init_TMD_MIPI - initialise a TMD interface
119 * @dsi_config: configuration
120 * @pipe: pipe to configure
122 * This function is called only by mrst_dsi_mode_set and
123 * restore_display_registers. since this function does not
124 * acquire the mutex, it is important that the calling function
125 * does!
129 static void mdfld_dsi_tmd_drv_ic_init(struct mdfld_dsi_config *dsi_config,
130 int pipe)
132 static u32 tmd_cmd_mcap_off[] = {0x000000b2};
133 static u32 tmd_cmd_enable_lane_switch[] = {0x000101ef};
134 static u32 tmd_cmd_set_lane_num[] = {0x006360ef};
135 static u32 tmd_cmd_pushing_clock0[] = {0x00cc2fef};
136 static u32 tmd_cmd_pushing_clock1[] = {0x00dd6eef};
137 static u32 tmd_cmd_set_mode[] = {0x000000b3};
138 static u32 tmd_cmd_set_sync_pulse_mode[] = {0x000961ef};
139 static u32 tmd_cmd_set_column[] = {0x0100002a, 0x000000df};
140 static u32 tmd_cmd_set_page[] = {0x0300002b, 0x00000055};
141 static u32 tmd_cmd_set_video_mode[] = {0x00000153};
142 /*no auto_bl,need add in furture*/
143 static u32 tmd_cmd_enable_backlight[] = {0x00005ab4};
144 static u32 tmd_cmd_set_backlight_dimming[] = {0x00000ebd};
146 struct mdfld_dsi_pkg_sender *sender
147 = mdfld_dsi_get_pkg_sender(dsi_config);
149 DRM_INFO("Enter mdfld init TMD MIPI display.\n");
151 if (!sender) {
152 DRM_ERROR("Cannot get sender\n");
153 return;
156 if (dsi_config->dvr_ic_inited)
157 return;
159 msleep(3);
161 mdfld_dsi_send_gen_long_lp(sender, tmd_cmd_mcap_off, 1, 0);
162 mdfld_dsi_send_gen_long_lp(sender, tmd_cmd_enable_lane_switch, 1, 0);
163 mdfld_dsi_send_gen_long_lp(sender, tmd_cmd_set_lane_num, 1, 0);
164 mdfld_dsi_send_gen_long_lp(sender, tmd_cmd_pushing_clock0, 1, 0);
165 mdfld_dsi_send_gen_long_lp(sender, tmd_cmd_pushing_clock1, 1, 0);
166 mdfld_dsi_send_gen_long_lp(sender, tmd_cmd_set_mode, 1, 0);
167 mdfld_dsi_send_gen_long_lp(sender, tmd_cmd_set_sync_pulse_mode, 1, 0);
168 mdfld_dsi_send_mcs_long_lp(sender, tmd_cmd_set_column, 2, 0);
169 mdfld_dsi_send_mcs_long_lp(sender, tmd_cmd_set_page, 2, 0);
170 mdfld_dsi_send_gen_long_lp(sender, tmd_cmd_set_video_mode, 1, 0);
171 mdfld_dsi_send_gen_long_lp(sender, tmd_cmd_enable_backlight, 1, 0);
172 mdfld_dsi_send_gen_long_lp(sender, tmd_cmd_set_backlight_dimming, 1, 0);
174 dsi_config->dvr_ic_inited = 1;
177 /* TMD DPI encoder helper funcs */
178 static const struct drm_encoder_helper_funcs
179 mdfld_tpo_dpi_encoder_helper_funcs = {
180 .dpms = mdfld_dsi_dpi_dpms,
181 .mode_fixup = mdfld_dsi_dpi_mode_fixup,
182 .prepare = mdfld_dsi_dpi_prepare,
183 .mode_set = mdfld_dsi_dpi_mode_set,
184 .commit = mdfld_dsi_dpi_commit,
187 /* TMD DPI encoder funcs */
188 static const struct drm_encoder_funcs mdfld_tpo_dpi_encoder_funcs = {
189 .destroy = drm_encoder_cleanup,
192 void tmd_vid_init(struct drm_device *dev, struct panel_funcs *p_funcs)
194 if (!dev || !p_funcs) {
195 dev_err(dev->dev, "Invalid parameters\n");
196 return;
199 p_funcs->encoder_funcs = &mdfld_tpo_dpi_encoder_funcs;
200 p_funcs->encoder_helper_funcs = &mdfld_tpo_dpi_encoder_helper_funcs;
201 p_funcs->get_config_mode = &tmd_vid_get_config_mode;
202 p_funcs->update_fb = NULL;
203 p_funcs->get_panel_info = tmd_vid_get_panel_info;
204 p_funcs->reset = mdfld_dsi_panel_reset;
205 p_funcs->drv_ic_init = mdfld_dsi_tmd_drv_ic_init;