Lines Matching +full:vref +full:- +full:buffered
1 // SPDX-License-Identifier: GPL-2.0-only
4 * Copyright (C) 2008-2010 Jonathan Cameron
7 * Copyright (C) 2002-2004 Stefan Eletzhofer
52 /* think about including max11600 etc - more settings */
59 /* max1363 only - though don't care on others.
80 /* max123{6-9} only */
83 /* max1363 only - merely part of channel selects or don't care for others */
88 /* max1363 strictly 0x06 - but doesn't matter */
95 * struct max1363_mode - scan mode information
123 * struct max1363_chip_info - chip specifc information
145 * struct max1363_state - driver instance specific data
159 * @vref: Reference voltage regulator
182 struct regulator *vref; member
304 for (i = 0; i < ci->num_modes; i++) in max1363_match_mode()
306 max1363_mode_table[ci->mode_list[i]]. in max1363_match_mode()
309 return &max1363_mode_table[ci->mode_list[i]]; in max1363_match_mode()
341 u8 tx_buf[2] = { st->setupbyte, st->configbyte }; in max1363_write_basic_config()
343 return st->send(st->client, tx_buf, 2); in max1363_write_basic_config()
348 st->configbyte &= ~(MAX1363_CHANNEL_SEL_MASK in max1363_set_scan_mode()
351 st->configbyte |= st->current_mode->conf; in max1363_set_scan_mode()
361 iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { in max1363_read_single_chan()
365 struct i2c_client *client = st->client; in max1363_read_single_chan()
367 guard(mutex)(&st->lock); in max1363_read_single_chan()
374 * Also, cannot read directly if buffered capture enabled. in max1363_read_single_chan()
376 if (st->monitor_on) in max1363_read_single_chan()
377 return -EBUSY; in max1363_read_single_chan()
380 if (st->current_mode != &max1363_mode_table[chan->address]) { in max1363_read_single_chan()
384 st->current_mode = &max1363_mode_table[chan->address]; in max1363_read_single_chan()
389 if (st->chip_info->bits != 8) { in max1363_read_single_chan()
391 data = st->recv(client, rxbuf, 2); in max1363_read_single_chan()
396 ((1 << st->chip_info->bits) - 1); in max1363_read_single_chan()
399 data = st->recv(client, rxbuf, 1); in max1363_read_single_chan()
428 *val = st->vref_uv / 1000; in max1363_read_raw()
429 *val2 = st->chip_info->bits; in max1363_read_raw()
432 return -EINVAL; in max1363_read_raw()
490 .datasheet_name = "AIN"#num"-AIN"#num2, \
682 return sprintf(buf, "%d\n", max1363_monitor_speeds[st->monitor_speed]); in max1363_monitor_show_freq()
698 return -EINVAL; in max1363_monitor_store_freq()
705 return -EINVAL; in max1363_monitor_store_freq()
707 scoped_guard(mutex, &st->lock) in max1363_monitor_store_freq()
708 st->monitor_speed = i; in max1363_monitor_store_freq()
727 *val = st->thresh_low[chan->channel]; in max1363_read_thresh()
729 *val = st->thresh_high[chan->channel]; in max1363_read_thresh()
740 switch (st->chip_info->bits) { in max1363_write_thresh()
743 return -EINVAL; in max1363_write_thresh()
747 return -EINVAL; in max1363_write_thresh()
753 st->thresh_low[chan->channel] = val; in max1363_write_thresh()
756 st->thresh_high[chan->channel] = val; in max1363_write_thresh()
759 return -EINVAL; in max1363_write_thresh()
791 u8 tx[2] = { st->setupbyte, in max1363_event_handler()
792 MAX1363_MON_INT_ENABLE | (st->monitor_speed << 1) | 0xF0 }; in max1363_event_handler()
794 st->recv(st->client, &rx, 1); in max1363_event_handler()
798 st->send(st->client, tx, 2); in max1363_event_handler()
809 int number = chan->channel; in max1363_read_event_config()
811 guard(mutex)(&st->lock); in max1363_read_event_config()
813 val = (1 << number) & st->mask_low; in max1363_read_event_config()
815 val = (1 << number) & st->mask_high; in max1363_read_event_config()
828 /* transition to buffered capture is not currently supported */ in max1363_monitor_mode_update()
829 st->setupbyte &= ~MAX1363_SETUP_MONITOR_SETUP; in max1363_monitor_mode_update()
830 st->configbyte &= ~MAX1363_SCAN_MASK; in max1363_monitor_mode_update()
831 st->monitor_on = false; in max1363_monitor_mode_update()
836 st->setupbyte |= MAX1363_SETUP_MONITOR_SETUP; in max1363_monitor_mode_update()
837 st->configbyte &= ~(MAX1363_CHANNEL_SEL_MASK in max1363_monitor_mode_update()
840 st->configbyte |= MAX1363_CONFIG_SCAN_MONITOR_MODE; in max1363_monitor_mode_update()
841 if ((st->mask_low | st->mask_high) & 0x0F) { in max1363_monitor_mode_update()
842 st->configbyte |= max1363_mode_table[s0to3].conf; in max1363_monitor_mode_update()
844 } else if ((st->mask_low | st->mask_high) & 0x30) { in max1363_monitor_mode_update()
845 st->configbyte |= max1363_mode_table[d0m1to2m3].conf; in max1363_monitor_mode_update()
848 st->configbyte |= max1363_mode_table[d1m0to3m2].conf; in max1363_monitor_mode_update()
855 return -ENOMEM; in max1363_monitor_mode_update()
857 tx_buf[0] = st->configbyte; in max1363_monitor_mode_update()
858 tx_buf[1] = st->setupbyte; in max1363_monitor_mode_update()
859 tx_buf[2] = (st->monitor_speed << 1); in max1363_monitor_mode_update()
868 if (st->mask_low & (1 << j)) { in max1363_monitor_mode_update()
869 tx_buf[i] = (st->thresh_low[j] >> 4) & 0xFF; in max1363_monitor_mode_update()
870 tx_buf[i + 1] = (st->thresh_low[j] << 4) & 0xF0; in max1363_monitor_mode_update()
878 if (st->mask_high & (1 << j)) { in max1363_monitor_mode_update()
880 (st->thresh_high[j] >> 8) & 0x0F; in max1363_monitor_mode_update()
881 tx_buf[i + 2] = st->thresh_high[j] & 0xFF; in max1363_monitor_mode_update()
893 ret = st->send(st->client, tx_buf, len); in max1363_monitor_mode_update()
897 return -EIO; in max1363_monitor_mode_update()
906 tx_buf[0] = st->setupbyte; in max1363_monitor_mode_update()
907 tx_buf[1] = MAX1363_MON_INT_ENABLE | (st->monitor_speed << 1) | 0xF0; in max1363_monitor_mode_update()
908 ret = st->send(st->client, tx_buf, 2); in max1363_monitor_mode_update()
912 return -EIO; in max1363_monitor_mode_update()
914 st->monitor_on = true; in max1363_monitor_mode_update()
921 * Scan 0...3, 0-1,2-3 and 1-0,3-2
930 ret = -EBUSY; in __max1363_check_event_mask()
935 ret = -EBUSY; in __max1363_check_event_mask()
939 ret = -EBUSY; in __max1363_check_event_mask()
950 iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { in max1363_write_event_config()
951 int number = chan->channel; in max1363_write_event_config()
955 guard(mutex)(&st->lock); in max1363_write_event_config()
957 unifiedmask = st->mask_low | st->mask_high; in max1363_write_event_config()
961 st->mask_low &= ~(1 << number); in max1363_write_event_config()
967 st->mask_low |= (1 << number); in max1363_write_event_config()
971 st->mask_high &= ~(1 << number); in max1363_write_event_config()
977 st->mask_high |= (1 << number); in max1363_write_event_config()
981 max1363_monitor_mode_update(st, !!(st->mask_high | st->mask_low)); in max1363_write_event_config()
1009 st->current_mode = max1363_match_mode(scan_mask, st->chip_info); in max1363_update_scan_mode()
1010 if (!st->current_mode) in max1363_update_scan_mode()
1011 return -EINVAL; in max1363_update_scan_mode()
1031 /* max1363 and max1368 tested - rest from data sheet */
1417 st->setupbyte = MAX1363_SETUP_INT_CLOCK in max1363_initial_setup()
1421 if (st->vref) in max1363_initial_setup()
1422 st->setupbyte |= MAX1363_SETUP_AIN3_IS_REF_EXT_TO_REF; in max1363_initial_setup()
1424 st->setupbyte |= MAX1363_SETUP_POWER_UP_INT_REF in max1363_initial_setup()
1428 st->setupbyte = MAX1363_SETUP_BYTE(st->setupbyte); in max1363_initial_setup()
1429 st->current_mode = &max1363_mode_table[st->chip_info->default_mode]; in max1363_initial_setup()
1430 st->configbyte = MAX1363_CONFIG_BYTE(st->configbyte); in max1363_initial_setup()
1441 masks = devm_kzalloc(&indio_dev->dev, in max1363_alloc_scan_masks()
1444 st->chip_info->num_modes + 1), in max1363_alloc_scan_masks()
1447 return -ENOMEM; in max1363_alloc_scan_masks()
1449 for (i = 0; i < st->chip_info->num_modes; i++) in max1363_alloc_scan_masks()
1451 max1363_mode_table[st->chip_info->mode_list[i]] in max1363_alloc_scan_masks()
1454 indio_dev->available_scan_masks = masks; in max1363_alloc_scan_masks()
1462 struct iio_dev *indio_dev = pf->indio_dev; in max1363_trigger_handler()
1467 unsigned long numvals = bitmap_weight(st->current_mode->modemask, in max1363_trigger_handler()
1471 if (st->chip_info->bits != 8) in max1363_trigger_handler()
1475 if (indio_dev->scan_timestamp) { in max1363_trigger_handler()
1478 d_size += sizeof(s64) - (d_size % sizeof(s64)); in max1363_trigger_handler()
1490 if (st->chip_info->bits != 8) in max1363_trigger_handler()
1491 b_sent = st->recv(st->client, rxbuf, numvals * 2); in max1363_trigger_handler()
1493 b_sent = st->recv(st->client, rxbuf, numvals); in max1363_trigger_handler()
1503 iio_trigger_notify_done(indio_dev->trig); in max1363_trigger_handler()
1563 indio_dev = devm_iio_device_alloc(&client->dev, in max1363_probe()
1566 return -ENOMEM; in max1363_probe()
1570 mutex_init(&st->lock); in max1363_probe()
1571 ret = devm_regulator_get_enable(&client->dev, "vcc"); in max1363_probe()
1575 st->chip_info = i2c_get_match_data(client); in max1363_probe()
1576 st->client = client; in max1363_probe()
1578 ret = devm_regulator_get_enable_read_voltage(&client->dev, "vref"); in max1363_probe()
1579 if (ret < 0 && ret != -ENODEV) in max1363_probe()
1583 st->vref_uv = ret == -ENODEV ? st->chip_info->int_vref_mv * 1000 : ret; in max1363_probe()
1585 if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { in max1363_probe()
1586 st->send = i2c_master_send; in max1363_probe()
1587 st->recv = i2c_master_recv; in max1363_probe()
1588 } else if (i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE) in max1363_probe()
1589 && st->chip_info->bits == 8) { in max1363_probe()
1590 st->send = max1363_smbus_send; in max1363_probe()
1591 st->recv = max1363_smbus_recv; in max1363_probe()
1593 return -EOPNOTSUPP; in max1363_probe()
1600 indio_dev->name = id->name; in max1363_probe()
1601 indio_dev->channels = st->chip_info->channels; in max1363_probe()
1602 indio_dev->num_channels = st->chip_info->num_channels; in max1363_probe()
1603 indio_dev->info = st->chip_info->info; in max1363_probe()
1604 indio_dev->modes = INDIO_DIRECT_MODE; in max1363_probe()
1609 ret = devm_iio_triggered_buffer_setup(&client->dev, indio_dev, NULL, in max1363_probe()
1614 if (client->irq) { in max1363_probe()
1615 ret = devm_request_threaded_irq(&client->dev, st->client->irq, in max1363_probe()
1626 return devm_iio_device_register(&client->dev, indio_dev); in max1363_probe()