From 88ca60f7a3e00c1b15dcfaecc9c7ea9711b43909 Mon Sep 17 00:00:00 2001 From: Jinhyung Choi Date: Mon, 11 May 2015 18:14:56 +0900 Subject: [PATCH] sensor driver: waited for set_sensor_data In order to resolve timing issue, set_sensor_data is waiting for a callback similar to get_sensor_data. Change-Id: I436375ea99b5f19c07d0683a89dd35d50218f830 Signed-off-by: Jinhyung Choi (cherry picked from commit b603734d766fa00ef69f2c075dd6264a7ad1bdb6) --- drivers/maru/sensors/maru_virtio_sensor.c | 22 ++++++++++++++++++---- drivers/maru/sensors/maru_virtio_sensor.h | 13 +++++++------ 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/drivers/maru/sensors/maru_virtio_sensor.c b/drivers/maru/sensors/maru_virtio_sensor.c index bdd7f1e..fd7283e 100644 --- a/drivers/maru/sensors/maru_virtio_sensor.c +++ b/drivers/maru/sensors/maru_virtio_sensor.c @@ -151,9 +151,15 @@ static void sensor_vq_done(struct virtqueue *rvq) { } if (msg->req != request_answer) { - LOG(1, "receive queue- not an answer message: %d", msg->req); + LOG(1, "set_sensor_data callback."); + mutex_lock(&vs->lock); + vs->flags = 1; + mutex_unlock(&vs->lock); + + wake_up_interruptible(&wq); return; } + if (msg->buf == NULL) { ERR("receive queue- message from host is NULL."); return; @@ -196,13 +202,19 @@ void set_sensor_data(int type, const char* buf) mutex_unlock(&vs->lock); - err = virtqueue_add_outbuf(vs->vq, vs->sg_vq, 1, &vs->msginfo, GFP_ATOMIC); + err = virtqueue_add_outbuf(vs->vq, vs->sg_svq, 1, &vs->msginfo, GFP_ATOMIC); if (err < 0) { - ERR("failed to add buffer to virtqueue (err = %d)", err); + ERR("failed to add_outbuf buffer to virtqueue (err = %d)", err); return; } virtqueue_kick(vs->vq); + + wait_event_interruptible(wq, vs->flags != 0); + + mutex_lock(&vs->lock); + vs->flags = 0; + mutex_unlock(&vs->lock); } int get_sensor_data(int type, char* data) @@ -230,7 +242,7 @@ int get_sensor_data(int type, char* data) err = virtqueue_add_sgs(vs->vq, sgs, 1, 1, &vs->msginfo, GFP_ATOMIC); if (err < 0) { - ERR("failed to add buffer to virtqueue (err = %d)", err); + ERR("failed to add_sgs buffer to virtqueue (err = %d)", err); return err; } @@ -452,6 +464,8 @@ static int sensor_probe(struct virtio_device* dev) sg_set_buf(&vs->sg_vq[index], &vs->msginfo, sizeof(vs->msginfo)); } + sg_init_one(vs->sg_svq, &vs->msginfo, sizeof(vs->msginfo)); + mutex_init(&vs->lock); mutex_init(&vs->vqlock); diff --git a/drivers/maru/sensors/maru_virtio_sensor.h b/drivers/maru/sensors/maru_virtio_sensor.h index a34c6c0..580b6e0 100644 --- a/drivers/maru/sensors/maru_virtio_sensor.h +++ b/drivers/maru/sensors/maru_virtio_sensor.h @@ -49,27 +49,27 @@ enum sensor_types { sensor_type_accel_enable, sensor_type_accel_delay, sensor_type_geo, - sensor_type_geo_enable, + sensor_type_geo_enable, // 5 sensor_type_geo_delay, sensor_type_gyro, sensor_type_gyro_enable, sensor_type_gyro_delay, - sensor_type_gyro_x, + sensor_type_gyro_x, // 10 sensor_type_gyro_y, sensor_type_gyro_z, sensor_type_light, sensor_type_light_enable, - sensor_type_light_delay, + sensor_type_light_delay, // 15 sensor_type_light_adc, sensor_type_light_level, sensor_type_proxi, sensor_type_proxi_enable, - sensor_type_proxi_delay, + sensor_type_proxi_delay, // 20 sensor_type_rotation_vector, sensor_type_rotation_vector_enable, sensor_type_rotation_vector_delay, sensor_type_mag, - sensor_type_tilt, + sensor_type_tilt, // 25 sensor_type_pressure, sensor_type_pressure_enable, sensor_type_pressure_delay, @@ -120,6 +120,7 @@ struct virtio_sensor { struct msg_info msginfo; struct scatterlist sg_vq[2]; + struct scatterlist sg_svq[1]; int flags; struct mutex lock; @@ -225,7 +226,7 @@ extern int sensor_driver_debug; #define LOG(log_level, fmt, ...) \ do { \ - if (sensor_driver_debug >= (log_level)) { \ + if (sensor_driver_debug == (log_level)) { \ printk(KERN_INFO "%s: " fmt "\n", SENSOR_CLASS_NAME, ##__VA_ARGS__); \ } \ } while (0) -- 2.7.4