18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Copyright © 2010 Intel Corporation
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
58c2ecf20Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
68c2ecf20Sopenharmony_ci * to deal in the Software without restriction, including without limitation
78c2ecf20Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
88c2ecf20Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
98c2ecf20Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
108c2ecf20Sopenharmony_ci *
118c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice (including the next
128c2ecf20Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the
138c2ecf20Sopenharmony_ci * Software.
148c2ecf20Sopenharmony_ci *
158c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
168c2ecf20Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
178c2ecf20Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
188c2ecf20Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
198c2ecf20Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
208c2ecf20Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
218c2ecf20Sopenharmony_ci * DEALINGS IN THE SOFTWARE.
228c2ecf20Sopenharmony_ci *
238c2ecf20Sopenharmony_ci * Authors:
248c2ecf20Sopenharmony_ci * Jim Liu <jim.liu@intel.com>
258c2ecf20Sopenharmony_ci * Jackie Li<yaodong.li@intel.com>
268c2ecf20Sopenharmony_ci * Gideon Eaton <eaton.
278c2ecf20Sopenharmony_ci * Scott Rowe <scott.m.rowe@intel.com>
288c2ecf20Sopenharmony_ci */
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci#include <linux/delay.h>
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci#include "mdfld_dsi_dpi.h"
338c2ecf20Sopenharmony_ci#include "mdfld_dsi_pkg_sender.h"
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_cistatic struct drm_display_mode *tmd_vid_get_config_mode(struct drm_device *dev)
368c2ecf20Sopenharmony_ci{
378c2ecf20Sopenharmony_ci	struct drm_display_mode *mode;
388c2ecf20Sopenharmony_ci	struct drm_psb_private *dev_priv = dev->dev_private;
398c2ecf20Sopenharmony_ci	struct oaktrail_timing_info *ti = &dev_priv->gct_data.DTD;
408c2ecf20Sopenharmony_ci	bool use_gct = false; /*Disable GCT for now*/
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci	mode = kzalloc(sizeof(*mode), GFP_KERNEL);
438c2ecf20Sopenharmony_ci	if (!mode)
448c2ecf20Sopenharmony_ci		return NULL;
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci	if (use_gct) {
478c2ecf20Sopenharmony_ci		mode->hdisplay = (ti->hactive_hi << 8) | ti->hactive_lo;
488c2ecf20Sopenharmony_ci		mode->vdisplay = (ti->vactive_hi << 8) | ti->vactive_lo;
498c2ecf20Sopenharmony_ci		mode->hsync_start = mode->hdisplay + \
508c2ecf20Sopenharmony_ci				((ti->hsync_offset_hi << 8) | \
518c2ecf20Sopenharmony_ci				ti->hsync_offset_lo);
528c2ecf20Sopenharmony_ci		mode->hsync_end = mode->hsync_start + \
538c2ecf20Sopenharmony_ci				((ti->hsync_pulse_width_hi << 8) | \
548c2ecf20Sopenharmony_ci				ti->hsync_pulse_width_lo);
558c2ecf20Sopenharmony_ci		mode->htotal = mode->hdisplay + ((ti->hblank_hi << 8) | \
568c2ecf20Sopenharmony_ci								ti->hblank_lo);
578c2ecf20Sopenharmony_ci		mode->vsync_start = \
588c2ecf20Sopenharmony_ci			mode->vdisplay + ((ti->vsync_offset_hi << 8) | \
598c2ecf20Sopenharmony_ci						ti->vsync_offset_lo);
608c2ecf20Sopenharmony_ci		mode->vsync_end = \
618c2ecf20Sopenharmony_ci			mode->vsync_start + ((ti->vsync_pulse_width_hi << 8) | \
628c2ecf20Sopenharmony_ci						ti->vsync_pulse_width_lo);
638c2ecf20Sopenharmony_ci		mode->vtotal = mode->vdisplay + \
648c2ecf20Sopenharmony_ci				((ti->vblank_hi << 8) | ti->vblank_lo);
658c2ecf20Sopenharmony_ci		mode->clock = ti->pixel_clock * 10;
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ci		dev_dbg(dev->dev, "hdisplay is %d\n", mode->hdisplay);
688c2ecf20Sopenharmony_ci		dev_dbg(dev->dev, "vdisplay is %d\n", mode->vdisplay);
698c2ecf20Sopenharmony_ci		dev_dbg(dev->dev, "HSS is %d\n", mode->hsync_start);
708c2ecf20Sopenharmony_ci		dev_dbg(dev->dev, "HSE is %d\n", mode->hsync_end);
718c2ecf20Sopenharmony_ci		dev_dbg(dev->dev, "htotal is %d\n", mode->htotal);
728c2ecf20Sopenharmony_ci		dev_dbg(dev->dev, "VSS is %d\n", mode->vsync_start);
738c2ecf20Sopenharmony_ci		dev_dbg(dev->dev, "VSE is %d\n", mode->vsync_end);
748c2ecf20Sopenharmony_ci		dev_dbg(dev->dev, "vtotal is %d\n", mode->vtotal);
758c2ecf20Sopenharmony_ci		dev_dbg(dev->dev, "clock is %d\n", mode->clock);
768c2ecf20Sopenharmony_ci	} else {
778c2ecf20Sopenharmony_ci		mode->hdisplay = 480;
788c2ecf20Sopenharmony_ci		mode->vdisplay = 854;
798c2ecf20Sopenharmony_ci		mode->hsync_start = 487;
808c2ecf20Sopenharmony_ci		mode->hsync_end = 490;
818c2ecf20Sopenharmony_ci		mode->htotal = 499;
828c2ecf20Sopenharmony_ci		mode->vsync_start = 861;
838c2ecf20Sopenharmony_ci		mode->vsync_end = 865;
848c2ecf20Sopenharmony_ci		mode->vtotal = 873;
858c2ecf20Sopenharmony_ci		mode->clock = 33264;
868c2ecf20Sopenharmony_ci	}
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci	drm_mode_set_name(mode);
898c2ecf20Sopenharmony_ci	drm_mode_set_crtcinfo(mode, 0);
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ci	mode->type |= DRM_MODE_TYPE_PREFERRED;
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci	return mode;
948c2ecf20Sopenharmony_ci}
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_cistatic int tmd_vid_get_panel_info(struct drm_device *dev,
978c2ecf20Sopenharmony_ci				int pipe,
988c2ecf20Sopenharmony_ci				struct panel_info *pi)
998c2ecf20Sopenharmony_ci{
1008c2ecf20Sopenharmony_ci	if (!dev || !pi)
1018c2ecf20Sopenharmony_ci		return -EINVAL;
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_ci	pi->width_mm = TMD_PANEL_WIDTH;
1048c2ecf20Sopenharmony_ci	pi->height_mm = TMD_PANEL_HEIGHT;
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_ci	return 0;
1078c2ecf20Sopenharmony_ci}
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_ci/* ************************************************************************* *\
1108c2ecf20Sopenharmony_ci * FUNCTION: mdfld_init_TMD_MIPI
1118c2ecf20Sopenharmony_ci *
1128c2ecf20Sopenharmony_ci * DESCRIPTION:  This function is called only by mrst_dsi_mode_set and
1138c2ecf20Sopenharmony_ci *               restore_display_registers.  since this function does not
1148c2ecf20Sopenharmony_ci *               acquire the mutex, it is important that the calling function
1158c2ecf20Sopenharmony_ci *               does!
1168c2ecf20Sopenharmony_ci\* ************************************************************************* */
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_ci/* FIXME: make the below data u8 instead of u32; note byte order! */
1198c2ecf20Sopenharmony_cistatic u32 tmd_cmd_mcap_off[] = {0x000000b2};
1208c2ecf20Sopenharmony_cistatic u32 tmd_cmd_enable_lane_switch[] = {0x000101ef};
1218c2ecf20Sopenharmony_cistatic u32 tmd_cmd_set_lane_num[] = {0x006360ef};
1228c2ecf20Sopenharmony_cistatic u32 tmd_cmd_pushing_clock0[] = {0x00cc2fef};
1238c2ecf20Sopenharmony_cistatic u32 tmd_cmd_pushing_clock1[] = {0x00dd6eef};
1248c2ecf20Sopenharmony_cistatic u32 tmd_cmd_set_mode[] = {0x000000b3};
1258c2ecf20Sopenharmony_cistatic u32 tmd_cmd_set_sync_pulse_mode[] = {0x000961ef};
1268c2ecf20Sopenharmony_cistatic u32 tmd_cmd_set_column[] = {0x0100002a, 0x000000df};
1278c2ecf20Sopenharmony_cistatic u32 tmd_cmd_set_page[] = {0x0300002b, 0x00000055};
1288c2ecf20Sopenharmony_cistatic u32 tmd_cmd_set_video_mode[] = {0x00000153};
1298c2ecf20Sopenharmony_ci/*no auto_bl,need add in furture*/
1308c2ecf20Sopenharmony_cistatic u32 tmd_cmd_enable_backlight[] = {0x00005ab4};
1318c2ecf20Sopenharmony_cistatic u32 tmd_cmd_set_backlight_dimming[] = {0x00000ebd};
1328c2ecf20Sopenharmony_ci
1338c2ecf20Sopenharmony_cistatic void mdfld_dsi_tmd_drv_ic_init(struct mdfld_dsi_config *dsi_config,
1348c2ecf20Sopenharmony_ci				      int pipe)
1358c2ecf20Sopenharmony_ci{
1368c2ecf20Sopenharmony_ci	struct mdfld_dsi_pkg_sender *sender
1378c2ecf20Sopenharmony_ci			= mdfld_dsi_get_pkg_sender(dsi_config);
1388c2ecf20Sopenharmony_ci
1398c2ecf20Sopenharmony_ci	DRM_INFO("Enter mdfld init TMD MIPI display.\n");
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_ci	if (!sender) {
1428c2ecf20Sopenharmony_ci		DRM_ERROR("Cannot get sender\n");
1438c2ecf20Sopenharmony_ci		return;
1448c2ecf20Sopenharmony_ci	}
1458c2ecf20Sopenharmony_ci
1468c2ecf20Sopenharmony_ci	if (dsi_config->dvr_ic_inited)
1478c2ecf20Sopenharmony_ci		return;
1488c2ecf20Sopenharmony_ci
1498c2ecf20Sopenharmony_ci	msleep(3);
1508c2ecf20Sopenharmony_ci
1518c2ecf20Sopenharmony_ci	/* FIXME: make the below data u8 instead of u32; note byte order! */
1528c2ecf20Sopenharmony_ci
1538c2ecf20Sopenharmony_ci	mdfld_dsi_send_gen_long(sender, (u8 *) tmd_cmd_mcap_off,
1548c2ecf20Sopenharmony_ci				sizeof(tmd_cmd_mcap_off), false);
1558c2ecf20Sopenharmony_ci	mdfld_dsi_send_gen_long(sender, (u8 *) tmd_cmd_enable_lane_switch,
1568c2ecf20Sopenharmony_ci				sizeof(tmd_cmd_enable_lane_switch), false);
1578c2ecf20Sopenharmony_ci	mdfld_dsi_send_gen_long(sender, (u8 *) tmd_cmd_set_lane_num,
1588c2ecf20Sopenharmony_ci				sizeof(tmd_cmd_set_lane_num), false);
1598c2ecf20Sopenharmony_ci	mdfld_dsi_send_gen_long(sender, (u8 *) tmd_cmd_pushing_clock0,
1608c2ecf20Sopenharmony_ci				sizeof(tmd_cmd_pushing_clock0), false);
1618c2ecf20Sopenharmony_ci	mdfld_dsi_send_gen_long(sender, (u8 *) tmd_cmd_pushing_clock1,
1628c2ecf20Sopenharmony_ci				sizeof(tmd_cmd_pushing_clock1), false);
1638c2ecf20Sopenharmony_ci	mdfld_dsi_send_gen_long(sender, (u8 *) tmd_cmd_set_mode,
1648c2ecf20Sopenharmony_ci				sizeof(tmd_cmd_set_mode), false);
1658c2ecf20Sopenharmony_ci	mdfld_dsi_send_gen_long(sender, (u8 *) tmd_cmd_set_sync_pulse_mode,
1668c2ecf20Sopenharmony_ci				sizeof(tmd_cmd_set_sync_pulse_mode), false);
1678c2ecf20Sopenharmony_ci	mdfld_dsi_send_mcs_long(sender, (u8 *) tmd_cmd_set_column,
1688c2ecf20Sopenharmony_ci				sizeof(tmd_cmd_set_column), false);
1698c2ecf20Sopenharmony_ci	mdfld_dsi_send_mcs_long(sender, (u8 *) tmd_cmd_set_page,
1708c2ecf20Sopenharmony_ci				sizeof(tmd_cmd_set_page), false);
1718c2ecf20Sopenharmony_ci	mdfld_dsi_send_gen_long(sender, (u8 *) tmd_cmd_set_video_mode,
1728c2ecf20Sopenharmony_ci				sizeof(tmd_cmd_set_video_mode), false);
1738c2ecf20Sopenharmony_ci	mdfld_dsi_send_gen_long(sender, (u8 *) tmd_cmd_enable_backlight,
1748c2ecf20Sopenharmony_ci				sizeof(tmd_cmd_enable_backlight), false);
1758c2ecf20Sopenharmony_ci	mdfld_dsi_send_gen_long(sender, (u8 *) tmd_cmd_set_backlight_dimming,
1768c2ecf20Sopenharmony_ci				sizeof(tmd_cmd_set_backlight_dimming), false);
1778c2ecf20Sopenharmony_ci
1788c2ecf20Sopenharmony_ci	dsi_config->dvr_ic_inited = 1;
1798c2ecf20Sopenharmony_ci}
1808c2ecf20Sopenharmony_ci
1818c2ecf20Sopenharmony_ci/*TPO DPI encoder helper funcs*/
1828c2ecf20Sopenharmony_cistatic const struct drm_encoder_helper_funcs
1838c2ecf20Sopenharmony_ci				mdfld_tpo_dpi_encoder_helper_funcs = {
1848c2ecf20Sopenharmony_ci	.dpms = mdfld_dsi_dpi_dpms,
1858c2ecf20Sopenharmony_ci	.mode_fixup = mdfld_dsi_dpi_mode_fixup,
1868c2ecf20Sopenharmony_ci	.prepare = mdfld_dsi_dpi_prepare,
1878c2ecf20Sopenharmony_ci	.mode_set = mdfld_dsi_dpi_mode_set,
1888c2ecf20Sopenharmony_ci	.commit = mdfld_dsi_dpi_commit,
1898c2ecf20Sopenharmony_ci};
1908c2ecf20Sopenharmony_ci
1918c2ecf20Sopenharmony_ciconst struct panel_funcs mdfld_tmd_vid_funcs = {
1928c2ecf20Sopenharmony_ci	.encoder_helper_funcs = &mdfld_tpo_dpi_encoder_helper_funcs,
1938c2ecf20Sopenharmony_ci	.get_config_mode = &tmd_vid_get_config_mode,
1948c2ecf20Sopenharmony_ci	.get_panel_info = tmd_vid_get_panel_info,
1958c2ecf20Sopenharmony_ci	.reset = mdfld_dsi_panel_reset,
1968c2ecf20Sopenharmony_ci	.drv_ic_init = mdfld_dsi_tmd_drv_ic_init,
1978c2ecf20Sopenharmony_ci};
198