Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp7122934rwp; Tue, 18 Jul 2023 10:19:00 -0700 (PDT) X-Google-Smtp-Source: APBJJlHptJQkj/6d/WsbBh2Skr3/f3U4Cp12Ggt0+ZBiJn9pPLgbQT4aI4QvqmIPtndDCCrzIIeD X-Received: by 2002:a17:902:a409:b0:1b9:be2e:2b40 with SMTP id p9-20020a170902a40900b001b9be2e2b40mr13279852plq.50.1689700739780; Tue, 18 Jul 2023 10:18:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689700739; cv=none; d=google.com; s=arc-20160816; b=gJbfBbButeFXSLJCItFoUL80IseqjOIbMGqtnK48q/jrMiQK8iO27IwKz+BE+3Kzgm RSyfNN1KdGx0Cbb89/0m9HFzG9ByKbhMjjOZ6LHvpkc/uMR66a4UXW0a/kTADADXicwE pAqTKBoLor6ci5v8IB6SUWuEBQ0E5qvghuk1sJXwkjkqivqmW0IHM+T/znKmrx089HP0 ZXtjw6fbZuO7LssW1bE3Ys9wRmU9ZJNMjaFi57M2lQ0gaSS68BxqoqxMecXXkPgOD4wQ zR+1jcVKRuz1SY/RkVghkVuwczuZawwXTz94MQlsqmsWNIM5tSKTtMrmSYLmq1fd0WBZ Cj6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=ontRQekaY+yfc2I+4g32sG1wEW12n3bYC3uZtMu1nhM=; fh=tA0tLsibEoQ30Z7eqHvQDapDuvXXp6os5IletQHgjxM=; b=RF0IprXW9d8KN8UiBpcOF8GnQNHbC+NMRbaj1GIqTW3nEfNyT+ciV8xdyIeSwCTvRT FIdLDSf+Mh1mFEnP6C3w1Rb0G4UPlC132F/g2gp8SBgJA1wZAYWN8oRFzm6FgUZqIIYa JgZ3CziIpaY166NsqkdpZ1VV9MLBlg7md0nuUW58LPE97PUwcjfe3R0ouiZm/hl4t6oR XokaQ4L7sfnz+ctgwUMxkbr/ZvyyWxgdLCoxPFCwWJoewGNjiaWzrL6BgMSVBIS08Od4 ExHMy7yfIMtxULTRCNaEsTUhworO82PetKZ6vcPk74XHyNDErcDQ8gUFD4EXRdTGNGu+ SBTw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e6-20020a170902cf4600b001b81e6ce809si1826029plg.5.2023.07.18.10.18.46; Tue, 18 Jul 2023 10:18:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232781AbjGRQzC (ORCPT + 99 others); Tue, 18 Jul 2023 12:55:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231927AbjGRQy6 (ORCPT ); Tue, 18 Jul 2023 12:54:58 -0400 Received: from laurent.telenet-ops.be (laurent.telenet-ops.be [IPv6:2a02:1800:110:4::f00:19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0184510D2 for ; Tue, 18 Jul 2023 09:54:54 -0700 (PDT) Received: from ramsan.of.borg ([84.195.187.55]) by laurent.telenet-ops.be with bizsmtp id Ngur2A00E1C8whw01gurjD; Tue, 18 Jul 2023 18:54:52 +0200 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtp (Exim 4.95) (envelope-from ) id 1qLnyD-001nZ4-GR; Tue, 18 Jul 2023 18:54:51 +0200 Received: from geert by rox.of.borg with local (Exim 4.95) (envelope-from ) id 1qLnyN-000gd6-Hc; Tue, 18 Jul 2023 18:54:51 +0200 From: Geert Uytterhoeven To: Laurent Pinchart , Kieran Bingham , David Airlie , Daniel Vetter , Thomas Zimmermann , Magnus Damm Cc: linux-renesas-soc@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH v2 25/41] drm: renesas: shmobile: Move interface handling to connector setup Date: Tue, 18 Jul 2023 18:54:30 +0200 Message-Id: <56e4480a712ad9b8a7f38f4741ac2683815d0efa.1689698048.git.geert+renesas@glider.be> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Move legacy interface handling to the connector setup code. Set up bus_flags and bus_formats in display_info according to the bus format and panel information from platform data, to make it more similar with DT-based connector/bridge/panel setup. This will allow us to use the same LCD interface setup code for both legacy and DT-based systems. Signed-off-by: Geert Uytterhoeven --- v2: - Drop superfluous blank lines, - Keep initialization of info fields together, - Use shmob_drm_bus_fmts[], - Keep bus format validation at probe time. --- .../gpu/drm/renesas/shmobile/shmob_drm_crtc.c | 118 +++++++++++++++--- .../gpu/drm/renesas/shmobile/shmob_drm_drv.c | 34 ----- .../gpu/drm/renesas/shmobile/shmob_drm_drv.h | 3 +- 3 files changed, 104 insertions(+), 51 deletions(-) diff --git a/drivers/gpu/drm/renesas/shmobile/shmob_drm_crtc.c b/drivers/gpu/drm/renesas/shmobile/shmob_drm_crtc.c index b3ef10b7828de197..caafd04acd3d46d0 100644 --- a/drivers/gpu/drm/renesas/shmobile/shmob_drm_crtc.c +++ b/drivers/gpu/drm/renesas/shmobile/shmob_drm_crtc.c @@ -8,6 +8,7 @@ */ #include +#include #include #include @@ -39,20 +40,55 @@ * CRTC */ +static const struct { + u32 fmt; + u32 ldmt1r; +} shmob_drm_bus_fmts[] = { + { MEDIA_BUS_FMT_RGB888_3X8, LDMT1R_MIFTYP_RGB8 }, + { MEDIA_BUS_FMT_RGB666_2X9_BE, LDMT1R_MIFTYP_RGB9 }, + { MEDIA_BUS_FMT_RGB888_2X12_BE, LDMT1R_MIFTYP_RGB12A }, + { MEDIA_BUS_FMT_RGB444_1X12, LDMT1R_MIFTYP_RGB12B }, + { MEDIA_BUS_FMT_RGB565_1X16, LDMT1R_MIFTYP_RGB16 }, + { MEDIA_BUS_FMT_RGB666_1X18, LDMT1R_MIFTYP_RGB18 }, + { MEDIA_BUS_FMT_RGB888_1X24, LDMT1R_MIFTYP_RGB24 }, + { MEDIA_BUS_FMT_UYVY8_1X16, LDMT1R_MIFTYP_YCBCR }, +}; + static void shmob_drm_crtc_setup_geometry(struct shmob_drm_crtc *scrtc) { struct drm_crtc *crtc = &scrtc->crtc; struct shmob_drm_device *sdev = to_shmob_device(crtc->dev); - enum display_flags dpy_flags = sdev->connector.mode->flags; + const struct drm_display_info *info = &sdev->connector->display_info; const struct drm_display_mode *mode = &crtc->mode; + unsigned int i; u32 value; - value = sdev->ldmt1r - | ((mode->flags & DRM_MODE_FLAG_PVSYNC) ? 0 : LDMT1R_VPOL) - | ((mode->flags & DRM_MODE_FLAG_PHSYNC) ? 0 : LDMT1R_HPOL) - | ((dpy_flags & DISPLAY_FLAGS_PIXDATA_POSEDGE) ? LDMT1R_DWPOL : 0) - | ((dpy_flags & DISPLAY_FLAGS_DE_LOW) ? LDMT1R_DIPOL : 0); + if (!info->num_bus_formats || !info->bus_formats) { + dev_warn(sdev->dev, "No bus format reported, using RGB888\n"); + value = LDMT1R_MIFTYP_RGB24; + } else { + for (i = 0; i < ARRAY_SIZE(shmob_drm_bus_fmts); i++) { + if (shmob_drm_bus_fmts[i].fmt == info->bus_formats[0]) + break; + } + if (i < ARRAY_SIZE(shmob_drm_bus_fmts)) { + value = shmob_drm_bus_fmts[i].ldmt1r; + } else { + dev_warn(sdev->dev, + "unsupported bus format 0x%x, using RGB888\n", + info->bus_formats[0]); + value = LDMT1R_MIFTYP_RGB24; + } + } + if (info->bus_flags & DRM_BUS_FLAG_PIXDATA_DRIVE_POSEDGE) + value |= LDMT1R_DWPOL; + if (info->bus_flags & DRM_BUS_FLAG_DE_LOW) + value |= LDMT1R_DIPOL; + if (mode->flags & DRM_MODE_FLAG_NVSYNC) + value |= LDMT1R_VPOL; + if (mode->flags & DRM_MODE_FLAG_NHSYNC) + value |= LDMT1R_HPOL; lcdc_write(sdev, LDMT1R, value); value = ((mode->hdisplay / 8) << 16) /* HDCN */ @@ -479,7 +515,7 @@ static bool shmob_drm_encoder_mode_fixup(struct drm_encoder *encoder, { struct drm_device *dev = encoder->dev; struct shmob_drm_device *sdev = to_shmob_device(dev); - struct drm_connector *connector = &sdev->connector.connector; + struct drm_connector *connector = sdev->connector; const struct drm_display_mode *panel_mode; if (list_empty(&connector->modes)) { @@ -581,6 +617,8 @@ static void shmob_drm_connector_destroy(struct drm_connector *connector) { drm_connector_unregister(connector); drm_connector_cleanup(connector); + + kfree(connector); } static const struct drm_connector_funcs connector_funcs = { @@ -589,26 +627,74 @@ static const struct drm_connector_funcs connector_funcs = { .destroy = shmob_drm_connector_destroy, }; -int shmob_drm_connector_create(struct shmob_drm_device *sdev, - struct drm_encoder *encoder) +static struct drm_connector * +shmob_drm_connector_init(struct shmob_drm_device *sdev, + struct drm_encoder *encoder) { - struct shmob_drm_connector *scon = &sdev->connector; - struct drm_connector *connector = &scon->connector; + u32 bus_fmt = sdev->pdata->iface.bus_fmt; + struct shmob_drm_connector *scon; + struct drm_connector *connector; + struct drm_display_info *info; + unsigned int i; int ret; + for (i = 0; i < ARRAY_SIZE(shmob_drm_bus_fmts); i++) { + if (shmob_drm_bus_fmts[i].fmt == bus_fmt) + break; + } + if (i == ARRAY_SIZE(shmob_drm_bus_fmts)) { + dev_err(sdev->dev, "unsupported bus format 0x%x\n", bus_fmt); + return ERR_PTR(-EINVAL); + } + + scon = kzalloc(sizeof(*scon), GFP_KERNEL); + if (!scon) + return ERR_PTR(-ENOMEM); + + connector = &scon->connector; scon->encoder = encoder; scon->mode = &sdev->pdata->panel.mode; - connector->display_info.width_mm = sdev->pdata->panel.width_mm; - connector->display_info.height_mm = sdev->pdata->panel.height_mm; + info = &connector->display_info; + info->width_mm = sdev->pdata->panel.width_mm; + info->height_mm = sdev->pdata->panel.height_mm; + + if (scon->mode->flags & DISPLAY_FLAGS_PIXDATA_POSEDGE) + info->bus_flags |= DRM_BUS_FLAG_PIXDATA_DRIVE_POSEDGE; + if (scon->mode->flags & DISPLAY_FLAGS_DE_LOW) + info->bus_flags |= DRM_BUS_FLAG_DE_LOW; + + ret = drm_display_info_set_bus_formats(info, &bus_fmt, 1); + if (ret < 0) { + kfree(scon); + return ERR_PTR(ret); + } ret = drm_connector_init(&sdev->ddev, connector, &connector_funcs, DRM_MODE_CONNECTOR_DPI); - if (ret < 0) - return ret; + if (ret < 0) { + kfree(scon); + return ERR_PTR(ret); + } drm_connector_helper_add(connector, &connector_helper_funcs); + return connector; +} + +int shmob_drm_connector_create(struct shmob_drm_device *sdev, + struct drm_encoder *encoder) +{ + struct drm_connector *connector; + int ret; + + connector = shmob_drm_connector_init(sdev, encoder); + if (IS_ERR(connector)) { + dev_err(sdev->dev, "failed to created connector: %pe\n", + connector); + return PTR_ERR(connector); + } + ret = drm_connector_attach_encoder(connector, encoder); if (ret < 0) goto error; @@ -617,6 +703,8 @@ int shmob_drm_connector_create(struct shmob_drm_device *sdev, drm_object_property_set_value(&connector->base, sdev->ddev.mode_config.dpms_property, DRM_MODE_DPMS_OFF); + sdev->connector = connector; + return 0; error: diff --git a/drivers/gpu/drm/renesas/shmobile/shmob_drm_drv.c b/drivers/gpu/drm/renesas/shmobile/shmob_drm_drv.c index 08b254f0f2874786..8da3054f26b2d235 100644 --- a/drivers/gpu/drm/renesas/shmobile/shmob_drm_drv.c +++ b/drivers/gpu/drm/renesas/shmobile/shmob_drm_drv.c @@ -9,7 +9,6 @@ #include #include -#include #include #include #include @@ -33,35 +32,6 @@ * Hardware initialization */ -static int shmob_drm_init_interface(struct shmob_drm_device *sdev) -{ - static const struct { - u32 fmt; - u32 ldmt1r; - } bus_fmts[] = { - { MEDIA_BUS_FMT_RGB888_3X8, LDMT1R_MIFTYP_RGB8 }, - { MEDIA_BUS_FMT_RGB666_2X9_BE, LDMT1R_MIFTYP_RGB9 }, - { MEDIA_BUS_FMT_RGB888_2X12_BE, LDMT1R_MIFTYP_RGB12A }, - { MEDIA_BUS_FMT_RGB444_1X12, LDMT1R_MIFTYP_RGB12B }, - { MEDIA_BUS_FMT_RGB565_1X16, LDMT1R_MIFTYP_RGB16 }, - { MEDIA_BUS_FMT_RGB666_1X18, LDMT1R_MIFTYP_RGB18 }, - { MEDIA_BUS_FMT_RGB888_1X24, LDMT1R_MIFTYP_RGB24 }, - { MEDIA_BUS_FMT_UYVY8_1X16, LDMT1R_MIFTYP_YCBCR }, - }; - unsigned int i; - - for (i = 0; i < ARRAY_SIZE(bus_fmts); i++) { - if (bus_fmts[i].fmt == sdev->pdata->iface.bus_fmt) { - sdev->ldmt1r = bus_fmts[i].ldmt1r; - return 0; - } - } - - dev_err(sdev->dev, "unsupported bus format 0x%x\n", - sdev->pdata->iface.bus_fmt); - return -EINVAL; -} - static int shmob_drm_setup_clocks(struct shmob_drm_device *sdev, enum shmob_drm_clk_source clksrc) { @@ -247,10 +217,6 @@ static int shmob_drm_probe(struct platform_device *pdev) if (ret) return ret; - ret = shmob_drm_init_interface(sdev); - if (ret < 0) - return ret; - ret = shmob_drm_modeset_init(sdev); if (ret < 0) return dev_err_probe(&pdev->dev, ret, diff --git a/drivers/gpu/drm/renesas/shmobile/shmob_drm_drv.h b/drivers/gpu/drm/renesas/shmobile/shmob_drm_drv.h index 5e55ba7a207865bd..18907e5ace51c681 100644 --- a/drivers/gpu/drm/renesas/shmobile/shmob_drm_drv.h +++ b/drivers/gpu/drm/renesas/shmobile/shmob_drm_drv.h @@ -27,7 +27,6 @@ struct shmob_drm_device { void __iomem *mmio; struct clk *clock; u32 lddckr; - u32 ldmt1r; unsigned int irq; spinlock_t irq_lock; /* Protects hardware LDINTR register */ @@ -36,7 +35,7 @@ struct shmob_drm_device { struct shmob_drm_crtc crtc; struct drm_encoder encoder; - struct shmob_drm_connector connector; + struct drm_connector *connector; }; static inline struct shmob_drm_device *to_shmob_device(struct drm_device *dev) -- 2.34.1