i2c.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /* ------------------------------------------------------------------------- */
  2. /* */
  3. /* i2c.h - definitions for the i2c-bus interface */
  4. /* */
  5. /* ------------------------------------------------------------------------- */
  6. /* Copyright (C) 1995-2000 Simon G. Vogl
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU General Public License for more details.
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
  18. /* ------------------------------------------------------------------------- */
  19. /* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and
  20. Frodo Looijaard <frodol@dds.nl> */
  21. #ifndef _LINUX_I2C_H
  22. #define _LINUX_I2C_H
  23. #include <linux/types.h>
  24. /**
  25. * struct i2c_msg - an I2C transaction segment beginning with START
  26. * @addr: Slave address, either seven or ten bits. When this is a ten
  27. * bit address, I2C_M_TEN must be set in @flags and the adapter
  28. * must support I2C_FUNC_10BIT_ADDR.
  29. * @flags: I2C_M_RD is handled by all adapters. No other flags may be
  30. * provided unless the adapter exported the relevant I2C_FUNC_*
  31. * flags through i2c_check_functionality().
  32. * @len: Number of data bytes in @buf being read from or written to the
  33. * I2C slave address. For read transactions where I2C_M_RECV_LEN
  34. * is set, the caller guarantees that this buffer can hold up to
  35. * 32 bytes in addition to the initial length byte sent by the
  36. * slave (plus, if used, the SMBus PEC); and this value will be
  37. * incremented by the number of block data bytes received.
  38. * @buf: The buffer into which data is read, or from which it's written.
  39. *
  40. * An i2c_msg is the low level representation of one segment of an I2C
  41. * transaction. It is visible to drivers in the @i2c_transfer() procedure,
  42. * to userspace from i2c-dev, and to I2C adapter drivers through the
  43. * @i2c_adapter.@master_xfer() method.
  44. *
  45. * Except when I2C "protocol mangling" is used, all I2C adapters implement
  46. * the standard rules for I2C transactions. Each transaction begins with a
  47. * START. That is followed by the slave address, and a bit encoding read
  48. * versus write. Then follow all the data bytes, possibly including a byte
  49. * with SMBus PEC. The transfer terminates with a NAK, or when all those
  50. * bytes have been transferred and ACKed. If this is the last message in a
  51. * group, it is followed by a STOP. Otherwise it is followed by the next
  52. * @i2c_msg transaction segment, beginning with a (repeated) START.
  53. *
  54. * Alternatively, when the adapter supports I2C_FUNC_PROTOCOL_MANGLING then
  55. * passing certain @flags may have changed those standard protocol behaviors.
  56. * Those flags are only for use with broken/nonconforming slaves, and with
  57. * adapters which are known to support the specific mangling options they
  58. * need (one or more of IGNORE_NAK, NO_RD_ACK, NOSTART, and REV_DIR_ADDR).
  59. */
  60. struct i2c_msg {
  61. __u16 addr; /* slave address */
  62. __u16 flags;
  63. #define I2C_M_TEN 0x0010 /* this is a ten bit chip address */
  64. #define I2C_M_RD 0x0001 /* read data, from slave to master */
  65. #define I2C_M_NOSTART 0x4000 /* if I2C_FUNC_PROTOCOL_MANGLING */
  66. #define I2C_M_REV_DIR_ADDR 0x2000 /* if I2C_FUNC_PROTOCOL_MANGLING */
  67. #define I2C_M_IGNORE_NAK 0x1000 /* if I2C_FUNC_PROTOCOL_MANGLING */
  68. #define I2C_M_NO_RD_ACK 0x0800 /* if I2C_FUNC_PROTOCOL_MANGLING */
  69. #define I2C_M_RECV_LEN 0x0400 /* length will be first received byte */
  70. __u16 len; /* msg length */
  71. __u8 *buf; /* pointer to msg data */
  72. };
  73. /* To determine what functionality is present */
  74. #define I2C_FUNC_I2C 0x00000001
  75. #define I2C_FUNC_10BIT_ADDR 0x00000002
  76. #define I2C_FUNC_PROTOCOL_MANGLING 0x00000004 /* I2C_M_NOSTART etc. */
  77. #define I2C_FUNC_SMBUS_PEC 0x00000008
  78. #define I2C_FUNC_SMBUS_BLOCK_PROC_CALL 0x00008000 /* SMBus 2.0 */
  79. #define I2C_FUNC_SMBUS_QUICK 0x00010000
  80. #define I2C_FUNC_SMBUS_READ_BYTE 0x00020000
  81. #define I2C_FUNC_SMBUS_WRITE_BYTE 0x00040000
  82. #define I2C_FUNC_SMBUS_READ_BYTE_DATA 0x00080000
  83. #define I2C_FUNC_SMBUS_WRITE_BYTE_DATA 0x00100000
  84. #define I2C_FUNC_SMBUS_READ_WORD_DATA 0x00200000
  85. #define I2C_FUNC_SMBUS_WRITE_WORD_DATA 0x00400000
  86. #define I2C_FUNC_SMBUS_PROC_CALL 0x00800000
  87. #define I2C_FUNC_SMBUS_READ_BLOCK_DATA 0x01000000
  88. #define I2C_FUNC_SMBUS_WRITE_BLOCK_DATA 0x02000000
  89. #define I2C_FUNC_SMBUS_READ_I2C_BLOCK 0x04000000 /* I2C-like block xfer */
  90. #define I2C_FUNC_SMBUS_WRITE_I2C_BLOCK 0x08000000 /* w/ 1-byte reg. addr. */
  91. #define I2C_FUNC_SMBUS_BYTE (I2C_FUNC_SMBUS_READ_BYTE | \
  92. I2C_FUNC_SMBUS_WRITE_BYTE)
  93. #define I2C_FUNC_SMBUS_BYTE_DATA (I2C_FUNC_SMBUS_READ_BYTE_DATA | \
  94. I2C_FUNC_SMBUS_WRITE_BYTE_DATA)
  95. #define I2C_FUNC_SMBUS_WORD_DATA (I2C_FUNC_SMBUS_READ_WORD_DATA | \
  96. I2C_FUNC_SMBUS_WRITE_WORD_DATA)
  97. #define I2C_FUNC_SMBUS_BLOCK_DATA (I2C_FUNC_SMBUS_READ_BLOCK_DATA | \
  98. I2C_FUNC_SMBUS_WRITE_BLOCK_DATA)
  99. #define I2C_FUNC_SMBUS_I2C_BLOCK (I2C_FUNC_SMBUS_READ_I2C_BLOCK | \
  100. I2C_FUNC_SMBUS_WRITE_I2C_BLOCK)
  101. #define I2C_FUNC_SMBUS_EMUL (I2C_FUNC_SMBUS_QUICK | \
  102. I2C_FUNC_SMBUS_BYTE | \
  103. I2C_FUNC_SMBUS_BYTE_DATA | \
  104. I2C_FUNC_SMBUS_WORD_DATA | \
  105. I2C_FUNC_SMBUS_PROC_CALL | \
  106. I2C_FUNC_SMBUS_WRITE_BLOCK_DATA | \
  107. I2C_FUNC_SMBUS_I2C_BLOCK | \
  108. I2C_FUNC_SMBUS_PEC)
  109. /*
  110. * Data for SMBus Messages
  111. */
  112. #define I2C_SMBUS_BLOCK_MAX 32 /* As specified in SMBus standard */
  113. union i2c_smbus_data {
  114. __u8 byte;
  115. __u16 word;
  116. __u8 block[I2C_SMBUS_BLOCK_MAX + 2]; /* block[0] is used for length */
  117. /* and one more for user-space compatibility */
  118. };
  119. /* i2c_smbus_xfer read or write markers */
  120. #define I2C_SMBUS_READ 1
  121. #define I2C_SMBUS_WRITE 0
  122. /* SMBus transaction types (size parameter in the above functions)
  123. Note: these no longer correspond to the (arbitrary) PIIX4 internal codes! */
  124. #define I2C_SMBUS_QUICK 0
  125. #define I2C_SMBUS_BYTE 1
  126. #define I2C_SMBUS_BYTE_DATA 2
  127. #define I2C_SMBUS_WORD_DATA 3
  128. #define I2C_SMBUS_PROC_CALL 4
  129. #define I2C_SMBUS_BLOCK_DATA 5
  130. #define I2C_SMBUS_I2C_BLOCK_BROKEN 6
  131. #define I2C_SMBUS_BLOCK_PROC_CALL 7 /* SMBus 2.0 */
  132. #define I2C_SMBUS_I2C_BLOCK_DATA 8
  133. #endif /* _LINUX_I2C_H */