Lines Matching +full:slave +full:- +full:addr

1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
4 * Copyright (C) 2008-2009 Semihalf, Michal Hajduk and Bartlomiej Sieka
60 uint32_t addr;
75 fprintf(stderr, "usage: %s -a addr [-f device] [-d [r|w]] [-o offset] "
76 "[-w [0|8|16|16LE|16BE]] [-c count] [-m [tr|ss|rs|no]] [-b] [-v]\n",
78 fprintf(stderr, " %s -s [-f device] [-n skip_addr] -v\n",
80 fprintf(stderr, " %s -r [-f device] -v\n", getprogname());
168 usage("Bad -n argument, expected (first) hex-digit");
171 usage("Bad -n argument, expected (second) hex-digit");
174 usage("Bad -n argument, (01..7f)");
181 if (*p == '-') {
186 usage("Bad -n argument, ([:|,|..|-])");
191 usage("Bad -n argument, expected (first) hex-digit");
194 usage("Bad -n argument, expected (second) hex-digit");
197 usage("Bad -n argument, (01..7f)");
199 usage("Bad -n argument, (end < start)");
230 cmd.slave = u << 1;
240 rdmsg.slave = u << 1;
265 "trying less-reliable read method.\n");
294 return ("Invalid 8-bit offset\n");
300 return ("Invalid 16-bit offset\n");
319 cmd->count = i2c_opt.off_len;
320 cmd->buf = (void*)i2c_opt.off_buf;
333 cmd.slave = i2c_opt.addr;
401 cmd.slave = i2c_opt.addr;
416 cmd.slave = i2c_opt.addr | 1;
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;
457 msgp->slave = i2c_opt.addr;
458 msgp->buf = i2c_opt.off_buf;
459 msgp->len = i2c_opt.off_len;
468 * a start; if we did an offset write above it'll be a repeat-start
472 msgp->flags = IIC_M_WR | flag;
474 msgp->flags = IIC_M_RD;
475 msgp->slave = i2c_opt.addr;
476 msgp->len = i2c_opt.count;
477 msgp->buf = i2c_buf;
481 xfer.nmsgs = msgp - msgs;
483 if (ioctl(fd, I2CRDWR, &xfer) == -1 )
524 if ((u % chunk_size) == chunk_size - 1)
582 return(-1);
589 return(-1);
592 i2c_opt.addr = strtoul(cmd, &cmd, 0);
593 if (i2c_opt.addr == 0 && errno == EINVAL) {
595 return(-1);
597 if (i2c_opt.addr < 1 || i2c_opt.addr > 0x7f) {
598 fprintf(stderr, "Invalid device (0x%x)\n", i2c_opt.addr);
599 return(-1);
601 i2c_opt.addr <<= 1;
618 return(-1);
624 return(-1);
631 return(-1);
638 return(-1);
649 return(-1);
657 return(-1);
661 return(-1);
671 if (fd == -1) {
681 return(-1);
719 while (argc-- > 0) {
720 if (argc == 0 && !strcmp(*argv, "-")) {
750 fd_cache[ch] = -1;
754 i2c_opt.addr = 0;
765 while ((ch = getopt(argc, argv, optflags)) != -1) {
772 usage("Only one of [-a|-h|-r|-s]");
786 case 0: usage("Pick one of [-a|-h|-i|-r|-s]"); break;
797 while ((ch = getopt(argc, argv, optflags)) != -1) {
800 i2c_opt.addr = strtoul(optarg, 0, 16);
801 if (i2c_opt.addr == 0 && errno == EINVAL)
802 usage("Bad -a argument (hex)");
803 if (i2c_opt.addr == 0 || i2c_opt.addr > 0x7f)
804 usage("Bad -a argument (01..7f)");
805 i2c_opt.addr <<= 1;
813 usage("Bad -c argument (decimal)");
817 usage("Bad -d argument ([r|w])");
834 usage("Bad -m argument ([no|ss|rs|tr])");
842 usage("Bad -o argument (hex)");
853 fprintf(stderr, "Illegal -%c option", ch);
857 argc -= optind;
864 /* Set default mode if option -m is not specified */
880 if (fd == -1) {
889 fprintf(stderr, "dev: %s, addr: 0x%x, r/w: %c, "
891 i2c_opt.addr >> 1, i2c_opt.dir, i2c_opt.off,