From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f179.google.com (mail-pg1-f179.google.com [209.85.215.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B9CD1535D8 for ; Wed, 23 Apr 2025 08:53:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745398400; cv=none; b=jenbnJ6ldj3ZSM0KLac6Z5Zb7cr1t7/b6CrwByW4+j0K8F0yQa8pWnqWJBAnAs4iVEOFVguYRVML+nb/q0Xf6yoT2+f/1BfJ/ykP4j0vvv7nCOs0VWB60KeFngstPC6K4d7gS5aCHqVAl9ZYthwJHS6hXAPTkX+k+wbaNEV+UP8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745398400; c=relaxed/simple; bh=UOI8lXRZPdfZSPbWA2ksZJRwnym2wxvE561CmHCyVWI=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=QQchr4EBvlBV+JeL7meGvQvrnN4DFy7HWCS5t+wqd8bwXWQT0aYCG0ftdTBKbuQgnCeLO5n2yw8qYmS/ggzmgny0QivzRZR1xyx1ccmZFEXKvRxaUnMoMON7G/JVD6YhZG38EjaiQcQ80e+MU+tUU9MTRoJR9nulPqsIiJxrSjo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com; spf=pass smtp.mailfrom=sifive.com; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b=IigiiLae; arc=none smtp.client-ip=209.85.215.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sifive.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="IigiiLae" Received: by mail-pg1-f179.google.com with SMTP id 41be03b00d2f7-b0db0b6a677so5318436a12.2 for ; Wed, 23 Apr 2025 01:53:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1745398397; x=1746003197; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=JjebrSqhRy+XNyTElbHFiq0P7Ym7xRzEEhcpacCtDZc=; b=IigiiLaeAZvI83uC5U0K5yngenzXu2CxZSUGHrFSWlrm+sZOIOf0rKkUdD4O6OwEuZ hbJOlbVg49fm+JCITRbx2q9SpFTZ61kGzxrn1wFokvSGJcWBNCSaLqAYb/Erd/qZnkEm uIXo1OgC8+/x/MQWIXWNcEpy4h/t4NnO+V6GlznJwe6pYpy47/09NJX8BBkkThfqTDB/ YgINLPOGDNjNdzRhvoQn2kXSu+KsOHvhlvgH/K+LQfSISb7j1IO4CF6hVK4awlOJWnhA nUr5lSKQ7VjzWtODzm27phQa4WY8lSx+QJPoj4WSzGxt/QOGp35JwDuk893rtZkWDsnX baXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745398397; x=1746003197; 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=JjebrSqhRy+XNyTElbHFiq0P7Ym7xRzEEhcpacCtDZc=; b=JazPupAfzjGSCvi/+MUDLQLVwiRfbx+asVe3clzqU+rtA5LTeOxgpKwDWdOPJ7Kge8 gx1LZUiAcjXc4jqShBGUkAUL7LU715Mu0egw/k3wH3mxXsbAHrBNDsep+qFr94zYJ8Jd oIrkURBHaobtyf+DpZ7FG88tpb4njOmhtNws43TXbDylk1UhBebvBLp8RkxcSe++Y6V+ 1jXzNeAIIbog+E76VzrqSvHxW1f+F65vpDJi2vltkzHhAjomS7p2aHFIqr4Wb6yyQLzp RdOyINl6jOM5hvPyDUk5UvviFQVzNlRSD85vZZCDqb4meV4s2m0H9MgLV1XJNAxxYPHU NbSA== X-Forwarded-Encrypted: i=1; AJvYcCWX+ioVG0qOSiloaWG3Kx96rgol3WnBTiLhkO+90Ouyie6ZgPCi/6iQ7W3Coy5iI83kuwLW9cxhziinom4=@vger.kernel.org X-Gm-Message-State: AOJu0YxSZKxSeeuwBcWaPI7YAu9ths5mpK9QY5An3apvdQMXcJRf4+6v caPV/B5cFM3LQnVjfmGHVZ6fLA0D0/duPS8blOcb2Tq0YKuI/npQPQWcjXgl8RA= X-Gm-Gg: ASbGnctGUgN8im+TImZKfVqjFEL8jUSuTlf8q429QcV8Va6BpuOKB1EssdCPV5Kmqo4 7EDWw1vhLkgPomg6AY9HXJj3//pVyaSW7J9FyhOzbY5QocX7tTWhzQ6+72yBWCxK972TedTxaOU H+rx+emOem5h97FqieNBAEX5B+kqUbDI6pOdgvILU4qRVKGIZQKHeRuBwgQzMY/awcynAbaW3Xk n6rgCdkvrFHZQiDoGwMPttecPHhhqFQHdvIJOJcStVgzE5M6Dir+YZ1BZO41BbMDoUiooxvSSaO vXRwgx8BAXPMST05wJsL3S47bw2xElpYpj/MOgj8jbgbStBha2BpXhBGFH1zdjcppfTCDYaSOP+ SEA== X-Google-Smtp-Source: AGHT+IE/xgNsfxLOOIy9HFiTH79KuPX/M8jQhMYXEVtLbecTAoeikygJMa2gCllgel3Hj8t3lvLqwQ== X-Received: by 2002:a17:90b:2751:b0:301:98fc:9b5a with SMTP id 98e67ed59e1d1-3087bb4150cmr24558428a91.6.1745398396823; Wed, 23 Apr 2025 01:53:16 -0700 (PDT) Received: from hsinchu36-syssw02.internal.sifive.com ([210.176.154.34]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-309dfa5f880sm1047611a91.38.2025.04.23.01.53.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Apr 2025 01:53:16 -0700 (PDT) From: Nylon Chen To: Conor Dooley , Rob Herring , Krzysztof Kozlowski , Paul Walmsley , Palmer Dabbelt , Albert Ou , Samuel Holland , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= Cc: linux-riscv@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pwm@vger.kernel.org, Nylon Chen Subject: [PATCH v13 0/5] Change PWM-controlled LED pin active mode and algorithm Date: Wed, 23 Apr 2025 17:04:41 +0800 Message-Id: <20250423090446.294846-1-nylon.chen@sifive.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit According to the circuit diagram of User LEDs - RGB described in the manual hifive-unleashed-a00.pdf[0] and hifive-unmatched-schematics-v3.pdf[1]. The behavior of PWM is acitve-high. According to the descriptionof PWM for pwmcmp in SiFive FU740-C000 Manual[2]. The pwm algorithm is (PW) pulse active time = (D) duty * (T) period. The `frac` variable is pulse "inactive" time so we need to invert it. So this patchset removes active-low in DTS and adds reverse logic to the driver. Links: - [0]: https://sifive.cdn.prismic.io/sifive/c52a8e32-05ce-4aaf-95c8-7bf8453f8698_hifive-unleashed-a00-schematics-1.pdf - [1]: https://sifive.cdn.prismic.io/sifive/6a06d6c0-6e66-49b5-8e9e-e68ce76f4192_hifive-unmatched-schematics-v3.pdf - [2]: https://sifive.cdn.prismic.io/sifive/1a82e600-1f93-4f41-b2d8-86ed8b16acba_fu740-c000-manual-v1p6.pdf Updated patches: 1 New patches: 0 Unchanged patches: 4 Changed in v13: - Fix syntax error: Added missing closing parenthesis in do_div() function call. Changed in v12: - Replace division with do_div() to fix __udivdi3 modpost error. Changed in v11: - Fix rounding consistency in apply() and get_state() - Add code comments to help clarify Reference Manual errors. Changed in v10: - Add 'inactive' variable in apply() to match pwm_sifive_get_state() style - Update comment about hardware limitation - it cannot generate 0% duty cycle rather than 100% duty cycle Changed in v9: - Fix commit message to adhere to 75 columns rule. - Update commit message's subject. - Add a variable for inactive logic. Changed in v8: - Fix Signed-off-by and Co-developed-by typo. Changed in v7: - Remove active-low strings from hifive-unleashed-a00.dts file. Changed in v6: - Separate the idempotent test bug fixes into a new patch. - Move the reversing the duty before the line checking state->enabled. - Fix the algorithm and change it to take the minimum value first and then reverse it. Changed in v5: - Add the updates to the PWM algorithm based on version 2 back in. - Replace div64_ul with DIV_ROUND_UP_ULL to correct the error in the period value of the idempotent test in pwm_apply_state_debug. Changed in v4: - Remove previous updates to the PWM algorithm. Changed in v3: - Convert the reference link to standard link. - Move the inverted function before taking the minimum value. - Change polarity check condition(high and low). - Pick the biggest period length possible that is not bigger than the requested period. Changed in v2: - Convert the reference link to standard link. - Fix typo: s/sifive unmatched:/sifive: unmatched:/. - Remove active-low from hifive-unleashed-a00.dts. - Include this reference link in the dts and pwm commit messages. Nylon Chen (5): riscv: dts: sifive: unleashed/unmatched: Remove PWM controlled LED's active-low properties pwm: sifive: change the PWM algorithm pwm: sifive: Fix the error in the idempotent test within the pwm_apply_state_debug function pwm: sifive: Fix rounding issues in apply and get_state functions pwm: sifive: clarify inverted compare logic in comments .../boot/dts/sifive/hifive-unleashed-a00.dts | 12 ++--- .../boot/dts/sifive/hifive-unmatched-a00.dts | 12 ++--- drivers/pwm/pwm-sifive.c | 49 ++++++++++++++----- 3 files changed, 45 insertions(+), 28 deletions(-) -- 2.34.1