Lines Matching +full:10 +full:- +full:bits
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
131 * @bits: accuracy of the adc in bits
141 u8 bits; member
145 * struct max1363_state - driver instance specific data
247 MAX1363_MODE_SINGLE(10, 1 << 10),
255 MAX1363_MODE_DIFF_SINGLE(10, 11, 1 << 17),
261 MAX1363_MODE_DIFF_SINGLE(11, 10, 1 << 23),
277 MAX1236_MODE_SCAN_MID_TO_CHANNEL(6, 10, 0x7C0),
278 MAX1363_MODE_SCAN_TO_CHANNEL(10, 0x7FF),
287 MAX1236_MODE_DIFF_SCAN_MID_TO_CHANNEL(10, 3, 0x038000),
288 MAX1363_MODE_DIFF_SCAN_TO_CHANNEL(10, 6, 0x3F000),
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()
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()
459 #define MAX1363_CHAN_U(num, addr, si, bits, ev_spec, num_ev_spec) \ argument
470 .realbits = bits, \
471 .storagebits = (bits > 8) ? 16 : 8, \
480 #define MAX1363_CHAN_B(num, num2, addr, si, bits, ev_spec, num_ev_spec) \ argument
490 .datasheet_name = "AIN"#num"-AIN"#num2, \
493 .realbits = bits, \
494 .storagebits = (bits > 8) ? 16 : 8, \
502 #define MAX1363_4X_CHANS(bits, ev_spec, num_ev_spec) { \ argument
503 MAX1363_CHAN_U(0, _s0, 0, bits, ev_spec, num_ev_spec), \
504 MAX1363_CHAN_U(1, _s1, 1, bits, ev_spec, num_ev_spec), \
505 MAX1363_CHAN_U(2, _s2, 2, bits, ev_spec, num_ev_spec), \
506 MAX1363_CHAN_U(3, _s3, 3, bits, ev_spec, num_ev_spec), \
507 MAX1363_CHAN_B(0, 1, d0m1, 4, bits, ev_spec, num_ev_spec), \
508 MAX1363_CHAN_B(2, 3, d2m3, 5, bits, ev_spec, num_ev_spec), \
509 MAX1363_CHAN_B(1, 0, d1m0, 6, bits, ev_spec, num_ev_spec), \
510 MAX1363_CHAN_B(3, 2, d3m2, 7, bits, ev_spec, num_ev_spec), \
517 MAX1363_4X_CHANS(10, NULL, 0);
521 MAX1363_4X_CHANS(10, max1363_events, ARRAY_SIZE(max1363_events));
547 #define MAX1363_12X_CHANS(bits) { \ argument
548 MAX1363_CHAN_U(0, _s0, 0, bits, NULL, 0), \
549 MAX1363_CHAN_U(1, _s1, 1, bits, NULL, 0), \
550 MAX1363_CHAN_U(2, _s2, 2, bits, NULL, 0), \
551 MAX1363_CHAN_U(3, _s3, 3, bits, NULL, 0), \
552 MAX1363_CHAN_U(4, _s4, 4, bits, NULL, 0), \
553 MAX1363_CHAN_U(5, _s5, 5, bits, NULL, 0), \
554 MAX1363_CHAN_U(6, _s6, 6, bits, NULL, 0), \
555 MAX1363_CHAN_U(7, _s7, 7, bits, NULL, 0), \
556 MAX1363_CHAN_U(8, _s8, 8, bits, NULL, 0), \
557 MAX1363_CHAN_U(9, _s9, 9, bits, NULL, 0), \
558 MAX1363_CHAN_U(10, _s10, 10, bits, NULL, 0), \
559 MAX1363_CHAN_U(11, _s11, 11, bits, NULL, 0), \
560 MAX1363_CHAN_B(0, 1, d0m1, 12, bits, NULL, 0), \
561 MAX1363_CHAN_B(2, 3, d2m3, 13, bits, NULL, 0), \
562 MAX1363_CHAN_B(4, 5, d4m5, 14, bits, NULL, 0), \
563 MAX1363_CHAN_B(6, 7, d6m7, 15, bits, NULL, 0), \
564 MAX1363_CHAN_B(8, 9, d8m9, 16, bits, NULL, 0), \
565 MAX1363_CHAN_B(10, 11, d10m11, 17, bits, NULL, 0), \
566 MAX1363_CHAN_B(1, 0, d1m0, 18, bits, NULL, 0), \
567 MAX1363_CHAN_B(3, 2, d3m2, 19, bits, NULL, 0), \
568 MAX1363_CHAN_B(5, 4, d5m4, 20, bits, NULL, 0), \
569 MAX1363_CHAN_B(7, 6, d7m6, 21, bits, NULL, 0), \
570 MAX1363_CHAN_B(9, 8, d9m8, 22, bits, NULL, 0), \
571 MAX1363_CHAN_B(11, 10, d11m10, 23, bits, NULL, 0), \
575 static const struct iio_chan_spec max1138_channels[] = MAX1363_12X_CHANS(10);
596 #define MAX1363_8X_CHANS(bits) { \ argument
597 MAX1363_CHAN_U(0, _s0, 0, bits, NULL, 0), \
598 MAX1363_CHAN_U(1, _s1, 1, bits, NULL, 0), \
599 MAX1363_CHAN_U(2, _s2, 2, bits, NULL, 0), \
600 MAX1363_CHAN_U(3, _s3, 3, bits, NULL, 0), \
601 MAX1363_CHAN_U(4, _s4, 4, bits, NULL, 0), \
602 MAX1363_CHAN_U(5, _s5, 5, bits, NULL, 0), \
603 MAX1363_CHAN_U(6, _s6, 6, bits, NULL, 0), \
604 MAX1363_CHAN_U(7, _s7, 7, bits, NULL, 0), \
605 MAX1363_CHAN_B(0, 1, d0m1, 8, bits, NULL, 0), \
606 MAX1363_CHAN_B(2, 3, d2m3, 9, bits, NULL, 0), \
607 MAX1363_CHAN_B(4, 5, d4m5, 10, bits, NULL, 0), \
608 MAX1363_CHAN_B(6, 7, d6m7, 11, bits, NULL, 0), \
609 MAX1363_CHAN_B(1, 0, d1m0, 12, bits, NULL, 0), \
610 MAX1363_CHAN_B(3, 2, d3m2, 13, bits, NULL, 0), \
611 MAX1363_CHAN_B(5, 4, d5m4, 14, bits, NULL, 0), \
612 MAX1363_CHAN_B(7, 6, d7m6, 15, bits, NULL, 0), \
616 static const struct iio_chan_spec max11608_channels[] = MAX1363_8X_CHANS(10);
623 #define MAX1363_2X_CHANS(bits) { \ argument
624 MAX1363_CHAN_U(0, _s0, 0, bits, NULL, 0), \
625 MAX1363_CHAN_U(1, _s1, 1, bits, NULL, 0), \
626 MAX1363_CHAN_B(0, 1, d0m1, 2, bits, NULL, 0), \
627 MAX1363_CHAN_B(1, 0, d1m0, 3, bits, NULL, 0), \
631 static const struct iio_chan_spec max11646_channels[] = MAX1363_2X_CHANS(10);
682 return sprintf(buf, "%d\n", max1363_monitor_speeds[st->monitor_speed]); in max1363_monitor_show_freq()
696 ret = kstrtoul(buf, 10, &val); in max1363_monitor_store_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()
741 case 10: 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()
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 */
1034 .bits = 10,
1044 .bits = 10,
1054 .bits = 12,
1064 .bits = 12,
1074 .bits = 8,
1084 .bits = 8,
1094 .bits = 8,
1104 .bits = 8,
1114 .bits = 10,
1124 .bits = 10,
1134 .bits = 10,
1144 .bits = 10,
1154 .bits = 12,
1164 .bits = 12,
1174 .bits = 12,
1184 .bits = 12,
1194 .bits = 8,
1204 .bits = 8,
1214 .bits = 8,
1224 .bits = 8,
1234 .bits = 8,
1244 .bits = 8,
1254 .bits = 10,
1264 .bits = 10,
1274 .bits = 10,
1284 .bits = 10,
1294 .bits = 10,
1304 .bits = 10,
1314 .bits = 12,
1324 .bits = 12,
1334 .bits = 12,
1344 .bits = 12,
1354 .bits = 12,
1364 .bits = 12,
1374 .bits = 12,
1384 .bits = 12,
1394 .bits = 10,
1404 .bits = 10,
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()