Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2010 Intel Corporation |
| 3 | * |
| 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: |
| 10 | * |
| 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. |
| 14 | * |
| 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. |
| 22 | * |
| 23 | * Authors: |
| 24 | * jim liu <jim.liu@intel.com> |
| 25 | * Jackie Li<yaodong.li@intel.com> |
| 26 | */ |
| 27 | |
| 28 | #include <linux/module.h> |
| 29 | |
| 30 | #include "mdfld_dsi_output.h" |
| 31 | #include "mdfld_dsi_dpi.h" |
| 32 | #include "mdfld_output.h" |
| 33 | #include "mdfld_dsi_pkg_sender.h" |
| 34 | #include "tc35876x-dsi-lvds.h" |
| 35 | #include <linux/pm_runtime.h> |
| 36 | #include <asm/intel_scu_ipc.h> |
| 37 | |
| 38 | /* get the LABC from command line. */ |
| 39 | static int LABC_control = 1; |
| 40 | |
| 41 | #ifdef MODULE |
| 42 | module_param(LABC_control, int, 0644); |
| 43 | #else |
| 44 | |
| 45 | static int __init parse_LABC_control(char *arg) |
| 46 | { |
| 47 | /* LABC control can be passed in as a cmdline parameter */ |
| 48 | /* to enable this feature add LABC=1 to cmdline */ |
| 49 | /* to disable this feature add LABC=0 to cmdline */ |
| 50 | if (!arg) |
| 51 | return -EINVAL; |
| 52 | |
| 53 | if (!strcasecmp(arg, "0")) |
| 54 | LABC_control = 0; |
| 55 | else if (!strcasecmp(arg, "1")) |
| 56 | LABC_control = 1; |
| 57 | |
| 58 | return 0; |
| 59 | } |
| 60 | early_param("LABC", parse_LABC_control); |
| 61 | #endif |
| 62 | |
| 63 | /** |
| 64 | * Check and see if the generic control or data buffer is empty and ready. |
| 65 | */ |
| 66 | void mdfld_dsi_gen_fifo_ready(struct drm_device *dev, u32 gen_fifo_stat_reg, |
| 67 | u32 fifo_stat) |
| 68 | { |
| 69 | u32 GEN_BF_time_out_count; |
| 70 | |
| 71 | /* Check MIPI Adatper command registers */ |
| 72 | for (GEN_BF_time_out_count = 0; |
| 73 | GEN_BF_time_out_count < GEN_FB_TIME_OUT; |
| 74 | GEN_BF_time_out_count++) { |
| 75 | if ((REG_READ(gen_fifo_stat_reg) & fifo_stat) == fifo_stat) |
| 76 | break; |
| 77 | udelay(100); |
| 78 | } |
| 79 | |
| 80 | if (GEN_BF_time_out_count == GEN_FB_TIME_OUT) |
| 81 | DRM_ERROR("mdfld_dsi_gen_fifo_ready, Timeout. gen_fifo_stat_reg = 0x%x.\n", |
| 82 | gen_fifo_stat_reg); |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Manage the DSI MIPI keyboard and display brightness. |
| 87 | * FIXME: this is exported to OSPM code. should work out an specific |
| 88 | * display interface to OSPM. |
| 89 | */ |
| 90 | |
| 91 | void mdfld_dsi_brightness_init(struct mdfld_dsi_config *dsi_config, int pipe) |
| 92 | { |
| 93 | struct mdfld_dsi_pkg_sender *sender = |
| 94 | mdfld_dsi_get_pkg_sender(dsi_config); |
| 95 | struct drm_device *dev = sender->dev; |
| 96 | struct drm_psb_private *dev_priv = dev->dev_private; |
| 97 | u32 gen_ctrl_val; |
| 98 | |
| 99 | if (!sender) { |
| 100 | DRM_ERROR("No sender found\n"); |
| 101 | return; |
| 102 | } |
| 103 | |
| 104 | /* Set default display backlight value to 85% (0xd8)*/ |
| 105 | mdfld_dsi_send_mcs_short(sender, write_display_brightness, 0xd8, 1, |
| 106 | true); |
| 107 | |
| 108 | /* Set minimum brightness setting of CABC function to 20% (0x33)*/ |
| 109 | mdfld_dsi_send_mcs_short(sender, write_cabc_min_bright, 0x33, 1, true); |
| 110 | |
| 111 | /* Enable backlight or/and LABC */ |
| 112 | gen_ctrl_val = BRIGHT_CNTL_BLOCK_ON | DISPLAY_DIMMING_ON | |
| 113 | BACKLIGHT_ON; |
| 114 | if (LABC_control == 1) |
| 115 | gen_ctrl_val |= DISPLAY_DIMMING_ON | DISPLAY_BRIGHTNESS_AUTO |
| 116 | | GAMMA_AUTO; |
| 117 | |
| 118 | if (LABC_control == 1) |
| 119 | gen_ctrl_val |= AMBIENT_LIGHT_SENSE_ON; |
| 120 | |
| 121 | dev_priv->mipi_ctrl_display = gen_ctrl_val; |
| 122 | |
| 123 | mdfld_dsi_send_mcs_short(sender, write_ctrl_display, (u8)gen_ctrl_val, |
| 124 | 1, true); |
| 125 | |
| 126 | mdfld_dsi_send_mcs_short(sender, write_ctrl_cabc, UI_IMAGE, 1, true); |
| 127 | } |
| 128 | |
| 129 | void mdfld_dsi_brightness_control(struct drm_device *dev, int pipe, int level) |
| 130 | { |
| 131 | struct mdfld_dsi_pkg_sender *sender; |
| 132 | struct drm_psb_private *dev_priv; |
| 133 | struct mdfld_dsi_config *dsi_config; |
| 134 | u32 gen_ctrl_val = 0; |
| 135 | int p_type = TMD_VID; |
| 136 | |
| 137 | if (!dev || (pipe != 0 && pipe != 2)) { |
| 138 | DRM_ERROR("Invalid parameter\n"); |
| 139 | return; |
| 140 | } |
| 141 | |
| 142 | p_type = mdfld_get_panel_type(dev, 0); |
| 143 | |
| 144 | dev_priv = dev->dev_private; |
| 145 | |
| 146 | if (pipe) |
| 147 | dsi_config = dev_priv->dsi_configs[1]; |
| 148 | else |
| 149 | dsi_config = dev_priv->dsi_configs[0]; |
| 150 | |
| 151 | sender = mdfld_dsi_get_pkg_sender(dsi_config); |
| 152 | |
| 153 | if (!sender) { |
| 154 | DRM_ERROR("No sender found\n"); |
| 155 | return; |
| 156 | } |
| 157 | |
| 158 | gen_ctrl_val = (level * 0xff / MDFLD_DSI_BRIGHTNESS_MAX_LEVEL) & 0xff; |
| 159 | |
| 160 | dev_dbg(sender->dev->dev, "pipe = %d, gen_ctrl_val = %d.\n", |
| 161 | pipe, gen_ctrl_val); |
| 162 | |
| 163 | if (p_type == TMD_VID) { |
| 164 | /* Set display backlight value */ |
| 165 | mdfld_dsi_send_mcs_short(sender, tmd_write_display_brightness, |
| 166 | (u8)gen_ctrl_val, 1, true); |
| 167 | } else { |
| 168 | /* Set display backlight value */ |
| 169 | mdfld_dsi_send_mcs_short(sender, write_display_brightness, |
| 170 | (u8)gen_ctrl_val, 1, true); |
| 171 | |
| 172 | /* Enable backlight control */ |
| 173 | if (level == 0) |
| 174 | gen_ctrl_val = 0; |
| 175 | else |
| 176 | gen_ctrl_val = dev_priv->mipi_ctrl_display; |
| 177 | |
| 178 | mdfld_dsi_send_mcs_short(sender, write_ctrl_display, |
| 179 | (u8)gen_ctrl_val, 1, true); |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | static int mdfld_dsi_get_panel_status(struct mdfld_dsi_config *dsi_config, |
| 184 | u8 dcs, u32 *data, bool hs) |
| 185 | { |
| 186 | struct mdfld_dsi_pkg_sender *sender |
| 187 | = mdfld_dsi_get_pkg_sender(dsi_config); |
| 188 | |
| 189 | if (!sender || !data) { |
| 190 | DRM_ERROR("Invalid parameter\n"); |
| 191 | return -EINVAL; |
| 192 | } |
| 193 | |
| 194 | return mdfld_dsi_read_mcs(sender, dcs, data, 1, hs); |
| 195 | } |
| 196 | |
| 197 | int mdfld_dsi_get_power_mode(struct mdfld_dsi_config *dsi_config, u32 *mode, |
| 198 | bool hs) |
| 199 | { |
| 200 | if (!dsi_config || !mode) { |
| 201 | DRM_ERROR("Invalid parameter\n"); |
| 202 | return -EINVAL; |
| 203 | } |
| 204 | |
| 205 | return mdfld_dsi_get_panel_status(dsi_config, 0x0a, mode, hs); |
| 206 | } |
| 207 | |
| 208 | int mdfld_dsi_get_diagnostic_result(struct mdfld_dsi_config *dsi_config, |
| 209 | u32 *result, bool hs) |
| 210 | { |
| 211 | if (!dsi_config || !result) { |
| 212 | DRM_ERROR("Invalid parameter\n"); |
| 213 | return -EINVAL; |
| 214 | } |
| 215 | |
| 216 | return mdfld_dsi_get_panel_status(dsi_config, 0x0f, result, hs); |
| 217 | } |
| 218 | |
| 219 | /* |
| 220 | * NOTE: this function was used by OSPM. |
| 221 | * TODO: will be removed later, should work out display interfaces for OSPM |
| 222 | */ |
| 223 | void mdfld_dsi_controller_init(struct mdfld_dsi_config *dsi_config, int pipe) |
| 224 | { |
| 225 | if (!dsi_config || ((pipe != 0) && (pipe != 2))) { |
| 226 | DRM_ERROR("Invalid parameters\n"); |
| 227 | return; |
| 228 | } |
| 229 | |
| 230 | mdfld_dsi_dpi_controller_init(dsi_config, pipe); |
| 231 | } |
| 232 | |
| 233 | static void mdfld_dsi_connector_save(struct drm_connector *connector) |
| 234 | { |
| 235 | } |
| 236 | |
| 237 | static void mdfld_dsi_connector_restore(struct drm_connector *connector) |
| 238 | { |
| 239 | } |
| 240 | |
| 241 | /* FIXME: start using the force parameter */ |
| 242 | static enum drm_connector_status |
| 243 | mdfld_dsi_connector_detect(struct drm_connector *connector, bool force) |
| 244 | { |
| 245 | struct mdfld_dsi_connector *dsi_connector |
| 246 | = mdfld_dsi_connector(connector); |
| 247 | |
| 248 | dsi_connector->status = connector_status_connected; |
| 249 | |
| 250 | return dsi_connector->status; |
| 251 | } |
| 252 | |
| 253 | static int mdfld_dsi_connector_set_property(struct drm_connector *connector, |
| 254 | struct drm_property *property, |
| 255 | uint64_t value) |
| 256 | { |
| 257 | struct drm_encoder *encoder = connector->encoder; |
| 258 | struct backlight_device *psb_bd; |
| 259 | |
| 260 | if (!strcmp(property->name, "scaling mode") && encoder) { |
| 261 | struct psb_intel_crtc *psb_crtc = |
| 262 | to_psb_intel_crtc(encoder->crtc); |
| 263 | bool centerechange; |
| 264 | uint64_t val; |
| 265 | |
| 266 | if (!psb_crtc) |
| 267 | goto set_prop_error; |
| 268 | |
| 269 | switch (value) { |
| 270 | case DRM_MODE_SCALE_FULLSCREEN: |
| 271 | break; |
| 272 | case DRM_MODE_SCALE_NO_SCALE: |
| 273 | break; |
| 274 | case DRM_MODE_SCALE_ASPECT: |
| 275 | break; |
| 276 | default: |
| 277 | goto set_prop_error; |
| 278 | } |
| 279 | |
| 280 | if (drm_connector_property_get_value(connector, property, &val)) |
| 281 | goto set_prop_error; |
| 282 | |
| 283 | if (val == value) |
| 284 | goto set_prop_done; |
| 285 | |
| 286 | if (drm_connector_property_set_value(connector, |
| 287 | property, value)) |
| 288 | goto set_prop_error; |
| 289 | |
| 290 | centerechange = (val == DRM_MODE_SCALE_NO_SCALE) || |
| 291 | (value == DRM_MODE_SCALE_NO_SCALE); |
| 292 | |
| 293 | if (psb_crtc->saved_mode.hdisplay != 0 && |
| 294 | psb_crtc->saved_mode.vdisplay != 0) { |
| 295 | if (centerechange) { |
| 296 | if (!drm_crtc_helper_set_mode(encoder->crtc, |
| 297 | &psb_crtc->saved_mode, |
| 298 | encoder->crtc->x, |
| 299 | encoder->crtc->y, |
| 300 | encoder->crtc->fb)) |
| 301 | goto set_prop_error; |
| 302 | } else { |
| 303 | struct drm_encoder_helper_funcs *funcs = |
| 304 | encoder->helper_private; |
| 305 | funcs->mode_set(encoder, |
| 306 | &psb_crtc->saved_mode, |
| 307 | &psb_crtc->saved_adjusted_mode); |
| 308 | } |
| 309 | } |
| 310 | } else if (!strcmp(property->name, "backlight") && encoder) { |
| 311 | if (drm_connector_property_set_value(connector, property, |
| 312 | value)) |
| 313 | goto set_prop_error; |
| 314 | else { |
| 315 | psb_bd = mdfld_get_backlight_device(); |
| 316 | if (psb_bd) { |
| 317 | psb_bd->props.brightness = value; |
| 318 | mdfld_set_brightness(psb_bd); |
| 319 | } |
| 320 | } |
| 321 | } |
| 322 | set_prop_done: |
| 323 | return 0; |
| 324 | set_prop_error: |
| 325 | return -1; |
| 326 | } |
| 327 | |
| 328 | static void mdfld_dsi_connector_destroy(struct drm_connector *connector) |
| 329 | { |
| 330 | struct mdfld_dsi_connector *dsi_connector = |
| 331 | mdfld_dsi_connector(connector); |
| 332 | struct mdfld_dsi_pkg_sender *sender; |
| 333 | |
| 334 | if (!dsi_connector) |
| 335 | return; |
| 336 | drm_sysfs_connector_remove(connector); |
| 337 | drm_connector_cleanup(connector); |
| 338 | sender = dsi_connector->pkg_sender; |
| 339 | mdfld_dsi_pkg_sender_destroy(sender); |
| 340 | kfree(dsi_connector); |
| 341 | } |
| 342 | |
| 343 | static int mdfld_dsi_connector_get_modes(struct drm_connector *connector) |
| 344 | { |
| 345 | struct mdfld_dsi_connector *dsi_connector = |
| 346 | mdfld_dsi_connector(connector); |
| 347 | struct mdfld_dsi_config *dsi_config = |
| 348 | mdfld_dsi_get_config(dsi_connector); |
| 349 | struct drm_display_mode *fixed_mode = dsi_config->fixed_mode; |
| 350 | struct drm_display_mode *dup_mode = NULL; |
| 351 | struct drm_device *dev = connector->dev; |
| 352 | |
| 353 | connector->display_info.min_vfreq = 0; |
| 354 | connector->display_info.max_vfreq = 200; |
| 355 | connector->display_info.min_hfreq = 0; |
| 356 | connector->display_info.max_hfreq = 200; |
| 357 | |
| 358 | if (fixed_mode) { |
| 359 | dev_dbg(dev->dev, "fixed_mode %dx%d\n", |
| 360 | fixed_mode->hdisplay, fixed_mode->vdisplay); |
| 361 | dup_mode = drm_mode_duplicate(dev, fixed_mode); |
| 362 | drm_mode_probed_add(connector, dup_mode); |
| 363 | return 1; |
| 364 | } |
| 365 | DRM_ERROR("Didn't get any modes!\n"); |
| 366 | return 0; |
| 367 | } |
| 368 | |
| 369 | static int mdfld_dsi_connector_mode_valid(struct drm_connector *connector, |
| 370 | struct drm_display_mode *mode) |
| 371 | { |
| 372 | struct mdfld_dsi_connector *dsi_connector = |
| 373 | mdfld_dsi_connector(connector); |
| 374 | struct mdfld_dsi_config *dsi_config = |
| 375 | mdfld_dsi_get_config(dsi_connector); |
| 376 | struct drm_display_mode *fixed_mode = dsi_config->fixed_mode; |
| 377 | |
| 378 | if (mode->flags & DRM_MODE_FLAG_DBLSCAN) |
| 379 | return MODE_NO_DBLESCAN; |
| 380 | |
| 381 | if (mode->flags & DRM_MODE_FLAG_INTERLACE) |
| 382 | return MODE_NO_INTERLACE; |
| 383 | |
| 384 | /** |
| 385 | * FIXME: current DC has no fitting unit, reject any mode setting |
| 386 | * request |
| 387 | * Will figure out a way to do up-scaling(pannel fitting) later. |
| 388 | **/ |
| 389 | if (fixed_mode) { |
| 390 | if (mode->hdisplay != fixed_mode->hdisplay) |
| 391 | return MODE_PANEL; |
| 392 | |
| 393 | if (mode->vdisplay != fixed_mode->vdisplay) |
| 394 | return MODE_PANEL; |
| 395 | } |
| 396 | |
| 397 | return MODE_OK; |
| 398 | } |
| 399 | |
| 400 | static void mdfld_dsi_connector_dpms(struct drm_connector *connector, int mode) |
| 401 | { |
| 402 | if (mode == connector->dpms) |
| 403 | return; |
| 404 | |
| 405 | /*first, execute dpms*/ |
| 406 | |
| 407 | drm_helper_connector_dpms(connector, mode); |
| 408 | } |
| 409 | |
| 410 | static struct drm_encoder *mdfld_dsi_connector_best_encoder( |
| 411 | struct drm_connector *connector) |
| 412 | { |
| 413 | struct mdfld_dsi_connector *dsi_connector = |
| 414 | mdfld_dsi_connector(connector); |
| 415 | struct mdfld_dsi_config *dsi_config = |
| 416 | mdfld_dsi_get_config(dsi_connector); |
| 417 | return &dsi_config->encoder->base.base; |
| 418 | } |
| 419 | |
| 420 | /*DSI connector funcs*/ |
| 421 | static const struct drm_connector_funcs mdfld_dsi_connector_funcs = { |
| 422 | .dpms = /*drm_helper_connector_dpms*/mdfld_dsi_connector_dpms, |
| 423 | .save = mdfld_dsi_connector_save, |
| 424 | .restore = mdfld_dsi_connector_restore, |
| 425 | .detect = mdfld_dsi_connector_detect, |
| 426 | .fill_modes = drm_helper_probe_single_connector_modes, |
| 427 | .set_property = mdfld_dsi_connector_set_property, |
| 428 | .destroy = mdfld_dsi_connector_destroy, |
| 429 | }; |
| 430 | |
| 431 | /*DSI connector helper funcs*/ |
| 432 | static const struct drm_connector_helper_funcs |
| 433 | mdfld_dsi_connector_helper_funcs = { |
| 434 | .get_modes = mdfld_dsi_connector_get_modes, |
| 435 | .mode_valid = mdfld_dsi_connector_mode_valid, |
| 436 | .best_encoder = mdfld_dsi_connector_best_encoder, |
| 437 | }; |
| 438 | |
| 439 | static int mdfld_dsi_get_default_config(struct drm_device *dev, |
| 440 | struct mdfld_dsi_config *config, int pipe) |
| 441 | { |
| 442 | if (!dev || !config) { |
| 443 | DRM_ERROR("Invalid parameters"); |
| 444 | return -EINVAL; |
| 445 | } |
| 446 | |
| 447 | config->bpp = 24; |
| 448 | if (mdfld_get_panel_type(dev, pipe) == TC35876X) |
| 449 | config->lane_count = 4; |
| 450 | else |
| 451 | config->lane_count = 2; |
| 452 | config->channel_num = 0; |
| 453 | |
| 454 | if (mdfld_get_panel_type(dev, pipe) == TMD_VID) |
| 455 | config->video_mode = MDFLD_DSI_VIDEO_NON_BURST_MODE_SYNC_PULSE; |
| 456 | else if (mdfld_get_panel_type(dev, pipe) == TC35876X) |
| 457 | config->video_mode = |
| 458 | MDFLD_DSI_VIDEO_NON_BURST_MODE_SYNC_EVENTS; |
| 459 | else |
| 460 | config->video_mode = MDFLD_DSI_VIDEO_BURST_MODE; |
| 461 | |
| 462 | return 0; |
| 463 | } |
| 464 | |
| 465 | int mdfld_dsi_panel_reset(int pipe) |
| 466 | { |
| 467 | unsigned gpio; |
| 468 | int ret = 0; |
| 469 | |
| 470 | switch (pipe) { |
| 471 | case 0: |
| 472 | gpio = 128; |
| 473 | break; |
| 474 | case 2: |
| 475 | gpio = 34; |
| 476 | break; |
| 477 | default: |
| 478 | DRM_ERROR("Invalid output\n"); |
| 479 | return -EINVAL; |
| 480 | } |
| 481 | |
| 482 | ret = gpio_request(gpio, "gfx"); |
| 483 | if (ret) { |
| 484 | DRM_ERROR("gpio_rqueset failed\n"); |
| 485 | return ret; |
| 486 | } |
| 487 | |
| 488 | ret = gpio_direction_output(gpio, 1); |
| 489 | if (ret) { |
| 490 | DRM_ERROR("gpio_direction_output failed\n"); |
| 491 | goto gpio_error; |
| 492 | } |
| 493 | |
| 494 | gpio_get_value(128); |
| 495 | |
| 496 | gpio_error: |
| 497 | if (gpio_is_valid(gpio)) |
| 498 | gpio_free(gpio); |
| 499 | |
| 500 | return ret; |
| 501 | } |
| 502 | |
| 503 | /* |
| 504 | * MIPI output init |
| 505 | * @dev drm device |
| 506 | * @pipe pipe number. 0 or 2 |
| 507 | * @config |
| 508 | * |
| 509 | * Do the initialization of a MIPI output, including create DRM mode objects |
| 510 | * initialization of DSI output on @pipe |
| 511 | */ |
| 512 | void mdfld_dsi_output_init(struct drm_device *dev, |
| 513 | int pipe, |
| 514 | struct mdfld_dsi_config *config, |
| 515 | const struct panel_funcs *p_vid_funcs) |
| 516 | { |
| 517 | struct mdfld_dsi_config *dsi_config; |
| 518 | struct mdfld_dsi_connector *dsi_connector; |
| 519 | struct drm_connector *connector; |
| 520 | struct mdfld_dsi_encoder *encoder; |
| 521 | struct drm_psb_private *dev_priv = dev->dev_private; |
| 522 | struct panel_info dsi_panel_info; |
| 523 | u32 width_mm, height_mm; |
| 524 | |
| 525 | dev_dbg(dev->dev, "init DSI output on pipe %d\n", pipe); |
| 526 | |
| 527 | if (!dev || ((pipe != 0) && (pipe != 2))) { |
| 528 | DRM_ERROR("Invalid parameter\n"); |
| 529 | return; |
| 530 | } |
| 531 | |
| 532 | /*create a new connetor*/ |
| 533 | dsi_connector = kzalloc(sizeof(struct mdfld_dsi_connector), GFP_KERNEL); |
| 534 | if (!dsi_connector) { |
| 535 | DRM_ERROR("No memory"); |
| 536 | return; |
| 537 | } |
| 538 | |
| 539 | dsi_connector->pipe = pipe; |
| 540 | |
| 541 | /*set DSI config*/ |
| 542 | if (config) |
| 543 | dsi_config = config; |
| 544 | else { |
| 545 | dsi_config = kzalloc(sizeof(struct mdfld_dsi_config), |
| 546 | GFP_KERNEL); |
| 547 | if (!dsi_config) { |
| 548 | DRM_ERROR("cannot allocate memory for DSI config\n"); |
| 549 | goto dsi_init_err0; |
| 550 | } |
| 551 | mdfld_dsi_get_default_config(dev, dsi_config, pipe); |
| 552 | } |
| 553 | |
| 554 | dsi_connector->private = dsi_config; |
| 555 | |
| 556 | dsi_config->changed = 1; |
| 557 | dsi_config->dev = dev; |
| 558 | |
| 559 | dsi_config->fixed_mode = p_vid_funcs->get_config_mode(dev); |
| 560 | if (p_vid_funcs->get_panel_info(dev, pipe, &dsi_panel_info)) |
| 561 | goto dsi_init_err0; |
| 562 | |
| 563 | width_mm = dsi_panel_info.width_mm; |
| 564 | height_mm = dsi_panel_info.height_mm; |
| 565 | |
| 566 | dsi_config->mode = dsi_config->fixed_mode; |
| 567 | dsi_config->connector = dsi_connector; |
| 568 | |
| 569 | if (!dsi_config->fixed_mode) { |
| 570 | DRM_ERROR("No pannel fixed mode was found\n"); |
| 571 | goto dsi_init_err0; |
| 572 | } |
| 573 | |
| 574 | if (pipe && dev_priv->dsi_configs[0]) { |
| 575 | dsi_config->dvr_ic_inited = 0; |
| 576 | dev_priv->dsi_configs[1] = dsi_config; |
| 577 | } else if (pipe == 0) { |
| 578 | dsi_config->dvr_ic_inited = 1; |
| 579 | dev_priv->dsi_configs[0] = dsi_config; |
| 580 | } else { |
| 581 | DRM_ERROR("Trying to init MIPI1 before MIPI0\n"); |
| 582 | goto dsi_init_err0; |
| 583 | } |
| 584 | |
| 585 | |
| 586 | connector = &dsi_connector->base.base; |
| 587 | drm_connector_init(dev, connector, &mdfld_dsi_connector_funcs, |
| 588 | DRM_MODE_CONNECTOR_LVDS); |
| 589 | drm_connector_helper_add(connector, &mdfld_dsi_connector_helper_funcs); |
| 590 | |
| 591 | connector->display_info.subpixel_order = SubPixelHorizontalRGB; |
| 592 | connector->display_info.width_mm = width_mm; |
| 593 | connector->display_info.height_mm = height_mm; |
| 594 | connector->interlace_allowed = false; |
| 595 | connector->doublescan_allowed = false; |
| 596 | |
| 597 | /*attach properties*/ |
| 598 | drm_connector_attach_property(connector, |
| 599 | dev->mode_config.scaling_mode_property, |
| 600 | DRM_MODE_SCALE_FULLSCREEN); |
| 601 | drm_connector_attach_property(connector, |
| 602 | dev_priv->backlight_property, |
| 603 | MDFLD_DSI_BRIGHTNESS_MAX_LEVEL); |
| 604 | |
| 605 | /*init DSI package sender on this output*/ |
| 606 | if (mdfld_dsi_pkg_sender_init(dsi_connector, pipe)) { |
| 607 | DRM_ERROR("Package Sender initialization failed on pipe %d\n", |
| 608 | pipe); |
| 609 | goto dsi_init_err0; |
| 610 | } |
| 611 | |
| 612 | encoder = mdfld_dsi_dpi_init(dev, dsi_connector, p_vid_funcs); |
| 613 | if (!encoder) { |
| 614 | DRM_ERROR("Create DPI encoder failed\n"); |
| 615 | goto dsi_init_err1; |
| 616 | } |
| 617 | encoder->private = dsi_config; |
| 618 | dsi_config->encoder = encoder; |
| 619 | encoder->base.type = (pipe == 0) ? INTEL_OUTPUT_MIPI : |
| 620 | INTEL_OUTPUT_MIPI2; |
| 621 | drm_sysfs_connector_add(connector); |
| 622 | return; |
| 623 | |
| 624 | /*TODO: add code to destroy outputs on error*/ |
| 625 | dsi_init_err1: |
| 626 | /*destroy sender*/ |
| 627 | mdfld_dsi_pkg_sender_destroy(dsi_connector->pkg_sender); |
| 628 | |
| 629 | drm_connector_cleanup(connector); |
| 630 | |
| 631 | kfree(dsi_config->fixed_mode); |
| 632 | kfree(dsi_config); |
| 633 | dsi_init_err0: |
| 634 | kfree(dsi_connector); |
| 635 | } |