Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp9000imm; Mon, 4 Jun 2018 12:03:44 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIK5WGcTNhmr31S8C+SWMqxsb9JZXKmgjoOMeb9PKJYt9sWvQZxDamrNIQ940bfGApmUvKQ X-Received: by 2002:a17:902:3343:: with SMTP id a61-v6mr22780611plc.241.1528139024061; Mon, 04 Jun 2018 12:03:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528139024; cv=none; d=google.com; s=arc-20160816; b=ngVWAinm/mJqsa8yynLbglzxtMIyv8wXNsRHMWq19HJWq9xfhzLVEAtAqb6C8PKx2z DKa2PdWZh+7oqvkmOOr/ZXZl/Ym1HAQJLxgJRpmpm7dgdHtoYptdgQPswJCI8iJzQYv2 ffjUXCXR6dTOyPQC0YOfaAwmir1f3FF/6Z+6zqOQyFCOkcvEUVi1ewRH4K+xmaIUMmBm p0pnHT75IaZpdfO5SnRc6z7Bcni/698LH+pJ8N/R5704py5VXxlYoubX5zAKFpW+m4tj tqk1PkOMvtcS3J+AddXj7o8kFvLdAI1BhVSdGBeT/pp9wJ+Q2BwojPKlk9EFA5gUqBpl SKQQ== 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=+bVF1ROwuUx4TD7Dxg6HfMvm5vhHSrx/vI8+ssSoNyI=; b=0aQejn/YXNFW/Brn9H/efp2iVsuu4koFcFHIJ9x8DB3Nt1ZVl6LCp35xCripvVkrfl HjDa/nK5JYozFkRpOk+dSxNyPdkz3tr98wgJLb63OR/F3per3WLMnRetkKjr9O5O4pdL i/QqGRSpTUpYTkfBhNmVrl5dNPVXcssLUlV1bj/+MNIgkh6QOGvt84qUcyJpFl1YzE2B e94l26Wr2HZw5vK1axsb0srMTJZUaegssDQLrJnooa2fsh13UnwMaCXPqf3VM0K9k//1 mqLVqhIZ+6z82OnemdztZQrQpoPV/5Me1ry8ekhNT6mcvYU/G+3DeqDZVphANC5IsQCQ GvnA== 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 w12-v6si46199127pld.46.2018.06.04.12.03.18; Mon, 04 Jun 2018 12:03:44 -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 S1751399AbeFDTBM (ORCPT + 99 others); Mon, 4 Jun 2018 15:01:12 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:42308 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751354AbeFDTBI (ORCPT ); Mon, 4 Jun 2018 15:01:08 -0400 Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w54Iwmf0043625 for ; Mon, 4 Jun 2018 15:01:08 -0400 Received: from e12.ny.us.ibm.com (e12.ny.us.ibm.com [129.33.205.202]) by mx0a-001b2d01.pphosted.com with ESMTP id 2jd8nr6gbj-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 04 Jun 2018 15:01:07 -0400 Received: from localhost by e12.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 4 Jun 2018 15:01:05 -0400 Received: from b01cxnp22035.gho.pok.ibm.com (9.57.198.25) by e12.ny.us.ibm.com (146.89.104.199) 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 15:01:01 -0400 Received: from b01ledav002.gho.pok.ibm.com (b01ledav002.gho.pok.ibm.com [9.57.199.107]) by b01cxnp22035.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w54J10Gi52756514 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 4 Jun 2018 19:01:00 GMT Received: from b01ledav002.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6E6B812405E; Mon, 4 Jun 2018 16:02:28 -0400 (EDT) Received: from b01ledav002.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 842A512405C; Mon, 4 Jun 2018 16:02:27 -0400 (EDT) Received: from talon7.ibm.com (unknown [9.41.241.240]) by b01ledav002.gho.pok.ibm.com (Postfix) with ESMTP; Mon, 4 Jun 2018 16:02:27 -0400 (EDT) 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, rdunlap@infradead.org, andy.shevchenko@gmail.com, Eddie James Subject: [PATCH v9 3/7] i2c: fsi: Add port structures Date: Mon, 4 Jun 2018 14:00:46 -0500 X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1528138850-18259-1-git-send-email-eajames@linux.vnet.ibm.com> References: <1528138850-18259-1-git-send-email-eajames@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18060419-0060-0000-0000-000002781684 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00009129; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000265; SDB=6.01042302; UDB=6.00533707; IPR=6.00821432; MB=3.00021461; MTD=3.00000008; XFM=3.00000015; UTC=2018-06-04 19:01:04 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18060419-0061-0000-0000-0000455670AC Message-Id: <1528138850-18259-4-git-send-email-eajames@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-06-04_13:,, 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-1806040219 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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: Eddie James --- drivers/i2c/busses/i2c-fsi.c | 90 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/drivers/i2c/busses/i2c-fsi.c b/drivers/i2c/busses/i2c-fsi.c index e1b183c..12130c3 100644 --- a/drivers/i2c/busses/i2c-fsi.c +++ b/drivers/i2c/busses/i2c-fsi.c @@ -17,7 +17,10 @@ #include #include #include +#include #include +#include +#include #define FSI_ENGID_I2C 0x7 @@ -123,6 +126,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, @@ -176,9 +187,38 @@ static int fsi_i2c_dev_init(struct fsi_i2c_master *i2c) return fsi_i2c_write_reg(i2c->fsi, I2C_FSI_WATER_MARK, &watermark); } +static int fsi_i2c_set_port(struct fsi_i2c_port *port) +{ + int rc; + struct fsi_device *fsi = port->master->fsi; + u32 mode, dummy = 0; + + rc = fsi_i2c_read_reg(fsi, I2C_FSI_MODE, &mode); + if (rc) + return rc; + + if (FIELD_GET(I2C_MODE_PORT, mode) == port->port) + return 0; + + mode = (mode & ~I2C_MODE_PORT) | FIELD_PREP(I2C_MODE_PORT, port->port); + rc = fsi_i2c_write_reg(fsi, I2C_FSI_MODE, &mode); + if (rc) + return rc; + + /* reset engine when port is changed */ + return fsi_i2c_write_reg(fsi, I2C_FSI_RESET_ERR, &dummy); +} + 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; } @@ -196,23 +236,72 @@ 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 = kzalloc(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); + kfree(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; + + list_for_each_entry(port, &i2c->ports, list) { + i2c_del_adapter(&port->adapter); + kfree(port); + } + + return 0; +} + static const struct fsi_device_id fsi_i2c_ids[] = { { FSI_ENGID_I2C, FSI_VERSION_ANY }, { 0 } @@ -224,6 +313,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