iic.c (682b069c5c5643d26199cc1b65717f99c98bce9d) | iic.c (473c90ac04cec0abbb414978c53e9c259c9129e8) |
---|---|
1/*- 2 * SPDX-License-Identifier: BSD-2-Clause 3 * 4 * Copyright (c) 1998, 2001 Nicolas Souchu 5 * Copyright (c) 2023 Juniper Networks, Inc. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 225 unchanged lines hidden (view full) --- 234 * We can only transfer up to sizeof(buffer) bytes in 1 shot, so loop until 235 * everything has been transferred. 236 */ 237 while ((error == 0) && (uio->uio_resid > 0)) { 238 239 num_bytes = MIN(uio->uio_resid, sizeof(buffer)); 240 transferred_bytes = 0; 241 | 1/*- 2 * SPDX-License-Identifier: BSD-2-Clause 3 * 4 * Copyright (c) 1998, 2001 Nicolas Souchu 5 * Copyright (c) 2023 Juniper Networks, Inc. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 225 unchanged lines hidden (view full) --- 234 * We can only transfer up to sizeof(buffer) bytes in 1 shot, so loop until 235 * everything has been transferred. 236 */ 237 while ((error == 0) && (uio->uio_resid > 0)) { 238 239 num_bytes = MIN(uio->uio_resid, sizeof(buffer)); 240 transferred_bytes = 0; 241 |
242 if (uio->uio_rw == UIO_WRITE) { | 242 switch (uio->uio_rw) { 243 case UIO_WRITE: |
243 error = uiomove(buffer, num_bytes, uio); 244 245 while ((error == 0) && (transferred_bytes < num_bytes)) { 246 written_bytes = 0; 247 error = iicbus_write(parent, &buffer[transferred_bytes], 248 num_bytes - transferred_bytes, &written_bytes, 0); 249 transferred_bytes += written_bytes; 250 } | 244 error = uiomove(buffer, num_bytes, uio); 245 246 while ((error == 0) && (transferred_bytes < num_bytes)) { 247 written_bytes = 0; 248 error = iicbus_write(parent, &buffer[transferred_bytes], 249 num_bytes - transferred_bytes, &written_bytes, 0); 250 transferred_bytes += written_bytes; 251 } |
251 252 } else if (uio->uio_rw == UIO_READ) { | 252 break; 253 case UIO_READ: |
253 error = iicbus_read(parent, buffer, 254 num_bytes, &transferred_bytes, 255 ((uio->uio_resid <= sizeof(buffer)) ? last : 0), 0); 256 if (error == 0) 257 error = uiomove(buffer, transferred_bytes, uio); | 254 error = iicbus_read(parent, buffer, 255 num_bytes, &transferred_bytes, 256 ((uio->uio_resid <= sizeof(buffer)) ? last : 0), 0); 257 if (error == 0) 258 error = uiomove(buffer, transferred_bytes, uio); |
259 break; |
|
258 } 259 } 260 261 return (error); 262} 263 264static int 265iicuio(struct cdev *dev, struct uio *uio, int ioflag) --- 19 unchanged lines hidden (view full) --- 285 286 error = iicbus_request_bus(parent, priv->sc->sc_dev, 287 (ioflag & O_NONBLOCK) ? IIC_DONTWAIT : (IIC_WAIT | IIC_INTR)); 288 if (error != 0) { 289 IIC_UNLOCK(priv); 290 return (error); 291 } 292 | 260 } 261 } 262 263 return (error); 264} 265 266static int 267iicuio(struct cdev *dev, struct uio *uio, int ioflag) --- 19 unchanged lines hidden (view full) --- 287 288 error = iicbus_request_bus(parent, priv->sc->sc_dev, 289 (ioflag & O_NONBLOCK) ? IIC_DONTWAIT : (IIC_WAIT | IIC_INTR)); 290 if (error != 0) { 291 IIC_UNLOCK(priv); 292 return (error); 293 } 294 |
293 if (uio->uio_rw == UIO_READ) | 295 switch (uio->uio_rw) { 296 case UIO_READ: |
294 addr = priv->addr | LSB; | 297 addr = priv->addr | LSB; |
295 else | 298 break; 299 case UIO_WRITE: |
296 addr = priv->addr & ~LSB; | 300 addr = priv->addr & ~LSB; |
301 break; 302 } |
|
297 298 error = iicbus_start(parent, addr, 0); 299 if (error != 0) 300 { 301 iicbus_release_bus(parent, priv->sc->sc_dev); 302 IIC_UNLOCK(priv); 303 return (error); 304 } --- 301 unchanged lines hidden --- | 303 304 error = iicbus_start(parent, addr, 0); 305 if (error != 0) 306 { 307 iicbus_release_bus(parent, priv->sc->sc_dev); 308 IIC_UNLOCK(priv); 309 return (error); 310 } --- 301 unchanged lines hidden --- |