Skip to content

Commit 847da8b

Browse files
Kalesh APdavem330
authored andcommitted
bnxt_en: Modify the driver to use hwmon_device_register_with_info
The use of hwmon_device_register_with_groups() is deprecated. Modified the driver to use hwmon_device_register_with_info(). Driver currently exports only temp1_input through hwmon sysfs interface. But FW has been modified to report more threshold temperatures and driver want to report them through the hwmon interface. Cc: Jean Delvare <[email protected]> Cc: Guenter Roeck <[email protected]> Cc: [email protected] Signed-off-by: Kalesh AP <[email protected]> Signed-off-by: Michael Chan <[email protected]> Acked-by: Guenter Roeck <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent a47f3b3 commit 847da8b

File tree

1 file changed

+55
-16
lines changed

1 file changed

+55
-16
lines changed

drivers/net/ethernet/broadcom/bnxt/bnxt_hwmon.c

Lines changed: 55 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,34 +18,73 @@
1818
#include "bnxt_hwrm.h"
1919
#include "bnxt_hwmon.h"
2020

21-
static ssize_t bnxt_show_temp(struct device *dev,
22-
struct device_attribute *devattr, char *buf)
21+
static int bnxt_hwrm_temp_query(struct bnxt *bp, u8 *temp)
2322
{
2423
struct hwrm_temp_monitor_query_output *resp;
2524
struct hwrm_temp_monitor_query_input *req;
26-
struct bnxt *bp = dev_get_drvdata(dev);
27-
u32 len = 0;
2825
int rc;
2926

3027
rc = hwrm_req_init(bp, req, HWRM_TEMP_MONITOR_QUERY);
3128
if (rc)
3229
return rc;
3330
resp = hwrm_req_hold(bp, req);
34-
rc = hwrm_req_send(bp, req);
35-
if (!rc)
36-
len = sprintf(buf, "%u\n", resp->temp * 1000); /* display millidegree */
37-
hwrm_req_drop(bp, req);
31+
rc = hwrm_req_send_silent(bp, req);
3832
if (rc)
33+
goto drop_req;
34+
35+
*temp = resp->temp;
36+
37+
drop_req:
38+
hwrm_req_drop(bp, req);
39+
return rc;
40+
}
41+
42+
static umode_t bnxt_hwmon_is_visible(const void *_data, enum hwmon_sensor_types type,
43+
u32 attr, int channel)
44+
{
45+
if (type != hwmon_temp)
46+
return 0;
47+
48+
switch (attr) {
49+
case hwmon_temp_input:
50+
return 0444;
51+
default:
52+
return 0;
53+
}
54+
}
55+
56+
static int bnxt_hwmon_read(struct device *dev, enum hwmon_sensor_types type, u32 attr,
57+
int channel, long *val)
58+
{
59+
struct bnxt *bp = dev_get_drvdata(dev);
60+
u8 temp = 0;
61+
int rc;
62+
63+
switch (attr) {
64+
case hwmon_temp_input:
65+
rc = bnxt_hwrm_temp_query(bp, &temp);
66+
if (!rc)
67+
*val = temp * 1000;
3968
return rc;
40-
return len;
69+
default:
70+
return -EOPNOTSUPP;
71+
}
4172
}
42-
static SENSOR_DEVICE_ATTR(temp1_input, 0444, bnxt_show_temp, NULL, 0);
4373

44-
static struct attribute *bnxt_attrs[] = {
45-
&sensor_dev_attr_temp1_input.dev_attr.attr,
74+
static const struct hwmon_channel_info *bnxt_hwmon_info[] = {
75+
HWMON_CHANNEL_INFO(temp, HWMON_T_INPUT),
4676
NULL
4777
};
48-
ATTRIBUTE_GROUPS(bnxt);
78+
79+
static const struct hwmon_ops bnxt_hwmon_ops = {
80+
.is_visible = bnxt_hwmon_is_visible,
81+
.read = bnxt_hwmon_read,
82+
};
83+
84+
static const struct hwmon_chip_info bnxt_hwmon_chip_info = {
85+
.ops = &bnxt_hwmon_ops,
86+
.info = bnxt_hwmon_info,
87+
};
4988

5089
void bnxt_hwmon_uninit(struct bnxt *bp)
5190
{
@@ -72,9 +111,9 @@ void bnxt_hwmon_init(struct bnxt *bp)
72111
if (bp->hwmon_dev)
73112
return;
74113

75-
bp->hwmon_dev = hwmon_device_register_with_groups(&pdev->dev,
76-
DRV_MODULE_NAME, bp,
77-
bnxt_groups);
114+
bp->hwmon_dev = hwmon_device_register_with_info(&pdev->dev,
115+
DRV_MODULE_NAME, bp,
116+
&bnxt_hwmon_chip_info, NULL);
78117
if (IS_ERR(bp->hwmon_dev)) {
79118
bp->hwmon_dev = NULL;
80119
dev_warn(&pdev->dev, "Cannot register hwmon device\n");

0 commit comments

Comments
 (0)