From patchwork Thu Jul 23 01:37:48 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Azael Avalos X-Patchwork-Id: 6848861 Return-Path: X-Original-To: patchwork-platform-driver-x86@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 57D6EC05AC for ; Thu, 23 Jul 2015 01:39:02 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6706D206C5 for ; Thu, 23 Jul 2015 01:39:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 77E9A206E8 for ; Thu, 23 Jul 2015 01:39:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753523AbbGWBiL (ORCPT ); Wed, 22 Jul 2015 21:38:11 -0400 Received: from mail-ob0-f181.google.com ([209.85.214.181]:36609 "EHLO mail-ob0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753196AbbGWBiE (ORCPT ); Wed, 22 Jul 2015 21:38:04 -0400 Received: by obnw1 with SMTP id w1so145097897obn.3; Wed, 22 Jul 2015 18:38:03 -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:in-reply-to:references; bh=pz4M+/Z1bMAcfCnkbRfVV64kS5WeBaRXeV3riednBE0=; b=dfcx2bhYH4QFBhsWs9w3mzT7TaHQh6lvgsrQQa32vBiDbDwnOevhm+O0Q37gR+/ztT gO4ZJv7DS6o3dzcDst2irREjvulN/r7EDajz5h6FdTfSdqXcZQnCF5zz5RA1CW3aYhIR oAuwovFSwCG/tEn22mCtAhWsuyoCvQE5ODEHSNQkq6ggxg6Vv5T8lBT/s8Xcnh8MVodA GRQ2kAslU+HoD3IAyrPR6ZoUdt+tH5ZyFUSvU5ntzvt+RmIyZAx1mjMkzGYMk39OWe5L pnMWyTH9kcrLY6mcTlMcrryZLEcvFPx0bphQ9OF9X893eAmD9QAy1MA3B2Fpig7dv1F+ PpaQ== X-Received: by 10.202.77.144 with SMTP id a138mr5188074oib.32.1437615483887; Wed, 22 Jul 2015 18:38:03 -0700 (PDT) Received: from Shakuras.scurra.org (189.202.43.115.cable.dyn.cableonline.com.mx. [189.202.43.115]) by smtp.gmail.com with ESMTPSA id z19sm1960401obp.17.2015.07.22.18.38.02 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 22 Jul 2015 18:38:02 -0700 (PDT) From: Azael Avalos To: Darren Hart , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Azael Avalos Subject: [PATCH 1/1] toshiba_acpi: Add set_fan_status function Date: Wed, 22 Jul 2015 19:37:48 -0600 Message-Id: <1437615474-27936-3-git-send-email-coproscefalo@gmail.com> X-Mailer: git-send-email 2.4.5 In-Reply-To: <1437615474-27936-1-git-send-email-coproscefalo@gmail.com> References: <1437615474-27936-1-git-send-email-coproscefalo@gmail.com> Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org X-Spam-Status: No, score=-8.0 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=ham 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 This patch adds a new function named "set_fan_status" to complement its get* counterpart, as well as to avoid code duplication between "fan_proc_write" and "fan_store". Signed-off-by: Azael Avalos --- drivers/platform/x86/toshiba_acpi.c | 55 ++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 19 deletions(-) diff --git a/drivers/platform/x86/toshiba_acpi.c b/drivers/platform/x86/toshiba_acpi.c index 6013a11..08fc867 100644 --- a/drivers/platform/x86/toshiba_acpi.c +++ b/drivers/platform/x86/toshiba_acpi.c @@ -1422,12 +1422,33 @@ static const struct file_operations video_proc_fops = { .write = video_proc_write, }; +/* Fan status */ static int get_fan_status(struct toshiba_acpi_dev *dev, u32 *status) { - u32 hci_result; + u32 result = hci_read(dev, HCI_FAN, status); - hci_result = hci_read(dev, HCI_FAN, status); - return hci_result == TOS_SUCCESS ? 0 : -EIO; + if (result == TOS_FAILURE) + pr_err("ACPI call to get Fan status failed\n"); + else if (result == TOS_NOT_SUPPORTED) + return -ENODEV; + else if (result == TOS_SUCCESS) + return 0; + + return -EIO; +} + +static int set_fan_status(struct toshiba_acpi_dev *dev, u32 status) +{ + u32 result = hci_write(dev, HCI_FAN, status); + + if (result == TOS_FAILURE) + pr_err("ACPI call to set Fan status failed\n"); + else if (result == TOS_NOT_SUPPORTED) + return -ENODEV; + else if (result == TOS_SUCCESS) + return 0; + + return -EIO; } static int fan_proc_show(struct seq_file *m, void *v) @@ -1457,23 +1478,22 @@ static ssize_t fan_proc_write(struct file *file, const char __user *buf, char cmd[42]; size_t len; int value; - u32 hci_result; + int ret; len = min(count, sizeof(cmd) - 1); if (copy_from_user(cmd, buf, len)) return -EFAULT; cmd[len] = '\0'; - if (sscanf(cmd, " force_on : %i", &value) == 1 && - value >= 0 && value <= 1) { - hci_result = hci_write(dev, HCI_FAN, value); - if (hci_result == TOS_SUCCESS) - dev->force_fan = value; - else - return -EIO; - } else { + if (sscanf(cmd, " force_on : %i", &value) != 1 && + value != 0 && value != 1) return -EINVAL; - } + + ret = set_fan_status(dev, value); + if (ret) + return ret; + + dev->force_fan = value; return count; } @@ -1610,7 +1630,6 @@ static ssize_t fan_store(struct device *dev, const char *buf, size_t count) { struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); - u32 result; int state; int ret; @@ -1621,11 +1640,9 @@ static ssize_t fan_store(struct device *dev, if (state != 0 && state != 1) return -EINVAL; - result = hci_write(toshiba, HCI_FAN, state); - if (result == TOS_FAILURE) - return -EIO; - else if (result == TOS_NOT_SUPPORTED) - return -ENODEV; + ret = set_fan_status(toshiba, state); + if (ret) + return ret; return count; }