Skip to contentSkip to conversation

prepare thinkpad-acpi for sysfs conversion

GIT PULL In review Henrique de Moraes Holschuh 3 participants 28 messages Apr 21, 2007 – Apr 22, 2007 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

Len,

Please pull from:
git://repo.or.cz/linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git for-upstream/acpi-test

to receive the following patches *already* in acpi-test:
ACPI: ibm-acpi: kill trailing whitespace
ACPI: ibm-acpi: rename some identifiers
ACPI: ibm-acpi: add header file
ACPI: ibm-acpi: organize code
ACPI: ibm-acpi: update copyright notice
ACPI: ibm-acpi: update documentation
ACPI: ibm-acpi: move driver to drivers/misc hierarchy
ACPI: ibm-acpi: rename driver to thinkpad-acpi
ACPI: thinkpad-acpi: cleanup Kconfig for thinkpad-acpi
ACPI: thinkpad-acpi: add compatibility MODULE_ALIAS entry
ACPI: thinkpad-acpi: cleanup after rename
ACPI: thinkpad-acpi: update MAINTAINERS

(the above should not cause any probles if you already pulled from that branch, as I have not rebased the branch or modified any of the above patches)

and to receive the following **new** patches:
ACPI: thinkpad-acpi: rename register_ibmacpi_subdriver
ACPI: thinkpad-acpi: rename one stray use of ibm-acpi in a comment
ACPI: thinkpad-acpi: rename module glue
ACPI: thinkpad-acpi: rename thinkpad constants
ACPI: thinkpad-acpi: update fan firmware documentation
ACPI: thinkpad-acpi: add debug mode
ACPI: thinkpad-acpi: clean up probing and move init to subdrivers
ACPI: thinkpad-acpi: add subdriver debug statements
ACPI: thinkpad-acpi: uncouple subdriver init from ibms struct
ACPI: thinkpad-acpi: improve thinkpad detection
ACPI: thinkpad-acpi: use bitfields to hold subdriver flags
ACPI: thinkpad-acpi: use bitfields for module flags
ACPI: thinkpad-acpi: prepare for device model conversion
ACPI: thinkpad-acpi: mark acpi helper functions __must_check
ACPI: thinkpad-acpi: clean up hotkey subdriver
ACPI: thinkpad-acpi: cleanup bluetooth and wan for sysfs conversion
ACPI: thinkpad-acpi: cleanup video subdriver
ACPI: thinkpad-acpi: clean up CMOS commands subdriver
ACPI: thinkpad-acpi: cleanup thermal subdriver for sysfs conversion
ACPI: thinkpad-acpi: improve fan watchdog messages

This is the preparatory work for the sysfs conversion. Some of the conversion is already ready for merge (the part that is hwmon-compatible), and I will send a pull request with it soon.

Please merge for 2.6.22.

Signature · 10 lines
  "One disk to rule them all, One disk to find them. One disk to bring
  them all and in the darkness grind them. In the Land of Redmond
  where the shadows lie." -- The Silicon Valley Tarot
  Henrique Holschuh

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
#2 lore raw

PATCH 1/20 ACPI: thinkpad-acpi: rename register_ibmacpi_subdriver

In reply to a message not in the archive

Rename register_ibmacpi_subdriver to register_tpacpi_subdriver, as we are not called ibmacpi anymore.

---
 drivers/misc/thinkpad_acpi.c |    4 ++--
 drivers/misc/thinkpad_acpi.h |    2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/misc/thinkpad_acpi.c +2 -2
index ddaedf8..cac73e5 100644
@@ -345,7 +345,7 @@ static int __init ibm_device_add(struct acpi_device *device)
 	return 0;
 }
 
-static int __init register_ibmacpi_subdriver(struct ibm_struct *ibm)
+static int __init register_tpacpi_subdriver(struct ibm_struct *ibm)
 {
 	int ret;
 
@@ -2574,7 +2574,7 @@ static int __init ibm_init(struct ibm_struct *ibm)
 		return 0;
 
 	if (ibm->hid) {
-		ret = register_ibmacpi_subdriver(ibm);
+		ret = register_tpacpi_subdriver(ibm);
 		if (ret < 0)
 			return ret;
 		ibm->driver_registered = 1;
drivers/misc/thinkpad_acpi.h +1 -1
index 015c02b..b86e574 100644
@@ -157,7 +157,7 @@ static void ibm_exit(struct ibm_struct *ibm);
 static void dispatch_notify(acpi_handle handle, u32 event, void *data);
 static int setup_notify(struct ibm_struct *ibm);
 static int ibm_device_add(struct acpi_device *device);
-static int register_ibmacpi_subdriver(struct ibm_struct *ibm);
+static int register_tpacpi_subdriver(struct ibm_struct *ibm);
 
 
 /*
Signature · 8 lines
1.5.1


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
#3 lore raw

PATCH 2/20 ACPI: thinkpad-acpi: rename one stray use of ibm-acpi in a comment

In reply to a message not in the archive

Rename a stray use of ibm-acpi on a comment, no functional changes.

---
 drivers/misc/thinkpad_acpi.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/misc/thinkpad_acpi.c +1 -1
index cac73e5..4b43486 100644
@@ -459,7 +459,7 @@ static char *next_cmd(char **cmds)
  ****************************************************************************/
 
 /*************************************************************************
- * ibm-acpi init subdriver
+ * thinkpad-acpi init subdriver
  */
 
 static int thinkpad_acpi_driver_init(void)
Signature · 8 lines
1.5.1


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
#4 lore raw

PATCH 3/20 ACPI: thinkpad-acpi: rename module glue

In reply to a message not in the archive

Rename module init and exit functions, now that we are not called ibm-acpi anymore.

---
 drivers/misc/thinkpad_acpi.c |   12 ++++++------
 drivers/misc/thinkpad_acpi.h |    4 ++--
 2 files changed, 8 insertions(+), 8 deletions(-)
drivers/misc/thinkpad_acpi.c +6 -6
index 4b43486..80ef195 100644
@@ -2707,7 +2707,7 @@ IBM_PARAM(brightness);
 IBM_PARAM(volume);
 IBM_PARAM(fan);
 
-static int __init acpi_ibm_init(void)
+static int __init thinkpad_acpi_module_init(void)
 {
 	int ret, i;
 
@@ -2754,7 +2754,7 @@ static int __init acpi_ibm_init(void)
 	proc_dir = proc_mkdir(IBM_DIR, acpi_root_dir);
 	if (!proc_dir) {
 		printk(IBM_ERR "unable to create proc dir %s", IBM_DIR);
-		acpi_ibm_exit();
+		thinkpad_acpi_module_exit();
 		return -ENODEV;
 	}
 	proc_dir->owner = THIS_MODULE;
@@ -2764,7 +2764,7 @@ static int __init acpi_ibm_init(void)
 		if (ret >= 0 && *ibms[i].param)
 			ret = ibms[i].write(ibms[i].param);
 		if (ret < 0) {
-			acpi_ibm_exit();
+			thinkpad_acpi_module_exit();
 			return ret;
 		}
 	}
@@ -2772,7 +2772,7 @@ static int __init acpi_ibm_init(void)
 	return 0;
 }
 
-static void acpi_ibm_exit(void)
+static void thinkpad_acpi_module_exit(void)
 {
 	int i;
 
@@ -2786,5 +2786,5 @@ static void acpi_ibm_exit(void)
 		kfree(ibm_thinkpad_ec_found);
 }
 
-module_init(acpi_ibm_init);
-module_exit(acpi_ibm_exit);
+module_init(thinkpad_acpi_module_init);
+module_exit(thinkpad_acpi_module_exit);
drivers/misc/thinkpad_acpi.h +2 -2
index b86e574..8b2fd1a 100644
@@ -115,8 +115,8 @@ static int experimental;
 static char *ibm_thinkpad_ec_found;
 
 static char* check_dmi_for_ec(void);
-static int acpi_ibm_init(void);
-static void acpi_ibm_exit(void);
+static int thinkpad_acpi_module_init(void);
+static void thinkpad_acpi_module_exit(void);
 
 
 /****************************************************************************
Signature · 8 lines
1.5.1


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
#5 lore raw

PATCH 6/20 ACPI: thinkpad-acpi: add debug mode

In reply to a message not in the archive

Add a debug mode parameter and verbose debug mode Kconfig option.

---
 Documentation/thinkpad-acpi.txt |   13 +++++++++++++
 drivers/misc/Kconfig            |   10 ++++++++++
 drivers/misc/thinkpad_acpi.c    |    3 +++
 drivers/misc/thinkpad_acpi.h    |   13 +++++++++++++
 4 files changed, 39 insertions(+), 0 deletions(-)
Documentation/thinkpad-acpi.txt +13 -0
index af18d29..82fd822 100644
@@ -699,3 +699,16 @@ for example:
 
 	modprobe thinkpad_acpi hotkey=enable,0xffff video=auto_disable
 
+Enabling debugging output
+-------------------------
+
+The module takes a debug paramater which can be used to selectively
+enable various classes of debugging output, for example:
+
+	 modprobe ibm_acpi debug=0xffff
+
+will enable all debugging output classes.  It takes a bitmask, so
+to enable more than one output class, just add their values.
+
+There is also a kernel build option to enable more debugging
+information, which may be necessary to debug driver problems.
drivers/misc/Kconfig +10 -0
index 2cd96a3..44e4c8f 100644
@@ -137,6 +137,16 @@ config THINKPAD_ACPI
 
 	  If you have an IBM or Lenovo ThinkPad laptop, say Y or M here.
 
+config THINKPAD_ACPI_DEBUG
+	bool "Verbose debug mode"
+	depends on THINKPAD_ACPI
+	default n
+	---help---
+	  Enables extra debugging information, at the expense of a slightly
+	  increase in driver size.
+
+	  If you are not sure, say N here.
+
 config THINKPAD_ACPI_DOCK
 	bool "Legacy Docking Station Support"
 	depends on THINKPAD_ACPI
drivers/misc/thinkpad_acpi.c +3 -0
index 4131a78..7fa906f 100644
@@ -2684,6 +2684,9 @@ static int __init set_ibm_param(const char *val, struct kernel_param *kp)
 static int experimental;
 module_param(experimental, int, 0);
 
+static u32 dbg_level;
+module_param_named(debug, dbg_level, uint, 0);
+
 #define IBM_PARAM(feature) \
 	module_param_call(feature, set_ibm_param, NULL, NULL, 0)
 
drivers/misc/thinkpad_acpi.h +13 -0
index 02a297e..b2348d7 100644
@@ -74,6 +74,18 @@
 #define enabled(status,bit) ((status) & (1 << (bit)) ? "enabled" : "disabled")
 #define strlencmp(a,b) (strncmp((a), (b), strlen(b)))
 
+/* Debugging */
+#define TPACPI_DBG_ALL		0xffff
+#define dbg_printk(a_dbg_level, format, arg...) \
+	do { if (dbg_level & a_dbg_level) \
+		printk(IBM_DEBUG "%s: " format, __func__ , ## arg); } while (0)
+#ifdef CONFIG_THINKPAD_ACPI_DEBUG
+#define vdbg_printk(a_dbg_level, format, arg...) \
+	dbg_printk(a_dbg_level, format, ## arg)
+#else
+#define vdbg_printk(a_dbg_level, format, arg...)
+#endif
+
 /* ACPI HIDs */
 #define IBM_HKEY_HID    "IBM0068"
 #define IBM_PCI_HID     "PNP0A03"
@@ -112,6 +124,7 @@ static char *next_cmd(char **cmds);
 
 /* Module */
 static int experimental;
+static u32 dbg_level;
 static char *ibm_thinkpad_ec_found;
 
 static char* check_dmi_for_ec(void);
Signature · 8 lines
1.5.1


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
#6 lore raw

PATCH 7/20 ACPI: thinkpad-acpi: clean up probing and move init to subdrivers

In reply to a message not in the archive

Move most of the probing code to its own function, and most of the subdriver-specific init code into subdriver init functions.

This allows us to not define pci_handle unless the dock subdriver is enabled, as well.

This patch causes a minor userland interface change: if a subdriver doesn't detect a capability, /proc entries for it are not created anymore (as opposed to a /proc entry that just returned "unsupported").

---
 drivers/misc/thinkpad_acpi.c |  231 +++++++++++++++++++++++++++---------------
 drivers/misc/thinkpad_acpi.h |    4 +-
 2 files changed, 151 insertions(+), 84 deletions(-)
drivers/misc/thinkpad_acpi.c +149 -82
index 7fa906f..eeab394 100644
@@ -277,9 +277,9 @@ static int _sta(acpi_handle handle)
  * ACPI device model
  */
 
-static void __init ibm_handle_init(char *name,
-				   acpi_handle * handle, acpi_handle parent,
-				   char **paths, int num_paths, char **path)
+static void ibm_handle_init(char *name,
+			   acpi_handle *handle, acpi_handle parent,
+			   char **paths, int num_paths, char **path)
 {
 	int i;
 	acpi_status status;
@@ -351,8 +351,8 @@ static int __init register_tpacpi_subdriver(struct ibm_struct *ibm)
 
 	ibm->driver = kzalloc(sizeof(struct acpi_driver), GFP_KERNEL);
 	if (!ibm->driver) {
-		printk(IBM_ERR "kmalloc(ibm->driver) failed\n");
-		return -1;
+		printk(IBM_ERR "kzalloc(ibm->driver) failed\n");
+		return -ENOMEM;
 	}
 
 	sprintf(ibm->driver->name, "%s_%s", IBM_NAME, ibm->name);
@@ -364,7 +364,9 @@ static int __init register_tpacpi_subdriver(struct ibm_struct *ibm)
 		printk(IBM_ERR "acpi_bus_register_driver(%s) failed: %d\n",
 		       ibm->hid, ret);
 		kfree(ibm->driver);
-	}
+		ibm->driver = NULL;
+	} else if (!ret)
+		ibm->driver_registered = 1;
 
 	return ret;
 }
@@ -495,6 +497,8 @@ static int hotkey_orig_mask;
 
 static int hotkey_init(void)
 {
+	IBM_HANDLE_INIT(hkey);
+
 	/* hotkey not supported on 570 */
 	hotkey_supported = hkey_handle != NULL;
 
@@ -508,13 +512,14 @@ static int hotkey_init(void)
 			return -ENODEV;
 	}
 
-	return 0;
+	return (hotkey_supported)? 0 : 1;
 }
 
 static void hotkey_exit(void)
 {
-	if (hotkey_supported)
+	if (hotkey_supported) {
 		hotkey_set(hotkey_orig_status, hotkey_orig_mask);
+	}
 }
 
 static void hotkey_notify(struct ibm_struct *ibm, u32 event)
@@ -628,12 +633,14 @@ static int bluetooth_supported;
 
 static int bluetooth_init(void)
 {
+	IBM_HANDLE_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");
 
-	return 0;
+	return (bluetooth_supported)? 0 : 1;
 }
 
 static int bluetooth_status(void)
@@ -697,10 +704,12 @@ static int wan_supported;
 
 static int wan_init(void)
 {
+	IBM_HANDLE_INIT(hkey);
+
 	wan_supported = hkey_handle &&
 	    acpi_evalf(hkey_handle, NULL, "GWAN", "qv");
 
-	return 0;
+	return (wan_supported)? 0 : 1;
 }
 
 static int wan_status(void)
@@ -775,6 +784,9 @@ static int video_init(void)
 {
 	int ivga;
 
+	IBM_HANDLE_INIT(vid);
+	IBM_HANDLE_INIT(vid2);
+
 	if (vid2_handle && acpi_evalf(NULL, &ivga, "\\IVGA", "d") && ivga)
 		/* G41, assume IVGA doesn't change */
 		vid_handle = vid2_handle;
@@ -792,7 +804,7 @@ static int video_init(void)
 		/* all others */
 		video_supported = TPACPI_VIDEO_NEW;
 
-	return 0;
+	return (video_supported != TPACPI_VIDEO_NONE)? 0 : 1;
 }
 
 static void video_exit(void)
@@ -979,6 +991,10 @@ IBM_HANDLE(ledb, ec, "LEDB");		/* G4x */
 
 static int light_init(void)
 {
+	IBM_HANDLE_INIT(ledb);
+	IBM_HANDLE_INIT(lght);
+	IBM_HANDLE_INIT(cmos);
+
 	/* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
 	light_supported = (cmos_handle || lght_handle) && !ledb_handle;
 
@@ -988,7 +1004,7 @@ static int light_init(void)
 		light_status_supported = acpi_evalf(ec_handle, NULL,
 						    "KBLT", "qv");
 
-	return 0;
+	return (light_supported)? 0 : 1;
 }
 
 static int light_read(char *p)
@@ -1044,9 +1060,6 @@ static int light_write(char *buf)
  * Dock subdriver
  */
 
-/* don't list other alternatives as we install a notify handler on the 570 */
-IBM_HANDLE(pci, root, "\\_SB.PCI");	/* 570 */
-
 #ifdef CONFIG_THINKPAD_ACPI_DOCK
 
 IBM_HANDLE(dock, root, "\\_SB.GDCK",	/* X30, X31, X40 */
@@ -1055,8 +1068,19 @@ IBM_HANDLE(dock, root, "\\_SB.GDCK",	/* X30, X31, X40 */
 	   "\\_SB.PCI.ISA.SLCE",	/* 570 */
     );				/* A21e,G4x,R30,R31,R32,R40,R40e,R50e */
 
+/* don't list other alternatives as we install a notify handler on the 570 */
+IBM_HANDLE(pci, root, "\\_SB.PCI");	/* 570 */
+
 #define dock_docked() (_sta(dock_handle) & 1)
 
+static int dock_init(void)
+{
+	IBM_HANDLE_INIT(dock);
+	IBM_HANDLE_INIT(pci);
+
+	return (dock_handle)? 0 : 1;
+}
+
 static void dock_notify(struct ibm_struct *ibm, u32 event)
 {
 	int docked = dock_docked();
@@ -1147,6 +1171,13 @@ IBM_HANDLE(bay2_ej, bay2, "_EJ3",	/* 600e/x, 770e, A3x */
 
 static int bay_init(void)
 {
+	IBM_HANDLE_INIT(bay);
+	if (bay_handle)
+		IBM_HANDLE_INIT(bay_ej);
+	IBM_HANDLE_INIT(bay2);
+	if (bay2_handle)
+		IBM_HANDLE_INIT(bay2_ej);
+
 	bay_status_supported = bay_handle &&
 	    acpi_evalf(bay_handle, NULL, "_STA", "qv");
 	bay_status2_supported = bay2_handle &&
@@ -1157,7 +1188,8 @@ static int bay_init(void)
 	bay_eject2_supported = bay2_handle && bay2_ej_handle &&
 	    (strlencmp(bay2_ej_path, "_EJ0") == 0 || experimental);
 
-	return 0;
+	return (bay_status_supported || bay_eject_supported ||
+		bay_status2_supported || bay_eject2_supported)? 0 : 1;
 }
 
 static void bay_notify(struct ibm_struct *ibm, u32 event)
@@ -1221,6 +1253,13 @@ static int bay_write(char *buf)
  * CMOS subdriver
  */
 
+static int cmos_init(void)
+{
+	IBM_HANDLE_INIT(cmos);
+
+	return (cmos_handle)? 0 : 1;
+}
+
 static int cmos_eval(int cmos_cmd)
 {
 	if (cmos_handle)
@@ -1281,6 +1320,8 @@ IBM_HANDLE(led, ec, "SLED",	/* 570 */
 
 static int led_init(void)
 {
+	IBM_HANDLE_INIT(led);
+
 	if (!led_handle)
 		/* led not supported on R30, R31 */
 		led_supported = TPACPI_LED_NONE;
@@ -1294,7 +1335,7 @@ static int led_init(void)
 		/* all others */
 		led_supported = TPACPI_LED_NEW;
 
-	return 0;
+	return (led_supported != TPACPI_LED_NONE)? 0 : 1;
 }
 
 #define led_status(s) ((s) == 0 ? "off" : ((s) == 1 ? "on" : "blinking"))
@@ -1391,6 +1432,13 @@ static int led_write(char *buf)
 
 IBM_HANDLE(beep, ec, "BEEP");	/* all except R30, R31 */
 
+static int beep_init(void)
+{
+	IBM_HANDLE_INIT(beep);
+
+	return (beep_handle)? 0 : 1;
+}
+
 static int beep_read(char *p)
 {
 	int len = 0;
@@ -1436,7 +1484,9 @@ static int thermal_init(void)
 {
 	u8 t, ta1, ta2;
 	int i;
-	int acpi_tmp7 = acpi_evalf(ec_handle, NULL, "TMP7", "qv");
+	int acpi_tmp7;
+
+	acpi_tmp7 = acpi_evalf(ec_handle, NULL, "TMP7", "qv");
 
 	if (ibm_thinkpad_ec_found && experimental) {
 		/*
@@ -1492,7 +1542,7 @@ static int thermal_init(void)
 		thermal_read_mode = TPACPI_THERMAL_NONE;
 	}
 
-	return 0;
+	return (thermal_read_mode != TPACPI_THERMAL_NONE)? 0 : 1;
 }
 
 static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s)
@@ -1973,6 +2023,10 @@ static int fan_init(void)
 	fan_control_status_known = 1;
 	fan_watchdog_maxinterval = 0;
 
+	IBM_HANDLE_INIT(fans);
+	IBM_HANDLE_INIT(gfan);
+	IBM_HANDLE_INIT(sfan);
+
 	if (gfan_handle) {
 		/* 570, 600e/x, 770e, 770x */
 		fan_status_access_mode = TPACPI_FAN_RD_ACPI_GFAN;
@@ -2010,7 +2064,7 @@ static int fan_init(void)
 			printk(IBM_ERR
 			       "ThinkPad ACPI EC access misbehaving, "
 			       "fan status and control unavailable\n");
-			return 0;
+			return 1;
 		}
 	}
 
@@ -2041,7 +2095,9 @@ static int fan_init(void)
 		}
 	}
 
-	return 0;
+	return (fan_status_access_mode != TPACPI_FAN_NONE ||
+	        fan_control_access_mode != TPACPI_FAN_WR_NONE)?
+			0 : 1;
 }
 
 static int fan_get_status(u8 *status)
@@ -2485,6 +2541,7 @@ static struct ibm_struct ibms[] = {
 #ifdef CONFIG_THINKPAD_ACPI_DOCK
 	{
 	 .name = "dock",
+	 .init = dock_init,
 	 .read = dock_read,
 	 .write = dock_write,
 	 .notify = dock_notify,
@@ -2512,6 +2569,7 @@ static struct ibm_struct ibms[] = {
 #endif /* CONFIG_THINKPAD_ACPI_BAY */
 	{
 	 .name = "cmos",
+	 .init = cmos_init,
 	 .read = cmos_read,
 	 .write = cmos_write,
 	 },
@@ -2523,6 +2581,7 @@ static struct ibm_struct ibms[] = {
 	 },
 	{
 	 .name = "beep",
+	 .init = beep_init,
 	 .read = beep_read,
 	 .write = beep_write,
 	 },
@@ -2571,20 +2630,33 @@ static int __init ibm_init(struct ibm_struct *ibm)
 	if (ibm->experimental && !experimental)
 		return 0;
 
-	if (ibm->hid) {
-		ret = register_tpacpi_subdriver(ibm);
-		if (ret < 0)
-			return ret;
-		ibm->driver_registered = 1;
-	}
-
 	if (ibm->init) {
 		ret = ibm->init();
-		if (ret != 0)
+		if (ret > 0)
+			return 0;	/* probe failed */
+		if (ret)
 			return ret;
 		ibm->init_called = 1;
 	}
 
+	if (ibm->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 (ret < 0)
+			goto err_out;
+	}
+
 	if (ibm->read) {
 		entry = create_proc_entry(ibm->name,
 					  S_IFREG | S_IRUGO | S_IWUSR,
@@ -2592,7 +2664,8 @@ static int __init ibm_init(struct ibm_struct *ibm)
 		if (!entry) {
 			printk(IBM_ERR "unable to create proc entry %s\n",
 			       ibm->name);
-			return -ENODEV;
+			ret = -ENODEV;
+			goto err_out;
 		}
 		entry->owner = THIS_MODULE;
 		entry->data = ibm;
@@ -2602,36 +2675,36 @@ static int __init ibm_init(struct ibm_struct *ibm)
 		ibm->proc_created = 1;
 	}
 
-	if (ibm->notify) {
-		ret = setup_notify(ibm);
-		if (ret == -ENODEV) {
-			printk(IBM_NOTICE "disabling subdriver %s\n",
-				ibm->name);
-			ibm_exit(ibm);
-			return 0;
-		}
-		if (ret < 0)
-			return ret;
-	}
-
 	return 0;
+
+err_out:
+	ibm_exit(ibm);
+	return (ret < 0)? ret : 0;
 }
 
 static void ibm_exit(struct ibm_struct *ibm)
 {
-	if (ibm->notify_installed)
+	if (ibm->notify_installed) {
 		acpi_remove_notify_handler(*ibm->handle, ibm->type,
 					   dispatch_notify);
+		ibm->notify_installed = 0;
+	}
 
-	if (ibm->proc_created)
+	if (ibm->proc_created) {
 		remove_proc_entry(ibm->name, proc_dir);
-
-	if (ibm->init_called && ibm->exit)
-		ibm->exit();
+		ibm->proc_created = 0;
+	}
 
 	if (ibm->driver_registered) {
 		acpi_bus_unregister_driver(ibm->driver);
 		kfree(ibm->driver);
+		ibm->driver = NULL;
+		ibm->driver_registered = 0;
+	}
+
+	if (ibm->init_called && ibm->exit) {
+		ibm->exit();
+		ibm->init_called = 0;
 	}
 }
 
@@ -2663,6 +2736,32 @@ static char* __init check_dmi_for_ec(void)
 	return NULL;
 }
 
+static int __init probe_for_thinkpad(void)
+{
+	int is_thinkpad;
+
+	if (acpi_disabled)
+		return -ENODEV;
+
+	/*
+	 * Non-ancient models have better DMI tagging, but very old models
+	 * don't.
+	 */
+	is_thinkpad = dmi_name_in_vendors("ThinkPad");
+
+	/* ec is required because many other handles are relative to it */
+	IBM_HANDLE_INIT(ec);
+	if (!ec_handle) {
+		if (is_thinkpad)
+			printk(IBM_ERR
+				"Not yet supported ThinkPad detected!\n");
+		return -ENODEV;
+	}
+
+	return 0;
+}
+
+
 /* Module init, exit, parameters */
 
 static int __init set_ibm_param(const char *val, struct kernel_param *kp)
@@ -2712,45 +2811,13 @@ static int __init thinkpad_acpi_module_init(void)
 {
 	int ret, i;
 
-	if (acpi_disabled)
-		return -ENODEV;
+	ret = probe_for_thinkpad();
+	if (ret)
+		return ret;
 
-	/* ec is required because many other handles are relative to it */
-	IBM_HANDLE_INIT(ec);
-	if (!ec_handle) {
-		printk(IBM_ERR "ec object not found\n");
-		return -ENODEV;
-	}
-
-	/* Models with newer firmware report the EC in DMI */
 	ibm_thinkpad_ec_found = check_dmi_for_ec();
-
-	/* these handles are not required */
-	IBM_HANDLE_INIT(vid);
-	IBM_HANDLE_INIT(vid2);
-	IBM_HANDLE_INIT(ledb);
-	IBM_HANDLE_INIT(led);
-	IBM_HANDLE_INIT(hkey);
-	IBM_HANDLE_INIT(lght);
-	IBM_HANDLE_INIT(cmos);
-#ifdef CONFIG_THINKPAD_ACPI_DOCK
-	IBM_HANDLE_INIT(dock);
-#endif
-	IBM_HANDLE_INIT(pci);
-#ifdef CONFIG_THINKPAD_ACPI_BAY
-	IBM_HANDLE_INIT(bay);
-	if (bay_handle)
-		IBM_HANDLE_INIT(bay_ej);
-	IBM_HANDLE_INIT(bay2);
-	if (bay2_handle)
-		IBM_HANDLE_INIT(bay2_ej);
-#endif /* CONFIG_THINKPAD_ACPI_BAY */
-	IBM_HANDLE_INIT(beep);
 	IBM_HANDLE_INIT(ecrd);
 	IBM_HANDLE_INIT(ecwr);
-	IBM_HANDLE_INIT(fans);
-	IBM_HANDLE_INIT(gfan);
-	IBM_HANDLE_INIT(sfan);
 
 	proc_dir = proc_mkdir(IBM_DIR, acpi_root_dir);
 	if (!proc_dir) {
drivers/misc/thinkpad_acpi.h +2 -2
index b2348d7..06d4c38 100644
@@ -104,7 +104,7 @@ static acpi_handle ecrd_handle, ecwr_handle;	/* 570 EC access */
 static acpi_handle cmos_handle, hkey_handle;	/* basic thinkpad handles */
 
 static void ibm_handle_init(char *name,
-		   acpi_handle * handle, acpi_handle parent,
+		   acpi_handle *handle, acpi_handle parent,
 		   char **paths, int num_paths, char **path);
 #define IBM_HANDLE_INIT(object)						\
 	ibm_handle_init(#object, &object##_handle, *object##_parent,	\
@@ -242,8 +242,8 @@ static int cmos_write(char *buf);
  * Dock subdriver
  */
 
-static acpi_handle pci_handle;
 #ifdef CONFIG_THINKPAD_ACPI_DOCK
+static acpi_handle pci_handle;
 static acpi_handle dock_handle;
 
 static void dock_notify(struct ibm_struct *ibm, u32 event);
Signature · 8 lines
1.5.1


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
#7 lore raw

PATCH 8/20 ACPI: thinkpad-acpi: add subdriver debug statements

In reply to a message not in the archive

Add debug messages to the subdriver initialization and exit code.

---
 Documentation/thinkpad-acpi.txt |    4 ++
 drivers/misc/thinkpad_acpi.c    |  111 +++++++++++++++++++++++++++++++++++++++
 drivers/misc/thinkpad_acpi.h    |    4 ++
 3 files changed, 119 insertions(+), 0 deletions(-)
Documentation/thinkpad-acpi.txt +4 -0
index 82fd822..20d5ec3 100644
@@ -710,5 +710,9 @@ enable various classes of debugging output, for example:
 will enable all debugging output classes.  It takes a bitmask, so
 to enable more than one output class, just add their values.
 
+	Debug bitmask		Description
+	0x0001			Initialization and probing
+	0x0002			Removal
+
 There is also a kernel build option to enable more debugging
 information, which may be necessary to debug driver problems.
drivers/misc/thinkpad_acpi.c +111 -0

337 lines not on this page · raw message

drivers/misc/thinkpad_acpi.h +4 -0
index 06d4c38..beb1447 100644
@@ -76,12 +76,16 @@
 
 /* Debugging */
 #define TPACPI_DBG_ALL		0xffff
+#define TPACPI_DBG_ALL		0xffff
+#define TPACPI_DBG_INIT		0x0001
+#define TPACPI_DBG_EXIT		0x0002
 #define dbg_printk(a_dbg_level, format, arg...) \
 	do { if (dbg_level & a_dbg_level) \
 		printk(IBM_DEBUG "%s: " format, __func__ , ## arg); } while (0)
 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
 #define vdbg_printk(a_dbg_level, format, arg...) \
 	dbg_printk(a_dbg_level, format, ## arg)
+static const char *str_supported(int is_supported);
 #else
 #define vdbg_printk(a_dbg_level, format, arg...)
 #endif
Signature · 8 lines
1.5.1


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
#8 lore raw

PATCH 10/20 ACPI: thinkpad-acpi: improve thinkpad detection

In reply to a message not in the archive

Improve the detection of ThinkPads, so as to reduce the chances of false positives.

Since this could potentially add false negatives on the very old models, add a module parameter to force the detection of a thinkpad.

---
 Documentation/thinkpad-acpi.txt |    7 +++++++
 drivers/misc/thinkpad_acpi.c    |   13 +++++++++++++
 drivers/misc/thinkpad_acpi.h    |    1 +
 3 files changed, 21 insertions(+), 0 deletions(-)
Documentation/thinkpad-acpi.txt +7 -0
index 20d5ec3..1a42b77 100644
@@ -716,3 +716,10 @@ to enable more than one output class, just add their values.
 
 There is also a kernel build option to enable more debugging
 information, which may be necessary to debug driver problems.
+
+Force loading of module
+-----------------------
+
+If thinkpad-acpi refuses to detect your ThinkPad, you can try to specify
+the module parameter force_load=1.  Regardless of whether this works or
+not, please contact [email protected] with a report.
drivers/misc/thinkpad_acpi.c +13 -0
index 5611268..cddf81b 100644
@@ -2881,6 +2881,16 @@ static int __init probe_for_thinkpad(void)
 		return -ENODEV;
 	}
 
+	/*
+	 * Risks a regression on very old machines, but reduces potential
+	 * false positives a damn great deal
+	 */
+	if (!is_thinkpad)
+		is_thinkpad = dmi_name_in_vendors("IBM");
+
+	if (!is_thinkpad && !force_load)
+		return -ENODEV;
+
 	return 0;
 }
 
@@ -2986,6 +2996,9 @@ module_param(experimental, int, 0);
 static u32 dbg_level;
 module_param_named(debug, dbg_level, uint, 0);
 
+static int force_load;
+module_param(force_load, int, 0);
+
 #define IBM_PARAM(feature) \
 	module_param_call(feature, set_ibm_param, NULL, NULL, 0)
 
drivers/misc/thinkpad_acpi.h +1 -0
index 97467b7..2020398 100644
@@ -128,6 +128,7 @@ static char *next_cmd(char **cmds);
 /* Module */
 static int experimental;
 static u32 dbg_level;
+static int force_load;
 static char *ibm_thinkpad_ec_found;
 
 static char* check_dmi_for_ec(void);
Signature · 8 lines
1.5.1


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
#9 lore raw

PATCH 12/20 ACPI: thinkpad-acpi: use bitfields for module flags

In reply to a message not in the archive

Use a bitfield to hold boolean module-wide flags, to conserve some memory. It is easy and it is clean, so we do it just for the heck of it even if it saves very little space.

---
 drivers/misc/thinkpad_acpi.c |  147 +++++++++++++++++++-----------------------
 drivers/misc/thinkpad_acpi.h |   28 +++++----
 2 files changed, 83 insertions(+), 92 deletions(-)
drivers/misc/thinkpad_acpi.c +67 -80
index a5efd06..e2a1b63 100644
@@ -501,8 +501,6 @@ static struct ibm_struct thinkpad_acpi_driver_data = {
  * Hotkey subdriver
  */
 
-static int hotkey_supported;
-static int hotkey_mask_supported;
 static int hotkey_orig_status;
 static int hotkey_orig_mask;
 
@@ -513,30 +511,30 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
 	IBM_HANDLE_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;
 	}
 
-	return (hotkey_supported)? 0 : 1;
+	return (tp_features.hotkey)? 0 : 1;
 }
 
 static void hotkey_exit(void)
 {
-	if (hotkey_supported) {
+	if (tp_features.hotkey) {
 		dbg_printk(TPACPI_DBG_EXIT, "restoring original hotkey mask\n");
 		hotkey_set(hotkey_orig_status, hotkey_orig_mask);
 	}
@@ -559,7 +557,7 @@ static int hotkey_get(int *status, int *mask)
 	if (!acpi_evalf(hkey_handle, status, "DHKC", "d"))
 		return 0;
 
-	if (hotkey_mask_supported)
+	if (tp_features.hotkey_mask)
 		if (!acpi_evalf(hkey_handle, mask, "DHKN", "d"))
 			return 0;
 
@@ -573,7 +571,7 @@ static int hotkey_set(int status, int mask)
 	if (!acpi_evalf(hkey_handle, NULL, "MHKC", "vd", status))
 		return 0;
 
-	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,
@@ -589,7 +587,7 @@ static int hotkey_read(char *p)
 	int status, mask;
 	int len = 0;
 
-	if (!hotkey_supported) {
+	if (!tp_features.hotkey) {
 		len += sprintf(p + len, "status:\t\tnot supported\n");
 		return len;
 	}
@@ -598,7 +596,7 @@ static int hotkey_read(char *p)
 		return -EIO;
 
 	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");
@@ -616,7 +614,7 @@ static int hotkey_write(char *buf)
 	char *cmd;
 	int do_cmd = 0;
 
-	if (!hotkey_supported)
+	if (!tp_features.hotkey)
 		return -ENODEV;
 
 	if (!hotkey_get(&status, &mask))
@@ -660,8 +658,6 @@ static struct ibm_struct hotkey_driver_data = {
  * Bluetooth subdriver
  */
 
-static int bluetooth_supported;
-
 static int __init bluetooth_init(struct ibm_init_struct *iibm)
 {
 	vdbg_printk(TPACPI_DBG_INIT, "initializing bluetooth subdriver\n");
@@ -670,20 +666,20 @@ static int __init bluetooth_init(struct ibm_init_struct *iibm)
 
 	/* 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 &&
+	tp_features.bluetooth = hkey_handle &&
 	    acpi_evalf(hkey_handle, NULL, "GBDC", "qv");
 
 	vdbg_printk(TPACPI_DBG_INIT, "bluetooth is %s\n",
-		str_supported(bluetooth_supported));
+		str_supported(tp_features.bluetooth));
 
-	return (bluetooth_supported)? 0 : 1;
+	return (tp_features.bluetooth)? 0 : 1;
 }
 
 static int bluetooth_status(void)
 {
 	int status;
 
-	if (!bluetooth_supported ||
+	if (!tp_features.bluetooth ||
 	    !acpi_evalf(hkey_handle, &status, "GBDC", "d"))
 		status = 0;
 
@@ -695,7 +691,7 @@ static int bluetooth_read(char *p)
 	int len = 0;
 	int status = bluetooth_status();
 
-	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");
@@ -713,7 +709,7 @@ static int bluetooth_write(char *buf)
 	char *cmd;
 	int do_cmd = 0;
 
-	if (!bluetooth_supported)
+	if (!tp_features.bluetooth)
 		return -ENODEV;
 
 	while ((cmd = next_cmd(&buf))) {
@@ -742,28 +738,27 @@ static struct ibm_struct bluetooth_driver_data = {
  * Wan subdriver
  */
 
-static int wan_supported;
-
 static int __init wan_init(struct ibm_init_struct *iibm)
 {
 	vdbg_printk(TPACPI_DBG_INIT, "initializing wan subdriver\n");
 
 	IBM_HANDLE_INIT(hkey);
 
-	wan_supported = hkey_handle &&
-	    acpi_evalf(hkey_handle, NULL, "GWAN", "qv");
+	tp_features.wan = hkey_handle &&
+			  acpi_evalf(hkey_handle, NULL, "GWAN", "qv");
 
 	vdbg_printk(TPACPI_DBG_INIT, "wan is %s\n",
-		str_supported(wan_supported));
+		str_supported(tp_features.wan));
 
-	return (wan_supported)? 0 : 1;
+	return (tp_features.wan)? 0 : 1;
 }
 
 static int wan_status(void)
 {
 	int status;
 
-	if (!wan_supported || !acpi_evalf(hkey_handle, &status, "GWAN", "d"))
+	if (!tp_features.wan ||
+	    !acpi_evalf(hkey_handle, &status, "GWAN", "d"))
 		status = 0;
 
 	return status;
@@ -774,7 +769,7 @@ static int wan_read(char *p)
 	int len = 0;
 	int status = wan_status();
 
-	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");
@@ -792,7 +787,7 @@ static int wan_write(char *buf)
 	char *cmd;
 	int do_cmd = 0;
 
-	if (!wan_supported)
+	if (!tp_features.wan)
 		return -ENODEV;
 
 	while ((cmd = next_cmd(&buf))) {
@@ -1051,9 +1046,6 @@ static struct ibm_struct video_driver_data = {
  * 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 */
 
@@ -1066,18 +1058,18 @@ static int __init light_init(struct ibm_init_struct *iibm)
 	IBM_HANDLE_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)
@@ -1085,9 +1077,9 @@ 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 {
@@ -1106,7 +1098,7 @@ static int light_write(char *buf)
 	char *cmd;
 	int success;
 
-	if (!light_supported)
+	if (!tp_features.light)
 		return -ENODEV;
 
 	while ((cmd = next_cmd(&buf))) {
@@ -1251,11 +1243,6 @@ static struct ibm_struct dock_driver_data[2] = {
  */
 
 #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 */
@@ -1282,25 +1269,25 @@ static int __init bay_init(struct ibm_init_struct *iibm)
 	if (bay2_handle)
 		IBM_HANDLE_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)
@@ -1317,15 +1304,16 @@ static int bay_read(char *p)
 	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");
@@ -1341,14 +1329,14 @@ static int bay_write(char *buf)
 {
 	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;
@@ -2188,7 +2176,6 @@ static enum fan_status_access_mode fan_status_access_mode;
 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);
@@ -2210,8 +2197,8 @@ static int __init fan_init(struct ibm_init_struct *iibm)
 	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);
@@ -2248,7 +2235,7 @@ static int __init fan_init(struct ibm_init_struct *iibm)
 				       "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
@@ -2411,7 +2398,7 @@ static int fan_set_level(int level)
 		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:
@@ -2438,7 +2425,7 @@ static int fan_set_enable(void)
 		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:
@@ -2469,7 +2456,7 @@ static int fan_set_disable(void)
 		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:
@@ -2524,9 +2511,9 @@ static int fan_read(char *p)
 		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 */
drivers/misc/thinkpad_acpi.h +16 -12
index 8b72061..4d3ab40 100644
@@ -173,6 +173,22 @@ struct ibm_init_struct {
 	struct ibm_struct *data;
 };
 
+static struct {
+#ifdef CONFIG_THINKPAD_ACPI_BAY
+	u16 bay_status:1;
+	u16 bay_eject:1;
+	u16 bay_status2:1;
+	u16 bay_eject2:1;
+#endif
+	u16 bluetooth:1;
+	u16 hotkey:1;
+	u16 hotkey_mask:1;
+	u16 light:1;
+	u16 light_status:1;
+	u16 wan:1;
+	u16 fan_ctrl_status_undef:1;
+} tp_features;
+
 static struct list_head tpacpi_all_drivers;
 
 static struct ibm_init_struct ibms_init[];
@@ -193,9 +209,6 @@ static int thinkpad_acpi_driver_read(char *p);
  */
 
 #ifdef CONFIG_THINKPAD_ACPI_BAY
-static int bay_status_supported, bay_eject_supported;
-static int bay_status2_supported, bay_eject2_supported;
-
 static acpi_handle bay_handle, bay_ej_handle;
 static acpi_handle bay2_handle, bay2_ej_handle;
 
@@ -220,8 +233,6 @@ static int beep_write(char *buf);
  * Bluetooth subdriver
  */
 
-static int bluetooth_supported;
-
 static int bluetooth_init(struct ibm_init_struct *iibm);
 static int bluetooth_status(void);
 static int bluetooth_read(char *p);
@@ -311,7 +322,6 @@ enum fan_control_commands {
 static enum fan_status_access_mode fan_status_access_mode;
 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 int fan_watchdog_maxinterval;
 
@@ -340,8 +350,6 @@ static int fan_write_cmd_watchdog(const char *cmd, int *rc);
  * Hotkey subdriver
  */
 
-static int hotkey_supported;
-static int hotkey_mask_supported;
 static int hotkey_orig_status;
 static int hotkey_orig_mask;
 
@@ -382,8 +390,6 @@ static int led_write(char *buf);
  * Light (thinklight) subdriver
  */
 
-static int light_supported;
-static int light_status_supported;
 static acpi_handle lght_handle, ledb_handle;
 
 static int light_init(struct ibm_init_struct *iibm);
@@ -453,8 +459,6 @@ static int volume_write(char *buf);
  * Wan subdriver
  */
 
-static int wan_supported;
-
 static int wan_init(struct ibm_init_struct *iibm);
 static int wan_status(void);
 static int wan_read(char *p);
Signature · 8 lines
1.5.1


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
#12 lore raw

PATCH 13/20 ACPI: thinkpad-acpi: prepare for device model conversion

In reply to a message not in the archive

Prepare the thinkpad-acpi driver for the conversion to the device model, by renaming variables and doing other glue work that shall make the later patches much cleaner.

---
 drivers/misc/thinkpad_acpi.c |  231 +++++++++++++++++++++++-------------------
 drivers/misc/thinkpad_acpi.h |   40 +++++---
 2 files changed, 153 insertions(+), 118 deletions(-)
drivers/misc/thinkpad_acpi.c +129 -102
index e2a1b63..809ec84 100644
@@ -277,7 +277,7 @@ static int _sta(acpi_handle handle)
  * 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)
 {
@@ -295,40 +295,42 @@ static void ibm_handle_init(char *name,
 	*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",
@@ -339,11 +341,11 @@ static int __init setup_notify(struct ibm_struct *ibm)
 		}
 		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;
 }
@@ -355,24 +357,26 @@ static int __init register_tpacpi_subdriver(struct ibm_struct *ibm)
 	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;
 }
@@ -386,8 +390,8 @@ static int __init register_tpacpi_subdriver(struct ibm_struct *ibm)
  ****************************************************************************
  ****************************************************************************/
 
-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;
@@ -411,8 +415,9 @@ static int dispatch_read(char *page, char **start, off_t off, int count,
 	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;
@@ -508,7 +513,7 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
 {
 	vdbg_printk(TPACPI_DBG_INIT, "initializing hotkey subdriver\n");
 
-	IBM_HANDLE_INIT(hkey);
+	IBM_ACPIHANDLE_INIT(hkey);
 
 	/* hotkey not supported on 570 */
 	tp_features.hotkey = hkey_handle != NULL;
@@ -545,10 +550,10 @@ static void hotkey_notify(struct ibm_struct *ibm, u32 event)
 	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);
 	}
 }
 
@@ -643,15 +648,19 @@ static int hotkey_write(char *buf)
 	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,
 };
 
 /*************************************************************************
@@ -662,7 +671,7 @@ static int __init bluetooth_init(struct ibm_init_struct *iibm)
 {
 	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 */
@@ -742,7 +751,7 @@ static int __init wan_init(struct ibm_init_struct *iibm)
 {
 	vdbg_printk(TPACPI_DBG_INIT, "initializing wan subdriver\n");
 
-	IBM_HANDLE_INIT(hkey);
+	IBM_ACPIHANDLE_INIT(hkey);
 
 	tp_features.wan = hkey_handle &&
 			  acpi_evalf(hkey_handle, NULL, "GWAN", "qv");
@@ -835,8 +844,8 @@ static int __init video_init(struct ibm_init_struct *iibm)
 
 	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 */
@@ -1053,9 +1062,9 @@ static int __init light_init(struct ibm_init_struct *iibm)
 {
 	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 */
 	tp_features.light = (cmos_handle || lght_handle) && !ledb_handle;
@@ -1148,8 +1157,8 @@ static int __init dock_init(struct ibm_init_struct *iibm)
 {
 	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));
@@ -1160,22 +1169,22 @@ static int __init dock_init(struct ibm_init_struct *iibm)
 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 */
 	}
 }
 
@@ -1218,17 +1227,13 @@ static int dock_write(char *buf)
 	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,
@@ -1236,6 +1241,19 @@ static struct ibm_struct dock_driver_data[2] = {
 	},
 };
 
+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 */
 
 /*************************************************************************
@@ -1262,12 +1280,12 @@ static int __init bay_init(struct ibm_init_struct *iibm)
 {
 	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);
 
 	tp_features.bay_status = bay_handle &&
 		acpi_evalf(bay_handle, NULL, "_STA", "qv");
@@ -1292,7 +1310,7 @@ static int __init bay_init(struct ibm_init_struct *iibm)
 
 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)
@@ -1347,13 +1365,17 @@ static int bay_write(char *buf)
 	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 */
@@ -1367,7 +1389,7 @@ static int __init cmos_init(struct ibm_init_struct *iibm)
 	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));
@@ -1441,7 +1463,7 @@ static int __init led_init(struct ibm_init_struct *iibm)
 {
 	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 */
@@ -1566,7 +1588,7 @@ static int __init beep_init(struct ibm_init_struct *iibm)
 {
 	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));
@@ -2200,9 +2222,9 @@ static int __init fan_init(struct ibm_init_struct *iibm)
 	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 */
@@ -2728,22 +2750,24 @@ static int __init ibm_init(struct ibm_init_struct *iibm)
 		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,
@@ -2761,9 +2785,9 @@ static int __init ibm_init(struct ibm_init_struct *iibm)
 		}
 		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;
 	}
 
@@ -2786,12 +2810,15 @@ static void ibm_exit(struct ibm_struct *ibm)
 
 	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) {
@@ -2801,13 +2828,14 @@ static void ibm_exit(struct ibm_struct *ibm)
 		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) {
@@ -2860,7 +2888,7 @@ static int __init probe_for_thinkpad(void)
 	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
@@ -3016,12 +3044,12 @@ static int __init thinkpad_acpi_module_init(void)
 		return ret;
 
 	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;
 	}
@@ -3053,10 +3081,9 @@ static void thinkpad_acpi_module_exit(void)
 	dbg_printk(TPACPI_DBG_INIT, "finished subdriver exit path...\n");
 
 	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);
drivers/misc/thinkpad_acpi.h +24 -16
index 4d3ab40..529528c 100644
@@ -52,8 +52,9 @@
 #define IBM_DESC "ThinkPad ACPI Extras"
 #define IBM_FILE "thinkpad_acpi"
 #define IBM_URL "http://ibm-acpi.sf.net/"
+#define IBM_MAIL "[email protected]"
 
-#define IBM_DIR "ibm"
+#define IBM_PROC_DIR "ibm"
 #define IBM_ACPI_EVENT_PREFIX "ibm"
 
 #define IBM_LOG IBM_FILE ": "
@@ -108,20 +109,21 @@ static acpi_handle ec_handle;			/* EC */
 static acpi_handle ecrd_handle, ecwr_handle;	/* 570 EC access */
 static acpi_handle cmos_handle, hkey_handle;	/* basic thinkpad handles */
 
-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);
-#define IBM_HANDLE_INIT(object)						\
-	ibm_handle_init(#object, &object##_handle, *object##_parent,	\
+#define IBM_ACPIHANDLE_INIT(object)						\
+	drv_acpi_handle_init(#object, &object##_handle, *object##_parent,	\
 		object##_paths, ARRAY_SIZE(object##_paths), &object##_path)
 
 /* procfs support */
 static struct proc_dir_entry *proc_dir;
 
 /* procfs helpers */
-static int dispatch_read(char *page, char **start, off_t off, int count,
-		int *eof, void *data);
-static int dispatch_write(struct file *file, const char __user * userbuf,
+static int dispatch_procfs_read(char *page, char **start, off_t off,
+		int count, int *eof, void *data);
+static int dispatch_procfs_write(struct file *file,
+		const char __user * userbuf,
 		unsigned long count, void *data);
 static char *next_cmd(char **cmds);
 
@@ -140,28 +142,34 @@ static void thinkpad_acpi_module_exit(void);
  * Subdrivers
  */
 
-struct ibm_struct {
-	char *name;
+struct ibm_struct;
 
+struct tp_acpi_drv_struct {
 	char *hid;
 	struct acpi_driver *driver;
 
-	int (*read) (char *);
-	int (*write) (char *);
-	void (*exit) (void);
-
 	void (*notify) (struct ibm_struct *, u32);
 	acpi_handle *handle;
-	int type;
+	u32 type;
 	struct acpi_device *device;
+};
+
+struct ibm_struct {
+	char *name;
+
+	int (*read) (char *);
+	int (*write) (char *);
+	void (*exit) (void);
 
 	struct list_head all_drivers;
 
+	struct tp_acpi_drv_struct *acpi;
+
 	struct {
-		u8 driver_registered:1;
+		u8 acpi_driver_registered:1;
+		u8 acpi_notify_installed:1;
 		u8 proc_created:1;
 		u8 init_called:1;
-		u8 notify_installed:1;
 		u8 experimental:1;
 	} flags;
 };
Signature · 8 lines
1.5.1


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
#13 lore raw

PATCH 14/20 ACPI: thinkpad-acpi: mark acpi helper functions __must_check

In reply to a message not in the archive

Mark acpi_evalf and friends __must_check.

---
 drivers/misc/thinkpad_acpi.h |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
drivers/misc/thinkpad_acpi.h +4 -4
index 529528c..1b4cd16 100644
@@ -97,11 +97,11 @@ static const char *str_supported(int is_supported);
 #define IBM_PCI_HID     "PNP0A03"
 
 /* ACPI helpers */
-static int acpi_evalf(acpi_handle handle,
+static int __must_check acpi_evalf(acpi_handle handle,
 		      void *res, char *method, char *fmt, ...);
-static int acpi_ec_read(int i, u8 * p);
-static int acpi_ec_write(int i, u8 v);
-static int _sta(acpi_handle handle);
+static int __must_check acpi_ec_read(int i, u8 * p);
+static int __must_check acpi_ec_write(int i, u8 v);
+static int __must_check _sta(acpi_handle handle);
 
 /* ACPI handles */
 static acpi_handle root_handle;			/* root namespace */
Signature · 8 lines
1.5.1


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
#14 lore raw

PATCH 15/20 ACPI: thinkpad-acpi: clean up hotkey subdriver

In reply to a message not in the archive

Cleanup hotkey subdriver code.

---
 drivers/misc/thinkpad_acpi.c |   46 ++++++++++++++++++++++++++---------------
 1 files changed, 29 insertions(+), 17 deletions(-)
drivers/misc/thinkpad_acpi.c +29 -17
index 809ec84..344eb55 100644
@@ -511,6 +511,8 @@ 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_ACPIHANDLE_INIT(hkey);
@@ -530,8 +532,9 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
 		vdbg_printk(TPACPI_DBG_INIT, "hotkey masks are %s\n",
 			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 (tp_features.hotkey)? 0 : 1;
@@ -539,9 +542,13 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
 
 static void hotkey_exit(void)
 {
+	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");
 	}
 }
 
@@ -560,13 +567,13 @@ static void hotkey_notify(struct ibm_struct *ibm, u32 event)
 static int hotkey_get(int *status, int *mask)
 {
 	if (!acpi_evalf(hkey_handle, status, "DHKC", "d"))
-		return 0;
+		return -EIO;
 
 	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)
@@ -574,22 +581,22 @@ static int hotkey_set(int status, int mask)
 	int i;
 
 	if (!acpi_evalf(hkey_handle, NULL, "MHKC", "vd", status))
-		return 0;
+		return -EIO;
 
 	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 (!tp_features.hotkey) {
@@ -597,8 +604,9 @@ static int hotkey_read(char *p)
 		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 (tp_features.hotkey_mask) {
@@ -615,15 +623,16 @@ static int hotkey_read(char *p)
 
 static int hotkey_write(char *buf)
 {
-	int status, mask;
+	int res, status, mask;
 	char *cmd;
 	int do_cmd = 0;
 
 	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) {
@@ -642,8 +651,11 @@ static int hotkey_write(char *buf)
 		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;
 }
Signature · 8 lines
1.5.1


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
#15 lore raw

PATCH 16/20 ACPI: thinkpad-acpi: cleanup bluetooth and wan for sysfs conversion

In reply to a message not in the archive

Prepare bluetooth and wan driver code to be more easily hooked into sysfs helpers, by separating the procfs logic from the device attribute handling.

These changes also remove the entries from procfs on notebooks without the bluetooth/wan hardware installed.

---
 drivers/misc/thinkpad_acpi.c |  130 +++++++++++++++++++++++++++++-------------
 drivers/misc/thinkpad_acpi.h |   20 ++++++-
 2 files changed, 108 insertions(+), 42 deletions(-)
drivers/misc/thinkpad_acpi.c +90 -40
index 344eb55..a77368f 100644
@@ -681,6 +681,8 @@ static struct ibm_struct hotkey_driver_data = {
 
 static int __init bluetooth_init(struct ibm_init_struct *iibm)
 {
+	int status = 0;
+
 	vdbg_printk(TPACPI_DBG_INIT, "initializing bluetooth subdriver\n");
 
 	IBM_ACPIHANDLE_INIT(hkey);
@@ -688,36 +690,65 @@ static int __init bluetooth_init(struct ibm_init_struct *iibm)
 	/* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
 	   G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
 	tp_features.bluetooth = hkey_handle &&
-	    acpi_evalf(hkey_handle, NULL, "GBDC", "qv");
+	    acpi_evalf(hkey_handle, &status, "GBDC", "qd");
 
-	vdbg_printk(TPACPI_DBG_INIT, "bluetooth is %s\n",
-		str_supported(tp_features.bluetooth));
+	vdbg_printk(TPACPI_DBG_INIT, "bluetooth is %s, status 0x%02x\n",
+		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");
+	}
 
 	return (tp_features.bluetooth)? 0 : 1;
 }
 
-static int bluetooth_status(void)
+static int bluetooth_get_radiosw(void)
 {
 	int status;
 
-	if (!tp_features.bluetooth ||
-	    !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 (!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");
 	}
 
@@ -726,26 +757,20 @@ static int bluetooth_read(char *p)
 
 static int bluetooth_write(char *buf)
 {
-	int status = bluetooth_status();
 	char *cmd;
-	int do_cmd = 0;
 
 	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;
 }
 
@@ -761,41 +786,72 @@ static struct ibm_struct bluetooth_driver_data = {
 
 static int __init wan_init(struct ibm_init_struct *iibm)
 {
+	int status = 0;
+
 	vdbg_printk(TPACPI_DBG_INIT, "initializing wan subdriver\n");
 
 	IBM_ACPIHANDLE_INIT(hkey);
 
 	tp_features.wan = hkey_handle &&
-			  acpi_evalf(hkey_handle, NULL, "GWAN", "qv");
+	    acpi_evalf(hkey_handle, &status, "GWAN", "qd");
 
-	vdbg_printk(TPACPI_DBG_INIT, "wan is %s\n",
-		str_supported(tp_features.wan));
+	vdbg_printk(TPACPI_DBG_INIT, "wan is %s, status 0x%02x\n",
+		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");
+	}
 
 	return (tp_features.wan)? 0 : 1;
 }
 
-static int wan_status(void)
+static int wan_get_radiosw(void)
 {
 	int status;
 
-	if (!tp_features.wan ||
-	    !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 (!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");
 	}
 
@@ -804,26 +860,20 @@ static int wan_read(char *p)
 
 static int wan_write(char *buf)
 {
-	int status = wan_status();
 	char *cmd;
-	int do_cmd = 0;
 
 	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;
 }
 
drivers/misc/thinkpad_acpi.h +18 -2
index 1b4cd16..e06bad5 100644
@@ -241,8 +241,16 @@ static int beep_write(char *buf);
  * Bluetooth subdriver
  */
 
+enum {
+	/* ACPI GBDC/SBDC bits */
+	TP_ACPI_BLUETOOTH_HWPRESENT	= 0x01,	/* Bluetooth hw available */
+	TP_ACPI_BLUETOOTH_RADIOSSW	= 0x02,	/* Bluetooth radio enabled */
+	TP_ACPI_BLUETOOTH_UNK		= 0x04,	/* unknown function */
+};
+
 static int bluetooth_init(struct ibm_init_struct *iibm);
-static int bluetooth_status(void);
+static int bluetooth_get_radiosw(void);
+static int bluetooth_set_radiosw(int radio_on);
 static int bluetooth_read(char *p);
 static int bluetooth_write(char *buf);
 
@@ -467,8 +475,16 @@ static int volume_write(char *buf);
  * Wan subdriver
  */
 
+enum {
+	/* ACPI GWAN/SWAN bits */
+	TP_ACPI_WANCARD_HWPRESENT	= 0x01,	/* Wan hw available */
+	TP_ACPI_WANCARD_RADIOSSW	= 0x02,	/* Wan radio enabled */
+	TP_ACPI_WANCARD_UNK		= 0x04,	/* unknown function */
+};
+
 static int wan_init(struct ibm_init_struct *iibm);
-static int wan_status(void);
+static int wan_get_radiosw(void);
+static int wan_set_radiosw(int radio_on);
 static int wan_read(char *p);
 static int wan_write(char *buf);
 
Signature · 8 lines
1.5.1


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
#16 lore raw

PATCH 17/20 ACPI: thinkpad-acpi: cleanup video subdriver

In reply to a message not in the archive

Cleanup video subdriver for sysfs conversion, and properly check result status of acpi_evalf.

---
 drivers/misc/thinkpad_acpi.c |  262 ++++++++++++++++++++++++++++--------------
 drivers/misc/thinkpad_acpi.h |   25 +++-
 2 files changed, 197 insertions(+), 90 deletions(-)
drivers/misc/thinkpad_acpi.c +177 -85
index a77368f..19c14bb 100644
@@ -935,111 +935,194 @@ static int __init video_init(struct ibm_init_struct *iibm)
 
 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;
-
-	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;
+	int autosw = video_autosw_get();
+	int res;
 
-		ret = acpi_evalf(vid_handle, NULL,
-				 "ASWT", "vdd", status * 0x100, 0);
+	if (autosw < 0)
+		return autosw;
 
-		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));
@@ -1060,47 +1143,56 @@ static int video_write(char *buf)
 {
 	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;
drivers/misc/thinkpad_acpi.h +20 -5
index e06bad5..3a8718a 100644
@@ -446,17 +446,32 @@ enum video_access_mode {
 	TPACPI_VIDEO_NEW,	/* all others */
 };
 
+enum {	/* video status flags, based on VIDEO_570 */
+	TP_ACPI_VIDEO_S_LCD = 0x01,	/* LCD output enabled */
+	TP_ACPI_VIDEO_S_CRT = 0x02,	/* CRT output enabled */
+	TP_ACPI_VIDEO_S_DVI = 0x08,	/* DVI output enabled */
+};
+
+enum {  /* TPACPI_VIDEO_570 constants */
+	TP_ACPI_VIDEO_570_PHSCMD = 0x87,	/* unknown magic constant :( */
+	TP_ACPI_VIDEO_570_PHSMASK = 0x03,	/* PHS bits that map to
+						 * video_status_flags */
+	TP_ACPI_VIDEO_570_PHS2CMD = 0x8b,	/* unknown magic constant :( */
+	TP_ACPI_VIDEO_570_PHS2SET = 0x80,	/* unknown magic constant :( */
+};
+
 static enum video_access_mode video_supported;
 static int video_orig_autosw;
 static acpi_handle vid_handle, vid2_handle;
 
 static int video_init(struct ibm_init_struct *iibm);
 static void video_exit(void);
-static int video_status(void);
-static int video_autosw(void);
-static int video_switch(void);
-static int video_switch2(int status);
-static int video_expand(void);
+static int video_outputsw_get(void);
+static int video_outputsw_set(int status);
+static int video_autosw_get(void);
+static int video_autosw_set(int enable);
+static int video_outputsw_cycle(void);
+static int video_expand_toggle(void);
 static int video_read(char *p);
 static int video_write(char *buf);
 
Signature · 8 lines
1.5.1


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
#17 lore raw

PATCH 18/20 ACPI: thinkpad-acpi: clean up CMOS commands subdriver

In reply to a message not in the archive

Some ThinkPad CMOS commands subdriver cleanups, and also rename/promote cmos_eval to a ACPI helper function, as it is used by many other subdrivers.

---
 drivers/misc/thinkpad_acpi.c |   39 ++++++++++++++++++++-------------------
 drivers/misc/thinkpad_acpi.h |    4 +++-
 2 files changed, 23 insertions(+), 20 deletions(-)
drivers/misc/thinkpad_acpi.c +20 -19
index 19c14bb..8829d3c 100644
@@ -273,6 +273,17 @@ static int _sta(acpi_handle handle)
 	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
  */
@@ -1550,14 +1561,6 @@ static int __init cmos_init(struct ibm_init_struct *iibm)
 	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;
@@ -1577,10 +1580,7 @@ static int cmos_read(char *p)
 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 &&
@@ -1589,8 +1589,9 @@ static int cmos_write(char *buf)
 		} else
 			return -EINVAL;
 
-		if (!cmos_eval(cmos_cmd))
-			return -EIO;
+		res = issue_thinkpad_cmos_command(cmos_cmd);
+		if (res)
+			return res;
 	}
 
 	return 0;
@@ -2093,7 +2094,7 @@ static int brightness_set(int value)
 	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;
@@ -2210,16 +2211,16 @@ static int volume_write(char *buf)
 			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;
@@ -2228,7 +2229,7 @@ static int volume_write(char *buf)
 		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;
 		}
drivers/misc/thinkpad_acpi.h +3 -1
index 3a8718a..fb0abb0 100644
@@ -116,6 +116,9 @@ static void drv_acpi_handle_init(char *name,
 	drv_acpi_handle_init(#object, &object##_handle, *object##_parent,	\
 		object##_paths, ARRAY_SIZE(object##_paths), &object##_path)
 
+/* ThinkPad ACPI helpers */
+static int issue_thinkpad_cmos_command(int cmos_cmd);
+
 /* procfs support */
 static struct proc_dir_entry *proc_dir;
 
@@ -275,7 +278,6 @@ static int brightness_write(char *buf);
  * CMOS subdriver
  */
 
-static int cmos_eval(int cmos_cmd);
 static int cmos_read(char *p);
 static int cmos_write(char *buf);
 
Signature · 8 lines
1.5.1


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
#18 lore raw

PATCH 19/20 ACPI: thinkpad-acpi: cleanup thermal subdriver for sysfs conversion

In reply to a message not in the archive

Clean-up the thermal subdriver for sysfs conversion. Make thermal_get_* reentrancy-safe while at it, and add the missing thermal_read_mode variable to the header file.

---
 drivers/misc/thinkpad_acpi.c |   79 ++++++++++++++++++++++++++++--------------
 drivers/misc/thinkpad_acpi.h |    8 ++++
 2 files changed, 61 insertions(+), 26 deletions(-)
drivers/misc/thinkpad_acpi.c +53 -26
index 8829d3c..e9aec87 100644
@@ -1818,13 +1818,13 @@ static int __init thermal_init(struct ibm_init_struct *iibm)
 
 		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;
@@ -1869,57 +1869,84 @@ static int __init thermal_init(struct ibm_init_struct *iibm)
 	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)
drivers/misc/thinkpad_acpi.h +8 -0
index fb0abb0..6432b28 100644
@@ -427,12 +427,20 @@ enum thermal_access_mode {
 	TPACPI_THERMAL_TPEC_16,		/* Use ACPI EC regs, 16 sensors */
 };
 
+enum { /* TPACPI_THERMAL_TPEC_* */
+	TP_EC_THERMAL_TMP0 = 0x78,	/* ACPI EC regs TMP 0..7 */
+	TP_EC_THERMAL_TMP8 = 0xC0,	/* ACPI EC regs TMP 8..15 */
+};
+
 #define TPACPI_MAX_THERMAL_SENSORS 16	/* Max thermal sensors supported */
 struct ibm_thermal_sensors_struct {
 	s32 temp[TPACPI_MAX_THERMAL_SENSORS];
 };
 
+static enum thermal_access_mode thermal_read_mode;
+
 static int thermal_init(struct ibm_init_struct *iibm);
+static int thermal_get_sensor(int idx, s32 *value);
 static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s);
 static int thermal_read(char *p);
 
Signature · 8 lines
1.5.1


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
#19 lore raw

PATCH 20/20 ACPI: thinkpad-acpi: improve fan watchdog messages

In reply to a message not in the archive

Improve some of the fan watchdog error messages to be a little more helpful.

---
 drivers/misc/thinkpad_acpi.c |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)
drivers/misc/thinkpad_acpi.c +7 -3
index e9aec87..9b4eea4 100644
@@ -2524,7 +2524,7 @@ static int fan_get_status(u8 *status)
 
 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();
 }
@@ -2554,9 +2554,13 @@ static int fan_get_speed(unsigned int *speed)
 
 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();
 	}
Signature · 8 lines
1.5.1


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
#21 lore raw

PATCH 4/20 ACPI: thinkpad-acpi: rename thinkpad constants

In reply to Henrique de Moraes Holschuh

Rename all IBMACPI_ constants, now that we are not called ibm-acpi anymore. Driver-specific constants are now prefixed TPACPI_, ThinkPad firmware specific ones are now prefixed TP_CMOS_, TP_ACPI_, or TP_EC_.

---
 drivers/misc/thinkpad_acpi.c |  188 +++++++++++++++++++++---------------------
 drivers/misc/thinkpad_acpi.h |   64 +++++++--------
 2 files changed, 125 insertions(+), 127 deletions(-)
drivers/misc/thinkpad_acpi.c +94 -94
index 80ef195..1683bfe 100644
@@ -781,16 +781,16 @@ static int video_init(void)
 
 	if (!vid_handle)
 		/* video switching not supported on R30, R31 */
-		video_supported = IBMACPI_VIDEO_NONE;
+		video_supported = TPACPI_VIDEO_NONE;
 	else if (acpi_evalf(vid_handle, &video_orig_autosw, "SWIT", "qd"))
 		/* 570 */
-		video_supported = IBMACPI_VIDEO_570;
+		video_supported = TPACPI_VIDEO_570;
 	else if (acpi_evalf(vid_handle, &video_orig_autosw, "^VADL", "qd"))
 		/* 600e/x, 770e, 770x */
-		video_supported = IBMACPI_VIDEO_770;
+		video_supported = TPACPI_VIDEO_770;
 	else
 		/* all others */
-		video_supported = IBMACPI_VIDEO_NEW;
+		video_supported = TPACPI_VIDEO_NEW;
 
 	return 0;
 }
@@ -805,15 +805,15 @@ static int video_status(void)
 	int status = 0;
 	int i;
 
-	if (video_supported == IBMACPI_VIDEO_570) {
+	if (video_supported == TPACPI_VIDEO_570) {
 		if (acpi_evalf(NULL, &i, "\\_SB.PHS", "dd", 0x87))
 			status = i & 3;
-	} else if (video_supported == IBMACPI_VIDEO_770) {
+	} 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 == IBMACPI_VIDEO_NEW) {
+	} else if (video_supported == TPACPI_VIDEO_NEW) {
 		acpi_evalf(NULL, NULL, "\\VUPS", "vd", 1);
 		if (acpi_evalf(NULL, &i, "\\VCDC", "d"))
 			status |= 0x02 * i;
@@ -832,10 +832,10 @@ static int video_autosw(void)
 {
 	int autosw = 0;
 
-	if (video_supported == IBMACPI_VIDEO_570)
+	if (video_supported == TPACPI_VIDEO_570)
 		acpi_evalf(vid_handle, &autosw, "SWIT", "d");
-	else if (video_supported == IBMACPI_VIDEO_770 ||
-		 video_supported == IBMACPI_VIDEO_NEW)
+	else if (video_supported == TPACPI_VIDEO_770 ||
+		 video_supported == TPACPI_VIDEO_NEW)
 		acpi_evalf(vid_handle, &autosw, "^VDEE", "d");
 
 	return autosw & 1;
@@ -848,7 +848,7 @@ static int video_switch(void)
 
 	if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", 1))
 		return -EIO;
-	ret = video_supported == IBMACPI_VIDEO_570 ?
+	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);
@@ -858,9 +858,9 @@ static int video_switch(void)
 
 static int video_expand(void)
 {
-	if (video_supported == IBMACPI_VIDEO_570)
+	if (video_supported == TPACPI_VIDEO_570)
 		return acpi_evalf(ec_handle, NULL, "_Q17", "v");
-	else if (video_supported == IBMACPI_VIDEO_770)
+	else if (video_supported == TPACPI_VIDEO_770)
 		return acpi_evalf(vid_handle, NULL, "VEXP", "v");
 	else
 		return acpi_evalf(NULL, NULL, "\\VEXP", "v");
@@ -870,10 +870,10 @@ static int video_switch2(int status)
 {
 	int ret;
 
-	if (video_supported == IBMACPI_VIDEO_570) {
+	if (video_supported == TPACPI_VIDEO_570) {
 		ret = acpi_evalf(NULL, NULL,
 				 "\\_SB.PHS2", "vdd", 0x8b, status | 0x80);
-	} else if (video_supported == IBMACPI_VIDEO_770) {
+	} else if (video_supported == TPACPI_VIDEO_770) {
 		int autosw = video_autosw();
 		if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", 1))
 			return -EIO;
@@ -904,12 +904,12 @@ static int video_read(char *p)
 	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));
-	if (video_supported == IBMACPI_VIDEO_NEW)
+	if (video_supported == TPACPI_VIDEO_NEW)
 		len += sprintf(p + len, "dvi:\t\t%s\n", enabled(status, 3));
 	len += sprintf(p + len, "auto:\t\t%s\n", enabled(autosw, 0));
 	len += sprintf(p + len, "commands:\tlcd_enable, lcd_disable\n");
 	len += sprintf(p + len, "commands:\tcrt_enable, crt_disable\n");
-	if (video_supported == IBMACPI_VIDEO_NEW)
+	if (video_supported == TPACPI_VIDEO_NEW)
 		len += sprintf(p + len, "commands:\tdvi_enable, dvi_disable\n");
 	len += sprintf(p + len, "commands:\tauto_enable, auto_disable\n");
 	len += sprintf(p + len, "commands:\tvideo_switch, expand_toggle\n");
@@ -936,10 +936,10 @@ static int video_write(char *buf)
 			enable |= 0x02;
 		} else if (strlencmp(cmd, "crt_disable") == 0) {
 			disable |= 0x02;
-		} else if (video_supported == IBMACPI_VIDEO_NEW &&
+		} else if (video_supported == TPACPI_VIDEO_NEW &&
 			   strlencmp(cmd, "dvi_enable") == 0) {
 			enable |= 0x08;
-		} else if (video_supported == IBMACPI_VIDEO_NEW &&
+		} else if (video_supported == TPACPI_VIDEO_NEW &&
 			   strlencmp(cmd, "dvi_disable") == 0) {
 			disable |= 0x08;
 		} else if (strlencmp(cmd, "auto_enable") == 0) {
@@ -1283,16 +1283,16 @@ static int led_init(void)
 {
 	if (!led_handle)
 		/* led not supported on R30, R31 */
-		led_supported = IBMACPI_LED_NONE;
+		led_supported = TPACPI_LED_NONE;
 	else if (strlencmp(led_path, "SLED") == 0)
 		/* 570 */
-		led_supported = IBMACPI_LED_570;
+		led_supported = TPACPI_LED_570;
 	else if (strlencmp(led_path, "SYSL") == 0)
 		/* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
-		led_supported = IBMACPI_LED_OLD;
+		led_supported = TPACPI_LED_OLD;
 	else
 		/* all others */
-		led_supported = IBMACPI_LED_NEW;
+		led_supported = TPACPI_LED_NEW;
 
 	return 0;
 }
@@ -1309,7 +1309,7 @@ static int led_read(char *p)
 	}
 	len += sprintf(p + len, "status:\t\tsupported\n");
 
-	if (led_supported == IBMACPI_LED_570) {
+	if (led_supported == TPACPI_LED_570) {
 		/* 570 */
 		int i, status;
 		for (i = 0; i < 8; i++) {
@@ -1354,23 +1354,23 @@ static int led_write(char *buf)
 		} else
 			return -EINVAL;
 
-		if (led_supported == IBMACPI_LED_570) {
+		if (led_supported == TPACPI_LED_570) {
 			/* 570 */
 			led = 1 << led;
 			if (!acpi_evalf(led_handle, NULL, NULL, "vdd",
 					led, led_sled_arg1[ind]))
 				return -EIO;
-		} else if (led_supported == IBMACPI_LED_OLD) {
+		} else if (led_supported == TPACPI_LED_OLD) {
 			/* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
 			led = 1 << led;
-			ret = ec_write(IBMACPI_LED_EC_HLMS, led);
+			ret = ec_write(TPACPI_LED_EC_HLMS, led);
 			if (ret >= 0)
 				ret =
-				    ec_write(IBMACPI_LED_EC_HLBL,
+				    ec_write(TPACPI_LED_EC_HLBL,
 				    	     led * led_exp_hlbl[ind]);
 			if (ret >= 0)
 				ret =
-				    ec_write(IBMACPI_LED_EC_HLCL,
+				    ec_write(TPACPI_LED_EC_HLCL,
 				    	     led * led_exp_hlcl[ind]);
 			if (ret < 0)
 				return ret;
@@ -1467,29 +1467,29 @@ static int thermal_init(void)
 				printk(IBM_ERR
 				       "ThinkPad ACPI EC access misbehaving, "
 				       "falling back to ACPI TMPx access mode\n");
-				thermal_read_mode = IBMACPI_THERMAL_ACPI_TMP07;
+				thermal_read_mode = TPACPI_THERMAL_ACPI_TMP07;
 			} else {
 				printk(IBM_ERR
 				       "ThinkPad ACPI EC access misbehaving, "
 				       "disabling thermal sensors access\n");
-				thermal_read_mode = IBMACPI_THERMAL_NONE;
+				thermal_read_mode = TPACPI_THERMAL_NONE;
 			}
 		} else {
 			thermal_read_mode =
 			    (ta2 != 0) ?
-			    IBMACPI_THERMAL_TPEC_16 : IBMACPI_THERMAL_TPEC_8;
+			    TPACPI_THERMAL_TPEC_16 : TPACPI_THERMAL_TPEC_8;
 		}
 	} else if (acpi_tmp7) {
 		if (acpi_evalf(ec_handle, NULL, "UPDT", "qv")) {
 			/* 600e/x, 770e, 770x */
-			thermal_read_mode = IBMACPI_THERMAL_ACPI_UPDT;
+			thermal_read_mode = TPACPI_THERMAL_ACPI_UPDT;
 		} else {
 			/* Standard ACPI TMPx access, max 8 sensors */
-			thermal_read_mode = IBMACPI_THERMAL_ACPI_TMP07;
+			thermal_read_mode = TPACPI_THERMAL_ACPI_TMP07;
 		}
 	} else {
 		/* temperatures not supported on 570, G4x, R30, R31, R32 */
-		thermal_read_mode = IBMACPI_THERMAL_NONE;
+		thermal_read_mode = TPACPI_THERMAL_NONE;
 	}
 
 	return 0;
@@ -1505,8 +1505,8 @@ static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s)
 		return -EINVAL;
 
 	switch (thermal_read_mode) {
-#if IBMACPI_MAX_THERMAL_SENSORS >= 16
-	case IBMACPI_THERMAL_TPEC_16:
+#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;
@@ -1514,15 +1514,15 @@ static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s)
 		}
 		/* fallthrough */
 #endif
-	case IBMACPI_THERMAL_TPEC_8:
+	case TPACPI_THERMAL_TPEC_8:
 		for (i = 0; i < 8; i++) {
 			if (!acpi_ec_read(0x78 + i, &tmp))
 				return -EIO;
 			s->temp[i] = tmp * 1000;
 		}
-		return (thermal_read_mode == IBMACPI_THERMAL_TPEC_16) ? 16 : 8;
+		return (thermal_read_mode == TPACPI_THERMAL_TPEC_16) ? 16 : 8;
 
-	case IBMACPI_THERMAL_ACPI_UPDT:
+	case TPACPI_THERMAL_ACPI_UPDT:
 		if (!acpi_evalf(ec_handle, NULL, "UPDT", "v"))
 			return -EIO;
 		for (i = 0; i < 8; i++) {
@@ -1533,7 +1533,7 @@ static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s)
 		}
 		return 8;
 
-	case IBMACPI_THERMAL_ACPI_TMP07:
+	case TPACPI_THERMAL_ACPI_TMP07:
 		for (i = 0; i < 8; i++) {
 			tmpi[3] = '0' + i;
 			if (!acpi_evalf(ec_handle, &t, tmpi, "d"))
@@ -1542,7 +1542,7 @@ static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s)
 		}
 		return 8;
 
-	case IBMACPI_THERMAL_NONE:
+	case TPACPI_THERMAL_NONE:
 	default:
 		return 0;
 	}
@@ -1848,18 +1848,18 @@ static int volume_write(char *buf)
 /*
  * FAN ACCESS MODES
  *
- * IBMACPI_FAN_RD_ACPI_GFAN:
+ * TPACPI_FAN_RD_ACPI_GFAN:
  * 	ACPI GFAN method: returns fan level
  *
- * 	see IBMACPI_FAN_WR_ACPI_SFAN
+ * 	see TPACPI_FAN_WR_ACPI_SFAN
  * 	EC 0x2f not available if GFAN exists
  *
- * IBMACPI_FAN_WR_ACPI_SFAN:
+ * TPACPI_FAN_WR_ACPI_SFAN:
  * 	ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
  *
  * 	EC 0x2f might be available *for reading*, but never for writing.
  *
- * IBMACPI_FAN_WR_TPEC:
+ * TPACPI_FAN_WR_TPEC:
  * 	ThinkPad EC register 0x2f (HFSP): fan control loop mode Supported
  * 	on almost all ThinkPads
  *
@@ -1888,7 +1888,7 @@ static int volume_write(char *buf)
  *			0x00 = stop
  * 			0x07 = max (set when temperatures critical)
  * 		Some ThinkPads may have other levels, see
- * 		IBMACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
+ * 		TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
  *
  *	FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
  *	boot. Apparently the EC does not intialize it, so unless ACPI DSDT
@@ -1923,7 +1923,7 @@ static int volume_write(char *buf)
  *	For firmware bugs, refer to:
  *	http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
  *
- * IBMACPI_FAN_WR_ACPI_FANS:
+ * TPACPI_FAN_WR_ACPI_FANS:
  *	ThinkPad X31, X40, X41.  Not available in the X60.
  *
  *	FANS ACPI handle: takes three arguments: low speed, medium speed,
@@ -1940,7 +1940,7 @@ static int volume_write(char *buf)
  * 	ACPI DSDT switches which set is in use depending on various
  * 	factors.
  *
- * 	IBMACPI_FAN_WR_TPEC is also available and should be used to
+ * 	TPACPI_FAN_WR_TPEC is also available and should be used to
  * 	command the fan.  The X31/X40/X41 seems to have 8 fan levels,
  * 	but the ACPI tables just mention level 7.
  */
@@ -1966,21 +1966,21 @@ IBM_HANDLE(sfan, ec, "SFAN",	/* 570 */
 
 static int fan_init(void)
 {
-	fan_status_access_mode = IBMACPI_FAN_NONE;
-	fan_control_access_mode = IBMACPI_FAN_WR_NONE;
+	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;
 
 	if (gfan_handle) {
 		/* 570, 600e/x, 770e, 770x */
-		fan_status_access_mode = IBMACPI_FAN_RD_ACPI_GFAN;
+		fan_status_access_mode = TPACPI_FAN_RD_ACPI_GFAN;
 	} else {
 		/* all other ThinkPads: note that even old-style
 		 * ThinkPad ECs supports the fan control register */
 		if (likely(acpi_ec_read(fan_status_offset,
 					&fan_control_initial_status))) {
-			fan_status_access_mode = IBMACPI_FAN_RD_TPEC;
+			fan_status_access_mode = TPACPI_FAN_RD_TPEC;
 
 			/* In some ThinkPads, neither the EC nor the ACPI
 			 * DSDT initialize the fan status, and it ends up
@@ -2015,9 +2015,9 @@ static int fan_init(void)
 
 	if (sfan_handle) {
 		/* 570, 770x-JL */
-		fan_control_access_mode = IBMACPI_FAN_WR_ACPI_SFAN;
+		fan_control_access_mode = TPACPI_FAN_WR_ACPI_SFAN;
 		fan_control_commands |=
-		    IBMACPI_FAN_CMD_LEVEL | IBMACPI_FAN_CMD_ENABLE;
+		    TPACPI_FAN_CMD_LEVEL | TPACPI_FAN_CMD_ENABLE;
 	} else {
 		if (!gfan_handle) {
 			/* gfan without sfan means no fan control */
@@ -2026,16 +2026,16 @@ static int fan_init(void)
 			if (fans_handle) {
 				/* X31, X40, X41 */
 				fan_control_access_mode =
-				    IBMACPI_FAN_WR_ACPI_FANS;
+				    TPACPI_FAN_WR_ACPI_FANS;
 				fan_control_commands |=
-				    IBMACPI_FAN_CMD_SPEED |
-				    IBMACPI_FAN_CMD_LEVEL |
-				    IBMACPI_FAN_CMD_ENABLE;
+				    TPACPI_FAN_CMD_SPEED |
+				    TPACPI_FAN_CMD_LEVEL |
+				    TPACPI_FAN_CMD_ENABLE;
 			} else {
-				fan_control_access_mode = IBMACPI_FAN_WR_TPEC;
+				fan_control_access_mode = TPACPI_FAN_WR_TPEC;
 				fan_control_commands |=
-				    IBMACPI_FAN_CMD_LEVEL |
-				    IBMACPI_FAN_CMD_ENABLE;
+				    TPACPI_FAN_CMD_LEVEL |
+				    TPACPI_FAN_CMD_ENABLE;
 			}
 		}
 	}
@@ -2048,10 +2048,10 @@ static int fan_get_status(u8 *status)
 	u8 s;
 
 	/* TODO:
-	 * Add IBMACPI_FAN_RD_ACPI_FANS ? */
+	 * Add TPACPI_FAN_RD_ACPI_FANS ? */
 
 	switch (fan_status_access_mode) {
-	case IBMACPI_FAN_RD_ACPI_GFAN:
+	case TPACPI_FAN_RD_ACPI_GFAN:
 		/* 570, 600e/x, 770e, 770x */
 
 		if (unlikely(!acpi_evalf(gfan_handle, &s, NULL, "d")))
@@ -2062,7 +2062,7 @@ static int fan_get_status(u8 *status)
 
 		break;
 
-	case IBMACPI_FAN_RD_TPEC:
+	case TPACPI_FAN_RD_TPEC:
 		/* all except 570, 600e/x, 770e, 770x */
 		if (unlikely(!acpi_ec_read(fan_status_offset, &s)))
 			return -EIO;
@@ -2090,7 +2090,7 @@ static int fan_get_speed(unsigned int *speed)
 	u8 hi, lo;
 
 	switch (fan_status_access_mode) {
-	case IBMACPI_FAN_RD_TPEC:
+	case TPACPI_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)))
@@ -2140,7 +2140,7 @@ static void fan_watchdog_reset(void)
 static int fan_set_level(int level)
 {
 	switch (fan_control_access_mode) {
-	case IBMACPI_FAN_WR_ACPI_SFAN:
+	case TPACPI_FAN_WR_ACPI_SFAN:
 		if (level >= 0 && level <= 7) {
 			if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", level))
 				return -EIO;
@@ -2148,10 +2148,10 @@ static int fan_set_level(int level)
 			return -EINVAL;
 		break;
 
-	case IBMACPI_FAN_WR_ACPI_FANS:
-	case IBMACPI_FAN_WR_TPEC:
-		if ((level != IBMACPI_FAN_EC_AUTO) &&
-		    (level != IBMACPI_FAN_EC_DISENGAGED) &&
+	case TPACPI_FAN_WR_ACPI_FANS:
+	case TPACPI_FAN_WR_TPEC:
+		if ((level != TP_EC_FAN_AUTO) &&
+		    (level != TP_EC_FAN_FULLSPEED) &&
 		    ((level < 0) || (level > 7)))
 			return -EINVAL;
 
@@ -2173,14 +2173,14 @@ static int fan_set_enable(void)
 	int rc;
 
 	switch (fan_control_access_mode) {
-	case IBMACPI_FAN_WR_ACPI_FANS:
-	case IBMACPI_FAN_WR_TPEC:
+	case TPACPI_FAN_WR_ACPI_FANS:
+	case TPACPI_FAN_WR_TPEC:
 		if ((rc = fan_get_status(&s)) < 0)
 			return rc;
 
 		/* Don't go out of emergency fan mode */
 		if (s != 7)
-			s = IBMACPI_FAN_EC_AUTO;
+			s = TP_EC_FAN_AUTO;
 
 		if (!acpi_ec_write(fan_status_offset, s))
 			return -EIO;
@@ -2188,7 +2188,7 @@ static int fan_set_enable(void)
 			fan_control_status_known = 1;
 		break;
 
-	case IBMACPI_FAN_WR_ACPI_SFAN:
+	case TPACPI_FAN_WR_ACPI_SFAN:
 		if ((rc = fan_get_status(&s)) < 0)
 			return rc;
 
@@ -2211,15 +2211,15 @@ static int fan_set_enable(void)
 static int fan_set_disable(void)
 {
 	switch (fan_control_access_mode) {
-	case IBMACPI_FAN_WR_ACPI_FANS:
-	case IBMACPI_FAN_WR_TPEC:
+	case TPACPI_FAN_WR_ACPI_FANS:
+	case TPACPI_FAN_WR_TPEC:
 		if (!acpi_ec_write(fan_status_offset, 0x00))
 			return -EIO;
 		else
 			fan_control_status_known = 1;
 		break;
 
-	case IBMACPI_FAN_WR_ACPI_SFAN:
+	case TPACPI_FAN_WR_ACPI_SFAN:
 		if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", 0x00))
 			return -EIO;
 		break;
@@ -2233,7 +2233,7 @@ static int fan_set_disable(void)
 static int fan_set_speed(int speed)
 {
 	switch (fan_control_access_mode) {
-	case IBMACPI_FAN_WR_ACPI_FANS:
+	case TPACPI_FAN_WR_ACPI_FANS:
 		if (speed >= 0 && speed <= 65535) {
 			if (!acpi_evalf(fans_handle, NULL, NULL, "vddd",
 					speed, speed, speed))
@@ -2256,7 +2256,7 @@ static int fan_read(char *p)
 	unsigned int speed = 0;
 
 	switch (fan_status_access_mode) {
-	case IBMACPI_FAN_RD_ACPI_GFAN:
+	case TPACPI_FAN_RD_ACPI_GFAN:
 		/* 570, 600e/x, 770e, 770x */
 		if ((rc = fan_get_status(&status)) < 0)
 			return rc;
@@ -2266,7 +2266,7 @@ static int fan_read(char *p)
 			       (status != 0) ? "enabled" : "disabled", status);
 		break;
 
-	case IBMACPI_FAN_RD_TPEC:
+	case TPACPI_FAN_RD_TPEC:
 		/* all except 570, 600e/x, 770e, 770x */
 		if ((rc = fan_get_status(&status)) < 0)
 			return rc;
@@ -2277,7 +2277,7 @@ static int fan_read(char *p)
 			else
 				/* Return most likely status. In fact, it
 				 * might be the only possible status */
-				status = IBMACPI_FAN_EC_AUTO;
+				status = TP_EC_FAN_AUTO;
 		}
 
 		len += sprintf(p + len, "status:\t\t%s\n",
@@ -2291,25 +2291,25 @@ static int fan_read(char *p)
 
 		len += sprintf(p + len, "speed:\t\t%d\n", speed);
 
-		if (status & IBMACPI_FAN_EC_DISENGAGED)
+		if (status & TP_EC_FAN_FULLSPEED)
 			/* Disengaged mode takes precedence */
 			len += sprintf(p + len, "level:\t\tdisengaged\n");
-		else if (status & IBMACPI_FAN_EC_AUTO)
+		else if (status & TP_EC_FAN_AUTO)
 			len += sprintf(p + len, "level:\t\tauto\n");
 		else
 			len += sprintf(p + len, "level:\t\t%d\n", status);
 		break;
 
-	case IBMACPI_FAN_NONE:
+	case TPACPI_FAN_NONE:
 	default:
 		len += sprintf(p + len, "status:\t\tnot supported\n");
 	}
 
-	if (fan_control_commands & IBMACPI_FAN_CMD_LEVEL) {
+	if (fan_control_commands & TPACPI_FAN_CMD_LEVEL) {
 		len += sprintf(p + len, "commands:\tlevel <level>");
 
 		switch (fan_control_access_mode) {
-		case IBMACPI_FAN_WR_ACPI_SFAN:
+		case TPACPI_FAN_WR_ACPI_SFAN:
 			len += sprintf(p + len, " (<level> is 0-7)\n");
 			break;
 
@@ -2320,12 +2320,12 @@ static int fan_read(char *p)
 		}
 	}
 
-	if (fan_control_commands & IBMACPI_FAN_CMD_ENABLE)
+	if (fan_control_commands & TPACPI_FAN_CMD_ENABLE)
 		len += sprintf(p + len, "commands:\tenable, disable\n"
 			       "commands:\twatchdog <timeout> (<timeout> is 0 (off), "
 			       "1-120 (seconds))\n");
 
-	if (fan_control_commands & IBMACPI_FAN_CMD_SPEED)
+	if (fan_control_commands & TPACPI_FAN_CMD_SPEED)
 		len += sprintf(p + len, "commands:\tspeed <speed>"
 			       " (<speed> is 0-65535)\n");
 
@@ -2337,9 +2337,9 @@ static int fan_write_cmd_level(const char *cmd, int *rc)
 	int level;
 
 	if (strlencmp(cmd, "level auto") == 0)
-		level = IBMACPI_FAN_EC_AUTO;
+		level = TP_EC_FAN_AUTO;
 	else if (strlencmp(cmd, "level disengaged") == 0)
-		level = IBMACPI_FAN_EC_DISENGAGED;
+		level = TP_EC_FAN_FULLSPEED;
 	else if (sscanf(cmd, "level %d", &level) != 1)
 		return 0;
 
@@ -2412,13 +2412,13 @@ static int fan_write(char *buf)
 	int rc = 0;
 
 	while (!rc && (cmd = next_cmd(&buf))) {
-		if (!((fan_control_commands & IBMACPI_FAN_CMD_LEVEL) &&
+		if (!((fan_control_commands & TPACPI_FAN_CMD_LEVEL) &&
 		      fan_write_cmd_level(cmd, &rc)) &&
-		    !((fan_control_commands & IBMACPI_FAN_CMD_ENABLE) &&
+		    !((fan_control_commands & TPACPI_FAN_CMD_ENABLE) &&
 		      (fan_write_cmd_enable(cmd, &rc) ||
 		       fan_write_cmd_disable(cmd, &rc) ||
 		       fan_write_cmd_watchdog(cmd, &rc))) &&
-		    !((fan_control_commands & IBMACPI_FAN_CMD_SPEED) &&
+		    !((fan_control_commands & TPACPI_FAN_CMD_SPEED) &&
 		      fan_write_cmd_speed(cmd, &rc))
 		    )
 			rc = -EINVAL;
drivers/misc/thinkpad_acpi.h +31 -33

102 lines not on this page · raw message

Signature · 1 line
1.5.1
#23 lore raw

PATCH 9/20 ACPI: thinkpad-acpi: uncouple subdriver init from ibms struct

In reply to Henrique de Moraes Holschuh

From: Henrique de Moraes Holschuh <[email protected]>

Move the .init method from ibms struct to another struct, and use a list head to control which subdrivers have been activated.

This allows us to have the subdriver init methods marked __init, saving quite a lot of .text size, and even a bit of .data size as some data can now be made __initdata.

---
 drivers/misc/thinkpad_acpi.c |  402 ++++++++++++++++++++++++++----------------
 drivers/misc/thinkpad_acpi.h |   51 +++---
 2 files changed, 278 insertions(+), 175 deletions(-)
drivers/misc/thinkpad_acpi.c +248 -154
index e8fc8da..5611268 100644
@@ -470,7 +470,7 @@ static char *next_cmd(char **cmds)
  * thinkpad-acpi init subdriver
  */
 
-static int thinkpad_acpi_driver_init(void)
+static int __init thinkpad_acpi_driver_init(struct ibm_init_struct *iibm)
 {
 	printk(IBM_INFO "%s v%s\n", IBM_DESC, IBM_VERSION);
 	printk(IBM_INFO "%s\n", IBM_URL);
@@ -492,6 +492,11 @@ static int thinkpad_acpi_driver_read(char *p)
 	return len;
 }
 
+static struct ibm_struct thinkpad_acpi_driver_data = {
+	.name = "driver",
+	.read = thinkpad_acpi_driver_read,
+};
+
 /*************************************************************************
  * Hotkey subdriver
  */
@@ -501,7 +506,7 @@ static int hotkey_mask_supported;
 static int hotkey_orig_status;
 static int hotkey_orig_mask;
 
-static int hotkey_init(void)
+static int __init hotkey_init(struct ibm_init_struct *iibm)
 {
 	vdbg_printk(TPACPI_DBG_INIT, "initializing hotkey subdriver\n");
 
@@ -640,13 +645,24 @@ static int hotkey_write(char *buf)
 	return 0;
 }
 
+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,
+};
+
 /*************************************************************************
  * Bluetooth subdriver
  */
 
 static int bluetooth_supported;
 
-static int bluetooth_init(void)
+static int __init bluetooth_init(struct ibm_init_struct *iibm)
 {
 	vdbg_printk(TPACPI_DBG_INIT, "initializing bluetooth subdriver\n");
 
@@ -716,13 +732,19 @@ static int bluetooth_write(char *buf)
 	return 0;
 }
 
+static struct ibm_struct bluetooth_driver_data = {
+	.name = "bluetooth",
+	.read = bluetooth_read,
+	.write = bluetooth_write,
+};
+
 /*************************************************************************
  * Wan subdriver
  */
 
 static int wan_supported;
 
-static int wan_init(void)
+static int __init wan_init(struct ibm_init_struct *iibm)
 {
 	vdbg_printk(TPACPI_DBG_INIT, "initializing wan subdriver\n");
 
@@ -789,6 +811,13 @@ static int wan_write(char *buf)
 	return 0;
 }
 
+static struct ibm_struct wan_driver_data = {
+	.name = "wan",
+	.read = wan_read,
+	.write = wan_write,
+	.experimental = 1,
+};
+
 /*************************************************************************
  * Video subdriver
  */
@@ -805,7 +834,7 @@ IBM_HANDLE(vid, root, "\\_SB.PCI.AGP.VGA",	/* 570 */
 
 IBM_HANDLE(vid2, root, "\\_SB.PCI0.AGPB.VID");	/* G41 */
 
-static int video_init(void)
+static int __init video_init(struct ibm_init_struct *iibm)
 {
 	int ivga;
 
@@ -1011,6 +1040,13 @@ static int video_write(char *buf)
 	return 0;
 }
 
+static struct ibm_struct video_driver_data = {
+	.name = "video",
+	.read = video_read,
+	.write = video_write,
+	.exit = video_exit,
+};
+
 /*************************************************************************
  * Light (thinklight) subdriver
  */
@@ -1021,7 +1057,7 @@ static int light_status_supported;
 IBM_HANDLE(lght, root, "\\LGHT");	/* A21e, A2xm/p, T20-22, X20-21 */
 IBM_HANDLE(ledb, ec, "LEDB");		/* G4x */
 
-static int light_init(void)
+static int __init light_init(struct ibm_init_struct *iibm)
 {
 	vdbg_printk(TPACPI_DBG_INIT, "initializing light subdriver\n");
 
@@ -1093,6 +1129,12 @@ static int light_write(char *buf)
 	return 0;
 }
 
+static struct ibm_struct light_driver_data = {
+	.name = "light",
+	.read = light_read,
+	.write = light_write,
+};
+
 /*************************************************************************
  * Dock subdriver
  */
@@ -1110,7 +1152,7 @@ IBM_HANDLE(pci, root, "\\_SB.PCI");	/* 570 */
 
 #define dock_docked() (_sta(dock_handle) & 1)
 
-static int dock_init(void)
+static int __init dock_init(struct ibm_init_struct *iibm)
 {
 	vdbg_printk(TPACPI_DBG_INIT, "initializing dock subdriver\n");
 
@@ -1184,6 +1226,24 @@ static int dock_write(char *buf)
 	return 0;
 }
 
+static struct ibm_struct dock_driver_data[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,
+	 .type = ACPI_SYSTEM_NOTIFY,
+	},
+};
+
 #endif /* CONFIG_THINKPAD_ACPI_DOCK */
 
 /*************************************************************************
@@ -1211,7 +1271,7 @@ IBM_HANDLE(bay2_ej, bay2, "_EJ3",	/* 600e/x, 770e, A3x */
 	   "_EJ0",			/* 770x */
 	   );				/* all others */
 
-static int bay_init(void)
+static int __init bay_init(struct ibm_init_struct *iibm)
 {
 	vdbg_printk(TPACPI_DBG_INIT, "initializing bay subdriver\n");
 
@@ -1298,13 +1358,23 @@ static int bay_write(char *buf)
 
 	return 0;
 }
+
+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,
+};
+
 #endif /* CONFIG_THINKPAD_ACPI_BAY */
 
 /*************************************************************************
  * CMOS subdriver
  */
 
-static int cmos_init(void)
+static int __init cmos_init(struct ibm_init_struct *iibm)
 {
 	vdbg_printk(TPACPI_DBG_INIT,
 		"initializing cmos commands subdriver\n");
@@ -1362,6 +1432,11 @@ static int cmos_write(char *buf)
 	return 0;
 }
 
+static struct ibm_struct cmos_driver_data = {
+	.name = "cmos",
+	.read = cmos_read,
+	.write = cmos_write,
+};
 
 /*************************************************************************
  * LED subdriver
@@ -1374,7 +1449,7 @@ IBM_HANDLE(led, ec, "SLED",	/* 570 */
 	   "LED",		/* all others */
 	   );			/* R30, R31 */
 
-static int led_init(void)
+static int __init led_init(struct ibm_init_struct *iibm)
 {
 	vdbg_printk(TPACPI_DBG_INIT, "initializing LED subdriver\n");
 
@@ -1487,13 +1562,19 @@ static int led_write(char *buf)
 	return 0;
 }
 
+static struct ibm_struct led_driver_data = {
+	.name = "led",
+	.read = led_read,
+	.write = led_write,
+};
+
 /*************************************************************************
  * Beep subdriver
  */
 
 IBM_HANDLE(beep, ec, "BEEP");	/* all except R30, R31 */
 
-static int beep_init(void)
+static int __init beep_init(struct ibm_init_struct *iibm)
 {
 	vdbg_printk(TPACPI_DBG_INIT, "initializing beep subdriver\n");
 
@@ -1540,13 +1621,19 @@ static int beep_write(char *buf)
 	return 0;
 }
 
+static struct ibm_struct beep_driver_data = {
+	.name = "beep",
+	.read = beep_read,
+	.write = beep_write,
+};
+
 /*************************************************************************
  * Thermal subdriver
  */
 
 static enum thermal_access_mode thermal_read_mode;
 
-static int thermal_init(void)
+static int __init thermal_init(struct ibm_init_struct *iibm)
 {
 	u8 t, ta1, ta2;
 	int i;
@@ -1692,6 +1779,11 @@ static int thermal_read(char *p)
 	return len;
 }
 
+static struct ibm_struct thermal_driver_data = {
+	.name = "thermal",
+	.read = thermal_read,
+};
+
 /*************************************************************************
  * EC Dump subdriver
  */
@@ -1755,6 +1847,13 @@ static int ecdump_write(char *buf)
 	return 0;
 }
 
+static struct ibm_struct ecdump_driver_data = {
+	.name = "ecdump",
+	.read = ecdump_read,
+	.write = ecdump_write,
+	.experimental = 1,
+};
+
 /*************************************************************************
  * Backlight/brightness subdriver
  */
@@ -1766,7 +1865,7 @@ static struct backlight_ops ibm_backlight_data = {
         .update_status  = brightness_update_status,
 };
 
-static int brightness_init(void)
+static int __init brightness_init(struct ibm_init_struct *iibm)
 {
 	int b;
 
@@ -1883,6 +1982,13 @@ static int brightness_write(char *buf)
 	return 0;
 }
 
+static struct ibm_struct brightness_driver_data = {
+	.name = "brightness",
+	.read = brightness_read,
+	.write = brightness_write,
+	.exit = brightness_exit,
+};
+
 /*************************************************************************
  * Volume subdriver
  */
@@ -1967,6 +2073,11 @@ static int volume_write(char *buf)
 	return 0;
 }
 
+static struct ibm_struct volume_driver_data = {
+	.name = "volume",
+	.read = volume_read,
+	.write = volume_write,
+};
 
 /*************************************************************************
  * Fan subdriver
@@ -2092,7 +2203,7 @@ IBM_HANDLE(sfan, ec, "SFAN",	/* 570 */
 	   "JFNS",		/* 770x-JL */
 	   );			/* all others */
 
-static int fan_init(void)
+static int __init fan_init(struct ibm_init_struct *iibm)
 {
 	vdbg_printk(TPACPI_DBG_INIT, "initializing fan subdriver\n");
 
@@ -2568,6 +2679,14 @@ static int fan_write(char *buf)
 	return rc;
 }
 
+static struct ibm_struct fan_driver_data = {
+	.name = "fan",
+	.read = fan_read,
+	.write = fan_write,
+	.exit = fan_exit,
+	.experimental = 1,
+};
+
 /****************************************************************************
  ****************************************************************************
  *
@@ -2580,159 +2699,45 @@ static int fan_write(char *buf)
 static struct proc_dir_entry *proc_dir = NULL;
 
 /* Subdriver registry */
-static struct ibm_struct ibms[] = {
-	{
-	 .name = "driver",
-	 .init = thinkpad_acpi_driver_init,
-	 .read = thinkpad_acpi_driver_read,
-	 },
-	{
-	 .name = "hotkey",
-	 .hid = IBM_HKEY_HID,
-	 .init = hotkey_init,
-	 .read = hotkey_read,
-	 .write = hotkey_write,
-	 .exit = hotkey_exit,
-	 .notify = hotkey_notify,
-	 .handle = &hkey_handle,
-	 .type = ACPI_DEVICE_NOTIFY,
-	 },
-	{
-	 .name = "bluetooth",
-	 .init = bluetooth_init,
-	 .read = bluetooth_read,
-	 .write = bluetooth_write,
-	 },
-	{
-	 .name = "wan",
-	 .init = wan_init,
-	 .read = wan_read,
-	 .write = wan_write,
-	 .experimental = 1,
-	 },
-	{
-	 .name = "video",
-	 .init = video_init,
-	 .read = video_read,
-	 .write = video_write,
-	 .exit = video_exit,
-	 },
-	{
-	 .name = "light",
-	 .init = light_init,
-	 .read = light_read,
-	 .write = light_write,
-	 },
-#ifdef CONFIG_THINKPAD_ACPI_DOCK
-	{
-	 .name = "dock",
-	 .init = dock_init,
-	 .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,
-	 .type = ACPI_SYSTEM_NOTIFY,
-	 },
-#endif
-#ifdef CONFIG_THINKPAD_ACPI_BAY
-	{
-	 .name = "bay",
-	 .init = bay_init,
-	 .read = bay_read,
-	 .write = bay_write,
-	 .notify = bay_notify,
-	 .handle = &bay_handle,
-	 .type = ACPI_SYSTEM_NOTIFY,
-	 },
-#endif /* CONFIG_THINKPAD_ACPI_BAY */
-	{
-	 .name = "cmos",
-	 .init = cmos_init,
-	 .read = cmos_read,
-	 .write = cmos_write,
-	 },
-	{
-	 .name = "led",
-	 .init = led_init,
-	 .read = led_read,
-	 .write = led_write,
-	 },
-	{
-	 .name = "beep",
-	 .init = beep_init,
-	 .read = beep_read,
-	 .write = beep_write,
-	 },
-	{
-	 .name = "thermal",
-	 .init = thermal_init,
-	 .read = thermal_read,
-	 },
-	{
-	 .name = "ecdump",
-	 .read = ecdump_read,
-	 .write = ecdump_write,
-	 .experimental = 1,
-	 },
-	{
-	 .name = "brightness",
-	 .read = brightness_read,
-	 .write = brightness_write,
-	 .init = brightness_init,
-	 .exit = brightness_exit,
-	 },
-	{
-	 .name = "volume",
-	 .read = volume_read,
-	 .write = volume_write,
-	 },
-	{
-	 .name = "fan",
-	 .read = fan_read,
-	 .write = fan_write,
-	 .init = fan_init,
-	 .exit = fan_exit,
-	 .experimental = 1,
-	 },
-};
+static LIST_HEAD(tpacpi_all_drivers);
+
 
 /*
  * Module and infrastructure proble, init and exit handling
  */
 
 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
-static const char * str_supported(int is_supported)
+static const char * __init str_supported(int is_supported)
 {
-	static const char * const text_unsupported = "not supported";
+	static char text_unsupported[] __initdata = "not supported";
 
-	return (is_supported)? text_unsupported + 4 : text_unsupported;
+	return (is_supported)? &text_unsupported[4] : &text_unsupported[0];
 }
 #endif /* CONFIG_THINKPAD_ACPI_DEBUG */
 
-static int __init ibm_init(struct ibm_struct *ibm)
+static int __init ibm_init(struct ibm_init_struct *iibm)
 {
 	int ret;
+	struct ibm_struct *ibm = iibm->data;
 	struct proc_dir_entry *entry;
 
+	BUG_ON(ibm == NULL);
+
+	INIT_LIST_HEAD(&ibm->all_drivers);
+
 	if (ibm->experimental && !experimental)
 		return 0;
 
 	dbg_printk(TPACPI_DBG_INIT,
 		"probing for %s\n", ibm->name);
 
-	if (ibm->init) {
-		ret = ibm->init();
+	if (iibm->init) {
+		ret = iibm->init(iibm);
 		if (ret > 0)
 			return 0;	/* probe failed */
 		if (ret)
 			return ret;
+
 		ibm->init_called = 1;
 	}
 
@@ -2775,6 +2780,8 @@ static int __init ibm_init(struct ibm_struct *ibm)
 		ibm->proc_created = 1;
 	}
 
+	list_add_tail(&ibm->all_drivers, &tpacpi_all_drivers);
+
 	return 0;
 
 err_out:
@@ -2789,6 +2796,9 @@ err_out:
 static void ibm_exit(struct ibm_struct *ibm)
 {
 	dbg_printk(TPACPI_DBG_EXIT, "removing %s\n", ibm->name);
+
+	list_del_init(&ibm->all_drivers);
+
 	if (ibm->notify_installed) {
 		dbg_printk(TPACPI_DBG_EXIT,
 			"%s: acpi_remove_notify_handler\n", ibm->name);
@@ -2817,6 +2827,8 @@ static void ibm_exit(struct ibm_struct *ibm)
 		ibm->exit();
 		ibm->init_called = 0;
 	}
+
+	dbg_printk(TPACPI_DBG_INIT, "finished removing %s\n", ibm->name);
 }
 
 /* Probing */
@@ -2875,18 +2887,95 @@ static int __init probe_for_thinkpad(void)
 
 /* Module init, exit, parameters */
 
+static struct ibm_init_struct ibms_init[] __initdata = {
+	{
+		.init = thinkpad_acpi_driver_init,
+		.data = &thinkpad_acpi_driver_data,
+	},
+	{
+		.init = hotkey_init,
+		.data = &hotkey_driver_data,
+	},
+	{
+		.init = bluetooth_init,
+		.data = &bluetooth_driver_data,
+	},
+	{
+		.init = wan_init,
+		.data = &wan_driver_data,
+	},
+	{
+		.init = video_init,
+		.data = &video_driver_data,
+	},
+	{
+		.init = light_init,
+		.data = &light_driver_data,
+	},
+#ifdef CONFIG_THINKPAD_ACPI_DOCK
+	{
+		.init = dock_init,
+		.data = &dock_driver_data[0],
+	},
+	{
+		.data = &dock_driver_data[1],
+	},
+#endif
+#ifdef CONFIG_THINKPAD_ACPI_BAY
+	{
+		.init = bay_init,
+		.data = &bay_driver_data,
+	},
+#endif
+	{
+		.init = cmos_init,
+		.data = &cmos_driver_data,
+	},
+	{
+		.init = led_init,
+		.data = &led_driver_data,
+	},
+	{
+		.init = beep_init,
+		.data = &beep_driver_data,
+	},
+	{
+		.init = thermal_init,
+		.data = &thermal_driver_data,
+	},
+	{
+		.data = &ecdump_driver_data,
+	},
+	{
+		.init = brightness_init,
+		.data = &brightness_driver_data,
+	},
+	{
+		.data = &volume_driver_data,
+	},
+	{
+		.init = fan_init,
+		.data = &fan_driver_data,
+	},
+};
+
 static int __init set_ibm_param(const char *val, struct kernel_param *kp)
 {
 	unsigned int i;
+	struct ibm_struct *ibm;
 
-	for (i = 0; i < ARRAY_SIZE(ibms); i++)
-		if (strcmp(ibms[i].name, kp->name) == 0 && ibms[i].write) {
-			if (strlen(val) > sizeof(ibms[i].param) - 2)
+	for (i = 0; i < ARRAY_SIZE(ibms_init); i++) {
+		ibm = ibms_init[i].data;
+		BUG_ON(ibm == NULL);
+
+		if (strcmp(ibm->name, kp->name) == 0 && ibm->write) {
+			if (strlen(val) > sizeof(ibms_init[i].param) - 2)
 				return -ENOSPC;
-			strcpy(ibms[i].param, val);
-			strcat(ibms[i].param, ",");
+			strcpy(ibms_init[i].param, val);
+			strcat(ibms_init[i].param, ",");
 			return 0;
 		}
+	}
 
 	return -EINVAL;
 }
@@ -2938,10 +3027,10 @@ static int __init thinkpad_acpi_module_init(void)
 	}
 	proc_dir->owner = THIS_MODULE;
 
-	for (i = 0; i < ARRAY_SIZE(ibms); i++) {
-		ret = ibm_init(&ibms[i]);
-		if (ret >= 0 && *ibms[i].param)
-			ret = ibms[i].write(ibms[i].param);
+	for (i = 0; i < ARRAY_SIZE(ibms_init); i++) {
+		ret = ibm_init(&ibms_init[i]);
+		if (ret >= 0 && *ibms_init[i].param)
+			ret = ibms_init[i].data->write(ibms_init[i].param);
 		if (ret < 0) {
 			thinkpad_acpi_module_exit();
 			return ret;
@@ -2953,10 +3042,15 @@ static int __init thinkpad_acpi_module_init(void)
 
 static void thinkpad_acpi_module_exit(void)
 {
-	int i;
+	struct ibm_struct *ibm, *itmp;
+
+	list_for_each_entry_safe_reverse(ibm, itmp,
+					 &tpacpi_all_drivers,
+					 all_drivers) {
+		ibm_exit(ibm);
+	}
 
-	for (i = ARRAY_SIZE(ibms) - 1; i >= 0; i--)
-		ibm_exit(&ibms[i]);
+	dbg_printk(TPACPI_DBG_INIT, "finished subdriver exit path...\n");
 
 	if (proc_dir)
 		remove_proc_entry(IBM_DIR, acpi_root_dir);
drivers/misc/thinkpad_acpi.h +30 -21

148 lines not on this page · raw message

Signature · 1 line
1.5.1
#22 lore raw

PATCH 5/20 ACPI: thinkpad-acpi: update fan firmware documentation

In reply to Henrique de Moraes Holschuh

Update some stuff in the in-code text describing the ThinkPad fan firmware. This patch has no code changes.

---
 drivers/misc/thinkpad_acpi.c |   28 +++++++++++++---------------
 1 files changed, 13 insertions(+), 15 deletions(-)
drivers/misc/thinkpad_acpi.c +13 -15
index 1683bfe..4131a78 100644
@@ -1852,16 +1852,17 @@ static int volume_write(char *buf)
  * 	ACPI GFAN method: returns fan level
  *
  * 	see TPACPI_FAN_WR_ACPI_SFAN
- * 	EC 0x2f not available if GFAN exists
+ * 	EC 0x2f (HFSP) not available if GFAN exists
  *
  * TPACPI_FAN_WR_ACPI_SFAN:
  * 	ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
  *
- * 	EC 0x2f might be available *for reading*, but never for writing.
+ * 	EC 0x2f (HFSP) might be available *for reading*, but do not use
+ * 	it for writing.
  *
  * TPACPI_FAN_WR_TPEC:
- * 	ThinkPad EC register 0x2f (HFSP): fan control loop mode Supported
- * 	on almost all ThinkPads
+ * 	ThinkPad EC register 0x2f (HFSP): fan control loop mode
+ * 	Supported on almost all ThinkPads
  *
  * 	Fan speed changes of any sort (including those caused by the
  * 	disengaged mode) are usually done slowly by the firmware as the
@@ -1875,12 +1876,13 @@ static int volume_write(char *buf)
  *	 7	automatic mode engaged;
  *  		(default operation mode of the ThinkPad)
  * 		fan level is ignored in this mode.
- *	 6	disengage mode (takes precedence over bit 7);
+ *	 6	full speed mode (takes precedence over bit 7);
  *		not available on all thinkpads.  May disable
- *		the tachometer, and speeds up fan to 100% duty-cycle,
- *		which speeds it up far above the standard RPM
- *		levels.  It is not impossible that it could cause
- *		hardware damage.
+ *		the tachometer while the fan controller ramps up
+ *		the speed (which can take up to a few *minutes*).
+ *		Speeds up fan to 100% duty-cycle, which is far above
+ *		the standard RPM levels.  It is not impossible that
+ *		it could cause hardware damage.
  *	5-3	unused in some models.  Extra bits for fan level
  *		in others, but still useless as all values above
  *		7 map to the same speed as level 7 in these models.
@@ -1916,9 +1918,8 @@ static int volume_write(char *buf)
  *	FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
  *	might result.
  *
- *	FIRMWARE BUG: when EC 0x2f bit 6 is set (disengaged mode), this
- *	register is not invalidated in ThinkPads that disable tachometer
- *	readings.  Thus, the tachometer readings go stale.
+ *	FIRMWARE BUG: may go stale while the EC is switching to full speed
+ *	mode.
  *
  *	For firmware bugs, refer to:
  *	http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
@@ -2283,9 +2284,6 @@ static int fan_read(char *p)
 		len += sprintf(p + len, "status:\t\t%s\n",
 			       (status != 0) ? "enabled" : "disabled");
 
-		/* No ThinkPad boots on disengaged mode, we can safely
-		 * assume the tachometer is online if fan control status
-		 * was unknown */
 		if ((rc = fan_get_speed(&speed)) < 0)
 			return rc;
 
Signature · 1 line
1.5.1
#26 lore raw

PATCH 11/20 ACPI: thinkpad-acpi: use bitfields to hold subdriver flags

In reply to Henrique de Moraes Holschuh

Save some memory by using bitfields to hold boolean flags for the subdrivers.

---
 drivers/misc/thinkpad_acpi.c |   32 ++++++++++++++++----------------
 drivers/misc/thinkpad_acpi.h |   13 +++++++------
 2 files changed, 23 insertions(+), 22 deletions(-)
drivers/misc/thinkpad_acpi.c +16 -16
index cddf81b..a5efd06 100644
@@ -339,7 +339,7 @@ static int __init setup_notify(struct ibm_struct *ibm)
 		}
 		return -ENODEV;
 	}
-	ibm->notify_installed = 1;
+	ibm->flags.notify_installed = 1;
 	return 0;
 }
 
@@ -372,7 +372,7 @@ static int __init register_tpacpi_subdriver(struct ibm_struct *ibm)
 		kfree(ibm->driver);
 		ibm->driver = NULL;
 	} else if (!ret)
-		ibm->driver_registered = 1;
+		ibm->flags.driver_registered = 1;
 
 	return ret;
 }
@@ -815,7 +815,7 @@ static struct ibm_struct wan_driver_data = {
 	.name = "wan",
 	.read = wan_read,
 	.write = wan_write,
-	.experimental = 1,
+	.flags.experimental = 1,
 };
 
 /*************************************************************************
@@ -1851,7 +1851,7 @@ static struct ibm_struct ecdump_driver_data = {
 	.name = "ecdump",
 	.read = ecdump_read,
 	.write = ecdump_write,
-	.experimental = 1,
+	.flags.experimental = 1,
 };
 
 /*************************************************************************
@@ -2684,7 +2684,7 @@ static struct ibm_struct fan_driver_data = {
 	.read = fan_read,
 	.write = fan_write,
 	.exit = fan_exit,
-	.experimental = 1,
+	.flags.experimental = 1,
 };
 
 /****************************************************************************
@@ -2725,7 +2725,7 @@ static int __init ibm_init(struct ibm_init_struct *iibm)
 
 	INIT_LIST_HEAD(&ibm->all_drivers);
 
-	if (ibm->experimental && !experimental)
+	if (ibm->flags.experimental && !experimental)
 		return 0;
 
 	dbg_printk(TPACPI_DBG_INIT,
@@ -2738,7 +2738,7 @@ static int __init ibm_init(struct ibm_init_struct *iibm)
 		if (ret)
 			return ret;
 
-		ibm->init_called = 1;
+		ibm->flags.init_called = 1;
 	}
 
 	if (ibm->hid) {
@@ -2777,7 +2777,7 @@ static int __init ibm_init(struct ibm_init_struct *iibm)
 		entry->read_proc = &dispatch_read;
 		if (ibm->write)
 			entry->write_proc = &dispatch_write;
-		ibm->proc_created = 1;
+		ibm->flags.proc_created = 1;
 	}
 
 	list_add_tail(&ibm->all_drivers, &tpacpi_all_drivers);
@@ -2799,33 +2799,33 @@ static void ibm_exit(struct ibm_struct *ibm)
 
 	list_del_init(&ibm->all_drivers);
 
-	if (ibm->notify_installed) {
+	if (ibm->flags.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->notify_installed = 0;
+		ibm->flags.notify_installed = 0;
 	}
 
-	if (ibm->proc_created) {
+	if (ibm->flags.proc_created) {
 		dbg_printk(TPACPI_DBG_EXIT,
 			"%s: remove_proc_entry\n", ibm->name);
 		remove_proc_entry(ibm->name, proc_dir);
-		ibm->proc_created = 0;
+		ibm->flags.proc_created = 0;
 	}
 
-	if (ibm->driver_registered) {
+	if (ibm->flags.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->driver_registered = 0;
+		ibm->flags.driver_registered = 0;
 	}
 
-	if (ibm->init_called && ibm->exit) {
+	if (ibm->flags.init_called && ibm->exit) {
 		ibm->exit();
-		ibm->init_called = 0;
+		ibm->flags.init_called = 0;
 	}
 
 	dbg_printk(TPACPI_DBG_INIT, "finished removing %s\n", ibm->name);
drivers/misc/thinkpad_acpi.h +7 -6
index 2020398..8b72061 100644
@@ -157,12 +157,13 @@ struct ibm_struct {
 
 	struct list_head all_drivers;
 
-	int driver_registered;
-	int proc_created;
-	int init_called;
-	int notify_installed;
-
-	int experimental;
+	struct {
+		u8 driver_registered:1;
+		u8 proc_created:1;
+		u8 init_called:1;
+		u8 notify_installed:1;
+		u8 experimental:1;
+	} flags;
 };
 
 struct ibm_init_struct {
Signature · 1 line
1.5.1
reviewer
#24 lore raw

Re: [PATCH 09/20] ACPI: thinkpad-acpi: uncouple subdriver init from ibms struct

In reply to Henrique de Moraes Holschuh
Quoted 8 lines · Henrique de Moraes Holschuh

From: Henrique de Moraes Holschuh <[email protected]>

Move the .init method from ibms struct to another struct, and use a list head to control which subdrivers have been activated.

This allows us to have the subdriver init methods marked __init, saving quite a lot of .text size, and even a bit of .data size as some data can now be made __initdata.

does this save any space when the driver is compiled as a module?

-Len

reviewer
#10 lore raw

Re: [PATCH 12/20] ACPI: thinkpad-acpi: use bitfields for module flags

In reply to Henrique de Moraes Holschuh
Quoted 3 lines · Henrique de Moraes Holschuh

Use a bitfield to hold boolean module-wide flags, to conserve some memory. It is easy and it is clean, so we do it just for the heck of it even if it saves very little space.

I think that is an under-statement.
This plus the patch before it actually increase text size for a static size change of 0.

-Len

before:

   text    data     bss     dec     hex filename
  24002    3286     728   28016    6d70 drivers/misc/thinkpad_acpi.o

after

   text    data     bss     dec     hex filename
  24082    3270     664   28016    6d70 drivers/misc/thinkpad_acpi.o
reviewer
#27 lore raw
In reply to Henrique de Moraes Holschuh

On Saturday 21 April 2007 10:08, Henrique de Moraes Holschuh wrote:
...

Quoted 22 lines

and to receive the following **new** patches:
ACPI: thinkpad-acpi: rename register_ibmacpi_subdriver
ACPI: thinkpad-acpi: rename one stray use of ibm-acpi in a comment
ACPI: thinkpad-acpi: rename module glue
ACPI: thinkpad-acpi: rename thinkpad constants
ACPI: thinkpad-acpi: update fan firmware documentation
ACPI: thinkpad-acpi: add debug mode
ACPI: thinkpad-acpi: clean up probing and move init to subdrivers
ACPI: thinkpad-acpi: add subdriver debug statements
ACPI: thinkpad-acpi: uncouple subdriver init from ibms struct
ACPI: thinkpad-acpi: improve thinkpad detection
ACPI: thinkpad-acpi: use bitfields to hold subdriver flags
ACPI: thinkpad-acpi: use bitfields for module flags
ACPI: thinkpad-acpi: prepare for device model conversion
ACPI: thinkpad-acpi: mark acpi helper functions __must_check
ACPI: thinkpad-acpi: clean up hotkey subdriver
ACPI: thinkpad-acpi: cleanup bluetooth and wan for sysfs conversion
ACPI: thinkpad-acpi: cleanup video subdriver
ACPI: thinkpad-acpi: clean up CMOS commands subdriver
ACPI: thinkpad-acpi: cleanup thermal subdriver for sysfs conversion
ACPI: thinkpad-acpi: improve fan watchdog messages

Quoted 3 lines

This is the preparatory work for the sysfs conversion. Some of the conversion is already ready for merge (the part that is hwmon-compatible), and I will send a pull request with it soon.

applied to acpi-test.

thanks,
-Len

#25 lore raw

Re: [PATCH 09/20] ACPI: thinkpad-acpi: uncouple subdriver init from ibms struct

In reply to Len Brown
Quoted 11 lines · Len Brown
Quoted 8 lines · Henrique de Moraes Holschuh

From: Henrique de Moraes Holschuh <[email protected]>

Move the .init method from ibms struct to another struct, and use a list head to control which subdrivers have been activated.

This allows us to have the subdriver init methods marked __init, saving quite a lot of .text size, and even a bit of .data size as some data can now be made __initdata.

does this save any space when the driver is compiled as a module?

Using gcc 4.1.2 20061115 pre-release (from Debian 4.1.1-21) and objdump -w -h, I get the following changes:

bss: no change
text: decreases from 0x46d8 to 0x3658
data: decreases from 0x7b4 to 0x784
init.text: increases from 0x5ff to 0x171f
init.data: increases from 0 to 0x2b6

and now the usual issues with gcc and its .rodata handling even while inside __init and __initdata:

rodata*: total increase of 0xbc bytes.

So yes, there are savings when used as a module, unless objdump is lying to me or I failed to understand how these things play together when the kernel links the module at runmtime.

Signature · 4 lines
  "One disk to rule them all, One disk to find them. One disk to bring
  them all and in the darkness grind them. In the Land of Redmond
  where the shadows lie." -- The Silicon Valley Tarot
  Henrique Holschuh
#11 lore raw

Re: [PATCH 12/20] ACPI: thinkpad-acpi: use bitfields for module flags

In reply to Len Brown
Quoted 11 lines · Len Brown
Quoted 3 lines · Henrique de Moraes Holschuh

Use a bitfield to hold boolean module-wide flags, to conserve some memory. It is easy and it is clean, so we do it just for the heck of it even if it saves very little space.

I think that is an under-statement.
This plus the patch before it actually increase text size for a static size change of 0.

-Len

Quoted 7 lines

before:

   text    data     bss     dec     hex filename
  24002    3286     728   28016    6d70 drivers/misc/thinkpad_acpi.o

after

   text    data     bss     dec     hex filename
  24082    3270     664   28016    6d70 drivers/misc/thinkpad_acpi.o

Well, as module, same Debian gcc 4.1.2 pre-release I used before, and objdump -w -h on the .ko file:

.bss: decreases from 0x22c to 0x20c
.data: decreases from 0x7a4 to 0x5b4
.init.data: no change
.text: decreases from 0x3658 to 0x3628
.init.text: increases from 0x174a to 0x1763
.rodata*: no change

Same remark as before: maybe I am mistaken on how these things work when the linking is done at insmod time.

I really did not even consider checking what happens in a static build, it is quite possible that size increases with these patches. One of the other patches really causes an unamusing size increase due to data structure alignment that I will address later (it is lower priority and would cause too much rework on patches I did not submit yet). It happened when some arrays were broken up to components and arrays of pointers to them.

Signature · 4 lines
  "One disk to rule them all, One disk to find them. One disk to bring
  them all and in the darkness grind them. In the Land of Redmond
  where the shadows lie." -- The Silicon Valley Tarot
  Henrique Holschuh
#28 lore raw
In reply to Len Brown
Quoted 1 line · Len Brown

applied to acpi-test.

Thanks, Len!

Signature · 4 lines
  "One disk to rule them all, One disk to find them. One disk to bring
  them all and in the darkness grind them. In the Land of Redmond
  where the shadows lie." -- The Silicon Valley Tarot
  Henrique Holschuh