]> git.baikalelectronics.ru Git - kernel.git/commitdiff
net: aquantia: implement hwmon api for chip temperature
authorYana Esina <yana.esina@aquantia.com>
Mon, 29 Apr 2019 10:04:38 +0000 (10:04 +0000)
committerDavid S. Miller <davem@davemloft.net>
Wed, 1 May 2019 13:30:14 +0000 (09:30 -0400)
Added support for hwmon api to fetch out chip temperature

Signed-off-by: Yana Esina <yana.esina@aquantia.com>
Signed-off-by: Nikita Danilov <nikita.danilov@aquantia.com>
Signed-off-by: Igor Russkikh <igor.russkikh@aquantia.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/aquantia/atlantic/Makefile
drivers/net/ethernet/aquantia/atlantic/aq_drvinfo.c [new file with mode: 0644]
drivers/net/ethernet/aquantia/atlantic/aq_drvinfo.h [new file with mode: 0644]
drivers/net/ethernet/aquantia/atlantic/aq_pci_func.c

index 4556630ee286cf42820ba2900727151012b4150c..1f99cf832476f0d7f5327672264e7c6990c74564 100644 (file)
@@ -36,6 +36,7 @@ atlantic-objs := aq_main.o \
        aq_ring.o \
        aq_hw_utils.o \
        aq_ethtool.o \
+       aq_drvinfo.o \
        aq_filters.o \
        hw_atl/hw_atl_a0.o \
        hw_atl/hw_atl_b0.o \
diff --git a/drivers/net/ethernet/aquantia/atlantic/aq_drvinfo.c b/drivers/net/ethernet/aquantia/atlantic/aq_drvinfo.c
new file mode 100644 (file)
index 0000000..f5a92b2
--- /dev/null
@@ -0,0 +1,125 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/* Copyright (C) 2014-2019 aQuantia Corporation. */
+
+/* File aq_drvinfo.c: Definition of common code for firmware info in sys.*/
+
+#include <linux/init.h>
+#include <linux/kobject.h>
+#include <linux/module.h>
+#include <linux/stat.h>
+#include <linux/string.h>
+#include <linux/hwmon.h>
+#include <linux/uaccess.h>
+
+#include "aq_drvinfo.h"
+
+static int aq_hwmon_read(struct device *dev, enum hwmon_sensor_types type,
+                        u32 attr, int channel, long *value)
+{
+       struct aq_nic_s *aq_nic = dev_get_drvdata(dev);
+       int temp;
+       int err;
+
+       if (!aq_nic)
+               return -EIO;
+
+       if (type != hwmon_temp)
+               return -EOPNOTSUPP;
+
+       if (!aq_nic->aq_fw_ops->get_phy_temp)
+               return -EOPNOTSUPP;
+
+       switch (attr) {
+       case hwmon_temp_input:
+               err = aq_nic->aq_fw_ops->get_phy_temp(aq_nic->aq_hw, &temp);
+               *value = temp;
+               return err;
+       default:
+               return -EOPNOTSUPP;
+       }
+}
+
+static int aq_hwmon_read_string(struct device *dev,
+                               enum hwmon_sensor_types type,
+                               u32 attr, int channel, const char **str)
+{
+       struct aq_nic_s *aq_nic = dev_get_drvdata(dev);
+
+       if (!aq_nic)
+               return -EIO;
+
+       if (type != hwmon_temp)
+               return -EOPNOTSUPP;
+
+       if (!aq_nic->aq_fw_ops->get_phy_temp)
+               return -EOPNOTSUPP;
+
+       switch (attr) {
+       case hwmon_temp_label:
+               *str = "PHY Temperature";
+               return 0;
+       default:
+               return -EOPNOTSUPP;
+       }
+}
+
+static umode_t aq_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_label:
+               return 0444;
+       default:
+               return 0;
+       }
+}
+
+static const struct hwmon_ops aq_hwmon_ops = {
+       .is_visible = aq_hwmon_is_visible,
+       .read = aq_hwmon_read,
+       .read_string = aq_hwmon_read_string,
+};
+
+static u32 aq_hwmon_temp_config[] = {
+       HWMON_T_INPUT | HWMON_T_LABEL,
+       0,
+};
+
+static const struct hwmon_channel_info aq_hwmon_temp = {
+       .type = hwmon_temp,
+       .config = aq_hwmon_temp_config,
+};
+
+static const struct hwmon_channel_info *aq_hwmon_info[] = {
+       &aq_hwmon_temp,
+       NULL,
+};
+
+static const struct hwmon_chip_info aq_hwmon_chip_info = {
+       .ops = &aq_hwmon_ops,
+       .info = aq_hwmon_info,
+};
+
+int aq_drvinfo_init(struct net_device *ndev)
+{
+       struct aq_nic_s *aq_nic = netdev_priv(ndev);
+       struct device *dev = &aq_nic->pdev->dev;
+       struct device *hwmon_dev;
+       int err = 0;
+
+       hwmon_dev = devm_hwmon_device_register_with_info(dev,
+                                                        ndev->name,
+                                                        aq_nic,
+                                                        &aq_hwmon_chip_info,
+                                                        NULL);
+
+       if (IS_ERR(hwmon_dev))
+               err = PTR_ERR(hwmon_dev);
+
+       return err;
+}
diff --git a/drivers/net/ethernet/aquantia/atlantic/aq_drvinfo.h b/drivers/net/ethernet/aquantia/atlantic/aq_drvinfo.h
new file mode 100644 (file)
index 0000000..41fbb13
--- /dev/null
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/* Copyright (C) 2014-2017 aQuantia Corporation. */
+
+/* File aq_drvinfo.h: Declaration of common code for firmware info in sys.*/
+
+#ifndef AQ_DRVINFO_H
+#define AQ_DRVINFO_H
+
+#include "aq_nic.h"
+#include "aq_hw.h"
+#include "hw_atl/hw_atl_utils.h"
+
+int aq_drvinfo_init(struct net_device *ndev);
+
+#endif /* AQ_DRVINFO_H */
index 0217ff4669a46f30b26c2f70d4f3f9e71813ece0..533a78deefee605d760875085cf80ec517647306 100644 (file)
@@ -20,6 +20,7 @@
 #include "hw_atl/hw_atl_a0.h"
 #include "hw_atl/hw_atl_b0.h"
 #include "aq_filters.h"
+#include "aq_drvinfo.h"
 
 static const struct pci_device_id aq_pci_tbl[] = {
        { PCI_VDEVICE(AQUANTIA, AQ_DEVICE_ID_0001), },
@@ -289,6 +290,8 @@ static int aq_pci_probe(struct pci_dev *pdev,
        if (err < 0)
                goto err_register;
 
+       aq_drvinfo_init(ndev);
+
        return 0;
 
 err_register: