Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp543058imm; Wed, 23 May 2018 01:10:48 -0700 (PDT) X-Google-Smtp-Source: AB8JxZp4ZTtCXEZnRO0+svh42NlDgQlhqHxjazkGrmtKUwEYbRUN0lPgBPfxgVPbyV9veRmwdSGM X-Received: by 2002:a63:a05d:: with SMTP id u29-v6mr1530049pgn.80.1527063048793; Wed, 23 May 2018 01:10:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527063048; cv=none; d=google.com; s=arc-20160816; b=Zk3GiiwgJ/5XhbLDZ+21jGLmZAI+i7kZRUNct3O6lH7P6YZUHuLGIlROPKwnQfVBQR djGDi/VmZj6peY/IfqUSWmJD4B0R8yyGs8nDhRZN2dorUhcXSYNu5Pq0tV6vqrF1nUIx s/8X86SshS7+NkggZ2Kxe5dtwxL180g9C/7ookeox4wqDFoItivavDL4ZbuZxqxk7wge iWdRtHVy1RdfoO7uFpwNJ7CuLqcH5lqbjbTmHLuvPohlDBvFTYyoyZhpR+NR1epNjm2B 8FsxEJPejW0XtKZibRB2AWaGAZXmqA3hfwxxyXPTGLEJQ+3x71p6J8QHyNr6pDvjyqhD osVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=DNt9KVUZIVnJif6Z/ALPGZAs7lpEks1HSkIoPuq2YDc=; b=jAYDR/RZIjdA6o5pND7y9Z34Gm1CO6F9hQ9iyHbsuYtY+jyxJRF5fNiv2/qnBT/ppG LtdF1Mx8H3ar8WHeJP7mXzeo5tDz1CG8icJTM0CJF1H0H4vavgDtRWhtMxzGpHWQIP9j 7fYJ0Xe17eUkFGw2s+LbP21h4ugvQgjiyYgER08SFx83ykAENve8KUnKhjnJ7cwAkOk1 ppoJTThQe6C/8lNqkKgfLxAg2u9N6rEfFFGrtPEKq5X7zQLDVj7qii6HDnxXm7fCtjcT o+s/pTWVdQL+q+NA50Q7uUg/XIcQM2uAhIBvfEeBgScyxS2uJXXp0L48euyh3v861aEj oIIQ== ARC-Authentication-Results: i=1; mx.google.com; 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 k9-v6si14535481pgo.340.2018.05.23.01.10.34; Wed, 23 May 2018 01:10:48 -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; 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 S1754448AbeEWIJU (ORCPT + 99 others); Wed, 23 May 2018 04:09:20 -0400 Received: from esa3.microchip.iphmx.com ([68.232.153.233]:1954 "EHLO esa3.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754266AbeEWIJQ (ORCPT ); Wed, 23 May 2018 04:09:16 -0400 X-IronPort-AV: E=Sophos;i="5.49,432,1520924400"; d="scan'208";a="14563992" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa3.microchip.iphmx.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 23 May 2018 01:09:15 -0700 Received: from [10.145.4.57] (10.10.76.4) by chn-sv-exch06.mchp-main.com (10.10.76.107) with Microsoft SMTP Server id 14.3.352.0; Wed, 23 May 2018 01:09:14 -0700 Subject: Re: [PATCH v3 5/6] spi: at91-usart: add driver for at91-usart as spi To: Mark Brown CC: , , , , , , , , , , , , References: <20180511103822.31698-1-radu.pirea@microchip.com> <20180511103822.31698-6-radu.pirea@microchip.com> <20180517050406.GF20254@sirena.org.uk> From: Radu Pirea Message-ID: <6a59e071-3159-4939-8535-6c7a9d491379@microchip.com> Date: Wed, 23 May 2018 11:10:28 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: <20180517050406.GF20254@sirena.org.uk> Content-Type: text/plain; charset="windows-1252"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 05/17/2018 08:04 AM, Mark Brown wrote: > On Fri, May 11, 2018 at 01:38:21PM +0300, Radu Pirea wrote: > >> +config SPI_AT91_USART >> + tristate "Atmel USART Controller as SPI" >> + depends on HAS_DMA >> + depends on (ARCH_AT91 || COMPILE_TEST) >> + select MFD_AT91_USART >> + help >> + This selects a driver for the AT91 USART Controller as SPI Master, >> + present on AT91 and SAMA5 SoC series. >> + > > This looks like there's some tab/space mixing going on here. > >> +// SPDX-License-Identifier: GPL-2.0 >> +/* >> + * Driver for AT91 USART Controllers as SPI >> + * >> + * Copyright (C) 2018 Microchip Technology Inc. > > Make the entire block a C++ comment so it looks more intentional rather > tha mixing C and C++. Hi Mark, I know it's ugly, but SPDX license identifier must be in a separate comment block. > >> +static inline void at91_usart_spi_tx(struct at91_usart_spi *aus) >> +{ >> + unsigned int len = aus->current_transfer->len; >> + unsigned int remaining = aus->current_tx_remaining_bytes; >> + const u8 *tx_buf = aus->current_transfer->tx_buf; >> + >> + if (tx_buf && remaining) { >> + if (at91_usart_spi_tx_ready(aus)) >> + spi_writel(aus, THR, tx_buf[len - remaining]); >> + aus->current_tx_remaining_bytes--; > > Missing braces here - we only write to the FIFO if there's space but we > unconditionally decrement the counter. > Thanks. I will fix it. >> + } else { >> + if (at91_usart_spi_tx_ready(aus)) >> + spi_writel(aus, THR, US_DUMMY_TX); >> + } >> +} > > This looks like you're open coding SPI_CONTROLLER_MUST_TX > >> + int len = aus->current_transfer->len; >> + int remaining = aus->current_rx_remaining_bytes; >> + u8 *rx_buf = aus->current_transfer->rx_buf; >> + >> + if (aus->current_rx_remaining_bytes) { >> + rx_buf[len - remaining] = spi_readb(aus, RHR); >> + aus->current_rx_remaining_bytes--; >> + } else { >> + spi_readb(aus, RHR); >> + } > > Similarly for _MUST_RX. > >> + controller->flags = SPI_MASTER_MUST_RX | SPI_MASTER_MUST_TX; > > You're actually setting both flags... this means that the handling for > cases with missing TX or RX buffers can't happen. Sorry. My mistake. I will remove unnecessary code.