gfch100: add gpio_mailbox support

	* also fix typo for GFLT200->GFLT110
	* also fix case where reset is polled when not present

Change-Id: I6f3cb716b3a60b65421c606ab76c6e069f838756
diff --git a/Makefile b/Makefile
index 2c82d1e..b0f8b94 100644
--- a/Makefile
+++ b/Makefile
@@ -52,11 +52,12 @@
 DIRS+=signing
 endif
 
-ifeq ($(BR2_TARGET_GOOGLE_PLATFORM),gfibersc)
+
+ifeq ($(BR2_TARGET_GENERIC_PLATFORM_NAME),gfsc100)
 DIRS+=diags
 endif
 
-ifeq ($(BR2_TARGET_GOOGLE_PLATFORM),gfiberwc)
+ifeq ($(BR2_TARGET_GENERIC_PLATFORM_NAME),gfmn100)
 DIRS+=diags
 endif
 
diff --git a/diags/Makefile b/diags/Makefile
index dec58f5..76855ce 100644
--- a/diags/Makefile
+++ b/diags/Makefile
@@ -1,10 +1,10 @@
 default: all
 
 DIRS = common
-ifeq ($(BR2_TARGET_GOOGLE_PLATFORM),gfiberwc)
+ifeq ($(BR2_TARGET_GENERIC_PLATFORM_NAME),gfmn100)
  DIRS += windcharger
 endif
-ifeq ($(BR2_TARGET_GOOGLE_PLATFORM),gfibersc)
+ifeq ($(BR2_TARGET_GENERIC_PLATFORM_NAME),gfsc100)
  DIRS += spacecast
 endif
 
diff --git a/gpio-mailbox/Makefile b/gpio-mailbox/Makefile
index 8259dd3..baa296d 100644
--- a/gpio-mailbox/Makefile
+++ b/gpio-mailbox/Makefile
@@ -23,26 +23,19 @@
 # enable the platform we're supporting
 ifeq ($(BR2_PACKAGE_BCM_NEXUS),y)
   CFLAGS += -DBROADCOM
-  NOSTUB=1
-endif
-ifeq ($(BR2_PACKAGE_MINDSPEED_DRIVERS),y)
+else ifeq ($(BR2_PACKAGE_MINDSPEED_DRIVERS),y)
   CFLAGS += -DMINDSPEED
-  NOSTUB=1
-endif
-
-ifeq ($(BR2_TARGET_GOOGLE_PLATFORM),gfiberlt)
+else ifeq ($(BR2_TARGET_GENERIC_PLATFORM_NAME),gflt110)
   CFLAGS += -DGFIBER_LT
-  NOSTUB=1
-endif
-
-ifeq ($(BR2_TARGET_GOOGLE_PLATFORM),gfiberwc)
+else ifeq ($(BR2_TARGET_GENERIC_PLATFORM_NAME),gfmn100)
   CFLAGS += -DWINDCHARGER
-  NOSTUB=1
-endif
-
-ifndef NOSTUB
+else ifeq ($(BR2_TARGET_GENERIC_PLATFORM_NAME),gfch100)
+  CFLAGS += -DGFCH100
+else ifeq ($(BR2_TARGET_GENERIC_PLATFORM_NAME),kvm)
   CFLAGS += -DSTUB
   LDFLAGS += -lm
