[Bluetooth] Use in-kernel sockets API
[pandora-kernel.git] / drivers / misc / thinkpad_acpi.c
index d5526e8..6c36a55 100644 (file)
@@ -296,14 +296,22 @@ static void drv_acpi_handle_init(char *name,
        int i;
        acpi_status status;
 
+       vdbg_printk(TPACPI_DBG_INIT, "trying to locate ACPI handle for %s\n",
+               name);
+
        for (i = 0; i < num_paths; i++) {
                status = acpi_get_handle(parent, paths[i], handle);
                if (ACPI_SUCCESS(status)) {
                        *path = paths[i];
+                       dbg_printk(TPACPI_DBG_INIT,
+                                  "Found ACPI handle %s for %s\n",
+                                  *path, name);
                        return;
                }
        }
 
+       vdbg_printk(TPACPI_DBG_INIT, "ACPI handle for %s not found\n",
+                   name);
        *handle = NULL;
 }
 
@@ -320,19 +328,20 @@ static void dispatch_acpi_notify(acpi_handle handle, u32 event, void *data)
 static int __init setup_acpi_notify(struct ibm_struct *ibm)
 {
        acpi_status status;
-       int ret;
+       int rc;
 
        BUG_ON(!ibm->acpi);
 
        if (!*ibm->acpi->handle)
                return 0;
 
-       dbg_printk(TPACPI_DBG_INIT,
+       vdbg_printk(TPACPI_DBG_INIT,
                "setting up ACPI notify for %s\n", ibm->name);
 
-       ret = acpi_bus_get_device(*ibm->acpi->handle, &ibm->acpi->device);
-       if (ret < 0) {
-               printk(IBM_ERR "%s device not present\n", ibm->name);
+       rc = acpi_bus_get_device(*ibm->acpi->handle, &ibm->acpi->device);
+       if (rc < 0) {
+               printk(IBM_ERR "acpi_bus_get_device(%s) failed: %d\n",
+                       ibm->name, rc);
                return -ENODEV;
        }
 
@@ -364,7 +373,7 @@ static int __init tpacpi_device_add(struct acpi_device *device)
 
 static int __init register_tpacpi_subdriver(struct ibm_struct *ibm)
 {
-       int ret;
+       int rc;
 
        dbg_printk(TPACPI_DBG_INIT,
                "registering %s as an ACPI driver\n", ibm->name);
@@ -381,16 +390,16 @@ static int __init register_tpacpi_subdriver(struct ibm_struct *ibm)
        ibm->acpi->driver->ids = ibm->acpi->hid;
        ibm->acpi->driver->ops.add = &tpacpi_device_add;
 
-       ret = acpi_bus_register_driver(ibm->acpi->driver);
-       if (ret < 0) {
+       rc = acpi_bus_register_driver(ibm->acpi->driver);
+       if (rc < 0) {
                printk(IBM_ERR "acpi_bus_register_driver(%s) failed: %d\n",
-                      ibm->acpi->hid, ret);
+                      ibm->acpi->hid, rc);
                kfree(ibm->acpi->driver);
                ibm->acpi->driver = NULL;
-       } else if (!ret)
+       } else if (!rc)
                ibm->flags.acpi_driver_registered = 1;
 
-       return ret;
+       return rc;
 }
 
 
@@ -697,6 +706,108 @@ static struct ibm_struct thinkpad_acpi_driver_data = {
 static int hotkey_orig_status;
 static int hotkey_orig_mask;
 
+static struct attribute_set *hotkey_dev_attributes = NULL;
+
+/* sysfs hotkey enable ------------------------------------------------- */
+static ssize_t hotkey_enable_show(struct device *dev,
+                          struct device_attribute *attr,
+                          char *buf)
+{
+       int res, status, mask;
+
+       res = hotkey_get(&status, &mask);
+       if (res)
+               return res;
+
+       return snprintf(buf, PAGE_SIZE, "%d\n", status);
+}
+
+static ssize_t hotkey_enable_store(struct device *dev,
+                           struct device_attribute *attr,
+                           const char *buf, size_t count)
+{
+       unsigned long t;
+       int res, status, mask;
+
+       if (parse_strtoul(buf, 1, &t))
+               return -EINVAL;
+
+       res = hotkey_get(&status, &mask);
+       if (!res)
+               res = hotkey_set(t, mask);
+
+       return (res) ? res : count;
+}
+
+static struct device_attribute dev_attr_hotkey_enable =
+       __ATTR(enable, S_IWUSR | S_IRUGO,
+               hotkey_enable_show, hotkey_enable_store);
+
+/* sysfs hotkey mask --------------------------------------------------- */
+static ssize_t hotkey_mask_show(struct device *dev,
+                          struct device_attribute *attr,
+                          char *buf)
+{
+       int res, status, mask;
+
+       res = hotkey_get(&status, &mask);
+       if (res)
+               return res;
+
+       return snprintf(buf, PAGE_SIZE, "0x%04x\n", mask);
+}
+
+static ssize_t hotkey_mask_store(struct device *dev,
+                           struct device_attribute *attr,
+                           const char *buf, size_t count)
+{
+       unsigned long t;
+       int res, status, mask;
+
+       if (parse_strtoul(buf, 0xffff, &t))
+               return -EINVAL;
+
+       res = hotkey_get(&status, &mask);
+       if (!res)
+               hotkey_set(status, t);
+
+       return (res) ? res : count;
+}
+
+static struct device_attribute dev_attr_hotkey_mask =
+       __ATTR(mask, S_IWUSR | S_IRUGO,
+               hotkey_mask_show, hotkey_mask_store);
+
+/* sysfs hotkey bios_enabled ------------------------------------------- */
+static ssize_t hotkey_bios_enabled_show(struct device *dev,
+                          struct device_attribute *attr,
+                          char *buf)
+{
+       return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_orig_status);
+}
+
+static struct device_attribute dev_attr_hotkey_bios_enabled =
+       __ATTR(bios_enabled, S_IRUGO, hotkey_bios_enabled_show, NULL);
+
+/* sysfs hotkey bios_mask ---------------------------------------------- */
+static ssize_t hotkey_bios_mask_show(struct device *dev,
+                          struct device_attribute *attr,
+                          char *buf)
+{
+       return snprintf(buf, PAGE_SIZE, "0x%04x\n", hotkey_orig_mask);
+}
+
+static struct device_attribute dev_attr_hotkey_bios_mask =
+       __ATTR(bios_mask, S_IRUGO, hotkey_bios_mask_show, NULL);
+
+/* --------------------------------------------------------------------- */
+
+static struct attribute *hotkey_mask_attributes[] = {
+       &dev_attr_hotkey_mask.attr,
+       &dev_attr_hotkey_bios_enabled.attr,
+       &dev_attr_hotkey_bios_mask.attr,
+};
+
 static int __init hotkey_init(struct ibm_init_struct *iibm)
 {
        int res;
@@ -713,6 +824,15 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
                str_supported(tp_features.hotkey));
 
        if (tp_features.hotkey) {
+               hotkey_dev_attributes = create_attr_set(4,
+                                               TPACPI_HOTKEY_SYSFS_GROUP);
+               if (!hotkey_dev_attributes)
+                       return -ENOMEM;
+               res = add_to_attr_set(hotkey_dev_attributes,
+                               &dev_attr_hotkey_enable.attr);
+               if (res)
+                       return res;
+
                /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
                   A30, R30, R31, T20-22, X20-21, X22-24 */
                tp_features.hotkey_mask =
@@ -722,6 +842,16 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
                        str_supported(tp_features.hotkey_mask));
 
                res = hotkey_get(&hotkey_orig_status, &hotkey_orig_mask);
+               if (!res && tp_features.hotkey_mask) {
+                       res = add_many_to_attr_set(hotkey_dev_attributes,
+                               hotkey_mask_attributes,
+                               ARRAY_SIZE(hotkey_mask_attributes));
+               }
+               if (!res)
+                       res = register_attr_set_with_sysfs(
+                                       hotkey_dev_attributes,
+                                       &tpacpi_pdev->dev.kobj);
+
                if (res)
                        return res;
        }
@@ -739,6 +869,11 @@ static void hotkey_exit(void)
                if (res)
                        printk(IBM_ERR "failed to restore hotkey to BIOS defaults\n");
        }
