RE: [EXT] Re: [PATCH v10 1/7] drm: bridge: Cadence: Creat mhdp helper driver

2023-10-16 Thread Sandor Yu
Hi Alexander,

>
> Hi Sandor,
>
> Am Montag, 16. Oktober 2023, 05:05:54 CEST schrieb Sandor Yu:
> > Hi Alexander,
> >
> > Thanks your comments,
> >
> > > Hi Sandor,
> > >
> > > thanks for the updated series.
> > >
> > > Am Freitag, 13. Oktober 2023, 05:24:20 CEST schrieb Sandor Yu:
> > > > MHDP8546 mailbox access functions will be share to other mhdp
> > > > driver and Cadence HDP-TX HDMI/DP PHY drivers.
> > > > Create a new mhdp helper driver and move all those functions into.
> > > >
> > > > cdns_mhdp_reg_write() is renamed to cdns_mhdp_dp_reg_write(),
> > > > because it use the DPTX command ID DPTX_WRITE_REGISTER.
> > > >
> > > > New cdns_mhdp_reg_write() is created with the general command ID
> > > > GENERAL_REGISTER_WRITE.
> > > >
> > > > Signed-off-by: Sandor Yu 
> > > > ---
> > > >
> > > > v9->v10:
> > > >  *use mhdp helper driver to replace macro functions,  move maibox
> > > >
> > > > access function and mhdp hdmi/dp common API  functions into the
> > > > driver.
> > > >
> > > >  drivers/gpu/drm/bridge/cadence/Kconfig|   4
> > > >  drivers/gpu/drm/bridge/cadence/Makefile   |   1 +
> > > >  .../gpu/drm/bridge/cadence/cdns-mhdp-helper.c | 306
> ++
> > > >  .../drm/bridge/cadence/cdns-mhdp8546-core.c   | 383
> +++---
> > > >  .../drm/bridge/cadence/cdns-mhdp8546-core.h   |  44 +-
> > > >  include/drm/bridge/cdns-mhdp-helper.h |  96 +
> > > >  6 files changed, 473 insertions(+), 361 deletions(-)  create mode
> > > >
> > > > 100644 drivers/gpu/drm/bridge/cadence/cdns-mhdp-helper.c
> > > >
> > > >  create mode 100644 include/drm/bridge/cdns-mhdp-helper.h
> > > >
> > > > diff --git a/drivers/gpu/drm/bridge/cadence/Kconfig
> > > > b/drivers/gpu/drm/bridge/cadence/Kconfig index
> > > > ec35215a20034..0b7b4626a7af0
> > > > 100644
> > > > --- a/drivers/gpu/drm/bridge/cadence/Kconfig
> > > > +++ b/drivers/gpu/drm/bridge/cadence/Kconfig
> > > > @@ -20,6 +20,9 @@ config DRM_CDNS_DSI_J721E
> > > >
> > > > the routing of the DSS DPI signal to the Cadence DSI.
> > > >
> > > >  endif
> > > >
> > > > +config CDNS_MHDP_HELPER
> > > > + tristate
> > > > +
> > > >
> > > >  config DRM_CDNS_MHDP8546
> > > >
> > > >   tristate "Cadence DPI/DP bridge"
> > > >   select DRM_DISPLAY_DP_HELPER
> > > >
> > > > @@ -27,6 +30,7 @@ config DRM_CDNS_MHDP8546
> > > >
> > > >   select DRM_DISPLAY_HELPER
> > > >   select DRM_KMS_HELPER
> > > >   select DRM_PANEL_BRIDGE
> > > >
> > > > + select CDNS_MHDP_HELPER
> > > >
> > > >   depends on OF
> > > >   help
> > > >
> > > > Support Cadence DPI to DP bridge. This is an internal diff
> > > >
> > > > --git a/drivers/gpu/drm/bridge/cadence/Makefile
> > > > b/drivers/gpu/drm/bridge/cadence/Makefile index
> > > > c95fd5b81d137..087dc074820d7 100644
> > > > --- a/drivers/gpu/drm/bridge/cadence/Makefile
> > > > +++ b/drivers/gpu/drm/bridge/cadence/Makefile
> > > > @@ -2,6 +2,7 @@
> > > >
> > > >  obj-$(CONFIG_DRM_CDNS_DSI) += cdns-dsi.o  cdns-dsi-y :=
> > > >
> > > > cdns-dsi-core.o
> > > >
> > > >  cdns-dsi-$(CONFIG_DRM_CDNS_DSI_J721E) += cdns-dsi-j721e.o
> > > >
> > > > +obj-$(CONFIG_CDNS_MHDP_HELPER) += cdns-mhdp-helper.o
> > > >
> > > >  obj-$(CONFIG_DRM_CDNS_MHDP8546) += cdns-mhdp8546.o
> > >
> > > cdns-mhdp8546-y
> > >
> > > > := cdns-mhdp8546-core.o cdns-mhdp8546-hdcp.o
> > > > :
> > > >  cdns-mhdp8546-$(CONFIG_DRM_CDNS_MHDP8546_J721E) +=
> > > >
> > > > cdns-mhdp8546-j721e.o diff --git
> > > > a/drivers/gpu/drm/bridge/cadence/cdns-mhdp-helper.c
> > > > b/drivers/gpu/drm/bridge/cadence/cdns-mhdp-helper.c new file mode
> > > > 100644 index 0..2e3eee40494f0
> > > > --- /dev/null
> > > > +++ b/drivers/gpu/drm/bridge/cadence/cdns-mhdp-helper.c
> > > > @@ -0,0 +1,306 @@
> > > > +// SPDX-License-Identifier: GPL-2.0-only
> > > > +/*
> > > > + * Copyright (C) 2023 NXP Semiconductor, Inc.
> > > > + *
> > > > + */
> > > > +#include  #include
> > > > + #include 
> > > > +
> > > > +/* Mailbox helper functions */
> > > > +int cdns_mhdp_mailbox_read(struct cdns_mhdp_base *base) {
> > > > + int ret, empty;
> > > > +
> > > > + WARN_ON(!mutex_is_locked(base->mbox_mutex));
> > > > +
> > > > + ret = readx_poll_timeout(readl, base->regs +
> > >
> > > CDNS_MAILBOX_EMPTY,
> > >
> > > > +  empty, !empty,
> MAILBOX_RETRY_US,
> > > > +  MAILBOX_TIMEOUT_US);
> > > > + if (ret < 0)
> > > > + return ret;
> > > > +
> > > > + return readl(base->regs + CDNS_MAILBOX_RX_DATA) & 0xff; }
> > > > +EXPORT_SYMBOL_GPL(cdns_mhdp_mailbox_read);
> > >
> > > No need to export this. You can make this function actually static.
> >
> > OK, I will change it to static in the next version.
> >
> > > > +
> > > > +int cdns_mhdp_mailbox_write(struct cdns_mhdp_base *base, u8 val) {
> > > > + int ret, full;
> > > > +
> > > > + WARN_ON(!mutex_is_locked(base->mbox_mutex));
> > > > +
> > > > + ret = readx_poll_timeout(readl, base->regs +

Re: [PATCH v10 1/7] drm: bridge: Cadence: Creat mhdp helper driver

2023-10-16 Thread Alexander Stein
Hi Sandor,

Am Montag, 16. Oktober 2023, 05:05:54 CEST schrieb Sandor Yu:
> Hi Alexander,
> 
> Thanks your comments,
> 
> > Hi Sandor,
> > 
> > thanks for the updated series.
> > 
> > Am Freitag, 13. Oktober 2023, 05:24:20 CEST schrieb Sandor Yu:
> > > MHDP8546 mailbox access functions will be share to other mhdp driver
> > > and Cadence HDP-TX HDMI/DP PHY drivers.
> > > Create a new mhdp helper driver and move all those functions into.
> > > 
> > > cdns_mhdp_reg_write() is renamed to cdns_mhdp_dp_reg_write(), because
> > > it use the DPTX command ID DPTX_WRITE_REGISTER.
> > > 
> > > New cdns_mhdp_reg_write() is created with the general command ID
> > > GENERAL_REGISTER_WRITE.
> > > 
> > > Signed-off-by: Sandor Yu 
> > > ---
> > > 
> > > v9->v10:
> > >  *use mhdp helper driver to replace macro functions,  move maibox
> > > 
> > > access function and mhdp hdmi/dp common API  functions into the
> > > driver.
> > > 
> > >  drivers/gpu/drm/bridge/cadence/Kconfig|   4
> > >  drivers/gpu/drm/bridge/cadence/Makefile   |   1 +
> > >  .../gpu/drm/bridge/cadence/cdns-mhdp-helper.c | 306 ++
> > >  .../drm/bridge/cadence/cdns-mhdp8546-core.c   | 383 +++---
> > >  .../drm/bridge/cadence/cdns-mhdp8546-core.h   |  44 +-
> > >  include/drm/bridge/cdns-mhdp-helper.h |  96 +
> > >  6 files changed, 473 insertions(+), 361 deletions(-)  create mode
> > > 
> > > 100644 drivers/gpu/drm/bridge/cadence/cdns-mhdp-helper.c
> > > 
> > >  create mode 100644 include/drm/bridge/cdns-mhdp-helper.h
> > > 
> > > diff --git a/drivers/gpu/drm/bridge/cadence/Kconfig
> > > b/drivers/gpu/drm/bridge/cadence/Kconfig index
> > > ec35215a20034..0b7b4626a7af0
> > > 100644
> > > --- a/drivers/gpu/drm/bridge/cadence/Kconfig
> > > +++ b/drivers/gpu/drm/bridge/cadence/Kconfig
> > > @@ -20,6 +20,9 @@ config DRM_CDNS_DSI_J721E
> > > 
> > > the routing of the DSS DPI signal to the Cadence DSI.
> > >  
> > >  endif
> > > 
> > > +config CDNS_MHDP_HELPER
> > > + tristate
> > > +
> > > 
> > >  config DRM_CDNS_MHDP8546
> > >  
> > >   tristate "Cadence DPI/DP bridge"
> > >   select DRM_DISPLAY_DP_HELPER
> > > 
> > > @@ -27,6 +30,7 @@ config DRM_CDNS_MHDP8546
> > > 
> > >   select DRM_DISPLAY_HELPER
> > >   select DRM_KMS_HELPER
> > >   select DRM_PANEL_BRIDGE
> > > 
> > > + select CDNS_MHDP_HELPER
> > > 
> > >   depends on OF
> > >   help
> > >   
> > > Support Cadence DPI to DP bridge. This is an internal diff
> > > 
> > > --git a/drivers/gpu/drm/bridge/cadence/Makefile
> > > b/drivers/gpu/drm/bridge/cadence/Makefile index
> > > c95fd5b81d137..087dc074820d7 100644
> > > --- a/drivers/gpu/drm/bridge/cadence/Makefile
> > > +++ b/drivers/gpu/drm/bridge/cadence/Makefile
> > > @@ -2,6 +2,7 @@
> > > 
> > >  obj-$(CONFIG_DRM_CDNS_DSI) += cdns-dsi.o  cdns-dsi-y :=
> > > 
> > > cdns-dsi-core.o
> > > 
> > >  cdns-dsi-$(CONFIG_DRM_CDNS_DSI_J721E) += cdns-dsi-j721e.o
> > > 
> > > +obj-$(CONFIG_CDNS_MHDP_HELPER) += cdns-mhdp-helper.o
> > > 
> > >  obj-$(CONFIG_DRM_CDNS_MHDP8546) += cdns-mhdp8546.o
> > 
> > cdns-mhdp8546-y
> > 
> > > := cdns-mhdp8546-core.o cdns-mhdp8546-hdcp.o
> > > :
> > >  cdns-mhdp8546-$(CONFIG_DRM_CDNS_MHDP8546_J721E) +=
> > > 
> > > cdns-mhdp8546-j721e.o diff --git
> > > a/drivers/gpu/drm/bridge/cadence/cdns-mhdp-helper.c
> > > b/drivers/gpu/drm/bridge/cadence/cdns-mhdp-helper.c new file mode
> > > 100644 index 0..2e3eee40494f0
> > > --- /dev/null
> > > +++ b/drivers/gpu/drm/bridge/cadence/cdns-mhdp-helper.c
> > > @@ -0,0 +1,306 @@
> > > +// SPDX-License-Identifier: GPL-2.0-only
> > > +/*
> > > + * Copyright (C) 2023 NXP Semiconductor, Inc.
> > > + *
> > > + */
> > > +#include  #include
> > > + #include 
> > > +
> > > +/* Mailbox helper functions */
> > > +int cdns_mhdp_mailbox_read(struct cdns_mhdp_base *base) {
> > > + int ret, empty;
> > > +
> > > + WARN_ON(!mutex_is_locked(base->mbox_mutex));
> > > +
> > > + ret = readx_poll_timeout(readl, base->regs +
> > 
> > CDNS_MAILBOX_EMPTY,
> > 
> > > +  empty, !empty, MAILBOX_RETRY_US,
> > > +  MAILBOX_TIMEOUT_US);
> > > + if (ret < 0)
> > > + return ret;
> > > +
> > > + return readl(base->regs + CDNS_MAILBOX_RX_DATA) & 0xff; }
> > > +EXPORT_SYMBOL_GPL(cdns_mhdp_mailbox_read);
> > 
> > No need to export this. You can make this function actually static.
> 
> OK, I will change it to static in the next version.
> 
> > > +
> > > +int cdns_mhdp_mailbox_write(struct cdns_mhdp_base *base, u8 val) {
> > > + int ret, full;
> > > +
> > > + WARN_ON(!mutex_is_locked(base->mbox_mutex));
> > > +
> > > + ret = readx_poll_timeout(readl, base->regs + CDNS_MAILBOX_FULL,
> > > +  full, !full, MAILBOX_RETRY_US,
> > > +  MAILBOX_TIMEOUT_US);
> > > + if (ret < 0)
> > > + return ret;
> > > +
> > > + writel(val, base->regs + CDNS_MAILBOX_TX_D

RE: [EXT] Re: [PATCH v10 1/7] drm: bridge: Cadence: Creat mhdp helper driver

2023-10-15 Thread Sandor Yu
Hi Alexander,

Thanks your comments,

> 
> Hi Sandor,
> 
> thanks for the updated series.
> 
> Am Freitag, 13. Oktober 2023, 05:24:20 CEST schrieb Sandor Yu:
> > MHDP8546 mailbox access functions will be share to other mhdp driver
> > and Cadence HDP-TX HDMI/DP PHY drivers.
> > Create a new mhdp helper driver and move all those functions into.
> >
> > cdns_mhdp_reg_write() is renamed to cdns_mhdp_dp_reg_write(), because
> > it use the DPTX command ID DPTX_WRITE_REGISTER.
> >
> > New cdns_mhdp_reg_write() is created with the general command ID
> > GENERAL_REGISTER_WRITE.
> >
> > Signed-off-by: Sandor Yu 
> > ---
> > v9->v10:
> >  *use mhdp helper driver to replace macro functions,  move maibox
> > access function and mhdp hdmi/dp common API  functions into the
> > driver.
> >
> >  drivers/gpu/drm/bridge/cadence/Kconfig|   4
> >  drivers/gpu/drm/bridge/cadence/Makefile   |   1 +
> >  .../gpu/drm/bridge/cadence/cdns-mhdp-helper.c | 306 ++
> >  .../drm/bridge/cadence/cdns-mhdp8546-core.c   | 383 +++---
> >  .../drm/bridge/cadence/cdns-mhdp8546-core.h   |  44 +-
> >  include/drm/bridge/cdns-mhdp-helper.h |  96 +
> >  6 files changed, 473 insertions(+), 361 deletions(-)  create mode
> > 100644 drivers/gpu/drm/bridge/cadence/cdns-mhdp-helper.c
> >  create mode 100644 include/drm/bridge/cdns-mhdp-helper.h
> >
> > diff --git a/drivers/gpu/drm/bridge/cadence/Kconfig
> > b/drivers/gpu/drm/bridge/cadence/Kconfig index
> > ec35215a20034..0b7b4626a7af0
> > 100644
> > --- a/drivers/gpu/drm/bridge/cadence/Kconfig
> > +++ b/drivers/gpu/drm/bridge/cadence/Kconfig
> > @@ -20,6 +20,9 @@ config DRM_CDNS_DSI_J721E
> > the routing of the DSS DPI signal to the Cadence DSI.
> >  endif
> >
> > +config CDNS_MHDP_HELPER
> > + tristate
> > +
> >  config DRM_CDNS_MHDP8546
> >   tristate "Cadence DPI/DP bridge"
> >   select DRM_DISPLAY_DP_HELPER
> > @@ -27,6 +30,7 @@ config DRM_CDNS_MHDP8546
> >   select DRM_DISPLAY_HELPER
> >   select DRM_KMS_HELPER
> >   select DRM_PANEL_BRIDGE
> > + select CDNS_MHDP_HELPER
> >   depends on OF
> >   help
> > Support Cadence DPI to DP bridge. This is an internal diff
> > --git a/drivers/gpu/drm/bridge/cadence/Makefile
> > b/drivers/gpu/drm/bridge/cadence/Makefile index
> > c95fd5b81d137..087dc074820d7 100644
> > --- a/drivers/gpu/drm/bridge/cadence/Makefile
> > +++ b/drivers/gpu/drm/bridge/cadence/Makefile
> > @@ -2,6 +2,7 @@
> >  obj-$(CONFIG_DRM_CDNS_DSI) += cdns-dsi.o  cdns-dsi-y :=
> > cdns-dsi-core.o
> >  cdns-dsi-$(CONFIG_DRM_CDNS_DSI_J721E) += cdns-dsi-j721e.o
> > +obj-$(CONFIG_CDNS_MHDP_HELPER) += cdns-mhdp-helper.o
> >  obj-$(CONFIG_DRM_CDNS_MHDP8546) += cdns-mhdp8546.o
> cdns-mhdp8546-y
> > := cdns-mhdp8546-core.o cdns-mhdp8546-hdcp.o
> >  cdns-mhdp8546-$(CONFIG_DRM_CDNS_MHDP8546_J721E) +=
> > cdns-mhdp8546-j721e.o diff --git
> > a/drivers/gpu/drm/bridge/cadence/cdns-mhdp-helper.c
> > b/drivers/gpu/drm/bridge/cadence/cdns-mhdp-helper.c new file mode
> > 100644 index 0..2e3eee40494f0
> > --- /dev/null
> > +++ b/drivers/gpu/drm/bridge/cadence/cdns-mhdp-helper.c
> > @@ -0,0 +1,306 @@
> > +// SPDX-License-Identifier: GPL-2.0-only
> > +/*
> > + * Copyright (C) 2023 NXP Semiconductor, Inc.
> > + *
> > + */
> > +#include  #include
> > + #include 
> > +
> > +/* Mailbox helper functions */
> > +int cdns_mhdp_mailbox_read(struct cdns_mhdp_base *base) {
> > + int ret, empty;
> > +
> > + WARN_ON(!mutex_is_locked(base->mbox_mutex));
> > +
> > + ret = readx_poll_timeout(readl, base->regs +
> CDNS_MAILBOX_EMPTY,
> > +  empty, !empty, MAILBOX_RETRY_US,
> > +  MAILBOX_TIMEOUT_US);
> > + if (ret < 0)
> > + return ret;
> > +
> > + return readl(base->regs + CDNS_MAILBOX_RX_DATA) & 0xff; }
> > +EXPORT_SYMBOL_GPL(cdns_mhdp_mailbox_read);
> 
> No need to export this. You can make this function actually static.

OK, I will change it to static in the next version.

> 
> > +
> > +int cdns_mhdp_mailbox_write(struct cdns_mhdp_base *base, u8 val) {
> > + int ret, full;
> > +
> > + WARN_ON(!mutex_is_locked(base->mbox_mutex));
> > +
> > + ret = readx_poll_timeout(readl, base->regs + CDNS_MAILBOX_FULL,
> > +  full, !full, MAILBOX_RETRY_US,
> > +  MAILBOX_TIMEOUT_US);
> > + if (ret < 0)
> > + return ret;
> > +
> > + writel(val, base->regs + CDNS_MAILBOX_TX_DATA);
> > +
> > + return 0;
> > +}
> > +EXPORT_SYMBOL_GPL(cdns_mhdp_mailbox_write);
> 
> No need to export that one as well. You can make this function actually static
> as these two functions are only called from the helper itself.

mhdp8546 driver need this function. 

> 
> > +
> > +int cdns_mhdp_mailbox_recv_header(struct cdns_mhdp_base *base,
> > +   u8 module_id, u8 opcode,
> > +   u16 req_size) {
> > + u32 mbox_size, i;

Re: [PATCH v10 1/7] drm: bridge: Cadence: Creat mhdp helper driver

2023-10-13 Thread Alexander Stein
Hi Sandor,

thanks for the updated series.

Am Freitag, 13. Oktober 2023, 05:24:20 CEST schrieb Sandor Yu:
> MHDP8546 mailbox access functions will be share to other mhdp driver
> and Cadence HDP-TX HDMI/DP PHY drivers.
> Create a new mhdp helper driver and move all those functions into.
> 
> cdns_mhdp_reg_write() is renamed to cdns_mhdp_dp_reg_write(),
> because it use the DPTX command ID DPTX_WRITE_REGISTER.
> 
> New cdns_mhdp_reg_write() is created with the general command ID
> GENERAL_REGISTER_WRITE.
> 
> Signed-off-by: Sandor Yu 
> ---
> v9->v10:
>  *use mhdp helper driver to replace macro functions,
>  move maibox access function and mhdp hdmi/dp common API
>  functions into the driver.
> 
>  drivers/gpu/drm/bridge/cadence/Kconfig|   4
>  drivers/gpu/drm/bridge/cadence/Makefile   |   1 +
>  .../gpu/drm/bridge/cadence/cdns-mhdp-helper.c | 306 ++
>  .../drm/bridge/cadence/cdns-mhdp8546-core.c   | 383 +++---
>  .../drm/bridge/cadence/cdns-mhdp8546-core.h   |  44 +-
>  include/drm/bridge/cdns-mhdp-helper.h |  96 +
>  6 files changed, 473 insertions(+), 361 deletions(-)
>  create mode 100644 drivers/gpu/drm/bridge/cadence/cdns-mhdp-helper.c
>  create mode 100644 include/drm/bridge/cdns-mhdp-helper.h
> 
> diff --git a/drivers/gpu/drm/bridge/cadence/Kconfig
> b/drivers/gpu/drm/bridge/cadence/Kconfig index ec35215a20034..0b7b4626a7af0
> 100644
> --- a/drivers/gpu/drm/bridge/cadence/Kconfig
> +++ b/drivers/gpu/drm/bridge/cadence/Kconfig
> @@ -20,6 +20,9 @@ config DRM_CDNS_DSI_J721E
> the routing of the DSS DPI signal to the Cadence DSI.
>  endif
> 
> +config CDNS_MHDP_HELPER
> + tristate
> +
>  config DRM_CDNS_MHDP8546
>   tristate "Cadence DPI/DP bridge"
>   select DRM_DISPLAY_DP_HELPER
> @@ -27,6 +30,7 @@ config DRM_CDNS_MHDP8546
>   select DRM_DISPLAY_HELPER
>   select DRM_KMS_HELPER
>   select DRM_PANEL_BRIDGE
> + select CDNS_MHDP_HELPER
>   depends on OF
>   help
> Support Cadence DPI to DP bridge. This is an internal
> diff --git a/drivers/gpu/drm/bridge/cadence/Makefile
> b/drivers/gpu/drm/bridge/cadence/Makefile index
> c95fd5b81d137..087dc074820d7 100644
> --- a/drivers/gpu/drm/bridge/cadence/Makefile
> +++ b/drivers/gpu/drm/bridge/cadence/Makefile
> @@ -2,6 +2,7 @@
>  obj-$(CONFIG_DRM_CDNS_DSI) += cdns-dsi.o
>  cdns-dsi-y := cdns-dsi-core.o
>  cdns-dsi-$(CONFIG_DRM_CDNS_DSI_J721E) += cdns-dsi-j721e.o
> +obj-$(CONFIG_CDNS_MHDP_HELPER) += cdns-mhdp-helper.o
>  obj-$(CONFIG_DRM_CDNS_MHDP8546) += cdns-mhdp8546.o
>  cdns-mhdp8546-y := cdns-mhdp8546-core.o cdns-mhdp8546-hdcp.o
>  cdns-mhdp8546-$(CONFIG_DRM_CDNS_MHDP8546_J721E) += cdns-mhdp8546-j721e.o
> diff --git a/drivers/gpu/drm/bridge/cadence/cdns-mhdp-helper.c
> b/drivers/gpu/drm/bridge/cadence/cdns-mhdp-helper.c new file mode 100644
> index 0..2e3eee40494f0
> --- /dev/null
> +++ b/drivers/gpu/drm/bridge/cadence/cdns-mhdp-helper.c
> @@ -0,0 +1,306 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * Copyright (C) 2023 NXP Semiconductor, Inc.
> + *
> + */
> +#include 
> +#include 
> +#include 
> +
> +/* Mailbox helper functions */
> +int cdns_mhdp_mailbox_read(struct cdns_mhdp_base *base)
> +{
> + int ret, empty;
> +
> + WARN_ON(!mutex_is_locked(base->mbox_mutex));
> +
> + ret = readx_poll_timeout(readl, base->regs + CDNS_MAILBOX_EMPTY,
> +  empty, !empty, MAILBOX_RETRY_US,
> +  MAILBOX_TIMEOUT_US);
> + if (ret < 0)
> + return ret;
> +
> + return readl(base->regs + CDNS_MAILBOX_RX_DATA) & 0xff;
> +}
> +EXPORT_SYMBOL_GPL(cdns_mhdp_mailbox_read);

No need to export this. You can make this function actually static.

> +
> +int cdns_mhdp_mailbox_write(struct cdns_mhdp_base *base, u8 val)
> +{
> + int ret, full;
> +
> + WARN_ON(!mutex_is_locked(base->mbox_mutex));
> +
> + ret = readx_poll_timeout(readl, base->regs + CDNS_MAILBOX_FULL,
> +  full, !full, MAILBOX_RETRY_US,
> +  MAILBOX_TIMEOUT_US);
> + if (ret < 0)
> + return ret;
> +
> + writel(val, base->regs + CDNS_MAILBOX_TX_DATA);
> +
> + return 0;
> +}
> +EXPORT_SYMBOL_GPL(cdns_mhdp_mailbox_write);

No need to export that one as well. You can make this function actually static 
as these two functions are only called from the helper itself.

> +
> +int cdns_mhdp_mailbox_recv_header(struct cdns_mhdp_base *base,
> +   u8 module_id, u8 opcode,
> +   u16 req_size)
> +{
> + u32 mbox_size, i;
> + u8 header[4];
> + int ret;
> +
> + /* read the header of the message */
> + for (i = 0; i < sizeof(header); i++) {
> + ret = cdns_mhdp_mailbox_read(base);
> + if (ret < 0)
> + return ret;
> +
> + header[i] = ret;
> + }
> +
> + mbox_size = get_unaligned_be16(header + 2);
> +
> + if (op

[PATCH v10 1/7] drm: bridge: Cadence: Creat mhdp helper driver

2023-10-12 Thread Sandor Yu
MHDP8546 mailbox access functions will be share to other mhdp driver
and Cadence HDP-TX HDMI/DP PHY drivers.
Create a new mhdp helper driver and move all those functions into.

cdns_mhdp_reg_write() is renamed to cdns_mhdp_dp_reg_write(),
because it use the DPTX command ID DPTX_WRITE_REGISTER.

New cdns_mhdp_reg_write() is created with the general command ID
GENERAL_REGISTER_WRITE.

Signed-off-by: Sandor Yu 
---
v9->v10:
 *use mhdp helper driver to replace macro functions,
 move maibox access function and mhdp hdmi/dp common API
 functions into the driver.

 drivers/gpu/drm/bridge/cadence/Kconfig|   4 
 drivers/gpu/drm/bridge/cadence/Makefile   |   1 +
 .../gpu/drm/bridge/cadence/cdns-mhdp-helper.c | 306 ++
 .../drm/bridge/cadence/cdns-mhdp8546-core.c   | 383 +++---
 .../drm/bridge/cadence/cdns-mhdp8546-core.h   |  44 +-
 include/drm/bridge/cdns-mhdp-helper.h |  96 +
 6 files changed, 473 insertions(+), 361 deletions(-)
 create mode 100644 drivers/gpu/drm/bridge/cadence/cdns-mhdp-helper.c
 create mode 100644 include/drm/bridge/cdns-mhdp-helper.h

diff --git a/drivers/gpu/drm/bridge/cadence/Kconfig 
b/drivers/gpu/drm/bridge/cadence/Kconfig
index ec35215a20034..0b7b4626a7af0 100644
--- a/drivers/gpu/drm/bridge/cadence/Kconfig
+++ b/drivers/gpu/drm/bridge/cadence/Kconfig
@@ -20,6 +20,9 @@ config DRM_CDNS_DSI_J721E
  the routing of the DSS DPI signal to the Cadence DSI.
 endif
 
+config CDNS_MHDP_HELPER
+   tristate
+
 config DRM_CDNS_MHDP8546
tristate "Cadence DPI/DP bridge"
select DRM_DISPLAY_DP_HELPER
@@ -27,6 +30,7 @@ config DRM_CDNS_MHDP8546
select DRM_DISPLAY_HELPER
select DRM_KMS_HELPER
select DRM_PANEL_BRIDGE
+   select CDNS_MHDP_HELPER
depends on OF
help
  Support Cadence DPI to DP bridge. This is an internal
diff --git a/drivers/gpu/drm/bridge/cadence/Makefile 
b/drivers/gpu/drm/bridge/cadence/Makefile
index c95fd5b81d137..087dc074820d7 100644
--- a/drivers/gpu/drm/bridge/cadence/Makefile
+++ b/drivers/gpu/drm/bridge/cadence/Makefile
@@ -2,6 +2,7 @@
 obj-$(CONFIG_DRM_CDNS_DSI) += cdns-dsi.o
 cdns-dsi-y := cdns-dsi-core.o
 cdns-dsi-$(CONFIG_DRM_CDNS_DSI_J721E) += cdns-dsi-j721e.o
+obj-$(CONFIG_CDNS_MHDP_HELPER) += cdns-mhdp-helper.o
 obj-$(CONFIG_DRM_CDNS_MHDP8546) += cdns-mhdp8546.o
 cdns-mhdp8546-y := cdns-mhdp8546-core.o cdns-mhdp8546-hdcp.o
 cdns-mhdp8546-$(CONFIG_DRM_CDNS_MHDP8546_J721E) += cdns-mhdp8546-j721e.o
diff --git a/drivers/gpu/drm/bridge/cadence/cdns-mhdp-helper.c 
b/drivers/gpu/drm/bridge/cadence/cdns-mhdp-helper.c
new file mode 100644
index 0..2e3eee40494f0
--- /dev/null
+++ b/drivers/gpu/drm/bridge/cadence/cdns-mhdp-helper.c
@@ -0,0 +1,306 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2023 NXP Semiconductor, Inc.
+ *
+ */
+#include 
+#include 
+#include 
+
+/* Mailbox helper functions */
+int cdns_mhdp_mailbox_read(struct cdns_mhdp_base *base)
+{
+   int ret, empty;
+
+   WARN_ON(!mutex_is_locked(base->mbox_mutex));
+
+   ret = readx_poll_timeout(readl, base->regs + CDNS_MAILBOX_EMPTY,
+empty, !empty, MAILBOX_RETRY_US,
+MAILBOX_TIMEOUT_US);
+   if (ret < 0)
+   return ret;
+
+   return readl(base->regs + CDNS_MAILBOX_RX_DATA) & 0xff;
+}
+EXPORT_SYMBOL_GPL(cdns_mhdp_mailbox_read);
+
+int cdns_mhdp_mailbox_write(struct cdns_mhdp_base *base, u8 val)
+{
+   int ret, full;
+
+   WARN_ON(!mutex_is_locked(base->mbox_mutex));
+
+   ret = readx_poll_timeout(readl, base->regs + CDNS_MAILBOX_FULL,
+full, !full, MAILBOX_RETRY_US,
+MAILBOX_TIMEOUT_US);
+   if (ret < 0)
+   return ret;
+
+   writel(val, base->regs + CDNS_MAILBOX_TX_DATA);
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(cdns_mhdp_mailbox_write);
+
+int cdns_mhdp_mailbox_recv_header(struct cdns_mhdp_base *base,
+ u8 module_id, u8 opcode,
+ u16 req_size)
+{
+   u32 mbox_size, i;
+   u8 header[4];
+   int ret;
+
+   /* read the header of the message */
+   for (i = 0; i < sizeof(header); i++) {
+   ret = cdns_mhdp_mailbox_read(base);
+   if (ret < 0)
+   return ret;
+
+   header[i] = ret;
+   }
+
+   mbox_size = get_unaligned_be16(header + 2);
+
+   if (opcode != header[0] || module_id != header[1] ||
+   req_size != mbox_size) {
+   /*
+* If the message in mailbox is not what we want, we need to
+* clear the mailbox by reading its contents.
+*/
+   for (i = 0; i < mbox_size; i++)
+   if (cdns_mhdp_mailbox_read(base) < 0)
+   break;
+
+   return -EINVAL;
+   }
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(cd