From patchwork Thu Jul 16 08:08:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rayagonda Kokatanur X-Patchwork-Id: 11666839 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 484101392 for ; Thu, 16 Jul 2020 08:10:39 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 20EB12065D for ; Thu, 16 Jul 2020 08:10:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="vtxIf0iv"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="gyYRQVs7" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 20EB12065D Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=broadcom.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:MIME-Version:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:References:In-Reply-To:Message-Id:Date:Subject:To: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=GB/LuWGoKBLEXiaWDroAm/oHacwI6u2v6CG/Hxm+0d0=; b=vtxIf0ivIEdhiYmuUbeOWO6Eri jP3f0ybXYqezo/9iYSDNMhELIvWya5u8pd5ejai0Ct8ebcKuPPa40kI4VQYn8nSfKFNzReIXbqTi6 aCAF48qCDXgXqGHPbI8scphBNaj0FdAVYCGkfnaiMot84ynhAlMg2FhunSAzV23yloiUN0f9GaDZV xGk4WG7fs+41+z5HP/4mRAbOLrD1g+kwRX4JbNFfFedKwFe69NkxhzfOi5AWar+cl6lkLNvdQGbSu 9s/K7WQF+Ql+nP4v1FXx5vzQCGDOh9nwBGM8Qsi8m5Vateb4dA7p81dWdmSKOT7QklacE2w7cMUIT isdLRnyg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jvywz-00030e-Et; Thu, 16 Jul 2020 08:09:05 +0000 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jvywv-0002yt-Qu for linux-arm-kernel@lists.infradead.org; Thu, 16 Jul 2020 08:09:02 +0000 Received: by mail-pg1-x544.google.com with SMTP id g67so4462222pgc.8 for ; Thu, 16 Jul 2020 01:09:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=aCGGactJae57qbbpYq++cFizr8LPhk+6s9WIHNZJ04M=; b=gyYRQVs7B8rmkhComuQRCcJpLDEtIx8vxhDmau+6R2aE5Q5MdT3CM/RdY/j0v9jZF+ KwtzTbBXKD0F3ABDzmqXSEvGouXyCrNujVr9fZ/sCrw6ata/aQq/hOHhf1npzTRchpRS +L4OsbBx5DEXz/FYoqJCpx0QOUST0xnjM69Lg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=aCGGactJae57qbbpYq++cFizr8LPhk+6s9WIHNZJ04M=; b=fcKAVBHmw5q48AnVul8JlntAX8HPju68S5op5ah4k1eFofnGlNicE05XgCgGfDmSPN f+IjKGt6E+6ffeRuO+VegvBONLvAjYCJfTf737v4P3qM6Qsy7y+/UVp8CYQO3JkHyHKq D3dRHRqHY1L+AatRUD3PLRCtxUyqaCspcUN0C8zrfPG5q0FmgMNRPVLA4ABBvrPihcQC dSSn6svf5Gcf6Zox+qCNvH6zU9lEILYALl8h+3w7yZneaJd+ck8vFgmZ0/h1LS7hppTC Dpyt0b8R3PQdJLYubTTAiric1EQ15/er0AP/CDy5EEcFzQ7Qy1WFBothfbruYDmmdG14 IOmg== X-Gm-Message-State: AOAM533I/6XBe+uUUyf5+XPhTw7TCdVLFf2Q0NJxErvTai9RJS6+cny6 dXJvT3RODTEM6kKRVdMdmbCp9g== X-Google-Smtp-Source: ABdhPJzY89owDrFh1Z8KnO6xelQRBmWpGhbIDfhY7bcls9gGw1PkpgX/IgpGYwIRWXuRLq7oDoIdPw== X-Received: by 2002:aa7:9f8f:: with SMTP id z15mr2592603pfr.73.1594886939485; Thu, 16 Jul 2020 01:08:59 -0700 (PDT) Received: from rayagonda.dhcp.broadcom.net ([192.19.234.250]) by smtp.gmail.com with ESMTPSA id a3sm4353085pgd.73.2020.07.16.01.08.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jul 2020 01:08:58 -0700 (PDT) From: Rayagonda Kokatanur To: Wolfram Sang , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, Ray Jui , Scott Branden , bcm-kernel-feedback-list@broadcom.com, Lori Hikichi , Robert Richter , Nishka Dasgupta , Andy Shevchenko , linux-arm-kernel@lists.infradead.org Subject: [PATCH V1 2/2] i2c: iproc: add slave pec support Date: Thu, 16 Jul 2020 13:38:36 +0530 Message-Id: <20200716080836.2279-3-rayagonda.kokatanur@broadcom.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200716080836.2279-1-rayagonda.kokatanur@broadcom.com> References: <20200716080836.2279-1-rayagonda.kokatanur@broadcom.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200716_040901_897400_17BC97F8 X-CRM114-Status: GOOD ( 17.03 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:544 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.0 DKIMWL_WL_HIGH DKIMwl.org - Whitelisted High sender X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Rayagonda Kokatanur MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Iproc supports PEC computation and checking in both Master and Slave mode. This patch adds support for PEC in slave mode. Signed-off-by: Rayagonda Kokatanur --- drivers/i2c/busses/i2c-bcm-iproc.c | 50 +++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 4 deletions(-) diff --git a/drivers/i2c/busses/i2c-bcm-iproc.c b/drivers/i2c/busses/i2c-bcm-iproc.c index 8a3c98866fb7..51c8b165bb5e 100644 --- a/drivers/i2c/busses/i2c-bcm-iproc.c +++ b/drivers/i2c/busses/i2c-bcm-iproc.c @@ -93,6 +93,7 @@ #define S_CMD_STATUS_MASK 0x07 #define S_CMD_STATUS_SUCCESS 0x0 #define S_CMD_STATUS_TIMEOUT 0x5 +#define S_CMD_PEC_SHIFT 8 #define IE_OFFSET 0x38 #define IE_M_RX_FIFO_FULL_SHIFT 31 @@ -138,7 +139,9 @@ #define S_RX_OFFSET 0x4c #define S_RX_STATUS_SHIFT 30 #define S_RX_STATUS_MASK 0x03 -#define S_RX_PEC_ERR_SHIFT 29 +#define S_RX_PEC_ERR_SHIFT 28 +#define S_RX_PEC_ERR_MASK 0x3 +#define S_RX_PEC_ERR 0x1 #define S_RX_DATA_SHIFT 0 #define S_RX_DATA_MASK 0xff @@ -205,6 +208,8 @@ struct bcm_iproc_i2c_dev { /* bytes that have been read */ unsigned int rx_bytes; unsigned int thld_bytes; + + bool en_s_pec; }; /* @@ -321,6 +326,24 @@ static void bcm_iproc_i2c_check_slave_status( } } +static int bcm_iproc_smbus_check_slave_pec(struct bcm_iproc_i2c_dev *iproc_i2c, + u32 val) +{ + u8 err_status; + int ret = 0; + + if (!iproc_i2c->en_s_pec) + return ret; + + err_status = (u8)((val >> S_RX_PEC_ERR_SHIFT) & S_RX_PEC_ERR_MASK); + if (err_status == S_RX_PEC_ERR) { + dev_err(iproc_i2c->device, "Slave PEC error\n"); + ret = -EBADMSG; + } + + return ret; +} + static bool bcm_iproc_i2c_slave_isr(struct bcm_iproc_i2c_dev *iproc_i2c, u32 status) { @@ -347,6 +370,8 @@ static bool bcm_iproc_i2c_slave_isr(struct bcm_iproc_i2c_dev *iproc_i2c, iproc_i2c_wr_reg(iproc_i2c, S_TX_OFFSET, value); val = BIT(S_CMD_START_BUSY_SHIFT); + if (iproc_i2c->en_s_pec) + val |= BIT(S_CMD_PEC_SHIFT); iproc_i2c_wr_reg(iproc_i2c, S_CMD_OFFSET, val); /* @@ -361,9 +386,19 @@ static bool bcm_iproc_i2c_slave_isr(struct bcm_iproc_i2c_dev *iproc_i2c, value = (u8)((val >> S_RX_DATA_SHIFT) & S_RX_DATA_MASK); i2c_slave_event(iproc_i2c->slave, I2C_SLAVE_WRITE_RECEIVED, &value); - if (rx_status == I2C_SLAVE_RX_END) - i2c_slave_event(iproc_i2c->slave, - I2C_SLAVE_STOP, &value); + if (rx_status == I2C_SLAVE_RX_END) { + int ret; + + ret = bcm_iproc_smbus_check_slave_pec(iproc_i2c, + val); + if (!ret) + i2c_slave_event(iproc_i2c->slave, + I2C_SLAVE_STOP, &value); + else + i2c_slave_event(iproc_i2c->slave, + I2C_SLAVE_PEC_ERR, + &value); + } } } else if (status & BIT(IS_S_TX_UNDERRUN_SHIFT)) { /* Master read other than start */ @@ -372,6 +407,8 @@ static bool bcm_iproc_i2c_slave_isr(struct bcm_iproc_i2c_dev *iproc_i2c, iproc_i2c_wr_reg(iproc_i2c, S_TX_OFFSET, value); val = BIT(S_CMD_START_BUSY_SHIFT); + if (iproc_i2c->en_s_pec) + val |= BIT(S_CMD_PEC_SHIFT); iproc_i2c_wr_reg(iproc_i2c, S_CMD_OFFSET, val); } @@ -1065,6 +1102,11 @@ static int bcm_iproc_i2c_reg_slave(struct i2c_client *slave) if (slave->flags & I2C_CLIENT_TEN) return -EAFNOSUPPORT; + /* Enable partial slave HW PEC support if requested by the client */ + iproc_i2c->en_s_pec = !!(slave->flags & I2C_CLIENT_PEC); + if (iproc_i2c->en_s_pec) + dev_info(iproc_i2c->device, "Enable PEC\n"); + iproc_i2c->slave = slave; bcm_iproc_i2c_slave_init(iproc_i2c, false); return 0;