Lines Matching refs:adap

32 #define I2C_HI_CLOCK(adap, ret)                          \
34 ret = i2c_setscl(adap); \
38 i2c_setsda(adap); \
39 i2c_udelay(adap); \
45 i2c_udelay(struct i2c_adapter *adap)
47 udelay((adap->udelay + 1) >> 1);
51 i2c_getsda(struct i2c_adapter *adap)
53 return adap->getsda(adap->data) ? 1 : 0;
57 i2c_clrsda(struct i2c_adapter *adap)
59 adap->setsda(adap->data, 0);
63 i2c_setsda(struct i2c_adapter *adap)
65 adap->setsda(adap->data, 1);
69 i2c_getscl(struct i2c_adapter *adap)
71 return adap->getscl(adap->data) ? 1 : 0;
75 i2c_clrscl(struct i2c_adapter *adap)
77 adap->setscl(adap->data, 0);
81 i2c_setscl(struct i2c_adapter *adap)
85 adap->setscl(adap->data, 1);
89 while (!i2c_getscl(adap)) {
93 if ((ddi_get_lbolt() - start) > adap->timeout)
101 i2c_start(struct i2c_adapter *adap)
106 i2c_setsda(adap);
107 i2c_udelay(adap);
108 ret = i2c_setscl(adap);
115 if (!i2c_getsda(adap)) {
119 i2c_udelay(adap);
122 i2c_clrsda(adap);
123 i2c_udelay(adap);
126 i2c_clrscl(adap);
127 i2c_udelay(adap);
133 i2c_stop(struct i2c_adapter *adap)
137 if (i2c_getscl(adap)) {
146 i2c_clrsda(adap);
147 i2c_udelay(adap);
150 I2C_HI_CLOCK(adap, ret);
151 i2c_udelay(adap);
154 i2c_setsda(adap);
155 i2c_udelay(adap);
156 if (!i2c_getsda(adap)) {
167 i2c_write_byte(struct i2c_adapter *adap, unsigned char c)
172 if (i2c_getscl(adap)) {
184 i2c_setsda(adap);
187 i2c_clrsda(adap);
189 i2c_udelay(adap);
192 I2C_HI_CLOCK(adap, ret);
193 if (needARB && !i2c_getsda(adap)) {
198 i2c_udelay(adap);
199 i2c_udelay(adap);
200 if (needARB && !i2c_getsda(adap)) {
206 i2c_clrscl(adap);
207 i2c_udelay(adap);
214 i2c_read_byte(struct i2c_adapter *adap, unsigned char *cp)
218 if (i2c_getscl(adap)) {
226 i2c_setsda(adap);
227 i2c_udelay(adap);
232 I2C_HI_CLOCK(adap, ret);
233 r = i2c_getsda(adap);
234 i2c_udelay(adap);
237 if (r != i2c_getsda(adap)) {
243 i2c_udelay(adap);
246 i2c_clrscl(adap);
247 i2c_udelay(adap);
254 i2c_ack(struct i2c_adapter *adap)
258 if (i2c_getscl(adap)) {
267 i2c_clrsda(adap);
268 i2c_udelay(adap);
271 I2C_HI_CLOCK(adap, ret);
272 i2c_udelay(adap);
275 i2c_clrscl(adap);
276 i2c_udelay(adap);
282 i2c_no_ack(struct i2c_adapter *adap)
286 if (i2c_getscl(adap)) {
295 i2c_setsda(adap);
296 i2c_udelay(adap);
299 I2C_HI_CLOCK(adap, ret);
300 if (!i2c_getsda(adap)) {
304 i2c_udelay(adap);
305 if (!i2c_getsda(adap)) {
311 i2c_clrscl(adap);
312 i2c_udelay(adap);
318 i2c_wait_ack(struct i2c_adapter *adap)
322 if (i2c_getscl(adap)) {
331 i2c_setsda(adap);
332 i2c_udelay(adap);
335 I2C_HI_CLOCK(adap, ret);
336 i2c_udelay(adap);
339 ret = i2c_getsda(adap) ? 0 : 1;
342 i2c_clrscl(adap);
343 i2c_udelay(adap);
349 i2c_write_msg(struct i2c_adapter *adap, struct i2c_msg *msg)
354 ret = i2c_write_byte(adap, msg->buf[i]);
358 ret = i2c_wait_ack(adap);
371 i2c_read_msg(struct i2c_adapter *adap, struct i2c_msg *msg)
377 ret = i2c_read_byte(adap, &c);
384 ret = i2c_ack(adap);
386 ret = i2c_no_ack(adap);
395 i2c_address(struct i2c_adapter *adap, struct i2c_msg *msg)
404 ret = i2c_write_byte(adap, addr);
408 ret = i2c_wait_ack(adap);
418 i2c_do_transfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
427 ret = i2c_start(adap);
431 ret = i2c_address(adap, msg);
437 ret = i2c_read_msg(adap, msg);
439 ret = i2c_write_msg(adap, msg);
444 ret = i2c_stop(adap);
457 i2c_bit_add_bus(struct i2c_adapter *adap)
459 if (!adap->setscl || !adap->getscl || !adap->setsda || !adap->getsda)
462 adap->algo = (struct i2c_algorithm *)&i2c_bit_algo;
463 adap->retries = 3;
469 i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
474 mutex_enter(&adap->bus_lock);
476 for (i = 0; i <= adap->retries; i++) {
477 ret = adap->algo->master_xfer(adap, msgs, num);
489 if ((ddi_get_lbolt() - start) > adap->timeout)
494 mutex_exit(&adap->bus_lock);