From patchwork Fri Jun 17 08:33:17 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 9183055 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 0FF7060776 for ; Fri, 17 Jun 2016 08:33:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 01DC42839C for ; Fri, 17 Jun 2016 08:33:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EB0B8283A8; Fri, 17 Jun 2016 08:33: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=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=unavailable 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 A5A642839C for ; Fri, 17 Jun 2016 08:33:42 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6DF286EB66; Fri, 17 Jun 2016 08:33:30 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x244.google.com (mail-wm0-x244.google.com [IPv6:2a00:1450:400c:c09::244]) by gabe.freedesktop.org (Postfix) with ESMTPS id 383AA6EB54; Fri, 17 Jun 2016 08:33:28 +0000 (UTC) Received: by mail-wm0-x244.google.com with SMTP id 187so14916409wmz.1; Fri, 17 Jun 2016 01:33: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=ntVTpDhH5gSxIwj2U6qeruvM2E0murmSPudQrs8k4ZHHX//1mbETQIwAqryKKG+UTj XqhVwPCi7QdHMkJqYyT4HzRV13pJ4Ro1DrEvLe5EZBHpYLD97aMfVFTF4E6/bu++lXMR fNxcacRCf05ChvB9c5MSsfXSmF3yvvIaBy3gvhIV60NIdKqc8D4piFbVtCIfRxqwhLLP EFsPUvbKKsrnqO9WDPRNWGukQuUfGl5mj/XESHPcg7cjvNkTJHutCcBVSLVbjEEWI/9o lDzdFXZYYma922M+kaFYMeTmhfOGKY1H7mQQ4Ll7eYiTDQ9yVfIewYUoUxrJqtk4GQku azkA== 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=iS7FrdTmpB0mdnapxMMyaNx3bgNbX069cZDxmU1KstLah4IaMoHB2RiWKTnS0Zy/8O yFWg/BhwxqJE19ymeRtuMQtb6FTdURGVUyHd1jT1fkxC9H7LIRB6FKnI3+AoupN0aE5w 2sz37WzfGL9g1TxclXXP/LOtyxLS7otlx1yZ6P7+d7xiNHe5ybh0hveZ0kARWXntVH6E XXJp1EOtbMyuFYMyNbZh82gInj120c72C88ZUwtCYe+XWviAt7OGrejyWvujfR8mqMuL GzA0rz9k6l+FZqZbgNjM1obDdqO1mb/9NX6OEH0tI27oxnnZKhhCpxFMIKbCnBlk+g1b 6tqw== X-Gm-Message-State: ALyK8tJ3mtV6fzIWHWZTmUyDzNDYOpfVJcatlXl+vuHKrv+RAnQadaOA2H9o5/q6DLAJqw== X-Received: by 10.28.153.6 with SMTP id b6mr1109792wme.56.1466152406457; Fri, 17 Jun 2016 01:33:26 -0700 (PDT) Received: from haswell.alporthouse.com ([78.156.65.138]) by smtp.gmail.com with ESMTPSA id u71sm18815169wmu.13.2016.06.17.01.33.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 17 Jun 2016 01:33:25 -0700 (PDT) From: Chris Wilson To: dri-devel@lists.freedesktop.org Subject: [PATCH 1/2] drm: Pass the drm_dp_aux->hw_mutex to i2c for its locking Date: Fri, 17 Jun 2016 09:33:17 +0100 Message-Id: <1466152398-20157-2-git-send-email-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1466152398-20157-1-git-send-email-chris@chris-wilson.co.uk> References: <1466152398-20157-1-git-send-email-chris@chris-wilson.co.uk> MIME-Version: 1.0 Cc: Dave Airlie , intel-gfx@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 --- 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;