Add hh2serial GPS support
authorMohamed Abbas <mohamed.abbas@intel.com>
Thu, 1 Apr 2010 21:13:18 +0000 (23:13 +0200)
committerSamuel Ortiz <sameo@linux.intel.com>
Thu, 1 Apr 2010 21:13:18 +0000 (23:13 +0200)
This patch brings the hh2serial GPS device on and off with offline mode
changes. Although this power control is currently done through sysfs
entries, this will be fixed once the hh2serial driver gets proper
rfkill support.

Makefile.am
Makefile.plugins
configure.ac
plugins/hh2serial-gps.c [new file with mode: 0644]

index 3edb790..e8d9b2c 100644 (file)
@@ -180,6 +180,7 @@ DISTCHECK_CONFIGURE_FLAGS = --disable-gtk-doc \
                                --enable-udev \
                                --enable-client \
                                --enable-portal \
+                               --enable-hh2serial-gps \
                                --enable-tools
 
 DISTCLEANFILES = $(pkgconfig_DATA)
index 2e04c2b..0748c3e 100644 (file)
@@ -54,6 +54,18 @@ plugins_bluetooth_la_LDFLAGS = $(plugin_ldflags)
 endif
 endif
 
+if HH2SERIAL_GPS
+if HH2SERIAL_GPS_BUILTIN
+builtin_modules += hh2serial_gps
+builtin_sources += plugins/hh2serial-gps.c
+else
+plugin_LTLIBRARIES += plugins/hh2serial-gps.la
+plugin_objects += $(plugins_hh2serial_gps_la_OBJECTS)
+plugins_hh2serial_gps_la_CFLAGS = $(plugin_cflags)
+plugins_hh2serial_gps_la_LDFLAGS = $(plugin_ldflags)
+endif
+endif
+
 if OFONO
 if OFONO_BUILTIN
 builtin_modules += ofono
index 6203b6d..a3fa54d 100644 (file)
@@ -86,6 +86,12 @@ AC_ARG_ENABLE(bluetooth,
 AM_CONDITIONAL(BLUETOOTH, test "${enable_bluetooth}" != "no")
 AM_CONDITIONAL(BLUETOOTH_BUILTIN, test "${enable_bluetooth}" = "builtin")
 
+AC_ARG_ENABLE(hh2serial-gps,
+        AC_HELP_STRING([--enable-hh2serial-gps], [enable hh2serial GPS support]),
+                        [enable_hh2serial_gps=${enableval}], [enable_hh2serial_gps="no"])
+AM_CONDITIONAL(HH2SERIAL_GPS, test "${enable_hh2serial_gps}" != "no")
+AM_CONDITIONAL(HH2SERIAL_GPS_BUILTIN, test "${enable_hh2serial_gps}" = "builtin")
+
 AC_ARG_ENABLE(ofono,
        AC_HELP_STRING([--enable-ofono], [enable oFono support]),
                        [enable_ofono=${enableval}], [enable_ofono="no"])
diff --git a/plugins/hh2serial-gps.c b/plugins/hh2serial-gps.c
new file mode 100644 (file)
index 0000000..245d1aa
--- /dev/null
@@ -0,0 +1,114 @@
+/*
+ *
+ *  hh2serial GPS
+ *
+ *  Copyright (C) 2007-2010  Intel Corporation. All rights reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <errno.h>
+
+#define CONNMAN_API_SUBJECT_TO_CHANGE
+#include <connman/plugin.h>
+#include <connman/device.h>
+#include <connman/log.h>
+
+static struct connman_device *hh2serial_device;
+
+static int set_reg(char *key, char *value)
+{
+       FILE *reg_file;
+
+       reg_file = fopen(key, "w");
+       if (!reg_file)
+               return -errno;
+
+       fprintf(reg_file, "%s", value);
+       fclose(reg_file);
+       return 0;
+}
+
+static int hh2serial_probe(struct connman_device *device)
+{
+       return 0;
+}
+
+static void hh2serial_remove(struct connman_device *device)
+{
+}
+
+static int hh2serial_enable(struct connman_device *device)
+{
+       DBG("");
+
+       set_reg("/sys/class/gpio/expo_rt", "85");
+       set_reg("/sys/class/gpio/gpio85/direction", "out");
+       set_reg("/sys/class/gpio/gpio85/value", "1");
+
+       return 0;
+}
+
+static int hh2serial_disable(struct connman_device *device)
+{
+       DBG("");
+
+       set_reg("/sys/class/gpio/expo_rt", "85");
+       set_reg("/sys/class/gpio/gpio85/direction", "out");
+       set_reg("/sys/class/gpio/gpio85/value", "0");
+
+       return 0;
+}
+
+static struct connman_device_driver hh2seial_device_driver = {
+       .name           = "hh2serial GPS",
+       .type           = CONNMAN_DEVICE_TYPE_GPS,
+       .enable         = hh2serial_enable,
+       .disable        = hh2serial_disable,
+       .probe          = hh2serial_probe,
+       .remove         = hh2serial_remove,
+};
+
+static int hh2serial_init(void)
+{
+       connman_device_driver_register(&hh2seial_device_driver);
+
+       hh2serial_device = connman_device_create("hh2serial_gps",
+                                               CONNMAN_DEVICE_TYPE_GPS);
+       if (hh2serial_device == NULL)
+               return -ENODEV;
+
+       connman_device_set_mode(hh2serial_device,
+                                       CONNMAN_DEVICE_MODE_NETWORK_SINGLE);
+       connman_device_register(hh2serial_device);
+
+       return 0;
+}
+
+static void hh2serial_exit(void)
+{
+       if (hh2serial_device != NULL) {
+               connman_device_unregister(hh2serial_device);
+               connman_device_unref(hh2serial_device);
+       }
+}
+
+CONNMAN_PLUGIN_DEFINE(hh2serial_gps, "hh2serial GPS", VERSION,
+               CONNMAN_PLUGIN_PRIORITY_LOW, hh2serial_init, hh2serial_exit)