Commit 53b17607 authored by Vaibhav Gupta's avatar Vaibhav Gupta

fixup! software: kernel: Use HWMON API to expose Temperature

parent 269e67b2
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
/* /*
* Author: Vaibhav Gupta <vaibhav.gupta@cern.ch> * Author: Vaibhav Gupta <vaibhav.gupta@cern.ch>
*
* Hardware Monitoring for fa-dev
*/ */
#include <linux/hwmon.h> #include <linux/hwmon.h>
...@@ -27,29 +29,13 @@ static int fa_hwmon_temp_read(struct device *dev, enum hwmon_sensor_types type, ...@@ -27,29 +29,13 @@ static int fa_hwmon_temp_read(struct device *dev, enum hwmon_sensor_types type,
return 0; return 0;
} }
static char *fa_hwmon_temp_sensor_id;
static int fa_hwmon_temp_sensor_id_read(struct device *dev, static int fa_hwmon_temp_sensor_id_read(struct device *dev,
enum hwmon_sensor_types type, enum hwmon_sensor_types type,
u32 attr, int channel, const char **str) u32 attr, int channel, const char **str)
{ {
int size;
char device_type[] = "Temperature - FMC ADC 100M14B4C - ";
struct fa_dev *fa = dev_get_drvdata(dev); struct fa_dev *fa = dev_get_drvdata(dev);
size = strlen(dev_name(&fa->slot->dev)); *str = fa->hwmon_temp_sensor_id;
size += strlen(device_type);
size++;
fa_hwmon_temp_sensor_id = kzalloc(size, GFP_KERNEL);
if(!fa_hwmon_temp_sensor_id)
return -ENOMEM;
snprintf(fa_hwmon_temp_sensor_id, size, "%s%s",
device_type, dev_name(&fa->slot->dev));
*str = fa_hwmon_temp_sensor_id;
return 0; return 0;
} }
...@@ -72,13 +58,34 @@ static const struct hwmon_chip_info fa_hwmon_temp_chip_info = { ...@@ -72,13 +58,34 @@ static const struct hwmon_chip_info fa_hwmon_temp_chip_info = {
int fa_hwmon_init(struct fa_dev *fa) int fa_hwmon_init(struct fa_dev *fa)
{ {
int size;
char device_type[] = "Temperature - FMC ADC 100M14B4C - ";
struct device *dev = &fa->pdev->dev; struct device *dev = &fa->pdev->dev;
fa->hwmon_dev = devm_hwmon_device_register_with_info(dev, fa->hwmon_dev = devm_hwmon_device_register_with_info(dev,
"fa_temperature", "fa_temperature",
fa, fa,
&fa_hwmon_temp_chip_info, &fa_hwmon_temp_chip_info,
NULL); NULL);
return PTR_ERR_OR_ZERO(fa->hwmon_dev); if(!IS_ERR(fa->hwmon_dev)) {
size = strlen(dev_name(&fa->slot->dev));
size += strlen(device_type);
size++;
fa->hwmon_temp_sensor_id = devm_kzalloc(fa->hwmon_dev,
size, GFP_KERNEL);
if(!fa->hwmon_temp_sensor_id) {
devm_hwmon_device_unregister(dev);
return -ENOMEM;
}
snprintf(fa->hwmon_temp_sensor_id, size, "%s%s",
device_type, dev_name(&fa->slot->dev));
return 0;
}
return PTR_ERR(fa->hwmon_dev);
} }
#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(5,10,0) */ #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(5,10,0) */
...@@ -345,9 +345,12 @@ struct fa_dev { ...@@ -345,9 +345,12 @@ struct fa_dev {
/* one-wire */ /* one-wire */
uint8_t ds18_id[8]; uint8_t ds18_id[8];
unsigned long next_t; unsigned long next_t;
struct device *hwmon_dev;
int temp; /* temperature: scaled by 4 bits */ int temp; /* temperature: scaled by 4 bits */
/* HWMON */
char *hwmon_temp_sensor_id;
struct device *hwmon_dev;
/* Calibration Data */ /* Calibration Data */
struct fa_calib calib; struct fa_calib calib;
int32_t range[FA100M14B4C_NCHAN]; int32_t range[FA100M14B4C_NCHAN];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment