diff options
Diffstat (limited to 'io-module/mts_capab.c')
-rw-r--r-- | io-module/mts_capab.c | 80 |
1 files changed, 54 insertions, 26 deletions
diff --git a/io-module/mts_capab.c b/io-module/mts_capab.c index e8e4a27..e4ddb6f 100644 --- a/io-module/mts_capab.c +++ b/io-module/mts_capab.c @@ -18,22 +18,21 @@ struct capab_map_s { * Should match mts_eeprom.h capabilities */ static struct capab_map_s capabilities_map[] = { - { CAPA_GPS, "gps"}, - { CAPA_DIN, "din"}, - { CAPA_DOUT, "dout"}, - { CAPA_ADC, "adc"}, - { CAPA_BLUETOOTH, "bluetooth"}, - { CAPA_WIFI, "wifi"}, - { CAPA_LORA, "lora"}, + { CAPA_GPS, "gps"}, + { CAPA_DIN, "din"}, + { CAPA_DOUT, "dout"}, + { CAPA_ADC, "adc"}, + { CAPA_BLUETOOTH, "bluetooth"}, + { CAPA_WIFI, "wifi"}, + { CAPA_LORA, "lora"}, }; -static const unsigned capabilities_count = sizeof(capabilities_map)/sizeof(capabilities_map[0]); static ssize_t capab_show_value(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { int i; const int count = sizeof(capabilities_map)/sizeof(capabilities_map[0]); - for(i=0;i<count;i++) { - if (! strcmp(capabilities_map[i].name, attr->attr.name)) { + for (i = 0; i < count; i++) { + if (strcmp(capabilities_map[i].name, attr->attr.name) == 0) { return snprintf(buf, 32, "%u\n", DEVICE_CAPA(id_eeprom.capa, capabilities_map[i].bitvalue) != 0); } } @@ -41,21 +40,50 @@ static ssize_t capab_show_value(struct kobject *kobj, struct kobj_attribute *att return (ssize_t)-1; } -static bool capab_add_attributes(struct attribute** attrs) { - struct kobj_attribute* kobj_attr; - int i; - int count = capabilities_count; - - // We must keep the number of attributes in sync - BUG_ON(CAPA_COUNT != count); - for(i=0;i<count;i++) { - kobj_attr = create_attribute(capabilities_map[i].name, MTS_ATTR_MODE_RO); - if (! kobj_attr) { - log_error("failed to create attribute [%s]", capabilities_map[i].name); - return false; - } - kobj_attr->show = capab_show_value; - attrs[i] = &kobj_attr->attr; +static DEVICE_ATTR_RO_MTS(capa_attr_gps, "gps", capab_show_value); +static DEVICE_ATTR_RO_MTS(capa_attr_din, "din", capab_show_value); +static DEVICE_ATTR_RO_MTS(capa_attr_dout, "dout", capab_show_value); +static DEVICE_ATTR_RO_MTS(capa_attr_adc, "adc", capab_show_value); +static DEVICE_ATTR_RO_MTS(capa_attr_bt, "bluetooth", capab_show_value); +static DEVICE_ATTR_RO_MTS(capa_attr_wifi, "wifi", capab_show_value); +static DEVICE_ATTR_RO_MTS(capa_attr_lora, "lora", capab_show_value); + +static struct attribute *mts_capa_attributes[] = { + &capa_attr_gps.attr, + &capa_attr_din.attr, + &capa_attr_dout.attr, + &capa_attr_adc.attr, + &capa_attr_bt.attr, + &capa_attr_wifi.attr, + &capa_attr_lora.attr, + NULL, +}; + +static struct attribute_group mts_capa_attr_group = { + .attrs = mts_capa_attributes +}; + +static struct kobject *mts_capa_kobject = NULL; + +static int mts_capab_dir_create(void) +{ + mts_capa_kobject = kobject_create_and_add("capability", &mts_io_platform_device->dev.kobj); + if (!mts_capa_kobject) { + log_error("kobject_create_and_add for capability directory failed"); + return -ENOMEM; + } + + if (sysfs_create_group(mts_capa_kobject, &mts_capa_attr_group)) { + log_error("sysfs_create_group failed to create capability group"); + return -ENOMEM; + } + + return 0; +} + +static void mts_capab_dir_delete(void) +{ + if (mts_capa_kobject) { + kobject_put(mts_capa_kobject); } - return true; } |