From patchwork Fri Aug 3 07:23:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Rosin X-Patchwork-Id: 10554757 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4E14914E2 for ; Fri, 3 Aug 2018 07:35:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3DDB22BF7F for ; Fri, 3 Aug 2018 07:35:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2F4362C074; Fri, 3 Aug 2018 07:35:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED,DKIM_VALID,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7B6FD2BF7F for ; Fri, 3 Aug 2018 07:35:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=G8K7Zm4WwuTtqYPLnthSLyuj2e03RyG9aeDp4u/zK2E=; b=FkwqMTKcwlnupP NfyrIhoxjiO/3cutuhUoB2BWyuBq8EtnZn7qVflxnFLriWIf30+ZGXBHBHRK0q2/b6XHIaUeA5DUp 8a9tG1HkQ/ynv/yqxQdBsKW7pQqPdUui9yRk4w2v/5F++V5NOHEh98eu/NEzASab7RS53SlTUbTOg uyMN8Dw9EIgm6MdDgIoWAZmLDLRgGlWqOu66H7D4rLVEAssCh4SYuRd5gpKmGScatjuwq56ZMvuu1 xme2SRuJaxNwkGZYTLwEhGGq7/ljLSZ00RTqn+WVGcfpVCt88/pGRWRl8Vo0C3Q8nO/CFhKmMAzcV SEbANVPBijY+F/WngfIQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1flUca-0006QG-Jj; Fri, 03 Aug 2018 07:35:36 +0000 Received: from mail-eopbgr00099.outbound.protection.outlook.com ([40.107.0.99] helo=EUR02-AM5-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1flUR8-0008V3-9Q for linux-arm-kernel@lists.infradead.org; Fri, 03 Aug 2018 07:23:51 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axentia.se; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=40eBm95wmDAmfblSHxYnQzKvC7vcwL7/NW7OyhfXZlY=; b=nxq9RWaHQSejWOQCf26OsyXjpW3tJ5MvML/ys2YBrr41mPF+36LQcIwhcDqf2jXI6wLpm5fPvl7mk/HTuxHjflTOvZdXJ3zJ+FUgx58HRpYB/d4Tg7PMhthy4NJLKShUAW1phU8RrtUNCn1qFXL7QDLNZJfx+X6MqTrQ9K5cYdo= Received: from orc.pedanet (85.226.244.23) by HE1PR0201MB2460.eurprd02.prod.outlook.com (10.168.147.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1017.15; Fri, 3 Aug 2018 07:23:31 +0000 From: Peter Rosin To: linux-kernel@vger.kernel.org Subject: [RESEND PATCH v5 3/3] drm/atmel-hlcdc: support bus-width (12/16/18/24) in endpoint nodes Date: Fri, 3 Aug 2018 09:23:08 +0200 Message-Id: <20180803072308.14962-4-peda@axentia.se> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180803072308.14962-1-peda@axentia.se> References: <20180803072308.14962-1-peda@axentia.se> MIME-Version: 1.0 X-Originating-IP: [85.226.244.23] X-ClientProxiedBy: PR2P264CA0045.FRAP264.PROD.OUTLOOK.COM (52.133.96.161) To HE1PR0201MB2460.eurprd02.prod.outlook.com (10.168.147.8) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b57991bb-42da-479a-82c5-08d5f9120507 X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(7021125)(8989117)(4534165)(7022125)(4603075)(4627221)(201702281549075)(8990107)(7048125)(7024125)(7027125)(7028125)(7023125)(5600074)(711020)(2017052603328)(7153060)(7193020); SRVR:HE1PR0201MB2460; X-Microsoft-Exchange-Diagnostics: 1; HE1PR0201MB2460; 3:AEao91U3L81WF98LtA56eg+X0DZctRYLcoZR6oCqHK1RDQx40d2ANbzDejNMtX4XrfVmwPmzlSbEsUlieYfK0Gb/IR86mDV4MBh0B5LBly4KnHpJPRNac9TDdn8Ba7comgT9ym1E/v4igt1Gvx70u8hqyYve07YQNAnMX3JuRhP6iev7QR5W1fkK1wMc4dU5aD15HfW/h37QF+E7PAvoY1jrxrGV/1sGUfL8xOES2aFR218M33wbbYYaSybo4t4x; 25:q3+DQhqyiJKRyaHJEpAgbqwJfOVLbTfzDkdsbsRcQSIUhMipPjAp5YjzjNIr+ABBzvsE+KzXQtbt7A+sjezfuE5te4lyC7MHCqZrEm4OSb08KXSgmb1jjvS+VZrsIP/9RWo1t4R3zD83KYKii9vzHk/93L498xEd66nB1Pd3xBFo4xAGqP+SRZeDq1r4H1DYYuDiqsZD9YA7ZFWF3qXa3gF5OPRgmKauzfdBi8sdcR5IH7Tc4TXHOMDeX4g9PZqAF+32AO4W0S1dUb46upI90Lh7dgvEgMspKk2I+sAz9NiO1v5IwsNNMh0deE8xQPO8mdOViQ11YMJu1nJcSMb0hA==; 31:CgCXJIK0AfuNoTFo5xGyW7P24+fY/izHVG5kIygcp3mr6KRebaokGLTTwALg6XDSj3hsa2GPN2PTOrG80BhPNRsoWpw52NutBBdaqUX5kb0VOdqUPjBwL7Oc390d4fYkYl5XsQL14/MtIr2gRTjJs984h7UYcuLHYbRv6UuPzlHVxR8W0dll1u6mOIPdyy/ZKkf4Jrh0PtoQi+13KW3Aq286Ax96TSDT7a1C7x8Zh2Q= X-MS-TrafficTypeDiagnostic: HE1PR0201MB2460: Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=peda@axentia.se; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040522)(2401047)(8121501046)(5005006)(3231311)(944501410)(52105095)(3002001)(10201501046)(93006095)(93001095)(149027)(150027)(6041310)(20161123558120)(20161123560045)(20161123564045)(20161123562045)(2016111802025)(6072148)(6043046)(201708071742011)(7699016); SRVR:HE1PR0201MB2460; BCL:0; PCL:0; RULEID:; SRVR:HE1PR0201MB2460; X-Microsoft-Exchange-Diagnostics: 1; HE1PR0201MB2460; 4:nzj6XqAVszAkRw8RR4OoL4F1cXVDpHrf+exX5DhN8xHh2XZORKzkClJ+1V7Oj1cTCDUpUKOF4VO81n8C8BxctrHrqZ7d2ngLXRe/HW/TS9ATGqy/Kp9Gp++ps4f7ukE4EtEXOgNuyAjuSlr0SIdptgC5k7o3Gl+GmkiBF8C7AMAOZFOfY9g3rESARuBXyTIzgvylAmtKEU5MKlQc9Lqw9pNOZf8/LjDFOdgMc8rOzHhtA4a3ygdpVN1sH7nPlaFLDPEXo1vp1u5BI9JtYAEMiA== X-Forefront-PRVS: 0753EA505A X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(39830400003)(346002)(396003)(366004)(136003)(376002)(199004)(189003)(2616005)(476003)(16586007)(2361001)(478600001)(11346002)(76176011)(51416003)(4326008)(486006)(47776003)(305945005)(52116002)(25786009)(217873002)(5024004)(54906003)(66066001)(2351001)(446003)(956004)(105586002)(68736007)(36756003)(316002)(106356001)(74482002)(186003)(50226002)(6486002)(97736004)(8936002)(1076002)(386003)(6512007)(7736002)(8676002)(2906002)(3846002)(6116002)(16526019)(53936002)(6506007)(6666003)(50466002)(86362001)(575784001)(26005)(81166006)(81156014)(6916009)(5660300001)(7416002)(48376002)(42262002); DIR:OUT; SFP:1102; SCL:1; SRVR:HE1PR0201MB2460; H:orc.pedanet; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; Received-SPF: None (protection.outlook.com: axentia.se does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; HE1PR0201MB2460; 23:gqnwGaT+CVqvssRRF70LJsAHLGQEACjXosY4eeY?= FOT7cspDxZTeW19fEFcilKVgNd8oGXqPDDUXDZFyAGgicBObnqmi+/BGZNDGq1joAun4nDsLwEPlyQA2PobqwRYGPFWE2HY3E2N4Eh80EtuCBLQUx29TZjskIdfCPefOBfWXpPY9soI+NVYd4bG1Yf2GdU7SMoXvbJ4e8V0ms3E+aPpvByjUyNhLmz9oBJXUyVrGzafVzbxQJMUSjkVKz9gxLonFy6oBwB8S35tM7Yq04W5pyLqYTate8cXQVKYdrsv7v6c3GrCkLPIaWp0gEITiHwReTtkeRiEh4x4Gx9+/FOp8gOpUuqZZUhJlajlebqddGSLa3Xb693UWT2aXBKpZ1xR3u3jhp00VDFFpb+zgCZyjhhTzzKBnLYZk/0ai7C7+q9Szh+HhKNuU1tEkFhNCwTW3397QrAK79yrXoIdDYx7ljSZErNFEKhahFwpWz7fVznJPjLLhm6pQC8FJjbs9wegC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6GvWUV91bS5q7lS9bvCumIHBC9fxofaHECxhY1Fo9y5r7ukvaFJVkVO7oECj1PO SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: axentia.se X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Aug 2018 07:23:31.7368 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b57991bb-42da-479a-82c5-08d5f9120507 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4ee68585-03e1-4785-942a-df9c1871a234 X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0201MB2460 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180803_002347_014975_7813538C X-CRM114-Status: GOOD ( 17.62 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , devicetree@vger.kernel.org, Alexandre Belloni , Andrzej Hajda , David Airlie , Jyri Sarha , dri-devel@lists.freedesktop.org, Russell King - ARM Linux , Boris Brezillon , Rob Herring , Jacopo Mondi , Laurent Pinchart , Daniel Vetter , Peter Rosin , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This beats the heuristic that the connector is involved in what format should be output for cases where this fails. E.g. if there is a bridge that changes format between the encoder and the connector, or if some of the RGB pins between the lcd controller and the encoder are not routed on the PCB. This is critical for the devices that have the "conflicting output formats" issue (SAM9N12, SAM9X5, SAMA5D3), since the most significant RGB bits move around depending on the selected output mode. For devices that do not have the "conflicting output formats" issue (SAMA5D2, SAMA5D4), this is completely irrelevant. Acked-by: Boris Brezillon Signed-off-by: Peter Rosin Reviewed-by: Jacopo Mondi --- drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_crtc.c | 70 +++++++++++++++++------- drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_dc.h | 1 + drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_output.c | 67 ++++++++++++++++++++--- 3 files changed, 111 insertions(+), 27 deletions(-) diff --git a/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_crtc.c b/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_crtc.c index d73281095fac..c38a479ada98 100644 --- a/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_crtc.c +++ b/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_crtc.c @@ -226,6 +226,55 @@ static void atmel_hlcdc_crtc_atomic_enable(struct drm_crtc *c, #define ATMEL_HLCDC_RGB888_OUTPUT BIT(3) #define ATMEL_HLCDC_OUTPUT_MODE_MASK GENMASK(3, 0) +static int atmel_hlcdc_connector_output_mode(struct drm_connector_state *state) +{ + struct drm_connector *connector = state->connector; + struct drm_display_info *info = &connector->display_info; + struct drm_encoder *encoder; + unsigned int supported_fmts = 0; + int j; + + encoder = state->best_encoder; + if (!encoder) + encoder = connector->encoder; + + switch (atmel_hlcdc_encoder_get_bus_fmt(encoder)) { + case 0: + break; + case MEDIA_BUS_FMT_RGB444_1X12: + return ATMEL_HLCDC_RGB444_OUTPUT; + case MEDIA_BUS_FMT_RGB565_1X16: + return ATMEL_HLCDC_RGB565_OUTPUT; + case MEDIA_BUS_FMT_RGB666_1X18: + return ATMEL_HLCDC_RGB666_OUTPUT; + case MEDIA_BUS_FMT_RGB888_1X24: + return ATMEL_HLCDC_RGB888_OUTPUT; + default: + return -EINVAL; + } + + for (j = 0; j < info->num_bus_formats; j++) { + switch (info->bus_formats[j]) { + case MEDIA_BUS_FMT_RGB444_1X12: + supported_fmts |= ATMEL_HLCDC_RGB444_OUTPUT; + break; + case MEDIA_BUS_FMT_RGB565_1X16: + supported_fmts |= ATMEL_HLCDC_RGB565_OUTPUT; + break; + case MEDIA_BUS_FMT_RGB666_1X18: + supported_fmts |= ATMEL_HLCDC_RGB666_OUTPUT; + break; + case MEDIA_BUS_FMT_RGB888_1X24: + supported_fmts |= ATMEL_HLCDC_RGB888_OUTPUT; + break; + default: + break; + } + } + + return supported_fmts; +} + static int atmel_hlcdc_crtc_select_output_mode(struct drm_crtc_state *state) { unsigned int output_fmts = ATMEL_HLCDC_OUTPUT_MODE_MASK; @@ -238,31 +287,12 @@ static int atmel_hlcdc_crtc_select_output_mode(struct drm_crtc_state *state) crtc = drm_crtc_to_atmel_hlcdc_crtc(state->crtc); for_each_new_connector_in_state(state->state, connector, cstate, i) { - struct drm_display_info *info = &connector->display_info; unsigned int supported_fmts = 0; - int j; if (!cstate->crtc) continue; - for (j = 0; j < info->num_bus_formats; j++) { - switch (info->bus_formats[j]) { - case MEDIA_BUS_FMT_RGB444_1X12: - supported_fmts |= ATMEL_HLCDC_RGB444_OUTPUT; - break; - case MEDIA_BUS_FMT_RGB565_1X16: - supported_fmts |= ATMEL_HLCDC_RGB565_OUTPUT; - break; - case MEDIA_BUS_FMT_RGB666_1X18: - supported_fmts |= ATMEL_HLCDC_RGB666_OUTPUT; - break; - case MEDIA_BUS_FMT_RGB888_1X24: - supported_fmts |= ATMEL_HLCDC_RGB888_OUTPUT; - break; - default: - break; - } - } + supported_fmts = atmel_hlcdc_connector_output_mode(cstate); if (crtc->dc->desc->conflicting_output_formats) output_fmts &= supported_fmts; diff --git a/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_dc.h b/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_dc.h index 60c937f42114..4cc1e03f0aee 100644 --- a/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_dc.h +++ b/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_dc.h @@ -441,5 +441,6 @@ void atmel_hlcdc_crtc_irq(struct drm_crtc *c); int atmel_hlcdc_crtc_create(struct drm_device *dev); int atmel_hlcdc_create_outputs(struct drm_device *dev); +int atmel_hlcdc_encoder_get_bus_fmt(struct drm_encoder *encoder); #endif /* DRM_ATMEL_HLCDC_H */ diff --git a/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_output.c b/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_output.c index 8db51fb131db..db4d6aaaef93 100644 --- a/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_output.c +++ b/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_output.c @@ -27,33 +27,86 @@ #include "atmel_hlcdc_dc.h" +struct atmel_hlcdc_rgb_output { + struct drm_encoder encoder; + int bus_fmt; +}; + static const struct drm_encoder_funcs atmel_hlcdc_panel_encoder_funcs = { .destroy = drm_encoder_cleanup, }; +static struct atmel_hlcdc_rgb_output * +atmel_hlcdc_encoder_to_rgb_output(struct drm_encoder *encoder) +{ + return container_of(encoder, struct atmel_hlcdc_rgb_output, encoder); +} + +int atmel_hlcdc_encoder_get_bus_fmt(struct drm_encoder *encoder) +{ + struct atmel_hlcdc_rgb_output *output; + + output = atmel_hlcdc_encoder_to_rgb_output(encoder); + + return output->bus_fmt; +} + +static int atmel_hlcdc_of_bus_fmt(struct device_node *ep) +{ + u32 bus_width = 0; + + of_property_read_u32(ep, "bus-width", &bus_width); + + switch (bus_width) { + case 0: + return 0; + case 12: + return MEDIA_BUS_FMT_RGB444_1X12; + case 16: + return MEDIA_BUS_FMT_RGB565_1X16; + case 18: + return MEDIA_BUS_FMT_RGB666_1X18; + case 24: + return MEDIA_BUS_FMT_RGB888_1X24; + default: + return -EINVAL; + } +} + static int atmel_hlcdc_attach_endpoint(struct drm_device *dev, int endpoint) { - struct drm_encoder *encoder; + struct atmel_hlcdc_rgb_output *output; + struct device_node *ep; struct drm_panel *panel; struct drm_bridge *bridge; int ret; + ep = of_graph_get_endpoint_by_regs(dev->dev->of_node, 0, endpoint); + if (!ep) + return -ENODEV; + ret = drm_of_find_panel_or_bridge(dev->dev->of_node, 0, endpoint, &panel, &bridge); if (ret) return ret; - encoder = devm_kzalloc(dev->dev, sizeof(*encoder), GFP_KERNEL); - if (!encoder) + output = devm_kzalloc(dev->dev, sizeof(*output), GFP_KERNEL); + if (!output) return -EINVAL; - ret = drm_encoder_init(dev, encoder, + output->bus_fmt = atmel_hlcdc_of_bus_fmt(ep); + if (output->bus_fmt < 0) { + dev_err(dev->dev, "invalid bus width\n"); + return -EINVAL; + } + + ret = drm_encoder_init(dev, &output->encoder, &atmel_hlcdc_panel_encoder_funcs, DRM_MODE_ENCODER_NONE, NULL); if (ret) return ret; - encoder->possible_crtcs = 0x1; + output->encoder.possible_crtcs = 0x1; if (panel) { bridge = drm_panel_bridge_add(panel, DRM_MODE_CONNECTOR_Unknown); @@ -62,7 +115,7 @@ static int atmel_hlcdc_attach_endpoint(struct drm_device *dev, int endpoint) } if (bridge) { - ret = drm_bridge_attach(encoder, bridge, NULL); + ret = drm_bridge_attach(&output->encoder, bridge, NULL); if (!ret) return 0; @@ -70,7 +123,7 @@ static int atmel_hlcdc_attach_endpoint(struct drm_device *dev, int endpoint) drm_panel_bridge_remove(bridge); } - drm_encoder_cleanup(encoder); + drm_encoder_cleanup(&output->encoder); return ret; }