From patchwork Fri Aug 3 10:11:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Rosin X-Patchwork-Id: 10554923 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 6D001157D for ; Fri, 3 Aug 2018 10:20:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 596362B31F for ; Fri, 3 Aug 2018 10:20:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4CB772C07C; Fri, 3 Aug 2018 10:20:42 +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 961C92B31F for ; Fri, 3 Aug 2018 10:20:41 +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=V2xS48Ror6b5Kj27KYkpXEkfCE7i2Kx8WYSPnzN75B8=; b=u5lsp+C7RA96uY UTiKUQn1QG5c49pB8eokeZFqXQ3VdN3DmtB1xAenfwHdXOznE2D59715uuJjbyuyuAfFgp1TxAbMo WYCPdRNW/ubvm1jprh1nPf1CxR49zNBlX9KDhsnMnt0G8a+/vhEIHmFJ6jwekLj5U8sV4mGifs6ex OaS3aexUwEggk47I5MToiixGk4tAvn56ncJsUpYCTGFvL6LQnaVnEZ6WwGKI6+wVJa5gnBAgsK4dR OfV2OOWUV/6G+aKZdQkSxfMUQUTIsSNDlIEW6dxSAH39v0N01ccrEWEQa8z3cM/xThgB1z9QagUrG 1tEreOrqtJ7qr7+aKxHw==; 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 1flXCH-0006tZ-N6; Fri, 03 Aug 2018 10:20:37 +0000 Received: from mail-he1eur01on0728.outbound.protection.outlook.com ([2a01:111:f400:fe1e::728] helo=EUR01-HE1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1flX3v-00025j-LO for linux-arm-kernel@lists.infradead.org; Fri, 03 Aug 2018 10:12:06 +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=QR1K3Y7YCs8AAB6dEQK7G40bpwip1E6XqXJRMNXOwUM=; b=iYdmFIkZFvR1SMmOD9eTlt6gdV8/FGzuFZACQRt91mBoeriL6kdSEKXu2qINFodMOLDsb+5UhD35/6hA3/T7fd7GfrsbyTO9VfCl6B3D9pEfD7KjmnNbzylfIOaas1Pjj6lP5kYyB5t6ajo2w1JfYUt3CQeC+DXfLVbAfRHGG9U= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=peda@axentia.se; Received: from orc.pedanet (85.226.244.23) by DB6PR0201MB2456.eurprd02.prod.outlook.com (2603:10a6:4:35::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.995.21; Fri, 3 Aug 2018 10:11:47 +0000 From: Peter Rosin To: linux-kernel@vger.kernel.org Subject: [PATCH v6 3/3] drm/atmel-hlcdc: support bus-width (12/16/18/24) in endpoint nodes Date: Fri, 3 Aug 2018 12:11:24 +0200 Message-Id: <20180803101124.4622-4-peda@axentia.se> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180803101124.4622-1-peda@axentia.se> References: <20180803101124.4622-1-peda@axentia.se> MIME-Version: 1.0 X-Originating-IP: [85.226.244.23] X-ClientProxiedBy: AM6PR0202CA0003.eurprd02.prod.outlook.com (2603:10a6:209:15::16) To DB6PR0201MB2456.eurprd02.prod.outlook.com (2603:10a6:4:35::8) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5609ba86-a425-47e7-6ef3-08d5f9298633 X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(7021125)(8989117)(5600074)(711020)(4534165)(7022125)(4603075)(4627221)(201702281549075)(8990107)(7048125)(7024125)(7027125)(7028125)(7023125)(2017052603328)(7153060)(7193020); SRVR:DB6PR0201MB2456; X-Microsoft-Exchange-Diagnostics: 1; DB6PR0201MB2456; 3:vn5ItCtcoYpfTBKlFY78eqsXDAmCnzPp/UdYZGzw/q05ZnRj+QocLe9+nVE6PBj8AOXZ+JfvBQZrLrnkjhhRvqTcEe+dQduIXRjn2Qe6JALyydRMpQCMSrnI6cojuIhORdQXSiNK5bFHx06Xab2OilzXToZgbqmHoYbWZsxVpmp8/pFce5VXO6E+PIcTHIaUl5sG+0cFEDFYhQ/tsePyrUB4iM7XD7z7J+9u781rJAh/hgnA/sJ6DkaBM8PpDhcq; 25:ipBJkJ6Ss1P9xb9Al04KymY/CzmZJaDxGZ5PI9KTteBYjZjYmjgGKnkcgscToYtxXCFI1V7UNjhE3OvqMakDObNhrq1gVpj37BdhabFcWcnfC4KoexsxJBhktW5z2VAFKtvtFDrFDld2yf013KjEhRofw7ibCa3Cg6sEPH6w3WjFEKvXka2syddb9eqk6jlZAc5daM6urUkc6721HmgGg7RlEEs8kPBBM7mFKqEC+6olhWBESYWocpNOXfxyco9JchFd9PpKudKJ2VmOaD5+YeIryJrspNOgqdCOetGqQG7ooJv5oCaiLxk0dFxrht4BabSpQoGz8bzeUKOZ7gUg5w==; 31:hW4/6okyLxgmvMWBfma5sfcVKMj6zsSrJd8wNs1BqdtJV1CPTlDjPLZ+melDm1D8YK4h7yQyO8bv2/jsHMBg1NXWoxzC4FhfDNjYIHUpm6BdltkM9/NetZknK7AofAgCzPGVhoo6Rmq2fw6GIFhnXzRkh96C8goD5xq2VrRLwejJG51oa7wOju1el3oBHZfBputQKUNttY7pI0EDKOoR5zhwC5LxcrmxJraYPe4v4ks= X-MS-TrafficTypeDiagnostic: DB6PR0201MB2456: 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)(10201501046)(3231311)(944501410)(52105095)(3002001)(93006095)(93001095)(149027)(150027)(6041310)(20161123560045)(20161123558120)(20161123562045)(2016111802025)(20161123564045)(6043046)(6072148)(201708071742011)(7699016); SRVR:DB6PR0201MB2456; BCL:0; PCL:0; RULEID:; SRVR:DB6PR0201MB2456; X-Microsoft-Exchange-Diagnostics: 1; DB6PR0201MB2456; 4:VD0naKv+uroVPk2wyCC40T+Y81Qo8agWFw1VehzhUDruHPQA9LvbxelNtK6FCTFP2paEETdbUwaEU6xAlz5e8UnwS6KcZ+hJj9j3kpPbCzllK2i0nSsAUqMF9+U0INUhbAG1wDq49BEaIoI1Qhydqon4w0L754SflT579O1PymqeDzK2fFlv1gR2ox8a++hq3EUdcb2fB1l2famnt+W+2J5tqU/ZqoJy73syZop/b7mDNMiTKkAOkCuctMG7S+PJpkocqwlIRZQVMjWJd3LE1A== X-Forefront-PRVS: 0753EA505A X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(366004)(346002)(39840400004)(396003)(376002)(136003)(189003)(199004)(386003)(25786009)(3846002)(5024004)(476003)(956004)(2616005)(2906002)(16526019)(74482002)(36756003)(7416002)(1076002)(486006)(446003)(86362001)(575784001)(26005)(105586002)(186003)(11346002)(97736004)(305945005)(106356001)(6116002)(6506007)(5660300001)(66066001)(8676002)(2361001)(6666003)(81156014)(6512007)(68736007)(47776003)(7736002)(81166006)(54906003)(478600001)(2351001)(8936002)(53936002)(48376002)(16586007)(76176011)(52116002)(51416003)(6916009)(50466002)(6486002)(50226002)(4326008)(316002)(42262002); DIR:OUT; SFP:1102; SCL:1; SRVR:DB6PR0201MB2456; H:orc.pedanet; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; Received-SPF: None (protection.outlook.com: axentia.se does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DB6PR0201MB2456; 23:YDOmSsDOe6ehwaaa/rlvFqNYKyu1+yCbTy3Xnsx?= IVXpJhmCqxfFPufVKvBpyXc65AzDGoxPueJiS2TzXOWYSvC0Wg/SC0hShcDU03VWhhaaM2NQ1ki1ej9WebIu4Dny0mNJUEIQ2ecIKTvUNnoe3YYQ/KyrTbS8TK70l+aHaHNeZk6TlyujdQ/e2rjPDKXkrovZ/uNoHmaqV/IIvnBsVZsl+8iprHdXEqALyx6MwR6LSBhpLoj1xKJ28MwpqVCEfRs0f4dNUrps97kjKYZzFg8KIqXmS74na+pyM3rIzDJBe5WBdoB/RL6ya3/b20/Y3V/VLV4yORjT1I7JXmdMKHwuDSvOezfBS/B0zeMsIROcc3ZesKDVtlBUCMVxVcU5N+2PCPyFth7E1TDtwoT/kTfjsy2zpC/ORfxaPt04czApCgvAMjG+EUVVl6QhOvHljHC+wjKQebeblRdajaSqcO2FG5A2kY/vm098b+FdrRNvpzVmMQni8g1v3DoMzEZGIIRZwhhbRPAfd3OF8MmvJ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N9RtQ42Spv1OIzQrzy54 SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: axentia.se X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Aug 2018 10:11:47.4848 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5609ba86-a425-47e7-6ef3-08d5f9298633 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4ee68585-03e1-4785-942a-df9c1871a234 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0201MB2456 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180803_031200_585133_355740AE X-CRM114-Status: GOOD ( 17.79 ) 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 , Sakari Ailus , 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 Reviewed-by: Jacopo Mondi Signed-off-by: Peter Rosin --- 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 | 70 +++++++++++++++++++++--- 3 files changed, 114 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..f587ae596791 100644 --- a/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_output.c +++ b/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_output.c @@ -27,33 +27,89 @@ #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; + int ret; + + ret = of_property_read_u32(ep, "bus-width", &bus_width); + if (ret == -EINVAL) + return 0; + if (ret) + return ret; + + switch (bus_width) { + 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 +118,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 +126,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; }