static int xgene_enet_reset(struct xgene_enet_pdata *pdata) { struct device *dev = &pdata->pdev->dev; if (!xgene_ring_mgr_init(pdata)) return -ENODEV; if (dev->of_node) { clk_prepare_enable(pdata->clk); udelay(5); clk_disable_unprepare(pdata->clk); udelay(5); clk_prepare_enable(pdata->clk); udelay(5); } else { #ifdef CONFIG_ACPI if (acpi_has_method(ACPI_HANDLE(&pdata->pdev->dev), "_RST")) { acpi_evaluate_object(ACPI_HANDLE(&pdata->pdev->dev), "_RST", NULL, NULL); } else if (acpi_has_method(ACPI_HANDLE(&pdata->pdev->dev), "_INI")) { acpi_evaluate_object(ACPI_HANDLE(&pdata->pdev->dev), "_INI", NULL, NULL); } #endif } xgene_enet_ecc_init(pdata); xgene_enet_config_ring_if_assoc(pdata); return 0; }
static int acpi_processor_get_lpi_info(struct acpi_processor *pr) { int ret, i; acpi_status status; acpi_handle handle = pr->handle, pr_ahandle; struct acpi_device *d = NULL; struct acpi_lpi_states_array info[2], *tmp, *prev, *curr; if (!osc_pc_lpi_support_confirmed) return -EOPNOTSUPP; if (!acpi_has_method(handle, "_LPI")) return -EINVAL; flat_state_cnt = 0; prev = &info[0]; curr = &info[1]; handle = pr->handle; ret = acpi_processor_evaluate_lpi(handle, prev); if (ret) return ret; flatten_lpi_states(pr, prev, NULL); status = acpi_get_parent(handle, &pr_ahandle); while (ACPI_SUCCESS(status)) { acpi_bus_get_device(pr_ahandle, &d); handle = pr_ahandle; if (strcmp(acpi_device_hid(d), ACPI_PROCESSOR_CONTAINER_HID)) break; /* can be optional ? */ if (!acpi_has_method(handle, "_LPI")) break; ret = acpi_processor_evaluate_lpi(handle, curr); if (ret) break; /* flatten all the LPI states in this level of hierarchy */ flatten_lpi_states(pr, curr, prev); tmp = prev, prev = curr, curr = tmp; status = acpi_get_parent(handle, &pr_ahandle); } pr->power.count = flat_state_cnt; /* reset the index after flattening */ for (i = 0; i < pr->power.count; i++) pr->power.lpi_states[i].index = i; /* Tell driver that _LPI is supported. */ pr->flags.has_lpi = 1; pr->flags.power = 1; return 0; }
static const char *find_hci_method(acpi_handle handle) { if (acpi_has_method(handle, "GHCI")) return "GHCI"; if (acpi_has_method(handle, "SPFC")) return "SPFC"; return NULL; }
static int pcihp_is_ejectable(acpi_handle handle) { acpi_status status; unsigned long long removable; if (!acpi_has_method(handle, "_ADR")) return 0; if (acpi_has_method(handle, "_EJ0")) return 1; status = acpi_evaluate_integer(handle, "_RMV", NULL, &removable); if (ACPI_SUCCESS(status) && removable) return 1; return 0; }
/** * acpi_dev_get_resources - Get current resources of a device. * @adev: ACPI device node to get the resources for. * @list: Head of the resultant list of resources (must be empty). * @preproc: The caller's preprocessing routine. * @preproc_data: Pointer passed to the caller's preprocessing routine. * * Evaluate the _CRS method for the given device node and process its output by * (1) executing the @preproc() rountine provided by the caller, passing the * resource pointer and @preproc_data to it as arguments, for each ACPI resource * returned and (2) converting all of the returned ACPI resources into struct * resource objects if possible. If the return value of @preproc() in step (1) * is different from 0, step (2) is not applied to the given ACPI resource and * if that value is negative, the whole processing is aborted and that value is * returned as the final error code. * * The resultant struct resource objects are put on the list pointed to by * @list, that must be empty initially, as members of struct resource_entry * objects. Callers of this routine should use %acpi_dev_free_resource_list() to * free that list. * * The number of resources in the output list is returned on success, an error * code reflecting the error condition is returned otherwise. */ int acpi_dev_get_resources(struct acpi_device *adev, struct list_head *list, int (*preproc)(struct acpi_resource *, void *), void *preproc_data) { struct res_proc_context c; acpi_status status; if (!adev || !adev->handle || !list_empty(list)) return -EINVAL; if (!acpi_has_method(adev->handle, METHOD_NAME__CRS)) return 0; c.list = list; c.preproc = preproc; c.preproc_data = preproc_data; c.count = 0; c.error = 0; status = acpi_walk_resources(adev->handle, METHOD_NAME__CRS, acpi_dev_process_resource, &c); if (ACPI_FAILURE(status)) { acpi_dev_free_resource_list(list); return c.error ? c.error : -EIO; } return c.count; }
int sys_set_trip_temp(struct thermal_zone_device *tzone, int trip, unsigned long temp) { struct int3403_priv *priv = tzone->devdata; struct acpi_device *device = priv->adev; struct int3403_sensor *obj = priv->priv; acpi_status status; char name[10]; int ret = 0; snprintf(name, sizeof(name), "PAT%d", trip); if (acpi_has_method(device->handle, name)) { status = acpi_execute_simple_method(device->handle, name, MILLI_CELSIUS_TO_DECI_KELVIN(temp, KELVIN_OFFSET)); if (ACPI_FAILURE(status)) ret = -EIO; else obj->thresholds[trip] = temp; } else { ret = -EIO; dev_err(&device->dev, "sys_set_trip_temp: method not found\n"); } return ret; }
static acpi_status acpi_backlight_cap_match(acpi_handle handle, u32 level, void *context, void **retyurn_value) { long *cap = context; if (acpi_has_method(handle, "_BCM") && acpi_has_method(handle, "_BCL")) { ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found generic backlight " "support\n")); *cap |= ACPI_VIDEO_BACKLIGHT; if (!acpi_has_method(handle, "_BQC")) printk(KERN_WARNING FW_BUG PREFIX "No _BQC method, " "cannot determine initial brightness\n"); /* We have backlight support, no need to scan further */ return AE_CTRL_TERMINATE; } return 0; }
/* Returns true if the ACPI object is a video device which can be * handled by video.ko. * The device will get a Linux specific CID added in scan.c to * identify the device as an ACPI graphics device * Be aware that the graphics device may not be physically present * Use acpi_video_get_capabilities() to detect general ACPI video * capabilities of present cards */ long acpi_is_video_device(acpi_handle handle) { long video_caps = 0; /* Is this device able to support video switching ? */ if (acpi_has_method(handle, "_DOD") || acpi_has_method(handle, "_DOS")) video_caps |= ACPI_VIDEO_OUTPUT_SWITCHING; /* Is this device able to retrieve a video ROM ? */ if (acpi_has_method(handle, "_ROM")) video_caps |= ACPI_VIDEO_ROM_AVAILABLE; /* Is this device able to configure which video head to be POSTed ? */ if (acpi_has_method(handle, "_VPO") && acpi_has_method(handle, "_GPD") && acpi_has_method(handle, "_SPD")) video_caps |= ACPI_VIDEO_DEVICE_POSTING; /* Only check for backlight functionality if one of the above hit. */ if (video_caps) acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, ACPI_UINT32_MAX, acpi_backlight_cap_match, NULL, &video_caps, NULL); return video_caps; }
static int acpi_thermal_set_cooling_mode(struct acpi_thermal *tz, int mode) { if (!tz) return -EINVAL; if (!acpi_has_method(tz->device->handle, "_SCP")) { ACPI_DEBUG_PRINT((ACPI_DB_INFO, "_SCP not present\n")); return -ENODEV; } else if (ACPI_FAILURE(acpi_execute_simple_method(tz->device->handle, "_SCP", mode))) { return -ENODEV; } return 0; }
static int acpi_thermal_trips_update(struct acpi_thermal *tz, int flag) { acpi_status status = AE_OK; unsigned long long tmp; struct acpi_handle_list devices; int valid = 0; int i; /* Critical Shutdown */ if (flag & ACPI_TRIPS_CRITICAL) { status = acpi_evaluate_integer(tz->device->handle, "_CRT", NULL, &tmp); tz->trips.critical.temperature = tmp; /* * Treat freezing temperatures as invalid as well; some * BIOSes return really low values and cause reboots at startup. * Below zero (Celsius) values clearly aren't right for sure.. * ... so lets discard those as invalid. */ if (ACPI_FAILURE(status)) { tz->trips.critical.flags.valid = 0; ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No critical threshold\n")); } else if (tmp <= 2732) { pr_warn(FW_BUG "Invalid critical threshold (%llu)\n", tmp); tz->trips.critical.flags.valid = 0; } else { tz->trips.critical.flags.valid = 1; ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found critical threshold [%lu]\n", tz->trips.critical.temperature)); } if (tz->trips.critical.flags.valid == 1) { if (crt == -1) { tz->trips.critical.flags.valid = 0; } else if (crt > 0) { unsigned long crt_k = CELSIUS_TO_DECI_KELVIN(crt); /* * Allow override critical threshold */ if (crt_k > tz->trips.critical.temperature) pr_warn(PREFIX "Critical threshold %d C\n", crt); tz->trips.critical.temperature = crt_k; } } } /* Critical Sleep (optional) */ if (flag & ACPI_TRIPS_HOT) { status = acpi_evaluate_integer(tz->device->handle, "_HOT", NULL, &tmp); if (ACPI_FAILURE(status)) { tz->trips.hot.flags.valid = 0; ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No hot threshold\n")); } else { tz->trips.hot.temperature = tmp; tz->trips.hot.flags.valid = 1; ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found hot threshold [%lu]\n", tz->trips.hot.temperature)); } } /* Passive (optional) */ if (((flag & ACPI_TRIPS_PASSIVE) && tz->trips.passive.flags.valid) || (flag == ACPI_TRIPS_INIT)) { valid = tz->trips.passive.flags.valid; if (psv == -1) { status = AE_SUPPORT; } else if (psv > 0) { tmp = CELSIUS_TO_DECI_KELVIN(psv); status = AE_OK; } else { status = acpi_evaluate_integer(tz->device->handle, "_PSV", NULL, &tmp); } if (ACPI_FAILURE(status)) tz->trips.passive.flags.valid = 0; else { tz->trips.passive.temperature = tmp; tz->trips.passive.flags.valid = 1; if (flag == ACPI_TRIPS_INIT) { status = acpi_evaluate_integer( tz->device->handle, "_TC1", NULL, &tmp); if (ACPI_FAILURE(status)) tz->trips.passive.flags.valid = 0; else tz->trips.passive.tc1 = tmp; status = acpi_evaluate_integer( tz->device->handle, "_TC2", NULL, &tmp); if (ACPI_FAILURE(status)) tz->trips.passive.flags.valid = 0; else tz->trips.passive.tc2 = tmp; status = acpi_evaluate_integer( tz->device->handle, "_TSP", NULL, &tmp); if (ACPI_FAILURE(status)) tz->trips.passive.flags.valid = 0; else tz->trips.passive.tsp = tmp; } } } if ((flag & ACPI_TRIPS_DEVICES) && tz->trips.passive.flags.valid) { memset(&devices, 0, sizeof(struct acpi_handle_list)); status = acpi_evaluate_reference(tz->device->handle, "_PSL", NULL, &devices); if (ACPI_FAILURE(status)) { pr_warn(PREFIX "Invalid passive threshold\n"); tz->trips.passive.flags.valid = 0; } else tz->trips.passive.flags.valid = 1; if (memcmp(&tz->trips.passive.devices, &devices, sizeof(struct acpi_handle_list))) { memcpy(&tz->trips.passive.devices, &devices, sizeof(struct acpi_handle_list)); ACPI_THERMAL_TRIPS_EXCEPTION(flag, "device"); } } if ((flag & ACPI_TRIPS_PASSIVE) || (flag & ACPI_TRIPS_DEVICES)) { if (valid != tz->trips.passive.flags.valid) ACPI_THERMAL_TRIPS_EXCEPTION(flag, "state"); } /* Active (optional) */ for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { char name[5] = { '_', 'A', 'C', ('0' + i), '\0' }; valid = tz->trips.active[i].flags.valid; if (act == -1) break; /* disable all active trip points */ if ((flag == ACPI_TRIPS_INIT) || ((flag & ACPI_TRIPS_ACTIVE) && tz->trips.active[i].flags.valid)) { status = acpi_evaluate_integer(tz->device->handle, name, NULL, &tmp); if (ACPI_FAILURE(status)) { tz->trips.active[i].flags.valid = 0; if (i == 0) break; if (act <= 0) break; if (i == 1) tz->trips.active[0].temperature = CELSIUS_TO_DECI_KELVIN(act); else /* * Don't allow override higher than * the next higher trip point */ tz->trips.active[i - 1].temperature = (tz->trips.active[i - 2].temperature < CELSIUS_TO_DECI_KELVIN(act) ? tz->trips.active[i - 2].temperature : CELSIUS_TO_DECI_KELVIN(act)); break; } else { tz->trips.active[i].temperature = tmp; tz->trips.active[i].flags.valid = 1; } } name[2] = 'L'; if ((flag & ACPI_TRIPS_DEVICES) && tz->trips.active[i].flags.valid ) { memset(&devices, 0, sizeof(struct acpi_handle_list)); status = acpi_evaluate_reference(tz->device->handle, name, NULL, &devices); if (ACPI_FAILURE(status)) { pr_warn(PREFIX "Invalid active%d threshold\n", i); tz->trips.active[i].flags.valid = 0; } else tz->trips.active[i].flags.valid = 1; if (memcmp(&tz->trips.active[i].devices, &devices, sizeof(struct acpi_handle_list))) { memcpy(&tz->trips.active[i].devices, &devices, sizeof(struct acpi_handle_list)); ACPI_THERMAL_TRIPS_EXCEPTION(flag, "device"); } } if ((flag & ACPI_TRIPS_ACTIVE) || (flag & ACPI_TRIPS_DEVICES)) if (valid != tz->trips.active[i].flags.valid) ACPI_THERMAL_TRIPS_EXCEPTION(flag, "state"); if (!tz->trips.active[i].flags.valid) break; } if ((flag & ACPI_TRIPS_DEVICES) && acpi_has_method(tz->device->handle, "_TZD")) { memset(&devices, 0, sizeof(devices)); status = acpi_evaluate_reference(tz->device->handle, "_TZD", NULL, &devices); if (ACPI_SUCCESS(status) && memcmp(&tz->devices, &devices, sizeof(devices))) { tz->devices = devices; ACPI_THERMAL_TRIPS_EXCEPTION(flag, "device"); } } return 0; }
/** * acpi_parse_trt - Thermal Relationship Table _TRT for passive cooling * * @handle: ACPI handle of the device contains _TRT * @trt_count: the number of valid entries resulted from parsing _TRT * @trtp: pointer to pointer of array of _TRT entries in parsing result * @create_dev: whether to create platform devices for target and source * */ int acpi_parse_trt(acpi_handle handle, int *trt_count, struct trt **trtp, bool create_dev) { acpi_status status; int result = 0; int i; int nr_bad_entries = 0; struct trt *trts; struct acpi_device *adev; union acpi_object *p; struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; struct acpi_buffer element = { 0, NULL }; struct acpi_buffer trt_format = { sizeof("RRNNNNNN"), "RRNNNNNN" }; if (!acpi_has_method(handle, "_TRT")) return -ENODEV; status = acpi_evaluate_object(handle, "_TRT", NULL, &buffer); if (ACPI_FAILURE(status)) return -ENODEV; p = buffer.pointer; if (!p || (p->type != ACPI_TYPE_PACKAGE)) { pr_err("Invalid _TRT data\n"); result = -EFAULT; goto end; } *trt_count = p->package.count; trts = kcalloc(*trt_count, sizeof(struct trt), GFP_KERNEL); if (!trts) { result = -ENOMEM; goto end; } for (i = 0; i < *trt_count; i++) { struct trt *trt = &trts[i - nr_bad_entries]; element.length = sizeof(struct trt); element.pointer = trt; status = acpi_extract_package(&(p->package.elements[i]), &trt_format, &element); if (ACPI_FAILURE(status)) { nr_bad_entries++; pr_warn("_TRT package %d is invalid, ignored\n", i); continue; } if (!create_dev) continue; result = acpi_bus_get_device(trt->source, &adev); if (result) pr_warn("Failed to get source ACPI device\n"); result = acpi_bus_get_device(trt->target, &adev); if (result) pr_warn("Failed to get target ACPI device\n"); } result = 0; *trtp = trts; /* don't count bad entries */ *trt_count -= nr_bad_entries; end: kfree(buffer.pointer); return result; }
/** * acpi_parse_art - Parse Active Relationship Table _ART * * @handle: ACPI handle of the device contains _ART * @art_count: the number of valid entries resulted from parsing _ART * @artp: pointer to pointer of array of art entries in parsing result * @create_dev: whether to create platform devices for target and source * */ int acpi_parse_art(acpi_handle handle, int *art_count, struct art **artp, bool create_dev) { acpi_status status; int result = 0; int i; int nr_bad_entries = 0; struct art *arts; struct acpi_device *adev; union acpi_object *p; struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; struct acpi_buffer element = { 0, NULL }; struct acpi_buffer art_format = { sizeof("RRNNNNNNNNNNN"), "RRNNNNNNNNNNN" }; if (!acpi_has_method(handle, "_ART")) return 0; status = acpi_evaluate_object(handle, "_ART", NULL, &buffer); if (ACPI_FAILURE(status)) return -ENODEV; p = buffer.pointer; if (!p || (p->type != ACPI_TYPE_PACKAGE)) { pr_err("Invalid _ART data\n"); result = -EFAULT; goto end; } /* ignore p->package.elements[0], as this is _ART Revision field */ *art_count = p->package.count - 1; arts = kzalloc(*art_count * sizeof(struct art), GFP_KERNEL); if (!arts) { result = -ENOMEM; goto end; } for (i = 0; i < *art_count; i++) { struct art *art = &arts[i - nr_bad_entries]; element.length = sizeof(struct art); element.pointer = art; status = acpi_extract_package(&(p->package.elements[i + 1]), &art_format, &element); if (ACPI_FAILURE(status)) { pr_warn("_ART package %d is invalid, ignored", i); nr_bad_entries++; continue; } if (!create_dev) continue; if (art->source) { result = acpi_bus_get_device(art->source, &adev); if (!result) acpi_create_platform_device(adev); else pr_warn("Failed to get source ACPI device\n"); } if (art->target) { result = acpi_bus_get_device(art->target, &adev); if (!result) acpi_create_platform_device(adev); else pr_warn("Failed to get source ACPI device\n"); } } *artp = arts; /* don't count bad entries */ *art_count -= nr_bad_entries; end: kfree(buffer.pointer); return result; }
static int toshiba_acpi_setup_keyboard(struct toshiba_acpi_dev *dev) { acpi_status status; acpi_handle ec_handle; int error; u32 hci_result; dev->hotkey_dev = input_allocate_device(); if (!dev->hotkey_dev) return -ENOMEM; dev->hotkey_dev->name = "Toshiba input device"; dev->hotkey_dev->phys = "toshiba_acpi/input0"; dev->hotkey_dev->id.bustype = BUS_HOST; error = sparse_keymap_setup(dev->hotkey_dev, toshiba_acpi_keymap, NULL); if (error) goto err_free_dev; /* * For some machines the SCI responsible for providing hotkey * notification doesn't fire. We can trigger the notification * whenever the Fn key is pressed using the NTFY method, if * supported, so if it's present set up an i8042 key filter * for this purpose. */ status = AE_ERROR; ec_handle = ec_get_handle(); if (ec_handle && acpi_has_method(ec_handle, "NTFY")) { INIT_WORK(&dev->hotkey_work, toshiba_acpi_hotkey_work); error = i8042_install_filter(toshiba_acpi_i8042_filter); if (error) { pr_err("Error installing key filter\n"); goto err_free_keymap; } dev->ntfy_supported = 1; } /* * Determine hotkey query interface. Prefer using the INFO * method when it is available. */ if (acpi_has_method(dev->acpi_dev->handle, "INFO")) dev->info_supported = 1; else { hci_write1(dev, HCI_SYSTEM_EVENT, 1, &hci_result); if (hci_result == HCI_SUCCESS) dev->system_event_supported = 1; } if (!dev->info_supported && !dev->system_event_supported) { pr_warn("No hotkey query interface found\n"); goto err_remove_filter; } status = acpi_evaluate_object(dev->acpi_dev->handle, "ENAB", NULL, NULL); if (ACPI_FAILURE(status)) { pr_info("Unable to enable hotkeys\n"); error = -ENODEV; goto err_remove_filter; } error = input_register_device(dev->hotkey_dev); if (error) { pr_info("Unable to register input device\n"); goto err_remove_filter; } hci_write1(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_ENABLE, &hci_result); return 0; err_remove_filter: if (dev->ntfy_supported) i8042_remove_filter(toshiba_acpi_i8042_filter); err_free_keymap: sparse_keymap_free(dev->hotkey_dev); err_free_dev: input_free_device(dev->hotkey_dev); dev->hotkey_dev = NULL; return error; }