Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp120853imm; Mon, 4 Jun 2018 14:13:03 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLubmV2YN8/gRjAELDpKZ+IPLeRiRGSEr/nRH+SD5puTW1WFFtrS7GJ6XPZMOJb2NaYf0sf X-Received: by 2002:a17:902:bb93:: with SMTP id m19-v6mr23664328pls.123.1528146783343; Mon, 04 Jun 2018 14:13:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528146783; cv=none; d=google.com; s=arc-20160816; b=ya3tgt4PHO5tKai1yaoCx393BVdKHdSHcrgknHSBtl0I5dpt8c/+PMKZkDyMgIxD9q Z89R5uIZwOIt/wEYXYPgJ5Pqsfoz9Mss/i46Ya4KjIDkikOMupCjOQLVGGL4CANJwTd9 RawUpjJWXKwtpjRx8mv6ykG2jfbtQewcFChl7pSYLZRtkmGm/sGwCjN9deHTp4re0fYw +lnG7c9laY3AfcU20BWrtnXC3T0q7V6JNTVe4SRBCch5MjDRTMZgORJdiXNnFuMatG25 KYS0fkW/Rvbvt3KRNgwXkwRSftZmXkvcW1Ova4G8g+pm3KTkZA2W6X4hd5WK5EAdQ5Xh A+qA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :from:references:cc:to:subject:arc-authentication-results; bh=prRGNRAM9wP7BTDlZXOtQaPm8QyCVNCNGQeXT824tP4=; b=MbrOqQtpzyNMo9Pj8SuTx9PLoomsZt8pYj0+gZ5EBjNcrEu7GzTnylk7WFkGEuWiXC Amu5RJZcTRZPwNZyfmwMcAc5W98SWfTuJkP02AgGowdqAeUvh7hdyXLHo+GsbfrvSU71 JA5mUxPyUUSb/6uJHPOeLfjTnWxuNv6YqDQEe+KgpVn3biEct1llzie+/k0j5ObQAVjD HvMvNypzvLlLGvj541HM7X3/ulEg584y/cCKoUqm47YBVMYaUI8QiqtR6L6Ar9sYAOhA jdrONC8MnKTh7G+t0COeTlpqQG0dTPyQKFmQ6dO2UT3+uoH6ZweYoxZcEdFxQ0iw8kRI yI0Q== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 67-v6si48096554pfm.167.2018.06.04.14.12.47; Mon, 04 Jun 2018 14:13:03 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751370AbeFDVLR (ORCPT + 99 others); Mon, 4 Jun 2018 17:11:17 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:42396 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751187AbeFDVLO (ORCPT ); Mon, 4 Jun 2018 17:11:14 -0400 Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w54L9HbV053198 for ; Mon, 4 Jun 2018 17:11:14 -0400 Received: from e16.ny.us.ibm.com (e16.ny.us.ibm.com [129.33.205.206]) by mx0b-001b2d01.pphosted.com with ESMTP id 2jd9b0h99m-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 04 Jun 2018 17:11:13 -0400 Received: from localhost by e16.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 4 Jun 2018 17:11:13 -0400 Received: from b01cxnp23034.gho.pok.ibm.com (9.57.198.29) by e16.ny.us.ibm.com (146.89.104.203) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Mon, 4 Jun 2018 17:11:08 -0400 Received: from b01ledav005.gho.pok.ibm.com (b01ledav005.gho.pok.ibm.com [9.57.199.110]) by b01cxnp23034.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w54LB7aH6160734 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 4 Jun 2018 21:11:07 GMT Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C558AAE05F; Mon, 4 Jun 2018 17:11:26 -0400 (EDT) Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9B19CAE063; Mon, 4 Jun 2018 17:11:25 -0400 (EDT) Received: from [9.41.241.240] (unknown [9.41.241.240]) by b01ledav005.gho.pok.ibm.com (Postfix) with ESMTP; Mon, 4 Jun 2018 17:11:25 -0400 (EDT) Subject: Re: [PATCH v9 2/7] i2c: Add FSI-attached I2C master algorithm To: Andy Shevchenko Cc: linux-i2c , Linux Kernel Mailing List , devicetree , Wolfram Sang , Rob Herring , Benjamin Herrenschmidt , Joel Stanley , Mark Rutland , Greg Kroah-Hartman , Randy Dunlap References: <1528138850-18259-1-git-send-email-eajames@linux.vnet.ibm.com> <1528138850-18259-3-git-send-email-eajames@linux.vnet.ibm.com> From: Eddie James Date: Mon, 4 Jun 2018 16:11:05 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-TM-AS-GCONF: 00 x-cbid: 18060421-0072-0000-0000-000003682864 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00009130; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000265; SDB=6.01042345; UDB=6.00533734; IPR=6.00821476; MB=3.00021462; MTD=3.00000008; XFM=3.00000015; UTC=2018-06-04 21:11:11 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18060421-0073-0000-0000-0000483EC7EC Message-Id: X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-06-04_14:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1805220000 definitions=main-1806040241 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 06/04/2018 02:21 PM, Andy Shevchenko wrote: > On Mon, Jun 4, 2018 at 10:00 PM, Eddie James wrote: >> 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. >> >> Signed-off-by: Eddie James >> --- >> drivers/i2c/busses/Kconfig | 11 ++ >> drivers/i2c/busses/Makefile | 1 + >> drivers/i2c/busses/i2c-fsi.c | 234 +++++++++++++++++++++++++++++++++++++++++++ >> 3 files changed, 246 insertions(+) >> create mode 100644 drivers/i2c/busses/i2c-fsi.c >> >> diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig >> index 4f8df2e..cddd159 100644 >> --- a/drivers/i2c/busses/Kconfig >> +++ b/drivers/i2c/busses/Kconfig >> @@ -1330,4 +1330,15 @@ config I2C_ZX2967 >> This driver can also be built as a module. If so, the module will be >> called i2c-zx2967. >> >> +config I2C_FSI >> + tristate "FSI I2C driver" >> + depends on FSI >> + help >> + Driver for FSI bus attached I2C masters. These are I2C masters that >> + are connected to the system over an FSI bus, instead of the more >> + common PCI or MMIO interface. >> + >> + This driver can also be built as a module. If so, the module will be >> + called as i2c-fsi. >> + >> endmenu >> diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile >> index 5a86914..4909fd6 100644 >> --- a/drivers/i2c/busses/Makefile >> +++ b/drivers/i2c/busses/Makefile >> @@ -137,5 +137,6 @@ obj-$(CONFIG_I2C_PCA_ISA) += i2c-pca-isa.o >> obj-$(CONFIG_I2C_SIBYTE) += i2c-sibyte.o >> obj-$(CONFIG_I2C_XGENE_SLIMPRO) += i2c-xgene-slimpro.o >> obj-$(CONFIG_SCx200_ACB) += scx200_acb.o >> +obj-$(CONFIG_I2C_FSI) += i2c-fsi.o >> >> ccflags-$(CONFIG_I2C_DEBUG_BUS) := -DDEBUG >> diff --git a/drivers/i2c/busses/i2c-fsi.c b/drivers/i2c/busses/i2c-fsi.c >> new file mode 100644 >> index 0000000..e1b183c >> --- /dev/null >> +++ b/drivers/i2c/busses/i2c-fsi.c >> @@ -0,0 +1,234 @@ >> +// SPDX-License-Identifier: GPL-2.0+ >> +/* >> + * FSI-attached I2C master algorithm >> + * >> + * Copyright 2018 IBM Corporation >> + * >> + * 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. >> + */ >> + >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> + >> +#define FSI_ENGID_I2C 0x7 >> + >> +#define I2C_DEFAULT_CLK_DIV 6 >> + >> +/* i2c registers */ >> +#define I2C_FSI_FIFO 0x00 >> +#define I2C_FSI_CMD 0x04 >> +#define I2C_FSI_MODE 0x08 >> +#define I2C_FSI_WATER_MARK 0x0C >> +#define I2C_FSI_INT_MASK 0x10 >> +#define I2C_FSI_INT_COND 0x14 >> +#define I2C_FSI_OR_INT_MASK 0x14 >> +#define I2C_FSI_INTS 0x18 >> +#define I2C_FSI_AND_INT_MASK 0x18 >> +#define I2C_FSI_STAT 0x1C >> +#define I2C_FSI_RESET_I2C 0x1C >> +#define I2C_FSI_ESTAT 0x20 >> +#define I2C_FSI_RESET_ERR 0x20 >> +#define I2C_FSI_RESID_LEN 0x24 >> +#define I2C_FSI_SET_SCL 0x24 >> +#define I2C_FSI_PORT_BUSY 0x28 >> +#define I2C_FSI_RESET_SCL 0x2C >> +#define I2C_FSI_SET_SDA 0x30 >> +#define I2C_FSI_RESET_SDA 0x34 >> + >> +/* cmd register */ >> +#define I2C_CMD_WITH_START BIT(31) >> +#define I2C_CMD_WITH_ADDR BIT(30) >> +#define I2C_CMD_RD_CONT BIT(29) >> +#define I2C_CMD_WITH_STOP BIT(28) >> +#define I2C_CMD_FORCELAUNCH BIT(27) >> +#define I2C_CMD_ADDR GENMASK(23, 17) >> +#define I2C_CMD_READ BIT(16) >> +#define I2C_CMD_LEN GENMASK(15, 0) >> + >> +/* mode register */ >> +#define I2C_MODE_CLKDIV GENMASK(31, 16) >> +#define I2C_MODE_PORT GENMASK(15, 10) >> +#define I2C_MODE_ENHANCED BIT(3) >> +#define I2C_MODE_DIAG BIT(2) >> +#define I2C_MODE_PACE_ALLOW BIT(1) >> +#define I2C_MODE_WRAP BIT(0) >> + >> +/* watermark register */ >> +#define I2C_WATERMARK_HI GENMASK(15, 12) >> +#define I2C_WATERMARK_LO GENMASK(7, 4) >> + >> +#define I2C_FIFO_HI_LVL 4 >> +#define I2C_FIFO_LO_LVL 4 >> + >> +/* interrupt register */ >> +#define I2C_INT_INV_CMD BIT(15) >> +#define I2C_INT_PARITY BIT(14) >> +#define I2C_INT_BE_OVERRUN BIT(13) >> +#define I2C_INT_BE_ACCESS BIT(12) >> +#define I2C_INT_LOST_ARB BIT(11) >> +#define I2C_INT_NACK BIT(10) >> +#define I2C_INT_DAT_REQ BIT(9) >> +#define I2C_INT_CMD_COMP BIT(8) >> +#define I2C_INT_STOP_ERR BIT(7) >> +#define I2C_INT_BUSY BIT(6) >> +#define I2C_INT_IDLE BIT(5) >> + >> +#define I2C_INT_ENABLE 0x0000ff80 >> +#define I2C_INT_ERR 0x0000fcc0 > Now it looks like a flags combinations. > For me as for reader would be better to see quickly a decoded line. > > My proposal is to introduce something like following > > _INT_ALL GENMASK() > _INT_ENABLE (_INT_ALL & ~(_FOO | _BAR)) > _INT_ERR ... similar way as above ... > > What do you think? Yes I considered that. I do prefer the simplicity of just writing the value directly. Doing GENMASK and then AND-ing out certain bits isn't that much more understandable, in my opinion. To understand each bit you'd still have to check the GENMASK against the bit fields defined above. And just OR-ing together all the bits would be very lengthy for such an expression. Up to you, I will follow your suggestion if you want. > >> + >> +/* status register */ >> +#define I2C_STAT_INV_CMD BIT(31) >> +#define I2C_STAT_PARITY BIT(30) >> +#define I2C_STAT_BE_OVERRUN BIT(29) >> +#define I2C_STAT_BE_ACCESS BIT(28) >> +#define I2C_STAT_LOST_ARB BIT(27) >> +#define I2C_STAT_NACK BIT(26) >> +#define I2C_STAT_DAT_REQ BIT(25) >> +#define I2C_STAT_CMD_COMP BIT(24) >> +#define I2C_STAT_STOP_ERR BIT(23) >> +#define I2C_STAT_MAX_PORT GENMASK(19, 16) >> +#define I2C_STAT_ANY_INT BIT(15) >> +#define I2C_STAT_SCL_IN BIT(11) >> +#define I2C_STAT_SDA_IN BIT(10) >> +#define I2C_STAT_PORT_BUSY BIT(9) >> +#define I2C_STAT_SELF_BUSY BIT(8) >> +#define I2C_STAT_FIFO_COUNT GENMASK(7, 0) >> + >> +#define I2C_STAT_ERR 0xfc800000 >> +#define I2C_STAT_ANY_RESP 0xff800000 > Ditto. > >> + >> +/* extended status register */ >> +#define I2C_ESTAT_FIFO_SZ GENMASK(31, 24) >> +#define I2C_ESTAT_SCL_IN_SY BIT(15) >> +#define I2C_ESTAT_SDA_IN_SY BIT(14) >> +#define I2C_ESTAT_S_SCL BIT(13) >> +#define I2C_ESTAT_S_SDA BIT(12) >> +#define I2C_ESTAT_M_SCL BIT(11) >> +#define I2C_ESTAT_M_SDA BIT(10) >> +#define I2C_ESTAT_HI_WATER BIT(9) >> +#define I2C_ESTAT_LO_WATER BIT(8) >> +#define I2C_ESTAT_PORT_BUSY BIT(7) >> +#define I2C_ESTAT_SELF_BUSY BIT(6) >> +#define I2C_ESTAT_VERSION GENMASK(4, 0) >> + >> +struct fsi_i2c_master { >> + struct fsi_device *fsi; >> + u8 fifo_size; >> +}; >> + >> +static int fsi_i2c_read_reg(struct fsi_device *fsi, unsigned int reg, >> + u32 *data) >> +{ >> + int rc; >> + __be32 data_be; >> + >> + rc = fsi_device_read(fsi, reg, &data_be, sizeof(data_be)); >> + if (rc) >> + return rc; >> + >> + *data = be32_to_cpu(data_be); >> + >> + return 0; >> +} >> + >> +static int fsi_i2c_write_reg(struct fsi_device *fsi, unsigned int reg, >> + u32 *data) >> +{ >> + __be32 data_be = cpu_to_be32p(data); >> + >> + return fsi_device_write(fsi, reg, &data_be, sizeof(data_be)); >> +} >> + >> +static int fsi_i2c_dev_init(struct fsi_i2c_master *i2c) >> +{ >> + int rc; >> + u32 mode = I2C_MODE_ENHANCED, extended_status, watermark; >> + u32 interrupt = 0; >> + >> + /* since we use polling, disable interrupts */ >> + rc = fsi_i2c_write_reg(i2c->fsi, I2C_FSI_INT_MASK, &interrupt); >> + if (rc) >> + return rc; >> + >> + mode |= FIELD_PREP(I2C_MODE_CLKDIV, I2C_DEFAULT_CLK_DIV); >> + rc = fsi_i2c_write_reg(i2c->fsi, I2C_FSI_MODE, &mode); >> + if (rc) >> + return rc; >> + >> + rc = fsi_i2c_read_reg(i2c->fsi, I2C_FSI_ESTAT, &extended_status); >> + if (rc) >> + return rc; >> + >> + i2c->fifo_size = FIELD_GET(I2C_ESTAT_FIFO_SZ, extended_status); >> + watermark = FIELD_PREP(I2C_WATERMARK_HI, >> + i2c->fifo_size - I2C_FIFO_HI_LVL); >> + watermark |= FIELD_PREP(I2C_WATERMARK_LO, I2C_FIFO_LO_LVL); >> + >> + return fsi_i2c_write_reg(i2c->fsi, I2C_FSI_WATER_MARK, &watermark); >> +} >> + >> +static int fsi_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, >> + int num) >> +{ >> + return -EOPNOTSUPP; >> +} >> + >> +static u32 fsi_i2c_functionality(struct i2c_adapter *adap) >> +{ >> + return I2C_FUNC_I2C | I2C_FUNC_PROTOCOL_MANGLING | I2C_FUNC_10BIT_ADDR >> + | I2C_FUNC_SMBUS_EMUL | I2C_FUNC_SMBUS_BLOCK_DATA; > Perhaps one property per line? At a quick glance through some other I2C bus drivers, it appears more standard to fit as many on a line as possible. I'll leave it as is unless anyone objects. I didn't get any checkpatch warning. Thanks, Eddie > >> +} >> + >> +static const struct i2c_algorithm fsi_i2c_algorithm = { >> + .master_xfer = fsi_i2c_xfer, >> + .functionality = fsi_i2c_functionality, >> +}; >> + >> +static int fsi_i2c_probe(struct device *dev) >> +{ >> + struct fsi_i2c_master *i2c; >> + int rc; >> + >> + i2c = devm_kzalloc(dev, sizeof(*i2c), GFP_KERNEL); >> + if (!i2c) >> + return -ENOMEM; >> + >> + i2c->fsi = to_fsi_dev(dev); >> + >> + rc = fsi_i2c_dev_init(i2c); >> + if (rc) >> + return rc; >> + >> + dev_set_drvdata(dev, i2c); >> + >> + return 0; >> +} >> + >> +static const struct fsi_device_id fsi_i2c_ids[] = { >> + { FSI_ENGID_I2C, FSI_VERSION_ANY }, >> + { 0 } > 0 is not required > >> +}; >> + >> +static struct fsi_driver fsi_i2c_driver = { >> + .id_table = fsi_i2c_ids, >> + .drv = { >> + .name = "i2c-fsi", >> + .bus = &fsi_bus_type, >> + .probe = fsi_i2c_probe, >> + }, >> +}; >> + >> +module_fsi_driver(fsi_i2c_driver); >> + >> +MODULE_AUTHOR("Eddie James "); >> +MODULE_DESCRIPTION("FSI attached I2C master"); >> +MODULE_LICENSE("GPL"); >> -- >> 1.8.3.1 >> > >