diff options
author | Mark Kettenis <kettenis@cvs.openbsd.org> | 2006-08-26 10:42:58 +0000 |
---|---|---|
committer | Mark Kettenis <kettenis@cvs.openbsd.org> | 2006-08-26 10:42:58 +0000 |
commit | 1711dda7a9d15505a07b7628f199778b6b57acad (patch) | |
tree | 38912e4f66fb631dc8ffa9e3332258ed689a7e26 | |
parent | 5988db216e2a31132593d48d80ec3db38aeccbb2 (diff) |
Cleanup. Add config flag to make fans blast at full speed.
ok drahn@
-rw-r--r-- | sys/dev/i2c/fintek.c | 368 |
1 files changed, 60 insertions, 308 deletions
diff --git a/sys/dev/i2c/fintek.c b/sys/dev/i2c/fintek.c index e3e3e76915a..bd1ad15f0b0 100644 --- a/sys/dev/i2c/fintek.c +++ b/sys/dev/i2c/fintek.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fintek.c,v 1.1 2006/06/15 20:50:44 drahn Exp $ */ +/* $OpenBSD: fintek.c,v 1.2 2006/08/26 10:42:57 kettenis Exp $ */ /* * Copyright (c) 2006 Dale Rahn <drahn@openbsd.org> * @@ -33,7 +33,6 @@ #define F_FAN2 7 #define F_NUM_SENSORS 8 - struct fintek_softc { struct device sc_dev; i2c_tag_t sc_tag; @@ -46,15 +45,11 @@ int fintek_match(struct device *, void *, void *); void fintek_attach(struct device *, struct device *, void *); void fintek_refresh(void *); - int fintek_read_reg(struct fintek_softc *sc, u_int8_t cmd, u_int8_t *data, size_t size); int fintek_write_reg(struct fintek_softc *sc, u_int8_t cmd, u_int8_t *data, size_t size); - -void fintek_setspeed(struct fintek_softc *sc); -void fintek_setauto(struct fintek_softc *sc); -void fintek_setpwm(struct fintek_softc *sc); +void fintek_fullspeed(struct fintek_softc *sc); struct cfattach fintek_ca = { sizeof(struct fintek_softc), fintek_match, fintek_attach @@ -64,16 +59,26 @@ struct cfdriver fintek_cd = { NULL, "fintek", DV_DULL }; -#define FINTEK_VOLT0 0x10 -#define FINTEK_VOLT1 0x11 -#define FINTEK_VOLT2 0x12 -#define FINTEK_VOLT3 0x13 -#define FINTEK_TEMP1 0x14 -#define FINTEK_TEMP2 0x15 -#define FINTEK_FAN1 0x16 -#define FINTEK_FAN2 0x18 -#define FINTEK_VERSION 0x5c -#define FINTEK_RSTCR 0x60 +#define FINTEK_CONFIG1 0x01 +#define FINTEK_FAN1_LINEAR_MODE 0x10 +#define FINTEK_FAN2_LINEAR_MODE 0x20 +#define FINTEK_VOLT0 0x10 +#define FINTEK_VOLT1 0x11 +#define FINTEK_VOLT2 0x12 +#define FINTEK_VOLT3 0x13 +#define FINTEK_TEMP1 0x14 +#define FINTEK_TEMP2 0x15 +#define FINTEK_FAN1 0x16 +#define FINTEK_FAN2 0x18 +#define FINTEK_VERSION 0x5c +#define FINTEK_RSTCR 0x60 +#define FINTEK_FAN1_MODE_MANUAL 0x30 +#define FINTEK_FAN2_MODE_MANUAL 0xc0 +#define FINTEK_PWM_DUTY1 0x76 +#define FINTEK_PWM_DUTY2 0x86 + +/* Options passed via the 'flags' config keyword. */ +#define FINTEK_OPTION_FULLSPEED 0x0001 int fintek_match(struct device *parent, void *match, void *aux) @@ -92,6 +97,7 @@ fintek_read_reg(struct fintek_softc *sc, u_int8_t cmd, u_int8_t *data, return iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP, sc->sc_addr, &cmd, sizeof cmd, data, size, 0); } + int fintek_write_reg(struct fintek_softc *sc, u_int8_t cmd, u_int8_t *data, size_t size) @@ -105,7 +111,7 @@ fintek_attach(struct device *parent, struct device *self, void *aux) { struct fintek_softc *sc = (struct fintek_softc *)self; struct i2c_attach_args *ia = aux; - u_int8_t cmd, data, data2; + u_int8_t cmd, data; int i; sc->sc_tag = ia->ia_tag; @@ -117,129 +123,21 @@ fintek_attach(struct device *parent, struct device *self, void *aux) if (fintek_read_reg(sc, cmd, &data, sizeof data)) goto failread; - printf(": F75375 rev %d.%d", data>> 4, data & 0xf); + /* + * It seems the fan in the Thecus n2100 doesn't provide a + * reliable fan count. As a result the automatic fan + * controlling mode that the chip comes up in after reset + * doesn't work reliably. So we have a flag to drive the fan + * at maximum voltage such that the box doesn't overheat. + */ + if (sc->sc_dev.dv_cfdata->cf_flags & FINTEK_OPTION_FULLSPEED) + fintek_fullspeed(sc); - cmd = FINTEK_RSTCR; - if (fintek_read_reg(sc, cmd, &data, sizeof data)) - goto failread; -#if 1 - data = 0x81; - cmd = 0; - if (fintek_write_reg(sc, cmd, &data, sizeof data)) - goto failwrite; - if (iic_exec(sc->sc_tag, I2C_OP_WRITE_WITH_STOP, - sc->sc_addr, &cmd, sizeof cmd, &data, sizeof data, 0)) { - iic_release_bus(sc->sc_tag, 0); - printf(": cannot read ID register\n"); - return; - } -#endif - - -#ifdef NOISY_DEBUG - cmd = 0; - if (fintek_read_reg(sc, cmd, &data, sizeof data)) - goto failread; - printf(" conf 0 %x", data); - - cmd = 0x1; - if (fintek_read_reg(sc, cmd, &data, sizeof data)) - goto failread; - printf(" conf 1 %x", data); - - cmd = 0x2; - if (fintek_read_reg(sc, cmd, &data, sizeof data)) - goto failread; - - printf(" conf 2 %x", data); - cmd = 0x3; - if (fintek_read_reg(sc, cmd, &data, sizeof data)) - goto failread; - printf(" conf 3 %x\n", data); - cmd = 0x70; - if (fintek_read_reg(sc, cmd, &data, sizeof data)) - goto failread; - cmd = 0x71; - if (fintek_read_reg(sc, cmd, &data2, sizeof data2)) - goto failread; - printf(" fan full speed %x %x\n", data, data2); - - cmd = 0xa0; - if (fintek_read_reg(sc, cmd, &data, sizeof data)) - goto failread; - printf(" temp 1 b %x\n", data); - - cmd = 0xa1; - if (fintek_read_reg(sc, cmd, &data, sizeof data)) - goto failread; - printf(" temp 2 b %x\n", data); - - cmd = 0xa2; - if (fintek_read_reg(sc, cmd, &data, sizeof data)) - goto failread; - printf(" temp 3 b %x\n", data); - - cmd = 0xa3; - if (fintek_read_reg(sc, cmd, &data, sizeof data)) - goto failread; - printf(" temp 4 b %x\n", data); - - cmd = 0xa4; - if (fintek_read_reg(sc, cmd, &data, sizeof data)) - goto failread; - cmd = 0xa5; - if (fintek_read_reg(sc, cmd, &data2, sizeof data)) - goto failread; - printf(" sec1speed %x %x\n", data, data2); - - cmd = 0xa6; - if (fintek_read_reg(sc, cmd, &data, sizeof data)) - goto failread; - cmd = 0xa7; - if (fintek_read_reg(sc, cmd, &data2, sizeof data)) - goto failread; - printf(" sec2speed %x %x\n", data, data2); - - cmd = 0xa8; - if (fintek_read_reg(sc, cmd, &data, sizeof data)) - goto failread; - cmd = 0xa9; - if (fintek_read_reg(sc, cmd, &data2, sizeof data)) - goto failread; - printf(" sec3speed %x %x\n", data, data2); - - cmd = 0xaa; - if (fintek_read_reg(sc, cmd, &data, sizeof data)) - goto failread; - cmd = 0xab; - if (fintek_read_reg(sc, cmd, &data2, sizeof data)) - goto failread; - printf(" sec4speed %x %x\n", data, data2); - - cmd = 0xac; - if (fintek_read_reg(sc, cmd, &data, sizeof data)) - goto failread; - cmd = 0xad; - if (fintek_read_reg(sc, cmd, &data2, sizeof data)) - goto failread; - printf(" sec5speed %x %x\n", data, data2); -#endif - -#if 0 - fintek_setpwm(sc); -#endif -#if 0 - fintek_setauto(sc); -#endif - data2 = data2; -#if 1 - fintek_setspeed(sc); -#endif iic_release_bus(sc->sc_tag, 0); -for (i = 0; i < F_NUM_SENSORS; i++) + for (i = 0; i < F_NUM_SENSORS; i++) strlcpy(sc->sc_sensor[i].device, sc->sc_dev.dv_xname, sizeof(sc->sc_sensor[i].device)); @@ -248,31 +146,31 @@ for (i = 0; i < F_NUM_SENSORS; i++) sizeof(sc->sc_sensor[F_VCC].desc)); sc->sc_sensor[F_V1].type = SENSOR_VOLTS_DC; - strlcpy(sc->sc_sensor[F_V1].desc, "Volt 1", + strlcpy(sc->sc_sensor[F_V1].desc, "Volt1", sizeof(sc->sc_sensor[F_V1].desc)); sc->sc_sensor[F_V2].type = SENSOR_VOLTS_DC; - strlcpy(sc->sc_sensor[F_V2].desc, "Volt 2", + strlcpy(sc->sc_sensor[F_V2].desc, "Volt2", sizeof(sc->sc_sensor[F_V2].desc)); sc->sc_sensor[F_V3].type = SENSOR_VOLTS_DC; - strlcpy(sc->sc_sensor[F_V3].desc, "Volt 3", + strlcpy(sc->sc_sensor[F_V3].desc, "Volt3", sizeof(sc->sc_sensor[F_V3].desc)); sc->sc_sensor[F_TEMP1].type = SENSOR_TEMP; - strlcpy(sc->sc_sensor[F_TEMP1].desc, "Temp 1", + strlcpy(sc->sc_sensor[F_TEMP1].desc, "Temp1", sizeof(sc->sc_sensor[F_TEMP1].desc)); sc->sc_sensor[F_TEMP2].type = SENSOR_TEMP; - strlcpy(sc->sc_sensor[F_TEMP2].desc, "Temp 2", + strlcpy(sc->sc_sensor[F_TEMP2].desc, "Temp2", sizeof(sc->sc_sensor[F_TEMP2].desc)); sc->sc_sensor[F_FAN1].type = SENSOR_FANRPM; - strlcpy(sc->sc_sensor[F_FAN1].desc, "FAN1", + strlcpy(sc->sc_sensor[F_FAN1].desc, "Fan1", sizeof(sc->sc_sensor[F_FAN1].desc)); sc->sc_sensor[F_FAN2].type = SENSOR_FANRPM; - strlcpy(sc->sc_sensor[F_FAN2].desc, "FAN1", + strlcpy(sc->sc_sensor[F_FAN2].desc, "Fan2", sizeof(sc->sc_sensor[F_FAN2].desc)); if (sensor_task_register(sc, fintek_refresh, 5)) { @@ -284,17 +182,14 @@ for (i = 0; i < F_NUM_SENSORS; i++) sc->sc_sensor[i].flags &= ~SENSOR_FINVALID; sensor_add(&sc->sc_sensor[i]); } + + printf("\n"); return; failread: printf("unable to read reg %d\n", cmd); iic_release_bus(sc->sc_tag, 0); return; -#if 1 -failwrite: - printf("unable to write reg %d\n", cmd); - iic_release_bus(sc->sc_tag, 0); -#endif } @@ -311,7 +206,7 @@ struct { { F_FAN1, FINTEK_FAN1 }, { F_FAN2, FINTEK_FAN2 } }; -#define FINTEK_WORKLIST_SZ (sizeof fintek_worklist/sizeof(fintek_worklist[0])) +#define FINTEK_WORKLIST_SZ (sizeof(fintek_worklist) / sizeof(fintek_worklist[0])) void fintek_refresh(void *arg) @@ -331,69 +226,35 @@ fintek_refresh(void *arg) sc->sc_sensor[i].flags &= ~SENSOR_FINVALID; switch (fintek_worklist[i].sensor) { case F_VCC: - /* FALLTHROUGH */ + sc->sc_sensor[i].value = data * 16000; + break; case F_V1: /* FALLTHROUGH */ case F_V2: /* FALLTHROUGH */ case F_V3: - sc->sc_sensor[i].value = 1000 * (data*8); + sc->sc_sensor[i].value = data * 8000; break; case F_TEMP1: /* FALLTHROUGH */ case F_TEMP2: - sc->sc_sensor[i].value = 273150000 + 1000000 * (data); + sc->sc_sensor[i].value = 273150000 + data * 1000000; break; case F_FAN1: /* FALLTHROUGH */ case F_FAN2: - /* FANxLSB follows FANxMSB */ + /* FANx LSB follows FANx MSB */ cmd = fintek_worklist[i].cmd + 1; if (fintek_read_reg(sc, cmd, &data2, sizeof data2)) { sc->sc_sensor[i].flags |= SENSOR_FINVALID; continue; } -// printf("fan speed %x: %x %x\n", fintek_worklist[i].cmd, -// data, data2); if ((data == 0xff && data2 == 0xff) || (data == 0 && data2 == 0)) sc->sc_sensor[i].value = 0; else - sc->sc_sensor[i].value = 1500000/ + sc->sc_sensor[i].value = 1500000 / (data << 8 | data2); - { - extern long hostid; - static long currentspeed; - int i; - if (currentspeed != hostid) { - currentspeed = hostid; - printf("setting speed to %d\n", hostid); - -#if 0 - data = hostid & 0xff; - cmd = 0x76; - fintek_write_reg(sc, cmd, &data, - sizeof data); -#else - cmd = 0x6d; - fintek_read_reg(sc, cmd, &data, - sizeof data); - printf("reg 6d contains %x setting to 0x11\n", data); - fintek_write_reg(sc, cmd, &data, - sizeof data); - i = hostid ; /* desired value */ - cmd = 0x74; - data = i >> 8; - fintek_write_reg(sc, cmd, &data, - sizeof data); - - cmd = 0x75; - data = i & 0xff; - fintek_write_reg(sc, cmd, &data, - sizeof data); -#endif - } - } break; default: sc->sc_sensor[i].flags |= SENSOR_FINVALID; @@ -403,128 +264,19 @@ fintek_refresh(void *arg) iic_release_bus(sc->sc_tag, 0); } -void -fintek_setspeed(struct fintek_softc *sc) -{ - u_int8_t cmd, data; - int i; - - cmd = 0x1; - fintek_read_reg(sc, cmd, &data, sizeof data); - - data |= (1<<4); - fintek_write_reg(sc, cmd, &data, sizeof data); - - i = 300; /* desired speed */ - i = 1500000/i; - cmd = 0x74; - data = i >> 8; - fintek_write_reg(sc, cmd, &data, sizeof data); - - cmd = 0x75; - data = i & 0xff; - fintek_write_reg(sc, cmd, &data, sizeof data); - - cmd = 0x60; - fintek_read_reg(sc, cmd, &data, sizeof data); - - data &= ~(0x1 << 4); - data |= (0x2 << 4); /* manual */ - fintek_write_reg(sc, cmd, &data, sizeof data); - printf("\n"); -} void -fintek_setauto(struct fintek_softc *sc) +fintek_fullspeed(struct fintek_softc *sc) { - u_int8_t cmd, data, data2; - int i; + u_int8_t data; - i = 2000; /* desired speed */ - i = 1500000/i; - data2 = i >> 8; - data = i & 0xff; - - cmd = 0xa4; - fintek_write_reg(sc, cmd, &data, sizeof data); - fintek_write_reg(sc, cmd, &data2, sizeof data2); - - i = 0x3A98; - data2 = i >> 8; - data = i & 0xff; - cmd = 0xa6; - fintek_write_reg(sc, cmd, &data, sizeof data); - - cmd = 0xa7; - fintek_write_reg(sc, cmd, &data2, sizeof data2); - - i = 0x3A98; - data2 = i >> 8; - data = i & 0xff; - cmd = 0xa8; - fintek_write_reg(sc, cmd, &data, sizeof data); - - cmd = 0xa9; - fintek_write_reg(sc, cmd, &data2, sizeof data2); - - i = 0x3A98; - data2 = i >> 8; - data = i & 0xff; - cmd = 0xaa; - fintek_write_reg(sc, cmd, &data, sizeof data); - - cmd = 0xab; - fintek_write_reg(sc, cmd, &data2, sizeof data2); - - i = 0x3A98; - data2 = i >> 8; - data = i & 0xff; - cmd = 0xac; - fintek_write_reg(sc, cmd, &data, sizeof data); - - cmd = 0xad; - fintek_write_reg(sc, cmd, &data2, sizeof data2); - - cmd = 0x74; - fintek_read_reg(sc, cmd, &data, sizeof data); - - cmd = 0x75; - fintek_read_reg(sc, cmd, &data2, sizeof data); - - printf("fan speed %x %x\n", data, data2); - - cmd = 0x60; - fintek_read_reg(sc, cmd, &data, sizeof data); - - data &= ~(0x3 << 4); - data |= (1 << 4); - fintek_write_reg(sc, cmd, &data, sizeof data); - - printf("\n"); + data = FINTEK_FAN1_LINEAR_MODE | FINTEK_FAN2_LINEAR_MODE; + fintek_write_reg(sc, FINTEK_CONFIG1, &data, sizeof data); -} -void -fintek_setpwm(struct fintek_softc *sc) -{ - u_int8_t cmd, data; - - cmd = 0x01; - fintek_read_reg(sc, cmd, &data, sizeof data); - data |= 1<<4; - fintek_write_reg(sc, cmd, &data, sizeof data); - - cmd = 0x60; - fintek_read_reg(sc, cmd, &data, sizeof data); - - data |= 0x3 << 4; - - fintek_write_reg(sc, cmd, &data, sizeof data); + data = FINTEK_FAN1_MODE_MANUAL | FINTEK_FAN2_MODE_MANUAL; + fintek_write_reg(sc, FINTEK_RSTCR, &data, sizeof data); - - data = 0x28; - cmd = 0x76; - fintek_write_reg(sc, cmd, &data, sizeof data); - - printf("\n"); - -} + data = 0xff; /* Maximum voltage */ + fintek_write_reg(sc, FINTEK_PWM_DUTY1, &data, sizeof data); + fintek_write_reg(sc, FINTEK_PWM_DUTY2, &data, sizeof data); +} |