From patchwork Mon Oct 19 14:07:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fabien Parent X-Patchwork-Id: 11844447 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7ABEDC43457 for ; Mon, 19 Oct 2020 14:09:55 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0110822263 for ; Mon, 19 Oct 2020 14:09:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="rq6FqsmS"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=baylibre-com.20150623.gappssmtp.com header.i=@baylibre-com.20150623.gappssmtp.com header.b="xE13WF5n" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0110822263 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version: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=2+Ljdp9I9FFgAxtcK8nCz9yX2994Vn5yoExwv1r1fFI=; b=rq6FqsmSnxqizULt37mkNh7lQ 5e7FajrKnrf7tYpOuQ/1gG5ird/nep/Tdrr5/0bbPwbIYjyUC+bOxxvI9LdEPf4T0A4EYkOOxsMUG bvgYAqO4QlwEPc+fk27AtTC+LA2n9muMhQMM5aDv97QD/pt8DJEUxid2ukaRtIkxK1Xp9Q/ES/5ue gAkFKdT/jYwv3BCgsOvaypD7akvLmdjA27f0V30Atd8Yw1sHUqlP9v286n0TjGF58doEHUT8uUe+M 8P2YvpcivD6y+PQ79a6b4yBkI7hWYQvA74rCdweWVvHHr85a3elh2G6FZpdY959mOlk6BKqSR7+9m ykvakXmCg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kUVpO-0004Xh-Fs; Mon, 19 Oct 2020 14:07:58 +0000 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kUVog-0004Ds-Gj for linux-arm-kernel@lists.infradead.org; Mon, 19 Oct 2020 14:07:15 +0000 Received: by mail-wm1-x344.google.com with SMTP id j136so13046652wmj.2 for ; Mon, 19 Oct 2020 07:07:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GwShl5vcYJ2ELCoQvFguH/TiK9AVeY/s6bTP5Pdb/OE=; b=xE13WF5n40AD/I5qncMg6iY9giph35ZwITQx1RbGSZ7ei7V+dzM5985Xk94WGDDmyn 4dTmrco5XqsO9fKT34k6MoNQi3g1P6HF2ZBlYcWBmJf0/8z/W3nWU93W6lcKx1Q7/G5K TpDkI9l9YBI7/LckXf9o3hrpvuCF8wuT0TW4A4zdjXuqKvUf20UKckAskX1HD2oeuSaC 7p7TDb5aa+nGsXGcedRHzw9pOum/Jw1Hu7NRmO3vKFyCJCDoXNXecMR1kXiOGw9OL4h2 s0RR0u5D8Fktl6hlYNOBV/Ha6AjkYWFHpMFpwfyq2aSfcwTeA7kXD17oXV1q8bG4AtV4 S2KA== 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:mime-version:content-transfer-encoding; bh=GwShl5vcYJ2ELCoQvFguH/TiK9AVeY/s6bTP5Pdb/OE=; b=dRJZYuOrA4WGKadYAmAI1jtnXvmdEOLiW72H0ua6emQHGe5AmI3HCXW9pKdstmWwW5 LdHG1whf8uaBre/XugYNzsTYA01qpgjoMUFEDNf06AUS3jmeaGI8/xuGakqycguC7fny MkZBbvsKGxhXdrncUsLsU+X5W9TKdTpp2DOZ2t0YfHVQBCNWw3EZD4qKH+qtXH+xkRu9 J0fFPSKymar5vWGNCAbZDe8YB4fITlIbZot2IV5gWOxqrp3cNnCl3AZgXiv+nPZgPZKY +X6f7tCo1hOMoJf7QGlW/e3ElOwEcRTEakIO0F76NJLCjClbot/bbotT6IoR6d2A3zXx w/Bw== X-Gm-Message-State: AOAM530O5jVNNWbqfpb2+pZUzs1aKb8EHzVVeHB4rBso0kukk1M2mvG2 CVJPPZWxmtHkHD6ixj0olq/xVA== X-Google-Smtp-Source: ABdhPJxpM2Vpfq/yWVUrjZCVwJcLDDOlDB6L3VPyeuoS6mCAvlVk3i8/5xVMTBu1ryEroDcTs668ZQ== X-Received: by 2002:a1c:4e1a:: with SMTP id g26mr17880686wmh.98.1603116433088; Mon, 19 Oct 2020 07:07:13 -0700 (PDT) Received: from localhost.localdomain (26.167.185.81.rev.sfr.net. [81.185.167.26]) by smtp.gmail.com with ESMTPSA id a3sm114182wmb.46.2020.10.19.07.07.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Oct 2020 07:07:12 -0700 (PDT) From: Fabien Parent To: linux-mediatek@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-pwm@vger.kernel.org Subject: [PATCH 2/5] pwm: pwm-mediatek: always use bus clock Date: Mon, 19 Oct 2020 16:07:02 +0200 Message-Id: <20201019140705.1518822-3-fparent@baylibre.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201019140705.1518822-1-fparent@baylibre.com> References: <20201019140705.1518822-1-fparent@baylibre.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201019_100714_579494_356CB8FE X-CRM114-Status: GOOD ( 20.97 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: robh+dt@kernel.org, Fabien Parent , thierry.reding@gmail.com, u.kleine-koenig@pengutronix.de, matthias.bgg@gmail.com, lee.jones@linaro.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The MediaTek PWM IP can sometimes use the 26MHz source clock to generate the PWM signal, but the driver currently assumes that we always use the PWM bus clock to generate the PWM signal. This commit modifies the PWM driver in order to force the PWM IP to always use the bus clock as source clock. I do not have the datasheet of all the MediaTek SoC, so I don't know if the register to choose the source clk is present in all the SoCs or only in subset. As a consequence I made this change optional by using a platform data paremeter to says whether this register is supported or not. On all the SoC I don't have the datasheet (MT2712, MT7622, MT7623, MT7628, MT7629) I kept the behavior to be the same as before this change. Signed-off-by: Fabien Parent Reviewed-by: Matthias Brugger --- drivers/pwm/pwm-mediatek.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/pwm/pwm-mediatek.c b/drivers/pwm/pwm-mediatek.c index ab001ce55178..108881619aea 100644 --- a/drivers/pwm/pwm-mediatek.c +++ b/drivers/pwm/pwm-mediatek.c @@ -30,12 +30,14 @@ #define PWM45DWIDTH_FIXUP 0x30 #define PWMTHRES 0x30 #define PWM45THRES_FIXUP 0x34 +#define PWM_CK_26M_SEL 0x210 #define PWM_CLK_DIV_MAX 7 struct pwm_mediatek_of_data { unsigned int num_pwms; bool pwm45_fixup; + bool has_ck_26m_sel; }; /** @@ -132,6 +134,10 @@ static int pwm_mediatek_config(struct pwm_chip *chip, struct pwm_device *pwm, if (ret < 0) return ret; + /* Make sure we use the bus clock and not the 26MHz clock */ + if (pc->soc->has_ck_26m_sel) + writel(0, pc->regs + PWM_CK_26M_SEL); + /* Using resolution in picosecond gets accuracy higher */ resolution = (u64)NSEC_PER_SEC * 1000; do_div(resolution, clk_get_rate(pc->clk_pwms[pwm->hwpwm])); @@ -281,31 +287,37 @@ static int pwm_mediatek_remove(struct platform_device *pdev) static const struct pwm_mediatek_of_data mt2712_pwm_data = { .num_pwms = 8, .pwm45_fixup = false, + .has_ck_26m_sel = false, }; static const struct pwm_mediatek_of_data mt7622_pwm_data = { .num_pwms = 6, .pwm45_fixup = false, + .has_ck_26m_sel = false, }; static const struct pwm_mediatek_of_data mt7623_pwm_data = { .num_pwms = 5, .pwm45_fixup = true, + .has_ck_26m_sel = false, }; static const struct pwm_mediatek_of_data mt7628_pwm_data = { .num_pwms = 4, .pwm45_fixup = true, + .has_ck_26m_sel = false, }; static const struct pwm_mediatek_of_data mt7629_pwm_data = { .num_pwms = 1, .pwm45_fixup = false, + .has_ck_26m_sel = false, }; static const struct pwm_mediatek_of_data mt8516_pwm_data = { .num_pwms = 5, .pwm45_fixup = false, + .has_ck_26m_sel = true, }; static const struct of_device_id pwm_mediatek_of_match[] = {