drv_i2c_main.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. #ifndef _DRV_I2C_MAIN_H_
  2. #define _DRV_I2C_MAIN_H_
  3. #include <linux/module.h>
  4. //#include <linux/devfs_fs_kernel.h>
  5. #include <linux/cdev.h>
  6. #include <linux/kernel.h>
  7. #include <linux/fs.h>
  8. #include <linux/ioctl.h>
  9. #include <linux/delay.h>
  10. #include <linux/interrupt.h>
  11. #include <linux/semaphore.h>
  12. #include <linux/workqueue.h>
  13. #include <asm/io.h>
  14. #include <drv_i2c.h>
  15. #include <drv_debug.h>
  16. typedef void * PVOID;
  17. #define I2C_SOFTWARE_MODE_MASTER 1
  18. #define I2C_HARDWARE_MODE_MASTER 2
  19. #define I2C_MODE I2C_HARDWARE_MODE_MASTER
  20. /*******************************************************************************
  21. *******************************************************************************/
  22. #ifdef INIT_BY_KMF
  23. #define DebugPrint(fmt,args...) do{if(*pdbgconf1&DBGCFG_I2C) printk(KERN_DEBUG "[I2C]" fmt "\n",## args);}while(0)
  24. #define DbgFunPrint(fmt,args...) do{if(*pdbgconf1&DBGCFG_I2C) printk(KERN_DEBUG "[I2C]%s %i: " fmt "\n",__FUNCTION__,__LINE__,## args);}while(0)
  25. #else
  26. #define DebugPrint(fmt,args...) printk(KERN_NOTICE "[I2C]" fmt "\n",## args)
  27. #define DbgFunPrint(fmt,args...) printk(KERN_NOTICE "[I2C]%s %i: " fmt "\n",__FUNCTION__,__LINE__,## args)
  28. #endif
  29. static inline INT32 cmd_list_is_last(const struct list_head *list,
  30. const struct list_head *head)
  31. {
  32. return list->next == head;
  33. }
  34. #define MmioWriteFun(Address,Data) writel(Data,(void *)(Address))
  35. #define MmioReadFun(Address) readl((void *)(Address))
  36. #define MmioWriteWordFun(Address,Data) writew(Data,(void *)(Address))
  37. #define MmioReadWordFun(Address) readw((void *)(Address))
  38. #define mReadByteFun(Address) readb((void *)(Address))
  39. #define mWriteByteFun(Address,Data) writeb(Data,(void *)(Address))
  40. #define INTERRUPT_ENABLE 1
  41. #define ONE_BYTE_INTERRUPT 0
  42. #define SOFTWARE_MODE_MASTER 0
  43. #define MASTER_A_IRQ_FINAL 58
  44. #define MASTER_B_IRQ_FINAL 57
  45. #define STATUS_SUCCESS 0
  46. #define STATUS_DEVICE_ID_ERROR 1
  47. #define STATUS_DATA_ERROR 2
  48. #define STATUS_SYSTEM_ERROR 3
  49. #define M0_CONTROL0 0xBE070000
  50. #define M0_CONTROL1 0xBE070004
  51. #define M0_DATA0 0xBE070008
  52. #define M0_DATA1 0xBE07000C
  53. #define M0_BASE_ADDRESS 0xBE070064
  54. #define M0_DATA_LENGTH 0xBE07006C
  55. #define M0_BUS_STATUS 0xBE070010
  56. #define M1_CONTROL0 0xBE110000
  57. #define M1_CONTROL1 0xBE110004
  58. #define M1_DATA0 0xBE110008
  59. #define M1_DATA1 0xBE11000C
  60. #define M1_BASS_ADDRESS 0xBE110064
  61. #define M1_DATA_LENGTH 0xBE11006C
  62. #define M1_BUS_STATUS 0xBE110010
  63. #define MX_CONTROL0_SCL_25K 0x000000c0//0x00000020
  64. #define MX_CONTROL0_SCL_100K 0x00000050//0x00000020
  65. #define MX_CONTROL0_SCL_400K 0x0000000B//0x0000000D//0x0000800D
  66. #define MX_CONTROL0_SCL_300K 0x00000010
  67. #define MX_CONTROL0_SCL_200K 0x00000017
  68. #define MX_CONTROL0_ASYNC_RESET 0x00020000
  69. #define MX_CONTROL0_MASTER_EN 0x00800000
  70. #define MX_CONTROL0_INT_EN 0x00400000 // Interrupt enable
  71. #define MX_CONTROL0_ONE_BYTE_INT 0x00200000 // One Byte Interrupt
  72. #define MX_CONTROL0_INT 0x04000000 // Interrupt bit
  73. #define MX_CONTROL0_INT_CLEAR 0x08000000 // Interrupt bit clear
  74. #define MX_CONTROL0_NO_ADDRESS 0x10000000 // Without base address
  75. #define MX_CONTROL0_ADDR_INT_DISABLE 0x20000000 // disable base address interrupt
  76. #define MX_CONTROL0_BUSY_WAIT_EN 0x80000000 //20110428 lwhite add
  77. //#define I2C_BUS_STATUS_M0_BUSY 0x01000000
  78. //#define I2C_BUS_STATUS_M1_BUSY 0x02000000
  79. #define I2C_BUS_STATUS_BUSY 0x01000000
  80. #define SW_MASTER0 0xBE070100
  81. #define SW_MASTER1 0xBE070102
  82. #define SW_MASTER_SCL_OUT 0x0001 // Useless
  83. #define SW_MASTER_SDA_OUT 0x0002 // Useless
  84. #define SW_MASTER_SCL_OUT_OEN 0x0004
  85. #define SW_MASTER_SDA_OUT_OEN 0x0008
  86. #define SW_MASTER_SCL_IN 0x0010
  87. #define SW_MASTER_SDA_IN 0x0020
  88. #define SW_MASTER_ENABLE 0x0040
  89. #define SW_MASTER_100K 8 // udelay(8)
  90. #define SW_MASTER_400K 2 // udelay(2)
  91. #define MASTER_NUMBER 2
  92. #define I2C_TIME_OUT (jiffies+HZ/25)
  93. typedef enum
  94. {
  95. I2C_SPIN_LOCK_QUEUE=0,
  96. I2C_SPIN_LOCK_MAX
  97. }I2C_SPIN_LOCK;
  98. #if INTERRUPT_ENABLE
  99. typedef struct _INTERRUPT_INFORMATION_
  100. {
  101. UINT8* pBuffer;
  102. UINT16 Length;
  103. UINT16 Completed;
  104. UINT8 bRead;
  105. }INT_INFO,*PINT_INFO;
  106. #endif
  107. typedef struct _QUEUE_I2C_
  108. {
  109. UINT8 Mx;
  110. UINT8 DeviceID;
  111. UINT8 AddrType;
  112. UINT8 Speed;
  113. UINT32 Address;
  114. struct list_head list;
  115. UINT16 Length;
  116. UINT8 Data[1];
  117. }QUEUE_I2C,*PQUEUE_I2C;
  118. typedef struct _I2C_CMD_LIST_
  119. {
  120. INT8 bRead;
  121. UINT8 Mx;
  122. UINT8 DeviceID;
  123. UINT8 AddrType;
  124. UINT8 Speed;
  125. UINT32 Address;
  126. struct list_head list;
  127. UINT16 Length;
  128. UINT8 Data[1];
  129. }I2C_CMD_LIST,*PI2C_CMD_LIST;
  130. typedef struct _I2C_DEV_
  131. {
  132. struct semaphore I2cMutex[MASTER_NUMBER];
  133. struct semaphore GPIOI2cMutex;
  134. struct semaphore GPIOXI2cMutex;
  135. INT32 InterruptCounter[MASTER_NUMBER];
  136. struct cdev cdev;
  137. #if (I2C_MODE==I2C_HARDWARE_MODE_MASTER) && INTERRUPT_ENABLE
  138. struct completion Comp[MASTER_NUMBER];
  139. //struct timer_list ResetTimer[MASTER_NUMBER];
  140. INT_INFO IntInfo[MASTER_NUMBER];
  141. #endif
  142. UINT8 Status[MASTER_NUMBER];
  143. struct list_head pQueueWriteList;
  144. struct workqueue_struct *i2cWorkQueue;
  145. struct work_struct QueueWork;
  146. spinlock_t Spinlock[I2C_SPIN_LOCK_MAX];
  147. }I2C_DEV,*PI2C_DEV;
  148. #endif // end of #ifndef _DRV_I2C_MAIN_H_