| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * DesignWare High-Definition Multimedia Interface (HDMI) driver |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright (C) 2013-2015 Mentor Graphics Inc. |
|---|
| 5 | 6 | * Copyright (C) 2011-2013 Freescale Semiconductor, Inc. |
|---|
| 6 | 7 | * Copyright (C) 2010, Guennadi Liakhovetski <g.liakhovetski@gmx.de> |
|---|
| 7 | | - * |
|---|
| 8 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 9 | | - * it under the terms of the GNU General Public License as published by |
|---|
| 10 | | - * the Free Software Foundation; either version 2 of the License, or |
|---|
| 11 | | - * (at your option) any later version. |
|---|
| 12 | | - * |
|---|
| 13 | 8 | */ |
|---|
| 14 | | -#include <linux/module.h> |
|---|
| 15 | | -#include <linux/irq.h> |
|---|
| 9 | +#include <linux/clk.h> |
|---|
| 16 | 10 | #include <linux/delay.h> |
|---|
| 17 | 11 | #include <linux/err.h> |
|---|
| 18 | 12 | #include <linux/extcon.h> |
|---|
| 19 | 13 | #include <linux/extcon-provider.h> |
|---|
| 20 | | -#include <linux/clk.h> |
|---|
| 21 | 14 | #include <linux/hdmi.h> |
|---|
| 15 | +#include <linux/irq.h> |
|---|
| 16 | +#include <linux/module.h> |
|---|
| 22 | 17 | #include <linux/mutex.h> |
|---|
| 23 | 18 | #include <linux/of_device.h> |
|---|
| 19 | +#include <linux/pinctrl/consumer.h> |
|---|
| 24 | 20 | #include <linux/regmap.h> |
|---|
| 21 | +#include <linux/dma-mapping.h> |
|---|
| 25 | 22 | #include <linux/spinlock.h> |
|---|
| 26 | 23 | #include <linux/pinctrl/consumer.h> |
|---|
| 27 | 24 | |
|---|
| 28 | | -#include <drm/drm_of.h> |
|---|
| 29 | | -#include <drm/drmP.h> |
|---|
| 30 | | -#include <drm/drm_atomic.h> |
|---|
| 31 | | -#include <drm/drm_atomic_helper.h> |
|---|
| 32 | | -#include <drm/drm_crtc_helper.h> |
|---|
| 33 | | -#include <drm/drm_edid.h> |
|---|
| 34 | | -#include <drm/drm_encoder_slave.h> |
|---|
| 35 | | -#include <drm/drm_scdc_helper.h> |
|---|
| 36 | | -#include <drm/bridge/dw_hdmi.h> |
|---|
| 25 | +#include <media/cec-notifier.h> |
|---|
| 37 | 26 | |
|---|
| 38 | 27 | #include <uapi/linux/media-bus-format.h> |
|---|
| 39 | 28 | #include <uapi/linux/videodev2.h> |
|---|
| 40 | 29 | |
|---|
| 41 | | -#include "dw-hdmi.h" |
|---|
| 30 | +#include <drm/bridge/dw_hdmi.h> |
|---|
| 31 | +#include <drm/drm_atomic.h> |
|---|
| 32 | +#include <drm/drm_atomic_helper.h> |
|---|
| 33 | +#include <drm/drm_bridge.h> |
|---|
| 34 | +#include <drm/drm_edid.h> |
|---|
| 35 | +#include <drm/drm_of.h> |
|---|
| 36 | +#include <drm/drm_print.h> |
|---|
| 37 | +#include <drm/drm_probe_helper.h> |
|---|
| 38 | +#include <drm/drm_scdc_helper.h> |
|---|
| 39 | + |
|---|
| 42 | 40 | #include "dw-hdmi-audio.h" |
|---|
| 43 | 41 | #include "dw-hdmi-cec.h" |
|---|
| 44 | 42 | #include "dw-hdmi-hdcp.h" |
|---|
| 45 | | - |
|---|
| 46 | | -#include <media/cec-notifier.h> |
|---|
| 43 | +#include "dw-hdmi.h" |
|---|
| 47 | 44 | |
|---|
| 48 | 45 | #define DDC_CI_ADDR 0x37 |
|---|
| 49 | 46 | #define DDC_SEGMENT_ADDR 0x30 |
|---|
| 50 | 47 | |
|---|
| 51 | 48 | #define HDMI_EDID_LEN 512 |
|---|
| 49 | +#define HDMI_EDID_BLOCK_LEN 128 |
|---|
| 52 | 50 | |
|---|
| 53 | 51 | /* DW-HDMI Controller >= 0x200a are at least compliant with SCDC version 1 */ |
|---|
| 54 | 52 | #define SCDC_MIN_SOURCE_VERSION 0x1 |
|---|
| .. | .. |
|---|
| 149 | 147 | |
|---|
| 150 | 148 | static const u16 csc_coeff_rgb_in_eitu601[3][4] = { |
|---|
| 151 | 149 | { 0x2591, 0x1322, 0x074b, 0x0000 }, |
|---|
| 152 | | - { 0xe535, 0x2000, 0xfacc, 0x0200 }, |
|---|
| 153 | | - { 0xeacd, 0xf534, 0x2000, 0x0200 } |
|---|
| 154 | | -}; |
|---|
| 155 | | - |
|---|
| 156 | | -static const u16 csc_coeff_rgb_in_eitu601_10bit[3][4] = { |
|---|
| 157 | | - { 0x2591, 0x1322, 0x074b, 0x0000 }, |
|---|
| 158 | | - { 0xe535, 0x2000, 0xfacc, 0x0800 }, |
|---|
| 159 | | - { 0xeacd, 0xf534, 0x2000, 0x0800 } |
|---|
| 160 | | -}; |
|---|
| 161 | | - |
|---|
| 162 | | -static const u16 csc_coeff_rgb_in_eitu601_limited[3][4] = { |
|---|
| 163 | | - { 0x2044, 0x106f, 0x0644, 0x0040 }, |
|---|
| 164 | | - { 0xe677, 0x1c1c, 0xfd46, 0x0200 }, |
|---|
| 165 | | - { 0xed60, 0xf685, 0x1c1c, 0x0200 } |
|---|
| 166 | | -}; |
|---|
| 167 | | - |
|---|
| 168 | | -static const u16 csc_coeff_rgb_in_eitu601_10bit_limited[3][4] = { |
|---|
| 169 | | - { 0x2044, 0x106f, 0x0644, 0x0100 }, |
|---|
| 170 | | - { 0xe677, 0x1c1c, 0xfd46, 0x0800 }, |
|---|
| 171 | | - { 0xed60, 0xf685, 0x1c1c, 0x0800 } |
|---|
| 150 | + { 0x6535, 0x2000, 0x7acc, 0x0200 }, |
|---|
| 151 | + { 0x6acd, 0x7534, 0x2000, 0x0200 } |
|---|
| 172 | 152 | }; |
|---|
| 173 | 153 | |
|---|
| 174 | 154 | static const u16 csc_coeff_rgb_in_eitu709[3][4] = { |
|---|
| 175 | 155 | { 0x2dc5, 0x0d9b, 0x049e, 0x0000 }, |
|---|
| 176 | | - { 0xe2f0, 0x2000, 0xfd11, 0x0200 }, |
|---|
| 177 | | - { 0xe756, 0xf8ab, 0x2000, 0x0200 } |
|---|
| 156 | + { 0x62f0, 0x2000, 0x7d11, 0x0200 }, |
|---|
| 157 | + { 0x6756, 0x78ab, 0x2000, 0x0200 } |
|---|
| 178 | 158 | }; |
|---|
| 179 | 159 | |
|---|
| 180 | | -static const u16 csc_coeff_rgb_in_eitu709_10bit[3][4] = { |
|---|
| 181 | | - { 0x2dc5, 0x0d9b, 0x049e, 0x0000 }, |
|---|
| 182 | | - { 0xe2f0, 0x2000, 0xfd11, 0x0800 }, |
|---|
| 183 | | - { 0xe756, 0xf8ab, 0x2000, 0x0800 } |
|---|
| 184 | | -}; |
|---|
| 185 | | - |
|---|
| 186 | | -static const u16 csc_coeff_rgb_in_eitu709_limited[3][4] = { |
|---|
| 187 | | - { 0x2750, 0x0baf, 0x03f8, 0x0040 }, |
|---|
| 188 | | - { 0xe677, 0x1c1c, 0xfd6d, 0x0200 }, |
|---|
| 189 | | - { 0xea55, 0xf98f, 0x1c1c, 0x0200 } |
|---|
| 190 | | -}; |
|---|
| 191 | | - |
|---|
| 192 | | -static const u16 csc_coeff_rgb_in_eitu709_10bit_limited[3][4] = { |
|---|
| 193 | | - { 0x2750, 0x0baf, 0x03f8, 0x0100 }, |
|---|
| 194 | | - { 0xe677, 0x1c1c, 0xfd6d, 0x0800 }, |
|---|
| 195 | | - { 0xea55, 0xf98f, 0x1c1c, 0x0800 } |
|---|
| 196 | | -}; |
|---|
| 197 | | - |
|---|
| 198 | | -static const u16 csc_coeff_full_to_limited[3][4] = { |
|---|
| 199 | | - { 0x36f7, 0x0000, 0x0000, 0x0040 }, |
|---|
| 200 | | - { 0x0000, 0x36f7, 0x0000, 0x0040 }, |
|---|
| 201 | | - { 0x0000, 0x0000, 0x36f7, 0x0040 } |
|---|
| 160 | +static const u16 csc_coeff_rgb_full_to_rgb_limited[3][4] = { |
|---|
| 161 | + { 0x1b7c, 0x0000, 0x0000, 0x0020 }, |
|---|
| 162 | + { 0x0000, 0x1b7c, 0x0000, 0x0020 }, |
|---|
| 163 | + { 0x0000, 0x0000, 0x1b7c, 0x0020 } |
|---|
| 202 | 164 | }; |
|---|
| 203 | 165 | |
|---|
| 204 | 166 | static const struct drm_display_mode dw_hdmi_default_modes[] = { |
|---|
| .. | .. |
|---|
| 206 | 168 | { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1390, |
|---|
| 207 | 169 | 1430, 1650, 0, 720, 725, 730, 750, 0, |
|---|
| 208 | 170 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC), |
|---|
| 209 | | - .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, }, |
|---|
| 171 | + .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, }, |
|---|
| 210 | 172 | /* 16 - 1920x1080@60Hz 16:9 */ |
|---|
| 211 | 173 | { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2008, |
|---|
| 212 | 174 | 2052, 2200, 0, 1080, 1084, 1089, 1125, 0, |
|---|
| 213 | 175 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC), |
|---|
| 214 | | - .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, }, |
|---|
| 176 | + .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, }, |
|---|
| 215 | 177 | /* 31 - 1920x1080@50Hz 16:9 */ |
|---|
| 216 | 178 | { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2448, |
|---|
| 217 | 179 | 2492, 2640, 0, 1080, 1084, 1089, 1125, 0, |
|---|
| 218 | 180 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC), |
|---|
| 219 | | - .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, }, |
|---|
| 181 | + .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, }, |
|---|
| 220 | 182 | /* 19 - 1280x720@50Hz 16:9 */ |
|---|
| 221 | 183 | { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1720, |
|---|
| 222 | 184 | 1760, 1980, 0, 720, 725, 730, 750, 0, |
|---|
| 223 | 185 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC), |
|---|
| 224 | | - .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, }, |
|---|
| 225 | | - /* 0x10 - 1024x768@60Hz */ |
|---|
| 226 | | - { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 65000, 1024, 1048, |
|---|
| 227 | | - 1184, 1344, 0, 768, 771, 777, 806, 0, |
|---|
| 228 | | - DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, |
|---|
| 186 | + .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, }, |
|---|
| 229 | 187 | /* 17 - 720x576@50Hz 4:3 */ |
|---|
| 230 | 188 | { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 27000, 720, 732, |
|---|
| 231 | 189 | 796, 864, 0, 576, 581, 586, 625, 0, |
|---|
| 232 | 190 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), |
|---|
| 233 | | - .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, }, |
|---|
| 191 | + .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, }, |
|---|
| 234 | 192 | /* 2 - 720x480@60Hz 4:3 */ |
|---|
| 235 | 193 | { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 27000, 720, 736, |
|---|
| 236 | 194 | 798, 858, 0, 480, 489, 495, 525, 0, |
|---|
| 237 | 195 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), |
|---|
| 238 | | - .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, }, |
|---|
| 196 | + .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, }, |
|---|
| 239 | 197 | }; |
|---|
| 240 | 198 | |
|---|
| 241 | 199 | struct hdmi_vmode { |
|---|
| .. | .. |
|---|
| 257 | 215 | unsigned int quant_range; |
|---|
| 258 | 216 | unsigned int pix_repet_factor; |
|---|
| 259 | 217 | struct hdmi_vmode video_mode; |
|---|
| 260 | | - bool update; |
|---|
| 218 | + bool rgb_limited_range; |
|---|
| 261 | 219 | }; |
|---|
| 262 | 220 | |
|---|
| 263 | 221 | struct dw_hdmi_i2c { |
|---|
| .. | .. |
|---|
| 303 | 261 | |
|---|
| 304 | 262 | struct hdmi_data_info hdmi_data; |
|---|
| 305 | 263 | const struct dw_hdmi_plat_data *plat_data; |
|---|
| 264 | + const struct dw_hdmi_cec_wake_ops *cec_ops; |
|---|
| 306 | 265 | struct dw_hdcp *hdcp; |
|---|
| 307 | 266 | |
|---|
| 308 | 267 | int vic; |
|---|
| .. | .. |
|---|
| 331 | 290 | struct delayed_work work; |
|---|
| 332 | 291 | struct workqueue_struct *workqueue; |
|---|
| 333 | 292 | |
|---|
| 293 | + struct pinctrl *pinctrl; |
|---|
| 294 | + struct pinctrl_state *default_state; |
|---|
| 295 | + struct pinctrl_state *unwedge_state; |
|---|
| 296 | + |
|---|
| 334 | 297 | struct mutex mutex; /* for state below and previous_mode */ |
|---|
| 335 | 298 | enum drm_connector_force force; /* mutex-protected force state */ |
|---|
| 299 | + struct drm_connector *curr_conn;/* current connector (only valid when !disabled) */ |
|---|
| 336 | 300 | bool disabled; /* DRM has disabled our bridge */ |
|---|
| 337 | 301 | bool bridge_is_on; /* indicates the bridge is on */ |
|---|
| 338 | 302 | bool rxsense; /* rxsense state */ |
|---|
| .. | .. |
|---|
| 355 | 319 | void (*enable_audio)(struct dw_hdmi *hdmi); |
|---|
| 356 | 320 | void (*disable_audio)(struct dw_hdmi *hdmi); |
|---|
| 357 | 321 | |
|---|
| 322 | + struct mutex cec_notifier_mutex; |
|---|
| 358 | 323 | struct cec_notifier *cec_notifier; |
|---|
| 324 | + struct cec_adapter *cec_adap; |
|---|
| 359 | 325 | |
|---|
| 360 | | - bool initialized; /* hdmi is enabled before bind */ |
|---|
| 361 | 326 | hdmi_codec_plugged_cb plugged_cb; |
|---|
| 362 | 327 | struct device *codec_dev; |
|---|
| 363 | 328 | enum drm_connector_status last_connector_result; |
|---|
| 364 | | - bool rgb_quant_range_selectable; |
|---|
| 329 | + bool initialized; /* hdmi is enabled before bind */ |
|---|
| 330 | + bool logo_plug_out; /* hdmi is plug out when kernel logo */ |
|---|
| 331 | + bool update; |
|---|
| 332 | + bool hdr2sdr; /* from hdr to sdr */ |
|---|
| 365 | 333 | }; |
|---|
| 366 | 334 | |
|---|
| 367 | 335 | #define HDMI_IH_PHY_STAT0_RX_SENSE \ |
|---|
| .. | .. |
|---|
| 441 | 409 | static void repo_hpd_event(struct work_struct *p_work) |
|---|
| 442 | 410 | { |
|---|
| 443 | 411 | struct dw_hdmi *hdmi = container_of(p_work, struct dw_hdmi, work.work); |
|---|
| 412 | + enum drm_connector_status status = hdmi->hpd_state ? |
|---|
| 413 | + connector_status_connected : connector_status_disconnected; |
|---|
| 444 | 414 | u8 phy_stat = hdmi_readb(hdmi, HDMI_PHY_STAT0); |
|---|
| 445 | 415 | |
|---|
| 446 | 416 | mutex_lock(&hdmi->mutex); |
|---|
| .. | .. |
|---|
| 452 | 422 | |
|---|
| 453 | 423 | if (hdmi->bridge.dev) { |
|---|
| 454 | 424 | bool change; |
|---|
| 425 | + void *data = hdmi->plat_data->phy_data; |
|---|
| 455 | 426 | |
|---|
| 456 | 427 | change = drm_helper_hpd_irq_event(hdmi->bridge.dev); |
|---|
| 457 | 428 | |
|---|
| 458 | | -#ifdef CONFIG_CEC_NOTIFIER |
|---|
| 459 | | - if (change) |
|---|
| 460 | | - cec_notifier_repo_cec_hpd(hdmi->cec_notifier, |
|---|
| 461 | | - hdmi->hpd_state, |
|---|
| 462 | | - ktime_get()); |
|---|
| 463 | | -#endif |
|---|
| 429 | + if (change) { |
|---|
| 430 | + if (hdmi->plat_data->set_ddc_io) |
|---|
| 431 | + hdmi->plat_data->set_ddc_io(data, hdmi->hpd_state); |
|---|
| 432 | + if (hdmi->cec_adap->devnode.registered) |
|---|
| 433 | + cec_queue_pin_hpd_event(hdmi->cec_adap, |
|---|
| 434 | + hdmi->hpd_state, |
|---|
| 435 | + ktime_get()); |
|---|
| 436 | + } |
|---|
| 437 | + drm_bridge_hpd_notify(&hdmi->bridge, status); |
|---|
| 464 | 438 | } |
|---|
| 465 | 439 | } |
|---|
| 466 | 440 | |
|---|
| .. | .. |
|---|
| 538 | 512 | |
|---|
| 539 | 513 | static void dw_hdmi_i2c_init(struct dw_hdmi *hdmi) |
|---|
| 540 | 514 | { |
|---|
| 515 | + hdmi_writeb(hdmi, HDMI_PHY_I2CM_INT_ADDR_DONE_POL, |
|---|
| 516 | + HDMI_PHY_I2CM_INT_ADDR); |
|---|
| 517 | + |
|---|
| 518 | + hdmi_writeb(hdmi, HDMI_PHY_I2CM_CTLINT_ADDR_NAC_POL | |
|---|
| 519 | + HDMI_PHY_I2CM_CTLINT_ADDR_ARBITRATION_POL, |
|---|
| 520 | + HDMI_PHY_I2CM_CTLINT_ADDR); |
|---|
| 521 | + |
|---|
| 541 | 522 | /* Software reset */ |
|---|
| 542 | 523 | hdmi_writeb(hdmi, 0x00, HDMI_I2CM_SOFTRSTZ); |
|---|
| 543 | 524 | |
|---|
| .. | .. |
|---|
| 558 | 539 | hdmi_writeb(hdmi, HDMI_IH_I2CM_STAT0_ERROR | HDMI_IH_I2CM_STAT0_DONE, |
|---|
| 559 | 540 | HDMI_IH_MUTE_I2CM_STAT0); |
|---|
| 560 | 541 | |
|---|
| 561 | | - /* set SDA high level holding time */ |
|---|
| 562 | | - hdmi_writeb(hdmi, 0x48, HDMI_I2CM_SDA_HOLD); |
|---|
| 542 | + /* Only configure when we use the internal I2C controller */ |
|---|
| 543 | + if (hdmi->i2c) { |
|---|
| 544 | + /* set SDA high level holding time */ |
|---|
| 545 | + hdmi_writeb(hdmi, 0x48, HDMI_I2CM_SDA_HOLD); |
|---|
| 546 | + dw_hdmi_i2c_set_divs(hdmi); |
|---|
| 547 | + } |
|---|
| 548 | +} |
|---|
| 563 | 549 | |
|---|
| 564 | | - dw_hdmi_i2c_set_divs(hdmi); |
|---|
| 550 | +static bool dw_hdmi_i2c_unwedge(struct dw_hdmi *hdmi) |
|---|
| 551 | +{ |
|---|
| 552 | + /* If no unwedge state then give up */ |
|---|
| 553 | + if (!hdmi->unwedge_state) |
|---|
| 554 | + return false; |
|---|
| 555 | + |
|---|
| 556 | + dev_info(hdmi->dev, "Attempting to unwedge stuck i2c bus\n"); |
|---|
| 557 | + |
|---|
| 558 | + /* |
|---|
| 559 | + * This is a huge hack to workaround a problem where the dw_hdmi i2c |
|---|
| 560 | + * bus could sometimes get wedged. Once wedged there doesn't appear |
|---|
| 561 | + * to be any way to unwedge it (including the HDMI_I2CM_SOFTRSTZ) |
|---|
| 562 | + * other than pulsing the SDA line. |
|---|
| 563 | + * |
|---|
| 564 | + * We appear to be able to pulse the SDA line (in the eyes of dw_hdmi) |
|---|
| 565 | + * by: |
|---|
| 566 | + * 1. Remux the pin as a GPIO output, driven low. |
|---|
| 567 | + * 2. Wait a little while. 1 ms seems to work, but we'll do 10. |
|---|
| 568 | + * 3. Immediately jump to remux the pin as dw_hdmi i2c again. |
|---|
| 569 | + * |
|---|
| 570 | + * At the moment of remuxing, the line will still be low due to its |
|---|
| 571 | + * recent stint as an output, but then it will be pulled high by the |
|---|
| 572 | + * (presumed) external pullup. dw_hdmi seems to see this as a rising |
|---|
| 573 | + * edge and that seems to get it out of its jam. |
|---|
| 574 | + * |
|---|
| 575 | + * This wedging was only ever seen on one TV, and only on one of |
|---|
| 576 | + * its HDMI ports. It happened when the TV was powered on while the |
|---|
| 577 | + * device was plugged in. A scope trace shows the TV bringing both SDA |
|---|
| 578 | + * and SCL low, then bringing them both back up at roughly the same |
|---|
| 579 | + * time. Presumably this confuses dw_hdmi because it saw activity but |
|---|
| 580 | + * no real STOP (maybe it thinks there's another master on the bus?). |
|---|
| 581 | + * Giving it a clean rising edge of SDA while SCL is already high |
|---|
| 582 | + * presumably makes dw_hdmi see a STOP which seems to bring dw_hdmi out |
|---|
| 583 | + * of its stupor. |
|---|
| 584 | + * |
|---|
| 585 | + * Note that after coming back alive, transfers seem to immediately |
|---|
| 586 | + * resume, so if we unwedge due to a timeout we should wait a little |
|---|
| 587 | + * longer for our transfer to finish, since it might have just started |
|---|
| 588 | + * now. |
|---|
| 589 | + */ |
|---|
| 590 | + pinctrl_select_state(hdmi->pinctrl, hdmi->unwedge_state); |
|---|
| 591 | + msleep(10); |
|---|
| 592 | + pinctrl_select_state(hdmi->pinctrl, hdmi->default_state); |
|---|
| 593 | + |
|---|
| 594 | + return true; |
|---|
| 595 | +} |
|---|
| 596 | + |
|---|
| 597 | +static int dw_hdmi_i2c_wait(struct dw_hdmi *hdmi) |
|---|
| 598 | +{ |
|---|
| 599 | + struct dw_hdmi_i2c *i2c = hdmi->i2c; |
|---|
| 600 | + int stat; |
|---|
| 601 | + |
|---|
| 602 | + stat = wait_for_completion_timeout(&i2c->cmp, HZ / 10); |
|---|
| 603 | + if (!stat) { |
|---|
| 604 | + /* If we can't unwedge, return timeout */ |
|---|
| 605 | + if (!dw_hdmi_i2c_unwedge(hdmi)) |
|---|
| 606 | + return -EAGAIN; |
|---|
| 607 | + |
|---|
| 608 | + /* We tried to unwedge; give it another chance */ |
|---|
| 609 | + stat = wait_for_completion_timeout(&i2c->cmp, HZ / 10); |
|---|
| 610 | + if (!stat) |
|---|
| 611 | + return -EAGAIN; |
|---|
| 612 | + } |
|---|
| 613 | + |
|---|
| 614 | + /* Check for error condition on the bus */ |
|---|
| 615 | + if (i2c->stat & HDMI_IH_I2CM_STAT0_ERROR) |
|---|
| 616 | + return -EIO; |
|---|
| 617 | + |
|---|
| 618 | + return 0; |
|---|
| 565 | 619 | } |
|---|
| 566 | 620 | |
|---|
| 567 | 621 | static int dw_hdmi_i2c_read(struct dw_hdmi *hdmi, |
|---|
| 568 | 622 | unsigned char *buf, unsigned int length) |
|---|
| 569 | 623 | { |
|---|
| 570 | 624 | struct dw_hdmi_i2c *i2c = hdmi->i2c; |
|---|
| 571 | | - int stat; |
|---|
| 625 | + int ret, retry, i; |
|---|
| 626 | + bool read_edid = false; |
|---|
| 572 | 627 | |
|---|
| 573 | 628 | if (!i2c->is_regaddr) { |
|---|
| 574 | 629 | dev_dbg(hdmi->dev, "set read register address to 0\n"); |
|---|
| .. | .. |
|---|
| 576 | 631 | i2c->is_regaddr = true; |
|---|
| 577 | 632 | } |
|---|
| 578 | 633 | |
|---|
| 579 | | - while (length--) { |
|---|
| 580 | | - reinit_completion(&i2c->cmp); |
|---|
| 634 | + /* edid reads are in 128 bytes. scdc reads are in 1 byte */ |
|---|
| 635 | + if (length == HDMI_EDID_BLOCK_LEN) |
|---|
| 636 | + read_edid = true; |
|---|
| 581 | 637 | |
|---|
| 582 | | - hdmi_writeb(hdmi, i2c->slave_reg++, HDMI_I2CM_ADDRESS); |
|---|
| 583 | | - if (i2c->is_segment) |
|---|
| 584 | | - hdmi_writeb(hdmi, HDMI_I2CM_OPERATION_READ_EXT, |
|---|
| 585 | | - HDMI_I2CM_OPERATION); |
|---|
| 586 | | - else |
|---|
| 587 | | - hdmi_writeb(hdmi, HDMI_I2CM_OPERATION_READ, |
|---|
| 588 | | - HDMI_I2CM_OPERATION); |
|---|
| 638 | + while (length > 0) { |
|---|
| 639 | + retry = 100; |
|---|
| 640 | + hdmi_writeb(hdmi, i2c->slave_reg, HDMI_I2CM_ADDRESS); |
|---|
| 589 | 641 | |
|---|
| 590 | | - stat = wait_for_completion_timeout(&i2c->cmp, HZ / 10); |
|---|
| 591 | | - if (!stat) |
|---|
| 592 | | - return -EAGAIN; |
|---|
| 642 | + if (read_edid) { |
|---|
| 643 | + i2c->slave_reg += 8; |
|---|
| 644 | + length -= 8; |
|---|
| 645 | + } else { |
|---|
| 646 | + i2c->slave_reg++; |
|---|
| 647 | + length--; |
|---|
| 648 | + } |
|---|
| 593 | 649 | |
|---|
| 594 | | - /* Check for error condition on the bus */ |
|---|
| 595 | | - if (i2c->stat & HDMI_IH_I2CM_STAT0_ERROR) |
|---|
| 650 | + while (retry > 0) { |
|---|
| 651 | + if (!(hdmi_readb(hdmi, HDMI_PHY_STAT0) & HDMI_PHY_HPD)) { |
|---|
| 652 | + dev_dbg(hdmi->dev, "hdmi disconnect, stop ddc read\n"); |
|---|
| 653 | + return -EPERM; |
|---|
| 654 | + } |
|---|
| 655 | + |
|---|
| 656 | + if (i2c->is_segment) { |
|---|
| 657 | + if (read_edid) |
|---|
| 658 | + hdmi_writeb(hdmi, HDMI_I2CM_OPERATION_READ8_EXT, |
|---|
| 659 | + HDMI_I2CM_OPERATION); |
|---|
| 660 | + else |
|---|
| 661 | + hdmi_writeb(hdmi, HDMI_I2CM_OPERATION_READ_EXT, |
|---|
| 662 | + HDMI_I2CM_OPERATION); |
|---|
| 663 | + } else { |
|---|
| 664 | + if (read_edid) |
|---|
| 665 | + hdmi_writeb(hdmi, HDMI_I2CM_OPERATION_READ8, |
|---|
| 666 | + HDMI_I2CM_OPERATION); |
|---|
| 667 | + else |
|---|
| 668 | + hdmi_writeb(hdmi, HDMI_I2CM_OPERATION_READ, |
|---|
| 669 | + HDMI_I2CM_OPERATION); |
|---|
| 670 | + } |
|---|
| 671 | + |
|---|
| 672 | + ret = dw_hdmi_i2c_wait(hdmi); |
|---|
| 673 | + if (ret == -EAGAIN) { |
|---|
| 674 | + dev_dbg(hdmi->dev, "ddc read time out\n"); |
|---|
| 675 | + hdmi_writeb(hdmi, 0, HDMI_I2CM_SOFTRSTZ); |
|---|
| 676 | + hdmi_writeb(hdmi, HDMI_I2CM_OPERATION_BUS_CLEAR, |
|---|
| 677 | + HDMI_I2CM_OPERATION); |
|---|
| 678 | + retry -= 10; |
|---|
| 679 | + continue; |
|---|
| 680 | + } else if (ret == -EIO) { |
|---|
| 681 | + dev_dbg(hdmi->dev, "ddc read err\n"); |
|---|
| 682 | + hdmi_writeb(hdmi, 0, HDMI_I2CM_SOFTRSTZ); |
|---|
| 683 | + hdmi_writeb(hdmi, HDMI_I2CM_OPERATION_BUS_CLEAR, |
|---|
| 684 | + HDMI_I2CM_OPERATION); |
|---|
| 685 | + retry--; |
|---|
| 686 | + usleep_range(10000, 11000); |
|---|
| 687 | + continue; |
|---|
| 688 | + } |
|---|
| 689 | + /* read success */ |
|---|
| 690 | + break; |
|---|
| 691 | + } |
|---|
| 692 | + if (retry <= 0) { |
|---|
| 693 | + dev_err(hdmi->dev, "ddc read failed\n"); |
|---|
| 596 | 694 | return -EIO; |
|---|
| 695 | + } |
|---|
| 597 | 696 | |
|---|
| 598 | | - *buf++ = hdmi_readb(hdmi, HDMI_I2CM_DATAI); |
|---|
| 697 | + if (read_edid) |
|---|
| 698 | + for (i = 0; i < 8; i++) |
|---|
| 699 | + *buf++ = hdmi_readb(hdmi, HDMI_I2CM_READ_BUFF0 + i); |
|---|
| 700 | + else |
|---|
| 701 | + *buf++ = hdmi_readb(hdmi, HDMI_I2CM_DATAI); |
|---|
| 599 | 702 | } |
|---|
| 703 | + |
|---|
| 600 | 704 | i2c->is_segment = false; |
|---|
| 601 | 705 | |
|---|
| 602 | 706 | return 0; |
|---|
| .. | .. |
|---|
| 606 | 710 | unsigned char *buf, unsigned int length) |
|---|
| 607 | 711 | { |
|---|
| 608 | 712 | struct dw_hdmi_i2c *i2c = hdmi->i2c; |
|---|
| 609 | | - int stat; |
|---|
| 713 | + int ret, retry; |
|---|
| 610 | 714 | |
|---|
| 611 | 715 | if (!i2c->is_regaddr) { |
|---|
| 612 | 716 | /* Use the first write byte as register address */ |
|---|
| .. | .. |
|---|
| 617 | 721 | } |
|---|
| 618 | 722 | |
|---|
| 619 | 723 | while (length--) { |
|---|
| 620 | | - reinit_completion(&i2c->cmp); |
|---|
| 724 | + retry = 100; |
|---|
| 621 | 725 | |
|---|
| 622 | 726 | hdmi_writeb(hdmi, *buf++, HDMI_I2CM_DATAO); |
|---|
| 623 | 727 | hdmi_writeb(hdmi, i2c->slave_reg++, HDMI_I2CM_ADDRESS); |
|---|
| 624 | | - hdmi_writeb(hdmi, HDMI_I2CM_OPERATION_WRITE, |
|---|
| 625 | | - HDMI_I2CM_OPERATION); |
|---|
| 626 | 728 | |
|---|
| 627 | | - stat = wait_for_completion_timeout(&i2c->cmp, HZ / 10); |
|---|
| 628 | | - if (!stat) |
|---|
| 629 | | - return -EAGAIN; |
|---|
| 729 | + while (retry > 0) { |
|---|
| 730 | + if (!(hdmi_readb(hdmi, HDMI_PHY_STAT0) & HDMI_PHY_HPD)) { |
|---|
| 731 | + dev_dbg(hdmi->dev, "hdmi disconnect, stop ddc write\n"); |
|---|
| 732 | + return -EPERM; |
|---|
| 733 | + } |
|---|
| 630 | 734 | |
|---|
| 631 | | - /* Check for error condition on the bus */ |
|---|
| 632 | | - if (i2c->stat & HDMI_IH_I2CM_STAT0_ERROR) |
|---|
| 735 | + reinit_completion(&i2c->cmp); |
|---|
| 736 | + hdmi_writeb(hdmi, HDMI_I2CM_OPERATION_WRITE, |
|---|
| 737 | + HDMI_I2CM_OPERATION); |
|---|
| 738 | + |
|---|
| 739 | + ret = dw_hdmi_i2c_wait(hdmi); |
|---|
| 740 | + if (ret == -EAGAIN) { |
|---|
| 741 | + dev_dbg(hdmi->dev, "ddc write time out\n"); |
|---|
| 742 | + hdmi_writeb(hdmi, 0, HDMI_I2CM_SOFTRSTZ); |
|---|
| 743 | + hdmi_writeb(hdmi, HDMI_I2CM_OPERATION_BUS_CLEAR, |
|---|
| 744 | + HDMI_I2CM_OPERATION); |
|---|
| 745 | + retry -= 10; |
|---|
| 746 | + continue; |
|---|
| 747 | + } else if (ret == -EIO) { |
|---|
| 748 | + dev_dbg(hdmi->dev, "ddc write err\n"); |
|---|
| 749 | + hdmi_writeb(hdmi, 0, HDMI_I2CM_SOFTRSTZ); |
|---|
| 750 | + hdmi_writeb(hdmi, HDMI_I2CM_OPERATION_BUS_CLEAR, |
|---|
| 751 | + HDMI_I2CM_OPERATION); |
|---|
| 752 | + retry--; |
|---|
| 753 | + usleep_range(10000, 11000); |
|---|
| 754 | + continue; |
|---|
| 755 | + } |
|---|
| 756 | + |
|---|
| 757 | + /* write success */ |
|---|
| 758 | + break; |
|---|
| 759 | + } |
|---|
| 760 | + |
|---|
| 761 | + if (retry <= 0) { |
|---|
| 762 | + dev_err(hdmi->dev, "ddc write failed\n"); |
|---|
| 633 | 763 | return -EIO; |
|---|
| 764 | + } |
|---|
| 634 | 765 | } |
|---|
| 635 | 766 | |
|---|
| 636 | 767 | return 0; |
|---|
| .. | .. |
|---|
| 665 | 796 | } |
|---|
| 666 | 797 | |
|---|
| 667 | 798 | mutex_lock(&i2c->lock); |
|---|
| 799 | + |
|---|
| 800 | + hdmi_writeb(hdmi, 0, HDMI_I2CM_SOFTRSTZ); |
|---|
| 801 | + udelay(100); |
|---|
| 668 | 802 | |
|---|
| 669 | 803 | /* Unmute DONE and ERROR interrupts */ |
|---|
| 670 | 804 | hdmi_writeb(hdmi, 0x00, HDMI_IH_MUTE_I2CM_STAT0); |
|---|
| .. | .. |
|---|
| 765 | 899 | /* nshift factor = 0 */ |
|---|
| 766 | 900 | hdmi_modb(hdmi, 0, HDMI_AUD_CTS3_N_SHIFT_MASK, HDMI_AUD_CTS3); |
|---|
| 767 | 901 | |
|---|
| 768 | | - hdmi_writeb(hdmi, ((cts >> 16) & HDMI_AUD_CTS3_AUDCTS19_16_MASK) | |
|---|
| 769 | | - HDMI_AUD_CTS3_CTS_MANUAL, HDMI_AUD_CTS3); |
|---|
| 902 | + /* Use automatic CTS generation mode when CTS is not set */ |
|---|
| 903 | + if (cts) |
|---|
| 904 | + hdmi_writeb(hdmi, ((cts >> 16) & |
|---|
| 905 | + HDMI_AUD_CTS3_AUDCTS19_16_MASK) | |
|---|
| 906 | + HDMI_AUD_CTS3_CTS_MANUAL, |
|---|
| 907 | + HDMI_AUD_CTS3); |
|---|
| 908 | + else |
|---|
| 909 | + hdmi_writeb(hdmi, 0, HDMI_AUD_CTS3); |
|---|
| 770 | 910 | hdmi_writeb(hdmi, (cts >> 8) & 0xff, HDMI_AUD_CTS2); |
|---|
| 771 | 911 | hdmi_writeb(hdmi, cts & 0xff, HDMI_AUD_CTS1); |
|---|
| 772 | 912 | |
|---|
| .. | .. |
|---|
| 888 | 1028 | return hdmi_compute_n(hdmi, pixel_clk, sample_rate); |
|---|
| 889 | 1029 | } |
|---|
| 890 | 1030 | |
|---|
| 1031 | +/* |
|---|
| 1032 | + * When transmitting IEC60958 linear PCM audio, these registers allow to |
|---|
| 1033 | + * configure the channel status information of all the channel status |
|---|
| 1034 | + * bits in the IEC60958 frame. For the moment this configuration is only |
|---|
| 1035 | + * used when the I2S audio interface, General Purpose Audio (GPA), |
|---|
| 1036 | + * or AHB audio DMA (AHBAUDDMA) interface is active |
|---|
| 1037 | + * (for S/PDIF interface this information comes from the stream). |
|---|
| 1038 | + */ |
|---|
| 1039 | +void dw_hdmi_set_channel_status(struct dw_hdmi *hdmi, |
|---|
| 1040 | + u8 *channel_status) |
|---|
| 1041 | +{ |
|---|
| 1042 | + /* |
|---|
| 1043 | + * Set channel status register for frequency and word length. |
|---|
| 1044 | + * Use default values for other registers. |
|---|
| 1045 | + */ |
|---|
| 1046 | + hdmi_writeb(hdmi, channel_status[3], HDMI_FC_AUDSCHNLS7); |
|---|
| 1047 | + hdmi_writeb(hdmi, channel_status[4], HDMI_FC_AUDSCHNLS8); |
|---|
| 1048 | +} |
|---|
| 1049 | +EXPORT_SYMBOL_GPL(dw_hdmi_set_channel_status); |
|---|
| 1050 | + |
|---|
| 891 | 1051 | static void hdmi_set_clk_regenerator(struct dw_hdmi *hdmi, |
|---|
| 892 | 1052 | unsigned long pixel_clk, unsigned int sample_rate) |
|---|
| 893 | 1053 | { |
|---|
| 894 | 1054 | unsigned long ftdms = pixel_clk; |
|---|
| 895 | 1055 | unsigned int n, cts; |
|---|
| 1056 | + u8 config3; |
|---|
| 896 | 1057 | u64 tmp; |
|---|
| 897 | 1058 | |
|---|
| 898 | 1059 | n = hdmi_find_n(hdmi, pixel_clk, sample_rate); |
|---|
| 899 | 1060 | |
|---|
| 900 | | - /* |
|---|
| 901 | | - * Compute the CTS value from the N value. Note that CTS and N |
|---|
| 902 | | - * can be up to 20 bits in total, so we need 64-bit math. Also |
|---|
| 903 | | - * note that our TDMS clock is not fully accurate; it is accurate |
|---|
| 904 | | - * to kHz. This can introduce an unnecessary remainder in the |
|---|
| 905 | | - * calculation below, so we don't try to warn about that. |
|---|
| 906 | | - */ |
|---|
| 907 | | - tmp = (u64)ftdms * n; |
|---|
| 908 | | - do_div(tmp, 128 * sample_rate); |
|---|
| 909 | | - cts = tmp; |
|---|
| 1061 | + config3 = hdmi_readb(hdmi, HDMI_CONFIG3_ID); |
|---|
| 910 | 1062 | |
|---|
| 911 | | - dev_dbg(hdmi->dev, "%s: fs=%uHz ftdms=%lu.%03luMHz N=%d cts=%d\n", |
|---|
| 912 | | - __func__, sample_rate, ftdms / 1000000, (ftdms / 1000) % 1000, |
|---|
| 913 | | - n, cts); |
|---|
| 1063 | + /* Only compute CTS when using internal AHB audio */ |
|---|
| 1064 | + if (config3 & HDMI_CONFIG3_AHBAUDDMA) { |
|---|
| 1065 | + /* |
|---|
| 1066 | + * Compute the CTS value from the N value. Note that CTS and N |
|---|
| 1067 | + * can be up to 20 bits in total, so we need 64-bit math. Also |
|---|
| 1068 | + * note that our TDMS clock is not fully accurate; it is |
|---|
| 1069 | + * accurate to kHz. This can introduce an unnecessary remainder |
|---|
| 1070 | + * in the calculation below, so we don't try to warn about that. |
|---|
| 1071 | + */ |
|---|
| 1072 | + tmp = (u64)ftdms * n; |
|---|
| 1073 | + do_div(tmp, 128 * sample_rate); |
|---|
| 1074 | + cts = tmp; |
|---|
| 1075 | + |
|---|
| 1076 | + dev_dbg(hdmi->dev, "%s: fs=%uHz ftdms=%lu.%03luMHz N=%d cts=%d\n", |
|---|
| 1077 | + __func__, sample_rate, |
|---|
| 1078 | + ftdms / 1000000, (ftdms / 1000) % 1000, |
|---|
| 1079 | + n, cts); |
|---|
| 1080 | + } else { |
|---|
| 1081 | + cts = 0; |
|---|
| 1082 | + } |
|---|
| 914 | 1083 | |
|---|
| 915 | 1084 | spin_lock_irq(&hdmi->audio_lock); |
|---|
| 916 | 1085 | hdmi->audio_n = n; |
|---|
| .. | .. |
|---|
| 944 | 1113 | } |
|---|
| 945 | 1114 | EXPORT_SYMBOL_GPL(dw_hdmi_set_sample_rate); |
|---|
| 946 | 1115 | |
|---|
| 1116 | +void dw_hdmi_set_channel_count(struct dw_hdmi *hdmi, unsigned int cnt) |
|---|
| 1117 | +{ |
|---|
| 1118 | + u8 layout; |
|---|
| 1119 | + |
|---|
| 1120 | + mutex_lock(&hdmi->audio_mutex); |
|---|
| 1121 | + |
|---|
| 1122 | + /* |
|---|
| 1123 | + * For >2 channel PCM audio, we need to select layout 1 |
|---|
| 1124 | + * and set an appropriate channel map. |
|---|
| 1125 | + */ |
|---|
| 1126 | + if (cnt > 2) |
|---|
| 1127 | + layout = HDMI_FC_AUDSCONF_AUD_PACKET_LAYOUT_LAYOUT1; |
|---|
| 1128 | + else |
|---|
| 1129 | + layout = HDMI_FC_AUDSCONF_AUD_PACKET_LAYOUT_LAYOUT0; |
|---|
| 1130 | + |
|---|
| 1131 | + hdmi_modb(hdmi, layout, HDMI_FC_AUDSCONF_AUD_PACKET_LAYOUT_MASK, |
|---|
| 1132 | + HDMI_FC_AUDSCONF); |
|---|
| 1133 | + |
|---|
| 1134 | + /* Set the audio infoframes channel count */ |
|---|
| 1135 | + hdmi_modb(hdmi, (cnt - 1) << HDMI_FC_AUDICONF0_CC_OFFSET, |
|---|
| 1136 | + HDMI_FC_AUDICONF0_CC_MASK, HDMI_FC_AUDICONF0); |
|---|
| 1137 | + |
|---|
| 1138 | + mutex_unlock(&hdmi->audio_mutex); |
|---|
| 1139 | +} |
|---|
| 1140 | +EXPORT_SYMBOL_GPL(dw_hdmi_set_channel_count); |
|---|
| 1141 | + |
|---|
| 1142 | +void dw_hdmi_set_channel_allocation(struct dw_hdmi *hdmi, unsigned int ca) |
|---|
| 1143 | +{ |
|---|
| 1144 | + mutex_lock(&hdmi->audio_mutex); |
|---|
| 1145 | + |
|---|
| 1146 | + hdmi_writeb(hdmi, ca, HDMI_FC_AUDICONF2); |
|---|
| 1147 | + |
|---|
| 1148 | + mutex_unlock(&hdmi->audio_mutex); |
|---|
| 1149 | +} |
|---|
| 1150 | +EXPORT_SYMBOL_GPL(dw_hdmi_set_channel_allocation); |
|---|
| 1151 | + |
|---|
| 947 | 1152 | static void hdmi_enable_audio_clk(struct dw_hdmi *hdmi, bool enable) |
|---|
| 948 | 1153 | { |
|---|
| 949 | 1154 | if (enable) |
|---|
| .. | .. |
|---|
| 951 | 1156 | else |
|---|
| 952 | 1157 | hdmi->mc_clkdis |= HDMI_MC_CLKDIS_AUDCLK_DISABLE; |
|---|
| 953 | 1158 | hdmi_writeb(hdmi, hdmi->mc_clkdis, HDMI_MC_CLKDIS); |
|---|
| 1159 | +} |
|---|
| 1160 | + |
|---|
| 1161 | +static u8 *hdmi_audio_get_eld(struct dw_hdmi *hdmi) |
|---|
| 1162 | +{ |
|---|
| 1163 | + if (!hdmi->curr_conn) |
|---|
| 1164 | + return NULL; |
|---|
| 1165 | + |
|---|
| 1166 | + return hdmi->curr_conn->eld; |
|---|
| 954 | 1167 | } |
|---|
| 955 | 1168 | |
|---|
| 956 | 1169 | static void dw_hdmi_ahb_audio_enable(struct dw_hdmi *hdmi) |
|---|
| .. | .. |
|---|
| 1161 | 1374 | |
|---|
| 1162 | 1375 | static int is_color_space_conversion(struct dw_hdmi *hdmi) |
|---|
| 1163 | 1376 | { |
|---|
| 1164 | | - const struct drm_display_mode mode = hdmi->previous_mode; |
|---|
| 1165 | | - bool is_cea_default; |
|---|
| 1377 | + struct hdmi_data_info *hdmi_data = &hdmi->hdmi_data; |
|---|
| 1378 | + bool is_input_rgb, is_output_rgb; |
|---|
| 1166 | 1379 | |
|---|
| 1167 | | - is_cea_default = (drm_match_cea_mode(&mode) > 1) && |
|---|
| 1168 | | - (hdmi->hdmi_data.quant_range == |
|---|
| 1169 | | - HDMI_QUANTIZATION_RANGE_DEFAULT); |
|---|
| 1380 | + is_input_rgb = hdmi_bus_fmt_is_rgb(hdmi_data->enc_in_bus_format); |
|---|
| 1381 | + is_output_rgb = hdmi_bus_fmt_is_rgb(hdmi_data->enc_out_bus_format); |
|---|
| 1170 | 1382 | |
|---|
| 1171 | | - /* |
|---|
| 1172 | | - * When output is rgb limited range or default range with |
|---|
| 1173 | | - * cea mode, csc should be enabled. |
|---|
| 1174 | | - */ |
|---|
| 1175 | | - if (hdmi->hdmi_data.enc_in_bus_format != |
|---|
| 1176 | | - hdmi->hdmi_data.enc_out_bus_format || |
|---|
| 1177 | | - ((hdmi->hdmi_data.quant_range == HDMI_QUANTIZATION_RANGE_LIMITED || |
|---|
| 1178 | | - is_cea_default) && |
|---|
| 1179 | | - hdmi_bus_fmt_is_rgb(hdmi->hdmi_data.enc_in_bus_format))) |
|---|
| 1180 | | - return 1; |
|---|
| 1181 | | - |
|---|
| 1182 | | - return 0; |
|---|
| 1383 | + return (is_input_rgb != is_output_rgb) || |
|---|
| 1384 | + (is_input_rgb && is_output_rgb && hdmi_data->rgb_limited_range); |
|---|
| 1183 | 1385 | } |
|---|
| 1184 | 1386 | |
|---|
| 1185 | 1387 | static int is_color_space_decimation(struct dw_hdmi *hdmi) |
|---|
| .. | .. |
|---|
| 1206 | 1408 | return 0; |
|---|
| 1207 | 1409 | } |
|---|
| 1208 | 1410 | |
|---|
| 1411 | +static bool is_csc_needed(struct dw_hdmi *hdmi) |
|---|
| 1412 | +{ |
|---|
| 1413 | + return is_color_space_conversion(hdmi) || |
|---|
| 1414 | + is_color_space_decimation(hdmi) || |
|---|
| 1415 | + is_color_space_interpolation(hdmi); |
|---|
| 1416 | +} |
|---|
| 1417 | + |
|---|
| 1418 | +static bool is_rgb_full_to_limited_needed(struct dw_hdmi *hdmi) |
|---|
| 1419 | +{ |
|---|
| 1420 | + if (hdmi->hdmi_data.quant_range == HDMI_QUANTIZATION_RANGE_LIMITED || |
|---|
| 1421 | + (!hdmi->hdmi_data.quant_range && hdmi->hdmi_data.rgb_limited_range)) |
|---|
| 1422 | + return true; |
|---|
| 1423 | + |
|---|
| 1424 | + return false; |
|---|
| 1425 | +} |
|---|
| 1426 | + |
|---|
| 1209 | 1427 | static void dw_hdmi_update_csc_coeffs(struct dw_hdmi *hdmi) |
|---|
| 1210 | 1428 | { |
|---|
| 1211 | 1429 | const u16 (*csc_coeff)[3][4] = &csc_coeff_default; |
|---|
| 1430 | + bool is_input_rgb, is_output_rgb; |
|---|
| 1212 | 1431 | unsigned i; |
|---|
| 1213 | 1432 | u32 csc_scale = 1; |
|---|
| 1214 | | - int enc_out_rgb, enc_in_rgb; |
|---|
| 1215 | | - int color_depth; |
|---|
| 1216 | 1433 | |
|---|
| 1217 | | - enc_out_rgb = hdmi_bus_fmt_is_rgb(hdmi->hdmi_data.enc_out_bus_format); |
|---|
| 1218 | | - enc_in_rgb = hdmi_bus_fmt_is_rgb(hdmi->hdmi_data.enc_in_bus_format); |
|---|
| 1219 | | - color_depth = hdmi_bus_fmt_color_depth(hdmi->hdmi_data.enc_out_bus_format); |
|---|
| 1434 | + is_input_rgb = hdmi_bus_fmt_is_rgb(hdmi->hdmi_data.enc_in_bus_format); |
|---|
| 1435 | + is_output_rgb = hdmi_bus_fmt_is_rgb(hdmi->hdmi_data.enc_out_bus_format); |
|---|
| 1220 | 1436 | |
|---|
| 1221 | | - if (is_color_space_conversion(hdmi)) { |
|---|
| 1222 | | - if (enc_out_rgb && enc_in_rgb) { |
|---|
| 1223 | | - csc_coeff = &csc_coeff_full_to_limited; |
|---|
| 1224 | | - csc_scale = 0; |
|---|
| 1225 | | - } else if (enc_out_rgb) { |
|---|
| 1226 | | - if (hdmi->hdmi_data.enc_out_encoding == |
|---|
| 1227 | | - V4L2_YCBCR_ENC_601) |
|---|
| 1228 | | - csc_coeff = &csc_coeff_rgb_out_eitu601; |
|---|
| 1229 | | - else |
|---|
| 1230 | | - csc_coeff = &csc_coeff_rgb_out_eitu709; |
|---|
| 1231 | | - } else if (enc_in_rgb) { |
|---|
| 1232 | | - if (hdmi->hdmi_data.enc_out_encoding == |
|---|
| 1233 | | - V4L2_YCBCR_ENC_601) { |
|---|
| 1234 | | - if (color_depth == 10) |
|---|
| 1235 | | - csc_coeff = &csc_coeff_rgb_in_eitu601_10bit_limited; |
|---|
| 1236 | | - else |
|---|
| 1237 | | - csc_coeff = &csc_coeff_rgb_in_eitu601_limited; |
|---|
| 1238 | | - } else { |
|---|
| 1239 | | - if (color_depth == 10) |
|---|
| 1240 | | - csc_coeff = &csc_coeff_rgb_in_eitu709_10bit_limited; |
|---|
| 1241 | | - else |
|---|
| 1242 | | - csc_coeff = &csc_coeff_rgb_in_eitu709_limited; |
|---|
| 1243 | | - } |
|---|
| 1244 | | - csc_scale = 0; |
|---|
| 1245 | | - } |
|---|
| 1437 | + if (!is_input_rgb && is_output_rgb) { |
|---|
| 1438 | + if (hdmi->hdmi_data.enc_out_encoding == V4L2_YCBCR_ENC_601) |
|---|
| 1439 | + csc_coeff = &csc_coeff_rgb_out_eitu601; |
|---|
| 1440 | + else |
|---|
| 1441 | + csc_coeff = &csc_coeff_rgb_out_eitu709; |
|---|
| 1442 | + } else if (is_input_rgb && !is_output_rgb) { |
|---|
| 1443 | + if (hdmi->hdmi_data.enc_out_encoding == V4L2_YCBCR_ENC_601) |
|---|
| 1444 | + csc_coeff = &csc_coeff_rgb_in_eitu601; |
|---|
| 1445 | + else |
|---|
| 1446 | + csc_coeff = &csc_coeff_rgb_in_eitu709; |
|---|
| 1447 | + csc_scale = 0; |
|---|
| 1448 | + } else if (is_input_rgb && is_output_rgb && |
|---|
| 1449 | + is_rgb_full_to_limited_needed(hdmi)) { |
|---|
| 1450 | + csc_coeff = &csc_coeff_rgb_full_to_rgb_limited; |
|---|
| 1246 | 1451 | } |
|---|
| 1247 | 1452 | |
|---|
| 1248 | 1453 | /* The CSC registers are sequential, alternating MSB then LSB */ |
|---|
| .. | .. |
|---|
| 1378 | 1583 | HDMI_VP_CONF_PR_EN_MASK | |
|---|
| 1379 | 1584 | HDMI_VP_CONF_BYPASS_SELECT_MASK, HDMI_VP_CONF); |
|---|
| 1380 | 1585 | |
|---|
| 1381 | | - if ((color_depth == 5 && hdmi->previous_mode.htotal % 4) || |
|---|
| 1382 | | - (color_depth == 6 && hdmi->previous_mode.htotal % 2)) |
|---|
| 1383 | | - hdmi_modb(hdmi, 0, HDMI_VP_STUFF_IDEFAULT_PHASE_MASK, |
|---|
| 1384 | | - HDMI_VP_STUFF); |
|---|
| 1385 | | - else |
|---|
| 1386 | | - hdmi_modb(hdmi, 1 << HDMI_VP_STUFF_IDEFAULT_PHASE_OFFSET, |
|---|
| 1387 | | - HDMI_VP_STUFF_IDEFAULT_PHASE_MASK, HDMI_VP_STUFF); |
|---|
| 1388 | | - |
|---|
| 1586 | + hdmi_modb(hdmi, 0, HDMI_VP_STUFF_IDEFAULT_PHASE_MASK, HDMI_VP_STUFF); |
|---|
| 1389 | 1587 | hdmi_writeb(hdmi, remap_size, HDMI_VP_REMAP); |
|---|
| 1390 | 1588 | |
|---|
| 1391 | 1589 | if (output_select == HDMI_VP_CONF_OUTPUT_SELECTOR_PP) { |
|---|
| .. | .. |
|---|
| 1457 | 1655 | } |
|---|
| 1458 | 1656 | EXPORT_SYMBOL_GPL(dw_hdmi_phy_i2c_write); |
|---|
| 1459 | 1657 | |
|---|
| 1460 | | -static int hdmi_phy_i2c_read(struct dw_hdmi *hdmi, unsigned char addr) |
|---|
| 1461 | | -{ |
|---|
| 1462 | | - int val; |
|---|
| 1463 | | - |
|---|
| 1464 | | - hdmi_writeb(hdmi, 0xFF, HDMI_IH_I2CMPHY_STAT0); |
|---|
| 1465 | | - hdmi_writeb(hdmi, addr, HDMI_PHY_I2CM_ADDRESS_ADDR); |
|---|
| 1466 | | - hdmi_writeb(hdmi, 0, HDMI_PHY_I2CM_DATAI_1_ADDR); |
|---|
| 1467 | | - hdmi_writeb(hdmi, 0, HDMI_PHY_I2CM_DATAI_0_ADDR); |
|---|
| 1468 | | - hdmi_writeb(hdmi, HDMI_PHY_I2CM_OPERATION_ADDR_READ, |
|---|
| 1469 | | - HDMI_PHY_I2CM_OPERATION_ADDR); |
|---|
| 1470 | | - hdmi_phy_wait_i2c_done(hdmi, 1000); |
|---|
| 1471 | | - val = hdmi_readb(hdmi, HDMI_PHY_I2CM_DATAI_1_ADDR); |
|---|
| 1472 | | - val = (val & 0xff) << 8; |
|---|
| 1473 | | - val += hdmi_readb(hdmi, HDMI_PHY_I2CM_DATAI_0_ADDR) & 0xff; |
|---|
| 1474 | | - return val; |
|---|
| 1475 | | -} |
|---|
| 1476 | | - |
|---|
| 1477 | 1658 | /* Filter out invalid setups to avoid configuring SCDC and scrambling */ |
|---|
| 1478 | | -static bool dw_hdmi_support_scdc(struct dw_hdmi *hdmi) |
|---|
| 1659 | +static bool dw_hdmi_support_scdc(struct dw_hdmi *hdmi, |
|---|
| 1660 | + const struct drm_display_info *display) |
|---|
| 1479 | 1661 | { |
|---|
| 1480 | | - struct drm_display_info *display = &hdmi->connector.display_info; |
|---|
| 1481 | | - |
|---|
| 1482 | 1662 | /* Completely disable SCDC support for older controllers */ |
|---|
| 1483 | 1663 | if (hdmi->version < 0x200a) |
|---|
| 1664 | + return false; |
|---|
| 1665 | + |
|---|
| 1666 | + /* Disable if no DDC bus */ |
|---|
| 1667 | + if (!hdmi->ddc) |
|---|
| 1484 | 1668 | return false; |
|---|
| 1485 | 1669 | |
|---|
| 1486 | 1670 | /* Disable if SCDC is not supported, or if an HF-VSDB block is absent */ |
|---|
| .. | .. |
|---|
| 1499 | 1683 | return true; |
|---|
| 1500 | 1684 | } |
|---|
| 1501 | 1685 | |
|---|
| 1686 | +static int hdmi_phy_i2c_read(struct dw_hdmi *hdmi, unsigned char addr) |
|---|
| 1687 | +{ |
|---|
| 1688 | + int val; |
|---|
| 1689 | + |
|---|
| 1690 | + hdmi_writeb(hdmi, 0xFF, HDMI_IH_I2CMPHY_STAT0); |
|---|
| 1691 | + hdmi_writeb(hdmi, addr, HDMI_PHY_I2CM_ADDRESS_ADDR); |
|---|
| 1692 | + hdmi_writeb(hdmi, 0, HDMI_PHY_I2CM_DATAI_1_ADDR); |
|---|
| 1693 | + hdmi_writeb(hdmi, 0, HDMI_PHY_I2CM_DATAI_0_ADDR); |
|---|
| 1694 | + hdmi_writeb(hdmi, HDMI_PHY_I2CM_OPERATION_ADDR_READ, |
|---|
| 1695 | + HDMI_PHY_I2CM_OPERATION_ADDR); |
|---|
| 1696 | + hdmi_phy_wait_i2c_done(hdmi, 1000); |
|---|
| 1697 | + val = hdmi_readb(hdmi, HDMI_PHY_I2CM_DATAI_1_ADDR); |
|---|
| 1698 | + val = (val & 0xff) << 8; |
|---|
| 1699 | + val += hdmi_readb(hdmi, HDMI_PHY_I2CM_DATAI_0_ADDR) & 0xff; |
|---|
| 1700 | + return val; |
|---|
| 1701 | +} |
|---|
| 1702 | + |
|---|
| 1502 | 1703 | /* |
|---|
| 1503 | 1704 | * HDMI2.0 Specifies the following procedure for High TMDS Bit Rates: |
|---|
| 1504 | 1705 | * - The Source shall suspend transmission of the TMDS clock and data |
|---|
| .. | .. |
|---|
| 1512 | 1713 | * helper should called right before enabling the TMDS Clock and Data in |
|---|
| 1513 | 1714 | * the PHY configuration callback. |
|---|
| 1514 | 1715 | */ |
|---|
| 1515 | | -void dw_hdmi_set_high_tmds_clock_ratio(struct dw_hdmi *hdmi) |
|---|
| 1716 | +void dw_hdmi_set_high_tmds_clock_ratio(struct dw_hdmi *hdmi, |
|---|
| 1717 | + const struct drm_display_info *display) |
|---|
| 1516 | 1718 | { |
|---|
| 1517 | 1719 | unsigned long mtmdsclock = hdmi->hdmi_data.video_mode.mtmdsclock; |
|---|
| 1518 | 1720 | |
|---|
| 1519 | 1721 | /* Control for TMDS Bit Period/TMDS Clock-Period Ratio */ |
|---|
| 1520 | | - if (dw_hdmi_support_scdc(hdmi)) { |
|---|
| 1722 | + if (dw_hdmi_support_scdc(hdmi, display)) { |
|---|
| 1521 | 1723 | if (mtmdsclock > HDMI14_MAX_TMDSCLK) |
|---|
| 1522 | 1724 | drm_scdc_set_high_tmds_clock_ratio(hdmi->ddc, 1); |
|---|
| 1523 | 1725 | else |
|---|
| .. | .. |
|---|
| 1730 | 1932 | return 0; |
|---|
| 1731 | 1933 | } |
|---|
| 1732 | 1934 | |
|---|
| 1733 | | -static int hdmi_phy_configure(struct dw_hdmi *hdmi) |
|---|
| 1935 | +static int hdmi_phy_configure(struct dw_hdmi *hdmi, |
|---|
| 1936 | + const struct drm_display_info *display) |
|---|
| 1734 | 1937 | { |
|---|
| 1735 | 1938 | const struct dw_hdmi_phy_data *phy = hdmi->phy.data; |
|---|
| 1736 | 1939 | const struct dw_hdmi_plat_data *pdata = hdmi->plat_data; |
|---|
| .. | .. |
|---|
| 1740 | 1943 | |
|---|
| 1741 | 1944 | dw_hdmi_phy_power_off(hdmi); |
|---|
| 1742 | 1945 | |
|---|
| 1743 | | - dw_hdmi_set_high_tmds_clock_ratio(hdmi); |
|---|
| 1946 | + dw_hdmi_set_high_tmds_clock_ratio(hdmi, display); |
|---|
| 1744 | 1947 | |
|---|
| 1745 | 1948 | /* Leave low power consumption mode by asserting SVSRET. */ |
|---|
| 1746 | 1949 | if (phy->has_svsret) |
|---|
| .. | .. |
|---|
| 1754 | 1957 | |
|---|
| 1755 | 1958 | /* Write to the PHY as configured by the platform */ |
|---|
| 1756 | 1959 | if (pdata->configure_phy) |
|---|
| 1757 | | - ret = pdata->configure_phy(hdmi, pdata, mpixelclock); |
|---|
| 1960 | + ret = pdata->configure_phy(hdmi, pdata->priv_data, mpixelclock); |
|---|
| 1758 | 1961 | else |
|---|
| 1759 | 1962 | ret = phy->configure(hdmi, pdata, mpixelclock); |
|---|
| 1760 | 1963 | if (ret) { |
|---|
| .. | .. |
|---|
| 1771 | 1974 | } |
|---|
| 1772 | 1975 | |
|---|
| 1773 | 1976 | static int dw_hdmi_phy_init(struct dw_hdmi *hdmi, void *data, |
|---|
| 1774 | | - struct drm_display_mode *mode) |
|---|
| 1977 | + const struct drm_display_info *display, |
|---|
| 1978 | + const struct drm_display_mode *mode) |
|---|
| 1775 | 1979 | { |
|---|
| 1776 | 1980 | int i, ret; |
|---|
| 1777 | 1981 | |
|---|
| .. | .. |
|---|
| 1780 | 1984 | dw_hdmi_phy_sel_data_en_pol(hdmi, 1); |
|---|
| 1781 | 1985 | dw_hdmi_phy_sel_interface_control(hdmi, 0); |
|---|
| 1782 | 1986 | |
|---|
| 1783 | | - ret = hdmi_phy_configure(hdmi); |
|---|
| 1987 | + ret = hdmi_phy_configure(hdmi, display); |
|---|
| 1784 | 1988 | if (ret) |
|---|
| 1785 | 1989 | return ret; |
|---|
| 1786 | 1990 | } |
|---|
| .. | .. |
|---|
| 1883 | 2087 | hdmi->hdcp->hdcp_start(hdmi->hdcp); |
|---|
| 1884 | 2088 | } |
|---|
| 1885 | 2089 | |
|---|
| 1886 | | -static void hdmi_config_AVI(struct dw_hdmi *hdmi, struct drm_display_mode *mode) |
|---|
| 2090 | +static void hdmi_config_AVI(struct dw_hdmi *hdmi, |
|---|
| 2091 | + const struct drm_connector *connector, |
|---|
| 2092 | + const struct drm_display_mode *mode) |
|---|
| 1887 | 2093 | { |
|---|
| 1888 | 2094 | struct hdmi_avi_infoframe frame; |
|---|
| 1889 | 2095 | u8 val; |
|---|
| 1890 | | - bool is_hdmi2 = false; |
|---|
| 1891 | | - enum hdmi_quantization_range rgb_quant_range = |
|---|
| 1892 | | - hdmi->hdmi_data.quant_range; |
|---|
| 2096 | + bool is_hdmi2; |
|---|
| 2097 | + const struct drm_display_info *info = &connector->display_info; |
|---|
| 1893 | 2098 | |
|---|
| 1894 | | - if (hdmi_bus_fmt_is_yuv420(hdmi->hdmi_data.enc_out_bus_format) || |
|---|
| 1895 | | - hdmi->connector.display_info.hdmi.scdc.supported) |
|---|
| 1896 | | - is_hdmi2 = true; |
|---|
| 2099 | + is_hdmi2 = info->hdmi.scdc.supported || (info->color_formats & DRM_COLOR_FORMAT_YCRCB420); |
|---|
| 2100 | + |
|---|
| 1897 | 2101 | /* Initialise info frame from DRM mode */ |
|---|
| 1898 | | - drm_hdmi_avi_infoframe_from_display_mode(&frame, mode, is_hdmi2); |
|---|
| 2102 | + drm_hdmi_avi_infoframe_from_display_mode(&frame, connector, mode); |
|---|
| 1899 | 2103 | |
|---|
| 1900 | | - drm_hdmi_avi_infoframe_quant_range(&frame, mode, rgb_quant_range, |
|---|
| 1901 | | - hdmi->rgb_quant_range_selectable || is_hdmi2, |
|---|
| 1902 | | - is_hdmi2); |
|---|
| 2104 | + if (hdmi_bus_fmt_is_rgb(hdmi->hdmi_data.enc_out_bus_format)) { |
|---|
| 2105 | + /* default range */ |
|---|
| 2106 | + if (!hdmi->hdmi_data.quant_range) |
|---|
| 2107 | + drm_hdmi_avi_infoframe_quant_range(&frame, connector, mode, |
|---|
| 2108 | + hdmi->hdmi_data.rgb_limited_range ? |
|---|
| 2109 | + HDMI_QUANTIZATION_RANGE_LIMITED : |
|---|
| 2110 | + HDMI_QUANTIZATION_RANGE_FULL); |
|---|
| 2111 | + else |
|---|
| 2112 | + drm_hdmi_avi_infoframe_quant_range(&frame, connector, mode, |
|---|
| 2113 | + hdmi->hdmi_data.quant_range); |
|---|
| 2114 | + } else { |
|---|
| 2115 | + frame.quantization_range = HDMI_QUANTIZATION_RANGE_DEFAULT; |
|---|
| 2116 | + frame.ycc_quantization_range = |
|---|
| 2117 | + HDMI_YCC_QUANTIZATION_RANGE_LIMITED; |
|---|
| 2118 | + } |
|---|
| 1903 | 2119 | |
|---|
| 1904 | 2120 | if (hdmi_bus_fmt_is_yuv444(hdmi->hdmi_data.enc_out_bus_format)) |
|---|
| 1905 | 2121 | frame.colorspace = HDMI_COLORSPACE_YUV444; |
|---|
| .. | .. |
|---|
| 1935 | 2151 | else |
|---|
| 1936 | 2152 | frame.colorimetry = HDMI_COLORIMETRY_ITU_709; |
|---|
| 1937 | 2153 | frame.extended_colorimetry = |
|---|
| 1938 | | - HDMI_EXTENDED_COLORIMETRY_BT2020; |
|---|
| 1939 | | - break; |
|---|
| 2154 | + HDMI_EXTENDED_COLORIMETRY_BT2020; |
|---|
| 2155 | + break; |
|---|
| 1940 | 2156 | default: /* Carries no data */ |
|---|
| 1941 | 2157 | frame.colorimetry = HDMI_COLORIMETRY_ITU_601; |
|---|
| 1942 | 2158 | frame.extended_colorimetry = |
|---|
| 1943 | 2159 | HDMI_EXTENDED_COLORIMETRY_XV_YCC_601; |
|---|
| 1944 | 2160 | break; |
|---|
| 1945 | 2161 | } |
|---|
| 2162 | + frame.ycc_quantization_range = HDMI_YCC_QUANTIZATION_RANGE_LIMITED; |
|---|
| 1946 | 2163 | } else { |
|---|
| 1947 | | - frame.colorimetry = HDMI_COLORIMETRY_NONE; |
|---|
| 1948 | | - frame.extended_colorimetry = |
|---|
| 1949 | | - HDMI_EXTENDED_COLORIMETRY_XV_YCC_601; |
|---|
| 1950 | | - } |
|---|
| 2164 | + if (hdmi->hdmi_data.enc_out_encoding == V4L2_YCBCR_ENC_BT2020) { |
|---|
| 2165 | + frame.colorimetry = HDMI_COLORIMETRY_EXTENDED; |
|---|
| 2166 | + frame.extended_colorimetry = |
|---|
| 2167 | + HDMI_EXTENDED_COLORIMETRY_BT2020; |
|---|
| 2168 | + } else { |
|---|
| 2169 | + frame.colorimetry = HDMI_COLORIMETRY_NONE; |
|---|
| 2170 | + frame.extended_colorimetry = |
|---|
| 2171 | + HDMI_EXTENDED_COLORIMETRY_XV_YCC_601; |
|---|
| 2172 | + } |
|---|
| 1951 | 2173 | |
|---|
| 1952 | | - frame.scan_mode = HDMI_SCAN_MODE_NONE; |
|---|
| 2174 | + if (is_hdmi2 && frame.quantization_range == HDMI_QUANTIZATION_RANGE_FULL) |
|---|
| 2175 | + frame.ycc_quantization_range = HDMI_YCC_QUANTIZATION_RANGE_FULL; |
|---|
| 2176 | + else |
|---|
| 2177 | + frame.ycc_quantization_range = HDMI_YCC_QUANTIZATION_RANGE_LIMITED; |
|---|
| 2178 | + } |
|---|
| 1953 | 2179 | |
|---|
| 1954 | 2180 | /* |
|---|
| 1955 | 2181 | * The Designware IP uses a different byte format from standard |
|---|
| .. | .. |
|---|
| 1986 | 2212 | hdmi_writeb(hdmi, val, HDMI_FC_AVICONF2); |
|---|
| 1987 | 2213 | |
|---|
| 1988 | 2214 | /* AVI data byte 4 differences: none */ |
|---|
| 1989 | | - val = frame.video_code & 0x7f; |
|---|
| 2215 | + if (hdmi_bus_fmt_is_yuv420(hdmi->hdmi_data.enc_out_bus_format) || |
|---|
| 2216 | + hdmi->connector.display_info.hdmi.scdc.supported) |
|---|
| 2217 | + val = hdmi->vic; |
|---|
| 2218 | + else |
|---|
| 2219 | + val = frame.video_code & 0x7f; |
|---|
| 1990 | 2220 | hdmi_writeb(hdmi, val, HDMI_FC_AVIVID); |
|---|
| 1991 | 2221 | |
|---|
| 1992 | 2222 | /* AVI Data Byte 5- set up input and output pixel repetition */ |
|---|
| .. | .. |
|---|
| 2018 | 2248 | } |
|---|
| 2019 | 2249 | |
|---|
| 2020 | 2250 | static void hdmi_config_vendor_specific_infoframe(struct dw_hdmi *hdmi, |
|---|
| 2021 | | - struct drm_display_mode *mode) |
|---|
| 2251 | + const struct drm_connector *connector, |
|---|
| 2252 | + const struct drm_display_mode *mode) |
|---|
| 2022 | 2253 | { |
|---|
| 2023 | 2254 | struct hdmi_vendor_infoframe frame; |
|---|
| 2024 | 2255 | u8 buffer[10]; |
|---|
| 2025 | 2256 | ssize_t err; |
|---|
| 2257 | + |
|---|
| 2258 | + /* if sink support hdmi2.0, don't send vsi */ |
|---|
| 2259 | + if (hdmi_bus_fmt_is_yuv420(hdmi->hdmi_data.enc_out_bus_format) || |
|---|
| 2260 | + hdmi->connector.display_info.hdmi.scdc.supported) { |
|---|
| 2261 | + hdmi_mask_writeb(hdmi, 0, HDMI_FC_DATAUTO0, HDMI_FC_DATAUTO0_VSD_OFFSET, |
|---|
| 2262 | + HDMI_FC_DATAUTO0_VSD_MASK); |
|---|
| 2263 | + return; |
|---|
| 2264 | + } |
|---|
| 2026 | 2265 | |
|---|
| 2027 | 2266 | err = drm_hdmi_vendor_infoframe_from_display_mode(&frame, |
|---|
| 2028 | 2267 | &hdmi->connector, |
|---|
| .. | .. |
|---|
| 2071 | 2310 | HDMI_FC_DATAUTO0_VSD_MASK); |
|---|
| 2072 | 2311 | } |
|---|
| 2073 | 2312 | |
|---|
| 2313 | +static void hdmi_config_drm_infoframe(struct dw_hdmi *hdmi, |
|---|
| 2314 | + const struct drm_connector *connector) |
|---|
| 2315 | +{ |
|---|
| 2316 | + const struct drm_connector_state *conn_state = connector->state; |
|---|
| 2317 | + struct hdr_output_metadata *hdr_metadata; |
|---|
| 2318 | + struct hdmi_drm_infoframe frame; |
|---|
| 2319 | + u8 buffer[30]; |
|---|
| 2320 | + ssize_t err; |
|---|
| 2321 | + int i; |
|---|
| 2322 | + |
|---|
| 2323 | + /* Dynamic Range and Mastering Infoframe is introduced in v2.11a. */ |
|---|
| 2324 | + if (hdmi->version < 0x211a) { |
|---|
| 2325 | + dev_dbg(hdmi->dev, "Not support DRM Infoframe\n"); |
|---|
| 2326 | + return; |
|---|
| 2327 | + } |
|---|
| 2328 | + |
|---|
| 2329 | + if (!hdmi->plat_data->use_drm_infoframe) |
|---|
| 2330 | + return; |
|---|
| 2331 | + |
|---|
| 2332 | + hdmi_modb(hdmi, HDMI_FC_PACKET_TX_EN_DRM_DISABLE, |
|---|
| 2333 | + HDMI_FC_PACKET_TX_EN_DRM_MASK, HDMI_FC_PACKET_TX_EN); |
|---|
| 2334 | + |
|---|
| 2335 | + if (!hdmi->connector.hdr_sink_metadata.hdmi_type1.eotf) { |
|---|
| 2336 | + DRM_DEBUG("No need to set HDR metadata in infoframe\n"); |
|---|
| 2337 | + return; |
|---|
| 2338 | + } |
|---|
| 2339 | + |
|---|
| 2340 | + if (!conn_state->hdr_output_metadata) { |
|---|
| 2341 | + DRM_DEBUG("source metadata not set yet\n"); |
|---|
| 2342 | + return; |
|---|
| 2343 | + } |
|---|
| 2344 | + |
|---|
| 2345 | + hdr_metadata = (struct hdr_output_metadata *) |
|---|
| 2346 | + conn_state->hdr_output_metadata->data; |
|---|
| 2347 | + |
|---|
| 2348 | + if (!(hdmi->connector.hdr_sink_metadata.hdmi_type1.eotf & |
|---|
| 2349 | + BIT(hdr_metadata->hdmi_metadata_type1.eotf))) { |
|---|
| 2350 | + DRM_ERROR("Not support EOTF %d\n", |
|---|
| 2351 | + hdr_metadata->hdmi_metadata_type1.eotf); |
|---|
| 2352 | + return; |
|---|
| 2353 | + } |
|---|
| 2354 | + |
|---|
| 2355 | + err = drm_hdmi_infoframe_set_hdr_metadata(&frame, conn_state); |
|---|
| 2356 | + if (err < 0) |
|---|
| 2357 | + return; |
|---|
| 2358 | + |
|---|
| 2359 | + err = hdmi_drm_infoframe_pack(&frame, buffer, sizeof(buffer)); |
|---|
| 2360 | + if (err < 0) { |
|---|
| 2361 | + dev_err(hdmi->dev, "Failed to pack drm infoframe: %zd\n", err); |
|---|
| 2362 | + return; |
|---|
| 2363 | + } |
|---|
| 2364 | + |
|---|
| 2365 | + hdmi_writeb(hdmi, frame.version, HDMI_FC_DRM_HB0); |
|---|
| 2366 | + hdmi_writeb(hdmi, frame.length, HDMI_FC_DRM_HB1); |
|---|
| 2367 | + |
|---|
| 2368 | + for (i = 0; i < frame.length; i++) |
|---|
| 2369 | + hdmi_writeb(hdmi, buffer[4 + i], HDMI_FC_DRM_PB0 + i); |
|---|
| 2370 | + |
|---|
| 2371 | + hdmi_writeb(hdmi, 1, HDMI_FC_DRM_UP); |
|---|
| 2372 | + /* |
|---|
| 2373 | + * avi and hdr infoframe cannot be sent at the same time |
|---|
| 2374 | + * for compatibility with Huawei TV |
|---|
| 2375 | + */ |
|---|
| 2376 | + msleep(300); |
|---|
| 2377 | + hdmi_modb(hdmi, HDMI_FC_PACKET_TX_EN_DRM_ENABLE, |
|---|
| 2378 | + HDMI_FC_PACKET_TX_EN_DRM_MASK, HDMI_FC_PACKET_TX_EN); |
|---|
| 2379 | + |
|---|
| 2380 | + DRM_DEBUG("%s eotf %d end\n", __func__, |
|---|
| 2381 | + hdr_metadata->hdmi_metadata_type1.eotf); |
|---|
| 2382 | +} |
|---|
| 2383 | + |
|---|
| 2074 | 2384 | static unsigned int |
|---|
| 2075 | 2385 | hdmi_get_tmdsclock(struct dw_hdmi *hdmi, unsigned long mpixelclock) |
|---|
| 2076 | 2386 | { |
|---|
| .. | .. |
|---|
| 2097 | 2407 | return tmdsclock; |
|---|
| 2098 | 2408 | } |
|---|
| 2099 | 2409 | |
|---|
| 2100 | | -#define HDR_LSB(n) ((n) & 0xff) |
|---|
| 2101 | | -#define HDR_MSB(n) (((n) & 0xff00) >> 8) |
|---|
| 2102 | | - |
|---|
| 2103 | | -/* Set Dynamic Range and Mastering Infoframe */ |
|---|
| 2104 | | -static void hdmi_config_hdr_infoframe(struct dw_hdmi *hdmi) |
|---|
| 2105 | | -{ |
|---|
| 2106 | | - struct hdmi_drm_infoframe frame; |
|---|
| 2107 | | - struct hdr_output_metadata *hdr_metadata; |
|---|
| 2108 | | - struct drm_connector_state *conn_state = hdmi->connector.state; |
|---|
| 2109 | | - int ret; |
|---|
| 2110 | | - |
|---|
| 2111 | | - /* Dynamic Range and Mastering Infoframe is introduced in v2.11a. */ |
|---|
| 2112 | | - if (hdmi->version < 0x211a) { |
|---|
| 2113 | | - DRM_ERROR("Not support DRM Infoframe\n"); |
|---|
| 2114 | | - return; |
|---|
| 2115 | | - } |
|---|
| 2116 | | - |
|---|
| 2117 | | - hdmi_modb(hdmi, HDMI_FC_PACKET_DRM_TX_DEN, |
|---|
| 2118 | | - HDMI_FC_PACKET_DRM_TX_EN_MASK, HDMI_FC_PACKET_TX_EN); |
|---|
| 2119 | | - |
|---|
| 2120 | | - if (!hdmi->connector.hdr_sink_metadata.hdmi_type1.eotf) { |
|---|
| 2121 | | - DRM_DEBUG("No need to set HDR metadata in infoframe\n"); |
|---|
| 2122 | | - return; |
|---|
| 2123 | | - } |
|---|
| 2124 | | - |
|---|
| 2125 | | - if (!conn_state->hdr_output_metadata) { |
|---|
| 2126 | | - DRM_DEBUG("source metadata not set yet\n"); |
|---|
| 2127 | | - return; |
|---|
| 2128 | | - } |
|---|
| 2129 | | - |
|---|
| 2130 | | - hdr_metadata = (struct hdr_output_metadata *) |
|---|
| 2131 | | - conn_state->hdr_output_metadata->data; |
|---|
| 2132 | | - |
|---|
| 2133 | | - if (!(hdmi->connector.hdr_sink_metadata.hdmi_type1.eotf & |
|---|
| 2134 | | - BIT(hdr_metadata->hdmi_metadata_type1.eotf))) { |
|---|
| 2135 | | - DRM_ERROR("Not support EOTF %d\n", |
|---|
| 2136 | | - hdr_metadata->hdmi_metadata_type1.eotf); |
|---|
| 2137 | | - return; |
|---|
| 2138 | | - } |
|---|
| 2139 | | - |
|---|
| 2140 | | - ret = drm_hdmi_infoframe_set_hdr_metadata(&frame, conn_state); |
|---|
| 2141 | | - if (ret < 0) { |
|---|
| 2142 | | - DRM_ERROR("couldn't set HDR metadata in infoframe\n"); |
|---|
| 2143 | | - return; |
|---|
| 2144 | | - } |
|---|
| 2145 | | - |
|---|
| 2146 | | - hdmi_writeb(hdmi, 1, HDMI_FC_DRM_HB0); |
|---|
| 2147 | | - hdmi_writeb(hdmi, frame.length, HDMI_FC_DRM_HB1); |
|---|
| 2148 | | - hdmi_writeb(hdmi, frame.eotf, HDMI_FC_DRM_PB0); |
|---|
| 2149 | | - hdmi_writeb(hdmi, frame.metadata_type, HDMI_FC_DRM_PB1); |
|---|
| 2150 | | - hdmi_writeb(hdmi, HDR_LSB(frame.display_primaries[0].x), |
|---|
| 2151 | | - HDMI_FC_DRM_PB2); |
|---|
| 2152 | | - hdmi_writeb(hdmi, HDR_MSB(frame.display_primaries[0].x), |
|---|
| 2153 | | - HDMI_FC_DRM_PB3); |
|---|
| 2154 | | - hdmi_writeb(hdmi, HDR_LSB(frame.display_primaries[0].y), |
|---|
| 2155 | | - HDMI_FC_DRM_PB4); |
|---|
| 2156 | | - hdmi_writeb(hdmi, HDR_MSB(frame.display_primaries[0].y), |
|---|
| 2157 | | - HDMI_FC_DRM_PB5); |
|---|
| 2158 | | - hdmi_writeb(hdmi, HDR_LSB(frame.display_primaries[1].x), |
|---|
| 2159 | | - HDMI_FC_DRM_PB6); |
|---|
| 2160 | | - hdmi_writeb(hdmi, HDR_MSB(frame.display_primaries[1].x), |
|---|
| 2161 | | - HDMI_FC_DRM_PB7); |
|---|
| 2162 | | - hdmi_writeb(hdmi, HDR_LSB(frame.display_primaries[1].y), |
|---|
| 2163 | | - HDMI_FC_DRM_PB8); |
|---|
| 2164 | | - hdmi_writeb(hdmi, HDR_MSB(frame.display_primaries[1].y), |
|---|
| 2165 | | - HDMI_FC_DRM_PB9); |
|---|
| 2166 | | - hdmi_writeb(hdmi, HDR_LSB(frame.display_primaries[2].x), |
|---|
| 2167 | | - HDMI_FC_DRM_PB10); |
|---|
| 2168 | | - hdmi_writeb(hdmi, HDR_MSB(frame.display_primaries[2].x), |
|---|
| 2169 | | - HDMI_FC_DRM_PB11); |
|---|
| 2170 | | - hdmi_writeb(hdmi, HDR_LSB(frame.display_primaries[2].y), |
|---|
| 2171 | | - HDMI_FC_DRM_PB12); |
|---|
| 2172 | | - hdmi_writeb(hdmi, HDR_MSB(frame.display_primaries[2].y), |
|---|
| 2173 | | - HDMI_FC_DRM_PB13); |
|---|
| 2174 | | - hdmi_writeb(hdmi, HDR_LSB(frame.white_point.x), HDMI_FC_DRM_PB14); |
|---|
| 2175 | | - hdmi_writeb(hdmi, HDR_MSB(frame.white_point.x), HDMI_FC_DRM_PB15); |
|---|
| 2176 | | - hdmi_writeb(hdmi, HDR_LSB(frame.white_point.y), HDMI_FC_DRM_PB16); |
|---|
| 2177 | | - hdmi_writeb(hdmi, HDR_MSB(frame.white_point.y), HDMI_FC_DRM_PB17); |
|---|
| 2178 | | - hdmi_writeb(hdmi, HDR_LSB(frame.max_display_mastering_luminance), |
|---|
| 2179 | | - HDMI_FC_DRM_PB18); |
|---|
| 2180 | | - hdmi_writeb(hdmi, HDR_MSB(frame.max_display_mastering_luminance), |
|---|
| 2181 | | - HDMI_FC_DRM_PB19); |
|---|
| 2182 | | - hdmi_writeb(hdmi, HDR_LSB(frame.min_display_mastering_luminance), |
|---|
| 2183 | | - HDMI_FC_DRM_PB20); |
|---|
| 2184 | | - hdmi_writeb(hdmi, HDR_MSB(frame.min_display_mastering_luminance), |
|---|
| 2185 | | - HDMI_FC_DRM_PB21); |
|---|
| 2186 | | - hdmi_writeb(hdmi, HDR_LSB(frame.max_cll), HDMI_FC_DRM_PB22); |
|---|
| 2187 | | - hdmi_writeb(hdmi, HDR_MSB(frame.max_cll), HDMI_FC_DRM_PB23); |
|---|
| 2188 | | - hdmi_writeb(hdmi, HDR_LSB(frame.max_fall), HDMI_FC_DRM_PB24); |
|---|
| 2189 | | - hdmi_writeb(hdmi, HDR_MSB(frame.max_fall), HDMI_FC_DRM_PB25); |
|---|
| 2190 | | - hdmi_writeb(hdmi, 1, HDMI_FC_DRM_UP); |
|---|
| 2191 | | - hdmi_modb(hdmi, HDMI_FC_PACKET_DRM_TX_EN, |
|---|
| 2192 | | - HDMI_FC_PACKET_DRM_TX_EN_MASK, HDMI_FC_PACKET_TX_EN); |
|---|
| 2193 | | - |
|---|
| 2194 | | - DRM_DEBUG("%s eotf %d end\n", __func__, |
|---|
| 2195 | | - hdr_metadata->hdmi_metadata_type1.eotf); |
|---|
| 2196 | | -} |
|---|
| 2197 | | - |
|---|
| 2198 | 2410 | static void hdmi_av_composer(struct dw_hdmi *hdmi, |
|---|
| 2411 | + const struct drm_display_info *display, |
|---|
| 2199 | 2412 | const struct drm_display_mode *mode) |
|---|
| 2200 | 2413 | { |
|---|
| 2201 | 2414 | u8 inv_val, bytes; |
|---|
| 2202 | | - struct drm_hdmi_info *hdmi_info = &hdmi->connector.display_info.hdmi; |
|---|
| 2415 | + const struct drm_hdmi_info *hdmi_info = &display->hdmi; |
|---|
| 2203 | 2416 | struct hdmi_vmode *vmode = &hdmi->hdmi_data.video_mode; |
|---|
| 2204 | 2417 | int hblank, vblank, h_de_hs, v_de_vs, hsync_len, vsync_len; |
|---|
| 2205 | 2418 | unsigned int vdisplay, hdisplay; |
|---|
| 2206 | 2419 | |
|---|
| 2207 | 2420 | vmode->previous_pixelclock = vmode->mpixelclock; |
|---|
| 2208 | 2421 | vmode->mpixelclock = mode->crtc_clock * 1000; |
|---|
| 2209 | | - if ((mode->flags & DRM_MODE_FLAG_3D_MASK) == |
|---|
| 2210 | | - DRM_MODE_FLAG_3D_FRAME_PACKING) |
|---|
| 2211 | | - vmode->mpixelclock *= 2; |
|---|
| 2212 | 2422 | dev_dbg(hdmi->dev, "final pixclk = %d\n", vmode->mpixelclock); |
|---|
| 2213 | 2423 | |
|---|
| 2214 | 2424 | vmode->previous_tmdsclock = vmode->mtmdsclock; |
|---|
| 2215 | 2425 | vmode->mtmdsclock = hdmi_get_tmdsclock(hdmi, vmode->mpixelclock); |
|---|
| 2216 | 2426 | if (hdmi_bus_fmt_is_yuv420(hdmi->hdmi_data.enc_out_bus_format)) |
|---|
| 2217 | 2427 | vmode->mtmdsclock /= 2; |
|---|
| 2428 | + dev_dbg(hdmi->dev, "final tmdsclock = %d\n", vmode->mtmdsclock); |
|---|
| 2429 | + |
|---|
| 2430 | + if (hdmi->update) |
|---|
| 2431 | + return; |
|---|
| 2218 | 2432 | |
|---|
| 2219 | 2433 | /* Set up HDMI_FC_INVIDCONF |
|---|
| 2220 | 2434 | * Some display equipments require that the interval |
|---|
| .. | .. |
|---|
| 2282 | 2496 | vblank /= 2; |
|---|
| 2283 | 2497 | v_de_vs /= 2; |
|---|
| 2284 | 2498 | vsync_len /= 2; |
|---|
| 2285 | | - } else if ((mode->flags & DRM_MODE_FLAG_3D_MASK) == |
|---|
| 2286 | | - DRM_MODE_FLAG_3D_FRAME_PACKING) { |
|---|
| 2287 | | - vdisplay += mode->vtotal; |
|---|
| 2288 | 2499 | } |
|---|
| 2289 | 2500 | |
|---|
| 2290 | 2501 | /* Scrambling Control */ |
|---|
| 2291 | | - if (dw_hdmi_support_scdc(hdmi)) { |
|---|
| 2502 | + if (dw_hdmi_support_scdc(hdmi, display)) { |
|---|
| 2292 | 2503 | if (vmode->mtmdsclock > HDMI14_MAX_TMDSCLK || |
|---|
| 2293 | 2504 | (hdmi_info->scdc.scrambling.low_rates && |
|---|
| 2294 | 2505 | hdmi->scramble_low_rates)) { |
|---|
| .. | .. |
|---|
| 2373 | 2584 | hdmi_writeb(hdmi, 0x21, HDMI_FC_CH2PREAM); |
|---|
| 2374 | 2585 | |
|---|
| 2375 | 2586 | /* Enable pixel clock and tmds data path */ |
|---|
| 2376 | | - hdmi->mc_clkdis |= HDMI_MC_CLKDIS_HDCPCLK_DISABLE | |
|---|
| 2377 | | - HDMI_MC_CLKDIS_CSCCLK_DISABLE | |
|---|
| 2378 | | - HDMI_MC_CLKDIS_AUDCLK_DISABLE | |
|---|
| 2379 | | - HDMI_MC_CLKDIS_PREPCLK_DISABLE | |
|---|
| 2380 | | - HDMI_MC_CLKDIS_TMDSCLK_DISABLE; |
|---|
| 2587 | + |
|---|
| 2588 | + if (!hdmi->update) |
|---|
| 2589 | + hdmi->mc_clkdis |= HDMI_MC_CLKDIS_HDCPCLK_DISABLE | |
|---|
| 2590 | + HDMI_MC_CLKDIS_CSCCLK_DISABLE | |
|---|
| 2591 | + HDMI_MC_CLKDIS_AUDCLK_DISABLE | |
|---|
| 2592 | + HDMI_MC_CLKDIS_PREPCLK_DISABLE | |
|---|
| 2593 | + HDMI_MC_CLKDIS_TMDSCLK_DISABLE; |
|---|
| 2381 | 2594 | hdmi->mc_clkdis &= ~HDMI_MC_CLKDIS_PIXELCLK_DISABLE; |
|---|
| 2382 | 2595 | hdmi_writeb(hdmi, hdmi->mc_clkdis, HDMI_MC_CLKDIS); |
|---|
| 2383 | 2596 | |
|---|
| 2384 | 2597 | hdmi->mc_clkdis &= ~HDMI_MC_CLKDIS_TMDSCLK_DISABLE; |
|---|
| 2385 | 2598 | hdmi_writeb(hdmi, hdmi->mc_clkdis, HDMI_MC_CLKDIS); |
|---|
| 2386 | | - |
|---|
| 2387 | | - /* Enable csc path */ |
|---|
| 2388 | | - if (is_color_space_conversion(hdmi)) { |
|---|
| 2389 | | - hdmi->mc_clkdis &= ~HDMI_MC_CLKDIS_CSCCLK_DISABLE; |
|---|
| 2390 | | - hdmi_writeb(hdmi, hdmi->mc_clkdis, HDMI_MC_CLKDIS); |
|---|
| 2391 | | - } |
|---|
| 2392 | 2599 | |
|---|
| 2393 | 2600 | /* Enable pixel repetition path */ |
|---|
| 2394 | 2601 | if (hdmi->hdmi_data.video_mode.mpixelrepetitioninput) { |
|---|
| .. | .. |
|---|
| 2396 | 2603 | hdmi_writeb(hdmi, hdmi->mc_clkdis, HDMI_MC_CLKDIS); |
|---|
| 2397 | 2604 | } |
|---|
| 2398 | 2605 | |
|---|
| 2399 | | - /* Enable color space conversion if needed */ |
|---|
| 2400 | | - if (is_color_space_conversion(hdmi)) |
|---|
| 2606 | + /* Enable csc path */ |
|---|
| 2607 | + if (is_csc_needed(hdmi)) { |
|---|
| 2608 | + hdmi->mc_clkdis &= ~HDMI_MC_CLKDIS_CSCCLK_DISABLE; |
|---|
| 2609 | + hdmi_writeb(hdmi, hdmi->mc_clkdis, HDMI_MC_CLKDIS); |
|---|
| 2610 | + |
|---|
| 2401 | 2611 | hdmi_writeb(hdmi, HDMI_MC_FLOWCTRL_FEED_THROUGH_OFF_CSC_IN_PATH, |
|---|
| 2402 | 2612 | HDMI_MC_FLOWCTRL); |
|---|
| 2403 | | - else |
|---|
| 2613 | + } else { |
|---|
| 2614 | + hdmi->mc_clkdis |= HDMI_MC_CLKDIS_CSCCLK_DISABLE; |
|---|
| 2615 | + hdmi_writeb(hdmi, hdmi->mc_clkdis, HDMI_MC_CLKDIS); |
|---|
| 2616 | + |
|---|
| 2404 | 2617 | hdmi_writeb(hdmi, HDMI_MC_FLOWCTRL_FEED_THROUGH_OFF_CSC_BYPASS, |
|---|
| 2405 | 2618 | HDMI_MC_FLOWCTRL); |
|---|
| 2619 | + } |
|---|
| 2406 | 2620 | } |
|---|
| 2407 | 2621 | |
|---|
| 2408 | 2622 | /* Workaround to clear the overflow condition */ |
|---|
| .. | .. |
|---|
| 2425 | 2639 | * iteration for others. |
|---|
| 2426 | 2640 | * The Amlogic Meson GX SoCs (v2.01a) have been identified as needing |
|---|
| 2427 | 2641 | * the workaround with a single iteration. |
|---|
| 2642 | + * The Rockchip RK3288 SoC (v2.00a) and RK3328/RK3399 SoCs (v2.11a) have |
|---|
| 2643 | + * been identified as needing the workaround with a single iteration. |
|---|
| 2428 | 2644 | */ |
|---|
| 2429 | 2645 | |
|---|
| 2430 | 2646 | switch (hdmi->version) { |
|---|
| .. | .. |
|---|
| 2432 | 2648 | count = 4; |
|---|
| 2433 | 2649 | break; |
|---|
| 2434 | 2650 | case 0x131a: |
|---|
| 2651 | + case 0x132a: |
|---|
| 2435 | 2652 | case 0x200a: |
|---|
| 2436 | 2653 | case 0x201a: |
|---|
| 2437 | 2654 | case 0x211a: |
|---|
| 2655 | + case 0x212a: |
|---|
| 2438 | 2656 | count = 1; |
|---|
| 2439 | 2657 | break; |
|---|
| 2440 | 2658 | default: |
|---|
| .. | .. |
|---|
| 2455 | 2673 | HDMI_IH_MUTE_FC_STAT2); |
|---|
| 2456 | 2674 | } |
|---|
| 2457 | 2675 | |
|---|
| 2458 | | -static int dw_hdmi_setup(struct dw_hdmi *hdmi, struct drm_display_mode *mode) |
|---|
| 2676 | +static void dw_hdmi_force_output_pattern(struct dw_hdmi *hdmi, const struct drm_display_mode *mode) |
|---|
| 2677 | +{ |
|---|
| 2678 | + /* force output black */ |
|---|
| 2679 | + if (hdmi_bus_fmt_is_rgb(hdmi->hdmi_data.enc_out_bus_format)) { |
|---|
| 2680 | + enum hdmi_quantization_range rgb_quant_range = drm_default_rgb_quant_range(mode); |
|---|
| 2681 | + |
|---|
| 2682 | + if (hdmi->hdmi_data.quant_range == HDMI_QUANTIZATION_RANGE_FULL) { |
|---|
| 2683 | + hdmi_writeb(hdmi, 0x00, HDMI_FC_DBGTMDS2); /*R*/ |
|---|
| 2684 | + hdmi_writeb(hdmi, 0x00, HDMI_FC_DBGTMDS1); /*G*/ |
|---|
| 2685 | + hdmi_writeb(hdmi, 0x00, HDMI_FC_DBGTMDS0); /*B*/ |
|---|
| 2686 | + } else if (hdmi->hdmi_data.quant_range == HDMI_QUANTIZATION_RANGE_LIMITED) { |
|---|
| 2687 | + hdmi_writeb(hdmi, 0x10, HDMI_FC_DBGTMDS2); /*R*/ |
|---|
| 2688 | + hdmi_writeb(hdmi, 0x10, HDMI_FC_DBGTMDS1); /*G*/ |
|---|
| 2689 | + hdmi_writeb(hdmi, 0x10, HDMI_FC_DBGTMDS0); /*B*/ |
|---|
| 2690 | + } else if (hdmi->hdmi_data.quant_range == HDMI_QUANTIZATION_RANGE_DEFAULT) { |
|---|
| 2691 | + if (rgb_quant_range == HDMI_QUANTIZATION_RANGE_FULL) { |
|---|
| 2692 | + hdmi_writeb(hdmi, 0x00, HDMI_FC_DBGTMDS2); /*R*/ |
|---|
| 2693 | + hdmi_writeb(hdmi, 0x00, HDMI_FC_DBGTMDS1); /*G*/ |
|---|
| 2694 | + hdmi_writeb(hdmi, 0x00, HDMI_FC_DBGTMDS0); /*B*/ |
|---|
| 2695 | + } else if (rgb_quant_range == HDMI_QUANTIZATION_RANGE_LIMITED) { |
|---|
| 2696 | + hdmi_writeb(hdmi, 0x10, HDMI_FC_DBGTMDS2); /*R*/ |
|---|
| 2697 | + hdmi_writeb(hdmi, 0x10, HDMI_FC_DBGTMDS1); /*G*/ |
|---|
| 2698 | + hdmi_writeb(hdmi, 0x10, HDMI_FC_DBGTMDS0); /*B*/ |
|---|
| 2699 | + } |
|---|
| 2700 | + } |
|---|
| 2701 | + } else { |
|---|
| 2702 | + hdmi_writeb(hdmi, 0x80, HDMI_FC_DBGTMDS2); /*Cr*/ |
|---|
| 2703 | + hdmi_writeb(hdmi, 0x10, HDMI_FC_DBGTMDS1); /*Y*/ |
|---|
| 2704 | + hdmi_writeb(hdmi, 0x80, HDMI_FC_DBGTMDS0); /*Cb*/ |
|---|
| 2705 | + } |
|---|
| 2706 | +} |
|---|
| 2707 | + |
|---|
| 2708 | +static int dw_hdmi_setup(struct dw_hdmi *hdmi, |
|---|
| 2709 | + const struct drm_connector *connector, |
|---|
| 2710 | + const struct drm_display_mode *mode) |
|---|
| 2459 | 2711 | { |
|---|
| 2460 | 2712 | int ret; |
|---|
| 2461 | 2713 | void *data = hdmi->plat_data->phy_data; |
|---|
| 2462 | | - bool need_delay = false; |
|---|
| 2463 | 2714 | |
|---|
| 2464 | 2715 | hdmi_disable_overflow_interrupts(hdmi); |
|---|
| 2465 | 2716 | |
|---|
| .. | .. |
|---|
| 2508 | 2759 | hdmi->hdmi_data.enc_out_bus_format = |
|---|
| 2509 | 2760 | MEDIA_BUS_FMT_RGB888_1X24; |
|---|
| 2510 | 2761 | |
|---|
| 2762 | + if (hdmi->plat_data->set_prev_bus_format) |
|---|
| 2763 | + hdmi->plat_data->set_prev_bus_format(data, hdmi->hdmi_data.enc_out_bus_format); |
|---|
| 2764 | + |
|---|
| 2511 | 2765 | /* TOFIX: Get input encoding from plat data or fallback to none */ |
|---|
| 2512 | 2766 | if (hdmi->plat_data->get_enc_in_encoding) |
|---|
| 2513 | 2767 | hdmi->hdmi_data.enc_in_encoding = |
|---|
| .. | .. |
|---|
| 2518 | 2772 | else |
|---|
| 2519 | 2773 | hdmi->hdmi_data.enc_in_encoding = V4L2_YCBCR_ENC_DEFAULT; |
|---|
| 2520 | 2774 | |
|---|
| 2775 | + |
|---|
| 2521 | 2776 | if (hdmi->plat_data->get_quant_range) |
|---|
| 2522 | 2777 | hdmi->hdmi_data.quant_range = |
|---|
| 2523 | 2778 | hdmi->plat_data->get_quant_range(data); |
|---|
| 2524 | | - else |
|---|
| 2525 | | - hdmi->hdmi_data.quant_range = HDMI_QUANTIZATION_RANGE_DEFAULT; |
|---|
| 2779 | + |
|---|
| 2780 | + hdmi->hdmi_data.rgb_limited_range = hdmi->sink_is_hdmi && |
|---|
| 2781 | + drm_default_rgb_quant_range(mode) == |
|---|
| 2782 | + HDMI_QUANTIZATION_RANGE_LIMITED; |
|---|
| 2526 | 2783 | |
|---|
| 2527 | 2784 | if (!hdmi->sink_is_hdmi) |
|---|
| 2528 | 2785 | hdmi->hdmi_data.quant_range = HDMI_QUANTIZATION_RANGE_FULL; |
|---|
| .. | .. |
|---|
| 2537 | 2794 | (mode->flags & DRM_MODE_FLAG_DBLCLK) ? 1 : 0; |
|---|
| 2538 | 2795 | hdmi->hdmi_data.video_mode.mdataenablepolarity = true; |
|---|
| 2539 | 2796 | |
|---|
| 2540 | | - /* HDMI Initialization Step B.1 */ |
|---|
| 2541 | | - hdmi_av_composer(hdmi, mode); |
|---|
| 2797 | + dw_hdmi_force_output_pattern(hdmi, mode); |
|---|
| 2542 | 2798 | |
|---|
| 2543 | | - /* HDMI Initializateion Step B.2 */ |
|---|
| 2544 | | - if (!hdmi->phy.enabled || |
|---|
| 2545 | | - hdmi->hdmi_data.video_mode.previous_pixelclock != |
|---|
| 2546 | | - hdmi->hdmi_data.video_mode.mpixelclock || |
|---|
| 2547 | | - hdmi->hdmi_data.video_mode.previous_tmdsclock != |
|---|
| 2548 | | - hdmi->hdmi_data.video_mode.mtmdsclock) { |
|---|
| 2549 | | - ret = hdmi->phy.ops->init(hdmi, hdmi->phy.data, |
|---|
| 2550 | | - &hdmi->previous_mode); |
|---|
| 2551 | | - if (ret) |
|---|
| 2552 | | - return ret; |
|---|
| 2553 | | - hdmi->phy.enabled = true; |
|---|
| 2554 | | - } else { |
|---|
| 2555 | | - need_delay = true; |
|---|
| 2556 | | - } |
|---|
| 2799 | + /* HDMI Initialization Step B.1 */ |
|---|
| 2800 | + hdmi_av_composer(hdmi, &connector->display_info, mode); |
|---|
| 2801 | + |
|---|
| 2557 | 2802 | /* HDMI Initialization Step B.3 */ |
|---|
| 2558 | 2803 | dw_hdmi_enable_video_path(hdmi); |
|---|
| 2559 | 2804 | |
|---|
| .. | .. |
|---|
| 2570 | 2815 | dev_dbg(hdmi->dev, "%s HDMI mode\n", __func__); |
|---|
| 2571 | 2816 | |
|---|
| 2572 | 2817 | /* HDMI Initialization Step F - Configure AVI InfoFrame */ |
|---|
| 2573 | | - hdmi_config_AVI(hdmi, mode); |
|---|
| 2574 | | - hdmi_config_vendor_specific_infoframe(hdmi, mode); |
|---|
| 2575 | | - hdmi_config_hdr_infoframe(hdmi); |
|---|
| 2818 | + hdmi_config_AVI(hdmi, connector, mode); |
|---|
| 2819 | + hdmi_config_vendor_specific_infoframe(hdmi, connector, mode); |
|---|
| 2820 | + hdmi_config_drm_infoframe(hdmi, connector); |
|---|
| 2576 | 2821 | } else { |
|---|
| 2577 | 2822 | dev_dbg(hdmi->dev, "%s DVI mode\n", __func__); |
|---|
| 2578 | 2823 | } |
|---|
| .. | .. |
|---|
| 2582 | 2827 | hdmi_video_sample(hdmi); |
|---|
| 2583 | 2828 | hdmi_tx_hdcp_config(hdmi, mode); |
|---|
| 2584 | 2829 | |
|---|
| 2830 | + /* HDMI Enable phy output */ |
|---|
| 2831 | + if (!hdmi->phy.enabled || |
|---|
| 2832 | + hdmi->hdmi_data.video_mode.previous_pixelclock != |
|---|
| 2833 | + hdmi->hdmi_data.video_mode.mpixelclock || |
|---|
| 2834 | + hdmi->hdmi_data.video_mode.previous_tmdsclock != |
|---|
| 2835 | + hdmi->hdmi_data.video_mode.mtmdsclock) { |
|---|
| 2836 | + ret = hdmi->phy.ops->init(hdmi, hdmi->phy.data, |
|---|
| 2837 | + &connector->display_info, |
|---|
| 2838 | + &hdmi->previous_mode); |
|---|
| 2839 | + if (ret) |
|---|
| 2840 | + return ret; |
|---|
| 2841 | + hdmi->phy.enabled = true; |
|---|
| 2842 | + } |
|---|
| 2843 | + |
|---|
| 2585 | 2844 | dw_hdmi_clear_overflow(hdmi); |
|---|
| 2586 | 2845 | |
|---|
| 2587 | | - /* XXX: Add delay to make csc work before unmute video. */ |
|---|
| 2588 | | - if (need_delay) |
|---|
| 2846 | + /* |
|---|
| 2847 | + * konka tv should switch pattern after set to yuv420 10bit or |
|---|
| 2848 | + * the TV might not recognize the signal. |
|---|
| 2849 | + */ |
|---|
| 2850 | + if (!hdmi->update) { |
|---|
| 2851 | + hdmi_writeb(hdmi, 1, HDMI_FC_DBGFORCE); |
|---|
| 2589 | 2852 | msleep(50); |
|---|
| 2853 | + hdmi_writeb(hdmi, 0, HDMI_FC_DBGFORCE); |
|---|
| 2854 | + } |
|---|
| 2855 | + |
|---|
| 2590 | 2856 | return 0; |
|---|
| 2591 | | -} |
|---|
| 2592 | | - |
|---|
| 2593 | | -static void dw_hdmi_setup_i2c(struct dw_hdmi *hdmi) |
|---|
| 2594 | | -{ |
|---|
| 2595 | | - hdmi_writeb(hdmi, HDMI_PHY_I2CM_INT_ADDR_DONE_POL, |
|---|
| 2596 | | - HDMI_PHY_I2CM_INT_ADDR); |
|---|
| 2597 | | - |
|---|
| 2598 | | - hdmi_writeb(hdmi, HDMI_PHY_I2CM_CTLINT_ADDR_NAC_POL | |
|---|
| 2599 | | - HDMI_PHY_I2CM_CTLINT_ADDR_ARBITRATION_POL, |
|---|
| 2600 | | - HDMI_PHY_I2CM_CTLINT_ADDR); |
|---|
| 2601 | 2857 | } |
|---|
| 2602 | 2858 | |
|---|
| 2603 | 2859 | static void initialize_hdmi_ih_mutes(struct dw_hdmi *hdmi) |
|---|
| .. | .. |
|---|
| 2654 | 2910 | static void dw_hdmi_poweron(struct dw_hdmi *hdmi) |
|---|
| 2655 | 2911 | { |
|---|
| 2656 | 2912 | hdmi->bridge_is_on = true; |
|---|
| 2657 | | - dw_hdmi_setup(hdmi, &hdmi->previous_mode); |
|---|
| 2913 | + |
|---|
| 2914 | + /* |
|---|
| 2915 | + * The curr_conn field is guaranteed to be valid here, as this function |
|---|
| 2916 | + * is only be called when !hdmi->disabled. |
|---|
| 2917 | + */ |
|---|
| 2918 | + dw_hdmi_setup(hdmi, hdmi->curr_conn, &hdmi->previous_mode); |
|---|
| 2658 | 2919 | } |
|---|
| 2659 | 2920 | |
|---|
| 2660 | 2921 | static void dw_hdmi_poweroff(struct dw_hdmi *hdmi) |
|---|
| .. | .. |
|---|
| 2686 | 2947 | if (hdmi->initialized) { |
|---|
| 2687 | 2948 | hdmi->initialized = false; |
|---|
| 2688 | 2949 | hdmi->disabled = true; |
|---|
| 2950 | + hdmi->logo_plug_out = true; |
|---|
| 2689 | 2951 | } |
|---|
| 2690 | 2952 | if (hdmi->bridge_is_on) |
|---|
| 2691 | 2953 | dw_hdmi_poweroff(hdmi); |
|---|
| .. | .. |
|---|
| 2715 | 2977 | hdmi->rxsense); |
|---|
| 2716 | 2978 | } |
|---|
| 2717 | 2979 | |
|---|
| 2718 | | -static enum drm_connector_status |
|---|
| 2719 | | -dw_hdmi_connector_detect(struct drm_connector *connector, bool force) |
|---|
| 2980 | +static enum drm_connector_status dw_hdmi_detect(struct dw_hdmi *hdmi) |
|---|
| 2720 | 2981 | { |
|---|
| 2721 | | - struct dw_hdmi *hdmi = container_of(connector, struct dw_hdmi, |
|---|
| 2722 | | - connector); |
|---|
| 2723 | 2982 | enum drm_connector_status result; |
|---|
| 2724 | 2983 | |
|---|
| 2725 | 2984 | if (!hdmi->force_logo) { |
|---|
| .. | .. |
|---|
| 2731 | 2990 | } |
|---|
| 2732 | 2991 | |
|---|
| 2733 | 2992 | result = hdmi->phy.ops->read_hpd(hdmi, hdmi->phy.data); |
|---|
| 2993 | + mutex_lock(&hdmi->mutex); |
|---|
| 2994 | + if (result != hdmi->last_connector_result) { |
|---|
| 2995 | + dev_dbg(hdmi->dev, "read_hpd result: %d", result); |
|---|
| 2996 | + handle_plugged_change(hdmi, |
|---|
| 2997 | + result == connector_status_connected); |
|---|
| 2998 | + hdmi->last_connector_result = result; |
|---|
| 2999 | + } |
|---|
| 3000 | + mutex_unlock(&hdmi->mutex); |
|---|
| 3001 | + |
|---|
| 2734 | 3002 | if (result == connector_status_connected) |
|---|
| 2735 | 3003 | extcon_set_state_sync(hdmi->extcon, EXTCON_DISP_HDMI, true); |
|---|
| 2736 | 3004 | else |
|---|
| 2737 | 3005 | extcon_set_state_sync(hdmi->extcon, EXTCON_DISP_HDMI, false); |
|---|
| 2738 | 3006 | |
|---|
| 2739 | | - mutex_lock(&hdmi->mutex); |
|---|
| 2740 | | - if (result != hdmi->last_connector_result) { |
|---|
| 2741 | | - dev_dbg(hdmi->dev, "read_hpd result: %d", result); |
|---|
| 2742 | | - handle_plugged_change(hdmi, |
|---|
| 2743 | | - result == connector_status_connected); |
|---|
| 2744 | | - hdmi->last_connector_result = result; |
|---|
| 2745 | | - } |
|---|
| 2746 | | - mutex_unlock(&hdmi->mutex); |
|---|
| 2747 | 3007 | return result; |
|---|
| 3008 | +} |
|---|
| 3009 | + |
|---|
| 3010 | +static struct edid *dw_hdmi_get_edid(struct dw_hdmi *hdmi, |
|---|
| 3011 | + struct drm_connector *connector) |
|---|
| 3012 | +{ |
|---|
| 3013 | + struct edid *edid; |
|---|
| 3014 | + |
|---|
| 3015 | + if (!hdmi->ddc) |
|---|
| 3016 | + return NULL; |
|---|
| 3017 | + |
|---|
| 3018 | + edid = drm_get_edid(connector, hdmi->ddc); |
|---|
| 3019 | + if (!edid) { |
|---|
| 3020 | + dev_dbg(hdmi->dev, "failed to get edid\n"); |
|---|
| 3021 | + return NULL; |
|---|
| 3022 | + } |
|---|
| 3023 | + |
|---|
| 3024 | + dev_dbg(hdmi->dev, "got edid: width[%d] x height[%d]\n", |
|---|
| 3025 | + edid->width_cm, edid->height_cm); |
|---|
| 3026 | + |
|---|
| 3027 | + hdmi->support_hdmi = drm_detect_hdmi_monitor(edid); |
|---|
| 3028 | + hdmi->sink_has_audio = drm_detect_monitor_audio(edid); |
|---|
| 3029 | + |
|---|
| 3030 | + return edid; |
|---|
| 3031 | +} |
|---|
| 3032 | + |
|---|
| 3033 | +/* ----------------------------------------------------------------------------- |
|---|
| 3034 | + * DRM Connector Operations |
|---|
| 3035 | + */ |
|---|
| 3036 | + |
|---|
| 3037 | +static enum drm_connector_status |
|---|
| 3038 | +dw_hdmi_connector_detect(struct drm_connector *connector, bool force) |
|---|
| 3039 | +{ |
|---|
| 3040 | + struct dw_hdmi *hdmi = container_of(connector, struct dw_hdmi, |
|---|
| 3041 | + connector); |
|---|
| 3042 | + return dw_hdmi_detect(hdmi); |
|---|
| 2748 | 3043 | } |
|---|
| 2749 | 3044 | |
|---|
| 2750 | 3045 | static int |
|---|
| .. | .. |
|---|
| 2785 | 3080 | struct edid *edid; |
|---|
| 2786 | 3081 | struct drm_display_mode *mode; |
|---|
| 2787 | 3082 | struct drm_display_info *info = &connector->display_info; |
|---|
| 2788 | | - int i, ret = 0; |
|---|
| 3083 | + void *data = hdmi->plat_data->phy_data; |
|---|
| 3084 | + int i, ret = 0; |
|---|
| 2789 | 3085 | |
|---|
| 2790 | 3086 | memset(metedata, 0, sizeof(*metedata)); |
|---|
| 2791 | | - if (!hdmi->ddc) |
|---|
| 2792 | | - return 0; |
|---|
| 2793 | | - |
|---|
| 2794 | | - edid = drm_get_edid(connector, hdmi->ddc); |
|---|
| 3087 | + edid = dw_hdmi_get_edid(hdmi, connector); |
|---|
| 2795 | 3088 | if (edid) { |
|---|
| 3089 | + int vic = 0; |
|---|
| 3090 | + |
|---|
| 2796 | 3091 | dev_dbg(hdmi->dev, "got edid: width[%d] x height[%d]\n", |
|---|
| 2797 | 3092 | edid->width_cm, edid->height_cm); |
|---|
| 2798 | | - |
|---|
| 2799 | | - hdmi->support_hdmi = drm_detect_hdmi_monitor(edid); |
|---|
| 2800 | | - hdmi->sink_has_audio = drm_detect_monitor_audio(edid); |
|---|
| 2801 | | - hdmi->rgb_quant_range_selectable = drm_rgb_quant_range_selectable(edid); |
|---|
| 2802 | 3093 | drm_connector_update_edid_property(connector, edid); |
|---|
| 2803 | 3094 | cec_notifier_set_phys_addr_from_edid(hdmi->cec_notifier, edid); |
|---|
| 2804 | 3095 | ret = drm_add_edid_modes(connector, edid); |
|---|
| 2805 | | - dw_hdmi_update_hdr_property(connector); |
|---|
| 3096 | + if (hdmi->plat_data->get_color_changed) |
|---|
| 3097 | + hdmi->plat_data->get_yuv422_format(connector, edid); |
|---|
| 3098 | + if (hdmi->plat_data->get_colorimetry) |
|---|
| 3099 | + hdmi->plat_data->get_colorimetry(data, edid); |
|---|
| 3100 | + |
|---|
| 3101 | + list_for_each_entry(mode, &connector->probed_modes, head) { |
|---|
| 3102 | + vic = drm_match_cea_mode(mode); |
|---|
| 3103 | + |
|---|
| 3104 | + if (mode->picture_aspect_ratio == HDMI_PICTURE_ASPECT_NONE) { |
|---|
| 3105 | + if (vic >= 93 && vic <= 95) |
|---|
| 3106 | + mode->picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9; |
|---|
| 3107 | + else if (vic == 98) |
|---|
| 3108 | + mode->picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135; |
|---|
| 3109 | + } |
|---|
| 3110 | + } |
|---|
| 3111 | + |
|---|
| 2806 | 3112 | kfree(edid); |
|---|
| 2807 | 3113 | } else { |
|---|
| 2808 | 3114 | hdmi->support_hdmi = true; |
|---|
| 2809 | 3115 | hdmi->sink_has_audio = true; |
|---|
| 2810 | | - hdmi->rgb_quant_range_selectable = false; |
|---|
| 2811 | | - |
|---|
| 2812 | 3116 | for (i = 0; i < ARRAY_SIZE(dw_hdmi_default_modes); i++) { |
|---|
| 2813 | 3117 | const struct drm_display_mode *ptr = |
|---|
| 2814 | 3118 | &dw_hdmi_default_modes[i]; |
|---|
| 2815 | 3119 | |
|---|
| 2816 | 3120 | mode = drm_mode_duplicate(connector->dev, ptr); |
|---|
| 2817 | 3121 | if (mode) { |
|---|
| 2818 | | - if (!i) { |
|---|
| 3122 | + if (!i) |
|---|
| 2819 | 3123 | mode->type = DRM_MODE_TYPE_PREFERRED; |
|---|
| 2820 | | - mode->picture_aspect_ratio = |
|---|
| 2821 | | - HDMI_PICTURE_ASPECT_NONE; |
|---|
| 2822 | | - } |
|---|
| 2823 | 3124 | drm_mode_probed_add(connector, mode); |
|---|
| 2824 | 3125 | ret++; |
|---|
| 2825 | 3126 | } |
|---|
| .. | .. |
|---|
| 2830 | 3131 | |
|---|
| 2831 | 3132 | dev_info(hdmi->dev, "failed to get edid\n"); |
|---|
| 2832 | 3133 | } |
|---|
| 3134 | + dw_hdmi_update_hdr_property(connector); |
|---|
| 2833 | 3135 | dw_hdmi_check_output_type_changed(hdmi); |
|---|
| 2834 | 3136 | |
|---|
| 2835 | 3137 | return ret; |
|---|
| 3138 | +} |
|---|
| 3139 | + |
|---|
| 3140 | +static struct drm_encoder * |
|---|
| 3141 | +dw_hdmi_connector_best_encoder(struct drm_connector *connector) |
|---|
| 3142 | +{ |
|---|
| 3143 | + struct dw_hdmi *hdmi = container_of(connector, struct dw_hdmi, |
|---|
| 3144 | + connector); |
|---|
| 3145 | + |
|---|
| 3146 | + return hdmi->bridge.encoder; |
|---|
| 3147 | +} |
|---|
| 3148 | + |
|---|
| 3149 | +static bool dw_hdmi_color_changed(struct drm_connector *connector) |
|---|
| 3150 | +{ |
|---|
| 3151 | + struct dw_hdmi *hdmi = container_of(connector, struct dw_hdmi, |
|---|
| 3152 | + connector); |
|---|
| 3153 | + void *data = hdmi->plat_data->phy_data; |
|---|
| 3154 | + bool ret = false; |
|---|
| 3155 | + |
|---|
| 3156 | + if (hdmi->plat_data->get_color_changed) |
|---|
| 3157 | + ret = hdmi->plat_data->get_color_changed(data); |
|---|
| 3158 | + |
|---|
| 3159 | + return ret; |
|---|
| 3160 | +} |
|---|
| 3161 | + |
|---|
| 3162 | +static bool hdr_metadata_equal(struct dw_hdmi *hdmi, const struct drm_connector_state *old_state, |
|---|
| 3163 | + const struct drm_connector_state *new_state) |
|---|
| 3164 | +{ |
|---|
| 3165 | + struct drm_property_blob *old_blob = old_state->hdr_output_metadata; |
|---|
| 3166 | + struct drm_property_blob *new_blob = new_state->hdr_output_metadata; |
|---|
| 3167 | + int i, ret; |
|---|
| 3168 | + u8 *data; |
|---|
| 3169 | + |
|---|
| 3170 | + hdmi->hdr2sdr = false; |
|---|
| 3171 | + |
|---|
| 3172 | + if (!old_blob && !new_blob) |
|---|
| 3173 | + return true; |
|---|
| 3174 | + |
|---|
| 3175 | + if (!old_blob) { |
|---|
| 3176 | + data = (u8 *)new_blob->data; |
|---|
| 3177 | + |
|---|
| 3178 | + for (i = 0; i < new_blob->length; i++) |
|---|
| 3179 | + if (data[i]) |
|---|
| 3180 | + return false; |
|---|
| 3181 | + |
|---|
| 3182 | + return true; |
|---|
| 3183 | + } |
|---|
| 3184 | + |
|---|
| 3185 | + if (!new_blob) { |
|---|
| 3186 | + data = (u8 *)old_blob->data; |
|---|
| 3187 | + |
|---|
| 3188 | + for (i = 0; i < old_blob->length; i++) |
|---|
| 3189 | + if (data[i]) |
|---|
| 3190 | + return false; |
|---|
| 3191 | + |
|---|
| 3192 | + return true; |
|---|
| 3193 | + } |
|---|
| 3194 | + |
|---|
| 3195 | + if (old_blob->length != new_blob->length) |
|---|
| 3196 | + return false; |
|---|
| 3197 | + |
|---|
| 3198 | + ret = !memcmp(old_blob->data, new_blob->data, old_blob->length); |
|---|
| 3199 | + |
|---|
| 3200 | + if (!ret && new_blob) { |
|---|
| 3201 | + data = (u8 *)new_blob->data; |
|---|
| 3202 | + |
|---|
| 3203 | + for (i = 0; i < new_blob->length; i++) |
|---|
| 3204 | + if (data[i]) |
|---|
| 3205 | + break; |
|---|
| 3206 | + |
|---|
| 3207 | + if (i == new_blob->length) |
|---|
| 3208 | + hdmi->hdr2sdr = true; |
|---|
| 3209 | + } |
|---|
| 3210 | + |
|---|
| 3211 | + return ret; |
|---|
| 3212 | +} |
|---|
| 3213 | + |
|---|
| 3214 | +static bool check_hdr_color_change(struct drm_connector_state *old_state, |
|---|
| 3215 | + struct drm_connector_state *new_state, |
|---|
| 3216 | + struct dw_hdmi *hdmi) |
|---|
| 3217 | +{ |
|---|
| 3218 | + void *data = hdmi->plat_data->phy_data; |
|---|
| 3219 | + |
|---|
| 3220 | + if (!hdr_metadata_equal(hdmi, old_state, new_state)) { |
|---|
| 3221 | + hdmi->plat_data->check_hdr_color_change(new_state, data); |
|---|
| 3222 | + return true; |
|---|
| 3223 | + } |
|---|
| 3224 | + |
|---|
| 3225 | + return false; |
|---|
| 3226 | +} |
|---|
| 3227 | + |
|---|
| 3228 | +static int dw_hdmi_connector_atomic_check(struct drm_connector *connector, |
|---|
| 3229 | + struct drm_atomic_state *state) |
|---|
| 3230 | +{ |
|---|
| 3231 | + struct drm_connector_state *old_state = |
|---|
| 3232 | + drm_atomic_get_old_connector_state(state, connector); |
|---|
| 3233 | + struct drm_connector_state *new_state = |
|---|
| 3234 | + drm_atomic_get_new_connector_state(state, connector); |
|---|
| 3235 | + struct drm_crtc *crtc = new_state->crtc; |
|---|
| 3236 | + struct drm_crtc_state *crtc_state; |
|---|
| 3237 | + struct dw_hdmi *hdmi = container_of(connector, struct dw_hdmi, |
|---|
| 3238 | + connector); |
|---|
| 3239 | + struct drm_display_mode *mode = NULL; |
|---|
| 3240 | + void *data = hdmi->plat_data->phy_data; |
|---|
| 3241 | + struct hdmi_vmode *vmode = &hdmi->hdmi_data.video_mode; |
|---|
| 3242 | + |
|---|
| 3243 | + if (!crtc) |
|---|
| 3244 | + return 0; |
|---|
| 3245 | + |
|---|
| 3246 | + crtc_state = drm_atomic_get_crtc_state(state, crtc); |
|---|
| 3247 | + if (IS_ERR(crtc_state)) |
|---|
| 3248 | + return PTR_ERR(crtc_state); |
|---|
| 3249 | + |
|---|
| 3250 | + mode = &crtc_state->mode; |
|---|
| 3251 | + |
|---|
| 3252 | + /* |
|---|
| 3253 | + * If HDMI is enabled in uboot, it's need to record |
|---|
| 3254 | + * drm_display_mode and set phy status to enabled. |
|---|
| 3255 | + */ |
|---|
| 3256 | + if (!vmode->mpixelclock) { |
|---|
| 3257 | + u8 val; |
|---|
| 3258 | + |
|---|
| 3259 | + hdmi->curr_conn = connector; |
|---|
| 3260 | + |
|---|
| 3261 | + if (hdmi->plat_data->get_enc_in_encoding) |
|---|
| 3262 | + hdmi->hdmi_data.enc_in_encoding = |
|---|
| 3263 | + hdmi->plat_data->get_enc_in_encoding(data); |
|---|
| 3264 | + if (hdmi->plat_data->get_enc_out_encoding) |
|---|
| 3265 | + hdmi->hdmi_data.enc_out_encoding = |
|---|
| 3266 | + hdmi->plat_data->get_enc_out_encoding(data); |
|---|
| 3267 | + if (hdmi->plat_data->get_input_bus_format) |
|---|
| 3268 | + hdmi->hdmi_data.enc_in_bus_format = |
|---|
| 3269 | + hdmi->plat_data->get_input_bus_format(data); |
|---|
| 3270 | + if (hdmi->plat_data->get_output_bus_format) |
|---|
| 3271 | + hdmi->hdmi_data.enc_out_bus_format = |
|---|
| 3272 | + hdmi->plat_data->get_output_bus_format(data); |
|---|
| 3273 | + |
|---|
| 3274 | + memcpy(&hdmi->previous_mode, mode, sizeof(hdmi->previous_mode)); |
|---|
| 3275 | + vmode->mpixelclock = mode->crtc_clock * 1000; |
|---|
| 3276 | + vmode->previous_pixelclock = mode->clock * 1000; |
|---|
| 3277 | + vmode->previous_tmdsclock = mode->clock * 1000; |
|---|
| 3278 | + vmode->mtmdsclock = hdmi_get_tmdsclock(hdmi, |
|---|
| 3279 | + vmode->mpixelclock); |
|---|
| 3280 | + if (hdmi_bus_fmt_is_yuv420(hdmi->hdmi_data.enc_out_bus_format)) |
|---|
| 3281 | + vmode->mtmdsclock /= 2; |
|---|
| 3282 | + |
|---|
| 3283 | + dw_hdmi_force_output_pattern(hdmi, mode); |
|---|
| 3284 | + drm_scdc_readb(hdmi->ddc, SCDC_TMDS_CONFIG, &val); |
|---|
| 3285 | + |
|---|
| 3286 | + /* if plug out before hdmi bind, reset hdmi */ |
|---|
| 3287 | + if (vmode->mtmdsclock >= 340000000 && !(val & SCDC_TMDS_BIT_CLOCK_RATIO_BY_40)) |
|---|
| 3288 | + hdmi->logo_plug_out = true; |
|---|
| 3289 | + } |
|---|
| 3290 | + |
|---|
| 3291 | + if (check_hdr_color_change(old_state, new_state, hdmi) || hdmi->logo_plug_out || |
|---|
| 3292 | + dw_hdmi_color_changed(connector)) { |
|---|
| 3293 | + u32 mtmdsclk; |
|---|
| 3294 | + |
|---|
| 3295 | + if (hdmi->plat_data->update_color_format) |
|---|
| 3296 | + hdmi->plat_data->update_color_format(new_state, data); |
|---|
| 3297 | + if (hdmi->plat_data->get_enc_in_encoding) |
|---|
| 3298 | + hdmi->hdmi_data.enc_in_encoding = |
|---|
| 3299 | + hdmi->plat_data->get_enc_in_encoding(data); |
|---|
| 3300 | + if (hdmi->plat_data->get_enc_out_encoding) |
|---|
| 3301 | + hdmi->hdmi_data.enc_out_encoding = |
|---|
| 3302 | + hdmi->plat_data->get_enc_out_encoding(data); |
|---|
| 3303 | + if (hdmi->plat_data->get_input_bus_format) |
|---|
| 3304 | + hdmi->hdmi_data.enc_in_bus_format = |
|---|
| 3305 | + hdmi->plat_data->get_input_bus_format(data); |
|---|
| 3306 | + if (hdmi->plat_data->get_output_bus_format) |
|---|
| 3307 | + hdmi->hdmi_data.enc_out_bus_format = |
|---|
| 3308 | + hdmi->plat_data->get_output_bus_format(data); |
|---|
| 3309 | + |
|---|
| 3310 | + mtmdsclk = hdmi_get_tmdsclock(hdmi, mode->clock); |
|---|
| 3311 | + |
|---|
| 3312 | + if (hdmi_bus_fmt_is_yuv420(hdmi->hdmi_data.enc_out_bus_format)) |
|---|
| 3313 | + mtmdsclk /= 2; |
|---|
| 3314 | + |
|---|
| 3315 | + if (!(hdmi_readb(hdmi, HDMI_PHY_STAT0) & HDMI_PHY_HPD)) |
|---|
| 3316 | + return 0; |
|---|
| 3317 | + |
|---|
| 3318 | + if (hdmi->hdmi_data.video_mode.mpixelclock == (mode->clock * 1000) && |
|---|
| 3319 | + hdmi->hdmi_data.video_mode.mtmdsclock == (mtmdsclk * 1000) && |
|---|
| 3320 | + !hdmi->logo_plug_out && !hdmi->disabled) { |
|---|
| 3321 | + hdmi->update = true; |
|---|
| 3322 | + hdmi_writeb(hdmi, HDMI_FC_GCP_SET_AVMUTE, HDMI_FC_GCP); |
|---|
| 3323 | + mdelay(180); |
|---|
| 3324 | + handle_plugged_change(hdmi, false); |
|---|
| 3325 | + } else { |
|---|
| 3326 | + hdmi->update = false; |
|---|
| 3327 | + crtc_state->mode_changed = true; |
|---|
| 3328 | + hdmi->logo_plug_out = false; |
|---|
| 3329 | + } |
|---|
| 3330 | + } |
|---|
| 3331 | + |
|---|
| 3332 | + return 0; |
|---|
| 2836 | 3333 | } |
|---|
| 2837 | 3334 | |
|---|
| 2838 | 3335 | static int |
|---|
| .. | .. |
|---|
| 2879 | 3376 | property, val); |
|---|
| 2880 | 3377 | } |
|---|
| 2881 | 3378 | |
|---|
| 2882 | | -static bool dw_hdmi_color_changed(struct drm_connector *connector) |
|---|
| 3379 | +static void dw_hdmi_connector_atomic_commit(struct drm_connector *connector, |
|---|
| 3380 | + struct drm_connector_state *state) |
|---|
| 2883 | 3381 | { |
|---|
| 2884 | | - struct dw_hdmi *hdmi = container_of(connector, struct dw_hdmi, |
|---|
| 2885 | | - connector); |
|---|
| 2886 | | - void *data = hdmi->plat_data->phy_data; |
|---|
| 2887 | | - bool ret = false; |
|---|
| 3382 | + struct dw_hdmi *hdmi = |
|---|
| 3383 | + container_of(connector, struct dw_hdmi, connector); |
|---|
| 2888 | 3384 | |
|---|
| 2889 | | - if (hdmi->plat_data->get_color_changed) |
|---|
| 2890 | | - ret = hdmi->plat_data->get_color_changed(data); |
|---|
| 2891 | | - |
|---|
| 2892 | | - return ret; |
|---|
| 2893 | | -} |
|---|
| 2894 | | - |
|---|
| 2895 | | -static bool hdr_metadata_equal(const struct drm_connector_state *old_state, |
|---|
| 2896 | | - const struct drm_connector_state *new_state) |
|---|
| 2897 | | -{ |
|---|
| 2898 | | - struct drm_property_blob *old_blob = old_state->hdr_output_metadata; |
|---|
| 2899 | | - struct drm_property_blob *new_blob = new_state->hdr_output_metadata; |
|---|
| 2900 | | - |
|---|
| 2901 | | - if (!old_blob || !new_blob) |
|---|
| 2902 | | - return old_blob == new_blob; |
|---|
| 2903 | | - |
|---|
| 2904 | | - if (old_blob->length != new_blob->length) |
|---|
| 2905 | | - return false; |
|---|
| 2906 | | - |
|---|
| 2907 | | - return !memcmp(old_blob->data, new_blob->data, old_blob->length); |
|---|
| 2908 | | -} |
|---|
| 2909 | | - |
|---|
| 2910 | | -static int dw_hdmi_connector_atomic_check(struct drm_connector *connector, |
|---|
| 2911 | | - struct drm_atomic_state *state) |
|---|
| 2912 | | -{ |
|---|
| 2913 | | - struct drm_connector_state *old_state = |
|---|
| 2914 | | - drm_atomic_get_old_connector_state(state, connector); |
|---|
| 2915 | | - struct drm_connector_state *new_state = |
|---|
| 2916 | | - drm_atomic_get_new_connector_state(state, connector); |
|---|
| 2917 | | - struct drm_crtc *crtc = new_state->crtc; |
|---|
| 2918 | | - struct drm_crtc_state *crtc_state; |
|---|
| 2919 | | - struct dw_hdmi *hdmi = container_of(connector, struct dw_hdmi, |
|---|
| 2920 | | - connector); |
|---|
| 2921 | | - struct drm_display_mode *mode = NULL; |
|---|
| 2922 | | - void *data = hdmi->plat_data->phy_data; |
|---|
| 2923 | | - struct hdmi_vmode *vmode = &hdmi->hdmi_data.video_mode; |
|---|
| 2924 | | - |
|---|
| 2925 | | - if (!crtc) |
|---|
| 2926 | | - return 0; |
|---|
| 2927 | | - |
|---|
| 2928 | | - /* |
|---|
| 2929 | | - * If HDMI is enabled in uboot, it's need to record |
|---|
| 2930 | | - * drm_display_mode and set phy status to enabled. |
|---|
| 2931 | | - */ |
|---|
| 2932 | | - if (!vmode->mpixelclock) { |
|---|
| 2933 | | - crtc_state = drm_atomic_get_crtc_state(state, crtc); |
|---|
| 2934 | | - if (hdmi->plat_data->get_enc_in_encoding) |
|---|
| 2935 | | - hdmi->hdmi_data.enc_in_encoding = |
|---|
| 2936 | | - hdmi->plat_data->get_enc_in_encoding(data); |
|---|
| 2937 | | - if (hdmi->plat_data->get_enc_out_encoding) |
|---|
| 2938 | | - hdmi->hdmi_data.enc_out_encoding = |
|---|
| 2939 | | - hdmi->plat_data->get_enc_out_encoding(data); |
|---|
| 2940 | | - if (hdmi->plat_data->get_input_bus_format) |
|---|
| 2941 | | - hdmi->hdmi_data.enc_in_bus_format = |
|---|
| 2942 | | - hdmi->plat_data->get_input_bus_format(data); |
|---|
| 2943 | | - if (hdmi->plat_data->get_output_bus_format) |
|---|
| 2944 | | - hdmi->hdmi_data.enc_out_bus_format = |
|---|
| 2945 | | - hdmi->plat_data->get_output_bus_format(data); |
|---|
| 2946 | | - |
|---|
| 2947 | | - mode = &crtc_state->mode; |
|---|
| 2948 | | - memcpy(&hdmi->previous_mode, mode, sizeof(hdmi->previous_mode)); |
|---|
| 2949 | | - vmode->mpixelclock = mode->crtc_clock * 1000; |
|---|
| 2950 | | - vmode->previous_pixelclock = mode->clock; |
|---|
| 2951 | | - vmode->previous_tmdsclock = mode->clock; |
|---|
| 2952 | | - vmode->mtmdsclock = hdmi_get_tmdsclock(hdmi, |
|---|
| 2953 | | - vmode->mpixelclock); |
|---|
| 2954 | | - if (hdmi_bus_fmt_is_yuv420(hdmi->hdmi_data.enc_out_bus_format)) |
|---|
| 2955 | | - vmode->mtmdsclock /= 2; |
|---|
| 3385 | + if (hdmi->update) { |
|---|
| 3386 | + dw_hdmi_setup(hdmi, hdmi->curr_conn, &hdmi->previous_mode); |
|---|
| 3387 | + mdelay(50); |
|---|
| 3388 | + handle_plugged_change(hdmi, true); |
|---|
| 3389 | + hdmi_writeb(hdmi, HDMI_FC_GCP_CLEAR_AVMUTE, HDMI_FC_GCP); |
|---|
| 3390 | + hdmi->update = false; |
|---|
| 2956 | 3391 | } |
|---|
| 2957 | | - |
|---|
| 2958 | | - if (!hdr_metadata_equal(old_state, new_state) || |
|---|
| 2959 | | - dw_hdmi_color_changed(connector)) { |
|---|
| 2960 | | - crtc_state = drm_atomic_get_crtc_state(state, crtc); |
|---|
| 2961 | | - if (IS_ERR(crtc_state)) |
|---|
| 2962 | | - return PTR_ERR(crtc_state); |
|---|
| 2963 | | - |
|---|
| 2964 | | - crtc_state->mode_changed = true; |
|---|
| 2965 | | - } |
|---|
| 2966 | | - |
|---|
| 2967 | | - return 0; |
|---|
| 2968 | 3392 | } |
|---|
| 2969 | 3393 | |
|---|
| 2970 | 3394 | void dw_hdmi_set_quant_range(struct dw_hdmi *hdmi) |
|---|
| .. | .. |
|---|
| 2973 | 3397 | return; |
|---|
| 2974 | 3398 | |
|---|
| 2975 | 3399 | hdmi_writeb(hdmi, HDMI_FC_GCP_SET_AVMUTE, HDMI_FC_GCP); |
|---|
| 2976 | | - dw_hdmi_setup(hdmi, &hdmi->previous_mode); |
|---|
| 3400 | + dw_hdmi_setup(hdmi, hdmi->curr_conn, &hdmi->previous_mode); |
|---|
| 2977 | 3401 | hdmi_writeb(hdmi, HDMI_FC_GCP_CLEAR_AVMUTE, HDMI_FC_GCP); |
|---|
| 2978 | 3402 | } |
|---|
| 2979 | 3403 | EXPORT_SYMBOL_GPL(dw_hdmi_set_quant_range); |
|---|
| .. | .. |
|---|
| 2989 | 3413 | return; |
|---|
| 2990 | 3414 | |
|---|
| 2991 | 3415 | hdmi_writeb(hdmi, HDMI_FC_GCP_SET_AVMUTE, HDMI_FC_GCP); |
|---|
| 2992 | | - dw_hdmi_setup(hdmi, &hdmi->previous_mode); |
|---|
| 3416 | + dw_hdmi_setup(hdmi, hdmi->curr_conn, &hdmi->previous_mode); |
|---|
| 2993 | 3417 | hdmi_writeb(hdmi, HDMI_FC_GCP_CLEAR_AVMUTE, HDMI_FC_GCP); |
|---|
| 2994 | 3418 | } |
|---|
| 2995 | 3419 | EXPORT_SYMBOL_GPL(dw_hdmi_set_output_type); |
|---|
| .. | .. |
|---|
| 3005 | 3429 | return hdmi->support_hdmi; |
|---|
| 3006 | 3430 | } |
|---|
| 3007 | 3431 | EXPORT_SYMBOL_GPL(dw_hdmi_get_output_type_cap); |
|---|
| 3432 | + |
|---|
| 3433 | +void dw_hdmi_set_hpd_wake(struct dw_hdmi *hdmi) |
|---|
| 3434 | +{ |
|---|
| 3435 | + if (!hdmi->cec) |
|---|
| 3436 | + return; |
|---|
| 3437 | + |
|---|
| 3438 | + if (!hdmi->cec_ops) |
|---|
| 3439 | + return; |
|---|
| 3440 | + |
|---|
| 3441 | + if (hdmi->cec_ops->hpd_wake_up) |
|---|
| 3442 | + hdmi->cec_ops->hpd_wake_up(hdmi->cec); |
|---|
| 3443 | +} |
|---|
| 3444 | +EXPORT_SYMBOL_GPL(dw_hdmi_set_hpd_wake); |
|---|
| 3008 | 3445 | |
|---|
| 3009 | 3446 | static void dw_hdmi_connector_force(struct drm_connector *connector) |
|---|
| 3010 | 3447 | { |
|---|
| .. | .. |
|---|
| 3043 | 3480 | |
|---|
| 3044 | 3481 | static const struct drm_connector_helper_funcs dw_hdmi_connector_helper_funcs = { |
|---|
| 3045 | 3482 | .get_modes = dw_hdmi_connector_get_modes, |
|---|
| 3046 | | - .best_encoder = drm_atomic_helper_best_encoder, |
|---|
| 3483 | + .best_encoder = dw_hdmi_connector_best_encoder, |
|---|
| 3047 | 3484 | .atomic_check = dw_hdmi_connector_atomic_check, |
|---|
| 3485 | + .atomic_commit = dw_hdmi_connector_atomic_commit, |
|---|
| 3048 | 3486 | }; |
|---|
| 3049 | 3487 | |
|---|
| 3050 | 3488 | static void dw_hdmi_attach_properties(struct dw_hdmi *hdmi) |
|---|
| .. | .. |
|---|
| 3113 | 3551 | if (ops && ops->attach_properties) |
|---|
| 3114 | 3552 | return ops->attach_properties(&hdmi->connector, |
|---|
| 3115 | 3553 | color, hdmi->version, |
|---|
| 3116 | | - hdmi->plat_data->phy_data); |
|---|
| 3554 | + hdmi->plat_data->phy_data, 0); |
|---|
| 3117 | 3555 | } |
|---|
| 3118 | 3556 | |
|---|
| 3119 | 3557 | static void dw_hdmi_destroy_properties(struct dw_hdmi *hdmi) |
|---|
| .. | .. |
|---|
| 3126 | 3564 | hdmi->plat_data->phy_data); |
|---|
| 3127 | 3565 | } |
|---|
| 3128 | 3566 | |
|---|
| 3129 | | -static int dw_hdmi_bridge_attach(struct drm_bridge *bridge) |
|---|
| 3567 | +static int dw_hdmi_connector_create(struct dw_hdmi *hdmi) |
|---|
| 3130 | 3568 | { |
|---|
| 3131 | | - struct dw_hdmi *hdmi = bridge->driver_private; |
|---|
| 3132 | | - struct drm_encoder *encoder = bridge->encoder; |
|---|
| 3133 | 3569 | struct drm_connector *connector = &hdmi->connector; |
|---|
| 3134 | | - int ret; |
|---|
| 3570 | + struct cec_connector_info conn_info; |
|---|
| 3571 | + struct cec_notifier *notifier; |
|---|
| 3135 | 3572 | |
|---|
| 3136 | | - if (!hdmi->next_bridge) { |
|---|
| 3137 | | - connector->interlace_allowed = 1; |
|---|
| 3138 | | - connector->polled = DRM_CONNECTOR_POLL_HPD; |
|---|
| 3573 | + if (hdmi->version >= 0x200a) |
|---|
| 3574 | + connector->ycbcr_420_allowed = |
|---|
| 3575 | + hdmi->plat_data->ycbcr_420_allowed; |
|---|
| 3576 | + else |
|---|
| 3577 | + connector->ycbcr_420_allowed = false; |
|---|
| 3139 | 3578 | |
|---|
| 3140 | | - drm_connector_helper_add(connector, &dw_hdmi_connector_helper_funcs); |
|---|
| 3579 | + connector->interlace_allowed = 1; |
|---|
| 3580 | + connector->polled = DRM_CONNECTOR_POLL_HPD; |
|---|
| 3141 | 3581 | |
|---|
| 3142 | | - drm_connector_init(bridge->dev, connector, &dw_hdmi_connector_funcs, |
|---|
| 3143 | | - DRM_MODE_CONNECTOR_HDMIA); |
|---|
| 3582 | + drm_connector_helper_add(connector, &dw_hdmi_connector_helper_funcs); |
|---|
| 3144 | 3583 | |
|---|
| 3145 | | - drm_connector_attach_encoder(connector, encoder); |
|---|
| 3584 | + drm_connector_init_with_ddc(hdmi->bridge.dev, connector, |
|---|
| 3585 | + &dw_hdmi_connector_funcs, |
|---|
| 3586 | + DRM_MODE_CONNECTOR_HDMIA, |
|---|
| 3587 | + hdmi->ddc); |
|---|
| 3146 | 3588 | |
|---|
| 3147 | | - dw_hdmi_attach_properties(hdmi); |
|---|
| 3589 | + /* |
|---|
| 3590 | + * drm_connector_attach_max_bpc_property() requires the |
|---|
| 3591 | + * connector to have a state. |
|---|
| 3592 | + */ |
|---|
| 3593 | + drm_atomic_helper_connector_reset(connector); |
|---|
| 3148 | 3594 | |
|---|
| 3149 | | - return 0; |
|---|
| 3150 | | - } |
|---|
| 3595 | + drm_connector_attach_max_bpc_property(connector, 8, 16); |
|---|
| 3151 | 3596 | |
|---|
| 3152 | | - hdmi->next_bridge->encoder = bridge->encoder; |
|---|
| 3153 | | - ret = drm_bridge_attach(bridge->encoder, hdmi->next_bridge, bridge); |
|---|
| 3154 | | - if (ret) { |
|---|
| 3155 | | - DRM_ERROR("Failed to attach bridge with dw-hdmi\n"); |
|---|
| 3156 | | - return ret; |
|---|
| 3157 | | - } |
|---|
| 3597 | + if (hdmi->version >= 0x200a && hdmi->plat_data->use_drm_infoframe) |
|---|
| 3598 | + drm_object_attach_property(&connector->base, |
|---|
| 3599 | + connector->dev->mode_config.hdr_output_metadata_property, 0); |
|---|
| 3158 | 3600 | |
|---|
| 3159 | | - bridge->next = hdmi->next_bridge; |
|---|
| 3601 | + drm_connector_attach_encoder(connector, hdmi->bridge.encoder); |
|---|
| 3602 | + |
|---|
| 3603 | + dw_hdmi_attach_properties(hdmi); |
|---|
| 3604 | + |
|---|
| 3605 | + cec_fill_conn_info_from_drm(&conn_info, connector); |
|---|
| 3606 | + |
|---|
| 3607 | + notifier = cec_notifier_conn_register(hdmi->dev, NULL, &conn_info); |
|---|
| 3608 | + if (!notifier) |
|---|
| 3609 | + return -ENOMEM; |
|---|
| 3610 | + |
|---|
| 3611 | + mutex_lock(&hdmi->cec_notifier_mutex); |
|---|
| 3612 | + hdmi->cec_notifier = notifier; |
|---|
| 3613 | + mutex_unlock(&hdmi->cec_notifier_mutex); |
|---|
| 3160 | 3614 | |
|---|
| 3161 | 3615 | return 0; |
|---|
| 3162 | 3616 | } |
|---|
| 3163 | 3617 | |
|---|
| 3618 | +/* ----------------------------------------------------------------------------- |
|---|
| 3619 | + * DRM Bridge Operations |
|---|
| 3620 | + */ |
|---|
| 3621 | + |
|---|
| 3622 | +/* |
|---|
| 3623 | + * Possible output formats : |
|---|
| 3624 | + * - MEDIA_BUS_FMT_UYYVYY16_0_5X48, |
|---|
| 3625 | + * - MEDIA_BUS_FMT_UYYVYY12_0_5X36, |
|---|
| 3626 | + * - MEDIA_BUS_FMT_UYYVYY10_0_5X30, |
|---|
| 3627 | + * - MEDIA_BUS_FMT_UYYVYY8_0_5X24, |
|---|
| 3628 | + * - MEDIA_BUS_FMT_YUV16_1X48, |
|---|
| 3629 | + * - MEDIA_BUS_FMT_RGB161616_1X48, |
|---|
| 3630 | + * - MEDIA_BUS_FMT_UYVY12_1X24, |
|---|
| 3631 | + * - MEDIA_BUS_FMT_YUV12_1X36, |
|---|
| 3632 | + * - MEDIA_BUS_FMT_RGB121212_1X36, |
|---|
| 3633 | + * - MEDIA_BUS_FMT_UYVY10_1X20, |
|---|
| 3634 | + * - MEDIA_BUS_FMT_YUV10_1X30, |
|---|
| 3635 | + * - MEDIA_BUS_FMT_RGB101010_1X30, |
|---|
| 3636 | + * - MEDIA_BUS_FMT_UYVY8_1X16, |
|---|
| 3637 | + * - MEDIA_BUS_FMT_YUV8_1X24, |
|---|
| 3638 | + * - MEDIA_BUS_FMT_RGB888_1X24, |
|---|
| 3639 | + */ |
|---|
| 3640 | + |
|---|
| 3641 | +/* Can return a maximum of 11 possible output formats for a mode/connector */ |
|---|
| 3642 | +#define MAX_OUTPUT_SEL_FORMATS 11 |
|---|
| 3643 | + |
|---|
| 3644 | +static u32 *dw_hdmi_bridge_atomic_get_output_bus_fmts(struct drm_bridge *bridge, |
|---|
| 3645 | + struct drm_bridge_state *bridge_state, |
|---|
| 3646 | + struct drm_crtc_state *crtc_state, |
|---|
| 3647 | + struct drm_connector_state *conn_state, |
|---|
| 3648 | + unsigned int *num_output_fmts) |
|---|
| 3649 | +{ |
|---|
| 3650 | + struct drm_connector *conn = conn_state->connector; |
|---|
| 3651 | + struct drm_display_info *info = &conn->display_info; |
|---|
| 3652 | + struct drm_display_mode *mode = &crtc_state->mode; |
|---|
| 3653 | + u8 max_bpc = conn_state->max_requested_bpc; |
|---|
| 3654 | + bool is_hdmi2_sink = info->hdmi.scdc.supported || |
|---|
| 3655 | + (info->color_formats & DRM_COLOR_FORMAT_YCRCB420); |
|---|
| 3656 | + u32 *output_fmts; |
|---|
| 3657 | + unsigned int i = 0; |
|---|
| 3658 | + |
|---|
| 3659 | + *num_output_fmts = 0; |
|---|
| 3660 | + |
|---|
| 3661 | + output_fmts = kcalloc(MAX_OUTPUT_SEL_FORMATS, sizeof(*output_fmts), |
|---|
| 3662 | + GFP_KERNEL); |
|---|
| 3663 | + if (!output_fmts) |
|---|
| 3664 | + return NULL; |
|---|
| 3665 | + |
|---|
| 3666 | + /* If dw-hdmi is the first or only bridge, avoid negociating with ourselves */ |
|---|
| 3667 | + if (list_is_singular(&bridge->encoder->bridge_chain) || |
|---|
| 3668 | + list_is_first(&bridge->chain_node, &bridge->encoder->bridge_chain)) { |
|---|
| 3669 | + *num_output_fmts = 1; |
|---|
| 3670 | + output_fmts[0] = MEDIA_BUS_FMT_FIXED; |
|---|
| 3671 | + |
|---|
| 3672 | + return output_fmts; |
|---|
| 3673 | + } |
|---|
| 3674 | + |
|---|
| 3675 | + /* |
|---|
| 3676 | + * If the current mode enforces 4:2:0, force the output but format |
|---|
| 3677 | + * to 4:2:0 and do not add the YUV422/444/RGB formats |
|---|
| 3678 | + */ |
|---|
| 3679 | + if (conn->ycbcr_420_allowed && |
|---|
| 3680 | + (drm_mode_is_420_only(info, mode) || |
|---|
| 3681 | + (is_hdmi2_sink && drm_mode_is_420_also(info, mode)))) { |
|---|
| 3682 | + |
|---|
| 3683 | + /* Order bus formats from 16bit to 8bit if supported */ |
|---|
| 3684 | + if (max_bpc >= 16 && info->bpc == 16 && |
|---|
| 3685 | + (info->hdmi.y420_dc_modes & DRM_EDID_YCBCR420_DC_48)) |
|---|
| 3686 | + output_fmts[i++] = MEDIA_BUS_FMT_UYYVYY16_0_5X48; |
|---|
| 3687 | + |
|---|
| 3688 | + if (max_bpc >= 12 && info->bpc >= 12 && |
|---|
| 3689 | + (info->hdmi.y420_dc_modes & DRM_EDID_YCBCR420_DC_36)) |
|---|
| 3690 | + output_fmts[i++] = MEDIA_BUS_FMT_UYYVYY12_0_5X36; |
|---|
| 3691 | + |
|---|
| 3692 | + if (max_bpc >= 10 && info->bpc >= 10 && |
|---|
| 3693 | + (info->hdmi.y420_dc_modes & DRM_EDID_YCBCR420_DC_30)) |
|---|
| 3694 | + output_fmts[i++] = MEDIA_BUS_FMT_UYYVYY10_0_5X30; |
|---|
| 3695 | + |
|---|
| 3696 | + /* Default 8bit fallback */ |
|---|
| 3697 | + output_fmts[i++] = MEDIA_BUS_FMT_UYYVYY8_0_5X24; |
|---|
| 3698 | + |
|---|
| 3699 | + *num_output_fmts = i; |
|---|
| 3700 | + |
|---|
| 3701 | + return output_fmts; |
|---|
| 3702 | + } |
|---|
| 3703 | + |
|---|
| 3704 | + /* |
|---|
| 3705 | + * Order bus formats from 16bit to 8bit and from YUV422 to RGB |
|---|
| 3706 | + * if supported. In any case the default RGB888 format is added |
|---|
| 3707 | + */ |
|---|
| 3708 | + |
|---|
| 3709 | + /* Default 8bit RGB fallback */ |
|---|
| 3710 | + output_fmts[i++] = MEDIA_BUS_FMT_RGB888_1X24; |
|---|
| 3711 | + |
|---|
| 3712 | + if (max_bpc >= 16 && info->bpc == 16) { |
|---|
| 3713 | + if (info->color_formats & DRM_COLOR_FORMAT_YCRCB444) |
|---|
| 3714 | + output_fmts[i++] = MEDIA_BUS_FMT_YUV16_1X48; |
|---|
| 3715 | + |
|---|
| 3716 | + output_fmts[i++] = MEDIA_BUS_FMT_RGB161616_1X48; |
|---|
| 3717 | + } |
|---|
| 3718 | + |
|---|
| 3719 | + if (max_bpc >= 12 && info->bpc >= 12) { |
|---|
| 3720 | + if (info->color_formats & DRM_COLOR_FORMAT_YCRCB422) |
|---|
| 3721 | + output_fmts[i++] = MEDIA_BUS_FMT_UYVY12_1X24; |
|---|
| 3722 | + |
|---|
| 3723 | + if (info->color_formats & DRM_COLOR_FORMAT_YCRCB444) |
|---|
| 3724 | + output_fmts[i++] = MEDIA_BUS_FMT_YUV12_1X36; |
|---|
| 3725 | + |
|---|
| 3726 | + output_fmts[i++] = MEDIA_BUS_FMT_RGB121212_1X36; |
|---|
| 3727 | + } |
|---|
| 3728 | + |
|---|
| 3729 | + if (max_bpc >= 10 && info->bpc >= 10) { |
|---|
| 3730 | + if (info->color_formats & DRM_COLOR_FORMAT_YCRCB422) |
|---|
| 3731 | + output_fmts[i++] = MEDIA_BUS_FMT_UYVY10_1X20; |
|---|
| 3732 | + |
|---|
| 3733 | + if (info->color_formats & DRM_COLOR_FORMAT_YCRCB444) |
|---|
| 3734 | + output_fmts[i++] = MEDIA_BUS_FMT_YUV10_1X30; |
|---|
| 3735 | + |
|---|
| 3736 | + output_fmts[i++] = MEDIA_BUS_FMT_RGB101010_1X30; |
|---|
| 3737 | + } |
|---|
| 3738 | + |
|---|
| 3739 | + if (info->color_formats & DRM_COLOR_FORMAT_YCRCB422) |
|---|
| 3740 | + output_fmts[i++] = MEDIA_BUS_FMT_UYVY8_1X16; |
|---|
| 3741 | + |
|---|
| 3742 | + if (info->color_formats & DRM_COLOR_FORMAT_YCRCB444) |
|---|
| 3743 | + output_fmts[i++] = MEDIA_BUS_FMT_YUV8_1X24; |
|---|
| 3744 | + |
|---|
| 3745 | + *num_output_fmts = i; |
|---|
| 3746 | + |
|---|
| 3747 | + return output_fmts; |
|---|
| 3748 | +} |
|---|
| 3749 | + |
|---|
| 3750 | +/* |
|---|
| 3751 | + * Possible input formats : |
|---|
| 3752 | + * - MEDIA_BUS_FMT_RGB888_1X24 |
|---|
| 3753 | + * - MEDIA_BUS_FMT_YUV8_1X24 |
|---|
| 3754 | + * - MEDIA_BUS_FMT_UYVY8_1X16 |
|---|
| 3755 | + * - MEDIA_BUS_FMT_UYYVYY8_0_5X24 |
|---|
| 3756 | + * - MEDIA_BUS_FMT_RGB101010_1X30 |
|---|
| 3757 | + * - MEDIA_BUS_FMT_YUV10_1X30 |
|---|
| 3758 | + * - MEDIA_BUS_FMT_UYVY10_1X20 |
|---|
| 3759 | + * - MEDIA_BUS_FMT_UYYVYY10_0_5X30 |
|---|
| 3760 | + * - MEDIA_BUS_FMT_RGB121212_1X36 |
|---|
| 3761 | + * - MEDIA_BUS_FMT_YUV12_1X36 |
|---|
| 3762 | + * - MEDIA_BUS_FMT_UYVY12_1X24 |
|---|
| 3763 | + * - MEDIA_BUS_FMT_UYYVYY12_0_5X36 |
|---|
| 3764 | + * - MEDIA_BUS_FMT_RGB161616_1X48 |
|---|
| 3765 | + * - MEDIA_BUS_FMT_YUV16_1X48 |
|---|
| 3766 | + * - MEDIA_BUS_FMT_UYYVYY16_0_5X48 |
|---|
| 3767 | + */ |
|---|
| 3768 | + |
|---|
| 3769 | +/* Can return a maximum of 3 possible input formats for an output format */ |
|---|
| 3770 | +#define MAX_INPUT_SEL_FORMATS 3 |
|---|
| 3771 | + |
|---|
| 3772 | +static u32 *dw_hdmi_bridge_atomic_get_input_bus_fmts(struct drm_bridge *bridge, |
|---|
| 3773 | + struct drm_bridge_state *bridge_state, |
|---|
| 3774 | + struct drm_crtc_state *crtc_state, |
|---|
| 3775 | + struct drm_connector_state *conn_state, |
|---|
| 3776 | + u32 output_fmt, |
|---|
| 3777 | + unsigned int *num_input_fmts) |
|---|
| 3778 | +{ |
|---|
| 3779 | + u32 *input_fmts; |
|---|
| 3780 | + unsigned int i = 0; |
|---|
| 3781 | + |
|---|
| 3782 | + *num_input_fmts = 0; |
|---|
| 3783 | + |
|---|
| 3784 | + input_fmts = kcalloc(MAX_INPUT_SEL_FORMATS, sizeof(*input_fmts), |
|---|
| 3785 | + GFP_KERNEL); |
|---|
| 3786 | + if (!input_fmts) |
|---|
| 3787 | + return NULL; |
|---|
| 3788 | + |
|---|
| 3789 | + switch (output_fmt) { |
|---|
| 3790 | + /* If MEDIA_BUS_FMT_FIXED is tested, return default bus format */ |
|---|
| 3791 | + case MEDIA_BUS_FMT_FIXED: |
|---|
| 3792 | + input_fmts[i++] = MEDIA_BUS_FMT_RGB888_1X24; |
|---|
| 3793 | + break; |
|---|
| 3794 | + /* 8bit */ |
|---|
| 3795 | + case MEDIA_BUS_FMT_RGB888_1X24: |
|---|
| 3796 | + input_fmts[i++] = MEDIA_BUS_FMT_RGB888_1X24; |
|---|
| 3797 | + input_fmts[i++] = MEDIA_BUS_FMT_YUV8_1X24; |
|---|
| 3798 | + input_fmts[i++] = MEDIA_BUS_FMT_UYVY8_1X16; |
|---|
| 3799 | + break; |
|---|
| 3800 | + case MEDIA_BUS_FMT_YUV8_1X24: |
|---|
| 3801 | + input_fmts[i++] = MEDIA_BUS_FMT_YUV8_1X24; |
|---|
| 3802 | + input_fmts[i++] = MEDIA_BUS_FMT_UYVY8_1X16; |
|---|
| 3803 | + input_fmts[i++] = MEDIA_BUS_FMT_RGB888_1X24; |
|---|
| 3804 | + break; |
|---|
| 3805 | + case MEDIA_BUS_FMT_UYVY8_1X16: |
|---|
| 3806 | + input_fmts[i++] = MEDIA_BUS_FMT_UYVY8_1X16; |
|---|
| 3807 | + input_fmts[i++] = MEDIA_BUS_FMT_YUV8_1X24; |
|---|
| 3808 | + input_fmts[i++] = MEDIA_BUS_FMT_RGB888_1X24; |
|---|
| 3809 | + break; |
|---|
| 3810 | + |
|---|
| 3811 | + /* 10bit */ |
|---|
| 3812 | + case MEDIA_BUS_FMT_RGB101010_1X30: |
|---|
| 3813 | + input_fmts[i++] = MEDIA_BUS_FMT_RGB101010_1X30; |
|---|
| 3814 | + input_fmts[i++] = MEDIA_BUS_FMT_YUV10_1X30; |
|---|
| 3815 | + input_fmts[i++] = MEDIA_BUS_FMT_UYVY10_1X20; |
|---|
| 3816 | + break; |
|---|
| 3817 | + case MEDIA_BUS_FMT_YUV10_1X30: |
|---|
| 3818 | + input_fmts[i++] = MEDIA_BUS_FMT_YUV10_1X30; |
|---|
| 3819 | + input_fmts[i++] = MEDIA_BUS_FMT_UYVY10_1X20; |
|---|
| 3820 | + input_fmts[i++] = MEDIA_BUS_FMT_RGB101010_1X30; |
|---|
| 3821 | + break; |
|---|
| 3822 | + case MEDIA_BUS_FMT_UYVY10_1X20: |
|---|
| 3823 | + input_fmts[i++] = MEDIA_BUS_FMT_UYVY10_1X20; |
|---|
| 3824 | + input_fmts[i++] = MEDIA_BUS_FMT_YUV10_1X30; |
|---|
| 3825 | + input_fmts[i++] = MEDIA_BUS_FMT_RGB101010_1X30; |
|---|
| 3826 | + break; |
|---|
| 3827 | + |
|---|
| 3828 | + /* 12bit */ |
|---|
| 3829 | + case MEDIA_BUS_FMT_RGB121212_1X36: |
|---|
| 3830 | + input_fmts[i++] = MEDIA_BUS_FMT_RGB121212_1X36; |
|---|
| 3831 | + input_fmts[i++] = MEDIA_BUS_FMT_YUV12_1X36; |
|---|
| 3832 | + input_fmts[i++] = MEDIA_BUS_FMT_UYVY12_1X24; |
|---|
| 3833 | + break; |
|---|
| 3834 | + case MEDIA_BUS_FMT_YUV12_1X36: |
|---|
| 3835 | + input_fmts[i++] = MEDIA_BUS_FMT_YUV12_1X36; |
|---|
| 3836 | + input_fmts[i++] = MEDIA_BUS_FMT_UYVY12_1X24; |
|---|
| 3837 | + input_fmts[i++] = MEDIA_BUS_FMT_RGB121212_1X36; |
|---|
| 3838 | + break; |
|---|
| 3839 | + case MEDIA_BUS_FMT_UYVY12_1X24: |
|---|
| 3840 | + input_fmts[i++] = MEDIA_BUS_FMT_UYVY12_1X24; |
|---|
| 3841 | + input_fmts[i++] = MEDIA_BUS_FMT_YUV12_1X36; |
|---|
| 3842 | + input_fmts[i++] = MEDIA_BUS_FMT_RGB121212_1X36; |
|---|
| 3843 | + break; |
|---|
| 3844 | + |
|---|
| 3845 | + /* 16bit */ |
|---|
| 3846 | + case MEDIA_BUS_FMT_RGB161616_1X48: |
|---|
| 3847 | + input_fmts[i++] = MEDIA_BUS_FMT_RGB161616_1X48; |
|---|
| 3848 | + input_fmts[i++] = MEDIA_BUS_FMT_YUV16_1X48; |
|---|
| 3849 | + break; |
|---|
| 3850 | + case MEDIA_BUS_FMT_YUV16_1X48: |
|---|
| 3851 | + input_fmts[i++] = MEDIA_BUS_FMT_YUV16_1X48; |
|---|
| 3852 | + input_fmts[i++] = MEDIA_BUS_FMT_RGB161616_1X48; |
|---|
| 3853 | + break; |
|---|
| 3854 | + |
|---|
| 3855 | + /*YUV 4:2:0 */ |
|---|
| 3856 | + case MEDIA_BUS_FMT_UYYVYY8_0_5X24: |
|---|
| 3857 | + case MEDIA_BUS_FMT_UYYVYY10_0_5X30: |
|---|
| 3858 | + case MEDIA_BUS_FMT_UYYVYY12_0_5X36: |
|---|
| 3859 | + case MEDIA_BUS_FMT_UYYVYY16_0_5X48: |
|---|
| 3860 | + input_fmts[i++] = output_fmt; |
|---|
| 3861 | + break; |
|---|
| 3862 | + } |
|---|
| 3863 | + |
|---|
| 3864 | + *num_input_fmts = i; |
|---|
| 3865 | + |
|---|
| 3866 | + if (*num_input_fmts == 0) { |
|---|
| 3867 | + kfree(input_fmts); |
|---|
| 3868 | + input_fmts = NULL; |
|---|
| 3869 | + } |
|---|
| 3870 | + |
|---|
| 3871 | + return input_fmts; |
|---|
| 3872 | +} |
|---|
| 3873 | + |
|---|
| 3874 | +static int dw_hdmi_bridge_atomic_check(struct drm_bridge *bridge, |
|---|
| 3875 | + struct drm_bridge_state *bridge_state, |
|---|
| 3876 | + struct drm_crtc_state *crtc_state, |
|---|
| 3877 | + struct drm_connector_state *conn_state) |
|---|
| 3878 | +{ |
|---|
| 3879 | + struct dw_hdmi *hdmi = bridge->driver_private; |
|---|
| 3880 | + void *data = hdmi->plat_data->phy_data; |
|---|
| 3881 | + |
|---|
| 3882 | + if (bridge_state->output_bus_cfg.format == MEDIA_BUS_FMT_FIXED) { |
|---|
| 3883 | + if (hdmi->plat_data->get_output_bus_format) |
|---|
| 3884 | + hdmi->hdmi_data.enc_out_bus_format = |
|---|
| 3885 | + hdmi->plat_data->get_output_bus_format(data); |
|---|
| 3886 | + else |
|---|
| 3887 | + hdmi->hdmi_data.enc_out_bus_format = |
|---|
| 3888 | + MEDIA_BUS_FMT_RGB888_1X24; |
|---|
| 3889 | + |
|---|
| 3890 | + if (hdmi->plat_data->get_input_bus_format) |
|---|
| 3891 | + hdmi->hdmi_data.enc_in_bus_format = |
|---|
| 3892 | + hdmi->plat_data->get_input_bus_format(data); |
|---|
| 3893 | + else if (hdmi->plat_data->input_bus_format) |
|---|
| 3894 | + hdmi->hdmi_data.enc_in_bus_format = |
|---|
| 3895 | + hdmi->plat_data->input_bus_format; |
|---|
| 3896 | + else |
|---|
| 3897 | + hdmi->hdmi_data.enc_in_bus_format = |
|---|
| 3898 | + MEDIA_BUS_FMT_RGB888_1X24; |
|---|
| 3899 | + } else { |
|---|
| 3900 | + hdmi->hdmi_data.enc_out_bus_format = |
|---|
| 3901 | + bridge_state->output_bus_cfg.format; |
|---|
| 3902 | + |
|---|
| 3903 | + hdmi->hdmi_data.enc_in_bus_format = |
|---|
| 3904 | + bridge_state->input_bus_cfg.format; |
|---|
| 3905 | + |
|---|
| 3906 | + dev_dbg(hdmi->dev, "input format 0x%04x, output format 0x%04x\n", |
|---|
| 3907 | + bridge_state->input_bus_cfg.format, |
|---|
| 3908 | + bridge_state->output_bus_cfg.format); |
|---|
| 3909 | + } |
|---|
| 3910 | + |
|---|
| 3911 | + return 0; |
|---|
| 3912 | +} |
|---|
| 3913 | + |
|---|
| 3914 | +static int dw_hdmi_bridge_attach(struct drm_bridge *bridge, |
|---|
| 3915 | + enum drm_bridge_attach_flags flags) |
|---|
| 3916 | +{ |
|---|
| 3917 | + struct dw_hdmi *hdmi = bridge->driver_private; |
|---|
| 3918 | + int ret; |
|---|
| 3919 | + |
|---|
| 3920 | + if (flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR) |
|---|
| 3921 | + return 0; |
|---|
| 3922 | + |
|---|
| 3923 | + if (hdmi->next_bridge) { |
|---|
| 3924 | + hdmi->next_bridge->encoder = bridge->encoder; |
|---|
| 3925 | + ret = drm_bridge_attach(bridge->encoder, hdmi->next_bridge, bridge, flags); |
|---|
| 3926 | + if (ret) { |
|---|
| 3927 | + DRM_ERROR("Failed to attach bridge with dw-hdmi\n"); |
|---|
| 3928 | + return ret; |
|---|
| 3929 | + } |
|---|
| 3930 | + |
|---|
| 3931 | + return 0; |
|---|
| 3932 | + } |
|---|
| 3933 | + |
|---|
| 3934 | + return dw_hdmi_connector_create(hdmi); |
|---|
| 3935 | +} |
|---|
| 3936 | + |
|---|
| 3937 | +static void dw_hdmi_bridge_detach(struct drm_bridge *bridge) |
|---|
| 3938 | +{ |
|---|
| 3939 | + struct dw_hdmi *hdmi = bridge->driver_private; |
|---|
| 3940 | + |
|---|
| 3941 | + mutex_lock(&hdmi->cec_notifier_mutex); |
|---|
| 3942 | + cec_notifier_conn_unregister(hdmi->cec_notifier); |
|---|
| 3943 | + hdmi->cec_notifier = NULL; |
|---|
| 3944 | + mutex_unlock(&hdmi->cec_notifier_mutex); |
|---|
| 3945 | +} |
|---|
| 3946 | + |
|---|
| 3164 | 3947 | static enum drm_mode_status |
|---|
| 3165 | 3948 | dw_hdmi_bridge_mode_valid(struct drm_bridge *bridge, |
|---|
| 3949 | + const struct drm_display_info *info, |
|---|
| 3166 | 3950 | const struct drm_display_mode *mode) |
|---|
| 3167 | 3951 | { |
|---|
| 3168 | 3952 | struct dw_hdmi *hdmi = bridge->driver_private; |
|---|
| 3169 | | - struct drm_connector *connector = &hdmi->connector; |
|---|
| 3953 | + const struct dw_hdmi_plat_data *pdata = hdmi->plat_data; |
|---|
| 3170 | 3954 | enum drm_mode_status mode_status = MODE_OK; |
|---|
| 3171 | 3955 | |
|---|
| 3172 | 3956 | if (hdmi->next_bridge) |
|---|
| 3173 | 3957 | return MODE_OK; |
|---|
| 3174 | 3958 | |
|---|
| 3175 | | - if (hdmi->plat_data->mode_valid) |
|---|
| 3176 | | - mode_status = hdmi->plat_data->mode_valid(connector, mode); |
|---|
| 3959 | + if (!(hdmi_readb(hdmi, HDMI_PHY_STAT0) & HDMI_PHY_HPD) && hdmi->hdr2sdr) |
|---|
| 3960 | + return MODE_OK; |
|---|
| 3961 | + |
|---|
| 3962 | + if (pdata->mode_valid) |
|---|
| 3963 | + mode_status = pdata->mode_valid(hdmi, pdata->priv_data, info, |
|---|
| 3964 | + mode); |
|---|
| 3177 | 3965 | |
|---|
| 3178 | 3966 | return mode_status; |
|---|
| 3179 | 3967 | } |
|---|
| 3180 | 3968 | |
|---|
| 3181 | 3969 | static void dw_hdmi_bridge_mode_set(struct drm_bridge *bridge, |
|---|
| 3182 | | - struct drm_display_mode *orig_mode, |
|---|
| 3183 | | - struct drm_display_mode *mode) |
|---|
| 3970 | + const struct drm_display_mode *orig_mode, |
|---|
| 3971 | + const struct drm_display_mode *mode) |
|---|
| 3184 | 3972 | { |
|---|
| 3185 | 3973 | struct dw_hdmi *hdmi = bridge->driver_private; |
|---|
| 3186 | 3974 | |
|---|
| .. | .. |
|---|
| 3192 | 3980 | mutex_unlock(&hdmi->mutex); |
|---|
| 3193 | 3981 | } |
|---|
| 3194 | 3982 | |
|---|
| 3195 | | -static void dw_hdmi_bridge_disable(struct drm_bridge *bridge) |
|---|
| 3983 | +static void dw_hdmi_bridge_atomic_disable(struct drm_bridge *bridge, |
|---|
| 3984 | + struct drm_bridge_state *old_state) |
|---|
| 3196 | 3985 | { |
|---|
| 3197 | 3986 | struct dw_hdmi *hdmi = bridge->driver_private; |
|---|
| 3198 | 3987 | |
|---|
| 3199 | 3988 | mutex_lock(&hdmi->mutex); |
|---|
| 3200 | 3989 | hdmi->disabled = true; |
|---|
| 3990 | + handle_plugged_change(hdmi, false); |
|---|
| 3991 | + hdmi->curr_conn = NULL; |
|---|
| 3201 | 3992 | dw_hdmi_update_power(hdmi); |
|---|
| 3202 | 3993 | dw_hdmi_update_phy_mask(hdmi); |
|---|
| 3994 | + if (hdmi->plat_data->dclk_set) |
|---|
| 3995 | + hdmi->plat_data->dclk_set(hdmi->plat_data->phy_data, false, 0); |
|---|
| 3203 | 3996 | mutex_unlock(&hdmi->mutex); |
|---|
| 3204 | 3997 | } |
|---|
| 3205 | 3998 | |
|---|
| 3206 | | -static void dw_hdmi_bridge_enable(struct drm_bridge *bridge) |
|---|
| 3999 | +static void dw_hdmi_bridge_atomic_enable(struct drm_bridge *bridge, |
|---|
| 4000 | + struct drm_bridge_state *old_state) |
|---|
| 3207 | 4001 | { |
|---|
| 3208 | 4002 | struct dw_hdmi *hdmi = bridge->driver_private; |
|---|
| 4003 | + struct drm_atomic_state *state = old_state->base.state; |
|---|
| 4004 | + struct drm_connector *connector; |
|---|
| 4005 | + |
|---|
| 4006 | + connector = drm_atomic_get_new_connector_for_encoder(state, |
|---|
| 4007 | + bridge->encoder); |
|---|
| 3209 | 4008 | |
|---|
| 3210 | 4009 | mutex_lock(&hdmi->mutex); |
|---|
| 3211 | 4010 | hdmi->disabled = false; |
|---|
| 4011 | + hdmi->curr_conn = connector; |
|---|
| 4012 | + if (hdmi->plat_data->dclk_set) |
|---|
| 4013 | + hdmi->plat_data->dclk_set(hdmi->plat_data->phy_data, true, 0); |
|---|
| 3212 | 4014 | dw_hdmi_update_power(hdmi); |
|---|
| 3213 | 4015 | dw_hdmi_update_phy_mask(hdmi); |
|---|
| 4016 | + handle_plugged_change(hdmi, true); |
|---|
| 3214 | 4017 | mutex_unlock(&hdmi->mutex); |
|---|
| 3215 | 4018 | } |
|---|
| 3216 | 4019 | |
|---|
| 4020 | +static enum drm_connector_status dw_hdmi_bridge_detect(struct drm_bridge *bridge) |
|---|
| 4021 | +{ |
|---|
| 4022 | + struct dw_hdmi *hdmi = bridge->driver_private; |
|---|
| 4023 | + |
|---|
| 4024 | + return dw_hdmi_detect(hdmi); |
|---|
| 4025 | +} |
|---|
| 4026 | + |
|---|
| 4027 | +static struct edid *dw_hdmi_bridge_get_edid(struct drm_bridge *bridge, |
|---|
| 4028 | + struct drm_connector *connector) |
|---|
| 4029 | +{ |
|---|
| 4030 | + struct dw_hdmi *hdmi = bridge->driver_private; |
|---|
| 4031 | + |
|---|
| 4032 | + return dw_hdmi_get_edid(hdmi, connector); |
|---|
| 4033 | +} |
|---|
| 4034 | + |
|---|
| 3217 | 4035 | static const struct drm_bridge_funcs dw_hdmi_bridge_funcs = { |
|---|
| 4036 | + .atomic_duplicate_state = drm_atomic_helper_bridge_duplicate_state, |
|---|
| 4037 | + .atomic_destroy_state = drm_atomic_helper_bridge_destroy_state, |
|---|
| 4038 | + .atomic_reset = drm_atomic_helper_bridge_reset, |
|---|
| 3218 | 4039 | .attach = dw_hdmi_bridge_attach, |
|---|
| 3219 | | - .enable = dw_hdmi_bridge_enable, |
|---|
| 3220 | | - .disable = dw_hdmi_bridge_disable, |
|---|
| 4040 | + .detach = dw_hdmi_bridge_detach, |
|---|
| 4041 | + .atomic_check = dw_hdmi_bridge_atomic_check, |
|---|
| 4042 | + .atomic_get_output_bus_fmts = dw_hdmi_bridge_atomic_get_output_bus_fmts, |
|---|
| 4043 | + .atomic_get_input_bus_fmts = dw_hdmi_bridge_atomic_get_input_bus_fmts, |
|---|
| 4044 | + .atomic_enable = dw_hdmi_bridge_atomic_enable, |
|---|
| 4045 | + .atomic_disable = dw_hdmi_bridge_atomic_disable, |
|---|
| 3221 | 4046 | .mode_set = dw_hdmi_bridge_mode_set, |
|---|
| 3222 | 4047 | .mode_valid = dw_hdmi_bridge_mode_valid, |
|---|
| 4048 | + .detect = dw_hdmi_bridge_detect, |
|---|
| 4049 | + .get_edid = dw_hdmi_bridge_get_edid, |
|---|
| 3223 | 4050 | }; |
|---|
| 4051 | + |
|---|
| 4052 | +void dw_hdmi_set_cec_adap(struct dw_hdmi *hdmi, struct cec_adapter *adap) |
|---|
| 4053 | +{ |
|---|
| 4054 | + hdmi->cec_adap = adap; |
|---|
| 4055 | +} |
|---|
| 4056 | +EXPORT_SYMBOL_GPL(dw_hdmi_set_cec_adap); |
|---|
| 4057 | + |
|---|
| 4058 | +/* ----------------------------------------------------------------------------- |
|---|
| 4059 | + * IRQ Handling |
|---|
| 4060 | + */ |
|---|
| 3224 | 4061 | |
|---|
| 3225 | 4062 | static irqreturn_t dw_hdmi_i2c_irq(struct dw_hdmi *hdmi) |
|---|
| 3226 | 4063 | { |
|---|
| .. | .. |
|---|
| 3330 | 4167 | phy_stat & HDMI_PHY_HPD, |
|---|
| 3331 | 4168 | phy_stat & HDMI_PHY_RX_SENSE); |
|---|
| 3332 | 4169 | |
|---|
| 3333 | | - if ((phy_stat & (HDMI_PHY_RX_SENSE | HDMI_PHY_HPD)) == 0) |
|---|
| 3334 | | - cec_notifier_set_phys_addr(hdmi->cec_notifier, |
|---|
| 3335 | | - CEC_PHYS_ADDR_INVALID); |
|---|
| 4170 | + if ((phy_stat & (HDMI_PHY_RX_SENSE | HDMI_PHY_HPD)) == 0) { |
|---|
| 4171 | + mutex_lock(&hdmi->cec_notifier_mutex); |
|---|
| 4172 | + cec_notifier_phys_addr_invalidate(hdmi->cec_notifier); |
|---|
| 4173 | + mutex_unlock(&hdmi->cec_notifier_mutex); |
|---|
| 4174 | + } |
|---|
| 3336 | 4175 | } |
|---|
| 3337 | 4176 | |
|---|
| 3338 | 4177 | check_hdmi_irq(hdmi, intr_stat, phy_int_pol); |
|---|
| .. | .. |
|---|
| 3456 | 4295 | static const struct dw_hdmi_cec_ops dw_hdmi_cec_ops = { |
|---|
| 3457 | 4296 | .write = hdmi_writeb, |
|---|
| 3458 | 4297 | .read = hdmi_readb, |
|---|
| 4298 | + .mod = hdmi_modb, |
|---|
| 3459 | 4299 | .enable = dw_hdmi_cec_enable, |
|---|
| 3460 | 4300 | .disable = dw_hdmi_cec_disable, |
|---|
| 3461 | 4301 | }; |
|---|
| .. | .. |
|---|
| 3464 | 4304 | .reg_bits = 32, |
|---|
| 3465 | 4305 | .val_bits = 8, |
|---|
| 3466 | 4306 | .reg_stride = 1, |
|---|
| 3467 | | - .max_register = HDMI_I2CM_FS_SCL_LCNT_0_ADDR, |
|---|
| 4307 | + .max_register = HDMI_I2CM_SCDC_UPDATE1, |
|---|
| 3468 | 4308 | }; |
|---|
| 3469 | 4309 | |
|---|
| 3470 | 4310 | static const struct regmap_config hdmi_regmap_32bit_config = { |
|---|
| 3471 | 4311 | .reg_bits = 32, |
|---|
| 3472 | 4312 | .val_bits = 32, |
|---|
| 3473 | 4313 | .reg_stride = 4, |
|---|
| 3474 | | - .max_register = HDMI_I2CM_FS_SCL_LCNT_0_ADDR << 2, |
|---|
| 4314 | + .max_register = HDMI_I2CM_SCDC_UPDATE1 << 2, |
|---|
| 3475 | 4315 | }; |
|---|
| 4316 | + |
|---|
| 4317 | +static void dw_hdmi_init_hw(struct dw_hdmi *hdmi) |
|---|
| 4318 | +{ |
|---|
| 4319 | + initialize_hdmi_ih_mutes(hdmi); |
|---|
| 4320 | + |
|---|
| 4321 | + /* |
|---|
| 4322 | + * Reset HDMI DDC I2C master controller and mute I2CM interrupts. |
|---|
| 4323 | + * Even if we are using a separate i2c adapter doing this doesn't |
|---|
| 4324 | + * hurt. |
|---|
| 4325 | + */ |
|---|
| 4326 | + dw_hdmi_i2c_init(hdmi); |
|---|
| 4327 | + |
|---|
| 4328 | + if (hdmi->phy.ops->setup_hpd) |
|---|
| 4329 | + hdmi->phy.ops->setup_hpd(hdmi, hdmi->phy.data); |
|---|
| 4330 | +} |
|---|
| 3476 | 4331 | |
|---|
| 3477 | 4332 | static int dw_hdmi_status_show(struct seq_file *s, void *v) |
|---|
| 3478 | 4333 | { |
|---|
| .. | .. |
|---|
| 3532 | 4387 | } |
|---|
| 3533 | 4388 | |
|---|
| 3534 | 4389 | val = hdmi_readb(hdmi, HDMI_FC_PACKET_TX_EN); |
|---|
| 3535 | | - if (!(val & HDMI_FC_PACKET_DRM_TX_EN_MASK)) { |
|---|
| 4390 | + if (!(val & HDMI_FC_PACKET_TX_EN_DRM_MASK)) { |
|---|
| 3536 | 4391 | seq_puts(s, "Off\n"); |
|---|
| 3537 | 4392 | return 0; |
|---|
| 3538 | 4393 | } |
|---|
| 3539 | 4394 | |
|---|
| 3540 | 4395 | switch (hdmi_readb(hdmi, HDMI_FC_DRM_PB0)) { |
|---|
| 3541 | | - case TRADITIONAL_GAMMA_SDR: |
|---|
| 4396 | + case HDMI_EOTF_TRADITIONAL_GAMMA_SDR: |
|---|
| 3542 | 4397 | seq_puts(s, "SDR"); |
|---|
| 3543 | 4398 | break; |
|---|
| 3544 | | - case TRADITIONAL_GAMMA_HDR: |
|---|
| 4399 | + case HDMI_EOTF_TRADITIONAL_GAMMA_HDR: |
|---|
| 3545 | 4400 | seq_puts(s, "HDR"); |
|---|
| 3546 | 4401 | break; |
|---|
| 3547 | | - case SMPTE_ST2084: |
|---|
| 4402 | + case HDMI_EOTF_SMPTE_ST2084: |
|---|
| 3548 | 4403 | seq_puts(s, "ST2084"); |
|---|
| 3549 | 4404 | break; |
|---|
| 3550 | | - case HLG: |
|---|
| 4405 | + case HDMI_EOTF_BT_2100_HLG: |
|---|
| 3551 | 4406 | seq_puts(s, "HLG"); |
|---|
| 3552 | 4407 | break; |
|---|
| 3553 | 4408 | default: |
|---|
| .. | .. |
|---|
| 3824 | 4679 | return 0; |
|---|
| 3825 | 4680 | } |
|---|
| 3826 | 4681 | |
|---|
| 3827 | | -static struct dw_hdmi * |
|---|
| 3828 | | -__dw_hdmi_probe(struct platform_device *pdev, |
|---|
| 3829 | | - const struct dw_hdmi_plat_data *plat_data) |
|---|
| 4682 | +void |
|---|
| 4683 | +dw_hdmi_cec_wake_ops_register(struct dw_hdmi *hdmi, const struct dw_hdmi_cec_wake_ops *cec_ops) |
|---|
| 4684 | +{ |
|---|
| 4685 | + if (!cec_ops || !hdmi) |
|---|
| 4686 | + return; |
|---|
| 4687 | + |
|---|
| 4688 | + hdmi->cec_ops = cec_ops; |
|---|
| 4689 | +} |
|---|
| 4690 | +EXPORT_SYMBOL_GPL(dw_hdmi_cec_wake_ops_register); |
|---|
| 4691 | + |
|---|
| 4692 | + |
|---|
| 4693 | +/* ----------------------------------------------------------------------------- |
|---|
| 4694 | + * Probe/remove API, used from platforms based on the DRM bridge API. |
|---|
| 4695 | + */ |
|---|
| 4696 | +struct dw_hdmi *dw_hdmi_probe(struct platform_device *pdev, |
|---|
| 4697 | + const struct dw_hdmi_plat_data *plat_data) |
|---|
| 3830 | 4698 | { |
|---|
| 3831 | 4699 | struct device *dev = &pdev->dev; |
|---|
| 3832 | 4700 | struct device_node *np = dev->of_node; |
|---|
| .. | .. |
|---|
| 3861 | 4729 | |
|---|
| 3862 | 4730 | mutex_init(&hdmi->mutex); |
|---|
| 3863 | 4731 | mutex_init(&hdmi->audio_mutex); |
|---|
| 4732 | + mutex_init(&hdmi->cec_notifier_mutex); |
|---|
| 3864 | 4733 | spin_lock_init(&hdmi->audio_lock); |
|---|
| 3865 | 4734 | |
|---|
| 3866 | 4735 | ddc_node = of_parse_phandle(np, "ddc-i2c-bus", 0); |
|---|
| .. | .. |
|---|
| 3983 | 4852 | if (ret) |
|---|
| 3984 | 4853 | goto err_iahb; |
|---|
| 3985 | 4854 | |
|---|
| 4855 | + hdmi->logo_plug_out = false; |
|---|
| 3986 | 4856 | hdmi->initialized = false; |
|---|
| 3987 | 4857 | ret = hdmi_readb(hdmi, HDMI_PHY_STAT0); |
|---|
| 3988 | 4858 | if (((ret & HDMI_PHY_TX_PHY_LOCK) && (ret & HDMI_PHY_HPD) && |
|---|
| .. | .. |
|---|
| 3992 | 4862 | hdmi->bridge_is_on = true; |
|---|
| 3993 | 4863 | hdmi->phy.enabled = true; |
|---|
| 3994 | 4864 | hdmi->initialized = true; |
|---|
| 4865 | + if (hdmi->plat_data->set_ddc_io) |
|---|
| 4866 | + hdmi->plat_data->set_ddc_io(hdmi->plat_data->phy_data, true); |
|---|
| 4867 | + if (hdmi->plat_data->dclk_set) |
|---|
| 4868 | + hdmi->plat_data->dclk_set(hdmi->plat_data->phy_data, true, 0); |
|---|
| 3995 | 4869 | } else if (ret & HDMI_PHY_TX_PHY_LOCK) { |
|---|
| 3996 | 4870 | hdmi->phy.ops->disable(hdmi, hdmi->phy.data); |
|---|
| 4871 | + if (hdmi->plat_data->set_ddc_io) |
|---|
| 4872 | + hdmi->plat_data->set_ddc_io(hdmi->plat_data->phy_data, false); |
|---|
| 3997 | 4873 | } |
|---|
| 3998 | 4874 | |
|---|
| 3999 | 4875 | init_hpd_work(hdmi); |
|---|
| 4000 | | - initialize_hdmi_ih_mutes(hdmi); |
|---|
| 4001 | 4876 | |
|---|
| 4002 | 4877 | irq = platform_get_irq(pdev, 0); |
|---|
| 4003 | 4878 | if (irq < 0) { |
|---|
| .. | .. |
|---|
| 4007 | 4882 | |
|---|
| 4008 | 4883 | hdmi->irq = irq; |
|---|
| 4009 | 4884 | ret = devm_request_threaded_irq(dev, irq, dw_hdmi_hardirq, |
|---|
| 4010 | | - dw_hdmi_irq, IRQF_SHARED, |
|---|
| 4885 | + dw_hdmi_irq, IRQF_SHARED | IRQF_ONESHOT, |
|---|
| 4011 | 4886 | dev_name(dev), hdmi); |
|---|
| 4012 | 4887 | if (ret) |
|---|
| 4013 | 4888 | goto err_iahb; |
|---|
| 4014 | | - |
|---|
| 4015 | | - hdmi->cec_notifier = cec_notifier_get(dev); |
|---|
| 4016 | | - if (!hdmi->cec_notifier) { |
|---|
| 4017 | | - ret = -ENOMEM; |
|---|
| 4018 | | - goto err_iahb; |
|---|
| 4019 | | - } |
|---|
| 4020 | 4889 | |
|---|
| 4021 | 4890 | /* |
|---|
| 4022 | 4891 | * To prevent overflows in HDMI_IH_FC_STAT2, set the clk regenerator |
|---|
| .. | .. |
|---|
| 4026 | 4895 | |
|---|
| 4027 | 4896 | /* If DDC bus is not specified, try to register HDMI I2C bus */ |
|---|
| 4028 | 4897 | if (!hdmi->ddc) { |
|---|
| 4898 | + /* Look for (optional) stuff related to unwedging */ |
|---|
| 4899 | + hdmi->pinctrl = devm_pinctrl_get(dev); |
|---|
| 4900 | + if (!IS_ERR(hdmi->pinctrl)) { |
|---|
| 4901 | + hdmi->unwedge_state = |
|---|
| 4902 | + pinctrl_lookup_state(hdmi->pinctrl, "unwedge"); |
|---|
| 4903 | + hdmi->default_state = |
|---|
| 4904 | + pinctrl_lookup_state(hdmi->pinctrl, "default"); |
|---|
| 4905 | + |
|---|
| 4906 | + if (IS_ERR(hdmi->default_state) || |
|---|
| 4907 | + IS_ERR(hdmi->unwedge_state)) { |
|---|
| 4908 | + if (!IS_ERR(hdmi->unwedge_state)) |
|---|
| 4909 | + dev_warn(dev, |
|---|
| 4910 | + "Unwedge requires default pinctrl\n"); |
|---|
| 4911 | + hdmi->default_state = NULL; |
|---|
| 4912 | + hdmi->unwedge_state = NULL; |
|---|
| 4913 | + } |
|---|
| 4914 | + } |
|---|
| 4915 | + |
|---|
| 4029 | 4916 | hdmi->ddc = dw_hdmi_i2c_adapter(hdmi); |
|---|
| 4030 | 4917 | if (IS_ERR(hdmi->ddc)) |
|---|
| 4031 | 4918 | hdmi->ddc = NULL; |
|---|
| .. | .. |
|---|
| 4041 | 4928 | hdmi->i2c->scl_low_ns = 4916; |
|---|
| 4042 | 4929 | } |
|---|
| 4043 | 4930 | |
|---|
| 4931 | + dw_hdmi_init_hw(hdmi); |
|---|
| 4932 | + |
|---|
| 4044 | 4933 | hdmi->bridge.driver_private = hdmi; |
|---|
| 4045 | 4934 | hdmi->bridge.funcs = &dw_hdmi_bridge_funcs; |
|---|
| 4935 | + hdmi->bridge.ops = DRM_BRIDGE_OP_DETECT | DRM_BRIDGE_OP_EDID |
|---|
| 4936 | + | DRM_BRIDGE_OP_HPD; |
|---|
| 4046 | 4937 | #ifdef CONFIG_OF |
|---|
| 4047 | 4938 | hdmi->bridge.of_node = pdev->dev.of_node; |
|---|
| 4048 | 4939 | #endif |
|---|
| .. | .. |
|---|
| 4071 | 4962 | hdmi->sink_has_audio = true; |
|---|
| 4072 | 4963 | } |
|---|
| 4073 | 4964 | |
|---|
| 4074 | | - dw_hdmi_setup_i2c(hdmi); |
|---|
| 4075 | | - if (hdmi->phy.ops->setup_hpd) |
|---|
| 4076 | | - hdmi->phy.ops->setup_hpd(hdmi, hdmi->phy.data); |
|---|
| 4077 | | - |
|---|
| 4078 | | - if (hdmi->version >= 0x200a) |
|---|
| 4079 | | - hdmi->connector.ycbcr_420_allowed = |
|---|
| 4080 | | - hdmi->plat_data->ycbcr_420_allowed; |
|---|
| 4081 | | - else |
|---|
| 4082 | | - hdmi->connector.ycbcr_420_allowed = false; |
|---|
| 4083 | | - |
|---|
| 4084 | 4965 | memset(&pdevinfo, 0, sizeof(pdevinfo)); |
|---|
| 4085 | 4966 | pdevinfo.parent = dev; |
|---|
| 4086 | 4967 | pdevinfo.id = PLATFORM_DEVID_AUTO; |
|---|
| .. | .. |
|---|
| 4095 | 4976 | audio.base = hdmi->regs; |
|---|
| 4096 | 4977 | audio.irq = irq; |
|---|
| 4097 | 4978 | audio.hdmi = hdmi; |
|---|
| 4098 | | - audio.eld = hdmi->connector.eld; |
|---|
| 4979 | + audio.get_eld = hdmi_audio_get_eld; |
|---|
| 4099 | 4980 | hdmi->enable_audio = dw_hdmi_ahb_audio_enable; |
|---|
| 4100 | 4981 | hdmi->disable_audio = dw_hdmi_ahb_audio_disable; |
|---|
| 4101 | 4982 | |
|---|
| .. | .. |
|---|
| 4108 | 4989 | struct dw_hdmi_i2s_audio_data audio; |
|---|
| 4109 | 4990 | |
|---|
| 4110 | 4991 | audio.hdmi = hdmi; |
|---|
| 4992 | + audio.get_eld = hdmi_audio_get_eld; |
|---|
| 4111 | 4993 | audio.write = hdmi_writeb; |
|---|
| 4112 | 4994 | audio.read = hdmi_readb; |
|---|
| 4113 | 4995 | audio.mod = hdmi_modb; |
|---|
| .. | .. |
|---|
| 4126 | 5008 | cec.ops = &dw_hdmi_cec_ops; |
|---|
| 4127 | 5009 | cec.irq = irq; |
|---|
| 4128 | 5010 | |
|---|
| 5011 | + irq = platform_get_irq(pdev, 1); |
|---|
| 5012 | + if (irq < 0) |
|---|
| 5013 | + dev_dbg(hdmi->dev, "can't get cec wake up irq\n"); |
|---|
| 5014 | + |
|---|
| 5015 | + cec.wake_irq = irq; |
|---|
| 5016 | + |
|---|
| 4129 | 5017 | pdevinfo.name = "dw-hdmi-cec"; |
|---|
| 4130 | 5018 | pdevinfo.data = &cec; |
|---|
| 4131 | 5019 | pdevinfo.size_data = sizeof(cec); |
|---|
| .. | .. |
|---|
| 4136 | 5024 | |
|---|
| 4137 | 5025 | hdmi->extcon = devm_extcon_dev_allocate(hdmi->dev, dw_hdmi_cable); |
|---|
| 4138 | 5026 | if (IS_ERR(hdmi->extcon)) { |
|---|
| 4139 | | - dev_err(hdmi->dev, "allocate extcon failed\n"); |
|---|
| 5027 | + ret = PTR_ERR(hdmi->extcon); |
|---|
| 5028 | + dev_err(hdmi->dev, "allocate extcon failed: %d\n", ret); |
|---|
| 4140 | 5029 | goto err_iahb; |
|---|
| 4141 | 5030 | } |
|---|
| 4142 | 5031 | |
|---|
| .. | .. |
|---|
| 4156 | 5045 | goto err_iahb; |
|---|
| 4157 | 5046 | } |
|---|
| 4158 | 5047 | |
|---|
| 4159 | | - /* Reset HDMI DDC I2C master controller and mute I2CM interrupts */ |
|---|
| 4160 | | - if (hdmi->i2c) |
|---|
| 4161 | | - dw_hdmi_i2c_init(hdmi); |
|---|
| 5048 | + drm_bridge_add(&hdmi->bridge); |
|---|
| 4162 | 5049 | |
|---|
| 4163 | 5050 | dw_hdmi_register_debugfs(dev, hdmi); |
|---|
| 4164 | 5051 | |
|---|
| .. | .. |
|---|
| 4172 | 5059 | return hdmi; |
|---|
| 4173 | 5060 | |
|---|
| 4174 | 5061 | err_iahb: |
|---|
| 4175 | | - if (hdmi->i2c) { |
|---|
| 4176 | | - i2c_del_adapter(&hdmi->i2c->adap); |
|---|
| 4177 | | - hdmi->ddc = NULL; |
|---|
| 4178 | | - } |
|---|
| 4179 | | - |
|---|
| 4180 | | - if (hdmi->cec_notifier) |
|---|
| 4181 | | - cec_notifier_put(hdmi->cec_notifier); |
|---|
| 4182 | | - |
|---|
| 4183 | 5062 | clk_disable_unprepare(hdmi->iahb_clk); |
|---|
| 4184 | 5063 | if (hdmi->cec_clk) |
|---|
| 4185 | 5064 | clk_disable_unprepare(hdmi->cec_clk); |
|---|
| 4186 | 5065 | err_isfr: |
|---|
| 4187 | 5066 | clk_disable_unprepare(hdmi->isfr_clk); |
|---|
| 4188 | 5067 | err_res: |
|---|
| 4189 | | - i2c_put_adapter(hdmi->ddc); |
|---|
| 5068 | + if (hdmi->i2c) |
|---|
| 5069 | + i2c_del_adapter(&hdmi->i2c->adap); |
|---|
| 5070 | + else |
|---|
| 5071 | + i2c_put_adapter(hdmi->ddc); |
|---|
| 4190 | 5072 | |
|---|
| 4191 | 5073 | return ERR_PTR(ret); |
|---|
| 4192 | 5074 | } |
|---|
| 5075 | +EXPORT_SYMBOL_GPL(dw_hdmi_probe); |
|---|
| 4193 | 5076 | |
|---|
| 4194 | | -static void __dw_hdmi_remove(struct dw_hdmi *hdmi) |
|---|
| 5077 | +void dw_hdmi_remove(struct dw_hdmi *hdmi) |
|---|
| 4195 | 5078 | { |
|---|
| 4196 | 5079 | if (hdmi->irq) |
|---|
| 4197 | 5080 | disable_irq(hdmi->irq); |
|---|
| .. | .. |
|---|
| 4201 | 5084 | destroy_workqueue(hdmi->workqueue); |
|---|
| 4202 | 5085 | |
|---|
| 4203 | 5086 | debugfs_remove_recursive(hdmi->debugfs_dir); |
|---|
| 5087 | + |
|---|
| 5088 | + drm_bridge_remove(&hdmi->bridge); |
|---|
| 4204 | 5089 | |
|---|
| 4205 | 5090 | if (hdmi->audio && !IS_ERR(hdmi->audio)) |
|---|
| 4206 | 5091 | platform_device_unregister(hdmi->audio); |
|---|
| .. | .. |
|---|
| 4220 | 5105 | if (hdmi->bridge.encoder) |
|---|
| 4221 | 5106 | hdmi->bridge.encoder->funcs->destroy(hdmi->bridge.encoder); |
|---|
| 4222 | 5107 | |
|---|
| 4223 | | - if (hdmi->cec_notifier) |
|---|
| 4224 | | - cec_notifier_put(hdmi->cec_notifier); |
|---|
| 4225 | | - |
|---|
| 4226 | 5108 | clk_disable_unprepare(hdmi->iahb_clk); |
|---|
| 4227 | 5109 | clk_disable_unprepare(hdmi->isfr_clk); |
|---|
| 4228 | 5110 | if (hdmi->cec_clk) |
|---|
| .. | .. |
|---|
| 4232 | 5114 | i2c_del_adapter(&hdmi->i2c->adap); |
|---|
| 4233 | 5115 | else |
|---|
| 4234 | 5116 | i2c_put_adapter(hdmi->ddc); |
|---|
| 4235 | | -} |
|---|
| 4236 | | - |
|---|
| 4237 | | -/* ----------------------------------------------------------------------------- |
|---|
| 4238 | | - * Probe/remove API, used from platforms based on the DRM bridge API. |
|---|
| 4239 | | - */ |
|---|
| 4240 | | -struct dw_hdmi *dw_hdmi_probe(struct platform_device *pdev, |
|---|
| 4241 | | - const struct dw_hdmi_plat_data *plat_data) |
|---|
| 4242 | | -{ |
|---|
| 4243 | | - struct dw_hdmi *hdmi; |
|---|
| 4244 | | - |
|---|
| 4245 | | - hdmi = __dw_hdmi_probe(pdev, plat_data); |
|---|
| 4246 | | - if (IS_ERR(hdmi)) |
|---|
| 4247 | | - return hdmi; |
|---|
| 4248 | | - |
|---|
| 4249 | | - drm_bridge_add(&hdmi->bridge); |
|---|
| 4250 | | - |
|---|
| 4251 | | - return hdmi; |
|---|
| 4252 | | -} |
|---|
| 4253 | | -EXPORT_SYMBOL_GPL(dw_hdmi_probe); |
|---|
| 4254 | | - |
|---|
| 4255 | | -void dw_hdmi_remove(struct dw_hdmi *hdmi) |
|---|
| 4256 | | -{ |
|---|
| 4257 | | - drm_bridge_remove(&hdmi->bridge); |
|---|
| 4258 | | - |
|---|
| 4259 | | - __dw_hdmi_remove(hdmi); |
|---|
| 4260 | 5117 | } |
|---|
| 4261 | 5118 | EXPORT_SYMBOL_GPL(dw_hdmi_remove); |
|---|
| 4262 | 5119 | |
|---|
| .. | .. |
|---|
| 4270 | 5127 | struct dw_hdmi *hdmi; |
|---|
| 4271 | 5128 | int ret; |
|---|
| 4272 | 5129 | |
|---|
| 4273 | | - hdmi = __dw_hdmi_probe(pdev, plat_data); |
|---|
| 5130 | + hdmi = dw_hdmi_probe(pdev, plat_data); |
|---|
| 4274 | 5131 | if (IS_ERR(hdmi)) |
|---|
| 4275 | 5132 | return hdmi; |
|---|
| 4276 | 5133 | |
|---|
| 4277 | | - ret = drm_bridge_attach(encoder, &hdmi->bridge, NULL); |
|---|
| 5134 | + ret = drm_bridge_attach(encoder, &hdmi->bridge, NULL, 0); |
|---|
| 4278 | 5135 | if (ret) { |
|---|
| 4279 | | - __dw_hdmi_remove(hdmi); |
|---|
| 5136 | + dw_hdmi_remove(hdmi); |
|---|
| 4280 | 5137 | DRM_ERROR("Failed to initialize bridge with drm\n"); |
|---|
| 4281 | 5138 | return ERR_PTR(ret); |
|---|
| 4282 | 5139 | } |
|---|
| .. | .. |
|---|
| 4290 | 5147 | |
|---|
| 4291 | 5148 | void dw_hdmi_unbind(struct dw_hdmi *hdmi) |
|---|
| 4292 | 5149 | { |
|---|
| 4293 | | - __dw_hdmi_remove(hdmi); |
|---|
| 5150 | + dw_hdmi_remove(hdmi); |
|---|
| 4294 | 5151 | } |
|---|
| 4295 | 5152 | EXPORT_SYMBOL_GPL(dw_hdmi_unbind); |
|---|
| 4296 | 5153 | |
|---|
| .. | .. |
|---|
| 4319 | 5176 | } |
|---|
| 4320 | 5177 | } |
|---|
| 4321 | 5178 | |
|---|
| 4322 | | -void dw_hdmi_suspend(struct device *dev, struct dw_hdmi *hdmi) |
|---|
| 5179 | +void dw_hdmi_suspend(struct dw_hdmi *hdmi) |
|---|
| 4323 | 5180 | { |
|---|
| 4324 | | - if (!hdmi) { |
|---|
| 4325 | | - dev_warn(dev, "Hdmi has not been initialized\n"); |
|---|
| 5181 | + if (!hdmi) |
|---|
| 4326 | 5182 | return; |
|---|
| 4327 | | - } |
|---|
| 4328 | 5183 | |
|---|
| 4329 | 5184 | mutex_lock(&hdmi->mutex); |
|---|
| 4330 | 5185 | |
|---|
| .. | .. |
|---|
| 4345 | 5200 | disable_irq(hdmi->irq); |
|---|
| 4346 | 5201 | cancel_delayed_work(&hdmi->work); |
|---|
| 4347 | 5202 | flush_workqueue(hdmi->workqueue); |
|---|
| 4348 | | - pinctrl_pm_select_sleep_state(dev); |
|---|
| 5203 | + pinctrl_pm_select_sleep_state(hdmi->dev); |
|---|
| 4349 | 5204 | } |
|---|
| 4350 | 5205 | EXPORT_SYMBOL_GPL(dw_hdmi_suspend); |
|---|
| 4351 | 5206 | |
|---|
| 4352 | | -void dw_hdmi_resume(struct device *dev, struct dw_hdmi *hdmi) |
|---|
| 5207 | +void dw_hdmi_resume(struct dw_hdmi *hdmi) |
|---|
| 4353 | 5208 | { |
|---|
| 4354 | | - if (!hdmi) { |
|---|
| 4355 | | - dev_warn(dev, "Hdmi has not been initialized\n"); |
|---|
| 5209 | + if (!hdmi) |
|---|
| 4356 | 5210 | return; |
|---|
| 4357 | | - } |
|---|
| 4358 | 5211 | |
|---|
| 4359 | | - pinctrl_pm_select_default_state(dev); |
|---|
| 5212 | + pinctrl_pm_select_default_state(hdmi->dev); |
|---|
| 4360 | 5213 | mutex_lock(&hdmi->mutex); |
|---|
| 4361 | 5214 | dw_hdmi_reg_initial(hdmi); |
|---|
| 4362 | | - if (hdmi->i2c) |
|---|
| 4363 | | - dw_hdmi_i2c_init(hdmi); |
|---|
| 5215 | + dw_hdmi_i2c_init(hdmi); |
|---|
| 4364 | 5216 | if (hdmi->irq) |
|---|
| 4365 | 5217 | enable_irq(hdmi->irq); |
|---|
| 4366 | 5218 | /* |
|---|