[Feature][SPI] Add SE XA2000 AT engineering test commands

Only Configure: Yes
Affected branch: DSDS
Affected module: SPI
Is it affected on both ZXIC and MTK: only MTK
Self-test: Yes
Doc Update: No

Change-Id: Ida06a98e0f9c13600bb5a63602b33cb21ed9f3d3
diff --git a/common_src/lib/liblynq-at-factory/lynq_at_factory.cpp b/common_src/lib/liblynq-at-factory/lynq_at_factory.cpp
index 82a3ad8..f894d3e 100755
--- a/common_src/lib/liblynq-at-factory/lynq_at_factory.cpp
+++ b/common_src/lib/liblynq-at-factory/lynq_at_factory.cpp
@@ -10,6 +10,11 @@
 #include <net/if.h>

 #include <errno.h>

 #include <log/log.h>

+#include <fcntl.h>

+#include <unistd.h>

+#include <stdint.h>

+#include <sys/ioctl.h>

+#include <linux/spi/spidev.h>

 #include <liblog/lynq_deflog.h>

 #include "include/libat/lynq_at_factory.h"

 

@@ -790,6 +795,87 @@
     pclose(fp_sim2);

 }

 

+/*dongyu@2024.7.23 Add SE XA2000 AT engineering test commands start*/

+void lynq_handle_hsm_xa2000()

+{

+    char command[256] = {0};

+

+    uint8_t tx[] = {0x5A, 0xCF, 0x00, 0x00, 0x3B, 0xB5};

+    uint8_t rx[sizeof(tx)] = {0};

+    uint8_t expected_cmd[] = {0xA5, 0xEF, 0x00, 0x00, 0xD2, 0x73};

+

+    sprintf(command, "echo out 205 1 > /sys/devices/platform/10005000.pinctrl/mt_gpio");

+    system(command);

+    usleep(100000);

+    sprintf(command, "echo out 200 1 > /sys/devices/platform/10005000.pinctrl/mt_gpio");

+    system(command);

+    usleep(100000);

+    sprintf(command, "echo out 200 0 > /sys/devices/platform/10005000.pinctrl/mt_gpio");

+    system(command);

+    usleep(100000);

+    sprintf(command, "echo out 200 1 > /sys/devices/platform/10005000.pinctrl/mt_gpio");

+    system(command);

+

+    struct spi_ioc_transfer tr = {

+        .tx_buf = (unsigned long)tx,

+        .rx_buf = (unsigned long)rx,

+        .len = sizeof(tx),

+        .speed_hz = 1000000,

+        .delay_usecs = 0,

+        .bits_per_word = 8,

+    };

+    int spi_fd = open("/dev/spidev1.0", O_RDWR);

+    if (spi_fd < 0)

+    {

+        perror("Failed to open the SPI device");

+        lynq_response_error(2);

+        return;

+    }

+

+    int attempts = 0;

+    const int max_attempts = 10;

+    while (attempts < max_attempts)

+    {

+        if (ioctl(spi_fd, SPI_IOC_MESSAGE(1), &tr) < 1)

+        {

+            perror("Failed to send SPI message");

+            close(spi_fd);

+            lynq_response_error(2);

+            return;

+        }

+

+        if (memcmp(rx, expected_cmd, sizeof(rx)) == 0) {

+            char flag[256] = "Reset data: ";

+            for (int i = 0; i < sizeof(rx); i++) {

+                char temp[10];

+                sprintf(temp, "0x%02X ", rx[i]);

+                strcat(flag, temp);

+            }

+            if(handle_output != NULL)

+            {

+                handle_output(flag, strlen(flag), Response);

+            }

+            break;

+        }

+        attempts++;

+    }

+    close(spi_fd);

+

+    if (attempts >= max_attempts)

+    {

+        lynq_response_error(100);

+        return;

+    }

+

+    sprintf(command, "echo out 205 0 > /sys/devices/platform/10005000.pinctrl/mt_gpio");

+    system(command);

+    usleep(100000);

+    sprintf(command, "echo out 200 0 > /sys/devices/platform/10005000.pinctrl/mt_gpio");

+    system(command);

+

+    lynq_response_ok();

+}

+/*dongyu@2024.7.23 Add SE XA2000 AT engineering test commands end*/

 

 static Command commands[] = 

 {

@@ -803,6 +889,7 @@
     {"sgmii",lynq_handle_sgmii},

     {"usb",lynq_handle_usb},

     {"iccid",lynq_handle_iccid_dual},

+    {"XA2000",lynq_handle_hsm_xa2000},

     {NULL, NULL}

 };