1 // SPDX-License-Identifier: GPL-2.0-only
2 /* Atlantic Network Driver
4 * Copyright (C) 2014-2019 aQuantia Corporation
5 * Copyright (C) 2019-2020 Marvell International Ltd.
8 /* File aq_drvinfo.c: Definition of common code for firmware info in sys.*/
10 #include <linux/init.h>
11 #include <linux/kobject.h>
12 #include <linux/module.h>
13 #include <linux/stat.h>
14 #include <linux/string.h>
15 #include <linux/hwmon.h>
16 #include <linux/uaccess.h>
18 #include "aq_drvinfo.h"
21 #if IS_REACHABLE(CONFIG_HWMON)
22 static const char * const atl_temp_label
[] = {
27 static int aq_hwmon_read(struct device
*dev
, enum hwmon_sensor_types type
,
28 u32 attr
, int channel
, long *value
)
30 struct aq_nic_s
*aq_nic
= dev_get_drvdata(dev
);
37 if (type
!= hwmon_temp
|| attr
!= hwmon_temp_input
)
42 if (!aq_nic
->aq_fw_ops
->get_phy_temp
)
45 err
= aq_nic
->aq_fw_ops
->get_phy_temp(aq_nic
->aq_hw
, &temp
);
49 if (!aq_nic
->aq_fw_ops
->get_mac_temp
&&
50 !aq_nic
->aq_hw_ops
->hw_get_mac_temp
)
53 if (aq_nic
->aq_fw_ops
->get_mac_temp
)
54 err
= aq_nic
->aq_fw_ops
->get_mac_temp(aq_nic
->aq_hw
, &temp
);
56 err
= aq_nic
->aq_hw_ops
->hw_get_mac_temp(aq_nic
->aq_hw
, &temp
);
66 static int aq_hwmon_read_string(struct device
*dev
,
67 enum hwmon_sensor_types type
,
68 u32 attr
, int channel
, const char **str
)
70 struct aq_nic_s
*aq_nic
= dev_get_drvdata(dev
);
75 if (type
!= hwmon_temp
|| attr
!= hwmon_temp_label
)
78 if (channel
< ARRAY_SIZE(atl_temp_label
))
79 *str
= atl_temp_label
[channel
];
86 static umode_t
aq_hwmon_is_visible(const void *data
,
87 enum hwmon_sensor_types type
,
88 u32 attr
, int channel
)
90 const struct aq_nic_s
*nic
= data
;
92 if (type
!= hwmon_temp
)
95 if (channel
== 0 && !nic
->aq_fw_ops
->get_phy_temp
)
97 else if (channel
== 1 && !nic
->aq_fw_ops
->get_mac_temp
&&
98 !nic
->aq_hw_ops
->hw_get_mac_temp
)
102 case hwmon_temp_input
:
103 case hwmon_temp_label
:
110 static const struct hwmon_ops aq_hwmon_ops
= {
111 .is_visible
= aq_hwmon_is_visible
,
112 .read
= aq_hwmon_read
,
113 .read_string
= aq_hwmon_read_string
,
116 static u32 aq_hwmon_temp_config
[] = {
117 HWMON_T_INPUT
| HWMON_T_LABEL
,
118 HWMON_T_INPUT
| HWMON_T_LABEL
,
122 static const struct hwmon_channel_info aq_hwmon_temp
= {
124 .config
= aq_hwmon_temp_config
,
127 static const struct hwmon_channel_info
*aq_hwmon_info
[] = {
132 static const struct hwmon_chip_info aq_hwmon_chip_info
= {
133 .ops
= &aq_hwmon_ops
,
134 .info
= aq_hwmon_info
,
137 int aq_drvinfo_init(struct net_device
*ndev
)
139 struct aq_nic_s
*aq_nic
= netdev_priv(ndev
);
140 struct device
*dev
= &aq_nic
->pdev
->dev
;
141 struct device
*hwmon_dev
;
144 hwmon_dev
= devm_hwmon_device_register_with_info(dev
,
150 if (IS_ERR(hwmon_dev
))
151 err
= PTR_ERR(hwmon_dev
);
157 int aq_drvinfo_init(struct net_device
*ndev
) { return 0; }