Browse Source

Use a 20-bit limit for the i2c bus number.

Use snprintf for the i2c dev node name.
Update copyright years.


git-svn-id: http://lm-sensors.org/svn/i2c-tools/trunk@5885 7894878c-1315-0410-8ee3-d5d059ff63e0
tags/v3.0.3
Jean Delvare 15 years ago
parent
commit
3a5d21649e
  1. 8
      CHANGES
  2. 13
      tools/i2cbusses.c
  3. 6
      tools/i2cbusses.h
  4. 8
      tools/i2cdetect.c
  5. 4
      tools/i2cdump.c
  6. 4
      tools/i2cget.c
  7. 4
      tools/i2cset.c

8
CHANGES

@ -16,11 +16,11 @@ SVN
decode-xeon: Delete
eepromer: Fix array initialization overrun
i2cdetect: Drop legacy reference to ISA bus
Drop arbitrary limit on I2C bus number
i2cdump: Drop arbitrary limit on I2C bus number
i2cget: Drop arbitrary limit on I2C bus number
Increase limit on I2C bus number
i2cdump: Increase limit on I2C bus number
i2cget: Increase limit on I2C bus number
i2cset: Add support for short writes with PEC
Drop arbitrary limit on I2C bus number
Increase limit on I2C bus number
i2c-stub-from-dump: Use udev settle to speed up initialization
Unload i2c-stub automatically if needed
Add support for multiple dumps

13
tools/i2cbusses.c

@ -4,7 +4,7 @@
devices.
Copyright (c) 1999-2003 Frodo Looijaard <frodol@dds.nl> and
Mark D. Studebaker <mdsxyz123@yahoo.com>
Copyright (C) 2008 Jean Delvare <khali@linux-fr.org>
Copyright (C) 2008-2010 Jean Delvare <khali@linux-fr.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -22,7 +22,7 @@
MA 02110-1301 USA.
*/
/* For strdup */
/* For strdup and snprintf */
#define _BSD_SOURCE 1
#include <sys/types.h>
@ -67,7 +67,7 @@ static enum adt i2c_get_funcs(int i2cbus)
char filename[20];
enum adt ret;
file = open_i2c_dev(i2cbus, filename, 1);
file = open_i2c_dev(i2cbus, filename, sizeof(filename), 1);
if (file < 0)
return adt_unknown;
@ -340,7 +340,7 @@ int lookup_i2c_bus(const char *i2cbus_arg)
/* Not a number, maybe a name? */
return lookup_i2c_bus_by_name(i2cbus_arg);
}
if (i2cbus > INT_MAX) {
if (i2cbus > 0xFFFFF) {
fprintf(stderr, "Error: I2C bus out of range!\n");
return -2;
}
@ -371,11 +371,12 @@ int parse_i2c_address(const char *address_arg)
return address;
}
int open_i2c_dev(const int i2cbus, char *filename, const int quiet)
int open_i2c_dev(int i2cbus, char *filename, size_t size, int quiet)
{
int file;
sprintf(filename, "/dev/i2c/%d", i2cbus);
snprintf(filename, size, "/dev/i2c/%d", i2cbus);
filename[size - 1] = '\0';
file = open(filename, O_RDWR);
if (file < 0 && (errno == ENOENT || errno == ENOTDIR)) {

6
tools/i2cbusses.h

@ -1,7 +1,7 @@
/*
i2cbusses.h - Part of the i2c-tools package
Copyright (C) 2004-2007 Jean Delvare <khali@linux-fr.org>
Copyright (C) 2004-2010 Jean Delvare <khali@linux-fr.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -22,6 +22,8 @@
#ifndef _I2CBUSSES_H
#define _I2CBUSSES_H
#include <unistd.h>
struct i2c_adap {
int nr;
char *name;
@ -34,7 +36,7 @@ void free_adapters(struct i2c_adap *adapters);
int lookup_i2c_bus(const char *i2cbus_arg);
int parse_i2c_address(const char *address_arg);
int open_i2c_dev(const int i2cbus, char *filename, const int quiet);
int open_i2c_dev(int i2cbus, char *filename, size_t size, int quiet);
int set_slave_addr(int file, int address, int force);
#define MISSING_FUNC_FMT "Error: Adapter does not have %s capability\n"

8
tools/i2cdetect.c

@ -1,8 +1,8 @@
/*
i2cdetect.c - a user-space program to scan for I2C devices
Copyright (C) 1999-2004 Frodo Looijaard <frodol@dds.nl>,
Mark D. Studebaker <mdsxyz123@yahoo.com> and
Jean Delvare <khali@linux-fr.org>
Copyright (C) 1999-2004 Frodo Looijaard <frodol@dds.nl>, and
Mark D. Studebaker <mdsxyz123@yahoo.com>
Copyright (C) 2004-2010 Jean Delvare <khali@linux-fr.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -295,7 +295,7 @@ int main(int argc, char *argv[])
exit(1);
}
file = open_i2c_dev(i2cbus, filename, 0);
file = open_i2c_dev(i2cbus, filename, sizeof(filename), 0);
if (file < 0) {
exit(1);
}

4
tools/i2cdump.c

@ -2,7 +2,7 @@
i2cdump.c - a user-space program to dump I2C registers
Copyright (C) 2002-2003 Frodo Looijaard <frodol@dds.nl>, and
Mark D. Studebaker <mdsxyz123@yahoo.com>
Copyright (C) 2004-2008 Jean Delvare <khali@linux-fr.org>
Copyright (C) 2004-2010 Jean Delvare <khali@linux-fr.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -259,7 +259,7 @@ int main(int argc, char *argv[])
}
}
file = open_i2c_dev(i2cbus, filename, 0);
file = open_i2c_dev(i2cbus, filename, sizeof(filename), 0);
if (file < 0
|| check_funcs(file, size, pec)
|| set_slave_addr(file, address, force))

4
tools/i2cget.c

@ -1,6 +1,6 @@
/*
i2cget.c - A user-space program to read an I2C register.
Copyright (C) 2005-2008 Jean Delvare <khali@linux-fr.org>
Copyright (C) 2005-2010 Jean Delvare <khali@linux-fr.org>
Based on i2cset.c:
Copyright (C) 2001-2003 Frodo Looijaard <frodol@dds.nl>, and
@ -212,7 +212,7 @@ int main(int argc, char *argv[])
pec = argv[flags+4][1] == 'p';
}
file = open_i2c_dev(i2cbus, filename, 0);
file = open_i2c_dev(i2cbus, filename, sizeof(filename), 0);
if (file < 0
|| check_funcs(file, size, daddress, pec)
|| set_slave_addr(file, address, force))

4
tools/i2cset.c

@ -2,7 +2,7 @@
i2cset.c - A user-space program to write an I2C register.
Copyright (C) 2001-2003 Frodo Looijaard <frodol@dds.nl>, and
Mark D. Studebaker <mdsxyz123@yahoo.com>
Copyright (C) 2004-2009 Jean Delvare <khali@linux-fr.org>
Copyright (C) 2004-2010 Jean Delvare <khali@linux-fr.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -236,7 +236,7 @@ int main(int argc, char *argv[])
help();
}
file = open_i2c_dev(i2cbus, filename, 0);
file = open_i2c_dev(i2cbus, filename, sizeof(filename), 0);
if (file < 0
|| check_funcs(file, size, pec)
|| set_slave_addr(file, address, force))

Loading…
Cancel
Save