GTA04: Added power handlers and fixed transport handlers
authorPaul Kocialkowski <contact@paulk.fr>
Wed, 1 Aug 2012 14:05:23 +0000 (16:05 +0200)
committerPaul Kocialkowski <contact@paulk.fr>
Wed, 1 Aug 2012 14:05:23 +0000 (16:05 +0200)
Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
device/gta04/gta04.c
device/gta04/gta04.h

index 86a7968..64a9aae 100644 (file)
 #include "gta04.h"
 #include <hayes-ril.h>
 
-int gta04_power_boot(void *sdata)
+int gta04_power_count_nodes(void)
 {
        struct stat tty_node_stat;
-       char *tty_node;
+       char *tty_node = NULL;
+       int tty_nodes_count = 0;
        int rc;
        int i;
 
+       // Count how many nodes are available
        for(i=0 ; i < TTY_NODE_MAX ; i++) {
                asprintf(&tty_node, "%s/%s%d", TTY_DEV_BASE, TTY_NODE_BASE, i);
 
                rc = stat(tty_node, &tty_node_stat);
-               if(rc < 0) {
-                       free(tty_node);
+               if(rc == 0)
+                       tty_nodes_count++;
+
+               free(tty_node);
+       }
+
+       return tty_nodes_count;
+}
+
+int gta04_power_on(void *sdata)
+{
+       char gpio_sysfs_value[] = "1\n";
+       int tty_nodes_count;
+       int fd;
+
+       tty_nodes_count = gta04_power_count_nodes();
+       if(tty_nodes_count < 2) {
+               LOGD("Powering modem on");
+
+               fd = open(GPIO_SYSFS, O_RDWR);
+               if(fd < 0) {
+                       LOGE("Unable to open GPIO SYSFS node, modem will stay off");
                        return -1;
                }
 
-               free(tty_node);
+               write(fd, gpio_sysfs_value, strlen(gpio_sysfs_value));
+               sleep(1);
+
+               return 0;
+       }
+
+       LOGD("Modem is already on");
+       return 0;
+}
+
+int gta04_power_off(void *sdata)
+{
+       char gpio_sysfs_value_0[] = "0\n";
+       char gpio_sysfs_value_1[] = "1\n";
+       int tty_nodes_count;
+       int fd;
+
+       tty_nodes_count = gta04_power_count_nodes();
+       if(tty_nodes_count > 0) {
+               LOGD("Powering modem off");
+
+               fd = open(GPIO_SYSFS, O_RDWR);
+               if(fd < 0) {
+                       LOGE("Unable to open GPIO SYSFS node, modem will stay on");
+                       return -1;
+               }
+
+               write(fd, gpio_sysfs_value_0, strlen(gpio_sysfs_value_0));
+               usleep(500);
+               write(fd, gpio_sysfs_value_1, strlen(gpio_sysfs_value_1));
+               usleep(500);
+               write(fd, gpio_sysfs_value_0, strlen(gpio_sysfs_value_0));
+               sleep(1);
+
+               return 0;
+       }
+
+       LOGD("Modem is already off");
+       return 0;
+}
+
+int gta04_power_boot(void *sdata)
+{
+       int tty_nodes_count;
+
+       tty_nodes_count = gta04_power_count_nodes();
+       if(tty_nodes_count < 2) {
+               // We need at least Modem and Application
+               LOGE("Not enough modem nodes available!");
+               return -1;
        }
 
        return 0;
@@ -64,10 +135,8 @@ int gta04_transport_sdata_create(void **sdata)
 
 int gta04_transport_sdata_destroy(void *sdata)
 {
-       if(sdata == NULL)
-               return 0;
-
-       free(sdata);
+       if(sdata != NULL)
+               free(sdata);
 
        return 0;
 }
@@ -369,8 +438,8 @@ struct ril_device_power_handlers gta04_power_handlers = {
        .sdata = NULL,
        .sdata_create = gta04_dummy,
        .sdata_destroy = gta04_dummy,
-       .power_on = gta04_dummy,
-       .power_off = gta04_dummy,
+       .power_on = gta04_power_on,
+       .power_off = gta04_power_off,
        .suspend = gta04_dummy,
        .resume = gta04_dummy,
        .boot = gta04_power_boot,
@@ -394,6 +463,7 @@ struct ril_device_handlers gta04_handlers = {
 
 struct ril_device gta04_device = {
        .name = "Goldelico GTA04",
+       .tag = "GTA04",
        .type = DEV_GSM,
        .sdata = NULL,
        .handlers = &gta04_handlers,
index cf82c20..e5c309f 100644 (file)
@@ -25,7 +25,8 @@
 #define TTY_DEV_BASE   "/dev"
 #define TTY_HSOTYPE    "hsotype"
 #define TTY_NODE_BASE  "ttyHS"
-#define TTY_NODE_MAX   6
+#define TTY_NODE_MAX   6 * 6
+#define GPIO_SYSFS     "/sys/class/gpio/gpio186/value"
 
 #define RECV_BYTES_MAX 0x1000