i2c.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Copyright 2016-2021 NXP
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. *
  6. */
  7. #ifndef I2C_H
  8. #define I2C_H
  9. #include <lib/mmio.h>
  10. #define I2C_TIMEOUT 1000 /* ms */
  11. #define I2C_FD_CONSERV 0x7e
  12. #define I2C_CR_DIS (1 << 7)
  13. #define I2C_CR_EN (0 << 7)
  14. #define I2C_CR_MA (1 << 5)
  15. #define I2C_CR_TX (1 << 4)
  16. #define I2C_CR_TX_NAK (1 << 3)
  17. #define I2C_CR_RSTA (1 << 2)
  18. #define I2C_SR_BB (1 << 5)
  19. #define I2C_SR_IDLE (0 << 5)
  20. #define I2C_SR_AL (1 << 4)
  21. #define I2C_SR_IF (1 << 1)
  22. #define I2C_SR_RX_NAK (1 << 0)
  23. #define I2C_SR_RST (I2C_SR_AL | I2C_SR_IF)
  24. #define I2C_GLITCH_EN 0x8
  25. #define i2c_in(a) mmio_read_8((uintptr_t)(a))
  26. #define i2c_out(a, v) mmio_write_8((uintptr_t)(a), (v))
  27. struct ls_i2c {
  28. unsigned char ad; /* I2c Bus Address Register */
  29. unsigned char fd; /* I2c Bus Frequency Dividor Register */
  30. unsigned char cr; /* I2c Bus Control Register */
  31. unsigned char sr; /* I2c Bus Status Register */
  32. unsigned char dr; /* I2C Bus Data I/O Register */
  33. unsigned char ic; /* I2C Bus Interrupt Config Register */
  34. unsigned char dbg; /* I2C Bus Debug Register */
  35. };
  36. void i2c_init(uintptr_t nxp_i2c_addr);
  37. int i2c_read(unsigned char chip, int addr, int alen,
  38. unsigned char *buf, int len);
  39. int i2c_write(unsigned char chip, int addr, int alen,
  40. const unsigned char *buf, int len);
  41. int i2c_probe_chip(unsigned char chip);
  42. #endif /* I2C_H */