Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _LINUX_I2C_ALGO_PCA_H
0003 #define _LINUX_I2C_ALGO_PCA_H
0004 
0005 /* Chips known to the pca algo */
0006 #define I2C_PCA_CHIP_9564   0x00
0007 #define I2C_PCA_CHIP_9665   0x01
0008 
0009 /* Internal period for PCA9665 oscilator */
0010 #define I2C_PCA_OSC_PER     3 /* e10-8s */
0011 
0012 /* Clock speeds for the bus for PCA9564*/
0013 #define I2C_PCA_CON_330kHz  0x00
0014 #define I2C_PCA_CON_288kHz  0x01
0015 #define I2C_PCA_CON_217kHz  0x02
0016 #define I2C_PCA_CON_146kHz  0x03
0017 #define I2C_PCA_CON_88kHz   0x04
0018 #define I2C_PCA_CON_59kHz   0x05
0019 #define I2C_PCA_CON_44kHz   0x06
0020 #define I2C_PCA_CON_36kHz   0x07
0021 
0022 /* PCA9564 registers */
0023 #define I2C_PCA_STA     0x00 /* STATUS  Read Only  */
0024 #define I2C_PCA_TO      0x00 /* TIMEOUT Write Only */
0025 #define I2C_PCA_DAT     0x01 /* DATA    Read/Write */
0026 #define I2C_PCA_ADR     0x02 /* OWN ADR Read/Write */
0027 #define I2C_PCA_CON     0x03 /* CONTROL Read/Write */
0028 
0029 /* PCA9665 registers */
0030 #define I2C_PCA_INDPTR          0x00 /* INDIRECT Pointer Write Only */
0031 #define I2C_PCA_IND             0x02 /* INDIRECT Read/Write */
0032 
0033 /* PCA9665 indirect registers */
0034 #define I2C_PCA_ICOUNT          0x00 /* Byte Count for buffered mode */
0035 #define I2C_PCA_IADR            0x01 /* OWN ADR */
0036 #define I2C_PCA_ISCLL           0x02 /* SCL LOW period */
0037 #define I2C_PCA_ISCLH           0x03 /* SCL HIGH period */
0038 #define I2C_PCA_ITO             0x04 /* TIMEOUT */
0039 #define I2C_PCA_IPRESET         0x05 /* Parallel bus reset */
0040 #define I2C_PCA_IMODE           0x06 /* I2C Bus mode */
0041 
0042 /* PCA9665 I2C bus mode */
0043 #define I2C_PCA_MODE_STD        0x00 /* Standard mode */
0044 #define I2C_PCA_MODE_FAST       0x01 /* Fast mode */
0045 #define I2C_PCA_MODE_FASTP      0x02 /* Fast Plus mode */
0046 #define I2C_PCA_MODE_TURBO      0x03 /* Turbo mode */
0047 
0048 
0049 #define I2C_PCA_CON_AA      0x80 /* Assert Acknowledge */
0050 #define I2C_PCA_CON_ENSIO   0x40 /* Enable */
0051 #define I2C_PCA_CON_STA     0x20 /* Start */
0052 #define I2C_PCA_CON_STO     0x10 /* Stop */
0053 #define I2C_PCA_CON_SI      0x08 /* Serial Interrupt */
0054 #define I2C_PCA_CON_CR      0x07 /* Clock Rate (MASK) */
0055 
0056 /**
0057  * struct pca_i2c_bus_settings - The configured PCA i2c bus settings
0058  * @mode: Configured i2c bus mode
0059  * @tlow: Configured SCL LOW period
0060  * @thi: Configured SCL HIGH period
0061  * @clock_freq: The configured clock frequency
0062  */
0063 struct pca_i2c_bus_settings {
0064     int mode;
0065     int tlow;
0066     int thi;
0067     int clock_freq;
0068 };
0069 
0070 struct i2c_algo_pca_data {
0071     void                *data;  /* private low level data */
0072     void (*write_byte)      (void *data, int reg, int val);
0073     int  (*read_byte)       (void *data, int reg);
0074     int  (*wait_for_completion) (void *data);
0075     void (*reset_chip)      (void *data);
0076     /* For PCA9564, use one of the predefined frequencies:
0077      * 330000, 288000, 217000, 146000, 88000, 59000, 44000, 36000
0078      * For PCA9665, use the frequency you want here. */
0079     unsigned int            i2c_clock;
0080     unsigned int            chip;
0081     struct pca_i2c_bus_settings     bus_settings;
0082 };
0083 
0084 int i2c_pca_add_bus(struct i2c_adapter *);
0085 int i2c_pca_add_numbered_bus(struct i2c_adapter *);
0086 
0087 #endif /* _LINUX_I2C_ALGO_PCA_H */