iicsmb.c (38775) | iicsmb.c (40782) |
---|---|
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 --- 9 unchanged lines hidden (view full) --- 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 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 * | 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 --- 9 unchanged lines hidden (view full) --- 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 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 * $Id: iicsmb.c,v 1.1.2.2 1998/08/13 17:10:44 son Exp $ | 26 * $Id: iicsmb.c,v 1.1.1.1 1998/09/03 20:51:50 nsouch Exp $ |
27 * 28 */ 29 30/* 31 * I2C to SMB bridge | 27 * 28 */ 29 30/* 31 * I2C to SMB bridge |
32 * 33 * Example: 34 * 35 * smb bttv 36 * \ / 37 * smbus 38 * / \ 39 * iicsmb bti2c 40 * | 41 * iicbus 42 * / | \ 43 * iicbb pcf ... 44 * | 45 * lpbb |
|
32 */ 33 34#include <sys/param.h> 35#include <sys/kernel.h> 36#include <sys/systm.h> 37#include <sys/module.h> 38#include <sys/bus.h> 39#include <sys/conf.h> --- 27 unchanged lines hidden (view full) --- 67 device_t smbus; 68}; 69 70static int iicsmb_probe(device_t); 71static int iicsmb_attach(device_t); 72static void iicsmb_print_child(device_t, device_t); 73 74static void iicsmb_intr(device_t dev, int event, char *buf); | 46 */ 47 48#include <sys/param.h> 49#include <sys/kernel.h> 50#include <sys/systm.h> 51#include <sys/module.h> 52#include <sys/bus.h> 53#include <sys/conf.h> --- 27 unchanged lines hidden (view full) --- 81 device_t smbus; 82}; 83 84static int iicsmb_probe(device_t); 85static int iicsmb_attach(device_t); 86static void iicsmb_print_child(device_t, device_t); 87 88static void iicsmb_intr(device_t dev, int event, char *buf); |
89static int iicsmb_callback(device_t dev, int index, caddr_t data); |
|
75static int iicsmb_quick(device_t dev, u_char slave, int how); 76static int iicsmb_sendb(device_t dev, u_char slave, char byte); 77static int iicsmb_recvb(device_t dev, u_char slave, char *byte); 78static int iicsmb_writeb(device_t dev, u_char slave, char cmd, char byte); 79static int iicsmb_writew(device_t dev, u_char slave, char cmd, short word); 80static int iicsmb_readb(device_t dev, u_char slave, char cmd, char *byte); 81static int iicsmb_readw(device_t dev, u_char slave, char cmd, short *word); 82static int iicsmb_pcall(device_t dev, u_char slave, char cmd, short sdata, short *rdata); --- 9 unchanged lines hidden (view full) --- 92 93 /* bus interface */ 94 DEVMETHOD(bus_print_child, iicsmb_print_child), 95 96 /* iicbus interface */ 97 DEVMETHOD(iicbus_intr, iicsmb_intr), 98 99 /* smbus interface */ | 90static int iicsmb_quick(device_t dev, u_char slave, int how); 91static int iicsmb_sendb(device_t dev, u_char slave, char byte); 92static int iicsmb_recvb(device_t dev, u_char slave, char *byte); 93static int iicsmb_writeb(device_t dev, u_char slave, char cmd, char byte); 94static int iicsmb_writew(device_t dev, u_char slave, char cmd, short word); 95static int iicsmb_readb(device_t dev, u_char slave, char cmd, char *byte); 96static int iicsmb_readw(device_t dev, u_char slave, char cmd, short *word); 97static int iicsmb_pcall(device_t dev, u_char slave, char cmd, short sdata, short *rdata); --- 9 unchanged lines hidden (view full) --- 107 108 /* bus interface */ 109 DEVMETHOD(bus_print_child, iicsmb_print_child), 110 111 /* iicbus interface */ 112 DEVMETHOD(iicbus_intr, iicsmb_intr), 113 114 /* smbus interface */ |
115 DEVMETHOD(smbus_callback, iicsmb_callback), |
|
100 DEVMETHOD(smbus_quick, iicsmb_quick), 101 DEVMETHOD(smbus_sendb, iicsmb_sendb), 102 DEVMETHOD(smbus_recvb, iicsmb_recvb), 103 DEVMETHOD(smbus_writeb, iicsmb_writeb), 104 DEVMETHOD(smbus_writew, iicsmb_writew), 105 DEVMETHOD(smbus_readb, iicsmb_readb), 106 DEVMETHOD(smbus_readw, iicsmb_readw), 107 DEVMETHOD(smbus_pcall, iicsmb_pcall), --- 110 unchanged lines hidden (view full) --- 218 default: 219 panic("%s: unknown event (%d)!", __FUNCTION__, event); 220 } 221 222 return; 223} 224 225static int | 116 DEVMETHOD(smbus_quick, iicsmb_quick), 117 DEVMETHOD(smbus_sendb, iicsmb_sendb), 118 DEVMETHOD(smbus_recvb, iicsmb_recvb), 119 DEVMETHOD(smbus_writeb, iicsmb_writeb), 120 DEVMETHOD(smbus_writew, iicsmb_writew), 121 DEVMETHOD(smbus_readb, iicsmb_readb), 122 DEVMETHOD(smbus_readw, iicsmb_readw), 123 DEVMETHOD(smbus_pcall, iicsmb_pcall), --- 110 unchanged lines hidden (view full) --- 234 default: 235 panic("%s: unknown event (%d)!", __FUNCTION__, event); 236 } 237 238 return; 239} 240 241static int |
242iicsmb_callback(device_t dev, int index, caddr_t data) 243{ 244 device_t parent = device_get_parent(dev); 245 int error = 0; 246 int how; 247 248 switch (index) { 249 case SMB_REQUEST_BUS: 250 /* request underlying iicbus */ 251 how = *(int *)data; 252 error = iicbus_request_bus(parent, dev, how); 253 break; 254 255 case SMB_RELEASE_BUS: 256 /* release underlying iicbus */ 257 error = iicbus_release_bus(parent, dev); 258 break; 259 260 default: 261 error = EINVAL; 262 } 263 264 return (error); 265} 266 267static int |
|
226iicsmb_quick(device_t dev, u_char slave, int how) 227{ 228 device_t parent = device_get_parent(dev); 229 int error; 230 231 switch (how) { 232 case SMB_QWRITE: | 268iicsmb_quick(device_t dev, u_char slave, int how) 269{ 270 device_t parent = device_get_parent(dev); 271 int error; 272 273 switch (how) { 274 case SMB_QWRITE: |
233 error = iicbus_start(parent, slave & ~LSB); | 275 error = iicbus_start(parent, slave & ~LSB, 0); |
234 break; 235 236 case SMB_QREAD: | 276 break; 277 278 case SMB_QREAD: |
237 error = iicbus_start(parent, slave | LSB); | 279 error = iicbus_start(parent, slave | LSB, 0); |
238 break; 239 240 default: 241 error = EINVAL; 242 break; 243 } 244 245 if (!error) 246 error = iicbus_stop(parent); 247 248 return (error); 249} 250 251static int 252iicsmb_sendb(device_t dev, u_char slave, char byte) 253{ 254 device_t parent = device_get_parent(dev); 255 int error, sent; 256 | 280 break; 281 282 default: 283 error = EINVAL; 284 break; 285 } 286 287 if (!error) 288 error = iicbus_stop(parent); 289 290 return (error); 291} 292 293static int 294iicsmb_sendb(device_t dev, u_char slave, char byte) 295{ 296 device_t parent = device_get_parent(dev); 297 int error, sent; 298 |
257 error = iicbus_start(parent, slave & ~LSB); | 299 error = iicbus_start(parent, slave & ~LSB, 0); |
258 259 if (!error) { | 300 301 if (!error) { |
260 error = iicbus_write(parent, &byte, 1, &sent); | 302 error = iicbus_write(parent, &byte, 1, &sent, 0); |
261 262 iicbus_stop(parent); 263 } 264 265 return (error); 266} 267 268static int 269iicsmb_recvb(device_t dev, u_char slave, char *byte) 270{ 271 device_t parent = device_get_parent(dev); 272 int error, read; 273 | 303 304 iicbus_stop(parent); 305 } 306 307 return (error); 308} 309 310static int 311iicsmb_recvb(device_t dev, u_char slave, char *byte) 312{ 313 device_t parent = device_get_parent(dev); 314 int error, read; 315 |
274 error = iicbus_start(parent, slave | LSB); | 316 error = iicbus_start(parent, slave | LSB, 0); |
275 | 317 |
276 if (!error) 277 error = iicbus_read(parent, byte, 1, &read); | 318 if (!error) { 319 error = iicbus_read(parent, byte, 1, &read, IIC_LAST_READ, 0); |
278 | 320 |
321 iicbus_stop(parent); 322 } 323 |
|
279 return (error); 280} 281 282static int 283iicsmb_writeb(device_t dev, u_char slave, char cmd, char byte) 284{ 285 device_t parent = device_get_parent(dev); 286 int error, sent; 287 | 324 return (error); 325} 326 327static int 328iicsmb_writeb(device_t dev, u_char slave, char cmd, char byte) 329{ 330 device_t parent = device_get_parent(dev); 331 int error, sent; 332 |
288 error = iicbus_start(parent, slave & ~LSB); | 333 error = iicbus_start(parent, slave & ~LSB, 0); |
289 290 if (!error) { | 334 335 if (!error) { |
291 if (!(error = iicbus_write(parent, &cmd, 1, &sent))) 292 error = iicbus_write(parent, &byte, 1, &sent); | 336 if (!(error = iicbus_write(parent, &cmd, 1, &sent, 0))) 337 error = iicbus_write(parent, &byte, 1, &sent, 0); |
293 294 iicbus_stop(parent); 295 } 296 297 return (error); 298} 299 300static int 301iicsmb_writew(device_t dev, u_char slave, char cmd, short word) 302{ 303 device_t parent = device_get_parent(dev); 304 int error, sent; 305 306 char low = (char)(word & 0xff); 307 char high = (char)((word & 0xff00) >> 8); 308 | 338 339 iicbus_stop(parent); 340 } 341 342 return (error); 343} 344 345static int 346iicsmb_writew(device_t dev, u_char slave, char cmd, short word) 347{ 348 device_t parent = device_get_parent(dev); 349 int error, sent; 350 351 char low = (char)(word & 0xff); 352 char high = (char)((word & 0xff00) >> 8); 353 |
309 error = iicbus_start(parent, slave & ~LSB); | 354 error = iicbus_start(parent, slave & ~LSB, 0); |
310 311 if (!error) { | 355 356 if (!error) { |
312 if (!(error = iicbus_write(parent, &cmd, 1, &sent))) 313 if (!(error = iicbus_write(parent, &low, 1, &sent))) 314 error = iicbus_write(parent, &high, 1, &sent); | 357 if (!(error = iicbus_write(parent, &cmd, 1, &sent, 0))) 358 if (!(error = iicbus_write(parent, &low, 1, &sent, 0))) 359 error = iicbus_write(parent, &high, 1, &sent, 0); |
315 316 iicbus_stop(parent); 317 } 318 319 return (error); 320} 321 322static int 323iicsmb_readb(device_t dev, u_char slave, char cmd, char *byte) 324{ 325 device_t parent = device_get_parent(dev); 326 int error, sent, read; 327 | 360 361 iicbus_stop(parent); 362 } 363 364 return (error); 365} 366 367static int 368iicsmb_readb(device_t dev, u_char slave, char cmd, char *byte) 369{ 370 device_t parent = device_get_parent(dev); 371 int error, sent, read; 372 |
328 if ((error = iicbus_start(parent, slave & ~LSB))) 329 goto error; | 373 if ((error = iicbus_start(parent, slave & ~LSB, 0))) 374 return (error); |
330 | 375 |
331 if ((error = iicbus_write(parent, &cmd, 1, &sent))) | 376 if ((error = iicbus_write(parent, &cmd, 1, &sent, 0))) |
332 goto error; 333 | 377 goto error; 378 |
334 if ((error = iicbus_repeated_start(parent, slave | LSB))) | 379 if ((error = iicbus_repeated_start(parent, slave | LSB, 0))) |
335 goto error; 336 | 380 goto error; 381 |
337 if ((error = iicbus_read(parent, byte, 1, &read))) | 382 if ((error = iicbus_read(parent, byte, 1, &read, IIC_LAST_READ, 0))) |
338 goto error; 339 340error: | 383 goto error; 384 385error: |
386 iicbus_stop(parent); |
|
341 return (error); 342} 343 344#define BUF2SHORT(low,high) \ 345 ((short)(((high) & 0xff) << 8) | (short)((low) & 0xff)) 346 347static int 348iicsmb_readw(device_t dev, u_char slave, char cmd, short *word) 349{ 350 device_t parent = device_get_parent(dev); 351 int error, sent, read; 352 char buf[2]; 353 | 387 return (error); 388} 389 390#define BUF2SHORT(low,high) \ 391 ((short)(((high) & 0xff) << 8) | (short)((low) & 0xff)) 392 393static int 394iicsmb_readw(device_t dev, u_char slave, char cmd, short *word) 395{ 396 device_t parent = device_get_parent(dev); 397 int error, sent, read; 398 char buf[2]; 399 |
354 if ((error = iicbus_start(parent, slave & ~LSB))) 355 goto error; | 400 if ((error = iicbus_start(parent, slave & ~LSB, 0))) 401 return (error); |
356 | 402 |
357 if ((error = iicbus_write(parent, &cmd, 1, &sent))) | 403 if ((error = iicbus_write(parent, &cmd, 1, &sent, 0))) |
358 goto error; 359 | 404 goto error; 405 |
360 if ((error = iicbus_repeated_start(parent, slave | LSB))) | 406 if ((error = iicbus_repeated_start(parent, slave | LSB, 0))) |
361 goto error; 362 | 407 goto error; 408 |
363 if ((error = iicbus_read(parent, buf, 2, &read))) | 409 if ((error = iicbus_read(parent, buf, 2, &read, IIC_LAST_READ, 0))) |
364 goto error; 365 366 /* first, receive low, then high byte */ 367 *word = BUF2SHORT(buf[0], buf[1]); 368 369error: | 410 goto error; 411 412 /* first, receive low, then high byte */ 413 *word = BUF2SHORT(buf[0], buf[1]); 414 415error: |
416 iicbus_stop(parent); |
|
370 return (error); 371} 372 373static int 374iicsmb_pcall(device_t dev, u_char slave, char cmd, short sdata, short *rdata) 375{ 376 device_t parent = device_get_parent(dev); 377 int error, sent, read; 378 char buf[2]; 379 | 417 return (error); 418} 419 420static int 421iicsmb_pcall(device_t dev, u_char slave, char cmd, short sdata, short *rdata) 422{ 423 device_t parent = device_get_parent(dev); 424 int error, sent, read; 425 char buf[2]; 426 |
380 if ((error = iicbus_start(parent, slave & ~LSB))) 381 goto error; | 427 if ((error = iicbus_start(parent, slave & ~LSB, 0))) 428 return (error); |
382 | 429 |
383 if ((error = iicbus_write(parent, &cmd, 1, &sent))) | 430 if ((error = iicbus_write(parent, &cmd, 1, &sent, 0))) |
384 goto error; 385 386 /* first, send low, then high byte */ 387 buf[0] = (char)(sdata & 0xff); 388 buf[1] = (char)((sdata & 0xff00) >> 8); 389 | 431 goto error; 432 433 /* first, send low, then high byte */ 434 buf[0] = (char)(sdata & 0xff); 435 buf[1] = (char)((sdata & 0xff00) >> 8); 436 |
390 if ((error = iicbus_write(parent, buf, 2, &sent))) | 437 if ((error = iicbus_write(parent, buf, 2, &sent, 0))) |
391 goto error; 392 | 438 goto error; 439 |
393 if ((error = iicbus_repeated_start(parent, slave | LSB))) | 440 if ((error = iicbus_repeated_start(parent, slave | LSB, 0))) |
394 goto error; 395 | 441 goto error; 442 |
396 if ((error = iicbus_read(parent, buf, 2, &read))) | 443 if ((error = iicbus_read(parent, buf, 2, &read, IIC_LAST_READ, 0))) |
397 goto error; 398 399 /* first, receive low, then high byte */ 400 *rdata = BUF2SHORT(buf[0], buf[1]); 401 402error: | 444 goto error; 445 446 /* first, receive low, then high byte */ 447 *rdata = BUF2SHORT(buf[0], buf[1]); 448 449error: |
450 iicbus_stop(parent); |
|
403 return (error); 404} 405 406static int 407iicsmb_bwrite(device_t dev, u_char slave, char cmd, u_char count, char *buf) 408{ 409 device_t parent = device_get_parent(dev); 410 int error, sent; 411 | 451 return (error); 452} 453 454static int 455iicsmb_bwrite(device_t dev, u_char slave, char cmd, u_char count, char *buf) 456{ 457 device_t parent = device_get_parent(dev); 458 int error, sent; 459 |
412 if ((error = iicbus_start(parent, slave & ~LSB))) | 460 if ((error = iicbus_start(parent, slave & ~LSB, 0))) |
413 goto error; 414 | 461 goto error; 462 |
415 if ((error = iicbus_write(parent, &cmd, 1, &sent))) | 463 if ((error = iicbus_write(parent, &cmd, 1, &sent, 0))) |
416 goto error; 417 | 464 goto error; 465 |
418 if ((error = iicbus_write(parent, buf, (int)count, &sent))) | 466 if ((error = iicbus_write(parent, buf, (int)count, &sent, 0))) |
419 goto error; 420 421 if ((error = iicbus_stop(parent))) 422 goto error; 423 424error: 425 return (error); 426} 427 428static int 429iicsmb_bread(device_t dev, u_char slave, char cmd, u_char count, char *buf) 430{ 431 device_t parent = device_get_parent(dev); 432 int error, sent, read; 433 | 467 goto error; 468 469 if ((error = iicbus_stop(parent))) 470 goto error; 471 472error: 473 return (error); 474} 475 476static int 477iicsmb_bread(device_t dev, u_char slave, char cmd, u_char count, char *buf) 478{ 479 device_t parent = device_get_parent(dev); 480 int error, sent, read; 481 |
434 if ((error = iicbus_start(parent, slave & ~LSB))) 435 goto error; | 482 if ((error = iicbus_start(parent, slave & ~LSB, 0))) 483 return (error); |
436 | 484 |
437 if ((error = iicbus_write(parent, &cmd, 1, &sent))) | 485 if ((error = iicbus_write(parent, &cmd, 1, &sent, 0))) |
438 goto error; 439 | 486 goto error; 487 |
440 if ((error = iicbus_repeated_start(parent, slave | LSB))) | 488 if ((error = iicbus_repeated_start(parent, slave | LSB, 0))) |
441 goto error; 442 | 489 goto error; 490 |
443 if ((error = iicbus_read(parent, buf, (int)count, &read))) | 491 if ((error = iicbus_read(parent, buf, (int)count, &read, 492 IIC_LAST_READ, 0))) |
444 goto error; 445 446error: | 493 goto error; 494 495error: |
496 iicbus_stop(parent); |
|
447 return (error); 448} 449 450DRIVER_MODULE(iicsmb, iicbus, iicsmb_driver, iicsmb_devclass, 0, 0); | 497 return (error); 498} 499 500DRIVER_MODULE(iicsmb, iicbus, iicsmb_driver, iicsmb_devclass, 0, 0); |