Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp38378469rwd; Wed, 12 Jul 2023 07:00:55 -0700 (PDT) X-Google-Smtp-Source: APBJJlExoeZgoWZrKXf+StNUMVe79lMU5fVfiXOjzqFTTpmlV3oooZUNmas1OOn+mju2jpAFX4GG X-Received: by 2002:a17:902:b110:b0:1b6:76ee:190b with SMTP id q16-20020a170902b11000b001b676ee190bmr16530578plr.35.1689170455668; Wed, 12 Jul 2023 07:00:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689170455; cv=none; d=google.com; s=arc-20160816; b=FeA2yMyXm36JCm95d8aaMOpCO+ElKwQMoJPzPZHRkpx5AizZb9g6XXU5DDPC/pITsK OFVUL+MH8q6sK2nxuADxMZjR2p92K2Zc+nsUBjicgPUyK974i3yZgvJ3z2AZrZ9I5Vyv AcgZ00B+xMmNI6o/m3t8LPyv4AMi2AMZEdKd038Q8e0dr9YyY83OYTKUDjw1TFv5NcCS 3VN5ufxkI+Ccn5SY4Z5ZaeDuzPl535vZlX4KeastQsE1F/mt0wRSCab1E3M1v7cmJm7n GkZbm2tEKUm+5q4I93y3Kvn9W29D5HLQ4J9U6x47x/b0TOY35QHPNbmavODUWHoK4Z6M wZ3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=Q9/dLQLgKmsLxbd3aGxhVA74ctHdZI0VI9d8S6+Rzsw=; fh=z/nSrmeg/NvqQkiVRA853d/50Tpd5x5RVrBaAIiB+fU=; b=0pgIc2hN0FgUHWesWeCvQLk9QgsTH6RxAFVU5ezi1UDqD+bcIDQIobye4rbqSbZ1GS B8eQufKY9i4VZbRbslMcHzlK4uKQSa0GXDaOqIbVjMifDyAPCmG/dpWWwKQKy+uD9Qjn 9Fo9fV3z/oZ29Cs91zdW09cTWTKVlHaO4+paiY1mX/jS9OEO2Yc95cK5LzRwfTVsdDab eDrG9cP4RuRmDZSfTV0JnGXRa33Nw2pkZGQbe6N+d55l5OgrID9Mcz5eHwbWOyIFBc5L 83MMAk23upWOb/FBWDAOm5jitKlc9R+0yftUd7iB3zle9kPRb/WmMNAxOcUy9vTivliY gIOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=mryBbePb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p18-20020a170902ebd200b001b80ecdcb88si3311706plg.473.2023.07.12.07.00.40; Wed, 12 Jul 2023 07:00:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=mryBbePb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233099AbjGLNoL (ORCPT + 99 others); Wed, 12 Jul 2023 09:44:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233119AbjGLNoJ (ORCPT ); Wed, 12 Jul 2023 09:44:09 -0400 Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6EB9B1BD5; Wed, 12 Jul 2023 06:44:06 -0700 (PDT) Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-6686708c986so6339425b3a.0; Wed, 12 Jul 2023 06:44:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689169446; x=1691761446; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Q9/dLQLgKmsLxbd3aGxhVA74ctHdZI0VI9d8S6+Rzsw=; b=mryBbePbwMBVx6XGrEXzXAOuHLh3UqdMw2WuA+6wIgGA/md7XMF35wZg3SodGqNqiL mGoA2T44pMO+KhpVvMgq+ThpLjCcQlA0RqJ3dnEoD7m8S4+LmshSNmGjBDFeWnnxJFWY UwRwq5/ZKqJ2H7b73YoB3fZKN35IEUNucCWhwe3FdzVI81TWEwWdBvTob7ztjYidCAYu lL/qSNW6pqCaV3HvhA9rB7nxLv/+MxwNqjld9rX5OVnMue2gNLAlvVqrRhEbXNZfExtJ RXR10sbFrRjfPDYh70iQt64CkjcVwo/sDmpvMxw+cS29hpSGNRhbs2VXvGex+fi/6Jrk wXGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689169446; x=1691761446; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Q9/dLQLgKmsLxbd3aGxhVA74ctHdZI0VI9d8S6+Rzsw=; b=kajPjiDx0pELERFhhr+N26lZEywbc1aGxA04Btu/wWgIDPIoEZnvWPEYkFZATZY1bS kRHDcItgnA11kH8uOdYhj2d2X/Ib0y+o/zyBufQplaPfKrUpZtlkuLR8mMVPiqeTEiaK I6vGbbWCMSxiYuPuZmpPXoc42DBCfmbLzWCWD2YoQ8g0eepXsA5rWsFh7nyQSGT4tNVD WiMwGuky/soacsUEvOhe+nmrtXqX5UaoACswzIbUAvl7wuWRqHVFILgxDS0iNvqUQ82n HCI/NCHHPwn8jdEYcPD4C4J5f7F5Tbj0yqNvBkZI7D63LMwLRlW5QO93bGnpM7G/1jK1 m49g== X-Gm-Message-State: ABy/qLalARzZxTkgRSP3IoWMOnnq13lsp/2hOuJhFxhuikl2TyDgZPY2 9Txy6AvRg8XHehStAIF35/w= X-Received: by 2002:a05:6a00:b51:b0:668:8545:cbeb with SMTP id p17-20020a056a000b5100b006688545cbebmr26295423pfo.15.1689169445774; Wed, 12 Jul 2023 06:44:05 -0700 (PDT) Received: from localhost.localdomain ([113.103.7.132]) by smtp.gmail.com with ESMTPSA id c3-20020aa781c3000000b0067978a01246sm3775641pfn.14.2023.07.12.06.44.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jul 2023 06:44:05 -0700 (PDT) From: Guiting Shen To: thierry.reding@gmail.com, u.kleine-koenig@pengutronix.de Cc: claudiu.beznea@microchip.com, nicolas.ferre@microchip.com, alexandre.belloni@bootlin.com, linux-arm-kernel@lists.infradead.org, linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org, Guiting Shen Subject: [PATCH v4] pwm: atmel: Enable clk when pwm already enabled in bootloader Date: Wed, 12 Jul 2023 21:43:47 +0800 Message-Id: <20230712134347.14897-1-aarongt.shen@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The driver would never call clk_enable() if the PWM channel was already enabled in bootloader which lead to dump the warning message "the PWM clock already disabled" when turning off the PWM channel. Add atmel_pwm_enable_clk_if_on() in probe function to enable clock if the PWM channel was already enabled in bootloader. Signed-off-by: Guiting Shen --- drivers/pwm/pwm-atmel.c | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/drivers/pwm/pwm-atmel.c b/drivers/pwm/pwm-atmel.c index cdbc23649032..28ea0f7267ca 100644 --- a/drivers/pwm/pwm-atmel.c +++ b/drivers/pwm/pwm-atmel.c @@ -36,7 +36,7 @@ #define PWM_SR 0x0C #define PWM_ISR 0x1C /* Bit field in SR */ -#define PWM_SR_ALL_CH_ON 0x0F +#define PWM_SR_ALL_CH_MASK 0x0F /* The following register is PWM channel related registers */ #define PWM_CH_REG_OFFSET 0x200 @@ -464,6 +464,37 @@ static const struct of_device_id atmel_pwm_dt_ids[] = { }; MODULE_DEVICE_TABLE(of, atmel_pwm_dt_ids); +static int atmel_pwm_enable_clk_if_on(struct atmel_pwm_chip *atmel_pwm) +{ + unsigned int i; + int err; + u32 sr; + + sr = atmel_pwm_readl(atmel_pwm, PWM_SR); + if (!(sr & PWM_SR_ALL_CH_MASK)) + return 0; + + for (i = 0; i < atmel_pwm->chip.npwm; i++) { + if (!(sr & (1 << i))) + continue; + + err = clk_enable(atmel_pwm->clk); + if (err) { + dev_err(atmel_pwm->chip.dev, + "failed to enable clock for pwm #%d: %pe\n", + i, ERR_PTR(err)); + + while (i--) { + if (sr & (1 << i)) + clk_disable(atmel_pwm->clk); + } + return err; + } + } + + return 0; +} + static int atmel_pwm_probe(struct platform_device *pdev) { struct atmel_pwm_chip *atmel_pwm; @@ -504,8 +535,15 @@ static int atmel_pwm_probe(struct platform_device *pdev) platform_set_drvdata(pdev, atmel_pwm); + ret = atmel_pwm_enable_clk_if_on(atmel_pwm); + if (ret < 0) + goto remove_pwmchip; + return ret; +remove_pwmchip: + pwmchip_remove(&atmel_pwm->chip); + unprepare_clk: clk_unprepare(atmel_pwm->clk); return ret; -- 2.25.1