*/
#define IBM_VERSION "0.14"
+#define TPACPI_SYSFS_VERSION 0x000100
/*
* Changelog:
return status;
}
+static int issue_thinkpad_cmos_command(int cmos_cmd)
+{
+ if (!cmos_handle)
+ return -ENXIO;
+
+ if (!acpi_evalf(cmos_handle, NULL, NULL, "vd", cmos_cmd))
+ return -EIO;
+
+ return 0;
+}
+
/*************************************************************************
* ACPI device model
*/
-static void ibm_handle_init(char *name,
+static void drv_acpi_handle_init(char *name,
acpi_handle *handle, acpi_handle parent,
char **paths, int num_paths, char **path)
{
*handle = NULL;
}
-static void dispatch_notify(acpi_handle handle, u32 event, void *data)
+static void dispatch_acpi_notify(acpi_handle handle, u32 event, void *data)
{
struct ibm_struct *ibm = data;
- if (!ibm || !ibm->notify)
+ if (!ibm || !ibm->acpi || !ibm->acpi->notify)
return;
- ibm->notify(ibm, event);
+ ibm->acpi->notify(ibm, event);
}
-static int __init setup_notify(struct ibm_struct *ibm)
+static int __init setup_acpi_notify(struct ibm_struct *ibm)
{
acpi_status status;
int ret;
- if (!*ibm->handle)
+ BUG_ON(!ibm->acpi);
+
+ if (!*ibm->acpi->handle)
return 0;
dbg_printk(TPACPI_DBG_INIT,
"setting up ACPI notify for %s\n", ibm->name);
- ret = acpi_bus_get_device(*ibm->handle, &ibm->device);
+ ret = acpi_bus_get_device(*ibm->acpi->handle, &ibm->acpi->device);
if (ret < 0) {
printk(IBM_ERR "%s device not present\n", ibm->name);
return -ENODEV;
}
- acpi_driver_data(ibm->device) = ibm;
- sprintf(acpi_device_class(ibm->device), "%s/%s",
+ acpi_driver_data(ibm->acpi->device) = ibm;
+ sprintf(acpi_device_class(ibm->acpi->device), "%s/%s",
IBM_ACPI_EVENT_PREFIX,
ibm->name);
- status = acpi_install_notify_handler(*ibm->handle, ibm->type,
- dispatch_notify, ibm);
+ status = acpi_install_notify_handler(*ibm->acpi->handle,
+ ibm->acpi->type, dispatch_acpi_notify, ibm);
if (ACPI_FAILURE(status)) {
if (status == AE_ALREADY_EXISTS) {
printk(IBM_NOTICE "another device driver is already handling %s events\n",
}
return -ENODEV;
}
- ibm->flags.notify_installed = 1;
+ ibm->flags.acpi_notify_installed = 1;
return 0;
}
-static int __init ibm_device_add(struct acpi_device *device)
+static int __init tpacpi_device_add(struct acpi_device *device)
{
return 0;
}
dbg_printk(TPACPI_DBG_INIT,
"registering %s as an ACPI driver\n", ibm->name);
- ibm->driver = kzalloc(sizeof(struct acpi_driver), GFP_KERNEL);
- if (!ibm->driver) {
+ BUG_ON(!ibm->acpi);
+
+ ibm->acpi->driver = kzalloc(sizeof(struct acpi_driver), GFP_KERNEL);
+ if (!ibm->acpi->driver) {
printk(IBM_ERR "kzalloc(ibm->driver) failed\n");
return -ENOMEM;
}
- sprintf(ibm->driver->name, "%s_%s", IBM_NAME, ibm->name);
- ibm->driver->ids = ibm->hid;
- ibm->driver->ops.add = &ibm_device_add;
+ sprintf(ibm->acpi->driver->name, "%s_%s", IBM_NAME, ibm->name);
+ ibm->acpi->driver->ids = ibm->acpi->hid;
+ ibm->acpi->driver->ops.add = &tpacpi_device_add;
- ret = acpi_bus_register_driver(ibm->driver);
+ ret = acpi_bus_register_driver(ibm->acpi->driver);
if (ret < 0) {
printk(IBM_ERR "acpi_bus_register_driver(%s) failed: %d\n",
- ibm->hid, ret);
- kfree(ibm->driver);
- ibm->driver = NULL;
+ ibm->acpi->hid, ret);
+ kfree(ibm->acpi->driver);
+ ibm->acpi->driver = NULL;
} else if (!ret)
- ibm->flags.driver_registered = 1;
+ ibm->flags.acpi_driver_registered = 1;
return ret;
}
****************************************************************************
****************************************************************************/
-static int dispatch_read(char *page, char **start, off_t off, int count,
- int *eof, void *data)
+static int dispatch_procfs_read(char *page, char **start, off_t off,
+ int count, int *eof, void *data)
{
struct ibm_struct *ibm = data;
int len;
return len;
}
-static int dispatch_write(struct file *file, const char __user * userbuf,
- unsigned long count, void *data)
+static int dispatch_procfs_write(struct file *file,
+ const char __user * userbuf,
+ unsigned long count, void *data)
{
struct ibm_struct *ibm = data;
char *kernbuf;
}
+/****************************************************************************
+ ****************************************************************************
+ *
+ * Device model: hwmon and platform
+ *
+ ****************************************************************************
+ ****************************************************************************/
+
+static struct platform_device *tpacpi_pdev = NULL;
+static struct class_device *tpacpi_hwmon = NULL;
+
+static struct platform_driver tpacpi_pdriver = {
+ .driver = {
+ .name = IBM_DRVR_NAME,
+ .owner = THIS_MODULE,
+ },
+};
+
+
+/*************************************************************************
+ * thinkpad-acpi driver attributes
+ */
+
+/* interface_version --------------------------------------------------- */
+static ssize_t tpacpi_driver_interface_version_show(
+ struct device_driver *drv,
+ char *buf)
+{
+ return snprintf(buf, PAGE_SIZE, "0x%08x\n", TPACPI_SYSFS_VERSION);
+}
+
+static DRIVER_ATTR(interface_version, S_IRUGO,
+ tpacpi_driver_interface_version_show, NULL);
+
+/* debug_level --------------------------------------------------------- */
+static ssize_t tpacpi_driver_debug_show(struct device_driver *drv,
+ char *buf)
+{
+ return snprintf(buf, PAGE_SIZE, "0x%04x\n", dbg_level);
+}
+
+static ssize_t tpacpi_driver_debug_store(struct device_driver *drv,
+ const char *buf, size_t count)
+{
+ unsigned long t;
+ char *endp;
+
+ t = simple_strtoul(buf, &endp, 0);
+ while (*endp && isspace(*endp))
+ endp++;
+ if (*endp)
+ return -EINVAL;
+
+ dbg_level = t;
+
+ return count;
+}
+
+static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO,
+ tpacpi_driver_debug_show, tpacpi_driver_debug_store);
+
+/* version ------------------------------------------------------------- */
+static ssize_t tpacpi_driver_version_show(struct device_driver *drv,
+ char *buf)
+{
+ return snprintf(buf, PAGE_SIZE, "%s v%s\n", IBM_DESC, IBM_VERSION);
+}
+
+static DRIVER_ATTR(version, S_IRUGO,
+ tpacpi_driver_version_show, NULL);
+
+/* --------------------------------------------------------------------- */
+
+static struct driver_attribute* tpacpi_driver_attributes[] = {
+ &driver_attr_debug_level, &driver_attr_version,
+ &driver_attr_interface_version,
+};
+
+static int __init tpacpi_create_driver_attributes(struct device_driver *drv)
+{
+ int i, res;
+
+ i = 0;
+ res = 0;
+ while (!res && i < ARRAY_SIZE(tpacpi_driver_attributes)) {
+ res = driver_create_file(drv, tpacpi_driver_attributes[i]);
+ i++;
+ }
+
+ return res;
+}
+
+static void tpacpi_remove_driver_attributes(struct device_driver *drv)
+{
+ int i;
+
+ for(i = 0; i < ARRAY_SIZE(tpacpi_driver_attributes); i++)
+ driver_remove_file(drv, tpacpi_driver_attributes[i]);
+}
+
/****************************************************************************
****************************************************************************
*
* Hotkey subdriver
*/
-static int hotkey_supported;
-static int hotkey_mask_supported;
static int hotkey_orig_status;
static int hotkey_orig_mask;
static int __init hotkey_init(struct ibm_init_struct *iibm)
{
+ int res;
+
vdbg_printk(TPACPI_DBG_INIT, "initializing hotkey subdriver\n");
- IBM_HANDLE_INIT(hkey);
+ IBM_ACPIHANDLE_INIT(hkey);
/* hotkey not supported on 570 */
- hotkey_supported = hkey_handle != NULL;
+ tp_features.hotkey = hkey_handle != NULL;
vdbg_printk(TPACPI_DBG_INIT, "hotkeys are %s\n",
- str_supported(hotkey_supported));
+ str_supported(tp_features.hotkey));
- if (hotkey_supported) {
+ if (tp_features.hotkey) {
/* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
A30, R30, R31, T20-22, X20-21, X22-24 */
- hotkey_mask_supported =
- acpi_evalf(hkey_handle, NULL, "DHKN", "qv");
+ tp_features.hotkey_mask =
+ acpi_evalf(hkey_handle, NULL, "DHKN", "qv");
vdbg_printk(TPACPI_DBG_INIT, "hotkey masks are %s\n",
- str_supported(hotkey_mask_supported));
+ str_supported(tp_features.hotkey_mask));
- if (!hotkey_get(&hotkey_orig_status, &hotkey_orig_mask))
- return -ENODEV;
+ res = hotkey_get(&hotkey_orig_status, &hotkey_orig_mask);
+ if (res)
+ return res;
}
- return (hotkey_supported)? 0 : 1;
+ return (tp_features.hotkey)? 0 : 1;
}
static void hotkey_exit(void)
{
- if (hotkey_supported) {
+ int res;
+
+ if (tp_features.hotkey) {
dbg_printk(TPACPI_DBG_EXIT, "restoring original hotkey mask\n");
- hotkey_set(hotkey_orig_status, hotkey_orig_mask);
+ res = hotkey_set(hotkey_orig_status, hotkey_orig_mask);
+ if (res)
+ printk(IBM_ERR "failed to restore hotkey to BIOS defaults\n");
}
}
int hkey;
if (acpi_evalf(hkey_handle, &hkey, "MHKP", "d"))
- acpi_bus_generate_event(ibm->device, event, hkey);
+ acpi_bus_generate_event(ibm->acpi->device, event, hkey);
else {
printk(IBM_ERR "unknown hotkey event %d\n", event);
- acpi_bus_generate_event(ibm->device, event, 0);
+ acpi_bus_generate_event(ibm->acpi->device, event, 0);
}
}
static int hotkey_get(int *status, int *mask)
{
if (!acpi_evalf(hkey_handle, status, "DHKC", "d"))
- return 0;
+ return -EIO;
- if (hotkey_mask_supported)
+ if (tp_features.hotkey_mask)
if (!acpi_evalf(hkey_handle, mask, "DHKN", "d"))
- return 0;
+ return -EIO;
- return 1;
+ return 0;
}
static int hotkey_set(int status, int mask)
int i;
if (!acpi_evalf(hkey_handle, NULL, "MHKC", "vd", status))
- return 0;
+ return -EIO;
- if (hotkey_mask_supported)
+ if (tp_features.hotkey_mask)
for (i = 0; i < 32; i++) {
int bit = ((1 << i) & mask) != 0;
if (!acpi_evalf(hkey_handle,
NULL, "MHKM", "vdd", i + 1, bit))
- return 0;
+ return -EIO;
}
- return 1;
+ return 0;
}
static int hotkey_read(char *p)
{
- int status, mask;
+ int res, status, mask;
int len = 0;
- if (!hotkey_supported) {
+ if (!tp_features.hotkey) {
len += sprintf(p + len, "status:\t\tnot supported\n");
return len;
}
- if (!hotkey_get(&status, &mask))
- return -EIO;
+ res = hotkey_get(&status, &mask);
+ if (res)
+ return res;
len += sprintf(p + len, "status:\t\t%s\n", enabled(status, 0));
- if (hotkey_mask_supported) {
+ if (tp_features.hotkey_mask) {
len += sprintf(p + len, "mask:\t\t0x%04x\n", mask);
len += sprintf(p + len,
"commands:\tenable, disable, reset, <mask>\n");
static int hotkey_write(char *buf)
{
- int status, mask;
+ int res, status, mask;
char *cmd;
int do_cmd = 0;
- if (!hotkey_supported)
+ if (!tp_features.hotkey)
return -ENODEV;
- if (!hotkey_get(&status, &mask))
- return -EIO;
+ res = hotkey_get(&status, &mask);
+ if (res)
+ return res;
while ((cmd = next_cmd(&buf))) {
if (strlencmp(cmd, "enable") == 0) {
do_cmd = 1;
}
- if (do_cmd && !hotkey_set(status, mask))
- return -EIO;
+ if (do_cmd) {
+ res = hotkey_set(status, mask);
+ if (res)
+ return res;
+ }
return 0;
}
+static struct tp_acpi_drv_struct ibm_hotkey_acpidriver = {
+ .hid = IBM_HKEY_HID,
+ .notify = hotkey_notify,
+ .handle = &hkey_handle,
+ .type = ACPI_DEVICE_NOTIFY,
+};
+
static struct ibm_struct hotkey_driver_data = {
.name = "hotkey",
- .hid = IBM_HKEY_HID,
.read = hotkey_read,
.write = hotkey_write,
.exit = hotkey_exit,
- .notify = hotkey_notify,
- .handle = &hkey_handle,
- .type = ACPI_DEVICE_NOTIFY,
+ .acpi = &ibm_hotkey_acpidriver,
};
/*************************************************************************
* Bluetooth subdriver
*/
-static int bluetooth_supported;
-
static int __init bluetooth_init(struct ibm_init_struct *iibm)
{
+ int status = 0;
+
vdbg_printk(TPACPI_DBG_INIT, "initializing bluetooth subdriver\n");
- IBM_HANDLE_INIT(hkey);
+ IBM_ACPIHANDLE_INIT(hkey);
/* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
- bluetooth_supported = hkey_handle &&
- acpi_evalf(hkey_handle, NULL, "GBDC", "qv");
+ tp_features.bluetooth = hkey_handle &&
+ acpi_evalf(hkey_handle, &status, "GBDC", "qd");
+
+ vdbg_printk(TPACPI_DBG_INIT, "bluetooth is %s, status 0x%02x\n",
+ str_supported(tp_features.bluetooth),
+ status);
- vdbg_printk(TPACPI_DBG_INIT, "bluetooth is %s\n",
- str_supported(bluetooth_supported));
+ 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");
+ }
- return (bluetooth_supported)? 0 : 1;
+ return (tp_features.bluetooth)? 0 : 1;
}
-static int bluetooth_status(void)
+static int bluetooth_get_radiosw(void)
{
int status;
- if (!bluetooth_supported ||
- !acpi_evalf(hkey_handle, &status, "GBDC", "d"))
- status = 0;
+ if (!tp_features.bluetooth)
+ return -ENODEV;
- return status;
+ if (!acpi_evalf(hkey_handle, &status, "GBDC", "d"))
+ return -EIO;
+
+ return ((status & TP_ACPI_BLUETOOTH_RADIOSSW) != 0);
+}
+
+static int bluetooth_set_radiosw(int radio_on)
+{
+ int status;
+
+ if (!tp_features.bluetooth)
+ return -ENODEV;
+
+ if (!acpi_evalf(hkey_handle, &status, "GBDC", "d"))
+ return -EIO;
+ if (radio_on)
+ status |= TP_ACPI_BLUETOOTH_RADIOSSW;
+ else
+ status &= ~TP_ACPI_BLUETOOTH_RADIOSSW;
+ if (!acpi_evalf(hkey_handle, NULL, "SBDC", "vd", status))
+ return -EIO;
+
+ return 0;
}
static int bluetooth_read(char *p)
{
int len = 0;
- int status = bluetooth_status();
+ int status = bluetooth_get_radiosw();
- if (!bluetooth_supported)
+ if (!tp_features.bluetooth)
len += sprintf(p + len, "status:\t\tnot supported\n");
- else if (!(status & 1))
- len += sprintf(p + len, "status:\t\tnot installed\n");
else {
- len += sprintf(p + len, "status:\t\t%s\n", enabled(status, 1));
+ len += sprintf(p + len, "status:\t\t%s\n",
+ (status)? "enabled" : "disabled");
len += sprintf(p + len, "commands:\tenable, disable\n");
}
static int bluetooth_write(char *buf)
{
- int status = bluetooth_status();
char *cmd;
- int do_cmd = 0;
- if (!bluetooth_supported)
+ if (!tp_features.bluetooth)
return -ENODEV;
while ((cmd = next_cmd(&buf))) {
if (strlencmp(cmd, "enable") == 0) {
- status |= 2;
+ bluetooth_set_radiosw(1);
} else if (strlencmp(cmd, "disable") == 0) {
- status &= ~2;
+ bluetooth_set_radiosw(0);
} else
return -EINVAL;
- do_cmd = 1;
}
- if (do_cmd && !acpi_evalf(hkey_handle, NULL, "SBDC", "vd", status))
- return -EIO;
-
return 0;
}
* Wan subdriver
*/
-static int wan_supported;
-
static int __init wan_init(struct ibm_init_struct *iibm)
{
+ int status = 0;
+
vdbg_printk(TPACPI_DBG_INIT, "initializing wan subdriver\n");
- IBM_HANDLE_INIT(hkey);
+ IBM_ACPIHANDLE_INIT(hkey);
- wan_supported = hkey_handle &&
- acpi_evalf(hkey_handle, NULL, "GWAN", "qv");
+ tp_features.wan = hkey_handle &&
+ acpi_evalf(hkey_handle, &status, "GWAN", "qd");
- vdbg_printk(TPACPI_DBG_INIT, "wan is %s\n",
- str_supported(wan_supported));
+ vdbg_printk(TPACPI_DBG_INIT, "wan is %s, status 0x%02x\n",
+ str_supported(tp_features.wan),
+ status);
- return (wan_supported)? 0 : 1;
+ 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");
+ }
+
+ return (tp_features.wan)? 0 : 1;
}
-static int wan_status(void)
+static int wan_get_radiosw(void)
{
int status;
- if (!wan_supported || !acpi_evalf(hkey_handle, &status, "GWAN", "d"))
- status = 0;
+ if (!tp_features.wan)
+ return -ENODEV;
- return status;
+ if (!acpi_evalf(hkey_handle, &status, "GWAN", "d"))
+ return -EIO;
+
+ return ((status & TP_ACPI_WANCARD_RADIOSSW) != 0);
+}
+
+static int wan_set_radiosw(int radio_on)
+{
+ int status;
+
+ if (!tp_features.wan)
+ return -ENODEV;
+
+ if (!acpi_evalf(hkey_handle, &status, "GWAN", "d"))
+ return -EIO;
+ if (radio_on)
+ status |= TP_ACPI_WANCARD_RADIOSSW;
+ else
+ status &= ~TP_ACPI_WANCARD_RADIOSSW;
+ if (!acpi_evalf(hkey_handle, NULL, "SWAN", "vd", status))
+ return -EIO;
+
+ return 0;
}
static int wan_read(char *p)
{
int len = 0;
- int status = wan_status();
+ int status = wan_get_radiosw();
- if (!wan_supported)
+ if (!tp_features.wan)
len += sprintf(p + len, "status:\t\tnot supported\n");
- else if (!(status & 1))
- len += sprintf(p + len, "status:\t\tnot installed\n");
else {
- len += sprintf(p + len, "status:\t\t%s\n", enabled(status, 1));
+ len += sprintf(p + len, "status:\t\t%s\n",
+ (status)? "enabled" : "disabled");
len += sprintf(p + len, "commands:\tenable, disable\n");
}
static int wan_write(char *buf)
{
- int status = wan_status();
char *cmd;
- int do_cmd = 0;
- if (!wan_supported)
+ if (!tp_features.wan)
return -ENODEV;
while ((cmd = next_cmd(&buf))) {
if (strlencmp(cmd, "enable") == 0) {
- status |= 2;
+ wan_set_radiosw(1);
} else if (strlencmp(cmd, "disable") == 0) {
- status &= ~2;
+ wan_set_radiosw(0);
} else
return -EINVAL;
- do_cmd = 1;
}
- if (do_cmd && !acpi_evalf(hkey_handle, NULL, "SWAN", "vd", status))
- return -EIO;
-
return 0;
}
vdbg_printk(TPACPI_DBG_INIT, "initializing video subdriver\n");
- IBM_HANDLE_INIT(vid);
- IBM_HANDLE_INIT(vid2);
+ IBM_ACPIHANDLE_INIT(vid);
+ IBM_ACPIHANDLE_INIT(vid2);
if (vid2_handle && acpi_evalf(NULL, &ivga, "\\IVGA", "d") && ivga)
/* G41, assume IVGA doesn't change */
static void video_exit(void)
{
- dbg_printk(TPACPI_DBG_EXIT, "restoring original video autoswitch mode\n");
- acpi_evalf(vid_handle, NULL, "_DOS", "vd", video_orig_autosw);
+ dbg_printk(TPACPI_DBG_EXIT,
+ "restoring original video autoswitch mode\n");
+ if (video_autosw_set(video_orig_autosw))
+ printk(IBM_ERR "error while trying to restore original "
+ "video autoswitch mode\n");
}
-static int video_status(void)
+static int video_outputsw_get(void)
{
int status = 0;
int i;
- if (video_supported == TPACPI_VIDEO_570) {
- if (acpi_evalf(NULL, &i, "\\_SB.PHS", "dd", 0x87))
- status = i & 3;
- } else if (video_supported == TPACPI_VIDEO_770) {
- if (acpi_evalf(NULL, &i, "\\VCDL", "d"))
- status |= 0x01 * i;
- if (acpi_evalf(NULL, &i, "\\VCDC", "d"))
- status |= 0x02 * i;
- } else if (video_supported == TPACPI_VIDEO_NEW) {
- acpi_evalf(NULL, NULL, "\\VUPS", "vd", 1);
- if (acpi_evalf(NULL, &i, "\\VCDC", "d"))
- status |= 0x02 * i;
-
- acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0);
- if (acpi_evalf(NULL, &i, "\\VCDL", "d"))
- status |= 0x01 * i;
- if (acpi_evalf(NULL, &i, "\\VCDD", "d"))
- status |= 0x08 * i;
+ switch (video_supported) {
+ case TPACPI_VIDEO_570:
+ if (!acpi_evalf(NULL, &i, "\\_SB.PHS", "dd",
+ TP_ACPI_VIDEO_570_PHSCMD))
+ return -EIO;
+ status = i & TP_ACPI_VIDEO_570_PHSMASK;
+ break;
+ case TPACPI_VIDEO_770:
+ if (!acpi_evalf(NULL, &i, "\\VCDL", "d"))
+ return -EIO;
+ if (i)
+ status |= TP_ACPI_VIDEO_S_LCD;
+ if (!acpi_evalf(NULL, &i, "\\VCDC", "d"))
+ return -EIO;
+ if (i)
+ status |= TP_ACPI_VIDEO_S_CRT;
+ break;
+ case TPACPI_VIDEO_NEW:
+ if (!acpi_evalf(NULL, NULL, "\\VUPS", "vd", 1) ||
+ !acpi_evalf(NULL, &i, "\\VCDC", "d"))
+ return -EIO;
+ if (i)
+ status |= TP_ACPI_VIDEO_S_CRT;
+
+ if (!acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0) ||
+ !acpi_evalf(NULL, &i, "\\VCDL", "d"))
+ return -EIO;
+ if (i)
+ status |= TP_ACPI_VIDEO_S_LCD;
+ if (!acpi_evalf(NULL, &i, "\\VCDD", "d"))
+ return -EIO;
+ if (i)
+ status |= TP_ACPI_VIDEO_S_DVI;
+ break;
+ default:
+ return -ENOSYS;
}
return status;
}
-static int video_autosw(void)
+static int video_outputsw_set(int status)
{
- int autosw = 0;
+ int autosw;
+ int res = 0;
- if (video_supported == TPACPI_VIDEO_570)
- acpi_evalf(vid_handle, &autosw, "SWIT", "d");
- else if (video_supported == TPACPI_VIDEO_770 ||
- video_supported == TPACPI_VIDEO_NEW)
- acpi_evalf(vid_handle, &autosw, "^VDEE", "d");
+ switch (video_supported) {
+ case TPACPI_VIDEO_570:
+ res = acpi_evalf(NULL, NULL,
+ "\\_SB.PHS2", "vdd",
+ TP_ACPI_VIDEO_570_PHS2CMD,
+ status | TP_ACPI_VIDEO_570_PHS2SET);
+ break;
+ case TPACPI_VIDEO_770:
+ autosw = video_autosw_get();
+ if (autosw < 0)
+ return autosw;
- return autosw & 1;
+ res = video_autosw_set(1);
+ if (res)
+ return res;
+ res = acpi_evalf(vid_handle, NULL,
+ "ASWT", "vdd", status * 0x100, 0);
+ if (!autosw && video_autosw_set(autosw)) {
+ printk(IBM_ERR "video auto-switch left enabled due to error\n");
+ return -EIO;
+ }
+ break;
+ case TPACPI_VIDEO_NEW:
+ res = acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0x80) &&
+ acpi_evalf(NULL, NULL, "\\VSDS", "vdd", status, 1);
+ break;
+ default:
+ return -ENOSYS;
+ }
+
+ return (res)? 0 : -EIO;
}
-static int video_switch(void)
+static int video_autosw_get(void)
{
- int autosw = video_autosw();
- int ret;
+ int autosw = 0;
- if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", 1))
- return -EIO;
- ret = video_supported == TPACPI_VIDEO_570 ?
- acpi_evalf(ec_handle, NULL, "_Q16", "v") :
- acpi_evalf(vid_handle, NULL, "VSWT", "v");
- acpi_evalf(vid_handle, NULL, "_DOS", "vd", autosw);
+ switch (video_supported) {
+ case TPACPI_VIDEO_570:
+ if (!acpi_evalf(vid_handle, &autosw, "SWIT", "d"))
+ return -EIO;
+ break;
+ case TPACPI_VIDEO_770:
+ case TPACPI_VIDEO_NEW:
+ if (!acpi_evalf(vid_handle, &autosw, "^VDEE", "d"))
+ return -EIO;
+ break;
+ default:
+ return -ENOSYS;
+ }
- return ret;
+ return autosw & 1;
}
-static int video_expand(void)
+static int video_autosw_set(int enable)
{
- if (video_supported == TPACPI_VIDEO_570)
- return acpi_evalf(ec_handle, NULL, "_Q17", "v");
- else if (video_supported == TPACPI_VIDEO_770)
- return acpi_evalf(vid_handle, NULL, "VEXP", "v");
- else
- return acpi_evalf(NULL, NULL, "\\VEXP", "v");
+ if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", (enable)? 1 : 0))
+ return -EIO;
+ return 0;
}
-static int video_switch2(int status)
+static int video_outputsw_cycle(void)
{
- int ret;
+ int autosw = video_autosw_get();
+ int res;
- if (video_supported == TPACPI_VIDEO_570) {
- ret = acpi_evalf(NULL, NULL,
- "\\_SB.PHS2", "vdd", 0x8b, status | 0x80);
- } else if (video_supported == TPACPI_VIDEO_770) {
- int autosw = video_autosw();
- if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", 1))
- return -EIO;
+ if (autosw < 0)
+ return autosw;
- ret = acpi_evalf(vid_handle, NULL,
- "ASWT", "vdd", status * 0x100, 0);
-
- acpi_evalf(vid_handle, NULL, "_DOS", "vd", autosw);
- } else {
- ret = acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0x80) &&
- acpi_evalf(NULL, NULL, "\\VSDS", "vdd", status, 1);
+ switch (video_supported) {
+ case TPACPI_VIDEO_570:
+ res = video_autosw_set(1);
+ if (res)
+ return res;
+ res = acpi_evalf(ec_handle, NULL, "_Q16", "v");
+ break;
+ case TPACPI_VIDEO_770:
+ case TPACPI_VIDEO_NEW:
+ res = video_autosw_set(1);
+ if (res)
+ return res;
+ res = acpi_evalf(vid_handle, NULL, "VSWT", "v");
+ break;
+ default:
+ return -ENOSYS;
+ }
+ if (!autosw && video_autosw_set(autosw)) {
+ printk(IBM_ERR "video auto-switch left enabled due to error\n");
+ return -EIO;
}
- return ret;
+ return (res)? 0 : -EIO;
+}
+
+static int video_expand_toggle(void)
+{
+ switch (video_supported) {
+ case TPACPI_VIDEO_570:
+ return acpi_evalf(ec_handle, NULL, "_Q17", "v")?
+ 0 : -EIO;
+ case TPACPI_VIDEO_770:
+ return acpi_evalf(vid_handle, NULL, "VEXP", "v")?
+ 0 : -EIO;
+ case TPACPI_VIDEO_NEW:
+ return acpi_evalf(NULL, NULL, "\\VEXP", "v")?
+ 0 : -EIO;
+ default:
+ return -ENOSYS;
+ }
+ /* not reached */
}
static int video_read(char *p)
{
- int status = video_status();
- int autosw = video_autosw();
+ int status, autosw;
int len = 0;
- if (!video_supported) {
+ if (video_supported == TPACPI_VIDEO_NONE) {
len += sprintf(p + len, "status:\t\tnot supported\n");
return len;
}
+ status = video_outputsw_get();
+ if (status < 0)
+ return status;
+
+ autosw = video_autosw_get();
+ if (autosw < 0)
+ return autosw;
+
len += sprintf(p + len, "status:\t\tsupported\n");
len += sprintf(p + len, "lcd:\t\t%s\n", enabled(status, 0));
len += sprintf(p + len, "crt:\t\t%s\n", enabled(status, 1));
{
char *cmd;
int enable, disable, status;
+ int res;
- if (!video_supported)
+ if (video_supported == TPACPI_VIDEO_NONE)
return -ENODEV;
- enable = disable = 0;
+ enable = 0;
+ disable = 0;
while ((cmd = next_cmd(&buf))) {
if (strlencmp(cmd, "lcd_enable") == 0) {
- enable |= 0x01;
+ enable |= TP_ACPI_VIDEO_S_LCD;
} else if (strlencmp(cmd, "lcd_disable") == 0) {
- disable |= 0x01;
+ disable |= TP_ACPI_VIDEO_S_LCD;
} else if (strlencmp(cmd, "crt_enable") == 0) {
- enable |= 0x02;
+ enable |= TP_ACPI_VIDEO_S_CRT;
} else if (strlencmp(cmd, "crt_disable") == 0) {
- disable |= 0x02;
+ disable |= TP_ACPI_VIDEO_S_CRT;
} else if (video_supported == TPACPI_VIDEO_NEW &&
strlencmp(cmd, "dvi_enable") == 0) {
- enable |= 0x08;
+ enable |= TP_ACPI_VIDEO_S_DVI;
} else if (video_supported == TPACPI_VIDEO_NEW &&
strlencmp(cmd, "dvi_disable") == 0) {
- disable |= 0x08;
+ disable |= TP_ACPI_VIDEO_S_DVI;
} else if (strlencmp(cmd, "auto_enable") == 0) {
- if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", 1))
- return -EIO;
+ res = video_autosw_set(1);
+ if (res)
+ return res;
} else if (strlencmp(cmd, "auto_disable") == 0) {
- if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", 0))
- return -EIO;
+ res = video_autosw_set(0);
+ if (res)
+ return res;
} else if (strlencmp(cmd, "video_switch") == 0) {
- if (!video_switch())
- return -EIO;
+ res = video_outputsw_cycle();
+ if (res)
+ return res;
} else if (strlencmp(cmd, "expand_toggle") == 0) {
- if (!video_expand())
- return -EIO;
+ res = video_expand_toggle();
+ if (res)
+ return res;
} else
return -EINVAL;
}
if (enable || disable) {
- status = (video_status() & 0x0f & ~disable) | enable;
- if (!video_switch2(status))
- return -EIO;
+ status = video_outputsw_get();
+ if (status < 0)
+ return status;
+ res = video_outputsw_set((status & ~disable) | enable);
+ if (res)
+ return res;
}
return 0;
* Light (thinklight) subdriver
*/
-static int light_supported;
-static int light_status_supported;
-
IBM_HANDLE(lght, root, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
IBM_HANDLE(ledb, ec, "LEDB"); /* G4x */
{
vdbg_printk(TPACPI_DBG_INIT, "initializing light subdriver\n");
- IBM_HANDLE_INIT(ledb);
- IBM_HANDLE_INIT(lght);
- IBM_HANDLE_INIT(cmos);
+ IBM_ACPIHANDLE_INIT(ledb);
+ IBM_ACPIHANDLE_INIT(lght);
+ IBM_ACPIHANDLE_INIT(cmos);
/* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
- light_supported = (cmos_handle || lght_handle) && !ledb_handle;
+ tp_features.light = (cmos_handle || lght_handle) && !ledb_handle;
- if (light_supported)
+ if (tp_features.light)
/* light status not supported on
570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
- light_status_supported = acpi_evalf(ec_handle, NULL,
- "KBLT", "qv");
+ tp_features.light_status =
+ acpi_evalf(ec_handle, NULL, "KBLT", "qv");
vdbg_printk(TPACPI_DBG_INIT, "light is %s\n",
- str_supported(light_supported));
+ str_supported(tp_features.light));
- return (light_supported)? 0 : 1;
+ return (tp_features.light)? 0 : 1;
}
static int light_read(char *p)
int len = 0;
int status = 0;
- if (!light_supported) {
+ if (!tp_features.light) {
len += sprintf(p + len, "status:\t\tnot supported\n");
- } else if (!light_status_supported) {
+ } else if (!tp_features.light_status) {
len += sprintf(p + len, "status:\t\tunknown\n");
len += sprintf(p + len, "commands:\ton, off\n");
} else {
char *cmd;
int success;
- if (!light_supported)
+ if (!tp_features.light)
return -ENODEV;
while ((cmd = next_cmd(&buf))) {
{
vdbg_printk(TPACPI_DBG_INIT, "initializing dock subdriver\n");
- IBM_HANDLE_INIT(dock);
- IBM_HANDLE_INIT(pci);
+ IBM_ACPIHANDLE_INIT(dock);
+ IBM_ACPIHANDLE_INIT(pci);
vdbg_printk(TPACPI_DBG_INIT, "dock is %s\n",
str_supported(dock_handle != NULL));
static void dock_notify(struct ibm_struct *ibm, u32 event)
{
int docked = dock_docked();
- int pci = ibm->hid && strstr(ibm->hid, IBM_PCI_HID);
+ int pci = ibm->acpi->hid && strstr(ibm->acpi->hid, IBM_PCI_HID);
if (event == 1 && !pci) /* 570 */
- acpi_bus_generate_event(ibm->device, event, 1); /* button */
+ acpi_bus_generate_event(ibm->acpi->device, event, 1); /* button */
else if (event == 1 && pci) /* 570 */
- acpi_bus_generate_event(ibm->device, event, 3); /* dock */
+ acpi_bus_generate_event(ibm->acpi->device, event, 3); /* dock */
else if (event == 3 && docked)
- acpi_bus_generate_event(ibm->device, event, 1); /* button */
+ acpi_bus_generate_event(ibm->acpi->device, event, 1); /* button */
else if (event == 3 && !docked)
- acpi_bus_generate_event(ibm->device, event, 2); /* undock */
+ acpi_bus_generate_event(ibm->acpi->device, event, 2); /* undock */
else if (event == 0 && docked)
- acpi_bus_generate_event(ibm->device, event, 3); /* dock */
+ acpi_bus_generate_event(ibm->acpi->device, event, 3); /* dock */
else {
printk(IBM_ERR "unknown dock event %d, status %d\n",
event, _sta(dock_handle));
- acpi_bus_generate_event(ibm->device, event, 0); /* unknown */
+ acpi_bus_generate_event(ibm->acpi->device, event, 0); /* unknown */
}
}
return 0;
}
-static struct ibm_struct dock_driver_data[2] = {
+static struct tp_acpi_drv_struct ibm_dock_acpidriver[2] = {
{
- .name = "dock",
- .read = dock_read,
- .write = dock_write,
.notify = dock_notify,
.handle = &dock_handle,
.type = ACPI_SYSTEM_NOTIFY,
},
{
- .name = "dock",
.hid = IBM_PCI_HID,
.notify = dock_notify,
.handle = &pci_handle,
},
};
+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 */
/*************************************************************************
*/
#ifdef CONFIG_THINKPAD_ACPI_BAY
-static int bay_status_supported;
-static int bay_status2_supported;
-static int bay_eject_supported;
-static int bay_eject2_supported;
-
IBM_HANDLE(bay, root, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */
"\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */
"\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */
{
vdbg_printk(TPACPI_DBG_INIT, "initializing bay subdriver\n");
- IBM_HANDLE_INIT(bay);
+ IBM_ACPIHANDLE_INIT(bay);
if (bay_handle)
- IBM_HANDLE_INIT(bay_ej);
- IBM_HANDLE_INIT(bay2);
+ IBM_ACPIHANDLE_INIT(bay_ej);
+ IBM_ACPIHANDLE_INIT(bay2);
if (bay2_handle)
- IBM_HANDLE_INIT(bay2_ej);
+ IBM_ACPIHANDLE_INIT(bay2_ej);
- bay_status_supported = bay_handle &&
- acpi_evalf(bay_handle, NULL, "_STA", "qv");
- bay_status2_supported = bay2_handle &&
- acpi_evalf(bay2_handle, NULL, "_STA", "qv");
+ tp_features.bay_status = bay_handle &&
+ acpi_evalf(bay_handle, NULL, "_STA", "qv");
+ tp_features.bay_status2 = bay2_handle &&
+ acpi_evalf(bay2_handle, NULL, "_STA", "qv");
- bay_eject_supported = bay_handle && bay_ej_handle &&
- (strlencmp(bay_ej_path, "_EJ0") == 0 || experimental);
- bay_eject2_supported = bay2_handle && bay2_ej_handle &&
- (strlencmp(bay2_ej_path, "_EJ0") == 0 || experimental);
+ tp_features.bay_eject = bay_handle && bay_ej_handle &&
+ (strlencmp(bay_ej_path, "_EJ0") == 0 || experimental);
+ tp_features.bay_eject2 = bay2_handle && bay2_ej_handle &&
+ (strlencmp(bay2_ej_path, "_EJ0") == 0 || experimental);
vdbg_printk(TPACPI_DBG_INIT,
"bay 1: status %s, eject %s; bay 2: status %s, eject %s\n",
- str_supported(bay_status_supported),
- str_supported(bay_eject_supported),
- str_supported(bay_status2_supported),
- str_supported(bay_eject2_supported));
+ str_supported(tp_features.bay_status),
+ str_supported(tp_features.bay_eject),
+ str_supported(tp_features.bay_status2),
+ str_supported(tp_features.bay_eject2));
- return (bay_status_supported || bay_eject_supported ||
- bay_status2_supported || bay_eject2_supported)? 0 : 1;
+ return (tp_features.bay_status || tp_features.bay_eject ||
+ tp_features.bay_status2 || tp_features.bay_eject2)? 0 : 1;
}
static void bay_notify(struct ibm_struct *ibm, u32 event)
{
- acpi_bus_generate_event(ibm->device, event, 0);
+ acpi_bus_generate_event(ibm->acpi->device, event, 0);
}
#define bay_occupied(b) (_sta(b##_handle) & 1)
int occupied2 = bay_occupied(bay2);
int eject, eject2;
- len += sprintf(p + len, "status:\t\t%s\n", bay_status_supported ?
- (occupied ? "occupied" : "unoccupied") :
- "not supported");
- if (bay_status2_supported)
+ len += sprintf(p + len, "status:\t\t%s\n",
+ tp_features.bay_status ?
+ (occupied ? "occupied" : "unoccupied") :
+ "not supported");
+ if (tp_features.bay_status2)
len += sprintf(p + len, "status2:\t%s\n", occupied2 ?
"occupied" : "unoccupied");
- eject = bay_eject_supported && occupied;
- eject2 = bay_eject2_supported && occupied2;
+ eject = tp_features.bay_eject && occupied;
+ eject2 = tp_features.bay_eject2 && occupied2;
if (eject && eject2)
len += sprintf(p + len, "commands:\teject, eject2\n");
{
char *cmd;
- if (!bay_eject_supported && !bay_eject2_supported)
+ if (!tp_features.bay_eject && !tp_features.bay_eject2)
return -ENODEV;
while ((cmd = next_cmd(&buf))) {
- if (bay_eject_supported && strlencmp(cmd, "eject") == 0) {
+ if (tp_features.bay_eject && strlencmp(cmd, "eject") == 0) {
if (!acpi_evalf(bay_ej_handle, NULL, NULL, "vd", 1))
return -EIO;
- } else if (bay_eject2_supported &&
+ } else if (tp_features.bay_eject2 &&
strlencmp(cmd, "eject2") == 0) {
if (!acpi_evalf(bay2_ej_handle, NULL, NULL, "vd", 1))
return -EIO;
return 0;
}
+static struct tp_acpi_drv_struct ibm_bay_acpidriver = {
+ .notify = bay_notify,
+ .handle = &bay_handle,
+ .type = ACPI_SYSTEM_NOTIFY,
+};
+
static struct ibm_struct bay_driver_data = {
.name = "bay",
.read = bay_read,
.write = bay_write,
- .notify = bay_notify,
- .handle = &bay_handle,
- .type = ACPI_SYSTEM_NOTIFY,
+ .acpi = &ibm_bay_acpidriver,
};
#endif /* CONFIG_THINKPAD_ACPI_BAY */
vdbg_printk(TPACPI_DBG_INIT,
"initializing cmos commands subdriver\n");
- IBM_HANDLE_INIT(cmos);
+ IBM_ACPIHANDLE_INIT(cmos);
vdbg_printk(TPACPI_DBG_INIT, "cmos commands are %s\n",
str_supported(cmos_handle != NULL));
return (cmos_handle)? 0 : 1;
}
-static int cmos_eval(int cmos_cmd)
-{
- if (cmos_handle)
- return acpi_evalf(cmos_handle, NULL, NULL, "vd", cmos_cmd);
- else
- return 1;
-}
-
static int cmos_read(char *p)
{
int len = 0;
static int cmos_write(char *buf)
{
char *cmd;
- int cmos_cmd;
-
- if (!cmos_handle)
- return -EINVAL;
+ int cmos_cmd, res;
while ((cmd = next_cmd(&buf))) {
if (sscanf(cmd, "%u", &cmos_cmd) == 1 &&
} else
return -EINVAL;
- if (!cmos_eval(cmos_cmd))
- return -EIO;
+ res = issue_thinkpad_cmos_command(cmos_cmd);
+ if (res)
+ return res;
}
return 0;
{
vdbg_printk(TPACPI_DBG_INIT, "initializing LED subdriver\n");
- IBM_HANDLE_INIT(led);
+ IBM_ACPIHANDLE_INIT(led);
if (!led_handle)
/* led not supported on R30, R31 */
{
vdbg_printk(TPACPI_DBG_INIT, "initializing beep subdriver\n");
- IBM_HANDLE_INIT(beep);
+ IBM_ACPIHANDLE_INIT(beep);
vdbg_printk(TPACPI_DBG_INIT, "beep is %s\n",
str_supported(beep_handle != NULL));
ta1 = ta2 = 0;
for (i = 0; i < 8; i++) {
- if (likely(acpi_ec_read(0x78 + i, &t))) {
+ if (acpi_ec_read(TP_EC_THERMAL_TMP0 + i, &t)) {
ta1 |= t;
} else {
ta1 = 0;
break;
}
- if (likely(acpi_ec_read(0xC0 + i, &t))) {
+ if (acpi_ec_read(TP_EC_THERMAL_TMP8 + i, &t)) {
ta2 |= t;
} else {
ta1 = 0;
return (thermal_read_mode != TPACPI_THERMAL_NONE)? 0 : 1;
}
-static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s)
+/* idx is zero-based */
+static int thermal_get_sensor(int idx, s32 *value)
{
- int i, t;
+ int t;
s8 tmp;
- char tmpi[] = "TMPi";
+ char tmpi[5];
- if (!s)
- return -EINVAL;
+ t = TP_EC_THERMAL_TMP0;
switch (thermal_read_mode) {
#if TPACPI_MAX_THERMAL_SENSORS >= 16
case TPACPI_THERMAL_TPEC_16:
- for (i = 0; i < 8; i++) {
- if (!acpi_ec_read(0xC0 + i, &tmp))
- return -EIO;
- s->temp[i + 8] = tmp * 1000;
+ if (idx >= 8 && idx <= 15) {
+ t = TP_EC_THERMAL_TMP8;
+ idx -= 8;
}
/* fallthrough */
#endif
case TPACPI_THERMAL_TPEC_8:
- for (i = 0; i < 8; i++) {
- if (!acpi_ec_read(0x78 + i, &tmp))
+ if (idx <= 7) {
+ if (!acpi_ec_read(t + idx, &tmp))
return -EIO;
- s->temp[i] = tmp * 1000;
+ *value = tmp * 1000;
+ return 0;
}
- return (thermal_read_mode == TPACPI_THERMAL_TPEC_16) ? 16 : 8;
+ break;
case TPACPI_THERMAL_ACPI_UPDT:
- if (!acpi_evalf(ec_handle, NULL, "UPDT", "v"))
- return -EIO;
- for (i = 0; i < 8; i++) {
- tmpi[3] = '0' + i;
+ if (idx <= 7) {
+ snprintf(tmpi, sizeof(tmpi), "TMP%c", '0' + idx);
+ if (!acpi_evalf(ec_handle, NULL, "UPDT", "v"))
+ return -EIO;
if (!acpi_evalf(ec_handle, &t, tmpi, "d"))
return -EIO;
- s->temp[i] = (t - 2732) * 100;
+ *value = (t - 2732) * 100;
+ return 0;
}
- return 8;
+ break;
case TPACPI_THERMAL_ACPI_TMP07:
- for (i = 0; i < 8; i++) {
- tmpi[3] = '0' + i;
+ if (idx <= 7) {
+ snprintf(tmpi, sizeof(tmpi), "TMP%c", '0' + idx);
if (!acpi_evalf(ec_handle, &t, tmpi, "d"))
return -EIO;
- s->temp[i] = t * 1000;
+ *value = t * 1000;
+ return 0;
}
- return 8;
+ break;
case TPACPI_THERMAL_NONE:
default:
- return 0;
+ return -ENOSYS;
}
+
+ return -EINVAL;
+}
+
+static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s)
+{
+ int res, i;
+ int n;
+
+ n = 8;
+ i = 0;
+
+ if (!s)
+ return -EINVAL;
+
+ if (thermal_read_mode == TPACPI_THERMAL_TPEC_16)
+ n = 16;
+
+ for(i = 0 ; i < n; i++) {
+ res = thermal_get_sensor(i, &s->temp[i]);
+ if (res)
+ return res;
+ }
+
+ return n;
}
static int thermal_read(char *p)
cmos_cmd = value > current_value ? TP_CMOS_BRIGHTNESS_UP : TP_CMOS_BRIGHTNESS_DOWN;
inc = value > current_value ? 1 : -1;
for (i = current_value; i != value; i += inc) {
- if (!cmos_eval(cmos_cmd))
+ if (issue_thinkpad_cmos_command(cmos_cmd))
return -EIO;
if (!acpi_ec_write(brightness_offset, i + inc))
return -EIO;
cmos_cmd = new_level > level ? TP_CMOS_VOLUME_UP : TP_CMOS_VOLUME_DOWN;
inc = new_level > level ? 1 : -1;
- if (mute && (!cmos_eval(cmos_cmd) ||
+ if (mute && (issue_thinkpad_cmos_command(cmos_cmd) ||
!acpi_ec_write(volume_offset, level)))
return -EIO;
for (i = level; i != new_level; i += inc)
- if (!cmos_eval(cmos_cmd) ||
+ if (issue_thinkpad_cmos_command(cmos_cmd) ||
!acpi_ec_write(volume_offset, i + inc))
return -EIO;
- if (mute && (!cmos_eval(TP_CMOS_VOLUME_MUTE) ||
+ if (mute && (issue_thinkpad_cmos_command(TP_CMOS_VOLUME_MUTE) ||
!acpi_ec_write(volume_offset,
new_level + mute)))
return -EIO;
if (new_mute != mute) { /* level doesn't change */
cmos_cmd = new_mute ? TP_CMOS_VOLUME_MUTE : TP_CMOS_VOLUME_UP;
- if (!cmos_eval(cmos_cmd) ||
+ if (issue_thinkpad_cmos_command(cmos_cmd) ||
!acpi_ec_write(volume_offset, level + new_mute))
return -EIO;
}
static enum fan_control_access_mode fan_control_access_mode;
static enum fan_control_commands fan_control_commands;
-static int fan_control_status_known;
static u8 fan_control_initial_status;
static void fan_watchdog_fire(struct work_struct *ignored);
fan_status_access_mode = TPACPI_FAN_NONE;
fan_control_access_mode = TPACPI_FAN_WR_NONE;
fan_control_commands = 0;
- fan_control_status_known = 1;
fan_watchdog_maxinterval = 0;
+ tp_features.fan_ctrl_status_undef = 0;
- IBM_HANDLE_INIT(fans);
- IBM_HANDLE_INIT(gfan);
- IBM_HANDLE_INIT(sfan);
+ IBM_ACPIHANDLE_INIT(fans);
+ IBM_ACPIHANDLE_INIT(gfan);
+ IBM_ACPIHANDLE_INIT(sfan);
if (gfan_handle) {
/* 570, 600e/x, 770e, 770x */
"fan_init: initial fan status is "
"unknown, assuming it is in auto "
"mode\n");
- fan_control_status_known = 0;
+ tp_features.fan_ctrl_status_undef = 1;
}
} else {
printk(IBM_ERR
static void fan_exit(void)
{
- vdbg_printk(TPACPI_DBG_EXIT, "cancelling any pending watchdogs\n");
+ vdbg_printk(TPACPI_DBG_EXIT, "cancelling any pending fan watchdog tasks\n");
cancel_delayed_work(&fan_watchdog_task);
flush_scheduled_work();
}
static void fan_watchdog_fire(struct work_struct *ignored)
{
+ int rc;
+
printk(IBM_NOTICE "fan watchdog: enabling fan\n");
- if (fan_set_enable()) {
- printk(IBM_ERR "fan watchdog: error while enabling fan\n");
+ rc = fan_set_enable();
+ if (rc < 0) {
+ printk(IBM_ERR "fan watchdog: error %d while enabling fan, "
+ "will try again later...\n", -rc);
/* reschedule for later */
fan_watchdog_reset();
}
if (!acpi_ec_write(fan_status_offset, level))
return -EIO;
else
- fan_control_status_known = 1;
+ tp_features.fan_ctrl_status_undef = 0;
break;
default:
if (!acpi_ec_write(fan_status_offset, s))
return -EIO;
else
- fan_control_status_known = 1;
+ tp_features.fan_ctrl_status_undef = 0;
break;
case TPACPI_FAN_WR_ACPI_SFAN:
if (!acpi_ec_write(fan_status_offset, 0x00))
return -EIO;
else
- fan_control_status_known = 1;
+ tp_features.fan_ctrl_status_undef = 0;
break;
case TPACPI_FAN_WR_ACPI_SFAN:
if ((rc = fan_get_status(&status)) < 0)
return rc;
- if (unlikely(!fan_control_status_known)) {
+ if (unlikely(tp_features.fan_ctrl_status_undef)) {
if (status != fan_control_initial_status)
- fan_control_status_known = 1;
+ tp_features.fan_ctrl_status_undef = 0;
else
/* Return most likely status. In fact, it
* might be the only possible status */
ibm->flags.init_called = 1;
}
- if (ibm->hid) {
- ret = register_tpacpi_subdriver(ibm);
- if (ret)
- goto err_out;
- }
+ if (ibm->acpi) {
+ if (ibm->acpi->hid) {
+ ret = register_tpacpi_subdriver(ibm);
+ if (ret)
+ goto err_out;
+ }
- if (ibm->notify) {
- ret = setup_notify(ibm);
- if (ret == -ENODEV) {
- printk(IBM_NOTICE "disabling subdriver %s\n",
- ibm->name);
- ret = 0;
- goto err_out;
+ if (ibm->acpi->notify) {
+ ret = setup_acpi_notify(ibm);
+ if (ret == -ENODEV) {
+ printk(IBM_NOTICE "disabling subdriver %s\n",
+ ibm->name);
+ ret = 0;
+ goto err_out;
+ }
+ if (ret < 0)
+ goto err_out;
}
- if (ret < 0)
- goto err_out;
}
dbg_printk(TPACPI_DBG_INIT,
}
entry->owner = THIS_MODULE;
entry->data = ibm;
- entry->read_proc = &dispatch_read;
+ entry->read_proc = &dispatch_procfs_read;
if (ibm->write)
- entry->write_proc = &dispatch_write;
+ entry->write_proc = &dispatch_procfs_write;
ibm->flags.proc_created = 1;
}
list_del_init(&ibm->all_drivers);
- if (ibm->flags.notify_installed) {
+ if (ibm->flags.acpi_notify_installed) {
dbg_printk(TPACPI_DBG_EXIT,
"%s: acpi_remove_notify_handler\n", ibm->name);
- acpi_remove_notify_handler(*ibm->handle, ibm->type,
- dispatch_notify);
- ibm->flags.notify_installed = 0;
+ BUG_ON(!ibm->acpi);
+ acpi_remove_notify_handler(*ibm->acpi->handle,
+ ibm->acpi->type,
+ dispatch_acpi_notify);
+ ibm->flags.acpi_notify_installed = 0;
+ ibm->flags.acpi_notify_installed = 0;
}
if (ibm->flags.proc_created) {
ibm->flags.proc_created = 0;
}
- if (ibm->flags.driver_registered) {
+ if (ibm->flags.acpi_driver_registered) {
dbg_printk(TPACPI_DBG_EXIT,
"%s: acpi_bus_unregister_driver\n", ibm->name);
- acpi_bus_unregister_driver(ibm->driver);
- kfree(ibm->driver);
- ibm->driver = NULL;
- ibm->flags.driver_registered = 0;
+ BUG_ON(!ibm->acpi);
+ acpi_bus_unregister_driver(ibm->acpi->driver);
+ kfree(ibm->acpi->driver);
+ ibm->acpi->driver = NULL;
+ ibm->flags.acpi_driver_registered = 0;
}
if (ibm->flags.init_called && ibm->exit) {
is_thinkpad = dmi_name_in_vendors("ThinkPad");
/* ec is required because many other handles are relative to it */
- IBM_HANDLE_INIT(ec);
+ IBM_ACPIHANDLE_INIT(ec);
if (!ec_handle) {
if (is_thinkpad)
printk(IBM_ERR
{
int ret, i;
+ /* Driver-level probe */
ret = probe_for_thinkpad();
if (ret)
return ret;
+ /* Driver initialization */
ibm_thinkpad_ec_found = check_dmi_for_ec();
- IBM_HANDLE_INIT(ecrd);
- IBM_HANDLE_INIT(ecwr);
+ IBM_ACPIHANDLE_INIT(ecrd);
+ IBM_ACPIHANDLE_INIT(ecwr);
- proc_dir = proc_mkdir(IBM_DIR, acpi_root_dir);
+ proc_dir = proc_mkdir(IBM_PROC_DIR, acpi_root_dir);
if (!proc_dir) {
- printk(IBM_ERR "unable to create proc dir %s", IBM_DIR);
+ printk(IBM_ERR "unable to create proc dir " IBM_PROC_DIR);
thinkpad_acpi_module_exit();
return -ENODEV;
}
proc_dir->owner = THIS_MODULE;
+ ret = platform_driver_register(&tpacpi_pdriver);
+ if (ret) {
+ printk(IBM_ERR "unable to register platform driver\n");
+ thinkpad_acpi_module_exit();
+ return ret;
+ }
+ ret = tpacpi_create_driver_attributes(&tpacpi_pdriver.driver);
+ if (ret) {
+ printk(IBM_ERR "unable to create sysfs driver attributes\n");
+ thinkpad_acpi_module_exit();
+ return ret;
+ }
+
+
+ /* Device initialization */
+ tpacpi_pdev = platform_device_register_simple(IBM_DRVR_NAME, -1,
+ NULL, 0);
+ if (IS_ERR(tpacpi_pdev)) {
+ ret = PTR_ERR(tpacpi_pdev);
+ tpacpi_pdev = NULL;
+ printk(IBM_ERR "unable to register platform device\n");
+ thinkpad_acpi_module_exit();
+ return ret;
+ }
+ tpacpi_hwmon = hwmon_device_register(&tpacpi_pdev->dev);
+ if (IS_ERR(tpacpi_hwmon)) {
+ ret = PTR_ERR(tpacpi_hwmon);
+ tpacpi_hwmon = NULL;
+ printk(IBM_ERR "unable to register hwmon device\n");
+ thinkpad_acpi_module_exit();
+ return ret;
+ }
for (i = 0; i < ARRAY_SIZE(ibms_init); i++) {
ret = ibm_init(&ibms_init[i]);
if (ret >= 0 && *ibms_init[i].param)
dbg_printk(TPACPI_DBG_INIT, "finished subdriver exit path...\n");
+ if (tpacpi_hwmon)
+ hwmon_device_unregister(tpacpi_hwmon);
+
+ if (tpacpi_pdev)
+ platform_device_unregister(tpacpi_pdev);
+
+ tpacpi_remove_driver_attributes(&tpacpi_pdriver.driver);
+ platform_driver_unregister(&tpacpi_pdriver);
+
if (proc_dir)
- remove_proc_entry(IBM_DIR, acpi_root_dir);
+ remove_proc_entry(IBM_PROC_DIR, acpi_root_dir);
- if (ibm_thinkpad_ec_found)
- kfree(ibm_thinkpad_ec_found);
+ kfree(ibm_thinkpad_ec_found);
}
module_init(thinkpad_acpi_module_init);