From patchwork Sun Jul 14 07:10:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Trimarchi X-Patchwork-Id: 3248 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 233C9412C7 for ; Sun, 14 Jul 2024 09:10:51 +0200 (CEST) Received: by mail-ed1-f70.google.com with SMTP id 4fb4d7f45d1cf-58cdd86c091sf2986071a12.3 for ; Sun, 14 Jul 2024 00:10:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1720941051; cv=pass; d=google.com; s=arc-20160816; b=nPcfpUl2JgOd9oqz37EMPrYbAlrZI5ZeqUc4lczyUmVZm6JnKCt4vEN/2JHfmtDZKq PI9LOWU4gjIDmJPSf/no22ggOlxAg4JuVHT+rJXXLIWMIs1NrFFVdeUKDbw9hS6CSGQz KRhecf2Pauv1PvHAbYJGv+sWThFGQ3d61iC7Jcm9GbZSYg7312Wh0iNyRmqSiKIHgvEt ZXNH9juWgNPlk8R1IlVJ/VEMuMYMsdy2hQq5PCMQfg0luPvsvvfFHj5j03RkURJm8w9H II8VxcHLp2PoFiLIQpzV7tyejoxxHEd5L9pBf7/+CHIHU4zv7lSTgJlvgAWE0ZeW2OGK +m1g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=krP4NUGSkeUMNK8SEII3obvO7Ty4Vj7hFPOtuUS94Cs=; fh=oX6qgex7klFO2rbFAx2EBt27yBN0we/WYIWiwnWCB/8=; b=tI2QsG4lPmh5VKEjN6nmcx2jF0vWH08b21bh3uDswzNoWkqFYvHfJdFPt6tY34SKAP JemT+emNqSn6WU/zd4NysCs3tuAx4vP6HIB/lwJyvdBaXrDcidqhGlIbZSAxn/8vMXcV MoAN/sGncEAurkdXcibGdab/QNbR9as/mqKUytwyqT6SHlnsHEV+GorAD8UwomAj+mC1 00w4Kn+2SoQP46nFMkX4oKV4z9clrI6CIFE0DtkN53OGI6kMVwDwbyHxHchpY25GjcLI 17YvbUFhplNgxv70i/iMLKCHI2OOOXOhjbiaTEGaqFoi302op0le/uGopSjuziCXgKuQ StBg==; darn=patchwork.amarulasolutions.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=QJX0iNEY; spf=pass (google.com: domain of michael@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=michael@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=1720941051; x=1721545851; 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:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=krP4NUGSkeUMNK8SEII3obvO7Ty4Vj7hFPOtuUS94Cs=; b=O1DwB8lfEFxKWmQSo0CLo7pkiJLKf4jNjDTnxkf/CB/dQrCcuK3ITR+1Q4PGb3ALx1 7SP9S2lCVM4KZwIvExuXESvlvMiyUNPBxWVQglWDyklatuPJpBvSwQq3tlIrTjL1KIBH 62NTmAhiF/wPIcKenyaaYGRP8sp0FyKsa1yPE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720941051; x=1721545851; 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:cc:to:from :x-beenthere:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=krP4NUGSkeUMNK8SEII3obvO7Ty4Vj7hFPOtuUS94Cs=; b=w0v08sZ5t7Cqe3qqwSxNIhoQd7TSYZYQyt/oTj1r3LAQSoo7mCqlnTGA8G2kqsB5o1 CB0g/lm50v/pAdkS3buZf1t5haiVVc9x7I/ZR4yrxLFwqZeN+14VI+iWeMxPdFKV52t5 UE+S8RYuoB5j8ErKMGzyx76pLI4XG+jdlnJeYsk0KkWRoZFjBah6xK1lkWaw/B/11u9g UwC1r/GD0OuB3VNjOdobl5LewFlFupKrLHOKbiDINu/2stSWu1GqDLVxNrnUytl5uYaQ aT9/q4JXF7LDRgBZLwDyhiS92BB9sJc2Ys7LdbASdilX4ktj+hzEhnFfKEDc3lU7SttR 3++g== X-Forwarded-Encrypted: i=2; AJvYcCV6nCQzC7OvJwaQUpLP9lwwNzP0AC42M+NlW3TkOj2/NNYSJMhSYD587/x15fecQyKJhhcjRHsdPTVCwo1+ULmPZVv3y7aXL4Yy4sdDNVUc7d5kE+FT0+PQNucv0A== X-Gm-Message-State: AOJu0Yw67FoUGiYieBbo8lnYFSMSQTtnyxB/2dUhyNmR8QkU/rYWBb2y R+erJKuMux7WMhcoLuF1ZfmpwVyi6Bd+3kK0PCqGDvasonWgln0OnsZxDebi1VmmSw== X-Google-Smtp-Source: AGHT+IGvzmikHbBhr/QYqNi7Nc1TVMutSHWlo61rdl0hGo7T+jRvpU0AhhhdNzuk2hbahJxS403MCw== X-Received: by 2002:a05:6402:60f:b0:57c:7486:3f7d with SMTP id 4fb4d7f45d1cf-594bb56a567mr9096509a12.19.1720941050864; Sun, 14 Jul 2024 00:10:50 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:6402:4310:b0:599:9c73:c392 with SMTP id 4fb4d7f45d1cf-5999c73c484ls1238602a12.2.-pod-prod-04-eu; Sun, 14 Jul 2024 00:10:49 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWPjAZgXLOLVk+nzkIR6ZZyTZLXlm17y5nUDmx7D1bKa+09qPMj1jJ6gYsReqSrorcA+ho62IVm/Mp7lz0c+gHwQYkOl5USn/e21BjTEf2bIuNt X-Received: by 2002:a17:906:3989:b0:a77:cd4f:e4f5 with SMTP id a640c23a62f3a-a780b89ca7dmr1007891666b.68.1720941049225; Sun, 14 Jul 2024 00:10:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1720941049; cv=none; d=google.com; s=arc-20160816; b=l8vS5UhxNTYGAKa+8UdYS4K3vDbL8akIjemb6MZKBKowQboDf33zWsC99KvZa9Ea4W 1cynqKi/5OlxlHTDa6nNNybMnR42SNlvBh46HbwbEseMktmV2iP1kmr/zmIdmzA65W0c Gqrba/4GhsJU5POGdAYS4OJGDdAHxRUGkSbVy8vzhCbmzxR8fB8PtrG67cv4eddyuvpL nQ8Czj0yDcpN9ToX4Qx6wAcP4+Dk+f3hBlFsBInoU/m06rxUFrpgPPJ+mJ8fxINi6fUr pG49AImfFqlv70/0oYisj4cS4UAaSRXt2TimnpP6UfY9F1tPTn8aMtK4ywrDbB9l07wF 2R3g== 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:cc:to:from:dkim-signature; bh=Hmbbxb1F+DyFqKbkxqGn2PPIwpqkWAvkpsklF4VY2yo=; fh=M5FBtg+rPq+VGZ8UhU7lRS9ehphXz+BpwFSx/mfbt78=; b=P/MuUdSuq2afl4RB2vWZDqwO15cusvHa2ze4EwwtWfSwUQ7XKHa3dXsNgHDI8LSpBH CY/GEeDClT4YAKu7KtuS9CF+GLt4GM85R0YtVGeq/rOr0G9J79vvB71POrfQgrKH2LgO 7jiDW8GjxhkOoyQdFAIeMQMZB0VRPbiarTny/zjH0LddYhlXxSVHe9U+gsSJ7Sejp9/b RpmJ9DgZaezR9Dk+7GbbBl7HKMBNJNx6QBFn28HUecLOvKfv9hjhDe/zHDfoNMgdfOEK DAv2qpnsi2U2EDfTWL/AHoPYsICslPRGwiSJWJ3RwrgaHhGdol2keCfPNhcRDcCgxi/F K3gQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=QJX0iNEY; spf=pass (google.com: domain of michael@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=michael@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 a640c23a62f3a-a79bc5a3a79sor35001366b.8.2024.07.14.00.10.49 for (Google Transport Security); Sun, 14 Jul 2024 00:10:49 -0700 (PDT) Received-SPF: pass (google.com: domain of michael@amarulasolutions.com designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; X-Forwarded-Encrypted: i=1; AJvYcCXYObprW7o46tiKZGVIownqaFeAyzOXoPVMen3Id7v0ufoJBN7fiUNEqmrJex8nrPsphEL/GJXjU9Got6uw2hCl68WlMF5YPRPDQPKFadcUx+7l X-Received: by 2002:a17:906:f10c:b0:a77:c824:b4c4 with SMTP id a640c23a62f3a-a780b6b1886mr1136497866b.19.1720941048794; Sun, 14 Jul 2024 00:10:48 -0700 (PDT) Received: from panicking.. (93-35-128-17.ip55.fastwebnet.it. [93.35.128.17]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a79bc820d52sm104950266b.214.2024.07.14.00.10.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Jul 2024 00:10:48 -0700 (PDT) From: Michael Trimarchi To: Michael Trimarchi Cc: Dario Binacchi , Patrick Barsanti , linux-amarula@amarulasolutions.com Subject: [PATCH 17/25] video: Update mxsfb video drivers for iMX8MM/iMX8MN display Date: Sun, 14 Jul 2024 09:10:15 +0200 Message-ID: <20240714071023.10417-17-michael@amarulasolutions.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240714071023.10417-1-michael@amarulasolutions.com> References: <20240714071023.10417-1-michael@amarulasolutions.com> MIME-Version: 1.0 X-Original-Sender: michael@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=QJX0iNEY; spf=pass (google.com: domain of michael@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=michael@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: , 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 792d6314d1..4186ccd002 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), };