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.
28 #include <linux/delay.h>
29 #include <linux/moduleparam.h>
30 #include <linux/pm_runtime.h>
31 #include <linux/gpio/consumer.h>
33 #include <asm/intel_scu_ipc.h>
35 #include "mdfld_dsi_dpi.h"
36 #include "mdfld_dsi_output.h"
37 #include "mdfld_dsi_pkg_sender.h"
38 #include "mdfld_output.h"
39 #include "tc35876x-dsi-lvds.h"
41 /* get the LABC from command line. */
42 static int LABC_control = 1;
45 module_param(LABC_control, int, 0644);
48 static int __init parse_LABC_control(char *arg)
50 /* LABC control can be passed in as a cmdline parameter */
51 /* to enable this feature add LABC=1 to cmdline */
52 /* to disable this feature add LABC=0 to cmdline */
56 if (!strcasecmp(arg, "0"))
58 else if (!strcasecmp(arg, "1"))
63 early_param("LABC", parse_LABC_control);
67 * Check and see if the generic control or data buffer is empty and ready.
69 void mdfld_dsi_gen_fifo_ready(struct drm_device *dev, u32 gen_fifo_stat_reg,
72 u32 GEN_BF_time_out_count;
74 /* Check MIPI Adatper command registers */
75 for (GEN_BF_time_out_count = 0;
76 GEN_BF_time_out_count < GEN_FB_TIME_OUT;
77 GEN_BF_time_out_count++) {
78 if ((REG_READ(gen_fifo_stat_reg) & fifo_stat) == fifo_stat)
83 if (GEN_BF_time_out_count == GEN_FB_TIME_OUT)
84 DRM_ERROR("mdfld_dsi_gen_fifo_ready, Timeout. gen_fifo_stat_reg = 0x%x.\n",
89 * Manage the DSI MIPI keyboard and display brightness.
90 * FIXME: this is exported to OSPM code. should work out an specific
91 * display interface to OSPM.
94 void mdfld_dsi_brightness_init(struct mdfld_dsi_config *dsi_config, int pipe)
96 struct mdfld_dsi_pkg_sender *sender =
97 mdfld_dsi_get_pkg_sender(dsi_config);
98 struct drm_device *dev;
99 struct drm_psb_private *dev_priv;
103 DRM_ERROR("No sender found\n");
108 dev_priv = dev->dev_private;
110 /* Set default display backlight value to 85% (0xd8)*/
111 mdfld_dsi_send_mcs_short(sender, write_display_brightness, 0xd8, 1,
114 /* Set minimum brightness setting of CABC function to 20% (0x33)*/
115 mdfld_dsi_send_mcs_short(sender, write_cabc_min_bright, 0x33, 1, true);
117 /* Enable backlight or/and LABC */
118 gen_ctrl_val = BRIGHT_CNTL_BLOCK_ON | DISPLAY_DIMMING_ON |
120 if (LABC_control == 1)
121 gen_ctrl_val |= DISPLAY_DIMMING_ON | DISPLAY_BRIGHTNESS_AUTO
124 if (LABC_control == 1)
125 gen_ctrl_val |= AMBIENT_LIGHT_SENSE_ON;
127 dev_priv->mipi_ctrl_display = gen_ctrl_val;
129 mdfld_dsi_send_mcs_short(sender, write_ctrl_display, (u8)gen_ctrl_val,
132 mdfld_dsi_send_mcs_short(sender, write_ctrl_cabc, UI_IMAGE, 1, true);
135 void mdfld_dsi_brightness_control(struct drm_device *dev, int pipe, int level)
137 struct mdfld_dsi_pkg_sender *sender;
138 struct drm_psb_private *dev_priv;
139 struct mdfld_dsi_config *dsi_config;
140 u32 gen_ctrl_val = 0;
141 int p_type = TMD_VID;
143 if (!dev || (pipe != 0 && pipe != 2)) {
144 DRM_ERROR("Invalid parameter\n");
148 p_type = mdfld_get_panel_type(dev, 0);
150 dev_priv = dev->dev_private;
153 dsi_config = dev_priv->dsi_configs[1];
155 dsi_config = dev_priv->dsi_configs[0];
157 sender = mdfld_dsi_get_pkg_sender(dsi_config);
160 DRM_ERROR("No sender found\n");
164 gen_ctrl_val = (level * 0xff / MDFLD_DSI_BRIGHTNESS_MAX_LEVEL) & 0xff;
166 dev_dbg(sender->dev->dev, "pipe = %d, gen_ctrl_val = %d.\n",
169 if (p_type == TMD_VID) {
170 /* Set display backlight value */
171 mdfld_dsi_send_mcs_short(sender, tmd_write_display_brightness,
172 (u8)gen_ctrl_val, 1, true);
174 /* Set display backlight value */
175 mdfld_dsi_send_mcs_short(sender, write_display_brightness,
176 (u8)gen_ctrl_val, 1, true);
178 /* Enable backlight control */
182 gen_ctrl_val = dev_priv->mipi_ctrl_display;
184 mdfld_dsi_send_mcs_short(sender, write_ctrl_display,
185 (u8)gen_ctrl_val, 1, true);
189 static int mdfld_dsi_get_panel_status(struct mdfld_dsi_config *dsi_config,
190 u8 dcs, u32 *data, bool hs)
192 struct mdfld_dsi_pkg_sender *sender
193 = mdfld_dsi_get_pkg_sender(dsi_config);
195 if (!sender || !data) {
196 DRM_ERROR("Invalid parameter\n");
200 return mdfld_dsi_read_mcs(sender, dcs, data, 1, hs);
203 int mdfld_dsi_get_power_mode(struct mdfld_dsi_config *dsi_config, u32 *mode,
206 if (!dsi_config || !mode) {
207 DRM_ERROR("Invalid parameter\n");
211 return mdfld_dsi_get_panel_status(dsi_config, 0x0a, mode, hs);
215 * NOTE: this function was used by OSPM.
216 * TODO: will be removed later, should work out display interfaces for OSPM
218 void mdfld_dsi_controller_init(struct mdfld_dsi_config *dsi_config, int pipe)
220 if (!dsi_config || ((pipe != 0) && (pipe != 2))) {
221 DRM_ERROR("Invalid parameters\n");
225 mdfld_dsi_dpi_controller_init(dsi_config, pipe);
228 static void mdfld_dsi_connector_save(struct drm_connector *connector)
232 static void mdfld_dsi_connector_restore(struct drm_connector *connector)
236 /* FIXME: start using the force parameter */
237 static enum drm_connector_status
238 mdfld_dsi_connector_detect(struct drm_connector *connector, bool force)
240 struct mdfld_dsi_connector *dsi_connector
241 = mdfld_dsi_connector(connector);
243 dsi_connector->status = connector_status_connected;
245 return dsi_connector->status;
248 static int mdfld_dsi_connector_set_property(struct drm_connector *connector,
249 struct drm_property *property,
252 struct drm_encoder *encoder = connector->encoder;
254 if (!strcmp(property->name, "scaling mode") && encoder) {
255 struct gma_crtc *gma_crtc = to_gma_crtc(encoder->crtc);
263 case DRM_MODE_SCALE_FULLSCREEN:
265 case DRM_MODE_SCALE_NO_SCALE:
267 case DRM_MODE_SCALE_ASPECT:
273 if (drm_object_property_get_value(&connector->base, property, &val))
279 if (drm_object_property_set_value(&connector->base,
283 centerechange = (val == DRM_MODE_SCALE_NO_SCALE) ||
284 (value == DRM_MODE_SCALE_NO_SCALE);
286 if (gma_crtc->saved_mode.hdisplay != 0 &&
287 gma_crtc->saved_mode.vdisplay != 0) {
289 if (!drm_crtc_helper_set_mode(encoder->crtc,
290 &gma_crtc->saved_mode,
293 encoder->crtc->primary->fb))
296 const struct drm_encoder_helper_funcs *funcs =
297 encoder->helper_private;
298 funcs->mode_set(encoder,
299 &gma_crtc->saved_mode,
300 &gma_crtc->saved_adjusted_mode);
303 } else if (!strcmp(property->name, "backlight") && encoder) {
304 if (drm_object_property_set_value(&connector->base, property,
308 gma_backlight_set(encoder->dev, value);
316 static void mdfld_dsi_connector_destroy(struct drm_connector *connector)
318 struct mdfld_dsi_connector *dsi_connector =
319 mdfld_dsi_connector(connector);
320 struct mdfld_dsi_pkg_sender *sender;
324 drm_connector_unregister(connector);
325 drm_connector_cleanup(connector);
326 sender = dsi_connector->pkg_sender;
327 mdfld_dsi_pkg_sender_destroy(sender);
328 kfree(dsi_connector);
331 static int mdfld_dsi_connector_get_modes(struct drm_connector *connector)
333 struct mdfld_dsi_connector *dsi_connector =
334 mdfld_dsi_connector(connector);
335 struct mdfld_dsi_config *dsi_config =
336 mdfld_dsi_get_config(dsi_connector);
337 struct drm_display_mode *fixed_mode = dsi_config->fixed_mode;
338 struct drm_display_mode *dup_mode = NULL;
339 struct drm_device *dev = connector->dev;
342 dev_dbg(dev->dev, "fixed_mode %dx%d\n",
343 fixed_mode->hdisplay, fixed_mode->vdisplay);
344 dup_mode = drm_mode_duplicate(dev, fixed_mode);
345 drm_mode_probed_add(connector, dup_mode);
348 DRM_ERROR("Didn't get any modes!\n");
352 static enum drm_mode_status mdfld_dsi_connector_mode_valid(struct drm_connector *connector,
353 struct drm_display_mode *mode)
355 struct mdfld_dsi_connector *dsi_connector =
356 mdfld_dsi_connector(connector);
357 struct mdfld_dsi_config *dsi_config =
358 mdfld_dsi_get_config(dsi_connector);
359 struct drm_display_mode *fixed_mode = dsi_config->fixed_mode;
361 if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
362 return MODE_NO_DBLESCAN;
364 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
365 return MODE_NO_INTERLACE;
368 * FIXME: current DC has no fitting unit, reject any mode setting
370 * Will figure out a way to do up-scaling(panel fitting) later.
373 if (mode->hdisplay != fixed_mode->hdisplay)
376 if (mode->vdisplay != fixed_mode->vdisplay)
383 static struct drm_encoder *mdfld_dsi_connector_best_encoder(
384 struct drm_connector *connector)
386 struct mdfld_dsi_connector *dsi_connector =
387 mdfld_dsi_connector(connector);
388 struct mdfld_dsi_config *dsi_config =
389 mdfld_dsi_get_config(dsi_connector);
390 return &dsi_config->encoder->base.base;
393 /*DSI connector funcs*/
394 static const struct drm_connector_funcs mdfld_dsi_connector_funcs = {
395 .dpms = drm_helper_connector_dpms,
396 .detect = mdfld_dsi_connector_detect,
397 .fill_modes = drm_helper_probe_single_connector_modes,
398 .set_property = mdfld_dsi_connector_set_property,
399 .destroy = mdfld_dsi_connector_destroy,
402 /*DSI connector helper funcs*/
403 static const struct drm_connector_helper_funcs
404 mdfld_dsi_connector_helper_funcs = {
405 .get_modes = mdfld_dsi_connector_get_modes,
406 .mode_valid = mdfld_dsi_connector_mode_valid,
407 .best_encoder = mdfld_dsi_connector_best_encoder,
410 static int mdfld_dsi_get_default_config(struct drm_device *dev,
411 struct mdfld_dsi_config *config, int pipe)
413 if (!dev || !config) {
414 DRM_ERROR("Invalid parameters");
419 if (mdfld_get_panel_type(dev, pipe) == TC35876X)
420 config->lane_count = 4;
422 config->lane_count = 2;
423 config->channel_num = 0;
425 if (mdfld_get_panel_type(dev, pipe) == TMD_VID)
426 config->video_mode = MDFLD_DSI_VIDEO_NON_BURST_MODE_SYNC_PULSE;
427 else if (mdfld_get_panel_type(dev, pipe) == TC35876X)
429 MDFLD_DSI_VIDEO_NON_BURST_MODE_SYNC_EVENTS;
431 config->video_mode = MDFLD_DSI_VIDEO_BURST_MODE;
436 int mdfld_dsi_panel_reset(struct drm_device *ddev, int pipe)
438 struct device *dev = ddev->dev;
439 struct gpio_desc *gpiod;
442 * Raise the GPIO reset line for the corresponding pipe to HIGH,
443 * this is probably because it is active low so this takes the
444 * respective pipe out of reset. (We have no code to put it back
445 * into reset in this driver.)
449 gpiod = gpiod_get(dev, "dsi-pipe0-reset", GPIOD_OUT_HIGH);
451 return PTR_ERR(gpiod);
454 gpiod = gpiod_get(dev, "dsi-pipe2-reset", GPIOD_OUT_HIGH);
456 return PTR_ERR(gpiod);
459 DRM_DEV_ERROR(dev, "Invalid output pipe\n");
464 /* Flush posted writes on the device */
465 gpiod = gpiod_get(dev, "dsi-pipe0-reset", GPIOD_ASIS);
467 return PTR_ERR(gpiod);
468 gpiod_get_value(gpiod);
477 * @pipe pipe number. 0 or 2
480 * Do the initialization of a MIPI output, including create DRM mode objects
481 * initialization of DSI output on @pipe
483 void mdfld_dsi_output_init(struct drm_device *dev,
485 const struct panel_funcs *p_vid_funcs)
487 struct mdfld_dsi_config *dsi_config;
488 struct mdfld_dsi_connector *dsi_connector;
489 struct drm_connector *connector;
490 struct mdfld_dsi_encoder *encoder;
491 struct drm_psb_private *dev_priv = dev->dev_private;
492 struct panel_info dsi_panel_info;
493 u32 width_mm, height_mm;
495 dev_dbg(dev->dev, "init DSI output on pipe %d\n", pipe);
497 if (pipe != 0 && pipe != 2) {
498 DRM_ERROR("Invalid parameter\n");
502 /*create a new connector*/
503 dsi_connector = kzalloc(sizeof(struct mdfld_dsi_connector), GFP_KERNEL);
504 if (!dsi_connector) {
505 DRM_ERROR("No memory");
509 dsi_connector->pipe = pipe;
511 dsi_config = kzalloc(sizeof(struct mdfld_dsi_config),
514 DRM_ERROR("cannot allocate memory for DSI config\n");
517 mdfld_dsi_get_default_config(dev, dsi_config, pipe);
519 dsi_connector->private = dsi_config;
521 dsi_config->changed = 1;
522 dsi_config->dev = dev;
524 dsi_config->fixed_mode = p_vid_funcs->get_config_mode(dev);
525 if (p_vid_funcs->get_panel_info(dev, pipe, &dsi_panel_info))
528 width_mm = dsi_panel_info.width_mm;
529 height_mm = dsi_panel_info.height_mm;
531 dsi_config->mode = dsi_config->fixed_mode;
532 dsi_config->connector = dsi_connector;
534 if (!dsi_config->fixed_mode) {
535 DRM_ERROR("No panel fixed mode was found\n");
539 if (pipe && dev_priv->dsi_configs[0]) {
540 dsi_config->dvr_ic_inited = 0;
541 dev_priv->dsi_configs[1] = dsi_config;
542 } else if (pipe == 0) {
543 dsi_config->dvr_ic_inited = 1;
544 dev_priv->dsi_configs[0] = dsi_config;
546 DRM_ERROR("Trying to init MIPI1 before MIPI0\n");
551 connector = &dsi_connector->base.base;
552 dsi_connector->base.save = mdfld_dsi_connector_save;
553 dsi_connector->base.restore = mdfld_dsi_connector_restore;
555 drm_connector_init(dev, connector, &mdfld_dsi_connector_funcs,
556 DRM_MODE_CONNECTOR_LVDS);
557 drm_connector_helper_add(connector, &mdfld_dsi_connector_helper_funcs);
559 connector->display_info.subpixel_order = SubPixelHorizontalRGB;
560 connector->display_info.width_mm = width_mm;
561 connector->display_info.height_mm = height_mm;
562 connector->interlace_allowed = false;
563 connector->doublescan_allowed = false;
565 /*attach properties*/
566 drm_object_attach_property(&connector->base,
567 dev->mode_config.scaling_mode_property,
568 DRM_MODE_SCALE_FULLSCREEN);
569 drm_object_attach_property(&connector->base,
570 dev_priv->backlight_property,
571 MDFLD_DSI_BRIGHTNESS_MAX_LEVEL);
573 /*init DSI package sender on this output*/
574 if (mdfld_dsi_pkg_sender_init(dsi_connector, pipe)) {
575 DRM_ERROR("Package Sender initialization failed on pipe %d\n",
580 encoder = mdfld_dsi_dpi_init(dev, dsi_connector, p_vid_funcs);
582 DRM_ERROR("Create DPI encoder failed\n");
585 encoder->private = dsi_config;
586 dsi_config->encoder = encoder;
587 encoder->base.type = (pipe == 0) ? INTEL_OUTPUT_MIPI :
589 drm_connector_register(connector);
592 /*TODO: add code to destroy outputs on error*/
595 mdfld_dsi_pkg_sender_destroy(dsi_connector->pkg_sender);
597 drm_connector_cleanup(connector);
599 kfree(dsi_config->fixed_mode);
602 kfree(dsi_connector);