Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5fba344c authored by Henrique de Moraes Holschuh's avatar Henrique de Moraes Holschuh Committed by Len Brown
Browse files

ACPI: thinkpad-acpi: clean up probing and move init to subdrivers



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").

Signed-off-by: default avatarHenrique de Moraes Holschuh <hmh@hmh.eng.br>
Signed-off-by: default avatarLen Brown <len.brown@intel.com>
parent 132ce091
Loading
Loading
Loading
Loading
+149 −82
Original line number Original line Diff line number Diff line
@@ -277,7 +277,7 @@ static int _sta(acpi_handle handle)
 * ACPI device model
 * ACPI device model
 */
 */


static void __init ibm_handle_init(char *name,
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)
			   char **paths, int num_paths, char **path)
{
{
@@ -351,8 +351,8 @@ static int __init register_tpacpi_subdriver(struct ibm_struct *ibm)


	ibm->driver = kzalloc(sizeof(struct acpi_driver), GFP_KERNEL);
	ibm->driver = kzalloc(sizeof(struct acpi_driver), GFP_KERNEL);
	if (!ibm->driver) {
	if (!ibm->driver) {
		printk(IBM_ERR "kmalloc(ibm->driver) failed\n");
		printk(IBM_ERR "kzalloc(ibm->driver) failed\n");
		return -1;
		return -ENOMEM;
	}
	}


	sprintf(ibm->driver->name, "%s_%s", IBM_NAME, ibm->name);
	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",
		printk(IBM_ERR "acpi_bus_register_driver(%s) failed: %d\n",
		       ibm->hid, ret);
		       ibm->hid, ret);
		kfree(ibm->driver);
		kfree(ibm->driver);
	}
		ibm->driver = NULL;
	} else if (!ret)
		ibm->driver_registered = 1;


	return ret;
	return ret;
}
}
@@ -495,6 +497,8 @@ static int hotkey_orig_mask;


static int hotkey_init(void)
static int hotkey_init(void)
{
{
	IBM_HANDLE_INIT(hkey);

	/* hotkey not supported on 570 */
	/* hotkey not supported on 570 */
	hotkey_supported = hkey_handle != NULL;
	hotkey_supported = hkey_handle != NULL;


@@ -508,14 +512,15 @@ static int hotkey_init(void)
			return -ENODEV;
			return -ENODEV;
	}
	}


	return 0;
	return (hotkey_supported)? 0 : 1;
}
}


static void hotkey_exit(void)
static void hotkey_exit(void)
{
{
	if (hotkey_supported)
	if (hotkey_supported) {
		hotkey_set(hotkey_orig_status, hotkey_orig_mask);
		hotkey_set(hotkey_orig_status, hotkey_orig_mask);
	}
	}
}


static void hotkey_notify(struct ibm_struct *ibm, u32 event)
static void hotkey_notify(struct ibm_struct *ibm, u32 event)
{
{
@@ -628,12 +633,14 @@ static int bluetooth_supported;


static int bluetooth_init(void)
static int bluetooth_init(void)
{
{
	IBM_HANDLE_INIT(hkey);

	/* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
	/* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
	   G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
	   G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
	bluetooth_supported = hkey_handle &&
	bluetooth_supported = hkey_handle &&
	    acpi_evalf(hkey_handle, NULL, "GBDC", "qv");
	    acpi_evalf(hkey_handle, NULL, "GBDC", "qv");


	return 0;
	return (bluetooth_supported)? 0 : 1;
}
}


static int bluetooth_status(void)
static int bluetooth_status(void)
@@ -697,10 +704,12 @@ static int wan_supported;


static int wan_init(void)
static int wan_init(void)
{
{
	IBM_HANDLE_INIT(hkey);

	wan_supported = hkey_handle &&
	wan_supported = hkey_handle &&
	    acpi_evalf(hkey_handle, NULL, "GWAN", "qv");
	    acpi_evalf(hkey_handle, NULL, "GWAN", "qv");


	return 0;
	return (wan_supported)? 0 : 1;
}
}


static int wan_status(void)
static int wan_status(void)
@@ -775,6 +784,9 @@ static int video_init(void)
{
{
	int ivga;
	int ivga;


	IBM_HANDLE_INIT(vid);
	IBM_HANDLE_INIT(vid2);

	if (vid2_handle && acpi_evalf(NULL, &ivga, "\\IVGA", "d") && ivga)
	if (vid2_handle && acpi_evalf(NULL, &ivga, "\\IVGA", "d") && ivga)
		/* G41, assume IVGA doesn't change */
		/* G41, assume IVGA doesn't change */
		vid_handle = vid2_handle;
		vid_handle = vid2_handle;
@@ -792,7 +804,7 @@ static int video_init(void)
		/* all others */
		/* all others */
		video_supported = TPACPI_VIDEO_NEW;
		video_supported = TPACPI_VIDEO_NEW;


	return 0;
	return (video_supported != TPACPI_VIDEO_NONE)? 0 : 1;
}
}


static void video_exit(void)
static void video_exit(void)
@@ -979,6 +991,10 @@ IBM_HANDLE(ledb, ec, "LEDB"); /* G4x */


static int light_init(void)
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 not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
	light_supported = (cmos_handle || lght_handle) && !ledb_handle;
	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,
		light_status_supported = acpi_evalf(ec_handle, NULL,
						    "KBLT", "qv");
						    "KBLT", "qv");


	return 0;
	return (light_supported)? 0 : 1;
}
}


