Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp3908509imm; Tue, 29 May 2018 16:43:17 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKZfzK9MLFIujIcG8YY7lcOPQX1rYVTtYZzeIiyAuRU3jeoTITC87v12Gc7cqPvqnuZ0D8t X-Received: by 2002:a62:9513:: with SMTP id p19-v6mr414046pfd.239.1527637397561; Tue, 29 May 2018 16:43:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527637397; cv=none; d=google.com; s=arc-20160816; b=PNcwj+fbY/O4SZCxbWfyRw7nGvfgzP+kdVFBNBn+7wOjMJ/Xpgrs0JygL5W/8SeTRV ktgshBPeU08qvRVG2kOuPPrioVxAuryFOI/UTtNilq/aJyudPok8um/b6oPGxEKfnBGm WRPHpTCojISoKqM3cCJEz512selIlgcw6TvXb85kT/VoY+9ZD8/01Xrwcvigqt7ZaSMX wUI7h0JgG54AdnDoZzW9eJ8Wg1BswtGJpRrGAfV2OdODRoylfXN2C/w9fuEY0Yqle5WZ MjGK+ILQe/nZvVp7CLAS30CSWufbzS56xTxT9N1xGvNYBQC+d4JTm/uZczoHzaetfP1s bWzg== 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=OknQZ+IddHjFo1yhgS4pLsHCAPzNDw0Q1PG0RRye7+0=; b=psDN8v68Y7/pi4aYG4KAlbHVuEfA/lVHvo0g7Ps0QFAn4jjUpHrp/qhbwXA4UAyTKa HB22oeL3ACfMyGk/bAMTR98YWstxhf87HVsyhW395ZdgVCrtC1/fdkFFDcrAF2Xh8kUY PiJwAcFUmAuCeAzOKhd4c9yZC+4rApUciX/dZ3DyQuzE1hYEqIVqhXr1i5pG0ubW8Z9z EV3sN8b3L+ahuFC+tpWS1omMGHXc9K4OLFHB07vd0G6B+H0pRMFsmc2Q29umfc1ekuPB 1ySyalUODJUXchOxZq5Pq8MEFhT5M9oqS6F5RN4G1YaY6btpIIQu8HUfTRiRaS08d9eb tjWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=io0/awU7; 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 a65-v6si61449pge.133.2018.05.29.16.43.02; Tue, 29 May 2018 16:43:17 -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=io0/awU7; 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 S1755263AbeE2Xmh (ORCPT + 99 others); Tue, 29 May 2018 19:42:37 -0400 Received: from mail-qk0-f196.google.com ([209.85.220.196]:33959 "EHLO mail-qk0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755165AbeE2Xmf (ORCPT ); Tue, 29 May 2018 19:42:35 -0400 Received: by mail-qk0-f196.google.com with SMTP id q70-v6so4345624qke.1; Tue, 29 May 2018 16:42:35 -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=OknQZ+IddHjFo1yhgS4pLsHCAPzNDw0Q1PG0RRye7+0=; b=io0/awU7cJU0PuoV0m6m1LIWt3yc54c97Qg56FAAHI/crR6FtydK1sKbu3OzNb+K7R 979qgrC8dlQflJObd1ToFmqDl6h72SNU0L2jYCCl80ivB1eEFEb9QCjN0og4lKAcziew 5GvaQv6B3bVeIwk0W6csRmPEYiy8/gEK7n3eUtQA07cnRA1oswzXxmxslOW0RgrZAgrP suZNAR3mMK8tta8rXwPmhzBZUrpQ/glFIAtvloPLf910BpfF/ZJRpEWgXfO+gwi/l0u3 mCIoXA16EYHQh2uYiZW8KAJ2fRrmrW+L8qCKZfjjoq1c50LrOr1c5CB89ptyIj7MrmUd /GAg== 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=OknQZ+IddHjFo1yhgS4pLsHCAPzNDw0Q1PG0RRye7+0=; b=Hum17TFwROPDgG8Bxu66PKU7R2NDL/GGMbnBml5CNxrJw+zGfZfBnZ13dXeyXoHMeg jJFYFWK/ORzX6u5Amj/GpGdr8tUC6jHddMN4hUO9DNn12fq+L9O0o/KH5ZLBBSE4Mqmv emhJZyzkCMI7RAP8X8GEKug823CHh7KWDn3hG0fjM/BMrJnAeZdhxNmHOcJUYFwPaFJv oipeWSWaQqm/IYXhOggjy8G4FLy1phWudPs7mA1KbVA2j1I1IxH4n7+GHZ+u7JlvUHGU Ru+h+ADBZscsc58u62q0ZBI0NM2+gXv6+j29yED9JS3KmR5SDZibvis7RdkMz/LevujL egMw== X-Gm-Message-State: APt69E1HGNJnBeMxWT/dmW/UXg+CS//CICc0Z3Xl3AquGdTHa3el6q5U FccjpttN+ivhTQSQKBmHMOjzDCk8cFf4iDS/8iY= X-Received: by 2002:a37:1457:: with SMTP id e84-v6mr425788qkh.3.1527637354742; Tue, 29 May 2018 16:42:34 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a0c:9896:0:0:0:0:0 with HTTP; Tue, 29 May 2018 16:42:34 -0700 (PDT) In-Reply-To: <1527632665-25707-3-git-send-email-eajames@linux.vnet.ibm.com> References: <1527632665-25707-1-git-send-email-eajames@linux.vnet.ibm.com> <1527632665-25707-3-git-send-email-eajames@linux.vnet.ibm.com> From: Andy Shevchenko Date: Wed, 30 May 2018 02:42:34 +0300 Message-ID: Subject: Re: [PATCH v7 2/7] drivers/i2c: Add FSI-attached I2C master algorithm To: Eddie James Cc: linux-i2c , Linux Kernel Mailing List , devicetree , Wolfram Sang , Rob Herring , Benjamin Herrenschmidt , Joel Stanley , Mark Rutland , Greg Kroah-Hartman , "Edward A. James" 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 Wed, May 30, 2018 at 1:24 AM, Eddie James wrote: > From: "Edward A. James" > > Add register definitions for FSI-attached I2C master and functions to > access those registers over FSI. Add an FSI driver so that our I2C bus > is probed up during an FSI scan. This looks like reinventing a wheel in some ways. See my comments below. > +/* > + * Copyright 2017 IBM Corporation > + * > + * Eddie James > + * > + * This program is free software; you can redistribute it and/or > + * modify it under the terms of the GNU General Public License > + * as published by the Free Software Foundation; either version > + * 2 of the License, or (at your option) any later version. > + */ We are using SPDX identifiers. Can you? > +/* Find left shift from first set bit in m */ > +#define MASK_TO_LSH(m) (__builtin_ffsll(m) - 1ULL) Oh. What about GENMASK()? > +/* Extract field m from v */ > +#define GETFIELD(m, v) (((v) & (m)) >> MASK_TO_LSH(m)) > + > +/* Set field m of v to val */ > +#define SETFIELD(m, v, val) \ > + (((v) & ~(m)) | ((((typeof(v))(val)) << MASK_TO_LSH(m)) & (m))) Oh, what about https://elixir.bootlin.com/linux/latest/source/include/linux/bitfield.h ? > +#define I2C_CMD_WITH_START 0x80000000 > +#define I2C_CMD_WITH_ADDR 0x40000000 > +#define I2C_CMD_RD_CONT 0x20000000 > +#define I2C_CMD_WITH_STOP 0x10000000 > +#define I2C_CMD_FORCELAUNCH 0x08000000 BIT() ? > +#define I2C_CMD_ADDR 0x00fe0000 > +#define I2C_CMD_READ 0x00010000 GENMASK()? Though precisely here it might be good to leave explicit values. > +#define I2C_CMD_LEN 0x0000ffff > +#define I2C_MODE_CLKDIV 0xffff0000 > +#define I2C_MODE_PORT 0x0000fc00 > +#define I2C_MODE_ENHANCED 0x00000008 > +#define I2C_MODE_DIAG 0x00000004 > +#define I2C_MODE_PACE_ALLOW 0x00000002 > +#define I2C_MODE_WRAP 0x00000001 What are they? Masks? Bit fields? Just plain numbers? > +#define I2C_WATERMARK_HI 0x0000f000 > +#define I2C_WATERMARK_LO 0x000000f0 GENMASK() ? > +#define I2C_INT_INV_CMD 0x00008000 > +#define I2C_INT_PARITY 0x00004000 > +#define I2C_INT_BE_OVERRUN 0x00002000 > +#define I2C_INT_BE_ACCESS 0x00001000 > +#define I2C_INT_LOST_ARB 0x00000800 > +#define I2C_INT_NACK 0x00000400 > +#define I2C_INT_DAT_REQ 0x00000200 > +#define I2C_INT_CMD_COMP 0x00000100 > +#define I2C_INT_STOP_ERR 0x00000080 > +#define I2C_INT_BUSY 0x00000040 > +#define I2C_INT_IDLE 0x00000020 BIT() > +#define I2C_INT_ENABLE 0x0000ff80 > +#define I2C_INT_ERR 0x0000fcc0 > +#define I2C_STAT_INV_CMD 0x80000000 > +#define I2C_STAT_PARITY 0x40000000 > +#define I2C_STAT_BE_OVERRUN 0x20000000 > +#define I2C_STAT_BE_ACCESS 0x10000000 > +#define I2C_STAT_LOST_ARB 0x08000000 > +#define I2C_STAT_NACK 0x04000000 > +#define I2C_STAT_DAT_REQ 0x02000000 > +#define I2C_STAT_CMD_COMP 0x01000000 > +#define I2C_STAT_STOP_ERR 0x00800000 > +#define I2C_STAT_MAX_PORT 0x000f0000 > +#define I2C_STAT_ANY_INT 0x00008000 > +#define I2C_STAT_SCL_IN 0x00000800 > +#define I2C_STAT_SDA_IN 0x00000400 > +#define I2C_STAT_PORT_BUSY 0x00000200 > +#define I2C_STAT_SELF_BUSY 0x00000100 BIT() > +#define I2C_STAT_FIFO_COUNT 0x000000ff GENMASK() > + > +#define I2C_STAT_ERR 0xfc800000 > +#define I2C_STAT_ANY_RESP 0xff800000 > +#define I2C_ESTAT_FIFO_SZ 0xff000000 GENMASK() > +#define I2C_ESTAT_SCL_IN_SY 0x00008000 > +#define I2C_ESTAT_SDA_IN_SY 0x00004000 > +#define I2C_ESTAT_S_SCL 0x00002000 > +#define I2C_ESTAT_S_SDA 0x00001000 > +#define I2C_ESTAT_M_SCL 0x00000800 > +#define I2C_ESTAT_M_SDA 0x00000400 > +#define I2C_ESTAT_HI_WATER 0x00000200 > +#define I2C_ESTAT_LO_WATER 0x00000100 > +#define I2C_ESTAT_PORT_BUSY 0x00000080 > +#define I2C_ESTAT_SELF_BUSY 0x00000040 BIT() > +#define I2C_ESTAT_VERSION 0x0000001f GENMASK() > + __be32 data_be; No need to have a suffix. If anything can go wrong we have a tool, it's called sparse. It will catch out inappropriate use of __bitwise types. > + __be32 data_be = cpu_to_be32(*data); cpu_to_be32p() IIUC? > +static int fsi_i2c_dev_init(struct fsi_i2c_master *i2c) > +{ > + int rc; > + u32 mode = I2C_MODE_ENHANCED, extended_status, watermark = 0; > + u32 interrupt = 0; Redundant assignment. > + > + /* since we use polling, disable interrupts */ > + rc = fsi_i2c_write_reg(i2c->fsi, I2C_FSI_INT_MASK, &interrupt); > + if (rc) > + return rc; > + return rc; Would be non-zero? > +} -- With Best Regards, Andy Shevchenko