コード例 #1
0
static gboolean
fu_plugin_thunderbolt_power_coldplug (FuPlugin *plugin, GError **error)
{
	FuPluginData *data = fu_plugin_get_data (plugin);

	if (!fu_plugin_thunderbolt_power_supported (plugin)) {
		g_set_error (error,
			     FWUPD_ERROR,
			     FWUPD_ERROR_NOT_SUPPORTED,
			     "missing kernel support for intel-wmi-thunderbolt");
		return FALSE;
	}

	/* this means no devices were found at coldplug by thunderbolt plugin */
	if (data->needs_forcepower) {
		if (!fu_plugin_thunderbolt_power_set (plugin, TRUE, error))
			return FALSE;
		/* in case this was a re-coldplug */
		if (data->timeout_id != 0)
			g_source_remove (data->timeout_id);

		/* reset force power to off after enough time to enumerate */
		data->timeout_id =
			g_timeout_add (TBT_NEW_DEVICE_TIMEOUT * 10000,
				       fu_plugin_thunderbolt_power_reset_cb,
				       plugin);
	}

	return TRUE;
}
コード例 #2
0
static gboolean
fu_plugin_thunderbolt_power_reset_cb (gpointer user_data)
{
	FuPlugin *plugin = FU_PLUGIN (user_data);
	FuPluginData *data = fu_plugin_get_data (plugin);

	if (!fu_plugin_thunderbolt_power_set (plugin, FALSE, NULL))
		g_warning ("failed to reset thunderbolt power");
	data->timeout_id = 0;
	return FALSE;
}
コード例 #3
0
gboolean
fu_plugin_update_prepare (FuPlugin *plugin,
			  FwupdInstallFlags flags,
			  FuDevice *device,
			  GError **error)
{
	FuPluginData *data = fu_plugin_get_data (plugin);
	g_autoptr(GUdevDevice) udevice = NULL;
	const gchar *devpath;

	/* only run for thunderbolt plugin */
	if (g_strcmp0 (fu_device_get_plugin (device), "thunderbolt") != 0)
		return TRUE;

	/* reset any timers that might still be running from coldplug */
	if (data->timeout_id != 0) {
		g_source_remove (data->timeout_id);
		data->timeout_id = 0;
	}

	devpath = fu_device_get_metadata (device, "sysfs-path");

	udevice = g_udev_client_query_by_sysfs_path (data->udev, devpath);
	if (udevice != NULL) {
		data->needs_forcepower = FALSE;
		return TRUE;
	}
	data->updating = TRUE;
	if (!fu_plugin_thunderbolt_power_set (plugin, TRUE, error))
		return FALSE;

	data->needs_forcepower = TRUE;

	/* wait for the device to come back onto the bus */
	fu_device_set_status (device, FWUPD_STATUS_DEVICE_RESTART);
	for (guint i = 0; i < 5; i++) {
		g_autoptr(GUdevDevice) udevice_tmp = NULL;
		g_usleep (TBT_NEW_DEVICE_TIMEOUT * G_USEC_PER_SEC);
		udevice_tmp = g_udev_client_query_by_sysfs_path (data->udev, devpath);
		if (udevice_tmp != NULL)
			return TRUE;
	}

	/* device did not wake up */
	g_set_error (error,
		     FWUPD_ERROR,
		     FWUPD_ERROR_NOT_SUPPORTED,
		     "device did not wake up when required");
	return FALSE;
}
コード例 #4
0
gboolean
fu_plugin_update_cleanup (FuPlugin *plugin,
			  FuDevice *device,
			  GError **error)
{
	FuPluginData *data = fu_plugin_get_data (plugin);

	/* only run for thunderbolt plugin */
	if (g_strcmp0 (fu_device_get_plugin (device), "thunderbolt") != 0)
		return TRUE;

	if (data->needs_forcepower &&
	    !fu_plugin_thunderbolt_power_set (plugin, FALSE, error))
		return FALSE;
	return TRUE;
}
コード例 #5
0
static gboolean
fu_plugin_thunderbolt_power_coldplug (FuPlugin *plugin, GError **error)
{
	FuPluginData *data = fu_plugin_get_data (plugin);

	if (!fu_plugin_thunderbolt_power_bolt_supported (plugin) &&
	    !fu_plugin_thunderbolt_power_kernel_supported (plugin)) {
		g_set_error (error,
			     FWUPD_ERROR,
			     FWUPD_ERROR_NOT_SUPPORTED,
			     "No support for force power via kernel or bolt");
		return FALSE;
	}

	/* this means no devices were found at coldplug by thunderbolt plugin */
	if (data->needs_forcepower) {
		if (!fu_plugin_thunderbolt_power_set (plugin, TRUE, error))
			return FALSE;

		fu_plugin_thunderbolt_reset_timeout (plugin);
	}

	return TRUE;
}