Merge "[Bugfix][T106BUG-662]Fixed the problem that the profile_idx form callback function is wrong"
diff --git a/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-autosuspend/files/autosuspend_wakeup_count.c b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-autosuspend/files/autosuspend_wakeup_count.c
index ca823c2..c7cc274 100755
--- a/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-autosuspend/files/autosuspend_wakeup_count.c
+++ b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-autosuspend/files/autosuspend_wakeup_count.c
@@ -236,11 +236,29 @@
#endif
#ifdef MOBILETEK_TARGET_PLATFORM_T106
+int t106_set_lowpwr(int state)
+{
+ int ret;
+ char rsp[128];
+ char cmdstr[32];
+ if(state == 0)
+ {
+ strcpy(cmdstr, "AT+ZLOWPWR=0\r\n");
+ }
+ else
+ {
+ strcpy(cmdstr, "AT+ZLOWPWR=1\r\n");
+ }
+ ret = sc_at_send(1,cmdstr,rsp,sizeof(rsp));
+ printf("AT+ZLOWPWR result:%d %s\n",ret,rsp);
+ return ret;
+}
+
int t106_set_blacklist(int blacklist_state)
{
int ret;
char rsp[128];
- char cmdstr[256];
+ char cmdstr[128];
if(blacklist_state == 0)
{
strcpy(cmdstr, "AT+SHELL=echo \"+CREG:+CGREG:+CEREG:^MODE:\" > /sys/module/at_io/parameters/at_psm_filter\r\n");
@@ -249,9 +267,8 @@
{
strcpy(cmdstr, "AT+SHELL=echo \"\" > /sys/module/at_io/parameters/at_psm_filter\r\n");
}
- printf("cmd:%s\n",cmdstr);
ret = sc_at_send(1,cmdstr,rsp,sizeof(rsp));
- printf("sc_at_send result:%d %s\n",ret,rsp);
+ printf("AT+SHELL=echo result:%d %s\n",ret,rsp);
return ret;
}
@@ -318,7 +335,8 @@
RLOGD("t106_early_suspend start\n");
ret=lynq_sleep_status(0);
RLOGD("lynq_get_sleep_status ret=%d\n", ret);
-
+ ret = t106_set_lowpwr(1);
+ RLOGD("t106_set_lowpwr status ret=%d\n", ret);
system("zlog_nvctrl -m 1");
ret = t106_set_whitelist();
if(ret)
@@ -350,7 +368,8 @@
RLOGD("sc_mnet_whitelist_clear ret=%d\n", ret);
}
system("zlog_nvctrl -m 0");
-
+ ret = t106_set_lowpwr(0);
+ RLOGD("t106_set_lowpwr status ret=%d\n", ret);
ret=lynq_sleep_status(1);
RLOGD("lynq_get_sleep_status ret=%d\n", ret);
diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-qser-fota/lynq-qser-fota.cpp b/cap/zx297520v3/src/lynq/lib/liblynq-qser-fota/lynq-qser-fota.cpp
index 10f967a..1589c5f 100755
--- a/cap/zx297520v3/src/lynq/lib/liblynq-qser-fota/lynq-qser-fota.cpp
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-qser-fota/lynq-qser-fota.cpp
@@ -537,14 +537,15 @@
if(ret != 0)
{
LYINFLOG("fota update fail!\n");
+ qser_wakelock_unlock(lock_fd);
+ tmp = qser_wakelock_destroy(lock_fd);
+ if(tmp < 0)
+ {
+ LYERRLOG("Destroy fota wakelock failed");
+ }
}
- qser_wakelock_unlock(lock_fd);
- tmp = qser_wakelock_destroy(lock_fd);
- if(tmp < 0)
- {
- LYERRLOG("Destroy fota wakelock failed");
- }
+
return ret;
}
diff --git a/cap/zx297520v3/src/lynq/lib/libpoweralarm/libpoweralarm.cpp b/cap/zx297520v3/src/lynq/lib/libpoweralarm/libpoweralarm.cpp
index 26f57be..af24cd9 100755
--- a/cap/zx297520v3/src/lynq/lib/libpoweralarm/libpoweralarm.cpp
+++ b/cap/zx297520v3/src/lynq/lib/libpoweralarm/libpoweralarm.cpp
@@ -24,15 +24,18 @@
extern "C" {
#endif
+#include "sc_rtc_timer.h"
+
#define USER_LOG_TAG "LYNQ_POWERALARM"
#define MIN_TIME 1
#define MAX_TIME 268435456
-typedef int (*sc_rtc_timer_exp_cb)(unsigned int src_id, int rtc_id);
+//typedef int (*sc_rtc_timer_exp_cb)(unsigned int src_id, int rtc_id);
typedef int (*lynq_wakealarm_add_cb)(unsigned int src_id, int rtc_id);
+/*
extern int sc_rtc_timer_init(void);
extern int sc_rtc_timer_uninit(void );
extern int sc_rtc_timer_add(int srcid, int rtc_id, unsigned long ulSec, sc_rtc_timer_exp_cb rtc_notify);
@@ -44,6 +47,7 @@
extern int sc_rtc_add_poweroff_alarm(int srcid, int alarm_modid, int rtc_id, struct tm *utc_sec, sc_rtc_timer_exp_cb rtc_notify);
+*/
/*****************************************
* @brief:lynq_rtc_service_init
diff --git a/cap/zx297520v3/zxic_code/zxic_source/linux-5.10/drivers/dma/sc/zx297520v3_dma.c b/cap/zx297520v3/zxic_code/zxic_source/linux-5.10/drivers/dma/sc/zx297520v3_dma.c
index a1ebb94..6ef00d8 100644
--- a/cap/zx297520v3/zxic_code/zxic_source/linux-5.10/drivers/dma/sc/zx297520v3_dma.c
+++ b/cap/zx297520v3/zxic_code/zxic_source/linux-5.10/drivers/dma/sc/zx297520v3_dma.c
@@ -117,7 +117,7 @@
#define MAX(a,b) ((a) > (b) ? (a) : (b))
-/* Ò»¸öÁ´±íÖÐ×î´óµÄÁ´±íÏî¸öÊý */
+/* һ��������������������� */
#define MAX_LLI_PARA_CNT (32)
@@ -1088,13 +1088,15 @@
dmac_ptr->dma_chan[channel_id].desc.callback(dmac_ptr->dma_chan[channel_id].desc.callback_param);
#else
/* schedule tasklet on this channel */
- #ifdef _USE_VEHICLE_DC
- if((channel_id == DMA_CH_UART0_RX) || (channel_id == DMA_CH_UART2_RX)){
+ /* yu.dong@20240617 [T106BUG-641] SPI packet loss issue, increase kernel buffer and read all cached data away, no data loss start */
+ #ifdef _USE_VEHICLE_DC || _USE_VEHICLE_DC_REF
+ if((channel_id == DMA_CH_UART0_RX) || (channel_id == DMA_CH_UART2_RX) || (channel_id == DMA_CH_SSP0_RX)){
if (dmac_ptr->dma_chan[channel_id].desc.callback)
dmac_ptr->dma_chan[channel_id].desc.callback(dmac_ptr->dma_chan[channel_id].desc.callback_param);
}else
tasklet_schedule(&dmac_ptr->dma_chan[channel_id].tasklet);
#else
+ /* yu.dong@20240617 [T106BUG-641] SPI packet loss issue, increase kernel buffer and read all cached data away, no data loss end */
tasklet_schedule(&dmac_ptr->dma_chan[channel_id].tasklet);
#endif
#endif
diff --git a/cap/zx297520v3/zxic_code/zxic_source/linux-5.10/drivers/spi/spi-zx29.c b/cap/zx297520v3/zxic_code/zxic_source/linux-5.10/drivers/spi/spi-zx29.c
index 9d3f781..d570db1 100755
--- a/cap/zx297520v3/zxic_code/zxic_source/linux-5.10/drivers/spi/spi-zx29.c
+++ b/cap/zx297520v3/zxic_code/zxic_source/linux-5.10/drivers/spi/spi-zx29.c
@@ -158,6 +158,8 @@
#define SPI_INTR_EN_MASK_TX_EMPTY_IE (0x1UL << 3)
#define SPI_INTR_EN_MASK_RX_THRES_IE (0x1UL << 4)
#define SPI_INTR_EN_MASK_TX_THRES_IE (0x1UL << 5)
+//yu.dong@20240617 [T106BUG-641] SPI packet loss problem, add kernel buffer scheme.
+#define SPI_INTR_EN_MASK_MST_EOT_IE (0x1UL << 6)
/*
* SPI Interrupt Status Register OR Interrupt Clear Register - SPI_INTR_SR_SCLR
@@ -391,9 +393,10 @@
#endif
struct semaphore sema_dma;
/* yu.dong@20240521 [T106BUG-616] SPI set to slave mode for read will get stuck start */
- wait_queue_head_t wait;
- int trans_done;
+ wait_queue_head_t wait;
+ int trans_done;
/* yu.dong@20240521 [T106BUG-616] SPI set to slave mode for read will get stuck end */
+
u8 iface_mode;
#define SPI_MOTO_FORMAT 0x00
#define SPI_TI_FORMAT 0x01
@@ -875,14 +878,13 @@
struct zx29_spi *zx29spi = (struct zx29_spi *)data;
//printk(KERN_INFO "spi:dma transfer complete. %X-%X-%x\n", zx29spi->dma_running, readl((SPI_INTR_SR_OFFSET+zx29spi->virtbase)),readl((SPI_FIFO_SR_OFFSET+zx29spi->virtbase)));
/* yu.dong@20240521 [T106BUG-616] SPI set to slave mode for read will get stuck start */
- //up(&zx29spi->sema_dma);
- if(zx29spi->master->slave == true){
+ //up(&zx29spi->sema_dma);
+ if(zx29spi->master->slave == true){
wake_up(&zx29spi->wait);
zx29spi->trans_done = true;
- }else
- {
+ }else{
up(&zx29spi->sema_dma);
- }
+ }
/* yu.dong@20240521 [T106BUG-616] SPI set to slave mode for read will get stuck end */
}
@@ -1207,6 +1209,7 @@
for(i = 0;i <= (len-8);i+=8) {
printk("%02x %02x %02x %02x %02x %02x %02x %02x \r\n",p[i],p[i+1],p[i+2],p[i+3],p[i+4],p[i+5],p[i+6],p[i+7]);
}
+ printk("\n");
}
}
@@ -1313,65 +1316,84 @@
}
/* yu.dong@20240521 [T106BUG-616] SPI set to slave mode for read will get stuck start */
+#define SSP0_PARA_BASE_ADDR 0x1400030
#define SSP1_PARA_BASE_ADDR 0x1400048
-
-#define SSP_MASK_SW_WRST (0x1L << 9)
-#define SSP_MASK_SW_PRST (0x1L << 8)
-
-static int zx29_slave_ctrl_reset(struct zx29_spi *zx29spi) {
+#define SSP_MASK_SW_WRST (0x1L << 9)
+#define SSP_MASK_SW_PRST (0x1L << 8)
+static int zx29_slave_ctrl_reset(struct zx29_spi *zx29spi)
+{
void __iomem *addr = NULL;
ktime_t k_time_start = 0;
ktime_t diff_ns = 0;
volatile unsigned int val = 0;
+ if(!strcmp(zx29spi->pdev->name,"1410000.ssp")) {
addr = ioremap(SSP1_PARA_BASE_ADDR, 0x1000);
+ }else{
+ addr = ioremap(SSP0_PARA_BASE_ADDR, 0x1000);
+ }
- if (addr) {
+ if(addr){
val = *(volatile unsigned int *)addr;
- *(volatile unsigned int *)addr = val & (~(SSP_MASK_SW_WRST | SSP_MASK_SW_PRST));
+ //dev_info(&zx29spi->pdev->dev, "val = 0x%x 0x%x\n",val,(~(SSP_MASK_SW_WRST|SSP_MASK_SW_PRST)));
+ *(volatile unsigned int *)addr = val & (~(SSP_MASK_SW_WRST|SSP_MASK_SW_PRST));
k_time_start = ktime_get();
do {
- diff_ns = ktime_sub(ktime_get(), k_time_start);
- val = readl((SPI_COM_CTRL_OFFSET + zx29spi->virtbase)) >> 1 & 0x1;
+ diff_ns = ktime_sub(ktime_get(),k_time_start);
+ val = readl((SPI_COM_CTRL_OFFSET+zx29spi->virtbase))>> 1 & 0x1;
cpu_relax();
- } while (val && diff_ns < 100000000); // 100ms
+ }while(val && diff_ns < 100000000); //100ms
- if (diff_ns >= 100000000)
+ if(diff_ns >= 100000000)
dev_info(&zx29spi->pdev->dev, "zx29_slave_assert_ctrl failed!!! \n");
else
dev_info(&zx29spi->pdev->dev, "zx29_slave_assert_ctrl success! \n");
+
val = *(volatile unsigned int *)addr;
- *(volatile unsigned int *)addr = val | (SSP_MASK_SW_WRST | SSP_MASK_SW_PRST);
+ *(volatile unsigned int *)addr = val|(SSP_MASK_SW_WRST|SSP_MASK_SW_PRST);
udelay(500);
+
+ iounmap(addr);
}
return 0;
}
-static int zx29_slave_ctrl_reinit(struct zx29_spi *zx29spi) {
+static int zx29_slave_ctrl_reinit(struct zx29_spi *zx29spi)
+{
volatile unsigned int regval;
+ ktime_t k_time_start = 0;
+ ktime_t diff_ns = 0;
zx29_slave_ctrl_reset(zx29spi);
/* Disable SPI */
- regval = readl((SPI_COM_CTRL_OFFSET + zx29spi->virtbase)) & (~SPI_COM_CTRL_MASK_SSPE);
- writel(regval, (SPI_COM_CTRL_OFFSET + zx29spi->virtbase));
+ regval = readl((SPI_COM_CTRL_OFFSET+zx29spi->virtbase)) & (~SPI_COM_CTRL_MASK_SSPE);
+ writel(regval, (SPI_COM_CTRL_OFFSET+zx29spi->virtbase));
load_spi_default_config(zx29spi);
writel(0, (SPI_TIMING_OFFSET + zx29spi->virtbase));
- if (!strcmp(zx29spi->pdev->name, "1410000.ssp")) {
- regval = readl((SPI_FMT_CTRL_OFFSET + zx29spi->virtbase)) & (~(0x1 << 12));
- writel(regval, (SPI_FMT_CTRL_OFFSET + zx29spi->virtbase));
- dev_info(&zx29spi->pdev->dev, "%s set non-camera mode regval:0x%x \n", zx29spi->pdev->name, regval);
+ if(!strcmp(zx29spi->pdev->name,"1410000.ssp")) {
+ regval = readl((SPI_FMT_CTRL_OFFSET+zx29spi->virtbase))&(~(0x1<<12));
+ writel(regval, (SPI_FMT_CTRL_OFFSET+zx29spi->virtbase));
+ dev_info(&zx29spi->pdev->dev," %s set non-camera mode regval:0x%x \n",zx29spi->pdev->name,regval);
}
- writel(readl((SPI_COM_CTRL_OFFSET + zx29spi->virtbase)) | SPI_COM_CTRL_MASK_SSPE, (SPI_COM_CTRL_OFFSET + zx29spi->virtbase));
- while (((readl((SPI_COM_CTRL_OFFSET + zx29spi->virtbase)) >> 4) & 0x1) == 0);
+ writel(readl((SPI_COM_CTRL_OFFSET+zx29spi->virtbase)) | SPI_COM_CTRL_MASK_SSPE, (SPI_COM_CTRL_OFFSET+zx29spi->virtbase));
+ k_time_start = ktime_get();
+ do{
+ diff_ns = ktime_sub(ktime_get(),k_time_start);
+ regval = ((readl((SPI_COM_CTRL_OFFSET+zx29spi->virtbase))>> 4)&0x1);
+ cpu_relax();
+ }while((regval == 0) && diff_ns < 100000000);
- dev_info(&zx29spi->pdev->dev, "ssp enabled \n", regval);
+ if(diff_ns >= 100000000)
+ dev_info(&zx29spi->pdev->dev, "wait sspen timeout!!! \n");
+ else
+ dev_info(&zx29spi->pdev->dev,"ssp enabled \n",regval);
return 0;
}
@@ -1405,7 +1427,7 @@
/* If we're using DMA, set up DMA here */
if (zx29spi->cur_chip->enable_dma) {
/* Configure DMA transfer */
- zx29spi->trans_done = false; //yu.dong@20240521 [T106BUG-616] SPI set to slave mode for read will get stuck
+ zx29spi->trans_done = false; //yu.dong@20240521 [T106BUG-616] SPI set to slave mode for read will get stuck
ret = configure_dma(zx29spi);
if (ret) {
dev_err(&zx29spi->pdev->dev, "configuration of DMA failed, fall back to interrupt mode\n");
@@ -1418,17 +1440,18 @@
extern void spi_dev_send_dma_cfg_down(struct spi_device *spi);
struct spi_device *spi = zx29spi->cur_msg->spi;
spi_dev_send_dma_cfg_down(spi);
- /* yu.dong@20240521 [T106BUG-616] SPI set to slave mode for read will get stuck start */
- //down(&zx29spi->sema_dma);
- ret = wait_event_freezable(zx29spi->wait, zx29spi->trans_done);
- if(ret){
- terminate_dma(zx29spi);
- disable_irq_nosync(zx29spi->irq);
- zx29spi->dma_running = 0;
- zx29_slave_ctrl_reinit(zx29spi);
- goto err_config_dma;
- }
- /* yu.dong@20240521 [T106BUG-616] SPI set to slave mode for read will get stuck end */
+ /* yu.dong@20240521 [T106BUG-616] SPI set to slave mode for read will get stuck start */
+ //down(&zx29spi->sema_dma);
+ ret = wait_event_freezable(zx29spi->wait, zx29spi->trans_done);
+ if(ret){
+ terminate_dma(zx29spi);
+ disable_irq_nosync(zx29spi->irq);
+ zx29spi->dma_running = 0;
+ zx29_slave_ctrl_reinit(zx29spi);
+ goto err_config_dma;
+
+ }
+ /* yu.dong@20240521 [T106BUG-616] SPI set to slave mode for read will get stuck end */
//printk("COM=0x%x,FMT=0x%x,FIFO_CTL=0x%x,FIFO_SR=0x%x\n",readl((SPI_COM_CTRL_OFFSET+zx29spi->virtbase)),readl((SPI_FMT_CTRL_OFFSET+zx29spi->virtbase)),readl((SPI_FIFO_CTRL_OFFSET+zx29spi->virtbase)),readl((SPI_FIFO_SR_OFFSET+zx29spi->virtbase)));
@@ -1961,8 +1984,252 @@
return ret;
}
+/* yu.dong@20240617 [T106BUG-641] SPI packet loss problem, add kernel buffer scheme start */
+#define SPI_SLVAE_RX_BUFF_SIZE 4096
+#define SPI_SLVAE_RX_MAX_PACK_NUM 15
+#define SPI_SLVAE_RX_PACK_LEN 146
+#define SPI_SLVAE_RX_LIST_BUFF_LEN (SPI_SLVAE_RX_MAX_PACK_NUM*SPI_SLVAE_RX_PACK_LEN)
+static dma_channel_def slave_rx_conf[SPI_SLVAE_RX_MAX_PACK_NUM] = {0};
+//yu.dong@20240617 [T106BUG-641] SPI packet loss issue, increase kernel buffer and read all cached data away, no data loss.
+#define SPI_MAGIC 0x55555555
+static bool rxbuf_is_free_space(struct spi_device *spi)
+{
+ if (spi->recv_pos < spi->rd_pos) {
+ if ((spi->rd_pos - spi->recv_pos) > SPI_SLVAE_RX_PACK_LEN)
+ return 1;
+ else
+ return 0;
+ }
+ else {
+ if ((SPI_SLVAE_RX_BUFF_SIZE - spi->recv_pos + spi->rd_pos ) > SPI_SLVAE_RX_PACK_LEN)
+ return 1;
+ else
+ return 0;
+ }
+}
+/* yu.dong@20240617 [T106BUG-641] SPI packet loss issue, increase kernel buffer and read all cached data away, no data loss start */
+static void dma_cyclic_callback(void *data)
+{
+ struct spi_device *spi = (struct spi_device *)data;
+ struct zx29_spi *zx29spi = NULL;
+ int index = 0;
+ unsigned int end = 0;
+ zx29spi = spi_master_get_devdata(spi->master);
+ zx29spi->spi_poll_cnt++;
+ end = *(volatile unsigned int *)(spi->cyc_buf +spi->cyc_index * SPI_SLVAE_RX_PACK_LEN + SPI_SLVAE_RX_PACK_LEN - 4);
+ while((end != SPI_MAGIC) && index < SPI_SLVAE_RX_MAX_PACK_NUM) {
+ if(!rxbuf_is_free_space(spi)) {
+ printk("rx_buff not enough space!!!!!");
+ zx29spi->spi_dma_cnt++;
+ break;
+ }else {
+ if((spi->recv_pos + SPI_SLVAE_RX_PACK_LEN) <= SPI_SLVAE_RX_BUFF_SIZE) {
+ memcpy(spi->rx_buf + spi->recv_pos,spi->cyc_buf + spi->cyc_index * SPI_SLVAE_RX_PACK_LEN,SPI_SLVAE_RX_PACK_LEN);
+ }else {
+ memcpy(spi->rx_buf + spi->recv_pos,spi->cyc_buf + spi->cyc_index * SPI_SLVAE_RX_PACK_LEN,SPI_SLVAE_RX_BUFF_SIZE - spi->recv_pos);
+ memcpy(spi->rx_buf,spi->cyc_buf + spi->cyc_index * SPI_SLVAE_RX_PACK_LEN + (SPI_SLVAE_RX_BUFF_SIZE - spi->recv_pos),SPI_SLVAE_RX_PACK_LEN-(SPI_SLVAE_RX_BUFF_SIZE-spi->recv_pos));
+ }
+ *(volatile unsigned int *)(spi->cyc_buf +spi->cyc_index * SPI_SLVAE_RX_PACK_LEN + SPI_SLVAE_RX_PACK_LEN - 4) = SPI_MAGIC;
+ spi->recv_pos = (spi->recv_pos + SPI_SLVAE_RX_PACK_LEN)%SPI_SLVAE_RX_BUFF_SIZE;
+ spi->cyc_index = (spi->cyc_index + 1)%SPI_SLVAE_RX_MAX_PACK_NUM;
+
+ zx29spi->spi_dma_cnt++;
+ index++;
+ end = *(volatile unsigned int *)(spi->cyc_buf +spi->cyc_index * SPI_SLVAE_RX_PACK_LEN + SPI_SLVAE_RX_PACK_LEN - 4);
+ }
+
+ if(spi->is_rd_waiting == true && spi->recv_done == 0) {
+ wake_up(&spi->rd_wait);
+ spi->recv_done = 1;
+ }
+ }
+ if((end != SPI_MAGIC) && index == SPI_SLVAE_RX_MAX_PACK_NUM)
+ printk("cyc_buf be covered!!!!!");
+ return;
+}
+/* yu.dong@20240617 [T106BUG-641] SPI packet loss issue, increase kernel buffer and read all cached data away, no data loss end */
+
+static int zx29_slave_config_dma(struct zx29_spi *zx29spi,struct spi_device *spi)
+{
+ struct chip_data *chip = NULL;
+ struct dma_chan *rxchan = NULL;
+ struct dma_async_tx_descriptor *rxdesc;
+ unsigned short transfer_len = SPI_SLVAE_RX_PACK_LEN;
+ int i;
+
+ chip = zx29spi->cur_chip = spi->controller_state;
+
+ if (spi->rx_dma)
+ flush(zx29spi);
+ writel(CLEAR_ALL_INTERRUPTS, (SPI_INTR_SR_OFFSET+zx29spi->virtbase));
+ writel((chip->fifo_ctrl | SPI_FIFO_CTRL_MASK_RX_DMA_EN), (SPI_FIFO_CTRL_OFFSET+zx29spi->virtbase));
+
+ zx29spi->write = zx29spi->tx ? zx29spi->cur_chip->write : WRITING_NULL;
+ zx29spi->read = zx29spi->rx ? zx29spi->cur_chip->read : READING_NULL;
+ rxchan = zx29spi->dma_rx_channel;
+ /* Check that the channels are available */
+ if (!rxchan)
+ return -ENODEV;
+
+ /*
+ * If supplied, the DMA burstsize should equal the FIFO trigger level.
+ * Notice that the DMA engine uses one-to-one mapping. Since we can
+ * not trigger on 2 elements this needs explicit mapping rather than
+ * calculation.
+ */
+ for(i = 0;i < SPI_SLVAE_RX_MAX_PACK_NUM;i++) {
+ switch (zx29spi->rx_lev_trig) {
+ case SPI_RX_1_OR_MORE_ELEM:
+ slave_rx_conf[i].dma_control.src_burst_len = DMA_BURST_LEN_1;
+ slave_rx_conf[i].dma_control.dest_burst_len = DMA_BURST_LEN_1;
+ break;
+ case SPI_RX_4_OR_MORE_ELEM:
+ slave_rx_conf[i].dma_control.src_burst_len = DMA_BURST_LEN_4;
+ slave_rx_conf[i].dma_control.dest_burst_len = DMA_BURST_LEN_4;
+ break;
+ case SPI_RX_8_OR_MORE_ELEM:
+ slave_rx_conf[i].dma_control.src_burst_len = DMA_BURST_LEN_8;
+ slave_rx_conf[i].dma_control.dest_burst_len = DMA_BURST_LEN_8;
+ break;
+ case SPI_RX_16_OR_MORE_ELEM:
+ slave_rx_conf[i].dma_control.src_burst_len = DMA_BURST_LEN_16;
+ slave_rx_conf[i].dma_control.dest_burst_len = DMA_BURST_LEN_16;
+ break;
+ case SPI_RX_32_OR_MORE_ELEM:
+ slave_rx_conf[i].dma_control.src_burst_len = DMA_BURST_LEN_ALL;
+ slave_rx_conf[i].dma_control.dest_burst_len = DMA_BURST_LEN_ALL;
+ break;
+ default:
+ slave_rx_conf[i].dma_control.src_burst_len = zx29spi->vendor->fifodepth >> 1;
+ slave_rx_conf[i].dma_control.dest_burst_len = zx29spi->vendor->fifodepth >> 1;
+ break;
+ }
+
+ switch (zx29spi->read) {
+ case READING_NULL:
+ /* Use the same as for writing */
+ slave_rx_conf[i].dma_control.src_burst_size = DMA_BURST_SIZE_8BIT;
+ slave_rx_conf[i].dma_control.dest_burst_size = DMA_BURST_SIZE_8BIT;
+ slave_rx_conf[i].count = transfer_len;
+ break;
+ case READING_U8:
+ slave_rx_conf[i].dma_control.src_burst_size = DMA_BURST_SIZE_8BIT;
+ slave_rx_conf[i].dma_control.dest_burst_size = DMA_BURST_SIZE_8BIT;
+ slave_rx_conf[i].count = transfer_len;
+ break;
+ case READING_U16:
+ slave_rx_conf[i].dma_control.src_burst_size = DMA_BURST_SIZE_16BIT;
+ slave_rx_conf[i].dma_control.dest_burst_size = DMA_BURST_SIZE_16BIT;
+ slave_rx_conf[i].count = transfer_len;
+ break;
+ case READING_U32:
+ slave_rx_conf[i].dma_control.src_burst_size = DMA_BURST_SIZE_32BIT;
+ slave_rx_conf[i].dma_control.dest_burst_size = DMA_BURST_SIZE_32BIT;
+ slave_rx_conf[i].count = transfer_len;
+ break;
+ }
+
+ slave_rx_conf[i].src_addr = (SPI_DR_OFFSET+zx29spi->phybase);
+ slave_rx_conf[i].dma_control.tran_mode = TRAN_PERI_TO_MEM;
+ slave_rx_conf[i].dma_control.irq_mode = DMA_ALL_IRQ_ENABLE;
+ slave_rx_conf[i].dest_addr = (unsigned int)spi->rx_dma + transfer_len*i;
+ slave_rx_conf[i].link_addr = 1;
+ //yu.dong@20240617 [T106BUG-641] SPI packet loss issue, increase kernel buffer and read all cached data away, no data loss.
+ *(volatile unsigned int *)(spi->cyc_buf + transfer_len*i + transfer_len -4) = SPI_MAGIC;
+ }
+
+ dmaengine_slave_config(rxchan,(struct dma_slave_config*)&slave_rx_conf[0]);
+
+ /* Submit and fire RX and TX with TX last so we're ready to read! */
+ if (spi->rx_dma) {
+ rxdesc = rxchan->device->device_prep_dma_cyclic(rxchan,NULL,SPI_SLVAE_RX_MAX_PACK_NUM * SPI_SLVAE_RX_PACK_LEN, SPI_SLVAE_RX_PACK_LEN,0,0);
+ if (!rxdesc) {
+ printk(KERN_INFO "!!ERROR DESC !!![%s][%d]\n",__func__,__LINE__);
+ dmaengine_terminate_all(rxchan);
+ return -EBUSY;
+ }
+ /* Put the callback on the RX transfer only, that should finish last */
+ rxdesc->callback = dma_cyclic_callback;
+ rxdesc->callback_param = spi;
+ dmaengine_submit(rxdesc);
+ dma_async_issue_pending(rxchan);
+ zx29spi->dma_running = RX_TRANSFER;
+ }
+ return 0;
+}
+
+static int zx29_slave_rd_start(struct spi_device *spi)
+{
+ struct zx29_spi *zx29spi = NULL;
+ struct device *dev;
+ int status = 0;
+ static int wd_wait_queue_init = 0;
+
+ printk("zx29_slave_rd_start...\r\n");
+
+ zx29spi = spi_master_get_devdata(spi->master);
+ dev = &zx29spi->pdev->dev;
+ if (!zx29spi)
+ return -EINVAL;
+
+ spi->cyc_index = 0;
+ spi->rd_pos = spi->recv_pos = 0;
+
+ spi->cyc_buf = dma_alloc_coherent(dev, SPI_SLVAE_RX_BUFF_SIZE, &spi->rx_dma, GFP_KERNEL);
+ if (dma_mapping_error(dev, spi->rx_dma)) {
+ dev_err(dev, "dma_map_single spi rx failed\n");
+ return -ENOMEM;
+ }
+
+ if(wd_wait_queue_init == 0) {
+ init_waitqueue_head(&spi->rd_wait);
+ spi->recv_done = false;
+ spi->is_rd_waiting = false;
+ wd_wait_queue_init = 1;
+ }
+ status = zx29_slave_config_dma(zx29spi,spi);
+
+ return status;
+}
+
+static int zx29_slave_rd_stop(struct spi_device *spi)
+{
+ struct zx29_spi *zx29spi = NULL;
+ struct device *dev;
+ int status = 0;
+ struct chip_data *chip = NULL;
+ struct dma_chan *rxchan = NULL;
+
+ zx29spi = spi_master_get_devdata(spi->master);
+ dev = &zx29spi->pdev->dev;
+ if (!zx29spi)
+ return -EINVAL;
+
+ chip = zx29spi->cur_chip= spi->controller_state;
+ writel(chip->fifo_ctrl, (SPI_FIFO_CTRL_OFFSET+zx29spi->virtbase));
+ rxchan = zx29spi->dma_rx_channel;
+ /* Submit and fire RX and TX with TX last so we're ready to read! */
+ if(spi->rx_dma) {
+ dmaengine_terminate_all(rxchan);
+ zx29spi->dma_running = 0;
+ }
+
+ if(spi->cyc_buf != NULL && spi->rx_dma) {
+ dma_free_coherent(dev, SPI_SLVAE_RX_BUFF_SIZE, spi->cyc_buf, spi->rx_dma);
+ spi->cyc_buf = NULL;
+ }
+
+ spi->cyc_index = 0;
+ spi->rd_pos = spi->recv_pos = 0;
+ spi->recv_done = false;
+ spi->is_rd_waiting = false;
+ printk("zx29_slave_rd_stop...\r\n");
+
+ return status;
+}
+/* yu.dong@20240617 [T106BUG-641] SPI packet loss problem, add kernel buffer scheme end */
static int zx29_prepare_transfer_hardware(struct spi_master *master)
{
@@ -2085,7 +2352,7 @@
};
/*
-* spi ʹÓÃGPIOģʽ¶ÁÈ¡LCD µÄID Begin
+
*/
static void spi_set_gpio_function(int dev_id)
{
@@ -2344,14 +2611,13 @@
ktime_t k_time_start = 0;
ktime_t k_time_end = 0;
ktime_t diff_ns = 0;
-
- if(false == zx29spi->master->slave)
- pm_stay_awake(&zx29spi->pdev->dev);
+ /* yu.dong@20240617 [T106BUG-641] SPI packet loss problem, add kernel buffer scheme start */
regval = readl((SPI_COM_CTRL_OFFSET+zx29spi->virtbase)) & (~SPI_COM_CTRL_MASK_SSPE);
writel(regval, (SPI_COM_CTRL_OFFSET+zx29spi->virtbase));
writel(chip->fmt_ctrl, (SPI_FMT_CTRL_OFFSET+zx29spi->virtbase));
- writel(chip->fifo_ctrl, (SPI_FIFO_CTRL_OFFSET+zx29spi->virtbase));
+ //writel(chip->fifo_ctrl, (SPI_FIFO_CTRL_OFFSET+zx29spi->virtbase));
+ /* yu.dong@20240617 [T106BUG-641] SPI packet loss problem, add kernel buffer scheme end */
writel(chip->com_ctrl, (SPI_COM_CTRL_OFFSET + zx29spi->virtbase));
//writel(chip->timing, (SPI_TIMING_OFFSET + zx29spi->virtbase));
@@ -2369,9 +2635,6 @@
if(diff_ns >= 10000000) {
dev_info(&zx29spi->pdev->dev, " zx29_setup_to_regs failed! diff_ns=%lld \n",diff_ns);
}
-
- if(false == zx29spi->master->slave)
- pm_relax(&zx29spi->pdev->dev);
}
/**
@@ -2557,11 +2820,9 @@
SPI_WRITE_BITS(chip->com_ctrl, SPI_SLAVE_MODE, SPI_COM_CTRL_MASK_MS, 2);
zx29_setup_to_regs(chip,zx29spi);
}
-
- if(zx29spi->mode == ZX29_SSP_MASTER_TYPE) {
- if(spi->setup_immediately == 1)
- zx29_setup_to_regs(chip,zx29spi);
- }
+
+ //yu.dong@20240617 [T106BUG-641] SPI packet loss problem, add kernel buffer scheme.
+
return status;
err_config_params:
spi_set_ctldata(spi, NULL);
@@ -2911,10 +3172,10 @@
zx29spi->mode = ZX29_SSP_MASTER_TYPE;
zx29spi->zx29_flush_rxfifo = zx29_flush_rxfifo;
sema_init(&zx29spi->sema_dma, 0);
- /* yu.dong@20240521 [T106BUG-616] SPI set to slave mode for read will get stuck start */
- init_waitqueue_head(&zx29spi->wait);
- zx29spi->trans_done = false;
- /* yu.dong@20240521 [T106BUG-616] SPI set to slave mode for read will get stuck end */
+ /* yu.dong@20240521 [T106BUG-616] SPI set to slave mode for read will get stuck start */
+ init_waitqueue_head(&zx29spi->wait);
+ zx29spi->trans_done = false;
+ /* yu.dong@20240521 [T106BUG-616] SPI set to slave mode for read will get stuck end */
dev_set_drvdata(&pdev->dev, zx29spi);
device_init_wakeup(&pdev->dev, true);
/*
@@ -3087,11 +3348,11 @@
zx29spi->vendor = &vendor_arm;
zx29spi->mode = ZX29_SSP_SLAVE_TYPE;
zx29spi->zx29_flush_rxfifo = zx29_flush_rxfifo;
- sema_init(&zx29spi->sema_dma, 0);
- /* yu.dong@20240521 [T106BUG-616] SPI set to slave mode for read will get stuck start */
- init_waitqueue_head(&zx29spi->wait);
- zx29spi->trans_done = false;
- /* yu.dong@20240521 [T106BUG-616] SPI set to slave mode for read will get stuck end */
+ sema_init(&zx29spi->sema_dma, 0);
+ /* yu.dong@20240521 [T106BUG-616] SPI set to slave mode for read will get stuck start */
+ init_waitqueue_head(&zx29spi->wait);
+ zx29spi->trans_done = false;
+ /* yu.dong@20240521 [T106BUG-616] SPI set to slave mode for read will get stuck end */
dev_set_drvdata(&pdev->dev, zx29spi);
/*
* Bus Number Which has been Assigned to this SSP controller
@@ -3104,6 +3365,10 @@
master->prepare_transfer_hardware = zx29_prepare_transfer_hardware;
master->transfer_one_message = zx29_slave_transfer_one_message;
master->unprepare_transfer_hardware = zx29_unprepare_transfer_hardware;
+ /* yu.dong@20240617 [T106BUG-641] SPI packet loss problem, add kernel buffer scheme start */
+ master->spi_slave_rd_start = zx29_slave_rd_start;
+ master->spi_slave_rd_stop = zx29_slave_rd_stop;
+ /* yu.dong@20240617 [T106BUG-641] SPI packet loss problem, add kernel buffer scheme end */
//master->rt = platform_info->rt;
/*
diff --git a/cap/zx297520v3/zxic_code/zxic_source/linux-5.10/drivers/spi/spidev.c b/cap/zx297520v3/zxic_code/zxic_source/linux-5.10/drivers/spi/spidev.c
index 53ea041..1522a21 100755
--- a/cap/zx297520v3/zxic_code/zxic_source/linux-5.10/drivers/spi/spidev.c
+++ b/cap/zx297520v3/zxic_code/zxic_source/linux-5.10/drivers/spi/spidev.c
@@ -31,9 +31,12 @@
#include <linux/of_irq.h>
#include <linux/interrupt.h>
#include <linux/delay.h>
+/* yu.dong@20240617 [T106BUG-641] SPI packet loss problem, add kernel buffer scheme start*/
+#include <linux/wait.h>
+#include <linux/suspend.h>
-
-
+#define SPI_SLAVE_FOR_YK
+/* yu.dong@20240617 [T106BUG-641] SPI packet loss problem, add kernel buffer scheme end */
/*
* This supports access to SPI devices using normal userspace I/O calls.
* Note that while traditional UNIX/POSIX I/O semantics are half duplex,
@@ -201,29 +204,100 @@
/*-------------------------------------------------------------------------*/
-
+/* yu.dong@20240617 [T106BUG-641] SPI packet loss problem, add kernel buffer scheme start*/
/* Read-only message with current device setup */
static ssize_t
spidev_read(struct file *filp, char __user *buf, size_t count, loff_t *f_pos)
{
struct spidev_data *spidev;
ssize_t status;
-
+ unsigned long missing;
/* chipselect only toggles at start or end of operation */
if (count > bufsiz)
return -EMSGSIZE;
spidev = filp->private_data;
+
+
+ #ifdef SPI_SLAVE_FOR_YK
+ size_t total = 0;
+
+ if (spidev->spi->rd_pos == spidev->spi->recv_pos) {
+
+ status = 0;
+ spidev->spi->is_rd_waiting = true;
+ if(0 != wait_event_freezable(spidev->spi->rd_wait, spidev->spi->recv_done)) {
+ if(spidev->spi->controller->spi_slave_rd_stop)
+ spidev->spi->controller->spi_slave_rd_stop(spidev->spi);
+ spidev->spi->is_rd_waiting = false;
+ return status;
+ }else {
+ spidev->spi->recv_done = false;
+ spidev->spi->is_rd_waiting = false;
+ }
+ }
mutex_lock(&spidev->buf_lock);
+ if(spidev->spi->rd_pos < spidev->spi->recv_pos) {
+
+ total = spidev->spi->recv_pos - spidev->spi->rd_pos;
+ status = (total > count) ? count : total;
+ missing = copy_to_user(buf, spidev->rx_buffer+spidev->spi->rd_pos, status);
+ if (missing == status) {
+ status = -EFAULT;
+ }
+ else {
+ status = status - missing;
+ spidev->spi->rd_pos += status;
+ }
+
+ }else if(spidev->spi->rd_pos > spidev->spi->recv_pos) {
+
+ total = bufsiz - (spidev->spi->rd_pos - spidev->spi->recv_pos);
+ status = (total > count) ? count : total;
+
+ if((spidev->spi->rd_pos + status) <= bufsiz) {
+
+ missing = copy_to_user(buf, spidev->rx_buffer+spidev->spi->rd_pos, status);
+ if (missing == status) {
+ status = -EFAULT;
+ }
+ else {
+ status = status - missing;
+ spidev->spi->rd_pos += status;
+ spidev->spi->rd_pos = spidev->spi->rd_pos%bufsiz;
+ }
+ }else {
+
+ unsigned long first,rest;
+
+ first = bufsiz - spidev->spi->rd_pos;
+ missing = copy_to_user(buf, spidev->rx_buffer+spidev->spi->rd_pos, first);
+ if (missing == first) {
+ status = -EFAULT;
+ } else {
+ status = status - missing;
+ }
+
+ rest = status-first;
+ missing = copy_to_user(buf+first, spidev->rx_buffer, rest);
+ if (missing == rest) {
+ status = -EFAULT;
+ } else {
+ status = status - missing;
+ }
+ spidev->spi->rd_pos = rest;
+ }
+ }
+ #else
+ mutex_lock(&spidev->buf_lock);
if(spidev->rd_from_rx_buffer)
status = count;
else
status = spidev_sync_read(spidev, count);
if (status > 0) {
- unsigned long missing;
missing = copy_to_user(buf, spidev->rx_buffer, status);
if (missing == status)
@@ -231,10 +305,12 @@
else
status = status - missing;
}
+ #endif
mutex_unlock(&spidev->buf_lock);
return status;
}
+/* yu.dong@20240617 [T106BUG-641] SPI packet loss problem, add kernel buffer scheme end*/
/* Write-only message with current device setup */
static ssize_t
@@ -556,6 +632,16 @@
spidev->rd_from_rx_buffer ? "RX_BUFFER":"DEVICE");
}
break;
+/* yu.dong@20240617 [T106BUG-641] SPI packet loss problem, add kernel buffer scheme start */
+#ifdef SPI_SLAVE_FOR_YK
+ case SPI_IOC_RD_BLOCK_RELEASE:
+ if(spidev->spi->is_rd_waiting == true) {
+ wake_up(&spidev->spi->rd_wait);
+ spidev->spi->recv_done = 1;
+ }
+ break;
+#endif
+/* yu.dong@20240617 [T106BUG-641] SPI packet loss problem, add kernel buffer scheme end */
#ifdef TEST_SWAP_KERNEL_AND_USER
case SPI_IOC_WR_SIG_PID:
retval = get_user(tmp, (__u32 __user *)arg);
@@ -697,6 +783,15 @@
}
}
+ /* yu.dong@20240617 [T106BUG-641] SPI packet loss problem, add kernel buffer scheme start */
+ #ifdef SPI_SLAVE_FOR_YK
+ if(spidev->rx_buffer) {
+ spidev->spi->rx_buf = spidev->rx_buffer;
+ if(spidev->spi->controller->spi_slave_rd_start)
+ spidev->spi->controller->spi_slave_rd_start(spidev->spi);
+ }
+ #endif
+ /* yu.dong@20240617 [T106BUG-641] SPI packet loss problem, add kernel buffer scheme end */
spidev->users++;
filp->private_data = spidev;
stream_open(inode, filp);
@@ -742,6 +837,15 @@
spin_lock_irq(&spidev->spi_lock);
spi = spi_dev_get(spidev->spi);
spin_unlock_irq(&spidev->spi_lock);
+
+ /* yu.dong@20240617 [T106BUG-641] SPI packet loss problem, add kernel buffer scheme start */
+ #ifdef SPI_SLAVE_FOR_YK
+ if(spidev->rx_buffer) {
+ if(spi->controller->spi_slave_rd_stop)
+ spi->controller->spi_slave_rd_stop(spi);
+ }
+ #endif
+ /* yu.dong@20240617 [T106BUG-641] SPI packet loss problem, add kernel buffer scheme end */
if(spi && spi->master->slave)
pm_relax(&spi->dev);
kfree(spidev->tx_buffer);
@@ -2153,14 +2257,7 @@
dev_info(&spi->dev,"trans_gap_num = 0x%x",val);
}
- if (device_property_read_u32(&spi->dev, "setup-immediately",&val)) {
- spi->setup_immediately = 0;
- dev_err(&spi->dev,"setup-immediately get failed");
- }
- else {
- spi->setup_immediately = val;
- dev_info(&spi->dev,"setup-immediately = 0x%x",val);
- }
+ // yu.dong@20240617 [T106BUG-641] SPI packet loss problem, add kernel buffer scheme.
/* If we can allocate a minor number, hook up this device.
* Reusing minors is fine so long as udev or mdev is working.
diff --git a/cap/zx297520v3/zxic_code/zxic_source/linux-5.10/include/linux/spi/spi.h b/cap/zx297520v3/zxic_code/zxic_source/linux-5.10/include/linux/spi/spi.h
index e308466..569ba92 100755
--- a/cap/zx297520v3/zxic_code/zxic_source/linux-5.10/include/linux/spi/spi.h
+++ b/cap/zx297520v3/zxic_code/zxic_source/linux-5.10/include/linux/spi/spi.h
@@ -209,7 +209,17 @@
u8 dma_used;
u8 trans_gaped;
u8 trans_gap_num;
- u8 setup_immediately;
+ /* yu.dong@20240617 [T106BUG-641] SPI packet loss problem, add kernel buffer scheme start */
+ u32 rd_pos;
+ u32 recv_pos;
+ u8 * rx_buf;
+ u8 * cyc_buf;
+ u8 cyc_index;
+ dma_addr_t rx_dma;
+ wait_queue_head_t rd_wait;
+ int recv_done;
+ bool is_rd_waiting;
+ /* yu.dong@20240617 [T106BUG-641] SPI packet loss problem, add kernel buffer scheme end */
};
static inline struct spi_device *to_spi_device(struct device *dev)
@@ -675,6 +685,11 @@
/* Interrupt enable state during PTP system timestamping */
unsigned long irq_flags;
+
+ /* yu.dong@20240617 [T106BUG-641] SPI packet loss problem, add kernel buffer scheme start */
+ int (*spi_slave_rd_start)(struct spi_device *spi);
+ int (*spi_slave_rd_stop)(struct spi_device *spi);
+ /* yu.dong@20240617 [T106BUG-641] SPI packet loss problem, add kernel buffer scheme end */
};
static inline void *spi_controller_get_devdata(struct spi_controller *ctlr)
diff --git a/cap/zx297520v3/zxic_code/zxic_source/linux-5.10/include/uapi/linux/spi/spidev.h b/cap/zx297520v3/zxic_code/zxic_source/linux-5.10/include/uapi/linux/spi/spidev.h
index f930a8e..d69bab6 100755
--- a/cap/zx297520v3/zxic_code/zxic_source/linux-5.10/include/uapi/linux/spi/spidev.h
+++ b/cap/zx297520v3/zxic_code/zxic_source/linux-5.10/include/uapi/linux/spi/spidev.h
@@ -158,5 +158,10 @@
#define SPI_IOC_RD_INT_ST _IOR(SPI_IOC_MAGIC, 8, __u32)
#define SPI_IOC_WR_INT_ST _IOW(SPI_IOC_MAGIC, 8, __u32)
+/* yu.dong@20240617 [T106BUG-641] SPI packet loss problem, add kernel buffer scheme start*/
+/* release from rd/wr block */
+#define SPI_IOC_RD_BLOCK_RELEASE _IOR(SPI_IOC_MAGIC, 9, __u32)
+//#define SPI_IOC_WR_INT_ST _IOW(SPI_IOC_MAGIC, 9, __u32)
+/* yu.dong@20240617 [T106BUG-641] SPI packet loss problem, add kernel buffer scheme end*/
#endif /* SPIDEV_H */