Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 83683C433EF for ; Wed, 24 Nov 2021 18:40:07 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A3D216E17C; Wed, 24 Nov 2021 18:40:06 +0000 (UTC) Received: from aposti.net (aposti.net [89.234.176.197]) by gabe.freedesktop.org (Postfix) with ESMTPS id B79B66E17C for ; Wed, 24 Nov 2021 18:40:05 +0000 (UTC) Date: Wed, 24 Nov 2021 18:39:49 +0000 From: Paul Cercueil Subject: Re: [PATCH v8 4/8] drm/ingenic: Add dw-hdmi driver for jz4780 To: "H. Nikolaus Schaller" Message-Id: In-Reply-To: <016973B0-B7F0-4E63-BF4F-2643611A6351@goldelico.com> References: <64c6ab288d4d7159f633c860f1b23b3395491ae1.1637691240.git.hns@goldelico.com> <016973B0-B7F0-4E63-BF4F-2643611A6351@goldelico.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Paul Boddie , Geert Uytterhoeven , Neil Armstrong , David Airlie , dri-devel@lists.freedesktop.org, linux-mips@vger.kernel.org, Laurent Pinchart , Miquel Raynal , Sam Ravnborg , Jernej Skrabec , devicetree@vger.kernel.org, Kees Cook , Jonas Karlman , Mark Brown , Maxime Ripard , letux-kernel@openphoenux.org, Ezequiel Garcia , Thomas Bogendoerfer , Liam Girdwood , Robert Foss , linux-kernel@vger.kernel.org, Rob Herring , "Eric W. Biederman" , Hans Verkuil Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Hi Nikolaus, Le mer., nov. 24 2021 at 17:13:30 +0100, H. Nikolaus Schaller=20 a =E9crit : >=20 >=20 >> Am 23.11.2021 um 21:05 schrieb Paul Cercueil : >>=20 >> Hi Nikolaus, >>=20 >> I keep seeing a few things, sorry. >=20 > no problem. >=20 >>=20 >>=20 >> Le mar., nov. 23 2021 at 19:13:57 +0100, H. Nikolaus Schaller=20 >> a =E9crit : >>> From: Paul Boddie >>> A specialisation of the generic Synopsys HDMI driver is employed=20 >>> for >>> JZ4780 HDMI support. This requires a new driver, plus device tree=20 >>> and >>> configuration modifications. >>> Here we add Kconfig DRM_INGENIC_DW_HDMI, Makefile and driver code. >>> Signed-off-by: Paul Boddie >>> Signed-off-by: Ezequiel Garcia >>> Signed-off-by: H. Nikolaus Schaller >>> --- >>> drivers/gpu/drm/ingenic/Kconfig | 9 ++ >>> drivers/gpu/drm/ingenic/Makefile | 1 + >>> drivers/gpu/drm/ingenic/ingenic-dw-hdmi.c | 129=20 >>> ++++++++++++++++++++++ >>> 3 files changed, 139 insertions(+) >>> create mode 100644 drivers/gpu/drm/ingenic/ingenic-dw-hdmi.c >>> diff --git a/drivers/gpu/drm/ingenic/Kconfig=20 >>> b/drivers/gpu/drm/ingenic/Kconfig >>> index 3b57f8be007c4..4efc709d77b0a 100644 >>> --- a/drivers/gpu/drm/ingenic/Kconfig >>> +++ b/drivers/gpu/drm/ingenic/Kconfig >>> @@ -25,4 +25,13 @@ config DRM_INGENIC_IPU >>> The Image Processing Unit (IPU) will appear as a second primary=20 >>> plane. >>> +config DRM_INGENIC_DW_HDMI >>> + tristate "Ingenic specific support for Synopsys DW HDMI" >>> + depends on MACH_JZ4780 >>> + select DRM_DW_HDMI >>> + help >>> + Choose this option to enable Synopsys DesignWare HDMI based=20 >>> driver. >>> + If you want to enable HDMI on Ingenic JZ4780 based SoC, you=20 >>> should >>> + select this option.. >>> + >>> endif >>> diff --git a/drivers/gpu/drm/ingenic/Makefile=20 >>> b/drivers/gpu/drm/ingenic/Makefile >>> index d313326bdddbb..f10cc1c5a5f22 100644 >>> --- a/drivers/gpu/drm/ingenic/Makefile >>> +++ b/drivers/gpu/drm/ingenic/Makefile >>> @@ -1,3 +1,4 @@ >>> obj-$(CONFIG_DRM_INGENIC) +=3D ingenic-drm.o >>> ingenic-drm-y =3D ingenic-drm-drv.o >>> ingenic-drm-$(CONFIG_DRM_INGENIC_IPU) +=3D ingenic-ipu.o >>> +obj-$(CONFIG_DRM_INGENIC_DW_HDMI) +=3D ingenic-dw-hdmi.o >>> diff --git a/drivers/gpu/drm/ingenic/ingenic-dw-hdmi.c=20 >>> b/drivers/gpu/drm/ingenic/ingenic-dw-hdmi.c >>> new file mode 100644 >>> index 0000000000000..c14890d6b9826 >>> --- /dev/null >>> +++ b/drivers/gpu/drm/ingenic/ingenic-dw-hdmi.c >>> @@ -0,0 +1,129 @@ >>> +// SPDX-License-Identifier: GPL-2.0 >>> +/* Copyright (C) 2011-2013 Freescale Semiconductor, Inc. >>> + * Copyright (C) 2019, 2020 Paul Boddie >>> + * >>> + * Derived from dw_hdmi-imx.c with i.MX portions removed. >>> + * Probe and remove operations derived from rcar_dw_hdmi.c. >>> + */ >>> + >>> +#include >>> +#include >>> +#include >>> + >>> +#include >>> +#include >>> +#include >>> + >>> +static const struct dw_hdmi_mpll_config ingenic_mpll_cfg[] =3D { >>> + { 45250000, { { 0x01e0, 0x0000 }, { 0x21e1, 0x0000 }, { 0x41e2,=20 >>> 0x0000 } } }, >>> + { 92500000, { { 0x0140, 0x0005 }, { 0x2141, 0x0005 }, { 0x4142,=20 >>> 0x0005 } } }, >>> + { 148500000, { { 0x00a0, 0x000a }, { 0x20a1, 0x000a }, { 0x40a2,=20 >>> 0x000a } } }, >>> + { 216000000, { { 0x00a0, 0x000a }, { 0x2001, 0x000f }, { 0x4002,=20 >>> 0x000f } } }, >>> + { ~0UL, { { 0x0000, 0x0000 }, { 0x0000, 0x0000 }, { 0x0000,=20 >>> 0x0000 } } } >>> +}; >>> + >>> +static const struct dw_hdmi_curr_ctrl ingenic_cur_ctr[] =3D { >>> + /*pixelclk bpp8 bpp10 bpp12 */ >>> + { 54000000, { 0x091c, 0x091c, 0x06dc } }, >>> + { 58400000, { 0x091c, 0x06dc, 0x06dc } }, >>> + { 72000000, { 0x06dc, 0x06dc, 0x091c } }, >>> + { 74250000, { 0x06dc, 0x0b5c, 0x091c } }, >>> + { 118800000, { 0x091c, 0x091c, 0x06dc } }, >>> + { 216000000, { 0x06dc, 0x0b5c, 0x091c } }, >>> + { ~0UL, { 0x0000, 0x0000, 0x0000 } }, >>> +}; >>> + >>> +/* >>> + * Resistance term 133Ohm Cfg >>> + * PREEMP config 0.00 >>> + * TX/CK level 10 >>> + */ >>> +static const struct dw_hdmi_phy_config ingenic_phy_config[] =3D { >>> + /*pixelclk symbol term vlev */ >>> + { 216000000, 0x800d, 0x0005, 0x01ad}, >>> + { ~0UL, 0x0000, 0x0000, 0x0000} >>> +}; >>> + >>> +static enum drm_mode_status >>> +ingenic_dw_hdmi_mode_valid(struct dw_hdmi *hdmi, void *data, >>> + const struct drm_display_info *info, >>> + const struct drm_display_mode *mode) >>> +{ >>> + if (mode->clock < 13500) >>> + return MODE_CLOCK_LOW; >>> + /* FIXME: Hardware is capable of 270MHz, but setup data is=20 >>> missing. */ >>> + if (mode->clock > 216000) >>> + return MODE_CLOCK_HIGH; >>> + >>> + return MODE_OK; >>> +} >>> + >>> +static struct dw_hdmi_plat_data ingenic_dw_hdmi_plat_data =3D { >>> + .mpll_cfg =3D ingenic_mpll_cfg, >>> + .cur_ctr =3D ingenic_cur_ctr, >>> + .phy_config =3D ingenic_phy_config, >>> + .mode_valid =3D ingenic_dw_hdmi_mode_valid, >>> + .output_port =3D 1, >>> +}; >>> + >>> +static const struct of_device_id ingenic_dw_hdmi_dt_ids[] =3D { >>> + { .compatible =3D "ingenic,jz4780-dw-hdmi" }, >>> + { /* Sentinel */ }, >>> +}; >>> +MODULE_DEVICE_TABLE(of, ingenic_dw_hdmi_dt_ids); >>> + >>> +static int ingenic_dw_hdmi_probe(struct platform_device *pdev) >>> +{ >>> + struct dw_hdmi *hdmi; >>> + struct regulator *regulator; >>> + int ret; >>> + >>> + hdmi =3D dw_hdmi_probe(pdev, &ingenic_dw_hdmi_plat_data); >>> + if (IS_ERR(hdmi)) >>> + return PTR_ERR(hdmi); >>> + >>> + platform_set_drvdata(pdev, hdmi); >>> + >>> + regulator =3D devm_regulator_get_optional(&pdev->dev, "hdmi-5v"); >>> + >>=20 >> Nit - you can remove this blank line. >=20 > ok. >=20 >>=20 >>> + if (IS_ERR(regulator)) { >>> + ret =3D PTR_ERR(regulator); >>> + >>> + DRM_DEV_ERROR(&pdev->dev, "failed to get hpd regulator: %s=20 >>> (%d)\n", >>> + "hdmi-5v", ret); >>> + return ret; >>> + } >>> + >>> + ret =3D regulator_enable(regulator); >>=20 >> You used devm_regulator_get_optional(), so you are not guaranteed=20 >> to obtain anything; your "regulator" variable might be a NULL=20 >> pointer, so you can't just call regulator_enable() without checking=20 >> it first. >=20 > right. I forgot about that. >=20 >>=20 >>> + if (ret) { >>> + DRM_DEV_ERROR(&pdev->dev, "Failed to enable hpd regulator:=20 >>> %d\n", >>> + ret); >>> + return ret; >>> + } >>> + >>> + return 0; >>> +} >>> + >>> +static int ingenic_dw_hdmi_remove(struct platform_device *pdev) >>> +{ >>> + struct dw_hdmi *hdmi =3D platform_get_drvdata(pdev); >>> + >>> + dw_hdmi_remove(hdmi); >>=20 >> You probably should disable the regulator (if not NULL) here. >=20 > Indeed. Would it be ok to make struct regulator *regulator static > or do we need dynamically allocated memory? static non-const is almost always a bad idea, so avoid it. You can either: - create a "ingenic_dw_hdmi" struct that will contain a pointer to=20 dw_hdmi and a pointer to the regulator. Instanciate it in the probe=20 with devm_kzalloc() and set the pointers, then set it as the driver=20 data (platform_set_drvdata). In the remove function you can then obtain=20 the pointer to your ingenic_dw_hdmi struct with platform_get_drvdata(),=20 and you can remove the dw_hdmi and unregister the regulator. - register cleanup functions, using devm_add_action_or_reset(dev, f,=20 priv). When it's time to cleanup, the kernel core will call f(priv)=20 automatically. So you can add a small wrapper around dw_hdmi_remove()=20 and another one around regulator_disable(), and those will be called=20 automatically if your probe function fails, or when the driver is=20 removed. Then you can completely remove the ".remove" callback. There=20 are a few examples of these in the ingenic-drm-drv.c if you want to=20 take a look. Cheers, -Paul >>=20 >>> + >>> + return 0; >>> +} >>> + >>> +static struct platform_driver ingenic_dw_hdmi_driver =3D { >>> + .probe =3D ingenic_dw_hdmi_probe, >>> + .remove =3D ingenic_dw_hdmi_remove, >>> + .driver =3D { >>> + .name =3D "dw-hdmi-ingenic", >>> + .of_match_table =3D ingenic_dw_hdmi_dt_ids, >>> + }, >>> +}; >>> + >>=20 >> Nit - remove this blank line too. >=20 > ok. >=20 >>=20 >> Cheers, >> -Paul >>=20 >>> +module_platform_driver(ingenic_dw_hdmi_driver); >>> + >>> +MODULE_DESCRIPTION("JZ4780 Specific DW-HDMI Driver Extension"); >>> +MODULE_LICENSE("GPL v2"); >>> +MODULE_ALIAS("platform:dwhdmi-ingenic"); >>> -- >>> 2.33.0 >>=20 >>=20 >=20