static int light_read(char *p)
static int light_read(char *p)
@@ -1044,9 +1060,6 @@ static int light_write(char *buf)
 * Dock subdriver
 * 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
#ifdef CONFIG_THINKPAD_ACPI_DOCK


IBM_HANDLE(dock, root, "\\_SB.GDCK",	/* X30, X31, X40 */
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 */
	   "\\_SB.PCI.ISA.SLCE",	/* 570 */
    );				/* A21e,G4x,R30,R31,R32,R40,R40e,R50e */
    );				/* 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)
#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)
static void dock_notify(struct ibm_struct *ibm, u32 event)
{
{
	int docked = dock_docked();
	int docked = dock_docked();
@@ -1147,6 +1171,13 @@ IBM_HANDLE(bay2_ej, bay2, "_EJ3", /* 600e/x, 770e, A3x */


static int bay_init(void)
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 &&
	bay_status_supported = bay_handle &&
	    acpi_evalf(bay_handle, NULL, "_STA", "qv");
	    acpi_evalf(bay_handle, NULL, "_STA", "qv");
	bay_status2_supported = bay2_handle &&
	bay_status2_supported = bay2_handle &&
@@ -1157,7 +1188,8 @@ static int bay_init(void)
	bay_eject2_supported = bay2_handle && bay2_ej_handle &&
	bay_eject2_supported = bay2_handle && bay2_ej_handle &&
	    (strlencmp(bay2_ej_path, "_EJ0") == 0 || experimental);
	    (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)
static void bay_notify(struct ibm_struct *ibm, u32 event)
@@ -1221,6 +1253,13 @@ static int bay_write(char *buf)
 * CMOS subdriver
 * CMOS subdriver
 */
 */


static int cmos_init(void)
{
	IBM_HANDLE_INIT(cmos);

	return (cmos_handle)? 0 : 1;
}

