aboutsummaryrefslogtreecommitdiffstats
path: root/samsung-ipc/ipc.c
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 /samsung-ipc/ipc.c
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
Diffstat (limited to 'samsung-ipc/ipc.c')
-rw-r--r--samsung-ipc/ipc.c80
1 files changed, 58 insertions, 22 deletions
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;
}