i2c-keywest.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #ifndef __I2C_KEYWEST_H__
  2. #define __I2C_KEYWEST_H__
  3. /* The Tumbler audio equalizer can be really slow sometimes */
  4. #define POLL_TIMEOUT (2*HZ)
  5. /* Register indices */
  6. typedef enum {
  7. reg_mode = 0,
  8. reg_control,
  9. reg_status,
  10. reg_isr,
  11. reg_ier,
  12. reg_addr,
  13. reg_subaddr,
  14. reg_data
  15. } reg_t;
  16. /* Mode register */
  17. #define KW_I2C_MODE_100KHZ 0x00
  18. #define KW_I2C_MODE_50KHZ 0x01
  19. #define KW_I2C_MODE_25KHZ 0x02
  20. #define KW_I2C_MODE_DUMB 0x00
  21. #define KW_I2C_MODE_STANDARD 0x04
  22. #define KW_I2C_MODE_STANDARDSUB 0x08
  23. #define KW_I2C_MODE_COMBINED 0x0C
  24. #define KW_I2C_MODE_MODE_MASK 0x0C
  25. #define KW_I2C_MODE_CHAN_MASK 0xF0
  26. /* Control register */
  27. #define KW_I2C_CTL_AAK 0x01
  28. #define KW_I2C_CTL_XADDR 0x02
  29. #define KW_I2C_CTL_STOP 0x04
  30. #define KW_I2C_CTL_START 0x08
  31. /* Status register */
  32. #define KW_I2C_STAT_BUSY 0x01
  33. #define KW_I2C_STAT_LAST_AAK 0x02
  34. #define KW_I2C_STAT_LAST_RW 0x04
  35. #define KW_I2C_STAT_SDA 0x08
  36. #define KW_I2C_STAT_SCL 0x10
  37. /* IER & ISR registers */
  38. #define KW_I2C_IRQ_DATA 0x01
  39. #define KW_I2C_IRQ_ADDR 0x02
  40. #define KW_I2C_IRQ_STOP 0x04
  41. #define KW_I2C_IRQ_START 0x08
  42. #define KW_I2C_IRQ_MASK 0x0F
  43. /* Physical interface */
  44. struct keywest_iface
  45. {
  46. struct device_node *node;
  47. void __iomem * base;
  48. unsigned bsteps;
  49. int irq;
  50. spinlock_t lock;
  51. struct keywest_chan *channels;
  52. unsigned chan_count;
  53. u8 cur_mode;
  54. char read_write;
  55. u8 *data;
  56. unsigned datalen;
  57. int state;
  58. int result;
  59. struct timer_list timeout_timer;
  60. struct completion complete;
  61. };
  62. enum {
  63. state_idle,
  64. state_addr,
  65. state_read,
  66. state_write,
  67. state_stop,
  68. state_dead
  69. };
  70. /* Channel on an interface */
  71. struct keywest_chan
  72. {
  73. struct i2c_adapter adapter;
  74. struct keywest_iface* iface;
  75. unsigned chan_no;
  76. };
  77. /* Register access */
  78. static inline u8 __read_reg(struct keywest_iface *iface, reg_t reg)
  79. {
  80. return in_8(iface->base
  81. + (((unsigned)reg) << iface->bsteps));
  82. }
  83. static inline void __write_reg(struct keywest_iface *iface, reg_t reg, u8 val)
  84. {
  85. out_8(iface->base
  86. + (((unsigned)reg) << iface->bsteps), val);
  87. (void)__read_reg(iface, reg_subaddr);
  88. }
  89. #define write_reg(reg, val) __write_reg(iface, reg, val)
  90. #define read_reg(reg) __read_reg(iface, reg)
  91. #endif /* __I2C_KEYWEST_H__ */