amdsmb.c (162234) | amdsmb.c (165951) |
---|---|
1#include <sys/cdefs.h> | 1#include <sys/cdefs.h> |
2__FBSDID("$FreeBSD: head/sys/pci/amdsmb.c 162234 2006-09-11 20:52:41Z jhb $"); | 2__FBSDID("$FreeBSD: head/sys/pci/amdsmb.c 165951 2007-01-11 19:56:24Z jhb $"); |
3 4#include <sys/param.h> | 3 4#include <sys/param.h> |
5#include <sys/bus.h> |
|
5#include <sys/kernel.h> | 6#include <sys/kernel.h> |
6#include <sys/systm.h> | 7#include <sys/lock.h> |
7#include <sys/module.h> | 8#include <sys/module.h> |
8#include <sys/bus.h> 9#include <sys/uio.h> | 9#include <sys/mutex.h> 10#include <sys/systm.h> |
10 11#include <machine/bus.h> 12#include <machine/resource.h> 13#include <sys/rman.h> 14 15#include <dev/pci/pcivar.h> 16#include <dev/pci/pcireg.h> 17 | 11 12#include <machine/bus.h> 13#include <machine/resource.h> 14#include <sys/rman.h> 15 16#include <dev/pci/pcivar.h> 17#include <dev/pci/pcireg.h> 18 |
18#include <dev/iicbus/iiconf.h> | |
19#include <dev/smbus/smbconf.h> 20#include "smbus_if.h" 21 22#define AMDSMB_DEBUG(x) if (amdsmb_debug) (x) 23 24#ifdef DEBUG 25static int amdsmb_debug = 1; 26#else --- 54 unchanged lines hidden (view full) --- 81#define SMB_PRTCL_BLOCK_PROC_CALL 0x0d 82#define SMB_PRTCL_PEC 0x80 83 84struct amdsmb_softc { 85 int rid; 86 struct resource *res; 87 bus_space_tag_t smbst; 88 bus_space_handle_t smbsh; | 19#include <dev/smbus/smbconf.h> 20#include "smbus_if.h" 21 22#define AMDSMB_DEBUG(x) if (amdsmb_debug) (x) 23 24#ifdef DEBUG 25static int amdsmb_debug = 1; 26#else --- 54 unchanged lines hidden (view full) --- 81#define SMB_PRTCL_BLOCK_PROC_CALL 0x0d 82#define SMB_PRTCL_PEC 0x80 83 84struct amdsmb_softc { 85 int rid; 86 struct resource *res; 87 bus_space_tag_t smbst; 88 bus_space_handle_t smbsh; |
89 | |
90 device_t smbus; | 89 device_t smbus; |
90 struct mtx lock; |
|
91}; 92 | 91}; 92 |
93#define AMDSMB_ECINB(amdsmb, register) \ | 93#define AMDSMB_LOCK(amdsmb) mtx_lock(&(amdsmb)->lock) 94#define AMDSMB_UNLOCK(amdsmb) mtx_unlock(&(amdsmb)->lock) 95#define AMDSMB_LOCK_ASSERT(amdsmb) mtx_assert(&(amdsmb)->lock, MA_OWNED) 96 97#define AMDSMB_ECINB(amdsmb, register) \ |
94 (bus_space_read_1(amdsmb->smbst, amdsmb->smbsh, register)) 95#define AMDSMB_ECOUTB(amdsmb, register, value) \ 96 (bus_space_write_1(amdsmb->smbst, amdsmb->smbsh, register, value)) 97 | 98 (bus_space_read_1(amdsmb->smbst, amdsmb->smbsh, register)) 99#define AMDSMB_ECOUTB(amdsmb, register, value) \ 100 (bus_space_write_1(amdsmb->smbst, amdsmb->smbsh, register, value)) 101 |
102static int amdsmb_detach(device_t dev); 103 |
|
98static int 99amdsmb_probe(device_t dev) 100{ 101 u_int16_t vid; 102 u_int16_t did; 103 104 vid = pci_get_vendor(dev); 105 did = pci_get_device(dev); --- 22 unchanged lines hidden (view full) --- 128 129 if (amdsmb_sc->res == NULL) { 130 device_printf(dev, "could not map i/o space\n"); 131 return (ENXIO); 132 } 133 134 amdsmb_sc->smbst = rman_get_bustag(amdsmb_sc->res); 135 amdsmb_sc->smbsh = rman_get_bushandle(amdsmb_sc->res); | 104static int 105amdsmb_probe(device_t dev) 106{ 107 u_int16_t vid; 108 u_int16_t did; 109 110 vid = pci_get_vendor(dev); 111 did = pci_get_device(dev); --- 22 unchanged lines hidden (view full) --- 134 135 if (amdsmb_sc->res == NULL) { 136 device_printf(dev, "could not map i/o space\n"); 137 return (ENXIO); 138 } 139 140 amdsmb_sc->smbst = rman_get_bustag(amdsmb_sc->res); 141 amdsmb_sc->smbsh = rman_get_bushandle(amdsmb_sc->res); |
142 mtx_init(&amdsmb_sc->lock, device_get_nameunit(dev), "amdsmb", MTX_DEF); |
|
136 137 /* Allocate a new smbus device */ 138 amdsmb_sc->smbus = device_add_child(dev, "smbus", -1); | 143 144 /* Allocate a new smbus device */ 145 amdsmb_sc->smbus = device_add_child(dev, "smbus", -1); |
139 if (!amdsmb_sc->smbus) | 146 if (!amdsmb_sc->smbus) { 147 amdsmb_detach(dev); |
140 return (EINVAL); | 148 return (EINVAL); |
149 } |
|
141 142 bus_generic_attach(dev); 143 144 return (0); 145} 146 147static int 148amdsmb_detach(device_t dev) 149{ 150 struct amdsmb_softc *amdsmb_sc = device_get_softc(dev); 151 152 if (amdsmb_sc->smbus) { 153 device_delete_child(dev, amdsmb_sc->smbus); 154 amdsmb_sc->smbus = NULL; 155 } 156 | 150 151 bus_generic_attach(dev); 152 153 return (0); 154} 155 156static int 157amdsmb_detach(device_t dev) 158{ 159 struct amdsmb_softc *amdsmb_sc = device_get_softc(dev); 160 161 if (amdsmb_sc->smbus) { 162 device_delete_child(dev, amdsmb_sc->smbus); 163 amdsmb_sc->smbus = NULL; 164 } 165 |
166 mtx_destroy(&amdsmb_sc->lock); |
|
157 if (amdsmb_sc->res) 158 bus_release_resource(dev, SYS_RES_IOPORT, amdsmb_sc->rid, 159 amdsmb_sc->res); 160 161 return (0); 162} 163 164static int --- 39 unchanged lines hidden (view full) --- 204 } 205 return (0); 206} 207 208static int 209amdsmb_ec_read(struct amdsmb_softc *sc, u_char addr, u_char *data) 210{ 211 | 167 if (amdsmb_sc->res) 168 bus_release_resource(dev, SYS_RES_IOPORT, amdsmb_sc->rid, 169 amdsmb_sc->res); 170 171 return (0); 172} 173 174static int --- 39 unchanged lines hidden (view full) --- 214 } 215 return (0); 216} 217 218static int 219amdsmb_ec_read(struct amdsmb_softc *sc, u_char addr, u_char *data) 220{ 221 |
222 AMDSMB_LOCK_ASSERT(sc); |
|
212 if (amdsmb_ec_wait_write(sc)) 213 return (1); 214 AMDSMB_ECOUTB(sc, EC_CMD, EC_CMD_RD); 215 216 if (amdsmb_ec_wait_write(sc)) 217 return (1); 218 AMDSMB_ECOUTB(sc, EC_DATA, addr); 219 220 if (amdsmb_ec_wait_read(sc)) 221 return (1); 222 *data = AMDSMB_ECINB(sc, EC_DATA); 223 224 return (0); 225} 226 227static int 228amdsmb_ec_write(struct amdsmb_softc *sc, u_char addr, u_char data) 229{ 230 | 223 if (amdsmb_ec_wait_write(sc)) 224 return (1); 225 AMDSMB_ECOUTB(sc, EC_CMD, EC_CMD_RD); 226 227 if (amdsmb_ec_wait_write(sc)) 228 return (1); 229 AMDSMB_ECOUTB(sc, EC_DATA, addr); 230 231 if (amdsmb_ec_wait_read(sc)) 232 return (1); 233 *data = AMDSMB_ECINB(sc, EC_DATA); 234 235 return (0); 236} 237 238static int 239amdsmb_ec_write(struct amdsmb_softc *sc, u_char addr, u_char data) 240{ 241 |
242 AMDSMB_LOCK_ASSERT(sc); |
|
231 if (amdsmb_ec_wait_write(sc)) 232 return (1); 233 AMDSMB_ECOUTB(sc, EC_CMD, EC_CMD_WR); 234 235 if (amdsmb_ec_wait_write(sc)) 236 return (1); 237 AMDSMB_ECOUTB(sc, EC_DATA, addr); 238 --- 5 unchanged lines hidden (view full) --- 244} 245 246static int 247amdsmb_wait(struct amdsmb_softc *sc) 248{ 249 u_char sts, temp; 250 int error, count; 251 | 243 if (amdsmb_ec_wait_write(sc)) 244 return (1); 245 AMDSMB_ECOUTB(sc, EC_CMD, EC_CMD_WR); 246 247 if (amdsmb_ec_wait_write(sc)) 248 return (1); 249 AMDSMB_ECOUTB(sc, EC_DATA, addr); 250 --- 5 unchanged lines hidden (view full) --- 256} 257 258static int 259amdsmb_wait(struct amdsmb_softc *sc) 260{ 261 u_char sts, temp; 262 int error, count; 263 |
264 AMDSMB_LOCK_ASSERT(sc); |
|
252 amdsmb_ec_read(sc, SMB_PRTCL, &temp); 253 if (temp != 0) 254 { 255 count = 10000; 256 do { 257 DELAY(500); 258 amdsmb_ec_read(sc, SMB_PRTCL, &temp); 259 } while (temp != 0 && count--); --- 48 unchanged lines hidden (view full) --- 308 case SMB_QREAD: 309 protocol |= SMB_PRTCL_READ; 310 AMDSMB_DEBUG(printf("amdsmb: QREAD to 0x%x", slave)); 311 break; 312 default: 313 panic("%s: unknown QUICK command (%x)!", __func__, how); 314 } 315 | 265 amdsmb_ec_read(sc, SMB_PRTCL, &temp); 266 if (temp != 0) 267 { 268 count = 10000; 269 do { 270 DELAY(500); 271 amdsmb_ec_read(sc, SMB_PRTCL, &temp); 272 } while (temp != 0 && count--); --- 48 unchanged lines hidden (view full) --- 321 case SMB_QREAD: 322 protocol |= SMB_PRTCL_READ; 323 AMDSMB_DEBUG(printf("amdsmb: QREAD to 0x%x", slave)); 324 break; 325 default: 326 panic("%s: unknown QUICK command (%x)!", __func__, how); 327 } 328 |
329 AMDSMB_LOCK(sc); |
|
316 amdsmb_ec_write(sc, SMB_ADDR, slave); 317 amdsmb_ec_write(sc, SMB_PRTCL, protocol); 318 319 error = amdsmb_wait(sc); 320 321 AMDSMB_DEBUG(printf(", error=0x%x\n", error)); | 330 amdsmb_ec_write(sc, SMB_ADDR, slave); 331 amdsmb_ec_write(sc, SMB_PRTCL, protocol); 332 333 error = amdsmb_wait(sc); 334 335 AMDSMB_DEBUG(printf(", error=0x%x\n", error)); |
336 AMDSMB_UNLOCK(sc); |
|
322 323 return (error); 324} 325 326static int 327amdsmb_sendb(device_t dev, u_char slave, char byte) 328{ 329 struct amdsmb_softc *sc = (struct amdsmb_softc *)device_get_softc(dev); 330 int error; 331 | 337 338 return (error); 339} 340 341static int 342amdsmb_sendb(device_t dev, u_char slave, char byte) 343{ 344 struct amdsmb_softc *sc = (struct amdsmb_softc *)device_get_softc(dev); 345 int error; 346 |
347 AMDSMB_LOCK(sc); |
|
332 amdsmb_ec_write(sc, SMB_CMD, byte); 333 amdsmb_ec_write(sc, SMB_ADDR, slave); 334 amdsmb_ec_write(sc, SMB_PRTCL, SMB_PRTCL_WRITE | SMB_PRTCL_BYTE); 335 336 error = amdsmb_wait(sc); 337 338 AMDSMB_DEBUG(printf("amdsmb: SENDB to 0x%x, byte=0x%x, error=0x%x\n", 339 slave, byte, error)); | 348 amdsmb_ec_write(sc, SMB_CMD, byte); 349 amdsmb_ec_write(sc, SMB_ADDR, slave); 350 amdsmb_ec_write(sc, SMB_PRTCL, SMB_PRTCL_WRITE | SMB_PRTCL_BYTE); 351 352 error = amdsmb_wait(sc); 353 354 AMDSMB_DEBUG(printf("amdsmb: SENDB to 0x%x, byte=0x%x, error=0x%x\n", 355 slave, byte, error)); |
356 AMDSMB_UNLOCK(sc); |
|
340 341 return (error); 342} 343 344static int 345amdsmb_recvb(device_t dev, u_char slave, char *byte) 346{ 347 struct amdsmb_softc *sc = (struct amdsmb_softc *)device_get_softc(dev); 348 int error; 349 | 357 358 return (error); 359} 360 361static int 362amdsmb_recvb(device_t dev, u_char slave, char *byte) 363{ 364 struct amdsmb_softc *sc = (struct amdsmb_softc *)device_get_softc(dev); 365 int error; 366 |
367 AMDSMB_LOCK(sc); |
|
350 amdsmb_ec_write(sc, SMB_ADDR, slave); 351 amdsmb_ec_write(sc, SMB_PRTCL, SMB_PRTCL_READ | SMB_PRTCL_BYTE); 352 353 if ((error = amdsmb_wait(sc)) == SMB_ENOERR) 354 amdsmb_ec_read(sc, SMB_DATA, byte); 355 356 AMDSMB_DEBUG(printf("amdsmb: RECVB from 0x%x, byte=0x%x, error=0x%x\n", 357 slave, *byte, error)); | 368 amdsmb_ec_write(sc, SMB_ADDR, slave); 369 amdsmb_ec_write(sc, SMB_PRTCL, SMB_PRTCL_READ | SMB_PRTCL_BYTE); 370 371 if ((error = amdsmb_wait(sc)) == SMB_ENOERR) 372 amdsmb_ec_read(sc, SMB_DATA, byte); 373 374 AMDSMB_DEBUG(printf("amdsmb: RECVB from 0x%x, byte=0x%x, error=0x%x\n", 375 slave, *byte, error)); |
376 AMDSMB_UNLOCK(sc); |
|
358 359 return (error); 360} 361 362static int 363amdsmb_writeb(device_t dev, u_char slave, char cmd, char byte) 364{ 365 struct amdsmb_softc *sc = (struct amdsmb_softc *)device_get_softc(dev); 366 int error; 367 | 377 378 return (error); 379} 380 381static int 382amdsmb_writeb(device_t dev, u_char slave, char cmd, char byte) 383{ 384 struct amdsmb_softc *sc = (struct amdsmb_softc *)device_get_softc(dev); 385 int error; 386 |
387 AMDSMB_LOCK(sc); |
|
368 amdsmb_ec_write(sc, SMB_CMD, cmd); 369 amdsmb_ec_write(sc, SMB_DATA, byte); 370 amdsmb_ec_write(sc, SMB_ADDR, slave); 371 amdsmb_ec_write(sc, SMB_PRTCL, SMB_PRTCL_WRITE | SMB_PRTCL_BYTE_DATA); 372 373 error = amdsmb_wait(sc); 374 375 AMDSMB_DEBUG(printf("amdsmb: WRITEB to 0x%x, cmd=0x%x, byte=0x%x, " 376 "error=0x%x\n", slave, cmd, byte, error)); | 388 amdsmb_ec_write(sc, SMB_CMD, cmd); 389 amdsmb_ec_write(sc, SMB_DATA, byte); 390 amdsmb_ec_write(sc, SMB_ADDR, slave); 391 amdsmb_ec_write(sc, SMB_PRTCL, SMB_PRTCL_WRITE | SMB_PRTCL_BYTE_DATA); 392 393 error = amdsmb_wait(sc); 394 395 AMDSMB_DEBUG(printf("amdsmb: WRITEB to 0x%x, cmd=0x%x, byte=0x%x, " 396 "error=0x%x\n", slave, cmd, byte, error)); |
397 AMDSMB_UNLOCK(sc); |
|
377 378 return (error); 379} 380 381static int 382amdsmb_readb(device_t dev, u_char slave, char cmd, char *byte) 383{ 384 struct amdsmb_softc *sc = (struct amdsmb_softc *)device_get_softc(dev); 385 int error; 386 | 398 399 return (error); 400} 401 402static int 403amdsmb_readb(device_t dev, u_char slave, char cmd, char *byte) 404{ 405 struct amdsmb_softc *sc = (struct amdsmb_softc *)device_get_softc(dev); 406 int error; 407 |
408 AMDSMB_LOCK(sc); |
|
387 amdsmb_ec_write(sc, SMB_CMD, cmd); 388 amdsmb_ec_write(sc, SMB_ADDR, slave); 389 amdsmb_ec_write(sc, SMB_PRTCL, SMB_PRTCL_READ | SMB_PRTCL_BYTE_DATA); 390 391 if ((error = amdsmb_wait(sc)) == SMB_ENOERR) 392 amdsmb_ec_read(sc, SMB_DATA, byte); 393 394 AMDSMB_DEBUG(printf("amdsmb: READB from 0x%x, cmd=0x%x, byte=0x%x, " 395 "error=0x%x\n", slave, cmd, (unsigned char)*byte, error)); | 409 amdsmb_ec_write(sc, SMB_CMD, cmd); 410 amdsmb_ec_write(sc, SMB_ADDR, slave); 411 amdsmb_ec_write(sc, SMB_PRTCL, SMB_PRTCL_READ | SMB_PRTCL_BYTE_DATA); 412 413 if ((error = amdsmb_wait(sc)) == SMB_ENOERR) 414 amdsmb_ec_read(sc, SMB_DATA, byte); 415 416 AMDSMB_DEBUG(printf("amdsmb: READB from 0x%x, cmd=0x%x, byte=0x%x, " 417 "error=0x%x\n", slave, cmd, (unsigned char)*byte, error)); |
418 AMDSMB_UNLOCK(sc); |
|
396 397 return (error); 398} 399 400static int 401amdsmb_writew(device_t dev, u_char slave, char cmd, short word) 402{ 403 struct amdsmb_softc *sc = (struct amdsmb_softc *)device_get_softc(dev); 404 int error; 405 | 419 420 return (error); 421} 422 423static int 424amdsmb_writew(device_t dev, u_char slave, char cmd, short word) 425{ 426 struct amdsmb_softc *sc = (struct amdsmb_softc *)device_get_softc(dev); 427 int error; 428 |
429 AMDSMB_LOCK(sc); |
|
406 amdsmb_ec_write(sc, SMB_CMD, cmd); 407 amdsmb_ec_write(sc, SMB_DATA, word); 408 amdsmb_ec_write(sc, SMB_DATA + 1, word >> 8); 409 amdsmb_ec_write(sc, SMB_ADDR, slave); 410 amdsmb_ec_write(sc, SMB_PRTCL, SMB_PRTCL_WRITE | SMB_PRTCL_WORD_DATA); 411 412 error = amdsmb_wait(sc); 413 414 AMDSMB_DEBUG(printf("amdsmb: WRITEW to 0x%x, cmd=0x%x, word=0x%x, " 415 "error=0x%x\n", slave, cmd, word, error)); | 430 amdsmb_ec_write(sc, SMB_CMD, cmd); 431 amdsmb_ec_write(sc, SMB_DATA, word); 432 amdsmb_ec_write(sc, SMB_DATA + 1, word >> 8); 433 amdsmb_ec_write(sc, SMB_ADDR, slave); 434 amdsmb_ec_write(sc, SMB_PRTCL, SMB_PRTCL_WRITE | SMB_PRTCL_WORD_DATA); 435 436 error = amdsmb_wait(sc); 437 438 AMDSMB_DEBUG(printf("amdsmb: WRITEW to 0x%x, cmd=0x%x, word=0x%x, " 439 "error=0x%x\n", slave, cmd, word, error)); |
440 AMDSMB_UNLOCK(sc); |
|
416 417 return (error); 418} 419 420static int 421amdsmb_readw(device_t dev, u_char slave, char cmd, short *word) 422{ 423 struct amdsmb_softc *sc = (struct amdsmb_softc *)device_get_softc(dev); 424 u_char temp[2]; 425 int error; 426 | 441 442 return (error); 443} 444 445static int 446amdsmb_readw(device_t dev, u_char slave, char cmd, short *word) 447{ 448 struct amdsmb_softc *sc = (struct amdsmb_softc *)device_get_softc(dev); 449 u_char temp[2]; 450 int error; 451 |
452 AMDSMB_LOCK(sc); |
|
427 amdsmb_ec_write(sc, SMB_CMD, cmd); 428 amdsmb_ec_write(sc, SMB_ADDR, slave); 429 amdsmb_ec_write(sc, SMB_PRTCL, SMB_PRTCL_READ | SMB_PRTCL_WORD_DATA); 430 431 if ((error = amdsmb_wait(sc)) == SMB_ENOERR) { 432 amdsmb_ec_read(sc, SMB_DATA + 0, &temp[0]); 433 amdsmb_ec_read(sc, SMB_DATA + 1, &temp[1]); 434 *word = temp[0] | (temp[1] << 8); 435 } 436 437 AMDSMB_DEBUG(printf("amdsmb: READW from 0x%x, cmd=0x%x, word=0x%x, " 438 "error=0x%x\n", slave, cmd, (unsigned short)*word, error)); | 453 amdsmb_ec_write(sc, SMB_CMD, cmd); 454 amdsmb_ec_write(sc, SMB_ADDR, slave); 455 amdsmb_ec_write(sc, SMB_PRTCL, SMB_PRTCL_READ | SMB_PRTCL_WORD_DATA); 456 457 if ((error = amdsmb_wait(sc)) == SMB_ENOERR) { 458 amdsmb_ec_read(sc, SMB_DATA + 0, &temp[0]); 459 amdsmb_ec_read(sc, SMB_DATA + 1, &temp[1]); 460 *word = temp[0] | (temp[1] << 8); 461 } 462 463 AMDSMB_DEBUG(printf("amdsmb: READW from 0x%x, cmd=0x%x, word=0x%x, " 464 "error=0x%x\n", slave, cmd, (unsigned short)*word, error)); |
465 AMDSMB_UNLOCK(sc); |
|
439 440 return (error); 441} 442 443static int 444amdsmb_bwrite(device_t dev, u_char slave, char cmd, u_char count, char *buf) 445{ 446 struct amdsmb_softc *sc = (struct amdsmb_softc *)device_get_softc(dev); 447 u_char i; 448 int error; 449 450 if (count < 1 || count > 32) 451 return (SMB_EINVAL); | 466 467 return (error); 468} 469 470static int 471amdsmb_bwrite(device_t dev, u_char slave, char cmd, u_char count, char *buf) 472{ 473 struct amdsmb_softc *sc = (struct amdsmb_softc *)device_get_softc(dev); 474 u_char i; 475 int error; 476 477 if (count < 1 || count > 32) 478 return (SMB_EINVAL); |
479 480 AMDSMB_LOCK(sc); |
|
452 amdsmb_ec_write(sc, SMB_CMD, cmd); 453 amdsmb_ec_write(sc, SMB_BCNT, count); 454 for (i = 0; i < count; i++) 455 amdsmb_ec_write(sc, SMB_DATA + i, buf[i]); 456 amdsmb_ec_write(sc, SMB_ADDR, slave); 457 amdsmb_ec_write(sc, SMB_PRTCL, SMB_PRTCL_WRITE | SMB_PRTCL_BLOCK_DATA); 458 459 error = amdsmb_wait(sc); 460 461 AMDSMB_DEBUG(printf("amdsmb: WRITEBLK to 0x%x, count=0x%x, cmd=0x%x, " 462 "error=0x%x", slave, count, cmd, error)); | 481 amdsmb_ec_write(sc, SMB_CMD, cmd); 482 amdsmb_ec_write(sc, SMB_BCNT, count); 483 for (i = 0; i < count; i++) 484 amdsmb_ec_write(sc, SMB_DATA + i, buf[i]); 485 amdsmb_ec_write(sc, SMB_ADDR, slave); 486 amdsmb_ec_write(sc, SMB_PRTCL, SMB_PRTCL_WRITE | SMB_PRTCL_BLOCK_DATA); 487 488 error = amdsmb_wait(sc); 489 490 AMDSMB_DEBUG(printf("amdsmb: WRITEBLK to 0x%x, count=0x%x, cmd=0x%x, " 491 "error=0x%x", slave, count, cmd, error)); |
492 AMDSMB_UNLOCK(sc); |
|
463 464 return (error); 465} 466 467static int 468amdsmb_bread(device_t dev, u_char slave, char cmd, u_char *count, char *buf) 469{ 470 struct amdsmb_softc *sc = (struct amdsmb_softc *)device_get_softc(dev); 471 u_char data, len, i; 472 int error; 473 474 if (*count < 1 || *count > 32) 475 return (SMB_EINVAL); | 493 494 return (error); 495} 496 497static int 498amdsmb_bread(device_t dev, u_char slave, char cmd, u_char *count, char *buf) 499{ 500 struct amdsmb_softc *sc = (struct amdsmb_softc *)device_get_softc(dev); 501 u_char data, len, i; 502 int error; 503 504 if (*count < 1 || *count > 32) 505 return (SMB_EINVAL); |
506 507 AMDSMB_LOCK(sc); |
|
476 amdsmb_ec_write(sc, SMB_CMD, cmd); 477 amdsmb_ec_write(sc, SMB_ADDR, slave); 478 amdsmb_ec_write(sc, SMB_PRTCL, SMB_PRTCL_READ | SMB_PRTCL_BLOCK_DATA); 479 480 if ((error = amdsmb_wait(sc)) == SMB_ENOERR) { 481 amdsmb_ec_read(sc, SMB_BCNT, &len); 482 for (i = 0; i < len; i++) { 483 amdsmb_ec_read(sc, SMB_DATA + i, &data); 484 if (i < *count) 485 buf[i] = data; 486 } 487 *count = len; 488 } 489 490 AMDSMB_DEBUG(printf("amdsmb: READBLK to 0x%x, count=0x%x, cmd=0x%x, " 491 "error=0x%x", slave, *count, cmd, error)); | 508 amdsmb_ec_write(sc, SMB_CMD, cmd); 509 amdsmb_ec_write(sc, SMB_ADDR, slave); 510 amdsmb_ec_write(sc, SMB_PRTCL, SMB_PRTCL_READ | SMB_PRTCL_BLOCK_DATA); 511 512 if ((error = amdsmb_wait(sc)) == SMB_ENOERR) { 513 amdsmb_ec_read(sc, SMB_BCNT, &len); 514 for (i = 0; i < len; i++) { 515 amdsmb_ec_read(sc, SMB_DATA + i, &data); 516 if (i < *count) 517 buf[i] = data; 518 } 519 *count = len; 520 } 521 522 AMDSMB_DEBUG(printf("amdsmb: READBLK to 0x%x, count=0x%x, cmd=0x%x, " 523 "error=0x%x", slave, *count, cmd, error)); |
524 AMDSMB_UNLOCK(sc); |
|
492 493 return (error); 494} 495 496static device_method_t amdsmb_methods[] = { 497 /* Device interface */ 498 DEVMETHOD(device_probe, amdsmb_probe), 499 DEVMETHOD(device_attach, amdsmb_attach), --- 31 unchanged lines hidden --- | 525 526 return (error); 527} 528 529static device_method_t amdsmb_methods[] = { 530 /* Device interface */ 531 DEVMETHOD(device_probe, amdsmb_probe), 532 DEVMETHOD(device_attach, amdsmb_attach), --- 31 unchanged lines hidden --- |