From patchwork Wed Sep 11 15:10:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 3443 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id AA52842E89 for ; Wed, 11 Sep 2024 17:10:55 +0200 (CEST) Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-374c581ce35sf3496847f8f.3 for ; Wed, 11 Sep 2024 08:10:55 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1726067455; cv=pass; d=google.com; s=arc-20240605; b=OGFpf03k6r5M4FYIIag8nWsQHejvxhLILIopgrXvj4JEVyOnXOV+Idlu+A4XN/3qLt y+H2kFb3V03kEqwxLh0DMJpXmVSIvWqat2WGq2Z5hS2WGzk6MVxERSX7u3DgWrkzxR9y Upe1RHoEddq5G44i0riJ22ICdTYae78Xp3waSZPzmRbGgbW9fZ3ng76FDko8Vv8GJ5KI jCglY7ptm+B5Ul0YVynezMa1cRCv7UvmjFdcXv+7wIsxlkhMHIwO01Aa3Rfq32CYmcHS 2ZD1sktUv32DaH16WdIFY4Oq48xxiWN0Ouhv61Lm2kvQR3Fh+mYpJV5SDu/DhzSHxrMr yDbg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:mime-version:references:in-reply-to :message-id:date:subject:to:from:dkim-signature; bh=1qjXluEZqIJ4ivd7s/zLuoeS4yndFJ8JwctijI6n0D8=; fh=FfS3SK5cROBa03wfbsZNpPN44wEq3j0nrLXNhbaTmAI=; b=TzTLR7cEioRCseuDDNULkeHiL3OGeOulJUUCsCVXutUutYJ6Vh61KFc0xXtJd9kwZk O7X9LyziP3n+MV0V4xS/VIQuJYn7PTfYObZJyKVySrTyttcE68v3yCaqZaPHygNCpAZg e36vnZyVCUIw+E0uqX+izkuuEhRw61JTBuNWayyqF8VlLG8Cuas8EvtIKwjQh6iYnzTa Eay0ddwtxSLnZckkRFooSynr7RUHOlqOGQszRtDGM4eRmnMzRyEOsTK5xRBLaxyTtBQV k21gU+EqzBNrK2mU/iFHzGsMEFE/L9PoEoE3xwHl1abnJzS/3OLZUHHEXbR2sXfL8Z0A +9sA==; darn=patchwork.amarulasolutions.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=rRzzdn8b; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com; dara=pass header.i=@amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; t=1726067455; x=1726672255; darn=patchwork.amarulasolutions.com; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:x-original-authentication-results :x-original-sender:mime-version:references:in-reply-to:message-id :date:subject:to:from:from:to:cc:subject:date:message-id:reply-to; bh=1qjXluEZqIJ4ivd7s/zLuoeS4yndFJ8JwctijI6n0D8=; b=cT66cs1AfO98LjotfWhvblSuR7htrgABIzPJ4eXpzp/MFPgvamHgkg8fT9hTvKM401 UepwTa10Lnf90QwiDCtjeplv9Bvw/mcu3mkbDrF4EuAkMEAq7eHuIMkBmOvzOxmfDtV/ YUfcKqC4j46sqfyZ4qnZtShjTnjKBiNJKr/9M= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726067455; x=1726672255; h=list-unsubscribe:list-archive:list-help:list-post :x-spam-checked-in-group:list-id:mailing-list:precedence :x-original-authentication-results:x-original-sender:mime-version :references:in-reply-to:message-id:date:subject:to:from:x-beenthere :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=1qjXluEZqIJ4ivd7s/zLuoeS4yndFJ8JwctijI6n0D8=; b=hrw5g32sGu0EeAZl9JsyjT+eoCuy9ei7n0VsNbUUWzkSepRoKieU9v8GirNJ+SCzh7 6hlHw99ueB0+qAazEF18VK+NIXcdS7/UF4ytXTLEgnCDbFJPrtOe6wQoVvUFIqq86CPh L3nVjOaWQqeS8Oh0Zg9EtpzEW3HSU6KI4thdfFLaqGT/4oJ3fLopxu+JDmMO136pqs1w bLIdxB5o2+I77g2E9z0czt6a/Qhb/n8NvgWySxzS3cJDuBS91eCtBcq7Ks7FktBZc4I8 EgdteI2Zz66L0gJRG90Lppp7PcgYRC/3+sx6P62c6X25t0E/VDPGB6vOAAyK3a++6Z2h hmIg== X-Forwarded-Encrypted: i=2; AJvYcCVXVD3J5gAhtwPD36IldoJJkKk+V8tYOzDm3r+d1kc0khB6QzyR1RpZfnbRR58kWwFGD7ZDVJ1hn1m7P+vo@patchwork.amarulasolutions.com X-Gm-Message-State: AOJu0Yyf0pt3ebP4rl1qezdfjL/rDPs2UdLkkolYZg/vdnM4Fo+M/4PL dgdjDdWs2PFnpf/MofS14KdfsAbO+94qZ6uQLEYaslwCq7DFL/Cg3cZwIG1o3Ho5YQ== X-Google-Smtp-Source: AGHT+IEQSgPWRwttRJxBhoCpHZu/GSJAKVAFOaXrVXopx8y0Jdww9bdhHf5c16glIzNH0/+m3gE9UQ== X-Received: by 2002:a5d:658b:0:b0:377:205f:c494 with SMTP id ffacd0b85a97d-378895c541cmr11033709f8f.11.1726067455160; Wed, 11 Sep 2024 08:10:55 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a5d:6845:0:b0:377:2d98:7c90 with SMTP id ffacd0b85a97d-378883d759dls1863718f8f.2.-pod-prod-09-eu; Wed, 11 Sep 2024 08:10:54 -0700 (PDT) X-Received: by 2002:a5d:558d:0:b0:374:c671:2324 with SMTP id ffacd0b85a97d-378896591d5mr10495981f8f.44.1726067453676; Wed, 11 Sep 2024 08:10:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1726067453; cv=none; d=google.com; s=arc-20160816; b=E17Gwnj+xq2J8RCO7f5jFXDlgBxg3LwTI1fw2dux3Wjkn+iU+oxIeLRn30KcrIj6md 0BqJZl0cYxNsOKR437ivWfljB/utIBjWvVCqGv6b6MnqCsnMex2wgBkX1Gc+mmwyQ8Pg RBJq+vGSKdmXsveEkkSiBp8GFBehwNchv7FZcAXVCwzskSPNNZKs1lhxOmRZJahtWUA/ IUuLxYgBOygItKMtXRxG7//akSk0tQeDadhVP15zbjEJfKm4Ol5d/CcGZrEcAv2Q8q/Q h/sjErUHr3cTQEgOxIBc5+pL4pFHzyf47tp/dK/v2D7LORwfTPP/cDt5aKxLF4vmdj/U HINA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:dkim-signature; bh=z8nF2JDMXf0aSXakTOuvB/aSZNwxPB0i3IX2I/2bdOc=; fh=FtQepR0uNoeKT2PVdKfTKOkvEYfwbRmoVE9BmlYw3tk=; b=oP511oLfR9lJTALeJtyZSV8bakUuvebs7Xf7ysjqtHNAxLemfG9y1Wj9aI4QrE65fZ VulXNjgF9/jqATJPMUt1vB5YumCFSol8rDw/bL5iW8Kdpzp1oN+wq3e9lw5vgEnolxMa WmhwGZhrJemedgqxQgUxwdfiqCGtzqw8pCz9wVKzfkzsKWNi2SEUIkzrCdCE3SSQoX/I wWQ3fZrGdgvMEuBs4EfNFbMisRf8GSVZkffHvcKKfu85XW5HfeO0L6mXkKpp1ka9KS6E lZh2bolJIaFzKkwCwDvYc3Xv2luDZLlOkQjTwzLDR2VrriY9JnSALXY0/osMgnZ82QzF DyZQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=rRzzdn8b; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com; dara=pass header.i=@amarulasolutions.com Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id 5b1f17b1804b1-42caf301b51sor39504615e9.10.2024.09.11.08.10.53 for (Google Transport Security); Wed, 11 Sep 2024 08:10:53 -0700 (PDT) Received-SPF: pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; X-Received: by 2002:a05:600c:3b1d:b0:42c:b750:1a1e with SMTP id 5b1f17b1804b1-42cb7501dc3mr89467655e9.0.1726067452803; Wed, 11 Sep 2024 08:10:52 -0700 (PDT) Received: from dario-ThinkPad-T14s-Gen-2i.amarulasolutions.com ([2.196.41.3]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42cb116f44esm137688375e9.45.2024.09.11.08.10.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 08:10:52 -0700 (PDT) From: Dario Binacchi To: linux-amarula@amarulasolutions.com Subject: [PATCH v2 13/27] video: Update mxsfb video drivers for iMX8MM/iMX8MN display Date: Wed, 11 Sep 2024 17:10:25 +0200 Message-ID: <20240911151039.2914886-13-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240911151039.2914886-1-dario.binacchi@amarulasolutions.com> References: <20240911151039.2914886-1-dario.binacchi@amarulasolutions.com> MIME-Version: 1.0 X-Original-Sender: dario.binacchi@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=rRzzdn8b; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com; dara=pass header.i=@amarulasolutions.com Content-Type: text/plain; charset="UTF-8" Precedence: list Mailing-list: list linux-amarula@amarulasolutions.com; contact linux-amarula+owners@amarulasolutions.com List-ID: X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com X-Google-Group-Id: 476853432473 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Michael Trimarchi Update mxsfb for LCD video driver Signed-off-by: Ye Li Signed-off-by: Michael Trimarchi --- drivers/video/mxsfb.c | 141 ++++++++++++++++++++++++++++-------------- 1 file changed, 95 insertions(+), 46 deletions(-) diff --git a/drivers/video/mxsfb.c b/drivers/video/mxsfb.c index 792d6314d15e..4186ccd00209 100644 --- a/drivers/video/mxsfb.c +++ b/drivers/video/mxsfb.c @@ -21,8 +21,13 @@ #include #include #include +#include +#include +#include +#include #include "videomodes.h" +#include #define PS2KHZ(ps) (1000000000UL / (ps)) #define HZ2PS(hz) (1000000000UL / ((hz) / 1000)) @@ -30,6 +35,11 @@ #define BITS_PP 18 #define BYTES_PP 4 +struct mxsfb_priv { + fdt_addr_t reg_base; + struct udevice *disp_dev; +}; + struct mxs_dma_desc desc; /** @@ -56,9 +66,10 @@ __weak void mxsfb_system_setup(void) */ static void mxs_lcd_init(struct udevice *dev, u32 fb_addr, - struct display_timing *timings, int bpp) + struct display_timing *timings, int bpp, bool bridge) { - struct mxs_lcdif_regs *regs = (struct mxs_lcdif_regs *)MXS_LCDIF_BASE; + struct mxsfb_priv *priv = dev_get_priv(dev); + struct mxs_lcdif_regs *regs = (struct mxs_lcdif_regs *)priv->reg_base; const enum display_flags flags = timings->flags; uint32_t word_len = 0, bus_width = 0; uint8_t valid_data = 0; @@ -109,7 +120,7 @@ static void mxs_lcd_init(struct udevice *dev, u32 fb_addr, } #else /* Kick in the LCDIF clock */ - mxs_set_lcdclk(MXS_LCDIF_BASE, timings->pixelclock.typ / 1000); + mxs_set_lcdclk(priv->reg_base, timings->pixelclock.typ / 1000); #endif /* Restart the LCDIF block */ @@ -142,26 +153,30 @@ static void mxs_lcd_init(struct udevice *dev, u32 fb_addr, LCDIF_CTRL_BYPASS_COUNT | LCDIF_CTRL_LCDIF_MASTER, ®s->hw_lcdif_ctrl); - writel(valid_data << LCDIF_CTRL1_BYTE_PACKING_FORMAT_OFFSET, + writel((valid_data << LCDIF_CTRL1_BYTE_PACKING_FORMAT_OFFSET) | + LCDIF_CTRL1_RECOVER_ON_UNDERFLOW, ®s->hw_lcdif_ctrl1); + if (bridge) + writel(LCDIF_CTRL2_OUTSTANDING_REQS_REQ_16, ®s->hw_lcdif_ctrl2); + mxsfb_system_setup(); writel((timings->vactive.typ << LCDIF_TRANSFER_COUNT_V_COUNT_OFFSET) | timings->hactive.typ, ®s->hw_lcdif_transfer_count); - vdctrl0 = LCDIF_VDCTRL0_ENABLE_PRESENT | LCDIF_VDCTRL0_ENABLE_POL | + vdctrl0 = LCDIF_VDCTRL0_ENABLE_PRESENT | LCDIF_VDCTRL0_VSYNC_PERIOD_UNIT | LCDIF_VDCTRL0_VSYNC_PULSE_WIDTH_UNIT | timings->vsync_len.typ; - if(flags & DISPLAY_FLAGS_HSYNC_HIGH) + if (flags & DISPLAY_FLAGS_HSYNC_HIGH) vdctrl0 |= LCDIF_VDCTRL0_HSYNC_POL; - if(flags & DISPLAY_FLAGS_VSYNC_HIGH) + if (flags & DISPLAY_FLAGS_VSYNC_HIGH) vdctrl0 |= LCDIF_VDCTRL0_VSYNC_POL; - if(flags & DISPLAY_FLAGS_PIXDATA_NEGEDGE) + if (flags & DISPLAY_FLAGS_PIXDATA_NEGEDGE) vdctrl0 |= LCDIF_VDCTRL0_DOTCLK_POL; - if(flags & DISPLAY_FLAGS_DE_HIGH) + if (flags & DISPLAY_FLAGS_DE_HIGH) vdctrl0 |= LCDIF_VDCTRL0_ENABLE_POL; writel(vdctrl0, ®s->hw_lcdif_vdctrl0); @@ -198,10 +213,10 @@ static void mxs_lcd_init(struct udevice *dev, u32 fb_addr, } static int mxs_probe_common(struct udevice *dev, struct display_timing *timings, - int bpp, u32 fb) + int bpp, u32 fb, bool bridge) { /* Start framebuffer */ - mxs_lcd_init(dev, fb, timings, bpp); + mxs_lcd_init(dev, fb, timings, bpp, bridge); #ifdef CONFIG_VIDEO_MXS_MODE_SYSTEM /* @@ -212,7 +227,8 @@ static int mxs_probe_common(struct udevice *dev, struct display_timing *timings, * sets the RUN bit, then waits until it gets cleared and repeats this * infinitelly. This way, we get smooth continuous updates of the LCD. */ - struct mxs_lcdif_regs *regs = (struct mxs_lcdif_regs *)MXS_LCDIF_BASE; + struct mxsfb_priv *priv = dev_get_priv(dev); + struct mxs_lcdif_regs *regs = (struct mxs_lcdif_regs *)priv->reg_base; memset(&desc, 0, sizeof(struct mxs_dma_desc)); desc.address = (dma_addr_t)&desc; @@ -229,9 +245,9 @@ static int mxs_probe_common(struct udevice *dev, struct display_timing *timings, return 0; } -static int mxs_remove_common(u32 fb) +static int mxs_remove_common(phys_addr_t reg_base, u32 fb) { - struct mxs_lcdif_regs *regs = (struct mxs_lcdif_regs *)MXS_LCDIF_BASE; + struct mxs_lcdif_regs *regs = (struct mxs_lcdif_regs *)(reg_base); int timeout = 1000000; if (!fb) @@ -258,6 +274,7 @@ static int mxs_of_get_timings(struct udevice *dev, int ret = 0; u32 display_phandle; ofnode display_node; + struct mxsfb_priv *priv = dev_get_priv(dev); ret = ofnode_read_u32(dev_ofnode(dev), "display", &display_phandle); if (ret) { @@ -278,10 +295,19 @@ static int mxs_of_get_timings(struct udevice *dev, return -EINVAL; } - ret = ofnode_decode_display_timing(display_node, 0, timings); - if (ret) { - dev_err(dev, "failed to get any display timings\n"); - return -EINVAL; + priv->disp_dev = video_link_get_next_device(dev); + if (priv->disp_dev) { + ret = video_link_get_display_timings(timings); + if (ret) { + dev_err(dev, "failed to get any video link display timings\n"); + return -EINVAL; + } + } else { + ret = ofnode_decode_display_timing(display_node, 0, timings); + if (ret) { + dev_err(dev, "failed to get any display timings\n"); + return -EINVAL; + } } return ret; @@ -291,20 +317,58 @@ static int mxs_video_probe(struct udevice *dev) { struct video_uc_plat *plat = dev_get_uclass_plat(dev); struct video_priv *uc_priv = dev_get_uclass_priv(dev); + struct mxsfb_priv *priv = dev_get_priv(dev); struct display_timing timings; u32 bpp = 0; u32 fb_start, fb_end; int ret; + bool enable_bridge = false; debug("%s() plat: base 0x%lx, size 0x%x\n", __func__, plat->base, plat->size); + priv->reg_base = dev_read_addr(dev); + if (priv->reg_base == FDT_ADDR_T_NONE) { + dev_err(dev, "lcdif base address is not found\n"); + return -EINVAL; + } + ret = mxs_of_get_timings(dev, &timings, &bpp); if (ret) return ret; - ret = mxs_probe_common(dev, &timings, bpp, plat->base); + if (priv->disp_dev) { +#if IS_ENABLED(CONFIG_VIDEO_BRIDGE) + if (device_get_uclass_id(priv->disp_dev) == UCLASS_VIDEO_BRIDGE) { + ret = video_bridge_attach(priv->disp_dev); + if (ret) { + dev_err(dev, "fail to attach bridge\n"); + return ret; + } + + ret = video_bridge_set_backlight(priv->disp_dev, 80); + if (ret) { + dev_err(dev, "fail to set backlight\n"); + return ret; + } + + enable_bridge = true; + video_bridge_check_timing(priv->disp_dev, &timings); + } +#endif + + if (device_get_uclass_id(priv->disp_dev) == UCLASS_PANEL) { + ret = panel_enable_backlight(priv->disp_dev); + if (ret) { + dev_err(dev, "panel %s enable backlight error %d\n", + priv->disp_dev->name, ret); + return ret; + } + } + } + + ret = mxs_probe_common(dev, &timings, bpp, plat->base, enable_bridge); if (ret) return ret; @@ -343,33 +407,9 @@ static int mxs_video_probe(struct udevice *dev) static int mxs_video_bind(struct udevice *dev) { struct video_uc_plat *plat = dev_get_uclass_plat(dev); - struct display_timing timings; - u32 bpp = 0; - u32 bytes_pp = 0; - int ret; - ret = mxs_of_get_timings(dev, &timings, &bpp); - if (ret) - return ret; - - switch (bpp) { - case 32: - case 24: - case 18: - bytes_pp = 4; - break; - case 16: - bytes_pp = 2; - break; - case 8: - bytes_pp = 1; - break; - default: - dev_err(dev, "invalid bpp specified (bpp = %i)\n", bpp); - return -EINVAL; - } - - plat->size = timings.hactive.typ * timings.vactive.typ * bytes_pp; + /* Max size supported by LCDIF, because in bind, we can't probe panel */ + plat->size = 1920 * 1080 *4 * 2; return 0; } @@ -377,8 +417,14 @@ static int mxs_video_bind(struct udevice *dev) static int mxs_video_remove(struct udevice *dev) { struct video_uc_plat *plat = dev_get_uclass_plat(dev); + struct mxsfb_priv *priv = dev_get_priv(dev); + + debug("%s\n", __func__); + + if (priv->disp_dev) + device_remove(priv->disp_dev, DM_REMOVE_NORMAL); - mxs_remove_common(plat->base); + mxs_remove_common(priv->reg_base, plat->base); return 0; } @@ -389,6 +435,8 @@ static const struct udevice_id mxs_video_ids[] = { { .compatible = "fsl,imx6sx-lcdif" }, { .compatible = "fsl,imx7ulp-lcdif" }, { .compatible = "fsl,imxrt-lcdif" }, + { .compatible = "fsl,imx8mm-lcdif" }, + { .compatible = "fsl,imx8mn-lcdif" }, { /* sentinel */ } }; @@ -400,4 +448,5 @@ U_BOOT_DRIVER(mxs_video) = { .probe = mxs_video_probe, .remove = mxs_video_remove, .flags = DM_FLAG_PRE_RELOC | DM_FLAG_OS_PREPARE, + .priv_auto = sizeof(struct mxsfb_priv), };