From patchwork Mon Jun 26 03:10:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeffy Chen X-Patchwork-Id: 9808599 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 62FB860382 for ; Mon, 26 Jun 2017 03:15:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5245528111 for ; Mon, 26 Jun 2017 03:15:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 446552818A; Mon, 26 Jun 2017 03:15:05 +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=-5.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, URIBL_BLACK autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7C4F628111 for ; Mon, 26 Jun 2017 03:15:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751617AbdFZDPB (ORCPT ); Sun, 25 Jun 2017 23:15:01 -0400 Received: from regular1.263xmail.com ([211.150.99.141]:48970 "EHLO regular1.263xmail.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751525AbdFZDPA (ORCPT ); Sun, 25 Jun 2017 23:15:00 -0400 Received: from jeffy.chen?rock-chips.com (unknown [192.168.167.76]) by regular1.263xmail.com (Postfix) with ESMTP id 8E83E80; Mon, 26 Jun 2017 11:14:54 +0800 (CST) X-263anti-spam: X-MAIL-GRAY: 0 X-MAIL-DELIVERY: 1 X-ABS-CHECKED: 4 Received: from localhost (localhost [127.0.0.1]) by smtp.263.net (Postfix) with ESMTPA id C00543CB; Mon, 26 Jun 2017 11:14:50 +0800 (CST) X-RL-SENDER: jeffy.chen@rock-chips.com X-FST-TO: linux-kernel@vger.kernel.org X-SENDER-IP: 103.29.142.67 X-LOGIN-NAME: jeffy.chen@rock-chips.com X-UNIQUE-TAG: <2289c68ef3d088c8e3fc9f799d78832f> X-ATTACHMENT-NUM: 0 X-SENDER: cjf@rock-chips.com X-DNS-TYPE: 0 Received: from localhost (unknown [103.29.142.67]) by smtp.263.net (Postfix) whith ESMTP id 22838GXIBO4; Mon, 26 Jun 2017 11:14:53 +0800 (CST) From: Jeffy Chen To: linux-kernel@vger.kernel.org, broonie@kernel.org Cc: briannorris@chromium.org, dianders@chromium.org, heiko@sntech.de, Jeffy Chen , linux-spi@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH] spi: rockchip: Keep master alive when CS asserted Date: Mon, 26 Jun 2017 11:10:06 +0800 Message-Id: <1498446606-5529-1-git-send-email-jeffy.chen@rock-chips.com> X-Mailer: git-send-email 2.1.4 Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The cros_ec requires CS line to be active after last message. But the CS would be toggled when powering off/on rockchip spi, which breaks ec xfer. Keep spi alive after CS asserted to prevent that. Suggested-by: Doug Anderson Signed-off-by: Jeffy Chen --- drivers/spi/spi-rockchip.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/drivers/spi/spi-rockchip.c b/drivers/spi/spi-rockchip.c index acf31f3..df016a1 100644 --- a/drivers/spi/spi-rockchip.c +++ b/drivers/spi/spi-rockchip.c @@ -264,7 +264,7 @@ static inline u32 rx_max(struct rockchip_spi *rs) static void rockchip_spi_set_cs(struct spi_device *spi, bool enable) { - u32 ser; + u32 ser, new_ser; struct spi_master *master = spi->master; struct rockchip_spi *rs = spi_master_get_devdata(master); @@ -288,13 +288,25 @@ static void rockchip_spi_set_cs(struct spi_device *spi, bool enable) * Note: enable(rockchip_spi_set_cs) = !enable(spi_set_cs) */ if (!enable) - ser |= 1 << spi->chip_select; + new_ser = ser | BIT(spi->chip_select); else - ser &= ~(1 << spi->chip_select); + new_ser = ser & ~BIT(spi->chip_select); - writel_relaxed(ser, rs->regs + ROCKCHIP_SPI_SER); + if (new_ser == ser) + goto out; - pm_runtime_put_sync(rs->dev); + writel_relaxed(new_ser, rs->regs + ROCKCHIP_SPI_SER); + + /* + * The rockchip spi would stop driving CS when power down. + * So we need to keep it alive after CS asserted + */ + if (!enable) + return; + pm_runtime_put(rs->dev); + +out: + pm_runtime_put(rs->dev); } static int rockchip_spi_prepare_message(struct spi_master *master,