From patchwork Wed May 19 07:49:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quan Nguyen X-Patchwork-Id: 12266575 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D32F9C433ED for ; Wed, 19 May 2021 07:52:16 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 5B40361244 for ; Wed, 19 May 2021 07:52:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5B40361244 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=os.amperecomputing.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=S0Gyasq2tqIMvDETpttosj7pW46lpQWXGho0vUVe+u0=; b=mSquBKiMLFxCFPnIJ8X1vhHcC JvvtRHf1xYAittrgmjaLqJIezwhXVNOyZEq7OKyV+oa4fUhRZnwcApcuLalB97maX2mWq3ftghI3L dGzauw7O9mSMiIyeonIm8iktcnxGAt8IFMYZvaY7QkzZZOuFTrMoUOB3Em5H7f9z7ubdaOWiu5G2p ypgqbJYZ06+PWpB8fnwu66na5hAmi2Jy0qMiXqUsuu3itqgZugmRHF8jDGDNODu9eTFyEXfT1bz5v L3VblHsTbB5MP1u6g9MvBVMWqXUb6EeUtrtyeIC9NPQeQMfUI/Ns82e3xEhWWcxWHWUdlSdYcp2CW 2UCn29nXQ==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1ljGyY-003EJV-Tq; Wed, 19 May 2021 07:50:43 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1ljGyK-003EFX-Ul for linux-arm-kernel@desiato.infradead.org; Wed, 19 May 2021 07:50:29 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=MIME-Version:Content-Type: Content-Transfer-Encoding:References:In-Reply-To:Message-Id:Date:Subject:Cc: To:From:Sender:Reply-To:Content-ID:Content-Description; bh=ZPvJYCQ34HkZHonaIejkvrkgzZ75z1OPkw/fSHEanIc=; b=WNSxRbTgbFFGy8foiWPFXqKWqV Y2dtn4oMVJKKPWsK0MRyKpummRvqWyTv1uxUw5TrWfeeh0gfwwSFdIH+q0Hr47B+4UeKSFlxj5kuo DLlh5pgJFDy4WnJ1rPBg66efkFxwl6KMRmQKy5R1BNbgKQJWfGUubILlTXsjWTrlR81RaYTkmFhoj 8DyudK+7cq3XfIKNZC2dRdpTHMX+y9vap7pSUS2KDZB/4PMUIB/ZLxxHaVFqV/JENJY3oCvypwewg U9wF5RJDgDg4YZKnud0my2kzEjiFcsP2/42U5bfxpOUYsthNGgxajbIW8zpuXUaN52FmOR5m50ZQa GfCn/Q1g==; Received: from mail-dm6nam10on2124.outbound.protection.outlook.com ([40.107.93.124] helo=NAM10-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1ljGyI-00FEbU-EY for linux-arm-kernel@lists.infradead.org; Wed, 19 May 2021 07:50:27 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=d0J8gUImQqdj84aKv32CUgxa0dRV6Mrzd/s1hOlxERbRrIlnUAxMidYcP5KUyW4S+/xJWPs+1sd4J5ckcfz5c7/aOX8pgU9dWvz8tLqtnORRhmozXCCnu9qg8OGMNUjHjrUfzjFfA7c0KYfL3om2tTGWXXg3ui4WO/eO8hJozH3BGfIgpnlsZjKTp3Cz77yzcbWrg3b3TuaXWqFmiH0jpnDzl0K119A584aMwuja4cWGFgzwe1xT/2yHq0ITYtHWEuPr2RhojRYkDIwQ1Dofc6YYXjixW73d5rAliWTnI135rOx4JleF00BLT/M9oASnP57wrE698aXfViXu7xiVOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ZPvJYCQ34HkZHonaIejkvrkgzZ75z1OPkw/fSHEanIc=; b=duxFUUF2Yi8KpoNRCItpj/c548s+jnmOvXzgNHbU8FnnA9TWTiyRoBd3BFWbpnYOU33X0NR1BQrS7hA8yeClmzhTqHIVUCC4MNPBT4yN+NV5TyhIWC9qbBybRaSzLBM90ZVldkzUZg6c7E93O0jZC0zCmLEduAyEVac+WAjF6J4zpuYnqeeMdij/HkY9s2RPLkjPJ4/iEINnHPC0mw0H0LbuKRZl0vBFkbThPMmEbFowkpoAdWry4YM4IR/aGpgT0H+dagqJcTYRah48Og8+9t1h5HpGsM7ptkrjdFnPQIGz+Jg9di1csHcAMqd7gdwaoaSxmHsbstUao6uMT2okwQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=os.amperecomputing.com; dmarc=pass action=none header.from=os.amperecomputing.com; dkim=pass header.d=os.amperecomputing.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=os.amperecomputing.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ZPvJYCQ34HkZHonaIejkvrkgzZ75z1OPkw/fSHEanIc=; b=qUGj5Hg0p8/tKW5K5HSOrk4Of0W9wYsQk2c3v700OiUNspcqv9L+7w4Gse8B+rNVbCYcU7Pta5AiVjNO/upwK91mmEXxmC5YsuqUqS8KmurjzAi/XjmI2k9BHWZ801rCsi+EAD7cAJ/T0kq0buXiVtN4dz4sSB/tBfYbze17kEQ= Authentication-Results: acm.org; dkim=none (message not signed) header.d=none;acm.org; dmarc=none action=none header.from=os.amperecomputing.com; Received: from MW2PR0102MB3482.prod.exchangelabs.com (2603:10b6:302:c::32) by MW2PR0102MB3451.prod.exchangelabs.com (2603:10b6:302:10::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4129.28; Wed, 19 May 2021 07:50:21 +0000 Received: from MW2PR0102MB3482.prod.exchangelabs.com ([fe80::d840:7aa7:58d4:b503]) by MW2PR0102MB3482.prod.exchangelabs.com ([fe80::d840:7aa7:58d4:b503%5]) with mapi id 15.20.4129.032; Wed, 19 May 2021 07:50:20 +0000 From: Quan Nguyen To: Corey Minyard , Rob Herring , Joel Stanley , Andrew Jeffery , Brendan Higgins , Benjamin Herrenschmidt , Wolfram Sang , Philipp Zabel , openipmi-developer@lists.sourceforge.net, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-aspeed@lists.ozlabs.org, linux-kernel@vger.kernel.org, linux-i2c@vger.kernel.org Cc: Open Source Submission , Phong Vo , "Thang Q . Nguyen" , openbmc@lists.ozlabs.org Subject: [PATCH v3 1/7] i2c: i2c-core-smbus: Expose PEC calculate function for generic use Date: Wed, 19 May 2021 14:49:28 +0700 Message-Id: <20210519074934.20712-2-quan@os.amperecomputing.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20210519074934.20712-1-quan@os.amperecomputing.com> References: <20210519074934.20712-1-quan@os.amperecomputing.com> X-Originating-IP: [118.69.219.201] X-ClientProxiedBy: HK2PR04CA0081.apcprd04.prod.outlook.com (2603:1096:202:15::25) To MW2PR0102MB3482.prod.exchangelabs.com (2603:10b6:302:c::32) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from hcm-sw-17.amperecomputing.com (118.69.219.201) by HK2PR04CA0081.apcprd04.prod.outlook.com (2603:1096:202:15::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4129.25 via Frontend Transport; Wed, 19 May 2021 07:50:15 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a869516a-260f-4ffe-5fd7-08d91a9abfad X-MS-TrafficTypeDiagnostic: MW2PR0102MB3451: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3968; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: cKJYc003RUYINxsr/3eLWSnIItakq5k34BDw5Px7GOcuMdOV83TumNEFwQpGa0TcK7UjWrlDSBxp3GoVrpqtjN6yqt4SjFL9+D+04eunZYNWuJ6F3pZAYL0f9lKRZVMA4i2gAQfA89yiOJkIExCIstw7BwCLm9KpyZDF/a4RlS70X4bqF4S7QKFqmqbxj0pv+0zgQf0cQLTq50fEQXUW8Y/e528YAnFGsn7Nu3d4BLkZyiX15x8kBrsIfZWl13bcVR25qQ8VxS9Qd3k0n+4FC3uEWafvzrCqGob6qrug1TEH7aTp+GVK3O5Nuo/oxlVpV7191UtFj0JTBPoAXrVefL0IwJNMvbsTieV+5LeQUY+z6GuMFuSt78FRurPYZzAXhYJDdzClmOoYyJZWA4r88U4b74Ja/+ODsrFVvlj+hOPFljDEzT+IE4mbc3tCHaA2oMs9Ib2XM9QCkv5r8jTAyA6hMyoSyBzOTaZND9cjPKmEBWZwAYzYh8WgCJepfXdT8vAla//1g7KYYTlqKlfdHNJ+F3HyG5TISIuujHAtvMMIPxLhdIDphVpWhD8L3nEbo42MkPyPrJMqkNtiwFLX3+oavJUGJkVnaBzznMm1rCQrr+tyV+o1FugCUff1f6y43QeYsG4+QjuUzFOUnuqD8Ar6MzS4P723NiV0HDlbbDDZwvG+u7tiz/8FskmIAGbM X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MW2PR0102MB3482.prod.exchangelabs.com; PTR:; CAT:NONE; SFS:(4636009)(136003)(39850400004)(376002)(366004)(396003)(346002)(83380400001)(7416002)(8676002)(2906002)(921005)(6512007)(478600001)(38100700002)(8936002)(186003)(16526019)(38350700002)(52116002)(5660300002)(956004)(2616005)(4326008)(110136005)(54906003)(316002)(66556008)(66476007)(66946007)(6486002)(6506007)(1076003)(26005)(86362001)(6666004)(41533002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: augMxzP4NYET6V3Ie45SWy6VlDTdMfbw+bxBL96SVfQsH95A0cx6Mu9Rurv9mqAKT8aYXgDrV3oxnQlxC6RhpAhVzFXLdsQ2C6HedT7OrEsh9PLZKE71nTupJs8GOQ4kPGP+jBSdSHT5benVa8AeaS/L9xOatui8bL2UyVAf9F2nn15sdb1ixucF8qEmZyCEmgp4QoZoRUjnUVL8Z25/2Q2PiovpEpVWNCQcfiHEwRpBEEssOtfntheMtwyiv+RCu2D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UucT X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: a869516a-260f-4ffe-5fd7-08d91a9abfad X-MS-Exchange-CrossTenant-AuthSource: MW2PR0102MB3482.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2021 07:50:19.7459 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3bc2b170-fd94-476d-b0ce-4229bdc904a7 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 9U89xkakyr5UHQH42/ugrphwgHFWOSkgvU2gmSvHw//47xWwx1ZucJ0jW7FXsUVlC5srfrx7Hra1Zf+linnmBIEO9DeXtTk3bbr6F+pYBdI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW2PR0102MB3451 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210519_005026_512889_04BA0D83 X-CRM114-Status: GOOD ( 12.54 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Expose the PEC calculation i2c_smbus_pec() for generic use. Signed-off-by: Quan Nguyen --- drivers/i2c/i2c-core-smbus.c | 12 ++++++++++-- include/linux/i2c.h | 1 + 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/i2c/i2c-core-smbus.c b/drivers/i2c/i2c-core-smbus.c index d2d32c0fd8c3..e5b2d1465e7e 100644 --- a/drivers/i2c/i2c-core-smbus.c +++ b/drivers/i2c/i2c-core-smbus.c @@ -37,8 +37,15 @@ static u8 crc8(u16 data) return (u8)(data >> 8); } -/* Incremental CRC8 over count bytes in the array pointed to by p */ -static u8 i2c_smbus_pec(u8 crc, u8 *p, size_t count) +/** + * i2c_smbus_pec - Incremental CRC8 over the given input data array + * @crc: previous return crc8 value + * @p: pointer to data buffer. + * @count: number of bytes in data buffer. + * + * Incremental CRC8 over count bytes in the array pointed to by p + */ +u8 i2c_smbus_pec(u8 crc, u8 *p, size_t count) { int i; @@ -46,6 +53,7 @@ static u8 i2c_smbus_pec(u8 crc, u8 *p, size_t count) crc = crc8((crc ^ p[i]) << 8); return crc; } +EXPORT_SYMBOL(i2c_smbus_pec); /* Assume a 7-bit address, which is reasonable for SMBus */ static u8 i2c_smbus_msg_pec(u8 pec, struct i2c_msg *msg) diff --git a/include/linux/i2c.h b/include/linux/i2c.h index e8f2ac8c9c3d..2494a007dfda 100644 --- a/include/linux/i2c.h +++ b/include/linux/i2c.h @@ -147,6 +147,7 @@ s32 __i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr, /* Now follow the 'nice' access routines. These also document the calling conventions of i2c_smbus_xfer. */ +u8 i2c_smbus_pec(u8 crc, u8 *p, size_t count); s32 i2c_smbus_read_byte(const struct i2c_client *client); s32 i2c_smbus_write_byte(const struct i2c_client *client, u8 value); s32 i2c_smbus_read_byte_data(const struct i2c_client *client, u8 command);