Root/target/linux/etrax/files/arch/cris/arch-v10/drivers/etraxi2c.h

1#ifndef _LINUX_ETRAXI2C_H
2#define _LINUX_ETRAXI2C_H
3
4/* etraxi2c _IOC_TYPE, bits 8 to 15 in ioctl cmd */
5
6#define ETRAXI2C_IOCTYPE 44
7
8/* supported ioctl _IOC_NR's */
9
10/* in write operations, the argument contains both i2c
11 * slave, register and value.
12 */
13
14#define I2C_WRITEARG(slave, reg, value) (((slave) << 16) | ((reg) << 8) | (value))
15#define I2C_READARG(slave, reg) (((slave) << 16) | ((reg) << 8))
16
17#define I2C_ARGSLAVE(arg) ((arg) >> 16)
18#define I2C_ARGREG(arg) (((arg) >> 8) & 0xff)
19#define I2C_ARGVALUE(arg) ((arg) & 0xff)
20
21#define I2C_WRITEREG 0x1 /* write to an I2C register */
22#define I2C_READREG 0x2 /* read from an I2C register */
23
24/*
25EXAMPLE usage:
26
27    i2c_arg = I2C_WRITEARG(STA013_WRITE_ADDR, reg, val);
28    ioctl(fd, _IO(ETRAXI2C_IOCTYPE, I2C_WRITEREG), i2c_arg);
29
30    i2c_arg = I2C_READARG(STA013_READ_ADDR, reg);
31    val = ioctl(fd, _IO(ETRAXI2C_IOCTYPE, I2C_READREG), i2c_arg);
32
33*/
34
35/* Extended part */
36#define I2C_READ 0x4 /* reads from I2C device */
37#define I2C_WRITE 0x3 /* writes to I2C device */
38#define I2C_WRITEREAD 0x5 /* writes to I2C device where to start reading */
39
40typedef struct _I2C_DATA
41{
42    unsigned char slave; /* I2C address (8-bit representation) of slave device */
43    unsigned char wbuf[256]; /* Write buffer (length = 256 bytes) */
44    unsigned int wlen; /* Number of bytes to write from wbuf[] */
45    unsigned char rbuf[256]; /* Read buffer (length = 256 bytes) */
46    unsigned int rlen; /* Number of bytes to read into rbuf[] */
47} I2C_DATA;
48
49#endif
50

Archive Download this file



interactive