Add linux v2.6.20-rc2, as most patches were merged in
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / releases / upstream / 2.6.20-rc2 / 0008-ACPI-ibm-acpi-prepare-to-cleanup-fan_read-and-fan_write.txt
blob606b932ef87525b5b7c5a2f4b37dcd6e22d78c76
1 From 69ba91cbd6d79aa197adbdd10a44e71c84044b44 Mon Sep 17 00:00:00 2001
2 From: Henrique de Moraes Holschuh <hmh@hmh.eng.br>
3 Date: Fri, 24 Nov 2006 11:47:09 -0200
4 Subject: [PATCH 8/28] ACPI: ibm-acpi: prepare to cleanup fan_read and fan_write
6 This patch lays some groundwork for a fan_read and fan_write cleanup in the
7 next patches.  To do so, it provides a new fan_init initializer, and also some
8 constants (through enums).
10 Signed-off-by: Henrique de Moraes Holschuh <hmh@hmh.eng.br>
11 ---
12  drivers/acpi/ibm_acpi.c |   81 +++++++++++++++++++++++++++++++++++++++++++++-
13  1 files changed, 79 insertions(+), 2 deletions(-)
15 diff --git a/drivers/acpi/ibm_acpi.c b/drivers/acpi/ibm_acpi.c
16 index 1703c61..7d0bd61 100644
17 --- a/drivers/acpi/ibm_acpi.c
18 +++ b/drivers/acpi/ibm_acpi.c
19 @@ -231,6 +231,31 @@ struct ibm_thermal_sensors_struct {
20         s32 temp[IBMACPI_MAX_THERMAL_SENSORS];
21  };
23 +enum fan_status_access_mode {
24 +       IBMACPI_FAN_NONE = 0,           /* No fan status or control */
25 +       IBMACPI_FAN_RD_ACPI_GFAN,       /* Use ACPI GFAN */
26 +       IBMACPI_FAN_RD_TPEC,            /* Use ACPI EC regs 0x2f, 0x84-0x85 */
27 +};
29 +enum fan_control_access_mode {
30 +       IBMACPI_FAN_WR_NONE = 0,        /* No fan control */
31 +       IBMACPI_FAN_WR_ACPI_SFAN,       /* Use ACPI SFAN */
32 +       IBMACPI_FAN_WR_TPEC,            /* Use ACPI EC reg 0x2f */
33 +       IBMACPI_FAN_WR_ACPI_FANS,       /* Use ACPI FANS and EC reg 0x2f */
34 +};
36 +enum fan_control_commands {
37 +       IBMACPI_FAN_CMD_SPEED   = 0x0001,       /* speed command */
38 +       IBMACPI_FAN_CMD_LEVEL   = 0x0002,       /* level command  */
39 +       IBMACPI_FAN_CMD_ENABLE  = 0x0004,       /* enable/disable cmd */
40 +};
42 +enum {                                 /* Fan control constants */
43 +       fan_status_offset = 0x2f,       /* EC register 0x2f */
44 +       fan_rpm_offset = 0x84,          /* EC register 0x84: LSB, 0x85 MSB (RPM)
45 +                                        * 0x84 must be read before 0x85 */
46 +};
48  static int ibm_thinkpad_ec_found;
50  struct ibm_struct {
51 @@ -1659,8 +1684,59 @@ static int volume_write(char *buf)
52         return 0;
53  }
55 -static int fan_status_offset = 0x2f;
56 -static int fan_rpm_offset = 0x84;
57 +static enum fan_status_access_mode fan_status_access_mode;
58 +static enum fan_control_access_mode fan_control_access_mode;
59 +static enum fan_control_commands fan_control_commands;
61 +static int fan_init(void)
63 +       u8 status;
65 +       fan_status_access_mode = IBMACPI_FAN_NONE;
66 +       fan_control_access_mode = IBMACPI_FAN_WR_NONE;
67 +       fan_control_commands = 0;
69 +       if (gfan_handle) {
70 +               /* 570, 600e/x, 770e, 770x */
71 +               fan_status_access_mode = IBMACPI_FAN_RD_ACPI_GFAN;
72 +       } else {
73 +               /* all other ThinkPads: note that even old-style
74 +                * ThinkPad ECs supports the fan control register */
75 +               if (likely(acpi_ec_read(fan_status_offset, &status))) {
76 +                       fan_status_access_mode = IBMACPI_FAN_RD_TPEC;
77 +               } else {
78 +                       printk(IBM_ERR
79 +                              "ThinkPad ACPI EC access misbehaving, "
80 +                              "fan status and control unavailable\n");
81 +                       return 0;
82 +               }
83 +       }
85 +       if (sfan_handle) {
86 +               /* 570, 770x-JL */
87 +               fan_control_access_mode = IBMACPI_FAN_WR_ACPI_SFAN;
88 +               fan_control_commands |= IBMACPI_FAN_CMD_LEVEL;
89 +       } else {
90 +               if (!gfan_handle) {
91 +                       /* gfan without sfan means no fan control */
92 +                       /* all other models implement TP EC 0x2f control */
94 +                       if (fans_handle) {
95 +                               /* X31, X40 */
96 +                               fan_control_access_mode =
97 +                                   IBMACPI_FAN_WR_ACPI_FANS;
98 +                               fan_control_commands |=
99 +                                   IBMACPI_FAN_CMD_SPEED |
100 +                                   IBMACPI_FAN_CMD_ENABLE;
101 +                       } else {
102 +                               fan_control_access_mode = IBMACPI_FAN_WR_TPEC;
103 +                               fan_control_commands |= IBMACPI_FAN_CMD_ENABLE;
104 +                       }
105 +               }
106 +       }
108 +       return 0;
111  static int fan_read(char *p)
113 @@ -1849,6 +1925,7 @@ static struct ibm_struct ibms[] = {
114          .name = "fan",
115          .read = fan_read,
116          .write = fan_write,
117 +        .init = fan_init,
118          .experimental = 1,
119          },
120  };
121 -- 
122 1.4.4.2