Received: by 10.213.65.68 with SMTP id h4csp3667598imn; Tue, 3 Apr 2018 08:48:40 -0700 (PDT) X-Google-Smtp-Source: AIpwx49nqmN+Omje2aAHXzlCYjqOt1UAvm9W0i5AI/KS9njraJ3nS4ahwWMQYZM8P35x6sVYNOeT X-Received: by 2002:a17:902:9a96:: with SMTP id w22-v6mr14519028plp.209.1522770520427; Tue, 03 Apr 2018 08:48:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522770520; cv=none; d=google.com; s=arc-20160816; b=fWJvz8pMBBsoyk/4yEksugl4ZPAB7eOOGeJxi7WRnokVKJnw3xfluh/x1Xf/VSaM1A utkqjxhLJFQtZETFFoaK3yoFX9DyTl3if33OxvzWJktCM4KFFAxsHCRMImiUO4gDuPzq Oh37MG323OR6E9rP924LoHFh0vXes15xhWxQ494MmCfHUSGEHGiDxcdg1wnGZyF4P+BN HhlGPcSwJ4nlzUOlHsKEomIxbdbQVaoVjp/6CMaoESi7QyfNFEJKTQvIXo2mnmJM5CwW eSu7FsnQIN/1pnycC9mpLfKwf9MYKSwlAfXGHmeXIqjYBIP9GNyTwRJx58cCeitxSCkW M2Ow== 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=OXRm/BdhDcbaZFgYtlMnpQC1Dbc5tlwRiTwPADTii84=; b=iE1xUmnp28KuGrS5pH82fbwhslgvyepYU6as2V+fhE3sDvnG/G1rbEmbuFLiFSYVSy RnjO/nyAPpr+JKqy2HTnrlPgEcXXovThujHOt/nhRdujz2htUeh8DBGLqwqJkQ0Zfd3p eRFi7pxRhixYu75q5Mwv/Js1ISWpNvATSi9UiQyPv5xdBqM/jcpmQucCEUuKUr5V7Kee 6Kc0pe247hDx8Y8WDBmOV/O6oNscAZ0VlYsR9O5Csm/jrXynNDIVSHQo4dQ+NN/TxqjF 0uVB94lttWzcxJjHV+6cp7zCa/jjM8dyU4uK6WQi4hm1KYXTOystEebJ/lRh7LAiYp1/ kSoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@orpaltech.com header.s=mailru header.b=GivvhiiK; 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 a92-v6si3170666pla.107.2018.04.03.08.48.26; Tue, 03 Apr 2018 08:48:40 -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=GivvhiiK; 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 S1752454AbeDCPpA (ORCPT + 99 others); Tue, 3 Apr 2018 11:45:00 -0400 Received: from smtp57.i.mail.ru ([217.69.128.37]:43102 "EHLO smtp57.i.mail.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752258AbeDCPo6 (ORCPT ); Tue, 3 Apr 2018 11:44:58 -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=OXRm/BdhDcbaZFgYtlMnpQC1Dbc5tlwRiTwPADTii84=; b=GivvhiiK49KcunTi5Bhpph5TfcNZxYPo9CHrhVamjEI5S7bIISh8rWgWMJDhTQeNvrZDz0eKwZQrdHZ0URpay9M69WMhC7thSQn/ScyEi7lLKPC/EAvIiQqOOz8jEsCTej5gAMa6KVPlU8f9Z2K2yF36CEHO516+b9csqxAuaGM=; Received: by smtp57.i.mail.ru with esmtpa (envelope-from ) id 1f3O7E-0002Dz-3A; Tue, 03 Apr 2018 18:44:56 +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 v3 3/6] spi: sun6i: restrict transfer length in PIO-mode Date: Tue, 3 Apr 2018 18:44:46 +0300 Message-Id: <20180403154449.2443-4-ssuloev@orpaltech.com> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180403154449.2443-1-ssuloev@orpaltech.com> References: <20180403154449.2443-1-ssuloev@orpaltech.com> Authentication-Results: smtp57.i.mail.ru; auth=pass smtp.auth=ssuloev@orpaltech.com smtp.mailfrom=ssuloev@orpaltech.com X-7FA49CB5: 0D63561A33F958A505A817744D892096840FE9263A247D771AB4854A73F4B921725E5C173C3A84C3A1C30C8AFC676C8B69F971CF7D0B934D6C9A9530EBF72002C4224003CC836476C0CAF46E325F83A50BF2EBBBDD9D6B0F05F538519369F3743B503F486389A921A5CC5B56E945C8DA X-Mailru-Sender: C5364AD02485212F3ACDC11E67D84917604D420E97150EFE699A29BC7B69B943069BFC61DABEEB110841D3AAAB1726C63DDE9B364B0DF289264D2CD8C2503E8C22A194DADEED8EEDCA01A23BA9CD1BE7ED14614B50AE0675 X-Mras: OK Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There is no need to handle 3/4 empty interrupt as the maximum supported transfer length in PIO mode is equal to FIFO depth, i.e. 128 bytes for sun6i and 64 bytes for sun8i SoCs. Changes in v3: 1) Restored processing of 3/4 FIFO full interrupt. Signed-off-by: Sergey Suloev --- drivers/spi/spi-sun6i.c | 41 +++++++++++++++++------------------------ 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/drivers/spi/spi-sun6i.c b/drivers/spi/spi-sun6i.c index 78acc1f..c09ad10 100644 --- a/drivers/spi/spi-sun6i.c +++ b/drivers/spi/spi-sun6i.c @@ -207,7 +207,10 @@ static void sun6i_spi_set_cs(struct spi_device *spi, bool enable) static size_t sun6i_spi_max_transfer_size(struct spi_device *spi) { - return SUN6I_MAX_XFER_SIZE - 1; + struct spi_master *master = spi->master; + struct sun6i_spi *sspi = spi_master_get_devdata(master); + + return sspi->fifo_depth; } static int sun6i_spi_prepare_message(struct spi_master *master, @@ -255,8 +258,14 @@ static int sun6i_spi_transfer_one(struct spi_master *master, int ret = 0; u32 reg; - if (tfr->len > SUN6I_MAX_XFER_SIZE) - return -EINVAL; + /* A zero length transfer never finishes if programmed + in the hardware */ + if (!tfr->len) + return 0; + + /* Don't support transfer larger than the FIFO */ + if (tfr->len > sspi->fifo_depth) + return -EMSGSIZE; reinit_completion(&sspi->done); sspi->tx_buf = tfr->tx_buf; @@ -278,8 +287,7 @@ static int sun6i_spi_transfer_one(struct spi_master *master, */ trig_level = sspi->fifo_depth / 4 * 3; sun6i_spi_write(sspi, SUN6I_FIFO_CTL_REG, - (trig_level << SUN6I_FIFO_CTL_RF_RDY_TRIG_LEVEL_BITS) | - (trig_level << SUN6I_FIFO_CTL_TF_ERQ_TRIG_LEVEL_BITS)); + (trig_level << SUN6I_FIFO_CTL_RF_RDY_TRIG_LEVEL_BITS)); reg = sun6i_spi_read(sspi, SUN6I_TFR_CTL_REG); @@ -343,11 +351,8 @@ static int sun6i_spi_transfer_one(struct spi_master *master, sun6i_spi_fill_fifo(sspi, sspi->fifo_depth); /* Enable the interrupts */ - sun6i_spi_write(sspi, SUN6I_INT_CTL_REG, SUN6I_INT_CTL_TC); sun6i_spi_enable_interrupt(sspi, SUN6I_INT_CTL_TC | SUN6I_INT_CTL_RF_RDY); - if (tx_len > sspi->fifo_depth) - sun6i_spi_enable_interrupt(sspi, SUN6I_INT_CTL_TF_ERQ); /* Start the transfer */ reg = sun6i_spi_read(sspi, SUN6I_TFR_CTL_REG); @@ -376,7 +381,9 @@ out: static irqreturn_t sun6i_spi_handler(int irq, void *dev_id) { struct sun6i_spi *sspi = dev_id; - u32 status = sun6i_spi_read(sspi, SUN6I_INT_STA_REG); + u32 status; + + status = sun6i_spi_read(sspi, SUN6I_INT_STA_REG); /* Transfer complete */ if (status & SUN6I_INT_CTL_TC) { @@ -388,26 +395,12 @@ static irqreturn_t sun6i_spi_handler(int irq, void *dev_id) /* Receive FIFO 3/4 full */ if (status & SUN6I_INT_CTL_RF_RDY) { - sun6i_spi_drain_fifo(sspi, SUN6I_FIFO_DEPTH); + sun6i_spi_drain_fifo(sspi, sspi->fifo_depth); /* Only clear the interrupt _after_ draining the FIFO */ sun6i_spi_write(sspi, SUN6I_INT_STA_REG, SUN6I_INT_CTL_RF_RDY); return IRQ_HANDLED; } - /* Transmit FIFO 3/4 empty */ - if (status & SUN6I_INT_CTL_TF_ERQ) { - sun6i_spi_fill_fifo(sspi, SUN6I_FIFO_DEPTH); - - if (!sspi->len) - /* nothing left to transmit */ - sun6i_spi_disable_interrupt(sspi, SUN6I_INT_CTL_TF_ERQ); - - /* Only clear the interrupt _after_ re-seeding the FIFO */ - sun6i_spi_write(sspi, SUN6I_INT_STA_REG, SUN6I_INT_CTL_TF_ERQ); - - return IRQ_HANDLED; - } - return IRQ_NONE; } -- 2.16.2