Skip to content

Commit 626e910

Browse files
committed
iio.h: Add function iio_device_is_hwmon()
This function can be used to detect if a given device is a hardware monitoring device, or a IIO device. Signed-off-by: Paul Cercueil <[email protected]>
1 parent 145b322 commit 626e910

File tree

4 files changed

+19
-12
lines changed

4 files changed

+19
-12
lines changed

channel.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ void iio_channel_init_finalize(struct iio_channel *chn)
177177
char *mod;
178178
int type;
179179

180-
if (iio_device_is_hwmon(chn->dev)) {
180+
if (WITH_HWMON && iio_device_is_hwmon(chn->dev)) {
181181
type = iio_channel_find_type(chn->id, hwmon_chan_type_name_spec,
182182
ARRAY_SIZE(hwmon_chan_type_name_spec));
183183
} else {

iio-private.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,4 @@ static inline void iio_update_xml_indexes(ssize_t ret, char **ptr, ssize_t *len,
291291

292292
bool iio_channel_is_hwmon(const char *id);
293293

294-
static inline bool iio_device_is_hwmon(const struct iio_device *dev)
295-
{
296-
return WITH_HWMON && dev->id[0] == 'h';
297-
}
298-
299294
#endif /* __IIO_PRIVATE_H__ */

iio.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,6 +1620,18 @@ hwmon_channel_get_type(const struct iio_channel *chn)
16201620
return (enum hwmon_chan_type) iio_channel_get_type(chn);
16211621
}
16221622

1623+
/**
1624+
* @brief Get whether or not the device is a hardware monitoring device
1625+
* @param dev A pointer to an iio_device structure
1626+
* @return True if the device is a hardware monitoring device,
1627+
* false if it is a IIO device */
1628+
static inline bool iio_device_is_hwmon(const struct iio_device *dev)
1629+
{
1630+
const char *id = iio_device_get_id(dev);
1631+
1632+
return id[0] == 'h';
1633+
}
1634+
16231635

16241636
/** @} *//* ------------------------------------------------------------------*/
16251637
/* ------------------------- Low-level functions -----------------------------*/

local.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ static ssize_t local_read_dev_attr(const struct iio_device *dev,
676676

677677
switch (type) {
678678
case IIO_ATTR_TYPE_DEVICE:
679-
if (iio_device_is_hwmon(dev)) {
679+
if (WITH_HWMON && iio_device_is_hwmon(dev)) {
680680
iio_snprintf(buf, sizeof(buf), "/sys/class/hwmon/%s/%s",
681681
dev->id, attr);
682682
} else {
@@ -730,7 +730,7 @@ static ssize_t local_write_dev_attr(const struct iio_device *dev,
730730

731731
switch (type) {
732732
case IIO_ATTR_TYPE_DEVICE:
733-
if (iio_device_is_hwmon(dev)) {
733+
if (WITH_HWMON && iio_device_is_hwmon(dev)) {
734734
iio_snprintf(buf, sizeof(buf), "/sys/class/hwmon/%s/%s",
735735
dev->id, attr);
736736
} else {
@@ -1144,7 +1144,7 @@ static bool is_channel(const struct iio_device *dev, const char *attr, bool stri
11441144
{
11451145
char *ptr = NULL;
11461146

1147-
if (iio_device_is_hwmon(dev))
1147+
if (WITH_HWMON && iio_device_is_hwmon(dev))
11481148
return iio_channel_is_hwmon(attr);
11491149
if (!strncmp(attr, "in_timestamp_", sizeof("in_timestamp_") - 1))
11501150
return true;
@@ -1169,7 +1169,7 @@ static char * get_channel_id(struct iio_device *dev, const char *attr)
11691169
char *res, *ptr = strchr(attr, '_');
11701170
size_t len;
11711171

1172-
if (!iio_device_is_hwmon(dev)) {
1172+
if (!WITH_HWMON || !iio_device_is_hwmon(dev)) {
11731173
attr = ptr + 1;
11741174
ptr = strchr(attr, '_');
11751175
if (find_channel_modifier(ptr + 1, &len) != IIO_NO_MOD)
@@ -1196,7 +1196,7 @@ static char * get_short_attr_name(struct iio_channel *chn, const char *attr)
11961196
char *ptr = strchr(attr, '_');
11971197
size_t len;
11981198

1199-
if (iio_device_is_hwmon(chn->dev)) {
1199+
if (WITH_HWMON && iio_device_is_hwmon(chn->dev)) {
12001200
/*
12011201
* PWM hwmon devices can have an attribute named directly after
12021202
* the channel's ID; in that particular case we don't need to
@@ -1457,7 +1457,7 @@ static struct iio_channel *create_channel(struct iio_device *dev,
14571457
if (!chn->pdata)
14581458
goto err_free_chn;
14591459

1460-
if (!iio_device_is_hwmon(dev)) {
1460+
if (!WITH_HWMON || !iio_device_is_hwmon(dev)) {
14611461
if (!strncmp(attr, "out_", 4)) {
14621462
chn->is_output = true;
14631463
} else if (strncmp(attr, "in_", 3)) {

0 commit comments

Comments
 (0)