================================== これは、 linux-2.6.13/Documentation/i2c/functionality の和訳(ドラフト) です。 翻訳団体: JF プロジェクト < http://www.linux.or.jp/JF/ > 更新日 : 2005/9/2 翻訳者 : Hiroshi.Suzuki < setter at reset dot jp > 校正者 : ================================== INTRODUCTION 序論 ------------ Because not every I2C or SMBus adapter implements everything in the I2C specifications, a client can not trust that everything it needs is implemented when it is given the option to attach to an adapter: the client needs some way to check whether an adapter has the needed functionality. すべての、I2C や SMBus アダプタが I2C 仕様を実装しているわけではありません。 クライアントは、アダプタに接続するためのオプションが提供されてるからといって、 必要とする実装がすべて存在すると期待してはいけません:クライアントには、アダプタ が必要な機能 (functionality) を持っているかを、検査する方法が必要です。 FUNCTIONALITY CONSTANTS 機能を表わす定数 ----------------------- For the most up-to-date list of functionality constants, please check ! 最新の機能定数いついては、 をみてください! I2C_FUNC_I2C Plain i2c-level commands (Pure SMBus adapters typically can not do these) I2C_FUNC_10BIT_ADDR Handles the 10-bit address extensions I2C_FUNC_PROTOCOL_MANGLING Knows about the I2C_M_REV_DIR_ADDR, I2C_M_REV_DIR_ADDR and I2C_M_REV_DIR_NOSTART flags (which modify the i2c protocol!) I2C_FUNC_SMBUS_QUICK Handles the SMBus write_quick command I2C_FUNC_SMBUS_READ_BYTE Handles the SMBus read_byte command I2C_FUNC_SMBUS_WRITE_BYTE Handles the SMBus write_byte command I2C_FUNC_SMBUS_READ_BYTE_DATA Handles the SMBus read_byte_data command I2C_FUNC_SMBUS_WRITE_BYTE_DATA Handles the SMBus write_byte_data command I2C_FUNC_SMBUS_READ_WORD_DATA Handles the SMBus read_word_data command I2C_FUNC_SMBUS_WRITE_WORD_DATA Handles the SMBus write_byte_data command I2C_FUNC_SMBUS_PROC_CALL Handles the SMBus process_call command I2C_FUNC_SMBUS_READ_BLOCK_DATA Handles the SMBus read_block_data command I2C_FUNC_SMBUS_WRITE_BLOCK_DATA Handles the SMBus write_block_data command I2C_FUNC_SMBUS_READ_I2C_BLOCK Handles the SMBus read_i2c_block_data command I2C_FUNC_SMBUS_WRITE_I2C_BLOCK Handles the SMBus write_i2c_block_data command I2C_FUNC_I2C 素の I2C 水準のコマンド (通常、純粋な SMBus アダプタはでは、実行できません) I2C_FUNC_10BIT_ADDR 拡張 10ビットアドレスを扱います I2C_FUNC_PROTOCOL_MANGLING I2C_M_REV_DIR_ADDR, I2C_M_REV_DIR_ADDR, I2C_M_REV_DIR_NOSTART フラグについて知ります (i2c プロトコルを書き換えます!) I2C_FUNC_SMBUS_QUICK SMBus write_quick コマンドを扱います I2C_FUNC_SMBUS_READ_BYTE SMBus read_byte コマンドを扱います I2C_FUNC_SMBUS_WRITE_BYTE SMBus write_byte コマンドを扱います I2C_FUNC_SMBUS_READ_BYTE_DATA SMBus read_byte_data コマンドを扱います I2C_FUNC_SMBUS_WRITE_BYTE_DATA SMBus write_byte_data コマンドを扱います I2C_FUNC_SMBUS_READ_WORD_DATA SMBus read_word_data コマンドを扱います I2C_FUNC_SMBUS_WRITE_WORD_DATA SMBus write_byte_data コマンドを扱います I2C_FUNC_SMBUS_PROC_CALL SMBus process_call コマンドを扱います I2C_FUNC_SMBUS_READ_BLOCK_DATA SMBus read_block_data コマンドを扱います I2C_FUNC_SMBUS_WRITE_BLOCK_DATA SMBus write_block_data コマンドを扱います I2C_FUNC_SMBUS_READ_I2C_BLOCK SMBus read_i2c_block_data コマンドを扱います I2C_FUNC_SMBUS_WRITE_I2C_BLOCK SMBus write_i2c_block_data コマンドを扱います A few combinations of the above flags are also defined for your convenience: 利便性のため、上で示したフラグを組合せたものも、いくつか定義されています: I2C_FUNC_SMBUS_BYTE Handles the SMBus read_byte and write_byte commands I2C_FUNC_SMBUS_BYTE_DATA Handles the SMBus read_byte_data and write_byte_data commands I2C_FUNC_SMBUS_WORD_DATA Handles the SMBus read_word_data and write_word_data commands I2C_FUNC_SMBUS_BLOCK_DATA Handles the SMBus read_block_data and write_block_data commands I2C_FUNC_SMBUS_I2C_BLOCK Handles the SMBus read_i2c_block_data and write_i2c_block_data commands I2C_FUNC_SMBUS_EMUL Handles all SMBus commands than can be emulated by a real I2C adapter (using the transparent emulation layer) I2C_FUNC_SMBUS_BYTE SMBus read_byte と write_byte コマンドを扱います I2C_FUNC_SMBUS_BYTE_DATA SMBus read_byte_data と write_byte_data コマンドを扱います I2C_FUNC_SMBUS_WORD_DATA SMBus read_word_data と write_word_data コマンドを扱います I2C_FUNC_SMBUS_BLOCK_DATA SMBus read_block_data と write_block_data コマンドを扱います I2C_FUNC_SMBUS_I2C_BLOCK SMBus read_i2c_block_data と write_i2c_block_data コマンドを扱います I2C_FUNC_SMBUS_EMUL 実際の I2C アダプタがエミュレートできない、 すべての SMBus コマンドを扱います (透過エミュレーション階層を使います) ALGORITHM/ADAPTER IMPLEMENTATION アルゴリズム/アダプタ実装 -------------------------------- When you write a new algorithm driver, you will have to implement a function callback `functionality', that gets an i2c_adapter structure pointer as its only parameter: 新しいアルゴリズムドライバを作るとき、'functionality' 呼び戻し機能を 実装しなければならないでしょう。その機能は唯一のパラメータとして、 i2c_adapter 構造体のポインタを得ます。 struct i2c_algorithm { /* Many other things of course; check ! */ /* 他のものは、 をみてください! */ u32 (*functionality) (struct i2c_adapter *); } A typically implementation is given below, from i2c-algo-bit.c: 通常、(利用可能な) 実装は次に示すように与えられます (i2c-algo-bit.c より抜粋): static u32 bit_func(struct i2c_adapter *adap) { return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_10BIT_ADDR | I2C_FUNC_PROTOCOL_MANGLING; } CLIENT CHECKING クライアント検査 --------------- Before a client tries to attach to an adapter, or even do tests to check whether one of the devices it supports is present on an adapter, it should check whether the needed functionality is present. There are two functions defined which should be used instead of calling the functionality hook in the algorithm structure directly: クライアントがアダプタに接続しようとする、またはサポートするデバイスがアダプタ に接続されているか確認する前に、必要な機能が提供されているか検査しなければなり ません。2つの関数が定義されていて、それらを、アルゴリズム構造体の "functionality" フックを直接呼び出す代わりに使わなければなりません: /* Return the functionality mask */ /* 機能マスクを返す */ extern u32 i2c_get_functionality (struct i2c_adapter *adap); /* Return 1 if adapter supports everything we need, 0 if not. */ /* アダプタが必要な機能をすべてサポートするなら 1 を、それ以外は 0 を返します */ extern int i2c_check_functionality (struct i2c_adapter *adap, u32 func); This is a typical way to use these functions (from the writing-clients document): それら関数の、一般的な使い方を次に示します (writing-clients 説明書より抜粋): int foo_detect_client(struct i2c_adapter *adapter, int address, unsigned short flags, int kind) { /* Define needed variables */ /* 必要な引数を定義する */ /* As the very first action, we check whether the adapter has the needed functionality: we need the SMBus read_word_data, write_word_data and write_byte functions in this example. */ /* 一番初めの行動は、アダプタが、必要な機能を持っているか検査します: この例では、SMBus read_word_data, write_word_data, write_byte 機能を必要としています。 */ if (!i2c_check_functionality(adapter,I2C_FUNC_SMBUS_WORD_DATA | I2C_FUNC_SMBUS_WRITE_BYTE)) goto ERROR0; /* Now we can do the real detection */ /* 実際の (デバイス) 検出ができるようになりました */ ERROR0: /* Return an error */ /* エラーを返す */ } CHECKING THROUGH /DEV /DEV で検査する --------------------- If you try to access an adapter from a userspace program, you will have to use the /dev interface. You will still have to check whether the functionality you need is supported, of course. This is done using the I2C_FUNCS ioctl. An example, adapted from the lm_sensors i2c_detect program, is below: ユーザ空間のプログラムからアダプタにアクセスしようとするなら、/dev インタフェー スを使わなければなりません。もちろん、必要な機能がサポートされているかも検査し なければなりません。これは、I2C_FUNC ioctl を使ってできます。lm_sensors の i2c_detect プログラムにあわせた例を次に示します: int file; if (file = open("/dev/i2c-0",O_RDWR) < 0) { /* Some kind of error handling */ /* 適切なエラー処理 */ exit(1); } if (ioctl(file,I2C_FUNCS,&funcs) < 0) { /* Some kind of error handling */ /* 適切なエラー処理 */ exit(1); } if (! (funcs & I2C_FUNC_SMBUS_QUICK)) { /* Oops, the needed functionality (SMBus write_quick function) is not available! */ /* なんてことでしょう! 必要な機能 (SMBus write_quick 機能) が使えません!*/ exit(1); } /* Now it is safe to use the SMBus write_quick command */ /* SMBus write_quick コマンドが安全に使えるようになりました */