Received: by 10.213.65.68 with SMTP id h4csp2113975imn; Sun, 8 Apr 2018 20:04:04 -0700 (PDT) X-Google-Smtp-Source: AIpwx49hV6qf7cIFY//rLTGu1WVzte+O8FNe116shG6cQckY9nj/5jqeRtJSKdbH9cxJcyxR6ke9 X-Received: by 2002:a17:902:51ce:: with SMTP id y72-v6mr36362394plh.157.1523243044826; Sun, 08 Apr 2018 20:04:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523243044; cv=none; d=google.com; s=arc-20160816; b=oZyTLP9460K38EMZDT1kRiRNirn/SGR6BPpEXtjG6WDCWY0u3183wDApdJk63bx9QL njtKRttBePlHCFsgZ1cQKG8gOrFd+Yj14SBsbmpnTqxwta0o5JyjN5ob5S/7aN3Q38SG EiQsDQFWF0Uc75XUQPsOnbpyBMXIKOxLNdYp0rYmWIjQ/8YjEqdGpk2dU1XojrcfNwpP UOpJ1ltadaFvfraWmCUCr0qpIsQw6Wf3XnkLePxw/kbH3/PoazX4SvIJL40WiJQd+10w dcV7QYUgBx/C6T2TUb9Nk+4/twyltOjXizmOmyeCh5ODIIDQA7P7fNjGZDsApPtje5ow uvog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=PYBHjBkGn35hsgeEwXaS9BTSvKx/fn6CeppyNxpB0Gk=; b=wyKWMG0GzKgcTUTnoJ4lpXhV3WXKd60ReS8pBjJOReX2u5Io4b37OytazuR2VKnyMl lWXytZriiFx9bCuHUBSOpNPSE7GmJSPY8Lacjzkyi4hOBb2hb0P5ocz0wtgIIIYuIYqb 0I56SCSsZeEOR2mrXDs8baLaYBOGhGN66ec3FE6kwhF/I0T81X28Lz7+KqDI7gd1p19M /T1DOPANBHQC+gAbhYUEE8zIv0g88L+NmdZxaJKzLlVI2rUlxpjOm4oCNOAGyKFlNZZz ev8mctkxv2MCzjF6zPjv8yd3aQyO5LJgy4rYe4NSCiLuBxftaK/4AUwKyhhz9xf54xbT zwBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=BPSYrUv5; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g1si10170913pgq.743.2018.04.08.20.03.27; Sun, 08 Apr 2018 20:04:04 -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=@microsoft.com header.s=selector1 header.b=BPSYrUv5; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756268AbeDIAbX (ORCPT + 99 others); Sun, 8 Apr 2018 20:31:23 -0400 Received: from mail-by2nam03on0126.outbound.protection.outlook.com ([104.47.42.126]:54752 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1756251AbeDIAbU (ORCPT ); Sun, 8 Apr 2018 20:31:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=PYBHjBkGn35hsgeEwXaS9BTSvKx/fn6CeppyNxpB0Gk=; b=BPSYrUv5/sgy79XFWBQLFzaR/mosNiKfWdwEu2tD1kZeI8VVaQOfK2SWYo5IJh//gdIONg/a7pAjU1ZcGK2KK05Wys+wd+Ik+Zi2+1sh8Q9a4XX8YdwoeYQNWbVfNqknbZKxaThhSqq84LQkj6pRmyPC9xUdX7zIZckZBwtzq1A= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB0917.namprd21.prod.outlook.com (52.132.132.162) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.696.0; Mon, 9 Apr 2018 00:31:15 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059%2]) with mapi id 15.20.0696.003; Mon, 9 Apr 2018 00:31:15 +0000 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Jeffy Chen , Mark Brown , Sasha Levin Subject: [PATCH AUTOSEL for 4.9 166/293] spi: rockchip: Disable Runtime PM when chip select is asserted Thread-Topic: [PATCH AUTOSEL for 4.9 166/293] spi: rockchip: Disable Runtime PM when chip select is asserted Thread-Index: AQHTz5k0KqXsMfmBHkGW1fg4xq/13g== Date: Mon, 9 Apr 2018 00:25:04 +0000 Message-ID: <20180409002239.163177-166-alexander.levin@microsoft.com> References: <20180409002239.163177-1-alexander.levin@microsoft.com> In-Reply-To: <20180409002239.163177-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR2101MB0917;7:+nmsKE5ax+Ofn2N0VWLMZc0ZRt40E6SXmEq8D5t6iUJ0FZ7HxGS4BGdCyjnPjRcKHpa0nfq36EBeTCpUhYtoy4GZ3tr538DvijfPZLp5P/rwlCUxSxm13foMgPz52hemGDzohaeZjGYUFmREjYFT7sF6cfPqD98sFuyEUfaSlGdfs+sbOq48ZBCyJ/O+wwuRcSCzqV6TNfizwCty6rnKgNimpCsIocK5Wn9oxKgPb7bz6Q/MU0Sal6FPtUTFTONB;20:b+yN/0RNZUJEQo+T58EGV+LnEnwwner8q4GyylroxY+7rogPuxsJBbb+D7mvA49qYNLf94X98cry4yM3q1HDljybymkwzC3WYiFqjEB3/fVofdLZNPojuBsjQGVyV5A80Ofi7pluqvJW/sbQDZjYbuxexzyqsr3tnPBb0uMQek4= X-MS-Office365-Filtering-Correlation-Id: 1cd13ae6-061c-4269-4d2a-08d59db1345e x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(4534165)(4627221)(201703031133081)(201702281549075)(5600026)(4604075)(3008032)(48565401081)(2017052603328)(7193020);SRVR:DM5PR2101MB0917; x-ms-traffictypediagnostic: DM5PR2101MB0917: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040522)(2401047)(8121501046)(5005006)(93006095)(93001095)(3231221)(944501327)(52105095)(3002001)(10201501046)(6055026)(61426038)(61427038)(6041310)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123564045)(20161123560045)(6072148)(201708071742011);SRVR:DM5PR2101MB0917;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB0917; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(39380400002)(39860400002)(366004)(396003)(346002)(376002)(189003)(199004)(99286004)(22452003)(106356001)(26005)(110136005)(478600001)(54906003)(10290500003)(316002)(1076002)(72206003)(186003)(4326008)(97736004)(66066001)(11346002)(25786009)(86362001)(575784001)(476003)(446003)(2906002)(6666003)(6486002)(105586002)(86612001)(3280700002)(3660700001)(6512007)(3846002)(6116002)(6436002)(2616005)(486006)(53936002)(7736002)(8676002)(81166006)(81156014)(8936002)(68736007)(305945005)(10090500001)(76176011)(6506007)(102836004)(36756003)(107886003)(59450400001)(2900100001)(2501003)(14454004)(5660300001)(5250100002)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB0917;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: RM6126KI87ngBaXxcxuaA9ry8P1Fdqtk7aJX5kVS4jGu65fGWm8E3+bQtTnxO9oSRcRE3c1eA47ysvEpaWO+ywqiZxw1ziNW3MSOY4TL/hf+mGD8tleEeJw7gmHn7Zk+4pAkkt7Y+OeWuWP3L43tWR2/mcMtOVVig8TrpxCG86IeHuWNYnWw0a0oN+r/XIi5zdOoRtf2qQmIUKnR5SCFMwzmOQfOj1V1uK2HFSvH1E8Kj3sLpa+iMWUd4KM4sppR3nosWKs0PE8+kpIOcDbtagsBVQeGz1po18Sh1rmvdKbX3jKzhw4qhnEGLiXIN/YxFIKTY6x0D6o+bKmHOdBKIjXgmtktMqwl44trKZt8T7VeglCpibVWrU8xv9q/WUGLmj8rxa37Ofm9tWfhomqOz3CTGLXlcat04aIu/FF9Dt0= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1cd13ae6-061c-4269-4d2a-08d59db1345e X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:25:04.4720 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB0917 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jeffy Chen [ Upstream commit aa099382ac0cda27e10fa8f45bf91edea0d1d35e ] The rockchip spi would stop driving pins when runtime suspended, which might break slave's xfer(for example cros_ec). Since we have pullups on those pins, we only need to care about this when the CS asserted. So let's keep the spi alive when chip select is asserted. Also use pm_runtime_put instead of pm_runtime_put_sync. Suggested-by: Doug Anderson Signed-off-by: Jeffy Chen Reviewed-by: Douglas Anderson Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- drivers/spi/spi-rockchip.c | 51 +++++++++++++++++++++++-------------------= ---- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/drivers/spi/spi-rockchip.c b/drivers/spi/spi-rockchip.c index 0f89c2169c24..c3648397c082 100644 --- a/drivers/spi/spi-rockchip.c +++ b/drivers/spi/spi-rockchip.c @@ -24,6 +24,11 @@ =20 #define DRIVER_NAME "rockchip-spi" =20 +#define ROCKCHIP_SPI_CLR_BITS(reg, bits) \ + writel_relaxed(readl_relaxed(reg) & ~(bits), reg) +#define ROCKCHIP_SPI_SET_BITS(reg, bits) \ + writel_relaxed(readl_relaxed(reg) | (bits), reg) + /* SPI register offsets */ #define ROCKCHIP_SPI_CTRLR0 0x0000 #define ROCKCHIP_SPI_CTRLR1 0x0004 @@ -148,6 +153,8 @@ */ #define ROCKCHIP_SPI_MAX_TRANLEN 0xffff =20 +#define ROCKCHIP_SPI_MAX_CS_NUM 2 + enum rockchip_ssi_type { SSI_MOTO_SPI =3D 0, SSI_TI_SSP, @@ -192,6 +199,8 @@ struct rockchip_spi { /* protect state */ spinlock_t lock; =20 + bool cs_asserted[ROCKCHIP_SPI_MAX_CS_NUM]; + u32 use_dma; struct sg_table tx_sg; struct sg_table rx_sg; @@ -263,37 +272,29 @@ static inline u32 rx_max(struct rockchip_spi *rs) =20 static void rockchip_spi_set_cs(struct spi_device *spi, bool enable) { - u32 ser; struct spi_master *master =3D spi->master; struct rockchip_spi *rs =3D spi_master_get_devdata(master); + bool cs_asserted =3D !enable; =20 - pm_runtime_get_sync(rs->dev); + /* Return immediately for no-op */ + if (cs_asserted =3D=3D rs->cs_asserted[spi->chip_select]) + return; =20 - ser =3D readl_relaxed(rs->regs + ROCKCHIP_SPI_SER) & SER_MASK; + if (cs_asserted) { + /* Keep things powered as long as CS is asserted */ + pm_runtime_get_sync(rs->dev); =20 - /* - * drivers/spi/spi.c: - * static void spi_set_cs(struct spi_device *spi, bool enable) - * { - * if (spi->mode & SPI_CS_HIGH) - * enable =3D !enable; - * - * if (spi->cs_gpio >=3D 0) - * gpio_set_value(spi->cs_gpio, !enable); - * else if (spi->master->set_cs) - * spi->master->set_cs(spi, !enable); - * } - * - * Note: enable(rockchip_spi_set_cs) =3D !enable(spi_set_cs) - */ - if (!enable) - ser |=3D 1 << spi->chip_select; - else - ser &=3D ~(1 << spi->chip_select); + ROCKCHIP_SPI_SET_BITS(rs->regs + ROCKCHIP_SPI_SER, + BIT(spi->chip_select)); + } else { + ROCKCHIP_SPI_CLR_BITS(rs->regs + ROCKCHIP_SPI_SER, + BIT(spi->chip_select)); =20 - writel_relaxed(ser, rs->regs + ROCKCHIP_SPI_SER); + /* Drop reference from when we first asserted CS */ + pm_runtime_put(rs->dev); + } =20 - pm_runtime_put_sync(rs->dev); + rs->cs_asserted[spi->chip_select] =3D cs_asserted; } =20 static int rockchip_spi_prepare_message(struct spi_master *master, @@ -738,7 +739,7 @@ static int rockchip_spi_probe(struct platform_device *p= dev) master->auto_runtime_pm =3D true; master->bus_num =3D pdev->id; master->mode_bits =3D SPI_CPOL | SPI_CPHA | SPI_LOOP; - master->num_chipselect =3D 2; + master->num_chipselect =3D ROCKCHIP_SPI_MAX_CS_NUM; master->dev.of_node =3D pdev->dev.of_node; master->bits_per_word_mask =3D SPI_BPW_MASK(16) | SPI_BPW_MASK(8); =20 --=20 2.15.1