/* * Copyright 2012 Red Hat Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial busions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. * * Authors: Ben Skeggs
*/ #include"bus.h"
nvkm_i2c_drive_scl(bus, 1); do {
nvkm_i2c_delay(bus, T_RISEFALL);
} while (!nvkm_i2c_sense_scl(bus) && --timeout);
return timeout != 0;
}
staticint
i2c_start(struct nvkm_i2c_bus *bus)
{ int ret = 0;
if (!nvkm_i2c_sense_scl(bus) ||
!nvkm_i2c_sense_sda(bus)) {
nvkm_i2c_drive_scl(bus, 0);
nvkm_i2c_drive_sda(bus, 1); if (!nvkm_i2c_raise_scl(bus))
ret = -EBUSY;
}
staticint
nvkm_i2c_get_byte(struct nvkm_i2c_bus *bus, u8 *byte, bool last)
{ int i, bit;
*byte = 0; for (i = 7; i >= 0; i--) {
bit = i2c_bitr(bus); if (bit < 0) return bit;
*byte |= bit << i;
}
return i2c_bitw(bus, last ? 1 : 0);
}
staticint
nvkm_i2c_put_byte(struct nvkm_i2c_bus *bus, u8 byte)
{ int i, ret; for (i = 7; i >= 0; i--) {
ret = i2c_bitw(bus, !!(byte & (1 << i))); if (ret < 0) return ret;
}
ret = i2c_bitr(bus); if (ret == 1) /* nack */
ret = -EIO; return ret;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.