Received: by 10.223.164.202 with SMTP id h10csp137803wrb; Thu, 16 Nov 2017 20:44:41 -0800 (PST) X-Google-Smtp-Source: AGs4zMY6DCwF6u0bo0t4GeL1Wzng0LBkQZp1Rq6fxObJWfj+0LSAM3tHc/eiWik+XPGzoAnSx1x6 X-Received: by 10.99.120.131 with SMTP id t125mr3899723pgc.81.1510893881827; Thu, 16 Nov 2017 20:44:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510893881; cv=none; d=google.com; s=arc-20160816; b=iBSG/soEl/6A/2cH5hPPMRvBIqaxkU6ZKPtnTqXbhllfI1f73lsUijyA0QKVZMMWoE jVhxcXubmrV/VYub3uNWsk0eOo7gtmvc/Eq/WoOzixEM55iMALfuAJc85M5cxnWghHbX LQPU4lKVD+aYHGFkpfXHb0YfqyGQUj5cVr1nvH8Igibp9LKuCj8DUhHrYgPygPd3GPi8 qnpvYMnKHNcHQDJHa1+fCrVxC23Cya9SSvZhLdge4bTaiGtZNNcK5tMigDmmsT2v+Gp6 ALdHIKyKeEBKKKLrzlEMiARUQ6hWq+mmPUz/iH2ot0T3vbTSDd+QPQoxyHjVOsZvpAEj 3ggg== 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=fIOoJKUbgKLtiqmF/rPpc7jm7/PBtvg0fFRju3mgELc=; b=X92cNp74oEnh8almJkxhrbK5PrSF06Gt4W5xGW0SzkcyhVmTbf2vFLuCm36JMWwSE2 LIbk8co0O/VrXYt+yj7RQ+VJ+pNL1jNgc60cF2i9IzDOjhY/8jB1Ur5hzvOunfCBJza+ v5cBxuNvKqgV6872+1xjByFUwIQzkAOEU43nNirnuIcrOY67rzYpM8cmcAaKGXmjTN7K 4AtTatPGw0q3jlDfOfl9okvxcmZnSjnq5+s3fJyKocqBTLJwGuxYsOhpd5+gDS72uksV fYQbzuG1PhHqe3S3HEqfhT+0FY7sKvDOTOIsihELuadHcZ/1Y86UVcmzMDV4NXEh9fwS ZITw== 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 bf5si2096466plb.226.2017.11.16.20.44.29; Thu, 16 Nov 2017 20:44:41 -0800 (PST) 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 S933319AbdKPTyx (ORCPT + 92 others); Thu, 16 Nov 2017 14:54:53 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:35786 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758067AbdKPTyU (ORCPT ); Thu, 16 Nov 2017 14:54:20 -0500 Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vAGJsHvf089575 for ; Thu, 16 Nov 2017 14:54:20 -0500 Received: from e36.co.us.ibm.com (e36.co.us.ibm.com [32.97.110.154]) by mx0a-001b2d01.pphosted.com with ESMTP id 2e9f4fpkmh-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 16 Nov 2017 14:54:19 -0500 Received: from localhost by e36.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 16 Nov 2017 12:54:18 -0700 Received: from b03cxnp08027.gho.boulder.ibm.com (9.17.130.19) by e36.co.us.ibm.com (192.168.1.136) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 16 Nov 2017 12:54:15 -0700 Received: from b03ledav004.gho.boulder.ibm.com (b03ledav004.gho.boulder.ibm.com [9.17.130.235]) by b03cxnp08027.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vAGJsE8Q4391372; Thu, 16 Nov 2017 12:54:14 -0700 Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9C41978043; Thu, 16 Nov 2017 12:54:14 -0700 (MST) Received: from oc3016140333.ibm.com (unknown [9.85.131.228]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP id 6A74078047; Thu, 16 Nov 2017 12:54:13 -0700 (MST) From: Eddie James To: linux-kernel@vger.kernel.org Cc: linux-i2c@vger.kernel.org, devicetree@vger.kernel.org, wsa@the-dreams.de, robh+dt@kernel.org, joel@jms.id.au, eajames@linux.vnet.ibm.com, "Edward A. James" Subject: [PATCH v6 5/7] drivers/i2c: Add transfer implementation for FSI algorithm Date: Thu, 16 Nov 2017 13:53:50 -0600 X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1510862032-12394-1-git-send-email-eajames@linux.vnet.ibm.com> References: <1510862032-12394-1-git-send-email-eajames@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17111619-0020-0000-0000-00000D029DB9 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008076; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000240; SDB=6.00946833; UDB=6.00477976; IPR=6.00727125; BA=6.00005695; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00018049; XFM=3.00000015; UTC=2017-11-16 19:54:17 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17111619-0021-0000-0000-00005EEE4677 Message-Id: <1510862032-12394-6-git-send-email-eajames@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-11-16_06:,, 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 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1711160266 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Edward A. James" Execute I2C transfers from the FSI-attached I2C master. Use polling instead of interrupts as we have no hardware IRQ over FSI. Signed-off-by: Edward A. James --- drivers/i2c/busses/i2c-fsi.c | 214 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 212 insertions(+), 2 deletions(-) diff --git a/drivers/i2c/busses/i2c-fsi.c b/drivers/i2c/busses/i2c-fsi.c index 61609bce..5c312ef 100644 --- a/drivers/i2c/busses/i2c-fsi.c +++ b/drivers/i2c/busses/i2c-fsi.c @@ -152,6 +152,7 @@ struct fsi_i2c_port { struct i2c_adapter adapter; struct fsi_i2c_master *master; u16 port; + u16 xfrd; }; static int fsi_i2c_read_reg(struct fsi_device *fsi, unsigned int reg, @@ -236,6 +237,103 @@ static int fsi_i2c_set_port(struct fsi_i2c_port *port) return rc; } +static int fsi_i2c_start(struct fsi_i2c_port *port, struct i2c_msg *msg, + bool stop) +{ + int rc; + struct fsi_i2c_master *i2c = port->master; + u32 cmd = I2C_CMD_WITH_START | I2C_CMD_WITH_ADDR; + + port->xfrd = 0; + + if (msg->flags & I2C_M_RD) + cmd |= I2C_CMD_READ; + + if (stop || msg->flags & I2C_M_STOP) + cmd |= I2C_CMD_WITH_STOP; + + cmd = SETFIELD(I2C_CMD_ADDR, cmd, msg->addr >> 1); + cmd = SETFIELD(I2C_CMD_LEN, cmd, msg->len); + + rc = fsi_i2c_write_reg(i2c->fsi, I2C_FSI_CMD, &cmd); + + return rc; +} + +static int fsi_i2c_write_fifo(struct fsi_i2c_port *port, struct i2c_msg *msg, + u8 fifo_count) +{ + int write; + int rc = 0; + struct fsi_i2c_master *i2c = port->master; + int bytes_to_write = i2c->fifo_size - fifo_count; + int bytes_remaining = msg->len - port->xfrd; + + if (bytes_to_write > bytes_remaining) + bytes_to_write = bytes_remaining; + + while (bytes_to_write > 0) { + write = bytes_to_write; + /* fsi limited to max 4 byte aligned ops */ + if (bytes_to_write > 4) + write = 4; + else if (write == 3) + write = 2; + + rc = fsi_device_write(i2c->fsi, I2C_FSI_FIFO, + &msg->buf[port->xfrd], write); + if (rc) + return rc; + + port->xfrd += write; + bytes_to_write -= write; + } + + return rc; +} + +static int fsi_i2c_read_fifo(struct fsi_i2c_port *port, struct i2c_msg *msg, + u8 fifo_count) +{ + int read; + int rc = 0; + struct fsi_i2c_master *i2c = port->master; + int xfr_remaining = msg->len - port->xfrd; + u32 dummy; + + while (fifo_count) { + read = fifo_count; + /* fsi limited to max 4 byte aligned ops */ + if (fifo_count > 4) + read = 4; + else if (read == 3) + read = 2; + + if (xfr_remaining) { + if (xfr_remaining < read) + read = xfr_remaining; + + rc = fsi_device_read(i2c->fsi, I2C_FSI_FIFO, + &msg->buf[port->xfrd], read); + if (rc) + return rc; + + port->xfrd += read; + xfr_remaining -= read; + } else { + /* no more buffer but data in fifo, need to clear it */ + rc = fsi_device_read(i2c->fsi, I2C_FSI_FIFO, &dummy, + read); + if (rc) + return rc; + } + + fifo_count -= read; + } + + return rc; +} + static int fsi_i2c_reset_bus(struct fsi_i2c_master *i2c) { int i, rc; @@ -409,17 +507,129 @@ static int fsi_i2c_abort(struct fsi_i2c_port *port, u32 status) return -ETIME; } +static int fsi_i2c_handle_status(struct fsi_i2c_port *port, + struct i2c_msg *msg, u32 status) +{ + int rc; + u8 fifo_count; + + if (status & I2C_STAT_ERR) { + rc = fsi_i2c_abort(port, status); + if (rc) + return rc; + + if (status & I2C_STAT_INV_CMD) + return -EINVAL; + + if (status & (I2C_STAT_PARITY | I2C_STAT_BE_OVERRUN | + I2C_STAT_BE_ACCESS)) + return -EPROTO; + + if (status & I2C_STAT_NACK) + return -ENXIO; + + if (status & I2C_STAT_LOST_ARB) + return -EAGAIN; + + if (status & I2C_STAT_STOP_ERR) + return -EBADMSG; + + return -EIO; + } + + if (status & I2C_STAT_DAT_REQ) { + fifo_count = GETFIELD(I2C_STAT_FIFO_COUNT, status); + + if (msg->flags & I2C_M_RD) + rc = fsi_i2c_read_fifo(port, msg, fifo_count); + else + rc = fsi_i2c_write_fifo(port, msg, fifo_count); + + return rc; + } + + if (status & I2C_STAT_CMD_COMP) { + if (port->xfrd < msg->len) + rc = -ENODATA; + else + rc = msg->len; + + return rc; + } + + return 0; +} + +static int fsi_i2c_wait(struct fsi_i2c_port *port, struct i2c_msg *msg, + unsigned long timeout) +{ + u32 status = 0; + int rc, rc_abort; + unsigned long start = jiffies; + + do { + rc = fsi_i2c_read_reg(port->master->fsi, I2C_FSI_STAT, + &status); + if (rc) + return rc; + + if (status & I2C_STAT_ANY_RESP) { + rc = fsi_i2c_handle_status(port, msg, status); + if (rc < 0) + return rc; + + /* cmd complete and all data xfrd */ + if (rc == msg->len) + return 0; + + /* need to xfr more data, but maybe don't need wait */ + continue; + } + + set_current_state(TASK_INTERRUPTIBLE); + if (schedule_timeout(I2C_LOCAL_WAIT_TIMEOUT) > 0) { + rc = -EINTR; + goto abort; + } + } while (time_after(start + timeout, jiffies)); + + rc = -ETIME; + +abort: + rc_abort = fsi_i2c_abort(port, status); + if (rc_abort) + return rc_abort; + + return rc; +} + static int fsi_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) { - int rc; + int i, rc; + unsigned long start_time; struct fsi_i2c_port *port = adap->algo_data; + struct i2c_msg *msg; rc = fsi_i2c_set_port(port); if (rc) return rc; - return -EOPNOTSUPP; + for (i = 0; i < num; ++i) { + msg = msgs + i; + start_time = jiffies; + + rc = fsi_i2c_start(port, msg, i == num - 1); + if (rc) + return rc; + + rc = fsi_i2c_wait(port, msg, + adap->timeout - (jiffies - start_time)); + if (rc) + return rc; + } + + return 0; } static u32 fsi_i2c_functionality(struct i2c_adapter *adap) -- 1.8.3.1 From 1584093088181985563@xxx Wed Nov 15 01:21:32 +0000 2017 X-GM-THRID: 1584093088181985563 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread