Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp394506imm; Thu, 13 Sep 2018 01:25:28 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaHha4/flPNJCAZYLZVHiLePitAWEwGcv9B/XKwY+3wc2cFjf0r/IVTABrKmA/8sNXlHHoo X-Received: by 2002:a63:6c89:: with SMTP id h131-v6mr5973828pgc.237.1536827128531; Thu, 13 Sep 2018 01:25:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536827128; cv=none; d=google.com; s=arc-20160816; b=m7dunMBAsswkWJ2qyX4fDwwrtYjmDt/nwM7blcQL7cmlk2OAlSivvbPhvda7gWD7x3 BvrA1/1b/AT4s4DM7QbMaepPhg2I/aWg6S7f3QNywgOngm6cQ89Xk0HUdHkbPddPYka+ HwGtX6Ma4K0SU/hjW65Pw5vXtXn+r6qctkhhFQC1Z787FZ3tR0zSBDeavVFElE8+4VkD WPP3RRMMJNppHT7vk1xA7TntG8uVlm9/8PrzrMS/d3oVcLRHdVQ+GH761Jmyxr65dhMr Wutb0zs8gYQgzj2KZhXq8R95yUPa6K9bpoSYW6mTZKaQuV4iKQjjDR7j9TBCRB+CpXSM BYvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:spamdiagnosticmetadata :spamdiagnosticoutput:content-transfer-encoding:mime-version :message-id:subject:cc:to:from:date:dkim-signature; bh=QcIQQDLzraG/B9zB0qjjWdBfNpQ8//NO4oDLUE1uEhM=; b=noNT/B442V3G4X2hzsk4o85xVuiRYRlpULrKeOVIp95G4kJrPQS1J630ARRRGwiBZA 5vHTWwgi0CIRJG3izlr9gTK3ajCiudwBnZqozFo5XggtsCzAcf5V8P2UhGLBInJoFg0M +ne0yelYPs9oKlzrKg/Su9Pk3MES3CRKa3Xw2VR2GV3eYWRviSRwx9OwO2OU+dP1WJBf TQqSaZjm3uhrumEJwqBo3aqu3iVZ0PnfKbkgyrrMH9debJRx5fXQGimbQxw0NIXZ+dIv LUyLKfBYejpWmHgeBY2xh00MDCK2AHK7XrLkd/iiHMG7YlAqxoOJ9atYStJD/fDpU0Q0 rWQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@Synaptics.onmicrosoft.com header.s=selector1-synaptics-com header.b=uXJjbA7F; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 71-v6si3475679pla.92.2018.09.13.01.25.12; Thu, 13 Sep 2018 01:25:28 -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; dkim=pass header.i=@Synaptics.onmicrosoft.com header.s=selector1-synaptics-com header.b=uXJjbA7F; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726985AbeIMNdb (ORCPT + 99 others); Thu, 13 Sep 2018 09:33:31 -0400 Received: from mail-bl2nam02on0054.outbound.protection.outlook.com ([104.47.38.54]:15328 "EHLO NAM02-BL2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726495AbeIMNda (ORCPT ); Thu, 13 Sep 2018 09:33:30 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Synaptics.onmicrosoft.com; s=selector1-synaptics-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=QcIQQDLzraG/B9zB0qjjWdBfNpQ8//NO4oDLUE1uEhM=; b=uXJjbA7FW16fGt2fXBmyvAJtTCgvFjykFKs/BeEkFgZwRh4+Ejs/rL0Kd56sRrsRf0aBi0b1cf3rL1jliCgl+MsK9XdRqn2V5qBvQqd4rE6SP5OVcq+bcT4DEA9XfXLRKOMsZB3ySAWlUW3vy8wfAT2mhFBvU7rEM1QUEOkS9Cc= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Jisheng.Zhang@synaptics.com; Received: from xhacker.debian (124.74.246.114) by SN1PR0301MB1584.namprd03.prod.outlook.com (2a01:111:e400:5232::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1122.16; Thu, 13 Sep 2018 08:24:58 +0000 Date: Thu, 13 Sep 2018 16:21:32 +0800 From: Jisheng Zhang To: Jarkko Nikula , Andy Shevchenko , Mika Westerberg , Wolfram Sang Cc: linux-arm-kernel , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] i2c: designware: select gpio/default pin when prepare/unprepare recovery Message-ID: <20180913162132.17c9c2b3@xhacker.debian> X-Mailer: Claws Mail 3.17.1 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Originating-IP: [124.74.246.114] X-ClientProxiedBy: OSAPR01CA0143.jpnprd01.prod.outlook.com (2603:1096:604:f::35) To SN1PR0301MB1584.namprd03.prod.outlook.com (2a01:111:e400:5232::18) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: cc94a946-60eb-4c84-5d15-08d6195265fe X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(7020095)(4652040)(8989137)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(5600074)(711020)(2017052603328)(7153060)(7193020);SRVR:SN1PR0301MB1584; X-Microsoft-Exchange-Diagnostics: 1;SN1PR0301MB1584;3:CVCZ98M5KgMhH2MckiLrYEGJQMV6P9ALUpOZurgabMh2A8jAvKYwfYjnfQRlzEKGkSp8T8iP+ugZSOCe+8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0I2qpS7Herni3pHj40Pkc+IdNqjJmgzRRoaL+oO2f2AfLg7XHdPB7TCLqP+rPdUyBfw3w82yUbFCh1EKh4J1/1vOAq8OodVhTzxutE89BAMpAI99R1s81OHaDmiv+afgjn+8HaQ3zIEkQY/G8RmyD3afBHZtFDnYJDs2eCdyJejr0EfV1o+Vutho7i4KFK8Ad8cf9O8tjkxsDpXJE7k1trUmBKjTTdcAWDbENV22Q7L7J9N559dMn/RYYzzr7tGFYh6Lqs75NwJDg3yO92;4:WXgY43IQFWONAlQ1z1Fz3Lwm34ImVH8Ic/eNlDSSyzivAk6jDBP/0qT+ZR3WwBpfrEUOFIT1vUcPWfZFXwUB6Nw7H101mQyF8UNnIf4pVYMeLRx3KBSF0QzIv90CfsH3x/zHyJ9E7a2NtUluxXnGdCJJlbjmDOQ4tGioADdvhbl68rBEazPODLAX8y3p7IabgsPinDyX7zhP2011UwKNSd/oX4/5hFCr8bb8iV1lz4m4B02FM3ZUk1pt1eY49MCjHfllUTbwf2Xt0ALqu+plKw== 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)(5005006)(8121501046)(10201501046)(3002001)(3231311)(944501410)(52105095)(93006095)(93001095)(149027)(150027)(6041310)(20161123558120)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(20161123564045)(20161123560045)(201708071742011)(7699050);SRVR:SN1PR0301MB1584;BCL:0;PCL:0;RULEID:;SRVR:SN1PR0301MB1584; X-Forefront-PRVS: 07943272E1 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(366004)(396003)(376002)(346002)(39830400003)(199004)(189003)(97736004)(5660300001)(186003)(16526019)(68736007)(305945005)(26005)(52116002)(2906002)(956004)(33896004)(25786009)(66066001)(230700001)(8676002)(476003)(486006)(50466002)(55016002)(9686003)(47776003)(7696005)(7736002)(6506007)(386003)(110136005)(316002)(508600001)(3846002)(6116002)(105586002)(72206003)(6666003)(1076002)(106356001)(86362001)(23726003)(4326008)(81156014)(50226002)(14444005)(8936002)(575784001)(81166006)(53936002)(39210200001);DIR:OUT;SFP:1101;SCL:1;SRVR:SN1PR0301MB1584;H:xhacker.debian;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; Received-SPF: None (protection.outlook.com: synaptics.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;SN1PR0301MB1584;23:2b54KkTEYUwf0pktTuitfICx+JEnbeX/SC1q0kn?= =?us-ascii?Q?JrVIHS+CWG34EHg+Y2zNaPABFvI4nVbp+YPVmKA0HfhOym9SFJ5AexqmAWfV?= =?us-ascii?Q?gvuRufnt5XyX5kalIlW4soH3QjTVNoltinAwWjqb1WZucGvFMks3xM8uNWjf?= =?us-ascii?Q?FeeIyR5eaXxdoMM2AZUOv/xhYKI5z3n+vrVe5K4MkPq0Ca7WY9aoEuvd0zDZ?= =?us-ascii?Q?V+/AkAKx5njiD00zvq3k9D+4VG3pXt4wuXiJF2lN7eymzYxPQrJik9cM5w8C?= =?us-ascii?Q?D0dnr2vJ9aZwEeK3LVdWZ3Z4kkZe5+5JbT/m7Zqm3Lx8dEPRCYl53IWc0AsA?= =?us-ascii?Q?SRnBA/XWGyOaNSdgOb0PsPgScDZev2hGv8b717vtoiZL1eWFIZuCDdABUFcx?= =?us-ascii?Q?mhTL/vyxlkEEKID3p4CdR/xWQo1PoLSm56yUzjULpvVdn5lcFYQTKJK1ZZKE?= =?us-ascii?Q?qC/FTo4TiVh6WXeN6R5CDnsL8DpS/c55tQpQQBhSbnv/jIqVS85K8cgKDBM8?= =?us-ascii?Q?BIp1c+xJUKD7pkOf7mc1/zyQdW6RfWpUZyjkMnMNpbqNGScJUqMnFFrbhER4?= =?us-ascii?Q?9Cp0srgs6xv0z1+ONV+ExtwiKRClhggtVW9H+ragULtutizOginSPxRcnWYo?= =?us-ascii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Exchange-Diagnostics: 1;SN1PR0301MB1584;6:mym8FXx8Trxs4pXii/L2B7oFr4lYhd24I4VjF1FQFkWE+vBMvv80KotpXKrhmjzulHehyFN/jrfMaChykq5a1dGoQSNn618ZFZ1W2ScghcH+9Ul2hiSE4PPT5Uvxuw/9iLqrtbtWt5+hhNbENdLKd56Si3pVm80DK9PGVB/IyfQjV1K0t4GOc9MMQJq9i3OqCAvBHnvoD0G75O955oCV6jGd4taVwMplnZaTm/aWGLN/9WUE/+zU5WplZeY1C7S24MOtRuW2sBdLTfIY6f4MSGLUymK3ElnCn9r/ZMxdIyysv8IHXXf/lciRYrZgnMT52jlGw03xdBE5mnrmem5Y7HbYUp+lob0HcxPuwTel/wCU0Fe5XWLLPaqeJILGEj3Owf/Eo8RcSeZTRmCb302z2pSbaUZOcnb9v16TfgjqxHV13fYbEcpV8pQwJIhweNJOSi17Yb1HBcJN5AgVkC0+3A==;5:kDv/hplEyjf/3In5pNR+1icuQdlml8+VMgFvPmuOylXEXKH/b81N5A5jno4JSeiiOGvAnPvEdpaIMd7WNkKh3fgBUK3riR3VuN0ktRi5NaCOv7LaIQYE7OsEduDnauK8eyZadJCrcRpw3HOp3Pm+WbdNV6DJLU0UjiytA/dsoIQ=;7:UBm7bsnBBZ3mJV0MKIOX/1l5F7K+9YZL0QAYw5kusAoYfTbQyF5xKGV0I+IoyTSmME9Usr187OflKXrlHN1cKUT05FWij1ugDhHS4xTNkRLnPLa9EFC/6CBTN18jKrVRaIaJVMK1aKAyZSL8wA4i5PFVFt2wEbonyis2bSP9aCiHGw/qSkdwTWLX/fSSIL+985dYGzUGQIj3Zle+x7a6aVo4qSnchfWoKNY3kdwEo9AREc4/tp2+YWjSVnEN7PUF SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: synaptics.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Sep 2018 08:24:58.9153 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: cc94a946-60eb-4c84-5d15-08d6195265fe X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 335d1fbc-2124-4173-9863-17e7051a2a0e X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR0301MB1584 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On some platforms, the sda/scl pins are muxed with gpio functions, so they could be used for recovery. Select the gpio/default pin function when prepare/unprepare recovery. Signed-off-by: Jisheng Zhang --- since v1: - use IS_ERR_OR_NULL drivers/i2c/busses/i2c-designware-core.h | 3 +++ drivers/i2c/busses/i2c-designware-master.c | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/drivers/i2c/busses/i2c-designware-core.h b/drivers/i2c/busses/i2c-designware-core.h index e367b1af4ab2..01d5f01691a4 100644 --- a/drivers/i2c/busses/i2c-designware-core.h +++ b/drivers/i2c/busses/i2c-designware-core.h @@ -271,6 +271,9 @@ struct dw_i2c_dev { int (*init)(struct dw_i2c_dev *dev); int mode; struct i2c_bus_recovery_info rinfo; + struct pinctrl *pinctrl; + struct pinctrl_state *pins_default; + struct pinctrl_state *pins_gpio; }; #define ACCESS_SWAP 0x00000001 diff --git a/drivers/i2c/busses/i2c-designware-master.c b/drivers/i2c/busses/i2c-designware-master.c index 94d94b4a9a0d..384d6630366a 100644 --- a/drivers/i2c/busses/i2c-designware-master.c +++ b/drivers/i2c/busses/i2c-designware-master.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -629,6 +630,9 @@ static void i2c_dw_prepare_recovery(struct i2c_adapter *adap) { struct dw_i2c_dev *dev = i2c_get_adapdata(adap); + if (dev->pinctrl && dev->pins_gpio) + pinctrl_select_state(dev->pinctrl, dev->pins_gpio); + i2c_dw_disable(dev); reset_control_assert(dev->rst); i2c_dw_prepare_clk(dev, false); @@ -641,6 +645,9 @@ static void i2c_dw_unprepare_recovery(struct i2c_adapter *adap) i2c_dw_prepare_clk(dev, true); reset_control_deassert(dev->rst); i2c_dw_init_master(dev); + + if (dev->pinctrl && dev->pins_default) + pinctrl_select_state(dev->pinctrl, dev->pins_default); } static int i2c_dw_init_recovery_info(struct dw_i2c_dev *dev) @@ -648,6 +655,8 @@ static int i2c_dw_init_recovery_info(struct dw_i2c_dev *dev) struct i2c_bus_recovery_info *rinfo = &dev->rinfo; struct i2c_adapter *adap = &dev->adapter; struct gpio_desc *gpio; + struct pinctrl *pinctrl; + struct pinctrl_state *s; int r; gpio = devm_gpiod_get(dev->dev, "scl", GPIOD_OUT_HIGH); @@ -664,6 +673,19 @@ static int i2c_dw_init_recovery_info(struct dw_i2c_dev *dev) return PTR_ERR(gpio); rinfo->sda_gpiod = gpio; + pinctrl = devm_pinctrl_get(dev->dev); + if (PTR_ERR(pinctrl) == -EPROBE_DEFER) + return -EPROBE_DEFER; + if (!IS_ERR_OR_NULL(pinctrl)) { + dev->pinctrl = pinctrl; + s = pinctrl_lookup_state(pinctrl, PINCTRL_STATE_DEFAULT); + if (!IS_ERR_OR_NULL(s)) + dev->pins_default = s; + s = pinctrl_lookup_state(pinctrl, "gpio"); + if (!IS_ERR_OR_NULL(s)) + dev->pins_gpio = s; + } + rinfo->recover_bus = i2c_generic_scl_recovery; rinfo->prepare_recovery = i2c_dw_prepare_recovery; rinfo->unprepare_recovery = i2c_dw_unprepare_recovery; -- 2.19.0