Received: by 10.213.65.68 with SMTP id h4csp957100imn; Tue, 20 Mar 2018 21:42:34 -0700 (PDT) X-Google-Smtp-Source: AG47ELtF0P0/Rnu3+G01OnX0+DmBLSLH4lvYL9rFcKyFt05boGaFPrTehFb9pHSFDobGEoC6ztq/ X-Received: by 2002:a17:902:c6b:: with SMTP id 98-v6mr19035541pls.267.1521607354503; Tue, 20 Mar 2018 21:42:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521607354; cv=none; d=google.com; s=arc-20160816; b=DsPHIMmcADTEhet+lMNgu46iaezo2VhqfCr2fjPBp8foyM1cat01RBAZaTzpbFnZOj EtoQyHLcvd7eHSiqBm9rS0/csusOaNxDGTT5XC/drPDuJGdgf2HKprPdIKzuva54wO20 p0xcASAe+Z7F2l6A/yTgucPWjhv8gyN79p/VBWUrEtHONBoftkmpgwLDWEz/YLReFTCC yXcDJqa8EG3aZbG3UQ6qZkmfMXUHYNoU5xnpOL/igh1gjad0q5gJ2KDXYeiIlgPAaD1E jedMaRj+l7ruXiDNSmgL/Ay6CwumfzD+6WOPzZ3/13pd5C7bKZiYU6tz6354vUajVSor baMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=ZJ9UkHPQWCh7rvQRwEwtiwH5JMOQuAQuSx32xVnaqsA=; b=YhbMhS5i4XFw4AZ5BZSY0cZF21MDXwSqFVoITDmzi+cUEzmbAQ7NdIV/xecaWY0kfE OIoYSce45CZ2rR6Wz6ZD5/Y6quOB0g/D608Hb2Lfar9dDXxOBcRksGsEyy6cNVWuwTSh VSX0ehL4tpJ46FIPHs5xdqadLox5ayWY3YYwnxJ6YD+x2UK4xH3a7//e6lY0/4W67UTz 0GVewoiDQj6mBX15MqV9ptZvIMzCY7e7F6ONqoK2OAXSgIBJnJ/SFLBgv5Jl1JcbWroV XhVpcGBWvvo3BxBSSyf3yVXHs7tirb8sitFVb2v4T414x3IrepdDuQRgHX6b1UYiWdNn 618w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n6si2218594pgc.801.2018.03.20.21.42.20; Tue, 20 Mar 2018 21:42:34 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751896AbeCUEky (ORCPT + 99 others); Wed, 21 Mar 2018 00:40:54 -0400 Received: from hqemgate16.nvidia.com ([216.228.121.65]:12169 "EHLO hqemgate16.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751531AbeCUEkv (ORCPT ); Wed, 21 Mar 2018 00:40:51 -0400 Received: from hqpgpgate102.nvidia.com (Not Verified[216.228.121.13]) by hqemgate16.nvidia.com id ; Tue, 20 Mar 2018 21:40:45 -0700 Received: from HQMAIL104.nvidia.com ([172.20.161.6]) by hqpgpgate102.nvidia.com (PGP Universal service); Tue, 20 Mar 2018 21:40:46 -0700 X-PGP-Universal: processed; by hqpgpgate102.nvidia.com on Tue, 20 Mar 2018 21:40:46 -0700 Received: from UKMAIL102.nvidia.com (10.26.138.15) by HQMAIL104.nvidia.com (172.18.146.11) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Wed, 21 Mar 2018 04:40:49 +0000 Received: from HQMAIL101.nvidia.com (172.20.187.10) by UKMAIL102.nvidia.com (10.26.138.15) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Wed, 21 Mar 2018 04:40:45 +0000 Received: from rrajk-ubuntu.nvidia.com (10.124.1.5) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1347.2 via Frontend Transport; Wed, 21 Mar 2018 04:40:36 +0000 From: Rajkumar Rampelli To: , , , , , , , , , , , , , , , , , , , , , CC: , , , , , , , , Subject: [PATCH V2 1/9] pwm: core: Add support for PWM HW driver with pwm capture only Date: Wed, 21 Mar 2018 10:10:36 +0530 Message-ID: <1521607244-29734-2-git-send-email-rrajk@nvidia.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1521607244-29734-1-git-send-email-rrajk@nvidia.com> References: <1521607244-29734-1-git-send-email-rrajk@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add support for pwm HW driver which has only capture functionality. This helps to implement the PWM based Tachometer driver which reads the PWM output signals from electronic fans. PWM Tachometer captures the period and duty cycle of the PWM signal Add conditional checks for callabacks enable(), disable(), config() to check if they are supported by the client driver or not. Skip these callbacks if they are not supported. Signed-off-by: Rajkumar Rampelli --- V2: Added if conditional checks for pwm callbacks since drivers may implements only pwm capture functionality. drivers/pwm/core.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c index 1581f6a..f70fe68 100644 --- a/drivers/pwm/core.c +++ b/drivers/pwm/core.c @@ -246,6 +246,10 @@ static bool pwm_ops_check(const struct pwm_ops *ops) if (ops->apply) return true; + /* driver supports capture operation */ + if (ops->capture) + return true; + return false; } @@ -495,7 +499,8 @@ int pwm_apply_state(struct pwm_device *pwm, struct pwm_state *state) * ->apply(). */ if (pwm->state.enabled) { - pwm->chip->ops->disable(pwm->chip, pwm); + if (pwm->chip->ops->disable) + pwm->chip->ops->disable(pwm->chip, pwm); pwm->state.enabled = false; } @@ -509,22 +514,26 @@ int pwm_apply_state(struct pwm_device *pwm, struct pwm_state *state) if (state->period != pwm->state.period || state->duty_cycle != pwm->state.duty_cycle) { - err = pwm->chip->ops->config(pwm->chip, pwm, + if (pwm->chip->ops->config) { + err = pwm->chip->ops->config(pwm->chip, pwm, state->duty_cycle, state->period); - if (err) - return err; + if (err) + return err; + } pwm->state.duty_cycle = state->duty_cycle; pwm->state.period = state->period; } if (state->enabled != pwm->state.enabled) { - if (state->enabled) { + if (state->enabled && pwm->chip->ops->enable) { err = pwm->chip->ops->enable(pwm->chip, pwm); if (err) return err; - } else { + } + + if (!state->enabled && pwm->chip->ops->disable) { pwm->chip->ops->disable(pwm->chip, pwm); } -- 2.1.4