| 1 | #include <stdio.h> // printf
|
|---|
| 2 | #include <stdlib.h> // atoi
|
|---|
| 3 | #include <stdint.h> // uint8_t, uint16_t
|
|---|
| 4 | #include <string.h> // strcmp
|
|---|
| 5 | #include <sys/io.h> // inb, outb
|
|---|
| 6 |
|
|---|
| 7 | // IO ports
|
|---|
| 8 | const uint16_t AEIC = 0x025D; // command register
|
|---|
| 9 | const uint16_t AEID = 0x025C; // data register
|
|---|
| 10 |
|
|---|
| 11 | // waits for the status bit to clear, max 0x4000 tries
|
|---|
| 12 | void WEIE() {
|
|---|
| 13 | uint16_t Local0 = 0x4000;
|
|---|
| 14 | uint8_t Local1 = inb(AEIC) & 0x02;
|
|---|
| 15 | while(Local0 != 0 && Local1 == 0x02) {
|
|---|
| 16 | Local1 = inb(AEIC) & 0x02;
|
|---|
| 17 | Local0--;
|
|---|
| 18 | }
|
|---|
| 19 | }
|
|---|
| 20 |
|
|---|
| 21 | // sets the fan speed
|
|---|
| 22 | void WMFN(uint8_t Arg0) {
|
|---|
| 23 | WEIE();
|
|---|
| 24 | outb(0x98, AEIC);
|
|---|
| 25 | WEIE();
|
|---|
| 26 | outb(Arg0, AEID);
|
|---|
| 27 | WEIE();
|
|---|
| 28 | }
|
|---|
| 29 |
|
|---|
| 30 | int main(int argc, char ** argv) {
|
|---|
| 31 | if(argc != 2) {
|
|---|
| 32 | printf("usage: %s speed\n", argv[0]);
|
|---|
| 33 | printf("speed: `auto' or a value between 1 and 15\n");
|
|---|
| 34 | printf("keep in mind that `auto' will be even faster than 15!\n");
|
|---|
| 35 | return 1;
|
|---|
| 36 | }
|
|---|
| 37 |
|
|---|
| 38 | uint8_t speed = 0xFF;
|
|---|
| 39 | if(strcmp(argv[1], "auto") == 0)
|
|---|
| 40 | printf("setting speed to 'auto'\n");
|
|---|
| 41 | else {
|
|---|
| 42 | int arg = atoi(argv[1]);
|
|---|
| 43 | if(arg < 1 || arg > 15) {
|
|---|
| 44 | printf("Error: the speed %d is not possible\n", arg);
|
|---|
| 45 | return 1;
|
|---|
| 46 | }
|
|---|
| 47 | printf("setting speed to %d\n", arg);
|
|---|
| 48 | speed = (arg << 3) | 0x07;
|
|---|
| 49 | }
|
|---|
| 50 |
|
|---|
| 51 | if(ioperm(AEID, 1, 1)) {
|
|---|
| 52 | printf("Error: could not gain access to IO port AEID (0x025C)\n");
|
|---|
| 53 | return 1;
|
|---|
| 54 | }
|
|---|
| 55 |
|
|---|
| 56 | if(ioperm(AEIC, 1, 1)) {
|
|---|
| 57 | printf("Error: could not gain access to IO port AEIC (0x025D)\n");
|
|---|
| 58 | return 1;
|
|---|
| 59 | }
|
|---|
| 60 |
|
|---|
| 61 | WMFN(speed);
|
|---|
| 62 |
|
|---|
| 63 | printf("done.\n");
|
|---|
| 64 | return 0;
|
|---|
| 65 | }
|
|---|
| 66 |
|
|---|