Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

misc: amd-sbi: Move hwmon device sensor as separate entity

- Move hwmon device sensor to misc as only power is reported through
hwmon sensor.

Reviewed-by: Naveen Krishna Chatradhi <naveenkrishna.chatradhi@amd.com>
Signed-off-by: Akshay Gupta <akshay.gupta@amd.com>
Link: https://lore.kernel.org/r/20250428063034.2145566-4-akshay.gupta@amd.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Akshay Gupta and committed by
Greg Kroah-Hartman
f4dc6406 43470595

+142 -104
+9 -1
drivers/misc/amd-sbi/Kconfig
··· 2 2 config AMD_SBRMI_I2C 3 3 tristate "AMD side band RMI support" 4 4 depends on I2C 5 - depends on HWMON 6 5 help 7 6 Side band RMI over I2C support for AMD out of band management. 8 7 9 8 This driver can also be built as a module. If so, the module will 10 9 be called sbrmi-i2c. 10 + 11 + config AMD_SBRMI_HWMON 12 + bool "SBRMI hardware monitoring" 13 + depends on AMD_SBRMI_I2C && HWMON 14 + depends on !(AMD_SBRMI_I2C=y && HWMON=m) 15 + help 16 + This provides support for RMI device hardware monitoring. If enabled, 17 + a hardware monitoring device will be created for each socket in 18 + the system.
+2 -1
drivers/misc/amd-sbi/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0-only 2 - sbrmi-i2c-objs := rmi-i2c.o rmi-core.o 2 + sbrmi-i2c-objs += rmi-i2c.o rmi-core.o 3 + sbrmi-i2c-$(CONFIG_AMD_SBRMI_HWMON) += rmi-hwmon.o 3 4 obj-$(CONFIG_AMD_SBRMI_I2C) += sbrmi-i2c.o
+8
drivers/misc/amd-sbi/rmi-core.h
··· 60 60 }; 61 61 62 62 int rmi_mailbox_xfer(struct sbrmi_data *data, struct sbrmi_mailbox_msg *msg); 63 + #ifdef CONFIG_AMD_SBRMI_HWMON 64 + int create_hwmon_sensor_device(struct device *dev, struct sbrmi_data *data); 65 + #else 66 + static inline int create_hwmon_sensor_device(struct device *dev, struct sbrmi_data *data) 67 + { 68 + return 0; 69 + } 70 + #endif 63 71 #endif /*_SBRMI_CORE_H_*/
+121
drivers/misc/amd-sbi/rmi-hwmon.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-or-later 2 + /* 3 + * rmi-hwmon.c - hwmon sensor support for side band RMI 4 + * 5 + * Copyright (C) 2025 Advanced Micro Devices, Inc. 6 + */ 7 + #include <linux/err.h> 8 + #include <linux/hwmon.h> 9 + #include "rmi-core.h" 10 + 11 + /* Do not allow setting negative power limit */ 12 + #define SBRMI_PWR_MIN 0 13 + 14 + static int sbrmi_read(struct device *dev, enum hwmon_sensor_types type, 15 + u32 attr, int channel, long *val) 16 + { 17 + struct sbrmi_data *data = dev_get_drvdata(dev); 18 + struct sbrmi_mailbox_msg msg = { 0 }; 19 + int ret; 20 + 21 + if (!data) 22 + return -ENODEV; 23 + 24 + if (type != hwmon_power) 25 + return -EINVAL; 26 + 27 + msg.read = true; 28 + switch (attr) { 29 + case hwmon_power_input: 30 + msg.cmd = SBRMI_READ_PKG_PWR_CONSUMPTION; 31 + ret = rmi_mailbox_xfer(data, &msg); 32 + break; 33 + case hwmon_power_cap: 34 + msg.cmd = SBRMI_READ_PKG_PWR_LIMIT; 35 + ret = rmi_mailbox_xfer(data, &msg); 36 + break; 37 + case hwmon_power_cap_max: 38 + msg.data_out = data->pwr_limit_max; 39 + ret = 0; 40 + break; 41 + default: 42 + return -EINVAL; 43 + } 44 + if (ret < 0) 45 + return ret; 46 + /* hwmon power attributes are in microWatt */ 47 + *val = (long)msg.data_out * 1000; 48 + return ret; 49 + } 50 + 51 + static int sbrmi_write(struct device *dev, enum hwmon_sensor_types type, 52 + u32 attr, int channel, long val) 53 + { 54 + struct sbrmi_data *data = dev_get_drvdata(dev); 55 + struct sbrmi_mailbox_msg msg = { 0 }; 56 + 57 + if (!data) 58 + return -ENODEV; 59 + 60 + if (type != hwmon_power && attr != hwmon_power_cap) 61 + return -EINVAL; 62 + /* 63 + * hwmon power attributes are in microWatt 64 + * mailbox read/write is in mWatt 65 + */ 66 + val /= 1000; 67 + 68 + val = clamp_val(val, SBRMI_PWR_MIN, data->pwr_limit_max); 69 + 70 + msg.cmd = SBRMI_WRITE_PKG_PWR_LIMIT; 71 + msg.data_in = val; 72 + msg.read = false; 73 + 74 + return rmi_mailbox_xfer(data, &msg); 75 + } 76 + 77 + static umode_t sbrmi_is_visible(const void *data, 78 + enum hwmon_sensor_types type, 79 + u32 attr, int channel) 80 + { 81 + switch (type) { 82 + case hwmon_power: 83 + switch (attr) { 84 + case hwmon_power_input: 85 + case hwmon_power_cap_max: 86 + return 0444; 87 + case hwmon_power_cap: 88 + return 0644; 89 + } 90 + break; 91 + default: 92 + break; 93 + } 94 + return 0; 95 + } 96 + 97 + static const struct hwmon_channel_info * const sbrmi_info[] = { 98 + HWMON_CHANNEL_INFO(power, 99 + HWMON_P_INPUT | HWMON_P_CAP | HWMON_P_CAP_MAX), 100 + NULL 101 + }; 102 + 103 + static const struct hwmon_ops sbrmi_hwmon_ops = { 104 + .is_visible = sbrmi_is_visible, 105 + .read = sbrmi_read, 106 + .write = sbrmi_write, 107 + }; 108 + 109 + static const struct hwmon_chip_info sbrmi_chip_info = { 110 + .ops = &sbrmi_hwmon_ops, 111 + .info = sbrmi_info, 112 + }; 113 + 114 + int create_hwmon_sensor_device(struct device *dev, struct sbrmi_data *data) 115 + { 116 + struct device *hwmon_dev; 117 + 118 + hwmon_dev = devm_hwmon_device_register_with_info(dev, "sbrmi", data, 119 + &sbrmi_chip_info, NULL); 120 + return PTR_ERR_OR_ZERO(hwmon_dev); 121 + }
+2 -102
drivers/misc/amd-sbi/rmi-i2c.c
··· 8 8 9 9 #include <linux/delay.h> 10 10 #include <linux/err.h> 11 - #include <linux/hwmon.h> 12 11 #include <linux/i2c.h> 13 12 #include <linux/init.h> 14 13 #include <linux/module.h> 15 14 #include <linux/mutex.h> 16 15 #include <linux/of.h> 17 16 #include "rmi-core.h" 18 - 19 - /* Do not allow setting negative power limit */ 20 - #define SBRMI_PWR_MIN 0 21 17 22 18 static int sbrmi_enable_alert(struct i2c_client *client) 23 19 { ··· 36 40 return 0; 37 41 } 38 42 39 - static int sbrmi_read(struct device *dev, enum hwmon_sensor_types type, 40 - u32 attr, int channel, long *val) 41 - { 42 - struct sbrmi_data *data = dev_get_drvdata(dev); 43 - struct sbrmi_mailbox_msg msg = { 0 }; 44 - int ret; 45 - 46 - if (type != hwmon_power) 47 - return -EINVAL; 48 - 49 - msg.read = true; 50 - switch (attr) { 51 - case hwmon_power_input: 52 - msg.cmd = SBRMI_READ_PKG_PWR_CONSUMPTION; 53 - ret = rmi_mailbox_xfer(data, &msg); 54 - break; 55 - case hwmon_power_cap: 56 - msg.cmd = SBRMI_READ_PKG_PWR_LIMIT; 57 - ret = rmi_mailbox_xfer(data, &msg); 58 - break; 59 - case hwmon_power_cap_max: 60 - msg.data_out = data->pwr_limit_max; 61 - ret = 0; 62 - break; 63 - default: 64 - return -EINVAL; 65 - } 66 - if (ret < 0) 67 - return ret; 68 - /* hwmon power attributes are in microWatt */ 69 - *val = (long)msg.data_out * 1000; 70 - return ret; 71 - } 72 - 73 - static int sbrmi_write(struct device *dev, enum hwmon_sensor_types type, 74 - u32 attr, int channel, long val) 75 - { 76 - struct sbrmi_data *data = dev_get_drvdata(dev); 77 - struct sbrmi_mailbox_msg msg = { 0 }; 78 - 79 - if (type != hwmon_power && attr != hwmon_power_cap) 80 - return -EINVAL; 81 - /* 82 - * hwmon power attributes are in microWatt 83 - * mailbox read/write is in mWatt 84 - */ 85 - val /= 1000; 86 - 87 - val = clamp_val(val, SBRMI_PWR_MIN, data->pwr_limit_max); 88 - 89 - msg.cmd = SBRMI_WRITE_PKG_PWR_LIMIT; 90 - msg.data_in = val; 91 - msg.read = false; 92 - 93 - return rmi_mailbox_xfer(data, &msg); 94 - } 95 - 96 - static umode_t sbrmi_is_visible(const void *data, 97 - enum hwmon_sensor_types type, 98 - u32 attr, int channel) 99 - { 100 - switch (type) { 101 - case hwmon_power: 102 - switch (attr) { 103 - case hwmon_power_input: 104 - case hwmon_power_cap_max: 105 - return 0444; 106 - case hwmon_power_cap: 107 - return 0644; 108 - } 109 - break; 110 - default: 111 - break; 112 - } 113 - return 0; 114 - } 115 - 116 - static const struct hwmon_channel_info * const sbrmi_info[] = { 117 - HWMON_CHANNEL_INFO(power, 118 - HWMON_P_INPUT | HWMON_P_CAP | HWMON_P_CAP_MAX), 119 - NULL 120 - }; 121 - 122 - static const struct hwmon_ops sbrmi_hwmon_ops = { 123 - .is_visible = sbrmi_is_visible, 124 - .read = sbrmi_read, 125 - .write = sbrmi_write, 126 - }; 127 - 128 - static const struct hwmon_chip_info sbrmi_chip_info = { 129 - .ops = &sbrmi_hwmon_ops, 130 - .info = sbrmi_info, 131 - }; 132 - 133 43 static int sbrmi_get_max_pwr_limit(struct sbrmi_data *data) 134 44 { 135 45 struct sbrmi_mailbox_msg msg = { 0 }; ··· 54 152 static int sbrmi_i2c_probe(struct i2c_client *client) 55 153 { 56 154 struct device *dev = &client->dev; 57 - struct device *hwmon_dev; 58 155 struct sbrmi_data *data; 59 156 int ret; 60 157 ··· 74 173 if (ret < 0) 75 174 return ret; 76 175 77 - hwmon_dev = devm_hwmon_device_register_with_info(dev, client->name, data, 78 - &sbrmi_chip_info, NULL); 79 - return PTR_ERR_OR_ZERO(hwmon_dev); 176 + dev_set_drvdata(dev, data); 177 + return create_hwmon_sensor_device(dev, data); 80 178 } 81 179 82 180 static const struct i2c_device_id sbrmi_id[] = {