Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2829429imm; Sun, 29 Jul 2018 04:28:31 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcuKZBogHOdvQBODxjcIjFa11G23+wL7a8lVksX4RXEMZBQs3TCwvZNkTfNOkd7KD2AvKJ8 X-Received: by 2002:a17:902:548f:: with SMTP id e15-v6mr12620632pli.317.1532863711709; Sun, 29 Jul 2018 04:28:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532863711; cv=none; d=google.com; s=arc-20160816; b=0MftePZuURF7TQlxYdMOeeJWe7/Owa6CwXASTfu3D3nHwwqKksBNWKYROfole2lAha yGlen/VAUvr+mJBvbNiBL1ffVZtpUsJrAXm+xTguup43Db6nKMEMLdsU/4NW5ex0UEwx 6i5nL7aQvEvklJ8lN1RpXo5O/gtBjAZleTy4VyDLy/1FTv0BtjbMII6zYbcQS1m8eYwS pjaj5gMVCxCFlHSfmKhuyVsMxG9JFFo3gt8JYlhXedGmwazGQqGuvDyIPstLuLIZivHk cmBlpgfl07JwsiNeQy2kADhsYDx1woVTxvq2gJLWwzoGjiUAPqy2+11AyDnX3Ncq4Hw+ EdDw== 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=pJ8JyHMqIYr/gindlb/Z2FeLEKJwg4/vhsvy92c/6yU=; b=ga2M1uhZOFl6hSQ5HM8MSyg/YWqfobp0ZSY5jtQPhT84kuAKQGWveElqZ8dH6J+fW3 9qd3HoHS7wetG6/xh1EHMJwrOj8a8BjGUnfMIgtiu0Zlod0hYZ4Cf1vIgvCW9ep26XyN rjVkhucphbu9Bf/O40S0W/hE/DnCEOzJllZRT3ew3AG+YC5Vi9WO/+pNIFxl5t23SsdS CSFy5bAv3yIWcyAkr27XXzbZFy90RWsjwgSmQydTMH/oM9OlObcz2bxF74Xf0zOQQMNB YRcRLc0FYxulibvnVcLxjAcPouSYIu5G54IlIuDR5+VkUMYGl75I4Y6QC+TF25BylBgd 89sw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=c6aroWsK; 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 p83-v6si8490756pfa.180.2018.07.29.04.28.15; Sun, 29 Jul 2018 04:28:31 -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=c6aroWsK; 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 S1726355AbeG2M5a (ORCPT + 99 others); Sun, 29 Jul 2018 08:57:30 -0400 Received: from mail-vk0-f65.google.com ([209.85.213.65]:46209 "EHLO mail-vk0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726263AbeG2M5a (ORCPT ); Sun, 29 Jul 2018 08:57:30 -0400 Received: by mail-vk0-f65.google.com with SMTP id b14-v6so4461967vke.13; Sun, 29 Jul 2018 04:27:22 -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=pJ8JyHMqIYr/gindlb/Z2FeLEKJwg4/vhsvy92c/6yU=; b=c6aroWsK7eFqgJcEgKi2mXyulOcRkhIV3FrLqab+qqg+i6W2SVt7lJt0uAiUrYkQBU FM1bEh28Bi9pYqeub/akcQrN1yZuULabxofD7nG1hhggtap5X032VkNmXA+w73KWnh+R L83Jd3wicmT+5R44kP9EcBIFZDc5gMmMmtNcowg3v75ar/3YNmluwyZ9mZmz4WL6Ei9b cTihpt53rryct84wSmYcYYiwWhkqfACOZJicsRvQO1zGgAxHwnXlLOOpeKHS9iN3jWz1 Kqdx6NBV32yY6a24tFv1PTXXZJE+8gi1wxXmiH8cNMDQSND4nTnVL42/3938lyqQTGIy gr4Q== 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=pJ8JyHMqIYr/gindlb/Z2FeLEKJwg4/vhsvy92c/6yU=; b=ahLykliAQ1ucRdxKOY4jOWT2CGC1QBneORBMwwq3W+MOiFv1jfPCuAt4VrafT3ioZj SD63qT4ENCzrnWweXp4PSo5Ae4eqraEX2FVOBzW9mO2jjgkPknk8339CcxokZGMnh8KI YYwgyRslwr3qMiTkYDDrLQvKt3m/4rTa/m+PDMIihdX0975vXUqfyGG+iQIMn57DH7li SMZvGXa9U9piih7ueeftdtwLN+mEhm30MLKxup90b0jsPSxG0tdgf13ezkuDQGOPtAX8 /gqvLOASsjH8s5oRWzB3OIWgyCmYWEWOmFvFrKXVe5nWwvFlS+mrWAKNUesvm+p3iOs4 CDaw== X-Gm-Message-State: AOUpUlExSnK1zX7XnNOaev6pVWn7o8N4gRdYT3qt3FBr4azZ3+X9epEo z/uneXHAroYPgigoa7MHVZbRxvdjR2Cg2HUY2BQ= X-Received: by 2002:a1f:b503:: with SMTP id e3-v6mr8573653vkf.97.1532863642121; Sun, 29 Jul 2018 04:27:22 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a67:2149:0:0:0:0:0 with HTTP; Sun, 29 Jul 2018 04:27:21 -0700 (PDT) In-Reply-To: <20180729091449.385951-3-tali.perry1@gmail.com> References: <20180729091449.385951-1-tali.perry1@gmail.com> <20180729091449.385951-3-tali.perry1@gmail.com> From: Andy Shevchenko Date: Sun, 29 Jul 2018 14:27:21 +0300 Message-ID: Subject: Re: [PATCH v1 2/2] i2c: npcm7xx: add i2c controller master mode only To: Tali Perry Cc: Avi Fishman , Tomer Maimon , venture@google.com, yuenn@google.com, brendanhiggins@google.com, Rob Herring , Mark Rutland , "David S. Miller" , Mauro Carvalho Chehab , Greg Kroah-Hartman , Andrew Morton , Arnd Bergmann , Wolfram Sang , Andy Shevchenko , pierre-yves.mordret@st.com, cedric.madianga@gmail.com, Baolin Wang , Jarkko Nikula , Hans de Goede , rmk+kernel@armlinux.org.uk, Ard Biesheuvel , Thor Thayer , Geert Uytterhoeven , "Krogerus, Heikki" , Thomas Gleixner , linux-i2c , OpenBMC Maillist , devicetree , Linux Kernel Mailing List 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 Sun, Jul 29, 2018 at 12:14 PM, Tali Perry wrote: > Nuvoton NPCM7XX I2C Controller > NPCM7xx includes 16 I2C contollers. THis driver operates the controller. > This module also includes a slave mode, which will be submitted later on. > > Any feedback would be appreciated. Too much lines of code as for I2C driver. Briefly looking it seems it doesn't utilize what kernel already has (e.g. crc8 already is in kernel library) and doesn't follow modern style of drivers there. > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include > +#include > +#include > + > +#include > +#include Just wow. Are you sure you need all of them? (Also, to see better what it's used, keep them in order) > +#define ENABLE 1 > +#define DISABLE 0 So, what's wrong with 1, 0 or true, false? > +#define _1Hz_ (u32)1UL > +#define _1KHz_ (1000 * _1Hz_) > +#define _1MHz_ (1000 * _1KHz_) > +#define _1GHz_ (1000 * _1MHz_) If you need such constants it would be something like for time periods we have HZ_PER_KHZ 1000 HZ_PER_MHZ 1000000 etc. I saw in a code some of those predefined. If they are not yet generic (in scope of kernel) it might be worth to do in the future. > +#ifndef ASSERT > +#ifdef DEBUG > +#define ASSERT(cond) {if (!(cond)) for (;;) ; } > +#else > +#define ASSERT(cond) > +#endif > +#endif Hmm... In production code?! > + > +#define ROUND_UP(val, n) (((val)+(n)-1) & ~((n)-1)) > +#define DIV_CEILING(a, b) (((a) + ((b)-1)) / (b)) You really need to check what kernel provides. > +#define I2C_DEBUG2(f, x...) ??? > + > + > + > + Why to have so many blank lines? > + > + Ditto. > +// Common regs > +#define NPCM7XX_SMBSDA(bus) (bus->base + 0x000) > +#define NPCM7XX_SMBST(bus) (bus->base + 0x002) > +#define NPCM7XX_SMBCST(bus) (bus->base + 0x004) > +#define NPCM7XX_SMBCTL1(bus) (bus->base + 0x006) > +#define NPCM7XX_SMBADDR1(bus) (bus->base + 0x008) > +#define NPCM7XX_SMBCTL2(bus) (bus->base + 0x00A) > +#define NPCM7XX_SMBADDR2(bus) (bus->base + 0x00C) > +#define NPCM7XX_SMBCTL3(bus) (bus->base + 0x00E) > +#define NPCM7XX_SMBCST2(bus) (bus->base + 0x018) // Control Status 2 > +#define NPCM7XX_SMBCST3(bus) (bus->base + 0x019) // Control Status 3 > +#define SMB_VER(bus) (bus->base + 0x01F) // SMB Version reg Usually we put just numbers here and use custom I/O accessors which take bus as a parameter. > + > +// BANK 0 regs > +#define NPCM7XX_SMBADDR3(bus) (bus->base + 0x010) > +#define NPCM7XX_SMBADDR7(bus) (bus->base + 0x011) > +#define NPCM7XX_SMBADDR4(bus) (bus->base + 0x012) > +#define NPCM7XX_SMBADDR8(bus) (bus->base + 0x013) > +#define NPCM7XX_SMBADDR5(bus) (bus->base + 0x014) > +#define NPCM7XX_SMBADDR9(bus) (bus->base + 0x015) > +#define NPCM7XX_SMBADDR6(bus) (bus->base + 0x016) > +#define NPCM7XX_SMBADDR10(bus) (bus->base + 0x017) > +#define NPCM7XX_SMBADDR(bus, i) (bus->base + 0x008 + \ > + (u32)(((int)i * 4) + (((int)i < 2) ? 0 : \ > + ((int)i - 2)*(-2)) + (((int)i < 6) ? 0 : (-7)))) It's rather complicated. > + // Current state of SMBus I guess more compact is to put a kernel doc descriprion. > + enum smb_state state; > +static bool NPCM7XX_smb_init_module(struct NPCM7XX_i2c *bus, > + enum smb_mode mode, u16 bus_freq); Do you need all forward declarations? Why? So, I stopped here. Try to make your code twice less in a lenght (looking at it I think it's doable). > +static const struct of_device_id NPCM7XX_i2c_bus_of_table[] = { > + { .compatible = "nuvoton,npcm750-i2c-bus", }, > + {}, Slightly better without comma for terminator lines. > +}; > +MODULE_DEVICE_TABLE(of, NPCM7XX_i2c_bus_of_table); -- With Best Regards, Andy Shevchenko