Lines Matching +full:high +full:- +full:threshold

1 // SPDX-License-Identifier: GPL-2.0-only
26 #define VCNL_PS_LO_THR_HI 0x8a /* High byte of low threshold value */
27 #define VCNL_PS_LO_THR_LO 0x8b /* Low byte of low threshold value */
28 #define VCNL_PS_HI_THR_HI 0x8c /* High byte of high threshold value */
29 #define VCNL_PS_HI_THR_LO 0x8d /* Low byte of high threshold value */
35 #define VCNL_PS_OD BIT(3) /* start on-demand proximity
47 /* Enable interrupts on low or high thresholds */
51 #define VCNL_INT_TH_HI BIT(0) /* High threshold hit */
52 #define VCNL_INT_TH_LOW BIT(1) /* Low threshold hit */
69 * struct vcnl3020_data - vcnl3020 specific data.
85 * struct vcnl3020_property - vcnl3020 property.
106 .name = "vishay,led-current-microamp",
117 rc = device_property_read_u32(data->dev, prop.name, &val); in vcnl3020_get_and_apply_property()
124 rc = regmap_write(data->regmap, prop.reg, val); in vcnl3020_get_and_apply_property()
126 dev_err(data->dev, "Error (%d) setting property (%s)\n", in vcnl3020_get_and_apply_property()
138 rc = regmap_read(data->regmap, VCNL_PROD_REV, &reg); in vcnl3020_init()
140 dev_err(data->dev, in vcnl3020_init()
146 dev_err(data->dev, in vcnl3020_init()
149 return -ENODEV; in vcnl3020_init()
152 data->rev = reg; in vcnl3020_init()
153 mutex_init(&data->lock); in vcnl3020_init()
164 rc = regmap_read(data->regmap, VCNL_COMMAND, &cmd); in vcnl3020_is_in_periodic_mode()
166 dev_err(data->dev, in vcnl3020_is_in_periodic_mode()
179 mutex_lock(&data->lock); in vcnl3020_measure_proximity()
183 rc = -EBUSY; in vcnl3020_measure_proximity()
187 rc = regmap_write(data->regmap, VCNL_COMMAND, VCNL_PS_OD); in vcnl3020_measure_proximity()
192 rc = regmap_read_poll_timeout(data->regmap, VCNL_COMMAND, reg, in vcnl3020_measure_proximity()
196 dev_err(data->dev, in vcnl3020_measure_proximity()
201 /* high & low result bytes read */ in vcnl3020_measure_proximity()
202 rc = regmap_bulk_read(data->regmap, VCNL_PS_RESULT_HI, &data->buf, in vcnl3020_measure_proximity()
203 sizeof(data->buf)); in vcnl3020_measure_proximity()
207 *val = be16_to_cpu(data->buf); in vcnl3020_measure_proximity()
210 mutex_unlock(&data->lock); in vcnl3020_measure_proximity()
221 rc = regmap_read(data->regmap, VCNL_PROXIMITY_RATE, &prox_rate); in vcnl3020_read_proxy_samp_freq()
226 return -EINVAL; in vcnl3020_read_proxy_samp_freq()
238 int index = -1; in vcnl3020_write_proxy_samp_freq()
241 mutex_lock(&data->lock); in vcnl3020_write_proxy_samp_freq()
245 rc = -EBUSY; in vcnl3020_write_proxy_samp_freq()
258 rc = -EINVAL; in vcnl3020_write_proxy_samp_freq()
262 rc = regmap_write(data->regmap, VCNL_PROXIMITY_RATE, index); in vcnl3020_write_proxy_samp_freq()
264 dev_err(data->dev, in vcnl3020_write_proxy_samp_freq()
268 mutex_unlock(&data->lock); in vcnl3020_write_proxy_samp_freq()
278 rc = regmap_read(data->regmap, VCNL_PS_ICR, &icr); in vcnl3020_is_thr_enabled()
280 dev_err(data->dev, in vcnl3020_is_thr_enabled()
302 rc = regmap_bulk_read(data->regmap, VCNL_PS_HI_THR_HI, in vcnl3020_read_event()
303 &data->buf, sizeof(data->buf)); in vcnl3020_read_event()
306 *val = be16_to_cpu(data->buf); in vcnl3020_read_event()
309 rc = regmap_bulk_read(data->regmap, VCNL_PS_LO_THR_HI, in vcnl3020_read_event()
310 &data->buf, sizeof(data->buf)); in vcnl3020_read_event()
313 *val = be16_to_cpu(data->buf); in vcnl3020_read_event()
316 return -EINVAL; in vcnl3020_read_event()
319 return -EINVAL; in vcnl3020_read_event()
333 mutex_lock(&data->lock); in vcnl3020_write_event()
339 /* 16 bit word/ low * high */ in vcnl3020_write_event()
340 data->buf = cpu_to_be16(val); in vcnl3020_write_event()
341 rc = regmap_bulk_write(data->regmap, VCNL_PS_HI_THR_HI, in vcnl3020_write_event()
342 &data->buf, sizeof(data->buf)); in vcnl3020_write_event()
348 data->buf = cpu_to_be16(val); in vcnl3020_write_event()
349 rc = regmap_bulk_write(data->regmap, VCNL_PS_LO_THR_HI, in vcnl3020_write_event()
350 &data->buf, sizeof(data->buf)); in vcnl3020_write_event()
356 rc = -EINVAL; in vcnl3020_write_event()
360 rc = -EINVAL; in vcnl3020_write_event()
364 mutex_unlock(&data->lock); in vcnl3020_write_event()
375 mutex_lock(&data->lock); in vcnl3020_enable_periodic()
380 rc = regmap_write(data->regmap, VCNL_COMMAND, cmd); in vcnl3020_enable_periodic()
382 dev_err(data->dev, in vcnl3020_enable_periodic()
388 * Enable interrupts on threshold, for proximity data by in vcnl3020_enable_periodic()
391 rc = regmap_write(data->regmap, VCNL_PS_ICR, VCNL_ICR_THRES_EN); in vcnl3020_enable_periodic()
393 dev_err(data->dev, in vcnl3020_enable_periodic()
397 mutex_unlock(&data->lock); in vcnl3020_enable_periodic()
407 mutex_lock(&data->lock); in vcnl3020_disable_periodic()
409 rc = regmap_write(data->regmap, VCNL_COMMAND, 0); in vcnl3020_disable_periodic()
411 dev_err(data->dev, in vcnl3020_disable_periodic()
416 rc = regmap_write(data->regmap, VCNL_PS_ICR, 0); in vcnl3020_disable_periodic()
418 dev_err(data->dev, in vcnl3020_disable_periodic()
424 rc = regmap_write(data->regmap, VCNL_ISR, 0); in vcnl3020_disable_periodic()
426 dev_err(data->dev, in vcnl3020_disable_periodic()
430 mutex_unlock(&data->lock); in vcnl3020_disable_periodic()
454 switch (chan->type) { in vcnl3020_write_event_config()
458 return -EINVAL; in vcnl3020_write_event_config()
469 switch (chan->type) { in vcnl3020_read_event_config()
473 return -EINVAL; in vcnl3020_read_event_config()
523 return -EINVAL; in vcnl3020_read_raw()
537 return -EINVAL; in vcnl3020_write_raw()
553 return -EINVAL; in vcnl3020_read_avail()
580 rc = regmap_read(data->regmap, VCNL_ISR, &isr); in vcnl3020_handle_irq_thread()
582 dev_err(data->dev, "Error (%d) reading reg (0x%x)\n", in vcnl3020_handle_irq_thread()
596 rc = regmap_write(data->regmap, VCNL_ISR, isr & VCNL_ICR_THRES_EN); in vcnl3020_handle_irq_thread()
598 dev_err(data->dev, "Error (%d) writing in reg (0x%x)\n", in vcnl3020_handle_irq_thread()
613 dev_err(&client->dev, "regmap_init failed\n"); in vcnl3020_probe()
617 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); in vcnl3020_probe()
619 return -ENOMEM; in vcnl3020_probe()
623 data->regmap = regmap; in vcnl3020_probe()
624 data->dev = &client->dev; in vcnl3020_probe()
630 indio_dev->info = &vcnl3020_info; in vcnl3020_probe()
631 indio_dev->channels = vcnl3020_channels; in vcnl3020_probe()
632 indio_dev->num_channels = ARRAY_SIZE(vcnl3020_channels); in vcnl3020_probe()
633 indio_dev->name = "vcnl3020"; in vcnl3020_probe()
634 indio_dev->modes = INDIO_DIRECT_MODE; in vcnl3020_probe()
636 if (client->irq) { in vcnl3020_probe()
637 rc = devm_request_threaded_irq(&client->dev, client->irq, in vcnl3020_probe()
639 IRQF_ONESHOT, indio_dev->name, in vcnl3020_probe()
642 dev_err(&client->dev, in vcnl3020_probe()
644 client->irq); in vcnl3020_probe()
649 return devm_iio_device_register(&client->dev, indio_dev); in vcnl3020_probe()