in hid-sensor-custom.c [276:382]
static ssize_t show_value(struct device *dev, struct device_attribute *attr,
char *buf)
{
struct hid_sensor_custom *sensor_inst = dev_get_drvdata(dev);
struct hid_sensor_hub_attribute_info *attribute;
int index, usage, field_index;
char name[HID_CUSTOM_NAME_LENGTH];
bool feature = false;
bool input = false;
int value = 0;
if (sscanf(attr->attr.name, "feature-%x-%x-%s", &index, &usage,
name) == 3) {
feature = true;
field_index = index + sensor_inst->input_field_count;
} else if (sscanf(attr->attr.name, "input-%x-%x-%s", &index, &usage,
name) == 3) {
input = true;
field_index = index;
} else
return -EINVAL;
if (!strncmp(name, "value", strlen("value"))) {
u32 report_id;
int ret;
attribute = &sensor_inst->fields[field_index].attribute;
report_id = attribute->report_id;
if (feature) {
u8 values[HID_CUSTOM_MAX_FEATURE_BYTES];
int len = 0;
u64 value = 0;
int i = 0;
ret = sensor_hub_get_feature(sensor_inst->hsdev,
report_id,
index,
sizeof(values), values);
if (ret < 0)
return ret;
while (i < ret) {
if (i + attribute->size > ret) {
len += scnprintf(&buf[len],
PAGE_SIZE - len,
"%d ", values[i]);
break;
}
switch (attribute->size) {
case 2:
value = (u64) *(u16 *)&values[i];
i += attribute->size;
break;
case 4:
value = (u64) *(u32 *)&values[i];
i += attribute->size;
break;
case 8:
value = *(u64 *)&values[i];
i += attribute->size;
break;
default:
value = (u64) values[i];
++i;
break;
}
len += scnprintf(&buf[len], PAGE_SIZE - len,
"%lld ", value);
}
len += scnprintf(&buf[len], PAGE_SIZE - len, "\n");
return len;
} else if (input)
value = sensor_hub_input_attr_get_raw_value(
sensor_inst->hsdev,
sensor_inst->hsdev->usage,
usage, report_id,
SENSOR_HUB_SYNC, false);
} else if (!strncmp(name, "units", strlen("units")))
value = sensor_inst->fields[field_index].attribute.units;
else if (!strncmp(name, "unit-expo", strlen("unit-expo")))
value = sensor_inst->fields[field_index].attribute.unit_expo;
else if (!strncmp(name, "size", strlen("size")))
value = sensor_inst->fields[field_index].attribute.size;
else if (!strncmp(name, "minimum", strlen("minimum")))
value = sensor_inst->fields[field_index].attribute.
logical_minimum;
else if (!strncmp(name, "maximum", strlen("maximum")))
value = sensor_inst->fields[field_index].attribute.
logical_maximum;
else if (!strncmp(name, "name", strlen("name"))) {
struct hid_custom_usage_desc *usage_desc;
usage_desc = bsearch(&usage, hid_custom_usage_desc_table,
ARRAY_SIZE(hid_custom_usage_desc_table),
sizeof(struct hid_custom_usage_desc),
usage_id_cmp);
if (usage_desc)
return snprintf(buf, PAGE_SIZE, "%s\n",
usage_desc->desc);
else
return sprintf(buf, "not-specified\n");
} else
return -EINVAL;
return sprintf(buf, "%d\n", value);
}