From patchwork Mon Jul 11 08:18:08 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Weiqing Kong X-Patchwork-Id: 9223001 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 9159060572 for ; Mon, 11 Jul 2016 08:21:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 80D6C27569 for ; Mon, 11 Jul 2016 08:21:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7553927AC2; Mon, 11 Jul 2016 08:21:03 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0A37B27569 for ; Mon, 11 Jul 2016 08:21:03 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bMWSc-0000DQ-C3; Mon, 11 Jul 2016 08:21:02 +0000 Received: from [210.61.82.184] (helo=mailgw02.mediatek.com) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bMWSa-0008Vn-B9; Mon, 11 Jul 2016 08:21:01 +0000 Received: from mtkhts07.mediatek.inc [(172.21.101.69)] by mailgw02.mediatek.com (envelope-from ) (mhqrelay.mediatek.com ESMTP with TLS) with ESMTP id 1010495239; Mon, 11 Jul 2016 16:20:38 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkhts07.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 14.3.266.1; Mon, 11 Jul 2016 16:20:36 +0800 From: Weiqing Kong To: Thierry Reding , Mark Rutland , Matthias Brugger , Subject: [PATCH V2 2/3] pwm: Add MediaTek MT2701 display PWM driver support Date: Mon, 11 Jul 2016 16:18:08 +0800 Message-ID: <1468225089-28576-3-git-send-email-weiqing.kong@mediatek.com> X-Mailer: git-send-email 1.8.1.1.dirty In-Reply-To: <1468225089-28576-1-git-send-email-weiqing.kong@mediatek.com> References: <1468225089-28576-1-git-send-email-weiqing.kong@mediatek.com> MIME-Version: 1.0 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160711_012100_815331_6C716962 X-CRM114-Status: GOOD ( 22.52 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-pwm@vger.kernel.org, yh.huang@mediatek.com, Russell King , srv_heupstream@mediatek.com, Pawel Moll , Ian Campbell , erin.lo@mediatek.com, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Rob Herring , linux-mediatek@lists.infradead.org, Sascha Hauer , Kumar Gala , yt.shen@mediatek.com, yingjoe.chen@mediatek.com, eddie.huang@mediatek.com, linux-arm-kernel@lists.infradead.org Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Use the mtk_pwm_data struction to define different registers and add MT2701 specific register operations, such as MT2701 doesn't have commit register, needs to disable double buffer before writing register, and needs to select manual mode and use PWM_PERIOD/PWM_HIGH_WIDTH. Signed-off-by: Weiqing Kong --- drivers/pwm/pwm-mtk-disp.c | 99 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 80 insertions(+), 19 deletions(-) diff --git a/drivers/pwm/pwm-mtk-disp.c b/drivers/pwm/pwm-mtk-disp.c index 0ad3385..5eb1f6c 100644 --- a/drivers/pwm/pwm-mtk-disp.c +++ b/drivers/pwm/pwm-mtk-disp.c @@ -18,33 +18,45 @@ #include #include #include +#include #include #include #include #define DISP_PWM_EN 0x00 -#define PWM_ENABLE_MASK BIT(0) -#define DISP_PWM_COMMIT 0x08 -#define PWM_COMMIT_MASK BIT(0) +#define MT8173_PWM_COMMIT_MASK BIT(0) -#define DISP_PWM_CON_0 0x10 #define PWM_CLKDIV_SHIFT 16 #define PWM_CLKDIV_MAX 0x3ff #define PWM_CLKDIV_MASK (PWM_CLKDIV_MAX << PWM_CLKDIV_SHIFT) -#define DISP_PWM_CON_1 0x14 #define PWM_PERIOD_BIT_WIDTH 12 #define PWM_PERIOD_MASK ((1 << PWM_PERIOD_BIT_WIDTH) - 1) #define PWM_HIGH_WIDTH_SHIFT 16 #define PWM_HIGH_WIDTH_MASK (0x1fff << PWM_HIGH_WIDTH_SHIFT) +#define MT2701_PWM_MANUAL_SEL_MASK BIT(1) +#define MT2701_PWM_BLS_DEBUG 0xb0 +#define MT2701_PWM_BLS_DEBUG_MASK 0x3 + +struct mtk_pwm_data { + unsigned int bls_debug; + unsigned int enable_bit; + unsigned int con0; + unsigned int con0_sel; + unsigned int con1; + unsigned int commit_reg_offset; + bool have_commit_reg; +}; + struct mtk_disp_pwm { struct pwm_chip chip; struct clk *clk_main; struct clk *clk_mm; void __iomem *base; + const struct mtk_pwm_data *data; }; static inline struct mtk_disp_pwm *to_mtk_disp_pwm(struct pwm_chip *chip) @@ -106,12 +118,18 @@ static int mtk_disp_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, return err; } - mtk_disp_pwm_update_bits(mdp, DISP_PWM_CON_0, PWM_CLKDIV_MASK, + mtk_disp_pwm_update_bits(mdp, mdp->data->con0, + PWM_CLKDIV_MASK, clk_div << PWM_CLKDIV_SHIFT); - mtk_disp_pwm_update_bits(mdp, DISP_PWM_CON_1, - PWM_PERIOD_MASK | PWM_HIGH_WIDTH_MASK, value); - mtk_disp_pwm_update_bits(mdp, DISP_PWM_COMMIT, PWM_COMMIT_MASK, 1); - mtk_disp_pwm_update_bits(mdp, DISP_PWM_COMMIT, PWM_COMMIT_MASK, 0); + mtk_disp_pwm_update_bits(mdp, mdp->data->con1, + PWM_PERIOD_MASK | PWM_HIGH_WIDTH_MASK, + value); + if (mdp->data->have_commit_reg) { + mtk_disp_pwm_update_bits(mdp, mdp->data->commit_reg_offset, + MT8173_PWM_COMMIT_MASK, 0x1); + mtk_disp_pwm_update_bits(mdp, mdp->data->commit_reg_offset, + MT8173_PWM_COMMIT_MASK, 0x0); + } clk_disable(mdp->clk_mm); clk_disable(mdp->clk_main); @@ -134,7 +152,9 @@ static int mtk_disp_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm) return err; } - mtk_disp_pwm_update_bits(mdp, DISP_PWM_EN, PWM_ENABLE_MASK, 1); + mtk_disp_pwm_update_bits(mdp, DISP_PWM_EN, + mdp->data->enable_bit, + mdp->data->enable_bit); return 0; } @@ -143,7 +163,8 @@ static void mtk_disp_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm) { struct mtk_disp_pwm *mdp = to_mtk_disp_pwm(chip); - mtk_disp_pwm_update_bits(mdp, DISP_PWM_EN, PWM_ENABLE_MASK, 0); + mtk_disp_pwm_update_bits(mdp, DISP_PWM_EN, + mdp->data->enable_bit, 0x0); clk_disable(mdp->clk_mm); clk_disable(mdp->clk_main); @@ -156,12 +177,45 @@ static const struct pwm_ops mtk_disp_pwm_ops = { .owner = THIS_MODULE, }; +static const struct mtk_pwm_data mt8173_pwm_data = { + .bls_debug = 0x0, + .enable_bit = BIT(0), + .con0 = 0x10, + .con0_sel = 0x0, + .con1 = 0x14, + .commit_reg_offset = 0x8, + .have_commit_reg = true, +}; + +static const struct mtk_pwm_data mt2701_pwm_data = { + .bls_debug = 0x3, + .enable_bit = BIT(16), + .con0 = 0xa8, + .con0_sel = 0x2, + .con1 = 0xac, + .commit_reg_offset = 0x0, + .have_commit_reg = false, +}; + +static const struct of_device_id mtk_disp_pwm_of_match[] = { + { .compatible = "mediatek,mt2701-disp-pwm", .data = &mt2701_pwm_data}, + { .compatible = "mediatek,mt6595-disp-pwm", .data = &mt8173_pwm_data}, + { .compatible = "mediatek,mt8173-disp-pwm", .data = &mt8173_pwm_data}, + { } +}; +MODULE_DEVICE_TABLE(of, mtk_disp_pwm_of_match); + static int mtk_disp_pwm_probe(struct platform_device *pdev) { + const struct of_device_id *id; struct mtk_disp_pwm *mdp; struct resource *r; int ret; + id = of_match_device(mtk_disp_pwm_of_match, &pdev->dev); + if (!id) + return -EINVAL; + mdp = devm_kzalloc(&pdev->dev, sizeof(*mdp), GFP_KERNEL); if (!mdp) return -ENOMEM; @@ -191,6 +245,7 @@ static int mtk_disp_pwm_probe(struct platform_device *pdev) mdp->chip.ops = &mtk_disp_pwm_ops; mdp->chip.base = -1; mdp->chip.npwm = 1; + mdp->data = id->data; ret = pwmchip_add(&mdp->chip); if (ret < 0) { @@ -200,6 +255,19 @@ static int mtk_disp_pwm_probe(struct platform_device *pdev) platform_set_drvdata(pdev, mdp); + /* + * For MT2701, disable double buffer before writing register + * and select manual mode and use PWM_PERIOD/PWM_HIGH_WIDTH. + */ + if (!mdp->data->have_commit_reg) { + mtk_disp_pwm_update_bits(mdp, MT2701_PWM_BLS_DEBUG, + MT2701_PWM_BLS_DEBUG_MASK, + mdp->data->bls_debug); + mtk_disp_pwm_update_bits(mdp, mdp->data->con0, + MT2701_PWM_MANUAL_SEL_MASK, + mdp->data->con0_sel); + } + return 0; disable_clk_mm: @@ -221,13 +289,6 @@ static int mtk_disp_pwm_remove(struct platform_device *pdev) return ret; } -static const struct of_device_id mtk_disp_pwm_of_match[] = { - { .compatible = "mediatek,mt8173-disp-pwm" }, - { .compatible = "mediatek,mt6595-disp-pwm" }, - { } -}; -MODULE_DEVICE_TABLE(of, mtk_disp_pwm_of_match); - static struct platform_driver mtk_disp_pwm_driver = { .driver = { .name = "mediatek-disp-pwm",