Lines Matching refs:gp2ap002
140 struct gp2ap002 { struct
156 struct gp2ap002 *gp2ap002 = iio_priv(indio_dev); in gp2ap002_prox_irq() local
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()
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()
228 static int gp2ap002_get_lux(struct gp2ap002 *gp2ap002) in gp2ap002_get_lux() argument
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()
250 struct gp2ap002 *gp2ap002 = iio_priv(indio_dev); in gp2ap002_read_raw() local
253 pm_runtime_get_sync(gp2ap002->dev); in gp2ap002_read_raw()
259 ret = gp2ap002_get_lux(gp2ap002); 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()
280 static int gp2ap002_init(struct gp2ap002 *gp2ap002) in gp2ap002_init() argument
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()
330 struct gp2ap002 *gp2ap002 = iio_priv(indio_dev); in gp2ap002_read_event_config() local
336 return gp2ap002->enabled; in gp2ap002_read_event_config()
345 struct gp2ap002 *gp2ap002 = iio_priv(indio_dev); in gp2ap002_write_event_config() local
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()
430 struct gp2ap002 *gp2ap002; in gp2ap002_probe() local
445 indio_dev = devm_iio_device_alloc(dev, sizeof(*gp2ap002)); in gp2ap002_probe()
450 gp2ap002 = iio_priv(indio_dev); in gp2ap002_probe()
451 gp2ap002->dev = dev; in gp2ap002_probe()
463 gp2ap002->is_gp2ap002s00f = !strcmp(compat, "sharp,gp2ap002s00f"); in gp2ap002_probe()
470 gp2ap002->map = regmap; in gp2ap002_probe()
490 gp2ap002->hys_far = val; 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()
509 ret = iio_get_channel_type(gp2ap002->alsout, &ch_type); 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()
565 ret = gp2ap002_init(gp2ap002); in gp2ap002_probe()
573 gp2ap002->enabled = false; in gp2ap002_probe()
582 gp2ap002->irq = client->irq; in gp2ap002_probe()
598 if (gp2ap002->is_gp2ap002s00f) in gp2ap002_probe()
615 regulator_disable(gp2ap002->vio); in gp2ap002_probe()
617 regulator_disable(gp2ap002->vdd); in gp2ap002_probe()
624 struct gp2ap002 *gp2ap002 = iio_priv(indio_dev); in gp2ap002_remove() local
631 regulator_disable(gp2ap002->vio); in gp2ap002_remove()
632 regulator_disable(gp2ap002->vdd); in gp2ap002_remove()
638 struct gp2ap002 *gp2ap002 = iio_priv(indio_dev); in gp2ap002_runtime_suspend() local
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()
663 struct gp2ap002 *gp2ap002 = iio_priv(indio_dev); in gp2ap002_runtime_resume() local
666 ret = regulator_enable(gp2ap002->vdd); in gp2ap002_runtime_resume()
671 ret = regulator_enable(gp2ap002->vio); in gp2ap002_runtime_resume()
679 ret = gp2ap002_init(gp2ap002); in gp2ap002_runtime_resume()
686 enable_irq(gp2ap002->irq); in gp2ap002_runtime_resume()