Lines Matching +full:- +full:b
6 * (c) 1998 Gerd Knorr <kraxel@cs.tu-berlin.de>
10 #include <xorg-config.h>
46 I2CUDelay(I2CBusPtr b, int usec) in I2CUDelay() argument
59 d_secs = (cur.tv_sec - begin.tv_sec); in I2CUDelay()
60 d_usecs = (cur.tv_usec - begin.tv_usec); in I2CUDelay()
86 I2CRaiseSCL(I2CBusPtr b, int sda, int timeout) in I2CRaiseSCL() argument
90 b->I2CPutBits(b, 1, sda); in I2CRaiseSCL()
91 b->I2CUDelay(b, b->RiseFallTime); in I2CRaiseSCL()
93 for (i = timeout; i > 0; i -= b->RiseFallTime) { in I2CRaiseSCL()
94 b->I2CGetBits(b, &scl, &sda); in I2CRaiseSCL()
97 b->I2CUDelay(b, b->RiseFallTime); in I2CRaiseSCL()
102 ("[I2CRaiseSCL(<%s>, %d, %d) timeout]", b->BusName, sda, in I2CRaiseSCL()
130 I2CStart(I2CBusPtr b, int timeout) in I2CStart() argument
132 if (!I2CRaiseSCL(b, 1, timeout)) in I2CStart()
135 b->I2CPutBits(b, 1, 0); in I2CStart()
136 b->I2CUDelay(b, b->HoldTime); in I2CStart()
137 b->I2CPutBits(b, 0, 0); in I2CStart()
138 b->I2CUDelay(b, b->HoldTime); in I2CStart()
155 I2CBusPtr b = d->pI2CBus; in I2CStop() local
157 b->I2CPutBits(b, 0, 0); in I2CStop()
158 b->I2CUDelay(b, b->RiseFallTime); in I2CStop()
160 b->I2CPutBits(b, 1, 0); in I2CStop()
161 b->I2CUDelay(b, b->HoldTime); in I2CStop()
162 b->I2CPutBits(b, 1, 1); in I2CStop()
163 b->I2CUDelay(b, b->HoldTime); in I2CStop()
173 I2CWriteBit(I2CBusPtr b, int sda, int timeout) in I2CWriteBit() argument
177 b->I2CPutBits(b, 0, sda); in I2CWriteBit()
178 b->I2CUDelay(b, b->RiseFallTime); in I2CWriteBit()
180 r = I2CRaiseSCL(b, sda, timeout); in I2CWriteBit()
181 b->I2CUDelay(b, b->HoldTime); in I2CWriteBit()
183 b->I2CPutBits(b, 0, sda); in I2CWriteBit()
184 b->I2CUDelay(b, b->HoldTime); in I2CWriteBit()
190 I2CReadBit(I2CBusPtr b, int *psda, int timeout) in I2CReadBit() argument
195 r = I2CRaiseSCL(b, 1, timeout); in I2CReadBit()
196 b->I2CUDelay(b, b->HoldTime); in I2CReadBit()
198 b->I2CGetBits(b, &scl, psda); in I2CReadBit()
200 b->I2CPutBits(b, 0, 1); in I2CReadBit()
201 b->I2CUDelay(b, b->HoldTime); in I2CReadBit()
218 * AcknTimeout must be at least b->HoldTime, the other timeouts can be
227 I2CBusPtr b = d->pI2CBus; in I2CPutByte() local
229 if (!I2CWriteBit(b, (data >> 7) & 1, d->ByteTimeout)) in I2CPutByte()
232 for (i = 6; i >= 0; i--) in I2CPutByte()
233 if (!I2CWriteBit(b, (data >> i) & 1, d->BitTimeout)) in I2CPutByte()
236 b->I2CPutBits(b, 0, 1); in I2CPutByte()
237 b->I2CUDelay(b, b->RiseFallTime); in I2CPutByte()
239 r = I2CRaiseSCL(b, 1, b->HoldTime); in I2CPutByte()
242 for (i = d->AcknTimeout; i > 0; i -= b->HoldTime) { in I2CPutByte()
243 b->I2CUDelay(b, b->HoldTime); in I2CPutByte()
244 b->I2CGetBits(b, &scl, &sda); in I2CPutByte()
251 b->BusName, data, d->BitTimeout, in I2CPutByte()
252 d->ByteTimeout, d->AcknTimeout)); in I2CPutByte()
256 I2C_TRACE(ErrorF("W%02x%c ", (int) data, sda ? '-' : '+')); in I2CPutByte()
259 b->I2CPutBits(b, 0, 1); in I2CPutByte()
260 b->I2CUDelay(b, b->HoldTime); in I2CPutByte()
273 * or slows down the bus for more than b->BitTimeout usecs for each bit.
275 * ByteTimeout must be at least b->HoldTime, the other timeouts can be
286 I2CBusPtr b = d->pI2CBus; in I2CGetByte() local
288 b->I2CPutBits(b, 0, 1); in I2CGetByte()
289 b->I2CUDelay(b, b->RiseFallTime); in I2CGetByte()
291 if (!I2CReadBit(b, &sda, d->ByteTimeout)) in I2CGetByte()
296 for (i = 6; i >= 0; i--) in I2CGetByte()
297 if (!I2CReadBit(b, &sda, d->BitTimeout)) in I2CGetByte()
302 if (!I2CWriteBit(b, last ? 1 : 0, d->BitTimeout)) in I2CGetByte()
305 I2C_TRACE(ErrorF("R%02x%c ", (int) *data, last ? '+' : '-')); in I2CGetByte()
312 * It creates the start condition, followed by the d->SlaveAddr.
331 * b) a 'general call address', this is LSB = 0000 000x - see the I2C specs
338 if (I2CStart(d->pI2CBus, d->StartTimeout)) { in I2CAddress()
360 * Don't expect a read- or write-only device will respond otherwise.
364 xf86I2CProbeAddress(I2CBusPtr b, I2CSlaveAddr addr) in xf86I2CProbeAddress() argument
370 d.BitTimeout = b->BitTimeout; in xf86I2CProbeAddress()
371 d.ByteTimeout = b->ByteTimeout; in xf86I2CProbeAddress()
372 d.AcknTimeout = b->AcknTimeout; in xf86I2CProbeAddress()
373 d.StartTimeout = b->StartTimeout; in xf86I2CProbeAddress()
375 d.pI2CBus = b; in xf86I2CProbeAddress()
378 r = b->I2CAddress(&d, addr); in xf86I2CProbeAddress()
381 b->I2CStop(&d); in xf86I2CProbeAddress()
414 I2CBusPtr b = d->pI2CBus; in I2CWriteRead() local
418 r = b->I2CAddress(d, d->SlaveAddr & ~1); in I2CWriteRead()
420 for (; nWrite > 0; WriteBuffer++, nWrite--) in I2CWriteRead()
421 if (!(r = b->I2CPutByte(d, *WriteBuffer))) in I2CWriteRead()
428 r = b->I2CAddress(d, d->SlaveAddr | 1); in I2CWriteRead()
430 for (; nRead > 0; ReadBuffer++, nRead--) in I2CWriteRead()
431 if (!(r = b->I2CGetByte(d, ReadBuffer, nRead == 1))) in I2CWriteRead()
438 b->I2CStop(d); in I2CWriteRead()
443 /* wrapper - for compatibility and convinience */
450 I2CBusPtr b = d->pI2CBus; in xf86I2CWriteRead() local
452 return b->I2CWriteRead(d, WriteBuffer, nWrite, ReadBuffer, nRead); in xf86I2CWriteRead()
464 /* Read a byte from one of the registers determined by its sub-address.
474 * sub-address of the first register.
484 * determined by its sub-address.
500 /* Write a byte to one of the registers determined by its sub-address.
515 * sub-address of the first register.
522 I2CBusPtr b = d->pI2CBus; in xf86I2CWriteBytes() local
526 r = b->I2CAddress(d, d->SlaveAddr & ~1); in xf86I2CWriteBytes()
528 if ((r = b->I2CPutByte(d, subaddr))) in xf86I2CWriteBytes()
529 for (; nWrite > 0; WriteBuffer++, nWrite--) in xf86I2CWriteBytes()
530 if (!(r = b->I2CPutByte(d, *WriteBuffer))) in xf86I2CWriteBytes()
533 b->I2CStop(d); in xf86I2CWriteBytes()
541 * determined by its sub-address.
557 * 1st byte sub-address, 2nd byte value, 3rd byte sub-address asf.
566 I2CBusPtr b = d->pI2CBus; in xf86I2CWriteVec() local
571 for (; nValues > 0; nValues--, vec += 2) { in xf86I2CWriteVec()
572 if (!(r = b->I2CAddress(d, d->SlaveAddr & ~1))) in xf86I2CWriteVec()
577 if (!(r = b->I2CPutByte(d, vec[0]))) in xf86I2CWriteVec()
580 if (!(r = b->I2CPutByte(d, vec[1]))) in xf86I2CWriteVec()
585 b->I2CStop(d); in xf86I2CWriteVec()
617 if (d && d->pI2CBus) { in xf86DestroyI2CDevRec()
622 for (p = &d->pI2CBus->FirstDev; *p != NULL; p = &(*p)->NextDev) in xf86DestroyI2CDevRec()
624 *p = (*p)->NextDev; in xf86DestroyI2CDevRec()
628 xf86DrvMsg(d->pI2CBus->scrnIndex, X_INFO, in xf86DestroyI2CDevRec()
630 d->pI2CBus->BusName, d->DevName); in xf86DestroyI2CDevRec()
647 * the bus-wide defaults. The function returns TRUE on success.
653 I2CBusPtr b; in xf86I2CDevInit() local
656 (b = d->pI2CBus) == NULL || in xf86I2CDevInit()
657 (d->SlaveAddr & 1) || xf86I2CFindDev(b, d->SlaveAddr) != NULL) in xf86I2CDevInit()
660 if (d->BitTimeout <= 0) in xf86I2CDevInit()
661 d->BitTimeout = b->BitTimeout; in xf86I2CDevInit()
662 if (d->ByteTimeout <= 0) in xf86I2CDevInit()
663 d->ByteTimeout = b->ByteTimeout; in xf86I2CDevInit()
664 if (d->AcknTimeout <= 0) in xf86I2CDevInit()
665 d->AcknTimeout = b->AcknTimeout; in xf86I2CDevInit()
666 if (d->StartTimeout <= 0) in xf86I2CDevInit()
667 d->StartTimeout = b->StartTimeout; in xf86I2CDevInit()
669 d->NextDev = b->FirstDev; in xf86I2CDevInit()
670 b->FirstDev = d; in xf86I2CDevInit()
672 xf86DrvMsg(b->scrnIndex, X_INFO, in xf86I2CDevInit()
674 b->BusName, d->DevName, d->SlaveAddr); in xf86I2CDevInit()
680 xf86I2CFindDev(I2CBusPtr b, I2CSlaveAddr addr) in xf86I2CFindDev() argument
684 if (b) { in xf86I2CFindDev()
685 for (d = b->FirstDev; d != NULL; d = d->NextDev) in xf86I2CFindDev()
686 if (d->SlaveAddr == addr) in xf86I2CFindDev()
697 * contain at least a BusName, a scrnIndex (or -1), and a complete set
699 * bus-wide timeouts, otherwise inplausible values will be replaced
706 I2CBusPtr b; in xf86CreateI2CBusRec() local
708 b = (I2CBusPtr) calloc(1, sizeof(I2CBusRec)); in xf86CreateI2CBusRec()
710 if (b != NULL) { in xf86CreateI2CBusRec()
711 b->scrnIndex = -1; in xf86CreateI2CBusRec()
712 b->pScrn = NULL; in xf86CreateI2CBusRec()
713 b->HoldTime = 5; /* 100 kHz bus */ in xf86CreateI2CBusRec()
714 b->BitTimeout = 5; in xf86CreateI2CBusRec()
715 b->ByteTimeout = 5; in xf86CreateI2CBusRec()
716 b->AcknTimeout = 5; in xf86CreateI2CBusRec()
717 b->StartTimeout = 5; in xf86CreateI2CBusRec()
718 b->RiseFallTime = RISEFALLTIME; in xf86CreateI2CBusRec()
721 return b; in xf86CreateI2CBusRec()
731 xf86DestroyI2CBusRec(I2CBusPtr b, Bool unalloc, Bool devs_too) in xf86DestroyI2CBusRec() argument
733 if (b) { in xf86DestroyI2CBusRec()
738 for (p = &I2CBusList; *p != NULL; p = &(*p)->NextBus) in xf86DestroyI2CBusRec()
739 if (*p == b) { in xf86DestroyI2CBusRec()
740 *p = (*p)->NextBus; in xf86DestroyI2CBusRec()
744 if (b->FirstDev != NULL) { in xf86DestroyI2CBusRec()
748 while ((d = b->FirstDev) != NULL) { in xf86DestroyI2CBusRec()
749 b->FirstDev = d->NextDev; in xf86DestroyI2CBusRec()
757 "but device list is not empty.\n", b->BusName); in xf86DestroyI2CBusRec()
763 xf86DrvMsg(b->scrnIndex, X_INFO, "I2C bus \"%s\" removed.\n", in xf86DestroyI2CBusRec()
764 b->BusName); in xf86DestroyI2CBusRec()
767 free(b); in xf86DestroyI2CBusRec()
780 xf86I2CBusInit(I2CBusPtr b) in xf86I2CBusInit() argument
787 if (b->BusName == NULL || xf86I2CFindBus(b->scrnIndex, b->BusName) != NULL) in xf86I2CBusInit()
792 * In this case we need the low-level in xf86I2CBusInit()
795 if (b->I2CWriteRead == NULL) { in xf86I2CBusInit()
796 b->I2CWriteRead = I2CWriteRead; in xf86I2CBusInit()
798 if (b->I2CPutBits == NULL || b->I2CGetBits == NULL) { in xf86I2CBusInit()
799 if (b->I2CPutByte == NULL || in xf86I2CBusInit()
800 b->I2CGetByte == NULL || in xf86I2CBusInit()
801 b->I2CAddress == NULL || in xf86I2CBusInit()
802 b->I2CStart == NULL || b->I2CStop == NULL) in xf86I2CBusInit()
806 b->I2CPutByte = I2CPutByte; in xf86I2CBusInit()
807 b->I2CGetByte = I2CGetByte; in xf86I2CBusInit()
808 b->I2CAddress = I2CAddress; in xf86I2CBusInit()
809 b->I2CStop = I2CStop; in xf86I2CBusInit()
810 b->I2CStart = I2CStart; in xf86I2CBusInit()
814 if (b->I2CUDelay == NULL) in xf86I2CBusInit()
815 b->I2CUDelay = I2CUDelay; in xf86I2CBusInit()
817 if (b->HoldTime < 2) in xf86I2CBusInit()
818 b->HoldTime = 5; in xf86I2CBusInit()
819 if (b->BitTimeout <= 0) in xf86I2CBusInit()
820 b->BitTimeout = b->HoldTime; in xf86I2CBusInit()
821 if (b->ByteTimeout <= 0) in xf86I2CBusInit()
822 b->ByteTimeout = b->HoldTime; in xf86I2CBusInit()
823 if (b->AcknTimeout <= 0) in xf86I2CBusInit()
824 b->AcknTimeout = b->HoldTime; in xf86I2CBusInit()
825 if (b->StartTimeout <= 0) in xf86I2CBusInit()
826 b->StartTimeout = b->HoldTime; in xf86I2CBusInit()
830 b->NextBus = I2CBusList; in xf86I2CBusInit()
831 I2CBusList = b; in xf86I2CBusInit()
833 xf86DrvMsg(b->scrnIndex, X_INFO, "I2C bus \"%s\" initialized.\n", in xf86I2CBusInit()
834 b->BusName); in xf86I2CBusInit()
845 for (p = I2CBusList; p != NULL; p = p->NextBus) in xf86I2CFindBus()
846 if (scrnIndex < 0 || p->scrnIndex == scrnIndex) in xf86I2CFindBus()
847 if (!strcmp(p->BusName, name)) in xf86I2CFindBus()
866 for (pI2CBus = I2CBusList; pI2CBus; pI2CBus = pI2CBus->NextBus) { in xf86I2CGetScreenBuses()
867 if ((pI2CBus->scrnIndex >= 0) && (pI2CBus->scrnIndex != scrnIndex)) in xf86I2CGetScreenBuses()
876 (*pppI2CBus)[n - 1] = pI2CBus; in xf86I2CGetScreenBuses()