wigig_sensing: add support for asynchronous events

Driver can now send asynchronous events to user space application.
Available events are RESET and FW_READY.

Change-Id: I8b3819927ac3e55b69be03d288600c81ad23e319
Signed-off-by: Gidon Studinski <gidons@codeaurora.org>
Signed-off-by: Alexei Avshalom Lazar <ailizaro@codeaurora.org>
This commit is contained in:
Alexei Avshalom Lazar 2020-04-19 12:39:35 +03:00
commit 03547d5eb7
3 changed files with 44 additions and 6 deletions

View file

@ -2,7 +2,6 @@
/*
* Copyright (c) 2019, The Linux foundation. All rights reserved.
*/
#include <linux/cdev.h>
#include <linux/circ_buf.h>
#include <linux/clk.h>
@ -15,6 +14,7 @@
#include <linux/io.h>
#include <linux/ioctl.h>
#include <linux/kernel.h>
#include <linux/kfifo.h>
#include <linux/list.h>
#include <linux/module.h>
#include <linux/of.h>
@ -639,9 +639,19 @@ static int wigig_sensing_ioc_get_num_avail_bursts(
return 0;
}
static int wigig_sensing_ioc_get_event(struct wigig_sensing_ctx *ctx)
static int wigig_sensing_ioc_get_event(struct wigig_sensing_ctx *ctx,
enum wigig_sensing_event *event)
{
return 0;
u32 copied;
if (!ctx->event_pending)
return -EINVAL;
if (kfifo_len(&ctx->events_fifo) == 1)
ctx->event_pending = false;
return kfifo_to_user(&ctx->events_fifo, event,
sizeof(enum wigig_sensing_event), &copied);
}
static int wigig_sensing_open(struct inode *inode, struct file *filp)
@ -769,7 +779,7 @@ static int wigig_sensing_release(struct inode *inode, struct file *filp)
}
static long wigig_sensing_ioctl(struct file *file, unsigned int cmd,
unsigned long arg)
__user unsigned long arg)
{
int rc;
struct wigig_sensing_ctx *ctx = file->private_data;
@ -822,7 +832,8 @@ static long wigig_sensing_ioctl(struct file *file, unsigned int cmd,
break;
case WIGIG_SENSING_IOCTL_GET_EVENT:
pr_info("Received WIGIG_SENSING_IOCTL_GET_EVENT command\n");
rc = wigig_sensing_ioc_get_event(ctx);
rc = wigig_sensing_ioc_get_event(ctx,
(enum wigig_sensing_event *)arg);
break;
case WIGIG_SENSING_IOCTL_GET_NUM_AVAIL_BURSTS:
pr_info("Received WIGIG_SENSING_IOCTL_GET_NUM_AVAIL_BURSTS command\n");
@ -1145,6 +1156,22 @@ cmd_reply_buf_alloc_failed:
return rc;
}
static int wigig_sensing_send_event(struct wigig_sensing_ctx *ctx,
enum wigig_sensing_event event)
{
if (kfifo_is_full(&ctx->events_fifo)) {
pr_err("events fifo is full, unable to send event\n");
return -EFAULT;
}
kfifo_in(&ctx->events_fifo, &event, 1);
ctx->event_pending = true;
wake_up_interruptible(&ctx->cmd_wait_q);
return 0;
}
static irqreturn_t wigig_sensing_dri_isr_thread(int irq, void *cookie)
{
struct wigig_sensing_ctx *ctx = cookie;
@ -1232,6 +1259,9 @@ static irqreturn_t wigig_sensing_dri_isr_thread(int irq, void *cookie)
wigig_sensing_change_state(ctx, &ctx->stm,
WIGIG_SENSING_STATE_READY_STOPPED);
/* Send asynchronous FW_READY event to application */
wigig_sensing_send_event(ctx, WIGIG_SENSING_EVENT_FW_READY);
spi_status.v &= ~INT_FW_READY;
}
if (spi_status.b.int_data_ready) {
@ -1254,6 +1284,9 @@ static irqreturn_t wigig_sensing_dri_isr_thread(int irq, void *cookie)
ctx->stm.state != WIGIG_SENSING_STATE_SYS_ASSERT)
pr_err("State change to WIGIG_SENSING_SYS_ASSERT failed\n");
/* Send asynchronous RESET event to application */
wigig_sensing_send_event(ctx, WIGIG_SENSING_EVENT_RESET);
ctx->stm.spi_malfunction = true;
spi_status.v &= ~INT_SYSASSERT;
}
@ -1326,6 +1359,7 @@ static int wigig_sensing_probe(struct spi_device *spi)
init_waitqueue_head(&ctx->cmd_wait_q);
init_waitqueue_head(&ctx->data_wait_q);
ctx->stm.state = WIGIG_SENSING_STATE_INITIALIZED;
INIT_KFIFO(ctx->events_fifo);
/* Allocate memory for the CIRs */
/* Allocate a 2MB == 2^21 buffer for CIR data */

View file

@ -7,6 +7,7 @@
#define __WIGIG_SENSING_H__
#include <linux/cdev.h>
#include <linux/circ_buf.h>
#include <linux/kfifo.h>
#include <linux/slab.h>
#include <uapi/misc/wigig_sensing_uapi.h>
@ -193,6 +194,7 @@ struct wigig_sensing_ctx {
struct cir_data cir_data;
u8 *temp_buffer;
bool event_pending;
DECLARE_KFIFO(events_fifo, enum wigig_sensing_event, 8);
u32 dropped_bursts;
};

View file

@ -27,8 +27,10 @@ struct wigig_sensing_change_mode {
};
enum wigig_sensing_event {
WIGIG_SENSING_EVENT_MIN,
WIGIG_SENSING_EVENT_FW_READY,
WIGIG_SENSING_EVENT_RESET,
WIGIG_SENSING_EVENT_MAX,
};
#define WIGIG_SENSING_IOC_MAGIC 'r'
@ -84,7 +86,7 @@ enum wigig_sensing_event {
WIGIG_SENSING_IOCTL_GET_NUM_DROPPED_BURSTS, uint32_t)
/**
* Get number of bursts that where dropped due to data buffer overflow
* Get asynchronous event (FW_READY, RESET)
*/
#define WIGIG_SENSING_IOC_GET_EVENT \
_IOR(WIGIG_SENSING_IOC_MAGIC, WIGIG_SENSING_IOCTL_GET_EVENT, \