Lines Matching refs:ops
21 #define SET_SDA(ops, val) ops->set_sda(ops->data, val) argument
22 #define SET_SCL(ops, val) ops->set_scl(ops->data, val) argument
23 #define GET_SDA(ops) ops->get_sda(ops->data) argument
24 #define GET_SCL(ops) ops->get_scl(ops->data) argument
26 rt_inline void i2c_delay(struct rt_i2c_bit_ops *ops) in i2c_delay() argument
28 ops->udelay((ops->delay_us + 1) >> 1); in i2c_delay()
31 rt_inline void i2c_delay2(struct rt_i2c_bit_ops *ops) in i2c_delay2() argument
33 ops->udelay(ops->delay_us); in i2c_delay2()
36 #define SDA_L(ops) SET_SDA(ops, 0) argument
37 #define SDA_H(ops) SET_SDA(ops, 1) argument
38 #define SCL_L(ops) SET_SCL(ops, 0) argument
43 static rt_err_t SCL_H(struct rt_i2c_bit_ops *ops) in SCL_H() argument
47 SET_SCL(ops, 1); in SCL_H()
49 if (!ops->get_scl) in SCL_H()
53 while (!GET_SCL(ops)) in SCL_H()
55 if ((rt_tick_get() - start) > ops->timeout) in SCL_H()
57 i2c_delay(ops); in SCL_H()
68 i2c_delay(ops); in SCL_H()
73 static void i2c_start(struct rt_i2c_bit_ops *ops) in i2c_start() argument
76 if (ops->get_scl && !GET_SCL(ops)) in i2c_start()
80 if (ops->get_sda && !GET_SDA(ops)) in i2c_start()
85 SDA_L(ops); in i2c_start()
86 i2c_delay(ops); in i2c_start()
87 SCL_L(ops); in i2c_start()
90 static void i2c_restart(struct rt_i2c_bit_ops *ops) in i2c_restart() argument
92 SDA_H(ops); in i2c_restart()
93 SCL_H(ops); in i2c_restart()
94 i2c_delay(ops); in i2c_restart()
95 SDA_L(ops); in i2c_restart()
96 i2c_delay(ops); in i2c_restart()
97 SCL_L(ops); in i2c_restart()
100 static void i2c_stop(struct rt_i2c_bit_ops *ops) in i2c_stop() argument
102 SDA_L(ops); in i2c_stop()
103 i2c_delay(ops); in i2c_stop()
104 SCL_H(ops); in i2c_stop()
105 i2c_delay(ops); in i2c_stop()
106 SDA_H(ops); in i2c_stop()
107 i2c_delay2(ops); in i2c_stop()
110 rt_inline rt_bool_t i2c_waitack(struct rt_i2c_bit_ops *ops) in i2c_waitack() argument
114 SDA_H(ops); in i2c_waitack()
115 i2c_delay(ops); in i2c_waitack()
117 if (SCL_H(ops) < 0) in i2c_waitack()
124 ack = !GET_SDA(ops); /* ACK : SDA pin is pulled low */ in i2c_waitack()
127 SCL_L(ops); in i2c_waitack()
137 struct rt_i2c_bit_ops *ops = (struct rt_i2c_bit_ops *)bus->priv; in i2c_writeb() local
141 SCL_L(ops); in i2c_writeb()
143 SET_SDA(ops, bit); in i2c_writeb()
144 i2c_delay(ops); in i2c_writeb()
145 if (SCL_H(ops) < 0) in i2c_writeb()
154 SCL_L(ops); in i2c_writeb()
155 i2c_delay(ops); in i2c_writeb()
157 return i2c_waitack(ops); in i2c_writeb()
164 struct rt_i2c_bit_ops *ops = (struct rt_i2c_bit_ops *)bus->priv; in i2c_readb() local
166 SDA_H(ops); in i2c_readb()
167 i2c_delay(ops); in i2c_readb()
172 if (SCL_H(ops) < 0) in i2c_readb()
180 if (GET_SDA(ops)) in i2c_readb()
182 SCL_L(ops); in i2c_readb()
183 i2c_delay2(ops); in i2c_readb()
227 struct rt_i2c_bit_ops *ops = (struct rt_i2c_bit_ops *)bus->priv; in i2c_send_ack_or_nack() local
230 SET_SDA(ops, 0); in i2c_send_ack_or_nack()
231 i2c_delay(ops); in i2c_send_ack_or_nack()
232 if (SCL_H(ops) < 0) in i2c_send_ack_or_nack()
238 SCL_L(ops); in i2c_send_ack_or_nack()
287 struct rt_i2c_bit_ops *ops = (struct rt_i2c_bit_ops *)bus->priv; in i2c_send_address() local
297 i2c_stop(ops); in i2c_send_address()
298 i2c_delay2(ops); in i2c_send_address()
300 i2c_start(ops); in i2c_send_address()
311 struct rt_i2c_bit_ops *ops = (struct rt_i2c_bit_ops *)bus->priv; in i2c_bit_send_address() local
344 i2c_restart(ops); in i2c_bit_send_address()
374 struct rt_i2c_bit_ops *ops = (struct rt_i2c_bit_ops *)bus->priv; in i2c_bit_xfer() local
379 if((ops->i2c_pin_init_flag == RT_FALSE) && (ops->pin_init != RT_NULL)) in i2c_bit_xfer()
381 ops->pin_init(); in i2c_bit_xfer()
382 ops->i2c_pin_init_flag = RT_TRUE; in i2c_bit_xfer()
395 i2c_restart(ops); in i2c_bit_xfer()
400 i2c_start(ops); in i2c_bit_xfer()
445 i2c_stop(ops); in i2c_bit_xfer()
461 bus->ops = &i2c_bit_bus_ops; in rt_i2c_bit_add_bus()