]> Git Repo - linux.git/commitdiff
Merge tag 'drm-misc-next-2017-11-30' of git://anongit.freedesktop.org/drm/drm-misc...
authorDave Airlie <[email protected]>
Sun, 3 Dec 2017 19:38:52 +0000 (05:38 +1000)
committerDave Airlie <[email protected]>
Sun, 3 Dec 2017 19:42:49 +0000 (05:42 +1000)
Cross-subsystem Changes:

- device tree doc for the Mitsubishi AA070MC01 and Tianma TM070RVHG71
panels (Lukasz Majewski) and for a 2nd endpoint on stm32 (Philippe Cornu)

Core Changes:

The most important changes are:

- Add drm_driver .last_close and .output_poll_changed helpers to reduce
fbdev emulation footprint in drivers (Noralf)
- Fix plane clipping in core and for vmwgfx (Ville)

Then we have a bunch of of improvement for print and debug such as the
addition of a framebuffer debugfs file. ELD connector, HDMI and
improvements.  And a bunch of misc improvements, clean ups and style
changes and doc updates

[airlied: drop eld bits from amdgpu_dm]

Driver Changes:

- sii8620: filter unsupported modes and add DVI mode support (Maciej Purski)
- rockchip: analogix_dp: Remove unnecessary init code (Jeffy Chen)
- virtio, cirrus: add fb create_handle support to enable screenshots(Lepton Wu)
- virtio: replace reference/unreference with get/put (Aastha Gupta)
- vc4, gma500: Convert timers to use timer_setup() (Kees Cook)
- vc4: Reject HDMI modes with too high of clocks (Eric)
- vc4: Add support for more pixel formats (Dave Stevenson)
- stm: dsi: Rename driver name to "stm32-display-dsi" (Philippe Cornu)
- stm: ltdc: add a 2nd endpoint (Philippe Cornu)
- via: use monotonic time for VIA_WAIT_IRQ (Arnd Bergmann)

* tag 'drm-misc-next-2017-11-30' of git://anongit.freedesktop.org/drm/drm-misc: (96 commits)
  drm/bridge: tc358767: add copyright lines
  MAINTAINERS: change maintainer for Rockchip drm drivers
  drm/vblank: Fix vblank timestamp debugs
  drm/via: use monotonic time for VIA_WAIT_IRQ
  dma-buf: Fix ifnullfree.cocci warnings
  drm/printer: Add drm_vprintf()
  drm/edid: Allow HDMI infoframe without VIC or S3D
  video/hdmi: Allow "empty" HDMI infoframes
  dma-buf/fence: Fix lock inversion within dma-fence-array
  drm/sti: Handle return value of platform_get_irq_byname
  drm/vc4: Add support for NV21 and NV61.
  drm/vc4: Use .pixel_order instead of custom .flip_cbcr
  drm/vc4: Add support for DRM_FORMAT_RGB888 and DRM_FORMAT_BGR888
  drm: Move drm_plane_helper_check_state() into drm_atomic_helper.c
  drm: Check crtc_state->enable rather than crtc->enabled in drm_plane_helper_check_state()
  drm/vmwgfx: Try to fix plane clipping
  drm/vmwgfx: Use drm_plane_helper_check_state()
  drm/vmwgfx: Remove bogus crtc coords vs fb size check
  gpu: gma500: remove unneeded DRIVER_LICENSE #define
  drm: don't link DP aux i2c adapter to the hardware device node
  ...

27 files changed:
1  2 
Documentation/gpu/todo.rst
MAINTAINERS
drivers/base/Kconfig
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c
drivers/gpu/drm/arm/hdlcd_crtc.c
drivers/gpu/drm/arm/hdlcd_drv.c
drivers/gpu/drm/arm/malidp_planes.c
drivers/gpu/drm/bridge/synopsys/dw-hdmi.c
drivers/gpu/drm/bridge/tc358767.c
drivers/gpu/drm/drm_atomic_helper.c
drivers/gpu/drm/drm_edid.c
drivers/gpu/drm/drm_fb_helper.c
drivers/gpu/drm/drm_vblank.c
drivers/gpu/drm/i2c/tda998x_drv.c
drivers/gpu/drm/i915/intel_display.c
drivers/gpu/drm/i915/intel_dp.c
drivers/gpu/drm/i915/intel_hdmi.c
drivers/gpu/drm/nouveau/nv50_display.c
drivers/gpu/drm/radeon/radeon_dp_mst.c
drivers/gpu/drm/vc4/vc4_hdmi.c
include/drm/drm_connector.h
include/drm/drm_dp_helper.h
include/drm/drm_edid.h
include/drm/drm_fb_cma_helper.h
include/drm/drm_gem_cma_helper.h
include/drm/drm_mode_config.h

index 36625aa66c27672c00219e1283d4ecb034913e40,e9840d693a863161097a5d2bc9dafeb8fcf5b760..01eaa40dafc9be452dd232855458f0bf1fdbfde0
@@@ -179,6 -179,10 +179,10 @@@ don't do this, drivers used dev_info/wa
  now have DRM_DEV_* variants of the drm print macros, so we can start to convert
  those drivers back to using drm-formwatted specific log messages.
  
+ Before you start this conversion please contact the relevant maintainers to make
+ sure your work will be merged - not everyone agrees that the DRM dmesg macros
+ are better.
  Contact: Sean Paul, Maintainer of the driver you plan to convert
  
  Core refactorings
@@@ -409,15 -413,5 +413,15 @@@ those drivers as simple as possible, s
  
  Contact: Noralf Trønnes, Daniel Vetter
  
 +AMD DC Display Driver
 +---------------------
 +
 +AMD DC is the display driver for AMD devices starting with Vega. There has been
 +a bunch of progress cleaning it up but there's still plenty of work to be done.
 +
 +See drivers/gpu/drm/amd/display/TODO for tasks.
 +
 +Contact: Harry Wentland, Alex Deucher
 +
  Outside DRM
  ===========
diff --combined MAINTAINERS
index d4fdcb12616c7a10c2a05407ca3586b208ed11a4,4f0756a4ff1aa579ad0abb24364fe8899c391eaa..d7eedb15be8544dc498741d62191c2e536059c23
@@@ -384,7 -384,6 +384,7 @@@ ACPI WMI DRIVE
  L:    [email protected]
  S:    Orphan
  F:    drivers/platform/x86/wmi.c
 +F:    include/uapi/linux/wmi.h
  
  AD1889 ALSA SOUND DRIVER
  M:    Thibaut Varene <[email protected]>
@@@ -528,6 -527,11 +528,6 @@@ W:        http://ez.analog.com/community/linux
  S:    Supported
  F:    drivers/input/misc/adxl34x.c
  
 -AEDSP16 DRIVER
 -M:    Riccardo Facchetti <[email protected]>
 -S:    Maintained
 -F:    sound/oss/aedsp16.c
 -
  AF9013 MEDIA DRIVER
  M:    Antti Palosaari <[email protected]>
  L:    [email protected]
@@@ -696,9 -700,9 +696,9 @@@ F: include/linux/altera_uart.
  F:    include/linux/altera_jtaguart.h
  
  AMAZON ETHERNET DRIVERS
 -M:    Netanel Belgazal <netanel@annapurnalabs.com>
 -R:    Saeed Bishara <saeed@annapurnalabs.com>
 -R:    Zorik Machulsky <zorik@annapurnalabs.com>
 +M:    Netanel Belgazal <netanel@amazon.com>
 +R:    Saeed Bishara <saeedb@amazon.com>
 +R:    Zorik Machulsky <zorik@amazon.com>
  L:    [email protected]
  S:    Supported
  F:    Documentation/networking/ena.txt
@@@ -867,7 -871,7 +867,7 @@@ F: drivers/android
  F:    drivers/staging/android/
  
  ANDROID GOLDFISH RTC DRIVER
 -M:    Miodrag Dinic <miodrag.dinic@imgtec.com>
 +M:    Miodrag Dinic <miodrag.dinic@mips.com>
  S:    Supported
  F:    Documentation/devicetree/bindings/rtc/google,goldfish-rtc.txt
  F:    drivers/rtc/rtc-goldfish.c
@@@ -1220,8 -1224,6 +1220,8 @@@ L:      [email protected]
  W:    http://www.linux4sam.org
  T:    git git://git.kernel.org/pub/scm/linux/kernel/git/nferre/linux-at91.git
  S:    Supported
 +N:    at91
 +N:    atmel
  F:    arch/arm/mach-at91/
  F:    include/soc/at91/
  F:    arch/arm/boot/dts/at91*.dts
@@@ -1230,9 -1232,6 +1230,9 @@@ F:      arch/arm/boot/dts/sama*.dt
  F:    arch/arm/boot/dts/sama*.dtsi
  F:    arch/arm/include/debug/at91.S
  F:    drivers/memory/atmel*
 +F:    drivers/watchdog/sama5d4_wdt.c
 +X:    drivers/input/touchscreen/atmel_mxt_ts.c
 +X:    drivers/net/wireless/atmel/
  
  ARM/CALXEDA HIGHBANK ARCHITECTURE
  M:    Rob Herring <[email protected]>
@@@ -1590,13 -1589,10 +1590,13 @@@ F:   drivers/rtc/rtc-armada38x.
  
  ARM/Mediatek RTC DRIVER
  M:    Eddie Huang <[email protected]>
 +M:    Sean Wang <[email protected]>
  L:    [email protected] (moderated for non-subscribers)
  L:    [email protected] (moderated for non-subscribers)
  S:    Maintained
 +F:    Documentation/devicetree/bindings/rtc/rtc-mt7622.txt
  F:    drivers/rtc/rtc-mt6397.c
 +F:    drivers/rtc/rtc-mt7622.c
  
  ARM/Mediatek SoC support
  M:    Matthias Brugger <[email protected]>
@@@ -1770,7 -1766,6 +1770,7 @@@ Q:      http://patchwork.kernel.org/project/
  T:    git git://git.kernel.org/pub/scm/linux/kernel/git/horms/renesas.git next
  S:    Supported
  F:    arch/arm64/boot/dts/renesas/
 +F:    Documentation/devicetree/bindings/arm/shmobile.txt
  F:    drivers/soc/renesas/
  F:    include/linux/soc/renesas/
  
@@@ -1890,7 -1885,6 +1890,7 @@@ F:      arch/arm/boot/dts/sh
  F:    arch/arm/configs/shmobile_defconfig
  F:    arch/arm/include/debug/renesas-scif.S
  F:    arch/arm/mach-shmobile/
 +F:    Documentation/devicetree/bindings/arm/shmobile.txt
  F:    drivers/soc/renesas/
  F:    include/linux/soc/renesas/
  
@@@ -1965,14 -1959,6 +1965,14 @@@ M:    Lennert Buytenhek <kernel@wantstofly
  L:    [email protected] (moderated for non-subscribers)
  S:    Maintained
  
 +ARM/TEGRA HDMI CEC SUBSYSTEM SUPPORT
 +M:    Hans Verkuil <[email protected]>
 +L:    [email protected]
 +L:    [email protected]
 +S:    Maintained
 +F:    drivers/media/platform/tegra-cec/
 +F:    Documentation/devicetree/bindings/media/tegra-cec.txt
 +
  ARM/TETON BGA MACHINE SUPPORT
  M:    "Mark F. Brown" <[email protected]>
  L:    [email protected] (moderated for non-subscribers)
@@@ -2041,7 -2027,6 +2041,7 @@@ M:      Masahiro Yamada <yamada.masahiro@soc
  L:    [email protected] (moderated for non-subscribers)
  T:    git git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-uniphier.git
  S:    Maintained
 +F:    Documentation/devicetree/bindings/gpio/gpio-uniphier.txt
  F:    arch/arm/boot/dts/uniphier*
  F:    arch/arm/include/asm/hardware/cache-uniphier.h
  F:    arch/arm/mach-uniphier/
@@@ -2049,7 -2034,6 +2049,7 @@@ F:      arch/arm/mm/cache-uniphier.
  F:    arch/arm64/boot/dts/socionext/
  F:    drivers/bus/uniphier-system-bus.c
  F:    drivers/clk/uniphier/
 +F:    drivers/gpio/gpio-uniphier.c
  F:    drivers/i2c/busses/i2c-uniphier*
  F:    drivers/irqchip/irq-uniphier-aidet.c
  F:    drivers/pinctrl/uniphier/
@@@ -2150,6 -2134,7 +2150,6 @@@ F:      drivers/gpio/gpio-zx.
  F:    drivers/i2c/busses/i2c-zx2967.c
  F:    drivers/mmc/host/dw_mmc-zx.*
  F:    drivers/pinctrl/zte/
 -F:    drivers/reset/reset-zx2967.c
  F:    drivers/soc/zte/
  F:    drivers/thermal/zx2967_thermal.c
  F:    drivers/watchdog/zx2967_wdt.c
@@@ -2172,6 -2157,7 +2172,6 @@@ F:      sound/soc/zte
  
  ARM/ZYNQ ARCHITECTURE
  M:    Michal Simek <[email protected]>
 -R:    Sören Brinkmann <[email protected]>
  L:    [email protected] (moderated for non-subscribers)
  W:    http://wiki.xilinx.com
  T:    git https://github.com/Xilinx/linux-xlnx.git
@@@ -2259,7 -2245,7 +2259,7 @@@ F:      include/linux/dmaengine.
  F:    include/linux/async_tx.h
  
  AT24 EEPROM DRIVER
 -M:    Wolfram Sang <[email protected]>
 +M:    Bartosz Golaszewski <[email protected]>
  L:    [email protected]
  S:    Maintained
  F:    drivers/misc/eeprom/at24.c
@@@ -2574,12 -2560,10 +2574,12 @@@ S:   Maintaine
  F:    drivers/net/hamradio/baycom*
  
  BCACHE (BLOCK LAYER CACHE)
 +M:    Michael Lyle <[email protected]>
  M:    Kent Overstreet <[email protected]>
  L:    [email protected]
  W:    http://bcache.evilpiepirate.org
 -S:    Orphan
 +C:    irc://irc.oftc.net/bcache
 +S:    Maintained
  F:    drivers/md/bcache/
  
  BDISP ST MEDIA DRIVER
@@@ -2727,7 -2711,6 +2727,7 @@@ L:      [email protected]
  S:    Supported
  F:    arch/x86/net/bpf_jit*
  F:    Documentation/networking/filter.txt
 +F:    Documentation/bpf/
  F:    include/linux/bpf*
  F:    include/linux/filter.h
  F:    include/uapi/linux/bpf*
@@@ -2740,7 -2723,7 +2740,7 @@@ F:      net/core/filter.
  F:    net/sched/act_bpf.c
  F:    net/sched/cls_bpf.c
  F:    samples/bpf/
 -F:    tools/net/bpf*
 +F:    tools/bpf/
  F:    tools/testing/selftests/bpf/
  
  BROADCOM B44 10/100 ETHERNET DRIVER
@@@ -2911,15 -2894,7 +2911,15 @@@ S:    Supporte
  F:    drivers/gpio/gpio-brcmstb.c
  F:    Documentation/devicetree/bindings/gpio/brcm,brcmstb-gpio.txt
  
 +BROADCOM BRCMSTB USB2 and USB3 PHY DRIVER
 +M:    Al Cooper <[email protected]>
 +L:    [email protected]
 +L:    [email protected]
 +S:    Maintained
 +F:    drivers/phy/broadcom/phy-brcm-usb*
 +
  BROADCOM GENET ETHERNET DRIVER
 +M:    Doug Berger <[email protected]>
  M:    Florian Fainelli <[email protected]>
  L:    [email protected]
  S:    Supported
@@@ -2946,7 -2921,6 +2946,7 @@@ N:      bcm583
  N:    bcm585*
  N:    bcm586*
  N:    bcm88312
 +N:    hr2
  F:    arch/arm64/boot/dts/broadcom/ns2*
  F:    drivers/clk/bcm/clk-ns*
  F:    drivers/pinctrl/bcm/pinctrl-ns*
@@@ -2990,14 -2964,6 +2990,14 @@@ S:    Maintaine
  F:    Documentation/devicetree/bindings/cpufreq/brcm,stb-avs-cpu-freq.txt
  F:    drivers/cpufreq/brcmstb*
  
 +BROADCOM STB AVS TMON DRIVER
 +M:    Markus Mayer <[email protected]>
 +M:    [email protected]
 +L:    [email protected]
 +S:    Maintained
 +F:    Documentation/devicetree/bindings/thermal/brcm,avs-tmon.txt
 +F:    drivers/thermal/broadcom/brcmstb*
 +
  BROADCOM STB NAND FLASH DRIVER
  M:    Brian Norris <[email protected]>
  M:    Kamal Dasu <[email protected]>
  S:    Maintained
  F:    drivers/mtd/nand/brcmnand/
  
 +BROADCOM STB DPFE DRIVER
 +M:    Markus Mayer <[email protected]>
 +M:    [email protected]
 +L:    [email protected] (moderated for non-subscribers)
 +S:    Maintained
 +F:    Documentation/devicetree/bindings/memory-controllers/brcm,dpfe-cpu.txt
 +F:    drivers/memory/brcmstb_dpfe.c
 +
  BROADCOM SYSTEMPORT ETHERNET DRIVER
  M:    Florian Fainelli <[email protected]>
  L:    [email protected]
@@@ -3122,6 -3080,7 +3122,6 @@@ F:      arch/c6x
  
  CA8210 IEEE-802.15.4 RADIO DRIVER
  M:    Harry Morris <[email protected]>
 -M:    [email protected]
  L:    [email protected]
  W:    https://github.com/Cascoda/ca8210-linux.git
  S:    Maintained
@@@ -3296,15 -3255,6 +3296,15 @@@ F:    include/uapi/linux/cec.
  F:    include/uapi/linux/cec-funcs.h
  F:    Documentation/devicetree/bindings/media/cec.txt
  
 +CEC GPIO DRIVER
 +M:    Hans Verkuil <[email protected]>
 +L:    [email protected]
 +T:    git git://linuxtv.org/media_tree.git
 +W:    http://linuxtv.org
 +S:    Supported
 +F:    drivers/media/platform/cec-gpio/
 +F:    Documentation/devicetree/bindings/media/cec-gpio.txt
 +
  CELL BROADBAND ENGINE ARCHITECTURE
  M:    Arnd Bergmann <[email protected]>
  L:    [email protected]
@@@ -3377,22 -3327,17 +3377,22 @@@ S:   Maintaine
  F:    drivers/auxdisplay/cfag12864bfb.c
  F:    include/linux/cfag12864b.h
  
 -CFG80211 and NL80211
 +802.11 (including CFG80211/NL80211)
  M:    Johannes Berg <[email protected]>
  L:    [email protected]
  W:    http://wireless.kernel.org/
  T:    git git://git.kernel.org/pub/scm/linux/kernel/git/jberg/mac80211.git
  T:    git git://git.kernel.org/pub/scm/linux/kernel/git/jberg/mac80211-next.git
  S:    Maintained
 +F:    net/wireless/
  F:    include/uapi/linux/nl80211.h
 +F:    include/linux/ieee80211.h
 +F:    include/net/wext.h
  F:    include/net/cfg80211.h
 -F:    net/wireless/*
 -X:    net/wireless/wext*
 +F:    include/net/iw_handler.h
 +F:    include/net/ieee80211_radiotap.h
 +F:    Documentation/driver-api/80211/cfg80211.rst
 +F:    Documentation/networking/regulatory.txt
  
  CHAR and MISC DRIVERS
  M:    Arnd Bergmann <[email protected]>
@@@ -3468,7 -3413,7 +3468,7 @@@ F:      drivers/scsi/snic
  CISCO VIC ETHERNET NIC DRIVER
  M:    Christian Benvenuti <[email protected]>
  M:    Govindarajulu Varadarajan <[email protected]>
 -M:    Neel Patel <neepatel@cisco.com>
 +M:    Parvi Kaustubhi <pkaustub@cisco.com>
  S:    Supported
  F:    drivers/net/ethernet/cisco/enic/
  
@@@ -3497,8 -3442,7 +3497,8 @@@ M:      Thomas Gleixner <[email protected]
  L:    [email protected]
  T:    git git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git timers/core
  S:    Supported
 -F:    drivers/clocksource
 +F:    drivers/clocksource/
 +F:    Documentation/devicetree/bindings/timer/
  
  CMPC ACPI DRIVER
  M:    Thadeu Lima de Souza Cascardo <[email protected]>
@@@ -3519,7 -3463,7 +3519,7 @@@ COCCINELLE/Semantic Patches (SmPL
  M:    Julia Lawall <[email protected]>
  M:    Gilles Muller <[email protected]>
  M:    Nicolas Palix <[email protected]>
 -M:    Michal Marek <m[email protected]>
 +M:    Michal Marek <m[email protected]>
  L:    [email protected] (moderated for non-subscribers)
  T:    git git://git.kernel.org/pub/scm/linux/kernel/git/mmarek/kbuild.git misc
  W:    http://coccinelle.lip6.fr/
@@@ -3633,7 -3577,7 +3633,7 @@@ T:      git git://git.kernel.org/pub/scm/lin
  S:    Maintained
  F:    Documentation/cgroup-v1/cpusets.txt
  F:    include/linux/cpuset.h
 -F:    kernel/cpuset.c
 +F:    kernel/cgroup/cpuset.c
  
  CONTROL GROUP - MEMORY RESOURCE CONTROLLER (MEMCG)
  M:    Johannes Weiner <[email protected]>
@@@ -3690,8 -3634,6 +3690,8 @@@ F:      drivers/cpufreq/arm_big_little_dt.
  
  CPU POWER MONITORING SUBSYSTEM
  M:    Thomas Renninger <[email protected]>
 +M:    Shuah Khan <[email protected]>
 +M:    Shuah Khan <[email protected]>
  L:    [email protected]
  S:    Maintained
  F:    tools/power/cpupower/
@@@ -3732,8 -3674,8 +3732,8 @@@ F:      drivers/cpuidle/
  F:    include/linux/cpuidle.h
  
  CRAMFS FILESYSTEM
 -W:    http://sourceforge.net/projects/cramfs/
 -S:    Orphan / Obsolete
 +M:    Nicolas Pitre <[email protected]>
 +S:    Maintained
  F:    Documentation/filesystems/cramfs.txt
  F:    fs/cramfs/
  
@@@ -4034,26 -3976,6 +4034,26 @@@ M:    "Maciej W. Rozycki" <macro@linux-mip
  S:    Maintained
  F:    drivers/net/fddi/defxx.*
  
 +DELL SMBIOS DRIVER
 +M:    Pali Rohár <[email protected]>
 +M:    Mario Limonciello <[email protected]>
 +L:    [email protected]
 +S:    Maintained
 +F:    drivers/platform/x86/dell-smbios.*
 +
 +DELL SMBIOS SMM DRIVER
 +M:    Mario Limonciello <[email protected]>
 +L:    [email protected]
 +S:    Maintained
 +F:    drivers/platform/x86/dell-smbios-smm.c
 +
 +DELL SMBIOS WMI DRIVER
 +M:    Mario Limonciello <[email protected]>
 +L:    [email protected]
 +S:    Maintained
 +F:    drivers/platform/x86/dell-smbios-wmi.c
 +F:    tools/wmi/dell-smbios-example.c
 +
  DELL LAPTOP DRIVER
  M:    Matthew Garrett <[email protected]>
  M:    Pali Rohár <[email protected]>
@@@ -4083,17 -4005,12 +4083,17 @@@ S:   Maintaine
  F:    Documentation/dcdbas.txt
  F:    drivers/firmware/dcdbas.*
  
 -DELL WMI EXTRAS DRIVER
 +DELL WMI NOTIFICATIONS DRIVER
  M:    Matthew Garrett <[email protected]>
  M:    Pali Rohár <[email protected]>
  S:    Maintained
  F:    drivers/platform/x86/dell-wmi.c
  
 +DELL WMI DESCRIPTOR DRIVER
 +M:    Mario Limonciello <[email protected]>
 +S:    Maintained
 +F:    drivers/platform/x86/dell-wmi-descriptor.c
 +
  DELTA ST MEDIA DRIVER
  M:    Hugues Fruchet <[email protected]>
  L:    [email protected]
@@@ -4172,8 -4089,6 +4172,8 @@@ T:      git git://git.kernel.org/pub/scm/lin
  T:    quilt http://people.redhat.com/agk/patches/linux/editing/
  S:    Maintained
  F:    Documentation/device-mapper/
 +F:    drivers/md/Makefile
 +F:    drivers/md/Kconfig
  F:    drivers/md/dm*
  F:    drivers/md/persistent-data/
  F:    include/linux/device-mapper.h
@@@ -4197,7 -4112,7 +4197,7 @@@ F:      Documentation/devicetree/bindings/mf
  F:    Documentation/devicetree/bindings/input/da90??-onkey.txt
  F:    Documentation/devicetree/bindings/thermal/da90??-thermal.txt
  F:    Documentation/devicetree/bindings/regulator/da92*.txt
 -F:    Documentation/devicetree/bindings/watchdog/da92??-wdt.txt
 +F:    Documentation/devicetree/bindings/watchdog/da90??-wdt.txt
  F:    Documentation/devicetree/bindings/sound/da[79]*.txt
  F:    drivers/gpio/gpio-da90??.c
  F:    drivers/hwmon/da90??-hwmon.c
@@@ -4245,7 -4160,7 +4245,7 @@@ L:      [email protected]
  S:    Maintained
  F:    drivers/i2c/busses/i2c-diolan-u2c.c
  
 -DIRECT ACCESS (DAX)
 +FILESYSTEM DIRECT ACCESS (DAX)
  M:    Matthew Wilcox <[email protected]>
  M:    Ross Zwisler <[email protected]>
  L:    [email protected]
@@@ -4254,12 -4169,6 +4254,12 @@@ F:    fs/dax.
  F:    include/linux/dax.h
  F:    include/trace/events/fs_dax.h
  
 +DEVICE DIRECT ACCESS (DAX)
 +M:    Dan Williams <[email protected]>
 +L:    [email protected]
 +S:    Supported
 +F:    drivers/dax/
 +
  DIRECTORY NOTIFICATION (DNOTIFY)
  M:    Jan Kara <[email protected]>
  R:    Amir Goldstein <[email protected]>
@@@ -4323,7 -4232,7 +4323,7 @@@ S:      Maintaine
  F:    drivers/dma/
  F:    include/linux/dmaengine.h
  F:    Documentation/devicetree/bindings/dma/
 -F:    Documentation/dmaengine/
 +F:    Documentation/driver-api/dmaengine/
  T:    git git://git.infradead.org/users/vkoul/slave-dma.git
  
  DMA MAPPING HELPERS
@@@ -4587,6 -4496,7 +4587,7 @@@ F:      include/linux/vga
  DRM DRIVERS AND MISC GPU PATCHES
  M:    Daniel Vetter <[email protected]>
  M:    Jani Nikula <[email protected]>
+ M:    Gustavo Padovan <[email protected]>
  M:    Sean Paul <[email protected]>
  W:    https://01.org/linuxgraphics/gfx-docs/maintainer-tools/drm-misc.html
  S:    Maintained
@@@ -4715,7 -4625,8 +4716,8 @@@ F:      Documentation/devicetree/bindings/di
  F:    Documentation/devicetree/bindings/display/renesas,du.txt
  
  DRM DRIVERS FOR ROCKCHIP
- M:    Mark Yao <[email protected]>
+ M:    Sandy Huang <[email protected]>
+ M:    Heiko Stübner <[email protected]>
  L:    [email protected]
  S:    Maintained
  F:    drivers/gpu/drm/rockchip/
  S:    Maintained
  F:    drivers/edac/highbank*
  
 -EDAC-CAVIUM
 +EDAC-CAVIUM OCTEON
  M:    Ralf Baechle <[email protected]>
  M:    David Daney <[email protected]>
  L:    [email protected]
  L:    [email protected]
  S:    Supported
  F:    drivers/edac/octeon_edac*
 +
 +EDAC-CAVIUM THUNDERX
 +M:    David Daney <[email protected]>
 +M:    Jan Glauber <[email protected]>
 +L:    [email protected]
 +S:    Supported
  F:    drivers/edac/thunderx_edac*
  
  EDAC-CORE
@@@ -5253,7 -5158,7 +5255,7 @@@ F:      drivers/video/fbdev/s1d13xxxfb.
  F:    include/video/s1d13xxxfb.h
  
  ERRSEQ ERROR TRACKING INFRASTRUCTURE
 -M:    Jeff Layton <jlayton@poochiereds.net>
 +M:    Jeff Layton <jlayton@kernel.org>
  S:    Maintained
  F:    lib/errseq.c
  F:    include/linux/errseq.h
@@@ -5314,7 -5219,8 +5316,7 @@@ F:      fs/ext4
  
  Extended Verification Module (EVM)
  M:    Mimi Zohar <[email protected]>
 -L:    [email protected]
 -L:    [email protected]
 +L:    [email protected]
  S:    Supported
  F:    security/integrity/evm/
  
@@@ -5441,7 -5347,7 +5443,7 @@@ F:      include/scsi/libfcoe.
  F:    include/uapi/scsi/fc/
  
  FILE LOCKING (flock() and fcntl()/lockf())
 -M:    Jeff Layton <jlayton@poochiereds.net>
 +M:    Jeff Layton <jlayton@kernel.org>
  M:    "J. Bruce Fields" <[email protected]>
  L:    [email protected]
  S:    Maintained
@@@ -5531,7 -5437,7 +5533,7 @@@ K:      fmc_d.*registe
  
  FPGA MANAGER FRAMEWORK
  M:    Alan Tull <[email protected]>
 -R:    Moritz Fischer <[email protected]>
 +M:    Moritz Fischer <[email protected]>
  L:    [email protected]
  S:    Maintained
  T:    git git://git.kernel.org/pub/scm/linux/kernel/git/atull/linux-fpga.git
@@@ -5570,7 -5476,7 +5572,7 @@@ F:      include/uapi/linux/fb.
  
  FREESCALE CAAM (Cryptographic Acceleration and Assurance Module) DRIVER
  M:    Horia Geantă <[email protected]>
 -M:    Dan Douglass <dan.douglass@nxp.com>
 +M:    Aymen Sghaier <aymen.sghaier@nxp.com>
  L:    [email protected]
  S:    Maintained
  F:    drivers/crypto/caam/
@@@ -5750,7 -5656,6 +5752,7 @@@ T:      git git://git.kernel.org/pub/scm/lin
  S:    Supported
  F:    fs/crypto/
  F:    include/linux/fscrypt*.h
 +F:    Documentation/filesystems/fscrypt.rst
  
  FUJITSU FR-V (FRV) PORT
  S:    Orphan
@@@ -6174,6 -6079,7 +6176,6 @@@ M:      Jean Delvare <[email protected]
  M:    Guenter Roeck <[email protected]>
  L:    [email protected]
  W:    http://hwmon.wiki.kernel.org/
 -T:    quilt http://jdelvare.nerim.net/devel/linux/jdelvare-hwmon/
  T:    git git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging.git
  S:    Maintained
  F:    Documentation/hwmon/
@@@ -6343,13 -6249,6 +6345,13 @@@ S:    Maintaine
  F:    drivers/net/ethernet/hisilicon/
  F:    Documentation/devicetree/bindings/net/hisilicon*.txt
  
 +HISILICON PMU DRIVER
 +M:    Shaokun Zhang <[email protected]>
 +W:    http://www.hisilicon.com
 +S:    Supported
 +F:    drivers/perf/hisilicon
 +F:    Documentation/perf/hisi-pmu.txt
 +
  HISILICON ROCE DRIVER
  M:    Lijun Ou <[email protected]>
  M:    Wei Hu(Xavier) <[email protected]>
@@@ -6779,7 -6678,7 +6781,7 @@@ F:      include/net/ieee802154_netdev.
  F:    Documentation/networking/ieee802154.txt
  
  IFE PROTOCOL
 -M:    Yotam Gigi <yotamg@mellanox.com>
 +M:    Yotam Gigi <yotam.gi@gmail.com>
  M:    Jamal Hadi Salim <[email protected]>
  F:    net/ife
  F:    include/net/ife.h
@@@ -6841,7 -6740,7 +6843,7 @@@ S:      Maintaine
  F:    drivers/usb/atm/ueagle-atm.c
  
  IMGTEC ASCII LCD DRIVER
 -M:    Paul Burton <paul.burton@imgtec.com>
 +M:    Paul Burton <paul.burton@mips.com>
  S:    Maintained
  F:    Documentation/devicetree/bindings/auxdisplay/img-ascii-lcd.txt
  F:    drivers/auxdisplay/img-ascii-lcd.c
@@@ -6883,7 -6782,8 +6885,7 @@@ F:      drivers/ipack
  
  INFINIBAND SUBSYSTEM
  M:    Doug Ledford <[email protected]>
 -M:    Sean Hefty <[email protected]>
 -M:    Hal Rosenstock <[email protected]>
 +M:    Jason Gunthorpe <[email protected]>
  L:    [email protected]
  W:    http://www.openfabrics.org/
  Q:    http://patchwork.kernel.org/project/linux-rdma/list/
@@@ -6948,7 -6848,9 +6950,7 @@@ L:      [email protected]
  INTEGRITY MEASUREMENT ARCHITECTURE (IMA)
  M:    Mimi Zohar <[email protected]>
  M:    Dmitry Kasatkin <[email protected]>
 -L:    [email protected]
 -L:    [email protected]
 -L:    [email protected]
 +L:    [email protected]
  T:    git git://git.kernel.org/pub/scm/linux/kernel/git/zohar/linux-integrity.git
  S:    Supported
  F:    security/integrity/ima/
@@@ -7209,11 -7111,6 +7211,11 @@@ F:    Documentation/wimax/README.i2400
  F:    drivers/net/wimax/i2400m/
  F:    include/uapi/linux/wimax/i2400m.h
  
 +INTEL WMI THUNDERBOLT FORCE POWER DRIVER
 +M:    Mario Limonciello <[email protected]>
 +S:    Maintained
 +F:    drivers/platform/x86/intel-wmi-thunderbolt.c
 +
  INTEL(R) TRACE HUB
  M:    Alexander Shishkin <[email protected]>
  S:    Supported
@@@ -7475,7 -7372,7 +7477,7 @@@ JFS FILESYSTE
  M:    Dave Kleikamp <[email protected]>
  L:    [email protected]
  W:    http://jfs.sourceforge.net/
 -T:    git git://git.kernel.org/pub/scm/linux/kernel/git/shaggy/jfs-2.6.git
 +T:    git git://github.com/kleikamp/linux-shaggy.git
  S:    Maintained
  F:    Documentation/filesystems/jfs.txt
  F:    fs/jfs/
@@@ -7543,8 -7440,10 +7545,8 @@@ F:     mm/kasan
  F:    scripts/Makefile.kasan
  
  KCONFIG
 -M:    "Yann E. MORIN" <[email protected]>
  L:    [email protected]
 -T:    git git://gitorious.org/linux-kconfig/linux-kconfig
 -S:    Maintained
 +S:    Orphan
  F:    Documentation/kbuild/kconfig-language.txt
  F:    scripts/kconfig/
  
@@@ -7573,7 -7472,7 +7575,7 @@@ F:      fs/autofs4
  
  KERNEL BUILD + files below scripts/ (unless maintained elsewhere)
  M:    Masahiro Yamada <[email protected]>
 -M:    Michal Marek <m[email protected]>
 +M:    Michal Marek <m[email protected]>
  T:    git git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild.git
  L:    [email protected]
  S:    Maintained
@@@ -7591,7 -7490,7 +7593,7 @@@ S:      Odd Fixe
  
  KERNEL NFSD, SUNRPC, AND LOCKD SERVERS
  M:    "J. Bruce Fields" <[email protected]>
 -M:    Jeff Layton <jlayton@poochiereds.net>
 +M:    Jeff Layton <jlayton@kernel.org>
  L:    [email protected]
  W:    http://nfs.sourceforge.net/
  T:    git git://linux-nfs.org/~bfields/linux.git
@@@ -7712,7 -7611,6 +7714,7 @@@ S:      Supporte
  F:    arch/x86/kvm/
  F:    arch/x86/include/uapi/asm/kvm*
  F:    arch/x86/include/asm/kvm*
 +F:    arch/x86/include/asm/pvclock-abi.h
  F:    arch/x86/kernel/kvm.c
  F:    arch/x86/kernel/kvmclock.c
  
@@@ -7735,7 -7633,8 +7737,7 @@@ F:      kernel/kexec
  
  KEYS-ENCRYPTED
  M:    Mimi Zohar <[email protected]>
 -M:    David Safford <[email protected]>
 -L:    [email protected]
 +L:    [email protected]
  L:    [email protected]
  S:    Supported
  F:    Documentation/security/keys/trusted-encrypted.rst
@@@ -7743,8 -7642,9 +7745,8 @@@ F:      include/keys/encrypted-type.
  F:    security/keys/encrypted-keys/
  
  KEYS-TRUSTED
 -M:    David Safford <[email protected]>
  M:    Mimi Zohar <[email protected]>
 -L:    linux-security-module@vger.kernel.org
 +L:    linux-integrity@vger.kernel.org
  L:    [email protected]
  S:    Supported
  F:    Documentation/security/keys/trusted-encrypted.rst
@@@ -7777,6 -7677,16 +7779,6 @@@ F:     include/linux/kdb.
  F:    include/linux/kgdb.h
  F:    kernel/debug/
  
 -KMEMCHECK
 -M:    Vegard Nossum <[email protected]>
 -M:    Pekka Enberg <[email protected]>
 -S:    Maintained
 -F:    Documentation/dev-tools/kmemcheck.rst
 -F:    arch/x86/include/asm/kmemcheck.h
 -F:    arch/x86/mm/kmemcheck/
 -F:    include/linux/kmemcheck.h
 -F:    mm/kmemcheck.c
 -
  KMEMLEAK
  M:    Catalin Marinas <[email protected]>
  S:    Maintained
@@@ -7842,11 -7752,6 +7844,11 @@@ S:    Maintaine
  F:    Documentation/scsi/53c700.txt
  F:    drivers/scsi/53c700*
  
 +LEAKING_ADDRESSES
 +M:    Tobin C. Harding <[email protected]>
 +S:    Maintained
 +F:    scripts/leaking_addresses.pl
 +
  LED SUBSYSTEM
  M:    Richard Purdie <[email protected]>
  M:    Jacek Anaszewski <[email protected]>
@@@ -8310,7 -8215,6 +8312,7 @@@ F:      Documentation/networking/mac80211-in
  F:    include/net/mac80211.h
  F:    net/mac80211/
  F:    drivers/net/wireless/mac80211_hwsim.[ch]
 +F:    Documentation/networking/mac80211_hwsim/README
  
  MAILBOX API
  M:    Jassi Brar <[email protected]>
@@@ -8846,7 -8750,7 +8848,7 @@@ Q:      http://patchwork.ozlabs.org/project/
  F:    drivers/net/ethernet/mellanox/mlxsw/
  
  MELLANOX FIRMWARE FLASH LIBRARY (mlxfw)
 -M:    Yotam Gigi <[email protected]>
 +M:    [email protected]
  L:    [email protected]
  S:    Supported
  W:    http://www.mellanox.com
@@@ -9096,7 -9000,7 +9098,7 @@@ F:      Documentation/mips
  F:    arch/mips/
  
  MIPS BOSTON DEVELOPMENT BOARD
 -M:    Paul Burton <paul.burton@imgtec.com>
 +M:    Paul Burton <paul.burton@mips.com>
  L:    [email protected]
  S:    Maintained
  F:    Documentation/devicetree/bindings/clock/img,boston-clock.txt
@@@ -9106,7 -9010,7 +9108,7 @@@ F:      drivers/clk/imgtec/clk-boston.
  F:    include/dt-bindings/clock/boston-clock.h
  
  MIPS GENERIC PLATFORM
 -M:    Paul Burton <paul.burton@imgtec.com>
 +M:    Paul Burton <paul.burton@mips.com>
  L:    [email protected]
  S:    Supported
  F:    arch/mips/generic/
@@@ -9122,7 -9026,7 +9124,7 @@@ F:      drivers/*/*loongson1
  F:    drivers/*/*/*loongson1*
  
  MIPS RINT INSTRUCTION EMULATION
 -M:    Aleksandar Markovic <aleksandar.markovic@imgtec.com>
 +M:    Aleksandar Markovic <aleksandar.markovic@mips.com>
  L:    [email protected]
  S:    Supported
  F:    arch/mips/math-emu/sp_rint.c
@@@ -9302,6 -9206,12 +9304,6 @@@ F:     include/linux/dt-bindings/mux
  F:    include/linux/mux/
  F:    drivers/mux/
  
 -MULTISOUND SOUND DRIVER
 -M:    Andrew Veliath <[email protected]>
 -S:    Maintained
 -F:    Documentation/sound/oss/MultiSound
 -F:    sound/oss/msnd*
 -
  MULTITECH MULTIPORT CARD (ISICOM)
  S:    Orphan
  F:    drivers/tty/isicom.c
@@@ -9330,9 -9240,9 +9332,9 @@@ F:      drivers/gpu/drm/mxsfb
  F:    Documentation/devicetree/bindings/display/mxsfb-drm.txt
  
  MYRICOM MYRI-10G 10GbE DRIVER (MYRI10GE)
 -M:    Hyong-Youb Kim <hykim@myri.com>
 +M:    Chris Lee <christopher.lee@cspi.com>
  L:    [email protected]
 -W:    https://www.myricom.com/support/downloads/myri10ge.html
 +W:    https://www.cspi.com/ethernet-products/support/downloads/
  S:    Supported
  F:    drivers/net/ethernet/myricom/myri10ge/
  
@@@ -9505,7 -9415,6 +9507,7 @@@ M:      Florian Fainelli <[email protected]
  S:    Maintained
  F:    net/dsa/
  F:    include/net/dsa.h
 +F:    include/linux/dsa/
  F:    drivers/net/dsa/
  
  NETWORKING [GENERAL]
@@@ -9526,8 -9435,8 +9528,8 @@@ F:      include/uapi/linux/in.
  F:    include/uapi/linux/net.h
  F:    include/uapi/linux/netdevice.h
  F:    include/uapi/linux/net_namespace.h
 -F:    tools/net/
  F:    tools/testing/selftests/net/
 +F:    lib/net_utils.c
  F:    lib/random32.c
  
  NETWORKING [IPSEC]
@@@ -9728,11 -9637,12 +9730,11 @@@ S:   Supporte
  F:    drivers/ntb/hw/idt/
  
  NTB INTEL DRIVER
 -M:    Jon Mason <[email protected]>
  M:    Dave Jiang <[email protected]>
  L:    [email protected]
  S:    Supported
 -W:    https://github.com/jonmason/ntb/wiki
 -T:    git git://github.com/jonmason/ntb.git
 +W:    https://github.com/davejiang/linux/wiki
 +T:    git https://github.com/davejiang/linux.git
  F:    drivers/ntb/hw/intel/
  
  NTFS FILESYSTEM
@@@ -10128,11 -10038,7 +10130,11 @@@ T: git git://github.com/openrisc/linux.
  L:    [email protected]
  W:    http://openrisc.io
  S:    Maintained
 +F:    Documentation/devicetree/bindings/openrisc/
 +F:    Documentation/openrisc/
  F:    arch/openrisc/
 +F:    drivers/irqchip/irq-ompic.c
 +F:    drivers/irqchip/irq-or1k-*
  
  OPENVSWITCH
  M:    Pravin Shelar <[email protected]>
@@@ -10150,7 -10056,7 +10152,7 @@@ M:   Stephen Boyd <[email protected]
  L:    [email protected]
  S:    Maintained
  T:    git git://git.kernel.org/pub/scm/linux/kernel/git/vireshk/pm.git
 -F:    drivers/base/power/opp/
 +F:    drivers/opp/
  F:    include/linux/pm_opp.h
  F:    Documentation/power/opp.txt
  F:    Documentation/devicetree/bindings/opp/
@@@ -10437,6 -10343,7 +10439,6 @@@ F:   drivers/pci/host/vmd.
  
  PCI DRIVER FOR MICROSEMI SWITCHTEC
  M:    Kurt Schwemmer <[email protected]>
 -M:    Stephen Bates <[email protected]>
  M:    Logan Gunthorpe <[email protected]>
  L:    [email protected]
  S:    Maintained
@@@ -10444,8 -10351,6 +10446,8 @@@ F:   Documentation/switchtec.tx
  F:    Documentation/ABI/testing/sysfs-class-switchtec
  F:    drivers/pci/switch/switchtec*
  F:    include/uapi/linux/switchtec_ioctl.h
 +F:    include/linux/switchtec.h
 +F:    drivers/ntb/hw/mscc/
  
  PCI DRIVER FOR MVEBU (Marvell Armada 370 and Armada XP SOC support)
  M:    Thomas Petazzoni <[email protected]>
@@@ -10503,7 -10408,6 +10505,7 @@@ F:   drivers/pci/dwc/*keystone
  
  PCI ENDPOINT SUBSYSTEM
  M:    Kishon Vijay Abraham I <[email protected]>
 +M:    Lorenzo Pieralisi <[email protected]>
  L:    [email protected]
  T:    git git://git.kernel.org/pub/scm/linux/kernel/git/kishon/pci-endpoint.git
  S:    Supported
@@@ -10555,15 -10459,6 +10557,15 @@@ F: include/linux/pci
  F:    arch/x86/pci/
  F:    arch/x86/kernel/quirks.c
  
 +PCI NATIVE HOST BRIDGE AND ENDPOINT DRIVERS
 +M:    Lorenzo Pieralisi <[email protected]>
 +L:    [email protected]
 +Q:    http://patchwork.ozlabs.org/project/linux-pci/list/
 +T:    git git://git.kernel.org/pub/scm/linux/kernel/git/lpieralisi/pci.git/
 +S:    Supported
 +F:    drivers/pci/host/
 +F:    drivers/pci/dwc/
 +
  PCIE DRIVER FOR AXIS ARTPEC
  M:    Niklas Cassel <[email protected]>
  M:    Jesper Nilsson <[email protected]>
@@@ -10583,6 -10478,7 +10585,6 @@@ F:   drivers/pci/host/pci-thunder-
  
  PCIE DRIVER FOR HISILICON
  M:    Zhou Wang <[email protected]>
 -M:    Gabriele Paoloni <[email protected]>
  L:    [email protected]
  S:    Maintained
  F:    Documentation/devicetree/bindings/pci/hisilicon-pcie.txt
@@@ -10596,14 -10492,6 +10598,14 @@@ S: Maintaine
  F:    Documentation/devicetree/bindings/pci/pcie-kirin.txt
  F:    drivers/pci/dwc/pcie-kirin.c
  
 +PCIE DRIVER FOR HISILICON STB
 +M:    Jianguo Sun <[email protected]>
 +M:    Shawn Guo <[email protected]>
 +L:    [email protected]
 +S:    Maintained
 +F:    Documentation/devicetree/bindings/pci/hisilicon-histb-pcie.txt
 +F:    drivers/pci/dwc/pcie-histb.c
 +
  PCIE DRIVER FOR MEDIATEK
  M:    Ryder Lee <[email protected]>
  L:    [email protected]
@@@ -10627,13 -10515,6 +10629,13 @@@ S: Maintaine
  F:    Documentation/devicetree/bindings/pci/rockchip-pcie.txt
  F:    drivers/pci/host/pcie-rockchip.c
  
 +PCI DRIVER FOR V3 SEMICONDUCTOR V360EPC
 +M:    Linus Walleij <[email protected]>
 +L:    [email protected]
 +S:    Maintained
 +F:    Documentation/devicetree/bindings/pci/v3-v360epc-pci.txt
 +F:    drivers/pci/host/pci-v3-semi.c
 +
  PCIE DRIVER FOR ST SPEAR13XX
  M:    Pratyush Anand <[email protected]>
  L:    [email protected]
@@@ -10664,12 -10545,6 +10666,12 @@@ S: Maintaine
  F:    crypto/pcrypt.c
  F:    include/crypto/pcrypt.h
  
 +PEAQ WMI HOTKEYS DRIVER
 +M:    Hans de Goede <[email protected]>
 +L:    [email protected]
 +S:    Maintained
 +F:    drivers/platform/x86/peaq-wmi.c
 +
  PER-CPU MEMORY ALLOCATOR
  M:    Tejun Heo <[email protected]>
  M:    Christoph Lameter <[email protected]>
@@@ -10783,7 -10658,6 +10785,7 @@@ PIN CONTROLLER - RENESA
  M:    Laurent Pinchart <[email protected]>
  M:    Geert Uytterhoeven <[email protected]>
  L:    [email protected]
 +T:    git git://git.kernel.org/pub/scm/linux/kernel/git/geert/renesas-drivers.git sh-pfc
  S:    Maintained
  F:    drivers/pinctrl/sh-pfc/
  
@@@ -10816,9 -10690,10 +10818,9 @@@ S:  Maintaine
  F:    drivers/pinctrl/spear/
  
  PISTACHIO SOC SUPPORT
 -M:    James Hartley <[email protected]>
 -M:    Ionela Voinescu <[email protected]>
 +M:    James Hartley <[email protected]>
  L:    [email protected]
 -S:    Maintained
 +S:    Odd Fixes
  F:    arch/mips/pistachio/
  F:    arch/mips/include/asm/mach-pistachio/
  F:    arch/mips/boot/dts/img/pistachio*
@@@ -11022,7 -10897,7 +11024,7 @@@ S:   Maintaine
  F:    drivers/block/ps3vram.c
  
  PSAMPLE PACKET SAMPLING SUPPORT:
 -M:    Yotam Gigi <yotamg@mellanox.com>
 +M:    Yotam Gigi <yotam.gi@gmail.com>
  S:    Maintained
  F:    net/psample
  F:    include/net/psample.h
@@@ -11165,6 -11040,7 +11167,6 @@@ F:   drivers/mtd/nand/pxa3xx_nand.
  
  QAT DRIVER
  M:    Giovanni Cabiddu <[email protected]>
 -M:    Salvatore Benedetto <[email protected]>
  L:    [email protected]
  S:    Supported
  F:    drivers/crypto/qat/
@@@ -11212,7 -11088,6 +11214,7 @@@ F:   drivers/net/ethernet/qlogic/qede
  
  QLOGIC QL4xxx RDMA DRIVER
  M:    Ram Amrani <[email protected]>
 +M:    Michal Kalderon <[email protected]>
  M:    Ariel Elior <[email protected]>
  L:    [email protected]
  S:    Supported
@@@ -11583,7 -11458,6 +11585,7 @@@ F:   include/linux/rpmsg
  RENESAS CLOCK DRIVERS
  M:    Geert Uytterhoeven <[email protected]>
  L:    [email protected]
 +T:    git git://git.kernel.org/pub/scm/linux/kernel/git/geert/renesas-drivers.git clk-renesas
  S:    Supported
  F:    drivers/clk/renesas/
  
@@@ -11626,7 -11500,6 +11628,7 @@@ T:   git git://git.kernel.org/pub/scm/lin
  T:    git git://git.kernel.org/pub/scm/linux/kernel/git/jberg/mac80211-next.git
  S:    Maintained
  F:    Documentation/rfkill.txt
 +F:    Documentation/ABI/stable/sysfs-class-rfkill
  F:    net/rfkill/
  
  RHASHTABLE
@@@ -11648,16 -11521,6 +11650,16 @@@ S: Maintaine
  F:    drivers/mtd/nand/r852.c
  F:    drivers/mtd/nand/r852.h
  
 +RISC-V ARCHITECTURE
 +M:    Palmer Dabbelt <[email protected]>
 +M:    Albert Ou <[email protected]>
 +L:    [email protected]
 +T:    git https://github.com/riscv/riscv-linux
 +S:    Supported
 +F:    arch/riscv/
 +K:    riscv
 +N:    riscv
 +
  ROCCAT DRIVERS
  M:    Stefan Achatz <[email protected]>
  W:    http://sourceforge.net/projects/roccat/
@@@ -11666,13 -11529,6 +11668,13 @@@ F: drivers/hid/hid-roccat
  F:    include/linux/hid-roccat*
  F:    Documentation/ABI/*/sysfs-driver-hid-roccat*
  
 +ROCKCHIP RASTER 2D GRAPHIC ACCELERATION UNIT DRIVER
 +M:    Jacob chen <[email protected]>
 +L:    [email protected]
 +S:    Maintained
 +F:    drivers/media/platform/rockchip/rga/
 +F:    Documentation/devicetree/bindings/media/rockchip-rga.txt
 +
  ROCKER DRIVER
  M:    Jiri Pirko <[email protected]>
  L:    [email protected]
  L:    [email protected]
  S:    Maintained
  F:    drivers/crypto/exynos-rng.c
 -F:    Documentation/devicetree/bindings/rng/samsung,exynos-rng4.txt
 +F:    Documentation/devicetree/bindings/crypto/samsung,exynos-rng4.txt
  
  SAMSUNG FRAMEBUFFER DRIVER
  M:    Jingoo Han <[email protected]>
@@@ -12200,15 -12056,10 +12202,15 @@@ L:        [email protected]
  S:    Maintained
  F:    drivers/mmc/host/sdhci-spear.c
  
 +SECURE DIGITAL HOST CONTROLLER INTERFACE (SDHCI) TI OMAP DRIVER
 +M:    Kishon Vijay Abraham I <[email protected]>
 +L:    [email protected]
 +S:    Maintained
 +F:    drivers/mmc/host/sdhci-omap.c
 +
  SECURE ENCRYPTING DEVICE (SED) OPAL DRIVER
  M:    Scott Bauer <[email protected]>
  M:    Jonathan Derrick <[email protected]>
 -M:    Rafael Antognolli <[email protected]>
  L:    [email protected]
  S:    Supported
  F:    block/sed*
@@@ -12609,10 -12460,7 +12611,10 @@@ M: Shaohua Li <[email protected]
  L:    [email protected]
  T:    git git://git.kernel.org/pub/scm/linux/kernel/git/shli/md.git
  S:    Supported
 -F:    drivers/md/
 +F:    drivers/md/Makefile
 +F:    drivers/md/Kconfig
 +F:    drivers/md/md*
 +F:    drivers/md/raid*
  F:    include/linux/raid/
  F:    include/uapi/linux/raid/
  
  S:    Supported
  F:    Documentation/process/stable-kernel-rules.rst
  
 +STAGING - ATOMISP DRIVER
 +M:    Alan Cox <[email protected]>
 +M:    Sakari Ailus <[email protected]>
 +L:    [email protected]
 +S:    Maintained
 +F:    drivers/staging/media/atomisp/
 +
  STAGING - COMEDI
  M:    Ian Abbott <[email protected]>
  M:    H Hartley Sweeten <[email protected]>
@@@ -13072,22 -12913,9 +13074,22 @@@ F: arch/arc/plat-axs10
  F:    arch/arc/boot/dts/ax*
  F:    Documentation/devicetree/bindings/arc/axs10*
  
 +SYNOPSYS AXS10x RESET CONTROLLER DRIVER
 +M:    Eugeniy Paltsev <[email protected]>
 +S:    Supported
 +F:    drivers/reset/reset-axs10x.c
 +F:    Documentation/devicetree/bindings/reset/snps,axs10x-reset.txt
 +
 +SYNOPSYS DESIGNWARE APB GPIO DRIVER
 +M:    Hoan Tran <[email protected]>
 +L:    [email protected]
 +S:    Maintained
 +F:    drivers/gpio/gpio-dwapb.c
 +F:    Documentation/devicetree/bindings/gpio/snps-dwapb-gpio.txt
 +
  SYNOPSYS DESIGNWARE DMAC DRIVER
  M:    Viresh Kumar <[email protected]>
 -M:    Andy Shevchenko <[email protected]>
 +R:    Andy Shevchenko <[email protected]>
  S:    Maintained
  F:    include/linux/dma/dw.h
  F:    include/linux/platform_data/dma-dw.h
@@@ -13468,18 -13296,8 +13470,18 @@@ M: Andreas Noever <andreas.noever@gmail
  M:    Michael Jamet <[email protected]>
  M:    Mika Westerberg <[email protected]>
  M:    Yehezkel Bernat <[email protected]>
 +T:    git git://git.kernel.org/pub/scm/linux/kernel/git/westeri/thunderbolt.git
  S:    Maintained
  F:    drivers/thunderbolt/
 +F:    include/linux/thunderbolt.h
 +
 +THUNDERBOLT NETWORK DRIVER
 +M:    Michael Jamet <[email protected]>
 +M:    Mika Westerberg <[email protected]>
 +M:    Yehezkel Bernat <[email protected]>
 +L:    [email protected]
 +S:    Maintained
 +F:    drivers/net/thunderbolt.c
  
  THUNDERX GPIO DRIVER
  M:    David Daney <[email protected]>
@@@ -13788,14 -13606,23 +13790,14 @@@ F:        drivers/platform/x86/toshiba-wmi.
  
  TPM DEVICE DRIVER
  M:    Peter Huewe <[email protected]>
 -M:    Marcel Selhorst <[email protected]>
  M:    Jarkko Sakkinen <[email protected]>
  R:    Jason Gunthorpe <[email protected]>
 -W:    http://tpmdd.sourceforge.net
 -L:    [email protected] (moderated for non-subscribers)
 -Q:    https://patchwork.kernel.org/project/tpmdd-devel/list/
 +L:    [email protected]
 +Q:    https://patchwork.kernel.org/project/linux-integrity/list/
  T:    git git://git.infradead.org/users/jjs/linux-tpmdd.git
  S:    Maintained
  F:    drivers/char/tpm/
  
 -TPM IBM_VTPM DEVICE DRIVER
 -M:    Ashley Lai <[email protected]>
 -W:    http://tpmdd.sourceforge.net
 -L:    [email protected] (moderated for non-subscribers)
 -S:    Maintained
 -F:    drivers/char/tpm/tpm_ibmvtpm*
 -
  TRACING
  M:    Steven Rostedt <[email protected]>
  M:    Ingo Molnar <[email protected]>
@@@ -13936,7 -13763,7 +13938,7 @@@ UDRAW TABLE
  M:    Bastien Nocera <[email protected]>
  L:    [email protected]
  S:    Maintained
 -F:    drivers/hid/hid-udraw.c
 +F:    drivers/hid/hid-udraw-ps3.c
  
  UFS FILESYSTEM
  M:    Evgeniy Dushistov <[email protected]>
@@@ -14459,15 -14286,12 +14461,15 @@@ S:        Maintaine
  F:    include/linux/virtio_vsock.h
  F:    include/uapi/linux/virtio_vsock.h
  F:    include/uapi/linux/vsockmon.h
 +F:    include/uapi/linux/vm_sockets_diag.h
 +F:    net/vmw_vsock/diag.c
  F:    net/vmw_vsock/af_vsock_tap.c
  F:    net/vmw_vsock/virtio_transport_common.c
  F:    net/vmw_vsock/virtio_transport.c
  F:    drivers/net/vsockmon.c
  F:    drivers/vhost/vsock.c
  F:    drivers/vhost/vsock.h
 +F:    tools/testing/vsock/
  
  VIRTIO CONSOLE DRIVER
  M:    Amit Shah <[email protected]>
  L:    [email protected]
  S:    Supported
  F:    drivers/s390/virtio/
 +F:    arch/s390/include/uapi/asm/virtio-ccw.h
  
  VIRTIO GPU DRIVER
  M:    David Airlie <[email protected]>
@@@ -14564,7 -14387,7 +14566,7 @@@ M:   Manohar Vanga <[email protected]
  M:    Greg Kroah-Hartman <[email protected]>
  L:    [email protected]
  S:    Maintained
 -T:    git git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core.git
 +T:    git git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc.git
  F:    Documentation/driver-api/vme.rst
  F:    drivers/staging/vme/
  F:    drivers/vme/
  S:    Supported
  W:    http://wireless.kernel.org/en/users/Drivers/wil6210
  F:    drivers/net/wireless/ath/wil6210/
 -F:    include/uapi/linux/wil6210_uapi.h
  
  WIMAX STACK
  M:    Inaky Perez-Gonzalez <[email protected]>
@@@ -14781,7 -14605,6 +14783,7 @@@ F:   Documentation/devicetree/bindings/ex
  F:    Documentation/devicetree/bindings/regulator/arizona-regulator.txt
  F:    Documentation/devicetree/bindings/mfd/arizona.txt
  F:    Documentation/devicetree/bindings/mfd/wm831x.txt
 +F:    Documentation/devicetree/bindings/sound/wlf,arizona.txt
  F:    arch/arm/mach-s3c64xx/mach-crag6410*
  F:    drivers/clk/clk-wm83*.c
  F:    drivers/extcon/extcon-arizona.c
@@@ -14915,7 -14738,6 +14917,7 @@@ F:   arch/x86/xen
  F:    drivers/*/xen-*front.c
  F:    drivers/xen/
  F:    arch/x86/include/asm/xen/
 +F:    arch/x86/include/asm/pvclock-abi.h
  F:    include/xen/
  F:    include/uapi/xen/
  F:    Documentation/ABI/stable/sysfs-hypervisor-xen
diff --combined drivers/base/Kconfig
index 2f6614c9a229ab213f8a140a3e0bcc272dcc1bfd,62b0de06836e1e2eba9b098fc5a40a9de5d5b432..2c3cab066871680b9a6a5e778e8deb20b57f99b9
@@@ -1,4 -1,3 +1,4 @@@
 +# SPDX-License-Identifier: GPL-2.0
  menu "Generic Driver Options"
  
  config UEVENT_HELPER
@@@ -245,6 -244,7 +245,7 @@@ config DMA_SHARED_BUFFE
        bool
        default n
        select ANON_INODES
+       select IRQ_WORK
        help
          This option enables the framework for buffer-sharing between
          multiple drivers. A buffer is associated with a file using driver
index f71fe6d2ddda795fd2fb914740b75845893c1298,0000000000000000000000000000000000000000..c324c3b76facb4d1ba3fc75a22a107df9fc353af
mode 100644,000000..100644
--- /dev/null
@@@ -1,4934 -1,0 +1,4932 @@@
-               drm_edid_to_eld(connector, edid);
 +/*
 + * Copyright 2015 Advanced Micro Devices, Inc.
 + *
 + * Permission is hereby granted, free of charge, to any person obtaining a
 + * copy of this software and associated documentation files (the "Software"),
 + * to deal in the Software without restriction, including without limitation
 + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 + * and/or sell copies of the Software, and to permit persons to whom the
 + * Software is furnished to do so, subject to the following conditions:
 + *
 + * The above copyright notice and this permission notice shall be included in
 + * all copies or substantial portions of the Software.
 + *
 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
 + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 + * OTHER DEALINGS IN THE SOFTWARE.
 + *
 + * Authors: AMD
 + *
 + */
 +
 +#include "dm_services_types.h"
 +#include "dc.h"
 +#include "dc/inc/core_types.h"
 +
 +#include "vid.h"
 +#include "amdgpu.h"
 +#include "amdgpu_display.h"
 +#include "atom.h"
 +#include "amdgpu_dm.h"
 +#include "amdgpu_pm.h"
 +
 +#include "amd_shared.h"
 +#include "amdgpu_dm_irq.h"
 +#include "dm_helpers.h"
 +#include "dm_services_types.h"
 +#include "amdgpu_dm_mst_types.h"
 +
 +#include "ivsrcid/ivsrcid_vislands30.h"
 +
 +#include <linux/module.h>
 +#include <linux/moduleparam.h>
 +#include <linux/version.h>
 +#include <linux/types.h>
 +
 +#include <drm/drmP.h>
 +#include <drm/drm_atomic.h>
 +#include <drm/drm_atomic_helper.h>
 +#include <drm/drm_dp_mst_helper.h>
 +#include <drm/drm_fb_helper.h>
 +#include <drm/drm_edid.h>
 +
 +#include "modules/inc/mod_freesync.h"
 +
 +#if defined(CONFIG_DRM_AMD_DC_DCN1_0)
 +#include "ivsrcid/irqsrcs_dcn_1_0.h"
 +
 +#include "raven1/DCN/dcn_1_0_offset.h"
 +#include "raven1/DCN/dcn_1_0_sh_mask.h"
 +#include "vega10/soc15ip.h"
 +
 +#include "soc15_common.h"
 +#endif
 +
 +#include "modules/inc/mod_freesync.h"
 +
 +#include "i2caux_interface.h"
 +
 +/* basic init/fini API */
 +static int amdgpu_dm_init(struct amdgpu_device *adev);
 +static void amdgpu_dm_fini(struct amdgpu_device *adev);
 +
 +/* initializes drm_device display related structures, based on the information
 + * provided by DAL. The drm strcutures are: drm_crtc, drm_connector,
 + * drm_encoder, drm_mode_config
 + *
 + * Returns 0 on success
 + */
 +static int amdgpu_dm_initialize_drm_device(struct amdgpu_device *adev);
 +/* removes and deallocates the drm structures, created by the above function */
 +static void amdgpu_dm_destroy_drm_device(struct amdgpu_display_manager *dm);
 +
 +static void
 +amdgpu_dm_update_connector_after_detect(struct amdgpu_dm_connector *aconnector);
 +
 +static int amdgpu_dm_plane_init(struct amdgpu_display_manager *dm,
 +                              struct amdgpu_plane *aplane,
 +                              unsigned long possible_crtcs);
 +static int amdgpu_dm_crtc_init(struct amdgpu_display_manager *dm,
 +                             struct drm_plane *plane,
 +                             uint32_t link_index);
 +static int amdgpu_dm_connector_init(struct amdgpu_display_manager *dm,
 +                                  struct amdgpu_dm_connector *amdgpu_dm_connector,
 +                                  uint32_t link_index,
 +                                  struct amdgpu_encoder *amdgpu_encoder);
 +static int amdgpu_dm_encoder_init(struct drm_device *dev,
 +                                struct amdgpu_encoder *aencoder,
 +                                uint32_t link_index);
 +
 +static int amdgpu_dm_connector_get_modes(struct drm_connector *connector);
 +
 +static int amdgpu_dm_atomic_commit(struct drm_device *dev,
 +                                 struct drm_atomic_state *state,
 +                                 bool nonblock);
 +
 +static void amdgpu_dm_atomic_commit_tail(struct drm_atomic_state *state);
 +
 +static int amdgpu_dm_atomic_check(struct drm_device *dev,
 +                                struct drm_atomic_state *state);
 +
 +
 +
 +
 +static const enum drm_plane_type dm_plane_type_default[AMDGPU_MAX_PLANES] = {
 +      DRM_PLANE_TYPE_PRIMARY,
 +      DRM_PLANE_TYPE_PRIMARY,
 +      DRM_PLANE_TYPE_PRIMARY,
 +      DRM_PLANE_TYPE_PRIMARY,
 +      DRM_PLANE_TYPE_PRIMARY,
 +      DRM_PLANE_TYPE_PRIMARY,
 +};
 +
 +static const enum drm_plane_type dm_plane_type_carizzo[AMDGPU_MAX_PLANES] = {
 +      DRM_PLANE_TYPE_PRIMARY,
 +      DRM_PLANE_TYPE_PRIMARY,
 +      DRM_PLANE_TYPE_PRIMARY,
 +      DRM_PLANE_TYPE_OVERLAY,/* YUV Capable Underlay */
 +};
 +
 +static const enum drm_plane_type dm_plane_type_stoney[AMDGPU_MAX_PLANES] = {
 +      DRM_PLANE_TYPE_PRIMARY,
 +      DRM_PLANE_TYPE_PRIMARY,
 +      DRM_PLANE_TYPE_OVERLAY, /* YUV Capable Underlay */
 +};
 +
 +/*
 + * dm_vblank_get_counter
 + *
 + * @brief
 + * Get counter for number of vertical blanks
 + *
 + * @param
 + * struct amdgpu_device *adev - [in] desired amdgpu device
 + * int disp_idx - [in] which CRTC to get the counter from
 + *
 + * @return
 + * Counter for vertical blanks
 + */
 +static u32 dm_vblank_get_counter(struct amdgpu_device *adev, int crtc)
 +{
 +      if (crtc >= adev->mode_info.num_crtc)
 +              return 0;
 +      else {
 +              struct amdgpu_crtc *acrtc = adev->mode_info.crtcs[crtc];
 +              struct dm_crtc_state *acrtc_state = to_dm_crtc_state(
 +                              acrtc->base.state);
 +
 +
 +              if (acrtc_state->stream == NULL) {
 +                      DRM_ERROR("dc_stream_state is NULL for crtc '%d'!\n",
 +                                crtc);
 +                      return 0;
 +              }
 +
 +              return dc_stream_get_vblank_counter(acrtc_state->stream);
 +      }
 +}
 +
 +static int dm_crtc_get_scanoutpos(struct amdgpu_device *adev, int crtc,
 +                                u32 *vbl, u32 *position)
 +{
 +      uint32_t v_blank_start, v_blank_end, h_position, v_position;
 +
 +      if ((crtc < 0) || (crtc >= adev->mode_info.num_crtc))
 +              return -EINVAL;
 +      else {
 +              struct amdgpu_crtc *acrtc = adev->mode_info.crtcs[crtc];
 +              struct dm_crtc_state *acrtc_state = to_dm_crtc_state(
 +                                              acrtc->base.state);
 +
 +              if (acrtc_state->stream ==  NULL) {
 +                      DRM_ERROR("dc_stream_state is NULL for crtc '%d'!\n",
 +                                crtc);
 +                      return 0;
 +              }
 +
 +              /*
 +               * TODO rework base driver to use values directly.
 +               * for now parse it back into reg-format
 +               */
 +              dc_stream_get_scanoutpos(acrtc_state->stream,
 +                                       &v_blank_start,
 +                                       &v_blank_end,
 +                                       &h_position,
 +                                       &v_position);
 +
 +              *position = v_position | (h_position << 16);
 +              *vbl = v_blank_start | (v_blank_end << 16);
 +      }
 +
 +      return 0;
 +}
 +
 +static bool dm_is_idle(void *handle)
 +{
 +      /* XXX todo */
 +      return true;
 +}
 +
 +static int dm_wait_for_idle(void *handle)
 +{
 +      /* XXX todo */
 +      return 0;
 +}
 +
 +static bool dm_check_soft_reset(void *handle)
 +{
 +      return false;
 +}
 +
 +static int dm_soft_reset(void *handle)
 +{
 +      /* XXX todo */
 +      return 0;
 +}
 +
 +static struct amdgpu_crtc *
 +get_crtc_by_otg_inst(struct amdgpu_device *adev,
 +                   int otg_inst)
 +{
 +      struct drm_device *dev = adev->ddev;
 +      struct drm_crtc *crtc;
 +      struct amdgpu_crtc *amdgpu_crtc;
 +
 +      /*
 +       * following if is check inherited from both functions where this one is
 +       * used now. Need to be checked why it could happen.
 +       */
 +      if (otg_inst == -1) {
 +              WARN_ON(1);
 +              return adev->mode_info.crtcs[0];
 +      }
 +
 +      list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
 +              amdgpu_crtc = to_amdgpu_crtc(crtc);
 +
 +              if (amdgpu_crtc->otg_inst == otg_inst)
 +                      return amdgpu_crtc;
 +      }
 +
 +      return NULL;
 +}
 +
 +static void dm_pflip_high_irq(void *interrupt_params)
 +{
 +      struct amdgpu_crtc *amdgpu_crtc;
 +      struct common_irq_params *irq_params = interrupt_params;
 +      struct amdgpu_device *adev = irq_params->adev;
 +      unsigned long flags;
 +
 +      amdgpu_crtc = get_crtc_by_otg_inst(adev, irq_params->irq_src - IRQ_TYPE_PFLIP);
 +
 +      /* IRQ could occur when in initial stage */
 +      /*TODO work and BO cleanup */
 +      if (amdgpu_crtc == NULL) {
 +              DRM_DEBUG_DRIVER("CRTC is null, returning.\n");
 +              return;
 +      }
 +
 +      spin_lock_irqsave(&adev->ddev->event_lock, flags);
 +
 +      if (amdgpu_crtc->pflip_status != AMDGPU_FLIP_SUBMITTED){
 +              DRM_DEBUG_DRIVER("amdgpu_crtc->pflip_status = %d !=AMDGPU_FLIP_SUBMITTED(%d) on crtc:%d[%p] \n",
 +                                               amdgpu_crtc->pflip_status,
 +                                               AMDGPU_FLIP_SUBMITTED,
 +                                               amdgpu_crtc->crtc_id,
 +                                               amdgpu_crtc);
 +              spin_unlock_irqrestore(&adev->ddev->event_lock, flags);
 +              return;
 +      }
 +
 +
 +      /* wakeup usersapce */
 +      if (amdgpu_crtc->event) {
 +              /* Update to correct count/ts if racing with vblank irq */
 +              drm_crtc_accurate_vblank_count(&amdgpu_crtc->base);
 +
 +              drm_crtc_send_vblank_event(&amdgpu_crtc->base, amdgpu_crtc->event);
 +
 +              /* page flip completed. clean up */
 +              amdgpu_crtc->event = NULL;
 +
 +      } else
 +              WARN_ON(1);
 +
 +      amdgpu_crtc->pflip_status = AMDGPU_FLIP_NONE;
 +      spin_unlock_irqrestore(&adev->ddev->event_lock, flags);
 +
 +      DRM_DEBUG_DRIVER("%s - crtc :%d[%p], pflip_stat:AMDGPU_FLIP_NONE\n",
 +                                      __func__, amdgpu_crtc->crtc_id, amdgpu_crtc);
 +
 +      drm_crtc_vblank_put(&amdgpu_crtc->base);
 +}
 +
 +static void dm_crtc_high_irq(void *interrupt_params)
 +{
 +      struct common_irq_params *irq_params = interrupt_params;
 +      struct amdgpu_device *adev = irq_params->adev;
 +      uint8_t crtc_index = 0;
 +      struct amdgpu_crtc *acrtc;
 +
 +      acrtc = get_crtc_by_otg_inst(adev, irq_params->irq_src - IRQ_TYPE_VBLANK);
 +
 +      if (acrtc)
 +              crtc_index = acrtc->crtc_id;
 +
 +      drm_handle_vblank(adev->ddev, crtc_index);
 +}
 +
 +static int dm_set_clockgating_state(void *handle,
 +                enum amd_clockgating_state state)
 +{
 +      return 0;
 +}
 +
 +static int dm_set_powergating_state(void *handle,
 +                enum amd_powergating_state state)
 +{
 +      return 0;
 +}
 +
 +/* Prototypes of private functions */
 +static int dm_early_init(void* handle);
 +
 +static void hotplug_notify_work_func(struct work_struct *work)
 +{
 +      struct amdgpu_display_manager *dm = container_of(work, struct amdgpu_display_manager, mst_hotplug_work);
 +      struct drm_device *dev = dm->ddev;
 +
 +      drm_kms_helper_hotplug_event(dev);
 +}
 +
 +#if defined(CONFIG_DRM_AMD_DC_FBC)
 +#include "dal_asic_id.h"
 +/* Allocate memory for FBC compressed data  */
 +/* TODO: Dynamic allocation */
 +#define AMDGPU_FBC_SIZE    (3840 * 2160 * 4)
 +
 +static void amdgpu_dm_initialize_fbc(struct amdgpu_device *adev)
 +{
 +      int r;
 +      struct dm_comressor_info *compressor = &adev->dm.compressor;
 +
 +      if (!compressor->bo_ptr) {
 +              r = amdgpu_bo_create_kernel(adev, AMDGPU_FBC_SIZE, PAGE_SIZE,
 +                              AMDGPU_GEM_DOMAIN_VRAM, &compressor->bo_ptr,
 +                              &compressor->gpu_addr, &compressor->cpu_addr);
 +
 +              if (r)
 +                      DRM_ERROR("DM: Failed to initialize fbc\n");
 +      }
 +
 +}
 +#endif
 +
 +
 +/* Init display KMS
 + *
 + * Returns 0 on success
 + */
 +static int amdgpu_dm_init(struct amdgpu_device *adev)
 +{
 +      struct dc_init_data init_data;
 +      adev->dm.ddev = adev->ddev;
 +      adev->dm.adev = adev;
 +
 +      /* Zero all the fields */
 +      memset(&init_data, 0, sizeof(init_data));
 +
 +      /* initialize DAL's lock (for SYNC context use) */
 +      spin_lock_init(&adev->dm.dal_lock);
 +
 +      /* initialize DAL's mutex */
 +      mutex_init(&adev->dm.dal_mutex);
 +
 +      if(amdgpu_dm_irq_init(adev)) {
 +              DRM_ERROR("amdgpu: failed to initialize DM IRQ support.\n");
 +              goto error;
 +      }
 +
 +      init_data.asic_id.chip_family = adev->family;
 +
 +      init_data.asic_id.pci_revision_id = adev->rev_id;
 +      init_data.asic_id.hw_internal_rev = adev->external_rev_id;
 +
 +      init_data.asic_id.vram_width = adev->mc.vram_width;
 +      /* TODO: initialize init_data.asic_id.vram_type here!!!! */
 +      init_data.asic_id.atombios_base_address =
 +              adev->mode_info.atom_context->bios;
 +
 +      init_data.driver = adev;
 +
 +      adev->dm.cgs_device = amdgpu_cgs_create_device(adev);
 +
 +      if (!adev->dm.cgs_device) {
 +              DRM_ERROR("amdgpu: failed to create cgs device.\n");
 +              goto error;
 +      }
 +
 +      init_data.cgs_device = adev->dm.cgs_device;
 +
 +      adev->dm.dal = NULL;
 +
 +      init_data.dce_environment = DCE_ENV_PRODUCTION_DRV;
 +
 +      if (amdgpu_dc_log)
 +              init_data.log_mask = DC_DEFAULT_LOG_MASK;
 +      else
 +              init_data.log_mask = DC_MIN_LOG_MASK;
 +
 +#if defined(CONFIG_DRM_AMD_DC_FBC)
 +      if (adev->family == FAMILY_CZ)
 +              amdgpu_dm_initialize_fbc(adev);
 +      init_data.fbc_gpu_addr = adev->dm.compressor.gpu_addr;
 +#endif
 +      /* Display Core create. */
 +      adev->dm.dc = dc_create(&init_data);
 +
 +      if (adev->dm.dc) {
 +              DRM_INFO("Display Core initialized!\n");
 +      } else {
 +              DRM_INFO("Display Core failed to initialize!\n");
 +              goto error;
 +      }
 +
 +      INIT_WORK(&adev->dm.mst_hotplug_work, hotplug_notify_work_func);
 +
 +      adev->dm.freesync_module = mod_freesync_create(adev->dm.dc);
 +      if (!adev->dm.freesync_module) {
 +              DRM_ERROR(
 +              "amdgpu: failed to initialize freesync_module.\n");
 +      } else
 +              DRM_DEBUG_DRIVER("amdgpu: freesync_module init done %p.\n",
 +                              adev->dm.freesync_module);
 +
 +      if (amdgpu_dm_initialize_drm_device(adev)) {
 +              DRM_ERROR(
 +              "amdgpu: failed to initialize sw for display support.\n");
 +              goto error;
 +      }
 +
 +      /* Update the actual used number of crtc */
 +      adev->mode_info.num_crtc = adev->dm.display_indexes_num;
 +
 +      /* TODO: Add_display_info? */
 +
 +      /* TODO use dynamic cursor width */
 +      adev->ddev->mode_config.cursor_width = adev->dm.dc->caps.max_cursor_size;
 +      adev->ddev->mode_config.cursor_height = adev->dm.dc->caps.max_cursor_size;
 +
 +      if (drm_vblank_init(adev->ddev, adev->dm.display_indexes_num)) {
 +              DRM_ERROR(
 +              "amdgpu: failed to initialize sw for display support.\n");
 +              goto error;
 +      }
 +
 +      DRM_DEBUG_DRIVER("KMS initialized.\n");
 +
 +      return 0;
 +error:
 +      amdgpu_dm_fini(adev);
 +
 +      return -1;
 +}
 +
 +static void amdgpu_dm_fini(struct amdgpu_device *adev)
 +{
 +      amdgpu_dm_destroy_drm_device(&adev->dm);
 +      /*
 +       * TODO: pageflip, vlank interrupt
 +       *
 +       * amdgpu_dm_irq_fini(adev);
 +       */
 +
 +      if (adev->dm.cgs_device) {
 +              amdgpu_cgs_destroy_device(adev->dm.cgs_device);
 +              adev->dm.cgs_device = NULL;
 +      }
 +      if (adev->dm.freesync_module) {
 +              mod_freesync_destroy(adev->dm.freesync_module);
 +              adev->dm.freesync_module = NULL;
 +      }
 +      /* DC Destroy TODO: Replace destroy DAL */
 +      if (adev->dm.dc)
 +              dc_destroy(&adev->dm.dc);
 +      return;
 +}
 +
 +static int dm_sw_init(void *handle)
 +{
 +      return 0;
 +}
 +
 +static int dm_sw_fini(void *handle)
 +{
 +      return 0;
 +}
 +
 +static int detect_mst_link_for_all_connectors(struct drm_device *dev)
 +{
 +      struct amdgpu_dm_connector *aconnector;
 +      struct drm_connector *connector;
 +      int ret = 0;
 +
 +      drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
 +
 +      list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
 +              aconnector = to_amdgpu_dm_connector(connector);
 +              if (aconnector->dc_link->type == dc_connection_mst_branch &&
 +                  aconnector->mst_mgr.aux) {
 +                      DRM_DEBUG_DRIVER("DM_MST: starting TM on aconnector: %p [id: %d]\n",
 +                                      aconnector, aconnector->base.base.id);
 +
 +                      ret = drm_dp_mst_topology_mgr_set_mst(&aconnector->mst_mgr, true);
 +                      if (ret < 0) {
 +                              DRM_ERROR("DM_MST: Failed to start MST\n");
 +                              ((struct dc_link *)aconnector->dc_link)->type = dc_connection_single;
 +                              return ret;
 +                              }
 +                      }
 +      }
 +
 +      drm_modeset_unlock(&dev->mode_config.connection_mutex);
 +      return ret;
 +}
 +
 +static int dm_late_init(void *handle)
 +{
 +      struct drm_device *dev = ((struct amdgpu_device *)handle)->ddev;
 +
 +      return detect_mst_link_for_all_connectors(dev);
 +}
 +
 +static void s3_handle_mst(struct drm_device *dev, bool suspend)
 +{
 +      struct amdgpu_dm_connector *aconnector;
 +      struct drm_connector *connector;
 +
 +      drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
 +
 +      list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
 +                 aconnector = to_amdgpu_dm_connector(connector);
 +                 if (aconnector->dc_link->type == dc_connection_mst_branch &&
 +                                 !aconnector->mst_port) {
 +
 +                         if (suspend)
 +                                 drm_dp_mst_topology_mgr_suspend(&aconnector->mst_mgr);
 +                         else
 +                                 drm_dp_mst_topology_mgr_resume(&aconnector->mst_mgr);
 +                 }
 +      }
 +
 +      drm_modeset_unlock(&dev->mode_config.connection_mutex);
 +}
 +
 +static int dm_hw_init(void *handle)
 +{
 +      struct amdgpu_device *adev = (struct amdgpu_device *)handle;
 +      /* Create DAL display manager */
 +      amdgpu_dm_init(adev);
 +      amdgpu_dm_hpd_init(adev);
 +
 +      return 0;
 +}
 +
 +static int dm_hw_fini(void *handle)
 +{
 +      struct amdgpu_device *adev = (struct amdgpu_device *)handle;
 +
 +      amdgpu_dm_hpd_fini(adev);
 +
 +      amdgpu_dm_irq_fini(adev);
 +      amdgpu_dm_fini(adev);
 +      return 0;
 +}
 +
 +static int dm_suspend(void *handle)
 +{
 +      struct amdgpu_device *adev = handle;
 +      struct amdgpu_display_manager *dm = &adev->dm;
 +      int ret = 0;
 +
 +      s3_handle_mst(adev->ddev, true);
 +
 +      amdgpu_dm_irq_suspend(adev);
 +
 +      WARN_ON(adev->dm.cached_state);
 +      adev->dm.cached_state = drm_atomic_helper_suspend(adev->ddev);
 +
 +      dc_set_power_state(dm->dc, DC_ACPI_CM_POWER_STATE_D3);
 +
 +      return ret;
 +}
 +
 +static struct amdgpu_dm_connector *
 +amdgpu_dm_find_first_crtc_matching_connector(struct drm_atomic_state *state,
 +                                           struct drm_crtc *crtc)
 +{
 +      uint32_t i;
 +      struct drm_connector_state *new_con_state;
 +      struct drm_connector *connector;
 +      struct drm_crtc *crtc_from_state;
 +
 +      for_each_new_connector_in_state(state, connector, new_con_state, i) {
 +              crtc_from_state = new_con_state->crtc;
 +
 +              if (crtc_from_state == crtc)
 +                      return to_amdgpu_dm_connector(connector);
 +      }
 +
 +      return NULL;
 +}
 +
 +static int dm_resume(void *handle)
 +{
 +      struct amdgpu_device *adev = handle;
 +      struct amdgpu_display_manager *dm = &adev->dm;
 +
 +      /* power on hardware */
 +      dc_set_power_state(dm->dc, DC_ACPI_CM_POWER_STATE_D0);
 +
 +      return 0;
 +}
 +
 +int amdgpu_dm_display_resume(struct amdgpu_device *adev)
 +{
 +      struct drm_device *ddev = adev->ddev;
 +      struct amdgpu_display_manager *dm = &adev->dm;
 +      struct amdgpu_dm_connector *aconnector;
 +      struct drm_connector *connector;
 +      struct drm_crtc *crtc;
 +      struct drm_crtc_state *new_crtc_state;
 +      struct dm_crtc_state *dm_new_crtc_state;
 +      struct drm_plane *plane;
 +      struct drm_plane_state *new_plane_state;
 +      struct dm_plane_state *dm_new_plane_state;
 +
 +      int ret = 0;
 +      int i;
 +
 +      /* program HPD filter */
 +      dc_resume(dm->dc);
 +
 +      /* On resume we need to  rewrite the MSTM control bits to enamble MST*/
 +      s3_handle_mst(ddev, false);
 +
 +      /*
 +       * early enable HPD Rx IRQ, should be done before set mode as short
 +       * pulse interrupts are used for MST
 +       */
 +      amdgpu_dm_irq_resume_early(adev);
 +
 +      /* Do detection*/
 +      list_for_each_entry(connector,
 +                      &ddev->mode_config.connector_list, head) {
 +              aconnector = to_amdgpu_dm_connector(connector);
 +
 +              /*
 +               * this is the case when traversing through already created
 +               * MST connectors, should be skipped
 +               */
 +              if (aconnector->mst_port)
 +                      continue;
 +
 +              mutex_lock(&aconnector->hpd_lock);
 +              dc_link_detect(aconnector->dc_link, DETECT_REASON_HPD);
 +
 +              if (aconnector->fake_enable && aconnector->dc_link->local_sink)
 +                      aconnector->fake_enable = false;
 +
 +              aconnector->dc_sink = NULL;
 +              amdgpu_dm_update_connector_after_detect(aconnector);
 +              mutex_unlock(&aconnector->hpd_lock);
 +      }
 +
 +      /* Force mode set in atomic comit */
 +      for_each_new_crtc_in_state(adev->dm.cached_state, crtc, new_crtc_state, i)
 +              new_crtc_state->active_changed = true;
 +
 +      /*
 +       * atomic_check is expected to create the dc states. We need to release
 +       * them here, since they were duplicated as part of the suspend
 +       * procedure.
 +       */
 +      for_each_new_crtc_in_state(adev->dm.cached_state, crtc, new_crtc_state, i) {
 +              dm_new_crtc_state = to_dm_crtc_state(new_crtc_state);
 +              if (dm_new_crtc_state->stream) {
 +                      WARN_ON(kref_read(&dm_new_crtc_state->stream->refcount) > 1);
 +                      dc_stream_release(dm_new_crtc_state->stream);
 +                      dm_new_crtc_state->stream = NULL;
 +              }
 +      }
 +
 +      for_each_new_plane_in_state(adev->dm.cached_state, plane, new_plane_state, i) {
 +              dm_new_plane_state = to_dm_plane_state(new_plane_state);
 +              if (dm_new_plane_state->dc_state) {
 +                      WARN_ON(kref_read(&dm_new_plane_state->dc_state->refcount) > 1);
 +                      dc_plane_state_release(dm_new_plane_state->dc_state);
 +                      dm_new_plane_state->dc_state = NULL;
 +              }
 +      }
 +
 +      ret = drm_atomic_helper_resume(ddev, adev->dm.cached_state);
 +
 +      adev->dm.cached_state = NULL;
 +
 +      amdgpu_dm_irq_resume_late(adev);
 +
 +      return ret;
 +}
 +
 +static const struct amd_ip_funcs amdgpu_dm_funcs = {
 +      .name = "dm",
 +      .early_init = dm_early_init,
 +      .late_init = dm_late_init,
 +      .sw_init = dm_sw_init,
 +      .sw_fini = dm_sw_fini,
 +      .hw_init = dm_hw_init,
 +      .hw_fini = dm_hw_fini,
 +      .suspend = dm_suspend,
 +      .resume = dm_resume,
 +      .is_idle = dm_is_idle,
 +      .wait_for_idle = dm_wait_for_idle,
 +      .check_soft_reset = dm_check_soft_reset,
 +      .soft_reset = dm_soft_reset,
 +      .set_clockgating_state = dm_set_clockgating_state,
 +      .set_powergating_state = dm_set_powergating_state,
 +};
 +
 +const struct amdgpu_ip_block_version dm_ip_block =
 +{
 +      .type = AMD_IP_BLOCK_TYPE_DCE,
 +      .major = 1,
 +      .minor = 0,
 +      .rev = 0,
 +      .funcs = &amdgpu_dm_funcs,
 +};
 +
 +
 +static struct drm_atomic_state *
 +dm_atomic_state_alloc(struct drm_device *dev)
 +{
 +      struct dm_atomic_state *state = kzalloc(sizeof(*state), GFP_KERNEL);
 +
 +      if (!state)
 +              return NULL;
 +
 +      if (drm_atomic_state_init(dev, &state->base) < 0)
 +              goto fail;
 +
 +      return &state->base;
 +
 +fail:
 +      kfree(state);
 +      return NULL;
 +}
 +
 +static void
 +dm_atomic_state_clear(struct drm_atomic_state *state)
 +{
 +      struct dm_atomic_state *dm_state = to_dm_atomic_state(state);
 +
 +      if (dm_state->context) {
 +              dc_release_state(dm_state->context);
 +              dm_state->context = NULL;
 +      }
 +
 +      drm_atomic_state_default_clear(state);
 +}
 +
 +static void
 +dm_atomic_state_alloc_free(struct drm_atomic_state *state)
 +{
 +      struct dm_atomic_state *dm_state = to_dm_atomic_state(state);
 +      drm_atomic_state_default_release(state);
 +      kfree(dm_state);
 +}
 +
 +static const struct drm_mode_config_funcs amdgpu_dm_mode_funcs = {
 +      .fb_create = amdgpu_user_framebuffer_create,
 +      .output_poll_changed = amdgpu_output_poll_changed,
 +      .atomic_check = amdgpu_dm_atomic_check,
 +      .atomic_commit = amdgpu_dm_atomic_commit,
 +      .atomic_state_alloc = dm_atomic_state_alloc,
 +      .atomic_state_clear = dm_atomic_state_clear,
 +      .atomic_state_free = dm_atomic_state_alloc_free
 +};
 +
 +static struct drm_mode_config_helper_funcs amdgpu_dm_mode_config_helperfuncs = {
 +      .atomic_commit_tail = amdgpu_dm_atomic_commit_tail
 +};
 +
 +static void
 +amdgpu_dm_update_connector_after_detect(struct amdgpu_dm_connector *aconnector)
 +{
 +      struct drm_connector *connector = &aconnector->base;
 +      struct drm_device *dev = connector->dev;
 +      struct dc_sink *sink;
 +
 +      /* MST handled by drm_mst framework */
 +      if (aconnector->mst_mgr.mst_state == true)
 +              return;
 +
 +
 +      sink = aconnector->dc_link->local_sink;
 +
 +      /* Edid mgmt connector gets first update only in mode_valid hook and then
 +       * the connector sink is set to either fake or physical sink depends on link status.
 +       * don't do it here if u are during boot
 +       */
 +      if (aconnector->base.force != DRM_FORCE_UNSPECIFIED
 +                      && aconnector->dc_em_sink) {
 +
 +              /* For S3 resume with headless use eml_sink to fake stream
 +               * because on resume connecotr->sink is set ti NULL
 +               */
 +              mutex_lock(&dev->mode_config.mutex);
 +
 +              if (sink) {
 +                      if (aconnector->dc_sink) {
 +                              amdgpu_dm_remove_sink_from_freesync_module(
 +                                                              connector);
 +                              /* retain and release bellow are used for
 +                               * bump up refcount for sink because the link don't point
 +                               * to it anymore after disconnect so on next crtc to connector
 +                               * reshuffle by UMD we will get into unwanted dc_sink release
 +                               */
 +                              if (aconnector->dc_sink != aconnector->dc_em_sink)
 +                                      dc_sink_release(aconnector->dc_sink);
 +                      }
 +                      aconnector->dc_sink = sink;
 +                      amdgpu_dm_add_sink_to_freesync_module(
 +                                              connector, aconnector->edid);
 +              } else {
 +                      amdgpu_dm_remove_sink_from_freesync_module(connector);
 +                      if (!aconnector->dc_sink)
 +                              aconnector->dc_sink = aconnector->dc_em_sink;
 +                      else if (aconnector->dc_sink != aconnector->dc_em_sink)
 +                              dc_sink_retain(aconnector->dc_sink);
 +              }
 +
 +              mutex_unlock(&dev->mode_config.mutex);
 +              return;
 +      }
 +
 +      /*
 +       * TODO: temporary guard to look for proper fix
 +       * if this sink is MST sink, we should not do anything
 +       */
 +      if (sink && sink->sink_signal == SIGNAL_TYPE_DISPLAY_PORT_MST)
 +              return;
 +
 +      if (aconnector->dc_sink == sink) {
 +              /* We got a DP short pulse (Link Loss, DP CTS, etc...).
 +               * Do nothing!! */
 +              DRM_DEBUG_DRIVER("DCHPD: connector_id=%d: dc_sink didn't change.\n",
 +                              aconnector->connector_id);
 +              return;
 +      }
 +
 +      DRM_DEBUG_DRIVER("DCHPD: connector_id=%d: Old sink=%p New sink=%p\n",
 +              aconnector->connector_id, aconnector->dc_sink, sink);
 +
 +      mutex_lock(&dev->mode_config.mutex);
 +
 +      /* 1. Update status of the drm connector
 +       * 2. Send an event and let userspace tell us what to do */
 +      if (sink) {
 +              /* TODO: check if we still need the S3 mode update workaround.
 +               * If yes, put it here. */
 +              if (aconnector->dc_sink)
 +                      amdgpu_dm_remove_sink_from_freesync_module(
 +                                                      connector);
 +
 +              aconnector->dc_sink = sink;
 +              if (sink->dc_edid.length == 0) {
 +                      aconnector->edid = NULL;
 +              } else {
 +                      aconnector->edid =
 +                              (struct edid *) sink->dc_edid.raw_edid;
 +
 +
 +                      drm_mode_connector_update_edid_property(connector,
 +                                      aconnector->edid);
 +              }
 +              amdgpu_dm_add_sink_to_freesync_module(connector, aconnector->edid);
 +
 +      } else {
 +              amdgpu_dm_remove_sink_from_freesync_module(connector);
 +              drm_mode_connector_update_edid_property(connector, NULL);
 +              aconnector->num_modes = 0;
 +              aconnector->dc_sink = NULL;
 +      }
 +
 +      mutex_unlock(&dev->mode_config.mutex);
 +}
 +
 +static void handle_hpd_irq(void *param)
 +{
 +      struct amdgpu_dm_connector *aconnector = (struct amdgpu_dm_connector *)param;
 +      struct drm_connector *connector = &aconnector->base;
 +      struct drm_device *dev = connector->dev;
 +
 +      /* In case of failure or MST no need to update connector status or notify the OS
 +       * since (for MST case) MST does this in it's own context.
 +       */
 +      mutex_lock(&aconnector->hpd_lock);
 +
 +      if (aconnector->fake_enable)
 +              aconnector->fake_enable = false;
 +
 +      if (dc_link_detect(aconnector->dc_link, DETECT_REASON_HPD)) {
 +              amdgpu_dm_update_connector_after_detect(aconnector);
 +
 +
 +              drm_modeset_lock_all(dev);
 +              dm_restore_drm_connector_state(dev, connector);
 +              drm_modeset_unlock_all(dev);
 +
 +              if (aconnector->base.force == DRM_FORCE_UNSPECIFIED)
 +                      drm_kms_helper_hotplug_event(dev);
 +      }
 +      mutex_unlock(&aconnector->hpd_lock);
 +
 +}
 +
 +static void dm_handle_hpd_rx_irq(struct amdgpu_dm_connector *aconnector)
 +{
 +      uint8_t esi[DP_PSR_ERROR_STATUS - DP_SINK_COUNT_ESI] = { 0 };
 +      uint8_t dret;
 +      bool new_irq_handled = false;
 +      int dpcd_addr;
 +      int dpcd_bytes_to_read;
 +
 +      const int max_process_count = 30;
 +      int process_count = 0;
 +
 +      const struct dc_link_status *link_status = dc_link_get_status(aconnector->dc_link);
 +
 +      if (link_status->dpcd_caps->dpcd_rev.raw < 0x12) {
 +              dpcd_bytes_to_read = DP_LANE0_1_STATUS - DP_SINK_COUNT;
 +              /* DPCD 0x200 - 0x201 for downstream IRQ */
 +              dpcd_addr = DP_SINK_COUNT;
 +      } else {
 +              dpcd_bytes_to_read = DP_PSR_ERROR_STATUS - DP_SINK_COUNT_ESI;
 +              /* DPCD 0x2002 - 0x2005 for downstream IRQ */
 +              dpcd_addr = DP_SINK_COUNT_ESI;
 +      }
 +
 +      dret = drm_dp_dpcd_read(
 +              &aconnector->dm_dp_aux.aux,
 +              dpcd_addr,
 +              esi,
 +              dpcd_bytes_to_read);
 +
 +      while (dret == dpcd_bytes_to_read &&
 +              process_count < max_process_count) {
 +              uint8_t retry;
 +              dret = 0;
 +
 +              process_count++;
 +
 +              DRM_DEBUG_DRIVER("ESI %02x %02x %02x\n", esi[0], esi[1], esi[2]);
 +              /* handle HPD short pulse irq */
 +              if (aconnector->mst_mgr.mst_state)
 +                      drm_dp_mst_hpd_irq(
 +                              &aconnector->mst_mgr,
 +                              esi,
 +                              &new_irq_handled);
 +
 +              if (new_irq_handled) {
 +                      /* ACK at DPCD to notify down stream */
 +                      const int ack_dpcd_bytes_to_write =
 +                              dpcd_bytes_to_read - 1;
 +
 +                      for (retry = 0; retry < 3; retry++) {
 +                              uint8_t wret;
 +
 +                              wret = drm_dp_dpcd_write(
 +                                      &aconnector->dm_dp_aux.aux,
 +                                      dpcd_addr + 1,
 +                                      &esi[1],
 +                                      ack_dpcd_bytes_to_write);
 +                              if (wret == ack_dpcd_bytes_to_write)
 +                                      break;
 +                      }
 +
 +                      /* check if there is new irq to be handle */
 +                      dret = drm_dp_dpcd_read(
 +                              &aconnector->dm_dp_aux.aux,
 +                              dpcd_addr,
 +                              esi,
 +                              dpcd_bytes_to_read);
 +
 +                      new_irq_handled = false;
 +              } else {
 +                      break;
 +              }
 +      }
 +
 +      if (process_count == max_process_count)
 +              DRM_DEBUG_DRIVER("Loop exceeded max iterations\n");
 +}
 +
 +static void handle_hpd_rx_irq(void *param)
 +{
 +      struct amdgpu_dm_connector *aconnector = (struct amdgpu_dm_connector *)param;
 +      struct drm_connector *connector = &aconnector->base;
 +      struct drm_device *dev = connector->dev;
 +      struct dc_link *dc_link = aconnector->dc_link;
 +      bool is_mst_root_connector = aconnector->mst_mgr.mst_state;
 +
 +      /* TODO:Temporary add mutex to protect hpd interrupt not have a gpio
 +       * conflict, after implement i2c helper, this mutex should be
 +       * retired.
 +       */
 +      if (dc_link->type != dc_connection_mst_branch)
 +              mutex_lock(&aconnector->hpd_lock);
 +
 +      if (dc_link_handle_hpd_rx_irq(dc_link, NULL) &&
 +                      !is_mst_root_connector) {
 +              /* Downstream Port status changed. */
 +              if (dc_link_detect(dc_link, DETECT_REASON_HPDRX)) {
 +                      amdgpu_dm_update_connector_after_detect(aconnector);
 +
 +
 +                      drm_modeset_lock_all(dev);
 +                      dm_restore_drm_connector_state(dev, connector);
 +                      drm_modeset_unlock_all(dev);
 +
 +                      drm_kms_helper_hotplug_event(dev);
 +              }
 +      }
 +      if ((dc_link->cur_link_settings.lane_count != LANE_COUNT_UNKNOWN) ||
 +          (dc_link->type == dc_connection_mst_branch))
 +              dm_handle_hpd_rx_irq(aconnector);
 +
 +      if (dc_link->type != dc_connection_mst_branch)
 +              mutex_unlock(&aconnector->hpd_lock);
 +}
 +
 +static void register_hpd_handlers(struct amdgpu_device *adev)
 +{
 +      struct drm_device *dev = adev->ddev;
 +      struct drm_connector *connector;
 +      struct amdgpu_dm_connector *aconnector;
 +      const struct dc_link *dc_link;
 +      struct dc_interrupt_params int_params = {0};
 +
 +      int_params.requested_polarity = INTERRUPT_POLARITY_DEFAULT;
 +      int_params.current_polarity = INTERRUPT_POLARITY_DEFAULT;
 +
 +      list_for_each_entry(connector,
 +                      &dev->mode_config.connector_list, head) {
 +
 +              aconnector = to_amdgpu_dm_connector(connector);
 +              dc_link = aconnector->dc_link;
 +
 +              if (DC_IRQ_SOURCE_INVALID != dc_link->irq_source_hpd) {
 +                      int_params.int_context = INTERRUPT_LOW_IRQ_CONTEXT;
 +                      int_params.irq_source = dc_link->irq_source_hpd;
 +
 +                      amdgpu_dm_irq_register_interrupt(adev, &int_params,
 +                                      handle_hpd_irq,
 +                                      (void *) aconnector);
 +              }
 +
 +              if (DC_IRQ_SOURCE_INVALID != dc_link->irq_source_hpd_rx) {
 +
 +                      /* Also register for DP short pulse (hpd_rx). */
 +                      int_params.int_context = INTERRUPT_LOW_IRQ_CONTEXT;
 +                      int_params.irq_source = dc_link->irq_source_hpd_rx;
 +
 +                      amdgpu_dm_irq_register_interrupt(adev, &int_params,
 +                                      handle_hpd_rx_irq,
 +                                      (void *) aconnector);
 +              }
 +      }
 +}
 +
 +/* Register IRQ sources and initialize IRQ callbacks */
 +static int dce110_register_irq_handlers(struct amdgpu_device *adev)
 +{
 +      struct dc *dc = adev->dm.dc;
 +      struct common_irq_params *c_irq_params;
 +      struct dc_interrupt_params int_params = {0};
 +      int r;
 +      int i;
 +      unsigned client_id = AMDGPU_IH_CLIENTID_LEGACY;
 +
 +      if (adev->asic_type == CHIP_VEGA10 ||
 +          adev->asic_type == CHIP_RAVEN)
 +              client_id = AMDGPU_IH_CLIENTID_DCE;
 +
 +      int_params.requested_polarity = INTERRUPT_POLARITY_DEFAULT;
 +      int_params.current_polarity = INTERRUPT_POLARITY_DEFAULT;
 +
 +      /* Actions of amdgpu_irq_add_id():
 +       * 1. Register a set() function with base driver.
 +       *    Base driver will call set() function to enable/disable an
 +       *    interrupt in DC hardware.
 +       * 2. Register amdgpu_dm_irq_handler().
 +       *    Base driver will call amdgpu_dm_irq_handler() for ALL interrupts
 +       *    coming from DC hardware.
 +       *    amdgpu_dm_irq_handler() will re-direct the interrupt to DC
 +       *    for acknowledging and handling. */
 +
 +      /* Use VBLANK interrupt */
 +      for (i = VISLANDS30_IV_SRCID_D1_VERTICAL_INTERRUPT0; i <= VISLANDS30_IV_SRCID_D6_VERTICAL_INTERRUPT0; i++) {
 +              r = amdgpu_irq_add_id(adev, client_id, i, &adev->crtc_irq);
 +              if (r) {
 +                      DRM_ERROR("Failed to add crtc irq id!\n");
 +                      return r;
 +              }
 +
 +              int_params.int_context = INTERRUPT_HIGH_IRQ_CONTEXT;
 +              int_params.irq_source =
 +                      dc_interrupt_to_irq_source(dc, i, 0);
 +
 +              c_irq_params = &adev->dm.vblank_params[int_params.irq_source - DC_IRQ_SOURCE_VBLANK1];
 +
 +              c_irq_params->adev = adev;
 +              c_irq_params->irq_src = int_params.irq_source;
 +
 +              amdgpu_dm_irq_register_interrupt(adev, &int_params,
 +                              dm_crtc_high_irq, c_irq_params);
 +      }
 +
 +      /* Use GRPH_PFLIP interrupt */
 +      for (i = VISLANDS30_IV_SRCID_D1_GRPH_PFLIP;
 +                      i <= VISLANDS30_IV_SRCID_D6_GRPH_PFLIP; i += 2) {
 +              r = amdgpu_irq_add_id(adev, client_id, i, &adev->pageflip_irq);
 +              if (r) {
 +                      DRM_ERROR("Failed to add page flip irq id!\n");
 +                      return r;
 +              }
 +
 +              int_params.int_context = INTERRUPT_HIGH_IRQ_CONTEXT;
 +              int_params.irq_source =
 +                      dc_interrupt_to_irq_source(dc, i, 0);
 +
 +              c_irq_params = &adev->dm.pflip_params[int_params.irq_source - DC_IRQ_SOURCE_PFLIP_FIRST];
 +
 +              c_irq_params->adev = adev;
 +              c_irq_params->irq_src = int_params.irq_source;
 +
 +              amdgpu_dm_irq_register_interrupt(adev, &int_params,
 +                              dm_pflip_high_irq, c_irq_params);
 +
 +      }
 +
 +      /* HPD */
 +      r = amdgpu_irq_add_id(adev, client_id,
 +                      VISLANDS30_IV_SRCID_HOTPLUG_DETECT_A, &adev->hpd_irq);
 +      if (r) {
 +              DRM_ERROR("Failed to add hpd irq id!\n");
 +              return r;
 +      }
 +
 +      register_hpd_handlers(adev);
 +
 +      return 0;
 +}
 +
 +#if defined(CONFIG_DRM_AMD_DC_DCN1_0)
 +/* Register IRQ sources and initialize IRQ callbacks */
 +static int dcn10_register_irq_handlers(struct amdgpu_device *adev)
 +{
 +      struct dc *dc = adev->dm.dc;
 +      struct common_irq_params *c_irq_params;
 +      struct dc_interrupt_params int_params = {0};
 +      int r;
 +      int i;
 +
 +      int_params.requested_polarity = INTERRUPT_POLARITY_DEFAULT;
 +      int_params.current_polarity = INTERRUPT_POLARITY_DEFAULT;
 +
 +      /* Actions of amdgpu_irq_add_id():
 +       * 1. Register a set() function with base driver.
 +       *    Base driver will call set() function to enable/disable an
 +       *    interrupt in DC hardware.
 +       * 2. Register amdgpu_dm_irq_handler().
 +       *    Base driver will call amdgpu_dm_irq_handler() for ALL interrupts
 +       *    coming from DC hardware.
 +       *    amdgpu_dm_irq_handler() will re-direct the interrupt to DC
 +       *    for acknowledging and handling.
 +       * */
 +
 +      /* Use VSTARTUP interrupt */
 +      for (i = DCN_1_0__SRCID__DC_D1_OTG_VSTARTUP;
 +                      i <= DCN_1_0__SRCID__DC_D1_OTG_VSTARTUP + adev->mode_info.num_crtc - 1;
 +                      i++) {
 +              r = amdgpu_irq_add_id(adev, AMDGPU_IH_CLIENTID_DCE, i, &adev->crtc_irq);
 +
 +              if (r) {
 +                      DRM_ERROR("Failed to add crtc irq id!\n");
 +                      return r;
 +              }
 +
 +              int_params.int_context = INTERRUPT_HIGH_IRQ_CONTEXT;
 +              int_params.irq_source =
 +                      dc_interrupt_to_irq_source(dc, i, 0);
 +
 +              c_irq_params = &adev->dm.vblank_params[int_params.irq_source - DC_IRQ_SOURCE_VBLANK1];
 +
 +              c_irq_params->adev = adev;
 +              c_irq_params->irq_src = int_params.irq_source;
 +
 +              amdgpu_dm_irq_register_interrupt(adev, &int_params,
 +                              dm_crtc_high_irq, c_irq_params);
 +      }
 +
 +      /* Use GRPH_PFLIP interrupt */
 +      for (i = DCN_1_0__SRCID__HUBP0_FLIP_INTERRUPT;
 +                      i <= DCN_1_0__SRCID__HUBP0_FLIP_INTERRUPT + adev->mode_info.num_crtc - 1;
 +                      i++) {
 +              r = amdgpu_irq_add_id(adev, AMDGPU_IH_CLIENTID_DCE, i, &adev->pageflip_irq);
 +              if (r) {
 +                      DRM_ERROR("Failed to add page flip irq id!\n");
 +                      return r;
 +              }
 +
 +              int_params.int_context = INTERRUPT_HIGH_IRQ_CONTEXT;
 +              int_params.irq_source =
 +                      dc_interrupt_to_irq_source(dc, i, 0);
 +
 +              c_irq_params = &adev->dm.pflip_params[int_params.irq_source - DC_IRQ_SOURCE_PFLIP_FIRST];
 +
 +              c_irq_params->adev = adev;
 +              c_irq_params->irq_src = int_params.irq_source;
 +
 +              amdgpu_dm_irq_register_interrupt(adev, &int_params,
 +                              dm_pflip_high_irq, c_irq_params);
 +
 +      }
 +
 +      /* HPD */
 +      r = amdgpu_irq_add_id(adev, AMDGPU_IH_CLIENTID_DCE, DCN_1_0__SRCID__DC_HPD1_INT,
 +                      &adev->hpd_irq);
 +      if (r) {
 +              DRM_ERROR("Failed to add hpd irq id!\n");
 +              return r;
 +      }
 +
 +      register_hpd_handlers(adev);
 +
 +      return 0;
 +}
 +#endif
 +
 +static int amdgpu_dm_mode_config_init(struct amdgpu_device *adev)
 +{
 +      int r;
 +
 +      adev->mode_info.mode_config_initialized = true;
 +
 +      adev->ddev->mode_config.funcs = (void *)&amdgpu_dm_mode_funcs;
 +      adev->ddev->mode_config.helper_private = &amdgpu_dm_mode_config_helperfuncs;
 +
 +      adev->ddev->mode_config.max_width = 16384;
 +      adev->ddev->mode_config.max_height = 16384;
 +
 +      adev->ddev->mode_config.preferred_depth = 24;
 +      adev->ddev->mode_config.prefer_shadow = 1;
 +      /* indicate support of immediate flip */
 +      adev->ddev->mode_config.async_page_flip = true;
 +
 +      adev->ddev->mode_config.fb_base = adev->mc.aper_base;
 +
 +      r = amdgpu_modeset_create_props(adev);
 +      if (r)
 +              return r;
 +
 +      return 0;
 +}
 +
 +#if defined(CONFIG_BACKLIGHT_CLASS_DEVICE) ||\
 +      defined(CONFIG_BACKLIGHT_CLASS_DEVICE_MODULE)
 +
 +static int amdgpu_dm_backlight_update_status(struct backlight_device *bd)
 +{
 +      struct amdgpu_display_manager *dm = bl_get_data(bd);
 +
 +      if (dc_link_set_backlight_level(dm->backlight_link,
 +                      bd->props.brightness, 0, 0))
 +              return 0;
 +      else
 +              return 1;
 +}
 +
 +static int amdgpu_dm_backlight_get_brightness(struct backlight_device *bd)
 +{
 +      return bd->props.brightness;
 +}
 +
 +static const struct backlight_ops amdgpu_dm_backlight_ops = {
 +      .get_brightness = amdgpu_dm_backlight_get_brightness,
 +      .update_status  = amdgpu_dm_backlight_update_status,
 +};
 +
 +static void
 +amdgpu_dm_register_backlight_device(struct amdgpu_display_manager *dm)
 +{
 +      char bl_name[16];
 +      struct backlight_properties props = { 0 };
 +
 +      props.max_brightness = AMDGPU_MAX_BL_LEVEL;
 +      props.type = BACKLIGHT_RAW;
 +
 +      snprintf(bl_name, sizeof(bl_name), "amdgpu_bl%d",
 +                      dm->adev->ddev->primary->index);
 +
 +      dm->backlight_dev = backlight_device_register(bl_name,
 +                      dm->adev->ddev->dev,
 +                      dm,
 +                      &amdgpu_dm_backlight_ops,
 +                      &props);
 +
 +      if (IS_ERR(dm->backlight_dev))
 +              DRM_ERROR("DM: Backlight registration failed!\n");
 +      else
 +              DRM_DEBUG_DRIVER("DM: Registered Backlight device: %s\n", bl_name);
 +}
 +
 +#endif
 +
 +/* In this architecture, the association
 + * connector -> encoder -> crtc
 + * id not really requried. The crtc and connector will hold the
 + * display_index as an abstraction to use with DAL component
 + *
 + * Returns 0 on success
 + */
 +static int amdgpu_dm_initialize_drm_device(struct amdgpu_device *adev)
 +{
 +      struct amdgpu_display_manager *dm = &adev->dm;
 +      uint32_t i;
 +      struct amdgpu_dm_connector *aconnector = NULL;
 +      struct amdgpu_encoder *aencoder = NULL;
 +      struct amdgpu_mode_info *mode_info = &adev->mode_info;
 +      uint32_t link_cnt;
 +      unsigned long possible_crtcs;
 +
 +      link_cnt = dm->dc->caps.max_links;
 +      if (amdgpu_dm_mode_config_init(dm->adev)) {
 +              DRM_ERROR("DM: Failed to initialize mode config\n");
 +              return -1;
 +      }
 +
 +      for (i = 0; i < dm->dc->caps.max_planes; i++) {
 +              struct amdgpu_plane *plane;
 +
 +              plane = kzalloc(sizeof(struct amdgpu_plane), GFP_KERNEL);
 +              mode_info->planes[i] = plane;
 +
 +              if (!plane) {
 +                      DRM_ERROR("KMS: Failed to allocate plane\n");
 +                      goto fail;
 +              }
 +              plane->base.type = mode_info->plane_type[i];
 +
 +              /*
 +               * HACK: IGT tests expect that each plane can only have one
 +               * one possible CRTC. For now, set one CRTC for each
 +               * plane that is not an underlay, but still allow multiple
 +               * CRTCs for underlay planes.
 +               */
 +              possible_crtcs = 1 << i;
 +              if (i >= dm->dc->caps.max_streams)
 +                      possible_crtcs = 0xff;
 +
 +              if (amdgpu_dm_plane_init(dm, mode_info->planes[i], possible_crtcs)) {
 +                      DRM_ERROR("KMS: Failed to initialize plane\n");
 +                      goto fail;
 +              }
 +      }
 +
 +      for (i = 0; i < dm->dc->caps.max_streams; i++)
 +              if (amdgpu_dm_crtc_init(dm, &mode_info->planes[i]->base, i)) {
 +                      DRM_ERROR("KMS: Failed to initialize crtc\n");
 +                      goto fail;
 +              }
 +
 +      dm->display_indexes_num = dm->dc->caps.max_streams;
 +
 +      /* loops over all connectors on the board */
 +      for (i = 0; i < link_cnt; i++) {
 +
 +              if (i > AMDGPU_DM_MAX_DISPLAY_INDEX) {
 +                      DRM_ERROR(
 +                              "KMS: Cannot support more than %d display indexes\n",
 +                                      AMDGPU_DM_MAX_DISPLAY_INDEX);
 +                      continue;
 +              }
 +
 +              aconnector = kzalloc(sizeof(*aconnector), GFP_KERNEL);
 +              if (!aconnector)
 +                      goto fail;
 +
 +              aencoder = kzalloc(sizeof(*aencoder), GFP_KERNEL);
 +              if (!aencoder)
 +                      goto fail;
 +
 +              if (amdgpu_dm_encoder_init(dm->ddev, aencoder, i)) {
 +                      DRM_ERROR("KMS: Failed to initialize encoder\n");
 +                      goto fail;
 +              }
 +
 +              if (amdgpu_dm_connector_init(dm, aconnector, i, aencoder)) {
 +                      DRM_ERROR("KMS: Failed to initialize connector\n");
 +                      goto fail;
 +              }
 +
 +              if (dc_link_detect(dc_get_link_at_index(dm->dc, i),
 +                              DETECT_REASON_BOOT))
 +                      amdgpu_dm_update_connector_after_detect(aconnector);
 +      }
 +
 +      /* Software is initialized. Now we can register interrupt handlers. */
 +      switch (adev->asic_type) {
 +      case CHIP_BONAIRE:
 +      case CHIP_HAWAII:
 +      case CHIP_KAVERI:
 +      case CHIP_KABINI:
 +      case CHIP_MULLINS:
 +      case CHIP_TONGA:
 +      case CHIP_FIJI:
 +      case CHIP_CARRIZO:
 +      case CHIP_STONEY:
 +      case CHIP_POLARIS11:
 +      case CHIP_POLARIS10:
 +      case CHIP_POLARIS12:
 +      case CHIP_VEGA10:
 +              if (dce110_register_irq_handlers(dm->adev)) {
 +                      DRM_ERROR("DM: Failed to initialize IRQ\n");
 +                      goto fail;
 +              }
 +              break;
 +#if defined(CONFIG_DRM_AMD_DC_DCN1_0)
 +      case CHIP_RAVEN:
 +              if (dcn10_register_irq_handlers(dm->adev)) {
 +                      DRM_ERROR("DM: Failed to initialize IRQ\n");
 +                      goto fail;
 +              }
 +              /*
 +               * Temporary disable until pplib/smu interaction is implemented
 +               */
 +              dm->dc->debug.disable_stutter = true;
 +              break;
 +#endif
 +      default:
 +              DRM_ERROR("Usupported ASIC type: 0x%X\n", adev->asic_type);
 +              goto fail;
 +      }
 +
 +      return 0;
 +fail:
 +      kfree(aencoder);
 +      kfree(aconnector);
 +      for (i = 0; i < dm->dc->caps.max_planes; i++)
 +              kfree(mode_info->planes[i]);
 +      return -1;
 +}
 +
 +static void amdgpu_dm_destroy_drm_device(struct amdgpu_display_manager *dm)
 +{
 +      drm_mode_config_cleanup(dm->ddev);
 +      return;
 +}
 +
 +/******************************************************************************
 + * amdgpu_display_funcs functions
 + *****************************************************************************/
 +
 +/**
 + * dm_bandwidth_update - program display watermarks
 + *
 + * @adev: amdgpu_device pointer
 + *
 + * Calculate and program the display watermarks and line buffer allocation.
 + */
 +static void dm_bandwidth_update(struct amdgpu_device *adev)
 +{
 +      /* TODO: implement later */
 +}
 +
 +static void dm_set_backlight_level(struct amdgpu_encoder *amdgpu_encoder,
 +                                   u8 level)
 +{
 +      /* TODO: translate amdgpu_encoder to display_index and call DAL */
 +}
 +
 +static u8 dm_get_backlight_level(struct amdgpu_encoder *amdgpu_encoder)
 +{
 +      /* TODO: translate amdgpu_encoder to display_index and call DAL */
 +      return 0;
 +}
 +
 +static int amdgpu_notify_freesync(struct drm_device *dev, void *data,
 +                              struct drm_file *filp)
 +{
 +      struct mod_freesync_params freesync_params;
 +      uint8_t num_streams;
 +      uint8_t i;
 +
 +      struct amdgpu_device *adev = dev->dev_private;
 +      int r = 0;
 +
 +      /* Get freesync enable flag from DRM */
 +
 +      num_streams = dc_get_current_stream_count(adev->dm.dc);
 +
 +      for (i = 0; i < num_streams; i++) {
 +              struct dc_stream_state *stream;
 +              stream = dc_get_stream_at_index(adev->dm.dc, i);
 +
 +              mod_freesync_update_state(adev->dm.freesync_module,
 +                                        &stream, 1, &freesync_params);
 +      }
 +
 +      return r;
 +}
 +
 +static const struct amdgpu_display_funcs dm_display_funcs = {
 +      .bandwidth_update = dm_bandwidth_update, /* called unconditionally */
 +      .vblank_get_counter = dm_vblank_get_counter,/* called unconditionally */
 +      .vblank_wait = NULL,
 +      .backlight_set_level =
 +              dm_set_backlight_level,/* called unconditionally */
 +      .backlight_get_level =
 +              dm_get_backlight_level,/* called unconditionally */
 +      .hpd_sense = NULL,/* called unconditionally */
 +      .hpd_set_polarity = NULL, /* called unconditionally */
 +      .hpd_get_gpio_reg = NULL, /* VBIOS parsing. DAL does it. */
 +      .page_flip_get_scanoutpos =
 +              dm_crtc_get_scanoutpos,/* called unconditionally */
 +      .add_encoder = NULL, /* VBIOS parsing. DAL does it. */
 +      .add_connector = NULL, /* VBIOS parsing. DAL does it. */
 +      .notify_freesync = amdgpu_notify_freesync,
 +
 +};
 +
 +#if defined(CONFIG_DEBUG_KERNEL_DC)
 +
 +static ssize_t s3_debug_store(struct device *device,
 +                            struct device_attribute *attr,
 +                            const char *buf,
 +                            size_t count)
 +{
 +      int ret;
 +      int s3_state;
 +      struct pci_dev *pdev = to_pci_dev(device);
 +      struct drm_device *drm_dev = pci_get_drvdata(pdev);
 +      struct amdgpu_device *adev = drm_dev->dev_private;
 +
 +      ret = kstrtoint(buf, 0, &s3_state);
 +
 +      if (ret == 0) {
 +              if (s3_state) {
 +                      dm_resume(adev);
 +                      amdgpu_dm_display_resume(adev);
 +                      drm_kms_helper_hotplug_event(adev->ddev);
 +              } else
 +                      dm_suspend(adev);
 +      }
 +
 +      return ret == 0 ? count : 0;
 +}
 +
 +DEVICE_ATTR_WO(s3_debug);
 +
 +#endif
 +
 +static int dm_early_init(void *handle)
 +{
 +      struct amdgpu_device *adev = (struct amdgpu_device *)handle;
 +
 +      adev->ddev->driver->driver_features |= DRIVER_ATOMIC;
 +      amdgpu_dm_set_irq_funcs(adev);
 +
 +      switch (adev->asic_type) {
 +      case CHIP_BONAIRE:
 +      case CHIP_HAWAII:
 +              adev->mode_info.num_crtc = 6;
 +              adev->mode_info.num_hpd = 6;
 +              adev->mode_info.num_dig = 6;
 +              adev->mode_info.plane_type = dm_plane_type_default;
 +              break;
 +      case CHIP_KAVERI:
 +              adev->mode_info.num_crtc = 4;
 +              adev->mode_info.num_hpd = 6;
 +              adev->mode_info.num_dig = 7;
 +              adev->mode_info.plane_type = dm_plane_type_default;
 +              break;
 +      case CHIP_KABINI:
 +      case CHIP_MULLINS:
 +              adev->mode_info.num_crtc = 2;
 +              adev->mode_info.num_hpd = 6;
 +              adev->mode_info.num_dig = 6;
 +              adev->mode_info.plane_type = dm_plane_type_default;
 +              break;
 +      case CHIP_FIJI:
 +      case CHIP_TONGA:
 +              adev->mode_info.num_crtc = 6;
 +              adev->mode_info.num_hpd = 6;
 +              adev->mode_info.num_dig = 7;
 +              adev->mode_info.plane_type = dm_plane_type_default;
 +              break;
 +      case CHIP_CARRIZO:
 +              adev->mode_info.num_crtc = 3;
 +              adev->mode_info.num_hpd = 6;
 +              adev->mode_info.num_dig = 9;
 +              adev->mode_info.plane_type = dm_plane_type_carizzo;
 +              break;
 +      case CHIP_STONEY:
 +              adev->mode_info.num_crtc = 2;
 +              adev->mode_info.num_hpd = 6;
 +              adev->mode_info.num_dig = 9;
 +              adev->mode_info.plane_type = dm_plane_type_stoney;
 +              break;
 +      case CHIP_POLARIS11:
 +      case CHIP_POLARIS12:
 +              adev->mode_info.num_crtc = 5;
 +              adev->mode_info.num_hpd = 5;
 +              adev->mode_info.num_dig = 5;
 +              adev->mode_info.plane_type = dm_plane_type_default;
 +              break;
 +      case CHIP_POLARIS10:
 +              adev->mode_info.num_crtc = 6;
 +              adev->mode_info.num_hpd = 6;
 +              adev->mode_info.num_dig = 6;
 +              adev->mode_info.plane_type = dm_plane_type_default;
 +              break;
 +      case CHIP_VEGA10:
 +              adev->mode_info.num_crtc = 6;
 +              adev->mode_info.num_hpd = 6;
 +              adev->mode_info.num_dig = 6;
 +              adev->mode_info.plane_type = dm_plane_type_default;
 +              break;
 +#if defined(CONFIG_DRM_AMD_DC_DCN1_0)
 +      case CHIP_RAVEN:
 +              adev->mode_info.num_crtc = 4;
 +              adev->mode_info.num_hpd = 4;
 +              adev->mode_info.num_dig = 4;
 +              adev->mode_info.plane_type = dm_plane_type_default;
 +              break;
 +#endif
 +      default:
 +              DRM_ERROR("Usupported ASIC type: 0x%X\n", adev->asic_type);
 +              return -EINVAL;
 +      }
 +
 +      if (adev->mode_info.funcs == NULL)
 +              adev->mode_info.funcs = &dm_display_funcs;
 +
 +      /* Note: Do NOT change adev->audio_endpt_rreg and
 +       * adev->audio_endpt_wreg because they are initialised in
 +       * amdgpu_device_init() */
 +#if defined(CONFIG_DEBUG_KERNEL_DC)
 +      device_create_file(
 +              adev->ddev->dev,
 +              &dev_attr_s3_debug);
 +#endif
 +
 +      return 0;
 +}
 +
 +struct dm_connector_state {
 +      struct drm_connector_state base;
 +
 +      enum amdgpu_rmx_type scaling;
 +      uint8_t underscan_vborder;
 +      uint8_t underscan_hborder;
 +      bool underscan_enable;
 +};
 +
 +#define to_dm_connector_state(x)\
 +      container_of((x), struct dm_connector_state, base)
 +
 +static bool modeset_required(struct drm_crtc_state *crtc_state,
 +                           struct dc_stream_state *new_stream,
 +                           struct dc_stream_state *old_stream)
 +{
 +      if (!drm_atomic_crtc_needs_modeset(crtc_state))
 +              return false;
 +
 +      if (!crtc_state->enable)
 +              return false;
 +
 +      return crtc_state->active;
 +}
 +
 +static bool modereset_required(struct drm_crtc_state *crtc_state)
 +{
 +      if (!drm_atomic_crtc_needs_modeset(crtc_state))
 +              return false;
 +
 +      return !crtc_state->enable || !crtc_state->active;
 +}
 +
 +static void amdgpu_dm_encoder_destroy(struct drm_encoder *encoder)
 +{
 +      drm_encoder_cleanup(encoder);
 +      kfree(encoder);
 +}
 +
 +static const struct drm_encoder_funcs amdgpu_dm_encoder_funcs = {
 +      .destroy = amdgpu_dm_encoder_destroy,
 +};
 +
 +static bool fill_rects_from_plane_state(const struct drm_plane_state *state,
 +                                      struct dc_plane_state *plane_state)
 +{
 +      plane_state->src_rect.x = state->src_x >> 16;
 +      plane_state->src_rect.y = state->src_y >> 16;
 +      /*we ignore for now mantissa and do not to deal with floating pixels :(*/
 +      plane_state->src_rect.width = state->src_w >> 16;
 +
 +      if (plane_state->src_rect.width == 0)
 +              return false;
 +
 +      plane_state->src_rect.height = state->src_h >> 16;
 +      if (plane_state->src_rect.height == 0)
 +              return false;
 +
 +      plane_state->dst_rect.x = state->crtc_x;
 +      plane_state->dst_rect.y = state->crtc_y;
 +
 +      if (state->crtc_w == 0)
 +              return false;
 +
 +      plane_state->dst_rect.width = state->crtc_w;
 +
 +      if (state->crtc_h == 0)
 +              return false;
 +
 +      plane_state->dst_rect.height = state->crtc_h;
 +
 +      plane_state->clip_rect = plane_state->dst_rect;
 +
 +      switch (state->rotation & DRM_MODE_ROTATE_MASK) {
 +      case DRM_MODE_ROTATE_0:
 +              plane_state->rotation = ROTATION_ANGLE_0;
 +              break;
 +      case DRM_MODE_ROTATE_90:
 +              plane_state->rotation = ROTATION_ANGLE_90;
 +              break;
 +      case DRM_MODE_ROTATE_180:
 +              plane_state->rotation = ROTATION_ANGLE_180;
 +              break;
 +      case DRM_MODE_ROTATE_270:
 +              plane_state->rotation = ROTATION_ANGLE_270;
 +              break;
 +      default:
 +              plane_state->rotation = ROTATION_ANGLE_0;
 +              break;
 +      }
 +
 +      return true;
 +}
 +static int get_fb_info(const struct amdgpu_framebuffer *amdgpu_fb,
 +                     uint64_t *tiling_flags,
 +                     uint64_t *fb_location)
 +{
 +      struct amdgpu_bo *rbo = gem_to_amdgpu_bo(amdgpu_fb->obj);
 +      int r = amdgpu_bo_reserve(rbo, false);
 +
 +      if (unlikely(r)) {
 +              // Don't show error msg. when return -ERESTARTSYS
 +              if (r != -ERESTARTSYS)
 +                      DRM_ERROR("Unable to reserve buffer: %d\n", r);
 +              return r;
 +      }
 +
 +      if (fb_location)
 +              *fb_location = amdgpu_bo_gpu_offset(rbo);
 +
 +      if (tiling_flags)
 +              amdgpu_bo_get_tiling_flags(rbo, tiling_flags);
 +
 +      amdgpu_bo_unreserve(rbo);
 +
 +      return r;
 +}
 +
 +static int fill_plane_attributes_from_fb(struct amdgpu_device *adev,
 +                                       struct dc_plane_state *plane_state,
 +                                       const struct amdgpu_framebuffer *amdgpu_fb,
 +                                       bool addReq)
 +{
 +      uint64_t tiling_flags;
 +      uint64_t fb_location = 0;
 +      uint64_t chroma_addr = 0;
 +      unsigned int awidth;
 +      const struct drm_framebuffer *fb = &amdgpu_fb->base;
 +      int ret = 0;
 +      struct drm_format_name_buf format_name;
 +
 +      ret = get_fb_info(
 +              amdgpu_fb,
 +              &tiling_flags,
 +              addReq == true ? &fb_location:NULL);
 +
 +      if (ret)
 +              return ret;
 +
 +      switch (fb->format->format) {
 +      case DRM_FORMAT_C8:
 +              plane_state->format = SURFACE_PIXEL_FORMAT_GRPH_PALETA_256_COLORS;
 +              break;
 +      case DRM_FORMAT_RGB565:
 +              plane_state->format = SURFACE_PIXEL_FORMAT_GRPH_RGB565;
 +              break;
 +      case DRM_FORMAT_XRGB8888:
 +      case DRM_FORMAT_ARGB8888:
 +              plane_state->format = SURFACE_PIXEL_FORMAT_GRPH_ARGB8888;
 +              break;
 +      case DRM_FORMAT_XRGB2101010:
 +      case DRM_FORMAT_ARGB2101010:
 +              plane_state->format = SURFACE_PIXEL_FORMAT_GRPH_ARGB2101010;
 +              break;
 +      case DRM_FORMAT_XBGR2101010:
 +      case DRM_FORMAT_ABGR2101010:
 +              plane_state->format = SURFACE_PIXEL_FORMAT_GRPH_ABGR2101010;
 +              break;
 +      case DRM_FORMAT_NV21:
 +              plane_state->format = SURFACE_PIXEL_FORMAT_VIDEO_420_YCbCr;
 +              break;
 +      case DRM_FORMAT_NV12:
 +              plane_state->format = SURFACE_PIXEL_FORMAT_VIDEO_420_YCrCb;
 +              break;
 +      default:
 +              DRM_ERROR("Unsupported screen format %s\n",
 +                        drm_get_format_name(fb->format->format, &format_name));
 +              return -EINVAL;
 +      }
 +
 +      if (plane_state->format < SURFACE_PIXEL_FORMAT_VIDEO_BEGIN) {
 +              plane_state->address.type = PLN_ADDR_TYPE_GRAPHICS;
 +              plane_state->address.grph.addr.low_part = lower_32_bits(fb_location);
 +              plane_state->address.grph.addr.high_part = upper_32_bits(fb_location);
 +              plane_state->plane_size.grph.surface_size.x = 0;
 +              plane_state->plane_size.grph.surface_size.y = 0;
 +              plane_state->plane_size.grph.surface_size.width = fb->width;
 +              plane_state->plane_size.grph.surface_size.height = fb->height;
 +              plane_state->plane_size.grph.surface_pitch =
 +                              fb->pitches[0] / fb->format->cpp[0];
 +              /* TODO: unhardcode */
 +              plane_state->color_space = COLOR_SPACE_SRGB;
 +
 +      } else {
 +              awidth = ALIGN(fb->width, 64);
 +              plane_state->address.type = PLN_ADDR_TYPE_VIDEO_PROGRESSIVE;
 +              plane_state->address.video_progressive.luma_addr.low_part
 +                                              = lower_32_bits(fb_location);
 +              plane_state->address.video_progressive.luma_addr.high_part
 +                                              = upper_32_bits(fb_location);
 +              chroma_addr = fb_location + (u64)(awidth * fb->height);
 +              plane_state->address.video_progressive.chroma_addr.low_part
 +                                              = lower_32_bits(chroma_addr);
 +              plane_state->address.video_progressive.chroma_addr.high_part
 +                                              = upper_32_bits(chroma_addr);
 +              plane_state->plane_size.video.luma_size.x = 0;
 +              plane_state->plane_size.video.luma_size.y = 0;
 +              plane_state->plane_size.video.luma_size.width = awidth;
 +              plane_state->plane_size.video.luma_size.height = fb->height;
 +              /* TODO: unhardcode */
 +              plane_state->plane_size.video.luma_pitch = awidth;
 +
 +              plane_state->plane_size.video.chroma_size.x = 0;
 +              plane_state->plane_size.video.chroma_size.y = 0;
 +              plane_state->plane_size.video.chroma_size.width = awidth;
 +              plane_state->plane_size.video.chroma_size.height = fb->height;
 +              plane_state->plane_size.video.chroma_pitch = awidth / 2;
 +
 +              /* TODO: unhardcode */
 +              plane_state->color_space = COLOR_SPACE_YCBCR709;
 +      }
 +
 +      memset(&plane_state->tiling_info, 0, sizeof(plane_state->tiling_info));
 +
 +      /* Fill GFX8 params */
 +      if (AMDGPU_TILING_GET(tiling_flags, ARRAY_MODE) == DC_ARRAY_2D_TILED_THIN1) {
 +              unsigned int bankw, bankh, mtaspect, tile_split, num_banks;
 +
 +              bankw = AMDGPU_TILING_GET(tiling_flags, BANK_WIDTH);
 +              bankh = AMDGPU_TILING_GET(tiling_flags, BANK_HEIGHT);
 +              mtaspect = AMDGPU_TILING_GET(tiling_flags, MACRO_TILE_ASPECT);
 +              tile_split = AMDGPU_TILING_GET(tiling_flags, TILE_SPLIT);
 +              num_banks = AMDGPU_TILING_GET(tiling_flags, NUM_BANKS);
 +
 +              /* XXX fix me for VI */
 +              plane_state->tiling_info.gfx8.num_banks = num_banks;
 +              plane_state->tiling_info.gfx8.array_mode =
 +                              DC_ARRAY_2D_TILED_THIN1;
 +              plane_state->tiling_info.gfx8.tile_split = tile_split;
 +              plane_state->tiling_info.gfx8.bank_width = bankw;
 +              plane_state->tiling_info.gfx8.bank_height = bankh;
 +              plane_state->tiling_info.gfx8.tile_aspect = mtaspect;
 +              plane_state->tiling_info.gfx8.tile_mode =
 +                              DC_ADDR_SURF_MICRO_TILING_DISPLAY;
 +      } else if (AMDGPU_TILING_GET(tiling_flags, ARRAY_MODE)
 +                      == DC_ARRAY_1D_TILED_THIN1) {
 +              plane_state->tiling_info.gfx8.array_mode = DC_ARRAY_1D_TILED_THIN1;
 +      }
 +
 +      plane_state->tiling_info.gfx8.pipe_config =
 +                      AMDGPU_TILING_GET(tiling_flags, PIPE_CONFIG);
 +
 +      if (adev->asic_type == CHIP_VEGA10 ||
 +          adev->asic_type == CHIP_RAVEN) {
 +              /* Fill GFX9 params */
 +              plane_state->tiling_info.gfx9.num_pipes =
 +                      adev->gfx.config.gb_addr_config_fields.num_pipes;
 +              plane_state->tiling_info.gfx9.num_banks =
 +                      adev->gfx.config.gb_addr_config_fields.num_banks;
 +              plane_state->tiling_info.gfx9.pipe_interleave =
 +                      adev->gfx.config.gb_addr_config_fields.pipe_interleave_size;
 +              plane_state->tiling_info.gfx9.num_shader_engines =
 +                      adev->gfx.config.gb_addr_config_fields.num_se;
 +              plane_state->tiling_info.gfx9.max_compressed_frags =
 +                      adev->gfx.config.gb_addr_config_fields.max_compress_frags;
 +              plane_state->tiling_info.gfx9.num_rb_per_se =
 +                      adev->gfx.config.gb_addr_config_fields.num_rb_per_se;
 +              plane_state->tiling_info.gfx9.swizzle =
 +                      AMDGPU_TILING_GET(tiling_flags, SWIZZLE_MODE);
 +              plane_state->tiling_info.gfx9.shaderEnable = 1;
 +      }
 +
 +      plane_state->visible = true;
 +      plane_state->scaling_quality.h_taps_c = 0;
 +      plane_state->scaling_quality.v_taps_c = 0;
 +
 +      /* is this needed? is plane_state zeroed at allocation? */
 +      plane_state->scaling_quality.h_taps = 0;
 +      plane_state->scaling_quality.v_taps = 0;
 +      plane_state->stereo_format = PLANE_STEREO_FORMAT_NONE;
 +
 +      return ret;
 +
 +}
 +
 +static void fill_gamma_from_crtc_state(const struct drm_crtc_state *crtc_state,
 +                                     struct dc_plane_state *plane_state)
 +{
 +      int i;
 +      struct dc_gamma *gamma;
 +      struct drm_color_lut *lut =
 +                      (struct drm_color_lut *) crtc_state->gamma_lut->data;
 +
 +      gamma = dc_create_gamma();
 +
 +      if (gamma == NULL) {
 +              WARN_ON(1);
 +              return;
 +      }
 +
 +      gamma->type = GAMMA_RGB_256;
 +      gamma->num_entries = GAMMA_RGB_256_ENTRIES;
 +      for (i = 0; i < GAMMA_RGB_256_ENTRIES; i++) {
 +              gamma->entries.red[i] = dal_fixed31_32_from_int(lut[i].red);
 +              gamma->entries.green[i] = dal_fixed31_32_from_int(lut[i].green);
 +              gamma->entries.blue[i] = dal_fixed31_32_from_int(lut[i].blue);
 +      }
 +
 +      plane_state->gamma_correction = gamma;
 +}
 +
 +static int fill_plane_attributes(struct amdgpu_device *adev,
 +                               struct dc_plane_state *dc_plane_state,
 +                               struct drm_plane_state *plane_state,
 +                               struct drm_crtc_state *crtc_state,
 +                               bool addrReq)
 +{
 +      const struct amdgpu_framebuffer *amdgpu_fb =
 +              to_amdgpu_framebuffer(plane_state->fb);
 +      const struct drm_crtc *crtc = plane_state->crtc;
 +      struct dc_transfer_func *input_tf;
 +      int ret = 0;
 +
 +      if (!fill_rects_from_plane_state(plane_state, dc_plane_state))
 +              return -EINVAL;
 +
 +      ret = fill_plane_attributes_from_fb(
 +              crtc->dev->dev_private,
 +              dc_plane_state,
 +              amdgpu_fb,
 +              addrReq);
 +
 +      if (ret)
 +              return ret;
 +
 +      input_tf = dc_create_transfer_func();
 +
 +      if (input_tf == NULL)
 +              return -ENOMEM;
 +
 +      input_tf->type = TF_TYPE_PREDEFINED;
 +      input_tf->tf = TRANSFER_FUNCTION_SRGB;
 +
 +      dc_plane_state->in_transfer_func = input_tf;
 +
 +      /* In case of gamma set, update gamma value */
 +      if (crtc_state->gamma_lut)
 +              fill_gamma_from_crtc_state(crtc_state, dc_plane_state);
 +
 +      return ret;
 +}
 +
 +/*****************************************************************************/
 +
 +static void update_stream_scaling_settings(const struct drm_display_mode *mode,
 +                                         const struct dm_connector_state *dm_state,
 +                                         struct dc_stream_state *stream)
 +{
 +      enum amdgpu_rmx_type rmx_type;
 +
 +      struct rect src = { 0 }; /* viewport in composition space*/
 +      struct rect dst = { 0 }; /* stream addressable area */
 +
 +      /* no mode. nothing to be done */
 +      if (!mode)
 +              return;
 +
 +      /* Full screen scaling by default */
 +      src.width = mode->hdisplay;
 +      src.height = mode->vdisplay;
 +      dst.width = stream->timing.h_addressable;
 +      dst.height = stream->timing.v_addressable;
 +
 +      rmx_type = dm_state->scaling;
 +      if (rmx_type == RMX_ASPECT || rmx_type == RMX_OFF) {
 +              if (src.width * dst.height <
 +                              src.height * dst.width) {
 +                      /* height needs less upscaling/more downscaling */
 +                      dst.width = src.width *
 +                                      dst.height / src.height;
 +              } else {
 +                      /* width needs less upscaling/more downscaling */
 +                      dst.height = src.height *
 +                                      dst.width / src.width;
 +              }
 +      } else if (rmx_type == RMX_CENTER) {
 +              dst = src;
 +      }
 +
 +      dst.x = (stream->timing.h_addressable - dst.width) / 2;
 +      dst.y = (stream->timing.v_addressable - dst.height) / 2;
 +
 +      if (dm_state->underscan_enable) {
 +              dst.x += dm_state->underscan_hborder / 2;
 +              dst.y += dm_state->underscan_vborder / 2;
 +              dst.width -= dm_state->underscan_hborder;
 +              dst.height -= dm_state->underscan_vborder;
 +      }
 +
 +      stream->src = src;
 +      stream->dst = dst;
 +
 +      DRM_DEBUG_DRIVER("Destination Rectangle x:%d  y:%d  width:%d  height:%d\n",
 +                      dst.x, dst.y, dst.width, dst.height);
 +
 +}
 +
 +static enum dc_color_depth
 +convert_color_depth_from_display_info(const struct drm_connector *connector)
 +{
 +      uint32_t bpc = connector->display_info.bpc;
 +
 +      /* Limited color depth to 8bit
 +       * TODO: Still need to handle deep color
 +       */
 +      if (bpc > 8)
 +              bpc = 8;
 +
 +      switch (bpc) {
 +      case 0:
 +              /* Temporary Work around, DRM don't parse color depth for
 +               * EDID revision before 1.4
 +               * TODO: Fix edid parsing
 +               */
 +              return COLOR_DEPTH_888;
 +      case 6:
 +              return COLOR_DEPTH_666;
 +      case 8:
 +              return COLOR_DEPTH_888;
 +      case 10:
 +              return COLOR_DEPTH_101010;
 +      case 12:
 +              return COLOR_DEPTH_121212;
 +      case 14:
 +              return COLOR_DEPTH_141414;
 +      case 16:
 +              return COLOR_DEPTH_161616;
 +      default:
 +              return COLOR_DEPTH_UNDEFINED;
 +      }
 +}
 +
 +static enum dc_aspect_ratio
 +get_aspect_ratio(const struct drm_display_mode *mode_in)
 +{
 +      int32_t width = mode_in->crtc_hdisplay * 9;
 +      int32_t height = mode_in->crtc_vdisplay * 16;
 +
 +      if ((width - height) < 10 && (width - height) > -10)
 +              return ASPECT_RATIO_16_9;
 +      else
 +              return ASPECT_RATIO_4_3;
 +}
 +
 +static enum dc_color_space
 +get_output_color_space(const struct dc_crtc_timing *dc_crtc_timing)
 +{
 +      enum dc_color_space color_space = COLOR_SPACE_SRGB;
 +
 +      switch (dc_crtc_timing->pixel_encoding) {
 +      case PIXEL_ENCODING_YCBCR422:
 +      case PIXEL_ENCODING_YCBCR444:
 +      case PIXEL_ENCODING_YCBCR420:
 +      {
 +              /*
 +               * 27030khz is the separation point between HDTV and SDTV
 +               * according to HDMI spec, we use YCbCr709 and YCbCr601
 +               * respectively
 +               */
 +              if (dc_crtc_timing->pix_clk_khz > 27030) {
 +                      if (dc_crtc_timing->flags.Y_ONLY)
 +                              color_space =
 +                                      COLOR_SPACE_YCBCR709_LIMITED;
 +                      else
 +                              color_space = COLOR_SPACE_YCBCR709;
 +              } else {
 +                      if (dc_crtc_timing->flags.Y_ONLY)
 +                              color_space =
 +                                      COLOR_SPACE_YCBCR601_LIMITED;
 +                      else
 +                              color_space = COLOR_SPACE_YCBCR601;
 +              }
 +
 +      }
 +      break;
 +      case PIXEL_ENCODING_RGB:
 +              color_space = COLOR_SPACE_SRGB;
 +              break;
 +
 +      default:
 +              WARN_ON(1);
 +              break;
 +      }
 +
 +      return color_space;
 +}
 +
 +/*****************************************************************************/
 +
 +static void
 +fill_stream_properties_from_drm_display_mode(struct dc_stream_state *stream,
 +                                           const struct drm_display_mode *mode_in,
 +                                           const struct drm_connector *connector)
 +{
 +      struct dc_crtc_timing *timing_out = &stream->timing;
 +
 +      memset(timing_out, 0, sizeof(struct dc_crtc_timing));
 +
 +      timing_out->h_border_left = 0;
 +      timing_out->h_border_right = 0;
 +      timing_out->v_border_top = 0;
 +      timing_out->v_border_bottom = 0;
 +      /* TODO: un-hardcode */
 +
 +      if ((connector->display_info.color_formats & DRM_COLOR_FORMAT_YCRCB444)
 +                      && stream->sink->sink_signal == SIGNAL_TYPE_HDMI_TYPE_A)
 +              timing_out->pixel_encoding = PIXEL_ENCODING_YCBCR444;
 +      else
 +              timing_out->pixel_encoding = PIXEL_ENCODING_RGB;
 +
 +      timing_out->timing_3d_format = TIMING_3D_FORMAT_NONE;
 +      timing_out->display_color_depth = convert_color_depth_from_display_info(
 +                      connector);
 +      timing_out->scan_type = SCANNING_TYPE_NODATA;
 +      timing_out->hdmi_vic = 0;
 +      timing_out->vic = drm_match_cea_mode(mode_in);
 +
 +      timing_out->h_addressable = mode_in->crtc_hdisplay;
 +      timing_out->h_total = mode_in->crtc_htotal;
 +      timing_out->h_sync_width =
 +              mode_in->crtc_hsync_end - mode_in->crtc_hsync_start;
 +      timing_out->h_front_porch =
 +              mode_in->crtc_hsync_start - mode_in->crtc_hdisplay;
 +      timing_out->v_total = mode_in->crtc_vtotal;
 +      timing_out->v_addressable = mode_in->crtc_vdisplay;
 +      timing_out->v_front_porch =
 +              mode_in->crtc_vsync_start - mode_in->crtc_vdisplay;
 +      timing_out->v_sync_width =
 +              mode_in->crtc_vsync_end - mode_in->crtc_vsync_start;
 +      timing_out->pix_clk_khz = mode_in->crtc_clock;
 +      timing_out->aspect_ratio = get_aspect_ratio(mode_in);
 +      if (mode_in->flags & DRM_MODE_FLAG_PHSYNC)
 +              timing_out->flags.HSYNC_POSITIVE_POLARITY = 1;
 +      if (mode_in->flags & DRM_MODE_FLAG_PVSYNC)
 +              timing_out->flags.VSYNC_POSITIVE_POLARITY = 1;
 +
 +      stream->output_color_space = get_output_color_space(timing_out);
 +
 +      {
 +              struct dc_transfer_func *tf = dc_create_transfer_func();
 +
 +              tf->type = TF_TYPE_PREDEFINED;
 +              tf->tf = TRANSFER_FUNCTION_SRGB;
 +              stream->out_transfer_func = tf;
 +      }
 +}
 +
 +static void fill_audio_info(struct audio_info *audio_info,
 +                          const struct drm_connector *drm_connector,
 +                          const struct dc_sink *dc_sink)
 +{
 +      int i = 0;
 +      int cea_revision = 0;
 +      const struct dc_edid_caps *edid_caps = &dc_sink->edid_caps;
 +
 +      audio_info->manufacture_id = edid_caps->manufacturer_id;
 +      audio_info->product_id = edid_caps->product_id;
 +
 +      cea_revision = drm_connector->display_info.cea_rev;
 +
 +      strncpy(audio_info->display_name,
 +              edid_caps->display_name,
 +              AUDIO_INFO_DISPLAY_NAME_SIZE_IN_CHARS - 1);
 +
 +      if (cea_revision >= 3) {
 +              audio_info->mode_count = edid_caps->audio_mode_count;
 +
 +              for (i = 0; i < audio_info->mode_count; ++i) {
 +                      audio_info->modes[i].format_code =
 +                                      (enum audio_format_code)
 +                                      (edid_caps->audio_modes[i].format_code);
 +                      audio_info->modes[i].channel_count =
 +                                      edid_caps->audio_modes[i].channel_count;
 +                      audio_info->modes[i].sample_rates.all =
 +                                      edid_caps->audio_modes[i].sample_rate;
 +                      audio_info->modes[i].sample_size =
 +                                      edid_caps->audio_modes[i].sample_size;
 +              }
 +      }
 +
 +      audio_info->flags.all = edid_caps->speaker_flags;
 +
 +      /* TODO: We only check for the progressive mode, check for interlace mode too */
 +      if (drm_connector->latency_present[0]) {
 +              audio_info->video_latency = drm_connector->video_latency[0];
 +              audio_info->audio_latency = drm_connector->audio_latency[0];
 +      }
 +
 +      /* TODO: For DP, video and audio latency should be calculated from DPCD caps */
 +
 +}
 +
 +static void
 +copy_crtc_timing_for_drm_display_mode(const struct drm_display_mode *src_mode,
 +                                    struct drm_display_mode *dst_mode)
 +{
 +      dst_mode->crtc_hdisplay = src_mode->crtc_hdisplay;
 +      dst_mode->crtc_vdisplay = src_mode->crtc_vdisplay;
 +      dst_mode->crtc_clock = src_mode->crtc_clock;
 +      dst_mode->crtc_hblank_start = src_mode->crtc_hblank_start;
 +      dst_mode->crtc_hblank_end = src_mode->crtc_hblank_end;
 +      dst_mode->crtc_hsync_start =  src_mode->crtc_hsync_start;
 +      dst_mode->crtc_hsync_end = src_mode->crtc_hsync_end;
 +      dst_mode->crtc_htotal = src_mode->crtc_htotal;
 +      dst_mode->crtc_hskew = src_mode->crtc_hskew;
 +      dst_mode->crtc_vblank_start = src_mode->crtc_vblank_start;
 +      dst_mode->crtc_vblank_end = src_mode->crtc_vblank_end;
 +      dst_mode->crtc_vsync_start = src_mode->crtc_vsync_start;
 +      dst_mode->crtc_vsync_end = src_mode->crtc_vsync_end;
 +      dst_mode->crtc_vtotal = src_mode->crtc_vtotal;
 +}
 +
 +static void
 +decide_crtc_timing_for_drm_display_mode(struct drm_display_mode *drm_mode,
 +                                      const struct drm_display_mode *native_mode,
 +                                      bool scale_enabled)
 +{
 +      if (scale_enabled) {
 +              copy_crtc_timing_for_drm_display_mode(native_mode, drm_mode);
 +      } else if (native_mode->clock == drm_mode->clock &&
 +                      native_mode->htotal == drm_mode->htotal &&
 +                      native_mode->vtotal == drm_mode->vtotal) {
 +              copy_crtc_timing_for_drm_display_mode(native_mode, drm_mode);
 +      } else {
 +              /* no scaling nor amdgpu inserted, no need to patch */
 +      }
 +}
 +
 +static int create_fake_sink(struct amdgpu_dm_connector *aconnector)
 +{
 +      struct dc_sink *sink = NULL;
 +      struct dc_sink_init_data sink_init_data = { 0 };
 +
 +      sink_init_data.link = aconnector->dc_link;
 +      sink_init_data.sink_signal = aconnector->dc_link->connector_signal;
 +
 +      sink = dc_sink_create(&sink_init_data);
 +      if (!sink) {
 +              DRM_ERROR("Failed to create sink!\n");
 +              return -ENOMEM;
 +      }
 +
 +      sink->sink_signal = SIGNAL_TYPE_VIRTUAL;
 +      aconnector->fake_enable = true;
 +
 +      aconnector->dc_sink = sink;
 +      aconnector->dc_link->local_sink = sink;
 +
 +      return 0;
 +}
 +
 +static struct dc_stream_state *
 +create_stream_for_sink(struct amdgpu_dm_connector *aconnector,
 +                     const struct drm_display_mode *drm_mode,
 +                     const struct dm_connector_state *dm_state)
 +{
 +      struct drm_display_mode *preferred_mode = NULL;
 +      const struct drm_connector *drm_connector;
 +      struct dc_stream_state *stream = NULL;
 +      struct drm_display_mode mode = *drm_mode;
 +      bool native_mode_found = false;
 +
 +      if (aconnector == NULL) {
 +              DRM_ERROR("aconnector is NULL!\n");
 +              goto drm_connector_null;
 +      }
 +
 +      if (dm_state == NULL) {
 +              DRM_ERROR("dm_state is NULL!\n");
 +              goto dm_state_null;
 +      }
 +
 +      drm_connector = &aconnector->base;
 +
 +      if (!aconnector->dc_sink) {
 +              /*
 +               * Exclude MST from creating fake_sink
 +               * TODO: need to enable MST into fake_sink feature
 +               */
 +              if (aconnector->mst_port)
 +                      goto stream_create_fail;
 +
 +              if (create_fake_sink(aconnector))
 +                      goto stream_create_fail;
 +      }
 +
 +      stream = dc_create_stream_for_sink(aconnector->dc_sink);
 +
 +      if (stream == NULL) {
 +              DRM_ERROR("Failed to create stream for sink!\n");
 +              goto stream_create_fail;
 +      }
 +
 +      list_for_each_entry(preferred_mode, &aconnector->base.modes, head) {
 +              /* Search for preferred mode */
 +              if (preferred_mode->type & DRM_MODE_TYPE_PREFERRED) {
 +                      native_mode_found = true;
 +                      break;
 +              }
 +      }
 +      if (!native_mode_found)
 +              preferred_mode = list_first_entry_or_null(
 +                              &aconnector->base.modes,
 +                              struct drm_display_mode,
 +                              head);
 +
 +      if (preferred_mode == NULL) {
 +              /* This may not be an error, the use case is when we we have no
 +               * usermode calls to reset and set mode upon hotplug. In this
 +               * case, we call set mode ourselves to restore the previous mode
 +               * and the modelist may not be filled in in time.
 +               */
 +              DRM_DEBUG_DRIVER("No preferred mode found\n");
 +      } else {
 +              decide_crtc_timing_for_drm_display_mode(
 +                              &mode, preferred_mode,
 +                              dm_state->scaling != RMX_OFF);
 +      }
 +
 +      fill_stream_properties_from_drm_display_mode(stream,
 +                      &mode, &aconnector->base);
 +      update_stream_scaling_settings(&mode, dm_state, stream);
 +
 +      fill_audio_info(
 +              &stream->audio_info,
 +              drm_connector,
 +              aconnector->dc_sink);
 +
 +stream_create_fail:
 +dm_state_null:
 +drm_connector_null:
 +      return stream;
 +}
 +
 +static void amdgpu_dm_crtc_destroy(struct drm_crtc *crtc)
 +{
 +      drm_crtc_cleanup(crtc);
 +      kfree(crtc);
 +}
 +
 +static void dm_crtc_destroy_state(struct drm_crtc *crtc,
 +                                struct drm_crtc_state *state)
 +{
 +      struct dm_crtc_state *cur = to_dm_crtc_state(state);
 +
 +      /* TODO Destroy dc_stream objects are stream object is flattened */
 +      if (cur->stream)
 +              dc_stream_release(cur->stream);
 +
 +
 +      __drm_atomic_helper_crtc_destroy_state(state);
 +
 +
 +      kfree(state);
 +}
 +
 +static void dm_crtc_reset_state(struct drm_crtc *crtc)
 +{
 +      struct dm_crtc_state *state;
 +
 +      if (crtc->state)
 +              dm_crtc_destroy_state(crtc, crtc->state);
 +
 +      state = kzalloc(sizeof(*state), GFP_KERNEL);
 +      if (WARN_ON(!state))
 +              return;
 +
 +      crtc->state = &state->base;
 +      crtc->state->crtc = crtc;
 +
 +}
 +
 +static struct drm_crtc_state *
 +dm_crtc_duplicate_state(struct drm_crtc *crtc)
 +{
 +      struct dm_crtc_state *state, *cur;
 +
 +      cur = to_dm_crtc_state(crtc->state);
 +
 +      if (WARN_ON(!crtc->state))
 +              return NULL;
 +
 +      state = kzalloc(sizeof(*state), GFP_KERNEL);
 +      if (!state)
 +              return NULL;
 +
 +      __drm_atomic_helper_crtc_duplicate_state(crtc, &state->base);
 +
 +      if (cur->stream) {
 +              state->stream = cur->stream;
 +              dc_stream_retain(state->stream);
 +      }
 +
 +      /* TODO Duplicate dc_stream after objects are stream object is flattened */
 +
 +      return &state->base;
 +}
 +
 +/* Implemented only the options currently availible for the driver */
 +static const struct drm_crtc_funcs amdgpu_dm_crtc_funcs = {
 +      .reset = dm_crtc_reset_state,
 +      .destroy = amdgpu_dm_crtc_destroy,
 +      .gamma_set = drm_atomic_helper_legacy_gamma_set,
 +      .set_config = drm_atomic_helper_set_config,
 +      .page_flip = drm_atomic_helper_page_flip,
 +      .atomic_duplicate_state = dm_crtc_duplicate_state,
 +      .atomic_destroy_state = dm_crtc_destroy_state,
 +};
 +
 +static enum drm_connector_status
 +amdgpu_dm_connector_detect(struct drm_connector *connector, bool force)
 +{
 +      bool connected;
 +      struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(connector);
 +
 +      /* Notes:
 +       * 1. This interface is NOT called in context of HPD irq.
 +       * 2. This interface *is called* in context of user-mode ioctl. Which
 +       * makes it a bad place for *any* MST-related activit. */
 +
 +      if (aconnector->base.force == DRM_FORCE_UNSPECIFIED &&
 +          !aconnector->fake_enable)
 +              connected = (aconnector->dc_sink != NULL);
 +      else
 +              connected = (aconnector->base.force == DRM_FORCE_ON);
 +
 +      return (connected ? connector_status_connected :
 +                      connector_status_disconnected);
 +}
 +
 +int amdgpu_dm_connector_atomic_set_property(struct drm_connector *connector,
 +                                          struct drm_connector_state *connector_state,
 +                                          struct drm_property *property,
 +                                          uint64_t val)
 +{
 +      struct drm_device *dev = connector->dev;
 +      struct amdgpu_device *adev = dev->dev_private;
 +      struct dm_connector_state *dm_old_state =
 +              to_dm_connector_state(connector->state);
 +      struct dm_connector_state *dm_new_state =
 +              to_dm_connector_state(connector_state);
 +
 +      int ret = -EINVAL;
 +
 +      if (property == dev->mode_config.scaling_mode_property) {
 +              enum amdgpu_rmx_type rmx_type;
 +
 +              switch (val) {
 +              case DRM_MODE_SCALE_CENTER:
 +                      rmx_type = RMX_CENTER;
 +                      break;
 +              case DRM_MODE_SCALE_ASPECT:
 +                      rmx_type = RMX_ASPECT;
 +                      break;
 +              case DRM_MODE_SCALE_FULLSCREEN:
 +                      rmx_type = RMX_FULL;
 +                      break;
 +              case DRM_MODE_SCALE_NONE:
 +              default:
 +                      rmx_type = RMX_OFF;
 +                      break;
 +              }
 +
 +              if (dm_old_state->scaling == rmx_type)
 +                      return 0;
 +
 +              dm_new_state->scaling = rmx_type;
 +              ret = 0;
 +      } else if (property == adev->mode_info.underscan_hborder_property) {
 +              dm_new_state->underscan_hborder = val;
 +              ret = 0;
 +      } else if (property == adev->mode_info.underscan_vborder_property) {
 +              dm_new_state->underscan_vborder = val;
 +              ret = 0;
 +      } else if (property == adev->mode_info.underscan_property) {
 +              dm_new_state->underscan_enable = val;
 +              ret = 0;
 +      }
 +
 +      return ret;
 +}
 +
 +int amdgpu_dm_connector_atomic_get_property(struct drm_connector *connector,
 +                                          const struct drm_connector_state *state,
 +                                          struct drm_property *property,
 +                                          uint64_t *val)
 +{
 +      struct drm_device *dev = connector->dev;
 +      struct amdgpu_device *adev = dev->dev_private;
 +      struct dm_connector_state *dm_state =
 +              to_dm_connector_state(state);
 +      int ret = -EINVAL;
 +
 +      if (property == dev->mode_config.scaling_mode_property) {
 +              switch (dm_state->scaling) {
 +              case RMX_CENTER:
 +                      *val = DRM_MODE_SCALE_CENTER;
 +                      break;
 +              case RMX_ASPECT:
 +                      *val = DRM_MODE_SCALE_ASPECT;
 +                      break;
 +              case RMX_FULL:
 +                      *val = DRM_MODE_SCALE_FULLSCREEN;
 +                      break;
 +              case RMX_OFF:
 +              default:
 +                      *val = DRM_MODE_SCALE_NONE;
 +                      break;
 +              }
 +              ret = 0;
 +      } else if (property == adev->mode_info.underscan_hborder_property) {
 +              *val = dm_state->underscan_hborder;
 +              ret = 0;
 +      } else if (property == adev->mode_info.underscan_vborder_property) {
 +              *val = dm_state->underscan_vborder;
 +              ret = 0;
 +      } else if (property == adev->mode_info.underscan_property) {
 +              *val = dm_state->underscan_enable;
 +              ret = 0;
 +      }
 +      return ret;
 +}
 +
 +static void amdgpu_dm_connector_destroy(struct drm_connector *connector)
 +{
 +      struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(connector);
 +      const struct dc_link *link = aconnector->dc_link;
 +      struct amdgpu_device *adev = connector->dev->dev_private;
 +      struct amdgpu_display_manager *dm = &adev->dm;
 +#if defined(CONFIG_BACKLIGHT_CLASS_DEVICE) ||\
 +      defined(CONFIG_BACKLIGHT_CLASS_DEVICE_MODULE)
 +
 +      if (link->connector_signal & (SIGNAL_TYPE_EDP | SIGNAL_TYPE_LVDS)) {
 +              amdgpu_dm_register_backlight_device(dm);
 +
 +              if (dm->backlight_dev) {
 +                      backlight_device_unregister(dm->backlight_dev);
 +                      dm->backlight_dev = NULL;
 +              }
 +
 +      }
 +#endif
 +      drm_connector_unregister(connector);
 +      drm_connector_cleanup(connector);
 +      kfree(connector);
 +}
 +
 +void amdgpu_dm_connector_funcs_reset(struct drm_connector *connector)
 +{
 +      struct dm_connector_state *state =
 +              to_dm_connector_state(connector->state);
 +
 +      kfree(state);
 +
 +      state = kzalloc(sizeof(*state), GFP_KERNEL);
 +
 +      if (state) {
 +              state->scaling = RMX_OFF;
 +              state->underscan_enable = false;
 +              state->underscan_hborder = 0;
 +              state->underscan_vborder = 0;
 +
 +              connector->state = &state->base;
 +              connector->state->connector = connector;
 +      }
 +}
 +
 +struct drm_connector_state *
 +amdgpu_dm_connector_atomic_duplicate_state(struct drm_connector *connector)
 +{
 +      struct dm_connector_state *state =
 +              to_dm_connector_state(connector->state);
 +
 +      struct dm_connector_state *new_state =
 +                      kmemdup(state, sizeof(*state), GFP_KERNEL);
 +
 +      if (new_state) {
 +              __drm_atomic_helper_connector_duplicate_state(connector,
 +                                                            &new_state->base);
 +              return &new_state->base;
 +      }
 +
 +      return NULL;
 +}
 +
 +static const struct drm_connector_funcs amdgpu_dm_connector_funcs = {
 +      .reset = amdgpu_dm_connector_funcs_reset,
 +      .detect = amdgpu_dm_connector_detect,
 +      .fill_modes = drm_helper_probe_single_connector_modes,
 +      .destroy = amdgpu_dm_connector_destroy,
 +      .atomic_duplicate_state = amdgpu_dm_connector_atomic_duplicate_state,
 +      .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
 +      .atomic_set_property = amdgpu_dm_connector_atomic_set_property,
 +      .atomic_get_property = amdgpu_dm_connector_atomic_get_property
 +};
 +
 +static struct drm_encoder *best_encoder(struct drm_connector *connector)
 +{
 +      int enc_id = connector->encoder_ids[0];
 +      struct drm_mode_object *obj;
 +      struct drm_encoder *encoder;
 +
 +      DRM_DEBUG_DRIVER("Finding the best encoder\n");
 +
 +      /* pick the encoder ids */
 +      if (enc_id) {
 +              obj = drm_mode_object_find(connector->dev, NULL, enc_id, DRM_MODE_OBJECT_ENCODER);
 +              if (!obj) {
 +                      DRM_ERROR("Couldn't find a matching encoder for our connector\n");
 +                      return NULL;
 +              }
 +              encoder = obj_to_encoder(obj);
 +              return encoder;
 +      }
 +      DRM_ERROR("No encoder id\n");
 +      return NULL;
 +}
 +
 +static int get_modes(struct drm_connector *connector)
 +{
 +      return amdgpu_dm_connector_get_modes(connector);
 +}
 +
 +static void create_eml_sink(struct amdgpu_dm_connector *aconnector)
 +{
 +      struct dc_sink_init_data init_params = {
 +                      .link = aconnector->dc_link,
 +                      .sink_signal = SIGNAL_TYPE_VIRTUAL
 +      };
 +      struct edid *edid;
 +
 +      if (!aconnector->base.edid_blob_ptr ||
 +              !aconnector->base.edid_blob_ptr->data) {
 +              DRM_ERROR("No EDID firmware found on connector: %s ,forcing to OFF!\n",
 +                              aconnector->base.name);
 +
 +              aconnector->base.force = DRM_FORCE_OFF;
 +              aconnector->base.override_edid = false;
 +              return;
 +      }
 +
 +      edid = (struct edid *) aconnector->base.edid_blob_ptr->data;
 +
 +      aconnector->edid = edid;
 +
 +      aconnector->dc_em_sink = dc_link_add_remote_sink(
 +              aconnector->dc_link,
 +              (uint8_t *)edid,
 +              (edid->extensions + 1) * EDID_LENGTH,
 +              &init_params);
 +
 +      if (aconnector->base.force == DRM_FORCE_ON)
 +              aconnector->dc_sink = aconnector->dc_link->local_sink ?
 +              aconnector->dc_link->local_sink :
 +              aconnector->dc_em_sink;
 +}
 +
 +static void handle_edid_mgmt(struct amdgpu_dm_connector *aconnector)
 +{
 +      struct dc_link *link = (struct dc_link *)aconnector->dc_link;
 +
 +      /* In case of headless boot with force on for DP managed connector
 +       * Those settings have to be != 0 to get initial modeset
 +       */
 +      if (link->connector_signal == SIGNAL_TYPE_DISPLAY_PORT) {
 +              link->verified_link_cap.lane_count = LANE_COUNT_FOUR;
 +              link->verified_link_cap.link_rate = LINK_RATE_HIGH2;
 +      }
 +
 +
 +      aconnector->base.override_edid = true;
 +      create_eml_sink(aconnector);
 +}
 +
 +int amdgpu_dm_connector_mode_valid(struct drm_connector *connector,
 +                                 struct drm_display_mode *mode)
 +{
 +      int result = MODE_ERROR;
 +      struct dc_sink *dc_sink;
 +      struct amdgpu_device *adev = connector->dev->dev_private;
 +      /* TODO: Unhardcode stream count */
 +      struct dc_stream_state *stream;
 +      struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(connector);
 +
 +      if ((mode->flags & DRM_MODE_FLAG_INTERLACE) ||
 +                      (mode->flags & DRM_MODE_FLAG_DBLSCAN))
 +              return result;
 +
 +      /* Only run this the first time mode_valid is called to initilialize
 +       * EDID mgmt
 +       */
 +      if (aconnector->base.force != DRM_FORCE_UNSPECIFIED &&
 +              !aconnector->dc_em_sink)
 +              handle_edid_mgmt(aconnector);
 +
 +      dc_sink = to_amdgpu_dm_connector(connector)->dc_sink;
 +
 +      if (dc_sink == NULL) {
 +              DRM_ERROR("dc_sink is NULL!\n");
 +              goto fail;
 +      }
 +
 +      stream = dc_create_stream_for_sink(dc_sink);
 +      if (stream == NULL) {
 +              DRM_ERROR("Failed to create stream for sink!\n");
 +              goto fail;
 +      }
 +
 +      drm_mode_set_crtcinfo(mode, 0);
 +      fill_stream_properties_from_drm_display_mode(stream, mode, connector);
 +
 +      stream->src.width = mode->hdisplay;
 +      stream->src.height = mode->vdisplay;
 +      stream->dst = stream->src;
 +
 +      if (dc_validate_stream(adev->dm.dc, stream) == DC_OK)
 +              result = MODE_OK;
 +
 +      dc_stream_release(stream);
 +
 +fail:
 +      /* TODO: error handling*/
 +      return result;
 +}
 +
 +static const struct drm_connector_helper_funcs
 +amdgpu_dm_connector_helper_funcs = {
 +      /*
 +       * If hotplug a second bigger display in FB Con mode, bigger resolution
 +       * modes will be filtered by drm_mode_validate_size(), and those modes
 +       * is missing after user start lightdm. So we need to renew modes list.
 +       * in get_modes call back, not just return the modes count
 +       */
 +      .get_modes = get_modes,
 +      .mode_valid = amdgpu_dm_connector_mode_valid,
 +      .best_encoder = best_encoder
 +};
 +
 +static void dm_crtc_helper_disable(struct drm_crtc *crtc)
 +{
 +}
 +
 +static int dm_crtc_helper_atomic_check(struct drm_crtc *crtc,
 +                                     struct drm_crtc_state *state)
 +{
 +      struct amdgpu_device *adev = crtc->dev->dev_private;
 +      struct dc *dc = adev->dm.dc;
 +      struct dm_crtc_state *dm_crtc_state = to_dm_crtc_state(state);
 +      int ret = -EINVAL;
 +
 +      if (unlikely(!dm_crtc_state->stream &&
 +                   modeset_required(state, NULL, dm_crtc_state->stream))) {
 +              WARN_ON(1);
 +              return ret;
 +      }
 +
 +      /* In some use cases, like reset, no stream  is attached */
 +      if (!dm_crtc_state->stream)
 +              return 0;
 +
 +      if (dc_validate_stream(dc, dm_crtc_state->stream) == DC_OK)
 +              return 0;
 +
 +      return ret;
 +}
 +
 +static bool dm_crtc_helper_mode_fixup(struct drm_crtc *crtc,
 +                                    const struct drm_display_mode *mode,
 +                                    struct drm_display_mode *adjusted_mode)
 +{
 +      return true;
 +}
 +
 +static const struct drm_crtc_helper_funcs amdgpu_dm_crtc_helper_funcs = {
 +      .disable = dm_crtc_helper_disable,
 +      .atomic_check = dm_crtc_helper_atomic_check,
 +      .mode_fixup = dm_crtc_helper_mode_fixup
 +};
 +
 +static void dm_encoder_helper_disable(struct drm_encoder *encoder)
 +{
 +
 +}
 +
 +static int dm_encoder_helper_atomic_check(struct drm_encoder *encoder,
 +                                        struct drm_crtc_state *crtc_state,
 +                                        struct drm_connector_state *conn_state)
 +{
 +      return 0;
 +}
 +
 +const struct drm_encoder_helper_funcs amdgpu_dm_encoder_helper_funcs = {
 +      .disable = dm_encoder_helper_disable,
 +      .atomic_check = dm_encoder_helper_atomic_check
 +};
 +
 +static void dm_drm_plane_reset(struct drm_plane *plane)
 +{
 +      struct dm_plane_state *amdgpu_state = NULL;
 +
 +      if (plane->state)
 +              plane->funcs->atomic_destroy_state(plane, plane->state);
 +
 +      amdgpu_state = kzalloc(sizeof(*amdgpu_state), GFP_KERNEL);
 +      WARN_ON(amdgpu_state == NULL);
 +      
 +      if (amdgpu_state) {
 +              plane->state = &amdgpu_state->base;
 +              plane->state->plane = plane;
 +              plane->state->rotation = DRM_MODE_ROTATE_0;
 +      }
 +}
 +
 +static struct drm_plane_state *
 +dm_drm_plane_duplicate_state(struct drm_plane *plane)
 +{
 +      struct dm_plane_state *dm_plane_state, *old_dm_plane_state;
 +
 +      old_dm_plane_state = to_dm_plane_state(plane->state);
 +      dm_plane_state = kzalloc(sizeof(*dm_plane_state), GFP_KERNEL);
 +      if (!dm_plane_state)
 +              return NULL;
 +
 +      __drm_atomic_helper_plane_duplicate_state(plane, &dm_plane_state->base);
 +
 +      if (old_dm_plane_state->dc_state) {
 +              dm_plane_state->dc_state = old_dm_plane_state->dc_state;
 +              dc_plane_state_retain(dm_plane_state->dc_state);
 +      }
 +
 +      return &dm_plane_state->base;
 +}
 +
 +void dm_drm_plane_destroy_state(struct drm_plane *plane,
 +                              struct drm_plane_state *state)
 +{
 +      struct dm_plane_state *dm_plane_state = to_dm_plane_state(state);
 +
 +      if (dm_plane_state->dc_state)
 +              dc_plane_state_release(dm_plane_state->dc_state);
 +
 +      drm_atomic_helper_plane_destroy_state(plane, state);
 +}
 +
 +static const struct drm_plane_funcs dm_plane_funcs = {
 +      .update_plane   = drm_atomic_helper_update_plane,
 +      .disable_plane  = drm_atomic_helper_disable_plane,
 +      .destroy        = drm_plane_cleanup,
 +      .reset = dm_drm_plane_reset,
 +      .atomic_duplicate_state = dm_drm_plane_duplicate_state,
 +      .atomic_destroy_state = dm_drm_plane_destroy_state,
 +};
 +
 +static int dm_plane_helper_prepare_fb(struct drm_plane *plane,
 +                                    struct drm_plane_state *new_state)
 +{
 +      struct amdgpu_framebuffer *afb;
 +      struct drm_gem_object *obj;
 +      struct amdgpu_bo *rbo;
 +      uint64_t chroma_addr = 0;
 +      int r;
 +      struct dm_plane_state *dm_plane_state_new, *dm_plane_state_old;
 +      unsigned int awidth;
 +
 +      dm_plane_state_old = to_dm_plane_state(plane->state);
 +      dm_plane_state_new = to_dm_plane_state(new_state);
 +
 +      if (!new_state->fb) {
 +              DRM_DEBUG_DRIVER("No FB bound\n");
 +              return 0;
 +      }
 +
 +      afb = to_amdgpu_framebuffer(new_state->fb);
 +
 +      obj = afb->obj;
 +      rbo = gem_to_amdgpu_bo(obj);
 +      r = amdgpu_bo_reserve(rbo, false);
 +      if (unlikely(r != 0))
 +              return r;
 +
 +      r = amdgpu_bo_pin(rbo, AMDGPU_GEM_DOMAIN_VRAM, &afb->address);
 +
 +
 +      amdgpu_bo_unreserve(rbo);
 +
 +      if (unlikely(r != 0)) {
 +              if (r != -ERESTARTSYS)
 +                      DRM_ERROR("Failed to pin framebuffer with error %d\n", r);
 +              return r;
 +      }
 +
 +      amdgpu_bo_ref(rbo);
 +
 +      if (dm_plane_state_new->dc_state &&
 +                      dm_plane_state_old->dc_state != dm_plane_state_new->dc_state) {
 +              struct dc_plane_state *plane_state = dm_plane_state_new->dc_state;
 +
 +              if (plane_state->format < SURFACE_PIXEL_FORMAT_VIDEO_BEGIN) {
 +                      plane_state->address.grph.addr.low_part = lower_32_bits(afb->address);
 +                      plane_state->address.grph.addr.high_part = upper_32_bits(afb->address);
 +              } else {
 +                      awidth = ALIGN(new_state->fb->width, 64);
 +                      plane_state->address.type = PLN_ADDR_TYPE_VIDEO_PROGRESSIVE;
 +                      plane_state->address.video_progressive.luma_addr.low_part
 +                                                      = lower_32_bits(afb->address);
 +                      plane_state->address.video_progressive.luma_addr.high_part
 +                                                      = upper_32_bits(afb->address);
 +                      chroma_addr = afb->address + (u64)(awidth * new_state->fb->height);
 +                      plane_state->address.video_progressive.chroma_addr.low_part
 +                                                      = lower_32_bits(chroma_addr);
 +                      plane_state->address.video_progressive.chroma_addr.high_part
 +                                                      = upper_32_bits(chroma_addr);
 +              }
 +      }
 +
 +      /* It's a hack for s3 since in 4.9 kernel filter out cursor buffer
 +       * prepare and cleanup in drm_atomic_helper_prepare_planes
 +       * and drm_atomic_helper_cleanup_planes because fb doens't in s3.
 +       * IN 4.10 kernel this code should be removed and amdgpu_device_suspend
 +       * code touching fram buffers should be avoided for DC.
 +       */
 +      if (plane->type == DRM_PLANE_TYPE_CURSOR) {
 +              struct amdgpu_crtc *acrtc = to_amdgpu_crtc(new_state->crtc);
 +
 +              acrtc->cursor_bo = obj;
 +      }
 +      return 0;
 +}
 +
 +static void dm_plane_helper_cleanup_fb(struct drm_plane *plane,
 +                                     struct drm_plane_state *old_state)
 +{
 +      struct amdgpu_bo *rbo;
 +      struct amdgpu_framebuffer *afb;
 +      int r;
 +
 +      if (!old_state->fb)
 +              return;
 +
 +      afb = to_amdgpu_framebuffer(old_state->fb);
 +      rbo = gem_to_amdgpu_bo(afb->obj);
 +      r = amdgpu_bo_reserve(rbo, false);
 +      if (unlikely(r)) {
 +              DRM_ERROR("failed to reserve rbo before unpin\n");
 +              return;
 +      }
 +
 +      amdgpu_bo_unpin(rbo);
 +      amdgpu_bo_unreserve(rbo);
 +      amdgpu_bo_unref(&rbo);
 +}
 +
 +static int dm_plane_atomic_check(struct drm_plane *plane,
 +                               struct drm_plane_state *state)
 +{
 +      struct amdgpu_device *adev = plane->dev->dev_private;
 +      struct dc *dc = adev->dm.dc;
 +      struct dm_plane_state *dm_plane_state = to_dm_plane_state(state);
 +
 +      if (!dm_plane_state->dc_state)
 +              return 0;
 +
 +      if (dc_validate_plane(dc, dm_plane_state->dc_state) == DC_OK)
 +              return 0;
 +
 +      return -EINVAL;
 +}
 +
 +static const struct drm_plane_helper_funcs dm_plane_helper_funcs = {
 +      .prepare_fb = dm_plane_helper_prepare_fb,
 +      .cleanup_fb = dm_plane_helper_cleanup_fb,
 +      .atomic_check = dm_plane_atomic_check,
 +};
 +
 +/*
 + * TODO: these are currently initialized to rgb formats only.
 + * For future use cases we should either initialize them dynamically based on
 + * plane capabilities, or initialize this array to all formats, so internal drm
 + * check will succeed, and let DC to implement proper check
 + */
 +static const uint32_t rgb_formats[] = {
 +      DRM_FORMAT_RGB888,
 +      DRM_FORMAT_XRGB8888,
 +      DRM_FORMAT_ARGB8888,
 +      DRM_FORMAT_RGBA8888,
 +      DRM_FORMAT_XRGB2101010,
 +      DRM_FORMAT_XBGR2101010,
 +      DRM_FORMAT_ARGB2101010,
 +      DRM_FORMAT_ABGR2101010,
 +};
 +
 +static const uint32_t yuv_formats[] = {
 +      DRM_FORMAT_NV12,
 +      DRM_FORMAT_NV21,
 +};
 +
 +static const u32 cursor_formats[] = {
 +      DRM_FORMAT_ARGB8888
 +};
 +
 +static int amdgpu_dm_plane_init(struct amdgpu_display_manager *dm,
 +                              struct amdgpu_plane *aplane,
 +                              unsigned long possible_crtcs)
 +{
 +      int res = -EPERM;
 +
 +      switch (aplane->base.type) {
 +      case DRM_PLANE_TYPE_PRIMARY:
 +              aplane->base.format_default = true;
 +
 +              res = drm_universal_plane_init(
 +                              dm->adev->ddev,
 +                              &aplane->base,
 +                              possible_crtcs,
 +                              &dm_plane_funcs,
 +                              rgb_formats,
 +                              ARRAY_SIZE(rgb_formats),
 +                              NULL, aplane->base.type, NULL);
 +              break;
 +      case DRM_PLANE_TYPE_OVERLAY:
 +              res = drm_universal_plane_init(
 +                              dm->adev->ddev,
 +                              &aplane->base,
 +                              possible_crtcs,
 +                              &dm_plane_funcs,
 +                              yuv_formats,
 +                              ARRAY_SIZE(yuv_formats),
 +                              NULL, aplane->base.type, NULL);
 +              break;
 +      case DRM_PLANE_TYPE_CURSOR:
 +              res = drm_universal_plane_init(
 +                              dm->adev->ddev,
 +                              &aplane->base,
 +                              possible_crtcs,
 +                              &dm_plane_funcs,
 +                              cursor_formats,
 +                              ARRAY_SIZE(cursor_formats),
 +                              NULL, aplane->base.type, NULL);
 +              break;
 +      }
 +
 +      drm_plane_helper_add(&aplane->base, &dm_plane_helper_funcs);
 +
 +      /* Create (reset) the plane state */
 +      if (aplane->base.funcs->reset)
 +              aplane->base.funcs->reset(&aplane->base);
 +
 +
 +      return res;
 +}
 +
 +static int amdgpu_dm_crtc_init(struct amdgpu_display_manager *dm,
 +                             struct drm_plane *plane,
 +                             uint32_t crtc_index)
 +{
 +      struct amdgpu_crtc *acrtc = NULL;
 +      struct amdgpu_plane *cursor_plane;
 +
 +      int res = -ENOMEM;
 +
 +      cursor_plane = kzalloc(sizeof(*cursor_plane), GFP_KERNEL);
 +      if (!cursor_plane)
 +              goto fail;
 +
 +      cursor_plane->base.type = DRM_PLANE_TYPE_CURSOR;
 +      res = amdgpu_dm_plane_init(dm, cursor_plane, 0);
 +
 +      acrtc = kzalloc(sizeof(struct amdgpu_crtc), GFP_KERNEL);
 +      if (!acrtc)
 +              goto fail;
 +
 +      res = drm_crtc_init_with_planes(
 +                      dm->ddev,
 +                      &acrtc->base,
 +                      plane,
 +                      &cursor_plane->base,
 +                      &amdgpu_dm_crtc_funcs, NULL);
 +
 +      if (res)
 +              goto fail;
 +
 +      drm_crtc_helper_add(&acrtc->base, &amdgpu_dm_crtc_helper_funcs);
 +
 +      /* Create (reset) the plane state */
 +      if (acrtc->base.funcs->reset)
 +              acrtc->base.funcs->reset(&acrtc->base);
 +
 +      acrtc->max_cursor_width = dm->adev->dm.dc->caps.max_cursor_size;
 +      acrtc->max_cursor_height = dm->adev->dm.dc->caps.max_cursor_size;
 +
 +      acrtc->crtc_id = crtc_index;
 +      acrtc->base.enabled = false;
 +
 +      dm->adev->mode_info.crtcs[crtc_index] = acrtc;
 +      drm_mode_crtc_set_gamma_size(&acrtc->base, 256);
 +
 +      return 0;
 +
 +fail:
 +      kfree(acrtc);
 +      kfree(cursor_plane);
 +      return res;
 +}
 +
 +
 +static int to_drm_connector_type(enum signal_type st)
 +{
 +      switch (st) {
 +      case SIGNAL_TYPE_HDMI_TYPE_A:
 +              return DRM_MODE_CONNECTOR_HDMIA;
 +      case SIGNAL_TYPE_EDP:
 +              return DRM_MODE_CONNECTOR_eDP;
 +      case SIGNAL_TYPE_RGB:
 +              return DRM_MODE_CONNECTOR_VGA;
 +      case SIGNAL_TYPE_DISPLAY_PORT:
 +      case SIGNAL_TYPE_DISPLAY_PORT_MST:
 +              return DRM_MODE_CONNECTOR_DisplayPort;
 +      case SIGNAL_TYPE_DVI_DUAL_LINK:
 +      case SIGNAL_TYPE_DVI_SINGLE_LINK:
 +              return DRM_MODE_CONNECTOR_DVID;
 +      case SIGNAL_TYPE_VIRTUAL:
 +              return DRM_MODE_CONNECTOR_VIRTUAL;
 +
 +      default:
 +              return DRM_MODE_CONNECTOR_Unknown;
 +      }
 +}
 +
 +static void amdgpu_dm_get_native_mode(struct drm_connector *connector)
 +{
 +      const struct drm_connector_helper_funcs *helper =
 +              connector->helper_private;
 +      struct drm_encoder *encoder;
 +      struct amdgpu_encoder *amdgpu_encoder;
 +
 +      encoder = helper->best_encoder(connector);
 +
 +      if (encoder == NULL)
 +              return;
 +
 +      amdgpu_encoder = to_amdgpu_encoder(encoder);
 +
 +      amdgpu_encoder->native_mode.clock = 0;
 +
 +      if (!list_empty(&connector->probed_modes)) {
 +              struct drm_display_mode *preferred_mode = NULL;
 +
 +              list_for_each_entry(preferred_mode,
 +                                  &connector->probed_modes,
 +                                  head) {
 +                      if (preferred_mode->type & DRM_MODE_TYPE_PREFERRED)
 +                              amdgpu_encoder->native_mode = *preferred_mode;
 +
 +                      break;
 +              }
 +
 +      }
 +}
 +
 +static struct drm_display_mode *
 +amdgpu_dm_create_common_mode(struct drm_encoder *encoder,
 +                           char *name,
 +                           int hdisplay, int vdisplay)
 +{
 +      struct drm_device *dev = encoder->dev;
 +      struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
 +      struct drm_display_mode *mode = NULL;
 +      struct drm_display_mode *native_mode = &amdgpu_encoder->native_mode;
 +
 +      mode = drm_mode_duplicate(dev, native_mode);
 +
 +      if (mode == NULL)
 +              return NULL;
 +
 +      mode->hdisplay = hdisplay;
 +      mode->vdisplay = vdisplay;
 +      mode->type &= ~DRM_MODE_TYPE_PREFERRED;
 +      strncpy(mode->name, name, DRM_DISPLAY_MODE_LEN);
 +
 +      return mode;
 +
 +}
 +
 +static void amdgpu_dm_connector_add_common_modes(struct drm_encoder *encoder,
 +                                               struct drm_connector *connector)
 +{
 +      struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
 +      struct drm_display_mode *mode = NULL;
 +      struct drm_display_mode *native_mode = &amdgpu_encoder->native_mode;
 +      struct amdgpu_dm_connector *amdgpu_dm_connector =
 +                              to_amdgpu_dm_connector(connector);
 +      int i;
 +      int n;
 +      struct mode_size {
 +              char name[DRM_DISPLAY_MODE_LEN];
 +              int w;
 +              int h;
 +      } common_modes[] = {
 +              {  "640x480",  640,  480},
 +              {  "800x600",  800,  600},
 +              { "1024x768", 1024,  768},
 +              { "1280x720", 1280,  720},
 +              { "1280x800", 1280,  800},
 +              {"1280x1024", 1280, 1024},
 +              { "1440x900", 1440,  900},
 +              {"1680x1050", 1680, 1050},
 +              {"1600x1200", 1600, 1200},
 +              {"1920x1080", 1920, 1080},
 +              {"1920x1200", 1920, 1200}
 +      };
 +
 +      n = ARRAY_SIZE(common_modes);
 +
 +      for (i = 0; i < n; i++) {
 +              struct drm_display_mode *curmode = NULL;
 +              bool mode_existed = false;
 +
 +              if (common_modes[i].w > native_mode->hdisplay ||
 +                  common_modes[i].h > native_mode->vdisplay ||
 +                 (common_modes[i].w == native_mode->hdisplay &&
 +                  common_modes[i].h == native_mode->vdisplay))
 +                      continue;
 +
 +              list_for_each_entry(curmode, &connector->probed_modes, head) {
 +                      if (common_modes[i].w == curmode->hdisplay &&
 +                          common_modes[i].h == curmode->vdisplay) {
 +                              mode_existed = true;
 +                              break;
 +                      }
 +              }
 +
 +              if (mode_existed)
 +                      continue;
 +
 +              mode = amdgpu_dm_create_common_mode(encoder,
 +                              common_modes[i].name, common_modes[i].w,
 +                              common_modes[i].h);
 +              drm_mode_probed_add(connector, mode);
 +              amdgpu_dm_connector->num_modes++;
 +      }
 +}
 +
 +static void amdgpu_dm_connector_ddc_get_modes(struct drm_connector *connector,
 +                                            struct edid *edid)
 +{
 +      struct amdgpu_dm_connector *amdgpu_dm_connector =
 +                      to_amdgpu_dm_connector(connector);
 +
 +      if (edid) {
 +              /* empty probed_modes */
 +              INIT_LIST_HEAD(&connector->probed_modes);
 +              amdgpu_dm_connector->num_modes =
 +                              drm_add_edid_modes(connector, edid);
 +
 +              amdgpu_dm_get_native_mode(connector);
 +      } else {
 +              amdgpu_dm_connector->num_modes = 0;
 +      }
 +}
 +
 +static int amdgpu_dm_connector_get_modes(struct drm_connector *connector)
 +{
 +      const struct drm_connector_helper_funcs *helper =
 +                      connector->helper_private;
 +      struct amdgpu_dm_connector *amdgpu_dm_connector =
 +                      to_amdgpu_dm_connector(connector);
 +      struct drm_encoder *encoder;
 +      struct edid *edid = amdgpu_dm_connector->edid;
 +
 +      encoder = helper->best_encoder(connector);
 +
 +      amdgpu_dm_connector_ddc_get_modes(connector, edid);
 +      amdgpu_dm_connector_add_common_modes(encoder, connector);
 +      return amdgpu_dm_connector->num_modes;
 +}
 +
 +void amdgpu_dm_connector_init_helper(struct amdgpu_display_manager *dm,
 +                                   struct amdgpu_dm_connector *aconnector,
 +                                   int connector_type,
 +                                   struct dc_link *link,
 +                                   int link_index)
 +{
 +      struct amdgpu_device *adev = dm->ddev->dev_private;
 +
 +      aconnector->connector_id = link_index;
 +      aconnector->dc_link = link;
 +      aconnector->base.interlace_allowed = false;
 +      aconnector->base.doublescan_allowed = false;
 +      aconnector->base.stereo_allowed = false;
 +      aconnector->base.dpms = DRM_MODE_DPMS_OFF;
 +      aconnector->hpd.hpd = AMDGPU_HPD_NONE; /* not used */
 +
 +      mutex_init(&aconnector->hpd_lock);
 +
 +      /* configure support HPD hot plug connector_>polled default value is 0
 +       * which means HPD hot plug not supported
 +       */
 +      switch (connector_type) {
 +      case DRM_MODE_CONNECTOR_HDMIA:
 +              aconnector->base.polled = DRM_CONNECTOR_POLL_HPD;
 +              break;
 +      case DRM_MODE_CONNECTOR_DisplayPort:
 +              aconnector->base.polled = DRM_CONNECTOR_POLL_HPD;
 +              break;
 +      case DRM_MODE_CONNECTOR_DVID:
 +              aconnector->base.polled = DRM_CONNECTOR_POLL_HPD;
 +              break;
 +      default:
 +              break;
 +      }
 +
 +      drm_object_attach_property(&aconnector->base.base,
 +                              dm->ddev->mode_config.scaling_mode_property,
 +                              DRM_MODE_SCALE_NONE);
 +
 +      drm_object_attach_property(&aconnector->base.base,
 +                              adev->mode_info.underscan_property,
 +                              UNDERSCAN_OFF);
 +      drm_object_attach_property(&aconnector->base.base,
 +                              adev->mode_info.underscan_hborder_property,
 +                              0);
 +      drm_object_attach_property(&aconnector->base.base,
 +                              adev->mode_info.underscan_vborder_property,
 +                              0);
 +
 +}
 +
 +static int amdgpu_dm_i2c_xfer(struct i2c_adapter *i2c_adap,
 +                            struct i2c_msg *msgs, int num)
 +{
 +      struct amdgpu_i2c_adapter *i2c = i2c_get_adapdata(i2c_adap);
 +      struct ddc_service *ddc_service = i2c->ddc_service;
 +      struct i2c_command cmd;
 +      int i;
 +      int result = -EIO;
 +
 +      cmd.payloads = kcalloc(num, sizeof(struct i2c_payload), GFP_KERNEL);
 +
 +      if (!cmd.payloads)
 +              return result;
 +
 +      cmd.number_of_payloads = num;
 +      cmd.engine = I2C_COMMAND_ENGINE_DEFAULT;
 +      cmd.speed = 100;
 +
 +      for (i = 0; i < num; i++) {
 +              cmd.payloads[i].write = !(msgs[i].flags & I2C_M_RD);
 +              cmd.payloads[i].address = msgs[i].addr;
 +              cmd.payloads[i].length = msgs[i].len;
 +              cmd.payloads[i].data = msgs[i].buf;
 +      }
 +
 +      if (dal_i2caux_submit_i2c_command(
 +                      ddc_service->ctx->i2caux,
 +                      ddc_service->ddc_pin,
 +                      &cmd))
 +              result = num;
 +
 +      kfree(cmd.payloads);
 +      return result;
 +}
 +
 +static u32 amdgpu_dm_i2c_func(struct i2c_adapter *adap)
 +{
 +      return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
 +}
 +
 +static const struct i2c_algorithm amdgpu_dm_i2c_algo = {
 +      .master_xfer = amdgpu_dm_i2c_xfer,
 +      .functionality = amdgpu_dm_i2c_func,
 +};
 +
 +static struct amdgpu_i2c_adapter *
 +create_i2c(struct ddc_service *ddc_service,
 +         int link_index,
 +         int *res)
 +{
 +      struct amdgpu_device *adev = ddc_service->ctx->driver_context;
 +      struct amdgpu_i2c_adapter *i2c;
 +
 +      i2c = kzalloc(sizeof(struct amdgpu_i2c_adapter), GFP_KERNEL);
 +      if (!i2c)
 +              return NULL;
 +      i2c->base.owner = THIS_MODULE;
 +      i2c->base.class = I2C_CLASS_DDC;
 +      i2c->base.dev.parent = &adev->pdev->dev;
 +      i2c->base.algo = &amdgpu_dm_i2c_algo;
 +      snprintf(i2c->base.name, sizeof(i2c->base.name), "AMDGPU DM i2c hw bus %d", link_index);
 +      i2c_set_adapdata(&i2c->base, i2c);
 +      i2c->ddc_service = ddc_service;
 +
 +      return i2c;
 +}
 +
 +/* Note: this function assumes that dc_link_detect() was called for the
 + * dc_link which will be represented by this aconnector.
 + */
 +static int amdgpu_dm_connector_init(struct amdgpu_display_manager *dm,
 +                                  struct amdgpu_dm_connector *aconnector,
 +                                  uint32_t link_index,
 +                                  struct amdgpu_encoder *aencoder)
 +{
 +      int res = 0;
 +      int connector_type;
 +      struct dc *dc = dm->dc;
 +      struct dc_link *link = dc_get_link_at_index(dc, link_index);
 +      struct amdgpu_i2c_adapter *i2c;
 +
 +      link->priv = aconnector;
 +
 +      DRM_DEBUG_DRIVER("%s()\n", __func__);
 +
 +      i2c = create_i2c(link->ddc, link->link_index, &res);
 +      if (!i2c) {
 +              DRM_ERROR("Failed to create i2c adapter data\n");
 +              return -ENOMEM;
 +      }
 +
 +      aconnector->i2c = i2c;
 +      res = i2c_add_adapter(&i2c->base);
 +
 +      if (res) {
 +              DRM_ERROR("Failed to register hw i2c %d\n", link->link_index);
 +              goto out_free;
 +      }
 +
 +      connector_type = to_drm_connector_type(link->connector_signal);
 +
 +      res = drm_connector_init(
 +                      dm->ddev,
 +                      &aconnector->base,
 +                      &amdgpu_dm_connector_funcs,
 +                      connector_type);
 +
 +      if (res) {
 +              DRM_ERROR("connector_init failed\n");
 +              aconnector->connector_id = -1;
 +              goto out_free;
 +      }
 +
 +      drm_connector_helper_add(
 +                      &aconnector->base,
 +                      &amdgpu_dm_connector_helper_funcs);
 +
 +      if (aconnector->base.funcs->reset)
 +              aconnector->base.funcs->reset(&aconnector->base);
 +
 +      amdgpu_dm_connector_init_helper(
 +              dm,
 +              aconnector,
 +              connector_type,
 +              link,
 +              link_index);
 +
 +      drm_mode_connector_attach_encoder(
 +              &aconnector->base, &aencoder->base);
 +
 +      drm_connector_register(&aconnector->base);
 +
 +      if (connector_type == DRM_MODE_CONNECTOR_DisplayPort
 +              || connector_type == DRM_MODE_CONNECTOR_eDP)
 +              amdgpu_dm_initialize_dp_connector(dm, aconnector);
 +
 +#if defined(CONFIG_BACKLIGHT_CLASS_DEVICE) ||\
 +      defined(CONFIG_BACKLIGHT_CLASS_DEVICE_MODULE)
 +
 +      /* NOTE: this currently will create backlight device even if a panel
 +       * is not connected to the eDP/LVDS connector.
 +       *
 +       * This is less than ideal but we don't have sink information at this
 +       * stage since detection happens after. We can't do detection earlier
 +       * since MST detection needs connectors to be created first.
 +       */
 +      if (link->connector_signal & (SIGNAL_TYPE_EDP | SIGNAL_TYPE_LVDS)) {
 +              /* Event if registration failed, we should continue with
 +               * DM initialization because not having a backlight control
 +               * is better then a black screen.
 +               */
 +              amdgpu_dm_register_backlight_device(dm);
 +
 +              if (dm->backlight_dev)
 +                      dm->backlight_link = link;
 +      }
 +#endif
 +
 +out_free:
 +      if (res) {
 +              kfree(i2c);
 +              aconnector->i2c = NULL;
 +      }
 +      return res;
 +}
 +
 +int amdgpu_dm_get_encoder_crtc_mask(struct amdgpu_device *adev)
 +{
 +      switch (adev->mode_info.num_crtc) {
 +      case 1:
 +              return 0x1;
 +      case 2:
 +              return 0x3;
 +      case 3:
 +              return 0x7;
 +      case 4:
 +              return 0xf;
 +      case 5:
 +              return 0x1f;
 +      case 6:
 +      default:
 +              return 0x3f;
 +      }
 +}
 +
 +static int amdgpu_dm_encoder_init(struct drm_device *dev,
 +                                struct amdgpu_encoder *aencoder,
 +                                uint32_t link_index)
 +{
 +      struct amdgpu_device *adev = dev->dev_private;
 +
 +      int res = drm_encoder_init(dev,
 +                                 &aencoder->base,
 +                                 &amdgpu_dm_encoder_funcs,
 +                                 DRM_MODE_ENCODER_TMDS,
 +                                 NULL);
 +
 +      aencoder->base.possible_crtcs = amdgpu_dm_get_encoder_crtc_mask(adev);
 +
 +      if (!res)
 +              aencoder->encoder_id = link_index;
 +      else
 +              aencoder->encoder_id = -1;
 +
 +      drm_encoder_helper_add(&aencoder->base, &amdgpu_dm_encoder_helper_funcs);
 +
 +      return res;
 +}
 +
 +static void manage_dm_interrupts(struct amdgpu_device *adev,
 +                               struct amdgpu_crtc *acrtc,
 +                               bool enable)
 +{
 +      /*
 +       * this is not correct translation but will work as soon as VBLANK
 +       * constant is the same as PFLIP
 +       */
 +      int irq_type =
 +              amdgpu_crtc_idx_to_irq_type(
 +                      adev,
 +                      acrtc->crtc_id);
 +
 +      if (enable) {
 +              drm_crtc_vblank_on(&acrtc->base);
 +              amdgpu_irq_get(
 +                      adev,
 +                      &adev->pageflip_irq,
 +                      irq_type);
 +      } else {
 +
 +              amdgpu_irq_put(
 +                      adev,
 +                      &adev->pageflip_irq,
 +                      irq_type);
 +              drm_crtc_vblank_off(&acrtc->base);
 +      }
 +}
 +
 +static bool
 +is_scaling_state_different(const struct dm_connector_state *dm_state,
 +                         const struct dm_connector_state *old_dm_state)
 +{
 +      if (dm_state->scaling != old_dm_state->scaling)
 +              return true;
 +      if (!dm_state->underscan_enable && old_dm_state->underscan_enable) {
 +              if (old_dm_state->underscan_hborder != 0 && old_dm_state->underscan_vborder != 0)
 +                      return true;
 +      } else  if (dm_state->underscan_enable && !old_dm_state->underscan_enable) {
 +              if (dm_state->underscan_hborder != 0 && dm_state->underscan_vborder != 0)
 +                      return true;
 +      } else if (dm_state->underscan_hborder != old_dm_state->underscan_hborder ||
 +                 dm_state->underscan_vborder != old_dm_state->underscan_vborder)
 +              return true;
 +      return false;
 +}
 +
 +static void remove_stream(struct amdgpu_device *adev,
 +                        struct amdgpu_crtc *acrtc,
 +                        struct dc_stream_state *stream)
 +{
 +      /* this is the update mode case */
 +      if (adev->dm.freesync_module)
 +              mod_freesync_remove_stream(adev->dm.freesync_module, stream);
 +
 +      acrtc->otg_inst = -1;
 +      acrtc->enabled = false;
 +}
 +
 +static int get_cursor_position(struct drm_plane *plane, struct drm_crtc *crtc,
 +                             struct dc_cursor_position *position)
 +{
 +      struct amdgpu_crtc *amdgpu_crtc = amdgpu_crtc = to_amdgpu_crtc(crtc);
 +      int x, y;
 +      int xorigin = 0, yorigin = 0;
 +
 +      if (!crtc || !plane->state->fb) {
 +              position->enable = false;
 +              position->x = 0;
 +              position->y = 0;
 +              return 0;
 +      }
 +
 +      if ((plane->state->crtc_w > amdgpu_crtc->max_cursor_width) ||
 +          (plane->state->crtc_h > amdgpu_crtc->max_cursor_height)) {
 +              DRM_ERROR("%s: bad cursor width or height %d x %d\n",
 +                        __func__,
 +                        plane->state->crtc_w,
 +                        plane->state->crtc_h);
 +              return -EINVAL;
 +      }
 +
 +      x = plane->state->crtc_x;
 +      y = plane->state->crtc_y;
 +      /* avivo cursor are offset into the total surface */
 +      x += crtc->primary->state->src_x >> 16;
 +      y += crtc->primary->state->src_y >> 16;
 +      if (x < 0) {
 +              xorigin = min(-x, amdgpu_crtc->max_cursor_width - 1);
 +              x = 0;
 +      }
 +      if (y < 0) {
 +              yorigin = min(-y, amdgpu_crtc->max_cursor_height - 1);
 +              y = 0;
 +      }
 +      position->enable = true;
 +      position->x = x;
 +      position->y = y;
 +      position->x_hotspot = xorigin;
 +      position->y_hotspot = yorigin;
 +
 +      return 0;
 +}
 +
 +static void handle_cursor_update(struct drm_plane *plane,
 +                               struct drm_plane_state *old_plane_state)
 +{
 +      struct amdgpu_framebuffer *afb = to_amdgpu_framebuffer(plane->state->fb);
 +      struct drm_crtc *crtc = afb ? plane->state->crtc : old_plane_state->crtc;
 +      struct dm_crtc_state *crtc_state = crtc ? to_dm_crtc_state(crtc->state) : NULL;
 +      struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
 +      uint64_t address = afb ? afb->address : 0;
 +      struct dc_cursor_position position;
 +      struct dc_cursor_attributes attributes;
 +      int ret;
 +
 +      if (!plane->state->fb && !old_plane_state->fb)
 +              return;
 +
 +      DRM_DEBUG_DRIVER("%s: crtc_id=%d with size %d to %d\n",
 +                       __func__,
 +                       amdgpu_crtc->crtc_id,
 +                       plane->state->crtc_w,
 +                       plane->state->crtc_h);
 +
 +      ret = get_cursor_position(plane, crtc, &position);
 +      if (ret)
 +              return;
 +
 +      if (!position.enable) {
 +              /* turn off cursor */
 +              if (crtc_state && crtc_state->stream)
 +                      dc_stream_set_cursor_position(crtc_state->stream,
 +                                                    &position);
 +              return;
 +      }
 +
 +      amdgpu_crtc->cursor_width = plane->state->crtc_w;
 +      amdgpu_crtc->cursor_height = plane->state->crtc_h;
 +
 +      attributes.address.high_part = upper_32_bits(address);
 +      attributes.address.low_part  = lower_32_bits(address);
 +      attributes.width             = plane->state->crtc_w;
 +      attributes.height            = plane->state->crtc_h;
 +      attributes.color_format      = CURSOR_MODE_COLOR_PRE_MULTIPLIED_ALPHA;
 +      attributes.rotation_angle    = 0;
 +      attributes.attribute_flags.value = 0;
 +
 +      attributes.pitch = attributes.width;
 +
 +      if (crtc_state->stream) {
 +              if (!dc_stream_set_cursor_attributes(crtc_state->stream,
 +                                                       &attributes))
 +                      DRM_ERROR("DC failed to set cursor attributes\n");
 +
 +              if (!dc_stream_set_cursor_position(crtc_state->stream,
 +                                                 &position))
 +                      DRM_ERROR("DC failed to set cursor position\n");
 +      }
 +}
 +
 +static void prepare_flip_isr(struct amdgpu_crtc *acrtc)
 +{
 +
 +      assert_spin_locked(&acrtc->base.dev->event_lock);
 +      WARN_ON(acrtc->event);
 +
 +      acrtc->event = acrtc->base.state->event;
 +
 +      /* Set the flip status */
 +      acrtc->pflip_status = AMDGPU_FLIP_SUBMITTED;
 +
 +      /* Mark this event as consumed */
 +      acrtc->base.state->event = NULL;
 +
 +      DRM_DEBUG_DRIVER("crtc:%d, pflip_stat:AMDGPU_FLIP_SUBMITTED\n",
 +                                               acrtc->crtc_id);
 +}
 +
 +/*
 + * Executes flip
 + *
 + * Waits on all BO's fences and for proper vblank count
 + */
 +static void amdgpu_dm_do_flip(struct drm_crtc *crtc,
 +                            struct drm_framebuffer *fb,
 +                            uint32_t target,
 +                            struct dc_state *state)
 +{
 +      unsigned long flags;
 +      uint32_t target_vblank;
 +      int r, vpos, hpos;
 +      struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
 +      struct amdgpu_framebuffer *afb = to_amdgpu_framebuffer(fb);
 +      struct amdgpu_bo *abo = gem_to_amdgpu_bo(afb->obj);
 +      struct amdgpu_device *adev = crtc->dev->dev_private;
 +      bool async_flip = (crtc->state->pageflip_flags & DRM_MODE_PAGE_FLIP_ASYNC) != 0;
 +      struct dc_flip_addrs addr = { {0} };
 +      /* TODO eliminate or rename surface_update */
 +      struct dc_surface_update surface_updates[1] = { {0} };
 +      struct dm_crtc_state *acrtc_state = to_dm_crtc_state(crtc->state);
 +
 +
 +      /* Prepare wait for target vblank early - before the fence-waits */
 +      target_vblank = target - drm_crtc_vblank_count(crtc) +
 +                      amdgpu_get_vblank_counter_kms(crtc->dev, acrtc->crtc_id);
 +
 +      /* TODO This might fail and hence better not used, wait
 +       * explicitly on fences instead
 +       * and in general should be called for
 +       * blocking commit to as per framework helpers
 +       */
 +      r = amdgpu_bo_reserve(abo, true);
 +      if (unlikely(r != 0)) {
 +              DRM_ERROR("failed to reserve buffer before flip\n");
 +              WARN_ON(1);
 +      }
 +
 +      /* Wait for all fences on this FB */
 +      WARN_ON(reservation_object_wait_timeout_rcu(abo->tbo.resv, true, false,
 +                                                                  MAX_SCHEDULE_TIMEOUT) < 0);
 +
 +      amdgpu_bo_unreserve(abo);
 +
 +      /* Wait until we're out of the vertical blank period before the one
 +       * targeted by the flip
 +       */
 +      while ((acrtc->enabled &&
 +              (amdgpu_get_crtc_scanoutpos(adev->ddev, acrtc->crtc_id, 0,
 +                                      &vpos, &hpos, NULL, NULL,
 +                                      &crtc->hwmode)
 +               & (DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_IN_VBLANK)) ==
 +              (DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_IN_VBLANK) &&
 +              (int)(target_vblank -
 +                amdgpu_get_vblank_counter_kms(adev->ddev, acrtc->crtc_id)) > 0)) {
 +              usleep_range(1000, 1100);
 +      }
 +
 +      /* Flip */
 +      spin_lock_irqsave(&crtc->dev->event_lock, flags);
 +      /* update crtc fb */
 +      crtc->primary->fb = fb;
 +
 +      WARN_ON(acrtc->pflip_status != AMDGPU_FLIP_NONE);
 +      WARN_ON(!acrtc_state->stream);
 +
 +      addr.address.grph.addr.low_part = lower_32_bits(afb->address);
 +      addr.address.grph.addr.high_part = upper_32_bits(afb->address);
 +      addr.flip_immediate = async_flip;
 +
 +
 +      if (acrtc->base.state->event)
 +              prepare_flip_isr(acrtc);
 +
 +      surface_updates->surface = dc_stream_get_status(acrtc_state->stream)->plane_states[0];
 +      surface_updates->flip_addr = &addr;
 +
 +
 +      dc_commit_updates_for_stream(adev->dm.dc,
 +                                           surface_updates,
 +                                           1,
 +                                           acrtc_state->stream,
 +                                           NULL,
 +                                           &surface_updates->surface,
 +                                           state);
 +
 +      DRM_DEBUG_DRIVER("%s Flipping to hi: 0x%x, low: 0x%x \n",
 +                       __func__,
 +                       addr.address.grph.addr.high_part,
 +                       addr.address.grph.addr.low_part);
 +
 +
 +      spin_unlock_irqrestore(&crtc->dev->event_lock, flags);
 +}
 +
 +static void amdgpu_dm_commit_planes(struct drm_atomic_state *state,
 +                                  struct drm_device *dev,
 +                                  struct amdgpu_display_manager *dm,
 +                                  struct drm_crtc *pcrtc,
 +                                  bool *wait_for_vblank)
 +{
 +      uint32_t i;
 +      struct drm_plane *plane;
 +      struct drm_plane_state *old_plane_state, *new_plane_state;
 +      struct dc_stream_state *dc_stream_attach;
 +      struct dc_plane_state *plane_states_constructed[MAX_SURFACES];
 +      struct amdgpu_crtc *acrtc_attach = to_amdgpu_crtc(pcrtc);
 +      struct drm_crtc_state *new_pcrtc_state =
 +                      drm_atomic_get_new_crtc_state(state, pcrtc);
 +      struct dm_crtc_state *acrtc_state = to_dm_crtc_state(new_pcrtc_state);
 +      struct dm_atomic_state *dm_state = to_dm_atomic_state(state);
 +      int planes_count = 0;
 +      unsigned long flags;
 +
 +      /* update planes when needed */
 +      for_each_oldnew_plane_in_state(state, plane, old_plane_state, new_plane_state, i) {
 +              struct drm_crtc *crtc = new_plane_state->crtc;
 +              struct drm_crtc_state *new_crtc_state;
 +              struct drm_framebuffer *fb = new_plane_state->fb;
 +              bool pflip_needed;
 +              struct dm_plane_state *dm_new_plane_state = to_dm_plane_state(new_plane_state);
 +
 +              if (plane->type == DRM_PLANE_TYPE_CURSOR) {
 +                      handle_cursor_update(plane, old_plane_state);
 +                      continue;
 +              }
 +
 +              if (!fb || !crtc || pcrtc != crtc)
 +                      continue;
 +
 +              new_crtc_state = drm_atomic_get_new_crtc_state(state, crtc);
 +              if (!new_crtc_state->active)
 +                      continue;
 +
 +              pflip_needed = !state->allow_modeset;
 +
 +              spin_lock_irqsave(&crtc->dev->event_lock, flags);
 +              if (acrtc_attach->pflip_status != AMDGPU_FLIP_NONE) {
 +                      DRM_ERROR("%s: acrtc %d, already busy\n",
 +                                __func__,
 +                                acrtc_attach->crtc_id);
 +                      /* In commit tail framework this cannot happen */
 +                      WARN_ON(1);
 +              }
 +              spin_unlock_irqrestore(&crtc->dev->event_lock, flags);
 +
 +              if (!pflip_needed) {
 +                      WARN_ON(!dm_new_plane_state->dc_state);
 +
 +                      plane_states_constructed[planes_count] = dm_new_plane_state->dc_state;
 +
 +                      dc_stream_attach = acrtc_state->stream;
 +                      planes_count++;
 +
 +              } else if (new_crtc_state->planes_changed) {
 +                      /* Assume even ONE crtc with immediate flip means
 +                       * entire can't wait for VBLANK
 +                       * TODO Check if it's correct
 +                       */
 +                      *wait_for_vblank =
 +                                      new_pcrtc_state->pageflip_flags & DRM_MODE_PAGE_FLIP_ASYNC ?
 +                              false : true;
 +
 +                      /* TODO: Needs rework for multiplane flip */
 +                      if (plane->type == DRM_PLANE_TYPE_PRIMARY)
 +                              drm_crtc_vblank_get(crtc);
 +
 +                      amdgpu_dm_do_flip(
 +                              crtc,
 +                              fb,
 +                              drm_crtc_vblank_count(crtc) + *wait_for_vblank,
 +                              dm_state->context);
 +              }
 +
 +      }
 +
 +      if (planes_count) {
 +              unsigned long flags;
 +
 +              if (new_pcrtc_state->event) {
 +
 +                      drm_crtc_vblank_get(pcrtc);
 +
 +                      spin_lock_irqsave(&pcrtc->dev->event_lock, flags);
 +                      prepare_flip_isr(acrtc_attach);
 +                      spin_unlock_irqrestore(&pcrtc->dev->event_lock, flags);
 +              }
 +
 +              if (false == dc_commit_planes_to_stream(dm->dc,
 +                                                      plane_states_constructed,
 +                                                      planes_count,
 +                                                      dc_stream_attach,
 +                                                      dm_state->context))
 +                      dm_error("%s: Failed to attach plane!\n", __func__);
 +      } else {
 +              /*TODO BUG Here should go disable planes on CRTC. */
 +      }
 +}
 +
 +
 +static int amdgpu_dm_atomic_commit(struct drm_device *dev,
 +                                 struct drm_atomic_state *state,
 +                                 bool nonblock)
 +{
 +      struct drm_crtc *crtc;
 +      struct drm_crtc_state *old_crtc_state, *new_crtc_state;
 +      struct amdgpu_device *adev = dev->dev_private;
 +      int i;
 +
 +      /*
 +       * We evade vblanks and pflips on crtc that
 +       * should be changed. We do it here to flush & disable
 +       * interrupts before drm_swap_state is called in drm_atomic_helper_commit
 +       * it will update crtc->dm_crtc_state->stream pointer which is used in
 +       * the ISRs.
 +       */
 +      for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
 +              struct dm_crtc_state *dm_old_crtc_state = to_dm_crtc_state(old_crtc_state);
 +              struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
 +
 +              if (drm_atomic_crtc_needs_modeset(new_crtc_state) && dm_old_crtc_state->stream)
 +                      manage_dm_interrupts(adev, acrtc, false);
 +      }
 +      /* Add check here for SoC's that support hardware cursor plane, to
 +       * unset legacy_cursor_update */
 +
 +      return drm_atomic_helper_commit(dev, state, nonblock);
 +
 +      /*TODO Handle EINTR, reenable IRQ*/
 +}
 +
 +static void amdgpu_dm_atomic_commit_tail(struct drm_atomic_state *state)
 +{
 +      struct drm_device *dev = state->dev;
 +      struct amdgpu_device *adev = dev->dev_private;
 +      struct amdgpu_display_manager *dm = &adev->dm;
 +      struct dm_atomic_state *dm_state;
 +      uint32_t i, j;
 +      uint32_t new_crtcs_count = 0;
 +      struct drm_crtc *crtc;
 +      struct drm_crtc_state *old_crtc_state, *new_crtc_state;
 +      struct amdgpu_crtc *new_crtcs[MAX_STREAMS];
 +      struct dc_stream_state *new_stream = NULL;
 +      unsigned long flags;
 +      bool wait_for_vblank = true;
 +      struct drm_connector *connector;
 +      struct drm_connector_state *old_con_state, *new_con_state;
 +      struct dm_crtc_state *dm_old_crtc_state, *dm_new_crtc_state;
 +
 +      drm_atomic_helper_update_legacy_modeset_state(dev, state);
 +
 +      dm_state = to_dm_atomic_state(state);
 +
 +      /* update changed items */
 +      for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
 +              struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
 +
 +              dm_new_crtc_state = to_dm_crtc_state(new_crtc_state);
 +              dm_old_crtc_state = to_dm_crtc_state(old_crtc_state);
 +
 +              DRM_DEBUG_DRIVER(
 +                      "amdgpu_crtc id:%d crtc_state_flags: enable:%d, active:%d, "
 +                      "planes_changed:%d, mode_changed:%d,active_changed:%d,"
 +                      "connectors_changed:%d\n",
 +                      acrtc->crtc_id,
 +                      new_crtc_state->enable,
 +                      new_crtc_state->active,
 +                      new_crtc_state->planes_changed,
 +                      new_crtc_state->mode_changed,
 +                      new_crtc_state->active_changed,
 +                      new_crtc_state->connectors_changed);
 +
 +              /* handles headless hotplug case, updating new_state and
 +               * aconnector as needed
 +               */
 +
 +              if (modeset_required(new_crtc_state, dm_new_crtc_state->stream, dm_old_crtc_state->stream)) {
 +
 +                      DRM_DEBUG_DRIVER("Atomic commit: SET crtc id %d: [%p]\n", acrtc->crtc_id, acrtc);
 +
 +                      if (!dm_new_crtc_state->stream) {
 +                              /*
 +                               * this could happen because of issues with
 +                               * userspace notifications delivery.
 +                               * In this case userspace tries to set mode on
 +                               * display which is disconnect in fact.
 +                               * dc_sink in NULL in this case on aconnector.
 +                               * We expect reset mode will come soon.
 +                               *
 +                               * This can also happen when unplug is done
 +                               * during resume sequence ended
 +                               *
 +                               * In this case, we want to pretend we still
 +                               * have a sink to keep the pipe running so that
 +                               * hw state is consistent with the sw state
 +                               */
 +                              DRM_DEBUG_DRIVER("%s: Failed to create new stream for crtc %d\n",
 +                                              __func__, acrtc->base.base.id);
 +                              continue;
 +                      }
 +
 +
 +                      if (dm_old_crtc_state->stream)
 +                              remove_stream(adev, acrtc, dm_old_crtc_state->stream);
 +
 +
 +                      /*
 +                       * this loop saves set mode crtcs
 +                       * we needed to enable vblanks once all
 +                       * resources acquired in dc after dc_commit_streams
 +                       */
 +
 +                      /*TODO move all this into dm_crtc_state, get rid of
 +                       * new_crtcs array and use old and new atomic states
 +                       * instead
 +                       */
 +                      new_crtcs[new_crtcs_count] = acrtc;
 +                      new_crtcs_count++;
 +
 +                      new_crtc_state = drm_atomic_get_new_crtc_state(state, crtc);
 +                      acrtc->enabled = true;
 +                      acrtc->hw_mode = new_crtc_state->mode;
 +                      crtc->hwmode = new_crtc_state->mode;
 +              } else if (modereset_required(new_crtc_state)) {
 +                      DRM_DEBUG_DRIVER("Atomic commit: RESET. crtc id %d:[%p]\n", acrtc->crtc_id, acrtc);
 +
 +                      /* i.e. reset mode */
 +                      if (dm_old_crtc_state->stream)
 +                              remove_stream(adev, acrtc, dm_old_crtc_state->stream);
 +              }
 +      } /* for_each_crtc_in_state() */
 +
 +      /*
 +       * Add streams after required streams from new and replaced streams
 +       * are removed from freesync module
 +       */
 +      if (adev->dm.freesync_module) {
 +              for (i = 0; i < new_crtcs_count; i++) {
 +                      struct amdgpu_dm_connector *aconnector = NULL;
 +
 +                      new_crtc_state = drm_atomic_get_new_crtc_state(state,
 +                                      &new_crtcs[i]->base);
 +                      dm_new_crtc_state = to_dm_crtc_state(new_crtc_state);
 +
 +                      new_stream = dm_new_crtc_state->stream;
 +                      aconnector = amdgpu_dm_find_first_crtc_matching_connector(
 +                                      state,
 +                                      &new_crtcs[i]->base);
 +                      if (!aconnector) {
 +                              DRM_DEBUG_DRIVER("Atomic commit: Failed to find connector for acrtc id:%d "
 +                                       "skipping freesync init\n",
 +                                       new_crtcs[i]->crtc_id);
 +                              continue;
 +                      }
 +
 +                      mod_freesync_add_stream(adev->dm.freesync_module,
 +                                              new_stream, &aconnector->caps);
 +              }
 +      }
 +
 +      if (dm_state->context)
 +              WARN_ON(!dc_commit_state(dm->dc, dm_state->context));
 +
 +      for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) {
 +              struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
 +
 +              dm_new_crtc_state = to_dm_crtc_state(new_crtc_state);
 +
 +              if (dm_new_crtc_state->stream != NULL) {
 +                      const struct dc_stream_status *status =
 +                                      dc_stream_get_status(dm_new_crtc_state->stream);
 +
 +                      if (!status)
 +                              DC_ERR("got no status for stream %p on acrtc%p\n", dm_new_crtc_state->stream, acrtc);
 +                      else
 +                              acrtc->otg_inst = status->primary_otg_inst;
 +              }
 +      }
 +
 +      /* Handle scaling and underscan changes*/
 +      for_each_oldnew_connector_in_state(state, connector, old_con_state, new_con_state, i) {
 +              struct dm_connector_state *dm_new_con_state = to_dm_connector_state(new_con_state);
 +              struct dm_connector_state *dm_old_con_state = to_dm_connector_state(old_con_state);
 +              struct amdgpu_crtc *acrtc = to_amdgpu_crtc(dm_new_con_state->base.crtc);
 +              struct dc_stream_status *status = NULL;
 +
 +              if (acrtc)
 +                      new_crtc_state = drm_atomic_get_new_crtc_state(state, &acrtc->base);
 +
 +              /* Skip any modesets/resets */
 +              if (!acrtc || drm_atomic_crtc_needs_modeset(new_crtc_state))
 +                      continue;
 +
 +              /* Skip any thing not scale or underscan changes */
 +              if (!is_scaling_state_different(dm_new_con_state, dm_old_con_state))
 +                      continue;
 +
 +              dm_new_crtc_state = to_dm_crtc_state(new_crtc_state);
 +
 +              update_stream_scaling_settings(&dm_new_con_state->base.crtc->mode,
 +                              dm_new_con_state, (struct dc_stream_state *)dm_new_crtc_state->stream);
 +
 +              if (!dm_new_crtc_state->stream)
 +                      continue;
 +
 +              status = dc_stream_get_status(dm_new_crtc_state->stream);
 +              WARN_ON(!status);
 +              WARN_ON(!status->plane_count);
 +
 +              /*TODO How it works with MPO ?*/
 +              if (!dc_commit_planes_to_stream(
 +                              dm->dc,
 +                              status->plane_states,
 +                              status->plane_count,
 +                              dm_new_crtc_state->stream,
 +                              dm_state->context))
 +                      dm_error("%s: Failed to update stream scaling!\n", __func__);
 +      }
 +
 +      for (i = 0; i < new_crtcs_count; i++) {
 +              /*
 +               * loop to enable interrupts on newly arrived crtc
 +               */
 +              struct amdgpu_crtc *acrtc = new_crtcs[i];
 +
 +              new_crtc_state = drm_atomic_get_new_crtc_state(state, &acrtc->base);
 +              dm_new_crtc_state = to_dm_crtc_state(new_crtc_state);
 +
 +              if (adev->dm.freesync_module)
 +                      mod_freesync_notify_mode_change(
 +                              adev->dm.freesync_module, &dm_new_crtc_state->stream, 1);
 +
 +              manage_dm_interrupts(adev, acrtc, true);
 +      }
 +
 +      /* update planes when needed per crtc*/
 +      for_each_new_crtc_in_state(state, crtc, new_crtc_state, j) {
 +              dm_new_crtc_state = to_dm_crtc_state(new_crtc_state);
 +
 +              if (dm_new_crtc_state->stream)
 +                      amdgpu_dm_commit_planes(state, dev, dm, crtc, &wait_for_vblank);
 +      }
 +
 +
 +      /*
 +       * send vblank event on all events not handled in flip and
 +       * mark consumed event for drm_atomic_helper_commit_hw_done
 +       */
 +      spin_lock_irqsave(&adev->ddev->event_lock, flags);
 +      for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) {
 +
 +              if (new_crtc_state->event)
 +                      drm_send_event_locked(dev, &new_crtc_state->event->base);
 +
 +              new_crtc_state->event = NULL;
 +      }
 +      spin_unlock_irqrestore(&adev->ddev->event_lock, flags);
 +
 +      /* Signal HW programming completion */
 +      drm_atomic_helper_commit_hw_done(state);
 +
 +      if (wait_for_vblank)
 +              drm_atomic_helper_wait_for_flip_done(dev, state);
 +
 +      drm_atomic_helper_cleanup_planes(dev, state);
 +}
 +
 +
 +static int dm_force_atomic_commit(struct drm_connector *connector)
 +{
 +      int ret = 0;
 +      struct drm_device *ddev = connector->dev;
 +      struct drm_atomic_state *state = drm_atomic_state_alloc(ddev);
 +      struct amdgpu_crtc *disconnected_acrtc = to_amdgpu_crtc(connector->encoder->crtc);
 +      struct drm_plane *plane = disconnected_acrtc->base.primary;
 +      struct drm_connector_state *conn_state;
 +      struct drm_crtc_state *crtc_state;
 +      struct drm_plane_state *plane_state;
 +
 +      if (!state)
 +              return -ENOMEM;
 +
 +      state->acquire_ctx = ddev->mode_config.acquire_ctx;
 +
 +      /* Construct an atomic state to restore previous display setting */
 +
 +      /*
 +       * Attach connectors to drm_atomic_state
 +       */
 +      conn_state = drm_atomic_get_connector_state(state, connector);
 +
 +      ret = PTR_ERR_OR_ZERO(conn_state);
 +      if (ret)
 +              goto err;
 +
 +      /* Attach crtc to drm_atomic_state*/
 +      crtc_state = drm_atomic_get_crtc_state(state, &disconnected_acrtc->base);
 +
 +      ret = PTR_ERR_OR_ZERO(crtc_state);
 +      if (ret)
 +              goto err;
 +
 +      /* force a restore */
 +      crtc_state->mode_changed = true;
 +
 +      /* Attach plane to drm_atomic_state */
 +      plane_state = drm_atomic_get_plane_state(state, plane);
 +
 +      ret = PTR_ERR_OR_ZERO(plane_state);
 +      if (ret)
 +              goto err;
 +
 +
 +      /* Call commit internally with the state we just constructed */
 +      ret = drm_atomic_commit(state);
 +      if (!ret)
 +              return 0;
 +
 +err:
 +      DRM_ERROR("Restoring old state failed with %i\n", ret);
 +      drm_atomic_state_put(state);
 +
 +      return ret;
 +}
 +
 +/*
 + * This functions handle all cases when set mode does not come upon hotplug.
 + * This include when the same display is unplugged then plugged back into the
 + * same port and when we are running without usermode desktop manager supprot
 + */
 +void dm_restore_drm_connector_state(struct drm_device *dev,
 +                                  struct drm_connector *connector)
 +{
 +      struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(connector);
 +      struct amdgpu_crtc *disconnected_acrtc;
 +      struct dm_crtc_state *acrtc_state;
 +
 +      if (!aconnector->dc_sink || !connector->state || !connector->encoder)
 +              return;
 +
 +      disconnected_acrtc = to_amdgpu_crtc(connector->encoder->crtc);
 +      if (!disconnected_acrtc)
 +              return;
 +
 +      acrtc_state = to_dm_crtc_state(disconnected_acrtc->base.state);
 +      if (!acrtc_state->stream)
 +              return;
 +
 +      /*
 +       * If the previous sink is not released and different from the current,
 +       * we deduce we are in a state where we can not rely on usermode call
 +       * to turn on the display, so we do it here
 +       */
 +      if (acrtc_state->stream->sink != aconnector->dc_sink)
 +              dm_force_atomic_commit(&aconnector->base);
 +}
 +
 +/*`
 + * Grabs all modesetting locks to serialize against any blocking commits,
 + * Waits for completion of all non blocking commits.
 + */
 +static int do_aquire_global_lock(struct drm_device *dev,
 +                               struct drm_atomic_state *state)
 +{
 +      struct drm_crtc *crtc;
 +      struct drm_crtc_commit *commit;
 +      long ret;
 +
 +      /* Adding all modeset locks to aquire_ctx will
 +       * ensure that when the framework release it the
 +       * extra locks we are locking here will get released to
 +       */
 +      ret = drm_modeset_lock_all_ctx(dev, state->acquire_ctx);
 +      if (ret)
 +              return ret;
 +
 +      list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
 +              spin_lock(&crtc->commit_lock);
 +              commit = list_first_entry_or_null(&crtc->commit_list,
 +                              struct drm_crtc_commit, commit_entry);
 +              if (commit)
 +                      drm_crtc_commit_get(commit);
 +              spin_unlock(&crtc->commit_lock);
 +
 +              if (!commit)
 +                      continue;
 +
 +              /* Make sure all pending HW programming completed and
 +               * page flips done
 +               */
 +              ret = wait_for_completion_interruptible_timeout(&commit->hw_done, 10*HZ);
 +
 +              if (ret > 0)
 +                      ret = wait_for_completion_interruptible_timeout(
 +                                      &commit->flip_done, 10*HZ);
 +
 +              if (ret == 0)
 +                      DRM_ERROR("[CRTC:%d:%s] hw_done or flip_done "
 +                                "timed out\n", crtc->base.id, crtc->name);
 +
 +              drm_crtc_commit_put(commit);
 +      }
 +
 +      return ret < 0 ? ret : 0;
 +}
 +
 +static int dm_update_crtcs_state(struct dc *dc,
 +                               struct drm_atomic_state *state,
 +                               bool enable,
 +                               bool *lock_and_validation_needed)
 +{
 +      struct drm_crtc *crtc;
 +      struct drm_crtc_state *old_crtc_state, *new_crtc_state;
 +      int i;
 +      struct dm_crtc_state *dm_old_crtc_state, *dm_new_crtc_state;
 +      struct dm_atomic_state *dm_state = to_dm_atomic_state(state);
 +      struct dc_stream_state *new_stream;
 +      int ret = 0;
 +
 +      /*TODO Move this code into dm_crtc_atomic_check once we get rid of dc_validation_set */
 +      /* update changed items */
 +      for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
 +              struct amdgpu_crtc *acrtc = NULL;
 +              struct amdgpu_dm_connector *aconnector = NULL;
 +              struct drm_connector_state *new_con_state = NULL;
 +              struct dm_connector_state *dm_conn_state = NULL;
 +
 +              new_stream = NULL;
 +
 +              dm_old_crtc_state = to_dm_crtc_state(old_crtc_state);
 +              dm_new_crtc_state = to_dm_crtc_state(new_crtc_state);
 +              acrtc = to_amdgpu_crtc(crtc);
 +
 +              aconnector = amdgpu_dm_find_first_crtc_matching_connector(state, crtc);
 +
 +              /* TODO This hack should go away */
 +              if (aconnector && enable) {
 +                      // Make sure fake sink is created in plug-in scenario
 +                      new_con_state = drm_atomic_get_connector_state(state,
 +                                                                  &aconnector->base);
 +
 +                      if (IS_ERR(new_con_state)) {
 +                              ret = PTR_ERR_OR_ZERO(new_con_state);
 +                              break;
 +                      }
 +
 +                      dm_conn_state = to_dm_connector_state(new_con_state);
 +
 +                      new_stream = create_stream_for_sink(aconnector,
 +                                                           &new_crtc_state->mode,
 +                                                          dm_conn_state);
 +
 +                      /*
 +                       * we can have no stream on ACTION_SET if a display
 +                       * was disconnected during S3, in this case it not and
 +                       * error, the OS will be updated after detection, and
 +                       * do the right thing on next atomic commit
 +                       */
 +
 +                      if (!new_stream) {
 +                              DRM_DEBUG_DRIVER("%s: Failed to create new stream for crtc %d\n",
 +                                              __func__, acrtc->base.base.id);
 +                              break;
 +                      }
 +              }
 +
 +              if (enable && dc_is_stream_unchanged(new_stream, dm_old_crtc_state->stream) &&
 +                              dc_is_stream_scaling_unchanged(new_stream, dm_old_crtc_state->stream)) {
 +
 +                      new_crtc_state->mode_changed = false;
 +
 +                      DRM_DEBUG_DRIVER("Mode change not required, setting mode_changed to %d",
 +                                       new_crtc_state->mode_changed);
 +              }
 +
 +
 +              if (!drm_atomic_crtc_needs_modeset(new_crtc_state))
 +                      goto next_crtc;
 +
 +              DRM_DEBUG_DRIVER(
 +                      "amdgpu_crtc id:%d crtc_state_flags: enable:%d, active:%d, "
 +                      "planes_changed:%d, mode_changed:%d,active_changed:%d,"
 +                      "connectors_changed:%d\n",
 +                      acrtc->crtc_id,
 +                      new_crtc_state->enable,
 +                      new_crtc_state->active,
 +                      new_crtc_state->planes_changed,
 +                      new_crtc_state->mode_changed,
 +                      new_crtc_state->active_changed,
 +                      new_crtc_state->connectors_changed);
 +
 +              /* Remove stream for any changed/disabled CRTC */
 +              if (!enable) {
 +
 +                      if (!dm_old_crtc_state->stream)
 +                              goto next_crtc;
 +
 +                      DRM_DEBUG_DRIVER("Disabling DRM crtc: %d\n",
 +                                      crtc->base.id);
 +
 +                      /* i.e. reset mode */
 +                      if (dc_remove_stream_from_ctx(
 +                                      dc,
 +                                      dm_state->context,
 +                                      dm_old_crtc_state->stream) != DC_OK) {
 +                              ret = -EINVAL;
 +                              goto fail;
 +                      }
 +
 +                      dc_stream_release(dm_old_crtc_state->stream);
 +                      dm_new_crtc_state->stream = NULL;
 +
 +                      *lock_and_validation_needed = true;
 +
 +              } else {/* Add stream for any updated/enabled CRTC */
 +                      /*
 +                       * Quick fix to prevent NULL pointer on new_stream when
 +                       * added MST connectors not found in existing crtc_state in the chained mode
 +                       * TODO: need to dig out the root cause of that
 +                       */
 +                      if (!aconnector || (!aconnector->dc_sink && aconnector->mst_port))
 +                              goto next_crtc;
 +
 +                      if (modereset_required(new_crtc_state))
 +                              goto next_crtc;
 +
 +                      if (modeset_required(new_crtc_state, new_stream,
 +                                           dm_old_crtc_state->stream)) {
 +
 +                              WARN_ON(dm_new_crtc_state->stream);
 +
 +                              dm_new_crtc_state->stream = new_stream;
 +                              dc_stream_retain(new_stream);
 +
 +                              DRM_DEBUG_DRIVER("Enabling DRM crtc: %d\n",
 +                                                      crtc->base.id);
 +
 +                              if (dc_add_stream_to_ctx(
 +                                              dc,
 +                                              dm_state->context,
 +                                              dm_new_crtc_state->stream) != DC_OK) {
 +                                      ret = -EINVAL;
 +                                      goto fail;
 +                              }
 +
 +                              *lock_and_validation_needed = true;
 +                      }
 +              }
 +
 +next_crtc:
 +              /* Release extra reference */
 +              if (new_stream)
 +                       dc_stream_release(new_stream);
 +      }
 +
 +      return ret;
 +
 +fail:
 +      if (new_stream)
 +              dc_stream_release(new_stream);
 +      return ret;
 +}
 +
 +static int dm_update_planes_state(struct dc *dc,
 +                                struct drm_atomic_state *state,
 +                                bool enable,
 +                                bool *lock_and_validation_needed)
 +{
 +      struct drm_crtc *new_plane_crtc, *old_plane_crtc;
 +      struct drm_crtc_state *old_crtc_state, *new_crtc_state;
 +      struct drm_plane *plane;
 +      struct drm_plane_state *old_plane_state, *new_plane_state;
 +      struct dm_crtc_state *dm_new_crtc_state, *dm_old_crtc_state;
 +      struct dm_atomic_state *dm_state = to_dm_atomic_state(state);
 +      struct dm_plane_state *dm_new_plane_state, *dm_old_plane_state;
 +      int i ;
 +      /* TODO return page_flip_needed() function */
 +      bool pflip_needed  = !state->allow_modeset;
 +      int ret = 0;
 +
 +      if (pflip_needed)
 +              return ret;
 +
 +      /* Add new planes */
 +      for_each_oldnew_plane_in_state(state, plane, old_plane_state, new_plane_state, i) {
 +              new_plane_crtc = new_plane_state->crtc;
 +              old_plane_crtc = old_plane_state->crtc;
 +              dm_new_plane_state = to_dm_plane_state(new_plane_state);
 +              dm_old_plane_state = to_dm_plane_state(old_plane_state);
 +
 +              /*TODO Implement atomic check for cursor plane */
 +              if (plane->type == DRM_PLANE_TYPE_CURSOR)
 +                      continue;
 +
 +              /* Remove any changed/removed planes */
 +              if (!enable) {
 +
 +                      if (!old_plane_crtc)
 +                              continue;
 +
 +                      old_crtc_state = drm_atomic_get_old_crtc_state(
 +                                      state, old_plane_crtc);
 +                      dm_old_crtc_state = to_dm_crtc_state(old_crtc_state);
 +
 +                      if (!dm_old_crtc_state->stream)
 +                              continue;
 +
 +                      DRM_DEBUG_DRIVER("Disabling DRM plane: %d on DRM crtc %d\n",
 +                                      plane->base.id, old_plane_crtc->base.id);
 +
 +                      if (!dc_remove_plane_from_context(
 +                                      dc,
 +                                      dm_old_crtc_state->stream,
 +                                      dm_old_plane_state->dc_state,
 +                                      dm_state->context)) {
 +
 +                              ret = EINVAL;
 +                              return ret;
 +                      }
 +
 +
 +                      dc_plane_state_release(dm_old_plane_state->dc_state);
 +                      dm_new_plane_state->dc_state = NULL;
 +
 +                      *lock_and_validation_needed = true;
 +
 +              } else { /* Add new planes */
 +
 +                      if (drm_atomic_plane_disabling(plane->state, new_plane_state))
 +                              continue;
 +
 +                      if (!new_plane_crtc)
 +                              continue;
 +
 +                      new_crtc_state = drm_atomic_get_new_crtc_state(state, new_plane_crtc);
 +                      dm_new_crtc_state = to_dm_crtc_state(new_crtc_state);
 +
 +                      if (!dm_new_crtc_state->stream)
 +                              continue;
 +
 +
 +                      WARN_ON(dm_new_plane_state->dc_state);
 +
 +                      dm_new_plane_state->dc_state = dc_create_plane_state(dc);
 +
 +                      DRM_DEBUG_DRIVER("Enabling DRM plane: %d on DRM crtc %d\n",
 +                                      plane->base.id, new_plane_crtc->base.id);
 +
 +                      if (!dm_new_plane_state->dc_state) {
 +                              ret = -EINVAL;
 +                              return ret;
 +                      }
 +
 +                      ret = fill_plane_attributes(
 +                              new_plane_crtc->dev->dev_private,
 +                              dm_new_plane_state->dc_state,
 +                              new_plane_state,
 +                              new_crtc_state,
 +                              false);
 +                      if (ret)
 +                              return ret;
 +
 +
 +                      if (!dc_add_plane_to_context(
 +                                      dc,
 +                                      dm_new_crtc_state->stream,
 +                                      dm_new_plane_state->dc_state,
 +                                      dm_state->context)) {
 +
 +                              ret = -EINVAL;
 +                              return ret;
 +                      }
 +
 +                      *lock_and_validation_needed = true;
 +              }
 +      }
 +
 +
 +      return ret;
 +}
 +
 +static int amdgpu_dm_atomic_check(struct drm_device *dev,
 +                                struct drm_atomic_state *state)
 +{
 +      int i;
 +      int ret;
 +      struct amdgpu_device *adev = dev->dev_private;
 +      struct dc *dc = adev->dm.dc;
 +      struct dm_atomic_state *dm_state = to_dm_atomic_state(state);
 +      struct drm_connector *connector;
 +      struct drm_connector_state *old_con_state, *new_con_state;
 +      struct drm_crtc *crtc;
 +      struct drm_crtc_state *old_crtc_state, *new_crtc_state;
 +
 +      /*
 +       * This bool will be set for true for any modeset/reset
 +       * or plane update which implies non fast surface update.
 +       */
 +      bool lock_and_validation_needed = false;
 +
 +      ret = drm_atomic_helper_check_modeset(dev, state);
 +      if (ret)
 +              goto fail;
 +
 +      /*
 +       * legacy_cursor_update should be made false for SoC's having
 +       * a dedicated hardware plane for cursor in amdgpu_dm_atomic_commit(),
 +       * otherwise for software cursor plane,
 +       * we should not add it to list of affected planes.
 +       */
 +      if (state->legacy_cursor_update) {
 +              for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) {
 +                      if (new_crtc_state->color_mgmt_changed) {
 +                              ret = drm_atomic_add_affected_planes(state, crtc);
 +                              if (ret)
 +                                      goto fail;
 +                      }
 +              }
 +      } else {
 +              for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
 +                      if (!drm_atomic_crtc_needs_modeset(new_crtc_state) &&
 +                                      !new_crtc_state->color_mgmt_changed)
 +                              continue;
 +
 +                      if (!new_crtc_state->enable)
 +                              continue;
 +
 +                      ret = drm_atomic_add_affected_connectors(state, crtc);
 +                      if (ret)
 +                              return ret;
 +
 +                      ret = drm_atomic_add_affected_planes(state, crtc);
 +                      if (ret)
 +                              goto fail;
 +              }
 +      }
 +
 +      dm_state->context = dc_create_state();
 +      ASSERT(dm_state->context);
 +      dc_resource_state_copy_construct_current(dc, dm_state->context);
 +
 +      /* Remove exiting planes if they are modified */
 +      ret = dm_update_planes_state(dc, state, false, &lock_and_validation_needed);
 +      if (ret) {
 +              goto fail;
 +      }
 +
 +      /* Disable all crtcs which require disable */
 +      ret = dm_update_crtcs_state(dc, state, false, &lock_and_validation_needed);
 +      if (ret) {
 +              goto fail;
 +      }
 +
 +      /* Enable all crtcs which require enable */
 +      ret = dm_update_crtcs_state(dc, state, true, &lock_and_validation_needed);
 +      if (ret) {
 +              goto fail;
 +      }
 +
 +      /* Add new/modified planes */
 +      ret = dm_update_planes_state(dc, state, true, &lock_and_validation_needed);
 +      if (ret) {
 +              goto fail;
 +      }
 +
 +      /* Run this here since we want to validate the streams we created */
 +      ret = drm_atomic_helper_check_planes(dev, state);
 +      if (ret)
 +              goto fail;
 +
 +      /* Check scaling and underscan changes*/
 +      /*TODO Removed scaling changes validation due to inability to commit
 +       * new stream into context w\o causing full reset. Need to
 +       * decide how to handle.
 +       */
 +      for_each_oldnew_connector_in_state(state, connector, old_con_state, new_con_state, i) {
 +              struct dm_connector_state *dm_old_con_state = to_dm_connector_state(old_con_state);
 +              struct dm_connector_state *dm_new_con_state = to_dm_connector_state(new_con_state);
 +              struct amdgpu_crtc *acrtc = to_amdgpu_crtc(dm_new_con_state->base.crtc);
 +
 +              /* Skip any modesets/resets */
 +              if (!acrtc || drm_atomic_crtc_needs_modeset(
 +                              drm_atomic_get_new_crtc_state(state, &acrtc->base)))
 +                      continue;
 +
 +              /* Skip any thing not scale or underscan changes */
 +              if (!is_scaling_state_different(dm_new_con_state, dm_old_con_state))
 +                      continue;
 +
 +              lock_and_validation_needed = true;
 +      }
 +
 +      /*
 +       * For full updates case when
 +       * removing/adding/updating  streams on once CRTC while flipping
 +       * on another CRTC,
 +       * acquiring global lock  will guarantee that any such full
 +       * update commit
 +       * will wait for completion of any outstanding flip using DRMs
 +       * synchronization events.
 +       */
 +
 +      if (lock_and_validation_needed) {
 +
 +              ret = do_aquire_global_lock(dev, state);
 +              if (ret)
 +                      goto fail;
 +
 +              if (dc_validate_global_state(dc, dm_state->context) != DC_OK) {
 +                      ret = -EINVAL;
 +                      goto fail;
 +              }
 +      }
 +
 +      /* Must be success */
 +      WARN_ON(ret);
 +      return ret;
 +
 +fail:
 +      if (ret == -EDEADLK)
 +              DRM_DEBUG_DRIVER("Atomic check stopped to avoid deadlock.\n");
 +      else if (ret == -EINTR || ret == -EAGAIN || ret == -ERESTARTSYS)
 +              DRM_DEBUG_DRIVER("Atomic check stopped due to signal.\n");
 +      else
 +              DRM_DEBUG_DRIVER("Atomic check failed with err: %d \n", ret);
 +
 +      return ret;
 +}
 +
 +static bool is_dp_capable_without_timing_msa(struct dc *dc,
 +                                           struct amdgpu_dm_connector *amdgpu_dm_connector)
 +{
 +      uint8_t dpcd_data;
 +      bool capable = false;
 +
 +      if (amdgpu_dm_connector->dc_link &&
 +              dm_helpers_dp_read_dpcd(
 +                              NULL,
 +                              amdgpu_dm_connector->dc_link,
 +                              DP_DOWN_STREAM_PORT_COUNT,
 +                              &dpcd_data,
 +                              sizeof(dpcd_data))) {
 +              capable = (dpcd_data & DP_MSA_TIMING_PAR_IGNORED) ? true:false;
 +      }
 +
 +      return capable;
 +}
 +void amdgpu_dm_add_sink_to_freesync_module(struct drm_connector *connector,
 +                                         struct edid *edid)
 +{
 +      int i;
 +      uint64_t val_capable;
 +      bool edid_check_required;
 +      struct detailed_timing *timing;
 +      struct detailed_non_pixel *data;
 +      struct detailed_data_monitor_range *range;
 +      struct amdgpu_dm_connector *amdgpu_dm_connector =
 +                      to_amdgpu_dm_connector(connector);
 +
 +      struct drm_device *dev = connector->dev;
 +      struct amdgpu_device *adev = dev->dev_private;
 +
 +      edid_check_required = false;
 +      if (!amdgpu_dm_connector->dc_sink) {
 +              DRM_ERROR("dc_sink NULL, could not add free_sync module.\n");
 +              return;
 +      }
 +      if (!adev->dm.freesync_module)
 +              return;
 +      /*
 +       * if edid non zero restrict freesync only for dp and edp
 +       */
 +      if (edid) {
 +              if (amdgpu_dm_connector->dc_sink->sink_signal == SIGNAL_TYPE_DISPLAY_PORT
 +                      || amdgpu_dm_connector->dc_sink->sink_signal == SIGNAL_TYPE_EDP) {
 +                      edid_check_required = is_dp_capable_without_timing_msa(
 +                                              adev->dm.dc,
 +                                              amdgpu_dm_connector);
 +              }
 +      }
 +      val_capable = 0;
 +      if (edid_check_required == true && (edid->version > 1 ||
 +         (edid->version == 1 && edid->revision > 1))) {
 +              for (i = 0; i < 4; i++) {
 +
 +                      timing  = &edid->detailed_timings[i];
 +                      data    = &timing->data.other_data;
 +                      range   = &data->data.range;
 +                      /*
 +                       * Check if monitor has continuous frequency mode
 +                       */
 +                      if (data->type != EDID_DETAIL_MONITOR_RANGE)
 +                              continue;
 +                      /*
 +                       * Check for flag range limits only. If flag == 1 then
 +                       * no additional timing information provided.
 +                       * Default GTF, GTF Secondary curve and CVT are not
 +                       * supported
 +                       */
 +                      if (range->flags != 1)
 +                              continue;
 +
 +                      amdgpu_dm_connector->min_vfreq = range->min_vfreq;
 +                      amdgpu_dm_connector->max_vfreq = range->max_vfreq;
 +                      amdgpu_dm_connector->pixel_clock_mhz =
 +                              range->pixel_clock_mhz * 10;
 +                      break;
 +              }
 +
 +              if (amdgpu_dm_connector->max_vfreq -
 +                              amdgpu_dm_connector->min_vfreq > 10) {
 +                      amdgpu_dm_connector->caps.supported = true;
 +                      amdgpu_dm_connector->caps.min_refresh_in_micro_hz =
 +                                      amdgpu_dm_connector->min_vfreq * 1000000;
 +                      amdgpu_dm_connector->caps.max_refresh_in_micro_hz =
 +                                      amdgpu_dm_connector->max_vfreq * 1000000;
 +                              val_capable = 1;
 +              }
 +      }
 +
 +      /*
 +       * TODO figure out how to notify user-mode or DRM of freesync caps
 +       * once we figure out how to deal with freesync in an upstreamable
 +       * fashion
 +       */
 +
 +}
 +
 +void amdgpu_dm_remove_sink_from_freesync_module(struct drm_connector *connector)
 +{
 +      /*
 +       * TODO fill in once we figure out how to deal with freesync in
 +       * an upstreamable fashion
 +       */
 +}
index f8efb98b1fa72f86ecbec4c568a653af164c7daa,0000000000000000000000000000000000000000..707928b88448cf13fb41caaab84d999e31be3891
mode 100644,000000..100644
--- /dev/null
@@@ -1,446 -1,0 +1,441 @@@
-       int ret;
-       ret = drm_add_edid_modes(connector, edid);
-       drm_edid_to_eld(connector, edid);
-       return ret;
 +/*
 + * Copyright 2012-15 Advanced Micro Devices, Inc.
 + *
 + * Permission is hereby granted, free of charge, to any person obtaining a
 + * copy of this software and associated documentation files (the "Software"),
 + * to deal in the Software without restriction, including without limitation
 + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 + * and/or sell copies of the Software, and to permit persons to whom the
 + * Software is furnished to do so, subject to the following conditions:
 + *
 + * The above copyright notice and this permission notice shall be included in
 + * all copies or substantial portions of the Software.
 + *
 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
 + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 + * OTHER DEALINGS IN THE SOFTWARE.
 + *
 + * Authors: AMD
 + *
 + */
 +
 +#include <linux/version.h>
 +#include <drm/drm_atomic_helper.h>
 +#include "dm_services.h"
 +#include "amdgpu.h"
 +#include "amdgpu_dm.h"
 +#include "amdgpu_dm_mst_types.h"
 +
 +#include "dc.h"
 +#include "dm_helpers.h"
 +
 +#include "dc_link_ddc.h"
 +
 +/* #define TRACE_DPCD */
 +
 +#ifdef TRACE_DPCD
 +#define SIDE_BAND_MSG(address) (address >= DP_SIDEBAND_MSG_DOWN_REQ_BASE && address < DP_SINK_COUNT_ESI)
 +
 +static inline char *side_band_msg_type_to_str(uint32_t address)
 +{
 +      static char str[10] = {0};
 +
 +      if (address < DP_SIDEBAND_MSG_UP_REP_BASE)
 +              strcpy(str, "DOWN_REQ");
 +      else if (address < DP_SIDEBAND_MSG_DOWN_REP_BASE)
 +              strcpy(str, "UP_REP");
 +      else if (address < DP_SIDEBAND_MSG_UP_REQ_BASE)
 +              strcpy(str, "DOWN_REP");
 +      else
 +              strcpy(str, "UP_REQ");
 +
 +      return str;
 +}
 +
 +static void log_dpcd(uint8_t type,
 +                   uint32_t address,
 +                   uint8_t *data,
 +                   uint32_t size,
 +                   bool res)
 +{
 +      DRM_DEBUG_KMS("Op: %s, addr: %04x, SideBand Msg: %s, Op res: %s\n",
 +                      (type == DP_AUX_NATIVE_READ) ||
 +                      (type == DP_AUX_I2C_READ) ?
 +                                      "Read" : "Write",
 +                      address,
 +                      SIDE_BAND_MSG(address) ?
 +                                      side_band_msg_type_to_str(address) : "Nop",
 +                      res ? "OK" : "Fail");
 +
 +      if (res) {
 +              print_hex_dump(KERN_INFO, "Body: ", DUMP_PREFIX_NONE, 16, 1, data, size, false);
 +      }
 +}
 +#endif
 +
 +static ssize_t dm_dp_aux_transfer(struct drm_dp_aux *aux,
 +                                struct drm_dp_aux_msg *msg)
 +{
 +      enum i2c_mot_mode mot = (msg->request & DP_AUX_I2C_MOT) ?
 +              I2C_MOT_TRUE : I2C_MOT_FALSE;
 +      enum ddc_result res;
 +
 +      switch (msg->request & ~DP_AUX_I2C_MOT) {
 +      case DP_AUX_NATIVE_READ:
 +              res = dal_ddc_service_read_dpcd_data(
 +                              TO_DM_AUX(aux)->ddc_service,
 +                              false,
 +                              I2C_MOT_UNDEF,
 +                              msg->address,
 +                              msg->buffer,
 +                              msg->size);
 +              break;
 +      case DP_AUX_NATIVE_WRITE:
 +              res = dal_ddc_service_write_dpcd_data(
 +                              TO_DM_AUX(aux)->ddc_service,
 +                              false,
 +                              I2C_MOT_UNDEF,
 +                              msg->address,
 +                              msg->buffer,
 +                              msg->size);
 +              break;
 +      case DP_AUX_I2C_READ:
 +              res = dal_ddc_service_read_dpcd_data(
 +                              TO_DM_AUX(aux)->ddc_service,
 +                              true,
 +                              mot,
 +                              msg->address,
 +                              msg->buffer,
 +                              msg->size);
 +              break;
 +      case DP_AUX_I2C_WRITE:
 +              res = dal_ddc_service_write_dpcd_data(
 +                              TO_DM_AUX(aux)->ddc_service,
 +                              true,
 +                              mot,
 +                              msg->address,
 +                              msg->buffer,
 +                              msg->size);
 +              break;
 +      default:
 +              return 0;
 +      }
 +
 +#ifdef TRACE_DPCD
 +      log_dpcd(msg->request,
 +               msg->address,
 +               msg->buffer,
 +               msg->size,
 +               r == DDC_RESULT_SUCESSFULL);
 +#endif
 +
 +      return msg->size;
 +}
 +
 +static enum drm_connector_status
 +dm_dp_mst_detect(struct drm_connector *connector, bool force)
 +{
 +      struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(connector);
 +      struct amdgpu_dm_connector *master = aconnector->mst_port;
 +
 +      enum drm_connector_status status =
 +              drm_dp_mst_detect_port(
 +                      connector,
 +                      &master->mst_mgr,
 +                      aconnector->port);
 +
 +      return status;
 +}
 +
 +static void
 +dm_dp_mst_connector_destroy(struct drm_connector *connector)
 +{
 +      struct amdgpu_dm_connector *amdgpu_dm_connector = to_amdgpu_dm_connector(connector);
 +      struct amdgpu_encoder *amdgpu_encoder = amdgpu_dm_connector->mst_encoder;
 +
 +      drm_encoder_cleanup(&amdgpu_encoder->base);
 +      kfree(amdgpu_encoder);
 +      drm_connector_cleanup(connector);
 +      kfree(amdgpu_dm_connector);
 +}
 +
 +static const struct drm_connector_funcs dm_dp_mst_connector_funcs = {
 +      .detect = dm_dp_mst_detect,
 +      .fill_modes = drm_helper_probe_single_connector_modes,
 +      .destroy = dm_dp_mst_connector_destroy,
 +      .reset = amdgpu_dm_connector_funcs_reset,
 +      .atomic_duplicate_state = amdgpu_dm_connector_atomic_duplicate_state,
 +      .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
 +      .atomic_set_property = amdgpu_dm_connector_atomic_set_property,
 +      .atomic_get_property = amdgpu_dm_connector_atomic_get_property
 +};
 +
 +static int dm_connector_update_modes(struct drm_connector *connector,
 +                              struct edid *edid)
 +{
++      return drm_add_edid_modes(connector, edid);
 +}
 +
 +static int dm_dp_mst_get_modes(struct drm_connector *connector)
 +{
 +      struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(connector);
 +      int ret = 0;
 +
 +      if (!aconnector)
 +              return dm_connector_update_modes(connector, NULL);
 +
 +      if (!aconnector->edid) {
 +              struct edid *edid;
 +              struct dc_sink *dc_sink;
 +              struct dc_sink_init_data init_params = {
 +                              .link = aconnector->dc_link,
 +                              .sink_signal = SIGNAL_TYPE_DISPLAY_PORT_MST };
 +              edid = drm_dp_mst_get_edid(connector, &aconnector->mst_port->mst_mgr, aconnector->port);
 +
 +              if (!edid) {
 +                      drm_mode_connector_update_edid_property(
 +                              &aconnector->base,
 +                              NULL);
 +                      return ret;
 +              }
 +
 +              aconnector->edid = edid;
 +
 +              dc_sink = dc_link_add_remote_sink(
 +                      aconnector->dc_link,
 +                      (uint8_t *)edid,
 +                      (edid->extensions + 1) * EDID_LENGTH,
 +                      &init_params);
 +
 +              dc_sink->priv = aconnector;
 +              aconnector->dc_sink = dc_sink;
 +
 +              if (aconnector->dc_sink)
 +                      amdgpu_dm_add_sink_to_freesync_module(
 +                                      connector, edid);
 +
 +              drm_mode_connector_update_edid_property(
 +                                              &aconnector->base, edid);
 +      }
 +
 +      ret = dm_connector_update_modes(connector, aconnector->edid);
 +
 +      return ret;
 +}
 +
 +static struct drm_encoder *dm_mst_best_encoder(struct drm_connector *connector)
 +{
 +      struct amdgpu_dm_connector *amdgpu_dm_connector = to_amdgpu_dm_connector(connector);
 +
 +      return &amdgpu_dm_connector->mst_encoder->base;
 +}
 +
 +static const struct drm_connector_helper_funcs dm_dp_mst_connector_helper_funcs = {
 +      .get_modes = dm_dp_mst_get_modes,
 +      .mode_valid = amdgpu_dm_connector_mode_valid,
 +      .best_encoder = dm_mst_best_encoder,
 +};
 +
 +static void amdgpu_dm_encoder_destroy(struct drm_encoder *encoder)
 +{
 +      drm_encoder_cleanup(encoder);
 +      kfree(encoder);
 +}
 +
 +static const struct drm_encoder_funcs amdgpu_dm_encoder_funcs = {
 +      .destroy = amdgpu_dm_encoder_destroy,
 +};
 +
 +static struct amdgpu_encoder *
 +dm_dp_create_fake_mst_encoder(struct amdgpu_dm_connector *connector)
 +{
 +      struct drm_device *dev = connector->base.dev;
 +      struct amdgpu_device *adev = dev->dev_private;
 +      struct amdgpu_encoder *amdgpu_encoder;
 +      struct drm_encoder *encoder;
 +      const struct drm_connector_helper_funcs *connector_funcs =
 +              connector->base.helper_private;
 +      struct drm_encoder *enc_master =
 +              connector_funcs->best_encoder(&connector->base);
 +
 +      DRM_DEBUG_KMS("enc master is %p\n", enc_master);
 +      amdgpu_encoder = kzalloc(sizeof(*amdgpu_encoder), GFP_KERNEL);
 +      if (!amdgpu_encoder)
 +              return NULL;
 +
 +      encoder = &amdgpu_encoder->base;
 +      encoder->possible_crtcs = amdgpu_dm_get_encoder_crtc_mask(adev);
 +
 +      drm_encoder_init(
 +              dev,
 +              &amdgpu_encoder->base,
 +              &amdgpu_dm_encoder_funcs,
 +              DRM_MODE_ENCODER_DPMST,
 +              NULL);
 +
 +      drm_encoder_helper_add(encoder, &amdgpu_dm_encoder_helper_funcs);
 +
 +      return amdgpu_encoder;
 +}
 +
 +static struct drm_connector *
 +dm_dp_add_mst_connector(struct drm_dp_mst_topology_mgr *mgr,
 +                      struct drm_dp_mst_port *port,
 +                      const char *pathprop)
 +{
 +      struct amdgpu_dm_connector *master = container_of(mgr, struct amdgpu_dm_connector, mst_mgr);
 +      struct drm_device *dev = master->base.dev;
 +      struct amdgpu_device *adev = dev->dev_private;
 +      struct amdgpu_dm_connector *aconnector;
 +      struct drm_connector *connector;
 +      struct drm_connector_list_iter conn_iter;
 +
 +      drm_connector_list_iter_begin(dev, &conn_iter);
 +      drm_for_each_connector_iter(connector, &conn_iter) {
 +              aconnector = to_amdgpu_dm_connector(connector);
 +              if (aconnector->mst_port == master
 +                              && !aconnector->port) {
 +                      DRM_INFO("DM_MST: reusing connector: %p [id: %d] [master: %p]\n",
 +                                              aconnector, connector->base.id, aconnector->mst_port);
 +
 +                      aconnector->port = port;
 +                      drm_mode_connector_set_path_property(connector, pathprop);
 +
 +                      drm_connector_list_iter_end(&conn_iter);
 +                      return &aconnector->base;
 +              }
 +      }
 +      drm_connector_list_iter_end(&conn_iter);
 +
 +      aconnector = kzalloc(sizeof(*aconnector), GFP_KERNEL);
 +      if (!aconnector)
 +              return NULL;
 +
 +      connector = &aconnector->base;
 +      aconnector->port = port;
 +      aconnector->mst_port = master;
 +
 +      if (drm_connector_init(
 +              dev,
 +              connector,
 +              &dm_dp_mst_connector_funcs,
 +              DRM_MODE_CONNECTOR_DisplayPort)) {
 +              kfree(aconnector);
 +              return NULL;
 +      }
 +      drm_connector_helper_add(connector, &dm_dp_mst_connector_helper_funcs);
 +
 +      amdgpu_dm_connector_init_helper(
 +              &adev->dm,
 +              aconnector,
 +              DRM_MODE_CONNECTOR_DisplayPort,
 +              master->dc_link,
 +              master->connector_id);
 +
 +      aconnector->mst_encoder = dm_dp_create_fake_mst_encoder(master);
 +
 +      /*
 +       * TODO: understand why this one is needed
 +       */
 +      drm_object_attach_property(
 +              &connector->base,
 +              dev->mode_config.path_property,
 +              0);
 +      drm_object_attach_property(
 +              &connector->base,
 +              dev->mode_config.tile_property,
 +              0);
 +
 +      drm_mode_connector_set_path_property(connector, pathprop);
 +
 +      /*
 +       * Initialize connector state before adding the connectror to drm and
 +       * framebuffer lists
 +       */
 +      amdgpu_dm_connector_funcs_reset(connector);
 +
 +      DRM_INFO("DM_MST: added connector: %p [id: %d] [master: %p]\n",
 +                      aconnector, connector->base.id, aconnector->mst_port);
 +
 +      DRM_DEBUG_KMS(":%d\n", connector->base.id);
 +
 +      return connector;
 +}
 +
 +static void dm_dp_destroy_mst_connector(struct drm_dp_mst_topology_mgr *mgr,
 +                                      struct drm_connector *connector)
 +{
 +      struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(connector);
 +
 +      DRM_INFO("DM_MST: Disabling connector: %p [id: %d] [master: %p]\n",
 +                              aconnector, connector->base.id, aconnector->mst_port);
 +
 +      aconnector->port = NULL;
 +      if (aconnector->dc_sink) {
 +              amdgpu_dm_remove_sink_from_freesync_module(connector);
 +              dc_link_remove_remote_sink(aconnector->dc_link, aconnector->dc_sink);
 +              dc_sink_release(aconnector->dc_sink);
 +              aconnector->dc_sink = NULL;
 +      }
 +      if (aconnector->edid) {
 +              kfree(aconnector->edid);
 +              aconnector->edid = NULL;
 +      }
 +
 +      drm_mode_connector_update_edid_property(
 +                      &aconnector->base,
 +                      NULL);
 +}
 +
 +static void dm_dp_mst_hotplug(struct drm_dp_mst_topology_mgr *mgr)
 +{
 +      struct amdgpu_dm_connector *master = container_of(mgr, struct amdgpu_dm_connector, mst_mgr);
 +      struct drm_device *dev = master->base.dev;
 +
 +      drm_kms_helper_hotplug_event(dev);
 +}
 +
 +static void dm_dp_mst_register_connector(struct drm_connector *connector)
 +{
 +      struct drm_device *dev = connector->dev;
 +      struct amdgpu_device *adev = dev->dev_private;
 +
 +      if (adev->mode_info.rfbdev)
 +              drm_fb_helper_add_one_connector(&adev->mode_info.rfbdev->helper, connector);
 +      else
 +              DRM_ERROR("adev->mode_info.rfbdev is NULL\n");
 +
 +      drm_connector_register(connector);
 +
 +}
 +
 +static const struct drm_dp_mst_topology_cbs dm_mst_cbs = {
 +      .add_connector = dm_dp_add_mst_connector,
 +      .destroy_connector = dm_dp_destroy_mst_connector,
 +      .hotplug = dm_dp_mst_hotplug,
 +      .register_connector = dm_dp_mst_register_connector
 +};
 +
 +void amdgpu_dm_initialize_dp_connector(struct amdgpu_display_manager *dm,
 +                                     struct amdgpu_dm_connector *aconnector)
 +{
 +      aconnector->dm_dp_aux.aux.name = "dmdc";
 +      aconnector->dm_dp_aux.aux.dev = dm->adev->dev;
 +      aconnector->dm_dp_aux.aux.transfer = dm_dp_aux_transfer;
 +      aconnector->dm_dp_aux.ddc_service = aconnector->dc_link->ddc;
 +
 +      drm_dp_aux_register(&aconnector->dm_dp_aux.aux);
 +      aconnector->mst_mgr.cbs = &dm_mst_cbs;
 +      drm_dp_mst_topology_mgr_init(
 +              &aconnector->mst_mgr,
 +              dm->adev->ddev,
 +              &aconnector->dm_dp_aux.aux,
 +              16,
 +              4,
 +              aconnector->connector_id);
 +}
 +
index 5a5427bbd70e47e8e8e1e0b744bf356a6175a6bc,63511a3bbf6c090781b68c2b93f2834c1f6379cf..630721f429f7e748dfbc7e8a7d89a0a98b4f6377
@@@ -252,10 -252,10 +252,10 @@@ static int hdlcd_plane_atomic_check(str
        clip.x2 = crtc_state->adjusted_mode.hdisplay;
        clip.y2 = crtc_state->adjusted_mode.vdisplay;
  
-       return drm_plane_helper_check_state(state, &clip,
-                                           DRM_PLANE_HELPER_NO_SCALING,
-                                           DRM_PLANE_HELPER_NO_SCALING,
-                                           false, true);
+       return drm_atomic_helper_check_plane_state(state, crtc_state, &clip,
+                                                  DRM_PLANE_HELPER_NO_SCALING,
+                                                  DRM_PLANE_HELPER_NO_SCALING,
+                                                  false, true);
  }
  
  static void hdlcd_plane_atomic_update(struct drm_plane *plane,
@@@ -317,8 -317,9 +317,8 @@@ static struct drm_plane *hdlcd_plane_in
                                       formats, ARRAY_SIZE(formats),
                                       NULL,
                                       DRM_PLANE_TYPE_PRIMARY, NULL);
 -      if (ret) {
 +      if (ret)
                return ERR_PTR(ret);
 -      }
  
        drm_plane_helper_add(plane, &hdlcd_plane_helper_funcs);
        hdlcd->plane = plane;
index 0afb53b1f4e92b516088b03e287b09936818dd43,59b21bdc0c30dfd2cf808bcc8bb9b8a5e443c14a..feaa8bc3d7b760a58e2b4e32011ef252a22d85cd
@@@ -13,7 -13,6 +13,7 @@@
  #include <linux/spinlock.h>
  #include <linux/clk.h>
  #include <linux/component.h>
 +#include <linux/console.h>
  #include <linux/list.h>
  #include <linux/of_graph.h>
  #include <linux/of_reserved_mem.h>
@@@ -231,7 -230,6 +231,6 @@@ static int hdlcd_show_pxlclock(struct s
  static struct drm_info_list hdlcd_debugfs_list[] = {
        { "interrupt_count", hdlcd_show_underrun_count, 0 },
        { "clocks", hdlcd_show_pxlclock, 0 },
-       { "fb", drm_fb_cma_debugfs_show, 0 },
  };
  
  static int hdlcd_debugfs_init(struct drm_minor *minor)
@@@ -253,6 -251,7 +252,7 @@@ static struct drm_driver hdlcd_driver 
        .irq_postinstall = hdlcd_irq_postinstall,
        .irq_uninstall = hdlcd_irq_uninstall,
        .gem_free_object_unlocked = drm_gem_cma_free_object,
+       .gem_print_info = drm_gem_cma_print_info,
        .gem_vm_ops = &drm_gem_cma_vm_ops,
        .dumb_create = drm_gem_cma_dumb_create,
        .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
@@@ -355,7 -354,7 +355,7 @@@ err_unload
  err_free:
        drm_mode_config_cleanup(drm);
        dev_set_drvdata(dev, NULL);
 -      drm_dev_unref(drm);
 +      drm_dev_put(drm);
  
        return ret;
  }
@@@ -380,7 -379,7 +380,7 @@@ static void hdlcd_drm_unbind(struct dev
        pm_runtime_disable(drm->dev);
        of_reserved_mem_device_release(drm->dev);
        drm_mode_config_cleanup(drm);
 -      drm_dev_unref(drm);
 +      drm_dev_put(drm);
        drm->dev_private = NULL;
        dev_set_drvdata(dev, NULL);
  }
@@@ -433,11 -432,9 +433,11 @@@ static int __maybe_unused hdlcd_pm_susp
                return 0;
  
        drm_kms_helper_poll_disable(drm);
 +      drm_fbdev_cma_set_suspend_unlocked(hdlcd->fbdev, 1);
  
        hdlcd->state = drm_atomic_helper_suspend(drm);
        if (IS_ERR(hdlcd->state)) {
 +              drm_fbdev_cma_set_suspend_unlocked(hdlcd->fbdev, 0);
                drm_kms_helper_poll_enable(drm);
                return PTR_ERR(hdlcd->state);
        }
@@@ -454,8 -451,8 +454,8 @@@ static int __maybe_unused hdlcd_pm_resu
                return 0;
  
        drm_atomic_helper_resume(drm, hdlcd->state);
 +      drm_fbdev_cma_set_suspend_unlocked(hdlcd->fbdev, 0);
        drm_kms_helper_poll_enable(drm);
 -      pm_runtime_set_active(dev);
  
        return 0;
  }
index e7419797bbd16c157cab134184c24fd552cd2c44,72a07950167e8cb78edfc94a5f1f8ee3c3f297fc..33c5ef96ced0e0936d115096e04b55c173c9d0ec
@@@ -57,7 -57,7 +57,7 @@@ static void malidp_de_plane_destroy(str
        struct malidp_plane *mp = to_malidp_plane(plane);
  
        if (mp->base.fb)
 -              drm_framebuffer_unreference(mp->base.fb);
 +              drm_framebuffer_put(mp->base.fb);
  
        drm_plane_helper_disable(plane);
        drm_plane_cleanup(plane);
@@@ -150,7 -150,8 +150,8 @@@ static int malidp_se_check_scaling(stru
  
        clip.x2 = crtc_state->adjusted_mode.hdisplay;
        clip.y2 = crtc_state->adjusted_mode.vdisplay;
-       ret = drm_plane_helper_check_state(state, &clip, 0, INT_MAX, true, true);
+       ret = drm_atomic_helper_check_plane_state(state, crtc_state, &clip,
+                                                 0, INT_MAX, true, true);
        if (ret)
                return ret;
  
@@@ -185,9 -186,8 +186,9 @@@ static int malidp_de_plane_check(struc
  
        fb = state->fb;
  
 -      ms->format = malidp_hw_get_format_id(&mp->hwdev->map, mp->layer->id,
 -                                          fb->format->format);
 +      ms->format = malidp_hw_get_format_id(&mp->hwdev->hw->map,
 +                                           mp->layer->id,
 +                                           fb->format->format);
        if (ms->format == MALIDP_INVALID_FORMAT_ID)
                return -EINVAL;
  
         * third plane stride register.
         */
        if (ms->n_planes == 3 &&
 -          !(mp->hwdev->features & MALIDP_DEVICE_LV_HAS_3_STRIDES) &&
 +          !(mp->hwdev->hw->features & MALIDP_DEVICE_LV_HAS_3_STRIDES) &&
            (state->fb->pitches[1] != state->fb->pitches[2]))
                return -EINVAL;
  
        if (state->rotation & MALIDP_ROTATED_MASK) {
                int val;
  
 -              val = mp->hwdev->rotmem_required(mp->hwdev, state->crtc_h,
 -                                               state->crtc_w,
 -                                               fb->format->format);
 +              val = mp->hwdev->hw->rotmem_required(mp->hwdev, state->crtc_h,
 +                                                   state->crtc_w,
 +                                                   fb->format->format);
                if (val < 0)
                        return val;
  
@@@ -252,7 -252,7 +253,7 @@@ static void malidp_de_set_plane_pitches
                return;
  
        if (num_planes == 3)
 -              num_strides = (mp->hwdev->features &
 +              num_strides = (mp->hwdev->hw->features &
                               MALIDP_DEVICE_LV_HAS_3_STRIDES) ? 3 : 2;
  
        for (i = 0; i < num_strides; ++i)
@@@ -265,11 -265,13 +266,11 @@@ static void malidp_de_plane_update(stru
                                   struct drm_plane_state *old_state)
  {
        struct malidp_plane *mp;
 -      const struct malidp_hw_regmap *map;
        struct malidp_plane_state *ms = to_malidp_plane_state(plane->state);
        u32 src_w, src_h, dest_w, dest_h, val;
        int i;
  
        mp = to_malidp_plane(plane);
 -      map = &mp->hwdev->map;
  
        /* convert src values from Q16 fixed point to integer */
        src_w = plane->state->src_w >> 16;
@@@ -362,7 -364,7 +363,7 @@@ static const struct drm_plane_helper_fu
  int malidp_de_planes_init(struct drm_device *drm)
  {
        struct malidp_drm *malidp = drm->dev_private;
 -      const struct malidp_hw_regmap *map = &malidp->dev->map;
 +      const struct malidp_hw_regmap *map = &malidp->dev->hw->map;
        struct malidp_plane *plane = NULL;
        enum drm_plane_type plane_type;
        unsigned long crtcs = 1 << drm->mode_config.num_crtc;
index b72259bf6e2fb37ce155108a43f6e1ce49de91dc,b172139502d6dc8a66a50b7b70842961009c69a2..a38db40ce990de2c572fd0b0c2aca42d8273611c
@@@ -138,7 -138,6 +138,7 @@@ struct dw_hdmi 
        struct device *dev;
        struct clk *isfr_clk;
        struct clk *iahb_clk;
 +      struct clk *cec_clk;
        struct dw_hdmi_i2c *i2c;
  
        struct hdmi_data_info hdmi_data;
@@@ -1438,7 -1437,9 +1438,9 @@@ static void hdmi_config_vendor_specific
        u8 buffer[10];
        ssize_t err;
  
-       err = drm_hdmi_vendor_infoframe_from_display_mode(&frame, mode);
+       err = drm_hdmi_vendor_infoframe_from_display_mode(&frame,
+                                                         &hdmi->connector,
+                                                         mode);
        if (err < 0)
                /*
                 * Going into that statement does not means vendor infoframe
@@@ -1911,8 -1912,6 +1913,6 @@@ static int dw_hdmi_connector_get_modes(
                drm_mode_connector_update_edid_property(connector, edid);
                cec_notifier_set_phys_addr_from_edid(hdmi->cec_notifier, edid);
                ret = drm_add_edid_modes(connector, edid);
-               /* Store the ELD */
-               drm_edid_to_eld(connector, edid);
                kfree(edid);
        } else {
                dev_dbg(hdmi->dev, "failed to get edid\n");
@@@ -2383,26 -2382,6 +2383,26 @@@ __dw_hdmi_probe(struct platform_device 
                goto err_isfr;
        }
  
 +      hdmi->cec_clk = devm_clk_get(hdmi->dev, "cec");
 +      if (PTR_ERR(hdmi->cec_clk) == -ENOENT) {
 +              hdmi->cec_clk = NULL;
 +      } else if (IS_ERR(hdmi->cec_clk)) {
 +              ret = PTR_ERR(hdmi->cec_clk);
 +              if (ret != -EPROBE_DEFER)
 +                      dev_err(hdmi->dev, "Cannot get HDMI cec clock: %d\n",
 +                              ret);
 +
 +              hdmi->cec_clk = NULL;
 +              goto err_iahb;
 +      } else {
 +              ret = clk_prepare_enable(hdmi->cec_clk);
 +              if (ret) {
 +                      dev_err(hdmi->dev, "Cannot enable HDMI cec clock: %d\n",
 +                              ret);
 +                      goto err_iahb;
 +              }
 +      }
 +
        /* Product and revision IDs */
        hdmi->version = (hdmi_readb(hdmi, HDMI_DESIGN_ID) << 8)
                      | (hdmi_readb(hdmi, HDMI_REVISION_ID) << 0);
@@@ -2539,8 -2518,6 +2539,8 @@@ err_iahb
                cec_notifier_put(hdmi->cec_notifier);
  
        clk_disable_unprepare(hdmi->iahb_clk);
 +      if (hdmi->cec_clk)
 +              clk_disable_unprepare(hdmi->cec_clk);
  err_isfr:
        clk_disable_unprepare(hdmi->isfr_clk);
  err_res:
@@@ -2564,8 -2541,6 +2564,8 @@@ static void __dw_hdmi_remove(struct dw_
  
        clk_disable_unprepare(hdmi->iahb_clk);
        clk_disable_unprepare(hdmi->isfr_clk);
 +      if (hdmi->cec_clk)
 +              clk_disable_unprepare(hdmi->cec_clk);
  
        if (hdmi->i2c)
                i2c_del_adapter(&hdmi->i2c->adap);
index 8636e7eeb7315c471eae9a01dad16d20133a441b,e79fbc1b770441d7280a1efe537a47c1efbad630..08ab7d6aea65168c9e903ab6582d24157b3cc8f1
@@@ -6,6 -6,8 +6,8 @@@
   *
   * Copyright (C) 2016 Pengutronix, Philipp Zabel <[email protected]>
   *
+  * Copyright (C) 2016 Zodiac Inflight Innovations
+  *
   * Initially based on: drivers/gpu/drm/i2c/tda998x_drv.c
   *
   * Copyright (C) 2012 Texas Instruments
@@@ -97,7 -99,7 +99,7 @@@
  #define DP0_ACTIVEVAL         0x0650
  #define DP0_SYNCVAL           0x0654
  #define DP0_MISC              0x0658
 -#define TU_SIZE_RECOMMENDED           (0x3f << 16) /* LSCLK cycles per TU */
 +#define TU_SIZE_RECOMMENDED           (63) /* LSCLK cycles per TU */
  #define BPC_6                         (0 << 5)
  #define BPC_8                         (1 << 5)
  
@@@ -318,7 -320,7 +320,7 @@@ static ssize_t tc_aux_transfer(struct d
                                tmp = (tmp << 8) | buf[i];
                        i++;
                        if (((i % 4) == 0) || (i == size)) {
 -                              tc_write(DP0_AUXWDATA(i >> 2), tmp);
 +                              tc_write(DP0_AUXWDATA((i - 1) >> 2), tmp);
                                tmp = 0;
                        }
                }
@@@ -603,15 -605,8 +605,15 @@@ static int tc_get_display_props(struct 
        ret = drm_dp_link_probe(&tc->aux, &tc->link.base);
        if (ret < 0)
                goto err_dpcd_read;
 -      if ((tc->link.base.rate != 162000) && (tc->link.base.rate != 270000))
 -              goto err_dpcd_inval;
 +      if (tc->link.base.rate != 162000 && tc->link.base.rate != 270000) {
 +              dev_dbg(tc->dev, "Falling to 2.7 Gbps rate\n");
 +              tc->link.base.rate = 270000;
 +      }
 +
 +      if (tc->link.base.num_lanes > 2) {
 +              dev_dbg(tc->dev, "Falling to 2 lanes\n");
 +              tc->link.base.num_lanes = 2;
 +      }
  
        ret = drm_dp_dpcd_readb(&tc->aux, DP_MAX_DOWNSPREAD, tmp);
        if (ret < 0)
  err_dpcd_read:
        dev_err(tc->dev, "failed to read DPCD: %d\n", ret);
        return ret;
 -err_dpcd_inval:
 -      dev_err(tc->dev, "invalid DPCD\n");
 -      return -EINVAL;
  }
  
  static int tc_set_video_mode(struct tc_data *tc, struct drm_display_mode *mode)
        int lower_margin = mode->vsync_start - mode->vdisplay;
        int vsync_len = mode->vsync_end - mode->vsync_start;
  
 +      /*
 +       * Recommended maximum number of symbols transferred in a transfer unit:
 +       * DIV_ROUND_UP((input active video bandwidth in bytes) * tu_size,
 +       *              (output active video bandwidth in bytes))
 +       * Must be less than tu_size.
 +       */
 +      max_tu_symbol = TU_SIZE_RECOMMENDED - 1;
 +
        dev_dbg(tc->dev, "set mode %dx%d\n",
                mode->hdisplay, mode->vdisplay);
        dev_dbg(tc->dev, "H margin %d,%d sync %d\n",
        dev_dbg(tc->dev, "total: %dx%d\n", mode->htotal, mode->vtotal);
  
  
 -      /* LCD Ctl Frame Size */
 -      tc_write(VPCTRL0, (0x40 << 20) /* VSDELAY */ |
 +      /*
 +       * LCD Ctl Frame Size
 +       * datasheet is not clear of vsdelay in case of DPI
 +       * assume we do not need any delay when DPI is a source of
 +       * sync signals
 +       */
 +      tc_write(VPCTRL0, (0 << 20) /* VSDELAY */ |
                 OPXLFMT_RGB888 | FRMSYNC_DISABLED | MSF_DISABLED);
 -      tc_write(HTIM01, (left_margin << 16) |          /* H back porch */
 -                       (hsync_len << 0));             /* Hsync */
 -      tc_write(HTIM02, (right_margin << 16) |         /* H front porch */
 -                       (mode->hdisplay << 0));        /* width */
 +      tc_write(HTIM01, (ALIGN(left_margin, 2) << 16) | /* H back porch */
 +                       (ALIGN(hsync_len, 2) << 0));    /* Hsync */
 +      tc_write(HTIM02, (ALIGN(right_margin, 2) << 16) |  /* H front porch */
 +                       (ALIGN(mode->hdisplay, 2) << 0)); /* width */
        tc_write(VTIM01, (upper_margin << 16) |         /* V back porch */
                         (vsync_len << 0));             /* Vsync */
        tc_write(VTIM02, (lower_margin << 16) |         /* V front porch */
        /* DP Main Stream Attributes */
        vid_sync_dly = hsync_len + left_margin + mode->hdisplay;
        tc_write(DP0_VIDSYNCDELAY,
 -               (0x003e << 16) |       /* thresh_dly */
 +               (max_tu_symbol << 16) |        /* thresh_dly */
                 (vid_sync_dly << 0));
  
        tc_write(DP0_TOTALVAL, (mode->vtotal << 16) | (mode->htotal));
        tc_write(DPIPXLFMT, VS_POL_ACTIVE_LOW | HS_POL_ACTIVE_LOW |
                 DE_POL_ACTIVE_HIGH | SUB_CFG_TYPE_CONFIG1 | DPI_BPP_RGB888);
  
 -      /*
 -       * Recommended maximum number of symbols transferred in a transfer unit:
 -       * DIV_ROUND_UP((input active video bandwidth in bytes) * tu_size,
 -       *              (output active video bandwidth in bytes))
 -       * Must be less than tu_size.
 -       */
 -      max_tu_symbol = TU_SIZE_RECOMMENDED - 1;
 -      tc_write(DP0_MISC, (max_tu_symbol << 23) | TU_SIZE_RECOMMENDED | BPC_8);
 +      tc_write(DP0_MISC, (max_tu_symbol << 23) | (TU_SIZE_RECOMMENDED << 16) |
 +                         BPC_8);
  
        return 0;
  err:
@@@ -819,6 -810,8 +821,6 @@@ static int tc_main_link_setup(struct tc
        unsigned int rate;
        u32 dp_phy_ctrl;
        int timeout;
 -      bool aligned;
 -      bool ready;
        u32 value;
        int ret;
        u8 tmp[8];
                ret = drm_dp_dpcd_read_link_status(aux, tmp + 2);
                if (ret < 0)
                        goto err_dpcd_read;
 -              ready = (tmp[2] == ((DP_CHANNEL_EQ_BITS << 4) | /* Lane1 */
 -                                   DP_CHANNEL_EQ_BITS));      /* Lane0 */
 -              aligned = tmp[4] & DP_INTERLANE_ALIGN_DONE;
 -      } while ((--timeout) && !(ready && aligned));
 +      } while ((--timeout) &&
 +               !(drm_dp_channel_eq_ok(tmp + 2,  tc->link.base.num_lanes)));
  
        if (timeout == 0) {
                /* Read DPCD 0x200-0x201 */
                ret = drm_dp_dpcd_read(aux, DP_SINK_COUNT, tmp, 2);
                if (ret < 0)
                        goto err_dpcd_read;
 +              dev_err(dev, "channel(s) EQ not ok\n");
                dev_info(dev, "0x0200 SINK_COUNT: 0x%02x\n", tmp[0]);
                dev_info(dev, "0x0201 DEVICE_SERVICE_IRQ_VECTOR: 0x%02x\n",
                         tmp[1]);
                dev_info(dev, "0x0206 ADJUST_REQUEST_LANE0_1: 0x%02x\n",
                         tmp[6]);
  
 -              if (!ready)
 -                      dev_err(dev, "Lane0/1 not ready\n");
 -              if (!aligned)
 -                      dev_err(dev, "Lane0/1 not aligned\n");
                return -EAGAIN;
        }
  
@@@ -1103,10 -1101,7 +1105,10 @@@ static bool tc_bridge_mode_fixup(struc
  static int tc_connector_mode_valid(struct drm_connector *connector,
                                   struct drm_display_mode *mode)
  {
 -      /* Accept any mode */
 +      /* DPI interface clock limitation: upto 154 MHz */
 +      if (mode->clock > 154000)
 +              return MODE_CLOCK_HIGH;
 +
        return MODE_OK;
  }
  
index b16f1d69a0bbf345e33e277de5ce73a38974bf73,2f80377101a19b9fb9007f4309fffc759262fda0..ab4032167094cca0ddeb3583915af6fe07ae5301
@@@ -695,6 -695,100 +695,100 @@@ drm_atomic_helper_check_modeset(struct 
  }
  EXPORT_SYMBOL(drm_atomic_helper_check_modeset);
  
+ /**
+  * drm_atomic_helper_check_plane_state() - Check plane state for validity
+  * @plane_state: plane state to check
+  * @crtc_state: crtc state to check
+  * @clip: integer clipping coordinates
+  * @min_scale: minimum @src:@dest scaling factor in 16.16 fixed point
+  * @max_scale: maximum @src:@dest scaling factor in 16.16 fixed point
+  * @can_position: is it legal to position the plane such that it
+  *                doesn't cover the entire crtc?  This will generally
+  *                only be false for primary planes.
+  * @can_update_disabled: can the plane be updated while the crtc
+  *                       is disabled?
+  *
+  * Checks that a desired plane update is valid, and updates various
+  * bits of derived state (clipped coordinates etc.). Drivers that provide
+  * their own plane handling rather than helper-provided implementations may
+  * still wish to call this function to avoid duplication of error checking
+  * code.
+  *
+  * RETURNS:
+  * Zero if update appears valid, error code on failure
+  */
+ int drm_atomic_helper_check_plane_state(struct drm_plane_state *plane_state,
+                                       const struct drm_crtc_state *crtc_state,
+                                       const struct drm_rect *clip,
+                                       int min_scale,
+                                       int max_scale,
+                                       bool can_position,
+                                       bool can_update_disabled)
+ {
+       struct drm_framebuffer *fb = plane_state->fb;
+       struct drm_rect *src = &plane_state->src;
+       struct drm_rect *dst = &plane_state->dst;
+       unsigned int rotation = plane_state->rotation;
+       int hscale, vscale;
+       WARN_ON(plane_state->crtc && plane_state->crtc != crtc_state->crtc);
+       *src = drm_plane_state_src(plane_state);
+       *dst = drm_plane_state_dest(plane_state);
+       if (!fb) {
+               plane_state->visible = false;
+               return 0;
+       }
+       /* crtc should only be NULL when disabling (i.e., !fb) */
+       if (WARN_ON(!plane_state->crtc)) {
+               plane_state->visible = false;
+               return 0;
+       }
+       if (!crtc_state->enable && !can_update_disabled) {
+               DRM_DEBUG_KMS("Cannot update plane of a disabled CRTC.\n");
+               return -EINVAL;
+       }
+       drm_rect_rotate(src, fb->width << 16, fb->height << 16, rotation);
+       /* Check scaling */
+       hscale = drm_rect_calc_hscale(src, dst, min_scale, max_scale);
+       vscale = drm_rect_calc_vscale(src, dst, min_scale, max_scale);
+       if (hscale < 0 || vscale < 0) {
+               DRM_DEBUG_KMS("Invalid scaling of plane\n");
+               drm_rect_debug_print("src: ", &plane_state->src, true);
+               drm_rect_debug_print("dst: ", &plane_state->dst, false);
+               return -ERANGE;
+       }
+       plane_state->visible = drm_rect_clip_scaled(src, dst, clip, hscale, vscale);
+       drm_rect_rotate_inv(src, fb->width << 16, fb->height << 16, rotation);
+       if (!plane_state->visible)
+               /*
+                * Plane isn't visible; some drivers can handle this
+                * so we just return success here.  Drivers that can't
+                * (including those that use the primary plane helper's
+                * update function) will return an error from their
+                * update_plane handler.
+                */
+               return 0;
+       if (!can_position && !drm_rect_equals(dst, clip)) {
+               DRM_DEBUG_KMS("Plane must cover entire CRTC\n");
+               drm_rect_debug_print("dst: ", dst, false);
+               drm_rect_debug_print("clip: ", clip, false);
+               return -EINVAL;
+       }
+       return 0;
+ }
+ EXPORT_SYMBOL(drm_atomic_helper_check_plane_state);
  /**
   * drm_atomic_helper_check_planes - validate state object for planes changes
   * @dev: DRM device
@@@ -907,6 -1001,12 +1001,12 @@@ disable_outputs(struct drm_device *dev
   *
   * Drivers can use this for building their own atomic commit if they don't have
   * a pure helper-based modeset implementation.
+  *
+  * Since these updates are not synchronized with lockings, only code paths
+  * called from &drm_mode_config_helper_funcs.atomic_commit_tail can look at the
+  * legacy state filled out by this helper. Defacto this means this helper and
+  * the legacy state pointers are only really useful for transitioning an
+  * existing driver to the atomic world.
   */
  void
  drm_atomic_helper_update_legacy_modeset_state(struct drm_device *dev,
@@@ -1225,7 -1325,7 +1325,7 @@@ drm_atomic_helper_wait_for_vblanks(stru
                return;
  
        for_each_oldnew_crtc_in_state(old_state, crtc, old_crtc_state, new_crtc_state, i) {
 -              if (!new_crtc_state->active || !new_crtc_state->planes_changed)
 +              if (!new_crtc_state->active)
                        continue;
  
                ret = drm_crtc_vblank_get(crtc);
@@@ -1787,11 -1887,8 +1887,8 @@@ int drm_atomic_helper_setup_commit(stru
                    !try_wait_for_completion(&old_conn_state->commit->flip_done))
                        return -EBUSY;
  
-               /* commit tracked through new_crtc_state->commit, no need to do it explicitly */
-               if (new_conn_state->crtc)
-                       continue;
-               commit = crtc_or_fake_commit(state, old_conn_state->crtc);
+               /* Always track connectors explicitly for e.g. link retraining. */
+               commit = crtc_or_fake_commit(state, new_conn_state->crtc ?: old_conn_state->crtc);
                if (!commit)
                        return -ENOMEM;
  
                    !try_wait_for_completion(&old_plane_state->commit->flip_done))
                        return -EBUSY;
  
-               /*
-                * Unlike connectors, always track planes explicitly for
-                * async pageflip support.
-                */
+               /* Always track planes explicitly for async pageflip support. */
                commit = crtc_or_fake_commit(state, new_plane_state->crtc ?: old_plane_state->crtc);
                if (!commit)
                        return -ENOMEM;
index 5dfe147638716730573d008edc65abfc92f6d75a,9ada0ccf50dff96a7bfe57c4f407db73bf81ca9d..524eace3d460fe66841884c7e434f8d5b0406d85
@@@ -82,8 -82,6 +82,8 @@@
  #define EDID_QUIRK_FORCE_6BPC                 (1 << 10)
  /* Force 10bpc */
  #define EDID_QUIRK_FORCE_10BPC                        (1 << 11)
 +/* Non desktop display (i.e. HMD) */
 +#define EDID_QUIRK_NON_DESKTOP                        (1 << 12)
  
  struct detailed_mode_closure {
        struct drm_connector *connector;
@@@ -159,9 -157,6 +159,9 @@@ static const struct edid_quirk 
  
        /* Rotel RSX-1058 forwards sink's EDID but only does HDMI 1.1*/
        { "ETR", 13896, EDID_QUIRK_FORCE_8BPC },
 +
 +      /* HTC Vive VR Headset */
 +      { "HVR", 0xaa01, EDID_QUIRK_NON_DESKTOP },
  };
  
  /*
@@@ -3398,6 -3393,7 +3398,7 @@@ static in
  do_hdmi_vsdb_modes(struct drm_connector *connector, const u8 *db, u8 len,
                   const u8 *video_db, u8 video_len)
  {
+       struct drm_display_info *info = &connector->display_info;
        int modes = 0, offset = 0, i, multi_present = 0, multi_len;
        u8 vic_len, hdmi_3d_len = 0;
        u16 mask;
        }
  
  out:
+       if (modes > 0)
+               info->has_hdmi_infoframe = true;
        return modes;
  }
  
@@@ -3761,8 -3759,8 +3764,8 @@@ drm_parse_hdmi_vsdb_audio(struct drm_co
  {
        u8 len = cea_db_payload_len(db);
  
-       if (len >= 6)
-               connector->eld[5] |= (db[6] >> 7) << 1;  /* Supports_AI */
+       if (len >= 6 && (db[6] & (1 << 7)))
+               connector->eld[DRM_ELD_SAD_COUNT_CONN_TYPE] |= DRM_ELD_SUPPORTS_AI;
        if (len >= 8) {
                connector->latency_present[0] = db[8] >> 7;
                connector->latency_present[1] = (db[8] >> 6) & 1;
@@@ -3834,16 -3832,27 +3837,27 @@@ void drm_edid_get_monitor_name(struct e
  }
  EXPORT_SYMBOL(drm_edid_get_monitor_name);
  
- /**
+ static void clear_eld(struct drm_connector *connector)
+ {
+       memset(connector->eld, 0, sizeof(connector->eld));
+       connector->latency_present[0] = false;
+       connector->latency_present[1] = false;
+       connector->video_latency[0] = 0;
+       connector->audio_latency[0] = 0;
+       connector->video_latency[1] = 0;
+       connector->audio_latency[1] = 0;
+ }
+ /*
   * drm_edid_to_eld - build ELD from EDID
   * @connector: connector corresponding to the HDMI/DP sink
   * @edid: EDID to parse
   *
   * Fill the ELD (EDID-Like Data) buffer for passing to the audio driver. The
-  * Conn_Type, HDCP and Port_ID ELD fields are left for the graphics driver to
-  * fill in.
+  * HDCP and Port_ID ELD fields are left for the graphics driver to fill in.
   */
- void drm_edid_to_eld(struct drm_connector *connector, struct edid *edid)
static void drm_edid_to_eld(struct drm_connector *connector, struct edid *edid)
  {
        uint8_t *eld = connector->eld;
        u8 *cea;
        int mnl;
        int dbl;
  
-       memset(eld, 0, sizeof(connector->eld));
-       connector->latency_present[0] = false;
-       connector->latency_present[1] = false;
-       connector->video_latency[0] = 0;
-       connector->audio_latency[0] = 0;
-       connector->video_latency[1] = 0;
-       connector->audio_latency[1] = 0;
+       clear_eld(connector);
  
        if (!edid)
                return;
                return;
        }
  
-       mnl = get_monitor_name(edid, eld + 20);
+       mnl = get_monitor_name(edid, &eld[DRM_ELD_MONITOR_NAME_STRING]);
+       DRM_DEBUG_KMS("ELD monitor %s\n", &eld[DRM_ELD_MONITOR_NAME_STRING]);
  
-       eld[4] = (cea[1] << 5) | mnl;
-       DRM_DEBUG_KMS("ELD monitor %s\n", eld + 20);
+       eld[DRM_ELD_CEA_EDID_VER_MNL] = cea[1] << DRM_ELD_CEA_EDID_VER_SHIFT;
+       eld[DRM_ELD_CEA_EDID_VER_MNL] |= mnl;
  
-       eld[0] = 2 << 3;                /* ELD version: 2 */
+       eld[DRM_ELD_VER] = DRM_ELD_VER_CEA861D;
  
-       eld[16] = edid->mfg_id[0];
-       eld[17] = edid->mfg_id[1];
-       eld[18] = edid->prod_code[0];
-       eld[19] = edid->prod_code[1];
+       eld[DRM_ELD_MANUFACTURER_NAME0] = edid->mfg_id[0];
+       eld[DRM_ELD_MANUFACTURER_NAME1] = edid->mfg_id[1];
+       eld[DRM_ELD_PRODUCT_CODE0] = edid->prod_code[0];
+       eld[DRM_ELD_PRODUCT_CODE1] = edid->prod_code[1];
  
        if (cea_revision(cea) >= 3) {
                int i, start, end;
                                /* Audio Data Block, contains SADs */
                                sad_count = min(dbl / 3, 15 - total_sad_count);
                                if (sad_count >= 1)
-                                       memcpy(eld + 20 + mnl + total_sad_count * 3,
+                                       memcpy(&eld[DRM_ELD_CEA_SAD(mnl, total_sad_count)],
                                               &db[1], sad_count * 3);
                                total_sad_count += sad_count;
                                break;
                        case SPEAKER_BLOCK:
                                /* Speaker Allocation Data Block */
                                if (dbl >= 1)
-                                       eld[7] = db[1];
+                                       eld[DRM_ELD_SPEAKER] = db[1];
                                break;
                        case VENDOR_BLOCK:
                                /* HDMI Vendor-Specific Data Block */
                        }
                }
        }
-       eld[5] |= total_sad_count << 4;
+       eld[DRM_ELD_SAD_COUNT_CONN_TYPE] |= total_sad_count << DRM_ELD_SAD_COUNT_SHIFT;
+       if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
+           connector->connector_type == DRM_MODE_CONNECTOR_eDP)
+               eld[DRM_ELD_SAD_COUNT_CONN_TYPE] |= DRM_ELD_CONN_TYPE_DP;
+       else
+               eld[DRM_ELD_SAD_COUNT_CONN_TYPE] |= DRM_ELD_CONN_TYPE_HDMI;
  
        eld[DRM_ELD_BASELINE_ELD_LEN] =
                DIV_ROUND_UP(drm_eld_calc_baseline_block_size(eld), 4);
        DRM_DEBUG_KMS("ELD size %d, SAD count %d\n",
                      drm_eld_size(eld), total_sad_count);
  }
- EXPORT_SYMBOL(drm_edid_to_eld);
  
  /**
   * drm_edid_to_sad - extracts SADs from EDID
@@@ -4238,6 -4246,8 +4251,8 @@@ static void drm_parse_hdmi_forum_vsdb(s
        struct drm_display_info *display = &connector->display_info;
        struct drm_hdmi_info *hdmi = &display->hdmi;
  
+       display->has_hdmi_infoframe = true;
        if (hf_vsdb[6] & 0x80) {
                hdmi->scdc.supported = true;
                if (hf_vsdb[6] & 0x40)
@@@ -4398,7 -4408,7 +4413,7 @@@ static void drm_parse_cea_ext(struct dr
  }
  
  static void drm_add_display_info(struct drm_connector *connector,
 -                               struct edid *edid)
 +                               struct edid *edid, u32 quirks)
  {
        struct drm_display_info *info = &connector->display_info;
  
        info->cea_rev = 0;
        info->max_tmds_clock = 0;
        info->dvi_dual = false;
+       info->has_hdmi_infoframe = false;
  
 +      info->non_desktop = !!(quirks & EDID_QUIRK_NON_DESKTOP);
 +
        if (edid->revision < 3)
                return;
  
@@@ -4608,8 -4617,8 +4624,8 @@@ static int add_displayid_detailed_modes
   * @edid: EDID data
   *
   * Add the specified modes to the connector's mode list. Also fills out the
-  * &drm_display_info structure in @connector with any information which can be
-  * derived from the edid.
+  * &drm_display_info structure and ELD in @connector with any information which
+  * can be derived from the edid.
   *
   * Return: The number of modes added or 0 if we couldn't find any.
   */
@@@ -4619,9 -4628,11 +4635,11 @@@ int drm_add_edid_modes(struct drm_conne
        u32 quirks;
  
        if (edid == NULL) {
+               clear_eld(connector);
                return 0;
        }
        if (!drm_edid_is_valid(edid)) {
+               clear_eld(connector);
                dev_warn(connector->dev->dev, "%s: EDID invalid.\n",
                         connector->name);
                return 0;
  
        quirks = edid_get_quirks(edid);
  
+       drm_edid_to_eld(connector, edid);
        /*
         * CEA-861-F adds ycbcr capability map block, for HDMI 2.0 sinks.
         * To avoid multiple parsing of same block, lets parse that map
         * from sink info, before parsing CEA modes.
         */
 -      drm_add_display_info(connector, edid);
 +      drm_add_display_info(connector, edid, quirks);
  
        /*
         * EDID spec says modes should be preferred in this order:
@@@ -4831,8 -4844,7 +4851,8 @@@ voi
  drm_hdmi_avi_infoframe_quant_range(struct hdmi_avi_infoframe *frame,
                                   const struct drm_display_mode *mode,
                                   enum hdmi_quantization_range rgb_quant_range,
 -                                 bool rgb_quant_range_selectable)
 +                                 bool rgb_quant_range_selectable,
 +                                 bool is_hdmi2_sink)
  {
        /*
         * CEA-861:
         *  YQ-field to match the RGB Quantization Range being transmitted
         *  (e.g., when Limited Range RGB, set YQ=0 or when Full Range RGB,
         *  set YQ=1) and the Sink shall ignore the YQ-field."
 +       *
 +       * Unfortunate certain sinks (eg. VIZ Model 67/E261VA) get confused
 +       * by non-zero YQ when receiving RGB. There doesn't seem to be any
 +       * good way to tell which version of CEA-861 the sink supports, so
 +       * we limit non-zero YQ to HDMI 2.0 sinks only as HDMI 2.0 is based
 +       * on on CEA-861-F.
         */
 -      if (rgb_quant_range == HDMI_QUANTIZATION_RANGE_LIMITED)
 +      if (!is_hdmi2_sink ||
 +          rgb_quant_range == HDMI_QUANTIZATION_RANGE_LIMITED)
                frame->ycc_quantization_range =
                        HDMI_YCC_QUANTIZATION_RANGE_LIMITED;
        else
@@@ -4904,6 -4909,7 +4924,7 @@@ s3d_structure_from_display_mode(const s
   * drm_hdmi_vendor_infoframe_from_display_mode() - fill an HDMI infoframe with
   * data from a DRM display mode
   * @frame: HDMI vendor infoframe
+  * @connector: the connector
   * @mode: DRM display mode
   *
   * Note that there's is a need to send HDMI vendor infoframes only when using a
   */
  int
  drm_hdmi_vendor_infoframe_from_display_mode(struct hdmi_vendor_infoframe *frame,
+                                           struct drm_connector *connector,
                                            const struct drm_display_mode *mode)
  {
+       /*
+        * FIXME: sil-sii8620 doesn't have a connector around when
+        * we need one, so we have to be prepared for a NULL connector.
+        */
+       bool has_hdmi_infoframe = connector ?
+               connector->display_info.has_hdmi_infoframe : false;
        int err;
        u32 s3d_flags;
        u8 vic;
        if (!frame || !mode)
                return -EINVAL;
  
+       if (!has_hdmi_infoframe)
+               return -EINVAL;
        vic = drm_match_hdmi_mode(mode);
        s3d_flags = mode->flags & DRM_MODE_FLAG_3D_MASK;
  
-       if (!vic && !s3d_flags)
-               return -EINVAL;
+       /*
+        * Even if it's not absolutely necessary to send the infoframe
+        * (ie.vic==0 and s3d_struct==0) we will still send it if we
+        * know that the sink can handle it. This is based on a
+        * suggestion in HDMI 2.0 Appendix F. Apparently some sinks
+        * have trouble realizing that they shuld switch from 3D to 2D
+        * mode if the source simply stops sending the infoframe when
+        * it wants to switch from 3D to 2D.
+        */
  
        if (vic && s3d_flags)
                return -EINVAL;
        if (err < 0)
                return err;
  
-       if (vic)
-               frame->vic = vic;
-       else
-               frame->s3d_struct = s3d_structure_from_display_mode(mode);
+       frame->vic = vic;
+       frame->s3d_struct = s3d_structure_from_display_mode(mode);
  
        return 0;
  }
index e561663344559b065643464cf669d8b84930007f,defd6a76fef33d578a30c6e25192976afd165335..09919e8d67f9deed89fc5dd6e1c1b5ed80330c34
@@@ -150,6 -150,9 +150,9 @@@ int drm_fb_helper_add_one_connector(str
  {
        int err;
  
+       if (!fb_helper)
+               return 0;
        mutex_lock(&fb_helper->lock);
        err = __drm_fb_helper_add_one_connector(fb_helper, connector);
        mutex_unlock(&fb_helper->lock);
@@@ -161,7 -164,7 +164,7 @@@ EXPORT_SYMBOL(drm_fb_helper_add_one_con
  /**
   * drm_fb_helper_single_add_all_connectors() - add all connectors to fbdev
   *                                           emulation helper
-  * @fb_helper: fbdev initialized with drm_fb_helper_init
+  * @fb_helper: fbdev initialized with drm_fb_helper_init, can be NULL
   *
   * This functions adds all the available connectors for use with the given
   * fb_helper. This is a separate step to allow drivers to freely assign
@@@ -179,7 -182,7 +182,7 @@@ int drm_fb_helper_single_add_all_connec
        struct drm_connector_list_iter conn_iter;
        int i, ret = 0;
  
-       if (!drm_fbdev_emulation)
+       if (!drm_fbdev_emulation || !fb_helper)
                return 0;
  
        mutex_lock(&fb_helper->lock);
@@@ -245,6 -248,9 +248,9 @@@ int drm_fb_helper_remove_one_connector(
  {
        int err;
  
+       if (!fb_helper)
+               return 0;
        mutex_lock(&fb_helper->lock);
        err = __drm_fb_helper_remove_one_connector(fb_helper, connector);
        mutex_unlock(&fb_helper->lock);
@@@ -484,7 -490,7 +490,7 @@@ static int restore_fbdev_mode(struct dr
  
  /**
   * drm_fb_helper_restore_fbdev_mode_unlocked - restore fbdev configuration
-  * @fb_helper: fbcon to restore
+  * @fb_helper: driver-allocated fbdev helper, can be NULL
   *
   * This should be called from driver's drm &drm_driver.lastclose callback
   * when implementing an fbcon on top of kms using this helper. This ensures that
@@@ -498,7 -504,7 +504,7 @@@ int drm_fb_helper_restore_fbdev_mode_un
        bool do_delayed;
        int ret;
  
-       if (!drm_fbdev_emulation)
+       if (!drm_fbdev_emulation || !fb_helper)
                return -ENODEV;
  
        if (READ_ONCE(fb_helper->deferred_setup))
@@@ -793,8 -799,10 +799,10 @@@ int drm_fb_helper_init(struct drm_devic
        struct drm_mode_config *config = &dev->mode_config;
        int i;
  
-       if (!drm_fbdev_emulation)
+       if (!drm_fbdev_emulation) {
+               dev->fb_helper = fb_helper;
                return 0;
+       }
  
        if (!max_conn_count)
                return -EINVAL;
                i++;
        }
  
+       dev->fb_helper = fb_helper;
        return 0;
  out_free:
        drm_fb_helper_crtc_free(fb_helper);
@@@ -883,7 -893,7 +893,7 @@@ EXPORT_SYMBOL(drm_fb_helper_alloc_fbi)
  
  /**
   * drm_fb_helper_unregister_fbi - unregister fb_info framebuffer device
-  * @fb_helper: driver-allocated fbdev helper
+  * @fb_helper: driver-allocated fbdev helper, can be NULL
   *
   * A wrapper around unregister_framebuffer, to release the fb_info
   * framebuffer device. This must be called before releasing all resources for
@@@ -898,7 -908,7 +908,7 @@@ EXPORT_SYMBOL(drm_fb_helper_unregister_
  
  /**
   * drm_fb_helper_fini - finialize a &struct drm_fb_helper
-  * @fb_helper: driver-allocated fbdev helper
+  * @fb_helper: driver-allocated fbdev helper, can be NULL
   *
   * This cleans up all remaining resources associated with @fb_helper. Must be
   * called after drm_fb_helper_unlink_fbi() was called.
@@@ -907,7 -917,12 +917,12 @@@ void drm_fb_helper_fini(struct drm_fb_h
  {
        struct fb_info *info;
  
-       if (!drm_fbdev_emulation || !fb_helper)
+       if (!fb_helper)
+               return;
+       fb_helper->dev->fb_helper = NULL;
+       if (!drm_fbdev_emulation)
                return;
  
        cancel_work_sync(&fb_helper->resume_work);
@@@ -937,7 -952,7 +952,7 @@@ EXPORT_SYMBOL(drm_fb_helper_fini)
  
  /**
   * drm_fb_helper_unlink_fbi - wrapper around unlink_framebuffer
-  * @fb_helper: driver-allocated fbdev helper
+  * @fb_helper: driver-allocated fbdev helper, can be NULL
   *
   * A wrapper around unlink_framebuffer implemented by fbdev core
   */
@@@ -1138,7 -1153,7 +1153,7 @@@ EXPORT_SYMBOL(drm_fb_helper_cfb_imagebl
  
  /**
   * drm_fb_helper_set_suspend - wrapper around fb_set_suspend
-  * @fb_helper: driver-allocated fbdev helper
+  * @fb_helper: driver-allocated fbdev helper, can be NULL
   * @suspend: whether to suspend or resume
   *
   * A wrapper around fb_set_suspend implemented by fbdev core.
@@@ -1155,7 -1170,7 +1170,7 @@@ EXPORT_SYMBOL(drm_fb_helper_set_suspend
  /**
   * drm_fb_helper_set_suspend_unlocked - wrapper around fb_set_suspend that also
   *                                      takes the console lock
-  * @fb_helper: driver-allocated fbdev helper
+  * @fb_helper: driver-allocated fbdev helper, can be NULL
   * @suspend: whether to suspend or resume
   *
   * A wrapper around fb_set_suspend() that takes the console lock. If the lock
@@@ -1809,10 -1824,6 +1824,10 @@@ static int drm_fb_helper_single_fb_prob
  
        if (crtc_count == 0 || sizes.fb_width == -1 || sizes.fb_height == -1) {
                DRM_INFO("Cannot find any crtc or sizes\n");
 +
 +              /* First time: disable all crtc's.. */
 +              if (!fb_helper->deferred_setup && !READ_ONCE(fb_helper->dev->master))
 +                      restore_fbdev_mode(fb_helper);
                return -EAGAIN;
        }
  
@@@ -2037,9 -2048,6 +2052,9 @@@ static bool drm_connector_enabled(struc
  {
        bool enable;
  
 +      if (connector->display_info.non_desktop)
 +              return false;
 +
        if (strict)
                enable = connector->status == connector_status_connected;
        else
@@@ -2059,8 -2067,7 +2074,8 @@@ static void drm_enable_connectors(struc
                connector = fb_helper->connector_info[i]->connector;
                enabled[i] = drm_connector_enabled(connector, true);
                DRM_DEBUG_KMS("connector %d enabled? %s\n", connector->base.id,
 -                        enabled[i] ? "yes" : "no");
 +                            connector->display_info.non_desktop ? "non desktop" : enabled[i] ? "yes" : "no");
 +
                any_enabled |= enabled[i];
        }
  
@@@ -2576,7 -2583,7 +2591,7 @@@ EXPORT_SYMBOL(drm_fb_helper_initial_con
  /**
   * drm_fb_helper_hotplug_event - respond to a hotplug notification by
   *                               probing all the outputs attached to the fb
-  * @fb_helper: the drm_fb_helper
+  * @fb_helper: driver-allocated fbdev helper, can be NULL
   *
   * Scan the connectors attached to the fb_helper and try to put together a
   * setup after notification of a change in output configuration.
@@@ -2598,7 -2605,7 +2613,7 @@@ int drm_fb_helper_hotplug_event(struct 
  {
        int err = 0;
  
-       if (!drm_fbdev_emulation)
+       if (!drm_fbdev_emulation || !fb_helper)
                return 0;
  
        mutex_lock(&fb_helper->lock);
  }
  EXPORT_SYMBOL(drm_fb_helper_hotplug_event);
  
+ /**
+  * drm_fb_helper_lastclose - DRM driver lastclose helper for fbdev emulation
+  * @dev: DRM device
+  *
+  * This function can be used as the &drm_driver->lastclose callback for drivers
+  * that only need to call drm_fb_helper_restore_fbdev_mode_unlocked().
+  */
+ void drm_fb_helper_lastclose(struct drm_device *dev)
+ {
+       drm_fb_helper_restore_fbdev_mode_unlocked(dev->fb_helper);
+ }
+ EXPORT_SYMBOL(drm_fb_helper_lastclose);
+ /**
+  * drm_fb_helper_output_poll_changed - DRM mode config \.output_poll_changed
+  *                                     helper for fbdev emulation
+  * @dev: DRM device
+  *
+  * This function can be used as the
+  * &drm_mode_config_funcs.output_poll_changed callback for drivers that only
+  * need to call drm_fb_helper_hotplug_event().
+  */
+ void drm_fb_helper_output_poll_changed(struct drm_device *dev)
+ {
+       drm_fb_helper_hotplug_event(dev->fb_helper);
+ }
+ EXPORT_SYMBOL(drm_fb_helper_output_poll_changed);
  /* The Kconfig DRM_KMS_HELPER selects FRAMEBUFFER_CONSOLE (if !EXPERT)
   * but the module doesn't depend on any fb console symbols.  At least
   * attempt to load fbcon to avoid leaving the system without a usable console.
index 3717b3df34a41fdc2170af50802490d4ee63ad20,2c68909637b536ac0a34fab56427186ff1b8a9bb..32d9bcf5be7f3f28367f7751b633f9b20fbb5ddc
@@@ -367,9 -367,9 +367,9 @@@ void drm_vblank_disable_and_save(struc
        spin_unlock_irqrestore(&dev->vblank_time_lock, irqflags);
  }
  
 -static void vblank_disable_fn(unsigned long arg)
 +static void vblank_disable_fn(struct timer_list *t)
  {
 -      struct drm_vblank_crtc *vblank = (void *)arg;
 +      struct drm_vblank_crtc *vblank = from_timer(vblank, t, disable_timer);
        struct drm_device *dev = vblank->dev;
        unsigned int pipe = vblank->pipe;
        unsigned long irqflags;
@@@ -436,7 -436,8 +436,7 @@@ int drm_vblank_init(struct drm_device *
                vblank->dev = dev;
                vblank->pipe = i;
                init_waitqueue_head(&vblank->queue);
 -              setup_timer(&vblank->disable_timer, vblank_disable_fn,
 -                          (unsigned long)vblank);
 +              timer_setup(&vblank->disable_timer, vblank_disable_fn, 0);
                seqlock_init(&vblank->seqlock);
        }
  
@@@ -663,14 -664,16 +663,16 @@@ bool drm_calc_vbltimestamp_from_scanout
        delta_ns = div_s64(1000000LL * (vpos * mode->crtc_htotal + hpos),
                           mode->crtc_clock);
  
-       /* save this only for debugging purposes */
-       ts_etime = ktime_to_timespec64(etime);
-       ts_vblank_time = ktime_to_timespec64(*vblank_time);
        /* Subtract time delta from raw timestamp to get final
         * vblank_time timestamp for end of vblank.
         */
-       etime = ktime_sub_ns(etime, delta_ns);
-       *vblank_time = etime;
+       *vblank_time = ktime_sub_ns(etime, delta_ns);
+       if ((drm_debug & DRM_UT_VBL) == 0)
+               return true;
+       ts_etime = ktime_to_timespec64(etime);
+       ts_vblank_time = ktime_to_timespec64(*vblank_time);
  
        DRM_DEBUG_VBL("crtc %u : v p(%d,%d)@ %lld.%06ld -> %lld.%06ld [e %d us, %d rep]\n",
                      pipe, hpos, vpos,
@@@ -1018,7 -1021,7 +1020,7 @@@ static void drm_vblank_put(struct drm_d
                if (drm_vblank_offdelay == 0)
                        return;
                else if (drm_vblank_offdelay < 0)
 -                      vblank_disable_fn((unsigned long)vblank);
 +                      vblank_disable_fn(&vblank->disable_timer);
                else if (!dev->vblank_disable_immediate)
                        mod_timer(&vblank->disable_timer,
                                  jiffies + ((drm_vblank_offdelay * HZ)/1000));
@@@ -1649,7 -1652,7 +1651,7 @@@ bool drm_handle_vblank(struct drm_devic
        spin_unlock_irqrestore(&dev->event_lock, irqflags);
  
        if (disable_irq)
 -              vblank_disable_fn((unsigned long)vblank);
 +              vblank_disable_fn(&vblank->disable_timer);
  
        return true;
  }
index 127815253a84522b2e7c59f1f1af175a56b46158,60981505763cbecd81471a08549f3ac74c3e6d53..cd3f0873bbddabe41845bf08d3fde399c09290f6
@@@ -601,9 -601,9 +601,9 @@@ tda998x_reset(struct tda998x_priv *priv
   * we have seen a HPD inactive->active transition.  This code implements
   * that delay.
   */
 -static void tda998x_edid_delay_done(unsigned long data)
 +static void tda998x_edid_delay_done(struct timer_list *t)
  {
 -      struct tda998x_priv *priv = (struct tda998x_priv *)data;
 +      struct tda998x_priv *priv = from_timer(priv, t, edid_delay_timer);
  
        priv->edid_delay_active = false;
        wake_up(&priv->edid_delay_waitq);
@@@ -1100,7 -1100,6 +1100,6 @@@ static int tda998x_connector_get_modes(
  
        drm_mode_connector_update_edid_property(connector, edid);
        n = drm_add_edid_modes(connector, edid);
-       drm_edid_to_eld(connector, edid);
  
        kfree(edid);
  
@@@ -1492,7 -1491,8 +1491,7 @@@ static int tda998x_create(struct i2c_cl
  
        mutex_init(&priv->mutex);       /* protect the page access */
        init_waitqueue_head(&priv->edid_delay_waitq);
 -      setup_timer(&priv->edid_delay_timer, tda998x_edid_delay_done,
 -                  (unsigned long)priv);
 +      timer_setup(&priv->edid_delay_timer, tda998x_edid_delay_done, 0);
        INIT_WORK(&priv->detect_work, tda998x_detect_work);
  
        /* wake up the device: */
index 878acc432a4b0c7ad3ea4774696928309756b207,053ae6d3d3395697836c7fbd602ee1edc94343b2..e0fffd883b54baf7f5e17ca492f51d8e08d4e958
@@@ -9314,11 -9314,12 +9314,12 @@@ static int intel_check_cursor(struct in
        u32 offset;
        int ret;
  
-       ret = drm_plane_helper_check_state(&plane_state->base,
-                                          &plane_state->clip,
-                                          DRM_PLANE_HELPER_NO_SCALING,
-                                          DRM_PLANE_HELPER_NO_SCALING,
-                                          true, true);
+       ret = drm_atomic_helper_check_plane_state(&plane_state->base,
+                                                 &crtc_state->base,
+                                                 &plane_state->clip,
+                                                 DRM_PLANE_HELPER_NO_SCALING,
+                                                 DRM_PLANE_HELPER_NO_SCALING,
+                                                 true, true);
        if (ret)
                return ret;
  
@@@ -12794,10 -12795,11 +12795,11 @@@ intel_check_primary_plane(struct intel_
                can_position = true;
        }
  
-       ret = drm_plane_helper_check_state(&state->base,
-                                          &state->clip,
-                                          min_scale, max_scale,
-                                          can_position, true);
+       ret = drm_atomic_helper_check_plane_state(&state->base,
+                                                 &crtc_state->base,
+                                                 &state->clip,
+                                                 min_scale, max_scale,
+                                                 can_position, true);
        if (ret)
                return ret;
  
@@@ -15196,23 -15198,6 +15198,23 @@@ void intel_connector_unregister(struct 
        intel_panel_destroy_backlight(connector);
  }
  
 +static void intel_hpd_poll_fini(struct drm_device *dev)
 +{
 +      struct intel_connector *connector;
 +      struct drm_connector_list_iter conn_iter;
 +
 +      /* First disable polling... */
 +      drm_kms_helper_poll_fini(dev);
 +
 +      /* Then kill the work that may have been queued by hpd. */
 +      drm_connector_list_iter_begin(dev, &conn_iter);
 +      for_each_intel_connector_iter(connector, &conn_iter) {
 +              if (connector->modeset_retry_work.func)
 +                      cancel_work_sync(&connector->modeset_retry_work);
 +      }
 +      drm_connector_list_iter_end(&conn_iter);
 +}
 +
  void intel_modeset_cleanup(struct drm_device *dev)
  {
        struct drm_i915_private *dev_priv = to_i915(dev);
         * Due to the hpd irq storm handling the hotplug work can re-arm the
         * poll handlers. Hence disable polling after hpd handling is shut down.
         */
 -      drm_kms_helper_poll_fini(dev);
 +      intel_hpd_poll_fini(dev);
  
        /* poll work can call into fbdev, hence clean that up afterwards */
        intel_fbdev_fini(dev_priv);
index 158438bb03891092514b047f9ca73f57d89dcb82,d112810041098171398dc81f016b3fdd20f2707f..65260fb35d2a78def00f92d8d57bebafbc3a60c6
@@@ -3735,16 -3735,9 +3735,16 @@@ intel_edp_init_dpcd(struct intel_dp *in
  
        }
  
 -      /* Read the eDP Display control capabilities registers */
 -      if ((intel_dp->dpcd[DP_EDP_CONFIGURATION_CAP] & DP_DPCD_DISPLAY_CONTROL_CAPABLE) &&
 -          drm_dp_dpcd_read(&intel_dp->aux, DP_EDP_DPCD_REV,
 +      /*
 +       * Read the eDP display control registers.
 +       *
 +       * Do this independent of DP_DPCD_DISPLAY_CONTROL_CAPABLE bit in
 +       * DP_EDP_CONFIGURATION_CAP, because some buggy displays do not have it
 +       * set, but require eDP 1.4+ detection (e.g. for supported link rates
 +       * method). The display control registers should read zero if they're
 +       * not supported anyway.
 +       */
 +      if (drm_dp_dpcd_read(&intel_dp->aux, DP_EDP_DPCD_REV,
                             intel_dp->edp_dpcd, sizeof(intel_dp->edp_dpcd)) ==
                             sizeof(intel_dp->edp_dpcd))
                DRM_DEBUG_KMS("EDP DPCD : %*ph\n", (int) sizeof(intel_dp->edp_dpcd),
@@@ -5868,7 -5861,6 +5868,6 @@@ static bool intel_edp_init_connector(st
                if (drm_add_edid_modes(connector, edid)) {
                        drm_mode_connector_update_edid_property(connector,
                                                                edid);
-                       drm_edid_to_eld(connector, edid);
                } else {
                        kfree(edid);
                        edid = ERR_PTR(-EINVAL);
index 4dea833f9d1b78c17239eeade593a72c88fbc166,59247a49a07730052b06bc6828623a29ccd06478..e039702c19073b747b19c81bab88df3c5ab7bc7b
@@@ -487,8 -487,7 +487,8 @@@ static void intel_hdmi_set_avi_infofram
                                           crtc_state->limited_color_range ?
                                           HDMI_QUANTIZATION_RANGE_LIMITED :
                                           HDMI_QUANTIZATION_RANGE_FULL,
 -                                         intel_hdmi->rgb_quant_range_selectable);
 +                                         intel_hdmi->rgb_quant_range_selectable,
 +                                         is_hdmi2_sink);
  
        /* TODO: handle pixel repetition for YCBCR420 outputs */
        intel_write_infoframe(encoder, crtc_state, &frame);
@@@ -513,12 -512,14 +513,14 @@@ static void intel_hdmi_set_spd_infofram
  
  static void
  intel_hdmi_set_hdmi_infoframe(struct drm_encoder *encoder,
-                             const struct intel_crtc_state *crtc_state)
+                             const struct intel_crtc_state *crtc_state,
+                             const struct drm_connector_state *conn_state)
  {
        union hdmi_infoframe frame;
        int ret;
  
        ret = drm_hdmi_vendor_infoframe_from_display_mode(&frame.vendor.hdmi,
+                                                         conn_state->connector,
                                                          &crtc_state->base.adjusted_mode);
        if (ret < 0)
                return;
@@@ -585,7 -586,7 +587,7 @@@ static void g4x_set_infoframes(struct d
  
        intel_hdmi_set_avi_infoframe(encoder, crtc_state);
        intel_hdmi_set_spd_infoframe(encoder, crtc_state);
-       intel_hdmi_set_hdmi_infoframe(encoder, crtc_state);
+       intel_hdmi_set_hdmi_infoframe(encoder, crtc_state, conn_state);
  }
  
  static bool hdmi_sink_is_deep_color(const struct drm_connector_state *conn_state)
@@@ -726,7 -727,7 +728,7 @@@ static void ibx_set_infoframes(struct d
  
        intel_hdmi_set_avi_infoframe(encoder, crtc_state);
        intel_hdmi_set_spd_infoframe(encoder, crtc_state);
-       intel_hdmi_set_hdmi_infoframe(encoder, crtc_state);
+       intel_hdmi_set_hdmi_infoframe(encoder, crtc_state, conn_state);
  }
  
  static void cpt_set_infoframes(struct drm_encoder *encoder,
  
        intel_hdmi_set_avi_infoframe(encoder, crtc_state);
        intel_hdmi_set_spd_infoframe(encoder, crtc_state);
-       intel_hdmi_set_hdmi_infoframe(encoder, crtc_state);
+       intel_hdmi_set_hdmi_infoframe(encoder, crtc_state, conn_state);
  }
  
  static void vlv_set_infoframes(struct drm_encoder *encoder,
  
        intel_hdmi_set_avi_infoframe(encoder, crtc_state);
        intel_hdmi_set_spd_infoframe(encoder, crtc_state);
-       intel_hdmi_set_hdmi_infoframe(encoder, crtc_state);
+       intel_hdmi_set_hdmi_infoframe(encoder, crtc_state, conn_state);
  }
  
  static void hsw_set_infoframes(struct drm_encoder *encoder,
  
        intel_hdmi_set_avi_infoframe(encoder, crtc_state);
        intel_hdmi_set_spd_infoframe(encoder, crtc_state);
-       intel_hdmi_set_hdmi_infoframe(encoder, crtc_state);
+       intel_hdmi_set_hdmi_infoframe(encoder, crtc_state, conn_state);
  }
  
  void intel_dp_dual_mode_set_tmds_output(struct intel_hdmi *hdmi, bool enable)
index 584466ef688f5f965acf14de06f06a217bc1afab,fdfeae12ef62206e870ed97e83c7fd40190749ae..65336948e807877746f39c8f6c778668c1a2e149
@@@ -1143,10 -1143,11 +1143,11 @@@ nv50_curs_acquire(struct nv50_wndw *wnd
  {
        int ret;
  
-       ret = drm_plane_helper_check_state(&asyw->state, &asyw->clip,
-                                          DRM_PLANE_HELPER_NO_SCALING,
-                                          DRM_PLANE_HELPER_NO_SCALING,
-                                          true, true);
+       ret = drm_atomic_helper_check_plane_state(&asyw->state, &asyh->state,
+                                                 &asyw->clip,
+                                                 DRM_PLANE_HELPER_NO_SCALING,
+                                                 DRM_PLANE_HELPER_NO_SCALING,
+                                                 true, true);
        asyh->curs.visible = asyw->state.visible;
        if (ret || !asyh->curs.visible)
                return ret;
@@@ -1432,10 -1433,11 +1433,11 @@@ nv50_base_acquire(struct nv50_wndw *wnd
        if (!fb->format->depth)
                return -EINVAL;
  
-       ret = drm_plane_helper_check_state(&asyw->state, &asyw->clip,
-                                          DRM_PLANE_HELPER_NO_SCALING,
-                                          DRM_PLANE_HELPER_NO_SCALING,
-                                          false, true);
+       ret = drm_atomic_helper_check_plane_state(&asyw->state, &asyh->state,
+                                                 &asyw->clip,
+                                                 DRM_PLANE_HELPER_NO_SCALING,
+                                                 DRM_PLANE_HELPER_NO_SCALING,
+                                                 false, true);
        if (ret)
                return ret;
  
@@@ -2688,7 -2690,6 +2690,6 @@@ nv50_audio_enable(struct drm_encoder *e
        if (!drm_detect_monitor_audio(nv_connector->edid))
                return;
  
-       drm_edid_to_eld(&nv_connector->base, nv_connector->edid);
        memcpy(args.data, nv_connector->base.eld, sizeof(args.data));
  
        nvif_mthd(disp->disp, 0, &args,
@@@ -2755,7 -2756,8 +2756,8 @@@ nv50_hdmi_enable(struct drm_encoder *en
                        = hdmi_infoframe_pack(&avi_frame, args.infoframes, 17);
        }
  
-       ret = drm_hdmi_vendor_infoframe_from_display_mode(&vendor_frame.vendor.hdmi, mode);
+       ret = drm_hdmi_vendor_infoframe_from_display_mode(&vendor_frame.vendor.hdmi,
+                                                         &nv_connector->base, mode);
        if (!ret) {
                /* We have a Vendor InfoFrame, populate it to the display */
                args.pwr.vendor_infoframe_length
@@@ -3064,10 -3066,8 +3066,8 @@@ nv50_mstc_get_modes(struct drm_connecto
  
        mstc->edid = drm_dp_mst_get_edid(&mstc->connector, mstc->port->mgr, mstc->port);
        drm_mode_connector_update_edid_property(&mstc->connector, mstc->edid);
-       if (mstc->edid) {
+       if (mstc->edid)
                ret = drm_add_edid_modes(&mstc->connector, mstc->edid);
-               drm_edid_to_eld(&mstc->connector, mstc->edid);
-       }
  
        if (!mstc->connector.display_info.bpc)
                mstc->connector.display_info.bpc = 8;
@@@ -4099,7 -4099,7 +4099,7 @@@ nv50_disp_atomic_commit(struct drm_devi
  {
        struct nouveau_drm *drm = nouveau_drm(dev);
        struct nv50_disp *disp = nv50_disp(dev);
 -      struct drm_plane_state *old_plane_state;
 +      struct drm_plane_state *new_plane_state;
        struct drm_plane *plane;
        struct drm_crtc *crtc;
        bool active = false;
        if (ret)
                goto err_cleanup;
  
 -      for_each_old_plane_in_state(state, plane, old_plane_state, i) {
 -              struct nv50_wndw_atom *asyw = nv50_wndw_atom(old_plane_state);
 +      for_each_new_plane_in_state(state, plane, new_plane_state, i) {
 +              struct nv50_wndw_atom *asyw = nv50_wndw_atom(new_plane_state);
                struct nv50_wndw *wndw = nv50_wndw(plane);
  
                if (asyw->set.image) {
index 2917ea1b667e59ee6b4149851f9e10d2350b23b1,1768926d2ebc01a727cc9c8662ea41efe881f93c..183b4b4821383ecb5ed218a974cff7c4b7fef156
@@@ -1,4 -1,3 +1,4 @@@
 +// SPDX-License-Identifier: GPL-2.0
  
  #include <drm/drmP.h>
  #include <drm/drm_dp_mst_helper.h>
@@@ -197,7 -196,6 +197,6 @@@ static int radeon_dp_mst_get_ddc_modes(
        if (radeon_connector->edid) {
                drm_mode_connector_update_edid_property(&radeon_connector->base, radeon_connector->edid);
                ret = drm_add_edid_modes(&radeon_connector->base, radeon_connector->edid);
-               drm_edid_to_eld(&radeon_connector->base, radeon_connector->edid);
                return ret;
        }
        drm_mode_connector_update_edid_property(&radeon_connector->base, NULL);
index 0b2088264039131f05c2f09bc9ba84d2d3793e39,ab3bcbe0bb93f34c09966f6989e9f45eb46bc90e..984501e3f0b0adc02ed12342eb8f1fbafd8e3dd4
@@@ -287,7 -287,6 +287,6 @@@ static int vc4_hdmi_connector_get_modes
  
        drm_mode_connector_update_edid_property(connector, edid);
        ret = drm_add_edid_modes(connector, edid);
-       drm_edid_to_eld(connector, edid);
        kfree(edid);
  
        return ret;
@@@ -424,8 -423,7 +423,8 @@@ static void vc4_hdmi_set_avi_infoframe(
                                           vc4_encoder->limited_rgb_range ?
                                           HDMI_QUANTIZATION_RANGE_LIMITED :
                                           HDMI_QUANTIZATION_RANGE_FULL,
 -                                         vc4_encoder->rgb_range_selectable);
 +                                         vc4_encoder->rgb_range_selectable,
 +                                         false);
  
        vc4_hdmi_write_infoframe(encoder, &frame);
  }
@@@ -695,7 -693,22 +694,22 @@@ static void vc4_hdmi_encoder_enable(str
        }
  }
  
+ static enum drm_mode_status
+ vc4_hdmi_encoder_mode_valid(struct drm_encoder *crtc,
+                           const struct drm_display_mode *mode)
+ {
+       /* HSM clock must be 108% of the pixel clock.  Additionally,
+        * the AXI clock needs to be at least 25% of pixel clock, but
+        * HSM ends up being the limiting factor.
+        */
+       if (mode->clock > HSM_CLOCK_FREQ / (1000 * 108 / 100))
+               return MODE_CLOCK_HIGH;
+       return MODE_OK;
+ }
  static const struct drm_encoder_helper_funcs vc4_hdmi_encoder_helper_funcs = {
+       .mode_valid = vc4_hdmi_encoder_mode_valid,
        .disable = vc4_hdmi_encoder_disable,
        .enable = vc4_hdmi_encoder_enable,
  };
index df9807a3caaea4d9f77e0797e594f3a8b12ddd11,1543212b044963622a45b577c3b0c07986ee3b5d..66d6c99d15e56449c8d1693c24668bb345b004f5
@@@ -269,6 -269,11 +269,11 @@@ struct drm_display_info 
         */
        bool dvi_dual;
  
+       /**
+        * @has_hdmi_infoframe: Does the sink support the HDMI infoframe?
+        */
+       bool has_hdmi_infoframe;
        /**
         * @edid_hdmi_dc_modes: Mask of supported hdmi deep color modes. Even
         * more stuff redundant with @bus_formats.
         * @hdmi: advance features of a HDMI sink.
         */
        struct drm_hdmi_info hdmi;
 +
 +      /**
 +       * @non_desktop: Non desktop display (HMD).
 +       */
 +      bool non_desktop;
  };
  
  int drm_display_info_set_bus_formats(struct drm_display_info *info,
@@@ -704,7 -704,6 +709,6 @@@ struct drm_cmdline_mode 
   * @force: a DRM_FORCE_<foo> state for forced mode sets
   * @override_edid: has the EDID been overwritten through debugfs for testing?
   * @encoder_ids: valid encoders for this connector
-  * @encoder: encoder driving this connector, if any
   * @eld: EDID-like data, if present
   * @latency_present: AV delay info from ELD, if found
   * @video_latency: video latency info from ELD, if found
@@@ -874,7 -873,13 +878,13 @@@ struct drm_connector 
  
  #define DRM_CONNECTOR_MAX_ENCODER 3
        uint32_t encoder_ids[DRM_CONNECTOR_MAX_ENCODER];
-       struct drm_encoder *encoder; /* currently active encoder */
+       /**
+        * @encoder: Currently bound encoder driving this connector, if any.
+        * Only really meaningful for non-atomic drivers. Atomic drivers should
+        * instead look at &drm_connector_state.best_encoder, and in case they
+        * need the CRTC driving this output, &drm_connector_state.crtc.
+        */
+       struct drm_encoder *encoder;
  
  #define MAX_ELD_BYTES 128
        /* EDID bits */
index 2623a1255481651ce6d3858fa2d3f00906d49971,9049ef133d692536c175a11fb56e3f3ef7585260..da58a428c8d725475751c4fef7b5a2c4dcbbac1e
  # define DP_ADJUST_PRE_EMPHASIS_LANE1_MASK   0xc0
  # define DP_ADJUST_PRE_EMPHASIS_LANE1_SHIFT  6
  
 +#define DP_ADJUST_REQUEST_POST_CURSOR2      0x20c
 +
  #define DP_TEST_REQUEST                           0x218
  # define DP_TEST_LINK_TRAINING                    (1 << 0)
  # define DP_TEST_LINK_VIDEO_PATTERN       (1 << 1)
  
  #define DP_TEST_REFRESH_RATE_NUMERATOR      0x234
  
 +#define DP_TEST_MISC0                       0x232
 +
  #define DP_TEST_CRC_R_CR                  0x240
  #define DP_TEST_CRC_G_Y                           0x242
  #define DP_TEST_CRC_B_CB                  0x244
  # define DP_TEST_CRC_SUPPORTED                    (1 << 5)
  # define DP_TEST_COUNT_MASK               0xf
  
 +#define DP_TEST_PHY_PATTERN                 0x248
 +#define DP_TEST_80BIT_CUSTOM_PATTERN_7_0    0x250
 +#define       DP_TEST_80BIT_CUSTOM_PATTERN_15_8   0x251
 +#define       DP_TEST_80BIT_CUSTOM_PATTERN_23_16  0x252
 +#define       DP_TEST_80BIT_CUSTOM_PATTERN_31_24  0x253
 +#define       DP_TEST_80BIT_CUSTOM_PATTERN_39_32  0x254
 +#define       DP_TEST_80BIT_CUSTOM_PATTERN_47_40  0x255
 +#define       DP_TEST_80BIT_CUSTOM_PATTERN_55_48  0x256
 +#define       DP_TEST_80BIT_CUSTOM_PATTERN_63_56  0x257
 +#define       DP_TEST_80BIT_CUSTOM_PATTERN_71_64  0x258
 +#define       DP_TEST_80BIT_CUSTOM_PATTERN_79_72  0x259
 +
  #define DP_TEST_RESPONSE                  0x260
  # define DP_TEST_ACK                      (1 << 0)
  # define DP_TEST_NAK                      (1 << 1)
  #define DP_SINK_OUI                       0x400
  #define DP_BRANCH_OUI                     0x500
  #define DP_BRANCH_ID                        0x503
 +#define DP_BRANCH_REVISION_START            0x509
  #define DP_BRANCH_HW_REV                    0x509
  #define DP_BRANCH_SW_REV                    0x50A
  
  # define DP_SET_POWER_D0                    0x1
  # define DP_SET_POWER_D3                    0x2
  # define DP_SET_POWER_MASK                  0x3
+ # define DP_SET_POWER_D3_AUX_ON             0x5
  
  #define DP_EDP_DPCD_REV                           0x700    /* eDP 1.2 */
  # define DP_EDP_11                        0x00
  #define DP_LANE_ALIGN_STATUS_UPDATED_ESI       0x200e /* status same as 0x204 */
  #define DP_SINK_STATUS_ESI                     0x200f /* status same as 0x205 */
  
 +#define DP_DP13_DPCD_REV                    0x2200
 +#define DP_DP13_MAX_LINK_RATE               0x2201
 +
  #define DP_DPRX_FEATURE_ENUMERATION_LIST    0x2210  /* DP 1.3 */
  # define DP_GTC_CAP                                   (1 << 0)  /* DP 1.3 */
  # define DP_SST_SPLIT_SDP_CAP                         (1 << 1)  /* DP 1.4 */
diff --combined include/drm/drm_edid.h
index 2ec41d032e560f0fa4d04ef8d23d6b3442529473,3c8740ad1db685cc7af1c2e3aa3c6e2f30b3d754..b25d12ef120a10d9cada8072a019d38d5aa17075
@@@ -333,7 -333,6 +333,6 @@@ struct drm_encoder
  struct drm_connector;
  struct drm_display_mode;
  
- void drm_edid_to_eld(struct drm_connector *connector, struct edid *edid);
  int drm_edid_to_sad(struct edid *edid, struct cea_sad **sads);
  int drm_edid_to_speaker_allocation(struct edid *edid, u8 **sadb);
  int drm_av_sync_delay(struct drm_connector *connector,
@@@ -357,13 -356,13 +356,14 @@@ drm_hdmi_avi_infoframe_from_display_mod
                                         bool is_hdmi2_sink);
  int
  drm_hdmi_vendor_infoframe_from_display_mode(struct hdmi_vendor_infoframe *frame,
+                                           struct drm_connector *connector,
                                            const struct drm_display_mode *mode);
  void
  drm_hdmi_avi_infoframe_quant_range(struct hdmi_avi_infoframe *frame,
                                   const struct drm_display_mode *mode,
                                   enum hdmi_quantization_range rgb_quant_range,
 -                                 bool rgb_quant_range_selectable);
 +                                 bool rgb_quant_range_selectable,
 +                                 bool is_hdmi2_sink);
  
  /**
   * drm_eld_mnl - Get ELD monitor name length in bytes.
index faf56c53df284def80f3b96be854851bb10d11d8,a613ff022e6cf7f2f64851655bc8c0a353d7ae57..65def43eb231dc0ac9a3abf41c2ca8c5bbcbff51
@@@ -1,4 -1,3 +1,4 @@@
 +/* SPDX-License-Identifier: GPL-2.0 */
  #ifndef __DRM_FB_CMA_HELPER_H__
  #define __DRM_FB_CMA_HELPER_H__
  
@@@ -36,11 -35,5 +36,5 @@@ dma_addr_t drm_fb_cma_get_gem_addr(stru
                                   struct drm_plane_state *state,
                                   unsigned int plane);
  
- #ifdef CONFIG_DEBUG_FS
- struct seq_file;
- int drm_fb_cma_debugfs_show(struct seq_file *m, void *arg);
- #endif
  #endif
  
index 520e3feb502c569374f5c30f69f1afdb449728b9,f191227f60c0f72f911bfb84ef01c8c452d29c88..19777145cf8ede8ff9a0272513f82fc971149345
@@@ -1,4 -1,3 +1,4 @@@
 +/* SPDX-License-Identifier: GPL-2.0 */
  #ifndef __DRM_GEM_CMA_HELPER_H__
  #define __DRM_GEM_CMA_HELPER_H__
  
@@@ -9,7 -8,9 +9,9 @@@
   * struct drm_gem_cma_object - GEM object backed by CMA memory allocations
   * @base: base GEM object
   * @paddr: physical address of the backing memory
-  * @sgt: scatter/gather table for imported PRIME buffers
+  * @sgt: scatter/gather table for imported PRIME buffers. The table can have
+  *       more than one entry but they are guaranteed to have contiguous
+  *       DMA addresses.
   * @vaddr: kernel virtual address of the backing memory
   */
  struct drm_gem_cma_object {
        void *vaddr;
  };
  
- static inline struct drm_gem_cma_object *
- to_drm_gem_cma_obj(struct drm_gem_object *gem_obj)
- {
-       return container_of(gem_obj, struct drm_gem_cma_object, base);
- }
+ #define to_drm_gem_cma_obj(gem_obj) \
+       container_of(gem_obj, struct drm_gem_cma_object, base)
  
  #ifndef CONFIG_MMU
  #define DRM_GEM_CMA_UNMAPPED_AREA_FOPS \
@@@ -91,9 -89,8 +90,8 @@@ unsigned long drm_gem_cma_get_unmapped_
                                            unsigned long flags);
  #endif
  
- #ifdef CONFIG_DEBUG_FS
- void drm_gem_cma_describe(struct drm_gem_cma_object *obj, struct seq_file *m);
- #endif
+ void drm_gem_cma_print_info(struct drm_printer *p, unsigned int indent,
+                           const struct drm_gem_object *obj);
  
  struct sg_table *drm_gem_cma_prime_get_sg_table(struct drm_gem_object *obj);
  struct drm_gem_object *
index b21e827c5c78775742533d28f3baebfd6e0a9b5e,cf73c5eaab9808790b9bf432b5c762579a99d46e..5306ebd537b2f388d494f5675b8e3942febe118c
@@@ -728,13 -728,6 +728,13 @@@ struct drm_mode_config 
         */
        struct drm_property *suggested_y_property;
  
 +      /**
 +       * @non_desktop_property: Optional connector property with a hint
 +       * that device isn't a standard display, and the console/desktop,
 +       * should not be displayed on it.
 +       */
 +      struct drm_property *non_desktop_property;
 +
        /* dumb ioctl parameters */
        uint32_t preferred_depth, prefer_shadow;
  
        bool allow_fb_modifiers;
  
        /**
-        * @modifiers: Plane property to list support modifier/format
+        * @modifiers_property: Plane property to list support modifier/format
         * combination.
         */
        struct drm_property *modifiers_property;
This page took 0.470928 seconds and 4 git commands to generate.