All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yicong Yang <yangyicong@hisilicon.com>
To: <wsa@kernel.org>, <andriy.shevchenko@linux.intel.com>,
	<linux-i2c@vger.kernel.org>, <Sergey.Semin@baikalelectronics.ru>,
	<linux-kernel@vger.kernel.org>
Cc: <digetx@gmail.com>, <treding@nvidia.com>,
	<jarkko.nikula@linux.intel.com>, <rmk+kernel@armlinux.org.uk>,
	<song.bao.hua@hisilicon.com>, <john.garry@huawei.com>,
	<mika.westerberg@linux.intel.com>, <yangyicong@hisilicon.com>,
	<prime.zeng@huawei.com>, <linuxarm@huawei.com>
Subject: [PATCH v7 2/5] i2c: core: add api to provide frequency mode strings
Date: Thu, 8 Apr 2021 19:17:18 +0800	[thread overview]
Message-ID: <1617880641-664-3-git-send-email-yangyicong@hisilicon.com> (raw)
In-Reply-To: <1617880641-664-1-git-send-email-yangyicong@hisilicon.com>

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 <jarkko.nikula@linux.intel.com>
Reviewed-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Yicong Yang <yangyicong@hisilicon.com>
---
 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


  parent reply	other threads:[~2021-04-08 11:20 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-08 11:17 [PATCH v7 0/5] Add support for HiSilicon I2C controller Yicong Yang
2021-04-08 11:17 ` [PATCH v7 1/5] i2c: core: add managed function for adding i2c adapters Yicong Yang
2021-04-08 11:17 ` Yicong Yang [this message]
2021-04-08 20:55   ` [PATCH v7 2/5] i2c: core: add api to provide frequency mode strings Wolfram Sang
2021-04-09 10:36     ` Andy Shevchenko
2021-04-09 11:37       ` Wolfram Sang
2021-04-09 11:40         ` Andy Shevchenko
2021-04-09 13:49           ` Yicong Yang
2021-04-08 11:17 ` [PATCH v7 3/5] i2c: add support for HiSilicon I2C controller Yicong Yang
2021-04-08 11:17 ` [PATCH v7 4/5] MAINTAINERS: Add maintainer for HiSilicon I2C driver Yicong Yang
2021-04-08 20:57   ` Wolfram Sang
2021-04-08 11:17 ` [PATCH v7 5/5] i2c: designware: Switch over to i2c_freq_mode_string() Yicong Yang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1617880641-664-3-git-send-email-yangyicong@hisilicon.com \
    --to=yangyicong@hisilicon.com \
    --cc=Sergey.Semin@baikalelectronics.ru \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=digetx@gmail.com \
    --cc=jarkko.nikula@linux.intel.com \
    --cc=john.garry@huawei.com \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxarm@huawei.com \
    --cc=mika.westerberg@linux.intel.com \
    --cc=prime.zeng@huawei.com \
    --cc=rmk+kernel@armlinux.org.uk \
    --cc=song.bao.hua@hisilicon.com \
    --cc=treding@nvidia.com \
    --cc=wsa@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.