Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ist415 semaphore and recording mode. #6626

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 34 additions & 4 deletions os/drivers/input/ist415.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,10 @@ static int ist415_process_event(struct ist415_dev_s *dev)

kmm_free(touch_event);

if (dev->rec_mode) {
ist415_recording(dev);
}

return OK;
}

Expand Down Expand Up @@ -406,6 +410,8 @@ static int ist415_cmd(struct touchscreen_s *upper, int argc, char **argv)
ret = ist415_set_dbg(dev, argc, argv);
} else if (strncmp(argv[1], "selftest", 9) == 0) {
ist415_selftest(dev);
} else if (strncmp(argv[1], "rec", 4) == 0) {
ret = ist415_rec_mode(dev, argc, argv);
} else {
ret = -EINVAL;
}
Expand Down Expand Up @@ -490,6 +496,10 @@ static void ist415_stop_device(struct ist415_dev_s *dev)
{
ist415vdbg("%s\n", __func__);

while (sem_wait(&dev->sem) != OK) {
ASSERT(get_errno() == EINTR);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It call ASSERT, not retry, is it right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes it's checking errno == EINTR. sem_wait fail case must be EINTR only. If not system is corrupted

}

dev->suspend = true;

if (dev->knockknock) {
Expand All @@ -503,6 +513,10 @@ static void ist415_stop_device(struct ist415_dev_s *dev)
ist415_disable(dev);
ist415_power_off(dev);
}

ist415_forced_release(dev);

sem_post(&dev->sem);
}

/****************************************************************************
Expand All @@ -513,6 +527,10 @@ static void ist415_start_device(struct ist415_dev_s *dev)
{
ist415vdbg("%s\n", __func__);

while (sem_wait(&dev->sem) != OK) {
ASSERT(get_errno() == EINTR);
}

dev->suspend = false;

if (dev->knockknock) {
Expand All @@ -525,6 +543,8 @@ static void ist415_start_device(struct ist415_dev_s *dev)
ist415_enable(dev);
ist415_start(dev);
}

sem_post(&dev->sem);
}

/****************************************************************************
Expand Down Expand Up @@ -553,10 +573,10 @@ static void ist415_enable_touch(struct touchscreen_s *upper)
* Name: ist415_lockup_work
****************************************************************************/

