Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp339068pxf; Thu, 8 Apr 2021 04:21:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzjuze0lUeYUim21vn9z8QBp+d11g3ZfkFHXY8vJ1eaeKAhjfwiAH+QkAJRoicPWktbD9j4 X-Received: by 2002:a63:4423:: with SMTP id r35mr7887951pga.13.1617880860824; Thu, 08 Apr 2021 04:21:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617880860; cv=none; d=google.com; s=arc-20160816; b=0GARm5uLaY+8VgLobYJXVXmtjLTg3/klCWIZkHobzf48r1Wwxl8LXeULGYpiNGotWN vtNkSE3/KOYYi2573LsVcSn5Cfj7NxTU3/a3jRexDaMZlTn1dDRh06f6j9g6xs4tDP7P 1Y4DfR83burEq2sUkgBh3JD6AMLOBb35oyMswhZCRY+Bjm9Ko4Ukx+o6bweGBlRM6PU7 fisowayk0UmF3+bVgJAeIS1AhoktjBsoS47M1Au6XPa8IYkddYmOnzmqWkf8Sf8CEv+9 3gpIUw8ZAQ/4lrSeLaVs8aZRu+bhJbiC5nBAVPppqYqDnXwE1Zep327tTaQxZmmDL6+i hOnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=muwK7U9Zr+BlEPmAMZ6JNCz9xs4JATZHPmT2xFwX9nM=; b=l19ChZvOCmW19TKYbuIO/9VyOXD+BIZxY5lyGy3O2X0FLeJX/g+zfQuAlJ+Wl88k4j ntJr5LF2sWzIm150jzPX2FQQEG0UzQw6jv2ZqsKeAfIWf7hfeEMi9Nd0I9Q/1+NyeOT6 qQi6QRNMZN35LFt5VWH8eI5QcDNtPy/axl9FZK4R14k8NNFZIWJ3hkvvya4zIjT26Fyy VvSHPv8bnUtIEVLlDNkiUBTm5BxnvTrpD0HRZAQ1UynxLNbGksuLsJ1ap1sPG01w/DZD gwWP+jnNhyFtFaSDs4Q0+E5R8HupHEDhPY8b2kdNDRt2k44l3UmEXAO8+Qq7Lly9ulP9 bESw== ARC-Authentication-Results: i=1; mx.google.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=fail (p=NONE sp=NONE dis=NONE) header.from=hisilicon.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k13si28921451plk.217.2021.04.08.04.20.48; Thu, 08 Apr 2021 04:21:00 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=hisilicon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231295AbhDHLUS (ORCPT + 99 others); Thu, 8 Apr 2021 07:20:18 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:15187 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231152AbhDHLUQ (ORCPT ); Thu, 8 Apr 2021 07:20:16 -0400 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4FGJd73MbhzpWZr; Thu, 8 Apr 2021 19:17:15 +0800 (CST) Received: from localhost.localdomain (10.67.165.24) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.498.0; Thu, 8 Apr 2021 19:19:55 +0800 From: Yicong Yang To: , , , , CC: , , , , , , , , , Subject: [PATCH v7 2/5] i2c: core: add api to provide frequency mode strings Date: Thu, 8 Apr 2021 19:17:18 +0800 Message-ID: <1617880641-664-3-git-send-email-yangyicong@hisilicon.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1617880641-664-1-git-send-email-yangyicong@hisilicon.com> References: <1617880641-664-1-git-send-email-yangyicong@hisilicon.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.67.165.24] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Some I2C drivers like Designware and HiSilicon will print the bus frequency mode information, so add a public one that everyone can make use of. Tested-by: Jarkko Nikula Reviewed-by: Jarkko Nikula Reviewed-by: Andy Shevchenko Signed-off-by: Yicong Yang --- drivers/i2c/i2c-core-base.c | 21 +++++++++++++++++++++ include/linux/i2c.h | 3 +++ 2 files changed, 24 insertions(+) diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c index de9402c..775b8cc 100644 --- a/drivers/i2c/i2c-core-base.c +++ b/drivers/i2c/i2c-core-base.c @@ -76,6 +76,27 @@ void i2c_transfer_trace_unreg(void) static_branch_dec(&i2c_trace_msg_key); } +const char *i2c_freq_mode_string(u32 bus_freq_hz) +{ + switch (bus_freq_hz) { + case I2C_MAX_STANDARD_MODE_FREQ: + return "Standard Mode (100 kHz)"; + case I2C_MAX_FAST_MODE_FREQ: + return "Fast Mode (400 kHz)"; + case I2C_MAX_FAST_MODE_PLUS_FREQ: + return "Fast Mode Plus (1.0 MHz)"; + case I2C_MAX_TURBO_MODE_FREQ: + return "Turbo Mode (1.4 MHz)"; + case I2C_MAX_HIGH_SPEED_MODE_FREQ: + return "High Speed Mode (3.4 MHz)"; + case I2C_MAX_ULTRA_FAST_MODE_FREQ: + return "Ultra Fast Mode (5.0 MHz)"; + default: + return "Unknown Mode"; + } +} +EXPORT_SYMBOL_GPL(i2c_freq_mode_string); + const struct i2c_device_id *i2c_match_id(const struct i2c_device_id *id, const struct i2c_client *client) { diff --git a/include/linux/i2c.h b/include/linux/i2c.h index 10bd0b0..0813be1 100644 --- a/include/linux/i2c.h +++ b/include/linux/i2c.h @@ -51,6 +51,9 @@ struct module; struct property_entry; #if IS_ENABLED(CONFIG_I2C) +/* Return the Frequency mode string based on the bus frequency */ +const char *i2c_freq_mode_string(u32 bus_freq_hz); + /* * The master routines are the ones normally used to transmit data to devices * on a bus (or read from them). Apart from two basic transfer functions to -- 2.8.1