Received: by 10.213.65.68 with SMTP id h4csp1538276imn; Thu, 15 Mar 2018 02:32:14 -0700 (PDT) X-Google-Smtp-Source: AG47ELsvlLcHNMnrq8P3f77VQy2oXLrZgk1SRhSV/dzga2Pj8CRrQELnVK3lm15gYaTaQ5gFA7km X-Received: by 2002:a17:902:8603:: with SMTP id f3-v6mr3488022plo.37.1521106333988; Thu, 15 Mar 2018 02:32:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521106333; cv=none; d=google.com; s=arc-20160816; b=V3Wv4LBM6OmxqKTPbw8YH+4znqT4V+JLqbZS/qZTprlbmw50NHxWU7EeUsrdjJHVFL V1tgIYiZ6e1PNh9oXB7CEaaLfL6Hth7IxZkIXqsU37w+eu4yrp7hV7boMUbayD/z/WFz xi1hlaziBzv1dOM0JbCYLAbyjcG083OlGJ+FlmE+HAB4eHZCYawNMWqRlnYYEqa+Ijt5 2z6qVEBmxn7FEOxAxCMPdp569iZJGutBY+rct7UVySu1mFf6oRNu9IHzdGDv9RTTj9dC ZHGCoAgyLHHBBhYmr+sHYAf+RFCp2uM0ABCWCIC+0/fODkhCUlAYGmox32jgDXqa+Ges NxmA== 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 x80si3579537pfe.393.2018.03.15.02.31.59; Thu, 15 Mar 2018 02:32:13 -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 S1751769AbeCOJan (ORCPT + 99 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(-) 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, }, }; -- 2.15.0