Lines Matching +full:lock +full:- +full:state
1 // SPDX-License-Identifier: GPL-2.0
43 /* this is fine since passed float is always non-negative */ in sps30_float_to_int_clamped()
51 exp -= 127; in sps30_float_to_int_clamped()
54 return ((((1 << 23) + mantissa) * 100) >> 23) >> (-exp); in sps30_float_to_int_clamped()
58 shift = 23 - exp; in sps30_float_to_int_clamped()
63 fraction = mantissa & GENMASK(shift - 1, 0); in sps30_float_to_int_clamped()
68 static int sps30_do_meas(struct sps30_state *state, s32 *data, int size) in sps30_do_meas() argument
72 if (state->state == RESET) { in sps30_do_meas()
73 ret = state->ops->start_meas(state); in sps30_do_meas()
77 state->state = MEASURING; in sps30_do_meas()
80 ret = state->ops->read_meas(state, (__be32 *)data, size); in sps30_do_meas()
90 static int sps30_do_reset(struct sps30_state *state) in sps30_do_reset() argument
94 ret = state->ops->reset(state); in sps30_do_reset()
98 state->state = RESET; in sps30_do_reset()
106 struct iio_dev *indio_dev = pf->indio_dev; in sps30_trigger_handler()
107 struct sps30_state *state = iio_priv(indio_dev); in sps30_trigger_handler() local
114 mutex_lock(&state->lock); in sps30_trigger_handler()
115 ret = sps30_do_meas(state, scan.data, ARRAY_SIZE(scan.data)); in sps30_trigger_handler()
116 mutex_unlock(&state->lock); in sps30_trigger_handler()
123 iio_trigger_notify_done(indio_dev->trig); in sps30_trigger_handler()
132 struct sps30_state *state = iio_priv(indio_dev); in sps30_read_raw() local
133 int data[4], ret = -EINVAL; in sps30_read_raw()
137 switch (chan->type) { in sps30_read_raw()
139 mutex_lock(&state->lock); in sps30_read_raw()
141 switch (chan->channel2) { in sps30_read_raw()
143 ret = sps30_do_meas(state, data, 1); in sps30_read_raw()
146 ret = sps30_do_meas(state, data, 2); in sps30_read_raw()
149 ret = sps30_do_meas(state, data, 3); in sps30_read_raw()
152 ret = sps30_do_meas(state, data, 4); in sps30_read_raw()
155 mutex_unlock(&state->lock); in sps30_read_raw()
159 *val = data[chan->address] / 100; in sps30_read_raw()
160 *val2 = (data[chan->address] % 100) * 10000; in sps30_read_raw()
164 return -EINVAL; in sps30_read_raw()
167 switch (chan->type) { in sps30_read_raw()
169 switch (chan->channel2) { in sps30_read_raw()
179 return -EINVAL; in sps30_read_raw()
182 return -EINVAL; in sps30_read_raw()
186 return -EINVAL; in sps30_read_raw()
194 struct sps30_state *state = iio_priv(indio_dev); in start_cleaning_store() local
198 return -EINVAL; in start_cleaning_store()
200 mutex_lock(&state->lock); in start_cleaning_store()
201 ret = state->ops->clean_fan(state); in start_cleaning_store()
202 mutex_unlock(&state->lock); in start_cleaning_store()
214 struct sps30_state *state = iio_priv(indio_dev); in cleaning_period_show() local
218 mutex_lock(&state->lock); in cleaning_period_show()
219 ret = state->ops->read_cleaning_period(state, &val); in cleaning_period_show()
220 mutex_unlock(&state->lock); in cleaning_period_show()
231 struct sps30_state *state = iio_priv(indio_dev); in cleaning_period_store() local
235 return -EINVAL; in cleaning_period_store()
239 return -EINVAL; in cleaning_period_store()
241 mutex_lock(&state->lock); in cleaning_period_store()
242 ret = state->ops->write_cleaning_period(state, cpu_to_be32(val)); in cleaning_period_store()
244 mutex_unlock(&state->lock); in cleaning_period_store()
254 ret = sps30_do_reset(state); in cleaning_period_store()
259 mutex_unlock(&state->lock); in cleaning_period_store()
319 struct sps30_state *state = data; in sps30_devm_stop_meas() local
321 if (state->state == MEASURING) in sps30_devm_stop_meas()
322 state->ops->stop_meas(state); in sps30_devm_stop_meas()
330 struct sps30_state *state; in sps30_probe() local
333 indio_dev = devm_iio_device_alloc(dev, sizeof(*state)); in sps30_probe()
335 return -ENOMEM; in sps30_probe()
339 state = iio_priv(indio_dev); in sps30_probe()
340 state->dev = dev; in sps30_probe()
341 state->priv = priv; in sps30_probe()
342 state->ops = ops; in sps30_probe()
343 mutex_init(&state->lock); in sps30_probe()
345 indio_dev->info = &sps30_info; in sps30_probe()
346 indio_dev->name = name; in sps30_probe()
347 indio_dev->channels = sps30_channels; in sps30_probe()
348 indio_dev->num_channels = ARRAY_SIZE(sps30_channels); in sps30_probe()
349 indio_dev->modes = INDIO_DIRECT_MODE; in sps30_probe()
350 indio_dev->available_scan_masks = sps30_scan_masks; in sps30_probe()
352 ret = sps30_do_reset(state); in sps30_probe()
358 ret = state->ops->show_info(state); in sps30_probe()
364 ret = devm_add_action_or_reset(dev, sps30_devm_stop_meas, state); in sps30_probe()