summaryrefslogtreecommitdiff
path: root/io-module/mts_capab.c
diff options
context:
space:
mode:
Diffstat (limited to 'io-module/mts_capab.c')
-rw-r--r--io-module/mts_capab.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/io-module/mts_capab.c b/io-module/mts_capab.c
new file mode 100644
index 0000000..646f707
--- /dev/null
+++ b/io-module/mts_capab.c
@@ -0,0 +1,63 @@
+/*
+ * 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;i<count;i++) {
+ if (! strcmp(capabilities_map[i].name, attr->attr.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;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;
+ }
+ return true;
+}