Lines Matching +full:count +full:- +full:width

1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
4 * Copyright (C) 2008-2009 Semihalf, Michal Hajduk and Bartlomiej Sieka
53 const char *width; member
54 unsigned count; member
75 fprintf(stderr, "usage: %s -a addr [-f device] [-d [r|w]] [-o offset] " in usage()
76 "[-w [0|8|16|16LE|16BE]] [-c count] [-m [tr|ss|rs|no]] [-b] [-v]\n", in usage()
78 fprintf(stderr, " %s -s [-f device] [-n skip_addr] -v\n", in usage()
80 fprintf(stderr, " %s -r [-f device] -v\n", getprogname()); in usage()
168 usage("Bad -n argument, expected (first) hex-digit"); in parse_skip()
171 usage("Bad -n argument, expected (second) hex-digit"); in parse_skip()
174 usage("Bad -n argument, (01..7f)"); in parse_skip()
181 if (*p == '-') { in parse_skip()
186 usage("Bad -n argument, ([:|,|..|-])"); in parse_skip()
191 usage("Bad -n argument, expected (first) hex-digit"); in parse_skip()
194 usage("Bad -n argument, expected (second) hex-digit"); in parse_skip()
197 usage("Bad -n argument, (01..7f)"); in parse_skip()
199 usage("Bad -n argument, (end < start)"); in parse_skip()
232 cmd.count = 0; in scan_bus()
265 "trying less-reliable read method.\n"); in scan_bus()
285 encode_offset(const char *width, unsigned offset, uint8_t *dst, size_t *len) in encode_offset() argument
288 if (!strcmp(width, "0")) { in encode_offset()
292 if (!strcmp(width, "8")) { in encode_offset()
294 return ("Invalid 8-bit offset\n"); in encode_offset()
300 return ("Invalid 16-bit offset\n"); in encode_offset()
301 if (!strcmp(width, "16LE") || !strcmp(width, "16")) { in encode_offset()
306 if (!strcmp(width, "16BE")) { in encode_offset()
311 return ("Invalid offset width, must be: 0|8|16|16LE|16BE\n"); in encode_offset()
319 cmd->count = i2c_opt.off_len; in write_offset()
320 cmd->buf = (void*)i2c_opt.off_buf; in write_offset()
330 char buf[i2c_opt.off_len + i2c_opt.count]; in i2c_write()
352 cmd.count = i2c_opt.count; in i2c_write()
369 cmd.count = i2c_opt.count; in i2c_write()
379 memcpy(buf + i2c_opt.off_len, i2c_buf, i2c_opt.count); in i2c_write()
383 cmd.count = i2c_opt.off_len + i2c_opt.count; in i2c_write()
404 cmd.count = 1; in i2c_read()
417 cmd.count = 1; in i2c_read()
428 cmd.count = i2c_opt.count; in i2c_read()
438 * i2c_rdwr_transfer() - use I2CRDWR to conduct a complete i2c transfer.
440 * Some i2c hardware is unable to provide direct control over START, REPEAT-
442 * START-<data>-STOP or START-<data>-REPEAT-START-<data>-STOP sequence as a
456 msgp->flags = IIC_M_WR | IIC_M_NOSTOP; in i2c_rdwr_transfer()
457 msgp->slave = i2c_opt.addr; in i2c_rdwr_transfer()
458 msgp->buf = i2c_opt.off_buf; in i2c_rdwr_transfer()
459 msgp->len = i2c_opt.off_len; in i2c_rdwr_transfer()
468 * a start; if we did an offset write above it'll be a repeat-start in i2c_rdwr_transfer()
472 msgp->flags = IIC_M_WR | flag; in i2c_rdwr_transfer()
474 msgp->flags = IIC_M_RD; in i2c_rdwr_transfer()
475 msgp->slave = i2c_opt.addr; in i2c_rdwr_transfer()
476 msgp->len = i2c_opt.count; in i2c_rdwr_transfer()
477 msgp->buf = i2c_buf; in i2c_rdwr_transfer()
481 xfer.nmsgs = msgp - msgs; in i2c_rdwr_transfer()
483 if (ioctl(fd, I2CRDWR, &xfer) == -1 ) in i2c_rdwr_transfer()
492 uint8_t i2c_buf[i2c_opt.count]; in access_bus()
502 i2c_opt.count); in access_bus()
503 if (fread(i2c_buf, 1, i2c_opt.count, stdin) != i2c_opt.count) in access_bus()
516 (void)fwrite(i2c_buf, 1, i2c_opt.count, stdout); in access_bus()
522 for (u = 0; u < i2c_opt.count; u++) { in access_bus()
524 if ((u % chunk_size) == chunk_size - 1) in access_bus()
551 const char *width = NULL; in command_bus() local
582 return(-1); in command_bus()
589 return(-1); in command_bus()
595 return(-1); in command_bus()
599 return(-1); in command_bus()
612 width = widths[u]; in command_bus()
616 if (width == NULL) { in command_bus()
617 fprintf(stderr, "Invalid width\n"); in command_bus()
618 return(-1); in command_bus()
624 return(-1); in command_bus()
627 err_msg = encode_offset(width, offset, in command_bus()
631 return(-1); in command_bus()
635 i2c_opt.count = strtoul(cmd, &cmd, 0); in command_bus()
636 if (i2c_opt.count == 0 && errno == EINVAL) { in command_bus()
638 return(-1); in command_bus()
641 i2c_opt.count = 0; in command_bus()
649 return(-1); in command_bus()
651 dbuf[i2c_opt.count] = digittoint(*cmd++) << 4; in command_bus()
657 return(-1); in command_bus()
661 return(-1); in command_bus()
663 dbuf[i2c_opt.count++] |= digittoint(*cmd++); in command_bus()
671 if (fd == -1) { in command_bus()
681 return(-1); in command_bus()
684 for (u = 0; u < i2c_opt.count; u++) in command_bus()
719 while (argc-- > 0) { in instruct_bus()
720 if (argc == 0 && !strcmp(*argv, "-")) { in instruct_bus()
750 fd_cache[ch] = -1; in main()
757 i2c_opt.width = "8"; in main()
758 i2c_opt.count = 1; in main()
765 while ((ch = getopt(argc, argv, optflags)) != -1) { in main()
772 usage("Only one of [-a|-h|-r|-s]"); in main()
786 case 0: usage("Pick one of [-a|-h|-i|-r|-s]"); break; in main()
797 while ((ch = getopt(argc, argv, optflags)) != -1) { in main()
802 usage("Bad -a argument (hex)"); in main()
804 usage("Bad -a argument (01..7f)"); in main()
811 i2c_opt.count = (strtoul(optarg, 0, 10)); in main()
812 if (i2c_opt.count == 0 && errno == EINVAL) in main()
813 usage("Bad -c argument (decimal)"); in main()
817 usage("Bad -d argument ([r|w])"); in main()
834 usage("Bad -m argument ([no|ss|rs|tr])"); in main()
842 usage("Bad -o argument (hex)"); in main()
850 i2c_opt.width = optarg; // checked later. in main()
853 fprintf(stderr, "Illegal -%c option", ch); in main()
857 argc -= optind; in main()
864 /* Set default mode if option -m is not specified */ in main()
872 err_msg = encode_offset(i2c_opt.width, i2c_opt.off, in main()
880 if (fd == -1) { in main()
890 "offset: 0x%02x, width: %s, count: %u\n", dev, in main()
892 i2c_opt.width, i2c_opt.count); in main()