[Replicant] [libsamsung-ipc][PATCH 51/53] modems: xmm626: hsic: switch to Linux code style
Denis 'GNUtoo' Carikli
GNUtoo at cyberdimension.org
Thu Jun 11 10:57:53 UTC 2020
This contains no functional changes.
Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo at cyberdimension.org>
---
samsung-ipc/modems/xmm626/xmm626_hsic.c | 907 +++++++++---------
samsung-ipc/modems/xmm626/xmm626_hsic.h | 56 +-
.../xmm626/xmm626_modem_link_device_hsic.h | 26 +-
3 files changed, 506 insertions(+), 483 deletions(-)
diff --git a/samsung-ipc/modems/xmm626/xmm626_hsic.c b/samsung-ipc/modems/xmm626/xmm626_hsic.c
index 30ade46..9b78885 100644
--- a/samsung-ipc/modems/xmm626/xmm626_hsic.c
+++ b/samsung-ipc/modems/xmm626/xmm626_hsic.c
@@ -34,554 +34,579 @@
int xmm626_hsic_ack_read(int device_fd, unsigned short ack)
{
- struct timeval timeout;
- fd_set fds;
- unsigned short value;
- int rc;
- int i;
+ struct timeval timeout;
+ fd_set fds;
+ unsigned short value;
+ int rc;
+ int i;
- timeout.tv_sec = 1;
- timeout.tv_usec = 0;
+ timeout.tv_sec = 1;
+ timeout.tv_usec = 0;
- FD_ZERO(&fds);
- FD_SET(device_fd, &fds);
+ FD_ZERO(&fds);
+ FD_SET(device_fd, &fds);
- for (i = 0; i < 50; i++) {
- rc = select(device_fd + 1, &fds, NULL, NULL, &timeout);
- if (rc <= 0)
- return -1;
+ for (i = 0; i < 50; i++) {
+ rc = select(device_fd + 1, &fds, NULL, NULL, &timeout);
+ if (rc <= 0)
+ return -1;
- value = 0;
- rc = read(device_fd, &value, sizeof(value));
- if (rc < (int) sizeof(value))
- continue;
+ value = 0;
+ rc = read(device_fd, &value, sizeof(value));
+ if (rc < (int) sizeof(value))
+ continue;
- if (value == ack)
- return 0;
- }
+ if (value == ack)
+ return 0;
+ }
- return -1;
+ return -1;
}
int xmm626_hsic_psi_send(struct ipc_client *client, int device_fd,
- const void *psi_data, unsigned short psi_size)
+ const void *psi_data, unsigned short psi_size)
{
- struct xmm626_hsic_psi_header psi_header;
- char at[] = XMM626_AT;
- unsigned char psi_ack;
- unsigned char chip_id;
- unsigned char psi_crc;
- struct timeval timeout;
- fd_set fds;
- size_t wc;
- size_t length;
- unsigned char *p;
- int rc;
- int i;
-
- if (client == NULL || device_fd < 0 || psi_data == NULL || psi_size == 0)
- return -1;
-
- FD_ZERO(&fds);
-
- i = 0;
- length = strlen(at);
-
- do {
- FD_SET(device_fd, &fds);
-
- timeout.tv_sec = 0;
- timeout.tv_usec = 100000;
-
- rc = write(device_fd, at, length);
- if (rc < (int) length) {
- ipc_client_log(client, "Writing ATAT in ASCII failed");
- goto error;
- }
- ipc_client_log(client, "Wrote ATAT in ASCII");
-
- rc = select(device_fd + 1, &fds, NULL, NULL, &timeout);
- if (rc < 0) {
- ipc_client_log(client, "Waiting for bootup failed");
- goto error;
- }
-
- if (i++ > 50) {
- ipc_client_log(client, "Waiting for bootup failed");
- goto error;
- }
- } while(rc == 0);
-
- FD_SET(device_fd, &fds);
-
- timeout.tv_sec = 0;
- timeout.tv_usec = 100000;
-
- rc = select(device_fd + 1, &fds, NULL, NULL, &timeout);
- if (rc <= 0) {
- ipc_client_log(client, "Reading boot ACK failed");
- goto error;
- }
-
- psi_ack = 0;
- rc = read(device_fd, &psi_ack, sizeof(psi_ack));
- if (rc < (int) sizeof(psi_ack)) {
- ipc_client_log(client, "Reading boot ACK failed");
- goto error;
- }
-
- rc = select(device_fd + 1, &fds, NULL, NULL, &timeout);
- if (rc <= 0) {
- ipc_client_log(client, "Reading chip id failed");
- goto error;
- }
-
- chip_id = 0;
- rc = read(device_fd, &chip_id, sizeof(chip_id));
- if (rc < (int) sizeof(chip_id)) {
- ipc_client_log(client, "Reading chip id failed");
- goto error;
- }
- ipc_client_log(client, "Read chip id (0x%x)", chip_id);
-
- psi_header.magic = XMM626_PSI_MAGIC;
- psi_header.length = psi_size;
- psi_header.padding = XMM626_PSI_PADDING;
-
- rc = write(device_fd, &psi_header, sizeof(psi_header));
- if (rc < (int) sizeof(psi_header)) {
- ipc_client_log(client, "Writing PSI header failed");
- goto error;
- }
- ipc_client_log(client, "Wrote PSI header");
-
- p = (unsigned char *) psi_data;
-
- wc = 0;
- while (wc < psi_size) {
- rc = write(device_fd, (void *) p, psi_size - wc);
- if (rc <= 0) {
- ipc_client_log(client, "Writing PSI failed");
- goto error;
- }
-
- p += rc;
- wc += rc;
- }
-
- psi_crc = xmm626_crc_calculate(psi_data, psi_size);
-
- ipc_client_log(client, "Wrote PSI, CRC is 0x%x", psi_crc);
-
- rc = write(device_fd, &psi_crc, sizeof(psi_crc));
- if (rc < (int) sizeof(psi_crc)) {
- ipc_client_log(client, "Writing PSI CRC failed");
- goto error;
- }
- ipc_client_log(client, "Wrote PSI CRC (0x%x)", psi_crc);
-
- timeout.tv_sec = 0;
- timeout.tv_usec = 100000;
-
- for (i = 0; i < XMM626_HSIC_PSI_UNKNOWN_COUNT; i++) {
- rc = select(device_fd + 1, &fds, NULL, NULL, &timeout);
- if (rc <= 0) {
- ipc_client_log(client, "Reading PSI unknown failed");
- goto error;
- }
-
- rc = read(device_fd, &psi_ack, sizeof(psi_ack));
- if (rc < (int) sizeof(psi_ack)) {
- ipc_client_log(client, "Reading PSI unknown failed");
- goto error;
- }
- }
-
- for (i = 0; i < XMM626_HSIC_PSI_CRC_ACK_COUNT ; i++) {
- rc = select(device_fd + 1, &fds, NULL, NULL, &timeout);
- if (rc <= 0) {
- ipc_client_log(client, "Reading PSI CRC ACK failed");
- goto error;
- }
-
- rc = read(device_fd, &psi_ack, sizeof(psi_ack));
- if (rc < (int) sizeof(psi_ack)) {
- ipc_client_log(client, "Reading PSI CRC ACK failed");
- goto error;
- }
- }
- ipc_client_log(client, "Read PSI CRC ACK");
-
- rc = xmm626_hsic_ack_read(device_fd, XMM626_HSIC_PSI_ACK);
- if (rc < 0) {
- ipc_client_log(client, "Reading PSI ACK failed");
- goto error;
- }
- ipc_client_log(client, "Read PSI ACK");
-
- rc = 0;
- goto complete;
+ struct xmm626_hsic_psi_header psi_header;
+ char at[] = XMM626_AT;
+ unsigned char psi_ack;
+ unsigned char chip_id;
+ unsigned char psi_crc;
+ struct timeval timeout;
+ fd_set fds;
+ size_t wc;
+ size_t length;
+ unsigned char *p;
+ int rc;
+ int i;
+
+ if (client == NULL || device_fd < 0 || psi_data == NULL ||
+ psi_size == 0) {
+ return -1;
+ }
+
+ FD_ZERO(&fds);
+
+ i = 0;
+ length = strlen(at);
+
+ do {
+ FD_SET(device_fd, &fds);
+
+ timeout.tv_sec = 0;
+ timeout.tv_usec = 100000;
+
+ rc = write(device_fd, at, length);
+ if (rc < (int) length) {
+ ipc_client_log(client, "Writing ATAT in ASCII failed");
+ goto error;
+ }
+ ipc_client_log(client, "Wrote ATAT in ASCII");
+
+ rc = select(device_fd + 1, &fds, NULL, NULL, &timeout);
+ if (rc < 0) {
+ ipc_client_log(client, "Waiting for bootup failed");
+ goto error;
+ }
+
+ if (i++ > 50) {
+ ipc_client_log(client, "Waiting for bootup failed");
+ goto error;
+ }
+ } while (rc == 0);
+
+ FD_SET(device_fd, &fds);
+
+ timeout.tv_sec = 0;
+ timeout.tv_usec = 100000;
+
+ rc = select(device_fd + 1, &fds, NULL, NULL, &timeout);
+ if (rc <= 0) {
+ ipc_client_log(client, "Reading boot ACK failed");
+ goto error;
+ }
+
+ psi_ack = 0;
+ rc = read(device_fd, &psi_ack, sizeof(psi_ack));
+ if (rc < (int) sizeof(psi_ack)) {
+ ipc_client_log(client, "Reading boot ACK failed");
+ goto error;
+ }
+
+ rc = select(device_fd + 1, &fds, NULL, NULL, &timeout);
+ if (rc <= 0) {
+ ipc_client_log(client, "Reading chip id failed");
+ goto error;
+ }
+
+ chip_id = 0;
+ rc = read(device_fd, &chip_id, sizeof(chip_id));
+ if (rc < (int) sizeof(chip_id)) {
+ ipc_client_log(client, "Reading chip id failed");
+ goto error;
+ }
+ ipc_client_log(client, "Read chip id (0x%x)", chip_id);
+
+ psi_header.magic = XMM626_PSI_MAGIC;
+ psi_header.length = psi_size;
+ psi_header.padding = XMM626_PSI_PADDING;
+
+ rc = write(device_fd, &psi_header, sizeof(psi_header));
+ if (rc < (int) sizeof(psi_header)) {
+ ipc_client_log(client, "Writing PSI header failed");
+ goto error;
+ }
+ ipc_client_log(client, "Wrote PSI header");
+
+ p = (unsigned char *) psi_data;
+
+ wc = 0;
+ while (wc < psi_size) {
+ rc = write(device_fd, (void *) p, psi_size - wc);
+ if (rc <= 0) {
+ ipc_client_log(client, "Writing PSI failed");
+ goto error;
+ }
+
+ p += rc;
+ wc += rc;
+ }
+
+ psi_crc = xmm626_crc_calculate(psi_data, psi_size);
+
+ ipc_client_log(client, "Wrote PSI, CRC is 0x%x", psi_crc);
+
+ rc = write(device_fd, &psi_crc, sizeof(psi_crc));
+ if (rc < (int) sizeof(psi_crc)) {
+ ipc_client_log(client, "Writing PSI CRC failed");
+ goto error;
+ }
+ ipc_client_log(client, "Wrote PSI CRC (0x%x)", psi_crc);
+
+ timeout.tv_sec = 0;
+ timeout.tv_usec = 100000;
+
+ for (i = 0; i < XMM626_HSIC_PSI_UNKNOWN_COUNT; i++) {
+ rc = select(device_fd + 1, &fds, NULL, NULL, &timeout);
+ if (rc <= 0) {
+ ipc_client_log(client, "Reading PSI unknown failed");
+ goto error;
+ }
+
+ rc = read(device_fd, &psi_ack, sizeof(psi_ack));
+ if (rc < (int) sizeof(psi_ack)) {
+ ipc_client_log(client, "Reading PSI unknown failed");
+ goto error;
+ }
+ }
+
+ for (i = 0; i < XMM626_HSIC_PSI_CRC_ACK_COUNT ; i++) {
+ rc = select(device_fd + 1, &fds, NULL, NULL, &timeout);
+ if (rc <= 0) {
+ ipc_client_log(client, "Reading PSI CRC ACK failed");
+ goto error;
+ }
+
+ rc = read(device_fd, &psi_ack, sizeof(psi_ack));
+ if (rc < (int) sizeof(psi_ack)) {
+ ipc_client_log(client, "Reading PSI CRC ACK failed");
+ goto error;
+ }
+ }
+ ipc_client_log(client, "Read PSI CRC ACK");
+
+ rc = xmm626_hsic_ack_read(device_fd, XMM626_HSIC_PSI_ACK);
+ if (rc < 0) {
+ ipc_client_log(client, "Reading PSI ACK failed");
+ goto error;
+ }
+ ipc_client_log(client, "Read PSI ACK");
+
+ rc = 0;
+ goto complete;
error:
- rc = -1;
+ rc = -1;
complete:
- return rc;
+ return rc;
}
int xmm626_hsic_ebl_send(struct ipc_client *client, int device_fd,
- const void *ebl_data, size_t ebl_size)
+ const void *ebl_data, size_t ebl_size)
{
- unsigned char ebl_crc;
- size_t chunk;
- size_t count;
- size_t wc;
- size_t size;
- unsigned char *p;
- int rc;
-
- if (client == NULL || device_fd < 0 || ebl_data == NULL || ebl_size == 0)
- return -1;
-
- size = sizeof(ebl_size);
-
- rc = write(device_fd, &ebl_size, size);
- if (rc < (int) size) {
- ipc_client_log(client, "Writing EBL size failed");
- goto error;
- }
- ipc_client_log(client, "Wrote EBL size");
-
- rc = xmm626_hsic_ack_read(device_fd, XMM626_HSIC_EBL_SIZE_ACK);
- if (rc < 0) {
- ipc_client_log(client, "Reading EBL size ACK failed");
- goto error;
- }
-
- p = (unsigned char *) ebl_data;
-
- chunk = XMM626_HSIC_EBL_CHUNK;
- wc = 0;
- while (wc < ebl_size) {
- count = chunk < ebl_size - wc ? chunk : ebl_size - wc;
-
- rc = write(device_fd, (void *) p, count);
- if (rc <= 0) {
- ipc_client_log(client, "Writing EBL failed");
- goto error;
- }
-
- p += rc;
- wc += rc;
- }
-
- ebl_crc = xmm626_crc_calculate(ebl_data, ebl_size);
-
- ipc_client_log(client, "Wrote EBL, CRC is 0x%x", ebl_crc);
-
- rc = write(device_fd, &ebl_crc, sizeof(ebl_crc));
- if (rc < (int) sizeof(ebl_crc)) {
- ipc_client_log(client, "Writing EBL CRC failed");
- goto error;
- }
- ipc_client_log(client, "Wrote EBL CRC (0x%x)", ebl_crc);
-
- rc = xmm626_hsic_ack_read(device_fd, XMM626_HSIC_EBL_ACK);
- if (rc < 0) {
- ipc_client_log(client, "Reading EBL ACK failed");
- goto error;
- }
-
- rc = 0;
- goto complete;
+ unsigned char ebl_crc;
+ size_t chunk;
+ size_t count;
+ size_t wc;
+ size_t size;
+ unsigned char *p;
+ int rc;
+
+ if (client == NULL || device_fd < 0 || ebl_data == NULL ||
+ ebl_size == 0) {
+ return -1;
+ }
+
+ size = sizeof(ebl_size);
+
+ rc = write(device_fd, &ebl_size, size);
+ if (rc < (int) size) {
+ ipc_client_log(client, "Writing EBL size failed");
+ goto error;
+ }
+ ipc_client_log(client, "Wrote EBL size");
+
+ rc = xmm626_hsic_ack_read(device_fd, XMM626_HSIC_EBL_SIZE_ACK);
+ if (rc < 0) {
+ ipc_client_log(client, "Reading EBL size ACK failed");
+ goto error;
+ }
+
+ p = (unsigned char *) ebl_data;
+
+ chunk = XMM626_HSIC_EBL_CHUNK;
+ wc = 0;
+ while (wc < ebl_size) {
+ count = chunk < ebl_size - wc ? chunk : ebl_size - wc;
+
+ rc = write(device_fd, (void *) p, count);
+ if (rc <= 0) {
+ ipc_client_log(client, "Writing EBL failed");
+ goto error;
+ }
+
+ p += rc;
+ wc += rc;
+ }
+
+ ebl_crc = xmm626_crc_calculate(ebl_data, ebl_size);
+
+ ipc_client_log(client, "Wrote EBL, CRC is 0x%x", ebl_crc);
+
+ rc = write(device_fd, &ebl_crc, sizeof(ebl_crc));
+ if (rc < (int) sizeof(ebl_crc)) {
+ ipc_client_log(client, "Writing EBL CRC failed");
+ goto error;
+ }
+ ipc_client_log(client, "Wrote EBL CRC (0x%x)", ebl_crc);
+
+ rc = xmm626_hsic_ack_read(device_fd, XMM626_HSIC_EBL_ACK);
+ if (rc < 0) {
+ ipc_client_log(client, "Reading EBL ACK failed");
+ goto error;
+ }
+
+ rc = 0;
+ goto complete;
error:
- rc = -1;
+ rc = -1;
complete:
- return rc;
+ return rc;
}
int xmm626_hsic_command_send(int device_fd, unsigned short code,
- const void *data, size_t size, size_t command_data_size, int ack)
+ const void *data, size_t size,
+ size_t command_data_size, int ack)
{
- struct xmm626_hsic_command_header header;
- void *buffer = NULL;
- size_t length;
- struct timeval timeout;
- fd_set fds;
- unsigned char *p;
- int rc;
- int i;
+ struct xmm626_hsic_command_header header;
+ void *buffer = NULL;
+ size_t length;
+ struct timeval timeout;
+ fd_set fds;
+ unsigned char *p;
+ int rc;
+ int i;
- if (device_fd < 0 || data == NULL || size == 0 || command_data_size == 0 || command_data_size < size)
- return -1;
+ if (device_fd < 0 || data == NULL || size == 0 ||
+ command_data_size == 0 || command_data_size < size) {
+ return -1;
+ }
- header.checksum = (size & 0xffff) + code;
- header.code = code;
- header.data_size = size;
+ header.checksum = (size & 0xffff) + code;
+ header.code = code;
+ header.data_size = size;
- p = (unsigned char *) data;
+ p = (unsigned char *) data;
- for (i = 0; i < (int) size; i++)
- header.checksum += *p++;
+ for (i = 0; i < (int) size; i++)
+ header.checksum += *p++;
- length = command_data_size + sizeof(header);
- buffer = calloc(1, length);
+ length = command_data_size + sizeof(header);
+ buffer = calloc(1, length);
- memset(buffer, 0, length);
- p = (unsigned char *) buffer;
- memcpy(p, &header, sizeof(header));
- p += sizeof(header);
- memcpy(p, data, size);
+ memset(buffer, 0, length);
+ p = (unsigned char *) buffer;
+ memcpy(p, &header, sizeof(header));
+ p += sizeof(header);
+ memcpy(p, data, size);
- rc = write(device_fd, buffer, length);
- if (rc < (int) length)
- goto error;
+ rc = write(device_fd, buffer, length);
+ if (rc < (int) length)
+ goto error;
- if (!ack) {
- rc = 0;
- goto complete;
- }
+ if (!ack) {
+ rc = 0;
+ goto complete;
+ }
- memset(buffer, 0, length);
+ memset(buffer, 0, length);
- FD_ZERO(&fds);
- FD_SET(device_fd, &fds);
+ FD_ZERO(&fds);
+ FD_SET(device_fd, &fds);
- timeout.tv_sec = 1;
- timeout.tv_usec = 0;
+ timeout.tv_sec = 1;
+ timeout.tv_usec = 0;
- rc = select(device_fd + 1, &fds, NULL, NULL, &timeout);
- if (rc <= 0)
- goto error;
+ rc = select(device_fd + 1, &fds, NULL, NULL, &timeout);
+ if (rc <= 0)
+ goto error;
- rc = read(device_fd, &header, sizeof(header));
- if (rc < (int) sizeof(header))
- goto error;
+ rc = read(device_fd, &header, sizeof(header));
+ if (rc < (int) sizeof(header))
+ goto error;
- rc = select(device_fd + 1, &fds, NULL, NULL, &timeout);
- if (rc <= 0)
- goto error;
+ rc = select(device_fd + 1, &fds, NULL, NULL, &timeout);
+ if (rc <= 0)
+ goto error;
- rc = read(device_fd, buffer, command_data_size);
- if (rc < (int) command_data_size)
- goto error;
+ rc = read(device_fd, buffer, command_data_size);
+ if (rc < (int) command_data_size)
+ goto error;
- if (header.code != code)
- goto error;
+ if (header.code != code)
+ goto error;
- rc = 0;
- goto complete;
+ rc = 0;
+ goto complete;
error:
- rc = -1;
+ rc = -1;
complete:
- if (buffer != NULL)
- free(buffer);
+ if (buffer != NULL)
+ free(buffer);
- return rc;
+ return rc;
}
int xmm626_hsic_modem_data_send(int device_fd, const void *data, size_t size,
- int address)
+ int address)
{
- size_t chunk;
- size_t count;
- size_t c;
- unsigned char *p;
- int rc;
-
- if (device_fd < 0 || data == NULL || size == 0)
- return -1;
-
- rc = xmm626_hsic_command_send(device_fd, XMM626_COMMAND_FLASH_SET_ADDRESS, &address, sizeof(address), XMM626_HSIC_FLASH_SET_ADDRESS_SIZE, 1);
- if (rc < 0)
- goto error;
-
- p = (unsigned char *) data;
-
- chunk = XMM626_HSIC_MODEM_DATA_CHUNK;
- c = 0;
- while (c < size) {
- count = chunk < size - c ? chunk : size - c;
-
- rc = xmm626_hsic_command_send(device_fd, XMM626_COMMAND_FLASH_WRITE_BLOCK, p, count, XMM626_HSIC_FLASH_WRITE_BLOCK_SIZE, 0);
- if (rc < 0)
- goto error;
-
- p += count;
- c += count;
- }
-
- rc = 0;
- goto complete;
+ size_t chunk;
+ size_t count;
+ size_t c;
+ unsigned char *p;
+ int rc;
+
+ if (device_fd < 0 || data == NULL || size == 0)
+ return -1;
+
+ rc = xmm626_hsic_command_send(device_fd,
+ XMM626_COMMAND_FLASH_SET_ADDRESS,
+ &address, sizeof(address),
+ XMM626_HSIC_FLASH_SET_ADDRESS_SIZE, 1);
+ if (rc < 0)
+ goto error;
+
+ p = (unsigned char *) data;
+
+ chunk = XMM626_HSIC_MODEM_DATA_CHUNK;
+ c = 0;
+ while (c < size) {
+ count = chunk < size - c ? chunk : size - c;
+
+ rc = xmm626_hsic_command_send(
+ device_fd, XMM626_COMMAND_FLASH_WRITE_BLOCK,
+ p, count, XMM626_HSIC_FLASH_WRITE_BLOCK_SIZE, 0);
+ if (rc < 0)
+ goto error;
+
+ p += count;
+ c += count;
+ }
+
+ rc = 0;
+ goto complete;
error:
- rc = -1;
+ rc = -1;
complete:
- return rc;
+ return rc;
}
int xmm626_hsic_port_config_send(struct ipc_client *client, int device_fd)
{
- void *buffer = NULL;
- size_t length;
- struct timeval timeout;
- fd_set fds;
- int rc;
-
- if (client == NULL || device_fd < 0)
- return -1;
-
- FD_ZERO(&fds);
- FD_SET(device_fd, &fds);
-
- timeout.tv_sec = 2;
- timeout.tv_usec = 0;
-
- rc = select(device_fd + 1, &fds, NULL, NULL, &timeout);
- if (rc <= 0)
- goto error;
-
- length = XMM626_HSIC_PORT_CONFIG_SIZE;
- buffer = calloc(1, length);
-
- rc = select(device_fd + 1, &fds, NULL, NULL, &timeout);
- if (rc <= 0)
- goto error;
-
- rc = read(device_fd, buffer, length);
- if (rc < (int) length) {
- ipc_client_log(client, "Reading port config failed");
- goto error;
- }
- ipc_client_log(client, "Read port config");
-
- rc = xmm626_hsic_command_send(device_fd, XMM626_COMMAND_SET_PORT_CONFIG, buffer, length, XMM626_HSIC_SET_PORT_CONFIG_SIZE, 1);
- if (rc < 0) {
- ipc_client_log(client, "Sending port config command failed");
- goto error;
- }
-
- rc = 0;
- goto complete;
+ void *buffer = NULL;
+ size_t length;
+ struct timeval timeout;
+ fd_set fds;
+ int rc;
+
+ if (client == NULL || device_fd < 0)
+ return -1;
+
+ FD_ZERO(&fds);
+ FD_SET(device_fd, &fds);
+
+ timeout.tv_sec = 2;
+ timeout.tv_usec = 0;
+
+ rc = select(device_fd + 1, &fds, NULL, NULL, &timeout);
+ if (rc <= 0)
+ goto error;
+
+ length = XMM626_HSIC_PORT_CONFIG_SIZE;
+ buffer = calloc(1, length);
+
+ rc = select(device_fd + 1, &fds, NULL, NULL, &timeout);
+ if (rc <= 0)
+ goto error;
+
+ rc = read(device_fd, buffer, length);
+ if (rc < (int) length) {
+ ipc_client_log(client, "Reading port config failed");
+ goto error;
+ }
+ ipc_client_log(client, "Read port config");
+
+ rc = xmm626_hsic_command_send(device_fd, XMM626_COMMAND_SET_PORT_CONFIG,
+ buffer, length,
+ XMM626_HSIC_SET_PORT_CONFIG_SIZE, 1);
+ if (rc < 0) {
+ ipc_client_log(client, "Sending port config command failed");
+ goto error;
+ }
+
+ rc = 0;
+ goto complete;
error:
- rc = -1;
+ rc = -1;
complete:
- if (buffer != NULL)
- free(buffer);
+ if (buffer != NULL)
+ free(buffer);
- return rc;
+ return rc;
}
int xmm626_hsic_sec_start_send(struct ipc_client *client, int device_fd,
- const void *sec_data, size_t sec_size)
+ const void *sec_data, size_t sec_size)
{
- int rc;
+ int rc;
- if (client == NULL || device_fd < 0 || sec_data == NULL || sec_size == 0)
- return -1;
+ if (client == NULL || device_fd < 0 || sec_data == NULL ||
+ sec_size == 0) {
+ return -1;
+ }
- rc = xmm626_hsic_command_send(device_fd, XMM626_COMMAND_SEC_START, sec_data, sec_size, XMM626_HSIC_SEC_START_SIZE, 1);
- if (rc < 0)
- return -1;
+ rc = xmm626_hsic_command_send(device_fd, XMM626_COMMAND_SEC_START,
+ sec_data, sec_size,
+ XMM626_HSIC_SEC_START_SIZE, 1);
+ if (rc < 0)
+ return -1;
- return 0;
+ return 0;
}
int xmm626_hsic_sec_end_send(struct ipc_client *client, int device_fd)
{
- unsigned short sec_data;
- size_t sec_size;
- int rc;
+ unsigned short sec_data;
+ size_t sec_size;
+ int rc;
- if (client == NULL || device_fd < 0)
- return -1;
+ if (client == NULL || device_fd < 0)
+ return -1;
- sec_data = XMM626_SEC_END_MAGIC;
- sec_size = sizeof(sec_data);
+ sec_data = XMM626_SEC_END_MAGIC;
+ sec_size = sizeof(sec_data);
- rc = xmm626_hsic_command_send(device_fd, XMM626_COMMAND_SEC_END, &sec_data, sec_size, XMM626_HSIC_SEC_END_SIZE, 1);
- if (rc < 0)
- return -1;
+ rc = xmm626_hsic_command_send(device_fd, XMM626_COMMAND_SEC_END,
+ &sec_data, sec_size,
+ XMM626_HSIC_SEC_END_SIZE, 1);
+ if (rc < 0)
+ return -1;
- return 0;
+ return 0;
}
int xmm626_hsic_firmware_send(struct ipc_client *client, int device_fd,
- const void *firmware_data, size_t firmware_size)
+ const void *firmware_data, size_t firmware_size)
{
- int rc;
+ int rc;
- if (client == NULL || device_fd < 0 || firmware_data == NULL || firmware_size == 0)
- return -1;
+ if (client == NULL || device_fd < 0 || firmware_data == NULL ||
+ firmware_size == 0) {
+ return -1;
+ }
- rc = xmm626_hsic_modem_data_send(device_fd, firmware_data, firmware_size, XMM626_FIRMWARE_ADDRESS);
- if (rc < 0)
- return -1;
+ rc = xmm626_hsic_modem_data_send(device_fd, firmware_data,
+ firmware_size,
+ XMM626_FIRMWARE_ADDRESS);
+ if (rc < 0)
+ return -1;
- return 0;
+ return 0;
}
int xmm626_hsic_nv_data_send(struct ipc_client *client, int device_fd)
{
- void *nv_data = NULL;
- size_t nv_size;
- int rc;
+ void *nv_data = NULL;
+ size_t nv_size;
+ int rc;
- if (client == NULL || device_fd < 0)
- return -1;
+ if (client == NULL || device_fd < 0)
+ return -1;
- nv_size = ipc_client_nv_data_size(client);
- if (nv_size == 0)
- return -1;
+ nv_size = ipc_client_nv_data_size(client);
+ if (nv_size == 0)
+ return -1;
- nv_data = ipc_nv_data_load(client);
- if (nv_data == NULL) {
- ipc_client_log(client, "Loading nv_data failed");
- goto error;
- }
- ipc_client_log(client, "Loaded nv_data");
+ nv_data = ipc_nv_data_load(client);
+ if (nv_data == NULL) {
+ ipc_client_log(client, "Loading nv_data failed");
+ goto error;
+ }
+ ipc_client_log(client, "Loaded nv_data");
- rc = xmm626_hsic_modem_data_send(device_fd, nv_data, nv_size, XMM626_NV_DATA_ADDRESS);
- if (rc < 0)
- goto error;
+ rc = xmm626_hsic_modem_data_send(device_fd, nv_data, nv_size,
+ XMM626_NV_DATA_ADDRESS);
+ if (rc < 0)
+ goto error;
- rc = 0;
- goto complete;
+ rc = 0;
+ goto complete;
error:
- rc = -1;
+ rc = -1;
complete:
- if (nv_data != NULL)
- free(nv_data);
+ if (nv_data != NULL)
+ free(nv_data);
- return rc;
+ return rc;
}
int xmm626_hsic_hw_reset_send(struct ipc_client *client, int device_fd)
{
- unsigned int hw_reset_data;
- int hw_reset_size;
- int rc;
+ unsigned int hw_reset_data;
+ int hw_reset_size;
+ int rc;
- if (client == NULL || device_fd < 0)
- return -1;
+ if (client == NULL || device_fd < 0)
+ return -1;
- hw_reset_data = XMM626_HW_RESET_MAGIC;
- hw_reset_size = sizeof(hw_reset_data);
+ hw_reset_data = XMM626_HW_RESET_MAGIC;
+ hw_reset_size = sizeof(hw_reset_data);
- rc = xmm626_hsic_command_send(device_fd, XMM626_COMMAND_HW_RESET, &hw_reset_data, hw_reset_size, XMM626_HSIC_HW_RESET_SIZE, 0);
- if (rc < 0)
- return -1;
+ rc = xmm626_hsic_command_send(device_fd, XMM626_COMMAND_HW_RESET,
+ &hw_reset_data, hw_reset_size,
+ XMM626_HSIC_HW_RESET_SIZE, 0);
+ if (rc < 0)
+ return -1;
- return 0;
+ return 0;
}
-
-// vim:ts=4:sw=4:expandtab
diff --git a/samsung-ipc/modems/xmm626/xmm626_hsic.h b/samsung-ipc/modems/xmm626/xmm626_hsic.h
index b35e1ba..6385cdc 100644
--- a/samsung-ipc/modems/xmm626/xmm626_hsic.h
+++ b/samsung-ipc/modems/xmm626/xmm626_hsic.h
@@ -21,49 +21,47 @@
#ifndef __XMM626_HSIC_H__
#define __XMM626_HSIC_H__
-#define XMM626_HSIC_BOOT0_ACK 0xF0
-#define XMM626_HSIC_PSI_UNKNOWN_COUNT 22
-#define XMM626_HSIC_PSI_CRC_ACK 0x01
-#define XMM626_HSIC_PSI_CRC_ACK_COUNT 2
-#define XMM626_HSIC_PSI_ACK 0xAA00
-#define XMM626_HSIC_EBL_SIZE_ACK 0xCCCC
-#define XMM626_HSIC_EBL_ACK 0xA551
-#define XMM626_HSIC_EBL_CHUNK 0x4000
-#define XMM626_HSIC_PORT_CONFIG_SIZE 0x4C
-#define XMM626_HSIC_SET_PORT_CONFIG_SIZE 0x800
-#define XMM626_HSIC_SEC_START_SIZE 0x4000
-#define XMM626_HSIC_SEC_END_SIZE 0x4000
-#define XMM626_HSIC_HW_RESET_SIZE 0x4000
-#define XMM626_HSIC_FLASH_SET_ADDRESS_SIZE 0x4000
-#define XMM626_HSIC_FLASH_WRITE_BLOCK_SIZE 0x4000
-#define XMM626_HSIC_MODEM_DATA_CHUNK 0x4000
+#define XMM626_HSIC_BOOT0_ACK 0xF0
+#define XMM626_HSIC_PSI_UNKNOWN_COUNT 22
+#define XMM626_HSIC_PSI_CRC_ACK 0x01
+#define XMM626_HSIC_PSI_CRC_ACK_COUNT 2
+#define XMM626_HSIC_PSI_ACK 0xAA00
+#define XMM626_HSIC_EBL_SIZE_ACK 0xCCCC
+#define XMM626_HSIC_EBL_ACK 0xA551
+#define XMM626_HSIC_EBL_CHUNK 0x4000
+#define XMM626_HSIC_PORT_CONFIG_SIZE 0x4C
+#define XMM626_HSIC_SET_PORT_CONFIG_SIZE 0x800
+#define XMM626_HSIC_SEC_START_SIZE 0x4000
+#define XMM626_HSIC_SEC_END_SIZE 0x4000
+#define XMM626_HSIC_HW_RESET_SIZE 0x4000
+#define XMM626_HSIC_FLASH_SET_ADDRESS_SIZE 0x4000
+#define XMM626_HSIC_FLASH_WRITE_BLOCK_SIZE 0x4000
+#define XMM626_HSIC_MODEM_DATA_CHUNK 0x4000
struct xmm626_hsic_psi_header {
- unsigned char magic;
- unsigned short length;
- unsigned char padding;
+ unsigned char magic;
+ unsigned short length;
+ unsigned char padding;
} __attribute__((packed));
struct xmm626_hsic_command_header {
- unsigned short checksum;
- unsigned short code;
- unsigned int data_size;
+ unsigned short checksum;
+ unsigned short code;
+ unsigned int data_size;
} __attribute__((packed));
int xmm626_hsic_psi_send(struct ipc_client *client, int device_fd,
- const void *psi_data, unsigned short psi_size);
+ const void *psi_data, unsigned short psi_size);
int xmm626_hsic_ebl_send(struct ipc_client *client, int device_fd,
- const void *ebl_data, size_t ebl_size);
+ const void *ebl_data, size_t ebl_size);
int xmm626_hsic_port_config_send(struct ipc_client *client, int device_fd);
int xmm626_hsic_sec_start_send(struct ipc_client *client, int device_fd,
- const void *sec_data, size_t sec_size);
+ const void *sec_data, size_t sec_size);
int xmm626_hsic_sec_end_send(struct ipc_client *client, int device_fd);
int xmm626_hsic_firmware_send(struct ipc_client *client, int device_fd,
- const void *firmware_data, size_t firmware_size);
+ const void *firmware_data, size_t firmware_size);
int xmm626_hsic_nv_data_send(struct ipc_client *client, int device_fd);
int xmm626_hsic_hw_reset_send(struct ipc_client *client, int device_fd);
-#endif
-
-// vim:ts=4:sw=4:expandtab
+#endif /* __XMM626_HSIC_H__ */
diff --git a/samsung-ipc/modems/xmm626/xmm626_modem_link_device_hsic.h b/samsung-ipc/modems/xmm626/xmm626_modem_link_device_hsic.h
index a8acca8..f2421e0 100644
--- a/samsung-ipc/modems/xmm626/xmm626_modem_link_device_hsic.h
+++ b/samsung-ipc/modems/xmm626/xmm626_modem_link_device_hsic.h
@@ -27,26 +27,26 @@ enum {
};
/* each pipe has 2 ep for in/out */
-#define LINKPM_DEV_NUM (IF_USB_DEVNUM_MAX * 2)
-/******************/
+#define LINKPM_DEV_NUM (IF_USB_DEVNUM_MAX * 2)
+/*******************/
/* xmm626 specific */
#define IOCTL_LINK_CONTROL_ENABLE _IO('o', 0x30)
#define IOCTL_LINK_CONTROL_ACTIVE _IO('o', 0x31)
-#define IOCTL_LINK_GET_HOSTWAKE _IO('o', 0x32)
+#define IOCTL_LINK_GET_HOSTWAKE _IO('o', 0x32)
#define IOCTL_LINK_CONNECTED _IO('o', 0x33)
#define IOCTL_LINK_SET_BIAS_CLEAR _IO('o', 0x34)
/* VID,PID for IMC - XMM626, XMM6262*/
-#define IMC_BOOT_VID 0x058b
-#define IMC_BOOT_PID 0x0041
-#define IMC_MAIN_VID 0x1519
-#define IMC_MAIN_PID 0x0020
+#define IMC_BOOT_VID 0x058b
+#define IMC_BOOT_PID 0x0041
+#define IMC_MAIN_VID 0x1519
+#define IMC_MAIN_PID 0x0020
/* VID,PID for STE - M7400 */
-#define STE_BOOT_VID 0x04cc
-#define STE_BOOT_PID 0x7400
-#define STE_MAIN_VID 0x04cc
-#define STE_MAIN_PID 0x2333
+#define STE_BOOT_VID 0x04cc
+#define STE_BOOT_PID 0x7400
+#define STE_MAIN_VID 0x04cc
+#define STE_MAIN_PID 0x2333
enum {
BOOT_DOWN = 0,
@@ -58,6 +58,6 @@ enum ch_state {
STATE_RESUMED,
};
-#define HOSTWAKE_TRIGLEVEL 0
+#define HOSTWAKE_TRIGLEVEL 0
-#endif
+#endif /* __MODEM_LINK_DEVICE_USB_H__ */
--
2.27.0
More information about the Replicant
mailing list