Lines Matching full:data
61 struct sx_common_data *data = iio_priv(indio_dev); in sx_common_irq_handler() local
63 if (data->trigger_enabled) in sx_common_irq_handler()
64 iio_trigger_poll(data->trig); in sx_common_irq_handler()
78 struct sx_common_data *data = iio_priv(indio_dev); in sx_common_push_events() local
83 ret = regmap_read(data->regmap, data->chip_info->reg_stat, &val); in sx_common_push_events()
85 dev_err(&data->client->dev, "i2c transfer error in irq\n"); in sx_common_push_events()
89 val >>= data->chip_info->stat_offset; in sx_common_push_events()
95 prox_changed = (data->chan_prox_stat ^ val) & data->chan_event; in sx_common_push_events()
97 for_each_set_bit(chan, &prox_changed, data->chip_info->num_channels) { in sx_common_push_events()
107 data->chan_prox_stat = val; in sx_common_push_events()
110 static int sx_common_enable_irq(struct sx_common_data *data, unsigned int irq) in sx_common_enable_irq() argument
112 if (!data->client->irq) in sx_common_enable_irq()
114 return regmap_update_bits(data->regmap, data->chip_info->reg_irq_msk, in sx_common_enable_irq()
115 irq << data->chip_info->irq_msk_offset, in sx_common_enable_irq()
116 irq << data->chip_info->irq_msk_offset); in sx_common_enable_irq()
119 static int sx_common_disable_irq(struct sx_common_data *data, unsigned int irq) in sx_common_disable_irq() argument
121 if (!data->client->irq) in sx_common_disable_irq()
123 return regmap_update_bits(data->regmap, data->chip_info->reg_irq_msk, in sx_common_disable_irq()
124 irq << data->chip_info->irq_msk_offset, 0); in sx_common_disable_irq()
127 static int sx_common_update_chan_en(struct sx_common_data *data, in sx_common_update_chan_en() argument
134 if ((data->chan_read | data->chan_event) != channels) { in sx_common_update_chan_en()
135 ret = regmap_update_bits(data->regmap, in sx_common_update_chan_en()
136 data->chip_info->reg_enable_chan, in sx_common_update_chan_en()
137 data->chip_info->mask_enable_chan, in sx_common_update_chan_en()
142 data->chan_read = chan_read; in sx_common_update_chan_en()
143 data->chan_event = chan_event; in sx_common_update_chan_en()
147 static int sx_common_get_read_channel(struct sx_common_data *data, int channel) in sx_common_get_read_channel() argument
149 return sx_common_update_chan_en(data, data->chan_read | BIT(channel), in sx_common_get_read_channel()
150 data->chan_event); in sx_common_get_read_channel()
153 static int sx_common_put_read_channel(struct sx_common_data *data, int channel) in sx_common_put_read_channel() argument
155 return sx_common_update_chan_en(data, data->chan_read & ~BIT(channel), in sx_common_put_read_channel()
156 data->chan_event); in sx_common_put_read_channel()
159 static int sx_common_get_event_channel(struct sx_common_data *data, int channel) in sx_common_get_event_channel() argument
161 return sx_common_update_chan_en(data, data->chan_read, in sx_common_get_event_channel()
162 data->chan_event | BIT(channel)); in sx_common_get_event_channel()
165 static int sx_common_put_event_channel(struct sx_common_data *data, int channel) in sx_common_put_event_channel() argument
167 return sx_common_update_chan_en(data, data->chan_read, in sx_common_put_event_channel()
168 data->chan_event & ~BIT(channel)); in sx_common_put_event_channel()
173 * @data: Internal data
180 int sx_common_read_proximity(struct sx_common_data *data, in sx_common_read_proximity() argument
186 mutex_lock(&data->mutex); in sx_common_read_proximity()
188 ret = sx_common_get_read_channel(data, chan->channel); in sx_common_read_proximity()
192 ret = sx_common_enable_irq(data, SX_COMMON_CONVDONE_IRQ); in sx_common_read_proximity()
196 mutex_unlock(&data->mutex); in sx_common_read_proximity()
198 if (data->client->irq) { in sx_common_read_proximity()
199 ret = wait_for_completion_interruptible(&data->completion); in sx_common_read_proximity()
200 reinit_completion(&data->completion); in sx_common_read_proximity()
202 ret = data->chip_info->ops.wait_for_sample(data); in sx_common_read_proximity()
205 mutex_lock(&data->mutex); in sx_common_read_proximity()
210 ret = data->chip_info->ops.read_prox_data(data, chan, &rawval); in sx_common_read_proximity()
216 ret = sx_common_disable_irq(data, SX_COMMON_CONVDONE_IRQ); in sx_common_read_proximity()
220 ret = sx_common_put_read_channel(data, chan->channel); in sx_common_read_proximity()
224 mutex_unlock(&data->mutex); in sx_common_read_proximity()
229 sx_common_disable_irq(data, SX_COMMON_CONVDONE_IRQ); in sx_common_read_proximity()
231 sx_common_put_read_channel(data, chan->channel); in sx_common_read_proximity()
233 mutex_unlock(&data->mutex); in sx_common_read_proximity()
253 struct sx_common_data *data = iio_priv(indio_dev); in sx_common_read_event_config() local
255 return !!(data->chan_event & BIT(chan->channel)); in sx_common_read_event_config()
274 struct sx_common_data *data = iio_priv(indio_dev); in sx_common_write_event_config() local
279 if (!!(data->chan_event & BIT(chan->channel)) == state) in sx_common_write_event_config()
282 mutex_lock(&data->mutex); in sx_common_write_event_config()
284 ret = sx_common_get_event_channel(data, chan->channel); in sx_common_write_event_config()
287 if (!(data->chan_event & ~BIT(chan->channel))) { in sx_common_write_event_config()
288 ret = sx_common_enable_irq(data, eventirq); in sx_common_write_event_config()
290 sx_common_put_event_channel(data, chan->channel); in sx_common_write_event_config()
293 ret = sx_common_put_event_channel(data, chan->channel); in sx_common_write_event_config()
296 if (!data->chan_event) { in sx_common_write_event_config()
297 ret = sx_common_disable_irq(data, eventirq); in sx_common_write_event_config()
299 sx_common_get_event_channel(data, chan->channel); in sx_common_write_event_config()
304 mutex_unlock(&data->mutex); in sx_common_write_event_config()
312 struct sx_common_data *data = iio_priv(indio_dev); in sx_common_set_trigger_state() local
315 mutex_lock(&data->mutex); in sx_common_set_trigger_state()
318 ret = sx_common_enable_irq(data, SX_COMMON_CONVDONE_IRQ); in sx_common_set_trigger_state()
319 else if (!data->chan_read) in sx_common_set_trigger_state()
320 ret = sx_common_disable_irq(data, SX_COMMON_CONVDONE_IRQ); in sx_common_set_trigger_state()
324 data->trigger_enabled = state; in sx_common_set_trigger_state()
327 mutex_unlock(&data->mutex); in sx_common_set_trigger_state()
339 struct sx_common_data *data = iio_priv(indio_dev); in sx_common_irq_thread_handler() local
343 mutex_lock(&data->mutex); in sx_common_irq_thread_handler()
345 ret = regmap_read(data->regmap, SX_COMMON_REG_IRQ_SRC, &val); in sx_common_irq_thread_handler()
347 dev_err(&data->client->dev, "i2c transfer error in irq\n"); in sx_common_irq_thread_handler()
351 if (val & ((SX_COMMON_FAR_IRQ | SX_COMMON_CLOSE_IRQ) << data->chip_info->irq_msk_offset)) in sx_common_irq_thread_handler()
354 if (val & (SX_COMMON_CONVDONE_IRQ << data->chip_info->irq_msk_offset)) in sx_common_irq_thread_handler()
355 complete(&data->completion); in sx_common_irq_thread_handler()
358 mutex_unlock(&data->mutex); in sx_common_irq_thread_handler()
367 struct sx_common_data *data = iio_priv(indio_dev); in sx_common_trigger_handler() local
371 mutex_lock(&data->mutex); in sx_common_trigger_handler()
375 ret = data->chip_info->ops.read_prox_data(data, in sx_common_trigger_handler()
381 data->buffer.channels[i++] = val; in sx_common_trigger_handler()
384 iio_push_to_buffers_with_timestamp(indio_dev, &data->buffer, in sx_common_trigger_handler()
388 mutex_unlock(&data->mutex); in sx_common_trigger_handler()
397 struct sx_common_data *data = iio_priv(indio_dev); in sx_common_buffer_preenable() local
401 mutex_lock(&data->mutex); in sx_common_buffer_preenable()
406 ret = sx_common_update_chan_en(data, channels, data->chan_event); in sx_common_buffer_preenable()
407 mutex_unlock(&data->mutex); in sx_common_buffer_preenable()
413 struct sx_common_data *data = iio_priv(indio_dev); in sx_common_buffer_postdisable() local
416 mutex_lock(&data->mutex); in sx_common_buffer_postdisable()
417 ret = sx_common_update_chan_en(data, 0, data->chan_event); in sx_common_buffer_postdisable()
418 mutex_unlock(&data->mutex); in sx_common_buffer_postdisable()
452 struct sx_common_data *data = iio_priv(indio_dev); in sx_common_init_device() local
458 ret = regmap_write(data->regmap, data->chip_info->reg_reset, in sx_common_init_device()
466 ret = regmap_read(data->regmap, SX_COMMON_REG_IRQ_SRC, &val); in sx_common_init_device()
471 for (i = 0; i < data->chip_info->num_default_regs; i++) { in sx_common_init_device()
472 initval = data->chip_info->ops.get_default_reg(dev, i, &tmp); in sx_common_init_device()
473 ret = regmap_write(data->regmap, initval->reg, initval->def); in sx_common_init_device()
478 return data->chip_info->ops.init_compensation(indio_dev); in sx_common_init_device()
494 struct sx_common_data *data; in sx_common_probe() local
497 indio_dev = devm_iio_device_alloc(dev, sizeof(*data)); in sx_common_probe()
501 data = iio_priv(indio_dev); in sx_common_probe()
503 data->chip_info = chip_info; in sx_common_probe()
504 data->client = client; in sx_common_probe()
505 mutex_init(&data->mutex); in sx_common_probe()
506 init_completion(&data->completion); in sx_common_probe()
508 data->regmap = devm_regmap_init_i2c(client, regmap_config); in sx_common_probe()
509 if (IS_ERR(data->regmap)) in sx_common_probe()
510 return dev_err_probe(dev, PTR_ERR(data->regmap), in sx_common_probe()
521 ret = data->chip_info->ops.check_whoami(dev, indio_dev); in sx_common_probe()
527 indio_dev->channels = data->chip_info->iio_channels; in sx_common_probe()
528 indio_dev->num_channels = data->chip_info->num_iio_channels; in sx_common_probe()
529 indio_dev->info = &data->chip_info->iio_info; in sx_common_probe()
546 data->trig = devm_iio_trigger_alloc(dev, "%s-dev%d", in sx_common_probe()
549 if (!data->trig) in sx_common_probe()
552 data->trig->ops = &sx_common_trigger_ops; in sx_common_probe()
553 iio_trigger_set_drvdata(data->trig, indio_dev); in sx_common_probe()
555 ret = devm_iio_trigger_register(dev, data->trig); in sx_common_probe()