From patchwork Mon Jul 14 14:33:31 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 33600 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f69.google.com (mail-pa0-f69.google.com [209.85.220.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 4DA2F20CAD for ; Mon, 14 Jul 2014 14:35:13 +0000 (UTC) Received: by mail-pa0-f69.google.com with SMTP id kx10sf24723051pab.8 for ; Mon, 14 Jul 2014 07:35:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=IeKAZqupFlMnr4zKy/XQcs/SZCI3BlYEioE8fhZIe7Q=; b=ktFkokPzQEGHy0t8R1Gfd87nmYfM7EOxZoZaQco9dg21nCaeXWTe5mYXLC8JHjE56B slsdmHSnuCCaX5M68W9nCgpMXc0/wKc1aplO5kgNrmn+vr9AieQ/zXavA0IF7DANaCNf xFpWGx8MHRm8D3EyzWorkfOyVsK+NG8I7leopQX4U8UYbFn20NU9t38TLDfyvomoY+vi pdOWvUs7UkKfLhquo4zpPSyMtKrTqd6HXPRBPesqUkEl3lMTx0t6/N5wReJcrkQ/Txv+ u7vByD6KMhtxwTVyFuPW1WqfEyFw1yhzQnXjHJtF/FRwYUc1dYyuWvk5GrD5sgbVXy67 wfow== X-Gm-Message-State: ALoCoQnvMazZhcDL9i6ObkTw6JWzRw5EzhOru+kA+OCWFLEClsVFAsZrF+eHDpKA9s0yuvngVtHE X-Received: by 10.66.65.109 with SMTP id w13mr8040536pas.21.1405348512512; Mon, 14 Jul 2014 07:35:12 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.87.37 with SMTP id q34ls343022qgd.5.gmail; Mon, 14 Jul 2014 07:35:12 -0700 (PDT) X-Received: by 10.52.27.80 with SMTP id r16mr131218vdg.91.1405348512394; Mon, 14 Jul 2014 07:35:12 -0700 (PDT) Received: from mail-vc0-f172.google.com (mail-vc0-f172.google.com [209.85.220.172]) by mx.google.com with ESMTPS id si10si5437961vcb.10.2014.07.14.07.35.12 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 14 Jul 2014 07:35:12 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.172 as permitted sender) client-ip=209.85.220.172; Received: by mail-vc0-f172.google.com with SMTP id hq11so6400860vcb.3 for ; Mon, 14 Jul 2014 07:35:12 -0700 (PDT) X-Received: by 10.53.5.230 with SMTP id cp6mr12726236vdd.25.1405348512288; Mon, 14 Jul 2014 07:35:12 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp139628vcb; Mon, 14 Jul 2014 07:35:11 -0700 (PDT) X-Received: by 10.68.252.73 with SMTP id zq9mr658299pbc.146.1405348511461; Mon, 14 Jul 2014 07:35:11 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ei3si9273434pbb.219.2014.07.14.07.35.10; Mon, 14 Jul 2014 07:35:10 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755946AbaGNOe7 (ORCPT + 28 others); Mon, 14 Jul 2014 10:34:59 -0400 Received: from mail-ig0-f176.google.com ([209.85.213.176]:50998 "EHLO mail-ig0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755863AbaGNOeK (ORCPT ); Mon, 14 Jul 2014 10:34:10 -0400 Received: by mail-ig0-f176.google.com with SMTP id hn18so1729097igb.9 for ; Mon, 14 Jul 2014 07:34:09 -0700 (PDT) X-Received: by 10.50.138.66 with SMTP id qo2mr12787805igb.12.1405348449804; Mon, 14 Jul 2014 07:34:09 -0700 (PDT) Received: from localhost.localdomain (host109-148-237-85.range109-148.btcentralplus.com. [109.148.237.85]) by mx.google.com with ESMTPSA id q11sm25317390igr.7.2014.07.14.07.34.07 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 14 Jul 2014 07:34:09 -0700 (PDT) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: lee.jones@linaro.org, kernel@stlinux.com, thierry.reding@gmail.com, linux-pwm@vger.kernel.org, devicetree@vger.kernel.org, ajitpal.singh@st.com Subject: [PATCH v2 10/11] pwm: sti: Sync between enable/disable calls Date: Mon, 14 Jul 2014 15:33:31 +0100 Message-Id: <1405348412-7352-11-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1405348412-7352-1-git-send-email-lee.jones@linaro.org> References: <1405348412-7352-1-git-send-email-lee.jones@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: lee.jones@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.172 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Ajit Pal Singh ST PWM IP has a common enable/disable control for all the PWM channels on a PWM cell. Disables PWM output on the PWM HW only when disable is called for the last channel. Signed-off-by: Ajit Pal Singh Signed-off-by: Lee Jones --- drivers/pwm/pwm-sti.c | 44 ++++++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/drivers/pwm/pwm-sti.c b/drivers/pwm/pwm-sti.c index 0fdf4b4..1aa901d 100644 --- a/drivers/pwm/pwm-sti.c +++ b/drivers/pwm/pwm-sti.c @@ -59,6 +59,8 @@ struct sti_pwm_chip { unsigned long *pwm_periods; struct pwm_chip chip; struct pwm_device *cur; + unsigned int en_count; + struct mutex sti_pwm_lock; /* To sync between enable/disable calls */ void __iomem *mmio; }; @@ -236,32 +238,44 @@ static int sti_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm) { struct sti_pwm_chip *pc = to_sti_pwmchip(chip); struct device *dev = pc->dev; - int ret; - - ret = clk_enable(pc->clk); - if (ret) - return ret; + int ret = 0; - ret = regmap_field_write(pc->pwm_en, 1); - if (ret) - dev_err(dev, "%s,pwm_en write failed\n", __func__); + /* + * Since we have a common enable for all PWM channels, + * do not enable if already enabled. + */ + mutex_lock(&pc->sti_pwm_lock); + if (!pc->en_count) { + ret = clk_enable(pc->clk); + if (ret) + goto out; + ret = regmap_field_write(pc->pwm_en, 1); + if (ret) { + dev_err(dev, "failed to enable PWM device:%d\n", + pwm->hwpwm); + goto out; + } + } + pc->en_count++; +out: + mutex_unlock(&pc->sti_pwm_lock); return ret; } static void sti_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm) { struct sti_pwm_chip *pc = to_sti_pwmchip(chip); - struct device *dev = pc->dev; - unsigned int val; + mutex_lock(&pc->sti_pwm_lock); + if (--pc->en_count) { + mutex_unlock(&pc->sti_pwm_lock); + return; + } regmap_field_write(pc->pwm_en, 0); - regmap_read(pc->regmap, STI_CNT, &val); - - dev_dbg(dev, "pwm counter :%u\n", val); - clk_disable(pc->clk); + mutex_unlock(&pc->sti_pwm_lock); } static const struct pwm_ops sti_pwm_ops = { @@ -352,6 +366,8 @@ static int sti_pwm_probe(struct platform_device *pdev) pc->cdata = cdata; pc->dev = dev; + pc->en_count = 0; + mutex_init(&pc->sti_pwm_lock); ret = sti_pwm_probe_dt(pc); if (ret)