+
+       if (hotkey_dev_attributes) {
+               delete_attr_set(hotkey_dev_attributes, &tpacpi_pdev->dev.kobj);
+               hotkey_dev_attributes = NULL;
+       }
 }
 
 static void hotkey_notify(struct ibm_struct *ibm, u32 event)
@@ -789,6 +924,7 @@ static int hotkey_set(int status, int mask)
        return 0;
 }
 
+/* procfs -------------------------------------------------------------- */
 static int hotkey_read(char *p)
 {
        int res, status, mask;
@@ -884,8 +1020,54 @@ static struct ibm_struct hotkey_driver_data = {
  * Bluetooth subdriver
  */
 
+/* sysfs bluetooth enable ---------------------------------------------- */
+static ssize_t bluetooth_enable_show(struct device *dev,
+                          struct device_attribute *attr,
+                          char *buf)
+{
+       int status;
+
+       status = bluetooth_get_radiosw();
+       if (status < 0)
+               return status;
+
+       return snprintf(buf, PAGE_SIZE, "%d\n", status ? 1 : 0);
+}
+
+static ssize_t bluetooth_enable_store(struct device *dev,
+                           struct device_attribute *attr,
+                           const char *buf, size_t count)
+{
+       unsigned long t;
+       int res;
+
+       if (parse_strtoul(buf, 1, &t))
+               return -EINVAL;
+
+       res = bluetooth_set_radiosw(t);
+
+       return (res) ? res : count;
+}
+
+static struct device_attribute dev_attr_bluetooth_enable =
+       __ATTR(enable, S_IWUSR | S_IRUGO,
+               bluetooth_enable_show, bluetooth_enable_store);
+
+/* --------------------------------------------------------------------- */
+
+static struct attribute *bluetooth_attributes[] = {
+       &dev_attr_bluetooth_enable.attr,
+       NULL
+};
+
+static const struct attribute_group bluetooth_attr_group = {
+       .name = TPACPI_BLUETH_SYSFS_GROUP,
+       .attrs = bluetooth_attributes,
+};
+
 static int __init bluetooth_init(struct ibm_init_struct *iibm)
 {
+       int res;
        int status = 0;
 
        vdbg_printk(TPACPI_DBG_INIT, "initializing bluetooth subdriver\n");
@@ -901,17 +1083,29 @@ static int __init bluetooth_init(struct ibm_init_struct *iibm)
                str_supported(tp_features.bluetooth),
                status);
 
-       if (tp_features.bluetooth &&
-           !(status & TP_ACPI_BLUETOOTH_HWPRESENT)) {
-               /* no bluetooth hardware present in system */
-               tp_features.bluetooth = 0;
-               dbg_printk(TPACPI_DBG_INIT,
-                          "bluetooth hardware not installed\n");
+       if (tp_features.bluetooth) {
+               if (!(status & TP_ACPI_BLUETOOTH_HWPRESENT)) {
+                       /* no bluetooth hardware present in system */
+                       tp_features.bluetooth = 0;
+                       dbg_printk(TPACPI_DBG_INIT,
+                                  "bluetooth hardware not installed\n");
+               } else {
+                       res = sysfs_create_group(&tpacpi_pdev->dev.kobj,
+                                       &bluetooth_attr_group);
+                       if (res)
+                               return res;
+               }
        }
 
        return (tp_features.bluetooth)? 0 : 1;
 }
 
+static void bluetooth_exit(void)
+{
+       sysfs_remove_group(&tpacpi_pdev->dev.kobj,
+                       &bluetooth_attr_group);
+}
+
 static int bluetooth_get_radiosw(void)
 {
        int status;
@@ -944,6 +1138,7 @@ static int bluetooth_set_radiosw(int radio_on)
        return 0;
 }
 
+/* procfs -------------------------------------------------------------- */
 static int bluetooth_read(char *p)
 {
        int len = 0;
@@ -983,14 +1178,61 @@ static struct ibm_struct bluetooth_driver_data = {
        .name = "bluetooth",
        .read = bluetooth_read,
        .write = bluetooth_write,
+       .exit = bluetooth_exit,
 };
 
 /*************************************************************************
  * Wan subdriver
  */
 
+/* sysfs wan enable ---------------------------------------------------- */
+static ssize_t wan_enable_show(struct device *dev,
+                          struct device_attribute *attr,
+                          char *buf)
+{
+       int status;
+
+       status = wan_get_radiosw();
+       if (status < 0)
+               return status;
+
+       return snprintf(buf, PAGE_SIZE, "%d\n", status ? 1 : 0);
+}
+
+static ssize_t wan_enable_store(struct device *dev,
+                           struct device_attribute *attr,
+                           const char *buf, size_t count)
+{
+       unsigned long t;
+       int res;
+
+       if (parse_strtoul(buf, 1, &t))
+               return -EINVAL;
+
+       res = wan_set_radiosw(t);
+
+       return (res) ? res : count;
+}
+
+static struct device_attribute dev_attr_wan_enable =
+       __ATTR(enable, S_IWUSR | S_IRUGO,
+               wan_enable_show, wan_enable_store);
+
+/* --------------------------------------------------------------------- */
+
+static struct attribute *wan_attributes[] = {
+       &dev_attr_wan_enable.attr,
+       NULL
+};
+
+static const struct attribute_group wan_attr_group = {
+       .name = TPACPI_WAN_SYSFS_GROUP,
+       .attrs = wan_attributes,
+};
+
 static int __init wan_init(struct ibm_init_struct *iibm)
 {
+       int res;
        int status = 0;
 
        vdbg_printk(TPACPI_DBG_INIT, "initializing wan subdriver\n");
@@ -1004,17 +1246,29 @@ static int __init wan_init(struct ibm_init_struct *iibm)
                str_supported(tp_features.wan),
                status);
 
-       if (tp_features.wan &&
-           !(status & TP_ACPI_WANCARD_HWPRESENT)) {
-               /* no wan hardware present in system */
-               tp_features.wan = 0;
-               dbg_printk(TPACPI_DBG_INIT,
-                          "wan hardware not installed\n");
+       if (tp_features.wan) {
+               if (!(status & TP_ACPI_WANCARD_HWPRESENT)) {
+                       /* no wan hardware present in system */
+                       tp_features.wan = 0;
+                       dbg_printk(TPACPI_DBG_INIT,
+                                  "wan hardware not installed\n");
+               } else {
+                       res = sysfs_create_group(&tpacpi_pdev->dev.kobj,
+                                       &wan_attr_group);
+                       if (res)
+                               return res;
+               }
        }
 
        return (tp_features.wan)? 0 : 1;
 }
 
+static void wan_exit(void)
+{
+       sysfs_remove_group(&tpacpi_pdev->dev.kobj,
+               &wan_attr_group);
+}
+
 static int wan_get_radiosw(void)
 {
        int status;
@@ -1047,6 +1301,7 @@ static int wan_set_radiosw(int radio_on)
        return 0;
 }
 
+/* procfs -------------------------------------------------------------- */
 static int wan_read(char *p)
 {
        int len = 0;
@@ -1086,6 +1341,7 @@ static struct ibm_struct wan_driver_data = {
        .name = "wan",
        .read = wan_read,
        .write = wan_write,
+       .exit = wan_exit,
        .flags.experimental = 1,
 };
 
@@ -1510,6 +1766,33 @@ IBM_HANDLE(dock, root, "\\_SB.GDCK",     /* X30, X31, X40 */
 /* don't list other alternatives as we install a notify handler on the 570 */
 IBM_HANDLE(pci, root, "\\_SB.PCI");    /* 570 */
 
+static struct tp_acpi_drv_struct ibm_dock_acpidriver[2] = {
+       {
+        .notify = dock_notify,
+        .handle = &dock_handle,
+        .type = ACPI_SYSTEM_NOTIFY,
+       },
+       {
+        .hid = IBM_PCI_HID,
+        .notify = dock_notify,
+        .handle = &pci_handle,
+        .type = ACPI_SYSTEM_NOTIFY,
+       },
+};
+
+static struct ibm_struct dock_driver_data[2] = {
+       {
+        .name = "dock",
+        .read = dock_read,
+        .write = dock_write,
+        .acpi = &ibm_dock_acpidriver[0],
+       },
+       {
+        .name = "dock",
+        .acpi = &ibm_dock_acpidriver[1],
+       },
+};
+
 #define dock_docked() (_sta(dock_handle) & 1)
 
 static int __init dock_init(struct ibm_init_struct *iibm)
@@ -1517,7 +1800,6 @@ static int __init dock_init(struct ibm_init_struct *iibm)
        vdbg_printk(TPACPI_DBG_INIT, "initializing dock subdriver\n");
 
        IBM_ACPIHANDLE_INIT(dock);
-       IBM_ACPIHANDLE_INIT(pci);
 
        vdbg_printk(TPACPI_DBG_INIT, "dock is %s\n",
                str_supported(dock_handle != NULL));
@@ -1525,6 +1807,28 @@ static int __init dock_init(struct ibm_init_struct *iibm)
        return (dock_handle)? 0 : 1;
 }
 
+static int __init dock_init2(struct ibm_init_struct *iibm)
+{
+       int dock2_needed;
+
+       vdbg_printk(TPACPI_DBG_INIT, "initializing dock subdriver part 2\n");
+
+       if (dock_driver_data[0].flags.acpi_driver_registered &&
+           dock_driver_data[0].flags.acpi_notify_installed) {
+               IBM_ACPIHANDLE_INIT(pci);
+               dock2_needed = (pci_handle != NULL);
+               vdbg_printk(TPACPI_DBG_INIT,
+                           "dock PCI handler for the TP 570 is %s\n",
+                           str_supported(dock2_needed));
+       } else {
+               vdbg_printk(TPACPI_DBG_INIT,
+               "dock subdriver part 2 not required\n");
+               dock2_needed = 0;
+       }
+
+       return (dock2_needed)? 0 : 1;
+}
+
 static void dock_notify(struct ibm_struct *ibm, u32 event)
 {
        int docked = dock_docked();
@@ -1586,33 +1890,6 @@ static int dock_write(char *buf)
        return 0;
 }
 
-static struct tp_acpi_drv_struct ibm_dock_acpidriver[2] = {
-       {
-        .notify = dock_notify,
-        .handle = &dock_handle,
-        .type = ACPI_SYSTEM_NOTIFY,
-       },
-       {
-        .hid = IBM_PCI_HID,
-        .notify = dock_notify,
-        .handle = &pci_handle,
-        .type = ACPI_SYSTEM_NOTIFY,
-       },
-};
-
-static struct ibm_struct dock_driver_data[2] = {
-       {
-        .name = "dock",
-        .read = dock_read,
-        .write = dock_write,
-        .acpi = &ibm_dock_acpidriver[0],
-       },
-       {
-        .name = "dock",
-        .acpi = &ibm_dock_acpidriver[1],
-       },
-};
-
 #endif /* CONFIG_THINKPAD_ACPI_DOCK */
 
 /*************************************************************************
@@ -1743,8 +2020,30 @@ static struct ibm_struct bay_driver_data = {
  * CMOS subdriver
  */
 
+/* sysfs cmos_command -------------------------------------------------- */
+static ssize_t cmos_command_store(struct device *dev,
+                           struct device_attribute *attr,
+                           const char *buf, size_t count)
+{
+       unsigned long cmos_cmd;
+       int res;
+
+       if (parse_strtoul(buf, 21, &cmos_cmd))
+               return -EINVAL;
+
+       res = issue_thinkpad_cmos_command(cmos_cmd);
+       return (res)? res : count;
+}
+
+static struct device_attribute dev_attr_cmos_command =
+       __ATTR(cmos_command, S_IWUSR, NULL, cmos_command_store);
+
+/* --------------------------------------------------------------------- */
+
 static int __init cmos_init(struct ibm_init_struct *iibm)
 {
+       int res;
+
        vdbg_printk(TPACPI_DBG_INIT,
                "initializing cmos commands subdriver\n");
 
@@ -1752,9 +2051,19 @@ static int __init cmos_init(struct ibm_init_struct *iibm)
 
        vdbg_printk(TPACPI_DBG_INIT, "cmos commands are %s\n",
                str_supported(cmos_handle != NULL));
+
+       res = device_create_file(&tpacpi_pdev->dev, &dev_attr_cmos_command);
+       if (res)
+               return res;
+
        return (cmos_handle)? 0 : 1;
 }
 
+static void cmos_exit(void)
+{
+       device_remove_file(&tpacpi_pdev->dev, &dev_attr_cmos_command);
+}
+
 static int cmos_read(char *p)
 {
        int len = 0;
@@ -1795,6 +2104,7 @@ static struct ibm_struct cmos_driver_data = {
        .name = "cmos",
        .read = cmos_read,
        .write = cmos_write,
+       .exit = cmos_exit,
 };
 
 /*************************************************************************
@@ -2381,8 +2691,9 @@ static int __init brightness_init(struct ibm_init_struct *iibm)
        if (b < 0)
                return b;
 
-       ibm_backlight_device = backlight_device_register("ibm", NULL, NULL,
-                                                        &ibm_backlight_data);
+       ibm_backlight_device = backlight_device_register(
+                                       TPACPI_BACKLIGHT_DEV_NAME, NULL, NULL,
+                                       &ibm_backlight_data);
        if (IS_ERR(ibm_backlight_device)) {
                printk(IBM_ERR "Could not register backlight device\n");
                return PTR_ERR(ibm_backlight_device);
@@ -2695,6 +3006,7 @@ static enum fan_control_access_mode fan_control_access_mode;
 static enum fan_control_commands fan_control_commands;
 
 static u8 fan_control_initial_status;
+static u8 fan_control_desired_level;
 
 static void fan_watchdog_fire(struct work_struct *ignored);
 static int fan_watchdog_maxinterval;
@@ -2708,8 +3020,230 @@ IBM_HANDLE(sfan, ec, "SFAN",    /* 570 */
           "JFNS",              /* 770x-JL */
           );                   /* all others */
 
+/*
+ * SYSFS fan layout: hwmon compatible (device)
+ *
+ * pwm*_enable:
+ *     0: "disengaged" mode
+ *     1: manual mode
+ *     2: native EC "auto" mode (recommended, hardware default)
+ *
+ * pwm*: set speed in manual mode, ignored otherwise.
+ *     0 is level 0; 255 is level 7. Intermediate points done with linear
+ *     interpolation.
+ *
+ * fan*_input: tachometer reading, RPM
+ *
+ *
+ * SYSFS fan layout: extensions
+ *
+ * fan_watchdog (driver):
+ *     fan watchdog interval in seconds, 0 disables (default), max 120
+ */
+
+/* sysfs fan pwm1_enable ----------------------------------------------- */
+static ssize_t fan_pwm1_enable_show(struct device *dev,
+                                   struct device_attribute *attr,
+                                   char *buf)
+{
+       int res, mode;
+       u8 status;
+
+       res = fan_get_status_safe(&status);
+       if (res)
+               return res;
+
+       if (unlikely(tp_features.fan_ctrl_status_undef)) {
+               if (status != fan_control_initial_status) {
+                       tp_features.fan_ctrl_status_undef = 0;
+               } else {
+                       /* Return most likely status. In fact, it
+                        * might be the only possible status */
+                       status = TP_EC_FAN_AUTO;
+               }
+       }
+
+       if (status & TP_EC_FAN_FULLSPEED) {
+               mode = 0;
+       } else if (status & TP_EC_FAN_AUTO) {
+               mode = 2;
+       } else
+               mode = 1;
+
+       return snprintf(buf, PAGE_SIZE, "%d\n", mode);
+}
+
+static ssize_t fan_pwm1_enable_store(struct device *dev,
+                                    struct device_attribute *attr,
+                                    const char *buf, size_t count)
+{
+       unsigned long t;
+       int res, level;
+
+       if (parse_strtoul(buf, 2, &t))
+               return -EINVAL;
+
+       switch (t) {
+       case 0:
+               level = TP_EC_FAN_FULLSPEED;
+               break;
+       case 1:
+               level = TPACPI_FAN_LAST_LEVEL;
+               break;
+       case 2:
+               level = TP_EC_FAN_AUTO;
+               break;
+       case 3:
+               /* reserved for software-controlled auto mode */
+               return -ENOSYS;
+       default:
+               return -EINVAL;
+       }
+
+       res = fan_set_level_safe(level);
+       if (res == -ENXIO)
+               return -EINVAL;
+       else if (res < 0)
+               return res;
+
+       fan_watchdog_reset();
+
+       return count;
+}
+
+static struct device_attribute dev_attr_fan_pwm1_enable =
+       __ATTR(pwm1_enable, S_IWUSR | S_IRUGO,
+               fan_pwm1_enable_show, fan_pwm1_enable_store);
+
+/* sysfs fan pwm1 ------------------------------------------------------ */
+static ssize_t fan_pwm1_show(struct device *dev,
+                            struct device_attribute *attr,
+                            char *buf)
+{
+       int res;
+       u8 status;
+
+       res = fan_get_status_safe(&status);
+       if (res)
+               return res;
+
+       if (unlikely(tp_features.fan_ctrl_status_undef)) {
+               if (status != fan_control_initial_status) {
+                       tp_features.fan_ctrl_status_undef = 0;
+               } else {
+                       status = TP_EC_FAN_AUTO;
+               }
+       }
+
+       if ((status &
+            (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) != 0)
+               status = fan_control_desired_level;
+
+       if (status > 7)
+               status = 7;
+
+       return snprintf(buf, PAGE_SIZE, "%u\n", (status * 255) / 7);
+}
+
+static ssize_t fan_pwm1_store(struct device *dev,
+                             struct device_attribute *attr,
+                             const char *buf, size_t count)
+{
+       unsigned long s;
+       int rc;
+       u8 status, newlevel;
+
+       if (parse_strtoul(buf, 255, &s))
+               return -EINVAL;
+
+       /* scale down from 0-255 to 0-7 */
+       newlevel = (s >> 5) & 0x07;
+
+       rc = mutex_lock_interruptible(&fan_mutex);
+       if (rc < 0)
+               return rc;
+
+       rc = fan_get_status(&status);
+       if (!rc && (status &
+                   (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) == 0) {
+               rc = fan_set_level(newlevel);
+               if (rc == -ENXIO)
+                       rc = -EINVAL;
+               else if (!rc) {
+                       fan_update_desired_level(newlevel);
+                       fan_watchdog_reset();
+               }
+       }
+
+       mutex_unlock(&fan_mutex);
+       return (rc)? rc : count;
+}
+
+static struct device_attribute dev_attr_fan_pwm1 =
+       __ATTR(pwm1, S_IWUSR | S_IRUGO,
+               fan_pwm1_show, fan_pwm1_store);
+
+/* sysfs fan fan1_input ------------------------------------------------ */
+static ssize_t fan_fan1_input_show(struct device *dev,
+                          struct device_attribute *attr,
+                          char *buf)
+{
+       int res;
+       unsigned int speed;
+
+       res = fan_get_speed(&speed);
+       if (res < 0)
+               return res;
+
+       return snprintf(buf, PAGE_SIZE, "%u\n", speed);
+}
+
+static struct device_attribute dev_attr_fan_fan1_input =
+       __ATTR(fan1_input, S_IRUGO,
+               fan_fan1_input_show, NULL);
+
+/* sysfs fan fan_watchdog (driver) ------------------------------------- */
+static ssize_t fan_fan_watchdog_show(struct device_driver *drv,
+                                    char *buf)
+{
+       return snprintf(buf, PAGE_SIZE, "%u\n", fan_watchdog_maxinterval);
+}
+
+static ssize_t fan_fan_watchdog_store(struct device_driver *drv,
+                                     const char *buf, size_t count)
+{
+       unsigned long t;
+
+       if (parse_strtoul(buf, 120, &t))
+               return -EINVAL;
+
+       if (!fan_control_allowed)
+               return -EPERM;
+
+       fan_watchdog_maxinterval = t;
+       fan_watchdog_reset();
+
+       return count;
+}
+
+static DRIVER_ATTR(fan_watchdog, S_IWUSR | S_IRUGO,
+               fan_fan_watchdog_show, fan_fan_watchdog_store);
+
+/* --------------------------------------------------------------------- */
+static struct attribute *fan_attributes[] = {
+       &dev_attr_fan_pwm1_enable.attr, &dev_attr_fan_pwm1.attr,
+       &dev_attr_fan_fan1_input.attr,
+       NULL
+};
+
+static const struct attribute_group fan_attr_group = {
+       .attrs = fan_attributes,
+};
+
 static int __init fan_init(struct ibm_init_struct *iibm)
 {
+       int rc;
+
        vdbg_printk(TPACPI_DBG_INIT, "initializing fan subdriver\n");
 
        mutex_init(&fan_mutex);
@@ -2718,6 +3252,7 @@ static int __init fan_init(struct ibm_init_struct *iibm)
        fan_control_commands = 0;
        fan_watchdog_maxinterval = 0;
        tp_features.fan_ctrl_status_undef = 0;
+       fan_control_desired_level = 7;
 
        IBM_ACPIHANDLE_INIT(fans);
        IBM_ACPIHANDLE_INIT(gfan);
@@ -2796,9 +3331,44 @@ static int __init fan_init(struct ibm_init_struct *iibm)
                  fan_control_access_mode != TPACPI_FAN_WR_NONE),
                fan_status_access_mode, fan_control_access_mode);
 
-       return (fan_status_access_mode != TPACPI_FAN_NONE ||
-               fan_control_access_mode != TPACPI_FAN_WR_NONE)?
-                       0 : 1;
+       /* fan control master switch */
+       if (!fan_control_allowed) {
+               fan_control_access_mode = TPACPI_FAN_WR_NONE;
+               fan_control_commands = 0;
+               dbg_printk(TPACPI_DBG_INIT,
+                          "fan control features disabled by parameter\n");
+       }
+
+       /* update fan_control_desired_level */
+       if (fan_status_access_mode != TPACPI_FAN_NONE)
+               fan_get_status_safe(NULL);
+
+       if (fan_status_access_mode != TPACPI_FAN_NONE ||
+           fan_control_access_mode != TPACPI_FAN_WR_NONE) {
+               rc = sysfs_create_group(&tpacpi_pdev->dev.kobj,
+                                        &fan_attr_group);
+               if (!(rc < 0))
+                       rc = driver_create_file(&tpacpi_pdriver.driver,
+                                       &driver_attr_fan_watchdog);
+               if (rc < 0)
+                       return rc;
+               return 0;
+       } else
+               return 1;
+}
+
+/*
+ * Call with fan_mutex held
+ */
+static void fan_update_desired_level(u8 status)
+{
+       if ((status &
+            (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) == 0) {
+               if (status > 7)
+                       fan_control_desired_level = 7;
+               else
+                       fan_control_desired_level = status;
+       }
 }
 
 static int fan_get_status(u8 *status)
@@ -2837,9 +3407,33 @@ static int fan_get_status(u8 *status)
        return 0;
 }
 
+static int fan_get_status_safe(u8 *status)
+{
+       int rc;
+       u8 s;
+
+       rc = mutex_lock_interruptible(&fan_mutex);
+       if (rc < 0)
+               return rc;
+       rc = fan_get_status(&s);
+       if (!rc)
+               fan_update_desired_level(s);
+       mutex_unlock(&fan_mutex);
+
+       if (status)
+               *status = s;
+
+       return rc;
+}
+
 static void fan_exit(void)
 {
        vdbg_printk(TPACPI_DBG_EXIT, "cancelling any pending fan watchdog tasks\n");
+
+       /* FIXME: can we really do this unconditionally? */
+       sysfs_remove_group(&tpacpi_pdev->dev.kobj, &fan_attr_group);
+       driver_remove_file(&tpacpi_pdriver.driver, &driver_attr_fan_watchdog);
+
        cancel_delayed_work(&fan_watchdog_task);
        flush_scheduled_work();
 }
@@ -2885,6 +3479,9 @@ static void fan_watchdog_reset(void)
 {
        static int fan_watchdog_active = 0;
 
+       if (fan_control_access_mode == TPACPI_FAN_WR_NONE)
+               return;
+
        if (fan_watchdog_active)
                cancel_delayed_work(&fan_watchdog_task);
 
@@ -2902,17 +3499,13 @@ static void fan_watchdog_reset(void)
 
 static int fan_set_level(int level)
 {
-       int res;
+       if (!fan_control_allowed)
+               return -EPERM;
 
        switch (fan_control_access_mode) {
        case TPACPI_FAN_WR_ACPI_SFAN:
                if (level >= 0 && level <= 7) {
-                       res = mutex_lock_interruptible(&fan_mutex);
-                       if (res < 0)
-                               return res;
-                       res = acpi_evalf(sfan_handle, NULL, NULL, "vd", level);
-                       mutex_unlock(&fan_mutex);
-                       if (!res)
+                       if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", level))
                                return -EIO;
                } else
                        return -EINVAL;
@@ -2925,12 +3518,14 @@ static int fan_set_level(int level)
                    ((level < 0) || (level > 7)))
                        return -EINVAL;
 
-               res = mutex_lock_interruptible(&fan_mutex);
-               if (res < 0)
-                       return res;
-               res = acpi_ec_write(fan_status_offset, level);
-               mutex_unlock(&fan_mutex);
-               if (!res)
+               /* safety net should the EC not support AUTO
+                * or FULLSPEED mode bits and just ignore them */
+               if (level & TP_EC_FAN_FULLSPEED)
+                       level |= 7;     /* safety min speed 7 */
+               else if (level & TP_EC_FAN_FULLSPEED)
+                       level |= 4;     /* safety min speed 4 */
+
+               if (!acpi_ec_write(fan_status_offset, level))
                        return -EIO;
                else
                        tp_features.fan_ctrl_status_undef = 0;
@@ -2942,11 +3537,36 @@ static int fan_set_level(int level)
        return 0;
 }
 
+static int fan_set_level_safe(int level)
+{
+       int rc;
+
+       if (!fan_control_allowed)
+               return -EPERM;
+
+       rc = mutex_lock_interruptible(&fan_mutex);
+       if (rc < 0)
+               return rc;
+
+       if (level == TPACPI_FAN_LAST_LEVEL)
+               level = fan_control_desired_level;
+
+       rc = fan_set_level(level);
+       if (!rc)
+               fan_update_desired_level(level);
+
+       mutex_unlock(&fan_mutex);
+       return rc;
+}
+
 static int fan_set_enable(void)
 {
        u8 s;
        int rc;
 
+       if (!fan_control_allowed)
+               return -EPERM;
+
        rc = mutex_lock_interruptible(&fan_mutex);
        if (rc < 0)
                return rc;
@@ -2959,8 +3579,10 @@ static int fan_set_enable(void)
                        break;
 
                /* Don't go out of emergency fan mode */
-               if (s != 7)
-                       s = TP_EC_FAN_AUTO;
+               if (s != 7) {
+                       s &= 0x07;
+                       s |= TP_EC_FAN_AUTO | 4; /* min fan speed 4 */
+               }
 
                if (!acpi_ec_write(fan_status_offset, s))
                        rc = -EIO;
@@ -2978,8 +3600,7 @@ static int fan_set_enable(void)
                s &= 0x07;
 
                /* Set fan to at least level 4 */
-               if (s < 4)
-                       s = 4;
+               s |= 4;
 
                if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", s))
                        rc= -EIO;
@@ -2999,6 +3620,9 @@ static int fan_set_disable(void)
 {
        int rc;
 
+       if (!fan_control_allowed)
+               return -EPERM;
+
        rc = mutex_lock_interruptible(&fan_mutex);
        if (rc < 0)
                return rc;
@@ -3009,19 +3633,24 @@ static int fan_set_disable(void)
        case TPACPI_FAN_WR_TPEC:
                if (!acpi_ec_write(fan_status_offset, 0x00))
                        rc = -EIO;
-               else
+               else {
+                       fan_control_desired_level = 0;
                        tp_features.fan_ctrl_status_undef = 0;
+               }
                break;
 
        case TPACPI_FAN_WR_ACPI_SFAN:
                if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", 0x00))
                        rc = -EIO;
+               else
+                       fan_control_desired_level = 0;
                break;
 
        default:
                rc = -ENXIO;
        }
 
+
        mutex_unlock(&fan_mutex);
        return rc;
 }
@@ -3030,6 +3659,9 @@ static int fan_set_speed(int speed)
 {
        int rc;
 
+       if (!fan_control_allowed)
+               return -EPERM;
+
        rc = mutex_lock_interruptible(&fan_mutex);
        if (rc < 0)
                return rc;
@@ -3063,7 +3695,7 @@ static int fan_read(char *p)
        switch (fan_status_access_mode) {
        case TPACPI_FAN_RD_ACPI_GFAN:
                /* 570, 600e/x, 770e, 770x */
-               if ((rc = fan_get_status(&status)) < 0)
+               if ((rc = fan_get_status_safe(&status)) < 0)
                        return rc;
 
                len += sprintf(p + len, "status:\t\t%s\n"
@@ -3073,7 +3705,7 @@ static int fan_read(char *p)
 
        case TPACPI_FAN_RD_TPEC:
                /* all except 570, 600e/x, 770e, 770x */
-               if ((rc = fan_get_status(&status)) < 0)
+               if ((rc = fan_get_status_safe(&status)) < 0)
                        return rc;
 
                if (unlikely(tp_features.fan_ctrl_status_undef)) {
@@ -3117,7 +3749,7 @@ static int fan_read(char *p)
 
                default:
                        len += sprintf(p + len, " (<level> is 0-7, "
-                                      "auto, disengaged)\n");
+                                      "auto, disengaged, full-speed)\n");
                        break;
                }
        }
@@ -3140,12 +3772,13 @@ static int fan_write_cmd_level(const char *cmd, int *rc)
 
        if (strlencmp(cmd, "level auto") == 0)
                level = TP_EC_FAN_AUTO;
-       else if (strlencmp(cmd, "level disengaged") == 0)
+       else if ((strlencmp(cmd, "level disengaged") == 0) |
+                (strlencmp(cmd, "level full-speed") == 0))
                level = TP_EC_FAN_FULLSPEED;
        else if (sscanf(cmd, "level %d", &level) != 1)
                return 0;
 
-       if ((*rc = fan_set_level(level)) == -ENXIO)
+       if ((*rc = fan_set_level_safe(level)) == -ENXIO)
                printk(IBM_ERR "level command accepted for unsupported "
                       "access mode %d", fan_control_access_mode);
 
@@ -3236,7 +3869,6 @@ static struct ibm_struct fan_driver_data = {
        .read = fan_read,
        .write = fan_write,
        .exit = fan_exit,
-       .flags.experimental = 1,
 };
 
 /****************************************************************************
@@ -3486,6 +4118,7 @@ static struct ibm_init_struct ibms_init[] __initdata = {
                .data = &dock_driver_data[0],
        },
        {
+               .init = dock_init2,
                .data = &dock_driver_data[1],
        },
 #endif
@@ -3557,6 +4190,9 @@ module_param_named(debug, dbg_level, uint, 0);
 static int force_load;
 module_param(force_load, int, 0);
 
+static int fan_control_allowed;
+module_param_named(fan_control, fan_control_allowed, int, 0);
+
 #define IBM_PARAM(feature) \
        module_param_call(feature, set_ibm_param, NULL, NULL, 0)