Skip to content

Commit

Permalink
Make wakelocks not crespo-specific and add for xmm6260
Browse files Browse the repository at this point in the history
  • Loading branch information
astarasikov committed Jul 26, 2012
1 parent 89904c0 commit e4403cb
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 42 deletions.
1 change: 1 addition & 0 deletions Android.mk
Expand Up @@ -55,6 +55,7 @@ samsung-ipc_files := \
samsung-ipc/misc.c \
samsung-ipc/net.c \
samsung-ipc/sec.c \
samsung-ipc/wakelock.c \
samsung-ipc/device/h1/h1_ipc.c \
samsung-ipc/device/crespo/crespo_ipc.c \
samsung-ipc/device/aries/aries_ipc.c \
Expand Down
1 change: 1 addition & 0 deletions include/Makefile.am
Expand Up @@ -16,6 +16,7 @@ samsung_ipcinclude_HEADERS = \
gprs.h \
snd.h \
rfs.h \
wakelock.h \
$(NULL)

samsung_ipc_v4includedir = $(includedir)/samsung-ipc-1.0/device/ipc-v4/
Expand Down
27 changes: 27 additions & 0 deletions include/wakelock.h
@@ -0,0 +1,27 @@
/**
* This file is part of libsamsung-ipc.
*
* Copyright (C) 2012 Alexander Tarasikov <alexander.tarasikov@gmail.com>
*
* 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 __WAKELOCK_H__
#define __WAKELOCK_H__

extern int wake_lock(char *lock_name);
extern int wake_unlock(char *lock_name);

#endif //__WAKELOCK_H__
1 change: 1 addition & 0 deletions samsung-ipc/Makefile.am
Expand Up @@ -26,6 +26,7 @@ libsamsung_ipc_la_SOURCES = \
gprs.c \
call.c \
net.c \
wakelock.c \
ipc_private.h \
ipc_devices.h \
device/crespo/crespo_ipc.c \
Expand Down
36 changes: 5 additions & 31 deletions samsung-ipc/device/crespo/crespo_ipc.c
Expand Up @@ -34,38 +34,12 @@
#include <assert.h>

#include <radio.h>
#include <wakelock.h>

#include "crespo_modem_ctl.h"
#include "crespo_ipc.h"
#include "ipc_private.h"

int wake_lock_fd = -1;
int wake_unlock_fd = -1;

int wake_lock(char *lock_name, int len)
{
int rc = 0;

if(wake_lock_fd < 0)
wake_lock_fd = open("/sys/power/wake_lock", O_RDWR);

rc = write(wake_lock_fd, lock_name, len);

return rc;
}

int wake_unlock(char *lock_name, int len)
{
int rc = 0;

if(wake_unlock_fd < 0)
wake_unlock_fd = open("/sys/power/wake_unlock", O_RDWR);

rc = write(wake_unlock_fd, lock_name, len);

return rc;
}

int crespo_modem_bootstrap(struct ipc_client *client)
{
int s3c2410_serial3_fd = -1;
Expand Down Expand Up @@ -360,7 +334,7 @@ int crespo_ipc_fmt_client_recv(struct ipc_client *client, struct ipc_message_inf

memset(response, 0, sizeof(struct ipc_message_info));

wake_lock("secril_fmt-interface", 20);
wake_lock("secril_fmt-interface");

assert(client->handlers->read != NULL);
bread = client->handlers->read((uint8_t*) &modem_data, sizeof(struct modem_io) + MAX_MODEM_DATA_SIZE, client->handlers->read_data);
Expand Down Expand Up @@ -396,7 +370,7 @@ int crespo_ipc_fmt_client_recv(struct ipc_client *client, struct ipc_message_inf

ipc_client_log_recv(client, response, __func__);

wake_unlock("secril_fmt-interface", 20);
wake_unlock("secril_fmt-interface");

return 0;
}
Expand All @@ -412,7 +386,7 @@ int crespo_ipc_rfs_client_recv(struct ipc_client *client, struct ipc_message_inf

memset(response, 0, sizeof(struct ipc_message_info));

wake_lock("secril_rfs-interface", 20);
wake_lock("secril_rfs-interface");

assert(client->handlers->read != NULL);
bread = client->handlers->read((uint8_t*) &modem_data, sizeof(struct modem_io) + MAX_MODEM_DATA_SIZE, client->handlers->read_data);
Expand Down Expand Up @@ -446,7 +420,7 @@ int crespo_ipc_rfs_client_recv(struct ipc_client *client, struct ipc_message_inf

ipc_client_log_recv(client, response, __func__);

wake_unlock("secril_rfs-interface", 20);
wake_unlock("secril_rfs-interface");

return 0;
}
Expand Down
3 changes: 0 additions & 3 deletions samsung-ipc/device/crespo/crespo_ipc.h
Expand Up @@ -30,9 +30,6 @@

#define GPRS_IFACE "rmnet0"

int wake_lock(char *lock_name, int len);
int wake_unlock(char *lock_name, int len);

extern struct ipc_handlers crespo_ipc_default_handlers;

#endif
Expand Down
36 changes: 31 additions & 5 deletions samsung-ipc/device/xmm6260/xmm6260_ipc.c
Expand Up @@ -38,6 +38,7 @@
#include <assert.h>

#include <radio.h>
#include <wakelock.h>

#include "ipc_private.h"

Expand All @@ -46,12 +47,17 @@
#include "xmm6260_modemctl.h"
#include "modem_prj.h"

#define FMT_LOCK_NAME "xmm6260-fmt-lock"
#define RFS_LOCK_NAME "xmm6260-rfs-lock"

int xmm6260_ipc_fmt_client_send(struct ipc_client *client, struct ipc_message_info *request)
{
struct ipc_header *hdr;
unsigned char *frame;
unsigned char *payload;
size_t frame_length;

wake_lock(FMT_LOCK_NAME);

/* Frame IPC header + payload length */
frame_length = (sizeof(*hdr) + request->length);
Expand All @@ -77,6 +83,8 @@ int xmm6260_ipc_fmt_client_send(struct ipc_client *client, struct ipc_message_in

free(frame);

wake_unlock(FMT_LOCK_NAME);

return 0;
}

