Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp3450386imm; Tue, 29 May 2018 07:28:52 -0700 (PDT) X-Google-Smtp-Source: AB8JxZp/VqZr46AfB1IsweNxZ5NGQ6incM83caGlX0GK/B4jwJW7cU15sOhrjEPI+lg0HMsOslEP X-Received: by 2002:a63:7145:: with SMTP id b5-v6mr14156621pgn.45.1527604132192; Tue, 29 May 2018 07:28:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527604132; cv=none; d=google.com; s=arc-20160816; b=Xpz8jDHiUS9aDiZwoFhmRf47xpw3OwDe7N04zOlIr9M94CWfuln/skI5cn6iZnwhUU ode2pKZKGuT2H0dCfS3C0HpgPkBmGzmREdC8LfAbIRNrSPMoGM5AFS2uSLIZ7A2XoJ7e N24uA+lILVnGEQA/31VKbMS5Lx7AcDORLL60R9VGtoxoL/J4Ow1C2ZNAa6Pm9DcRoki4 ijmid0Zsklqk0DNCz/1Z1LXiT8g7My5m2+v0ZAvyTnPI/nLphbKK6zYzTgl0xdsRH8aB 879QcIs8P/J5CuAK2F/cbA971QumiAcMycxfpVzKngzUJAGHROktDtdbibLLurVUPAjy Ok2A== 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=6ygL/83tSPZ6p/y6DpAP71Kb0uaAOuRHljWV1uOBxYQ=; b=odC2scwB+N8oP7n4/7WAbZ8DzFpzpRlmkpWx5qEBCtrRfxgX6eBooUSiUdMC1kPpgV k3fb0xneF1JPFyLUhv8AkQr/HvmJuQJsopu26iLXlvXgk34E+Syjr2Z+bi91lNe16pXl EOHbfT5dOyl938dXqXU14sLNANMEElt/Uy4tE5l5c2uWvKWwzFhMhdVPfRHKYR2PqOPi 8mlt8nVcjOMCMZtl1wtKJYN4eOxTdHhhJee2Jq8iSQZJqNNA8Wu5JB4fhSrfB+SyfkOp xvj0QPSzPly5z9xKmpG3kcCybkKrGDUJp/9Y3YkwNX0b0qhpux0Ab7fgmZopVAqgej6l Q28w== 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 d15-v6si12269668pgu.21.2018.05.29.07.28.37; Tue, 29 May 2018 07:28:52 -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 S935272AbeE2O1i (ORCPT + 99 others); Tue, 29 May 2018 10:27:38 -0400 Received: from esa1.microchip.iphmx.com ([68.232.147.91]:14140 "EHLO esa1.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934861AbeE2O1b (ORCPT ); Tue, 29 May 2018 10:27:31 -0400 X-IronPort-AV: E=Sophos;i="5.49,456,1520924400"; d="scan'208";a="15402368" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa1.microchip.iphmx.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 29 May 2018 07:27:30 -0700 Received: from [10.145.4.57] (10.10.76.4) by chn-sv-exch07.mchp-main.com (10.10.76.108) with Microsoft SMTP Server id 14.3.352.0; Tue, 29 May 2018 07:27:29 -0700 Subject: Re: [PATCH v4 5/6] spi: at91-usart: add driver for at91-usart as spi To: Andy Shevchenko CC: Mark Brown , Nicolas Ferre , , Lee Jones , Richard Genoud , Rob Herring , Mark Rutland , Greg Kroah-Hartman , linux-spi , linux-arm Mailing List , Linux Kernel Mailing List , devicetree , "open list:SERIAL DRIVERS" References: <20180525171941.26766-1-radu.pirea@microchip.com> <20180525171941.26766-6-radu.pirea@microchip.com> From: Radu Pirea Message-ID: <110bb353-b131-348c-8e26-9863b074142d@microchip.com> Date: Tue, 29 May 2018 17:28:37 +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: Content-Type: text/plain; charset="utf-8"; 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/28/2018 11:21 AM, Andy Shevchenko wrote: > On Fri, May 25, 2018 at 8:19 PM, Radu Pirea wrote: >> This is the driver for at91-usart in spi mode. The USART IP can be configured >> to work in many modes and one of them is SPI. >> >> The driver was tested on sama5d3-xplained and sama5d4-xplained boards with >> enc28j60 ethernet controller as slave. > >> +#include > > What is the use of it? I need of_gpio.h for of_gpio_named_count, of_get_named_gpio and devm_gpio_request_one(found in gpio.h) > >> +#define US_INIT (US_MR_SPI_MASTER | US_MR_CHRL | US_MR_CLKO | \ >> + US_MR_WRDBT) > > Don't split lines like this, it's hard to read. > > #define FOO \ > (BAR1 | BAR2) I'll fix it. > > I think I already told this to someone recently, maybe to you. > >> +/* Register access macros */ >> +#define spi_readl(port, reg) \ >> + readl_relaxed((port)->regs + US_##reg) >> +#define spi_writel(port, reg, value) \ >> + writel_relaxed((value), (port)->regs + US_##reg) >> + >> +#define spi_readb(port, reg) \ >> + readb_relaxed((port)->regs + US_##reg) >> +#define spi_writeb(port, reg, value) \ >> + writeb_relaxed((value), (port)->regs + US_##reg) > > Names are too generic. You better to use the same prefix as for the > rest, i.e. at91_spi_ Good ideea. I will change the names. > >> + /*used in interrupt to protect data reading*/ > > Comment style. > > You need to read some existing code, perhaps, to see how it's done. Ok. I will add the comment. > >> +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 (remaining) >> + if (at91_usart_spi_tx_ready(aus)) { > > if (x) { > if (y) { > ... > } > } > > is equivalent to if (x && y) {}. > > Though, considering your intention here, I would rather go with better > pattern, i.e. > > if (!remaining) > return; Thank for suggestion. I will change. > >> + spi_writeb(aus, THR, tx_buf[len - remaining]); >> + aus->current_tx_remaining_bytes--; >> + } >> +} >> + >> +static inline void at91_usart_spi_rx(struct at91_usart_spi *aus) >> +{ > >> + if (remaining) { >> + rx_buf[len - remaining] = spi_readb(aus, RHR); >> + aus->current_rx_remaining_bytes--; >> + } > > Ditto. > >> +} > > >> +static int at91_usart_gpio_setup(struct platform_device *pdev) >> +{ > >> + struct device_node *np = pdev->dev.parent->of_node; > > Your driver is not OF specific as far as I can see. Drop all these > device_node stuff and change API calls respectively. Ok. What do you suggest to use instead of OF API to get the count of cs-gpios and to read their values one by one? > >> + int i; > >> + int ret = 0; >> + int nb = 0; > > What happened to indentation? > > Redundnant assignment for both. > >> + if (!np) >> + return -EINVAL; >> + >> + nb = of_gpio_named_count(np, "cs-gpios"); >> + for (i = 0; i < nb; i++) { >> + int cs_gpio = of_get_named_gpio(np, "cs-gpios", i); >> + >> + if (cs_gpio < 0) >> + return cs_gpio; >> + >> + if (gpio_is_valid(cs_gpio)) { >> + ret = devm_gpio_request_one(&pdev->dev, cs_gpio, >> + GPIOF_DIR_OUT, >> + dev_name(&pdev->dev)); >> + if (ret) >> + return ret; >> + } >> + } >> + >> + return 0; >> +} >> + >> +static int at91_usart_spi_probe(struct platform_device *pdev) >> +{ > >> + regs = platform_get_resource(to_platform_device(pdev->dev.parent), >> + IORESOURCE_MEM, 0); >> + if (!regs) >> + return -EINVAL; > > This looks weird. Supply resource to _this_ device in your MFD code. I know weird, but is the safest way to pass the resource and the of_node. > >> + dev_info(&pdev->dev, >> + "Atmel USART SPI Controller version 0x%x at 0x%08lx (irq %d)\n", >> + spi_readl(aus, VERSION), >> + (unsigned long)regs->start, irq); > > I think I already told you, don't use explicit casting when print. > If it wasn't you, do you homework then. But above is no go. > >> + return 0; > >> +static struct platform_driver at91_usart_spi_driver = { >> + .driver = { >> + .name = "at91_usart_spi", > >> + .of_match_table = of_match_ptr(at91_usart_spi_dt_ids), > > Drop of_match_ptr(). It's not needed. > >> + }, >> + .probe = at91_usart_spi_probe, > >> + .remove = at91_usart_spi_remove, }; > > Already told ya, split lines correctly. >