static void ist415_lookup_work(struct ist415_dev_s *dev)
static void ist415_lockup_work(struct ist415_dev_s *dev)
{
u32 touch_status = 0;
u32 scan_count = 0;
uint32_t touch_status = 0;
uint32_t scan_count = 0;
int ret = 0;

if (dev->irq_working == false) {
Expand Down Expand Up @@ -595,6 +615,10 @@ static void ist415_lookup_work(struct ist415_dev_s *dev)
dev->alive_retry++;
ist415dbg("Retry touch status(%d)\n", dev->alive_retry);
if (dev->alive_retry == IST415_MAX_ALIVE_CNT) {
while (sem_wait(&dev->sem) != OK) {
ASSERT(get_errno() == EINTR);
}

ist415_disable(dev);
ist415_forced_release(dev);
ist415_reset(dev, false);
Expand All @@ -615,8 +639,11 @@ static void ist415_lookup_work(struct ist415_dev_s *dev)
ist415_start(dev);
ist415_enable(dev);
}

dev->alive_retry = 0;
dev->scan_count = 0;

sem_post(&dev->sem);
} else {
(void)wd_start(dev->wdog, MSEC2TICK(IST415_LOOKUP_RETRY_MS), (wdentry_t)ist415_timer_handler, 1, (uint32_t)dev);
}
Expand All @@ -630,7 +657,7 @@ static void ist415_timer_handler(int argc, uint32_t arg1)
{
struct ist415_dev_s *dev = (struct ist415_dev_s *)arg1;

work_queue(HPWORK, &dev->work, (worker_t)ist415_lookup_work, dev, 0);
work_queue(HPWORK, &dev->work, (worker_t)ist415_lockup_work, dev, 0);
}

/****************************************************************************
Expand Down Expand Up @@ -1105,6 +1132,9 @@ int ist415_initialize(const char *path, struct i2c_dev_s *i2c, struct ist415_con

ist415_disable(dev);

// Semaphore reset scenario
sem_init(&dev->sem, 0, 1);

dev->lower->handler = touch_interrupt;
sem_init(&dev->wait_irq, 0, 0);
itoa((int)dev, parm_buf, 16);
Expand Down
4 changes: 3 additions & 1 deletion os/drivers/input/ist415.h
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ struct ist415_dev_s {
bool rec_idle;
int rec_type;
int rec_delay;
uint32_t recording_scancnt;
uint32_t rec_scancnt;
uint32_t rec_addr;
uint32_t rec_size;

Expand All @@ -460,6 +460,8 @@ struct ist415_dev_s {
int pid;
sem_t wait_irq;

sem_t sem;

WDOG_ID wdog;
struct work_s work;
};
Expand Down
146 changes: 146 additions & 0 deletions os/drivers/input/ist415_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,15 @@ int ist415_get_info(struct ist415_dev_s *dev)

void ist415_autocalibration(struct ist415_dev_s *dev)
{
while (sem_wait(&dev->sem) != OK) {
ASSERT(get_errno() == EINTR);
}

ist415_calibrate(dev, 1);
ist415_start(dev);
ist415_enable(dev);

sem_post(&dev->sem);
}

/****************************************************************************
Expand Down Expand Up @@ -787,3 +793,143 @@ int ist415_selftest(struct ist415_dev_s *dev)

return ret;
}

/****************************************************************************
* Name: ist415_rec_mode
*
* Description
* This function is called by Uart Command.
****************************************************************************/

int ist415_rec_mode(struct ist415_dev_s *dev, int argc, char **argv)
{
int mode;
uint8_t data;
char header[32];
int ret = 0;

if (argc < 4) {
return -EINVAL;
}

mode = atoi(argv[2]);
ist415vdbg("rec mode : %s\n", mode ? "start" : "stop");

ret = ist415_i2c_write(dev, HCOM_SET_REC_MODE, (uint8_t *)&mode, 1);
if (ret) {
return -ENODEV;
}

dev->rec_mode = mode;
if (dev->rec_mode) {
dev->rec_delay = atoi(argv[3]);
ist415vdbg("rec delay : %d\n", dev->rec_delay);

snprintf(header, sizeof(header), "%s2 2 %d, %d, %d, %d\n", RECS_TAG, dev->slf_node_len, dev->tx_num, dev->rx_num, dev->rec_size);
ist415vdbg("%s", header);

msleep(100);

data = REC_START_SCAN;
ret = ist415_i2c_write(dev, HCOM_SET_REC_MODE, (uint8_t *)&data, 1);
if (ret) {
return -ENODEV;
}
}

return OK;
}

/****************************************************************************
* Name: ist415_recording
****************************************************************************/
void ist415_recording(struct ist415_dev_s *dev)
{
uint32_t *buf32 = NULL;
uint32_t fb = 0;
uint32_t scancnt = 0;
uint8_t data = 0;
int size = 0;
char logbuf[512] = { 0, };
int offset = 0;
int i;
int ret = 0;

if (dev->rec_idle && (dev->rec_mode > REC_ENABLE)) {
goto rec_end;
}

msleep(dev->rec_delay);

ret = ist415_i2c_read_da(dev, IST415_TOUCH_STATUS, (uint32_t *)&scancnt, 1);
if (ret) {
ist415dbg("Fail to read scan count\n");
goto rec_end;
}

if (dev->rec_scancnt == scancnt) {
ist415dbg("Same rec scan count\n");
goto rec_end;
}

dev->rec_scancnt = scancnt;

buf32 = (uint32_t *)kmm_malloc(dev->rec_size + ((dev->slf_node_len + dev->mtl_node_len) * sizeof(uint32_t)));
if (!buf32) {
ist415dbg("Fail to allocate buf32\n");
goto rec_end;
}

if (dev->rec_size > 0) {
ret = ist415_i2c_read_da(dev, dev->rec_addr, (uint32_t *)buf32, dev->rec_size / sizeof(uint32_t));
if (ret) {
ist415dbg("Fail to reaqd rec data\n");
goto rec_end;
}
}

ret = ist415_i2c_read_da(dev, IST415_FB_SEL, (uint32_t *)&fb, 1);
if (ret) {
ist415dbg("Fail to read fb\n");
goto rec_end;
}

size = dev->rec_size / sizeof(uint32_t);
ret = ist415_i2c_read_da(dev, IST415_FB_SLF_ADDR(fb), (uint32_t *)(buf32 + size),
dev->slf_node_len);
if (ret) {
ist415dbg("Fail to read self data\n");
goto rec_end;
}

size += dev->slf_node_len;
ret = ist415_i2c_read_da(dev, IST415_FB_MTL_ADDR(fb), (uint32_t *)(buf32 + size), dev->mtl_node_len);
if (ret) {
ist415dbg("Fail to read mutual data\n");
goto rec_end;
}

size += dev->mtl_node_len;

offset = snprintf(logbuf, sizeof(logbuf), "%s", RECS_TAG);
for (i = 1; i <= size; i++) {
offset += snprintf(logbuf + offset, sizeof(logbuf) - offset, "%08X ", buf32[i]);
if ((i % REC_PRINT_SIZE) == 0) {
ist415vdbg("%s", logbuf);
offset = snprintf(logbuf, sizeof(logbuf), "%s", RECC_TAG);
}
}
snprintf(logbuf + offset, sizeof(logbuf) - offset, "\n");
ist415vdbg("%s", logbuf);

rec_end:
if (buf32) {
kmm_free(buf32);
}

data = REC_START_SCAN;
ret = ist415_i2c_write(dev, HCOM_SET_REC_MODE, (uint8_t *)&data, 1);
if (ret) {
ist415dbg("Fail to write rec start scan\n");
}
}
11 changes: 11 additions & 0 deletions os/drivers/input/ist415_misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@
#define REC_ENABLE 1
#define REC_DISABLE 0

#define REC_PRINT_SIZE 50

#define RECS_TAG "[RECS] "
#define RECC_TAG "[RECC] "

#define IST415_FB_SEL 0x3002002C
#define IST415_FB_MTL_ADDR(n) (n ? 0x40010000 : 0x40000000)
#define IST415_FB_SLF_ADDR(n) (n ? 0x40011768 : 0x40001768)

// SelfTest
//#define USE_SELFTEST_CS

Expand Down Expand Up @@ -83,5 +92,7 @@ void ist415_run_intr_debug(struct ist415_dev_s *dev);
void ist415_display_cpc(struct ist415_dev_s *dev);
void ist415_display_rawdata(struct ist415_dev_s *dev);
int ist415_selftest(struct ist415_dev_s *dev);
int ist415_rec_mode(struct ist415_dev_s *dev, int argc, char **argv);
void ist415_recording(struct ist415_dev_s *dev);

#endif /* __DRIVERS_INPUT_IST415_MISC_H */
16 changes: 16 additions & 0 deletions os/drivers/input/ist415_update.c
Original file line number Diff line number Diff line change
Expand Up @@ -581,14 +581,22 @@ int ist415_check_fw(struct ist415_dev_s *dev)

ist415vdbg("Main : %08X Core: %x, Config %x, Release: %x, Test: %x\n", fw->bin.main_ver, fw->bin.core_ver, fw->bin.config_ver, fw->bin.release_ver, fw->bin.test_ver);

while (sem_wait(&dev->sem) != OK) {
ASSERT(get_errno() == EINTR);
}
ret = ist415_check_auto_update(dev);
sem_post(&dev->sem);
if (ret >= 0) {
kmm_free(fw->buf);
return OK;
}

ist415vdbg("Update version. release(core, config, test): %x(%x, %x, %x) -> %x(%x, %x, %x)\n", fw->cur.release_ver, fw->cur.core_ver, fw->cur.config_ver, fw->cur.test_ver, fw->bin.release_ver, fw->bin.core_ver, fw->bin.config_ver, fw->bin.test_ver);

while (sem_wait(&dev->sem) != OK) {
ASSERT(get_errno() == EINTR);
}

retry = IST415_RETRY_CNT;
while (retry--) {
ret = ist415_fw_update(dev, fw->buf, fw->buf_size);
Expand All @@ -598,6 +606,8 @@ int ist415_check_fw(struct ist415_dev_s *dev)
}
}

sem_post(&dev->sem);

kmm_free(fw->buf);
return ret;
}
Expand Down Expand Up @@ -659,6 +669,10 @@ int ist415_force_update(struct ist415_dev_s *dev, int argc, char **argv)

ist415vdbg("Update version. release(core, config, test): %x(%x, %x, %x) -> %x(%x, %x, %x)\n", fw->cur.release_ver, fw->cur.core_ver, fw->cur.config_ver, fw->cur.test_ver, fw->bin.release_ver, fw->bin.core_ver, fw->bin.config_ver, fw->bin.test_ver);

while (sem_wait(&dev->sem) != OK) {
ASSERT(get_errno() == EINTR);
}

ist415_disable(dev);

ret = ist415_fw_update(dev, fw->buf, fw->buf_size);
Expand All @@ -671,6 +685,8 @@ int ist415_force_update(struct ist415_dev_s *dev, int argc, char **argv)
ist415_start(dev);
ist415_enable(dev);

sem_post(&dev->sem);

kmm_free(fw->buf);

return ret;
Expand Down