summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMykyta Dorokhin <mykyta.dorokhin@globallogic.com>2016-12-06 15:21:25 +0200
committerBrandon Bayer <bbayer@multitech.com>2016-12-06 09:54:18 -0600
commitefa9ca1dad49be7f53220a2cd0342b4238f653a6 (patch)
tree760adde270a8f737341aa2e9f6999655d4dfe686
parentab76db18c883b9b8eec3976e2cf6c5904b3ccd93 (diff)
downloadmts-io-efa9ca1dad49be7f53220a2cd0342b4238f653a6.tar.gz
mts-io-efa9ca1dad49be7f53220a2cd0342b4238f653a6.tar.bz2
mts-io-efa9ca1dad49be7f53220a2cd0342b4238f653a6.zip
mtcap: fix build + refactoring.1.5.7
-rw-r--r--io-module/mts_capab.c80
-rw-r--r--io-module/mts_eeprom.h1
-rw-r--r--io-module/mts_io.c28
-rwxr-xr-xio-tool/mts-io-sysfs3
4 files changed, 65 insertions, 47 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;
}
diff --git a/io-module/mts_eeprom.h b/io-module/mts_eeprom.h
index ec82e0d..4e15f8c 100644
--- a/io-module/mts_eeprom.h
+++ b/io-module/mts_eeprom.h
@@ -55,7 +55,6 @@ do { \
#define DEVICE_CAPA_VALUE(index, bit) ((((index) & 0x1F) << 3) | ((bit) & 0x07))
-#define CAPA_COUNT 7 // See also attribute_names in capab.c
#define CAPA_GPS DEVICE_CAPA_VALUE(0, 7)
#define CAPA_DIN DEVICE_CAPA_VALUE(0, 6)
#define CAPA_DOUT DEVICE_CAPA_VALUE(0, 5)
diff --git a/io-module/mts_io.c b/io-module/mts_io.c
index 33fee4f..284ab7e 100644
--- a/io-module/mts_io.c
+++ b/io-module/mts_io.c
@@ -47,7 +47,7 @@
#include "mts_io.h"
-#define DRIVER_VERSION "v1.5.6"
+#define DRIVER_VERSION "v1.5.7"
#define DRIVER_AUTHOR "James Maki <jmaki@multitech.com>"
#define DRIVER_DESC "MTS-IO Controller"
#define DRIVER_NAME "mts-io"
@@ -641,6 +641,9 @@ static DEVICE_ATTR_RO_MTS(dev_attr_eth_mac, "mac-eth",
#include "mtcdt.c"
#include "mtcap.c"
+/* include capabilities sub-directory support */
+#include "mts_capab.c"
+
#if NUM_AP > 0
@@ -653,8 +656,6 @@ static struct kobject *ap_subdirs[NUM_AP];
static struct attribute_group ap_attr_groups[NUM_AP];
/* info for accessory port (contains function pointers for setup and teardown and and useful info) */
static struct ap_info* port_info[NUM_AP];
-static struct kobject *capab;
-static struct attribute_group capab_group;
/* accessory card support */
#include "mtac.c"
@@ -662,7 +663,6 @@ static struct attribute_group capab_group;
#include "mtac_mfser.c"
#include "mtac_eth.c"
#include "mtac_lora.c"
-#include "mts_capab.c"
static bool load_port(int port) {
int port_index = port - 1;
@@ -936,8 +936,7 @@ static void cleanup(void)
freelater = NULL;
}
- if(capab_group.attrs)
- kfree((struct kobject *)capab_group.attrs);
+ mts_capab_dir_delete();
}
static int __init mts_io_init(void)
@@ -968,21 +967,10 @@ static int __init mts_io_init(void)
init_ports();
- capab = kobject_create_and_add("capability", &mts_io_platform_device->dev.kobj);
- if (capab == NULL) {
- log_error("kobject_create_and_add for capability directory failed");
- return false;
- }
-
- capab_group.attrs = kzalloc(sizeof(struct attribute*) * (capabilities_count+1), GFP_KERNEL);
- if (! capab_add_attributes(capab_group.attrs)) {
- return false;
- }
-
- if (sysfs_create_group(capab, &capab_group)) {
+ ret = mts_capab_dir_create();
+ if (ret) {
cleanup();
- log_error("sysfs_create_group failed to create capability group");
- return false;
+ return ret;
}
ret = sysfs_create_group(&mts_io_platform_device->dev.kobj, attr_group);
diff --git a/io-tool/mts-io-sysfs b/io-tool/mts-io-sysfs
index 55b5087..a7f7455 100755
--- a/io-tool/mts-io-sysfs
+++ b/io-tool/mts-io-sysfs
@@ -122,6 +122,9 @@ usage() {
#imei is read-only
imei )
;;
+ #capabilities are read-only
+ capability/* )
+ ;;
radio-reset-backoff-seconds )
;;
modalias )