Expand All @@ -92,14 +100,16 @@ int xmm6260_ipc_fmt_client_recv(struct ipc_client *client, struct ipc_message_in
int num_read = 0;
int left = 0;

wake_lock(FMT_LOCK_NAME);

num_read = client->handlers->read(buf, IPC_MAX_XFER,
client->handlers->read_data);

if (num_read < 0) {
ipc_client_log(client, "read failed to read ipc length: %d", num_read);
response->data = 0;
response->length = 0;
return 0;
goto done;
}

memcpy(&ipc, buf, sizeof(ipc));
Expand All @@ -124,6 +134,8 @@ int xmm6260_ipc_fmt_client_recv(struct ipc_client *client, struct ipc_message_in

ipc_client_log_recv(client, response, __func__);

done:
wake_unlock(FMT_LOCK_NAME);
return 0;
}

Expand All @@ -135,27 +147,34 @@ int xmm6260_ipc_rfs_client_recv(struct ipc_client *client, struct ipc_message_in
unsigned count=0;
int rc;

int ret = 0;

wake_lock(RFS_LOCK_NAME);

do {
rc = client->handlers->read(buf, IPC_MAX_XFER, client->handlers->read_data);

if (rc < 0) {
ipc_client_log(client, "Failed to read RFS data.");
return -1;
ret = -1;
goto done;
}
ipc_client_log(client, "received %d bytes", rc);

// We didn't recieve the header yet
if (!header_recv) {
if ((unsigned)rc < sizeof(struct rfs_hdr)) {
ipc_client_log(client, "Failed to read RFS data.");
return -1;
ret = -1;
goto done;
}

memcpy((void *) &header, (void *) buf, sizeof(struct rfs_hdr));

if (header.size < sizeof(struct rfs_hdr)) {
ipc_client_log(client, "Invalid size in header");
return -1;
ret = -1;
goto done;
}

response->mseq = 0;
Expand Down Expand Up @@ -184,7 +203,10 @@ int xmm6260_ipc_rfs_client_recv(struct ipc_client *client, struct ipc_message_in

ipc_client_log_recv(client, response, __func__);

return 0;
done:

wake_unlock(RFS_LOCK_NAME);
return ret;
}

int xmm6260_ipc_rfs_client_send(struct ipc_client *client, struct ipc_message_info *request)
Expand All @@ -194,6 +216,8 @@ int xmm6260_ipc_rfs_client_send(struct ipc_client *client, struct ipc_message_in
int data_length;
int rc;

wake_lock(RFS_LOCK_NAME);

data_length = sizeof(struct rfs_hdr) + request->length;
data = malloc(data_length);
memset(data, 0, data_length);
Expand All @@ -208,6 +232,8 @@ int xmm6260_ipc_rfs_client_send(struct ipc_client *client, struct ipc_message_in
ipc_client_log_send(client, request, __func__);

rc = client->handlers->write(data, data_length, client->handlers->write_data);

wake_unlock(RFS_LOCK_NAME);
return rc;
}

Expand Down
6 changes: 3 additions & 3 deletions samsung-ipc/rfs.c
Expand Up @@ -113,7 +113,7 @@ int nv_data_size(struct ipc_client *client)
{
if (client == NULL ||
client->nv_data_specs == NULL ||
client->nv_data_specs->nv_data_size == NULL)
client->nv_data_specs->nv_data_size == 0)
return NV_DATA_SIZE_DEFAULT;

return client->nv_data_specs->nv_data_size;
Expand All @@ -123,7 +123,7 @@ int nv_data_chunk_size(struct ipc_client *client)
{
if (client == NULL ||
client->nv_data_specs == NULL ||
client->nv_data_specs->nv_data_chunk_size == NULL)
client->nv_data_specs->nv_data_chunk_size == 0)
return NV_DATA_CHUNK_SIZE_DEFAULT;

return client->nv_data_specs->nv_data_chunk_size;
Expand Down Expand Up @@ -714,7 +714,7 @@ void ipc_rfs_send_io_confirm_for_nv_read_item(struct ipc_client *client, struct
if (rfs_io == NULL)
{
ipc_client_log(client, "ERROR: Request message is invalid: aseq = %i", info->aseq);
return NULL;
return;
}

rfs_io_conf = malloc(rfs_io->length + sizeof(struct ipc_rfs_io_confirm));
Expand Down
53 changes: 53 additions & 0 deletions samsung-ipc/wakelock.c
@@ -0,0 +1,53 @@
/**
* This file is part of libsamsung-ipc.
*
* Copyright (C) 2012 Alexander Tarasikov <alexander.tarasikov@gmail.com>
*
* 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 <assert.h>
#include <fcntl.h>
#include <wakelock.h>

int wake_lock(char *lock_name) {
int rc;
assert(lock_name != NULL);

int fd = open("/sys/power/wake_lock", O_RDWR);
if (fd < 0) {
return fd;
}

rc = write(fd, lock_name, strlen(lock_name));
close(fd);

return rc;
}

int wake_unlock(char *lock_name) {
int rc;
assert(lock_name != NULL);

int fd = open("/sys/power/wake_unlock", O_RDWR);
if (fd < 0) {
return fd;
}

rc = write(fd, lock_name, strlen(lock_name));
close(fd);

return rc;
}

0 comments on commit e4403cb

Please sign in to comment.