amdpm.c (158651) | amdpm.c (162234) |
---|---|
1/*- 2 * Copyright (c) 2000 Matthew C. Forman 3 * 4 * Based (heavily) on alpm.c which is: 5 * 6 * Copyright (c) 1998, 1999 Nicolas Souchu 7 * All rights reserved. 8 * --- 19 unchanged lines hidden (view full) --- 28 * SUCH DAMAGE. 29 */ 30 31/* 32 * Power management function/SMBus function support for the AMD 756 chip. 33 */ 34 35#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2000 Matthew C. Forman 3 * 4 * Based (heavily) on alpm.c which is: 5 * 6 * Copyright (c) 1998, 1999 Nicolas Souchu 7 * All rights reserved. 8 * --- 19 unchanged lines hidden (view full) --- 28 * SUCH DAMAGE. 29 */ 30 31/* 32 * Power management function/SMBus function support for the AMD 756 chip. 33 */ 34 35#include <sys/cdefs.h> |
36__FBSDID("$FreeBSD: head/sys/pci/amdpm.c 158651 2006-05-16 14:37:58Z phk $"); | 36__FBSDID("$FreeBSD: head/sys/pci/amdpm.c 162234 2006-09-11 20:52:41Z jhb $"); |
37 38#include <sys/param.h> 39#include <sys/kernel.h> 40#include <sys/systm.h> 41#include <sys/module.h> 42#include <sys/bus.h> 43#include <sys/uio.h> 44 --- 186 unchanged lines hidden (view full) --- 231 if (amdpm_sc->res) 232 bus_release_resource(dev, SYS_RES_IOPORT, amdpm_sc->rid, 233 amdpm_sc->res); 234 235 return (0); 236} 237 238static int | 37 38#include <sys/param.h> 39#include <sys/kernel.h> 40#include <sys/systm.h> 41#include <sys/module.h> 42#include <sys/bus.h> 43#include <sys/uio.h> 44 --- 186 unchanged lines hidden (view full) --- 231 if (amdpm_sc->res) 232 bus_release_resource(dev, SYS_RES_IOPORT, amdpm_sc->rid, 233 amdpm_sc->res); 234 235 return (0); 236} 237 238static int |
239amdpm_callback(device_t dev, int index, caddr_t *data) | 239amdpm_callback(device_t dev, int index, void *data) |
240{ 241 int error = 0; 242 243 switch (index) { 244 case SMB_REQUEST_BUS: 245 case SMB_RELEASE_BUS: 246 break; 247 default: --- 251 unchanged lines hidden (view full) --- 499 500 return (error); 501} 502 503static int 504amdpm_bwrite(device_t dev, u_char slave, char cmd, u_char count, char *buf) 505{ 506 struct amdpm_softc *sc = (struct amdpm_softc *)device_get_softc(dev); | 240{ 241 int error = 0; 242 243 switch (index) { 244 case SMB_REQUEST_BUS: 245 case SMB_RELEASE_BUS: 246 break; 247 default: --- 251 unchanged lines hidden (view full) --- 499 500 return (error); 501} 502 503static int 504amdpm_bwrite(device_t dev, u_char slave, char cmd, u_char count, char *buf) 505{ 506 struct amdpm_softc *sc = (struct amdpm_softc *)device_get_softc(dev); |
507 u_char remain, len, i; 508 int error = SMB_ENOERR; | 507 u_char i; 508 int error; |
509 u_short l; 510 | 509 u_short l; 510 |
511 if (count < 1 || count > 32) 512 return (SMB_EINVAL); |
|
511 amdpm_clear(sc); 512 if(!amdpm_idle(sc)) 513 return (SMB_EBUSY); 514 | 513 amdpm_clear(sc); 514 if(!amdpm_idle(sc)) 515 return (SMB_EBUSY); 516 |
515 remain = count; 516 while (remain) { 517 len = min(remain, 32); 518 519 AMDPM_SMBOUTW(sc, AMDSMB_HSTADDR, slave & ~LSB); | 517 AMDPM_SMBOUTW(sc, AMDSMB_HSTADDR, slave & ~LSB); |
520 | 518 |
521 /* 522 * Do we have to reset the internal 32-byte buffer? 523 * Can't see how to do this from the data sheet. 524 */ | 519 /* 520 * Do we have to reset the internal 32-byte buffer? 521 * Can't see how to do this from the data sheet. 522 */ 523 AMDPM_SMBOUTW(sc, AMDSMB_HSTDATA, count); |
525 | 524 |
526 AMDPM_SMBOUTW(sc, AMDSMB_HSTDATA, len); 527 528 /* Fill the 32-byte internal buffer */ 529 for (i=0; i<len; i++) { 530 AMDPM_SMBOUTB(sc, AMDSMB_HSTDFIFO, buf[count-remain+i]); 531 DELAY(2); 532 } 533 AMDPM_SMBOUTB(sc, AMDSMB_HSTCMD, cmd); 534 l = AMDPM_SMBINW(sc, AMDSMB_GLOBAL_ENABLE); 535 AMDPM_SMBOUTW(sc, AMDSMB_GLOBAL_ENABLE, (l & 0xfff8) | AMDSMB_GE_CYC_BLOCK | AMDSMB_GE_HOST_STC); 536 537 if ((error = amdpm_wait(sc)) != SMB_ENOERR) 538 goto error; 539 540 remain -= len; | 525 /* Fill the 32-byte internal buffer */ 526 for (i = 0; i < count; i++) { 527 AMDPM_SMBOUTB(sc, AMDSMB_HSTDFIFO, buf[i]); 528 DELAY(2); |
541 } | 529 } |
530 AMDPM_SMBOUTB(sc, AMDSMB_HSTCMD, cmd); 531 l = AMDPM_SMBINW(sc, AMDSMB_GLOBAL_ENABLE); 532 AMDPM_SMBOUTW(sc, AMDSMB_GLOBAL_ENABLE, 533 (l & 0xfff8) | AMDSMB_GE_CYC_BLOCK | AMDSMB_GE_HOST_STC); |
|
542 | 534 |
543error: | 535 error = amdpm_wait(sc); 536 |
544 AMDPM_DEBUG(printf("amdpm: WRITEBLK to 0x%x, count=0x%x, cmd=0x%x, error=0x%x", slave, count, cmd, error)); 545 546 return (error); 547} 548 549static int | 537 AMDPM_DEBUG(printf("amdpm: WRITEBLK to 0x%x, count=0x%x, cmd=0x%x, error=0x%x", slave, count, cmd, error)); 538 539 return (error); 540} 541 542static int |
550amdpm_bread(device_t dev, u_char slave, char cmd, u_char count, char *buf) | 543amdpm_bread(device_t dev, u_char slave, char cmd, u_char *count, char *buf) |
551{ 552 struct amdpm_softc *sc = (struct amdpm_softc *)device_get_softc(dev); | 544{ 545 struct amdpm_softc *sc = (struct amdpm_softc *)device_get_softc(dev); |
553 u_char remain, len, i; 554 int error = SMB_ENOERR; | 546 u_char data, len, i; 547 int error; |
555 u_short l; 556 | 548 u_short l; 549 |
550 if (*count < 1 || *count > 32) 551 return (SMB_EINVAL); |
|
557 amdpm_clear(sc); 558 if (!amdpm_idle(sc)) 559 return (SMB_EBUSY); 560 | 552 amdpm_clear(sc); 553 if (!amdpm_idle(sc)) 554 return (SMB_EBUSY); 555 |
561 remain = count; 562 while (remain) { 563 AMDPM_SMBOUTW(sc, AMDSMB_HSTADDR, slave | LSB); | 556 AMDPM_SMBOUTW(sc, AMDSMB_HSTADDR, slave | LSB); |
564 | 557 |
565 AMDPM_SMBOUTB(sc, AMDSMB_HSTCMD, cmd); | 558 AMDPM_SMBOUTB(sc, AMDSMB_HSTCMD, cmd); |
566 | 559 |
567 l = AMDPM_SMBINW(sc, AMDSMB_GLOBAL_ENABLE); 568 AMDPM_SMBOUTW(sc, AMDSMB_GLOBAL_ENABLE, (l & 0xfff8) | AMDSMB_GE_CYC_BLOCK | AMDSMB_GE_HOST_STC); | 560 l = AMDPM_SMBINW(sc, AMDSMB_GLOBAL_ENABLE); 561 AMDPM_SMBOUTW(sc, AMDSMB_GLOBAL_ENABLE, 562 (l & 0xfff8) | AMDSMB_GE_CYC_BLOCK | AMDSMB_GE_HOST_STC); |
569 | 563 |
570 if ((error = amdpm_wait(sc)) != SMB_ENOERR) 571 goto error; | 564 if ((error = amdpm_wait(sc)) != SMB_ENOERR) 565 goto error; |
572 | 566 |
573 len = AMDPM_SMBINW(sc, AMDSMB_HSTDATA); | 567 len = AMDPM_SMBINW(sc, AMDSMB_HSTDATA); |
574 | 568 |
575 /* Read the 32-byte internal buffer */ 576 for (i=0; i<len; i++) { 577 buf[count-remain+i] = AMDPM_SMBINB(sc, AMDSMB_HSTDFIFO); 578 DELAY(2); 579 } 580 581 remain -= len; | 569 /* Read the 32-byte internal buffer */ 570 for (i = 0; i < len; i++) { 571 data = AMDPM_SMBINB(sc, AMDSMB_HSTDFIFO); 572 if (i < *count) 573 buf[i] = data; 574 DELAY(2); |
582 } | 575 } |
576 *count = len; 577 |
|
583error: | 578error: |
584 AMDPM_DEBUG(printf("amdpm: READBLK to 0x%x, count=0x%x, cmd=0x%x, error=0x%x", slave, count, cmd, error)); | 579 AMDPM_DEBUG(printf("amdpm: READBLK to 0x%x, count=0x%x, cmd=0x%x, error=0x%x", slave, *count, cmd, error)); |
585 586 return (error); 587} 588 589static devclass_t amdpm_devclass; 590 591static device_method_t amdpm_methods[] = { 592 /* Device interface */ --- 18 unchanged lines hidden (view full) --- 611 612static driver_t amdpm_driver = { 613 "amdpm", 614 amdpm_methods, 615 sizeof(struct amdpm_softc), 616}; 617 618DRIVER_MODULE(amdpm, pci, amdpm_driver, amdpm_devclass, 0, 0); | 580 581 return (error); 582} 583 584static devclass_t amdpm_devclass; 585 586static device_method_t amdpm_methods[] = { 587 /* Device interface */ --- 18 unchanged lines hidden (view full) --- 606 607static driver_t amdpm_driver = { 608 "amdpm", 609 amdpm_methods, 610 sizeof(struct amdpm_softc), 611}; 612 613DRIVER_MODULE(amdpm, pci, amdpm_driver, amdpm_devclass, 0, 0); |
614DRIVER_MODULE(smbus, amdpm, smbus_driver, smbus_devclass, 0, 0); |
|
619 620MODULE_DEPEND(amdpm, pci, 1, 1, 1); 621MODULE_DEPEND(amdpm, smbus, SMBUS_MINVER, SMBUS_PREFVER, SMBUS_MAXVER); 622MODULE_VERSION(amdpm, 1); | 615 616MODULE_DEPEND(amdpm, pci, 1, 1, 1); 617MODULE_DEPEND(amdpm, smbus, SMBUS_MINVER, SMBUS_PREFVER, SMBUS_MAXVER); 618MODULE_VERSION(amdpm, 1); |
623 | |