static int cmos_eval(int cmos_cmd)
static int cmos_eval(int cmos_cmd)
{
{
	if (cmos_handle)
	if (cmos_handle)
@@ -1281,6 +1320,8 @@ IBM_HANDLE(led, ec, "SLED", /* 570 */


static int led_init(void)
static int led_init(void)
{
{
	IBM_HANDLE_INIT(led);

	if (!led_handle)
	if (!led_handle)
		/* led not supported on R30, R31 */
		/* led not supported on R30, R31 */
		led_supported = TPACPI_LED_NONE;
		led_supported = TPACPI_LED_NONE;
@@ -1294,7 +1335,7 @@ static int led_init(void)
		/* all others */
		/* all others */
		led_supported = TPACPI_LED_NEW;
		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"))
#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 */
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)
static int beep_read(char *p)
{
{
	int len = 0;
	int len = 0;
@@ -1436,7 +1484,9 @@ static int thermal_init(void)
{
{
	u8 t, ta1, ta2;
	u8 t, ta1, ta2;
	int i;
	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) {
	if (ibm_thinkpad_ec_found && experimental) {
		/*
		/*
@@ -1492,7 +1542,7 @@ static int thermal_init(void)
		thermal_read_mode = TPACPI_THERMAL_NONE;
		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)
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_control_status_known = 1;
	fan_watchdog_maxinterval = 0;
	fan_watchdog_maxinterval = 0;


	IBM_HANDLE_INIT(fans);
	IBM_HANDLE_INIT(gfan);
	IBM_HANDLE_INIT(sfan);

	if (gfan_handle) {
	if (gfan_handle) {
		/* 570, 600e/x, 770e, 770x */
		/* 570, 600e/x, 770e, 770x */
		fan_status_access_mode = TPACPI_FAN_RD_ACPI_GFAN;
		fan_status_access_mode = TPACPI_FAN_RD_ACPI_GFAN;
@@ -2010,7 +2064,7 @@ static int fan_init(void)
			printk(IBM_ERR
			printk(IBM_ERR
			       "ThinkPad ACPI EC access misbehaving, "
			       "ThinkPad ACPI EC access misbehaving, "
			       "fan status and control unavailable\n");
			       "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)
static int fan_get_status(u8 *status)
@@ -2485,6 +2541,7 @@ static struct ibm_struct ibms[] = {
#ifdef CONFIG_THINKPAD_ACPI_DOCK
#ifdef CONFIG_THINKPAD_ACPI_DOCK
	{
	{
	 .name = "dock",
	 .name = "dock",
	 .init = dock_init,
	 .read = dock_read,
	 .read = dock_read,
	 .write = dock_write,
	 .write = dock_write,
	 .notify = dock_notify,
	 .notify = dock_notify,
@@ -2512,6 +2569,7 @@ static struct ibm_struct ibms[] = {
#endif /* CONFIG_THINKPAD_ACPI_BAY */
#endif /* CONFIG_THINKPAD_ACPI_BAY */
	{
	{
	 .name = "cmos",
	 .name = "cmos",
	 .init = cmos_init,
	 .read = cmos_read,
	 .read = cmos_read,
	 .write = cmos_write,
	 .write = cmos_write,
	 },
	 },
@@ -2523,6 +2581,7 @@ static struct ibm_struct ibms[] = {
	 },
	 },
	{
	{
	 .name = "beep",
	 .name = "beep",
	 .init = beep_init,
	 .read = beep_read,
	 .read = beep_read,
	 .write = beep_write,
	 .write = beep_write,
	 },
	 },
@@ -2571,20 +2630,33 @@ static int __init ibm_init(struct ibm_struct *ibm)
	if (ibm->experimental && !experimental)
	if (ibm->experimental && !experimental)
		return 0;
		return 0;


	if (ibm->hid) {
		ret = register_tpacpi_subdriver(ibm);
		if (ret < 0)
			return ret;
		ibm->driver_registered = 1;
	}

	if (ibm->init) {
	if (ibm->init) {
		ret = ibm->init();
		ret = ibm->init();
		if (ret != 0)
		if (ret > 0)
			return 0;	/* probe failed */
		if (ret)
			return ret;
			return ret;
		ibm->init_called = 1;
		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) {
	if (ibm->read) {
		entry = create_proc_entry(ibm->name,
		entry = create_proc_entry(ibm->name,
					  S_IFREG | S_IRUGO | S_IWUSR,
					  S_IFREG | S_IRUGO | S_IWUSR,
@@ -2592,7 +2664,8 @@ static int __init ibm_init(struct ibm_struct *ibm)
		if (!entry) {
		if (!entry) {
			printk(IBM_ERR "unable to create proc entry %s\n",
			printk(IBM_ERR "unable to create proc entry %s\n",
			       ibm->name);
			       ibm->name);
			return -ENODEV;
			ret = -ENODEV;
			goto err_out;
		}
		}
		entry->owner = THIS_MODULE;
		entry->owner = THIS_MODULE;
		entry->data = ibm;
		entry->data = ibm;
@@ -2602,36 +2675,36 @@ static int __init ibm_init(struct ibm_struct *ibm)
		ibm->proc_created = 1;
		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;
	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)
static void ibm_exit(struct ibm_struct *ibm)
{
{
	if (ibm->notify_installed)
	if (ibm->notify_installed) {
		acpi_remove_notify_handler(*ibm->handle, ibm->type,
		acpi_remove_notify_handler(*ibm->handle, ibm->type,
					   dispatch_notify);
					   dispatch_notify);
		ibm->notify_installed = 0;
	}


	if (ibm->proc_created)
	if (ibm->proc_created) {
		remove_proc_entry(ibm->name, proc_dir);
		remove_proc_entry(ibm->name, proc_dir);

		ibm->proc_created = 0;
	if (ibm->init_called && ibm->exit)
	}
		ibm->exit();


	if (ibm->driver_registered) {
	if (ibm->driver_registered) {
		acpi_bus_unregister_driver(ibm->driver);
		acpi_bus_unregister_driver(ibm->driver);
		kfree(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;
	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 */
/* Module init, exit, parameters */


static int __init set_ibm_param(const char *val, struct kernel_param *kp)
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;
	int ret, i;


	if (acpi_disabled)
	ret = probe_for_thinkpad();
		return -ENODEV;
	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();
	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(ecrd);
	IBM_HANDLE_INIT(ecwr);
	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);
	proc_dir = proc_mkdir(IBM_DIR, acpi_root_dir);
	if (!proc_dir) {
	if (!proc_dir) {
+2 −2
Original line number Original line Diff line number Diff line
@@ -242,8 +242,8 @@ static int cmos_write(char *buf);
 * Dock subdriver
 * Dock subdriver
 */
 */


static acpi_handle pci_handle;
#ifdef CONFIG_THINKPAD_ACPI_DOCK
#ifdef CONFIG_THINKPAD_ACPI_DOCK
static acpi_handle pci_handle;
static acpi_handle dock_handle;
static acpi_handle dock_handle;


static void dock_notify(struct ibm_struct *ibm, u32 event);
static void dock_notify(struct ibm_struct *ibm, u32 event);