Lines Matching refs:resource

130 static int update_avg_interval(struct acpi_power_meter_resource *resource)
135 status = acpi_evaluate_integer(resource->acpi_dev->handle, "_GAI",
142 resource->avg_interval = data;
151 struct acpi_power_meter_resource *resource = acpi_dev->driver_data;
153 mutex_lock(&resource->lock);
154 update_avg_interval(resource);
155 mutex_unlock(&resource->lock);
157 return sprintf(buf, "%llu\n", resource->avg_interval);
165 struct acpi_power_meter_resource *resource = acpi_dev->driver_data;
177 if (temp > resource->caps.max_avg_interval ||
178 temp < resource->caps.min_avg_interval)
182 mutex_lock(&resource->lock);
183 status = acpi_evaluate_integer(resource->acpi_dev->handle, "_PAI",
186 resource->avg_interval = temp;
187 mutex_unlock(&resource->lock);
202 static int update_cap(struct acpi_power_meter_resource *resource)
207 status = acpi_evaluate_integer(resource->acpi_dev->handle, "_GHL",
214 resource->cap = data;
223 struct acpi_power_meter_resource *resource = acpi_dev->driver_data;
225 mutex_lock(&resource->lock);
226 update_cap(resource);
227 mutex_unlock(&resource->lock);
229 return sprintf(buf, "%llu\n", resource->cap * 1000);
236 struct acpi_power_meter_resource *resource = acpi_dev->driver_data;
249 if (temp > resource->caps.max_cap || temp < resource->caps.min_cap)
253 mutex_lock(&resource->lock);
254 status = acpi_evaluate_integer(resource->acpi_dev->handle, "_SHL",
257 resource->cap = temp;
258 mutex_unlock(&resource->lock);
273 static int set_acpi_trip(struct acpi_power_meter_resource *resource)
284 if (resource->trip[0] < 0 || resource->trip[1] < 0)
288 arg_objs[0].integer.value = resource->trip[1];
289 arg_objs[1].integer.value = resource->trip[0];
291 status = acpi_evaluate_integer(resource->acpi_dev->handle, "_PTP",
310 struct acpi_power_meter_resource *resource = acpi_dev->driver_data;
322 mutex_lock(&resource->lock);
323 resource->trip[attr->index - 7] = temp;
324 res = set_acpi_trip(resource);
325 mutex_unlock(&resource->lock);
334 static int update_meter(struct acpi_power_meter_resource *resource)
340 if (time_before(local_jiffies, resource->sensors_last_updated +
341 msecs_to_jiffies(resource->caps.sampling_time)) &&
342 resource->sensors_valid)
345 status = acpi_evaluate_integer(resource->acpi_dev->handle, "_PMM",
352 resource->power = data;
353 resource->sensors_valid = 1;
354 resource->sensors_last_updated = jiffies;
363 struct acpi_power_meter_resource *resource = acpi_dev->driver_data;
365 mutex_lock(&resource->lock);
366 update_meter(resource);
367 mutex_unlock(&resource->lock);
369 return sprintf(buf, "%llu\n", resource->power * 1000);
379 struct acpi_power_meter_resource *resource = acpi_dev->driver_data;
384 val = resource->model_number;
387 val = resource->serial_number;
390 val = resource->oem_info;
406 struct acpi_power_meter_resource *resource = acpi_dev->driver_data;
411 val = resource->caps.min_avg_interval;
414 val = resource->caps.max_avg_interval;
417 val = resource->caps.min_cap * 1000;
420 val = resource->caps.max_cap * 1000;
423 if (resource->caps.hysteresis == UNKNOWN_HYSTERESIS)
426 val = resource->caps.hysteresis * 1000;
429 if (resource->caps.flags & POWER_METER_IS_BATTERY)
435 if (resource->power > resource->cap)
442 if (resource->trip[attr->index - 7] < 0)
445 val = resource->trip[attr->index - 7] * 1000;
459 struct acpi_power_meter_resource *resource = acpi_dev->driver_data;
460 unsigned int acc = resource->caps.accuracy;
520 static void remove_domain_devices(struct acpi_power_meter_resource *resource)
524 if (!resource->num_domain_devices)
527 for (i = 0; i < resource->num_domain_devices; i++) {
528 struct acpi_device *obj = resource->domain_devices[i];
532 sysfs_remove_link(resource->holders_dir,
537 kfree(resource->domain_devices);
538 kobject_put(resource->holders_dir);
539 resource->num_domain_devices = 0;
542 static int read_domain_devices(struct acpi_power_meter_resource *resource)
550 status = acpi_evaluate_object(resource->acpi_dev->handle, "_PMD", NULL,
560 dev_err(&resource->acpi_dev->dev, ACPI_POWER_METER_NAME
569 resource->domain_devices = kzalloc(sizeof(struct acpi_device *) *
571 if (!resource->domain_devices) {
576 resource->holders_dir = kobject_create_and_add("measures",
577 &resource->acpi_dev->dev.kobj);
578 if (!resource->holders_dir) {
583 resource->num_domain_devices = pss->package.count;
594 resource->domain_devices[i] = NULL;
596 &resource->domain_devices[i]);
600 obj = resource->domain_devices[i];
603 res = sysfs_create_link(resource->holders_dir, &obj->dev.kobj,
607 resource->domain_devices[i] = NULL;
615 kfree(resource->domain_devices);
622 static int register_ro_attrs(struct acpi_power_meter_resource *resource,
625 struct device *dev = &resource->acpi_dev->dev;
627 &resource->sensors[resource->num_sensors];
643 resource->num_sensors++;
651 static int register_rw_attrs(struct acpi_power_meter_resource *resource,
654 struct device *dev = &resource->acpi_dev->dev;
656 &resource->sensors[resource->num_sensors];
673 resource->num_sensors++;
681 static void remove_attrs(struct acpi_power_meter_resource *resource)
685 for (i = 0; i < resource->num_sensors; i++) {
686 if (!resource->sensors[i].dev_attr.attr.name)
688 device_remove_file(&resource->acpi_dev->dev,
689 &resource->sensors[i].dev_attr);
692 remove_domain_devices(resource);
694 resource->num_sensors = 0;
697 static int setup_attrs(struct acpi_power_meter_resource *resource)
701 res = read_domain_devices(resource);
705 if (resource->caps.flags & POWER_METER_CAN_MEASURE) {
706 res = register_ro_attrs(resource, meter_ro_attrs);
709 res = register_rw_attrs(resource, meter_rw_attrs);
714 if (resource->caps.flags & POWER_METER_CAN_CAP) {
716 dev_err(&resource->acpi_dev->dev,
721 if (resource->caps.configurable_cap) {
722 res = register_rw_attrs(resource, rw_cap_attrs);
726 res = register_ro_attrs(resource, ro_cap_attrs);
730 res = register_ro_attrs(resource, misc_cap_attrs);
736 if (resource->caps.flags & POWER_METER_CAN_TRIP) {
737 res = register_rw_attrs(resource, trip_attrs);
742 res = register_ro_attrs(resource, misc_attrs);
748 remove_attrs(resource);
752 static void free_capabilities(struct acpi_power_meter_resource *resource)
757 str = &resource->model_number;
762 static int read_capabilities(struct acpi_power_meter_resource *resource)
773 status = acpi_evaluate_object(resource->acpi_dev->handle, "_PMC", NULL,
784 dev_err(&resource->acpi_dev->dev, ACPI_POWER_METER_NAME
792 state.pointer = &resource->caps;
801 if (resource->caps.units) {
802 dev_err(&resource->acpi_dev->dev, ACPI_POWER_METER_NAME
804 resource->caps.units);
810 str = &resource->model_number;
831 dev_info(&resource->acpi_dev->dev, "Found ACPI power meter.\n");
834 str = &resource->model_number;
845 struct acpi_power_meter_resource *resource;
851 resource = acpi_driver_data(device);
853 mutex_lock(&resource->lock);
856 free_capabilities(resource);
857 res = read_capabilities(resource);
861 remove_attrs(resource);
862 setup_attrs(resource);
866 update_meter(resource);
870 update_cap(resource);
874 update_avg_interval(resource);
883 mutex_unlock(&resource->lock);
892 struct acpi_power_meter_resource *resource;
897 resource = kzalloc(sizeof(struct acpi_power_meter_resource),
899 if (!resource)
902 resource->sensors_valid = 0;
903 resource->acpi_dev = device;
904 mutex_init(&resource->lock);
907 device->driver_data = resource;
909 free_capabilities(resource);
910 res = read_capabilities(resource);
914 resource->trip[0] = resource->trip[1] = -1;
916 res = setup_attrs(resource);
920 resource->hwmon_dev = hwmon_device_register(&device->dev);
921 if (IS_ERR(resource->hwmon_dev)) {
922 res = PTR_ERR(resource->hwmon_dev);
930 remove_attrs(resource);
932 kfree(resource);
939 struct acpi_power_meter_resource *resource;
944 resource = acpi_driver_data(device);
945 hwmon_device_unregister(resource->hwmon_dev);
947 free_capabilities(resource);
948 remove_attrs(resource);
950 kfree(resource);
956 struct acpi_power_meter_resource *resource;
961 resource = acpi_driver_data(device);
962 free_capabilities(resource);
963 read_capabilities(resource);