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

1 // SPDX-License-Identifier: GPL-2.0-only
4 * Copyright (C) 2008-2010 Jonathan Cameron
7 * Copyright (C) 2002-2004 Stefan Eletzhofer
51 /* think about including max11600 etc - more settings */
58 /* max1363 only - though don't care on others.
79 /* max123{6-9} only */
82 /* max1363 only - merely part of channel selects or don't care for others */
87 /* max1363 strictly 0x06 - but doesn't matter */
94 * struct max1363_mode - scan mode information
122 * struct max1363_chip_info - chip specifc information
144 * struct max1363_state - driver instance specific data
159 * @vref: Reference voltage regulator
183 struct regulator *vref; member
305 for (i = 0; i < ci->num_modes; i++) in max1363_match_mode()
307 max1363_mode_table[ci->mode_list[i]]. in max1363_match_mode()
310 return &max1363_mode_table[ci->mode_list[i]]; in max1363_match_mode()
342 u8 tx_buf[2] = { st->setupbyte, st->configbyte }; in max1363_write_basic_config()
344 return st->send(st->client, tx_buf, 2); in max1363_write_basic_config()
349 st->configbyte &= ~(MAX1363_CHANNEL_SEL_MASK in max1363_set_scan_mode()
352 st->configbyte |= st->current_mode->conf; in max1363_set_scan_mode()
366 struct i2c_client *client = st->client; in max1363_read_single_chan()
371 mutex_lock(&st->lock); in max1363_read_single_chan()
380 if (st->monitor_on) { in max1363_read_single_chan()
381 ret = -EBUSY; in max1363_read_single_chan()
386 if (st->current_mode != &max1363_mode_table[chan->address]) { in max1363_read_single_chan()
388 st->current_mode = &max1363_mode_table[chan->address]; in max1363_read_single_chan()
393 if (st->chip_info->bits != 8) { in max1363_read_single_chan()
395 data = st->recv(client, rxbuf, 2); in max1363_read_single_chan()
401 ((1 << st->chip_info->bits) - 1); in max1363_read_single_chan()
404 data = st->recv(client, rxbuf, 1); in max1363_read_single_chan()
414 mutex_unlock(&st->lock); in max1363_read_single_chan()
436 *val = st->vref_uv / 1000; in max1363_read_raw()
437 *val2 = st->chip_info->bits; in max1363_read_raw()
440 return -EINVAL; in max1363_read_raw()
498 .datasheet_name = "AIN"#num"-AIN"#num2, \
690 return sprintf(buf, "%d\n", max1363_monitor_speeds[st->monitor_speed]); in max1363_monitor_show_freq()
706 return -EINVAL; in max1363_monitor_store_freq()
713 return -EINVAL; in max1363_monitor_store_freq()
715 mutex_lock(&st->lock); in max1363_monitor_store_freq()
716 st->monitor_speed = i; in max1363_monitor_store_freq()
717 mutex_unlock(&st->lock); in max1363_monitor_store_freq()
736 *val = st->thresh_low[chan->channel]; in max1363_read_thresh()
738 *val = st->thresh_high[chan->channel]; in max1363_read_thresh()
749 switch (st->chip_info->bits) { in max1363_write_thresh()
752 return -EINVAL; in max1363_write_thresh()
756 return -EINVAL; in max1363_write_thresh()
762 st->thresh_low[chan->channel] = val; in max1363_write_thresh()
765 st->thresh_high[chan->channel] = val; in max1363_write_thresh()
768 return -EINVAL; in max1363_write_thresh()
800 u8 tx[2] = { st->setupbyte, in max1363_event_handler()
801 MAX1363_MON_INT_ENABLE | (st->monitor_speed << 1) | 0xF0 }; in max1363_event_handler()
803 st->recv(st->client, &rx, 1); in max1363_event_handler()
807 st->send(st->client, tx, 2); in max1363_event_handler()
818 int number = chan->channel; in max1363_read_event_config()
820 mutex_lock(&st->lock); in max1363_read_event_config()
822 val = (1 << number) & st->mask_low; in max1363_read_event_config()
824 val = (1 << number) & st->mask_high; in max1363_read_event_config()
825 mutex_unlock(&st->lock); in max1363_read_event_config()
840 st->setupbyte &= ~MAX1363_SETUP_MONITOR_SETUP; in max1363_monitor_mode_update()
841 st->configbyte &= ~MAX1363_SCAN_MASK; in max1363_monitor_mode_update()
842 st->monitor_on = false; in max1363_monitor_mode_update()
847 st->setupbyte |= MAX1363_SETUP_MONITOR_SETUP; in max1363_monitor_mode_update()
848 st->configbyte &= ~(MAX1363_CHANNEL_SEL_MASK in max1363_monitor_mode_update()
851 st->configbyte |= MAX1363_CONFIG_SCAN_MONITOR_MODE; in max1363_monitor_mode_update()
852 if ((st->mask_low | st->mask_high) & 0x0F) { in max1363_monitor_mode_update()
853 st->configbyte |= max1363_mode_table[s0to3].conf; in max1363_monitor_mode_update()
855 } else if ((st->mask_low | st->mask_high) & 0x30) { in max1363_monitor_mode_update()
856 st->configbyte |= max1363_mode_table[d0m1to2m3].conf; in max1363_monitor_mode_update()
859 st->configbyte |= max1363_mode_table[d1m0to3m2].conf; in max1363_monitor_mode_update()
866 ret = -ENOMEM; in max1363_monitor_mode_update()
869 tx_buf[0] = st->configbyte; in max1363_monitor_mode_update()
870 tx_buf[1] = st->setupbyte; in max1363_monitor_mode_update()
871 tx_buf[2] = (st->monitor_speed << 1); in max1363_monitor_mode_update()
880 if (st->mask_low & (1 << j)) { in max1363_monitor_mode_update()
881 tx_buf[i] = (st->thresh_low[j] >> 4) & 0xFF; in max1363_monitor_mode_update()
882 tx_buf[i + 1] = (st->thresh_low[j] << 4) & 0xF0; in max1363_monitor_mode_update()
890 if (st->mask_high & (1 << j)) { in max1363_monitor_mode_update()
892 (st->thresh_high[j] >> 8) & 0x0F; in max1363_monitor_mode_update()
893 tx_buf[i + 2] = st->thresh_high[j] & 0xFF; in max1363_monitor_mode_update()
905 ret = st->send(st->client, tx_buf, len); in max1363_monitor_mode_update()
909 ret = -EIO; in max1363_monitor_mode_update()
920 tx_buf[0] = st->setupbyte; in max1363_monitor_mode_update()
921 tx_buf[1] = MAX1363_MON_INT_ENABLE | (st->monitor_speed << 1) | 0xF0; in max1363_monitor_mode_update()
922 ret = st->send(st->client, tx_buf, 2); in max1363_monitor_mode_update()
926 ret = -EIO; in max1363_monitor_mode_update()
930 st->monitor_on = true; in max1363_monitor_mode_update()
940 * Scan 0...3, 0-1,2-3 and 1-0,3-2
949 ret = -EBUSY; in __max1363_check_event_mask()
954 ret = -EBUSY; in __max1363_check_event_mask()
958 ret = -EBUSY; in __max1363_check_event_mask()
970 int number = chan->channel; in max1363_write_event_config()
975 mutex_lock(&st->lock); in max1363_write_event_config()
977 unifiedmask = st->mask_low | st->mask_high; in max1363_write_event_config()
981 st->mask_low &= ~(1 << number); in max1363_write_event_config()
987 st->mask_low |= (1 << number); in max1363_write_event_config()
991 st->mask_high &= ~(1 << number); in max1363_write_event_config()
997 st->mask_high |= (1 << number); in max1363_write_event_config()
1001 max1363_monitor_mode_update(st, !!(st->mask_high | st->mask_low)); in max1363_write_event_config()
1003 mutex_unlock(&st->lock); in max1363_write_event_config()
1032 st->current_mode = max1363_match_mode(scan_mask, st->chip_info); in max1363_update_scan_mode()
1033 if (!st->current_mode) in max1363_update_scan_mode()
1034 return -EINVAL; in max1363_update_scan_mode()
1054 /* max1363 and max1368 tested - rest from data sheet */
1440 st->setupbyte = MAX1363_SETUP_INT_CLOCK in max1363_initial_setup()
1444 if (st->vref) in max1363_initial_setup()
1445 st->setupbyte |= MAX1363_SETUP_AIN3_IS_REF_EXT_TO_REF; in max1363_initial_setup()
1447 st->setupbyte |= MAX1363_SETUP_POWER_UP_INT_REF in max1363_initial_setup()
1451 st->setupbyte = MAX1363_SETUP_BYTE(st->setupbyte); in max1363_initial_setup()
1452 st->current_mode = &max1363_mode_table[st->chip_info->default_mode]; in max1363_initial_setup()
1453 st->configbyte = MAX1363_CONFIG_BYTE(st->configbyte); in max1363_initial_setup()
1464 masks = devm_kzalloc(&indio_dev->dev, in max1363_alloc_scan_masks()
1467 st->chip_info->num_modes + 1), in max1363_alloc_scan_masks()
1470 return -ENOMEM; in max1363_alloc_scan_masks()
1472 for (i = 0; i < st->chip_info->num_modes; i++) in max1363_alloc_scan_masks()
1474 max1363_mode_table[st->chip_info->mode_list[i]] in max1363_alloc_scan_masks()
1477 indio_dev->available_scan_masks = masks; in max1363_alloc_scan_masks()
1482 static irqreturn_t max1363_trigger_handler(int irq, void *p) in max1363_trigger_handler() argument
1484 struct iio_poll_func *pf = p; in max1363_trigger_handler()
1485 struct iio_dev *indio_dev = pf->indio_dev; in max1363_trigger_handler()
1490 unsigned long numvals = bitmap_weight(st->current_mode->modemask, in max1363_trigger_handler()
1494 if (st->chip_info->bits != 8) in max1363_trigger_handler()
1498 if (indio_dev->scan_timestamp) { in max1363_trigger_handler()
1501 d_size += sizeof(s64) - (d_size % sizeof(s64)); in max1363_trigger_handler()
1513 if (st->chip_info->bits != 8) in max1363_trigger_handler()
1514 b_sent = st->recv(st->client, rxbuf, numvals * 2); in max1363_trigger_handler()
1516 b_sent = st->recv(st->client, rxbuf, numvals); in max1363_trigger_handler()
1526 iio_trigger_notify_done(indio_dev->trig); in max1363_trigger_handler()
1590 struct regulator *vref; in max1363_probe() local
1592 indio_dev = devm_iio_device_alloc(&client->dev, in max1363_probe()
1595 return -ENOMEM; in max1363_probe()
1599 mutex_init(&st->lock); in max1363_probe()
1600 st->reg = devm_regulator_get(&client->dev, "vcc"); in max1363_probe()
1601 if (IS_ERR(st->reg)) in max1363_probe()
1602 return PTR_ERR(st->reg); in max1363_probe()
1604 ret = regulator_enable(st->reg); in max1363_probe()
1608 ret = devm_add_action_or_reset(&client->dev, max1363_reg_disable, st->reg); in max1363_probe()
1612 st->chip_info = device_get_match_data(&client->dev); in max1363_probe()
1613 if (!st->chip_info) in max1363_probe()
1614 st->chip_info = &max1363_chip_info_tbl[id->driver_data]; in max1363_probe()
1615 st->client = client; in max1363_probe()
1617 st->vref_uv = st->chip_info->int_vref_mv * 1000; in max1363_probe()
1618 vref = devm_regulator_get_optional(&client->dev, "vref"); in max1363_probe()
1619 if (!IS_ERR(vref)) { in max1363_probe()
1622 ret = regulator_enable(vref); in max1363_probe()
1626 ret = devm_add_action_or_reset(&client->dev, max1363_reg_disable, vref); in max1363_probe()
1630 st->vref = vref; in max1363_probe()
1631 vref_uv = regulator_get_voltage(vref); in max1363_probe()
1633 return -EINVAL; in max1363_probe()
1635 st->vref_uv = vref_uv; in max1363_probe()
1638 if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { in max1363_probe()
1639 st->send = i2c_master_send; in max1363_probe()
1640 st->recv = i2c_master_recv; in max1363_probe()
1641 } else if (i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE) in max1363_probe()
1642 && st->chip_info->bits == 8) { in max1363_probe()
1643 st->send = max1363_smbus_send; in max1363_probe()
1644 st->recv = max1363_smbus_recv; in max1363_probe()
1646 return -EOPNOTSUPP; in max1363_probe()
1653 indio_dev->name = id->name; in max1363_probe()
1654 indio_dev->channels = st->chip_info->channels; in max1363_probe()
1655 indio_dev->num_channels = st->chip_info->num_channels; in max1363_probe()
1656 indio_dev->info = st->chip_info->info; in max1363_probe()
1657 indio_dev->modes = INDIO_DIRECT_MODE; in max1363_probe()
1662 ret = devm_iio_triggered_buffer_setup(&client->dev, indio_dev, NULL, in max1363_probe()
1667 if (client->irq) { in max1363_probe()
1668 ret = devm_request_threaded_irq(&client->dev, st->client->irq, in max1363_probe()
1679 return devm_iio_device_register(&client->dev, indio_dev); in max1363_probe()