From: Guenter Roeck <linux@roeck-us.net>
To: Alexandru Gagniuc <mr.nuke.me@gmail.com>
Cc: linux-hwmon@vger.kernel.org, robert.marko@sartura.hr,
luka.perkov@sartura.hr, jdelvare@suse.com, dev@aboehler.at,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/3] hwmon: (tps23861) reduce count of i2c transactions for port_status
Date: Mon, 5 Sep 2022 15:29:28 -0700 [thread overview]
Message-ID: <20220905222928.GA3695028@roeck-us.net> (raw)
In-Reply-To: <20220905142806.110598-2-mr.nuke.me@gmail.com>
On Mon, Sep 05, 2022 at 09:28:05AM -0500, Alexandru Gagniuc wrote:
> When reading the 'port_status' debugfs entry, some I2C registers were
> read more than once. This looks inefficient in an I2C trace.
>
> To reduce I2C traffic, update tps23861_port_status_show() to only read
> each register once. Indexing the port number from 0 instead of 1 also
> allows simplifying things a bit, resulting in a negative line count.
"resulting in a negative line count"
That took me a while to understand. Please rephrase or drop.
>
> Signed-off-by: Alexandru Gagniuc <mr.nuke.me@gmail.com>
> ---
> drivers/hwmon/tps23861.c | 75 ++++++++++++----------------------------
> 1 file changed, 22 insertions(+), 53 deletions(-)
>
> diff --git a/drivers/hwmon/tps23861.c b/drivers/hwmon/tps23861.c
> index f7c59ff7ae8e..0dbd12060b50 100644
> --- a/drivers/hwmon/tps23861.c
> +++ b/drivers/hwmon/tps23861.c
> @@ -372,29 +372,12 @@ static const struct hwmon_chip_info tps23861_chip_info = {
> .info = tps23861_info,
> };
>
> -static char *tps23861_port_operating_mode(struct tps23861_data *data, int port)
> +static char *port_operating_mode_string(uint8_t mode_reg, unsigned int port)
> {
> - unsigned int regval;
> - int mode;
> -
> - regmap_read(data->regmap, OPERATING_MODE, ®val);
> + unsigned int mode = ~0;
>
> - switch (port) {
> - case 1:
> - mode = FIELD_GET(OPERATING_MODE_PORT_1_MASK, regval);
> - break;
> - case 2:
> - mode = FIELD_GET(OPERATING_MODE_PORT_2_MASK, regval);
> - break;
> - case 3:
> - mode = FIELD_GET(OPERATING_MODE_PORT_3_MASK, regval);
> - break;
> - case 4:
> - mode = FIELD_GET(OPERATING_MODE_PORT_4_MASK, regval);
> - break;
> - default:
> - mode = -EINVAL;
> - }
> + if (port < TPS23861_NUM_PORTS)
> + mode = (mode_reg >> (2 * port)) & OPERATING_MODE_PORT_1_MASK;
>
> switch (mode) {
> case OPERATING_MODE_OFF:
> @@ -410,15 +393,9 @@ static char *tps23861_port_operating_mode(struct tps23861_data *data, int port)
> }
> }
>
> -static char *tps23861_port_detect_status(struct tps23861_data *data, int port)
> +static char *port_detect_status_string(uint8_t status_reg)
> {
> - unsigned int regval;
> -
> - regmap_read(data->regmap,
> - PORT_1_STATUS + (port - 1),
> - ®val);
> -
> - switch (FIELD_GET(PORT_STATUS_DETECT_MASK, regval)) {
> + switch (FIELD_GET(PORT_STATUS_DETECT_MASK, status_reg)) {
> case PORT_DETECT_UNKNOWN:
> return "Unknown device";
> case PORT_DETECT_SHORT:
> @@ -448,15 +425,9 @@ static char *tps23861_port_detect_status(struct tps23861_data *data, int port)
> }
> }
>
> -static char *tps23861_port_class_status(struct tps23861_data *data, int port)
> +static char *port_class_status_string(uint8_t status_reg)
> {
> - unsigned int regval;
> -
> - regmap_read(data->regmap,
> - PORT_1_STATUS + (port - 1),
> - ®val);
> -
> - switch (FIELD_GET(PORT_STATUS_CLASS_MASK, regval)) {
> + switch (FIELD_GET(PORT_STATUS_CLASS_MASK, status_reg)) {
> case PORT_CLASS_UNKNOWN:
> return "Unknown";
> case PORT_CLASS_RESERVED:
> @@ -479,16 +450,9 @@ static char *tps23861_port_class_status(struct tps23861_data *data, int port)
> }
> }
>
> -static char *tps23861_port_poe_plus_status(struct tps23861_data *data, int port)
> +static char *port_poe_plus_status_string(uint8_t poe_plus, unsigned int port)
> {
> - unsigned int regval;
> -
> - regmap_read(data->regmap, POE_PLUS, ®val);
> -
> - if (BIT(port + 3) & regval)
> - return "Yes";
> - else
> - return "No";
> + return (BIT(port + 4) & poe_plus) ? "Yes" : "No";
> }
>
> static int tps23861_port_resistance(struct tps23861_data *data, int port)
> @@ -497,7 +461,7 @@ static int tps23861_port_resistance(struct tps23861_data *data, int port)
> __le16 regval;
>
> regmap_bulk_read(data->regmap,
> - PORT_1_RESISTANCE_LSB + PORT_N_RESISTANCE_LSB_OFFSET * (port - 1),
> + PORT_1_RESISTANCE_LSB + PORT_N_RESISTANCE_LSB_OFFSET * port,
> ®val,
> 2);
>
> @@ -517,14 +481,19 @@ static int tps23861_port_resistance(struct tps23861_data *data, int port)
> static int tps23861_port_status_show(struct seq_file *s, void *data)
> {
> struct tps23861_data *priv = s->private;
> - int i;
> + unsigned int i, mode, poe_plus, status;
> +
> + regmap_read(priv->regmap, OPERATING_MODE, &mode);
> + regmap_read(priv->regmap, POE_PLUS, &poe_plus);
> +
> + for (i = 0; i < TPS23861_NUM_PORTS; i++) {
> + regmap_read(priv->regmap, PORT_1_STATUS + i, &status);
>
> - for (i = 1; i < TPS23861_NUM_PORTS + 1; i++) {
> seq_printf(s, "Port: \t\t%d\n", i);
This changes the port number output from 1..4 to 0..3.
Why ? I can understand the code change, but that doesn't mean
the output has to change as well.
Thanks,
Guenter
> - seq_printf(s, "Operating mode: %s\n", tps23861_port_operating_mode(priv, i));
> - seq_printf(s, "Detected: \t%s\n", tps23861_port_detect_status(priv, i));
> - seq_printf(s, "Class: \t\t%s\n", tps23861_port_class_status(priv, i));
> - seq_printf(s, "PoE Plus: \t%s\n", tps23861_port_poe_plus_status(priv, i));
> + seq_printf(s, "Operating mode: %s\n", port_operating_mode_string(mode, i));
> + seq_printf(s, "Detected: \t%s\n", port_detect_status_string(status));
> + seq_printf(s, "Class: \t\t%s\n", port_class_status_string(status));
> + seq_printf(s, "PoE Plus: \t%s\n", port_poe_plus_status_string(poe_plus, i));
> seq_printf(s, "Resistance: \t%d\n", tps23861_port_resistance(priv, i));
> seq_putc(s, '\n');
> }
next prev parent reply other threads:[~2022-09-05 22:29 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-05 14:28 [PATCH 1/3] hwmon: (tps23861) fix byte order in resistance register Alexandru Gagniuc
2022-09-05 14:28 ` [PATCH 2/3] hwmon: (tps23861) reduce count of i2c transactions for port_status Alexandru Gagniuc
2022-09-05 22:29 ` Guenter Roeck [this message]
2022-09-05 14:28 ` [PATCH 3/3] hwmon: (tps23861) create unique debugfs directory per device Alexandru Gagniuc
2022-09-05 22:30 ` Guenter Roeck
2022-09-05 22:10 ` [PATCH 1/3] hwmon: (tps23861) fix byte order in resistance register Guenter Roeck
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=20220905222928.GA3695028@roeck-us.net \
--to=linux@roeck-us.net \
--cc=dev@aboehler.at \
--cc=jdelvare@suse.com \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luka.perkov@sartura.hr \
--cc=mr.nuke.me@gmail.com \
--cc=robert.marko@sartura.hr \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox