From patchwork Tue Apr 11 19:22:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 13208172 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A5523C77B6F for ; Tue, 11 Apr 2023 19:27:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:References:Cc:To:From: Subject:MIME-Version:Date:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=FKbobng3SCldSckE8kTsVEbUjNtlU6r08TkrBBdWjwE=; b=TEP4ry0LcqD4D5 As7XPdttYEvH+E3hmld7n6pu0nVRXMK/J2hz+bu03ODW5iGZdMHcDfdQIlB7hmyJxhStbRFOe0vYh kKKRt+XHhSQ0J4AsplX03npL874e98jWFofYrvemU1QYwhjwbeotszi89N3Rb6CYd4s0DdghSPYng P4MFR/0BWnhsLEEaUSyPj0OUfYdG33krT82I6cLptvEXsamVyBdYo1CaSpWDA6MtcCw/u4qibefSm 7cso3Dq6zOMH1ZN8AJ3H961kVGqF4TZBkYkWRS9mXVI82LCEI9SrZcfQqrmXDbB3Ki/SJR41mcZ30 7XHl2rBGN5YTwp25da4g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pmJdV-000wQu-1I; Tue, 11 Apr 2023 19:26:37 +0000 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pmJdS-000wPu-1w; Tue, 11 Apr 2023 19:26:35 +0000 Received: by mail-wr1-x436.google.com with SMTP id v29so8671432wra.13; Tue, 11 Apr 2023 12:26:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1681241192; x=1683833192; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=OxWZ3lc7cHgbqUIVxG2SqSCxtmOZkFcO8gtsNb4LbME=; b=kkHeH97+ArBF9/0zQysc+2G8LTCn28AvF+hDw4OwXHmtvpeaM4fTSo8zxfu95O/lCy dWrQE6QLdS+mnXvTlIy4dtXd9d3BWY9NxW5vnUxbjrKDhuna9QoiwfqbUQQU+nkNo3fo bJGFKe3cPzhtPR5YyNTQ41H9G/IuJZ1TNyDRRnT7DucdPVA+lsKBhzSjcrpfCLF056Q9 oz3CzwUmV/FOxNc8bYKDx3XBF7EZvIvwRBCoYtnhFOOVEikmKIxpDs/l2TIfOks/dPkS Sqt+77if3p4ms5pO8SGVAPMm3sU0ixv1mLeOG3A8YCZLPLpGfbcO0+qZB0uChJV93aV7 ytWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681241192; x=1683833192; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=OxWZ3lc7cHgbqUIVxG2SqSCxtmOZkFcO8gtsNb4LbME=; b=GDlRv37QMEs0BgygC4zQ3iwdqEmnPxns58aK5tm8oMoqxx1Kz1CS5Q6b332jPvki/y dclOXqyzx7u0pAfzrKREfnk2ANLP9+aJFS7dJcRi1n1BjQpEA7EGGtARjhAMbwOQmABz k+wrELfLB78IMBB2oc9ePgykEW3iBEZaQ30CzwduAA0FQQBBNJA/frhdOGyQCmSrwwIR bwnTbapCtFSUqZiVSKDd4Lt4c6m9WIvQ7mQu3G6cApgmVL1BsXvwYG2tfJEqtefAs/L0 bTI4o3rQrZAnNSV0YYlWab7Ee9Ok3U4O4uuaELmzorNgJHgXpUOOTZGZIa92YzaPaafJ c72Q== X-Gm-Message-State: AAQBX9cpONbdKh03enfOTdzeF1I/om9Zba0GY81QNG9I5JHdBoUDiP9O eP8Bic4e5wD5odFo9kI9Qq8= X-Google-Smtp-Source: AKy350Y8UGQNTb1QdJvRPlNvRx/fVmbzC3WA4YTp6Q2H2MzZRPxG1pqPqaNj8p9w7JNf4wE3vQJh3Q== X-Received: by 2002:adf:e4c1:0:b0:2f4:fcd:98d2 with SMTP id v1-20020adfe4c1000000b002f40fcd98d2mr585544wrm.31.1681241191637; Tue, 11 Apr 2023 12:26:31 -0700 (PDT) Received: from ?IPV6:2a01:c23:c4bb:c200:90e3:4731:63e4:d333? (dynamic-2a01-0c23-c4bb-c200-90e3-4731-63e4-d333.c23.pool.telefonica.de. [2a01:c23:c4bb:c200:90e3:4731:63e4:d333]) by smtp.googlemail.com with ESMTPSA id h7-20020a05600c314700b003f07ef4e3e0sm4158098wmo.0.2023.04.11.12.26.30 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 11 Apr 2023 12:26:31 -0700 (PDT) Message-ID: <2760498e-23a6-f787-bac2-0460566a995d@gmail.com> Date: Tue, 11 Apr 2023 21:22:33 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.9.1 Subject: [PATCH v2 1/4] pwm: meson: switch to using struct clk_parent_data for mux parents Content-Language: en-US From: Heiner Kallweit To: Jerome Brunet , Martin Blumenstingl , Neil Armstrong , Kevin Hilman , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , "thierry.reding@gmail.com" Cc: "linux-arm-kernel@lists.infradead.org" , "open list:ARM/Amlogic Meson..." , linux-pwm@vger.kernel.org References: <0f087629-810d-f0e0-bf0b-05ca5defc16d@gmail.com> In-Reply-To: <0f087629-810d-f0e0-bf0b-05ca5defc16d@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230411_122634_643847_FEAF7AAE X-CRM114-Status: GOOD ( 11.88 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org We'll use struct clk_parent_data for mux/div/gate initialization in the follow-up patches. As a first step switch the mux from using parent_names to clk_parent_data. Suggested-by: Martin Blumenstingl Signed-off-by: Heiner Kallweit --- drivers/pwm/pwm-meson.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/pwm/pwm-meson.c b/drivers/pwm/pwm-meson.c index 4e5605c9d..52a2104f0 100644 --- a/drivers/pwm/pwm-meson.c +++ b/drivers/pwm/pwm-meson.c @@ -61,6 +61,7 @@ #define MISC_A_EN BIT(0) #define MESON_NUM_PWMS 2 +#define MESON_MAX_MUX_PARENTS 4 static struct meson_pwm_channel_data { u8 reg_offset; @@ -485,20 +486,27 @@ MODULE_DEVICE_TABLE(of, meson_pwm_matches); static int meson_pwm_init_channels(struct meson_pwm *meson) { struct device *dev = meson->chip.dev; - struct clk_init_data init; unsigned int i; char name[255]; int err; for (i = 0; i < meson->chip.npwm; i++) { struct meson_pwm_channel *channel = &meson->channels[i]; + struct clk_parent_data mux_parent_data[MESON_MAX_MUX_PARENTS] = {}; + struct clk_init_data init = {}; + int j; snprintf(name, sizeof(name), "%s#mux%u", dev_name(dev), i); + for (j = 0; j < meson->data->num_parents; j++) { + mux_parent_data[j].index = -1; + mux_parent_data[j].name = meson->data->parent_names[j]; + } + init.name = name; init.ops = &clk_mux_ops; init.flags = 0; - init.parent_names = meson->data->parent_names; + init.parent_data = mux_parent_data; init.num_parents = meson->data->num_parents; channel->mux.reg = meson->base + REG_MISC_AB; From patchwork Tue Apr 11 19:23:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 13208170 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F1781C7619A for ; Tue, 11 Apr 2023 19:27:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:References:Cc:To:From: Subject:MIME-Version:Date:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=R5ZCyZCP1oCMI7aKManbgePd5mTU68QyZZbWRzwL8C0=; b=GVGXMOPkioiHFj iHOvoAgvPlSsYL4MwdZ22Egd2hqndWSRtUnOVxFyI/zEpopG6ARVrqlrGrAsxG6hmNnAqGD1jMw+B dXU9e7By2f4Osng9cA75JS+Dv4Ib9nxZoZe58GNHyIZunEUjEMT2fQBeVwc1k3O2N49ZdM40H6z6/ 3NeK4nIUbLdCWP+6PDhgMxu9PUoe2/0vKmfjzEMWgl9mfYLItlZLhbPKC7ct6FkxXEG/WVWFcT4Hp 0c10BGSZ/k39p/TLLqLhRONcDXPawB8sKS5jT4MBwfwu19+lZN9591yFH1iS6C8fJ0Ale/W2MAIbt PnbbXHGnWm877iB60f9A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pmJdY-000wSa-2c; Tue, 11 Apr 2023 19:26:40 +0000 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pmJdU-000wPx-2t; Tue, 11 Apr 2023 19:26:38 +0000 Received: by mail-wr1-x42c.google.com with SMTP id l18so8592889wrb.9; Tue, 11 Apr 2023 12:26:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681241193; x=1683833193; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=+z8YpC2eOejAdzfjBHEwDRl9Fr5MgCbUHcvYTd3HmNY=; b=aoQupWLGNf4cLI0OgUlJMqZu0kloECrUcXOvi3XOP8Psft1XBcIYdvkJ6U8S2WRfXW 43V6+2lWgYbQ8Oy96dCdWQAaACs1o0LBbLMzErqucQtDKLzai9Xmo1vnviHDlZ7VKFFa Y/WGHSV7Df+9d8jeFsXiY6SY9aiz9p29p+FgwfyjWTqBnbo/pegKw4nccSd0PFtlRCcH eS5cH8ZIjrddgo9zFNTFIFoIdRmVT7TJ9JLTt8NkJ8pXwnmA/5bM2dqJ2krGLc8K+UTz PVMhe1rqQ5De5sVoh3nZtSuTeiWs4FpDUfiWARX7XC8/vcK+p1oc3daMT1g6QiBUvtJj qKIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681241193; x=1683833193; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=+z8YpC2eOejAdzfjBHEwDRl9Fr5MgCbUHcvYTd3HmNY=; b=WFU/IRjQLlcnHX703r5DnmDzUenj56h4VPPxF192G+uSE63tBqh0pnL/oFLSz1zKHm 8G6K1twevWrdh1t3++ZTGhz/4vuA5m9r0h6WJ1WZHqBwCFTZRvL5IkFg19QzGg9YvNGs G1580g18l9z3drMkMNDjpQ103gsk9tKwAZS+UymRpimBsAmt+ri2FtDQpkHuKB0xLyth z1ZvNJl0tlkkD9lRVtWxHlZ+6eW15/N9uWmS6EgpnnfWqx13UbiP9iVgJddGoR2tlVgq SJOVzx5w+J1Twtpfsd/yb3mnjknO3pauEmy5uM6i9oRPOJtX2VjVWj/rsGws1XVc49Z9 5O+w== X-Gm-Message-State: AAQBX9eKUNMY7F8Gw9P2wR5u+LWH/AR6WYdvHqDfXdYXluh6A3kmN1Mu UV9VoJf1CQcZweF6/GTZays= X-Google-Smtp-Source: AKy350bOAxztOgN2CwmM2wYn4R8YGgKVKJjv7V726pbvbhBozS+/RaKpacGtWcfjjjjtdkWGsAGSzQ== X-Received: by 2002:adf:f146:0:b0:2cf:e3d0:2a43 with SMTP id y6-20020adff146000000b002cfe3d02a43mr169952wro.4.1681241193048; Tue, 11 Apr 2023 12:26:33 -0700 (PDT) Received: from ?IPV6:2a01:c23:c4bb:c200:90e3:4731:63e4:d333? (dynamic-2a01-0c23-c4bb-c200-90e3-4731-63e4-d333.c23.pool.telefonica.de. [2a01:c23:c4bb:c200:90e3:4731:63e4:d333]) by smtp.googlemail.com with ESMTPSA id fm7-20020a05600c0c0700b003f063a709dbsm3898839wmb.2.2023.04.11.12.26.32 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 11 Apr 2023 12:26:32 -0700 (PDT) Message-ID: Date: Tue, 11 Apr 2023 21:23:29 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.9.1 Subject: [PATCH v2 2/4] pwm: meson: don't use hdmi/video clock as mux parent Content-Language: en-US From: Heiner Kallweit To: Jerome Brunet , Martin Blumenstingl , Neil Armstrong , Kevin Hilman , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , "thierry.reding@gmail.com" Cc: "linux-arm-kernel@lists.infradead.org" , "open list:ARM/Amlogic Meson..." , linux-pwm@vger.kernel.org References: <0f087629-810d-f0e0-bf0b-05ca5defc16d@gmail.com> In-Reply-To: <0f087629-810d-f0e0-bf0b-05ca5defc16d@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230411_122636_932617_28620983 X-CRM114-Status: GOOD ( 11.13 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org meson_vclk may change the rate of the video clock. Therefore better don't use it as pwm mux parent. After removing this clock from the parent list pwm_gxbb_data and pwm_g12a_ee_data are the same as pwm_meson8b_data. So we can remove them. Reported-by: Martin Blumenstingl Signed-off-by: Heiner Kallweit --- drivers/pwm/pwm-meson.c | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/drivers/pwm/pwm-meson.c b/drivers/pwm/pwm-meson.c index 52a2104f0..931cf14ca 100644 --- a/drivers/pwm/pwm-meson.c +++ b/drivers/pwm/pwm-meson.c @@ -371,7 +371,7 @@ static const struct pwm_ops meson_pwm_ops = { }; static const char * const pwm_meson8b_parent_names[] = { - "xtal", "vid_pll", "fclk_div4", "fclk_div3" + "xtal", NULL, "fclk_div4", "fclk_div3" }; static const struct meson_pwm_data pwm_meson8b_data = { @@ -379,15 +379,6 @@ static const struct meson_pwm_data pwm_meson8b_data = { .num_parents = ARRAY_SIZE(pwm_meson8b_parent_names), }; -static const char * const pwm_gxbb_parent_names[] = { - "xtal", "hdmi_pll", "fclk_div4", "fclk_div3" -}; - -static const struct meson_pwm_data pwm_gxbb_data = { - .parent_names = pwm_gxbb_parent_names, - .num_parents = ARRAY_SIZE(pwm_gxbb_parent_names), -}; - /* * Only the 2 first inputs of the GXBB AO PWMs are valid * The last 2 are grounded @@ -437,15 +428,6 @@ static const struct meson_pwm_data pwm_g12a_ao_cd_data = { .num_parents = ARRAY_SIZE(pwm_g12a_ao_cd_parent_names), }; -static const char * const pwm_g12a_ee_parent_names[] = { - "xtal", "hdmi_pll", "fclk_div4", "fclk_div3" -}; - -static const struct meson_pwm_data pwm_g12a_ee_data = { - .parent_names = pwm_g12a_ee_parent_names, - .num_parents = ARRAY_SIZE(pwm_g12a_ee_parent_names), -}; - static const struct of_device_id meson_pwm_matches[] = { { .compatible = "amlogic,meson8b-pwm", @@ -453,7 +435,7 @@ static const struct of_device_id meson_pwm_matches[] = { }, { .compatible = "amlogic,meson-gxbb-pwm", - .data = &pwm_gxbb_data + .data = &pwm_meson8b_data }, { .compatible = "amlogic,meson-gxbb-ao-pwm", @@ -469,7 +451,7 @@ static const struct of_device_id meson_pwm_matches[] = { }, { .compatible = "amlogic,meson-g12a-ee-pwm", - .data = &pwm_g12a_ee_data + .data = &pwm_meson8b_data }, { .compatible = "amlogic,meson-g12a-ao-pwm-ab", From patchwork Tue Apr 11 19:24:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 13208171 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5AC34C76196 for ; Tue, 11 Apr 2023 19:27:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:References:Cc:To:From: Subject:MIME-Version:Date:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=pMT3bGSXpTJbK2CwaLzncBey7ziD7t7XfQU2WBdJppY=; b=ieJc3AeDE7iXjW PtV+4f0StrSwdiXjIzJJjm8faJrgWODvjhmAYMz2WHn5PZCjbnCIKT1WIOJp4mmUaiajdDjyvrjJu z3NckucHMzrLMC+eXBXADpqMjRFF4NirvDqMcvJZsZxw8C49vpiRor35xteOM0bSpzRfQ2l52mF5m 9bKyqzvEzMIKCJAzcOksMm6SycJqYslCNCtEUvkf7WpICFy976WqV4gBO5tyCG2cCcFhNwiP8wIil 2HSniEMzbldC8zK5p2ukSD7B/B4X5w9do6oBlXVU3urjJvWMTMppRdl3yVyhjn2OI+WVlHa2OMGW+ bq8Dof6eieXDraxoEkbg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pmJda-000wTS-0r; Tue, 11 Apr 2023 19:26:42 +0000 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pmJdW-000wQP-18; Tue, 11 Apr 2023 19:26:39 +0000 Received: by mail-wm1-x32f.google.com with SMTP id l16so4731973wms.1; Tue, 11 Apr 2023 12:26:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681241194; x=1683833194; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=2IQ1M5BMFas/wX1eONZkvXXJkqyMTMp78nC08EBVyZc=; b=gIWTuhJlpBJDlZUymscknkzviuToH7Nnqiv7YnRTpAIhgf2PxOAEzAVq49IjAl2Ov8 MuS3p6BtX/2etmDJbU2vcPkuVi9Bq/UGo59omDZTrG7177VGBgj0YOVv0dWl0guig3of 0HEc9ph9i2WxEB3pjGZsbk+34tD6BZQalRWkFpXR8zqS0wUUL4ymMd0ah3jPlzdGEwD+ /oDnd9cVwzGxLJFa44M/+GaJbZj7vMQOWuTzyzXhNKkPs6j7oycdEEWoTFibawiMK3Ph YvwnYba6aEuceTVlBmvDJhgmddYuLrVXUVW4rW+JDnPPzu2chTQQz08BoXiO1dr/4F6A XIUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681241194; x=1683833194; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=2IQ1M5BMFas/wX1eONZkvXXJkqyMTMp78nC08EBVyZc=; b=AANWnks0tC1OFUDrtB4iCi/0v/quXVl/aNor9U+EcTjJqMmZ3WxhDrcPf6L90XF0Pt StXTVg/0DteoGgkSjkgz4TiQsBTkdy8bGsweVHeHIE0QKA4Xh18dgby8T+O/w9yaUB5q FeK+21+Ah9ULUSPzg6fB7tVpRv9vljcbucsTaeL7Or9lsguMKp7YnFrLNuEX43ZSATk0 a/f6kDmVePTBD3mgKOEnhymHi8mI4lb/q+zMeIlHYCSWoW8MUUW1KbQnz5XEgQDqzoOJ 7BnRqAjksAXqFOgC2y5R2xvW/IeCw4HIgDd5oR0P2GIqVuBquqsg6uEmoG0IPvvBjOqT 9Rqw== X-Gm-Message-State: AAQBX9dsvwU+NQF0poNABIGkZPgEJjuVDk2XWJxHO3+0Wg+nRSGs+KiM ffSQzi2GvWVFAUvHzdsp4PY= X-Google-Smtp-Source: AKy350aFVdr29HDi8szE4pmFLAcT6lc7CfvJUtVkQOa5yHVWxDcOsRLrPcV/zDvURqNbUqoYWWiKjQ== X-Received: by 2002:a05:600c:2214:b0:3eb:2e1e:beae with SMTP id z20-20020a05600c221400b003eb2e1ebeaemr7590680wml.25.1681241194561; Tue, 11 Apr 2023 12:26:34 -0700 (PDT) Received: from ?IPV6:2a01:c23:c4bb:c200:90e3:4731:63e4:d333? (dynamic-2a01-0c23-c4bb-c200-90e3-4731-63e4-d333.c23.pool.telefonica.de. [2a01:c23:c4bb:c200:90e3:4731:63e4:d333]) by smtp.googlemail.com with ESMTPSA id s6-20020a5d4ec6000000b002efb6e0c495sm10593820wrv.91.2023.04.11.12.26.33 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 11 Apr 2023 12:26:34 -0700 (PDT) Message-ID: Date: Tue, 11 Apr 2023 21:24:40 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.9.1 Subject: [PATCH v2 3/4] pwm: meson: change clk/pwm gate from mask to bit Content-Language: en-US From: Heiner Kallweit To: Jerome Brunet , Martin Blumenstingl , Neil Armstrong , Kevin Hilman , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , "thierry.reding@gmail.com" Cc: "linux-arm-kernel@lists.infradead.org" , "open list:ARM/Amlogic Meson..." , linux-pwm@vger.kernel.org References: <0f087629-810d-f0e0-bf0b-05ca5defc16d@gmail.com> In-Reply-To: <0f087629-810d-f0e0-bf0b-05ca5defc16d@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230411_122638_402594_26FF15A7 X-CRM114-Status: GOOD ( 10.45 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Change single-bit values from mask to bit. This facilitates CCF initialization for the clock gate in a follow-up patch. Signed-off-by: Heiner Kallweit --- drivers/pwm/pwm-meson.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/drivers/pwm/pwm-meson.c b/drivers/pwm/pwm-meson.c index 931cf14ca..f7595f81c 100644 --- a/drivers/pwm/pwm-meson.c +++ b/drivers/pwm/pwm-meson.c @@ -49,16 +49,16 @@ #define PWM_HIGH_MASK GENMASK(31, 16) #define REG_MISC_AB 0x8 -#define MISC_B_CLK_EN BIT(23) -#define MISC_A_CLK_EN BIT(15) +#define MISC_B_CLK_EN 23 +#define MISC_A_CLK_EN 15 #define MISC_CLK_DIV_MASK 0x7f #define MISC_B_CLK_DIV_SHIFT 16 #define MISC_A_CLK_DIV_SHIFT 8 #define MISC_B_CLK_SEL_SHIFT 6 #define MISC_A_CLK_SEL_SHIFT 4 #define MISC_CLK_SEL_MASK 0x3 -#define MISC_B_EN BIT(1) -#define MISC_A_EN BIT(0) +#define MISC_B_EN 1 +#define MISC_A_EN 0 #define MESON_NUM_PWMS 2 #define MESON_MAX_MUX_PARENTS 4 @@ -67,22 +67,22 @@ static struct meson_pwm_channel_data { u8 reg_offset; u8 clk_sel_shift; u8 clk_div_shift; - u32 clk_en_mask; - u32 pwm_en_mask; + u8 clk_en_bit; + u8 pwm_en_bit; } meson_pwm_per_channel_data[MESON_NUM_PWMS] = { { .reg_offset = REG_PWM_A, .clk_sel_shift = MISC_A_CLK_SEL_SHIFT, .clk_div_shift = MISC_A_CLK_DIV_SHIFT, - .clk_en_mask = MISC_A_CLK_EN, - .pwm_en_mask = MISC_A_EN, + .clk_en_bit = MISC_A_CLK_EN, + .pwm_en_bit = MISC_A_EN, }, { .reg_offset = REG_PWM_B, .clk_sel_shift = MISC_B_CLK_SEL_SHIFT, .clk_div_shift = MISC_B_CLK_DIV_SHIFT, - .clk_en_mask = MISC_B_CLK_EN, - .pwm_en_mask = MISC_B_EN, + .clk_en_bit = MISC_B_CLK_EN, + .pwm_en_bit = MISC_B_EN, } }; @@ -231,7 +231,7 @@ static void meson_pwm_enable(struct meson_pwm *meson, struct pwm_device *pwm) value = readl(meson->base + REG_MISC_AB); value &= ~(MISC_CLK_DIV_MASK << channel_data->clk_div_shift); value |= channel->pre_div << channel_data->clk_div_shift; - value |= channel_data->clk_en_mask; + value |= BIT(channel_data->clk_en_bit); writel(value, meson->base + REG_MISC_AB); value = FIELD_PREP(PWM_HIGH_MASK, channel->hi) | @@ -239,7 +239,7 @@ static void meson_pwm_enable(struct meson_pwm *meson, struct pwm_device *pwm) writel(value, meson->base + channel_data->reg_offset); value = readl(meson->base + REG_MISC_AB); - value |= channel_data->pwm_en_mask; + value |= BIT(channel_data->pwm_en_bit); writel(value, meson->base + REG_MISC_AB); spin_unlock_irqrestore(&meson->lock, flags); @@ -253,7 +253,7 @@ static void meson_pwm_disable(struct meson_pwm *meson, struct pwm_device *pwm) spin_lock_irqsave(&meson->lock, flags); value = readl(meson->base + REG_MISC_AB); - value &= ~meson_pwm_per_channel_data[pwm->hwpwm].pwm_en_mask; + value &= ~BIT(meson_pwm_per_channel_data[pwm->hwpwm].pwm_en_bit); writel(value, meson->base + REG_MISC_AB); spin_unlock_irqrestore(&meson->lock, flags); @@ -335,7 +335,7 @@ static int meson_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm, value = readl(meson->base + REG_MISC_AB); - tmp = channel_data->pwm_en_mask | channel_data->clk_en_mask; + tmp = BIT(channel_data->pwm_en_bit) | BIT(channel_data->clk_en_bit); state->enabled = (value & tmp) == tmp; tmp = value >> channel_data->clk_div_shift; From patchwork Tue Apr 11 19:26:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 13208173 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A3178C76196 for ; Tue, 11 Apr 2023 19:27:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:References:Cc:To:From: Subject:MIME-Version:Date:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Z32G204WdyKXohjOAP3mT/Kg/HcwQXjafwYCWpqGGoI=; b=Y3JiMCziWzSdGJ mznzzaWSxOQGLs7NOGf42cADCl4NiCQquAb2SlgrZqN8i+gpO70nc1uOgQ+PlGNbWOxz0nKR5aSPM CIo4POzjM4AqpoqVQ4ghz/2zjGvQMJm2wpHpjYum2IFSSV8Tttj5IJnEeEwAT+/RPaPtiCc8ykm0U LsbQSOKofOQACHK4h70RoHFkd1CiaoZTPChJj/9E1C2M4j4fPokXlw+P5+BGwh0z1ShYQ1mjAyNuY HiU3Q/nQR2f+26o57Nlv2PhPGiGDahKrGijwHDAIHFxELHyLXQbpqW3DrSwGU9kr8h/Cnt/DqwKrN fQ1WVeq2tBcmHT8FRJgA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pmJdf-000wVp-1b; Tue, 11 Apr 2023 19:26:47 +0000 Received: from mail-wr1-x435.google.com ([2a00:1450:4864:20::435]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pmJdX-000wQg-1X; Tue, 11 Apr 2023 19:26:41 +0000 Received: by mail-wr1-x435.google.com with SMTP id e22so8567849wra.6; Tue, 11 Apr 2023 12:26:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1681241196; x=1683833196; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=jjTcv9ISBL6Oz86Z5Q8IZbwq6mT5uF1034ER6v+8wcw=; b=m9BGxS/YDtb/FnmThK/9ZqChjjc2a9+h9YYyTZ44iz+tMec+IA+EiIIJlT/QhyDHQ+ 2Ywx6MzCG+o/+y5951RRgMPD69IEC5xx5Wnz9sz39k2w9Zp7kuDbN+fV3HiSAYrNlZ53 Bn3RggjCEnlt1An/CVi5/uuuunGpSgWsg6PFQs5VEvCaKbNkZBq2bjskADJ4k7tQKLgp O3SLFBKwG322xZCThPphSHGIUs+o7jQDA5Q8Y8rTXpSueV2k/sMW/PeIxZmhUCcgAza3 khZsxPl5wbgHGh8HJXsDqDMW6JsVOW0O7xbgh4DpPTdiSykiIvenwHYcq+DjU0vPZKdv cMHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681241196; x=1683833196; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=jjTcv9ISBL6Oz86Z5Q8IZbwq6mT5uF1034ER6v+8wcw=; b=XmI9OGHYvxq4tdM4vZolcVQsnLb8ze7wNaCqGkRRABSQ5PnGl+T6r4NuNFKyLFLkXv /9Eb5WY5p1E8gruf62cK0R7fDEYJ34XYyD8a4gWfTlk9yzWE7e9WLZ2p+GUXM138aIFd drlde8epwkg3bvuBBJ2v/nJfZPzv+//M58hbp//RXOXMETvuvu6pTbvprSf2LcuTMX24 NqLZ0MAFbtX9Ly1AUjku6JD0Vs+gBAzOsp+/6WFM1EnPxc9JtvZcj6mDl0ujhOD3Og19 y08W6PwRFGCwzVBCPZi6VOQgBI1AcRXQIv8QcWzp3a5f2fareILQ6hwAr4t+uDniSkb7 WQGQ== X-Gm-Message-State: AAQBX9deCTGs5EYFkpjAwAkzUH22sb6HE5vsozrWI6pWRi4cP3tjdks8 IHf+hb3Bh9V/fN8TnA04NZI= X-Google-Smtp-Source: AKy350YuZ8cLZf4VKnQpd/KyyFO/R+p01/xclXqXeiQ96OgqauxuC30NN55OTjySPKJUigd8eHsL9g== X-Received: by 2002:a5d:464b:0:b0:2f2:4790:fccc with SMTP id j11-20020a5d464b000000b002f24790fcccmr4236838wrs.46.1681241195862; Tue, 11 Apr 2023 12:26:35 -0700 (PDT) Received: from ?IPV6:2a01:c23:c4bb:c200:90e3:4731:63e4:d333? (dynamic-2a01-0c23-c4bb-c200-90e3-4731-63e4-d333.c23.pool.telefonica.de. [2a01:c23:c4bb:c200:90e3:4731:63e4:d333]) by smtp.googlemail.com with ESMTPSA id r5-20020adfce85000000b002c54c9bd71fsm15236003wrn.93.2023.04.11.12.26.35 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 11 Apr 2023 12:26:35 -0700 (PDT) Message-ID: <05e3b9de-ee38-97b6-7f39-5b6f7de1674f@gmail.com> Date: Tue, 11 Apr 2023 21:26:08 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.9.1 Subject: [PATCH v2 4/4] pwm: meson: make full use of common clock framework Content-Language: en-US From: Heiner Kallweit To: Jerome Brunet , Martin Blumenstingl , Neil Armstrong , Kevin Hilman , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , "thierry.reding@gmail.com" Cc: "linux-arm-kernel@lists.infradead.org" , "open list:ARM/Amlogic Meson..." , linux-pwm@vger.kernel.org References: <0f087629-810d-f0e0-bf0b-05ca5defc16d@gmail.com> In-Reply-To: <0f087629-810d-f0e0-bf0b-05ca5defc16d@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230411_122639_516664_D645560E X-CRM114-Status: GOOD ( 31.28 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Newer versions of the PWM block use a core clock with external mux, divider, and gate. These components either don't exist any longer in the PWM block, or they are bypassed. To minimize needed changes for supporting the new version, the internal divider and gate should be handled by CCF too. I didn't see a good way to split the patch, therefore it's somewhat bigger. What it does: - The internal mux is handled by CCF already. Register also internal divider and gate with CCF, so that we have one representation of the input clock: [mux] parent of [divider] parent of [gate] - Now that CCF selects an appropriate mux parent, we don't need the DT-provided default parent any longer. Accordingly we can also omit setting the mux parent directly in the driver. - Instead of manually handling the pre-div divider value, let CCF set the input clock. Targeted input clock frequency is 0xffff * 1/period for best precision. - For the "inverted pwm disabled" scenario target an input clock frequency of 1GHz. This ensures that the remaining low pulses have minimum length. I don't have hw with the old PWM block, therefore I couldn't test this patch. With the not yet included extension for the new PWM block (channel->clock directly coming from get_clk(external_clk)) I didn't notice any problem. My system uses PWM for the CPU voltage regulator and for the SDIO 32kHz clock. Note: The clock gate in the old PWM block is permanently disabled. This seems to indicate that it's not used by the new PWM block. Signed-off-by: Heiner Kallweit --- Changes to RFT/RFC version: - use parent_hws instead of parent_names for div/gate clock - use devm_clk_hw_register where the struct clk * returned by devm_clk_register isn't needed v2: - add patch 1 - add patch 3 - switch to using clk_parent_data in all relevant places --- drivers/pwm/pwm-meson.c | 134 +++++++++++++++++++++++----------------- 1 file changed, 76 insertions(+), 58 deletions(-) diff --git a/drivers/pwm/pwm-meson.c b/drivers/pwm/pwm-meson.c index f7595f81c..ec9c82e48 100644 --- a/drivers/pwm/pwm-meson.c +++ b/drivers/pwm/pwm-meson.c @@ -51,7 +51,7 @@ #define REG_MISC_AB 0x8 #define MISC_B_CLK_EN 23 #define MISC_A_CLK_EN 15 -#define MISC_CLK_DIV_MASK 0x7f +#define MISC_CLK_DIV_WIDTH 7 #define MISC_B_CLK_DIV_SHIFT 16 #define MISC_A_CLK_DIV_SHIFT 8 #define MISC_B_CLK_SEL_SHIFT 6 @@ -87,12 +87,13 @@ static struct meson_pwm_channel_data { }; struct meson_pwm_channel { + unsigned long rate; unsigned int hi; unsigned int lo; - u8 pre_div; - struct clk *clk_parent; struct clk_mux mux; + struct clk_divider div; + struct clk_gate gate; struct clk *clk; }; @@ -125,16 +126,6 @@ static int meson_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm) struct device *dev = chip->dev; int err; - if (channel->clk_parent) { - err = clk_set_parent(channel->clk, channel->clk_parent); - if (err < 0) { - dev_err(dev, "failed to set parent %s for %s: %d\n", - __clk_get_name(channel->clk_parent), - __clk_get_name(channel->clk), err); - return err; - } - } - err = clk_prepare_enable(channel->clk); if (err < 0) { dev_err(dev, "failed to enable clock %s: %d\n", @@ -157,8 +148,9 @@ static int meson_pwm_calc(struct meson_pwm *meson, struct pwm_device *pwm, const struct pwm_state *state) { struct meson_pwm_channel *channel = &meson->channels[pwm->hwpwm]; - unsigned int duty, period, pre_div, cnt, duty_cnt; + unsigned int duty, period, cnt, duty_cnt; unsigned long fin_freq; + u64 freq; duty = state->duty_cycle; period = state->period; @@ -166,7 +158,11 @@ static int meson_pwm_calc(struct meson_pwm *meson, struct pwm_device *pwm, if (state->polarity == PWM_POLARITY_INVERSED) duty = period - duty; - fin_freq = clk_get_rate(channel->clk); + freq = div64_u64(NSEC_PER_SEC * (u64)0xffff, period); + if (freq > ULONG_MAX) + freq = ULONG_MAX; + + fin_freq = clk_round_rate(channel->clk, freq); if (fin_freq == 0) { dev_err(meson->chip.dev, "invalid source clock frequency\n"); return -EINVAL; @@ -174,46 +170,35 @@ static int meson_pwm_calc(struct meson_pwm *meson, struct pwm_device *pwm, dev_dbg(meson->chip.dev, "fin_freq: %lu Hz\n", fin_freq); - pre_div = div64_u64(fin_freq * (u64)period, NSEC_PER_SEC * 0xffffLL); - if (pre_div > MISC_CLK_DIV_MASK) { - dev_err(meson->chip.dev, "unable to get period pre_div\n"); - return -EINVAL; - } - - cnt = div64_u64(fin_freq * (u64)period, NSEC_PER_SEC * (pre_div + 1)); + cnt = div64_u64(fin_freq * (u64)period, NSEC_PER_SEC); if (cnt > 0xffff) { dev_err(meson->chip.dev, "unable to get period cnt\n"); return -EINVAL; } - dev_dbg(meson->chip.dev, "period=%u pre_div=%u cnt=%u\n", period, - pre_div, cnt); + dev_dbg(meson->chip.dev, "period=%u cnt=%u\n", period, cnt); if (duty == period) { - channel->pre_div = pre_div; channel->hi = cnt; channel->lo = 0; } else if (duty == 0) { - channel->pre_div = pre_div; channel->hi = 0; channel->lo = cnt; } else { - /* Then check is we can have the duty with the same pre_div */ - duty_cnt = div64_u64(fin_freq * (u64)duty, - NSEC_PER_SEC * (pre_div + 1)); + duty_cnt = div64_u64(fin_freq * (u64)duty, NSEC_PER_SEC); if (duty_cnt > 0xffff) { dev_err(meson->chip.dev, "unable to get duty cycle\n"); return -EINVAL; } - dev_dbg(meson->chip.dev, "duty=%u pre_div=%u duty_cnt=%u\n", - duty, pre_div, duty_cnt); + dev_dbg(meson->chip.dev, "duty=%u duty_cnt=%u\n", duty, duty_cnt); - channel->pre_div = pre_div; channel->hi = duty_cnt; channel->lo = cnt - duty_cnt; } + channel->rate = fin_freq; + return 0; } @@ -223,16 +208,15 @@ static void meson_pwm_enable(struct meson_pwm *meson, struct pwm_device *pwm) struct meson_pwm_channel_data *channel_data; unsigned long flags; u32 value; + int err; channel_data = &meson_pwm_per_channel_data[pwm->hwpwm]; - spin_lock_irqsave(&meson->lock, flags); + err = clk_set_rate(channel->clk, channel->rate); + if (err) + dev_err(meson->chip.dev, "setting clock rate failed\n"); - value = readl(meson->base + REG_MISC_AB); - value &= ~(MISC_CLK_DIV_MASK << channel_data->clk_div_shift); - value |= channel->pre_div << channel_data->clk_div_shift; - value |= BIT(channel_data->clk_en_bit); - writel(value, meson->base + REG_MISC_AB); + spin_lock_irqsave(&meson->lock, flags); value = FIELD_PREP(PWM_HIGH_MASK, channel->hi) | FIELD_PREP(PWM_LOW_MASK, channel->lo); @@ -271,16 +255,16 @@ static int meson_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, /* * This IP block revision doesn't have an "always high" * setting which we can use for "inverted disabled". - * Instead we achieve this using the same settings - * that we use a pre_div of 0 (to get the shortest - * possible duration for one "count") and + * Instead we achieve this by setting an arbitrary, + * very high frequency, resulting in the shortest + * possible duration for one "count" and * "period == duty_cycle". This results in a signal * which is LOW for one "count", while being HIGH for * the rest of the (so the signal is HIGH for slightly * less than 100% of the period, but this is the best * we can achieve). */ - channel->pre_div = 0; + channel->rate = 1000000000; channel->hi = ~0; channel->lo = 0; @@ -305,7 +289,6 @@ static unsigned int meson_pwm_cnt_to_ns(struct pwm_chip *chip, struct meson_pwm *meson = to_meson_pwm(chip); struct meson_pwm_channel *channel; unsigned long fin_freq; - u32 fin_ns; /* to_meson_pwm() can only be used after .get_state() is called */ channel = &meson->channels[pwm->hwpwm]; @@ -314,9 +297,7 @@ static unsigned int meson_pwm_cnt_to_ns(struct pwm_chip *chip, if (fin_freq == 0) return 0; - fin_ns = div_u64(NSEC_PER_SEC, fin_freq); - - return cnt * fin_ns * (channel->pre_div + 1); + return div_u64(NSEC_PER_SEC * (u64)cnt, fin_freq); } static int meson_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm, @@ -335,11 +316,8 @@ static int meson_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm, value = readl(meson->base + REG_MISC_AB); - tmp = BIT(channel_data->pwm_en_bit) | BIT(channel_data->clk_en_bit); - state->enabled = (value & tmp) == tmp; - - tmp = value >> channel_data->clk_div_shift; - channel->pre_div = FIELD_GET(MISC_CLK_DIV_MASK, tmp); + tmp = BIT(channel_data->pwm_en_bit); + state->enabled = __clk_is_enabled(channel->clk) && (value & tmp) == tmp; value = readl(meson->base + channel_data->reg_offset); @@ -475,6 +453,7 @@ static int meson_pwm_init_channels(struct meson_pwm *meson) for (i = 0; i < meson->chip.npwm; i++) { struct meson_pwm_channel *channel = &meson->channels[i]; struct clk_parent_data mux_parent_data[MESON_MAX_MUX_PARENTS] = {}; + struct clk_parent_data div_parent = {}, gate_parent = {}; struct clk_init_data init = {}; int j; @@ -500,18 +479,57 @@ static int meson_pwm_init_channels(struct meson_pwm *meson) channel->mux.table = NULL; channel->mux.hw.init = &init; - channel->clk = devm_clk_register(dev, &channel->mux.hw); - if (IS_ERR(channel->clk)) { - err = PTR_ERR(channel->clk); + err = devm_clk_hw_register(dev, &channel->mux.hw); + if (err) { dev_err(dev, "failed to register %s: %d\n", name, err); return err; } - snprintf(name, sizeof(name), "clkin%u", i); + snprintf(name, sizeof(name), "%s#div%u", dev_name(dev), i); + + init.name = name; + init.ops = &clk_divider_ops; + init.flags = CLK_SET_RATE_PARENT; + div_parent.index = -1; + div_parent.hw = &channel->mux.hw; + init.parent_data = &div_parent; + init.num_parents = 1; + + channel->div.reg = meson->base + REG_MISC_AB; + channel->div.shift = meson_pwm_per_channel_data[i].clk_div_shift; + channel->div.width = MISC_CLK_DIV_WIDTH; + channel->div.hw.init = &init; + channel->div.flags = 0; + channel->div.lock = &meson->lock; + + err = devm_clk_hw_register(dev, &channel->div.hw); + if (err) { + dev_err(dev, "failed to register %s: %d\n", name, err); + return err; + } - channel->clk_parent = devm_clk_get_optional(dev, name); - if (IS_ERR(channel->clk_parent)) - return PTR_ERR(channel->clk_parent); + snprintf(name, sizeof(name), "%s#gate%u", dev_name(dev), i); + + init.name = name; + init.ops = &clk_gate_ops; + init.flags = CLK_SET_RATE_PARENT; + gate_parent.index = -1; + gate_parent.hw = &channel->div.hw; + init.parent_data = &gate_parent; + init.num_parents = 1; + + channel->gate.reg = meson->base + REG_MISC_AB; + channel->gate.bit_idx = meson_pwm_per_channel_data[i].clk_en_bit; + channel->gate.hw.init = &init; + channel->gate.flags = 0; + channel->gate.lock = &meson->lock; + + channel->clk = devm_clk_register(dev, &channel->gate.hw); + if (IS_ERR(channel->clk)) { + err = PTR_ERR(channel->clk); + dev_err(dev, "failed to register %s: %d\n", name, err); + return err; + } } return 0;