From patchwork Thu Mar 15 09:29:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 131756 Delivered-To: patch@linaro.org Received: by 10.46.84.17 with SMTP id i17csp868868ljb; Thu, 15 Mar 2018 02:30:47 -0700 (PDT) X-Google-Smtp-Source: AG47ELtKznLV+mRcwENHxm/DilTZIcw7bm0hDrAxQf5BqCcSKO9Ugdih1PTDezIorw2rnNq0203r X-Received: by 10.99.110.137 with SMTP id j131mr6234146pgc.85.1521106247035; Thu, 15 Mar 2018 02:30:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521106247; cv=none; d=google.com; s=arc-20160816; b=Xq7z8JdIwgDPpq6IYZprzBxiPZ20vDoUFN9d8XRVYcwoul+I4Nh2VircxN522L6iMP CynjLLDvsVUYgeJJ3NzN95ac5oVuNZT0tB2x6UhTg+d0B63FzQg5NQS5hmM2Ql/gyZ/J F9xd3/XsgeywJ19IpjWXOvmQgIr/IoGHj6PKACr1xEtGIs5MMUu1f/PlFFokZs+IIskt 4p69H+5iu48ajWMG3xQ0a5ejLOzi+KqobhvBWw6uy+5RNeR/Ec1F2uyy87w9JSl4hqgr dzgxcHHkoePmuhxqLkpR/Sb4yYsq31jvzSxOkizeJYkf194A22juASAfE7kOPLhp+DZv duNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=gfV0c872ULAHYwlNt2ZtFduTpDn5/sTi8IyqFyrjMvM=; b=HQ6XTkdrpWnxFZQJn+pc9gtkPGzCbhTmHlZ4MKKqUGfMRjMrSJljI6XNmfStu43lZ0 L3D1etUDL5X1ldTEkuiHzbYCczMSXXBrScHPduRvC7CJbjwn4qVAlIORd2jcAjpToEN6 T/QdlNzlK22CHctcr5KEL5LilqBjck078B1S6Hv5VTAdpC+VpAHGdimt22iWFl5yJEOq stQa+Pt6CRe6Aiosgu45jiN+rbxlwXiSEc3hKKFmtBmVMqPHn/3AdQu5wfhCsYTyfmd2 00tGJHqOHSRRzB8SQtVbXxy8EhgXcA7ufskkk7TLBpF012I/LUEc8tF8t0d0HBS4BPG5 ASHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LbbQl2kZ; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e5-v6si3801937plk.185.2018.03.15.02.30.46; Thu, 15 Mar 2018 02:30:47 -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; dkim=pass header.i=@linaro.org header.s=google header.b=LbbQl2kZ; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751774AbeCOJan (ORCPT + 28 others); Thu, 15 Mar 2018 05:30:43 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:54726 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751095AbeCOJak (ORCPT ); Thu, 15 Mar 2018 05:30:40 -0400 Received: by mail-wm0-f66.google.com with SMTP id h76so9126031wme.4 for ; Thu, 15 Mar 2018 02:30:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=gfV0c872ULAHYwlNt2ZtFduTpDn5/sTi8IyqFyrjMvM=; b=LbbQl2kZse737gz5gc3kSxxkKXYJDtd/+1s3EMOzrjZGereaWnGm1IbR1WWgaCirE6 PZelymBIFzgeODZUvOGj+ZKzodulcmyZgmSazvfM+ALfytlX+zYJqiKHSNfPalG1G+bW 0to1NYc2EAMBtzDjIUJXuFWmFNXwzqyoMy37w= 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; bh=gfV0c872ULAHYwlNt2ZtFduTpDn5/sTi8IyqFyrjMvM=; b=Dd+V/hwB8L6G7c88J0bWgtDG28lBJ1Tr3Fk7109zY9McqC6gaQhQgMQu37zgoIGTy/ +uG6I6OwYh//g2tFPg8r8c8bDDiQfYgrtw6rgcWOHC9m56sp6LclobTE8k7gr3gbeie4 Ti0DmK9+NK3etB+310NeBobOlzbh4GYG8eQlh/XL+UyyDJujIjppR3GN3d9IIECg9tUw EzUlpaCZfvzpAQGwOxewgY++PC+y7RYA1Q5NXIsTsZB2M1EVFhC5RUR2D3D7wlTYEMvL Ksh3PIUT2dI5XsSNcek5rmd5ssJEuAFd96i7P47gddAiIqhaDeMBnTLy/q99l5tV5fJs VRbg== X-Gm-Message-State: AElRT7G/ZDikf8eH8LFojfhILNPDpXANiPkZVHqU74KQSmANFlNGMlfs ZFaANyCrihC9tNbg5/Ge74H536qijKs= X-Received: by 10.28.144.5 with SMTP id s5mr3971333wmd.98.1521106239147; Thu, 15 Mar 2018 02:30:39 -0700 (PDT) Received: from lmecxl0911.lme.st.com ([80.214.78.222]) by smtp.gmail.com with ESMTPSA id m71sm3603844wmd.6.2018.03.15.02.30.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 15 Mar 2018 02:30:38 -0700 (PDT) From: Benjamin Gaignard X-Google-Original-From: Benjamin Gaignard To: mchehab@kernel.org, mcoquelin.stm32@gmail.com, alexandre.torgue@st.com, hans.verkuil@cisco.com Cc: linux-media@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Benjamin Gaignard Subject: [PATCH 1/2] cec: stm32: simplify clock management Date: Thu, 15 Mar 2018 10:29:48 +0100 Message-Id: <20180315092949.9895-2-benjamin.gaignard@st.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20180315092949.9895-1-benjamin.gaignard@st.com> References: <20180315092949.9895-1-benjamin.gaignard@st.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Benjamin Gaignard Since CEC framework enable and disable the adapter when it is needed just follow it orders to enable/disable the clocks. Call stm32_cec_hw_init() when the adapter is enabled and do not let regmap manage registers clock help to simplify clocking scheme. While reworking cec clock start using pm_runtime. Signed-off-by: Benjamin Gaignard --- drivers/media/platform/stm32/stm32-cec.c | 70 ++++++++++++++++++-------------- 1 file changed, 40 insertions(+), 30 deletions(-) -- 2.15.0 diff --git a/drivers/media/platform/stm32/stm32-cec.c b/drivers/media/platform/stm32/stm32-cec.c index 7c496bc1cf38..35cc2ffd6b96 100644 --- a/drivers/media/platform/stm32/stm32-cec.c +++ b/drivers/media/platform/stm32/stm32-cec.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -70,7 +71,7 @@ struct stm32_cec { int tx_cnt; }; -static void cec_hw_init(struct stm32_cec *cec) +static void stm32_cec_hw_init(struct stm32_cec *cec) { regmap_update_bits(cec->regmap, CEC_CR, TXEOM | TXSOM | CECEN, 0); @@ -166,22 +167,17 @@ static irqreturn_t stm32_cec_irq_handler(int irq, void *arg) static int stm32_cec_adap_enable(struct cec_adapter *adap, bool enable) { struct stm32_cec *cec = adap->priv; - int ret = 0; if (enable) { - ret = clk_enable(cec->clk_cec); - if (ret) - dev_err(cec->dev, "fail to enable cec clock\n"); - - clk_enable(cec->clk_hdmi_cec); + pm_runtime_get_sync(cec->dev); + stm32_cec_hw_init(cec); regmap_update_bits(cec->regmap, CEC_CR, CECEN, CECEN); } else { - clk_disable(cec->clk_cec); - clk_disable(cec->clk_hdmi_cec); regmap_update_bits(cec->regmap, CEC_CR, CECEN, 0); + pm_runtime_disable(cec->dev); } - return ret; + return 0; } static int stm32_cec_adap_log_addr(struct cec_adapter *adap, u8 logical_addr) @@ -260,8 +256,8 @@ static int stm32_cec_probe(struct platform_device *pdev) if (IS_ERR(mmio)) return PTR_ERR(mmio); - cec->regmap = devm_regmap_init_mmio_clk(&pdev->dev, "cec", mmio, - &stm32_cec_regmap_cfg); + cec->regmap = devm_regmap_init_mmio(&pdev->dev, mmio, + &stm32_cec_regmap_cfg); if (IS_ERR(cec->regmap)) return PTR_ERR(cec->regmap); @@ -284,19 +280,10 @@ static int stm32_cec_probe(struct platform_device *pdev) return PTR_ERR(cec->clk_cec); } - ret = clk_prepare(cec->clk_cec); - if (ret) { - dev_err(&pdev->dev, "Unable to prepare cec clock\n"); - return ret; - } - cec->clk_hdmi_cec = devm_clk_get(&pdev->dev, "hdmi-cec"); - if (!IS_ERR(cec->clk_hdmi_cec)) { - ret = clk_prepare(cec->clk_hdmi_cec); - if (ret) { - dev_err(&pdev->dev, "Unable to prepare hdmi-cec clock\n"); - return ret; - } + if (IS_ERR(cec->clk_hdmi_cec)) { + dev_err(&pdev->dev, "Cannot get cec clock\n"); + return PTR_ERR(cec->clk_hdmi_cec); } /* @@ -315,24 +302,46 @@ static int stm32_cec_probe(struct platform_device *pdev) return ret; } - cec_hw_init(cec); - platform_set_drvdata(pdev, cec); + pm_runtime_enable(&pdev->dev); - return 0; + return ret; } static int stm32_cec_remove(struct platform_device *pdev) { struct stm32_cec *cec = platform_get_drvdata(pdev); - clk_unprepare(cec->clk_cec); - clk_unprepare(cec->clk_hdmi_cec); - cec_unregister_adapter(cec->adap); + pm_runtime_disable(&pdev->dev); + return 0; } +static int __maybe_unused stm32_cec_runtime_suspend(struct device *dev) +{ + struct stm32_cec *cec = dev_get_drvdata(dev); + + clk_disable_unprepare(cec->clk_cec); + clk_disable_unprepare(cec->clk_hdmi_cec); + + return 0; +} + +static int __maybe_unused stm32_cec_runtime_resume(struct device *dev) +{ + struct stm32_cec *cec = dev_get_drvdata(dev); + + clk_prepare_enable(cec->clk_cec); + clk_prepare_enable(cec->clk_hdmi_cec); + + return 0; +} + +static const struct dev_pm_ops stm32_cec_pm_ops = { + SET_RUNTIME_PM_OPS(stm32_cec_runtime_suspend, stm32_cec_runtime_resume, + NULL) +}; static const struct of_device_id stm32_cec_of_match[] = { { .compatible = "st,stm32-cec" }, @@ -346,6 +355,7 @@ static struct platform_driver stm32_cec_driver = { .driver = { .name = CEC_NAME, .of_match_table = stm32_cec_of_match, + .pm = &stm32_cec_pm_ops, }, };