This adds i2c documentation, build options for i2c commands and a support header.
Signed-off-by: Nishanth Menon <[EMAIL PROTECTED]> --- Documentation/commands.dox | 4 commands/Kconfig | 31 +++++ commands/i2c.c | 233 +++++++++++++++++++++++++++++++++++++++++++++ commands/i2c.h | 65 ++++++++++++ 4 files changed, 333 insertions(+) Index: u-boot-v2.git/commands/i2c.h =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ u-boot-v2.git/commands/i2c.h 2008-06-19 09:31:42.000000000 -0500 @@ -0,0 +1,65 @@ +/** + * @file + * @brief I2C Commands specific header. + * + * FileName: commands/i2c.h + * This provides i2cdump, i2cdetect, i2cset and i2cget appplications + * The code originates from the i2c-tools located here: + * http://www.lm-sensors.org/wiki/I2CTools + * This is used by the c file + */ +/* + * (C) Copyright 2006-2008 + * Texas Instruments, <www.ti.com> + * Nishanth Menon <[EMAIL PROTECTED]> + * + * This application is based on the following: + * + * i2cbusses: Print the installed i2c busses for both 2.4 and 2.6 kernels. + * Part of user-space programs to access for I2C + * devices. + * Copyright (c) 1999-2003 Frodo Looijaard <[EMAIL PROTECTED]> and + * Mark D. Studebaker <[EMAIL PROTECTED]> + * Copyright (C) 2008 Jean Delvare <[EMAIL PROTECTED]> + * i2cdump.c - a user-space program to dump I2C registers + * Copyright (C) 2002-2003 Frodo Looijaard <[EMAIL PROTECTED]>, and + * Mark D. Studebaker <[EMAIL PROTECTED]> + * Copyright (C) 2004-2008 Jean Delvare <[EMAIL PROTECTED]> + * i2cget.c - A user-space program to read an I2C register. + * Copyright (C) 2005-2008 Jean Delvare <[EMAIL PROTECTED]> + * i2cset.c - A user-space program to write an I2C register. + * Copyright (C) 2001-2003 Frodo Looijaard <[EMAIL PROTECTED]>, and + * Mark D. Studebaker <[EMAIL PROTECTED]> + * Copyright (C) 2004-2008 Jean Delvare <[EMAIL PROTECTED]> + * + * 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 + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA. + */ + +#ifndef __CMD_I2C_H +#define __CMD_I2C_H + +/*********** "USER SPACE I2C Access APIs" ************/ + +int lookup_i2c_bus(const char *i2cbus_arg); +int open_i2c_dev(const int i2cbus, char *filename, const int quiet); +int parse_i2c_address(const char *address_arg); +int set_slave_addr(int file, int address, int force); +int check_funcs(int file, int size, int daddress, int pec); +int read_i2c(int file, uchar daddr, u16 addr, u8 reg_width, char *buffer, + size_t count); +int write_i2c(int file, uchar daddr, u16 addr, u8 reg_width, char *buffer, + size_t count); +#endif /* __CMD_I2C_H */ Index: u-boot-v2.git/Documentation/commands.dox =================================================================== --- u-boot-v2.git.orig/Documentation/commands.dox 2008-06-19 09:29:03.000000000 -0500 +++ u-boot-v2.git/Documentation/commands.dox 2008-06-19 09:31:42.000000000 -0500 @@ -20,5 +20,9 @@ - @subpage setenv_command - @subpage sh_command - @subpage unprotect_command + - @subpage page_do_cmd_i2c_detect + - @subpage page_do_cmd_i2c_dump + - @subpage page_do_cmd_i2c_get + - @subpage page_do_cmd_i2c_set */ Index: u-boot-v2.git/commands/Kconfig =================================================================== --- u-boot-v2.git.orig/commands/Kconfig 2008-06-19 09:29:03.000000000 -0500 +++ u-boot-v2.git/commands/Kconfig 2008-06-19 09:31:42.000000000 -0500 @@ -180,6 +180,37 @@ prompt "nand" endmenu +menu "i2c " + depends on I2C_CHARDEV + +config CMD_I2C + bool + default n + +config CMD_I2C_DETECT + tristate + default y + select CMD_I2C + prompt "i2cdetect" + +config CMD_I2C_DUMP + tristate + default y + select CMD_I2C + prompt "i2cdump" + +config CMD_I2C_GET + tristate + default y + select CMD_I2C + prompt "i2cget" + +config CMD_I2C_SET + tristate + default y + select CMD_I2C + prompt "i2cset" +endmenu menu "booting " Index: u-boot-v2.git/commands/i2c.c =================================================================== --- u-boot-v2.git.orig/commands/i2c.c 2008-06-19 09:31:49.000000000 -0500 +++ u-boot-v2.git/commands/i2c.c 2008-06-19 09:32:57.000000000 -0500 @@ -515,6 +515,64 @@ U_BOOT_CMD_HELP(cmd_i2cdetect_help_s) U_BOOT_CMD_END #endif /* CONFIG_CMD_I2C_DETECT */ +/** @page page_do_cmd_i2c_detect i2cdetect detect I2C chips +SYNOPSIS: [EMAIL PROTECTED] i2cdetect [-a] [-q|-r] i2cbus [first last] [EMAIL PROTECTED] i2cdetect -F i2cbus + [EMAIL PROTECTED] + This program can confuse your I2C bus, cause data loss and worse! + +DESCRIPTION: [EMAIL PROTECTED] + i2cdetect is a program to scan an I2C bus for devices. It + outputs a table with the list of detected devices on the specified bus. + i2cbus indicates the number of the I2C bus to be scanned, these are + present as 'xx' of /dev/i2cdxx. The optional parameters first and + last restrict the scanning range (default: from 0x03 to 0x77). + + i2cdetect can also be used to query the functionalities of an I2C bus + (see option -F.) [EMAIL PROTECTED] + +INTERPRETING THE OUTPUT: [EMAIL PROTECTED] + Each cell in the output table will contain one of the following sym + bols: + + · "--". The address was probed but no chip answered. + + · "UU". Probing was skipped, because this address is currently in use + by a driver. This strongly suggests that there is a chip at this + address. + + · An address number in hexadecimal, e.g. "2d" or "4e". A chip was found + at this address. [EMAIL PROTECTED] + +OPTIONS: [EMAIL PROTECTED] + -a Force scanning of non-regular addresses. Not recommended. + + -q Use "quick write" commands for probing. Not recommended. + + -r Use "read byte" commands for probing. Not recommended. + This is known to lock on various write-only chips. + + -F Display the list of functionalities implemented by the adapter + and exit. + [EMAIL PROTECTED] + +AUTHOR: [EMAIL PROTECTED] + Frodo Looijaard, Mark D. Studebaker and Jean Delvare + + This manual page was originally written by Aurelien Jarno + <[EMAIL PROTECTED]>, for the Debian GNU/Linux system. + [EMAIL PROTECTED] + */ #ifdef CONFIG_CMD_I2C_DUMP static const __maybe_unused char cmd_i2cdump_help_s[] = @@ -789,6 +847,66 @@ U_BOOT_CMD_HELP(cmd_i2cdump_help_s) U_BOOT_CMD_END #endif /* CONFIG_CMD_I2C_DUMP */ +/** @page page_do_cmd_i2c_dump i2cdump examine I2C registers +SYNOPSIS [EMAIL PROTECTED] i2cdump [-f] [-r first-last] i2cbus address [mode] + [EMAIL PROTECTED] + i2cdump can be dangerous if used improperly. Most notably, the c mode + starts with WRITING a byte to the chip. On most chips it will be stored + in the address pointer register, which is OK, but some chips with a + single register or no (visible) register at all will most likely see + this as a real WRITE, resulting in possible misbehavior or corruption. + Do not use i2cdump on random addresses. Anyway, it is of little use + unless you have good knowledge of the chip youâ€(tm)re working with and an + idea of what you are looking for. + +DESCRIPTION: [EMAIL PROTECTED] + i2cdump is a small helper program to examine registers visible through + the I2C bus. [EMAIL PROTECTED] + +OPTIONS: [EMAIL PROTECTED] + -f Force access to the device even if it is already busy. By + default, i2cdump will refuse to access a device which is already + under the control of a kernel driver. Using this flag is danger†+ ous, it can seriously confuse the kernel driver in question. It + can also cause i2cdump to return invalid results. So use at your + own risk and only if you know what youâ€(tm)re doing. + + -r first-last + Limit the range of registers being accessed. This option is only + available with modes b, w, c and W. For mode W, first must be + even and last must be odd. + + At least two options must be provided to i2cdump. i2cbus indicates the + number of the I2C bus to be scanned, these are present as 'xx' of + /dev/i2cdxx. The optional parameters first and address indicates + the address to be scanned on that bus, and is an integer between + 0x03 and 0x77. + + The mode parameter, if specified, is one of the letters b, w, + corresponding to a read size of a single byte, a 16-bit word, + respectively.The W mode is also special, it is similar to w except that + a read command will only be issued on even register addresses; + this is again mainly useful for EEPROMs. + + A p can also be appended to the mode parameter (except for i and W) to + enable PEC. If the mode parameter is omitted, i2cdump defaults to byte + access without PEC. + [EMAIL PROTECTED] + +AUTHOR [EMAIL PROTECTED] + Frodo Looijaard, Mark D. Studebaker and Jean Delvare + + This manual page was originally written by David Z Maze + <[EMAIL PROTECTED]> for the Debian GNU/Linux system. [EMAIL PROTECTED] + */ #ifdef CONFIG_CMD_I2C_GET static const __maybe_unused char cmd_i2cget_help_s[] = @@ -992,6 +1110,57 @@ U_BOOT_CMD_HELP(cmd_i2cget_help_s) U_BOOT_CMD_END #endif /* CONFIG_CMD_I2C_GET */ +/** @page page_do_cmd_i2c_get i2cget read from I2C chip registers +SYNOPSIS [EMAIL PROTECTED] i2cget [-f] [-y] i2cbus chip-address [data-address [mode]] + [EMAIL PROTECTED] + i2cget can be extremely dangerous if used improperly. + Be extremely careful using this program. + +DESCRIPTION: [EMAIL PROTECTED] + i2cget is a small helper program to read registers visible through the + I2C bus. [EMAIL PROTECTED] + +OPTIONS [EMAIL PROTECTED] + -f Force access to the device even if it is already busy. By + default, i2cget will refuse to access a device which is already + under the control of a kernel driver. Using this flag is danger + ous, it can seriously confuse the kernel driver in question. It + can also cause i2cget to return an invalid value. So use at your + own risk and only if you know what youâ€(tm)re doing. + + -y will allow to set 0x50 to 0x57 with pec enabled + + At least two options must be provided to i2cget. i2cbus indicates the + number of the I2C bus to be scanned, these are present as 'xx' of + /dev/i2cdxx. chip-address specifies the address of the chip on + that bus, and is an integer between 0x03 and 0x77. + + data-address specifies the address on that chip to read from, and is an + integer between 0x00 and 0xFF. If omitted, the currently active regis + ter will be read (if that makes sense for the considered chip). + + The mode parameter, if specified, is one of the letters b, w or c, cor + responding to a read byte data, a read word data or a write byte/read + byte transaction, respectively. A p can also be appended to the mode + parameter to enable PEC. If the mode parameter is omitted, i2cget + defaults to a read byte data transaction, unless data-address is also + omitted, in which case the default (and only valid) transaction is a + single read byte. [EMAIL PROTECTED] + +AUTHOR [EMAIL PROTECTED] + Jean Delvare + + This manual page was strongly inspired from those written by David Z + Maze for i2cset. [EMAIL PROTECTED] +*/ #ifdef CONFIG_CMD_I2C_SET static const __maybe_unused char cmd_i2cset_help_s[] = @@ -1266,3 +1435,67 @@ U_BOOT_CMD_HELP(cmd_i2cset_help_s) U_BOOT_CMD_END #endif /* CONFIG_CMD_I2C_SET */ +/** @page page_do_cmd_i2c_set i2cset set I2C registers + +SYNOPSIS [EMAIL PROTECTED] i2cset [-f] [-y] i2cbus chip-address data-address [value [mode [mask]]] + [EMAIL PROTECTED] + i2cset can be extremely dangerous if used improperly. It can confuse + your I2C bus, cause data loss, or have more serious side effects. Writ + ing to a serial EEPROM on a memory DIMM (chip addresses between 0x50 + and 0x57) may DESTROY your memory! Be extremely careful using this + program. + +DESCRIPTION [EMAIL PROTECTED] + i2cset is a small helper program to set registers visible through the + I2C bus. [EMAIL PROTECTED] + +OPTIONS [EMAIL PROTECTED] + -f Force access to the device even if it is already busy. By + default, i2cset will refuse to access a device which is already + under the control of a kernel driver. Using this flag is danger + ous, it can seriously confuse the kernel driver in question. It + can also cause i2cset to silently write to the wrong register. + So use at your own risk and only if you know what you are + doing. + + -y will allow to set 0x50 to 0x57 with pec enabled + + There are three required options to i2cset. i2cbus indicates the number + of the I2C bus to be scanned, these are present as 'xx' of /dev/i2cdxx. + chip-address specifies the address of th chip on that bus, and is + an integer between 0x03 and 0x77. data-address specifies the address on + that chip to write to, and is an integer between 0x00 and 0xFF. + + The value parameter, if specified, is the value to write to that loca + tion on the chip. If this parameter is omited, then a short write is + issued. For most chips, it simply sets an internal pointer to the tar + get location, but doesnâ€(tm)t actually write to that location. For a few + chips though, in particular simple ones with a single register, this + short write is an actual write. + + The mode parameter, if specified, is one of the letters b or w, corre + sponding to a write size of a single byte or a 16-bit word, respec + tively. A p can also be appended to the mode parameter to enable PEC. + If the mode parameter is omitted, i2cset defaults to byte mode without + PEC. The value provided must be within range for the specified data + type (0x00-0xFF for bytes, 0x0000-0xFFFF for words). + + The mask parameter, if specified, describes which bits of value will be + actually written to data-address. Bits set to 1 in the mask are taken + from value, while bits set to 0 will be read from data-address and thus + preserved by the operation. [EMAIL PROTECTED] + +AUTHOR [EMAIL PROTECTED] + Frodo Looijaard, Mark D. Studebaker and Jean Delvare + + This manual page was originally written by David Z Maze + <[EMAIL PROTECTED]> for the Debian GNU/Linux system. [EMAIL PROTECTED] +*/ ------------------------------------------------------------------------- Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://sourceforge.net/services/buy/index.php _______________________________________________ U-Boot-Users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/u-boot-users
