aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Busch <morphis@gravedo.de>2012-02-03 20:34:15 +0100
committerSimon Busch <morphis@gravedo.de>2012-02-03 20:34:15 +0100
commite8bec379a346442f3719eb3e76fbf79697622754 (patch)
tree0ce63e73fc639f49619cc1e2e48205b02aa20e81
parentc41dcc61f8271b1459f2ae6d27777b5580c08a6b (diff)
parent1789f2ac0766851f078c754fe31cb87a6f013184 (diff)
downloadexternal_libsamsung-ipc-e8bec379a346442f3719eb3e76fbf79697622754.zip
external_libsamsung-ipc-e8bec379a346442f3719eb3e76fbf79697622754.tar.gz
external_libsamsung-ipc-e8bec379a346442f3719eb3e76fbf79697622754.tar.bz2
Merge remote-tracking branch 'origin/paulk/rework-device-specific' into morphis/rework-device-specific
Conflicts: include/radio.h samsung-ipc/ipc.c samsung-ipc/ipc_private.h
-rw-r--r--Android.mk1
-rw-r--r--include/radio.h10
-rw-r--r--samsung-ipc/Makefile.am1
-rw-r--r--samsung-ipc/device/h1/h1_ipc.c4
-rw-r--r--samsung-ipc/ipc.c80
-rw-r--r--samsung-ipc/ipc_devices.c33
-rw-r--r--samsung-ipc/ipc_devices.h57
-rw-r--r--samsung-ipc/ipc_private.h6
8 files changed, 152 insertions, 40 deletions
diff --git a/Android.mk b/Android.mk
index 11d941f..8997e80 100644
--- a/Android.mk
+++ b/Android.mk
@@ -37,6 +37,7 @@ endif
samsung-ipc_files := \
samsung-ipc/ipc.c \
samsung-ipc/ipc_util.c \
+ samsung-ipc/ipc_devices.c \
samsung-ipc/util.c \
samsung-ipc/rfs.c \
samsung-ipc/gen.c \
diff --git a/include/radio.h b/include/radio.h
index 4c14d79..3cd8834 100644
--- a/include/radio.h
+++ b/include/radio.h
@@ -29,11 +29,6 @@
#define IPC_CLIENT_TYPE_FMT 0
#define IPC_CLIENT_TYPE_RFS 1
-#define IPC_DEVICE_CRESPO 0
-#define IPC_DEVICE_ARIES 1
-
-#define IPC_DEVICE_MAX IPC_DEVICE_ARIES
-
#define IPC_COMMAND(f) ((f->group << 8) | f->index)
#define IPC_GROUP(m) (m >> 8)
#define IPC_INDEX(m) (m & 0xff)
@@ -57,11 +52,6 @@ struct ipc_message_info {
struct ipc_client;
struct ipc_handlers;
-extern struct ipc_handlers ipc_default_handlers;
-
-void ipc_init(void);
-void ipc_shutdown(void);
-
typedef void (*ipc_client_log_handler_cb)(const char *message, void *user_data);
typedef int (*ipc_io_handler_cb)(void *data, unsigned int size, void *io_data);
diff --git a/samsung-ipc/Makefile.am b/samsung-ipc/Makefile.am
index 31c3934..df5dc22 100644
--- a/samsung-ipc/Makefile.am
+++ b/samsung-ipc/Makefile.am
@@ -17,6 +17,7 @@ lib_LTLIBRARIES = \
libsamsung_ipc_la_SOURCES = \
ipc.c \
ipc_util.c \
+ ipc_devices.c \
util.c \
\
rfs.c \
diff --git a/samsung-ipc/device/h1/h1_ipc.c b/samsung-ipc/device/h1/h1_ipc.c
index 8363449..1f6b825 100644
--- a/samsung-ipc/device/h1/h1_ipc.c
+++ b/samsung-ipc/device/h1/h1_ipc.c
@@ -263,7 +263,7 @@ int h1_ipc_common_data_get_fd(void *io_data)
return (int) *(common_data);
}
-struct ipc_handlers ipc_default_handlers = {
+struct ipc_handlers h1_default_handlers = {
.open = h1_ipc_open,
.close = h1_ipc_close,
.power_on = h1_ipc_power_on,
@@ -277,7 +277,7 @@ struct ipc_handlers ipc_default_handlers = {
.common_data_get_fd = h1_ipc_common_data_get_fd,
};
-struct ipc_ops ipc_fmt_ops = {
+struct ipc_ops h1_fmt_ops = {
.send = h1_ipc_send,
.recv = h1_ipc_recv,
.bootstrap = NULL,
diff --git a/samsung-ipc/ipc.c b/samsung-ipc/ipc.c
index 97af363..91ee455 100644
--- a/samsung-ipc/ipc.c
+++ b/samsung-ipc/ipc.c
@@ -38,21 +38,7 @@
#include <radio.h>
#include "ipc_private.h"
-
-struct ipc_device_desc devices[IPC_DEVICE_MAX+1];
-
-extern void crespo_ipc_register(void);
-extern void aries_ipc_register();
-
-void ipc_init(void)
-{
- crespo_ipc_register();
- aries_ipc_register();
-}
-
-void ipc_shutdown(void)
-{
-}
+#include "ipc_devices.h"
void log_handler_default(const char *message, void *user_data)
{
@@ -80,6 +66,51 @@ void ipc_client_log(struct ipc_client *client, const char *message, ...)
va_end(args);
}
+int ipc_device_detect(void)
+{
+ int index = -1;
+ int i;
+
+#ifdef IPC_DEVICE_EXPLICIT
+ for(i=0 ; i < ipc_devices_count ; i++)
+ {
+ if(strcmp(IPC_DEVICE_EXPLICIT, ipc_device[i].name) == 0)
+ {
+ index = i;
+ break;
+ }
+ }
+#else
+ char buf[4096];
+
+ // gather device type from /proc/cpuinfo
+ int fd = open("/proc/cpuinfo", O_RDONLY);
+ int bytesread = read(fd, buf, 4096);
+ close(fd);
+
+ // match hardware name with our supported devices
+ char *pch = strtok(buf, "\n");
+ while (pch != NULL)
+ {
+ int rc;
+ if ((rc = strncmp(pch, "Hardware", 9)) == 9)
+ {
+ for(i=0 ; i < ipc_devices_count ; i++)
+ {
+ if(strcmp(pch, ipc_devices[i].board_name) == 0)
+ {
+ index = i;
+ break;
+ }
+ }
+ }
+ pch = strtok(NULL, "\n");
+ }
+#endif
+
+ return index;
+}
+
struct ipc_client* ipc_client_new(int client_type)
{
int device_type = -1, in_hardware = 0;
@@ -114,11 +145,15 @@ struct ipc_client* ipc_client_new(int client_type)
struct ipc_client* ipc_client_new_for_device(int device_type, int client_type)
{
struct ipc_client *client;
+ int device_index = -1;
+
+ device_index = ipc_device_detect();
+
+ if(device_index < 0 || device_index > ipc_devices_count)
+ return NULL;
- if (device_type < 0 || device_type > IPC_DEVICE_MAX)
- return 0;
if (client_type < 0 || client_type > IPC_CLIENT_TYPE_RFS)
- return 0;
+ return NULL;
client = (struct ipc_client*) malloc(sizeof(struct ipc_client));
client->type = client_type;
@@ -126,17 +161,18 @@ struct ipc_client* ipc_client_new_for_device(int device_type, int client_type)
switch (client_type)
{
case IPC_CLIENT_TYPE_RFS:
- client->ops = devices[device_type].rfs_ops;
+ client->ops = ipc_devices[device_index].rfs_ops;
break;
case IPC_CLIENT_TYPE_FMT:
- client->ops = devices[device_type].fmt_ops;
+ client->ops = ipc_devices[device_index].fmt_ops;
break;
}
client->handlers = (struct ipc_handlers *) malloc(sizeof(struct ipc_handlers));
client->log_handler = log_handler_default;
- if (devices[device_type].handlers != 0)
- memcpy(client->handlers, devices[device_type].handlers , sizeof(struct ipc_handlers));
+
+ if (ipc_devices[device_index].handlers != 0)
+ memcpy(client->handlers, ipc_devices[device_index].handlers, sizeof(struct ipc_handlers));
return client;
}
diff --git a/samsung-ipc/ipc_devices.c b/samsung-ipc/ipc_devices.c
new file mode 100644
index 0000000..f3f2b17
--- /dev/null
+++ b/samsung-ipc/ipc_devices.c
@@ -0,0 +1,33 @@
+/**
+ * This file is part of libsamsung-ipc.
+ *
+ * Copyright (C) 2012 Paul Kocialkowski <contact@paulk.fr>
+ *
+ * libsamsung-ipc 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * libsamsung-ipc 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 libsamsung-ipc. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <radio.h>
+
+#include "ipc_devices.h"
+
+struct ipc_device_desc ipc_devices[] = {
+ { "crespo", "herring", &crespo_default_handlers, &crespo_fmt_ops, &crespo_rfs_ops },
+ { "aries", "aries", &aries_default_handlers, &aries_fmt_ops, &aries_rfs_ops },
+ { "aries", "gt-p1000", &aries_default_handlers, &aries_fmt_ops, &aries_rfs_ops }
+};
+
+int ipc_devices_count = sizeof(ipc_devices) / sizeof(struct ipc_device_desc);
+
+// vim:ts=4:sw=4:expandtab
diff --git a/samsung-ipc/ipc_devices.h b/samsung-ipc/ipc_devices.h
new file mode 100644
index 0000000..baddb76
--- /dev/null
+++ b/samsung-ipc/ipc_devices.h
@@ -0,0 +1,57 @@
+/**
+ * This file is part of libsamsung-ipc.
+ *
+ * Copyright (C) 2012 Paul Kocialkowski <contact@paulk.fr>
+ *
+ * libsamsung-ipc 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * libsamsung-ipc 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 libsamsung-ipc. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef __IPC_DEVICES_H__
+#define __IPC_DEVICES_H__
+
+#include <radio.h>
+
+struct ipc_device_desc {
+ char *name;
+ char *board_name;
+
+ struct ipc_handlers *handlers;
+ struct ipc_ops *fmt_ops;
+ struct ipc_ops *rfs_ops;
+};
+
+extern struct ipc_device_desc ipc_devices[];
+extern int ipc_devices_count;
+
+// h1
+
+extern struct ipc_handlers h1_default_handlers;
+extern struct ipc_ops h1_fmt_ops;
+extern struct ipc_ops h1_rfs_ops;
+
+// crespo
+
+extern struct ipc_handlers crespo_default_handlers;
+extern struct ipc_ops crespo_fmt_ops;
+extern struct ipc_ops crespo_rfs_ops;
+
+// aries
+extern struct ipc_handlers aries_default_handlers;
+extern struct ipc_ops aries_fmt_ops;
+extern struct ipc_ops aries_rfs_ops;
+
+#endif
+
+// vim:ts=4:sw=4:expandtab
diff --git a/samsung-ipc/ipc_private.h b/samsung-ipc/ipc_private.h
index 1795def..ac8db78 100644
--- a/samsung-ipc/ipc_private.h
+++ b/samsung-ipc/ipc_private.h
@@ -65,12 +65,6 @@ struct ipc_client {
struct ipc_handlers *handlers;
};
-struct ipc_device_desc {
- struct ipc_ops *fmt_ops;
- struct ipc_ops *rfs_ops;
- struct ips_handlers *handlers;
-};
-
void ipc_client_log(struct ipc_client *client, const char *message, ...);
void ipc_register_device_client_handlers(int device, struct ipc_ops *fmt_ops,
struct ipc_ops *rfs_ops, struct ipc_handlers *handlers);