RE: [PATCH v4 02/10] drm/bridge: add common api for inno hdmi

2024-05-21 Thread Keith Zhao
Hi Alex, Laurent:

I want to make as few changes as possible on the current basis, and add 
bridge_fun, 


> -Original Message-
> From: Laurent Pinchart 
> Sent: 2024年5月21日 23:42
> To: Alex Bee 
> Cc: Keith Zhao ; andrzej.ha...@intel.com;
> neil.armstr...@linaro.org; rf...@kernel.org; jo...@kwiboo.se;
> jernej.skra...@gmail.com; maarten.lankho...@linux.intel.com;
> mrip...@kernel.org; tzimmerm...@suse.de; airl...@gmail.com;
> dan...@ffwll.ch; r...@kernel.org; krzk...@kernel.org; conor...@kernel.org;
> h...@rock-chips.com; he...@sntech.de; andy@rock-chips.com; Xingyu Wu
> ; p.za...@pengutronix.de; Jack Zhu
> ; Shengyang Chen
> ; dri-devel@lists.freedesktop.org;
> devicet...@vger.kernel.org; linux-ker...@vger.kernel.org;
> linux-arm-ker...@lists.infradead.org
> Subject: Re: [PATCH v4 02/10] drm/bridge: add common api for inno hdmi
> 
> On Tue, May 21, 2024 at 05:36:43PM +0200, Alex Bee wrote:
> > Hi Keith,
> >
> > thanks a lot for working on this. See some general remarks below
> >
> > Am 21.05.24 um 12:58 schrieb keith:
> > > Add INNO common api so that it can be used by vendor drivers which
> > > implement vendor specific extensions to Innosilicon HDMI.
> > >
> > > Signed-off-by: keith 
> > > ---
> > >   MAINTAINERS   |   2 +
> > >   drivers/gpu/drm/bridge/Kconfig|   2 +
> > >   drivers/gpu/drm/bridge/Makefile   |   1 +
> > >   drivers/gpu/drm/bridge/innosilicon/Kconfig|   6 +
> > >   drivers/gpu/drm/bridge/innosilicon/Makefile   |   2 +
> > >   .../gpu/drm/bridge/innosilicon/inno-hdmi.c| 587
> ++
> > >   .../gpu/drm/bridge/innosilicon/inno-hdmi.h|  97 +++
> > >   include/drm/bridge/inno_hdmi.h|  69 ++
> > >   8 files changed, 766 insertions(+)
> > >   create mode 100644 drivers/gpu/drm/bridge/innosilicon/Kconfig
> > >   create mode 100644 drivers/gpu/drm/bridge/innosilicon/Makefile
> > >   create mode 100644 drivers/gpu/drm/bridge/innosilicon/inno-hdmi.c
> > >   create mode 100644 drivers/gpu/drm/bridge/innosilicon/inno-hdmi.h
> > >   create mode 100644 include/drm/bridge/inno_hdmi.h
> > >
> > 
> >
> > > + drm_encoder_helper_add(encoder, pdata->helper_private);
> > > +
> > > + hdmi->connector.polled = DRM_CONNECTOR_POLL_HPD;
> > > +
> > > + drm_connector_helper_add(>connector,
> > > +  _hdmi_connector_helper_funcs);
> > > +
> > > + drmm_connector_init(drm, >connector,
> > > + _hdmi_connector_funcs,
> > > + DRM_MODE_CONNECTOR_HDMIA,
> > > + hdmi->ddc);
> > > +
> >
> > I really don't want to anticipate bridge maintainer's feedback, but
> > new bridge drivers must not contain connector creation. That must
> > happen somewhere else.
> 
> You're absolutely right :-) Connector creation should be handled by the
> drm_bridge_connector helper. The HDMI bridge driver should focus on the
> HDMI bridge itself.

static int inno_bridge_attach(struct drm_bridge *bridge,
 enum drm_bridge_attach_flags flags)
{
struct inno_hdmi *hdmi = bridge_to_inno(bridge);

if (flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR) {
DRM_ERROR("Fix bridge driver to make connector optional!");
return -EINVAL;
}
hdmi->connector.polled = DRM_CONNECTOR_POLL_HPD;

drm_connector_helper_add(>connector,
 _hdmi_connector_helper_funcs);

drmm_connector_init(drm, >connector,
_hdmi_connector_funcs,
DRM_MODE_CONNECTOR_HDMIA,
hdmi->ddc);

drm_connector_attach_encoder(>connector, encoder);
}

static const struct drm_bridge_funcs inno_bridge_attach = {
.attach = inno_bridge_attach,
};

Connector creation is handled by the drm_bridge_funcs ->attach.
Is it ok?

Regards
Keith
> 
> > Also I'm neither seeing any drm_brige struct nor drm_bridge_funcs,
> > which are both essential for a bridge driver. I don't think moving a
> > part of a driver to .../drm/bridge/ makes it a bridge driver.
> >
> > > + drm_connector_attach_encoder(>connector, encoder);
> > > +
> > > + return 0;
> > > +}
> > > +
> > 
> >
> 
> --
> Regards,
> 
> Laurent Pinchart


RE: [PATCH v4 01/10] dt-bindings: display: Add YAML schema for JH7110 display pipeline

2024-05-21 Thread Keith Zhao
Hi Krzysztof:

> -Original Message-
> From: Krzysztof Kozlowski 
> Sent: 2024年5月21日 15:30
> To: Keith Zhao ; andrzej.ha...@intel.com;
> neil.armstr...@linaro.org; rf...@kernel.org;
> laurent.pinch...@ideasonboard.com; jo...@kwiboo.se;
> jernej.skra...@gmail.com; maarten.lankho...@linux.intel.com;
> mrip...@kernel.org; tzimmerm...@suse.de; airl...@gmail.com;
> dan...@ffwll.ch; r...@kernel.org; krzk...@kernel.org; conor...@kernel.org;
> h...@rock-chips.com; he...@sntech.de; andy@rock-chips.com; Xingyu Wu
> ; p.za...@pengutronix.de; Jack Zhu
> ; Shengyang Chen
> 
> Cc: dri-devel@lists.freedesktop.org; devicet...@vger.kernel.org;
> linux-ker...@vger.kernel.org; linux-arm-ker...@lists.infradead.org
> Subject: Re: [PATCH v4 01/10] dt-bindings: display: Add YAML schema for JH7110
> display pipeline
> 
> On 21/05/2024 12:58, keith wrote:
> > JH7110 SoC display pipeline includes a display controller and hdmi.
> > Dc controller IP : Vivante DC8200 Dual Display HDMI IP : INNOSILICON
> > HDMI2.0
> >
> > As the INNO hdmi ip is also used by rockchip SoC in the driver code,
> > the innosilicon,inno-hdmi.yaml schema containing the common properties
> > for the INNO DesignWare HDMI TX controller isn't a full device tree
> > binding specification, but is meant to be referenced by
> > platform-specific bindings for the IP core.
> >
> > Signed-off-by: keith 
> > ---
> >  .../display/bridge/innosilicon,inno-hdmi.yaml |  49 +
> > .../display/rockchip/rockchip,inno-hdmi.yaml  |  27 +--
> >  .../starfive/starfive,dsi-encoder.yaml|  92 ++
> >  .../starfive/starfive,jh7110-dc8200.yaml  | 169 ++
> >  .../starfive/starfive,jh7110-inno-hdmi.yaml   |  75 
> >  .../soc/starfive/starfive,jh7110-syscon.yaml  |   1 +
> >  MAINTAINERS   |   8 +
> >  7 files changed, 396 insertions(+), 25 deletions(-)  create mode
> > 100644
> > Documentation/devicetree/bindings/display/bridge/innosilicon,inno-hdmi
> > .yaml  create mode 100644
> > Documentation/devicetree/bindings/display/starfive/starfive,dsi-encode
> > r.yaml  create mode 100644
> > Documentation/devicetree/bindings/display/starfive/starfive,jh7110-dc8
> > 200.yaml  create mode 100644
> > Documentation/devicetree/bindings/display/starfive/starfive,jh7110-inn
> > o-hdmi.yaml
> >
> > diff --git
> > a/Documentation/devicetree/bindings/display/bridge/innosilicon,inno-hd
> > mi.yaml
> > b/Documentation/devicetree/bindings/display/bridge/innosilicon,inno-hd
> > mi.yaml
> > new file mode 100644
> > index ..8540174dcaeb
> > --- /dev/null
> > +++ b/Documentation/devicetree/bindings/display/bridge/innosilicon,inn
> > +++ o-hdmi.yaml
> > @@ -0,0 +1,49 @@
> > +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) %YAML 1.2
> > +---
> > +$id:
> > +http://devicetree.org/schemas/display/bridge/innosilicon,inno-hdmi.ya
> > +ml#
> > +$schema: http://devicetree.org/meta-schemas/core.yaml#
> > +
> > +title: Common Properties for Innosilicon HDMI TX IP
> 
> Your patch is difficult to review. Split changing existing bindings (and 
> defining
> common part) to a separate patch.

The background is that because the existing inno hdmi driver on the main line 
has some interfaces that can be public, 
its yaml counterpart attempts to make a public reference file
> 
> > +
> > +maintainers:
> > +  - Keith Zhao 
> > +
> > +description: |
> > +  This document defines device tree properties for the Innosilicon
> > +HDMI TX
> 
> Nothing improved here. Don't say obvious that this documents says something.
> It cannot do anything else.
> 
> "Innosilicon HDMI TX is a foo bar device present on zap SoC "
> 
> 
> > +  controller (INNO HDMI) IP core. It doesn't constitute a full device
> > + tree  binding specification by itself but is meant to be referenced
> > + by device tree  bindings for the platform-specific integrations of the 
> > INNO
> HDMI.
> 
> I don't understand this at all. I don't know what is "full device tree binding
> specification".
> 
> > +
> > +  When referenced from platform device tree bindings the properties
> > + defined in  this document are defined as follows. The platform
> > + device tree bindings are  responsible for defining whether each property 
> > is
> required or optional.
> 
> Nothing improved - drop paragraph.

These descriptions are based this file, and because their roles are close, only 
some key elements have been changed
of course, I will make co

RE: [v3 6/6] drm/vs: simple encoder

2024-05-15 Thread Keith Zhao


> -Original Message-
> From: Dmitry Baryshkov 
> Sent: 2024年5月15日 23:17
> To: Keith Zhao 
> Cc: devicet...@vger.kernel.org; dri-devel@lists.freedesktop.org;
> linux-ker...@vger.kernel.org; linux-ri...@lists.infradead.org;
> a...@eecs.berkeley.edu; suijingf...@loongson.cn; tzimmerm...@suse.de;
> paul.walms...@sifive.com; mrip...@kernel.org; Xingyu Wu
> ; Jack Zhu ;
> pal...@dabbelt.com; krzysztof.kozlowski...@linaro.org; William Qiu
> ; Shengyang Chen
> ; Changhuang Liang
> 
> Subject: Re: [v3 6/6] drm/vs: simple encoder
> 
> On Wed, May 15, 2024 at 10:07:27AM +, Keith Zhao wrote:
> >
> >
> > > -Original Message-
> > > From: Dmitry Baryshkov 
> > > Sent: 2023年12月5日 21:19
> > > To: Keith Zhao 
> > > Cc: devicet...@vger.kernel.org; dri-devel@lists.freedesktop.org;
> > > linux-ker...@vger.kernel.org; linux-ri...@lists.infradead.org;
> > > a...@eecs.berkeley.edu; suijingf...@loongson.cn; tzimmerm...@suse.de;
> > > paul.walms...@sifive.com; mrip...@kernel.org; Xingyu Wu
> > > ; Jack Zhu ;
> > > pal...@dabbelt.com; krzysztof.kozlowski...@linaro.org; William Qiu
> > > ; Shengyang Chen
> > > ; Changhuang Liang
> > > 
> > > Subject: Re: [v3 6/6] drm/vs: simple encoder
> > >
> > > On Tue, 5 Dec 2023 at 15:14, Dmitry Baryshkov
> > > 
> > > wrote:
> > > >
> > > > On Mon, 4 Dec 2023 at 14:33, Keith Zhao
> > > > 
> > > wrote:
> > > > >
> > > > > add simple encoder for dsi bridge
> > > >
> > > > This doesn't look like a proper commit message.
> > > >
> > > > >
> > > > > Signed-off-by: Keith Zhao 
> > > > > ---
> > > > >  drivers/gpu/drm/verisilicon/Makefile|   4 +-
> > > > >  drivers/gpu/drm/verisilicon/vs_drv.c|   2 +
> > > > >  drivers/gpu/drm/verisilicon/vs_simple_enc.c | 195
> > > > > 
> > > > >  drivers/gpu/drm/verisilicon/vs_simple_enc.h
> > > > >  |
> > > > > 23 +++
> > > > >  4 files changed, 223 insertions(+), 1 deletion(-)  create mode
> > > > > 100644 drivers/gpu/drm/verisilicon/vs_simple_enc.c
> > > > >  create mode 100644 drivers/gpu/drm/verisilicon/vs_simple_enc.h
> > > > >
> > > > > diff --git a/drivers/gpu/drm/verisilicon/Makefile
> > > > > b/drivers/gpu/drm/verisilicon/Makefile
> > > > > index 71fadafcee13..cd5d0a90bcfe 100644
> > > > > --- a/drivers/gpu/drm/verisilicon/Makefile
> > > > > +++ b/drivers/gpu/drm/verisilicon/Makefile
> > > > > @@ -5,6 +5,8 @@ vs_drm-objs := vs_dc_hw.o \
> > > > > vs_crtc.o \
> > > > > vs_drv.o \
> > > > > vs_modeset.o \
> > > > > -   vs_plane.o
> > > > > +   vs_plane.o \
> > > > > +   vs_simple_enc.o
> > > > > +
> > > > >  vs_drm-$(CONFIG_DRM_VERISILICON_STARFIVE_HDMI) +=
> > > starfive_hdmi.o
> > > > >  obj-$(CONFIG_DRM_VERISILICON) += vs_drm.o diff --git
> > > > > a/drivers/gpu/drm/verisilicon/vs_drv.c
> > > > > b/drivers/gpu/drm/verisilicon/vs_drv.c
> > > > > index d7e5199fe293..946f137ab124 100644
> > > > > --- a/drivers/gpu/drm/verisilicon/vs_drv.c
> > > > > +++ b/drivers/gpu/drm/verisilicon/vs_drv.c
> > > > > @@ -23,6 +23,7 @@
> > > > >  #include "vs_drv.h"
> > > > >  #include "vs_modeset.h"
> > > > >  #include "vs_dc.h"
> > > > > +#include "vs_simple_enc.h"
> > > > >
> > > > >  #define DRV_NAME   "verisilicon"
> > > > >  #define DRV_DESC   "Verisilicon DRM driver"
> > > > > @@ -217,6 +218,7 @@ static struct platform_driver
> > > > > *drm_sub_drivers[] = {  #ifdef
> CONFIG_DRM_VERISILICON_STARFIVE_HDMI
> > > > > _hdmi_driver,
> > > > >  #endif
> > > > > +   _encoder_driver,
> > > > >  };
> > > > >
> > > > >  static struct component_match *vs_drm_match_add(struct device
> > > > > *dev) diff --git a/drivers/gpu/drm/verisilicon/vs_simple_enc.c
> > > > > b/drivers/gpu/drm/verisilicon/vs_simple_enc.c
> > &

RE: [v3 6/6] drm/vs: simple encoder

2024-05-15 Thread Keith Zhao


> -Original Message-
> From: Dmitry Baryshkov 
> Sent: 2023年12月5日 21:19
> To: Keith Zhao 
> Cc: devicet...@vger.kernel.org; dri-devel@lists.freedesktop.org;
> linux-ker...@vger.kernel.org; linux-ri...@lists.infradead.org;
> a...@eecs.berkeley.edu; suijingf...@loongson.cn; tzimmerm...@suse.de;
> paul.walms...@sifive.com; mrip...@kernel.org; Xingyu Wu
> ; Jack Zhu ;
> pal...@dabbelt.com; krzysztof.kozlowski...@linaro.org; William Qiu
> ; Shengyang Chen
> ; Changhuang Liang
> 
> Subject: Re: [v3 6/6] drm/vs: simple encoder
> 
> On Tue, 5 Dec 2023 at 15:14, Dmitry Baryshkov 
> wrote:
> >
> > On Mon, 4 Dec 2023 at 14:33, Keith Zhao 
> wrote:
> > >
> > > add simple encoder for dsi bridge
> >
> > This doesn't look like a proper commit message.
> >
> > >
> > > Signed-off-by: Keith Zhao 
> > > ---
> > >  drivers/gpu/drm/verisilicon/Makefile|   4 +-
> > >  drivers/gpu/drm/verisilicon/vs_drv.c|   2 +
> > >  drivers/gpu/drm/verisilicon/vs_simple_enc.c | 195
> > >   drivers/gpu/drm/verisilicon/vs_simple_enc.h |
> > > 23 +++
> > >  4 files changed, 223 insertions(+), 1 deletion(-)  create mode
> > > 100644 drivers/gpu/drm/verisilicon/vs_simple_enc.c
> > >  create mode 100644 drivers/gpu/drm/verisilicon/vs_simple_enc.h
> > >
> > > diff --git a/drivers/gpu/drm/verisilicon/Makefile
> > > b/drivers/gpu/drm/verisilicon/Makefile
> > > index 71fadafcee13..cd5d0a90bcfe 100644
> > > --- a/drivers/gpu/drm/verisilicon/Makefile
> > > +++ b/drivers/gpu/drm/verisilicon/Makefile
> > > @@ -5,6 +5,8 @@ vs_drm-objs := vs_dc_hw.o \
> > > vs_crtc.o \
> > > vs_drv.o \
> > > vs_modeset.o \
> > > -   vs_plane.o
> > > +   vs_plane.o \
> > > +   vs_simple_enc.o
> > > +
> > >  vs_drm-$(CONFIG_DRM_VERISILICON_STARFIVE_HDMI) +=
> starfive_hdmi.o
> > >  obj-$(CONFIG_DRM_VERISILICON) += vs_drm.o diff --git
> > > a/drivers/gpu/drm/verisilicon/vs_drv.c
> > > b/drivers/gpu/drm/verisilicon/vs_drv.c
> > > index d7e5199fe293..946f137ab124 100644
> > > --- a/drivers/gpu/drm/verisilicon/vs_drv.c
> > > +++ b/drivers/gpu/drm/verisilicon/vs_drv.c
> > > @@ -23,6 +23,7 @@
> > >  #include "vs_drv.h"
> > >  #include "vs_modeset.h"
> > >  #include "vs_dc.h"
> > > +#include "vs_simple_enc.h"
> > >
> > >  #define DRV_NAME   "verisilicon"
> > >  #define DRV_DESC   "Verisilicon DRM driver"
> > > @@ -217,6 +218,7 @@ static struct platform_driver *drm_sub_drivers[]
> > > = {  #ifdef CONFIG_DRM_VERISILICON_STARFIVE_HDMI
> > > _hdmi_driver,
> > >  #endif
> > > +   _encoder_driver,
> > >  };
> > >
> > >  static struct component_match *vs_drm_match_add(struct device *dev)
> > > diff --git a/drivers/gpu/drm/verisilicon/vs_simple_enc.c
> > > b/drivers/gpu/drm/verisilicon/vs_simple_enc.c
> > > new file mode 100644
> > > index ..c5a8d82bc469
> > > --- /dev/null
> > > +++ b/drivers/gpu/drm/verisilicon/vs_simple_enc.c
> > > @@ -0,0 +1,195 @@
> > > +// SPDX-License-Identifier: GPL-2.0
> > > +/*
> > > + * Copyright (C) 2020 VeriSilicon Holdings Co., Ltd.
> > > + */
> > > +#include 
> > > +#include 
> > > +#include 
> > > +
> > > +#include 
> > > +#include 
> > > +#include 
> > > +#include 
> > > +#include 
> > > +#include  #include 
> > > +
> > > +#include "vs_crtc.h"
> > > +#include "vs_simple_enc.h"
> > > +
> > > +static const struct simple_encoder_priv dsi_priv = {
> >
> > Please use proper prefix for all the struct and function names.
> > vs_simple_encoder sounds better. Or vs_dsi_encoder.
> >
> > > +   .encoder_type = DRM_MODE_ENCODER_DSI };
> > > +
> > > +static inline struct simple_encoder *to_simple_encoder(struct
> > > +drm_encoder *enc) {
> > > +   return container_of(enc, struct simple_encoder, encoder); }
> > > +
> > > +static int encoder_parse_dt(struct device *dev) {
> > > +   struct simple_encoder *simple = dev_get_drvdata(dev);
> > > +   unsigned int args[2];
> > > +
> > > +   simple->dss_regmap =
> syscon_reg

[v3 4/6] drm/vs: Add KMS crtc

2024-01-31 Thread Keith Zhao


> -邮件原件-
> 发件人: Maxime Ripard 
> 发送时间: 2023年12月6日 16:56
> 收件人: Keith Zhao 
> 抄送: devicet...@vger.kernel.org; dri-devel@lists.freedesktop.org;
> linux-ker...@vger.kernel.org; linux-ri...@lists.infradead.org;
> tzimmerm...@suse.de; airl...@gmail.com; krzysztof.kozlowski...@linaro.org;
> William Qiu ; Xingyu Wu
> ; paul.walms...@sifive.com;
> a...@eecs.berkeley.edu; pal...@dabbelt.com; p.za...@pengutronix.de;
> Shengyang Chen ; Jack Zhu
> ; Changhuang Liang
> ; maarten.lankho...@linux.intel.com;
> suijingf...@loongson.cn
> 主题: Re: [v3 4/6] drm/vs: Add KMS crtc
> 
> On Mon, Dec 04, 2023 at 08:33:13PM +0800, Keith Zhao wrote:
> > +static const struct vs_plane_info dc_hw_planes_rev0[PLANE_NUM] = {
> > +   {
> > +   .name   = "Primary",
> > +   .id = PRIMARY_PLANE_0,
> > +   .type   = DRM_PLANE_TYPE_PRIMARY,
> > +   .num_formats= ARRAY_SIZE(primary_overlay_format0),
> > +   .formats= primary_overlay_format0,
> > +   .num_modifiers  = ARRAY_SIZE(format_modifier0),
> > +   .modifiers  = format_modifier0,
> > +   .min_width  = 0,
> > +   .min_height = 0,
> > +   .max_width  = 4096,
> > +   .max_height = 4096,
> > +   .rotation   = DRM_MODE_ROTATE_0 |
> > + DRM_MODE_ROTATE_90 |
> > + DRM_MODE_ROTATE_180 |
> > + DRM_MODE_ROTATE_270 |
> > + DRM_MODE_REFLECT_X |
> > + DRM_MODE_REFLECT_Y,
> > +   .blend_mode = BIT(DRM_MODE_BLEND_PIXEL_NONE) |
> > + BIT(DRM_MODE_BLEND_PREMULTI) |
> > + BIT(DRM_MODE_BLEND_COVERAGE),
> > +   .color_encoding = BIT(DRM_COLOR_YCBCR_BT709) |
> > + BIT(DRM_COLOR_YCBCR_BT2020),
> > +   .degamma_size   = DEGAMMA_SIZE,
> > +   .min_scale  = FRAC_16_16(1, 3),
> > +   .max_scale  = FRAC_16_16(10, 1),
> > +   .zpos   = 0,
> > +   .watermark  = true,
> > +   .color_mgmt = true,
> > +   .roi= true,
> > +   },
> > +   {
> > +   .name   = "Overlay",
> > +   .id = OVERLAY_PLANE_0,
> > +   .type   = DRM_PLANE_TYPE_OVERLAY,
> > +   .num_formats= ARRAY_SIZE(primary_overlay_format0),
> > +   .formats= primary_overlay_format0,
> > +   .num_modifiers  = ARRAY_SIZE(format_modifier0),
> > +   .modifiers  = format_modifier0,
> > +   .min_width  = 0,
> > +   .min_height = 0,
> > +   .max_width  = 4096,
> > +   .max_height = 4096,
> > +   .rotation   = DRM_MODE_ROTATE_0 |
> > + DRM_MODE_ROTATE_90 |
> > + DRM_MODE_ROTATE_180 |
> > + DRM_MODE_ROTATE_270 |
> > + DRM_MODE_REFLECT_X |
> > + DRM_MODE_REFLECT_Y,
> > +   .blend_mode = BIT(DRM_MODE_BLEND_PIXEL_NONE) |
> > + BIT(DRM_MODE_BLEND_PREMULTI) |
> > + BIT(DRM_MODE_BLEND_COVERAGE),
> > +   .color_encoding = BIT(DRM_COLOR_YCBCR_BT709) |
> > + BIT(DRM_COLOR_YCBCR_BT2020),
> > +   .degamma_size   = DEGAMMA_SIZE,
> > +   .min_scale  = FRAC_16_16(1, 3),
> > +   .max_scale  = FRAC_16_16(10, 1),
> > +   .zpos   = 1,
> > +   .watermark  = true,
> > +   .color_mgmt = true,
> > +   .roi= true,
> > +   },
> > +   {
> > +   .name   = "Overlay_1",
> > +   .id = OVERLAY_PLANE_1,
> > +   .type   = DRM_PLANE_TYPE_OVERLAY,
> > +   .num_formats= A

回复: [v3 4/6] drm/vs: Add KMS crtc

2024-01-31 Thread Keith Zhao


> -邮件原件-
> 发件人: Maxime Ripard 
> 发送时间: 2023年12月6日 16:56
> 收件人: Keith Zhao 
> 抄送: devicet...@vger.kernel.org; dri-devel@lists.freedesktop.org;
> linux-ker...@vger.kernel.org; linux-ri...@lists.infradead.org;
> tzimmerm...@suse.de; airl...@gmail.com; krzysztof.kozlowski...@linaro.org;
> William Qiu ; Xingyu Wu
> ; paul.walms...@sifive.com;
> a...@eecs.berkeley.edu; pal...@dabbelt.com; p.za...@pengutronix.de;
> Shengyang Chen ; Jack Zhu
> ; Changhuang Liang
> ; maarten.lankho...@linux.intel.com;
> suijingf...@loongson.cn
> 主题: Re: [v3 4/6] drm/vs: Add KMS crtc
> 
> On Mon, Dec 04, 2023 at 08:33:13PM +0800, Keith Zhao wrote:
> > +static const struct vs_plane_info dc_hw_planes_rev0[PLANE_NUM] = {
> > +   {
> > +   .name   = "Primary",
> > +   .id = PRIMARY_PLANE_0,
> > +   .type   = DRM_PLANE_TYPE_PRIMARY,
> > +   .num_formats= ARRAY_SIZE(primary_overlay_format0),
> > +   .formats= primary_overlay_format0,
> > +   .num_modifiers  = ARRAY_SIZE(format_modifier0),
> > +   .modifiers  = format_modifier0,
> > +   .min_width  = 0,
> > +   .min_height = 0,
> > +   .max_width  = 4096,
> > +   .max_height = 4096,
> > +   .rotation   = DRM_MODE_ROTATE_0 |
> > + DRM_MODE_ROTATE_90 |
> > + DRM_MODE_ROTATE_180 |
> > + DRM_MODE_ROTATE_270 |
> > + DRM_MODE_REFLECT_X |
> > + DRM_MODE_REFLECT_Y,
> > +   .blend_mode = BIT(DRM_MODE_BLEND_PIXEL_NONE) |
> > + BIT(DRM_MODE_BLEND_PREMULTI) |
> > + BIT(DRM_MODE_BLEND_COVERAGE),
> > +   .color_encoding = BIT(DRM_COLOR_YCBCR_BT709) |
> > + BIT(DRM_COLOR_YCBCR_BT2020),
> > +   .degamma_size   = DEGAMMA_SIZE,
> > +   .min_scale  = FRAC_16_16(1, 3),
> > +   .max_scale  = FRAC_16_16(10, 1),
> > +   .zpos   = 0,
> > +   .watermark  = true,
> > +   .color_mgmt = true,
> > +   .roi= true,
> > +   },
> > +   {
> > +   .name   = "Overlay",
> > +   .id = OVERLAY_PLANE_0,
> > +   .type   = DRM_PLANE_TYPE_OVERLAY,
> > +   .num_formats= ARRAY_SIZE(primary_overlay_format0),
> > +   .formats= primary_overlay_format0,
> > +   .num_modifiers  = ARRAY_SIZE(format_modifier0),
> > +   .modifiers  = format_modifier0,
> > +   .min_width  = 0,
> > +   .min_height = 0,
> > +   .max_width  = 4096,
> > +   .max_height = 4096,
> > +   .rotation   = DRM_MODE_ROTATE_0 |
> > + DRM_MODE_ROTATE_90 |
> > + DRM_MODE_ROTATE_180 |
> > + DRM_MODE_ROTATE_270 |
> > + DRM_MODE_REFLECT_X |
> > + DRM_MODE_REFLECT_Y,
> > +   .blend_mode = BIT(DRM_MODE_BLEND_PIXEL_NONE) |
> > + BIT(DRM_MODE_BLEND_PREMULTI) |
> > + BIT(DRM_MODE_BLEND_COVERAGE),
> > +   .color_encoding = BIT(DRM_COLOR_YCBCR_BT709) |
> > + BIT(DRM_COLOR_YCBCR_BT2020),
> > +   .degamma_size   = DEGAMMA_SIZE,
> > +   .min_scale  = FRAC_16_16(1, 3),
> > +   .max_scale  = FRAC_16_16(10, 1),
> > +   .zpos   = 1,
> > +   .watermark  = true,
> > +   .color_mgmt = true,
> > +   .roi= true,
> > +   },
> > +   {
> > +   .name   = "Overlay_1",
> > +   .id = OVERLAY_PLANE_1,
> > +   .type   = DRM_PLANE_TYPE_OVERLAY,
> > +   .num_formats= A

Re: [v3 5/6] drm/vs: Add hdmi driver

2023-12-12 Thread Keith Zhao



On 2023/12/11 20:13, Andy Yan wrote:
> Hi Keith:
> 
> 在 2023-12-11 18:24:35,"Keith Zhao"  写道:
>>hi Maxime:
>>hi Andy:
>>
>>On 2023/12/8 17:14, Maxime Ripard wrote:
>>> Hi,
>>> 
>>> On Fri, Dec 08, 2023 at 11:23:37AM +0800, Andy Yan wrote:
>>>> 在 2023-12-08 11:00:31,"Keith Zhao"  写道:
>>>> >
>>>> >
>>>> >On 2023/12/8 8:37, Andy Yan wrote:
>>>> >> Hi Keth:
>>>> >> 
>>>> >> 
>>>> >> 
>>>> >> 
>>>> >> 
>>>> >> 
>>>> >> 在 2023-12-07 18:48:13,"Keith Zhao"  写道:
>>>> >>>
>>>> >>>
>>>> >>>On 2023/12/7 17:02, Andy Yan wrote:
>>>> >>>> 
>>>> >>>> 
>>>> >>>> 
>>>> >>>> 
>>>> >>>> Hi Keith:
>>>> >>>> 
>>>> >>>> 
>>>> >>>> 
>>>> >>>> 
>>>> >>>> 
>>>> >>>> 
>>>> >>>> 
>>>> >>>> 
>>>> >>>> 
>>>> >>>> 
>>>> >>>> 
>>>> >>>> At 2023-12-06 22:11:33, "Keith Zhao"  
>>>> >>>> wrote:
>>>> >>>>>
>>>> >>>>>
>>>> >>>>>On 2023/12/6 20:56, Maxime Ripard wrote:
>>>> >>>>>> On Wed, Dec 06, 2023 at 08:02:55PM +0800, Keith Zhao wrote:
>>>> >>>>>>> >> +static const struct of_device_id starfive_hdmi_dt_ids[] = {
>>>> >>>>>>> >> +   { .compatible = "starfive,jh7110-inno-hdmi",},
>>>> >>>>>>> > 
>>>> >>>>>>> > So it's inno hdmi, just like Rockchip then?
>>>> >>>>>>> > 
>>>> >>>>>>> > This should be a common driver.
>>>> >>>>>>>
>>>> >>>>>>> Rockchip has a inno hdmi IP. and Starfive has a inno hdmi IP.
>>>> >>>>>>> but the harewawre difference of them is big , it is not easy to 
>>>> >>>>>>> use the common driver
>>>> >>>>>>> maybe i need the inno hdmi version here to make a distinction
>>>> >>>>>> 
>>>> >>>>>> I just had a look at the rockchip header file: all the registers 
>>>> >>>>>> but the
>>>> >>>>>> STARFIVE_* ones are identical.
>>>> >>>>>> 
>>>> >>>>>> There's no need to have two identical drivers then, please use the
>>>> >>>>>> rockchip driver instead.
>>>> >>>>>> 
>>>> >>>>>> Maxime
>>>> >>>>>
>>>> >>>>>ok, have a simple test , edid can get . i will continue 
>>>> >>>> 
>>>> >>>> Maybe you can take drivers/gpu/drm/bridge/synopsys/dw-hdmi as a 
>>>> >>>> reference, this
>>>> >>>> is also a hdmi ip used by rockchip/meson/sunxi/jz/imx。
>>>> >>>> We finally make it share one driver。
>>>> >>>>>
>>>> >>>hi Andy:
>>>> >>>
>>>> >>>dw_hdmi seems a good choice , it can handle inno hdmi hardware by 
>>>> >>>define its dw_hdmi_plat_data.
>>>> >>>does it means i can write own driver files such as(dw_hdmi-starfive.c) 
>>>> >>>based on dw_hdmi instead of add plat_data in inno_hdmi.c
>>>> >>>
>>>> >> 
>>>> >> I think the process maybe like this:
>>>> >> 
>>>> >> 1. split the inno_hdmi.c under rockchip to  inno_hdmi.c(the common 
>>>> >> part), inno_hdmi-rockchip.c(the soc specific part)
>>>> >> 2. move the common part inno_hdmi.c to 
>>>> >> drivers/gpu/drm/bridge/innosilicon/
>>>> >> 3. add startfive specific part, inno_hdmi-startfive.c
>>>> >> 
>>>> >> bellow git log from kernel three show how we convert  dw_hdmi to a 
>>>> >> common driver: 
>>

Re: [v3 5/6] drm/vs: Add hdmi driver

2023-12-11 Thread Keith Zhao
hi Maxime:
hi Andy:

On 2023/12/8 17:14, Maxime Ripard wrote:
> Hi,
> 
> On Fri, Dec 08, 2023 at 11:23:37AM +0800, Andy Yan wrote:
>> 在 2023-12-08 11:00:31,"Keith Zhao"  写道:
>> >
>> >
>> >On 2023/12/8 8:37, Andy Yan wrote:
>> >> Hi Keth:
>> >> 
>> >> 
>> >> 
>> >> 
>> >> 
>> >> 
>> >> 在 2023-12-07 18:48:13,"Keith Zhao"  写道:
>> >>>
>> >>>
>> >>>On 2023/12/7 17:02, Andy Yan wrote:
>> >>>> 
>> >>>> 
>> >>>> 
>> >>>> 
>> >>>> Hi Keith:
>> >>>> 
>> >>>> 
>> >>>> 
>> >>>> 
>> >>>> 
>> >>>> 
>> >>>> 
>> >>>> 
>> >>>> 
>> >>>> 
>> >>>> 
>> >>>> At 2023-12-06 22:11:33, "Keith Zhao"  
>> >>>> wrote:
>> >>>>>
>> >>>>>
>> >>>>>On 2023/12/6 20:56, Maxime Ripard wrote:
>> >>>>>> On Wed, Dec 06, 2023 at 08:02:55PM +0800, Keith Zhao wrote:
>> >>>>>>> >> +static const struct of_device_id starfive_hdmi_dt_ids[] = {
>> >>>>>>> >> + { .compatible = "starfive,jh7110-inno-hdmi",},
>> >>>>>>> > 
>> >>>>>>> > So it's inno hdmi, just like Rockchip then?
>> >>>>>>> > 
>> >>>>>>> > This should be a common driver.
>> >>>>>>>
>> >>>>>>> Rockchip has a inno hdmi IP. and Starfive has a inno hdmi IP.
>> >>>>>>> but the harewawre difference of them is big , it is not easy to use 
>> >>>>>>> the common driver
>> >>>>>>> maybe i need the inno hdmi version here to make a distinction
>> >>>>>> 
>> >>>>>> I just had a look at the rockchip header file: all the registers but 
>> >>>>>> the
>> >>>>>> STARFIVE_* ones are identical.
>> >>>>>> 
>> >>>>>> There's no need to have two identical drivers then, please use the
>> >>>>>> rockchip driver instead.
>> >>>>>> 
>> >>>>>> Maxime
>> >>>>>
>> >>>>>ok, have a simple test , edid can get . i will continue 
>> >>>> 
>> >>>> Maybe you can take drivers/gpu/drm/bridge/synopsys/dw-hdmi as a 
>> >>>> reference, this
>> >>>> is also a hdmi ip used by rockchip/meson/sunxi/jz/imx。
>> >>>> We finally make it share one driver。
>> >>>>>
>> >>>hi Andy:
>> >>>
>> >>>dw_hdmi seems a good choice , it can handle inno hdmi hardware by define 
>> >>>its dw_hdmi_plat_data.
>> >>>does it means i can write own driver files such as(dw_hdmi-starfive.c) 
>> >>>based on dw_hdmi instead of add plat_data in inno_hdmi.c
>> >>>
>> >> 
>> >> I think the process maybe like this:
>> >> 
>> >> 1. split the inno_hdmi.c under rockchip to  inno_hdmi.c(the common part), 
>> >> inno_hdmi-rockchip.c(the soc specific part)
>> >> 2. move the common part inno_hdmi.c to drivers/gpu/drm/bridge/innosilicon/
>> >> 3. add startfive specific part, inno_hdmi-startfive.c
>> >> 
>> >> bellow git log from kernel three show how we convert  dw_hdmi to a common 
>> >> driver: 
>> >> 
>> >> 
>> >> 
>> >> 12b9f204e804 drm: bridge/dw_hdmi: add rockchip rk3288 support
>> >> 74af9e4d03b8 dt-bindings: Add documentation for rockchip dw hdmi
>> >> d346c14eeea9 drm: bridge/dw_hdmi: add function dw_hdmi_phy_enable_spare
>> >> a4d3b8b050d5 drm: bridge/dw_hdmi: clear i2cmphy_stat0 reg in 
>> >> hdmi_phy_wait_i2c_done
>> >> 632d035bace2 drm: bridge/dw_hdmi: add mode_valid support
>> >> 0cd9d1428322 drm: bridge/dw_hdmi: add support for multi-byte register 
>> >> width access
>> >> cd152393967e dt-bindings: add document for dw_hdmi
>> >> b21f4b658df8 drm: imx: imx-hdmi: move imx-hdmi to bridge/dw_hdmi
>> >> aaa757a092c2 drm: imx: imx-hdmi: split phy configuration to platform 
>> >> driver
>> >> 3d1b35a3d9f3 drm: imx: imx-hdmi: convert imx-hdmi to drm_bridge mode
>> >> c2c3848851a7 drm: imx: imx-hdmi: return defer if can't get ddc i2c adapter
>> >> b587833933de drm: imx: imx-hdmi: make checkpatch happy
>> >> 
>> >hi Andy:
>> >I got you means, 
>> >as I don't have a rockchip board on hand , to split the inno_hdmi.c can not 
>> >be tested.
>> >
>> >how adout this idea:
>> >1、split the starfive_hdmi.c under verisilicion to  inno_hdmi.c(the common 
>> >part), inno_hdmi-starfive.c(the soc specific part)
>> >2. move the common part inno_hdmi.c to drivers/gpu/drm/bridge/innosilicon/
>> >3. In the future, inno hdmi.c under rockchip will reuse the public driver.
>> 
>> I am not sure if drm maintainers are happy with this。
> 
> Not really, no.
> 
> Because we would still have two drivers for the same controller, and a
> common one that haven't really been tested on anything but a single
> platform. So arguably a worse situation than what you were suggesting in
> the first place.
> 
> The best solution would be to find someone with a Rockchip board to test
> your changes, or to get one if it's doable so you can test yourself.

ok I will also try to buy a Rockchip 3036 board for self-test.
According to the commit log idea provided by Andy before, make the inno_hdmi 
driver common module.

would the steps be ok? (if I tested rockchip and starifve pass)
1. split the inno_hdmi.c under rockchip to  inno_hdmi.c(the common part), 
inno_hdmi-rockchip.c(the soc specific part)
2. move the common part inno_hdmi.c to drivers/gpu/drm/bridge/innosilicon/
3. add startfive specific part, inno_hdmi-startfive.c

Thanks
> 
> Maxime


Re: [v3 3/6] drm/vs: Register DRM device

2023-12-11 Thread Keith Zhao
hi Philipp:

On 2023/12/4 21:30, Philipp Zabel wrote:
> Hi Keith,
> 
> On Mo, 2023-12-04 at 20:33 +0800, Keith Zhao wrote:
>> Implement drm device registration interface
>> 
>> Signed-off-by: Keith Zhao 
>> ---
> [...]
>> diff --git a/drivers/gpu/drm/verisilicon/Kconfig 
>> b/drivers/gpu/drm/verisilicon/Kconfig
>> new file mode 100644
>> index ..e10fa97635aa
>> --- /dev/null
>> +++ b/drivers/gpu/drm/verisilicon/Kconfig
>> @@ -0,0 +1,13 @@
>> +# SPDX-License-Identifier: GPL-2.0
>> +config DRM_VERISILICON
>> +tristate "DRM Support for VeriSilicon"
>> +depends on DRM
>> +select DRM_KMS_HELPER
>> +select DRM_GEM_DMA_HELPER
>> +select CMA
>> +select DMA_CMA
>> +help
>> +  Choose this option if you have a VeriSilicon soc chipset.
> 
> This seems a bit generic. Doesn't the VeriSilicon display controller IP
> used on JH7110 have a product name?
yes , there is a product name "dc8200", I will match it.
> 
> [...]
>> diff --git a/drivers/gpu/drm/verisilicon/vs_drv.c 
>> b/drivers/gpu/drm/verisilicon/vs_drv.c
>> new file mode 100644
>> index ..4fb1f29ef84b
>> --- /dev/null
>> +++ b/drivers/gpu/drm/verisilicon/vs_drv.c
>> @@ -0,0 +1,316 @@
>> +// SPDX-License-Identifier: GPL-2.0
> [...]
>> +static void vs_drm_device_release_clocks(void *res)
>> +{
>> +struct vs_drm_device *priv = res;
>> +unsigned int i;
>> +
>> +reset_control_bulk_assert(priv->nrsts, priv->rst_vout);
>> +
>> +for (i = 0; i < priv->clk_count; ++i) {
>> +if (priv->clks[i]) {
>> +clk_disable_unprepare(priv->clks[i]);
>> +clk_put(priv->clks[i]);
>> +}
>> +}
> 
> Why not use the bulk API for clk as well?
ok , will do it next version
> 
> [...]
>> +static int vs_drm_device_init_clocks(struct vs_drm_device *priv)
>> +{
>> +struct drm_device *dev = >base;
>> +struct platform_device *pdev = to_platform_device(dev->dev);
>> +struct device_node *of_node = pdev->dev.of_node;
>> +struct clk *clock;
>> +unsigned int i;
>> +int ret;
>> +
>> +if (dev_get_platdata(>dev) || !of_node)
>> +return 0;
>> +
>> +priv->nrsts = ARRAY_SIZE(priv->rst_vout);
>> +for (int i = 0; i < priv->nrsts; ++i)
>> +priv->rst_vout[i].id = vout_resets[i];
>> +ret = devm_reset_control_bulk_get_shared(dev->dev, priv->nrsts,
>> + priv->rst_vout);
> 
> I would request resets and clocks in _probe().

> 
> If component_bind_all() returns -EPROBE_DEFER because of a still
> missing DSI panel backlight or similar, this doesn't have to be done
> multiple times.
I got what you mean. component_bind_all should be done multiple times
 to prevent the dsi panel driver from lagging load.

in my drm subsystem , there are 2 pipeline 

  +--+
  |  |
  |  |
  ++  |   +---+  |   +---+   +--+   +--+
  |+->+  dc controller 0  +--->->+HDMICtl| ->+ PHY  +-->+PANEL0+
  |AXI |  |   +---+  |   +---+   +--+   +--+
  ||  |  |
  ||  |  |
  ||  |  |
  ||  |  |
  |APB |  |   +---+ +-++--+  +---+
  |+->+  dc controller 1  +--->>+ dsiTx   +--->+DPHY  +->+ PANEL1+
  ||  |   +---+ +-++--+  +---+
  ++  |  |
  +--+


component_bind_all will bind the hdmi encoder and dsi encoder .
binding the hdmi encoder will always return ok .

binging the dsi encoder has a question :
I used the panel-raspberrypi-touchscreen.c as panel driver , 
this driver is a i2c device and it use a i2c command to read reg ID
if read success , it will do drm_panel_add. 

if I disconnect the panel ,it will not do drm_panel_add.
dsiTx will fail to find panel , The consequence is that the inputbridge cannot 
be created , 
also outputbridge cannot be created.
for encoder bind , it will fail to find the input bridge of dsi.
Under this premise, although returning -EPROBE_DEFER allows bind to be executed 
multiple times, 
the final result is that the entire bind fails.

returning -EPROBE_DEFER can solve panel driver 

Re: [v3 5/6] drm/vs: Add hdmi driver

2023-12-07 Thread Keith Zhao



On 2023/12/8 8:37, Andy Yan wrote:
> Hi Keth:
> 
> 
> 
> 
> 
> 
> 在 2023-12-07 18:48:13,"Keith Zhao"  写道:
>>
>>
>>On 2023/12/7 17:02, Andy Yan wrote:
>>> 
>>> 
>>> 
>>> 
>>> Hi Keith:
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> At 2023-12-06 22:11:33, "Keith Zhao"  wrote:
>>>>
>>>>
>>>>On 2023/12/6 20:56, Maxime Ripard wrote:
>>>>> On Wed, Dec 06, 2023 at 08:02:55PM +0800, Keith Zhao wrote:
>>>>>> >> +static const struct of_device_id starfive_hdmi_dt_ids[] = {
>>>>>> >> + { .compatible = "starfive,jh7110-inno-hdmi",},
>>>>>> > 
>>>>>> > So it's inno hdmi, just like Rockchip then?
>>>>>> > 
>>>>>> > This should be a common driver.
>>>>>>
>>>>>> Rockchip has a inno hdmi IP. and Starfive has a inno hdmi IP.
>>>>>> but the harewawre difference of them is big , it is not easy to use the 
>>>>>> common driver
>>>>>> maybe i need the inno hdmi version here to make a distinction
>>>>> 
>>>>> I just had a look at the rockchip header file: all the registers but the
>>>>> STARFIVE_* ones are identical.
>>>>> 
>>>>> There's no need to have two identical drivers then, please use the
>>>>> rockchip driver instead.
>>>>> 
>>>>> Maxime
>>>>
>>>>ok, have a simple test , edid can get . i will continue 
>>> 
>>> Maybe you can take drivers/gpu/drm/bridge/synopsys/dw-hdmi as a reference, 
>>> this
>>> is also a hdmi ip used by rockchip/meson/sunxi/jz/imx。
>>> We finally make it share one driver。
>>>>
>>hi Andy:
>>
>>dw_hdmi seems a good choice , it can handle inno hdmi hardware by define its 
>>dw_hdmi_plat_data.
>>does it means i can write own driver files such as(dw_hdmi-starfive.c) based 
>>on dw_hdmi instead of add plat_data in inno_hdmi.c
>>
> 
> I think the process maybe like this:
> 
> 1. split the inno_hdmi.c under rockchip to  inno_hdmi.c(the common part), 
> inno_hdmi-rockchip.c(the soc specific part)
> 2. move the common part inno_hdmi.c to drivers/gpu/drm/bridge/innosilicon/
> 3. add startfive specific part, inno_hdmi-startfive.c
> 
> bellow git log from kernel three show how we convert  dw_hdmi to a common 
> driver: 
> 
> 
> 
> 12b9f204e804 drm: bridge/dw_hdmi: add rockchip rk3288 support
> 74af9e4d03b8 dt-bindings: Add documentation for rockchip dw hdmi
> d346c14eeea9 drm: bridge/dw_hdmi: add function dw_hdmi_phy_enable_spare
> a4d3b8b050d5 drm: bridge/dw_hdmi: clear i2cmphy_stat0 reg in 
> hdmi_phy_wait_i2c_done
> 632d035bace2 drm: bridge/dw_hdmi: add mode_valid support
> 0cd9d1428322 drm: bridge/dw_hdmi: add support for multi-byte register width 
> access
> cd152393967e dt-bindings: add document for dw_hdmi
> b21f4b658df8 drm: imx: imx-hdmi: move imx-hdmi to bridge/dw_hdmi
> aaa757a092c2 drm: imx: imx-hdmi: split phy configuration to platform driver
> 3d1b35a3d9f3 drm: imx: imx-hdmi: convert imx-hdmi to drm_bridge mode
> c2c3848851a7 drm: imx: imx-hdmi: return defer if can't get ddc i2c adapter
> b587833933de drm: imx: imx-hdmi: make checkpatch happy
> 
hi Andy:
I got you means, 
as I don't have a rockchip board on hand , to split the inno_hdmi.c can not be 
tested.

how adout this idea:
1、split the starfive_hdmi.c under verisilicion to  inno_hdmi.c(the common 
part), inno_hdmi-starfive.c(the soc specific part)
2. move the common part inno_hdmi.c to drivers/gpu/drm/bridge/innosilicon/
3. In the future, inno hdmi.c under rockchip will reuse the public driver.

> 
>>Thanks for pointing this out!!!
>>
>>>>
>>>>___
>>>>linux-riscv mailing list
>>>>linux-ri...@lists.infradead.org
>>>>http://lists.infradead.org/mailman/listinfo/linux-riscv
>>
>>___
>>linux-riscv mailing list
>>linux-ri...@lists.infradead.org
>>http://lists.infradead.org/mailman/listinfo/linux-riscv


Re: [v3 4/6] drm/vs: Add KMS crtc

2023-12-07 Thread Keith Zhao



On 2023/12/7 16:41, Icenowy Zheng wrote:
> 在 2023-12-04星期一的 20:33 +0800,Keith Zhao写道:
> *snip*
> 
>> +static void update_cursor_plane(struct vs_dc *dc, struct vs_plane
>> *plane,
>> +   struct drm_plane *drm_plane,
>> +   struct drm_atomic_state *drm_state)
>> +{
>> +   struct drm_plane_state *state =
>> drm_atomic_get_new_plane_state(drm_state,
>> +
>>   drm_plane);
>> +   struct vs_plane_state *plane_state =
>> to_vs_plane_state(state);
>> +   struct drm_framebuffer *drm_fb = state->fb;
>> +   struct dc_hw_cursor cursor;
>> +
>> +   cursor.address = plane_state->dma_addr[0];
>> +   cursor.x = state->crtc_x;
>> +   cursor.y = state->crtc_y;
> 
> From my experiments on poking with registers on T-Head TH1520 (also
> uses DC8200 display controller and a similar driver), the DC8200
> hardware have a different definition of cursor position X and Y with
> the CRTC plane state.
> 
> For CRTC plane state, hot_x and hot_y are only provided as reference,
> and the cursor should be displayed with its (0,0) drawn to (crtc_x,
> crtc_y) ([XY]_crtc are values specified in CRTC state, the right part
> of the assignments here), when the cursor is moved to (0,0) but the hot
> point is not (0,0), it could be negative.
> 
> However, for DC8200 registers definition, cursor XY position could not
> be negative -- the cursor will disappear then; because in its
> definition, the cursor XY position should be where the cursor is
> pointing to, instead of its (0,0). DC8200 will draw (0,0) of the cursor
> to (x - hot_x, y - hot_y). So to met the expectation of the KMS plane
> settings, the DC8200 position should be set to (crtc_x + hot_x, crtc_y
> + hot_y) instead. Thus these two lines of code should be:
> 
> ```
> cursor.x = state->crtc_x + drm_fb->hot_x;
> cursor.y = state->crtc_y + drm_fb->hot_y;
> ```
> 
> 
>> +   cursor.hot_x = drm_fb->hot_x;
>> +   cursor.hot_y = drm_fb->hot_y;
>> +   cursor.display_id = to_vs_display_id(dc, state->crtc);
>> +   update_cursor_size(state, );
>> +   cursor.enable = true;
>> +
>> +   dc_hw_update_cursor(>hw, cursor.display_id, );
>> +}
> *snip
hello Icenowy:
you are deep understanding on dc8200.
by the way of practice
I tested this change on the debian desktop, is there a way to compare the 
cursor behavior change?
Thanks





Re: [v3 5/6] drm/vs: Add hdmi driver

2023-12-07 Thread Keith Zhao



On 2023/12/7 17:02, Andy Yan wrote:
> 
> 
> 
> 
> Hi Keith:
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> At 2023-12-06 22:11:33, "Keith Zhao"  wrote:
>>
>>
>>On 2023/12/6 20:56, Maxime Ripard wrote:
>>> On Wed, Dec 06, 2023 at 08:02:55PM +0800, Keith Zhao wrote:
>>>> >> +static const struct of_device_id starfive_hdmi_dt_ids[] = {
>>>> >> +   { .compatible = "starfive,jh7110-inno-hdmi",},
>>>> > 
>>>> > So it's inno hdmi, just like Rockchip then?
>>>> > 
>>>> > This should be a common driver.
>>>>
>>>> Rockchip has a inno hdmi IP. and Starfive has a inno hdmi IP.
>>>> but the harewawre difference of them is big , it is not easy to use the 
>>>> common driver
>>>> maybe i need the inno hdmi version here to make a distinction
>>> 
>>> I just had a look at the rockchip header file: all the registers but the
>>> STARFIVE_* ones are identical.
>>> 
>>> There's no need to have two identical drivers then, please use the
>>> rockchip driver instead.
>>> 
>>> Maxime
>>
>>ok, have a simple test , edid can get . i will continue 
> 
> Maybe you can take drivers/gpu/drm/bridge/synopsys/dw-hdmi as a reference, 
> this
> is also a hdmi ip used by rockchip/meson/sunxi/jz/imx。
> We finally make it share one driver。
>>
hi Andy:

dw_hdmi seems a good choice , it can handle inno hdmi hardware by define its 
dw_hdmi_plat_data.
does it means i can write own driver files such as(dw_hdmi-starfive.c) based on 
dw_hdmi instead of add plat_data in inno_hdmi.c

Thanks for pointing this out!!!

>>
>>___
>>linux-riscv mailing list
>>linux-ri...@lists.infradead.org
>>http://lists.infradead.org/mailman/listinfo/linux-riscv


Re: [PATCH v1 0/2] Add waveshare 7inch touchscreen panel support

2023-12-06 Thread Keith Zhao



On 2023/12/6 22:56, Dave Stevenson wrote:
> Hi Keith
> 
> On Wed, 6 Dec 2023 at 08:55, Keith Zhao  wrote:
>>
>>
>>
>> On 2023/11/25 0:04, Dave Stevenson wrote:
>> > On Fri, 24 Nov 2023 at 15:00, Stefan Wahren  wrote:
>> >>
>> >> Hi Shengyang,
>> >>
>> >> [fix address of Emma]
>> >
>> > Not merged to master yet, but Emma has stepped back from maintenance.
>> > https://lists.freedesktop.org/archives/dri-devel/2023-October/428829.html
>> > Dropped from the cc.
>> >
>> >> Am 24.11.23 um 11:44 schrieb Shengyang Chen:
>> >> > This patchset adds waveshare 7inch touchscreen panel support
>> >> > for the StarFive JH7110 SoC.
>> >> >
>> >> > Patch 1 add new compatible for the raspberrypi panel driver and its 
>> >> > dt-binding.
>> >> > Patch 2 add new display mode and new probing process for raspberrypi 
>> >> > panel driver.
>> >> >
>> >> > Waveshare 7inch touchscreen panel is a kind of raspberrypi panel
>> >> > which can be drived by raspberrypi panel driver.
>> >> >
>> >> > The series has been tested on the VisionFive 2 board.
>> >> surprisingly i was recently working on the official Raspberry Pi
>> >> touchscreen and was able to get it running the new way.
>> >>
>> >> What do i mean with the new way. There is almost nothing special to the
>> >> Raspberry Pi touchscreen, so we should try to use/extend existing
>> >> components like:
>> >>
>> >> CONFIG_DRM_PANEL_SIMPLE
>> >> CONFIG_TOUCHSCREEN_EDT_FT5X06
>> >> CONFIG_DRM_TOSHIBA_TC358762
>> >>
>> >> The only special part is the Attiny on the connector PCB which requires:
>> >>
>> >> CONFIG_REGULATOR_RASPBERRYPI_TOUCHSCREEN_ATTINY
>> >>
>> >> So the whole point is to avoid writing monolitic drivers for simple
>> >> panel like that.
>> >>
>> >> There is a WIP branch based on top of Linux 6.7-rcX, which should
>> >> demonstrate this approach [1]. Unfortunately it is not ready for
>> >> upstreaming, but it has been tested on a Raspberry Pi 3 B Plus. Maybe
>> >> this is helpful for your case.
>> >>
>> >> Actually i consider panel-raspberrypi-touchscreen.c as a dead end, which
>> >> shouldn't be extended.
>> >
>> > Agreed.
>> >
>> > The panel control being bound in with the Atmel control has no hook
>> > for the EDT5x06 touch driver to hook in and keep the power to the
>> > touch controller active. When the panel disable gets called, bye bye
>> > touch overlay :-(
>> >
>> > And I'm reading the driver change as more of a hack to get it to work
>> > on your platform, not as adding support for the Waveshare panel
>> > variant.
>> > Waveshare deliberately cloned the behaviour of the Pi 7" panel in
>> > order to make it work with the old Pi firmware drivers, so it
>> > shouldn't need any significant changes. Where did the new timings come
>> > from?
>> >
>> >   Dave
>> hi Dave :
>> that's means the panel driver split into 3 sub-modules:
>> panel + panel_bridge + regulator.
> 
> Correct.
> 
> You'll have a fourth device in edt_ft5x06 for the touch overlay too,
> which will link to the regulator driver for power control.
> 
>> I have a question: in the
>> static int rpi_touchscreen_probe(struct i2c_client *i2c)
>> {
>> ..
>>
>> ver = rpi_touchscreen_i2c_read(ts, REG_ID);
>> if (ver < 0) {
>> dev_err(dev, "Atmel I2C read failed: %d\n", ver);
>> return -ENODEV;
>> }
>>
>> switch (ver) {
>> case 0xde: /* ver 1 */
>> case 0xc3: /* ver 2 */
>> break;
>> default:
>> dev_err(dev, "Unknown Atmel firmware revision: 0x%02x\n", 
>> ver);
>> return -ENODEV;
>> }
>>
>> ..
>> }
>> i think this "I2C read" can use to detect whether the panel is connected to 
>> dsi controller.
>>
>> and when split the panel driver into 3 sub-modules, it seems the default way 
>> is connected.
>> if I drop the panel , run modetest to check the connector status , result 
>> connected.
>> Is there any way to detect th

Re: [v3 5/6] drm/vs: Add hdmi driver

2023-12-06 Thread Keith Zhao



On 2023/12/6 20:56, Maxime Ripard wrote:
> On Wed, Dec 06, 2023 at 08:02:55PM +0800, Keith Zhao wrote:
>> >> +static const struct of_device_id starfive_hdmi_dt_ids[] = {
>> >> + { .compatible = "starfive,jh7110-inno-hdmi",},
>> > 
>> > So it's inno hdmi, just like Rockchip then?
>> > 
>> > This should be a common driver.
>>
>> Rockchip has a inno hdmi IP. and Starfive has a inno hdmi IP.
>> but the harewawre difference of them is big , it is not easy to use the 
>> common driver
>> maybe i need the inno hdmi version here to make a distinction
> 
> I just had a look at the rockchip header file: all the registers but the
> STARFIVE_* ones are identical.
> 
> There's no need to have two identical drivers then, please use the
> rockchip driver instead.
> 
> Maxime

ok, have a simple test , edid can get . i will continue 



Re: [v3 4/6] drm/vs: Add KMS crtc

2023-12-06 Thread Keith Zhao



On 2023/12/6 16:55, Maxime Ripard wrote:
> On Mon, Dec 04, 2023 at 08:33:13PM +0800, Keith Zhao wrote:
>> +static const struct vs_plane_info dc_hw_planes_rev0[PLANE_NUM] = {
>> +{
>> +.name   = "Primary",
>> +.id = PRIMARY_PLANE_0,
>> +.type   = DRM_PLANE_TYPE_PRIMARY,
>> +.num_formats= ARRAY_SIZE(primary_overlay_format0),
>> +.formats= primary_overlay_format0,
>> +.num_modifiers  = ARRAY_SIZE(format_modifier0),
>> +.modifiers  = format_modifier0,
>> +.min_width  = 0,
>> +.min_height = 0,
>> +.max_width  = 4096,
>> +.max_height = 4096,
>> +.rotation   = DRM_MODE_ROTATE_0 |
>> +  DRM_MODE_ROTATE_90 |
>> +  DRM_MODE_ROTATE_180 |
>> +  DRM_MODE_ROTATE_270 |
>> +  DRM_MODE_REFLECT_X |
>> +  DRM_MODE_REFLECT_Y,
>> +.blend_mode = BIT(DRM_MODE_BLEND_PIXEL_NONE) |
>> +  BIT(DRM_MODE_BLEND_PREMULTI) |
>> +  BIT(DRM_MODE_BLEND_COVERAGE),
>> +.color_encoding = BIT(DRM_COLOR_YCBCR_BT709) |
>> +  BIT(DRM_COLOR_YCBCR_BT2020),
>> +.degamma_size   = DEGAMMA_SIZE,
>> +.min_scale  = FRAC_16_16(1, 3),
>> +.max_scale  = FRAC_16_16(10, 1),
>> +.zpos   = 0,
>> +.watermark  = true,
>> +.color_mgmt = true,
>> +.roi= true,
>> +},
>> +{
>> +.name   = "Overlay",
>> +.id = OVERLAY_PLANE_0,
>> +.type   = DRM_PLANE_TYPE_OVERLAY,
>> +.num_formats= ARRAY_SIZE(primary_overlay_format0),
>> +.formats= primary_overlay_format0,
>> +.num_modifiers  = ARRAY_SIZE(format_modifier0),
>> +.modifiers  = format_modifier0,
>> +.min_width  = 0,
>> +.min_height = 0,
>> +.max_width  = 4096,
>> +.max_height = 4096,
>> +.rotation   = DRM_MODE_ROTATE_0 |
>> +  DRM_MODE_ROTATE_90 |
>> +  DRM_MODE_ROTATE_180 |
>> +  DRM_MODE_ROTATE_270 |
>> +  DRM_MODE_REFLECT_X |
>> +  DRM_MODE_REFLECT_Y,
>> +.blend_mode = BIT(DRM_MODE_BLEND_PIXEL_NONE) |
>> +  BIT(DRM_MODE_BLEND_PREMULTI) |
>> +  BIT(DRM_MODE_BLEND_COVERAGE),
>> +.color_encoding = BIT(DRM_COLOR_YCBCR_BT709) |
>> +  BIT(DRM_COLOR_YCBCR_BT2020),
>> +.degamma_size   = DEGAMMA_SIZE,
>> +.min_scale  = FRAC_16_16(1, 3),
>> +.max_scale  = FRAC_16_16(10, 1),
>> +.zpos   = 1,
>> +.watermark  = true,
>> +.color_mgmt = true,
>> +.roi= true,
>> +},
>> +{
>> +.name   = "Overlay_1",
>> +.id = OVERLAY_PLANE_1,
>> +.type   = DRM_PLANE_TYPE_OVERLAY,
>> +.num_formats= ARRAY_SIZE(primary_overlay_format0),
>> +.formats= primary_overlay_format0,
>> +.num_modifiers  = 
>> ARRAY_SIZE(secondary_format_modifiers),
>> +.modifiers  = secondary_format_modifiers,
>> +.min_width  = 0,
>> +.min_height = 0,
>> +.max_width  = 4096,
>> +.max_height = 4096,
>> +.rotation   = 0,
>> +.blend_mode = B

Re: [v3 5/6] drm/vs: Add hdmi driver

2023-12-06 Thread Keith Zhao



On 2023/12/6 17:04, Maxime Ripard wrote:
> On Mon, Dec 04, 2023 at 08:33:14PM +0800, Keith Zhao wrote:
>> add hdmi driver as encoder and connect
>> 
>> Signed-off-by: Keith Zhao 
>> ---
>>  drivers/gpu/drm/verisilicon/Kconfig |   8 +
>>  drivers/gpu/drm/verisilicon/Makefile|   1 +
>>  drivers/gpu/drm/verisilicon/starfive_hdmi.c | 849 
>>  drivers/gpu/drm/verisilicon/starfive_hdmi.h | 304 +++
>>  drivers/gpu/drm/verisilicon/vs_drv.c|   3 +
>>  drivers/gpu/drm/verisilicon/vs_drv.h|   4 +
>>  6 files changed, 1169 insertions(+)
>>  create mode 100644 drivers/gpu/drm/verisilicon/starfive_hdmi.c
>>  create mode 100644 drivers/gpu/drm/verisilicon/starfive_hdmi.h
>> 
>> diff --git a/drivers/gpu/drm/verisilicon/Kconfig 
>> b/drivers/gpu/drm/verisilicon/Kconfig
>> index e10fa97635aa..122c786e3948 100644
>> --- a/drivers/gpu/drm/verisilicon/Kconfig
>> +++ b/drivers/gpu/drm/verisilicon/Kconfig
>> @@ -11,3 +11,11 @@ config DRM_VERISILICON
>>This driver provides VeriSilicon kernel mode
>>setting and buffer management. It does not
>>provide 2D or 3D acceleration.
>> +
>> +config DRM_VERISILICON_STARFIVE_HDMI
>> +bool "Starfive HDMI extensions"
>> +depends on DRM_VERISILICON
>> +help
>> +   This selects support for StarFive soc specific extensions
>> +   for the Innosilicon HDMI driver. If you want to enable
>> +   HDMI on JH7110 based soc, you should select this option.
> 
> I'm confused, is it a starfive or verisilicon IP?
it is Innosilicon ip ,I need describe it clearer in my next.
> 
>> diff --git a/drivers/gpu/drm/verisilicon/Makefile 
>> b/drivers/gpu/drm/verisilicon/Makefile
>> index bf6f2b7ee480..71fadafcee13 100644
>> --- a/drivers/gpu/drm/verisilicon/Makefile
>> +++ b/drivers/gpu/drm/verisilicon/Makefile
>> @@ -6,4 +6,5 @@ vs_drm-objs := vs_dc_hw.o \
>>  vs_drv.o \
>>  vs_modeset.o \
>>  vs_plane.o
>> +vs_drm-$(CONFIG_DRM_VERISILICON_STARFIVE_HDMI) += starfive_hdmi.o
>>  obj-$(CONFIG_DRM_VERISILICON) += vs_drm.o
>> diff --git a/drivers/gpu/drm/verisilicon/starfive_hdmi.c 
>> b/drivers/gpu/drm/verisilicon/starfive_hdmi.c
>> new file mode 100644
>> index ..aa621db0dee0
>> --- /dev/null
>> +++ b/drivers/gpu/drm/verisilicon/starfive_hdmi.c
>> @@ -0,0 +1,849 @@
>> +// SPDX-License-Identifier: GPL-2.0-only
>> +/*
>> + * Copyright (C) 2023 StarFive Technology Co., Ltd.
>> + */
>> +
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +
>> +#include "starfive_hdmi.h"
>> +#include "vs_drv.h"
>> +#include "vs_crtc.h"
>> +
>> +static const char * const hdmi_clocks[] = {
>> +"sysclk",
>> +"mclk",
>> +"bclk"
>> +};
>> +
>> +static struct starfive_hdmi_encoder *encoder_to_hdmi(struct drm_encoder 
>> *encoder)
>> +{
>> +return container_of(encoder, struct starfive_hdmi_encoder, encoder);
>> +}
>> +
>> +static struct starfive_hdmi *connector_to_hdmi(struct drm_connector 
>> *connector)
>> +{
>> +return container_of(connector, struct starfive_hdmi, connector);
>> +}
>> +
>> +static const struct post_pll_config post_pll_cfg_table[] = {
>> +{2520,  1, 80, 13, 3, 1},
>> +{2700,  1, 40, 11, 3, 1},
>> +{3375,  1, 40, 11, 3, 1},
>> +{4900,  1, 20, 1, 3, 3},
>> +{24170, 1, 20, 1, 3, 3},
>> +{29700, 4, 20, 0, 0, 3},
>> +{59400, 4, 20, 0, 0, 0},
> 
> If you don't support modes > 340MHz, then there's no point in listing 594MHz 
> here
sure . max should be 297M here.
> 
>> +{ /* sentinel */ }
>> +};
>> +
>> +inline u8 hdmi_readb(struct starfive_hdmi *hdmi, u16 offset)
>> +{
>> +return readl_relaxed(hdmi->regs + (offset) * 0x04);
>> +}
>> +
>> +inline void hdmi_writeb(struct starfive_hdmi *hdmi, u16 offset, u32 val)
>> +{
>> +writel_relaxed(val, hdmi->regs + (offset) * 0x04);
>> +}
>> +
>> +inline void hdmi_writew(struc

Re: [PATCH v1 0/2] Add waveshare 7inch touchscreen panel support

2023-12-06 Thread Keith Zhao



On 2023/11/25 0:04, Dave Stevenson wrote:
> On Fri, 24 Nov 2023 at 15:00, Stefan Wahren  wrote:
>>
>> Hi Shengyang,
>>
>> [fix address of Emma]
> 
> Not merged to master yet, but Emma has stepped back from maintenance.
> https://lists.freedesktop.org/archives/dri-devel/2023-October/428829.html
> Dropped from the cc.
> 
>> Am 24.11.23 um 11:44 schrieb Shengyang Chen:
>> > This patchset adds waveshare 7inch touchscreen panel support
>> > for the StarFive JH7110 SoC.
>> >
>> > Patch 1 add new compatible for the raspberrypi panel driver and its 
>> > dt-binding.
>> > Patch 2 add new display mode and new probing process for raspberrypi panel 
>> > driver.
>> >
>> > Waveshare 7inch touchscreen panel is a kind of raspberrypi panel
>> > which can be drived by raspberrypi panel driver.
>> >
>> > The series has been tested on the VisionFive 2 board.
>> surprisingly i was recently working on the official Raspberry Pi
>> touchscreen and was able to get it running the new way.
>>
>> What do i mean with the new way. There is almost nothing special to the
>> Raspberry Pi touchscreen, so we should try to use/extend existing
>> components like:
>>
>> CONFIG_DRM_PANEL_SIMPLE
>> CONFIG_TOUCHSCREEN_EDT_FT5X06
>> CONFIG_DRM_TOSHIBA_TC358762
>>
>> The only special part is the Attiny on the connector PCB which requires:
>>
>> CONFIG_REGULATOR_RASPBERRYPI_TOUCHSCREEN_ATTINY
>>
>> So the whole point is to avoid writing monolitic drivers for simple
>> panel like that.
>>
>> There is a WIP branch based on top of Linux 6.7-rcX, which should
>> demonstrate this approach [1]. Unfortunately it is not ready for
>> upstreaming, but it has been tested on a Raspberry Pi 3 B Plus. Maybe
>> this is helpful for your case.
>>
>> Actually i consider panel-raspberrypi-touchscreen.c as a dead end, which
>> shouldn't be extended.
> 
> Agreed.
> 
> The panel control being bound in with the Atmel control has no hook
> for the EDT5x06 touch driver to hook in and keep the power to the
> touch controller active. When the panel disable gets called, bye bye
> touch overlay :-(
> 
> And I'm reading the driver change as more of a hack to get it to work
> on your platform, not as adding support for the Waveshare panel
> variant.
> Waveshare deliberately cloned the behaviour of the Pi 7" panel in
> order to make it work with the old Pi firmware drivers, so it
> shouldn't need any significant changes. Where did the new timings come
> from?
> 
>   Dave
hi Dave :
that's means the panel driver split into 3 sub-modules:
panel + panel_bridge + regulator.

I have a question: in the  
static int rpi_touchscreen_probe(struct i2c_client *i2c)
{
..

ver = rpi_touchscreen_i2c_read(ts, REG_ID);
if (ver < 0) {
dev_err(dev, "Atmel I2C read failed: %d\n", ver);
return -ENODEV;
}

switch (ver) {
case 0xde: /* ver 1 */
case 0xc3: /* ver 2 */
break;
default:
dev_err(dev, "Unknown Atmel firmware revision: 0x%02x\n", ver);
return -ENODEV;
}

..
}
i think this "I2C read" can use to detect whether the panel is connected to dsi 
controller.

and when split the panel driver into 3 sub-modules, it seems the default way is 
connected.
if I drop the panel , run modetest to check the connector status , result 
connected.
Is there any way to detect the connection in this case? 
Thanks



-

Where did the new timings come from?

-
My platform dphy tx hardware has certain limitations.
Only supports integer multiples of 10M bitrate: 
such as 160M ,170M, 180M,190M,...1G(max)

as common dphy bitrate = pixclock*bpp/lanes.
This value cannot match successfully in most cases.

so in order to match bitrate , I choose a bitrate value around 
pixclock*bpp/lanes,
Prevent overflow and underflow by fine-tuning the timing parameters:-(
that will make the new timming value.

> 
>> Btw there are already DT overlays in mainline which seems to use the
>> Raspberry Pi 7inch panel (without touch function yet) [2].
>>
>> [1] - https://github.com/lategoodbye/rpi-zero/commits/v6.7-7inch-ts
>> [2] -
>> https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/arch/arm64/boot/dts/freescale/imx8mm-venice-gw72xx-0x-rpidsi.dtso?h=v6.6.2=6b4da1354fd81adace0cda448c77d8f2a47d8474
>>
>> >
>> > Shengyang Chen (2):
>> >dt-bindings: display: panel: raspberrypi: Add compatible property for
>> >  waveshare 7inch touchscreen panel
>> >gpu: drm: panel: raspberrypi: add new display mode and new probing
>> >  process
>> >
>> >   .../panel/raspberrypi,7inch-touchscreen.yaml  |  4 +-
>> >   .../drm/panel/panel-raspberrypi-touchscreen.c | 99 ---
>> >   2 files changed, 91 insertions(+), 12 deletions(-)
>> >
>>


[v3 0/6] DRM driver for verisilicon

2023-12-04 Thread Keith Zhao
This patch is a drm driver for Starfive Soc JH7110,
I am sending Drm driver part and HDMI driver part.

We used GEM framework for buffer management,
and for buffer allocation,we use DMA APIs.

the Starfive HDMI servers as interface between a LCD Controller 
and a HDMI bus. 
A HDMI TX consists of one HDMI transmitter controller 
and one HDMI transmitter PHY.
(Sound support is not include in this patch)

This patchset should be applied on next branch.

V1:
Changes since v1:
- Further standardize the yaml file.
- Dts naming convention improved.
- Fix the problem of compiling and loading ko files.
- Use drm new api to automatically manage resources.
- Drop vs_crtc_funcs_plane_funcs, subdivide the plane's help interface.
- Reduce the modifiers unused.
- Optimize the hdmi driver code

V2:
Changes since v2:
- fix the error about checking the yaml file.
- match drm driver GEM DMA API.
- Delete the custom crtc property .
- hdmi use drmm_ new api to automatically manage resources.
- update the modifiers comments.
- enabling KASAN, fix the error during removing module 

V3:
Changes since v3:
- Delete the custom plane property.
- Delete the custom fourcc modifiers.
- Adjust the calculation mode of hdmi pixclock.
- Add match data for dc8200 driver.
- Adjust some magic values.
- Add a simple encoder for dsi output.

Keith Zhao (6):
  dt-bindings: display: Add yamls for JH7110 display system
  riscv: dts: starfive: jh7110: display subsystem
  drm/vs: Register DRM device
  drm/vs: Add KMS crtc
  drm/vs: Add hdmi driver
  drm/vs: simple encoder

 .../starfive/starfive,display-subsystem.yaml  |  104 ++
 .../starfive/starfive,dsi-encoder.yaml|   92 ++
 .../starfive/starfive,jh7110-dc8200.yaml  |  113 ++
 .../starfive/starfive,jh7110-inno-hdmi.yaml   |   82 ++
 .../soc/starfive/starfive,jh7110-syscon.yaml  |1 +
 MAINTAINERS   |8 +
 .../jh7110-starfive-visionfive-2.dtsi |  134 ++
 arch/riscv/boot/dts/starfive/jh7110.dtsi  |   49 +
 drivers/gpu/drm/Kconfig   |2 +
 drivers/gpu/drm/Makefile  |1 +
 drivers/gpu/drm/verisilicon/Kconfig   |   21 +
 drivers/gpu/drm/verisilicon/Makefile  |   12 +
 drivers/gpu/drm/verisilicon/starfive_hdmi.c   |  849 
 drivers/gpu/drm/verisilicon/starfive_hdmi.h   |  304 +
 drivers/gpu/drm/verisilicon/vs_crtc.c |  208 +++
 drivers/gpu/drm/verisilicon/vs_crtc.h |   42 +
 drivers/gpu/drm/verisilicon/vs_dc.c   | 1192 +
 drivers/gpu/drm/verisilicon/vs_dc.h   |   67 +
 drivers/gpu/drm/verisilicon/vs_dc_hw.c| 1022 ++
 drivers/gpu/drm/verisilicon/vs_dc_hw.h|  580 
 drivers/gpu/drm/verisilicon/vs_drv.c  |  323 +
 drivers/gpu/drm/verisilicon/vs_drv.h  |   46 +
 drivers/gpu/drm/verisilicon/vs_modeset.c  |   39 +
 drivers/gpu/drm/verisilicon/vs_modeset.h  |   10 +
 drivers/gpu/drm/verisilicon/vs_plane.c|  301 +
 drivers/gpu/drm/verisilicon/vs_plane.h|   39 +
 drivers/gpu/drm/verisilicon/vs_simple_enc.c   |  195 +++
 drivers/gpu/drm/verisilicon/vs_simple_enc.h   |   23 +
 drivers/gpu/drm/verisilicon/vs_type.h |   69 +
 29 files changed, 5928 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/display/starfive/starfive,display-subsystem.yaml
 create mode 100644 
Documentation/devicetree/bindings/display/starfive/starfive,dsi-encoder.yaml
 create mode 100644 
Documentation/devicetree/bindings/display/starfive/starfive,jh7110-dc8200.yaml
 create mode 100644 
Documentation/devicetree/bindings/display/starfive/starfive,jh7110-inno-hdmi.yaml
 create mode 100644 drivers/gpu/drm/verisilicon/Kconfig
 create mode 100644 drivers/gpu/drm/verisilicon/Makefile
 create mode 100644 drivers/gpu/drm/verisilicon/starfive_hdmi.c
 create mode 100644 drivers/gpu/drm/verisilicon/starfive_hdmi.h
 create mode 100644 drivers/gpu/drm/verisilicon/vs_crtc.c
 create mode 100644 drivers/gpu/drm/verisilicon/vs_crtc.h
 create mode 100644 drivers/gpu/drm/verisilicon/vs_dc.c
 create mode 100644 drivers/gpu/drm/verisilicon/vs_dc.h
 create mode 100644 drivers/gpu/drm/verisilicon/vs_dc_hw.c
 create mode 100644 drivers/gpu/drm/verisilicon/vs_dc_hw.h
 create mode 100644 drivers/gpu/drm/verisilicon/vs_drv.c
 create mode 100644 drivers/gpu/drm/verisilicon/vs_drv.h
 create mode 100644 drivers/gpu/drm/verisilicon/vs_modeset.c
 create mode 100644 drivers/gpu/drm/verisilicon/vs_modeset.h
 create mode 100644 drivers/gpu/drm/verisilicon/vs_plane.c
 create mode 100644 drivers/gpu/drm/verisilicon/vs_plane.h
 create mode 100644 drivers/gpu/drm/verisilicon/vs_simple_enc.c
 create mode 100644 drivers/gpu/drm/verisilicon/vs_simple_enc.h
 create mode 100644 drivers/gpu/drm/verisilicon/vs_type.h

-- 
2.34.1



[v3 4/6] drm/vs: Add KMS crtc

2023-12-04 Thread Keith Zhao
add 2 crtcs and 8 planes in vs-drm

Signed-off-by: Keith Zhao 
---
 drivers/gpu/drm/verisilicon/Makefile   |9 +-
 drivers/gpu/drm/verisilicon/vs_crtc.c  |  208 +
 drivers/gpu/drm/verisilicon/vs_crtc.h  |   42 +
 drivers/gpu/drm/verisilicon/vs_dc.c| 1192 
 drivers/gpu/drm/verisilicon/vs_dc.h|   67 ++
 drivers/gpu/drm/verisilicon/vs_dc_hw.c | 1022 
 drivers/gpu/drm/verisilicon/vs_dc_hw.h |  580 
 drivers/gpu/drm/verisilicon/vs_drv.c   |2 +
 drivers/gpu/drm/verisilicon/vs_plane.c |  301 ++
 drivers/gpu/drm/verisilicon/vs_plane.h |   39 +
 drivers/gpu/drm/verisilicon/vs_type.h  |   69 ++
 11 files changed, 3528 insertions(+), 3 deletions(-)
 create mode 100644 drivers/gpu/drm/verisilicon/vs_crtc.c
 create mode 100644 drivers/gpu/drm/verisilicon/vs_crtc.h
 create mode 100644 drivers/gpu/drm/verisilicon/vs_dc.c
 create mode 100644 drivers/gpu/drm/verisilicon/vs_dc.h
 create mode 100644 drivers/gpu/drm/verisilicon/vs_dc_hw.c
 create mode 100644 drivers/gpu/drm/verisilicon/vs_dc_hw.h
 create mode 100644 drivers/gpu/drm/verisilicon/vs_plane.c
 create mode 100644 drivers/gpu/drm/verisilicon/vs_plane.h
 create mode 100644 drivers/gpu/drm/verisilicon/vs_type.h

diff --git a/drivers/gpu/drm/verisilicon/Makefile 
b/drivers/gpu/drm/verisilicon/Makefile
index d785a1dfaa7f..bf6f2b7ee480 100644
--- a/drivers/gpu/drm/verisilicon/Makefile
+++ b/drivers/gpu/drm/verisilicon/Makefile
@@ -1,6 +1,9 @@
 # SPDX-License-Identifier: GPL-2.0
 
-vs_drm-objs := vs_drv.o \
-  vs_modeset.o
-
+vs_drm-objs := vs_dc_hw.o \
+   vs_dc.o \
+   vs_crtc.o \
+   vs_drv.o \
+   vs_modeset.o \
+   vs_plane.o
 obj-$(CONFIG_DRM_VERISILICON) += vs_drm.o
diff --git a/drivers/gpu/drm/verisilicon/vs_crtc.c 
b/drivers/gpu/drm/verisilicon/vs_crtc.c
new file mode 100644
index ..5581219b1230
--- /dev/null
+++ b/drivers/gpu/drm/verisilicon/vs_crtc.c
@@ -0,0 +1,208 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2023 VeriSilicon Holdings Co., Ltd.
+ *
+ */
+
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "vs_crtc.h"
+#include "vs_dc.h"
+#include "vs_drv.h"
+
+static void vs_crtc_atomic_destroy_state(struct drm_crtc *crtc,
+struct drm_crtc_state *state)
+{
+   __drm_atomic_helper_crtc_destroy_state(state);
+   kfree(to_vs_crtc_state(state));
+}
+
+static void vs_crtc_reset(struct drm_crtc *crtc)
+{
+   struct vs_crtc_state *state;
+
+   if (crtc->state)
+   vs_crtc_atomic_destroy_state(crtc, crtc->state);
+
+   state = kzalloc(sizeof(*state), GFP_KERNEL);
+   if (!state)
+   return;
+
+   __drm_atomic_helper_crtc_reset(crtc, >base);
+}
+
+static struct drm_crtc_state *
+vs_crtc_atomic_duplicate_state(struct drm_crtc *crtc)
+{
+   struct vs_crtc_state *old_state;
+   struct vs_crtc_state *state;
+
+   if (!crtc->state)
+   return NULL;
+
+   old_state = to_vs_crtc_state(crtc->state);
+
+   state = kmemdup(old_state, sizeof(*old_state), GFP_KERNEL);
+   if (!state)
+   return NULL;
+
+   __drm_atomic_helper_crtc_duplicate_state(crtc, >base);
+
+   return >base;
+}
+
+static int vs_crtc_enable_vblank(struct drm_crtc *crtc)
+{
+   struct vs_crtc *vs_crtc = to_vs_crtc(crtc);
+   struct vs_dc *dc = dev_get_drvdata(vs_crtc->dev);
+
+   vs_dc_enable_vblank(dc, true);
+
+   return 0;
+}
+
+static void vs_crtc_disable_vblank(struct drm_crtc *crtc)
+{
+   struct vs_crtc *vs_crtc = to_vs_crtc(crtc);
+   struct vs_dc *dc = dev_get_drvdata(vs_crtc->dev);
+
+   vs_dc_enable_vblank(dc, false);
+}
+
+static void vs_crtc_atomic_print_state(struct drm_printer *p,
+  const struct drm_crtc_state *state)
+{
+   struct vs_crtc *vs_crtc = to_vs_crtc(state->crtc);
+
+   drm_printf(p, "vs crtc State\n");
+   drm_printf(p, "\tcolor_formats: %d\n", vs_crtc->color_formats);
+   drm_printf(p, "\tmax_bpc: %d\n", vs_crtc->max_bpc);
+}
+
+static const struct drm_crtc_funcs vs_crtc_funcs = {
+   .set_config = drm_atomic_helper_set_config,
+   .page_flip  = drm_atomic_helper_page_flip,
+   .reset  = vs_crtc_reset,
+   .atomic_duplicate_state = vs_crtc_atomic_duplicate_state,
+   .atomic_destroy_state   = vs_crtc_atomic_destroy_state,
+   .enable_vblank  = vs_crtc_enable_vblank,
+   .disable_vblank = vs_crtc_disable_vblank,
+   .atomic_print_state = vs_crtc_atomic_print_state,
+};
+
+static void vs_crtc_atomic_enable(struct drm_crtc *crtc,
+ struct drm_atomic_state *state)
+{
+   struct vs_crtc *vs_crtc = to_vs

[v3 3/6] drm/vs: Register DRM device

2023-12-04 Thread Keith Zhao
Implement drm device registration interface

Signed-off-by: Keith Zhao 
---
 MAINTAINERS  |   1 +
 drivers/gpu/drm/Kconfig  |   2 +
 drivers/gpu/drm/Makefile |   1 +
 drivers/gpu/drm/verisilicon/Kconfig  |  13 +
 drivers/gpu/drm/verisilicon/Makefile |   6 +
 drivers/gpu/drm/verisilicon/vs_drv.c | 316 +++
 drivers/gpu/drm/verisilicon/vs_drv.h |  42 +++
 drivers/gpu/drm/verisilicon/vs_modeset.c |  39 +++
 drivers/gpu/drm/verisilicon/vs_modeset.h |  10 +
 9 files changed, 430 insertions(+)
 create mode 100644 drivers/gpu/drm/verisilicon/Kconfig
 create mode 100644 drivers/gpu/drm/verisilicon/Makefile
 create mode 100644 drivers/gpu/drm/verisilicon/vs_drv.c
 create mode 100644 drivers/gpu/drm/verisilicon/vs_drv.h
 create mode 100644 drivers/gpu/drm/verisilicon/vs_modeset.c
 create mode 100644 drivers/gpu/drm/verisilicon/vs_modeset.h

diff --git a/MAINTAINERS b/MAINTAINERS
index 7caaadb83f3f..8dc9ebfe4605 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -6887,6 +6887,7 @@ L:dri-devel@lists.freedesktop.org
 S: Maintained
 T: git git://anongit.freedesktop.org/drm/drm-misc
 F: Documentation/devicetree/bindings/display/starfive/
+F: drivers/gpu/drm/verisilicon/
 
 DRM DRIVER FOR TI DLPC3433 MIPI DSI TO DMD BRIDGE
 M: Jagan Teki 
diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig
index 3eee8636f847..e8d53c2e7c86 100644
--- a/drivers/gpu/drm/Kconfig
+++ b/drivers/gpu/drm/Kconfig
@@ -394,6 +394,8 @@ source "drivers/gpu/drm/solomon/Kconfig"
 
 source "drivers/gpu/drm/sprd/Kconfig"
 
+source "drivers/gpu/drm/verisilicon/Kconfig"
+
 config DRM_HYPERV
tristate "DRM Support for Hyper-V synthetic video device"
depends on DRM && PCI && MMU && HYPERV
diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
index 8e1bde059170..29e04acded06 100644
--- a/drivers/gpu/drm/Makefile
+++ b/drivers/gpu/drm/Makefile
@@ -198,3 +198,4 @@ obj-$(CONFIG_DRM_HYPERV) += hyperv/
 obj-y  += solomon/
 obj-$(CONFIG_DRM_SPRD) += sprd/
 obj-$(CONFIG_DRM_LOONGSON) += loongson/
+obj-$(CONFIG_DRM_VERISILICON) += verisilicon/
diff --git a/drivers/gpu/drm/verisilicon/Kconfig 
b/drivers/gpu/drm/verisilicon/Kconfig
new file mode 100644
index ..e10fa97635aa
--- /dev/null
+++ b/drivers/gpu/drm/verisilicon/Kconfig
@@ -0,0 +1,13 @@
+# SPDX-License-Identifier: GPL-2.0
+config DRM_VERISILICON
+   tristate "DRM Support for VeriSilicon"
+   depends on DRM
+   select DRM_KMS_HELPER
+   select DRM_GEM_DMA_HELPER
+   select CMA
+   select DMA_CMA
+   help
+ Choose this option if you have a VeriSilicon soc chipset.
+ This driver provides VeriSilicon kernel mode
+ setting and buffer management. It does not
+ provide 2D or 3D acceleration.
diff --git a/drivers/gpu/drm/verisilicon/Makefile 
b/drivers/gpu/drm/verisilicon/Makefile
new file mode 100644
index ..d785a1dfaa7f
--- /dev/null
+++ b/drivers/gpu/drm/verisilicon/Makefile
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0
+
+vs_drm-objs := vs_drv.o \
+  vs_modeset.o
+
+obj-$(CONFIG_DRM_VERISILICON) += vs_drm.o
diff --git a/drivers/gpu/drm/verisilicon/vs_drv.c 
b/drivers/gpu/drm/verisilicon/vs_drv.c
new file mode 100644
index ..4fb1f29ef84b
--- /dev/null
+++ b/drivers/gpu/drm/verisilicon/vs_drv.c
@@ -0,0 +1,316 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2023 VeriSilicon Holdings Co., Ltd.
+ */
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "vs_drv.h"
+#include "vs_modeset.h"
+
+#define DRV_NAME   "verisilicon"
+#define DRV_DESC   "Verisilicon DRM driver"
+#define DRV_DATE   "20230516"
+#define DRV_MAJOR  1
+#define DRV_MINOR  0
+
+static int vs_gem_dumb_create(struct drm_file *file, struct drm_device *dev,
+ struct drm_mode_create_dumb *args)
+{
+   struct vs_drm_device *priv = to_vs_drm_private(dev);
+   unsigned int pitch = DIV_ROUND_UP(args->width * args->bpp, 8);
+
+   args->pitch = ALIGN(pitch, priv->pitch_alignment);
+   return drm_gem_dma_dumb_create_internal(file, dev, args);
+}
+
+DEFINE_DRM_GEM_FOPS(vs_drm_fops);
+
+static struct drm_driver vs_drm_driver = {
+   .driver_features= DRIVER_MODESET | DRIVER_ATOMIC | DRIVER_GEM,
+
+   DRM_GEM_DMA_DRIVER_OPS_WITH_DUMB_CREATE(vs_gem_dumb_create),
+
+   .fops   = _drm_fops,
+   .name   = DRV_NAME,
+   .desc   = DRV_DESC,
+   .date   = DRV_DATE,
+   .major  = DRV_MAJOR,
+   .minor  = D

[v3 5/6] drm/vs: Add hdmi driver

2023-12-04 Thread Keith Zhao
add hdmi driver as encoder and connect

Signed-off-by: Keith Zhao 
---
 drivers/gpu/drm/verisilicon/Kconfig |   8 +
 drivers/gpu/drm/verisilicon/Makefile|   1 +
 drivers/gpu/drm/verisilicon/starfive_hdmi.c | 849 
 drivers/gpu/drm/verisilicon/starfive_hdmi.h | 304 +++
 drivers/gpu/drm/verisilicon/vs_drv.c|   3 +
 drivers/gpu/drm/verisilicon/vs_drv.h|   4 +
 6 files changed, 1169 insertions(+)
 create mode 100644 drivers/gpu/drm/verisilicon/starfive_hdmi.c
 create mode 100644 drivers/gpu/drm/verisilicon/starfive_hdmi.h

diff --git a/drivers/gpu/drm/verisilicon/Kconfig 
b/drivers/gpu/drm/verisilicon/Kconfig
index e10fa97635aa..122c786e3948 100644
--- a/drivers/gpu/drm/verisilicon/Kconfig
+++ b/drivers/gpu/drm/verisilicon/Kconfig
@@ -11,3 +11,11 @@ config DRM_VERISILICON
  This driver provides VeriSilicon kernel mode
  setting and buffer management. It does not
  provide 2D or 3D acceleration.
+
+config DRM_VERISILICON_STARFIVE_HDMI
+   bool "Starfive HDMI extensions"
+   depends on DRM_VERISILICON
+   help
+  This selects support for StarFive soc specific extensions
+  for the Innosilicon HDMI driver. If you want to enable
+  HDMI on JH7110 based soc, you should select this option.
diff --git a/drivers/gpu/drm/verisilicon/Makefile 
b/drivers/gpu/drm/verisilicon/Makefile
index bf6f2b7ee480..71fadafcee13 100644
--- a/drivers/gpu/drm/verisilicon/Makefile
+++ b/drivers/gpu/drm/verisilicon/Makefile
@@ -6,4 +6,5 @@ vs_drm-objs := vs_dc_hw.o \
vs_drv.o \
vs_modeset.o \
vs_plane.o
+vs_drm-$(CONFIG_DRM_VERISILICON_STARFIVE_HDMI) += starfive_hdmi.o
 obj-$(CONFIG_DRM_VERISILICON) += vs_drm.o
diff --git a/drivers/gpu/drm/verisilicon/starfive_hdmi.c 
b/drivers/gpu/drm/verisilicon/starfive_hdmi.c
new file mode 100644
index ..aa621db0dee0
--- /dev/null
+++ b/drivers/gpu/drm/verisilicon/starfive_hdmi.c
@@ -0,0 +1,849 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2023 StarFive Technology Co., Ltd.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "starfive_hdmi.h"
+#include "vs_drv.h"
+#include "vs_crtc.h"
+
+static const char * const hdmi_clocks[] = {
+   "sysclk",
+   "mclk",
+   "bclk"
+};
+
+static struct starfive_hdmi_encoder *encoder_to_hdmi(struct drm_encoder 
*encoder)
+{
+   return container_of(encoder, struct starfive_hdmi_encoder, encoder);
+}
+
+static struct starfive_hdmi *connector_to_hdmi(struct drm_connector *connector)
+{
+   return container_of(connector, struct starfive_hdmi, connector);
+}
+
+static const struct post_pll_config post_pll_cfg_table[] = {
+   {2520,  1, 80, 13, 3, 1},
+   {2700,  1, 40, 11, 3, 1},
+   {3375,  1, 40, 11, 3, 1},
+   {4900,  1, 20, 1, 3, 3},
+   {24170, 1, 20, 1, 3, 3},
+   {29700, 4, 20, 0, 0, 3},
+   {59400, 4, 20, 0, 0, 0},
+   { /* sentinel */ }
+};
+
+inline u8 hdmi_readb(struct starfive_hdmi *hdmi, u16 offset)
+{
+   return readl_relaxed(hdmi->regs + (offset) * 0x04);
+}
+
+inline void hdmi_writeb(struct starfive_hdmi *hdmi, u16 offset, u32 val)
+{
+   writel_relaxed(val, hdmi->regs + (offset) * 0x04);
+}
+
+inline void hdmi_writew(struct starfive_hdmi *hdmi, u16 offset, u32 val)
+{
+   writew_relaxed(val & 0xFF, hdmi->regs + (offset) * 0x04);
+   writew_relaxed((val >> 8) & 0xFF, hdmi->regs + (offset + 1) * 0x04);
+}
+
+inline void hdmi_modb(struct starfive_hdmi *hdmi, u16 offset,
+u32 msk, u32 val)
+{
+   u8 temp = hdmi_readb(hdmi, offset) & ~msk;
+
+   temp |= val & msk;
+   hdmi_writeb(hdmi, offset, temp);
+}
+
+static int starfive_hdmi_enable_clk_deassert_rst(struct device *dev, struct 
starfive_hdmi *hdmi)
+{
+   int ret;
+
+   ret = clk_bulk_prepare_enable(hdmi->nclks, hdmi->clk_hdmi);
+   if (ret) {
+   dev_err(dev, "failed to enable clocks\n");
+   return ret;
+   }
+
+   ret = reset_control_deassert(hdmi->tx_rst);
+   if (ret < 0) {
+   dev_err(dev, "failed to deassert tx_rst\n");
+   return ret;
+   }
+   return 0;
+}
+
+static void starfive_hdmi_disable_clk_assert_rst(struct device *dev, struct 
starfive_hdmi *hdmi)
+{
+   int ret;
+
+   ret = reset_control_assert(hdmi->tx_rst);
+   if (ret < 0)
+   dev_err(dev, "failed to assert tx_rst\n");
+
+   clk_bulk_disable_unprepare(hdmi->nclks, hdmi->clk_hdmi);
+}
+
+#ifdef CONFIG_PM_SLEEP
+static int hdmi_syste

[v3 6/6] drm/vs: simple encoder

2023-12-04 Thread Keith Zhao
add simple encoder for dsi bridge

Signed-off-by: Keith Zhao 
---
 drivers/gpu/drm/verisilicon/Makefile|   4 +-
 drivers/gpu/drm/verisilicon/vs_drv.c|   2 +
 drivers/gpu/drm/verisilicon/vs_simple_enc.c | 195 
 drivers/gpu/drm/verisilicon/vs_simple_enc.h |  23 +++
 4 files changed, 223 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/verisilicon/vs_simple_enc.c
 create mode 100644 drivers/gpu/drm/verisilicon/vs_simple_enc.h

diff --git a/drivers/gpu/drm/verisilicon/Makefile 
b/drivers/gpu/drm/verisilicon/Makefile
index 71fadafcee13..cd5d0a90bcfe 100644
--- a/drivers/gpu/drm/verisilicon/Makefile
+++ b/drivers/gpu/drm/verisilicon/Makefile
@@ -5,6 +5,8 @@ vs_drm-objs := vs_dc_hw.o \
vs_crtc.o \
vs_drv.o \
vs_modeset.o \
-   vs_plane.o
+   vs_plane.o \
+   vs_simple_enc.o
+
 vs_drm-$(CONFIG_DRM_VERISILICON_STARFIVE_HDMI) += starfive_hdmi.o
 obj-$(CONFIG_DRM_VERISILICON) += vs_drm.o
diff --git a/drivers/gpu/drm/verisilicon/vs_drv.c 
b/drivers/gpu/drm/verisilicon/vs_drv.c
index d7e5199fe293..946f137ab124 100644
--- a/drivers/gpu/drm/verisilicon/vs_drv.c
+++ b/drivers/gpu/drm/verisilicon/vs_drv.c
@@ -23,6 +23,7 @@
 #include "vs_drv.h"
 #include "vs_modeset.h"
 #include "vs_dc.h"
+#include "vs_simple_enc.h"
 
 #define DRV_NAME   "verisilicon"
 #define DRV_DESC   "Verisilicon DRM driver"
@@ -217,6 +218,7 @@ static struct platform_driver *drm_sub_drivers[] = {
 #ifdef CONFIG_DRM_VERISILICON_STARFIVE_HDMI
_hdmi_driver,
 #endif
+   _encoder_driver,
 };
 
 static struct component_match *vs_drm_match_add(struct device *dev)
diff --git a/drivers/gpu/drm/verisilicon/vs_simple_enc.c 
b/drivers/gpu/drm/verisilicon/vs_simple_enc.c
new file mode 100644
index ..c5a8d82bc469
--- /dev/null
+++ b/drivers/gpu/drm/verisilicon/vs_simple_enc.c
@@ -0,0 +1,195 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2020 VeriSilicon Holdings Co., Ltd.
+ */
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "vs_crtc.h"
+#include "vs_simple_enc.h"
+
+static const struct simple_encoder_priv dsi_priv = {
+   .encoder_type = DRM_MODE_ENCODER_DSI
+};
+
+static inline struct simple_encoder *to_simple_encoder(struct drm_encoder *enc)
+{
+   return container_of(enc, struct simple_encoder, encoder);
+}
+
+static int encoder_parse_dt(struct device *dev)
+{
+   struct simple_encoder *simple = dev_get_drvdata(dev);
+   unsigned int args[2];
+
+   simple->dss_regmap = syscon_regmap_lookup_by_phandle_args(dev->of_node,
+ 
"starfive,syscon",
+ 2, args);
+
+   if (IS_ERR(simple->dss_regmap)) {
+   return dev_err_probe(dev, PTR_ERR(simple->dss_regmap),
+"getting the regmap failed\n");
+   }
+
+   simple->offset = args[0];
+   simple->mask = args[1];
+
+   return 0;
+}
+
+void encoder_atomic_enable(struct drm_encoder *encoder,
+  struct drm_atomic_state *state)
+{
+   struct simple_encoder *simple = to_simple_encoder(encoder);
+
+   regmap_update_bits(simple->dss_regmap, simple->offset, simple->mask,
+  simple->mask);
+}
+
+int encoder_atomic_check(struct drm_encoder *encoder,
+struct drm_crtc_state *crtc_state,
+struct drm_connector_state *conn_state)
+{
+   struct vs_crtc_state *vs_crtc_state = to_vs_crtc_state(crtc_state);
+   struct drm_connector *connector = conn_state->connector;
+   int ret = 0;
+
+   struct drm_bridge *first_bridge = 
drm_bridge_chain_get_first_bridge(encoder);
+   struct drm_bridge_state *bridge_state = ERR_PTR(-EINVAL);
+
+   vs_crtc_state->encoder_type = encoder->encoder_type;
+
+   if (first_bridge && first_bridge->funcs->atomic_duplicate_state)
+   bridge_state = drm_atomic_get_bridge_state(crtc_state->state, 
first_bridge);
+
+   if (IS_ERR(bridge_state)) {
+   if (connector->display_info.num_bus_formats)
+   vs_crtc_state->output_fmt = 
connector->display_info.bus_formats[0];
+   else
+   vs_crtc_state->output_fmt = MEDIA_BUS_FMT_FIXED;
+   } else {
+   vs_crtc_state->output_fmt = bridge_state->input_bus_cfg.format;
+   }
+
+   switch (vs_crtc_state->output_fmt) {
+   case MEDIA_BUS_FMT_FIXED:
+   case MEDIA_BUS_FMT_RGB565_1X16:
+   case MEDIA_BUS_FMT_RGB666_1X18:
+   case MEDIA_BUS_FMT_RGB888_1X24:
+   case MEDIA_BUS_FMT_RGB666_1X24_CPADHI

[v3 1/6] dt-bindings: display: Add yamls for JH7110 display system

2023-12-04 Thread Keith Zhao
StarFive SoCs JH7110 display system:
dc controller, hdmi controller,
encoder, vout syscon.

add the path of yaml file in MAINTAINERS

Signed-off-by: Keith Zhao 
---
 .../starfive/starfive,display-subsystem.yaml  | 104 
 .../starfive/starfive,dsi-encoder.yaml|  92 ++
 .../starfive/starfive,jh7110-dc8200.yaml  | 113 ++
 .../starfive/starfive,jh7110-inno-hdmi.yaml   |  82 +
 .../soc/starfive/starfive,jh7110-syscon.yaml  |   1 +
 MAINTAINERS   |   7 ++
 6 files changed, 399 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/display/starfive/starfive,display-subsystem.yaml
 create mode 100644 
Documentation/devicetree/bindings/display/starfive/starfive,dsi-encoder.yaml
 create mode 100644 
Documentation/devicetree/bindings/display/starfive/starfive,jh7110-dc8200.yaml
 create mode 100644 
Documentation/devicetree/bindings/display/starfive/starfive,jh7110-inno-hdmi.yaml

diff --git 
a/Documentation/devicetree/bindings/display/starfive/starfive,display-subsystem.yaml
 
b/Documentation/devicetree/bindings/display/starfive/starfive,display-subsystem.yaml
new file mode 100644
index ..d5ebdba3fb36
--- /dev/null
+++ 
b/Documentation/devicetree/bindings/display/starfive/starfive,display-subsystem.yaml
@@ -0,0 +1,104 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: 
http://devicetree.org/schemas/display/starfive/starfive,display-subsystem.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Starfive JH7110 Soc Display SubSystem
+
+maintainers:
+  - Keith Zhao 
+  - ShengYang Chen 
+
+description:
+  This is the bindings documentation for the JH7110 Soc Display Subsystem that
+  includes front-end video data capture, display controller and display
+  interface. such as HDMI and MIPI.
+
+  JH7110 display pipeline have several components as below description,
+  multi display controllers and corresponding physical interfaces.
+  For different display scenarios, pipe0 and pipe1 maybe binding to different
+  encoder. for example,
+
+  pipe0 binding to HDMI for primary display,
+  pipe1 binding to DSI for external display.
+
+  +--+
+  |  |
+  |  |
+  ++  |   +---+  |   +---+   +--+   +--+
+  |+->+  dc controller 0  +--->->+HDMICtl| ->+ PHY  +-->+PANEL0+
+  |AXI |  |   +---+  |   +---+   +--+   +--+
+  ||  |  |
+  ||  |  |
+  ||  |  |
+  ||  |  |
+  |APB |  |   +---+ +-++--+  +---+
+  |+->+  dc controller 1  +--->>+ dsiTx   +--->+DPHY  +->+ PANEL1+
+  ||  |   +---+ +-++--+  +---+
+  ++  |  |
+  +--+
+
+
+properties:
+  compatible:
+const: starfive,display-subsystem
+
+  clocks:
+items:
+  - description: Clock for display system noc bus.
+  - description: Core clock for display controller.
+  - description: Clock for axi bus to access ddr.
+  - description: Clock for ahb bus to R/W the phy regs.
+
+  clock-names:
+items:
+  - const: noc_bus
+  - const: dc_core
+  - const: axi_core
+  - const: ahb
+
+  resets:
+items:
+  - description: Reset for axi bus.
+  - description: Reset for ahb bus.
+  - description: Core reset of display controller.
+
+  reset-names:
+items:
+  - const: axi
+  - const: ahb
+  - const: core
+
+  ports:
+$ref: /schemas/types.yaml#/definitions/phandle-array
+items:
+  maxItems: 1
+description:
+  Should contain a list of phandles pointing to display interface port
+  of dc-controller devices.
+
+required:
+  - compatible
+  - clocks
+  - clock-names
+  - resets
+  - reset-names
+  - ports
+
+additionalProperties: false
+
+examples:
+  - |
+display-subsystem {
+compatible = "starfive,display-subsystem";
+ports = <_out>;
+
+clocks = < 60>,
+   < 4>,
+   < 5>,
+   < 6>;
+clock-names = "noc_bus", "dc_core", "axi_core", "ahb";
+resets = < 0>, < 1>, < 2>;
+reset-names = "axi", "ahb", "core";
+};
diff --git 
a/Documentation/devicetree/bindings/display/starfive/starfive,dsi-encoder.yaml 
b/Documentation/devicetree/bindings/display/starfive/starfive,dsi-encoder.yaml
new file mode 100644
index ..2cc0ad8e65ba
--- /dev/null
+++ 
b/Documentation/devicetree/bindings/display/starfive/starfive,dsi-encoder.

[v3 2/6] riscv: dts: starfive: jh7110: display subsystem

2023-12-04 Thread Keith Zhao
Add the dc controller and hdmi node for the Starfive JH7110 SoC.

Signed-off-by: Keith Zhao 
---
 .../jh7110-starfive-visionfive-2.dtsi | 134 ++
 arch/riscv/boot/dts/starfive/jh7110.dtsi  |  49 +++
 2 files changed, 183 insertions(+)

diff --git a/arch/riscv/boot/dts/starfive/jh7110-starfive-visionfive-2.dtsi 
b/arch/riscv/boot/dts/starfive/jh7110-starfive-visionfive-2.dtsi
index b89e9791efa7..6e387e0138c0 100644
--- a/arch/riscv/boot/dts/starfive/jh7110-starfive-visionfive-2.dtsi
+++ b/arch/riscv/boot/dts/starfive/jh7110-starfive-visionfive-2.dtsi
@@ -35,6 +35,25 @@ memory@4000 {
reg = <0x0 0x4000 0x1 0x0>;
};
 
+   reserved-memory {
+   #address-cells = <2>;
+   #size-cells = <2>;
+   ranges;
+
+   /* vout applies for space from this CMA
+* Without this CMA reservation,
+* vout may not work properly.
+*/
+   linux,cma {
+   compatible = "shared-dma-pool";
+   reusable;
+   size = <0x0 0x2000>;
+   alignment = <0x0 0x1000>;
+   alloc-ranges = <0x0 0x7000 0x0 0x2000>;
+   linux,cma-default;
+   };
+   };
+
gpio-restart {
compatible = "gpio-restart";
gpios = < 35 GPIO_ACTIVE_HIGH>;
@@ -69,6 +88,68 @@ codec {
};
 };
 
+ {
+   status = "okay";
+
+   crtc_out: ports {
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   dc_out0: port@0 {
+   reg = <0>;
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   dc_out_dpi0: endpoint@0 {
+   reg = <0>;
+   remote-endpoint = <_enc>;
+   };
+
+   };
+
+   dc_out1: port@1 {
+   reg = <1>;
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   dc_out_dpi1: endpoint@1 {
+   reg = <1>;
+   remote-endpoint = <_enc>;
+   };
+
+   };
+   };
+};
+
+ {
+   status = "okay";
+   ports = <_out>;
+};
+
+_encoder {
+   status = "okay";
+
+   ports {
+   #address-cells = <1>;
+   #size-cells = <0>;
+   /* input */
+   enc_in: port@0 {
+   #address-cells = <1>;
+   #size-cells = <0>;
+   reg = <0>;
+   dsi_enc:endpoint@0 {
+   reg = <0>;
+   remote-endpoint = <_out_dpi1>;
+   };
+   };
+   /* output */
+   enc_out: port@1 {
+   reg = <1>;
+   /*need add a remote-endpoint to dsi bridge*/
+   };
+   };
+};
+
 _clk {
clock-frequency = <7425>;
 };
@@ -89,6 +170,21 @@ _rmii_refin {
clock-frequency = <5000>;
 };
 
+ {
+   status = "okay";
+   pinctrl-names = "default";
+   pinctrl-0 = <_pins>;
+
+   hdmi_in: port {
+   #address-cells = <1>;
+   #size-cells = <0>;
+   hdmi_enc: endpoint@0 {
+   reg = <0>;
+   remote-endpoint = <_out_dpi0>;
+   };
+   };
+};
+
 _pixelclk {
clock-frequency = <29700>;
 };
@@ -336,6 +432,40 @@ spi_dev0: spi@0 {
 };
 
  {
+   hdmi_pins: hdmi-0 {
+   hdmi-cec-pins {
+   pinmux = ;
+   input-enable;
+   bias-pull-up;
+   };
+
+   hdmi-hpd-pins {
+   pinmux = ;
+   input-enable;
+   bias-disable; /* external pull-up */
+   };
+
+   hdmi-scl-pins {
+   pinmux = ;
+   input-enable;
+   bias-pull-up;
+   };
+
+   hdmi-sda-pins {
+   pinmux = ;
+   input-enable;
+   bias-pull-up;
+   };
+   };
+
i2c0_pins: i2c0-0 {
i2c-pins {
pinmux = ;
 };
+
+ {
+   status = "okay";
+};
diff --git a/arch/riscv/boot/dts/starfive/jh7110.dtsi 
b/arch/riscv/boot/dts/starfive/jh7110.dtsi
index 45213cdf50

Re: [PATCH v2 1/6] dt-bindings: display: Add yamls for JH7110 display system

2023-11-28 Thread Keith Zhao



On 2023/10/25 20:50, Krzysztof Kozlowski wrote:
> On 25/10/2023 12:39, Keith Zhao wrote:
>> StarFive SoCs JH7110 display system:
> 
> A nit, subject: drop second/last, redundant "yamls for". The
> "dt-bindings" prefix is already stating that these are bindings, so
> format is fixed.
> 
>> lcd-controller bases verisilicon dc8200 IP,
>> and hdmi bases Innosilicon IP. Add bindings for them.
> 
> Please make it a proper sentences, with proper wrapping.
> 
>> 
>> also update MAINTAINERS for dt-bindings
> 
> Not a sentence, but also not really needed.ok I see.
> 
>> 
>> about this patch, I tested the dtbs_check and dt_binding_check
>> with the result pass.
>> Based on the feedback of the previous version, the corresponding arrangement 
>> is made
> 
> Not relevant, so not really suitable for commit msg.
> 
>> 
>> Signed-off-by: Keith Zhao 
>> ---
>>  .../starfive/starfive,display-subsystem.yaml  |  41 +++
>>  .../starfive/starfive,jh7110-dc8200.yaml  | 109 ++
>>  .../starfive/starfive,jh7110-inno-hdmi.yaml   |  85 ++
>>  MAINTAINERS   |   7 ++
>>  4 files changed, 242 insertions(+)
>>  create mode 100644 
>> Documentation/devicetree/bindings/display/starfive/starfive,display-subsystem.yaml
>>  create mode 100644 
>> Documentation/devicetree/bindings/display/starfive/starfive,jh7110-dc8200.yaml
>>  create mode 100644 
>> Documentation/devicetree/bindings/display/starfive/starfive,jh7110-inno-hdmi.yaml
>> 
>> diff --git 
>> a/Documentation/devicetree/bindings/display/starfive/starfive,display-subsystem.yaml
>>  
>> b/Documentation/devicetree/bindings/display/starfive/starfive,display-subsystem.yaml
>> new file mode 100644
>> index 0..f45b97b08
>> --- /dev/null
>> +++ 
>> b/Documentation/devicetree/bindings/display/starfive/starfive,display-subsystem.yaml
>> @@ -0,0 +1,41 @@
>> +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
>> +%YAML 1.2
>> +---
>> +$id: 
>> http://devicetree.org/schemas/display/starfive/starfive,display-subsystem.yaml#
>> +$schema: http://devicetree.org/meta-schemas/core.yaml#
>> +
>> +title: Starfive DRM master device
> 
> What is DRM in hardware? I know Digital Rights Management, but then
> subsystem seems wrong. If you mean Linux DRM, then Linux is not a
> hardware, so drop all Linuxisms and describe hardware.
ok , will only keep hardware describe in my next version
> 
> 
>> +
>> +maintainers:
>> +  - Keith Zhao 
>> +  - ShengYang Chen 
>> +
>> +description:
>> +  The Starfive DRM master device is a virtual device needed to list all
> 
> Virtual device? Then not suitable for bindings, sorry.
> 
>> +  display controller or other display interface nodes that comprise the
>> +  graphics subsystem.
>> +
>> +properties:
>> +  compatible:
>> +const: starfive,display-subsystem
>> +
>> +  ports:
>> +$ref: /schemas/types.yaml#/definitions/phandle-array
> 
> No, ports is not phandle-array. ports is object, always.
> 
>> +description:
>> +  Should contain a list of phandles pointing to display interface ports
>> +  of display controller devices. Display controller definitions as 
>> defined
>> +  in Documentation/devicetree/bindings/display/starfive/
>> +  starfive,jh7110-dc8200.yaml
> 
> Use standard graph ports, not some own, custom property.
> 
> Anyway, entire binding should be dropped. You do not need it even.
Hi Krzysztof:
Virtual device is not suitable for bindings, matbe I need associate it with the 
real hardware.
such as the top clocks & reset , irq , etc.
Currently I configure them in another yaml file. Logically speaking, this is 
more suitable.

Can adding the corresponding hardware description change its fate of being 
deleted?
 
> 
>> +
>> +required:
>> +  - compatible
>> +  - ports
>> +
>> +additionalProperties: false
>> +
>> +examples:
>> +  - |
>> +display-subsystem {
>> +compatible = "starfive,display-subsystem";
>> +ports = <_out>;
>> +};
>> diff --git 
>> a/Documentation/devicetree/bindings/display/starfive/starfive,jh7110-dc8200.yaml
>>  
>> b/Documentation/devicetree/bindings/display/starfive/starfive,jh7110-dc8200.yaml
>> new file mode 100644
>> index 0..87051cddf
>> --- /dev/null
>> +++ 
>> b/Documentation/devicetree/bindings/display/starfive/starfive,jh7110-dc8200.yaml

Re: [PATCH v2 5/6] drm/vs: Add KMS crtc

2023-11-15 Thread Keith Zhao



On 2023/10/25 21:57, Maxime Ripard wrote:
> On Wed, Oct 25, 2023 at 06:39:56PM +0800, Keith Zhao wrote:
>> +static struct drm_crtc_state *
>> +vs_crtc_atomic_duplicate_state(struct drm_crtc *crtc)
>> +{
>> +struct vs_crtc_state *ori_state;
>> +struct vs_crtc_state *state;
>> +
>> +if (!crtc->state)
>> +return NULL;
>> +
>> +ori_state = to_vs_crtc_state(crtc->state);
>> +state = kzalloc(sizeof(*state), GFP_KERNEL);
>> +if (!state)
>> +return NULL;
>> +
>> +__drm_atomic_helper_crtc_duplicate_state(crtc, >base);
>> +
>> +state->output_fmt = ori_state->output_fmt;
> 
> That field is never set in your patch.
> 
>> +state->encoder_type = ori_state->encoder_type;
> 
> That isn't either, and it's not clear why you would need the
> encoder_type stored in the CRTC?
> 
>> +state->bpp = ori_state->bpp;
> 
> You seem to derive that from output_fmt, it doesn't need to be in the
> CRTC state.
> 
>> +state->underflow = ori_state->underflow;
> 
> Assuming you're setting this from the interrupt handler, it's unsafe,
> you shouldn't do that. What are you using it for?
I am going to use the crtc_debugfs function for printing.
crtc_debugfs  will use it
But now I'd better delete it

> 
>> +static const struct drm_prop_enum_list vs_sync_mode_enum_list[] = {
>> +{ VS_SINGLE_DC, "single dc mode" },
>> +{ VS_MULTI_DC_PRIMARY,  "primary dc for multi dc mode" },
>> +{ VS_MULTI_DC_SECONDARY,"secondary dc for multi dc mode" },
>> +};
> 
> Custom driver properties are a no-go:
> https://docs.kernel.org/gpu/drm-kms.html#requirements
> 
> And
> 
> https://docs.kernel.org/gpu/drm-uapi.html#open-source-userspace-requirements
> 
>> +void vs_dc_enable(struct vs_dc *dc, struct drm_crtc *crtc)
>> +{
>> +struct vs_crtc_state *crtc_state = to_vs_crtc_state(crtc->state);
>> +struct drm_display_mode *mode = >state->adjusted_mode;
>> +struct dc_hw_display display;
> 
> Why are you rolling your own structure here, if it's exactly equivalent
> to what drm_display_mode and the crtc_state provide?
My original intention was to make the hardware part purer. and 
want to decouple hardware from drm struct.

so I define the own structure  between drm and hardware.
Maybe doing this will make both the hardware and drm happy

> 
>> +void vs_dc_commit(struct vs_dc *dc)
>> +{
>> +dc_hw_enable_shadow_register(>hw, false);
>> +
>> +dc_hw_commit(>hw);
>> +
>> +if (dc->first_frame)
>> +dc->first_frame = false;
>> +
>> +dc_hw_enable_shadow_register(>hw, true);
>> +}
> 
> It's not clear to me what you're trying to do here, does the hardware
> have latched registers that are only updated during vblank?
> 
>> +static int dc_bind(struct device *dev, struct device *master, void *data)
>> +{
>> +struct drm_device *drm_dev = data;
>> +struct vs_dc *dc = dev_get_drvdata(dev);
>> +struct device_node *port;
>> +struct vs_crtc *crtc;
>> +struct vs_dc_info *dc_info;
>> +struct vs_plane *plane;
>> +struct vs_plane_info *plane_info;
>> +int i, ret;
>> +u32 ctrc_mask = 0;
>> +
>> +if (!drm_dev || !dc) {
>> +dev_err(dev, "devices are not created.\n");
>> +return -ENODEV;
>> +}
>> +
>> +ret = dc_init(dev);
>> +if (ret < 0) {
>> +drm_err(drm_dev, "Failed to initialize DC hardware.\n");
>> +return ret;
>> +}
>> +
>> +port = of_get_child_by_name(dev->of_node, "port");
>> +if (!port) {
>> +drm_err(drm_dev, "no port node found\n");
>> +return -ENODEV;
>> +}
>> +of_node_put(port);
>> +
>> +dc_info = dc->hw.info;
>> +
>> +for (i = 0; i < dc_info->panel_num; i++) {
>> +crtc = vs_crtc_create(drm_dev, dc_info);
>> +if (!crtc) {
>> +drm_err(drm_dev, "Failed to create CRTC.\n");
>> +ret = -ENOMEM;
>> +return ret;
>> +}
>> +
>> +crtc->base.port = port;
>> +crtc->dev = dev;
>> +dc->crtc[i] = crtc;
>> +ctrc_mask |= drm_crtc_mask(>base);
>> +}
>> +
>> +for (i = 

Re: [PATCH v2 3/6] drm/fourcc: Add drm/vs tiled modifiers

2023-11-15 Thread Keith Zhao
ok, I will do this in my next patch
Thanks your advice!

On 2023/10/25 23:44, Simon Ser wrote:
>  it seems like you could start with just simple
> enumerated modifiers like Intel does, and then only switch to more
> complicated logic with macros and fields if there is an actual need in
> the future.


Re: [PATCH v2 5/6] drm/vs: Add KMS crtc

2023-11-14 Thread Keith Zhao



On 2023/10/26 3:28, Dmitry Baryshkov wrote:
> On 25/10/2023 13:39, Keith Zhao wrote:
>> add 2 crtcs and 8 planes in vs-drm
>> 
>> Signed-off-by: Keith Zhao 
>> ---
>>   drivers/gpu/drm/verisilicon/Makefile   |8 +-
>>   drivers/gpu/drm/verisilicon/vs_crtc.c  |  257 
>>   drivers/gpu/drm/verisilicon/vs_crtc.h  |   43 +
>>   drivers/gpu/drm/verisilicon/vs_dc.c| 1002 
>>   drivers/gpu/drm/verisilicon/vs_dc.h|   80 +
>>   drivers/gpu/drm/verisilicon/vs_dc_hw.c | 1959 
>>   drivers/gpu/drm/verisilicon/vs_dc_hw.h |  492 ++
>>   drivers/gpu/drm/verisilicon/vs_drv.c   |2 +
>>   drivers/gpu/drm/verisilicon/vs_plane.c |  526 +++
>>   drivers/gpu/drm/verisilicon/vs_plane.h |   58 +
>>   drivers/gpu/drm/verisilicon/vs_type.h  |   69 +
>>   11 files changed, 4494 insertions(+), 2 deletions(-)
>>   create mode 100644 drivers/gpu/drm/verisilicon/vs_crtc.c
>>   create mode 100644 drivers/gpu/drm/verisilicon/vs_crtc.h
>>   create mode 100644 drivers/gpu/drm/verisilicon/vs_dc.c
>>   create mode 100644 drivers/gpu/drm/verisilicon/vs_dc.h
>>   create mode 100644 drivers/gpu/drm/verisilicon/vs_dc_hw.c
>>   create mode 100644 drivers/gpu/drm/verisilicon/vs_dc_hw.h
>>   create mode 100644 drivers/gpu/drm/verisilicon/vs_plane.c
>>   create mode 100644 drivers/gpu/drm/verisilicon/vs_plane.h
>>   create mode 100644 drivers/gpu/drm/verisilicon/vs_type.h
>> 
>> diff --git a/drivers/gpu/drm/verisilicon/Makefile 
>> b/drivers/gpu/drm/verisilicon/Makefile
>> index 7d3be305b..1d48016ca 100644
>> --- a/drivers/gpu/drm/verisilicon/Makefile
>> +++ b/drivers/gpu/drm/verisilicon/Makefile
>> @@ -1,7 +1,11 @@
>>   # SPDX-License-Identifier: GPL-2.0
>>   
>> -vs_drm-objs := vs_drv.o \
>> -vs_modeset.o
>> +vs_drm-objs := vs_dc_hw.o \
>> +vs_dc.o \
>> +vs_crtc.o \
>> +vs_drv.o \
>> +vs_modeset.o \
>> +vs_plane.o
>>   
>>   obj-$(CONFIG_DRM_VERISILICON) += vs_drm.o
>>   
>> diff --git a/drivers/gpu/drm/verisilicon/vs_crtc.c 
>> b/drivers/gpu/drm/verisilicon/vs_crtc.c
>> new file mode 100644
>> index 0..8a658ea77
>> --- /dev/null
>> +++ b/drivers/gpu/drm/verisilicon/vs_crtc.c
>> @@ -0,0 +1,257 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +/*
>> + * Copyright (C) 2023 VeriSilicon Holdings Co., Ltd.
>> + *
>> + */
>> +
>> +#include 
>> +#include 
>> +#include 
>> +
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +
>> +#include "vs_crtc.h"
>> +#include "vs_dc.h"
>> +#include "vs_drv.h"
>> +
>> +static void vs_crtc_reset(struct drm_crtc *crtc)
>> +{
>> +struct vs_crtc_state *state;
>> +
>> +if (crtc->state) {
>> +__drm_atomic_helper_crtc_destroy_state(crtc->state);
>> +
>> +state = to_vs_crtc_state(crtc->state);
>> +kfree(state);
>> +crtc->state = NULL;
>> +}
> 
> You can call your crtc_destroy_state function directly here.
> 
>> +
>> +state = kzalloc(sizeof(*state), GFP_KERNEL);
>> +if (!state)
>> +return;
>> +
>> +__drm_atomic_helper_crtc_reset(crtc, >base);
>> +}
>> +
>> +static struct drm_crtc_state *
>> +vs_crtc_atomic_duplicate_state(struct drm_crtc *crtc)
>> +{
>> +struct vs_crtc_state *ori_state;
> 
> It might be a matter of taste, but it is usually old_state.
> 
>> +struct vs_crtc_state *state;
>> +
>> +if (!crtc->state)
>> +return NULL;
>> +
>> +ori_state = to_vs_crtc_state(crtc->state);
>> +state = kzalloc(sizeof(*state), GFP_KERNEL);
>> +if (!state)
>> +return NULL;
>> +
>> +__drm_atomic_helper_crtc_duplicate_state(crtc, >base);
>> +
>> +state->output_fmt = ori_state->output_fmt;
>> +state->encoder_type = ori_state->encoder_type;
>> +state->bpp = ori_state->bpp;
>> +state->underflow = ori_state->underflow;
> 
> Can you use kmemdup instead?
> 
>> +
>> +return >base;
>> +}
>> +
>> +static void vs_crtc_atomic_destroy_state(struct drm_crtc *crtc,
>> + struct drm_crtc_state *state)
>> +{
>> +__drm_atomic_helper_crtc_destroy_state(state);
>> 

Re: [PATCH v2 6/6] drm/vs: Add hdmi driver

2023-11-14 Thread Keith Zhao



On 2023/11/13 21:31, Dmitry Baryshkov wrote:
> On Mon, 13 Nov 2023 at 14:11, Keith Zhao  wrote:
>>
>>
>>
>> On 2023/10/26 6:23, Dmitry Baryshkov wrote:
>> > On 25/10/2023 13:39, Keith Zhao wrote:
>> >> add hdmi driver as encoder and connect
>> >>
>> >> Signed-off-by: Keith Zhao 
>> >> ---
>> >>   drivers/gpu/drm/verisilicon/Kconfig |   8 +-
>> >>   drivers/gpu/drm/verisilicon/Makefile|   1 +
>> >>   drivers/gpu/drm/verisilicon/starfive_hdmi.c | 949 
>> >>   drivers/gpu/drm/verisilicon/starfive_hdmi.h | 295 ++
>> >>   drivers/gpu/drm/verisilicon/vs_drv.c|   5 +
>> >>   drivers/gpu/drm/verisilicon/vs_drv.h|   4 +
>> >>   6 files changed, 1261 insertions(+), 1 deletion(-)
>> >>   create mode 100644 drivers/gpu/drm/verisilicon/starfive_hdmi.c
>> >>   create mode 100644 drivers/gpu/drm/verisilicon/starfive_hdmi.h
>> >>
>> >> diff --git a/drivers/gpu/drm/verisilicon/Kconfig 
>> >> b/drivers/gpu/drm/verisilicon/Kconfig
>> >> index 3a361f8c8..122c786e3 100644
>> >> --- a/drivers/gpu/drm/verisilicon/Kconfig
>> >> +++ b/drivers/gpu/drm/verisilicon/Kconfig
>> >> @@ -12,4 +12,10 @@ config DRM_VERISILICON
>> >> setting and buffer management. It does not
>> >> provide 2D or 3D acceleration.
>> >>   -
>> >> +config DRM_VERISILICON_STARFIVE_HDMI
>> >> +bool "Starfive HDMI extensions"
>> >> +depends on DRM_VERISILICON
>> >> +help
>> >> +   This selects support for StarFive soc specific extensions
>> >> +   for the Innosilicon HDMI driver. If you want to enable
>> >> +   HDMI on JH7110 based soc, you should select this option.
>> >> diff --git a/drivers/gpu/drm/verisilicon/Makefile 
>> >> b/drivers/gpu/drm/verisilicon/Makefile
>> >> index 1d48016ca..08350f25b 100644
>> >> --- a/drivers/gpu/drm/verisilicon/Makefile
>> >> +++ b/drivers/gpu/drm/verisilicon/Makefile
>> >> @@ -7,5 +7,6 @@ vs_drm-objs := vs_dc_hw.o \
>> >>   vs_modeset.o \
>> >>   vs_plane.o
>> >>   +vs_drm-$(CONFIG_DRM_VERISILICON_STARFIVE_HDMI) += starfive_hdmi.o
>> >>   obj-$(CONFIG_DRM_VERISILICON) += vs_drm.o
>> >>   diff --git a/drivers/gpu/drm/verisilicon/starfive_hdmi.c 
>> >> b/drivers/gpu/drm/verisilicon/starfive_hdmi.c
>> >> new file mode 100644
>> >> index 0..d296c4b71
>> >> --- /dev/null
>> >> +++ b/drivers/gpu/drm/verisilicon/starfive_hdmi.c
>> >> @@ -0,0 +1,949 @@
>> >> +// SPDX-License-Identifier: GPL-2.0-only
>> >> +/*
>> >> + * Copyright (C) 2023 StarFive Technology Co., Ltd.
>> >> + */
>> >> +
>> >> +#include 
>> >> +#include 
>> >> +#include 
>> >> +#include 
>> >> +#include 
>> >> +#include 
>> >> +#include 
>> >> +#include 
>> >> +#include 
>> >> +#include 
>> >> +#include 
>> >> +#include 
>> >> +#include 
>> >> +#include 
>> >> +
>> >> +#include 
>> >> +#include 
>> >> +#include 
>> >> +#include 
>> >> +#include 
>> >> +#include 
>> >> +#include 
>> >> +
>> >> +#include "starfive_hdmi.h"
>> >> +#include "vs_drv.h"
>> >> +#include "vs_crtc.h"
>> >> +
>> >> +static struct starfive_hdmi *encoder_to_hdmi(struct drm_encoder *encoder)
>> >> +{
>> >> +return container_of(encoder, struct starfive_hdmi, encoder);
>> >> +}
>> >> +
>> >> +static struct starfive_hdmi *connector_to_hdmi(struct drm_connector 
>> >> *connector)
>> >> +{
>> >> +return container_of(connector, struct starfive_hdmi, connector);
>> >> +}
>> >> +
>> >> +struct starfive_hdmi_i2c {
>> >> +struct i2c_adapter adap;
>> >> +
>> >> +u8 ddc_addr;
>> >> +u8 segment_addr;
>> >> +/* protects the edid data when use i2c cmd to read edid */
>> >> +struct mutex lock;
>> >> +struct completion cmp;
>> >> +};
>> >> +
>> >> +static const struct pre_pll_config pre_pl

Re: [PATCH v2 6/6] drm/vs: Add hdmi driver

2023-11-13 Thread Keith Zhao



On 2023/10/26 6:23, Dmitry Baryshkov wrote:
> On 25/10/2023 13:39, Keith Zhao wrote:
>> add hdmi driver as encoder and connect
>>
>> Signed-off-by: Keith Zhao 
>> ---
>>   drivers/gpu/drm/verisilicon/Kconfig |   8 +-
>>   drivers/gpu/drm/verisilicon/Makefile    |   1 +
>>   drivers/gpu/drm/verisilicon/starfive_hdmi.c | 949 
>>   drivers/gpu/drm/verisilicon/starfive_hdmi.h | 295 ++
>>   drivers/gpu/drm/verisilicon/vs_drv.c    |   5 +
>>   drivers/gpu/drm/verisilicon/vs_drv.h    |   4 +
>>   6 files changed, 1261 insertions(+), 1 deletion(-)
>>   create mode 100644 drivers/gpu/drm/verisilicon/starfive_hdmi.c
>>   create mode 100644 drivers/gpu/drm/verisilicon/starfive_hdmi.h
>>
>> diff --git a/drivers/gpu/drm/verisilicon/Kconfig 
>> b/drivers/gpu/drm/verisilicon/Kconfig
>> index 3a361f8c8..122c786e3 100644
>> --- a/drivers/gpu/drm/verisilicon/Kconfig
>> +++ b/drivers/gpu/drm/verisilicon/Kconfig
>> @@ -12,4 +12,10 @@ config DRM_VERISILICON
>>     setting and buffer management. It does not
>>     provide 2D or 3D acceleration.
>>   -
>> +config DRM_VERISILICON_STARFIVE_HDMI
>> +    bool "Starfive HDMI extensions"
>> +    depends on DRM_VERISILICON
>> +    help
>> +   This selects support for StarFive soc specific extensions
>> +   for the Innosilicon HDMI driver. If you want to enable
>> +   HDMI on JH7110 based soc, you should select this option.
>> diff --git a/drivers/gpu/drm/verisilicon/Makefile 
>> b/drivers/gpu/drm/verisilicon/Makefile
>> index 1d48016ca..08350f25b 100644
>> --- a/drivers/gpu/drm/verisilicon/Makefile
>> +++ b/drivers/gpu/drm/verisilicon/Makefile
>> @@ -7,5 +7,6 @@ vs_drm-objs := vs_dc_hw.o \
>>   vs_modeset.o \
>>   vs_plane.o
>>   +vs_drm-$(CONFIG_DRM_VERISILICON_STARFIVE_HDMI) += starfive_hdmi.o
>>   obj-$(CONFIG_DRM_VERISILICON) += vs_drm.o
>>   diff --git a/drivers/gpu/drm/verisilicon/starfive_hdmi.c 
>> b/drivers/gpu/drm/verisilicon/starfive_hdmi.c
>> new file mode 100644
>> index 0..d296c4b71
>> --- /dev/null
>> +++ b/drivers/gpu/drm/verisilicon/starfive_hdmi.c
>> @@ -0,0 +1,949 @@
>> +// SPDX-License-Identifier: GPL-2.0-only
>> +/*
>> + * Copyright (C) 2023 StarFive Technology Co., Ltd.
>> + */
>> +
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +
>> +#include "starfive_hdmi.h"
>> +#include "vs_drv.h"
>> +#include "vs_crtc.h"
>> +
>> +static struct starfive_hdmi *encoder_to_hdmi(struct drm_encoder *encoder)
>> +{
>> +    return container_of(encoder, struct starfive_hdmi, encoder);
>> +}
>> +
>> +static struct starfive_hdmi *connector_to_hdmi(struct drm_connector 
>> *connector)
>> +{
>> +    return container_of(connector, struct starfive_hdmi, connector);
>> +}
>> +
>> +struct starfive_hdmi_i2c {
>> +    struct i2c_adapter adap;
>> +
>> +    u8 ddc_addr;
>> +    u8 segment_addr;
>> +    /* protects the edid data when use i2c cmd to read edid */
>> +    struct mutex lock;
>> +    struct completion cmp;
>> +};
>> +
>> +static const struct pre_pll_config pre_pll_cfg_table[] = {
>> +    { 25175000,  25175000, 1,  100, 2, 3, 3, 12, 3, 3, 4, 0, 0xf5},
>> +    { 2520,  2520, 1,  100, 2, 3, 3, 12, 3, 3, 4, 0, 0},
>> +    { 2700,  2700, 1,  90, 3, 2, 2, 10, 3, 3, 4, 0, 0},
> 
> Such data structures are usually pretyt limited and hard to handle. Could you 
> please replace it with the runtime calculations of
> 
>> +    { 27027000,  27027000, 1,  90, 3, 2, 2, 10, 3, 3, 4, 0, 0x170a3d},
>> +    { 2832,  2832, 1,  28, 2, 1, 1,  3, 0, 3, 4, 0, 0x51eb85},
>> +    { 3024,  3024, 1,  30, 2, 1, 1,  3, 0, 3, 4, 0, 0x3d70a3},
>> +    { 3150,  3150, 1,  31, 2, 1, 1,  3, 0, 3, 4, 0, 0x7f},
>> +    { 3375,  3375, 1,  33, 2, 1, 1,  3, 0, 3, 4, 0, 0xcf},
>> +    { 3600,  3600, 1,  36, 2, 1, 1,  3, 0, 3, 4, 0, 0},
>> +    { 4000,  4000, 1,  80, 2, 2, 2, 12, 2, 2, 2, 0, 0},
>> +    { 4697,  4697, 1,  46, 2, 1, 1,  3, 0, 3, 4, 0, 0xf851eb},
>> +    { 4950,  49500

Re: [PATCH v2 5/6] drm/vs: Add KMS crtc

2023-10-26 Thread Keith Zhao
sorry 
Dmitry ,accidentally wrote the wrong name
Take no offense

On 2023/10/26 17:42, Keith Zhao wrote:
> hi Ville:
> very glad to receive your feedback
> Some of them are very good ideas.
> Some are not very clear and hope to get your further reply!
> 
> 
> On 2023/10/26 3:49, Ville Syrjälä wrote:
>> On Wed, Oct 25, 2023 at 10:28:56PM +0300, Dmitry Baryshkov wrote:
>>> On 25/10/2023 13:39, Keith Zhao wrote:
>>> > add 2 crtcs and 8 planes in vs-drm
>>> > 
>>> > Signed-off-by: Keith Zhao 
>>> > ---
>>> >   drivers/gpu/drm/verisilicon/Makefile   |8 +-
>>> >   drivers/gpu/drm/verisilicon/vs_crtc.c  |  257 
>>> >   drivers/gpu/drm/verisilicon/vs_crtc.h  |   43 +
>>> >   drivers/gpu/drm/verisilicon/vs_dc.c| 1002 
>>> >   drivers/gpu/drm/verisilicon/vs_dc.h|   80 +
>>> >   drivers/gpu/drm/verisilicon/vs_dc_hw.c | 1959 
>>> >   drivers/gpu/drm/verisilicon/vs_dc_hw.h |  492 ++
>>> >   drivers/gpu/drm/verisilicon/vs_drv.c   |2 +
>>> >   drivers/gpu/drm/verisilicon/vs_plane.c |  526 +++
>>> >   drivers/gpu/drm/verisilicon/vs_plane.h |   58 +
>>> >   drivers/gpu/drm/verisilicon/vs_type.h  |   69 +
>>> >   11 files changed, 4494 insertions(+), 2 deletions(-)
>>> >   create mode 100644 drivers/gpu/drm/verisilicon/vs_crtc.c
>>> >   create mode 100644 drivers/gpu/drm/verisilicon/vs_crtc.h
>>> >   create mode 100644 drivers/gpu/drm/verisilicon/vs_dc.c
>>> >   create mode 100644 drivers/gpu/drm/verisilicon/vs_dc.h
>>> >   create mode 100644 drivers/gpu/drm/verisilicon/vs_dc_hw.c
>>> >   create mode 100644 drivers/gpu/drm/verisilicon/vs_dc_hw.h
>>> >   create mode 100644 drivers/gpu/drm/verisilicon/vs_plane.c
>>> >   create mode 100644 drivers/gpu/drm/verisilicon/vs_plane.h
>>> >   create mode 100644 drivers/gpu/drm/verisilicon/vs_type.h
>>> > 
>>> > diff --git a/drivers/gpu/drm/verisilicon/Makefile 
>>> > b/drivers/gpu/drm/verisilicon/Makefile
>>> > index 7d3be305b..1d48016ca 100644
>>> > --- a/drivers/gpu/drm/verisilicon/Makefile
>>> > +++ b/drivers/gpu/drm/verisilicon/Makefile
>>> > @@ -1,7 +1,11 @@
>>> >   # SPDX-License-Identifier: GPL-2.0
>>> >   
>>> > -vs_drm-objs := vs_drv.o \
>>> > - vs_modeset.o
>>> > +vs_drm-objs := vs_dc_hw.o \
>>> > + vs_dc.o \
>>> > + vs_crtc.o \
>>> > + vs_drv.o \
>>> > + vs_modeset.o \
>>> > + vs_plane.o
>>> >   
>>> >   obj-$(CONFIG_DRM_VERISILICON) += vs_drm.o
>>> >   
>>> > diff --git a/drivers/gpu/drm/verisilicon/vs_crtc.c 
>>> > b/drivers/gpu/drm/verisilicon/vs_crtc.c
>>> > new file mode 100644
>>> > index 0..8a658ea77
>>> > --- /dev/null
>>> > +++ b/drivers/gpu/drm/verisilicon/vs_crtc.c
>>> > @@ -0,0 +1,257 @@
>>> > +// SPDX-License-Identifier: GPL-2.0
>>> > +/*
>>> > + * Copyright (C) 2023 VeriSilicon Holdings Co., Ltd.
>>> > + *
>>> > + */
>>> > +
>>> > +#include 
>>> > +#include 
>>> > +#include 
>>> > +
>>> > +#include 
>>> > +#include 
>>> > +#include 
>>> > +#include 
>>> > +#include 
>>> > +#include 
>>> > +
>>> > +#include "vs_crtc.h"
>>> > +#include "vs_dc.h"
>>> > +#include "vs_drv.h"
>>> > +
>>> > +static void vs_crtc_reset(struct drm_crtc *crtc)
>>> > +{
>>> > + struct vs_crtc_state *state;
>>> > +
>>> > + if (crtc->state) {
>>> > + __drm_atomic_helper_crtc_destroy_state(crtc->state);
>>> > +
>>> > + state = to_vs_crtc_state(crtc->state);
>>> > + kfree(state);
>>> > + crtc->state = NULL;
>>> > + }
>>> 
>>> You can call your crtc_destroy_state function directly here.
> ok got it !
>>> 
>>> > +
>>> > + state = kzalloc(sizeof(*state), GFP_KERNEL);
>>> > + if (!state)
>>> > + return;
>>> > +
>>> > + __drm_atomic_helper_crtc_reset(crtc, >base);
>>> > +}
>>> > +
>>> > +static struct drm_crtc_state *
>>> &g

Re: [PATCH v2 5/6] drm/vs: Add KMS crtc

2023-10-26 Thread Keith Zhao
hi Ville:
very glad to receive your feedback
Some of them are very good ideas.
Some are not very clear and hope to get your further reply!


On 2023/10/26 3:49, Ville Syrjälä wrote:
> On Wed, Oct 25, 2023 at 10:28:56PM +0300, Dmitry Baryshkov wrote:
>> On 25/10/2023 13:39, Keith Zhao wrote:
>> > add 2 crtcs and 8 planes in vs-drm
>> > 
>> > Signed-off-by: Keith Zhao 
>> > ---
>> >   drivers/gpu/drm/verisilicon/Makefile   |8 +-
>> >   drivers/gpu/drm/verisilicon/vs_crtc.c  |  257 
>> >   drivers/gpu/drm/verisilicon/vs_crtc.h  |   43 +
>> >   drivers/gpu/drm/verisilicon/vs_dc.c| 1002 
>> >   drivers/gpu/drm/verisilicon/vs_dc.h|   80 +
>> >   drivers/gpu/drm/verisilicon/vs_dc_hw.c | 1959 
>> >   drivers/gpu/drm/verisilicon/vs_dc_hw.h |  492 ++
>> >   drivers/gpu/drm/verisilicon/vs_drv.c   |2 +
>> >   drivers/gpu/drm/verisilicon/vs_plane.c |  526 +++
>> >   drivers/gpu/drm/verisilicon/vs_plane.h |   58 +
>> >   drivers/gpu/drm/verisilicon/vs_type.h  |   69 +
>> >   11 files changed, 4494 insertions(+), 2 deletions(-)
>> >   create mode 100644 drivers/gpu/drm/verisilicon/vs_crtc.c
>> >   create mode 100644 drivers/gpu/drm/verisilicon/vs_crtc.h
>> >   create mode 100644 drivers/gpu/drm/verisilicon/vs_dc.c
>> >   create mode 100644 drivers/gpu/drm/verisilicon/vs_dc.h
>> >   create mode 100644 drivers/gpu/drm/verisilicon/vs_dc_hw.c
>> >   create mode 100644 drivers/gpu/drm/verisilicon/vs_dc_hw.h
>> >   create mode 100644 drivers/gpu/drm/verisilicon/vs_plane.c
>> >   create mode 100644 drivers/gpu/drm/verisilicon/vs_plane.h
>> >   create mode 100644 drivers/gpu/drm/verisilicon/vs_type.h
>> > 
>> > diff --git a/drivers/gpu/drm/verisilicon/Makefile 
>> > b/drivers/gpu/drm/verisilicon/Makefile
>> > index 7d3be305b..1d48016ca 100644
>> > --- a/drivers/gpu/drm/verisilicon/Makefile
>> > +++ b/drivers/gpu/drm/verisilicon/Makefile
>> > @@ -1,7 +1,11 @@
>> >   # SPDX-License-Identifier: GPL-2.0
>> >   
>> > -vs_drm-objs := vs_drv.o \
>> > -  vs_modeset.o
>> > +vs_drm-objs := vs_dc_hw.o \
>> > +  vs_dc.o \
>> > +  vs_crtc.o \
>> > +  vs_drv.o \
>> > +  vs_modeset.o \
>> > +  vs_plane.o
>> >   
>> >   obj-$(CONFIG_DRM_VERISILICON) += vs_drm.o
>> >   
>> > diff --git a/drivers/gpu/drm/verisilicon/vs_crtc.c 
>> > b/drivers/gpu/drm/verisilicon/vs_crtc.c
>> > new file mode 100644
>> > index 0..8a658ea77
>> > --- /dev/null
>> > +++ b/drivers/gpu/drm/verisilicon/vs_crtc.c
>> > @@ -0,0 +1,257 @@
>> > +// SPDX-License-Identifier: GPL-2.0
>> > +/*
>> > + * Copyright (C) 2023 VeriSilicon Holdings Co., Ltd.
>> > + *
>> > + */
>> > +
>> > +#include 
>> > +#include 
>> > +#include 
>> > +
>> > +#include 
>> > +#include 
>> > +#include 
>> > +#include 
>> > +#include 
>> > +#include 
>> > +
>> > +#include "vs_crtc.h"
>> > +#include "vs_dc.h"
>> > +#include "vs_drv.h"
>> > +
>> > +static void vs_crtc_reset(struct drm_crtc *crtc)
>> > +{
>> > +  struct vs_crtc_state *state;
>> > +
>> > +  if (crtc->state) {
>> > +  __drm_atomic_helper_crtc_destroy_state(crtc->state);
>> > +
>> > +  state = to_vs_crtc_state(crtc->state);
>> > +  kfree(state);
>> > +  crtc->state = NULL;
>> > +  }
>> 
>> You can call your crtc_destroy_state function directly here.
ok got it !
>> 
>> > +
>> > +  state = kzalloc(sizeof(*state), GFP_KERNEL);
>> > +  if (!state)
>> > +  return;
>> > +
>> > +  __drm_atomic_helper_crtc_reset(crtc, >base);
>> > +}
>> > +
>> > +static struct drm_crtc_state *
>> > +vs_crtc_atomic_duplicate_state(struct drm_crtc *crtc)
>> > +{
>> > +  struct vs_crtc_state *ori_state;
>> 
>> It might be a matter of taste, but it is usually old_state.
>> 
>> > +  struct vs_crtc_state *state;
>> > +
>> > +  if (!crtc->state)
>> > +  return NULL;
>> > +
>> > +  ori_state = to_vs_crtc_state(crtc->state);
>> > +  state = kzalloc(sizeof(*state), GFP_KERNEL);
>> > +  if (!state)

[PATCH v2 2/6] riscv: dts: starfive: jh7110: add dc controller and hdmi node

2023-10-25 Thread Keith Zhao
Add the dc controller and hdmi node for the Starfive JH7110 SoC.

Signed-off-by: Keith Zhao 
---
 .../jh7110-starfive-visionfive-2.dtsi | 91 +++
 arch/riscv/boot/dts/starfive/jh7110.dtsi  | 41 +
 2 files changed, 132 insertions(+)

diff --git a/arch/riscv/boot/dts/starfive/jh7110-starfive-visionfive-2.dtsi 
b/arch/riscv/boot/dts/starfive/jh7110-starfive-visionfive-2.dtsi
index de0f40a8b..97909b6d2 100644
--- a/arch/riscv/boot/dts/starfive/jh7110-starfive-visionfive-2.dtsi
+++ b/arch/riscv/boot/dts/starfive/jh7110-starfive-visionfive-2.dtsi
@@ -31,6 +31,25 @@ memory@4000 {
reg = <0x0 0x4000 0x1 0x0>;
};
 
+   reserved-memory {
+   #address-cells = <2>;
+   #size-cells = <2>;
+   ranges;
+
+   /* vout applies for space from this CMA
+* Without this CMA reservation,
+* vout may not work properly.
+*/
+   linux,cma {
+   compatible = "shared-dma-pool";
+   reusable;
+   size = <0x0 0x2000>;
+   alignment = <0x0 0x1000>;
+   alloc-ranges = <0x0 0x7000 0x0 0x2000>;
+   linux,cma-default;
+   };
+   };
+
gpio-restart {
compatible = "gpio-restart";
gpios = < 35 GPIO_ACTIVE_HIGH>;
@@ -231,6 +250,41 @@ GPOEN_DISABLE,
slew-rate = <0>;
};
};
+
+   hdmi_pins: hdmi-0 {
+   hdmi-scl-pins {
+   pinmux = ;
+   input-enable;
+   bias-pull-up;
+   };
+
+   hdmi-sda-pins {
+   pinmux = ;
+   input-enable;
+   bias-pull-up;
+   };
+
+   hdmi-cec-pins {
+   pinmux = ;
+   input-enable;
+   bias-pull-up;
+   };
+
+   hdmi-hpd-pins {
+   pinmux = ;
+   input-enable;
+   bias-disable; /* external pull-up */
+   };
+   };
+
 };
 
  {
@@ -254,3 +308,40 @@ _3 {
 _4 {
cpu-supply = <_cpu>;
 };
+
+ {
+   status = "okay";
+};
+
+ {
+   status = "okay";
+};
+
+ {
+   status = "okay";
+   pinctrl-names = "default";
+   pinctrl-0 = <_pins>;
+
+   hdmi_in: port {
+   #address-cells = <1>;
+   #size-cells = <0>;
+   hdmi_in_dc: endpoint@0 {
+   reg = <0>;
+   remote-endpoint = <_out_hdmi>;
+   };
+   };
+};
+
+ {
+   status = "okay";
+
+   dc_out: port {
+   #address-cells = <1>;
+   #size-cells = <0>;
+   dc_out_hdmi: endpoint@0 {
+   reg = <0>;
+   remote-endpoint = <_in_dc>;
+   };
+
+   };
+};
diff --git a/arch/riscv/boot/dts/starfive/jh7110.dtsi 
b/arch/riscv/boot/dts/starfive/jh7110.dtsi
index 0005fa163..1670452fb 100644
--- a/arch/riscv/boot/dts/starfive/jh7110.dtsi
+++ b/arch/riscv/boot/dts/starfive/jh7110.dtsi
@@ -282,6 +282,11 @@ tdm_ext: tdm-ext-clock {
#clock-cells = <0>;
};
 
+   display: display-subsystem {
+   compatible = "starfive,display-subsystem";
+   ports = <_out>;
+   };
+
soc {
compatible = "simple-bus";
interrupt-parent = <>;
@@ -613,5 +618,41 @@ voutcrg: clock-controller@295c {
#reset-cells = <1>;
power-domains = < JH7110_PD_VOUT>;
};
+
+   dc8200: lcd-controller@2940 {
+   compatible = "starfive,jh7110-dc8200";
+   reg = <0x0 0x2940 0x0 0x100>,
+ <0x0 0x29400800 0x0 0x2000>;
+   interrupts = <95>;
+   clocks = < JH7110_SYSCLK_NOC_BUS_DISP_AXI>,
+   < JH7110_VOUTCLK_DC8200_PIX0>,
+   < JH7110_VOUTCLK_DC8200_PIX1>,
+   < JH7110_VOUTCLK_DC8200_CORE>,
+   < JH7110_VOUTCLK_DC8200_AXI>,
+   < JH7110_VOUTCLK_DC8200_AHB>,
+   <_pixelclk>,
+   < JH7110_VOUTCLK_DC8200_PIX>;
+   clock-names = "noc_bus", "channel0", "

[PATCH v2 3/6] drm/fourcc: Add drm/vs tiled modifiers

2023-10-25 Thread Keith Zhao
For each modifier, add the corresponding description

Signed-off-by: Keith Zhao 
---
 include/uapi/drm/drm_fourcc.h | 57 +++
 1 file changed, 57 insertions(+)

diff --git a/include/uapi/drm/drm_fourcc.h b/include/uapi/drm/drm_fourcc.h
index 8db7fd3f7..a580a848c 100644
--- a/include/uapi/drm/drm_fourcc.h
+++ b/include/uapi/drm/drm_fourcc.h
@@ -419,6 +419,7 @@ extern "C" {
 #define DRM_FORMAT_MOD_VENDOR_ARM 0x08
 #define DRM_FORMAT_MOD_VENDOR_ALLWINNER 0x09
 #define DRM_FORMAT_MOD_VENDOR_AMLOGIC 0x0a
+#define DRM_FORMAT_MOD_VENDOR_VERISILICON 0x0b
 
 /* add more to the end as needed */
 
@@ -1562,6 +1563,62 @@ drm_fourcc_canonicalize_nvidia_format_mod(__u64 modifier)
 #define AMD_FMT_MOD_CLEAR(field) \
(~((__u64)AMD_FMT_MOD_##field##_MASK << AMD_FMT_MOD_##field##_SHIFT))
 
+#define DRM_FORMAT_MOD_VERISILICON_TYPE_NORMAL 
0x00
+#define DRM_FORMAT_MOD_VERISILICON_TYPE_MASK   
((__u64)0x3 << 54)
+
+#define fourcc_mod_vs_code(type, val) \
+   fourcc_mod_code(VERISILICON, __u64)type) << 54) | (val)))
+
+#define DRM_FORMAT_MOD_VERISILICON_NORM_MODE_MASK  
0x1F
+
+/*
+ * An x-major 8x8 super tile consists of 64 8x8 sub-tiles in total.
+ * Each 8x8 sub-tile consists of four standard tiles .
+ * standard tiles (see Vivante 4x4 tiling layout)
+ */
+#define DRM_FORMAT_MOD_VERISILICON_SUPER_TILED_XMAJOR_8X8  0x02
+
+/*
+ * A y-major 8x8 super tile consists of 64 8x8 sub-tiles in total.
+ * Each 8x8 sub-tile consists of four standard tiles .
+ * standard tiles (see Vivante 4x4 tiling layout)
+ */
+#define DRM_FORMAT_MOD_VERISILICON_SUPER_TILED_YMAJOR_8X8  0x03
+
+/*
+ * An 8x8 tile consists of four standard tiles
+ * that are organized in Z-order.
+ * standard tiles (see Vivante 4x4 tiling layout)
+ */
+#define DRM_FORMAT_MOD_VERISILICON_TILE_8X8
0x04
+
+/*
+ * An 8x4 tile consists of two standard tiles
+ * that are organized in Z-order.
+ * standard tiles (see Vivante 4x4 tiling layout)
+ */
+#define DRM_FORMAT_MOD_VERISILICON_TILE_8X4
0x07
+
+/*
+ * An x-major 8x4 super tile consists of 128 8x4 sub-tiles in total.
+ * Each 8x4 sub-tile consists of two standard tiles.
+ * two standard tiles also same with DRM_FORMAT_MOD_VS_TILE_8X4
+ * standard tiles (see Vivante 4x4 tiling layout)
+ */
+#define DRM_FORMAT_MOD_VERISILICON_SUPER_TILED_XMAJOR_8X4  0x0B
+
+/*
+ * A y-major 4x8 super tile consists of 128 4x8 sub-tiles in total.
+ * Each 4x8 sub-tile consists of two standard tiles.
+ * two standard tiles also same with DRM_FORMAT_MOD_VS_TILE_8X4
+ * standard tiles (see Vivante 4x4 tiling layout)
+ */
+#define DRM_FORMAT_MOD_VERISILICON_SUPER_TILED_YMAJOR_4X80x0C
+
+#define fourcc_mod_vs_norm_code(tile) \
+   fourcc_mod_vs_code(DRM_FORMAT_MOD_VERISILICON_TYPE_NORMAL, \
+   (tile))
+
 #if defined(__cplusplus)
 }
 #endif
-- 
2.34.1



[PATCH v2 0/6] DRM driver for verisilicon

2023-10-25 Thread Keith Zhao
This patch is a drm driver for Starfive Soc JH7110,
I am sending Drm driver part and HDMI driver part.

We used GEM framework for buffer management , and 
for buffer allocation,we use DMA APIs.

the Starfive HDMI servers as interface between a LCD 
Controller and a HDMI bus. A HDMI TX consists of one 
HDMI transmitter controller and one HDMI transmitter PHY.
(Sound support is not include in this patch)

This patchset should be applied after the patchset:
https://patchwork.kernel.org/project/linux-clk/cover/20230713113902.56519-1-xingyu...@starfivetech.com/

V1:
Changes since v1:
- Further standardize the yaml file.
- Dts naming convention improved.
- Fix the problem of compiling and loading ko files.
- Use drm new api to automatically manage resources.
- Drop struct vs_crtc_funcs_plane_funcs??subdivide the plane's help interface
- Reduce the modifiers unused.
- Optimize the hdmi driver code

V2:
Changes since v2:
- fix the error about checking the yaml file.
- match drm driver GEM DMA API.
- Delete the custom crtc property .
- hdmi use drmm_ new api to automatically manage resources.
- update the modifiers comments.
- enabling KASAN, fix the error during removing module 

Keith Zhao (6):
  dt-bindings: display: Add yamls for JH7110 display system
  riscv: dts: starfive: jh7110: add dc controller and hdmi node
  drm/fourcc: Add drm/vs tiled modifiers
  drm/vs: Register DRM device
  drm/vs: Add KMS crtc
  drm/vs: Add hdmi driver

 .../starfive/starfive,display-subsystem.yaml  |   41 +
 .../starfive/starfive,jh7110-dc8200.yaml  |  109 +
 .../starfive/starfive,jh7110-inno-hdmi.yaml   |   85 +
 MAINTAINERS   |7 +
 .../jh7110-starfive-visionfive-2.dtsi |   91 +
 arch/riscv/boot/dts/starfive/jh7110.dtsi  |   41 +
 drivers/gpu/drm/Kconfig   |2 +
 drivers/gpu/drm/Makefile  |1 +
 drivers/gpu/drm/verisilicon/Kconfig   |   21 +
 drivers/gpu/drm/verisilicon/Makefile  |   12 +
 drivers/gpu/drm/verisilicon/starfive_hdmi.c   |  949 
 drivers/gpu/drm/verisilicon/starfive_hdmi.h   |  295 +++
 drivers/gpu/drm/verisilicon/vs_crtc.c |  257 +++
 drivers/gpu/drm/verisilicon/vs_crtc.h |   43 +
 drivers/gpu/drm/verisilicon/vs_dc.c   | 1002 +
 drivers/gpu/drm/verisilicon/vs_dc.h   |   80 +
 drivers/gpu/drm/verisilicon/vs_dc_hw.c| 1959 +
 drivers/gpu/drm/verisilicon/vs_dc_hw.h|  492 +
 drivers/gpu/drm/verisilicon/vs_drv.c  |  234 ++
 drivers/gpu/drm/verisilicon/vs_drv.h  |   31 +
 drivers/gpu/drm/verisilicon/vs_modeset.c  |   36 +
 drivers/gpu/drm/verisilicon/vs_modeset.h  |   10 +
 drivers/gpu/drm/verisilicon/vs_plane.c|  526 +
 drivers/gpu/drm/verisilicon/vs_plane.h|   58 +
 drivers/gpu/drm/verisilicon/vs_type.h |   69 +
 include/uapi/drm/drm_fourcc.h |   57 +
 include/uapi/drm/vs_drm.h |   50 +
 27 files changed, 6558 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/display/starfive/starfive,display-subsystem.yaml
 create mode 100644 
Documentation/devicetree/bindings/display/starfive/starfive,jh7110-dc8200.yaml
 create mode 100644 
Documentation/devicetree/bindings/display/starfive/starfive,jh7110-inno-hdmi.yaml
 create mode 100644 drivers/gpu/drm/verisilicon/Kconfig
 create mode 100644 drivers/gpu/drm/verisilicon/Makefile
 create mode 100644 drivers/gpu/drm/verisilicon/starfive_hdmi.c
 create mode 100644 drivers/gpu/drm/verisilicon/starfive_hdmi.h
 create mode 100644 drivers/gpu/drm/verisilicon/vs_crtc.c
 create mode 100644 drivers/gpu/drm/verisilicon/vs_crtc.h
 create mode 100644 drivers/gpu/drm/verisilicon/vs_dc.c
 create mode 100644 drivers/gpu/drm/verisilicon/vs_dc.h
 create mode 100644 drivers/gpu/drm/verisilicon/vs_dc_hw.c
 create mode 100644 drivers/gpu/drm/verisilicon/vs_dc_hw.h
 create mode 100644 drivers/gpu/drm/verisilicon/vs_drv.c
 create mode 100644 drivers/gpu/drm/verisilicon/vs_drv.h
 create mode 100644 drivers/gpu/drm/verisilicon/vs_modeset.c
 create mode 100644 drivers/gpu/drm/verisilicon/vs_modeset.h
 create mode 100644 drivers/gpu/drm/verisilicon/vs_plane.c
 create mode 100644 drivers/gpu/drm/verisilicon/vs_plane.h
 create mode 100644 drivers/gpu/drm/verisilicon/vs_type.h
 create mode 100644 include/uapi/drm/vs_drm.h

-- 
2.34.1



[PATCH v2 4/6] drm/vs: Register DRM device

2023-10-25 Thread Keith Zhao
Implement drm device registration interface

Thomas Zimmermann wrote:
You are replacing almost all of the GEM DMA object's helper code.
Either inherit directly from drm_gem_object drop the dependency entirely,
or you could try to fit your code into GEM DMA as well

Eventually I found an answer and it was DRM_GEM_DMA_DRIVER_OPS_WITH_DUMB_CREATE
After I adapt this interface, the custom gem logic interfaces can be deleted.
It's a big shocking, clap!

Signed-off-by: Keith Zhao 
---
 drivers/gpu/drm/Kconfig  |   2 +
 drivers/gpu/drm/Makefile |   1 +
 drivers/gpu/drm/verisilicon/Kconfig  |  15 ++
 drivers/gpu/drm/verisilicon/Makefile |   7 +
 drivers/gpu/drm/verisilicon/vs_drv.c | 227 +++
 drivers/gpu/drm/verisilicon/vs_drv.h |  27 +++
 drivers/gpu/drm/verisilicon/vs_modeset.c |  36 
 drivers/gpu/drm/verisilicon/vs_modeset.h |  10 +
 include/uapi/drm/vs_drm.h|  50 +
 9 files changed, 375 insertions(+)
 create mode 100644 drivers/gpu/drm/verisilicon/Kconfig
 create mode 100644 drivers/gpu/drm/verisilicon/Makefile
 create mode 100644 drivers/gpu/drm/verisilicon/vs_drv.c
 create mode 100644 drivers/gpu/drm/verisilicon/vs_drv.h
 create mode 100644 drivers/gpu/drm/verisilicon/vs_modeset.c
 create mode 100644 drivers/gpu/drm/verisilicon/vs_modeset.h
 create mode 100644 include/uapi/drm/vs_drm.h

diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig
index afb3b2f5f..9ede80ef9 100644
--- a/drivers/gpu/drm/Kconfig
+++ b/drivers/gpu/drm/Kconfig
@@ -363,6 +363,8 @@ source "drivers/gpu/drm/solomon/Kconfig"
 
 source "drivers/gpu/drm/sprd/Kconfig"
 
+source "drivers/gpu/drm/verisilicon/Kconfig"
+
 config DRM_HYPERV
tristate "DRM Support for Hyper-V synthetic video device"
depends on DRM && PCI && MMU && HYPERV
diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
index 7a09a89b4..6db3bc397 100644
--- a/drivers/gpu/drm/Makefile
+++ b/drivers/gpu/drm/Makefile
@@ -194,3 +194,4 @@ obj-y   += gud/
 obj-$(CONFIG_DRM_HYPERV) += hyperv/
 obj-y  += solomon/
 obj-$(CONFIG_DRM_SPRD) += sprd/
+obj-$(CONFIG_DRM_VERISILICON) += verisilicon/
diff --git a/drivers/gpu/drm/verisilicon/Kconfig 
b/drivers/gpu/drm/verisilicon/Kconfig
new file mode 100644
index 0..3a361f8c8
--- /dev/null
+++ b/drivers/gpu/drm/verisilicon/Kconfig
@@ -0,0 +1,15 @@
+# SPDX-License-Identifier: GPL-2.0
+config DRM_VERISILICON
+   tristate "DRM Support for VeriSilicon"
+   depends on DRM
+   select DRM_KMS_HELPER
+   select DRM_GEM_DMA_HELPER
+   select CMA
+   select DMA_CMA
+   help
+ Choose this option if you have a VeriSilicon soc chipset.
+ This driver provides VeriSilicon kernel mode
+ setting and buffer management. It does not
+ provide 2D or 3D acceleration.
+
+
diff --git a/drivers/gpu/drm/verisilicon/Makefile 
b/drivers/gpu/drm/verisilicon/Makefile
new file mode 100644
index 0..7d3be305b
--- /dev/null
+++ b/drivers/gpu/drm/verisilicon/Makefile
@@ -0,0 +1,7 @@
+# SPDX-License-Identifier: GPL-2.0
+
+vs_drm-objs := vs_drv.o \
+   vs_modeset.o 
+
+obj-$(CONFIG_DRM_VERISILICON) += vs_drm.o
+
diff --git a/drivers/gpu/drm/verisilicon/vs_drv.c 
b/drivers/gpu/drm/verisilicon/vs_drv.c
new file mode 100644
index 0..da7698c3d
--- /dev/null
+++ b/drivers/gpu/drm/verisilicon/vs_drv.c
@@ -0,0 +1,227 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2023 VeriSilicon Holdings Co., Ltd.
+ */
+
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "vs_drv.h"
+#include "vs_modeset.h"
+
+#define DRV_NAME   "verisilicon"
+#define DRV_DESC   "Verisilicon DRM driver"
+#define DRV_DATE   "20230516"
+#define DRV_MAJOR  1
+#define DRV_MINOR  0
+
+static int vs_gem_dumb_create(struct drm_file *file, struct drm_device *dev,
+ struct drm_mode_create_dumb *args)
+{
+   struct vs_drm_device *priv = to_vs_drm_private(dev);
+
+   unsigned int pitch = DIV_ROUND_UP(args->width * args->bpp, 8);
+
+   if (args->bpp % 10)
+   args->pitch = ALIGN(pitch, priv->pitch_alignment);
+   else
+   /* for costum 10bit format with no bit gaps */
+   args->pitch = pitch;
+
+   return drm_gem_dma_dumb_create_internal(file, dev, args);
+}
+
+DEFINE_DRM_GEM_FOPS(vs_drm_fops);
+
+static struct drm_driver vs_drm_driver = {
+   .driver_features= DRIVER_MODESET | DRIVER_ATOMIC | DRIVER_GEM,
+
+   DRM_GEM_DMA_DRIVER_OPS_WITH_DUMB_CREATE(vs_gem_dumb_create),
+
+   .fops   = _drm_fops,
+   .name   = DRV_NAME,
+   .desc   = 

[PATCH v2 5/6] drm/vs: Add KMS crtc

2023-10-25 Thread Keith Zhao
add 2 crtcs and 8 planes in vs-drm

Signed-off-by: Keith Zhao 
---
 drivers/gpu/drm/verisilicon/Makefile   |8 +-
 drivers/gpu/drm/verisilicon/vs_crtc.c  |  257 
 drivers/gpu/drm/verisilicon/vs_crtc.h  |   43 +
 drivers/gpu/drm/verisilicon/vs_dc.c| 1002 
 drivers/gpu/drm/verisilicon/vs_dc.h|   80 +
 drivers/gpu/drm/verisilicon/vs_dc_hw.c | 1959 
 drivers/gpu/drm/verisilicon/vs_dc_hw.h |  492 ++
 drivers/gpu/drm/verisilicon/vs_drv.c   |2 +
 drivers/gpu/drm/verisilicon/vs_plane.c |  526 +++
 drivers/gpu/drm/verisilicon/vs_plane.h |   58 +
 drivers/gpu/drm/verisilicon/vs_type.h  |   69 +
 11 files changed, 4494 insertions(+), 2 deletions(-)
 create mode 100644 drivers/gpu/drm/verisilicon/vs_crtc.c
 create mode 100644 drivers/gpu/drm/verisilicon/vs_crtc.h
 create mode 100644 drivers/gpu/drm/verisilicon/vs_dc.c
 create mode 100644 drivers/gpu/drm/verisilicon/vs_dc.h
 create mode 100644 drivers/gpu/drm/verisilicon/vs_dc_hw.c
 create mode 100644 drivers/gpu/drm/verisilicon/vs_dc_hw.h
 create mode 100644 drivers/gpu/drm/verisilicon/vs_plane.c
 create mode 100644 drivers/gpu/drm/verisilicon/vs_plane.h
 create mode 100644 drivers/gpu/drm/verisilicon/vs_type.h

diff --git a/drivers/gpu/drm/verisilicon/Makefile 
b/drivers/gpu/drm/verisilicon/Makefile
index 7d3be305b..1d48016ca 100644
--- a/drivers/gpu/drm/verisilicon/Makefile
+++ b/drivers/gpu/drm/verisilicon/Makefile
@@ -1,7 +1,11 @@
 # SPDX-License-Identifier: GPL-2.0
 
-vs_drm-objs := vs_drv.o \
-   vs_modeset.o 
+vs_drm-objs := vs_dc_hw.o \
+   vs_dc.o \
+   vs_crtc.o \
+   vs_drv.o \
+   vs_modeset.o \
+   vs_plane.o
 
 obj-$(CONFIG_DRM_VERISILICON) += vs_drm.o
 
diff --git a/drivers/gpu/drm/verisilicon/vs_crtc.c 
b/drivers/gpu/drm/verisilicon/vs_crtc.c
new file mode 100644
index 0..8a658ea77
--- /dev/null
+++ b/drivers/gpu/drm/verisilicon/vs_crtc.c
@@ -0,0 +1,257 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2023 VeriSilicon Holdings Co., Ltd.
+ *
+ */
+
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "vs_crtc.h"
+#include "vs_dc.h"
+#include "vs_drv.h"
+
+static void vs_crtc_reset(struct drm_crtc *crtc)
+{
+   struct vs_crtc_state *state;
+
+   if (crtc->state) {
+   __drm_atomic_helper_crtc_destroy_state(crtc->state);
+
+   state = to_vs_crtc_state(crtc->state);
+   kfree(state);
+   crtc->state = NULL;
+   }
+
+   state = kzalloc(sizeof(*state), GFP_KERNEL);
+   if (!state)
+   return;
+
+   __drm_atomic_helper_crtc_reset(crtc, >base);
+}
+
+static struct drm_crtc_state *
+vs_crtc_atomic_duplicate_state(struct drm_crtc *crtc)
+{
+   struct vs_crtc_state *ori_state;
+   struct vs_crtc_state *state;
+
+   if (!crtc->state)
+   return NULL;
+
+   ori_state = to_vs_crtc_state(crtc->state);
+   state = kzalloc(sizeof(*state), GFP_KERNEL);
+   if (!state)
+   return NULL;
+
+   __drm_atomic_helper_crtc_duplicate_state(crtc, >base);
+
+   state->output_fmt = ori_state->output_fmt;
+   state->encoder_type = ori_state->encoder_type;
+   state->bpp = ori_state->bpp;
+   state->underflow = ori_state->underflow;
+
+   return >base;
+}
+
+static void vs_crtc_atomic_destroy_state(struct drm_crtc *crtc,
+struct drm_crtc_state *state)
+{
+   __drm_atomic_helper_crtc_destroy_state(state);
+   kfree(to_vs_crtc_state(state));
+}
+
+static int vs_crtc_enable_vblank(struct drm_crtc *crtc)
+{
+   struct vs_crtc *vs_crtc = to_vs_crtc(crtc);
+   struct vs_dc *dc = dev_get_drvdata(vs_crtc->dev);
+
+   vs_dc_enable_vblank(dc, true);
+
+   return 0;
+}
+
+static void vs_crtc_disable_vblank(struct drm_crtc *crtc)
+{
+   struct vs_crtc *vs_crtc = to_vs_crtc(crtc);
+   struct vs_dc *dc = dev_get_drvdata(vs_crtc->dev);
+
+   vs_dc_enable_vblank(dc, false);
+}
+
+static const struct drm_crtc_funcs vs_crtc_funcs = {
+   .set_config = drm_atomic_helper_set_config,
+   .page_flip  = drm_atomic_helper_page_flip,
+   .reset  = vs_crtc_reset,
+   .atomic_duplicate_state = vs_crtc_atomic_duplicate_state,
+   .atomic_destroy_state   = vs_crtc_atomic_destroy_state,
+   .enable_vblank  = vs_crtc_enable_vblank,
+   .disable_vblank = vs_crtc_disable_vblank,
+};
+
+static u8 cal_pixel_bits(u32 bus_format)
+{
+   u8 bpp;
+
+   switch (bus_format) {
+   case MEDIA_BUS_FMT_RGB565_1X16:
+   case MEDIA_BUS_FMT_UYVY8_1X16:
+   bpp = 16;
+   break;
+   case MEDIA_BUS_FMT_RGB666_1X18:
+   case MEDIA_BUS_FMT_RGB666_1X24_CPADHI:
+   bpp =

[PATCH v2 1/6] dt-bindings: display: Add yamls for JH7110 display system

2023-10-25 Thread Keith Zhao
StarFive SoCs JH7110 display system:
lcd-controller bases verisilicon dc8200 IP,
and hdmi bases Innosilicon IP. Add bindings for them.

also update MAINTAINERS for dt-bindings

about this patch, I tested the dtbs_check and dt_binding_check
with the result pass.
Based on the feedback of the previous version, the corresponding arrangement is 
made

Signed-off-by: Keith Zhao 
---
 .../starfive/starfive,display-subsystem.yaml  |  41 +++
 .../starfive/starfive,jh7110-dc8200.yaml  | 109 ++
 .../starfive/starfive,jh7110-inno-hdmi.yaml   |  85 ++
 MAINTAINERS   |   7 ++
 4 files changed, 242 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/display/starfive/starfive,display-subsystem.yaml
 create mode 100644 
Documentation/devicetree/bindings/display/starfive/starfive,jh7110-dc8200.yaml
 create mode 100644 
Documentation/devicetree/bindings/display/starfive/starfive,jh7110-inno-hdmi.yaml

diff --git 
a/Documentation/devicetree/bindings/display/starfive/starfive,display-subsystem.yaml
 
b/Documentation/devicetree/bindings/display/starfive/starfive,display-subsystem.yaml
new file mode 100644
index 0..f45b97b08
--- /dev/null
+++ 
b/Documentation/devicetree/bindings/display/starfive/starfive,display-subsystem.yaml
@@ -0,0 +1,41 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: 
http://devicetree.org/schemas/display/starfive/starfive,display-subsystem.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Starfive DRM master device
+
+maintainers:
+  - Keith Zhao 
+  - ShengYang Chen 
+
+description:
+  The Starfive DRM master device is a virtual device needed to list all
+  display controller or other display interface nodes that comprise the
+  graphics subsystem.
+
+properties:
+  compatible:
+const: starfive,display-subsystem
+
+  ports:
+$ref: /schemas/types.yaml#/definitions/phandle-array
+description:
+  Should contain a list of phandles pointing to display interface ports
+  of display controller devices. Display controller definitions as defined
+  in Documentation/devicetree/bindings/display/starfive/
+  starfive,jh7110-dc8200.yaml
+
+required:
+  - compatible
+  - ports
+
+additionalProperties: false
+
+examples:
+  - |
+display-subsystem {
+compatible = "starfive,display-subsystem";
+ports = <_out>;
+};
diff --git 
a/Documentation/devicetree/bindings/display/starfive/starfive,jh7110-dc8200.yaml
 
b/Documentation/devicetree/bindings/display/starfive/starfive,jh7110-dc8200.yaml
new file mode 100644
index 0..87051cddf
--- /dev/null
+++ 
b/Documentation/devicetree/bindings/display/starfive/starfive,jh7110-dc8200.yaml
@@ -0,0 +1,109 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: 
http://devicetree.org/schemas/display/starfive/starfive,jh7110-dc8200.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: StarFive display controller
+
+description:
+  The StarFive SoC uses the display controller based on Verisilicon IP
+  to transfer the image data from a video memory buffer to an external
+  LCD interface.
+
+maintainers:
+  - Keith Zhao 
+
+properties:
+  compatible:
+const: starfive,jh7110-dc8200
+
+  reg:
+minItems: 1
+items:
+  - description:
+  host interface
+  - description:
+  display physical base address and length.
+
+  interrupts:
+items:
+  - description: The interrupt will be generated when DC finish one frame
+
+  clocks:
+items:
+  - description: Clock for display system noc bus.
+  - description: Pixel clock for display channel 0.
+  - description: Pixel clock for display channel 1.
+  - description: Core clock for display controller.
+  - description: Clock for axi bus to access ddr.
+  - description: Clock for ahb bus to R/W the phy regs.
+  - description: External HDMI pixel clock.
+  - description: Parent clock for pixel clock
+
+  clock-names:
+items:
+  - const: noc_bus
+  - const: channel0
+  - const: channel1
+  - const: dc_core
+  - const: axi_core
+  - const: ahb
+  - const: hdmi_tx
+  - const: dc_parent
+
+  resets:
+items:
+  - description: Reset for axi bus.
+  - description: Reset for ahb bus.
+  - description: Core reset of display controller.
+
+  reset-names:
+items:
+  - const: axi
+  - const: ahb
+  - const: core
+
+  port:
+$ref: /schemas/graph.yaml#/properties/port
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - clocks
+  - clock-names
+  - resets
+  - reset-names
+  - port
+
+additionalProperties: false
+
+examples:
+  - |
+dc8200: lcd-controller@2940 {
+compatible = "starfive,jh7110-dc8200";
+reg = <0x2940 0x100>, <0x29400800 0x2000>;
+interrupts = <95>;
+clocks = <

[PATCH v2 6/6] drm/vs: Add hdmi driver

2023-10-25 Thread Keith Zhao
add hdmi driver as encoder and connect

Signed-off-by: Keith Zhao 
---
 drivers/gpu/drm/verisilicon/Kconfig |   8 +-
 drivers/gpu/drm/verisilicon/Makefile|   1 +
 drivers/gpu/drm/verisilicon/starfive_hdmi.c | 949 
 drivers/gpu/drm/verisilicon/starfive_hdmi.h | 295 ++
 drivers/gpu/drm/verisilicon/vs_drv.c|   5 +
 drivers/gpu/drm/verisilicon/vs_drv.h|   4 +
 6 files changed, 1261 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/verisilicon/starfive_hdmi.c
 create mode 100644 drivers/gpu/drm/verisilicon/starfive_hdmi.h

diff --git a/drivers/gpu/drm/verisilicon/Kconfig 
b/drivers/gpu/drm/verisilicon/Kconfig
index 3a361f8c8..122c786e3 100644
--- a/drivers/gpu/drm/verisilicon/Kconfig
+++ b/drivers/gpu/drm/verisilicon/Kconfig
@@ -12,4 +12,10 @@ config DRM_VERISILICON
  setting and buffer management. It does not
  provide 2D or 3D acceleration.
 
-
+config DRM_VERISILICON_STARFIVE_HDMI
+   bool "Starfive HDMI extensions"
+   depends on DRM_VERISILICON
+   help
+  This selects support for StarFive soc specific extensions
+  for the Innosilicon HDMI driver. If you want to enable
+  HDMI on JH7110 based soc, you should select this option.
diff --git a/drivers/gpu/drm/verisilicon/Makefile 
b/drivers/gpu/drm/verisilicon/Makefile
index 1d48016ca..08350f25b 100644
--- a/drivers/gpu/drm/verisilicon/Makefile
+++ b/drivers/gpu/drm/verisilicon/Makefile
@@ -7,5 +7,6 @@ vs_drm-objs := vs_dc_hw.o \
vs_modeset.o \
vs_plane.o
 
+vs_drm-$(CONFIG_DRM_VERISILICON_STARFIVE_HDMI) += starfive_hdmi.o
 obj-$(CONFIG_DRM_VERISILICON) += vs_drm.o
 
diff --git a/drivers/gpu/drm/verisilicon/starfive_hdmi.c 
b/drivers/gpu/drm/verisilicon/starfive_hdmi.c
new file mode 100644
index 0..d296c4b71
--- /dev/null
+++ b/drivers/gpu/drm/verisilicon/starfive_hdmi.c
@@ -0,0 +1,949 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2023 StarFive Technology Co., Ltd.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "starfive_hdmi.h"
+#include "vs_drv.h"
+#include "vs_crtc.h"
+
+static struct starfive_hdmi *encoder_to_hdmi(struct drm_encoder *encoder)
+{
+   return container_of(encoder, struct starfive_hdmi, encoder);
+}
+
+static struct starfive_hdmi *connector_to_hdmi(struct drm_connector *connector)
+{
+   return container_of(connector, struct starfive_hdmi, connector);
+}
+
+struct starfive_hdmi_i2c {
+   struct i2c_adapter adap;
+
+   u8 ddc_addr;
+   u8 segment_addr;
+   /* protects the edid data when use i2c cmd to read edid */
+   struct mutex lock;
+   struct completion cmp;
+};
+
+static const struct pre_pll_config pre_pll_cfg_table[] = {
+   { 25175000,  25175000, 1,  100, 2, 3, 3, 12, 3, 3, 4, 0, 0xf5},
+   { 2520,  2520, 1,  100, 2, 3, 3, 12, 3, 3, 4, 0, 0},
+   { 2700,  2700, 1,  90, 3, 2, 2, 10, 3, 3, 4, 0, 0},
+   { 27027000,  27027000, 1,  90, 3, 2, 2, 10, 3, 3, 4, 0, 0x170a3d},
+   { 2832,  2832, 1,  28, 2, 1, 1,  3, 0, 3, 4, 0, 0x51eb85},
+   { 3024,  3024, 1,  30, 2, 1, 1,  3, 0, 3, 4, 0, 0x3d70a3},
+   { 3150,  3150, 1,  31, 2, 1, 1,  3, 0, 3, 4, 0, 0x7f},
+   { 3375,  3375, 1,  33, 2, 1, 1,  3, 0, 3, 4, 0, 0xcf},
+   { 3600,  3600, 1,  36, 2, 1, 1,  3, 0, 3, 4, 0, 0},
+   { 4000,  4000, 1,  80, 2, 2, 2, 12, 2, 2, 2, 0, 0},
+   { 4697,  4697, 1,  46, 2, 1, 1,  3, 0, 3, 4, 0, 0xf851eb},
+   { 4950,  4950, 1,  49, 2, 1, 1,  3, 0, 3, 4, 0, 0x7f},
+   { 4900,  4900, 1,  49, 2, 1, 1,  3, 0, 3, 4, 0, 0},
+   { 5000,  5000, 1,  50, 2, 1, 1,  3, 0, 3, 4, 0, 0},
+   { 5400,  5400, 1,  54, 2, 1, 1,  3, 0, 3, 4, 0, 0},
+   { 54054000,  54054000, 1,  54, 2, 1, 1,  3, 0, 3, 4, 0, 0x0dd2f1},
+   { 57284000,  57284000, 1,  57, 2, 1, 1,  3, 0, 3, 4, 0, 0x48b439},
+   { 5823,  5823, 1,  58, 2, 1, 1,  3, 0, 3, 4, 0, 0x3ae147},
+   { 59341000,  59341000, 1,  59, 2, 1, 1,  3, 0, 3, 4, 0, 0x574bc6},
+   { 5940,  5940, 1,  99, 3, 1, 1,  1, 3, 3, 4, 0, 0},
+   { 6500,  6500, 1, 130, 2, 2, 2,  12, 0, 2, 2, 0, 0},
+   { 6825,  6825, 1, 68,  2, 1, 1,  3,  0, 3, 4, 0, 0x3f},
+   { 7100,  7100, 1,  71, 2, 1, 1,  3, 0, 3,  4, 0, 0},
+   { 74176000,  74176000, 1,  98, 1, 2, 2,  1, 2, 3, 4, 0, 0xe6ae6b},
+   { 7425,  7425, 1,  99, 1, 2, 2,  1, 2, 3, 4, 0, 0},
+   { 7500,  7500, 1,  75, 2, 1, 1,  3, 0, 3, 4, 0, 0},
+   { 7875,  7875, 1,  78, 2, 1, 1,  3, 0, 3, 4, 0, 0xcf},
+   { 7950,  7950, 1,  79, 2, 1, 1,  3, 0

[PATCH v1 v1 7/7] drm/vs: Add hdmi

2023-08-01 Thread Keith Zhao
add hdmi driver as encoder and connect

Signed-off-by: Keith Zhao 
---
 drivers/gpu/drm/verisilicon/starfive_hdmi.c | 940 
 drivers/gpu/drm/verisilicon/starfive_hdmi.h | 295 ++
 2 files changed, 1235 insertions(+)
 create mode 100644 drivers/gpu/drm/verisilicon/starfive_hdmi.c
 create mode 100644 drivers/gpu/drm/verisilicon/starfive_hdmi.h

diff --git a/drivers/gpu/drm/verisilicon/starfive_hdmi.c 
b/drivers/gpu/drm/verisilicon/starfive_hdmi.c
new file mode 100644
index 0..c02f4f749
--- /dev/null
+++ b/drivers/gpu/drm/verisilicon/starfive_hdmi.c
@@ -0,0 +1,940 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2023 StarFive Technology Co., Ltd.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "starfive_hdmi.h"
+#include "vs_drv.h"
+
+static struct starfive_hdmi *encoder_to_hdmi(struct drm_encoder *encoder)
+{
+   return container_of(encoder, struct starfive_hdmi, encoder);
+}
+
+static struct starfive_hdmi *connector_to_hdmi(struct drm_connector *connector)
+{
+   return container_of(connector, struct starfive_hdmi, connector);
+}
+
+struct starfive_hdmi_i2c {
+   struct i2c_adapter adap;
+
+   u8 ddc_addr;
+   u8 segment_addr;
+   /* protects the edid data when use i2c cmd to read edid */
+   struct mutex lock;
+   struct completion cmp;
+};
+
+static const struct pre_pll_config pre_pll_cfg_table[] = {
+   { 25175000,  25175000, 1,  100, 2, 3, 3, 12, 3, 3, 4, 0, 0xf5},
+   { 2520,  2520, 1,  100, 2, 3, 3, 12, 3, 3, 4, 0, 0},
+   { 2700,  2700, 1,  90, 3, 2, 2, 10, 3, 3, 4, 0, 0},
+   { 27027000,  27027000, 1,  90, 3, 2, 2, 10, 3, 3, 4, 0, 0x170a3d},
+   { 2832,  2832, 1,  28, 2, 1, 1,  3, 0, 3, 4, 0, 0x51eb85},
+   { 3024,  3024, 1,  30, 2, 1, 1,  3, 0, 3, 4, 0, 0x3d70a3},
+   { 3150,  3150, 1,  31, 2, 1, 1,  3, 0, 3, 4, 0, 0x7f},
+   { 3375,  3375, 1,  33, 2, 1, 1,  3, 0, 3, 4, 0, 0xcf},
+   { 3600,  3600, 1,  36, 2, 1, 1,  3, 0, 3, 4, 0, 0},
+   { 4000,  4000, 1,  80, 2, 2, 2, 12, 2, 2, 2, 0, 0},
+   { 4697,  4697, 1,  46, 2, 1, 1,  3, 0, 3, 4, 0, 0xf851eb},
+   { 4950,  4950, 1,  49, 2, 1, 1,  3, 0, 3, 4, 0, 0x7f},
+   { 4900,  4900, 1,  49, 2, 1, 1,  3, 0, 3, 4, 0, 0},
+   { 5000,  5000, 1,  50, 2, 1, 1,  3, 0, 3, 4, 0, 0},
+   { 5400,  5400, 1,  54, 2, 1, 1,  3, 0, 3, 4, 0, 0},
+   { 54054000,  54054000, 1,  54, 2, 1, 1,  3, 0, 3, 4, 0, 0x0dd2f1},
+   { 57284000,  57284000, 1,  57, 2, 1, 1,  3, 0, 3, 4, 0, 0x48b439},
+   { 5823,  5823, 1,  58, 2, 1, 1,  3, 0, 3, 4, 0, 0x3ae147},
+   { 59341000,  59341000, 1,  59, 2, 1, 1,  3, 0, 3, 4, 0, 0x574bc6},
+   { 5940,  5940, 1,  99, 3, 1, 1,  1, 3, 3, 4, 0, 0},
+   { 6500,  6500, 1, 130, 2, 2, 2,  12, 0, 2, 2, 0, 0},
+   { 6825,  6825, 1, 68,  2, 1, 1,  3,  0, 3, 4, 0, 0x3f},
+   { 7100,  7100, 1,  71, 2, 1, 1,  3, 0, 3,  4, 0, 0},
+   { 74176000,  74176000, 1,  98, 1, 2, 2,  1, 2, 3, 4, 0, 0xe6ae6b},
+   { 7425,  7425, 1,  99, 1, 2, 2,  1, 2, 3, 4, 0, 0},
+   { 7500,  7500, 1,  75, 2, 1, 1,  3, 0, 3, 4, 0, 0},
+   { 7875,  7875, 1,  78, 2, 1, 1,  3, 0, 3, 4, 0, 0xcf},
+   { 7950,  7950, 1,  79, 2, 1, 1,  3, 0, 3, 4, 0, 0x7f},
+   { 8350,  8350, 2, 167, 2, 1, 1,  1, 0, 0,  6, 0, 0},
+   { 8350, 104375000, 1, 104, 2, 1, 1,  1, 1, 0,  5, 0, 0x60},
+   { 84858000,  84858000, 1,  85, 2, 1, 1,  3, 0, 3,  4, 0, 0xdba5e2},
+   { 8550,  8550, 1,  85, 2, 1, 1,  3, 0, 3,  4, 0, 0x7f},
+   { 8575,  8575, 1,  85, 2, 1, 1,  3, 0, 3,  4, 0, 0xcf},
+   { 8580,  8580, 1,  85, 2, 1, 1,  3, 0, 3,  4, 0, 0xcc},
+   { 8875,  8875, 1,  88, 2, 1, 1,  3, 0, 3,  4, 0, 0xcf},
+   { 8991,  8991, 1,  89, 2, 1, 1,  3, 0, 3, 4, 0, 0xe8f5c1},
+   { 9000,  9000, 1,  90, 2, 1, 1,  3, 0, 3, 4, 0, 0},
+   {10100, 10100, 1, 101, 2, 1, 1,  3, 0, 3, 4, 0, 0},
+   {10225, 10225, 1, 102, 2, 1, 1,  3, 0, 3, 4, 0, 0x3f},
+   {10650, 10650, 1, 106, 2, 1, 1,  3, 0, 3, 4, 0, 0x7f},
+   {10800, 10800, 1,  90, 3, 0, 0,  5, 0, 2,  2, 0, 0},
+   {11900, 11900, 1, 119, 2, 1, 1,  3, 0, 3,  4, 0, 0},
+   {131481000, 131481000, 1,  131, 2, 1, 1,  3, 0, 3,  4, 0, 0x7b22d1},
+   {13500, 13500, 1,  135, 2, 1, 1,  3, 0, 3, 4, 0, 0},
+   {13675, 13675, 1,  136, 2, 1, 1,  3, 0, 3, 4, 0, 0xcf},
+   {14718, 14718, 1,  147, 2, 1, 1,  3, 0, 3, 4, 0, 0x2e147a},
+   {148352000, 148352000, 1,  98, 

[PATCH v1 v1 1/7] MAINTAINERS: Update starfive maintainers

2023-08-01 Thread Keith Zhao
update starfive maintainers

Signed-off-by: Keith Zhao 
---
 MAINTAINERS | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 3be1bdfe8..daadd1707 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -6760,6 +6760,13 @@ S:   Supported
 T: git git://anongit.freedesktop.org/drm/drm-misc
 F: drivers/gpu/drm/udl/
 
+DRM DRIVERS FOR STARFIVE
+M: Keith Zhao 
+L: dri-devel@lists.freedesktop.org
+S: Maintained
+T: git git://anongit.freedesktop.org/drm/drm-misc
+F: Documentation/devicetree/bindings/display/starfive/
+
 DRM DRIVER FOR VIRTUAL KERNEL MODESETTING (VKMS)
 M: Rodrigo Siqueira 
 M: Melissa Wen 
-- 
2.34.1



[PATCH v1 v1 6/7] drm/vs: Add KMS crtc

2023-08-01 Thread Keith Zhao
add 2 crtcs and 8 planes in vs-drm

Signed-off-by: Keith Zhao 
---
 drivers/gpu/drm/verisilicon/vs_crtc.c  |  365 +
 drivers/gpu/drm/verisilicon/vs_crtc.h  |   54 +
 drivers/gpu/drm/verisilicon/vs_dc.c| 1036 
 drivers/gpu/drm/verisilicon/vs_dc.h|   87 +
 drivers/gpu/drm/verisilicon/vs_dc_hw.c | 2008 
 drivers/gpu/drm/verisilicon/vs_dc_hw.h |  496 ++
 drivers/gpu/drm/verisilicon/vs_drv.c   |3 +-
 drivers/gpu/drm/verisilicon/vs_plane.c |  502 ++
 drivers/gpu/drm/verisilicon/vs_plane.h |   65 +
 drivers/gpu/drm/verisilicon/vs_type.h  |   70 +
 10 files changed, 4685 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/verisilicon/vs_crtc.c
 create mode 100644 drivers/gpu/drm/verisilicon/vs_crtc.h
 create mode 100644 drivers/gpu/drm/verisilicon/vs_dc.c
 create mode 100644 drivers/gpu/drm/verisilicon/vs_dc.h
 create mode 100644 drivers/gpu/drm/verisilicon/vs_dc_hw.c
 create mode 100644 drivers/gpu/drm/verisilicon/vs_dc_hw.h
 create mode 100644 drivers/gpu/drm/verisilicon/vs_plane.c
 create mode 100644 drivers/gpu/drm/verisilicon/vs_plane.h
 create mode 100644 drivers/gpu/drm/verisilicon/vs_type.h

diff --git a/drivers/gpu/drm/verisilicon/vs_crtc.c 
b/drivers/gpu/drm/verisilicon/vs_crtc.c
new file mode 100644
index 0..6a5af8d8c
--- /dev/null
+++ b/drivers/gpu/drm/verisilicon/vs_crtc.c
@@ -0,0 +1,365 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2023 VeriSilicon Holdings Co., Ltd.
+ *
+ */
+
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "vs_crtc.h"
+#include "vs_dc.h"
+#include "vs_drv.h"
+
+static void vs_crtc_reset(struct drm_crtc *crtc)
+{
+   struct vs_crtc_state *state;
+
+   if (crtc->state) {
+   __drm_atomic_helper_crtc_destroy_state(crtc->state);
+
+   state = to_vs_crtc_state(crtc->state);
+   kfree(state);
+   crtc->state = NULL;
+   }
+
+   state = kzalloc(sizeof(*state), GFP_KERNEL);
+   if (!state)
+   return;
+
+   __drm_atomic_helper_crtc_reset(crtc, >base);
+
+   state->sync_mode = VS_SINGLE_DC;
+   state->output_fmt = MEDIA_BUS_FMT_RBG888_1X24;
+   state->encoder_type = DRM_MODE_ENCODER_NONE;
+}
+
+static struct drm_crtc_state *
+vs_crtc_atomic_duplicate_state(struct drm_crtc *crtc)
+{
+   struct vs_crtc_state *ori_state;
+   struct vs_crtc_state *state;
+
+   if (!crtc->state)
+   return NULL;
+
+   ori_state = to_vs_crtc_state(crtc->state);
+   state = kzalloc(sizeof(*state), GFP_KERNEL);
+   if (!state)
+   return NULL;
+
+   __drm_atomic_helper_crtc_duplicate_state(crtc, >base);
+
+   state->sync_mode = ori_state->sync_mode;
+   state->output_fmt = ori_state->output_fmt;
+   state->encoder_type = ori_state->encoder_type;
+   state->bg_color = ori_state->bg_color;
+   state->bpp = ori_state->bpp;
+   state->sync_enable = ori_state->sync_enable;
+   state->dither_enable = ori_state->dither_enable;
+   state->underflow = ori_state->underflow;
+
+   return >base;
+}
+
+static void vs_crtc_atomic_destroy_state(struct drm_crtc *crtc,
+struct drm_crtc_state *state)
+{
+   __drm_atomic_helper_crtc_destroy_state(state);
+   kfree(to_vs_crtc_state(state));
+}
+
+static int vs_crtc_atomic_set_property(struct drm_crtc *crtc,
+  struct drm_crtc_state *state,
+  struct drm_property *property,
+  uint64_t val)
+{
+   struct vs_crtc *vs_crtc = to_vs_crtc(crtc);
+   struct vs_crtc_state *vs_crtc_state = to_vs_crtc_state(state);
+
+   if (property == vs_crtc->sync_mode)
+   vs_crtc_state->sync_mode = val;
+   else if (property == vs_crtc->mmu_prefetch)
+   vs_crtc_state->mmu_prefetch = val;
+   else if (property == vs_crtc->bg_color)
+   vs_crtc_state->bg_color = val;
+   else if (property == vs_crtc->panel_sync)
+   vs_crtc_state->sync_enable = val;
+   else if (property == vs_crtc->dither)
+   vs_crtc_state->dither_enable = val;
+   else
+   return -EINVAL;
+
+   return 0;
+}
+
+static int vs_crtc_atomic_get_property(struct drm_crtc *crtc,
+  const struct drm_crtc_state *state,
+  struct drm_property *property,
+  uint64_t *val)
+{
+   struct vs_crtc *vs_crtc = to_vs_crtc(crtc);
+   const struct vs_crtc_state *vs_crtc_state =
+   container_of(state, const struct vs_crtc_state, base);
+
+   if (property == vs_crtc->sync_mode)
+   

[PATCH v1 v1 4/7] drm/fourcc: Add drm/vs tiled modifiers

2023-08-01 Thread Keith Zhao
These are mainly used internally in vs-drm,
I'm not sure if the new modifiers can be used with the existing ones.
If there is a problem, I will improve it further.

Signed-off-by: Keith Zhao 
---
 include/uapi/drm/drm_fourcc.h | 27 +++
 1 file changed, 27 insertions(+)

diff --git a/include/uapi/drm/drm_fourcc.h b/include/uapi/drm/drm_fourcc.h
index 8db7fd3f7..0b884cf50 100644
--- a/include/uapi/drm/drm_fourcc.h
+++ b/include/uapi/drm/drm_fourcc.h
@@ -419,6 +419,7 @@ extern "C" {
 #define DRM_FORMAT_MOD_VENDOR_ARM 0x08
 #define DRM_FORMAT_MOD_VENDOR_ALLWINNER 0x09
 #define DRM_FORMAT_MOD_VENDOR_AMLOGIC 0x0a
+#define DRM_FORMAT_MOD_VENDOR_VS  0x0b
 
 /* add more to the end as needed */
 
@@ -1562,6 +1563,32 @@ drm_fourcc_canonicalize_nvidia_format_mod(__u64 modifier)
 #define AMD_FMT_MOD_CLEAR(field) \
(~((__u64)AMD_FMT_MOD_##field##_MASK << AMD_FMT_MOD_##field##_SHIFT))
 
+#define DRM_FORMAT_MOD_VS_TYPE_NORMAL0x00
+#define DRM_FORMAT_MOD_VS_TYPE_COMPRESSED0x01
+#define DRM_FORMAT_MOD_VS_TYPE_CUSTOM_10BIT  0x02
+#define DRM_FORMAT_MOD_VS_TYPE_MASK ((__u64)0x3 << 54)
+
+#define fourcc_mod_vs_code(type, val) \
+   fourcc_mod_code(VS, __u64)type) << 54) | (val)))
+
+#define DRM_FORMAT_MOD_VS_NORM_MODE_MASK0x1F
+#define DRM_FORMAT_MOD_VS_LINEAR0x00
+#define DRM_FORMAT_MOD_VS_SUPER_TILED_XMAJOR0x02
+#define DRM_FORMAT_MOD_VS_SUPER_TILED_YMAJOR0x03
+#define DRM_FORMAT_MOD_VS_TILE_8X8  0x04
+#define DRM_FORMAT_MOD_VS_TILE_8X4  0x07
+#define DRM_FORMAT_MOD_VS_SUPER_TILED_XMAJOR_8X40x0B
+#define DRM_FORMAT_MOD_VS_SUPER_TILED_YMAJOR_4X80x0C
+#define DRM_FORMAT_MOD_VS_TILE_MODE4X4  0x15
+
+#define fourcc_mod_vs_norm_code(tile) \
+   fourcc_mod_vs_code(DRM_FORMAT_MOD_VS_TYPE_NORMAL, \
+   (tile))
+
+#define fourcc_mod_vs_custom_code(tile) \
+   fourcc_mod_vs_code(DRM_FORMAT_MOD_VS_TYPE_CUSTOM_10BIT, \
+   (tile))
+
 #if defined(__cplusplus)
 }
 #endif
-- 
2.34.1



[PATCH v1 v1 0/7] DRM driver for verisilicon

2023-08-01 Thread Keith Zhao
This patch is a drm driver for Starfive Soc JH7110,
I am sending Drm driver part and HDMI driver part.

We used GEM framework for buffer management , and 
for buffer allocation,we use DMA APIs.

the Starfive HDMI servers as interface between a LCD 
Controller and a HDMI bus. A HDMI TX consists of one 
HDMI transmitter controller and one HDMI transmitter PHY.
(Sound support is not include in this patch)

This patchset should be applied after the patchset:
https://patchwork.kernel.org/project/linux-clk/cover/20230713113902.56519-1-xingyu...@starfivetech.com/

V1:
Changes since v1:
- Further standardize the yaml file.
- Dts naming convention improved.
- Fix the problem of compiling and loading ko files.
- Use drm new api to automatically manage resources.
- Drop struct vs_crtc_funcs_plane_funcs,subdivide the plane's help interface
- Reduce the modifiers unused.
- Optimize the hdmi driver code

Keith Zhao (7):
  MAINTAINERS: Update starfive maintainers
  dt-bindings: display: Add yamls for JH7110 display system
  riscv: dts: starfive: jh7110: add dc controller and hdmi  node
  drm/fourcc: Add drm/vs tiled modifiers
  drm/vs: Register DRM device
  drm/vs: Add KMS crtc
  drm/vs: Add hdmi

 .../starfive/starfive,display-subsystem.yaml  |   41 +
 .../starfive/starfive,jh7110-dc8200.yaml  |  107 +
 .../starfive/starfive,jh7110-inno-hdmi.yaml   |   92 +
 MAINTAINERS   |7 +
 .../jh7110-starfive-visionfive-2.dtsi |   87 +
 arch/riscv/boot/dts/starfive/jh7110.dtsi  |   43 +
 drivers/gpu/drm/Kconfig   |2 +
 drivers/gpu/drm/Makefile  |1 +
 drivers/gpu/drm/verisilicon/Kconfig   |   25 +
 drivers/gpu/drm/verisilicon/Makefile  |   13 +
 drivers/gpu/drm/verisilicon/starfive_hdmi.c   |  940 
 drivers/gpu/drm/verisilicon/starfive_hdmi.h   |  295 +++
 drivers/gpu/drm/verisilicon/vs_crtc.c |  365 +++
 drivers/gpu/drm/verisilicon/vs_crtc.h |   54 +
 drivers/gpu/drm/verisilicon/vs_dc.c   | 1036 +
 drivers/gpu/drm/verisilicon/vs_dc.h   |   87 +
 drivers/gpu/drm/verisilicon/vs_dc_hw.c| 2008 +
 drivers/gpu/drm/verisilicon/vs_dc_hw.h|  496 
 drivers/gpu/drm/verisilicon/vs_drv.c  |  274 +++
 drivers/gpu/drm/verisilicon/vs_drv.h  |   54 +
 drivers/gpu/drm/verisilicon/vs_gem.c  |  298 +++
 drivers/gpu/drm/verisilicon/vs_gem.h  |   50 +
 drivers/gpu/drm/verisilicon/vs_modeset.c  |   92 +
 drivers/gpu/drm/verisilicon/vs_modeset.h  |   13 +
 drivers/gpu/drm/verisilicon/vs_plane.c|  502 +
 drivers/gpu/drm/verisilicon/vs_plane.h|   65 +
 drivers/gpu/drm/verisilicon/vs_type.h |   70 +
 include/uapi/drm/drm_fourcc.h |   27 +
 include/uapi/drm/vs_drm.h |   50 +
 29 files changed, 7194 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/display/starfive/starfive,display-subsystem.yaml
 create mode 100644 
Documentation/devicetree/bindings/display/starfive/starfive,jh7110-dc8200.yaml
 create mode 100644 
Documentation/devicetree/bindings/display/starfive/starfive,jh7110-inno-hdmi.yaml
 create mode 100644 drivers/gpu/drm/verisilicon/Kconfig
 create mode 100644 drivers/gpu/drm/verisilicon/Makefile
 create mode 100644 drivers/gpu/drm/verisilicon/starfive_hdmi.c
 create mode 100644 drivers/gpu/drm/verisilicon/starfive_hdmi.h
 create mode 100644 drivers/gpu/drm/verisilicon/vs_crtc.c
 create mode 100644 drivers/gpu/drm/verisilicon/vs_crtc.h
 create mode 100644 drivers/gpu/drm/verisilicon/vs_dc.c
 create mode 100644 drivers/gpu/drm/verisilicon/vs_dc.h
 create mode 100644 drivers/gpu/drm/verisilicon/vs_dc_hw.c
 create mode 100644 drivers/gpu/drm/verisilicon/vs_dc_hw.h
 create mode 100644 drivers/gpu/drm/verisilicon/vs_drv.c
 create mode 100644 drivers/gpu/drm/verisilicon/vs_drv.h
 create mode 100644 drivers/gpu/drm/verisilicon/vs_gem.c
 create mode 100644 drivers/gpu/drm/verisilicon/vs_gem.h
 create mode 100644 drivers/gpu/drm/verisilicon/vs_modeset.c
 create mode 100644 drivers/gpu/drm/verisilicon/vs_modeset.h
 create mode 100644 drivers/gpu/drm/verisilicon/vs_plane.c
 create mode 100644 drivers/gpu/drm/verisilicon/vs_plane.h
 create mode 100644 drivers/gpu/drm/verisilicon/vs_type.h
 create mode 100644 include/uapi/drm/vs_drm.h

-- 
2.34.1



[PATCH v1 v1 3/7] riscv: dts: starfive: jh7110: add dc controller and hdmi node

2023-08-01 Thread Keith Zhao
Add the dc controller and hdmi node for the Starfive JH7110 SoC.

Signed-off-by: Keith Zhao 
---
 .../jh7110-starfive-visionfive-2.dtsi | 87 +++
 arch/riscv/boot/dts/starfive/jh7110.dtsi  | 43 +
 2 files changed, 130 insertions(+)

diff --git a/arch/riscv/boot/dts/starfive/jh7110-starfive-visionfive-2.dtsi 
b/arch/riscv/boot/dts/starfive/jh7110-starfive-visionfive-2.dtsi
index de0f40a8b..32e5cc96c 100644
--- a/arch/riscv/boot/dts/starfive/jh7110-starfive-visionfive-2.dtsi
+++ b/arch/riscv/boot/dts/starfive/jh7110-starfive-visionfive-2.dtsi
@@ -31,6 +31,21 @@ memory@4000 {
reg = <0x0 0x4000 0x1 0x0>;
};
 
+   reserved-memory {
+   #address-cells = <2>;
+   #size-cells = <2>;
+   ranges;
+
+   linux,cma {
+   compatible = "shared-dma-pool";
+   reusable;
+   size = <0x0 0x2000>;
+   alignment = <0x0 0x1000>;
+   alloc-ranges = <0x0 0x8000 0x0 0x2000>;
+   linux,cma-default;
+   };
+   };
+
gpio-restart {
compatible = "gpio-restart";
gpios = < 35 GPIO_ACTIVE_HIGH>;
@@ -231,6 +246,41 @@ GPOEN_DISABLE,
slew-rate = <0>;
};
};
+
+   hdmi_pins: hdmi-0 {
+   hdmi-scl-pins {
+   pinmux = ;
+   input-enable;
+   bias-pull-up;
+   };
+
+   hdmi-sda-pins {
+   pinmux = ;
+   input-enable;
+   bias-pull-up;
+   };
+
+   hdmi-cec-pins {
+   pinmux = ;
+   input-enable;
+   bias-pull-up;
+   };
+
+   hdmi-hpd-pins {
+   pinmux = ;
+   input-enable;
+   bias-disable; /* external pull-up */
+   };
+   };
+
 };
 
  {
@@ -254,3 +304,40 @@ _3 {
 _4 {
cpu-supply = <_cpu>;
 };
+
+ {
+   status = "okay";
+};
+
+ {
+   status = "okay";
+};
+
+ {
+   status = "okay";
+   pinctrl-names = "default";
+   pinctrl-0 = <_pins>;
+
+   hdmi_in: port {
+   #address-cells = <1>;
+   #size-cells = <0>;
+   hdmi_in_dc: endpoint@0 {
+   reg = <0>;
+   remote-endpoint = <_out_hdmi>;
+   };
+   };
+};
+
+ {
+   status = "okay";
+
+   dc_out: port {
+   #address-cells = <1>;
+   #size-cells = <0>;
+   dc_out_hdmi: endpoint@0 {
+   reg = <0>;
+   remote-endpoint = <_in_dc>;
+   };
+
+   };
+};
diff --git a/arch/riscv/boot/dts/starfive/jh7110.dtsi 
b/arch/riscv/boot/dts/starfive/jh7110.dtsi
index 0005fa163..b8c527d9f 100644
--- a/arch/riscv/boot/dts/starfive/jh7110.dtsi
+++ b/arch/riscv/boot/dts/starfive/jh7110.dtsi
@@ -282,6 +282,11 @@ tdm_ext: tdm-ext-clock {
#clock-cells = <0>;
};
 
+   display: display-subsystem {
+   compatible = "starfive,display-subsystem";
+   ports = <_out>;
+   };
+
soc {
compatible = "simple-bus";
interrupt-parent = <>;
@@ -613,5 +618,43 @@ voutcrg: clock-controller@295c {
#reset-cells = <1>;
power-domains = < JH7110_PD_VOUT>;
};
+
+   dc8200: lcd-controller@2940 {
+   compatible = "starfive,jh7110-dc8200";
+   reg = <0x0 0x2940 0x0 0x100>,
+ <0x0 0x29400800 0x0 0x2000>,
+ <0x0 0x295b 0x0 0x90>;
+   interrupts = <95>;
+   clocks = < JH7110_SYSCLK_NOC_BUS_DISP_AXI>,
+   < JH7110_VOUTCLK_DC8200_PIX0>,
+   < JH7110_VOUTCLK_DC8200_PIX1>,
+   < JH7110_VOUTCLK_DC8200_AXI>,
+   < JH7110_VOUTCLK_DC8200_CORE>,
+   < JH7110_VOUTCLK_DC8200_AHB>,
+   <_pixelclk>,
+   < JH7110_VOUTCLK_DC8200_PIX>;
+   clock-names = "vout_noc_disp", "vout_pix0", "vout_pix1",
+ "vout_axi", "vout_

[PATCH v1 v1 2/7] dt-bindings: display: Add yamls for JH7110 display system

2023-08-01 Thread Keith Zhao
StarFive SoCs JH7110 display system:
lcd-controller bases verisilicon dc8200 IP,
and hdmi bases Innosilicon IP.
Add bindings for them.

Signed-off-by: Keith Zhao 
---
 .../starfive/starfive,display-subsystem.yaml  |  41 +++
 .../starfive/starfive,jh7110-dc8200.yaml  | 107 ++
 .../starfive/starfive,jh7110-inno-hdmi.yaml   |  92 +++
 3 files changed, 240 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/display/starfive/starfive,display-subsystem.yaml
 create mode 100644 
Documentation/devicetree/bindings/display/starfive/starfive,jh7110-dc8200.yaml
 create mode 100644 
Documentation/devicetree/bindings/display/starfive/starfive,jh7110-inno-hdmi.yaml

diff --git 
a/Documentation/devicetree/bindings/display/starfive/starfive,display-subsystem.yaml
 
b/Documentation/devicetree/bindings/display/starfive/starfive,display-subsystem.yaml
new file mode 100644
index 0..86018a8e6
--- /dev/null
+++ 
b/Documentation/devicetree/bindings/display/starfive/starfive,display-subsystem.yaml
@@ -0,0 +1,41 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: 
http://devicetree.org/schemas/display/starfive/starfive,display-subsystem.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Starfive DRM master device
+
+maintainers:
+  - Keith Zhao 
+  - ShengYang Chen 
+
+description:
+  The Starfive DRM master device is a virtual device needed to list all
+  display controller or other display interface nodes that comprise the
+  graphics subsystem.
+
+properties:
+  compatible:
+const: starfive,display-subsystem
+
+  ports:
+$ref: /schemas/graph.yaml#/properties/ports
+description: |
+  Should contain a list of phandles pointing to display interface ports
+  of display controller devices. Display controller definitions as defined
+  in Documentation/devicetree/bindings/display/starfive/
+  starfive,jh7110-dc8200.yaml
+
+required:
+  - compatible
+  - ports
+
+additionalProperties: false
+
+examples:
+  - |
+display-subsystem {
+compatible = "starfive,display-subsystem";
+ports = <_out>;
+};
diff --git 
a/Documentation/devicetree/bindings/display/starfive/starfive,jh7110-dc8200.yaml
 
b/Documentation/devicetree/bindings/display/starfive/starfive,jh7110-dc8200.yaml
new file mode 100644
index 0..bebe2050c
--- /dev/null
+++ 
b/Documentation/devicetree/bindings/display/starfive/starfive,jh7110-dc8200.yaml
@@ -0,0 +1,107 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: 
http://devicetree.org/schemas/display/starfive/starfive,jh7110-dc8200.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: StarFive display controller
+
+description:
+  The StarFive SoC uses the display controller based on Verisilicon IP
+  to transfer the image data from a video memory
+  buffer to an external LCD interface.
+
+maintainers:
+  - Keith Zhao 
+
+properties:
+  compatible:
+const: starfive,jh7110-dc8200
+
+  reg:
+maxItems: 3
+
+  interrupts:
+items:
+  - description: The interrupt will be generated when DC finish one frame
+
+  clocks:
+items:
+  - description: Clock for display system noc bus.
+  - description: Pixel clock for display channel 0.
+  - description: Pixel clock for display channel 1.
+  - description: Clock for axi interface of display controller.
+  - description: Core clock for display controller.
+  - description: Clock for ahb interface of display controller.
+  - description: External HDMI pixel clock.
+  - description: Parent clock for pixel clock
+
+  clock-names:
+items:
+  - const: vout_noc_disp
+  - const: vout_pix0
+  - const: vout_pix1
+  - const: vout_axi
+  - const: vout_core
+  - const: vout_vout_ahb
+  - const: hdmitx0_pixel
+  - const: vout_dc8200
+
+  resets:
+items:
+  - description: Reset for axi interface of display controller.
+  - description: Reset for ahb interface of display controller.
+  - description: Core reset of display controller.
+
+  reset-names:
+items:
+  - const: vout_axi
+  - const: vout_ahb
+  - const: vout_core
+
+  port:
+$ref: /schemas/graph.yaml#/properties/port
+description:
+  A port node with endpoint definitions as defined in
+  Documentation/devicetree/bindings/media/video-interfaces.txt.
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - clocks
+  - clock-names
+  - resets
+  - reset-names
+  - port
+
+additionalProperties: false
+
+examples:
+  - |
+dc8200: lcd-controller@2940 {
+compatible = "starfive,jh7110-dc8200";
+reg = <0x2940 0x100>, <0x29400800 0x2000>, <0x295b 0x90>;
+interrupts = <95>;
+clocks = < 60>,
+   < 7>,
+   < 8>,
+   < 4>,
+   &l

[PATCH v1 v1 5/7] drm/vs: Register DRM device

2023-08-01 Thread Keith Zhao
Implement drm device registration interface

Signed-off-by: Keith Zhao 
---
 drivers/gpu/drm/Kconfig  |   2 +
 drivers/gpu/drm/Makefile |   1 +
 drivers/gpu/drm/verisilicon/Kconfig  |  25 ++
 drivers/gpu/drm/verisilicon/Makefile |  13 +
 drivers/gpu/drm/verisilicon/vs_drv.c | 273 +
 drivers/gpu/drm/verisilicon/vs_drv.h |  54 
 drivers/gpu/drm/verisilicon/vs_gem.c | 298 +++
 drivers/gpu/drm/verisilicon/vs_gem.h |  50 
 drivers/gpu/drm/verisilicon/vs_modeset.c |  92 +++
 drivers/gpu/drm/verisilicon/vs_modeset.h |  13 +
 include/uapi/drm/vs_drm.h|  50 
 11 files changed, 871 insertions(+)
 create mode 100644 drivers/gpu/drm/verisilicon/Kconfig
 create mode 100644 drivers/gpu/drm/verisilicon/Makefile
 create mode 100644 drivers/gpu/drm/verisilicon/vs_drv.c
 create mode 100644 drivers/gpu/drm/verisilicon/vs_drv.h
 create mode 100644 drivers/gpu/drm/verisilicon/vs_gem.c
 create mode 100644 drivers/gpu/drm/verisilicon/vs_gem.h
 create mode 100644 drivers/gpu/drm/verisilicon/vs_modeset.c
 create mode 100644 drivers/gpu/drm/verisilicon/vs_modeset.h
 create mode 100644 include/uapi/drm/vs_drm.h

diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig
index afb3b2f5f..9ede80ef9 100644
--- a/drivers/gpu/drm/Kconfig
+++ b/drivers/gpu/drm/Kconfig
@@ -363,6 +363,8 @@ source "drivers/gpu/drm/solomon/Kconfig"
 
 source "drivers/gpu/drm/sprd/Kconfig"
 
+source "drivers/gpu/drm/verisilicon/Kconfig"
+
 config DRM_HYPERV
tristate "DRM Support for Hyper-V synthetic video device"
depends on DRM && PCI && MMU && HYPERV
diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
index 7a09a89b4..6db3bc397 100644
--- a/drivers/gpu/drm/Makefile
+++ b/drivers/gpu/drm/Makefile
@@ -194,3 +194,4 @@ obj-y   += gud/
 obj-$(CONFIG_DRM_HYPERV) += hyperv/
 obj-y  += solomon/
 obj-$(CONFIG_DRM_SPRD) += sprd/
+obj-$(CONFIG_DRM_VERISILICON) += verisilicon/
diff --git a/drivers/gpu/drm/verisilicon/Kconfig 
b/drivers/gpu/drm/verisilicon/Kconfig
new file mode 100644
index 0..fcc39dded
--- /dev/null
+++ b/drivers/gpu/drm/verisilicon/Kconfig
@@ -0,0 +1,25 @@
+# SPDX-License-Identifier: GPL-2.0
+config DRM_VERISILICON
+   tristate "DRM Support for VeriSilicon"
+   depends on DRM
+   select DRM_KMS_HELPER
+   select DRM_GEM_DMA_HELPER
+   select CMA
+   select DMA_CMA
+   help
+ Choose this option if you have a VeriSilicon soc chipset.
+ This driver provides VeriSilicon kernel mode
+ setting and buffer management. It does not
+ provide 2D or 3D acceleration.
+
+if DRM_VERISILICON
+
+config STARFIVE_HDMI
+   bool "Starfive specific extensions HDMI"
+   help
+  This selects support for StarFive SoC specific extensions
+  for the Innosilicon HDMI driver. If you want to enable
+  HDMI on JH7110 based SoC, you should select this option.
+
+  To compile this driver as a module, choose M here.
+endif
diff --git a/drivers/gpu/drm/verisilicon/Makefile 
b/drivers/gpu/drm/verisilicon/Makefile
new file mode 100644
index 0..26cc7e21b
--- /dev/null
+++ b/drivers/gpu/drm/verisilicon/Makefile
@@ -0,0 +1,13 @@
+# SPDX-License-Identifier: GPL-2.0
+
+vs_drm-objs := vs_dc_hw.o \
+   vs_dc.o \
+   vs_crtc.o \
+   vs_drv.o \
+   vs_modeset.o \
+   vs_gem.o \
+   vs_plane.o
+
+vs_drm-$(CONFIG_STARFIVE_HDMI) += starfive_hdmi.o
+obj-$(CONFIG_DRM_VERISILICON) += vs_drm.o
+
diff --git a/drivers/gpu/drm/verisilicon/vs_drv.c 
b/drivers/gpu/drm/verisilicon/vs_drv.c
new file mode 100644
index 0..69591e640
--- /dev/null
+++ b/drivers/gpu/drm/verisilicon/vs_drv.c
@@ -0,0 +1,273 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2023 VeriSilicon Holdings Co., Ltd.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "vs_drv.h"
+#include "vs_modeset.h"
+#include "vs_gem.h"
+
+#define DRV_NAME   "starfive"
+#define DRV_DESC   "Starfive DRM driver"
+#define DRV_DATE   "202305161"
+#define DRV_MAJOR  1
+#define DRV_MINOR  0
+
+static struct platform_driver vs_drm_platform_driver;
+
+static const struct file_operations fops = {
+   .owner  = THIS_MODULE,
+   .open   = drm_open,
+   .release= drm_release,
+   .unlocked_ioctl = drm_ioctl,
+   .compat_ioctl   = drm_compat_ioctl,
+   .poll   = drm

Re: [PATCH 3/9] drm/verisilicon: Add basic drm driver

2023-07-25 Thread Keith Zhao



On 2023/7/25 11:12, Keith Zhao wrote:
> 
> 
> On 2023/6/7 16:53, Lucas Stach wrote:
>> Hi Keith,
>> 
>> Am Freitag, dem 02.06.2023 um 15:40 +0800 schrieb Keith Zhao:
>>> Add a basic platform driver of the DRM driver for JH7110 SoC.
>>> 
>>> Signed-off-by: Keith Zhao 
>>> ---
>>>  MAINTAINERS  |   2 +
>>>  drivers/gpu/drm/Kconfig  |   2 +
>>>  drivers/gpu/drm/Makefile |   1 +
>>>  drivers/gpu/drm/verisilicon/Kconfig  |  13 ++
>>>  drivers/gpu/drm/verisilicon/Makefile |   6 +
>>>  drivers/gpu/drm/verisilicon/vs_drv.c | 284 +++
>>>  drivers/gpu/drm/verisilicon/vs_drv.h |  48 +
>>>  include/uapi/drm/drm_fourcc.h|  83 
>>>  include/uapi/drm/vs_drm.h|  50 +
>>>  9 files changed, 489 insertions(+)
>>>  create mode 100644 drivers/gpu/drm/verisilicon/Kconfig
>>>  create mode 100644 drivers/gpu/drm/verisilicon/Makefile
>>>  create mode 100644 drivers/gpu/drm/verisilicon/vs_drv.c
>>>  create mode 100644 drivers/gpu/drm/verisilicon/vs_drv.h
>>>  create mode 100644 include/uapi/drm/vs_drm.h
>>> 
>>> 
>>> [...]
>>> +#endif /* __VS_DRV_H__ */
>>> diff --git a/include/uapi/drm/drm_fourcc.h b/include/uapi/drm/drm_fourcc.h
>>> index de703c6be969..af4fb50f9207 100644
>>> --- a/include/uapi/drm/drm_fourcc.h
>>> +++ b/include/uapi/drm/drm_fourcc.h
>>> @@ -419,6 +419,7 @@ extern "C" {
>>>  #define DRM_FORMAT_MOD_VENDOR_ARM 0x08
>>>  #define DRM_FORMAT_MOD_VENDOR_ALLWINNER 0x09
>>>  #define DRM_FORMAT_MOD_VENDOR_AMLOGIC 0x0a
>>> +#define DRM_FORMAT_MOD_VENDOR_VS  0x0b
>>>  
>>>  /* add more to the end as needed */
>>>  
>>> @@ -1519,6 +1520,88 @@ drm_fourcc_canonicalize_nvidia_format_mod(__u64 
>>> modifier)
>>>  #define AMD_FMT_MOD_CLEAR(field) \
>>> (~((__u64)AMD_FMT_MOD_##field##_MASK << AMD_FMT_MOD_##field##_SHIFT))
>>>  
>>> +#define DRM_FORMAT_MOD_VS_TYPE_NORMAL0x00
>>> +#define DRM_FORMAT_MOD_VS_TYPE_COMPRESSED0x01
>>> +#define DRM_FORMAT_MOD_VS_TYPE_CUSTOM_10BIT  0x02
>>> +#define DRM_FORMAT_MOD_VS_TYPE_MASK ((__u64)0x3 << 54)
>>> +
>>> +#define fourcc_mod_vs_code(type, val) \
>>> +   fourcc_mod_code(VS, __u64)type) << 54) | (val)))
>>> +
>>> +#define DRM_FORMAT_MOD_VS_DEC_TILE_MODE_MASK0x3F
>>> +#define DRM_FORMAT_MOD_VS_DEC_TILE_8X8_XMAJOR   0x00
>>> +#define DRM_FORMAT_MOD_VS_DEC_TILE_8X8_YMAJOR   0x01
>>> +#define DRM_FORMAT_MOD_VS_DEC_TILE_16X4 0x02
>>> +#define DRM_FORMAT_MOD_VS_DEC_TILE_8X4  0x03
>>> +#define DRM_FORMAT_MOD_VS_DEC_TILE_4X8  0x04
>>> +#define DRM_FORMAT_MOD_VS_DEC_RASTER_16X4   0x06
>>> +#define DRM_FORMAT_MOD_VS_DEC_TILE_64X4 0x07
>>> +#define DRM_FORMAT_MOD_VS_DEC_TILE_32X4 0x08
>>> +#define DRM_FORMAT_MOD_VS_DEC_RASTER_256X1  0x09
>>> +#define DRM_FORMAT_MOD_VS_DEC_RASTER_128X1  0x0A
>>> +#define DRM_FORMAT_MOD_VS_DEC_RASTER_64X4   0x0B
>>> +#define DRM_FORMAT_MOD_VS_DEC_RASTER_256X2  0x0C
>>> +#define DRM_FORMAT_MOD_VS_DEC_RASTER_128X2  0x0D
>>> +#define DRM_FORMAT_MOD_VS_DEC_RASTER_128X4  0x0E
>>> +#define DRM_FORMAT_MOD_VS_DEC_RASTER_64X1   0x0F
>>> +#define DRM_FORMAT_MOD_VS_DEC_TILE_16X8 0x10
>>> +#define DRM_FORMAT_MOD_VS_DEC_TILE_8X16 0x11
>>> +#define DRM_FORMAT_MOD_VS_DEC_RASTER_512X1  0x12
>>> +#define DRM_FORMAT_MOD_VS_DEC_RASTER_32X4   0x13
>>> +#define DRM_FORMAT_MOD_VS_DEC_RASTER_64X2   0x14
>>> +#define DRM_FORMAT_MOD_VS_DEC_RASTER_32X2   0x15
>>> +#define DRM_FORMAT_MOD_VS_DEC_RASTER_32X1   0x16
>>> +#define DRM_FORMAT_MOD_VS_DEC_RASTER_16X1   0x17
>>> +#define DRM_FORMAT_MOD_VS_DEC_TILE_128X40x18
>>> +#define DRM_FORMAT_MOD_VS_DEC_TILE_256X40x19
>>> +#define DRM_FORMAT_MOD_VS_DEC_TILE_512X40x1A
>>> +#define DRM_FORMAT_MOD_VS_DEC_TILE_16X160x1B
>>> +#define DRM_FORMAT_MOD_VS_DEC_TILE_32X160x1C
>>> +#define DRM_FORMAT_MOD_VS_DEC_TILE_64X160x1D
>>> +#define DRM_FORMAT_MOD_VS_DEC_TILE_128X80x1E
>>> +#define DRM_FORMAT_MOD_VS_DEC_TILE_8X4_S0x1F
>>> +#define DRM_FORMAT_MOD_VS_DEC_TILE_16X4_S   0x20
>>> +#define DRM_FORMAT_MOD_VS_DEC_TILE_32X4_S   0x21
>>> +#define DRM_FORMAT_MOD_VS_DEC_TILE_16X4_LSB 0x22
>>> +#define DRM_FORMAT_MOD_VS_DEC_TILE_32X4_LSB 0x23
>>> +#define DRM_

Re: [PATCH 3/9] drm/verisilicon: Add basic drm driver

2023-07-24 Thread Keith Zhao



On 2023/6/7 16:53, Lucas Stach wrote:
> Hi Keith,
> 
> Am Freitag, dem 02.06.2023 um 15:40 +0800 schrieb Keith Zhao:
>> Add a basic platform driver of the DRM driver for JH7110 SoC.
>> 
>> Signed-off-by: Keith Zhao 
>> ---
>>  MAINTAINERS  |   2 +
>>  drivers/gpu/drm/Kconfig  |   2 +
>>  drivers/gpu/drm/Makefile |   1 +
>>  drivers/gpu/drm/verisilicon/Kconfig  |  13 ++
>>  drivers/gpu/drm/verisilicon/Makefile |   6 +
>>  drivers/gpu/drm/verisilicon/vs_drv.c | 284 +++
>>  drivers/gpu/drm/verisilicon/vs_drv.h |  48 +
>>  include/uapi/drm/drm_fourcc.h|  83 
>>  include/uapi/drm/vs_drm.h|  50 +
>>  9 files changed, 489 insertions(+)
>>  create mode 100644 drivers/gpu/drm/verisilicon/Kconfig
>>  create mode 100644 drivers/gpu/drm/verisilicon/Makefile
>>  create mode 100644 drivers/gpu/drm/verisilicon/vs_drv.c
>>  create mode 100644 drivers/gpu/drm/verisilicon/vs_drv.h
>>  create mode 100644 include/uapi/drm/vs_drm.h
>> 
>> 
>> [...]
>> +#endif /* __VS_DRV_H__ */
>> diff --git a/include/uapi/drm/drm_fourcc.h b/include/uapi/drm/drm_fourcc.h
>> index de703c6be969..af4fb50f9207 100644
>> --- a/include/uapi/drm/drm_fourcc.h
>> +++ b/include/uapi/drm/drm_fourcc.h
>> @@ -419,6 +419,7 @@ extern "C" {
>>  #define DRM_FORMAT_MOD_VENDOR_ARM 0x08
>>  #define DRM_FORMAT_MOD_VENDOR_ALLWINNER 0x09
>>  #define DRM_FORMAT_MOD_VENDOR_AMLOGIC 0x0a
>> +#define DRM_FORMAT_MOD_VENDOR_VS  0x0b
>>  
>>  /* add more to the end as needed */
>>  
>> @@ -1519,6 +1520,88 @@ drm_fourcc_canonicalize_nvidia_format_mod(__u64 
>> modifier)
>>  #define AMD_FMT_MOD_CLEAR(field) \
>>  (~((__u64)AMD_FMT_MOD_##field##_MASK << AMD_FMT_MOD_##field##_SHIFT))
>>  
>> +#define DRM_FORMAT_MOD_VS_TYPE_NORMAL0x00
>> +#define DRM_FORMAT_MOD_VS_TYPE_COMPRESSED0x01
>> +#define DRM_FORMAT_MOD_VS_TYPE_CUSTOM_10BIT  0x02
>> +#define DRM_FORMAT_MOD_VS_TYPE_MASK ((__u64)0x3 << 54)
>> +
>> +#define fourcc_mod_vs_code(type, val) \
>> +fourcc_mod_code(VS, __u64)type) << 54) | (val)))
>> +
>> +#define DRM_FORMAT_MOD_VS_DEC_TILE_MODE_MASK0x3F
>> +#define DRM_FORMAT_MOD_VS_DEC_TILE_8X8_XMAJOR   0x00
>> +#define DRM_FORMAT_MOD_VS_DEC_TILE_8X8_YMAJOR   0x01
>> +#define DRM_FORMAT_MOD_VS_DEC_TILE_16X4 0x02
>> +#define DRM_FORMAT_MOD_VS_DEC_TILE_8X4  0x03
>> +#define DRM_FORMAT_MOD_VS_DEC_TILE_4X8  0x04
>> +#define DRM_FORMAT_MOD_VS_DEC_RASTER_16X4   0x06
>> +#define DRM_FORMAT_MOD_VS_DEC_TILE_64X4 0x07
>> +#define DRM_FORMAT_MOD_VS_DEC_TILE_32X4 0x08
>> +#define DRM_FORMAT_MOD_VS_DEC_RASTER_256X1  0x09
>> +#define DRM_FORMAT_MOD_VS_DEC_RASTER_128X1  0x0A
>> +#define DRM_FORMAT_MOD_VS_DEC_RASTER_64X4   0x0B
>> +#define DRM_FORMAT_MOD_VS_DEC_RASTER_256X2  0x0C
>> +#define DRM_FORMAT_MOD_VS_DEC_RASTER_128X2  0x0D
>> +#define DRM_FORMAT_MOD_VS_DEC_RASTER_128X4  0x0E
>> +#define DRM_FORMAT_MOD_VS_DEC_RASTER_64X1   0x0F
>> +#define DRM_FORMAT_MOD_VS_DEC_TILE_16X8 0x10
>> +#define DRM_FORMAT_MOD_VS_DEC_TILE_8X16 0x11
>> +#define DRM_FORMAT_MOD_VS_DEC_RASTER_512X1  0x12
>> +#define DRM_FORMAT_MOD_VS_DEC_RASTER_32X4   0x13
>> +#define DRM_FORMAT_MOD_VS_DEC_RASTER_64X2   0x14
>> +#define DRM_FORMAT_MOD_VS_DEC_RASTER_32X2   0x15
>> +#define DRM_FORMAT_MOD_VS_DEC_RASTER_32X1   0x16
>> +#define DRM_FORMAT_MOD_VS_DEC_RASTER_16X1   0x17
>> +#define DRM_FORMAT_MOD_VS_DEC_TILE_128X40x18
>> +#define DRM_FORMAT_MOD_VS_DEC_TILE_256X40x19
>> +#define DRM_FORMAT_MOD_VS_DEC_TILE_512X40x1A
>> +#define DRM_FORMAT_MOD_VS_DEC_TILE_16X160x1B
>> +#define DRM_FORMAT_MOD_VS_DEC_TILE_32X160x1C
>> +#define DRM_FORMAT_MOD_VS_DEC_TILE_64X160x1D
>> +#define DRM_FORMAT_MOD_VS_DEC_TILE_128X80x1E
>> +#define DRM_FORMAT_MOD_VS_DEC_TILE_8X4_S0x1F
>> +#define DRM_FORMAT_MOD_VS_DEC_TILE_16X4_S   0x20
>> +#define DRM_FORMAT_MOD_VS_DEC_TILE_32X4_S   0x21
>> +#define DRM_FORMAT_MOD_VS_DEC_TILE_16X4_LSB 0x22
>> +#define DRM_FORMAT_MOD_VS_DEC_TILE_32X4_LSB 0x23
>> +#define DRM_FORMAT_MOD_VS_DEC_TILE_32X8 0x24
>> +
>> +#define DRM_FORMAT_MOD_VS_DEC_ALIGN_32  (0x01 << 6)
>> +#define DRM_FORMAT_MOD_VS_DEC_ALIGN_64  (0x01 << 7)
>> +
>> +#define fourcc_mod_vs_dec_code(tile, align) \
>> +fourcc_mod_vs_code(DRM_FORMAT_MOD_VS_TYPE_COMPRESSED, \
>> +((tile) | (align)))
>> +
>

Re: [PATCH 6/9] drm/verisilicon: Add drm crtc funcs

2023-07-21 Thread Keith Zhao



On 2023/6/30 19:55, Thomas Zimmermann wrote:
> Hi
> 
> Am 02.06.23 um 09:40 schrieb Keith Zhao:
>> Add crtc driver which implements crtc related operation functions.
>>
>> Signed-off-by: Keith Zhao 
>> ---
>>   drivers/gpu/drm/verisilicon/Makefile  |   1 +
>>   drivers/gpu/drm/verisilicon/vs_crtc.c | 388 ++
>>   drivers/gpu/drm/verisilicon/vs_crtc.h |  74 +
>>   drivers/gpu/drm/verisilicon/vs_type.h |  72 +
>>   4 files changed, 535 insertions(+)
>>   create mode 100644 drivers/gpu/drm/verisilicon/vs_crtc.c
>>   create mode 100644 drivers/gpu/drm/verisilicon/vs_crtc.h
>>   create mode 100644 drivers/gpu/drm/verisilicon/vs_type.h
>>
>> diff --git a/drivers/gpu/drm/verisilicon/Makefile 
>> b/drivers/gpu/drm/verisilicon/Makefile
>> index 38254dc5d98d..bae5fbab9bbb 100644
>> --- a/drivers/gpu/drm/verisilicon/Makefile
>> +++ b/drivers/gpu/drm/verisilicon/Makefile
>> @@ -1,6 +1,7 @@
>>   # SPDX-License-Identifier: GPL-2.0
>>     vs_drm-objs := vs_drv.o \
>> +    vs_crtc.o \
>>   vs_fb.o \
>>   vs_gem.o
>>   diff --git a/drivers/gpu/drm/verisilicon/vs_crtc.c 
>> b/drivers/gpu/drm/verisilicon/vs_crtc.c
>> new file mode 100644
>> index ..a9e742d7bd1a
>> --- /dev/null
>> +++ b/drivers/gpu/drm/verisilicon/vs_crtc.c
>> @@ -0,0 +1,388 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +/*
>> + * Copyright (C) 2023 VeriSilicon Holdings Co., Ltd.
>> + *
>> + */
>> +
>> +#include 
>> +#include 
>> +#include 
>> +
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +
>> +#include "vs_crtc.h"
>> +
>> +void vs_crtc_destroy(struct drm_crtc *crtc)
>> +{
>> +    struct vs_crtc *vs_crtc = to_vs_crtc(crtc);
>> +
>> +    drm_crtc_cleanup(crtc);
>> +    kfree(vs_crtc);
>> +}
>> +
>> +static void vs_crtc_reset(struct drm_crtc *crtc)
>> +{
>> +    struct vs_crtc_state *state;
>> +
>> +    if (crtc->state) {
>> +    __drm_atomic_helper_crtc_destroy_state(crtc->state);
>> +
>> +    state = to_vs_crtc_state(crtc->state);
>> +    kfree(state);
>> +    crtc->state = NULL;
>> +    }
>> +
>> +    state = kzalloc(sizeof(*state), GFP_KERNEL);
>> +    if (!state)
>> +    return;
>> +
>> +    __drm_atomic_helper_crtc_reset(crtc, >base);
>> +
>> +    state->sync_mode = VS_SINGLE_DC;
>> +    state->output_fmt = MEDIA_BUS_FMT_RBG888_1X24;
>> +    state->encoder_type = DRM_MODE_ENCODER_NONE;
>> +}
>> +
>> +static struct drm_crtc_state *
>> +vs_crtc_atomic_duplicate_state(struct drm_crtc *crtc)
>> +{
>> +    struct vs_crtc_state *ori_state;
>> +    struct vs_crtc_state *state;
>> +
>> +    if (WARN_ON(!crtc->state))
>> +    return NULL;
> 
> I'd leave this check out. IIRC, crtc->state not supposed to be NULL here. 
> Rather let it crash.
> 
>> +
>> +    ori_state = to_vs_crtc_state(crtc->state);
>> +    state = kzalloc(sizeof(*state), GFP_KERNEL);
>> +    if (!state)
>> +    return NULL;
>> +
>> +    __drm_atomic_helper_crtc_duplicate_state(crtc, >base);
>> +
>> +    state->sync_mode = ori_state->sync_mode;
>> +    state->output_fmt = ori_state->output_fmt;
>> +    state->encoder_type = ori_state->encoder_type;
>> +    state->bg_color = ori_state->bg_color;
>> +    state->bpp = ori_state->bpp;
>> +    state->sync_enable = ori_state->sync_enable;
>> +    state->dither_enable = ori_state->dither_enable;
>> +    state->underflow = ori_state->underflow;
>> +
>> +    return >base;
>> +}
>> +
>> +static void vs_crtc_atomic_destroy_state(struct drm_crtc *crtc,
>> + struct drm_crtc_state *state)
>> +{
>> +    __drm_atomic_helper_crtc_destroy_state(state);
>> +    kfree(to_vs_crtc_state(state));
>> +}
>> +
>> +static int vs_crtc_atomic_set_property(struct drm_crtc *crtc,
>> +   struct drm_crtc_state *state,
>> +   struct drm_property *property,
>> +   uint64_t val)
>> +{
>> +    struct vs_crtc *vs_crtc = to_vs_crtc(crtc);
>> +    struct vs_crtc_state *vs_crtc_state = to_vs_crtc_state(state);
>> +
>> +    if (property == vs_crtc->sync_mode)
>> +    vs_crtc_state->sync_mode = val;
>&g

Re: [PATCH 5/9] drm/verisilicon: Add mode config funcs

2023-07-21 Thread Keith Zhao



On 2023/6/21 19:04, Thomas Zimmermann wrote:
> Hi Keith
> 
> Am 02.06.23 um 09:40 schrieb Keith Zhao:
>> Add mode setting functions for JH7110 SoC.
>>
>> Signed-off-by: Keith Zhao 
>> ---
>>   drivers/gpu/drm/verisilicon/Makefile |   1 +
>>   drivers/gpu/drm/verisilicon/vs_drv.c |   3 +
> 
>>   drivers/gpu/drm/verisilicon/vs_fb.c  | 181 +++
>>   drivers/gpu/drm/verisilicon/vs_fb.h  |  15 +++
> 
> I'd call these files vs_modeset.{c,h} to be consistent with the rest of the 
> drivers.
> 
>>   4 files changed, 200 insertions(+)
>>   create mode 100644 drivers/gpu/drm/verisilicon/vs_fb.c
>>   create mode 100644 drivers/gpu/drm/verisilicon/vs_fb.h
>>
>> diff --git a/drivers/gpu/drm/verisilicon/Makefile 
>> b/drivers/gpu/drm/verisilicon/Makefile
>> index 30360e370e47..38254dc5d98d 100644
>> --- a/drivers/gpu/drm/verisilicon/Makefile
>> +++ b/drivers/gpu/drm/verisilicon/Makefile
>> @@ -1,6 +1,7 @@
>>   # SPDX-License-Identifier: GPL-2.0
>>     vs_drm-objs := vs_drv.o \
>> +    vs_fb.o \
>>   vs_gem.o
>>     obj-$(CONFIG_DRM_VERISILICON) += vs_drm.o
>> diff --git a/drivers/gpu/drm/verisilicon/vs_drv.c 
>> b/drivers/gpu/drm/verisilicon/vs_drv.c
>> index e0a2fc43b55f..d84aacd751bc 100644
>> --- a/drivers/gpu/drm/verisilicon/vs_drv.c
>> +++ b/drivers/gpu/drm/verisilicon/vs_drv.c
>> @@ -30,6 +30,7 @@
>>   #include 
>>     #include "vs_drv.h"
>> +#include "vs_fb.h"
>>   #include "vs_gem.h"
>>     #define DRV_NAME    "starfive"
>> @@ -118,6 +119,8 @@ static int vs_drm_bind(struct device *dev)
>>   if (ret)
>>   goto err_mode;
>>   +    vs_mode_config_init(drm_dev);
>> +
>>   ret = drm_vblank_init(drm_dev, drm_dev->mode_config.num_crtc);
>>   if (ret)
>>   goto err_bind;
>> diff --git a/drivers/gpu/drm/verisilicon/vs_fb.c 
>> b/drivers/gpu/drm/verisilicon/vs_fb.c
>> new file mode 100644
>> index ..3e85f7365084
>> --- /dev/null
>> +++ b/drivers/gpu/drm/verisilicon/vs_fb.c
>> @@ -0,0 +1,181 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +/*
>> + * Copyright (C) 2023 VeriSilicon Holdings Co., Ltd.
>> + */
>> +
>> +#include 
>> +#include 
>> +
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +
>> +#include "vs_fb.h"
>> +#include "vs_gem.h"
>> +
>> +#define fourcc_mod_vs_get_type(val) \
>> +    (((val) & DRM_FORMAT_MOD_VS_TYPE_MASK) >> 54)
>> +
>> +static struct drm_framebuffer_funcs vs_fb_funcs = {
>> +    .create_handle    = drm_gem_fb_create_handle,
>> +    .destroy    = drm_gem_fb_destroy,
>> +    .dirty    = drm_atomic_helper_dirtyfb,
>> +};
>> +
>> +static struct drm_framebuffer *
>> +vs_fb_alloc(struct drm_device *dev, const struct drm_mode_fb_cmd2 *mode_cmd,
>> +    struct vs_gem_object **obj, unsigned int num_planes)
>> +{
>> +    struct drm_framebuffer *fb;
>> +    int ret, i;
>> +
>> +    fb = kzalloc(sizeof(*fb), GFP_KERNEL);
>> +    if (!fb)
>> +    return ERR_PTR(-ENOMEM);
>> +
>> +    drm_helper_mode_fill_fb_struct(dev, fb, mode_cmd);
>> +
>> +    for (i = 0; i < num_planes; i++)
>> +    fb->obj[i] = [i]->base;
>> +
>> +    ret = drm_framebuffer_init(dev, fb, _fb_funcs);
>> +    if (ret) {
>> +    dev_err(dev->dev, "Failed to initialize framebuffer: %d\n",
>> +    ret);
>> +    kfree(fb);
>> +    return ERR_PTR(ret);
>> +    }
>> +
>> +    return fb;
>> +}
>> +
>> +static struct drm_framebuffer *vs_fb_create(struct drm_device *dev,
>> +    struct drm_file *file_priv,
>> +    const struct drm_mode_fb_cmd2 *mode_cmd)
>> +{
>> +    struct drm_framebuffer *fb;
>> +    const struct drm_format_info *info;
>> +    struct vs_gem_object *objs[MAX_NUM_PLANES];
>> +    struct drm_gem_object *obj;
>> +    unsigned int height, size;
>> +    unsigned char i, num_planes;
>> +    int ret = 0;
>> +
>> +    info = drm_get_format_info(dev, mode_cmd);
>> +    if (!info)
>> +    return ERR_PTR(-EINVAL);
>> +
>> +    num_planes = info->num_planes;
>> +    if (num_planes > MAX_NUM_PLANES)
>> +    return ERR_PTR(-EINVAL);
>> +
>> +    for (i = 

Re: [PATCH 4/9] drm/verisilicon: Add gem driver for JH7110 SoC

2023-07-20 Thread Keith Zhao



On 2023/6/19 21:18, Thomas Zimmermann wrote:
> 
> 
> Am 02.06.23 um 09:40 schrieb Keith Zhao:
>> This patch implements gem related APIs for JH7100 SoC.
>>
>> Signed-off-by: Keith Zhao 
>> ---
>>   drivers/gpu/drm/verisilicon/Makefile |   3 +-
>>   drivers/gpu/drm/verisilicon/vs_drv.c |   6 +
>>   drivers/gpu/drm/verisilicon/vs_gem.c | 372 +++
>>   drivers/gpu/drm/verisilicon/vs_gem.h |  72 ++
>>   4 files changed, 452 insertions(+), 1 deletion(-)
>>   create mode 100644 drivers/gpu/drm/verisilicon/vs_gem.c
>>   create mode 100644 drivers/gpu/drm/verisilicon/vs_gem.h
>>
>> diff --git a/drivers/gpu/drm/verisilicon/Makefile 
>> b/drivers/gpu/drm/verisilicon/Makefile
>> index 64ce1b26546c..30360e370e47 100644
>> --- a/drivers/gpu/drm/verisilicon/Makefile
>> +++ b/drivers/gpu/drm/verisilicon/Makefile
>> @@ -1,6 +1,7 @@
>>   # SPDX-License-Identifier: GPL-2.0
>>   -vs_drm-objs := vs_drv.o
>> +vs_drm-objs := vs_drv.o \
>> +    vs_gem.o
>>     obj-$(CONFIG_DRM_VERISILICON) += vs_drm.o
>>   diff --git a/drivers/gpu/drm/verisilicon/vs_drv.c 
>> b/drivers/gpu/drm/verisilicon/vs_drv.c
>> index 24d333598477..e0a2fc43b55f 100644
>> --- a/drivers/gpu/drm/verisilicon/vs_drv.c
>> +++ b/drivers/gpu/drm/verisilicon/vs_drv.c
>> @@ -30,6 +30,7 @@
>>   #include 
>>     #include "vs_drv.h"
>> +#include "vs_gem.h"
>>     #define DRV_NAME    "starfive"
>>   #define DRV_DESC    "Starfive DRM driver"
>> @@ -47,6 +48,7 @@ static const struct file_operations fops = {
>>   .compat_ioctl    = drm_compat_ioctl,
>>   .poll    = drm_poll,
>>   .read    = drm_read,
>> +    .mmap    = vs_gem_mmap,
>>   };
>>     static struct drm_driver vs_drm_driver = {
>> @@ -54,6 +56,10 @@ static struct drm_driver vs_drm_driver = {
>>   .lastclose    = drm_fb_helper_lastclose,
>>   .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
>>   .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
>> +    .gem_prime_import    = vs_gem_prime_import,
>> +    .gem_prime_import_sg_table = vs_gem_prime_import_sg_table,
>> +    .gem_prime_mmap    = vs_gem_prime_mmap,
>> +    .dumb_create    = vs_gem_dumb_create,
>>   .fops    = ,
>>   .name    = DRV_NAME,
>>   .desc    = DRV_DESC,
>> diff --git a/drivers/gpu/drm/verisilicon/vs_gem.c 
>> b/drivers/gpu/drm/verisilicon/vs_gem.c
>> new file mode 100644
>> index ..3f963471c1ab
>> --- /dev/null
>> +++ b/drivers/gpu/drm/verisilicon/vs_gem.c
>> @@ -0,0 +1,372 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +/*
>> + * Copyright (C) 2023 VeriSilicon Holdings Co., Ltd.
>> + */
>> +
>> +#include 
>> +#include 
>> +#include 
>> +
>> +#include "vs_drv.h"
>> +#include "vs_gem.h"
>> +
>> +static const struct drm_gem_object_funcs vs_gem_default_funcs;
>> +
>> +static int vs_gem_alloc_buf(struct vs_gem_object *vs_obj)
>> +{
>> +    struct drm_device *dev = vs_obj->base.dev;
>> +    unsigned int nr_pages;
>> +    struct sg_table sgt;
>> +    int ret = -ENOMEM;
>> +
>> +    if (vs_obj->dma_addr) {
>> +    DRM_DEV_DEBUG_KMS(dev->dev, "already allocated.\n");
>> +    return 0;
>> +    }
>> +
>> +    vs_obj->dma_attrs = DMA_ATTR_WRITE_COMBINE | DMA_ATTR_FORCE_CONTIGUOUS
>> +   | DMA_ATTR_NO_KERNEL_MAPPING;
>> +
>> +    nr_pages = vs_obj->size >> PAGE_SHIFT;
>> +
>> +    vs_obj->pages = kvmalloc_array(nr_pages, sizeof(struct page *),
>> +   GFP_KERNEL | __GFP_ZERO);
>> +    if (!vs_obj->pages) {
>> +    DRM_DEV_ERROR(dev->dev, "failed to allocate pages.\n");
>> +    return -ENOMEM;
>> +    }
>> +
>> +    vs_obj->cookie = dma_alloc_attrs(to_dma_dev(dev), vs_obj->size,
>> + _obj->dma_addr, GFP_KERNEL,
>> + vs_obj->dma_attrs);
>> +
>> +    if (!vs_obj->cookie) {
>> +    DRM_DEV_ERROR(dev->dev, "failed to allocate buffer.\n");
>> +    goto err_free;
>> +    }
>> +
>> +    vs_obj->iova = vs_obj->dma_addr;
>> +
>> +    ret = dma_get_sgtable_attrs(to_dma_dev(dev), ,
>> +    vs_obj->cookie, vs_obj->dma_addr,
>> +    vs_obj->size, vs_obj->dma_attrs);
>> +    if (ret &l

Re: [PATCH 7/9] drm/verisilicon: Add drm plane funcs

2023-07-10 Thread Keith Zhao



On 2023/7/11 0:46, Shengyu Qu wrote:
> Hello Keith,
>> +
>> +static void vs_plane_atomic_update(struct drm_plane *plane,
>> +   struct drm_atomic_state *state)
>> +{
>> +    struct drm_plane_state *new_state = 
>> drm_atomic_get_new_plane_state(state,
>> +   plane);
>> +    unsigned char i, num_planes;
>> +    struct drm_framebuffer *fb;
>> +    struct vs_plane *vs_plane = to_vs_plane(plane);
>> +    //struct drm_plane_state *state = plane->state;
>> +    struct vs_crtc *vs_crtc = to_vs_crtc(new_state->crtc);
>> +    struct vs_plane_state *plane_state = to_vs_plane_state(new_state);
>> +    //struct drm_format_name_buf *name = _state->status.format_name;
>> +
>> +    if (!new_state->fb || !new_state->crtc)
>> +    return;
>> +
>> +    fb = new_state->fb;
>> +
>> +    num_planes = vs_get_plane_number(fb);
>> +
>> +    for (i = 0; i < num_planes; i++) {
>> +    struct vs_gem_object *vs_obj;
>> +
>> +    vs_obj = vs_fb_get_gem_obj(fb, i);
>> +    vs_plane->dma_addr[i] = vs_obj->iova + fb->offsets[i];
> 
> There is a dcache flush operation here in downstream driver. Is that a cache 
> coherence problem?
> 
> Best regards,
> 
> Shengyu
> 
>> +    }
>> +
>> +    plane_state->status.src = drm_plane_state_src(new_state);
>> +    plane_state->status.dest = drm_plane_state_dest(new_state);
>> +
>> +    vs_plane->funcs->update(vs_crtc->dev, vs_plane, plane, state);
>> +}
>>yes , You can find that the current situation is very professional. 
This problem exists at present, but the dma interface is not perfect at now, 
and the dma_sync_single_for_device interface needs to be implemented later. 
I will consider repairing this problem in the form of patch


Re: [PATCH 3/9] drm/verisilicon: Add basic drm driver

2023-07-04 Thread Keith Zhao



On 2023/7/4 2:42, Shengyu Qu wrote:
> Hello Keith,
> 
> While compiling this driver as a module, a error happens:
> 
> drivers/gpu/drm/verisilicon/vs_drm: struct of_device_id is 200 bytes.  The 
> last of 1 is:
> 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 
> 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 
> 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 
> 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 
> 0x00 0x00 0x00 0x00 0x76 0x65 0x72 0x69 0x73 0x69 0x6c 0x69 0x63 0x6f 0x6e 
> 0x2c 0x64 0x69 0x73 0x70 0x6c 0x61 0x79 0x2d 0x73 0x75 0x62 0x73 0x79 0x73 
> 0x74 0x65 0x6d 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 
> 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 
> 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 
> 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 
> 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 
> 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 
> 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 
> 0x00 0x00 0x00
> 0x00 0x00
> FATAL: modpost: drivers/gpu/drm/verisilicon/vs_drm: struct of_device_id is 
> not terminated with a NULL entry!
> 
>> +
>> +static const struct of_device_id vs_drm_dt_ids[] = {
>> +    { .compatible = "verisilicon,display-subsystem", },
>> +};
>> +
> 
> So, this should be:
> 
> static const struct of_device_id vs_drm_dt_ids[] = {
> { .compatible = "verisilicon,display-subsystem", },
> { },
> };
> 
> After fixing this problem, another error happens:
> 
> ERROR: modpost: module vs_drm uses symbol dma_buf_mmap from namespace 
> DMA_BUF, but does not import it.
> 
> Please fix.
> 
> Best regards,
> Shengyu

hello Shengyu , 

I can reproduce the error generated by compiling ko , and add 
MODULE_IMPORT_NS(DMA_BUF) at the beginning of vs_gem.c ,
it can fix the error message, 
I will add this in my next patch , thanks


Re: [PATCH 9/9] drm/verisilicon: Add starfive hdmi driver

2023-06-26 Thread Keith Zhao
yes I tested 
modetest -M starfive -D 0 -s 116@31:1280x720-59.94 -v
modetest -M starfive -D 0 -s 116@31:1920x1080 -v

and the second command will repeat the problem
as you advise at the beginning
I call the "starfive_hdmi_setup"  function in the "starfive_hdmi_encoder_enable"
instead of "starfive_hdmi_encoder_mode_set"
resolve the problem
i will add this modify in my next patch

Thank you Hoegeun

On 2023/6/23 10:38, Hoegeun Kwon wrote:
> Hi Keith,
> 
> There is a problem with stopping when changing modes.
> 
> Below test log
> 
> root:~> modetest -Mstarfive -c
> Connectors:
> id  encoder status  namesize (mm)   modes
> encoders
> 116 115 connected   HDMI-A-1320x180 51  115
>   modes:
> index name refresh (Hz) hdisp hss hse htot vdisp vss vse vtot
>   #0 1280x800 59.91 1280 1328 1360 1440 800 803 809 823 71000 flags: phsync,
> pvsync; type: preferred, driver
>   #1 1920x1080 60.00 1920 2008 2052 2200 1080 1084 1089 1125 148500 flags:
> phsync, pvsync; type: driver
> [...]
> 
> root:~> modetest -Mstarfive -s 116:#0 -v
> setting mode 1280x800-59.91Hz on connectors 116, crtc 31
> freq: 60.65Hz
> freq: 59.91Hz
> freq: 59.91Hz
> 
> root:~> modetest -Mstarfive -s 116:#1 -v
> setting mode 1920x1080-60.00Hz on connectors 116, crtc 31
> [   94.535626] rcu: INFO: rcu_sched detected stalls on CPUs/tasks:
> [   94.560985] rcu: 1-...0: (20 ticks this GP)
> idle=c9bc/1/0x4000 softirq=3869/3871 fqs=1120
> [   94.589532] rcu: (detected by 3, t=5264 jiffies, g=4645, q=63
> ncpus=4)
> [   94.615335] Task dump for CPU 1:
> [   94.637723] task:modeteststate:R  running task stack:0
> pid:407   ppid:397flags:0x0008
> [   94.667299] Call Trace:
> [   94.689297] [] __schedule+0x2a8/0xa52
> [   94.714221] [] schedule+0x5a/0xdc
> [   94.738626] [] schedule_timeout+0x220/0x2a6
> [   94.763762] [] wait_for_completion+0xfe/0x126
> [   94.789073] [] kthread_flush_worker+0x82/0xa0
> 
> 
>> -Original Message-
>> From: dri-devel  On Behalf Of
>> Keith Zhao
>> Sent: Friday, June 2, 2023 4:41 PM
>> To: dri-devel@lists.freedesktop.org; devicet...@vger.kernel.org; linux-
>> ker...@vger.kernel.org; linux-ri...@lists.infradead.org; linux-
>> me...@vger.kernel.org; linaro-mm-...@lists.linaro.org
>> Cc: Krzysztof Kozlowski ; Sumit Semwal
>> ; Emil Renner Berthing ;
>> Shengyang Chen ; Conor Dooley
>> ; Albert Ou ; Thomas
>> Zimmermann ; Jagan Teki ; Rob
>> Herring ; Chris Morgan ; Paul
>> Walmsley ; Keith Zhao
>> ; Bjorn Andersson ;
>> Changhuang Liang ; Jack Zhu
>> ; Palmer Dabbelt ; Shawn
>> Guo ; christian.koe...@amd.com
>> Subject: [PATCH 9/9] drm/verisilicon: Add starfive hdmi driver
>> 
>> Add HDMI dirver for StarFive SoC JH7110.
>> 
>> Signed-off-by: Keith Zhao 
>> ---
>>  drivers/gpu/drm/verisilicon/Kconfig |  11 +
>>  drivers/gpu/drm/verisilicon/Makefile|   1 +
>>  drivers/gpu/drm/verisilicon/starfive_hdmi.c | 928 
>> drivers/gpu/drm/verisilicon/starfive_hdmi.h | 296 +++
>>  drivers/gpu/drm/verisilicon/vs_drv.c|   6 +
>>  drivers/gpu/drm/verisilicon/vs_drv.h|   4 +
>>  6 files changed, 1246 insertions(+)
>>  create mode 100644 drivers/gpu/drm/verisilicon/starfive_hdmi.c
>>  create mode 100644 drivers/gpu/drm/verisilicon/starfive_hdmi.h
> 
> [...]
> 
>> diff --git a/drivers/gpu/drm/verisilicon/starfive_hdmi.c
>> b/drivers/gpu/drm/verisilicon/starfive_hdmi.c
>> new file mode 100644
>> index ..128ecca03309
>> --- /dev/null
>> +++ b/drivers/gpu/drm/verisilicon/starfive_hdmi.c
>> @@ -0,0 +1,928 @@
> 
> [...]
> 
>> +static int starfive_hdmi_setup(struct starfive_hdmi *hdmi,
>> +   struct drm_display_mode *mode) {
> 
> [...]
> 
>> +return 0;
>> +}
>> +
>> +static void starfive_hdmi_encoder_mode_set(struct drm_encoder *encoder,
>> +   struct drm_display_mode *mode,
>> +   struct drm_display_mode
> *adj_mode) {
>> +struct starfive_hdmi *hdmi = encoder_to_hdmi(encoder);
>> +
>> +starfive_hdmi_setup(hdmi, adj_mode);
> 
> When starfive_hdmi_setup runs here,
> when changing the mode, a problem occurs because try to write a value to reg
> in a state that is not resumed after suspend.
> 
>> +
>> +memcpy(>previous_mode, adj_mode, sizeof(hdmi-
>> >previous_mode)); }
>> +
>> +static void starfive_hdmi_encoder_enable(struct drm_encoder *encoder) {
>> +struct starfive_hdmi *hdmi = encoder_to_hdmi(encoder);
>> +
>> +pm_runtime_get_sync(hdmi->dev);
> 
> So if move the call point of starfive_hdmi_setup here, it works normally.
> 
>> +}
> 
> Best regards,
> Hoegeun
> 
> 


Re: [PATCH 1/9] dt-bindings: display: Add yamls for JH7110 display subsystem

2023-06-07 Thread Keith Zhao



On 2023/6/7 14:41, Maxime Ripard wrote:
> On Tue, Jun 06, 2023 at 11:37:53PM +0100, Conor Dooley wrote:
>> On Wed, Jun 07, 2023 at 12:22:33AM +0200, Heiko Stübner wrote:
>> > Am Dienstag, 6. Juni 2023, 20:41:17 CEST schrieb Shengyu Qu:
>> > > > On Fri, Jun 02, 2023 at 03:40:35PM +0800, Keith Zhao wrote:
>> > > >> Add bindings for JH7110 display subsystem which
>> > > >> has a display controller verisilicon dc8200
>> > > >> and an HDMI interface.
>> 
>> > > >> +description:
>> > > >> +  The StarFive SoC uses the HDMI signal transmiter based on 
>> > > >> innosilicon IP
>> > > > Is innosilicon the same thing as verisilicon? Also
>> > > > s/transmiter/transmitter/, both here and in the title.
yes,innosilicon is the HDMI IP  and verisilicon is the DC-controller IP

>> > > 
>> > > I think that is not the same, I remember Rockchip has used a HDMI 
>> > > transmitter from
>> > > 
>> > > Innosilicon, and there is a existing driver for that in mainline.
>> > 
>> > Yep, I think Innosilicon is the company you turn to when you want to save
>> > a bit of money ;-) . In the bigger SoCs Rockchip most of the time uses
>> > Designware hdmi blocks and looking at the history only the rk3036 ever
>> > used an Innosilicon block.
>> > 
I have done a HDMIcomparison of the rk3036 and the jh7110, and they are both 
based on ip Innosilicon.

the hardware of them .
Some parts of the hardware of the two are common, such as the logic of hdmi I2C 
to obtain edid, and the register definition is consistent.

Many registers are defined differently from the linux main line inno driver, 
including registers that contain specific bits
and some registers in linux main line inno driver no longer used in my new inoo 
hdmi hardware.

>> > Looking at the history, 2016 really was a long time ago :-D.
>> > 
>> > > So Keith, if that's true, I think it is better to seperate the HDMI 
>> > > stuff and reuse existing driver.
>> > 
>> > I'm not so sure about that - at least from a cursory glance :-) .
>> > 
>> > The registers do look slightly different and I don't know how much
>> > the IP changed between the rk3036-version and the jh7110 version.
>> > 
>> > At the very least, I know my rk3036 board isn't booting right now, so
>> > I can't really provide help for generalizing the rockchip-driver.
>> > 
>> > At the very least both the binding and driver could drop the 
>> > "starfive-hdmi"
>> > and actually use the Innosilicon in the naming somewhere, so that it's
>> > clear for future developers :-)
>> 
>> Seeing "based on" always makes me a little bit nervous to be honest when
>> it comes to using a compatible from the IP. Is it the IP? What version
>> is it? etc. Perhaps "starfive,jh7110-hdmi" & falling back to some sort
>> of "innosilicon,hdmi" would be more future/IP-silliness proof.
>> Driver can always be generic & bind against "innosilicon,hdmi" until
>> that becomes impossible.
> 
> Given that Neil was saying that there's at least two
> generations/revisions/models of an HDMI controller from Innosilicon, I'm
> not sure that compatible is enough to reach that goal anyway.
> 
> Maxime



I will change the  the binding  to meet innosilicon,hdmi .
for the drivers part , I will study the possibility of RK-HDMI reuse.

Thank you for your comments

















[PATCH 2/9] riscv: dts: starfive: jh7110: add dc controller node

2023-06-02 Thread Keith Zhao
Add the dc controller and hdmi node for the Starfive JH7110 SoC.

Signed-off-by: Keith Zhao 
---
 .../jh7110-starfive-visionfive-2.dtsi | 87 +++
 arch/riscv/boot/dts/starfive/jh7110.dtsi  | 46 ++
 2 files changed, 133 insertions(+)

diff --git a/arch/riscv/boot/dts/starfive/jh7110-starfive-visionfive-2.dtsi 
b/arch/riscv/boot/dts/starfive/jh7110-starfive-visionfive-2.dtsi
index 1155b97b593d..8dc6c8a15c59 100644
--- a/arch/riscv/boot/dts/starfive/jh7110-starfive-visionfive-2.dtsi
+++ b/arch/riscv/boot/dts/starfive/jh7110-starfive-visionfive-2.dtsi
@@ -31,6 +31,21 @@ memory@4000 {
reg = <0x0 0x4000 0x1 0x0>;
};
 
+   reserved-memory {
+   #address-cells = <2>;
+   #size-cells = <2>;
+   ranges;
+
+   linux,cma {
+   compatible = "shared-dma-pool";
+   reusable;
+   size = <0x0 0x2000>;
+   alignment = <0x0 0x1000>;
+   alloc-ranges = <0x0 0x8000 0x0 0x2000>;
+   linux,cma-default;
+   };
+   };
+
gpio-restart {
compatible = "gpio-restart";
gpios = < 35 GPIO_ACTIVE_HIGH>;
@@ -214,6 +229,41 @@ GPOEN_DISABLE,
slew-rate = <0>;
};
};
+
+   hdmi_pins: hdmi-0 {
+   hdmi-scl-pins {
+   pinmux = ;
+   input-enable;
+   bias-pull-up;
+   };
+
+   hdmi-sda-pins {
+   pinmux = ;
+   input-enable;
+   bias-pull-up;
+   };
+
+   hdmi-cec-pins {
+   pinmux = ;
+   input-enable;
+   bias-pull-up;
+   };
+
+   hdmi-hpd-pins {
+   pinmux = ;
+   input-enable;
+   bias-disable; /* external pull-up */
+   };
+   };
+
 };
 
  {
@@ -221,3 +271,40 @@  {
pinctrl-0 = <_pins>;
status = "okay";
 };
+
+ {
+   status = "okay";
+};
+
+ {
+   status = "okay";
+};
+
+ {
+   status = "okay";
+   pinctrl-names = "default";
+   pinctrl-0 = <_pins>;
+
+   hdmi_in: port {
+   #address-cells = <1>;
+   #size-cells = <0>;
+   hdmi_input: endpoint@0 {
+   reg = <0>;
+   remote-endpoint = <_out_dpi0>;
+   };
+   };
+};
+
+ {
+   status = "okay";
+
+   dc_out: port {
+   #address-cells = <1>;
+   #size-cells = <0>;
+   dc_out_dpi0: endpoint@0 {
+   reg = <0>;
+   remote-endpoint = <_input>;
+   };
+
+   };
+};
diff --git a/arch/riscv/boot/dts/starfive/jh7110.dtsi 
b/arch/riscv/boot/dts/starfive/jh7110.dtsi
index 9acb5fb1716d..66be6e65a066 100644
--- a/arch/riscv/boot/dts/starfive/jh7110.dtsi
+++ b/arch/riscv/boot/dts/starfive/jh7110.dtsi
@@ -249,6 +249,11 @@ tdm_ext: tdm-ext-clock {
#clock-cells = <0>;
};
 
+   display: display-subsystem {
+   compatible = "verisilicon,display-subsystem";
+   ports = <_out>;
+   };
+
soc {
compatible = "simple-bus";
interrupt-parent = <>;
@@ -570,5 +575,46 @@ voutcrg: clock-controller@295c {
#reset-cells = <1>;
power-domains = < JH7110_PD_VOUT>;
};
+
+   dc8200: dc8200@2940 {
+   compatible = "verisilicon,dc8200";
+   reg = <0x0 0x2940 0x0 0x100>,
+ <0x0 0x29400800 0x0 0x2000>,
+ <0x0 0x295B 0x0 0x90>;
+   interrupts = <95>;
+   clocks = < JH7110_SYSCLK_NOC_BUS_DISP_AXI>,
+   < JH7110_VOUTCLK_DC8200_PIX0>,
+   < JH7110_VOUTCLK_DC8200_PIX1>,
+   < JH7110_VOUTCLK_DC8200_AXI>,
+   < JH7110_VOUTCLK_DC8200_CORE>,
+   < JH7110_VOUTCLK_DC8200_AHB>,
+   <_pixelclk>,
+   < JH7110_VOUTCLK_DC8200_PIX>;
+   clock-names = "clk_vout_noc_disp",
+   "clk_vout_pix0","clk_vout_pix1",
+

[PATCH 8/9] drm/verisilicon: Add verisilicon dc controller driver

2023-06-02 Thread Keith Zhao
Add DC8200 display controller driver for StarFive JH7110 SoC.

Signed-off-by: Keith Zhao 
---
 drivers/gpu/drm/verisilicon/Makefile   |4 +-
 drivers/gpu/drm/verisilicon/vs_dc.c| 1040 
 drivers/gpu/drm/verisilicon/vs_dc.h|   62 +
 drivers/gpu/drm/verisilicon/vs_dc_hw.c | 2008 
 drivers/gpu/drm/verisilicon/vs_dc_hw.h |  496 ++
 drivers/gpu/drm/verisilicon/vs_drv.c   |2 +
 6 files changed, 3611 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/verisilicon/vs_dc.c
 create mode 100644 drivers/gpu/drm/verisilicon/vs_dc.h
 create mode 100644 drivers/gpu/drm/verisilicon/vs_dc_hw.c
 create mode 100644 drivers/gpu/drm/verisilicon/vs_dc_hw.h

diff --git a/drivers/gpu/drm/verisilicon/Makefile 
b/drivers/gpu/drm/verisilicon/Makefile
index d96ad9399fc7..0ed25b5e3062 100644
--- a/drivers/gpu/drm/verisilicon/Makefile
+++ b/drivers/gpu/drm/verisilicon/Makefile
@@ -1,7 +1,9 @@
 # SPDX-License-Identifier: GPL-2.0
 
-vs_drm-objs := vs_drv.o \
+vs_drm-objs := vs_dc_hw.o \
+   vs_dc.o \
vs_crtc.o \
+   vs_drv.o \
vs_fb.o \
vs_gem.o \
vs_plane.o
diff --git a/drivers/gpu/drm/verisilicon/vs_dc.c 
b/drivers/gpu/drm/verisilicon/vs_dc.c
new file mode 100644
index ..a512aaa57f2f
--- /dev/null
+++ b/drivers/gpu/drm/verisilicon/vs_dc.c
@@ -0,0 +1,1040 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2023 VeriSilicon Holdings Co., Ltd.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "vs_crtc.h"
+#include "vs_dc_hw.h"
+#include "vs_dc.h"
+#include "vs_drv.h"
+#include "vs_type.h"
+
+static const char * const vout_clocks[] = {
+   "clk_vout_noc_disp",
+   "clk_vout_pix0",
+   "clk_vout_pix1",
+   "clk_vout_axi",
+   "clk_vout_core",
+   "clk_vout_vout_ahb",
+   "hdmitx0_pixel",
+   "clk_vout_dc8200",
+
+};
+
+static const char * const vout_resets[] = {
+   "rst_vout_axi",
+   "rst_vout_ahb",
+   "rst_vout_core",
+};
+
+static inline void update_format(u32 format, u64 mod, struct dc_hw_fb *fb)
+{
+   u8 f = FORMAT_A8R8G8B8;
+
+   switch (format) {
+   case DRM_FORMAT_XRGB:
+   case DRM_FORMAT_RGBX:
+   case DRM_FORMAT_XBGR:
+   case DRM_FORMAT_BGRX:
+   f = FORMAT_X4R4G4B4;
+   break;
+   case DRM_FORMAT_ARGB:
+   case DRM_FORMAT_RGBA:
+   case DRM_FORMAT_ABGR:
+   case DRM_FORMAT_BGRA:
+   f = FORMAT_A4R4G4B4;
+   break;
+   case DRM_FORMAT_XRGB1555:
+   case DRM_FORMAT_RGBX5551:
+   case DRM_FORMAT_XBGR1555:
+   case DRM_FORMAT_BGRX5551:
+   f = FORMAT_X1R5G5B5;
+   break;
+   case DRM_FORMAT_ARGB1555:
+   case DRM_FORMAT_RGBA5551:
+   case DRM_FORMAT_ABGR1555:
+   case DRM_FORMAT_BGRA5551:
+   f = FORMAT_A1R5G5B5;
+   break;
+   case DRM_FORMAT_RGB565:
+   case DRM_FORMAT_BGR565:
+   f = FORMAT_R5G6B5;
+   break;
+   case DRM_FORMAT_XRGB:
+   case DRM_FORMAT_RGBX:
+   case DRM_FORMAT_XBGR:
+   case DRM_FORMAT_BGRX:
+   f = FORMAT_X8R8G8B8;
+   break;
+   case DRM_FORMAT_ARGB:
+   case DRM_FORMAT_RGBA:
+   case DRM_FORMAT_ABGR:
+   case DRM_FORMAT_BGRA:
+   f = FORMAT_A8R8G8B8;
+   break;
+   case DRM_FORMAT_YUYV:
+   case DRM_FORMAT_YVYU:
+   f = FORMAT_YUY2;
+   break;
+   case DRM_FORMAT_UYVY:
+   case DRM_FORMAT_VYUY:
+   f = FORMAT_UYVY;
+   break;
+   case DRM_FORMAT_YUV420:
+   case DRM_FORMAT_YVU420:
+   f = FORMAT_YV12;
+   break;
+   case DRM_FORMAT_NV21:
+   f = FORMAT_NV12;
+   break;
+   case DRM_FORMAT_NV16:
+   case DRM_FORMAT_NV61:
+   f = FORMAT_NV16;
+   break;
+   case DRM_FORMAT_P010:
+   f = FORMAT_P010;
+   break;
+   case DRM_FORMAT_ARGB2101010:
+   case DRM_FORMAT_RGBA1010102:
+   case DRM_FORMAT_ABGR2101010:
+   case DRM_FORMAT_BGRA1010102:
+   f = FORMAT_A2R10G10B10;
+   break;
+   case DRM_FORMAT_NV12:
+   if (fourcc_mod_vs_get_type(mod) ==
+   DRM_FORMAT_MOD_VS_TYPE_CUSTOM_10BIT)
+   f = FORMAT_NV12_10BIT;
+   else
+   f = FORMAT_NV12;
+   break;
+   case DRM_FORMAT_YUV444:
+   if (f

[PATCH 9/9] drm/verisilicon: Add starfive hdmi driver

2023-06-02 Thread Keith Zhao
Add HDMI dirver for StarFive SoC JH7110.

Signed-off-by: Keith Zhao 
---
 drivers/gpu/drm/verisilicon/Kconfig |  11 +
 drivers/gpu/drm/verisilicon/Makefile|   1 +
 drivers/gpu/drm/verisilicon/starfive_hdmi.c | 928 
 drivers/gpu/drm/verisilicon/starfive_hdmi.h | 296 +++
 drivers/gpu/drm/verisilicon/vs_drv.c|   6 +
 drivers/gpu/drm/verisilicon/vs_drv.h|   4 +
 6 files changed, 1246 insertions(+)
 create mode 100644 drivers/gpu/drm/verisilicon/starfive_hdmi.c
 create mode 100644 drivers/gpu/drm/verisilicon/starfive_hdmi.h

diff --git a/drivers/gpu/drm/verisilicon/Kconfig 
b/drivers/gpu/drm/verisilicon/Kconfig
index 89d12185f73b..35e85ac41b10 100644
--- a/drivers/gpu/drm/verisilicon/Kconfig
+++ b/drivers/gpu/drm/verisilicon/Kconfig
@@ -11,3 +11,14 @@ config DRM_VERISILICON
  This driver provides VeriSilicon kernel mode
  setting and buffer management. It does not
  provide 2D or 3D acceleration.
+
+config STARFIVE_HDMI
+   bool "Starfive specific extensions HDMI"
+   help
+  This selects support for StarFive SoC specific extensions
+  for the Innosilicon HDMI driver. If you want to enable
+  HDMI on JH7110 based SoC, you should select this option.
+
+  To compile this driver as a module, choose M here.
+
+
diff --git a/drivers/gpu/drm/verisilicon/Makefile 
b/drivers/gpu/drm/verisilicon/Makefile
index 0ed25b5e3062..ebe2c94f529a 100644
--- a/drivers/gpu/drm/verisilicon/Makefile
+++ b/drivers/gpu/drm/verisilicon/Makefile
@@ -8,5 +8,6 @@ vs_drm-objs := vs_dc_hw.o \
vs_gem.o \
vs_plane.o
 
+vs_drm-$(CONFIG_STARFIVE_HDMI) += starfive_hdmi.o
 obj-$(CONFIG_DRM_VERISILICON) += vs_drm.o
 
diff --git a/drivers/gpu/drm/verisilicon/starfive_hdmi.c 
b/drivers/gpu/drm/verisilicon/starfive_hdmi.c
new file mode 100644
index ..128ecca03309
--- /dev/null
+++ b/drivers/gpu/drm/verisilicon/starfive_hdmi.c
@@ -0,0 +1,928 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2023 StarFive Technology Co., Ltd.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "starfive_hdmi.h"
+#include "vs_drv.h"
+
+static struct starfive_hdmi *encoder_to_hdmi(struct drm_encoder *encoder)
+{
+   return container_of(encoder, struct starfive_hdmi, encoder);
+}
+
+static struct starfive_hdmi *connector_to_hdmi(struct drm_connector *connector)
+{
+   return container_of(connector, struct starfive_hdmi, connector);
+}
+
+struct starfive_hdmi_i2c {
+   struct i2c_adapter adap;
+
+   u8 ddc_addr;
+   u8 segment_addr;
+   /* protects the edid data when use i2c cmd to read edid */
+   struct mutex lock;
+   struct completion cmp;
+};
+
+static const struct pre_pll_config pre_pll_cfg_table[] = {
+   { 25175000,  25175000, 1,  100, 2, 3, 3, 12, 3, 3, 4, 0, 0xf5},
+   { 2520,  2520, 1,  100, 2, 3, 3, 12, 3, 3, 4, 0, 0},
+   { 2700,  2700, 1,  90, 3, 2, 2, 10, 3, 3, 4, 0, 0},
+   { 27027000,  27027000, 1,  90, 3, 2, 2, 10, 3, 3, 4, 0, 0x170a3d},
+   { 2832,  2832, 1,  28, 2, 1, 1,  3, 0, 3, 4, 0, 0x51eb85},
+   { 3024,  3024, 1,  30, 2, 1, 1,  3, 0, 3, 4, 0, 0x3d70a3},
+   { 3150,  3150, 1,  31, 2, 1, 1,  3, 0, 3, 4, 0, 0x7f},
+   { 3375,  3375, 1,  33, 2, 1, 1,  3, 0, 3, 4, 0, 0xcf},
+   { 3600,  3600, 1,  36, 2, 1, 1,  3, 0, 3, 4, 0, 0},
+   { 4000,  4000, 1,  80, 2, 2, 2, 12, 2, 2, 2, 0, 0},
+   { 4697,  4697, 1,  46, 2, 1, 1,  3, 0, 3, 4, 0, 0xf851eb},
+   { 4950,  4950, 1,  49, 2, 1, 1,  3, 0, 3, 4, 0, 0x7f},
+   { 4900,  4900, 1,  49, 2, 1, 1,  3, 0, 3, 4, 0, 0},
+   { 5000,  5000, 1,  50, 2, 1, 1,  3, 0, 3, 4, 0, 0},
+   { 5400,  5400, 1,  54, 2, 1, 1,  3, 0, 3, 4, 0, 0},
+   { 54054000,  54054000, 1,  54, 2, 1, 1,  3, 0, 3, 4, 0, 0x0dd2f1},
+   { 57284000,  57284000, 1,  57, 2, 1, 1,  3, 0, 3, 4, 0, 0x48b439},
+   { 5823,  5823, 1,  58, 2, 1, 1,  3, 0, 3, 4, 0, 0x3ae147},
+   { 59341000,  59341000, 1,  59, 2, 1, 1,  3, 0, 3, 4, 0, 0x574bc6},
+   { 5940,  5940, 1,  99, 3, 1, 1,  1, 3, 3, 4, 0, 0},
+   { 6500,  6500, 1, 130, 2, 2, 2,  12, 0, 2, 2, 0, 0},
+   { 6825,  6825, 1, 68,  2, 1, 1,  3,  0, 3, 4, 0, 0x3f},
+   { 7100,  7100, 1,  71, 2, 1, 1,  3, 0, 3,  4, 0, 0},
+   { 74176000,  74176000, 1,  98, 1, 2, 2,  1, 2, 3, 4, 0, 0xe6ae6b},
+   { 7425,  7425, 1,  99, 1, 2, 2,  1, 2, 3, 4, 0, 0},
+   { 7500,  7500, 1,  75, 2, 1, 1,  3, 0, 3, 4, 0, 0},
+   { 7875,  7875, 1,  78, 2, 1, 1,  3, 0, 3, 4, 0, 0xcf},
+   { 7950,  7950, 1,  79, 2, 

[PATCH 5/9] drm/verisilicon: Add mode config funcs

2023-06-02 Thread Keith Zhao
Add mode setting functions for JH7110 SoC.

Signed-off-by: Keith Zhao 
---
 drivers/gpu/drm/verisilicon/Makefile |   1 +
 drivers/gpu/drm/verisilicon/vs_drv.c |   3 +
 drivers/gpu/drm/verisilicon/vs_fb.c  | 181 +++
 drivers/gpu/drm/verisilicon/vs_fb.h  |  15 +++
 4 files changed, 200 insertions(+)
 create mode 100644 drivers/gpu/drm/verisilicon/vs_fb.c
 create mode 100644 drivers/gpu/drm/verisilicon/vs_fb.h

diff --git a/drivers/gpu/drm/verisilicon/Makefile 
b/drivers/gpu/drm/verisilicon/Makefile
index 30360e370e47..38254dc5d98d 100644
--- a/drivers/gpu/drm/verisilicon/Makefile
+++ b/drivers/gpu/drm/verisilicon/Makefile
@@ -1,6 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0
 
 vs_drm-objs := vs_drv.o \
+   vs_fb.o \
vs_gem.o
 
 obj-$(CONFIG_DRM_VERISILICON) += vs_drm.o
diff --git a/drivers/gpu/drm/verisilicon/vs_drv.c 
b/drivers/gpu/drm/verisilicon/vs_drv.c
index e0a2fc43b55f..d84aacd751bc 100644
--- a/drivers/gpu/drm/verisilicon/vs_drv.c
+++ b/drivers/gpu/drm/verisilicon/vs_drv.c
@@ -30,6 +30,7 @@
 #include 
 
 #include "vs_drv.h"
+#include "vs_fb.h"
 #include "vs_gem.h"
 
 #define DRV_NAME   "starfive"
@@ -118,6 +119,8 @@ static int vs_drm_bind(struct device *dev)
if (ret)
goto err_mode;
 
+   vs_mode_config_init(drm_dev);
+
ret = drm_vblank_init(drm_dev, drm_dev->mode_config.num_crtc);
if (ret)
goto err_bind;
diff --git a/drivers/gpu/drm/verisilicon/vs_fb.c 
b/drivers/gpu/drm/verisilicon/vs_fb.c
new file mode 100644
index ..3e85f7365084
--- /dev/null
+++ b/drivers/gpu/drm/verisilicon/vs_fb.c
@@ -0,0 +1,181 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2023 VeriSilicon Holdings Co., Ltd.
+ */
+
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "vs_fb.h"
+#include "vs_gem.h"
+
+#define fourcc_mod_vs_get_type(val) \
+   (((val) & DRM_FORMAT_MOD_VS_TYPE_MASK) >> 54)
+
+static struct drm_framebuffer_funcs vs_fb_funcs = {
+   .create_handle  = drm_gem_fb_create_handle,
+   .destroy= drm_gem_fb_destroy,
+   .dirty  = drm_atomic_helper_dirtyfb,
+};
+
+static struct drm_framebuffer *
+vs_fb_alloc(struct drm_device *dev, const struct drm_mode_fb_cmd2 *mode_cmd,
+   struct vs_gem_object **obj, unsigned int num_planes)
+{
+   struct drm_framebuffer *fb;
+   int ret, i;
+
+   fb = kzalloc(sizeof(*fb), GFP_KERNEL);
+   if (!fb)
+   return ERR_PTR(-ENOMEM);
+
+   drm_helper_mode_fill_fb_struct(dev, fb, mode_cmd);
+
+   for (i = 0; i < num_planes; i++)
+   fb->obj[i] = [i]->base;
+
+   ret = drm_framebuffer_init(dev, fb, _fb_funcs);
+   if (ret) {
+   dev_err(dev->dev, "Failed to initialize framebuffer: %d\n",
+   ret);
+   kfree(fb);
+   return ERR_PTR(ret);
+   }
+
+   return fb;
+}
+
+static struct drm_framebuffer *vs_fb_create(struct drm_device *dev,
+   struct drm_file *file_priv,
+   const struct drm_mode_fb_cmd2 
*mode_cmd)
+{
+   struct drm_framebuffer *fb;
+   const struct drm_format_info *info;
+   struct vs_gem_object *objs[MAX_NUM_PLANES];
+   struct drm_gem_object *obj;
+   unsigned int height, size;
+   unsigned char i, num_planes;
+   int ret = 0;
+
+   info = drm_get_format_info(dev, mode_cmd);
+   if (!info)
+   return ERR_PTR(-EINVAL);
+
+   num_planes = info->num_planes;
+   if (num_planes > MAX_NUM_PLANES)
+   return ERR_PTR(-EINVAL);
+
+   for (i = 0; i < num_planes; i++) {
+   obj = drm_gem_object_lookup(file_priv, mode_cmd->handles[i]);
+   if (!obj) {
+   dev_err(dev->dev, "Failed to lookup GEM object.\n");
+   ret = -ENXIO;
+   goto err;
+   }
+
+   height = drm_format_info_plane_height(info,
+ mode_cmd->height, i);
+
+   size = height * mode_cmd->pitches[i] + mode_cmd->offsets[i];
+
+   if (obj->size < size) {
+   drm_gem_object_put(obj);
+
+   ret = -EINVAL;
+   goto err;
+   }
+
+   objs[i] = to_vs_gem_object(obj);
+   }
+
+   fb = vs_fb_alloc(dev, mode_cmd, objs, i);
+   if (IS_ERR(fb)) {
+   ret = PTR_ERR(fb);
+   goto err;
+   }
+
+   return fb;
+
+err:
+   for (; i > 0; i--)
+   drm_gem_object_put([i - 1]->base);
+
+   return ERR_PTR(ret);
+}
+
+struct vs_gem_object *vs_fb_get_gem_obj(struct drm_fra

[PATCH 1/9] dt-bindings: display: Add yamls for JH7110 display subsystem

2023-06-02 Thread Keith Zhao
Add bindings for JH7110 display subsystem which
has a display controller verisilicon dc8200
and an HDMI interface.

Signed-off-by: Keith Zhao 
---
 .../display/verisilicon/starfive-hdmi.yaml|  93 +++
 .../display/verisilicon/verisilicon-dc.yaml   | 110 ++
 .../display/verisilicon/verisilicon-drm.yaml  |  42 +++
 .../devicetree/bindings/vendor-prefixes.yaml  |   2 +
 MAINTAINERS   |   7 ++
 5 files changed, 254 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/display/verisilicon/starfive-hdmi.yaml
 create mode 100644 
Documentation/devicetree/bindings/display/verisilicon/verisilicon-dc.yaml
 create mode 100644 
Documentation/devicetree/bindings/display/verisilicon/verisilicon-drm.yaml

diff --git 
a/Documentation/devicetree/bindings/display/verisilicon/starfive-hdmi.yaml 
b/Documentation/devicetree/bindings/display/verisilicon/starfive-hdmi.yaml
new file mode 100644
index ..c30b7954a355
--- /dev/null
+++ b/Documentation/devicetree/bindings/display/verisilicon/starfive-hdmi.yaml
@@ -0,0 +1,93 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/display/verisilicon/starfive-hdmi.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: StarFive HDMI transmiter
+
+description:
+  The StarFive SoC uses the HDMI signal transmiter based on innosilicon IP
+  to generate HDMI signal from its input and transmit the signal to the screen.
+
+maintainers:
+  - Keith Zhao 
+  - ShengYang Chen 
+
+properties:
+  compatible:
+const: starfive,hdmi
+
+  reg:
+minItems: 1
+
+  interrupts:
+items:
+  - description: The HDMI hot plug detection interrupt.
+
+  clocks:
+items:
+  - description: System clock of HDMI module.
+  - description: Mclk clock of HDMI audio.
+  - description: Bclk clock of HDMI audio.
+  - description: Pixel clock generated by HDMI module.
+
+  clock-names:
+items:
+  - const: sysclk
+  - const: mclk
+  - const: bclk
+  - const: pclk
+
+  resets:
+items:
+  - description: Reset for HDMI module.
+
+  reset-names:
+items:
+  - const: hdmi_tx
+
+  '#sound-dai-cells':
+const: 0
+
+  port:
+$ref: /schemas/graph.yaml#/properties/port
+description:
+  Port node with one endpoint connected to a display connector node.
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - clocks
+  - clock-names
+  - resets
+  - reset-names
+  - '#sound-dai-cells'
+  - port
+
+additionalProperties: false
+
+examples:
+  - |
+hdmi: hdmi@2959 {
+  compatible = "starfive,hdmi";
+  reg = <0x2959 0x4000>;
+  interrupts = <99>;
+  clocks = < 17>,
+   < 15>,
+   < 16>,
+   <_pixelclk>;
+  clock-names = "sysclk", "mclk","bclk","pclk";
+  resets = < 9>;
+  reset-names = "hdmi_tx";
+  #sound-dai-cells = <0>;
+  hdmi_in: port {
+  #address-cells = <1>;
+  #size-cells = <0>;
+  hdmi_input: endpoint@0 {
+reg = <0>;
+remote-endpoint = <_out_dpi0>;
+  };
+  };
+};
diff --git 
a/Documentation/devicetree/bindings/display/verisilicon/verisilicon-dc.yaml 
b/Documentation/devicetree/bindings/display/verisilicon/verisilicon-dc.yaml
new file mode 100644
index ..1322502c4cde
--- /dev/null
+++ b/Documentation/devicetree/bindings/display/verisilicon/verisilicon-dc.yaml
@@ -0,0 +1,110 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/display/verisilicon/verisilicon-dc.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: StarFive display controller
+
+description:
+  The StarFive SoC uses the display controller based on Verisilicon IP
+  to transfer the image data from a video memory
+  buffer to an external LCD interface.
+
+maintainers:
+  - Keith Zhao 
+  - ShengYang Chen 
+
+properties:
+  compatible:
+const: verisilicon,dc8200
+
+  reg:
+maxItems: 3
+
+  interrupts:
+items:
+  - description: The interrupt will be generated when DC finish one frame
+
+  clocks:
+items:
+  - description: Clock for display system noc bus.
+  - description: Pixel clock for display channel 0.
+  - description: Pixel clock for display channel 1.
+  - description: Clock for axi interface of display controller.
+  - description: Core clock for display controller.
+  - description: Clock for ahb interface of display controller.
+  - description: External HDMI pixel clock.
+  - description: Parent clock for pixel clock
+
+  clock-names:
+items:
+  - const: clk_vout_noc_disp
+  - const: clk_vout_pix0
+  - const: clk_vout_pix1
+  - const: clk_vout_axi
+  - const: c

[PATCH 3/9] drm/verisilicon: Add basic drm driver

2023-06-02 Thread Keith Zhao
Add a basic platform driver of the DRM driver for JH7110 SoC.

Signed-off-by: Keith Zhao 
---
 MAINTAINERS  |   2 +
 drivers/gpu/drm/Kconfig  |   2 +
 drivers/gpu/drm/Makefile |   1 +
 drivers/gpu/drm/verisilicon/Kconfig  |  13 ++
 drivers/gpu/drm/verisilicon/Makefile |   6 +
 drivers/gpu/drm/verisilicon/vs_drv.c | 284 +++
 drivers/gpu/drm/verisilicon/vs_drv.h |  48 +
 include/uapi/drm/drm_fourcc.h|  83 
 include/uapi/drm/vs_drm.h|  50 +
 9 files changed, 489 insertions(+)
 create mode 100644 drivers/gpu/drm/verisilicon/Kconfig
 create mode 100644 drivers/gpu/drm/verisilicon/Makefile
 create mode 100644 drivers/gpu/drm/verisilicon/vs_drv.c
 create mode 100644 drivers/gpu/drm/verisilicon/vs_drv.h
 create mode 100644 include/uapi/drm/vs_drm.h

diff --git a/MAINTAINERS b/MAINTAINERS
index 293aa13d484c..da5b6766a7bb 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -7055,6 +7055,8 @@ L:dri-devel@lists.freedesktop.org
 S: Maintained
 T: git git://anongit.freedesktop.org/drm/drm-misc
 F: Documentation/devicetree/bindings/display/verisilicon/
+F: drivers/gpu/drm/verisilicon/
+F: include/uapi/drm/vs_drm.h
 
 DRM DRIVERS FOR VIVANTE GPU IP
 M: Lucas Stach 
diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig
index ba3fb04bb691..f7e461fa4656 100644
--- a/drivers/gpu/drm/Kconfig
+++ b/drivers/gpu/drm/Kconfig
@@ -371,6 +371,8 @@ source "drivers/gpu/drm/solomon/Kconfig"
 
 source "drivers/gpu/drm/sprd/Kconfig"
 
+source "drivers/gpu/drm/verisilicon/Kconfig"
+
 config DRM_HYPERV
tristate "DRM Support for Hyper-V synthetic video device"
depends on DRM && PCI && MMU && HYPERV
diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
index a33257d2bc7f..e50622ee4e46 100644
--- a/drivers/gpu/drm/Makefile
+++ b/drivers/gpu/drm/Makefile
@@ -194,3 +194,4 @@ obj-y   += gud/
 obj-$(CONFIG_DRM_HYPERV) += hyperv/
 obj-y  += solomon/
 obj-$(CONFIG_DRM_SPRD) += sprd/
+obj-$(CONFIG_DRM_VERISILICON) += verisilicon/
diff --git a/drivers/gpu/drm/verisilicon/Kconfig 
b/drivers/gpu/drm/verisilicon/Kconfig
new file mode 100644
index ..89d12185f73b
--- /dev/null
+++ b/drivers/gpu/drm/verisilicon/Kconfig
@@ -0,0 +1,13 @@
+# SPDX-License-Identifier: GPL-2.0
+
+config DRM_VERISILICON
+   tristate "DRM Support for VeriSilicon"
+   depends on DRM
+   select DRM_KMS_HELPER
+   select CMA
+   select DMA_CMA
+   help
+ Choose this option if you have a VeriSilicon soc chipset.
+ This driver provides VeriSilicon kernel mode
+ setting and buffer management. It does not
+ provide 2D or 3D acceleration.
diff --git a/drivers/gpu/drm/verisilicon/Makefile 
b/drivers/gpu/drm/verisilicon/Makefile
new file mode 100644
index ..64ce1b26546c
--- /dev/null
+++ b/drivers/gpu/drm/verisilicon/Makefile
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0
+
+vs_drm-objs := vs_drv.o
+
+obj-$(CONFIG_DRM_VERISILICON) += vs_drm.o
+
diff --git a/drivers/gpu/drm/verisilicon/vs_drv.c 
b/drivers/gpu/drm/verisilicon/vs_drv.c
new file mode 100644
index ..24d333598477
--- /dev/null
+++ b/drivers/gpu/drm/verisilicon/vs_drv.c
@@ -0,0 +1,284 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2023 VeriSilicon Holdings Co., Ltd.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "vs_drv.h"
+
+#define DRV_NAME   "starfive"
+#define DRV_DESC   "Starfive DRM driver"
+#define DRV_DATE   "202305161"
+#define DRV_MAJOR  1
+#define DRV_MINOR  0
+
+static struct platform_driver vs_drm_platform_driver;
+
+static const struct file_operations fops = {
+   .owner  = THIS_MODULE,
+   .open   = drm_open,
+   .release= drm_release,
+   .unlocked_ioctl = drm_ioctl,
+   .compat_ioctl   = drm_compat_ioctl,
+   .poll   = drm_poll,
+   .read   = drm_read,
+};
+
+static struct drm_driver vs_drm_driver = {
+   .driver_features= DRIVER_MODESET | DRIVER_ATOMIC | DRIVER_GEM,
+   .lastclose  = drm_fb_helper_lastclose,
+   .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
+   .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
+   .fops   = ,
+   .name   = DRV_NAME,
+   .desc   = DRV_DESC,
+   .date   = DRV_DATE,
+   .major  = DRV_MAJOR,
+   .minor  = DRV_MINOR,
+};
+
+void v

[PATCH 0/9] Add DRM driver for StarFive SoC JH7110

2023-06-02 Thread Keith Zhao
Hi,

This series is a DRM driver for StarFive SoC JH7110, which includes a
display controller driver for Verisilicon DC8200 and an HMDI driver.

We use GEM framework for buffer management and allocate memory by 
using DMA APIs.

The JH7110 display subsystem includes a display controller Verisilicon
DC8200 and an HDMI transmitter. The HDMI TX IP is designed for transmitting 
video and audio data from DC8200 to a display device. The HDMI TX IP 
consists of  the digital controller and the physical layer.

This series does not support HDMI audio driver.

Keith Zhao (9):
  dt-bindings: display: Add yamls for JH7110 display subsystem
  riscv: dts: starfive: jh7110: add dc controller node
  drm/verisilicon: Add basic drm driver
  drm/verisilicon: Add gem driver for JH7110 SoC
  drm/verisilicon: Add mode config funcs
  drm/verisilicon: Add drm crtc funcs
  drm/verisilicon: Add drm plane funcs
  drm/verisilicon: Add verisilicon dc controller driver
  drm/verisilicon: Add starfive hdmi driver

 .../display/verisilicon/starfive-hdmi.yaml|   93 +
 .../display/verisilicon/verisilicon-dc.yaml   |  110 +
 .../display/verisilicon/verisilicon-drm.yaml  |   42 +
 .../devicetree/bindings/vendor-prefixes.yaml  |2 +
 MAINTAINERS   |9 +
 .../jh7110-starfive-visionfive-2.dtsi |   87 +
 arch/riscv/boot/dts/starfive/jh7110.dtsi  |   46 +
 drivers/gpu/drm/Kconfig   |2 +
 drivers/gpu/drm/Makefile  |1 +
 drivers/gpu/drm/verisilicon/Kconfig   |   24 +
 drivers/gpu/drm/verisilicon/Makefile  |   13 +
 drivers/gpu/drm/verisilicon/starfive_hdmi.c   |  928 
 drivers/gpu/drm/verisilicon/starfive_hdmi.h   |  296 +++
 drivers/gpu/drm/verisilicon/vs_crtc.c |  388 
 drivers/gpu/drm/verisilicon/vs_crtc.h |   74 +
 drivers/gpu/drm/verisilicon/vs_dc.c   | 1040 +
 drivers/gpu/drm/verisilicon/vs_dc.h   |   62 +
 drivers/gpu/drm/verisilicon/vs_dc_hw.c| 2008 +
 drivers/gpu/drm/verisilicon/vs_dc_hw.h|  496 
 drivers/gpu/drm/verisilicon/vs_drv.c  |  301 +++
 drivers/gpu/drm/verisilicon/vs_drv.h  |   52 +
 drivers/gpu/drm/verisilicon/vs_fb.c   |  181 ++
 drivers/gpu/drm/verisilicon/vs_fb.h   |   15 +
 drivers/gpu/drm/verisilicon/vs_gem.c  |  372 +++
 drivers/gpu/drm/verisilicon/vs_gem.h  |   72 +
 drivers/gpu/drm/verisilicon/vs_plane.c|  440 
 drivers/gpu/drm/verisilicon/vs_plane.h|   74 +
 drivers/gpu/drm/verisilicon/vs_type.h |   72 +
 include/uapi/drm/drm_fourcc.h |   83 +
 include/uapi/drm/vs_drm.h |   50 +
 30 files changed, 7433 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/display/verisilicon/starfive-hdmi.yaml
 create mode 100644 
Documentation/devicetree/bindings/display/verisilicon/verisilicon-dc.yaml
 create mode 100644 
Documentation/devicetree/bindings/display/verisilicon/verisilicon-drm.yaml
 create mode 100644 drivers/gpu/drm/verisilicon/Kconfig
 create mode 100644 drivers/gpu/drm/verisilicon/Makefile
 create mode 100644 drivers/gpu/drm/verisilicon/starfive_hdmi.c
 create mode 100644 drivers/gpu/drm/verisilicon/starfive_hdmi.h
 create mode 100644 drivers/gpu/drm/verisilicon/vs_crtc.c
 create mode 100644 drivers/gpu/drm/verisilicon/vs_crtc.h
 create mode 100644 drivers/gpu/drm/verisilicon/vs_dc.c
 create mode 100644 drivers/gpu/drm/verisilicon/vs_dc.h
 create mode 100644 drivers/gpu/drm/verisilicon/vs_dc_hw.c
 create mode 100644 drivers/gpu/drm/verisilicon/vs_dc_hw.h
 create mode 100644 drivers/gpu/drm/verisilicon/vs_drv.c
 create mode 100644 drivers/gpu/drm/verisilicon/vs_drv.h
 create mode 100644 drivers/gpu/drm/verisilicon/vs_fb.c
 create mode 100644 drivers/gpu/drm/verisilicon/vs_fb.h
 create mode 100644 drivers/gpu/drm/verisilicon/vs_gem.c
 create mode 100644 drivers/gpu/drm/verisilicon/vs_gem.h
 create mode 100644 drivers/gpu/drm/verisilicon/vs_plane.c
 create mode 100644 drivers/gpu/drm/verisilicon/vs_plane.h
 create mode 100644 drivers/gpu/drm/verisilicon/vs_type.h
 create mode 100644 include/uapi/drm/vs_drm.h

-- 
2.34.1



[PATCH 7/9] drm/verisilicon: Add drm plane funcs

2023-06-02 Thread Keith Zhao
Implement plane functions for the DRM driver.

Signed-off-by: Keith Zhao 
---
 drivers/gpu/drm/verisilicon/Makefile   |   3 +-
 drivers/gpu/drm/verisilicon/vs_plane.c | 440 +
 drivers/gpu/drm/verisilicon/vs_plane.h |  74 +
 3 files changed, 516 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/verisilicon/vs_plane.c
 create mode 100644 drivers/gpu/drm/verisilicon/vs_plane.h

diff --git a/drivers/gpu/drm/verisilicon/Makefile 
b/drivers/gpu/drm/verisilicon/Makefile
index bae5fbab9bbb..d96ad9399fc7 100644
--- a/drivers/gpu/drm/verisilicon/Makefile
+++ b/drivers/gpu/drm/verisilicon/Makefile
@@ -3,7 +3,8 @@
 vs_drm-objs := vs_drv.o \
vs_crtc.o \
vs_fb.o \
-   vs_gem.o
+   vs_gem.o \
+   vs_plane.o
 
 obj-$(CONFIG_DRM_VERISILICON) += vs_drm.o
 
diff --git a/drivers/gpu/drm/verisilicon/vs_plane.c 
b/drivers/gpu/drm/verisilicon/vs_plane.c
new file mode 100644
index ..7b0dcef232ae
--- /dev/null
+++ b/drivers/gpu/drm/verisilicon/vs_plane.c
@@ -0,0 +1,440 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2023 VeriSilicon Holdings Co., Ltd.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#include "vs_crtc.h"
+#include "vs_fb.h"
+#include "vs_gem.h"
+#include "vs_plane.h"
+#include "vs_type.h"
+
+void vs_plane_destory(struct drm_plane *plane)
+{
+   struct vs_plane *vs_plane = to_vs_plane(plane);
+
+   drm_plane_cleanup(plane);
+   kfree(vs_plane);
+}
+
+static void vs_plane_reset(struct drm_plane *plane)
+{
+   struct vs_plane_state *state;
+   struct vs_plane *vs_plane = to_vs_plane(plane);
+
+   if (plane->state) {
+   __drm_atomic_helper_plane_destroy_state(plane->state);
+
+   state = to_vs_plane_state(plane->state);
+   kfree(state);
+   plane->state = NULL;
+   }
+
+   state = kzalloc(sizeof(*state), GFP_KERNEL);
+   if (!state)
+   return;
+
+   __drm_atomic_helper_plane_reset(plane, >base);
+
+   state->degamma = VS_DEGAMMA_DISABLE;
+   state->degamma_changed = false;
+   state->base.zpos = vs_plane->id;
+
+   memset(>status, 0, sizeof(state->status));
+}
+
+static void _vs_plane_duplicate_blob(struct vs_plane_state *state,
+struct vs_plane_state *ori_state)
+{
+   state->watermark = ori_state->watermark;
+   state->color_mgmt = ori_state->color_mgmt;
+   state->roi = ori_state->roi;
+
+   if (state->watermark)
+   drm_property_blob_get(state->watermark);
+   if (state->color_mgmt)
+   drm_property_blob_get(state->color_mgmt);
+   if (state->roi)
+   drm_property_blob_get(state->roi);
+}
+
+static int
+_vs_plane_set_property_blob_from_id(struct drm_device *dev,
+   struct drm_property_blob **blob,
+   u64 blob_id,
+   size_t expected_size)
+{
+   struct drm_property_blob *new_blob = NULL;
+
+   if (blob_id) {
+   new_blob = drm_property_lookup_blob(dev, blob_id);
+   if (!new_blob)
+   return -EINVAL;
+
+   if (new_blob->length != expected_size) {
+   drm_property_blob_put(new_blob);
+   return -EINVAL;
+   }
+   }
+
+   drm_property_replace_blob(blob, new_blob);
+   drm_property_blob_put(new_blob);
+
+   return 0;
+}
+
+static struct drm_plane_state *
+vs_plane_atomic_duplicate_state(struct drm_plane *plane)
+{
+   struct vs_plane_state *ori_state;
+   struct vs_plane_state *state;
+
+   if (WARN_ON(!plane->state))
+   return NULL;
+
+   ori_state = to_vs_plane_state(plane->state);
+   state = kzalloc(sizeof(*state), GFP_KERNEL);
+   if (!state)
+   return NULL;
+
+   __drm_atomic_helper_plane_duplicate_state(plane, >base);
+
+   state->degamma = ori_state->degamma;
+   state->degamma_changed = ori_state->degamma_changed;
+
+   _vs_plane_duplicate_blob(state, ori_state);
+   memcpy(>status, _state->status, sizeof(ori_state->status));
+
+   return >base;
+}
+
+static void vs_plane_atomic_destroy_state(struct drm_plane *plane,
+ struct drm_plane_state *state)
+{
+   struct vs_plane_state *vs_plane_state = to_vs_plane_state(state);
+
+   __drm_atomic_helper_plane_destroy_state(state);
+
+   drm_property_blob_put(vs_plane_state->watermark);
+   drm_property_blob_put(vs_plane_state->color_mgmt);
+   drm_property_blob_put(vs_plane_state->roi);
+   kfree(vs_plane_state);
+}
+
+static int vs_plan

[PATCH 4/9] drm/verisilicon: Add gem driver for JH7110 SoC

2023-06-02 Thread Keith Zhao
This patch implements gem related APIs for JH7100 SoC.

Signed-off-by: Keith Zhao 
---
 drivers/gpu/drm/verisilicon/Makefile |   3 +-
 drivers/gpu/drm/verisilicon/vs_drv.c |   6 +
 drivers/gpu/drm/verisilicon/vs_gem.c | 372 +++
 drivers/gpu/drm/verisilicon/vs_gem.h |  72 ++
 4 files changed, 452 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/verisilicon/vs_gem.c
 create mode 100644 drivers/gpu/drm/verisilicon/vs_gem.h

diff --git a/drivers/gpu/drm/verisilicon/Makefile 
b/drivers/gpu/drm/verisilicon/Makefile
index 64ce1b26546c..30360e370e47 100644
--- a/drivers/gpu/drm/verisilicon/Makefile
+++ b/drivers/gpu/drm/verisilicon/Makefile
@@ -1,6 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0
 
-vs_drm-objs := vs_drv.o
+vs_drm-objs := vs_drv.o \
+   vs_gem.o
 
 obj-$(CONFIG_DRM_VERISILICON) += vs_drm.o
 
diff --git a/drivers/gpu/drm/verisilicon/vs_drv.c 
b/drivers/gpu/drm/verisilicon/vs_drv.c
index 24d333598477..e0a2fc43b55f 100644
--- a/drivers/gpu/drm/verisilicon/vs_drv.c
+++ b/drivers/gpu/drm/verisilicon/vs_drv.c
@@ -30,6 +30,7 @@
 #include 
 
 #include "vs_drv.h"
+#include "vs_gem.h"
 
 #define DRV_NAME   "starfive"
 #define DRV_DESC   "Starfive DRM driver"
@@ -47,6 +48,7 @@ static const struct file_operations fops = {
.compat_ioctl   = drm_compat_ioctl,
.poll   = drm_poll,
.read   = drm_read,
+   .mmap   = vs_gem_mmap,
 };
 
 static struct drm_driver vs_drm_driver = {
@@ -54,6 +56,10 @@ static struct drm_driver vs_drm_driver = {
.lastclose  = drm_fb_helper_lastclose,
.prime_handle_to_fd = drm_gem_prime_handle_to_fd,
.prime_fd_to_handle = drm_gem_prime_fd_to_handle,
+   .gem_prime_import   = vs_gem_prime_import,
+   .gem_prime_import_sg_table = vs_gem_prime_import_sg_table,
+   .gem_prime_mmap = vs_gem_prime_mmap,
+   .dumb_create= vs_gem_dumb_create,
.fops   = ,
.name   = DRV_NAME,
.desc   = DRV_DESC,
diff --git a/drivers/gpu/drm/verisilicon/vs_gem.c 
b/drivers/gpu/drm/verisilicon/vs_gem.c
new file mode 100644
index ..3f963471c1ab
--- /dev/null
+++ b/drivers/gpu/drm/verisilicon/vs_gem.c
@@ -0,0 +1,372 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2023 VeriSilicon Holdings Co., Ltd.
+ */
+
+#include 
+#include 
+#include 
+
+#include "vs_drv.h"
+#include "vs_gem.h"
+
+static const struct drm_gem_object_funcs vs_gem_default_funcs;
+
+static int vs_gem_alloc_buf(struct vs_gem_object *vs_obj)
+{
+   struct drm_device *dev = vs_obj->base.dev;
+   unsigned int nr_pages;
+   struct sg_table sgt;
+   int ret = -ENOMEM;
+
+   if (vs_obj->dma_addr) {
+   DRM_DEV_DEBUG_KMS(dev->dev, "already allocated.\n");
+   return 0;
+   }
+
+   vs_obj->dma_attrs = DMA_ATTR_WRITE_COMBINE | DMA_ATTR_FORCE_CONTIGUOUS
+  | DMA_ATTR_NO_KERNEL_MAPPING;
+
+   nr_pages = vs_obj->size >> PAGE_SHIFT;
+
+   vs_obj->pages = kvmalloc_array(nr_pages, sizeof(struct page *),
+  GFP_KERNEL | __GFP_ZERO);
+   if (!vs_obj->pages) {
+   DRM_DEV_ERROR(dev->dev, "failed to allocate pages.\n");
+   return -ENOMEM;
+   }
+
+   vs_obj->cookie = dma_alloc_attrs(to_dma_dev(dev), vs_obj->size,
+_obj->dma_addr, GFP_KERNEL,
+vs_obj->dma_attrs);
+
+   if (!vs_obj->cookie) {
+   DRM_DEV_ERROR(dev->dev, "failed to allocate buffer.\n");
+   goto err_free;
+   }
+
+   vs_obj->iova = vs_obj->dma_addr;
+
+   ret = dma_get_sgtable_attrs(to_dma_dev(dev), ,
+   vs_obj->cookie, vs_obj->dma_addr,
+   vs_obj->size, vs_obj->dma_attrs);
+   if (ret < 0) {
+   DRM_DEV_ERROR(dev->dev, "failed to get sgtable.\n");
+   goto err_mem_free;
+   }
+
+   if (drm_prime_sg_to_page_array(, vs_obj->pages, nr_pages)) {
+   DRM_DEV_ERROR(dev->dev, "invalid sgtable.\n");
+   ret = -EINVAL;
+   goto err_sgt_free;
+   }
+
+   sg_free_table();
+
+   return 0;
+
+err_sgt_free:
+   sg_free_table();
+err_mem_free:
+   dma_free_attrs(to_dma_dev(dev), vs_obj->size, vs_obj->cookie,
+  vs_obj->dma_addr, vs_obj->dma_attrs);
+err_free:
+   kvfree(vs_obj->pages);
+
+   return ret;
+}
+
+static void vs_gem_free_buf(struct vs_gem_object *vs_obj)
+{
+   struct drm_device *dev = vs_obj->base.dev;
+
+ 

[PATCH 6/9] drm/verisilicon: Add drm crtc funcs

2023-06-02 Thread Keith Zhao
Add crtc driver which implements crtc related operation functions.

Signed-off-by: Keith Zhao 
---
 drivers/gpu/drm/verisilicon/Makefile  |   1 +
 drivers/gpu/drm/verisilicon/vs_crtc.c | 388 ++
 drivers/gpu/drm/verisilicon/vs_crtc.h |  74 +
 drivers/gpu/drm/verisilicon/vs_type.h |  72 +
 4 files changed, 535 insertions(+)
 create mode 100644 drivers/gpu/drm/verisilicon/vs_crtc.c
 create mode 100644 drivers/gpu/drm/verisilicon/vs_crtc.h
 create mode 100644 drivers/gpu/drm/verisilicon/vs_type.h

diff --git a/drivers/gpu/drm/verisilicon/Makefile 
b/drivers/gpu/drm/verisilicon/Makefile
index 38254dc5d98d..bae5fbab9bbb 100644
--- a/drivers/gpu/drm/verisilicon/Makefile
+++ b/drivers/gpu/drm/verisilicon/Makefile
@@ -1,6 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0
 
 vs_drm-objs := vs_drv.o \
+   vs_crtc.o \
vs_fb.o \
vs_gem.o
 
diff --git a/drivers/gpu/drm/verisilicon/vs_crtc.c 
b/drivers/gpu/drm/verisilicon/vs_crtc.c
new file mode 100644
index ..a9e742d7bd1a
--- /dev/null
+++ b/drivers/gpu/drm/verisilicon/vs_crtc.c
@@ -0,0 +1,388 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2023 VeriSilicon Holdings Co., Ltd.
+ *
+ */
+
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "vs_crtc.h"
+
+void vs_crtc_destroy(struct drm_crtc *crtc)
+{
+   struct vs_crtc *vs_crtc = to_vs_crtc(crtc);
+
+   drm_crtc_cleanup(crtc);
+   kfree(vs_crtc);
+}
+
+static void vs_crtc_reset(struct drm_crtc *crtc)
+{
+   struct vs_crtc_state *state;
+
+   if (crtc->state) {
+   __drm_atomic_helper_crtc_destroy_state(crtc->state);
+
+   state = to_vs_crtc_state(crtc->state);
+   kfree(state);
+   crtc->state = NULL;
+   }
+
+   state = kzalloc(sizeof(*state), GFP_KERNEL);
+   if (!state)
+   return;
+
+   __drm_atomic_helper_crtc_reset(crtc, >base);
+
+   state->sync_mode = VS_SINGLE_DC;
+   state->output_fmt = MEDIA_BUS_FMT_RBG888_1X24;
+   state->encoder_type = DRM_MODE_ENCODER_NONE;
+}
+
+static struct drm_crtc_state *
+vs_crtc_atomic_duplicate_state(struct drm_crtc *crtc)
+{
+   struct vs_crtc_state *ori_state;
+   struct vs_crtc_state *state;
+
+   if (WARN_ON(!crtc->state))
+   return NULL;
+
+   ori_state = to_vs_crtc_state(crtc->state);
+   state = kzalloc(sizeof(*state), GFP_KERNEL);
+   if (!state)
+   return NULL;
+
+   __drm_atomic_helper_crtc_duplicate_state(crtc, >base);
+
+   state->sync_mode = ori_state->sync_mode;
+   state->output_fmt = ori_state->output_fmt;
+   state->encoder_type = ori_state->encoder_type;
+   state->bg_color = ori_state->bg_color;
+   state->bpp = ori_state->bpp;
+   state->sync_enable = ori_state->sync_enable;
+   state->dither_enable = ori_state->dither_enable;
+   state->underflow = ori_state->underflow;
+
+   return >base;
+}
+
+static void vs_crtc_atomic_destroy_state(struct drm_crtc *crtc,
+struct drm_crtc_state *state)
+{
+   __drm_atomic_helper_crtc_destroy_state(state);
+   kfree(to_vs_crtc_state(state));
+}
+
+static int vs_crtc_atomic_set_property(struct drm_crtc *crtc,
+  struct drm_crtc_state *state,
+  struct drm_property *property,
+  uint64_t val)
+{
+   struct vs_crtc *vs_crtc = to_vs_crtc(crtc);
+   struct vs_crtc_state *vs_crtc_state = to_vs_crtc_state(state);
+
+   if (property == vs_crtc->sync_mode)
+   vs_crtc_state->sync_mode = val;
+   else if (property == vs_crtc->mmu_prefetch)
+   vs_crtc_state->mmu_prefetch = val;
+   else if (property == vs_crtc->bg_color)
+   vs_crtc_state->bg_color = val;
+   else if (property == vs_crtc->panel_sync)
+   vs_crtc_state->sync_enable = val;
+   else if (property == vs_crtc->dither)
+   vs_crtc_state->dither_enable = val;
+   else
+   return -EINVAL;
+
+   return 0;
+}
+
+static int vs_crtc_atomic_get_property(struct drm_crtc *crtc,
+  const struct drm_crtc_state *state,
+  struct drm_property *property,
+  uint64_t *val)
+{
+   struct vs_crtc *vs_crtc = to_vs_crtc(crtc);
+   const struct vs_crtc_state *vs_crtc_state =
+   container_of(state, const struct vs_crtc_state, base);
+
+   if (property == vs_crtc->sync_mode)
+   *val = vs_crtc_state->sync_mode;
+   else if (property == vs_crtc->mmu_prefetch)
+   *val = vs_crtc_state->mmu_prefet