Received: by 10.213.65.68 with SMTP id h4csp3650276imn; Tue, 3 Apr 2018 08:31:02 -0700 (PDT) X-Google-Smtp-Source: AIpwx487nHseNj3lCM+y+EyCsKfPVNCmaX+rpPhXn61Gv9fk8wgxBYqBkukwCNTc1KCJoy728zBF X-Received: by 2002:a17:902:9a44:: with SMTP id x4-v6mr14602870plv.312.1522769462191; Tue, 03 Apr 2018 08:31:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522769462; cv=none; d=google.com; s=arc-20160816; b=P8NA1u4QjK/UebL3n5M4oMZ75TxjWcfADBubFML+7Z6dkEThbK4B7DE3/JyHL8GQyU EA+0cKhcP+6NIgzrOlfKF1aXbbRLV0WcvTNZoh/PC3X9P5VsPgOugyfCwTIEEc+7nS+T iU31wGOqitWZTnMAe4lGCkk+fUmV+90ftq11vWupt5soC91gGAAqMyX8Hw7uVedRpFCs 5cMsauwEXheXIhSe8ZBMdrfiduFgTV+Iu0Vkf/SIKiCmNhndjFFNKnB24oedZQpV0QAZ 9bImxQABXXMHVzgLQPSG0jZa4HcjaSZelDP5n6hviB+8nZqbkzQwp340p8/MSlkpIUbn B/sw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=rO19aE9aM8tR0CS5Kb4BSOHI6EyKA2kRE0IFCmq1hWg=; b=mlx31LURZkDrDBhPfs2f6lcBt8zYJwmMF0SF6VyRp+YbKuhUKfIqeLMs7U8XZ04oKv oWggzCbzPyvSZMpesrA55oPoYWhTMmTCDl3fRr3AadlmTa4Ts9nn2wkNKizptAV/sMT9 V/McLlBcmtVIoPkhB65cN0f655eXYoggZZ3eCMS5G/9veMDQbcaT1txyRw/ieGVH1Iw+ S+1oE+iyoCTR2McFFqbw+T3lVlJQyExXJ1874ABT5BVZmQ0dxaZ69rpVitOpCTMP8kvF fMRJqY4oNadBwxiSRB814CwDvGAgqon8zTk/hlZZweSt8Ic+ytWHu48tQkdxl5MA8Spe NOjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@orpaltech.com header.s=mailru header.b=ngL+g85s; 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 f6-v6si762172plf.70.2018.04.03.08.30.48; Tue, 03 Apr 2018 08:31:02 -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=@orpaltech.com header.s=mailru header.b=ngL+g85s; 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 S1752447AbeDCP3h (ORCPT + 99 others); Tue, 3 Apr 2018 11:29:37 -0400 Received: from smtp54.i.mail.ru ([217.69.128.34]:34306 "EHLO smtp54.i.mail.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752079AbeDCP3Q (ORCPT ); Tue, 3 Apr 2018 11:29:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=orpaltech.com; s=mailru; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=rO19aE9aM8tR0CS5Kb4BSOHI6EyKA2kRE0IFCmq1hWg=; b=ngL+g85sNTzRR4dkbx/OrQHfY6R3rp8pTpo+wTW30aS89qrG37a354GhV/c5cLFWPTNsG1i/7MXt9TmTecieGbvG0By9S+qPy3HT6/CbOADHueIQ99m+b9iUiMJpKB+1sIn1+CmGvCrLfap6AFTvy5uohT2fnsPXO12Ny+1qmV8=; Received: by smtp54.i.mail.ru with esmtpa (envelope-from ) id 1f3Ns2-0003oL-GP; Tue, 03 Apr 2018 18:29:15 +0300 From: Sergey Suloev To: Mark Brown , Maxime Ripard , Chen-Yu Tsai Cc: linux-spi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Sergey Suloev Subject: [PATCH v2 5/6] spi: sun4i: introduce register set/unset helpers Date: Tue, 3 Apr 2018 18:29:04 +0300 Message-Id: <20180403152905.1524-6-ssuloev@orpaltech.com> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180403152905.1524-1-ssuloev@orpaltech.com> References: <20180403152905.1524-1-ssuloev@orpaltech.com> Authentication-Results: smtp54.i.mail.ru; auth=pass smtp.auth=ssuloev@orpaltech.com smtp.mailfrom=ssuloev@orpaltech.com X-7FA49CB5: 0D63561A33F958A599C85922B24F2F2EFD153644D6503B5897EC0D2FCC39F5ED725E5C173C3A84C3A1C30C8AFC676C8B00932676BA91E3DEC96613F75B7D048DC4224003CC836476C0CAF46E325F83A50BF2EBBBDD9D6B0F05F538519369F3743B503F486389A921A5CC5B56E945C8DA X-Mailru-Sender: C5364AD02485212F3ACDC11E67D849172D9EF3D5532EE6439962E812D144211F069BFC61DABEEB110841D3AAAB1726C63DDE9B364B0DF289264D2CD8C2503E8C22A194DADEED8EEDCA01A23BA9CD1BE7ED14614B50AE0675 X-Mras: OK Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Two helper functions were added in order to set/unset specified flags in registers. Signed-off-by: Sergey Suloev --- drivers/spi/spi-sun4i.c | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/drivers/spi/spi-sun4i.c b/drivers/spi/spi-sun4i.c index 9d1bc20..d81d31c 100644 --- a/drivers/spi/spi-sun4i.c +++ b/drivers/spi/spi-sun4i.c @@ -107,29 +107,29 @@ static inline void sun4i_spi_write(struct sun4i_spi *sspi, u32 reg, u32 value) writel(value, sspi->base_addr + reg); } -static inline u32 sun4i_spi_get_tx_fifo_count(struct sun4i_spi *sspi) +static inline void sun4i_spi_set(struct sun4i_spi *sspi, u32 addr, u32 val) { - u32 reg = sun4i_spi_read(sspi, SUN4I_FIFO_STA_REG); - - reg >>= SUN4I_FIFO_STA_TF_CNT_BITS; + u32 reg = sun4i_spi_read(sspi, addr); - return reg & SUN4I_FIFO_STA_TF_CNT_MASK; + reg |= val; + sun4i_spi_write(sspi, addr, reg); } -static inline void sun4i_spi_enable_interrupt(struct sun4i_spi *sspi, u32 mask) +static inline void sun4i_spi_unset(struct sun4i_spi *sspi, u32 addr, u32 val) { - u32 reg = sun4i_spi_read(sspi, SUN4I_INT_CTL_REG); + u32 reg = sun4i_spi_read(sspi, addr); - reg |= mask; - sun4i_spi_write(sspi, SUN4I_INT_CTL_REG, reg); + reg &= ~val; + sun4i_spi_write(sspi, addr, reg); } -static inline void sun4i_spi_disable_interrupt(struct sun4i_spi *sspi, u32 mask) +static inline u32 sun4i_spi_get_tx_fifo_count(struct sun4i_spi *sspi) { - u32 reg = sun4i_spi_read(sspi, SUN4I_INT_CTL_REG); + u32 reg = sun4i_spi_read(sspi, SUN4I_FIFO_STA_REG); - reg &= ~mask; - sun4i_spi_write(sspi, SUN4I_INT_CTL_REG, reg); + reg >>= SUN4I_FIFO_STA_TF_CNT_BITS; + + return reg & SUN4I_FIFO_STA_TF_CNT_MASK; } static inline void sun4i_spi_drain_fifo(struct sun4i_spi *sspi, int len) @@ -256,13 +256,12 @@ static int sun4i_spi_transfer_one(struct spi_master *master, /* Clear pending interrupts */ sun4i_spi_write(sspi, SUN4I_INT_STA_REG, ~0); + /* Reset FIFOs */ + sun4i_spi_set(sspi, SUN4I_CTL_REG, + SUN4I_CTL_RF_RST | SUN4I_CTL_TF_RST); reg = sun4i_spi_read(sspi, SUN4I_CTL_REG); - /* Reset FIFOs */ - sun4i_spi_write(sspi, SUN4I_CTL_REG, - reg | SUN4I_CTL_RF_RST | SUN4I_CTL_TF_RST); - /* * Setup the transfer control register: Chip Select, * polarities, etc. @@ -342,12 +341,11 @@ static int sun4i_spi_transfer_one(struct spi_master *master, sun4i_spi_fill_fifo(sspi, SUN4I_FIFO_DEPTH); /* Enable the interrupts */ - sun4i_spi_enable_interrupt(sspi, SUN4I_INT_CTL_TC | - SUN4I_INT_CTL_RF_F34); + sun4i_spi_set(sspi, SUN4I_INT_CTL_REG, SUN4I_INT_CTL_TC | + SUN4I_INT_CTL_RF_F34); /* Start the transfer */ - reg = sun4i_spi_read(sspi, SUN4I_CTL_REG); - sun4i_spi_write(sspi, SUN4I_CTL_REG, reg | SUN4I_CTL_XCH); + sun4i_spi_set(sspi, SUN4I_CTL_REG, SUN4I_CTL_XCH); ret = sun4i_spi_wait_for_transfer(spi, tfr); -- 2.16.2