Lines Matching +full:use +full:- +full:prox

1 // SPDX-License-Identifier: GPL-2.0-only
14 * https://lore.kernel.org/lkml/1315556546-7445-1-git-send-email-dg77.kim@samsung.com/
17 * https://lore.kernel.org/linux-input/20190125175045.22576-1-pawel.mikolaj.chmiel@gmail.com/
18 * Based partly on code from the Samsung GT-S7710 by <mjchen@sta.samsung.com>
42 /* ------------------------------------------------------------------------ */
45 /* ------------------------------------------------------------------------ */
46 /* 0 PROX X X X X X X X VO H'00 R */
52 /* ------------------------------------------------------------------------ */
54 /* LED0 :Select switch for LED driver's On-registence(0:2x higher, 1:normal)*/
127 * struct gp2ap002 - GP2AP002 state
161 if (!gp2ap002->enabled) in gp2ap002_prox_irq()
164 ret = regmap_read(gp2ap002->map, GP2AP002_PROX, &val); in gp2ap002_prox_irq()
166 dev_err(gp2ap002->dev, "error reading proximity\n"); in gp2ap002_prox_irq()
172 dev_dbg(gp2ap002->dev, "close\n"); in gp2ap002_prox_irq()
173 ret = regmap_write(gp2ap002->map, GP2AP002_HYS, in gp2ap002_prox_irq()
174 gp2ap002->hys_far); in gp2ap002_prox_irq()
176 dev_err(gp2ap002->dev, in gp2ap002_prox_irq()
182 dev_dbg(gp2ap002->dev, "far\n"); in gp2ap002_prox_irq()
183 ret = regmap_write(gp2ap002->map, GP2AP002_HYS, in gp2ap002_prox_irq()
184 gp2ap002->hys_close); in gp2ap002_prox_irq()
186 dev_err(gp2ap002->dev, in gp2ap002_prox_irq()
197 * register, we are hard-coding ~8 ms in probe() so wait some more in gp2ap002_prox_irq()
198 * than this, 20-30 ms. in gp2ap002_prox_irq()
203 ret = regmap_write(gp2ap002->map, GP2AP002_CON, in gp2ap002_prox_irq()
206 dev_err(gp2ap002->dev, "error setting up VOUT control\n"); in gp2ap002_prox_irq()
233 ret = iio_read_channel_processed(gp2ap002->alsout, &res); in gp2ap002_get_lux()
237 dev_dbg(gp2ap002->dev, "read %d mA from ADC\n", res); in gp2ap002_get_lux()
240 res = clamp(res, 0, (int)ARRAY_SIZE(gp2ap002_illuminance_table) - 1); in gp2ap002_get_lux()
253 pm_runtime_get_sync(gp2ap002->dev); in gp2ap002_read_raw()
257 switch (chan->type) { in gp2ap002_read_raw()
266 ret = -EINVAL; in gp2ap002_read_raw()
270 ret = -EINVAL; in gp2ap002_read_raw()
274 pm_runtime_mark_last_busy(gp2ap002->dev); in gp2ap002_read_raw()
275 pm_runtime_put_autosuspend(gp2ap002->dev); in gp2ap002_read_raw()
285 ret = regmap_write(gp2ap002->map, GP2AP002_GAIN, in gp2ap002_init()
288 dev_err(gp2ap002->dev, "error setting up LED gain\n"); in gp2ap002_init()
291 ret = regmap_write(gp2ap002->map, GP2AP002_HYS, gp2ap002->hys_far); in gp2ap002_init()
293 dev_err(gp2ap002->dev, in gp2ap002_init()
299 ret = regmap_write(gp2ap002->map, GP2AP002_CYCLE, in gp2ap002_init()
302 dev_err(gp2ap002->dev, in gp2ap002_init()
308 ret = regmap_write(gp2ap002->map, GP2AP002_OPMOD, in gp2ap002_init()
312 dev_err(gp2ap002->dev, "error setting up operation mode\n"); in gp2ap002_init()
317 ret = regmap_write(gp2ap002->map, GP2AP002_CON, in gp2ap002_init()
320 dev_err(gp2ap002->dev, "error setting up VOUT control\n"); in gp2ap002_init()
336 return gp2ap002->enabled; in gp2ap002_read_event_config()
353 pm_runtime_get_sync(gp2ap002->dev); in gp2ap002_write_event_config()
354 gp2ap002->enabled = true; in gp2ap002_write_event_config()
356 pm_runtime_mark_last_busy(gp2ap002->dev); in gp2ap002_write_event_config()
357 pm_runtime_put_autosuspend(gp2ap002->dev); in gp2ap002_write_event_config()
358 gp2ap002->enabled = false; in gp2ap002_write_event_config()
432 struct device *dev = &client->dev; in gp2ap002_probe()
447 return -ENOMEM; in gp2ap002_probe()
451 gp2ap002->dev = dev; in gp2ap002_probe()
454 * Check the device compatible like this makes it possible to use in gp2ap002_probe()
463 gp2ap002->is_gp2ap002s00f = !strcmp(compat, "sharp,gp2ap002s00f"); in gp2ap002_probe()
470 gp2ap002->map = regmap; in gp2ap002_probe()
475 * modes "A", "B1" and "B2" with fixed values to be use but vendor in gp2ap002_probe()
483 ret = device_property_read_u8(dev, "sharp,proximity-far-hysteresis", in gp2ap002_probe()
490 gp2ap002->hys_far = val; in gp2ap002_probe()
492 ret = device_property_read_u8(dev, "sharp,proximity-close-hysteresis", in gp2ap002_probe()
499 gp2ap002->hys_close = val; in gp2ap002_probe()
502 if (!gp2ap002->is_gp2ap002s00f) { in gp2ap002_probe()
503 gp2ap002->alsout = devm_iio_channel_get(dev, "alsout"); in gp2ap002_probe()
504 if (IS_ERR(gp2ap002->alsout)) { in gp2ap002_probe()
505 ret = PTR_ERR(gp2ap002->alsout); in gp2ap002_probe()
506 ret = (ret == -ENODEV) ? -EPROBE_DEFER : ret; in gp2ap002_probe()
509 ret = iio_get_channel_type(gp2ap002->alsout, &ch_type); in gp2ap002_probe()
515 return -EINVAL; in gp2ap002_probe()
519 gp2ap002->vdd = devm_regulator_get(dev, "vdd"); in gp2ap002_probe()
520 if (IS_ERR(gp2ap002->vdd)) in gp2ap002_probe()
521 return dev_err_probe(dev, PTR_ERR(gp2ap002->vdd), in gp2ap002_probe()
524 gp2ap002->vio = devm_regulator_get(dev, "vio"); in gp2ap002_probe()
525 if (IS_ERR(gp2ap002->vio)) in gp2ap002_probe()
526 return dev_err_probe(dev, PTR_ERR(gp2ap002->vio), in gp2ap002_probe()
530 ret = regulator_set_voltage(gp2ap002->vdd, 2400000, 3600000); in gp2ap002_probe()
537 ret = regulator_get_voltage(gp2ap002->vdd); in gp2ap002_probe()
542 ret = regulator_set_voltage(gp2ap002->vio, 1650000, ret); in gp2ap002_probe()
548 ret = regulator_enable(gp2ap002->vdd); in gp2ap002_probe()
553 ret = regulator_enable(gp2ap002->vio); in gp2ap002_probe()
573 gp2ap002->enabled = false; in gp2ap002_probe()
575 ret = devm_request_threaded_irq(dev, client->irq, NULL, in gp2ap002_probe()
582 gp2ap002->irq = client->irq; in gp2ap002_probe()
586 * measurement after power-on, do not shut it down unnecessarily. in gp2ap002_probe()
593 indio_dev->info = &gp2ap002_info; in gp2ap002_probe()
594 indio_dev->name = "gp2ap002"; in gp2ap002_probe()
595 indio_dev->channels = gp2ap002_channels; in gp2ap002_probe()
596 /* Skip light channel for the proximity-only sensor */ in gp2ap002_probe()
598 if (gp2ap002->is_gp2ap002s00f) in gp2ap002_probe()
599 num_chan--; in gp2ap002_probe()
600 indio_dev->num_channels = num_chan; in gp2ap002_probe()
601 indio_dev->modes = INDIO_DIRECT_MODE; in gp2ap002_probe()
615 regulator_disable(gp2ap002->vio); in gp2ap002_probe()
617 regulator_disable(gp2ap002->vdd); in gp2ap002_probe()
625 struct device *dev = &client->dev; in gp2ap002_remove()
631 regulator_disable(gp2ap002->vio); in gp2ap002_remove()
632 regulator_disable(gp2ap002->vdd); in gp2ap002_remove()
642 disable_irq(gp2ap002->irq); in gp2ap002_runtime_suspend()
645 ret = regmap_write(gp2ap002->map, GP2AP002_OPMOD, 0x00); in gp2ap002_runtime_suspend()
647 dev_err(gp2ap002->dev, "error setting up operation mode\n"); in gp2ap002_runtime_suspend()
654 regulator_disable(gp2ap002->vio); in gp2ap002_runtime_suspend()
655 regulator_disable(gp2ap002->vdd); in gp2ap002_runtime_suspend()
666 ret = regulator_enable(gp2ap002->vdd); in gp2ap002_runtime_resume()
671 ret = regulator_enable(gp2ap002->vio); in gp2ap002_runtime_resume()
681 dev_err(dev, "re-initialization failed\n"); in gp2ap002_runtime_resume()
685 /* Re-activate the IRQ */ in gp2ap002_runtime_resume()
686 enable_irq(gp2ap002->irq); in gp2ap002_runtime_resume()