Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp337331imm; Tue, 15 May 2018 02:24:38 -0700 (PDT) X-Google-Smtp-Source: AB8JxZp7acHO9XW/guci1xjQhTY81IAkhcp7QvhpTmwqiAU+BUTQx5yeYY1z9z+kQKB1qrtDSTlx X-Received: by 2002:a63:77c9:: with SMTP id s192-v6mr11675508pgc.364.1526376278020; Tue, 15 May 2018 02:24:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526376277; cv=none; d=google.com; s=arc-20160816; b=zhXfnmGwe23DnIX1ciL9sI+IHijOyPpL/6mcmA4TuxhkryG6YPT8N2GvUcRV/uXtR7 /yHz2VEt7qtqlMg/XtgKHorzcgJMwjFDNVBmQYTNCYFsh4ZKNINGEI4iK4rqSImVPcYw 8/nuEp3AltSpOwfInbeMWLgxgUBUoptIWWRbeNff8N7z4D95J/vdSvli/e75iC91jVVF nCPTwsvccaxsztXr7M9Dm6IA81l91nfU1DJr2kMfAyCHC9waooCG3wufajZuFPYsXCk3 hNvVnQWxQ4o0SbS7EaatPIKaArI8OFWOSY3+SD4sqhPR4JmLQm6hFti0oAzIOWggotVk 7Fbg== 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:mime-version :references:in-reply-to:date:cc:to:from:subject:message-id :arc-authentication-results; bh=8K98yKojlIhuDQKmvvh4MWHLKKd6cMd6qPuftBsN9/c=; b=1EgmNatb+KxgIpx9AW6yCo41h63lhhOk+za/7U5oUa3M6r3C8HngGDMV8Y1Zy5oDgV /xln20zocqAE9R3LB5c9r5rMHTXfmCdOb5keaDqLcXvuz1UmlvOMAqscQT33NtgUMEdD Lz5T4gyJY+CqHWUMDkti0abjKpESMk9SQ93I+DIPSB+yjsVKF9oX+Sv4qch/Dj6BnWL5 HtMTPPPGLXTYi3dq0i4KFj7/dPnsGIIaB6l+Kl4kJfumDAC4fCVfaGs058xmuaQbauj9 wyKsDrRRUOngB4B2ZpxCKGSvcDxkWj2zW7dXdS9krzz0FzoEVDSzlvCmoI2Rv+2pXYCt HEkA== 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 33-v6si8118242plt.596.2018.05.15.02.24.23; Tue, 15 May 2018 02:24:37 -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 S1752644AbeEOJYC (ORCPT + 99 others); Tue, 15 May 2018 05:24:02 -0400 Received: from esa3.microchip.iphmx.com ([68.232.153.233]:23635 "EHLO esa3.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752495AbeEOJX7 (ORCPT ); Tue, 15 May 2018 05:23:59 -0400 X-IronPort-AV: E=Sophos;i="5.49,403,1520924400"; d="scan'208";a="14262232" 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; 15 May 2018 02:23:58 -0700 Received: from m19893 (10.10.76.4) by chn-sv-exch05.mchp-main.com (10.10.76.106) with Microsoft SMTP Server id 14.3.352.0; Tue, 15 May 2018 02:23:57 -0700 Message-ID: <49c13a964f517c9c90e61beda327d4174fd1358c.camel@microchip.com> Subject: Re: [PATCH v3 5/6] spi: at91-usart: add driver for at91-usart as spi From: Radu Pirea To: Andy Shevchenko CC: devicetree , "open list:SERIAL DRIVERS" , Linux Kernel Mailing List , linux-arm Mailing List , linux-spi , Mark Rutland , "Rob Herring" , Lee Jones , "Greg Kroah-Hartman" , Jiri Slaby , Richard Genoud , , Nicolas Ferre , Mark Brown Date: Tue, 15 May 2018 12:25:10 +0300 In-Reply-To: References: <20180511103822.31698-1-radu.pirea@microchip.com> <20180511103822.31698-6-radu.pirea@microchip.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.28.2 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, 2018-05-13 at 16:33 +0300, Andy Shevchenko wrote: > On Fri, May 11, 2018 at 1:38 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. > > +#include > > +#include > > Here is something wrong. You need to use latter one in new code. > > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > Hmm... Do you need all of them? > > > +static inline void at91_usart_spi_cs_activate(struct spi_device > > *spi) > > +{ > > ... > > + gpiod_set_value(ausd->npcs_pin, active); > > + aus->cs_active = true; > > +} > > + > > +static inline void at91_usart_spi_cs_deactivate(struct spi_device > > *spi) > > +{ > > ... > > + gpiod_set_value(ausd->npcs_pin, !active); > > + aus->cs_active = false; > > +} > > ... > > + if (!ausd) { > > + if (gpio_is_valid(spi->cs_gpio)) { > > + npcs_pin = gpio_to_desc(spi->cs_gpio); > > ... > > + } > > ... > > + gpiod_direction_output(npcs_pin, !(spi->mode & > > SPI_CS_HIGH)); > > + > > + ausd->npcs_pin = npcs_pin; > > ... > > + } > > I will refer to above as (1) later on. > > > + dev_dbg(&spi->dev, "new message %p submitted for %s\n", > > + msg, dev_name(&spi->dev)); > > %p does make a very little sense. > > > + list_for_each_entry(xfer, &msg->transfers, transfer_list) { > > + ret = at91_usart_spi_one_transfer(controller, msg, > > xfer); > > + if (ret) > > + goto msg_done; > > + } > > Cant SPI core do this for your? > > > +static void at91_usart_spi_cleanup(struct spi_device *spi) > > +{ > > + struct at91_usart_spi_device *ausd = spi->controller_state; > > + > > + if (!ausd) > > + return; > > Is it even possible? > > Anyway the code below will work fine even if it's the case. > > > + > > + spi->controller_state = NULL; > > + kfree(ausd); > > +} > > +static int at91_usart_spi_gpio_cs(struct platform_device *pdev) > > +{ > > + struct spi_controller *controller = > > platform_get_drvdata(pdev); > > + struct device_node *np = controller->dev.parent->of_node; > > + struct gpio_desc *cs_gpio; > > + int nb; > > + int i; > > + > > + if (!np) > > + return 0; > > + > > + nb = of_gpio_named_count(np, "cs-gpios"); > > + for (i = 0; i < nb; i++) { > > + cs_gpio = devm_gpiod_get_from_of_node(&pdev->dev, > > + pdev- > > >dev.parent->of_node, > > + "cs-gpios", > > + i, > > GPIOD_OUT_HIGH, > > + dev_name(&pde > > v->dev)); > > + if (IS_ERR(cs_gpio)) > > + return PTR_ERR(cs_gpio); > > + } > > + > > + controller->num_chipselect = nb; > > + > > + return 0; > > +} > > The question is, why you didn't utilize what SPI core provides you? > > > + spi_writel(aus, MR, US_MR_SPI_MASTER | US_MR_CHRL | > > US_MR_CLKO | > > + US_MR_WRDBT); > > + spi_writel(aus, CR, US_CR_RXDIS | US_CR_TXDIS | US_CR_RSTRX > > | > > + US_CR_RSTTX); > > I didn't check over, but it seems like you might have duplication in > these bitwise ORs. Consider to unify them into another (shorter) > definitions and reuse all over the code. > > > + regs = platform_get_resource(to_platform_device(pdev- > > >dev.parent), > > + IORESOURCE_MEM, 0); > > + if (!regs) > > + return -ENXIO; > > Strange error code for getting MMIO resource. ENOMEM sounds better. > > > + 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); > > If you do explicit casting when printing something you are doing > wrong. > Please use %pR or %pr in this case. > > > +static struct platform_driver at91_usart_spi_driver = { > > + .driver = { > > + .name = "at91_usart_spi", > > + .of_match_table = > > of_match_ptr(at91_usart_spi_dt_ids), > > Can it work as pure platform driver? If no, of_match_ptr() is > redundant. This driver can not work as pure platform driver, but I the way I used to probe it from MFD(by compatbile string). Do you know another way? > > > + }, > > + .probe = at91_usart_spi_probe, > > + .remove = at91_usart_spi_remove, }; > > Two lines at one. Split. >