bfin_twi.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*
  2. * i2c-bfin-twi.h - interface to ADI TWI controller
  3. *
  4. * Copyright 2005-2014 Analog Devices Inc.
  5. *
  6. * Licensed under the GPL-2 or later.
  7. */
  8. #ifndef __I2C_BFIN_TWI_H__
  9. #define __I2C_BFIN_TWI_H__
  10. #include <linux/types.h>
  11. #include <linux/i2c.h>
  12. /*
  13. * ADI twi registers layout
  14. */
  15. struct bfin_twi_regs {
  16. u16 clkdiv;
  17. u16 dummy1;
  18. u16 control;
  19. u16 dummy2;
  20. u16 slave_ctl;
  21. u16 dummy3;
  22. u16 slave_stat;
  23. u16 dummy4;
  24. u16 slave_addr;
  25. u16 dummy5;
  26. u16 master_ctl;
  27. u16 dummy6;
  28. u16 master_stat;
  29. u16 dummy7;
  30. u16 master_addr;
  31. u16 dummy8;
  32. u16 int_stat;
  33. u16 dummy9;
  34. u16 int_mask;
  35. u16 dummy10;
  36. u16 fifo_ctl;
  37. u16 dummy11;
  38. u16 fifo_stat;
  39. u16 dummy12;
  40. u32 __pad[20];
  41. u16 xmt_data8;
  42. u16 dummy13;
  43. u16 xmt_data16;
  44. u16 dummy14;
  45. u16 rcv_data8;
  46. u16 dummy15;
  47. u16 rcv_data16;
  48. u16 dummy16;
  49. };
  50. struct bfin_twi_iface {
  51. int irq;
  52. spinlock_t lock;
  53. char read_write;
  54. u8 command;
  55. u8 *transPtr;
  56. int readNum;
  57. int writeNum;
  58. int cur_mode;
  59. int manual_stop;
  60. int result;
  61. struct i2c_adapter adap;
  62. struct completion complete;
  63. struct i2c_msg *pmsg;
  64. int msg_num;
  65. int cur_msg;
  66. u16 saved_clkdiv;
  67. u16 saved_control;
  68. struct bfin_twi_regs __iomem *regs_base;
  69. };
  70. /* ******************** TWO-WIRE INTERFACE (TWI) MASKS ********************/
  71. /* TWI_CLKDIV Macros (Use: *pTWI_CLKDIV = CLKLOW(x)|CLKHI(y); ) */
  72. #define CLKLOW(x) ((x) & 0xFF) /* Periods Clock Is Held Low */
  73. #define CLKHI(y) (((y)&0xFF)<<0x8) /* Periods Before New Clock Low */
  74. /* TWI_PRESCALE Masks */
  75. #define PRESCALE 0x007F /* SCLKs Per Internal Time Reference (10MHz) */
  76. #define TWI_ENA 0x0080 /* TWI Enable */
  77. #define SCCB 0x0200 /* SCCB Compatibility Enable */
  78. /* TWI_SLAVE_CTL Masks */
  79. #define SEN 0x0001 /* Slave Enable */
  80. #define SADD_LEN 0x0002 /* Slave Address Length */
  81. #define STDVAL 0x0004 /* Slave Transmit Data Valid */
  82. #define NAK 0x0008 /* NAK Generated At Conclusion Of Transfer */
  83. #define GEN 0x0010 /* General Call Address Matching Enabled */
  84. /* TWI_SLAVE_STAT Masks */
  85. #define SDIR 0x0001 /* Slave Transfer Direction (RX/TX*) */
  86. #define GCALL 0x0002 /* General Call Indicator */
  87. /* TWI_MASTER_CTL Masks */
  88. #define MEN 0x0001 /* Master Mode Enable */
  89. #define MADD_LEN 0x0002 /* Master Address Length */
  90. #define MDIR 0x0004 /* Master Transmit Direction (RX/TX*) */
  91. #define FAST 0x0008 /* Use Fast Mode Timing Specs */
  92. #define STOP 0x0010 /* Issue Stop Condition */
  93. #define RSTART 0x0020 /* Repeat Start or Stop* At End Of Transfer */
  94. #define DCNT 0x3FC0 /* Data Bytes To Transfer */
  95. #define SDAOVR 0x4000 /* Serial Data Override */
  96. #define SCLOVR 0x8000 /* Serial Clock Override */
  97. /* TWI_MASTER_STAT Masks */
  98. #define MPROG 0x0001 /* Master Transfer In Progress */
  99. #define LOSTARB 0x0002 /* Lost Arbitration Indicator (Xfer Aborted) */
  100. #define ANAK 0x0004 /* Address Not Acknowledged */
  101. #define DNAK 0x0008 /* Data Not Acknowledged */
  102. #define BUFRDERR 0x0010 /* Buffer Read Error */
  103. #define BUFWRERR 0x0020 /* Buffer Write Error */
  104. #define SDASEN 0x0040 /* Serial Data Sense */
  105. #define SCLSEN 0x0080 /* Serial Clock Sense */
  106. #define BUSBUSY 0x0100 /* Bus Busy Indicator */
  107. /* TWI_INT_SRC and TWI_INT_ENABLE Masks */
  108. #define SINIT 0x0001 /* Slave Transfer Initiated */
  109. #define SCOMP 0x0002 /* Slave Transfer Complete */
  110. #define SERR 0x0004 /* Slave Transfer Error */
  111. #define SOVF 0x0008 /* Slave Overflow */
  112. #define MCOMP 0x0010 /* Master Transfer Complete */
  113. #define MERR 0x0020 /* Master Transfer Error */
  114. #define XMTSERV 0x0040 /* Transmit FIFO Service */
  115. #define RCVSERV 0x0080 /* Receive FIFO Service */
  116. /* TWI_FIFO_CTRL Masks */
  117. #define XMTFLUSH 0x0001 /* Transmit Buffer Flush */
  118. #define RCVFLUSH 0x0002 /* Receive Buffer Flush */
  119. #define XMTINTLEN 0x0004 /* Transmit Buffer Interrupt Length */
  120. #define RCVINTLEN 0x0008 /* Receive Buffer Interrupt Length */
  121. /* TWI_FIFO_STAT Masks */
  122. #define XMTSTAT 0x0003 /* Transmit FIFO Status */
  123. #define XMT_EMPTY 0x0000 /* Transmit FIFO Empty */
  124. #define XMT_HALF 0x0001 /* Transmit FIFO Has 1 Byte To Write */
  125. #define XMT_FULL 0x0003 /* Transmit FIFO Full (2 Bytes To Write) */
  126. #define RCVSTAT 0x000C /* Receive FIFO Status */
  127. #define RCV_EMPTY 0x0000 /* Receive FIFO Empty */
  128. #define RCV_HALF 0x0004 /* Receive FIFO Has 1 Byte To Read */
  129. #define RCV_FULL 0x000C /* Receive FIFO Full (2 Bytes To Read) */
  130. #endif