Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp8269imm; Mon, 4 Jun 2018 12:03:12 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKR/BiOiJPHjqMwa+2cJdHYIzW7DX1fo/lQZxY3QF1G09bNySQbKx7yidY5YYz4vNEdH4e+ X-Received: by 2002:a17:902:7105:: with SMTP id a5-v6mr23577621pll.171.1528138992093; Mon, 04 Jun 2018 12:03:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528138992; cv=none; d=google.com; s=arc-20160816; b=ptdxtGKwPQ/6kHPeuue57Qy5VeO6WEYoPsA6uw7kLUf1IziBLPJDyj9A0tmvJQXPz+ cD2p+Nn/F+XPtI88im7h21UnmRmYrgguth6gLM2hANbVdX99llpWF78CvJNYlaf7I3gZ 6wO50T+Ti9PmZcO8A/JKx1U6sb0rf20zfDUKqAL3a4dI9FUcpXRRngaHRCsF21Hsk2Ea KEYd+9SvcPafnKcW0sQvfuLRIXbInoSu963n5pvkWTEOu0tsfAsB4G7cGkv5wosNqOmU 7Ske03/K0n9fEZX4ubiDkmpnwtM45mBnFTAeLLDxi8rNZM40oSiuqY3dd+DHRjWnU14o Pusw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:references:in-reply-to:date :subject:cc:to:from:arc-authentication-results; bh=92qBO91f4+qxsBNDsYHgFE32d83FCRCbI3oELVVSdNg=; b=GwXV8e4v2PhA+Vl3rwgp3qzYZrkvrucRskmqiHJJYvAKKC9eRdKJx8X6MPE5f+KpxL SKMfiD5HHhDIuiDt0kxDa/HJjnsp9X0sS9wP8VHR8B5hvI1UF3wq70M5r6MrcH+eqK7A 6ns2s55AlIXaEmiJYnV8ccUFuIG2DpVwHqOp3KWMr8NYr6WLBJC7HhTSYzPHTaxcTDun ar3O7Ts9mV9Jm1Ud53kC3zlb01e7043a28Nl3/gUF6JUj/ZojVa5xWoYctiL7Eiae2Tc IJZDKraHqIwtNVtcR+Zyhim19v8uqM5im99C6D4vSM6tETwIrOYauQnG7g54VHfYtCUL 22Gw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m67-v6si6644810pgm.517.2018.06.04.12.02.46; Mon, 04 Jun 2018 12:03:12 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751441AbeFDTBO (ORCPT + 99 others); Mon, 4 Jun 2018 15:01:14 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:40308 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751411AbeFDTBM (ORCPT ); Mon, 4 Jun 2018 15:01:12 -0400 Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w54IwlBI132932 for ; Mon, 4 Jun 2018 15:01:12 -0400 Received: from e17.ny.us.ibm.com (e17.ny.us.ibm.com [129.33.205.207]) by mx0a-001b2d01.pphosted.com with ESMTP id 2jd8mgepmj-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 04 Jun 2018 15:01:11 -0400 Received: from localhost by e17.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 4 Jun 2018 15:01:10 -0400 Received: from b01cxnp23034.gho.pok.ibm.com (9.57.198.29) by e17.ny.us.ibm.com (146.89.104.204) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Mon, 4 Jun 2018 15:01:07 -0400 Received: from b01ledav002.gho.pok.ibm.com (b01ledav002.gho.pok.ibm.com [9.57.199.107]) by b01cxnp23034.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w54J16bn5636606 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 4 Jun 2018 19:01:06 GMT Received: from b01ledav002.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C86F1124055; Mon, 4 Jun 2018 16:02:34 -0400 (EDT) Received: from b01ledav002.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DF11B12405A; Mon, 4 Jun 2018 16:02:33 -0400 (EDT) Received: from talon7.ibm.com (unknown [9.41.241.240]) by b01ledav002.gho.pok.ibm.com (Postfix) with ESMTP; Mon, 4 Jun 2018 16:02:33 -0400 (EDT) From: Eddie James To: linux-i2c@vger.kernel.org Cc: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, wsa@the-dreams.de, robh+dt@kernel.org, benh@kernel.crashing.org, joel@jms.id.au, mark.rutland@arm.com, gregkh@linuxfoundation.org, rdunlap@infradead.org, andy.shevchenko@gmail.com, Eddie James Subject: [PATCH v9 6/7] i2c: fsi: Add I2C master locking Date: Mon, 4 Jun 2018 14:00:49 -0500 X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1528138850-18259-1-git-send-email-eajames@linux.vnet.ibm.com> References: <1528138850-18259-1-git-send-email-eajames@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18060419-0040-0000-0000-0000043B17C1 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00009129; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000265; SDB=6.01042302; UDB=6.00533708; IPR=6.00821432; MB=3.00021461; MTD=3.00000008; XFM=3.00000015; UTC=2018-06-04 19:01:09 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18060419-0041-0000-0000-0000084117C9 Message-Id: <1528138850-18259-7-git-send-email-eajames@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-06-04_13:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1805220000 definitions=main-1806040219 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Since there are many ports per master, each with it's own adapter and chardev, we need some locking to prevent transfers from changing the master state while other transfers are in progress. Signed-off-by: Eddie James --- drivers/i2c/busses/i2c-fsi.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/drivers/i2c/busses/i2c-fsi.c b/drivers/i2c/busses/i2c-fsi.c index 4e5964e..6e6e2b1 100644 --- a/drivers/i2c/busses/i2c-fsi.c +++ b/drivers/i2c/busses/i2c-fsi.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -143,6 +144,7 @@ struct fsi_i2c_master { struct fsi_device *fsi; u8 fifo_size; struct list_head ports; + struct mutex lock; }; struct fsi_i2c_port { @@ -569,11 +571,14 @@ static int fsi_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int i, rc; unsigned long start_time; struct fsi_i2c_port *port = adap->algo_data; + struct fsi_i2c_master *master = port->master; struct i2c_msg *msg; + mutex_lock(&master->lock); + rc = fsi_i2c_set_port(port); if (rc) - return rc; + goto unlock; for (i = 0; i < num; i++) { msg = msgs + i; @@ -581,15 +586,17 @@ static int fsi_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, rc = fsi_i2c_start(port, msg, i == num - 1); if (rc) - return rc; + goto unlock; rc = fsi_i2c_wait(port, msg, adap->timeout - (jiffies - start_time)); if (rc) - return rc; + goto unlock; } - return 0; +unlock: + mutex_unlock(&master->lock); + return rc; } static u32 fsi_i2c_functionality(struct i2c_adapter *adap) @@ -615,6 +622,7 @@ static int fsi_i2c_probe(struct device *dev) if (!i2c) return -ENOMEM; + mutex_init(&i2c->lock); i2c->fsi = to_fsi_dev(dev); INIT_LIST_HEAD(&i2c->ports); -- 1.8.3.1