From patchwork Wed Jun 26 16:30:57 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiang Liu X-Patchwork-Id: 2787241 Return-Path: X-Original-To: patchwork-linux-acpi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 0AEAFC0AB1 for ; Wed, 26 Jun 2013 16:36:17 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id AD840205AF for ; Wed, 26 Jun 2013 16:36:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7FF69205AA for ; Wed, 26 Jun 2013 16:36:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752685Ab3FZQf6 (ORCPT ); Wed, 26 Jun 2013 12:35:58 -0400 Received: from mail-pa0-f42.google.com ([209.85.220.42]:40557 "EHLO mail-pa0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751924Ab3FZQd5 (ORCPT ); Wed, 26 Jun 2013 12:33:57 -0400 Received: by mail-pa0-f42.google.com with SMTP id rl6so14453149pac.1 for ; Wed, 26 Jun 2013 09:33:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=6pOls4vCCRKyG6Cz16LoR+zQdrec0aMpY/YbWYBiJzQ=; b=R4b2u7LiPNYRR6zsNv4PKUlys3WDQPoJngUytsnvngZCJ/2Pzl8D1e4qbkX9+T6BvS GxBvGUYG8PKMI4illKqGkLnUW6Dw4zkouPi9UJISR3GEUFF/07bIestko/3Z7BQzqMwF +64d5HPAytlsy6uz+xE2N3reTb4CBSSJm3+KQOkFSm1khHy5SqVeq0J3vbgaYpcCe7uK BiZjfbifL6UD2bfoiCpP0xSb/DRByNqM7CpPGVrOmB6txLZpyj/eVG2WdT2E4nQ43H+5 gqhsPAe4IyA1d0RMvubnP2ABmEURi/diLFB60YW/6Yvc0ZYI8pLlGMby2sOeCLpm5H80 CAIg== X-Received: by 10.66.122.5 with SMTP id lo5mr1532821pab.175.1372264437283; Wed, 26 Jun 2013 09:33:57 -0700 (PDT) Received: from localhost.localdomain ([114.250.101.234]) by mx.google.com with ESMTPSA id ib9sm28981911pbc.43.2013.06.26.09.33.53 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 26 Jun 2013 09:33:56 -0700 (PDT) From: Jiang Liu To: "Rafael J . Wysocki" Cc: liuj97@gmail.com, Jiang Liu , Yijing Wang , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, Len Brown Subject: [PATCH v2 5/9] ACPI: introduce three helper functions Date: Thu, 27 Jun 2013 00:30:57 +0800 Message-Id: <1372264261-17442-6-git-send-email-liuj97@gmail.com> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1372264261-17442-1-git-send-email-liuj97@gmail.com> References: <1372264261-17442-1-git-send-email-liuj97@gmail.com> Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Spam-Status: No, score=-8.1 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Jiang Liu Introduce three helper functions, which will be used to simplify code. Signed-off-by: Jiang Liu Cc: Jiang Liu Cc: Len Brown Cc: "Rafael J. Wysocki" Cc: linux-acpi@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- drivers/acpi/utils.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++ include/acpi/acpi_bus.h | 5 ++++ 2 files changed, 77 insertions(+) diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c index 74437130..5bcf068 100644 --- a/drivers/acpi/utils.c +++ b/drivers/acpi/utils.c @@ -495,3 +495,75 @@ acpi_handle_printk(const char *level, acpi_handle handle, const char *fmt, ...) kfree(buffer.pointer); } EXPORT_SYMBOL(acpi_handle_printk); + +static acpi_status +acpi_evaluate_object_with_int_arg(acpi_handle handle, char *method, u64 val) +{ + union acpi_object arg; + struct acpi_object_list arg_list; + + arg.type = ACPI_TYPE_INTEGER; + arg.integer.value = val; + arg_list.count = 1; + arg_list.pointer = &arg; + + return acpi_evaluate_object(handle, method, &arg_list, NULL); +} + +/** + * acpi_evaluate_ej0: Evaluate _EJ0 method for hotplug operations + * @handle: ACPI device handle + * + * Evaluate device's _EJ0 method for hotplug operations. + */ +acpi_status acpi_evaluate_ej0(acpi_handle handle) +{ + acpi_status status; + + status = acpi_evaluate_object_with_int_arg(handle, "_EJ0", 1); + if (status == AE_NOT_FOUND) + acpi_handle_warn(handle, "No _EJ0 support for device\n"); + else if (ACPI_FAILURE(status)) + acpi_handle_warn(handle, "Eject failed (0x%x)\n", status); + + return status; +} + +/** + * acpi_evaluate_lck: Evaluate _LCK method to lock/unlock device + * @handle: ACPI device handle + * @lock: lock device if non-zero, otherwise unlock device + * + * Evaluate device's _LCK method if present to lock/unlock device + */ +acpi_status acpi_evaluate_lck(acpi_handle handle, int lock) +{ + acpi_status status; + + status = acpi_evaluate_object_with_int_arg(handle, "_LCK", !!lock); + if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) { + if (lock) + acpi_handle_warn(handle, + "Locking device failed (0x%x)\n", status); + else + acpi_handle_warn(handle, + "Unlocking device failed (0x%x)\n", status); + } + + return status; +} + +/** + * acpi_has_method: Check whether @handle has a method named @name + * @handle: ACPI device handle + * @name: name of object or method + * + * Check whether @handle has a method named @name. + */ +bool acpi_has_method(acpi_handle handle, char *name) +{ + acpi_handle tmp; + + return ACPI_SUCCESS(acpi_get_handle(handle, name, &tmp)); +} +EXPORT_SYMBOL(acpi_has_method); diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h index ca081ac..3db3b97 100644 --- a/include/acpi/acpi_bus.h +++ b/include/acpi/acpi_bus.h @@ -56,6 +56,11 @@ acpi_evaluate_hotplug_ost(acpi_handle handle, u32 source_event, acpi_status acpi_get_physical_device_location(acpi_handle handle, struct acpi_pld_info **pld); + +acpi_status acpi_evaluate_ej0(acpi_handle handle); +acpi_status acpi_evaluate_lck(acpi_handle handle, int lock); +bool acpi_has_method(acpi_handle handle, char *name); + #ifdef CONFIG_ACPI #include