Re: [PATCH net-next 12/12] net: pse-pd: tps23881: Add support for PSE events and interrupts

Oleksij Rempel
2024-10-09T07:25:22Z

Hi Kory,

On Wed, Oct 02, 2024 at 06:28:08PM +0200, Kory Maincent wrote:
> From: Kory Maincent (Dent Project) <kory.maincent@bootlin.com>
>
> Add support for PSE event reporting through interrupts. Set up the newly
> introduced devm_pse_irq_helper helper to register the interrupt. Events are
> reported for over-current and over-temperature conditions.
>
> This patch also adds support for an OSS GPIO line to turn off all low
> priority ports in case of an over-current event.
>
> Signed-off-by: Kory Maincent <kory.maincent@bootlin.com>

...
> +static int tps23881_irq_handler(int irq, struct pse_irq_data *pid,
> + unsigned long *dev_mask)
> +{
> + struct tps23881_priv *priv = (struct tps23881_priv *)pid->data;
> + struct i2c_client *client = priv->client;
> + struct pse_err_state *stat;
> + int ret, i;
> + u16 val;
> +
> + *dev_mask = 0;
> + for (i = 0; i < TPS23881_MAX_CHANS; i++) {
> + stat = &pid->states[i];
> + stat->notifs = 0;
> + stat->errors = 0;
> + }
> +
> + ret = i2c_smbus_read_word_data(client, TPS23881_REG_IT);
> + if (ret < 0)
> + return PSE_FAILED_RETRY;
> +
> + val = (u16)ret;
> + if (val & TPS23881_REG_IT_SUPF) {
> + ret = i2c_smbus_read_word_data(client, TPS23881_REG_SUPF_EVENT);
> + if (ret < 0)
> + return PSE_FAILED_RETRY;
> +
> + if (ret & TPS23881_REG_TSD) {
> + for (i = 0; i < TPS23881_MAX_CHANS; i++) {
> + stat = &pid->states[i];
> + *dev_mask |= 1 << i;
> + stat->notifs = PSE_EVENT_OVER_TEMP;
> + stat->errors = PSE_ERROR_OVER_TEMP;
> + }
> + }
> + }
> +
> + if (val & (TPS23881_REG_IT_IFAULT | TPS23881_REG_IT_IFAULT << 8)) {
> + ret = i2c_smbus_read_word_data(client, TPS23881_REG_FAULT);
> + if (ret < 0)
> + return PSE_FAILED_RETRY;
> +
> + val = (u16)(ret & 0xf0f);
> +
> + /* Power cut detected, shutdown low priority port */
> + if (val && priv->oss)
> + tps23881_turn_off_low_prio(priv);

Sorry, this is policy and even not the best one.
The priority concept is related to the power budget, but this
implementation will shutdown all low prios ports only if some
port/channel has over-current event. It means, in case high prio port
has over-current event, it will be not shut down.

I'll propose not to add prio support for this chip right now, it will
need more software infrastructure to handle it nearly in similar way as
it is done by pd692x0.
--
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 |