[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Zbi+5ymzbL9sckdi@shell.armlinux.org.uk>
Date: Tue, 30 Jan 2024 09:18:31 +0000
From: "Russell King (Oracle)" <linux@...linux.org.uk>
To: Dimitri Fedrau <dima.fedrau@...il.com>
Cc: Andrew Lunn <andrew@...n.ch>, Heiner Kallweit <hkallweit1@...il.com>,
"David S. Miller" <davem@...emloft.net>,
Eric Dumazet <edumazet@...gle.com>,
Jakub Kicinski <kuba@...nel.org>, Paolo Abeni <pabeni@...hat.com>,
Jean Delvare <jdelvare@...e.com>,
Guenter Roeck <linux@...ck-us.net>,
Stefan Eichenberger <eichest@...il.com>, netdev@...r.kernel.org,
linux-kernel@...r.kernel.org, linux-hwmon@...r.kernel.org
Subject: Re: [PATCH v5 net-next 08/13] net: phy: marvell-88q2xxx: add support
for temperature sensor
On Mon, Jan 22, 2024 at 10:28:41PM +0100, Dimitri Fedrau wrote:
int tmp;
> + switch (attr) {
> + case hwmon_temp_input:
> + ret = phy_read_mmd(phydev, MDIO_MMD_PCS,
> + MDIO_MMD_PCS_MV_TEMP_SENSOR3);
> + if (ret < 0)
> + return ret;
> +
> + *val = ((ret & MDIO_MMD_PCS_MV_TEMP_SENSOR3_MASK) - 75) * 1000;
tmp = FIELD_GET(MDIO_MMD_PCS_MV_TEMP_SENSOR3_MASK, ret);
*val = (tmp - 75) * 1000;
> + return 0;
> + case hwmon_temp_max:
> + ret = phy_read_mmd(phydev, MDIO_MMD_PCS,
> + MDIO_MMD_PCS_MV_TEMP_SENSOR3);
> + if (ret < 0)
> + return ret;
> +
> + *val = (((ret & MDIO_MMD_PCS_MV_TEMP_SENSOR3_INT_THRESH_MASK) >>
> + MDIO_MMD_PCS_MV_TEMP_SENSOR3_INT_THRESH_SHIFT) - 75) *
> + 1000;
tmp = FIELD_GET(MDIO_MMD_PCS_MV_TEMP_SENSOR3_INT_THRESH_MASK,
ret);
*val = (tmp - 75) * 1000;
> + return 0;
> + case hwmon_temp_alarm:
> + ret = phy_read_mmd(phydev, MDIO_MMD_PCS,
> + MDIO_MMD_PCS_MV_TEMP_SENSOR1);
> + if (ret < 0)
> + return ret;
> +
> + *val = !!(ret & MDIO_MMD_PCS_MV_TEMP_SENSOR1_RAW_INT);
> + return 0;
> + default:
> + return -EOPNOTSUPP;
> + }
> +}
> +
> +static int mv88q2xxx_hwmon_write(struct device *dev,
> + enum hwmon_sensor_types type, u32 attr,
> + int channel, long val)
> +{
> + struct phy_device *phydev = dev_get_drvdata(dev);
> +
> + switch (attr) {
> + case hwmon_temp_max:
> + if (val < -75000 || val > 180000)
> + return -EINVAL;
> +
> + val = ((val / 1000) + 75) <<
> + MDIO_MMD_PCS_MV_TEMP_SENSOR3_INT_THRESH_SHIFT;
val = (val / 1000) + 75;
val = FIELD_PREP(MDIO_MMD_PCS_MV_TEMP_SENSOR3_INT_THRESH_MASK,
val);
.. and therefore no need for the _SHIFT constants.
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
Powered by blists - more mailing lists