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
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.
24 * jim liu <jim.liu@intel.com>
25 * Jackie Li<yaodong.li@intel.com>
28 #include "mdfld_dsi_output.h"
29 #include "mdfld_dsi_dbi.h"
30 #include "mdfld_dsi_dpi.h"
31 #include "mdfld_output.h"
32 #include <asm/intel_scu_ipc.h>
33 #include "mdfld_dsi_pkg_sender.h"
34 #include <linux/pm_runtime.h>
36 #define MDFLD_DSI_BRIGHTNESS_MAX_LEVEL 100
38 /* get the CABC LABC from command line. */
39 static int CABC_control = 1;
40 static int LABC_control = 1;
43 module_param (CABC_control, int, 0644);
44 module_param (LABC_control, int, 0644);
46 static int __init parse_CABC_control(char *arg)
48 /* CABC control can be passed in as a cmdline parameter */
49 /* to enable this feature add CABC=1 to cmdline */
50 /* to disable this feature add CABC=0 to cmdline */
54 if (!strcasecmp(arg, "0"))
56 else if (!strcasecmp (arg, "1"))
61 early_param ("CABC", parse_CABC_control);
63 static int __init parse_LABC_control(char *arg)
65 /* LABC control can be passed in as a cmdline parameter */
66 /* to enable this feature add LABC=1 to cmdline */
67 /* to disable this feature add LABC=0 to cmdline */
71 if (!strcasecmp(arg, "0"))
73 else if (!strcasecmp (arg, "1"))
78 early_param ("LABC", parse_LABC_control);
82 * make these MCS command global
83 * we don't need 'movl' everytime we send them.
84 * FIXME: these datas were provided by OEM, we should get them from GCT.
86 static u32 mdfld_dbi_mcs_hysteresis[] = {
87 0x42000f57, 0x8c006400, 0xff00bf00, 0xffffffff,
88 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
89 0x38000aff, 0x82005000, 0xff00ab00, 0xffffffff,
90 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
94 static u32 mdfld_dbi_mcs_display_profile[] = {
95 0x50281450, 0x0000c882, 0x00000000, 0x00000000,
99 static u32 mdfld_dbi_mcs_kbbc_profile[] = {
100 0x00ffcc60, 0x00000000, 0x00000000, 0x00000000,
103 static u32 mdfld_dbi_mcs_gamma_profile[] = {
104 0x81111158, 0x88888888, 0x88888888,
108 * write hysteresis values.
110 static void mdfld_dsi_write_hysteresis (struct mdfld_dsi_config * dsi_config, int pipe)
112 struct mdfld_dsi_pkg_sender * sender = mdfld_dsi_get_pkg_sender(dsi_config);
118 mdfld_dsi_send_mcs_long_hs(sender,
119 mdfld_dbi_mcs_hysteresis,
121 MDFLD_DSI_SEND_PACKAGE);
125 * write display profile values.
127 static void mdfld_dsi_write_display_profile (struct mdfld_dsi_config * dsi_config, int pipe)
129 struct mdfld_dsi_pkg_sender * sender = mdfld_dsi_get_pkg_sender(dsi_config);
135 mdfld_dsi_send_mcs_long_hs(sender,
136 mdfld_dbi_mcs_display_profile,
138 MDFLD_DSI_SEND_PACKAGE);
142 * write KBBC profile values.
144 static void mdfld_dsi_write_kbbc_profile (struct mdfld_dsi_config * dsi_config, int pipe)
146 struct mdfld_dsi_pkg_sender * sender = mdfld_dsi_get_pkg_sender(dsi_config);
152 mdfld_dsi_send_mcs_long_hs(sender,
153 mdfld_dbi_mcs_kbbc_profile,
155 MDFLD_DSI_SEND_PACKAGE);
159 * write gamma setting.
161 static void mdfld_dsi_write_gamma_setting (struct mdfld_dsi_config * dsi_config, int pipe)
163 struct mdfld_dsi_pkg_sender * sender = mdfld_dsi_get_pkg_sender(dsi_config);
169 mdfld_dsi_send_mcs_long_hs(sender,
170 mdfld_dbi_mcs_gamma_profile,
172 MDFLD_DSI_SEND_PACKAGE);
176 * Check and see if the generic control or data buffer is empty and ready.
178 void mdfld_dsi_gen_fifo_ready (struct drm_device *dev, u32 gen_fifo_stat_reg, u32 fifo_stat)
180 u32 GEN_BF_time_out_count = 0;
182 /* Check MIPI Adatper command registers */
183 for (GEN_BF_time_out_count = 0; GEN_BF_time_out_count < GEN_FB_TIME_OUT; GEN_BF_time_out_count++)
185 if ((REG_READ(gen_fifo_stat_reg) & fifo_stat) == fifo_stat)
190 if (GEN_BF_time_out_count == GEN_FB_TIME_OUT)
192 "mdfld_dsi_gen_fifo_ready, Timeout. gen_fifo_stat_reg = 0x%x. \n",
197 * Manage the DSI MIPI keyboard and display brightness.
198 * FIXME: this is exported to OSPM code. should work out an specific
199 * display interface to OSPM.
201 void mdfld_dsi_brightness_init (struct mdfld_dsi_config * dsi_config, int pipe)
203 struct mdfld_dsi_pkg_sender * sender = mdfld_dsi_get_pkg_sender(dsi_config);
204 struct drm_device * dev = sender->dev;
205 struct drm_psb_private * dev_priv = dev->dev_private;
212 /* Set default display backlight value to 85% (0xd8)*/
213 mdfld_dsi_send_mcs_short_hs(sender,
214 write_display_brightness,
217 MDFLD_DSI_SEND_PACKAGE);
219 /* Set minimum brightness setting of CABC function to 20% (0x33)*/
220 mdfld_dsi_send_mcs_short_hs(sender,
221 write_cabc_min_bright,
224 MDFLD_DSI_SEND_PACKAGE);
226 mdfld_dsi_write_hysteresis (dsi_config, pipe);
227 mdfld_dsi_write_display_profile (dsi_config, pipe);
228 mdfld_dsi_write_kbbc_profile (dsi_config, pipe);
229 mdfld_dsi_write_gamma_setting (dsi_config, pipe);
231 /* Enable backlight or/and LABC */
232 gen_ctrl_val = BRIGHT_CNTL_BLOCK_ON | DISPLAY_DIMMING_ON| BACKLIGHT_ON;
233 if (LABC_control == 1 || CABC_control == 1)
234 gen_ctrl_val |= DISPLAY_DIMMING_ON| DISPLAY_BRIGHTNESS_AUTO | GAMMA_AUTO;
236 if (LABC_control == 1)
237 gen_ctrl_val |= AMBIENT_LIGHT_SENSE_ON;
239 dev_priv->mipi_ctrl_display = gen_ctrl_val;
241 mdfld_dsi_send_mcs_short_hs(sender,
245 MDFLD_DSI_SEND_PACKAGE);
247 if (CABC_control == 0)
249 mdfld_dsi_send_mcs_short_hs(sender,
253 MDFLD_DSI_SEND_PACKAGE);
257 * Manage the mipi display brightness.
258 * TODO: refine this interface later
260 void mdfld_dsi_brightness_control(struct drm_device *dev, int pipe, int level)
262 struct mdfld_dsi_pkg_sender *sender;
263 struct drm_psb_private *dev_priv;
264 struct mdfld_dsi_config *dsi_config;
265 u32 gen_ctrl_val = 0;
266 int p_type = TMD_VID;
268 if (!dev || (pipe != 0 && pipe != 2)) {
269 dev_err(dev->dev, "Invalid parameter\n");
273 p_type = mdfld_get_panel_type(dev, 0);
275 dev_priv = dev->dev_private;
278 dsi_config = dev_priv->dsi_configs[1];
280 dsi_config = dev_priv->dsi_configs[0];
282 sender = mdfld_dsi_get_pkg_sender(dsi_config);
289 gen_ctrl_val = ((level * 0xff) / MDFLD_DSI_BRIGHTNESS_MAX_LEVEL) & 0xff;
291 dev_dbg(dev->dev, "pipe = %d, gen_ctrl_val = %d. \n", pipe, gen_ctrl_val);
293 if(p_type == TMD_VID || p_type == TMD_CMD){
294 /* Set display backlight value */
295 mdfld_dsi_send_mcs_short_hs(sender,
296 tmd_write_display_brightness,
299 MDFLD_DSI_SEND_PACKAGE);
301 /* Set display backlight value */
302 mdfld_dsi_send_mcs_short_hs(sender,
303 write_display_brightness,
306 MDFLD_DSI_SEND_PACKAGE);
309 /* Enable backlight control */
313 gen_ctrl_val = dev_priv->mipi_ctrl_display;
315 mdfld_dsi_send_mcs_short_hs(sender,
319 MDFLD_DSI_SEND_PACKAGE);
324 * shut down DSI controller
326 void mdfld_dsi_controller_shutdown(struct mdfld_dsi_config * dsi_config, int pipe)
328 struct drm_device * dev;
329 u32 reg_offset = pipe ? MIPIC_REG_OFFSET : 0;
337 dev = dsi_config->dev;
339 if (!gma_power_begin(dev, true)) {
340 dev_err(dev->dev, "hw begin failed\n");
344 if(!(REG_READ(MIPIA_DEVICE_READY_REG + reg_offset) & DSI_DEVICE_READY))
347 /*send shut down package, clean packet send bit first*/
348 if(REG_READ(MIPIA_INTR_STAT_REG + reg_offset) & DSI_INTR_STATE_SPL_PKG_SENT) {
349 REG_WRITE((MIPIA_INTR_STAT_REG + reg_offset),
350 (REG_READ(MIPIA_INTR_STAT_REG + reg_offset) | DSI_INTR_STATE_SPL_PKG_SENT));
353 /*send shut down package in HS*/
354 REG_WRITE((MIPIA_DPI_CONTROL_REG + reg_offset), DSI_DPI_CTRL_HS_SHUTDOWN);
358 * make sure shut down is sent.
359 * FIXME: add max retry counter
361 while(!(REG_READ(MIPIA_INTR_STAT_REG + reg_offset) & DSI_INTR_STATE_SPL_PKG_SENT)) {
365 dev_err(dev->dev, "timeout\n");
370 /*sleep 1 ms to ensure shutdown finished*/
374 REG_WRITE((MIPIA_DEVICE_READY_REG + reg_offset),
375 (REG_READ(MIPIA_DEVICE_READY_REG + reg_offset) & ~DSI_DEVICE_READY));
381 void mdfld_dsi_controller_startup(struct mdfld_dsi_config * dsi_config, int pipe)
383 struct drm_device * dev;
384 u32 reg_offset = pipe ? MIPIC_REG_OFFSET : 0;
393 dev = dsi_config->dev;
394 dev_dbg(dev->dev, "starting up DSI controller on pipe %d...\n", pipe);
396 if (!gma_power_begin(dev, true)) {
397 dev_err(dev->dev, "hw begin failed\n");
401 if((REG_READ(MIPIA_DEVICE_READY_REG + reg_offset) & DSI_DEVICE_READY))
404 /*if config DPI, turn on DPI interface*/
405 if(dsi_config->type == MDFLD_DSI_ENCODER_DPI) {
406 if(REG_READ(MIPIA_INTR_STAT_REG + reg_offset) & DSI_INTR_STATE_SPL_PKG_SENT) {
407 REG_WRITE((MIPIA_INTR_STAT_REG + reg_offset), DSI_INTR_STATE_SPL_PKG_SENT);
410 REG_WRITE((MIPIA_DPI_CONTROL_REG + reg_offset), DSI_DPI_CTRL_HS_TURN_ON);
413 * make sure shut down is sent.
414 * FIXME: add max retry counter
416 while(!(REG_READ(MIPIA_INTR_STAT_REG + reg_offset) & DSI_INTR_STATE_SPL_PKG_SENT)) {
419 dev_err(dev->dev, "timeout\n");
428 REG_WRITE((MIPIA_DEVICE_READY_REG + reg_offset),
429 (REG_READ(MIPIA_DEVICE_READY_REG + reg_offset) | DSI_DEVICE_READY));
436 * NOTE: this function was used by OSPM.
437 * TODO: will be removed later, should work out display interfaces for OSPM
439 void mdfld_dsi_controller_init(struct mdfld_dsi_config * dsi_config, int pipe)
441 if(!dsi_config || ((pipe != 0) && (pipe != 2))) {
447 mdfld_dsi_dpi_controller_init(dsi_config, pipe);
449 mdfld_dsi_controller_dbi_init(dsi_config, pipe);
452 static void mdfld_dsi_connector_save(struct drm_connector * connector)
456 static void mdfld_dsi_connector_restore(struct drm_connector * connector)
460 static enum drm_connector_status mdfld_dsi_connector_detect(struct drm_connector * connector, bool force)
462 return connector_status_connected;
465 static int mdfld_dsi_connector_set_property(struct drm_connector * connector,
466 struct drm_property * property,
469 struct drm_encoder * encoder = connector->encoder;
470 struct backlight_device * psb_bd;
472 if (!strcmp(property->name, "scaling mode") && encoder) {
473 struct psb_intel_crtc * psb_crtc = to_psb_intel_crtc(encoder->crtc);
474 bool bTransitionFromToCentered;
481 case DRM_MODE_SCALE_FULLSCREEN:
483 case DRM_MODE_SCALE_NO_SCALE:
485 case DRM_MODE_SCALE_ASPECT:
491 if (drm_connector_property_get_value(connector, property, &curValue))
494 if (curValue == value)
497 if (drm_connector_property_set_value(connector, property, value))
500 bTransitionFromToCentered = (curValue == DRM_MODE_SCALE_NO_SCALE) ||
501 (value == DRM_MODE_SCALE_NO_SCALE);
503 if (psb_crtc->saved_mode.hdisplay != 0 &&
504 psb_crtc->saved_mode.vdisplay != 0) {
505 if (bTransitionFromToCentered) {
506 if (!drm_crtc_helper_set_mode(encoder->crtc, &psb_crtc->saved_mode,
507 encoder->crtc->x, encoder->crtc->y, encoder->crtc->fb))
510 struct drm_encoder_helper_funcs *pEncHFuncs = encoder->helper_private;
511 pEncHFuncs->mode_set(encoder, &psb_crtc->saved_mode,
512 &psb_crtc->saved_adjusted_mode);
515 } else if (!strcmp(property->name, "backlight") && encoder) {
516 dev_dbg(encoder->dev->dev, "backlight level = %d\n", (int)value);
517 if (drm_connector_property_set_value(connector, property, value))
520 dev_dbg(encoder->dev->dev,
521 "set brightness to %d", (int)value);
522 psb_bd = psb_get_backlight_device();
524 psb_bd->props.brightness = value;
525 psb_set_brightness(psb_bd);
535 static void mdfld_dsi_connector_destroy(struct drm_connector * connector)
537 struct psb_intel_output * psb_output = to_psb_intel_output(connector);
538 struct mdfld_dsi_connector * dsi_connector = MDFLD_DSI_CONNECTOR(psb_output);
539 struct mdfld_dsi_pkg_sender * sender;
544 drm_sysfs_connector_remove(connector);
545 drm_connector_cleanup(connector);
547 sender = dsi_connector->pkg_sender;
549 mdfld_dsi_pkg_sender_destroy(sender);
551 kfree(dsi_connector);
554 static int mdfld_dsi_connector_get_modes(struct drm_connector * connector)
556 struct psb_intel_output * psb_output = to_psb_intel_output(connector);
557 struct mdfld_dsi_connector * dsi_connector = MDFLD_DSI_CONNECTOR(psb_output);
558 struct mdfld_dsi_config * dsi_config = mdfld_dsi_get_config(dsi_connector);
559 struct drm_display_mode * fixed_mode = dsi_config->fixed_mode;
560 struct drm_display_mode * dup_mode = NULL;
561 struct drm_device * dev = connector->dev;
563 connector->display_info.min_vfreq = 0;
564 connector->display_info.max_vfreq = 200;
565 connector->display_info.min_hfreq = 0;
566 connector->display_info.max_hfreq = 200;
569 dev_dbg(dev->dev, "fixed_mode %dx%d\n",
570 fixed_mode->hdisplay, fixed_mode->vdisplay);
572 dup_mode = drm_mode_duplicate(dev, fixed_mode);
573 drm_mode_probed_add(connector, dup_mode);
576 dev_err(dev->dev, "Didn't get any modes!\n");
580 static int mdfld_dsi_connector_mode_valid(struct drm_connector * connector, struct drm_display_mode * mode)
582 struct psb_intel_output * psb_output = to_psb_intel_output(connector);
583 struct mdfld_dsi_connector * dsi_connector = MDFLD_DSI_CONNECTOR(psb_output);
584 struct mdfld_dsi_config * dsi_config = mdfld_dsi_get_config(dsi_connector);
585 struct drm_display_mode * fixed_mode = dsi_config->fixed_mode;
587 dev_dbg(connector->dev->dev, "mode %p, fixed mode %p\n",
590 if(mode->flags & DRM_MODE_FLAG_DBLSCAN)
591 return MODE_NO_DBLESCAN;
593 if(mode->flags & DRM_MODE_FLAG_INTERLACE)
594 return MODE_NO_INTERLACE;
597 * FIXME: current DC has no fitting unit, reject any mode setting request
598 * will figure out a way to do up-scaling(pannel fitting) later.
601 if(mode->hdisplay != fixed_mode->hdisplay)
604 if(mode->vdisplay != fixed_mode->vdisplay)
607 dev_dbg(connector->dev->dev, "mode ok\n");
612 static void mdfld_dsi_connector_dpms(struct drm_connector *connector, int mode)
614 #ifdef CONFIG_PM_RUNTIME
615 struct drm_device * dev = connector->dev;
616 struct drm_psb_private * dev_priv = dev->dev_private;
617 bool panel_on, panel_on2;
619 /* First, execute DPMS */
620 drm_helper_connector_dpms(connector, mode);
622 #ifdef CONFIG_PM_RUNTIME
623 if(mdfld_panel_dpi(dev)) {
625 panel_on = dev_priv->dpi_panel_on;
626 panel_on2 = dev_priv->dpi_panel_on2;
629 panel_on = dev_priv->dbi_panel_on;
630 panel_on2 = dev_priv->dbi_panel_on2;
633 /* Then check all display panels + monitors status */
634 if(!panel_on && !panel_on2 && !(REG_READ(HDMIB_CONTROL)
637 if(dev_priv->rpm_enabled)
638 pm_request_idle(&dev->pdev->dev);
641 * if rpm wasn't enabled yet, try to allow it
642 * FIXME: won't enable rpm for DPI since DPI
643 * CRTC setting is a little messy now.
647 if(!dev_priv->rpm_enabled && !mdfld_panel_dpi(dev))
648 ospm_runtime_pm_allow(dev);
653 static struct drm_encoder * mdfld_dsi_connector_best_encoder(
654 struct drm_connector * connector)
656 struct psb_intel_output * psb_output = to_psb_intel_output(connector);
657 struct mdfld_dsi_connector * dsi_connector = MDFLD_DSI_CONNECTOR(psb_output);
658 struct mdfld_dsi_config * dsi_config = mdfld_dsi_get_config(dsi_connector);
659 struct mdfld_dsi_encoder * encoder = NULL;
661 if(dsi_config->type == MDFLD_DSI_ENCODER_DBI)
662 encoder = dsi_config->encoders[MDFLD_DSI_ENCODER_DBI];
663 else if (dsi_config->type == MDFLD_DSI_ENCODER_DPI)
664 encoder = dsi_config->encoders[MDFLD_DSI_ENCODER_DPI];
666 dev_dbg(connector->dev->dev, "get encoder %p\n", encoder);
669 dev_err(connector->dev->dev,
670 "Invalid encoder for type %d\n", dsi_config->type);
673 dsi_config->encoder = encoder;
674 return &encoder->base;
677 /* DSI connector funcs */
678 static const struct drm_connector_funcs mdfld_dsi_connector_funcs = {
679 .dpms = /*drm_helper_connector_dpms*/mdfld_dsi_connector_dpms,
680 .save = mdfld_dsi_connector_save,
681 .restore = mdfld_dsi_connector_restore,
682 .detect = mdfld_dsi_connector_detect,
683 .fill_modes = drm_helper_probe_single_connector_modes,
684 .set_property = mdfld_dsi_connector_set_property,
685 .destroy = mdfld_dsi_connector_destroy,
688 /* DSI connector helper funcs */
689 static const struct drm_connector_helper_funcs mdfld_dsi_connector_helper_funcs = {
690 .get_modes = mdfld_dsi_connector_get_modes,
691 .mode_valid = mdfld_dsi_connector_mode_valid,
692 .best_encoder = mdfld_dsi_connector_best_encoder,
695 static int mdfld_dsi_get_default_config(struct drm_device * dev,
696 struct mdfld_dsi_config * config, int pipe)
698 if(!dev || !config) {
704 config->type = mdfld_panel_dpi(dev);
705 config->lane_count = 2;
706 config->channel_num = 0;
707 /*NOTE: video mode is ignored when type is MDFLD_DSI_ENCODER_DBI*/
708 if (mdfld_get_panel_type(dev, pipe) == TMD_VID) {
709 config->video_mode = MDFLD_DSI_VIDEO_NON_BURST_MODE_SYNC_PULSE;
711 config->video_mode = MDFLD_DSI_VIDEO_BURST_MODE;
718 * Returns the panel fixed mode from configuration.
720 struct drm_display_mode *
721 mdfld_dsi_get_configuration_mode(struct mdfld_dsi_config * dsi_config, int pipe)
723 struct drm_device *dev = dsi_config->dev;
724 struct drm_display_mode *mode;
725 struct drm_psb_private *dev_priv = dev->dev_private;
726 struct mrst_timing_info *ti = &dev_priv->gct_data.DTD;
727 bool use_gct = false;
729 mode = kzalloc(sizeof(*mode), GFP_KERNEL);
731 dev_err(dev->dev, "Out of memory for mode\n");
735 dev_dbg(dev->dev, "gct find MIPI panel.\n");
737 mode->hdisplay = (ti->hactive_hi << 8) | ti->hactive_lo;
738 mode->vdisplay = (ti->vactive_hi << 8) | ti->vactive_lo;
739 mode->hsync_start = mode->hdisplay + \
740 ((ti->hsync_offset_hi << 8) | \
741 ti->hsync_offset_lo);
742 mode->hsync_end = mode->hsync_start + \
743 ((ti->hsync_pulse_width_hi << 8) | \
744 ti->hsync_pulse_width_lo);
745 mode->htotal = mode->hdisplay + ((ti->hblank_hi << 8) | \
747 mode->vsync_start = \
748 mode->vdisplay + ((ti->vsync_offset_hi << 8) | \
749 ti->vsync_offset_lo);
751 mode->vsync_start + ((ti->vsync_pulse_width_hi << 8) | \
752 ti->vsync_pulse_width_lo);
753 mode->vtotal = mode->vdisplay + \
754 ((ti->vblank_hi << 8) | ti->vblank_lo);
755 mode->clock = ti->pixel_clock * 10;
757 dev_dbg(dev->dev, "hdisplay is %d\n", mode->hdisplay);
758 dev_dbg(dev->dev, "vdisplay is %d\n", mode->vdisplay);
759 dev_dbg(dev->dev, "HSS is %d\n", mode->hsync_start);
760 dev_dbg(dev->dev, "HSE is %d\n", mode->hsync_end);
761 dev_dbg(dev->dev, "htotal is %d\n", mode->htotal);
762 dev_dbg(dev->dev, "VSS is %d\n", mode->vsync_start);
763 dev_dbg(dev->dev, "VSE is %d\n", mode->vsync_end);
764 dev_dbg(dev->dev, "vtotal is %d\n", mode->vtotal);
765 dev_dbg(dev->dev, "clock is %d\n", mode->clock);
767 if(dsi_config->type == MDFLD_DSI_ENCODER_DPI) {
768 if (mdfld_get_panel_type(dev, pipe) == TMD_VID) {
769 mode->hdisplay = 480;
770 mode->vdisplay = 854;
771 mode->hsync_start = 487;
772 mode->hsync_end = 490;
774 mode->vsync_start = 861;
775 mode->vsync_end = 865;
779 mode->hdisplay = 864;
780 mode->vdisplay = 480;
781 mode->hsync_start = 873;
782 mode->hsync_end = 876;
784 mode->vsync_start = 487;
785 mode->vsync_end = 490;
789 } else if(dsi_config->type == MDFLD_DSI_ENCODER_DBI) {
790 mode->hdisplay = 864;
791 mode->vdisplay = 480;
792 mode->hsync_start = 872;
793 mode->hsync_end = 876;
795 mode->vsync_start = 482;
796 mode->vsync_end = 494;
803 drm_mode_set_name(mode);
804 drm_mode_set_crtcinfo(mode, 0);
806 mode->type |= DRM_MODE_TYPE_PREFERRED;
814 * @pipe pipe number. 0 or 2
817 * Do the initialization of a MIPI output, including create DRM mode objects
818 * initialization of DSI output on @pipe
820 void mdfld_dsi_output_init(struct drm_device * dev,
822 struct mdfld_dsi_config * config,
823 struct panel_funcs* p_cmd_funcs,
824 struct panel_funcs* p_vid_funcs)
826 struct mdfld_dsi_config * dsi_config;
827 struct mdfld_dsi_connector * dsi_connector;
828 struct psb_intel_output * psb_output;
829 struct drm_connector * connector;
830 struct mdfld_dsi_encoder * encoder;
831 struct drm_psb_private * dev_priv = dev->dev_private;
832 struct panel_info dsi_panel_info;
833 u32 width_mm, height_mm;
835 dev_dbg(dev->dev, "init DSI output on pipe %d\n", pipe);
837 if(!dev || ((pipe != 0) && (pipe != 2))) {
842 /*create a new connetor*/
843 dsi_connector = kzalloc(sizeof(struct mdfld_dsi_connector), GFP_KERNEL);
845 DRM_ERROR("No memory");
849 dsi_connector->pipe = pipe;
855 dsi_config = kzalloc(sizeof(struct mdfld_dsi_config), GFP_KERNEL);
858 "cannot allocate memory for DSI config\n");
862 mdfld_dsi_get_default_config(dev, dsi_config, pipe);
865 dsi_connector->private = dsi_config;
867 dsi_config->changed = 1;
868 dsi_config->dev = dev;
870 /*init fixed mode basing on DSI config type*/
871 if(dsi_config->type == MDFLD_DSI_ENCODER_DBI) {
872 dsi_config->fixed_mode = p_cmd_funcs->get_config_mode(dev);
873 if(p_cmd_funcs->get_panel_info(dev, pipe, &dsi_panel_info))
875 } else if(dsi_config->type == MDFLD_DSI_ENCODER_DPI) {
876 dsi_config->fixed_mode = p_vid_funcs->get_config_mode(dev);
877 if(p_vid_funcs->get_panel_info(dev, pipe, &dsi_panel_info))
881 width_mm = dsi_panel_info.width_mm;
882 height_mm = dsi_panel_info.height_mm;
884 dsi_config->mode = dsi_config->fixed_mode;
885 dsi_config->connector = dsi_connector;
887 if(!dsi_config->fixed_mode) {
888 dev_err(dev->dev, "No pannel fixed mode was found\n");
892 if(pipe && dev_priv->dsi_configs[0]) {
893 dsi_config->dvr_ic_inited = 0;
894 dev_priv->dsi_configs[1] = dsi_config;
895 } else if(pipe == 0) {
896 dsi_config->dvr_ic_inited = 1;
897 dev_priv->dsi_configs[0] = dsi_config;
899 dev_err(dev->dev, "Trying to init MIPI1 before MIPI0\n");
903 /*init drm connector object*/
904 psb_output = &dsi_connector->base;
906 psb_output->type = (pipe == 0) ? INTEL_OUTPUT_MIPI : INTEL_OUTPUT_MIPI2;
908 connector = &psb_output->base;
909 drm_connector_init(dev, connector, &mdfld_dsi_connector_funcs, DRM_MODE_CONNECTOR_MIPI);
910 drm_connector_helper_add(connector, &mdfld_dsi_connector_helper_funcs);
912 connector->display_info.subpixel_order = SubPixelHorizontalRGB;
913 connector->display_info.width_mm = width_mm;
914 connector->display_info.height_mm = height_mm;
915 connector->interlace_allowed = false;
916 connector->doublescan_allowed = false;
918 /*attach properties*/
919 drm_connector_attach_property(connector, dev->mode_config.scaling_mode_property, DRM_MODE_SCALE_FULLSCREEN);
920 drm_connector_attach_property(connector, dev_priv->backlight_property, MDFLD_DSI_BRIGHTNESS_MAX_LEVEL);
922 /*init DBI & DPI encoders*/
924 encoder = mdfld_dsi_dbi_init(dev, dsi_connector, p_cmd_funcs);
926 dev_err(dev->dev, "Create DBI encoder failed\n");
929 encoder->private = dsi_config;
930 dsi_config->encoders[MDFLD_DSI_ENCODER_DBI] = encoder;
932 dev_priv->encoder2 = encoder;
935 dev_priv->encoder0 = encoder;
940 encoder = mdfld_dsi_dpi_init(dev, dsi_connector, p_vid_funcs);
942 dev_err(dev->dev, "Create DPI encoder failed\n");
945 encoder->private = dsi_config;
946 dsi_config->encoders[MDFLD_DSI_ENCODER_DPI] = encoder;
949 dev_priv->encoder2 = encoder;
952 dev_priv->encoder0 = encoder;
955 drm_sysfs_connector_add(connector);
957 /*init DSI package sender on this output*/
958 if(mdfld_dsi_pkg_sender_init(dsi_connector, pipe)) {
960 "Package Sender initialization failed on pipe %d\n",
965 dev_dbg(dev->dev, "successfully\n");
968 /*TODO: add code to destroy outputs on error*/
970 drm_sysfs_connector_remove(connector);
972 drm_connector_cleanup(connector);
973 kfree(dsi_config->fixed_mode);
976 kfree(dsi_connector);