From patchwork Tue Mar 30 14:10:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quan Nguyen X-Patchwork-Id: 411867 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=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, 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=unavailable 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 559B0C433E0 for ; Tue, 30 Mar 2021 14:11:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 319D7619CB for ; Tue, 30 Mar 2021 14:11:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231812AbhC3OLJ (ORCPT ); Tue, 30 Mar 2021 10:11:09 -0400 Received: from mail-dm6nam12on2133.outbound.protection.outlook.com ([40.107.243.133]:61537 "EHLO NAM12-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S230243AbhC3OLD (ORCPT ); Tue, 30 Mar 2021 10:11:03 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HYT4U+S5AB+znlKPZrDJ7LJgZRKqAecWenwgnO6z4e7h11nR9eksYr+snKW50YTnxmkbW2AOLAqq50tLZAvxwU6e//fhyv1ZnwZk4Oira/BL6DrzvDGj4wkch5fFNGgdgBRYtgBTH8UCCVoD4bIedMhDywtTZupxlMC6FmG1SsI1gjfLVW8L7y/jjNmAca9vAvADw8W1nUln2CU/pBJPXuFv5yrotMHRfM7aDnGxMaRsWBxN0Z3wttz6jrPMKF/sWDzN+FU/iIkkT9ugL5PatIh7RNZBBhZtd7Nw6YgrrDbCFLxl2k3zeDNdgTs9Re8wAFAthHSnkCMoq1KvtZ8d8A== 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=ObTdeZ8zsjlufq5/WNaeZ0cI2o4TsSWrRB99EetYum4=; b=VCJ45QZ0aULI8qYvE1ia+CUPu2lUH0iCmW4JQBXd4nFSEwBZc3dRtnf9IWj+gDC4P39lICmvOgPuGwvTCmgDP/2QfM0VTgI/fw1jGtknIZHKPdXb5FLlZrLph73tBZqLFtmmOq9O3euUqlKd9iwo34Uw86NsgGSlcFa9+pX5M0XVTFth3tmjaaa0SXNDyJUmXyZyT/oUlOFMepxEqlbOLd7IEFx6fKaZtA5ihq1wnBKsjOMJYl2ZpjcJZO+JerExA+8VU780z/BAiC0eDdIJBoy/E58zWJCLAe3MkQMW9J0WNlKDRINcQ27Y9ZniNBkGwzr8iTibGJd6H055pesdXw== 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=ObTdeZ8zsjlufq5/WNaeZ0cI2o4TsSWrRB99EetYum4=; b=Xp4E2zia66KuqUhiWJTWj5inSM3+AubRLqrbVDWcYiBkQ03WKQ/iaXupUC0appSoPfCXXYun0Untz3eTPDLPvpSB7UMCqPnfJ7/r1vGnp+rvfrFpWbGX7RCSgXbYIXDqFhHyHXz8gV5uQkGzOXb9mXYC5AoBZmDjes8/vCjAyrc= 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 MW4PR01MB6338.prod.exchangelabs.com (2603:10b6:303:7b::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.30; Tue, 30 Mar 2021 14:10:54 +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.3977.033; Tue, 30 Mar 2021 14:10:54 +0000 From: Quan Nguyen To: Corey Minyard , Rob Herring , Joel Stanley , Andrew Jeffery , 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: openbmc@lists.ozlabs.org, Open Source Submission , Phong Vo , "Thang Q . Nguyen" Subject: [PATCH v2 1/3] i2c: i2c-core-smbus: Expose PEC calculate function for generic use Date: Tue, 30 Mar 2021 21:10:27 +0700 Message-Id: <20210330141029.20412-2-quan@os.amperecomputing.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20210330141029.20412-1-quan@os.amperecomputing.com> References: <20210330141029.20412-1-quan@os.amperecomputing.com> X-Originating-IP: [118.69.219.201] X-ClientProxiedBy: HK0PR03CA0120.apcprd03.prod.outlook.com (2603:1096:203:b0::36) 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 HK0PR03CA0120.apcprd03.prod.outlook.com (2603:1096:203:b0::36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.29 via Frontend Transport; Tue, 30 Mar 2021 14:10:50 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0915a22f-cb1c-4fc6-b4cf-08d8f385a1c7 X-MS-TrafficTypeDiagnostic: MW4PR01MB6338: 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: ibtCF2jG/bRJ/vMV+HgnOaljgF2gjiXfDRxM1lb0rnTxGqEWVlkRCtJUMjXf+VxUiIuPtU5qKKebeLcsu3B7ZCDGSR3EYXOOLwQzopBlNoE7YeP3F2ZgJ63dciKse++HjjsJr0UDYiSgAgG6ag5Kze95dMB/APadYwrBmu3k9M2fRgg+9a9NTQArDvplfaUnnLkfaMinBbDrNie9fgEG2bCfWGOogYbf3bxx+uhObsTzlBVSyh4hh0ckbjp59V0NI7ZC42GMea4oWCPYfo5fqkYYH9tG3EuhSOdrJgJbrfiro1HxZTC7TYtpq+ed41S1ffH4skya7TAoczm7XQ82LkN2Zw9Ja7pAJxk8+NnQUzVdz2o3RzX87c2zYZOrwsr2nMZ4Nsn8EiPqydsljl2/YWyqtEDCNwEb/juhgv4fxg0x+r+la7EEnZD+oUj0NY+V/X7ZmiKFtiTfBIdHj4tsWD0nQUdfuCH5sLXYteL7DejwTKVOC6PjOy1AXs7DZw62KQTidDDGpOAqmZne6xuHirUia9FMSyIEPt6K26jZy5tthoW3yVvCKle/GJBAO0Kvn93sCzZwgTE2d5kYGoennoye/V/+qCoKRFwAx/yLRbpSD9lvbf9/R5iKSQDDIZYhyhMWaQ1k91LHbIYp05a5l+mgMWj4/vY6NmBbpdpzPt+TnawKcIYrqeA0y1BlqjDmuI4+8iWWmLoFGzLDS6uUww== 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)(366004)(2616005)(5660300002)(2906002)(956004)(186003)(16526019)(6512007)(66556008)(66476007)(6666004)(921005)(107886003)(52116002)(8676002)(7416002)(8936002)(86362001)(38100700001)(66946007)(110136005)(6506007)(83380400001)(498600001)(6486002)(4326008)(1076003)(26005)(54906003)(41533002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: CBHYV2yQ0q92bfTkMZg8G7STuaJM1Ob5oWxTRvT/+C20yDdxtfx6HKr3p6tLH+5Oa6VnMYdMdmV+W+JImj4LGXgU+7Bg69O+GslEeiPqqe/Kb8SBUbnS3RpzbtvElmsDdwmNUP8ONFbA7rmtow6wESC/MKrouR3ODMzj98nlc27dAMoVCj/MCfSg37aere70tOltfgh1mGGZhNBangZNTuXoD4z0GV0xT73O7qf191OgjUPbOLaQcN3KNDNCH4oNBQ5/eqjNdBlnyfgMp4/e/3rM6rxiNYfLYPfAoZ3qk0F2E9i1cTVEKC+rKuzJsodepGAfXjxhQK0Mv+Yh/Sl2QiLWeJbAdCPAaQ/zS9rvvm2wqYLizbNtyfF9hRQlpz8iRRRUFyo+xgQ9j2JZecrkiviG0jj1G+rSRZ2iWMz85R2bfFCpMPSF81zjKXndQ9GTlPQmprZBjC7SRYVXkW/WBlTqUeuJ5xNAFSxxIP2dhHE7eTDnBf1Tjr5wSxZX/0a0eidJE2UQmQXdUTZaNfPKYNeRLuK92QuVqMXLmh95O1wnLXZAysEIcmAua8h7YQtZBDTYMdzF/KIv2fn/IUDOhMw+jEPUHymEAFNt4iAlNVOlxaWxDNHUYCJX6bejZzggs5dhmNhk6I81f4eKrgleqRWpgaZxZ4nVw2/gSGI4Plj/GJM0hJzHCgjKZvVTuYgOrLHKZ0lHotI9xM/wDH8v+YpFhukjCNBIWMfT3h9dQPCfyiewee0EX1DkgCuemzTyk0BLgu/j7QjX5NHek8tjXzOYKPlVwnjiUGXSbFbU/pfq+Oi5BMxm/ulSIpTM0NCH8FPHW7GoA8j2sy1pIgSFZrso3pcL2JB2bWZkPxGxNZncuoKxDilSxwhTFxRCKctmxNhv2QAhMTuIy0f0phLsTloSYzAgTow0X3vJEd/NOUlfm+SRSAUDZTgTEWpsftxavV5pmfU0nA4Hv7OFZABMzW6m1NPLjO+TrXVXPf59jKi7pUNnc2RikNoVREaqZHAGgwfd4R0Hwepuo7ECdtdSDCWO8A40IRQSahXLIIkFWYxrzUINdid6qg3QZXCdL+CS4ZTGLssAN5y5VvX9RgdZPNL5Jcw4jRYyFJSVpDtgZKXcI3b8tLNj/5Gok92Vp4/kRtDI0j2xZn2oh2Bc95v85cSBoQf6a2RxSzsoMsbkQIajoN2T+s4SrYktxS7JZoLXI+evMN0WLLLBjkI/Xf0hJZIcq/XO1ELWO8cFv4OVUHj8eDlyRqDDgOdVI1CXiefH1t3vvoy349tMFEGiQnjhDTFGdVHkhYdOqvcZPPFqZNkQlzuyvi6ECELkm9DRkiJA X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0915a22f-cb1c-4fc6-b4cf-08d8f385a1c7 X-MS-Exchange-CrossTenant-AuthSource: MW2PR0102MB3482.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Mar 2021 14:10:54.7752 (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: VTiLY/qwMIT9qKH9qr1dkXfld33hyHg/9hK7w5koBwss2FybuIkd24Ib2GOa9pRq2cyC9UNB893r3HJHYktgr2XPwgEfntBP6VllJlx7aMo= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR01MB6338 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.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 56622658b215..0d75e5bcdde6 100644 --- a/include/linux/i2c.h +++ b/include/linux/i2c.h @@ -144,6 +144,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);