Lines Matching refs:resource

109 static int update_avg_interval(struct acpi_power_meter_resource *resource)  in update_avg_interval()  argument
114 status = acpi_evaluate_integer(resource->acpi_dev->handle, "_GAI", in update_avg_interval()
117 acpi_evaluation_failure_warn(resource->acpi_dev->handle, "_GAI", in update_avg_interval()
122 resource->avg_interval = data; in update_avg_interval()
131 struct acpi_power_meter_resource *resource = acpi_dev->driver_data; in show_avg_interval() local
133 mutex_lock(&resource->lock); in show_avg_interval()
134 update_avg_interval(resource); in show_avg_interval()
135 mutex_unlock(&resource->lock); in show_avg_interval()
137 return sprintf(buf, "%llu\n", resource->avg_interval); in show_avg_interval()
145 struct acpi_power_meter_resource *resource = acpi_dev->driver_data; in set_avg_interval() local
157 if (temp > resource->caps.max_avg_interval || in set_avg_interval()
158 temp < resource->caps.min_avg_interval) in set_avg_interval()
162 mutex_lock(&resource->lock); in set_avg_interval()
163 status = acpi_evaluate_integer(resource->acpi_dev->handle, "_PAI", in set_avg_interval()
166 resource->avg_interval = temp; in set_avg_interval()
167 mutex_unlock(&resource->lock); in set_avg_interval()
170 acpi_evaluation_failure_warn(resource->acpi_dev->handle, "_PAI", in set_avg_interval()
183 static int update_cap(struct acpi_power_meter_resource *resource) in update_cap() argument
188 status = acpi_evaluate_integer(resource->acpi_dev->handle, "_GHL", in update_cap()
191 acpi_evaluation_failure_warn(resource->acpi_dev->handle, "_GHL", in update_cap()
196 resource->cap = data; in update_cap()
205 struct acpi_power_meter_resource *resource = acpi_dev->driver_data; in show_cap() local
207 mutex_lock(&resource->lock); in show_cap()
208 update_cap(resource); in show_cap()
209 mutex_unlock(&resource->lock); in show_cap()
211 return sprintf(buf, "%llu\n", resource->cap * 1000); in show_cap()
218 struct acpi_power_meter_resource *resource = acpi_dev->driver_data; in set_cap() local
231 if (temp > resource->caps.max_cap || temp < resource->caps.min_cap) in set_cap()
235 mutex_lock(&resource->lock); in set_cap()
236 status = acpi_evaluate_integer(resource->acpi_dev->handle, "_SHL", in set_cap()
239 resource->cap = temp; in set_cap()
240 mutex_unlock(&resource->lock); in set_cap()
243 acpi_evaluation_failure_warn(resource->acpi_dev->handle, "_SHL", in set_cap()
256 static int set_acpi_trip(struct acpi_power_meter_resource *resource) in set_acpi_trip() argument
267 if (resource->trip[0] < 0 || resource->trip[1] < 0) in set_acpi_trip()
271 arg_objs[0].integer.value = resource->trip[1]; in set_acpi_trip()
272 arg_objs[1].integer.value = resource->trip[0]; in set_acpi_trip()
274 status = acpi_evaluate_integer(resource->acpi_dev->handle, "_PTP", in set_acpi_trip()
277 acpi_evaluation_failure_warn(resource->acpi_dev->handle, "_PTP", in set_acpi_trip()
294 struct acpi_power_meter_resource *resource = acpi_dev->driver_data; in set_trip() local
304 mutex_lock(&resource->lock); in set_trip()
305 resource->trip[attr->index - 7] = temp; in set_trip()
306 res = set_acpi_trip(resource); in set_trip()
307 mutex_unlock(&resource->lock); in set_trip()
316 static int update_meter(struct acpi_power_meter_resource *resource) in update_meter() argument
322 if (time_before(local_jiffies, resource->sensors_last_updated + in update_meter()
323 msecs_to_jiffies(resource->caps.sampling_time)) && in update_meter()
324 resource->sensors_valid) in update_meter()
327 status = acpi_evaluate_integer(resource->acpi_dev->handle, "_PMM", in update_meter()
330 acpi_evaluation_failure_warn(resource->acpi_dev->handle, "_PMM", in update_meter()
335 resource->power = data; in update_meter()
336 resource->sensors_valid = 1; in update_meter()
337 resource->sensors_last_updated = jiffies; in update_meter()
346 struct acpi_power_meter_resource *resource = acpi_dev->driver_data; in show_power() local
348 mutex_lock(&resource->lock); in show_power()
349 update_meter(resource); in show_power()
350 mutex_unlock(&resource->lock); in show_power()
352 if (resource->power == UNKNOWN_POWER) in show_power()
355 return sprintf(buf, "%llu\n", resource->power * 1000); in show_power()
365 struct acpi_power_meter_resource *resource = acpi_dev->driver_data; in show_str() local
369 mutex_lock(&resource->lock); in show_str()
372 val = resource->model_number; in show_str()
375 val = resource->serial_number; in show_str()
378 val = resource->oem_info; in show_str()
387 mutex_unlock(&resource->lock); in show_str()
397 struct acpi_power_meter_resource *resource = acpi_dev->driver_data; in show_val() local
402 val = resource->caps.min_avg_interval; in show_val()
405 val = resource->caps.max_avg_interval; in show_val()
408 val = resource->caps.min_cap * 1000; in show_val()
411 val = resource->caps.max_cap * 1000; in show_val()
414 if (resource->caps.hysteresis == UNKNOWN_HYSTERESIS) in show_val()
417 val = resource->caps.hysteresis * 1000; in show_val()
420 if (resource->caps.flags & POWER_METER_IS_BATTERY) in show_val()
426 if (resource->power > resource->cap) in show_val()
433 if (resource->trip[attr->index - 7] < 0) in show_val()
436 val = resource->trip[attr->index - 7] * 1000; in show_val()
452 struct acpi_power_meter_resource *resource = acpi_dev->driver_data; in show_accuracy() local
453 unsigned int acc = resource->caps.accuracy; in show_accuracy()
528 static void remove_domain_devices(struct acpi_power_meter_resource *resource) in remove_domain_devices() argument
532 if (!resource->num_domain_devices) in remove_domain_devices()
535 for (i = 0; i < resource->num_domain_devices; i++) { in remove_domain_devices()
536 struct acpi_device *obj = resource->domain_devices[i]; in remove_domain_devices()
541 sysfs_remove_link(resource->holders_dir, in remove_domain_devices()
546 kfree(resource->domain_devices); in remove_domain_devices()
547 kobject_put(resource->holders_dir); in remove_domain_devices()
548 resource->num_domain_devices = 0; in remove_domain_devices()
551 static int read_domain_devices(struct acpi_power_meter_resource *resource) in read_domain_devices() argument
559 status = acpi_evaluate_object(resource->acpi_dev->handle, "_PMD", NULL, in read_domain_devices()
562 acpi_evaluation_failure_warn(resource->acpi_dev->handle, "_PMD", in read_domain_devices()
570 dev_err(&resource->acpi_dev->dev, ACPI_POWER_METER_NAME in read_domain_devices()
579 resource->domain_devices = kcalloc(pss->package.count, in read_domain_devices()
582 if (!resource->domain_devices) { in read_domain_devices()
587 resource->holders_dir = kobject_create_and_add("measures", in read_domain_devices()
588 &resource->acpi_dev->dev.kobj); in read_domain_devices()
589 if (!resource->holders_dir) { in read_domain_devices()
594 resource->num_domain_devices = pss->package.count; in read_domain_devices()
606 resource->domain_devices[i] = obj; in read_domain_devices()
610 res = sysfs_create_link(resource->holders_dir, &obj->dev.kobj, in read_domain_devices()
614 resource->domain_devices[i] = NULL; in read_domain_devices()
622 kfree(resource->domain_devices); in read_domain_devices()
629 static int register_attrs(struct acpi_power_meter_resource *resource, in register_attrs() argument
632 struct device *dev = &resource->acpi_dev->dev; in register_attrs()
634 &resource->sensors[resource->num_sensors]; in register_attrs()
655 resource->num_sensors++; in register_attrs()
663 static void remove_attrs(struct acpi_power_meter_resource *resource) in remove_attrs() argument
667 for (i = 0; i < resource->num_sensors; i++) { in remove_attrs()
668 if (!resource->sensors[i].dev_attr.attr.name) in remove_attrs()
670 device_remove_file(&resource->acpi_dev->dev, in remove_attrs()
671 &resource->sensors[i].dev_attr); in remove_attrs()
674 remove_domain_devices(resource); in remove_attrs()
676 resource->num_sensors = 0; in remove_attrs()
679 static int setup_attrs(struct acpi_power_meter_resource *resource) in setup_attrs() argument
683 res = read_domain_devices(resource); in setup_attrs()
687 if (resource->caps.flags & POWER_METER_CAN_MEASURE) { in setup_attrs()
688 res = register_attrs(resource, meter_attrs); in setup_attrs()
693 if (resource->caps.flags & POWER_METER_CAN_CAP) { in setup_attrs()
695 dev_warn(&resource->acpi_dev->dev, in setup_attrs()
700 if (resource->caps.configurable_cap) in setup_attrs()
701 res = register_attrs(resource, rw_cap_attrs); in setup_attrs()
703 res = register_attrs(resource, ro_cap_attrs); in setup_attrs()
708 res = register_attrs(resource, misc_cap_attrs); in setup_attrs()
714 if (resource->caps.flags & POWER_METER_CAN_TRIP) { in setup_attrs()
715 res = register_attrs(resource, trip_attrs); in setup_attrs()
720 res = register_attrs(resource, misc_attrs); in setup_attrs()
726 remove_attrs(resource); in setup_attrs()
730 static void free_capabilities(struct acpi_power_meter_resource *resource) in free_capabilities() argument
735 str = &resource->model_number; in free_capabilities()
742 static int read_capabilities(struct acpi_power_meter_resource *resource) in read_capabilities() argument
753 status = acpi_evaluate_object(resource->acpi_dev->handle, "_PMC", NULL, in read_capabilities()
756 acpi_evaluation_failure_warn(resource->acpi_dev->handle, "_PMC", in read_capabilities()
765 dev_err(&resource->acpi_dev->dev, ACPI_POWER_METER_NAME in read_capabilities()
773 state.pointer = &resource->caps; in read_capabilities()
777 dev_err(&resource->acpi_dev->dev, ACPI_POWER_METER_NAME in read_capabilities()
784 if (resource->caps.units) { in read_capabilities()
785 dev_err(&resource->acpi_dev->dev, ACPI_POWER_METER_NAME in read_capabilities()
787 resource->caps.units); in read_capabilities()
793 str = &resource->model_number; in read_capabilities()
813 dev_info(&resource->acpi_dev->dev, "Found ACPI power meter.\n"); in read_capabilities()
816 free_capabilities(resource); in read_capabilities()
825 struct acpi_power_meter_resource *resource; in acpi_power_meter_notify() local
831 resource = acpi_driver_data(device); in acpi_power_meter_notify()
835 mutex_lock(&resource->lock); in acpi_power_meter_notify()
836 free_capabilities(resource); in acpi_power_meter_notify()
837 res = read_capabilities(resource); in acpi_power_meter_notify()
838 mutex_unlock(&resource->lock); in acpi_power_meter_notify()
842 remove_attrs(resource); in acpi_power_meter_notify()
843 setup_attrs(resource); in acpi_power_meter_notify()
870 struct acpi_power_meter_resource *resource; in acpi_power_meter_add() local
875 resource = kzalloc(sizeof(*resource), GFP_KERNEL); in acpi_power_meter_add()
876 if (!resource) in acpi_power_meter_add()
879 resource->sensors_valid = 0; in acpi_power_meter_add()
880 resource->acpi_dev = device; in acpi_power_meter_add()
881 mutex_init(&resource->lock); in acpi_power_meter_add()
884 device->driver_data = resource; in acpi_power_meter_add()
902 res = read_capabilities(resource); in acpi_power_meter_add()
906 resource->trip[0] = -1; in acpi_power_meter_add()
907 resource->trip[1] = -1; in acpi_power_meter_add()
909 res = setup_attrs(resource); in acpi_power_meter_add()
913 resource->hwmon_dev = hwmon_device_register(&device->dev); in acpi_power_meter_add()
914 if (IS_ERR(resource->hwmon_dev)) { in acpi_power_meter_add()
915 res = PTR_ERR(resource->hwmon_dev); in acpi_power_meter_add()
923 remove_attrs(resource); in acpi_power_meter_add()
925 free_capabilities(resource); in acpi_power_meter_add()
927 kfree(resource); in acpi_power_meter_add()
934 struct acpi_power_meter_resource *resource; in acpi_power_meter_remove() local
939 resource = acpi_driver_data(device); in acpi_power_meter_remove()
940 hwmon_device_unregister(resource->hwmon_dev); in acpi_power_meter_remove()
942 remove_attrs(resource); in acpi_power_meter_remove()
943 free_capabilities(resource); in acpi_power_meter_remove()
945 kfree(resource); in acpi_power_meter_remove()
950 struct acpi_power_meter_resource *resource; in acpi_power_meter_resume() local
955 resource = acpi_driver_data(to_acpi_device(dev)); in acpi_power_meter_resume()
956 if (!resource) in acpi_power_meter_resume()
959 free_capabilities(resource); in acpi_power_meter_resume()
960 read_capabilities(resource); in acpi_power_meter_resume()