From patchwork Tue Apr 20 07:53:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 425063 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DB6F4C433B4 for ; Tue, 20 Apr 2021 07:54:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9D921613B8 for ; Tue, 20 Apr 2021 07:54:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230035AbhDTHzX (ORCPT ); Tue, 20 Apr 2021 03:55:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:40544 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229659AbhDTHzV (ORCPT ); Tue, 20 Apr 2021 03:55:21 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8D1DF6135F; Tue, 20 Apr 2021 07:54:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1618905290; bh=3mhmNEzOJjKtkjqMFYZa8CyBVLTGaWoXu/Hi9ip1nQE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jMaBuObGNTz0buCveVvJ8LJS8lJhdh1c1M3ovH2TO9Goq9jGJKWNee+GrjuSmXMo4 9yLh5ViL1lVw6Xpa79ag+DQsFnbMHf9ii2q99g3kk2q/Sq7kHtqTIgR/uJWBmK4RWz y/X+snZLus3B7p8LxXfQttlt9gkFFV1c/bVCYr4HQR3x+s/tKtMd7d42OJmB1qF2KC UDZZK4gxx5bdDGEQNB/XGelQhqgqHQ1pf/cV158mRJ6V5v9wWR6gbH1GkpRyD89gCE VV7+qLbsmkQ2zUFUxt7A9tIVGRjEGV/YYYJb70630x09L4DLcLClqWIu6Zr6TeHB9V qVxL6pgwo6lZA== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: netdev@vger.kernel.org, Andrew Lunn Cc: "David S . Miller" , Russell King , kuba@kernel.org, =?utf-8?q?Marek_Beh?= =?utf-8?b?w7pu?= Subject: [PATCH net-next v2 1/5] net: phy: marvell: refactor HWMON OOP style Date: Tue, 20 Apr 2021 09:53:59 +0200 Message-Id: <20210420075403.5845-2-kabel@kernel.org> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210420075403.5845-1-kabel@kernel.org> References: <20210420075403.5845-1-kabel@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Use a structure of Marvell PHY specific HWMON methods to reduce code duplication. Store a pointer to this structure into the PHY driver's driver_data member. Signed-off-by: Marek Behún --- drivers/net/phy/marvell.c | 369 +++++++++++++------------------------- 1 file changed, 125 insertions(+), 244 deletions(-) diff --git a/drivers/net/phy/marvell.c b/drivers/net/phy/marvell.c index 8018ddf7f316..70cfcfcdd8f2 100644 --- a/drivers/net/phy/marvell.c +++ b/drivers/net/phy/marvell.c @@ -2216,6 +2216,19 @@ static int marvell_vct7_cable_test_get_status(struct phy_device *phydev, } #ifdef CONFIG_HWMON +struct marvell_hwmon_ops { + int (*get_temp)(struct phy_device *phydev, long *temp); + int (*get_temp_critical)(struct phy_device *phydev, long *temp); + int (*set_temp_critical)(struct phy_device *phydev, long temp); + int (*get_temp_alarm)(struct phy_device *phydev, long *alarm); +}; + +static const struct marvell_hwmon_ops * +to_marvell_hwmon_ops(const struct phy_device *phydev) +{ + return phydev->drv->driver_data; +} + static int m88e1121_get_temp(struct phy_device *phydev, long *temp) { int oldpage; @@ -2259,75 +2272,6 @@ static int m88e1121_get_temp(struct phy_device *phydev, long *temp) return phy_restore_page(phydev, oldpage, ret); } -static int m88e1121_hwmon_read(struct device *dev, - enum hwmon_sensor_types type, - u32 attr, int channel, long *temp) -{ - struct phy_device *phydev = dev_get_drvdata(dev); - int err; - - switch (attr) { - case hwmon_temp_input: - err = m88e1121_get_temp(phydev, temp); - break; - default: - return -EOPNOTSUPP; - } - - return err; -} - -static umode_t m88e1121_hwmon_is_visible(const void *data, - enum hwmon_sensor_types type, - u32 attr, int channel) -{ - if (type != hwmon_temp) - return 0; - - switch (attr) { - case hwmon_temp_input: - return 0444; - default: - return 0; - } -} - -static u32 m88e1121_hwmon_chip_config[] = { - HWMON_C_REGISTER_TZ, - 0 -}; - -static const struct hwmon_channel_info m88e1121_hwmon_chip = { - .type = hwmon_chip, - .config = m88e1121_hwmon_chip_config, -}; - -static u32 m88e1121_hwmon_temp_config[] = { - HWMON_T_INPUT, - 0 -}; - -static const struct hwmon_channel_info m88e1121_hwmon_temp = { - .type = hwmon_temp, - .config = m88e1121_hwmon_temp_config, -}; - -static const struct hwmon_channel_info *m88e1121_hwmon_info[] = { - &m88e1121_hwmon_chip, - &m88e1121_hwmon_temp, - NULL -}; - -static const struct hwmon_ops m88e1121_hwmon_hwmon_ops = { - .is_visible = m88e1121_hwmon_is_visible, - .read = m88e1121_hwmon_read, -}; - -static const struct hwmon_chip_info m88e1121_hwmon_chip_info = { - .ops = &m88e1121_hwmon_hwmon_ops, - .info = m88e1121_hwmon_info, -}; - static int m88e1510_get_temp(struct phy_device *phydev, long *temp) { int ret; @@ -2390,92 +2334,6 @@ static int m88e1510_get_temp_alarm(struct phy_device *phydev, long *alarm) return 0; } -static int m88e1510_hwmon_read(struct device *dev, - enum hwmon_sensor_types type, - u32 attr, int channel, long *temp) -{ - struct phy_device *phydev = dev_get_drvdata(dev); - int err; - - switch (attr) { - case hwmon_temp_input: - err = m88e1510_get_temp(phydev, temp); - break; - case hwmon_temp_crit: - err = m88e1510_get_temp_critical(phydev, temp); - break; - case hwmon_temp_max_alarm: - err = m88e1510_get_temp_alarm(phydev, temp); - break; - default: - return -EOPNOTSUPP; - } - - return err; -} - -static int m88e1510_hwmon_write(struct device *dev, - enum hwmon_sensor_types type, - u32 attr, int channel, long temp) -{ - struct phy_device *phydev = dev_get_drvdata(dev); - int err; - - switch (attr) { - case hwmon_temp_crit: - err = m88e1510_set_temp_critical(phydev, temp); - break; - default: - return -EOPNOTSUPP; - } - return err; -} - -static umode_t m88e1510_hwmon_is_visible(const void *data, - enum hwmon_sensor_types type, - u32 attr, int channel) -{ - if (type != hwmon_temp) - return 0; - - switch (attr) { - case hwmon_temp_input: - case hwmon_temp_max_alarm: - return 0444; - case hwmon_temp_crit: - return 0644; - default: - return 0; - } -} - -static u32 m88e1510_hwmon_temp_config[] = { - HWMON_T_INPUT | HWMON_T_CRIT | HWMON_T_MAX_ALARM, - 0 -}; - -static const struct hwmon_channel_info m88e1510_hwmon_temp = { - .type = hwmon_temp, - .config = m88e1510_hwmon_temp_config, -}; - -static const struct hwmon_channel_info *m88e1510_hwmon_info[] = { - &m88e1121_hwmon_chip, - &m88e1510_hwmon_temp, - NULL -}; - -static const struct hwmon_ops m88e1510_hwmon_hwmon_ops = { - .is_visible = m88e1510_hwmon_is_visible, - .read = m88e1510_hwmon_read, - .write = m88e1510_hwmon_write, -}; - -static const struct hwmon_chip_info m88e1510_hwmon_chip_info = { - .ops = &m88e1510_hwmon_hwmon_ops, - .info = m88e1510_hwmon_info, -}; - static int m88e6390_get_temp(struct phy_device *phydev, long *temp) { int sum = 0; @@ -2534,63 +2392,112 @@ static int m88e6390_get_temp(struct phy_device *phydev, long *temp) return ret; } -static int m88e6390_hwmon_read(struct device *dev, - enum hwmon_sensor_types type, - u32 attr, int channel, long *temp) +static int marvell_hwmon_read(struct device *dev, enum hwmon_sensor_types type, + u32 attr, int channel, long *temp) { struct phy_device *phydev = dev_get_drvdata(dev); - int err; + const struct marvell_hwmon_ops *ops = to_marvell_hwmon_ops(phydev); + int err = -EOPNOTSUPP; switch (attr) { case hwmon_temp_input: - err = m88e6390_get_temp(phydev, temp); + if (ops->get_temp) + err = ops->get_temp(phydev, temp); + break; + case hwmon_temp_crit: + if (ops->get_temp_critical) + err = ops->get_temp_critical(phydev, temp); + break; + case hwmon_temp_max_alarm: + if (ops->get_temp_alarm) + err = ops->get_temp_alarm(phydev, temp); + break; + } + + return err; +} + +static int marvell_hwmon_write(struct device *dev, enum hwmon_sensor_types type, + u32 attr, int channel, long temp) +{ + struct phy_device *phydev = dev_get_drvdata(dev); + const struct marvell_hwmon_ops *ops = to_marvell_hwmon_ops(phydev); + int err = -EOPNOTSUPP; + + switch (attr) { + case hwmon_temp_crit: + if (ops->set_temp_critical) + err = ops->set_temp_critical(phydev, temp); break; default: - return -EOPNOTSUPP; + fallthrough; } return err; } -static umode_t m88e6390_hwmon_is_visible(const void *data, - enum hwmon_sensor_types type, - u32 attr, int channel) +static umode_t marvell_hwmon_is_visible(const void *data, + enum hwmon_sensor_types type, + u32 attr, int channel) { + const struct phy_device *phydev = data; + const struct marvell_hwmon_ops *ops = to_marvell_hwmon_ops(phydev); + if (type != hwmon_temp) return 0; switch (attr) { case hwmon_temp_input: - return 0444; + return ops->get_temp ? 0444 : 0; + case hwmon_temp_max_alarm: + return ops->get_temp_alarm ? 0444 : 0; + case hwmon_temp_crit: + return (ops->get_temp_critical ? 0444 : 0) | + (ops->set_temp_critical ? 0200 : 0); default: return 0; } } -static u32 m88e6390_hwmon_temp_config[] = { - HWMON_T_INPUT, +static u32 marvell_hwmon_chip_config[] = { + HWMON_C_REGISTER_TZ, 0 }; -static const struct hwmon_channel_info m88e6390_hwmon_temp = { +static const struct hwmon_channel_info marvell_hwmon_chip = { + .type = hwmon_chip, + .config = marvell_hwmon_chip_config, +}; + +/* we can define HWMON_T_CRIT and HWMON_T_MAX_ALARM even though these are not + * defined for all PHYs, because the hwmon code checks whether the attributes + * exists via the .is_visible method + */ +static u32 marvell_hwmon_temp_config[] = { + HWMON_T_INPUT | HWMON_T_CRIT | HWMON_T_MAX_ALARM, + 0 +}; + +static const struct hwmon_channel_info marvell_hwmon_temp = { .type = hwmon_temp, - .config = m88e6390_hwmon_temp_config, + .config = marvell_hwmon_temp_config, }; -static const struct hwmon_channel_info *m88e6390_hwmon_info[] = { - &m88e1121_hwmon_chip, - &m88e6390_hwmon_temp, +static const struct hwmon_channel_info *marvell_hwmon_info[] = { + &marvell_hwmon_chip, + &marvell_hwmon_temp, NULL }; -static const struct hwmon_ops m88e6390_hwmon_hwmon_ops = { - .is_visible = m88e6390_hwmon_is_visible, - .read = m88e6390_hwmon_read, +static const struct hwmon_ops marvell_hwmon_hwmon_ops = { + .is_visible = marvell_hwmon_is_visible, + .read = marvell_hwmon_read, + .write = marvell_hwmon_write, }; -static const struct hwmon_chip_info m88e6390_hwmon_chip_info = { - .ops = &m88e6390_hwmon_hwmon_ops, - .info = m88e6390_hwmon_info, +static const struct hwmon_chip_info marvell_hwmon_chip_info = { + .ops = &marvell_hwmon_hwmon_ops, + .info = marvell_hwmon_info, }; static int marvell_hwmon_name(struct phy_device *phydev) @@ -2613,49 +2520,48 @@ static int marvell_hwmon_name(struct phy_device *phydev) return 0; } -static int marvell_hwmon_probe(struct phy_device *phydev, - const struct hwmon_chip_info *chip) +static int marvell_hwmon_probe(struct phy_device *phydev) { + const struct marvell_hwmon_ops *ops = to_marvell_hwmon_ops(phydev); struct marvell_priv *priv = phydev->priv; struct device *dev = &phydev->mdio.dev; int err; + if (!ops) + return 0; + err = marvell_hwmon_name(phydev); if (err) return err; priv->hwmon_dev = devm_hwmon_device_register_with_info( - dev, priv->hwmon_name, phydev, chip, NULL); + dev, priv->hwmon_name, phydev, &marvell_hwmon_chip_info, NULL); return PTR_ERR_OR_ZERO(priv->hwmon_dev); } -static int m88e1121_hwmon_probe(struct phy_device *phydev) -{ - return marvell_hwmon_probe(phydev, &m88e1121_hwmon_chip_info); -} +static const struct marvell_hwmon_ops m88e1121_hwmon_ops = { + .get_temp = m88e1121_get_temp, +}; -static int m88e1510_hwmon_probe(struct phy_device *phydev) -{ - return marvell_hwmon_probe(phydev, &m88e1510_hwmon_chip_info); -} +static const struct marvell_hwmon_ops m88e1510_hwmon_ops = { + .get_temp = m88e1510_get_temp, + .get_temp_critical = m88e1510_get_temp_critical, + .set_temp_critical = m88e1510_set_temp_critical, + .get_temp_alarm = m88e1510_get_temp_alarm, +}; + +static const struct marvell_hwmon_ops m88e6390_hwmon_ops = { + .get_temp = m88e6390_get_temp, +}; + +#define DEF_MARVELL_HWMON_OPS(s) (&(s)) -static int m88e6390_hwmon_probe(struct phy_device *phydev) -{ - return marvell_hwmon_probe(phydev, &m88e6390_hwmon_chip_info); -} #else -static int m88e1121_hwmon_probe(struct phy_device *phydev) -{ - return 0; -} -static int m88e1510_hwmon_probe(struct phy_device *phydev) -{ - return 0; -} +#define DEF_MARVELL_HWMON_OPS(s) NULL -static int m88e6390_hwmon_probe(struct phy_device *phydev) +static int marvell_hwmon_probe(struct phy_device *phydev) { return 0; } @@ -2671,40 +2577,7 @@ static int marvell_probe(struct phy_device *phydev) phydev->priv = priv; - return 0; -} - -static int m88e1121_probe(struct phy_device *phydev) -{ - int err; - - err = marvell_probe(phydev); - if (err) - return err; - - return m88e1121_hwmon_probe(phydev); -} - -static int m88e1510_probe(struct phy_device *phydev) -{ - int err; - - err = marvell_probe(phydev); - if (err) - return err; - - return m88e1510_hwmon_probe(phydev); -} - -static int m88e6390_probe(struct phy_device *phydev) -{ - int err; - - err = marvell_probe(phydev); - if (err) - return err; - - return m88e6390_hwmon_probe(phydev); + return marvell_hwmon_probe(phydev); } static struct phy_driver marvell_drivers[] = { @@ -2810,8 +2683,9 @@ static struct phy_driver marvell_drivers[] = { .phy_id = MARVELL_PHY_ID_88E1121R, .phy_id_mask = MARVELL_PHY_ID_MASK, .name = "Marvell 88E1121R", + .driver_data = DEF_MARVELL_HWMON_OPS(m88e1121_hwmon_ops), /* PHY_GBIT_FEATURES */ - .probe = m88e1121_probe, + .probe = marvell_probe, .config_init = marvell_config_init, .config_aneg = m88e1121_config_aneg, .read_status = marvell_read_status, @@ -2927,9 +2801,10 @@ static struct phy_driver marvell_drivers[] = { .phy_id = MARVELL_PHY_ID_88E1510, .phy_id_mask = MARVELL_PHY_ID_MASK, .name = "Marvell 88E1510", + .driver_data = DEF_MARVELL_HWMON_OPS(m88e1510_hwmon_ops), .features = PHY_GBIT_FIBRE_FEATURES, .flags = PHY_POLL_CABLE_TEST, - .probe = m88e1510_probe, + .probe = marvell_probe, .config_init = m88e1510_config_init, .config_aneg = m88e1510_config_aneg, .read_status = marvell_read_status, @@ -2955,9 +2830,10 @@ static struct phy_driver marvell_drivers[] = { .phy_id = MARVELL_PHY_ID_88E1540, .phy_id_mask = MARVELL_PHY_ID_MASK, .name = "Marvell 88E1540", + .driver_data = DEF_MARVELL_HWMON_OPS(m88e1510_hwmon_ops), /* PHY_GBIT_FEATURES */ .flags = PHY_POLL_CABLE_TEST, - .probe = m88e1510_probe, + .probe = marvell_probe, .config_init = marvell_config_init, .config_aneg = m88e1510_config_aneg, .read_status = marvell_read_status, @@ -2980,7 +2856,8 @@ static struct phy_driver marvell_drivers[] = { .phy_id = MARVELL_PHY_ID_88E1545, .phy_id_mask = MARVELL_PHY_ID_MASK, .name = "Marvell 88E1545", - .probe = m88e1510_probe, + .driver_data = DEF_MARVELL_HWMON_OPS(m88e1510_hwmon_ops), + .probe = marvell_probe, /* PHY_GBIT_FEATURES */ .flags = PHY_POLL_CABLE_TEST, .config_init = marvell_config_init, @@ -3024,9 +2901,10 @@ static struct phy_driver marvell_drivers[] = { .phy_id = MARVELL_PHY_ID_88E6341_FAMILY, .phy_id_mask = MARVELL_PHY_ID_MASK, .name = "Marvell 88E6341 Family", + .driver_data = DEF_MARVELL_HWMON_OPS(m88e1510_hwmon_ops), /* PHY_GBIT_FEATURES */ .flags = PHY_POLL_CABLE_TEST, - .probe = m88e1510_probe, + .probe = marvell_probe, .config_init = marvell_config_init, .config_aneg = m88e6390_config_aneg, .read_status = marvell_read_status, @@ -3049,9 +2927,10 @@ static struct phy_driver marvell_drivers[] = { .phy_id = MARVELL_PHY_ID_88E6390_FAMILY, .phy_id_mask = MARVELL_PHY_ID_MASK, .name = "Marvell 88E6390 Family", + .driver_data = DEF_MARVELL_HWMON_OPS(m88e6390_hwmon_ops), /* PHY_GBIT_FEATURES */ .flags = PHY_POLL_CABLE_TEST, - .probe = m88e6390_probe, + .probe = marvell_probe, .config_init = marvell_config_init, .config_aneg = m88e6390_config_aneg, .read_status = marvell_read_status, @@ -3074,7 +2953,8 @@ static struct phy_driver marvell_drivers[] = { .phy_id = MARVELL_PHY_ID_88E1340S, .phy_id_mask = MARVELL_PHY_ID_MASK, .name = "Marvell 88E1340S", - .probe = m88e1510_probe, + .driver_data = DEF_MARVELL_HWMON_OPS(m88e1510_hwmon_ops), + .probe = marvell_probe, /* PHY_GBIT_FEATURES */ .config_init = marvell_config_init, .config_aneg = m88e1510_config_aneg, @@ -3095,7 +2975,8 @@ static struct phy_driver marvell_drivers[] = { .phy_id = MARVELL_PHY_ID_88E1548P, .phy_id_mask = MARVELL_PHY_ID_MASK, .name = "Marvell 88E1548P", - .probe = m88e1510_probe, + .driver_data = DEF_MARVELL_HWMON_OPS(m88e1510_hwmon_ops), + .probe = marvell_probe, .features = PHY_GBIT_FIBRE_FEATURES, .config_init = marvell_config_init, .config_aneg = m88e1510_config_aneg, From patchwork Tue Apr 20 07:54:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 425062 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E4187C433ED for ; Tue, 20 Apr 2021 07:54:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A49E261155 for ; Tue, 20 Apr 2021 07:54:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230187AbhDTHz0 (ORCPT ); Tue, 20 Apr 2021 03:55:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:40614 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229981AbhDTHzZ (ORCPT ); Tue, 20 Apr 2021 03:55:25 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id EBF68613B4; Tue, 20 Apr 2021 07:54:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1618905294; bh=9+SHHBZIc/0Ed6lwP2UUfNL+XmMEtfetbMXJsD3EnOY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qonqMvilBvPiHu4rpY/InGbtW0+WG7cvr1aOW1UffvSjYa66iZfVFXzfU9sGr3v9t 7ES64MeC79eterRXRNy8Nx2JUW8B70bY9uM37ZbPm1UcCuBDBvzCvvxWAsxgXMYAUl Dmb1Pdn7F0JxVKnVQKv7c1h95xu/8LW9Q2PUuSt16ZEpZPzXV/KeRcF4cXwY9jCKWM X4fu1Qt3B54YtVzuYag9LiEB8FSLIAc50mvZz/xgX77Kt5eMbKhTqGGinwnVB9QDS+ 2X5YyK2RAFK8v+/EZbYGxqB5H6F9nzuZ3xdzlYTbl98RigIX+dJsS26lalxep1id6r nVLfn3sT597iw== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: netdev@vger.kernel.org, Andrew Lunn Cc: "David S . Miller" , Russell King , kuba@kernel.org, =?utf-8?q?Marek_Beh?= =?utf-8?b?w7pu?= Subject: [PATCH net-next v2 3/5] net: phy: marvell: use assignment by bitwise AND operator Date: Tue, 20 Apr 2021 09:54:01 +0200 Message-Id: <20210420075403.5845-4-kabel@kernel.org> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210420075403.5845-1-kabel@kernel.org> References: <20210420075403.5845-1-kabel@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Use the &= operator instead of ret = ret & ... Signed-off-by: Marek Behún Reviewed-by: Andrew Lunn --- drivers/net/phy/marvell.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/phy/marvell.c b/drivers/net/phy/marvell.c index 9529aaa3bed3..e505060d0743 100644 --- a/drivers/net/phy/marvell.c +++ b/drivers/net/phy/marvell.c @@ -2352,7 +2352,7 @@ static int m88e6390_get_temp(struct phy_device *phydev, long *temp) if (ret < 0) goto error; - ret = ret & ~MII_88E6390_MISC_TEST_TEMP_SENSOR_MASK; + ret &= ~MII_88E6390_MISC_TEST_TEMP_SENSOR_MASK; ret |= MII_88E6390_MISC_TEST_TEMP_SENSOR_ENABLE_SAMPLE_1S; ret = __phy_write(phydev, MII_88E6390_MISC_TEST, ret); From patchwork Tue Apr 20 07:54:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 425061 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 761FBC433ED for ; Tue, 20 Apr 2021 07:55:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3763D61077 for ; Tue, 20 Apr 2021 07:55:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230227AbhDTHzf (ORCPT ); Tue, 20 Apr 2021 03:55:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:40680 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230188AbhDTHz3 (ORCPT ); Tue, 20 Apr 2021 03:55:29 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5992361008; Tue, 20 Apr 2021 07:54:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1618905297; bh=rSCmV+qhLHvP35CWKC8PL/2R16UdtRxJjyiMInS+7EY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=budcQ/jocN92Uvy9E7W0DrVHwDoaSLGyCeX9bvN+LiXoUrqy3mbi0pHQTbeVeyLme 8jmC1UVx5qQL0zxQsmyraXuA/uyce8g1Fm0QpLmUZJfz9ZSJSOhu9MMztK3Wy8iXIA jrOlPKfJUxppFIDSSD0AjEMqfesroMsXRBEyvedMemvxvIQu1diB9qbeOlkdHaEoF3 YhDy73FUqgT4OeX1/ufjKTLS0c894tb5RJXqJ4RboNHtry8flMUZGjgLTFIHpNbGny cuhy9nTuTMFCktsF7nDQKd/7vpWUhRADiEmqGKL4/i/sWXe+96ZW4juw6Ng9ceTApb JMb+DFptVcoQA== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: netdev@vger.kernel.org, Andrew Lunn Cc: "David S . Miller" , Russell King , kuba@kernel.org, =?utf-8?q?Marek_Beh?= =?utf-8?b?w7pu?= Subject: [PATCH net-next v2 5/5] net: phy: marvell: add support for Amethyst internal PHY Date: Tue, 20 Apr 2021 09:54:03 +0200 Message-Id: <20210420075403.5845-6-kabel@kernel.org> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210420075403.5845-1-kabel@kernel.org> References: <20210420075403.5845-1-kabel@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Add support for Amethyst internal PHY. The only difference from Peridot is HWMON. Signed-off-by: Marek Behún --- drivers/net/phy/marvell.c | 117 +++++++++++++++++++++++++++++++++++- include/linux/marvell_phy.h | 1 + 2 files changed, 115 insertions(+), 3 deletions(-) diff --git a/drivers/net/phy/marvell.c b/drivers/net/phy/marvell.c index e505060d0743..1cce86b280af 100644 --- a/drivers/net/phy/marvell.c +++ b/drivers/net/phy/marvell.c @@ -118,10 +118,21 @@ #define MII_88E6390_MISC_TEST_TEMP_SENSOR_ENABLE_ONESHOT (0x2 << 14) #define MII_88E6390_MISC_TEST_TEMP_SENSOR_DISABLE (0x3 << 14) #define MII_88E6390_MISC_TEST_TEMP_SENSOR_MASK (0x3 << 14) +#define MII_88E6393_MISC_TEST_SAMPLES_2048 (0x0 << 11) +#define MII_88E6393_MISC_TEST_SAMPLES_4096 (0x1 << 11) +#define MII_88E6393_MISC_TEST_SAMPLES_8192 (0x2 << 11) +#define MII_88E6393_MISC_TEST_SAMPLES_16384 (0x3 << 11) +#define MII_88E6393_MISC_TEST_SAMPLES_MASK (0x3 << 11) +#define MII_88E6393_MISC_TEST_RATE_2_3MS (0x5 << 8) +#define MII_88E6393_MISC_TEST_RATE_6_4MS (0x6 << 8) +#define MII_88E6393_MISC_TEST_RATE_11_9MS (0x7 << 8) +#define MII_88E6393_MISC_TEST_RATE_MASK (0x7 << 8) #define MII_88E6390_TEMP_SENSOR 0x1c -#define MII_88E6390_TEMP_SENSOR_MASK 0xff -#define MII_88E6390_TEMP_SENSOR_SAMPLES 10 +#define MII_88E6393_TEMP_SENSOR_THRESHOLD_MASK 0xff00 +#define MII_88E6393_TEMP_SENSOR_THRESHOLD_SHIFT 8 +#define MII_88E6390_TEMP_SENSOR_MASK 0xff +#define MII_88E6390_TEMP_SENSOR_SAMPLES 10 #define MII_88E1318S_PHY_MSCR1_REG 16 #define MII_88E1318S_PHY_MSCR1_PAD_ODD BIT(6) @@ -2217,6 +2228,7 @@ static int marvell_vct7_cable_test_get_status(struct phy_device *phydev, #ifdef CONFIG_HWMON struct marvell_hwmon_ops { + int (*config)(struct phy_device *phydev); int (*get_temp)(struct phy_device *phydev, long *temp); int (*get_temp_critical)(struct phy_device *phydev, long *temp); int (*set_temp_critical)(struct phy_device *phydev, long temp); @@ -2391,6 +2403,65 @@ static int m88e6390_get_temp(struct phy_device *phydev, long *temp) return ret; } +static int m88e6393_get_temp(struct phy_device *phydev, long *temp) +{ + int err; + + err = m88e1510_get_temp(phydev, temp); + + /* 88E1510 measures T + 25, while the PHY on 88E6393X switch + * T + 75, so we have to subtract another 50 + */ + *temp -= 50000; + + return err; +} + +static int m88e6393_get_temp_critical(struct phy_device *phydev, long *temp) +{ + int ret; + + *temp = 0; + + ret = phy_read_paged(phydev, MII_MARVELL_MISC_TEST_PAGE, + MII_88E6390_TEMP_SENSOR); + if (ret < 0) + return ret; + + *temp = (((ret & MII_88E6393_TEMP_SENSOR_THRESHOLD_MASK) >> + MII_88E6393_TEMP_SENSOR_THRESHOLD_SHIFT) - 75) * 1000; + + return 0; +} + +static int m88e6393_set_temp_critical(struct phy_device *phydev, long temp) +{ + temp = (temp / 1000) + 75; + + return phy_modify_paged(phydev, MII_MARVELL_MISC_TEST_PAGE, + MII_88E6390_TEMP_SENSOR, + MII_88E6393_TEMP_SENSOR_THRESHOLD_MASK, + temp << MII_88E6393_TEMP_SENSOR_THRESHOLD_SHIFT); +} + +static int m88e6393_hwmon_config(struct phy_device *phydev) +{ + int err; + + err = m88e6393_set_temp_critical(phydev, 100000); + if (err) + return err; + + return phy_modify_paged(phydev, MII_MARVELL_MISC_TEST_PAGE, + MII_88E6390_MISC_TEST, + MII_88E6390_MISC_TEST_TEMP_SENSOR_MASK | + MII_88E6393_MISC_TEST_SAMPLES_MASK | + MII_88E6393_MISC_TEST_RATE_MASK, + MII_88E6390_MISC_TEST_TEMP_SENSOR_ENABLE | + MII_88E6393_MISC_TEST_SAMPLES_2048 | + MII_88E6393_MISC_TEST_RATE_2_3MS); +} + static int marvell_hwmon_read(struct device *dev, enum hwmon_sensor_types type, u32 attr, int channel, long *temp) { @@ -2535,8 +2606,13 @@ static int marvell_hwmon_probe(struct phy_device *phydev) priv->hwmon_dev = devm_hwmon_device_register_with_info( dev, priv->hwmon_name, phydev, &marvell_hwmon_chip_info, NULL); + if (IS_ERR(priv->hwmon_dev)) + return PTR_ERR(priv->hwmon_dev); - return PTR_ERR_OR_ZERO(priv->hwmon_dev); + if (ops->config) + err = ops->config(phydev); + + return err; } static const struct marvell_hwmon_ops m88e1121_hwmon_ops = { @@ -2554,6 +2630,14 @@ static const struct marvell_hwmon_ops m88e6390_hwmon_ops = { .get_temp = m88e6390_get_temp, }; +static const struct marvell_hwmon_ops m88e6393_hwmon_ops = { + .config = m88e6393_hwmon_config, + .get_temp = m88e6393_get_temp, + .get_temp_critical = m88e6393_get_temp_critical, + .set_temp_critical = m88e6393_set_temp_critical, + .get_temp_alarm = m88e1510_get_temp_alarm, +}; + #define DEF_MARVELL_HWMON_OPS(s) (&(s)) #else @@ -2948,6 +3032,32 @@ static struct phy_driver marvell_drivers[] = { .cable_test_tdr_start = marvell_vct5_cable_test_tdr_start, .cable_test_get_status = marvell_vct7_cable_test_get_status, }, + { + .phy_id = MARVELL_PHY_ID_88E6393_FAMILY, + .phy_id_mask = MARVELL_PHY_ID_MASK, + .name = "Marvell 88E6393 Family", + .driver_data = DEF_MARVELL_HWMON_OPS(m88e6393_hwmon_ops), + /* PHY_GBIT_FEATURES */ + .flags = PHY_POLL_CABLE_TEST, + .probe = marvell_probe, + .config_init = marvell_config_init, + .config_aneg = m88e1510_config_aneg, + .read_status = marvell_read_status, + .config_intr = marvell_config_intr, + .handle_interrupt = marvell_handle_interrupt, + .resume = genphy_resume, + .suspend = genphy_suspend, + .read_page = marvell_read_page, + .write_page = marvell_write_page, + .get_sset_count = marvell_get_sset_count, + .get_strings = marvell_get_strings, + .get_stats = marvell_get_stats, + .get_tunable = m88e1540_get_tunable, + .set_tunable = m88e1540_set_tunable, + .cable_test_start = marvell_vct7_cable_test_start, + .cable_test_tdr_start = marvell_vct5_cable_test_tdr_start, + .cable_test_get_status = marvell_vct7_cable_test_get_status, + }, { .phy_id = MARVELL_PHY_ID_88E1340S, .phy_id_mask = MARVELL_PHY_ID_MASK, @@ -3014,6 +3124,7 @@ static struct mdio_device_id __maybe_unused marvell_tbl[] = { { MARVELL_PHY_ID_88E3016, MARVELL_PHY_ID_MASK }, { MARVELL_PHY_ID_88E6341_FAMILY, MARVELL_PHY_ID_MASK }, { MARVELL_PHY_ID_88E6390_FAMILY, MARVELL_PHY_ID_MASK }, + { MARVELL_PHY_ID_88E6393_FAMILY, MARVELL_PHY_ID_MASK }, { MARVELL_PHY_ID_88E1340S, MARVELL_PHY_ID_MASK }, { MARVELL_PHY_ID_88E1548P, MARVELL_PHY_ID_MASK }, { } diff --git a/include/linux/marvell_phy.h b/include/linux/marvell_phy.h index f61d82c53f30..acee44b9db26 100644 --- a/include/linux/marvell_phy.h +++ b/include/linux/marvell_phy.h @@ -39,6 +39,7 @@ */ #define MARVELL_PHY_ID_88E6341_FAMILY 0x01410f41 #define MARVELL_PHY_ID_88E6390_FAMILY 0x01410f90 +#define MARVELL_PHY_ID_88E6393_FAMILY 0x002b0b9b #define MARVELL_PHY_FAMILY_ID(id) ((id) >> 4)