+else
+  $(error can't determine which pin implementation to use for gpio_mailbox)
 endif
 
 INC_DIRS += ../libstacktrace
diff --git a/gpio-mailbox/gfch100.c b/gpio-mailbox/gfch100.c
new file mode 100644
index 0000000..0b68514
--- /dev/null
+++ b/gpio-mailbox/gfch100.c
@@ -0,0 +1,157 @@
+#ifdef GFCH100
+
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "fileops.h"
+#include "pin.h"
+
+#define GPIO_OFF		"0"
+#define GPIO_ON		"1"
+
+#define GPIO_OUT		"out"
+
+#define GPIO_RED		"30"
+#define GPIO_ACTIVITY		"31"
+
+#define GPIO_BASE_DIR        	"/sys/class/gpio"
+#define GPIO_EXPORT     	GPIO_BASE_DIR "/export"
+
+#define GPIO_DIR(n)       	GPIO_BASE_DIR "/gpio" n
+
+#define GPIO_DIRECTION(dir)	dir "/direction"
+#define GPIO_VALUE(dir)		dir "/value"
+
+struct PinHandle_s {
+  int   unused;
+};
+
+struct systemp {
+  const char* value_path;
+};
+
+struct sysgpio {
+  const char* export_value;
+  const char* value_path;
+  const char* direction_path;
+};
+
+struct platform_info {
+  const char *name;
+  struct systemp temp_cpu;
+  struct sysgpio led_red;
+  struct sysgpio led_activity;
+};
+
+struct platform_info platforms[] = {
+  {
+    .name = "GFCH100",
+    .temp_cpu = {
+      .value_path = "/sys/class/hwmon/hwmon0/temp1_input",
+    },
+    .led_red = {
+      .export_value = GPIO_RED,
+      .direction_path = GPIO_DIRECTION(GPIO_DIR(GPIO_RED)),
+      .value_path = GPIO_VALUE(GPIO_DIR(GPIO_RED)),
+    },
+    .led_activity = {
+      .export_value = GPIO_ACTIVITY,
+      .direction_path = GPIO_DIRECTION(GPIO_DIR(GPIO_ACTIVITY)),
+      .value_path = GPIO_VALUE(GPIO_DIR(GPIO_ACTIVITY)),
+    },
+  }
+};
+
+struct platform_info *platform = &platforms[0];
+
+// Write the given sysfile
+static void set_sysfile(const char* s, int level) {
+  write_file_int(s, NULL, level);
+}
+
+// Read the given sysfile pin
+static int get_sysfile(const char* s) {
+  return read_file_long(s);
+}
+
+/* standard API follows */
+
+PinHandle PinCreate(void) {
+  PinHandle handle = (PinHandle) calloc(1, sizeof (*handle));
+  if (handle == NULL) {
+    perror("calloc(PinHandle)");
+    return NULL;
+  }
+
+  // initialize leds to match boot values
+  write_file_string(GPIO_EXPORT, GPIO_RED);
+  write_file_string(platform->led_red.direction_path, GPIO_OUT);
+  write_file_string(platform->led_red.value_path, GPIO_OFF);
+
+  write_file_string(GPIO_EXPORT, GPIO_ACTIVITY);
+  write_file_string(platform->led_activity.direction_path, GPIO_OUT);
+  write_file_string(platform->led_activity.value_path, GPIO_ON);
+
+  return handle;
+}
+
+void PinDestroy(PinHandle handle) {
+  if (handle == NULL)
+    return;
+
+  free(handle);
+}
+
+int PinIsPresent(PinHandle handle, PinId id) {
+  if (handle == NULL) return PIN_ERROR;
+  switch (id) {
+    case PIN_LED_RED:
+    case PIN_LED_ACTIVITY:
+    case PIN_TEMP_CPU:
+      return 1;
+
+    default:
+      return 0;
+  }
+  return 0;
+}
+
+PinStatus PinValue(PinHandle handle, PinId id, int* valueP) {
+  if (handle == NULL) return PIN_ERROR;
+  switch (id) {
+    case PIN_LED_RED:
+      *valueP = get_sysfile(platform->led_red.value_path);
+      break;
+    case PIN_LED_ACTIVITY:
+      *valueP = get_sysfile(platform->led_activity.value_path);
+      break;
+    case PIN_TEMP_CPU:
+      *valueP = get_sysfile(platform->temp_cpu.value_path);
+      break;
+
+    default:
+      *valueP = -1;
+      return PIN_ERROR;
+  }
+  return PIN_OKAY;
+}
+
+PinStatus PinSetValue(PinHandle handle, PinId id, int value) {
+  if (handle == NULL) return PIN_ERROR;
+  switch (id) {
+    case PIN_LED_RED:
+      set_sysfile(platform->led_red.value_path, value);
+      break;
+    case PIN_LED_ACTIVITY:
+      set_sysfile(platform->led_activity.value_path, value);
+      break;
+    default:
+      return PIN_ERROR;
+  }
+  return PIN_OKAY;
+}
+#endif /* GFCH100 */
diff --git a/gpio-mailbox/gfiber-lt.c b/gpio-mailbox/gfiber-lt.c
index 6d883dc..1926837 100644
--- a/gpio-mailbox/gfiber-lt.c
+++ b/gpio-mailbox/gfiber-lt.c
@@ -29,7 +29,7 @@
 
 struct platform_info platforms[] = {
   {
-    .name = "GFLT200",
+    .name = "GFLT110",          // or GFLT120
     .led_red = {
       .file_path = "/sys/devices/platform/board/leds:sys-red/brightness",
     },