From: Oleksij Rempel <o.rempel@pengutronix.de>
To: Kory Maincent <kory.maincent@bootlin.com>
Cc: "David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Jonathan Corbet <corbet@lwn.net>,
Donald Hunter <donald.hunter@gmail.com>,
Thomas Petazzoni <thomas.petazzoni@bootlin.com>,
linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
linux-doc@vger.kernel.org, Kyle Swenson <kyle.swenson@est.tech>,
Dent Project <dentproject@linuxfoundation.org>,
kernel@pengutronix.de
Subject: Re: [PATCH net-next 04/12] net: pse-pd: tps23881: Add support for power limit and measurement features
Date: Wed, 9 Oct 2024 17:16:20 +0200 [thread overview]
Message-ID: <ZwaeRL9z310dBBlh@pengutronix.de> (raw)
In-Reply-To: <20241009110501.5f776c9b@kmaincent-XPS-13-7390>
On Wed, Oct 09, 2024 at 11:05:01AM +0200, Kory Maincent wrote:
> On Wed, 9 Oct 2024 07:02:38 +0200
> Oleksij Rempel <o.rempel@pengutronix.de> wrote:
>
> > On Wed, Oct 02, 2024 at 06:28:00PM +0200, Kory Maincent wrote:
> > > From: Kory Maincent (Dent Project) <kory.maincent@bootlin.com>
> > >
> > > Expand PSE callbacks to support the newly introduced
> > > pi_get/set_current_limit() and pi_get_voltage() functions. These callbacks
> > > allow for power limit configuration in the TPS23881 controller.
> > >
> > > Additionally, the patch includes the detected class, the current power
> > > delivered and the power limit ranges in the status returned, providing more
> > > comprehensive PoE status reporting.
> > >
> > > Signed-off-by: Kory Maincent <kory.maincent@bootlin.com>
> >
> > > +static int tps23881_pi_get_class(struct tps23881_priv *priv, int id)
> > > +{
> > ....
> > > + if (chan < 4)
> > > + class = ret >> 4;
> > > + else
> > > + class = ret >> 12;
> >
> > ....
> > > +tps23881_pi_set_2p_pw_limit(struct tps23881_priv *priv, u8 chan, u8 pol)
> > > +{
> > ....
> > > + reg = TPS23881_REG_2PAIR_POL1 + (chan % 4);
> > > + ret = i2c_smbus_read_word_data(client, reg);
> > > + if (ret < 0)
> > > + return ret;
> > > +
> > > + if (chan < 4)
> > > + val = (ret & 0xff00) | pol;
> > > + else
> > > + val = (ret & 0xff) | (pol << 8);
> >
> > This is a common pattern in this driver, we read and write two registers
> > in one run and then calculate bit offset for the channel, can you please
> > move it in to separate function. This can be done in a separate patch if
> > you like.
>
> The pattern is common but the operations are always different so I didn't found
> a clean way of doing it.
> Here is a listing of it:
> if (chan < 4)
> class = ret >> 4;
> else
> class = ret >> 12;
>
> if (chan < 4)
> val = (ret & 0xff00) | pol;
> else
> val = (ret & 0xff) | (pol << 8);
>
> if (chan < 4)
> val = (u16)(ret | BIT(chan));
> else
> val = (u16)(ret | BIT(chan + 4));
>
> if (chan < 4)
> mW = (ret & 0xff) * TPS23881_MW_STEP;
> else
> mW = (ret >> 8) * TPS23881_MW_STEP;
>
>
> Any idea?
>
something like this:
/*
* Helper to extract a value from a u16 register value, which is made of two u8 registers.
* The function calculates the bit offset based on the channel and extracts the relevant
* bits using a provided field mask.
*
* @param reg_val: The u16 register value (composed of two u8 registers).
* @param chan: The channel number (0-7).
* @param field_offset: The base bit offset to apply (e.g., 0 or 4).
* @param field_mask: The mask to apply to extract the required bits.
* @return: The extracted value for the specific channel.
*/
static u16 tps23881_calc_val(u16 reg_val, u8 chan, u8 field_offset, u16 field_mask)
{
u8 bit_offset;
if (chan < 4) {
bit_offset = field_offset;
} else {
bit_offset = field_offset;
reg_val >>= 8;
}
return (reg_val >> bit_offset) & field_mask;
}
/*
* Helper to combine individual channel values into a u16 register value.
* The function sets the value for a specific channel in the appropriate position.
*
* @param reg_val: The current u16 register value.
* @param chan: The channel number (0-7).
* @param field_offset: The base bit offset to apply (e.g., 0 or 4).
* @param field_mask: The mask to apply for the field (e.g., 0x0F).
* @param field_val: The value to set for the specific channel (masked by field_mask).
* @return: The updated u16 register value with the channel value set.
*/
static u16 tps23881_set_val(u16 reg_val, u8 chan, u8 field_offset, u16 field_mask, u16 field_val)
{
u8 bit_offset;
field_val &= field_mask;
if (chan < 4) {
bit_offset = field_offset;
reg_val &= ~(field_mask << bit_offset);
reg_val |= (field_val << bit_offset);
} else {
bit_offset = field_offset;
reg_val &= ~(field_mask << (bit_offset + 8));
reg_val |= (field_val << (bit_offset + 8));
}
return reg_val;
}
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
next prev parent reply other threads:[~2024-10-09 15:16 UTC|newest]
Thread overview: 68+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-02 16:27 [PATCH net-next 00/12] Add support for PSE port priority Kory Maincent
2024-10-02 16:27 ` [PATCH net-next 01/12] net: pse-pd: Remove unused pse_ethtool_get_pw_limit function declaration Kory Maincent
2024-10-02 23:24 ` Andrew Lunn
2024-10-03 3:25 ` Kalesh Anakkur Purayil
2024-10-09 4:37 ` Oleksij Rempel
2024-10-02 16:27 ` [PATCH net-next 02/12] net: pse-pd: tps23881: Correct boolean evaluation for bitmask checks Kory Maincent
2024-10-02 16:27 ` [PATCH net-next 03/12] net: pse-pd: tps23881: Simplify function returns by removing redundant checks Kory Maincent
2024-10-02 23:26 ` Andrew Lunn
2024-10-09 4:38 ` Oleksij Rempel
2024-10-02 16:28 ` [PATCH net-next 04/12] net: pse-pd: tps23881: Add support for power limit and measurement features Kory Maincent
2024-10-02 23:31 ` Andrew Lunn
2024-10-09 5:02 ` Oleksij Rempel
2024-10-09 9:05 ` Kory Maincent
2024-10-09 15:16 ` Oleksij Rempel [this message]
2024-10-09 16:17 ` Kory Maincent
2024-10-02 16:28 ` [PATCH net-next 05/12] net: pse-pd: Add support for getting and setting port priority Kory Maincent
2024-10-02 23:34 ` Andrew Lunn
2024-10-09 5:04 ` Oleksij Rempel
2024-10-02 16:28 ` [PATCH net-next 06/12] net: ethtool: Add PSE new port priority support feature Kory Maincent
2024-10-02 23:37 ` Andrew Lunn
2024-10-05 6:26 ` Oleksij Rempel
2024-10-07 9:30 ` Kory Maincent
2024-10-07 14:10 ` Oleksij Rempel
2024-10-08 10:23 ` Kory Maincent
2024-10-08 12:56 ` Kory Maincent
2024-10-08 15:01 ` Oleksij Rempel
2024-10-08 16:31 ` Oleksij Rempel
2024-10-02 16:28 ` [PATCH net-next 07/12] netlink: specs: Expand the PSE netlink command with C33 prio attributes Kory Maincent
2024-10-04 10:44 ` Donald Hunter
2024-10-02 16:28 ` [PATCH net-next 08/12] net: pse-pd: pd692x0: Add support for PSE PI priority feature Kory Maincent
2024-10-02 23:41 ` Andrew Lunn
2024-10-03 8:01 ` Kory Maincent
2024-10-08 13:57 ` Oleksij Rempel
2024-10-08 14:21 ` Kory Maincent
2024-10-08 14:53 ` Oleksij Rempel
2024-10-08 16:50 ` Andrew Lunn
2024-10-09 7:16 ` Oleksij Rempel
2024-10-09 16:09 ` Andrew Lunn
2024-10-02 16:28 ` [PATCH net-next 09/12] net: pse-pd: tps23881: " Kory Maincent
2024-10-02 23:42 ` Andrew Lunn
2024-10-08 16:26 ` Oleksij Rempel
2024-10-02 16:28 ` [PATCH net-next 10/12] net: pse-pd: Register regulator even for undescribed PSE PIs Kory Maincent
2024-10-02 23:46 ` Andrew Lunn
2024-10-03 8:19 ` Kory Maincent
2024-10-02 16:28 ` [PATCH net-next 11/12] net: pse-pd: Add support for event reporting using devm_regulator_irq_helper Kory Maincent
2024-10-02 23:52 ` Andrew Lunn
2024-10-03 8:28 ` Kory Maincent
2024-10-03 12:56 ` Andrew Lunn
2024-10-03 13:33 ` Kory Maincent
2024-10-03 15:22 ` Andrew Lunn
2024-10-04 13:56 ` Oleksij Rempel
2024-10-04 14:02 ` Oleksij Rempel
2024-10-04 14:10 ` Kory Maincent
2024-10-03 0:02 ` Andrew Lunn
2024-10-02 16:28 ` [PATCH net-next 12/12] net: pse-pd: tps23881: Add support for PSE events and interrupts Kory Maincent
2024-10-02 23:57 ` Andrew Lunn
2024-10-03 8:29 ` Kory Maincent
2024-10-08 17:03 ` Oleksij Rempel
2024-10-09 7:25 ` Oleksij Rempel
2024-10-09 8:25 ` Kory Maincent
2024-10-09 13:54 ` [PATCH net-next 00/12] Add support for PSE port priority Kyle Swenson
2024-10-09 15:04 ` Kory Maincent
2024-10-09 17:42 ` Kyle Swenson
2024-10-10 5:42 ` Oleksij Rempel
2024-10-15 9:43 ` Kory Maincent
2024-10-17 10:35 ` Kory Maincent
2024-10-18 6:14 ` Oleksij Rempel
2024-10-18 12:37 ` Kory Maincent
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=ZwaeRL9z310dBBlh@pengutronix.de \
--to=o.rempel@pengutronix.de \
--cc=corbet@lwn.net \
--cc=davem@davemloft.net \
--cc=dentproject@linuxfoundation.org \
--cc=donald.hunter@gmail.com \
--cc=edumazet@google.com \
--cc=kernel@pengutronix.de \
--cc=kory.maincent@bootlin.com \
--cc=kuba@kernel.org \
--cc=kyle.swenson@est.tech \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=thomas.petazzoni@bootlin.com \
/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;
as well as URLs for NNTP newsgroup(s).