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_set_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()
118 static int sx_common_disable_irq(struct sx_common_data *data, unsigned int irq) in sx_common_disable_irq() argument
120 if (!data->client->irq) in sx_common_disable_irq()
122 return regmap_clear_bits(data->regmap, data->chip_info->reg_irq_msk, in sx_common_disable_irq()
123 irq << data->chip_info->irq_msk_offset); in sx_common_disable_irq()
126 static int sx_common_update_chan_en(struct sx_common_data *data, in sx_common_update_chan_en() argument
133 if ((data->chan_read | data->chan_event) != channels) { in sx_common_update_chan_en()
134 ret = regmap_update_bits(data->regmap, in sx_common_update_chan_en()
135 data->chip_info->reg_enable_chan, in sx_common_update_chan_en()
136 data->chip_info->mask_enable_chan, in sx_common_update_chan_en()
141 data->chan_read = chan_read; in sx_common_update_chan_en()
142 data->chan_event = chan_event; in sx_common_update_chan_en()
146 static int sx_common_get_read_channel(struct sx_common_data *data, int channel) in sx_common_get_read_channel() argument
148 return sx_common_update_chan_en(data, data->chan_read | BIT(channel), in sx_common_get_read_channel()
149 data->chan_event); in sx_common_get_read_channel()
152 static int sx_common_put_read_channel(struct sx_common_data *data, int channel) in sx_common_put_read_channel() argument
154 return sx_common_update_chan_en(data, data->chan_read & ~BIT(channel), in sx_common_put_read_channel()
155 data->chan_event); in sx_common_put_read_channel()
158 static int sx_common_get_event_channel(struct sx_common_data *data, int channel) in sx_common_get_event_channel() argument
160 return sx_common_update_chan_en(data, data->chan_read, in sx_common_get_event_channel()
161 data->chan_event | BIT(channel)); in sx_common_get_event_channel()
164 static int sx_common_put_event_channel(struct sx_common_data *data, int channel) in sx_common_put_event_channel() argument
166 return sx_common_update_chan_en(data, data->chan_read, in sx_common_put_event_channel()
167 data->chan_event & ~BIT(channel)); in sx_common_put_event_channel()
172 * @data: Internal data
179 int sx_common_read_proximity(struct sx_common_data *data, in sx_common_read_proximity() argument
185 mutex_lock(&data->mutex); in sx_common_read_proximity()
187 ret = sx_common_get_read_channel(data, chan->channel); in sx_common_read_proximity()
191 ret = sx_common_enable_irq(data, SX_COMMON_CONVDONE_IRQ); in sx_common_read_proximity()
195 mutex_unlock(&data->mutex); in sx_common_read_proximity()
197 if (data->client->irq) { in sx_common_read_proximity()
198 ret = wait_for_completion_interruptible(&data->completion); in sx_common_read_proximity()
199 reinit_completion(&data->completion); in sx_common_read_proximity()
201 ret = data->chip_info->ops.wait_for_sample(data); in sx_common_read_proximity()
204 mutex_lock(&data->mutex); in sx_common_read_proximity()
209 ret = data->chip_info->ops.read_prox_data(data, chan, &rawval); in sx_common_read_proximity()
215 ret = sx_common_disable_irq(data, SX_COMMON_CONVDONE_IRQ); in sx_common_read_proximity()
219 ret = sx_common_put_read_channel(data, chan->channel); in sx_common_read_proximity()
223 mutex_unlock(&data->mutex); in sx_common_read_proximity()
228 sx_common_disable_irq(data, SX_COMMON_CONVDONE_IRQ); in sx_common_read_proximity()
230 sx_common_put_read_channel(data, chan->channel); in sx_common_read_proximity()
232 mutex_unlock(&data->mutex); in sx_common_read_proximity()
252 struct sx_common_data *data = iio_priv(indio_dev); in sx_common_read_event_config() local
254 return !!(data->chan_event & BIT(chan->channel)); in sx_common_read_event_config()
273 struct sx_common_data *data = iio_priv(indio_dev); in sx_common_write_event_config() local
278 if (!!(data->chan_event & BIT(chan->channel)) == state) in sx_common_write_event_config()
281 mutex_lock(&data->mutex); in sx_common_write_event_config()
283 ret = sx_common_get_event_channel(data, chan->channel); in sx_common_write_event_config()
286 if (!(data->chan_event & ~BIT(chan->channel))) { in sx_common_write_event_config()
287 ret = sx_common_enable_irq(data, eventirq); in sx_common_write_event_config()
289 sx_common_put_event_channel(data, chan->channel); in sx_common_write_event_config()
292 ret = sx_common_put_event_channel(data, chan->channel); in sx_common_write_event_config()
295 if (!data->chan_event) { in sx_common_write_event_config()
296 ret = sx_common_disable_irq(data, eventirq); in sx_common_write_event_config()
298 sx_common_get_event_channel(data, chan->channel); in sx_common_write_event_config()
303 mutex_unlock(&data->mutex); in sx_common_write_event_config()
311 struct sx_common_data *data = iio_priv(indio_dev); in sx_common_set_trigger_state() local
314 mutex_lock(&data->mutex); in sx_common_set_trigger_state()
317 ret = sx_common_enable_irq(data, SX_COMMON_CONVDONE_IRQ); in sx_common_set_trigger_state()
318 else if (!data->chan_read) in sx_common_set_trigger_state()
319 ret = sx_common_disable_irq(data, SX_COMMON_CONVDONE_IRQ); in sx_common_set_trigger_state()
323 data->trigger_enabled = state; in sx_common_set_trigger_state()
326 mutex_unlock(&data->mutex); in sx_common_set_trigger_state()
338 struct sx_common_data *data = iio_priv(indio_dev); in sx_common_irq_thread_handler() local
342 mutex_lock(&data->mutex); in sx_common_irq_thread_handler()
344 ret = regmap_read(data->regmap, SX_COMMON_REG_IRQ_SRC, &val); in sx_common_irq_thread_handler()
346 dev_err(&data->client->dev, "i2c transfer error in irq\n"); in sx_common_irq_thread_handler()
350 if (val & ((SX_COMMON_FAR_IRQ | SX_COMMON_CLOSE_IRQ) << data->chip_info->irq_msk_offset)) in sx_common_irq_thread_handler()
353 if (val & (SX_COMMON_CONVDONE_IRQ << data->chip_info->irq_msk_offset)) in sx_common_irq_thread_handler()
354 complete(&data->completion); in sx_common_irq_thread_handler()
357 mutex_unlock(&data->mutex); in sx_common_irq_thread_handler()
366 struct sx_common_data *data = iio_priv(indio_dev); in sx_common_trigger_handler() local
370 mutex_lock(&data->mutex); in sx_common_trigger_handler()
373 ret = data->chip_info->ops.read_prox_data(data, in sx_common_trigger_handler()
379 data->buffer.channels[i++] = val; in sx_common_trigger_handler()
382 iio_push_to_buffers_with_timestamp(indio_dev, &data->buffer, in sx_common_trigger_handler()
386 mutex_unlock(&data->mutex); in sx_common_trigger_handler()
395 struct sx_common_data *data = iio_priv(indio_dev); in sx_common_buffer_preenable() local
399 mutex_lock(&data->mutex); in sx_common_buffer_preenable()
403 ret = sx_common_update_chan_en(data, channels, data->chan_event); in sx_common_buffer_preenable()
404 mutex_unlock(&data->mutex); in sx_common_buffer_preenable()
410 struct sx_common_data *data = iio_priv(indio_dev); in sx_common_buffer_postdisable() local
413 mutex_lock(&data->mutex); in sx_common_buffer_postdisable()
414 ret = sx_common_update_chan_en(data, 0, data->chan_event); in sx_common_buffer_postdisable()
415 mutex_unlock(&data->mutex); in sx_common_buffer_postdisable()
428 struct sx_common_data *data = iio_priv(indio_dev); in sx_common_init_device() local
434 ret = regmap_write(data->regmap, data->chip_info->reg_reset, in sx_common_init_device()
442 ret = regmap_read(data->regmap, SX_COMMON_REG_IRQ_SRC, &val); in sx_common_init_device()
447 for (i = 0; i < data->chip_info->num_default_regs; i++) { in sx_common_init_device()
448 initval = data->chip_info->ops.get_default_reg(dev, i, &tmp); in sx_common_init_device()
449 ret = regmap_write(data->regmap, initval->reg, initval->def); in sx_common_init_device()
454 return data->chip_info->ops.init_compensation(indio_dev); in sx_common_init_device()
470 struct sx_common_data *data; in sx_common_probe() local
473 indio_dev = devm_iio_device_alloc(dev, sizeof(*data)); in sx_common_probe()
477 data = iio_priv(indio_dev); in sx_common_probe()
479 data->chip_info = chip_info; in sx_common_probe()
480 data->client = client; in sx_common_probe()
481 mutex_init(&data->mutex); in sx_common_probe()
482 init_completion(&data->completion); in sx_common_probe()
484 data->regmap = devm_regmap_init_i2c(client, regmap_config); in sx_common_probe()
485 if (IS_ERR(data->regmap)) in sx_common_probe()
486 return dev_err_probe(dev, PTR_ERR(data->regmap), in sx_common_probe()
497 ret = data->chip_info->ops.check_whoami(dev, indio_dev); in sx_common_probe()
503 indio_dev->channels = data->chip_info->iio_channels; in sx_common_probe()
504 indio_dev->num_channels = data->chip_info->num_iio_channels; in sx_common_probe()
505 indio_dev->info = &data->chip_info->iio_info; in sx_common_probe()
522 data->trig = devm_iio_trigger_alloc(dev, "%s-dev%d", in sx_common_probe()
525 if (!data->trig) in sx_common_probe()
528 data->trig->ops = &sx_common_trigger_ops; in sx_common_probe()
529 iio_trigger_set_drvdata(data->trig, indio_dev); in sx_common_probe()
531 ret = devm_iio_trigger_register(dev, data->trig); in sx_common_probe()