Merge tag 'drm-next-2022-03-24' of git://anongit.freedesktop.org/drm/drm
authorLinus Torvalds <torvalds@linux-foundation.org>
Thu, 24 Mar 2022 23:19:43 +0000 (16:19 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 24 Mar 2022 23:19:43 +0000 (16:19 -0700)
Pull drm updates from Dave Airlie:
 "Lots of work all over, Intel improving DG2 support, amdkfd CRIU
  support, msm new hw support, and faster fbdev support.

  dma-buf:
   - rename dma-buf-map to iosys-map

  core:
   - move buddy allocator to core
   - add pci/platform init macros
   - improve EDID parser deep color handling
   - EDID timing type 7 support
   - add GPD Win Max quirk
   - add yes/no helpers to string_helpers
   - flatten syncobj chains
   - add nomodeset support to lots of drivers
   - improve fb-helper clipping support
   - add default property value interface

  fbdev:
   - improve fbdev ops speed

  ttm:
   - add a backpointer from ttm bo->ttm resource

  dp:
   - move displayport headers
   - add a dp helper module

  bridge:
   - anx7625 atomic support, HDCP support

  panel:
   - split out panel-lvds and lvds bindings
   - find panels in OF subnodes

  privacy:
   - add chromeos privacy screen support

  fb:
   - hot unplug fw fb on forced removal

  simpledrm:
   - request region instead of marking ioresource busy
   - add panel oreintation property

  udmabuf:
   - fix oops with 0 pages

  amdgpu:
   - power management code cleanup
   - Enable freesync video mode by default
   - RAS code cleanup
   - Improve VRAM access for debug using SDMA
   - SR-IOV rework special register access and fixes
   - profiling power state request ioctl
   - expose IP discovery via sysfs
   - Cyan skillfish updates
   - GC 10.3.7, SDMA 5.2.7, DCN 3.1.6 updates
   - expose benchmark tests via debugfs
   - add module param to disable XGMI for testing
   - GPU reset debugfs register dumping support

  amdkfd:
   - CRIU support
   - SDMA queue fixes

  radeon:
   - UVD suspend fix
   - iMac backlight fix

  i915:
   - minimal parallel submission for execlists
   - DG2-G12 subplatform added
   - DG2 programming workarounds
   - DG2 accelerated migration support
   - flat CCS and CCS engine support for XeHP
   - initial small BAR support
   - drop fake LMEM support
   - ADL-N PCH support
   - bigjoiner updates
   - introduce VMA resources and async unbinding
   - register definitions cleanups
   - multi-FBC refactoring
   - DG1 OPROM over SPI support
   - ADL-N platform enabling
   - opregion mailbox #5 support
   - DP MST ESI improvements
   - drm device based logging
   - async flip optimisation for DG2
   - CPU arch abstraction fixes
   - improve GuC ADS init to work on aarch64
   - tweak TTM LRU priority hint
   - GuC 69.0.3 support
   - remove short term execbuf pins

  nouveau:
   - higher DP/eDP bitrates
   - backlight fixes

  msm:
   - dpu + dp support for sc8180x
   - dp support for sm8350
   - dpu + dsi support for qcm2290
   - 10nm dsi phy tuning support
   - bridge support for dp encoder
   - gpu support for additional 7c3 SKUs

  ingenic:
   - HDMI support for JZ4780
   - aux channel EDID support

  ast:
   - AST2600 support
   - add wide screen support
   - create DP/DVI connectors

  omapdrm:
   - fix implicit dma_buf fencing

  vc4:
   - add CSC + full range support
   - better display firmware handoff

  panfrost:
   - add initial dual-core GPU support

  stm:
   - new revision support
   - fb handover support

  mediatek:
   - transfer display binding document to yaml format.
   - add mt8195 display device binding.
   - allow commands to be sent during video mode.
   - add wait_for_event for crtc disable by cmdq.

  tegra:
   - YUV format support

  rcar-du:
   - LVDS support for M3-W+ (R8A77961)

  exynos:
   - BGR pixel format for FIMD device"

* tag 'drm-next-2022-03-24' of git://anongit.freedesktop.org/drm/drm: (1529 commits)
  drm/i915/display: Do not re-enable PSR after it was marked as not reliable
  drm/i915/display: Fix HPD short pulse handling for eDP
  drm/amdgpu: Use drm_mode_copy()
  drm/radeon: Use drm_mode_copy()
  drm/amdgpu: Use ternary operator in `vcn_v1_0_start()`
  drm/amdgpu: Remove pointless on stack mode copies
  drm/amd/pm: fix indenting in __smu_cmn_reg_print_error()
  drm/amdgpu/dc: fix typos in comments
  drm/amdgpu: fix typos in comments
  drm/amd/pm: fix typos in comments
  drm/amdgpu: Add stolen reserved memory for MI25 SRIOV.
  drm/amdgpu: Merge get_reserved_allocation to get_vbios_allocations.
  drm/amdkfd: evict svm bo worker handle error
  drm/amdgpu/vcn: fix vcn ring test failure in igt reload test
  drm/amdgpu: only allow secure submission on rings which support that
  drm/amdgpu: fixed the warnings reported by kernel test robot
  drm/amd/display: 3.2.177
  drm/amd/display: [FW Promotion] Release 0.0.108.0
  drm/amd/display: Add save/restore PANEL_PWRSEQ_REF_DIV2
  drm/amd/display: Wait for hubp read line for Pollock
  ...

30 files changed:
1  2 
Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml
Documentation/devicetree/bindings/display/mediatek/mediatek,ovl-2l.yaml
Documentation/devicetree/bindings/display/mediatek/mediatek,ovl.yaml
Documentation/devicetree/bindings/display/mediatek/mediatek,rdma.yaml
Documentation/devicetree/bindings/display/mediatek/mediatek,wdma.yaml
MAINTAINERS
drivers/gpu/drm/amd/amdkfd/kfd_migrate.c
drivers/gpu/drm/amd/amdkfd/kfd_priv.h
drivers/gpu/drm/bridge/Kconfig
drivers/gpu/drm/bridge/ti-sn65dsi86.c
drivers/gpu/drm/drm_cache.c
drivers/gpu/drm/i915/display/intel_psr.c
drivers/gpu/drm/i915/gt/uc/intel_guc_ads.c
drivers/gpu/drm/i915/i915_reg.h
drivers/gpu/drm/i915/intel_pch.c
drivers/gpu/drm/i915/intel_pch.h
drivers/gpu/drm/mediatek/mtk_drm_crtc.c
drivers/gpu/drm/mediatek/mtk_drm_drv.c
drivers/gpu/drm/nouveau/nouveau_svm.c
drivers/gpu/drm/panel/Kconfig
drivers/gpu/drm/panel/panel-simple.c
drivers/gpu/drm/rockchip/cdn-dp-core.c
drivers/gpu/drm/rockchip/cdn-dp-core.h
drivers/gpu/drm/tiny/panel-mipi-dbi.c
drivers/gpu/drm/tiny/repaper.c
drivers/media/common/videobuf2/videobuf2-dma-contig.c
drivers/video/fbdev/core/fb_defio.c
drivers/video/fbdev/core/fbmem.c
drivers/video/fbdev/s3c-fb.c
drivers/video/fbdev/udlfb.c

index 0000000,611a2db..e3cef99
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,88 +1,78 @@@
 -  mediatek,larb:
 -    description:
 -      This property should contain a phandle pointing to the local arbiter devices defined in
 -      Documentation/devicetree/bindings/memory-controllers/mediatek,smi-larb.yaml.
 -      It must sort according to the local arbiter index, like larb0, larb1, larb2...
 -    $ref: /schemas/types.yaml#/definitions/phandle-array
 -    minItems: 1
 -    maxItems: 32
 -
+ # SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+ %YAML 1.2
+ ---
+ $id: http://devicetree.org/schemas/display/mediatek/mediatek,ovl-2l.yaml#
+ $schema: http://devicetree.org/meta-schemas/core.yaml#
+ title: Mediatek display overlay 2 layer
+ maintainers:
+   - Chun-Kuang Hu <chunkuang.hu@kernel.org>
+   - Philipp Zabel <p.zabel@pengutronix.de>
+ description: |
+   Mediatek display overlay 2 layer, namely OVL-2L, provides 2 more layer
+   for OVL.
+   OVL-2L device node must be siblings to the central MMSYS_CONFIG node.
+   For a description of the MMSYS_CONFIG binding, see
+   Documentation/devicetree/bindings/arm/mediatek/mediatek,mmsys.yaml
+   for details.
+ properties:
+   compatible:
+     oneOf:
+       - items:
+           - const: mediatek,mt8183-disp-ovl-2l
+       - items:
+           - const: mediatek,mt8192-disp-ovl-2l
+   reg:
+     maxItems: 1
+   interrupts:
+     maxItems: 1
+   power-domains:
+     description: A phandle and PM domain specifier as defined by bindings of
+       the power controller specified by phandle. See
+       Documentation/devicetree/bindings/power/power-domain.yaml for details.
+   clocks:
+     items:
+       - description: OVL-2L Clock
+   iommus:
+     description:
+       This property should point to the respective IOMMU block with master port as argument,
+       see Documentation/devicetree/bindings/iommu/mediatek,iommu.yaml for details.
 -        mediatek,larb = <&larb0>;
+   mediatek,gce-client-reg:
+     description: The register of client driver can be configured by gce with
+       4 arguments defined in this property, such as phandle of gce, subsys id,
+       register offset and size. Each GCE subsys id is mapping to a client
+       defined in the header include/dt-bindings/gce/<chip>-gce.h.
+     $ref: /schemas/types.yaml#/definitions/phandle-array
+     maxItems: 1
+ required:
+   - compatible
+   - reg
+   - interrupts
+   - power-domains
+   - clocks
+   - iommus
+ additionalProperties: false
+ examples:
+   - |
+     ovl_2l0: ovl@14009000 {
+         compatible = "mediatek,mt8183-disp-ovl-2l";
+         reg = <0 0x14009000 0 0x1000>;
+         interrupts = <GIC_SPI 226 IRQ_TYPE_LEVEL_LOW>;
+         power-domains = <&spm MT8183_POWER_DOMAIN_DISP>;
+         clocks = <&mmsys CLK_MM_DISP_OVL0_2L>;
+         iommus = <&iommu M4U_PORT_DISP_2L_OVL0_LARB0>;
+         mediatek,gce-client-reg = <&gce SUBSYS_1400XXXX 0x9000 0x1000>;
+     };
index 0000000,e71f79b..93d5c68
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,103 +1,93 @@@
 -  mediatek,larb:
 -    description:
 -      This property should contain a phandle pointing to the local arbiter devices defined in
 -      Documentation/devicetree/bindings/memory-controllers/mediatek,smi-larb.yaml.
 -      It must sort according to the local arbiter index, like larb0, larb1, larb2...
 -    $ref: /schemas/types.yaml#/definitions/phandle-array
 -    minItems: 1
 -    maxItems: 32
 -
+ # SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+ %YAML 1.2
+ ---
+ $id: http://devicetree.org/schemas/display/mediatek/mediatek,ovl.yaml#
+ $schema: http://devicetree.org/meta-schemas/core.yaml#
+ title: Mediatek display overlay
+ maintainers:
+   - Chun-Kuang Hu <chunkuang.hu@kernel.org>
+   - Philipp Zabel <p.zabel@pengutronix.de>
+ description: |
+   Mediatek display overlay, namely OVL, can do alpha blending from
+   the memory.
+   OVL device node must be siblings to the central MMSYS_CONFIG node.
+   For a description of the MMSYS_CONFIG binding, see
+   Documentation/devicetree/bindings/arm/mediatek/mediatek,mmsys.yaml
+   for details.
+ properties:
+   compatible:
+     oneOf:
+       - items:
+           - const: mediatek,mt2701-disp-ovl
+       - items:
+           - const: mediatek,mt8173-disp-ovl
+       - items:
+           - const: mediatek,mt8183-disp-ovl
+       - items:
+           - const: mediatek,mt8192-disp-ovl
+       - items:
+           - enum:
+               - mediatek,mt7623-disp-ovl
+               - mediatek,mt2712-disp-ovl
+           - enum:
+               - mediatek,mt2701-disp-ovl
+       - items:
+           - enum:
+               - mediatek,mt8195-disp-ovl
+           - enum:
+               - mediatek,mt8183-disp-ovl
+   reg:
+     maxItems: 1
+   interrupts:
+     maxItems: 1
+   power-domains:
+     description: A phandle and PM domain specifier as defined by bindings of
+       the power controller specified by phandle. See
+       Documentation/devicetree/bindings/power/power-domain.yaml for details.
+   clocks:
+     items:
+       - description: OVL Clock
+   iommus:
+     description:
+       This property should point to the respective IOMMU block with master port as argument,
+       see Documentation/devicetree/bindings/iommu/mediatek,iommu.yaml for details.
 -        mediatek,larb = <&larb0>;
+   mediatek,gce-client-reg:
+     description: The register of client driver can be configured by gce with
+       4 arguments defined in this property, such as phandle of gce, subsys id,
+       register offset and size. Each GCE subsys id is mapping to a client
+       defined in the header include/dt-bindings/gce/<chip>-gce.h.
+     $ref: /schemas/types.yaml#/definitions/phandle-array
+     maxItems: 1
+ required:
+   - compatible
+   - reg
+   - interrupts
+   - power-domains
+   - clocks
+   - iommu
+ additionalProperties: false
+ examples:
+   - |
+     ovl0: ovl@1400c000 {
+         compatible = "mediatek,mt8173-disp-ovl";
+         reg = <0 0x1400c000 0 0x1000>;
+         interrupts = <GIC_SPI 180 IRQ_TYPE_LEVEL_LOW>;
+         power-domains = <&scpsys MT8173_POWER_DOMAIN_MM>;
+         clocks = <&mmsys CLK_MM_DISP_OVL0>;
+         iommus = <&iommu M4U_PORT_DISP_OVL0>;
+         mediatek,gce-client-reg = <&gce SUBSYS_1400XXXX 0xc000 0x1000>;
+     };
index 0000000,8ef8216..b56e22f
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,117 +1,107 @@@
 -  mediatek,larb:
 -    description:
 -      This property should contain a phandle pointing to the local arbiter devices defined in
 -      Documentation/devicetree/bindings/memory-controllers/mediatek,smi-larb.yaml.
 -      It must sort according to the local arbiter index, like larb0, larb1, larb2...
 -    $ref: /schemas/types.yaml#/definitions/phandle-array
 -    minItems: 1
 -    maxItems: 32
 -
+ # SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+ %YAML 1.2
+ ---
+ $id: http://devicetree.org/schemas/display/mediatek/mediatek,rdma.yaml#
+ $schema: http://devicetree.org/meta-schemas/core.yaml#
+ title: Mediatek Read Direct Memory Access
+ maintainers:
+   - Chun-Kuang Hu <chunkuang.hu@kernel.org>
+   - Philipp Zabel <p.zabel@pengutronix.de>
+ description: |
+   Mediatek Read Direct Memory Access(RDMA) component used to read the
+   data into DMA. It provides real time data to the back-end panel
+   driver, such as DSI, DPI and DP_INTF.
+   It contains one line buffer to store the sufficient pixel data.
+   RDMA device node must be siblings to the central MMSYS_CONFIG node.
+   For a description of the MMSYS_CONFIG binding, see
+   Documentation/devicetree/bindings/arm/mediatek/mediatek,mmsys.yaml
+   for details.
+ properties:
+   compatible:
+     oneOf:
+       - items:
+           - const: mediatek,mt2701-disp-rdma
+       - items:
+           - const: mediatek,mt8173-disp-rdma
+       - items:
+           - const: mediatek,mt8183-disp-rdma
+       - items:
+           - const: mediatek,mt8195-disp-rdma
+       - items:
+           - enum:
+               - mediatek,mt7623-disp-rdma
+               - mediatek,mt2712-disp-rdma
+           - enum:
+               - mediatek,mt2701-disp-rdma
+       - items:
+           - enum:
+               - mediatek,mt8192-disp-rdma
+           - enum:
+               - mediatek,mt8183-disp-rdma
+   reg:
+     maxItems: 1
+   interrupts:
+     maxItems: 1
+   power-domains:
+     description: A phandle and PM domain specifier as defined by bindings of
+       the power controller specified by phandle. See
+       Documentation/devicetree/bindings/power/power-domain.yaml for details.
+   clocks:
+     items:
+       - description: RDMA Clock
+   iommus:
+     description:
+       This property should point to the respective IOMMU block with master port as argument,
+       see Documentation/devicetree/bindings/iommu/mediatek,iommu.yaml for details.
 -        mediatek,larb = <&larb0>;
+   mediatek,rdma-fifo-size:
+     description:
+       rdma fifo size may be different even in same SOC, add this property to the
+       corresponding rdma.
+       The value below is the Max value which defined in hardware data sheet
+       mediatek,rdma-fifo-size of mt8173-rdma0 is 8K
+       mediatek,rdma-fifo-size of mt8183-rdma0 is 5K
+       mediatek,rdma-fifo-size of mt8183-rdma1 is 2K
+     $ref: /schemas/types.yaml#/definitions/uint32
+     enum: [8192, 5120, 2048]
+   mediatek,gce-client-reg:
+     description: The register of client driver can be configured by gce with
+       4 arguments defined in this property, such as phandle of gce, subsys id,
+       register offset and size. Each GCE subsys id is mapping to a client
+       defined in the header include/dt-bindings/gce/<chip>-gce.h.
+     $ref: /schemas/types.yaml#/definitions/phandle-array
+     maxItems: 1
+ required:
+   - compatible
+   - reg
+   - interrupts
+   - power-domains
+   - clocks
+   - iommus
+ additionalProperties: false
+ examples:
+   - |
+     rdma0: rdma@1400e000 {
+         compatible = "mediatek,mt8173-disp-rdma";
+         reg = <0 0x1400e000 0 0x1000>;
+         interrupts = <GIC_SPI 182 IRQ_TYPE_LEVEL_LOW>;
+         power-domains = <&scpsys MT8173_POWER_DOMAIN_MM>;
+         clocks = <&mmsys CLK_MM_DISP_RDMA0>;
+         iommus = <&iommu M4U_PORT_DISP_RDMA0>;
+         mediatek,rdma-fifosize = <8192>;
+         mediatek,gce-client-reg = <&gce SUBSYS_1400XXXX 0xe000 0x1000>;
+     };
index 0000000,aaf5649..f9f00a5
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,86 +1,76 @@@
 -  mediatek,larb:
 -    description:
 -      This property should contain a phandle pointing to the local arbiter devices defined in
 -      Documentation/devicetree/bindings/memory-controllers/mediatek,smi-larb.yaml.
 -      It must sort according to the local arbiter index, like larb0, larb1, larb2...
 -    $ref: /schemas/types.yaml#/definitions/phandle-array
 -    minItems: 1
 -    maxItems: 32
 -
+ # SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+ %YAML 1.2
+ ---
+ $id: http://devicetree.org/schemas/display/mediatek/mediatek,wdma.yaml#
+ $schema: http://devicetree.org/meta-schemas/core.yaml#
+ title: Mediatek Write Direct Memory Access
+ maintainers:
+   - Chun-Kuang Hu <chunkuang.hu@kernel.org>
+   - Philipp Zabel <p.zabel@pengutronix.de>
+ description: |
+   Mediatek Write Direct Memory Access(WDMA) component used to write
+   the data into DMA.
+   WDMA device node must be siblings to the central MMSYS_CONFIG node.
+   For a description of the MMSYS_CONFIG binding, see
+   Documentation/devicetree/bindings/arm/mediatek/mediatek,mmsys.yaml
+   for details.
+ properties:
+   compatible:
+     oneOf:
+       - items:
+           - const: mediatek,mt8173-disp-wdma
+   reg:
+     maxItems: 1
+   interrupts:
+     maxItems: 1
+   power-domains:
+     description: A phandle and PM domain specifier as defined by bindings of
+       the power controller specified by phandle. See
+       Documentation/devicetree/bindings/power/power-domain.yaml for details.
+   clocks:
+     items:
+       - description: WDMA Clock
+   iommus:
+     description:
+       This property should point to the respective IOMMU block with master port as argument,
+       see Documentation/devicetree/bindings/iommu/mediatek,iommu.yaml for details.
 -        mediatek,larb = <&larb0>;
+   mediatek,gce-client-reg:
+     description: The register of client driver can be configured by gce with
+       4 arguments defined in this property, such as phandle of gce, subsys id,
+       register offset and size. Each GCE subsys id is mapping to a client
+       defined in the header include/dt-bindings/gce/<chip>-gce.h.
+     $ref: /schemas/types.yaml#/definitions/phandle-array
+     maxItems: 1
+ required:
+   - compatible
+   - reg
+   - interrupts
+   - power-domains
+   - clocks
+   - iommus
+ additionalProperties: false
+ examples:
+   - |
+     wdma0: wdma@14011000 {
+         compatible = "mediatek,mt8173-disp-wdma";
+         reg = <0 0x14011000 0 0x1000>;
+         interrupts = <GIC_SPI 185 IRQ_TYPE_LEVEL_LOW>;
+         power-domains = <&scpsys MT8173_POWER_DOMAIN_MM>;
+         clocks = <&mmsys CLK_MM_DISP_WDMA0>;
+         iommus = <&iommu M4U_PORT_DISP_WDMA0>;
+         mediatek,gce-client-reg = <&gce SUBSYS_1401XXXX 0x1000 0x1000>;
+     };
diff --cc MAINTAINERS
Simple merge
Simple merge
Simple merge
Simple merge
  /*
   * Authors: Thomas Hellström <thomas-at-tungstengraphics-dot-com>
   */
- #include <linux/dma-buf-map.h>
 -
+ #include <linux/cc_platform.h>
  #include <linux/export.h>
  #include <linux/highmem.h>
- #include <linux/cc_platform.h>
 +#include <linux/ioport.h>
+ #include <linux/iosys-map.h>
  #include <xen/xen.h>
  
  #include <drm/drm_cache.h>
@@@ -51,9 -57,22 +57,22 @@@ struct __guc_ads_blob 
        struct guc_gt_system_info system_info;
        struct guc_engine_usage engine_usage;
        /* From here on, location is dynamic! Refer to above diagram. */
 -      struct guc_mmio_reg regset[0];
 +      struct guc_mmio_reg regset[];
  } __packed;
  
