From patchwork Thu Jan 24 20:27:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Pawe=C5=82_Chmiel?= X-Patchwork-Id: 10780095 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6127114E5 for ; Thu, 24 Jan 2019 20:28:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3A6CB2D48F for ; Thu, 24 Jan 2019 20:28:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2952E2E1C5; Thu, 24 Jan 2019 20:28:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8CE1C2D48F for ; Thu, 24 Jan 2019 20:28:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728162AbfAXU17 (ORCPT ); Thu, 24 Jan 2019 15:27:59 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:52821 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726141AbfAXU17 (ORCPT ); Thu, 24 Jan 2019 15:27:59 -0500 Received: by mail-wm1-f65.google.com with SMTP id m1so4598043wml.2; Thu, 24 Jan 2019 12:27:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=nr4/BbRpVEWQXv12T0zxMGq0I9UYwLzSU2BFQ7EQtWo=; b=YAVLp9UNpipnUuEYY1divL9x2JIffPUh/yilFiykASCoTmsRmQAlEYPLp/XOIEj45Z XYt3BDjvOzD9ubbfQU6kILfEmN5hBpvVCGJ+JsXWZmB/znf1H24g/8EXl7pujhIRJ/3h 9xaGj0mKZM5X45j7H175N63igszfLbvtcgvY/1yfAwDjj+pNGBWGXgF4xFIxSaAI4Cay L88BpdB+6twXFjZlpqGihqGdZDX+NQfB/9iBPPMdZ9uSEphsdEwbMnpuZC3jnPLjK3VY VCA6tTGQivauEjygZCJCOBCk4ukpfHJR5VfC55MF3DK8YuSwy3rW8jA1hQE1Bl0oByrZ SfIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=nr4/BbRpVEWQXv12T0zxMGq0I9UYwLzSU2BFQ7EQtWo=; b=bft6aI8/plQGBOzia4uNM+bWAn5ig6cIUs/QcSKoVYXdvIL1jB4qE2N45rIjdEHDDQ vtJ/6Yc55sH1QhyDaiYOaKOh4LxUE+ZE1j42VcAYg8I0faYc2/xu+pIC2/aWZa8fp3QM 7VV3xZSYNhTYtnANgrd9xK7h7Gun5P8R61SMkvfAb9aOSU7T/0VKRmb81JitWlvJGElV +Us6vY6ALfgqyE8PNmtKltjhxtgJzKuzCkdrSGUCwdtD3YglqREHPAkXuve+z4+5Kze7 b87crFCQJVM8lvvOxMCdB28nYRIJStskl3D4rTv0i9m2tiINtdZV/B6jy3gYF+XMyGHv dbCg== X-Gm-Message-State: AJcUukc4TXyow0TGdS1qDxYQZhBk1KzXM5RJhbNudadhCzanJIxO399Z VUZbAzzL5kFw055CJd3XLp8= X-Google-Smtp-Source: ALg8bN52vADhE4joaXEfF03VuaO6b8ln2Y9GQHJZdE0nkDrwrK89XJ52/dVjPM6VmBUwI1oAMwzL7w== X-Received: by 2002:a1c:ae15:: with SMTP id x21mr4084973wme.146.1548361677237; Thu, 24 Jan 2019 12:27:57 -0800 (PST) Received: from localhost.localdomain ([2a02:a315:5445:5300:9dbf:5832:1d37:55b2]) by smtp.googlemail.com with ESMTPSA id g67sm128617960wmd.38.2019.01.24.12.27.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 24 Jan 2019 12:27:56 -0800 (PST) From: =?utf-8?q?Pawe=C5=82_Chmiel?= To: dmitry.torokhov@gmail.com Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, Jonathan Bakker , =?utf-8?q?Pawe=C5=82_Chmiel?= Subject: [PATCH v2 1/2] input: misc: pwm-vibra: Prevent unbalanced regulator Date: Thu, 24 Jan 2019 21:27:31 +0100 Message-Id: <20190124202732.14723-1-pawel.mikolaj.chmiel@gmail.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Jonathan Bakker pwm_vibrator_stop disables the regulator, but it can be called from multiple places, even when the regulator is already disabled. Fix this by using regulator_is_enabled check when starting and stopping device. Signed-off-by: Jonathan Bakker Signed-off-by: Paweł Chmiel --- Changes from v1: - Rather than using regulator_is_enabled api, use local flag for checking if regulator is enabled --- drivers/input/misc/pwm-vibra.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/drivers/input/misc/pwm-vibra.c b/drivers/input/misc/pwm-vibra.c index 55da191ae550..9df87431d7d4 100644 --- a/drivers/input/misc/pwm-vibra.c +++ b/drivers/input/misc/pwm-vibra.c @@ -34,6 +34,7 @@ struct pwm_vibrator { struct work_struct play_work; u16 level; u32 direction_duty_cycle; + bool vcc_on; }; static int pwm_vibrator_start(struct pwm_vibrator *vibrator) @@ -42,10 +43,13 @@ static int pwm_vibrator_start(struct pwm_vibrator *vibrator) struct pwm_state state; int err; - err = regulator_enable(vibrator->vcc); - if (err) { - dev_err(pdev, "failed to enable regulator: %d", err); - return err; + if (!vibrator->vcc_on) { + err = regulator_enable(vibrator->vcc); + if (err) { + dev_err(pdev, "failed to enable regulator: %d", err); + return err; + } + vibrator->vcc_on = true; } pwm_get_state(vibrator->pwm, &state); @@ -76,7 +80,10 @@ static int pwm_vibrator_start(struct pwm_vibrator *vibrator) static void pwm_vibrator_stop(struct pwm_vibrator *vibrator) { - regulator_disable(vibrator->vcc); + if (vibrator->vcc_on) { + regulator_disable(vibrator->vcc); + vibrator->vcc_on = false; + } if (vibrator->pwm_dir) pwm_disable(vibrator->pwm_dir); From patchwork Thu Jan 24 20:27:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Pawe=C5=82_Chmiel?= X-Patchwork-Id: 10780097 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7ED551399 for ; Thu, 24 Jan 2019 20:28:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6F6062D48F for ; Thu, 24 Jan 2019 20:28:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 630462E1AC; Thu, 24 Jan 2019 20:28:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 150C02D48F for ; Thu, 24 Jan 2019 20:28:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728395AbfAXU2C (ORCPT ); Thu, 24 Jan 2019 15:28:02 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:54563 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728084AbfAXU2A (ORCPT ); Thu, 24 Jan 2019 15:28:00 -0500 Received: by mail-wm1-f67.google.com with SMTP id a62so4585598wmh.4; Thu, 24 Jan 2019 12:27:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+6IfJiCGXlpW+dv24DGIPbhLiY/a5Z0pefOdxLNkgPs=; b=sePglr2n5+N+RPa28bDMFT82KfHBuei3V4a878wR5TOYpuiUowEvgw56bX4z2HmCFC 2GCose1fGUuw/V+/FMTgmdXebl0740MFL5AdZkbrR+uOw27TQXk7XjFPB82suVp3ydwx ig3/F1i9Ayf9c3jd8/M46Ojv2AxLos/lJNigSq+MquOgsuzf/Ysg/5zUwBv5LuTpNEHf 2q+vnbf1OxUbL0i/+JATZM0CpO2STUQfrnDlPr0yHYOh/i0TTp4rqVIUBRl9F7Ibrzy8 2q5RGugAfCtyIMG24TYWYO3YLxOiJYbpbYZy5K9SE8X8Ip1PJzkR/QBJiiIG2Emp1fvg FUzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+6IfJiCGXlpW+dv24DGIPbhLiY/a5Z0pefOdxLNkgPs=; b=LovjbO8UtRmMByeh+sU0LWDPP1yLHMbF/ntiwTNhjiSME8p4E72H4IXgw2cXcyxcPw ltgTfmwC7GhUKdhmVq5cY2D3VaZdFhKueza5PeP8MghQ37dNqonknu5L03Hg/EQTCQpI MEouEQp+AdQutza/nIsSxtZNrJxiMCS6svfFOyaYjfDjT+M8qdHTUzmo4/meJBoSXTKd NYA12DCKRIMGbQDwTeB9NF0/D+4a4Uk9gaqH9yx7hsPK1+wA5dsZl+S8+NMWW6RzBxSA Fkv5nc8/WGJrBTxFbwcJgjlR5ZCSVKgYZzaBfLGYTO9v9lTFq36l6KbLxgu3ZRVutkUx MGXg== X-Gm-Message-State: AJcUukfr7k8SmYFk7cMCXG67zzgolLPvDqxrpujjfNqASBF3FNCoBt0i tVWbb+HXT6OXjlmV4G0ycF8+P8Y2yOc= X-Google-Smtp-Source: ALg8bN7772rhYUqdCQQQ+0xH6mYJHPLxLdHLm3PyD7m8TqeQYB0q1Y4bW6PHt21ydQ2cKQXcLAg6ww== X-Received: by 2002:a1c:4d12:: with SMTP id o18mr4266950wmh.92.1548361678614; Thu, 24 Jan 2019 12:27:58 -0800 (PST) Received: from localhost.localdomain ([2a02:a315:5445:5300:9dbf:5832:1d37:55b2]) by smtp.googlemail.com with ESMTPSA id g67sm128617960wmd.38.2019.01.24.12.27.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 24 Jan 2019 12:27:57 -0800 (PST) From: =?utf-8?q?Pawe=C5=82_Chmiel?= To: dmitry.torokhov@gmail.com Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Paw?= =?utf-8?q?e=C5=82_Chmiel?= Subject: [PATCH v2 2/2] input: misc: pwm-vibra: Stop regulator after disabling pwm, not before Date: Thu, 24 Jan 2019 21:27:32 +0100 Message-Id: <20190124202732.14723-2-pawel.mikolaj.chmiel@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190124202732.14723-1-pawel.mikolaj.chmiel@gmail.com> References: <20190124202732.14723-1-pawel.mikolaj.chmiel@gmail.com> MIME-Version: 1.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch fixes order of disable calls in pwm_vibrator_stop. Currently when starting device, we first enable vcc regulator and then setup and enable pwm. When stopping, we should do this in oposite order, so first disable pwm and then disable regulator. Previously order was the same as in start. Signed-off-by: Paweł Chmiel --- drivers/input/misc/pwm-vibra.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/input/misc/pwm-vibra.c b/drivers/input/misc/pwm-vibra.c index 9df87431d7d4..dbb6d9e1b947 100644 --- a/drivers/input/misc/pwm-vibra.c +++ b/drivers/input/misc/pwm-vibra.c @@ -80,14 +80,14 @@ static int pwm_vibrator_start(struct pwm_vibrator *vibrator) static void pwm_vibrator_stop(struct pwm_vibrator *vibrator) { + if (vibrator->pwm_dir) + pwm_disable(vibrator->pwm_dir); + pwm_disable(vibrator->pwm); + if (vibrator->vcc_on) { regulator_disable(vibrator->vcc); vibrator->vcc_on = false; } - - if (vibrator->pwm_dir) - pwm_disable(vibrator->pwm_dir); - pwm_disable(vibrator->pwm); } static void pwm_vibrator_play_work(struct work_struct *work)