1 // SPDX-License-Identifier: GPL-2.0-only
2 /* Copyright (C) 2014-2019 aQuantia Corporation. */
4 /* File aq_drvinfo.c: Definition of common code for firmware info in sys.*/
6 #include <linux/init.h>
7 #include <linux/kobject.h>
8 #include <linux/module.h>
9 #include <linux/stat.h>
10 #include <linux/string.h>
11 #include <linux/hwmon.h>
12 #include <linux/uaccess.h>
14 #include "aq_drvinfo.h"
16 #if IS_REACHABLE(CONFIG_HWMON)
17 static int aq_hwmon_read(struct device
*dev
, enum hwmon_sensor_types type
,
18 u32 attr
, int channel
, long *value
)
20 struct aq_nic_s
*aq_nic
= dev_get_drvdata(dev
);
27 if (type
!= hwmon_temp
)
30 if (!aq_nic
->aq_fw_ops
->get_phy_temp
)
34 case hwmon_temp_input
:
35 err
= aq_nic
->aq_fw_ops
->get_phy_temp(aq_nic
->aq_hw
, &temp
);
43 static int aq_hwmon_read_string(struct device
*dev
,
44 enum hwmon_sensor_types type
,
45 u32 attr
, int channel
, const char **str
)
47 struct aq_nic_s
*aq_nic
= dev_get_drvdata(dev
);
52 if (type
!= hwmon_temp
)
55 if (!aq_nic
->aq_fw_ops
->get_phy_temp
)
59 case hwmon_temp_label
:
60 *str
= "PHY Temperature";
67 static umode_t
aq_hwmon_is_visible(const void *data
,
68 enum hwmon_sensor_types type
,
69 u32 attr
, int channel
)
71 if (type
!= hwmon_temp
)
75 case hwmon_temp_input
:
76 case hwmon_temp_label
:
83 static const struct hwmon_ops aq_hwmon_ops
= {
84 .is_visible
= aq_hwmon_is_visible
,
85 .read
= aq_hwmon_read
,
86 .read_string
= aq_hwmon_read_string
,
89 static u32 aq_hwmon_temp_config
[] = {
90 HWMON_T_INPUT
| HWMON_T_LABEL
,
94 static const struct hwmon_channel_info aq_hwmon_temp
= {
96 .config
= aq_hwmon_temp_config
,
99 static const struct hwmon_channel_info
*aq_hwmon_info
[] = {
104 static const struct hwmon_chip_info aq_hwmon_chip_info
= {
105 .ops
= &aq_hwmon_ops
,
106 .info
= aq_hwmon_info
,
109 int aq_drvinfo_init(struct net_device
*ndev
)
111 struct aq_nic_s
*aq_nic
= netdev_priv(ndev
);
112 struct device
*dev
= &aq_nic
->pdev
->dev
;
113 struct device
*hwmon_dev
;
116 hwmon_dev
= devm_hwmon_device_register_with_info(dev
,
122 if (IS_ERR(hwmon_dev
))
123 err
= PTR_ERR(hwmon_dev
);
129 int aq_drvinfo_init(struct net_device
*ndev
) { return 0; }