Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2098250imm; Mon, 28 May 2018 01:24:09 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqIqeKASGdcoB6y7Ukhb03tatzmPf1BPd/mluafBK00rbKp3vkmElIpx6tmp9RLRM0ceAYY X-Received: by 2002:a63:7d47:: with SMTP id m7-v6mr9829847pgn.443.1527495849347; Mon, 28 May 2018 01:24:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527495849; cv=none; d=google.com; s=arc-20160816; b=TOEukgmFaCF/sEKBnxs7z9IVJll+VTkWxRlyT221ssg4aLrO0vu0iJcmImLs7BrXaq cOfQfOaoWUGkahlbL06mIqESntCfDxOwGj4idcX4kFz5pUlX/+18reQ7el9V2T9IFtPa QGcRJUj/3po+wNP5j/reRCJ4ikWHTSMi4OT3rtpXg0i/6/X5/iPdaz1lHmlPl72ftN+A U3DKp9vzMx7BDTBHrMn8FWcXiv9CJLqUJ21P1Uugr+90OXJN4D21yI9lRWgmajVNZfbO Qoflvnyl0WFxQ78q16qSRrbDkuJqEnlbNCBWcG17EYVdhVXQ80g9UuhH3/eLpN8CXqK6 O0rA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=s05KWQ7r3PqSjFPTDwH6VyFikb1Q9lGk8u67qIbkxHE=; b=p5PuWLr7CWDQnM6Q/mWbSfc8pdQPtRe6ajXKYPqK/d52eybdp4TFfOOixbrZlxq583 +S/5dzCQ8MJpRqK6BwEUltaOx+2xo4VpuxZlNc5sbs/AACmWdEaMxvtaRV8bHiPvbRNq 24T4sCjCLZAXocCGD5FkYhghWnNaj0hBCrjfg5/5ZZuO59el8HG+ewJiCf1l4GIXDSSN gDPkySY4QQQkxSFfRHU4swFVWmDV65orFXgsvObtctH2m2B46EQ80dWqQDS1Q2ZYnrgM I8y1PzVWjO7lylV8+HaoQeY2Ymx9TAgVXslcFcOOhfAEYkjtGZnqkC3vCSoBmJjk9OuK Joxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=IvejCD0+; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d77-v6si181046pfb.262.2018.05.28.01.23.43; Mon, 28 May 2018 01:24:09 -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=@gmail.com header.s=20161025 header.b=IvejCD0+; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754019AbeE1IVd (ORCPT + 99 others); Mon, 28 May 2018 04:21:33 -0400 Received: from mail-qt0-f195.google.com ([209.85.216.195]:37742 "EHLO mail-qt0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753932AbeE1IV2 (ORCPT ); Mon, 28 May 2018 04:21:28 -0400 Received: by mail-qt0-f195.google.com with SMTP id q13-v6so14015246qtp.4; Mon, 28 May 2018 01:21:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=s05KWQ7r3PqSjFPTDwH6VyFikb1Q9lGk8u67qIbkxHE=; b=IvejCD0+wHUezTp9h0b/tMHjKVVlw/3/eAMh0Bli0iKk3Ee4aUHL3BLy8LoE6GyIKR GdQVHAxhQKx7icrJUDd+Lg1OO6o5WMoDLueV7bJiM3kXHKM8C1qXOqA9mQ9m2hZ47/WN XssMPwaSqRorVUWf7LorngYULsZtqwg6WKHNeIn2LJEBnXlT5GFcrnWkHDcURSaaYRmM /4S0RYKhaYfgTylQgRqBcrkD+0isotYtVuiJEJqQv07VhQMNmleeE8oiumyefk9AQaug aIv1OOGekVMNYo7QNoOLJpQQthDmClC+szz3ajYFCet4wYSMYXsyH3Q4YUKCQhJlESOH /8kg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=s05KWQ7r3PqSjFPTDwH6VyFikb1Q9lGk8u67qIbkxHE=; b=Xk0w5QnPdajJiV0wY7U9h7xSqY3iPcucqJyTduHawfXFPielsmpvDdnEUxArFCmRVl 1GQtY/VSIz3VhFqnv1OUx/pyVzjCSMzZpfwaJU1Gcg8mPCKSywOERf+SrDCjJZLgvhkE HGesh/I4kXVWCC/3nJg4qSnR6YEU7SHAOmAuu2Z3Kx4V1YyVKx1KA4QNsqvpoHFH9fSY w3l6zDirqpxkE7zlkt48lArkkUi15+yhcIp1x0xT5BlwTSlSzLXfvHqVQRH2HFs6kmoh tJx/U5CZ+NOkMMhMuClXdg7joAGDMXP7omcU+znIz5avTlHPyOoaP81bZknBQ19Ftmp0 8v9A== X-Gm-Message-State: ALKqPwf7a9fnpuA0WaggrC+e7aq5X6+3FXWPtK+RqdmXp23Yq8y+PVfp jM4p12tCLu7qGJ8qQfWsCd7sBzKhHxqOdFepHt0kvg== X-Received: by 2002:ac8:190c:: with SMTP id t12-v6mr3898172qtj.278.1527495687415; Mon, 28 May 2018 01:21:27 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a0c:9896:0:0:0:0:0 with HTTP; Mon, 28 May 2018 01:21:26 -0700 (PDT) In-Reply-To: <20180525171941.26766-6-radu.pirea@microchip.com> References: <20180525171941.26766-1-radu.pirea@microchip.com> <20180525171941.26766-6-radu.pirea@microchip.com> From: Andy Shevchenko Date: Mon, 28 May 2018 11:21:26 +0300 Message-ID: Subject: Re: [PATCH v4 5/6] spi: at91-usart: add driver for at91-usart as spi To: Radu Pirea Cc: Mark Brown , Nicolas Ferre , alexandre.belloni@bootlin.com, 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" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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? > +#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 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_ > + /*used in interrupt to protect data reading*/ Comment style. You need to read some existing code, perhaps, to see how it's done. > +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; > + 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. > + 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. > + 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. -- With Best Regards, Andy Shevchenko