Lines Matching refs:resource

108 static int update_avg_interval(struct acpi_power_meter_resource *resource)  in update_avg_interval()  argument
113 status = acpi_evaluate_integer(resource->acpi_dev->handle, "_GAI", in update_avg_interval()
116 acpi_evaluation_failure_warn(resource->acpi_dev->handle, "_GAI", in update_avg_interval()
121 resource->avg_interval = data; in update_avg_interval()
130 struct acpi_power_meter_resource *resource = acpi_dev->driver_data; in show_avg_interval() local
132 mutex_lock(&resource->lock); in show_avg_interval()
133 update_avg_interval(resource); in show_avg_interval()
134 mutex_unlock(&resource->lock); in show_avg_interval()
136 return sprintf(buf, "%llu\n", resource->avg_interval); in show_avg_interval()
144 struct acpi_power_meter_resource *resource = acpi_dev->driver_data; in set_avg_interval() local
156 if (temp > resource->caps.max_avg_interval || in set_avg_interval()
157 temp < resource->caps.min_avg_interval) in set_avg_interval()
161 mutex_lock(&resource->lock); in set_avg_interval()
162 status = acpi_evaluate_integer(resource->acpi_dev->handle, "_PAI", in set_avg_interval()
165 resource->avg_interval = temp; in set_avg_interval()
166 mutex_unlock(&resource->lock); in set_avg_interval()
169 acpi_evaluation_failure_warn(resource->acpi_dev->handle, "_PAI", in set_avg_interval()
182 static int update_cap(struct acpi_power_meter_resource *resource) in update_cap() argument
187 status = acpi_evaluate_integer(resource->acpi_dev->handle, "_GHL", in update_cap()
190 acpi_evaluation_failure_warn(resource->acpi_dev->handle, "_GHL", in update_cap()
195 resource->cap = data; in update_cap()
204 struct acpi_power_meter_resource *resource = acpi_dev->driver_data; in show_cap() local
206 mutex_lock(&resource->lock); in show_cap()
207 update_cap(resource); in show_cap()
208 mutex_unlock(&resource->lock); in show_cap()
210 return sprintf(buf, "%llu\n", resource->cap * 1000); in show_cap()
217 struct acpi_power_meter_resource *resource = acpi_dev->driver_data; in set_cap() local
230 if (temp > resource->caps.max_cap || temp < resource->caps.min_cap) in set_cap()
234 mutex_lock(&resource->lock); in set_cap()
235 status = acpi_evaluate_integer(resource->acpi_dev->handle, "_SHL", in set_cap()
238 resource->cap = temp; in set_cap()
239 mutex_unlock(&resource->lock); in set_cap()
242 acpi_evaluation_failure_warn(resource->acpi_dev->handle, "_SHL", in set_cap()
255 static int set_acpi_trip(struct acpi_power_meter_resource *resource) in set_acpi_trip() argument
266 if (resource->trip[0] < 0 || resource->trip[1] < 0) in set_acpi_trip()
270 arg_objs[0].integer.value = resource->trip[1]; in set_acpi_trip()
271 arg_objs[1].integer.value = resource->trip[0]; in set_acpi_trip()
273 status = acpi_evaluate_integer(resource->acpi_dev->handle, "_PTP", in set_acpi_trip()
276 acpi_evaluation_failure_warn(resource->acpi_dev->handle, "_PTP", in set_acpi_trip()
293 struct acpi_power_meter_resource *resource = acpi_dev->driver_data; in set_trip() local
303 mutex_lock(&resource->lock); in set_trip()
304 resource->trip[attr->index - 7] = temp; in set_trip()
305 res = set_acpi_trip(resource); in set_trip()
306 mutex_unlock(&resource->lock); in set_trip()
315 static int update_meter(struct acpi_power_meter_resource *resource) in update_meter() argument
321 if (time_before(local_jiffies, resource->sensors_last_updated + in update_meter()
322 msecs_to_jiffies(resource->caps.sampling_time)) && in update_meter()
323 resource->sensors_valid) in update_meter()
326 status = acpi_evaluate_integer(resource->acpi_dev->handle, "_PMM", in update_meter()
329 acpi_evaluation_failure_warn(resource->acpi_dev->handle, "_PMM", in update_meter()
334 resource->power = data; in update_meter()
335 resource->sensors_valid = 1; in update_meter()
336 resource->sensors_last_updated = jiffies; in update_meter()
345 struct acpi_power_meter_resource *resource = acpi_dev->driver_data; in show_power() local
347 mutex_lock(&resource->lock); in show_power()
348 update_meter(resource); in show_power()
349 mutex_unlock(&resource->lock); in show_power()
351 return sprintf(buf, "%llu\n", resource->power * 1000); in show_power()
361 struct acpi_power_meter_resource *resource = acpi_dev->driver_data; in show_str() local
365 mutex_lock(&resource->lock); in show_str()
368 val = resource->model_number; in show_str()
371 val = resource->serial_number; in show_str()
374 val = resource->oem_info; in show_str()
383 mutex_unlock(&resource->lock); in show_str()
393 struct acpi_power_meter_resource *resource = acpi_dev->driver_data; in show_val() local
398 val = resource->caps.min_avg_interval; in show_val()
401 val = resource->caps.max_avg_interval; in show_val()
404 val = resource->caps.min_cap * 1000; in show_val()
407 val = resource->caps.max_cap * 1000; in show_val()
410 if (resource->caps.hysteresis == UNKNOWN_HYSTERESIS) in show_val()
413 val = resource->caps.hysteresis * 1000; in show_val()
416 if (resource->caps.flags & POWER_METER_IS_BATTERY) in show_val()
422 if (resource->power > resource->cap) in show_val()
429 if (resource->trip[attr->index - 7] < 0) in show_val()
432 val = resource->trip[attr->index - 7] * 1000; in show_val()
448 struct acpi_power_meter_resource *resource = acpi_dev->driver_data; in show_accuracy() local
449 unsigned int acc = resource->caps.accuracy; in show_accuracy()
524 static void remove_domain_devices(struct acpi_power_meter_resource *resource) in remove_domain_devices() argument
528 if (!resource->num_domain_devices) in remove_domain_devices()
531 for (i = 0; i < resource->num_domain_devices; i++) { in remove_domain_devices()
532 struct acpi_device *obj = resource->domain_devices[i]; in remove_domain_devices()
536 sysfs_remove_link(resource->holders_dir, in remove_domain_devices()
541 kfree(resource->domain_devices); in remove_domain_devices()
542 kobject_put(resource->holders_dir); in remove_domain_devices()
543 resource->num_domain_devices = 0; in remove_domain_devices()
546 static int read_domain_devices(struct acpi_power_meter_resource *resource) in read_domain_devices() argument
554 status = acpi_evaluate_object(resource->acpi_dev->handle, "_PMD", NULL, in read_domain_devices()
557 acpi_evaluation_failure_warn(resource->acpi_dev->handle, "_PMD", in read_domain_devices()
565 dev_err(&resource->acpi_dev->dev, ACPI_POWER_METER_NAME in read_domain_devices()
574 resource->domain_devices = kcalloc(pss->package.count, in read_domain_devices()
577 if (!resource->domain_devices) { in read_domain_devices()
582 resource->holders_dir = kobject_create_and_add("measures", in read_domain_devices()
583 &resource->acpi_dev->dev.kobj); in read_domain_devices()
584 if (!resource->holders_dir) { in read_domain_devices()
589 resource->num_domain_devices = pss->package.count; in read_domain_devices()
601 resource->domain_devices[i] = obj; in read_domain_devices()
605 res = sysfs_create_link(resource->holders_dir, &obj->dev.kobj, in read_domain_devices()
609 resource->domain_devices[i] = NULL; in read_domain_devices()
617 kfree(resource->domain_devices); in read_domain_devices()
624 static int register_attrs(struct acpi_power_meter_resource *resource, in register_attrs() argument
627 struct device *dev = &resource->acpi_dev->dev; in register_attrs()
629 &resource->sensors[resource->num_sensors]; in register_attrs()
650 resource->num_sensors++; in register_attrs()
658 static void remove_attrs(struct acpi_power_meter_resource *resource) in remove_attrs() argument
662 for (i = 0; i < resource->num_sensors; i++) { in remove_attrs()
663 if (!resource->sensors[i].dev_attr.attr.name) in remove_attrs()
665 device_remove_file(&resource->acpi_dev->dev, in remove_attrs()
666 &resource->sensors[i].dev_attr); in remove_attrs()
669 remove_domain_devices(resource); in remove_attrs()
671 resource->num_sensors = 0; in remove_attrs()
674 static int setup_attrs(struct acpi_power_meter_resource *resource) in setup_attrs() argument
678 res = read_domain_devices(resource); in setup_attrs()
682 if (resource->caps.flags & POWER_METER_CAN_MEASURE) { in setup_attrs()
683 res = register_attrs(resource, meter_attrs); in setup_attrs()
688 if (resource->caps.flags & POWER_METER_CAN_CAP) { in setup_attrs()
690 dev_warn(&resource->acpi_dev->dev, in setup_attrs()
695 if (resource->caps.configurable_cap) in setup_attrs()
696 res = register_attrs(resource, rw_cap_attrs); in setup_attrs()
698 res = register_attrs(resource, ro_cap_attrs); in setup_attrs()
703 res = register_attrs(resource, misc_cap_attrs); in setup_attrs()
709 if (resource->caps.flags & POWER_METER_CAN_TRIP) { in setup_attrs()
710 res = register_attrs(resource, trip_attrs); in setup_attrs()
715 res = register_attrs(resource, misc_attrs); in setup_attrs()
721 remove_attrs(resource); in setup_attrs()
725 static void free_capabilities(struct acpi_power_meter_resource *resource) in free_capabilities() argument
730 str = &resource->model_number; in free_capabilities()
737 static int read_capabilities(struct acpi_power_meter_resource *resource) in read_capabilities() argument
748 status = acpi_evaluate_object(resource->acpi_dev->handle, "_PMC", NULL, in read_capabilities()
751 acpi_evaluation_failure_warn(resource->acpi_dev->handle, "_PMC", in read_capabilities()
760 dev_err(&resource->acpi_dev->dev, ACPI_POWER_METER_NAME in read_capabilities()
768 state.pointer = &resource->caps; in read_capabilities()
772 dev_err(&resource->acpi_dev->dev, ACPI_POWER_METER_NAME in read_capabilities()
779 if (resource->caps.units) { in read_capabilities()
780 dev_err(&resource->acpi_dev->dev, ACPI_POWER_METER_NAME in read_capabilities()
782 resource->caps.units); in read_capabilities()
788 str = &resource->model_number; in read_capabilities()
809 dev_info(&resource->acpi_dev->dev, "Found ACPI power meter.\n"); in read_capabilities()
812 free_capabilities(resource); in read_capabilities()
821 struct acpi_power_meter_resource *resource; in acpi_power_meter_notify() local
827 resource = acpi_driver_data(device); in acpi_power_meter_notify()
831 mutex_lock(&resource->lock); in acpi_power_meter_notify()
832 free_capabilities(resource); in acpi_power_meter_notify()
833 res = read_capabilities(resource); in acpi_power_meter_notify()
834 mutex_unlock(&resource->lock); in acpi_power_meter_notify()
838 remove_attrs(resource); in acpi_power_meter_notify()
839 setup_attrs(resource); in acpi_power_meter_notify()
866 struct acpi_power_meter_resource *resource; in acpi_power_meter_add() local
871 resource = kzalloc(sizeof(struct acpi_power_meter_resource), in acpi_power_meter_add()
873 if (!resource) in acpi_power_meter_add()
876 resource->sensors_valid = 0; in acpi_power_meter_add()
877 resource->acpi_dev = device; in acpi_power_meter_add()
878 mutex_init(&resource->lock); in acpi_power_meter_add()
881 device->driver_data = resource; in acpi_power_meter_add()
883 res = read_capabilities(resource); in acpi_power_meter_add()
887 resource->trip[0] = resource->trip[1] = -1; in acpi_power_meter_add()
889 res = setup_attrs(resource); in acpi_power_meter_add()
893 resource->hwmon_dev = hwmon_device_register(&device->dev); in acpi_power_meter_add()
894 if (IS_ERR(resource->hwmon_dev)) { in acpi_power_meter_add()
895 res = PTR_ERR(resource->hwmon_dev); in acpi_power_meter_add()
903 remove_attrs(resource); in acpi_power_meter_add()
905 free_capabilities(resource); in acpi_power_meter_add()
907 kfree(resource); in acpi_power_meter_add()
914 struct acpi_power_meter_resource *resource; in acpi_power_meter_remove() local
919 resource = acpi_driver_data(device); in acpi_power_meter_remove()
920 hwmon_device_unregister(resource->hwmon_dev); in acpi_power_meter_remove()
922 remove_attrs(resource); in acpi_power_meter_remove()
923 free_capabilities(resource); in acpi_power_meter_remove()
925 kfree(resource); in acpi_power_meter_remove()
933 struct acpi_power_meter_resource *resource; in acpi_power_meter_resume() local
938 resource = acpi_driver_data(to_acpi_device(dev)); in acpi_power_meter_resume()
939 if (!resource) in acpi_power_meter_resume()
942 free_capabilities(resource); in acpi_power_meter_resume()
943 read_capabilities(resource); in acpi_power_meter_resume()