Lines Matching +full:vref +full:- +full:p

1 // SPDX-License-Identifier: GPL-2.0-only
4 * Copyright (C) 2010-2011 Michael Hennerich, Analog Devices Inc.
7 * Copyright (C) 2008-2010 Jonathan Cameron
10 * Copyright (C) 2002-2004 Stefan Eletzhofer
101 * struct ad799x_chip_config - chip specific information
113 * struct ad799x_chip_info - chip specific information
128 struct regulator *vref; member
140 switch (st->id) { in ad799x_write_config()
143 return i2c_smbus_write_word_swapped(st->client, AD7998_CONF_REG, in ad799x_write_config()
148 return i2c_smbus_write_byte_data(st->client, AD7998_CONF_REG, in ad799x_write_config()
152 st->config = val; in ad799x_write_config()
159 switch (st->id) { in ad799x_read_config()
162 return i2c_smbus_read_word_swapped(st->client, AD7998_CONF_REG); in ad799x_read_config()
166 return i2c_smbus_read_byte_data(st->client, AD7998_CONF_REG); in ad799x_read_config()
169 return st->config; in ad799x_read_config()
183 st->config = ret; in ad799x_update_config()
188 static irqreturn_t ad799x_trigger_handler(int irq, void *p) in ad799x_trigger_handler() argument
190 struct iio_poll_func *pf = p; in ad799x_trigger_handler()
191 struct iio_dev *indio_dev = pf->indio_dev; in ad799x_trigger_handler()
196 switch (st->id) { in ad799x_trigger_handler()
200 cmd = st->config | in ad799x_trigger_handler()
201 (*indio_dev->active_scan_mask << AD799X_CHANNEL_SHIFT); in ad799x_trigger_handler()
206 cmd = (*indio_dev->active_scan_mask << AD799X_CHANNEL_SHIFT) | in ad799x_trigger_handler()
217 b_sent = i2c_smbus_read_i2c_block_data(st->client, in ad799x_trigger_handler()
218 cmd, st->transfer_size, st->rx_buf); in ad799x_trigger_handler()
222 iio_push_to_buffers_with_timestamp(indio_dev, st->rx_buf, in ad799x_trigger_handler()
225 iio_trigger_notify_done(indio_dev->trig); in ad799x_trigger_handler()
235 kfree(st->rx_buf); in ad799x_update_scan_mode()
236 st->rx_buf = kmalloc(indio_dev->scan_bytes, GFP_KERNEL); in ad799x_update_scan_mode()
237 if (!st->rx_buf) in ad799x_update_scan_mode()
238 return -ENOMEM; in ad799x_update_scan_mode()
240 st->transfer_size = bitmap_weight(scan_mask, in ad799x_update_scan_mode()
243 switch (st->id) { in ad799x_update_scan_mode()
249 st->config &= ~(GENMASK(7, 0) << AD799X_CHANNEL_SHIFT); in ad799x_update_scan_mode()
250 st->config |= (*scan_mask << AD799X_CHANNEL_SHIFT); in ad799x_update_scan_mode()
251 return ad799x_write_config(st, st->config); in ad799x_update_scan_mode()
261 switch (st->id) { in ad799x_scan_direct()
265 cmd = st->config | (BIT(ch) << AD799X_CHANNEL_SHIFT); in ad799x_scan_direct()
277 return -EINVAL; in ad799x_scan_direct()
280 return i2c_smbus_read_word_swapped(st->client, cmd); in ad799x_scan_direct()
297 mutex_lock(&st->lock); in ad799x_read_raw()
298 ret = ad799x_scan_direct(st, chan->scan_index); in ad799x_read_raw()
299 mutex_unlock(&st->lock); in ad799x_read_raw()
304 *val = (ret >> chan->scan_type.shift) & in ad799x_read_raw()
305 GENMASK(chan->scan_type.realbits - 1, 0); in ad799x_read_raw()
308 if (st->vref) in ad799x_read_raw()
309 ret = regulator_get_voltage(st->vref); in ad799x_read_raw()
311 ret = regulator_get_voltage(st->reg); in ad799x_read_raw()
316 *val2 = chan->scan_type.realbits; in ad799x_read_raw()
319 return -EINVAL; in ad799x_read_raw()
338 int ret = i2c_smbus_read_byte_data(st->client, AD7998_CYCLE_TMR_REG); in ad799x_read_frequency()
361 mutex_lock(&st->lock); in ad799x_write_frequency()
363 ret = i2c_smbus_read_byte_data(st->client, AD7998_CYCLE_TMR_REG); in ad799x_write_frequency()
373 ret = -EINVAL; in ad799x_write_frequency()
377 ret = i2c_smbus_write_byte_data(st->client, AD7998_CYCLE_TMR_REG, in ad799x_write_frequency()
384 mutex_unlock(&st->lock); in ad799x_write_frequency()
396 if (!(st->config & AD7998_ALERT_EN)) in ad799x_read_event_config()
399 if ((st->config >> AD799X_CHANNEL_SHIFT) & BIT(chan->scan_index)) in ad799x_read_event_config()
418 mutex_lock(&st->lock); in ad799x_write_event_config()
421 st->config |= BIT(chan->scan_index) << AD799X_CHANNEL_SHIFT; in ad799x_write_event_config()
423 st->config &= ~(BIT(chan->scan_index) << AD799X_CHANNEL_SHIFT); in ad799x_write_event_config()
425 if (st->config >> AD799X_CHANNEL_SHIFT) in ad799x_write_event_config()
426 st->config |= AD7998_ALERT_EN; in ad799x_write_event_config()
428 st->config &= ~AD7998_ALERT_EN; in ad799x_write_event_config()
430 ret = ad799x_write_config(st, st->config); in ad799x_write_event_config()
431 mutex_unlock(&st->lock); in ad799x_write_event_config()
443 return AD7998_DATALOW_REG(chan->channel); in ad799x_threshold_reg()
445 return AD7998_DATAHIGH_REG(chan->channel); in ad799x_threshold_reg()
447 return AD7998_HYST_REG(chan->channel); in ad799x_threshold_reg()
449 return -EINVAL; in ad799x_threshold_reg()
465 if (val < 0 || val > GENMASK(chan->scan_type.realbits - 1, 0)) in ad799x_write_event_value()
466 return -EINVAL; in ad799x_write_event_value()
468 ret = i2c_smbus_write_word_swapped(st->client, in ad799x_write_event_value()
470 val << chan->scan_type.shift); in ad799x_write_event_value()
485 ret = i2c_smbus_read_word_swapped(st->client, in ad799x_read_event_value()
489 *val = (ret >> chan->scan_type.shift) & in ad799x_read_event_value()
490 GENMASK(chan->scan_type.realbits - 1, 0); in ad799x_read_event_value()
501 ret = i2c_smbus_read_byte_data(st->client, AD7998_ALERT_STAT_REG); in ad799x_event_handler()
505 if (i2c_smbus_write_byte_data(st->client, AD7998_ALERT_STAT_REG, in ad799x_event_handler()
592 .shift = 12 - (_realbits), \
788 &ad799x_chip_info_tbl[id->driver_data]; in ad799x_probe()
790 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*st)); in ad799x_probe()
792 return -ENOMEM; in ad799x_probe()
798 st->id = id->driver_data; in ad799x_probe()
799 if (client->irq > 0 && chip_info->irq_config.info) in ad799x_probe()
800 st->chip_config = &chip_info->irq_config; in ad799x_probe()
802 st->chip_config = &chip_info->noirq_config; in ad799x_probe()
806 st->reg = devm_regulator_get(&client->dev, "vcc"); in ad799x_probe()
807 if (IS_ERR(st->reg)) in ad799x_probe()
808 return PTR_ERR(st->reg); in ad799x_probe()
809 ret = regulator_enable(st->reg); in ad799x_probe()
814 st->vref = devm_regulator_get_optional(&client->dev, "vref"); in ad799x_probe()
816 if (IS_ERR(st->vref)) { in ad799x_probe()
817 if (PTR_ERR(st->vref) == -ENODEV) { in ad799x_probe()
818 st->vref = NULL; in ad799x_probe()
819 dev_info(&client->dev, "Using VCC reference voltage\n"); in ad799x_probe()
821 ret = PTR_ERR(st->vref); in ad799x_probe()
826 if (st->vref) { in ad799x_probe()
831 if ((st->id == ad7991) || (st->id == ad7995) || (st->id == ad7999)) { in ad799x_probe()
832 dev_info(&client->dev, "Using external reference voltage\n"); in ad799x_probe()
834 ret = regulator_enable(st->vref); in ad799x_probe()
838 st->vref = NULL; in ad799x_probe()
839 dev_warn(&client->dev, "Supplied reference not supported\n"); in ad799x_probe()
843 st->client = client; in ad799x_probe()
845 indio_dev->name = id->name; in ad799x_probe()
846 indio_dev->info = st->chip_config->info; in ad799x_probe()
848 indio_dev->modes = INDIO_DIRECT_MODE; in ad799x_probe()
849 indio_dev->channels = st->chip_config->channel; in ad799x_probe()
850 indio_dev->num_channels = chip_info->num_channels; in ad799x_probe()
852 ret = ad799x_update_config(st, st->chip_config->default_config | extra_config); in ad799x_probe()
861 if (client->irq > 0) { in ad799x_probe()
862 ret = devm_request_threaded_irq(&client->dev, in ad799x_probe()
863 client->irq, in ad799x_probe()
868 client->name, in ad799x_probe()
874 mutex_init(&st->lock); in ad799x_probe()
885 if (st->vref) in ad799x_probe()
886 regulator_disable(st->vref); in ad799x_probe()
888 regulator_disable(st->reg); in ad799x_probe()
901 if (st->vref) in ad799x_remove()
902 regulator_disable(st->vref); in ad799x_remove()
903 regulator_disable(st->reg); in ad799x_remove()
904 kfree(st->rx_buf); in ad799x_remove()
912 if (st->vref) in ad799x_suspend()
913 regulator_disable(st->vref); in ad799x_suspend()
914 regulator_disable(st->reg); in ad799x_suspend()
925 ret = regulator_enable(st->reg); in ad799x_resume()
931 if (st->vref) { in ad799x_resume()
932 ret = regulator_enable(st->vref); in ad799x_resume()
934 regulator_disable(st->reg); in ad799x_resume()
935 dev_err(dev, "Unable to enable vref regulator\n"); in ad799x_resume()
941 ret = ad799x_update_config(st, st->config); in ad799x_resume()
943 if (st->vref) in ad799x_resume()
944 regulator_disable(st->vref); in ad799x_resume()
945 regulator_disable(st->reg); in ad799x_resume()