Thread (67 messages) 67 messages, 5 authors, 2024-10-18

Re: [PATCH net-next 04/12] net: pse-pd: tps23881: Add support for power limit and measurement features

flat view

From: Kory Maincent <kory.maincent@bootlin.com>
Date: 2024-10-09 09:05:05
Also in: linux-doc, lkml

On Wed, 9 Oct 2024 07:02:38 +0200
Oleksij Rempel [off-list ref] wrote:
On Wed, Oct 02, 2024 at 06:28:00PM +0200, Kory Maincent wrote:
quoted
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>  
quoted
+static int tps23881_pi_get_class(struct tps23881_priv *priv, int id)
+{  
....
quoted
+	if (chan < 4)
+		class = ret >> 4;
+	else
+		class = ret >> 12;  
....
quoted
+tps23881_pi_set_2p_pw_limit(struct tps23881_priv *priv, u8 chan, u8 pol)
+{  
....
quoted
+	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?

Regards,
-- 
Köry Maincent, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help