summaryrefslogtreecommitdiffstats
path: root/meta-facebook/meta-wedge/recipes-wedge/fblibs/files/alert_control
diff options
context:
space:
mode:
Diffstat (limited to 'meta-facebook/meta-wedge/recipes-wedge/fblibs/files/alert_control')
-rw-r--r--meta-facebook/meta-wedge/recipes-wedge/fblibs/files/alert_control/Makefile11
-rw-r--r--meta-facebook/meta-wedge/recipes-wedge/fblibs/files/alert_control/alert_control.c117
-rw-r--r--meta-facebook/meta-wedge/recipes-wedge/fblibs/files/alert_control/alert_control.h64
3 files changed, 192 insertions, 0 deletions
diff --git a/meta-facebook/meta-wedge/recipes-wedge/fblibs/files/alert_control/Makefile b/meta-facebook/meta-wedge/recipes-wedge/fblibs/files/alert_control/Makefile
new file mode 100644
index 0000000..74ce8f3
--- /dev/null
+++ b/meta-facebook/meta-wedge/recipes-wedge/fblibs/files/alert_control/Makefile
@@ -0,0 +1,11 @@
+# Copyright 2014-present Facebook. All Rights Reserved.
+lib: libalert_control.so
+
+libalert_control.so: alert_control.c
+ $(CC) $(CCFLAGS) -fPIC -c -o alert_control.o alert_control.c
+ $(CC) -shared -o libalert_control.so alert_control.o -lc
+
+.PHONY: clean
+
+clean:
+ rm -rf *.o libalert_control.so
diff --git a/meta-facebook/meta-wedge/recipes-wedge/fblibs/files/alert_control/alert_control.c b/meta-facebook/meta-wedge/recipes-wedge/fblibs/files/alert_control/alert_control.c
new file mode 100644
index 0000000..81b0329
--- /dev/null
+++ b/meta-facebook/meta-wedge/recipes-wedge/fblibs/files/alert_control/alert_control.c
@@ -0,0 +1,117 @@
+/*
+ *
+ * Copyright 2014-present Facebook. 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 as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+#include <syslog.h>
+#include "alert_control.h"
+
+#define PATH_ALERT_STATUS "/sys/bus/i2c/drivers/panther_plus/4-0040/alert_status"
+#define PATH_ALERT_CONTROL "/sys/bus/i2c/drivers/panther_plus/4-0040/alert_control"
+
+#define MASK_ALERT_SMS_KCS 0x01
+
+/*
+ * Function to enable/disable alert signal generation for a given Function Block
+ */
+int
+alert_control(e_fbid_t id, e_flag_t cflag) {
+ FILE *fp;
+ unsigned char rbuf[5] = {0};
+ unsigned char tbuf[3] = {0};
+ int count = 0;
+
+ fp = fopen(PATH_ALERT_CONTROL, "r+");
+ if (!fp) {
+ return -1;
+ }
+
+ count = fread(rbuf, sizeof(unsigned char), sizeof(rbuf), fp);
+ if (count == 0x0) {
+ fclose(fp);
+ return -1;
+ }
+
+ // Size of the request
+ tbuf[0] = 0x02;
+
+ switch(id) {
+ case FBID_SMS_KCS:
+ if (cflag == FLAG_ENABLE)
+ tbuf[1] = rbuf[2] | (0x01 << FBID_SMS_KCS);
+ else
+ tbuf[1] = rbuf[2] & (~(0x01 << FBID_SMS_KCS));
+
+ tbuf[2] = rbuf[3];
+ break;
+ // TODO: Add logic for other Function Blocks here
+ default:
+ tbuf[0] = rbuf[2];
+ tbuf[1] = rbuf[3];
+ break;
+ }
+
+ count = fwrite(tbuf, sizeof(unsigned char), sizeof(tbuf), fp);
+ if (count != sizeof(tbuf)) {
+ fclose(fp);
+ return (-1);
+ }
+
+ fclose(fp);
+
+ return 0;
+}
+
+/*
+ * Function to check if the alert for a given Function Block is asserted or not
+ */
+bool
+is_alert_present(e_fbid_t id) {
+ FILE *fp;
+ unsigned char buf[5] = {0};
+ int count = 0;
+
+ fp = fopen(PATH_ALERT_STATUS, "r");
+
+ if (!fp) {
+ return false;
+ }
+
+ count = fread(buf, sizeof(unsigned char), sizeof(buf), fp);
+ if (count == 0x0) {
+ fclose(fp);
+ sleep(2);
+ return false;
+ }
+
+ fclose(fp);
+
+ switch(id) {
+ case FBID_SMS_KCS:
+ if (buf[2] & (0x01 << FBID_SMS_KCS))
+ return true;
+ else
+ return false;
+ //TODO: Add logic for other Function Blocks here
+ default:
+ return false;
+ }
+}
diff --git a/meta-facebook/meta-wedge/recipes-wedge/fblibs/files/alert_control/alert_control.h b/meta-facebook/meta-wedge/recipes-wedge/fblibs/files/alert_control/alert_control.h
new file mode 100644
index 0000000..ca72591
--- /dev/null
+++ b/meta-facebook/meta-wedge/recipes-wedge/fblibs/files/alert_control/alert_control.h
@@ -0,0 +1,64 @@
+/*
+ *
+ * Copyright 2014-present Facebook. 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 as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef __ALERT_CONTROL_H__
+#define __ALERT_CONTROL_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stdbool.h>
+
+typedef enum {
+ FLAG_DISABLE = 0x00,
+ FLAG_ENABLE,
+} e_flag_t;
+
+typedef enum {
+ FBID_SMS_KCS = 0x00,
+ FBID_SMM_KCS,
+ FBID_COM1_DATA,
+ FBID_COM2_DATA,
+ FBID_COM1_STAT_CTRL,
+ FBID_COM2_STAT_CTRL,
+ FBID_POST,
+ FBID_I2C_PROXY1_MASTER,
+ FBID_I2C_PROXY1_STAT,
+ FBID_I2C_PROXY2_MASTER,
+ FBID_I2C_PROXY2_STAT,
+ FBID_GPIO_CONFIG,
+ FBID_GPIO_OUTPUT,
+ FBID_GPIO_INPUT,
+ FBID_GPIO_INTR,
+ FBID_GPIO_EVENT,
+ FBID_REG_READ,
+ FBID_ALERT_CTRL = 0xFD,
+ FBID_AERT_STAT = 0xFE,
+ FBID_DISCOVERY = 0xFF,
+} e_fbid_t;
+
+int alert_control(e_fbid_t id, e_flag_t cflag);
+bool is_alert_present(e_fbid_t id);
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+#endif /* __ALERT_CONTROL_H__ */
OpenPOWER on IntegriCloud