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: 10284151 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3DED760386 for ; Thu, 15 Mar 2018 09:32:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3F02228971 for ; Thu, 15 Mar 2018 09:32:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 33A3728973; Thu, 15 Mar 2018 09:32:04 +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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B781A28971 for ; Thu, 15 Mar 2018 09:32:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=c9e8kiT48wOawuQ4Ush5wOCIHoIorNrHdncgz6wKprs=; b=G5369UYkbsWuJvoOS3v3WKhk6X A9OdXZ2B+UmgdEBsoxXLgdMutL95lOaP7KyrWxafhWoMj5wXH+8Mx0iiCZn3ZgIPAx4DRtd2dcwLQ suVqhlT4WLjYvEc7zMS335vGXD2QAhYvbdi/HRm8NXB7JMMJs5a1b7ji6SVCi7CBNcQSB0xlgtcUI M7NZafOPsPlufcfs43Kz4AOxFPhCQGI4kmMBfH7XIzNYH6FiSztzPbjO0jQEeoxfQKrsAvYGk3Qqa f8eewHSamvPocOi1J+1/Bba0lSQqlIv0BB6HIdv0vM74aPqBHHwgzOa9HVAxw9BMzVtfkt64uMZE5 KTRd024g==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1ewPEt-0002kr-9K; Thu, 15 Mar 2018 09:31:59 +0000 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1ewPDo-00023i-Hf for linux-arm-kernel@lists.infradead.org; Thu, 15 Mar 2018 09:30:56 +0000 Received: by mail-wm0-x241.google.com with SMTP id t3so9059549wmc.2 for ; Thu, 15 Mar 2018 02:30:40 -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=DDxI8OEpLqmpxjyOvNIPJawpNs44jf1f7lhVuJvqRIEhj/6jEdm2kLG06ZceddstID UuoC3nv7yIG82OEpfqVHaf4uFWLOSdz+4kkGtsOK3q4o33G8G6GyoCeWfrJu0E/oUwU1 7/eACMqdOt+hAN+x+b8ZVVGCLQp0M+F4DG1m1V7ocgFtZWpEUPpy4z2q8I45ZVqlgfuY 8lU60Hj0LO+zh3GqdREHaVljn1q84MYeaNV6OpwKxG0czHRjATrjSDiWBJBnUy2C931X tTNAlI+F2AJC7E7Q/+Hlcu5a5HTKyYSKc9RZ8KMywkEsvSlqNfc8ctEIybevXnS63cMD gzlw== X-Gm-Message-State: AElRT7E3JiDYBECau1Icc0f6k13lVHX8O/aZ//KIZ9w8ppXwTO0Xvrdp 5jZhfbpsH+hCT8hPkSgORyUIBA== X-Google-Smtp-Source: AG47ELukeXaLuEjgHvViGnOSmh5IGM1JTRImoSoNOqrEaNrtJQRLJPN115G8Ie1BQ17JnoPHD17/4A== 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 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180315_023052_729606_17E670BD X-CRM114-Status: GOOD ( 19.08 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Benjamin Gaignard , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-media@vger.kernel.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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(-) 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, }, };