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()
537 sysfs_remove_link(resource->holders_dir, in remove_domain_devices()
542 kfree(resource->domain_devices); in remove_domain_devices()
543 kobject_put(resource->holders_dir); in remove_domain_devices()
544 resource->num_domain_devices = 0; in remove_domain_devices()
547 static int read_domain_devices(struct acpi_power_meter_resource *resource) in read_domain_devices() argument
555 status = acpi_evaluate_object(resource->acpi_dev->handle, "_PMD", NULL, in read_domain_devices()
558 acpi_evaluation_failure_warn(resource->acpi_dev->handle, "_PMD", in read_domain_devices()
566 dev_err(&resource->acpi_dev->dev, ACPI_POWER_METER_NAME in read_domain_devices()
575 resource->domain_devices = kcalloc(pss->package.count, in read_domain_devices()
578 if (!resource->domain_devices) { in read_domain_devices()
583 resource->holders_dir = kobject_create_and_add("measures", in read_domain_devices()
584 &resource->acpi_dev->dev.kobj); in read_domain_devices()
585 if (!resource->holders_dir) { in read_domain_devices()
590 resource->num_domain_devices = pss->package.count; in read_domain_devices()
602 resource->domain_devices[i] = obj; in read_domain_devices()
606 res = sysfs_create_link(resource->holders_dir, &obj->dev.kobj, in read_domain_devices()
610 resource->domain_devices[i] = NULL; in read_domain_devices()
618 kfree(resource->domain_devices); in read_domain_devices()
625 static int register_attrs(struct acpi_power_meter_resource *resource, in register_attrs() argument
628 struct device *dev = &resource->acpi_dev->dev; in register_attrs()
630 &resource->sensors[resource->num_sensors]; in register_attrs()
651 resource->num_sensors++; in register_attrs()
659 static void remove_attrs(struct acpi_power_meter_resource *resource) in remove_attrs() argument
663 for (i = 0; i < resource->num_sensors; i++) { in remove_attrs()
664 if (!resource->sensors[i].dev_attr.attr.name) in remove_attrs()
666 device_remove_file(&resource->acpi_dev->dev, in remove_attrs()
667 &resource->sensors[i].dev_attr); in remove_attrs()
670 remove_domain_devices(resource); in remove_attrs()
672 resource->num_sensors = 0; in remove_attrs()
675 static int setup_attrs(struct acpi_power_meter_resource *resource) in setup_attrs() argument
679 res = read_domain_devices(resource); in setup_attrs()
683 if (resource->caps.flags & POWER_METER_CAN_MEASURE) { in setup_attrs()
684 res = register_attrs(resource, meter_attrs); in setup_attrs()
689 if (resource->caps.flags & POWER_METER_CAN_CAP) { in setup_attrs()
691 dev_warn(&resource->acpi_dev->dev, in setup_attrs()
696 if (resource->caps.configurable_cap) in setup_attrs()
697 res = register_attrs(resource, rw_cap_attrs); in setup_attrs()
699 res = register_attrs(resource, ro_cap_attrs); in setup_attrs()
704 res = register_attrs(resource, misc_cap_attrs); in setup_attrs()
710 if (resource->caps.flags & POWER_METER_CAN_TRIP) { in setup_attrs()
711 res = register_attrs(resource, trip_attrs); in setup_attrs()
716 res = register_attrs(resource, misc_attrs); in setup_attrs()
722 remove_attrs(resource); in setup_attrs()
726 static void free_capabilities(struct acpi_power_meter_resource *resource) in free_capabilities() argument
731 str = &resource->model_number; in free_capabilities()
738 static int read_capabilities(struct acpi_power_meter_resource *resource) in read_capabilities() argument
749 status = acpi_evaluate_object(resource->acpi_dev->handle, "_PMC", NULL, in read_capabilities()
752 acpi_evaluation_failure_warn(resource->acpi_dev->handle, "_PMC", in read_capabilities()
761 dev_err(&resource->acpi_dev->dev, ACPI_POWER_METER_NAME in read_capabilities()
769 state.pointer = &resource->caps; in read_capabilities()
773 dev_err(&resource->acpi_dev->dev, ACPI_POWER_METER_NAME in read_capabilities()
780 if (resource->caps.units) { in read_capabilities()
781 dev_err(&resource->acpi_dev->dev, ACPI_POWER_METER_NAME in read_capabilities()
783 resource->caps.units); in read_capabilities()
789 str = &resource->model_number; in read_capabilities()
810 dev_info(&resource->acpi_dev->dev, "Found ACPI power meter.\n"); in read_capabilities()
813 free_capabilities(resource); in read_capabilities()
822 struct acpi_power_meter_resource *resource; in acpi_power_meter_notify() local
828 resource = acpi_driver_data(device); in acpi_power_meter_notify()
832 mutex_lock(&resource->lock); in acpi_power_meter_notify()
833 free_capabilities(resource); in acpi_power_meter_notify()
834 res = read_capabilities(resource); in acpi_power_meter_notify()
835 mutex_unlock(&resource->lock); in acpi_power_meter_notify()
839 remove_attrs(resource); in acpi_power_meter_notify()
840 setup_attrs(resource); in acpi_power_meter_notify()
867 struct acpi_power_meter_resource *resource; in acpi_power_meter_add() local
872 resource = kzalloc(sizeof(*resource), GFP_KERNEL); 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] = -1; in acpi_power_meter_add()
888 resource->trip[1] = -1; in acpi_power_meter_add()
890 res = setup_attrs(resource); in acpi_power_meter_add()
894 resource->hwmon_dev = hwmon_device_register(&device->dev); in acpi_power_meter_add()
895 if (IS_ERR(resource->hwmon_dev)) { in acpi_power_meter_add()
896 res = PTR_ERR(resource->hwmon_dev); in acpi_power_meter_add()
904 remove_attrs(resource); in acpi_power_meter_add()
906 free_capabilities(resource); in acpi_power_meter_add()
908 kfree(resource); in acpi_power_meter_add()
915 struct acpi_power_meter_resource *resource; in acpi_power_meter_remove() local
920 resource = acpi_driver_data(device); in acpi_power_meter_remove()
921 hwmon_device_unregister(resource->hwmon_dev); in acpi_power_meter_remove()
923 remove_attrs(resource); in acpi_power_meter_remove()
924 free_capabilities(resource); in acpi_power_meter_remove()
926 kfree(resource); in acpi_power_meter_remove()
932 struct acpi_power_meter_resource *resource; in acpi_power_meter_resume() local
937 resource = acpi_driver_data(to_acpi_device(dev)); in acpi_power_meter_resume()
938 if (!resource) in acpi_power_meter_resume()
941 free_capabilities(resource); in acpi_power_meter_resume()
942 read_capabilities(resource); in acpi_power_meter_resume()