Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp4412022pxf; Tue, 30 Mar 2021 07:14:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzc67xKe9QsHtC4+VFKKmK06S36TZOiO6xQ7zrYQIAVjVXsWBxI1YGQ6fcrY/dFA1Xb8CGd X-Received: by 2002:a17:906:354a:: with SMTP id s10mr33050046eja.21.1617113685939; Tue, 30 Mar 2021 07:14:45 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1617113685; cv=pass; d=google.com; s=arc-20160816; b=zKryDcY4UB/+YCKsmGIK3MiEdNGuxSG9HtYjnuMDjfeVQxnMspAg5eO+R23x8w3m6V xa3Qz84F9oisog4m4E+n2HSoH8yzh3l5J4nelAU3TyQoVIQxctjeiWpolFlOCeLglSVF sWertMXP8lJoQmOUHyeW3ju2IkcUkBqwP7P8n4scvnGOO6FZlp59O8sDHWB5/LNTn099 mMovirjdTLSKlDSu20UCRfCigXDy2DSHTRm0mJ71dUg6aojVDRne5B50+XaLVgsx5iI/ VjMSEbSzQvbAIu3VaFqC7AwesoSlBvh3v6siSxt2WUSFdqW4/RDhKcupwJJw9eDlDKiq 12aw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ObTdeZ8zsjlufq5/WNaeZ0cI2o4TsSWrRB99EetYum4=; b=gFkS10g7jJ3aHjmCR96dcE2fQnDQTiw0o98sk5kNMz5RNxy8bFTcJGLhj4ymI89lIZ Wa0sBanMTNDx+ajgqujdhHpfgTb0Nx3OLH5yCJiLBczmWlNKJxgqWKP72oXU2wm/qtNq 4DT+1luJKWDuongoJ8W6JE0QvWrGNhe/xqGvBVeYPhduZ+ftWA3sQzDwMeqAxgan7g5K tmLAL8E/zEOcAa8P0DkbUCwCptvEwu5BWIepsD0LdG/LyDx4UIaNQlEBM9U+Yqv02t7n kJGOul2TAoI7eQF8aKBfbgk6flzwJFyUI8mY6sY5yavBWKbtf0OTJH7Fw6Zp1NC5mdJS wtOQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@os.amperecomputing.com header.s=selector2 header.b=Xp4E2zia; arc=pass (i=1 spf=pass spfdomain=os.amperecomputing.com dkim=pass dkdomain=os.amperecomputing.com dmarc=pass fromdomain=os.amperecomputing.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amperecomputing.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n15si13791133edc.19.2021.03.30.07.14.22; Tue, 30 Mar 2021 07:14:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@os.amperecomputing.com header.s=selector2 header.b=Xp4E2zia; arc=pass (i=1 spf=pass spfdomain=os.amperecomputing.com dkim=pass dkdomain=os.amperecomputing.com dmarc=pass fromdomain=os.amperecomputing.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amperecomputing.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231942AbhC3OLL (ORCPT + 99 others); Tue, 30 Mar 2021 10:11:11 -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> Content-Transfer-Encoding: 8bit Content-Type: text/plain 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: =?us-ascii?Q?CBHYV2yQ0q92bfTkMZg8G7STuaJM1Ob5oWxTRvT/+C20yDdxtfx6HKr3p6tL?= =?us-ascii?Q?H+5Oa6VnMYdMdmV+W+JImj4LGXgU+7Bg69O+GslEeiPqqe/Kb8SBUbnS3Rpz?= =?us-ascii?Q?btvElmsDdwmNUP8ONFbA7rmtow6wESC/MKrouR3ODMzj98nlc27dAMoVCj/M?= =?us-ascii?Q?CfSg37aere70tOltfgh1mGGZhNBangZNTuXoD4z0GV0xT73O7qf191OgjUPb?= =?us-ascii?Q?OLaQcN3KNDNCH4oNBQ5/eqjNdBlnyfgMp4/e/3rM6rxiNYfLYPfAoZ3qk0F2?= =?us-ascii?Q?E9i1cTVEKC+rKuzJsodepGAfXjxhQK0Mv+Yh/Sl2QiLWeJbAdCPAaQ/zS9rv?= =?us-ascii?Q?vm2wqYLizbNtyfF9hRQlpz8iRRRUFyo+xgQ9j2JZecrkiviG0jj1G+rSRZ2i?= =?us-ascii?Q?WMz85R2bfFCpMPSF81z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YdOqvcZPPFq?= =?us-ascii?Q?ZNkQlzuyvi6ECELkm9DRkiJA?= 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: linux-kernel@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); -- 2.28.0