From patchwork Fri May 31 14:11:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hironori KIKUCHI X-Patchwork-Id: 13681737 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 06BDDC25B75 for ; Fri, 31 May 2024 14:12: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:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=2GTNpGcfMHLyVSId3K/PUR1EEX3+4MhWDwCZ4JBuv+8=; b=t4fcFlJfhpFY6J lizOYsgwn6paE2ZiNNGRHUH03L4PPsjum04zIZdHJupcl2WZYhtduQNBzT+hwX7UI38LqiSMeAsnz Kn6xs+KJ3soYO7apL6ThFHgii0c1YVpirmx057ST24uSfeIjr6q6HwwsXUoY6i/5dAmu/nPMtx7KU cvgQ8QUqvSasP3vUbsfNg0tPaGMBaxtKdWIQ1dCaoeP6qBqP+t+Cxjb76EH6Dk7kkho7gqEykZjNg UVK1Ucw8MCDt+FEAtHNQl1K+b+tr1J1Pd0Nvsz5WTRRnQJ8dKG0MXTjpwcI01wyDol1pc1rSPgBHD Zom7EbRbwS6imasg5hXw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sD2za-0000000ASof-1tGW; Fri, 31 May 2024 14:12:26 +0000 Received: from mail-pf1-x433.google.com ([2607:f8b0:4864:20::433]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sD2zX-0000000ASmU-0XDO for linux-arm-kernel@lists.infradead.org; Fri, 31 May 2024 14:12:24 +0000 Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-7024426c75dso799327b3a.1 for ; Fri, 31 May 2024 07:12:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717164741; x=1717769541; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6wTHZBEFwXJhWoEDkPDRuoh0St8wlNAfA/2opNNZCGE=; b=cGSlH0yeqzpUUyjPE5BBN6LQCVHrZy4MYNBUQCMXsXpdQcAsRxhkOs4h+wyAyPTgOY Q1iUS0NwHl2D4B09cDHK0TsfwU1T2+hdBNCHq3hwvAEIhGjT86fRaX2A+tfYP9vDmaYT YiA9xfMV2Qy8vh5783i+gOR1hLopyyZZw2pf1IZszJuNTKseaUqywVvEM8AQ8TJ+5Zn1 cNEcrCmpfjYlHo5fAmotPRX8SsroZTA/92lF02+VYtRn9VeWICd+gwkp0wmlrYbKV9sx 7jCCOWmI8ep0Llsw10kV1FT7nqBZAJQ+XsQLjG9Z5zC57Oll1FMuUGCGeKWchwBSMMfq fKjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717164741; x=1717769541; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6wTHZBEFwXJhWoEDkPDRuoh0St8wlNAfA/2opNNZCGE=; b=p2urzlBYdDU8QV0wq4UmWt0akYP0OVtuHsehN+AQhYHfUKXGgiEAQ76EEOgsdtLnzT 6BEOl5W1liv2/JMjQSYgVocKuMw9Khytkb6RAxUFDFr60xjyrw62BQlMiHL3+EoGmDKI dBfs3XT7zbSliWc7HN8YPUk0WhhN4z5PFj3tO9zvJPNABkO5cS/HxGaZNcCq3q/PyP5y MOQl/SsSxEYA7Uvw5Gr668Fip38inxZTtsGShSYYQmxGcC4xvbp5vD4Q1hdWSe8POjxS n1SWN6zz+4GE1fjN2Cg4o1tE1FTkRJPKTnyi/aK6KG08jMVr5r9PLlECXWd9G4MyyyKv YwVA== X-Forwarded-Encrypted: i=1; AJvYcCXCt6rbAovoadQCvxSlaTG06vqgJYY9vsmoeJ4FdfM7n3OAeOBpHavfzA8ntXNui2fwm8vankwrVvsViGYE9m5l4oCF7JQZQCng+2LKKuUqmsaj9Bs= X-Gm-Message-State: AOJu0Yyji4NKJhYl528qL5awNhaW7JzMsOWdCKckNmiu6YCWa6cWwPQe /Mk25yhDSgtRi/3kpKoKN07QE9oGGhaEj7TmkLpKqfV+wXvAU9/L X-Google-Smtp-Source: AGHT+IGoJr0t15MSyl5iBphGcVZieynY1XhJgQ2y4dhBK/dl/1tYzaCMu+V5iPs17tOhEXXS6/u+gw== X-Received: by 2002:a05:6a20:6a25:b0:1ad:7e4d:2ea2 with SMTP id adf61e73a8af0-1b26f0ec300mr2694125637.4.1717164741148; Fri, 31 May 2024 07:12:21 -0700 (PDT) Received: from noel.flets-west.jp ([2405:6586:4480:a10:167:9818:d778:5c14]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70242b057besm1418103b3a.162.2024.05.31.07.12.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 May 2024 07:12:20 -0700 (PDT) From: Hironori KIKUCHI To: linux-kernel@vger.kernel.org Cc: Hironori KIKUCHI , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Aleksandr Shubin , Cheo Fusi , linux-pwm@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev Subject: [PATCH 1/5] pwm: sun20i: Use devm_pwmchip_alloc() helper Date: Fri, 31 May 2024 23:11:33 +0900 Message-ID: <20240531141152.327592-2-kikuchan98@gmail.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240531141152.327592-1-kikuchan98@gmail.com> References: <20240531141152.327592-1-kikuchan98@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240531_071223_204310_32CBE4BB X-CRM114-Status: GOOD ( 17.31 ) 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 This patch fixes a compile error by using the devm_pwmchip_alloc() helper function along the way. Signed-off-by: Hironori KIKUCHI --- drivers/pwm/pwm-sun20i.c | 45 ++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/drivers/pwm/pwm-sun20i.c b/drivers/pwm/pwm-sun20i.c index 3e3b5b138b3..93782023af6 100644 --- a/drivers/pwm/pwm-sun20i.c +++ b/drivers/pwm/pwm-sun20i.c @@ -102,7 +102,7 @@ struct sun20i_pwm_chip { static inline struct sun20i_pwm_chip *to_sun20i_pwm_chip(struct pwm_chip *chip) { - return container_of(chip, struct sun20i_pwm_chip, chip); + return pwmchip_get_drvdata(chip); } static inline u32 sun20i_pwm_readl(struct sun20i_pwm_chip *chip, @@ -308,12 +308,31 @@ static void sun20i_pwm_reset_ctrl_release(void *data) static int sun20i_pwm_probe(struct platform_device *pdev) { + struct pwm_chip *chip; struct sun20i_pwm_chip *sun20i_chip; + const struct sun20i_pwm_data *data; + u32 npwm; int ret; - sun20i_chip = devm_kzalloc(&pdev->dev, sizeof(*sun20i_chip), GFP_KERNEL); - if (!sun20i_chip) - return -ENOMEM; + data = of_device_get_match_data(&pdev->dev); + if (!data) + return -ENODEV; + + ret = of_property_read_u32(pdev->dev.of_node, "allwinner,pwm-channels", &npwm); + if (ret) + npwm = 8; + + if (npwm > 16) { + dev_info(&pdev->dev, "Limiting number of PWM lines from %u to 16", npwm); + npwm = 16; + } + + chip = devm_pwmchip_alloc(&pdev->dev, npwm, sizeof(*sun20i_chip)); + if (IS_ERR(chip)) + return PTR_ERR(chip); + sun20i_chip = to_sun20i_pwm_chip(chip); + + sun20i_chip->data = data; sun20i_chip->base = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(sun20i_chip->base)) @@ -339,17 +358,6 @@ static int sun20i_pwm_probe(struct platform_device *pdev) return dev_err_probe(&pdev->dev, PTR_ERR(sun20i_chip->rst), "failed to get bus reset\n"); - ret = of_property_read_u32(pdev->dev.of_node, "allwinner,pwm-channels", - &sun20i_chip->chip.npwm); - if (ret) - sun20i_chip->chip.npwm = 8; - - if (sun20i_chip->chip.npwm > 16) { - dev_info(&pdev->dev, "Limiting number of PWM lines from %u to 16", - sun20i_chip->chip.npwm); - sun20i_chip->chip.npwm = 16; - } - /* Deassert reset */ ret = reset_control_deassert(sun20i_chip->rst); if (ret) @@ -359,17 +367,14 @@ static int sun20i_pwm_probe(struct platform_device *pdev) if (ret) return ret; - sun20i_chip->chip.dev = &pdev->dev; - sun20i_chip->chip.ops = &sun20i_pwm_ops; + chip->ops = &sun20i_pwm_ops; mutex_init(&sun20i_chip->mutex); - ret = devm_pwmchip_add(&pdev->dev, &sun20i_chip->chip); + ret = devm_pwmchip_add(&pdev->dev, chip); if (ret < 0) return dev_err_probe(&pdev->dev, ret, "failed to add PWM chip\n"); - platform_set_drvdata(pdev, sun20i_chip); - return 0; } From patchwork Fri May 31 14:11:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hironori KIKUCHI X-Patchwork-Id: 13681739 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 8EC03C27C4F for ; Fri, 31 May 2024 14:12:50 +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:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=B2je9MjTqCwHrx6HcVCoZWs8SOGUf6Kr9ucwmr3pNhU=; b=Sksx0SaxuNhl6y ds3R0J+eVnlpTMgtBA9aepIgs3YGho0q54dDhLDJvymJC/9gR4xV+P1YpOVfo4f/vvb7arvbv6Glu Q6Owmam54DQGIPotm2WGFxafU7KgMmY9MJ8Hdkj4hJWKIKCDEpi8175Z7BojYONO7fRbCvzLeVlmE 3CPssD78HDYnALX7irRO0BjCzffcLwq8pRxkUL/Z/bDdTUyWUGDFIsam0K7z1N4zlBL9L78r7oey/ BaNAxX3K2nwXex+Pb2Y2WxAyfdK+XLip53Ivh7ytMK2UD8KjVrxbdFTYbUkdNapEPC5fPfDv0mTiV LA8jp8Z50ppK791FrFoA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sD2zn-0000000ASuz-0pMy; Fri, 31 May 2024 14:12:39 +0000 Received: from mail-pf1-x435.google.com ([2607:f8b0:4864:20::435]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sD2zc-0000000ASoH-08ic for linux-arm-kernel@lists.infradead.org; Fri, 31 May 2024 14:12:31 +0000 Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-70245b22365so631650b3a.1 for ; Fri, 31 May 2024 07:12:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717164745; x=1717769545; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=S+bkqqaFUuGbFWxlDKxozcD2p6jDvwkVorFlVtLPXmU=; b=AXpWv7X2enyrttddG3rAA4P1FQG7JVobGEKmIFlbBfrG/r+vwWQ97F4y9g+g1IQfd2 hJ8Nc3qtf731Q9SP+cTkN//80r7ovMDuZhD8gJ18z7MJCrQI3X7bkTOCaz6WJnsNACas qRINDbgEbXe7LInMc8V0ntTy3Nu7asAcaJrLwZpquG+hbi7S89KxWnNAOtzRjrz3KKyf pLr/2/bREpEZ/kPGHAqOKHA/29+LwjDpXCTjEep3+VMrlJPacOqSO5zjdLStuEtpMdtH xJ7VzG6RpoiuegSeMnbrrLz6OQAt7o/kQd2P2DuTa4svf3osRpCXguNYYOYdq025OLtA sVMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717164745; x=1717769545; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=S+bkqqaFUuGbFWxlDKxozcD2p6jDvwkVorFlVtLPXmU=; b=T+dV7i1a15gpZwAEcw1Rmvl0ZFsuO1rUqIlpqA8THwMEjVSZfI48fq/K48NLuqI3Im qnCcO+1Yg9CnYcfCaacsVaKNK19EngowhQP/4zS/nS8xJwFUyxySTdPS2J5f8nwYq/jF vbSwp8V4nzi35IA52013wPD8v/6XXd684+LwRmRYv+iilECsadwxhcPOoklITUuURPkl pFdCGCcuDqggfU0lgCqmEJhAmN4njq3OE2ER6aZioEs9UvIDSUDmqJ/fJflDQlnmg8Br I1BpQ2gigo8IUek61zSdEFsgwGQxJbcRnctUyIIxjZ7b65JkNb+CHMFoYUPCdYY+Rprm wlpg== X-Forwarded-Encrypted: i=1; AJvYcCVHqNz5NXlYWXV+cfG5wKbjijMGH+WRWA32b9hWW5u8GBgL0cqUEFnYHW0GqGSkCQI+10HNq4s0OffMdfVkoVYrSPwVUZnhMgdo7Jq9/2wfolApzY8= X-Gm-Message-State: AOJu0YyK/Ltj/2Dql+jUuMpPO2XO5McBpYbV1bPuU4ZSpi6oVV6Wu03l Vq13iiE5/LUVJkZpREWuAFKDAMqHkrRNC9MMwhNo+03HiywqixYU X-Google-Smtp-Source: AGHT+IHPJgFaqgnxSWkMBgv7lPh1JhhIs574AgD6tNqP5a50Y7sg2nqLpeaI6lfcDle6Wt7ebuqnvw== X-Received: by 2002:a05:6a21:7888:b0:1af:d148:b713 with SMTP id adf61e73a8af0-1b26f17c7a0mr2374657637.1.1717164744673; Fri, 31 May 2024 07:12:24 -0700 (PDT) Received: from noel.flets-west.jp ([2405:6586:4480:a10:167:9818:d778:5c14]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70242b057besm1418103b3a.162.2024.05.31.07.12.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 May 2024 07:12:24 -0700 (PDT) From: Hironori KIKUCHI To: linux-kernel@vger.kernel.org Cc: Hironori KIKUCHI , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Aleksandr Shubin , Cheo Fusi , linux-pwm@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev Subject: [PATCH 2/5] pwm: sun20i: Add support for Allwinner H616 PWM Date: Fri, 31 May 2024 23:11:34 +0900 Message-ID: <20240531141152.327592-3-kikuchan98@gmail.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240531141152.327592-1-kikuchan98@gmail.com> References: <20240531141152.327592-1-kikuchan98@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240531_071228_934498_4D44DE25 X-CRM114-Status: GOOD ( 26.94 ) 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 Allwinner H616 SoC has a PWM controller similar to the one in the D1, which is supported by the pwm-sun20i driver. This patch adds support for the Allwinner H616 PWM. The main difference is in the register layout. Specifically, the GATING flag is placed in the PCCR register instead of the individual PCGR register. Thus, it must be handled properly. Signed-off-by: Hironori KIKUCHI --- drivers/pwm/pwm-sun20i.c | 109 ++++++++++++++++++++++++++++++--------- 1 file changed, 86 insertions(+), 23 deletions(-) diff --git a/drivers/pwm/pwm-sun20i.c b/drivers/pwm/pwm-sun20i.c index 93782023af6..d07ce0ebd2a 100644 --- a/drivers/pwm/pwm-sun20i.c +++ b/drivers/pwm/pwm-sun20i.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 /* - * PWM Controller Driver for sunxi platforms (D1, T113-S3 and R329) + * PWM Controller Driver for sunxi platforms (D1, T113-S3, R329 and H616) * * Limitations: * - When the parameters change, current running period will not be completed @@ -20,8 +20,17 @@ #include #include +#define SUN20I_PWM_REG_OFFSET_PER_D1 (0x0080) +#define SUN20I_PWM_REG_OFFSET_PCR_D1 (0x0100 + 0x0000) +#define SUN20I_PWM_REG_OFFSET_PPR_D1 (0x0100 + 0x0004) +#define SUN20I_PWM_REG_OFFSET_PER_H616 (0x0040) +#define SUN20I_PWM_REG_OFFSET_PCR_H616 (0x0060 + 0x0000) +#define SUN20I_PWM_REG_OFFSET_PPR_H616 (0x0060 + 0x0004) + #define SUN20I_PWM_CLK_CFG(chan) (0x20 + (((chan) >> 1) * 0x4)) #define SUN20I_PWM_CLK_CFG_SRC GENMASK(8, 7) +#define SUN20I_PWM_CLK_CFG_BYPASS(chan) BIT(5 + ((chan) & 1)) +#define SUN20I_PWM_CLK_CFG_GATING BIT(4) #define SUN20I_PWM_CLK_CFG_DIV_M GENMASK(3, 0) #define SUN20I_PWM_CLK_DIV_M_MAX 8 @@ -29,15 +38,15 @@ #define SUN20I_PWM_CLK_GATE_BYPASS(chan) BIT((chan) + 16) #define SUN20I_PWM_CLK_GATE_GATING(chan) BIT(chan) -#define SUN20I_PWM_ENABLE 0x80 +#define SUN20I_PWM_ENABLE(chip) ((chip)->data->reg_per) #define SUN20I_PWM_ENABLE_EN(chan) BIT(chan) -#define SUN20I_PWM_CTL(chan) (0x100 + (chan) * 0x20) +#define SUN20I_PWM_CTL(chip, chan) ((chip)->data->reg_pcr + (chan) * 0x20) #define SUN20I_PWM_CTL_ACT_STA BIT(8) #define SUN20I_PWM_CTL_PRESCAL_K GENMASK(7, 0) #define SUN20I_PWM_CTL_PRESCAL_K_MAX field_max(SUN20I_PWM_CTL_PRESCAL_K) -#define SUN20I_PWM_PERIOD(chan) (0x104 + (chan) * 0x20) +#define SUN20I_PWM_PERIOD(chip, chan) ((chip)->data->reg_ppr + (chan) * 0x20) #define SUN20I_PWM_PERIOD_ENTIRE_CYCLE GENMASK(31, 16) #define SUN20I_PWM_PERIOD_ACT_CYCLE GENMASK(15, 0) @@ -91,6 +100,13 @@ */ #define SUN20I_PWM_MAGIC (255 * 65537 + 2 * 65536 + 1) +struct sun20i_pwm_data { + unsigned long reg_per; + unsigned long reg_pcr; + unsigned long reg_ppr; + bool has_pcgr; +}; + struct sun20i_pwm_chip { struct clk *clk_bus, *clk_hosc, *clk_apb; struct reset_control *rst; @@ -98,6 +114,7 @@ struct sun20i_pwm_chip { void __iomem *base; /* Mutex to protect pwm apply state */ struct mutex mutex; + const struct sun20i_pwm_data *data; }; static inline struct sun20i_pwm_chip *to_sun20i_pwm_chip(struct pwm_chip *chip) @@ -139,16 +156,16 @@ static int sun20i_pwm_get_state(struct pwm_chip *chip, else clk_rate = clk_get_rate(sun20i_chip->clk_apb); - val = sun20i_pwm_readl(sun20i_chip, SUN20I_PWM_CTL(pwm->hwpwm)); + val = sun20i_pwm_readl(sun20i_chip, SUN20I_PWM_CTL(sun20i_chip, pwm->hwpwm)); state->polarity = (SUN20I_PWM_CTL_ACT_STA & val) ? PWM_POLARITY_NORMAL : PWM_POLARITY_INVERSED; prescale_k = FIELD_GET(SUN20I_PWM_CTL_PRESCAL_K, val) + 1; - val = sun20i_pwm_readl(sun20i_chip, SUN20I_PWM_ENABLE); + val = sun20i_pwm_readl(sun20i_chip, SUN20I_PWM_ENABLE(sun20i_chip)); state->enabled = (SUN20I_PWM_ENABLE_EN(pwm->hwpwm) & val) ? true : false; - val = sun20i_pwm_readl(sun20i_chip, SUN20I_PWM_PERIOD(pwm->hwpwm)); + val = sun20i_pwm_readl(sun20i_chip, SUN20I_PWM_PERIOD(sun20i_chip, pwm->hwpwm)); mutex_unlock(&sun20i_chip->mutex); @@ -187,23 +204,32 @@ static int sun20i_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, mutex_lock(&sun20i_chip->mutex); - pwm_en = sun20i_pwm_readl(sun20i_chip, SUN20I_PWM_ENABLE); + pwm_en = sun20i_pwm_readl(sun20i_chip, SUN20I_PWM_ENABLE(sun20i_chip)); - if (state->enabled != pwm->state.enabled) { - clk_gate = sun20i_pwm_readl(sun20i_chip, SUN20I_PWM_CLK_GATE); - - if (!state->enabled) { + if (state->enabled != pwm->state.enabled && !state->enabled) { + if (sun20i_chip->data->has_pcgr) { + /* Disabling the gate via PWM Clock Gating Register */ + clk_gate = sun20i_pwm_readl(sun20i_chip, SUN20I_PWM_CLK_GATE); clk_gate &= ~SUN20I_PWM_CLK_GATE_GATING(pwm->hwpwm); - pwm_en &= ~SUN20I_PWM_ENABLE_EN(pwm->hwpwm); - sun20i_pwm_writel(sun20i_chip, pwm_en, SUN20I_PWM_ENABLE); sun20i_pwm_writel(sun20i_chip, clk_gate, SUN20I_PWM_CLK_GATE); + } else if (!(pwm_en & SUN20I_PWM_ENABLE_EN(pwm->hwpwm ^ 1))) { + /* + * Disabling the gate via PWM Clock Configuration Register + * if and only if the counterpart channel is disabled + */ + clk_cfg = sun20i_pwm_readl(sun20i_chip, SUN20I_PWM_CLK_CFG(pwm->hwpwm)); + clk_cfg &= ~SUN20I_PWM_CLK_CFG_GATING; + sun20i_pwm_writel(sun20i_chip, clk_cfg, SUN20I_PWM_CLK_CFG(pwm->hwpwm)); } + + pwm_en &= ~SUN20I_PWM_ENABLE_EN(pwm->hwpwm); + sun20i_pwm_writel(sun20i_chip, pwm_en, sun20i_chip->data->reg_per); } if (state->polarity != pwm->state.polarity || state->duty_cycle != pwm->state.duty_cycle || state->period != pwm->state.period) { - ctl = sun20i_pwm_readl(sun20i_chip, SUN20I_PWM_CTL(pwm->hwpwm)); + ctl = sun20i_pwm_readl(sun20i_chip, SUN20I_PWM_CTL(sun20i_chip, pwm->hwpwm)); clk_cfg = sun20i_pwm_readl(sun20i_chip, SUN20I_PWM_CLK_CFG(pwm->hwpwm)); hosc_rate = clk_get_rate(sun20i_chip->clk_hosc); bus_rate = clk_get_rate(sun20i_chip->clk_apb); @@ -234,7 +260,8 @@ static int sun20i_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, } /* set up the CLK_DIV_M and clock CLK_SRC */ - clk_cfg = FIELD_PREP(SUN20I_PWM_CLK_CFG_DIV_M, div_m); + clk_cfg &= ~(SUN20I_PWM_CLK_CFG_DIV_M | SUN20I_PWM_CLK_CFG_SRC); + clk_cfg |= FIELD_PREP(SUN20I_PWM_CLK_CFG_DIV_M, div_m); clk_cfg |= FIELD_PREP(SUN20I_PWM_CLK_CFG_SRC, use_bus_clk); sun20i_pwm_writel(sun20i_chip, clk_cfg, SUN20I_PWM_CLK_CFG(pwm->hwpwm)); @@ -265,21 +292,33 @@ static int sun20i_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, * Duty-cycle = T high-level / T period */ reg_period |= FIELD_PREP(SUN20I_PWM_PERIOD_ACT_CYCLE, act_cycle); - sun20i_pwm_writel(sun20i_chip, reg_period, SUN20I_PWM_PERIOD(pwm->hwpwm)); + sun20i_pwm_writel(sun20i_chip, reg_period, + SUN20I_PWM_PERIOD(sun20i_chip, pwm->hwpwm)); ctl = FIELD_PREP(SUN20I_PWM_CTL_PRESCAL_K, prescale_k); if (state->polarity == PWM_POLARITY_NORMAL) ctl |= SUN20I_PWM_CTL_ACT_STA; - sun20i_pwm_writel(sun20i_chip, ctl, SUN20I_PWM_CTL(pwm->hwpwm)); + sun20i_pwm_writel(sun20i_chip, ctl, SUN20I_PWM_CTL(sun20i_chip, pwm->hwpwm)); } if (state->enabled != pwm->state.enabled && state->enabled) { - clk_gate &= ~SUN20I_PWM_CLK_GATE_BYPASS(pwm->hwpwm); - clk_gate |= SUN20I_PWM_CLK_GATE_GATING(pwm->hwpwm); + if (sun20i_chip->data->has_pcgr) { + /* Enabling the gate via PWM Clock Gating Register */ + clk_gate = sun20i_pwm_readl(sun20i_chip, SUN20I_PWM_CLK_GATE); + clk_gate &= ~SUN20I_PWM_CLK_GATE_BYPASS(pwm->hwpwm); + clk_gate |= SUN20I_PWM_CLK_GATE_GATING(pwm->hwpwm); + sun20i_pwm_writel(sun20i_chip, clk_gate, SUN20I_PWM_CLK_GATE); + } else { + /* Enabling the gate via PWM Clock Configuration Register */ + clk_cfg = sun20i_pwm_readl(sun20i_chip, SUN20I_PWM_CLK_CFG(pwm->hwpwm)); + clk_cfg &= ~SUN20I_PWM_CLK_CFG_BYPASS(pwm->hwpwm); + clk_cfg |= SUN20I_PWM_CLK_CFG_GATING; + sun20i_pwm_writel(sun20i_chip, clk_cfg, SUN20I_PWM_CLK_CFG(pwm->hwpwm)); + } + pwm_en |= SUN20I_PWM_ENABLE_EN(pwm->hwpwm); - sun20i_pwm_writel(sun20i_chip, pwm_en, SUN20I_PWM_ENABLE); - sun20i_pwm_writel(sun20i_chip, clk_gate, SUN20I_PWM_CLK_GATE); + sun20i_pwm_writel(sun20i_chip, pwm_en, SUN20I_PWM_ENABLE(sun20i_chip)); } unlock_mutex: @@ -293,8 +332,29 @@ static const struct pwm_ops sun20i_pwm_ops = { .get_state = sun20i_pwm_get_state, }; +static const struct sun20i_pwm_data sun20i_d1_pwm_data = { + .reg_per = SUN20I_PWM_REG_OFFSET_PER_D1, + .reg_pcr = SUN20I_PWM_REG_OFFSET_PCR_D1, + .reg_ppr = SUN20I_PWM_REG_OFFSET_PPR_D1, + .has_pcgr = true, +}; + +static const struct sun20i_pwm_data sun50i_h616_pwm_data = { + .reg_per = SUN20I_PWM_REG_OFFSET_PER_H616, + .reg_pcr = SUN20I_PWM_REG_OFFSET_PCR_H616, + .reg_ppr = SUN20I_PWM_REG_OFFSET_PPR_H616, + .has_pcgr = false, +}; + static const struct of_device_id sun20i_pwm_dt_ids[] = { - { .compatible = "allwinner,sun20i-d1-pwm" }, + { + .compatible = "allwinner,sun20i-d1-pwm", + .data = &sun20i_d1_pwm_data + }, + { + .compatible = "allwinner,sun50i-h616-pwm", + .data = &sun50i_h616_pwm_data + }, { }, }; MODULE_DEVICE_TABLE(of, sun20i_pwm_dt_ids); @@ -338,6 +398,8 @@ static int sun20i_pwm_probe(struct platform_device *pdev) if (IS_ERR(sun20i_chip->base)) return PTR_ERR(sun20i_chip->base); + sun20i_chip->data = data; + sun20i_chip->clk_bus = devm_clk_get_enabled(&pdev->dev, "bus"); if (IS_ERR(sun20i_chip->clk_bus)) return dev_err_probe(&pdev->dev, PTR_ERR(sun20i_chip->clk_bus), @@ -388,5 +450,6 @@ static struct platform_driver sun20i_pwm_driver = { module_platform_driver(sun20i_pwm_driver); MODULE_AUTHOR("Aleksandr Shubin "); +MODULE_AUTHOR("Hironori KIKUCHI "); MODULE_DESCRIPTION("Allwinner sun20i PWM driver"); MODULE_LICENSE("GPL"); From patchwork Fri May 31 14:11:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hironori KIKUCHI X-Patchwork-Id: 13681738 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 36AF7C25B75 for ; Fri, 31 May 2024 14:12:50 +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:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=zWDbVyJ5/W7Ig3qJdMrlufWbYOpl0c0Fpbk+GSXX5jk=; b=mtUxOlNWVeKUL3 /BkQ4rYKbuR6Xj79mYAEK+HbZrqPMEh6ii5WcJYCqXKI0tH/QOTAz9qPti+saUx3NKwDLRfqlwimv jcPaWDCZvAUj82HnawMsZAr3FqGGSSUldnUOzqwQjxs447pq4//ov+nY+tH0Le1TcgRIzlAbts7GG O0LfjLH4tr466E5Feeu/W8dTBBdQeBsYz9LQBbiEUnFyswp/iqCQV/Z7zHnezpNr0w7syKcteryLM NkrPlxHbKtHpfvIyZCwvBwPbbNCfjhJZor6W55n2qF3RYCuIudFKUnVfY6s+peXhBeV50u1jciH98 DCgmU8MCSp3qfV2LJgpQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sD2zo-0000000ASvx-16yj; Fri, 31 May 2024 14:12:40 +0000 Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sD2ze-0000000ASpE-12za for linux-arm-kernel@lists.infradead.org; Fri, 31 May 2024 14:12:33 +0000 Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-6f693306b7cso1888555b3a.1 for ; Fri, 31 May 2024 07:12:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717164748; x=1717769548; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=CPJfZzAlshx5ECsaUbb27JTh2zfd8fB5yh8nTmdx9Ew=; b=aPKwwr2JiCURCFe/G8z9LdhQDXhLkbnRIwngwiaLjJSWuva3r7zHKOu5TGvDeQhxC4 5BhXf7VsXcKmtpqUY19H7ANxdI33JiPp40rG+dCRREpYVKClA32EeLC5D/vZkMfKACKC R1wyrJcD9ler+NM7BUHpV7ShxWNQFW3qE4nMHZvXrjpwCFSPm3nIUg60/c1DU3EI/Rjc le0JkaHvepmCm3nEgSWfP7nmW6mNBQw826Wq7v/7ptM9nYfYluB1FNFo0wkAnbS3Fz/5 rCvo4EJ2RyrmFq10UCpBnGg2fT2GBdf/QdOnI9DoIaQvjbQG5dm66MSOag4zkuWxp4F6 f83w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717164748; x=1717769548; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CPJfZzAlshx5ECsaUbb27JTh2zfd8fB5yh8nTmdx9Ew=; b=dXdgS2TmKpfjKSxBqCtV2lNbmh8DirMNtkL5dH9OjNdY5aBtI2K0Kyro8XV5zW8rB9 Bho4N70U60tazBUFPM1niT3GFI7TZXBPJ1Xa1ihtWkL6a9JAEXZaqoCiId9waMZt9mwx FNIFNbgztOFn+a1wP9VLf/7dOHyCMzihNgRK5vKWBW8ZOkAtI+zU3JL2Xg3TLi/zpuhq bEDLVEEg7Ig+9OGkYvP9y5ivtdjL6vXDnKUpztVRQFN68ItNF1MComCN/L/cdQ/x0Kpf ZSl115KyrcZnAlV00tOBQO1s+FlI+lRLvhiVqbY9KR5u+uXesolPH42AUvNZdfKC8mJs BXbg== X-Forwarded-Encrypted: i=1; AJvYcCWPNw6VKeSqTh3YuGLIoh7vbqZNKmd1BpfudKmefAYMDrZiWZrid5Z5cpf0RCRgiT0F/30OhrYoJHjZcH6cLIsI7AKD27DOUtqIctUXVnBil2CoGX4= X-Gm-Message-State: AOJu0Yy/EEL7zWS7Aaym2nI9ZMPv9FpZWXxkdqTJBgsCx+/ZJTK8HREj ULaOEGsp477SIfCWqz/frxmRVfzPPDmzEDtZK6WPkhzoKtLMy3Uu X-Google-Smtp-Source: AGHT+IFUfZFrkaT77WlxLeA/cfEsI2cTENqqh2ey9z8VUL3vIVSJO76NvoXO2i0KDDceR47Z029OGA== X-Received: by 2002:a05:6a00:244d:b0:6f4:43d7:6bdc with SMTP id d2e1a72fcca58-702478c6fbcmr2196315b3a.31.1717164748356; Fri, 31 May 2024 07:12:28 -0700 (PDT) Received: from noel.flets-west.jp ([2405:6586:4480:a10:167:9818:d778:5c14]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70242b057besm1418103b3a.162.2024.05.31.07.12.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 May 2024 07:12:28 -0700 (PDT) From: Hironori KIKUCHI To: linux-kernel@vger.kernel.org Cc: Hironori KIKUCHI , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Aleksandr Shubin , Cheo Fusi , linux-pwm@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev Subject: [PATCH 3/5] dt-bindings: pwm: sun20i: Add compatible string for Allwinner H616 PWM Date: Fri, 31 May 2024 23:11:35 +0900 Message-ID: <20240531141152.327592-4-kikuchan98@gmail.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240531141152.327592-1-kikuchan98@gmail.com> References: <20240531141152.327592-1-kikuchan98@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240531_071230_355364_92583FCA X-CRM114-Status: GOOD ( 12.35 ) 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 Allwinner H616 SoC has a PWM controller similar to the one in the D1, which is supported by the pwm-sun20i driver. The main difference is in the register layout. Specifically, the GATING flag is placed in the PCCR register instead of the individual PCGR register. Add a compatible string to distinguish them. Signed-off-by: Hironori KIKUCHI --- Documentation/devicetree/bindings/pwm/allwinner,sun20i-pwm.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/devicetree/bindings/pwm/allwinner,sun20i-pwm.yaml b/Documentation/devicetree/bindings/pwm/allwinner,sun20i-pwm.yaml index 89cebf7841a..b9b6d7e7c87 100644 --- a/Documentation/devicetree/bindings/pwm/allwinner,sun20i-pwm.yaml +++ b/Documentation/devicetree/bindings/pwm/allwinner,sun20i-pwm.yaml @@ -17,6 +17,7 @@ properties: - items: - const: allwinner,sun50i-r329-pwm - const: allwinner,sun20i-d1-pwm + - const: allwinner,sun50i-h616-pwm reg: maxItems: 1 From patchwork Fri May 31 14:11:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Hironori KIKUCHI X-Patchwork-Id: 13681740 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 92334C25B75 for ; Fri, 31 May 2024 14:12:52 +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:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=c+Uaaxk9QvmaWsUWViuORQ22zY4iq91WilN32e+935k=; b=YqiDaFG5f9YO7j HcFHNpdQ3UHL7qziW2VfYgTzkvMu6K14ug7AODkFwQ2CVzysTpyFLZvQMlzPeVdW2mHJ6vniJMvdQ SmHj99hxTpeh5Gr4clAuK0nNSe2oa+FmOBQXfpXFMBshH9ETpTC7wxhntpTueY+0QewzCcShNQTLo fkIIEjOogLsqxfTOMds2WyneMXKEO+BwLvXFrqyWWG3j5x4EVnWosOSfqotnNVF4f4wvRP6hcnFyM SlN1A+E+WY9ngcKwa35LeITuyx8V5SfzEE3bpEJUXyV9hmViu1PE+BXn5XqYBCvF3qeU61T+gCHnb JeWJiK68eCfES1qPBxAw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sD2zp-0000000ASwc-1M54; Fri, 31 May 2024 14:12:41 +0000 Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sD2zh-0000000ASrk-3ozJ for linux-arm-kernel@lists.infradead.org; Fri, 31 May 2024 14:12:35 +0000 Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-7024d560b32so324779b3a.1 for ; Fri, 31 May 2024 07:12:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717164752; x=1717769552; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=iRKfuq7tJP6RRlShAcOHog3cbaDmp6QUmMlJFE3QvoU=; b=OuzfTssYa8QI8x2sm9y495Y2UD5mLKNvtXXj4YhDOMaXlvlR8VCFBSbl+mJHY9oM5S tUDlS4vsHRJ85X0iksXI7Yz4if4rrX4EwlhGxl92vlVwuMLg2jzSMqDWOC70gFxwtUAI kHEq7wWbo6HwsqfWYOV8kPvxEecm/MHOU8O9kycP66bIUsTmsVIe5O2tW55gyDwwoME5 uT7JBV8MSO6s1U/RffJze9fxajO+p0JXrWv+y81y3CUnNrJztQnknh7dWh/30HQOgLdM itpXcOyjMXqzIaZfNclzbjFWodpqmXkFv5K4VF19YjU6I05e0OqNKY9E/wjp7xw1Ufwd uRDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717164752; x=1717769552; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iRKfuq7tJP6RRlShAcOHog3cbaDmp6QUmMlJFE3QvoU=; b=ciIdTvXmP5gaKB+hcJxXrlNiA7Agk7wM/sMj0jgdyUAQblJSCqgUIGXPezGHdZC+xo Bro9kd7jVqfb0yGfXD/UF6JuSLNUMBs+W7ztxMun4UHsepvhJHGvaiSNJAxsWepOmDIe c07nQhj7p5h+9e8GK3eCaSGo/bLydMDErCGrDgDJh711jZxq1P1Sz4+Zg58OgTl1aZiO luO3xlFpCM4k4/+JvUUZWOeY8iInr4BKd+9bS+1Z5W1/DGpbveUKlc8vNZ8cwWYd1y8L c7TCy3WE1f2iA5GX2Kk9icZzv2p6m1zWVDe0rNxln+jWul/SOJCfQhsAgpvd37mrPw+Y cthw== X-Forwarded-Encrypted: i=1; AJvYcCX5hmD9Zd6JLJ3xT2EbGtr+xmywW6p0BOXgjjzhSLzzY0Z+pWbnLtiBCHoUYdfucbnSOAJY4KumXmkP57VnhlrvWnUr8pN2bACTDO8FIwyhUyOEyCI= X-Gm-Message-State: AOJu0Ywww5qV5yxg8xw0/VyIrVAxWggHCRbnX2fFllDkOm9m/i85HSbb sf0yUMO2T6v1wRwXnVraZWhmpEewN51tLY4m7x/c1UbS4v39rFyl X-Google-Smtp-Source: AGHT+IEDId5bGd2rtdv1MJoyfA1gkmv24Qhvy26tVItCuDcbxaF94h7HM+TLn21fO32yRuaYw68WQw== X-Received: by 2002:a05:6a00:2d1c:b0:6f8:b8d7:1123 with SMTP id d2e1a72fcca58-7024569eae9mr3142578b3a.1.1717164751842; Fri, 31 May 2024 07:12:31 -0700 (PDT) Received: from noel.flets-west.jp ([2405:6586:4480:a10:167:9818:d778:5c14]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70242b057besm1418103b3a.162.2024.05.31.07.12.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 May 2024 07:12:31 -0700 (PDT) From: Hironori KIKUCHI To: linux-kernel@vger.kernel.org Cc: Hironori KIKUCHI , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Aleksandr Shubin , Cheo Fusi , linux-pwm@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev Subject: [PATCH 4/5] pwm: sun20i: Delegating the clock source and DIV_M to the Device Tree Date: Fri, 31 May 2024 23:11:36 +0900 Message-ID: <20240531141152.327592-5-kikuchan98@gmail.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240531141152.327592-1-kikuchan98@gmail.com> References: <20240531141152.327592-1-kikuchan98@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240531_071234_088153_6AC7908C X-CRM114-Status: GOOD ( 26.83 ) 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 This patch removes the SUN20I_PWM_MAGIC macro by delegating the clock source and DIV_M selection to the Device Tree. This change addresses the issue of resolution discrepancies that arise from the enabling order of PWM channels which are coupled. Additionally, this patch clarifies and corrects the calculations for the period and duty cycle. By using DIV_ROUND_CLOSEST(), it minimizes the errors between the configured and actual values. Signed-off-by: Hironori KIKUCHI --- drivers/pwm/pwm-sun20i.c | 190 ++++++++++++++++----------------------- 1 file changed, 79 insertions(+), 111 deletions(-) diff --git a/drivers/pwm/pwm-sun20i.c b/drivers/pwm/pwm-sun20i.c index d07ce0ebd2a..4bf8a67df38 100644 --- a/drivers/pwm/pwm-sun20i.c +++ b/drivers/pwm/pwm-sun20i.c @@ -52,53 +52,13 @@ #define SUN20I_PWM_PCNTR_SIZE BIT(16) -/* - * SUN20I_PWM_MAGIC is used to quickly compute the values of the clock dividers - * div_m (SUN20I_PWM_CLK_CFG_DIV_M) & prescale_k (SUN20I_PWM_CTL_PRESCAL_K) - * without using a loop. These dividers limit the # of cycles in a period - * to SUN20I_PWM_PCNTR_SIZE by applying a scaling factor of - * 1/(div_m * (prescale_k + 1)) to the clock source. - * - * SUN20I_PWM_MAGIC is derived by solving for div_m and prescale_k - * such that for a given requested period, - * - * i) div_m is minimized for any prescale_k ≤ SUN20I_PWM_CTL_PRESCAL_K_MAX, - * ii) prescale_k is minimized. - * - * The derivation proceeds as follows, with val = # of cycles for requested - * period: - * - * for a given value of div_m we want the smallest prescale_k such that - * - * (val >> div_m) // (prescale_k + 1) ≤ 65536 (SUN20I_PWM_PCNTR_SIZE) - * - * This is equivalent to: - * - * (val >> div_m) ≤ 65536 * (prescale_k + 1) + prescale_k - * ⟺ (val >> div_m) ≤ 65537 * prescale_k + 65536 - * ⟺ (val >> div_m) - 65536 ≤ 65537 * prescale_k - * ⟺ ((val >> div_m) - 65536) / 65537 ≤ prescale_k - * - * As prescale_k is integer, this becomes - * - * ((val >> div_m) - 65536) // 65537 ≤ prescale_k - * - * And is minimized at - * - * ((val >> div_m) - 65536) // 65537 - * - * Now we pick the smallest div_m that satifies prescale_k ≤ 255 - * (i.e SUN20I_PWM_CTL_PRESCAL_K_MAX), - * - * ((val >> div_m) - 65536) // 65537 ≤ 255 - * ⟺ (val >> div_m) - 65536 ≤ 255 * 65537 + 65536 - * ⟺ val >> div_m ≤ 255 * 65537 + 2 * 65536 - * ⟺ val >> div_m < (255 * 65537 + 2 * 65536 + 1) - * ⟺ div_m = fls((val) / (255 * 65537 + 2 * 65536 + 1)) - * - * Suggested by Uwe Kleine-König - */ -#define SUN20I_PWM_MAGIC (255 * 65537 + 2 * 65536 + 1) +#define SUN20I_PWM_CLOCK_SRC_HOSC (0) +#define SUN20I_PWM_CLOCK_SRC_APB (1) +#define SUN20I_PWM_CLOCK_SRC_DEFAULT SUN20I_PWM_CLOCK_SRC_HOSC +#define SUN20I_PWM_DIV_M_SHIFT_DEFAULT (0) + +#define SUN20I_PWM_CHANNELS_MAX (16) +#define SUN20I_PWM_ENTIRE_CYCLE_MAX (0xffff) struct sun20i_pwm_data { unsigned long reg_per; @@ -115,6 +75,9 @@ struct sun20i_pwm_chip { /* Mutex to protect pwm apply state */ struct mutex mutex; const struct sun20i_pwm_data *data; + + u32 clk_src_reg[(SUN20I_PWM_CHANNELS_MAX + 1) / 2]; + u32 div_m_shift_reg[(SUN20I_PWM_CHANNELS_MAX + 1) / 2]; }; static inline struct sun20i_pwm_chip *to_sun20i_pwm_chip(struct pwm_chip *chip) @@ -139,7 +102,8 @@ static int sun20i_pwm_get_state(struct pwm_chip *chip, struct pwm_state *state) { struct sun20i_pwm_chip *sun20i_chip = to_sun20i_pwm_chip(chip); - u16 ent_cycle, act_cycle, prescale_k; + u32 ent_cycle, act_cycle; + u16 prescale_k; u64 clk_rate, tmp; u8 div_m; u32 val; @@ -170,7 +134,7 @@ static int sun20i_pwm_get_state(struct pwm_chip *chip, mutex_unlock(&sun20i_chip->mutex); act_cycle = FIELD_GET(SUN20I_PWM_PERIOD_ACT_CYCLE, val); - ent_cycle = FIELD_GET(SUN20I_PWM_PERIOD_ENTIRE_CYCLE, val); + ent_cycle = FIELD_GET(SUN20I_PWM_PERIOD_ENTIRE_CYCLE, val) + 1; /* * The duration of the active phase should not be longer @@ -196,9 +160,9 @@ static int sun20i_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, const struct pwm_state *state) { struct sun20i_pwm_chip *sun20i_chip = to_sun20i_pwm_chip(chip); - u64 bus_rate, hosc_rate, val, ent_cycle, act_cycle; - u32 clk_gate, clk_cfg, pwm_en, ctl, reg_period; - u32 prescale_k, div_m; + u64 bus_rate, hosc_rate, ent_cycle, act_cycle; + u32 clk_gate, clk_cfg, pwm_en, ctl, reg_period, clk_rate; + u32 prescale_k, div_m, div_m_shift; bool use_bus_clk; int ret = 0; @@ -229,76 +193,49 @@ static int sun20i_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, if (state->polarity != pwm->state.polarity || state->duty_cycle != pwm->state.duty_cycle || state->period != pwm->state.period) { - ctl = sun20i_pwm_readl(sun20i_chip, SUN20I_PWM_CTL(sun20i_chip, pwm->hwpwm)); - clk_cfg = sun20i_pwm_readl(sun20i_chip, SUN20I_PWM_CLK_CFG(pwm->hwpwm)); + int idx = pwm->hwpwm / 2; + hosc_rate = clk_get_rate(sun20i_chip->clk_hosc); bus_rate = clk_get_rate(sun20i_chip->clk_apb); - if (pwm_en & SUN20I_PWM_ENABLE_EN(pwm->hwpwm ^ 1)) { - /* if the neighbor channel is enable, check period only */ - use_bus_clk = FIELD_GET(SUN20I_PWM_CLK_CFG_SRC, clk_cfg) != 0; - val = mul_u64_u64_div_u64(state->period, - (use_bus_clk ? bus_rate : hosc_rate), - NSEC_PER_SEC); - div_m = FIELD_GET(SUN20I_PWM_CLK_CFG_DIV_M, clk_cfg); - } else { - /* check period and select clock source */ - use_bus_clk = false; - val = mul_u64_u64_div_u64(state->period, hosc_rate, NSEC_PER_SEC); - if (val <= 1) { - use_bus_clk = true; - val = mul_u64_u64_div_u64(state->period, bus_rate, NSEC_PER_SEC); - if (val <= 1) { - ret = -EINVAL; - goto unlock_mutex; - } - } - div_m = fls(DIV_ROUND_DOWN_ULL(val, SUN20I_PWM_MAGIC)); - if (div_m > SUN20I_PWM_CLK_DIV_M_MAX) { - ret = -EINVAL; - goto unlock_mutex; - } + use_bus_clk = sun20i_chip->clk_src_reg[idx] == SUN20I_PWM_CLOCK_SRC_APB; + clk_rate = use_bus_clk ? bus_rate : hosc_rate; + div_m_shift = sun20i_chip->div_m_shift_reg[idx]; + div_m = 1 << div_m_shift; - /* set up the CLK_DIV_M and clock CLK_SRC */ - clk_cfg &= ~(SUN20I_PWM_CLK_CFG_DIV_M | SUN20I_PWM_CLK_CFG_SRC); - clk_cfg |= FIELD_PREP(SUN20I_PWM_CLK_CFG_DIV_M, div_m); - clk_cfg |= FIELD_PREP(SUN20I_PWM_CLK_CFG_SRC, use_bus_clk); - - sun20i_pwm_writel(sun20i_chip, clk_cfg, SUN20I_PWM_CLK_CFG(pwm->hwpwm)); + if (state->period > U64_MAX / clk_rate || state->duty_cycle > state->period) { + ret = -EINVAL; + goto unlock_mutex; } + ent_cycle = DIV_ROUND_CLOSEST(state->period * clk_rate, NSEC_PER_SEC * div_m); + act_cycle = + min(DIV_ROUND_CLOSEST(state->duty_cycle * clk_rate, NSEC_PER_SEC * div_m), + ent_cycle); + if (ent_cycle == 0 || + ent_cycle > SUN20I_PWM_ENTIRE_CYCLE_MAX * SUN20I_PWM_CTL_PRESCAL_K_MAX) { + ret = -EINVAL; + goto unlock_mutex; + } + prescale_k = clamp(DIV_ROUND_UP_ULL(ent_cycle, SUN20I_PWM_ENTIRE_CYCLE_MAX), 1, + SUN20I_PWM_CTL_PRESCAL_K_MAX); + ent_cycle = clamp(DIV_ROUND_CLOSEST_ULL(ent_cycle, prescale_k), 1, + SUN20I_PWM_ENTIRE_CYCLE_MAX); + act_cycle = clamp(DIV_ROUND_CLOSEST_ULL(act_cycle, prescale_k), 0, ent_cycle); - /* calculate prescale_k, PWM entire cycle */ - ent_cycle = val >> div_m; - prescale_k = DIV_ROUND_DOWN_ULL(ent_cycle, 65537); - if (prescale_k > SUN20I_PWM_CTL_PRESCAL_K_MAX) - prescale_k = SUN20I_PWM_CTL_PRESCAL_K_MAX; + clk_cfg = sun20i_pwm_readl(sun20i_chip, SUN20I_PWM_CLK_CFG(pwm->hwpwm)); + clk_cfg &= ~(SUN20I_PWM_CLK_CFG_DIV_M | SUN20I_PWM_CLK_CFG_SRC); + clk_cfg |= FIELD_PREP(SUN20I_PWM_CLK_CFG_DIV_M, div_m_shift); + clk_cfg |= FIELD_PREP(SUN20I_PWM_CLK_CFG_SRC, use_bus_clk); + sun20i_pwm_writel(sun20i_chip, clk_cfg, SUN20I_PWM_CLK_CFG(pwm->hwpwm)); - do_div(ent_cycle, prescale_k + 1); - - /* for N cycles, PPRx.PWM_ENTIRE_CYCLE = (N-1) */ reg_period = FIELD_PREP(SUN20I_PWM_PERIOD_ENTIRE_CYCLE, ent_cycle - 1); - - /* set duty cycle */ - val = mul_u64_u64_div_u64(state->duty_cycle, - (use_bus_clk ? bus_rate : hosc_rate), - NSEC_PER_SEC); - act_cycle = val >> div_m; - do_div(act_cycle, prescale_k + 1); - - /* - * The formula of the output period and the duty-cycle for PWM are as follows. - * T period = (PWM01_CLK / PWM0_PRESCALE_K)^-1 * (PPR0.PWM_ENTIRE_CYCLE + 1) - * T high-level = (PWM01_CLK / PWM0_PRESCALE_K)^-1 * PPR0.PWM_ACT_CYCLE - * Duty-cycle = T high-level / T period - */ reg_period |= FIELD_PREP(SUN20I_PWM_PERIOD_ACT_CYCLE, act_cycle); sun20i_pwm_writel(sun20i_chip, reg_period, SUN20I_PWM_PERIOD(sun20i_chip, pwm->hwpwm)); - ctl = FIELD_PREP(SUN20I_PWM_CTL_PRESCAL_K, prescale_k); + ctl = FIELD_PREP(SUN20I_PWM_CTL_PRESCAL_K, prescale_k - 1); if (state->polarity == PWM_POLARITY_NORMAL) ctl |= SUN20I_PWM_CTL_ACT_STA; - sun20i_pwm_writel(sun20i_chip, ctl, SUN20I_PWM_CTL(sun20i_chip, pwm->hwpwm)); } @@ -382,9 +319,10 @@ static int sun20i_pwm_probe(struct platform_device *pdev) if (ret) npwm = 8; - if (npwm > 16) { - dev_info(&pdev->dev, "Limiting number of PWM lines from %u to 16", npwm); - npwm = 16; + if (npwm > SUN20I_PWM_CHANNELS_MAX) { + dev_info(&pdev->dev, "Limiting number of PWM lines from %u to %u", npwm, + SUN20I_PWM_CHANNELS_MAX); + npwm = SUN20I_PWM_CHANNELS_MAX; } chip = devm_pwmchip_alloc(&pdev->dev, npwm, sizeof(*sun20i_chip)); @@ -420,6 +358,36 @@ static int sun20i_pwm_probe(struct platform_device *pdev) return dev_err_probe(&pdev->dev, PTR_ERR(sun20i_chip->rst), "failed to get bus reset\n"); + for (int i = 0; i < (npwm + 1) / 2; i++) { + const char *source; + u32 div_m; + + sun20i_chip->clk_src_reg[i] = SUN20I_PWM_CLOCK_SRC_DEFAULT; + sun20i_chip->div_m_shift_reg[i] = SUN20I_PWM_DIV_M_SHIFT_DEFAULT; + + ret = of_property_read_string_index(pdev->dev.of_node, + "allwinner,pwm-pair-clock-sources", i, &source); + if (!ret) { + if (!strcasecmp(source, "hosc")) + sun20i_chip->clk_src_reg[i] = SUN20I_PWM_CLOCK_SRC_HOSC; + else if (!strcasecmp(source, "apb")) + sun20i_chip->clk_src_reg[i] = SUN20I_PWM_CLOCK_SRC_APB; + else + return dev_err_probe(&pdev->dev, -EINVAL, + "Unknown clock source: %s\n", source); + } + + ret = of_property_read_u32_index(pdev->dev.of_node, + "allwinner,pwm-pair-clock-prescales", i, &div_m); + if (!ret) { + if (div_m <= SUN20I_PWM_CLK_DIV_M_MAX) + sun20i_chip->div_m_shift_reg[i] = div_m; + else + return dev_err_probe(&pdev->dev, -EINVAL, + "Invalid prescale value: %u\n", div_m); + } + } + /* Deassert reset */ ret = reset_control_deassert(sun20i_chip->rst); if (ret) From patchwork Fri May 31 14:11:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hironori KIKUCHI X-Patchwork-Id: 13681741 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 CB41DC25B75 for ; Fri, 31 May 2024 14:13:23 +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:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=wTYOyuWj53aJlzPJgu97p/P4z3/uTPO8KZW7MCaxJAU=; b=OlzrQY3QFKLCwr ES2CjYJsh1gI4CUZ9HmHmsMoMrh04ekk2unVO4C/1rLoasU1Jmc7SGDUtDk41Zgy+LkeKMBd/UaZE He7DTPwz4UnXNffPbS6DAMjxPYpCTRP6/Jgm3fE64yooMaSPLrmt8Mrb9wtIL5iZiQPjv2xk5GVQ+ EGOSU6bLV+wSEmq8EVH7CHT/7Yv7oxgpvNPWoCovG5kgwFkjOKupg2yWIlsIxaUG8amAsgPwDJxNO lskOPDLz99yylSpZLzJ4nYnZkQEtzJ0wPgpu71y044jd1f2WiORwIm8p05dyYhxTHP+Hi49nsdThv G/6+eTOAq35+VENzAFmg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sD30K-0000000ATBh-31k6; Fri, 31 May 2024 14:13:12 +0000 Received: from mail-pf1-x431.google.com ([2607:f8b0:4864:20::431]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sD2zl-0000000AStf-2xT7 for linux-arm-kernel@lists.infradead.org; Fri, 31 May 2024 14:12:39 +0000 Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-70109d34a16so1911773b3a.2 for ; Fri, 31 May 2024 07:12:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717164755; x=1717769555; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=JOcPgbtosl6aPaHyurBEDKVmEjsqOQ4R8FjC6nla/j0=; b=DAe8mYLgdnVoDVLPT/bUuwdvXYQAFH9mmoULghr0w1NN4dY4j5/3JjxrHO5HZjfM/l MeFlMcztUIb6fQhIQ3rTuM7TXl/tCUcusapJ6wQVGldY157JJMJGlh8zk9zZaROMZ0QL BwlRRFdH9LsnB63e2WvB1JwUhunF6J1GdS94iTHMWbvnHigQWT5abZ8z3NB4Ru3yF+Zu PP20s7G6ryHpB3Mrs2++VJdv57be8jA/OAgzLARyJI4NWPQ7b+1xzFGw/gQh1ZzlgAI9 uC0xoEkqkPm8d0ojqXvilCOJnryHgm3RZtgbKFgx2qrgEWyEpv8SGxnmHgp/2Jn2o17T epQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717164755; x=1717769555; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JOcPgbtosl6aPaHyurBEDKVmEjsqOQ4R8FjC6nla/j0=; b=LrnMbH89g3Tg8itAbtIA3tH+bO5CZDR1iwcVX/uWpDfwkuZHDSivXolp85uP5EAx2m N9haQH7uDz/PIhWIQcUSgE5VeccTAFThic6qaxV8boE/hPWqQZJrdDOdnuR9eqWacD40 wEE+pOQVH4BSPgDKpgLiQMZptpFSRFlQLxcnlrcnGHwoXMGZ7kpIVUshjko1bd2bOyh4 ZsLJZxSxGOf0SCYwGGQ53NTlj43ExViMyLnLNK6QBOhVoehN6RzCKhN5F5CJeUfRTSdK zXQvJpfCVPoJR9700T0X5pa0wItOHMJsBV6KO/gCPBG73ihJyo+JrvumGXInP9nT4K0z MQOQ== X-Forwarded-Encrypted: i=1; AJvYcCXzcQP4Dq1oT9TrugFOnbxBB4d1EvKCtkY5Habkdd81VGGKnYWVONaChUiy661wTUwNCKfh3+caPt+EMOpZG/kdhf74Gh09yqilVoHKVTwAuy2C89c= X-Gm-Message-State: AOJu0Yx8+HxTNPqTVfuJ+Vn/i4p8rDFzup9TSns5UN7J39FBtKroKsWu Wl/zSk4JBqKujwcks7Bejb9y/kncjF1/Wf81U6RzPvRSZYlyIuPv X-Google-Smtp-Source: AGHT+IED1pv9oGjdH+Ngk5fD7H3whpkkw+4F3I2DkC4Ur7bEQ6LnfE0ADN36jmtn6xY3QZI+rCQlyw== X-Received: by 2002:a05:6a21:33a3:b0:1b2:6b27:5cac with SMTP id adf61e73a8af0-1b26f1f73b5mr2415856637.32.1717164755418; Fri, 31 May 2024 07:12:35 -0700 (PDT) Received: from noel.flets-west.jp ([2405:6586:4480:a10:167:9818:d778:5c14]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70242b057besm1418103b3a.162.2024.05.31.07.12.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 May 2024 07:12:35 -0700 (PDT) From: Hironori KIKUCHI To: linux-kernel@vger.kernel.org Cc: Hironori KIKUCHI , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Aleksandr Shubin , Cheo Fusi , linux-pwm@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev Subject: [PATCH 5/5] dt-bindings: pwm: sun20i: Add options to select a clock source and DIV_M Date: Fri, 31 May 2024 23:11:37 +0900 Message-ID: <20240531141152.327592-6-kikuchan98@gmail.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240531141152.327592-1-kikuchan98@gmail.com> References: <20240531141152.327592-1-kikuchan98@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240531_071237_883198_2F0D9918 X-CRM114-Status: GOOD ( 10.43 ) 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 This patch adds new options to select a clock source and DIV_M register value for each coupled PWM channels. Signed-off-by: Hironori KIKUCHI --- .../bindings/pwm/allwinner,sun20i-pwm.yaml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Documentation/devicetree/bindings/pwm/allwinner,sun20i-pwm.yaml b/Documentation/devicetree/bindings/pwm/allwinner,sun20i-pwm.yaml index b9b6d7e7c87..436a1d344ab 100644 --- a/Documentation/devicetree/bindings/pwm/allwinner,sun20i-pwm.yaml +++ b/Documentation/devicetree/bindings/pwm/allwinner,sun20i-pwm.yaml @@ -45,6 +45,25 @@ properties: description: The number of PWM channels configured for this instance enum: [6, 9] + allwinner,pwm-pair-clock-sources: + description: The clock source names for each PWM pair + items: + enum: [hosc, apb] + minItems: 1 + maxItems: 8 + + allwinner,pwm-pair-clock-prescales: + description: The prescale (DIV_M register) values for each PWM pair + $ref: /schemas/types.yaml#/definitions/uint32-matrix + items: + items: + minimum: 0 + maximum: 8 + minItems: 1 + maxItems: 1 + minItems: 1 + maxItems: 8 + allOf: - $ref: pwm.yaml#