From patchwork Thu Sep 13 08:21:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jisheng Zhang X-Patchwork-Id: 10598849 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 12EDC13BF for ; Thu, 13 Sep 2018 08:25:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 01BAF2A564 for ; Thu, 13 Sep 2018 08:25:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E9E322A56A; Thu, 13 Sep 2018 08:25:28 +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=-2.9 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED,DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5E9EC2A564 for ; Thu, 13 Sep 2018 08:25:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Subject:To:From :Date:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=UnhGp2c9sC4QAW6eDJVN1Wt5eqFB4CXnIQ84JQy/6D8=; b=lrqIQv01AH7F5j LrqP2vt/qPA8KwbOfnw2H123RqEvc8cOgLidqNR4Jk4LeUf/TJQ0b/g5DU/9sK1qynCcGWH3+9MzZ Qmn9eLUurqFl7RitZLC0hKdUoOOjrHMGoJJgjcz2fxuOyJI58uO+69SK0CDMHKGU4fuJ51PUYhZhn /cxkxegVu94wvO8Hwr5/rBgteJGXBEhKrsrGL+OmzQdrG9BA4sn7jZR1S+gXIik0+pKEXLQNQevHH D6pYWqBfgaRroVFHwAftTXHwcBhsyQ8IX0QU/h3c/Qp40cYccqcLUYYNHDxnXFQuST+W7+2cvW2c+ I53ENnEEDENW2AyYlxJA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1g0MwB-0002Ux-R9; Thu, 13 Sep 2018 08:25:19 +0000 Received: from mail-bl2nam02on0060.outbound.protection.outlook.com ([104.47.38.60] helo=NAM02-BL2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1g0Mw8-0001Iq-66 for linux-arm-kernel@lists.infradead.org; Thu, 13 Sep 2018 08:25:17 +0000 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 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 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+8Y0If189umwyH9dxSCG60sH30xWW9q4wOBbRuPu7+UTT+tDIR87FZIl3dewoC2KBt5PJ2gMMP7curwLPKhgO94LzyP0G5Rd+1oNlm/yD9tu47fLcdJUw3uNFhvgb0Jpy4Xs9XNhfAS3GvEauDfd7r8LvMfo8NfzOYOknekm+2uBmkJS; 25:Q2rrDaIZdMbGVKgLLNW7C9bUSo0IuuI7qwvkdiNr4+Ml8/R4nC4zaSxQ3JO0MJIu2qatYiVkf0xX55Rz7x0dsKOx12Cz08y2zU52qi6/CHzHtrE+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1z1Fz3Lwm34ImVH8Ic/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; 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dpaIMd7WNkKh3fgBUK3riR3VuN0ktRi5NaCOv7LaIQYE7OsEduDnauK8eyZadJCrcRpw3HOp3Pm+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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180913_012516_316450_5205536B X-CRM114-Status: GOOD ( 10.02 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-i2c@vger.kernel.org, linux-arm-kernel , linux-kernel@vger.kernel.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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;