From patchwork Thu Oct 13 11:04:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pin-yen Lin X-Patchwork-Id: 2018 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp207579wrs; Thu, 13 Oct 2022 04:06:58 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7ScX3Ojl2S+SUU0SgD4Eg8YgxKHZLCAqH5nASty2v5x49yAYFhAJyY89qeAb2K/LNUVNZn X-Received: by 2002:a05:6402:357:b0:458:5cb6:f587 with SMTP id r23-20020a056402035700b004585cb6f587mr31916296edw.183.1665659217991; Thu, 13 Oct 2022 04:06:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665659217; cv=none; d=google.com; s=arc-20160816; b=Xz9Bs1NVZ2xsCiv7tgCFMFrdHjLLMORDm81839MS0u8ZsiiwcLBpDUlbTNQvRL0Z4U Gy4F6SDYcBogi3EvGmIbtY0q720Px/WfMhZGGhUxrseCUt4Bvdf+b0yOwXA1DaxTdk0L ExfMhPHWiBBJbo9/4qIawqs2FZMHvwzgr1c7mwHRXpAJkzTqSkmK5Z7yIYfioGn7jbRW HmR0Us0qOwEkq02JHLGiuCCaAoy6xWSEq+xSf4xl4BLNQNXcvJbnAzJG9coEFoOPyJlr SD+qOPckVifNBAuxaTCuI5WWQ35s1RBhii56Nua0AwNzoyR4cciPyNzEAHl6Gl+RUOJP wbqA== 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 :dkim-signature; bh=BptX1vlVcNHP5LWvhu8S2NjiO9ee4jWe/KGbor9Uaxo=; b=ZUklv50xN7H0DFtPT0FwiKKTa7ZgY2oy8IGNCILyJR9CTmWGcVWA7c/jLycF7JZjha DEv3uEit4iTih3BT4EXdNHhkJdC52nGJnsRK78F5nzUWHM1405EdzYclkWzYSFiwzK4l KhiPd0pvWMLTyRlwidWVvwM0h5gO6iggIYTVqd6wWm2KFgicPog2SUARedkHIsTlSBiA cO7lvg4NOvG9pSoogWPwDFGkqstQaJYlR84QipPq4iVhgYIeXbrJl6ZalRQKam/vSJ4S 7NuBKkzPesZtwxHJrF7Jb078Hp8PushzrLE6oB5de9yoNw90zp7qWzHV5+ISDir6Gjpw 5c0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=IjO7mPYp; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nd16-20020a170907629000b0077bc1269f8esi18861311ejc.424.2022.10.13.04.06.26; Thu, 13 Oct 2022 04:06:57 -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; dkim=pass header.i=@chromium.org header.s=google header.b=IjO7mPYp; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229619AbiJMLEa (ORCPT + 99 others); Thu, 13 Oct 2022 07:04:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229554AbiJMLEY (ORCPT ); Thu, 13 Oct 2022 07:04:24 -0400 Received: from mail-pg1-x533.google.com (mail-pg1-x533.google.com [IPv6:2607:f8b0:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1BF4610B7B3 for ; Thu, 13 Oct 2022 04:04:23 -0700 (PDT) Received: by mail-pg1-x533.google.com with SMTP id bh13so1264707pgb.4 for ; Thu, 13 Oct 2022 04:04:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=BptX1vlVcNHP5LWvhu8S2NjiO9ee4jWe/KGbor9Uaxo=; b=IjO7mPYpHNOk7l0IwChYojbxdMe0w7AtfsioruRTxng85gyCJNgkqJnFCxndp4y7CF LmqkG0MoozuBvOalP282o4s4e+MTQ5av6B5oaw8LvDe0Sbi6JKY3IsvlYNw+/irSHaoK /rpzoM8YRjbt815iGMAdUlEYWZVUMlSH94ac8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BptX1vlVcNHP5LWvhu8S2NjiO9ee4jWe/KGbor9Uaxo=; b=xiR6Gn6qG9yvvqWtA+PpkF8zKMcYB7Zo8iMNt4MxrfCug8kDozlTiYfRSqKhE2z/rW aH5xyGBIbZT3wy8Y7GokzoC0s4c+UgYvbY4vnbKmMrX+qJfJecVbuXglBrwLkXka19MK 6v/dBEr0c9MQiR3f/80JvTxondxkSslUt+BMBKVG1XO8uF1GYcooYwI0HL/+7B997GiP 7QcXsxYloxWSXPyWWNO7QdnwEH7hA4tbIq/HWteyuWcJsrDVnigJCXr+/O03pAHaNV79 awVkwyWdfpn14LRa5UdZ6Banq1XNjCU1pc+b1CXKMPGKUwzmr397254Km5mjvCsH0XX4 O+TA== X-Gm-Message-State: ACrzQf11jbjLa8rOR5kJkyX02QjAWCg7m7YFNidUGNbrM8szcV79TgoM 2+l0JBXfNH5ULtj1hEHMAPBSBABJVOeFgg== X-Received: by 2002:a63:2cc2:0:b0:41c:681d:60d2 with SMTP id s185-20020a632cc2000000b0041c681d60d2mr28700706pgs.502.1665659062636; Thu, 13 Oct 2022 04:04:22 -0700 (PDT) Received: from treapking.tpe.corp.google.com ([2401:fa00:1:10:4b90:18ed:8d41:7622]) by smtp.gmail.com with ESMTPSA id o11-20020a17090ab88b00b0020af2411721sm2914794pjr.34.2022.10.13.04.04.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 04:04:22 -0700 (PDT) From: Pin-yen Lin To: Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , David Airlie , Daniel Vetter Cc: Pin-yen Lin , Allen Chen , AngeloGioacchino Del Regno , Hermes Wu , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/3] drm/bridge: it6505: Initialize AUX channel in it6505_i2c_probe Date: Thu, 13 Oct 2022 19:04:08 +0800 Message-Id: <20221013110411.1674359-2-treapking@chromium.org> X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog In-Reply-To: <20221013110411.1674359-1-treapking@chromium.org> References: <20221013110411.1674359-1-treapking@chromium.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746570280338956103?= X-GMAIL-MSGID: =?utf-8?q?1746570280338956103?= During device boot, the HPD interrupt could be triggered before the DRM subsystem registers it6505 as a DRM bridge. In such cases, the driver tries to access AUX channel and causes NULL pointer dereference. Initializing the AUX channel earlier to prevent such error. Fixes: b5c84a9edcd4 ("drm/bridge: add it6505 driver") Signed-off-by: Pin-yen Lin Reviewed-by: Robert Foss --- (no changes since v1) drivers/gpu/drm/bridge/ite-it6505.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/bridge/ite-it6505.c b/drivers/gpu/drm/bridge/ite-it6505.c index a4302492cf8d..f7f6c3e20fae 100644 --- a/drivers/gpu/drm/bridge/ite-it6505.c +++ b/drivers/gpu/drm/bridge/ite-it6505.c @@ -2871,10 +2871,7 @@ static int it6505_bridge_attach(struct drm_bridge *bridge, } /* Register aux channel */ - it6505->aux.name = "DP-AUX"; - it6505->aux.dev = dev; it6505->aux.drm_dev = bridge->dev; - it6505->aux.transfer = it6505_aux_transfer; ret = drm_dp_aux_register(&it6505->aux); @@ -3354,6 +3351,11 @@ static int it6505_i2c_probe(struct i2c_client *client, debugfs_init(it6505); pm_runtime_enable(dev); + it6505->aux.name = "DP-AUX"; + it6505->aux.dev = dev; + it6505->aux.transfer = it6505_aux_transfer; + drm_dp_aux_init(&it6505->aux); + it6505->bridge.funcs = &it6505_bridge_funcs; it6505->bridge.type = DRM_MODE_CONNECTOR_DisplayPort; it6505->bridge.ops = DRM_BRIDGE_OP_DETECT | DRM_BRIDGE_OP_EDID | From patchwork Thu Oct 13 11:04:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pin-yen Lin X-Patchwork-Id: 2019 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp207852wrs; Thu, 13 Oct 2022 04:07:26 -0700 (PDT) X-Google-Smtp-Source: AMsMyM70Ildy2TqeaGJZJBD4WGaZCKtoUQL7JojFjPJkrGEbta/RCAs4MdFbqTIfr4ccYJ149nEy X-Received: by 2002:a17:907:6eab:b0:78d:4c16:a687 with SMTP id sh43-20020a1709076eab00b0078d4c16a687mr25848307ejc.392.1665659246468; Thu, 13 Oct 2022 04:07:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665659246; cv=none; d=google.com; s=arc-20160816; b=bS9MtGZaRUTkIgbil9l+RPRUeNoKbXggrcTaTl+bVPY6q6n7TMdHWT4aBrLM+j86GN JyC6CDGYmAlpl8cVjQ87hUx5505lFbyCWd/+YOi8p8AE7W53ud0JIiBlWsQ1hheW2CRP YdmMOk/FBfNHXMHSCZGcRYH1TJJ3eMY4kkJIpBoXpc1GFyicdfHxfDE1dYAFQ8gxBAf2 zXWaefNzZ5ua+osUvQQW0xemkEoXyFGoIZzxpgYMJnxH7rLPBV1rhStyJfEDY/GaSI2/ W09+5JC9L19sh2ZmMRtXJC6GQjoJ+GD1Qc+MVmMpQ6lAwP4vvDI+r09ujipgOm08lcTa E43g== 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 :dkim-signature; bh=EYXJKMiQJ4PCw73TzI+ObZcy3XsnxrjgsDmU8SHv3n4=; b=EJqAdclHZlGgDIInN6xwogfSMoUIs8K95dJtLvQUFj8N4SyoosTydbdbj0Xwc64ekM zDsWdYQTZyidZTOYzAeeZhAw/7Ntmy6Vk1X5MQrvpQ0rQjBAT/W+64Pl98nJ2y2S05uU de8QcIRX50geXDscbPP40fr73dYbpkzheGlJIOYooXw5vQgi1A38iRVaj2c+pdzj4hS1 XE7lLz2R1Fuxg9U1f/zhzzeldwE59PNiyQ044+0BvFM9BvOV59h57BnsDFdPo9KsG3R7 7+MYtoh8foBEZVHlIgRphMWqrsYpdTs+TZHNWHCyUzJM3UlSzG/8DCutxpBaQcp+2Iwt tKOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=i+v3uGLf; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r15-20020aa7da0f000000b00459c448d32csi14667275eds.446.2022.10.13.04.06.58; Thu, 13 Oct 2022 04:07:26 -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; dkim=pass header.i=@chromium.org header.s=google header.b=i+v3uGLf; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229598AbiJMLEe (ORCPT + 99 others); Thu, 13 Oct 2022 07:04:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229437AbiJMLE2 (ORCPT ); Thu, 13 Oct 2022 07:04:28 -0400 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE23A10B785 for ; Thu, 13 Oct 2022 04:04:27 -0700 (PDT) Received: by mail-pj1-x102d.google.com with SMTP id a6-20020a17090abe0600b0020d7c0c6650so4636844pjs.0 for ; Thu, 13 Oct 2022 04:04:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=EYXJKMiQJ4PCw73TzI+ObZcy3XsnxrjgsDmU8SHv3n4=; b=i+v3uGLfxi76/KZh6GQhp6XyoYwQZqCvqQ936yd1CA565biHsX/Aow6gZdo9RfCLym DAxYk4wr6Oe76tPOGXRh8u9godGzap7LlYktW9HuvakC1jam47Hq4SLD/j892SxD/sXU koYKEF4tO5MW2wVnz6HdPJLVQAHzHFyCLNdYE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EYXJKMiQJ4PCw73TzI+ObZcy3XsnxrjgsDmU8SHv3n4=; b=SwTemLTdOyrcqhvol/s321s+83JdTj2YH3TvIzaN5Jkp5SMJ2B0dzdFwt1VtqgcxuD uFozuZnmlp8fdj+2RT+2y3/MrWQZEHR31fEU2v/HY5tHN13KdkPtX4/wYuiuGYOYH2oV gpTu0XDaacgMcHBxygnfOsbjFzmkr4YjgnVfWirw5eDjgk5JFs2EiAUUq1KwAjHSB6Ur BSN4v5nsulYerVIFppgxC9fMOB4qo7ypwnnsj8vra302NSJKDz7q2olAisxRiX6nL4i0 zxphRdtAYp63WogEfbVnoXBIuDUyTMwcpiQV2Mw99DAlg2QBlg0NU5NaRPRjrL9bb2eG ZB5A== X-Gm-Message-State: ACrzQf03jNwGWHvo0Ey/qeHhFILbkyXgqMz52uZm/yubvJ7CvnQ6ww9S ji12U6In4ov2YDZs7TKx4FVBPw== X-Received: by 2002:a17:90b:4d05:b0:202:ec78:9d73 with SMTP id mw5-20020a17090b4d0500b00202ec789d73mr10606717pjb.103.1665659067240; Thu, 13 Oct 2022 04:04:27 -0700 (PDT) Received: from treapking.tpe.corp.google.com ([2401:fa00:1:10:4b90:18ed:8d41:7622]) by smtp.gmail.com with ESMTPSA id o11-20020a17090ab88b00b0020af2411721sm2914794pjr.34.2022.10.13.04.04.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 04:04:26 -0700 (PDT) From: Pin-yen Lin To: Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , David Airlie , Daniel Vetter Cc: Pin-yen Lin , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/3] drm/bridge: it6505: Setup links in it6505_irq_hpd Date: Thu, 13 Oct 2022 19:04:09 +0800 Message-Id: <20221013110411.1674359-3-treapking@chromium.org> X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog In-Reply-To: <20221013110411.1674359-1-treapking@chromium.org> References: <20221013110411.1674359-1-treapking@chromium.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746570309921591845?= X-GMAIL-MSGID: =?utf-8?q?1746570309921591845?= Move the DPCD read and link setup steps to HPD IRQ handler to remove an unnecessary dependency between .detect callback and the HPD IRQ handler before registering it6505 as a DRM bridge. This is safe because there is always a .detect call after each HPD IRQ handler triggered by the drm_helper_hpd_irq_event call. Signed-off-by: Pin-yen Lin Reviewed-by: Robert Foss --- Changes in v2: - Remove redundant spaces in it6505_detect - Read sink count in it6505_irq_hpd drivers/gpu/drm/bridge/ite-it6505.c | 80 +++++++++++++---------------- 1 file changed, 35 insertions(+), 45 deletions(-) diff --git a/drivers/gpu/drm/bridge/ite-it6505.c b/drivers/gpu/drm/bridge/ite-it6505.c index f7f6c3e20fae..4b6061272599 100644 --- a/drivers/gpu/drm/bridge/ite-it6505.c +++ b/drivers/gpu/drm/bridge/ite-it6505.c @@ -725,28 +725,6 @@ static void it6505_calc_video_info(struct it6505 *it6505) DRM_MODE_ARG(&it6505->video_info)); } -static int it6505_drm_dp_link_probe(struct drm_dp_aux *aux, - struct it6505_drm_dp_link *link) -{ - u8 values[3]; - int err; - - memset(link, 0, sizeof(*link)); - - err = drm_dp_dpcd_read(aux, DP_DPCD_REV, values, sizeof(values)); - if (err < 0) - return err; - - link->revision = values[0]; - link->rate = drm_dp_bw_code_to_link_rate(values[1]); - link->num_lanes = values[2] & DP_MAX_LANE_COUNT_MASK; - - if (values[2] & DP_ENHANCED_FRAME_CAP) - link->capabilities = DP_ENHANCED_FRAME_CAP; - - return 0; -} - static int it6505_drm_dp_link_set_power(struct drm_dp_aux *aux, struct it6505_drm_dp_link *link, u8 mode) @@ -1456,11 +1434,19 @@ static void it6505_parse_link_capabilities(struct it6505 *it6505) int bcaps; if (it6505->dpcd[0] == 0) { - it6505_aux_on(it6505); - it6505_get_dpcd(it6505, DP_DPCD_REV, it6505->dpcd, - ARRAY_SIZE(it6505->dpcd)); + dev_err(dev, "DPCD is not initialized"); + return; } + memset(link, 0, sizeof(*link)); + + link->revision = it6505->dpcd[0]; + link->rate = drm_dp_bw_code_to_link_rate(it6505->dpcd[1]); + link->num_lanes = it6505->dpcd[2] & DP_MAX_LANE_COUNT_MASK; + + if (it6505->dpcd[2] & DP_ENHANCED_FRAME_CAP) + link->capabilities = DP_ENHANCED_FRAME_CAP; + DRM_DEV_DEBUG_DRIVER(dev, "DPCD Rev.: %d.%d", link->revision >> 4, link->revision & 0x0F); @@ -2323,19 +2309,32 @@ static int it6505_process_hpd_irq(struct it6505 *it6505) static void it6505_irq_hpd(struct it6505 *it6505) { struct device *dev = &it6505->client->dev; + int dp_sink_count; it6505->hpd_state = it6505_get_sink_hpd_status(it6505); DRM_DEV_DEBUG_DRIVER(dev, "hpd change interrupt, change to %s", it6505->hpd_state ? "high" : "low"); - if (it6505->bridge.dev) - drm_helper_hpd_irq_event(it6505->bridge.dev); - DRM_DEV_DEBUG_DRIVER(dev, "it6505->sink_count: %d", - it6505->sink_count); - if (it6505->hpd_state) { wait_for_completion_timeout(&it6505->wait_edid_complete, msecs_to_jiffies(6000)); + it6505_aux_on(it6505); + if (it6505->dpcd[0] == 0) { + it6505_get_dpcd(it6505, DP_DPCD_REV, it6505->dpcd, + ARRAY_SIZE(it6505->dpcd)); + it6505_variable_config(it6505); + it6505_parse_link_capabilities(it6505); + } + it6505->auto_train_retry = AUTO_TRAIN_RETRY; + + it6505_drm_dp_link_set_power(&it6505->aux, &it6505->link, + DP_SET_POWER_D0); + dp_sink_count = it6505_dpcd_read(it6505, DP_SINK_COUNT); + it6505->sink_count = DP_GET_SINK_COUNT(dp_sink_count); + + DRM_DEV_DEBUG_DRIVER(dev, "it6505->sink_count: %d", + it6505->sink_count); + it6505_lane_termination_on(it6505); it6505_lane_power_on(it6505); @@ -2363,6 +2362,9 @@ static void it6505_irq_hpd(struct it6505 *it6505) it6505_lane_off(it6505); it6505_link_reset_step_train(it6505); } + + if (it6505->bridge.dev) + drm_helper_hpd_irq_event(it6505->bridge.dev); } static void it6505_irq_hpd_irq(struct it6505 *it6505) @@ -2625,26 +2627,14 @@ static enum drm_connector_status it6505_detect(struct it6505 *it6505) goto unlock; if (it6505->enable_drv_hold) { - status = it6505_get_sink_hpd_status(it6505) ? - connector_status_connected : - connector_status_disconnected; + status = it6505->hpd_state ? connector_status_connected : + connector_status_disconnected; goto unlock; } - if (it6505_get_sink_hpd_status(it6505)) { - it6505_aux_on(it6505); - it6505_drm_dp_link_probe(&it6505->aux, &it6505->link); + if (it6505->hpd_state) { it6505_drm_dp_link_set_power(&it6505->aux, &it6505->link, DP_SET_POWER_D0); - it6505->auto_train_retry = AUTO_TRAIN_RETRY; - - if (it6505->dpcd[0] == 0) { - it6505_get_dpcd(it6505, DP_DPCD_REV, it6505->dpcd, - ARRAY_SIZE(it6505->dpcd)); - it6505_variable_config(it6505); - it6505_parse_link_capabilities(it6505); - } - dp_sink_count = it6505_dpcd_read(it6505, DP_SINK_COUNT); it6505->sink_count = DP_GET_SINK_COUNT(dp_sink_count); DRM_DEV_DEBUG_DRIVER(dev, "it6505->sink_count:%d branch:%d", From patchwork Thu Oct 13 11:04:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pin-yen Lin X-Patchwork-Id: 2020 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp207918wrs; Thu, 13 Oct 2022 04:07:35 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6pdZ86FQf/3snxj6Kj56a9wj0Rru2FpPY7ooNJYhbVGUxYIADeVKZsMzzZrSfZ9dEyXILq X-Received: by 2002:a17:906:db0a:b0:781:f24:a782 with SMTP id xj10-20020a170906db0a00b007810f24a782mr25837447ejb.399.1665659255150; Thu, 13 Oct 2022 04:07:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665659255; cv=none; d=google.com; s=arc-20160816; b=eP4FppWGSB678y1ql+t2WblyHp8J7Un6rnk/fx85+N63UqKTRN0wTtvuvFJHiKTx4J v5SOnsi0ZJpoq/wASAXDD24WL34vz8e7kiWG5gtgDDW0YYyMWRToqNZcCgo7vZ9kV4O/ PbP8yzqHdBy6VTZUUFy3RiS5bOzVUzV9vBSWj4YkE30osVTiLQpvcDKI2n5fbOlSE8pe LvtaxRjIw750zKvRoffb6RsEPBIDWFLI+EF78aNDPecQIQx0BOqfGpYGKA3q//jSntLv Yl9HZjzTi33dXjXRlKLw2dHmC5ON/m44YkET27IvrIuRIb+cbJ0DOgEmloMNth3/xzrq biJA== 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 :dkim-signature; bh=0yF0qS9tpjnO5hKItBT5kTiggjtXt00AKvk0lGYLixs=; b=IXfNmi1qzimsWitT7mp4Yi+ZkeHb9eqf/NqBvXx0toSPr133FqQiPTmiVojxOluN6W bMdiCAjkD89Rnl+T+7NMgfR5uRYBEkpY/w4lH1//XMkQzcKGbcQIjuUuhL91b2hjNI2O bqsxj2GxYWkCUIcQFshNG9/UEfAN0za/W1zP7EKovjc8Ws0at2zZbPIuncLTmeTesGDG GpIenUclaSg/s0KpoYlgGRODG5GmGNY7ILEOHAVNt9hFyKSA2oKlyhTfyJpCgN8LV2x8 K12Gfnv/uicJ37Wbbyy5wtXss/KvqrD5ngPvT6TDyoSj5yuk+/d/BYptDe4ssrf3NR4R 4SsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=lBd+WLaz; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id xf4-20020a17090731c400b0078d9b2facaesi16039119ejb.339.2022.10.13.04.07.08; Thu, 13 Oct 2022 04:07:35 -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; dkim=pass header.i=@chromium.org header.s=google header.b=lBd+WLaz; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229658AbiJMLEj (ORCPT + 99 others); Thu, 13 Oct 2022 07:04:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229635AbiJMLEd (ORCPT ); Thu, 13 Oct 2022 07:04:33 -0400 Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B687710CFB9 for ; Thu, 13 Oct 2022 04:04:31 -0700 (PDT) Received: by mail-pj1-x1031.google.com with SMTP id q10-20020a17090a304a00b0020b1d5f6975so1622053pjl.0 for ; Thu, 13 Oct 2022 04:04:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0yF0qS9tpjnO5hKItBT5kTiggjtXt00AKvk0lGYLixs=; b=lBd+WLazCAhdHwvY2Ydhae9hCVMbvMx0M3hb3hy0vujF2bvWl0gPMyEqZGHGXh6OVj sUYmtigt3bUR5i8ZVQ/KOl9sCb04tIaF2JW0rkmxBPvMGSHvtV2TTinTDMwaqiOky0cf +FVbSuyM3Ll7gEXcjrLD37S0ElVORRerxb+R8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0yF0qS9tpjnO5hKItBT5kTiggjtXt00AKvk0lGYLixs=; b=fSr8f22TxnGgiZBbprOvGqXIgqhFZ55VedIlfLz/jlK5frIwVH5DqFkc4q5qxVy+OJ rvHeuIuq+z9B3LKzrMwHYlFqOtnl5f7sjPa2kj8thYCIIS3QV7xIHAou1KsJ7rjdSVmV NmyWx7qAMxyKr8c1NxUM84z7TV73mI18g+kjn4o3VJ3NcAfoSha3WAZZuobCqLRiy/IM H2FG2VFrtOvlHO9XsqKqwcNhvzRuL3LDtgpsaneQZqnGWycCMe/wueWbPuhj6+x1K8z0 oiNJ7WZ40d/vqEbAOPGxZxq/1Mx2Dygbx+aVGnWwFOZjRsdwDiy/Ntscmn8xy1ZHpxsl HsFg== X-Gm-Message-State: ACrzQf0UUwSRge+PK+pKdiD5oJTVa3woOsAyR0RWoDBxT4YELJ3GMHQD nctrX7Ht9zMqZEwisHiGsUYn4nPdlvdIoQ== X-Received: by 2002:a17:90b:4b8b:b0:20d:ac2f:8bb2 with SMTP id lr11-20020a17090b4b8b00b0020dac2f8bb2mr1353420pjb.194.1665659070952; Thu, 13 Oct 2022 04:04:30 -0700 (PDT) Received: from treapking.tpe.corp.google.com ([2401:fa00:1:10:4b90:18ed:8d41:7622]) by smtp.gmail.com with ESMTPSA id o11-20020a17090ab88b00b0020af2411721sm2914794pjr.34.2022.10.13.04.04.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 04:04:30 -0700 (PDT) From: Pin-yen Lin To: Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , David Airlie , Daniel Vetter Cc: Pin-yen Lin , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/3] drm/bridge: it6505: Improve synchronization between extcon subsystem Date: Thu, 13 Oct 2022 19:04:10 +0800 Message-Id: <20221013110411.1674359-4-treapking@chromium.org> X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog In-Reply-To: <20221013110411.1674359-1-treapking@chromium.org> References: <20221013110411.1674359-1-treapking@chromium.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746570318926725520?= X-GMAIL-MSGID: =?utf-8?q?1746570318926725520?= Originally, the it6505 relies on a short sleep in the IRQ handler and a long sleep to make sure it6505->lane_swap and it6505->lane_count is configured in it6505_extcon_work and it6505_detect, respectively. Use completion and additional DPCD read to remove the unnecessary waits, and use a different lock for it6505_extcon_work and the threaded IRQ handler because they no longer need to run exclusively. The wait time of the completion is usually less than 10ms in local experiments, but leave it larger here just in case. Signed-off-by: Pin-yen Lin Reviewed-by: Robert Foss --- Changes in v2: - Add the empty line back drivers/gpu/drm/bridge/ite-it6505.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/drm/bridge/ite-it6505.c b/drivers/gpu/drm/bridge/ite-it6505.c index 4b6061272599..0de44c651c60 100644 --- a/drivers/gpu/drm/bridge/ite-it6505.c +++ b/drivers/gpu/drm/bridge/ite-it6505.c @@ -412,6 +412,7 @@ struct it6505 { * Mutex protects extcon and interrupt functions from interfering * each other. */ + struct mutex irq_lock; struct mutex extcon_lock; struct mutex mode_lock; /* used to bridge_detect */ struct mutex aux_lock; /* used to aux data transfers */ @@ -440,7 +441,7 @@ struct it6505 { enum hdcp_state hdcp_status; struct delayed_work hdcp_work; struct work_struct hdcp_wait_ksv_list; - struct completion wait_edid_complete; + struct completion extcon_completion; u8 auto_train_retry; bool hdcp_desired; bool is_repeater; @@ -2316,8 +2317,8 @@ static void it6505_irq_hpd(struct it6505 *it6505) it6505->hpd_state ? "high" : "low"); if (it6505->hpd_state) { - wait_for_completion_timeout(&it6505->wait_edid_complete, - msecs_to_jiffies(6000)); + wait_for_completion_timeout(&it6505->extcon_completion, + msecs_to_jiffies(1000)); it6505_aux_on(it6505); if (it6505->dpcd[0] == 0) { it6505_get_dpcd(it6505, DP_DPCD_REV, it6505->dpcd, @@ -2493,8 +2494,7 @@ static irqreturn_t it6505_int_threaded_handler(int unused, void *data) }; int int_status[3], i; - msleep(100); - mutex_lock(&it6505->extcon_lock); + mutex_lock(&it6505->irq_lock); if (it6505->enable_drv_hold || !it6505->powered) goto unlock; @@ -2524,7 +2524,7 @@ static irqreturn_t it6505_int_threaded_handler(int unused, void *data) } unlock: - mutex_unlock(&it6505->extcon_lock); + mutex_unlock(&it6505->irq_lock); return IRQ_HANDLED; } @@ -2701,9 +2701,12 @@ static void it6505_extcon_work(struct work_struct *work) */ if (ret) it6505_poweron(it6505); + + complete_all(&it6505->extcon_completion); } else { DRM_DEV_DEBUG_DRIVER(dev, "start to power off"); pm_runtime_put_sync(dev); + reinit_completion(&it6505->extcon_completion); drm_helper_hpd_irq_event(it6505->bridge.dev); memset(it6505->dpcd, 0, sizeof(it6505->dpcd)); @@ -3274,6 +3277,7 @@ static int it6505_i2c_probe(struct i2c_client *client, if (!it6505) return -ENOMEM; + mutex_init(&it6505->irq_lock); mutex_init(&it6505->extcon_lock); mutex_init(&it6505->mode_lock); mutex_init(&it6505->aux_lock); @@ -3329,7 +3333,7 @@ static int it6505_i2c_probe(struct i2c_client *client, INIT_WORK(&it6505->link_works, it6505_link_training_work); INIT_WORK(&it6505->hdcp_wait_ksv_list, it6505_hdcp_wait_ksv_list); INIT_DELAYED_WORK(&it6505->hdcp_work, it6505_hdcp_work); - init_completion(&it6505->wait_edid_complete); + init_completion(&it6505->extcon_completion); memset(it6505->dpcd, 0, sizeof(it6505->dpcd)); it6505->powered = false; it6505->enable_drv_hold = DEFAULT_DRV_HOLD;