ACPI: ibm-acpi: break fan_read into separate functions

This patch breaks fan_read mechanics into a generic function to get fan
status and speed, and leaves only the procfs interface code in fan_read.

Signed-off-by: Henrique de Moraes Holschuh <hmh@hmh.eng.br>
This commit is contained in:
Henrique de Moraes Holschuh 2006-11-24 11:47:10 -02:00 committed by Len Brown
parent 3ef8a6096c
commit c52f0aa574

View file

@ -1738,36 +1738,90 @@ static int fan_init(void)
return 0; return 0;
} }
static int fan_read(char *p) static int fan_get_status(u8 *status)
{ {
int len = 0; u8 s;
u8 lo, hi, status;
switch (fan_status_access_mode) { switch (fan_status_access_mode) {
case IBMACPI_FAN_RD_ACPI_GFAN: case IBMACPI_FAN_RD_ACPI_GFAN:
/* 570, 600e/x, 770e, 770x */ /* 570, 600e/x, 770e, 770x */
if (unlikely(!acpi_evalf(gfan_handle, &status, NULL, "d")))
if (unlikely(!acpi_evalf(gfan_handle, &s, NULL, "d")))
return -EIO; return -EIO;
if (likely(status))
*status = s & 0x07;
break;
case IBMACPI_FAN_RD_TPEC:
/* all except 570, 600e/x, 770e, 770x */
if (unlikely(!acpi_ec_read(fan_status_offset, &s)))
return -EIO;
if (likely(status))
*status = s;
break;
default:
return -ENXIO;
}
return 0;
}
static int fan_get_speed(unsigned int *speed)
{
u8 hi, lo;
switch (fan_status_access_mode) {
case IBMACPI_FAN_RD_TPEC:
/* all except 570, 600e/x, 770e, 770x */
if (unlikely(!acpi_ec_read(fan_rpm_offset, &lo) ||
!acpi_ec_read(fan_rpm_offset + 1, &hi)))
return -EIO;
if (likely(speed))
*speed = (hi << 8) | lo;
break;
default:
return -ENXIO;
}
return 0;
}
static int fan_read(char *p)
{
int len = 0;
int rc;
u8 status;
unsigned int speed = 0;
switch (fan_status_access_mode) {
case IBMACPI_FAN_RD_ACPI_GFAN:
/* 570, 600e/x, 770e, 770x */
if ((rc = fan_get_status(&status)) < 0)
return rc;
len += sprintf(p + len, "level:\t\t%d\n", status); len += sprintf(p + len, "level:\t\t%d\n", status);
break; break;
case IBMACPI_FAN_RD_TPEC: case IBMACPI_FAN_RD_TPEC:
/* all except 570, 600e/x, 770e, 770x */ /* all except 570, 600e/x, 770e, 770x */
if (unlikely(!acpi_ec_read(fan_status_offset, &status))) if ((rc = fan_get_status(&status)) < 0)
return -EIO; return rc;
else
len += sprintf(p + len, "status:\t\t%s\n",
enabled(status, 7));
if (unlikely(!acpi_ec_read(fan_rpm_offset, &lo) || len += sprintf(p + len, "status:\t\t%s\n", enabled(status, 7));
!acpi_ec_read(fan_rpm_offset + 1, &hi)))
return -EIO;
else
len += sprintf(p + len, "speed:\t\t%d\n",
(hi << 8) + lo);
if ((rc = fan_get_speed(&speed)) < 0)
return rc;
len += sprintf(p + len, "speed:\t\t%d\n", speed);
break; break;
case IBMACPI_FAN_NONE: case IBMACPI_FAN_NONE: