1/*- 2 * Copyright (c) 1998 Nicolas Souchu 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 11 unchanged lines hidden (view full) --- 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> |
28__FBSDID("$FreeBSD: head/sys/dev/iicbus/iiconf.c 289097 2015-10-09 23:58:19Z ian $"); |
29 30#include <sys/param.h> 31#include <sys/systm.h> 32#include <sys/lock.h> 33#include <sys/malloc.h> 34#include <sys/module.h> 35#include <sys/mutex.h> 36#include <sys/bus.h> --- 165 unchanged lines hidden (view full) --- 202 */ 203int 204iicbus_start(device_t bus, u_char slave, int timeout) 205{ 206 struct iicbus_softc *sc = (struct iicbus_softc *)device_get_softc(bus); 207 int error = 0; 208 209 if (sc->started) |
210 return (IIC_ESTATUS); /* protocol error, bus already started */ |
211 212 if (!(error = IICBUS_START(device_get_parent(bus), slave, timeout))) 213 sc->started = slave; 214 else 215 sc->started = 0; 216 217 return (error); 218} --- 5 unchanged lines hidden (view full) --- 224 */ 225int 226iicbus_repeated_start(device_t bus, u_char slave, int timeout) 227{ 228 struct iicbus_softc *sc = (struct iicbus_softc *)device_get_softc(bus); 229 int error = 0; 230 231 if (!sc->started) |
232 return (IIC_ESTATUS); /* protocol error, bus not started */ |
233 234 if (!(error = IICBUS_REPEATED_START(device_get_parent(bus), slave, timeout))) 235 sc->started = slave; 236 else 237 sc->started = 0; 238 239 return (error); 240} --- 5 unchanged lines hidden (view full) --- 246 */ 247int 248iicbus_stop(device_t bus) 249{ 250 struct iicbus_softc *sc = (struct iicbus_softc *)device_get_softc(bus); 251 int error = 0; 252 253 if (!sc->started) |
254 return (IIC_ESTATUS); /* protocol error, bus not started */ |
255 256 error = IICBUS_STOP(device_get_parent(bus)); 257 258 /* refuse any further access */ 259 sc->started = 0; 260 261 return (error); 262} --- 6 unchanged lines hidden (view full) --- 269 */ 270int 271iicbus_write(device_t bus, const char *buf, int len, int *sent, int timeout) 272{ 273 struct iicbus_softc *sc = (struct iicbus_softc *)device_get_softc(bus); 274 275 /* a slave must have been started for writing */ 276 if (sc->started == 0 || (sc->strict != 0 && (sc->started & LSB) != 0)) |
277 return (IIC_ESTATUS); |
278 279 return (IICBUS_WRITE(device_get_parent(bus), buf, len, sent, timeout)); 280} 281 282/* 283 * iicbus_read() 284 * 285 * Read a block of data from the slave previously started by 286 * iicbus_read() call 287 */ 288int 289iicbus_read(device_t bus, char *buf, int len, int *read, int last, int delay) 290{ 291 struct iicbus_softc *sc = (struct iicbus_softc *)device_get_softc(bus); 292 293 /* a slave must have been started for reading */ 294 if (sc->started == 0 || (sc->strict != 0 && (sc->started & LSB) == 0)) |
295 return (IIC_ESTATUS); |
296 297 return (IICBUS_READ(device_get_parent(bus), buf, len, read, last, delay)); 298} 299 300/* 301 * iicbus_write_byte() 302 * 303 * Write a byte to the slave previously started by iicbus_start() call 304 */ 305int 306iicbus_write_byte(device_t bus, char byte, int timeout) 307{ |
308 struct iicbus_softc *sc = device_get_softc(bus); |
309 char data = byte; 310 int sent; 311 |
312 /* a slave must have been started for writing */ 313 if (sc->started == 0 || (sc->strict != 0 && (sc->started & LSB) != 0)) 314 return (IIC_ESTATUS); 315 |
316 return (iicbus_write(bus, &data, 1, &sent, timeout)); 317} 318 319/* 320 * iicbus_read_byte() 321 * 322 * Read a byte from the slave previously started by iicbus_start() call 323 */ 324int 325iicbus_read_byte(device_t bus, char *byte, int timeout) 326{ |
327 struct iicbus_softc *sc = device_get_softc(bus); |
328 int read; 329 |
330 /* a slave must have been started for reading */ 331 if (sc->started == 0 || (sc->strict != 0 && (sc->started & LSB) == 0)) 332 return (IIC_ESTATUS); 333 |
334 return (iicbus_read(bus, byte, 1, &read, IIC_LAST_READ, timeout)); 335} 336 337/* 338 * iicbus_block_write() 339 * 340 * Write a block of data to slave ; start/stop protocol managed 341 */ --- 44 unchanged lines hidden (view full) --- 386 * transfers at a low level. 387 * 388 * Pointers passed in as part of iic_msg must be kernel pointers. 389 * Callers that have user addresses to manage must do so on their own. 390 */ 391int 392iicbus_transfer(device_t bus, struct iic_msg *msgs, uint32_t nmsgs) 393{ |
394 |
395 return (IICBUS_TRANSFER(device_get_parent(bus), msgs, nmsgs)); 396} 397 398/* 399 * Generic version of iicbus_transfer that calls the appropriate 400 * routines to accomplish this. See note above about acceptable 401 * buffer addresses. 402 */ 403int 404iicbus_transfer_gen(device_t dev, struct iic_msg *msgs, uint32_t nmsgs) 405{ 406 int i, error, lenread, lenwrote, nkid, rpstart, addr; 407 device_t *children, bus; 408 bool nostop; 409 410 if ((error = device_get_children(dev, &children, &nkid)) != 0) |
411 return (IIC_ERESOURCE); |
412 if (nkid != 1) { 413 free(children, M_TEMP); |
414 return (IIC_ENOTSUPP); |
415 } 416 bus = children[0]; 417 rpstart = 0; 418 free(children, M_TEMP); 419 nostop = iicbus_get_nostop(dev); 420 for (i = 0, error = 0; i < nmsgs && error == 0; i++) { 421 addr = msgs[i].slave; 422 if (msgs[i].flags & IIC_M_RD) --- 34 unchanged lines hidden --- |