/* * capab.c * * Created on: Dec 1, 2016 * Author: jklug * * capabilities from EE-PROM, enumerated in /sys/devices/platform/mts-io/capability * an associative array, written the hard way in C. */ /* This array is not in any order. */ struct capab_map_s { unsigned int bitvalue; const char *name; }; /* * 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_WIFI_BT, "wifi_bt"}, { CAPA_GNSS, "gnss"}, { 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;iattr.name)) { return snprintf(buf, 32, "%u\n", DEVICE_CAPA(id_eeprom.capa, capabilities_map[i].bitvalue) != 0); } } 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;ishow = capab_show_value; attrs[i] = &kobj_attr->attr; } return true; }