+ #define ads_blob_read(guc_, field_)                                   \
+       iosys_map_rd_field(&(guc_)->ads_map, 0, struct __guc_ads_blob, field_)
+ #define ads_blob_write(guc_, field_, val_)                            \
+       iosys_map_wr_field(&(guc_)->ads_map, 0, struct __guc_ads_blob,  \
+                          field_, val_)
+ #define info_map_write(map_, field_, val_) \
+       iosys_map_wr_field(map_, 0, struct guc_gt_system_info, field_, val_)
+ #define info_map_read(map_, field_) \
+       iosys_map_rd_field(map_, 0, struct guc_gt_system_info, field_)
  static u32 guc_ads_regset_size(struct intel_guc *guc)
  {
        GEM_BUG_ON(!guc->ads_regset_size);
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
@@@ -7,10 -7,9 +7,10 @@@
  #ifndef _CDN_DP_CORE_H
  #define _CDN_DP_CORE_H
  
- #include <drm/drm_dp_helper.h>
+ #include <drm/dp/drm_dp_helper.h>
  #include <drm/drm_panel.h>
  #include <drm/drm_probe_helper.h>
 +#include <sound/hdmi-codec.h>
  
  #include "rockchip_drm_drv.h"
  
index 0000000,7f8c6c5..c759ff9
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,398 +1,396 @@@
 -static int panel_mipi_dbi_spi_remove(struct spi_device *spi)
+ // SPDX-License-Identifier: GPL-2.0
+ /*
+  * DRM driver for MIPI DBI compatible display panels
+  *
+  * Copyright 2022 Noralf Trønnes
+  */
+ #include <linux/backlight.h>
+ #include <linux/delay.h>
+ #include <linux/firmware.h>
+ #include <linux/gpio/consumer.h>
+ #include <linux/module.h>
+ #include <linux/property.h>
+ #include <linux/regulator/consumer.h>
+ #include <linux/spi/spi.h>
+ #include <drm/drm_atomic_helper.h>
+ #include <drm/drm_drv.h>
+ #include <drm/drm_fb_helper.h>
+ #include <drm/drm_gem_atomic_helper.h>
+ #include <drm/drm_gem_cma_helper.h>
+ #include <drm/drm_managed.h>
+ #include <drm/drm_mipi_dbi.h>
+ #include <drm/drm_modes.h>
+ #include <drm/drm_modeset_helper.h>
+ #include <video/mipi_display.h>
+ static const u8 panel_mipi_dbi_magic[15] = { 'M', 'I', 'P', 'I', ' ', 'D', 'B', 'I',
+                                            0, 0, 0, 0, 0, 0, 0 };
+ /*
+  * The display controller configuration is stored in a firmware file.
+  * The Device Tree 'compatible' property value with a '.bin' suffix is passed
+  * to request_firmware() to fetch this file.
+  */
+ struct panel_mipi_dbi_config {
+       /* Magic string: panel_mipi_dbi_magic */
+       u8 magic[15];
+       /* Config file format version */
+       u8 file_format_version;
+       /*
+        * MIPI commands to execute when the display pipeline is enabled.
+        * This is used to configure the display controller.
+        *
+        * The commands are stored in a byte array with the format:
+        *     command, num_parameters, [ parameter, ...], command, ...
+        *
+        * Some commands require a pause before the next command can be received.
+        * Inserting a delay in the command sequence is done by using the NOP command with one
+        * parameter: delay in miliseconds (the No Operation command is part of the MIPI Display
+        * Command Set where it has no parameters).
+        *
+        * Example:
+        *     command 0x11
+        *     sleep 120ms
+        *     command 0xb1 parameters 0x01, 0x2c, 0x2d
+        *     command 0x29
+        *
+        * Byte sequence:
+        *     0x11 0x00
+        *     0x00 0x01 0x78
+        *     0xb1 0x03 0x01 0x2c 0x2d
+        *     0x29 0x00
+        */
+       u8 commands[];
+ };
+ struct panel_mipi_dbi_commands {
+       const u8 *buf;
+       size_t len;
+ };
+ static struct panel_mipi_dbi_commands *
+ panel_mipi_dbi_check_commands(struct device *dev, const struct firmware *fw)
+ {
+       const struct panel_mipi_dbi_config *config = (struct panel_mipi_dbi_config *)fw->data;
+       struct panel_mipi_dbi_commands *commands;
+       size_t size = fw->size, commands_len;
+       unsigned int i = 0;
+       if (size < sizeof(*config) + 2) { /* At least 1 command */
+               dev_err(dev, "config: file size=%zu is too small\n", size);
+               return ERR_PTR(-EINVAL);
+       }
+       if (memcmp(config->magic, panel_mipi_dbi_magic, sizeof(config->magic))) {
+               dev_err(dev, "config: Bad magic: %15ph\n", config->magic);
+               return ERR_PTR(-EINVAL);
+       }
+       if (config->file_format_version != 1) {
+               dev_err(dev, "config: version=%u is not supported\n", config->file_format_version);
+               return ERR_PTR(-EINVAL);
+       }
+       drm_dev_dbg(dev, DRM_UT_DRIVER, "size=%zu version=%u\n", size, config->file_format_version);
+       commands_len = size - sizeof(*config);
+       while ((i + 1) < commands_len) {
+               u8 command = config->commands[i++];
+               u8 num_parameters = config->commands[i++];
+               const u8 *parameters = &config->commands[i];
+               i += num_parameters;
+               if (i > commands_len) {
+                       dev_err(dev, "config: command=0x%02x num_parameters=%u overflows\n",
+                               command, num_parameters);
+                       return ERR_PTR(-EINVAL);
+               }
+               if (command == 0x00 && num_parameters == 1)
+                       drm_dev_dbg(dev, DRM_UT_DRIVER, "sleep %ums\n", parameters[0]);
+               else
+                       drm_dev_dbg(dev, DRM_UT_DRIVER, "command %02x %*ph\n",
+                                   command, num_parameters, parameters);
+       }
+       if (i != commands_len) {
+               dev_err(dev, "config: malformed command array\n");
+               return ERR_PTR(-EINVAL);
+       }
+       commands = devm_kzalloc(dev, sizeof(*commands), GFP_KERNEL);
+       if (!commands)
+               return ERR_PTR(-ENOMEM);
+       commands->len = commands_len;
+       commands->buf = devm_kmemdup(dev, config->commands, commands->len, GFP_KERNEL);
+       if (!commands->buf)
+               return ERR_PTR(-ENOMEM);
+       return commands;
+ }
+ static struct panel_mipi_dbi_commands *panel_mipi_dbi_commands_from_fw(struct device *dev)
+ {
+       struct panel_mipi_dbi_commands *commands;
+       const struct firmware *fw;
+       const char *compatible;
+       char fw_name[40];
+       int ret;
+       ret = of_property_read_string_index(dev->of_node, "compatible", 0, &compatible);
+       if (ret)
+               return ERR_PTR(ret);
+       snprintf(fw_name, sizeof(fw_name), "%s.bin", compatible);
+       ret = request_firmware(&fw, fw_name, dev);
+       if (ret) {
+               dev_err(dev, "No config file found for compatible '%s' (error=%d)\n",
+                       compatible, ret);
+               return ERR_PTR(ret);
+       }
+       commands = panel_mipi_dbi_check_commands(dev, fw);
+       release_firmware(fw);
+       return commands;
+ }
+ static void panel_mipi_dbi_commands_execute(struct mipi_dbi *dbi,
+                                           struct panel_mipi_dbi_commands *commands)
+ {
+       unsigned int i = 0;
+       if (!commands)
+               return;
+       while (i < commands->len) {
+               u8 command = commands->buf[i++];
+               u8 num_parameters = commands->buf[i++];
+               const u8 *parameters = &commands->buf[i];
+               if (command == 0x00 && num_parameters == 1)
+                       msleep(parameters[0]);
+               else if (num_parameters)
+                       mipi_dbi_command_stackbuf(dbi, command, parameters, num_parameters);
+               else
+                       mipi_dbi_command(dbi, command);
+               i += num_parameters;
+       }
+ }
+ static void panel_mipi_dbi_enable(struct drm_simple_display_pipe *pipe,
+                                 struct drm_crtc_state *crtc_state,
+                                 struct drm_plane_state *plane_state)
+ {
+       struct mipi_dbi_dev *dbidev = drm_to_mipi_dbi_dev(pipe->crtc.dev);
+       struct mipi_dbi *dbi = &dbidev->dbi;
+       int ret, idx;
+       if (!drm_dev_enter(pipe->crtc.dev, &idx))
+               return;
+       drm_dbg(pipe->crtc.dev, "\n");
+       ret = mipi_dbi_poweron_conditional_reset(dbidev);
+       if (ret < 0)
+               goto out_exit;
+       if (!ret)
+               panel_mipi_dbi_commands_execute(dbi, dbidev->driver_private);
+       mipi_dbi_enable_flush(dbidev, crtc_state, plane_state);
+ out_exit:
+       drm_dev_exit(idx);
+ }
+ static const struct drm_simple_display_pipe_funcs panel_mipi_dbi_pipe_funcs = {
+       .enable = panel_mipi_dbi_enable,
+       .disable = mipi_dbi_pipe_disable,
+       .update = mipi_dbi_pipe_update,
+ };
+ DEFINE_DRM_GEM_CMA_FOPS(panel_mipi_dbi_fops);
+ static const struct drm_driver panel_mipi_dbi_driver = {
+       .driver_features        = DRIVER_GEM | DRIVER_MODESET | DRIVER_ATOMIC,
+       .fops                   = &panel_mipi_dbi_fops,
+       DRM_GEM_CMA_DRIVER_OPS_VMAP,
+       .debugfs_init           = mipi_dbi_debugfs_init,
+       .name                   = "panel-mipi-dbi",
+       .desc                   = "MIPI DBI compatible display panel",
+       .date                   = "20220103",
+       .major                  = 1,
+       .minor                  = 0,
+ };
+ static int panel_mipi_dbi_get_mode(struct mipi_dbi_dev *dbidev, struct drm_display_mode *mode)
+ {
+       struct device *dev = dbidev->drm.dev;
+       u16 hback_porch, vback_porch;
+       int ret;
+       ret = of_get_drm_panel_display_mode(dev->of_node, mode, NULL);
+       if (ret) {
+               dev_err(dev, "%pOF: failed to get panel-timing (error=%d)\n", dev->of_node, ret);
+               return ret;
+       }
+       mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
+       hback_porch = mode->htotal - mode->hsync_end;
+       vback_porch = mode->vtotal - mode->vsync_end;
+       /*
+        * Make sure width and height are set and that only back porch and
+        * pixelclock are set in the other timing values. Also check that
+        * width and height don't exceed the 16-bit value specified by MIPI DCS.
+        */
+       if (!mode->hdisplay || !mode->vdisplay || mode->flags ||
+           mode->hsync_end > mode->hdisplay || (hback_porch + mode->hdisplay) > 0xffff ||
+           mode->vsync_end > mode->vdisplay || (vback_porch + mode->vdisplay) > 0xffff) {
+               dev_err(dev, "%pOF: panel-timing out of bounds\n", dev->of_node);
+               return -EINVAL;
+       }
+       /* The driver doesn't use the pixel clock but it is mandatory so fake one if not set */
+       if (!mode->clock)
+               mode->clock = mode->htotal * mode->vtotal * 60 / 1000;
+       dbidev->top_offset = vback_porch;
+       dbidev->left_offset = hback_porch;
+       return 0;
+ }
+ static int panel_mipi_dbi_spi_probe(struct spi_device *spi)
+ {
+       struct device *dev = &spi->dev;
+       struct drm_display_mode mode;
+       struct mipi_dbi_dev *dbidev;
+       struct drm_device *drm;
+       struct mipi_dbi *dbi;
+       struct gpio_desc *dc;
+       int ret;
+       dbidev = devm_drm_dev_alloc(dev, &panel_mipi_dbi_driver, struct mipi_dbi_dev, drm);
+       if (IS_ERR(dbidev))
+               return PTR_ERR(dbidev);
+       dbi = &dbidev->dbi;
+       drm = &dbidev->drm;
+       ret = panel_mipi_dbi_get_mode(dbidev, &mode);
+       if (ret)
+               return ret;
+       dbidev->regulator = devm_regulator_get(dev, "power");
+       if (IS_ERR(dbidev->regulator))
+               return dev_err_probe(dev, PTR_ERR(dbidev->regulator),
+                                    "Failed to get regulator 'power'\n");
+       dbidev->backlight = devm_of_find_backlight(dev);
+       if (IS_ERR(dbidev->backlight))
+               return dev_err_probe(dev, PTR_ERR(dbidev->backlight), "Failed to get backlight\n");
+       dbi->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
+       if (IS_ERR(dbi->reset))
+               return dev_err_probe(dev, PTR_ERR(dbi->reset), "Failed to get GPIO 'reset'\n");
+       dc = devm_gpiod_get_optional(dev, "dc", GPIOD_OUT_LOW);
+       if (IS_ERR(dc))
+               return dev_err_probe(dev, PTR_ERR(dc), "Failed to get GPIO 'dc'\n");
+       ret = mipi_dbi_spi_init(spi, dbi, dc);
+       if (ret)
+               return ret;
+       if (device_property_present(dev, "write-only"))
+               dbi->read_commands = NULL;
+       dbidev->driver_private = panel_mipi_dbi_commands_from_fw(dev);
+       if (IS_ERR(dbidev->driver_private))
+               return PTR_ERR(dbidev->driver_private);
+       ret = mipi_dbi_dev_init(dbidev, &panel_mipi_dbi_pipe_funcs, &mode, 0);
+       if (ret)
+               return ret;
+       drm_mode_config_reset(drm);
+       ret = drm_dev_register(drm, 0);
+       if (ret)
+               return ret;
+       spi_set_drvdata(spi, drm);
+       drm_fbdev_generic_setup(drm, 0);
+       return 0;
+ }
 -
 -      return 0;
++static void panel_mipi_dbi_spi_remove(struct spi_device *spi)
+ {
+       struct drm_device *drm = spi_get_drvdata(spi);
+       drm_dev_unplug(drm);
+       drm_atomic_helper_shutdown(drm);
+ }
+ static void panel_mipi_dbi_spi_shutdown(struct spi_device *spi)
+ {
+       drm_atomic_helper_shutdown(spi_get_drvdata(spi));
+ }
+ static int __maybe_unused panel_mipi_dbi_pm_suspend(struct device *dev)
+ {
+       return drm_mode_config_helper_suspend(dev_get_drvdata(dev));
+ }
+ static int __maybe_unused panel_mipi_dbi_pm_resume(struct device *dev)
+ {
+       drm_mode_config_helper_resume(dev_get_drvdata(dev));
+       return 0;
+ }
+ static const struct dev_pm_ops panel_mipi_dbi_pm_ops = {
+       SET_SYSTEM_SLEEP_PM_OPS(panel_mipi_dbi_pm_suspend, panel_mipi_dbi_pm_resume)
+ };
+ static const struct of_device_id panel_mipi_dbi_spi_of_match[] = {
+       { .compatible = "panel-mipi-dbi-spi" },
+       {},
+ };
+ MODULE_DEVICE_TABLE(of, panel_mipi_dbi_spi_of_match);
+ static const struct spi_device_id panel_mipi_dbi_spi_id[] = {
+       { "panel-mipi-dbi-spi", 0 },
+       { },
+ };
+ MODULE_DEVICE_TABLE(spi, panel_mipi_dbi_spi_id);
+ static struct spi_driver panel_mipi_dbi_spi_driver = {
+       .driver = {
+               .name = "panel-mipi-dbi-spi",
+               .owner = THIS_MODULE,
+               .of_match_table = panel_mipi_dbi_spi_of_match,
+               .pm = &panel_mipi_dbi_pm_ops,
+       },
+       .id_table = panel_mipi_dbi_spi_id,
+       .probe = panel_mipi_dbi_spi_probe,
+       .remove = panel_mipi_dbi_spi_remove,
+       .shutdown = panel_mipi_dbi_spi_shutdown,
+ };
+ module_spi_driver(panel_mipi_dbi_spi_driver);
+ MODULE_DESCRIPTION("MIPI DBI compatible display panel driver");
+ MODULE_AUTHOR("Noralf Trønnes");
+ MODULE_LICENSE("GPL");
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge