From patchwork Fri Jun 3 14:36:48 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 9153237 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 24CCA60221 for ; Fri, 3 Jun 2016 14:37:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1651626C9B for ; Fri, 3 Jun 2016 14:37:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0AD65282E8; Fri, 3 Jun 2016 14:37:53 +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=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AA22826C9B for ; Fri, 3 Jun 2016 14:37:52 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 627DB6EDBF; Fri, 3 Jun 2016 14:37:34 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x243.google.com (mail-wm0-x243.google.com [IPv6:2a00:1450:400c:c09::243]) by gabe.freedesktop.org (Postfix) with ESMTPS id CFFFE6E52E; Fri, 3 Jun 2016 14:37:28 +0000 (UTC) Received: by mail-wm0-x243.google.com with SMTP id e3so24020440wme.2; Fri, 03 Jun 2016 07:37:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=MBrebZ3xAf5S87NojPHNUPmfM2nk42Zd1ZuGINGGXOw=; b=pANcgry/CWygA9u8a9bM3B2J+t4IlPDtad9wLwK9Ei+gee9iF7CdJhUjMDERLt+UtO QD7LXogvJ72X0KWoxQ6NtFNNQJivKNxzfA6bK91Y5/fkCAMLmnsK5hmAhHih/Tc2Sjpd a18bOuKapT6S0u4Eemh8f+uVNAG+s29ACqOD7CpmUEQifguV50zIRBw3QSBOf52fDZOf rHzfH6NmP7dyrFmTv5SQ/qeadc4lFq0aVHvuqBhSmU7Anh5TnT+Z5yB7Si8gCrX00mAf 8NLO2Rqnvtw3oK1HrD+MmkAgPLlShnejZWP7wkNgdP25WoD2KjKsv9HSH5u09vpQuWwA QByw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=MBrebZ3xAf5S87NojPHNUPmfM2nk42Zd1ZuGINGGXOw=; b=mr1dCZ3aE7A1Bm2ZUMvkHBkOxqGA1CTmWp58KKxREKTlYjIdl4DydWi0Q8/qmm1T9J KOo4Xah41TPAfYFpGkN2GJVhFQGThJMERHnf3wX0GYGLMs4XvjJQl1XcBshn+gYLu2Un Xwz5wOKJXZEX6cnK2TmrgRVpGanu8cEz/hQmTgL7udsBWCbFHWoe246z9ua13Ah6s3S0 QAys+YHW3Pbp7gaFxyMNdczNbjxT3wo/O/ibWLI3yuy+i/Zd0kazJb6fq4Wj4YvjdPYU VxfrpM7yTs2ZSzmCiNSijSZDRjGa73UW+hm3rZWnQ+sfaUDlsX2zonHY5cnWow5SjG5U MvcA== X-Gm-Message-State: ALyK8tK/IxPh3r1WYf2/ZajOzyRKQmFevwd6r+Xl2dtQMxpeAx3Ft2MN5pmPPDekIhaluw== X-Received: by 10.28.153.80 with SMTP id b77mr32673237wme.71.1464964646920; Fri, 03 Jun 2016 07:37:26 -0700 (PDT) Received: from haswell.alporthouse.com ([78.156.65.138]) by smtp.gmail.com with ESMTPSA id e1sm6060275wjv.9.2016.06.03.07.37.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 03 Jun 2016 07:37:26 -0700 (PDT) From: Chris Wilson To: intel-gfx@lists.freedesktop.org Subject: [PATCH v3 05/33] drm: Pass the drm_dp_aux->hw_mutex to i2c for its locking Date: Fri, 3 Jun 2016 15:36:48 +0100 Message-Id: <1464964636-3877-6-git-send-email-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1464964636-3877-1-git-send-email-chris@chris-wilson.co.uk> References: <1464964636-3877-1-git-send-email-chris@chris-wilson.co.uk> MIME-Version: 1.0 Cc: Dave Airlie , dri-devel@lists.freedesktop.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Rather than have both drm_dp_aux lock within its transfer, and i2c to lock around the transfer, use the same lock by filling in the locking callbacks that i2c wants to use. We require our own hw_mutex as we bypass i2c_transfer for drm_dp_dpcd_access(). Signed-off-by: Chris Wilson Cc: Dave Airlie Cc: Rafael Antognolli Cc: Ville Syrjälä Cc: dri-devel@lists.freedesktop.org Reviewed-by: Ville Syrjälä --- drivers/gpu/drm/drm_dp_helper.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/drm_dp_helper.c b/drivers/gpu/drm/drm_dp_helper.c index eeaf5a7c3aa7..4b088afa21b2 100644 --- a/drivers/gpu/drm/drm_dp_helper.c +++ b/drivers/gpu/drm/drm_dp_helper.c @@ -708,8 +708,6 @@ static int drm_dp_i2c_xfer(struct i2c_adapter *adapter, struct i2c_msg *msgs, memset(&msg, 0, sizeof(msg)); - mutex_lock(&aux->hw_mutex); - for (i = 0; i < num; i++) { msg.address = msgs[i].addr; drm_dp_i2c_msg_set_request(&msg, &msgs[i]); @@ -764,8 +762,6 @@ static int drm_dp_i2c_xfer(struct i2c_adapter *adapter, struct i2c_msg *msgs, msg.size = 0; (void)drm_dp_i2c_do_msg(aux, &msg); - mutex_unlock(&aux->hw_mutex); - return err; } @@ -774,6 +770,26 @@ static const struct i2c_algorithm drm_dp_i2c_algo = { .master_xfer = drm_dp_i2c_xfer, }; +static struct drm_dp_aux *i2c_to_aux(struct i2c_adapter *i2c) +{ + return container_of(i2c, struct drm_dp_aux, ddc); +} + +static void lock_bus(struct i2c_adapter *i2c, unsigned int flags) +{ + mutex_lock(&i2c_to_aux(i2c)->hw_mutex); +} + +static int trylock_bus(struct i2c_adapter *i2c, unsigned int flags) +{ + return mutex_trylock(&i2c_to_aux(i2c)->hw_mutex); +} + +static void unlock_bus(struct i2c_adapter *i2c, unsigned int flags) +{ + mutex_unlock(&i2c_to_aux(i2c)->hw_mutex); +} + /** * drm_dp_aux_register() - initialise and register aux channel * @aux: DisplayPort AUX channel @@ -790,6 +806,10 @@ int drm_dp_aux_register(struct drm_dp_aux *aux) aux->ddc.algo_data = aux; aux->ddc.retries = 3; + aux->ddc.lock_bus = lock_bus; + aux->ddc.trylock_bus = trylock_bus; + aux->ddc.unlock_bus = unlock_bus; + aux->ddc.class = I2C_CLASS_DDC; aux->ddc.owner = THIS_MODULE; aux->ddc.dev.parent = aux->dev;