Lines Matching +full:iio +full:- +full:consumer

1 // SPDX-License-Identifier: GPL-2.0-only
14 #include <linux/iio/iio.h>
15 #include <linux/iio/sysfs.h>
16 #include <linux/iio/events.h>
17 #include <linux/iio/consumer.h> /* To get our ADC channel */
18 #include <linux/iio/types.h> /* To deal with our ADC channel */
23 #include <linux/regulator/consumer.h>
24 #include <linux/gpio/consumer.h>
36 * struct cm3605 - CM3605 state
40 * @aout: IIO ADC channel to convert the AOUT signal
62 IIO_EV_TYPE_THRESH, cm3605->dir); in cm3605_prox_irq()
66 if (cm3605->dir == IIO_EV_DIR_RISING) in cm3605_prox_irq()
67 cm3605->dir = IIO_EV_DIR_FALLING; in cm3605_prox_irq()
69 cm3605->dir = IIO_EV_DIR_RISING; in cm3605_prox_irq()
79 ret = iio_read_channel_processed(cm3605->aout, &res); in cm3605_get_lux()
83 dev_dbg(cm3605->dev, "read %d mV from ADC\n", res); in cm3605_get_lux()
94 dev_err(cm3605->dev, "device out of range\n"); in cm3605_get_lux()
97 lux = res - 30; in cm3605_get_lux()
100 lux *= cm3605->als_max; in cm3605_get_lux()
115 switch (chan->type) { in cm3605_read_raw()
123 return -EINVAL; in cm3605_read_raw()
126 return -EINVAL; in cm3605_read_raw()
159 struct device *dev = &pdev->dev; in cm3605_probe()
167 return -ENOMEM; in cm3605_probe()
171 cm3605->dev = dev; in cm3605_probe()
172 cm3605->dir = IIO_EV_DIR_FALLING; in cm3605_probe()
174 ret = device_property_read_u32(dev, "capella,aset-resistance-ohms", &rset); in cm3605_probe()
181 cm3605->als_max = 650; in cm3605_probe()
184 cm3605->als_max = 300; in cm3605_probe()
187 cm3605->als_max = 100; in cm3605_probe()
190 cm3605->als_max = 50; in cm3605_probe()
193 dev_info(dev, "non-standard resistance\n"); in cm3605_probe()
194 return -EINVAL; in cm3605_probe()
197 cm3605->aout = devm_iio_channel_get(dev, "aout"); in cm3605_probe()
198 if (IS_ERR(cm3605->aout)) { in cm3605_probe()
199 ret = PTR_ERR(cm3605->aout); in cm3605_probe()
200 ret = (ret == -ENODEV) ? -EPROBE_DEFER : ret; in cm3605_probe()
203 ret = iio_get_channel_type(cm3605->aout, &ch_type); in cm3605_probe()
207 dev_err(dev, "wrong type of IIO channel specified for AOUT\n"); in cm3605_probe()
208 return -EINVAL; in cm3605_probe()
211 cm3605->vdd = devm_regulator_get(dev, "vdd"); in cm3605_probe()
212 if (IS_ERR(cm3605->vdd)) in cm3605_probe()
213 return dev_err_probe(dev, PTR_ERR(cm3605->vdd), in cm3605_probe()
216 ret = regulator_enable(cm3605->vdd); in cm3605_probe()
222 cm3605->aset = devm_gpiod_get(dev, "aset", GPIOD_OUT_HIGH); in cm3605_probe()
223 if (IS_ERR(cm3605->aset)) { in cm3605_probe()
224 ret = dev_err_probe(dev, PTR_ERR(cm3605->aset), "no ASET GPIO\n"); in cm3605_probe()
242 led_trigger_register_simple("cm3605", &cm3605->led); in cm3605_probe()
243 led_trigger_event(cm3605->led, LED_FULL); in cm3605_probe()
245 indio_dev->info = &cm3605_info; in cm3605_probe()
246 indio_dev->name = "cm3605"; in cm3605_probe()
247 indio_dev->channels = cm3605_channels; in cm3605_probe()
248 indio_dev->num_channels = ARRAY_SIZE(cm3605_channels); in cm3605_probe()
249 indio_dev->modes = INDIO_DIRECT_MODE; in cm3605_probe()
255 cm3605->als_max); in cm3605_probe()
260 led_trigger_event(cm3605->led, LED_OFF); in cm3605_probe()
261 led_trigger_unregister_simple(cm3605->led); in cm3605_probe()
263 gpiod_set_value_cansleep(cm3605->aset, 0); in cm3605_probe()
265 regulator_disable(cm3605->vdd); in cm3605_probe()
274 led_trigger_event(cm3605->led, LED_OFF); in cm3605_remove()
275 led_trigger_unregister_simple(cm3605->led); in cm3605_remove()
276 gpiod_set_value_cansleep(cm3605->aset, 0); in cm3605_remove()
278 regulator_disable(cm3605->vdd); in cm3605_remove()
286 led_trigger_event(cm3605->led, LED_OFF); in cm3605_pm_suspend()
287 regulator_disable(cm3605->vdd); in cm3605_pm_suspend()
298 ret = regulator_enable(cm3605->vdd); in cm3605_pm_resume()
301 led_trigger_event(cm3605->led, LED_FULL); in cm3605_pm_resume()