Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp43546imm; Mon, 4 Jun 2018 12:41:25 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJAObwP+i5xnMUYMqB5IguyaOhFIbzgcOwKEcNYHOLl9NA6BQZ457VSDGbNkQjxGWVuaHHc X-Received: by 2002:a63:343:: with SMTP id 64-v6mr18533922pgd.354.1528141285931; Mon, 04 Jun 2018 12:41:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528141285; cv=none; d=google.com; s=arc-20160816; b=oQszSqbponFIEreHzR5QLg4hAoEVzE0tE6GN7cqfskl8KlHPSQhUKQODvfr6s2IGhe sW+NFF5ReTozbnN1YiFpvBeJEmTEN2alCPABzqoUmN7qjhH/u07Y8CCVufD2QJf+Fu2u EeLD0xFXhzKk4L+Bxv6wMTleWDM8A8RvwWi2VdDV0HYX6FpXBmDSP7ajrh0Ypp7cE5QG X3xIY9y/FGSj7jdOnIqeK8zgHXObu+lsqkjlRTslVWhw4MCopB2t9g8+gjYCUtGQQQFr sezlqnIruAQF3JaB+K3P6+kkmPImz+3awJNK1n5IvjiWaxFZK3S46XY3gR/Bqf4oX2vA YRbQ== 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=ovk894FAJlMiRcMOw0OpbKBmvhVCjVVrqDA8urJv6ek=; b=Ps5kkAVRXOv0KnioKU+JAp5db24qYF7p/MxuKKVX9KgcZudXCbXxncUUy/ffFj7uR/ A25j1h7IWvMvI9YIC/pR2GNME6lH4jwKdW3GYv0ni2X3oTfkl1VatIiaHsCvn1Mx3N0Q +fYW/0Ctp4pXsbWbeqLXeSzRT799Kzb4BTMvEnLhTAF/Y1rBAJXb//AggI1VBqMLivTS ag02RBowM1SfqdBZK8AJrSj2rPzyDuxzBCHHGiQzf4Iy42PY/5Zm0SOHfhP2w4TXUOCy KLKkFeX1+cz4ZVXfCZyPXjt2KWyu3K6ycvs2eq5hYNEW5LVGzTarfwpRRKDZdAgLOUjE lVxg== 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 s187-v6si20657981pgc.447.2018.06.04.12.41.11; Mon, 04 Jun 2018 12:41:25 -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 S1751119AbeFDTko (ORCPT + 99 others); Mon, 4 Jun 2018 15:40:44 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:37134 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750995AbeFDTkl (ORCPT ); Mon, 4 Jun 2018 15:40:41 -0400 Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w54Jd931132792 for ; Mon, 4 Jun 2018 15:40:41 -0400 Received: from e14.ny.us.ibm.com (e14.ny.us.ibm.com [129.33.205.204]) by mx0a-001b2d01.pphosted.com with ESMTP id 2jd8mgg617-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 04 Jun 2018 15:40:41 -0400 Received: from localhost by e14.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 4 Jun 2018 15:40:40 -0400 Received: from b01cxnp22033.gho.pok.ibm.com (9.57.198.23) by e14.ny.us.ibm.com (146.89.104.201) 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:40:35 -0400 Received: from b01ledav005.gho.pok.ibm.com (b01ledav005.gho.pok.ibm.com [9.57.199.110]) by b01cxnp22033.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w54JeYPe7799096 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 4 Jun 2018 19:40:34 GMT Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5B50CAE05F; Mon, 4 Jun 2018 15:40:53 -0400 (EDT) Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 48323AE063; Mon, 4 Jun 2018 15:40:52 -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 15:40:52 -0400 (EDT) Subject: Re: [PATCH v9 3/7] i2c: fsi: Add port structures 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-4-git-send-email-eajames@linux.vnet.ibm.com> From: Eddie James Date: Mon, 4 Jun 2018 14:40:32 -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: 18060419-0052-0000-0000-000002F81BB2 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.01042315; UDB=6.00533716; IPR=6.00821445; MB=3.00021461; MTD=3.00000008; XFM=3.00000015; UTC=2018-06-04 19:40:38 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18060419-0053-0000-0000-00005CE484B9 Message-Id: <2c839e9a-5b60-af90-40f1-df94c0112d95@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=2 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-1806040226 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 06/04/2018 02:17 PM, Andy Shevchenko wrote: > On Mon, Jun 4, 2018 at 10:00 PM, Eddie James wrote: >> 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); > Did you consider to split this to two lines / assignments? It fit on one line (< 80 chars) so I left it as-is... > >> + 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); >> + } > Just to be sure, it will be called if and only if all adapters are not > busy. Correct? If I understand the code and comments correctly, i2c_del_adapter will block until all references to the adapter device are gone. So, should be safe to free it now. Thanks, Eddie > >> + >> + 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 >> > >