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
100 * struct ad799x_chip_config - chip specific information
112 * struct ad799x_chip_info - chip specific information
127 struct regulator *vref; member
137 switch (st->id) { in ad799x_write_config()
140 return i2c_smbus_write_word_swapped(st->client, AD7998_CONF_REG, in ad799x_write_config()
145 return i2c_smbus_write_byte_data(st->client, AD7998_CONF_REG, in ad799x_write_config()
149 st->config = val; in ad799x_write_config()
156 switch (st->id) { in ad799x_read_config()
159 return i2c_smbus_read_word_swapped(st->client, AD7998_CONF_REG); in ad799x_read_config()
163 return i2c_smbus_read_byte_data(st->client, AD7998_CONF_REG); in ad799x_read_config()
166 return st->config; in ad799x_read_config()
180 st->config = ret; in ad799x_update_config()
185 static irqreturn_t ad799x_trigger_handler(int irq, void *p) in ad799x_trigger_handler() argument
187 struct iio_poll_func *pf = p; in ad799x_trigger_handler()
188 struct iio_dev *indio_dev = pf->indio_dev; in ad799x_trigger_handler()
193 switch (st->id) { in ad799x_trigger_handler()
197 cmd = st->config | in ad799x_trigger_handler()
198 (*indio_dev->active_scan_mask << AD799X_CHANNEL_SHIFT); in ad799x_trigger_handler()
203 cmd = (*indio_dev->active_scan_mask << AD799X_CHANNEL_SHIFT) | in ad799x_trigger_handler()
214 b_sent = i2c_smbus_read_i2c_block_data(st->client, in ad799x_trigger_handler()
215 cmd, st->transfer_size, st->rx_buf); in ad799x_trigger_handler()
219 iio_push_to_buffers_with_timestamp(indio_dev, st->rx_buf, in ad799x_trigger_handler()
222 iio_trigger_notify_done(indio_dev->trig); in ad799x_trigger_handler()
232 kfree(st->rx_buf); in ad799x_update_scan_mode()
233 st->rx_buf = kmalloc(indio_dev->scan_bytes, GFP_KERNEL); in ad799x_update_scan_mode()
234 if (!st->rx_buf) in ad799x_update_scan_mode()
235 return -ENOMEM; in ad799x_update_scan_mode()
237 st->transfer_size = bitmap_weight(scan_mask, indio_dev->masklength) * 2; in ad799x_update_scan_mode()
239 switch (st->id) { in ad799x_update_scan_mode()
245 st->config &= ~(GENMASK(7, 0) << AD799X_CHANNEL_SHIFT); in ad799x_update_scan_mode()
246 st->config |= (*scan_mask << AD799X_CHANNEL_SHIFT); in ad799x_update_scan_mode()
247 return ad799x_write_config(st, st->config); in ad799x_update_scan_mode()
257 switch (st->id) { in ad799x_scan_direct()
261 cmd = st->config | (BIT(ch) << AD799X_CHANNEL_SHIFT); in ad799x_scan_direct()
273 return -EINVAL; in ad799x_scan_direct()
276 return i2c_smbus_read_word_swapped(st->client, cmd); in ad799x_scan_direct()
293 ret = ad799x_scan_direct(st, chan->scan_index); in ad799x_read_raw()
298 *val = (ret >> chan->scan_type.shift) & in ad799x_read_raw()
299 GENMASK(chan->scan_type.realbits - 1, 0); in ad799x_read_raw()
302 if (st->vref) in ad799x_read_raw()
303 ret = regulator_get_voltage(st->vref); in ad799x_read_raw()
305 ret = regulator_get_voltage(st->reg); in ad799x_read_raw()
310 *val2 = chan->scan_type.realbits; in ad799x_read_raw()
313 return -EINVAL; in ad799x_read_raw()
332 int ret = i2c_smbus_read_byte_data(st->client, AD7998_CYCLE_TMR_REG); in ad799x_read_frequency()
354 mutex_lock(&indio_dev->mlock); in ad799x_write_frequency()
355 ret = i2c_smbus_read_byte_data(st->client, AD7998_CYCLE_TMR_REG); in ad799x_write_frequency()
365 ret = -EINVAL; in ad799x_write_frequency()
369 ret = i2c_smbus_write_byte_data(st->client, AD7998_CYCLE_TMR_REG, in ad799x_write_frequency()
376 mutex_unlock(&indio_dev->mlock); in ad799x_write_frequency()
388 if (!(st->config & AD7998_ALERT_EN)) in ad799x_read_event_config()
391 if ((st->config >> AD799X_CHANNEL_SHIFT) & BIT(chan->scan_index)) in ad799x_read_event_config()
411 st->config |= BIT(chan->scan_index) << AD799X_CHANNEL_SHIFT; in ad799x_write_event_config()
413 st->config &= ~(BIT(chan->scan_index) << AD799X_CHANNEL_SHIFT); in ad799x_write_event_config()
415 if (st->config >> AD799X_CHANNEL_SHIFT) in ad799x_write_event_config()
416 st->config |= AD7998_ALERT_EN; in ad799x_write_event_config()
418 st->config &= ~AD7998_ALERT_EN; in ad799x_write_event_config()
420 ret = ad799x_write_config(st, st->config); in ad799x_write_event_config()
432 return AD7998_DATALOW_REG(chan->channel); in ad799x_threshold_reg()
434 return AD7998_DATAHIGH_REG(chan->channel); in ad799x_threshold_reg()
436 return AD7998_HYST_REG(chan->channel); in ad799x_threshold_reg()
438 return -EINVAL; in ad799x_threshold_reg()
454 if (val < 0 || val > GENMASK(chan->scan_type.realbits - 1, 0)) in ad799x_write_event_value()
455 return -EINVAL; in ad799x_write_event_value()
457 mutex_lock(&indio_dev->mlock); in ad799x_write_event_value()
458 ret = i2c_smbus_write_word_swapped(st->client, in ad799x_write_event_value()
460 val << chan->scan_type.shift); in ad799x_write_event_value()
461 mutex_unlock(&indio_dev->mlock); in ad799x_write_event_value()
476 mutex_lock(&indio_dev->mlock); in ad799x_read_event_value()
477 ret = i2c_smbus_read_word_swapped(st->client, in ad799x_read_event_value()
479 mutex_unlock(&indio_dev->mlock); in ad799x_read_event_value()
482 *val = (ret >> chan->scan_type.shift) & in ad799x_read_event_value()
483 GENMASK(chan->scan_type.realbits - 1, 0); in ad799x_read_event_value()
494 ret = i2c_smbus_read_byte_data(st->client, AD7998_ALERT_STAT_REG); in ad799x_event_handler()
498 if (i2c_smbus_write_byte_data(st->client, AD7998_ALERT_STAT_REG, in ad799x_event_handler()
585 .shift = 12 - (_realbits), \
781 &ad799x_chip_info_tbl[id->driver_data]; in ad799x_probe()
783 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*st)); in ad799x_probe()
785 return -ENOMEM; in ad799x_probe()
791 st->id = id->driver_data; in ad799x_probe()
792 if (client->irq > 0 && chip_info->irq_config.info) in ad799x_probe()
793 st->chip_config = &chip_info->irq_config; in ad799x_probe()
795 st->chip_config = &chip_info->noirq_config; in ad799x_probe()
799 st->reg = devm_regulator_get(&client->dev, "vcc"); in ad799x_probe()
800 if (IS_ERR(st->reg)) in ad799x_probe()
801 return PTR_ERR(st->reg); in ad799x_probe()
802 ret = regulator_enable(st->reg); in ad799x_probe()
807 st->vref = devm_regulator_get_optional(&client->dev, "vref"); in ad799x_probe()
809 if (IS_ERR(st->vref)) { in ad799x_probe()
810 if (PTR_ERR(st->vref) == -ENODEV) { in ad799x_probe()
811 st->vref = NULL; in ad799x_probe()
812 dev_info(&client->dev, "Using VCC reference voltage\n"); in ad799x_probe()
814 ret = PTR_ERR(st->vref); in ad799x_probe()
819 if (st->vref) { in ad799x_probe()
824 if ((st->id == ad7991) || (st->id == ad7995) || (st->id == ad7999)) { in ad799x_probe()
825 dev_info(&client->dev, "Using external reference voltage\n"); in ad799x_probe()
827 ret = regulator_enable(st->vref); in ad799x_probe()
831 st->vref = NULL; in ad799x_probe()
832 dev_warn(&client->dev, "Supplied reference not supported\n"); in ad799x_probe()
836 st->client = client; in ad799x_probe()
838 indio_dev->name = id->name; in ad799x_probe()
839 indio_dev->info = st->chip_config->info; in ad799x_probe()
841 indio_dev->modes = INDIO_DIRECT_MODE; in ad799x_probe()
842 indio_dev->channels = st->chip_config->channel; in ad799x_probe()
843 indio_dev->num_channels = chip_info->num_channels; in ad799x_probe()
845 ret = ad799x_update_config(st, st->chip_config->default_config | extra_config); in ad799x_probe()
854 if (client->irq > 0) { in ad799x_probe()
855 ret = devm_request_threaded_irq(&client->dev, in ad799x_probe()
856 client->irq, in ad799x_probe()
861 client->name, in ad799x_probe()
875 if (st->vref) in ad799x_probe()
876 regulator_disable(st->vref); in ad799x_probe()
878 regulator_disable(st->reg); in ad799x_probe()
891 if (st->vref) in ad799x_remove()
892 regulator_disable(st->vref); in ad799x_remove()
893 regulator_disable(st->reg); in ad799x_remove()
894 kfree(st->rx_buf); in ad799x_remove()
902 if (st->vref) in ad799x_suspend()
903 regulator_disable(st->vref); in ad799x_suspend()
904 regulator_disable(st->reg); in ad799x_suspend()
915 ret = regulator_enable(st->reg); in ad799x_resume()
921 if (st->vref) { in ad799x_resume()
922 ret = regulator_enable(st->vref); in ad799x_resume()
924 regulator_disable(st->reg); in ad799x_resume()
925 dev_err(dev, "Unable to enable vref regulator\n"); in ad799x_resume()
931 ret = ad799x_update_config(st, st->config); in ad799x_resume()
933 if (st->vref) in ad799x_resume()
934 regulator_disable(st->vref); in ad799x_resume()
935 regulator_disable(st->reg); in ad799x_resume()