Received: by 10.213.65.68 with SMTP id h4csp9092imn; Wed, 21 Mar 2018 11:06:25 -0700 (PDT) X-Google-Smtp-Source: AG47ELtne4CdQ5NuYQtLjeST30B01smTpoBLCVS2Bz63dMGMOUyvtgJJ9xbAz+DcabL1sENB21qP X-Received: by 2002:a17:902:690b:: with SMTP id j11-v6mr21932305plk.124.1521655585612; Wed, 21 Mar 2018 11:06:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521655585; cv=none; d=google.com; s=arc-20160816; b=hrT1XGHbYAbUcP1uvoT2v1A6M5jS5DOr+UJixbBq1rezITWUb0mVZbBC95v58IOgBE +eTcB74GSF3Kq5bO3QSn11nTPl+p/kVuMnlyIkVK/DR+21e8yMPH1hxxKtYft+KtrnfQ Ha6azdSNIWseVoFFHHA5GDblqga9G9GcSUkbe7PcQaLdZelugEW37AMGMO90AIxNDGvx QptZW6gbzt9Iua4S8Yr8nKs9SSFtiWNOOzaHO8ZBxN1r5U5T2I58JFcj+P3eocUEDkMr lQrx82/q5+m/ihJXxkSTTaMzh38nAacPmeoPpZI8/wBdlLZjgZsnH3GrqAJWRt/q3PGK HYKw== 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=EYkAHU1xjdwxWCZ7flid9hn2XGZMWyd66F4JpTvghdU=; b=zGFKbum7DIgP7cJJzcjjHkQcdjG9X7x11GZeGzVelOZD6lyH2wOw51oro8X3nvRfX+ BsCLddqzs0BhOIuGq5WEJm1O4EHG9LWzRCMAssb01eXdzSjly66A8QVrjlV8/+1ltXxi 06/98K/Aw1ERSZ7N6lOaguHF58dNnUCrGATbNFcqS45/bWEvITwZ+AOcbCTKjq/XIiU8 R4UR/WqozINK4dPUYOkCI73u3XFW6WzlqXeAPnp/BILOMo7Ff4zcdSeQSX0zp2k8C9fU ca+x3zMTQUQL8wEU5g/RixLojSulImREcsk9yiJD6pyRU5kvxLANSqEndDSCX9rWXGPh 3APA== 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 t13si3130941pgs.430.2018.03.21.11.06.10; Wed, 21 Mar 2018 11:06:25 -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 S1752612AbeCUSE5 (ORCPT + 99 others); Wed, 21 Mar 2018 14:04:57 -0400 Received: from smtprelay0125.hostedemail.com ([216.40.44.125]:59045 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752512AbeCUSE4 (ORCPT ); Wed, 21 Mar 2018 14:04:56 -0400 Received: from filter.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay07.hostedemail.com (Postfix) with ESMTP id 5FAB4181D397B; Wed, 21 Mar 2018 18:04:55 +0000 (UTC) X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::::::::::,RULES_HIT:41:152:355:379:541:599:973:988:989:1260:1277:1311:1313:1314:1345:1359:1373:1437:1515:1516:1518:1534:1542:1593:1594:1711:1730:1747:1777:1792:2194:2199:2393:2559:2562:3138:3139:3140:3141:3142:3355:3622:3865:3866:3867:3868:3870:3872:4225:4250:4321:4605:5007:6119:7875:7903:10004:10400:10848:11026:11232:11473:11658:11914:12048:12296:12438:12681:12740:12895:13141:13161:13229:13230:13894:14093:14096:14097:14659:14721:21080:21324:21433:21451:21627:30012:30046:30054:30080:30091,0,RBL:47.151.150.235:@perches.com:.lbl8.mailshell.net-62.14.0.100 64.201.201.201,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:21,LUA_SUMMARY:none X-HE-Tag: voice66_47dc40e384d16 X-Filterd-Recvd-Size: 3899 Received: from XPS-9350 (unknown [47.151.150.235]) (Authenticated sender: joe@perches.com) by omf03.hostedemail.com (Postfix) with ESMTPA; Wed, 21 Mar 2018 18:04:53 +0000 (UTC) Message-ID: <1521655492.7999.13.camel@perches.com> Subject: Re: [PATCH 2/2] fpga: lattice machxo2: Add Lattice MachXO2 support From: Joe Perches To: Paolo Pisati , Alan Tull , Moritz Fischer , Rob Herring , Mark Rutland Cc: linux-fpga@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Date: Wed, 21 Mar 2018 11:04:52 -0700 In-Reply-To: <1521653726-24625-3-git-send-email-p.pisati@gmail.com> References: <1521653726-24625-1-git-send-email-p.pisati@gmail.com> <1521653726-24625-3-git-send-email-p.pisati@gmail.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.26.1-1 Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 2018-03-21 at 18:35 +0100, Paolo Pisati wrote: > This patch adds support to the FPGA manager for programming > MachXO2 device’s internal flash memory, via slave SPI. style trivia: > diff --git a/drivers/fpga/machxo2-spi.c b/drivers/fpga/machxo2-spi.c [] > +static int get_status(struct spi_device *spi, unsigned long *status) > +{ > + struct spi_message msg; > + struct spi_transfer rx, tx; > + u8 cmd[] = LSC_READ_STATUS; static const u8 cmd[] here and everywhere else as all the tx_buf assignments of cmd are to const void * > + int ret; > + > + memset(&rx, 0, sizeof(rx)); > + memset(&tx, 0, sizeof(tx)); > + tx.tx_buf = cmd; [] > +#ifdef DEBUG > +static void dump_status_reg(unsigned long *status) > +{ Instead of multiple declarations of dump_status_reg it's frequently nicer to use a style like static void debug_func(args...) { #ifdef DEBUG [code...] #endif } so if function arguments ever need to be changed it's only required to be changed in one spot and not multiply compilation tested with and without the DEBUG definition > + char *ferr; > + > + switch (get_err(status)) { > + case ENOERR: > + ferr = "No Error"; > + break; > + case EID: > + ferr = "ID ERR"; > + break; > + case ECMD: > + ferr = "CMD ERR"; > + break; > + case ECRC: > + ferr = "CRC ERR"; > + break; > + case EPREAM: > + ferr = "Preamble ERR"; > + break; > + case EABRT: > + ferr = "Abort ERR"; > + break; > + case EOVERFL: > + ferr = "Overflow ERR"; > + break; > + case ESDMEOF: > + ferr = "SDM EOF"; > + break; > + default: > + ferr = "Default switch case"; > + } It's frequently nicer to use a static function for these enum -> string conversions like: static const char *get_err_string(unsigned long err) { switch (err) { case ENOERR: return "No Error"; case EID: return "ID ERR"; case ECMD: return "CMD ERR"; [...] } return "default switch case"; } > + pr_debug("machxo2 status: 0x%08lX - done=%d, cfgena=%d, busy=%d, fail=%d, devver=%d, err=%s\n", > + *status, test_bit(DONE, status), test_bit(ENAB, status), > + test_bit(BUSY, status), test_bit(FAIL, status), > + test_bit(DVER, status), ferr); So instead of ferr, this could use get_err_string(*status) And please try to keep a consistent alignment for indentation of multiple line statements > +} > +#else > +static void dump_status_reg(unsigned long *status) {} > +#endif > + > +static int wait_until_not_busy(struct spi_device *spi) > +{ > + unsigned long status; > + int ret, loop = 0; > + > + do { > + ret = get_status(spi, &status); > + if (ret) > + break; > + if (++loop >= MACHXO2_MAX_BUSY_LOOP) { > + ret = -EBUSY; > + break; > + } > + } while (test_bit(BUSY, &status)); > + > + return ret; > +} Direct returns are OK and would shorten the function line count.