Exemplo n.º 1
0
i2c_tunable::i2c_tunable(const char *path, const char *name, bool is_adapter) : tunable("", 0.9, _("Good"), _("Bad"), _("Unknown"))
{
	ifstream file;
	char filename[4096];
	string devname;

	sprintf(filename, "%s/name", path);
	file.open(filename, ios::in);
	if (file) {
		getline(file, devname);
		file.close();
	}

	if (is_adapter) {
		sprintf(i2c_path, "%s/device/power/control", path);
		sprintf(filename, "%s/device", path);
	} else {
		sprintf(i2c_path, "%s/power/control", path);
		sprintf(filename, "%s/device", path);
	}

	if (device_has_runtime_pm(filename))
		sprintf(desc, _("Runtime PM for I2C %s %s (%s)"), (is_adapter ? _("Adapter") : _("Device")), name, (devname.empty() ? "" : devname.c_str()));
	else
		sprintf(desc, _("I2C %s %s has no runtime power management"), (is_adapter ? _("Adapter") : _("Device")), name);

	sprintf(toggle_good, "echo 'auto' > '%s';", i2c_path);
	sprintf(toggle_bad, "echo 'on' > '%s';", i2c_path);
}
Exemplo n.º 2
0
runtime_tunable::runtime_tunable(const char *path, const char *bus, const char *dev) : tunable("", 0.4, _("Good"), _("Bad"), _("Unknown"))
{
	ifstream file;
	sprintf(runtime_path, "%s/power/control", path);


	sprintf(desc, _("Runtime PM for %s device %s"), bus, dev);
	if (!device_has_runtime_pm(path))
		sprintf(desc, _("%s device %s has no runtime power management"), bus, dev);

	if (strcmp(bus, "pci") == 0) {
		char filename[4096];
		uint16_t vendor = 0, device = 0;

		sprintf(filename, "/sys/bus/%s/devices/%s/vendor", bus, dev);

		file.open(filename, ios::in);
		if (file) {
			file >> hex >> vendor;
			file.close();
		}


		sprintf(filename, "/sys/bus/%s/devices/%s/device", bus, dev);
		file.open(filename, ios::in);
		if (file) {
			file >> hex >> device;
			file.close();
		}

		if (vendor && device) {
			if (!device_has_runtime_pm(path))
				sprintf(desc, _("PCI Device %s has no runtime power management"), pci_id_to_name(vendor, device, filename, 4095));
			else
				sprintf(desc, _("Runtime PM for PCI Device %s"), pci_id_to_name(vendor, device, filename, 4095));
		}

		
	}
Exemplo n.º 3
0
static void add_i2c_callback(const char *d_name)
{
	class i2c_tunable *i2c;
	char filename[4096];
	bool is_adapter = false;

	sprintf(filename, "/sys/bus/i2c/devices/%s/new_device", d_name);
	if (access(filename, W_OK) == 0)
		is_adapter = true;

	sprintf(filename, "/sys/bus/i2c/devices/%s", d_name);
	i2c = new class i2c_tunable(filename, d_name, is_adapter);

	if (is_adapter)
		sprintf(filename, "/sys/bus/i2c/devices/%s/device", d_name);
	else
		sprintf(filename, "/sys/bus/i2c/devices/%s", d_name);

	if (device_has_runtime_pm(filename))
		all_tunables.push_back(i2c);
	else
		all_untunables.push_back(i2c);
}