static void yas_work_func(struct work_struct *work) { struct yas_data acc[1]; struct yas_state *st = container_of((struct delayed_work *)work, struct yas_state, work); struct iio_dev *indio_dev = iio_priv_to_dev(st); uint32_t time_before, time_after; int32_t delay; int ret, i; time_before = jiffies_to_msecs(jiffies); mutex_lock(&st->lock); ret = st->acc.measure(acc, 1); if (ret == 1) { for (i = 0; i < 3; i++) st->compass_data[i] = acc[0].xyz.v[i] - st->calib_bias[i]; } mutex_unlock(&st->lock); if (ret == 1) yas_data_rdy_trig_poll(indio_dev); time_after = jiffies_to_msecs(jiffies); delay = MSEC_PER_SEC / st->sampling_frequency - (time_after - time_before); if (delay <= 0) delay = 1; schedule_delayed_work(&st->work, msecs_to_jiffies(delay)); }
static void yas_work_func(struct work_struct *work) { struct yas_data mag[1]; struct yas_state *st = container_of((struct delayed_work *)work, struct yas_state, work); struct iio_dev *indio_dev = iio_priv_to_dev(st); int ret, i; mutex_lock(&st->lock); ret = st->mag.measure(mag, 1); if (ret == 1) { for (i = 0; i < 3; i++) st->compass_data[i] = mag[0].xyz.v[i]; } mutex_unlock(&st->lock); if (ret == 1) yas_data_rdy_trig_poll(indio_dev); else pr_err("[SENSOR] %s: ret %d\n", __func__, ret); schedule_delayed_work(&st->work, msecs_to_jiffies(st->poll_delay)); }