i2c-algo-pca.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _LINUX_I2C_ALGO_PCA_H
  3. #define _LINUX_I2C_ALGO_PCA_H
  4. /* Chips known to the pca algo */
  5. #define I2C_PCA_CHIP_9564 0x00
  6. #define I2C_PCA_CHIP_9665 0x01
  7. /* Internal period for PCA9665 oscilator */
  8. #define I2C_PCA_OSC_PER 3 /* e10-8s */
  9. /* Clock speeds for the bus for PCA9564*/
  10. #define I2C_PCA_CON_330kHz 0x00
  11. #define I2C_PCA_CON_288kHz 0x01
  12. #define I2C_PCA_CON_217kHz 0x02
  13. #define I2C_PCA_CON_146kHz 0x03
  14. #define I2C_PCA_CON_88kHz 0x04
  15. #define I2C_PCA_CON_59kHz 0x05
  16. #define I2C_PCA_CON_44kHz 0x06
  17. #define I2C_PCA_CON_36kHz 0x07
  18. /* PCA9564 registers */
  19. #define I2C_PCA_STA 0x00 /* STATUS Read Only */
  20. #define I2C_PCA_TO 0x00 /* TIMEOUT Write Only */
  21. #define I2C_PCA_DAT 0x01 /* DATA Read/Write */
  22. #define I2C_PCA_ADR 0x02 /* OWN ADR Read/Write */
  23. #define I2C_PCA_CON 0x03 /* CONTROL Read/Write */
  24. /* PCA9665 registers */
  25. #define I2C_PCA_INDPTR 0x00 /* INDIRECT Pointer Write Only */
  26. #define I2C_PCA_IND 0x02 /* INDIRECT Read/Write */
  27. /* PCA9665 indirect registers */
  28. #define I2C_PCA_ICOUNT 0x00 /* Byte Count for buffered mode */
  29. #define I2C_PCA_IADR 0x01 /* OWN ADR */
  30. #define I2C_PCA_ISCLL 0x02 /* SCL LOW period */
  31. #define I2C_PCA_ISCLH 0x03 /* SCL HIGH period */
  32. #define I2C_PCA_ITO 0x04 /* TIMEOUT */
  33. #define I2C_PCA_IPRESET 0x05 /* Parallel bus reset */
  34. #define I2C_PCA_IMODE 0x06 /* I2C Bus mode */
  35. /* PCA9665 I2C bus mode */
  36. #define I2C_PCA_MODE_STD 0x00 /* Standard mode */
  37. #define I2C_PCA_MODE_FAST 0x01 /* Fast mode */
  38. #define I2C_PCA_MODE_FASTP 0x02 /* Fast Plus mode */
  39. #define I2C_PCA_MODE_TURBO 0x03 /* Turbo mode */
  40. #define I2C_PCA_CON_AA 0x80 /* Assert Acknowledge */
  41. #define I2C_PCA_CON_ENSIO 0x40 /* Enable */
  42. #define I2C_PCA_CON_STA 0x20 /* Start */
  43. #define I2C_PCA_CON_STO 0x10 /* Stop */
  44. #define I2C_PCA_CON_SI 0x08 /* Serial Interrupt */
  45. #define I2C_PCA_CON_CR 0x07 /* Clock Rate (MASK) */
  46. /**
  47. * struct pca_i2c_bus_settings - The configured PCA i2c bus settings
  48. * @mode: Configured i2c bus mode
  49. * @tlow: Configured SCL LOW period
  50. * @thi: Configured SCL HIGH period
  51. * @clock_freq: The configured clock frequency
  52. */
  53. struct pca_i2c_bus_settings {
  54. int mode;
  55. int tlow;
  56. int thi;
  57. int clock_freq;
  58. };
  59. struct i2c_algo_pca_data {
  60. void *data; /* private low level data */
  61. void (*write_byte) (void *data, int reg, int val);
  62. int (*read_byte) (void *data, int reg);
  63. int (*wait_for_completion) (void *data);
  64. void (*reset_chip) (void *data);
  65. /* For PCA9564, use one of the predefined frequencies:
  66. * 330000, 288000, 217000, 146000, 88000, 59000, 44000, 36000
  67. * For PCA9665, use the frequency you want here. */
  68. unsigned int i2c_clock;
  69. unsigned int chip;
  70. struct pca_i2c_bus_settings bus_settings;
  71. };
  72. int i2c_pca_add_bus(struct i2c_adapter *);
  73. int i2c_pca_add_numbered_bus(struct i2c_adapter *);
  74. #endif /* _LINUX_I2C_ALGO_PCA_H */