Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp3859077imm; Tue, 29 May 2018 15:26:33 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLfhs9ItyNCuB7zLhhl+yWMk9x2fGC83VREQ6w9DnS5VO3GeWyoQSdqvgrefmbZJ03gBjiW X-Received: by 2002:a17:902:c81:: with SMTP id 1-v6mr263644plt.126.1527632793132; Tue, 29 May 2018 15:26:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527632793; cv=none; d=google.com; s=arc-20160816; b=vv/f8UAWHRQ/8yqIzFBtSDvZQQCpAOA40LdxpRJAfg8vP0CnR2IKivpuzDSszTJ09f XHzhcM2MH65J7DbZN7e5LMKe993ZDb4z/tUCjWQk0NYhhEOJn5H9bdBT+79L+rEQGJkz gaBIe6M7wC4W6EqiMlgPbkbemQeAwamwyMpxPDFddy7Ai8aBs4hGe3YAAnZBZarAqXRO 2Lsfm+TkMbuSnJGQX27be1gPa2xItXnFIxmgMNIpSNDhsw4v1nResSE9URqAO4jKB2bq I6ONrpeJczzQAS0XP1zKnnpfqnrIyx2ZSNoIzZ19NvAqxX+PYIrZA9yrzxoomvTY/sKQ 9ifw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:references:in-reply-to:date :subject:cc:to:from:arc-authentication-results; bh=/MgRjq2urKJerMNXMVKLpSjS/cNidjA86xq6ABSnbzw=; b=Nd8la5Is3ODwHuwHi50idElxAEVhtlMJjysYRLW9FS0Z6Zn43kOtfq+ffdkhhYLGVQ 2Jccnf591qT8WquB9JdyeTg8wY9MmY7l1h0u4oli4TTJGE4PFxisbGX/CwahD5x62JfJ 3q0b4ryBb7+nbIP9cV0Qup1ZtDCkTPiXZL+b6eVskbpimpDW6VcpgWPi0PZSSGy+/gmX nbGJmxfPGbDtWShMgkUYdSN8rP7+h5twzMNBmZiGOVepjchE+SuHZCvcxatRnhsSmu8N H+zAZiBW35R1eY1C1VROHic2A2Z6EG2XWF3HQjk8jesmiknLs8hsb/Nx9PVAlfrjNaGW s5LA== 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 x3-v6si16823952plr.307.2018.05.29.15.26.19; Tue, 29 May 2018 15:26:33 -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 S968494AbeE2WYu (ORCPT + 99 others); Tue, 29 May 2018 18:24:50 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:44356 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S968351AbeE2WYn (ORCPT ); Tue, 29 May 2018 18:24:43 -0400 Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w4TMOGSw077636 for ; Tue, 29 May 2018 18:24:43 -0400 Received: from e36.co.us.ibm.com (e36.co.us.ibm.com [32.97.110.154]) by mx0a-001b2d01.pphosted.com with ESMTP id 2j9ewn1ehk-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 29 May 2018 18:24:42 -0400 Received: from localhost by e36.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 29 May 2018 16:24:42 -0600 Received: from b03cxnp08025.gho.boulder.ibm.com (9.17.130.17) by e36.co.us.ibm.com (192.168.1.136) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Tue, 29 May 2018 16:24:39 -0600 Received: from b03ledav004.gho.boulder.ibm.com (b03ledav004.gho.boulder.ibm.com [9.17.130.235]) by b03cxnp08025.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w4TMOcjx22282550 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 29 May 2018 15:24:38 -0700 Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4277B7804D; Tue, 29 May 2018 16:24:38 -0600 (MDT) Received: from talon7.ibm.com (unknown [9.80.223.183]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP id 5D92078037; Tue, 29 May 2018 16:24:36 -0600 (MDT) From: Eddie James To: linux-i2c@vger.kernel.org Cc: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, wsa@the-dreams.de, robh+dt@kernel.org, benh@kernel.crashing.org, joel@jms.id.au, mark.rutland@arm.com, gregkh@linuxfoundation.org, "Edward A. James" Subject: [PATCH v7 3/7] drivers/i2c: Add port structure to FSI algorithm Date: Tue, 29 May 2018 17:24:21 -0500 X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1527632665-25707-1-git-send-email-eajames@linux.vnet.ibm.com> References: <1527632665-25707-1-git-send-email-eajames@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18052922-0020-0000-0000-00000E0A1416 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00009097; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000264; SDB=6.01039557; UDB=6.00532065; IPR=6.00818685; MB=3.00021364; MTD=3.00000008; XFM=3.00000015; UTC=2018-05-29 22:24:41 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18052922-0021-0000-0000-000061A51D5E Message-Id: <1527632665-25707-4-git-send-email-eajames@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-05-29_10:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 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-1805290238 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Edward A. James" Add and initialize I2C adapters for each port on the FSI-attached I2C master. Ports for each master are defined in the devicetree. Signed-off-by: Edward A. James --- drivers/i2c/busses/i2c-fsi.c | 96 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/drivers/i2c/busses/i2c-fsi.c b/drivers/i2c/busses/i2c-fsi.c index 79475f8..4ad5d68 100644 --- a/drivers/i2c/busses/i2c-fsi.c +++ b/drivers/i2c/busses/i2c-fsi.c @@ -14,7 +14,9 @@ #include #include #include +#include #include +#include #define FSI_ENGID_I2C 0x7 @@ -130,6 +132,14 @@ struct fsi_i2c_master { struct fsi_device *fsi; u8 fifo_size; + struct list_head ports; +}; + +struct fsi_i2c_port { + struct list_head list; + struct i2c_adapter adapter; + struct fsi_i2c_master *master; + u16 port; }; static int fsi_i2c_read_reg(struct fsi_device *fsi, unsigned int reg, @@ -186,9 +196,44 @@ static int fsi_i2c_dev_init(struct fsi_i2c_master *i2c) return rc; } +static int fsi_i2c_set_port(struct fsi_i2c_port *port) +{ + int rc; + struct fsi_device *fsi = port->master->fsi; + u32 mode, dummy = 0; + u16 old_port; + + rc = fsi_i2c_read_reg(fsi, I2C_FSI_MODE, &mode); + if (rc) + return rc; + + old_port = GETFIELD(I2C_MODE_PORT, mode); + + if (old_port != port->port) { + mode = SETFIELD(I2C_MODE_PORT, mode, port->port); + rc = fsi_i2c_write_reg(fsi, I2C_FSI_MODE, &mode); + if (rc) + return rc; + + /* reset engine when port is changed */ + rc = fsi_i2c_write_reg(fsi, I2C_FSI_RESET_ERR, &dummy); + if (rc) + return rc; + } + + return rc; +} + static int fsi_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) { + int rc; + struct fsi_i2c_port *port = adap->algo_data; + + rc = fsi_i2c_set_port(port); + if (rc) + return rc; + return -EOPNOTSUPP; } @@ -206,23 +251,73 @@ static u32 fsi_i2c_functionality(struct i2c_adapter *adap) static int fsi_i2c_probe(struct device *dev) { struct fsi_i2c_master *i2c; + struct fsi_i2c_port *port; + struct device_node *np; int rc; + u32 port_no; i2c = devm_kzalloc(dev, sizeof(*i2c), GFP_KERNEL); if (!i2c) return -ENOMEM; i2c->fsi = to_fsi_dev(dev); + INIT_LIST_HEAD(&i2c->ports); rc = fsi_i2c_dev_init(i2c); if (rc) return rc; + /* Add adapter for each i2c port of the master. */ + for_each_available_child_of_node(dev->of_node, np) { + rc = of_property_read_u32(np, "reg", &port_no); + if (rc || port_no > USHRT_MAX) + continue; + + port = devm_kzalloc(dev, sizeof(*port), GFP_KERNEL); + if (!port) + break; + + port->master = i2c; + port->port = port_no; + + port->adapter.owner = THIS_MODULE; + port->adapter.dev.of_node = np; + port->adapter.dev.parent = dev; + port->adapter.algo = &fsi_i2c_algorithm; + port->adapter.algo_data = port; + + snprintf(port->adapter.name, sizeof(port->adapter.name), + "i2c_bus-%u", port_no); + + rc = i2c_add_adapter(&port->adapter); + if (rc < 0) { + dev_err(dev, "Failed to register adapter: %d\n", rc); + devm_kfree(dev, port); + continue; + } + + list_add(&port->list, &i2c->ports); + } + dev_set_drvdata(dev, i2c); return 0; } +static int fsi_i2c_remove(struct device *dev) +{ + struct fsi_i2c_master *i2c = dev_get_drvdata(dev); + struct fsi_i2c_port *port; + + if (!list_empty(&i2c->ports)) { + list_for_each_entry(port, &i2c->ports, list) { + i2c_del_adapter(&port->adapter); + } + } + + return 0; +} + static const struct fsi_device_id fsi_i2c_ids[] = { { FSI_ENGID_I2C, FSI_VERSION_ANY }, { 0 } @@ -234,6 +329,7 @@ static int fsi_i2c_probe(struct device *dev) .name = "i2c-fsi", .bus = &fsi_bus_type, .probe = fsi_i2c_probe, + .remove = fsi_i2c_remove, }, }; -- 1.8.3.1