Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp5566777pxb; Mon, 14 Feb 2022 02:08:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJw5sqS+OTAJawBKrZImpkKsWrZtxFyt5C1/AMnKhyYgfOHlsNKQSR0LqGvmR/1zqDhNAdFh X-Received: by 2002:a05:6402:1806:: with SMTP id g6mr1651818edy.259.1644833286008; Mon, 14 Feb 2022 02:08:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644833286; cv=none; d=google.com; s=arc-20160816; b=mAPrfwLt6TutX3AHsvUQ0kB6D39WQeSlYbo41Jm6+nk+SwEpUzO6wUsOTWaLRxoCEk 7BBRfgmbkfYDtNofcXSQgOVMA+xE1ysdy3UzVej14XZthvqXThePGD/LfLKPccrahNZu 9fLnsB3vB/sq2CyT5DDd50INpIrlXOqKdx1TApF3JNmIn3c3I+wVbJCB73BcAWMLyys6 W3a+barxbsyIdOabK4fv3I62cwIimhgvImEl7exT4GtBq2Zqn8ttIP2I5VgrFV8UfOTD XJZpUdUwMoMVZk+9geIvK36ngeKiQb2s9bJUqgewaf26XFfYiKBsjoDLOjrXp9HUHwU1 4xiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=QHCPj8KI/EVuRsgdQ1qEZCDnK7IbmPcZVpvCTzdKaAA=; b=ntGUNggpKoavfVymqBgU7by+WpNGsEaInJBPOVso8UNJK2xA+0M32XYa4KErzWhkVB 6cc5YhrEuETI/4Hcl9PqTocFHXlntsjpBZAvT01QizPHVZZLKnCiUG/ixqPxtIhtH0Td u5MuEhc1wyg4M2aTtJF5Prqted/dUBwkx+0/FR6ISIj36XFMaWFubTHBiJ5mbKCtot7J +bsIjG1yiIZNchyc3EglSjw7MYzUQDItZWsmn3iTfT+7Bd/JN74jSPHrgEktgb7Zv4jd BJykzF38vx98uB70pngi6XdKW17BOg/fbHJcPlZixJiIBigkHv76bgYpHmRcYXqy0B7R mc0A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=rock-chips.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bl4si22275170ejb.462.2022.02.14.02.07.38; Mon, 14 Feb 2022 02:08:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=rock-chips.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242284AbiBNIoU (ORCPT + 99 others); Mon, 14 Feb 2022 03:44:20 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:43846 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242261AbiBNIoL (ORCPT ); Mon, 14 Feb 2022 03:44:11 -0500 Received: from mail-m17664.qiye.163.com (mail-m17664.qiye.163.com [59.111.176.64]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1907F50E33; Mon, 14 Feb 2022 00:44:03 -0800 (PST) Received: from localhost.localdomain (unknown [58.22.7.114]) by mail-m17664.qiye.163.com (Hmail) with ESMTPA id 535FA1402A3; Mon, 14 Feb 2022 16:44:01 +0800 (CST) From: Jon Lin To: broonie@kernel.org Cc: heiko@sntech.de, linux-spi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org, Jon Lin Subject: [PATCH v2 4/6] spi: rockchip: Preset cs-high and clk polarity in setup progress Date: Mon, 14 Feb 2022 16:43:37 +0800 Message-Id: <20220214084339.18996-5-jon.lin@rock-chips.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220214084339.18996-1-jon.lin@rock-chips.com> References: <20220214084339.18996-1-jon.lin@rock-chips.com> X-HM-Spam-Status: e1kfGhgUHx5ZQUtXWQgPGg8OCBgUHx5ZQUlOS1dZCBgUCR5ZQVlLVUtZV1 kWDxoPAgseWUFZKDYvK1lXWShZQUhPN1dZLVlBSVdZDwkaFQgSH1lBWUJDT0pWTh9CGR0dGkJKQk tMVRMBExYaEhckFA4PWVdZFhoPEhUdFFlBWVVLWQY+ X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6KyI6Mjo*Az5MEhE0Nz0VGSFK DRcwCSpVSlVKTU9PQ0lDSU9KTEhPVTMWGhIXVREUFVUXEhU7CRQYEFYYExILCFUYFBZFWVdZEgtZ QVlOQ1VJSVVMVUpKT1lXWQgBWUFJQkxDNwY+ X-HM-Tid: 0a7ef7672e5cda2fkuws535fa1402a3 X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,RCVD_IN_SORBS_WEB,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org After power up, the cs and clock is in default status, and the cs-high and clock polarity dts property configuration will take no effect until the calling of rockchip_spi_config in the first transmission. So preset them to make sure a correct voltage before the first transmission coming. Signed-off-by: Jon Lin --- Changes in v2: - Limit cs-high presetting to the chip select n <= 1 Changes in v1: None drivers/spi/spi-rockchip.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/drivers/spi/spi-rockchip.c b/drivers/spi/spi-rockchip.c index 5ecd0692cca1..2628cf4e6f3d 100644 --- a/drivers/spi/spi-rockchip.c +++ b/drivers/spi/spi-rockchip.c @@ -713,6 +713,26 @@ static bool rockchip_spi_can_dma(struct spi_controller *ctlr, return xfer->len / bytes_per_word >= rs->fifo_len; } +static int rockchip_spi_setup(struct spi_device *spi) +{ + struct rockchip_spi *rs = spi_controller_get_devdata(spi->controller); + u32 cr0; + + pm_runtime_get_sync(rs->dev); + + cr0 = readl_relaxed(rs->regs + ROCKCHIP_SPI_CTRLR0); + + cr0 |= ((spi->mode & 0x3) << CR0_SCPH_OFFSET); + if (spi->mode & SPI_CS_HIGH && spi->chip_select <= 1) + cr0 |= BIT(spi->chip_select) << CR0_SOI_OFFSET; + + writel_relaxed(cr0, rs->regs + ROCKCHIP_SPI_CTRLR0); + + pm_runtime_put(rs->dev); + + return 0; +} + static int rockchip_spi_probe(struct platform_device *pdev) { int ret; @@ -840,6 +860,7 @@ static int rockchip_spi_probe(struct platform_device *pdev) ctlr->min_speed_hz = rs->freq / BAUDR_SCKDV_MAX; ctlr->max_speed_hz = min(rs->freq / BAUDR_SCKDV_MIN, MAX_SCLK_OUT); + ctlr->setup = rockchip_spi_setup; ctlr->set_cs = rockchip_spi_set_cs; ctlr->transfer_one = rockchip_spi_transfer_one; ctlr->max_transfer_size = rockchip_spi_max_transfer_size; -- 2.17.1